Lely core libraries  2.2.5
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 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 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 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 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 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 ? __builtin_clz(x) - 24 : 8;
338 #endif
339 }
340 #endif // _MSC_VER || __GNUC__ || __has_builtin(__builtin_clz)
341 
342 inline int
343 cls16(uint_least16_t x)
344 {
345  return clz16(~x);
346 }
347 
348 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 ? __builtin_clz(x) - 16 : 16;
357 #else
358  return (x >> 8) ? clz8(x >> 8) : clz8((uint_least8_t)x) + 8;
359 #endif
360 }
361 
362 inline int
363 cls32(uint_least32_t x)
364 {
365  return clz32(~x);
366 }
367 
368 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 ? __builtin_clz(x) : 32;
377 #elif defined(__GNUC__) || __has_builtin(__builtin_clzl)
378  return x ? __builtin_clzl(x) : 32;
379 #else
380  return (x >> 16) ? clz16(x >> 16) : clz16((uint_least16_t)x) + 16;
381 #endif
382 }
383 
384 inline int
385 cls64(uint_least64_t x)
386 {
387  return clz64(~x);
388 }
389 
390 inline int
391 clz64(uint_least64_t x)
392 {
393  x &= UINT64_C(0xffffffffffffffff);
394 #if defined(_MSC_VER) && _WIN64
395  unsigned long Index;
396  return _BitScanReverse64(&Index, x) ? 63 - Index : 64;
397 #elif (defined(__GNUC__) || __has_builtin(__builtin_clzl)) && LONG_BIT == 64
398  return x ? __builtin_clzl(x) : 64;
399 #elif defined(__GNUC__) || __has_builtin(__builtin_clzll)
400  return x ? __builtin_clzll(x) : 64;
401 #else
402  return (x >> 32) ? clz32(x >> 32) : clz32((uint_least32_t)x) + 32;
403 #endif
404 }
405 
406 inline int
407 cts8(uint_least8_t x)
408 {
409  return ctz8(~x);
410 }
411 
412 #if defined(_MSC_VER) || defined(__GNUC__) || __has_builtin(__builtin_ctz)
413 inline int
414 ctz8(uint_least8_t x)
415 {
416  x &= UINT8_C(0xff);
417 #ifdef _MSC_VER
418  unsigned long Index;
419  return _BitScanForward(&Index, x) ? Index : 8;
420 #elif defined(__GNUC__) || __has_builtin(__builtin_ctz)
421  return x ? __builtin_ctz(x) : 8;
422 #endif
423 }
424 #endif // _MSC_VER || __GNUC__ || __has_builtin(__builtin_ctz)
425 
426 inline int
427 cts16(uint_least16_t x)
428 {
429  return ctz16(~x);
430 }
431 
432 inline int
433 ctz16(uint_least16_t x)
434 {
435  x &= UINT16_C(0xffff);
436 #ifdef _MSC_VER
437  unsigned long Index;
438  return _BitScanForward(&Index, x) ? Index : 16;
439 #elif defined(__GNUC__) || __has_builtin(__builtin_ctz)
440  return x ? __builtin_ctz(x) : 16;
441 #else
442  return (x & 0xff) ? ctz8((uint_least8_t)x) : ctz8(x >> 8) + 8;
443 #endif
444 }
445 
446 inline int
447 cts32(uint_least32_t x)
448 {
449  return ctz32(~x);
450 }
451 
452 inline int
453 ctz32(uint_least32_t x)
454 {
455  x &= UINT32_C(0xffffffff);
456 #ifdef _MSC_VER
457  unsigned long Index;
458  return _BitScanForward(&Index, x) ? Index : 32;
459 #elif (defined(__GNUC__) || __has_builtin(__builtin_ctz)) && __WORDSIZE == 64
460  return x ? __builtin_ctz(x) : 32;
461 #elif defined(__GNUC__) || __has_builtin(__builtin_ctzl)
462  return x ? __builtin_ctzl(x) : 32;
463 #else
464  // clang-format off
465  return (x & UINT16_C(0xffff))
466  ? ctz16((uint_least16_t)x) : ctz16(x >> 16) + 16;
467  // clang-format on
468 #endif
469 }
470 
471 inline int
472 cts64(uint_least64_t x)
473 {
474  return ctz64(~x);
475 }
476 
477 inline int
478 ctz64(uint_least64_t x)
479 {
480  x &= UINT64_C(0xffffffffffffffff);
481 #if (defined(__GNUC__) || __has_builtin(__builtin_ctzl)) && LONG_BIT == 64
482  return x ? __builtin_ctzl(x) : 64;
483 #elif defined(__GNUC__) || __has_builtin(__builtin_ctzll)
484  return x ? __builtin_ctzll(x) : 64;
485 #else
486  // clang-format off
487  return (x & UINT32_C(0xffffffff))
488  ? ctz32((uint_least32_t)x) : ctz32(x >> 32) + 32;
489  // clang-format on
490 #endif
491 }
492 
493 #if defined(_MSC_VER) || defined(__GNUC__) || __has_builtin(__builtin_ffs)
494 inline int
495 ffs8(uint_least8_t x)
496 {
497  x &= UINT8_C(0xff);
498 #ifdef _MSC_VER
499  unsigned long Index;
500  return _BitScanForward(&Index, x) ? Index + 1 : 0;
501 #elif defined(__GNUC__) || __has_builtin(__builtin_ffs)
502  return __builtin_ffs(x);
503 #endif
504 }
505 #endif // _MSC_VER || __GNUC__ || __has_builtin(__builtin_ffs)
506 
507 inline int
508 ffz8(uint_least8_t x)
509 {
510  return ffs8(~x);
511 }
512 
513 inline int
514 ffs16(uint_least16_t x)
515 {
516  x &= UINT16_C(0xffff);
517 #ifdef _MSC_VER
518  unsigned long Index;
519  return _BitScanForward(&Index, x) ? Index + 1 : 0;
520 #elif defined(__GNUC__) || __has_builtin(__builtin_ffs)
521  return __builtin_ffs(x);
522 #else
523  // clang-format off
524  return x ? ((x & UINT8_C(0xff))
525  ? ffs8((uint_least8_t)x) : ffs8(x >> 8) + 8) : 0;
526  // clang-format on
527 #endif
528 }
529 
530 inline int
531 ffz16(uint_least16_t x)
532 {
533  return ffs16(~x);
534 }
535 
536 inline int
537 ffs32(uint_least32_t x)
538 {
539  x &= UINT32_C(0xffffffff);
540 #ifdef _MSC_VER
541  unsigned long Index;
542  return _BitScanForward(&Index, x) ? Index + 1 : 0;
543 #elif (defined(__GNUC__) || __has_builtin(__builtin_ffs)) && __WORDSIZE == 64
544  return __builtin_ffs(x);
545 #elif defined(__GNUC__) || __has_builtin(__builtin_ffsl)
546  return __builtin_ffsl(x);
547 #else
548  // clang-format off
549  return x ? ((x & UINT16_C(0xffff))
550  ? ffs16((uint_least16_t)x) : ffs16(x >> 16) + 16) : 0;
551  // clang-format on
552 #endif
553 }
554 
555 inline int
556 ffz32(uint_least32_t x)
557 {
558  return ffs32(~x);
559 }
560 
561 inline int
562 ffs64(uint_least64_t x)
563 {
564  x &= UINT64_C(0xffffffffffffffff);
565 #if defined(_MSC_VER) && _WIN64
566  unsigned long Index;
567  return _BitScanForward64(&Index, x) ? Index + 1 : 0;
568 #elif (defined(__GNUC__) || __has_builtin(__builtin_ffsl)) && LONG_BIT == 64
569  return __builtin_ffsl(x);
570 #elif defined(__GNUC__) || __has_builtin(__builtin_ffsll)
571  return __builtin_ffsll(x);
572 #else
573  // clang-format off
574  return x ? ((x & UINT32_C(0xffffffff))
575  ? ffs32((uint_least32_t)x) : ffs32(x >> 32) + 32) : 0;
576  // clang-format on
577 #endif
578 }
579 
580 inline int
581 ffz64(uint_least64_t x)
582 {
583  return ffs64(~x);
584 }
585 
586 #if defined(__GNUC__) || __has_builtin(__builtin_parity)
587 inline int
588 parity8(uint_least8_t x)
589 {
590  x &= UINT8_C(0xff);
591  return __builtin_parity(x);
592 }
593 #endif // __GNUC__ || __has_builtin(__builtin_parity)
594 
595 inline int
596 parity16(uint_least16_t x)
597 {
598  x &= UINT16_C(0xffff);
599 #if defined(__GNUC__) || __has_builtin(__builtin_parity)
600  return __builtin_parity(x);
601 #else
602  return parity8((uint_least8_t)x) ^ parity8(x >> 8);
603 #endif
604 }
605 
606 inline int
607 parity32(uint_least32_t x)
608 {
609  x &= UINT32_C(0xffffffff);
610 #if (defined(__GNUC__) || __has_builtin(__builtin_parity)) && __WORDSIZE == 64
611  return __builtin_parity(x);
612 #elif defined(__GNUC__) || __has_builtin(__builtin_parityl)
613  return __builtin_parityl(x);
614 #else
615  return parity16((uint_least16_t)x) ^ parity16(x >> 16);
616 #endif
617 }
618 
619 inline int
620 parity64(uint_least64_t x)
621 {
622  x &= UINT64_C(0xffffffffffffffff);
623 #if (defined(__GNUC__) || __has_builtin(__builtin_parityl)) && LONG_BIT == 64
624  return __builtin_parityl(x);
625 #elif defined(__GNUC__) || __has_builtin(__builtin_parityll)
626  return __builtin_parityll(x);
627 #else
628  return parity32((uint_least32_t)x) ^ parity32(x >> 32);
629 #endif
630 }
631 
632 #if defined(__GNUC__) || __has_builtin(__builtin_popcount)
633 inline int
634 popcount8(uint_least8_t x)
635 {
636  x &= UINT8_C(0xff);
637  return __builtin_popcount(x);
638 }
639 #endif // __GNUC__ || __has_builtin(__builtin_popcount)
640 
641 inline int
642 popcount16(uint_least16_t x)
643 {
644  x &= UINT16_C(0xffff);
645 #if defined(__GNUC__) || __has_builtin(__builtin_popcount)
646  return __builtin_popcount(x);
647 #else
648  return popcount8((uint_least8_t)x) + popcount8(x >> 8);
649 #endif
650 }
651 
652 inline int
653 popcount32(uint_least32_t x)
654 {
655  x &= UINT32_C(0xffffffff);
656 #if (defined(__GNUC__) || __has_builtin(__builtin_popcount)) && __WORDSIZE == 64
657  return __builtin_popcount(x);
658 #elif defined(__GNUC__) || __has_builtin(__builtin_popcountl)
659  return __builtin_popcountl(x);
660 #else
661  return popcount16((uint_least16_t)x) + popcount16(x >> 16);
662 #endif
663 }
664 
665 inline int
666 popcount64(uint_least64_t x)
667 {
668  x &= UINT64_C(0xffffffffffffffff);
669 #if (defined(__GNUC__) || __has_builtin(__builtin_popcountl)) && LONG_BIT == 64
670  return __builtin_popcountl(x);
671 #elif defined(__GNUC__) || __has_builtin(__builtin_popcountll)
672  return __builtin_popcountll(x);
673 #else
674  return popcount32((uint_least32_t)x) + popcount32(x >> 32);
675 #endif
676 }
677 
678 inline uint_least8_t
679 rol8(uint_least8_t x, unsigned int n)
680 {
681  x &= UINT8_C(0xff);
682  n %= 8;
683 #ifdef _MSC_VER
684  return _rotl8(x, n);
685 #else
686  return n ? (x << n) | (x >> (8 - n)) : x;
687 #endif
688 }
689 
690 inline uint_least8_t
691 ror8(uint_least8_t x, unsigned int n)
692 {
693  x &= UINT8_C(0xff);
694  n %= 8;
695 #ifdef _MSC_VER
696  return _rotr8(x, n);
697 #else
698  return n ? (x >> n) | (x << (8 - n)) : x;
699 #endif
700 }
701 
702 inline uint_least16_t
703 rol16(uint_least16_t x, unsigned int n)
704 {
705  x &= UINT16_C(0xffff);
706  n %= 16;
707 #ifdef _MSC_VER
708  return _rotl16(x, n);
709 #else
710  return n ? (x << n) | (x >> (16 - n)) : x;
711 #endif
712 }
713 
714 inline uint_least16_t
715 ror16(uint_least16_t x, unsigned int n)
716 {
717  x &= UINT16_C(0xffff);
718  n %= 16;
719 #ifdef _MSC_VER
720  return _rotr16(x, n);
721 #else
722  return n ? (x >> n) | (x << (16 - n)) : x;
723 #endif
724 }
725 
726 inline uint_least32_t
727 rol32(uint_least32_t x, unsigned int n)
728 {
729  x &= UINT32_C(0xffffffff);
730  n %= 32;
731 #ifdef _MSC_VER
732  return _rotl(x, n);
733 #else
734  return n ? (x << n) | (x >> (32 - n)) : x;
735 #endif
736 }
737 
738 inline uint_least32_t
739 ror32(uint_least32_t x, unsigned int n)
740 {
741  x &= UINT32_C(0xffffffff);
742  n %= 32;
743 #ifdef _MSC_VER
744  return _rotr(x, n);
745 #else
746  return n ? (x >> n) | (x << (32 - n)) : x;
747 #endif
748 }
749 
750 inline uint_least64_t
751 rol64(uint_least64_t x, unsigned int n)
752 {
753  x &= UINT64_C(0xffffffffffffffff);
754  n %= 64;
755 #ifdef _MSC_VER
756  return _rotl64(x, n);
757 #else
758  return n ? (x << n) | (x >> (64 - n)) : x;
759 #endif
760 }
761 
762 inline uint_least64_t
763 ror64(uint_least64_t x, unsigned int n)
764 {
765  x &= UINT64_C(0xffffffffffffffff);
766  n %= 64;
767 #ifdef _MSC_VER
768  return _rotr64(x, n);
769 #else
770  return n ? (x >> n) | (x << (64 - n)) : x;
771 #endif
772 }
773 
774 #ifdef __cplusplus
775 }
776 #endif
777 
778 #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:472
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:739
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:715
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:514
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:581
int cts8(uint_least8_t x)
Counts the number of trailing set bits in the unsigned 8-bit integer x.
Definition: bits.h:407
int parity16(uint_least16_t x)
Returns the parity of the unsigned 16-bit integer x.
Definition: bits.h:596
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:495
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:763
int ctz32(uint_least32_t x)
Counts the number of trailing zero bits in the unsigned 32-bit integer x.
Definition: bits.h:453
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:562
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:691
int cts32(uint_least32_t x)
Counts the number of trailing set bits in the unsigned 32-bit integer x.
Definition: bits.h:447
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:478
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:653
int cts16(uint_least16_t x)
Counts the number of trailing set bits in the unsigned 16-bit integer x.
Definition: bits.h:427
int cls64(uint_least64_t x)
Counts the number of leading set bits in the unsigned 64-bit integer x.
Definition: bits.h:385
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:588
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:727
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:679
int clz64(uint_least64_t x)
Counts the number of leading zero bits in the unsigned 64-bit integer x.
Definition: bits.h:391
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:508
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:537
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:607
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:556
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:531
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:666
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:703
int parity64(uint_least64_t x)
Returns the parity of the unsigned 64-bit integer x.
Definition: bits.h:620
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:751
int ctz16(uint_least16_t x)
Counts the number of trailing zero bits in the unsigned 16-bit integer x.
Definition: bits.h:433
int ctz8(uint_least8_t x)
Counts the number of trailing zero bits in the unsigned 8-bit integer x.
Definition: bits.h:414
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:642
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:634
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....