diff options
| author | Fangrui Song <i@maskray.me> | 2024-06-06 13:23:38 -0700 |
|---|---|---|
| committer | Fangrui Song <i@maskray.me> | 2024-06-06 13:23:38 -0700 |
| commit | 683ca4ab2cce926ca945b5eed9fa0bb3cf575de9 (patch) | |
| tree | c32c6df233afdf9469e20f99733cde3f552e49de /libc/src | |
| parent | cf44857e7bce6b2defe3f174e0134e2bb7a0ac9d (diff) | |
| parent | fbcb92ca017ee7fbf84be808701133fbdf3b1c59 (diff) | |
[𝘀𝗽𝗿] changes introduced through rebaseusers/MaskRay/spr/main.elf-orphan-placement-remove-hasinputsections-condition
Created using spr 1.3.5-bogner
[skip ci]
Diffstat (limited to 'libc/src')
46 files changed, 979 insertions, 88 deletions
diff --git a/libc/src/__support/CPP/CMakeLists.txt b/libc/src/__support/CPP/CMakeLists.txt index 08661aba5b6b..e6f58b7cd822 100644 --- a/libc/src/__support/CPP/CMakeLists.txt +++ b/libc/src/__support/CPP/CMakeLists.txt @@ -111,6 +111,7 @@ add_header_library( type_traits/add_lvalue_reference.h type_traits/add_pointer.h type_traits/add_rvalue_reference.h + type_traits/aligned_storage.h type_traits/always_false.h type_traits/bool_constant.h type_traits/conditional.h diff --git a/libc/src/__support/CPP/type_traits.h b/libc/src/__support/CPP/type_traits.h index 1494aeb905e0..d50b6612656d 100644 --- a/libc/src/__support/CPP/type_traits.h +++ b/libc/src/__support/CPP/type_traits.h @@ -12,6 +12,7 @@ #include "src/__support/CPP/type_traits/add_lvalue_reference.h" #include "src/__support/CPP/type_traits/add_pointer.h" #include "src/__support/CPP/type_traits/add_rvalue_reference.h" +#include "src/__support/CPP/type_traits/aligned_storage.h" #include "src/__support/CPP/type_traits/bool_constant.h" #include "src/__support/CPP/type_traits/conditional.h" #include "src/__support/CPP/type_traits/decay.h" diff --git a/libc/src/__support/CPP/type_traits/aligned_storage.h b/libc/src/__support/CPP/type_traits/aligned_storage.h new file mode 100644 index 000000000000..574b1146f6b2 --- /dev/null +++ b/libc/src/__support/CPP/type_traits/aligned_storage.h @@ -0,0 +1,27 @@ +//===-- aligned_storage type_traits --------------------------*- 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_CPP_TYPE_TRAITS_ALIGNED_STORAGE_H +#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_ALIGNED_STORAGE_H + +#include <stddef.h> // size_t + +namespace LIBC_NAMESPACE::cpp { + +template <size_t Len, size_t Align> struct aligned_storage { + struct type { + alignas(Align) unsigned char data[Len]; + }; +}; + +template <size_t Len, size_t Align> +using aligned_storage_t = typename aligned_storage<Len, Align>::type; + +} // namespace LIBC_NAMESPACE::cpp + +#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_ALIGNED_STORAGE_H diff --git a/libc/src/__support/fixedvector.h b/libc/src/__support/fixedvector.h index 6aeb4d56363e..ddd0993a9527 100644 --- a/libc/src/__support/fixedvector.h +++ b/libc/src/__support/fixedvector.h @@ -24,6 +24,17 @@ template <typename T, size_t CAPACITY> class FixedVector { public: constexpr FixedVector() = default; + using iterator = typename cpp::array<T, CAPACITY>::iterator; + constexpr FixedVector(iterator begin, iterator end) { + for (; begin != end; ++begin) + push_back(*begin); + } + + constexpr FixedVector(size_t count, const T &value) { + for (size_t i = 0; i < count; ++i) + push_back(value); + } + bool push_back(const T &obj) { if (item_count == CAPACITY) return false; @@ -43,8 +54,14 @@ public: return true; } + T &operator[](size_t idx) { return store[idx]; } + + const T &operator[](size_t idx) const { return store[idx]; } + bool empty() const { return item_count == 0; } + size_t size() const { return item_count; } + // Empties the store for all practical purposes. void reset() { item_count = 0; } @@ -64,7 +81,6 @@ public: } LIBC_INLINE constexpr reverse_iterator rend() { return store.rend(); } - using iterator = typename cpp::array<T, CAPACITY>::iterator; LIBC_INLINE constexpr iterator begin() { return store.begin(); } LIBC_INLINE constexpr iterator end() { return iterator{&store[item_count]}; } }; diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt index 5ae03b1f46c3..7a349ddc5372 100644 --- a/libc/src/math/CMakeLists.txt +++ b/libc/src/math/CMakeLists.txt @@ -124,50 +124,60 @@ add_math_entrypoint_object(fmax) add_math_entrypoint_object(fmaxf) add_math_entrypoint_object(fmaxl) add_math_entrypoint_object(fmaxf128) +add_math_entrypoint_object(fmaxf16) add_math_entrypoint_object(fmin) add_math_entrypoint_object(fminf) add_math_entrypoint_object(fminl) add_math_entrypoint_object(fminf128) +add_math_entrypoint_object(fminf16) add_math_entrypoint_object(fmaximum) add_math_entrypoint_object(fmaximumf) add_math_entrypoint_object(fmaximuml) +add_math_entrypoint_object(fmaximumf16) add_math_entrypoint_object(fmaximumf128) add_math_entrypoint_object(fmaximum_num) add_math_entrypoint_object(fmaximum_numf) add_math_entrypoint_object(fmaximum_numl) +add_math_entrypoint_object(fmaximum_numf16) add_math_entrypoint_object(fmaximum_numf128) add_math_entrypoint_object(fmaximum_mag) add_math_entrypoint_object(fmaximum_magf) add_math_entrypoint_object(fmaximum_magl) +add_math_entrypoint_object(fmaximum_magf16) add_math_entrypoint_object(fmaximum_magf128) add_math_entrypoint_object(fmaximum_mag_num) add_math_entrypoint_object(fmaximum_mag_numf) add_math_entrypoint_object(fmaximum_mag_numl) +add_math_entrypoint_object(fmaximum_mag_numf16) add_math_entrypoint_object(fmaximum_mag_numf128) add_math_entrypoint_object(fminimum) add_math_entrypoint_object(fminimumf) add_math_entrypoint_object(fminimuml) +add_math_entrypoint_object(fminimumf16) add_math_entrypoint_object(fminimumf128) add_math_entrypoint_object(fminimum_num) add_math_entrypoint_object(fminimum_numf) add_math_entrypoint_object(fminimum_numl) +add_math_entrypoint_object(fminimum_numf16) add_math_entrypoint_object(fminimum_numf128) add_math_entrypoint_object(fminimum_mag) add_math_entrypoint_object(fminimum_magf) add_math_entrypoint_object(fminimum_magl) +add_math_entrypoint_object(fminimum_magf16) add_math_entrypoint_object(fminimum_magf128) add_math_entrypoint_object(fminimum_mag_num) add_math_entrypoint_object(fminimum_mag_numf) add_math_entrypoint_object(fminimum_mag_numl) +add_math_entrypoint_object(fminimum_mag_numf16) add_math_entrypoint_object(fminimum_mag_numf128) add_math_entrypoint_object(fmod) @@ -270,20 +280,24 @@ add_math_entrypoint_object(nearbyintf128) add_math_entrypoint_object(nextafter) add_math_entrypoint_object(nextafterf) add_math_entrypoint_object(nextafterl) +add_math_entrypoint_object(nextafterf16) add_math_entrypoint_object(nextafterf128) add_math_entrypoint_object(nexttoward) add_math_entrypoint_object(nexttowardf) add_math_entrypoint_object(nexttowardl) +add_math_entrypoint_object(nexttowardf16) add_math_entrypoint_object(nextdown) add_math_entrypoint_object(nextdownf) add_math_entrypoint_object(nextdownl) +add_math_entrypoint_object(nextdownf16) add_math_entrypoint_object(nextdownf128) add_math_entrypoint_object(nextup) add_math_entrypoint_object(nextupf) add_math_entrypoint_object(nextupl) +add_math_entrypoint_object(nextupf16) add_math_entrypoint_object(nextupf128) add_math_entrypoint_object(pow) diff --git a/libc/src/math/fmaxf16.h b/libc/src/math/fmaxf16.h new file mode 100644 index 000000000000..bf608f82c420 --- /dev/null +++ b/libc/src/math/fmaxf16.h @@ -0,0 +1,20 @@ +//===-- Implementation header for fmaxf16 -----------------------*- 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_FMAXF16_H +#define LLVM_LIBC_SRC_MATH_FMAXF16_H + +#include "src/__support/macros/properties/types.h" + +namespace LIBC_NAMESPACE { + +float16 fmaxf16(float16 x, float16 y); + +} // namespace LIBC_NAMESPACE + +#endif // LLVM_LIBC_SRC_MATH_FMAXF16_H diff --git a/libc/src/math/fmaximum_mag_numf16.h b/libc/src/math/fmaximum_mag_numf16.h new file mode 100644 index 000000000000..4c963d4dccc7 --- /dev/null +++ b/libc/src/math/fmaximum_mag_numf16.h @@ -0,0 +1,20 @@ +//===-- Implementation header for fmaximum_mag_numf16 -----------*- 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_FMAXIMUM_MAG_NUMF16_H +#define LLVM_LIBC_SRC_MATH_FMAXIMUM_MAG_NUMF16_H + +#include "src/__support/macros/properties/types.h" + +namespace LIBC_NAMESPACE { + +float16 fmaximum_mag_numf16(float16 x, float16 y); + +} // namespace LIBC_NAMESPACE + +#endif // LLVM_LIBC_SRC_MATH_FMAXIMUM_MAG_NUMF16_H diff --git a/libc/src/math/fmaximum_magf16.h b/libc/src/math/fmaximum_magf16.h new file mode 100644 index 000000000000..e5f57d3b7f1d --- /dev/null +++ b/libc/src/math/fmaximum_magf16.h @@ -0,0 +1,20 @@ +//===-- Implementation header for fmaximum_magf16 ---------------*- 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_FMAXIMUM_MAGF16_H +#define LLVM_LIBC_SRC_MATH_FMAXIMUM_MAGF16_H + +#include "src/__support/macros/properties/types.h" + +namespace LIBC_NAMESPACE { + +float16 fmaximum_magf16(float16 x, float16 y); + +} // namespace LIBC_NAMESPACE + +#endif // LLVM_LIBC_SRC_MATH_FMAXIMUM_MAGF16_H diff --git a/libc/src/math/fmaximum_numf16.h b/libc/src/math/fmaximum_numf16.h new file mode 100644 index 000000000000..b450a4595648 --- /dev/null +++ b/libc/src/math/fmaximum_numf16.h @@ -0,0 +1,20 @@ +//===-- Implementation header for fmaximum_numf16 ---------------*- 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_FMAXIMUM_NUMF16_H +#define LLVM_LIBC_SRC_MATH_FMAXIMUM_NUMF16_H + +#include "src/__support/macros/properties/types.h" + +namespace LIBC_NAMESPACE { + +float16 fmaximum_numf16(float16 x, float16 y); + +} // namespace LIBC_NAMESPACE + +#endif // LLVM_LIBC_SRC_MATH_FMAXIMUM_NUMF16_H diff --git a/libc/src/math/fmaximumf16.h b/libc/src/math/fmaximumf16.h new file mode 100644 index 000000000000..806339fde683 --- /dev/null +++ b/libc/src/math/fmaximumf16.h @@ -0,0 +1,20 @@ +//===-- Implementation header for fmaximumf16 -------------------*- 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_FMAXIMUMF16_H +#define LLVM_LIBC_SRC_MATH_FMAXIMUMF16_H + +#include "src/__support/macros/properties/types.h" + +namespace LIBC_NAMESPACE { + +float16 fmaximumf16(float16 x, float16 y); + +} // namespace LIBC_NAMESPACE + +#endif // LLVM_LIBC_SRC_MATH_FMAXIMUMF16_H diff --git a/libc/src/math/fminf16.h b/libc/src/math/fminf16.h new file mode 100644 index 000000000000..22d4e6c80394 --- /dev/null +++ b/libc/src/math/fminf16.h @@ -0,0 +1,20 @@ +//===-- Implementation header for fminf16 -----------------------*- 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_FMINF16_H +#define LLVM_LIBC_SRC_MATH_FMINF16_H + +#include "src/__support/macros/properties/types.h" + +namespace LIBC_NAMESPACE { + +float16 fminf16(float16 x, float16 y); + +} // namespace LIBC_NAMESPACE + +#endif // LLVM_LIBC_SRC_MATH_FMINF16_H diff --git a/libc/src/math/fminimum_mag_numf16.h b/libc/src/math/fminimum_mag_numf16.h new file mode 100644 index 000000000000..0fd314b2f5a2 --- /dev/null +++ b/libc/src/math/fminimum_mag_numf16.h @@ -0,0 +1,20 @@ +//===-- Implementation header for fminimum_mag_numf16 -----------*- 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_FMINIMUM_MAG_NUMF16_H +#define LLVM_LIBC_SRC_MATH_FMINIMUM_MAG_NUMF16_H + +#include "src/__support/macros/properties/types.h" + +namespace LIBC_NAMESPACE { + +float16 fminimum_mag_numf16(float16 x, float16 y); + +} // namespace LIBC_NAMESPACE + +#endif // LLVM_LIBC_SRC_MATH_FMINIMUM_MAG_NUMF16_H diff --git a/libc/src/math/fminimum_magf16.h b/libc/src/math/fminimum_magf16.h new file mode 100644 index 000000000000..27673555403c --- /dev/null +++ b/libc/src/math/fminimum_magf16.h @@ -0,0 +1,20 @@ +//===-- Implementation header for fminimum_magf16 ---------------*- 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_FMINIMUM_MAGF16_H +#define LLVM_LIBC_SRC_MATH_FMINIMUM_MAGF16_H + +#include "src/__support/macros/properties/types.h" + +namespace LIBC_NAMESPACE { + +float16 fminimum_magf16(float16 x, float16 y); + +} // namespace LIBC_NAMESPACE + +#endif // LLVM_LIBC_SRC_MATH_FMINIMUM_MAGF16_H diff --git a/libc/src/math/fminimum_numf16.h b/libc/src/math/fminimum_numf16.h new file mode 100644 index 000000000000..598ff9d3c32d --- /dev/null +++ b/libc/src/math/fminimum_numf16.h @@ -0,0 +1,20 @@ +//===-- Implementation header for fminimum_numf16 ---------------*- 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_FMINIMUM_NUMF16_H +#define LLVM_LIBC_SRC_MATH_FMINIMUM_NUMF16_H + +#include "src/__support/macros/properties/types.h" + +namespace LIBC_NAMESPACE { + +float16 fminimum_numf16(float16 x, float16 y); + +} // namespace LIBC_NAMESPACE + +#endif // LLVM_LIBC_SRC_MATH_FMINIMUM_NUMF16_H diff --git a/libc/src/math/fminimumf16.h b/libc/src/math/fminimumf16.h new file mode 100644 index 000000000000..86dd240ae406 --- /dev/null +++ b/libc/src/math/fminimumf16.h @@ -0,0 +1,20 @@ +//===-- Implementation header for fminimumf16 -------------------*- 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_FMINIMUMF16_H +#define LLVM_LIBC_SRC_MATH_FMINIMUMF16_H + +#include "src/__support/macros/properties/types.h" + +namespace LIBC_NAMESPACE { + +float16 fminimumf16(float16 x, float16 y); + +} // namespace LIBC_NAMESPACE + +#endif // LLVM_LIBC_SRC_MATH_FMINIMUMF16_H diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt index 95904bef93d2..b1d786fc6b29 100644 --- a/libc/src/math/generic/CMakeLists.txt +++ b/libc/src/math/generic/CMakeLists.txt @@ -1783,6 +1783,20 @@ add_entrypoint_object( ) add_entrypoint_object( + fminf16 + SRCS + fminf16.cpp + HDRS + ../fminf16.h + DEPENDS + libc.src.__support.macros.properties.types + libc.src.__support.FPUtil.basic_operations + COMPILE_OPTIONS + -O3 +) + + +add_entrypoint_object( fmax SRCS fmax.cpp @@ -1832,6 +1846,19 @@ add_entrypoint_object( ) add_entrypoint_object( + fmaxf16 + SRCS + fmaxf16.cpp + HDRS + ../fmaxf16.h + DEPENDS + libc.src.__support.macros.properties.types + libc.src.__support.FPUtil.basic_operations + COMPILE_OPTIONS + -O3 +) + +add_entrypoint_object( fmaximum SRCS fmaximum.cpp @@ -1868,6 +1895,19 @@ add_entrypoint_object( ) add_entrypoint_object( + fmaximumf16 + SRCS + fmaximumf16.cpp + HDRS + ../fmaximumf16.h + DEPENDS + libc.src.__support.macros.properties.types + libc.src.__support.FPUtil.basic_operations + COMPILE_OPTIONS + -O3 +) + +add_entrypoint_object( fmaximumf128 SRCS fmaximumf128.cpp @@ -1917,6 +1957,19 @@ add_entrypoint_object( ) add_entrypoint_object( + fmaximum_numf16 + SRCS + fmaximum_numf16.cpp + HDRS + ../fmaximum_numf16.h + DEPENDS + libc.src.__support.macros.properties.types + libc.src.__support.FPUtil.basic_operations + COMPILE_OPTIONS + -O3 +) + +add_entrypoint_object( fmaximum_numf128 SRCS fmaximum_numf128.cpp @@ -1966,6 +2019,19 @@ add_entrypoint_object( ) add_entrypoint_object( + fmaximum_magf16 + SRCS + fmaximum_magf16.cpp + HDRS + ../fmaximum_magf16.h + DEPENDS + libc.src.__support.macros.properties.types + libc.src.__support.FPUtil.basic_operations + COMPILE_OPTIONS + -O3 +) + +add_entrypoint_object( fmaximum_magf128 SRCS fmaximum_magf128.cpp @@ -1978,7 +2044,6 @@ add_entrypoint_object( -O3 ) - add_entrypoint_object( fmaximum_mag_num SRCS @@ -2016,6 +2081,19 @@ add_entrypoint_object( ) add_entrypoint_object( + fmaximum_mag_numf16 + SRCS + fmaximum_mag_numf16.cpp + HDRS + ../fmaximum_mag_numf16.h + DEPENDS + libc.src.__support.macros.properties.types + libc.src.__support.FPUtil.basic_operations + COMPILE_OPTIONS + -O3 +) + +add_entrypoint_object( fmaximum_mag_numf128 SRCS fmaximum_mag_numf128.cpp @@ -2065,6 +2143,19 @@ add_entrypoint_object( ) add_entrypoint_object( + fminimumf16 + SRCS + fminimumf16.cpp + HDRS + ../fminimumf16.h + DEPENDS + libc.src.__support.macros.properties.types + libc.src.__support.FPUtil.basic_operations + COMPILE_OPTIONS + -O3 +) + +add_entrypoint_object( fminimumf128 SRCS fminimumf128.cpp @@ -2114,6 +2205,19 @@ add_entrypoint_object( ) add_entrypoint_object( + fminimum_numf16 + SRCS + fminimum_numf16.cpp + HDRS + ../fminimum_numf16.h + DEPENDS + libc.src.__support.macros.properties.types + libc.src.__support.FPUtil.basic_operations + COMPILE_OPTIONS + -O3 +) + +add_entrypoint_object( fminimum_numf128 SRCS fminimum_numf128.cpp @@ -2163,6 +2267,19 @@ add_entrypoint_object( ) add_entrypoint_object( + fminimum_magf16 + SRCS + fminimum_magf16.cpp + HDRS + ../fminimum_magf16.h + DEPENDS + libc.src.__support.macros.properties.types + libc.src.__support.FPUtil.basic_operations + COMPILE_OPTIONS + -O3 +) + +add_entrypoint_object( fminimum_magf128 SRCS fminimum_magf128.cpp @@ -2175,7 +2292,6 @@ add_entrypoint_object( -O3 ) - add_entrypoint_object( fminimum_mag_num SRCS @@ -2213,6 +2329,19 @@ add_entrypoint_object( ) add_entrypoint_object( + fminimum_mag_numf16 + SRCS + fminimum_mag_numf16.cpp + HDRS + ../fminimum_mag_numf16.h + DEPENDS + libc.src.__support.macros.properties.types + libc.src.__support.FPUtil.basic_operations + COMPILE_OPTIONS + -O3 +) + +add_entrypoint_object( fminimum_mag_numf128 SRCS fminimum_mag_numf128.cpp @@ -2524,6 +2653,19 @@ add_entrypoint_object( ) add_entrypoint_object( + nextafterf16 + SRCS + nextafterf16.cpp + HDRS + ../nextafterf16.h + DEPENDS + libc.src.__support.macros.properties.types + libc.src.__support.FPUtil.manipulation_functions + COMPILE_OPTIONS + -O3 +) + +add_entrypoint_object( nextafterf128 SRCS nextafterf128.cpp @@ -2573,6 +2715,19 @@ add_entrypoint_object( ) add_entrypoint_object( + nexttowardf16 + SRCS + nexttowardf16.cpp + HDRS + ../nexttowardf16.h + DEPENDS + libc.src.__support.macros.properties.types + libc.src.__support.FPUtil.manipulation_functions + COMPILE_OPTIONS + -O3 +) + +add_entrypoint_object( nextdown SRCS nextdown.cpp @@ -2609,6 +2764,19 @@ add_entrypoint_object( ) add_entrypoint_object( + nextdownf16 + SRCS + nextdownf16.cpp + HDRS + ../nextdownf16.h + DEPENDS + libc.src.__support.macros.properties.types + libc.src.__support.FPUtil.manipulation_functions + COMPILE_OPTIONS + -O3 +) + +add_entrypoint_object( nextdownf128 SRCS nextdownf128.cpp @@ -2658,6 +2826,19 @@ add_entrypoint_object( ) add_entrypoint_object( + nextupf16 + SRCS + nextupf16.cpp + HDRS + ../nextupf16.h + DEPENDS + libc.src.__support.macros.properties.types + libc.src.__support.FPUtil.manipulation_functions + COMPILE_OPTIONS + -O3 +) + +add_entrypoint_object( nextupf128 SRCS nextupf128.cpp diff --git a/libc/src/math/generic/fmaxf16.cpp b/libc/src/math/generic/fmaxf16.cpp new file mode 100644 index 000000000000..c317aef3cb3b --- /dev/null +++ b/libc/src/math/generic/fmaxf16.cpp @@ -0,0 +1,19 @@ +//===-- Implementation of fmaxf16 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/fmaxf16.h" +#include "src/__support/FPUtil/BasicOperations.h" +#include "src/__support/common.h" + +namespace LIBC_NAMESPACE { + +LLVM_LIBC_FUNCTION(float16, fmaxf16, (float16 x, float16 y)) { + return fputil::fmax(x, y); +} + +} // namespace LIBC_NAMESPACE diff --git a/libc/src/math/generic/fmaximum_mag_numf16.cpp b/libc/src/math/generic/fmaximum_mag_numf16.cpp new file mode 100644 index 000000000000..5055802c4cf8 --- /dev/null +++ b/libc/src/math/generic/fmaximum_mag_numf16.cpp @@ -0,0 +1,19 @@ +//===-- Implementation of fmaximum_mag_numf16 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/fmaximum_mag_numf16.h" +#include "src/__support/FPUtil/BasicOperations.h" +#include "src/__support/common.h" + +namespace LIBC_NAMESPACE { + +LLVM_LIBC_FUNCTION(float16, fmaximum_mag_numf16, (float16 x, float16 y)) { + return fputil::fmaximum_mag_num(x, y); +} + +} // namespace LIBC_NAMESPACE diff --git a/libc/src/math/generic/fmaximum_magf16.cpp b/libc/src/math/generic/fmaximum_magf16.cpp new file mode 100644 index 000000000000..fbd5eaccf309 --- /dev/null +++ b/libc/src/math/generic/fmaximum_magf16.cpp @@ -0,0 +1,19 @@ +//===-- Implementation of fmaximum_magf16 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/fmaximum_magf16.h" +#include "src/__support/FPUtil/BasicOperations.h" +#include "src/__support/common.h" + +namespace LIBC_NAMESPACE { + +LLVM_LIBC_FUNCTION(float16, fmaximum_magf16, (float16 x, float16 y)) { + return fputil::fmaximum_mag(x, y); +} + +} // namespace LIBC_NAMESPACE diff --git a/libc/src/math/generic/fmaximum_numf16.cpp b/libc/src/math/generic/fmaximum_numf16.cpp new file mode 100644 index 000000000000..187cfbeee6e2 --- /dev/null +++ b/libc/src/math/generic/fmaximum_numf16.cpp @@ -0,0 +1,19 @@ +//===-- Implementation of fmaximum_numf16 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/fmaximum_numf16.h" +#include "src/__support/FPUtil/BasicOperations.h" +#include "src/__support/common.h" + +namespace LIBC_NAMESPACE { + +LLVM_LIBC_FUNCTION(float16, fmaximum_numf16, (float16 x, float16 y)) { + return fputil::fmaximum_num(x, y); +} + +} // namespace LIBC_NAMESPACE diff --git a/libc/src/math/generic/fmaximumf16.cpp b/libc/src/math/generic/fmaximumf16.cpp new file mode 100644 index 000000000000..9e194d2ecef6 --- /dev/null +++ b/libc/src/math/generic/fmaximumf16.cpp @@ -0,0 +1,19 @@ +//===-- Implementation of fmaximumf16 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/fmaximumf16.h" +#include "src/__support/FPUtil/BasicOperations.h" +#include "src/__support/common.h" + +namespace LIBC_NAMESPACE { + +LLVM_LIBC_FUNCTION(float16, fmaximumf16, (float16 x, float16 y)) { + return fputil::fmaximum(x, y); +} + +} // namespace LIBC_NAMESPACE diff --git a/libc/src/math/generic/fminf16.cpp b/libc/src/math/generic/fminf16.cpp new file mode 100644 index 000000000000..12547c33c636 --- /dev/null +++ b/libc/src/math/generic/fminf16.cpp @@ -0,0 +1,19 @@ +//===-- Implementation of fminf16 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/fminf16.h" +#include "src/__support/FPUtil/BasicOperations.h" +#include "src/__support/common.h" + +namespace LIBC_NAMESPACE { + +LLVM_LIBC_FUNCTION(float16, fminf16, (float16 x, float16 y)) { + return fputil::fmin(x, y); +} + +} // namespace LIBC_NAMESPACE diff --git a/libc/src/math/generic/fminimum_mag_numf16.cpp b/libc/src/math/generic/fminimum_mag_numf16.cpp new file mode 100644 index 000000000000..1a893c6c4bbc --- /dev/null +++ b/libc/src/math/generic/fminimum_mag_numf16.cpp @@ -0,0 +1,19 @@ +//===-- Implementation of fminimum_mag_numf16 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/fminimum_mag_numf16.h" +#include "src/__support/FPUtil/BasicOperations.h" +#include "src/__support/common.h" + +namespace LIBC_NAMESPACE { + +LLVM_LIBC_FUNCTION(float16, fminimum_mag_numf16, (float16 x, float16 y)) { + return fputil::fminimum_mag_num(x, y); +} + +} // namespace LIBC_NAMESPACE diff --git a/libc/src/math/generic/fminimum_magf16.cpp b/libc/src/math/generic/fminimum_magf16.cpp new file mode 100644 index 000000000000..45183a963e2d --- /dev/null +++ b/libc/src/math/generic/fminimum_magf16.cpp @@ -0,0 +1,19 @@ +//===-- Implementation of fminimum_magf16 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/fminimum_magf16.h" +#include "src/__support/FPUtil/BasicOperations.h" +#include "src/__support/common.h" + +namespace LIBC_NAMESPACE { + +LLVM_LIBC_FUNCTION(float16, fminimum_magf16, (float16 x, float16 y)) { + return fputil::fminimum_mag(x, y); +} + +} // namespace LIBC_NAMESPACE diff --git a/libc/src/math/generic/fminimum_numf16.cpp b/libc/src/math/generic/fminimum_numf16.cpp new file mode 100644 index 000000000000..825ad3e7b63a --- /dev/null +++ b/libc/src/math/generic/fminimum_numf16.cpp @@ -0,0 +1,19 @@ +//===-- Implementation of fminimum_numf16 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/fminimum_numf16.h" +#include "src/__support/FPUtil/BasicOperations.h" +#include "src/__support/common.h" + +namespace LIBC_NAMESPACE { + +LLVM_LIBC_FUNCTION(float16, fminimum_numf16, (float16 x, float16 y)) { + return fputil::fminimum_num(x, y); +} + +} // namespace LIBC_NAMESPACE diff --git a/libc/src/math/generic/fminimumf16.cpp b/libc/src/math/generic/fminimumf16.cpp new file mode 100644 index 000000000000..16f738be7e58 --- /dev/null +++ b/libc/src/math/generic/fminimumf16.cpp @@ -0,0 +1,19 @@ +//===-- Implementation of fminimumf16 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/fminimumf16.h" +#include "src/__support/FPUtil/BasicOperations.h" +#include "src/__support/common.h" + +namespace LIBC_NAMESPACE { + +LLVM_LIBC_FUNCTION(float16, fminimumf16, (float16 x, float16 y)) { + return fputil::fminimum(x, y); +} + +} // namespace LIBC_NAMESPACE diff --git a/libc/src/math/generic/nextafterf16.cpp b/libc/src/math/generic/nextafterf16.cpp new file mode 100644 index 000000000000..144b3fc61461 --- /dev/null +++ b/libc/src/math/generic/nextafterf16.cpp @@ -0,0 +1,19 @@ +//===-- Implementation of nextafterf16 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/nextafterf16.h" +#include "src/__support/FPUtil/ManipulationFunctions.h" +#include "src/__support/common.h" + +namespace LIBC_NAMESPACE { + +LLVM_LIBC_FUNCTION(float16, nextafterf16, (float16 x, float16 y)) { + return fputil::nextafter(x, y); +} + +} // namespace LIBC_NAMESPACE diff --git a/libc/src/math/generic/nextdownf16.cpp b/libc/src/math/generic/nextdownf16.cpp new file mode 100644 index 000000000000..9fdaa9dafdd8 --- /dev/null +++ b/libc/src/math/generic/nextdownf16.cpp @@ -0,0 +1,19 @@ +//===-- Implementation of nextdownf16 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/nextdownf16.h" +#include "src/__support/FPUtil/ManipulationFunctions.h" +#include "src/__support/common.h" + +namespace LIBC_NAMESPACE { + +LLVM_LIBC_FUNCTION(float16, nextdownf16, (float16 x)) { + return fputil::nextupdown</*IsDown=*/true>(x); +} + +} // namespace LIBC_NAMESPACE diff --git a/libc/src/math/generic/nexttowardf16.cpp b/libc/src/math/generic/nexttowardf16.cpp new file mode 100644 index 000000000000..d1d78e8f22d3 --- /dev/null +++ b/libc/src/math/generic/nexttowardf16.cpp @@ -0,0 +1,21 @@ +//===-- Implementation of nexttowardf16 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/nexttowardf16.h" +#include "src/__support/FPUtil/ManipulationFunctions.h" +#include "src/__support/common.h" + +namespace LIBC_NAMESPACE { + +LLVM_LIBC_FUNCTION(float16, nexttowardf16, (float16 x, long double y)) { + // We can reuse the nextafter implementation because the internal nextafter is + // templated on the types of the arguments. + return fputil::nextafter(x, y); +} + +} // namespace LIBC_NAMESPACE diff --git a/libc/src/math/generic/nextupf16.cpp b/libc/src/math/generic/nextupf16.cpp new file mode 100644 index 000000000000..5d3d52c94068 --- /dev/null +++ b/libc/src/math/generic/nextupf16.cpp @@ -0,0 +1,19 @@ +//===-- Implementation of nextupf16 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/nextupf16.h" +#include "src/__support/FPUtil/ManipulationFunctions.h" +#include "src/__support/common.h" + +namespace LIBC_NAMESPACE { + +LLVM_LIBC_FUNCTION(float16, nextupf16, (float16 x)) { + return fputil::nextupdown</*IsDown=*/false>(x); +} + +} // namespace LIBC_NAMESPACE diff --git a/libc/src/math/nextafterf16.h b/libc/src/math/nextafterf16.h new file mode 100644 index 000000000000..293569ef40c5 --- /dev/null +++ b/libc/src/math/nextafterf16.h @@ -0,0 +1,20 @@ +//===-- Implementation header for nextafterf16 ------------------*- 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_NEXTAFTERF16_H +#define LLVM_LIBC_SRC_MATH_NEXTAFTERF16_H + +#include "src/__support/macros/properties/types.h" + +namespace LIBC_NAMESPACE { + +float16 nextafterf16(float16 x, float16 y); + +} // namespace LIBC_NAMESPACE + +#endif // LLVM_LIBC_SRC_MATH_NEXTAFTERF16_H diff --git a/libc/src/math/nextdownf16.h b/libc/src/math/nextdownf16.h new file mode 100644 index 000000000000..19137574ac92 --- /dev/null +++ b/libc/src/math/nextdownf16.h @@ -0,0 +1,20 @@ +//===-- Implementation header for nextdownf16 -------------------*- 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_NEXTDOWNF16_H +#define LLVM_LIBC_SRC_MATH_NEXTDOWNF16_H + +#include "src/__support/macros/properties/types.h" + +namespace LIBC_NAMESPACE { + +float16 nextdownf16(float16 x); + +} // namespace LIBC_NAMESPACE + +#endif // LLVM_LIBC_SRC_MATH_NEXTDOWNF16_H diff --git a/libc/src/math/nexttowardf16.h b/libc/src/math/nexttowardf16.h new file mode 100644 index 000000000000..604eb32c2577 --- /dev/null +++ b/libc/src/math/nexttowardf16.h @@ -0,0 +1,20 @@ +//===-- Implementation header for nexttowardf16 -----------------*- 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_NEXTTOWARDF16_H +#define LLVM_LIBC_SRC_MATH_NEXTTOWARDF16_H + +#include "src/__support/macros/properties/types.h" + +namespace LIBC_NAMESPACE { + +float16 nexttowardf16(float16 x, long double y); + +} // namespace LIBC_NAMESPACE + +#endif // LLVM_LIBC_SRC_MATH_NEXTTOWARDF16_H diff --git a/libc/src/math/nextupf16.h b/libc/src/math/nextupf16.h new file mode 100644 index 000000000000..b2973e4afc25 --- /dev/null +++ b/libc/src/math/nextupf16.h @@ -0,0 +1,20 @@ +//===-- Implementation header for nextupf16 ---------------------*- 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_NEXTUPF16_H +#define LLVM_LIBC_SRC_MATH_NEXTUPF16_H + +#include "src/__support/macros/properties/types.h" + +namespace LIBC_NAMESPACE { + +float16 nextupf16(float16 x); + +} // namespace LIBC_NAMESPACE + +#endif // LLVM_LIBC_SRC_MATH_NEXTUPF16_H diff --git a/libc/src/stdlib/CMakeLists.txt b/libc/src/stdlib/CMakeLists.txt index e0bff5198b59..219c85dda675 100644 --- a/libc/src/stdlib/CMakeLists.txt +++ b/libc/src/stdlib/CMakeLists.txt @@ -50,6 +50,7 @@ add_entrypoint_object( quick_exit.h DEPENDS libc.src.__support.OSUtil.osutil + .exit_handler ) add_entrypoint_object( @@ -415,14 +416,14 @@ add_entrypoint_object( libc.src.__support.OSUtil.osutil ) -add_entrypoint_object( - atexit +add_object_library( + exit_handler SRCS - atexit.cpp + exit_handler.cpp HDRS - atexit.h + exit_handler.h CXX_STANDARD - 20 # For constinit of the atexit callback list. + 20 # For constinit DEPENDS libc.src.__support.CPP.mutex libc.src.__support.CPP.new @@ -433,6 +434,26 @@ add_entrypoint_object( ) add_entrypoint_object( + atexit + SRCS + atexit.cpp + HDRS + atexit.h + DEPENDS + .exit_handler +) + +add_entrypoint_object( + at_quick_exit + SRCS + at_quick_exit.cpp + HDRS + at_quick_exit.h + DEPENDS + .exit_handler +) + +add_entrypoint_object( exit SRCS exit.cpp @@ -442,6 +463,7 @@ add_entrypoint_object( ._Exit .atexit libc.src.__support.OSUtil.osutil + .exit_handler ) add_entrypoint_object( diff --git a/libc/src/stdlib/at_quick_exit.cpp b/libc/src/stdlib/at_quick_exit.cpp new file mode 100644 index 000000000000..752d67e7fe44 --- /dev/null +++ b/libc/src/stdlib/at_quick_exit.cpp @@ -0,0 +1,22 @@ +//===-- Implementation of at_quick_exit -----------------------------------===// +// +// 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/stdlib/at_quick_exit.h" +#include "hdr/types/atexithandler_t.h" +#include "src/__support/common.h" +#include "src/stdlib/exit_handler.h" + +namespace LIBC_NAMESPACE { + +LLVM_LIBC_FUNCTION(int, at_quick_exit, (__atexithandler_t callback)) { + return add_atexit_unit( + at_quick_exit_callbacks, + {&stdc_at_exit_func, reinterpret_cast<void *>(callback)}); +} + +} // namespace LIBC_NAMESPACE diff --git a/libc/src/stdlib/at_quick_exit.h b/libc/src/stdlib/at_quick_exit.h new file mode 100644 index 000000000000..c36c797088ab --- /dev/null +++ b/libc/src/stdlib/at_quick_exit.h @@ -0,0 +1,20 @@ +//===-- Implementation header for at_quick_exit -----------------*- 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_STDLIB_AT_QUICK_EXIT_H +#define LLVM_LIBC_SRC_STDLIB_AT_QUICK_EXIT_H + +#include "hdr/types/atexithandler_t.h" + +namespace LIBC_NAMESPACE { + +int at_quick_exit(__atexithandler_t); + +} // namespace LIBC_NAMESPACE + +#endif // LLVM_LIBC_SRC_STDLIB_AT_QUICK_EXIT_H diff --git a/libc/src/stdlib/atexit.cpp b/libc/src/stdlib/atexit.cpp index 9e37c4cf256c..ca3cbfe87a88 100644 --- a/libc/src/stdlib/atexit.cpp +++ b/libc/src/stdlib/atexit.cpp @@ -7,95 +7,28 @@ //===----------------------------------------------------------------------===// #include "src/stdlib/atexit.h" -#include "src/__support/CPP/mutex.h" // lock_guard -#include "src/__support/blockstore.h" +#include "hdr/types/atexithandler_t.h" #include "src/__support/common.h" -#include "src/__support/fixedvector.h" -#include "src/__support/threads/mutex.h" +#include "src/stdlib/exit_handler.h" namespace LIBC_NAMESPACE { -namespace { - -Mutex handler_list_mtx(/*timed=*/false, /*recursive=*/false, /*robust=*/false, - /*pshared=*/false); - -using AtExitCallback = void(void *); -using StdCAtExitCallback = void(void); - -struct AtExitUnit { - AtExitCallback *callback = nullptr; - void *payload = nullptr; - constexpr AtExitUnit() = default; - constexpr AtExitUnit(AtExitCallback *c, void *p) : callback(c), payload(p) {} -}; - -#if defined(LIBC_TARGET_ARCH_IS_GPU) -// The GPU build cannot handle the potentially recursive definitions required by -// the BlockStore class. Additionally, the liklihood that someone exceeds this -// while executing on the GPU is extremely small. -// FIXME: It is not generally safe to use 'atexit' on the GPU because the -// mutexes simply passthrough. We will need a lock free stack. -using ExitCallbackList = FixedVector<AtExitUnit, 64>; -#elif defined(LIBC_COPT_PUBLIC_PACKAGING) -using ExitCallbackList = ReverseOrderBlockStore<AtExitUnit, 32>; -#else -// BlockStore uses dynamic memory allocation. To avoid dynamic memory -// allocation in tests, we use a fixed size callback list when built for -// tests. -// If we use BlockStore, then we will have to pull in malloc etc into -// the tests. While this is not bad, the problem we have currently is -// that LLVM libc' allocator is SCUDO. So, we will end up pulling SCUDO's -// deps also (some of which are not yet available in LLVM libc) into the -// integration tests. -using ExitCallbackList = FixedVector<AtExitUnit, CALLBACK_LIST_SIZE_FOR_TESTS>; -#endif // LIBC_COPT_PUBLIC_PACKAGING - -constinit ExitCallbackList exit_callbacks; - -void stdc_at_exit_func(void *payload) { - reinterpret_cast<StdCAtExitCallback *>(payload)(); -} - -void call_exit_callbacks() { - handler_list_mtx.lock(); - while (!exit_callbacks.empty()) { - AtExitUnit &unit = exit_callbacks.back(); - exit_callbacks.pop_back(); - handler_list_mtx.unlock(); - unit.callback(unit.payload); - handler_list_mtx.lock(); - } - ExitCallbackList::destroy(&exit_callbacks); -} - -int add_atexit_unit(const AtExitUnit &unit) { - cpp::lock_guard lock(handler_list_mtx); - if (exit_callbacks.push_back(unit)) - return 0; - return -1; -} - -} // namespace - extern "C" { -// TODO: Handle the last dso handle argument. int __cxa_atexit(AtExitCallback *callback, void *payload, void *) { - return add_atexit_unit({callback, payload}); + return add_atexit_unit(atexit_callbacks, {callback, payload}); } -// TODO: Handle the dso handle argument. call_exit_callbacks should only invoke -// the callbacks from this DSO. Requires adding support for __dso_handle. void __cxa_finalize(void *dso) { if (!dso) - call_exit_callbacks(); + call_exit_callbacks(atexit_callbacks); } } // extern "C" -LLVM_LIBC_FUNCTION(int, atexit, (StdCAtExitCallback * callback)) { +LLVM_LIBC_FUNCTION(int, atexit, (__atexithandler_t callback)) { return add_atexit_unit( + atexit_callbacks, {&stdc_at_exit_func, reinterpret_cast<void *>(callback)}); } diff --git a/libc/src/stdlib/atexit.h b/libc/src/stdlib/atexit.h index 7cf9d7c92191..7faaf654247c 100644 --- a/libc/src/stdlib/atexit.h +++ b/libc/src/stdlib/atexit.h @@ -9,13 +9,10 @@ #ifndef LLVM_LIBC_SRC_STDLIB_ATEXIT_H #define LLVM_LIBC_SRC_STDLIB_ATEXIT_H -#include <stddef.h> // For size_t - +#include "hdr/types/atexithandler_t.h" namespace LIBC_NAMESPACE { -constexpr size_t CALLBACK_LIST_SIZE_FOR_TESTS = 1024; - -int atexit(void (*function)()); +int atexit(__atexithandler_t); } // namespace LIBC_NAMESPACE diff --git a/libc/src/stdlib/exit_handler.cpp b/libc/src/stdlib/exit_handler.cpp new file mode 100644 index 000000000000..ed41247e4a31 --- /dev/null +++ b/libc/src/stdlib/exit_handler.cpp @@ -0,0 +1,42 @@ +//===--- Implementation of exit_handler------------------------------------===// +// +// 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/stdlib/exit_handler.h" +#include "src/__support/CPP/mutex.h" // lock_guard + +namespace LIBC_NAMESPACE { + +constinit ExitCallbackList at_quick_exit_callbacks; +constinit ExitCallbackList atexit_callbacks; + +Mutex handler_list_mtx(false, false, false, false); + +void stdc_at_exit_func(void *payload) { + reinterpret_cast<StdCAtExitCallback *>(payload)(); +} + +void call_exit_callbacks(ExitCallbackList &callbacks) { + handler_list_mtx.lock(); + while (!callbacks.empty()) { + AtExitUnit &unit = callbacks.back(); + callbacks.pop_back(); + handler_list_mtx.unlock(); + unit.callback(unit.payload); + handler_list_mtx.lock(); + } + ExitCallbackList::destroy(&callbacks); +} + +int add_atexit_unit(ExitCallbackList &callbacks, const AtExitUnit &unit) { + cpp::lock_guard lock(handler_list_mtx); + if (callbacks.push_back(unit)) + return 0; + return -1; +} + +} // namespace LIBC_NAMESPACE diff --git a/libc/src/stdlib/exit_handler.h b/libc/src/stdlib/exit_handler.h new file mode 100644 index 000000000000..8494c2f2e526 --- /dev/null +++ b/libc/src/stdlib/exit_handler.h @@ -0,0 +1,53 @@ +//===-- Implementation header for exit_handler ------------------*- 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_STDLIB_EXIT_HANDLER_H +#define LLVM_LIBC_SRC_STDLIB_EXIT_HANDLER_H + +#include "src/__support/CPP/mutex.h" // lock_guard +#include "src/__support/blockstore.h" +#include "src/__support/common.h" +#include "src/__support/fixedvector.h" +#include "src/__support/threads/mutex.h" + +namespace LIBC_NAMESPACE { + +using AtExitCallback = void(void *); +using StdCAtExitCallback = void(void); +constexpr size_t CALLBACK_LIST_SIZE_FOR_TESTS = 1024; + +struct AtExitUnit { + AtExitCallback *callback = nullptr; + void *payload = nullptr; + LIBC_INLINE constexpr AtExitUnit() = default; + LIBC_INLINE constexpr AtExitUnit(AtExitCallback *c, void *p) + : callback(c), payload(p) {} +}; + +#if defined(LIBC_TARGET_ARCH_IS_GPU) +using ExitCallbackList = FixedVector<AtExitUnit, 64>; +#elif defined(LIBC_COPT_PUBLIC_PACKAGING) +using ExitCallbackList = ReverseOrderBlockStore<AtExitUnit, 32>; +#else +using ExitCallbackList = FixedVector<AtExitUnit, CALLBACK_LIST_SIZE_FOR_TESTS>; +#endif + +extern ExitCallbackList atexit_callbacks; +extern ExitCallbackList at_quick_exit_callbacks; + +extern Mutex handler_list_mtx; + +void stdc_at_exit_func(void *payload); + +void call_exit_callbacks(ExitCallbackList &callbacks); + +int add_atexit_unit(ExitCallbackList &callbacks, const AtExitUnit &unit); + +} // namespace LIBC_NAMESPACE + +#endif // LLVM_LIBC_SRC_STDLIB_EXIT_HANDLER_H diff --git a/libc/src/stdlib/quick_exit.cpp b/libc/src/stdlib/quick_exit.cpp index cf7f07bf2439..38f0a3db3e2c 100644 --- a/libc/src/stdlib/quick_exit.cpp +++ b/libc/src/stdlib/quick_exit.cpp @@ -9,13 +9,15 @@ #include "src/stdlib/quick_exit.h" #include "src/__support/OSUtil/exit.h" #include "src/__support/common.h" +#include "src/stdlib/exit_handler.h" // extern "C" void __cxa_finalize(void *); - namespace LIBC_NAMESPACE { +extern ExitCallbackList at_quick_exit_callbacks; + [[noreturn]] LLVM_LIBC_FUNCTION(void, quick_exit, (int status)) { - // __cxa_finalize(nullptr); + call_exit_callbacks(at_quick_exit_callbacks); internal::exit(status); } diff --git a/libc/src/sys/epoll/linux/CMakeLists.txt b/libc/src/sys/epoll/linux/CMakeLists.txt index 4e661b262b85..5ba89bd1af60 100644 --- a/libc/src/sys/epoll/linux/CMakeLists.txt +++ b/libc/src/sys/epoll/linux/CMakeLists.txt @@ -48,6 +48,7 @@ add_entrypoint_object( libc.hdr.types.struct_timespec libc.include.sys_syscall libc.src.__support.OSUtil.osutil + libc.src.__support.macros.sanitizer libc.src.errno.errno ) @@ -65,6 +66,7 @@ add_entrypoint_object( libc.hdr.signal_macros libc.include.sys_syscall libc.src.__support.OSUtil.osutil + libc.src.__support.macros.sanitizer libc.src.errno.errno ) @@ -82,5 +84,6 @@ add_entrypoint_object( libc.hdr.signal_macros libc.include.sys_syscall libc.src.__support.OSUtil.osutil + libc.src.__support.macros.sanitizer libc.src.errno.errno ) diff --git a/libc/src/sys/epoll/linux/epoll_pwait.cpp b/libc/src/sys/epoll/linux/epoll_pwait.cpp index 8f498d18d547..24b66f0721b3 100644 --- a/libc/src/sys/epoll/linux/epoll_pwait.cpp +++ b/libc/src/sys/epoll/linux/epoll_pwait.cpp @@ -13,6 +13,7 @@ #include "hdr/types/struct_epoll_event.h" #include "src/__support/OSUtil/syscall.h" // For internal syscall function. #include "src/__support/common.h" +#include "src/__support/macros/sanitizer.h" #include "src/errno/libc_errno.h" #include <sys/syscall.h> // For syscall numbers. @@ -33,6 +34,8 @@ LLVM_LIBC_FUNCTION(int, epoll_pwait, return -1; } + MSAN_UNPOISON(events, ret * sizeof(struct epoll_event)); + return ret; } diff --git a/libc/src/sys/epoll/linux/epoll_pwait2.cpp b/libc/src/sys/epoll/linux/epoll_pwait2.cpp index bd33cb6325ce..e13423a085a5 100644 --- a/libc/src/sys/epoll/linux/epoll_pwait2.cpp +++ b/libc/src/sys/epoll/linux/epoll_pwait2.cpp @@ -14,6 +14,7 @@ #include "hdr/types/struct_timespec.h" #include "src/__support/OSUtil/syscall.h" // For internal syscall function. #include "src/__support/common.h" +#include "src/__support/macros/sanitizer.h" #include "src/errno/libc_errno.h" #include <sys/syscall.h> // For syscall numbers. @@ -35,6 +36,8 @@ LLVM_LIBC_FUNCTION(int, epoll_pwait2, return -1; } + MSAN_UNPOISON(events, ret * sizeof(struct epoll_event)); + return ret; } diff --git a/libc/src/sys/epoll/linux/epoll_wait.cpp b/libc/src/sys/epoll/linux/epoll_wait.cpp index 95238d872d52..3ce4a92e7969 100644 --- a/libc/src/sys/epoll/linux/epoll_wait.cpp +++ b/libc/src/sys/epoll/linux/epoll_wait.cpp @@ -13,6 +13,7 @@ #include "hdr/types/struct_epoll_event.h" #include "src/__support/OSUtil/syscall.h" // For internal syscall function. #include "src/__support/common.h" +#include "src/__support/macros/sanitizer.h" #include "src/errno/libc_errno.h" #include <sys/syscall.h> // For syscall numbers. @@ -39,6 +40,8 @@ LLVM_LIBC_FUNCTION(int, epoll_wait, return -1; } + MSAN_UNPOISON(events, ret * sizeof(struct epoll_event)); + return ret; } |
