]>
git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/testsuite/gcc.dg/optimize-bswaphi-1.c
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-*-* } } */
15 uint32_t read_le16_1 (void)
17 return data
[0] | (data
[1] << 8);
20 uint32_t read_le16_2 (struct uint16_st data
)
22 return data
.u0
| (data
.u1
<< 8);
25 uint32_t read_le16_3 (unsigned char *data
)
27 return *data
| (*(data
+ 1) << 8);
30 uint32_t read_be16_1 (void)
32 return data
[1] | (data
[0] << 8);
35 uint32_t read_be16_2 (struct uint16_st data
)
37 return data
.u1
| (data
.u0
<< 8);
40 uint32_t read_be16_3 (unsigned char *data
)
42 return *(data
+ 1) | (*data
<< 8);
45 typedef int HItype
__attribute__ ((mode (HI
)));
47 /* Test that detection of significant sign extension works correctly. This
48 checks that unknown byte markers are set correctly in cast of cast. */
53 return (HItype
) (((in
>> 0) & 0xFF) << 8)
54 | (((in
>> 8) & 0xFF) << 0);
58 get_unaligned_16_le (unsigned char *p
)
60 return p
[0] | (p
[1] << 8);
64 get_unaligned_16_be (unsigned char *p
)
66 return p
[1] | (p
[0] << 8);
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" 5 "bswap" } } */