XWOS API  4.0
XWOS C/C++ API参考手册
载入中...
搜索中...
未找到
xwbop.h
浏览该文件的文档.
1
13#ifndef __xwos_lib_xwbop_h__
14#define __xwos_lib_xwbop_h__
15
16#include <xwos/standard.h>
17
24#include <xwos/ospl/soc/xwbop.h>
25
26/******** ******** macros ******** ********/
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)
39
40/******** ******** 8-bit 位操作 ******** ********/
41#define xwbop_s1m8(a, mask) *(a) |= (mask)
42#define xwbop_c0m8(a, mask) *(a) &= (~(mask))
43#define xwbop_x1m8(a, mask) *(a) ^= (mask)
44
50
51static __xwlib_inline
53{
54 return x;
55}
56
58
59/******** ******** 16-bit 位操作 ******** ********/
60#define xwbop_s1m16(a, mask) *(a) |= (mask)
61#define xwbop_c0m16(a, mask) *(a) &= (~(mask))
62#define xwbop_x1m16(a, mask) *(a) ^= (mask)
63
71
72/******** ******** 32-bit 位操作 ******** ********/
73#define xwbop_s1m32(a, mask) *(a) |= (mask)
74#define xwbop_c0m32(a, mask) *(a) &= (~(mask))
75#define xwbop_x1m32(a, mask) *(a) ^= (mask)
76
84
85/******** ******** 64-bit 位操作 ******** ********/
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)
89
97
98/******** ******** 位操作 ******** ********/
105#define xwbop(type, op, ...) xwbop_##op##__##type(__VA_ARGS__)
106
113#define xwbop_s1m(type, addr, mask) xwbop(type, s1m, (addr), (mask))
114
121#define xwbop_c0m(type, addr, mask) xwbop(type, c0m, (addr), (mask))
122
129#define xwbop_x1m(type, addr, mask) xwbop(type, x1m, (addr), (mask))
130
137#define xwbop_rbit(type, data) xwbop(type, rbit, (data))
138
145#define xwbop_re(type, data) xwbop(type, re, (data))
146
157#define xwbop_ffs(type, data) xwbop(type, ffs, (data))
158
169#define xwbop_fls(type, data) xwbop(type, fls, (data))
170
181#define xwbop_ffz(type, data) xwbop(type, flz, (data))
182
193#define xwbop_flz(type, data) xwbop(type, flz, (data))
194
201#define xwbop_weight(type, data) xwbop(type, weight, (data))
202
203/******** ******** 位操作模板 ******** ********/
209#define DEFINE_XWBOP_S1M(type, bw) \
210static __xwlib_inline \
211void xwbop_s1m__##type(type * x, type m) \
212{ \
213 xwbop_s1m##bw((xwu##bw##_t *)x, (xwu##bw##_t)m); \
214}
215
221#define DEFINE_XWBOP_C0M(type, bw) \
222static __xwlib_inline \
223void xwbop_c0m__##type(type * x, type m) \
224{ \
225 xwbop_c0m##bw((xwu##bw##_t *)x, (xwu##bw##_t)m); \
226}
227
233#define DEFINE_XWBOP_X1M(type, bw) \
234static __xwlib_inline \
235void xwbop_x1m__##type(type * x, type m) \
236{ \
237 xwbop_x1m##bw((xwu##bw##_t *)x, (xwu##bw##_t)m); \
238}
239
245#define DEFINE_XWBOP_RBIT(type, bw) \
246static __xwlib_inline \
247type xwbop_rbit__##type(type x) \
248{ \
249 return (type)xwbop_rbit##bw((xwu##bw##_t)x); \
250}
251
257#define DEFINE_XWBOP_RE(type, bw) \
258static __xwlib_inline \
259type xwbop_re__##type(type x) \
260{ \
261 return (type)xwbop_re##bw((xwu##bw##_t)x); \
262}
263
269#define DEFINE_XWBOP_FFS(type, bw) \
270static __xwlib_inline \
271xwssq_t xwbop_ffs__##type(type x) \
272{ \
273 return xwbop_ffs##bw((xwu##bw##_t)x); \
274}
275
281#define DEFINE_XWBOP_FLS(type, bw) \
282static __xwlib_inline \
283xwssq_t xwbop_fls__##type(type x) \
284{ \
285 return xwbop_fls##bw((xwu##bw##_t)x); \
286}
287
293#define DEFINE_XWBOP_FLZ(type, bw) \
294static __xwlib_inline \
295xwssq_t xwbop_flz__##type(type x) \
296{ \
297 return xwbop_flz##bw((xwu##bw##_t)x); \
298}
299
305#define DEFINE_XWBOP_FFZ(type, bw) \
306static __xwlib_inline \
307xwssq_t xwbop_ffz__##type(type x) \
308{ \
309 return xwbop_ffz##bw((xwu##bw##_t)x); \
310}
311
317#define DEFINE_XWBOP_WEIGHT(type, bw) \
318static __xwlib_inline \
319xwsq_t xwbop_weight__##type(type x) \
320{ \
321 return xwbop_weight##bw((xwu##bw##_t)x); \
322}
323
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)
340
343
346
349
352
353#if (16 == BITS_PER_XWSZ_T)
355#elif (32 == BITS_PER_XWSZ_T)
357#elif (64 == BITS_PER_XWSZ_T)
359#endif
360
361#if (16 == BITS_PER_XWPTR_T)
363#elif (32 == BITS_PER_XWPTR_T)
365#elif (64 == BITS_PER_XWPTR_T)
367#endif
368
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)
377#endif
378
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)
387#endif
388
389#if (16 == BITS_PER_XWSQ_T)
391#elif (32 == BITS_PER_XWSQ_T)
393#elif (64 == BITS_PER_XWSQ_T)
395#endif
396
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)
405#endif
406
408
409/******** ******** 位图操作 ******** ********/
415#define xwbmpop_define(name, bits) xwbmp_t name[BITS_TO_XWBMP_T(bits)]
416
423void xwbmpop_assign(xwbmp_t * bmp, xwbmp_t opd[], xwsz_t num);
424
435xwssq_t xwbmpop_cmp(xwbmp_t * bmp, xwbmp_t opd[], xwsz_t num);
436
442void xwbmpop_s1all(xwbmp_t * bmp, xwsq_t num);
443
449void xwbmpop_c0all(xwbmp_t * bmp, xwsq_t num);
450
457
464void xwbmpop_s1m(xwbmp_t * bmp, xwbmp_t msk[], xwsz_t num);
465
472
479void xwbmpop_c0m(xwbmp_t * bmp, xwbmp_t msk[], xwsz_t num);
480
487
494void xwbmpop_x1m(xwbmp_t * bmp, xwbmp_t msk[], xwsz_t num);
495
505
515bool xwbmpop_t1ma(xwbmp_t * bmp, xwbmp_t msk[], xwsz_t num);
516
526bool xwbmpop_t1ma_then_c0m(xwbmp_t * bmp, xwbmp_t msk[], xwsz_t num);
527
537bool xwbmpop_t1mo(xwbmp_t * bmp, xwbmp_t msk[], xwsz_t num);
538
548bool xwbmpop_t1mo_then_c0m(xwbmp_t * bmp, xwbmp_t msk[], xwsz_t num);
549
559bool xwbmpop_t0ma(xwbmp_t * bmp, xwbmp_t msk[], xwsz_t num);
560
570bool xwbmpop_t0ma_then_s1m(xwbmp_t * bmp, xwbmp_t msk[], xwsz_t num);
571
581bool xwbmpop_t0mo(xwbmp_t * bmp, xwbmp_t msk[], xwsz_t num);
582
592bool xwbmpop_t0mo_then_s1m(xwbmp_t * bmp, xwbmp_t msk[], xwsz_t num);
593
599void xwbmpop_not(xwbmp_t * bmp, xwsz_t num);
600
607void xwbmpop_and(xwbmp_t * bmp, xwbmp_t opd[], xwsz_t num);
608
615void xwbmpop_or(xwbmp_t * bmp, xwbmp_t opd[], xwsz_t num);
616
623void xwbmpop_xor(xwbmp_t * bmp, xwbmp_t opd[], xwsz_t num);
624
636
648
660
672
680
685#endif /* xwos/lib/xwbop.h */
#define __xwlib_inline
Definition compiler.h:203
xwu64_t xwtk_t
XWOS系统滴答计数 (无符号)
Definition type.h:710
unsigned long xwid_t
Definition type.h:481
unsigned long xwsz_t
Definition type.h:339
uint8_t xwu8_t
Definition type.h:194
unsigned long xwsq_t
Definition type.h:445
int64_t xws64_t
Definition type.h:319
uint64_t xwu64_t
Definition type.h:303
signed long xwssq_t
Definition type.h:461
unsigned long xwptr_t
Definition type.h:375
xwptr_t xwreg_t
Definition type.h:409
uint16_t xwu16_t
Definition type.h:230
uint32_t xwu32_t
Definition type.h:266
int16_t xws16_t
Definition type.h:246
int8_t xws8_t
Definition type.h:210
xwu32_t xwbmp_t
Definition type.h:574
int32_t xws32_t
Definition type.h:283
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)
Definition xwbop.h:52
void xwbmpop_x1m(xwbmp_t *bmp, xwbmp_t msk[], xwsz_t num)
XWOS BOPLIB:将位图中掩码部分翻转
Definition xwbop.c:720
xwu32_t xwbop_re32(xwu32_t x)
void xwbmpop_assign(xwbmp_t *bmp, xwbmp_t opd[], xwsz_t num)
XWOS BOPLIB:赋值操作数到位图
Definition xwbop.c:614
xwssq_t xwbop_flz8(xwu8_t x)
Definition xwbop.c:114
xwssq_t xwbop_ffz8(xwu8_t x)
Definition xwbop.c:106
bool xwbmpop_t0ma_then_s1m(xwbmp_t *bmp, xwbmp_t msk[], xwsz_t num)
XWOS BOPLIB:测试位图中掩码部分是否全部为0,如果是,就将掩码部分全部置1
Definition xwbop.c:841
bool xwbmpop_t1i(xwbmp_t *bmp, xwsq_t n)
XWOS BOPLIB:测试位图中的单个位是否为1
xwsz_t xwbop_weight32(xwu32_t x)
Definition xwbop.c:421
xwu64_t xwbop_re64(xwu64_t x)
bool xwbmpop_t1mo(xwbmp_t *bmp, xwbmp_t msk[], xwsz_t num)
XWOS BOPLIB:测试位图中掩码部分是否至少有一位为1
Definition xwbop.c:782
#define DEFINE_XWBOP(type, bw)
使用模板为类型定义所有的位操作函数
Definition xwbop.h:329
xwsz_t xwbop_weight64(xwu64_t x)
Definition xwbop.c:601
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
Definition xwbop.c:800
void xwbmpop_and(xwbmp_t *bmp, xwbmp_t opd[], xwsz_t num)
XWOS BOPLIB:将位图与操作数进行逐位“与”运算
Definition xwbop.c:917
xwssq_t xwbop_ffz64(xwu64_t x)
Definition xwbop.c:524
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)
Definition xwbop.c:368
xwu16_t xwbop_re16(xwu16_t a)
void xwbmpop_c0all(xwbmp_t *bmp, xwsq_t num)
XWOS BOPLIB:将位图中所有位清0
Definition xwbop.c:658
void xwbmpop_s1m(xwbmp_t *bmp, xwbmp_t msk[], xwsz_t num)
XWOS BOPLIB:将位图中掩码部分置1
Definition xwbop.c:678
bool xwbmpop_t0ma(xwbmp_t *bmp, xwbmp_t msk[], xwsz_t num)
XWOS BOPLIB:测试位图中掩码部分是否全部为0
Definition xwbop.c:823
xwsz_t xwbop_weight16(xwu16_t x)
Definition xwbop.c:267
xwssq_t xwbop_ffz16(xwu16_t x)
Definition xwbop.c:214
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
Definition xwbop.c:647
xwssq_t xwbop_flz16(xwu16_t x)
Definition xwbop.c:222
xwssq_t xwbop_ffs16(xwu16_t x)
xwssq_t xwbop_ffz32(xwu32_t x)
Definition xwbop.c:360
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:将位图按位取反
Definition xwbop.c:905
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:从数组最高元素开始比较两个位图的数值大小
Definition xwbop.c:625
bool xwbmpop_t1ma(xwbmp_t *bmp, xwbmp_t msk[], xwsz_t num)
XWOS BOPLIB:测试位图中掩码部分是否全部为1
Definition xwbop.c:741
void xwbmpop_or(xwbmp_t *bmp, xwbmp_t opd[], xwsz_t num)
XWOS BOPLIB:将位图与操作数进行逐位“或”运算
Definition xwbop.c:929
bool xwbmpop_t0mo_then_s1m(xwbmp_t *bmp, xwbmp_t msk[], xwsz_t num)
XWOS BOPLIB:测试位图中掩码部分是否至少有一位为0,如果是,就将掩码部分全部置1
Definition xwbop.c:882
void xwbmpop_xor(xwbmp_t *bmp, xwbmp_t opd[], xwsz_t num)
XWOS BOPLIB:将位图与操作数进行逐位“异或”运算
Definition xwbop.c:941
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
Definition xwbop.c:759
xwssq_t xwbop_flz64(xwu64_t x)
Definition xwbop.c:532
xwssq_t xwbop_ffs64(xwu64_t x)
xwsz_t xwbop_weight8(xwu8_t x)
Definition xwbop.c:130
xwsz_t xwbmpop_weight(xwbmp_t *bmp, xwsz_t num)
XWOS BOPLIB:在位图中统计被置1的位的个数
Definition xwbop.c:1063
xwssq_t xwbop_fls8(xwu8_t x)
bool xwbmpop_t0mo(xwbmp_t *bmp, xwbmp_t msk[], xwsz_t num)
XWOS BOPLIB:测试位图中掩码部分是否至少有一位为0
Definition xwbop.c:864
void xwbmpop_c0m(xwbmp_t *bmp, xwbmp_t msk[], xwsz_t num)
XWOS BOPLIB:将位图中掩码部分清0
Definition xwbop.c:699
XWOS的标准头文件