| 1 |
/* { dg-do compile } */ |
| 2 |
/* { dg-require-effective-target bswap } */ |
| 3 |
/* { dg-require-effective-target stdint_types } */ |
| 4 |
/* { dg-options "-O2 -fdump-tree-optimized" } */ |
| 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 "= __builtin_bswap64 \\\(" 3 "optimized" } } */ |