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
39extern "C" {
40#endif
41
46LELY_UTIL_BITS_INLINE uint_least16_t bswap16(uint_least16_t x);
47
52LELY_UTIL_BITS_INLINE uint_least32_t bswap32(uint_least32_t x);
53
58LELY_UTIL_BITS_INLINE uint_least64_t bswap64(uint_least64_t x);
62LELY_UTIL_BITS_INLINE int cls8(uint_least8_t x);
63
68#if defined(_MSC_VER) || defined(__GNUC__) || __has_builtin(__builtin_clz)
69LELY_UTIL_BITS_INLINE int clz8(uint_least8_t x);
70#else
71int clz8(uint_least8_t x);
72#endif
73
78LELY_UTIL_BITS_INLINE int cls16(uint_least16_t x);
79
84LELY_UTIL_BITS_INLINE int clz16(uint_least16_t x);
85
90LELY_UTIL_BITS_INLINE int cls32(uint_least32_t x);
91
96LELY_UTIL_BITS_INLINE int clz32(uint_least32_t x);
97
102LELY_UTIL_BITS_INLINE int cls64(uint_least64_t x);
103
108LELY_UTIL_BITS_INLINE int clz64(uint_least64_t x);
109
114LELY_UTIL_BITS_INLINE int cts8(uint_least8_t x);
115
120#if defined(_MSC_VER) || defined(__GNUC__) || __has_builtin(__builtin_ctz)
121LELY_UTIL_BITS_INLINE int ctz8(uint_least8_t x);
122#else
123int ctz8(uint_least8_t x);
124#endif
125
130LELY_UTIL_BITS_INLINE int cts16(uint_least16_t x);
131
136LELY_UTIL_BITS_INLINE int ctz16(uint_least16_t x);
137
142LELY_UTIL_BITS_INLINE int cts32(uint_least32_t x);
143
148LELY_UTIL_BITS_INLINE int ctz32(uint_least32_t x);
149
154LELY_UTIL_BITS_INLINE int cts64(uint_least64_t x);
155
160LELY_UTIL_BITS_INLINE int ctz64(uint_least64_t x);
161
166#if defined(_MSC_VER) || defined(__GNUC__) || __has_builtin(__builtin_ffs)
167LELY_UTIL_BITS_INLINE int ffs8(uint_least8_t x);
168#else
169int ffs8(uint_least8_t x);
170#endif
171
176LELY_UTIL_BITS_INLINE int ffz8(uint_least8_t x);
177
182LELY_UTIL_BITS_INLINE int ffs16(uint_least16_t x);
183
188LELY_UTIL_BITS_INLINE int ffz16(uint_least16_t x);
189
194LELY_UTIL_BITS_INLINE int ffs32(uint_least32_t x);
195
200LELY_UTIL_BITS_INLINE int ffz32(uint_least32_t x);
201
206LELY_UTIL_BITS_INLINE int ffs64(uint_least64_t x);
207
212LELY_UTIL_BITS_INLINE int ffz64(uint_least64_t x);
213
215#if defined(__GNUC__) || __has_builtin(__builtin_parity)
216LELY_UTIL_BITS_INLINE int parity8(uint_least8_t x);
217#else
218int parity8(uint_least8_t x);
219#endif
220
222LELY_UTIL_BITS_INLINE int parity16(uint_least16_t x);
223
225LELY_UTIL_BITS_INLINE int parity32(uint_least32_t x);
226
228LELY_UTIL_BITS_INLINE int parity64(uint_least64_t x);
229
234#if defined(__GNUC__) || __has_builtin(__builtin_popcount)
235LELY_UTIL_BITS_INLINE int popcount8(uint_least8_t x);
236#else
237int popcount8(uint_least8_t x);
238#endif
239
244LELY_UTIL_BITS_INLINE int popcount16(uint_least16_t x);
245
250LELY_UTIL_BITS_INLINE int popcount32(uint_least32_t x);
251
256LELY_UTIL_BITS_INLINE int popcount64(uint_least64_t x);
257
259LELY_UTIL_BITS_INLINE uint_least8_t rol8(uint_least8_t x, unsigned int n);
260
262LELY_UTIL_BITS_INLINE uint_least8_t ror8(uint_least8_t x, unsigned int n);
263
265LELY_UTIL_BITS_INLINE uint_least16_t rol16(uint_least16_t x, unsigned int n);
266
268LELY_UTIL_BITS_INLINE uint_least16_t ror16(uint_least16_t x, unsigned int n);
269
271LELY_UTIL_BITS_INLINE uint_least32_t rol32(uint_least32_t x, unsigned int n);
272
274LELY_UTIL_BITS_INLINE uint_least32_t ror32(uint_least32_t x, unsigned int n);
275
277LELY_UTIL_BITS_INLINE uint_least64_t rol64(uint_least64_t x, unsigned int n);
278
280LELY_UTIL_BITS_INLINE uint_least64_t ror64(uint_least64_t x, unsigned int n);
281
282LELY_UTIL_BITS_INLINE uint_least16_t
283bswap16(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
294LELY_UTIL_BITS_INLINE uint_least32_t
295bswap32(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
307LELY_UTIL_BITS_INLINE uint_least64_t
308bswap64(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
322LELY_UTIL_BITS_INLINE int
323cls8(uint_least8_t x)
324{
325 return clz8(~x);
326}
327
328#if defined(_MSC_VER) || defined(__GNUC__) || __has_builtin(__builtin_clz)
329LELY_UTIL_BITS_INLINE int
330clz8(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
342LELY_UTIL_BITS_INLINE int
343cls16(uint_least16_t x)
344{
345 return clz16(~x);
346}
347
348LELY_UTIL_BITS_INLINE int
349clz16(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
362LELY_UTIL_BITS_INLINE int
363cls32(uint_least32_t x)
364{
365 return clz32(~x);
366}
367
368LELY_UTIL_BITS_INLINE int
369clz32(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
385LELY_UTIL_BITS_INLINE int
386cls64(uint_least64_t x)
387{
388 return clz64(~x);
389}
390
391LELY_UTIL_BITS_INLINE int
392clz64(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
408LELY_UTIL_BITS_INLINE int
409cts8(uint_least8_t x)
410{
411 return ctz8(~x);
412}
413
414#if defined(_MSC_VER) || defined(__GNUC__) || __has_builtin(__builtin_ctz)
415LELY_UTIL_BITS_INLINE int
416ctz8(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
428LELY_UTIL_BITS_INLINE int
429cts16(uint_least16_t x)
430{
431 return ctz16(~x);
432}
433
434LELY_UTIL_BITS_INLINE int
435ctz16(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
449LELY_UTIL_BITS_INLINE int
450cts32(uint_least32_t x)
451{
452 return ctz32(~x);
453}
454
455LELY_UTIL_BITS_INLINE int
456ctz32(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
474LELY_UTIL_BITS_INLINE int
475cts64(uint_least64_t x)
476{
477 return ctz64(~x);
478}
479
480LELY_UTIL_BITS_INLINE int
481ctz64(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)
497LELY_UTIL_BITS_INLINE int
498ffs8(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
510LELY_UTIL_BITS_INLINE int
511ffz8(uint_least8_t x)
512{
513 return ffs8(~x);
514}
515
516LELY_UTIL_BITS_INLINE int
517ffs16(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
533LELY_UTIL_BITS_INLINE int
534ffz16(uint_least16_t x)
535{
536 return ffs16(~x);
537}
538
539LELY_UTIL_BITS_INLINE int
540ffs32(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
558LELY_UTIL_BITS_INLINE int
559ffz32(uint_least32_t x)
560{
561 return ffs32(~x);
562}
563
564LELY_UTIL_BITS_INLINE int
565ffs64(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
583LELY_UTIL_BITS_INLINE int
584ffz64(uint_least64_t x)
585{
586 return ffs64(~x);
587}
588
589#if defined(__GNUC__) || __has_builtin(__builtin_parity)
590LELY_UTIL_BITS_INLINE int
591parity8(uint_least8_t x)
592{
593 x &= UINT8_C(0xff);
594 return __builtin_parity(x);
595}
596#endif // __GNUC__ || __has_builtin(__builtin_parity)
597
598LELY_UTIL_BITS_INLINE int
599parity16(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
609LELY_UTIL_BITS_INLINE int
610parity32(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
622LELY_UTIL_BITS_INLINE int
623parity64(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)
636LELY_UTIL_BITS_INLINE int
637popcount8(uint_least8_t x)
638{
639 x &= UINT8_C(0xff);
640 return __builtin_popcount(x);
641}
642#endif // __GNUC__ || __has_builtin(__builtin_popcount)
643
644LELY_UTIL_BITS_INLINE int
645popcount16(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
655LELY_UTIL_BITS_INLINE int
656popcount32(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
668LELY_UTIL_BITS_INLINE int
669popcount64(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
681LELY_UTIL_BITS_INLINE uint_least8_t
682rol8(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
693LELY_UTIL_BITS_INLINE uint_least8_t
694ror8(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
705LELY_UTIL_BITS_INLINE uint_least16_t
706rol16(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
717LELY_UTIL_BITS_INLINE uint_least16_t
718ror16(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
729LELY_UTIL_BITS_INLINE uint_least32_t
730rol32(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
741LELY_UTIL_BITS_INLINE uint_least32_t
742ror32(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
753LELY_UTIL_BITS_INLINE uint_least64_t
754rol64(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
765LELY_UTIL_BITS_INLINE uint_least64_t
766ror64(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....