Skip to content

Commit 637c370

Browse files
authored
[libc][math] Add C23 math function frexpf128. (#81337)
1 parent cc02e50 commit 637c370

File tree

15 files changed

+119
-45
lines changed

15 files changed

+119
-45
lines changed

libc/config/linux/aarch64/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@ if(LIBC_COMPILER_HAS_FLOAT128)
386386
libc.src.math.floorf128
387387
libc.src.math.fmaxf128
388388
libc.src.math.fminf128
389+
libc.src.math.frexpf128
389390
libc.src.math.roundf128
390391
libc.src.math.sqrtf128
391392
libc.src.math.truncf128

libc/config/linux/riscv/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,7 @@ if(LIBC_COMPILER_HAS_FLOAT128)
395395
libc.src.math.floorf128
396396
libc.src.math.fmaxf128
397397
libc.src.math.fminf128
398+
libc.src.math.frexpf128
398399
libc.src.math.roundf128
399400
libc.src.math.sqrtf128
400401
libc.src.math.truncf128

libc/config/linux/x86_64/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,7 @@ if(LIBC_COMPILER_HAS_FLOAT128)
414414
libc.src.math.floorf128
415415
libc.src.math.fmaxf128
416416
libc.src.math.fminf128
417+
libc.src.math.frexpf128
417418
libc.src.math.roundf128
418419
libc.src.math.sqrtf128
419420
libc.src.math.truncf128

libc/docs/math/index.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ Basic Operations
176176
+--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
177177
| frexpl | |check| | |check| | |check| | |check| | |check| | | | |check| | |check| | |check| | | |
178178
+--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
179+
| frexpf128 | |check| | |check| | | |check| | | | | | | | | |
180+
+--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
179181
| ilogb | |check| | |check| | |check| | |check| | |check| | | | |check| | |check| | |check| | | |
180182
+--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
181183
| ilogbf | |check| | |check| | |check| | |check| | |check| | | | |check| | |check| | |check| | | |

libc/spec/stdc.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,7 @@ def StdC : StandardSpec<"stdc"> {
401401
FunctionSpec<"frexp", RetValSpec<DoubleType>, [ArgSpec<DoubleType>, ArgSpec<IntPtr>]>,
402402
FunctionSpec<"frexpf", RetValSpec<FloatType>, [ArgSpec<FloatType>, ArgSpec<IntPtr>]>,
403403
FunctionSpec<"frexpl", RetValSpec<LongDoubleType>, [ArgSpec<LongDoubleType>, ArgSpec<IntPtr>]>,
404+
GuardedFunctionSpec<"frexpf128", RetValSpec<Float128Type>, [ArgSpec<Float128Type>, ArgSpec<IntPtr>]], "LIBC_COMPILER_HAS_FLOAT128">,
404405

405406
FunctionSpec<"hypot", RetValSpec<DoubleType>, [ArgSpec<DoubleType>, ArgSpec<DoubleType>]>,
406407
FunctionSpec<"hypotf", RetValSpec<FloatType>, [ArgSpec<FloatType>, ArgSpec<FloatType>]>,

libc/src/math/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ add_math_entrypoint_object(fmodf)
137137
add_math_entrypoint_object(frexp)
138138
add_math_entrypoint_object(frexpf)
139139
add_math_entrypoint_object(frexpl)
140+
add_math_entrypoint_object(frexpf128)
140141

141142
add_math_entrypoint_object(hypot)
142143
add_math_entrypoint_object(hypotf)

libc/src/math/frexpf128.h

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

libc/src/math/generic/CMakeLists.txt

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -916,10 +916,10 @@ add_entrypoint_object(
916916
frexp.cpp
917917
HDRS
918918
../frexp.h
919+
COMPILE_OPTIONS
920+
-O3
919921
DEPENDS
920922
libc.src.__support.FPUtil.manipulation_functions
921-
COMPILE_OPTIONS
922-
-O2
923923
)
924924

925925
add_entrypoint_object(
@@ -928,10 +928,10 @@ add_entrypoint_object(
928928
frexpf.cpp
929929
HDRS
930930
../frexpf.h
931+
COMPILE_OPTIONS
932+
-O3
931933
DEPENDS
932934
libc.src.__support.FPUtil.manipulation_functions
933-
COMPILE_OPTIONS
934-
-O2
935935
)
936936

937937
add_entrypoint_object(
@@ -940,10 +940,23 @@ add_entrypoint_object(
940940
frexpl.cpp
941941
HDRS
942942
../frexpl.h
943+
COMPILE_OPTIONS
944+
-O3
943945
DEPENDS
944946
libc.src.__support.FPUtil.manipulation_functions
947+
)
948+
949+
add_entrypoint_object(
950+
frexpf128
951+
SRCS
952+
frexpf128.cpp
953+
HDRS
954+
../frexpf128.h
945955
COMPILE_OPTIONS
946-
-O2
956+
-O3
957+
DEPENDS
958+
libc.src.__support.macros.properties.float
959+
libc.src.__support.FPUtil.manipulation_functions
947960
)
948961

949962
add_entrypoint_object(
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//===-- Implementation of frexpf128 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/frexpf128.h"
10+
#include "src/__support/FPUtil/ManipulationFunctions.h"
11+
#include "src/__support/common.h"
12+
13+
namespace LIBC_NAMESPACE {
14+
15+
LLVM_LIBC_FUNCTION(float128, frexpf128, (float128 x, int *exp)) {
16+
return fputil::frexp(x, *exp);
17+
}
18+
19+
} // namespace LIBC_NAMESPACE

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -779,9 +779,7 @@ add_fp_unittest(
779779
HDRS
780780
FrexpTest.h
781781
DEPENDS
782-
libc.include.math
783782
libc.src.math.frexp
784-
libc.src.__support.FPUtil.basic_operations
785783
)
786784

787785
add_fp_unittest(
@@ -793,9 +791,7 @@ add_fp_unittest(
793791
HDRS
794792
FrexpTest.h
795793
DEPENDS
796-
libc.include.math
797794
libc.src.math.frexpf
798-
libc.src.__support.FPUtil.basic_operations
799795
)
800796

801797
add_fp_unittest(
@@ -807,9 +803,19 @@ add_fp_unittest(
807803
HDRS
808804
FrexpTest.h
809805
DEPENDS
810-
libc.include.math
811806
libc.src.math.frexpl
812-
libc.src.__support.FPUtil.basic_operations
807+
)
808+
809+
add_fp_unittest(
810+
frexpf128_test
811+
SUITE
812+
libc-math-smoke-tests
813+
SRCS
814+
frexpf128_test.cpp
815+
HDRS
816+
FrexpTest.h
817+
DEPENDS
818+
libc.src.math.frexpf128
813819
)
814820

815821
# FIXME: These tests are currently broken for NVPTX.

0 commit comments

Comments
 (0)