brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.9 KiB · 44f75cf Raw
62 lines · c
1// RUN: %clang_builtins %s %librt -o %t && %run %t2 3#define QUAD_PRECISION4#include <fenv.h>5#include <math.h>6#include <stdio.h>7#include "fp_lib.h"8 9// Since we are comparing the compiler-rt IEEE implementation against libc's10// long double implementation, this test can only succeed if long double11// is an IEEE 128-bit floating point number.12#if defined(CRT_HAS_TF_MODE) && defined(CRT_LDBL_IEEE_F128)13 14int test__compiler_rt_fmaxl(fp_t x, fp_t y) {15  fp_t crt_value = __compiler_rt_fmaxl(x, y);16  fp_t libm_value = fmaxl(x, y);17  // Consider +0 and -0 equal, and also disregard the sign/payload of two NaNs.18  if (crt_value != libm_value &&19      !(crt_isnan(crt_value) && crt_isnan(libm_value))) {20    // Split expected values into two for printf21    twords x_t, y_t, crt_value_t, libm_value_t;22    x_t.all = toRep(x);23    y_t.all = toRep(y);24    crt_value_t.all = toRep(crt_value);25    libm_value_t.all = toRep(libm_value);26    printf(27        "error: in __compiler_rt_fmaxl([%llX %llX], [%llX %llX]) = "28        "[%llX %llX] != [%llX %llX]\n",29        (unsigned long long)x_t.s.high, (unsigned long long)x_t.s.low,30        (unsigned long long)y_t.s.high, (unsigned long long)y_t.s.low,31        (unsigned long long)crt_value_t.s.high,32        (unsigned long long)crt_value_t.s.low,33        (unsigned long long)libm_value_t.s.high,34        (unsigned long long)libm_value_t.s.low);35    return 1;36  }37  return 0;38}39 40fp_t cases[] = {41  -NAN, NAN, -INFINITY, INFINITY, -0.0, 0.0, -1, 1, -2, 2,42  -0x1.0p-16383L, 0x1.0p-16383L, -0x1.0p-16384L, 0x1.0p-16384L, // subnormals43  -1.001, 1.001, -1.002, 1.002,44};45 46int main() {47  const unsigned N = sizeof(cases) / sizeof(cases[0]);48  unsigned i, j;49  for (i = 0; i < N; ++i) {50    for (j = 0; j < N; ++j) {51      if (test__compiler_rt_fmaxl(cases[i], cases[j])) return 1;52    }53  }54  return 0;55}56#else57int main() {58  printf("skipped\n");59  return 0;60}61#endif62