Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / builtins / Unit / ppc / floattitf_test.c
blobe89e5d946ddbb7876c3ffad163d45ebc396c57cf
1 // REQUIRES: target-is-powerpc64le
2 // RUN: %clang_builtins %s %librt -o %t && %run %t
4 /*
5 * Test case execution for: long double __floattitf (__int128_t)
6 * Conversion from 128 bit integer to long double (IBM double-double).
7 */
9 #include <stdint.h>
10 #include <stdio.h>
12 #include "floattitf_test.h"
14 /* The long double representation, with the high and low portions of
15 * the long double, and the corresponding bit patterns of each double. */
16 typedef union {
17 long double ld;
18 double d[2]; /* [0] is the high double, [1] is the low double. */
19 unsigned long long ull[2]; /* High and low doubles as 64-bit integers. */
20 } ldUnion;
22 long double __floattitf(__int128_t);
24 int main(int argc, char *argv[]) {
25 /* Necessary long double and 128 bit integer declarations used to
26 * compare computed and expected high and low portions of the
27 * IBM double-double. */
28 ldUnion expectedLongDouble;
29 ldUnion computedLongDouble;
30 __int128_t result128;
32 for (int i = 0; i < numTests; ++i) {
33 /* Set the expected high and low values of the long double,
34 * and the 128 bit integer input to be converted. */
35 expectedLongDouble.d[0] = tests[i].hi;
36 expectedLongDouble.d[1] = tests[i].lo;
37 result128 = tests[i].input128;
39 /* Get the computed long double from the int128->long double conversion
40 * and check for errors between high and low portions. */
41 computedLongDouble.ld = __floattitf(result128);
43 if ((computedLongDouble.d[0] != expectedLongDouble.d[0]) ||
44 (computedLongDouble.d[1] != expectedLongDouble.d[1])) {
46 printf("Error on __floattitf( 0x%016llx 0x%016llx ):\n",
47 (long long)(tests[i].input128 >> 64),
48 (long long)tests[i].input128);
49 printf("\tExpected value - %La = ( %a, %a )\n", expectedLongDouble.ld,
50 expectedLongDouble.d[0], expectedLongDouble.d[1]);
51 printf("\tComputed value - %La = ( %a, %a )\n\n", computedLongDouble.ld,
52 computedLongDouble.d[0], computedLongDouble.d[1]);
54 return 1;
58 return 0;