PR middle-end/27945
[official-gcc.git] / gcc / testsuite / gcc.dg / builtin-bswap-4.c
blob03e190ad782f6fa907e51c22a3b5ee49331e00a7
1 /* { dg-do run } */
2 /* { dg-require-effective-target stdint_types } */
3 /* { dg-options "-Wall" } */
5 #include <stdint.h>
7 #define MAKE_FUN(suffix, type) \
8 type my_bswap##suffix(type x) { \
9 type result = 0; \
10 int shift; \
11 for (shift = 0; shift < 8 * sizeof (type); shift += 8) \
12 { \
13 result <<= 8; \
14 result |= (x >> shift) & 0xff; \
15 } \
16 return result; \
17 } \
19 MAKE_FUN(32, uint32_t);
20 MAKE_FUN(64, uint64_t);
22 extern void abort (void);
24 #define NUMS32 \
25 { \
26 0x00000000UL, \
27 0x11223344UL, \
28 0xffffffffUL, \
31 #define NUMS64 \
32 { \
33 0x0000000000000000ULL, \
34 0x1122334455667788ULL, \
35 0xffffffffffffffffULL, \
38 uint32_t uint32_ts[] =
39 NUMS32;
41 uint64_t uint64_ts[] =
42 NUMS64;
44 #define N(table) (sizeof (table) / sizeof (table[0]))
46 int
47 main (void)
49 int i;
51 for (i = 0; i < N(uint32_ts); i++)
52 if (__builtin_bswap32 (uint32_ts[i]) != my_bswap32 (uint32_ts[i]))
53 abort ();
55 for (i = 0; i < N(uint64_ts); i++)
56 if (__builtin_bswap64 (uint64_ts[i]) != my_bswap64 (uint64_ts[i]))
57 abort ();
59 return 0;