| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| //===-- Utility class to test fixed-point abs -------------------*- 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 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "test/UnitTest/Test.h" | ||
|
|
||
| #include "src/__support/fixed_point/fx_rep.h" | ||
|
|
||
| template <typename T> class AbsTest : public LIBC_NAMESPACE::testing::Test { | ||
|
|
||
| using FXRep = LIBC_NAMESPACE::fixed_point::FXRep<T>; | ||
| static constexpr T zero = FXRep::ZERO(); | ||
| static constexpr T min = FXRep::MIN(); | ||
| static constexpr T max = FXRep::MAX(); | ||
| static constexpr T half = static_cast<T>(0.5); | ||
| static constexpr T neg_half = static_cast<T>(-0.5); | ||
|
|
||
| public: | ||
| typedef T (*AbsFunc)(T); | ||
|
|
||
| void testSpecialNumbers(AbsFunc func) { | ||
| EXPECT_EQ(zero, func(zero)); | ||
| EXPECT_EQ(max, func(min)); | ||
| EXPECT_EQ(max, func(max)); | ||
| EXPECT_EQ(half, func(half)); | ||
| EXPECT_EQ(half, func(neg_half)); | ||
| } | ||
| }; | ||
|
|
||
| #define LIST_ABS_TESTS(T, func) \ | ||
| using LlvmLibcAbsTest = AbsTest<T>; \ | ||
| TEST_F(LlvmLibcAbsTest, SpecialNumbers) { testSpecialNumbers(&func); } \ | ||
| static_assert(true, "Require semicolon.") |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| if(NOT LIBC_COMPILER_HAS_FIXED_POINT) | ||
| return() | ||
| endif() | ||
|
|
||
| add_custom_target(libc-stdfix-tests) | ||
|
|
||
| foreach(suffix IN ITEMS hr r lr hk k lk) | ||
| add_libc_test( | ||
| abs${suffix}_test | ||
| SUITE | ||
| libc-stdfix-tests | ||
| HDRS | ||
| AbsTest.h | ||
| SRCS | ||
| abs${suffix}_test.cpp | ||
| COMPILE_OPTIONS | ||
| -O3 | ||
| -ffixed-point | ||
| DEPENDS | ||
| libc.src.stdfix.abs${suffix} | ||
| libc.src.__support.fixed_point.fx_bits | ||
| ) | ||
| endforeach() |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| //===-- Unittests for abshk -----------------------------------------------===// | ||
| // | ||
| // 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 "AbsTest.h" | ||
|
|
||
| #include "src/stdfix/abshk.h" | ||
|
|
||
| LIST_ABS_TESTS(short accum, LIBC_NAMESPACE::abshk); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| //===-- Unittests for abshr -----------------------------------------------===// | ||
| // | ||
| // 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 "AbsTest.h" | ||
|
|
||
| #include "src/stdfix/abshr.h" | ||
|
|
||
| LIST_ABS_TESTS(short fract, LIBC_NAMESPACE::abshr); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| //===-- Unittests for absk ------------------------------------------------===// | ||
| // | ||
| // 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 "AbsTest.h" | ||
|
|
||
| #include "src/stdfix/absk.h" | ||
|
|
||
| LIST_ABS_TESTS(accum, LIBC_NAMESPACE::absk); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| //===-- Unittests for abslk -----------------------------------------------===// | ||
| // | ||
| // 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 "AbsTest.h" | ||
|
|
||
| #include "src/stdfix/abslk.h" | ||
|
|
||
| LIST_ABS_TESTS(long accum, LIBC_NAMESPACE::abslk); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| //===-- Unittests for abslr -----------------------------------------------===// | ||
| // | ||
| // 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 "AbsTest.h" | ||
|
|
||
| #include "src/stdfix/abslr.h" | ||
|
|
||
| LIST_ABS_TESTS(long fract, LIBC_NAMESPACE::abslr); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| //===-- Unittests for absr ------------------------------------------------===// | ||
| // | ||
| // 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 "AbsTest.h" | ||
|
|
||
| #include "src/stdfix/absr.h" | ||
|
|
||
| LIST_ABS_TESTS(fract, LIBC_NAMESPACE::absr); |