Merged revision 156805 into branch.
[official-gcc.git] / gcc / testsuite / gcc.dg / optimize-bswapsi-1.c
blob35f53ba76cf9f43c77373515238c638a21f6b5ee
1 /* { dg-do compile { target arm*-*-* alpha*-*-* i?86-*-* powerpc*-*-* rs6000-*-* x86_64-*-* s390*-*-* } } */
2 /* { dg-require-effective-target stdint_types } */
3 /* { dg-options "-O2 -fdump-tree-bswap" } */
5 #include <stdint.h>
7 #define __const_swab32(x) ((uint32_t)( \
8 (((uint32_t)(x) & (uint32_t)0x000000ffUL) << 24) | \
9 (((uint32_t)(x) & (uint32_t)0x0000ff00UL) << 8) | \
10 (((uint32_t)(x) & (uint32_t)0x00ff0000UL) >> 8) | \
11 (((uint32_t)(x) & (uint32_t)0xff000000UL) >> 24)))
13 /* This byte swap implementation is used by the Linux kernel and the
14 GNU C library. */
16 uint32_t
17 swap32_a (uint32_t in)
19 return __const_swab32 (in);
22 /* The OpenSSH byte swap implementation. */
23 uint32_t
24 swap32_b (uint32_t in)
26 uint32_t a;
28 a = (in << 16) | (in >> 16);
29 a = ((a & 0x00ff00ff) << 8) | ((a & 0xff00ff00) >> 8);
31 return a;
34 /* This variant is currently used by libgcc. The difference is that
35 the bswap source and destination have a signed integer type which
36 requires a slightly higher search depth in order to dive through
37 the cast as well. */
39 typedef int SItype __attribute__ ((mode (SI)));
41 SItype
42 swap32_c (SItype u)
44 return ((((u) & 0xff000000) >> 24)
45 | (((u) & 0x00ff0000) >> 8)
46 | (((u) & 0x0000ff00) << 8)
47 | (((u) & 0x000000ff) << 24));
50 /* { dg-final { scan-tree-dump-times "32 bit bswap implementation found at" 3 "bswap" } } */
51 /* { dg-final { cleanup-tree-dump "bswap" } } */