Skip to content

Commit 61cc872

Browse files
committed
[libc][stdfix] Generate stdfix.h header with fixed point precision macros according to N1169 standard, and add fixed point type support detection.
1 parent b1b8a38 commit 61cc872

File tree

9 files changed

+491
-2
lines changed

9 files changed

+491
-2
lines changed

libc/cmake/modules/CheckCompilerFeatures.cmake

Lines changed: 9 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" "fixed_point")
77

88
# Making sure ALL_COMPILER_FEATURES is sorted.
99
list(SORT ALL_COMPILER_FEATURES)
@@ -42,16 +42,23 @@ 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 "fixed_point")
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
)
5156
if(has_feature)
5257
list(APPEND AVAILABLE_COMPILER_FEATURES ${feature})
5358
if(${feature} STREQUAL "float128")
5459
set(LIBC_COMPILER_HAS_FLOAT128 TRUE)
60+
elseif(${feature} STREQUAL "fixed_point")
61+
set(LIBC_COMPILER_HAS_FIXED_POINT TRUE)
5562
endif()
5663
endif()
5764
endforeach()
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#include "include/llvm-libc-macross/stdfix_macros.h"
2+
3+
#ifndef LIBC_COMPILER_HAS_FIXED_POINT
4+
#error unsupported
5+
#endif

libc/config/linux/x86_64/headers.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ set(TARGET_PUBLIC_HEADERS
1616
libc.include.spawn
1717
libc.include.setjmp
1818
libc.include.stdbit
19+
libc.include.stdfix
1920
libc.include.stdio
2021
libc.include.stdlib
2122
libc.include.string

libc/include/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,14 @@ 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+
)
114+
107115
# TODO: This should be conditional on POSIX networking being included.
108116
file(MAKE_DIRECTORY ${LIBC_INCLUDE_DIR}/arpa)
109117

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)