aboutsummaryrefslogtreecommitdiff
path: root/libc
diff options
context:
space:
mode:
Diffstat (limited to 'libc')
-rw-r--r--libc/config/baremetal/aarch64/entrypoints.txt5
-rw-r--r--libc/config/baremetal/arm/entrypoints.txt5
-rw-r--r--libc/config/baremetal/riscv/entrypoints.txt5
-rw-r--r--libc/config/darwin/aarch64/entrypoints.txt5
-rw-r--r--libc/config/darwin/x86_64/entrypoints.txt5
-rw-r--r--libc/config/gpu/amdgpu/entrypoints.txt5
-rw-r--r--libc/config/gpu/nvptx/entrypoints.txt5
-rw-r--r--libc/config/linux/aarch64/entrypoints.txt5
-rw-r--r--libc/config/linux/arm/entrypoints.txt5
-rw-r--r--libc/config/linux/riscv/entrypoints.txt5
-rw-r--r--libc/config/linux/x86_64/entrypoints.txt6
-rw-r--r--libc/config/windows/entrypoints.txt5
-rw-r--r--libc/include/dlfcn.yaml6
-rw-r--r--libc/src/dlfcn/dladdr.cpp3
-rw-r--r--libc/src/dlfcn/dladdr.h2
-rw-r--r--libc/src/dlfcn/dlinfo.cpp3
-rw-r--r--libc/src/dlfcn/dlinfo.h2
-rw-r--r--libc/src/dlfcn/dlsym.cpp4
-rw-r--r--libc/src/dlfcn/dlsym.h2
-rw-r--r--libc/src/math/CMakeLists.txt5
-rw-r--r--libc/src/math/ceilbf16.h21
-rw-r--r--libc/src/math/floorbf16.h21
-rw-r--r--libc/src/math/generic/CMakeLists.txt80
-rw-r--r--libc/src/math/generic/ceilbf16.cpp19
-rw-r--r--libc/src/math/generic/floorbf16.cpp21
-rw-r--r--libc/src/math/generic/roundbf16.cpp21
-rw-r--r--libc/src/math/generic/roundevenbf16.cpp21
-rw-r--r--libc/src/math/generic/truncbf16.cpp21
-rw-r--r--libc/src/math/roundbf16.h22
-rw-r--r--libc/src/math/roundevenbf16.h21
-rw-r--r--libc/src/math/truncbf16.h21
-rw-r--r--libc/test/UnitTest/CMakeLists.txt1
-rw-r--r--libc/test/UnitTest/FEnvSafeTest.cpp6
-rw-r--r--libc/test/UnitTest/FEnvSafeTest.h3
-rw-r--r--libc/test/UnitTest/FPMatcher.h11
-rw-r--r--libc/test/src/math/smoke/CMakeLists.txt65
-rw-r--r--libc/test/src/math/smoke/CeilTest.h4
-rw-r--r--libc/test/src/math/smoke/FloorTest.h5
-rw-r--r--libc/test/src/math/smoke/RoundTest.h6
-rw-r--r--libc/test/src/math/smoke/TruncTest.h4
-rw-r--r--libc/test/src/math/smoke/ceilbf16_test.cpp14
-rw-r--r--libc/test/src/math/smoke/floorbf16_test.cpp14
-rw-r--r--libc/test/src/math/smoke/roundbf16_test.cpp14
-rw-r--r--libc/test/src/math/smoke/roundevenbf16_test.cpp14
-rw-r--r--libc/test/src/math/smoke/truncbf16_test.cpp14
45 files changed, 533 insertions, 19 deletions
diff --git a/libc/config/baremetal/aarch64/entrypoints.txt b/libc/config/baremetal/aarch64/entrypoints.txt
index e24e2b9..683c746 100644
--- a/libc/config/baremetal/aarch64/entrypoints.txt
+++ b/libc/config/baremetal/aarch64/entrypoints.txt
@@ -757,7 +757,12 @@ endif()
list(APPEND TARGET_LIBM_ENTRYPOINTS
# bfloat16 entrypoints
+ libc.src.math.ceilbf16
libc.src.math.fabsbf16
+ libc.src.math.floorbf16
+ libc.src.math.roundbf16
+ libc.src.math.roundevenbf16
+ libc.src.math.truncbf16
)
if(LIBC_COMPILER_HAS_FIXED_POINT)
diff --git a/libc/config/baremetal/arm/entrypoints.txt b/libc/config/baremetal/arm/entrypoints.txt
index 44e9c3e..f8ecc2e 100644
--- a/libc/config/baremetal/arm/entrypoints.txt
+++ b/libc/config/baremetal/arm/entrypoints.txt
@@ -760,7 +760,12 @@ endif()
list(APPEND TARGET_LIBM_ENTRYPOINTS
# bfloat16 entrypoints
+ libc.src.math.ceilbf16
libc.src.math.fabsbf16
+ libc.src.math.floorbf16
+ libc.src.math.roundbf16
+ libc.src.math.roundevenbf16
+ libc.src.math.truncbf16
)
if(LIBC_COMPILER_HAS_FIXED_POINT)
diff --git a/libc/config/baremetal/riscv/entrypoints.txt b/libc/config/baremetal/riscv/entrypoints.txt
index 29cf322a..679bfb3 100644
--- a/libc/config/baremetal/riscv/entrypoints.txt
+++ b/libc/config/baremetal/riscv/entrypoints.txt
@@ -760,7 +760,12 @@ endif()
list(APPEND TARGET_LIBM_ENTRYPOINTS
# bfloat16 entrypoints
+ libc.src.math.ceilbf16
libc.src.math.fabsbf16
+ libc.src.math.floorbf16
+ libc.src.math.roundbf16
+ libc.src.math.roundevenbf16
+ libc.src.math.truncbf16
)
if(LIBC_COMPILER_HAS_FIXED_POINT)
diff --git a/libc/config/darwin/aarch64/entrypoints.txt b/libc/config/darwin/aarch64/entrypoints.txt
index 03e00a3..72b0265 100644
--- a/libc/config/darwin/aarch64/entrypoints.txt
+++ b/libc/config/darwin/aarch64/entrypoints.txt
@@ -590,7 +590,12 @@ endif()
list(APPEND TARGET_LIBM_ENTRYPOINTS
# bfloat16 entrypoints
+ libc.src.math.ceilbf16
libc.src.math.fabsbf16
+ libc.src.math.floorbf16
+ libc.src.math.roundbf16
+ libc.src.math.roundevenbf16
+ libc.src.math.truncbf16
)
if(LIBC_COMPILER_HAS_FIXED_POINT)
diff --git a/libc/config/darwin/x86_64/entrypoints.txt b/libc/config/darwin/x86_64/entrypoints.txt
index 00cedab..b5ab1ee 100644
--- a/libc/config/darwin/x86_64/entrypoints.txt
+++ b/libc/config/darwin/x86_64/entrypoints.txt
@@ -233,7 +233,12 @@ set(TARGET_LIBM_ENTRYPOINTS
list(APPEND TARGET_LIBM_ENTRYPOINTS
# bfloat16 entrypoints
+ libc.src.math.ceilbf16
libc.src.math.fabsbf16
+ libc.src.math.floorbf16
+ libc.src.math.roundbf16
+ libc.src.math.roundevenbf16
+ libc.src.math.truncbf16
)
set(TARGET_LLVMLIBC_ENTRYPOINTS
diff --git a/libc/config/gpu/amdgpu/entrypoints.txt b/libc/config/gpu/amdgpu/entrypoints.txt
index cf2b8c6..77a13a6 100644
--- a/libc/config/gpu/amdgpu/entrypoints.txt
+++ b/libc/config/gpu/amdgpu/entrypoints.txt
@@ -616,7 +616,12 @@ endif()
list(APPEND TARGET_LIBM_ENTRYPOINTS
# bfloat16 entrypoints
+ libc.src.math.ceilbf16
libc.src.math.fabsbf16
+ libc.src.math.floorbf16
+ libc.src.math.roundbf16
+ libc.src.math.roundevenbf16
+ libc.src.math.truncbf16
)
set(TARGET_LLVMLIBC_ENTRYPOINTS
diff --git a/libc/config/gpu/nvptx/entrypoints.txt b/libc/config/gpu/nvptx/entrypoints.txt
index 55b27e6..61c9c71 100644
--- a/libc/config/gpu/nvptx/entrypoints.txt
+++ b/libc/config/gpu/nvptx/entrypoints.txt
@@ -617,7 +617,12 @@ endif()
list(APPEND TARGET_LIBM_ENTRYPOINTS
# bfloat16 entrypoints
+ libc.src.math.ceilbf16
libc.src.math.fabsbf16
+ libc.src.math.floorbf16
+ libc.src.math.roundbf16
+ libc.src.math.roundevenbf16
+ libc.src.math.truncbf16
)
set(TARGET_LLVMLIBC_ENTRYPOINTS
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index d76cdc2..fbdf8fb 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -844,7 +844,12 @@ endif()
list(APPEND TARGET_LIBM_ENTRYPOINTS
# bfloat16 entrypoints
+ libc.src.math.ceilbf16
libc.src.math.fabsbf16
+ libc.src.math.floorbf16
+ libc.src.math.roundbf16
+ libc.src.math.roundevenbf16
+ libc.src.math.truncbf16
)
if(LLVM_LIBC_FULL_BUILD)
diff --git a/libc/config/linux/arm/entrypoints.txt b/libc/config/linux/arm/entrypoints.txt
index 813c34d..e3f5fee 100644
--- a/libc/config/linux/arm/entrypoints.txt
+++ b/libc/config/linux/arm/entrypoints.txt
@@ -460,7 +460,12 @@ set(TARGET_LIBM_ENTRYPOINTS
list(APPEND TARGET_LIBM_ENTRYPOINTS
# bfloat16 entrypoints
+ libc.src.math.ceilbf16
libc.src.math.fabsbf16
+ libc.src.math.floorbf16
+ libc.src.math.roundbf16
+ libc.src.math.roundevenbf16
+ libc.src.math.truncbf16
)
set(TARGET_LLVMLIBC_ENTRYPOINTS
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index 190aef7..ba67ddd 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -863,7 +863,12 @@ endif()
list(APPEND TARGET_LIBM_ENTRYPOINTS
# bfloat16 entrypoints
+ libc.src.math.ceilbf16
libc.src.math.fabsbf16
+ libc.src.math.floorbf16
+ libc.src.math.roundbf16
+ libc.src.math.roundevenbf16
+ libc.src.math.truncbf16
)
if(LIBC_COMPILER_HAS_FIXED_POINT)
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index ec41069..066dc21 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -893,10 +893,14 @@ if(LIBC_TYPES_HAS_FLOAT128)
)
endif()
-
list(APPEND TARGET_LIBM_ENTRYPOINTS
# bfloat16 entrypoints
+ libc.src.math.ceilbf16
libc.src.math.fabsbf16
+ libc.src.math.floorbf16
+ libc.src.math.roundbf16
+ libc.src.math.roundevenbf16
+ libc.src.math.truncbf16
)
if(LIBC_COMPILER_HAS_FIXED_POINT)
diff --git a/libc/config/windows/entrypoints.txt b/libc/config/windows/entrypoints.txt
index 3160d57..994078c 100644
--- a/libc/config/windows/entrypoints.txt
+++ b/libc/config/windows/entrypoints.txt
@@ -306,7 +306,12 @@ set(TARGET_LIBM_ENTRYPOINTS
list(APPEND TARGET_LIBM_ENTRYPOINTS
# bfloat16 entrypoints
+ libc.src.math.ceilbf16
libc.src.math.fabsbf16
+ libc.src.math.floorbf16
+ libc.src.math.roundbf16
+ libc.src.math.roundevenbf16
+ libc.src.math.truncbf16
)
set(TARGET_LLVMLIBC_ENTRYPOINTS
diff --git a/libc/include/dlfcn.yaml b/libc/include/dlfcn.yaml
index db2893a..bf17a11 100644
--- a/libc/include/dlfcn.yaml
+++ b/libc/include/dlfcn.yaml
@@ -46,7 +46,7 @@ enums:
standards:
- gnu
value: 2
- - name: RTLD_DI_CONFIGADDR,
+ - name: RTLD_DI_CONFIGADDR
standards:
- gnu
value: 3
@@ -127,5 +127,5 @@ functions:
- POSIX
return_type: int
arguments:
- - type: const void *
- - type: Dl_info *
+ - type: const void *__restrict
+ - type: Dl_info *__restrict
diff --git a/libc/src/dlfcn/dladdr.cpp b/libc/src/dlfcn/dladdr.cpp
index 61490fd..3db68b4 100644
--- a/libc/src/dlfcn/dladdr.cpp
+++ b/libc/src/dlfcn/dladdr.cpp
@@ -14,7 +14,8 @@
namespace LIBC_NAMESPACE_DECL {
// TODO: https:// github.com/llvm/llvm-project/issues/97929
-LLVM_LIBC_FUNCTION(int, dladdr, (const void *addr, Dl_info *info)) {
+LLVM_LIBC_FUNCTION(int, dladdr,
+ (const void *__restrict addr, Dl_info *__restrict info)) {
return -1;
}
diff --git a/libc/src/dlfcn/dladdr.h b/libc/src/dlfcn/dladdr.h
index 346fc8d..abbc9a9 100644
--- a/libc/src/dlfcn/dladdr.h
+++ b/libc/src/dlfcn/dladdr.h
@@ -13,7 +13,7 @@
namespace LIBC_NAMESPACE_DECL {
-int dladdr(const void *, Dl_info *);
+int dladdr(const void *__restrict, Dl_info *__restrict);
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/dlfcn/dlinfo.cpp b/libc/src/dlfcn/dlinfo.cpp
index d78cade..e1938d1 100644
--- a/libc/src/dlfcn/dlinfo.cpp
+++ b/libc/src/dlfcn/dlinfo.cpp
@@ -16,7 +16,8 @@ namespace LIBC_NAMESPACE_DECL {
// TODO: https://github.com/llvm/llvm-project/issues/149911
LLVM_LIBC_FUNCTION(int, dlinfo,
- (void *restrict handle, int request, void *restrict info)) {
+ (void *__restrict handle, int request,
+ void *__restrict info)) {
return -1;
}
diff --git a/libc/src/dlfcn/dlinfo.h b/libc/src/dlfcn/dlinfo.h
index c2c34f0..bc13152 100644
--- a/libc/src/dlfcn/dlinfo.h
+++ b/libc/src/dlfcn/dlinfo.h
@@ -13,7 +13,7 @@
namespace LIBC_NAMESPACE_DECL {
-int dlinfo(void *restrict, int, void *restrict);
+int dlinfo(void *__restrict, int, void *__restrict);
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/dlfcn/dlsym.cpp b/libc/src/dlfcn/dlsym.cpp
index c075c20..dc0da7d 100644
--- a/libc/src/dlfcn/dlsym.cpp
+++ b/libc/src/dlfcn/dlsym.cpp
@@ -14,6 +14,8 @@
namespace LIBC_NAMESPACE_DECL {
// TODO(@izaakschroeder): https://github.com/llvm/llvm-project/issues/97920
-LLVM_LIBC_FUNCTION(void *, dlsym, (void *, const char *)) { return nullptr; }
+LLVM_LIBC_FUNCTION(void *, dlsym, (void *__restrict, const char *__restrict)) {
+ return nullptr;
+}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/dlfcn/dlsym.h b/libc/src/dlfcn/dlsym.h
index 70c6ab3..f879792 100644
--- a/libc/src/dlfcn/dlsym.h
+++ b/libc/src/dlfcn/dlsym.h
@@ -13,7 +13,7 @@
namespace LIBC_NAMESPACE_DECL {
-void *dlsym(void *, const char *);
+void *dlsym(void *__restrict, const char *__restrict);
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt
index 0522e0e..c3840d3 100644
--- a/libc/src/math/CMakeLists.txt
+++ b/libc/src/math/CMakeLists.txt
@@ -91,6 +91,7 @@ add_math_entrypoint_object(ceilf)
add_math_entrypoint_object(ceill)
add_math_entrypoint_object(ceilf16)
add_math_entrypoint_object(ceilf128)
+add_math_entrypoint_object(ceilbf16)
add_math_entrypoint_object(copysign)
add_math_entrypoint_object(copysignf)
@@ -214,6 +215,7 @@ add_math_entrypoint_object(floorf)
add_math_entrypoint_object(floorl)
add_math_entrypoint_object(floorf16)
add_math_entrypoint_object(floorf128)
+add_math_entrypoint_object(floorbf16)
add_math_entrypoint_object(fma)
add_math_entrypoint_object(fmaf)
@@ -463,12 +465,14 @@ add_math_entrypoint_object(roundf)
add_math_entrypoint_object(roundl)
add_math_entrypoint_object(roundf16)
add_math_entrypoint_object(roundf128)
+add_math_entrypoint_object(roundbf16)
add_math_entrypoint_object(roundeven)
add_math_entrypoint_object(roundevenf)
add_math_entrypoint_object(roundevenl)
add_math_entrypoint_object(roundevenf16)
add_math_entrypoint_object(roundevenf128)
+add_math_entrypoint_object(roundevenbf16)
add_math_entrypoint_object(scalbln)
add_math_entrypoint_object(scalblnf)
@@ -546,6 +550,7 @@ add_math_entrypoint_object(truncf)
add_math_entrypoint_object(truncl)
add_math_entrypoint_object(truncf16)
add_math_entrypoint_object(truncf128)
+add_math_entrypoint_object(truncbf16)
add_math_entrypoint_object(ufromfp)
add_math_entrypoint_object(ufromfpf)
diff --git a/libc/src/math/ceilbf16.h b/libc/src/math/ceilbf16.h
new file mode 100644
index 0000000..bf70f25
--- /dev/null
+++ b/libc/src/math/ceilbf16.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for ceilbf16 ----------------------*- 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_CEILBF16_H
+#define LLVM_LIBC_SRC_MATH_CEILBF16_H
+
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/properties/types.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+bfloat16 ceilbf16(bfloat16 x);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_CEILBF16_H
diff --git a/libc/src/math/floorbf16.h b/libc/src/math/floorbf16.h
new file mode 100644
index 0000000..9b5a30a
--- /dev/null
+++ b/libc/src/math/floorbf16.h
@@ -0,0 +1,21 @@
+//===-- 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_MATH_FLOORBF16_H
+#define LLVM_LIBC_SRC_MATH_FLOORBF16_H
+
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/properties/types.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+bfloat16 floorbf16(bfloat16 x);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_FLOORBF16_H
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index a866195..0bec7dd 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -157,6 +157,22 @@ add_entrypoint_object(
)
add_entrypoint_object(
+ ceilbf16
+ SRCS
+ ceilbf16.cpp
+ HDRS
+ ../ceilbf16.h
+ DEPENDS
+ libc.src.__support.common
+ libc.src.__support.FPUtil.bfloat16
+ libc.src.__support.FPUtil.nearest_integer_operations
+ libc.src.__support.macros.config
+ libc.src.__support.macros.properties.types
+ FLAGS
+ ROUND_OPT
+)
+
+add_entrypoint_object(
daddl
SRCS
daddl.cpp
@@ -802,6 +818,22 @@ add_entrypoint_object(
)
add_entrypoint_object(
+ truncbf16
+ SRCS
+ truncbf16.cpp
+ HDRS
+ ../truncbf16.h
+ DEPENDS
+ libc.src.__support.common
+ libc.src.__support.FPUtil.bfloat16
+ libc.src.__support.FPUtil.nearest_integer_operations
+ libc.src.__support.macros.config
+ libc.src.__support.macros.properties.types
+ FLAGS
+ ROUND_OPT
+)
+
+add_entrypoint_object(
floor
SRCS
floor.cpp
@@ -862,6 +894,22 @@ add_entrypoint_object(
)
add_entrypoint_object(
+ floorbf16
+ SRCS
+ floorbf16.cpp
+ HDRS
+ ../floorbf16.h
+ DEPENDS
+ libc.src.__support.common
+ libc.src.__support.FPUtil.bfloat16
+ libc.src.__support.FPUtil.nearest_integer_operations
+ libc.src.__support.macros.config
+ libc.src.__support.macros.properties.types
+ FLAGS
+ ROUND_OPT
+)
+
+add_entrypoint_object(
round
SRCS
round.cpp
@@ -922,6 +970,22 @@ add_entrypoint_object(
)
add_entrypoint_object(
+ roundbf16
+ SRCS
+ roundbf16.cpp
+ HDRS
+ ../roundbf16.h
+ DEPENDS
+ libc.src.__support.common
+ libc.src.__support.FPUtil.bfloat16
+ libc.src.__support.FPUtil.nearest_integer_operations
+ libc.src.__support.macros.config
+ libc.src.__support.macros.properties.types
+ FLAGS
+ ROUND_OPT
+)
+
+add_entrypoint_object(
roundeven
SRCS
roundeven.cpp
@@ -982,6 +1046,22 @@ add_entrypoint_object(
)
add_entrypoint_object(
+ roundevenbf16
+ SRCS
+ roundevenbf16.cpp
+ HDRS
+ ../roundevenbf16.h
+ DEPENDS
+ libc.src.__support.common
+ libc.src.__support.FPUtil.bfloat16
+ libc.src.__support.FPUtil.nearest_integer_operations
+ libc.src.__support.macros.config
+ libc.src.__support.macros.properties.types
+ FLAGS
+ ROUND_OPT
+)
+
+add_entrypoint_object(
lround
SRCS
lround.cpp
diff --git a/libc/src/math/generic/ceilbf16.cpp b/libc/src/math/generic/ceilbf16.cpp
new file mode 100644
index 0000000..441dcf0
--- /dev/null
+++ b/libc/src/math/generic/ceilbf16.cpp
@@ -0,0 +1,19 @@
+//===-- Implementation of ceilbf16 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/ceilbf16.h"
+#include "src/__support/FPUtil/NearestIntegerOperations.h"
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(bfloat16, ceilbf16, (bfloat16 x)) { return fputil::ceil(x); }
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/floorbf16.cpp b/libc/src/math/generic/floorbf16.cpp
new file mode 100644
index 0000000..d157096
--- /dev/null
+++ b/libc/src/math/generic/floorbf16.cpp
@@ -0,0 +1,21 @@
+//===-- Implementation of floorbf16 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/floorbf16.h"
+#include "src/__support/FPUtil/NearestIntegerOperations.h"
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(bfloat16, floorbf16, (bfloat16 x)) {
+ return fputil::floor(x);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/roundbf16.cpp b/libc/src/math/generic/roundbf16.cpp
new file mode 100644
index 0000000..cc7e5e2
--- /dev/null
+++ b/libc/src/math/generic/roundbf16.cpp
@@ -0,0 +1,21 @@
+//===-- Implementation of roundbf16 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/roundbf16.h"
+#include "src/__support/FPUtil/NearestIntegerOperations.h"
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(bfloat16, roundbf16, (bfloat16 x)) {
+ return fputil::round(x);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/roundevenbf16.cpp b/libc/src/math/generic/roundevenbf16.cpp
new file mode 100644
index 0000000..39419e4
--- /dev/null
+++ b/libc/src/math/generic/roundevenbf16.cpp
@@ -0,0 +1,21 @@
+//===-- Implementation of roundevenbf16 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/roundevenbf16.h"
+#include "src/__support/FPUtil/NearestIntegerOperations.h"
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(bfloat16, roundevenbf16, (bfloat16 x)) {
+ return fputil::round_using_specific_rounding_mode(x, FP_INT_TONEAREST);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/truncbf16.cpp b/libc/src/math/generic/truncbf16.cpp
new file mode 100644
index 0000000..dfbe83d
--- /dev/null
+++ b/libc/src/math/generic/truncbf16.cpp
@@ -0,0 +1,21 @@
+//===-- Implementation of truncbf16 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/truncbf16.h"
+#include "src/__support/FPUtil/NearestIntegerOperations.h"
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(bfloat16, truncbf16, (bfloat16 x)) {
+ return fputil::trunc(x);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/roundbf16.h b/libc/src/math/roundbf16.h
new file mode 100644
index 0000000..0f74e43
--- /dev/null
+++ b/libc/src/math/roundbf16.h
@@ -0,0 +1,22 @@
+//===-- Implementation header for roundbf16 ---------------------*- 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_ROUNDBF16_H
+#define LLVM_LIBC_SRC_MATH_ROUNDBF16_H
+
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/properties/types.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+bfloat16 roundbf16(bfloat16 x);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_ROUNDBF16_H
diff --git a/libc/src/math/roundevenbf16.h b/libc/src/math/roundevenbf16.h
new file mode 100644
index 0000000..f4374d2
--- /dev/null
+++ b/libc/src/math/roundevenbf16.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for roundevenbf16 -----------------*- 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_ROUNDEVENBF16_H
+#define LLVM_LIBC_SRC_MATH_ROUNDEVENBF16_H
+
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/properties/types.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+bfloat16 roundevenbf16(bfloat16 x);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_ROUNDEVENBF16_H
diff --git a/libc/src/math/truncbf16.h b/libc/src/math/truncbf16.h
new file mode 100644
index 0000000..c87d4cc
--- /dev/null
+++ b/libc/src/math/truncbf16.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for truncbf16 ---------------------*- 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_TRUNCBF16_H
+#define LLVM_LIBC_SRC_MATH_TRUNCBF16_H
+
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/properties/types.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+bfloat16 truncbf16(bfloat16 x);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_TRUNCBF16_H
diff --git a/libc/test/UnitTest/CMakeLists.txt b/libc/test/UnitTest/CMakeLists.txt
index d92ab6f..f1a83fc 100644
--- a/libc/test/UnitTest/CMakeLists.txt
+++ b/libc/test/UnitTest/CMakeLists.txt
@@ -125,6 +125,7 @@ add_unittest_framework_library(
RoundingModeUtils.h
DEPENDS
LibcTest
+ libc.test.UnitTest.ErrnoCheckingTest
libc.test.UnitTest.string_utils
libc.src.__support.CPP.array
libc.src.__support.FPUtil.fp_bits
diff --git a/libc/test/UnitTest/FEnvSafeTest.cpp b/libc/test/UnitTest/FEnvSafeTest.cpp
index 168b1d4..f644569 100644
--- a/libc/test/UnitTest/FEnvSafeTest.cpp
+++ b/libc/test/UnitTest/FEnvSafeTest.cpp
@@ -9,8 +9,10 @@
#include "FEnvSafeTest.h"
#include "src/__support/FPUtil/FEnvImpl.h"
+#include "src/__support/libc_errno.h"
#include "src/__support/macros/config.h"
#include "src/__support/macros/properties/architectures.h"
+#include "test/UnitTest/ErrnoCheckingTest.h"
namespace LIBC_NAMESPACE_DECL {
namespace testing {
@@ -25,6 +27,10 @@ void FEnvSafeTest::TearDown() {
if (!should_be_unchanged) {
restore_fenv();
}
+ // TODO (PR 135320): Remove this override once all FEnvSafeTest instances are
+ // updated to validate or ignore errno.
+ libc_errno = 0;
+ ErrnoCheckingTest::TearDown();
}
void FEnvSafeTest::get_fenv(fenv_t &fenv) {
diff --git a/libc/test/UnitTest/FEnvSafeTest.h b/libc/test/UnitTest/FEnvSafeTest.h
index a3c5e62..1e10629 100644
--- a/libc/test/UnitTest/FEnvSafeTest.h
+++ b/libc/test/UnitTest/FEnvSafeTest.h
@@ -12,6 +12,7 @@
#include "hdr/types/fenv_t.h"
#include "src/__support/CPP/utility.h"
#include "src/__support/macros/config.h"
+#include "test/UnitTest/ErrnoCheckingTest.h"
#include "test/UnitTest/Test.h"
namespace LIBC_NAMESPACE_DECL {
@@ -20,7 +21,7 @@ namespace testing {
// This provides a test fixture (or base class for other test fixtures) that
// asserts that each test does not leave the FPU state represented by `fenv_t`
// (aka `FPState`) perturbed from its initial state.
-class FEnvSafeTest : public Test {
+class FEnvSafeTest : public ErrnoCheckingTest {
public:
void TearDown() override;
diff --git a/libc/test/UnitTest/FPMatcher.h b/libc/test/UnitTest/FPMatcher.h
index da15cf2..592cd1b 100644
--- a/libc/test/UnitTest/FPMatcher.h
+++ b/libc/test/UnitTest/FPMatcher.h
@@ -14,8 +14,10 @@
#include "src/__support/FPUtil/FEnvImpl.h"
#include "src/__support/FPUtil/FPBits.h"
#include "src/__support/FPUtil/fpbits_str.h"
+#include "src/__support/libc_errno.h"
#include "src/__support/macros/config.h"
#include "src/__support/macros/properties/architectures.h"
+#include "test/UnitTest/ErrnoCheckingTest.h"
#include "test/UnitTest/RoundingModeUtils.h"
#include "test/UnitTest/StringUtils.h"
#include "test/UnitTest/Test.h"
@@ -166,7 +168,7 @@ CFPMatcher<T, C> getMatcherComplex(T expectedValue) {
return CFPMatcher<T, C>(expectedValue);
}
-template <typename T> struct FPTest : public Test {
+template <typename T> struct FPTest : public ErrnoCheckingTest {
using FPBits = LIBC_NAMESPACE::fputil::FPBits<T>;
using StorageType = typename FPBits::StorageType;
static constexpr StorageType STORAGE_MAX =
@@ -191,6 +193,13 @@ template <typename T> struct FPTest : public Test {
fputil::testing::RoundingMode::Downward,
fputil::testing::RoundingMode::TowardZero,
};
+
+ void TearDown() override {
+ // TODO (PR 135320): Remove this override once all FPTest instances are
+ // updated to validate or ignore errno.
+ libc_errno = 0;
+ ErrnoCheckingTest::TearDown();
+ }
};
// Add facility to test Flush-Denormal-To-Zero (FTZ) and Denormal-As-Zero (DAZ)
diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index a722f61..5f497c6 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -345,6 +345,19 @@ add_fp_unittest(
)
add_fp_unittest(
+ truncbf16_test
+ SUITE
+ libc-math-smoke-tests
+ SRCS
+ truncbf16_test.cpp
+ HDRS
+ TruncTest.h
+ DEPENDS
+ libc.src.math.truncbf16
+ libc.src.__support.FPUtil.bfloat16
+)
+
+add_fp_unittest(
canonicalize_test
SUITE
libc-math-smoke-tests
@@ -544,6 +557,19 @@ add_fp_unittest(
)
add_fp_unittest(
+ ceilbf16_test
+ SUITE
+ libc-math-smoke-tests
+ SRCS
+ ceilbf16_test.cpp
+ HDRS
+ CeilTest.h
+ DEPENDS
+ libc.src.math.ceilbf16
+ libc.src.__support.FPUtil.bfloat16
+)
+
+add_fp_unittest(
dfmal_test
SUITE
libc-math-smoke-tests
@@ -664,6 +690,19 @@ add_fp_unittest(
)
add_fp_unittest(
+ floorbf16_test
+ SUITE
+ libc-math-smoke-tests
+ SRCS
+ floorbf16_test.cpp
+ HDRS
+ FloorTest.h
+ DEPENDS
+ libc.src.math.floorbf16
+ libc.src.__support.FPUtil.bfloat16
+)
+
+add_fp_unittest(
round_test
SUITE
libc-math-smoke-tests
@@ -728,6 +767,19 @@ add_fp_unittest(
)
add_fp_unittest(
+ roundbf16_test
+ SUITE
+ libc-math-smoke-tests
+ SRCS
+ roundbf16_test.cpp
+ HDRS
+ RoundTest.h
+ DEPENDS
+ libc.src.math.roundbf16
+ libc.src.__support.FPUtil.bfloat16
+)
+
+add_fp_unittest(
roundeven_test
SUITE
libc-math-smoke-tests
@@ -792,6 +844,19 @@ add_fp_unittest(
)
add_fp_unittest(
+ roundevenbf16_test
+ SUITE
+ libc-math-smoke-tests
+ SRCS
+ roundevenbf16_test.cpp
+ HDRS
+ RoundEvenTest.h
+ DEPENDS
+ libc.src.math.roundevenbf16
+ libc.src.__support.FPUtil.bfloat16
+)
+
+add_fp_unittest(
lround_test
SUITE
libc-math-smoke-tests
diff --git a/libc/test/src/math/smoke/CeilTest.h b/libc/test/src/math/smoke/CeilTest.h
index 7998eab..1839db9 100644
--- a/libc/test/src/math/smoke/CeilTest.h
+++ b/libc/test/src/math/smoke/CeilTest.h
@@ -59,10 +59,12 @@ public:
EXPECT_FP_EQ(T(-10.0), func(T(-10.32)));
EXPECT_FP_EQ(T(11.0), func(T(10.65)));
EXPECT_FP_EQ(T(-10.0), func(T(-10.65)));
+ EXPECT_FP_EQ(T(50.0), func(T(49.62)));
+ EXPECT_FP_EQ(T(-50.0), func(T(-50.31)));
EXPECT_FP_EQ(T(124.0), func(T(123.38)));
EXPECT_FP_EQ(T(-123.0), func(T(-123.38)));
EXPECT_FP_EQ(T(124.0), func(T(123.96)));
- EXPECT_FP_EQ(T(-123.0), func(T(-123.96)));
+ EXPECT_FP_EQ(T(-123.0), func(T(-123.5)));
}
};
diff --git a/libc/test/src/math/smoke/FloorTest.h b/libc/test/src/math/smoke/FloorTest.h
index bc19e4f..cbcf276 100644
--- a/libc/test/src/math/smoke/FloorTest.h
+++ b/libc/test/src/math/smoke/FloorTest.h
@@ -59,10 +59,11 @@ public:
EXPECT_FP_EQ(T(-11.0), func(T(-10.32)));
EXPECT_FP_EQ(T(10.0), func(T(10.65)));
EXPECT_FP_EQ(T(-11.0), func(T(-10.65)));
+ EXPECT_FP_EQ(T(50.0), func(T(50.31)));
+ EXPECT_FP_EQ(T(-50.0), func(T(-49.63)));
EXPECT_FP_EQ(T(123.0), func(T(123.38)));
EXPECT_FP_EQ(T(-124.0), func(T(-123.38)));
- EXPECT_FP_EQ(T(123.0), func(T(123.96)));
- EXPECT_FP_EQ(T(-124.0), func(T(-123.96)));
+ EXPECT_FP_EQ(T(-124.0), func(T(-123.5)));
}
};
diff --git a/libc/test/src/math/smoke/RoundTest.h b/libc/test/src/math/smoke/RoundTest.h
index beb7000..72889da 100644
--- a/libc/test/src/math/smoke/RoundTest.h
+++ b/libc/test/src/math/smoke/RoundTest.h
@@ -59,8 +59,10 @@ public:
EXPECT_FP_EQ(T(-10.0), func(T(-10.32)));
EXPECT_FP_EQ(T(11.0), func(T(10.65)));
EXPECT_FP_EQ(T(-11.0), func(T(-10.65)));
- EXPECT_FP_EQ(T(123.0), func(T(123.38)));
- EXPECT_FP_EQ(T(-123.0), func(T(-123.38)));
+ EXPECT_FP_EQ(T(50.0), func(T(49.63)));
+ EXPECT_FP_EQ(T(-50.0), func(T(-50.31)));
+ EXPECT_FP_EQ(T(124.0), func(T(123.5)));
+ EXPECT_FP_EQ(T(-124.0), func(T(-123.5)));
EXPECT_FP_EQ(T(124.0), func(T(123.96)));
EXPECT_FP_EQ(T(-124.0), func(T(-123.96)));
}
diff --git a/libc/test/src/math/smoke/TruncTest.h b/libc/test/src/math/smoke/TruncTest.h
index 49688e8..e088f29 100644
--- a/libc/test/src/math/smoke/TruncTest.h
+++ b/libc/test/src/math/smoke/TruncTest.h
@@ -61,8 +61,8 @@ public:
EXPECT_FP_EQ(T(-10.0), func(T(-10.65)));
EXPECT_FP_EQ(T(123.0), func(T(123.38)));
EXPECT_FP_EQ(T(-123.0), func(T(-123.38)));
- EXPECT_FP_EQ(T(123.0), func(T(123.96)));
- EXPECT_FP_EQ(T(-123.0), func(T(-123.96)));
+ EXPECT_FP_EQ(T(123.0), func(T(123.5)));
+ EXPECT_FP_EQ(T(-123.0), func(T(-123.5)));
}
};
diff --git a/libc/test/src/math/smoke/ceilbf16_test.cpp b/libc/test/src/math/smoke/ceilbf16_test.cpp
new file mode 100644
index 0000000..dcaf058
--- /dev/null
+++ b/libc/test/src/math/smoke/ceilbf16_test.cpp
@@ -0,0 +1,14 @@
+//===-- Unittests for ceilbf16 --------------------------------------------===//
+//
+// 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 "CeilTest.h"
+
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/math/ceilbf16.h"
+
+LIST_CEIL_TESTS(bfloat16, LIBC_NAMESPACE::ceilbf16)
diff --git a/libc/test/src/math/smoke/floorbf16_test.cpp b/libc/test/src/math/smoke/floorbf16_test.cpp
new file mode 100644
index 0000000..9cc77cd
--- /dev/null
+++ b/libc/test/src/math/smoke/floorbf16_test.cpp
@@ -0,0 +1,14 @@
+//===-- Unittests for floorbf16 -------------------------------------------===//
+//
+// 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 "FloorTest.h"
+
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/math/floorbf16.h"
+
+LIST_FLOOR_TESTS(bfloat16, LIBC_NAMESPACE::floorbf16)
diff --git a/libc/test/src/math/smoke/roundbf16_test.cpp b/libc/test/src/math/smoke/roundbf16_test.cpp
new file mode 100644
index 0000000..5163868
--- /dev/null
+++ b/libc/test/src/math/smoke/roundbf16_test.cpp
@@ -0,0 +1,14 @@
+//===-- Unittests for roundbf16 -------------------------------------------===//
+//
+// 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 "RoundTest.h"
+
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/math/roundbf16.h"
+
+LIST_ROUND_TESTS(bfloat16, LIBC_NAMESPACE::roundbf16)
diff --git a/libc/test/src/math/smoke/roundevenbf16_test.cpp b/libc/test/src/math/smoke/roundevenbf16_test.cpp
new file mode 100644
index 0000000..711c37a
--- /dev/null
+++ b/libc/test/src/math/smoke/roundevenbf16_test.cpp
@@ -0,0 +1,14 @@
+//===-- Unittests for roundevenbf16 ---------------------------------------===//
+//
+// 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 "RoundEvenTest.h"
+
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/math/roundevenbf16.h"
+
+LIST_ROUNDEVEN_TESTS(bfloat16, LIBC_NAMESPACE::roundevenbf16)
diff --git a/libc/test/src/math/smoke/truncbf16_test.cpp b/libc/test/src/math/smoke/truncbf16_test.cpp
new file mode 100644
index 0000000..970fa69
--- /dev/null
+++ b/libc/test/src/math/smoke/truncbf16_test.cpp
@@ -0,0 +1,14 @@
+//===-- Unittests for truncbf16 -------------------------------------------===//
+//
+// 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 "TruncTest.h"
+
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/math/truncbf16.h"
+
+LIST_TRUNC_TESTS(bfloat16, LIBC_NAMESPACE::truncbf16)