diff --git a/tools/qfcc/test/Makefile.am b/tools/qfcc/test/Makefile.am index a98cc2001..4c8e5b113 100644 --- a/tools/qfcc/test/Makefile.am +++ b/tools/qfcc/test/Makefile.am @@ -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) diff --git a/tools/qfcc/test/modulo.r b/tools/qfcc/test/modulo.r new file mode 100644 index 000000000..8175cc567 --- /dev/null +++ b/tools/qfcc/test/modulo.r @@ -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; +} diff --git a/tools/qfcc/test/old/modulo.r b/tools/qfcc/test/old/modulo.r deleted file mode 100644 index f12f1645f..000000000 --- a/tools/qfcc/test/old/modulo.r +++ /dev/null @@ -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