| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| //===-- Implementation header for f16mulf128 --------------------*- 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_SRC_MATH_F16MULF128_H | ||
| #define LLVM_LIBC_SRC_MATH_F16MULF128_H | ||
|
|
||
| #include "src/__support/macros/config.h" | ||
| #include "src/__support/macros/properties/types.h" | ||
|
|
||
| namespace LIBC_NAMESPACE_DECL { | ||
|
|
||
| float16 f16mulf128(float128 x, float128 y); | ||
|
|
||
| } // namespace LIBC_NAMESPACE_DECL | ||
|
|
||
| #endif // LLVM_LIBC_SRC_MATH_F16MULF128_H |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| //===-- Implementation header for f16mull -----------------------*- 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_SRC_MATH_F16MULL_H | ||
| #define LLVM_LIBC_SRC_MATH_F16MULL_H | ||
|
|
||
| #include "src/__support/macros/config.h" | ||
| #include "src/__support/macros/properties/types.h" | ||
|
|
||
| namespace LIBC_NAMESPACE_DECL { | ||
|
|
||
| float16 f16mull(long double x, long double y); | ||
|
|
||
| } // namespace LIBC_NAMESPACE_DECL | ||
|
|
||
| #endif // LLVM_LIBC_SRC_MATH_F16MULL_H |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| //===-- Implementation header for fmulf128 ----------------------*- 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_SRC_MATH_FMULF128_H | ||
| #define LLVM_LIBC_SRC_MATH_FMULF128_H | ||
|
|
||
| #include "src/__support/macros/config.h" | ||
| #include "src/__support/macros/properties/types.h" | ||
|
|
||
| namespace LIBC_NAMESPACE_DECL { | ||
|
|
||
| float fmulf128(float128 x, float128 y); | ||
|
|
||
| } // namespace LIBC_NAMESPACE_DECL | ||
|
|
||
| #endif // LLVM_LIBC_SRC_MATH_FMULF128_H |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| //===-- Implementation header for fmull -------------------------*- 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_SRC_MATH_FMULL_H | ||
| #define LLVM_LIBC_SRC_MATH_FMULL_H | ||
|
|
||
| #include "src/__support/macros/config.h" | ||
|
|
||
| namespace LIBC_NAMESPACE_DECL { | ||
|
|
||
| float fmull(long double x, long double y); | ||
|
|
||
| } // namespace LIBC_NAMESPACE_DECL | ||
|
|
||
| #endif // LLVM_LIBC_SRC_MATH_FMULL_H |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| //===-- Implementation of dmulf128 function -------------------------------===// | ||
| // | ||
| // 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 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "src/math/dmulf128.h" | ||
| #include "src/__support/FPUtil/generic/mul.h" | ||
| #include "src/__support/common.h" | ||
| #include "src/__support/macros/config.h" | ||
|
|
||
| namespace LIBC_NAMESPACE_DECL { | ||
|
|
||
| LLVM_LIBC_FUNCTION(double, dmulf128, (float128 x, float128 y)) { | ||
| return fputil::generic::mul<double>(x, y); | ||
| } | ||
|
|
||
| } // namespace LIBC_NAMESPACE_DECL |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| //===-- Implementation of dmull function ----------------------------------===// | ||
| // | ||
| // 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 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "src/math/dmull.h" | ||
| #include "src/__support/FPUtil/generic/mul.h" | ||
| #include "src/__support/common.h" | ||
| #include "src/__support/macros/config.h" | ||
|
|
||
| namespace LIBC_NAMESPACE_DECL { | ||
|
|
||
| LLVM_LIBC_FUNCTION(double, dmull, (long double x, long double y)) { | ||
| return fputil::generic::mul<double>(x, y); | ||
| } | ||
|
|
||
| } // namespace LIBC_NAMESPACE_DECL |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| //===-- Implementation of f16mul function ---------------------------------===// | ||
| // | ||
| // 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 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "src/math/f16mul.h" | ||
| #include "src/__support/FPUtil/generic/mul.h" | ||
| #include "src/__support/common.h" | ||
| #include "src/__support/macros/config.h" | ||
|
|
||
| namespace LIBC_NAMESPACE_DECL { | ||
|
|
||
| LLVM_LIBC_FUNCTION(float16, f16mul, (double x, double y)) { | ||
| return fputil::generic::mul<float16>(x, y); | ||
| } | ||
|
|
||
| } // namespace LIBC_NAMESPACE_DECL |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| //===-- Implementation of f16mulf function --------------------------------===// | ||
| // | ||
| // 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 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "src/math/f16mulf.h" | ||
| #include "src/__support/FPUtil/generic/mul.h" | ||
| #include "src/__support/common.h" | ||
| #include "src/__support/macros/config.h" | ||
|
|
||
| namespace LIBC_NAMESPACE_DECL { | ||
|
|
||
| LLVM_LIBC_FUNCTION(float16, f16mulf, (float x, float y)) { | ||
| return fputil::generic::mul<float16>(x, y); | ||
| } | ||
|
|
||
| } // namespace LIBC_NAMESPACE_DECL |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| //===-- Implementation of f16mulf128 function -----------------------------===// | ||
| // | ||
| // 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 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "src/math/f16mulf128.h" | ||
| #include "src/__support/FPUtil/generic/mul.h" | ||
| #include "src/__support/common.h" | ||
| #include "src/__support/macros/config.h" | ||
|
|
||
| namespace LIBC_NAMESPACE_DECL { | ||
|
|
||
| LLVM_LIBC_FUNCTION(float16, f16mulf128, (float128 x, float128 y)) { | ||
| return fputil::generic::mul<float16>(x, y); | ||
| } | ||
|
|
||
| } // namespace LIBC_NAMESPACE_DECL |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| //===-- Implementation of f16mull function --------------------------------===// | ||
| // | ||
| // 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 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "src/math/f16mull.h" | ||
| #include "src/__support/FPUtil/generic/mul.h" | ||
| #include "src/__support/common.h" | ||
| #include "src/__support/macros/config.h" | ||
|
|
||
| namespace LIBC_NAMESPACE_DECL { | ||
|
|
||
| LLVM_LIBC_FUNCTION(float16, f16mull, (long double x, long double y)) { | ||
| return fputil::generic::mul<float16>(x, y); | ||
| } | ||
|
|
||
| } // namespace LIBC_NAMESPACE_DECL |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| //===-- Implementation of fmulf128 function -------------------------------===// | ||
| // | ||
| // 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 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "src/math/fmulf128.h" | ||
| #include "src/__support/FPUtil/generic/mul.h" | ||
| #include "src/__support/common.h" | ||
| #include "src/__support/macros/config.h" | ||
|
|
||
| namespace LIBC_NAMESPACE_DECL { | ||
|
|
||
| LLVM_LIBC_FUNCTION(float, fmulf128, (float128 x, float128 y)) { | ||
| return fputil::generic::mul<float>(x, y); | ||
| } | ||
|
|
||
| } // namespace LIBC_NAMESPACE_DECL |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| //===-- Implementation of fmull function ----------------------------------===// | ||
| // | ||
| // 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 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "src/math/fmull.h" | ||
| #include "src/__support/FPUtil/generic/mul.h" | ||
| #include "src/__support/common.h" | ||
| #include "src/__support/macros/config.h" | ||
|
|
||
| namespace LIBC_NAMESPACE_DECL { | ||
|
|
||
| LLVM_LIBC_FUNCTION(float, fmull, (long double x, long double y)) { | ||
| return fputil::generic::mul<float>(x, y); | ||
| } | ||
|
|
||
| } // namespace LIBC_NAMESPACE_DECL |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| //===-- Utility class to test different flavors of float mul ----*- 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_SRC_MATH_MULTEST_H | ||
| #define LLVM_LIBC_TEST_SRC_MATH_MULTEST_H | ||
|
|
||
| #include "src/stdlib/rand.h" | ||
| #include "src/stdlib/srand.h" | ||
| #include "test/UnitTest/FEnvSafeTest.h" | ||
| #include "test/UnitTest/FPMatcher.h" | ||
| #include "test/UnitTest/Test.h" | ||
| #include "utils/MPFRWrapper/MPFRUtils.h" | ||
|
|
||
| namespace mpfr = LIBC_NAMESPACE::testing::mpfr; | ||
|
|
||
| template <typename OutType, typename InType> | ||
| class MulTest : public LIBC_NAMESPACE::testing::FEnvSafeTest { | ||
|
|
||
| struct InConstants { | ||
| DECLARE_SPECIAL_CONSTANTS(InType) | ||
| }; | ||
|
|
||
| using InFPBits = typename InConstants::FPBits; | ||
| using InStorageType = typename InConstants::StorageType; | ||
|
|
||
| static constexpr InStorageType IN_MAX_NORMAL_U = | ||
| InFPBits::max_normal().uintval(); | ||
| static constexpr InStorageType IN_MIN_NORMAL_U = | ||
| InFPBits::min_normal().uintval(); | ||
| static constexpr InStorageType IN_MAX_SUBNORMAL_U = | ||
| InFPBits::max_subnormal().uintval(); | ||
| static constexpr InStorageType IN_MIN_SUBNORMAL_U = | ||
| InFPBits::min_subnormal().uintval(); | ||
|
|
||
| InStorageType get_random_bit_pattern() { | ||
| InStorageType bits{0}; | ||
| for (InStorageType i = 0; i < sizeof(InStorageType) / 2; ++i) | ||
| bits = (bits << 2) + static_cast<uint16_t>(LIBC_NAMESPACE::rand()); | ||
| return bits; | ||
| } | ||
|
|
||
| public: | ||
| using MulFunc = OutType (*)(InType, InType); | ||
|
|
||
| void test_subnormal_range(MulFunc func) { | ||
| constexpr InStorageType COUNT = 10'001; | ||
| constexpr InStorageType STEP = | ||
| (IN_MAX_SUBNORMAL_U - IN_MIN_SUBNORMAL_U) / COUNT; | ||
| LIBC_NAMESPACE::srand(1); | ||
| for (int signs = 0; signs < 4; signs++) { | ||
| for (InStorageType i = 0, v = 0; i <= COUNT; ++i, v += STEP) { | ||
| InType x = InFPBits(get_random_bit_pattern()).get_val(); | ||
| InType y = InFPBits(v).get_val(); | ||
| if ((signs & 1) != 0) | ||
| x = -x; | ||
| if ((signs & 2) != 0) | ||
| y = -y; | ||
| mpfr::BinaryInput<InType> input{x, y}; | ||
| EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Mul, input, func(x, y), | ||
| 0.5); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| void test_normal_range(MulFunc func) { | ||
| constexpr InStorageType COUNT = 10'001; | ||
| constexpr InStorageType STEP = (IN_MAX_NORMAL_U - IN_MIN_NORMAL_U) / COUNT; | ||
| LIBC_NAMESPACE::srand(1); | ||
| for (int signs = 0; signs < 4; signs++) { | ||
| for (InStorageType i = 0, v = 0; i <= COUNT; ++i, v += STEP) { | ||
| InType x = InFPBits(get_random_bit_pattern()).get_val(); | ||
| InType y = InFPBits(v).get_val(); | ||
| if ((signs & 1) != 0) | ||
| x = -x; | ||
| if ((signs & 2) != 0) | ||
| y = -y; | ||
| mpfr::BinaryInput<InType> input{x, y}; | ||
| EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Mul, input, func(x, y), | ||
| 0.5); | ||
| } | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| #define LIST_MUL_TESTS(OutType, InType, func) \ | ||
| using LlvmLibcMulTest = MulTest<OutType, InType>; \ | ||
| TEST_F(LlvmLibcMulTest, SubnormalRange) { test_subnormal_range(&func); } \ | ||
| TEST_F(LlvmLibcMulTest, NormalRange) { test_normal_range(&func); } | ||
|
|
||
| #endif // LLVM_LIBC_TEST_SRC_MATH_MULTEST_H |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| //===-- Unittests for dmull -----------------------------------------------===// | ||
| // | ||
| // 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 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "MulTest.h" | ||
|
|
||
| #include "src/math/dmull.h" | ||
|
|
||
| LIST_MUL_TESTS(double, long double, LIBC_NAMESPACE::dmull) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| //===-- Unittests for f16mul ----------------------------------------------===// | ||
| // | ||
| // 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 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "MulTest.h" | ||
|
|
||
| #include "src/math/f16mul.h" | ||
|
|
||
| LIST_MUL_TESTS(float16, double, LIBC_NAMESPACE::f16mul) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| //===-- Unittests for f16mulf ---------------------------------------------===// | ||
| // | ||
| // 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 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "MulTest.h" | ||
|
|
||
| #include "src/math/f16mulf.h" | ||
|
|
||
| LIST_MUL_TESTS(float16, float, LIBC_NAMESPACE::f16mulf) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| //===-- Unittests for f16mull ---------------------------------------------===// | ||
| // | ||
| // 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 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "MulTest.h" | ||
|
|
||
| #include "src/math/f16mull.h" | ||
|
|
||
| LIST_MUL_TESTS(float16, long double, LIBC_NAMESPACE::f16mull) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,13 @@ | ||
| //===-- Unittests for fmul ------------------------------------------------===// | ||
| // | ||
| // 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 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "MulTest.h" | ||
|
|
||
| #include "src/math/fmul.h" | ||
|
|
||
| LIST_MUL_TESTS(float, double, LIBC_NAMESPACE::fmul) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| //===-- Unittests for fmull -----------------------------------------------===// | ||
| // | ||
| // 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 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "MulTest.h" | ||
|
|
||
| #include "src/math/fmull.h" | ||
|
|
||
| LIST_MUL_TESTS(float, long double, LIBC_NAMESPACE::fmull) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,171 @@ | ||
| //===-- Utility class to test different flavors of float mul ----*- 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_SRC_MATH_SMOKE_MULTEST_H | ||
| #define LLVM_LIBC_TEST_SRC_MATH_SMOKE_MULTEST_H | ||
|
|
||
| #include "hdr/errno_macros.h" | ||
| #include "hdr/fenv_macros.h" | ||
| #include "src/__support/FPUtil/BasicOperations.h" | ||
| #include "test/UnitTest/FEnvSafeTest.h" | ||
| #include "test/UnitTest/FPMatcher.h" | ||
| #include "test/UnitTest/Test.h" | ||
|
|
||
| template <typename OutType, typename InType> | ||
| class MulTest : public LIBC_NAMESPACE::testing::FEnvSafeTest { | ||
|
|
||
| DECLARE_SPECIAL_CONSTANTS(OutType) | ||
|
|
||
| struct InConstants { | ||
| DECLARE_SPECIAL_CONSTANTS(InType) | ||
| }; | ||
|
|
||
| using InFPBits = typename InConstants::FPBits; | ||
| using InStorageType = typename InConstants::StorageType; | ||
|
|
||
| InConstants in; | ||
|
|
||
| public: | ||
| using MulFunc = OutType (*)(InType, InType); | ||
|
|
||
| void test_special_numbers(MulFunc func) { | ||
| EXPECT_FP_IS_NAN(func(aNaN, aNaN)); | ||
| EXPECT_FP_IS_NAN_WITH_EXCEPTION(func(sNaN, sNaN), FE_INVALID); | ||
|
|
||
| InType qnan_42 = InFPBits::quiet_nan(Sign::POS, 0x42).get_val(); | ||
| EXPECT_FP_EQ(InType(0x42.0p+0), | ||
| LIBC_NAMESPACE::fputil::getpayload(func(qnan_42, zero))); | ||
| EXPECT_FP_EQ(InType(0x42.0p+0), | ||
| LIBC_NAMESPACE::fputil::getpayload(func(zero, qnan_42))); | ||
|
|
||
| if constexpr (sizeof(OutType) < sizeof(InType)) { | ||
| InStorageType max_payload = InFPBits::FRACTION_MASK >> 1; | ||
| InType qnan_max = InFPBits::quiet_nan(Sign::POS, max_payload).get_val(); | ||
| EXPECT_FP_EQ(zero, | ||
| LIBC_NAMESPACE::fputil::getpayload(func(qnan_max, zero))); | ||
| EXPECT_FP_EQ(zero, | ||
| LIBC_NAMESPACE::fputil::getpayload(func(zero, qnan_max))); | ||
| EXPECT_FP_EQ(InType(0x42.0p+0), | ||
| LIBC_NAMESPACE::fputil::getpayload(func(qnan_max, qnan_42))); | ||
| EXPECT_FP_EQ(InType(0x42.0p+0), | ||
| LIBC_NAMESPACE::fputil::getpayload(func(qnan_42, qnan_max))); | ||
| } | ||
|
|
||
| EXPECT_FP_EQ(inf, func(inf, InType(1.0))); | ||
| EXPECT_FP_EQ(neg_inf, func(neg_inf, InType(1.0))); | ||
| EXPECT_FP_EQ(neg_inf, func(inf, InType(-1.0))); | ||
| EXPECT_FP_EQ(inf, func(neg_inf, InType(-1.0))); | ||
|
|
||
| EXPECT_FP_EQ_ALL_ROUNDING(zero, func(zero, zero)); | ||
| EXPECT_FP_EQ_ALL_ROUNDING(zero, func(neg_zero, neg_zero)); | ||
| EXPECT_FP_EQ_ALL_ROUNDING(neg_zero, func(zero, neg_zero)); | ||
| EXPECT_FP_EQ_ALL_ROUNDING(neg_zero, func(neg_zero, zero)); | ||
|
|
||
| EXPECT_FP_EQ_ALL_ROUNDING(OutType(1.0), func(1.0, 1.0)); | ||
| EXPECT_FP_EQ_ALL_ROUNDING(OutType(15.0), func(3.0, 5.0)); | ||
| EXPECT_FP_EQ_ALL_ROUNDING(OutType(0x1.0p-13), func(0x1.0p+1, 0x1.0p-14)); | ||
| EXPECT_FP_EQ_ALL_ROUNDING(OutType(0x1.0p-10), func(0x1.0p+2, 0x1.0p-12)); | ||
| } | ||
|
|
||
| void test_invalid_operations(MulFunc func) { | ||
| EXPECT_FP_IS_NAN_WITH_EXCEPTION(func(inf, zero), FE_INVALID); | ||
| EXPECT_FP_IS_NAN_WITH_EXCEPTION(func(inf, neg_zero), FE_INVALID); | ||
| EXPECT_FP_IS_NAN_WITH_EXCEPTION(func(neg_inf, zero), FE_INVALID); | ||
| EXPECT_FP_IS_NAN_WITH_EXCEPTION(func(neg_inf, neg_zero), FE_INVALID); | ||
| } | ||
|
|
||
| void test_range_errors(MulFunc func) { | ||
| using namespace LIBC_NAMESPACE::fputil::testing; | ||
|
|
||
| if (ForceRoundingMode r(RoundingMode::Nearest); r.success) { | ||
| EXPECT_FP_EQ_WITH_EXCEPTION(inf, func(max_normal, max_normal), | ||
| FE_OVERFLOW | FE_INEXACT); | ||
| EXPECT_MATH_ERRNO(ERANGE); | ||
| EXPECT_FP_EQ_WITH_EXCEPTION(neg_inf, func(neg_max_normal, max_normal), | ||
| FE_OVERFLOW | FE_INEXACT); | ||
| EXPECT_MATH_ERRNO(ERANGE); | ||
|
|
||
| EXPECT_FP_EQ_WITH_EXCEPTION(zero, func(in.min_denormal, in.min_denormal), | ||
| FE_UNDERFLOW | FE_INEXACT); | ||
| EXPECT_MATH_ERRNO(ERANGE); | ||
| EXPECT_FP_EQ_WITH_EXCEPTION(neg_zero, | ||
| func(in.neg_min_denormal, in.min_denormal), | ||
| FE_UNDERFLOW | FE_INEXACT); | ||
| EXPECT_MATH_ERRNO(ERANGE); | ||
| } | ||
|
|
||
| if (ForceRoundingMode r(RoundingMode::TowardZero); r.success) { | ||
| EXPECT_FP_EQ_WITH_EXCEPTION(max_normal, func(max_normal, max_normal), | ||
| FE_OVERFLOW | FE_INEXACT); | ||
| EXPECT_FP_EQ_WITH_EXCEPTION(neg_max_normal, | ||
| func(neg_max_normal, max_normal), | ||
| FE_OVERFLOW | FE_INEXACT); | ||
|
|
||
| EXPECT_FP_EQ_WITH_EXCEPTION(zero, func(in.min_denormal, in.min_denormal), | ||
| FE_UNDERFLOW | FE_INEXACT); | ||
| EXPECT_MATH_ERRNO(ERANGE); | ||
| EXPECT_FP_EQ_WITH_EXCEPTION(neg_zero, | ||
| func(in.neg_min_denormal, in.min_denormal), | ||
| FE_UNDERFLOW | FE_INEXACT); | ||
| EXPECT_MATH_ERRNO(ERANGE); | ||
| } | ||
|
|
||
| if (ForceRoundingMode r(RoundingMode::Downward); r.success) { | ||
| EXPECT_FP_EQ_WITH_EXCEPTION(max_normal, func(max_normal, max_normal), | ||
| FE_OVERFLOW | FE_INEXACT); | ||
| EXPECT_FP_EQ_WITH_EXCEPTION(neg_inf, func(neg_max_normal, max_normal), | ||
| FE_OVERFLOW | FE_INEXACT); | ||
| EXPECT_MATH_ERRNO(ERANGE); | ||
|
|
||
| EXPECT_FP_EQ_WITH_EXCEPTION(zero, func(in.min_denormal, in.min_denormal), | ||
| FE_UNDERFLOW | FE_INEXACT); | ||
| EXPECT_MATH_ERRNO(ERANGE); | ||
| EXPECT_FP_EQ_WITH_EXCEPTION(neg_min_denormal, | ||
| func(in.neg_min_denormal, in.min_denormal), | ||
| FE_UNDERFLOW | FE_INEXACT); | ||
| EXPECT_MATH_ERRNO(ERANGE); | ||
| } | ||
|
|
||
| if (ForceRoundingMode r(RoundingMode::Upward); r.success) { | ||
| EXPECT_FP_EQ_WITH_EXCEPTION(inf, func(max_normal, max_normal), | ||
| FE_OVERFLOW | FE_INEXACT); | ||
| EXPECT_MATH_ERRNO(ERANGE); | ||
| EXPECT_FP_EQ_WITH_EXCEPTION(neg_max_normal, | ||
| func(neg_max_normal, max_normal), | ||
| FE_OVERFLOW | FE_INEXACT); | ||
|
|
||
| EXPECT_FP_EQ_WITH_EXCEPTION(min_denormal, | ||
| func(in.min_denormal, in.min_denormal), | ||
| FE_UNDERFLOW | FE_INEXACT); | ||
| EXPECT_MATH_ERRNO(ERANGE); | ||
| EXPECT_FP_EQ_WITH_EXCEPTION(neg_zero, | ||
| func(in.neg_min_denormal, in.min_denormal), | ||
| FE_UNDERFLOW | FE_INEXACT); | ||
| EXPECT_MATH_ERRNO(ERANGE); | ||
| } | ||
| } | ||
|
|
||
| void test_inexact_results(MulFunc func) { | ||
| InFPBits x_bits = InFPBits::one(); | ||
| x_bits.set_mantissa(InFPBits::SIG_MASK); | ||
| InType x = x_bits.get_val(); | ||
| func(x, x); | ||
| EXPECT_FP_EXCEPTION(FE_INEXACT); | ||
| } | ||
| }; | ||
|
|
||
| #define LIST_MUL_TESTS(OutType, InType, func) \ | ||
| using LlvmLibcMulTest = MulTest<OutType, InType>; \ | ||
| TEST_F(LlvmLibcMulTest, SpecialNumbers) { test_special_numbers(&func); } \ | ||
| TEST_F(LlvmLibcMulTest, InvalidOperations) { \ | ||
| test_invalid_operations(&func); \ | ||
| } \ | ||
| TEST_F(LlvmLibcMulTest, RangeErrors) { test_range_errors(&func); } \ | ||
| TEST_F(LlvmLibcMulTest, InexactResults) { test_inexact_results(&func); } | ||
|
|
||
| #endif // LLVM_LIBC_TEST_SRC_MATH_SMOKE_MULTEST_H |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| //===-- Unittests for dmulf128 --------------------------------------------===// | ||
| // | ||
| // 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 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "MulTest.h" | ||
|
|
||
| #include "src/math/dmulf128.h" | ||
|
|
||
| LIST_MUL_TESTS(double, float128, LIBC_NAMESPACE::dmulf128) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| //===-- Unittests for dmull -----------------------------------------------===// | ||
| // | ||
| // 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 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "MulTest.h" | ||
|
|
||
| #include "src/math/dmull.h" | ||
|
|
||
| LIST_MUL_TESTS(double, long double, LIBC_NAMESPACE::dmull) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| //===-- Unittests for f16mul ----------------------------------------------===// | ||
| // | ||
| // 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 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "MulTest.h" | ||
|
|
||
| #include "src/math/f16mul.h" | ||
|
|
||
| LIST_MUL_TESTS(float16, double, LIBC_NAMESPACE::f16mul) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| //===-- Unittests for f16mulf128 ------------------------------------------===// | ||
| // | ||
| // 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 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "MulTest.h" | ||
|
|
||
| #include "src/math/f16mulf128.h" | ||
|
|
||
| LIST_MUL_TESTS(float16, float128, LIBC_NAMESPACE::f16mulf128) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| //===-- Unittests for f16mulf ---------------------------------------------===// | ||
| // | ||
| // 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 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "MulTest.h" | ||
|
|
||
| #include "src/math/f16mulf.h" | ||
|
|
||
| LIST_MUL_TESTS(float16, float, LIBC_NAMESPACE::f16mulf) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| //===-- Unittests for f16mull ---------------------------------------------===// | ||
| // | ||
| // 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 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "MulTest.h" | ||
|
|
||
| #include "src/math/f16mull.h" | ||
|
|
||
| LIST_MUL_TESTS(float16, long double, LIBC_NAMESPACE::f16mull) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,13 @@ | ||
| //===-- Unittests for fmul ------------------------------------------------===// | ||
| // | ||
| // 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 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "MulTest.h" | ||
|
|
||
| #include "src/math/fmul.h" | ||
|
|
||
| LIST_MUL_TESTS(float, double, LIBC_NAMESPACE::fmul) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| //===-- Unittests for fmulf128 --------------------------------------------===// | ||
| // | ||
| // 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 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "MulTest.h" | ||
|
|
||
| #include "src/math/fmulf128.h" | ||
|
|
||
| LIST_MUL_TESTS(float, float128, LIBC_NAMESPACE::fmulf128) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| //===-- Unittests for fmull -----------------------------------------------===// | ||
| // | ||
| // 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 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "MulTest.h" | ||
|
|
||
| #include "src/math/fmull.h" | ||
|
|
||
| LIST_MUL_TESTS(float, long double, LIBC_NAMESPACE::fmull) |