Add new test to verify that the array index, limit, and stride are
[official-gcc.git] / gcc / testsuite / gcc.dg / optimize-bswapsi-1.c
blob78238e309558368d8563816526cc7dfe7822602b
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" } */
4 /* { dg-options "-O2 -fdump-tree-bswap -march=z900" { target s390-*-* } } */
6 #include <stdint.h>
8 #define __const_swab32(x) ((uint32_t)( \
9 (((uint32_t)(x) & (uint32_t)0x000000ffUL) << 24) | \
10 (((uint32_t)(x) & (uint32_t)0x0000ff00UL) << 8) | \
11 (((uint32_t)(x) & (uint32_t)0x00ff0000UL) >> 8) | \
12 (((uint32_t)(x) & (uint32_t)0xff000000UL) >> 24)))
14 /* This byte swap implementation is used by the Linux kernel and the
15 GNU C library. */
17 uint32_t
18 swap32_a (uint32_t in)
20 return __const_swab32 (in);
23 /* The OpenSSH byte swap implementation. */
24 uint32_t
25 swap32_b (uint32_t in)
27 uint32_t a;
29 a = (in << 16) | (in >> 16);
30 a = ((a & 0x00ff00ff) << 8) | ((a & 0xff00ff00) >> 8);
32 return a;
35 /* This variant is currently used by libgcc. The difference is that
36 the bswap source and destination have a signed integer type which
37 requires a slightly higher search depth in order to dive through
38 the cast as well. */
40 typedef int SItype __attribute__ ((mode (SI)));
42 SItype
43 swap32_c (SItype u)
45 return ((((u) & 0xff000000) >> 24)
46 | (((u) & 0x00ff0000) >> 8)
47 | (((u) & 0x0000ff00) << 8)
48 | (((u) & 0x000000ff) << 24));
51 /* { dg-final { scan-tree-dump-times "32 bit bswap implementation found at" 3 "bswap" } } */
52 /* { dg-final { cleanup-tree-dump "bswap" } } */