gcc/
[official-gcc.git] / gcc / testsuite / gcc.target / avr / torture / sat-ur-plus-minus.c
blobbc3c0bbcd9484c297dec1b9ec1616093ca8f6743
1 /* { dg-do run } */
2 /* { dg-options "-std=gnu99 -fwrapv" } */
4 #include "fix-types.h"
6 extern void abort (void);
7 extern void exit (int);
9 typedef unsigned _Fract fx_t;
10 typedef unsigned _Sat _Fract satfx_t;
11 typedef unsigned int intfx_t;
13 US_LFUN (us_add, +, fx_t, ur, >)
14 US_LFUN (us_sub, -, fx_t, ur, <)
16 #define VAL(N, X) \
17 __attribute__((noinline,noclone)) \
18 satfx_t us_add2_##N (satfx_t a) \
19 { \
20 return us_add_ur (a, X##P##-##16ur); \
21 } \
22 __attribute__((noinline,noclone)) \
23 satfx_t us_add_##N (satfx_t a) \
24 { \
25 return a + X##P##-##16ur; \
26 } \
27 __attribute__((noinline,noclone)) \
28 satfx_t us_sub2_##N (satfx_t a) \
29 { \
30 return us_sub_ur (a, X##P##-##16ur); \
31 } \
32 __attribute__((noinline,noclone)) \
33 satfx_t us_sub_##N (satfx_t a) \
34 { \
35 return a - X##P##-##16ur; \
37 #include "vals-ur.def"
38 #undef VAL
40 satfx_t (* __flash const fun[])(satfx_t) =
42 #define VAL(N, X) \
43 us_add_##N, us_add2_##N, \
44 us_sub_##N, us_sub2_##N,
45 #include "vals-ur.def"
46 #undef VAL
50 const volatile __flash intfx_t vals[] =
52 0, -1, 1, -2, 2, -127, -128, -129,
53 0x7f, 0x80, 0x81, 0x100,
54 0x4000, 0x3e80, 0x3f80,
55 0x7ffe, 0x7fff,
56 0x7f7f, 0x7f81, 0x7f80,
57 0x7f01,
58 0x8000, 0x8001, 0x8080,
59 0x8081, 0x80ff, 0x80fe,
60 0x8100, 0x8180, 0x817f,
61 0xff00, 0xff01, 0xff01,
62 0xff7f, 0xff80
66 int main (void)
68 for (unsigned int i = 0; i < sizeof (vals) / sizeof (*vals); i++)
70 satfx_t a, f1, f2;
71 intfx_t val = vals[i];
72 __builtin_memcpy (&a, &val, sizeof (satfx_t));
73 for (unsigned int f = 0; f < sizeof (fun) / sizeof (*fun); f += 2)
75 if (fun[f](a) != fun[f+1](a))
76 abort();
80 exit (0);
81 return 0;