2009-07-17 Richard Guenther <rguenther@suse.de>
[official-gcc.git] / gcc / testsuite / gcc.dg / optimize-bswapdi-1.c
blob449dc19f7652419c4a1a9331fff505b04cf34041
1 /* { dg-do compile { target alpha*-*-* ia64*-*-* x86_64-*-* s390x-*-* } } */
2 /* { dg-require-effective-target stdint_types } */
3 /* { dg-require-effective-target lp64 } */
4 /* { dg-options "-O2 -fdump-tree-bswap" } */
6 #include <stdint.h>
7 #define __const_swab64(x) ((uint64_t)( \
8 (((uint64_t)(x) & (uint64_t)0x00000000000000ffULL) << 56) | \
9 (((uint64_t)(x) & (uint64_t)0x000000000000ff00ULL) << 40) | \
10 (((uint64_t)(x) & (uint64_t)0x0000000000ff0000ULL) << 24) | \
11 (((uint64_t)(x) & (uint64_t)0x00000000ff000000ULL) << 8) | \
12 (((uint64_t)(x) & (uint64_t)0x000000ff00000000ULL) >> 8) | \
13 (((uint64_t)(x) & (uint64_t)0x0000ff0000000000ULL) >> 24) | \
14 (((uint64_t)(x) & (uint64_t)0x00ff000000000000ULL) >> 40) | \
15 (((uint64_t)(x) & (uint64_t)0xff00000000000000ULL) >> 56)))
18 /* This byte swap implementation is used by the Linux kernel and the
19 GNU C library. */
21 uint64_t
22 swap64 (uint64_t in)
24 return __const_swab64 (in);
27 /* This variant is currently used by libgcc. The difference is that
28 the bswap source and destination have a signed integer type which
29 requires a slightly higher search depth in order to dive through
30 the cast as well. */
32 typedef int DItype __attribute__ ((mode (DI)));
33 DItype
34 swap64_b (DItype u)
36 return ((((u) & 0xff00000000000000ull) >> 56)
37 | (((u) & 0x00ff000000000000ull) >> 40)
38 | (((u) & 0x0000ff0000000000ull) >> 24)
39 | (((u) & 0x000000ff00000000ull) >> 8)
40 | (((u) & 0x00000000ff000000ull) << 8)
41 | (((u) & 0x0000000000ff0000ull) << 24)
42 | (((u) & 0x000000000000ff00ull) << 40)
43 | (((u) & 0x00000000000000ffull) << 56));
47 /* { dg-final { scan-tree-dump-times "64 bit bswap implementation found at" 2 "bswap" } } */
48 /* { dg-final { cleanup-tree-dump "bswap" } } */