13#ifndef __xwos_lib_xwbop_h__
14#define __xwos_lib_xwbop_h__
24#include <xwos/ospl/soc/xwbop.h>
27#define XWBOP_BIT(n) ((xwbmp_t)1 << (n))
28#define XWBOP_BMP_MASK(n) ((xwbmp_t)1 << (xwbmp_t)((n) % BITS_PER_XWBMP_T))
29#define XWBOP_BMP(n) ((n) / BITS_PER_XWBMP_T)
30#define XWBOP_DIV_ROUND(n, d) ((n) / (d))
31#define XWBOP_DIV_ROUND_UP(n, d) (((n) + (d) - 1U) / (d))
32#define XWBOP_SHIFT_ROUND(n, s) ((n) >> (s))
33#define XWBOP_SHIFT_ROUND_UP(n, s) (((n) + (1ULL << (s)) - 1ULL) >> (s))
34#define BITS_TO_XWU8_T(n) XWBOP_DIV_ROUND_UP(n, BITS_PER_XWU8_T)
35#define BITS_TO_XWBMP_T(n) XWBOP_DIV_ROUND_UP(n, BITS_PER_XWU8_T * sizeof(xwbmp_t))
36#define XWBOP_ROUND(x, n) ((x) & (~((n) - 1U)))
37#define XWBOP_ALIGN(x, n) (((x) + ((n) - 1U)) & (~((n) - 1U)))
38#define XWBOP_TBIT(x, n) (((x) >> (n)) & 1U)
41#define xwbop_s1m8(a, mask) *(a) |= (mask)
42#define xwbop_c0m8(a, mask) *(a) &= (~(mask))
43#define xwbop_x1m8(a, mask) *(a) ^= (mask)
60#define xwbop_s1m16(a, mask) *(a) |= (mask)
61#define xwbop_c0m16(a, mask) *(a) &= (~(mask))
62#define xwbop_x1m16(a, mask) *(a) ^= (mask)
73#define xwbop_s1m32(a, mask) *(a) |= (mask)
74#define xwbop_c0m32(a, mask) *(a) &= (~(mask))
75#define xwbop_x1m32(a, mask) *(a) ^= (mask)
86#define xwbop_s1m64(a64, mask64) *((xwu64_t *)(a64)) |= (mask64)
87#define xwbop_c0m64(a64, mask64) *((xwu64_t *)(a64)) &= (~(mask64))
88#define xwbop_x1m64(a64, mask64) *((xwu64_t *)(a64)) ^= (mask64)
105#define xwbop(type, op, ...) xwbop_##op##__##type(__VA_ARGS__)
113#define xwbop_s1m(type, addr, mask) xwbop(type, s1m, (addr), (mask))
121#define xwbop_c0m(type, addr, mask) xwbop(type, c0m, (addr), (mask))
129#define xwbop_x1m(type, addr, mask) xwbop(type, x1m, (addr), (mask))
137#define xwbop_rbit(type, data) xwbop(type, rbit, (data))
145#define xwbop_re(type, data) xwbop(type, re, (data))
157#define xwbop_ffs(type, data) xwbop(type, ffs, (data))
169#define xwbop_fls(type, data) xwbop(type, fls, (data))
181#define xwbop_ffz(type, data) xwbop(type, flz, (data))
193#define xwbop_flz(type, data) xwbop(type, flz, (data))
201#define xwbop_weight(type, data) xwbop(type, weight, (data))
209#define DEFINE_XWBOP_S1M(type, bw) \
210static __xwlib_inline \
211void xwbop_s1m__##type(type * x, type m) \
213 xwbop_s1m##bw((xwu##bw##_t *)x, (xwu##bw##_t)m); \
221#define DEFINE_XWBOP_C0M(type, bw) \
222static __xwlib_inline \
223void xwbop_c0m__##type(type * x, type m) \
225 xwbop_c0m##bw((xwu##bw##_t *)x, (xwu##bw##_t)m); \
233#define DEFINE_XWBOP_X1M(type, bw) \
234static __xwlib_inline \
235void xwbop_x1m__##type(type * x, type m) \
237 xwbop_x1m##bw((xwu##bw##_t *)x, (xwu##bw##_t)m); \
245#define DEFINE_XWBOP_RBIT(type, bw) \
246static __xwlib_inline \
247type xwbop_rbit__##type(type x) \
249 return (type)xwbop_rbit##bw((xwu##bw##_t)x); \
257#define DEFINE_XWBOP_RE(type, bw) \
258static __xwlib_inline \
259type xwbop_re__##type(type x) \
261 return (type)xwbop_re##bw((xwu##bw##_t)x); \
269#define DEFINE_XWBOP_FFS(type, bw) \
270static __xwlib_inline \
271xwssq_t xwbop_ffs__##type(type x) \
273 return xwbop_ffs##bw((xwu##bw##_t)x); \
281#define DEFINE_XWBOP_FLS(type, bw) \
282static __xwlib_inline \
283xwssq_t xwbop_fls__##type(type x) \
285 return xwbop_fls##bw((xwu##bw##_t)x); \
293#define DEFINE_XWBOP_FLZ(type, bw) \
294static __xwlib_inline \
295xwssq_t xwbop_flz__##type(type x) \
297 return xwbop_flz##bw((xwu##bw##_t)x); \
305#define DEFINE_XWBOP_FFZ(type, bw) \
306static __xwlib_inline \
307xwssq_t xwbop_ffz__##type(type x) \
309 return xwbop_ffz##bw((xwu##bw##_t)x); \
317#define DEFINE_XWBOP_WEIGHT(type, bw) \
318static __xwlib_inline \
319xwsq_t xwbop_weight__##type(type x) \
321 return xwbop_weight##bw((xwu##bw##_t)x); \
329#define DEFINE_XWBOP(type, bw) \
330 DEFINE_XWBOP_S1M(type, bw) \
331 DEFINE_XWBOP_C0M(type, bw) \
332 DEFINE_XWBOP_X1M(type, bw) \
333 DEFINE_XWBOP_RBIT(type, bw) \
334 DEFINE_XWBOP_RE(type, bw) \
335 DEFINE_XWBOP_FFS(type, bw) \
336 DEFINE_XWBOP_FLS(type, bw) \
337 DEFINE_XWBOP_FLZ(type, bw) \
338 DEFINE_XWBOP_FFZ(type, bw) \
339 DEFINE_XWBOP_WEIGHT(type, bw)
353#if (16 == BITS_PER_XWSZ_T)
355#elif (32 == BITS_PER_XWSZ_T)
357#elif (64 == BITS_PER_XWSZ_T)
361#if (16 == BITS_PER_XWPTR_T)
363#elif (32 == BITS_PER_XWPTR_T)
365#elif (64 == BITS_PER_XWPTR_T)
369#if (8 == BITS_PER_XWID_T)
371#elif (16 == BITS_PER_XWID_T)
373#elif (32 == BITS_PER_XWID_T)
375#elif (64 == BITS_PER_XWID_T)
379#if (8 == BITS_PER_XWREG_T)
381#elif (16 == BITS_PER_XWREG_T)
383#elif (32 == BITS_PER_XWREG_T)
385#elif (64 == BITS_PER_XWREG_T)
389#if (16 == BITS_PER_XWSQ_T)
391#elif (32 == BITS_PER_XWSQ_T)
393#elif (64 == BITS_PER_XWSQ_T)
397#if (8 == BITS_PER_XWBMP_T)
399#elif (16 == BITS_PER_XWBMP_T)
401#elif (32 == BITS_PER_XWBMP_T)
403#elif (64 == BITS_PER_XWBMP_T)
415#define xwbmpop_define(name, bits) xwbmp_t name[BITS_TO_XWBMP_T(bits)]
xwu64_t xwtk_t
XWOS系统滴答计数 (无符号)
xwssq_t xwbmpop_ffs(xwbmp_t *bmp, xwsz_t num)
XWOS BOPLIB:在位图中从最低位起查找第一个被置1的位
xwssq_t xwbmpop_fls(xwbmp_t *bmp, xwsz_t num)
XWOS BOPLIB:在位图中从最高位起查找第一个被置1的位
xwssq_t xwbop_fls32(xwu32_t x)
static xwu8_t xwbop_re8(xwu8_t x)
void xwbmpop_x1m(xwbmp_t *bmp, xwbmp_t msk[], xwsz_t num)
XWOS BOPLIB:将位图中掩码部分翻转
xwu32_t xwbop_re32(xwu32_t x)
void xwbmpop_assign(xwbmp_t *bmp, xwbmp_t opd[], xwsz_t num)
XWOS BOPLIB:赋值操作数到位图
xwssq_t xwbop_flz8(xwu8_t x)
xwssq_t xwbop_ffz8(xwu8_t x)
bool xwbmpop_t0ma_then_s1m(xwbmp_t *bmp, xwbmp_t msk[], xwsz_t num)
XWOS BOPLIB:测试位图中掩码部分是否全部为0,如果是,就将掩码部分全部置1
bool xwbmpop_t1i(xwbmp_t *bmp, xwsq_t n)
XWOS BOPLIB:测试位图中的单个位是否为1
xwsz_t xwbop_weight32(xwu32_t x)
xwu64_t xwbop_re64(xwu64_t x)
bool xwbmpop_t1mo(xwbmp_t *bmp, xwbmp_t msk[], xwsz_t num)
XWOS BOPLIB:测试位图中掩码部分是否至少有一位为1
#define DEFINE_XWBOP(type, bw)
使用模板为类型定义所有的位操作函数
xwsz_t xwbop_weight64(xwu64_t x)
xwu8_t xwbop_rbit8(xwu8_t x)
bool xwbmpop_t1mo_then_c0m(xwbmp_t *bmp, xwbmp_t msk[], xwsz_t num)
XWOS BOPLIB:测试位图中掩码部分是否至少有一位为1,如果是,就将掩码部分全部清0
void xwbmpop_and(xwbmp_t *bmp, xwbmp_t opd[], xwsz_t num)
XWOS BOPLIB:将位图与操作数进行逐位“与”运算
xwssq_t xwbop_ffz64(xwu64_t x)
xwssq_t xwbop_fls64(xwu64_t x)
xwssq_t xwbop_ffs8(xwu8_t x)
xwu16_t xwbop_rbit16(xwu16_t x)
xwssq_t xwbop_ffs32(xwu32_t x)
xwu32_t xwbop_rbit32(xwu32_t x)
xwssq_t xwbmpop_flz(xwbmp_t *bmp, xwsz_t num)
XWOS BOPLIB:在位图中从最高位起查找第一个被清0的位
xwssq_t xwbop_flz32(xwu32_t x)
xwu16_t xwbop_re16(xwu16_t a)
void xwbmpop_c0all(xwbmp_t *bmp, xwsq_t num)
XWOS BOPLIB:将位图中所有位清0
void xwbmpop_s1m(xwbmp_t *bmp, xwbmp_t msk[], xwsz_t num)
XWOS BOPLIB:将位图中掩码部分置1
bool xwbmpop_t0ma(xwbmp_t *bmp, xwbmp_t msk[], xwsz_t num)
XWOS BOPLIB:测试位图中掩码部分是否全部为0
xwsz_t xwbop_weight16(xwu16_t x)
xwssq_t xwbop_ffz16(xwu16_t x)
xwu64_t xwbop_rbit64(xwu64_t x)
void xwbmpop_s1i(xwbmp_t *bmp, xwsq_t n)
XWOS BOPLIB:将位图中单个位置1
void xwbmpop_s1all(xwbmp_t *bmp, xwsq_t num)
XWOS BOPLIB:将位图中所有位置1
xwssq_t xwbop_flz16(xwu16_t x)
xwssq_t xwbop_ffs16(xwu16_t x)
xwssq_t xwbop_ffz32(xwu32_t x)
xwssq_t xwbop_fls16(xwu16_t x)
void xwbmpop_x1i(xwbmp_t *bmp, xwsq_t n)
XWOS BOPLIB:将位图中单个位翻转
void xwbmpop_not(xwbmp_t *bmp, xwsz_t num)
XWOS BOPLIB:将位图按位取反
void xwbmpop_c0i(xwbmp_t *bmp, xwsq_t n)
XWOS BOPLIB:将位图中单个位清0
xwssq_t xwbmpop_cmp(xwbmp_t *bmp, xwbmp_t opd[], xwsz_t num)
XWOS BOPLIB:从数组最高元素开始比较两个位图的数值大小
bool xwbmpop_t1ma(xwbmp_t *bmp, xwbmp_t msk[], xwsz_t num)
XWOS BOPLIB:测试位图中掩码部分是否全部为1
void xwbmpop_or(xwbmp_t *bmp, xwbmp_t opd[], xwsz_t num)
XWOS BOPLIB:将位图与操作数进行逐位“或”运算
bool xwbmpop_t0mo_then_s1m(xwbmp_t *bmp, xwbmp_t msk[], xwsz_t num)
XWOS BOPLIB:测试位图中掩码部分是否至少有一位为0,如果是,就将掩码部分全部置1
void xwbmpop_xor(xwbmp_t *bmp, xwbmp_t opd[], xwsz_t num)
XWOS BOPLIB:将位图与操作数进行逐位“异或”运算
xwssq_t xwbmpop_ffz(xwbmp_t *bmp, xwsz_t num)
XWOS BOPLIB:在位图中从最低位起查找第一个被清0的位
bool xwbmpop_t1ma_then_c0m(xwbmp_t *bmp, xwbmp_t msk[], xwsz_t num)
XWOS BOPLIB:测试位图中掩码部分是否全部为1,如果是,就将掩码部分全部清0
xwssq_t xwbop_flz64(xwu64_t x)
xwssq_t xwbop_ffs64(xwu64_t x)
xwsz_t xwbop_weight8(xwu8_t x)
xwsz_t xwbmpop_weight(xwbmp_t *bmp, xwsz_t num)
XWOS BOPLIB:在位图中统计被置1的位的个数
xwssq_t xwbop_fls8(xwu8_t x)
bool xwbmpop_t0mo(xwbmp_t *bmp, xwbmp_t msk[], xwsz_t num)
XWOS BOPLIB:测试位图中掩码部分是否至少有一位为0
void xwbmpop_c0m(xwbmp_t *bmp, xwbmp_t msk[], xwsz_t num)
XWOS BOPLIB:将位图中掩码部分清0