SpiNNFrontEndCommon 7.3.1
Common support code for user-facing front end systems.
Loading...
Searching...
No Matches
routing_table.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2019 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
19#ifndef __ROUTING_TABLE_H__
20#define __ROUTING_TABLE_H__
21
22//=============================================================================
23
25typedef struct key_mask_t {
27 uint32_t key;
28
30 uint32_t mask;
32
34typedef struct entry_t {
37
39 uint32_t route;
40
42 uint32_t source;
43} entry_t;
44
46typedef struct table_t {
48 uint32_t size;
49
52} table_t;
53
59entry_t* routing_table_get_entry(uint32_t entry_id_to_find);
60
66bool routing_table_get_entries(uint32_t start_entry, uint32_t n_entries,
67 entry_t *output);
68
72
76
81void routing_table_remove_from_size(int size_to_remove);
82
86static inline void routing_table_put_entry(const entry_t* entry, int index) {
87 entry_t* e_ptr = routing_table_get_entry(index);
88 e_ptr->key_mask.key = entry->key_mask.key;
89 e_ptr->key_mask.mask = entry->key_mask.mask;
90 e_ptr->route = entry->route;
91 e_ptr->source = entry->source;
92}
93
97static inline void routing_table_copy_entry(int new_index, int old_index) {
98 entry_t* e_ptr = routing_table_get_entry(old_index);
99 routing_table_put_entry(e_ptr, new_index);
100}
101
105static inline void swap_entries(int a, int b) {
106 log_debug("swap %u %u", a, b);
108 log_debug("before %u %u %u %u",
109 temp.key_mask.key, temp.key_mask.mask, temp.route, temp.source);
111 routing_table_put_entry(&temp, b);
113 log_debug("before %u %u %u %u",
114 temp2.key_mask.key, temp2.key_mask.mask, temp2.route, temp2.source);
115}
116
117//=============================================================================
118//state for reduction in parameters being passed around
119
123static inline uint32_t key_mask_get_xs(key_mask_t km) {
124 return ~km.key & ~km.mask;
125}
126
127
131static inline unsigned int key_mask_count_xs(key_mask_t km) {
132 return __builtin_popcount(key_mask_get_xs(km));
133}
134
135
140static inline bool key_mask_intersect(key_mask_t a, key_mask_t b) {
141 return (a.key & b.mask) == (b.key & a.mask);
142}
143
150 uint32_t new_xs = ~(a.key ^ b.key);
151 key_mask_t c;
152 c.mask = a.mask & b.mask & new_xs;
153 c.key = (a.key | b.key) & c.mask;
154
155 return c;
156}
157
158#endif // __ROUTING_TABLE_H__
void log_debug(const char *message,...)
This function logs debugging messages. This level of message is normally not printed except when the ...
key_mask_t key_mask
Key and mask.
uint32_t mask
Mask for the key_mask.
bool routing_table_get_entries(uint32_t start_entry, uint32_t n_entries, entry_t *output)
Gets a pointer to several entries.
Definition rt_single.h:176
static void swap_entries(int a, int b)
Swap a pair of entries at the given indices.
static uint32_t key_mask_get_xs(key_mask_t km)
Get a mask of the Xs in a key_mask.
entry_t entries[]
Entries in the table.
uint32_t size
Number of entries in the table.
static unsigned int key_mask_count_xs(key_mask_t km)
Get a count of the Xs in a key_mask.
static key_mask_t key_mask_merge(key_mask_t a, key_mask_t b)
Generate a new key-mask which is a combination of two other key_masks.
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
static bool key_mask_intersect(key_mask_t a, key_mask_t b)
Determine if two key_masks would match any of the same keys.
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
static void routing_table_put_entry(const entry_t *entry, int index)
Write an entry to a specific index.
uint32_t key
Key for the key_mask.
void routing_table_wait_for_last_transfer(void)
Waits for the last transfer from routing_table_get_entries to complete.
Definition rt_single.h:195
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.
Holds key and mask.
Holds a routing table description.