| 1 |
/* { dg-do compile } */ |
| 2 |
/* { dg-require-effective-target bswap } */ |
| 3 |
/* { dg-require-effective-target stdint_types } */ |
| 4 |
/* { dg-options "-O2 -fdump-tree-bswap" } */ |
| 5 |
/* { dg-additional-options "-march=z900" { target s390-*-* } } */ |
| 6 |
|
| 7 |
#include <stdint.h> |
| 8 |
|
| 9 |
unsigned char data[2]; |
| 10 |
|
| 11 |
struct uint16_st { |
| 12 |
unsigned char u0, u1; |
| 13 |
}; |
| 14 |
|
| 15 |
uint32_t read_le16_1 (void) |
| 16 |
{ |
| 17 |
return data[0] | (data[1] << 8); |
| 18 |
} |
| 19 |
|
| 20 |
uint32_t read_le16_2 (struct uint16_st data) |
| 21 |
{ |
| 22 |
return data.u0 | (data.u1 << 8); |
| 23 |
} |
| 24 |
|
| 25 |
uint32_t read_le16_3 (unsigned char *data) |
| 26 |
{ |
| 27 |
return *data | (*(data + 1) << 8); |
| 28 |
} |
| 29 |
|
| 30 |
uint32_t read_be16_1 (void) |
| 31 |
{ |
| 32 |
return data[1] | (data[0] << 8); |
| 33 |
} |
| 34 |
|
| 35 |
uint32_t read_be16_2 (struct uint16_st data) |
| 36 |
{ |
| 37 |
return data.u1 | (data.u0 << 8); |
| 38 |
} |
| 39 |
|
| 40 |
uint32_t read_be16_3 (unsigned char *data) |
| 41 |
{ |
| 42 |
return *(data + 1) | (*data << 8); |
| 43 |
} |
| 44 |
|
| 45 |
typedef int HItype __attribute__ ((mode (HI))); |
| 46 |
|
| 47 |
/* Test that detection of significant sign extension works correctly. This |
| 48 |
checks that unknown byte markers are set correctly in cast of cast. */ |
| 49 |
|
| 50 |
HItype |
| 51 |
swap16 (HItype in) |
| 52 |
{ |
| 53 |
return (HItype) (((in >> 0) & 0xFF) << 8) |
| 54 |
| (((in >> 8) & 0xFF) << 0); |
| 55 |
} |
| 56 |
|
| 57 |
unsigned short |
| 58 |
get_unaligned_16_le (unsigned char *p) |
| 59 |
{ |
| 60 |
return p[0] | (p[1] << 8); |
| 61 |
} |
| 62 |
|
| 63 |
unsigned short |
| 64 |
get_unaligned_16_be (unsigned char *p) |
| 65 |
{ |
| 66 |
return p[1] | (p[0] << 8); |
| 67 |
} |
| 68 |
|
| 69 |
|
| 70 |
/* { dg-final { scan-tree-dump-times "16 bit load in target endianness found at" 4 "bswap" } } */ |
| 71 |
/* { dg-final { scan-tree-dump-times "16 bit bswap implementation found at" 4 "bswap" } } */ |