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 long long _Accum fx_t;
10 typedef unsigned long long _Sat _Accum satfx_t;
11 typedef unsigned long long intfx_t;
12 
13 US_LFUN (us_add, +, fx_t, ullk, >)
14 US_LFUN (us_sub, -, fx_t, ullk, <)
15 
16 #define VAL(N, X)                               \
17   __attribute__((noinline,noclone))             \
18   satfx_t us_add2_##N (satfx_t a)               \
19   {                                             \
20     return us_add_ullk (a, X##P##-##48ullk);    \
21   }                                             \
22   __attribute__((noinline,noclone))             \
23   satfx_t us_add_##N (satfx_t a)                \
24   {                                             \
25     return a + X##P##-##48ullk;                 \
26   }                                             \
27   __attribute__((noinline,noclone))             \
28   satfx_t us_sub2_##N (satfx_t a)               \
29   {                                             \
30     return us_sub_ullk (a, X##P##-##48ullk);    \
31   }                                             \
32   __attribute__((noinline,noclone))             \
33   satfx_t us_sub_##N (satfx_t a)                \
34   {                                             \
35     return a - X##P##-##48ullk;                 \
36   }
37 #include "vals-ullk.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-ullk.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     0x4000000000000000, 0x3e80000000000000, 0x3f80000000000000,
55     0x7ffffffffffffffe, 0x7fffffffffffffff, 0x7f80000000000000,
56     0x7f7f7f7f7f7f7f7f, 0x7f81000000000080, 0x7f00000080000000,
57     0x7f00000000000001,
58     0x8000000000000000, 0x8000000000000001, 0x8080808080808080,
59     0x8081000000000000, 0x80ffffffffffffff, 0x80fffffffffffffe,
60     0x8100000000000000, 0x8180000000000000, 0x818000000000000,
61     0xff00000000000000, 0xffffffffffffff01, 0xffffffffffffff80,
62     0xffffffffffffff7f, 0xff80ff80ff80ff80
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