Mercurial > hg > CbC > CbC_gcc
comparison gcc/testsuite/gcc.dg/optimize-bswaphi-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 bswap16 } */ | |
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 /* { dg-final { scan-tree-dump-times "16 bit load in target endianness found at" 3 "bswap" } } */ | |
58 /* { dg-final { scan-tree-dump-times "16 bit bswap implementation found at" 4 "bswap" } } */ |