Lely core libraries  2.3.4
bits.h
Go to the documentation of this file.
1 
22 #ifndef LELY_UTIL_BITS_H_
23 #define LELY_UTIL_BITS_H_
24 
25 #include <lely/features.h>
26 
27 #include <stdint.h>
28 
29 #ifdef _MSC_VER
30 #include <intrin.h>
31 #include <stdlib.h>
32 #endif
33 
34 #ifndef LELY_UTIL_BITS_INLINE
35 #define LELY_UTIL_BITS_INLINE static inline
36 #endif
37 
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
46 LELY_UTIL_BITS_INLINE uint_least16_t bswap16(uint_least16_t x);
47 
52 LELY_UTIL_BITS_INLINE uint_least32_t bswap32(uint_least32_t x);
53 
58 LELY_UTIL_BITS_INLINE uint_least64_t bswap64(uint_least64_t x);
62 LELY_UTIL_BITS_INLINE int cls8(uint_least8_t x);
63 
68 #if defined(_MSC_VER) || defined(__GNUC__) || __has_builtin(__builtin_clz)
69 LELY_UTIL_BITS_INLINE int clz8(uint_least8_t x);
70 #else
71 int clz8(uint_least8_t x);
72 #endif
73 
78 LELY_UTIL_BITS_INLINE int cls16(uint_least16_t x);
79 
84 LELY_UTIL_BITS_INLINE int clz16(uint_least16_t x);
85 
90 LELY_UTIL_BITS_INLINE int cls32(uint_least32_t x);
91 
96 LELY_UTIL_BITS_INLINE int clz32(uint_least32_t x);
97 
102 LELY_UTIL_BITS_INLINE int cls64(uint_least64_t x);
103 
108 LELY_UTIL_BITS_INLINE int clz64(uint_least64_t x);
109 
114 LELY_UTIL_BITS_INLINE int cts8(uint_least8_t x);
115 
120 #if defined(_MSC_VER) || defined(__GNUC__) || __has_builtin(__builtin_ctz)
121 LELY_UTIL_BITS_INLINE int ctz8(uint_least8_t x);
122 #else
123 int ctz8(uint_least8_t x);
124 #endif
125 
130 LELY_UTIL_BITS_INLINE int cts16(uint_least16_t x);
131 
136 LELY_UTIL_BITS_INLINE int ctz16(uint_least16_t x);
137 
142 LELY_UTIL_BITS_INLINE int cts32(uint_least32_t x);
143 
148 LELY_UTIL_BITS_INLINE int ctz32(uint_least32_t x);
149 
154 LELY_UTIL_BITS_INLINE int cts64(uint_least64_t x);
155 
160 LELY_UTIL_BITS_INLINE int ctz64(uint_least64_t x);
161 
166 #if defined(_MSC_VER) || defined(__GNUC__) || __has_builtin(__builtin_ffs)
167 LELY_UTIL_BITS_INLINE int ffs8(uint_least8_t x);
168 #else
169 int ffs8(uint_least8_t x);
170 #endif
171 
176 LELY_UTIL_BITS_INLINE int ffz8(uint_least8_t x);
177 
182 LELY_UTIL_BITS_INLINE int ffs16(uint_least16_t x);
183 
188 LELY_UTIL_BITS_INLINE int ffz16(uint_least16_t x);
189 
194 LELY_UTIL_BITS_INLINE int ffs32(uint_least32_t x);
195 
200 LELY_UTIL_BITS_INLINE int ffz32(uint_least32_t x);
201 
206 LELY_UTIL_BITS_INLINE int ffs64(uint_least64_t x);
207 
212 LELY_UTIL_BITS_INLINE int ffz64(uint_least64_t x);
213 
215 #if defined(__GNUC__) || __has_builtin(__builtin_parity)
216 LELY_UTIL_BITS_INLINE int parity8(uint_least8_t x);
217 #else
218 int parity8(uint_least8_t x);
219 #endif
220 
222 LELY_UTIL_BITS_INLINE int parity16(uint_least16_t x);
223 
225 LELY_UTIL_BITS_INLINE int parity32(uint_least32_t x);
226 
228 LELY_UTIL_BITS_INLINE int parity64(uint_least64_t x);
229 
234 #if defined(__GNUC__) || __has_builtin(__builtin_popcount)
235 LELY_UTIL_BITS_INLINE int popcount8(uint_least8_t x);
236 #else
237 int popcount8(uint_least8_t x);
238 #endif
239 
244 LELY_UTIL_BITS_INLINE int popcount16(uint_least16_t x);
245 
250 LELY_UTIL_BITS_INLINE int popcount32(uint_least32_t x);
251 
256 LELY_UTIL_BITS_INLINE int popcount64(uint_least64_t x);
257 
259 LELY_UTIL_BITS_INLINE uint_least8_t rol8(uint_least8_t x, unsigned int n);
260 
262 LELY_UTIL_BITS_INLINE uint_least8_t ror8(uint_least8_t x, unsigned int n);
263 
265 LELY_UTIL_BITS_INLINE uint_least16_t rol16(uint_least16_t x, unsigned int n);
266 
268 LELY_UTIL_BITS_INLINE uint_least16_t ror16(uint_least16_t x, unsigned int n);
269 
271 LELY_UTIL_BITS_INLINE uint_least32_t rol32(uint_least32_t x, unsigned int n);
272 
274 LELY_UTIL_BITS_INLINE uint_least32_t ror32(uint_least32_t x, unsigned int n);
275 
277 LELY_UTIL_BITS_INLINE uint_least64_t rol64(uint_least64_t x, unsigned int n);
278 
280 LELY_UTIL_BITS_INLINE uint_least64_t ror64(uint_least64_t x, unsigned int n);
281 
282 LELY_UTIL_BITS_INLINE uint_least16_t
283 bswap16(uint_least16_t x)
284 {
285 #ifdef _MSC_VER
286  return _byteswap_ushort(x);
287 #elif GNUC_PREREQ(4, 8) || __has_builtin(__builtin_bswap16)
288  return __builtin_bswap16(x);
289 #else
290  return ((x & 0xff) << 8) | ((x >> 8) & 0xff);
291 #endif
292 }
293 
294 LELY_UTIL_BITS_INLINE uint_least32_t
295 bswap32(uint_least32_t x)
296 {
297 #ifdef _MSC_VER
298  return _byteswap_ulong(x);
299 #elif GNUC_PREREQ(4, 3) || __has_builtin(__builtin_bswap32)
300  return __builtin_bswap32(x);
301 #else
302  return ((x & 0xff) << 24) | ((x & 0xff00u) << 8) | ((x >> 8) & 0xff00u)
303  | ((x >> 24) & 0xff);
304 #endif
305 }
306 
307 LELY_UTIL_BITS_INLINE uint_least64_t
308 bswap64(uint_least64_t x)
309 {
310 #ifdef _MSC_VER
311  return _byteswap_uint64(x);
312 #elif GNUC_PREREQ(4, 3) || __has_builtin(__builtin_bswap64)
313  return __builtin_bswap64(x);
314 #else
315  return ((x & 0xff) << 56) | ((x & 0xff00u) << 40)
316  | ((x & 0xff0000ul) << 24) | ((x & 0xff000000ul) << 8)
317  | ((x >> 8) & 0xff000000ul) | ((x >> 24) & 0xff0000ul)
318  | ((x >> 40) & 0xff00u) | ((x >> 56) & 0xff);
319 #endif
320 }
321 
322 LELY_UTIL_BITS_INLINE int
323 cls8(uint_least8_t x)
324 {
325  return clz8(~x);
326 }
327 
328 #if defined(_MSC_VER) || defined(__GNUC__) || __has_builtin(__builtin_clz)
329 LELY_UTIL_BITS_INLINE int
330 clz8(uint_least8_t x)
331 {
332  x &= UINT8_C(0xff);
333 #ifdef _MSC_VER
334  unsigned long Index;
335  return _BitScanReverse(&Index, x) ? (7 - Index) : 8;
336 #elif defined(__GNUC__) || __has_builtin(__builtin_clz)
337  return (x != 0) ? (__builtin_clz(x) - 24) : 8;
338 #endif
339 }
340 #endif // _MSC_VER || __GNUC__ || __has_builtin(__builtin_clz)
341 
342 LELY_UTIL_BITS_INLINE int
343 cls16(uint_least16_t x)
344 {
345  return clz16(~x);
346 }
347 
348 LELY_UTIL_BITS_INLINE int
349 clz16(uint_least16_t x)
350 {
351  x &= UINT16_C(0xffff);
352 #ifdef _MSC_VER
353  unsigned long Index;
354  return _BitScanReverse(&Index, x) ? (15 - Index) : 16;
355 #elif defined(__GNUC__) || __has_builtin(__builtin_clz)
356  return (x != 0) ? (__builtin_clz(x) - 16) : 16;
357 #else
358  return ((x >> 8) != 0) ? clz8(x >> 8) : (clz8((uint_least8_t)x) + 8);
359 #endif
360 }
361 
362 LELY_UTIL_BITS_INLINE int
363 cls32(uint_least32_t x)
364 {
365  return clz32(~x);
366 }
367 
368 LELY_UTIL_BITS_INLINE int
369 clz32(uint_least32_t x)
370 {
371  x &= UINT32_C(0xffffffff);
372 #ifdef _MSC_VER
373  unsigned long Index;
374  return _BitScanReverse(&Index, x) ? 31 - Index : 32;
375 #elif (defined(__GNUC__) || __has_builtin(__builtin_clz)) && __WORDSIZE == 64
376  return (x != 0) ? __builtin_clz(x) : 32;
377 #elif defined(__GNUC__) || __has_builtin(__builtin_clzl)
378  return (x != 0) ? __builtin_clzl(x) : 32;
379 #else
380  return ((x >> 16) != 0) ? clz16(x >> 16)
381  : (clz16((uint_least16_t)x) + 16);
382 #endif
383 }
384 
385 LELY_UTIL_BITS_INLINE int
386 cls64(uint_least64_t x)
387 {
388  return clz64(~x);
389 }
390 
391 LELY_UTIL_BITS_INLINE int
392 clz64(uint_least64_t x)
393 {
394  x &= UINT64_C(0xffffffffffffffff);
395 #if defined(_MSC_VER) && _WIN64
396  unsigned long Index;
397  return _BitScanReverse64(&Index, x) ? (63 - Index) : 64;
398 #elif (defined(__GNUC__) || __has_builtin(__builtin_clzl)) && LONG_BIT == 64
399  return (x != 0) ? __builtin_clzl(x) : 64;
400 #elif defined(__GNUC__) || __has_builtin(__builtin_clzll)
401  return (x != 0) ? __builtin_clzll(x) : 64;
402 #else
403  return ((x >> 32) != 0) ? clz32(x >> 32)
404  : (clz32((uint_least32_t)x) + 32);
405 #endif
406 }
407 
408 LELY_UTIL_BITS_INLINE int
409 cts8(uint_least8_t x)
410 {
411  return ctz8(~x);
412 }
413 
414 #if defined(_MSC_VER) || defined(__GNUC__) || __has_builtin(__builtin_ctz)
415 LELY_UTIL_BITS_INLINE int
416 ctz8(uint_least8_t x)
417 {
418  x &= UINT8_C(0xff);
419 #ifdef _MSC_VER
420  unsigned long Index;
421  return _BitScanForward(&Index, x) ? Index : 8;
422 #elif defined(__GNUC__) || __has_builtin(__builtin_ctz)
423  return (x != 0) ? __builtin_ctz(x) : 8;
424 #endif
425 }
426 #endif // _MSC_VER || __GNUC__ || __has_builtin(__builtin_ctz)
427 
428 LELY_UTIL_BITS_INLINE int
429 cts16(uint_least16_t x)
430 {
431  return ctz16(~x);
432 }
433 
434 LELY_UTIL_BITS_INLINE int
435 ctz16(uint_least16_t x)
436 {
437  x &= UINT16_C(0xffff);
438 #ifdef _MSC_VER
439  unsigned long Index;
440  return _BitScanForward(&Index, x) ? Index : 16;
441 #elif defined(__GNUC__) || __has_builtin(__builtin_ctz)
442  return (x != 0) ? __builtin_ctz(x) : 16;
443 #else
444  return ((x & UINT8_C(0xff)) != 0) ? ctz8((uint_least8_t)x)
445  : ctz8(x >> 8) + 8;
446 #endif
447 }
448 
449 LELY_UTIL_BITS_INLINE int
450 cts32(uint_least32_t x)
451 {
452  return ctz32(~x);
453 }
454 
455 LELY_UTIL_BITS_INLINE int
456 ctz32(uint_least32_t x)
457 {
458  x &= UINT32_C(0xffffffff);
459 #ifdef _MSC_VER
460  unsigned long Index;
461  return _BitScanForward(&Index, x) ? Index : 32;
462 #elif (defined(__GNUC__) || __has_builtin(__builtin_ctz)) && __WORDSIZE == 64
463  return (x != 0) ? __builtin_ctz(x) : 32;
464 #elif defined(__GNUC__) || __has_builtin(__builtin_ctzl)
465  return (x != 0) ? __builtin_ctzl(x) : 32;
466 #else
467  // clang-format off
468  return (x & UINT16_C(0xffff))
469  ? ctz16((uint_least16_t)x) : ctz16(x >> 16) + 16;
470  // clang-format on
471 #endif
472 }
473 
474 LELY_UTIL_BITS_INLINE int
475 cts64(uint_least64_t x)
476 {
477  return ctz64(~x);
478 }
479 
480 LELY_UTIL_BITS_INLINE int
481 ctz64(uint_least64_t x)
482 {
483  x &= UINT64_C(0xffffffffffffffff);
484 #if (defined(__GNUC__) || __has_builtin(__builtin_ctzl)) && LONG_BIT == 64
485  return (x != 0) ? __builtin_ctzl(x) : 64;
486 #elif defined(__GNUC__) || __has_builtin(__builtin_ctzll)
487  return (x != 0) ? __builtin_ctzll(x) : 64;
488 #else
489  // clang-format off
490  return (x & UINT32_C(0xffffffff))
491  ? ctz32((uint_least32_t)x) : ctz32(x >> 32) + 32;
492  // clang-format on
493 #endif
494 }
495 
496 #if defined(_MSC_VER) || defined(__GNUC__) || __has_builtin(__builtin_ffs)
497 LELY_UTIL_BITS_INLINE int
498 ffs8(uint_least8_t x)
499 {
500  x &= UINT8_C(0xff);
501 #ifdef _MSC_VER
502  unsigned long Index;
503  return _BitScanForward(&Index, x) ? Index + 1 : 0;
504 #elif defined(__GNUC__) || __has_builtin(__builtin_ffs)
505  return __builtin_ffs(x);
506 #endif
507 }
508 #endif // _MSC_VER || __GNUC__ || __has_builtin(__builtin_ffs)
509 
510 LELY_UTIL_BITS_INLINE int
511 ffz8(uint_least8_t x)
512 {
513  return ffs8(~x);
514 }
515 
516 LELY_UTIL_BITS_INLINE int
517 ffs16(uint_least16_t x)
518 {
519  x &= UINT16_C(0xffff);
520 #ifdef _MSC_VER
521  unsigned long Index;
522  return _BitScanForward(&Index, x) ? Index + 1 : 0;
523 #elif defined(__GNUC__) || __has_builtin(__builtin_ffs)
524  return __builtin_ffs(x);
525 #else
526  // clang-format off
527  return (x != 0) ? ((x & UINT8_C(0xff))
528  ? ffs8((uint_least8_t)x) : ffs8(x >> 8) + 8) : 0;
529  // clang-format on
530 #endif
531 }
532 
533 LELY_UTIL_BITS_INLINE int
534 ffz16(uint_least16_t x)
535 {
536  return ffs16(~x);
537 }
538 
539 LELY_UTIL_BITS_INLINE int
540 ffs32(uint_least32_t x)
541 {
542  x &= UINT32_C(0xffffffff);
543 #ifdef _MSC_VER
544  unsigned long Index;
545  return _BitScanForward(&Index, x) ? Index + 1 : 0;
546 #elif (defined(__GNUC__) || __has_builtin(__builtin_ffs)) && __WORDSIZE == 64
547  return __builtin_ffs(x);
548 #elif defined(__GNUC__) || __has_builtin(__builtin_ffsl)
549  return __builtin_ffsl(x);
550 #else
551  // clang-format off
552  return (x != 0) ? ((x & UINT16_C(0xffff))
553  ? ffs16((uint_least16_t)x) : ffs16(x >> 16) + 16) : 0;
554  // clang-format on
555 #endif
556 }
557 
558 LELY_UTIL_BITS_INLINE int
559 ffz32(uint_least32_t x)
560 {
561  return ffs32(~x);
562 }
563 
564 LELY_UTIL_BITS_INLINE int
565 ffs64(uint_least64_t x)
566 {
567  x &= UINT64_C(0xffffffffffffffff);
568 #if defined(_MSC_VER) && _WIN64
569  unsigned long Index;
570  return _BitScanForward64(&Index, x) ? Index + 1 : 0;
571 #elif (defined(__GNUC__) || __has_builtin(__builtin_ffsl)) && LONG_BIT == 64
572  return __builtin_ffsl(x);
573 #elif defined(__GNUC__) || __has_builtin(__builtin_ffsll)
574  return __builtin_ffsll(x);
575 #else
576  // clang-format off
577  return (x != 0) ? ((x & UINT32_C(0xffffffff))
578  ? ffs32((uint_least32_t)x) : ffs32(x >> 32) + 32) : 0;
579  // clang-format on
580 #endif
581 }
582 
583 LELY_UTIL_BITS_INLINE int
584 ffz64(uint_least64_t x)
585 {
586  return ffs64(~x);
587 }
588 
589 #if defined(__GNUC__) || __has_builtin(__builtin_parity)
590 LELY_UTIL_BITS_INLINE int
591 parity8(uint_least8_t x)
592 {
593  x &= UINT8_C(0xff);
594  return __builtin_parity(x);
595 }
596 #endif // __GNUC__ || __has_builtin(__builtin_parity)
597 
598 LELY_UTIL_BITS_INLINE int
599 parity16(uint_least16_t x)
600 {
601  x &= UINT16_C(0xffff);
602 #if defined(__GNUC__) || __has_builtin(__builtin_parity)
603  return __builtin_parity(x);
604 #else
605  return parity8((uint_least8_t)x) ^ parity8(x >> 8);
606 #endif
607 }
608 
609 LELY_UTIL_BITS_INLINE int
610 parity32(uint_least32_t x)
611 {
612  x &= UINT32_C(0xffffffff);
613 #if (defined(__GNUC__) || __has_builtin(__builtin_parity)) && __WORDSIZE == 64
614  return __builtin_parity(x);
615 #elif defined(__GNUC__) || __has_builtin(__builtin_parityl)
616  return __builtin_parityl(x);
617 #else
618  return parity16((uint_least16_t)x) ^ parity16(x >> 16);
619 #endif
620 }
621 
622 LELY_UTIL_BITS_INLINE int
623 parity64(uint_least64_t x)
624 {
625  x &= UINT64_C(0xffffffffffffffff);
626 #if (defined(__GNUC__) || __has_builtin(__builtin_parityl)) && LONG_BIT == 64
627  return __builtin_parityl(x);
628 #elif defined(__GNUC__) || __has_builtin(__builtin_parityll)
629  return __builtin_parityll(x);
630 #else
631  return parity32((uint_least32_t)x) ^ parity32(x >> 32);
632 #endif
633 }
634 
635 #if defined(__GNUC__) || __has_builtin(__builtin_popcount)
636 LELY_UTIL_BITS_INLINE int
637 popcount8(uint_least8_t x)
638 {
639  x &= UINT8_C(0xff);
640  return __builtin_popcount(x);
641 }
642 #endif // __GNUC__ || __has_builtin(__builtin_popcount)
643 
644 LELY_UTIL_BITS_INLINE int
645 popcount16(uint_least16_t x)
646 {
647  x &= UINT16_C(0xffff);
648 #if defined(__GNUC__) || __has_builtin(__builtin_popcount)
649  return __builtin_popcount(x);
650 #else
651  return popcount8((uint_least8_t)x) + popcount8(x >> 8);
652 #endif
653 }
654 
655 LELY_UTIL_BITS_INLINE int
656 popcount32(uint_least32_t x)
657 {
658  x &= UINT32_C(0xffffffff);
659 #if (defined(__GNUC__) || __has_builtin(__builtin_popcount)) && __WORDSIZE == 64
660  return __builtin_popcount(x);
661 #elif defined(__GNUC__) || __has_builtin(__builtin_popcountl)
662  return __builtin_popcountl(x);
663 #else
664  return popcount16((uint_least16_t)x) + popcount16(x >> 16);
665 #endif
666 }
667 
668 LELY_UTIL_BITS_INLINE int
669 popcount64(uint_least64_t x)
670 {
671  x &= UINT64_C(0xffffffffffffffff);
672 #if (defined(__GNUC__) || __has_builtin(__builtin_popcountl)) && LONG_BIT == 64
673  return __builtin_popcountl(x);
674 #elif defined(__GNUC__) || __has_builtin(__builtin_popcountll)
675  return __builtin_popcountll(x);
676 #else
677  return popcount32((uint_least32_t)x) + popcount32(x >> 32);
678 #endif
679 }
680 
681 LELY_UTIL_BITS_INLINE uint_least8_t
682 rol8(uint_least8_t x, unsigned int n)
683 {
684  x &= UINT8_C(0xff);
685  n %= 8;
686 #ifdef _MSC_VER
687  return _rotl8(x, n);
688 #else
689  return (n != 0) ? (uint_least8_t)((x << n) | (x >> (8U - n))) : x;
690 #endif
691 }
692 
693 LELY_UTIL_BITS_INLINE uint_least8_t
694 ror8(uint_least8_t x, unsigned int n)
695 {
696  x &= UINT8_C(0xff);
697  n %= 8;
698 #ifdef _MSC_VER
699  return _rotr8(x, n);
700 #else
701  return (n != 0) ? (uint_least8_t)((x >> n) | (x << (8U - n))) : x;
702 #endif
703 }
704 
705 LELY_UTIL_BITS_INLINE uint_least16_t
706 rol16(uint_least16_t x, unsigned int n)
707 {
708  x &= UINT16_C(0xffff);
709  n %= 16;
710 #ifdef _MSC_VER
711  return _rotl16(x, n);
712 #else
713  return (n != 0) ? (uint_least16_t)((x << n) | (x >> (16U - n))) : x;
714 #endif
715 }
716 
717 LELY_UTIL_BITS_INLINE uint_least16_t
718 ror16(uint_least16_t x, unsigned int n)
719 {
720  x &= UINT16_C(0xffff);
721  n %= 16;
722 #ifdef _MSC_VER
723  return _rotr16(x, n);
724 #else
725  return (n != 0) ? (uint_least16_t)((x >> n) | (x << (16U - n))) : x;
726 #endif
727 }
728 
729 LELY_UTIL_BITS_INLINE uint_least32_t
730 rol32(uint_least32_t x, unsigned int n)
731 {
732  x &= UINT32_C(0xffffffff);
733  n %= 32;
734 #ifdef _MSC_VER
735  return _rotl(x, n);
736 #else
737  return (n != 0) ? (uint_least32_t)((x << n) | (x >> (32U - n))) : x;
738 #endif
739 }
740 
741 LELY_UTIL_BITS_INLINE uint_least32_t
742 ror32(uint_least32_t x, unsigned int n)
743 {
744  x &= UINT32_C(0xffffffff);
745  n %= 32;
746 #ifdef _MSC_VER
747  return _rotr(x, n);
748 #else
749  return (n != 0) ? (uint_least32_t)((x >> n) | (x << (32U - n))) : x;
750 #endif
751 }
752 
753 LELY_UTIL_BITS_INLINE uint_least64_t
754 rol64(uint_least64_t x, unsigned int n)
755 {
756  x &= UINT64_C(0xffffffffffffffff);
757  n %= 64;
758 #ifdef _MSC_VER
759  return _rotl64(x, n);
760 #else
761  return (n != 0) ? (uint_least64_t)((x << n) | (x >> (64U - n))) : x;
762 #endif
763 }
764 
765 LELY_UTIL_BITS_INLINE uint_least64_t
766 ror64(uint_least64_t x, unsigned int n)
767 {
768  x &= UINT64_C(0xffffffffffffffff);
769  n %= 64;
770 #ifdef _MSC_VER
771  return _rotr64(x, n);
772 #else
773  return (n != 0) ? (uint_least64_t)((x >> n) | (x << (64U - n))) : x;
774 #endif
775 }
776 
777 #ifdef __cplusplus
778 }
779 #endif
780 
781 #endif // !LELY_UTIL_BITS_H_
int cts64(uint_least64_t x)
Counts the number of trailing set bits in the unsigned 64-bit integer x.
Definition: bits.h:475
uint_least32_t ror32(uint_least32_t x, unsigned int n)
Rotates the 32-bit unsigned integer x right by n bits.
Definition: bits.h:742
uint_least16_t ror16(uint_least16_t x, unsigned int n)
Rotates the 16-bit unsigned integer x right by n bits.
Definition: bits.h:718
uint_least64_t bswap64(uint_least64_t x)
Reverses the byte order of the 64-bit unsigned integer x.
Definition: bits.h:308
int ffs16(uint_least16_t x)
Returns the index (starting from one) of the first set bit in the unsigned 16-bit integer x,...
Definition: bits.h:517
int ffz64(uint_least64_t x)
Returns the index (starting from one) of the first zero bit in the unsigned 64-bit integer x,...
Definition: bits.h:584
int cts8(uint_least8_t x)
Counts the number of trailing set bits in the unsigned 8-bit integer x.
Definition: bits.h:409
int parity16(uint_least16_t x)
Returns the parity of the unsigned 16-bit integer x.
Definition: bits.h:599
int ffs8(uint_least8_t x)
Returns the index (starting from one) of the first set bit in the unsigned 8-bit integer x,...
Definition: bits.h:498
uint_least64_t ror64(uint_least64_t x, unsigned int n)
Rotates the 64-bit unsigned integer x right by n bits.
Definition: bits.h:766
int ctz32(uint_least32_t x)
Counts the number of trailing zero bits in the unsigned 32-bit integer x.
Definition: bits.h:456
int cls16(uint_least16_t x)
Counts the number of leading set bits in the unsigned 16-bit integer x.
Definition: bits.h:343
int ffs64(uint_least64_t x)
Returns the index (starting from one) of the first set bit in the unsigned 64-bit integer x,...
Definition: bits.h:565
uint_least8_t ror8(uint_least8_t x, unsigned int n)
Rotates the 8-bit unsigned integer x right by n bits.
Definition: bits.h:694
int cts32(uint_least32_t x)
Counts the number of trailing set bits in the unsigned 32-bit integer x.
Definition: bits.h:450
int clz8(uint_least8_t x)
Counts the number of leading zero bits in the unsigned 8-bit integer x.
Definition: bits.h:330
int ctz64(uint_least64_t x)
Counts the number of trailing zero bits in the unsigned 64-bit integer x.
Definition: bits.h:481
int popcount32(uint_least32_t x)
Returns the population count (the number of set bits) in the unsigned 32-bit integer x.
Definition: bits.h:656
int cts16(uint_least16_t x)
Counts the number of trailing set bits in the unsigned 16-bit integer x.
Definition: bits.h:429
int cls64(uint_least64_t x)
Counts the number of leading set bits in the unsigned 64-bit integer x.
Definition: bits.h:386
uint_least16_t bswap16(uint_least16_t x)
Reverses the byte order of the 16-bit unsigned integer x.
Definition: bits.h:283
int parity8(uint_least8_t x)
Returns the parity of the unsigned 8-bit integer x.
Definition: bits.h:591
uint_least32_t rol32(uint_least32_t x, unsigned int n)
Rotates the 32-bit unsigned integer x left by n bits.
Definition: bits.h:730
uint_least8_t rol8(uint_least8_t x, unsigned int n)
Rotates the 8-bit unsigned integer x left by n bits.
Definition: bits.h:682
int clz64(uint_least64_t x)
Counts the number of leading zero bits in the unsigned 64-bit integer x.
Definition: bits.h:392
int ffz8(uint_least8_t x)
Returns the index (starting from one) of the first zero bit in the unsigned 8-bit integer x,...
Definition: bits.h:511
int ffs32(uint_least32_t x)
Returns the index (starting from one) of the first set bit in the unsigned 32-bit integer x,...
Definition: bits.h:540
int clz32(uint_least32_t x)
Counts the number of leading zero bits in the unsigned 32-bit integer x.
Definition: bits.h:369
int parity32(uint_least32_t x)
Returns the parity of the unsigned 32-bit integer x.
Definition: bits.h:610
int clz16(uint_least16_t x)
Counts the number of leading zero bits in the unsigned 16-bit integer x.
Definition: bits.h:349
int ffz32(uint_least32_t x)
Returns the index (starting from one) of the first zero bit in the unsigned 32-bit integer x,...
Definition: bits.h:559
int ffz16(uint_least16_t x)
Returns the index (starting from one) of the first zero bit in the unsigned 16-bit integer x,...
Definition: bits.h:534
int cls32(uint_least32_t x)
Counts the number of leading set bits in the unsigned 32-bit integer x.
Definition: bits.h:363
int popcount64(uint_least64_t x)
Returns the population count (the number of set bits) in the unsigned 64-bit integer x.
Definition: bits.h:669
uint_least16_t rol16(uint_least16_t x, unsigned int n)
Rotates the 16-bit unsigned integer x left by n bits.
Definition: bits.h:706
int parity64(uint_least64_t x)
Returns the parity of the unsigned 64-bit integer x.
Definition: bits.h:623
uint_least64_t rol64(uint_least64_t x, unsigned int n)
Rotates the 64-bit unsigned integer x left by n bits.
Definition: bits.h:754
int ctz16(uint_least16_t x)
Counts the number of trailing zero bits in the unsigned 16-bit integer x.
Definition: bits.h:435
int ctz8(uint_least8_t x)
Counts the number of trailing zero bits in the unsigned 8-bit integer x.
Definition: bits.h:416
int cls8(uint_least8_t x)
Counts the number of leading set bits in the unsigned 8-bit integer x.
Definition: bits.h:323
uint_least32_t bswap32(uint_least32_t x)
Reverses the byte order of the 32-bit unsigned integer x.
Definition: bits.h:295
int popcount16(uint_least16_t x)
Returns the population count (the number of set bits) in the unsigned 16-bit integer x.
Definition: bits.h:645
int popcount8(uint_least8_t x)
Returns the population count (the number of set bits) in the unsigned 8-bit integer x.
Definition: bits.h:637
This header file is part of the Lely libraries; it contains the compiler feature definitions.
This header file is part of the C11 and POSIX compatibility library; it includes <stdint....
This header file is part of the C11 and POSIX compatibility library; it includes <stdlib....