Home | History | Annotate | Download | only in s390x
      1 #include <math.h>
      2 #include <stdio.h>
      3 
      4 /* Following macros adopted from dfp/math.h from libdfp */
      5 #define DEC_INFINITY    __builtin_infd64()
      6 #define DEC_NAN         (0.0DF * DEC_INFINITY)
      7 
      8 /* Following instructions are tested:
      9 test data class tests for
     10    _Decimal32  - TDCET
     11    _Decimal64  - TDCDT
     12    _decimal128 - TDCXT
     13 test data group tests for
     14    _Decimal32  - TDGET
     15    _Decimal64  - TDGDT
     16    _decimal128 - TDGXT
     17 */
     18 
     19 #define TEST_128(opcode, d, n)                                  \
     20   ({                                                            \
     21     int match;                                                  \
     22     _Decimal128 f = d;                                          \
     23     long long num = n;                                          \
     24     asm volatile(opcode ", %1,0(%2)\n"                          \
     25                  "ipm %0\n"                                     \
     26                  "srl %0,28\n"                                  \
     27                  : "=d" (match) : "f" (f), "a" (num) : "cc");   \
     28     match;                                                      \
     29  })
     30 
     31 #define TEST_64(opcode, d, n)                                   \
     32   ({                                                            \
     33     int match;                                                  \
     34     _Decimal64 f = d;                                           \
     35     long long num = n;                                          \
     36     asm volatile(opcode ", %1,0(%2)\n"                          \
     37                  "ipm %0\n"                                     \
     38                  "srl %0,28\n"                                  \
     39                  : "=d" (match) : "f" (f), "a" (num) : "cc");   \
     40     match;                                                      \
     41  })
     42 
     43 #define TEST_32(opcode, d, n)                                   \
     44   ({                                                            \
     45     int match;                                                  \
     46     _Decimal32 f = d;                                           \
     47     long long num = n;                                          \
     48     asm volatile(opcode ", %1,0(%2)\n"                          \
     49                  "ipm %0\n"                                     \
     50                  "srl %0,28\n"                                  \
     51                  : "=d" (match) : "f" (f), "a" (num) : "cc");   \
     52     match;                                                      \
     53  })
     54 
     55 int main()
     56 {
     57 	int i;
     58 
     59     /* The right most 12 bits 52:63 of the second operand are set and tested */
     60     for (i = 0; i < 12; i++) {
     61         /* DFP 128 bit - TDCXT */
     62         printf("%d", TEST_128(".insn rxe, 0xed0000000058", +0.0DF, 1UL<<i));
     63         printf("%d", TEST_128(".insn rxe, 0xed0000000058", -0.0DF, 1UL<<i));
     64         printf("%d", TEST_128(".insn rxe, 0xed0000000058", +2.2DF, 1UL<<i));
     65         printf("%d", TEST_128(".insn rxe, 0xed0000000058", -2.2DF, 1UL<<i));
     66         printf("%d", TEST_128(".insn rxe, 0xed0000000058",+DEC_INFINITY,1UL<<i));
     67         printf("%d", TEST_128(".insn rxe, 0xed0000000058",-DEC_INFINITY,1UL<<i));
     68         printf("%d", TEST_128(".insn rxe, 0xed0000000058", +DEC_NAN, 1UL<<i));
     69         printf("%d", TEST_128(".insn rxe, 0xed0000000058", -DEC_NAN, 1UL<<i));
     70 
     71         /* DFP 128 bit - TDGXT */
     72         printf("%d", TEST_128(".insn rxe, 0xed0000000059", +0.0DF, 1UL<<i));
     73         printf("%d", TEST_128(".insn rxe, 0xed0000000059", -0.0DF, 1UL<<i));
     74         printf("%d", TEST_128(".insn rxe, 0xed0000000059", +2.2DF, 1UL<<i));
     75         printf("%d", TEST_128(".insn rxe, 0xed0000000059", -2.2DF, 1UL<<i));
     76         printf("%d", TEST_128(".insn rxe, 0xed0000000059",+DEC_INFINITY,1UL<<i));
     77         printf("%d", TEST_128(".insn rxe, 0xed0000000059",-DEC_INFINITY,1UL<<i));
     78         printf("%d", TEST_128(".insn rxe, 0xed0000000059", +DEC_NAN, 1UL<<i));
     79         printf("%d", TEST_128(".insn rxe, 0xed0000000059", -DEC_NAN, 1UL<<i));
     80 
     81         /* DFP 64 bit - TDCDT */
     82         printf("%d", TEST_64(".insn rxe, 0xed0000000054", +0.0DF, 1UL<<i));
     83         printf("%d", TEST_64(".insn rxe, 0xed0000000054", -0.0DF, 1UL<<i));
     84         printf("%d", TEST_64(".insn rxe, 0xed0000000054", +2.2DF, 1UL<<i));
     85         printf("%d", TEST_64(".insn rxe, 0xed0000000054", -2.2DF, 1UL<<i));
     86         printf("%d", TEST_64(".insn rxe, 0xed0000000054",+DEC_INFINITY,1UL<<i));
     87         printf("%d", TEST_64(".insn rxe, 0xed0000000054",-DEC_INFINITY,1UL<<i));
     88         printf("%d", TEST_64(".insn rxe, 0xed0000000054", +DEC_NAN, 1UL<<i));
     89         printf("%d", TEST_64(".insn rxe, 0xed0000000054", -DEC_NAN, 1UL<<i));
     90 
     91         /* DFP 64 bit - TDGDT */
     92         printf("%d", TEST_64(".insn rxe, 0xed0000000055", +0.0DF, 1UL<<i));
     93         printf("%d", TEST_64(".insn rxe, 0xed0000000055", -0.0DF, 1UL<<i));
     94         printf("%d", TEST_64(".insn rxe, 0xed0000000055", +2.2DF, 1UL<<i));
     95         printf("%d", TEST_64(".insn rxe, 0xed0000000055", -2.2DF, 1UL<<i));
     96         printf("%d", TEST_64(".insn rxe, 0xed0000000055",+DEC_INFINITY,1UL<<i));
     97         printf("%d", TEST_64(".insn rxe, 0xed0000000055",-DEC_INFINITY,1UL<<i));
     98         printf("%d", TEST_64(".insn rxe, 0xed0000000055", +DEC_NAN, 1UL<<i));
     99         printf("%d", TEST_64(".insn rxe, 0xed0000000055", -DEC_NAN, 1UL<<i));
    100 
    101         /* DFP 32 bit - TDCET */
    102         printf("%d", TEST_32(".insn rxe, 0xed0000000050", +0.0DF, 1UL<<i));
    103         printf("%d", TEST_32(".insn rxe, 0xed0000000050", -0.0DF, 1UL<<i));
    104         printf("%d", TEST_32(".insn rxe, 0xed0000000050", +2.2DF, 1UL<<i));
    105         printf("%d", TEST_32(".insn rxe, 0xed0000000050", -2.2DF, 1UL<<i));
    106         printf("%d", TEST_32(".insn rxe, 0xed0000000050",+DEC_INFINITY,1UL<<i));
    107         printf("%d", TEST_32(".insn rxe, 0xed0000000050",-DEC_INFINITY,1UL<<i));
    108         printf("%d", TEST_32(".insn rxe, 0xed0000000050", +DEC_NAN, 1UL<<i));
    109         printf("%d", TEST_32(".insn rxe, 0xed0000000050", -DEC_NAN, 1UL<<i));
    110 
    111         /* DFP 32 bit - TDGET */
    112         printf("%d", TEST_32(".insn rxe, 0xed0000000051", +0.0DF, 1UL<<i));
    113         printf("%d", TEST_32(".insn rxe, 0xed0000000051", -0.0DF, 1UL<<i));
    114         printf("%d", TEST_32(".insn rxe, 0xed0000000051", +2.2DF, 1UL<<i));
    115         printf("%d", TEST_32(".insn rxe, 0xed0000000051", -2.2DF, 1UL<<i));
    116         printf("%d", TEST_32(".insn rxe, 0xed0000000051",+DEC_INFINITY,1UL<<i));
    117         printf("%d", TEST_32(".insn rxe, 0xed0000000051",-DEC_INFINITY,1UL<<i));
    118         printf("%d", TEST_32(".insn rxe, 0xed0000000051", +DEC_NAN, 1UL<<i));
    119         printf("%d", TEST_32(".insn rxe, 0xed0000000051", -DEC_NAN, 1UL<<i));
    120 
    121         printf("\n");
    122 
    123 	}
    124 	return 0;
    125 }
    126