[PowerPC] Collect some CallLowering arguments into a struct. [NFC]
[llvm-project.git] / compiler-rt / test / builtins / Unit / compiler_rt_logb_test.c
blobc36b19ca3db16be9116006d82b87733d4e3830fc
1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 //===-- compiler_rt_logb_test.c - Test __compiler_rt_logb -----------------===//
3 //
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file checks __compiler_rt_logb from the compiler_rt library for
11 // conformance against libm.
13 //===----------------------------------------------------------------------===//
15 #define DOUBLE_PRECISION
16 #include <math.h>
17 #include <stdio.h>
18 #include "fp_lib.h"
20 int test__compiler_rt_logb(fp_t x) {
21 fp_t crt_value = __compiler_rt_logb(x);
22 fp_t libm_value = logb(x);
23 // Compare actual rep, e.g. to avoid NaN != the same NaN
24 if (toRep(crt_value) != toRep(libm_value)) {
25 printf("error: in __compiler_rt_logb(%a [%lX]) = %a [%lX] != %a [%lX]\n",
26 x, toRep(x), crt_value, toRep(crt_value), libm_value,
27 toRep(libm_value));
28 return 1;
30 return 0;
33 double cases[] = {
34 1.e-6, -1.e-6, NAN, -NAN, INFINITY, -INFINITY, -1,
35 -0.0, 0.0, 1, -2, 2, -0.5, 0.5,
38 #ifndef __GLIBC_PREREQ
39 #define __GLIBC_PREREQ(x, y) 0
40 #endif
42 int main() {
43 // Do not the run the compiler-rt logb test case if using GLIBC version
44 // < 2.23. Older versions might not compute to the same value as the
45 // compiler-rt value.
46 #if __GLIBC_PREREQ(2, 23)
47 const unsigned N = sizeof(cases) / sizeof(cases[0]);
48 unsigned i;
49 for (i = 0; i < N; ++i) {
50 if (test__compiler_rt_logb(cases[i])) return 1;
53 // Test a moving 1 bit, especially to handle denormal values.
54 // Test the negation as well.
55 rep_t x = signBit;
56 while (x) {
57 if (test__compiler_rt_logb(fromRep(x))) return 1;
58 if (test__compiler_rt_logb(fromRep(signBit ^ x))) return 1;
59 x >>= 1;
61 // Also try a couple moving ones
62 x = signBit | (signBit >> 1) | (signBit >> 2);
63 while (x) {
64 if (test__compiler_rt_logb(fromRep(x))) return 1;
65 if (test__compiler_rt_logb(fromRep(signBit ^ x))) return 1;
66 x >>= 1;
68 #else
69 printf("skipped\n");
70 #endif
72 return 0;