diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt index 8863749e12c6db..7ea70cad55a561 100644 --- a/libc/config/linux/aarch64/entrypoints.txt +++ b/libc/config/linux/aarch64/entrypoints.txt @@ -536,6 +536,7 @@ if(LIBC_TYPES_HAS_FLOAT16) # clang-12 and after: https://godbolt.org/z/8ceT9454c # libc.src.math.nexttowardf16 libc.src.math.nextupf16 + libc.src.math.remainderf16 libc.src.math.rintf16 libc.src.math.roundf16 libc.src.math.roundevenf16 diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt index 31ad0bc412836c..d2b73066ab04c4 100644 --- a/libc/config/linux/x86_64/entrypoints.txt +++ b/libc/config/linux/x86_64/entrypoints.txt @@ -566,6 +566,7 @@ if(LIBC_TYPES_HAS_FLOAT16) libc.src.math.nextdownf16 libc.src.math.nexttowardf16 libc.src.math.nextupf16 + libc.src.math.remainderf16 libc.src.math.rintf16 libc.src.math.roundf16 libc.src.math.roundevenf16 diff --git a/libc/docs/math/index.rst b/libc/docs/math/index.rst index 3e122fb8bc26e4..23e1555b531be9 100644 --- a/libc/docs/math/index.rst +++ b/libc/docs/math/index.rst @@ -198,7 +198,7 @@ Basic Operations +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+ | nextup | |check| | |check| | |check| | |check| | |check| | 7.12.11.5 | F.10.8.5 | +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+ -| remainder | |check| | |check| | |check| | | | 7.12.10.2 | F.10.7.2 | +| remainder | |check| | |check| | |check| | |check| | | 7.12.10.2 | F.10.7.2 | +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+ | remquo | |check| | |check| | |check| | | |check| | 7.12.10.3 | F.10.7.3 | +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+ diff --git a/libc/spec/stdc.td b/libc/spec/stdc.td index b5b6dbc481bd7e..430ed405f3fbea 100644 --- a/libc/spec/stdc.td +++ b/libc/spec/stdc.td @@ -581,9 +581,10 @@ def StdC : StandardSpec<"stdc"> { FunctionSpec<"exp10", RetValSpec, [ArgSpec]>, FunctionSpec<"exp10f", RetValSpec, [ArgSpec]>, - FunctionSpec<"remainderf", RetValSpec, [ArgSpec, ArgSpec]>, FunctionSpec<"remainder", RetValSpec, [ArgSpec, ArgSpec]>, + FunctionSpec<"remainderf", RetValSpec, [ArgSpec, ArgSpec]>, FunctionSpec<"remainderl", RetValSpec, [ArgSpec, ArgSpec]>, + GuardedFunctionSpec<"remainderf16", RetValSpec, [ArgSpec, ArgSpec], "LIBC_TYPES_HAS_FLOAT16">, FunctionSpec<"remquof", RetValSpec, [ArgSpec, ArgSpec, ArgSpec]>, GuardedFunctionSpec<"remquof128", RetValSpec, [ArgSpec, ArgSpec, ArgSpec], "LIBC_TYPES_HAS_FLOAT128">, diff --git a/libc/src/__support/FPUtil/NormalFloat.h b/libc/src/__support/FPUtil/NormalFloat.h index 33529d5e9b80a6..413d20430090bb 100644 --- a/libc/src/__support/FPUtil/NormalFloat.h +++ b/libc/src/__support/FPUtil/NormalFloat.h @@ -52,7 +52,7 @@ template struct NormalFloat { return; unsigned normalization_shift = evaluate_normalization_shift(mantissa); - mantissa = mantissa << normalization_shift; + mantissa <<= normalization_shift; exponent -= normalization_shift; } diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt index f8582d8d426833..6947e10bceadca 100644 --- a/libc/src/math/CMakeLists.txt +++ b/libc/src/math/CMakeLists.txt @@ -315,6 +315,7 @@ add_math_entrypoint_object(powf) add_math_entrypoint_object(remainder) add_math_entrypoint_object(remainderf) add_math_entrypoint_object(remainderl) +add_math_entrypoint_object(remainderf16) add_math_entrypoint_object(remquo) add_math_entrypoint_object(remquof) diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt index caaa0ac23dc7a0..24bf06ffab2c3e 100644 --- a/libc/src/math/generic/CMakeLists.txt +++ b/libc/src/math/generic/CMakeLists.txt @@ -2570,6 +2570,19 @@ add_entrypoint_object( -O2 ) +add_entrypoint_object( + remainderf16 + SRCS + remainderf16.cpp + HDRS + ../remainderf16.h + DEPENDS + libc.src.__support.macros.properties.types + libc.src.__support.FPUtil.division_and_remainder_operations + COMPILE_OPTIONS + -O2 +) + add_entrypoint_object( hypotf SRCS diff --git a/libc/src/math/generic/remainderf16.cpp b/libc/src/math/generic/remainderf16.cpp new file mode 100644 index 00000000000000..35177228acdbf5 --- /dev/null +++ b/libc/src/math/generic/remainderf16.cpp @@ -0,0 +1,20 @@ +//===-- Implementation of remainderf16 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/remainderf16.h" +#include "src/__support/FPUtil/DivisionAndRemainderOperations.h" +#include "src/__support/common.h" + +namespace LIBC_NAMESPACE { + +LLVM_LIBC_FUNCTION(float16, remainderf16, (float16 x, float16 y)) { + int quotient; + return fputil::remquo(x, y, quotient); +} + +} // namespace LIBC_NAMESPACE diff --git a/libc/src/math/remainderf16.h b/libc/src/math/remainderf16.h new file mode 100644 index 00000000000000..e23eead4bae2cc --- /dev/null +++ b/libc/src/math/remainderf16.h @@ -0,0 +1,20 @@ +//===-- Implementation header for remainderf16 ------------------*- 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_REMAINDERF16_H +#define LLVM_LIBC_SRC_MATH_REMAINDERF16_H + +#include "src/__support/macros/properties/types.h" + +namespace LIBC_NAMESPACE { + +float16 remainderf16(float16 x, float16 y); + +} // namespace LIBC_NAMESPACE + +#endif // LLVM_LIBC_SRC_MATH_REMAINDERF16_H