]> sourceware.org Git - valgrind.git/commitdiff
Bug 472875 - s390x regtest: Rework dfp-1
authorAndreas Arnez <arnez@linux.ibm.com>
Thu, 7 Sep 2023 14:43:24 +0000 (16:43 +0200)
committerAndreas Arnez <arnez@linux.ibm.com>
Thu, 7 Sep 2023 14:43:24 +0000 (16:43 +0200)
The dfp-1 test case has two main issues:

* It doesn't initialize the condition code before executing the DFP
  instructions for "multiply" and "divide", but asserts a certain value
  afterwards.  (See Bug 472875.)

* It doesn't compile with Clang.  (See Bug 465782.)

Fix these with a rework.  The first issue can be fixed by initializing the
condition code before executing the DFP instructions.  The second issue
requires avoiding any `_Decimal*' types, since they are not supported by
Clang.

NEWS
none/tests/s390x/dfp-1.c
none/tests/s390x/dfp_utils.h

diff --git a/NEWS b/NEWS
index 7c5247f0718572c6c437f262a15490b712b5df84..4459ddd7cf41c11048fae41ea5ad9769c1f76ff3 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -66,6 +66,7 @@ are not entered into bugzilla tend to get forgotten about or ignored.
 471311  gdb --multi mode stdout redirecting to stderr
 471807  Add support for lazy reading and downloading of DWARF debuginfo
 472219  Syscall param ppoll(ufds.events) points to uninitialised byte(s)
+472875  none/tests/s390x/dfp-1 failure 
 472963  Broken regular expression in configure.ac
 473604  Fix bug472219.c compile failure with Clang 16
 473677  make check compile failure with Clang 16 based on GCC 13.x
index b9be89963fd148d56256a83a51c90f138cf568f6..09f13353594f5888a2a43260e2400ee9c331cfa1 100644 (file)
-#include <stdio.h>
-#include "opcodes.h"
 #include "dfp_utils.h"
+#include <stdio.h>
 
-volatile _Decimal64 d64_1, d64_2, result_64;
-volatile _Decimal128 d128_1, d128_2, result_128;
-
-#define DFP_BINOP(insn, op1, op2, type, round, cc)                      \
-  ({                                                                    \
-    register type d1 asm("f0") =  op1;                                  \
-    register type d2 asm("f1") =  op2;                                  \
-    /* d1 = d1 (op) d2    */                                            \
-    asm volatile(insn(1,round,0,0)                                      \
-                 "ipm %1\n\t"                                           \
-                 "srl %1,28\n\t"                                        \
-                 :"+f" (d1), "=d" (cc)                                  \
-                 :"f"(d2)                                               \
-                 :"cc"                                                  \
-                 );                                                     \
-    d1;                                                                 \
-  })
+#define DFP_BINOP(type, opc, binop, op1, op2, round)                           \
+   ({                                                                          \
+      int        cc;                                                           \
+      reg_##type result;                                                       \
+      asm("cr 0,0\n\t" /* clear CC */                                          \
+          ".insn rrf," #opc "0000,%[res],%[r1],%[r2],%[mode]\n\t"              \
+          "ipm %[cc]\n\t"                                                      \
+          "srl %[cc],28\n\t"                                                   \
+          : [res] "=f"(result), [cc] "=d"(cc)                                  \
+          : [r1] "f"(op1.f), [r2] "f"(op2.f), [mode] "i"(round)                \
+          : "cc");                                                             \
+      DFP_VAL_PRINT(op1.f, reg_##type);                                        \
+      printf(" " binop " ");                                                   \
+      DFP_VAL_PRINT(op2.f, reg_##type);                                        \
+      printf(" = ");                                                           \
+      DFP_VAL_PRINT(result, reg_##type);                                       \
+      printf(" cc = %d\n", cc);                                                \
+   })
 
-int main() {
-  int cc;
+static const pun_d64 dd_3_14  = {0x2230000000000194}; /* 3.14DD */
+static const pun_d64 dd_m3_14 = {0xa230000000000194}; /* -3.14DD */
+static const pun_d64 dd_0_005 = {0x222c000000000005}; /* 0.005DD */
+static const pun_d64 dd_7     = {0x2238000000000007}; /* 7.DD */
+static const pun_d64 dd_0     = {0x2238000000000000}; /* 0.DD */
+static const pun_d64 dd_22    = {0x2238000000000022}; /* 22.DD */
+static const pun_d64 dd_m22   = {0xa238000000000022}; /* -22.DD */
 
-  printf("Decimal floating point arithmetic\n");
+static const pun_d128 dl_3_14  = {{0x2207800000000000, 0x0000000000000194}};
+static const pun_d128 dl_m3_14 = {{0xa207800000000000, 0x0000000000000194}};
+static const pun_d128 dl_0_005 = {{0x2207400000000000, 0x0000000000000005}};
+static const pun_d128 dl_7     = {{0x2208000000000000, 0x0000000000000007}};
+static const pun_d128 dl_0     = {{0x2208000000000000, 0x0000000000000000}};
+static const pun_d128 dl_22    = {{0x2208000000000000, 0x0000000000000022}};
+static const pun_d128 dl_m22   = {{0xa208000000000000, 0x0000000000000022}};
 
-    /* 64-bit ADD */
-  printf("64-bit ADD\n");
-  /* case 1: cc = 2 */
-  d64_1 = 3.14DD;
-  d64_2 = 0.005DD;
-  result_64 = DFP_BINOP(ADTRA, d64_1, d64_2, _Decimal64, 1, cc);
-  DFP_BINOP_PRINT(d64_1, d64_2, result_64, _Decimal64, "+", cc);
-  /* case 2: cc = 1 */
-  d64_1 = -3.14DD;
-  d64_2 = 0.005DD;
-  result_64 = DFP_BINOP(ADTRA, d64_1, d64_2, _Decimal64, 1, cc);
-  DFP_BINOP_PRINT(d64_1, d64_2, result_64, _Decimal64, "+", cc);
-  /* case 2: cc = 0 */
-  d64_1 = 3.14DD;
-  d64_2 = -d64_1;
-  result_64 = DFP_BINOP(ADTRA, d64_1, d64_2, _Decimal64, 3, cc);
-  DFP_BINOP_PRINT(d64_1, d64_2, result_64, _Decimal64, "+", cc);
+int main()
+{
+   printf("Decimal floating point arithmetic\n");
 
+   printf("64-bit ADD\n");
+   DFP_BINOP(d64, 0xb3d2, "+", dd_3_14, dd_0_005, 1);  /* cc = 2 */
+   DFP_BINOP(d64, 0xb3d2, "+", dd_m3_14, dd_0_005, 1); /* cc = 1 */
+   DFP_BINOP(d64, 0xb3d2, "+", dd_3_14, dd_m3_14, 3);  /* cc = 0 */
 
-    /* 64-bit SUBTRACT */
-  printf("64-bit SUBTRACT\n");
-  /* case 1: cc = 2 */
-  d64_1 = 3.14DD;
-  d64_2 = 0.005DD;
-  result_64 = DFP_BINOP(SDTRA, d64_1, d64_2, _Decimal64, 4, cc);
-  DFP_BINOP_PRINT(d64_1, d64_2, result_64, _Decimal64, "-", cc);
-  /* case 2: cc = 1 */
-  d64_1 = -3.14DD;
-  d64_2 = 0.005DD;
-  result_64 = DFP_BINOP(SDTRA, d64_1, d64_2, _Decimal64, 5, cc);
-  DFP_BINOP_PRINT(d64_1, d64_2, result_64, _Decimal64, "-", cc);
-  /* case 3: cc = 0 */
-  d64_1 = 3.14DD;
-  d64_2 = d64_1;
-  result_64 = DFP_BINOP(SDTRA, d64_1, d64_2, _Decimal64, 5, cc);
-  DFP_BINOP_PRINT(d64_1, d64_2, result_64, _Decimal64, "-", cc);
+   printf("64-bit SUBTRACT\n");
+   DFP_BINOP(d64, 0xb3d3, "-", dd_3_14, dd_0_005, 1);  /* cc = 2 */
+   DFP_BINOP(d64, 0xb3d3, "-", dd_m3_14, dd_0_005, 1); /* cc = 1 */
+   DFP_BINOP(d64, 0xb3d3, "-", dd_3_14, dd_3_14, 3);   /* cc = 0 */
 
-    /* 64-bit MULTIPLY */
-  printf("64-bit MULTIPLY\n");
-  /* case 1: cc = 2 */
-  d64_1 = 3.14DD;
-  d64_2 = 7.DD;
-  result_64 = DFP_BINOP(MDTRA, d64_1, d64_2, _Decimal64, 6, cc);
-  DFP_BINOP_PRINT(d64_1, d64_2, result_64, _Decimal64, "*", cc);
-  /* case 2: cc = 1 */
-  d64_1 = -3.14DD;
-  d64_2 = 7.DD;
-  result_64 = DFP_BINOP(MDTRA, d64_1, d64_2, _Decimal64, 7, cc);
-  DFP_BINOP_PRINT(d64_1, d64_2, result_64, _Decimal64, "*", cc);
-  /* case 3: cc = 0 */
-  d64_1 = -3.14DD;
-  d64_2 = 0.DD;
-  result_64 = DFP_BINOP(MDTRA, d64_1, d64_2, _Decimal64, 7, cc);
-  DFP_BINOP_PRINT(d64_1, d64_2, result_64, _Decimal64, "*", cc);
+   printf("64-bit MULTIPLY\n");
+   DFP_BINOP(d64, 0xb3d0, "*", dd_3_14, dd_7, 6);
+   DFP_BINOP(d64, 0xb3d0, "*", dd_m3_14, dd_7, 7);
+   DFP_BINOP(d64, 0xb3d0, "*", dd_m3_14, dd_0, 7);
 
-    /* 64-bit DIVIDE */
-  printf("64-bit DIVIDE\n");
-  /* case 1: cc = 2 */
-  d64_1 = 22.DD;
-  d64_2 = 7.DD;
-  result_64 = DFP_BINOP(DDTRA, d64_1, d64_2, _Decimal64, d, cc);
-  DFP_BINOP_PRINT(d64_1, d64_2, result_64, _Decimal64, "/", cc);
-  /* case 2: cc = 1 */
-  d64_1 = -22.DD;
-  d64_2 = 7.DD;
-  result_64 = DFP_BINOP(DDTRA, d64_1, d64_2, _Decimal64, e, cc);
-  DFP_BINOP_PRINT(d64_1, d64_2, result_64, _Decimal64, "/", cc);
-  /* case 3: cc = 0 */
-  d64_1 = 0.DD;
-  d64_2 = 7.DD;
-  result_64 = DFP_BINOP(DDTRA, d64_1, d64_2, _Decimal64, e, cc);
-  DFP_BINOP_PRINT(d64_1, d64_2, result_64, _Decimal64, "/", cc);
+   printf("64-bit DIVIDE\n");
+   DFP_BINOP(d64, 0xb3d1, "/", dd_22, dd_7, 13);
+   DFP_BINOP(d64, 0xb3d1, "/", dd_m22, dd_7, 14);
+   DFP_BINOP(d64, 0xb3d1, "/", dd_0, dd_7, 14);
 
-    /* 128-bit ADD */
-  printf("128-bit ADD\n");
-  /* case 1: cc = 2 */
-  d128_1 = 3.14DL;
-  d128_2 = 0.005DL;
-  result_128 = DFP_BINOP(AXTRA, d128_1, d128_2, _Decimal128, 1, cc);
-  DFP_BINOP_PRINT(d128_1, d128_2, result_128, _Decimal128, "+", cc);
-  /* case 2: cc = 1 */
-  d128_1 = -3.14DL;
-  d128_2 = 0.005DL;
-  result_128 = DFP_BINOP(AXTRA, d128_1, d128_2, _Decimal128, 1, cc);
-  DFP_BINOP_PRINT(d128_1, d128_2, result_128, _Decimal128, "+", cc);
-  /* case 3: cc = 0 */
-  d128_1 = 3.14DL;
-  d128_2 = -d128_1;
-  result_128 = DFP_BINOP(AXTRA, d128_1, d128_2, _Decimal128, 3, cc);
-  DFP_BINOP_PRINT(d128_1, d128_2, result_128, _Decimal128, "+", cc);
+   printf("128-bit ADD\n");
+   DFP_BINOP(d128, 0xb3da, "+", dl_3_14, dl_0_005, 1);  /* cc = 2 */
+   DFP_BINOP(d128, 0xb3da, "+", dl_m3_14, dl_0_005, 1); /* cc = 1 */
+   DFP_BINOP(d128, 0xb3da, "+", dl_3_14, dl_m3_14, 1);  /* cc = 0 */
 
-    /* 128-bit SUBTRACT */
-  printf("128-bit SUBTRACT\n");
-  /* case 1: cc = 2 */
-  d128_1 = 3.14DL;
-  d128_2 = 0.005DL;
-  result_128 = DFP_BINOP(SXTRA, d128_1, d128_2, _Decimal128, 4, cc);
-  DFP_BINOP_PRINT(d128_1, d128_2, result_128, _Decimal128, "-", cc);
-  /* case 2: cc = 1 */
-  d128_1 = -3.14DL;
-  d128_2 = 0.005DL;
-  result_128 = DFP_BINOP(SXTRA, d128_1, d128_2, _Decimal128, 5, cc);
-  DFP_BINOP_PRINT(d128_1, d128_2, result_128, _Decimal128, "-", cc);
-  /* case 3: cc = 0 */
-  d128_1 = 3.14DL;
-  d128_2 = d128_1;
-  result_128 = DFP_BINOP(SXTRA, d128_1, d128_2, _Decimal128, 5, cc);
-  DFP_BINOP_PRINT(d128_1, d128_2, result_128, _Decimal128, "-", cc);
+   printf("128-bit SUBTRACT\n");
+   DFP_BINOP(d128, 0xb3db, "-", dl_3_14, dl_0_005, 1);  /* cc = 2 */
+   DFP_BINOP(d128, 0xb3db, "-", dl_m3_14, dl_0_005, 1); /* cc = 1 */
+   DFP_BINOP(d128, 0xb3db, "-", dl_3_14, dl_3_14, 1);   /* cc = 0 */
 
-    /* 128-bit MULTIPLY */
-  printf("128-bit MULTIPLY\n");
-  /* case 1: cc = 2 */
-  d128_1 = 3.14DL;
-  d128_2 = 7.DL;
-  result_128 = DFP_BINOP(MXTRA, d128_1, d128_2, _Decimal128, 6, cc);
-  DFP_BINOP_PRINT(d128_1, d128_2, result_128, _Decimal128, "*", cc);
-  /* case 2: cc = 1 */
-  d128_1 = -3.14DL;
-  d128_2 = 7.DL;
-  result_128 = DFP_BINOP(MXTRA, d128_1, d128_2, _Decimal128, 7, cc);
-  DFP_BINOP_PRINT(d128_1, d128_2, result_128, _Decimal128, "*", cc);
-  /* case 3: cc = 0 */
-  d128_1 = 3.14DL;
-  d128_2 = 0.DL;
-  result_128 = DFP_BINOP(MXTRA, d128_1, d128_2, _Decimal128, 7, cc);
-  DFP_BINOP_PRINT(d128_1, d128_2, result_128, _Decimal128, "*", cc);
+   printf("128-bit MULTIPLY\n");
+   DFP_BINOP(d128, 0xb3d8, "*", dl_3_14, dl_7, 6);
+   DFP_BINOP(d128, 0xb3d8, "*", dl_m3_14, dl_7, 7);
+   DFP_BINOP(d128, 0xb3d8, "*", dl_3_14, dl_0, 7);
 
-    /* 128-bit DIVIDE */
-  printf("128-bit DIVIDE\n");
-  /* case 1: cc = 2 */
-  d128_1 = 22.DL;
-  d128_2 = 7.DL;
-  result_128 = DFP_BINOP(DXTRA, d128_1, d128_2, _Decimal128, d, cc);
-  DFP_BINOP_PRINT(d128_1, d128_2, result_128, _Decimal128, "/", cc);
-  /* case 2: cc = 1 */
-  d128_1 = -22.DL;
-  d128_2 = 7.DL;
-  result_128 = DFP_BINOP(DXTRA, d128_1, d128_2, _Decimal128, e, cc);
-  DFP_BINOP_PRINT(d128_1, d128_2, result_128, _Decimal128, "/", cc);
-  /* case 3: cc = 0 */
-  d128_1 = 0.DL;
-  d128_2 = 7.DL;
-  result_128 = DFP_BINOP(DXTRA, d128_1, d128_2, _Decimal128, e, cc);
-  DFP_BINOP_PRINT(d128_1, d128_2, result_128, _Decimal128, "/", cc);
+   printf("128-bit DIVIDE\n");
+   DFP_BINOP(d128, 0xb3d9, "/", dl_22, dl_7, 13);
+   DFP_BINOP(d128, 0xb3d9, "/", dl_m22, dl_7, 14);
+   DFP_BINOP(d128, 0xb3d9, "/", dl_0, dl_7, 14);
 
-  return 0;
+   return 0;
 }
index ec2bf1c75592223bfde037ebc7f3430ef9c66220..b12fef7eb7f7ca69f8516c9dc684608f6bfe7c4d 100644 (file)
@@ -4,6 +4,13 @@
 #include <stddef.h>      /* size_t */
 #include <stdio.h>       /* printf */
 
+typedef float reg_d32;
+typedef double reg_d64;
+typedef long double reg_d128;
+typedef union { unsigned int i; reg_d32 f; } pun_d32;
+typedef union { unsigned long i; reg_d64 f; } pun_d64;
+typedef union { unsigned long i[2]; reg_d128 f; } pun_d128;
+
 #define DFP_VAL_PRINT(op, type)                                         \
   {                                                                     \
     enum { n = sizeof(type) };                                          \
        printf("%02x", u.i[k]);                                          \
   }
 
-#define DFP_BINOP_PRINT(op1, op2, result, type, op, cc)                 \
-  {                                                                     \
-    DFP_VAL_PRINT(op1, type);                                           \
-    printf(" "op" ");                                                   \
-    DFP_VAL_PRINT(op2, type);                                           \
-    printf(" = ");                                                      \
-    DFP_VAL_PRINT(result, type);                                        \
-    printf(" cc = %d\n", cc);                                           \
-  }
-
 #endif /* DFP_UTILS_H */
This page took 0.043465 seconds and 5 git commands to generate.