Skip to content

[libc] Add fminf128 and fmaxf128 implementations for Linux x86_64. #79307

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 2 commits into from
Jan 25, 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
2 changes: 2 additions & 0 deletions libc/config/linux/x86_64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,8 @@ if(LIBC_COMPILER_HAS_FLOAT128)
libc.src.math.copysignf128
libc.src.math.fabsf128
libc.src.math.sqrtf128
libc.src.math.fmaxf128
libc.src.math.fminf128
)
endif()

Expand Down
4 changes: 4 additions & 0 deletions libc/docs/math/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,16 @@ Basic Operations
+--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
| fmaxf | |check| | |check| | |check| | |check| | |check| | | | |check| | |check| | |check| | | |
+--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
| fmaxf128 | |check| | | | | | | | | | | | |
+--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
| fmaxl | |check| | |check| | |check| | |check| | |check| | | | |check| | |check| | |check| | | |
+--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
| fmin | |check| | |check| | |check| | |check| | |check| | | | |check| | |check| | |check| | | |
+--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
| fminf | |check| | |check| | |check| | |check| | |check| | | | |check| | |check| | |check| | | |
+--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
| fminf128 | |check| | | | | | | | | | | | |
+--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
| fminl | |check| | |check| | |check| | |check| | |check| | | | |check| | |check| | |check| | | |
+--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
| fmod | |check| | |check| | |check| | |check| | |check| | | | |check| | |check| | |check| | | |
Expand Down
2 changes: 2 additions & 0 deletions libc/spec/stdc.td
Original file line number Diff line number Diff line change
Expand Up @@ -380,10 +380,12 @@ def StdC : StandardSpec<"stdc"> {
FunctionSpec<"fmin", RetValSpec<DoubleType>, [ArgSpec<DoubleType>, ArgSpec<DoubleType>]>,
FunctionSpec<"fminf", RetValSpec<FloatType>, [ArgSpec<FloatType>, ArgSpec<FloatType>]>,
FunctionSpec<"fminl", RetValSpec<LongDoubleType>, [ArgSpec<LongDoubleType>, ArgSpec<LongDoubleType>]>,
FunctionSpec<"fminf128", RetValSpec<Float128Type>, [ArgSpec<Float128Type>, ArgSpec<Float128Type>]>,

FunctionSpec<"fmax", RetValSpec<DoubleType>, [ArgSpec<DoubleType>, ArgSpec<DoubleType>]>,
FunctionSpec<"fmaxf", RetValSpec<FloatType>, [ArgSpec<FloatType>, ArgSpec<FloatType>]>,
FunctionSpec<"fmaxl", RetValSpec<LongDoubleType>, [ArgSpec<LongDoubleType>, ArgSpec<LongDoubleType>]>,
FunctionSpec<"fmaxf128", RetValSpec<Float128Type>, [ArgSpec<Float128Type>, ArgSpec<Float128Type>]>,

FunctionSpec<"fma", RetValSpec<DoubleType>, [ArgSpec<DoubleType>, ArgSpec<DoubleType>, ArgSpec<DoubleType>]>,
FunctionSpec<"fmaf", RetValSpec<FloatType>, [ArgSpec<FloatType>, ArgSpec<FloatType>, ArgSpec<FloatType>]>,
Expand Down
2 changes: 2 additions & 0 deletions libc/src/math/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,12 @@ add_math_entrypoint_object(fmaf)
add_math_entrypoint_object(fmax)
add_math_entrypoint_object(fmaxf)
add_math_entrypoint_object(fmaxl)
add_math_entrypoint_object(fmaxf128)

add_math_entrypoint_object(fmin)
add_math_entrypoint_object(fminf)
add_math_entrypoint_object(fminl)
add_math_entrypoint_object(fminf128)

add_math_entrypoint_object(fmod)
add_math_entrypoint_object(fmodf)
Expand Down
20 changes: 20 additions & 0 deletions libc/src/math/fmaxf128.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//===-- Implementation header for fmaxf128 ----------------------*- 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_FMAXF128_H
#define LLVM_LIBC_SRC_MATH_FMAXF128_H

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

namespace LIBC_NAMESPACE {

float128 fmaxf128(float128 x, float128 y);

} // namespace LIBC_NAMESPACE

#endif // LLVM_LIBC_SRC_MATH_FMAXF128_H
20 changes: 20 additions & 0 deletions libc/src/math/fminf128.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//===-- Implementation header for fminf128 ----------------------*- 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_FMINF128_H
#define LLVM_LIBC_SRC_MATH_FMINF128_H

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

namespace LIBC_NAMESPACE {

float128 fminf128(float128 x, float128 y);

} // namespace LIBC_NAMESPACE

#endif // LLVM_LIBC_SRC_MATH_FMINF128_H
24 changes: 24 additions & 0 deletions libc/src/math/generic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1243,6 +1243,18 @@ add_entrypoint_object(
-O2
)

add_entrypoint_object(
fminf128
SRCS
fminf128.cpp
HDRS
../fminf128.h
DEPENDS
libc.src.__support.FPUtil.basic_operations
COMPILE_OPTIONS
-O3
)

add_entrypoint_object(
fmax
SRCS
Expand Down Expand Up @@ -1279,6 +1291,18 @@ add_entrypoint_object(
-O2
)

add_entrypoint_object(
fmaxf128
SRCS
fmaxf128.cpp
HDRS
../fmaxf128.h
DEPENDS
libc.src.__support.FPUtil.basic_operations
COMPILE_OPTIONS
-O3
)

add_entrypoint_object(
sqrt
SRCS
Expand Down
19 changes: 19 additions & 0 deletions libc/src/math/generic/fmaxf128.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//===-- Implementation of fmaxf128 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/fmaxf128.h"
#include "src/__support/FPUtil/BasicOperations.h"
#include "src/__support/common.h"

namespace LIBC_NAMESPACE {

LLVM_LIBC_FUNCTION(float128, fmaxf128, (float128 x, float128 y)) {
return fputil::fmax(x, y);
}

} // namespace LIBC_NAMESPACE
19 changes: 19 additions & 0 deletions libc/src/math/generic/fminf128.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//===-- Implementation of fminf128 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/fminf128.h"
#include "src/__support/FPUtil/BasicOperations.h"
#include "src/__support/common.h"

namespace LIBC_NAMESPACE {

LLVM_LIBC_FUNCTION(float128, fminf128, (float128 x, float128 y)) {
return fputil::fmin(x, y);
}

} // namespace LIBC_NAMESPACE
32 changes: 26 additions & 6 deletions libc/test/src/math/smoke/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,6 @@ if(NOT LIBC_TARGET_ARCHITECTURE_IS_GPU)
HDRS
FMinTest.h
DEPENDS
libc.include.math
libc.src.math.fminf
libc.src.__support.FPUtil.fp_bits
)
Expand All @@ -998,7 +997,6 @@ if(NOT LIBC_TARGET_ARCHITECTURE_IS_GPU)
HDRS
FMinTest.h
DEPENDS
libc.include.math
libc.src.math.fmin
libc.src.__support.FPUtil.fp_bits
)
Expand All @@ -1012,11 +1010,23 @@ if(NOT LIBC_TARGET_ARCHITECTURE_IS_GPU)
HDRS
FMinTest.h
DEPENDS
libc.include.math
libc.src.math.fminl
libc.src.__support.FPUtil.fp_bits
)

add_fp_unittest(
fminf128_test
SUITE
libc-math-smoke-tests
SRCS
fminf128_test.cpp
HDRS
FMinTest.h
DEPENDS
libc.src.math.fminf128
libc.src.__support.FPUtil.fp_bits
)

add_fp_unittest(
fmaxf_test
SUITE
Expand All @@ -1026,7 +1036,6 @@ if(NOT LIBC_TARGET_ARCHITECTURE_IS_GPU)
HDRS
FMaxTest.h
DEPENDS
libc.include.math
libc.src.math.fmaxf
libc.src.__support.FPUtil.fp_bits
)
Expand All @@ -1040,7 +1049,6 @@ if(NOT LIBC_TARGET_ARCHITECTURE_IS_GPU)
HDRS
FMaxTest.h
DEPENDS
libc.include.math
libc.src.math.fmax
libc.src.__support.FPUtil.fp_bits
)
Expand All @@ -1054,10 +1062,22 @@ if(NOT LIBC_TARGET_ARCHITECTURE_IS_GPU)
HDRS
FMaxTest.h
DEPENDS
libc.include.math
libc.src.math.fmaxl
libc.src.__support.FPUtil.fp_bits
)

add_fp_unittest(
fmaxf128_test
SUITE
libc-math-smoke-tests
SRCS
fmaxf128_test.cpp
HDRS
FMaxTest.h
DEPENDS
libc.src.math.fmaxf128
libc.src.__support.FPUtil.fp_bits
)
endif()

add_fp_unittest(
Expand Down
10 changes: 5 additions & 5 deletions libc/test/src/math/smoke/FMaxTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
#include "test/UnitTest/FPMatcher.h"
#include "test/UnitTest/Test.h"

#include <math.h>

template <typename T> class FMaxTest : public LIBC_NAMESPACE::testing::Test {

DECLARE_SPECIAL_CONSTANTS(T)
Expand Down Expand Up @@ -56,11 +54,13 @@ template <typename T> class FMaxTest : public LIBC_NAMESPACE::testing::Test {
constexpr StorageType STEP = STORAGE_MAX / COUNT;
for (StorageType i = 0, v = 0, w = STORAGE_MAX; i <= COUNT;
++i, v += STEP, w -= STEP) {
T x = FPBits(v).get_val(), y = FPBits(w).get_val();
if (isnan(x) || isinf(x))
FPBits xbits(v), ybits(w);
if (xbits.is_inf_or_nan())
continue;
if (isnan(y) || isinf(y))
if (ybits.is_inf_or_nan())
continue;
T x = xbits.get_val();
T y = ybits.get_val();
if ((x == 0) && (y == 0))
continue;

Expand Down
10 changes: 5 additions & 5 deletions libc/test/src/math/smoke/FMinTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
#include "test/UnitTest/FPMatcher.h"
#include "test/UnitTest/Test.h"

#include <math.h>

template <typename T> class FMinTest : public LIBC_NAMESPACE::testing::Test {

DECLARE_SPECIAL_CONSTANTS(T)
Expand Down Expand Up @@ -56,11 +54,13 @@ template <typename T> class FMinTest : public LIBC_NAMESPACE::testing::Test {
constexpr StorageType STEP = STORAGE_MAX / COUNT;
for (StorageType i = 0, v = 0, w = STORAGE_MAX; i <= COUNT;
++i, v += STEP, w -= STEP) {
T x = FPBits(v).get_val(), y = FPBits(w).get_val();
if (isnan(x) || isinf(x))
FPBits xbits(v), ybits(w);
if (xbits.is_inf_or_nan())
continue;
if (isnan(y) || isinf(y))
if (ybits.is_inf_or_nan())
continue;
T x = xbits.get_val();
T y = ybits.get_val();
if ((x == 0) && (y == 0))
continue;

Expand Down
13 changes: 13 additions & 0 deletions libc/test/src/math/smoke/fmaxf128_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//===-- Unittests for fmaxf128 --------------------------------------------===//
//
// 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 "FMaxTest.h"

#include "src/math/fmaxf128.h"

LIST_FMAX_TESTS(float128, LIBC_NAMESPACE::fmaxf128)
13 changes: 13 additions & 0 deletions libc/test/src/math/smoke/fminf128_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//===-- Unittests for fminf128 --------------------------------------------===//
//
// 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 "FMinTest.h"

#include "src/math/fminf128.h"

LIST_FMIN_TESTS(float128, LIBC_NAMESPACE::fminf128)