XenevaOS
Loading...
Searching...
No Matches
bordoisila_bits.h
Go to the documentation of this file.
1
30#ifndef __BORDOISILA_BITS_H__
31#define __BORDOISILA_BITS_H__
32
33#include <stdint.h>
34
35#define BITS_PER_BYTE 8
36#define BITS_PER_LONG (sizeof(long) * BITS_PER_BYTE)
37
38#define BORDOISILA_DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
39#define BITS_TO_LONGS(nr) BORDOISILA_DIV_ROUND_UP(nr, BITS_PER_LONG)
40#define BORDOISILA_BITS_PER_TYPE(type) (sizeof(type) * BITS_PER_BYTE)
41
42
43#define BORDOISILA_BIT(nr) (1UL << (nr))
44#define BORDOISILA_GENMASK(h, l) (((~0UL) - (1UL << (l)) + 1) & (~0UL >> (BITS_PER_LONG - 1 - (h))))
45
46static inline int __bf_shf(uint32_t mask) {
47 if (mask == 0) return 0;
48 int shift = 0;
49 while ((mask & 1) == 0) {
50 mask >>= 1;
51 shift++;
52 }
53 return shift;
54}
55
56#define BORDOISILA_GET_FIELD(_mask, _reg) (((_reg) & (_mask)) >> __bf_shf(_mask))
57
58#define BORDOISILA_PREP_FIELD(_mask, _val) \
59 (((_val) << __bf_shf(_mask)) & (_mask))
60
61#endif
unsigned int uint32_t
Definition acefiex.h:163