@@ -121,6 +121,8 @@ add_macro_header(
|
||||
math_function_macros
|
||||
HDR
|
||||
math-function-macros.h
|
||||
DEPENDS
|
||||
.math_macros
|
||||
)
|
||||
|
||||
add_macro_header(
|
||||
|
||||
@@ -9,10 +9,14 @@
|
||||
#ifndef LLVM_LIBC_MACROS_MATH_FUNCTION_MACROS_H
|
||||
#define LLVM_LIBC_MACROS_MATH_FUNCTION_MACROS_H
|
||||
|
||||
#include "math-macros.h"
|
||||
|
||||
#define isfinite(x) __builtin_isfinite(x)
|
||||
#define isinf(x) __builtin_isinf(x)
|
||||
#define isnan(x) __builtin_isnan(x)
|
||||
#define signbit(x) __builtin_signbit(x)
|
||||
#define iszero(x) (x == 0)
|
||||
#define fpclassify(x) \
|
||||
__builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL, FP_ZERO, x)
|
||||
|
||||
#endif // LLVM_LIBC_MACROS_MATH_FUNCTION_MACROS_H
|
||||
|
||||
@@ -81,6 +81,36 @@ add_libc_test(
|
||||
libc.include.llvm-libc-macros.stdckdint_macros
|
||||
)
|
||||
|
||||
add_libc_test(
|
||||
fpclassify_test
|
||||
SUITE
|
||||
libc_include_tests
|
||||
SRCS
|
||||
fpclassify_test.cpp
|
||||
DEPENDS
|
||||
libc.include.llvm-libc-macros.math_function_macros
|
||||
)
|
||||
|
||||
add_libc_test(
|
||||
fpclassifyf_test
|
||||
SUITE
|
||||
libc_include_tests
|
||||
SRCS
|
||||
fpclassifyf_test.cpp
|
||||
DEPENDS
|
||||
libc.include.llvm-libc-macros.math_function_macros
|
||||
)
|
||||
|
||||
add_libc_test(
|
||||
fpclassifyl_test
|
||||
SUITE
|
||||
libc_include_tests
|
||||
SRCS
|
||||
fpclassifyl_test.cpp
|
||||
DEPENDS
|
||||
libc.include.llvm-libc-macros.math_function_macros
|
||||
)
|
||||
|
||||
add_libc_test(
|
||||
iszero_test
|
||||
SUITE
|
||||
@@ -291,6 +321,21 @@ add_libc_test(
|
||||
libc.include.llvm-libc-macros.math_function_macros
|
||||
)
|
||||
|
||||
add_libc_test(
|
||||
fpclassify_c_test
|
||||
C_TEST
|
||||
UNIT_TEST_ONLY
|
||||
SUITE
|
||||
libc_include_tests
|
||||
SRCS
|
||||
fpclassify_test.c
|
||||
COMPILE_OPTIONS
|
||||
-Wall
|
||||
-Werror
|
||||
DEPENDS
|
||||
libc.include.llvm-libc-macros.math_function_macros
|
||||
)
|
||||
|
||||
add_libc_test(
|
||||
iszero_c_test
|
||||
C_TEST
|
||||
|
||||
49
libc/test/include/FpClassifyTest.h
Normal file
49
libc/test/include/FpClassifyTest.h
Normal file
@@ -0,0 +1,49 @@
|
||||
//===-- Utility class to test the fpclassify macro -------------*- C++ -*-===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_LIBC_TEST_INCLUDE_MATH_FPCLASSIFY_H
|
||||
#define LLVM_LIBC_TEST_INCLUDE_MATH_FPCLASSIFY_H
|
||||
|
||||
#include "test/UnitTest/FPMatcher.h"
|
||||
#include "test/UnitTest/Test.h"
|
||||
|
||||
#include "include/llvm-libc-macros/math-function-macros.h"
|
||||
|
||||
template <typename T>
|
||||
class FpClassifyTest : public LIBC_NAMESPACE::testing::Test {
|
||||
DECLARE_SPECIAL_CONSTANTS(T)
|
||||
|
||||
public:
|
||||
typedef int (*FpClassifyFunc)(T);
|
||||
|
||||
void testSpecialNumbers(FpClassifyFunc func) {
|
||||
EXPECT_EQ(func(aNaN), FP_NAN);
|
||||
EXPECT_EQ(func(neg_aNaN), FP_NAN);
|
||||
EXPECT_EQ(func(sNaN), FP_NAN);
|
||||
EXPECT_EQ(func(neg_sNaN), FP_NAN);
|
||||
EXPECT_EQ(func(inf), FP_INFINITE);
|
||||
EXPECT_EQ(func(neg_inf), FP_INFINITE);
|
||||
EXPECT_EQ(func(min_normal), FP_NORMAL);
|
||||
EXPECT_EQ(func(max_normal), FP_NORMAL);
|
||||
EXPECT_EQ(func(neg_max_normal), FP_NORMAL);
|
||||
EXPECT_EQ(func(min_denormal), FP_SUBNORMAL);
|
||||
EXPECT_EQ(func(neg_min_denormal), FP_SUBNORMAL);
|
||||
EXPECT_EQ(func(max_denormal), FP_SUBNORMAL);
|
||||
EXPECT_EQ(func(zero), FP_ZERO);
|
||||
EXPECT_EQ(func(neg_zero), FP_ZERO);
|
||||
}
|
||||
};
|
||||
|
||||
#define LIST_FPCLASSIFY_TESTS(T, func) \
|
||||
using LlvmLibcFpClassifyTest = FpClassifyTest<T>; \
|
||||
TEST_F(LlvmLibcFpClassifyTest, SpecialNumbers) { \
|
||||
auto fpclassify_func = [](T x) { return func(x); }; \
|
||||
testSpecialNumbers(fpclassify_func); \
|
||||
}
|
||||
|
||||
#endif // LLVM_LIBC_TEST_INCLUDE_MATH_FPCLASSIFY_H
|
||||
25
libc/test/include/fpclassify_test.c
Normal file
25
libc/test/include/fpclassify_test.c
Normal file
@@ -0,0 +1,25 @@
|
||||
//===-- Unittests for fpclassify macro ------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDSList-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
#include "include/llvm-libc-macros/math-function-macros.h"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
// check if macro is defined
|
||||
#ifndef fpclassify
|
||||
#error "fpclassify macro is not defined"
|
||||
#else
|
||||
int main(void) {
|
||||
assert(fpclassify(1.819f) == FP_NORMAL);
|
||||
assert(fpclassify(-1.726) == FP_NORMAL);
|
||||
assert(fpclassify(1.426L) == FP_NORMAL);
|
||||
assert(fpclassify(-0.0f) == FP_ZERO);
|
||||
assert(fpclassify(0.0) == FP_ZERO);
|
||||
assert(fpclassify(-0.0L) == FP_ZERO);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
12
libc/test/include/fpclassify_test.cpp
Normal file
12
libc/test/include/fpclassify_test.cpp
Normal file
@@ -0,0 +1,12 @@
|
||||
//===-- Unittest for fpclassify[d] macro ----------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDSList-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "FpClassifyTest.h"
|
||||
#include "include/llvm-libc-macros/math-function-macros.h"
|
||||
|
||||
LIST_FPCLASSIFY_TESTS(double, fpclassify)
|
||||
12
libc/test/include/fpclassifyf_test.cpp
Normal file
12
libc/test/include/fpclassifyf_test.cpp
Normal file
@@ -0,0 +1,12 @@
|
||||
//===-- Unittest for fpclassify[f] macro ----------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDSList-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "FpClassifyTest.h"
|
||||
#include "include/llvm-libc-macros/math-function-macros.h"
|
||||
|
||||
LIST_FPCLASSIFY_TESTS(float, fpclassify)
|
||||
12
libc/test/include/fpclassifyl_test.cpp
Normal file
12
libc/test/include/fpclassifyl_test.cpp
Normal file
@@ -0,0 +1,12 @@
|
||||
//===-- Unittest for fpclassify[l] macro ----------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDSList-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "FpClassifyTest.h"
|
||||
#include "include/llvm-libc-macros/math-function-macros.h"
|
||||
|
||||
LIST_FPCLASSIFY_TESTS(long double, fpclassify)
|
||||
Reference in New Issue
Block a user