Skip to content

Commit b154a98

Browse files
committed
[libc][stdfix] Initial support for stdfix.h and fixed-point arithmetic.
1 parent fbf43b0 commit b154a98

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1219
-83
lines changed

libc/cmake/modules/CheckCompilerFeatures.cmake

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# ------------------------------------------------------------------------------
44

55
# Initialize ALL_COMPILER_FEATURES as empty list.
6-
set(ALL_COMPILER_FEATURES "float128")
6+
set(ALL_COMPILER_FEATURES "float128" "fixedpoint")
77

88
# Making sure ALL_COMPILER_FEATURES is sorted.
99
list(SORT ALL_COMPILER_FEATURES)
@@ -42,16 +42,24 @@ set(AVAILABLE_COMPILER_FEATURES "")
4242
# Try compile a C file to check if flag is supported.
4343
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
4444
foreach(feature IN LISTS ALL_COMPILER_FEATURES)
45+
set(compile_options ${LIBC_COMPILE_OPTIONS_NATIVE})
46+
if(${feature} STREQUAL "fixedpoint")
47+
list(APPEND compiler_options "-ffixed-point")
48+
endif()
49+
4550
try_compile(
4651
has_feature
4752
${CMAKE_CURRENT_BINARY_DIR}/compiler_features
4853
SOURCES ${LIBC_SOURCE_DIR}/cmake/modules/compiler_features/check_${feature}.cpp
49-
COMPILE_DEFINITIONS -I${LIBC_SOURCE_DIR} ${LIBC_COMPILE_OPTIONS_NATIVE}
54+
COMPILE_DEFINITIONS -I${LIBC_SOURCE_DIR} ${compiler_options}
5055
)
56+
5157
if(has_feature)
5258
list(APPEND AVAILABLE_COMPILER_FEATURES ${feature})
5359
if(${feature} STREQUAL "float128")
5460
set(LIBC_COMPILER_HAS_FLOAT128 TRUE)
61+
elseif(${feature} STREQUAL "fixedpoint")
62+
set(LIBC_COMPILER_HAS_FIXED_POINT TRUE)
5563
endif()
5664
endif()
5765
endforeach()

libc/cmake/modules/LLVMLibCObjectRules.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ function(_get_common_compile_options output_var flags)
4444
if(LLVM_COMPILER_IS_GCC_COMPATIBLE)
4545
list(APPEND compile_options "-fpie")
4646

47+
if(LIBC_COMPILER_HAS_FIXED_POINT)
48+
list(APPEND compile_options "-ffixed-point")
49+
endif()
50+
4751
if(LLVM_LIBC_FULL_BUILD)
4852
# Only add -ffreestanding flag in full build mode.
4953
list(APPEND compile_options "-ffreestanding")
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#include "include/llvm-libc-types/stdfix_types.h"
2+
3+
#ifndef LIBC_COMPILER_HAS_FIXED_POINT
4+
#error unsupported
5+
#endif

libc/config/linux/x86_64/entrypoints.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,18 @@ if(LIBC_COMPILER_HAS_FLOAT128)
419419
)
420420
endif()
421421

422+
if(LIBC_COMPILER_HAS_FIXED_POINT)
423+
list(APPEND TARGET_LIBM_ENTRYPOINTS
424+
# stdfix.h N1169 _Fract and _Accum entrypoints
425+
libc.src.stdfix.abshk
426+
libc.src.stdfix.abshr
427+
libc.src.stdfix.absk
428+
libc.src.stdfix.absr
429+
libc.src.stdfix.abslk
430+
libc.src.stdfix.abslr
431+
)
432+
endif()
433+
422434
if(LLVM_LIBC_FULL_BUILD)
423435
list(APPEND TARGET_LIBC_ENTRYPOINTS
424436
# assert.h entrypoints

libc/include/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,15 @@ add_gen_header(
104104
.llvm-libc-types.float128
105105
)
106106

107+
add_gen_header(
108+
stdfix
109+
DEF_FILE stdfix.h.def
110+
GEN_HDR stdfix.h
111+
DEPENDS
112+
.llvm-libc-macros.stdfix_macros
113+
.llvm-libc-types.stdfix_types
114+
)
115+
107116
# TODO: This should be conditional on POSIX networking being included.
108117
file(MAKE_DIRECTORY ${LIBC_INCLUDE_DIR}/arpa)
109118

libc/include/llvm-libc-macros/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,3 +227,9 @@ add_macro_header(
227227
HDR
228228
inttypes-macros.h
229229
)
230+
231+
add_macro_header(
232+
stdfix_macros
233+
HDR
234+
stdfix-macros.h
235+
)

0 commit comments

Comments
 (0)