diff options
author | geoffk <geoffk@138bc75d-0d04-0410-961f-82ee72b054a4> | 2006-11-01 05:20:05 +0000 |
---|---|---|
committer | geoffk <geoffk@138bc75d-0d04-0410-961f-82ee72b054a4> | 2006-11-01 05:20:05 +0000 |
commit | 154db13d9dd66114ec4845308146f4f993b6696c (patch) | |
tree | 544eecf6a9b2b5a2b237b57685072451e865376d /gcc/testsuite/gcc.dg/builtin-bswap-4.c | |
parent | b7afdbf76fbeafa81281561a8ea34e6333c677b5 (diff) | |
download | gcc-154db13d9dd66114ec4845308146f4f993b6696c.tar.gz |
2006-10-31 Eric Christopher <echristo@apple.com>
Falk Hueffner <falk@debian.org>
* gcc.dg/builtin-bswap-1.c: New.
* gcc.dg/builtin-bswap-2.c: New.
* gcc.dg/builtin-bswap-3.c: New.
* gcc.dg/builtin-bswap-4.c: New.
* gcc.dg/builtin-bswap-5.c: New.
* gcc.target/i386/builtin-bswap-1.c: New.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@118364 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/testsuite/gcc.dg/builtin-bswap-4.c')
-rw-r--r-- | gcc/testsuite/gcc.dg/builtin-bswap-4.c | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/builtin-bswap-4.c b/gcc/testsuite/gcc.dg/builtin-bswap-4.c new file mode 100644 index 00000000000..d14358e2ded --- /dev/null +++ b/gcc/testsuite/gcc.dg/builtin-bswap-4.c @@ -0,0 +1,59 @@ +/* { dg-do run } */ +/* { dg-options "-Wall" } */ + +#include <stdint.h> + +#define MAKE_FUN(suffix, type) \ + type my_bswap##suffix(type x) { \ + type result = 0; \ + int shift; \ + for (shift = 0; shift < 8 * sizeof (type); shift += 8) \ + { \ + result <<= 8; \ + result |= (x >> shift) & 0xff; \ + } \ + return result; \ + } \ + +MAKE_FUN(32, uint32_t); +MAKE_FUN(64, uint64_t); + +extern void abort (void); + +#define NUMS32 \ + { \ + 0x00000000UL, \ + 0x11223344UL, \ + 0xffffffffUL, \ + } + +#define NUMS64 \ + { \ + 0x0000000000000000ULL, \ + 0x1122334455667788ULL, \ + 0xffffffffffffffffULL, \ + } + +uint32_t uint32_ts[] = + NUMS32; + +uint64_t uint64_ts[] = + NUMS64; + +#define N(table) (sizeof (table) / sizeof (table[0])) + +int +main (void) +{ + int i; + + for (i = 0; i < N(uint32_ts); i++) + if (__builtin_bswap32 (uint32_ts[i]) != my_bswap32 (uint32_ts[i])) + abort (); + + for (i = 0; i < N(uint64_ts); i++) + if (__builtin_bswap64 (uint64_ts[i]) != my_bswap64 (uint64_ts[i])) + abort (); + + return 0; +} |