Skip to content

Commit 91623a2

Browse files
committed
[libc][math][c23] Add lroundf16 C23 math function
1 parent fea9c3a commit 91623a2

File tree

10 files changed

+104
-25
lines changed

10 files changed

+104
-25
lines changed

libc/config/linux/aarch64/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
502502
libc.src.math.fabsf16
503503
libc.src.math.llrintf16
504504
libc.src.math.lrintf16
505+
libc.src.math.lroundf16
505506
libc.src.math.nearbyintf16
506507
libc.src.math.rintf16
507508
)

libc/config/linux/x86_64/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
535535
libc.src.math.fabsf16
536536
libc.src.math.llrintf16
537537
libc.src.math.lrintf16
538+
libc.src.math.lroundf16
538539
libc.src.math.nearbyintf16
539540
libc.src.math.rintf16
540541
)

libc/docs/math/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ Basic Operations
182182
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
183183
| lrint | |check| | |check| | |check| | |check| | |check| | 7.12.9.5 | F.10.6.5 |
184184
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
185-
| lround | |check| | |check| | |check| | | |check| | 7.12.9.7 | F.10.6.7 |
185+
| lround | |check| | |check| | |check| | |check| | |check| | 7.12.9.7 | F.10.6.7 |
186186
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
187187
| modf | |check| | |check| | |check| | | |check| | 7.12.6.18 | F.10.3.18 |
188188
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+

libc/spec/stdc.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,7 @@ def StdC : StandardSpec<"stdc"> {
570570
FunctionSpec<"lround", RetValSpec<LongType>, [ArgSpec<DoubleType>]>,
571571
FunctionSpec<"lroundf", RetValSpec<LongType>, [ArgSpec<FloatType>]>,
572572
FunctionSpec<"lroundl", RetValSpec<LongType>, [ArgSpec<LongDoubleType>]>,
573+
GuardedFunctionSpec<"lroundf16", RetValSpec<LongType>, [ArgSpec<Float16Type>], "LIBC_TYPES_HAS_FLOAT16">,
573574
GuardedFunctionSpec<"lroundf128", RetValSpec<LongType>, [ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,
574575

575576
FunctionSpec<"llround", RetValSpec<LongLongType>, [ArgSpec<DoubleType>]>,

libc/src/math/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ add_math_entrypoint_object(lrintf128)
240240
add_math_entrypoint_object(lround)
241241
add_math_entrypoint_object(lroundf)
242242
add_math_entrypoint_object(lroundl)
243+
add_math_entrypoint_object(lroundf16)
243244
add_math_entrypoint_object(lroundf128)
244245

245246
add_math_entrypoint_object(modf)

libc/src/math/generic/CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,19 @@ add_entrypoint_object(
499499
libc.src.__support.FPUtil.nearest_integer_operations
500500
)
501501

502+
add_entrypoint_object(
503+
lroundf16
504+
SRCS
505+
lroundf16.cpp
506+
HDRS
507+
../lroundf16.h
508+
COMPILE_OPTIONS
509+
-O3
510+
DEPENDS
511+
libc.src.__support.macros.properties.types
512+
libc.src.__support.FPUtil.nearest_integer_operations
513+
)
514+
502515
add_entrypoint_object(
503516
lroundf128
504517
SRCS

libc/src/math/generic/lroundf16.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//===-- Implementation of lroundf16 function ------------------------------===//
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 "src/math/lroundf16.h"
10+
#include "src/__support/FPUtil/NearestIntegerOperations.h"
11+
#include "src/__support/common.h"
12+
13+
namespace LIBC_NAMESPACE {
14+
15+
LLVM_LIBC_FUNCTION(long, lroundf16, (float16 x)) {
16+
return fputil::round_to_signed_integer<float128, long>(x);
17+
}
18+
19+
} // namespace LIBC_NAMESPACE

libc/src/math/lroundf16.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//===-- Implementation header for lroundf16 ---------------------*- C++ -*-===//
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+
#ifndef LLVM_LIBC_SRC_MATH_LROUNDF16_H
10+
#define LLVM_LIBC_SRC_MATH_LROUNDF16_H
11+
12+
#include "src/__support/macros/properties/types.h"
13+
14+
namespace LIBC_NAMESPACE {
15+
16+
long lroundf16(float16 x);
17+
18+
} // namespace LIBC_NAMESPACE
19+
20+
#endif // LLVM_LIBC_SRC_MATH_LROUNDF16_H

libc/test/src/math/smoke/CMakeLists.txt

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -447,11 +447,9 @@ add_fp_unittest(
447447
RoundToIntegerTest.h
448448
DEPENDS
449449
libc.src.errno.errno
450-
libc.src.fenv.feclearexcept
451-
libc.src.fenv.feraiseexcept
452-
libc.src.fenv.fetestexcept
453450
libc.src.math.lround
454451
libc.src.__support.CPP.algorithm
452+
libc.src.__support.FPUtil.fenv_impl
455453
libc.src.__support.FPUtil.fp_bits
456454
)
457455

@@ -465,11 +463,9 @@ add_fp_unittest(
465463
RoundToIntegerTest.h
466464
DEPENDS
467465
libc.src.errno.errno
468-
libc.src.fenv.feclearexcept
469-
libc.src.fenv.feraiseexcept
470-
libc.src.fenv.fetestexcept
471466
libc.src.math.lroundf
472467
libc.src.__support.CPP.algorithm
468+
libc.src.__support.FPUtil.fenv_impl
473469
libc.src.__support.FPUtil.fp_bits
474470
)
475471

@@ -483,11 +479,25 @@ add_fp_unittest(
483479
RoundToIntegerTest.h
484480
DEPENDS
485481
libc.src.errno.errno
486-
libc.src.fenv.feclearexcept
487-
libc.src.fenv.feraiseexcept
488-
libc.src.fenv.fetestexcept
489482
libc.src.math.lroundl
490483
libc.src.__support.CPP.algorithm
484+
libc.src.__support.FPUtil.fenv_impl
485+
libc.src.__support.FPUtil.fp_bits
486+
)
487+
488+
add_fp_unittest(
489+
lroundf16_test
490+
SUITE
491+
libc-math-smoke-tests
492+
SRCS
493+
lroundf16_test.cpp
494+
HDRS
495+
RoundToIntegerTest.h
496+
DEPENDS
497+
libc.src.errno.errno
498+
libc.src.math.lroundf16
499+
libc.src.__support.CPP.algorithm
500+
libc.src.__support.FPUtil.fenv_impl
491501
libc.src.__support.FPUtil.fp_bits
492502
)
493503

@@ -501,11 +511,9 @@ add_fp_unittest(
501511
RoundToIntegerTest.h
502512
DEPENDS
503513
libc.src.errno.errno
504-
libc.src.fenv.feclearexcept
505-
libc.src.fenv.feraiseexcept
506-
libc.src.fenv.fetestexcept
507514
libc.src.math.lroundf128
508515
libc.src.__support.CPP.algorithm
516+
libc.src.__support.FPUtil.fenv_impl
509517
libc.src.__support.FPUtil.fp_bits
510518
)
511519

@@ -519,11 +527,9 @@ add_fp_unittest(
519527
RoundToIntegerTest.h
520528
DEPENDS
521529
libc.src.errno.errno
522-
libc.src.fenv.feclearexcept
523-
libc.src.fenv.feraiseexcept
524-
libc.src.fenv.fetestexcept
525530
libc.src.math.llround
526531
libc.src.__support.CPP.algorithm
532+
libc.src.__support.FPUtil.fenv_impl
527533
libc.src.__support.FPUtil.fp_bits
528534
)
529535

@@ -537,11 +543,9 @@ add_fp_unittest(
537543
RoundToIntegerTest.h
538544
DEPENDS
539545
libc.src.errno.errno
540-
libc.src.fenv.feclearexcept
541-
libc.src.fenv.feraiseexcept
542-
libc.src.fenv.fetestexcept
543546
libc.src.math.llroundf
544547
libc.src.__support.CPP.algorithm
548+
libc.src.__support.FPUtil.fenv_impl
545549
libc.src.__support.FPUtil.fp_bits
546550
)
547551

@@ -555,11 +559,9 @@ add_fp_unittest(
555559
RoundToIntegerTest.h
556560
DEPENDS
557561
libc.src.errno.errno
558-
libc.src.fenv.feclearexcept
559-
libc.src.fenv.feraiseexcept
560-
libc.src.fenv.fetestexcept
561562
libc.src.math.llroundl
562563
libc.src.__support.CPP.algorithm
564+
libc.src.__support.FPUtil.fenv_impl
563565
libc.src.__support.FPUtil.fp_bits
564566
)
565567

@@ -573,11 +575,9 @@ add_fp_unittest(
573575
RoundToIntegerTest.h
574576
DEPENDS
575577
libc.src.errno.errno
576-
libc.src.fenv.feclearexcept
577-
libc.src.fenv.feraiseexcept
578-
libc.src.fenv.fetestexcept
579578
libc.src.math.llroundf128
580579
libc.src.__support.CPP.algorithm
580+
libc.src.__support.FPUtil.fenv_impl
581581
libc.src.__support.FPUtil.fp_bits
582582
)
583583

@@ -660,6 +660,7 @@ add_fp_unittest(
660660
HDRS
661661
RoundToIntegerTest.h
662662
DEPENDS
663+
libc.src.errno.errno
663664
libc.src.math.lrint
664665
libc.src.__support.CPP.algorithm
665666
libc.src.__support.FPUtil.fenv_impl
@@ -675,6 +676,7 @@ add_fp_unittest(
675676
HDRS
676677
RoundToIntegerTest.h
677678
DEPENDS
679+
libc.src.errno.errno
678680
libc.src.math.lrintf
679681
libc.src.__support.CPP.algorithm
680682
libc.src.__support.FPUtil.fenv_impl
@@ -690,6 +692,7 @@ add_fp_unittest(
690692
HDRS
691693
RoundToIntegerTest.h
692694
DEPENDS
695+
libc.src.errno.errno
693696
libc.src.math.lrintl
694697
libc.src.__support.CPP.algorithm
695698
libc.src.__support.FPUtil.fenv_impl
@@ -705,6 +708,7 @@ add_fp_unittest(
705708
HDRS
706709
RoundToIntegerTest.h
707710
DEPENDS
711+
libc.src.errno.errno
708712
libc.src.math.lrintf16
709713
libc.src.__support.CPP.algorithm
710714
libc.src.__support.FPUtil.fenv_impl
@@ -720,6 +724,7 @@ add_fp_unittest(
720724
HDRS
721725
RoundToIntegerTest.h
722726
DEPENDS
727+
libc.src.errno.errno
723728
libc.src.math.lrintf128
724729
libc.src.__support.CPP.algorithm
725730
libc.src.__support.FPUtil.fenv_impl
@@ -735,6 +740,7 @@ add_fp_unittest(
735740
HDRS
736741
RoundToIntegerTest.h
737742
DEPENDS
743+
libc.src.errno.errno
738744
libc.src.math.llrint
739745
libc.src.__support.CPP.algorithm
740746
libc.src.__support.FPUtil.fenv_impl
@@ -750,6 +756,7 @@ add_fp_unittest(
750756
HDRS
751757
RoundToIntegerTest.h
752758
DEPENDS
759+
libc.src.errno.errno
753760
libc.src.math.llrintf
754761
libc.src.__support.CPP.algorithm
755762
libc.src.__support.FPUtil.fenv_impl
@@ -765,6 +772,7 @@ add_fp_unittest(
765772
HDRS
766773
RoundToIntegerTest.h
767774
DEPENDS
775+
libc.src.errno.errno
768776
libc.src.math.llrintl
769777
libc.src.__support.CPP.algorithm
770778
libc.src.__support.FPUtil.fenv_impl
@@ -780,6 +788,7 @@ add_fp_unittest(
780788
HDRS
781789
RoundToIntegerTest.h
782790
DEPENDS
791+
libc.src.errno.errno
783792
libc.src.math.llrintf16
784793
libc.src.__support.CPP.algorithm
785794
libc.src.__support.FPUtil.fenv_impl
@@ -795,6 +804,7 @@ add_fp_unittest(
795804
HDRS
796805
RoundToIntegerTest.h
797806
DEPENDS
807+
libc.src.errno.errno
798808
libc.src.math.llrintf128
799809
libc.src.__support.CPP.algorithm
800810
libc.src.__support.FPUtil.fenv_impl
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)