brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.4 KiB · a822fc4 Raw
69 lines · cpp
1//===-- Exhaustive test for hypotf16 --------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#include "exhaustive_test.h"10#include "src/__support/FPUtil/FPBits.h"11#include "src/__support/FPUtil/Hypot.h"12#include "src/math/hypotf16.h"13#include "test/UnitTest/FPMatcher.h"14#include "utils/MPFRWrapper/MPFRUtils.h"15 16namespace mpfr = LIBC_NAMESPACE::testing::mpfr;17 18struct Hypotf16Checker : public virtual LIBC_NAMESPACE::testing::Test {19  using FloatType = float16;20  using FPBits = LIBC_NAMESPACE::fputil::FPBits<float16>;21  using StorageType = typename FPBits::StorageType;22 23  uint64_t check(uint16_t x_start, uint16_t x_stop,24                 [[maybe_unused]] uint16_t y_start, uint16_t y_stop,25                 mpfr::RoundingMode rounding) {26    mpfr::ForceRoundingMode r(rounding);27    if (!r.success)28      return true;29    uint16_t xbits = x_start;30    uint64_t failed = 0;31    do {32      float16 x = FPBits(xbits).get_val();33      uint16_t ybits = xbits;34      do {35        float16 y = FPBits(ybits).get_val();36        bool correct = TEST_FP_EQ(LIBC_NAMESPACE::fputil::hypot<float16>(x, y),37                                  LIBC_NAMESPACE::hypotf16(x, y));38        // Using MPFR will be much slower.39        // mpfr::BinaryInput<float16> input{x, y};40        // bool correct = TEST_MPFR_MATCH_ROUNDING_SILENTLY(41        //  mpfr::Operation::Hypot, input, LIBC_NAMESPACE::hypotf16(x, y),42        // 0.5,43        //  rounding);44        failed += (!correct);45      } while (ybits++ < y_stop);46    } while (xbits++ < x_stop);47    return failed;48  }49};50 51using LlvmLibcHypotf16ExhaustiveTest =52    LlvmLibcExhaustiveMathTest<Hypotf16Checker, 1 << 2>;53 54// Range of both inputs: [0, inf]55static constexpr uint16_t POS_START = 0x0000U;56static constexpr uint16_t POS_STOP = 0x7C00U;57 58TEST_F(LlvmLibcHypotf16ExhaustiveTest, PositiveRange) {59  test_full_range_all_roundings(POS_START, POS_STOP, POS_START, POS_STOP);60}61 62// Range of both inputs: [-0, -inf]63static constexpr uint16_t NEG_START = 0x8000U;64static constexpr uint16_t NEG_STOP = 0xFC00U;65 66TEST_F(LlvmLibcHypotf16ExhaustiveTest, NegativeRange) {67  test_full_range_all_roundings(NEG_START, NEG_STOP, NEG_START, NEG_STOP);68}69