| 1 |
/* PR optimization/10024 */ |
| 2 |
extern int *allegro_errno; |
| 3 |
typedef long fixed; |
| 4 |
extern inline int |
| 5 |
fixfloor (fixed x) |
| 6 |
{ |
| 7 |
if (x >= 0) |
| 8 |
return (x >> 16); |
| 9 |
else |
| 10 |
return ~((~x) >> 16); |
| 11 |
} |
| 12 |
extern inline int |
| 13 |
fixtoi (fixed x) |
| 14 |
{ |
| 15 |
return fixfloor (x) + ((x & 0x8000) >> 15); |
| 16 |
} |
| 17 |
extern inline fixed |
| 18 |
ftofix (double x) |
| 19 |
{ |
| 20 |
if (x > 32767.0) |
| 21 |
{ |
| 22 |
*allegro_errno = 34; |
| 23 |
return 0x7FFFFFFF; |
| 24 |
} |
| 25 |
if (x < -32767.0) |
| 26 |
{ |
| 27 |
*allegro_errno = 34; |
| 28 |
return -0x7FFFFFFF; |
| 29 |
} |
| 30 |
return (long) (x * 65536.0 + (x < 0 ? -0.5 : 0.5)); |
| 31 |
} |
| 32 |
extern inline double |
| 33 |
fixtof (fixed x) |
| 34 |
{ |
| 35 |
return (double) x / 65536.0; |
| 36 |
} |
| 37 |
extern inline fixed |
| 38 |
fixdiv (fixed x, fixed y) |
| 39 |
{ |
| 40 |
if (y == 0) |
| 41 |
{ |
| 42 |
*allegro_errno = 34; |
| 43 |
return (x < 0) ? -0x7FFFFFFF : 0x7FFFFFFF; |
| 44 |
} |
| 45 |
else |
| 46 |
return ftofix (fixtof (x) / fixtof (y)); |
| 47 |
} |
| 48 |
extern inline fixed |
| 49 |
itofix (int x) |
| 50 |
{ |
| 51 |
return x << 16; |
| 52 |
} |
| 53 |
|
| 54 |
int |
| 55 |
foo (int n) |
| 56 |
{ |
| 57 |
return fixtoi (fixdiv (itofix (512), itofix (n))); |
| 58 |
} |