annotate gcc/testsuite/gcc.dg/optimize-bswapsi-1.c @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* { dg-do compile } */
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2 /* { dg-require-effective-target bswap } */
111
kono
parents:
diff changeset
3 /* { dg-require-effective-target stdint_types } */
kono
parents:
diff changeset
4 /* { dg-options "-O2 -fdump-tree-bswap" } */
kono
parents:
diff changeset
5 /* { dg-additional-options "-march=z900" { target s390*-*-* } } */
kono
parents:
diff changeset
6
kono
parents:
diff changeset
7 #include <stdint.h>
kono
parents:
diff changeset
8
kono
parents:
diff changeset
9 #define __const_swab32(x) ((uint32_t)( \
kono
parents:
diff changeset
10 (((uint32_t)(x) & (uint32_t)0x000000ffUL) << 24) | \
kono
parents:
diff changeset
11 (((uint32_t)(x) & (uint32_t)0x0000ff00UL) << 8) | \
kono
parents:
diff changeset
12 (((uint32_t)(x) & (uint32_t)0x00ff0000UL) >> 8) | \
kono
parents:
diff changeset
13 (((uint32_t)(x) & (uint32_t)0xff000000UL) >> 24)))
kono
parents:
diff changeset
14
kono
parents:
diff changeset
15 /* This byte swap implementation is used by the Linux kernel and the
kono
parents:
diff changeset
16 GNU C library. */
kono
parents:
diff changeset
17
kono
parents:
diff changeset
18 uint32_t
kono
parents:
diff changeset
19 swap32_a (uint32_t in)
kono
parents:
diff changeset
20 {
kono
parents:
diff changeset
21 return __const_swab32 (in);
kono
parents:
diff changeset
22 }
kono
parents:
diff changeset
23
kono
parents:
diff changeset
24 /* The OpenSSH byte swap implementation. */
kono
parents:
diff changeset
25 uint32_t
kono
parents:
diff changeset
26 swap32_b (uint32_t in)
kono
parents:
diff changeset
27 {
kono
parents:
diff changeset
28 uint32_t a;
kono
parents:
diff changeset
29
kono
parents:
diff changeset
30 a = (in << 16) | (in >> 16);
kono
parents:
diff changeset
31 a = ((a & 0x00ff00ff) << 8) | ((a & 0xff00ff00) >> 8);
kono
parents:
diff changeset
32
kono
parents:
diff changeset
33 return a;
kono
parents:
diff changeset
34 }
kono
parents:
diff changeset
35
kono
parents:
diff changeset
36 /* This variant is currently used by libgcc. The difference is that
kono
parents:
diff changeset
37 the bswap source and destination have a signed integer type which
kono
parents:
diff changeset
38 requires a slightly higher search depth in order to dive through
kono
parents:
diff changeset
39 the cast as well. */
kono
parents:
diff changeset
40
kono
parents:
diff changeset
41 typedef int SItype __attribute__ ((mode (SI)));
kono
parents:
diff changeset
42
kono
parents:
diff changeset
43 SItype
kono
parents:
diff changeset
44 swap32_c (SItype u)
kono
parents:
diff changeset
45 {
kono
parents:
diff changeset
46 return ((((u) & 0xff000000) >> 24)
kono
parents:
diff changeset
47 | (((u) & 0x00ff0000) >> 8)
kono
parents:
diff changeset
48 | (((u) & 0x0000ff00) << 8)
kono
parents:
diff changeset
49 | (((u) & 0x000000ff) << 24));
kono
parents:
diff changeset
50 }
kono
parents:
diff changeset
51
kono
parents:
diff changeset
52 /* This variant comes from gcc.target/sh/pr53568-1.c. It requires to track
kono
parents:
diff changeset
53 which bytes have an unpredictable value (eg. due to sign extension) to
kono
parents:
diff changeset
54 make sure that the final expression have only well defined byte values. */
kono
parents:
diff changeset
55
kono
parents:
diff changeset
56 SItype
kono
parents:
diff changeset
57 swap32_d (SItype in)
kono
parents:
diff changeset
58 {
kono
parents:
diff changeset
59 /* 1x swap.w
kono
parents:
diff changeset
60 2x swap.b */
kono
parents:
diff changeset
61 return (((in >> 0) & 0xFF) << 24)
kono
parents:
diff changeset
62 | (((in >> 8) & 0xFF) << 16)
kono
parents:
diff changeset
63 | (((in >> 16) & 0xFF) << 8)
kono
parents:
diff changeset
64 | (((in >> 24) & 0xFF) << 0);
kono
parents:
diff changeset
65 }
kono
parents:
diff changeset
66
kono
parents:
diff changeset
67 /* This variant is adapted from swap32_d above. It detects missing cast of
kono
parents:
diff changeset
68 MARKER_BYTE_UNKNOWN to uint64_t for the CASE_CONVERT case for host
kono
parents:
diff changeset
69 architecture where a left shift with too big an operand mask its high
kono
parents:
diff changeset
70 bits. */
kono
parents:
diff changeset
71
kono
parents:
diff changeset
72 SItype
kono
parents:
diff changeset
73 swap32_e (SItype in)
kono
parents:
diff changeset
74 {
kono
parents:
diff changeset
75 return (((in >> 0) & 0xFF) << 24)
kono
parents:
diff changeset
76 | (((in >> 8) & 0xFF) << 16)
kono
parents:
diff changeset
77 | (((((int64_t) in) & 0xFF0000FF0000) >> 16) << 8)
kono
parents:
diff changeset
78 | (((in >> 24) & 0xFF) << 0);
kono
parents:
diff changeset
79 }
kono
parents:
diff changeset
80
kono
parents:
diff changeset
81 /* This variant comes from PR63259. It compiles to a gimple sequence that ends
kono
parents:
diff changeset
82 with a rotation instead of a bitwise OR. */
kono
parents:
diff changeset
83
kono
parents:
diff changeset
84 unsigned
kono
parents:
diff changeset
85 swap32_f (unsigned in)
kono
parents:
diff changeset
86 {
kono
parents:
diff changeset
87 in = ((in & 0xff00ff00) >> 8) | ((in & 0x00ff00ff) << 8);
kono
parents:
diff changeset
88 in = ((in & 0xffff0000) >> 16) | ((in & 0x0000ffff) << 16);
kono
parents:
diff changeset
89 return in;
kono
parents:
diff changeset
90 }
kono
parents:
diff changeset
91
kono
parents:
diff changeset
92 /* { dg-final { scan-tree-dump-times "32 bit bswap implementation found at" 6 "bswap" } } */