Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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 @@ -94,6 +94,12 @@
#include "math/faddl.h"
#include "math/ffma.h"
#include "math/ffmal.h"
#include "math/floor.h"
#include "math/floorbf16.h"
#include "math/floorf.h"
#include "math/floorf128.h"
#include "math/floorf16.h"
#include "math/floorl.h"
#include "math/fmax.h"
#include "math/fmaxbf16.h"
#include "math/fmaxf.h"
Expand Down
22 changes: 22 additions & 0 deletions libc/shared/math/floor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//===-- Shared floor 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_FLOOR_H
#define LLVM_LIBC_SHARED_MATH_FLOOR_H

#include "src/__support/math/floor.h"

namespace LIBC_NAMESPACE_DECL {
namespace shared {

using math::floor;

} // namespace shared
} // namespace LIBC_NAMESPACE_DECL

#endif // LLVM_LIBC_SHARED_MATH_FLOOR_H
22 changes: 22 additions & 0 deletions libc/shared/math/floorbf16.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//===-- Shared floorbf16 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_FLOORBF16_H
#define LLVM_LIBC_SHARED_MATH_FLOORBF16_H

#include "src/__support/math/floorbf16.h"

namespace LIBC_NAMESPACE_DECL {
namespace shared {

using math::floorbf16;

} // namespace shared
} // namespace LIBC_NAMESPACE_DECL

#endif // LLVM_LIBC_SHARED_MATH_FLOORBF16_H
22 changes: 22 additions & 0 deletions libc/shared/math/floorf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//===-- Shared floorf 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_FLOORF_H
#define LLVM_LIBC_SHARED_MATH_FLOORF_H

#include "src/__support/math/floorf.h"

namespace LIBC_NAMESPACE_DECL {
namespace shared {

using math::floorf;

} // namespace shared
} // namespace LIBC_NAMESPACE_DECL

#endif // LLVM_LIBC_SHARED_MATH_FLOORF_H
28 changes: 28 additions & 0 deletions libc/shared/math/floorf128.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//===-- Shared floorf128 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_FLOORF128_H
#define LLVM_LIBC_SHARED_MATH_FLOORF128_H

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

#ifdef LIBC_TYPES_HAS_FLOAT128

#include "src/__support/math/floorf128.h"

namespace LIBC_NAMESPACE_DECL {
namespace shared {

using math::floorf128;

} // namespace shared
} // namespace LIBC_NAMESPACE_DECL

#endif // LIBC_TYPES_HAS_FLOAT128

#endif // LLVM_LIBC_SHARED_MATH_FLOORF128_H
28 changes: 28 additions & 0 deletions libc/shared/math/floorf16.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//===-- Shared floorf16 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_FLOORF16_H
#define LLVM_LIBC_SHARED_MATH_FLOORF16_H

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

#ifdef LIBC_TYPES_HAS_FLOAT16

#include "src/__support/math/floorf16.h"

namespace LIBC_NAMESPACE_DECL {
namespace shared {

using math::floorf16;

} // namespace shared
} // namespace LIBC_NAMESPACE_DECL

#endif // LIBC_TYPES_HAS_FLOAT16

#endif // LLVM_LIBC_SHARED_MATH_FLOORF16_H
22 changes: 22 additions & 0 deletions libc/shared/math/floorl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//===-- Shared floorl 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_FLOORL_H
#define LLVM_LIBC_SHARED_MATH_FLOORL_H

#include "src/__support/math/floorl.h"

namespace LIBC_NAMESPACE_DECL {
namespace shared {

using math::floorl;

} // namespace shared
} // namespace LIBC_NAMESPACE_DECL

#endif // LLVM_LIBC_SHARED_MATH_FLOORL_H
52 changes: 52 additions & 0 deletions libc/src/__support/math/CMakeLists.txt
Comment thread
hulxv marked this conversation as resolved.
Resolved
Original file line number Diff line number Diff line change
Expand Up @@ -894,6 +894,58 @@ add_header_library(
libc.src.__support.FPUtil.fma
libc.src.__support.macros.config
)
add_header_library(
floor
HDRS
floor.h
DEPENDS
libc.src.__support.FPUtil.nearest_integer_operations
libc.src.__support.macros.config
)
add_header_library(
floorbf16
HDRS
floorbf16.h
DEPENDS
libc.src.__support.FPUtil.bfloat16
libc.src.__support.FPUtil.nearest_integer_operations
libc.src.__support.macros.config
)
add_header_library(
floorf
HDRS
floorf.h
DEPENDS
libc.src.__support.FPUtil.nearest_integer_operations
libc.src.__support.macros.config
)
add_header_library(
floorf128
HDRS
floorf128.h
DEPENDS
libc.include.llvm-libc-types.float128
libc.src.__support.FPUtil.nearest_integer_operations
libc.src.__support.macros.config
)
add_header_library(
floorf16
HDRS
floorf16.h
DEPENDS
libc.include.llvm-libc-macros.float16_macros
libc.src.__support.FPUtil.cast
libc.src.__support.FPUtil.nearest_integer_operations
libc.src.__support.macros.config
)
add_header_library(
floorl
HDRS
floorl.h
DEPENDS
libc.src.__support.FPUtil.nearest_integer_operations
libc.src.__support.macros.config
)
Comment thread
hulxv marked this conversation as resolved.
Resolved

add_header_library(
fmax
Expand Down
29 changes: 29 additions & 0 deletions libc/src/__support/math/floor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//===-- Implementation header for floor -------------------------*- 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_FLOOR_H
#define LLVM_LIBC_SRC___SUPPORT_MATH_FLOOR_H

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

namespace LIBC_NAMESPACE_DECL {
namespace math {

LIBC_INLINE double floor(double x) {
#ifdef __LIBC_USE_BUILTIN_CEIL_FLOOR_RINT_TRUNC
return __builtin_floor(x);
#else
return fputil::floor(x);
#endif
}

} // namespace math
} // namespace LIBC_NAMESPACE_DECL

#endif // LLVM_LIBC_SRC___SUPPORT_MATH_FLOOR_H
24 changes: 24 additions & 0 deletions libc/src/__support/math/floorbf16.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//===-- Implementation header for floorbf16 ---------------------*- 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_FLOORBF16_H
#define LLVM_LIBC_SRC___SUPPORT_MATH_FLOORBF16_H

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

namespace LIBC_NAMESPACE_DECL {
namespace math {

LIBC_INLINE bfloat16 floorbf16(bfloat16 x) { return fputil::floor(x); }

} // namespace math
} // namespace LIBC_NAMESPACE_DECL

#endif // LLVM_LIBC_SRC___SUPPORT_MATH_FLOORBF16_H
29 changes: 29 additions & 0 deletions libc/src/__support/math/floorf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//===-- Implementation header for floorf ------------------------*- 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_FLOORF_H
#define LLVM_LIBC_SRC___SUPPORT_MATH_FLOORF_H

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

namespace LIBC_NAMESPACE_DECL {
namespace math {

LIBC_INLINE float floorf(float x) {
#ifdef __LIBC_USE_BUILTIN_CEIL_FLOOR_RINT_TRUNC
return __builtin_floorf(x);
#else
return fputil::floor(x);
#endif
}

} // namespace math
} // namespace LIBC_NAMESPACE_DECL

#endif // LLVM_LIBC_SRC___SUPPORT_MATH_FLOORF_H
29 changes: 29 additions & 0 deletions libc/src/__support/math/floorf128.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//===-- Implementation header for floorf128 ---------------------*- 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_FLOORF128_H
#define LLVM_LIBC_SRC___SUPPORT_MATH_FLOORF128_H

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

#ifdef LIBC_TYPES_HAS_FLOAT128

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

namespace LIBC_NAMESPACE_DECL {
namespace math {

LIBC_INLINE float128 floorf128(float128 x) { return fputil::floor(x); }

} // namespace math
} // namespace LIBC_NAMESPACE_DECL

#endif // LIBC_TYPES_HAS_FLOAT128

#endif // LLVM_LIBC_SRC___SUPPORT_MATH_FLOORF128_H
38 changes: 38 additions & 0 deletions libc/src/__support/math/floorf16.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//===-- Implementation header for floorf16 ----------------------*- 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_FLOORF16_H
#define LLVM_LIBC_SRC___SUPPORT_MATH_FLOORF16_H

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

#ifdef LIBC_TYPES_HAS_FLOAT16

#include "src/__support/FPUtil/NearestIntegerOperations.h"
#include "src/__support/FPUtil/cast.h"
#include "src/__support/macros/config.h"
#include "src/__support/macros/properties/cpu_features.h"

namespace LIBC_NAMESPACE_DECL {
namespace math {

LIBC_INLINE float16 floorf16(float16 x) {
#if defined(__LIBC_USE_BUILTIN_CEIL_FLOOR_RINT_TRUNC) && \
defined(LIBC_TARGET_CPU_HAS_FAST_FLOAT16_OPS)
return fputil::cast<float16>(__builtin_floorf(x));
#else
return fputil::floor(x);
#endif
}

} // namespace math
} // namespace LIBC_NAMESPACE_DECL

#endif // LIBC_TYPES_HAS_FLOAT16

#endif // LLVM_LIBC_SRC___SUPPORT_MATH_FLOORF16_H
23 changes: 23 additions & 0 deletions libc/src/__support/math/floorl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//===-- Implementation header for floorl ------------------------*- 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_FLOORL_H
#define LLVM_LIBC_SRC___SUPPORT_MATH_FLOORL_H

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

namespace LIBC_NAMESPACE_DECL {
namespace math {

LIBC_INLINE long double floorl(long double x) { return fputil::floor(x); }

} // namespace math
} // namespace LIBC_NAMESPACE_DECL

#endif // LLVM_LIBC_SRC___SUPPORT_MATH_FLOORL_H
Loading
Loading