Source code for the Trusted Boot Module.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
tbm-mcu/source/bitset.c

61 lines
929 B

#include <bitset.h>
#include <macros.h>
int is_bit_set(void *set_, size_t n)
{
uint8_t *set = set_;
uint8_t *word, mask;
word = set + n / BIT_SIZE(*set);
mask = (1 << (n % BIT_SIZE(*set)));
return (*word & mask) ? 1 : 0;
}
void set_bit(void *set_, size_t n)
{
uint8_t *set = set_;
uint8_t *word, mask;
word = set + n / BIT_SIZE(*set);
mask = (1 << (n % BIT_SIZE(*set)));
*word |= mask;
}
void clear_bit(void *set_, size_t n)
{
uint8_t *set = set_;
uint8_t *word, mask;
word = set + n / BIT_SIZE(*set);
mask = (1 << (n % BIT_SIZE(*set)));
*word &= ~mask;
}
size_t next_set_bit(void *set_, size_t len)
{
uint8_t *set = set_;
size_t n;
for (n = 0; n < len; ++n) {
if (is_bit_set(set, n))
return n;
}
return SIZE_MAX;
}
size_t next_clear_bit(void *set_, size_t len)
{
uint8_t *set = set_;
size_t n;
for (n = 0; n < len; ++n) {
if (!is_bit_set(set, n))
return n;
}
return SIZE_MAX;
}