| 1 | // REQUIRES: target-is-powerpc64le |
| 2 | // RUN: %clang_builtins %s %librt -o %t && %run %t |
| 3 | |
| 4 | #include <stdint.h> |
| 5 | #include <stdio.h> |
| 6 | |
| 7 | #include "fixtfti_test.h" |
| 8 | |
| 9 | // The long double representation, with the high and low portions of |
| 10 | // the long double, and the corresponding bit patterns of each double. |
| 11 | typedef union { |
| 12 | long double ld; |
| 13 | double d[2]; // [0] is the high double, [1] is the low double. |
| 14 | unsigned long long ull[2]; // High and low doubles as 64-bit integers. |
| 15 | } ldUnion; |
| 16 | |
| 17 | __int128_t __fixtfti(long double); |
| 18 | |
| 19 | int main(int argc, char *argv[]) { |
| 20 | // Necessary long double and (unsigned) 128 bit integer |
| 21 | // declarations used to compare the computed and expected results |
| 22 | // from converting the IBM double-double to int128. |
| 23 | ldUnion ldInput; |
| 24 | __uint128_t expectedResult, computedResult; |
| 25 | |
| 26 | for (int i = 0; i < numTests; ++i) { |
| 27 | // Set the expected 128 bit integer and the high and low |
| 28 | // values of the long double input. |
| 29 | ldInput.d[0] = testList[i].hiInput; |
| 30 | ldInput.d[1] = testList[i].loInput; |
| 31 | expectedResult = testList[i].result128; |
| 32 | |
| 33 | // Get the computed 128 bit integer from the long double to |
| 34 | // int128 conversion. Here we cast to unsigned int128 to |
| 35 | // get the bit pattern of the result. |
| 36 | computedResult = (__uint128_t) __fixtfti(ldInput.ld); |
| 37 | |
| 38 | if (computedResult != expectedResult) { |
| 39 | printf(format: "Error for __fixtfti at input %La = ( %a , %a ):\n" , ldInput.ld, |
| 40 | ldInput.d[0], ldInput.d[1]); |
| 41 | printf(format: "\tExpected __int128_t: 0x%016llx 0x%016llx\n" , |
| 42 | (unsigned long long)(expectedResult >> 64), |
| 43 | (unsigned long long)expectedResult); |
| 44 | printf(format: "\tComputed __int128_t: 0x%016llx 0x%016llx\n\n" , |
| 45 | (unsigned long long)(computedResult >> 64), |
| 46 | (unsigned long long)computedResult); |
| 47 | |
| 48 | return 1; |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | return 0; |
| 53 | } |
| 54 | |