XWOS API  4.0
XWOS C/C++ API参考手册
载入中...
搜索中...
未找到
xwbop.c
浏览该文件的文档.
1
13#include <xwos/standard.h>
14#include <xwos/lib/xwbop.h>
15
16#if (!defined(ARCHCFG_LIB_XWBOP_RBIT8)) || (1 != ARCHCFG_LIB_XWBOP_RBIT8)
17# define XWBOP_RBIT8_R2(n) (n), ((n) + 2U * 64U), ((n) + 1U * 64U), ((n) + 3U * 64U)
18# define XWBOP_RBIT8_R4(n) XWBOP_RBIT8_R2(n), \
19 XWBOP_RBIT8_R2((n) + 2U * 16U), \
20 XWBOP_RBIT8_R2((n) + 1U * 16U), \
21 XWBOP_RBIT8_R2((n) + 3U * 16U)
22# define XWBOP_RBIT8_R6(n) XWBOP_RBIT8_R4(n), \
23 XWBOP_RBIT8_R4((n) + 2U * 4U), \
24 XWBOP_RBIT8_R4((n) + 1U * 4U), \
25 XWBOP_RBIT8_R4((n) + 3U * 4U)
26#endif
27
28#if (!defined(ARCHCFG_LIB_XWBOP_RBIT8)) || (1 != ARCHCFG_LIB_XWBOP_RBIT8)
32__xwlib_rodata const xwu8_t xwbop_rbit8_table[256] = {
33 // cppcheck-suppress [misra-c2012-2.2, misra-c2012-12.1]
34 XWBOP_RBIT8_R6(0U), XWBOP_RBIT8_R6(2U), XWBOP_RBIT8_R6(1U), XWBOP_RBIT8_R6(3U),
35};
36#endif
37
38#if (!defined(ARCHCFG_LIB_XWBOP_FFS8)) || (1 != ARCHCFG_LIB_XWBOP_FFS8)
41{
42 xwssq_t r;
43# if defined(__GNUC__)
44 if ((xwu8_t)0 == x) {
45 r = (xwssq_t)-1;
46 } else {
47 r = (xwssq_t)__builtin_ffs((int)x) - (xwssq_t)1;
48 }
49# else
50 r = (xwssq_t)0;
51 if (0 == x) {
52 r = (xwssq_t)-1;
53 } else {
54 if (0 == (x & (xwu8_t)0x0F)) {
55 x >>= (xwu8_t)4;
56 r += (xwssq_t)4;
57 }
58 if (0 == (x & (xwu8_t)0x03)) {
59 x >>= (xwu8_t)2;
60 r += (xwssq_t)2;
61 }
62 if (0 == (x & (xwu8_t)0x01)) {
63 r += (xwssq_t)1;
64 }
65 }
66# endif
67 return r;
68}
69#endif
70
71#if ((!defined(ARCHCFG_LIB_XWBOP_FLS8)) || (1 != ARCHCFG_LIB_XWBOP_FLS8))
74{
75 xwssq_t r;
76# if defined(__GNUC__)
77 if ((xwu8_t)0 == x) {
78 r = (xwssq_t)-1;
79 } else {
80 r = (xwssq_t)7 - (xwssq_t)__builtin_clz((unsigned int)x);
81 }
82# else
83 r = (xwssq_t)7;
84 if (0 == x) {
85 r = (xwssq_t)-1;
86 } else {
87 if (0 == (x & (xwu8_t)0xF0)) {
88 x <<= (xwu8_t)4;
89 r -= (xwssq_t)4;
90 }
91 if (0 == (x & (xwu8_t)0xC0)) {
92 x <<= (xwu8_t)2;
93 r -= (xwssq_t)2;
94 }
95 if (0 == (x & (xwu8_t)0x80)) {
96 r -= (xwssq_t)1;
97 }
98 }
99# endif
100 return r;
101}
102#endif
103
104#if ((!defined(ARCHCFG_LIB_XWBOP_FFZ8)) || (1 != ARCHCFG_LIB_XWBOP_FFZ8))
107{
108 return xwbop_ffs8((xwu8_t)(~x));
109}
110#endif
111
112#if (!defined(ARCHCFG_LIB_XWBOP_FLZ8)) || (1 != ARCHCFG_LIB_XWBOP_FLZ8)
115{
116 return xwbop_fls8((xwu8_t)(~x));
117}
118#endif
119
120#if (!defined(ARCHCFG_LIB_XWBOP_RBIT8)) || (1 != ARCHCFG_LIB_XWBOP_RBIT8)
123{
124 return xwbop_rbit8_table[x];
125}
126#endif
127
128#if (!defined(ARCHCFG_LIB_XWBOP_WEIGHT8)) || (1 != ARCHCFG_LIB_XWBOP_WEIGHT8)
131{
132 xwu8_t res = x - ((x >> (xwu8_t)1) & (xwu8_t)0x55);
133 res = (res & (xwu8_t)0x33) + ((res >> (xwu8_t)2) & (xwu8_t)0x33);
134 return (res + (res >> (xwu8_t)4)) & (xwu8_t)0x0F;
135}
136#endif
137
138#if (!defined(ARCHCFG_LIB_XWBOP_FFS16)) || (1 != ARCHCFG_LIB_XWBOP_FFS16)
141{
142 xwssq_t r;
143# if defined(__GNUC__)
144 if ((xwu16_t)0 == x) {
145 r = (xwssq_t)-1;
146 } else {
147 r = (xwssq_t)__builtin_ffs((int)x) - (xwssq_t)1;
148 }
149# else
150 r = (xwssq_t)0;
151 if (0 == x) {
152 r = (xwssq_t)-1;
153 } else {
154 if (0 == (x & (xwu16_t)0x00FF)) {
155 x >>= (xwu16_t)8;
156 r += (xwssq_t)8;
157 }
158 if (0 == (x & (xwu16_t)0x000F)) {
159 x >>= (xwu16_t)4;
160 r += (xwssq_t)4;
161 }
162 if (0 == (x & (xwu16_t)0x0003)) {
163 x >>= (xwu16_t)2;
164 r += (xwssq_t)2;
165 }
166 if (0 == (x & (xwu16_t)0x0001)) {
167 r += (xwssq_t)1;
168 }
169 }
170# endif
171 return r;
172}
173#endif
174
175#if ((!defined(ARCHCFG_LIB_XWBOP_FLS16)) || (1 != ARCHCFG_LIB_XWBOP_FLS16))
178{
179 xwssq_t r;
180# if defined(__GNUC__)
181 if ((xwu16_t)0 == x) {
182 r = (xwssq_t)-1;
183 } else {
184 r = (xwssq_t)15 - (xwssq_t)__builtin_clz((unsigned int)x);
185 }
186# else
187 r = (xwssq_t)15;
188 if (0 == x) {
189 r = (xwssq_t)-1;
190 } else {
191 if (0 == (x & (xwu16_t)0xFF00)) {
192 x <<= (xwu16_t)8;
193 r -= (xwssq_t)8;
194 }
195 if (0 == (x & (xwu16_t)0xF000)) {
196 x <<= (xwu16_t)4;
197 r -= (xwssq_t)4;
198 }
199 if (0 == (x & (xwu16_t)0xC000)) {
200 x <<= (xwu16_t)2;
201 r -= (xwssq_t)2;
202 }
203 if (0 == (x & (xwu16_t)0x8000)) {
204 r -= (xwssq_t)1;
205 }
206 }
207# endif
208 return r;
209}
210#endif
211
212#if ((!defined(ARCHCFG_LIB_XWBOP_FFZ16)) || (1 != ARCHCFG_LIB_XWBOP_FFZ16))
215{
216 return xwbop_ffs16((xwu16_t)(~x));
217}
218#endif
219
220#if ((!defined(ARCHCFG_LIB_XWBOP_FLZ16)) || (1 != ARCHCFG_LIB_XWBOP_FLZ16))
223{
224 return xwbop_fls16((xwu16_t)(~x));
225}
226#endif
227
228#if (!defined(ARCHCFG_LIB_XWBOP_RBIT16)) || (1 != ARCHCFG_LIB_XWBOP_RBIT16)
231{
232 union {
233 xwu16_t d16;
234 struct {
235 xwu8_t h;
236 xwu8_t l;
237 } d8;
238 } r, t; // cppcheck-suppress [misra-c2012-12.3]
239
240 t.d16 = x;
241 r.d8.h = xwbop_rbit8(t.d8.l);
242 r.d8.l = xwbop_rbit8(t.d8.h);
243 return r.d16;
244}
245#endif
246
247#if (!defined(ARCHCFG_LIB_XWBOP_RE16)) || (1 != ARCHCFG_LIB_XWBOP_RE16)
250{
251 union {
252 xwu16_t d16;
253 struct {
254 xwu8_t byte0;
255 xwu8_t byte1;
256 } d8;
257 } r;
258
259 r.d8.byte0 = (xwu8_t)(x >> (xwu16_t)8);
260 r.d8.byte1 = (xwu8_t)(x >> (xwu16_t)0);
261 return r.d16;
262}
263#endif
264
265#if (!defined(ARCHCFG_LIB_XWBOP_WEIGHT16)) || (1 != ARCHCFG_LIB_XWBOP_WEIGHT16)
268{
269 xwu16_t res = x - ((x >> (xwu16_t)1) & (xwu16_t)0x5555);
270 res = (res & (xwu16_t)0x3333) + ((res >> (xwu16_t)2) & (xwu16_t)0x3333);
271 res = (res + (res >> (xwu16_t)4)) & (xwu16_t)0x0F0F;
272 return (res + (res >> (xwu16_t)8)) & (xwu16_t)0x00FF;
273}
274#endif
275
276#if (!defined(ARCHCFG_LIB_XWBOP_FFS32)) || (1 != ARCHCFG_LIB_XWBOP_FFS32)
279{
280 xwssq_t r;
281# if defined(__GNUC__)
282 if ((xwu32_t)0 == x) {
283 r = (xwssq_t)-1;
284 } else {
285 r = (xwssq_t)__builtin_ffs((int)x) - (xwssq_t)1;
286 }
287# else
288 r = (xwssq_t)0;
289 if (0 == x) {
290 r = (xwssq_t)-1;
291 } else {
292 if (0 == (x & (xwu32_t)0x0000FFFF)) {
293 x >>= (xwu32_t)16;
294 r += (xwssq_t)16;
295 }
296 if (0 == (x & (xwu32_t)0x000000FF)) {
297 x >>= (xwu32_t)8;
298 r += (xwssq_t)8;
299 }
300 if (0 == (x & (xwu32_t)0x0000000F)) {
301 x >>= (xwu32_t)4;
302 r += (xwssq_t)4;
303 }
304 if (0 == (x & (xwu32_t)0x00000003)) {
305 x >>= (xwu32_t)2;
306 r += (xwssq_t)2;
307 }
308 if (0 == (x & (xwu32_t)0x00000001)) {
309 r += (xwssq_t)1;
310 }
311 }
312# endif
313 return r;
314}
315#endif
316
317#if ((!defined(ARCHCFG_LIB_XWBOP_FLS32)) || (1 != ARCHCFG_LIB_XWBOP_FLS32))
320{
321 xwssq_t r;
322# if defined(__GNUC__)
323 if ((xwu32_t)0 == x) {
324 r = (xwssq_t)-1;
325 } else {
326 r = (xwssq_t)31 - (xwssq_t)__builtin_clz((unsigned int)x);
327 }
328# else
329 r = (xwssq_t)31;
330 if (0 == x) {
331 r = (xwssq_t)-1;
332 } else {
333 if (0 == (x & (xwu32_t)0xFFFF0000)) {
334 x <<= (xwu32_t)16;
335 r -= (xwssq_t)16;
336 }
337 if (0 == (x & (xwu32_t)0xFF000000)) {
338 x <<= (xwu32_t)8;
339 r -= (xwssq_t)8;
340 }
341 if (0 == (x & (xwu32_t)0xF0000000)) {
342 x <<= (xwu32_t)4;
343 r -= (xwssq_t)4;
344 }
345 if (0 == (x & (xwu32_t)0xC0000000)) {
346 x <<= (xwu32_t)2;
347 r -= (xwssq_t)2;
348 }
349 if (0 == (x & (xwu32_t)0x80000000)) {
350 r -= (xwssq_t)1;
351 }
352 }
353# endif
354 return r;
355}
356#endif
357
358#if ((!defined(ARCHCFG_LIB_XWBOP_FFZ32)) || (1 != ARCHCFG_LIB_XWBOP_FFZ32))
361{
362 return xwbop_ffs32(~x);
363}
364#endif
365
366#if ((!defined(ARCHCFG_LIB_XWBOP_FLZ32)) || (1 != ARCHCFG_LIB_XWBOP_FLZ32))
369{
370 return xwbop_fls32(~x);
371}
372#endif
373
374#if (!defined(ARCHCFG_LIB_XWBOP_RBIT32)) || (1 != ARCHCFG_LIB_XWBOP_RBIT32)
377{
378 union {
379 xwu32_t d32;
380 struct {
381 xwu8_t byte0;
382 xwu8_t byte1;
383 xwu8_t byte2;
384 xwu8_t byte3;
385 } d8;
386 } r, t; // cppcheck-suppress [misra-c2012-12.3]
387
388 t.d32 = x;
389 r.d8.byte0 = xwbop_rbit8(t.d8.byte3);
390 r.d8.byte1 = xwbop_rbit8(t.d8.byte2);
391 r.d8.byte2 = xwbop_rbit8(t.d8.byte1);
392 r.d8.byte3 = xwbop_rbit8(t.d8.byte0);
393 return r.d32;
394}
395#endif
396
397#if (!defined(ARCHCFG_LIB_XWBOP_RE32)) || (1 != ARCHCFG_LIB_XWBOP_RE32)
400{
401 union {
402 xwu32_t d32;
403 struct {
404 xwu8_t byte0;
405 xwu8_t byte1;
406 xwu8_t byte2;
407 xwu8_t byte3;
408 } d8;
409 } r;
410
411 r.d8.byte0 = (xwu8_t)(x >> (xwu32_t)24);
412 r.d8.byte1 = (xwu8_t)(x >> (xwu32_t)16);
413 r.d8.byte2 = (xwu8_t)(x >> (xwu32_t)8);
414 r.d8.byte3 = (xwu8_t)(x >> (xwu32_t)0);
415 return r.d32;
416}
417#endif
418
419#if (!defined(ARCHCFG_LIB_XWBOP_WEIGHT32)) || (1 != ARCHCFG_LIB_XWBOP_WEIGHT32)
422{
423 xwu32_t res = x - ((x >> (xwu32_t)1) & (xwu32_t)0x55555555);
424 res = (res & (xwu32_t)0x33333333) + ((res >> (xwu32_t)2) & (xwu32_t)0x33333333);
425 res = (res + (res >> (xwu32_t)4)) & (xwu32_t)0x0F0F0F0F;
426 res = res + (res >> (xwu32_t)8);
427 return (res + (res >> (xwu32_t)16)) & (xwu32_t)0x000000FF;
428}
429#endif
430
431#if ((!defined(ARCHCFG_LIB_XWBOP_FFS64)) || (1 != ARCHCFG_LIB_XWBOP_FFS64))
434{
435 xwssq_t r;
436# if defined(__GNUC__)
437 if ((xwu64_t)0 == x) {
438 r = (xwssq_t)-1;
439 } else {
440 r = (xwssq_t)__builtin_ffsll((long long)x) - (xwssq_t)1;
441 }
442# else
443 r = (xwssq_t)0;
444 if (0 == x) {
445 r = (xwssq_t)-1;
446 } else {
447 if (0 == (x & (xwu64_t)0xFFFFFFFF)) {
448 x >>= (xwu64_t)32;
449 r += (xwssq_t)32;
450 }
451 if (0 == (x & (xwu64_t)0xFFFF)) {
452 x >>= (xwu64_t)16;
453 r += (xwssq_t)16;
454 }
455 if (0 == (x & (xwu64_t)0xFF)) {
456 x >>= (xwu64_t)8;
457 r += (xwssq_t)8;
458 }
459 if (0 == (x & (xwu64_t)0xF)) {
460 x >>= (xwu64_t)4;
461 r += (xwssq_t)4;
462 }
463 if (0 == (x & (xwu64_t)0x3)) {
464 x >>= (xwu64_t)2;
465 r += (xwssq_t)2;
466 }
467 if (0 == (x & (xwu64_t)0x1)) {
468 r += (xwssq_t)1;
469 }
470 }
471# endif
472 return r;
473}
474#endif
475
476#if (!defined(ARCHCFG_LIB_XWBOP_FLS64)) || (1 != ARCHCFG_LIB_XWBOP_FLS64)
479{
480 xwssq_t r;
481# if defined(__GNUC__)
482 if (0 == x) {
483 r = (xwssq_t)-1;
484 } else {
485 r = (xwssq_t)63 - (xwssq_t)__builtin_clzll((unsigned long long)x);
486 }
487# else
488 r = (xwssq_t)63;
489 if (0 == x) {
490 r = (xwssq_t)-1;
491 } else {
492 if (0 == (x & (xwu64_t)0xFFFFFFFF00000000)) {
493 r -= (xwssq_t)32;
494 } else {
495 x >>= (xwu64_t)32;
496 }
497 if (0 == (x & (xwu64_t)0xFFFF0000)) {
498 x <<= (xwu64_t)16;
499 r -= (xwssq_t)16;
500 }
501 if (0 == (x & (xwu64_t)0xFF000000)) {
502 x <<= (xwu64_t)8;
503 r -= (xwssq_t)8;
504 }
505 if (0 == (x & (xwu64_t)0xF0000000)) {
506 x <<= (xwu64_t)4;
507 r -= (xwssq_t)4;
508 }
509 if (0 == (x & (xwu64_t)0xC0000000)) {
510 x <<= (xwu64_t)2;
511 r -= (xwssq_t)2;
512 }
513 if (0 == (x & (xwu64_t)0x80000000)) {
514 r -= (xwssq_t)1;
515 }
516 }
517# endif
518 return r;
519}
520#endif
521
522#if ((!defined(ARCHCFG_LIB_XWBOP_FFZ64)) || (1 != ARCHCFG_LIB_XWBOP_FFZ64))
525{
526 return xwbop_ffs64(~x);
527}
528#endif
529
530#if ((!defined(ARCHCFG_LIB_XWBOP_FLZ64)) || (1 != ARCHCFG_LIB_XWBOP_FLZ64))
533{
534 return xwbop_ffs64(~x);
535}
536#endif
537
538#if (!defined(ARCHCFG_LIB_XWBOP_RBIT64)) || (1 != ARCHCFG_LIB_XWBOP_RBIT64)
541{
542 union {
543 xwu64_t d64;
544 struct {
545 xwu8_t byte0;
546 xwu8_t byte1;
547 xwu8_t byte2;
548 xwu8_t byte3;
549 xwu8_t byte4;
550 xwu8_t byte5;
551 xwu8_t byte6;
552 xwu8_t byte7;
553 } d8;
554 } r, t; // cppcheck-suppress [misra-c2012-12.3]
555
556 t.d64 = x;
557 r.d8.byte0 = xwbop_rbit8(t.d8.byte7);
558 r.d8.byte1 = xwbop_rbit8(t.d8.byte6);
559 r.d8.byte2 = xwbop_rbit8(t.d8.byte5);
560 r.d8.byte3 = xwbop_rbit8(t.d8.byte4);
561 r.d8.byte4 = xwbop_rbit8(t.d8.byte3);
562 r.d8.byte5 = xwbop_rbit8(t.d8.byte2);
563 r.d8.byte6 = xwbop_rbit8(t.d8.byte1);
564 r.d8.byte7 = xwbop_rbit8(t.d8.byte0);
565 return r.d64;
566}
567#endif
568
569#if (!defined(ARCHCFG_LIB_XWBOP_RE64)) || (1 != ARCHCFG_LIB_XWBOP_RE64)
572{
573 union {
574 xwu64_t d64;
575 struct {
576 xwu8_t byte0;
577 xwu8_t byte1;
578 xwu8_t byte2;
579 xwu8_t byte3;
580 xwu8_t byte4;
581 xwu8_t byte5;
582 xwu8_t byte6;
583 xwu8_t byte7;
584 } d8;
585 } r;
586
587 r.d8.byte0 = (xwu8_t)(x >> (xwu64_t)56);
588 r.d8.byte1 = (xwu8_t)(x >> (xwu64_t)48);
589 r.d8.byte2 = (xwu8_t)(x >> (xwu64_t)40);
590 r.d8.byte3 = (xwu8_t)(x >> (xwu64_t)32);
591 r.d8.byte4 = (xwu8_t)(x >> (xwu64_t)24);
592 r.d8.byte5 = (xwu8_t)(x >> (xwu64_t)16);
593 r.d8.byte6 = (xwu8_t)(x >> (xwu64_t)8);
594 r.d8.byte7 = (xwu8_t)(x >> (xwu64_t)0);
595 return r.d64;
596}
597#endif
598
599#if (!defined(ARCHCFG_LIB_XWBOP_WEIGHT64)) || (1 != ARCHCFG_LIB_XWBOP_WEIGHT64)
602{
603 xwu64_t res = x - ((x >> (xwu64_t)1) & (xwu64_t)0x5555555555555555);
604 res = (res & (xwu64_t)0x3333333333333333) +
605 ((res >> (xwu64_t)2) & (xwu64_t)0x3333333333333333);
606 res = (res + (res >> (xwu64_t)4)) & (xwu64_t)0x0F0F0F0F0F0F0F0F;
607 res = res + (res >> (xwu64_t)8);
608 res = res + (res >> (xwu64_t)16);
609 return (res + (res >> (xwu64_t)32)) & (xwu64_t)0x00000000000000FF;
610}
611#endif
612
614void xwbmpop_assign(xwbmp_t * bmp, xwbmp_t opd[], xwsz_t num)
615{
616 xwsz_t n = BITS_TO_XWBMP_T(num);
617 xwsz_t i;
618
619 for (i = 0; i < n; i++) {
620 bmp[i] = opd[i];
621 }
622}
623
626{
627 xwsz_t n = BITS_TO_XWBMP_T(num);
628 xwsz_t i;
629 xwsz_t j;
630 xwssq_t ret;
631
632 ret = 0;
633 for (j = n; j > (xwsz_t)0; j--) { // cppcheck-suppress [misra-c2012-15.4]
634 i = j - (xwsz_t)1;
635 if (bmp[i] < opd[i]) {
636 ret = -1;
637 break;
638 } else if (bmp[i] > opd[i]) {
639 ret = 1;
640 break;
641 } else {}
642 }
643 return ret;
644}
645
648{
649 xwsz_t n = BITS_TO_XWBMP_T(num);
650 xwsz_t i;
651
652 for (i = 0; i < n; i++) {
653 xwbop_s1m(xwbmp_t, &bmp[i], (~(xwbmp_t)0));
654 }
655}
656
659{
660 xwsz_t n = BITS_TO_XWBMP_T(num);
661 xwsz_t i;
662
663 for (i = 0; i < n; i++) {
664 xwbop_c0m(xwbmp_t, &bmp[i], (~(xwbmp_t)0));
665 }
666}
667
668#if (!defined(ARCHCFG_LIB_XWBMPOP_S1I)) || (1 != ARCHCFG_LIB_XWBMPOP_S1I)
670void xwbmpop_s1i(xwbmp_t * bmp, xwsq_t n)
671{
672 bmp = bmp + XWBOP_BMP(n);
674}
675#endif
676
678void xwbmpop_s1m(xwbmp_t * bmp, xwbmp_t msk[], xwsz_t num)
679{
680 xwsq_t i;
681 xwsz_t size;
682
683 size = BITS_TO_XWBMP_T(num);
684 for (i = 0; i < size; i++) {
685 xwbop_s1m(xwbmp_t, &bmp[i], msk[i]);
686 }
687}
688
689#if (!defined(ARCHCFG_LIB_XWBMPOP_C0I)) || (1 != ARCHCFG_LIB_XWBMPOP_C0I)
691void xwbmpop_c0i(xwbmp_t * bmp, xwsq_t n)
692{
693 bmp = bmp + XWBOP_BMP(n);
695}
696#endif
697
699void xwbmpop_c0m(xwbmp_t * bmp, xwbmp_t msk[], xwsz_t num)
700{
701 xwsq_t i;
702 xwsz_t size;
703
704 size = BITS_TO_XWBMP_T(num);
705 for (i = 0; i < size; i++) {
706 xwbop_c0m(xwbmp_t, &bmp[i], msk[i]);
707 }
708}
709
710#if (!defined(ARCHCFG_LIB_XWBMPOP_X1I)) || (1 != ARCHCFG_LIB_XWBMPOP_X1I)
712void xwbmpop_x1i(xwbmp_t * bmp, xwsq_t n)
713{
714 bmp = bmp + XWBOP_BMP(n);
716}
717#endif
718
720void xwbmpop_x1m(xwbmp_t * bmp, xwbmp_t msk[], xwsz_t num)
721{
722 xwsq_t i;
723 xwsz_t size;
724
725 size = BITS_TO_XWBMP_T(num);
726 for (i = 0; i < size; i++) {
727 xwbop_x1m(xwbmp_t, &bmp[i], msk[i]);
728 }
729}
730
731#if (!defined(ARCHCFG_LIB_XWBMPOP_T1I)) || (1 != ARCHCFG_LIB_XWBMPOP_T1I)
733bool xwbmpop_t1i(xwbmp_t * bmp, xwsq_t n)
734{
735 bmp = bmp + XWBOP_BMP(n);
736 return (bool)(*bmp & XWBOP_BMP_MASK(n));
737}
738#endif
739
741bool xwbmpop_t1ma(xwbmp_t * bmp, xwbmp_t msk[], xwsz_t num)
742{
743 xwsq_t i;
744 xwsz_t size;
745 bool ret;
746
747 size = BITS_TO_XWBMP_T(num);
748 ret = false;
749 for (i = 0; i < size; i++) {
750 ret = !!((bmp[i] & msk[i]) == msk[i]);
751 if (!ret) {
752 break;
753 }
754 }
755 return ret;
756}
757
760{
761 xwsq_t i;
762 xwsz_t size;
763 bool ret;
764
765 size = BITS_TO_XWBMP_T(num);
766 ret = false;
767 for (i = 0; i < size; i++) {
768 ret = !!((bmp[i] & msk[i]) == msk[i]);
769 if (!ret) {
770 break;
771 }
772 }
773 if (ret) {
774 for (i = 0; i < size; i++) {
775 xwbop_c0m(xwbmp_t, &bmp[i], msk[i]);
776 }
777 }
778 return ret;
779}
780
782bool xwbmpop_t1mo(xwbmp_t * bmp, xwbmp_t msk[], xwsz_t num)
783{
784 xwsq_t i;
785 xwsz_t size;
786 bool ret;
787
788 size = BITS_TO_XWBMP_T(num);
789 ret = false;
790 for (i = 0; i < size; i++) {
791 ret = !!(bmp[i] & msk[i]);
792 if (ret) {
793 break;
794 }
795 }
796 return ret;
797}
798
801{
802 xwsq_t i;
803 xwsz_t size;
804 bool ret;
805
806 size = BITS_TO_XWBMP_T(num);
807 ret = false;
808 for (i = 0; i < size; i++) {
809 ret = !!(bmp[i] & msk[i]);
810 if (ret) {
811 break;
812 }
813 }
814 if (ret) {
815 for (i = 0; i < size; i++) {
816 xwbop_c0m(xwbmp_t, &bmp[i], msk[i]);
817 }
818 }
819 return ret;
820}
821
823bool xwbmpop_t0ma(xwbmp_t * bmp, xwbmp_t msk[], xwsz_t num)
824{
825 xwsq_t i;
826 xwsz_t size;
827 bool ret;
828
829 size = BITS_TO_XWBMP_T(num);
830 ret = false;
831 for (i = 0; i < size; i++) {
832 ret = !(bmp[i] & msk[i]);
833 if (!ret) {
834 break;
835 }
836 }
837 return ret;
838}
839
842{
843 xwsq_t i;
844 xwsz_t size;
845 bool ret;
846
847 size = BITS_TO_XWBMP_T(num);
848 ret = false;
849 for (i = 0; i < size; i++) {
850 ret = !(bmp[i] & msk[i]);
851 if (!ret) {
852 break;
853 }
854 }
855 if (ret) {
856 for (i = 0; i < size; i++) {
857 xwbop_s1m(xwbmp_t, &bmp[i], msk[i]);
858 }
859 }
860 return ret;
861}
862
864bool xwbmpop_t0mo(xwbmp_t * bmp, xwbmp_t msk[], xwsz_t num)
865{
866 xwsq_t i;
867 xwsz_t size;
868 bool ret;
869
870 size = BITS_TO_XWBMP_T(num);
871 ret = false;
872 for (i = 0; i < size; i++) {
873 ret = !!((bmp[i] & msk[i]) != msk[i]);
874 if (ret) {
875 break;
876 }
877 }
878 return ret;
879}
880
883{
884 xwsq_t i;
885 xwsz_t size;
886 bool ret;
887
888 size = BITS_TO_XWBMP_T(num);
889 ret = false;
890 for (i = 0; i < size; i++) {
891 ret = !!((bmp[i] & msk[i]) != msk[i]);
892 if (ret) {
893 break;
894 }
895 }
896 if (ret) {
897 for (i = 0; i < size; i++) {
898 xwbop_s1m(xwbmp_t, &bmp[i], msk[i]);
899 }
900 }
901 return ret;
902}
903
905void xwbmpop_not(xwbmp_t * bmp, xwsz_t num)
906{
907 xwsq_t i;
908 xwsz_t size;
909
910 size = BITS_TO_XWBMP_T(num);
911 for (i = 0; i < size; i++) {
912 bmp[i] = ~bmp[i];
913 }
914}
915
917void xwbmpop_and(xwbmp_t * bmp, xwbmp_t opd[], xwsz_t num)
918{
919 xwsq_t i;
920 xwsz_t size;
921
922 size = BITS_TO_XWBMP_T(num);
923 for (i = 0; i < size; i++) {
924 bmp[i] &= opd[i];
925 }
926}
927
929void xwbmpop_or(xwbmp_t * bmp, xwbmp_t opd[], xwsz_t num)
930{
931 xwsq_t i;
932 xwsz_t size;
933
934 size = BITS_TO_XWBMP_T(num);
935 for (i = 0; i < size; i++) {
936 bmp[i] |= opd[i];
937 }
938}
939
941void xwbmpop_xor(xwbmp_t * bmp, xwbmp_t opd[], xwsz_t num)
942{
943 xwsq_t i;
944 xwsz_t size;
945
946 size = BITS_TO_XWBMP_T(num);
947 for (i = 0; i < size; i++) {
948 bmp[i] ^= opd[i];
949 }
950}
951
952#if (!defined(ARCHCFG_LIB_XWBMPOP_FFS)) || (1 != ARCHCFG_LIB_XWBMPOP_FFS)
955{
956 xwsz_t m = BITS_TO_XWBMP_T(num);
957 xwsz_t i;
958 xwbmp_t msk;
959 xwssq_t p = -1;
960
961 for (i = 0; i < m; i++) {
962 if (i == (m - 1)) {
963 msk = (XWBOP_BIT(num % BITS_PER_XWBMP_T) - (xwbmp_t)1);
964 if ((xwbmp_t)0 == msk) {
965 msk = (xwbmp_t)(~(xwbmp_t)0);
966 }
967 } else {
968 msk = (xwbmp_t)(~(xwbmp_t)0);
969 }
970 p = xwbop_ffs(xwbmp_t, bmp[i] & msk);
971 if (p >= 0) {
972 break;
973 }
974 }
975 if (p >= 0) {
976 p += ((xwssq_t)i << XWBMP_T_SHIFT); /* p = p + i * BITS_PER_XWBMP_T; */
977 }
978 return p;
979}
980#endif
981
982#if (!defined(ARCHCFG_LIB_XWBMPOP_FFZ)) || (1 != ARCHCFG_LIB_XWBMPOP_FFZ)
985{
986 xwsz_t m = BITS_TO_XWBMP_T(num);
987 xwsz_t i;
988 xwbmp_t msk;
989 xwssq_t p = -1;
990
991 for (i = 0; i < m; i++) {
992 if (i == (m - 1)) {
993 msk = ~(XWBOP_BIT(num % BITS_PER_XWBMP_T) - (xwbmp_t)1);
994 if ((xwbmp_t)(~(xwbmp_t)0) == msk) {
995 msk = (xwbmp_t)0;
996 }
997 } else {
998 msk = (xwbmp_t)0;
999 }
1000 p = xwbop_ffz(xwbmp_t, bmp[i] | msk);
1001 if (p >= 0) {
1002 break;
1003 }
1004 }
1005 if (p >= 0) {
1006 p += ((xwssq_t)i << XWBMP_T_SHIFT); /* p = p + i * BITS_PER_XWBMP_T; */
1007 }
1008 return p;
1009}
1010#endif
1011
1012#if (!defined(ARCHCFG_LIB_XWBMPOP_FLS)) || (1 != ARCHCFG_LIB_XWBMPOP_FLS)
1015{
1016 xwsz_t i = BITS_TO_XWBMP_T(num);
1017 xwbmp_t msk;
1018 xwssq_t p = -1;
1019
1020 msk = (XWBOP_BIT(num % BITS_PER_XWBMP_T) - (xwbmp_t)1);
1021 if ((xwbmp_t)0 == msk) {
1022 msk = (xwbmp_t)(~(xwbmp_t)0);
1023 }
1024 while (i > 0) {
1025 i--;
1026 p = xwbop_fls(xwbmp_t, bmp[i] & msk);
1027 if (p >= 0) {
1028 break;
1029 }
1030 msk = (xwbmp_t)(~(xwbmp_t)0);
1031 }
1032 p += ((xwssq_t)i << XWBMP_T_SHIFT); /* p = p + i * BITS_PER_XWBMP_T; */
1033 return p;
1034}
1035#endif
1036
1037#if (!defined(ARCHCFG_LIB_XWBMPOP_FLZ)) || (1 != ARCHCFG_LIB_XWBMPOP_FLZ)
1040{
1041 xwsz_t i = BITS_TO_XWBMP_T(num);
1042 xwbmp_t msk;
1043 xwssq_t p = -1;
1044
1045 msk = ~(XWBOP_BIT(num % BITS_PER_XWBMP_T) - (xwbmp_t)1);
1046 if ((xwbmp_t)(~(xwbmp_t)0) == msk) {
1047 msk = (xwbmp_t)0;
1048 }
1049 while (i > 0) {
1050 i--;
1051 p = xwbop_flz(xwbmp_t, bmp[i] | msk);
1052 if (p >= 0) {
1053 break;
1054 }
1055 msk = (xwbmp_t)0;
1056 }
1057 p += ((xwssq_t)i << XWBMP_T_SHIFT); /* p = p + i * BITS_PER_XWBMP_T; */
1058 return p;
1059}
1060#endif
1061
1064{
1065 xwsz_t i;
1066 xwsz_t n;
1067 xwsz_t res;
1068
1069 res = 0;
1070 n = BITS_TO_XWBMP_T(num);
1071 for (i = 0; i < n; i++) {
1072 res += xwbop_weight(xwbmp_t, bmp[i]);
1073 }
1074 return res;
1075}
#define __xwlib_rodata
Definition compiler.h:211
#define __xwlib_code
Definition compiler.h:199
unsigned long xwsz_t
Definition type.h:339
uint8_t xwu8_t
Definition type.h:194
unsigned long xwsq_t
Definition type.h:445
#define XWBMP_T_SHIFT
Definition type.h:583
#define BITS_PER_XWBMP_T
Definition type.h:580
uint64_t xwu64_t
Definition type.h:303
signed long xwssq_t
Definition type.h:461
uint16_t xwu16_t
Definition type.h:230
uint32_t xwu32_t
Definition type.h:266
xwu32_t xwbmp_t
Definition type.h:574
#define XWBOP_BMP(n)
Definition xwbop.h:29
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)
void xwbmpop_x1m(xwbmp_t *bmp, xwbmp_t msk[], xwsz_t num)
XWOS BOPLIB:将位图中掩码部分翻转
Definition xwbop.c:720
#define xwbop_x1m(type, addr, mask)
XWOS BOPLIB:将数据掩码部分的位全部翻转
Definition xwbop.h:129
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
#define xwbop_fls(type, data)
XWOS BOPLIB:在数据中从最高位起查找第一个被置1的位
Definition xwbop.h:169
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)
#define xwbop_weight(type, data)
XWOS BOPLIB:统计数据中1的个数
Definition xwbop.h:201
bool xwbmpop_t1mo(xwbmp_t *bmp, xwbmp_t msk[], xwsz_t num)
XWOS BOPLIB:测试位图中掩码部分是否至少有一位为1
Definition xwbop.c:782
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
#define BITS_TO_XWBMP_T(n)
Definition xwbop.h:35
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
#define xwbop_flz(type, data)
XWOS BOPLIB:在数据中从最高位起查找第一个被清0的位
Definition xwbop.h:193
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
#define xwbop_c0m(type, addr, mask)
XWOS BOPLIB:将数据掩码部分的位全部清0
Definition xwbop.h:121
void xwbmpop_s1all(xwbmp_t *bmp, xwsq_t num)
XWOS BOPLIB:将位图中所有位置1
Definition xwbop.c:647
#define XWBOP_BIT(n)
Definition xwbop.h:27
#define xwbop_s1m(type, addr, mask)
XWOS BOPLIB:将数据掩码部分的位全部置1
Definition xwbop.h:113
#define xwbop_ffz(type, data)
XWOS BOPLIB:在数据中从最低位起查找第一个被清0的位
Definition xwbop.h:181
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
#define XWBOP_BMP_MASK(n)
Definition xwbop.h:28
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的位
#define xwbop_ffs(type, data)
XWOS BOPLIB:在数据中从最低位起查找第一个被置1的位
Definition xwbop.h:157
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通用库:位操作
XWOS的标准头文件