mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-11 15:51:36 +00:00
b920a4dec9
It turns out that the optimizer completely breaks (a + b) % (a - b) with v6 code.
56 lines
1,014 B
R
56 lines
1,014 B
R
#pragma traditional
|
|
|
|
void (...) printf = #0;
|
|
float foo (float a, float b)
|
|
{
|
|
float c = a % b;
|
|
return c;
|
|
}
|
|
float bar (float a, float b)
|
|
{
|
|
float c;
|
|
b &= b;
|
|
a &= a;
|
|
c = a - ((a / b) & -1) * b;
|
|
return c;
|
|
}
|
|
|
|
float baz (float a, float b)
|
|
{
|
|
float c = (a + b) % (a - b);
|
|
return c;
|
|
}
|
|
|
|
float test (string name, float (func)(float a, float b),
|
|
float a, float b, float c)
|
|
{
|
|
float ret;
|
|
|
|
ret = func (a, b);
|
|
if (ret != c) {
|
|
printf ("%s: %g %% %g: %g != %g\n", name, a, b, ret, c);
|
|
return 1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
float main (void)
|
|
{
|
|
float res = 0;
|
|
res |= test ("foo", foo, 5, 3, 2);
|
|
res |= test ("bar", bar, 5, 3, 2);
|
|
res |= test ("baz", baz, 5, 3, 0);
|
|
|
|
res |= test ("foo", foo, -5, 3, -2);
|
|
res |= test ("bar", bar, -5, 3, -2);
|
|
res |= test ("baz", baz, -5, 3, -2);
|
|
|
|
res |= test ("foo", foo, 5, -3, 2);
|
|
res |= test ("bar", bar, 5, -3, 2);
|
|
res |= test ("baz", baz, 5, -3, 2);
|
|
|
|
res |= test ("foo", foo, -5, -3, -2);
|
|
res |= test ("bar", bar, -5, -3, -2);
|
|
res |= test ("baz", baz, -5, -3, 0);
|
|
return res;
|
|
}
|