comparison gcc/testsuite/gcc.dg/optimize-bswapdi-1.c @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents
children 84e7813d76e9
comparison
equal deleted inserted replaced
68:561a7518be6b 111:04ced10e8804
1 /* { dg-do compile } */
2 /* { dg-require-effective-target bswap64 } */
3 /* { dg-require-effective-target stdint_types } */
4 /* { dg-options "-O2 -fdump-tree-bswap" } */
5 /* { dg-additional-options "-mzarch" { target s390*-*-* } } */
6
7 #include <stdint.h>
8 #define __const_swab64(x) ((uint64_t)( \
9 (((uint64_t)(x) & (uint64_t)0x00000000000000ffULL) << 56) | \
10 (((uint64_t)(x) & (uint64_t)0x000000000000ff00ULL) << 40) | \
11 (((uint64_t)(x) & (uint64_t)0x0000000000ff0000ULL) << 24) | \
12 (((uint64_t)(x) & (uint64_t)0x00000000ff000000ULL) << 8) | \
13 (((uint64_t)(x) & (uint64_t)0x000000ff00000000ULL) >> 8) | \
14 (((uint64_t)(x) & (uint64_t)0x0000ff0000000000ULL) >> 24) | \
15 (((uint64_t)(x) & (uint64_t)0x00ff000000000000ULL) >> 40) | \
16 (((uint64_t)(x) & (uint64_t)0xff00000000000000ULL) >> 56)))
17
18
19 /* This byte swap implementation is used by the Linux kernel and the
20 GNU C library. */
21
22 uint64_t
23 swap64 (uint64_t in)
24 {
25 return __const_swab64 (in);
26 }
27
28 /* This variant is currently used by libgcc. The difference is that
29 the bswap source and destination have a signed integer type which
30 requires a slightly higher search depth in order to dive through
31 the cast as well. */
32
33 typedef int DItype __attribute__ ((mode (DI)));
34 DItype
35 swap64_b (DItype u)
36 {
37 return ((((u) & 0xff00000000000000ull) >> 56)
38 | (((u) & 0x00ff000000000000ull) >> 40)
39 | (((u) & 0x0000ff0000000000ull) >> 24)
40 | (((u) & 0x000000ff00000000ull) >> 8)
41 | (((u) & 0x00000000ff000000ull) << 8)
42 | (((u) & 0x0000000000ff0000ull) << 24)
43 | (((u) & 0x000000000000ff00ull) << 40)
44 | (((u) & 0x00000000000000ffull) << 56));
45 }
46
47 /* The OpenSSL variant. */
48
49 uint64_t
50 swap64_c (uint64_t x)
51 {
52 uint32_t a = x >> 32;
53 uint32_t b = (uint32_t) x;
54 return ((uint64_t) ((((((b)) >> (8)) | (((b)) << (32 - (8)))) & 0xff00ff00L)
55 | (((((b)) << (8)) | (((b)) >> (32 - (8)))) & 0x00ff00ffL)) << 32)
56 | (uint64_t) ((((((a)) >> (8)) | (((a)) << (32 - (8)))) & 0xff00ff00L)
57 | (((((a)) << (8)) | (((a)) >> (32 - (8)))) & 0x00ff00ffL));
58 }
59
60
61 /* { dg-final { scan-tree-dump-times "64 bit bswap implementation found at" 3 "bswap" } } */