(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.dg/
builtin-bswap-11.c
       1  /* { dg-do run } */
       2  /* { dg-require-effective-target int128 } */
       3  /* { dg-require-effective-target stdint_types } */
       4  /* { dg-options "-Wall" } */
       5  
       6  #include <stdint.h>
       7  
       8  #define MAKE_FUN(suffix, type)						\
       9    type my_bswap##suffix(type x) {					\
      10      type result = 0;							\
      11      int shift;								\
      12      for (shift = 0; shift < 8 * sizeof (type); shift += 8)	\
      13        {									\
      14  	result <<= 8;							\
      15  	result |= (x >> shift) & 0xff;					\
      16        }									\
      17      return result;							\
      18    }									\
      19  
      20  MAKE_FUN(128, __uint128_t);
      21  
      22  extern void abort (void);
      23  
      24  typedef union
      25  {
      26    struct { uint64_t lo; uint64_t hi; } s;
      27    __uint128_t n;
      28  } u;
      29  
      30  #define NUMS128							\
      31    {								\
      32      { .s = { 0x0000000000000000ULL, 0x1122334455667788ULL } }, 	\
      33      { .s = { 0x1122334455667788ULL, 0xffffffffffffffffULL } },	\
      34      { .s = { 0xffffffffffffffffULL, 0x0000000000000000ULL } }	\
      35    }
      36  
      37  u uint128_ts[] = NUMS128;
      38  
      39  #define N(table) (sizeof (table) / sizeof (table[0]))
      40  
      41  int
      42  main (void)
      43  {
      44    int i;
      45  
      46    for (i = 0; i < N(uint128_ts); i++)
      47      if (__builtin_bswap128 (uint128_ts[i].n) != my_bswap128 (uint128_ts[i].n))
      48        abort ();
      49  
      50    return 0;
      51  }