]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
s390: Add testcases for CDTR, CXTR, LDETR. LXDTR, LEDTR, LDXTR.
authorFlorian Krohm <florian@eich-krohm.de>
Sun, 23 Dec 2012 16:17:18 +0000 (16:17 +0000)
committerFlorian Krohm <florian@eich-krohm.de>
Sun, 23 Dec 2012 16:17:18 +0000 (16:17 +0000)
This is part of fixing BZ 307113.
Patch by Maran Pakkirisamy (maranp@linux.vnet.ibm.com).

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@13196

none/tests/s390x/Makefile.am
none/tests/s390x/dfp-3.c [new file with mode: 0644]
none/tests/s390x/dfp-3.stderr.exp [new file with mode: 0644]
none/tests/s390x/dfp-3.stdout.exp [new file with mode: 0644]
none/tests/s390x/dfp-3.vgtest [new file with mode: 0644]
none/tests/s390x/dfp-4.c [new file with mode: 0644]
none/tests/s390x/dfp-4.stderr.exp [new file with mode: 0644]
none/tests/s390x/dfp-4.stdout.exp [new file with mode: 0644]
none/tests/s390x/dfp-4.vgtest [new file with mode: 0644]
none/tests/s390x/dfp_utils.h

index 7d6d3789ec20e674568b06cce0441f68d98278af..9577b3fcb047f6d99ae99390de09311035b1546f 100644 (file)
@@ -19,7 +19,7 @@ INSN_TESTS = clc clcle cvb cvd icm lpr tcxb lam_stam xc mvst add sub mul \
             spechelper-icm-1  spechelper-icm-2 spechelper-tmll \
             spechelper-tm laa
 if BUILD_DFP_TESTS
-  INSN_TESTS += dfp-1 dfp-2
+  INSN_TESTS += dfp-1 dfp-2 dfp-3 dfp-4
 endif
 
 check_PROGRAMS = $(INSN_TESTS) \
@@ -36,7 +36,9 @@ EXTRA_DIST = \
        test.h opcodes.h add.h  and.h  div.h  insert.h \
        mul.h  or.h  sub.h  xor.h table.h svc.h rounding.h \
        dfp-1.stderr.exp dfp-1.stdout.exp dfp-1.vgtest \
-       dfp-2.stderr.exp dfp-2.stdout.exp dfp-2.vgtest
+       dfp-2.stderr.exp dfp-2.stdout.exp dfp-2.vgtest \
+       dfp-3.stderr.exp dfp-3.stdout.exp dfp-3.vgtest \
+       dfp-4.stderr.exp dfp-4.stdout.exp dfp-4.vgtest
 
 AM_CFLAGS    += @FLAG_M64@
 AM_CXXFLAGS  += @FLAG_M64@
diff --git a/none/tests/s390x/dfp-3.c b/none/tests/s390x/dfp-3.c
new file mode 100644 (file)
index 0000000..f1c9969
--- /dev/null
@@ -0,0 +1,103 @@
+#include <stdio.h>
+#include <sys/types.h>
+#include "opcodes.h"
+#include "dfp_utils.h"
+
+/* Following macros adopted from dfp/math.h from libdfp */
+#define DEC_INFINITY    __builtin_infd64()
+#define DEC_NAN         (0.0DF * DEC_INFINITY)
+
+/* Test DFP value and exponent comparison for  64/128-bit. */
+
+#define CMP_DFP(insn, op1, op2, type, cc)                               \
+  ({                                                                    \
+  register type d1 asm("f0") =  op1;                                    \
+  register type d2 asm("f1") =  op2;                                    \
+  /* cc = d1 (cmp) d2    */                                             \
+  asm volatile(insn(0,1)                                                \
+               "ipm %0\n\t"                                             \
+               "srl %0,28\n\t"                                          \
+               :"=d" (cc)                                               \
+               :"f"(d1), "f"(d2)                                        \
+               );                                                       \
+  cc;                                                                   \
+})
+
+
+#define COMPARE(insn, v1, v2, type)                                     \
+  {                                                                     \
+    int cc;                                                             \
+    CMP_DFP(insn, v1, v2, type, cc);                                    \
+    DFP_VAL_PRINT(v1, type);                                            \
+    switch (cc) {                                                       \
+    case 0:                                                             \
+      printf(" == ");                                                   \
+      break;                                                            \
+    case 1:                                                             \
+      printf(" < ");                                                    \
+      break;                                                            \
+    case 2:                                                             \
+      printf(" > ");                                                    \
+      break;                                                            \
+    case 3:                                                             \
+      printf(" <> ");                                                    \
+      break;                                                            \
+    }                                                                   \
+    DFP_VAL_PRINT(v2, type);                                            \
+    printf(" (cc == %d)\n", cc);                                        \
+}
+
+int main(void)
+{
+   _Decimal64 d64_1, d64_2;
+   _Decimal128 d128_1, d128_2;
+
+   d64_1 = 5.000005DD;
+   d64_2 = 50000000000000000.000005DD;
+
+   // compare 8 bytes DFP value
+   printf("cdtr:\n");
+   COMPARE(CDTR, d64_1, d64_1, _Decimal64);
+   COMPARE(CDTR, d64_1, d64_2, _Decimal64);
+   COMPARE(CDTR, d64_2, d64_1, _Decimal64);
+
+   /* compare NAN and INF operands */
+   d64_1 = DEC_INFINITY;
+   d64_2 = DEC_NAN;
+   COMPARE(CDTR, d64_1, d64_2, _Decimal64);
+   COMPARE(CDTR, d64_1, d64_1, _Decimal64);
+   COMPARE(CDTR, d64_2, d64_2, _Decimal64);
+
+#if 0  //fixs390: enable it when Iop_ExtractD64 is available
+   // compare exponents of 8 bytes DFP value
+   printf("cedtr:\n");
+   COMPARE(CEDTR, d64_1, d64_1, _Decimal64);
+   COMPARE(CEDTR, d64_1, d64_2, _Decimal64);
+   COMPARE(CEDTR, d64_2, d64_1, _Decimal64);
+#endif
+   d128_1 = 5.00005DL;
+   d128_2 = 5000000000000000.5DL;
+
+   // compare 16 bytes DFP value
+   printf("cxtr:\n");
+   COMPARE(CXTR, d128_1, d128_1, _Decimal128);
+   COMPARE(CXTR, d128_1, d128_2, _Decimal128);
+   COMPARE(CXTR, d128_2, d128_1, _Decimal128);
+
+   /* compare NAN and INF operands */
+   d128_1 = DEC_INFINITY;
+   d128_2 = DEC_NAN;
+   COMPARE(CXTR, d128_1, d128_2, _Decimal128);
+   COMPARE(CXTR, d128_1, d128_1, _Decimal128);
+   COMPARE(CXTR, d128_2, d128_2, _Decimal128);
+
+#if 0  //fixs390: enable it when Iop_ExtractD128 is available
+   // compare exponents of 16 bytes DFP value
+   printf("cextr:\n");
+   COMPARE(CEXTR, d128_1, d128_1, _Decimal128);
+   COMPARE(CEXTR, d128_1, d128_2, _Decimal128);
+   COMPARE(CEXTR, d128_2, d128_1, _Decimal128);
+#endif
+
+   return 0;
+}
diff --git a/none/tests/s390x/dfp-3.stderr.exp b/none/tests/s390x/dfp-3.stderr.exp
new file mode 100644 (file)
index 0000000..139597f
--- /dev/null
@@ -0,0 +1,2 @@
+
+
diff --git a/none/tests/s390x/dfp-3.stdout.exp b/none/tests/s390x/dfp-3.stdout.exp
new file mode 100644 (file)
index 0000000..066ecc8
--- /dev/null
@@ -0,0 +1,14 @@
+cdtr:
+2220000000500005 == 2220000000500005 (cc == 0)
+2220000000500005 < 363c000000000000 (cc == 1)
+363c000000000000 > 2220000000500005 (cc == 2)
+7800000000000000 <> 7c00000000000000 (cc == 3)
+7800000000000000 == 7800000000000000 (cc == 0)
+7c00000000000000 <> 7c00000000000000 (cc == 3)
+cxtr:
+2206c00000000000000a0005 == 2206c00000000000000a0005 (cc == 0)
+2206c00000000000000a0005 < 2207c00000000000140000000000005 (cc == 1)
+2207c00000000000140000000000005 > 2206c00000000000000a0005 (cc == 2)
+780000000000000000000000 <> 7c0000000000000000000000 (cc == 3)
+780000000000000000000000 == 780000000000000000000000 (cc == 0)
+7c0000000000000000000000 <> 7c0000000000000000000000 (cc == 3)
diff --git a/none/tests/s390x/dfp-3.vgtest b/none/tests/s390x/dfp-3.vgtest
new file mode 100644 (file)
index 0000000..e2b5673
--- /dev/null
@@ -0,0 +1,2 @@
+prog: dfp-3
+prereq: test -e dfp-3 && ../../../tests/s390x_features s390x-dfp
diff --git a/none/tests/s390x/dfp-4.c b/none/tests/s390x/dfp-4.c
new file mode 100644 (file)
index 0000000..eaaea41
--- /dev/null
@@ -0,0 +1,43 @@
+#include <stdio.h>
+#include <sys/types.h>
+#include "dfp_utils.h"
+
+volatile _Decimal32 d32_1, d32_2;
+volatile _Decimal64 d64_1, d64_2;
+volatile _Decimal128 d128_1, d128_2;
+
+int main(void)
+{
+   d64_1 = 5.000005DD;
+   d64_2 = 60000.4DD;
+   d32_1 = 3.000002DF;
+   d32_2 = 500000.000005DF;
+   d128_1 = 100000000.000028DL;
+
+   d64_1 = (_Decimal64) d32_1; //Exercise LDETR (load lengthened)
+   printf("D32 -> D64  : ");
+   DFP_VAL_PRINT(d32_1, _Decimal32);
+   printf(" -> ");
+   DFP_VAL_PRINT(d64_1, _Decimal64);
+
+   d128_2 = (_Decimal128) d64_2; //Exercise LXDTR (load lengthened)
+   printf("\nD64 -> D128 : ");
+   DFP_VAL_PRINT(d64_2, _Decimal64);
+   printf(" -> ");
+   DFP_VAL_PRINT(d128_2, _Decimal128);
+
+   d32_2 = (_Decimal32) d64_2; //Exercise LEDTR (load rounded)
+   printf("\nD64 -> D32  : ");
+   DFP_VAL_PRINT(d64_2, _Decimal64);
+   printf(" -> ");
+   DFP_VAL_PRINT(d32_2, _Decimal32);
+
+   d64_2 = (_Decimal64) d128_1; //Exercise LDXTR (load rounded)
+   printf("\nD128 -> D64 : ");
+   DFP_VAL_PRINT(d128_1, _Decimal128);
+   printf(" -> ");
+   DFP_VAL_PRINT(d64_2, _Decimal64);
+   printf("\n");
+
+   return 0;
+}
diff --git a/none/tests/s390x/dfp-4.stderr.exp b/none/tests/s390x/dfp-4.stderr.exp
new file mode 100644 (file)
index 0000000..139597f
--- /dev/null
@@ -0,0 +1,2 @@
+
+
diff --git a/none/tests/s390x/dfp-4.stdout.exp b/none/tests/s390x/dfp-4.stdout.exp
new file mode 100644 (file)
index 0000000..9a2319c
--- /dev/null
@@ -0,0 +1,4 @@
+D32 -> D64  : 2df00002 -> 2220000000300002
+D64 -> D128 : 22340000000c0004 -> 2207c00000000000000c0004
+D64 -> D32  : 22340000000c0004 -> 224c0004
+D128 -> D64 : 2206800000000000800000000028 -> 2220800000000028
diff --git a/none/tests/s390x/dfp-4.vgtest b/none/tests/s390x/dfp-4.vgtest
new file mode 100644 (file)
index 0000000..0ffc1a6
--- /dev/null
@@ -0,0 +1,2 @@
+prog: dfp-4
+prereq: test -e dfp-4 && ../../../tests/s390x_features s390x-dfp
index eb70d63b50ed076fae3a3c15cdd1c4bd5e28a8a2..031f29eb4bb487bafcfac3968bbe3bf12d88c1d6 100644 (file)
@@ -1,13 +1,18 @@
 #ifndef DFP_UTILS_H
 #define DFP_UTILS_H
 
+#include <stddef.h>      /* size_t */
+#include <stdio.h>       /* printf */
+
 /* convinience macros to print DFP values to avoid linking libdfp to
    DFP testcases */
 
 #define DFP_VAL_PRINT(op, type)                                         \
   {                                                                     \
     size_t n = sizeof(type);                                            \
-    if (n == 8)                                                         \
+    if (n == 4)                                                         \
+      printf("%x", *((unsigned int *) &op));                            \
+    else if (n == 8)                                                    \
       printf("%lx", *((unsigned long *) &op));                          \
     else                                                                \
       printf("%lx%08lx", *((unsigned long *) &op),                      \