SpiNNFrontEndCommon 7.3.1
Common support code for user-facing front end systems.
Loading...
Searching...
No Matches
merge.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 __MERGE_H__
20#define __MERGE_H__
21
22#include "bit_set.h"
23#include "../common/routing_table.h"
24
26typedef struct merge_t {
29
32
34 uint32_t route;
35
37 uint32_t source;
38} merge_t;
39
41#define FULL 0xffffffff
42
44#define EMPTY 0x00000000
45
47#define INIT_SOURCE 0x0
48
50#define INIT_ROUTE 0x0
51
56 return merge->entries.count - 1;
57}
58
61static inline void merge_clear(merge_t *m) {
62 // Clear the bit set
64
65 // Initialise the key_mask and route
66 m->key_mask.key = FULL; // !!!...
67 m->key_mask.mask = EMPTY; // Matches nothing
68 m->route = INIT_ROUTE;
70}
71
76static inline bool merge_init(merge_t *m, uint32_t n_entries_in_table) {
77 // Initialise the bit_set
78 if (!bit_set_init(&m->entries, n_entries_in_table)) {
79 return false;
80 }
81
82 merge_clear(m);
83 return true;
84}
85
88static inline void merge_delete(merge_t *m) {
89 // Free the bit set
91}
92
96static inline void merge_add(merge_t *m, unsigned int i) {
97 // Add the entry to the bit set contained in the merge
98 if (bit_set_add(&m->entries, i)) {
100
101 // Get the key_mask
102 if (m->key_mask.key == FULL && m->key_mask.mask == EMPTY) {
103 // If this is the first entry in the merge then the merge key_mask
104 // is a copy of the entry key_mask.
105 m->key_mask = entry->key_mask;
106 } else {
107 // Otherwise update the key and mask associated with the merge
108 m->key_mask = key_mask_merge(m->key_mask, entry->key_mask);
109 }
110
111 // Add the route
112 m->route |= entry->route;
113 m->source |= entry->source;
114 }
115}
116
121static inline bool merge_contains(merge_t *m, unsigned int i) {
122 return bit_set_contains(&(m->entries), i);
123}
124
125
129static inline void merge_remove(merge_t *m, unsigned int i) {
130 // Remove the entry from the bit_set contained in the merge
131 if (bit_set_remove(&m->entries, i)) {
132 // Rebuild the key and mask from scratch
133 m->route = INIT_ROUTE;
134 m->source = INIT_SOURCE;
135 m->key_mask.key = FULL;
136 m->key_mask.mask = EMPTY;
137 for (int j = 0; j < routing_table_get_n_entries(); j++) {
139
140 if (bit_set_contains(&m->entries, j)) {
141 m->route |= e->route;
142 m->source |= e->source;
143 if (m->key_mask.key == FULL && m->key_mask.mask == EMPTY) {
144 // Initialise the key_mask
145 m->key_mask.key = e->key_mask.key;
146 m->key_mask.mask = e->key_mask.mask;
147 } else {
148 // Merge the key_mask
150 }
151 }
152 }
153 }
154}
155
156#endif // __MERGE_H__
Sets of bits.
bool bit_set_clear(bit_set_t *b)
Empty a bitset entirely.
Definition bit_set.h:50
static bool bit_set_add(bit_set_t *b, unsigned int i)
Add an element to a bitset.
Definition bit_set.h:100
static bool bit_set_contains(bit_set_t *b, unsigned int i)
Test if an element is in a bitset.
Definition bit_set.h:121
static bool bit_set_remove(bit_set_t *b, unsigned int i)
Remove an element from a bitset.
Definition bit_set.h:136
static bool bit_set_init(bit_set_t *b, unsigned int length)
Create a new bitset.
Definition bit_set.h:65
static void bit_set_delete(bit_set_t *b)
Destroy a bitset.
Definition bit_set.h:89
wrapper over bitfield
Definition bit_set.h:33
uint32_t route
Route taken by entries in the merge.
Definition merge.h:34
#define EMPTY
the empty mask
Definition merge.h:44
static int merge_goodness(merge_t *merge)
Get the goodness for a merge.
Definition merge.h:55
static void merge_clear(merge_t *m)
Clear a merge.
Definition merge.h:61
key_mask_t key_mask
key_mask resulting from the merge
Definition merge.h:31
#define INIT_ROUTE
the init for routes of entries
Definition merge.h:50
static bool merge_contains(merge_t *m, unsigned int i)
See if an entry is contained within a merge.
Definition merge.h:121
#define FULL
the ful key
Definition merge.h:41
static void merge_delete(merge_t *m)
Destroy a merge.
Definition merge.h:88
static void merge_remove(merge_t *m, unsigned int i)
Remove an entry from the merge.
Definition merge.h:129
static bool merge_init(merge_t *m, uint32_t n_entries_in_table)
Initialise a merge.
Definition merge.h:76
uint32_t source
Collective source of entries in the route.
Definition merge.h:37
#define INIT_SOURCE
the init for sources of entries
Definition merge.h:47
static void merge_add(merge_t *m, unsigned int i)
Add an entry to the merge.
Definition merge.h:96
bit_set_t entries
Set of entries included in the merge.
Definition merge.h:28
merge struct. entries which can be merged
Definition merge.h:26
static entry_t merge(const entry_t *entry1, const entry_t *entry2)
Merges a single pair of route entries.
key_mask_t key_mask
Key and mask.
uint32_t mask
Mask for the 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.
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
uint32_t key
Key for the key_mask.
uint32_t source
Source of packets arriving at this entry.
Holds data for a routing table entry.
Holds key and mask.