aboutsummaryrefslogtreecommitdiff
path: root/libc
diff options
context:
space:
mode:
Diffstat (limited to 'libc')
-rw-r--r--libc/config/linux/aarch64/headers.txt1
-rw-r--r--libc/config/linux/riscv/headers.txt1
-rw-r--r--libc/config/linux/x86_64/headers.txt1
-rw-r--r--libc/include/CMakeLists.txt11
-rw-r--r--libc/include/llvm-libc-macros/CMakeLists.txt6
-rw-r--r--libc/include/llvm-libc-macros/netinet-in-macros.h19
-rw-r--r--libc/include/netinet/in.h.def18
-rw-r--r--libc/include/netinet/in.yaml7
-rw-r--r--libc/shared/math.h1
-rw-r--r--libc/shared/math/exp2f.h23
-rw-r--r--libc/src/__support/math/CMakeLists.txt18
-rw-r--r--libc/src/__support/math/exp2f.h (renamed from libc/src/math/generic/exp2f_impl.h)22
-rw-r--r--libc/src/math/generic/CMakeLists.txt22
-rw-r--r--libc/src/math/generic/exp2f.cpp4
-rw-r--r--libc/src/math/generic/powf.cpp5
-rw-r--r--libc/test/include/CMakeLists.txt10
-rw-r--r--libc/test/include/netinet_in_test.cpp19
-rw-r--r--libc/test/shared/CMakeLists.txt1
-rw-r--r--libc/test/shared/shared_math_test.cpp1
19 files changed, 155 insertions, 35 deletions
diff --git a/libc/config/linux/aarch64/headers.txt b/libc/config/linux/aarch64/headers.txt
index 6d3bc91..0573851 100644
--- a/libc/config/linux/aarch64/headers.txt
+++ b/libc/config/linux/aarch64/headers.txt
@@ -18,6 +18,7 @@ set(TARGET_PUBLIC_HEADERS
libc.include.locale
libc.include.malloc
libc.include.math
+ libc.include.netinet_in
libc.include.poll
libc.include.pthread
libc.include.sched
diff --git a/libc/config/linux/riscv/headers.txt b/libc/config/linux/riscv/headers.txt
index 6d3bc91..0573851 100644
--- a/libc/config/linux/riscv/headers.txt
+++ b/libc/config/linux/riscv/headers.txt
@@ -18,6 +18,7 @@ set(TARGET_PUBLIC_HEADERS
libc.include.locale
libc.include.malloc
libc.include.math
+ libc.include.netinet_in
libc.include.poll
libc.include.pthread
libc.include.sched
diff --git a/libc/config/linux/x86_64/headers.txt b/libc/config/linux/x86_64/headers.txt
index 6d3bc91..0573851 100644
--- a/libc/config/linux/x86_64/headers.txt
+++ b/libc/config/linux/x86_64/headers.txt
@@ -18,6 +18,7 @@ set(TARGET_PUBLIC_HEADERS
libc.include.locale
libc.include.malloc
libc.include.math
+ libc.include.netinet_in
libc.include.poll
libc.include.pthread
libc.include.sched
diff --git a/libc/include/CMakeLists.txt b/libc/include/CMakeLists.txt
index 8fd37b0..afa90e6 100644
--- a/libc/include/CMakeLists.txt
+++ b/libc/include/CMakeLists.txt
@@ -191,6 +191,17 @@ add_header_macro(
.inttypes
)
+file(MAKE_DIRECTORY ${LIBC_INCLUDE_DIR}/netinet)
+
+add_header_macro(
+ netinet_in
+ ../libc/include/netinet/in.yaml
+ netinet/in.h
+ DEPENDS
+ .llvm_libc_common_h
+ .llvm-libc-macros.netinet_in_macros
+)
+
add_header_macro(
assert
../libc/include/assert.yaml
diff --git a/libc/include/llvm-libc-macros/CMakeLists.txt b/libc/include/llvm-libc-macros/CMakeLists.txt
index f715403..76c03d9 100644
--- a/libc/include/llvm-libc-macros/CMakeLists.txt
+++ b/libc/include/llvm-libc-macros/CMakeLists.txt
@@ -153,6 +153,12 @@ add_macro_header(
)
add_macro_header(
+ netinet_in_macros
+ HDR
+ netinet-in-macros.h
+)
+
+add_macro_header(
offsetof_macro
HDR
offsetof-macro.h
diff --git a/libc/include/llvm-libc-macros/netinet-in-macros.h b/libc/include/llvm-libc-macros/netinet-in-macros.h
new file mode 100644
index 0000000..c05e5e2
--- /dev/null
+++ b/libc/include/llvm-libc-macros/netinet-in-macros.h
@@ -0,0 +1,19 @@
+//===-- Definition of macros from netinet/in.h ----------------------------===//
+//
+// 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_MACROS_NETINET_IN_MACROS_H
+#define LLVM_LIBC_MACROS_NETINET_IN_MACROS_H
+
+#define IPPROTO_IP 0
+#define IPPROTO_ICMP 1
+#define IPPROTO_TCP 6
+#define IPPROTO_UDP 17
+#define IPPROTO_IPV6 41
+#define IPPROTO_RAW 255
+
+#endif // LLVM_LIBC_MACROS_NETINET_IN_MACROS_H
diff --git a/libc/include/netinet/in.h.def b/libc/include/netinet/in.h.def
new file mode 100644
index 0000000..d9a6a6e
--- /dev/null
+++ b/libc/include/netinet/in.h.def
@@ -0,0 +1,18 @@
+//===-- C standard library header in.h ------------------------------------===//
+//
+// 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_NETINET_IN_H
+#define LLVM_LIBC_NETINET_IN_H
+
+#include "__llvm-libc-common.h"
+
+#include "../llvm-libc-macros/netinet-in-macros.h"
+
+%%public_api()
+
+#endif // LLVM_LIBC_NETINET_IN_H
diff --git a/libc/include/netinet/in.yaml b/libc/include/netinet/in.yaml
new file mode 100644
index 0000000..fbd798d
--- /dev/null
+++ b/libc/include/netinet/in.yaml
@@ -0,0 +1,7 @@
+header: netinet/in.h
+header_template: in.h.def
+macros: []
+types: []
+enums: []
+objects: []
+functions: []
diff --git a/libc/shared/math.h b/libc/shared/math.h
index 924d0cb..1262fa6 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -48,6 +48,7 @@
#include "math/exp10m1f.h"
#include "math/exp10m1f16.h"
#include "math/exp2.h"
+#include "math/exp2f.h"
#include "math/expf.h"
#include "math/expf16.h"
#include "math/frexpf.h"
diff --git a/libc/shared/math/exp2f.h b/libc/shared/math/exp2f.h
new file mode 100644
index 0000000..8c37cbb
--- /dev/null
+++ b/libc/shared/math/exp2f.h
@@ -0,0 +1,23 @@
+//===-- Shared exp2f 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_EXP2F_H
+#define LLVM_LIBC_SHARED_MATH_EXP2F_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/exp2f.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::exp2f;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_EXP2F_H
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index 4130fdf..203ebb4 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -736,6 +736,24 @@ add_header_library(
)
add_header_library(
+ exp2f
+ HDRS
+ exp2f.h
+ DEPENDS
+ .exp10f_utils
+ libc.src.__support.FPUtil.except_value_utils
+ libc.src.__support.FPUtil.fenv_impl
+ libc.src.__support.FPUtil.fp_bits
+ libc.src.__support.FPUtil.multiply_add
+ libc.src.__support.FPUtil.nearest_integer
+ libc.src.__support.FPUtil.polyeval
+ libc.src.__support.FPUtil.rounding_mode
+ libc.src.__support.macros.optimization
+ libc.src.__support.common
+ libc.src.errno.errno
+)
+
+add_header_library(
exp10
HDRS
exp10.h
diff --git a/libc/src/math/generic/exp2f_impl.h b/libc/src/__support/math/exp2f.h
index b85bb15..ef2aad0 100644
--- a/libc/src/math/generic/exp2f_impl.h
+++ b/libc/src/__support/math/exp2f.h
@@ -1,4 +1,4 @@
-//===-- Single-precision 2^x function -------------------------------------===//
+//===-- Implementation header for exp2f -------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -6,9 +6,10 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_LIBC_SRC_MATH_GENERIC_EXP2F_IMPL_H
-#define LLVM_LIBC_SRC_MATH_GENERIC_EXP2F_IMPL_H
+#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_EXP2F_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_EXP2F_H
+#include "exp10f_utils.h"
#include "src/__support/FPUtil/FEnvImpl.h"
#include "src/__support/FPUtil/FPBits.h"
#include "src/__support/FPUtil/PolyEval.h"
@@ -20,12 +21,12 @@
#include "src/__support/macros/config.h"
#include "src/__support/macros/optimization.h" // LIBC_UNLIKELY
#include "src/__support/macros/properties/cpu_features.h"
-#include "src/__support/math/exp10f_utils.h"
namespace LIBC_NAMESPACE_DECL {
-namespace generic {
-LIBC_INLINE float exp2f(float x) {
+namespace math {
+
+LIBC_INLINE static constexpr float exp2f(float x) {
using FPBits = typename fputil::FPBits<float>;
FPBits xbits(x);
@@ -120,8 +121,8 @@ LIBC_INLINE float exp2f(float x) {
// of 2^mid.
// kf = (hi + mid) * 2^5 = round(x * 2^5)
- float kf;
- int k;
+ float kf = 0;
+ int k = 0;
#ifdef LIBC_TARGET_CPU_HAS_NEAREST_INT
kf = fputil::nearest_integer(x * 32.0f);
k = static_cast<int>(kf);
@@ -161,7 +162,8 @@ LIBC_INLINE float exp2f(float x) {
return static_cast<float>(fputil::multiply_add(p, dx_sq * mh, c1 * mh));
}
-} // namespace generic
+} // namespace math
+
} // namespace LIBC_NAMESPACE_DECL
-#endif // LLVM_LIBC_SRC_MATH_GENERIC_EXP2F_IMPL_H
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_EXP2F_H
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 28ea475..5738fe8 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -1451,24 +1451,6 @@ add_entrypoint_object(
libc.src.__support.math.exp2
)
-add_header_library(
- exp2f_impl
- HDRS
- exp2f_impl.h
- DEPENDS
- libc.src.__support.FPUtil.except_value_utils
- libc.src.__support.FPUtil.fenv_impl
- libc.src.__support.FPUtil.fp_bits
- libc.src.__support.FPUtil.multiply_add
- libc.src.__support.FPUtil.nearest_integer
- libc.src.__support.FPUtil.polyeval
- libc.src.__support.FPUtil.rounding_mode
- libc.src.__support.macros.optimization
- libc.src.__support.math.exp10f_utils
- libc.src.__support.common
- libc.src.errno.errno
-)
-
add_entrypoint_object(
exp2f
SRCS
@@ -1476,7 +1458,7 @@ add_entrypoint_object(
HDRS
../exp2f.h
DEPENDS
- .exp2f_impl
+ libc.src.__support.math.exp2f
)
add_entrypoint_object(
@@ -1659,8 +1641,8 @@ add_entrypoint_object(
HDRS
../powf.h
DEPENDS
- .exp2f_impl
libc.src.__support.math.exp10f
+ libc.src.__support.math.exp2f
libc.src.__support.CPP.bit
libc.src.__support.FPUtil.fenv_impl
libc.src.__support.FPUtil.fp_bits
diff --git a/libc/src/math/generic/exp2f.cpp b/libc/src/math/generic/exp2f.cpp
index 60d6510..3117f73 100644
--- a/libc/src/math/generic/exp2f.cpp
+++ b/libc/src/math/generic/exp2f.cpp
@@ -9,10 +9,10 @@
#include "src/math/exp2f.h"
#include "src/__support/common.h" // for LLVM_LIBC_FUNCTION
#include "src/__support/macros/config.h"
-#include "src/math/generic/exp2f_impl.h"
+#include "src/__support/math/exp2f.h"
namespace LIBC_NAMESPACE_DECL {
-LLVM_LIBC_FUNCTION(float, exp2f, (float x)) { return generic::exp2f(x); }
+LLVM_LIBC_FUNCTION(float, exp2f, (float x)) { return math::exp2f(x); }
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/powf.cpp b/libc/src/math/generic/powf.cpp
index 12246e9..dd2b6aa 100644
--- a/libc/src/math/generic/powf.cpp
+++ b/libc/src/math/generic/powf.cpp
@@ -20,10 +20,9 @@
#include "src/__support/macros/optimization.h" // LIBC_UNLIKELY
#include "src/__support/math/common_constants.h" // Lookup tables EXP_M1 and EXP_M2.
#include "src/__support/math/exp10f.h" // Speedup for powf(10, y) = exp10f(y)
+#include "src/__support/math/exp2f.h" // Speedup for powf(2, y) = exp2f(y)
#include "src/__support/math/exp_constants.h"
-#include "exp2f_impl.h" // Speedup for powf(2, y) = exp2f(y)
-
namespace LIBC_NAMESPACE_DECL {
using fputil::DoubleDouble;
@@ -779,7 +778,7 @@ LLVM_LIBC_FUNCTION(float, powf, (float x, float y)) {
#ifndef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
case 0x4000'0000: // x = 2.0f
// pow(2, y) = exp2(y)
- return generic::exp2f(y);
+ return math::exp2f(y);
case 0x4120'0000: // x = 10.0f
// pow(10, y) = exp10(y)
return math::exp10f(y);
diff --git a/libc/test/include/CMakeLists.txt b/libc/test/include/CMakeLists.txt
index 11e4c3a..3ac5615 100644
--- a/libc/test/include/CMakeLists.txt
+++ b/libc/test/include/CMakeLists.txt
@@ -208,6 +208,16 @@ add_libc_test(
)
add_libc_test(
+ netinet_in_test
+ SUITE
+ libc_include_tests
+ SRCS
+ netinet_in_test.cpp
+ DEPENDS
+ libc.include.llvm-libc-macros.netinet_in_macros
+)
+
+add_libc_test(
signbit_test
SUITE
libc_include_tests
diff --git a/libc/test/include/netinet_in_test.cpp b/libc/test/include/netinet_in_test.cpp
new file mode 100644
index 0000000..a6c47a7
--- /dev/null
+++ b/libc/test/include/netinet_in_test.cpp
@@ -0,0 +1,19 @@
+//===-- Unittests for netinet/in macro ------------------------------------===//
+//
+// 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 "include/llvm-libc-macros/netinet-in-macros.h"
+#include "test/UnitTest/Test.h"
+
+TEST(LlvmLibcNetinetInTest, IPPROTOMacro) {
+ EXPECT_EQ(IPPROTO_IP, 0);
+ EXPECT_EQ(IPPROTO_ICMP, 1);
+ EXPECT_EQ(IPPROTO_TCP, 6);
+ EXPECT_EQ(IPPROTO_UDP, 17);
+ EXPECT_EQ(IPPROTO_IPV6, 41);
+ EXPECT_EQ(IPPROTO_RAW, 255);
+}
diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index 040f635..dbc3889c 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -41,6 +41,7 @@ add_fp_unittest(
libc.src.__support.math.erff
libc.src.__support.math.exp
libc.src.__support.math.exp2
+ libc.src.__support.math.exp2f
libc.src.__support.math.exp10
libc.src.__support.math.exp10f
libc.src.__support.math.exp10f16
diff --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp
index ef2e7b8..d118d96 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -62,6 +62,7 @@ TEST(LlvmLibcSharedMathTest, AllFloat) {
EXPECT_FP_EQ(0x0p+0f, LIBC_NAMESPACE::shared::erff(0.0f));
EXPECT_FP_EQ(0x1p+0f, LIBC_NAMESPACE::shared::exp10f(0.0f));
EXPECT_FP_EQ(0x1p+0f, LIBC_NAMESPACE::shared::expf(0.0f));
+ EXPECT_FP_EQ(0x1p+0f, LIBC_NAMESPACE::shared::exp2f(0.0f));
EXPECT_FP_EQ_ALL_ROUNDING(0.75f,
LIBC_NAMESPACE::shared::frexpf(24.0f, &exponent));