kit

kit
git clone https://git.ryansepassi.com/git/kit.git
Log | Files | Refs | README

builtin_32_portable_bits.c (1192B)


      1 typedef unsigned char u8;
      2 typedef unsigned short u16;
      3 typedef unsigned int u32;
      4 typedef unsigned long long u64;
      5 
      6 int test_main(void) {
      7   if (__builtin_popcount(0xf00fu) != 8) return 1;
      8   if (__builtin_popcountl((unsigned long)0x80000001ul) != 2) return 2;
      9   if (__builtin_popcountll(0xf00000000000000full) != 8) return 3;
     10 
     11   if (__builtin_bswap16((u16)0x1234u) != (u16)0x3412u) return 4;
     12   if (__builtin_bswap32(0x12345678u) != 0x78563412u) return 5;
     13   if (__builtin_bswap64(0x0123456789abcdefull) !=
     14       0xefcdab8967452301ull)
     15     return 6;
     16 
     17   if (__builtin_rotateleft8((u8)0x81u, 1) != (u8)0x03u) return 7;
     18   if (__builtin_rotateright16((u16)0x0003u, 1) != (u16)0x8001u) return 8;
     19   if (__builtin_rotateleft32(0x12345678u, 36) != 0x23456781u) return 9;
     20   if (__builtin_rotateright64(0x0123456789abcdefull, 8) !=
     21       0xef0123456789abcdull)
     22     return 10;
     23   if (__builtin_rotateleft64(0x55aa55aa55aa55aaull, 0) !=
     24       0x55aa55aa55aa55aaull)
     25     return 11;
     26   if (__builtin_rotateright8((u8)0x03u, 1) != (u8)0x81u) return 12;
     27   if (__builtin_rotateleft16((u16)0x8001u, 1) != (u16)0x0003u) return 13;
     28   if (__builtin_rotateright32(0x23456781u, 4) != 0x12345678u) return 14;
     29   return 42;
     30 }