1 /* { dg-options "-std=gnu99" } */
2 /* { dg-do run } */
3 
4 #include <stdfix.h>
5 
6 extern void abort (void);
7 
8 #define DEFTEST1(T,FX)                              \
9   int test1_##FX (T x)                              \
10   {                                                 \
11     return countls##FX (x);                         \
12   }                                                 \
13                                                     \
14   int test1_u##FX (unsigned T x)                    \
15   {                                                 \
16     return countlsu##FX (x);                        \
17   }
18 
DEFTEST1(short fract,hr)19 DEFTEST1 (short fract, hr)
20 DEFTEST1 (fract, r)
21 DEFTEST1 (long fract, lr)
22 DEFTEST1 (long long fract, llr)
23 
24 DEFTEST1 (short accum, hk)
25 DEFTEST1 (accum, k)
26 DEFTEST1 (long accum, lk)
27 DEFTEST1 (long long accum, llk)
28 
29 
30 #define TEST2P(FX, VAL, DD)                                             \
31   {                                                                     \
32     if (countls##FX (FX##bits (VAL)) != 8 * sizeof (0##FX) - DD)        \
33       abort();                                                          \
34                                                                         \
35     if (countlsu##FX (u##FX##bits (VAL)) != 8 * sizeof (0u##FX) + 1 - DD) \
36       abort();                                                          \
37   }
38 
39 
40 #define TEST2M(FX, VAL, DD)                                             \
41   {                                                                     \
42     if (countls##FX (FX##bits (VAL)) != 8 * sizeof (0##FX) - (DD))      \
43       abort();                                                          \
44                                                                         \
45     if (countlsu##FX (u##FX##bits (VAL)) != 0)                          \
46       abort();                                                          \
47   }
48 
49 
50 #define TEST2PX(VAL, DD)                        \
51   TEST2P (hr, VAL, DD);                         \
52   TEST2P (r,  VAL, DD);                         \
53   TEST2P (lr, VAL, DD);                         \
54                                                 \
55   TEST2P (hk, VAL, DD);                         \
56   TEST2P (k,  VAL, DD);                         \
57   TEST2P (lk, VAL, DD);                         \
58   TEST2P (llk, VAL, DD)
59 
60 #define TEST2MX(VAL, DD)                        \
61   TEST2M (hr, VAL,  DD);                        \
62   TEST2M (r,  VAL,  DD);                        \
63   TEST2M (lr, VAL,  DD);                        \
64                                                 \
65   TEST2M (hk,  VAL, DD);                        \
66   TEST2M (k,   VAL, DD);                        \
67   TEST2M (lk,  VAL, DD);                        \
68   TEST2M (llk, VAL, DD)
69 
70 
71 int main (void)
72 {
73   TEST2PX (1, 2);
74   TEST2PX (2, 3);
75   TEST2PX (3, 3);
76 
77   TEST2MX (-1, 1);
78   TEST2MX (-2, 2);
79   TEST2MX (-3, 3);
80 
81   return 0;
82 }
83