Skip to content

Commit d467a96

Browse files
committed
[libc][math][c23] Add {lrint,llrint,lround,llround}f16 MPFR unit tests
1 parent 7ba9597 commit d467a96

File tree

6 files changed

+157
-24
lines changed

6 files changed

+157
-24
lines changed

libc/test/src/math/CMakeLists.txt

Lines changed: 92 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -440,11 +440,11 @@ add_fp_unittest(
440440
HDRS
441441
RoundToIntegerTest.h
442442
DEPENDS
443+
libc.hdr.fenv_macros
443444
libc.src.errno.errno
444-
libc.src.fenv.feclearexcept
445-
libc.src.fenv.feraiseexcept
446-
libc.src.fenv.fetestexcept
447445
libc.src.math.lround
446+
libc.src.__support.CPP.algorithm
447+
libc.src.__support.FPUtil.fenv_impl
448448
libc.src.__support.FPUtil.fp_bits
449449
)
450450

@@ -458,11 +458,11 @@ add_fp_unittest(
458458
HDRS
459459
RoundToIntegerTest.h
460460
DEPENDS
461+
libc.hdr.fenv_macros
461462
libc.src.errno.errno
462-
libc.src.fenv.feclearexcept
463-
libc.src.fenv.feraiseexcept
464-
libc.src.fenv.fetestexcept
465463
libc.src.math.lroundf
464+
libc.src.__support.CPP.algorithm
465+
libc.src.__support.FPUtil.fenv_impl
466466
libc.src.__support.FPUtil.fp_bits
467467
)
468468

@@ -476,11 +476,29 @@ add_fp_unittest(
476476
HDRS
477477
RoundToIntegerTest.h
478478
DEPENDS
479+
libc.hdr.fenv_macros
479480
libc.src.errno.errno
480-
libc.src.fenv.feclearexcept
481-
libc.src.fenv.feraiseexcept
482-
libc.src.fenv.fetestexcept
483481
libc.src.math.lroundl
482+
libc.src.__support.CPP.algorithm
483+
libc.src.__support.FPUtil.fenv_impl
484+
libc.src.__support.FPUtil.fp_bits
485+
)
486+
487+
add_fp_unittest(
488+
lroundf16_test
489+
NEED_MPFR
490+
SUITE
491+
libc-math-unittests
492+
SRCS
493+
lroundf16_test.cpp
494+
HDRS
495+
RoundToIntegerTest.h
496+
DEPENDS
497+
libc.hdr.fenv_macros
498+
libc.src.errno.errno
499+
libc.src.math.lroundf16
500+
libc.src.__support.CPP.algorithm
501+
libc.src.__support.FPUtil.fenv_impl
484502
libc.src.__support.FPUtil.fp_bits
485503
)
486504

@@ -494,11 +512,11 @@ add_fp_unittest(
494512
HDRS
495513
RoundToIntegerTest.h
496514
DEPENDS
515+
libc.hdr.fenv_macros
497516
libc.src.errno.errno
498-
libc.src.fenv.feclearexcept
499-
libc.src.fenv.feraiseexcept
500-
libc.src.fenv.fetestexcept
501517
libc.src.math.llround
518+
libc.src.__support.CPP.algorithm
519+
libc.src.__support.FPUtil.fenv_impl
502520
libc.src.__support.FPUtil.fp_bits
503521
)
504522

@@ -512,11 +530,11 @@ add_fp_unittest(
512530
HDRS
513531
RoundToIntegerTest.h
514532
DEPENDS
533+
libc.hdr.fenv_macros
515534
libc.src.errno.errno
516-
libc.src.fenv.feclearexcept
517-
libc.src.fenv.feraiseexcept
518-
libc.src.fenv.fetestexcept
519535
libc.src.math.llroundf
536+
libc.src.__support.CPP.algorithm
537+
libc.src.__support.FPUtil.fenv_impl
520538
libc.src.__support.FPUtil.fp_bits
521539
)
522540

@@ -530,11 +548,29 @@ add_fp_unittest(
530548
HDRS
531549
RoundToIntegerTest.h
532550
DEPENDS
551+
libc.hdr.fenv_macros
533552
libc.src.errno.errno
534-
libc.src.fenv.feclearexcept
535-
libc.src.fenv.feraiseexcept
536-
libc.src.fenv.fetestexcept
537553
libc.src.math.llroundl
554+
libc.src.__support.CPP.algorithm
555+
libc.src.__support.FPUtil.fenv_impl
556+
libc.src.__support.FPUtil.fp_bits
557+
)
558+
559+
add_fp_unittest(
560+
llroundf16_test
561+
NEED_MPFR
562+
SUITE
563+
libc-math-unittests
564+
SRCS
565+
llroundf16_test.cpp
566+
HDRS
567+
RoundToIntegerTest.h
568+
DEPENDS
569+
libc.hdr.fenv_macros
570+
libc.src.errno.errno
571+
libc.src.math.llroundf16
572+
libc.src.__support.CPP.algorithm
573+
libc.src.__support.FPUtil.fenv_impl
538574
libc.src.__support.FPUtil.fp_bits
539575
)
540576

@@ -613,6 +649,7 @@ add_fp_unittest(
613649
RoundToIntegerTest.h
614650
DEPENDS
615651
libc.src.math.lrint
652+
libc.src.__support.CPP.algorithm
616653
libc.src.__support.FPUtil.fenv_impl
617654
libc.src.__support.FPUtil.fp_bits
618655
)
@@ -628,6 +665,7 @@ add_fp_unittest(
628665
RoundToIntegerTest.h
629666
DEPENDS
630667
libc.src.math.lrintf
668+
libc.src.__support.CPP.algorithm
631669
libc.src.__support.FPUtil.fenv_impl
632670
libc.src.__support.FPUtil.fp_bits
633671
)
@@ -643,6 +681,23 @@ add_fp_unittest(
643681
RoundToIntegerTest.h
644682
DEPENDS
645683
libc.src.math.lrintl
684+
libc.src.__support.CPP.algorithm
685+
libc.src.__support.FPUtil.fenv_impl
686+
libc.src.__support.FPUtil.fp_bits
687+
)
688+
689+
add_fp_unittest(
690+
lrintf16_test
691+
NEED_MPFR
692+
SUITE
693+
libc-math-unittests
694+
SRCS
695+
lrintf16_test.cpp
696+
HDRS
697+
RoundToIntegerTest.h
698+
DEPENDS
699+
libc.src.math.lrintf16
700+
libc.src.__support.CPP.algorithm
646701
libc.src.__support.FPUtil.fenv_impl
647702
libc.src.__support.FPUtil.fp_bits
648703
)
@@ -658,6 +713,7 @@ add_fp_unittest(
658713
RoundToIntegerTest.h
659714
DEPENDS
660715
libc.src.math.llrint
716+
libc.src.__support.CPP.algorithm
661717
libc.src.__support.FPUtil.fenv_impl
662718
libc.src.__support.FPUtil.fp_bits
663719
)
@@ -673,6 +729,7 @@ add_fp_unittest(
673729
RoundToIntegerTest.h
674730
DEPENDS
675731
libc.src.math.llrintf
732+
libc.src.__support.CPP.algorithm
676733
libc.src.__support.FPUtil.fenv_impl
677734
libc.src.__support.FPUtil.fp_bits
678735
)
@@ -688,6 +745,23 @@ add_fp_unittest(
688745
RoundToIntegerTest.h
689746
DEPENDS
690747
libc.src.math.llrintl
748+
libc.src.__support.CPP.algorithm
749+
libc.src.__support.FPUtil.fenv_impl
750+
libc.src.__support.FPUtil.fp_bits
751+
)
752+
753+
add_fp_unittest(
754+
llrintf16_test
755+
NEED_MPFR
756+
SUITE
757+
libc-math-unittests
758+
SRCS
759+
llrintf16_test.cpp
760+
HDRS
761+
RoundToIntegerTest.h
762+
DEPENDS
763+
libc.src.math.llrintf16
764+
libc.src.__support.CPP.algorithm
691765
libc.src.__support.FPUtil.fenv_impl
692766
libc.src.__support.FPUtil.fp_bits
693767
)

libc/test/src/math/RoundToIntegerTest.h

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#ifndef LLVM_LIBC_TEST_SRC_MATH_ROUNDTOINTEGERTEST_H
1010
#define LLVM_LIBC_TEST_SRC_MATH_ROUNDTOINTEGERTEST_H
1111

12+
#include "src/__support/CPP/algorithm.h"
1213
#include "src/__support/FPUtil/FEnvImpl.h"
1314
#include "src/__support/FPUtil/FPBits.h"
1415
#include "test/UnitTest/FEnvSafeTest.h"
@@ -226,8 +227,10 @@ class RoundToIntegerTestTemplate
226227
}
227228

228229
void testSubnormalRange(RoundToIntegerFunc func) {
229-
constexpr StorageType COUNT = 1'000'001;
230-
constexpr StorageType STEP = (MAX_SUBNORMAL - MIN_SUBNORMAL) / COUNT;
230+
constexpr int COUNT = 1'000'001;
231+
constexpr StorageType STEP = LIBC_NAMESPACE::cpp::max(
232+
static_cast<StorageType>((MAX_SUBNORMAL - MIN_SUBNORMAL) / COUNT),
233+
StorageType(1));
231234
for (StorageType i = MIN_SUBNORMAL; i <= MAX_SUBNORMAL; i += STEP) {
232235
F x = FPBits(i).get_val();
233236
if (x == F(0.0))
@@ -268,13 +271,16 @@ class RoundToIntegerTestTemplate
268271
if (sizeof(I) > sizeof(long))
269272
return;
270273

271-
constexpr StorageType COUNT = 1'000'001;
272-
constexpr StorageType STEP = (MAX_NORMAL - MIN_NORMAL) / COUNT;
274+
constexpr int COUNT = 1'000'001;
275+
constexpr StorageType STEP = LIBC_NAMESPACE::cpp::max(
276+
static_cast<StorageType>((MAX_NORMAL - MIN_NORMAL) / COUNT),
277+
StorageType(1));
273278
for (StorageType i = MIN_NORMAL; i <= MAX_NORMAL; i += STEP) {
274-
F x = FPBits(i).get_val();
279+
FPBits xbits(i);
280+
F x = xbits.get_val();
275281
// In normal range on x86 platforms, the long double implicit 1 bit can be
276282
// zero making the numbers NaN. We will skip them.
277-
if (isnan(x)) {
283+
if (xbits.is_nan()) {
278284
continue;
279285
}
280286

libc/test/src/math/llrintf16_test.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//===-- Unittests for llrintf16 -------------------------------------------===//
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-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "RoundToIntegerTest.h"
10+
11+
#include "src/math/llrintf16.h"
12+
13+
LIST_ROUND_TO_INTEGER_TESTS_WITH_MODES(float16, long long,
14+
LIBC_NAMESPACE::llrintf16)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//===-- Unittests for llroundf16 ------------------------------------------===//
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-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "RoundToIntegerTest.h"
10+
11+
#include "src/math/llroundf16.h"
12+
13+
LIST_ROUND_TO_INTEGER_TESTS(float16, long long, LIBC_NAMESPACE::llroundf16)

libc/test/src/math/lrintf16_test.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//===-- Unittests for lrintf16 --------------------------------------------===//
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-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "RoundToIntegerTest.h"
10+
11+
#include "src/math/lrintf16.h"
12+
13+
LIST_ROUND_TO_INTEGER_TESTS_WITH_MODES(float16, long, LIBC_NAMESPACE::lrintf16)

libc/test/src/math/lroundf16_test.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//===-- Unittests for lroundf16 -------------------------------------------===//
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-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "RoundToIntegerTest.h"
10+
11+
#include "src/math/lroundf16.h"
12+
13+
LIST_ROUND_TO_INTEGER_TESTS(float16, long, LIBC_NAMESPACE::lroundf16)

0 commit comments

Comments
 (0)