SpiNNFrontEndCommon 7.3.1
Common support code for user-facing front end systems.
Loading...
Searching...
No Matches
unordered_remove_default_routes.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2017 The University of Manchester
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * https://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
22#ifndef __REMOVE_DEFAULT_ROUTES_H__
23#define __REMOVE_DEFAULT_ROUTES_H__
24
25#include <stdbool.h>
26#include "routing_table.h"
27#include <debug.h>
28
30#define LINK_MASK 0x3f
31
32static inline bool _just_a_link(uint32_t direction) {
33 return __builtin_popcount(direction) == 1 && // Only one direction...
34 (direction & LINK_MASK); // which is a link.
35}
36
37// Test if route's source is opposite to sink
38static inline bool _opposite_links(entry_t *entry) {
39 uint32_t src = entry->source & LINK_MASK;
40 uint32_t dst = entry->route & LINK_MASK;
41 // Equivalent to a rotate of 6 bits by 3 places and single compare
42 return ((dst >> 3) == (src & 0x7) && (src >> 3) == (dst & 0x7));
43}
44
48static inline bool remove_default_routes_minimise(int target_length) {
49 if (routing_table_get_n_entries() <= target_length) {
50 log_info("No Minimise needed as size %u, is below target of %u",
51 routing_table_get_n_entries(), target_length);
52 return true;
53 }
54 // Work out if removing defaultable links is worthwhile
55 int after_size = 0;
56 for (int i = 0; i < routing_table_get_n_entries(); i++) {
57 // Get the current entry
59
60 // See if it can be removed
61 if (_just_a_link(entry->route) && // Only one output, a link
62 _just_a_link(entry->source) && // Only one input, a link
63 _opposite_links(entry)) { // Source is opposite to sink
64 } else {
65 after_size++;
66 // If we won't fit afterwards, no sense trying
67 if (after_size > target_length) {
68 return false;
69 }
70 }
71 }
72
73 uint32_t removed = 0;
74 int last = routing_table_get_n_entries();
75 // Do the actual removal
76 for (int i = 0; i < after_size; i++) {
77 // Get the current entry
79
80 // See if it can be removed
81 if (_just_a_link(entry->route) && // Only one output, a link
82 _just_a_link(entry->source) && // Only one input, a link
83 _opposite_links(entry)) { // Source is opposite to sink
84 if (i < last) {
86 removed++;
87 last--;
88 // Reuse same i in next pass so reduce before the ++
89 i--;
90 }
91 }
92 }
94 return true;
95}
96
97#endif
SpiNNaker debug header file.
void log_info(const char *message,...)
This function logs informational messages. This is the lowest level of message normally printed.
Utilities for a single routing table.
static void routing_table_copy_entry(int new_index, int old_index)
Copy an entry from one index to another.
uint32_t route
Routing direction.
int routing_table_get_n_entries(void)
Get the number of entries in the routing table.
Definition rt_single.h:102
entry_t * routing_table_get_entry(uint32_t entry_id_to_find)
Gets a pointer to where this entry is stored.
Definition rt_single.h:110
void routing_table_remove_from_size(int size_to_remove)
updates table stores accordingly.
Definition rt_single.h:106
uint32_t source
Source of packets arriving at this entry.
Holds data for a routing table entry.
#define LINK_MASK
Picks the bits of a link out of a route.
static bool remove_default_routes_minimise(int target_length)
Remove defaultable routes from a routing table if that helps.