Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions libc/include/llvm-libc-macros/float-macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
#ifndef LLVM_LIBC_MACROS_FLOAT_MACROS_H
#define LLVM_LIBC_MACROS_FLOAT_MACROS_H

// __has_builtin is a Clang extension; GCC < 10 doesn't define it, which
Comment thread
hulxv marked this conversation as resolved.
// turns a bare `#if __has_builtin(...)` into a preprocessor syntax error.
#ifndef __has_builtin
#define __has_builtin(x) 0
#endif

#ifndef FLT_RADIX
#define FLT_RADIX __FLT_RADIX__
#endif // FLT_RADIX
Expand Down
22 changes: 22 additions & 0 deletions libc/shared/builtins.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//===----------------------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
///
/// \file
/// This header aggregates LLVM-libc's shared compiler-rt builtins so that
/// they can be reused by compiler-rt's builtins.
///
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_SHARED_BUILTINS_H
#define LLVM_LIBC_SHARED_BUILTINS_H

#include "libc_common.h"

#include "builtins/addtf3.h"

#endif // LLVM_LIBC_SHARED_BUILTINS_H
35 changes: 35 additions & 0 deletions libc/shared/builtins/addtf3.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//===----------------------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
///
/// \file
/// This header exposes LLVM-libc's __addtf3 implementation as shared::addtf3
/// so that it can be reused by compiler-rt's builtins.
///
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_SHARED_BUILTINS_ADDTF3_H
#define LLVM_LIBC_SHARED_BUILTINS_ADDTF3_H

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

#ifdef LIBC_TYPES_HAS_FLOAT128

#include "shared/libc_common.h"
#include "src/__support/builtins/addtf3.h"

namespace LIBC_NAMESPACE_DECL {
namespace shared {

using builtins::addtf3;

} // namespace shared
} // namespace LIBC_NAMESPACE_DECL

#endif // LIBC_TYPES_HAS_FLOAT128

#endif // LLVM_LIBC_SHARED_BUILTINS_ADDTF3_H
1 change: 1 addition & 0 deletions libc/src/__support/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,7 @@ add_subdirectory(wchar)
add_subdirectory(wctype)

add_subdirectory(math)
add_subdirectory(builtins)
if(LIBC_COMPILER_HAS_EXT_VECTOR_TYPE)
add_subdirectory(mathvec)
endif()
3 changes: 3 additions & 0 deletions libc/src/__support/FPUtil/dyadic_float.h
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,9 @@ template <size_t Bits> struct DyadicFloat {
if constexpr (cpp::is_same_v<T, bfloat16>
#if defined(LIBC_TYPES_HAS_FLOAT16) && !defined(__LIBC_USE_FLOAT16_CONVERSION)
|| cpp::is_same_v<T, float16>
#endif
#if defined(LIBC_TYPES_HAS_FLOAT128)
|| cpp::is_same_v<T, float128>
#endif
)
return generic_as<T, ShouldSignalExceptions>();
Expand Down
9 changes: 9 additions & 0 deletions libc/src/__support/builtins/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
add_header_library(
addtf3
HDRS
addtf3.h
DEPENDS
libc.include.llvm-libc-types.float128
libc.src.__support.FPUtil.generic.add_sub
libc.src.__support.macros.config
)
38 changes: 38 additions & 0 deletions libc/src/__support/builtins/addtf3.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//===----------------------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
///
/// \file
/// This header exposes LLVM-libc's __addtf3 implementation as
/// builtins::addtf3 so that it can be reused by compiler-rt's builtins.
///
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_SRC___SUPPORT_BUILTINS_ADDTF3_H
#define LLVM_LIBC_SRC___SUPPORT_BUILTINS_ADDTF3_H

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

#ifdef LIBC_TYPES_HAS_FLOAT128

#include "src/__support/FPUtil/generic/add_sub.h"
#include "src/__support/macros/config.h"

namespace LIBC_NAMESPACE_DECL {
namespace builtins {

// Mirrors the compiler-rt __addtf3 ABI: a + b at float128 precision.
LIBC_INLINE float128 addtf3(float128 x, float128 y) {
return fputil::generic::add<float128>(x, y);
}

} // namespace builtins
} // namespace LIBC_NAMESPACE_DECL

#endif // LIBC_TYPES_HAS_FLOAT128

#endif // LLVM_LIBC_SRC___SUPPORT_BUILTINS_ADDTF3_H
10 changes: 10 additions & 0 deletions libc/test/shared/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,16 @@ add_fp_unittest(
)
endif() # LIBC_TEST_SKIP_SHARED_MATH_TESTS

add_fp_unittest(
shared_builtins_test
SUITE
libc-shared-tests
SRCS
shared_builtins_test.cpp
DEPENDS
libc.src.__support.builtins.addtf3
)

add_fp_unittest(
shared_str_to_num_test
SUITE
Expand Down
29 changes: 29 additions & 0 deletions libc/test/shared/shared_builtins_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//===-- Unittests for shared builtins -------------------------------------===//
//
// 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 "shared/builtins.h"
#include "test/UnitTest/FPMatcher.h"
#include "test/UnitTest/Test.h"

TEST(LlvmLibcSharedBuiltinsTest, AllFloat) {
// TODO: assertions for shared::*sf3 builtins.
Comment thread
hulxv marked this conversation as resolved.
}

TEST(LlvmLibcSharedBuiltinsTest, AllDouble) {
// TODO: assertions for shared::*df3 builtins.
}

#ifdef LIBC_TYPES_HAS_FLOAT128

TEST(LlvmLibcSharedBuiltinsTest, AllFloat128) {
namespace shared = LIBC_NAMESPACE::shared;

EXPECT_FP_EQ(float128(3.0), shared::addtf3(float128(1.0), float128(2.0)));
}

#endif // LIBC_TYPES_HAS_FLOAT128
Loading