[libc][math][c23] Add fsub{,l,f128} and remainderf128 C23 math functions (#101576)

Co-authored-by: OverMighty <its.overmighty@gmail.com>
This commit is contained in:
aaryanshukla 2024-08-07 13:03:58 -07:00 committed by GitHub
parent 07ddf19438
commit 2c74237c0f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
28 changed files with 413 additions and 6 deletions

View File

@ -185,6 +185,8 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.frexp
libc.src.math.frexpf
libc.src.math.frexpl
libc.src.math.fsub
libc.src.math.fsubl
libc.src.math.hypot
libc.src.math.hypotf
libc.src.math.ilogb

View File

@ -152,6 +152,8 @@ set(TARGET_LIBM_ENTRYPOINTS
#libc.src.math.frexp
#libc.src.math.frexpf
#libc.src.math.frexpl
#libc.src.math.fsub
#libc.src.math.fsubl
#libc.src.math.hypot
#libc.src.math.hypotf
#libc.src.math.ilogb

View File

@ -461,6 +461,8 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.fromfpxl
libc.src.math.fsqrt
libc.src.math.fsqrtl
libc.src.math.fsub
libc.src.math.fsubl
libc.src.math.getpayload
libc.src.math.getpayloadf
libc.src.math.getpayloadl
@ -701,6 +703,7 @@ if(LIBC_TYPES_HAS_FLOAT128)
libc.src.math.fromfpf128
libc.src.math.fromfpxf128
libc.src.math.fsqrtf128
libc.src.math.fsubf128
libc.src.math.getpayloadf128
libc.src.math.ilogbf128
libc.src.math.ldexpf128
@ -716,6 +719,7 @@ if(LIBC_TYPES_HAS_FLOAT128)
libc.src.math.nextafterf128
libc.src.math.nextdownf128
libc.src.math.nextupf128
libc.src.math.remainderf128
libc.src.math.remquof128
libc.src.math.rintf128
libc.src.math.roundevenf128

View File

@ -297,6 +297,8 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.fromfpx
libc.src.math.fromfpxf
libc.src.math.fromfpxl
libc.src.math.fsub
libc.src.math.fsubl
libc.src.math.getpayload
libc.src.math.getpayloadf
libc.src.math.getpayloadl

View File

@ -464,6 +464,8 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.fromfpxl
libc.src.math.fsqrt
libc.src.math.fsqrtl
libc.src.math.fsub
libc.src.math.fsubl
libc.src.math.getpayload
libc.src.math.getpayloadf
libc.src.math.getpayloadl
@ -608,6 +610,7 @@ if(LIBC_TYPES_HAS_FLOAT128)
libc.src.math.fromfpf128
libc.src.math.fromfpxf128
libc.src.math.fsqrtf128
libc.src.math.fsubf128
libc.src.math.getpayloadf128
libc.src.math.ilogbf128
libc.src.math.ldexpf128
@ -623,6 +626,7 @@ if(LIBC_TYPES_HAS_FLOAT128)
libc.src.math.nextafterf128
libc.src.math.nextdownf128
libc.src.math.nextupf128
libc.src.math.remainderf128
libc.src.math.remquof128
libc.src.math.rintf128
libc.src.math.roundevenf128

View File

@ -464,6 +464,8 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.fromfpxl
libc.src.math.fsqrt
libc.src.math.fsqrtl
libc.src.math.fsub
libc.src.math.fsubl
libc.src.math.getpayload
libc.src.math.getpayloadf
libc.src.math.getpayloadl
@ -697,6 +699,7 @@ if(LIBC_TYPES_HAS_FLOAT128)
libc.src.math.fromfpf128
libc.src.math.fromfpxf128
libc.src.math.fsqrtf128
libc.src.math.fsubf128
libc.src.math.getpayloadf128
libc.src.math.ilogbf128
libc.src.math.ldexpf128
@ -712,6 +715,7 @@ if(LIBC_TYPES_HAS_FLOAT128)
libc.src.math.nextafterf128
libc.src.math.nextdownf128
libc.src.math.nextupf128
libc.src.math.remainderf128
libc.src.math.remquof128
libc.src.math.rintf128
libc.src.math.roundevenf128

View File

@ -201,6 +201,8 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.frexp
libc.src.math.frexpf
libc.src.math.frexpl
libc.src.math.fsub
libc.src.math.fsubl
libc.src.math.hypot
libc.src.math.hypotf
libc.src.math.ilogb

View File

@ -118,7 +118,7 @@ Basic Operations
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
| ddiv | N/A | N/A | | N/A | |check|\* | 7.12.14.4 | F.10.11 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
| dfma | N/A | N/A | |check| | N/A | |check|\* | 7.12.14.5 | F.10.11 |
| dfma | N/A | N/A | |check| | N/A | |check|\* | 7.12.14.5 | F.10.11 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
| dmul | N/A | N/A | |check| | N/A | |check|\* | 7.12.14.3 | F.10.11 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
@ -176,7 +176,7 @@ Basic Operations
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
| fromfpx | |check| | |check| | |check| | |check| | |check| | 7.12.9.11 | F.10.6.11 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
| fsub | N/A | | | N/A | | 7.12.14.2 | F.10.11 |
| fsub | N/A | |check| | |check| | N/A | |check|\* | 7.12.14.2 | F.10.11 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
| getpayload | |check| | |check| | |check| | |check| | |check| | F.10.13.1 | N/A |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
@ -210,7 +210,7 @@ Basic Operations
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
| nextup | |check| | |check| | |check| | |check| | |check| | 7.12.11.5 | F.10.8.5 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
| remainder | |check| | |check| | |check| | |check| | | 7.12.10.2 | F.10.7.2 |
| remainder | |check| | |check| | |check| | |check| | |check| | 7.12.10.2 | F.10.7.2 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
| remquo | |check| | |check| | |check| | |check| | |check| | 7.12.10.3 | F.10.7.3 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+

View File

@ -794,6 +794,14 @@ functions:
arguments:
- type: long double
- type: long double
- name: remainderf128
standards:
- stdc
return_type: float128
arguments:
- type: float128
- type: float128
guard: LIBC_TYPES_HAS_FLOAT128
- name: remquo
standards:
- stdc
@ -1540,6 +1548,28 @@ functions:
- type: int
- type: unsigned int
guard: LIBC_TYPES_HAS_FLOAT16
- name: fsub
standards:
- stdc
return_type: float
arguments:
- type: double
- type: double
- name: fsubl
standards:
- stdc
return_type: float
arguments:
- type: long double
- type: long double
- name: fsubf128
standards:
- llvm_libc_ext
return_type: float
arguments:
- type: float128
- type: float128
guard: LIBC_TYPES_HAS_FLOAT128
- name: getpayload
standards:
- stdc

View File

@ -98,6 +98,8 @@ def LLVMLibcExt : StandardSpec<"llvm_libc_ext"> {
GuardedFunctionSpec<"fsqrtf128", RetValSpec<FloatType>, [ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,
FunctionSpec<"fsubf128", RetValSpec<FloatType>, [ArgSpec<Float128Type>, ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,
FunctionSpec<"powi", RetValSpec<DoubleType>, [ArgSpec<DoubleType>, ArgSpec<IntType>]>,
FunctionSpec<"powif", RetValSpec<FloatType>, [ArgSpec<FloatType>, ArgSpec<IntType>]>,
]

View File

@ -516,6 +516,9 @@ def StdC : StandardSpec<"stdc"> {
GuardedFunctionSpec<"fromfpxf16", RetValSpec<Float16Type>, [ArgSpec<Float16Type>, ArgSpec<IntType>, ArgSpec<UnsignedIntType>], "LIBC_TYPES_HAS_FLOAT16">,
GuardedFunctionSpec<"fromfpxf128", RetValSpec<Float128Type>, [ArgSpec<Float128Type>, ArgSpec<IntType>, ArgSpec<UnsignedIntType>], "LIBC_TYPES_HAS_FLOAT128">,
FunctionSpec<"fsub", RetValSpec<FloatType>, [ArgSpec<DoubleType>, ArgSpec<DoubleType>]>,
FunctionSpec<"fsubl", RetValSpec<FloatType>, [ArgSpec<LongDoubleType>, ArgSpec<LongDoubleType>]>,
FunctionSpec<"ufromfp", RetValSpec<DoubleType>, [ArgSpec<DoubleType>, ArgSpec<IntType>, ArgSpec<UnsignedIntType>]>,
FunctionSpec<"ufromfpf", RetValSpec<FloatType>, [ArgSpec<FloatType>, ArgSpec<IntType>, ArgSpec<UnsignedIntType>]>,
FunctionSpec<"ufromfpl", RetValSpec<LongDoubleType>, [ArgSpec<LongDoubleType>, ArgSpec<IntType>, ArgSpec<UnsignedIntType>]>,
@ -603,6 +606,7 @@ def StdC : StandardSpec<"stdc"> {
FunctionSpec<"remainderf", RetValSpec<FloatType>, [ArgSpec<FloatType>, ArgSpec<FloatType>]>,
FunctionSpec<"remainderl", RetValSpec<LongDoubleType>, [ArgSpec<LongDoubleType>, ArgSpec<LongDoubleType>]>,
GuardedFunctionSpec<"remainderf16", RetValSpec<Float16Type>, [ArgSpec<Float16Type>, ArgSpec<Float16Type>], "LIBC_TYPES_HAS_FLOAT16">,
GuardedFunctionSpec<"remainderf128", RetValSpec<Float128Type, [ArgSpec<Float128Type>, ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,
FunctionSpec<"remquo", RetValSpec<DoubleType>, [ArgSpec<DoubleType>, ArgSpec<DoubleType>, ArgSpec<IntPtr>]>,
FunctionSpec<"remquof", RetValSpec<FloatType>, [ArgSpec<FloatType>, ArgSpec<FloatType>, ArgSpec<IntPtr>]>,

View File

@ -273,6 +273,10 @@ add_math_entrypoint_object(fromfpxl)
add_math_entrypoint_object(fromfpxf16)
add_math_entrypoint_object(fromfpxf128)
add_math_entrypoint_object(fsub)
add_math_entrypoint_object(fsubl)
add_math_entrypoint_object(fsubf128)
add_math_entrypoint_object(getpayload)
add_math_entrypoint_object(getpayloadf)
add_math_entrypoint_object(getpayloadl)
@ -396,6 +400,7 @@ add_math_entrypoint_object(remainder)
add_math_entrypoint_object(remainderf)
add_math_entrypoint_object(remainderl)
add_math_entrypoint_object(remainderf16)
add_math_entrypoint_object(remainderf128)
add_math_entrypoint_object(remquo)
add_math_entrypoint_object(remquof)

20
libc/src/math/fsub.h Normal file
View File

@ -0,0 +1,20 @@
//===-- Implementation header for fsub --------------------------*- 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_FSUB_H
#define LLVM_LIBC_SRC_MATH_FSUB_H
#include "src/__support/macros/config.h"
namespace LIBC_NAMESPACE_DECL {
float fsub(double x, double y);
} // namespace LIBC_NAMESPACE_DECL
#endif // LLVM_LIBC_SRC_MATH_FSUB_H

21
libc/src/math/fsubf128.h Normal file
View File

@ -0,0 +1,21 @@
//===-- Implementation header for fsubf128 ----------------------*- 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_FSUBF128_H
#define LLVM_LIBC_SRC_MATH_FSUBF128_H
#include "src/__support/macros/config.h"
#include "src/__support/macros/properties/types.h"
namespace LIBC_NAMESPACE_DECL {
float fsubf128(float128 x, float128 y);
} // namespace LIBC_NAMESPACE_DECL
#endif // LLVM_LIBC_SRC_MATH_FSUBF128_H

20
libc/src/math/fsubl.h Normal file
View File

@ -0,0 +1,20 @@
//===-- Implementation header for fsubl -------------------------*- 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_FSUBL_H
#define LLVM_LIBC_SRC_MATH_FSUBL_H
#include "src/__support/macros/config.h"
namespace LIBC_NAMESPACE_DECL {
float fsubl(long double x, long double y);
} // namespace LIBC_NAMESPACE_DECL
#endif // LLVM_LIBC_SRC_MATH_FSUBL_H

View File

@ -2931,6 +2931,43 @@ add_entrypoint_object(
-O3
)
add_entrypoint_object(
fsub
SRCS
fsub.cpp
HDRS
../fsub.h
DEPENDS
libc.src.__support.FPUtil.generic.add_sub
COMPILE_OPTIONS
-O3
)
add_entrypoint_object(
fsubl
SRCS
fsubl.cpp
HDRS
../fsubl.h
DEPENDS
libc.src.__support.FPUtil.generic.add_sub
COMPILE_OPTIONS
-O3
)
add_entrypoint_object(
fsubf128
SRCS
fsubf128.cpp
HDRS
../fsubf128.h
DEPENDS
libc.src.__support.macros.properties.types
libc.src.__support.FPUtil.generic.add_sub
COMPILE_OPTIONS
-O3
)
add_entrypoint_object(
sqrt
SRCS
@ -3091,6 +3128,19 @@ add_entrypoint_object(
-O3
)
add_entrypoint_object(
remainderf128
SRCS
remainderf128.cpp
HDRS
../remainderf128.h
DEPENDS
libc.src.__support.macros.properties.types
libc.src.__support.FPUtil.division_and_remainder_operations
COMPILE_OPTIONS
-O3
)
add_entrypoint_object(
hypotf
SRCS

View File

@ -0,0 +1,20 @@
//===-- Implementation of fsub 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/fsub.h"
#include "src/__support/FPUtil/generic/add_sub.h"
#include "src/__support/common.h"
#include "src/__support/macros/config.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(float, fsub, (double x, double y)) {
return fputil::generic::sub<float>(x, y);
}
} // namespace LIBC_NAMESPACE_DECL

View File

@ -0,0 +1,20 @@
//===-- Implementation of fsubf128 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/fsubf128.h"
#include "src/__support/FPUtil/generic/add_sub.h"
#include "src/__support/common.h"
#include "src/__support/macros/config.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(float, fsubf128, (float128 x, float128 y)) {
return fputil::generic::sub<float>(x, y);
}
} // namespace LIBC_NAMESPACE_DECL

View File

@ -0,0 +1,20 @@
//===-- Implementation of fsubl 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/fsubl.h"
#include "src/__support/FPUtil/generic/add_sub.h"
#include "src/__support/common.h"
#include "src/__support/macros/config.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(float, fsubl, (long double x, long double y)) {
return fputil::generic::sub<float>(x, y);
}
} // namespace LIBC_NAMESPACE_DECL

View File

@ -0,0 +1,21 @@
//===-- Implementation of remainderf128 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/remainderf128.h"
#include "src/__support/FPUtil/DivisionAndRemainderOperations.h"
#include "src/__support/common.h"
#include "src/__support/macros/config.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(float128, remainderf128, (float128 x, float128 y)) {
int quotient;
return fputil::remquo(x, y, quotient);
}
} // namespace LIBC_NAMESPACE_DECL

View File

@ -0,0 +1,21 @@
//===-- Implementation header for remainderf128 -----------------*- 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_REMAINDERF128_H
#define LLVM_LIBC_SRC_MATH_REMAINDERF128_H
#include "src/__support/macros/config.h"
#include "src/__support/macros/properties/types.h"
namespace LIBC_NAMESPACE_DECL {
float128 remainderf128(float128 x, float128 y);
} // namespace LIBC_NAMESPACE_DECL
#endif // LLVM_LIBC_SRC_MATH_REMAINDERF128_H

View File

@ -2341,6 +2341,32 @@ add_fp_unittest(
libc.src.math.fsqrtl
)
add_fp_unittest(
fsub_test
NEED_MPFR
SUITE
libc-math-unittests
SRCS
fsub_test.cpp
HDRS
SubTest.h
DEPENDS
libc.src.math.fsub
)
add_fp_unittest(
fsubl_test
NEED_MPFR
SUITE
libc-math-unittests
SRCS
fsubl_test.cpp
HDRS
SubTest.h
DEPENDS
libc.src.math.fsubl
)
add_fp_unittest(
dsqrtl_test
NEED_MPFR

View File

@ -0,0 +1,13 @@
//===-- Unittests for fsub ------------------------------------------------===//
//
// 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 "SubTest.h"
#include "src/math/fsub.h"
LIST_SUB_TESTS(float, double, LIBC_NAMESPACE::fsub)

View File

@ -0,0 +1,13 @@
//===-- Unittests for fsubl -----------------------------------------------===//
//
// 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 "SubTest.h"
#include "src/math/fsubl.h"
LIST_SUB_TESTS(float, long double, LIBC_NAMESPACE::fsubl)

View File

@ -4352,6 +4352,48 @@ add_fp_unittest(
libc.src.math.fsqrtf128
)
add_fp_unittest(
fsub_test
SUITE
libc-math-smoke-tests
SRCS
fsub_test.cpp
HDRS
SubTest.h
DEPENDS
libc.hdr.errno_macros
libc.hdr.fenv_macros
libc.src.math.fsub
)
add_fp_unittest(
fsubl_test
SUITE
libc-math-smoke-tests
SRCS
fsubl_test.cpp
HDRS
SubTest.h
DEPENDS
libc.hdr.errno_macros
libc.hdr.fenv_macros
libc.src.math.fsubl
)
add_fp_unittest(
fsubf128_test
SUITE
libc-math-smoke-tests
SRCS
fsubf128_test.cpp
HDRS
SubTest.h
DEPENDS
libc.hdr.errno_macros
libc.hdr.fenv_macros
libc.src.math.fsubf128
)
add_fp_unittest(
dsqrtl_test
SUITE

View File

@ -0,0 +1,13 @@
//===-- Unittests for fsub ------------------------------------------------===//
//
// 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 "SubTest.h"
#include "src/math/fsub.h"
LIST_SUB_TESTS(float, double, LIBC_NAMESPACE::fsub)

View File

@ -0,0 +1,13 @@
//===-- Unittests for fsubf128 --------------------------------------------===//
//
// 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 "SubTest.h"
#include "src/math/fsubf128.h"
LIST_SUB_TESTS(float, float128, LIBC_NAMESPACE::fsubf128)

View File

@ -0,0 +1,13 @@
//===-- Unittests for fsubl -----------------------------------------------===//
//
// 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 "SubTest.h"
#include "src/math/fsubl.h"
LIST_SUB_TESTS(float, long double, LIBC_NAMESPACE::fsubl)