libcpp, c, middle-end: Optimize initializers using #embed in C
[official-gcc.git] / gcc / testsuite / gcc.dg / builtin-bswap-11.c
blob3fedcf1bd3cebc889f96f293159509f475c497e4
1 /* { dg-do run } */
2 /* { dg-require-effective-target int128 } */
3 /* { dg-require-effective-target stdint_types } */
4 /* { dg-options "-Wall" } */
6 #include <stdint.h>
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 } \
20 MAKE_FUN(128, __uint128_t);
22 extern void abort (void);
24 typedef union
26 struct { uint64_t lo; uint64_t hi; } s;
27 __uint128_t n;
28 } u;
30 #define NUMS128 \
31 { \
32 { .s = { 0x0000000000000000ULL, 0x1122334455667788ULL } }, \
33 { .s = { 0x1122334455667788ULL, 0xffffffffffffffffULL } }, \
34 { .s = { 0xffffffffffffffffULL, 0x0000000000000000ULL } } \
37 u uint128_ts[] = NUMS128;
39 #define N(table) (sizeof (table) / sizeof (table[0]))
41 int
42 main (void)
44 int i;
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 ();
50 return 0;