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, const 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
625xwssq_t xwbmpop_cmp(xwbmp_t * bmp, const xwbmp_t opd[], xwsz_t num)
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, const 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, const 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, const 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
733{
734 bmp = bmp + XWBOP_BMP(n);
735 return !!(*bmp & XWBOP_BMP_MASK(n));
736}
737
740{
741 bmp = bmp + XWBOP_BMP(n);
742 return !(*bmp & XWBOP_BMP_MASK(n));
743}
744
746bool xwbmpop_t1ma(xwbmp_t * bmp, const xwbmp_t msk[], xwsz_t num)
747{
748 xwsq_t i;
749 xwsz_t size;
750 bool ret;
751
752 size = BITS_TO_XWBMP_T(num);
753 ret = false;
754 for (i = 0; i < size; i++) {
755 ret = !!((bmp[i] & msk[i]) == msk[i]);
756 if (!ret) {
757 break;
758 }
759 }
760 return ret;
761}
762
764bool xwbmpop_t1ma_then_c0m(xwbmp_t * bmp, const xwbmp_t msk[], xwsz_t num)
765{
766 xwsq_t i;
767 xwsz_t size;
768 bool ret;
769
770 size = BITS_TO_XWBMP_T(num);
771 ret = false;
772 for (i = 0; i < size; i++) {
773 ret = !!((bmp[i] & msk[i]) == msk[i]);
774 if (!ret) {
775 break;
776 }
777 }
778 if (ret) {
779 for (i = 0; i < size; i++) {
780 xwbop_c0m(xwbmp_t, &bmp[i], msk[i]);
781 }
782 }
783 return ret;
784}
785
787bool xwbmpop_t1mo(xwbmp_t * bmp, const xwbmp_t msk[], xwsz_t num)
788{
789 xwsq_t i;
790 xwsz_t size;
791 bool ret;
792
793 size = BITS_TO_XWBMP_T(num);
794 ret = false;
795 for (i = 0; i < size; i++) {
796 ret = !!(bmp[i] & msk[i]);
797 if (ret) {
798 break;
799 }
800 }
801 return ret;
802}
803
805bool xwbmpop_t1mo_then_c0m(xwbmp_t * bmp, const xwbmp_t msk[], xwsz_t num)
806{
807 xwsq_t i;
808 xwsz_t size;
809 bool ret;
810
811 size = BITS_TO_XWBMP_T(num);
812 ret = false;
813 for (i = 0; i < size; i++) {
814 ret = !!(bmp[i] & msk[i]);
815 if (ret) {
816 break;
817 }
818 }
819 if (ret) {
820 for (i = 0; i < size; i++) {
821 xwbop_c0m(xwbmp_t, &bmp[i], msk[i]);
822 }
823 }
824 return ret;
825}
826
828bool xwbmpop_t0ma(xwbmp_t * bmp, const xwbmp_t msk[], xwsz_t num)
829{
830 xwsq_t i;
831 xwsz_t size;
832 bool ret;
833
834 size = BITS_TO_XWBMP_T(num);
835 ret = false;
836 for (i = 0; i < size; i++) {
837 ret = !(bmp[i] & msk[i]);
838 if (!ret) {
839 break;
840 }
841 }
842 return ret;
843}
844
846bool xwbmpop_t0ma_then_s1m(xwbmp_t * bmp, const xwbmp_t msk[], xwsz_t num)
847{
848 xwsq_t i;
849 xwsz_t size;
850 bool ret;
851
852 size = BITS_TO_XWBMP_T(num);
853 ret = false;
854 for (i = 0; i < size; i++) {
855 ret = !(bmp[i] & msk[i]);
856 if (!ret) {
857 break;
858 }
859 }
860 if (ret) {
861 for (i = 0; i < size; i++) {
862 xwbop_s1m(xwbmp_t, &bmp[i], msk[i]);
863 }
864 }
865 return ret;
866}
867
869bool xwbmpop_t0mo(xwbmp_t * bmp, const xwbmp_t msk[], xwsz_t num)
870{
871 xwsq_t i;
872 xwsz_t size;
873 bool ret;
874
875 size = BITS_TO_XWBMP_T(num);
876 ret = false;
877 for (i = 0; i < size; i++) {
878 ret = !!((bmp[i] & msk[i]) != msk[i]);
879 if (ret) {
880 break;
881 }
882 }
883 return ret;
884}
885
887bool xwbmpop_t0mo_then_s1m(xwbmp_t * bmp, const xwbmp_t msk[], xwsz_t num)
888{
889 xwsq_t i;
890 xwsz_t size;
891 bool ret;
892
893 size = BITS_TO_XWBMP_T(num);
894 ret = false;
895 for (i = 0; i < size; i++) {
896 ret = !!((bmp[i] & msk[i]) != msk[i]);
897 if (ret) {
898 break;
899 }
900 }
901 if (ret) {
902 for (i = 0; i < size; i++) {
903 xwbop_s1m(xwbmp_t, &bmp[i], msk[i]);
904 }
905 }
906 return ret;
907}
908
910void xwbmpop_not(xwbmp_t * bmp, xwsz_t num)
911{
912 xwsq_t i;
913 xwsz_t size;
914
915 size = BITS_TO_XWBMP_T(num);
916 for (i = 0; i < size; i++) {
917 bmp[i] = ~bmp[i];
918 }
919}
920
922void xwbmpop_and(xwbmp_t * bmp, const xwbmp_t opd[], xwsz_t num)
923{
924 xwsq_t i;
925 xwsz_t size;
926
927 size = BITS_TO_XWBMP_T(num);
928 for (i = 0; i < size; i++) {
929 bmp[i] &= opd[i];
930 }
931}
932
934void xwbmpop_or(xwbmp_t * bmp, const xwbmp_t opd[], xwsz_t num)
935{
936 xwsq_t i;
937 xwsz_t size;
938
939 size = BITS_TO_XWBMP_T(num);
940 for (i = 0; i < size; i++) {
941 bmp[i] |= opd[i];
942 }
943}
944
946void xwbmpop_xor(xwbmp_t * bmp, const xwbmp_t opd[], xwsz_t num)
947{
948 xwsq_t i;
949 xwsz_t size;
950
951 size = BITS_TO_XWBMP_T(num);
952 for (i = 0; i < size; i++) {
953 bmp[i] ^= opd[i];
954 }
955}
956
957#if (!defined(ARCHCFG_LIB_XWBMPOP_FFS)) || (1 != ARCHCFG_LIB_XWBMPOP_FFS)
960{
961 xwsz_t m = BITS_TO_XWBMP_T(num);
962 xwsz_t i;
963 xwbmp_t msk;
964 xwssq_t p = -1;
965
966 for (i = 0; i < m; i++) {
967 if (i == (m - 1)) {
968 msk = (XWBOP_BIT(num % BITS_PER_XWBMP_T) - (xwbmp_t)1);
969 if ((xwbmp_t)0 == msk) {
970 msk = (xwbmp_t)(~(xwbmp_t)0);
971 }
972 } else {
973 msk = (xwbmp_t)(~(xwbmp_t)0);
974 }
975 p = xwbop_ffs(xwbmp_t, bmp[i] & msk);
976 if (p >= 0) {
977 break;
978 }
979 }
980 if (p >= 0) {
981 p += ((xwssq_t)i << XWBMP_T_SHIFT); /* p = p + i * BITS_PER_XWBMP_T; */
982 }
983 return p;
984}
985#endif
986
987#if (!defined(ARCHCFG_LIB_XWBMPOP_FFZ)) || (1 != ARCHCFG_LIB_XWBMPOP_FFZ)
990{
991 xwsz_t m = BITS_TO_XWBMP_T(num);
992 xwsz_t i;
993 xwbmp_t msk;
994 xwssq_t p = -1;
995
996 for (i = 0; i < m; i++) {
997 if (i == (m - 1)) {
998 msk = ~(XWBOP_BIT(num % BITS_PER_XWBMP_T) - (xwbmp_t)1);
999 if ((xwbmp_t)(~(xwbmp_t)0) == msk) {
1000 msk = (xwbmp_t)0;
1001 }
1002 } else {
1003 msk = (xwbmp_t)0;
1004 }
1005 p = xwbop_ffz(xwbmp_t, bmp[i] | msk);
1006 if (p >= 0) {
1007 break;
1008 }
1009 }
1010 if (p >= 0) {
1011 p += ((xwssq_t)i << XWBMP_T_SHIFT); /* p = p + i * BITS_PER_XWBMP_T; */
1012 }
1013 return p;
1014}
1015#endif
1016
1017#if (!defined(ARCHCFG_LIB_XWBMPOP_FLS)) || (1 != ARCHCFG_LIB_XWBMPOP_FLS)
1020{
1021 xwsz_t i = BITS_TO_XWBMP_T(num);
1022 xwbmp_t msk;
1023 xwssq_t p = -1;
1024
1025 msk = (XWBOP_BIT(num % BITS_PER_XWBMP_T) - (xwbmp_t)1);
1026 if ((xwbmp_t)0 == msk) {
1027 msk = (xwbmp_t)(~(xwbmp_t)0);
1028 }
1029 while (i > 0) {
1030 i--;
1031 p = xwbop_fls(xwbmp_t, bmp[i] & msk);
1032 if (p >= 0) {
1033 break;
1034 }
1035 msk = (xwbmp_t)(~(xwbmp_t)0);
1036 }
1037 p += ((xwssq_t)i << XWBMP_T_SHIFT); /* p = p + i * BITS_PER_XWBMP_T; */
1038 return p;
1039}
1040#endif
1041
1042#if (!defined(ARCHCFG_LIB_XWBMPOP_FLZ)) || (1 != ARCHCFG_LIB_XWBMPOP_FLZ)
1045{
1046 xwsz_t i = BITS_TO_XWBMP_T(num);
1047 xwbmp_t msk;
1048 xwssq_t p = -1;
1049
1050 msk = ~(XWBOP_BIT(num % BITS_PER_XWBMP_T) - (xwbmp_t)1);
1051 if ((xwbmp_t)(~(xwbmp_t)0) == msk) {
1052 msk = (xwbmp_t)0;
1053 }
1054 while (i > 0) {
1055 i--;
1056 p = xwbop_flz(xwbmp_t, bmp[i] | msk);
1057 if (p >= 0) {
1058 break;
1059 }
1060 msk = (xwbmp_t)0;
1061 }
1062 p += ((xwssq_t)i << XWBMP_T_SHIFT); /* p = p + i * BITS_PER_XWBMP_T; */
1063 return p;
1064}
1065#endif
1066
1069{
1070 xwsz_t i;
1071 xwsz_t n;
1072 xwsz_t res;
1073
1074 res = 0;
1075 n = BITS_TO_XWBMP_T(num);
1076 for (i = 0; i < n; i++) {
1077 res += xwbop_weight(xwbmp_t, bmp[i]);
1078 }
1079 return res;
1080}
#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)
在位图中从最低位起查找第一个被置1的位
xwssq_t xwbmpop_fls(xwbmp_t *bmp, xwsz_t num)
在位图中从最高位起查找第一个被置1的位
bool xwbmpop_t0ma(xwbmp_t *bmp, const xwbmp_t msk[], xwsz_t num)
测试位图中掩码部分是否全部为0
Definition xwbop.c:828
xwssq_t xwbop_fls32(xwu32_t x)
#define xwbop_x1m(type, addr, mask)
将数据掩码部分的位全部翻转
Definition xwbop.h:129
xwu32_t xwbop_re32(xwu32_t x)
bool xwbmpop_t1mo(xwbmp_t *bmp, const xwbmp_t msk[], xwsz_t num)
测试位图中掩码部分是否至少有一位为1
Definition xwbop.c:787
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)
在数据中从最高位起查找第一个被置1的位
Definition xwbop.h:169
void xwbmpop_xor(xwbmp_t *bmp, const xwbmp_t opd[], xwsz_t num)
将位图与操作数进行逐位“异或”运算
Definition xwbop.c:946
bool xwbmpop_t1i(xwbmp_t *bmp, xwsq_t n)
测试位图中的单个位是否为1
Definition xwbop.c:732
xwsz_t xwbop_weight32(xwu32_t x)
Definition xwbop.c:421
xwu64_t xwbop_re64(xwu64_t x)
#define xwbop_weight(type, data)
统计数据中1的个数
Definition xwbop.h:201
bool xwbmpop_t0mo(xwbmp_t *bmp, const xwbmp_t msk[], xwsz_t num)
测试位图中掩码部分是否至少有一位为0
Definition xwbop.c:869
bool xwbmpop_t0mo_then_s1m(xwbmp_t *bmp, const xwbmp_t msk[], xwsz_t num)
测试位图中掩码部分是否至少有一位为0,如果是,就将掩码部分全部置1
Definition xwbop.c:887
xwsz_t xwbop_weight64(xwu64_t x)
Definition xwbop.c:601
xwu8_t xwbop_rbit8(xwu8_t x)
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)
void xwbmpop_or(xwbmp_t *bmp, const xwbmp_t opd[], xwsz_t num)
将位图与操作数进行逐位“或”运算
Definition xwbop.c:934
xwssq_t xwbmpop_flz(xwbmp_t *bmp, xwsz_t num)
在位图中从最高位起查找第一个被清0的位
xwssq_t xwbop_flz32(xwu32_t x)
Definition xwbop.c:368
#define xwbop_flz(type, data)
在数据中从最高位起查找第一个被清0的位
Definition xwbop.h:193
xwu16_t xwbop_re16(xwu16_t a)
bool xwbmpop_t1mo_then_c0m(xwbmp_t *bmp, const xwbmp_t msk[], xwsz_t num)
测试位图中掩码部分是否至少有一位为1,如果是,就将掩码部分全部清0
Definition xwbop.c:805
void xwbmpop_c0all(xwbmp_t *bmp, xwsq_t num)
将位图中所有位清0
Definition xwbop.c:658
bool xwbmpop_t1ma(xwbmp_t *bmp, const xwbmp_t msk[], xwsz_t num)
测试位图中掩码部分是否全部为1
Definition xwbop.c:746
xwsz_t xwbop_weight16(xwu16_t x)
Definition xwbop.c:267
void xwbmpop_c0m(xwbmp_t *bmp, const xwbmp_t msk[], xwsz_t num)
将位图中掩码部分清0
Definition xwbop.c:699
xwssq_t xwbop_ffz16(xwu16_t x)
Definition xwbop.c:214
xwu64_t xwbop_rbit64(xwu64_t x)
bool xwbmpop_t1ma_then_c0m(xwbmp_t *bmp, const xwbmp_t msk[], xwsz_t num)
测试位图中掩码部分是否全部为1,如果是,就将掩码部分全部清0
Definition xwbop.c:764
void xwbmpop_s1i(xwbmp_t *bmp, xwsq_t n)
将位图中单个位置1
#define xwbop_c0m(type, addr, mask)
将数据掩码部分的位全部清0
Definition xwbop.h:121
void xwbmpop_x1m(xwbmp_t *bmp, const xwbmp_t msk[], xwsz_t num)
将位图中掩码部分翻转
Definition xwbop.c:720
void xwbmpop_s1all(xwbmp_t *bmp, xwsq_t num)
将位图中所有位置1
Definition xwbop.c:647
xwssq_t xwbmpop_cmp(xwbmp_t *bmp, const xwbmp_t opd[], xwsz_t num)
从数组最高元素开始比较两个位图的数值大小
Definition xwbop.c:625
void xwbmpop_assign(xwbmp_t *bmp, const xwbmp_t opd[], xwsz_t num)
赋值操作数到位图
Definition xwbop.c:614
#define XWBOP_BIT(n)
Definition xwbop.h:27
#define xwbop_s1m(type, addr, mask)
将数据掩码部分的位全部置1
Definition xwbop.h:113
#define xwbop_ffz(type, data)
在数据中从最低位起查找第一个被清0的位
Definition xwbop.h:181
xwssq_t xwbop_flz16(xwu16_t x)
Definition xwbop.c:222
bool xwbmpop_t0i(xwbmp_t *bmp, xwsq_t n)
测试位图中的单个位是否为0
Definition xwbop.c:739
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)
将位图中单个位翻转
void xwbmpop_not(xwbmp_t *bmp, xwsz_t num)
将位图按位取反
Definition xwbop.c:910
#define XWBOP_BMP_MASK(n)
Definition xwbop.h:28
void xwbmpop_c0i(xwbmp_t *bmp, xwsq_t n)
将位图中单个位清0
xwssq_t xwbmpop_ffz(xwbmp_t *bmp, xwsz_t num)
在位图中从最低位起查找第一个被清0的位
#define xwbop_ffs(type, data)
在数据中从最低位起查找第一个被置1的位
Definition xwbop.h:157
bool xwbmpop_t0ma_then_s1m(xwbmp_t *bmp, const xwbmp_t msk[], xwsz_t num)
测试位图中掩码部分是否全部为0,如果是,就将掩码部分全部置1
Definition xwbop.c:846
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)
在位图中统计被置1的位的个数
Definition xwbop.c:1068
xwssq_t xwbop_fls8(xwu8_t x)
void xwbmpop_s1m(xwbmp_t *bmp, const xwbmp_t msk[], xwsz_t num)
将位图中掩码部分置1
Definition xwbop.c:678
void xwbmpop_and(xwbmp_t *bmp, const xwbmp_t opd[], xwsz_t num)
将位图与操作数进行逐位“与”运算
Definition xwbop.c:922
XWOS通用库:位操作
XWOS的标准头文件