Skip to content

[libc][math] Add float128 rounding functions (ceilf128, floorf128, roundf128, truncf128). #80634

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion libc/config/linux/x86_64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -397,11 +397,15 @@ set(TARGET_LIBM_ENTRYPOINTS
if(LIBC_COMPILER_HAS_FLOAT128)
list(APPEND TARGET_LIBM_ENTRYPOINTS
# math.h C23 _Float128 entrypoints
libc.src.math.ceilf128
libc.src.math.copysignf128
libc.src.math.fabsf128
libc.src.math.sqrtf128
libc.src.math.floorf128
libc.src.math.fmaxf128
libc.src.math.fminf128
libc.src.math.roundf128
libc.src.math.sqrtf128
libc.src.math.truncf128
)
endif()

Expand Down
8 changes: 8 additions & 0 deletions libc/docs/math/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ Basic Operations
+--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
| ceill | |check| | |check| | |check| | |check| | |check| | | | |check| | |check| | |check| | | |
+--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
| ceilf128 | |check| | | | | | | | | | | | |
+--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
| copysign | |check| | |check| | |check| | |check| | |check| | | | |check| | |check| | |check| | | |
+--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
| copysignf | |check| | |check| | |check| | |check| | |check| | | | |check| | |check| | |check| | | |
Expand Down Expand Up @@ -142,6 +144,8 @@ Basic Operations
+--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
| floorl | |check| | |check| | |check| | |check| | |check| | | | |check| | |check| | |check| | | |
+--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
| floorf128 | |check| | | | | | | | | | | | |
+--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
| fmax | |check| | |check| | |check| | |check| | |check| | | | |check| | |check| | |check| | | |
+--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
| fmaxf | |check| | |check| | |check| | |check| | |check| | | | |check| | |check| | |check| | | |
Expand Down Expand Up @@ -266,6 +270,8 @@ Basic Operations
+--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
| roundl | |check| | |check| | |check| | |check| | |check| | | | |check| | |check| | |check| | | |
+--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
| roundf128 | |check| | | | | | | | | | | | |
+--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
| scalbn | |check| | |check| | |check| | |check| | |check| | | | |check| | |check| | |check| | | |
+--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
| scalbnf | |check| | |check| | |check| | |check| | |check| | | | |check| | |check| | |check| | | |
Expand All @@ -278,6 +284,8 @@ Basic Operations
+--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
| truncl | |check| | |check| | |check| | |check| | |check| | | | |check| | |check| | |check| | | |
+--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
| truncf128 | |check| | | | | | | | | | | | |
+--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+


Higher Math Functions
Expand Down
4 changes: 4 additions & 0 deletions libc/spec/stdc.td
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ def StdC : StandardSpec<"stdc"> {
FunctionSpec<"ceil", RetValSpec<DoubleType>, [ArgSpec<DoubleType>]>,
FunctionSpec<"ceilf", RetValSpec<FloatType>, [ArgSpec<FloatType>]>,
FunctionSpec<"ceill", RetValSpec<LongDoubleType>, [ArgSpec<LongDoubleType>]>,
FunctionSpec<"ceilf128", RetValSpec<Float128Type>, [ArgSpec<Float128Type>]>,

FunctionSpec<"fabs", RetValSpec<DoubleType>, [ArgSpec<DoubleType>]>,
FunctionSpec<"fabsf", RetValSpec<FloatType>, [ArgSpec<FloatType>]>,
Expand All @@ -376,6 +377,7 @@ def StdC : StandardSpec<"stdc"> {
FunctionSpec<"floor", RetValSpec<DoubleType>, [ArgSpec<DoubleType>]>,
FunctionSpec<"floorf", RetValSpec<FloatType>, [ArgSpec<FloatType>]>,
FunctionSpec<"floorl", RetValSpec<LongDoubleType>, [ArgSpec<LongDoubleType>]>,
FunctionSpec<"floorf128", RetValSpec<Float128Type>, [ArgSpec<Float128Type>]>,

FunctionSpec<"fmin", RetValSpec<DoubleType>, [ArgSpec<DoubleType>, ArgSpec<DoubleType>]>,
FunctionSpec<"fminf", RetValSpec<FloatType>, [ArgSpec<FloatType>, ArgSpec<FloatType>]>,
Expand Down Expand Up @@ -458,6 +460,7 @@ def StdC : StandardSpec<"stdc"> {
FunctionSpec<"round", RetValSpec<DoubleType>, [ArgSpec<DoubleType>]>,
FunctionSpec<"roundf", RetValSpec<FloatType>, [ArgSpec<FloatType>]>,
FunctionSpec<"roundl", RetValSpec<LongDoubleType>, [ArgSpec<LongDoubleType>]>,
FunctionSpec<"roundf128", RetValSpec<Float128Type>, [ArgSpec<Float128Type>]>,

FunctionSpec<"lround", RetValSpec<LongType>, [ArgSpec<DoubleType>]>,
FunctionSpec<"lroundf", RetValSpec<LongType>, [ArgSpec<FloatType>]>,
Expand Down Expand Up @@ -487,6 +490,7 @@ def StdC : StandardSpec<"stdc"> {
FunctionSpec<"trunc", RetValSpec<DoubleType>, [ArgSpec<DoubleType>]>,
FunctionSpec<"truncf", RetValSpec<FloatType>, [ArgSpec<FloatType>]>,
FunctionSpec<"truncl", RetValSpec<LongDoubleType>, [ArgSpec<LongDoubleType>]>,
FunctionSpec<"truncf128", RetValSpec<Float128Type>, [ArgSpec<Float128Type>]>,

FunctionSpec<"nearbyint", RetValSpec<DoubleType>, [ArgSpec<DoubleType>]>,
FunctionSpec<"nearbyintf", RetValSpec<FloatType>, [ArgSpec<FloatType>]>,
Expand Down
4 changes: 4 additions & 0 deletions libc/src/math/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ add_math_entrypoint_object(atanhf)
add_math_entrypoint_object(ceil)
add_math_entrypoint_object(ceilf)
add_math_entrypoint_object(ceill)
add_math_entrypoint_object(ceilf128)

add_math_entrypoint_object(copysign)
add_math_entrypoint_object(copysignf)
Expand Down Expand Up @@ -114,6 +115,7 @@ add_math_entrypoint_object(fdiml)
add_math_entrypoint_object(floor)
add_math_entrypoint_object(floorf)
add_math_entrypoint_object(floorl)
add_math_entrypoint_object(floorf128)

add_math_entrypoint_object(fma)
add_math_entrypoint_object(fmaf)
Expand Down Expand Up @@ -216,6 +218,7 @@ add_math_entrypoint_object(rintl)
add_math_entrypoint_object(round)
add_math_entrypoint_object(roundf)
add_math_entrypoint_object(roundl)
add_math_entrypoint_object(roundf128)

add_math_entrypoint_object(scalbn)
add_math_entrypoint_object(scalbnf)
Expand Down Expand Up @@ -247,3 +250,4 @@ add_math_entrypoint_object(tgammaf)
add_math_entrypoint_object(trunc)
add_math_entrypoint_object(truncf)
add_math_entrypoint_object(truncl)
add_math_entrypoint_object(truncf128)
20 changes: 20 additions & 0 deletions libc/src/math/ceilf128.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//===-- Implementation header for ceilf128 ----------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_SRC_MATH_CEILF128_H
#define LLVM_LIBC_SRC_MATH_CEILF128_H

#include "src/__support/macros/properties/float.h"

namespace LIBC_NAMESPACE {

float128 ceilf128(float128 x);

} // namespace LIBC_NAMESPACE

#endif // LLVM_LIBC_SRC_MATH_CEILF128_H
20 changes: 20 additions & 0 deletions libc/src/math/floorf128.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//===-- Implementation header for floorf128 ---------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_SRC_MATH_FLOORF128_H
#define LLVM_LIBC_SRC_MATH_FLOORF128_H

#include "src/__support/macros/properties/float.h"

namespace LIBC_NAMESPACE {

float128 floorf128(float128 x);

} // namespace LIBC_NAMESPACE

#endif // LLVM_LIBC_SRC_MATH_FLOORF128_H
88 changes: 68 additions & 20 deletions libc/src/math/generic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ add_entrypoint_object(
ceil.cpp
HDRS
../ceil.h
COMPILE_OPTIONS
-O3
DEPENDS
libc.src.__support.FPUtil.nearest_integer_operations
COMPILE_OPTIONS
-O2
)

add_entrypoint_object(
Expand All @@ -16,10 +16,10 @@ add_entrypoint_object(
ceilf.cpp
HDRS
../ceilf.h
COMPILE_OPTIONS
-O3
DEPENDS
libc.src.__support.FPUtil.nearest_integer_operations
COMPILE_OPTIONS
-O2
)

add_entrypoint_object(
Expand All @@ -28,10 +28,22 @@ add_entrypoint_object(
ceill.cpp
HDRS
../ceill.h
COMPILE_OPTIONS
-O3
DEPENDS
libc.src.__support.FPUtil.nearest_integer_operations
)

add_entrypoint_object(
ceilf128
SRCS
ceilf128.cpp
HDRS
../ceilf128.h
COMPILE_OPTIONS
-O2
-O3
DEPENDS
libc.src.__support.FPUtil.nearest_integer_operations
)

add_object_library(
Expand Down Expand Up @@ -214,10 +226,10 @@ add_entrypoint_object(
trunc.cpp
HDRS
../trunc.h
COMPILE_OPTIONS
-O3
DEPENDS
libc.src.__support.FPUtil.nearest_integer_operations
COMPILE_OPTIONS
-O2
)

add_entrypoint_object(
Expand All @@ -226,10 +238,10 @@ add_entrypoint_object(
truncf.cpp
HDRS
../truncf.h
COMPILE_OPTIONS
-O3
DEPENDS
libc.src.__support.FPUtil.nearest_integer_operations
COMPILE_OPTIONS
-O2
)

add_entrypoint_object(
Expand All @@ -238,10 +250,22 @@ add_entrypoint_object(
truncl.cpp
HDRS
../truncl.h
COMPILE_OPTIONS
-O3
DEPENDS
libc.src.__support.FPUtil.nearest_integer_operations
)

add_entrypoint_object(
truncf128
SRCS
truncf128.cpp
HDRS
../truncf128.h
COMPILE_OPTIONS
-O2
-O3
DEPENDS
libc.src.__support.FPUtil.nearest_integer_operations
)

add_entrypoint_object(
Expand All @@ -250,10 +274,10 @@ add_entrypoint_object(
floor.cpp
HDRS
../floor.h
COMPILE_OPTIONS
-O3
DEPENDS
libc.src.__support.FPUtil.nearest_integer_operations
COMPILE_OPTIONS
-O2
)

add_entrypoint_object(
Expand All @@ -262,10 +286,10 @@ add_entrypoint_object(
floorf.cpp
HDRS
../floorf.h
COMPILE_OPTIONS
-O3
DEPENDS
libc.src.__support.FPUtil.nearest_integer_operations
COMPILE_OPTIONS
-O2
)

add_entrypoint_object(
Expand All @@ -274,10 +298,22 @@ add_entrypoint_object(
floorl.cpp
HDRS
../floorl.h
COMPILE_OPTIONS
-O3
DEPENDS
libc.src.__support.FPUtil.nearest_integer_operations
)

add_entrypoint_object(
floorf128
SRCS
floorf128.cpp
HDRS
../floorf128.h
COMPILE_OPTIONS
-O2
-O3
DEPENDS
libc.src.__support.FPUtil.nearest_integer_operations
)

add_entrypoint_object(
Expand All @@ -286,10 +322,10 @@ add_entrypoint_object(
round.cpp
HDRS
../round.h
COMPILE_OPTIONS
-O3
DEPENDS
libc.src.__support.FPUtil.nearest_integer_operations
COMPILE_OPTIONS
-O2
)

add_entrypoint_object(
Expand All @@ -298,10 +334,10 @@ add_entrypoint_object(
roundf.cpp
HDRS
../roundf.h
COMPILE_OPTIONS
-O3
DEPENDS
libc.src.__support.FPUtil.nearest_integer_operations
COMPILE_OPTIONS
-O2
)

add_entrypoint_object(
Expand All @@ -310,10 +346,22 @@ add_entrypoint_object(
roundl.cpp
HDRS
../roundl.h
COMPILE_OPTIONS
-O3
DEPENDS
libc.src.__support.FPUtil.nearest_integer_operations
)

add_entrypoint_object(
roundf128
SRCS
roundf128.cpp
HDRS
../roundf128.h
COMPILE_OPTIONS
-O2
-O3
DEPENDS
libc.src.__support.FPUtil.nearest_integer_operations
)

add_entrypoint_object(
Expand Down
17 changes: 17 additions & 0 deletions libc/src/math/generic/ceilf128.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//===-- Implementation of ceilf128 function -------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "src/math/ceilf128.h"
#include "src/__support/FPUtil/NearestIntegerOperations.h"
#include "src/__support/common.h"

namespace LIBC_NAMESPACE {

LLVM_LIBC_FUNCTION(float128, ceilf128, (float128 x)) { return fputil::ceil(x); }

} // namespace LIBC_NAMESPACE
19 changes: 19 additions & 0 deletions libc/src/math/generic/floorf128.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//===-- Implementation of floorf128 function ------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "src/math/floorf128.h"
#include "src/__support/FPUtil/NearestIntegerOperations.h"
#include "src/__support/common.h"

namespace LIBC_NAMESPACE {

LLVM_LIBC_FUNCTION(float128, floorf128, (float128 x)) {
return fputil::floor(x);
}

} // namespace LIBC_NAMESPACE
Loading