164721a33STue Ly //===-- Exhaustive test for exp2f -----------------------------------------===// 264721a33STue Ly // 364721a33STue Ly // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 464721a33STue Ly // See https://llvm.org/LICENSE.txt for license information. 564721a33STue Ly // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 664721a33STue Ly // 764721a33STue Ly //===----------------------------------------------------------------------===// 864721a33STue Ly 964721a33STue Ly #include "exhaustive_test.h" 1064721a33STue Ly #include "src/__support/FPUtil/FPBits.h" 1164721a33STue Ly #include "src/math/exp2f.h" 1264721a33STue Ly #include "utils/MPFRWrapper/MPFRUtils.h" 1364721a33STue Ly #include "utils/UnitTest/FPMatcher.h" 1464721a33STue Ly 1564721a33STue Ly using FPBits = __llvm_libc::fputil::FPBits<float>; 1664721a33STue Ly 1764721a33STue Ly namespace mpfr = __llvm_libc::testing::mpfr; 1864721a33STue Ly 1964721a33STue Ly struct LlvmLibcExp2fExhaustiveTest : public LlvmLibcExhaustiveTest<uint32_t> { 20*4c9bfec6STue Ly bool check(uint32_t start, uint32_t stop, 2164721a33STue Ly mpfr::RoundingMode rounding) override { 2264721a33STue Ly mpfr::ForceRoundingMode r(rounding); 2364721a33STue Ly uint32_t bits = start; 24*4c9bfec6STue Ly bool result = true; 2564721a33STue Ly do { 2664721a33STue Ly FPBits xbits(bits); 2764721a33STue Ly float x = float(xbits); 28*4c9bfec6STue Ly result &= EXPECT_MPFR_MATCH(mpfr::Operation::Exp2, x, 29*4c9bfec6STue Ly __llvm_libc::exp2f(x), 0.5, rounding); 3064721a33STue Ly } while (bits++ < stop); 31*4c9bfec6STue Ly return result; 3264721a33STue Ly } 3364721a33STue Ly }; 3464721a33STue Ly 3564721a33STue Ly static constexpr int NUM_THREADS = 16; 3664721a33STue Ly 3764721a33STue Ly // Range: [0, 128]; 3864721a33STue Ly static constexpr uint32_t POS_START = 0x0000'0000U; 3964721a33STue Ly static constexpr uint32_t POS_STOP = 0x4300'0000U; 4064721a33STue Ly 4164721a33STue Ly TEST_F(LlvmLibcExp2fExhaustiveTest, PostiveRangeRoundNearestTieToEven) { 4264721a33STue Ly test_full_range(POS_START, POS_STOP, NUM_THREADS, 4364721a33STue Ly mpfr::RoundingMode::Nearest); 4464721a33STue Ly } 4564721a33STue Ly 4664721a33STue Ly TEST_F(LlvmLibcExp2fExhaustiveTest, PostiveRangeRoundUp) { 4764721a33STue Ly test_full_range(POS_START, POS_STOP, NUM_THREADS, mpfr::RoundingMode::Upward); 4864721a33STue Ly } 4964721a33STue Ly 5064721a33STue Ly TEST_F(LlvmLibcExp2fExhaustiveTest, PostiveRangeRoundDown) { 5164721a33STue Ly test_full_range(POS_START, POS_STOP, NUM_THREADS, 5264721a33STue Ly mpfr::RoundingMode::Downward); 5364721a33STue Ly } 5464721a33STue Ly 5564721a33STue Ly TEST_F(LlvmLibcExp2fExhaustiveTest, PostiveRangeRoundTowardZero) { 5664721a33STue Ly test_full_range(POS_START, POS_STOP, NUM_THREADS, 5764721a33STue Ly mpfr::RoundingMode::TowardZero); 5864721a33STue Ly } 5964721a33STue Ly 6064721a33STue Ly // Range: [-150, 0]; 6164721a33STue Ly static constexpr uint32_t NEG_START = 0x8000'0000U; 6264721a33STue Ly static constexpr uint32_t NEG_STOP = 0xc316'0000U; 6364721a33STue Ly 6464721a33STue Ly TEST_F(LlvmLibcExp2fExhaustiveTest, NegativeRangeRoundNearestTieToEven) { 6564721a33STue Ly test_full_range(NEG_START, NEG_STOP, NUM_THREADS, 6664721a33STue Ly mpfr::RoundingMode::Nearest); 6764721a33STue Ly } 6864721a33STue Ly 6964721a33STue Ly TEST_F(LlvmLibcExp2fExhaustiveTest, NegativeRangeRoundUp) { 7064721a33STue Ly test_full_range(NEG_START, NEG_STOP, NUM_THREADS, mpfr::RoundingMode::Upward); 7164721a33STue Ly } 7264721a33STue Ly 7364721a33STue Ly TEST_F(LlvmLibcExp2fExhaustiveTest, NegativeRangeRoundDown) { 7464721a33STue Ly test_full_range(NEG_START, NEG_STOP, NUM_THREADS, 7564721a33STue Ly mpfr::RoundingMode::Downward); 7664721a33STue Ly } 7764721a33STue Ly 7864721a33STue Ly TEST_F(LlvmLibcExp2fExhaustiveTest, NegativeRangeRoundTowardZero) { 7964721a33STue Ly test_full_range(NEG_START, NEG_STOP, NUM_THREADS, 8064721a33STue Ly mpfr::RoundingMode::TowardZero); 8164721a33STue Ly } 82