Skip to content
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
6 changes: 6 additions & 0 deletions libc/shared/math.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@
#include "math/ceilf128.h"
#include "math/ceilf16.h"
#include "math/ceill.h"
#include "math/copysign.h"
#include "math/copysignbf16.h"
#include "math/copysignf.h"
#include "math/copysignf128.h"
#include "math/copysignf16.h"
#include "math/copysignl.h"
#include "math/cos.h"
#include "math/cosf.h"
#include "math/cosf16.h"
Expand Down
23 changes: 23 additions & 0 deletions libc/shared/math/copysign.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//===-- Shared copysign function --------------------------------*- 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_SHARED_MATH_COPYSIGN_H
#define LLVM_LIBC_SHARED_MATH_COPYSIGN_H

#include "shared/libc_common.h"
#include "src/__support/math/copysign.h"

namespace LIBC_NAMESPACE_DECL {
namespace shared {

using math::copysign;

} // namespace shared
} // namespace LIBC_NAMESPACE_DECL

#endif // LLVM_LIBC_SHARED_MATH_COPYSIGN_H
23 changes: 23 additions & 0 deletions libc/shared/math/copysignbf16.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//===-- Shared copysignbf16 function ----------------------------*- 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_SHARED_MATH_COPYSIGNBF16_H
#define LLVM_LIBC_SHARED_MATH_COPYSIGNBF16_H

#include "shared/libc_common.h"
#include "src/__support/math/copysignbf16.h"

namespace LIBC_NAMESPACE_DECL {
namespace shared {

using math::copysignbf16;

} // namespace shared
} // namespace LIBC_NAMESPACE_DECL

#endif // LLVM_LIBC_SHARED_MATH_COPYSIGNBF16_H
23 changes: 23 additions & 0 deletions libc/shared/math/copysignf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//===-- Shared copysignf function -------------------------------*- 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_SHARED_MATH_COPYSIGNF_H
#define LLVM_LIBC_SHARED_MATH_COPYSIGNF_H

#include "shared/libc_common.h"
#include "src/__support/math/copysignf.h"

namespace LIBC_NAMESPACE_DECL {
namespace shared {

using math::copysignf;

} // namespace shared
} // namespace LIBC_NAMESPACE_DECL

#endif // LLVM_LIBC_SHARED_MATH_COPYSIGNF_H
29 changes: 29 additions & 0 deletions libc/shared/math/copysignf128.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//===-- Shared copysignf128 function ----------------------------*- 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_SHARED_MATH_COPYSIGNF128_H
#define LLVM_LIBC_SHARED_MATH_COPYSIGNF128_H

#include "include/llvm-libc-types/float128.h"

#ifdef LIBC_TYPES_HAS_FLOAT128

#include "shared/libc_common.h"
#include "src/__support/math/copysignf128.h"

namespace LIBC_NAMESPACE_DECL {
namespace shared {

using math::copysignf128;

} // namespace shared
} // namespace LIBC_NAMESPACE_DECL

#endif // LIBC_TYPES_HAS_FLOAT128

#endif // LLVM_LIBC_SHARED_MATH_COPYSIGNF128_H
29 changes: 29 additions & 0 deletions libc/shared/math/copysignf16.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//===-- Shared copysignf16 function -----------------------------*- 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_SHARED_MATH_COPYSIGNF16_H
#define LLVM_LIBC_SHARED_MATH_COPYSIGNF16_H

#include "include/llvm-libc-macros/float16-macros.h"

#ifdef LIBC_TYPES_HAS_FLOAT16

#include "shared/libc_common.h"
#include "src/__support/math/copysignf16.h"

namespace LIBC_NAMESPACE_DECL {
namespace shared {

using math::copysignf16;

} // namespace shared
} // namespace LIBC_NAMESPACE_DECL

#endif // LIBC_TYPES_HAS_FLOAT16

#endif // LLVM_LIBC_SHARED_MATH_COPYSIGNF16_H
23 changes: 23 additions & 0 deletions libc/shared/math/copysignl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//===-- Shared copysignl function -------------------------------*- 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_SHARED_MATH_COPYSIGNL_H
#define LLVM_LIBC_SHARED_MATH_COPYSIGNL_H

#include "shared/libc_common.h"
#include "src/__support/math/copysignl.h"

namespace LIBC_NAMESPACE_DECL {
namespace shared {

using math::copysignl;

} // namespace shared
} // namespace LIBC_NAMESPACE_DECL

#endif // LLVM_LIBC_SHARED_MATH_COPYSIGNL_H
2 changes: 1 addition & 1 deletion libc/src/__support/FPUtil/ManipulationFunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ LIBC_INLINE T modf(T x, T &iptr) {
}

template <typename T, cpp::enable_if_t<cpp::is_floating_point_v<T>, int> = 0>
LIBC_INLINE T copysign(T x, T y) {
LIBC_INLINE constexpr T copysign(T x, T y) {
FPBits<T> xbits(x);
xbits.set_sign(FPBits<T>(y).sign());
return xbits.get_val();
Expand Down
65 changes: 65 additions & 0 deletions libc/src/__support/math/CMakeLists.txt
Comment thread
bassiounix marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,71 @@ add_header_library(
libc.src.__support.math_extras
)

add_header_library(
copysign
HDRS
copysign.h
DEPENDS
libc.src.__support.FPUtil.manipulation_functions
libc.src.__support.macros.config
FLAGS
MISC_MATH_BASIC_OPS_OPT
)

add_header_library(
copysignbf16
HDRS
copysignbf16.h
DEPENDS
libc.src.__support.FPUtil.bfloat16
libc.src.__support.FPUtil.manipulation_functions
libc.src.__support.macros.config
FLAGS
MISC_MATH_BASIC_OPS_OPT
)

add_header_library(
copysignf
HDRS
copysignf.h
DEPENDS
libc.src.__support.FPUtil.manipulation_functions
libc.src.__support.macros.config
FLAGS
MISC_MATH_BASIC_OPS_OPT
)

add_header_library(
copysignf128
HDRS
copysignf128.h
DEPENDS
libc.include.llvm-libc-types.float128
libc.src.__support.FPUtil.manipulation_functions
libc.src.__support.macros.config
)

add_header_library(
copysignf16
HDRS
copysignf16.h
DEPENDS
libc.include.llvm-libc-macros.float16_macros
libc.src.__support.FPUtil.manipulation_functions
libc.src.__support.macros.config
FLAGS
MISC_MATH_BASIC_OPS_OPT
)

add_header_library(
copysignl
HDRS
copysignl.h
DEPENDS
libc.src.__support.FPUtil.manipulation_functions
libc.src.__support.macros.config
)

add_header_library(
cos_integer_eval
HDRS
Expand Down
30 changes: 30 additions & 0 deletions libc/src/__support/math/copysign.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//===-- Implementation header for copysign ----------------------*- 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___SUPPORT_MATH_COPYSIGN_H
#define LLVM_LIBC_SRC___SUPPORT_MATH_COPYSIGN_H

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

namespace LIBC_NAMESPACE_DECL {
namespace math {

LIBC_INLINE LIBC_CONSTEXPR double copysign(double x, double y) {
#if defined(__LIBC_MISC_MATH_BASIC_OPS_OPT) && \
!defined(LIBC_HAS_CONSTANT_EVALUATION)
return __builtin_copysign(x, y);
#else
return fputil::copysign(x, y);
#endif
}

} // namespace math
} // namespace LIBC_NAMESPACE_DECL

#endif // LLVM_LIBC_SRC___SUPPORT_MATH_COPYSIGN_H
26 changes: 26 additions & 0 deletions libc/src/__support/math/copysignbf16.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//===-- Implementation header for copysignbf16 ------------------*- 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___SUPPORT_MATH_COPYSIGNBF16_H
#define LLVM_LIBC_SRC___SUPPORT_MATH_COPYSIGNBF16_H

#include "src/__support/FPUtil/ManipulationFunctions.h"
#include "src/__support/FPUtil/bfloat16.h"
#include "src/__support/macros/config.h"

namespace LIBC_NAMESPACE_DECL {
namespace math {

LIBC_INLINE constexpr bfloat16 copysignbf16(bfloat16 x, bfloat16 y) {
return fputil::copysign(x, y);
}

} // namespace math
} // namespace LIBC_NAMESPACE_DECL

#endif // LLVM_LIBC_SRC___SUPPORT_MATH_COPYSIGNBF16_H
30 changes: 30 additions & 0 deletions libc/src/__support/math/copysignf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//===-- Implementation header for copysignf ---------------------*- 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___SUPPORT_MATH_COPYSIGNF_H
#define LLVM_LIBC_SRC___SUPPORT_MATH_COPYSIGNF_H

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

namespace LIBC_NAMESPACE_DECL {
namespace math {

LIBC_INLINE LIBC_CONSTEXPR float copysignf(float x, float y) {
#if defined(__LIBC_MISC_MATH_BASIC_OPS_OPT) && \
!defined(LIBC_HAS_CONSTANT_EVALUATION)
return __builtin_copysignf(x, y);
#else
return fputil::copysign(x, y);
#endif
}

} // namespace math
} // namespace LIBC_NAMESPACE_DECL

#endif // LLVM_LIBC_SRC___SUPPORT_MATH_COPYSIGNF_H
31 changes: 31 additions & 0 deletions libc/src/__support/math/copysignf128.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//===-- Implementation header for copysignf128 ------------------*- 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___SUPPORT_MATH_COPYSIGNF128_H
#define LLVM_LIBC_SRC___SUPPORT_MATH_COPYSIGNF128_H

#include "include/llvm-libc-types/float128.h"

#ifdef LIBC_TYPES_HAS_FLOAT128

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

namespace LIBC_NAMESPACE_DECL {
namespace math {

LIBC_INLINE constexpr float128 copysignf128(float128 x, float128 y) {
return fputil::copysign(x, y);
}

} // namespace math
} // namespace LIBC_NAMESPACE_DECL

#endif // LIBC_TYPES_HAS_FLOAT128

#endif // LLVM_LIBC_SRC___SUPPORT_MATH_COPYSIGNF128_H
Loading
Loading