OSDN Git Service

2011-10-18 Janus Weil <janus@gcc.gnu.org>
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / gcc.dg / optimize-bswapsi-1.c
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-*-* } } */
5
6 #include <stdint.h>
7
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)))
13
14 /* This byte swap implementation is used by the Linux kernel and the
15    GNU C library.  */
16
17 uint32_t
18 swap32_a (uint32_t in)
19 {
20   return __const_swab32 (in);
21 }
22
23 /* The OpenSSH byte swap implementation.  */
24 uint32_t
25 swap32_b (uint32_t in)
26 {
27   uint32_t a;
28
29   a = (in << 16) | (in >> 16);
30   a = ((a & 0x00ff00ff) << 8) | ((a & 0xff00ff00) >> 8);
31
32   return a;
33 }
34
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.  */
39
40 typedef int SItype __attribute__ ((mode (SI)));
41
42 SItype
43 swap32_c (SItype u)
44 {
45   return ((((u) & 0xff000000) >> 24)
46           | (((u) & 0x00ff0000) >>  8)
47           | (((u) & 0x0000ff00) <<  8)
48           | (((u) & 0x000000ff) << 24));
49 }
50
51 /* { dg-final { scan-tree-dump-times "32 bit bswap implementation found at" 3 "bswap" } } */
52 /* { dg-final { cleanup-tree-dump "bswap" } } */