File: fixunstfti_test.c

package info (click to toggle)
llvm-toolchain-15 1%3A15.0.6-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,554,644 kB
  • sloc: cpp: 5,922,452; ansic: 1,012,136; asm: 674,362; python: 191,568; objc: 73,855; f90: 42,327; lisp: 31,913; pascal: 11,973; javascript: 10,144; sh: 9,421; perl: 7,447; ml: 5,527; awk: 3,523; makefile: 2,520; xml: 885; cs: 573; fortran: 567
file content (52 lines) | stat: -rw-r--r-- 1,810 bytes parent folder | download | duplicates (28)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// REQUIRES: target-is-powerpc64le
// RUN: %clang_builtins %s %librt -o %t && %run %t

#include <stdint.h>
#include <stdio.h>

#include "fixunstfti_test.h"

/* The long double representation, with the high and low portions of
 * the long double, and the corresponding bit patterns of each double. */
typedef union {
  long double ld;
  double d[2]; /* [0] is the high double, [1] is the low double. */
  unsigned long long ull[2]; /* High and low doubles as 64-bit integers. */
} ldUnion;

__uint128_t __fixunstfti(long double);

int main(int argc, char *argv[]) {
  /* Necessary long double and (unsigned) 128 bit integer
   * declarations used to compare the computed and expected results
   * from converting the IBM double-double to int128. */
  ldUnion ldInput;
  __uint128_t expectedResult, computedResult;

  for (int i = 0; i < numTests; ++i) {
    /* Set the expected 128 bit integer and the high and low
     * values of the long double input. */
    ldInput.d[0] = testList[i].hiInput;
    ldInput.d[1] = testList[i].loInput;
    expectedResult = testList[i].result128;

    /* Get the computed 128 bit integer from the long double->
     * uint128 conversion, and check for errors between results. */
    computedResult = __fixunstfti(ldInput.ld);

    if (computedResult != expectedResult) {
      printf("Error for __fixunstfti at input %La = ( %a , %a ):\n", ldInput.ld,
             ldInput.d[0], ldInput.d[1]);
      printf("\tExpected __uint128_t: 0x%016llx 0x%016llx\n",
             (unsigned long long)(expectedResult >> 64),
             (unsigned long long)expectedResult);
      printf("\tComputed __uint128_t: 0x%016llx 0x%016llx\n\n",
             (unsigned long long)(computedResult >> 64),
             (unsigned long long)computedResult);

      return 1;
    }
  }

  return 0;
}