Skip to content

Commit ea477a6

Browse files
committed
Merge branch 'libc-math-rintf16-mpfr-tests' into libc-math-nearbyintf16-mpfr-tests
2 parents a0cdd32 + 8492b25 commit ea477a6

File tree

9 files changed

+263
-39
lines changed

9 files changed

+263
-39
lines changed

libc/test/src/math/CMakeLists.txt

Lines changed: 115 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -350,11 +350,11 @@ add_fp_unittest(
350350
HDRS
351351
RoundToIntegerTest.h
352352
DEPENDS
353+
libc.hdr.fenv_macros
353354
libc.src.errno.errno
354-
libc.src.fenv.feclearexcept
355-
libc.src.fenv.feraiseexcept
356-
libc.src.fenv.fetestexcept
357355
libc.src.math.lround
356+
libc.src.__support.CPP.algorithm
357+
libc.src.__support.FPUtil.fenv_impl
358358
libc.src.__support.FPUtil.fp_bits
359359
)
360360

@@ -368,11 +368,11 @@ add_fp_unittest(
368368
HDRS
369369
RoundToIntegerTest.h
370370
DEPENDS
371+
libc.hdr.fenv_macros
371372
libc.src.errno.errno
372-
libc.src.fenv.feclearexcept
373-
libc.src.fenv.feraiseexcept
374-
libc.src.fenv.fetestexcept
375373
libc.src.math.lroundf
374+
libc.src.__support.CPP.algorithm
375+
libc.src.__support.FPUtil.fenv_impl
376376
libc.src.__support.FPUtil.fp_bits
377377
)
378378

@@ -386,11 +386,29 @@ add_fp_unittest(
386386
HDRS
387387
RoundToIntegerTest.h
388388
DEPENDS
389+
libc.hdr.fenv_macros
389390
libc.src.errno.errno
390-
libc.src.fenv.feclearexcept
391-
libc.src.fenv.feraiseexcept
392-
libc.src.fenv.fetestexcept
393391
libc.src.math.lroundl
392+
libc.src.__support.CPP.algorithm
393+
libc.src.__support.FPUtil.fenv_impl
394+
libc.src.__support.FPUtil.fp_bits
395+
)
396+
397+
add_fp_unittest(
398+
lroundf16_test
399+
NEED_MPFR
400+
SUITE
401+
libc-math-unittests
402+
SRCS
403+
lroundf16_test.cpp
404+
HDRS
405+
RoundToIntegerTest.h
406+
DEPENDS
407+
libc.hdr.fenv_macros
408+
libc.src.errno.errno
409+
libc.src.math.lroundf16
410+
libc.src.__support.CPP.algorithm
411+
libc.src.__support.FPUtil.fenv_impl
394412
libc.src.__support.FPUtil.fp_bits
395413
)
396414

@@ -404,11 +422,11 @@ add_fp_unittest(
404422
HDRS
405423
RoundToIntegerTest.h
406424
DEPENDS
425+
libc.hdr.fenv_macros
407426
libc.src.errno.errno
408-
libc.src.fenv.feclearexcept
409-
libc.src.fenv.feraiseexcept
410-
libc.src.fenv.fetestexcept
411427
libc.src.math.llround
428+
libc.src.__support.CPP.algorithm
429+
libc.src.__support.FPUtil.fenv_impl
412430
libc.src.__support.FPUtil.fp_bits
413431
)
414432

@@ -422,11 +440,11 @@ add_fp_unittest(
422440
HDRS
423441
RoundToIntegerTest.h
424442
DEPENDS
443+
libc.hdr.fenv_macros
425444
libc.src.errno.errno
426-
libc.src.fenv.feclearexcept
427-
libc.src.fenv.feraiseexcept
428-
libc.src.fenv.fetestexcept
429445
libc.src.math.llroundf
446+
libc.src.__support.CPP.algorithm
447+
libc.src.__support.FPUtil.fenv_impl
430448
libc.src.__support.FPUtil.fp_bits
431449
)
432450

@@ -440,11 +458,29 @@ add_fp_unittest(
440458
HDRS
441459
RoundToIntegerTest.h
442460
DEPENDS
461+
libc.hdr.fenv_macros
443462
libc.src.errno.errno
444-
libc.src.fenv.feclearexcept
445-
libc.src.fenv.feraiseexcept
446-
libc.src.fenv.fetestexcept
447463
libc.src.math.llroundl
464+
libc.src.__support.CPP.algorithm
465+
libc.src.__support.FPUtil.fenv_impl
466+
libc.src.__support.FPUtil.fp_bits
467+
)
468+
469+
add_fp_unittest(
470+
llroundf16_test
471+
NEED_MPFR
472+
SUITE
473+
libc-math-unittests
474+
SRCS
475+
llroundf16_test.cpp
476+
HDRS
477+
RoundToIntegerTest.h
478+
DEPENDS
479+
libc.hdr.fenv_macros
480+
libc.src.errno.errno
481+
libc.src.math.llroundf16
482+
libc.src.__support.CPP.algorithm
483+
libc.src.__support.FPUtil.fenv_impl
448484
libc.src.__support.FPUtil.fp_bits
449485
)
450486

@@ -458,7 +494,9 @@ add_fp_unittest(
458494
HDRS
459495
RIntTest.h
460496
DEPENDS
497+
libc.hdr.fenv_macros
461498
libc.src.math.rint
499+
libc.src.__support.CPP.algorithm
462500
libc.src.__support.FPUtil.fenv_impl
463501
libc.src.__support.FPUtil.fp_bits
464502
)
@@ -473,7 +511,9 @@ add_fp_unittest(
473511
HDRS
474512
RIntTest.h
475513
DEPENDS
514+
libc.hdr.fenv_macros
476515
libc.src.math.rintf
516+
libc.src.__support.CPP.algorithm
477517
libc.src.__support.FPUtil.fenv_impl
478518
libc.src.__support.FPUtil.fp_bits
479519
)
@@ -488,7 +528,26 @@ add_fp_unittest(
488528
HDRS
489529
RIntTest.h
490530
DEPENDS
531+
libc.hdr.fenv_macros
491532
libc.src.math.rintl
533+
libc.src.__support.CPP.algorithm
534+
libc.src.__support.FPUtil.fenv_impl
535+
libc.src.__support.FPUtil.fp_bits
536+
)
537+
538+
add_fp_unittest(
539+
rintf16_test
540+
NEED_MPFR
541+
SUITE
542+
libc-math-unittests
543+
SRCS
544+
rintf16_test.cpp
545+
HDRS
546+
RIntTest.h
547+
DEPENDS
548+
libc.hdr.fenv_macros
549+
libc.src.math.rintf16
550+
libc.src.__support.CPP.algorithm
492551
libc.src.__support.FPUtil.fenv_impl
493552
libc.src.__support.FPUtil.fp_bits
494553
)
@@ -504,6 +563,7 @@ add_fp_unittest(
504563
RoundToIntegerTest.h
505564
DEPENDS
506565
libc.src.math.lrint
566+
libc.src.__support.CPP.algorithm
507567
libc.src.__support.FPUtil.fenv_impl
508568
libc.src.__support.FPUtil.fp_bits
509569
)
@@ -519,6 +579,7 @@ add_fp_unittest(
519579
RoundToIntegerTest.h
520580
DEPENDS
521581
libc.src.math.lrintf
582+
libc.src.__support.CPP.algorithm
522583
libc.src.__support.FPUtil.fenv_impl
523584
libc.src.__support.FPUtil.fp_bits
524585
)
@@ -534,6 +595,23 @@ add_fp_unittest(
534595
RoundToIntegerTest.h
535596
DEPENDS
536597
libc.src.math.lrintl
598+
libc.src.__support.CPP.algorithm
599+
libc.src.__support.FPUtil.fenv_impl
600+
libc.src.__support.FPUtil.fp_bits
601+
)
602+
603+
add_fp_unittest(
604+
lrintf16_test
605+
NEED_MPFR
606+
SUITE
607+
libc-math-unittests
608+
SRCS
609+
lrintf16_test.cpp
610+
HDRS
611+
RoundToIntegerTest.h
612+
DEPENDS
613+
libc.src.math.lrintf16
614+
libc.src.__support.CPP.algorithm
537615
libc.src.__support.FPUtil.fenv_impl
538616
libc.src.__support.FPUtil.fp_bits
539617
)
@@ -549,6 +627,7 @@ add_fp_unittest(
549627
RoundToIntegerTest.h
550628
DEPENDS
551629
libc.src.math.llrint
630+
libc.src.__support.CPP.algorithm
552631
libc.src.__support.FPUtil.fenv_impl
553632
libc.src.__support.FPUtil.fp_bits
554633
)
@@ -564,6 +643,7 @@ add_fp_unittest(
564643
RoundToIntegerTest.h
565644
DEPENDS
566645
libc.src.math.llrintf
646+
libc.src.__support.CPP.algorithm
567647
libc.src.__support.FPUtil.fenv_impl
568648
libc.src.__support.FPUtil.fp_bits
569649
)
@@ -579,6 +659,23 @@ add_fp_unittest(
579659
RoundToIntegerTest.h
580660
DEPENDS
581661
libc.src.math.llrintl
662+
libc.src.__support.CPP.algorithm
663+
libc.src.__support.FPUtil.fenv_impl
664+
libc.src.__support.FPUtil.fp_bits
665+
)
666+
667+
add_fp_unittest(
668+
llrintf16_test
669+
NEED_MPFR
670+
SUITE
671+
libc-math-unittests
672+
SRCS
673+
llrintf16_test.cpp
674+
HDRS
675+
RoundToIntegerTest.h
676+
DEPENDS
677+
libc.src.math.llrintf16
678+
libc.src.__support.CPP.algorithm
582679
libc.src.__support.FPUtil.fenv_impl
583680
libc.src.__support.FPUtil.fp_bits
584681
)

libc/test/src/math/RIntTest.h

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#ifndef LLVM_LIBC_TEST_SRC_MATH_RINTTEST_H
1010
#define LLVM_LIBC_TEST_SRC_MATH_RINTTEST_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"
@@ -18,7 +19,6 @@
1819

1920
#include "hdr/fenv_macros.h"
2021
#include "hdr/math_macros.h"
21-
#include <stdio.h>
2222

2323
namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
2424

@@ -101,8 +101,10 @@ class RIntTestTemplate : public LIBC_NAMESPACE::testing::FEnvSafeTest {
101101
}
102102

103103
void testSubnormalRange(RIntFunc func) {
104-
constexpr StorageType COUNT = 100'001;
105-
constexpr StorageType STEP = (MAX_SUBNORMAL - MIN_SUBNORMAL) / COUNT;
104+
constexpr int COUNT = 100'001;
105+
constexpr StorageType STEP = LIBC_NAMESPACE::cpp::max(
106+
static_cast<StorageType>((MAX_SUBNORMAL - MIN_SUBNORMAL) / COUNT),
107+
StorageType(1));
106108
for (StorageType i = MIN_SUBNORMAL; i <= MAX_SUBNORMAL; i += STEP) {
107109
T x = FPBits(i).get_val();
108110
for (int mode : ROUNDING_MODES) {
@@ -114,15 +116,17 @@ class RIntTestTemplate : public LIBC_NAMESPACE::testing::FEnvSafeTest {
114116
}
115117

116118
void testNormalRange(RIntFunc func) {
117-
constexpr StorageType COUNT = 100'001;
118-
constexpr StorageType STEP = (MAX_NORMAL - MIN_NORMAL) / COUNT;
119+
constexpr int COUNT = 100'001;
120+
constexpr StorageType STEP = LIBC_NAMESPACE::cpp::max(
121+
static_cast<StorageType>((MAX_NORMAL - MIN_NORMAL) / COUNT),
122+
StorageType(1));
119123
for (StorageType i = MIN_NORMAL; i <= MAX_NORMAL; i += STEP) {
120-
T x = FPBits(i).get_val();
124+
FPBits xbits(i);
125+
T x = xbits.get_val();
121126
// In normal range on x86 platforms, the long double implicit 1 bit can be
122127
// zero making the numbers NaN. We will skip them.
123-
if (isnan(x)) {
128+
if (xbits.is_nan())
124129
continue;
125-
}
126130

127131
for (int mode : ROUNDING_MODES) {
128132
LIBC_NAMESPACE::fputil::set_round(mode);

libc/test/src/math/RoundToIntegerTest.h

Lines changed: 20 additions & 9 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"
@@ -136,10 +137,13 @@ class RoundToIntegerTestTemplate
136137
return;
137138

138139
constexpr int EXPONENT_LIMIT = sizeof(I) * 8 - 1;
140+
constexpr int BIASED_EXPONENT_LIMIT = EXPONENT_LIMIT + FPBits::EXP_BIAS;
141+
if (BIASED_EXPONENT_LIMIT > FPBits::MAX_BIASED_EXPONENT)
142+
return;
139143
// We start with 1.0 so that the implicit bit for x86 long doubles
140144
// is set.
141145
FPBits bits(F(1.0));
142-
bits.set_biased_exponent(EXPONENT_LIMIT + FPBits::EXP_BIAS);
146+
bits.set_biased_exponent(BIASED_EXPONENT_LIMIT);
143147
bits.set_sign(Sign::NEG);
144148
bits.set_mantissa(0);
145149

@@ -200,10 +204,13 @@ class RoundToIntegerTestTemplate
200204
return;
201205

202206
constexpr int EXPONENT_LIMIT = sizeof(I) * 8 - 1;
207+
constexpr int BIASED_EXPONENT_LIMIT = EXPONENT_LIMIT + FPBits::EXP_BIAS;
208+
if (BIASED_EXPONENT_LIMIT > FPBits::MAX_BIASED_EXPONENT)
209+
return;
203210
// We start with 1.0 so that the implicit bit for x86 long doubles
204211
// is set.
205212
FPBits bits(F(1.0));
206-
bits.set_biased_exponent(EXPONENT_LIMIT + FPBits::EXP_BIAS);
213+
bits.set_biased_exponent(BIASED_EXPONENT_LIMIT);
207214
bits.set_sign(Sign::NEG);
208215
bits.set_mantissa(FPBits::FRACTION_MASK);
209216

@@ -226,8 +233,10 @@ class RoundToIntegerTestTemplate
226233
}
227234

228235
void testSubnormalRange(RoundToIntegerFunc func) {
229-
constexpr StorageType COUNT = 1'000'001;
230-
constexpr StorageType STEP = (MAX_SUBNORMAL - MIN_SUBNORMAL) / COUNT;
236+
constexpr int COUNT = 1'000'001;
237+
constexpr StorageType STEP = LIBC_NAMESPACE::cpp::max(
238+
static_cast<StorageType>((MAX_SUBNORMAL - MIN_SUBNORMAL) / COUNT),
239+
StorageType(1));
231240
for (StorageType i = MIN_SUBNORMAL; i <= MAX_SUBNORMAL; i += STEP) {
232241
F x = FPBits(i).get_val();
233242
if (x == F(0.0))
@@ -268,15 +277,17 @@ class RoundToIntegerTestTemplate
268277
if (sizeof(I) > sizeof(long))
269278
return;
270279

271-
constexpr StorageType COUNT = 1'000'001;
272-
constexpr StorageType STEP = (MAX_NORMAL - MIN_NORMAL) / COUNT;
280+
constexpr int COUNT = 1'000'001;
281+
constexpr StorageType STEP = LIBC_NAMESPACE::cpp::max(
282+
static_cast<StorageType>((MAX_NORMAL - MIN_NORMAL) / COUNT),
283+
StorageType(1));
273284
for (StorageType i = MIN_NORMAL; i <= MAX_NORMAL; i += STEP) {
274-
F x = FPBits(i).get_val();
285+
FPBits xbits(i);
286+
F x = xbits.get_val();
275287
// In normal range on x86 platforms, the long double implicit 1 bit can be
276288
// zero making the numbers NaN. We will skip them.
277-
if (isnan(x)) {
289+
if (xbits.is_nan())
278290
continue;
279-
}
280291

281292
if (TestModes) {
282293
for (int m : ROUNDING_MODES) {

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)

0 commit comments

Comments
 (0)