2014-07-29 Ed Smith-Rowland <3dw4rd@verizon.net>
[official-gcc.git] / gcc / testsuite / gcc.dg / optimize-bswapsi-1.c
blobebfca6077b9f33e7118fed829e3aecea529ec318
1 /* { dg-do compile } */
2 /* { dg-require-effective-target bswap32 } */
3 /* { dg-require-effective-target stdint_types } */
4 /* { dg-options "-O2 -fdump-tree-bswap" } */
5 /* { dg-additional-options "-march=z900" { target s390-*-* } } */
7 #include <stdint.h>
9 #define __const_swab32(x) ((uint32_t)( \
10 (((uint32_t)(x) & (uint32_t)0x000000ffUL) << 24) | \
11 (((uint32_t)(x) & (uint32_t)0x0000ff00UL) << 8) | \
12 (((uint32_t)(x) & (uint32_t)0x00ff0000UL) >> 8) | \
13 (((uint32_t)(x) & (uint32_t)0xff000000UL) >> 24)))
15 /* This byte swap implementation is used by the Linux kernel and the
16 GNU C library. */
18 uint32_t
19 swap32_a (uint32_t in)
21 return __const_swab32 (in);
24 /* The OpenSSH byte swap implementation. */
25 uint32_t
26 swap32_b (uint32_t in)
28 uint32_t a;
30 a = (in << 16) | (in >> 16);
31 a = ((a & 0x00ff00ff) << 8) | ((a & 0xff00ff00) >> 8);
33 return a;
36 /* This variant is currently used by libgcc. The difference is that
37 the bswap source and destination have a signed integer type which
38 requires a slightly higher search depth in order to dive through
39 the cast as well. */
41 typedef int SItype __attribute__ ((mode (SI)));
43 SItype
44 swap32_c (SItype u)
46 return ((((u) & 0xff000000) >> 24)
47 | (((u) & 0x00ff0000) >> 8)
48 | (((u) & 0x0000ff00) << 8)
49 | (((u) & 0x000000ff) << 24));
52 /* { dg-final { scan-tree-dump-times "32 bit bswap implementation found at" 3 "bswap" } } */
53 /* { dg-final { cleanup-tree-dump "bswap" } } */