Add a new test case.

It turns out that the optimizer completely breaks (a + b) % (a - b) with v6
code.
This commit is contained in:
Bill Currie 2012-11-22 20:49:12 +09:00
parent 47decd58d0
commit b920a4dec9
3 changed files with 64 additions and 39 deletions

View file

@ -18,7 +18,7 @@ QFCC_TEST_LIBS=@QFCC_TEST_LIBS@
QFCC_TEST_DEPS=@QFCC_TEST_DEPS@
QFCC_TEST_INCS=@QFCC_TEST_INCS@
test_progs_dat=structptr.dat while.dat
test_progs_dat=modulo.dat structptr.dat while.dat
TESTS=$(test_progs_dat:.dat=.run)
@ -28,6 +28,13 @@ test_harness_SOURCES= test-bi.c test-harness.c
test_harness_LDADD= $(QFCC_TEST_LIBS)
test_harness_DEPENDENCIES= $(QFCC_TEST_DEPS)
modulo_dat_SOURCES=modulo.r
modulo_obj=$(modulo_dat_SOURCES:.r=.qfo)
modulo.dat: $(modulo_obj) $(QFCC_DEP)
$(QFCC) $(QCFLAGS) -o $@ $(modulo_obj)
modulo.run: Makefile build-run
TEST_HARNESS_OPTS=--float $(srcdir)/build-run $@
structptr_dat_SOURCES=structptr.r
structptr_obj=$(structptr_dat_SOURCES:.r=.qfo)
structptr.dat: $(structptr_obj) $(QFCC_DEP)

56
tools/qfcc/test/modulo.r Normal file
View file

@ -0,0 +1,56 @@
#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;
}

View file

@ -1,38 +0,0 @@
#if 1
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;
}
#endif
float baz (float a, float b)
{
float c = (a + b) % (a - b);
return c;
}
#if 1
float main (void)
{
printf ("foo: 5 %% 3: %f\n", foo (5, 3));
printf ("bar: 5 %% 3: %f\n", bar (5, 3));
printf ("foo: -5 %% 3: %f\n", foo (-5, 3));
printf ("bar: -5 %% 3: %f\n", bar (-5, 3));
printf ("foo: 5 %% -3: %f\n", foo (5, -3));
printf ("bar: 5 %% -3: %f\n", bar (5, -3));
printf ("foo: -5 %% -3: %f\n", foo (-5, -3));
printf ("bar: -5 %% -3: %f\n", bar (-5, -3));
return 0;
}
#endif