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 "fixunstfti_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 | __uint128_t __fixunstfti(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-> |
34 | * uint128 conversion, and check for errors between results. */ |
35 | computedResult = __fixunstfti(ldInput.ld); |
36 | |
37 | if (computedResult != expectedResult) { |
38 | printf(format: "Error for __fixunstfti at input %La = ( %a , %a ):\n" , ldInput.ld, |
39 | ldInput.d[0], ldInput.d[1]); |
40 | printf(format: "\tExpected __uint128_t: 0x%016llx 0x%016llx\n" , |
41 | (unsigned long long)(expectedResult >> 64), |
42 | (unsigned long long)expectedResult); |
43 | printf(format: "\tComputed __uint128_t: 0x%016llx 0x%016llx\n\n" , |
44 | (unsigned long long)(computedResult >> 64), |
45 | (unsigned long long)computedResult); |
46 | |
47 | return 1; |
48 | } |
49 | } |
50 | |
51 | return 0; |
52 | } |
53 | |