| 1 |
/* { dg-do run } */ |
| 2 |
/* { dg-require-effective-target dfp_hw } */ |
| 3 |
/* { dg-require-effective-target has_arch_pwr6 } */ |
| 4 |
/* { dg-options "-mhard-float -O2 -save-temps" } */ |
| 5 |
|
| 6 |
/* Test the decimal floating point quantize built-ins. */ |
| 7 |
|
| 8 |
#define DEBUG 0 |
| 9 |
|
| 10 |
#ifdef DEBUG |
| 11 |
#include <stdio.h> |
| 12 |
#endif |
| 13 |
#include <float.h> |
| 14 |
|
| 15 |
void abort (void); |
| 16 |
|
| 17 |
int main() |
| 18 |
{ |
| 19 |
#define IMM2 2 |
| 20 |
#define IMM3 3 |
| 21 |
#define IMM4 4 |
| 22 |
|
| 23 |
_Decimal64 srcA_dfp64, srcB_dfp64; |
| 24 |
_Decimal64 result_dfp64; |
| 25 |
_Decimal64 expected_result_dfp64; |
| 26 |
_Decimal128 srcA_dfp128, srcB_dfp128; |
| 27 |
_Decimal128 result_dfp128; |
| 28 |
_Decimal128 expected_result_dfp128; |
| 29 |
|
| 30 |
/* Third argument of quantize built-ins is the rounding mode value (RMC). |
| 31 |
|
| 32 |
RMC Rounding Mode |
| 33 |
00 Round to nearest, ties to even |
| 34 |
01 Round toward 0 |
| 35 |
10 Round to nearest, ties toward 0 |
| 36 |
11 Round according to DRN */ |
| 37 |
|
| 38 |
|
| 39 |
/* Tests for quantize with 64-bit DFP variable. */ |
| 40 |
srcA_dfp64 = 100.0df; |
| 41 |
srcB_dfp64 = 300.456789df; |
| 42 |
expected_result_dfp64 = 300.5df; |
| 43 |
|
| 44 |
result_dfp64 = __builtin_dfp_quantize (srcA_dfp64, srcB_dfp64, 0x0); |
| 45 |
|
| 46 |
if (result_dfp64 != expected_result_dfp64) |
| 47 |
#if DEBUG |
| 48 |
printf("DFP 64-bit quantize of variable, RMC = 0 result does not match expected result\n"); |
| 49 |
#else |
| 50 |
abort(); |
| 51 |
#endif |
| 52 |
|
| 53 |
srcA_dfp64 = 100.00df; |
| 54 |
srcB_dfp64 = 300.456789df; |
| 55 |
expected_result_dfp64 = 300.45df; |
| 56 |
|
| 57 |
result_dfp64 = __builtin_dfp_quantize (srcA_dfp64, srcB_dfp64, 0x1); |
| 58 |
|
| 59 |
if (result_dfp64 != expected_result_dfp64) |
| 60 |
#if DEBUG |
| 61 |
printf("DFP 64-bit quantize of variable, RMC = 1 result does not match expected result\n"); |
| 62 |
#else |
| 63 |
abort(); |
| 64 |
#endif |
| 65 |
|
| 66 |
srcA_dfp64 = 100.001df; |
| 67 |
srcB_dfp64 = 3001.456789df; |
| 68 |
expected_result_dfp64 = 3001.457df; |
| 69 |
|
| 70 |
result_dfp64 = __builtin_dfp_quantize (srcA_dfp64, srcB_dfp64, 0x2); |
| 71 |
|
| 72 |
if (result_dfp64 != expected_result_dfp64) |
| 73 |
#if DEBUG |
| 74 |
printf("DFP 64-bit quantize of variable, RMC = 2 result does not match expected result\n"); |
| 75 |
#else |
| 76 |
abort(); |
| 77 |
#endif |
| 78 |
|
| 79 |
/* Tests for 64-bit quantize with immediate value. */ |
| 80 |
|
| 81 |
srcB_dfp64 = 10.4567df; |
| 82 |
expected_result_dfp64 = 000.0df; |
| 83 |
|
| 84 |
result_dfp64 = __builtin_dfp_quantize (IMM2, srcB_dfp64, 0x0); |
| 85 |
|
| 86 |
if (result_dfp64 != expected_result_dfp64) |
| 87 |
#if DEBUG |
| 88 |
printf("DFP 64-bit quantize immediate, RMC = 0 result does not match expected result\n"); |
| 89 |
#else |
| 90 |
abort(); |
| 91 |
#endif |
| 92 |
|
| 93 |
srcB_dfp64 = 104567.891df; |
| 94 |
expected_result_dfp64 = 100000.0df; |
| 95 |
|
| 96 |
result_dfp64 = __builtin_dfp_quantize (IMM4, srcB_dfp64, 0x1); |
| 97 |
|
| 98 |
if (result_dfp64 != expected_result_dfp64) |
| 99 |
#if DEBUG |
| 100 |
printf("DFP 64-bit quantize immediate, RMC = 1 result does not match expected result\n"); |
| 101 |
#else |
| 102 |
abort(); |
| 103 |
#endif |
| 104 |
|
| 105 |
srcB_dfp64 = 109876.54321df; |
| 106 |
expected_result_dfp64 = 109900.0df; |
| 107 |
|
| 108 |
result_dfp64 = __builtin_dfp_quantize (IMM2, srcB_dfp64, 0x2); |
| 109 |
|
| 110 |
if (result_dfp64 != expected_result_dfp64) |
| 111 |
#if DEBUG |
| 112 |
printf("DFP 64-bit quantize immediate, RMC = 2 result does not match expected result\n"); |
| 113 |
#else |
| 114 |
abort(); |
| 115 |
#endif |
| 116 |
|
| 117 |
/* Tests for quantize 128-bit DFP variable. */ |
| 118 |
srcA_dfp128 = 0.018df; |
| 119 |
srcB_dfp128 = 50000.18345df; |
| 120 |
expected_result_dfp128 = 50000.180df; |
| 121 |
|
| 122 |
result_dfp128 = __builtin_dfp_quantize (srcA_dfp128, srcB_dfp128, 0x0); |
| 123 |
|
| 124 |
if (result_dfp128 != expected_result_dfp128) |
| 125 |
#if DEBUG |
| 126 |
printf("DFP 128-bit quantize variable, RMC = 0 result does not match expected result\n"); |
| 127 |
#else |
| 128 |
abort(); |
| 129 |
#endif |
| 130 |
|
| 131 |
srcA_dfp128 = 8.01df; |
| 132 |
srcB_dfp128 = 50000.18345df; |
| 133 |
expected_result_dfp128 = 50000.18df; |
| 134 |
|
| 135 |
result_dfp128 = __builtin_dfp_quantize (srcA_dfp128, srcB_dfp128, 0x1); |
| 136 |
|
| 137 |
if (result_dfp128 != expected_result_dfp128) |
| 138 |
#if DEBUG |
| 139 |
printf("DFP 128-bit quantize variable, RMC = 1 result does not match expected result\n"); |
| 140 |
#else |
| 141 |
abort(); |
| 142 |
#endif |
| 143 |
|
| 144 |
srcA_dfp128 = 0.1234df; |
| 145 |
srcB_dfp128 = 50000.18346789df; |
| 146 |
expected_result_dfp128 = 50000.1800df; |
| 147 |
|
| 148 |
result_dfp128 = __builtin_dfp_quantize (srcA_dfp128, srcB_dfp128, 0x2); |
| 149 |
|
| 150 |
if (result_dfp128 != expected_result_dfp128) |
| 151 |
#if DEBUG |
| 152 |
printf("DFP 128-bit quantize variable, RMC = 2 result does not match expected result\n"); |
| 153 |
#else |
| 154 |
abort(); |
| 155 |
#endif |
| 156 |
|
| 157 |
/* Tests for 128-bit quantize with immediate value. */ |
| 158 |
srcB_dfp128 = 1234.18345df; |
| 159 |
expected_result_dfp128 = 1200.0df; |
| 160 |
|
| 161 |
result_dfp128 = __builtin_dfp_quantize (IMM2, srcB_dfp128, 0x0); |
| 162 |
|
| 163 |
if (result_dfp128 != expected_result_dfp128) |
| 164 |
#if DEBUG |
| 165 |
printf("DFP 128-bit quantize immediate, RMC = 0 result does not match expected result\n"); |
| 166 |
#else |
| 167 |
abort(); |
| 168 |
#endif |
| 169 |
|
| 170 |
srcB_dfp128 = 123456.18345df; |
| 171 |
expected_result_dfp128 = 120000.0df; |
| 172 |
|
| 173 |
result_dfp128 = __builtin_dfp_quantize (IMM4, srcB_dfp128, 0x1); |
| 174 |
|
| 175 |
if (result_dfp128 != expected_result_dfp128) |
| 176 |
#if DEBUG |
| 177 |
printf("DFP 128-bit quantize immediate, RMC = 1 result does not match expected result\n"); |
| 178 |
#else |
| 179 |
abort(); |
| 180 |
#endif |
| 181 |
|
| 182 |
srcB_dfp128 = 12361834.5df; |
| 183 |
expected_result_dfp128 = 12362000.0df; |
| 184 |
|
| 185 |
result_dfp128 = __builtin_dfp_quantize (IMM3, srcB_dfp128, 0x2); |
| 186 |
|
| 187 |
if (result_dfp128 != expected_result_dfp128) |
| 188 |
#if DEBUG |
| 189 |
printf("DFP 128-bit quantize immediate, RMC = 2 result does not match expected result\n"); |
| 190 |
#else |
| 191 |
abort(); |
| 192 |
#endif |
| 193 |
|
| 194 |
return 0; |
| 195 |
} |
| 196 |
|
| 197 |
/* { dg-final { scan-assembler-times {\mdqua\M} 3 } } */ |
| 198 |
/* { dg-final { scan-assembler-times {\mdquai\M} 3 } } */ |
| 199 |
/* { dg-final { scan-assembler-times {\mdquaq\M} 3 } } */ |
| 200 |
/* { dg-final { scan-assembler-times {\mdquaiq\M} 3 } } */ |