Skip to content
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

[libc][math][c23] Add totalorderl function. #102564

Merged
merged 5 commits into from
Aug 9, 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
1 change: 1 addition & 0 deletions libc/config/linux/aarch64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.tanhf
libc.src.math.totalorder
libc.src.math.totalorderf
libc.src.math.totalorderl
libc.src.math.totalordermag
libc.src.math.totalordermagf
libc.src.math.totalordermagl
Expand Down
1 change: 1 addition & 0 deletions libc/config/linux/arm/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.tanhf
libc.src.math.totalorder
libc.src.math.totalorderf
libc.src.math.totalorderl
libc.src.math.totalordermag
libc.src.math.totalordermagf
libc.src.math.totalordermagl
Expand Down
1 change: 1 addition & 0 deletions libc/config/linux/riscv/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.tanhf
libc.src.math.totalorder
libc.src.math.totalorderf
libc.src.math.totalorderl
libc.src.math.totalordermag
libc.src.math.totalordermagf
libc.src.math.totalordermagl
Expand Down
1 change: 1 addition & 0 deletions libc/config/linux/x86_64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.tanhf
libc.src.math.totalorder
libc.src.math.totalorderf
libc.src.math.totalorderl
libc.src.math.totalordermag
libc.src.math.totalordermagf
libc.src.math.totalordermagl
Expand Down
2 changes: 1 addition & 1 deletion libc/docs/math/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ Basic Operations
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
| setpayloadsig | |check| | |check| | |check| | |check| | |check| | F.10.13.3 | N/A |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
| totalorder | |check| | |check| | | |check| | |check| | F.10.12.1 | N/A |
| totalorder | |check| | |check| | |check| | |check| | |check| | F.10.12.1 | N/A |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
| totalordermag | |check| | |check| | |check| | |check| | |check| | F.10.12.2 | N/A |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
Expand Down
33 changes: 31 additions & 2 deletions libc/newhdrgen/yaml/math.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1839,14 +1839,43 @@ functions:
- type: float128 *
- type: float128
guard: LIBC_TYPES_HAS_FLOAT128
- name: totalorder
standards:
- stdc
return_type: int
arguments:
- type: const double *
- type: const double *
- name: totalorderf
standards:
- stdc
return_type: int
arguments:
- type: const float *
- type: const float *
- name: totalorderl
standards:
- stdc
return_type: int
arguments:
- type: const long double *
- type: const long double *
- name: totalorderf16
standards:
- stdc
return_type: int
arguments:
- type: _Float16 *
- type: _Float16 *
- type: const _Float16 *
- type: const _Float16 *
guard: LIBC_TYPES_HAS_FLOAT16
- name: totalorderf128
standards:
- stdc
return_type: int
arguments:
- type: const float128 *
- type: const float128 *
guard: LIBC_TYPES_HAS_FLOAT128
- name: totalordermagf16
standards:
- stdc
Expand Down
6 changes: 6 additions & 0 deletions libc/spec/spec.td
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ def Float16Ptr : PtrType<Float16Type>;
def Float128Ptr : PtrType<Float128Type>;
def UnsignedCharPtr : PtrType<UnsignedCharType>;

def ConstDoublePtr : ConstType<DoublePtr>;
def ConstFloatPtr : ConstType<FloatPtr>;
def ConstLongDoublePtr : ConstType<LongDoublePtr>;
def ConstFloat16Ptr : ConstType<Float16Ptr>;
def ConstFloat128Ptr : ConstType<Float128Ptr>;

def SigHandlerT : NamedType<"__sighandler_t">;

def TimeTType : NamedType<"time_t">;
Expand Down
9 changes: 5 additions & 4 deletions libc/spec/stdc.td
Original file line number Diff line number Diff line change
Expand Up @@ -743,10 +743,11 @@ def StdC : StandardSpec<"stdc"> {

FunctionSpec<"dsqrtl", RetValSpec<DoubleType>, [ArgSpec<LongDoubleType>]>,

FunctionSpec<"totalorder", RetValSpec<IntType>, [ArgSpec<DoublePtr>, ArgSpec<DoublePtr>]>,
FunctionSpec<"totalorderf", RetValSpec<IntType>, [ArgSpec<FloatPtr>, ArgSpec<FloatPtr>]>,
GuardedFunctionSpec<"totalorderf16", RetValSpec<IntType>, [ArgSpec<Float16Ptr>, ArgSpec<Float16Ptr>], "LIBC_TYPES_HAS_FLOAT16">,
GuardedFunctionSpec<"totalorderf128", RetValSpec<IntType>, [ArgSpec<Float128Ptr>, ArgSpec<Float128Ptr>], "LIBC_TYPES_HAS_FLOAT128">,
FunctionSpec<"totalorder", RetValSpec<IntType>, [ArgSpec<ConstDoublePtr>, ArgSpec<ConstDoublePtr>]>,
FunctionSpec<"totalorderf", RetValSpec<IntType>, [ArgSpec<ConstFloatPtr>, ArgSpec<ConstFloatPtr>]>,
FunctionSpec<"totalorderl", RetValSpec<IntType>, [ArgSpec<ConstLongDoublePtr>, ArgSpec<ConstLongDoublePtr>]>,
GuardedFunctionSpec<"totalorderf16", RetValSpec<IntType>, [ArgSpec<ConstFloat16Ptr>, ArgSpec<ConstFloat16Ptr>], "LIBC_TYPES_HAS_FLOAT16">,
GuardedFunctionSpec<"totalorderf128", RetValSpec<IntType>, [ArgSpec<ConstFloat128Ptr>, ArgSpec<ConstFloat128Ptr>], "LIBC_TYPES_HAS_FLOAT128">,

FunctionSpec<"totalordermag", RetValSpec<IntType>, [ArgSpec<DoublePtr>, ArgSpec<DoublePtr>]>,
FunctionSpec<"totalordermagf", RetValSpec<IntType>, [ArgSpec<FloatPtr>, ArgSpec<FloatPtr>]>,
Expand Down
8 changes: 2 additions & 6 deletions libc/src/__support/FPUtil/BasicOperations.h
Original file line number Diff line number Diff line change
Expand Up @@ -321,12 +321,8 @@ totalorder(T x, T y) {
StorageType x_u = x_bits.uintval();
StorageType y_u = y_bits.uintval();

using signed_t = make_integral_or_big_int_signed_t<StorageType>;
signed_t x_signed = static_cast<signed_t>(x_u);
signed_t y_signed = static_cast<signed_t>(y_u);

bool both_neg = (x_u & y_u & FPBits::SIGN_MASK) != 0;
return x_signed == y_signed || ((x_signed <= y_signed) != both_neg);
bool has_neg = ((x_u | y_u) & FPBits::SIGN_MASK) != 0;
return x_u == y_u || ((x_u < y_u) != has_neg);
}

template <typename T>
Expand Down
1 change: 1 addition & 0 deletions libc/src/math/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@ add_math_entrypoint_object(lgamma_r)

add_math_entrypoint_object(totalorder)
add_math_entrypoint_object(totalorderf)
add_math_entrypoint_object(totalorderl)
add_math_entrypoint_object(totalorderf16)
add_math_entrypoint_object(totalorderf128)

Expand Down
12 changes: 12 additions & 0 deletions libc/src/math/generic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4368,6 +4368,18 @@ add_entrypoint_object(
-O3
)

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

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

namespace LIBC_NAMESPACE_DECL {

LLVM_LIBC_FUNCTION(int, totalorderl,
(const long double *x, const long double *y)) {
return static_cast<int>(fputil::totalorder(*x, *y));
}

} // namespace LIBC_NAMESPACE_DECL
20 changes: 20 additions & 0 deletions libc/src/math/totalorderl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//===-- Implementation header for totalorderl -------------------*- 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_TOTALORDERL_H
#define LLVM_LIBC_SRC_MATH_TOTALORDERL_H

#include "src/__support/macros/config.h"

namespace LIBC_NAMESPACE_DECL {

int totalorderl(const long double *x, const long double *y);

} // namespace LIBC_NAMESPACE_DECL

#endif // LLVM_LIBC_SRC_MATH_TOTALORDERL_H
12 changes: 12 additions & 0 deletions libc/test/src/math/smoke/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3837,6 +3837,18 @@ add_fp_unittest(
libc.src.math.totalorderf
)

add_fp_unittest(
totalorderl_test
SUITE
libc-math-smoke-tests
SRCS
totalorderl_test.cpp
HDRS
TotalOrderTest.h
DEPENDS
libc.src.math.totalorderl
)

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

#include "src/math/totalorderl.h"

LIST_TOTALORDER_TESTS(long double, LIBC_NAMESPACE::totalorderl)
Loading