| 1 |
/* Check that the cmp/pz instruction is generated as expected. */ |
| 2 |
/* { dg-do compile } */ |
| 3 |
/* { dg-options "-O1" } */ |
| 4 |
|
| 5 |
/* { dg-final { scan-assembler-times "shll" 1 } } */ |
| 6 |
/* { dg-final { scan-assembler-times "movt" 5 } } */ |
| 7 |
/* { dg-final { scan-assembler-times "rotcl" 1 } } */ |
| 8 |
/* { dg-final { scan-assembler-times "and" 3 } } */ |
| 9 |
/* { dg-final { scan-assembler-times "extu.b" 5 } } */ |
| 10 |
|
| 11 |
/* { dg-final { scan-assembler-times "cmp/pz" 27 { target { ! sh2a } } } } */ |
| 12 |
/* { dg-final { scan-assembler-times "addc" 4 { target { ! sh2a } } } } */ |
| 13 |
/* { dg-final { scan-assembler-times "subc" 16 { target { ! sh2a } } } } */ |
| 14 |
|
| 15 |
/* { dg-final { scan-assembler-times "cmp/pz" 25 { target { sh2a } } } } */ |
| 16 |
/* { dg-final { scan-assembler-times "addc" 6 { target { sh2a } } } } */ |
| 17 |
/* { dg-final { scan-assembler-times "subc" 14 { target { sh2a } } } } */ |
| 18 |
/* { dg-final { scan-assembler-times "bld" 2 { target { sh2a } } } } */ |
| 19 |
|
| 20 |
int |
| 21 |
test_00 (unsigned char* a) |
| 22 |
{ |
| 23 |
/* 1x cmp/pz, 1x movt */ |
| 24 |
return a[0] < 128; |
| 25 |
} |
| 26 |
|
| 27 |
int |
| 28 |
test_01 (unsigned char* a) |
| 29 |
{ |
| 30 |
/* 1x cmp/pz, 1x addc */ |
| 31 |
return a[0] + (a[0] < 128); |
| 32 |
} |
| 33 |
|
| 34 |
int |
| 35 |
test_02 (unsigned char* a) |
| 36 |
{ |
| 37 |
/* 1x cmp/pz, 1x addc */ |
| 38 |
return a[0] + ((a[0] & 0x80) == 0); |
| 39 |
} |
| 40 |
|
| 41 |
int |
| 42 |
test_03 (unsigned char* a) |
| 43 |
{ |
| 44 |
/* 1x cmp/pz, 1x subc |
| 45 |
SH2A: 1x bld, 1x addc */ |
| 46 |
return a[0] + (a[0] > 127); |
| 47 |
} |
| 48 |
|
| 49 |
int |
| 50 |
test_04 (unsigned char* a) |
| 51 |
{ |
| 52 |
/* 1x cmp/pz, 1x subc |
| 53 |
SH2A: 1x bld, 1x addc */ |
| 54 |
return a[0] + ((a[0] & 0x80) != 0); |
| 55 |
} |
| 56 |
|
| 57 |
int |
| 58 |
test_05 (unsigned char* a, int b, int c) |
| 59 |
{ |
| 60 |
/* 1x cmp/pz */ |
| 61 |
if (a[0] < 128) |
| 62 |
return c; |
| 63 |
else |
| 64 |
return b + 50; |
| 65 |
} |
| 66 |
|
| 67 |
unsigned int |
| 68 |
test_06 (unsigned int a) |
| 69 |
{ |
| 70 |
/* 1x cmp/pz, 1x movt */ |
| 71 |
return ~a >> 31; |
| 72 |
} |
| 73 |
|
| 74 |
int |
| 75 |
test_07 (unsigned short* a) |
| 76 |
{ |
| 77 |
/* 1x cmp/pz */ |
| 78 |
return a[0] < 32768; |
| 79 |
} |
| 80 |
|
| 81 |
int |
| 82 |
test_08 (unsigned short* a) |
| 83 |
{ |
| 84 |
/* 1x cmp/pz, 1x addc */ |
| 85 |
return a[0] + (a[0] < 32768); |
| 86 |
} |
| 87 |
|
| 88 |
unsigned int |
| 89 |
test_09 (unsigned int a) |
| 90 |
{ |
| 91 |
/* 1x cmp/pz, 1x movt */ |
| 92 |
return (a >> 31) ^ 1; |
| 93 |
} |
| 94 |
|
| 95 |
unsigned int |
| 96 |
test_10 (unsigned int a, unsigned int b) |
| 97 |
{ |
| 98 |
/* 1x cmp/pz, 1x rotcl */ |
| 99 |
return (a << 1) | ((a >> 31) ^ 1); |
| 100 |
} |
| 101 |
|
| 102 |
unsigned int |
| 103 |
test_11 (int x) |
| 104 |
{ |
| 105 |
/* 1x cmp/pz, 1x subc */ |
| 106 |
return ~(x >> 31); |
| 107 |
} |
| 108 |
|
| 109 |
unsigned int |
| 110 |
test_12 (int x) |
| 111 |
{ |
| 112 |
/* 1x cmp/pz, 1x subc */ |
| 113 |
return 0xFFFFFFFF - (x >> 31); |
| 114 |
} |
| 115 |
|
| 116 |
unsigned int |
| 117 |
test_13 (int x) |
| 118 |
{ |
| 119 |
/* 1x cmp/pz, 1x subc, 1x add */ |
| 120 |
return ~(x >> 31) << 1; |
| 121 |
} |
| 122 |
|
| 123 |
unsigned int |
| 124 |
test_14 (int x) |
| 125 |
{ |
| 126 |
/* 1x cmp/pz, 1x subc */ |
| 127 |
return ~(x >> 31) >> 1; |
| 128 |
} |
| 129 |
|
| 130 |
unsigned int |
| 131 |
test_15 (int x) |
| 132 |
{ |
| 133 |
/* 1x cmp/pz, 1x subc */ |
| 134 |
return ~(x >> 31) >> 31; |
| 135 |
} |
| 136 |
|
| 137 |
unsigned int |
| 138 |
test_16 (int x) |
| 139 |
{ |
| 140 |
/* 1x cmp/pz, 1x subc, 1x and */ |
| 141 |
return ~(x >> 31) & 0xFF000000; |
| 142 |
} |
| 143 |
|
| 144 |
unsigned int |
| 145 |
test_17 (int x) |
| 146 |
{ |
| 147 |
/* 1x cmp/pz, 1x subc, 1x and */ |
| 148 |
return ~(x >> 31) & 0x00FF0000; |
| 149 |
} |
| 150 |
|
| 151 |
unsigned int |
| 152 |
test_18 (int x) |
| 153 |
{ |
| 154 |
/* 1x cmp/pz, 1x subc, 1x and */ |
| 155 |
return ~(x >> 31) & 0x0000FF00; |
| 156 |
} |
| 157 |
|
| 158 |
unsigned int |
| 159 |
test_19 (int x) |
| 160 |
{ |
| 161 |
/* 1x cmp/pz, 1x subc, 1x extu.b */ |
| 162 |
return ~(x >> 31) & 0x000000FF; |
| 163 |
} |
| 164 |
|
| 165 |
unsigned int |
| 166 |
test_20 (int x, unsigned int y, unsigned int z) |
| 167 |
{ |
| 168 |
/* 1x shll */ |
| 169 |
return ~(x >> 31) ? y : z; |
| 170 |
} |
| 171 |
|
| 172 |
int |
| 173 |
test_21 (int x) |
| 174 |
{ |
| 175 |
/* 1x cmp/pz, 1x subc */ |
| 176 |
return x >= 0 ? 0xFFFFFFFF : 0; |
| 177 |
} |
| 178 |
|
| 179 |
int |
| 180 |
test_22 (int x) |
| 181 |
{ |
| 182 |
/* 1x cmp/pz, 1x movt */ |
| 183 |
return (x >> 31) + 1; |
| 184 |
} |
| 185 |
|
| 186 |
int |
| 187 |
test_23 (int x) |
| 188 |
{ |
| 189 |
/* 1x cmp/pz, 1x subc */ |
| 190 |
return x < 0 ? x + 1 : x; |
| 191 |
} |
| 192 |
|
| 193 |
unsigned int |
| 194 |
test_24 (unsigned int x) |
| 195 |
{ |
| 196 |
/* 1x cmp/pz, 1x subc */ |
| 197 |
return x & 0x80000000 ? x + 1 : x; |
| 198 |
} |
| 199 |
|
| 200 |
unsigned int |
| 201 |
test_25 (unsigned int x) |
| 202 |
{ |
| 203 |
/* 1x cmp/pz, 1x subc */ |
| 204 |
return x >> 31 ? x + 1 : x; |
| 205 |
} |
| 206 |
|
| 207 |
int |
| 208 |
test_26 (int x) |
| 209 |
{ |
| 210 |
/* 1x cmp/pz, 1x subc */ |
| 211 |
return x >> 31 ? x + 1 : x; |
| 212 |
} |
| 213 |
|
| 214 |
int |
| 215 |
test_27 (int x, int y, int z) |
| 216 |
{ |
| 217 |
/* 1x cmp/pz, 1x addc */ |
| 218 |
return 1 - ((x >> 4) < 0) + z; |
| 219 |
} |