brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.8 KiB · 2c1be87 Raw
68 lines · c
1// RUN: %clang_builtins %s %librt -o %t && %run %t2 3#define DOUBLE_PRECISION4#include <math.h>5#include <stdio.h>6#include "fp_lib.h"7 8int test__compiler_rt_logb(fp_t x) {9#if defined(__ve__)10  if (fpclassify(x) == FP_SUBNORMAL)11    return 0;12#endif13  fp_t crt_value = __compiler_rt_logb(x);14  fp_t libm_value = logb(x);15  // Compare the values, considering all NaNs equivalent, as the spec doesn't16  // specify the NaN signedness/payload.17  if (crt_value != libm_value &&18      !(crt_isnan(crt_value) && crt_isnan(libm_value))) {19    printf("error: in __compiler_rt_logb(%a [%lX]) = %a [%lX] !=  %a [%lX]\n",20           x, toRep(x), crt_value, toRep(crt_value), libm_value,21           toRep(libm_value));22    return 1;23  }24  return 0;25}26 27double cases[] = {28    1.e-6, -1.e-6, NAN, -NAN, INFINITY, -INFINITY, -1,29    -0.0,  0.0,    1,   -2,   2,        -0.5,      0.5,30};31 32#ifndef __GLIBC_PREREQ33#define __GLIBC_PREREQ(x, y) 034#endif35 36int main() {37  // Do not the run the compiler-rt logb test case if using GLIBC version38  // < 2.23. Older versions might not compute to the same value as the39  // compiler-rt value.40#if __GLIBC_PREREQ(2, 23)41  const unsigned N = sizeof(cases) / sizeof(cases[0]);42  unsigned i;43  for (i = 0; i < N; ++i) {44    if (test__compiler_rt_logb(cases[i])) return 1;45  }46 47  // Test a moving 1 bit, especially to handle denormal values.48  // Test the negation as well.49  rep_t x = signBit;50  while (x) {51    if (test__compiler_rt_logb(fromRep(x))) return 1;52    if (test__compiler_rt_logb(fromRep(signBit ^ x))) return 1;53    x >>= 1;54  }55  // Also try a couple moving ones56  x = signBit | (signBit >> 1) | (signBit >> 2);57  while (x) {58    if (test__compiler_rt_logb(fromRep(x))) return 1;59    if (test__compiler_rt_logb(fromRep(signBit ^ x))) return 1;60    x >>= 1;61  }62#else63  printf("skipped\n");64#endif65 66  return 0;67}68