Lely core libraries  1.9.2
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 
43 LELY_UTIL_BITS_INLINE uint_least16_t bswap16(uint_least16_t x);
44 
46 LELY_UTIL_BITS_INLINE uint_least32_t bswap32(uint_least32_t x);
47 
49 LELY_UTIL_BITS_INLINE uint_least64_t bswap64(uint_least64_t x);
53 LELY_UTIL_BITS_INLINE int cls8(uint_least8_t x);
54 
59 #if defined(_MSC_VER) || defined(__GNUC__) || __has_builtin(__builtin_clz)
60 LELY_UTIL_BITS_INLINE int clz8(uint_least8_t x);
61 #else
62 int clz8(uint_least8_t x);
63 #endif
64 
69 LELY_UTIL_BITS_INLINE int cls16(uint_least16_t x);
70 
75 LELY_UTIL_BITS_INLINE int clz16(uint_least16_t x);
76 
81 LELY_UTIL_BITS_INLINE int cls32(uint_least32_t x);
82 
87 LELY_UTIL_BITS_INLINE int clz32(uint_least32_t x);
88 
93 LELY_UTIL_BITS_INLINE int cls64(uint_least64_t x);
94 
99 LELY_UTIL_BITS_INLINE int clz64(uint_least64_t x);
100 
105 LELY_UTIL_BITS_INLINE int cts8(uint_least8_t x);
106 
111 #if defined(_MSC_VER) || defined(__GNUC__) || __has_builtin(__builtin_ctz)
112 LELY_UTIL_BITS_INLINE int ctz8(uint_least8_t x);
113 #else
114 int ctz8(uint_least8_t x);
115 #endif
116 
121 LELY_UTIL_BITS_INLINE int cts16(uint_least16_t x);
122 
127 LELY_UTIL_BITS_INLINE int ctz16(uint_least16_t x);
128 
133 LELY_UTIL_BITS_INLINE int cts32(uint_least32_t x);
134 
139 LELY_UTIL_BITS_INLINE int ctz32(uint_least32_t x);
140 
145 LELY_UTIL_BITS_INLINE int cts64(uint_least64_t x);
146 
151 LELY_UTIL_BITS_INLINE int ctz64(uint_least64_t x);
152 
157 #if defined(_MSC_VER) || defined(__GNUC__) || __has_builtin(__builtin_ffs)
158 LELY_UTIL_BITS_INLINE int ffs8(uint_least8_t x);
159 #else
160 int ffs8(uint_least8_t x);
161 #endif
162 
167 LELY_UTIL_BITS_INLINE int ffz8(uint_least8_t x);
168 
173 LELY_UTIL_BITS_INLINE int ffs16(uint_least16_t x);
174 
179 LELY_UTIL_BITS_INLINE int ffz16(uint_least16_t x);
180 
185 LELY_UTIL_BITS_INLINE int ffs32(uint_least32_t x);
186 
191 LELY_UTIL_BITS_INLINE int ffz32(uint_least32_t x);
192 
197 LELY_UTIL_BITS_INLINE int ffs64(uint_least64_t x);
198 
203 LELY_UTIL_BITS_INLINE int ffz64(uint_least64_t x);
204 
206 #if defined(__GNUC__) || __has_builtin(__builtin_parity)
207 LELY_UTIL_BITS_INLINE int parity8(uint_least8_t x);
208 #else
209 int parity8(uint_least8_t x);
210 #endif
211 
213 LELY_UTIL_BITS_INLINE int parity16(uint_least16_t x);
214 
216 LELY_UTIL_BITS_INLINE int parity32(uint_least32_t x);
217 
219 LELY_UTIL_BITS_INLINE int parity64(uint_least64_t x);
220 
225 #if defined(__GNUC__) || __has_builtin(__builtin_popcount)
226 LELY_UTIL_BITS_INLINE int popcount8(uint_least8_t x);
227 #else
228 int popcount8(uint_least8_t x);
229 #endif
230 
235 LELY_UTIL_BITS_INLINE int popcount16(uint_least16_t x);
236 
241 LELY_UTIL_BITS_INLINE int popcount32(uint_least32_t x);
242 
247 LELY_UTIL_BITS_INLINE int popcount64(uint_least64_t x);
248 
250 LELY_UTIL_BITS_INLINE uint_least8_t rol8(uint_least8_t x, unsigned int n);
251 
253 LELY_UTIL_BITS_INLINE uint_least8_t ror8(uint_least8_t x, unsigned int n);
254 
256 LELY_UTIL_BITS_INLINE uint_least16_t rol16(uint_least16_t x, unsigned int n);
257 
259 LELY_UTIL_BITS_INLINE uint_least16_t ror16(uint_least16_t x, unsigned int n);
260 
262 LELY_UTIL_BITS_INLINE uint_least32_t rol32(uint_least32_t x, unsigned int n);
263 
265 LELY_UTIL_BITS_INLINE uint_least32_t ror32(uint_least32_t x, unsigned int n);
266 
268 LELY_UTIL_BITS_INLINE uint_least64_t rol64(uint_least64_t x, unsigned int n);
269 
271 LELY_UTIL_BITS_INLINE uint_least64_t ror64(uint_least64_t x, unsigned int n);
272 
273 #define LELY_UTIL_DEFINE_BSWAP_IMPL(type) \
274  type r = 0; \
275  for (unsigned int i = 0; i < sizeof(x) / 2; i++) \
276  r |= (x & ((type)UCHAR_MAX << (i * CHAR_BIT))) \
277  << ((sizeof(x) - 2 * i - 1) * CHAR_BIT); \
278  for (unsigned int i = sizeof(x) / 2; i < sizeof(x); i++) \
279  r |= (x & ((type)UCHAR_MAX << (i * CHAR_BIT))) \
280  >> ((2 * i + 1 - sizeof(x)) * CHAR_BIT); \
281  return r;
282 
283 inline uint_least16_t
284 bswap16(uint_least16_t x)
285 {
286 #ifdef _MSC_VER
287  return _byteswap_ushort(x);
288 #elif GNUC_PREREQ(4, 8) || __has_builtin(__builtin_bswap16)
289  return __builtin_bswap16(x);
290 #else
291  LELY_UTIL_DEFINE_BSWAP_IMPL(uint_least16_t)
292 #endif
293 }
294 
295 inline uint_least32_t
296 bswap32(uint_least32_t x)
297 {
298 #ifdef _MSC_VER
299  return _byteswap_ulong(x);
300 #elif GNUC_PREREQ(4, 3) || __has_builtin(__builtin_bswap32)
301  return __builtin_bswap32(x);
302 #else
303  LELY_UTIL_DEFINE_BSWAP_IMPL(uint_least32_t)
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  LELY_UTIL_DEFINE_BSWAP_IMPL(uint_least64_t)
316 #endif
317 }
318 
319 #undef LELY_UTIL_DEFINE_BSWAP_IMPL
320 
321 inline int
322 cls8(uint_least8_t x)
323 {
324  return clz8(~x);
325 }
326 
327 #if defined(_MSC_VER) || defined(__GNUC__) || __has_builtin(__builtin_clz)
328 inline int
329 clz8(uint_least8_t x)
330 {
331  x &= UINT8_C(0xff);
332 #ifdef _MSC_VER
333  unsigned long Index;
334  return _BitScanReverse(&Index, x) ? 7 - Index : 8;
335 #elif defined(__GNUC__) || __has_builtin(__builtin_clz)
336  return x ? __builtin_clz(x) - 24 : 8;
337 #endif
338 }
339 #endif // _MSC_VER || __GNUC__ || __has_builtin(__builtin_clz)
340 
341 inline int
342 cls16(uint_least16_t x)
343 {
344  return clz16(~x);
345 }
346 
347 inline int
348 clz16(uint_least16_t x)
349 {
350  x &= UINT16_C(0xffff);
351 #ifdef _MSC_VER
352  unsigned long Index;
353  return _BitScanReverse(&Index, x) ? 15 - Index : 16;
354 #elif defined(__GNUC__) || __has_builtin(__builtin_clz)
355  return x ? __builtin_clz(x) - 16 : 16;
356 #else
357  return (x >> 8) ? clz8(x >> 8) : clz8((uint_least8_t)x) + 8;
358 #endif
359 }
360 
361 inline int
362 cls32(uint_least32_t x)
363 {
364  return clz32(~x);
365 }
366 
367 inline int
368 clz32(uint_least32_t x)
369 {
370  x &= UINT32_C(0xffffffff);
371 #ifdef _MSC_VER
372  unsigned long Index;
373  return _BitScanReverse(&Index, x) ? 31 - Index : 32;
374 #elif (defined(__GNUC__) || __has_builtin(__builtin_clz)) && __WORDSIZE == 64
375  return x ? __builtin_clz(x) : 32;
376 #elif defined(__GNUC__) || __has_builtin(__builtin_clzl)
377  return x ? __builtin_clzl(x) : 32;
378 #else
379  return (x >> 16) ? clz16(x >> 16) : clz16((uint_least16_t)x) + 16;
380 #endif
381 }
382 
383 inline int
384 cls64(uint_least64_t x)
385 {
386  return clz64(~x);
387 }
388 
389 inline int
390 clz64(uint_least64_t x)
391 {
392  x &= UINT64_C(0xffffffffffffffff);
393 #if defined(_MSC_VER) && _WIN64
394  unsigned long Index;
395  return _BitScanReverse64(&Index, x) ? 63 - Index : 64;
396 #elif (defined(__GNUC__) || __has_builtin(__builtin_clzl)) && __WORDSIZE == 64
397  return x ? __builtin_clzl(x) : 64;
398 #elif defined(__GNUC__) || __has_builtin(__builtin_clzll)
399  return x ? __builtin_clzll(x) : 64;
400 #else
401  return (x >> 32) ? clz32(x >> 32) : clz32((uint_least32_t)x) + 32;
402 #endif
403 }
404 
405 inline int
406 cts8(uint_least8_t x)
407 {
408  return ctz8(~x);
409 }
410 
411 #if defined(_MSC_VER) || defined(__GNUC__) || __has_builtin(__builtin_ctz)
412 inline int
413 ctz8(uint_least8_t x)
414 {
415  x &= UINT8_C(0xff);
416 #ifdef _MSC_VER
417  unsigned long Index;
418  return _BitScanForward(&Index, x) ? Index : 8;
419 #elif defined(__GNUC__) || __has_builtin(__builtin_ctz)
420  return x ? __builtin_ctz(x) : 8;
421 #endif
422 }
423 #endif // _MSC_VER || __GNUC__ || __has_builtin(__builtin_ctz)
424 
425 inline int
426 cts16(uint_least16_t x)
427 {
428  return ctz16(~x);
429 }
430 
431 inline int
432 ctz16(uint_least16_t x)
433 {
434  x &= UINT16_C(0xffff);
435 #ifdef _MSC_VER
436  unsigned long Index;
437  return _BitScanForward(&Index, x) ? Index : 16;
438 #elif defined(__GNUC__) || __has_builtin(__builtin_ctz)
439  return x ? __builtin_ctz(x) : 16;
440 #else
441  return (x & 0xff) ? ctz8((uint_least8_t)x) : ctz8(x >> 8) + 8;
442 #endif
443 }
444 
445 inline int
446 cts32(uint_least32_t x)
447 {
448  return ctz32(~x);
449 }
450 
451 inline int
452 ctz32(uint_least32_t x)
453 {
454  x &= UINT32_C(0xffffffff);
455 #ifdef _MSC_VER
456  unsigned long Index;
457  return _BitScanForward(&Index, x) ? Index : 32;
458 #elif (defined(__GNUC__) || __has_builtin(__builtin_ctz)) && __WORDSIZE == 64
459  return x ? __builtin_ctz(x) : 32;
460 #elif defined(__GNUC__) || __has_builtin(__builtin_ctzl)
461  return x ? __builtin_ctzl(x) : 32;
462 #else
463  // clang-format off
464  return (x & UINT16_C(0xffff))
465  ? ctz16((uint_least16_t)x) : ctz16(x >> 16) + 16;
466  // clang-format on
467 #endif
468 }
469 
470 inline int
471 cts64(uint_least64_t x)
472 {
473  return ctz64(~x);
474 }
475 
476 inline int
477 ctz64(uint_least64_t x)
478 {
479  x &= UINT64_C(0xffffffffffffffff);
480 #if (defined(__GNUC__) || __has_builtin(__builtin_ctzl)) && __WORDSIZE == 64
481  return x ? __builtin_ctzl(x) : 64;
482 #elif defined(__GNUC__) || __has_builtin(__builtin_ctzll)
483  return x ? __builtin_ctzll(x) : 64;
484 #else
485  // clang-format off
486  return (x & UINT32_C(0xffffffff))
487  ? ctz32((uint_least32_t)x) : ctz32(x >> 32) + 32;
488  // clang-format on
489 #endif
490 }
491 
492 #if defined(_MSC_VER) || defined(__GNUC__) || __has_builtin(__builtin_ffs)
493 inline int
494 ffs8(uint_least8_t x)
495 {
496  x &= UINT8_C(0xff);
497 #ifdef _MSC_VER
498  unsigned long Index;
499  return _BitScanForward(&Index, x) ? Index + 1 : 0;
500 #elif defined(__GNUC__) || __has_builtin(__builtin_ffs)
501  return __builtin_ffs(x);
502 #endif
503 }
504 #endif // _MSC_VER || __GNUC__ || __has_builtin(__builtin_ffs)
505 
506 inline int
507 ffz8(uint_least8_t x)
508 {
509  return ffs8(~x);
510 }
511 
512 inline int
513 ffs16(uint_least16_t x)
514 {
515  x &= UINT16_C(0xffff);
516 #ifdef _MSC_VER
517  unsigned long Index;
518  return _BitScanForward(&Index, x) ? Index + 1 : 0;
519 #elif defined(__GNUC__) || __has_builtin(__builtin_ffs)
520  return __builtin_ffs(x);
521 #else
522  // clang-format off
523  return x ? ((x & UINT8_C(0xff))
524  ? ffs8((uint_least8_t)x) : ffs8(x >> 8) + 8) : 0;
525  // clang-format on
526 #endif
527 }
528 
529 inline int
530 ffz16(uint_least16_t x)
531 {
532  return ffs16(~x);
533 }
534 
535 inline int
536 ffs32(uint_least32_t x)
537 {
538  x &= UINT32_C(0xffffffff);
539 #ifdef _MSC_VER
540  unsigned long Index;
541  return _BitScanForward(&Index, x) ? Index + 1 : 0;
542 #elif (defined(__GNUC__) || __has_builtin(__builtin_ffs)) && __WORDSIZE == 64
543  return __builtin_ffs(x);
544 #elif defined(__GNUC__) || __has_builtin(__builtin_ffsl)
545  return __builtin_ffsl(x);
546 #else
547  // clang-format off
548  return x ? ((x & UINT16_C(0xffff))
549  ? ffs16((uint_least16_t)x) : ffs16(x >> 16) + 16) : 0;
550  // clang-format on
551 #endif
552 }
553 
554 inline int
555 ffz32(uint_least32_t x)
556 {
557  return ffs32(~x);
558 }
559 
560 inline int
561 ffs64(uint_least64_t x)
562 {
563  x &= UINT64_C(0xffffffffffffffff);
564 #if defined(_MSC_VER) && _WIN64
565  unsigned long Index;
566  return _BitScanForward64(&Index, x) ? Index + 1 : 0;
567 #elif (defined(__GNUC__) || __has_builtin(__builtin_ffsl)) && __WORDSIZE == 64
568  return __builtin_ffsl(x);
569 #elif defined(__GNUC__) || __has_builtin(__builtin_ffsll)
570  return __builtin_ffsll(x);
571 #else
572  // clang-format off
573  return x ? ((x & UINT32_C(0xffffffff))
574  ? ffs32((uint_least32_t)x) : ffs32(x >> 32) + 32) : 0;
575  // clang-format on
576 #endif
577 }
578 
579 inline int
580 ffz64(uint_least64_t x)
581 {
582  return ffs64(~x);
583 }
584 
585 #if defined(__GNUC__) || __has_builtin(__builtin_parity)
586 inline int
587 parity8(uint_least8_t x)
588 {
589  x &= UINT8_C(0xff);
590  return __builtin_parity(x);
591 }
592 #endif // __GNUC__ || __has_builtin(__builtin_parity)
593 
594 inline int
595 parity16(uint_least16_t x)
596 {
597  x &= UINT16_C(0xffff);
598 #if defined(__GNUC__) || __has_builtin(__builtin_parity)
599  return __builtin_parity(x);
600 #else
601  return parity8((uint_least8_t)x) ^ parity8(x >> 8);
602 #endif
603 }
604 
605 inline int
606 parity32(uint_least32_t x)
607 {
608  x &= UINT32_C(0xffffffff);
609 #if (defined(__GNUC__) || __has_builtin(__builtin_parity)) && __WORDSIZE == 64
610  return __builtin_parity(x);
611 #elif defined(__GNUC__) || __has_builtin(__builtin_parityl)
612  return __builtin_parityl(x);
613 #else
614  return parity16((uint_least16_t)x) ^ parity16(x >> 16);
615 #endif
616 }
617 
618 inline int
619 parity64(uint_least64_t x)
620 {
621  x &= UINT64_C(0xffffffffffffffff);
622 #if (defined(__GNUC__) || __has_builtin(__builtin_parityl)) && __WORDSIZE == 64
623  return __builtin_parityl(x);
624 #elif defined(__GNUC__) || __has_builtin(__builtin_parityll)
625  return __builtin_parityll(x);
626 #else
627  return parity32((uint_least32_t)x) ^ parity32(x >> 32);
628 #endif
629 }
630 
631 #if defined(__GNUC__) || __has_builtin(__builtin_popcount)
632 inline int
633 popcount8(uint_least8_t x)
634 {
635  x &= UINT8_C(0xff);
636  return __builtin_popcount(x);
637 }
638 #endif // __GNUC__ || __has_builtin(__builtin_popcount)
639 
640 inline int
641 popcount16(uint_least16_t x)
642 {
643  x &= UINT16_C(0xffff);
644 #if defined(__GNUC__) || __has_builtin(__builtin_popcount)
645  return __builtin_popcount(x);
646 #else
647  return popcount8((uint_least8_t)x) + popcount8(x >> 8);
648 #endif
649 }
650 
651 inline int
652 popcount32(uint_least32_t x)
653 {
654  x &= UINT32_C(0xffffffff);
655 #if (defined(__GNUC__) || __has_builtin(__builtin_popcount)) && __WORDSIZE == 64
656  return __builtin_popcount(x);
657 #elif defined(__GNUC__) || __has_builtin(__builtin_popcountl)
658  return __builtin_popcountl(x);
659 #else
660  return popcount16((uint_least16_t)x) + popcount16(x >> 16);
661 #endif
662 }
663 
664 inline int
665 popcount64(uint_least64_t x)
666 {
667  x &= UINT64_C(0xffffffffffffffff);
668 #if (defined(__GNUC__) || __has_builtin(__builtin_popcountl)) \
669  && __WORDSIZE == 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 cts32(uint_least32_t x)
Counts the number of trailing set bits in the unsigned 32-bit integer x.
Definition: bits.h:446
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:665
int clz8(uint_least8_t x)
Counts the number of leading zero bits in the unsigned 8-bit integer x.
Definition: bits.h:329
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:555
uint_least64_t bswap64(uint_least64_t x)
Reverses the byte order of the 64-bit unsigned integer x.
Definition: bits.h:308
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:494
int cls16(uint_least16_t x)
Counts the number of leading set bits in the unsigned 16-bit integer x.
Definition: bits.h:342
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:652
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:633
int cts16(uint_least16_t x)
Counts the number of trailing set bits in the unsigned 16-bit integer x.
Definition: bits.h:426
int cts64(uint_least64_t x)
Counts the number of trailing set bits in the unsigned 64-bit integer x.
Definition: bits.h:471
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
int clz64(uint_least64_t x)
Counts the number of leading zero bits in the unsigned 64-bit integer x.
Definition: bits.h:390
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:561
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
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:536
int cts8(uint_least8_t x)
Counts the number of trailing set bits in the unsigned 8-bit integer x.
Definition: bits.h:406
int parity16(uint_least16_t x)
Returns the parity of the unsigned 16-bit integer x.
Definition: bits.h:595
int cls64(uint_least64_t x)
Counts the number of leading set bits in the unsigned 64-bit integer x.
Definition: bits.h:384
int cls32(uint_least32_t x)
Counts the number of leading set bits in the unsigned 32-bit integer x.
Definition: bits.h:362
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 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:513
int cls8(uint_least8_t x)
Counts the number of leading set bits in the unsigned 8-bit integer x.
Definition: bits.h:322
int parity32(uint_least32_t x)
Returns the parity of the unsigned 32-bit integer x.
Definition: bits.h:606
int ctz8(uint_least8_t x)
Counts the number of trailing zero bits in the unsigned 8-bit integer x.
Definition: bits.h:413
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:580
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
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
This header file is part of the C11 and POSIX compatibility library; it includes <stdint.h> and defines any missing functionality.
int ctz32(uint_least32_t x)
Counts the number of trailing zero bits in the unsigned 32-bit integer x.
Definition: bits.h:452
int clz32(uint_least32_t x)
Counts the number of leading zero bits in the unsigned 32-bit integer x.
Definition: bits.h:368
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:641
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
int parity64(uint_least64_t x)
Returns the parity of the unsigned 64-bit integer x.
Definition: bits.h:619
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:507
uint_least32_t bswap32(uint_least32_t x)
Reverses the byte order of the 32-bit unsigned integer x.
Definition: bits.h:296
uint_least16_t bswap16(uint_least16_t x)
Reverses the byte order of the 16-bit unsigned integer x.
Definition: bits.h:284
int clz16(uint_least16_t x)
Counts the number of leading zero bits in the unsigned 16-bit integer x.
Definition: bits.h:348
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:530
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
This header file is part of the C11 and POSIX compatibility library; it includes <stdlib.h> and defines any missing functionality.
int ctz16(uint_least16_t x)
Counts the number of trailing zero bits in the unsigned 16-bit integer x.
Definition: bits.h:432
This header file is part of the Lely libraries; it contains the compiler feature definitions.
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 parity8(uint_least8_t x)
Returns the parity of the unsigned 8-bit integer x.
Definition: bits.h:587
int ctz64(uint_least64_t x)
Counts the number of trailing zero bits in the unsigned 64-bit integer x.
Definition: bits.h:477