1 /* { dg-do run { target { ! avr_tiny } } } */
2 /* { dg-options "-std=gnu99 -fwrapv" } */
3 
4 #include "fix-types.h"
5 
6 extern void abort (void);
7 extern void exit (int);
8 
9 typedef unsigned _Accum fx_t;
10 typedef unsigned _Sat _Accum satfx_t;
11 typedef unsigned long intfx_t;
12 
13 US_LFUN (us_add, +, fx_t, uk, >)
14 US_LFUN (us_sub, -, fx_t, uk, <)
15 
16 #define VAL(N, X)                               \
17     __attribute__((noinline,noclone))           \
18     satfx_t us_add2_##N (satfx_t a)             \
19     {                                           \
20         return us_add_uk (a, X##P##-##16uk);    \
21     }                                           \
22     __attribute__((noinline,noclone))           \
23     satfx_t us_add_##N (satfx_t a)              \
24     {                                           \
25         return a + X##P##-##16uk;               \
26     }                                           \
27     __attribute__((noinline,noclone))           \
28     satfx_t us_sub2_##N (satfx_t a)             \
29     {                                           \
30         return us_sub_uk (a, X##P##-##16uk);    \
31     }                                           \
32     __attribute__((noinline,noclone))           \
33     satfx_t us_sub_##N (satfx_t a)              \
34     {                                           \
35         return a - X##P##-##16uk;               \
36     }
37 #include "vals-uk.def"
38 #undef VAL
39 
40 satfx_t (* __flash const fun[])(satfx_t) =
41 {
42 #define VAL(N, X)                               \
43   us_add_##N, us_add2_##N,                      \
44   us_sub_##N, us_sub2_##N,
45 #include "vals-uk.def"
46 #undef VAL
47 };
48 
49 
50 const volatile __flash intfx_t vals[] =
51   {
52     0, -1, 1, -2, 2, -127, -128, -129,
53     0x7f, 0x80, 0x81, 0x100,
54     0x40000000, 0x3e800000, 0x3f800000,
55     0x7ffffffe, 0x7fffffff, 0x7f800000,
56     0x7f7f7f7f, 0x7f810080, 0x7f008000,
57     0x7f000001,
58     0x80000000, 0x80000001, 0x80808080,
59     0x80810000, 0x80ffffff, 0x80fffffe,
60     0x81000000, 0x81800000, 0x81800000,
61     0xff000000, 0xffffff01, 0xffffff80,
62     0xffffff7f, 0xff80ff80
63   };
64 
65 
main(void)66 int main (void)
67 {
68   for (unsigned int i = 0; i < sizeof (vals) / sizeof (*vals); i++)
69     {
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)
74         {
75           if (fun[f](a) != fun[f+1](a))
76             abort();
77         }
78     }
79 
80   exit (0);
81   return 0;
82 }
83