@@ -56,7 +56,13 @@ static inline short NEG16(int x)
56
56
}
57
57
res = - x ;
58
58
if (!VERIFY_SHORT (res ))
59
- fprintf (stderr , "NEG16: output is not short: %d\n" , (int )res );
59
+ {
60
+ fprintf (stderr , "NEG16: output is not short: %d\n" , (int )res );
61
+ if (res > 32767 )
62
+ res = 32767 ;
63
+ if (res < -32768 )
64
+ res = -32768 ;
65
+ }
60
66
spx_mips ++ ;
61
67
return res ;
62
68
}
@@ -110,7 +116,13 @@ static inline short _SHR16(int a, int shift, char *file, int line)
110
116
}
111
117
res = a >>shift ;
112
118
if (!VERIFY_SHORT (res ))
113
- fprintf (stderr , "SHR16: output is not short: %d in %s: line %d\n" , res , file , line );
119
+ {
120
+ fprintf (stderr , "SHR16: output is not short: %d in %s: line %d\n" , res , file , line );
121
+ if (res > 32767 )
122
+ res = 32767 ;
123
+ if (res < -32768 )
124
+ res = -32768 ;
125
+ }
114
126
spx_mips ++ ;
115
127
return res ;
116
128
}
@@ -124,7 +136,13 @@ static inline short _SHL16(int a, int shift, char *file, int line)
124
136
}
125
137
res = (int )((unsigned )a <<shift );
126
138
if (!VERIFY_SHORT (res ))
127
- fprintf (stderr , "SHL16: output is not short: %d in %s: line %d\n" , res , file , line );
139
+ {
140
+ fprintf (stderr , "SHL16: output is not short: %d in %s: line %d\n" , res , file , line );
141
+ if (res > 32767 )
142
+ res = 32767 ;
143
+ if (res < -32768 )
144
+ res = -32768 ;
145
+ }
128
146
spx_mips ++ ;
129
147
return res ;
130
148
}
@@ -181,7 +199,11 @@ static inline short _ADD16(int a, int b, char *file, int line)
181
199
res = a + b ;
182
200
if (!VERIFY_SHORT (res ))
183
201
{
184
- fprintf (stderr , "ADD16: output is not short: %d+%d=%d in %s: line %d\n" , a ,b ,res , file , line );
202
+ fprintf (stderr , "ADD16: output is not short: %d+%d=%d in %s: line %d\n" , a ,b ,res , file , line );
203
+ if (res > 32767 )
204
+ res = 32767 ;
205
+ if (res < -32768 )
206
+ res = -32768 ;
185
207
}
186
208
spx_mips ++ ;
187
209
return res ;
@@ -197,7 +219,13 @@ static inline short _SUB16(int a, int b, char *file, int line)
197
219
}
198
220
res = a - b ;
199
221
if (!VERIFY_SHORT (res ))
200
- fprintf (stderr , "SUB16: output is not short: %d in %s: line %d\n" , res , file , line );
222
+ {
223
+ fprintf (stderr , "SUB16: output is not short: %d in %s: line %d\n" , res , file , line );
224
+ if (res > 32767 )
225
+ res = 32767 ;
226
+ if (res < -32768 )
227
+ res = -32768 ;
228
+ }
201
229
spx_mips ++ ;
202
230
return res ;
203
231
}
@@ -227,8 +255,14 @@ static inline int SUB32(long long a, long long b)
227
255
fprintf (stderr , "SUB32: inputs are not int: %d %d\n" , (int )a , (int )b );
228
256
}
229
257
res = a - b ;
230
- if (!VERIFY_INT (res ))
231
- fprintf (stderr , "SUB32: output is not int: %d\n" , (int )res );
258
+ if (!VERIFY_SHORT (res ))
259
+ {
260
+ fprintf (stderr , "SUB32: output is not int: %d\n" , (int )res );
261
+ if (res > 32767 )
262
+ res = 32767 ;
263
+ if (res < -32768 )
264
+ res = -32768 ;
265
+ }
232
266
spx_mips ++ ;
233
267
return res ;
234
268
}
@@ -245,7 +279,13 @@ static inline short MULT16_16_16(int a, int b)
245
279
}
246
280
res = a * b ;
247
281
if (!VERIFY_SHORT (res ))
248
- fprintf (stderr , "MULT16_16_16: output is not short: %d\n" , res );
282
+ {
283
+ fprintf (stderr , "MULT16_16_16: output is not short: %d\n" , res );
284
+ if (res > 32767 )
285
+ res = 32767 ;
286
+ if (res < -32768 )
287
+ res = -32768 ;
288
+ }
249
289
spx_mips ++ ;
250
290
return res ;
251
291
}
@@ -329,8 +369,14 @@ static inline int MULT16_16_Q11_32(int a, int b)
329
369
}
330
370
res = ((long long )a )* b ;
331
371
res >>= 11 ;
332
- if (!VERIFY_INT (res ))
333
- fprintf (stderr , "MULT16_16_Q11: output is not short: %d*%d=%d\n" , (int )a , (int )b , (int )res );
372
+ if (!VERIFY_SHORT (res ))
373
+ {
374
+ fprintf (stderr , "MULT16_16_Q11: output is not short: %d*%d=%d\n" , (int )a , (int )b , (int )res );
375
+ if (res > 32767 )
376
+ res = 32767 ;
377
+ if (res < -32768 )
378
+ res = -32768 ;
379
+ }
334
380
spx_mips += 3 ;
335
381
return res ;
336
382
}
@@ -344,7 +390,13 @@ static inline short MULT16_16_Q13(int a, int b)
344
390
res = ((long long )a )* b ;
345
391
res >>= 13 ;
346
392
if (!VERIFY_SHORT (res ))
347
- fprintf (stderr , "MULT16_16_Q13: output is not short: %d*%d=%d\n" , a , b , (int )res );
393
+ {
394
+ fprintf (stderr , "MULT16_16_Q13: output is not short: %d*%d=%d\n" , a , b , (int )res );
395
+ if (res > 32767 )
396
+ res = 32767 ;
397
+ if (res < -32768 )
398
+ res = -32768 ;
399
+ }
348
400
spx_mips += 3 ;
349
401
return res ;
350
402
}
@@ -358,7 +410,13 @@ static inline short MULT16_16_Q14(int a, int b)
358
410
res = ((long long )a )* b ;
359
411
res >>= 14 ;
360
412
if (!VERIFY_SHORT (res ))
361
- fprintf (stderr , "MULT16_16_Q14: output is not short: %d\n" , (int )res );
413
+ {
414
+ fprintf (stderr , "MULT16_16_Q14: output is not short: %d\n" , (int )res );
415
+ if (res > 32767 )
416
+ res = 32767 ;
417
+ if (res < -32768 )
418
+ res = -32768 ;
419
+ }
362
420
spx_mips += 3 ;
363
421
return res ;
364
422
}
@@ -373,7 +431,11 @@ static inline short MULT16_16_Q15(int a, int b)
373
431
res >>= 15 ;
374
432
if (!VERIFY_SHORT (res ))
375
433
{
376
- fprintf (stderr , "MULT16_16_Q15: output is not short: %d\n" , (int )res );
434
+ fprintf (stderr , "MULT16_16_P14: output is not short: %d*%d=%d\n" , a , b , (int )res );
435
+ if (res > 32767 )
436
+ res = 32767 ;
437
+ if (res < -32768 )
438
+ res = -32768 ;
377
439
}
378
440
spx_mips += 3 ;
379
441
return res ;
@@ -392,7 +454,13 @@ static inline short MULT16_16_P13(int a, int b)
392
454
fprintf (stderr , "MULT16_16_P13: overflow: %d*%d=%d\n" , a , b , (int )res );
393
455
res >>= 13 ;
394
456
if (!VERIFY_SHORT (res ))
395
- fprintf (stderr , "MULT16_16_P13: output is not short: %d*%d=%d\n" , a , b , (int )res );
457
+ {
458
+ fprintf (stderr , "MULT16_16_P13: output is not short: %d*%d=%d\n" , a , b , (int )res );
459
+ if (res > 32767 )
460
+ res = 32767 ;
461
+ if (res < -32768 )
462
+ res = -32768 ;
463
+ }
396
464
spx_mips += 4 ;
397
465
return res ;
398
466
}
@@ -409,7 +477,13 @@ static inline short MULT16_16_P14(int a, int b)
409
477
fprintf (stderr , "MULT16_16_P14: overflow: %d*%d=%d\n" , a , b , (int )res );
410
478
res >>= 14 ;
411
479
if (!VERIFY_SHORT (res ))
412
- fprintf (stderr , "MULT16_16_P14: output is not short: %d*%d=%d\n" , a , b , (int )res );
480
+ {
481
+ fprintf (stderr , "MULT16_16_P14: output is not short: %d*%d=%d\n" , a , b , (int )res );
482
+ if (res > 32767 )
483
+ res = 32767 ;
484
+ if (res < -32768 )
485
+ res = -32768 ;
486
+ }
413
487
spx_mips += 4 ;
414
488
return res ;
415
489
}
@@ -426,7 +500,13 @@ static inline short MULT16_16_P15(int a, int b)
426
500
fprintf (stderr , "MULT16_16_P15: overflow: %d*%d=%d\n" , a , b , (int )res );
427
501
res >>= 15 ;
428
502
if (!VERIFY_SHORT (res ))
429
- fprintf (stderr , "MULT16_16_P15: output is not short: %d*%d=%d\n" , a , b , (int )res );
503
+ {
504
+ fprintf (stderr , "MULT16_16_P14: output is not short: %d*%d=%d\n" , a , b , (int )res );
505
+ if (res > 32767 )
506
+ res = 32767 ;
507
+ if (res < -32768 )
508
+ res = -32768 ;
509
+ }
430
510
spx_mips += 4 ;
431
511
return res ;
432
512
}
0 commit comments