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
39extern "C" {
40#endif
41
43LELY_UTIL_BITS_INLINE uint_least16_t bswap16(uint_least16_t x);
44
46LELY_UTIL_BITS_INLINE uint_least32_t bswap32(uint_least32_t x);
47
49LELY_UTIL_BITS_INLINE uint_least64_t bswap64(uint_least64_t x);
53LELY_UTIL_BITS_INLINE int cls8(uint_least8_t x);
54
59#if defined(_MSC_VER) || defined(__GNUC__) || __has_builtin(__builtin_clz)
60LELY_UTIL_BITS_INLINE int clz8(uint_least8_t x);
61#else
62int clz8(uint_least8_t x);
63#endif
64
69LELY_UTIL_BITS_INLINE int cls16(uint_least16_t x);
70
75LELY_UTIL_BITS_INLINE int clz16(uint_least16_t x);
76
81LELY_UTIL_BITS_INLINE int cls32(uint_least32_t x);
82
87LELY_UTIL_BITS_INLINE int clz32(uint_least32_t x);
88
93LELY_UTIL_BITS_INLINE int cls64(uint_least64_t x);
94
99LELY_UTIL_BITS_INLINE int clz64(uint_least64_t x);
100
105LELY_UTIL_BITS_INLINE int cts8(uint_least8_t x);
106
111#if defined(_MSC_VER) || defined(__GNUC__) || __has_builtin(__builtin_ctz)
112LELY_UTIL_BITS_INLINE int ctz8(uint_least8_t x);
113#else
114int ctz8(uint_least8_t x);
115#endif
116
121LELY_UTIL_BITS_INLINE int cts16(uint_least16_t x);
122
127LELY_UTIL_BITS_INLINE int ctz16(uint_least16_t x);
128
133LELY_UTIL_BITS_INLINE int cts32(uint_least32_t x);
134
139LELY_UTIL_BITS_INLINE int ctz32(uint_least32_t x);
140
145LELY_UTIL_BITS_INLINE int cts64(uint_least64_t x);
146
151LELY_UTIL_BITS_INLINE int ctz64(uint_least64_t x);
152
157#if defined(_MSC_VER) || defined(__GNUC__) || __has_builtin(__builtin_ffs)
158LELY_UTIL_BITS_INLINE int ffs8(uint_least8_t x);
159#else
160int ffs8(uint_least8_t x);
161#endif
162
167LELY_UTIL_BITS_INLINE int ffz8(uint_least8_t x);
168
173LELY_UTIL_BITS_INLINE int ffs16(uint_least16_t x);
174
179LELY_UTIL_BITS_INLINE int ffz16(uint_least16_t x);
180
185LELY_UTIL_BITS_INLINE int ffs32(uint_least32_t x);
186
191LELY_UTIL_BITS_INLINE int ffz32(uint_least32_t x);
192
197LELY_UTIL_BITS_INLINE int ffs64(uint_least64_t x);
198
203LELY_UTIL_BITS_INLINE int ffz64(uint_least64_t x);
204
206#if defined(__GNUC__) || __has_builtin(__builtin_parity)
207LELY_UTIL_BITS_INLINE int parity8(uint_least8_t x);
208#else
209int parity8(uint_least8_t x);
210#endif
211
213LELY_UTIL_BITS_INLINE int parity16(uint_least16_t x);
214
216LELY_UTIL_BITS_INLINE int parity32(uint_least32_t x);
217
219LELY_UTIL_BITS_INLINE int parity64(uint_least64_t x);
220
225#if defined(__GNUC__) || __has_builtin(__builtin_popcount)
226LELY_UTIL_BITS_INLINE int popcount8(uint_least8_t x);
227#else
228int popcount8(uint_least8_t x);
229#endif
230
235LELY_UTIL_BITS_INLINE int popcount16(uint_least16_t x);
236
241LELY_UTIL_BITS_INLINE int popcount32(uint_least32_t x);
242
247LELY_UTIL_BITS_INLINE int popcount64(uint_least64_t x);
248
250LELY_UTIL_BITS_INLINE uint_least8_t rol8(uint_least8_t x, unsigned int n);
251
253LELY_UTIL_BITS_INLINE uint_least8_t ror8(uint_least8_t x, unsigned int n);
254
256LELY_UTIL_BITS_INLINE uint_least16_t rol16(uint_least16_t x, unsigned int n);
257
259LELY_UTIL_BITS_INLINE uint_least16_t ror16(uint_least16_t x, unsigned int n);
260
262LELY_UTIL_BITS_INLINE uint_least32_t rol32(uint_least32_t x, unsigned int n);
263
265LELY_UTIL_BITS_INLINE uint_least32_t ror32(uint_least32_t x, unsigned int n);
266
268LELY_UTIL_BITS_INLINE uint_least64_t rol64(uint_least64_t x, unsigned int n);
269
271LELY_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
283inline uint_least16_t
284bswap16(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
295inline uint_least32_t
296bswap32(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
307inline 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 LELY_UTIL_DEFINE_BSWAP_IMPL(uint_least64_t)
316#endif
317}
318
319#undef LELY_UTIL_DEFINE_BSWAP_IMPL
320
321inline int
322cls8(uint_least8_t x)
323{
324 return clz8(~x);
325}
326
327#if defined(_MSC_VER) || defined(__GNUC__) || __has_builtin(__builtin_clz)
328inline int
329clz8(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
341inline int
342cls16(uint_least16_t x)
343{
344 return clz16(~x);
345}
346
347inline int
348clz16(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
361inline int
362cls32(uint_least32_t x)
363{
364 return clz32(~x);
365}
366
367inline int
368clz32(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
383inline int
384cls64(uint_least64_t x)
385{
386 return clz64(~x);
387}
388
389inline int
390clz64(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
405inline int
406cts8(uint_least8_t x)
407{
408 return ctz8(~x);
409}
410
411#if defined(_MSC_VER) || defined(__GNUC__) || __has_builtin(__builtin_ctz)
412inline int
413ctz8(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
425inline int
426cts16(uint_least16_t x)
427{
428 return ctz16(~x);
429}
430
431inline int
432ctz16(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
445inline int
446cts32(uint_least32_t x)
447{
448 return ctz32(~x);
449}
450
451inline int
452ctz32(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
470inline int
471cts64(uint_least64_t x)
472{
473 return ctz64(~x);
474}
475
476inline int
477ctz64(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)
493inline int
494ffs8(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
506inline int
507ffz8(uint_least8_t x)
508{
509 return ffs8(~x);
510}
511
512inline int
513ffs16(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
529inline int
530ffz16(uint_least16_t x)
531{
532 return ffs16(~x);
533}
534
535inline int
536ffs32(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
554inline int
555ffz32(uint_least32_t x)
556{
557 return ffs32(~x);
558}
559
560inline int
561ffs64(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
579inline int
580ffz64(uint_least64_t x)
581{
582 return ffs64(~x);
583}
584
585#if defined(__GNUC__) || __has_builtin(__builtin_parity)
586inline int
587parity8(uint_least8_t x)
588{
589 x &= UINT8_C(0xff);
590 return __builtin_parity(x);
591}
592#endif // __GNUC__ || __has_builtin(__builtin_parity)
593
594inline int
595parity16(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
605inline int
606parity32(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
618inline int
619parity64(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)
632inline int
633popcount8(uint_least8_t x)
634{
635 x &= UINT8_C(0xff);
636 return __builtin_popcount(x);
637}
638#endif // __GNUC__ || __has_builtin(__builtin_popcount)
639
640inline int
641popcount16(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
651inline int
652popcount32(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
664inline int
665popcount64(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
678inline uint_least8_t
679rol8(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
690inline uint_least8_t
691ror8(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
702inline uint_least16_t
703rol16(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
714inline uint_least16_t
715ror16(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
726inline uint_least32_t
727rol32(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
738inline uint_least32_t
739ror32(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
750inline uint_least64_t
751rol64(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
762inline uint_least64_t
763ror64(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: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
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:513
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
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 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
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:452
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 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_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:446
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 ctz64(uint_least64_t x)
Counts the number of trailing zero bits in the unsigned 64-bit integer x.
Definition: bits.h:477
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 cts16(uint_least16_t x)
Counts the number of trailing set bits in the unsigned 16-bit integer x.
Definition: bits.h:426
int cls64(uint_least64_t x)
Counts the number of leading set bits in the unsigned 64-bit integer x.
Definition: bits.h:384
uint_least16_t bswap16(uint_least16_t x)
Reverses the byte order of the 16-bit unsigned integer x.
Definition: bits.h:284
int parity8(uint_least8_t x)
Returns the parity of the unsigned 8-bit integer x.
Definition: bits.h:587
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:390
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
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 clz32(uint_least32_t x)
Counts the number of leading zero bits in the unsigned 32-bit integer x.
Definition: bits.h:368
int parity32(uint_least32_t x)
Returns the parity of the unsigned 32-bit integer x.
Definition: bits.h:606
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 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
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
int cls32(uint_least32_t x)
Counts the number of leading set bits in the unsigned 32-bit integer x.
Definition: bits.h:362
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
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:619
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:432
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 cls8(uint_least8_t x)
Counts the number of leading set bits in the unsigned 8-bit integer x.
Definition: bits.h:322
uint_least32_t bswap32(uint_least32_t x)
Reverses the byte order of the 32-bit unsigned integer x.
Definition: bits.h:296
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
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
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....