| 1 |
/* Verify that the SH2A clips and clipu instructions are generated as |
| 2 |
expected. */ |
| 3 |
/* { dg-do compile { target { sh2a } } } */ |
| 4 |
/* { dg-options "-O2" } */ |
| 5 |
/* { dg-final { scan-assembler-times "clips.b" 2 } } */ |
| 6 |
/* { dg-final { scan-assembler-times "clips.w" 2 } } */ |
| 7 |
/* { dg-final { scan-assembler-times "clipu.b" 2 } } */ |
| 8 |
/* { dg-final { scan-assembler-times "clipu.w" 2 } } */ |
| 9 |
|
| 10 |
static inline int |
| 11 |
min (int a, int b) |
| 12 |
{ |
| 13 |
return a < b ? a : b; |
| 14 |
} |
| 15 |
|
| 16 |
static inline int |
| 17 |
max (int a, int b) |
| 18 |
{ |
| 19 |
return a < b ? b : a; |
| 20 |
} |
| 21 |
|
| 22 |
int |
| 23 |
test_00 (int a) |
| 24 |
{ |
| 25 |
/* 1x clips.b */ |
| 26 |
return max (-128, min (127, a)); |
| 27 |
} |
| 28 |
|
| 29 |
int |
| 30 |
test_01 (int a) |
| 31 |
{ |
| 32 |
/* 1x clips.b */ |
| 33 |
return min (127, max (-128, a)); |
| 34 |
} |
| 35 |
|
| 36 |
int |
| 37 |
test_02 (int a) |
| 38 |
{ |
| 39 |
/* 1x clips.w */ |
| 40 |
return max (-32768, min (32767, a)); |
| 41 |
} |
| 42 |
|
| 43 |
int |
| 44 |
test_03 (int a) |
| 45 |
{ |
| 46 |
/* 1x clips.w */ |
| 47 |
return min (32767, max (-32768, a)); |
| 48 |
} |
| 49 |
|
| 50 |
unsigned int |
| 51 |
test_04 (unsigned int a) |
| 52 |
{ |
| 53 |
/* 1x clipu.b */ |
| 54 |
return a > 255 ? 255 : a; |
| 55 |
} |
| 56 |
|
| 57 |
unsigned int |
| 58 |
test_05 (unsigned int a) |
| 59 |
{ |
| 60 |
/* 1x clipu.b */ |
| 61 |
return a >= 255 ? 255 : a; |
| 62 |
} |
| 63 |
|
| 64 |
unsigned int |
| 65 |
test_06 (unsigned int a) |
| 66 |
{ |
| 67 |
/* 1x clipu.w */ |
| 68 |
return a > 65535 ? 65535 : a; |
| 69 |
} |
| 70 |
|
| 71 |
unsigned int |
| 72 |
test_07 (unsigned int a) |
| 73 |
{ |
| 74 |
/* 1x clipu.w */ |
| 75 |
return a >= 65535 ? 65535 : a; |
| 76 |
} |
| 77 |
|
| 78 |
void |
| 79 |
test_08 (unsigned short a, unsigned short b, unsigned int* r) |
| 80 |
{ |
| 81 |
/* Must not see a clip insn here -- it is not needed. */ |
| 82 |
unsigned short x = a + b; |
| 83 |
if (x > 65535) |
| 84 |
x = 65535; |
| 85 |
*r = x; |
| 86 |
} |