Merge aosp-toolchain/gcc/gcc-4_9 changes.
[official-gcc.git] / gcc-4_9 / gcc / testsuite / gcc.target / sh / pr55303-1.c
blobb77c5e10ee5753633771644df42e5c87f9360688
1 /* Verify that the SH2A clips and clipu instructions are generated as
2 expected. */
3 /* { dg-do compile } */
4 /* { dg-options "-O2" } */
5 /* { dg-skip-if "" { "sh*-*-*" } { "*" } { "-m2a*" } } */
6 /* { dg-final { scan-assembler-times "clips.b" 2 } } */
7 /* { dg-final { scan-assembler-times "clips.w" 2 } } */
8 /* { dg-final { scan-assembler-times "clipu.b" 2 } } */
9 /* { dg-final { scan-assembler-times "clipu.w" 2 } } */
11 static inline int
12 min (int a, int b)
14 return a < b ? a : b;
17 static inline int
18 max (int a, int b)
20 return a < b ? b : a;
23 int
24 test_00 (int a)
26 /* 1x clips.b */
27 return max (-128, min (127, a));
30 int
31 test_01 (int a)
33 /* 1x clips.b */
34 return min (127, max (-128, a));
37 int
38 test_02 (int a)
40 /* 1x clips.w */
41 return max (-32768, min (32767, a));
44 int
45 test_03 (int a)
47 /* 1x clips.w */
48 return min (32767, max (-32768, a));
51 unsigned int
52 test_04 (unsigned int a)
54 /* 1x clipu.b */
55 return a > 255 ? 255 : a;
58 unsigned int
59 test_05 (unsigned int a)
61 /* 1x clipu.b */
62 return a >= 255 ? 255 : a;
65 unsigned int
66 test_06 (unsigned int a)
68 /* 1x clipu.w */
69 return a > 65535 ? 65535 : a;
72 unsigned int
73 test_07 (unsigned int a)
75 /* 1x clipu.w */
76 return a >= 65535 ? 65535 : a;
79 void
80 test_08 (unsigned short a, unsigned short b, unsigned int* r)
82 /* Must not see a clip insn here -- it is not needed. */
83 unsigned short x = a + b;
84 if (x > 65535)
85 x = 65535;
86 *r = x;