brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.4 KiB · d01c3f9 Raw
44 lines · cpp
1//===-- Exhaustive test for rsqrtf16 --------------------------------------===//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 "src/math/rsqrtf16.h"10#include "test/UnitTest/FPMatcher.h"11#include "test/UnitTest/Test.h"12#include "utils/MPFRWrapper/MPFRUtils.h"13 14using LlvmLibcRsqrtf16Test = LIBC_NAMESPACE::testing::FPTest<float16>;15 16namespace mpfr = LIBC_NAMESPACE::testing::mpfr;17 18// Range: [0, Inf]19static constexpr uint16_t POS_START = 0x0000U;20static constexpr uint16_t POS_STOP = 0x7c00U;21 22// Range: [-Inf, 0)23// rsqrt(-0.0) is -inf, not the same for mpfr.24static constexpr uint16_t NEG_START = 0x8001U;25static constexpr uint16_t NEG_STOP = 0xfc00U;26 27TEST_F(LlvmLibcRsqrtf16Test, PositiveRange) {28  for (uint16_t v = POS_START; v <= POS_STOP; ++v) {29    float16 x = FPBits(v).get_val();30 31    EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Rsqrt, x,32                                   LIBC_NAMESPACE::rsqrtf16(x), 0.5);33  }34}35 36TEST_F(LlvmLibcRsqrtf16Test, NegativeRange) {37  for (uint16_t v = NEG_START; v <= NEG_STOP; ++v) {38    float16 x = FPBits(v).get_val();39 40    EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Rsqrt, x,41                                   LIBC_NAMESPACE::rsqrtf16(x), 0.5);42  }43}44