Skip to content

[libc][stdfix] Initial support for stdfix.h and fixed point arithmetic. #81201

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
12 changes: 10 additions & 2 deletions libc/cmake/modules/CheckCompilerFeatures.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# ------------------------------------------------------------------------------

# Initialize ALL_COMPILER_FEATURES as empty list.
set(ALL_COMPILER_FEATURES "float128")
set(ALL_COMPILER_FEATURES "float128" "fixedpoint")

# Making sure ALL_COMPILER_FEATURES is sorted.
list(SORT ALL_COMPILER_FEATURES)
Expand Down Expand Up @@ -42,16 +42,24 @@ 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)
set(compile_options ${LIBC_COMPILE_OPTIONS_NATIVE})
if(${feature} STREQUAL "fixedpoint")
list(APPEND compiler_options "-ffixed-point")
endif()

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}
COMPILE_DEFINITIONS -I${LIBC_SOURCE_DIR} ${compiler_options}
)

if(has_feature)
list(APPEND AVAILABLE_COMPILER_FEATURES ${feature})
if(${feature} STREQUAL "float128")
set(LIBC_COMPILER_HAS_FLOAT128 TRUE)
elseif(${feature} STREQUAL "fixedpoint")
set(LIBC_COMPILER_HAS_FIXED_POINT TRUE)
endif()
endif()
endforeach()
Expand Down
4 changes: 4 additions & 0 deletions libc/cmake/modules/LLVMLibCObjectRules.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ function(_get_common_compile_options output_var flags)
if(LLVM_COMPILER_IS_GCC_COMPATIBLE)
list(APPEND compile_options "-fpie")

if(LIBC_COMPILER_HAS_FIXED_POINT)
list(APPEND compile_options "-ffixed-point")
endif()

if(LLVM_LIBC_FULL_BUILD)
# Only add -ffreestanding flag in full build mode.
list(APPEND compile_options "-ffreestanding")
Expand Down
5 changes: 5 additions & 0 deletions libc/cmake/modules/compiler_features/check_fixedpoint.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include "include/llvm-libc-types/stdfix_types.h"

#ifndef LIBC_COMPILER_HAS_FIXED_POINT
#error unsupported
#endif
12 changes: 12 additions & 0 deletions libc/config/linux/x86_64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,18 @@ if(LIBC_COMPILER_HAS_FLOAT128)
)
endif()

if(LIBC_COMPILER_HAS_FIXED_POINT)
list(APPEND TARGET_LIBM_ENTRYPOINTS
# stdfix.h N1169 _Fract and _Accum entrypoints
libc.src.stdfix.abshk
libc.src.stdfix.abshr
libc.src.stdfix.absk
libc.src.stdfix.absr
libc.src.stdfix.abslk
libc.src.stdfix.abslr
)
endif()

if(LLVM_LIBC_FULL_BUILD)
list(APPEND TARGET_LIBC_ENTRYPOINTS
# assert.h entrypoints
Expand Down
9 changes: 9 additions & 0 deletions libc/include/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,15 @@ add_gen_header(
.llvm-libc-types.float128
)

add_gen_header(
stdfix
DEF_FILE stdfix.h.def
GEN_HDR stdfix.h
DEPENDS
.llvm-libc-macros.stdfix_macros
.llvm-libc-types.stdfix_types
)

# TODO: This should be conditional on POSIX networking being included.
file(MAKE_DIRECTORY ${LIBC_INCLUDE_DIR}/arpa)

Expand Down
6 changes: 6 additions & 0 deletions libc/include/llvm-libc-macros/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -227,3 +227,9 @@ add_macro_header(
HDR
inttypes-macros.h
)

add_macro_header(
stdfix_macros
HDR
stdfix-macros.h
)
Loading