Skip to content

Commit 777eb35

Browse files
felixh5678lntueFelix
authored
[libc] Add sqrtf128 implementation for Linux x86_64. (#79195)
Co-authored-by: Tue Ly <[email protected]> Co-authored-by: Felix <[email protected]>
1 parent aaa93ce commit 777eb35

File tree

10 files changed

+115
-5
lines changed

10 files changed

+115
-5
lines changed

libc/config/linux/x86_64/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@ if(LIBC_COMPILER_HAS_FLOAT128)
374374
# math.h C23 _Float128 entrypoints
375375
libc.src.math.copysignf128
376376
libc.src.math.fabsf128
377+
libc.src.math.sqrtf128
377378
)
378379
endif()
379380

libc/docs/math/index.rst

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,8 @@ Higher Math Functions
452452
+------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
453453
| sqrtl | |check| | |check| | |check| | |check| | |check| | | | |check| | |check| | |check| | | |
454454
+------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
455+
| sqrtf128 | |check| | | | | | | | | | | | |
456+
+------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
455457
| tan | |check| | | | | | | | | | | | |
456458
+------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
457459
| tanf | |check| | |check| | |check| | |check| | |check| | | | |check| | |check| | |check| | | |
@@ -475,9 +477,9 @@ Higher Math Functions
475477
Accuracy of Higher Math Functions
476478
=================================
477479

478-
============== ================ =============== ======================
479-
<Func> <Func_f> (float) <Func> (double) <Func_l> (long double)
480-
============== ================ =============== ======================
480+
============== ================ =============== ====================== ======================
481+
<Func> <Func_f> (float) <Func> (double) <Func_l> (long double) <Func_f128> (float128)
482+
============== ================ =============== ====================== ======================
481483
acos |check|
482484
acosh |check|
483485
asin |check|
@@ -501,10 +503,10 @@ pow |check|
501503
sin |check| large
502504
sincos |check| large
503505
sinh |check|
504-
sqrt |check| |check| |check|
506+
sqrt |check| |check| |check| |check|
505507
tan |check|
506508
tanh |check|
507-
============== ================ =============== ======================
509+
============== ================ =============== ====================== ======================
508510

509511

510512
Legends:

libc/spec/stdc.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,7 @@ def StdC : StandardSpec<"stdc"> {
480480
FunctionSpec<"sqrt", RetValSpec<DoubleType>, [ArgSpec<DoubleType>]>,
481481
FunctionSpec<"sqrtf", RetValSpec<FloatType>, [ArgSpec<FloatType>]>,
482482
FunctionSpec<"sqrtl", RetValSpec<LongDoubleType>, [ArgSpec<LongDoubleType>]>,
483+
FunctionSpec<"sqrtf128", RetValSpec<Float128Type>, [ArgSpec<Float128Type>]>,
483484

484485
FunctionSpec<"trunc", RetValSpec<DoubleType>, [ArgSpec<DoubleType>]>,
485486
FunctionSpec<"truncf", RetValSpec<FloatType>, [ArgSpec<FloatType>]>,

libc/src/math/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ add_math_entrypoint_object(sinhf)
231231
add_math_entrypoint_object(sqrt)
232232
add_math_entrypoint_object(sqrtf)
233233
add_math_entrypoint_object(sqrtl)
234+
add_math_entrypoint_object(sqrtf128)
234235

235236
add_math_entrypoint_object(tan)
236237
add_math_entrypoint_object(tanf)

libc/src/math/generic/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,6 +1315,18 @@ add_entrypoint_object(
13151315
-O3
13161316
)
13171317

1318+
add_entrypoint_object(
1319+
sqrtf128
1320+
SRCS
1321+
sqrtf128.cpp
1322+
HDRS
1323+
../sqrtf128.h
1324+
DEPENDS
1325+
libc.src.__support.FPUtil.sqrt
1326+
COMPILE_OPTIONS
1327+
-O3
1328+
)
1329+
13181330
add_entrypoint_object(
13191331
remquof
13201332
SRCS

libc/src/math/generic/sqrtf128.cpp

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

libc/src/math/sqrtf128.h

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

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,6 +1102,20 @@ add_fp_unittest(
11021102
UNIT_TEST_ONLY
11031103
)
11041104

1105+
add_fp_unittest(
1106+
sqrtf128_test
1107+
SUITE
1108+
libc-math-smoke-tests
1109+
SRCS
1110+
sqrtf128_test.cpp
1111+
DEPENDS
1112+
libc.include.math
1113+
libc.src.math.sqrtf128
1114+
libc.src.__support.FPUtil.fp_bits
1115+
# FIXME: Currently fails on the GPU build.
1116+
UNIT_TEST_ONLY
1117+
)
1118+
11051119
add_fp_unittest(
11061120
generic_sqrtf_test
11071121
SUITE
@@ -1150,6 +1164,22 @@ add_fp_unittest(
11501164
UNIT_TEST_ONLY
11511165
)
11521166

1167+
add_fp_unittest(
1168+
generic_sqrtf128_test
1169+
SUITE
1170+
libc-math-smoke-tests
1171+
SRCS
1172+
generic_sqrtf128_test.cpp
1173+
DEPENDS
1174+
libc.src.math.sqrtf128
1175+
libc.src.__support.FPUtil.fp_bits
1176+
libc.src.__support.FPUtil.generic.sqrt
1177+
COMPILE_OPTIONS
1178+
-O3
1179+
# FIXME: Currently fails on the GPU build.
1180+
UNIT_TEST_ONLY
1181+
)
1182+
11531183
add_fp_unittest(
11541184
remquof_test
11551185
SUITE
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//===-- Unittests for generic implementation of sqrtf128-------------------===//
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 "SqrtTest.h"
10+
11+
#include "src/__support/FPUtil/generic/sqrt.h"
12+
13+
LIST_SQRT_TESTS(float128, LIBC_NAMESPACE::fputil::sqrt<float128>)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//===-- Unittests for sqrtf128---------------------------------------------===//
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 "SqrtTest.h"
10+
11+
#include "src/math/sqrtf128.h"
12+
13+
LIST_SQRT_TESTS(float128, LIBC_NAMESPACE::sqrtf128)

0 commit comments

Comments
 (0)