| 1 |
/* { dg-do run } */ |
| 2 |
|
| 3 |
typedef __UINT32_TYPE__ uint32_t; |
| 4 |
typedef __UINT8_TYPE__ uint8_t; |
| 5 |
typedef __INT8_TYPE__ int8_t; |
| 6 |
typedef uint8_t pixel; |
| 7 |
|
| 8 |
#define MSB (__CHAR_BIT__ * __SIZEOF_INT__ - 1) |
| 9 |
|
| 10 |
/* get the sign of input variable (TODO: this is a dup, make common) */ |
| 11 |
static inline int8_t signOf(int x) |
| 12 |
{ |
| 13 |
return (x >> MSB) | ((int)((((uint32_t)-x)) >> MSB)); |
| 14 |
} |
| 15 |
|
| 16 |
__attribute__((noipa)) |
| 17 |
static void calSign_bug(int8_t *dst, const pixel *src1, const pixel *src2, const int endX) |
| 18 |
{ |
| 19 |
for (int x = 0; x < endX; x++) |
| 20 |
dst[x] = signOf(src1[x] - src2[x]); |
| 21 |
} |
| 22 |
|
| 23 |
__attribute__((noipa, optimize(0))) |
| 24 |
static void calSign_ok(int8_t *dst, const pixel *src1, const pixel *src2, const int endX) |
| 25 |
{ |
| 26 |
for (int x = 0; x < endX; x++) |
| 27 |
dst[x] = signOf(src1[x] - src2[x]); |
| 28 |
} |
| 29 |
|
| 30 |
__attribute__((noipa, optimize(0))) |
| 31 |
int main() |
| 32 |
{ |
| 33 |
const pixel s1[9] = { 0xcd, 0x33, 0xd4, 0x3e, 0xb0, 0xfb, 0x95, 0x64, 0x70, }; |
| 34 |
const pixel s2[9] = { 0xba, 0x9f, 0xab, 0xa1, 0x3b, 0x29, 0xb1, 0xbd, 0x64, }; |
| 35 |
int endX = 9; |
| 36 |
int8_t dst[9]; |
| 37 |
int8_t dst_ok[9]; |
| 38 |
|
| 39 |
calSign_bug(dst, s1, s2, endX); |
| 40 |
calSign_ok(dst_ok, s1, s2, endX); |
| 41 |
|
| 42 |
if (__builtin_memcmp(dst, dst_ok, endX) != 0) |
| 43 |
__builtin_abort (); |
| 44 |
return 0; |
| 45 |
} |