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
24 changes: 24 additions & 0 deletions compiler-rt/lib/builtins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,30 @@ set(GENERIC_TF_SOURCES
trunctfsf2.c
)

option(COMPILER_RT_USE_LIBC_MATH
"Use LLVM libc math routines for floating-point builtins" OFF)

# Swap the legacy soft-float <name>.c builtin in <list> for the libc-backed
# <name>.cpp implementation (which delegates to LIBC_NAMESPACE::shared::*).
macro(use_libc_builtin list_var name)
list(REMOVE_ITEM ${list_var} ${name}.c)
list(APPEND ${list_var} ${name}.cpp)
endmacro()

if(COMPILER_RT_USE_LIBC_MATH)
include(FindLibcCommonUtils)
if(NOT TARGET llvm-libc-common-utilities)
message(FATAL_ERROR "LLVM libc is not found at ${libc_path}.")
endif()

get_target_property(_libc_include_dirs llvm-libc-common-utilities
INTERFACE_INCLUDE_DIRECTORIES)
include_directories(SYSTEM ${_libc_include_dirs})
add_definitions(-DCOMPILER_RT_USE_LIBC_MATH)

use_libc_builtin(GENERIC_TF_SOURCES addtf3)
endif()

option(COMPILER_RT_EXCLUDE_ATOMIC_BUILTIN
"Skip the atomic builtin (these should normally be provided by a shared library)"
On)
Expand Down
22 changes: 22 additions & 0 deletions compiler-rt/lib/builtins/addtf3.cpp
Comment thread
hulxv marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//===-- lib/addtf3.cpp - Quad-precision addition (libc-backed) --*- 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
//
//===----------------------------------------------------------------------===//
//
// __addtf3 implemented on top of LLVM-libc's shared::addtf3 instruction.
//
//===----------------------------------------------------------------------===//

#define QUAD_PRECISION
#include "fp_lib.h"

#include "fp_libc_config.h"
#include "int_lib.h"
#include "shared/builtins/addtf3.h"

extern "C" COMPILER_RT_ABI fp_t __addtf3(fp_t a, fp_t b) {
return LIBC_NAMESPACE::shared::addtf3(a, b);
Comment thread
hulxv marked this conversation as resolved.
}
26 changes: 26 additions & 0 deletions compiler-rt/lib/builtins/fp_libc_config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//===-- lib/fp_libc_config.h - LLVM-libc compile config --------*- 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
//
//===----------------------------------------------------------------------===//
//
// Compile-time configuration consumed by LLVM-libc's fputil headers when they
// are included from compiler-rt builtins under COMPILER_RT_USE_LIBC_MATH.
// Pins the libc namespace to __llvm_libc_rt to avoid clashing with libc's own
// symbols, and disables errno / FP-exception bookkeeping inside libc routines
// called from builtins.
//
//===----------------------------------------------------------------------===//

#ifndef FP_LIBC_CONFIG_H
Comment thread
hulxv marked this conversation as resolved.
#define FP_LIBC_CONFIG_H

#ifndef LIBC_NAMESPACE
#define LIBC_NAMESPACE __llvm_libc_rt
#endif

Comment thread
hulxv marked this conversation as resolved.
#define LIBC_MATH (LIBC_MATH_NO_ERRNO | LIBC_MATH_NO_EXCEPT)

#endif // FP_LIBC_CONFIG_H