forked from rust-lang/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[libc][math] Add initial support for C23 float128 math functions, sta…
…rting with copysignf128. (llvm#71731)
- Loading branch information
Showing
19 changed files
with
310 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# ------------------------------------------------------------------------------ | ||
# Compiler features definition and flags | ||
# ------------------------------------------------------------------------------ | ||
|
||
# Initialize ALL_COMPILER_FEATURES as empty list. | ||
set(ALL_COMPILER_FEATURES "float128") | ||
|
||
# Making sure ALL_COMPILER_FEATURES is sorted. | ||
list(SORT ALL_COMPILER_FEATURES) | ||
|
||
# Function to check whether the compiler supports the provided set of features. | ||
# Usage: | ||
# compiler_supports( | ||
# <output variable> | ||
# <list of cpu features> | ||
# ) | ||
function(compiler_supports output_var features) | ||
_intersection(var "${LIBC_CPU_FEATURES}" "${features}") | ||
if("${var}" STREQUAL "${features}") | ||
set(${output_var} TRUE PARENT_SCOPE) | ||
else() | ||
unset(${output_var} PARENT_SCOPE) | ||
endif() | ||
endfunction() | ||
|
||
# ------------------------------------------------------------------------------ | ||
# Internal helpers and utilities. | ||
# ------------------------------------------------------------------------------ | ||
|
||
# Computes the intersection between two lists. | ||
function(_intersection output_var list1 list2) | ||
foreach(element IN LISTS list1) | ||
if("${list2}" MATCHES "(^|;)${element}(;|$)") | ||
list(APPEND tmp "${element}") | ||
endif() | ||
endforeach() | ||
set(${output_var} ${tmp} PARENT_SCOPE) | ||
endfunction() | ||
|
||
set(AVAILABLE_COMPILER_FEATURES "") | ||
|
||
# Try compile a C file to check if flag is supported. | ||
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) | ||
foreach(feature IN LISTS ALL_COMPILER_FEATURES) | ||
try_compile( | ||
has_feature | ||
${CMAKE_CURRENT_BINARY_DIR}/compiler_features | ||
SOURCES ${LIBC_SOURCE_DIR}/cmake/modules/compiler_features/check_${feature}.cpp | ||
COMPILE_DEFINITIONS -I${LIBC_SOURCE_DIR} ${LIBC_COMPILE_OPTIONS_NATIVE} | ||
) | ||
if(has_feature) | ||
list(APPEND AVAILABLE_COMPILER_FEATURES ${feature}) | ||
if(${feature} STREQUAL "float128") | ||
set(LIBC_COMPILER_HAS_FLOAT128 TRUE) | ||
endif() | ||
endif() | ||
endforeach() | ||
|
||
message(STATUS "Compiler features available: ${AVAILABLE_COMPILER_FEATURES}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#include "src/__support/macros/properties/compiler.h" | ||
|
||
#ifndef LIBC_COMPILER_HAS_FLOAT128 | ||
#error unsupported | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
//===-- Implementation header for copysignf128 ------------------*- 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_COPYSIGNF128_H | ||
#define LLVM_LIBC_SRC_MATH_COPYSIGNF128_H | ||
|
||
#include "src/__support/macros/properties/compiler.h" | ||
|
||
namespace LIBC_NAMESPACE { | ||
|
||
float128 copysignf128(float128 x, float128 y); | ||
|
||
} // namespace LIBC_NAMESPACE | ||
|
||
#endif // LLVM_LIBC_SRC_MATH_COPYSIGN_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
//===-- Implementation of copysignf128 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/copysignf128.h" | ||
#include "src/__support/FPUtil/ManipulationFunctions.h" | ||
#include "src/__support/common.h" | ||
#include "src/__support/macros/properties/compiler.h" | ||
|
||
namespace LIBC_NAMESPACE { | ||
|
||
LLVM_LIBC_FUNCTION(float128, copysignf128, (float128 x, float128 y)) { | ||
return fputil::copysign(x, y); | ||
} | ||
|
||
} // namespace LIBC_NAMESPACE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.