File: IntArith.c

package info (click to toggle)
oo2c32 1.5.4-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 8,888 kB
  • ctags: 5,436
  • sloc: ansic: 95,310; sh: 473; makefile: 345; perl: 57; lisp: 20
file content (359 lines) | stat: -rw-r--r-- 6,677 bytes parent folder | download | duplicates (2)
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
/* file generated by oo2c -- do not edit */
#include "__oo2c.h"
#include "__libc.h"
#include "IntArith.d"

static _ModId _mid;

signed char IntArith__Sgn(int i) {
  register int i0;
  i0 = i < 0;
  if (i0) goto l1;
  i0 = i > 0;
  if (i0) goto l0;
  i0 = 0;
  goto l2;
l0:
  i0 = 1;
  goto l2;
l1:
  i0 = -1;
l2:
  return (signed char)i0;
}

unsigned char IntArith__OutOfRange(int value, signed char range, short int *err) {
  register int i0;
  i0 = StdTypes__WholeMin((signed char)range);
  i0 = value < i0;
  if (i0) goto l0;
  i0 = StdTypes__WholeMax((signed char)range);
  i0 = value > i0;
  if (i0) goto l0;
  i0 = 0;
  goto l1;
l0:
  *err = 350;
  i0 = 1;
l1:
  return (unsigned char)i0;
}

unsigned char IntArith__Includes(signed char range0, signed char range1) {
  register int i0, i1, i2;
  i0 = range0 >= 8;
  if (i0) goto l2;
  i0 = range1 >= 8;
  if (i0) goto l2;
  i2 = StdTypes__WholeMin((signed char)range0);
  i1 = StdTypes__WholeMin((signed char)range1);
  i2 = i2 > i1;
  if (i2) goto l0;
  i2 = StdTypes__WholeMax((signed char)range1);
  i1 = StdTypes__WholeMax((signed char)range0);
  i1 = i2 <= i1;
  if (i1) goto l1;
l0:
  i2 = 0;
  goto l3;
l1:
  i2 = 1;
  goto l3;
l2:
  i2 = range0 >= range1;
l3:
  return (unsigned char)i2;
}

int IntArith__Add(int x, int y, signed char range, short int *err) {
  register int i0, i1;
  i1 = IntArith__Sgn((int)x);
  i0 = IntArith__Sgn((int)y);
  i0 = i1 != i0;
  if (i0) goto l0;
  i0 = x != 0;
  if (i0) goto l1;
l0:
  i0 = 0;
  goto l3;
l1:
  i0 = x > 0;
  if (i0) goto l2;
  i0 = StdTypes__WholeMin((signed char)range);
  i0 -= y;
  i0 = x < i0;
  goto l3;
l2:
  i0 = StdTypes__WholeMax((signed char)range);
  i0 -= y;
  i0 = x > i0;
l3:
  if (i0) goto l4;
  i1 = x + y;
  i0 = *err;
  i0 = IntArith__OutOfRange((int)i1, (signed char)range, (short int *)(int)err);
  if (i0) goto l4;
  *err = -1;
  goto l5;
l4:
  *err = 350;
  i1 = 1;
l5:
  return (int)i1;
}

int IntArith__Sub(int x, int y, signed char range, short int *err) {
  register int i0, i1;
  i0 = y == (-2147483647-1);
  if (i0) goto l0;
  i0 = - y;
  i1 = *err;
  i1 = IntArith__Add((int)x, (int)i0, (signed char)range, (short int *)(int)err);
  goto l2;
l0:
  i0 = x == 2147483647;
  if (i0) goto l1;
  i0 = x + 1;
  i1 = *err;
  i1 = IntArith__Add((int)i0, (int)2147483647, (signed char)range, (short int *)(int)err);
  goto l2;
l1:
  *err = 350;
  i1 = 1;
l2:
  return (int)i1;
}

int IntArith__Mult(int x, int y, signed char range, short int *err) {
  register int i0, i1, i2, i3, i4;
  i0 = x == 0;
  *err = -1;
  if (i0) goto l0;
  i1 = y == 0;
  if (i1) goto l0;
  i4 = x == 1;
  if (i4) goto l0;
  i1 = y != 1;
  if (i1) goto l1;
l0:
  i3 = x;
  i2 = y;
  goto l7;
l1:
  i0 = StdTypes__WholeMin((signed char)range);
  i4 = x == i0;
  if (i4) goto l6;
  i1 = y == i0;
  if (i1) goto l6;
  i1 = IntArith__Sgn((int)y);
  i4 = IntArith__Sgn((int)x);
  i1 = i4 != i1;
  if (i1) goto l2;
  i1 = - x;
  i1 = IntArith__Mult((int)i1, (int)y, (signed char)range, (short int *)(int)err);
  i1 = i1 == i0;
  if (i1) goto l6;
l2:
  i3 = y < 0;
  if (i3) goto l3;
  i3 = x;
  i2 = y;
  goto l4;
l3:
  i2 = - y;
  i3 = - x;
l4:
  _div(i1, i0, i2, int);
  i4 = i3 < i1;
  if (i4) goto l5;
  i1 = i3 != i1;
  if (i1) goto l7;
  _mod(i0, i0, i2, int);
  i0 = i0 <= 0;
  if (i0) goto l7;
l5:
  *err = 350;
  goto l7;
l6:
  *err = 350;
  i2 = y;
  i3 = x;
l7:
  i0 = *err;
  i1 = i0 > 0;
  if (i1) goto l8;
  i1 = i3 * i2;
  i2 = IntArith__OutOfRange((int)i1, (signed char)range, (short int *)(int)err);
  if (!(i2)) goto l9;
l8:
  i1 = 1;
l9:
  return (int)i1;
}

int IntArith__Div(int x, int y, signed char range, short int *err) {
  register int i0, i1, i2;
  *err = -1;
  i0 = y == 0;
  if (i0) goto l4;
  i0 = y < 0;
  if (i0) goto l0;
  _div(i2, x, y, int);
  goto l5;
l0:
  i1 = StdTypes__WholeMin((signed char)range);
  i0 = y == i1;
  if (i0) goto l2;
  i0 = x == i1;
  if (i0) goto l1;
  i0 = - x;
  i2 = - y;
  i2 = IntArith__Div((int)i0, (int)i2, (signed char)range, (short int *)(int)err);
  goto l5;
l1:
  i2 = x - y;
  i2 = - i2;
  i0 = - y;
  i2 = IntArith__Div((int)i2, (int)i0, (signed char)range, (short int *)(int)err);
  i2++;
  goto l5;
l2:
  i1 = x == i1;
  if (i1) goto l3;
  i2 = 0;
  goto l5;
l3:
  i2 = 1;
  goto l5;
l4:
  *err = 351;
  i2 = 1;
l5:
  i1 = *err;
  i0 = i1 > 0;
  if (i0) goto l6;
  i1 = IntArith__OutOfRange((int)i2, (signed char)range, (short int *)(int)err);
  if (!(i1)) goto l7;
l6:
  i2 = 1;
l7:
  return (int)i2;
}

int IntArith__Mod(int x, int y, signed char range, short int *err) {
  register int i0, i1, i2;
  *err = -1;
  i0 = y == 0;
  if (i0) goto l4;
  i0 = y < 0;
  if (i0) goto l0;
  _mod(i2, x, y, int);
  goto l5;
l0:
  i1 = StdTypes__WholeMin((signed char)range);
  i0 = y == i1;
  if (i0) goto l2;
  i0 = x == i1;
  if (i0) goto l1;
  i2 = - x;
  i0 = - y;
  i2 = IntArith__Mod((int)i2, (int)i0, (signed char)range, (short int *)(int)err);
  i2 = - i2;
  goto l5;
l1:
  i2 = x - y;
  i2 = - i2;
  i0 = - y;
  i2 = IntArith__Mod((int)i2, (int)i0, (signed char)range, (short int *)(int)err);
  i2 = - i2;
  goto l5;
l2:
  i1 = x == i1;
  if (i1) goto l3;
  i2 = y;
  goto l5;
l3:
  i2 = 0;
  goto l5;
l4:
  *err = 351;
  i2 = 1;
l5:
  i1 = *err;
  i0 = i1 > 0;
  if (i0) goto l6;
  i1 = IntArith__OutOfRange((int)i2, (signed char)range, (short int *)(int)err);
  if (!(i1)) goto l7;
l6:
  i2 = 1;
l7:
  return (int)i2;
}

int IntArith__Neg(int x, signed char range, short int *err) {
  register int i0;
  i0 = *err;
  i0 = IntArith__Sub((int)0, (int)x, (signed char)range, (short int *)(int)err);
  return (int)i0;
}

int IntArith__Abs(int x, signed char range, short int *err) {
  register int i0;
  i0 = x >= 0;
  if (i0) goto l0;
  i0 = *err;
  i0 = IntArith__Neg((int)x, (signed char)range, (short int *)(int)err);
  goto l1;
l0:
  *err = -1;
  i0 = x;
l1:
  return (int)i0;
}

int IntArith__Ash(int x, int y, signed char range, short int *err) {
  register int i0, i1, i2, i3, i4;
  *err = -1;
  i0 = y == 0;
  if (i0) goto l3;
  i3 = *err;
  i1 = i3 >= 0;
  if (i1) goto l3;
  i4 = x;
  i2 = y;
l0:
  i0 = i2 < 0;
  if (i0) goto l1;
  i3 = *err;
  i3 = IntArith__Mult((int)i4, (int)2, (signed char)range, (short int *)(int)err);
  i0 = i2 - 1;
  i2 = i0;
  i4 = i3;
  goto l2;
l1:
  i0 = *err;
  i0 = IntArith__Div((int)i4, (int)2, (signed char)range, (short int *)(int)err);
  i3 = i2 + 1;
  i2 = i3;
  i4 = i0;
l2:
  i0 = i2 != 0;
  if (!(i0)) goto l4;
  i0 = *err;
  i0 = i0 < 0;
  if (i0) goto l0;
  goto l4;
l3:
  i4 = x;
l4:
  i0 = *err;
  i1 = i0 < 0;
  if (i1) goto l5;
  i4 = 1;
l5:
  return (int)i4;
}

void IntArith_init(void) {
  _mid = _register_module(&IntArith_md.md, NULL);
}