tests/fpu: Add tests for fsel and fcmpu
authorPaul Mackerras <paulus@ozlabs.org>
Thu, 30 Jul 2020 03:38:09 +0000 (13:38 +1000)
committerPaul Mackerras <paulus@ozlabs.org>
Thu, 3 Sep 2020 07:45:26 +0000 (17:45 +1000)
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
tests/fpu/fpu.c
tests/test_fpu.bin
tests/test_fpu.console_out

index e62ce27ecdf29f77fd1711d15beeb77e8199c5a2..06da4750b969c7d2484c0eacb71760a866922164 100644 (file)
@@ -1148,6 +1148,102 @@ int fpu_test_18(void)
        return trapit(0, test18);
 }
 
+#define RES_B  0x7ffaaaaaaaaaaaaa
+#define RES_C  0x000bbbbbbbbbbbbb
+
+struct selvals {
+       unsigned long val;
+       unsigned long result;
+} selvals[] = {
+       { 0x0000000000000000, RES_C },
+       { 0x8000000000000000, RES_C },
+       { 0x3ff0000000000000, RES_C },
+       { 0xbff0000000000000, RES_B },
+       { 0x7ff0000000000000, RES_C },
+       { 0xfff0000000000000, RES_B },
+       { 0x7ff8000000000000, RES_B },
+       { 0xfff8000000000000, RES_B },
+       { 0x0000000000000001, RES_C },
+       { 0x8000000000000001, RES_B },
+       { 0xffffffffffffffff, RES_B },
+};
+
+int test19(long arg)
+{
+       long i;
+       unsigned long result;
+       unsigned long frb = RES_B;
+       unsigned long frc = RES_C;
+       struct selvals *vp = selvals;
+
+       for (i = 0; i < sizeof(selvals) / sizeof(selvals[0]); ++i, ++vp) {
+               asm("lfd 6,0(%0); lfd 10,0(%1); lfd 22,0(%2); fsel 0,6,22,10; stfd 0,0(%3)"
+                   : : "b" (&vp->val), "b" (&frb), "b" (&frc), "b" (&result) : "memory");
+               if (result != vp->result) {
+                       print_hex(i, 2, " ");
+                       print_hex(result, 16, " ");
+                       return i + 1;
+               }
+       }
+       return 0;
+}
+
+int fpu_test_19(void)
+{
+       enable_fp();
+       return trapit(0, test19);
+}
+
+#define LT     8
+#define GT     4
+#define EQ     2
+#define UN     1
+
+struct cmpvals {
+       unsigned long vala, valb;
+       unsigned long result;
+} cmpvals[] = {
+       { 0x0000000000000000, 0x0000000000000000, EQ },
+       { 0x8000000000000000, 0x0000000000000000, EQ },
+       { 0x3ff0000000000000, 0x3ff0000000000000, EQ },
+       { 0x3ff0000000000001, 0x3ff0000000000000, GT },
+       { 0x3ff0000000000000, 0x3ff0000000000001, LT },
+       { 0xbff0000000000000, 0x3ff0000000000000, LT },
+       { 0x7ff0000000000000, 0x7ff0000000000000, EQ },
+       { 0xfff0000000000000, 0x7ff0000000000000, LT },
+       { 0x7ff8000000000000, 0x7ff0000000000000, UN },
+       { 0xfff8000000000000, 0x7ff0000000000000, UN },
+       { 0x0000000000000001, 0x0000000000000001, EQ },
+       { 0x8000000000000001, 0x7ff0000000000000, LT },
+       { 0xffffffffffffffff, 0x7ff0000000000000, UN },
+       { 0xffffffffffffffff, 0xffffffffffffffff, UN },
+};
+
+int test20(long arg)
+{
+       long i;
+       unsigned long cr;
+       struct cmpvals *vp = cmpvals;
+
+       for (i = 0; i < sizeof(cmpvals) / sizeof(cmpvals[0]); ++i, ++vp) {
+               asm("lfd 6,0(%1); lfd 10,8(%1); fcmpu 7,6,10; mfcr %0"
+                   : "=r" (cr) : "b" (&vp->vala) : "memory");
+               cr &= 0xf;
+               if (cr != vp->result) {
+                       print_hex(i, 2, " ");
+                       print_hex(cr, 1, " ");
+                       return i + 1;
+               }
+       }
+       return 0;
+}
+
+int fpu_test_20(void)
+{
+       enable_fp();
+       return trapit(0, test20);
+}
+
 int fail = 0;
 
 void do_test(int num, int (*test)(void))
@@ -1191,6 +1287,8 @@ int main(void)
        do_test(16, fpu_test_16);
        do_test(17, fpu_test_17);
        do_test(18, fpu_test_18);
+       do_test(19, fpu_test_19);
+       do_test(20, fpu_test_20);
 
        return fail;
 }
index 572aad0ef8df74ffd3de84f0d0435c5bf1706b02..0f9e03a588b27413f4d3522e6be6362f86d9204d 100755 (executable)
Binary files a/tests/test_fpu.bin and b/tests/test_fpu.bin differ
index a5c08eadcfbab4cc3dc5837d8e03d4275188d755..aea206ff47b2b2d60b7d18bbe5a43aea6750b1cc 100644 (file)
@@ -16,3 +16,5 @@ test 15:PASS
 test 16:PASS\r
 test 17:PASS\r
 test 18:PASS\r
+test 19:PASS\r
+test 20:PASS\r