spinn_common 7.3.1
Support code for SpiNNaker applications.
Loading...
Searching...
No Matches
Typedefs | Functions
bit_field.h File Reference

Bit field manipulation. More...

#include <stdint.h>
#include <stdbool.h>

Go to the source code of this file.

Typedefs

typedef uint32_t * bit_field_t
 bit_field_t is an arbitrary length bit field (vector of bits) which is used to compactly represent a large number of boolean operations.
 
typedef uint32_t size_t
 An unsigned integer used for the size of objects.
 
typedef uint32_t index_t
 An unsigned integer used as an index.
 
typedef uint32_t counter_t
 An unsigned integer used as a counter or iterator.
 

Functions

static bool bit_field_test (bit_field_t b, index_t n)
 This function tests a particular bit of a bit_field.
 
static void bit_field_clear (bit_field_t restrict b, index_t n)
 This function clears a particular bit of a bit_field.
 
static void bit_field_set (bit_field_t restrict b, index_t n)
 This function sets a particular bit of a bit_field.
 
static void not_bit_field (bit_field_t restrict b, size_t s)
 This function negates the bits of an entire bit_field.
 
static void and_bit_fields (bit_field_t restrict b1, const bit_field_t restrict b2, size_t s)
 This function ands two bit_fields together.
 
static void or_bit_fields (bit_field_t restrict b1, const bit_field_t restrict b2, size_t s)
 This function ors two bit_fields together.
 
static void clear_bit_field (bit_field_t restrict b, size_t s)
 This function clears an entire bit_field.
 
static void set_bit_field (bit_field_t restrict b, size_t s)
 This function sets an entire bit_field.
 
static bool empty_bit_field (const bit_field_t restrict b, size_t s)
 This function tests whether a bit_field is all zeros.
 
static bool nonempty_bit_field (const bit_field_t restrict b, size_t s)
 Testing whether a bit_field is non-empty, i.e. if there is at least one bit set.
 
static size_t get_bit_field_size (size_t bits)
 A function that calculates the size of a bit_field to hold 'bits' bits.
 
static int count_bit_field (const bit_field_t restrict b, size_t s)
 Computes the number of set bits in a bit_field.
 
void print_bit_field_bits (const bit_field_t restrict b, size_t s)
 This function prints out an entire bit_field, as a sequence of ones and zeros.
 
void print_bit_field (const bit_field_t restrict b, size_t s)
 This function prints out an entire bit_field, as a sequence of hexadecimal numbers, one per line.
 
void random_bit_field (bit_field_t restrict b, size_t s)
 Generates a random bit_field for testing purposes.
 
bit_field_t bit_field_alloc (uint32_t n_atoms)
 allocates a bit_field_t object
 

Detailed Description

Bit field manipulation.

A bit field is a vector of machine words which is treated as a vector of bits.

For SpiNNaker each machine word is 32 bits, and so a bit_field for each neuron (assuming 256 neurons) would be 8 words long.

The API includes:

There are also support functions for:

Author
Dave Lester (david.nosp@m..r.l.nosp@m.ester.nosp@m.@man.nosp@m.chest.nosp@m.er.a.nosp@m.c.uk), Jamie Knight (knigh.nosp@m.tj@c.nosp@m.s.man.nosp@m..ac..nosp@m.uk)
Date
12 December, 2013

Function Documentation

◆ bit_field_test()

static bool bit_field_test ( bit_field_t  b,
index_t  n 
)
inlinestatic

This function tests a particular bit of a bit_field.

Parameters
[in]bThe sequence of words representing a bit_field.
[in]nThe size of the bit_field.
Returns
The function returns true if the bit is set or false otherwise.

◆ bit_field_clear()

static void bit_field_clear ( bit_field_t restrict  b,
index_t  n 
)
inlinestatic

This function clears a particular bit of a bit_field.

Parameters
[in]bThe sequence of words representing a bit_field.
[in]nThe size of the bit_field.

◆ bit_field_set()

static void bit_field_set ( bit_field_t restrict  b,
index_t  n 
)
inlinestatic

This function sets a particular bit of a bit_field.

Parameters
[in]bThe sequence of words representing a bit_field.
[in]nThe bit in the bit_field of interest.

◆ not_bit_field()

static void not_bit_field ( bit_field_t restrict  b,
size_t  s 
)
inlinestatic

This function negates the bits of an entire bit_field.

Parameters
[in]bThe sequence of words representing a bit_field.
[in]sThe size of the bit_field.

◆ and_bit_fields()

static void and_bit_fields ( bit_field_t restrict  b1,
const bit_field_t restrict  b2,
size_t  s 
)
inlinestatic

This function ands two bit_fields together.

Parameters
[in,out]b1The sequence of words representing the first bit_field; the result is returned in this parameter.
[in]b2The sequence of words representing the second bit_field.
[in]sThe size of the bit_field.

◆ or_bit_fields()

static void or_bit_fields ( bit_field_t restrict  b1,
const bit_field_t restrict  b2,
size_t  s 
)
inlinestatic

This function ors two bit_fields together.

Parameters
[in,out]b1The sequence of words representing the first bit_field; the result is returned in this parameter.
[in]b2The sequence of words representing the second bit_field.
[in]sThe size of the bit_field.

◆ clear_bit_field()

static void clear_bit_field ( bit_field_t restrict  b,
size_t  s 
)
inlinestatic

This function clears an entire bit_field.

Parameters
[in]bThe sequence of words representing a bit_field.
[in]sThe size of the bit_field.

◆ set_bit_field()

static void set_bit_field ( bit_field_t restrict  b,
size_t  s 
)
inlinestatic

This function sets an entire bit_field.

Parameters
[in]bThe sequence of words representing a bit_field.
[in]sThe size of the bit_field.

◆ empty_bit_field()

static bool empty_bit_field ( const bit_field_t restrict  b,
size_t  s 
)
inlinestatic

This function tests whether a bit_field is all zeros.

Parameters
[in]bThe sequence of words representing a bit_field.
[in]sThe size of the bit_field.
Returns
The function returns true if every bit is zero, or false otherwise.

◆ nonempty_bit_field()

static bool nonempty_bit_field ( const bit_field_t restrict  b,
size_t  s 
)
inlinestatic

Testing whether a bit_field is non-empty, i.e. if there is at least one bit set.

Parameters
[in]bThe sequence of words representing a bit_field.
[in]sThe size of the bit_field.
Returns
The function returns true if at least one bit is set; otherwise false.

◆ get_bit_field_size()

static size_t get_bit_field_size ( size_t  bits)
inlinestatic

A function that calculates the size of a bit_field to hold 'bits' bits.

Parameters
[in]bitsThe number of bits required for this bit_field.
Returns
The size (or number of words) in the bit_field.

◆ count_bit_field()

static int count_bit_field ( const bit_field_t restrict  b,
size_t  s 
)
inlinestatic

Computes the number of set bits in a bit_field.

Parameters
[in]bThe sequence of words representing a bit_field.
[in]sThe size of the bit_field.
Returns
The function returns the number of bits set to 1.

◆ print_bit_field_bits()

void print_bit_field_bits ( const bit_field_t restrict  b,
size_t  s 
)

This function prints out an entire bit_field, as a sequence of ones and zeros.

Parameters
[in]bThe sequence of words representing a bit_field.
[in]sThe size of the bit_field.

◆ print_bit_field()

void print_bit_field ( const bit_field_t restrict  b,
size_t  s 
)

This function prints out an entire bit_field, as a sequence of hexadecimal numbers, one per line.

Parameters
[in]bThe sequence of words representing a bit_field.
[in]sThe size of the bit_field.

◆ random_bit_field()

void random_bit_field ( bit_field_t restrict  b,
size_t  s 
)

Generates a random bit_field for testing purposes.

Parameters
[in]bThe sequence of words representing a bit_field.
[in]sThe size of the bit_field.

◆ bit_field_alloc()

bit_field_t bit_field_alloc ( uint32_t  n_atoms)

allocates a bit_field_t object

Parameters
[in]n_atomsthe number of atoms to cover with this bitfield
Returns
the allocated bitfield