summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/fixed-point/binary.c
blob: e2cb6ea258c205455a8898acc6e2a53b14715346 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/* { dg-do run } */
/* { dg-options "-std=gnu99" } */

/* N1169 6.5.7 - Bitwise shift operands.
   C99 6.5.5 Multiplicative operators.
   C99 6.5.6 Additive operators.
   C99 6.5.7 Bitwise shift operators.
   C99 6.5.8 Relational operators.
   C99 6.5.9 Equality operators.
   C99 6.5.16 Assignment operators.

   Check binary operators + - * / << >> < <= >= > == != += -= *= /= <<= >>=.  */

extern void abort (void);

#define BINARY(TYPE,POSTFIX) \
  { TYPE a = 0.5 ## POSTFIX; \
    TYPE b = 0.25 ## POSTFIX; \
    if (a + b != 0.75 ## POSTFIX) \
      abort(); \
    if (a - b != 0.25 ## POSTFIX) \
      abort(); \
    if (a * b != 0.125 ## POSTFIX) \
      abort(); \
    if (b / a != 0.5 ## POSTFIX) \
      abort(); \
    if (b << 1 != a) \
      abort(); \
    if (a >> 1 != b) \
      abort(); \
    if (a < b != 0) \
      abort(); \
    if (a <= b != 0) \
      abort(); \
    if (a > b != 1) \
      abort(); \
    if (a >= b != 1) \
      abort(); \
    if (a == b != 0) \
      abort(); \
    if (a != b != 1) \
      abort(); \
    a += b; \
    if (a != 0.75 ## POSTFIX) \
      abort(); \
    a -= b; \
    if (a != 0.5 ## POSTFIX) \
      abort(); \
    a *= b; \
    if (a != 0.125 ## POSTFIX) \
      abort(); \
    a /= b; \
    if (a != 0.5 ## POSTFIX) \
      abort(); \
    a >>= 2; \
    if (a != 0.125 ## POSTFIX) \
      abort(); \
    a <<= 1; \
    if (a != 0.25 ## POSTFIX) \
      abort(); \
  }

#define FRACT_SAT_BINARY(TYPE,POSTFIX) \
  { TYPE a = 0.7 ## POSTFIX; \
    TYPE b = 0.9 ## POSTFIX; \
    if (a + b != 1.0 ## POSTFIX) \
      abort(); \
    a = -0.7 ## POSTFIX; \
    b = -0.9 ## POSTFIX; \
    if (a + b != -0.5 ## POSTFIX - 0.5 ## POSTFIX) \
      abort(); \
    a = 0.7 ## POSTFIX; \
    b = -0.9 ## POSTFIX; \
    if (a - b != 1.0 ## POSTFIX) \
      abort(); \
    a = -0.7 ## POSTFIX; \
    b = 0.9 ## POSTFIX; \
    if (a - b != -0.5 ## POSTFIX - 0.5 ## POSTFIX) \
      abort(); \
    a = -0.5 ## POSTFIX - 0.5 ## POSTFIX; \
    if (a * a != 1.0 ## POSTFIX) \
      abort(); \
    a = 0.8 ## POSTFIX; \
    b = 0.5 ## POSTFIX; \
    if (a / b != 1.0 ## POSTFIX) \
      abort(); \
    a = -0.8 ## POSTFIX; \
    b = 0.5 ## POSTFIX; \
    if (a / b != -0.5 ## POSTFIX - 0.5 ## POSTFIX) \
      abort(); \
    a = 0.1 ## POSTFIX; \
    if (a << 4 != 1.0 ## POSTFIX) \
      abort(); \
    a = -0.8 ## POSTFIX; \
    if (a << 4 != -0.5 ## POSTFIX - 0.5 ## POSTFIX) \
      abort(); \
  }

#define FRACT_SAT_UNS_BINARY(TYPE,POSTFIX) \
  { TYPE a = 0.7 ## POSTFIX; \
    TYPE b = 0.9 ## POSTFIX; \
    if (a + b != 1.0 ## POSTFIX) \
      abort(); \
    if (a - b != 0.0 ## POSTFIX) \
      abort(); \
    if (b / a != 1.0 ## POSTFIX) \
      abort(); \
    if (a << 1 != 1.0 ## POSTFIX) \
      abort(); \
  }

int main ()
{
  BINARY(short _Fract, hr);
  BINARY(_Fract, r);
  BINARY(long _Fract, lr);
  BINARY(long long _Fract, llr);
  BINARY(unsigned short _Fract, uhr);
  BINARY(unsigned _Fract, ur);
  BINARY(unsigned long _Fract, ulr);
  BINARY(unsigned long long _Fract, ullr);
  BINARY(_Sat short _Fract, hr);
  BINARY(_Sat _Fract, r);
  BINARY(_Sat long _Fract, lr);
  BINARY(_Sat long long _Fract, llr);
  BINARY(_Sat unsigned short _Fract, uhr);
  BINARY(_Sat unsigned _Fract, ur);
  BINARY(_Sat unsigned long _Fract, ulr);
  BINARY(_Sat unsigned long long _Fract, ullr);
  BINARY(short _Accum, hk);
  BINARY(_Accum, k);
  BINARY(long _Accum, lk);
  BINARY(long long _Accum, llk);
  BINARY(unsigned short _Accum, uhk);
  BINARY(unsigned _Accum, uk);
  BINARY(unsigned long _Accum, ulk);
  BINARY(unsigned long long _Accum, ullk);
  BINARY(_Sat short _Accum, hk);
  BINARY(_Sat _Accum, k);
  BINARY(_Sat long _Accum, lk);
  BINARY(_Sat long long _Accum, llk);
  BINARY(_Sat unsigned short _Accum, uhk);
  BINARY(_Sat unsigned _Accum, uk);
  BINARY(_Sat unsigned long _Accum, ulk);
  BINARY(_Sat unsigned long long _Accum, ullk);

  FRACT_SAT_BINARY(_Sat short _Fract, hr);
  FRACT_SAT_BINARY(_Sat _Fract, r);
  FRACT_SAT_BINARY(_Sat long _Fract, lr);
  FRACT_SAT_BINARY(_Sat long long _Fract, llr);

  FRACT_SAT_UNS_BINARY(_Sat unsigned short _Fract, uhr);
  FRACT_SAT_UNS_BINARY(_Sat unsigned _Fract, ur);
  FRACT_SAT_UNS_BINARY(_Sat unsigned long _Fract, ulr);
  FRACT_SAT_UNS_BINARY(_Sat unsigned long long _Fract, ullr);

  return 0;
}