Skip to content

Commit 6ba9d29

Browse files
authored
[libc][math] Add float128 rounding functions (ceilf128, floorf128, roundf128, truncf128). (#80634)
1 parent c391f28 commit 6ba9d29

File tree

18 files changed

+359
-21
lines changed

18 files changed

+359
-21
lines changed

libc/config/linux/x86_64/entrypoints.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,11 +397,15 @@ set(TARGET_LIBM_ENTRYPOINTS
397397
if(LIBC_COMPILER_HAS_FLOAT128)
398398
list(APPEND TARGET_LIBM_ENTRYPOINTS
399399
# math.h C23 _Float128 entrypoints
400+
libc.src.math.ceilf128
400401
libc.src.math.copysignf128
401402
libc.src.math.fabsf128
402-
libc.src.math.sqrtf128
403+
libc.src.math.floorf128
403404
libc.src.math.fmaxf128
404405
libc.src.math.fminf128
406+
libc.src.math.roundf128
407+
libc.src.math.sqrtf128
408+
libc.src.math.truncf128
405409
)
406410
endif()
407411

libc/docs/math/index.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ Basic Operations
114114
+--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
115115
| ceill | |check| | |check| | |check| | |check| | |check| | | | |check| | |check| | |check| | | |
116116
+--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
117+
| ceilf128 | |check| | | | | | | | | | | | |
118+
+--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
117119
| copysign | |check| | |check| | |check| | |check| | |check| | | | |check| | |check| | |check| | | |
118120
+--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
119121
| copysignf | |check| | |check| | |check| | |check| | |check| | | | |check| | |check| | |check| | | |
@@ -142,6 +144,8 @@ Basic Operations
142144
+--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
143145
| floorl | |check| | |check| | |check| | |check| | |check| | | | |check| | |check| | |check| | | |
144146
+--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
147+
| floorf128 | |check| | | | | | | | | | | | |
148+
+--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
145149
| fmax | |check| | |check| | |check| | |check| | |check| | | | |check| | |check| | |check| | | |
146150
+--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
147151
| fmaxf | |check| | |check| | |check| | |check| | |check| | | | |check| | |check| | |check| | | |
@@ -266,6 +270,8 @@ Basic Operations
266270
+--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
267271
| roundl | |check| | |check| | |check| | |check| | |check| | | | |check| | |check| | |check| | | |
268272
+--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
273+
| roundf128 | |check| | | | | | | | | | | | |
274+
+--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
269275
| scalbn | |check| | |check| | |check| | |check| | |check| | | | |check| | |check| | |check| | | |
270276
+--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
271277
| scalbnf | |check| | |check| | |check| | |check| | |check| | | | |check| | |check| | |check| | | |
@@ -278,6 +284,8 @@ Basic Operations
278284
+--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
279285
| truncl | |check| | |check| | |check| | |check| | |check| | | | |check| | |check| | |check| | | |
280286
+--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
287+
| truncf128 | |check| | | | | | | | | | | | |
288+
+--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
281289

282290

283291
Higher Math Functions

libc/spec/stdc.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,7 @@ def StdC : StandardSpec<"stdc"> {
363363
FunctionSpec<"ceil", RetValSpec<DoubleType>, [ArgSpec<DoubleType>]>,
364364
FunctionSpec<"ceilf", RetValSpec<FloatType>, [ArgSpec<FloatType>]>,
365365
FunctionSpec<"ceill", RetValSpec<LongDoubleType>, [ArgSpec<LongDoubleType>]>,
366+
FunctionSpec<"ceilf128", RetValSpec<Float128Type>, [ArgSpec<Float128Type>]>,
366367

367368
FunctionSpec<"fabs", RetValSpec<DoubleType>, [ArgSpec<DoubleType>]>,
368369
FunctionSpec<"fabsf", RetValSpec<FloatType>, [ArgSpec<FloatType>]>,
@@ -376,6 +377,7 @@ def StdC : StandardSpec<"stdc"> {
376377
FunctionSpec<"floor", RetValSpec<DoubleType>, [ArgSpec<DoubleType>]>,
377378
FunctionSpec<"floorf", RetValSpec<FloatType>, [ArgSpec<FloatType>]>,
378379
FunctionSpec<"floorl", RetValSpec<LongDoubleType>, [ArgSpec<LongDoubleType>]>,
380+
FunctionSpec<"floorf128", RetValSpec<Float128Type>, [ArgSpec<Float128Type>]>,
379381

380382
FunctionSpec<"fmin", RetValSpec<DoubleType>, [ArgSpec<DoubleType>, ArgSpec<DoubleType>]>,
381383
FunctionSpec<"fminf", RetValSpec<FloatType>, [ArgSpec<FloatType>, ArgSpec<FloatType>]>,
@@ -458,6 +460,7 @@ def StdC : StandardSpec<"stdc"> {
458460
FunctionSpec<"round", RetValSpec<DoubleType>, [ArgSpec<DoubleType>]>,
459461
FunctionSpec<"roundf", RetValSpec<FloatType>, [ArgSpec<FloatType>]>,
460462
FunctionSpec<"roundl", RetValSpec<LongDoubleType>, [ArgSpec<LongDoubleType>]>,
463+
FunctionSpec<"roundf128", RetValSpec<Float128Type>, [ArgSpec<Float128Type>]>,
461464

462465
FunctionSpec<"lround", RetValSpec<LongType>, [ArgSpec<DoubleType>]>,
463466
FunctionSpec<"lroundf", RetValSpec<LongType>, [ArgSpec<FloatType>]>,
@@ -487,6 +490,7 @@ def StdC : StandardSpec<"stdc"> {
487490
FunctionSpec<"trunc", RetValSpec<DoubleType>, [ArgSpec<DoubleType>]>,
488491
FunctionSpec<"truncf", RetValSpec<FloatType>, [ArgSpec<FloatType>]>,
489492
FunctionSpec<"truncl", RetValSpec<LongDoubleType>, [ArgSpec<LongDoubleType>]>,
493+
FunctionSpec<"truncf128", RetValSpec<Float128Type>, [ArgSpec<Float128Type>]>,
490494

491495
FunctionSpec<"nearbyint", RetValSpec<DoubleType>, [ArgSpec<DoubleType>]>,
492496
FunctionSpec<"nearbyintf", RetValSpec<FloatType>, [ArgSpec<FloatType>]>,

libc/src/math/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ add_math_entrypoint_object(atanhf)
7676
add_math_entrypoint_object(ceil)
7777
add_math_entrypoint_object(ceilf)
7878
add_math_entrypoint_object(ceill)
79+
add_math_entrypoint_object(ceilf128)
7980

8081
add_math_entrypoint_object(copysign)
8182
add_math_entrypoint_object(copysignf)
@@ -114,6 +115,7 @@ add_math_entrypoint_object(fdiml)
114115
add_math_entrypoint_object(floor)
115116
add_math_entrypoint_object(floorf)
116117
add_math_entrypoint_object(floorl)
118+
add_math_entrypoint_object(floorf128)
117119

118120
add_math_entrypoint_object(fma)
119121
add_math_entrypoint_object(fmaf)
@@ -216,6 +218,7 @@ add_math_entrypoint_object(rintl)
216218
add_math_entrypoint_object(round)
217219
add_math_entrypoint_object(roundf)
218220
add_math_entrypoint_object(roundl)
221+
add_math_entrypoint_object(roundf128)
219222

220223
add_math_entrypoint_object(scalbn)
221224
add_math_entrypoint_object(scalbnf)
@@ -247,3 +250,4 @@ add_math_entrypoint_object(tgammaf)
247250
add_math_entrypoint_object(trunc)
248251
add_math_entrypoint_object(truncf)
249252
add_math_entrypoint_object(truncl)
253+
add_math_entrypoint_object(truncf128)

libc/src/math/ceilf128.h

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

libc/src/math/floorf128.h

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

libc/src/math/generic/CMakeLists.txt

Lines changed: 68 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ add_entrypoint_object(
44
ceil.cpp
55
HDRS
66
../ceil.h
7+
COMPILE_OPTIONS
8+
-O3
79
DEPENDS
810
libc.src.__support.FPUtil.nearest_integer_operations
9-
COMPILE_OPTIONS
10-
-O2
1111
)
1212

1313
add_entrypoint_object(
@@ -16,10 +16,10 @@ add_entrypoint_object(
1616
ceilf.cpp
1717
HDRS
1818
../ceilf.h
19+
COMPILE_OPTIONS
20+
-O3
1921
DEPENDS
2022
libc.src.__support.FPUtil.nearest_integer_operations
21-
COMPILE_OPTIONS
22-
-O2
2323
)
2424

2525
add_entrypoint_object(
@@ -28,10 +28,22 @@ add_entrypoint_object(
2828
ceill.cpp
2929
HDRS
3030
../ceill.h
31+
COMPILE_OPTIONS
32+
-O3
3133
DEPENDS
3234
libc.src.__support.FPUtil.nearest_integer_operations
35+
)
36+
37+
add_entrypoint_object(
38+
ceilf128
39+
SRCS
40+
ceilf128.cpp
41+
HDRS
42+
../ceilf128.h
3343
COMPILE_OPTIONS
34-
-O2
44+
-O3
45+
DEPENDS
46+
libc.src.__support.FPUtil.nearest_integer_operations
3547
)
3648

3749
add_object_library(
@@ -214,10 +226,10 @@ add_entrypoint_object(
214226
trunc.cpp
215227
HDRS
216228
../trunc.h
229+
COMPILE_OPTIONS
230+
-O3
217231
DEPENDS
218232
libc.src.__support.FPUtil.nearest_integer_operations
219-
COMPILE_OPTIONS
220-
-O2
221233
)
222234

223235
add_entrypoint_object(
@@ -226,10 +238,10 @@ add_entrypoint_object(
226238
truncf.cpp
227239
HDRS
228240
../truncf.h
241+
COMPILE_OPTIONS
242+
-O3
229243
DEPENDS
230244
libc.src.__support.FPUtil.nearest_integer_operations
231-
COMPILE_OPTIONS
232-
-O2
233245
)
234246

235247
add_entrypoint_object(
@@ -238,10 +250,22 @@ add_entrypoint_object(
238250
truncl.cpp
239251
HDRS
240252
../truncl.h
253+
COMPILE_OPTIONS
254+
-O3
241255
DEPENDS
242256
libc.src.__support.FPUtil.nearest_integer_operations
257+
)
258+
259+
add_entrypoint_object(
260+
truncf128
261+
SRCS
262+
truncf128.cpp
263+
HDRS
264+
../truncf128.h
243265
COMPILE_OPTIONS
244-
-O2
266+
-O3
267+
DEPENDS
268+
libc.src.__support.FPUtil.nearest_integer_operations
245269
)
246270

247271
add_entrypoint_object(
@@ -250,10 +274,10 @@ add_entrypoint_object(
250274
floor.cpp
251275
HDRS
252276
../floor.h
277+
COMPILE_OPTIONS
278+
-O3
253279
DEPENDS
254280
libc.src.__support.FPUtil.nearest_integer_operations
255-
COMPILE_OPTIONS
256-
-O2
257281
)
258282

259283
add_entrypoint_object(
@@ -262,10 +286,10 @@ add_entrypoint_object(
262286
floorf.cpp
263287
HDRS
264288
../floorf.h
289+
COMPILE_OPTIONS
290+
-O3
265291
DEPENDS
266292
libc.src.__support.FPUtil.nearest_integer_operations
267-
COMPILE_OPTIONS
268-
-O2
269293
)
270294

271295
add_entrypoint_object(
@@ -274,10 +298,22 @@ add_entrypoint_object(
274298
floorl.cpp
275299
HDRS
276300
../floorl.h
301+
COMPILE_OPTIONS
302+
-O3
277303
DEPENDS
278304
libc.src.__support.FPUtil.nearest_integer_operations
305+
)
306+
307+
add_entrypoint_object(
308+
floorf128
309+
SRCS
310+
floorf128.cpp
311+
HDRS
312+
../floorf128.h
279313
COMPILE_OPTIONS
280-
-O2
314+
-O3
315+
DEPENDS
316+
libc.src.__support.FPUtil.nearest_integer_operations
281317
)
282318

283319
add_entrypoint_object(
@@ -286,10 +322,10 @@ add_entrypoint_object(
286322
round.cpp
287323
HDRS
288324
../round.h
325+
COMPILE_OPTIONS
326+
-O3
289327
DEPENDS
290328
libc.src.__support.FPUtil.nearest_integer_operations
291-
COMPILE_OPTIONS
292-
-O2
293329
)
294330

295331
add_entrypoint_object(
@@ -298,10 +334,10 @@ add_entrypoint_object(
298334
roundf.cpp
299335
HDRS
300336
../roundf.h
337+
COMPILE_OPTIONS
338+
-O3
301339
DEPENDS
302340
libc.src.__support.FPUtil.nearest_integer_operations
303-
COMPILE_OPTIONS
304-
-O2
305341
)
306342

307343
add_entrypoint_object(
@@ -310,10 +346,22 @@ add_entrypoint_object(
310346
roundl.cpp
311347
HDRS
312348
../roundl.h
349+
COMPILE_OPTIONS
350+
-O3
313351
DEPENDS
314352
libc.src.__support.FPUtil.nearest_integer_operations
353+
)
354+
355+
add_entrypoint_object(
356+
roundf128
357+
SRCS
358+
roundf128.cpp
359+
HDRS
360+
../roundf128.h
315361
COMPILE_OPTIONS
316-
-O2
362+
-O3
363+
DEPENDS
364+
libc.src.__support.FPUtil.nearest_integer_operations
317365
)
318366

319367
add_entrypoint_object(

libc/src/math/generic/ceilf128.cpp

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

libc/src/math/generic/floorf128.cpp

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

0 commit comments

Comments
 (0)