Skip to content

Commit 30cd537

Browse files
committed
[libc][math][c23] Add lroundf16 C23 math function
1 parent f4a9850 commit 30cd537

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
@@ -504,6 +504,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
504504
libc.src.math.floorf16
505505
libc.src.math.llrintf16
506506
libc.src.math.lrintf16
507+
libc.src.math.lroundf16
507508
libc.src.math.nearbyintf16
508509
libc.src.math.rintf16
509510
libc.src.math.roundf16

libc/config/linux/x86_64/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
537537
libc.src.math.floorf16
538538
libc.src.math.llrintf16
539539
libc.src.math.lrintf16
540+
libc.src.math.lroundf16
540541
libc.src.math.nearbyintf16
541542
libc.src.math.rintf16
542543
libc.src.math.roundf16

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
@@ -579,6 +579,7 @@ def StdC : StandardSpec<"stdc"> {
579579
FunctionSpec<"lround", RetValSpec<LongType>, [ArgSpec<DoubleType>]>,
580580
FunctionSpec<"lroundf", RetValSpec<LongType>, [ArgSpec<FloatType>]>,
581581
FunctionSpec<"lroundl", RetValSpec<LongType>, [ArgSpec<LongDoubleType>]>,
582+
GuardedFunctionSpec<"lroundf16", RetValSpec<LongType>, [ArgSpec<Float16Type>], "LIBC_TYPES_HAS_FLOAT16">,
582583
GuardedFunctionSpec<"lroundf128", RetValSpec<LongType>, [ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,
583584

584585
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
@@ -242,6 +242,7 @@ add_math_entrypoint_object(lrintf128)
242242
add_math_entrypoint_object(lround)
243243
add_math_entrypoint_object(lroundf)
244244
add_math_entrypoint_object(lroundl)
245+
add_math_entrypoint_object(lroundf16)
245246
add_math_entrypoint_object(lroundf128)
246247

247248
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
@@ -564,6 +564,19 @@ add_entrypoint_object(
564564
libc.src.__support.FPUtil.nearest_integer_operations
565565
)
566566

567+
add_entrypoint_object(
568+
lroundf16
569+
SRCS
570+
lroundf16.cpp
571+
HDRS
572+
../lroundf16.h
573+
COMPILE_OPTIONS
574+
-O3
575+
DEPENDS
576+
libc.src.__support.macros.properties.types
577+
libc.src.__support.FPUtil.nearest_integer_operations
578+
)
579+
567580
add_entrypoint_object(
568581
lroundf128
569582
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
@@ -507,11 +507,9 @@ add_fp_unittest(
507507
RoundToIntegerTest.h
508508
DEPENDS
509509
libc.src.errno.errno
510-
libc.src.fenv.feclearexcept
511-
libc.src.fenv.feraiseexcept
512-
libc.src.fenv.fetestexcept
513510
libc.src.math.lround
514511
libc.src.__support.CPP.algorithm
512+
libc.src.__support.FPUtil.fenv_impl
515513
libc.src.__support.FPUtil.fp_bits
516514
)
517515

@@ -525,11 +523,9 @@ add_fp_unittest(
525523
RoundToIntegerTest.h
526524
DEPENDS
527525
libc.src.errno.errno
528-
libc.src.fenv.feclearexcept
529-
libc.src.fenv.feraiseexcept
530-
libc.src.fenv.fetestexcept
531526
libc.src.math.lroundf
532527
libc.src.__support.CPP.algorithm
528+
libc.src.__support.FPUtil.fenv_impl
533529
libc.src.__support.FPUtil.fp_bits
534530
)
535531

@@ -543,11 +539,25 @@ add_fp_unittest(
543539
RoundToIntegerTest.h
544540
DEPENDS
545541
libc.src.errno.errno
546-
libc.src.fenv.feclearexcept
547-
libc.src.fenv.feraiseexcept
548-
libc.src.fenv.fetestexcept
549542
libc.src.math.lroundl
550543
libc.src.__support.CPP.algorithm
544+
libc.src.__support.FPUtil.fenv_impl
545+
libc.src.__support.FPUtil.fp_bits
546+
)
547+
548+
add_fp_unittest(
549+
lroundf16_test
550+
SUITE
551+
libc-math-smoke-tests
552+
SRCS
553+
lroundf16_test.cpp
554+
HDRS
555+
RoundToIntegerTest.h
556+
DEPENDS
557+
libc.src.errno.errno
558+
libc.src.math.lroundf16
559+
libc.src.__support.CPP.algorithm
560+
libc.src.__support.FPUtil.fenv_impl
551561
libc.src.__support.FPUtil.fp_bits
552562
)
553563

@@ -561,11 +571,9 @@ add_fp_unittest(
561571
RoundToIntegerTest.h
562572
DEPENDS
563573
libc.src.errno.errno
564-
libc.src.fenv.feclearexcept
565-
libc.src.fenv.feraiseexcept
566-
libc.src.fenv.fetestexcept
567574
libc.src.math.lroundf128
568575
libc.src.__support.CPP.algorithm
576+
libc.src.__support.FPUtil.fenv_impl
569577
libc.src.__support.FPUtil.fp_bits
570578
)
571579

@@ -579,11 +587,9 @@ add_fp_unittest(
579587
RoundToIntegerTest.h
580588
DEPENDS
581589
libc.src.errno.errno
582-
libc.src.fenv.feclearexcept
583-
libc.src.fenv.feraiseexcept
584-
libc.src.fenv.fetestexcept
585590
libc.src.math.llround
586591
libc.src.__support.CPP.algorithm
592+
libc.src.__support.FPUtil.fenv_impl
587593
libc.src.__support.FPUtil.fp_bits
588594
)
589595

@@ -597,11 +603,9 @@ add_fp_unittest(
597603
RoundToIntegerTest.h
598604
DEPENDS
599605
libc.src.errno.errno
600-
libc.src.fenv.feclearexcept
601-
libc.src.fenv.feraiseexcept
602-
libc.src.fenv.fetestexcept
603606
libc.src.math.llroundf
604607
libc.src.__support.CPP.algorithm
608+
libc.src.__support.FPUtil.fenv_impl
605609
libc.src.__support.FPUtil.fp_bits
606610
)
607611

@@ -615,11 +619,9 @@ add_fp_unittest(
615619
RoundToIntegerTest.h
616620
DEPENDS
617621
libc.src.errno.errno
618-
libc.src.fenv.feclearexcept
619-
libc.src.fenv.feraiseexcept
620-
libc.src.fenv.fetestexcept
621622
libc.src.math.llroundl
622623
libc.src.__support.CPP.algorithm
624+
libc.src.__support.FPUtil.fenv_impl
623625
libc.src.__support.FPUtil.fp_bits
624626
)
625627

@@ -633,11 +635,9 @@ add_fp_unittest(
633635
RoundToIntegerTest.h
634636
DEPENDS
635637
libc.src.errno.errno
636-
libc.src.fenv.feclearexcept
637-
libc.src.fenv.feraiseexcept
638-
libc.src.fenv.fetestexcept
639638
libc.src.math.llroundf128
640639
libc.src.__support.CPP.algorithm
640+
libc.src.__support.FPUtil.fenv_impl
641641
libc.src.__support.FPUtil.fp_bits
642642
)
643643

@@ -720,6 +720,7 @@ add_fp_unittest(
720720
HDRS
721721
RoundToIntegerTest.h
722722
DEPENDS
723+
libc.src.errno.errno
723724
libc.src.math.lrint
724725
libc.src.__support.CPP.algorithm
725726
libc.src.__support.FPUtil.fenv_impl
@@ -735,6 +736,7 @@ add_fp_unittest(
735736
HDRS
736737
RoundToIntegerTest.h
737738
DEPENDS
739+
libc.src.errno.errno
738740
libc.src.math.lrintf
739741
libc.src.__support.CPP.algorithm
740742
libc.src.__support.FPUtil.fenv_impl
@@ -750,6 +752,7 @@ add_fp_unittest(
750752
HDRS
751753
RoundToIntegerTest.h
752754
DEPENDS
755+
libc.src.errno.errno
753756
libc.src.math.lrintl
754757
libc.src.__support.CPP.algorithm
755758
libc.src.__support.FPUtil.fenv_impl
@@ -765,6 +768,7 @@ add_fp_unittest(
765768
HDRS
766769
RoundToIntegerTest.h
767770
DEPENDS
771+
libc.src.errno.errno
768772
libc.src.math.lrintf16
769773
libc.src.__support.CPP.algorithm
770774
libc.src.__support.FPUtil.fenv_impl
@@ -780,6 +784,7 @@ add_fp_unittest(
780784
HDRS
781785
RoundToIntegerTest.h
782786
DEPENDS
787+
libc.src.errno.errno
783788
libc.src.math.lrintf128
784789
libc.src.__support.CPP.algorithm
785790
libc.src.__support.FPUtil.fenv_impl
@@ -795,6 +800,7 @@ add_fp_unittest(
795800
HDRS
796801
RoundToIntegerTest.h
797802
DEPENDS
803+
libc.src.errno.errno
798804
libc.src.math.llrint
799805
libc.src.__support.CPP.algorithm
800806
libc.src.__support.FPUtil.fenv_impl
@@ -810,6 +816,7 @@ add_fp_unittest(
810816
HDRS
811817
RoundToIntegerTest.h
812818
DEPENDS
819+
libc.src.errno.errno
813820
libc.src.math.llrintf
814821
libc.src.__support.CPP.algorithm
815822
libc.src.__support.FPUtil.fenv_impl
@@ -825,6 +832,7 @@ add_fp_unittest(
825832
HDRS
826833
RoundToIntegerTest.h
827834
DEPENDS
835+
libc.src.errno.errno
828836
libc.src.math.llrintl
829837
libc.src.__support.CPP.algorithm
830838
libc.src.__support.FPUtil.fenv_impl
@@ -840,6 +848,7 @@ add_fp_unittest(
840848
HDRS
841849
RoundToIntegerTest.h
842850
DEPENDS
851+
libc.src.errno.errno
843852
libc.src.math.llrintf16
844853
libc.src.__support.CPP.algorithm
845854
libc.src.__support.FPUtil.fenv_impl
@@ -855,6 +864,7 @@ add_fp_unittest(
855864
HDRS
856865
RoundToIntegerTest.h
857866
DEPENDS
867+
libc.src.errno.errno
858868
libc.src.math.llrintf128
859869
libc.src.__support.CPP.algorithm
860870
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)