mirror of
https://github.com/intel/llvm.git
synced 2026-02-08 08:57:43 +08:00
[libc][math][c23] Add modff128 C23 math function. (#84532)
This commit is contained in:
@@ -434,6 +434,7 @@ if(LIBC_TYPES_HAS_FLOAT128)
|
||||
libc.src.math.llroundf128
|
||||
libc.src.math.lrintf128
|
||||
libc.src.math.lroundf128
|
||||
libc.src.math.modff128
|
||||
libc.src.math.rintf128
|
||||
libc.src.math.roundf128
|
||||
libc.src.math.sqrtf128
|
||||
|
||||
@@ -442,6 +442,7 @@ if(LIBC_TYPES_HAS_FLOAT128)
|
||||
libc.src.math.llroundf128
|
||||
libc.src.math.lrintf128
|
||||
libc.src.math.lroundf128
|
||||
libc.src.math.modff128
|
||||
libc.src.math.rintf128
|
||||
libc.src.math.roundf128
|
||||
libc.src.math.sqrtf128
|
||||
|
||||
@@ -472,6 +472,7 @@ if(LIBC_TYPES_HAS_FLOAT128)
|
||||
libc.src.math.llroundf128
|
||||
libc.src.math.lrintf128
|
||||
libc.src.math.lroundf128
|
||||
libc.src.math.modff128
|
||||
libc.src.math.rintf128
|
||||
libc.src.math.roundf128
|
||||
libc.src.math.sqrtf128
|
||||
|
||||
@@ -249,6 +249,8 @@ Basic Operations
|
||||
+--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
|
||||
| modfl | |check| | |check| | |check| | |check| | |check| | | | |check| | |check| | |check| | | |
|
||||
+--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
|
||||
| modff128 | |check| | |check| | | |check| | | | | | | | | |
|
||||
+--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
|
||||
| nan | |check| | |check| | |check| | |check| | |check| | | | |check| | |check| | |check| | | |
|
||||
+--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
|
||||
| nanf | |check| | |check| | |check| | |check| | |check| | | | |check| | |check| | |check| | | |
|
||||
|
||||
@@ -111,6 +111,7 @@ def IntPtr : PtrType<IntType>;
|
||||
def RestrictedIntPtr : RestrictedPtrType<IntType>;
|
||||
def FloatPtr : PtrType<FloatType>;
|
||||
def DoublePtr : PtrType<DoubleType>;
|
||||
def Float128Ptr : PtrType<Float128Type>;
|
||||
def UnsignedCharPtr : PtrType<UnsignedCharType>;
|
||||
|
||||
def SigHandlerT : NamedType<"__sighandler_t">;
|
||||
|
||||
@@ -451,6 +451,7 @@ def StdC : StandardSpec<"stdc"> {
|
||||
FunctionSpec<"modf", RetValSpec<DoubleType>, [ArgSpec<DoubleType>, ArgSpec<DoublePtr>]>,
|
||||
FunctionSpec<"modff", RetValSpec<FloatType>, [ArgSpec<FloatType>, ArgSpec<FloatPtr>]>,
|
||||
FunctionSpec<"modfl", RetValSpec<LongDoubleType>, [ArgSpec<LongDoubleType>, ArgSpec<LongDoublePtr>]>,
|
||||
GuardedFunctionSpec<"modff128", RetValSpec<Float128Type>, [ArgSpec<Float128Type>, ArgSpec<Float128Ptr>], "LIBC_TYPES_HAS_FLOAT128">,
|
||||
|
||||
FunctionSpec<"cos", RetValSpec<DoubleType>, [ArgSpec<DoubleType>]>,
|
||||
FunctionSpec<"cosf", RetValSpec<FloatType>, [ArgSpec<FloatType>]>,
|
||||
|
||||
@@ -183,6 +183,7 @@ add_math_entrypoint_object(lroundf128)
|
||||
add_math_entrypoint_object(modf)
|
||||
add_math_entrypoint_object(modff)
|
||||
add_math_entrypoint_object(modfl)
|
||||
add_math_entrypoint_object(modff128)
|
||||
|
||||
add_math_entrypoint_object(nan)
|
||||
add_math_entrypoint_object(nanf)
|
||||
|
||||
@@ -1407,7 +1407,7 @@ add_entrypoint_object(
|
||||
DEPENDS
|
||||
libc.src.__support.FPUtil.manipulation_functions
|
||||
COMPILE_OPTIONS
|
||||
-O2
|
||||
-O3
|
||||
)
|
||||
|
||||
add_entrypoint_object(
|
||||
@@ -1419,7 +1419,7 @@ add_entrypoint_object(
|
||||
DEPENDS
|
||||
libc.src.__support.FPUtil.manipulation_functions
|
||||
COMPILE_OPTIONS
|
||||
-O2
|
||||
-O3
|
||||
)
|
||||
|
||||
add_entrypoint_object(
|
||||
@@ -1431,7 +1431,20 @@ add_entrypoint_object(
|
||||
DEPENDS
|
||||
libc.src.__support.FPUtil.manipulation_functions
|
||||
COMPILE_OPTIONS
|
||||
-O2
|
||||
-O3
|
||||
)
|
||||
|
||||
add_entrypoint_object(
|
||||
modff128
|
||||
SRCS
|
||||
modff128.cpp
|
||||
HDRS
|
||||
../modff128.h
|
||||
DEPENDS
|
||||
libc.src.__support.macros.properties.types
|
||||
libc.src.__support.FPUtil.manipulation_functions
|
||||
COMPILE_OPTIONS
|
||||
-O3
|
||||
)
|
||||
|
||||
add_entrypoint_object(
|
||||
|
||||
19
libc/src/math/generic/modff128.cpp
Normal file
19
libc/src/math/generic/modff128.cpp
Normal file
@@ -0,0 +1,19 @@
|
||||
//===-- Implementation of modff128 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/modff128.h"
|
||||
#include "src/__support/FPUtil/ManipulationFunctions.h"
|
||||
#include "src/__support/common.h"
|
||||
|
||||
namespace LIBC_NAMESPACE {
|
||||
|
||||
LLVM_LIBC_FUNCTION(float128, modff128, (float128 x, float128 *iptr)) {
|
||||
return fputil::modf(x, *iptr);
|
||||
}
|
||||
|
||||
} // namespace LIBC_NAMESPACE
|
||||
20
libc/src/math/modff128.h
Normal file
20
libc/src/math/modff128.h
Normal file
@@ -0,0 +1,20 @@
|
||||
//===-- Implementation header for modff128 -----------------------*- 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_MODFF128_H
|
||||
#define LLVM_LIBC_SRC_MATH_MODFF128_H
|
||||
|
||||
#include "src/__support/macros/properties/types.h"
|
||||
|
||||
namespace LIBC_NAMESPACE {
|
||||
|
||||
float128 modff128(float128 x, float128 *iptr);
|
||||
|
||||
} // namespace LIBC_NAMESPACE
|
||||
|
||||
#endif // LLVM_LIBC_SRC_MATH_MODFF128_H
|
||||
@@ -1078,8 +1078,6 @@ add_fp_unittest(
|
||||
libc.src.math.modf
|
||||
libc.src.__support.FPUtil.basic_operations
|
||||
libc.src.__support.FPUtil.nearest_integer_operations
|
||||
# Requires C++ limits.
|
||||
UNIT_TEST_ONLY
|
||||
)
|
||||
|
||||
add_fp_unittest(
|
||||
@@ -1095,8 +1093,6 @@ add_fp_unittest(
|
||||
libc.src.math.modff
|
||||
libc.src.__support.FPUtil.basic_operations
|
||||
libc.src.__support.FPUtil.nearest_integer_operations
|
||||
# Requires C++ limits.
|
||||
UNIT_TEST_ONLY
|
||||
)
|
||||
|
||||
add_fp_unittest(
|
||||
@@ -1114,6 +1110,21 @@ add_fp_unittest(
|
||||
libc.src.__support.FPUtil.nearest_integer_operations
|
||||
)
|
||||
|
||||
add_fp_unittest(
|
||||
modff128_test
|
||||
SUITE
|
||||
libc-math-smoke-tests
|
||||
SRCS
|
||||
modff128_test.cpp
|
||||
HDRS
|
||||
ModfTest.h
|
||||
DEPENDS
|
||||
libc.include.math
|
||||
libc.src.math.modff128
|
||||
libc.src.__support.FPUtil.basic_operations
|
||||
libc.src.__support.FPUtil.nearest_integer_operations
|
||||
)
|
||||
|
||||
add_fp_unittest(
|
||||
fdimf_test
|
||||
SUITE
|
||||
|
||||
@@ -84,10 +84,12 @@ public:
|
||||
constexpr StorageType COUNT = 100'000;
|
||||
constexpr StorageType STEP = STORAGE_MAX / COUNT;
|
||||
for (StorageType i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
|
||||
T x = FPBits(v).get_val();
|
||||
if (isnan(x) || isinf(x) || x == T(0.0))
|
||||
FPBits x_bits = FPBits(v);
|
||||
if (x_bits.is_zero() || x_bits.is_inf_or_nan())
|
||||
continue;
|
||||
|
||||
T x = x_bits.get_val();
|
||||
|
||||
T integral;
|
||||
T frac = func(x, &integral);
|
||||
ASSERT_TRUE(LIBC_NAMESPACE::fputil::abs(frac) < 1.0l);
|
||||
|
||||
13
libc/test/src/math/smoke/modff128_test.cpp
Normal file
13
libc/test/src/math/smoke/modff128_test.cpp
Normal file
@@ -0,0 +1,13 @@
|
||||
//===-- Unittests for modff128 --------------------------------------------===//
|
||||
//
|
||||
// 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 "ModfTest.h"
|
||||
|
||||
#include "src/math/modff128.h"
|
||||
|
||||
LIST_MODF_TESTS(float128, LIBC_NAMESPACE::modff128)
|
||||
Reference in New Issue
Block a user