diff options
author | NAKAMURA Takumi <geek4civic@gmail.com> | 2025-01-09 18:49:54 +0900 |
---|---|---|
committer | NAKAMURA Takumi <geek4civic@gmail.com> | 2025-01-09 18:49:54 +0900 |
commit | e2810c9a248f4c7fbfae84bb32b6f7e01027458b (patch) | |
tree | ae0b02a8491b969a1cee94ea16ffe42c559143c5 /libc | |
parent | fa04eb4af95c1ca7377279728cb004bcd2324d01 (diff) | |
parent | bdcf47e4bcb92889665825654bb80a8bbe30379e (diff) | |
download | llvm-users/chapuni/cov/single/switch.zip llvm-users/chapuni/cov/single/switch.tar.gz llvm-users/chapuni/cov/single/switch.tar.bz2 |
Merge branch 'users/chapuni/cov/single/base' into users/chapuni/cov/single/switchusers/chapuni/cov/single/switch
Diffstat (limited to 'libc')
-rw-r--r-- | libc/CMakeLists.txt | 2 | ||||
-rw-r--r-- | libc/cmake/modules/LLVMLibCHeaderRules.cmake | 26 | ||||
-rw-r--r-- | libc/config/baremetal/config.json | 5 | ||||
-rw-r--r-- | libc/config/gpu/amdgpu/config.json (renamed from libc/config/gpu/config.json) | 0 | ||||
-rw-r--r-- | libc/config/gpu/amdgpu/entrypoints.txt | 604 | ||||
-rw-r--r-- | libc/config/gpu/amdgpu/headers.txt (renamed from libc/config/gpu/headers.txt) | 0 | ||||
-rw-r--r-- | libc/config/gpu/nvptx/config.json | 37 | ||||
-rw-r--r-- | libc/config/gpu/nvptx/entrypoints.txt (renamed from libc/config/gpu/entrypoints.txt) | 4 | ||||
-rw-r--r-- | libc/config/gpu/nvptx/headers.txt | 21 | ||||
-rw-r--r-- | libc/docs/CMakeLists.txt | 67 | ||||
-rw-r--r-- | libc/docs/dev/header_generation.rst | 27 | ||||
-rw-r--r-- | libc/docs/dev/source_tree_layout.rst | 10 | ||||
-rw-r--r-- | libc/docs/full_cross_build.rst | 14 | ||||
-rw-r--r-- | libc/docs/headers/arpa/inet.rst | 50 | ||||
-rw-r--r-- | libc/docs/headers/assert.rst | 27 | ||||
-rw-r--r-- | libc/docs/headers/ctype.rst | 130 | ||||
-rw-r--r-- | libc/docs/headers/errno.rst | 35 | ||||
-rw-r--r-- | libc/docs/headers/fenv.rst | 175 | ||||
-rw-r--r-- | libc/docs/headers/float.rst | 227 | ||||
-rw-r--r-- | libc/docs/headers/inttypes.rst | 42 | ||||
-rw-r--r-- | libc/docs/headers/locale.rst | 83 | ||||
-rw-r--r-- | libc/docs/headers/setjmp.rst | 43 | ||||
-rw-r--r-- | libc/docs/headers/signal.rst | 207 | ||||
-rw-r--r-- | libc/docs/headers/stdbit.rst | 383 | ||||
-rw-r--r-- | libc/docs/headers/stdio.rst | 359 | ||||
-rw-r--r-- | libc/docs/headers/stdlib.rst | 255 | ||||
-rw-r--r-- | libc/docs/headers/string.rst | 163 | ||||
-rw-r--r-- | libc/docs/headers/strings.rst | 66 | ||||
-rw-r--r-- | libc/docs/headers/sys/mman.rst | 179 | ||||
-rw-r--r-- | libc/docs/headers/threads.rst | 147 | ||||
-rw-r--r-- | libc/docs/headers/uchar.rst | 59 | ||||
-rw-r--r-- | libc/docs/headers/wchar.rst | 287 | ||||
-rw-r--r-- | libc/docs/headers/wctype.rst | 86 | ||||
-rw-r--r-- | libc/fuzzing/stdlib/CMakeLists.txt | 6 | ||||
-rw-r--r-- | libc/fuzzing/stdlib/heap_sort_fuzz.cpp | 29 | ||||
-rw-r--r-- | libc/fuzzing/stdlib/quick_sort_fuzz.cpp (renamed from libc/fuzzing/stdlib/qsort_fuzz.cpp) | 29 | ||||
-rw-r--r-- | libc/hdr/types/CMakeLists.txt | 8 | ||||
-rw-r--r-- | libc/hdr/types/struct_tm.h | 21 | ||||
-rw-r--r-- | libc/include/CMakeLists.txt | 168 | ||||
-rw-r--r-- | libc/include/__llvm-libc-common.h | 19 | ||||
-rw-r--r-- | libc/include/arpa/inet.yaml (renamed from libc/hdrgen/yaml/arpa/inet.yaml) | 3 | ||||
-rw-r--r-- | libc/include/assert.yaml (renamed from libc/hdrgen/yaml/assert.yaml) | 1 | ||||
-rw-r--r-- | libc/include/complex.yaml (renamed from libc/hdrgen/yaml/complex.yaml) | 1 | ||||
-rw-r--r-- | libc/include/ctype.yaml (renamed from libc/hdrgen/yaml/ctype.yaml) | 1 | ||||
-rw-r--r-- | libc/include/dirent.yaml (renamed from libc/hdrgen/yaml/dirent.yaml) | 1 | ||||
-rw-r--r-- | libc/include/dlfcn.yaml (renamed from libc/hdrgen/yaml/dlfcn.yaml) | 1 | ||||
-rw-r--r-- | libc/include/elf.yaml (renamed from libc/hdrgen/yaml/elf.yaml) | 1 | ||||
-rw-r--r-- | libc/include/errno.yaml (renamed from libc/hdrgen/yaml/errno.yaml) | 1 | ||||
-rw-r--r-- | libc/include/fcntl.yaml (renamed from libc/hdrgen/yaml/fcntl.yaml) | 1 | ||||
-rw-r--r-- | libc/include/features.yaml (renamed from libc/hdrgen/yaml/features.yaml) | 1 | ||||
-rw-r--r-- | libc/include/fenv.yaml (renamed from libc/hdrgen/yaml/fenv.yaml) | 1 | ||||
-rw-r--r-- | libc/include/float.yaml (renamed from libc/hdrgen/yaml/float.yaml) | 1 | ||||
-rw-r--r-- | libc/include/inttypes.yaml (renamed from libc/hdrgen/yaml/inttypes.yaml) | 1 | ||||
-rw-r--r-- | libc/include/limits.yaml (renamed from libc/hdrgen/yaml/limits.yaml) | 1 | ||||
-rw-r--r-- | libc/include/link.yaml (renamed from libc/hdrgen/yaml/link.yaml) | 1 | ||||
-rw-r--r-- | libc/include/locale.yaml (renamed from libc/hdrgen/yaml/locale.yaml) | 1 | ||||
-rw-r--r-- | libc/include/malloc.yaml (renamed from libc/hdrgen/yaml/malloc.yaml) | 1 | ||||
-rw-r--r-- | libc/include/math.yaml (renamed from libc/hdrgen/yaml/math.yaml) | 1 | ||||
-rw-r--r-- | libc/include/pthread.yaml (renamed from libc/hdrgen/yaml/pthread.yaml) | 1 | ||||
-rw-r--r-- | libc/include/sched.yaml (renamed from libc/hdrgen/yaml/sched.yaml) | 1 | ||||
-rw-r--r-- | libc/include/search.yaml (renamed from libc/hdrgen/yaml/search.yaml) | 1 | ||||
-rw-r--r-- | libc/include/setjmp.yaml (renamed from libc/hdrgen/yaml/setjmp.yaml) | 1 | ||||
-rw-r--r-- | libc/include/signal.yaml (renamed from libc/hdrgen/yaml/signal.yaml) | 1 | ||||
-rw-r--r-- | libc/include/spawn.yaml (renamed from libc/hdrgen/yaml/spawn.yaml) | 1 | ||||
-rw-r--r-- | libc/include/stdbit.yaml (renamed from libc/hdrgen/yaml/stdbit.yaml) | 1 | ||||
-rw-r--r-- | libc/include/stdckdint.yaml (renamed from libc/hdrgen/yaml/stdckdint.yaml) | 1 | ||||
-rw-r--r-- | libc/include/stdfix.yaml (renamed from libc/hdrgen/yaml/stdfix.yaml) | 1 | ||||
-rw-r--r-- | libc/include/stdint.yaml (renamed from libc/hdrgen/yaml/stdint.yaml) | 1 | ||||
-rw-r--r-- | libc/include/stdio.yaml (renamed from libc/hdrgen/yaml/stdio.yaml) | 1 | ||||
-rw-r--r-- | libc/include/stdlib.yaml (renamed from libc/hdrgen/yaml/stdlib.yaml) | 1 | ||||
-rw-r--r-- | libc/include/string.yaml (renamed from libc/hdrgen/yaml/string.yaml) | 1 | ||||
-rw-r--r-- | libc/include/strings.yaml (renamed from libc/hdrgen/yaml/strings.yaml) | 1 | ||||
-rw-r--r-- | libc/include/sys/auxv.yaml (renamed from libc/hdrgen/yaml/sys/auxv.yaml) | 3 | ||||
-rw-r--r-- | libc/include/sys/epoll.yaml (renamed from libc/hdrgen/yaml/sys/epoll.yaml) | 3 | ||||
-rw-r--r-- | libc/include/sys/ioctl.yaml (renamed from libc/hdrgen/yaml/sys/ioctl.yaml) | 3 | ||||
-rw-r--r-- | libc/include/sys/mman.yaml (renamed from libc/hdrgen/yaml/sys/mman.yaml) | 3 | ||||
-rw-r--r-- | libc/include/sys/prctl.yaml (renamed from libc/hdrgen/yaml/sys/prctl.yaml) | 3 | ||||
-rw-r--r-- | libc/include/sys/random.yaml (renamed from libc/hdrgen/yaml/sys/random.yaml) | 3 | ||||
-rw-r--r-- | libc/include/sys/resource.yaml (renamed from libc/hdrgen/yaml/sys/resource.yaml) | 3 | ||||
-rw-r--r-- | libc/include/sys/select.yaml (renamed from libc/hdrgen/yaml/sys/select.yaml) | 3 | ||||
-rw-r--r-- | libc/include/sys/sendfile.yaml (renamed from libc/hdrgen/yaml/sys/sendfile.yaml) | 3 | ||||
-rw-r--r-- | libc/include/sys/socket.yaml (renamed from libc/hdrgen/yaml/sys/socket.yaml) | 3 | ||||
-rw-r--r-- | libc/include/sys/stat.yaml (renamed from libc/hdrgen/yaml/sys/stat.yaml) | 3 | ||||
-rw-r--r-- | libc/include/sys/statvfs.yaml (renamed from libc/hdrgen/yaml/sys/statvfs.yaml) | 3 | ||||
-rw-r--r-- | libc/include/sys/syscall.yaml (renamed from libc/hdrgen/yaml/sys/syscall.yaml) | 3 | ||||
-rw-r--r-- | libc/include/sys/time.yaml (renamed from libc/hdrgen/yaml/sys/time.yaml) | 3 | ||||
-rw-r--r-- | libc/include/sys/types.yaml (renamed from libc/hdrgen/yaml/sys/types.yaml) | 3 | ||||
-rw-r--r-- | libc/include/sys/utsname.yaml (renamed from libc/hdrgen/yaml/sys/utsname.yaml) | 3 | ||||
-rw-r--r-- | libc/include/sys/wait.yaml (renamed from libc/hdrgen/yaml/sys/wait.yaml) | 3 | ||||
-rw-r--r-- | libc/include/termios.yaml (renamed from libc/hdrgen/yaml/termios.yaml) | 1 | ||||
-rw-r--r-- | libc/include/threads.yaml (renamed from libc/hdrgen/yaml/threads.yaml) | 1 | ||||
-rw-r--r-- | libc/include/time.yaml (renamed from libc/hdrgen/yaml/time.yaml) | 1 | ||||
-rw-r--r-- | libc/include/uchar.yaml (renamed from libc/hdrgen/yaml/uchar.yaml) | 1 | ||||
-rw-r--r-- | libc/include/unistd.yaml (renamed from libc/hdrgen/yaml/unistd.yaml) | 1 | ||||
-rw-r--r-- | libc/include/wchar.yaml (renamed from libc/hdrgen/yaml/wchar.yaml) | 1 | ||||
-rw-r--r-- | libc/shared/rpc_util.h | 4 | ||||
-rw-r--r-- | libc/src/__support/CMakeLists.txt | 2 | ||||
-rw-r--r-- | libc/src/__support/File/file.cpp | 68 | ||||
-rw-r--r-- | libc/src/__support/File/file.h | 4 | ||||
-rw-r--r-- | libc/src/__support/GPU/CMakeLists.txt | 10 | ||||
-rw-r--r-- | libc/src/__support/GPU/amdgpu/CMakeLists.txt | 7 | ||||
-rw-r--r-- | libc/src/__support/GPU/amdgpu/utils.h | 183 | ||||
-rw-r--r-- | libc/src/__support/GPU/generic/CMakeLists.txt | 7 | ||||
-rw-r--r-- | libc/src/__support/GPU/generic/utils.h | 84 | ||||
-rw-r--r-- | libc/src/__support/GPU/nvptx/CMakeLists.txt | 7 | ||||
-rw-r--r-- | libc/src/__support/GPU/nvptx/utils.h | 160 | ||||
-rw-r--r-- | libc/src/__support/GPU/utils.h | 108 | ||||
-rw-r--r-- | libc/src/__support/fixedvector.h | 54 | ||||
-rw-r--r-- | libc/src/__support/threads/thread.cpp | 4 | ||||
-rw-r--r-- | libc/src/compiler/generic/__stack_chk_fail.cpp | 3 | ||||
-rw-r--r-- | libc/src/math/docs/add_math_function.md | 2 | ||||
-rw-r--r-- | libc/src/math/generic/CMakeLists.txt | 3 | ||||
-rw-r--r-- | libc/src/math/generic/exp10f_impl.h | 3 | ||||
-rw-r--r-- | libc/src/math/generic/range_reduction_double_common.h | 1 | ||||
-rw-r--r-- | libc/src/math/generic/sincosf16_utils.h | 2 | ||||
-rw-r--r-- | libc/src/pthread/pthread_condattr_init.cpp | 4 | ||||
-rw-r--r-- | libc/src/pthread/pthread_condattr_setclock.cpp | 6 | ||||
-rw-r--r-- | libc/src/stdlib/exit_handler.h | 2 | ||||
-rw-r--r-- | libc/src/stdlib/heap_sort.h | 12 | ||||
-rw-r--r-- | libc/src/stdlib/qsort.cpp | 10 | ||||
-rw-r--r-- | libc/src/stdlib/qsort_data.h | 171 | ||||
-rw-r--r-- | libc/src/stdlib/qsort_pivot.h | 85 | ||||
-rw-r--r-- | libc/src/stdlib/qsort_r.cpp | 11 | ||||
-rw-r--r-- | libc/src/stdlib/qsort_util.h | 47 | ||||
-rw-r--r-- | libc/src/stdlib/quick_sort.h | 203 | ||||
-rw-r--r-- | libc/src/time/CMakeLists.txt | 30 | ||||
-rw-r--r-- | libc/src/time/asctime.cpp | 8 | ||||
-rw-r--r-- | libc/src/time/asctime.h | 2 | ||||
-rw-r--r-- | libc/src/time/asctime_r.cpp | 6 | ||||
-rw-r--r-- | libc/src/time/asctime_r.h | 2 | ||||
-rw-r--r-- | libc/src/time/ctime.cpp | 11 | ||||
-rw-r--r-- | libc/src/time/ctime_r.cpp | 9 | ||||
-rw-r--r-- | libc/src/time/difftime.h | 2 | ||||
-rw-r--r-- | libc/src/time/gmtime.h | 3 | ||||
-rw-r--r-- | libc/src/time/gmtime_r.h | 3 | ||||
-rw-r--r-- | libc/src/time/gpu/clock.cpp | 2 | ||||
-rw-r--r-- | libc/src/time/gpu/nanosleep.cpp | 1 | ||||
-rw-r--r-- | libc/src/time/mktime.cpp | 37 | ||||
-rw-r--r-- | libc/src/time/mktime.h | 3 | ||||
-rw-r--r-- | libc/src/time/time.cpp | 3 | ||||
-rw-r--r-- | libc/src/time/time_constants.h | 100 | ||||
-rw-r--r-- | libc/src/time/time_utils.cpp | 53 | ||||
-rw-r--r-- | libc/src/time/time_utils.h | 93 | ||||
-rw-r--r-- | libc/src/unistd/linux/dup2.cpp | 1 | ||||
-rw-r--r-- | libc/test/UnitTest/FPMatcher.h | 8 | ||||
-rw-r--r-- | libc/test/src/stdlib/CMakeLists.txt | 18 | ||||
-rw-r--r-- | libc/test/src/stdlib/SortingTest.h | 203 | ||||
-rw-r--r-- | libc/test/src/stdlib/heap_sort_test.cpp | 18 | ||||
-rw-r--r-- | libc/test/src/stdlib/qsort_r_test.cpp | 4 | ||||
-rw-r--r-- | libc/test/src/stdlib/qsort_test.cpp | 17 | ||||
-rw-r--r-- | libc/test/src/stdlib/quick_sort_test.cpp | 19 | ||||
-rw-r--r-- | libc/test/src/time/CMakeLists.txt | 25 | ||||
-rw-r--r-- | libc/test/src/time/TmHelper.h | 9 | ||||
-rw-r--r-- | libc/test/src/time/TmMatcher.h | 3 | ||||
-rw-r--r-- | libc/test/src/time/asctime_r_test.cpp | 8 | ||||
-rw-r--r-- | libc/test/src/time/clock_gettime_test.cpp | 5 | ||||
-rw-r--r-- | libc/test/src/time/clock_test.cpp | 3 | ||||
-rw-r--r-- | libc/test/src/time/ctime_r_test.cpp | 12 | ||||
-rw-r--r-- | libc/test/src/time/difftime_test.cpp | 7 | ||||
-rw-r--r-- | libc/test/src/time/gettimeofday_test.cpp | 3 | ||||
-rw-r--r-- | libc/test/src/time/gmtime_r_test.cpp | 46 | ||||
-rw-r--r-- | libc/test/src/time/gmtime_test.cpp | 383 | ||||
-rw-r--r-- | libc/test/src/time/mktime_test.cpp | 438 | ||||
-rw-r--r-- | libc/test/src/time/nanosleep_test.cpp | 3 | ||||
-rw-r--r-- | libc/utils/CMakeLists.txt | 2 | ||||
-rw-r--r-- | libc/utils/docgen/arpa/inet.yaml | 16 | ||||
-rw-r--r-- | libc/utils/docgen/strings.yaml | 26 | ||||
-rw-r--r-- | libc/utils/docgen/sys/mman.yaml | 74 | ||||
-rw-r--r-- | libc/utils/hdrgen/CMakeLists.txt (renamed from libc/hdrgen/CMakeLists.txt) | 4 | ||||
-rw-r--r-- | libc/utils/hdrgen/README.rst | 4 | ||||
-rw-r--r-- | libc/utils/hdrgen/enumeration.py (renamed from libc/hdrgen/class_implementation/classes/enumeration.py) | 0 | ||||
-rw-r--r-- | libc/utils/hdrgen/function.py (renamed from libc/hdrgen/class_implementation/classes/function.py) | 0 | ||||
-rw-r--r-- | libc/utils/hdrgen/gpu_headers.py (renamed from libc/hdrgen/gpu_headers.py) | 26 | ||||
-rw-r--r-- | libc/utils/hdrgen/header.py (renamed from libc/hdrgen/header.py) | 3 | ||||
-rw-r--r-- | libc/utils/hdrgen/macro.py (renamed from libc/hdrgen/class_implementation/classes/macro.py) | 0 | ||||
-rwxr-xr-x | libc/utils/hdrgen/main.py | 91 | ||||
-rw-r--r-- | libc/utils/hdrgen/object.py (renamed from libc/hdrgen/class_implementation/classes/object.py) | 0 | ||||
-rw-r--r-- | libc/utils/hdrgen/tests/expected_output/test_header.h (renamed from libc/hdrgen/tests/expected_output/test_header.h) | 0 | ||||
-rw-r--r-- | libc/utils/hdrgen/tests/input/test_small.h.def (renamed from libc/hdrgen/tests/input/test_small.h.def) | 0 | ||||
-rw-r--r-- | libc/utils/hdrgen/tests/input/test_small.yaml (renamed from libc/hdrgen/tests/input/test_small.yaml) | 5 | ||||
-rw-r--r-- | libc/utils/hdrgen/tests/test_integration.py (renamed from libc/hdrgen/tests/test_integration.py) | 52 | ||||
-rw-r--r-- | libc/utils/hdrgen/type.py (renamed from libc/hdrgen/class_implementation/classes/type.py) | 0 | ||||
-rw-r--r-- | libc/utils/hdrgen/yaml_functions_sorted.py (renamed from libc/hdrgen/yaml_functions_sorted.py) | 0 | ||||
-rw-r--r-- | libc/utils/hdrgen/yaml_to_classes.py (renamed from libc/hdrgen/yaml_to_classes.py) | 31 |
184 files changed, 2686 insertions, 4707 deletions
diff --git a/libc/CMakeLists.txt b/libc/CMakeLists.txt index 00a07ea..6f1c180 100644 --- a/libc/CMakeLists.txt +++ b/libc/CMakeLists.txt @@ -64,8 +64,6 @@ if(LIBC_BUILD_GPU_LOADER OR ((NOT LLVM_RUNTIMES_BUILD) AND LLVM_LIBC_GPU_BUILD)) return() endif() -add_subdirectory(hdrgen) - option(LIBC_CMAKE_VERBOSE_LOGGING "Log details warnings and notifications during CMake configuration." OFF) diff --git a/libc/cmake/modules/LLVMLibCHeaderRules.cmake b/libc/cmake/modules/LLVMLibCHeaderRules.cmake index 31a88f0..288e4da 100644 --- a/libc/cmake/modules/LLVMLibCHeaderRules.cmake +++ b/libc/cmake/modules/LLVMLibCHeaderRules.cmake @@ -75,7 +75,7 @@ function(add_gen_header target_name) cmake_parse_arguments( "ADD_GEN_HDR" "PUBLIC" # No optional arguments - "YAML_FILE;DEF_FILE;GEN_HDR" # Single value arguments + "YAML_FILE;GEN_HDR" # Single value arguments "DEPENDS" # Multi value arguments ${ARGN} ) @@ -84,9 +84,6 @@ function(add_gen_header target_name) add_library(${fq_target_name} INTERFACE) return() endif() - if(NOT ADD_GEN_HDR_DEF_FILE) - message(FATAL_ERROR "`add_gen_hdr` rule requires DEF_FILE to be specified.") - endif() if(NOT ADD_GEN_HDR_GEN_HDR) message(FATAL_ERROR "`add_gen_hdr` rule requires GEN_HDR to be specified.") endif() @@ -97,8 +94,8 @@ function(add_gen_header target_name) set(absolute_path ${CMAKE_CURRENT_SOURCE_DIR}/${ADD_GEN_HDR_GEN_HDR}) file(RELATIVE_PATH relative_path ${LIBC_INCLUDE_SOURCE_DIR} ${absolute_path}) set(out_file ${LIBC_INCLUDE_DIR}/${relative_path}) + set(dep_file "${out_file}.d") set(yaml_file ${CMAKE_SOURCE_DIR}/${ADD_GEN_HDR_YAML_FILE}) - set(def_file ${CMAKE_CURRENT_SOURCE_DIR}/${ADD_GEN_HDR_DEF_FILE}) set(fq_data_files "") if(ADD_GEN_HDR_DATA_FILES) @@ -108,17 +105,20 @@ function(add_gen_header target_name) endif() set(entry_points "${TARGET_ENTRYPOINT_NAME_LIST}") - list(TRANSFORM entry_points PREPEND "--e=") + list(TRANSFORM entry_points PREPEND "--entry-point=") add_custom_command( OUTPUT ${out_file} - COMMAND ${Python3_EXECUTABLE} ${LIBC_SOURCE_DIR}/hdrgen/yaml_to_classes.py - ${yaml_file} - --h_def_file ${def_file} + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + COMMAND ${Python3_EXECUTABLE} "${LIBC_SOURCE_DIR}/utils/hdrgen/main.py" + --output ${out_file} + --depfile ${dep_file} + --write-if-changed ${entry_points} - --output_dir ${out_file} - DEPENDS ${yaml_file} ${def_file} ${fq_data_files} - COMMENT "Generating header ${ADD_GEN_HDR_GEN_HDR} from ${yaml_file} and ${def_file}" + ${yaml_file} + DEPENDS ${yaml_file} ${fq_data_files} + DEPFILE ${dep_file} + COMMENT "Generating header ${ADD_GEN_HDR_GEN_HDR} from ${yaml_file}" ) if(LIBC_TARGET_OS_IS_GPU) file(MAKE_DIRECTORY ${LIBC_INCLUDE_DIR}/llvm-libc-decls) @@ -126,7 +126,7 @@ function(add_gen_header target_name) set(decl_out_file ${LIBC_INCLUDE_DIR}/llvm-libc-decls/${relative_path}) add_custom_command( OUTPUT ${decl_out_file} - COMMAND ${Python3_EXECUTABLE} ${LIBC_SOURCE_DIR}/hdrgen/yaml_to_classes.py + COMMAND ${Python3_EXECUTABLE} "${LIBC_SOURCE_DIR}/utils/hdrgen/yaml_to_classes.py" ${yaml_file} --export-decls ${entry_points} diff --git a/libc/config/baremetal/config.json b/libc/config/baremetal/config.json index 85e8087..08c581d 100644 --- a/libc/config/baremetal/config.json +++ b/libc/config/baremetal/config.json @@ -30,10 +30,5 @@ "LIBC_CONF_MATH_OPTIMIZATIONS": { "value": "(LIBC_MATH_SKIP_ACCURATE_PASS | LIBC_MATH_SMALL_TABLES)" } - }, - "codegen": { - "LIBC_CONF_KEEP_FRAME_POINTER": { - "value": false - } } } diff --git a/libc/config/gpu/config.json b/libc/config/gpu/amdgpu/config.json index d99f48e..d99f48e 100644 --- a/libc/config/gpu/config.json +++ b/libc/config/gpu/amdgpu/config.json diff --git a/libc/config/gpu/amdgpu/entrypoints.txt b/libc/config/gpu/amdgpu/entrypoints.txt new file mode 100644 index 0000000..7a19828 --- /dev/null +++ b/libc/config/gpu/amdgpu/entrypoints.txt @@ -0,0 +1,604 @@ +set(TARGET_LIBC_ENTRYPOINTS + # assert.h entrypoints + libc.src.assert.__assert_fail + + # ctype.h entrypoints + libc.src.ctype.isalnum + libc.src.ctype.isalnum_l + libc.src.ctype.isalpha + libc.src.ctype.isalpha_l + libc.src.ctype.isascii + libc.src.ctype.isblank + libc.src.ctype.isblank_l + libc.src.ctype.iscntrl + libc.src.ctype.iscntrl_l + libc.src.ctype.isdigit + libc.src.ctype.isdigit_l + libc.src.ctype.isgraph + libc.src.ctype.isgraph_l + libc.src.ctype.islower + libc.src.ctype.islower_l + libc.src.ctype.isprint + libc.src.ctype.isprint_l + libc.src.ctype.ispunct + libc.src.ctype.ispunct_l + libc.src.ctype.isspace + libc.src.ctype.isspace_l + libc.src.ctype.isupper + libc.src.ctype.isupper_l + libc.src.ctype.isxdigit + libc.src.ctype.isxdigit_l + libc.src.ctype.toascii + libc.src.ctype.tolower + libc.src.ctype.tolower_l + libc.src.ctype.toupper + libc.src.ctype.toupper_l + + # string.h entrypoints + libc.src.string.memccpy + libc.src.string.memchr + libc.src.string.memcmp + libc.src.string.memcpy + libc.src.string.memmem + libc.src.string.memmove + libc.src.string.mempcpy + libc.src.string.memrchr + libc.src.string.memset + libc.src.string.stpcpy + libc.src.string.stpncpy + libc.src.string.strcasestr + libc.src.string.strcat + libc.src.string.strchr + libc.src.string.strchrnul + libc.src.string.strcmp + libc.src.string.strcoll + libc.src.string.strcoll_l + libc.src.string.strcpy + libc.src.string.strcspn + libc.src.string.strdup + libc.src.string.strerror + libc.src.string.strlcat + libc.src.string.strlcpy + libc.src.string.strlen + libc.src.string.strncat + libc.src.string.strncmp + libc.src.string.strncpy + libc.src.string.strndup + libc.src.string.strnlen + libc.src.string.strpbrk + libc.src.string.strrchr + libc.src.string.strsep + libc.src.string.strspn + libc.src.string.strstr + libc.src.string.strtok + libc.src.string.strtok_r + libc.src.string.strxfrm + libc.src.string.strxfrm_l + + # strings.h entrypoints + libc.src.strings.bcmp + libc.src.strings.bcopy + libc.src.strings.bzero + libc.src.strings.index + libc.src.strings.rindex + libc.src.strings.strcasecmp + libc.src.strings.strncasecmp + + # stdbit.h entrypoints + libc.src.stdbit.stdc_bit_ceil_uc + libc.src.stdbit.stdc_bit_ceil_ui + libc.src.stdbit.stdc_bit_ceil_ul + libc.src.stdbit.stdc_bit_ceil_ull + libc.src.stdbit.stdc_bit_ceil_us + libc.src.stdbit.stdc_bit_floor_uc + libc.src.stdbit.stdc_bit_floor_ui + libc.src.stdbit.stdc_bit_floor_ul + libc.src.stdbit.stdc_bit_floor_ull + libc.src.stdbit.stdc_bit_floor_us + libc.src.stdbit.stdc_bit_width_uc + libc.src.stdbit.stdc_bit_width_ui + libc.src.stdbit.stdc_bit_width_ul + libc.src.stdbit.stdc_bit_width_ull + libc.src.stdbit.stdc_bit_width_us + libc.src.stdbit.stdc_count_ones_uc + libc.src.stdbit.stdc_count_ones_ui + libc.src.stdbit.stdc_count_ones_ul + libc.src.stdbit.stdc_count_ones_ull + libc.src.stdbit.stdc_count_ones_us + libc.src.stdbit.stdc_count_zeros_uc + libc.src.stdbit.stdc_count_zeros_ui + libc.src.stdbit.stdc_count_zeros_ul + libc.src.stdbit.stdc_count_zeros_ull + libc.src.stdbit.stdc_count_zeros_us + libc.src.stdbit.stdc_first_leading_one_uc + libc.src.stdbit.stdc_first_leading_one_ui + libc.src.stdbit.stdc_first_leading_one_ul + libc.src.stdbit.stdc_first_leading_one_ull + libc.src.stdbit.stdc_first_leading_one_us + libc.src.stdbit.stdc_first_leading_zero_uc + libc.src.stdbit.stdc_first_leading_zero_ui + libc.src.stdbit.stdc_first_leading_zero_ul + libc.src.stdbit.stdc_first_leading_zero_ull + libc.src.stdbit.stdc_first_leading_zero_us + libc.src.stdbit.stdc_first_trailing_one_uc + libc.src.stdbit.stdc_first_trailing_one_ui + libc.src.stdbit.stdc_first_trailing_one_ul + libc.src.stdbit.stdc_first_trailing_one_ull + libc.src.stdbit.stdc_first_trailing_one_us + libc.src.stdbit.stdc_first_trailing_zero_uc + libc.src.stdbit.stdc_first_trailing_zero_ui + libc.src.stdbit.stdc_first_trailing_zero_ul + libc.src.stdbit.stdc_first_trailing_zero_ull + libc.src.stdbit.stdc_first_trailing_zero_us + libc.src.stdbit.stdc_has_single_bit_uc + libc.src.stdbit.stdc_has_single_bit_ui + libc.src.stdbit.stdc_has_single_bit_ul + libc.src.stdbit.stdc_has_single_bit_ull + libc.src.stdbit.stdc_has_single_bit_us + libc.src.stdbit.stdc_leading_ones_uc + libc.src.stdbit.stdc_leading_ones_ui + libc.src.stdbit.stdc_leading_ones_ul + libc.src.stdbit.stdc_leading_ones_ull + libc.src.stdbit.stdc_leading_ones_us + libc.src.stdbit.stdc_leading_zeros_uc + libc.src.stdbit.stdc_leading_zeros_ui + libc.src.stdbit.stdc_leading_zeros_ul + libc.src.stdbit.stdc_leading_zeros_ull + libc.src.stdbit.stdc_leading_zeros_us + libc.src.stdbit.stdc_trailing_ones_uc + libc.src.stdbit.stdc_trailing_ones_ui + libc.src.stdbit.stdc_trailing_ones_ul + libc.src.stdbit.stdc_trailing_ones_ull + libc.src.stdbit.stdc_trailing_ones_us + libc.src.stdbit.stdc_trailing_zeros_uc + libc.src.stdbit.stdc_trailing_zeros_ui + libc.src.stdbit.stdc_trailing_zeros_ul + libc.src.stdbit.stdc_trailing_zeros_ull + libc.src.stdbit.stdc_trailing_zeros_us + + # stdlib.h entrypoints + libc.src.stdlib._Exit + libc.src.stdlib.abort + libc.src.stdlib.abs + libc.src.stdlib.atexit + libc.src.stdlib.atof + libc.src.stdlib.atoi + libc.src.stdlib.atol + libc.src.stdlib.atoll + libc.src.stdlib.bsearch + libc.src.stdlib.div + libc.src.stdlib.exit + libc.src.stdlib.labs + libc.src.stdlib.ldiv + libc.src.stdlib.llabs + libc.src.stdlib.lldiv + libc.src.stdlib.qsort + libc.src.stdlib.qsort_r + libc.src.stdlib.rand + libc.src.stdlib.srand + libc.src.stdlib.strtod + libc.src.stdlib.strtod_l + libc.src.stdlib.strtof + libc.src.stdlib.strtof_l + libc.src.stdlib.strtol + libc.src.stdlib.strtol_l + libc.src.stdlib.strtold + libc.src.stdlib.strtold_l + libc.src.stdlib.strtoll + libc.src.stdlib.strtoll_l + libc.src.stdlib.strtoul + libc.src.stdlib.strtoul_l + libc.src.stdlib.strtoull + libc.src.stdlib.strtoull_l + libc.src.stdlib.at_quick_exit + libc.src.stdlib.quick_exit + libc.src.stdlib.getenv + libc.src.stdlib.system + + # TODO: Implement these correctly + libc.src.stdlib.aligned_alloc + libc.src.stdlib.calloc + libc.src.stdlib.free + libc.src.stdlib.malloc + libc.src.stdlib.realloc + + # errno.h entrypoints + libc.src.errno.errno + + # stdio.h entrypoints + libc.src.stdio.clearerr + libc.src.stdio.fclose + libc.src.stdio.printf + libc.src.stdio.vprintf + libc.src.stdio.fprintf + libc.src.stdio.vfprintf + libc.src.stdio.snprintf + libc.src.stdio.sprintf + libc.src.stdio.vsnprintf + libc.src.stdio.vsprintf + libc.src.stdio.asprintf + libc.src.stdio.vasprintf + libc.src.stdio.scanf + libc.src.stdio.vscanf + libc.src.stdio.fscanf + libc.src.stdio.vfscanf + libc.src.stdio.sscanf + libc.src.stdio.vsscanf + libc.src.stdio.feof + libc.src.stdio.ferror + libc.src.stdio.fflush + libc.src.stdio.fgetc + libc.src.stdio.fgets + libc.src.stdio.fopen + libc.src.stdio.fputc + libc.src.stdio.fputs + libc.src.stdio.fread + libc.src.stdio.fseek + libc.src.stdio.ftell + libc.src.stdio.fwrite + libc.src.stdio.getc + libc.src.stdio.getchar + libc.src.stdio.putc + libc.src.stdio.putchar + libc.src.stdio.puts + libc.src.stdio.remove + libc.src.stdio.rename + libc.src.stdio.stderr + libc.src.stdio.stdin + libc.src.stdio.stdout + libc.src.stdio.ungetc + + # inttypes.h entrypoints + libc.src.inttypes.imaxabs + libc.src.inttypes.imaxdiv + libc.src.inttypes.strtoimax + libc.src.inttypes.strtoumax + + # time.h entrypoints + libc.src.time.clock + libc.src.time.clock_gettime + libc.src.time.timespec_get + libc.src.time.nanosleep + + # wchar.h entrypoints + libc.src.wchar.wctob + + # locale.h entrypoints + libc.src.locale.localeconv + libc.src.locale.duplocale + libc.src.locale.freelocale + libc.src.locale.localeconv + libc.src.locale.newlocale + libc.src.locale.setlocale + libc.src.locale.uselocale +) + +set(TARGET_LIBM_ENTRYPOINTS + # math.h entrypoints + libc.src.math.acos + libc.src.math.acosf + libc.src.math.acosh + libc.src.math.acoshf + libc.src.math.asin + libc.src.math.asinf + libc.src.math.asinh + libc.src.math.asinhf + libc.src.math.atan + libc.src.math.atan2 + libc.src.math.atan2f + libc.src.math.atan2l + libc.src.math.atanf + libc.src.math.atanh + libc.src.math.atanhf + libc.src.math.canonicalize + libc.src.math.canonicalizef + libc.src.math.canonicalizel + libc.src.math.cbrt + libc.src.math.cbrtf + libc.src.math.ceil + libc.src.math.ceilf + libc.src.math.ceill + libc.src.math.copysign + libc.src.math.copysignf + libc.src.math.copysignl + libc.src.math.cos + libc.src.math.cosf + libc.src.math.cosh + libc.src.math.coshf + libc.src.math.cospif + libc.src.math.ddivl + libc.src.math.dfmal + libc.src.math.dmull + libc.src.math.dsqrtl + libc.src.math.erf + libc.src.math.erff + libc.src.math.exp + libc.src.math.exp10 + libc.src.math.exp10f + libc.src.math.exp2 + libc.src.math.exp2f + libc.src.math.exp2m1f + libc.src.math.expf + libc.src.math.expm1 + libc.src.math.expm1f + libc.src.math.fabs + libc.src.math.fabsf + libc.src.math.fabsl + libc.src.math.fadd + libc.src.math.faddl + libc.src.math.fdim + libc.src.math.fdimf + libc.src.math.fdiml + libc.src.math.fdiv + libc.src.math.fdivl + libc.src.math.ffma + libc.src.math.ffmal + libc.src.math.floor + libc.src.math.floorf + libc.src.math.floorl + libc.src.math.fma + libc.src.math.fmaf + libc.src.math.fmax + libc.src.math.fmaxf + libc.src.math.fmaximum + libc.src.math.fmaximumf + libc.src.math.fmaximuml + libc.src.math.fmaximum_mag + libc.src.math.fmaximum_magf + libc.src.math.fmaximum_magl + libc.src.math.fmaximum_mag_num + libc.src.math.fmaximum_mag_numf + libc.src.math.fmaximum_mag_numl + libc.src.math.fmaximum_num + libc.src.math.fmaximum_numf + libc.src.math.fmaximum_numl + libc.src.math.fmaxl + libc.src.math.fmin + libc.src.math.fminf + libc.src.math.fminimum + libc.src.math.fminimumf + libc.src.math.fminimuml + libc.src.math.fminimum_mag + libc.src.math.fminimum_magf + libc.src.math.fminimum_magl + libc.src.math.fminimum_mag_num + libc.src.math.fminimum_mag_numf + libc.src.math.fminimum_mag_numl + libc.src.math.fminimum_num + libc.src.math.fminimum_numf + libc.src.math.fminimum_numl + libc.src.math.fminl + libc.src.math.fmod + libc.src.math.fmodf + libc.src.math.fmodl + libc.src.math.fmul + libc.src.math.fmull + libc.src.math.frexp + libc.src.math.frexpf + libc.src.math.frexpl + libc.src.math.fromfp + libc.src.math.fromfpf + libc.src.math.fromfpl + libc.src.math.fromfpx + libc.src.math.fromfpxf + libc.src.math.fromfpxl + libc.src.math.fsqrt + libc.src.math.fsqrtl + libc.src.math.fsub + libc.src.math.fsubl + libc.src.math.getpayload + libc.src.math.getpayloadf + libc.src.math.getpayloadl + libc.src.math.hypot + libc.src.math.hypotf + libc.src.math.ilogb + libc.src.math.ilogbf + libc.src.math.ilogbl + libc.src.math.isnan + libc.src.math.isnanf + libc.src.math.isnanl + libc.src.math.ldexp + libc.src.math.ldexpf + libc.src.math.ldexpl + libc.src.math.lgamma + libc.src.math.lgamma_r + libc.src.math.llogb + libc.src.math.llogbf + libc.src.math.llogbl + libc.src.math.llrint + libc.src.math.llrintf + libc.src.math.llrintl + libc.src.math.llround + libc.src.math.llroundf + libc.src.math.llroundl + libc.src.math.log + libc.src.math.log10 + libc.src.math.log10f + libc.src.math.log1p + libc.src.math.log1pf + libc.src.math.log2 + libc.src.math.log2f + libc.src.math.logb + libc.src.math.logbf + libc.src.math.logbl + libc.src.math.logf + libc.src.math.lrint + libc.src.math.lrintf + libc.src.math.lrintl + libc.src.math.lround + libc.src.math.lroundf + libc.src.math.lroundl + libc.src.math.modf + libc.src.math.modff + libc.src.math.modfl + libc.src.math.nan + libc.src.math.nanf + libc.src.math.nanl + libc.src.math.nearbyint + libc.src.math.nearbyintf + libc.src.math.nearbyintl + libc.src.math.nextafter + libc.src.math.nextafterf + libc.src.math.nextafterl + libc.src.math.nextdown + libc.src.math.nextdownf + libc.src.math.nextdownl + libc.src.math.nexttoward + libc.src.math.nexttowardf + libc.src.math.nexttowardl + libc.src.math.nextup + libc.src.math.nextupf + libc.src.math.nextupl + libc.src.math.pow + libc.src.math.powf + libc.src.math.powi + libc.src.math.powif + libc.src.math.remainder + libc.src.math.remainderf + libc.src.math.remainderl + libc.src.math.remquo + libc.src.math.remquof + libc.src.math.remquol + libc.src.math.rint + libc.src.math.rintf + libc.src.math.rintl + libc.src.math.roundeven + libc.src.math.roundevenf + libc.src.math.roundevenl + libc.src.math.round + libc.src.math.roundf + libc.src.math.roundl + libc.src.math.scalbln + libc.src.math.scalblnf + libc.src.math.scalblnl + libc.src.math.scalbn + libc.src.math.scalbnf + libc.src.math.scalbnl + libc.src.math.setpayload + libc.src.math.setpayloadf + libc.src.math.setpayloadl + libc.src.math.setpayloadsig + libc.src.math.setpayloadsigf + libc.src.math.setpayloadsigl + libc.src.math.sin + libc.src.math.sincos + libc.src.math.sincosf + libc.src.math.sinf + libc.src.math.sinh + libc.src.math.sinhf + libc.src.math.sinpif + libc.src.math.sqrt + libc.src.math.sqrtf + libc.src.math.sqrtl + libc.src.math.tan + libc.src.math.tanf + libc.src.math.tanh + libc.src.math.tanhf + libc.src.math.tgamma + libc.src.math.tgammaf + libc.src.math.totalorder + libc.src.math.totalorderf + libc.src.math.totalorderl + libc.src.math.totalordermag + libc.src.math.totalordermagf + libc.src.math.totalordermagl + libc.src.math.trunc + libc.src.math.truncf + libc.src.math.truncl + libc.src.math.ufromfp + libc.src.math.ufromfpf + libc.src.math.ufromfpl + libc.src.math.ufromfpx + libc.src.math.ufromfpxf + libc.src.math.ufromfpxl +) + +if(LIBC_TYPES_HAS_FLOAT16) + list(APPEND TARGET_LIBM_ENTRYPOINTS + # math.h C23 _Float16 entrypoints + libc.src.math.canonicalizef16 + libc.src.math.ceilf16 + libc.src.math.copysignf16 + libc.src.math.coshf16 + libc.src.math.exp10f16 + libc.src.math.exp10m1f16 + libc.src.math.exp2f16 + libc.src.math.expf16 + libc.src.math.f16add + libc.src.math.f16addf + libc.src.math.f16addl + libc.src.math.f16div + libc.src.math.f16divf + libc.src.math.f16divl + libc.src.math.f16fma + libc.src.math.f16fmaf + libc.src.math.f16fmal + libc.src.math.f16mul + libc.src.math.f16mulf + libc.src.math.f16mull + libc.src.math.f16sqrt + libc.src.math.f16sqrtf + libc.src.math.f16sqrtl + libc.src.math.f16sub + libc.src.math.f16subf + libc.src.math.f16subl + libc.src.math.fabsf16 + libc.src.math.fdimf16 + libc.src.math.floorf16 + libc.src.math.fmaxf16 + libc.src.math.fmaximum_mag_numf16 + libc.src.math.fmaximum_magf16 + libc.src.math.fmaximum_numf16 + libc.src.math.fmaximumf16 + libc.src.math.fminf16 + libc.src.math.fminimum_mag_numf16 + libc.src.math.fminimum_magf16 + libc.src.math.fminimum_numf16 + libc.src.math.fminimumf16 + libc.src.math.fmodf16 + libc.src.math.frexpf16 + libc.src.math.fromfpf16 + libc.src.math.fromfpxf16 + libc.src.math.getpayloadf16 + libc.src.math.ilogbf16 + libc.src.math.ldexpf16 + libc.src.math.llogbf16 + libc.src.math.llrintf16 + libc.src.math.llroundf16 + libc.src.math.log10f16 + libc.src.math.log2f16 + libc.src.math.logbf16 + libc.src.math.logf16 + libc.src.math.lrintf16 + libc.src.math.lroundf16 + libc.src.math.modff16 + libc.src.math.nanf16 + libc.src.math.nearbyintf16 + libc.src.math.nextafterf16 + libc.src.math.nextdownf16 + libc.src.math.nexttowardf16 + libc.src.math.nextupf16 + libc.src.math.remainderf16 + libc.src.math.remquof16 + libc.src.math.rintf16 + libc.src.math.roundevenf16 + libc.src.math.roundf16 + libc.src.math.scalblnf16 + libc.src.math.scalbnf16 + libc.src.math.setpayloadf16 + libc.src.math.setpayloadsigf16 + libc.src.math.sinhf16 + libc.src.math.sqrtf16 + libc.src.math.tanhf16 + libc.src.math.totalorderf16 + libc.src.math.totalordermagf16 + libc.src.math.truncf16 + libc.src.math.ufromfpf16 + libc.src.math.ufromfpxf16 + ) +endif() + +set(TARGET_LLVMLIBC_ENTRYPOINTS + ${TARGET_LIBC_ENTRYPOINTS} + ${TARGET_LIBM_ENTRYPOINTS} +) diff --git a/libc/config/gpu/headers.txt b/libc/config/gpu/amdgpu/headers.txt index fa8ad7c..fa8ad7c 100644 --- a/libc/config/gpu/headers.txt +++ b/libc/config/gpu/amdgpu/headers.txt diff --git a/libc/config/gpu/nvptx/config.json b/libc/config/gpu/nvptx/config.json new file mode 100644 index 0000000..d99f48e --- /dev/null +++ b/libc/config/gpu/nvptx/config.json @@ -0,0 +1,37 @@ +{ + "errno": { + "LIBC_CONF_ERRNO_MODE": { + "value": "LIBC_ERRNO_MODE_SHARED" + } + }, + "printf": { + "LIBC_CONF_PRINTF_DISABLE_FLOAT": { + "value": true + }, + "LIBC_CONF_PRINTF_DISABLE_INDEX_MODE": { + "value": true + }, + "LIBC_CONF_PRINTF_DISABLE_WRITE_INT": { + "value": true + }, + "LIBC_CONF_PRINTF_FLOAT_TO_STR_USE_MEGA_LONG_DOUBLE_TABLE": { + "value": false + }, + "LIBC_CONF_PRINTF_DISABLE_STRERROR": { + "value": true + } + }, + "scanf": { + "LIBC_CONF_SCANF_DISABLE_FLOAT": { + "value": true + }, + "LIBC_CONF_SCANF_DISABLE_INDEX_MODE": { + "value": true + } + }, + "math": { + "LIBC_CONF_MATH_OPTIMIZATIONS": { + "value": "(LIBC_MATH_SKIP_ACCURATE_PASS | LIBC_MATH_SMALL_TABLES | LIBC_MATH_NO_ERRNO | LIBC_MATH_NO_EXCEPT)" + } + } +} diff --git a/libc/config/gpu/entrypoints.txt b/libc/config/gpu/nvptx/entrypoints.txt index b008e0e..059dc9b 100644 --- a/libc/config/gpu/entrypoints.txt +++ b/libc/config/gpu/nvptx/entrypoints.txt @@ -376,7 +376,7 @@ set(TARGET_LIBM_ENTRYPOINTS libc.src.math.frexp libc.src.math.frexpf libc.src.math.frexpl - # FIXME: Broken on NVPTX. + # FIXME: Broken. # libc.src.math.fromfp # libc.src.math.fromfpf # libc.src.math.fromfpl @@ -506,7 +506,7 @@ set(TARGET_LIBM_ENTRYPOINTS libc.src.math.trunc libc.src.math.truncf libc.src.math.truncl - # FIXME: Broken on NVPTX. + # FIXME: Broken. # libc.src.math.ufromfp # libc.src.math.ufromfpf # libc.src.math.ufromfpl diff --git a/libc/config/gpu/nvptx/headers.txt b/libc/config/gpu/nvptx/headers.txt new file mode 100644 index 0000000..fa8ad7c --- /dev/null +++ b/libc/config/gpu/nvptx/headers.txt @@ -0,0 +1,21 @@ +set(TARGET_PUBLIC_HEADERS + libc.include.assert + libc.include.ctype + libc.include.string + libc.include.strings + libc.include.signal + libc.include.float + libc.include.stdint + libc.include.inttypes + libc.include.limits + libc.include.math + libc.include.fenv + libc.include.time + libc.include.errno + libc.include.stdlib + libc.include.stdio + libc.include.wchar + libc.include.uchar + libc.include.features + libc.include.locale +) diff --git a/libc/docs/CMakeLists.txt b/libc/docs/CMakeLists.txt index be09423..5a3f827 100644 --- a/libc/docs/CMakeLists.txt +++ b/libc/docs/CMakeLists.txt @@ -1,9 +1,72 @@ - if (LLVM_ENABLE_SPHINX) include(AddSphinxTarget) if (SPHINX_FOUND) if (${SPHINX_OUTPUT_HTML}) - add_sphinx_target(html libc) + # Similar to clang, we copy our static .rst files from libc/docs/ to the + # $build_dir/libc/docs/. That way, we can have a mix of both static + # (committed) .rst files, and dynamically generated .rst files. We don't + # want the dynamically generated .rst files to pollute the source tree. + add_custom_target(copy-libc-rst-docs + COMMAND "${CMAKE_COMMAND}" -E copy_directory + "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_BINARY_DIR}") + + # For headers that are nested in directories, we need to + # `mkdir $build_dir/libc/docs/headers/$dir` since the above copy_directory + # command does not create such copies. Otherwise, the invocation of docgen + # below will fail since the output file would be placed in a directory that + # does not exist, leading to a `No such file or directory` error from the + # shell. + file(MAKE_DIRECTORY + "${CMAKE_CURRENT_BINARY_DIR}/headers/arpa/" + "${CMAKE_CURRENT_BINARY_DIR}/headers/sys/" + ) + + # Change sphinx to build from $build_dir/libc/docs/ rather than + # llvm-project/libc/docs/. + add_sphinx_target(html libc SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}") + # Depend on the copy target. + add_dependencies(docs-libc-html copy-libc-rst-docs) + + # Maintain a list of headers for which we dynamically generate html docs + # for via docgen. For more complex docs (such as per arch support, a la + # math.h), those should be omitted and exist statically in + # libc/docs/headers/. + list(APPEND docgen_list + arpa/inet + assert + ctype + errno + fenv + float + inttypes + locale + setjmp + signal + stdbit + stdio + stdlib + string + strings + sys/mman + threads + uchar + wchar + wctype + ) + + foreach(stem IN LISTS docgen_list) + # It is an error in cmake to have a target name that contains a "/", but + # docgen relies on the "/" to find headers nested under directories. + # Replace with underscore. + string(REPLACE "/" "_" stem_rst ${stem}) + + # docgen invocation. + add_custom_target(${stem_rst} + COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/../utils/docgen/docgen.py ${stem}.h > + ${CMAKE_CURRENT_BINARY_DIR}/headers/${stem}.rst) + # depend on the docgen invocation. + add_dependencies(docs-libc-html ${stem_rst}) + endforeach() endif() endif() endif() diff --git a/libc/docs/dev/header_generation.rst b/libc/docs/dev/header_generation.rst index 2c586cc..a946106 100644 --- a/libc/docs/dev/header_generation.rst +++ b/libc/docs/dev/header_generation.rst @@ -44,15 +44,15 @@ To add through the command line: .. code-block:: none - python3 libc/hdrgen/yaml_to_classes.py - libc/hdrgen/yaml/[yaml_file.yaml] --add_function "<return_type>" <function_name> "<function_arg1, function_arg2>" <standard> <guard> <attribute> + python3 libc/utils/hdrgen/yaml_to_classes.py + libc/include/[yaml_file.yaml] --add_function "<return_type>" <function_name> "<function_arg1, function_arg2>" <standard> <guard> <attribute> Example: .. code-block:: none - python3 libc/hdrgen/yaml_to_classes.py - libc/hdrgen/yaml/ctype.yaml --add_function "char" example_function + python3 libc/utils/hdrgen/yaml_to_classes.py + libc/include/ctype.yaml --add_function "char" example_function "int, void, const void" stdc example_float example_attribute Keep in mind only the return_type and arguments have quotes around them. If @@ -62,7 +62,8 @@ To add through the command line: generated header file with the new addition in the hdrgen directory to examine. -If you want to sort the functions alphabetically you can check out libc/hdrgen/yaml_functions_sorted.py. +If you want to sort the functions alphabetically you can check out +libc/utils/hdrgen/yaml_functions_sorted.py. Testing @@ -75,10 +76,10 @@ ensures the process of YAML to classes to generate headers works properly. If there are any new additions on formatting headers, make sure the test is updated with the specific addition. -Integration Test can be found in: ``libc/hdrgen/tests/test_integration.py`` +Integration Test can be found in: ``libc/utils/hdrgen/tests/test_integration.py`` File to modify if adding something to formatting: -``libc/hdrgen/tests/expected_output/test_header.h`` +``libc/utils/hdrgen/tests/expected_output/test_header.h`` Common Errors @@ -89,7 +90,7 @@ Common Errors .. code-block:: none - "/llvm-project/libc/hdrgen/yaml_to_classes.py", line 67, in yaml_to_classes function_data["return_type"] + "/llvm-project/libc/utils/hdrgen/yaml_to_classes.py", line 67, in yaml_to_classes function_data["return_type"] If you receive this error or any error pertaining to ``function_data[function_specific_component]`` while building the headers @@ -117,7 +118,7 @@ Common Errors missing. Ensure the correct style and required files are present: | ``[header_name]`` - | ``[../libc/hdrgen/yaml/[yaml_file.yaml]`` + | ``[../libc/include/[yaml_file.yaml]`` | ``[header_name.h.def]`` | ``[header_name.h]`` | ``DEPENDS`` @@ -147,13 +148,13 @@ Common Errors .. code-block:: none - File "/llvm-project/libc/hdrgen/header.py", line 60, in __str__ for + File "/llvm-project/libc/utils/hdrgen/header.py", line 60, in __str__ for function in self.functions: AttributeError: 'HeaderFile' object has no attribute 'functions' When running ``ninja libc`` in the build directory to generate headers you may receive the error above. Essentially this means that in - ``libc/hdrgen/header.py`` there is a missing attribute named functions. + ``libc/utils/hdrgen/header.py`` there is a missing attribute named functions. Make sure all function components are defined within this file and there are no missing functions to add these components. @@ -184,12 +185,12 @@ Common Errors Sometimes the integration test will fail but that still means the process is working unless the comparison between the output and expected_output is not showing. If that is the case make sure in - ``libc/hdrgen/tests/test_integration.py`` there are no missing arguments + ``libc/utils/hdrgen/tests/test_integration.py`` there are no missing arguments that run through the script. If the integration tests are failing due to mismatching of lines or small errors in spacing that is nothing to worry about. If this is happening while you are making a new change to the formatting of the headers, then ensure the expected output file - ``libc/hdrgen/tests/expected_output/test_header.h`` has the changes you + ``libc/utils/hdrgen/tests/expected_output/test_header.h`` has the changes you are applying. diff --git a/libc/docs/dev/source_tree_layout.rst b/libc/docs/dev/source_tree_layout.rst index bd9d6ca..62c0434 100644 --- a/libc/docs/dev/source_tree_layout.rst +++ b/libc/docs/dev/source_tree_layout.rst @@ -15,7 +15,6 @@ directories:: - examples - fuzzing - hdr - - hdrgen - include - lib - src @@ -88,15 +87,6 @@ The ``lib`` directory This directory contains a ``CMakeLists.txt`` file listing the targets for the public libraries ``libc.a``, ``libm.a`` etc. -The ``hdrgen`` directory ---------------------------- - -This directory contains the sources and specifications for the types, macros -and entrypoint functions. These definitions are organized in the ``yaml`` -subdirectory and match the organization of the ``*.h.def`` files. This folder -also contains the python sources for headergen, which is what generates the -headers. - The ``src`` directory --------------------- diff --git a/libc/docs/full_cross_build.rst b/libc/docs/full_cross_build.rst index 5f57169..cd1ec89 100644 --- a/libc/docs/full_cross_build.rst +++ b/libc/docs/full_cross_build.rst @@ -8,7 +8,7 @@ Full Cross Build :depth: 1 :local: -.. note:: +.. note:: Fullbuild requires running headergen, which is a python program that depends on pyyaml. The minimum versions are listed on the :ref:`header_generation` page, as well as additional information. @@ -95,8 +95,8 @@ configure step. Bootstrap cross build ===================== -In this recipe, the clang compiler and the ``libc-hdrgen`` binary, both are -built automatically before building the libc for the target. +In this recipe, the clang compiler is built automatically before building +the libc for the target. CMake configure step -------------------- @@ -151,8 +151,8 @@ built using any of the three recipes described above. Building for the GPU ==================== -To build for a GPU architecture, it should only be necessary to specify the -target triple as one of the supported GPU targets. Currently, this is either -``nvptx64-nvidia-cuda`` for NVIDIA GPUs or ``amdgcn-amd-amdhsa`` for AMD GPUs. -More detailed information is provided in the :ref:`GPU +To build for a GPU architecture, it should only be necessary to specify the +target triple as one of the supported GPU targets. Currently, this is either +``nvptx64-nvidia-cuda`` for NVIDIA GPUs or ``amdgcn-amd-amdhsa`` for AMD GPUs. +More detailed information is provided in the :ref:`GPU documentation<libc_gpu_building>`. diff --git a/libc/docs/headers/arpa/inet.rst b/libc/docs/headers/arpa/inet.rst deleted file mode 100644 index c82ca54..0000000 --- a/libc/docs/headers/arpa/inet.rst +++ /dev/null @@ -1,50 +0,0 @@ -.. include:: ../../check.rst - -=========== -arpa/inet.h -=========== - -Functions -========= - -.. list-table:: - :widths: auto - :align: center - :header-rows: 1 - - * - Function - - Implemented - - C23 Standard Section - - POSIX.1-2024 Standard Section - * - htonl - - |check| - - - - - * - htons - - |check| - - - - - * - inet_addr - - - - - - - * - inet_ntoa - - - - - - - * - inet_ntop - - - - - - - * - inet_pton - - - - - - - * - ntohl - - |check| - - - - - * - ntohs - - |check| - - - - diff --git a/libc/docs/headers/assert.rst b/libc/docs/headers/assert.rst deleted file mode 100644 index 6821707..0000000 --- a/libc/docs/headers/assert.rst +++ /dev/null @@ -1,27 +0,0 @@ -.. include:: ../check.rst - -======== -assert.h -======== - -Macros -====== - -.. list-table:: - :widths: auto - :align: center - :header-rows: 1 - - * - Macro - - Implemented - - C23 Standard Section - - POSIX Docs - * - __STDC_VERSION_ASSERT_H__ - - |check| - - 7.2.1 - - - * - assert - - - - 7.2.1 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/assert.h.html>`__ - diff --git a/libc/docs/headers/ctype.rst b/libc/docs/headers/ctype.rst deleted file mode 100644 index 9b5b157..0000000 --- a/libc/docs/headers/ctype.rst +++ /dev/null @@ -1,130 +0,0 @@ -.. include:: ../check.rst - -======= -ctype.h -======= - -Functions -========= - -.. list-table:: - :widths: auto - :align: center - :header-rows: 1 - - * - Function - - Implemented - - C23 Standard Section - - POSIX Docs - * - isalnum - - |check| - - 7.4.1.1 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/isalnum.html>`__ - * - isalnum_l - - |check| - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/isalnum_l.html>`__ - * - isalpha - - |check| - - 7.4.1.2 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/isalpha.html>`__ - * - isalpha_l - - |check| - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/isalpha_l.html>`__ - * - isblank - - |check| - - 7.4.1.3 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/isblank.html>`__ - * - isblank_l - - |check| - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/isblank_l.html>`__ - * - iscntrl - - |check| - - 7.4.1.4 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/iscntrl.html>`__ - * - iscntrl_l - - |check| - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/iscntrl_l.html>`__ - * - isdigit - - |check| - - 7.4.1.5 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/isdigit.html>`__ - * - isdigit_l - - |check| - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/isdigit_l.html>`__ - * - isgraph - - |check| - - 7.4.1.6 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/isgraph.html>`__ - * - isgraph_l - - |check| - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/isgraph_l.html>`__ - * - islower - - |check| - - 7.4.1.7 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/islower.html>`__ - * - islower_l - - |check| - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/islower_l.html>`__ - * - isprint - - |check| - - 7.4.1.8 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/isprint.html>`__ - * - isprint_l - - |check| - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/isprint_l.html>`__ - * - ispunct - - |check| - - 7.4.1.9 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/ispunct.html>`__ - * - ispunct_l - - |check| - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/ispunct_l.html>`__ - * - isspace - - |check| - - 7.4.1.10 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/isspace.html>`__ - * - isspace_l - - |check| - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/isspace_l.html>`__ - * - isupper - - |check| - - 7.4.1.11 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/isupper.html>`__ - * - isupper_l - - |check| - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/isupper_l.html>`__ - * - isxdigit - - |check| - - 7.4.1.12 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/isxdigit.html>`__ - * - isxdigit_l - - |check| - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/isxdigit_l.html>`__ - * - tolower - - |check| - - 7.4.2.1 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/tolower.html>`__ - * - tolower_l - - |check| - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/tolower_l.html>`__ - * - toupper - - |check| - - 7.4.2.2 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/toupper.html>`__ - * - toupper_l - - |check| - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/toupper_l.html>`__ diff --git a/libc/docs/headers/errno.rst b/libc/docs/headers/errno.rst deleted file mode 100644 index b2b2e62..0000000 --- a/libc/docs/headers/errno.rst +++ /dev/null @@ -1,35 +0,0 @@ -.. include:: ../check.rst - -======= -errno.h -======= - -Macros -====== - -.. list-table:: - :widths: auto - :align: center - :header-rows: 1 - - * - Macro - - Implemented - - C23 Standard Section - - POSIX Docs - * - EDOM - - - - 7.5 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/errno.h.html>`__ - * - EILSEQ - - - - 7.5 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/errno.h.html>`__ - * - ERANGE - - - - 7.5 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/errno.h.html>`__ - * - errno - - - - 7.5 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/errno.h.html>`__ - diff --git a/libc/docs/headers/fenv.rst b/libc/docs/headers/fenv.rst deleted file mode 100644 index d0e3c5d..0000000 --- a/libc/docs/headers/fenv.rst +++ /dev/null @@ -1,175 +0,0 @@ -.. include:: ../check.rst - -====== -fenv.h -====== - -Macros -====== - -.. list-table:: - :widths: auto - :align: center - :header-rows: 1 - - * - Macro - - Implemented - - C23 Standard Section - - POSIX Docs - * - FE_ALL_EXCEPT - - |check| - - 7.6.12 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/fenv.h.html>`__ - * - FE_DEC_DOWNWARD - - - - 7.6.14 - - - * - FE_DEC_TONEAREST - - - - 7.6.14 - - - * - FE_DEC_TONEARESTFROMZERO - - - - 7.6.14 - - - * - FE_DEC_TOWARDZERO - - - - 7.6.14 - - - * - FE_DEC_UPWARD - - - - 7.6.14 - - - * - FE_DFL_ENV - - |check| - - 7.6.17 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/fenv.h.html>`__ - * - FE_DFL_MODE - - - - 7.6.11 - - - * - FE_DIVBYZERO - - |check| - - 7.6.9 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/fenv.h.html>`__ - * - FE_DOWNWARD - - |check| - - 7.6.13 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/fenv.h.html>`__ - * - FE_INEXACT - - |check| - - 7.6.9 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/fenv.h.html>`__ - * - FE_INVALID - - |check| - - 7.6.9 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/fenv.h.html>`__ - * - FE_OVERFLOW - - |check| - - 7.6.9 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/fenv.h.html>`__ - * - FE_TONEAREST - - |check| - - 7.6.13 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/fenv.h.html>`__ - * - FE_TONEARESTFROMZERO - - - - 7.6.13 - - - * - FE_TOWARDZERO - - |check| - - 7.6.13 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/fenv.h.html>`__ - * - FE_UNDERFLOW - - |check| - - 7.6.9 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/fenv.h.html>`__ - * - FE_UPWARD - - |check| - - 7.6.13 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/fenv.h.html>`__ - * - __STDC_VERSION_FENV_H__ - - - - 7.6.5 - - - -Functions -========= - -.. list-table:: - :widths: auto - :align: center - :header-rows: 1 - - * - Function - - Implemented - - C23 Standard Section - - POSIX Docs - * - fe_dec_getround - - - - 7.6.5.3 - - - * - fe_dec_setround - - - - 7.6.5.6 - - - * - feclearexcept - - |check| - - 7.6.4.1 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/feclearexcept.html>`__ - * - fegetenv - - |check| - - 7.6.6.1 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/fegetenv.html>`__ - * - fegetexceptflag - - |check| - - 7.6.4.2 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/fegetexceptflag.html>`__ - * - fegetmode - - - - 7.6.5.1 - - - * - fegetround - - |check| - - 7.6.5.2 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/fegetround.html>`__ - * - feholdexcept - - |check| - - 7.6.6.2 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/feholdexcept.html>`__ - * - feraiseexcept - - |check| - - 7.6.4.3 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/feraiseexcept.html>`__ - * - fesetenv - - |check| - - 7.6.6.3 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/fesetenv.html>`__ - * - fesetexcept - - |check| - - 7.6.4.4 - - - * - fesetexceptflag - - |check| - - 7.6.4.5 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/fesetexceptflag.html>`__ - * - fesetmode - - - - 7.6.5.4 - - - * - fesetround - - |check| - - 7.6.5.5 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/fesetround.html>`__ - * - fetestexcept - - |check| - - 7.6.4.7 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/fetestexcept.html>`__ - * - fetestexceptflag - - |check| - - 7.6.4.6 - - - * - feupdateenv - - |check| - - 7.6.6.4 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/feupdateenv.html>`__ diff --git a/libc/docs/headers/float.rst b/libc/docs/headers/float.rst deleted file mode 100644 index 8ef0f3a..0000000 --- a/libc/docs/headers/float.rst +++ /dev/null @@ -1,227 +0,0 @@ -.. include:: ../check.rst - -======= -float.h -======= - -Macros -====== - -.. list-table:: - :widths: auto - :align: center - :header-rows: 1 - - * - Macro - - Implemented - - C23 Standard Section - - POSIX Docs - * - DBL_DECIMAL_DIG - - |check| - - 5.3.5.3.3 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/float.h.html>`__ - * - DBL_DIG - - |check| - - 5.3.5.3.3 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/float.h.html>`__ - * - DBL_EPSILON - - |check| - - 5.3.5.3.3 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/float.h.html>`__ - * - DBL_HAS_SUBNORM - - |check| - - 5.3.5.3.3 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/float.h.html>`__ - * - DBL_IS_IEC_60559 - - - - 5.3.5.3.3 - - - * - DBL_MANT_DIG - - |check| - - 5.3.5.3.3 - - - * - DBL_MAX - - |check| - - 5.3.5.3.3 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/float.h.html>`__ - * - DBL_MAX_10_EXP - - |check| - - 5.3.5.3.3 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/float.h.html>`__ - * - DBL_MAX_EXP - - |check| - - 5.3.5.3.3 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/float.h.html>`__ - * - DBL_MIN - - |check| - - 5.3.5.3.3 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/float.h.html>`__ - * - DBL_MIN_10_EXP - - |check| - - 5.3.5.3.3 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/float.h.html>`__ - * - DBL_MIN_EXP - - |check| - - 5.3.5.3.3 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/float.h.html>`__ - * - DBL_NORM_MAX - - - - 5.3.5.3.3 - - - * - DBL_SNAN - - - - 5.3.5.3.3 - - - * - DBL_TRUE_MIN - - |check| - - 5.3.5.3.3 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/float.h.html>`__ - * - DECIMAL_DIG - - |check| - - 5.3.5.3.3 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/float.h.html>`__ - * - FLT_DECIMAL_DIG - - |check| - - 5.3.5.3.3 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/float.h.html>`__ - * - FLT_DIG - - |check| - - 5.3.5.3.3 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/float.h.html>`__ - * - FLT_EPSILON - - |check| - - 5.3.5.3.3 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/float.h.html>`__ - * - FLT_EVAL_METHOD - - |check| - - 5.3.5.3.3 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/float.h.html>`__ - * - FLT_HAS_SUBNORM - - |check| - - 5.3.5.3.3 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/float.h.html>`__ - * - FLT_IS_IEC_60559 - - - - 5.3.5.3.3 - - - * - FLT_MANT_DIG - - |check| - - 5.3.5.3.3 - - - * - FLT_MAX - - |check| - - 5.3.5.3.3 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/float.h.html>`__ - * - FLT_MAX_10_EXP - - |check| - - 5.3.5.3.3 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/float.h.html>`__ - * - FLT_MAX_EXP - - |check| - - 5.3.5.3.3 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/float.h.html>`__ - * - FLT_MIN - - |check| - - 5.3.5.3.3 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/float.h.html>`__ - * - FLT_MIN_10_EXP - - |check| - - 5.3.5.3.3 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/float.h.html>`__ - * - FLT_MIN_EXP - - |check| - - 5.3.5.3.3 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/float.h.html>`__ - * - FLT_NORM_MAX - - - - 5.3.5.3.3 - - - * - FLT_RADIX - - |check| - - 5.3.5.3.3 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/float.h.html>`__ - * - FLT_ROUNDS - - |check| - - 5.3.5.3.3 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/float.h.html>`__ - * - FLT_SNAN - - - - 5.3.5.3.3 - - - * - FLT_TRUE_MIN - - |check| - - 5.3.5.3.3 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/float.h.html>`__ - * - INFINITY - - - - 5.3.5.3.3 - - - * - LDBL_DECIMAL_DIG - - |check| - - 5.3.5.3.3 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/float.h.html>`__ - * - LDBL_DIG - - |check| - - 5.3.5.3.3 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/float.h.html>`__ - * - LDBL_EPSILON - - |check| - - 5.3.5.3.3 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/float.h.html>`__ - * - LDBL_HAS_SUBNORM - - |check| - - 5.3.5.3.3 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/float.h.html>`__ - * - LDBL_IS_IEC_60559 - - - - 5.3.5.3.3 - - - * - LDBL_MANT_DIG - - |check| - - 5.3.5.3.3 - - - * - LDBL_MAX - - |check| - - 5.3.5.3.3 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/float.h.html>`__ - * - LDBL_MAX_10_EXP - - |check| - - 5.3.5.3.3 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/float.h.html>`__ - * - LDBL_MAX_EXP - - |check| - - 5.3.5.3.3 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/float.h.html>`__ - * - LDBL_MIN - - |check| - - 5.3.5.3.3 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/float.h.html>`__ - * - LDBL_MIN_10_EXP - - |check| - - 5.3.5.3.3 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/float.h.html>`__ - * - LDBL_MIN_EXP - - |check| - - 5.3.5.3.3 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/float.h.html>`__ - * - LDBL_NORM_MAX - - - - 5.3.5.3.3 - - - * - LDBL_SNAN - - - - 5.3.5.3.3 - - - * - LDBL_TRUE_MIN - - |check| - - 5.3.5.3.3 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/float.h.html>`__ - * - NAN - - - - 5.3.5.3.3 - - - * - __STDC_VERSION_FLOAT_H__ - - - - 7.7 - - - diff --git a/libc/docs/headers/inttypes.rst b/libc/docs/headers/inttypes.rst deleted file mode 100644 index 9269b40..0000000 --- a/libc/docs/headers/inttypes.rst +++ /dev/null @@ -1,42 +0,0 @@ -.. include:: ../check.rst - -========== -inttypes.h -========== - -Functions -========= - -.. list-table:: - :widths: auto - :align: center - :header-rows: 1 - - * - Function - - Implemented - - C23 Standard Section - - POSIX Docs - * - imaxabs - - |check| - - 7.8.2.1 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/imaxabs.html>`__ - * - imaxdiv - - |check| - - 7.8.2.2 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/imaxdiv.html>`__ - * - strtoimax - - |check| - - 7.8.2.3 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strtoimax.html>`__ - * - strtoumax - - |check| - - 7.8.2.3 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strtoumax.html>`__ - * - wcstoimax - - - - 7.8.2.4 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/wcstoimax.html>`__ - * - wcstoumax - - - - 7.8.2.4 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/wcstoumax.html>`__ diff --git a/libc/docs/headers/locale.rst b/libc/docs/headers/locale.rst deleted file mode 100644 index c97d1f6..0000000 --- a/libc/docs/headers/locale.rst +++ /dev/null @@ -1,83 +0,0 @@ -.. include:: ../check.rst - -======== -locale.h -======== - -Macros -====== - -.. list-table:: - :widths: auto - :align: center - :header-rows: 1 - - * - Macro - - Implemented - - C23 Standard Section - - POSIX Docs - * - LC_ALL - - |check| - - 7.11 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/locale.h.html>`__ - * - LC_COLLATE - - |check| - - 7.11 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/locale.h.html>`__ - * - LC_CTYPE - - |check| - - 7.11 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/locale.h.html>`__ - * - LC_MONETARY - - |check| - - 7.11 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/locale.h.html>`__ - * - LC_NUMERIC - - |check| - - 7.11 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/locale.h.html>`__ - * - LC_TIME - - |check| - - 7.11 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/locale.h.html>`__ - -Functions -========= - -.. list-table:: - :widths: auto - :align: center - :header-rows: 1 - - * - Function - - Implemented - - C23 Standard Section - - POSIX Docs - * - duplocale - - |check| - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/duplocale.html>`__ - * - freelocale - - |check| - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/freelocale.html>`__ - * - getlocalename_l - - - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/getlocalename_l.html>`__ - * - localeconv - - |check| - - 7.11.2.1 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/localeconv.html>`__ - * - newlocale - - |check| - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/newlocale.html>`__ - * - setlocale - - |check| - - 7.11.1.1 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/setlocale.html>`__ - * - uselocale - - |check| - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/uselocale.html>`__ diff --git a/libc/docs/headers/setjmp.rst b/libc/docs/headers/setjmp.rst deleted file mode 100644 index b009113..0000000 --- a/libc/docs/headers/setjmp.rst +++ /dev/null @@ -1,43 +0,0 @@ -.. include:: ../check.rst - -======== -setjmp.h -======== - -Macros -====== - -.. list-table:: - :widths: auto - :align: center - :header-rows: 1 - - * - Macro - - Implemented - - C23 Standard Section - - POSIX.1-2024 Standard Section - * - __STDC_VERSION_SETJMP_H__ - - - - 7.13.2 - - - -Functions -========= - -.. list-table:: - :widths: auto - :align: center - :header-rows: 1 - - * - Function - - Implemented - - C23 Standard Section - - POSIX.1-2024 Standard Section - * - longjmp - - |check| - - 7.13.2.1 - - - * - setjmp - - |check| - - 7.13.1.1 - - diff --git a/libc/docs/headers/signal.rst b/libc/docs/headers/signal.rst deleted file mode 100644 index 4f51f61..0000000 --- a/libc/docs/headers/signal.rst +++ /dev/null @@ -1,207 +0,0 @@ -.. include:: ../check.rst - -======== -signal.h -======== - -Macros -====== - -.. list-table:: - :widths: auto - :align: center - :header-rows: 1 - - * - Macro - - Implemented - - C23 Standard Section - - POSIX Docs - * - SIGABRT - - |check| - - 7.14.3 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/signal.h.html>`__ - * - SIGALRM - - |check| - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/signal.h.html>`__ - * - SIGBUS - - |check| - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/signal.h.html>`__ - * - SIGCHLD - - |check| - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/signal.h.html>`__ - * - SIGCONT - - |check| - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/signal.h.html>`__ - * - SIGFPE - - |check| - - 7.14.3 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/signal.h.html>`__ - * - SIGHUP - - |check| - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/signal.h.html>`__ - * - SIGILL - - |check| - - 7.14.3 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/signal.h.html>`__ - * - SIGINT - - |check| - - 7.14.3 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/signal.h.html>`__ - * - SIGKILL - - |check| - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/signal.h.html>`__ - * - SIGPIPE - - |check| - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/signal.h.html>`__ - * - SIGPOLL - - |check| - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/signal.h.html>`__ - * - SIGPROF - - |check| - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/signal.h.html>`__ - * - SIGQUIT - - |check| - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/signal.h.html>`__ - * - SIGRTMAX - - |check| - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/signal.h.html>`__ - * - SIGRTMIN - - |check| - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/signal.h.html>`__ - * - SIGSEGV - - |check| - - 7.14.3 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/signal.h.html>`__ - * - SIGSTOP - - |check| - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/signal.h.html>`__ - * - SIGSYS - - |check| - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/signal.h.html>`__ - * - SIGTERM - - |check| - - 7.14.3 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/signal.h.html>`__ - * - SIGTRAP - - |check| - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/signal.h.html>`__ - * - SIGTSTP - - |check| - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/signal.h.html>`__ - * - SIGTTIN - - |check| - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/signal.h.html>`__ - * - SIGTTOU - - |check| - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/signal.h.html>`__ - * - SIGURG - - |check| - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/signal.h.html>`__ - * - SIGUSR1 - - |check| - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/signal.h.html>`__ - * - SIGUSR2 - - |check| - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/signal.h.html>`__ - * - SIGVTALRM - - |check| - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/signal.h.html>`__ - * - SIGXCPU - - |check| - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/signal.h.html>`__ - * - SIGXFSZ - - |check| - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/signal.h.html>`__ - * - SIG_DFL - - |check| - - 7.14.3 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/signal.h.html>`__ - * - SIG_ERR - - |check| - - 7.14.3 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/signal.h.html>`__ - * - SIG_HOLD - - - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/signal.h.html>`__ - * - SIG_IGN - - |check| - - 7.14.3 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/signal.h.html>`__ - -Functions -========= - -.. list-table:: - :widths: auto - :align: center - :header-rows: 1 - - * - Function - - Implemented - - C23 Standard Section - - POSIX Docs - * - kill - - |check| - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/kill.html>`__ - * - raise - - |check| - - 7.14.2.1 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/raise.html>`__ - * - sigaction - - |check| - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/sigaction.html>`__ - * - sigaddset - - |check| - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/sigaddset.html>`__ - * - sigaltstack - - |check| - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/sigaltstack.html>`__ - * - sigdelset - - |check| - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/sigdelset.html>`__ - * - sigemptyset - - |check| - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/sigemptyset.html>`__ - * - sigfillset - - |check| - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/sigfillset.html>`__ - * - signal - - |check| - - 7.14.1.1 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/signal.html>`__ - * - sigprocmask - - |check| - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/sigprocmask.html>`__ diff --git a/libc/docs/headers/stdbit.rst b/libc/docs/headers/stdbit.rst deleted file mode 100644 index 0484d95..0000000 --- a/libc/docs/headers/stdbit.rst +++ /dev/null @@ -1,383 +0,0 @@ -.. include:: ../check.rst - -======== -stdbit.h -======== - -Macros -====== - -.. list-table:: - :widths: auto - :align: center - :header-rows: 1 - - * - Macro - - Implemented - - C23 Standard Section - - POSIX.1-2024 Standard Section - * - __STDC_ENDIAN_BIG__ - - |check| - - 7.18.2.2 - - - * - __STDC_ENDIAN_LITTLE__ - - |check| - - 7.18.2.2 - - - * - __STDC_ENDIAN_NATIVE__ - - |check| - - 7.18.2.2 - - - * - __STDC_VERSION_STDBIT_H__ - - |check| - - 7.18.1.2 - - - * - stdc_bit_ceil - - |check| - - 7.18.16.1 - - - * - stdc_bit_floor - - |check| - - 7.18.15.1 - - - * - stdc_bit_width - - |check| - - 7.18.14.1 - - - * - stdc_count_ones - - |check| - - 7.18.12.1 - - - * - stdc_count_zeros - - |check| - - 7.18.11.1 - - - * - stdc_first_leading_one - - |check| - - 7.18.8.1 - - - * - stdc_first_leading_zero - - |check| - - 7.18.7.1 - - - * - stdc_first_trailing_one - - |check| - - 7.18.10.1 - - - * - stdc_first_trailing_zero - - |check| - - 7.18.9.1 - - - * - stdc_has_single_bit - - |check| - - 7.18.13.1 - - - * - stdc_leading_ones - - |check| - - 7.18.4.1 - - - * - stdc_leading_zeros - - |check| - - 7.18.3.1 - - - * - stdc_trailing_ones - - |check| - - 7.18.6.1 - - - * - stdc_trailing_zeros - - |check| - - 7.18.5.1 - - - -Functions -========= - -.. list-table:: - :widths: auto - :align: center - :header-rows: 1 - - * - Function - - Implemented - - C23 Standard Section - - POSIX.1-2024 Standard Section - * - stdc_bit_ceil_uc - - |check| - - 7.18.16 - - - * - stdc_bit_ceil_ui - - |check| - - 7.18.16 - - - * - stdc_bit_ceil_ul - - |check| - - 7.18.16 - - - * - stdc_bit_ceil_ull - - |check| - - 7.18.16 - - - * - stdc_bit_ceil_us - - |check| - - 7.18.16 - - - * - stdc_bit_floor_uc - - |check| - - 7.18.15 - - - * - stdc_bit_floor_ui - - |check| - - 7.18.15 - - - * - stdc_bit_floor_ul - - |check| - - 7.18.15 - - - * - stdc_bit_floor_ull - - |check| - - 7.18.15 - - - * - stdc_bit_floor_us - - |check| - - 7.18.15 - - - * - stdc_bit_width_uc - - |check| - - 7.18.14 - - - * - stdc_bit_width_ui - - |check| - - 7.18.14 - - - * - stdc_bit_width_ul - - |check| - - 7.18.14 - - - * - stdc_bit_width_ull - - |check| - - 7.18.14 - - - * - stdc_bit_width_us - - |check| - - 7.18.14 - - - * - stdc_count_ones_uc - - |check| - - 7.18.12 - - - * - stdc_count_ones_ui - - |check| - - 7.18.12 - - - * - stdc_count_ones_ul - - |check| - - 7.18.12 - - - * - stdc_count_ones_ull - - |check| - - 7.18.12 - - - * - stdc_count_ones_us - - |check| - - 7.18.12 - - - * - stdc_count_zeros_uc - - |check| - - 7.18.11 - - - * - stdc_count_zeros_ui - - |check| - - 7.18.11 - - - * - stdc_count_zeros_ul - - |check| - - 7.18.11 - - - * - stdc_count_zeros_ull - - |check| - - 7.18.11 - - - * - stdc_count_zeros_us - - |check| - - 7.18.11 - - - * - stdc_first_leading_one_uc - - |check| - - 7.18.8 - - - * - stdc_first_leading_one_ui - - |check| - - 7.18.8 - - - * - stdc_first_leading_one_ul - - |check| - - 7.18.8 - - - * - stdc_first_leading_one_ull - - |check| - - 7.18.8 - - - * - stdc_first_leading_one_us - - |check| - - 7.18.8 - - - * - stdc_first_leading_zero_uc - - |check| - - 7.18.7 - - - * - stdc_first_leading_zero_ui - - |check| - - 7.18.7 - - - * - stdc_first_leading_zero_ul - - |check| - - 7.18.7 - - - * - stdc_first_leading_zero_ull - - |check| - - 7.18.7 - - - * - stdc_first_leading_zero_us - - |check| - - 7.18.7 - - - * - stdc_first_trailing_one_uc - - |check| - - 7.18.10 - - - * - stdc_first_trailing_one_ui - - |check| - - 7.18.10 - - - * - stdc_first_trailing_one_ul - - |check| - - 7.18.10 - - - * - stdc_first_trailing_one_ull - - |check| - - 7.18.10 - - - * - stdc_first_trailing_one_us - - |check| - - 7.18.10 - - - * - stdc_first_trailing_zero_uc - - |check| - - 7.18.9 - - - * - stdc_first_trailing_zero_ui - - |check| - - 7.18.9 - - - * - stdc_first_trailing_zero_ul - - |check| - - 7.18.9 - - - * - stdc_first_trailing_zero_ull - - |check| - - 7.18.9 - - - * - stdc_first_trailing_zero_us - - |check| - - 7.18.9 - - - * - stdc_has_single_bit_uc - - |check| - - 7.18.13 - - - * - stdc_has_single_bit_ui - - |check| - - 7.18.13 - - - * - stdc_has_single_bit_ul - - |check| - - 7.18.13 - - - * - stdc_has_single_bit_ull - - |check| - - 7.18.13 - - - * - stdc_has_single_bit_us - - |check| - - 7.18.13 - - - * - stdc_leading_ones_uc - - |check| - - 7.18.4 - - - * - stdc_leading_ones_ui - - |check| - - 7.18.4 - - - * - stdc_leading_ones_ul - - |check| - - 7.18.4 - - - * - stdc_leading_ones_ull - - |check| - - 7.18.4 - - - * - stdc_leading_ones_us - - |check| - - 7.18.4 - - - * - stdc_leading_zeros_uc - - |check| - - 7.18.3 - - - * - stdc_leading_zeros_ui - - |check| - - 7.18.3 - - - * - stdc_leading_zeros_ul - - |check| - - 7.18.3 - - - * - stdc_leading_zeros_ull - - |check| - - 7.18.3 - - - * - stdc_leading_zeros_us - - |check| - - 7.18.3 - - - * - stdc_trailing_ones_uc - - |check| - - 7.18.6 - - - * - stdc_trailing_ones_ui - - |check| - - 7.18.6 - - - * - stdc_trailing_ones_ul - - |check| - - 7.18.6 - - - * - stdc_trailing_ones_ull - - |check| - - 7.18.6 - - - * - stdc_trailing_ones_us - - |check| - - 7.18.6 - - - * - stdc_trailing_zeros_uc - - |check| - - 7.18.5 - - - * - stdc_trailing_zeros_ui - - |check| - - 7.18.5 - - - * - stdc_trailing_zeros_ul - - |check| - - 7.18.5 - - - * - stdc_trailing_zeros_ull - - |check| - - 7.18.5 - - - * - stdc_trailing_zeros_us - - |check| - - 7.18.5 - - diff --git a/libc/docs/headers/stdio.rst b/libc/docs/headers/stdio.rst deleted file mode 100644 index 1833eb5..0000000 --- a/libc/docs/headers/stdio.rst +++ /dev/null @@ -1,359 +0,0 @@ -.. include:: ../check.rst - -======= -stdio.h -======= - -Macros -====== - -.. list-table:: - :widths: auto - :align: center - :header-rows: 1 - - * - Macro - - Implemented - - C23 Standard Section - - POSIX Docs - * - BUFSIZ - - |check| - - 7.23.1 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/stdio.h.html>`__ - * - EOF - - |check| - - 7.23.1 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/stdio.h.html>`__ - * - FILENAME_MAX - - - - 7.23.1 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/stdio.h.html>`__ - * - FOPEN_MAX - - - - 7.23.1 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/stdio.h.html>`__ - * - L_ctermid - - - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/stdio.h.html>`__ - * - L_tmpnam - - - - 7.23.1 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/stdio.h.html>`__ - * - SEEK_CUR - - |check| - - 7.23.1 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/stdio.h.html>`__ - * - SEEK_END - - |check| - - 7.23.1 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/stdio.h.html>`__ - * - SEEK_SET - - |check| - - 7.23.1 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/stdio.h.html>`__ - * - TMP_MAX - - - - 7.23.1 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/stdio.h.html>`__ - * - _IOFBF - - |check| - - 7.23.1 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/stdio.h.html>`__ - * - _IOLBF - - |check| - - 7.23.1 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/stdio.h.html>`__ - * - _IONBF - - |check| - - 7.23.1 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/stdio.h.html>`__ - * - _PRINTF_NAN_LEN_MAX - - - - 7.23.1 - - - * - __STDC_VERSION_STDIO_H__ - - - - 7.23.1 - - - * - stderr - - |check| - - 7.23.1 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/stdio.h.html>`__ - * - stdin - - |check| - - 7.23.1 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/stdio.h.html>`__ - * - stdout - - |check| - - 7.23.1 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/stdio.h.html>`__ - -Functions -========= - -.. list-table:: - :widths: auto - :align: center - :header-rows: 1 - - * - Function - - Implemented - - C23 Standard Section - - POSIX Docs - * - clearerr - - |check| - - 7.23.10.1 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/clearerr.html>`__ - * - ctermid - - - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/ctermid.html>`__ - * - dprintf - - - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/dprintf.html>`__ - * - fclose - - |check| - - 7.23.5.1 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/fclose.html>`__ - * - fdopen - - |check| - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/fdopen.html>`__ - * - feof - - |check| - - 7.23.10.2 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/feof.html>`__ - * - ferror - - |check| - - 7.23.10.3 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/ferror.html>`__ - * - fflush - - |check| - - 7.23.5.2 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/fflush.html>`__ - * - fgetc - - |check| - - 7.23.7.1 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/fgetc.html>`__ - * - fgetpos - - - - 7.23.9.1 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/fgetpos.html>`__ - * - fgets - - |check| - - 7.23.7.2 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/fgets.html>`__ - * - fileno - - |check| - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/fileno.html>`__ - * - flockfile - - |check| - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/flockfile.html>`__ - * - fmemopen - - - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/fmemopen.html>`__ - * - fopen - - |check| - - 7.23.5.3 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/fopen.html>`__ - * - fprintf - - |check| - - 7.23.6.1 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/fprintf.html>`__ - * - fputc - - |check| - - 7.23.7.3 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/fputc.html>`__ - * - fputs - - |check| - - 7.23.7.4 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/fputs.html>`__ - * - fread - - |check| - - 7.23.8.1 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/fread.html>`__ - * - freopen - - - - 7.23.5.4 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/freopen.html>`__ - * - fscanf - - |check| - - 7.23.6.2 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/fscanf.html>`__ - * - fseek - - |check| - - 7.23.9.2 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/fseek.html>`__ - * - fseeko - - |check| - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/fseeko.html>`__ - * - fsetpos - - - - 7.23.9.3 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/fsetpos.html>`__ - * - ftell - - |check| - - 7.23.9.4 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/ftell.html>`__ - * - ftello - - |check| - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/ftello.html>`__ - * - ftrylockfile - - - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/ftrylockfile.html>`__ - * - funlockfile - - |check| - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/funlockfile.html>`__ - * - fwrite - - |check| - - 7.23.8.2 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/fwrite.html>`__ - * - getc - - |check| - - 7.23.7.5 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/getc.html>`__ - * - getchar - - |check| - - 7.23.7.6 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/getchar.html>`__ - * - getdelim - - - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/getdelim.html>`__ - * - getline - - - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/getline.html>`__ - * - open_memstream - - - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/open_memstream.html>`__ - * - pclose - - - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pclose.html>`__ - * - perror - - - - 7.23.10.4 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/perror.html>`__ - * - popen - - - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/popen.html>`__ - * - printf - - |check| - - 7.23.6.3 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/printf.html>`__ - * - putc - - |check| - - 7.23.7.7 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/putc.html>`__ - * - putc_unlocked - - - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/putc_unlocked.html>`__ - * - putchar - - |check| - - 7.23.7.8 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/putchar.html>`__ - * - putchar_unlocked - - - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/putchar_unlocked.html>`__ - * - puts - - |check| - - 7.23.7.9 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/puts.html>`__ - * - remove - - |check| - - 7.23.4.1 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/remove.html>`__ - * - rename - - |check| - - 7.23.4.2 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/rename.html>`__ - * - renameat - - - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/renameat.html>`__ - * - rewind - - - - 7.23.9.5 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/rewind.html>`__ - * - scanf - - |check| - - 7.23.6.4 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/scanf.html>`__ - * - setbuf - - |check| - - 7.23.5.5 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/setbuf.html>`__ - * - setvbuf - - |check| - - 7.23.5.6 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/setvbuf.html>`__ - * - snprintf - - |check| - - 7.23.6.5 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/snprintf.html>`__ - * - sprintf - - |check| - - 7.23.6.6 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/sprintf.html>`__ - * - sscanf - - |check| - - 7.23.6.7 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/sscanf.html>`__ - * - tmpfile - - - - 7.23.4.3 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/tmpfile.html>`__ - * - tmpnam - - - - 7.23.4.4 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/tmpnam.html>`__ - * - ungetc - - |check| - - 7.23.7.10 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/ungetc.html>`__ - * - vdprintf - - - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/vdprintf.html>`__ - * - vfprintf - - |check| - - 7.23.6.8 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/vfprintf.html>`__ - * - vfscanf - - |check| - - 7.23.6.9 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/vfscanf.html>`__ - * - vprintf - - |check| - - 7.23.6.10 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/vprintf.html>`__ - * - vscanf - - |check| - - 7.23.6.11 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/vscanf.html>`__ - * - vsnprintf - - |check| - - 7.23.6.12 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/vsnprintf.html>`__ - * - vsprintf - - |check| - - 7.23.6.13 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/vsprintf.html>`__ - * - vsscanf - - |check| - - 7.23.6.14 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/vsscanf.html>`__ diff --git a/libc/docs/headers/stdlib.rst b/libc/docs/headers/stdlib.rst deleted file mode 100644 index 4151f29..0000000 --- a/libc/docs/headers/stdlib.rst +++ /dev/null @@ -1,255 +0,0 @@ -.. include:: ../check.rst - -======== -stdlib.h -======== - -Macros -====== - -.. list-table:: - :widths: auto - :align: center - :header-rows: 1 - - * - Macro - - Implemented - - C23 Standard Section - - POSIX Docs - * - EXIT_FAILURE - - |check| - - 7.24 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/stdlib.h.html>`__ - * - EXIT_SUCCESS - - |check| - - 7.24 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/stdlib.h.html>`__ - * - MB_CUR_MAX - - |check| - - 7.24 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/stdlib.h.html>`__ - * - RAND_MAX - - |check| - - 7.24 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/stdlib.h.html>`__ - * - __STDC_VERSION_STDLIB_H__ - - - - 7.24 - - - -Functions -========= - -.. list-table:: - :widths: auto - :align: center - :header-rows: 1 - - * - Function - - Implemented - - C23 Standard Section - - POSIX Docs - * - _Exit - - |check| - - 7.24.4.5 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/_Exit.html>`__ - * - abort - - |check| - - 7.24.4.1 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/abort.html>`__ - * - abs - - |check| - - 7.24.6.1 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/abs.html>`__ - * - aligned_alloc - - |check| - - 7.24.3.1 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/aligned_alloc.html>`__ - * - at_quick_exit - - |check| - - 7.24.4.3 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/at_quick_exit.html>`__ - * - atexit - - |check| - - 7.24.4.2 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/atexit.html>`__ - * - atof - - |check| - - 7.24.1.1 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/atof.html>`__ - * - atoi - - |check| - - 7.24.1.2 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/atoi.html>`__ - * - atol - - |check| - - 7.24.1.2 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/atol.html>`__ - * - atoll - - |check| - - 7.24.1.2 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/atoll.html>`__ - * - bsearch - - |check| - - 7.24.5.1 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/bsearch.html>`__ - * - calloc - - |check| - - 7.24.3.2 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/calloc.html>`__ - * - div - - |check| - - 7.24.6.2 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/div.html>`__ - * - exit - - |check| - - 7.24.4.4 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/exit.html>`__ - * - free - - |check| - - 7.24.3.3 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/free.html>`__ - * - free_aligned_sized - - - - 7.24.3.5 - - - * - free_sized - - - - 7.24.3.4 - - - * - getenv - - |check| - - 7.24.4.6 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/getenv.html>`__ - * - labs - - |check| - - 7.24.6.1 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/labs.html>`__ - * - ldiv - - |check| - - 7.24.6.2 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/ldiv.html>`__ - * - llabs - - |check| - - 7.24.6.1 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/llabs.html>`__ - * - lldiv - - |check| - - 7.24.6.2 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/lldiv.html>`__ - * - malloc - - |check| - - 7.24.3.6 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/malloc.html>`__ - * - mblen - - - - 7.24.7.1 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/mblen.html>`__ - * - mbstowcs - - - - 7.24.8.1 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/mbstowcs.html>`__ - * - mbtowc - - - - 7.24.7.2 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/mbtowc.html>`__ - * - memalignment - - - - 7.24.9.1 - - - * - qsort - - |check| - - 7.24.5.2 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/qsort.html>`__ - * - quick_exit - - |check| - - 7.24.4.7 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/quick_exit.html>`__ - * - rand - - |check| - - 7.24.2.1 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/rand.html>`__ - * - realloc - - |check| - - 7.24.3.7 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/realloc.html>`__ - * - srand - - |check| - - 7.24.2.2 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/srand.html>`__ - * - strfromd - - |check| - - 7.24.1.3 - - - * - strfromd128 - - - - 7.24.1.4 - - - * - strfromd32 - - - - 7.24.1.4 - - - * - strfromd64 - - - - 7.24.1.4 - - - * - strfromf - - |check| - - 7.24.1.3 - - - * - strfroml - - |check| - - 7.24.1.3 - - - * - strtod - - |check| - - 7.24.1.5 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strtod.html>`__ - * - strtod128 - - - - 7.24.1.6 - - - * - strtod32 - - - - 7.24.1.6 - - - * - strtod64 - - - - 7.24.1.6 - - - * - strtof - - |check| - - 7.24.1.5 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strtof.html>`__ - * - strtol - - |check| - - 7.24.1.7 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strtol.html>`__ - * - strtold - - |check| - - 7.24.1.5 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strtold.html>`__ - * - strtoll - - |check| - - 7.24.1.7 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strtoll.html>`__ - * - strtoul - - |check| - - 7.24.1.7 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strtoul.html>`__ - * - strtoull - - |check| - - 7.24.1.7 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strtoull.html>`__ - * - system - - |check| - - 7.24.4.8 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/system.html>`__ - * - wcstombs - - - - 7.24.8.2 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/wcstombs.html>`__ - * - wctomb - - - - 7.24.7.3 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/wctomb.html>`__ diff --git a/libc/docs/headers/string.rst b/libc/docs/headers/string.rst deleted file mode 100644 index 2665ed8..0000000 --- a/libc/docs/headers/string.rst +++ /dev/null @@ -1,163 +0,0 @@ -.. include:: ../check.rst - -======== -string.h -======== - -Macros -====== - -.. list-table:: - :widths: auto - :align: center - :header-rows: 1 - - * - Macro - - Implemented - - C23 Standard Section - - POSIX Docs - * - __STDC_VERSION_STRING_H__ - - - - 7.26.1 - - - -Functions -========= - -.. list-table:: - :widths: auto - :align: center - :header-rows: 1 - - * - Function - - Implemented - - C23 Standard Section - - POSIX Docs - * - memccpy - - |check| - - 7.26.2.2 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/memccpy.html>`__ - * - memchr - - |check| - - 7.26.5.2 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/memchr.html>`__ - * - memcmp - - |check| - - 7.26.4.1 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/memcmp.html>`__ - * - memcpy - - |check| - - 7.26.2.1 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/memcpy.html>`__ - * - memmove - - |check| - - 7.26.2.3 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/memmove.html>`__ - * - mempcpy - - |check| - - TODO: glibc extension - - - * - memset - - |check| - - 7.26.6.1 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/memset.html>`__ - * - memset_explicit - - |check| - - 7.26.6.2 - - - * - stpcpy - - |check| - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/stpcpy.html>`__ - * - stpncpy - - |check| - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/stpncpy.html>`__ - * - strcat - - |check| - - 7.26.3.1 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strcat.html>`__ - * - strchr - - |check| - - 7.26.5.3 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strchr.html>`__ - * - strcmp - - |check| - - 7.26.4.2 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strcmp.html>`__ - * - strcoll - - |check| - - 7.26.4.3 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strcoll.html>`__ - * - strcoll_l - - |check| - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strcoll_l.html>`__ - * - strcpy - - |check| - - 7.26.2.4 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strcpy.html>`__ - * - strcspn - - |check| - - 7.26.5.4 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strcspn.html>`__ - * - strdup - - |check| - - 7.26.2.6 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strdup.html>`__ - * - strerror - - |check| - - 7.26.6.3 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strerror.html>`__ - * - strlen - - |check| - - 7.26.6.4 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strlen.html>`__ - * - strncat - - |check| - - 7.26.3.2 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strncat.html>`__ - * - strncmp - - |check| - - 7.26.4.4 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strncmp.html>`__ - * - strncpy - - |check| - - 7.26.2.5 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strncpy.html>`__ - * - strndup - - |check| - - 7.26.2.7 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strndup.html>`__ - * - strpbrk - - |check| - - 7.26.5.5 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strpbrk.html>`__ - * - strrchr - - |check| - - 7.26.5.6 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strrchr.html>`__ - * - strspn - - |check| - - 7.26.5.7 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strspn.html>`__ - * - strstr - - |check| - - 7.26.5.8 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strstr.html>`__ - * - strtok - - |check| - - 7.26.5.9 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strtok.html>`__ - * - strtok_r - - |check| - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strtok_r.html>`__ - * - strxfrm - - |check| - - 7.26.4.5 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strxfrm.html>`__ - * - strxfrm_l - - |check| - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strxfrm_l.html>`__ diff --git a/libc/docs/headers/strings.rst b/libc/docs/headers/strings.rst deleted file mode 100644 index effd667..0000000 --- a/libc/docs/headers/strings.rst +++ /dev/null @@ -1,66 +0,0 @@ -.. include:: ../check.rst - -========= -strings.h -========= - -Functions -========= - -.. list-table:: - :widths: auto - :align: center - :header-rows: 1 - - * - Function - - Implemented - - C23 Standard Section - - POSIX Docs - * - bcmp - - |check| - - - - `removed in POSIX.1-2008 <https://pubs.opengroup.org/onlinepubs/007904875/functions/bcmp.html>`__ - * - bcopy - - |check| - - - - `removed in POSIX.1-2008 <https://pubs.opengroup.org/onlinepubs/007904875/functions/bcopy.html>`__ - * - bzero - - |check| - - - - `removed in POSIX.1-2008 <https://pubs.opengroup.org/onlinepubs/007904875/functions/bzero.html>`__ - * - ffs - - - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/ffs.html>`__ - * - ffsl - - - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/ffsl.html>`__ - * - ffsll - - - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/ffsll.html>`__ - * - index - - |check| - - - - `removed in POSIX.1-2008 <https://pubs.opengroup.org/onlinepubs/007904875/functions/index.html>`__ - * - rindex - - |check| - - - - `removed in POSIX.1-2008 <https://pubs.opengroup.org/onlinepubs/007904875/functions/rindex.html>`__ - * - strcasecmp - - |check| - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strcasecmp.html>`__ - * - strcasecmp_l - - - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strcasecmp_l.html>`__ - * - strncasecmp - - |check| - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strncasecmp.html>`__ - * - strncasecmp_l - - - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strncasecmp_l.html>`__ diff --git a/libc/docs/headers/sys/mman.rst b/libc/docs/headers/sys/mman.rst deleted file mode 100644 index e340420..0000000 --- a/libc/docs/headers/sys/mman.rst +++ /dev/null @@ -1,179 +0,0 @@ -.. include:: ../../check.rst - -========== -sys/mman.h -========== - -Macros -====== - -.. list-table:: - :widths: auto - :align: center - :header-rows: 1 - - * - Macro - - Implemented - - C23 Standard Section - - POSIX.1-2024 Standard Section - * - MAP_ANON - - - - - - - * - MAP_ANONYMOUS - - - - - - - * - MAP_FAILED - - |check| - - - - - * - MAP_FIXED - - - - - - - * - MAP_PRIVATE - - - - - - - * - MAP_SHARED - - - - - - - * - MCL_CURRENT - - - - - - - * - MCL_FUTURE - - - - - - - * - MS_ASYNC - - - - - - - * - MS_INVALIDATE - - - - - - - * - MS_SYNC - - - - - - - * - POSIX_MADV_DONTNEED - - |check| - - - - - * - POSIX_MADV_NORMAL - - |check| - - - - - * - POSIX_MADV_RANDOM - - |check| - - - - - * - POSIX_MADV_SEQUENTIAL - - |check| - - - - - * - POSIX_MADV_WILLNEED - - |check| - - - - - * - POSIX_TYPED_MEM_ALLOCATE - - - - - - - * - POSIX_TYPED_MEM_ALLOCATE_CONTIG - - - - - - - * - POSIX_TYPED_MEM_MAP_ALLOCATABLE - - - - - - - * - PROT_EXEC - - - - - - - * - PROT_NONE - - - - - - - * - PROT_READ - - - - - - - * - PROT_WRITE - - - - - - - -Functions -========= - -.. list-table:: - :widths: auto - :align: center - :header-rows: 1 - - * - Function - - Implemented - - C23 Standard Section - - POSIX.1-2024 Standard Section - * - mlock - - |check| - - - - - * - mlockall - - |check| - - - - - * - mmap - - |check| - - - - - * - mprotect - - |check| - - - - - * - msync - - |check| - - - - - * - munlock - - |check| - - - - - * - munlockall - - |check| - - - - - * - munmap - - |check| - - - - - * - posix_madvise - - |check| - - - - - * - posix_mem_offset - - - - - - - * - posix_typed_mem_get_info - - - - - - - * - posix_typed_mem_open - - - - - - - * - shm_open - - |check| - - - - - * - shm_unlink - - |check| - - - - diff --git a/libc/docs/headers/threads.rst b/libc/docs/headers/threads.rst deleted file mode 100644 index c2837b8..0000000 --- a/libc/docs/headers/threads.rst +++ /dev/null @@ -1,147 +0,0 @@ -.. include:: ../check.rst - -========= -threads.h -========= - -Macros -====== - -.. list-table:: - :widths: auto - :align: center - :header-rows: 1 - - * - Macro - - Implemented - - C23 Standard Section - - POSIX Docs - * - ONCE_FLAG_INIT - - - - 7.28.1 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/threads.h.html>`__ - * - TSS_DTOR_ITERATIONS - - - - 7.28.1 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/threads.h.html>`__ - * - __STDC_NO_THREADS__ - - - - 7.28.1 - - - * - thread_local - - - - - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/threads.h.html>`__ - -Functions -========= - -.. list-table:: - :widths: auto - :align: center - :header-rows: 1 - - * - Function - - Implemented - - C23 Standard Section - - POSIX Docs - * - call_once - - |check| - - 7.28.2.1 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/call_once.html>`__ - * - cnd_broadcast - - |check| - - 7.28.3.1 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/cnd_broadcast.html>`__ - * - cnd_destroy - - |check| - - 7.28.3.2 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/cnd_destroy.html>`__ - * - cnd_init - - |check| - - 7.28.3.3 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/cnd_init.html>`__ - * - cnd_signal - - |check| - - 7.28.3.4 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/cnd_signal.html>`__ - * - cnd_timedwait - - - - 7.28.3.5 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/cnd_timedwait.html>`__ - * - cnd_wait - - |check| - - 7.28.3.6 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/cnd_wait.html>`__ - * - mtx_destroy - - |check| - - 7.28.4.2 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/mtx_destroy.html>`__ - * - mtx_init - - |check| - - 7.28.4.3 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/mtx_init.html>`__ - * - mtx_lock - - |check| - - 7.28.4.4 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/mtx_lock.html>`__ - * - mtx_timedlock - - - - 7.28.4.5 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/mtx_timedlock.html>`__ - * - mtx_trylock - - - - 7.28.4.6 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/mtx_trylock.html>`__ - * - mtx_unlock - - |check| - - 7.28.4.7 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/mtx_unlock.html>`__ - * - thrd_create - - |check| - - 7.28.5.1 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/thrd_create.html>`__ - * - thrd_current - - |check| - - 7.28.5.2 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/thrd_current.html>`__ - * - thrd_detach - - |check| - - 7.28.5.3 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/thrd_detach.html>`__ - * - thrd_equal - - |check| - - 7.28.5.4 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/thrd_equal.html>`__ - * - thrd_exit - - |check| - - 7.28.5.5 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/thrd_exit.html>`__ - * - thrd_join - - |check| - - 7.28.5.6 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/thrd_join.html>`__ - * - thrd_sleep - - - - 7.28.5.7 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/thrd_sleep.html>`__ - * - thrd_yield - - - - 7.28.5.8 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/thrd_yield.html>`__ - * - tss_create - - |check| - - 7.28.6.1 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/tss_create.html>`__ - * - tss_delete - - |check| - - 7.28.6.2 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/tss_delete.html>`__ - * - tss_get - - |check| - - 7.28.6.3 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/tss_get.html>`__ - * - tss_set - - |check| - - 7.28.6.4 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/tss_set.html>`__ diff --git a/libc/docs/headers/uchar.rst b/libc/docs/headers/uchar.rst deleted file mode 100644 index abb684b..0000000 --- a/libc/docs/headers/uchar.rst +++ /dev/null @@ -1,59 +0,0 @@ -.. include:: ../check.rst - -======= -uchar.h -======= - -Macros -====== - -.. list-table:: - :widths: auto - :align: center - :header-rows: 1 - - * - Macro - - Implemented - - C23 Standard Section - - POSIX Docs - * - __STDC_VERSION_UCHAR_H__ - - - - 7.30.1 - - - -Functions -========= - -.. list-table:: - :widths: auto - :align: center - :header-rows: 1 - - * - Function - - Implemented - - C23 Standard Section - - POSIX Docs - * - c16rtomb - - - - 7.30.2.5 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/c16rtomb.html>`__ - * - c32rtomb - - - - 7.30.2.7 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/c32rtomb.html>`__ - * - c8rtomb - - - - 7.30.2.3 - - - * - mbrtoc16 - - - - 7.30.2.4 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/mbrtoc16.html>`__ - * - mbrtoc32 - - - - 7.30.2.6 - - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/mbrtoc32.html>`__ - * - mbrtoc8 - - - - 7.30.2.2 - - diff --git a/libc/docs/headers/wchar.rst b/libc/docs/headers/wchar.rst deleted file mode 100644 index 89a1e7b..0000000 --- a/libc/docs/headers/wchar.rst +++ /dev/null @@ -1,287 +0,0 @@ -.. include:: ../check.rst - -======= -wchar.h -======= - -Macros -====== - -.. list-table:: - :widths: auto - :align: center - :header-rows: 1 - - * - Macro - - Implemented - - C23 Standard Section - - POSIX Docs - * - WEOF - - |check| - - 7.31.1 - - - * - __STDC_VERSION_WCHAR_H__ - - - - 7.31.1 - - - -Functions -========= - -.. list-table:: - :widths: auto - :align: center - :header-rows: 1 - - * - Function - - Implemented - - C23 Standard Section - - POSIX Docs - * - btowc - - |check| - - 7.31.6.2.1 - - - * - fgetwc - - - - 7.31.3.1 - - - * - fgetws - - - - 7.31.3.2 - - - * - fputwc - - - - 7.31.3.3 - - - * - fputws - - - - 7.31.3.4 - - - * - fwide - - - - 7.31.3.5 - - - * - fwprintf - - - - 7.31.2.2 - - - * - fwscanf - - - - 7.31.2.3 - - - * - getwc - - - - 7.31.3.6 - - - * - getwchar - - - - 7.31.3.7 - - - * - mbrlen - - - - 7.31.6.4.2 - - - * - mbrtowc - - - - 7.31.6.4.3 - - - * - mbsinit - - - - 7.31.6.3.1 - - - * - mbsrtowcs - - - - 7.31.6.5.2 - - - * - putwc - - - - 7.31.3.8 - - - * - putwchar - - - - 7.31.3.9 - - - * - swprintf - - - - 7.31.2.4 - - - * - swscanf - - - - 7.31.2.5 - - - * - ungetwc - - - - 7.31.3.10 - - - * - vfwprintf - - - - 7.31.2.6 - - - * - vfwscanf - - - - 7.31.2.7 - - - * - vswprintf - - - - 7.31.2.8 - - - * - vswscanf - - - - 7.31.2.9 - - - * - vwprintf - - - - 7.31.2.10 - - - * - vwscanf - - - - 7.31.2.11 - - - * - wcrtomb - - - - 7.31.6.4.4 - - - * - wcscat - - - - 7.31.4.4.1 - - - * - wcschr - - - - 7.31.4.6.2 - - - * - wcscmp - - - - 7.31.4.5.2 - - - * - wcscoll - - - - 7.31.4.5.3 - - - * - wcscpy - - - - 7.31.4.3.1 - - - * - wcscspn - - - - 7.31.4.6.3 - - - * - wcsftime - - - - 7.31.5.1 - - - * - wcslen - - - - 7.31.4.7.1 - - - * - wcsncat - - - - 7.31.4.4.2 - - - * - wcsncmp - - - - 7.31.4.5.4 - - - * - wcsncpy - - - - 7.31.4.3.2 - - - * - wcspbrk - - - - 7.31.4.6.4 - - - * - wcsrchr - - - - 7.31.4.6.5 - - - * - wcsrtombs - - - - 7.31.6.5.3 - - - * - wcsspn - - - - 7.31.4.6.6 - - - * - wcsstr - - - - 7.31.4.6.7 - - - * - wcstod - - - - 7.31.4.2.2 - - - * - wcstod128 - - - - 7.31.4.2.3 - - - * - wcstod32 - - - - 7.31.4.2.3 - - - * - wcstod64 - - - - 7.31.4.2.3 - - - * - wcstof - - - - 7.31.4.2.2 - - - * - wcstok - - - - 7.31.4.6.8 - - - * - wcstol - - - - 7.31.4.2.4 - - - * - wcstold - - - - 7.31.4.2.2 - - - * - wcstoll - - - - 7.31.4.2.4 - - - * - wcstoul - - - - 7.31.4.2.4 - - - * - wcstoull - - - - 7.31.4.2.4 - - - * - wcsxfrm - - - - 7.31.4.5.5 - - - * - wctob - - |check| - - 7.31.6.2.2 - - - * - wmemchr - - - - 7.31.4.6.9 - - - * - wmemcmp - - - - 7.31.4.5.6 - - - * - wmemcpy - - - - 7.31.4.3.3 - - - * - wmemmove - - - - 7.31.4.3.4 - - - * - wmemset - - - - 7.31.4.7.2 - - - * - wprintf - - - - 7.31.2.12 - - - * - wscanf - - - - 7.31.2.13 - - diff --git a/libc/docs/headers/wctype.rst b/libc/docs/headers/wctype.rst deleted file mode 100644 index 076db04..0000000 --- a/libc/docs/headers/wctype.rst +++ /dev/null @@ -1,86 +0,0 @@ -.. include:: ../check.rst - -======== -wctype.h -======== - -Functions -========= - -.. list-table:: - :widths: auto - :align: center - :header-rows: 1 - - * - Function - - Implemented - - C23 Standard Section - - POSIX Docs - * - iswalnum - - - - 7.32.2.1.1 - - - * - iswalpha - - - - 7.32.2.1.2 - - - * - iswblank - - - - 7.32.2.1.4 - - - * - iswctype - - - - 7.32.2.2.1 - - - * - iswdigit - - - - 7.32.2.1.5 - - - * - iswgraph - - - - 7.32.2.1.6 - - - * - iswlower - - - - 7.32.2.1.7 - - - * - iswprint - - - - 7.32.2.1.8 - - - * - iswpunct - - - - 7.32.2.1.9 - - - * - iswspace - - - - 7.32.2.1.10 - - - * - iswupper - - - - 7.32.2.1.11 - - - * - iswxdigit - - - - 7.32.2.1.12 - - - * - towctrans - - - - 7.32.3.2.1 - - - * - towlower - - - - 7.32.3.1.1 - - - * - towupper - - - - 7.32.3.1.2 - - - * - wctrans - - - - 7.32.3.2.2 - - - * - wctype - - - - 7.32.2.2.2 - - diff --git a/libc/fuzzing/stdlib/CMakeLists.txt b/libc/fuzzing/stdlib/CMakeLists.txt index 9b3298c..3dbd640 100644 --- a/libc/fuzzing/stdlib/CMakeLists.txt +++ b/libc/fuzzing/stdlib/CMakeLists.txt @@ -1,9 +1,9 @@ add_libc_fuzzer( - qsort_fuzz + quick_sort_fuzz SRCS - qsort_fuzz.cpp + quick_sort_fuzz.cpp DEPENDS - libc.src.stdlib.qsort + libc.src.stdlib.qsort_util ) add_libc_fuzzer( diff --git a/libc/fuzzing/stdlib/heap_sort_fuzz.cpp b/libc/fuzzing/stdlib/heap_sort_fuzz.cpp index 876c5f9..6b00306 100644 --- a/libc/fuzzing/stdlib/heap_sort_fuzz.cpp +++ b/libc/fuzzing/stdlib/heap_sort_fuzz.cpp @@ -10,21 +10,10 @@ /// //===----------------------------------------------------------------------===// -#include "src/stdlib/heap_sort.h" +#include "src/stdlib/qsort_util.h" #include <stdint.h> -static int int_compare(const void *l, const void *r) { - int li = *reinterpret_cast<const int *>(l); - int ri = *reinterpret_cast<const int *>(r); - if (li == ri) - return 0; - if (li > ri) - return 1; - return -1; -} - extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { - const size_t array_size = size / sizeof(int); if (array_size == 0) return 0; @@ -34,14 +23,22 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { for (size_t i = 0; i < array_size; ++i) array[i] = data_as_int[i]; - auto arr = LIBC_NAMESPACE::internal::Array( - reinterpret_cast<uint8_t *>(array), array_size, sizeof(int), int_compare); + const auto is_less = [](const void *a_ptr, + const void *b_ptr) noexcept -> bool { + const int &a = *static_cast<const int *>(a_ptr); + const int &b = *static_cast<const int *>(b_ptr); + + return a < b; + }; - LIBC_NAMESPACE::internal::heap_sort(arr); + constexpr bool USE_QUICKSORT = false; + LIBC_NAMESPACE::internal::unstable_sort_impl<USE_QUICKSORT>( + array, array_size, sizeof(int), is_less); - for (size_t i = 0; i < array_size - 1; ++i) + for (size_t i = 0; i < array_size - 1; ++i) { if (array[i] > array[i + 1]) __builtin_trap(); + } delete[] array; return 0; diff --git a/libc/fuzzing/stdlib/qsort_fuzz.cpp b/libc/fuzzing/stdlib/quick_sort_fuzz.cpp index 5d5053c..6371e85 100644 --- a/libc/fuzzing/stdlib/qsort_fuzz.cpp +++ b/libc/fuzzing/stdlib/quick_sort_fuzz.cpp @@ -1,4 +1,4 @@ -//===-- qsort_fuzz.cpp ----------------------------------------------------===// +//===-- quick_sort_fuzz.cpp------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,24 +6,13 @@ // //===----------------------------------------------------------------------===// /// -/// Fuzzing test for llvm-libc qsort implementation. +/// Fuzzing test for llvm-libc quick_sort implementation. /// //===----------------------------------------------------------------------===// -#include "src/stdlib/qsort.h" +#include "src/stdlib/qsort_util.h" #include <stdint.h> -static int int_compare(const void *l, const void *r) { - int li = *reinterpret_cast<const int *>(l); - int ri = *reinterpret_cast<const int *>(r); - if (li == ri) - return 0; - else if (li > ri) - return 1; - else - return -1; -} - extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { const size_t array_size = size / sizeof(int); if (array_size == 0) @@ -34,7 +23,17 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { for (size_t i = 0; i < array_size; ++i) array[i] = data_as_int[i]; - LIBC_NAMESPACE::qsort(array, array_size, sizeof(int), int_compare); + const auto is_less = [](const void *a_ptr, + const void *b_ptr) noexcept -> bool { + const int &a = *static_cast<const int *>(a_ptr); + const int &b = *static_cast<const int *>(b_ptr); + + return a < b; + }; + + constexpr bool USE_QUICKSORT = true; + LIBC_NAMESPACE::internal::unstable_sort_impl<USE_QUICKSORT>( + array, array_size, sizeof(int), is_less); for (size_t i = 0; i < array_size - 1; ++i) { if (array[i] > array[i + 1]) diff --git a/libc/hdr/types/CMakeLists.txt b/libc/hdr/types/CMakeLists.txt index 5156b58..1674de1 100644 --- a/libc/hdr/types/CMakeLists.txt +++ b/libc/hdr/types/CMakeLists.txt @@ -86,6 +86,14 @@ add_proxy_header_library( ) add_proxy_header_library( + struct_tm + HDRS + struct_tm.h + FULL_BUILD_DEPENDS + libc.include.llvm-libc-types.struct_tm +) + +add_proxy_header_library( size_t HDRS size_t.h diff --git a/libc/hdr/types/struct_tm.h b/libc/hdr/types/struct_tm.h new file mode 100644 index 0000000..96c23e2 --- /dev/null +++ b/libc/hdr/types/struct_tm.h @@ -0,0 +1,21 @@ +//===-- Proxy for struct tm ----------------------------------------===// +// +// 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_HDR_TYPES_STRUCT_TM_H +#define LLVM_LIBC_HDR_TYPES_STRUCT_TM_H + +#ifdef LIBC_FULL_BUILD + +#include "include/llvm-libc-types/struct_tm.h" + +#else + +#include <time.h> + +#endif // LIBC_FULL_BUILD + +#endif // LLVM_LIBC_HDR_TYPES_STRUCT_TM_H diff --git a/libc/include/CMakeLists.txt b/libc/include/CMakeLists.txt index 3a05c01..568bb05 100644 --- a/libc/include/CMakeLists.txt +++ b/libc/include/CMakeLists.txt @@ -19,11 +19,10 @@ add_header( # TODO: Can we simplify this macro expansion? # https://github.com/llvm/llvm-project/issues/117254 -macro(add_header_macro TARGET_NAME YAML_FILE DEF_FILE GEN_HDR DEPENDS) +macro(add_header_macro TARGET_NAME YAML_FILE GEN_HDR DEPENDS) add_gen_header( ${TARGET_NAME} YAML_FILE ${YAML_FILE} - DEF_FILE ${DEF_FILE} GEN_HDR ${GEN_HDR} ${DEPENDS} ${ARGN} @@ -32,8 +31,7 @@ endmacro() add_header_macro( ctype - ../libc/hdrgen/yaml/ctype.yaml - ctype.h.def + ../libc/include/ctype.yaml ctype.h DEPENDS .llvm_libc_common_h @@ -42,8 +40,7 @@ add_header_macro( add_header_macro( dirent - ../libc/hdrgen/yaml/dirent.yaml - dirent.h.def + ../libc/include/dirent.yaml dirent.h DEPENDS .llvm_libc_common_h @@ -54,8 +51,7 @@ add_header_macro( add_header_macro( fcntl - ../libc/hdrgen/yaml/fcntl.yaml - fcntl.h.def + ../libc/include/fcntl.yaml fcntl.h DEPENDS .llvm-libc-macros.fcntl_macros @@ -70,8 +66,7 @@ add_header_macro( add_header_macro( dlfcn - ../libc/hdrgen/yaml/dlfcn.yaml - dlfcn.h.def + ../libc/include/dlfcn.yaml dlfcn.h DEPENDS .llvm-libc-macros.dlfcn_macros @@ -80,8 +75,7 @@ add_header_macro( add_header_macro( features - ../libc/hdrgen/yaml/features.yaml - features.h.def + ../libc/include/features.yaml features.h DEPENDS .llvm_libc_common_h @@ -90,8 +84,7 @@ add_header_macro( add_header_macro( fenv - ../libc/hdrgen/yaml/fenv.yaml - fenv.h.def + ../libc/include/fenv.yaml fenv.h DEPENDS .llvm_libc_common_h @@ -102,8 +95,7 @@ add_header_macro( add_header_macro( inttypes - ../libc/hdrgen/yaml/inttypes.yaml - inttypes.h.def + ../libc/include/inttypes.yaml inttypes.h DEPENDS .llvm_libc_common_h @@ -113,8 +105,7 @@ add_header_macro( add_header_macro( float - ../libc/hdrgen/yaml/float.yaml - float.h.def + ../libc/include/float.yaml float.h DEPENDS .llvm-libc-macros.float_macros @@ -122,8 +113,7 @@ add_header_macro( add_header_macro( stdint - ../libc/hdrgen/yaml/stdint.yaml - stdint.h.def + ../libc/include/stdint.yaml stdint.h DEPENDS .llvm-libc-macros.stdint_macros @@ -131,8 +121,7 @@ add_header_macro( add_header_macro( limits - ../libc/hdrgen/yaml/limits.yaml - limits.h.def + ../libc/include/limits.yaml limits.h DEPENDS .llvm-libc-macros.limits_macros @@ -140,8 +129,7 @@ add_header_macro( add_header_macro( malloc - ../libc/hdrgen/yaml/malloc.yaml - malloc.h.def + ../libc/include/malloc.yaml malloc.h DEPENDS .llvm_libc_common_h @@ -150,8 +138,7 @@ add_header_macro( add_header_macro( math - ../libc/hdrgen/yaml/math.yaml - math.h.def + ../libc/include/math.yaml math.h DEPENDS .llvm_libc_common_h @@ -165,8 +152,7 @@ add_header_macro( add_header_macro( stdfix - ../libc/hdrgen/yaml/stdfix.yaml - stdfix.h.def + ../libc/include/stdfix.yaml stdfix.h DEPENDS .llvm-libc-macros.stdfix_macros @@ -178,8 +164,7 @@ file(MAKE_DIRECTORY ${LIBC_INCLUDE_DIR}/arpa) add_header_macro( arpa_inet - ../libc/hdrgen/yaml/arpa/inet.yaml - arpa/inet.h.def + ../libc/include/arpa/inet.yaml arpa/inet.h DEPENDS .llvm_libc_common_h @@ -187,8 +172,7 @@ add_header_macro( add_header_macro( assert - ../libc/hdrgen/yaml/assert.yaml - assert.h.def + ../libc/include/assert.yaml assert.h DEPENDS .llvm_libc_common_h @@ -197,8 +181,7 @@ add_header_macro( add_header_macro( complex - ../libc/hdrgen/yaml/complex.yaml - complex.h.def + ../libc/include/complex.yaml complex.h DEPENDS .llvm_libc_common_h @@ -207,8 +190,7 @@ add_header_macro( add_header_macro( setjmp - ../libc/hdrgen/yaml/setjmp.yaml - setjmp.h.def + ../libc/include/setjmp.yaml setjmp.h DEPENDS .llvm_libc_common_h @@ -217,8 +199,7 @@ add_header_macro( add_header_macro( string - ../libc/hdrgen/yaml/string.yaml - string.h.def + ../libc/include/string.yaml string.h DEPENDS .llvm_libc_common_h @@ -228,8 +209,7 @@ add_header_macro( add_header_macro( strings - ../libc/hdrgen/yaml/strings.yaml - strings.h.def + ../libc/include/strings.yaml strings.h DEPENDS .llvm_libc_common_h @@ -238,8 +218,7 @@ add_header_macro( add_header_macro( search - ../libc/hdrgen/yaml/search.yaml - search.h.def + ../libc/include/search.yaml search.h DEPENDS .llvm_libc_common_h @@ -252,8 +231,7 @@ add_header_macro( add_header_macro( time - ../libc/hdrgen/yaml/time.yaml - time.h.def + ../libc/include/time.yaml time.h DEPENDS .llvm_libc_common_h @@ -268,8 +246,7 @@ add_header_macro( add_header_macro( threads - ../libc/hdrgen/yaml/threads.yaml - threads.h.def + ../libc/include/threads.yaml threads.h DEPENDS .llvm_libc_common_h @@ -285,8 +262,7 @@ add_header_macro( add_header_macro( errno - ../libc/hdrgen/yaml/errno.yaml - errno.h.def + ../libc/include/errno.yaml errno.h DEPENDS .llvm-libc-macros.generic_error_number_macros @@ -295,8 +271,7 @@ add_header_macro( add_header_macro( signal - ../libc/hdrgen/yaml/signal.yaml - signal.h.def + ../libc/include/signal.yaml signal.h DEPENDS .llvm-libc-macros.signal_macros @@ -311,8 +286,7 @@ add_header_macro( add_header_macro( stdbit - ../libc/hdrgen/yaml/stdbit.yaml - stdbit.h.def + ../libc/include/stdbit.yaml stdbit.h DEPENDS .llvm_libc_common_h @@ -321,8 +295,7 @@ add_header_macro( add_header_macro( stdckdint - ../libc/hdrgen/yaml/stdckdint.yaml - stdckdint.h.def + ../libc/include/stdckdint.yaml stdckdint.h DEPENDS .llvm_libc_common_h @@ -331,8 +304,7 @@ add_header_macro( add_header_macro( stdio - ../libc/hdrgen/yaml/stdio.yaml - stdio.h.def + ../libc/include/stdio.yaml stdio.h DEPENDS .llvm-libc-macros.file_seek_macros @@ -347,8 +319,7 @@ add_header_macro( add_header_macro( stdlib - ../libc/hdrgen/yaml/stdlib.yaml - stdlib.h.def + ../libc/include/stdlib.yaml stdlib.h DEPENDS .llvm_libc_common_h @@ -366,8 +337,7 @@ add_header_macro( add_header_macro( unistd - ../libc/hdrgen/yaml/unistd.yaml - unistd.h.def + ../libc/include/unistd.yaml unistd.h DEPENDS .llvm_libc_common_h @@ -385,8 +355,7 @@ add_header_macro( add_header_macro( pthread - ../libc/hdrgen/yaml/pthread.yaml - pthread.h.def + ../libc/include/pthread.yaml pthread.h DEPENDS .llvm-libc-macros.pthread_macros @@ -409,8 +378,7 @@ add_header_macro( add_header_macro( sched - ../libc/hdrgen/yaml/sched.yaml - sched.h.def + ../libc/include/sched.yaml sched.h DEPENDS .llvm_libc_common_h @@ -426,8 +394,7 @@ add_header_macro( add_header_macro( spawn - ../libc/hdrgen/yaml/spawn.yaml - spawn.h.def + ../libc/include/spawn.yaml spawn.h DEPENDS .llvm_libc_common_h @@ -439,8 +406,7 @@ add_header_macro( add_header_macro( link - ../libc/hdrgen/yaml/link.yaml - link.h.def + ../libc/include/link.yaml link.h DEPENDS .llvm_libc_common_h @@ -449,8 +415,7 @@ add_header_macro( add_header_macro( elf - ../libc/hdrgen/yaml/elf.yaml - elf.h.def + ../libc/include/elf.yaml elf.h DEPENDS .llvm-libc-macros.elf_macros @@ -463,8 +428,7 @@ file(MAKE_DIRECTORY ${LIBC_INCLUDE_DIR}/sys) add_header_macro( sys_auxv - ../libc/hdrgen/yaml/sys/auxv.yaml - sys/auxv.h.def + ../libc/include/sys/auxv.yaml sys/auxv.h DEPENDS .llvm_libc_common_h @@ -473,8 +437,7 @@ add_header_macro( add_header_macro( sys_epoll - ../libc/hdrgen/yaml/sys/epoll.yaml - sys/epoll.h.def + ../libc/include/sys/epoll.yaml sys/epoll.h DEPENDS .llvm_libc_common_h @@ -486,8 +449,7 @@ add_header_macro( add_header_macro( sys_ioctl - ../libc/hdrgen/yaml/sys/ioctl.yaml - sys/ioctl.h.def + ../libc/include/sys/ioctl.yaml sys/ioctl.h DEPENDS .llvm_libc_common_h @@ -496,8 +458,7 @@ add_header_macro( add_header_macro( sys_mman - ../libc/hdrgen/yaml/sys/mman.yaml - sys/mman.h.def + ../libc/include/sys/mman.yaml sys/mman.h DEPENDS .llvm_libc_common_h @@ -509,8 +470,7 @@ add_header_macro( add_header_macro( sys_prctl - ../libc/hdrgen/yaml/sys/prctl.yaml - sys/prctl.h.def + ../libc/include/sys/prctl.yaml sys/prctl.h DEPENDS .llvm_libc_common_h @@ -526,8 +486,7 @@ add_header( add_header_macro( sys_random - ../libc/hdrgen/yaml/sys/random.yaml - sys/random.h.def + ../libc/include/sys/random.yaml sys/random.h DEPENDS .llvm_libc_common_h @@ -538,8 +497,7 @@ add_header_macro( add_header_macro( sys_resource - ../libc/hdrgen/yaml/sys/resource.yaml - sys/resource.h.def + ../libc/include/sys/resource.yaml sys/resource.h DEPENDS .llvm_libc_common_h @@ -550,8 +508,7 @@ add_header_macro( add_header_macro( sys_stat - ../libc/hdrgen/yaml/sys/stat.yaml - sys/stat.h.def + ../libc/include/sys/stat.yaml sys/stat.h DEPENDS .llvm_libc_common_h @@ -572,8 +529,7 @@ add_header_macro( add_header_macro( sys_select - ../libc/hdrgen/yaml/sys/select.yaml - sys/select.h.def + ../libc/include/sys/select.yaml sys/select.h DEPENDS .llvm_libc_common_h @@ -588,8 +544,7 @@ add_header_macro( add_header_macro( sys_sendfile - ../libc/hdrgen/yaml/sys/sendfile.yaml - sys/sendfile.h.def + ../libc/include/sys/sendfile.yaml sys/sendfile.h DEPENDS .llvm_libc_common_h @@ -600,8 +555,7 @@ add_header_macro( add_header_macro( sys_socket - ../libc/hdrgen/yaml/sys/socket.yaml - sys/socket.h.def + ../libc/include/sys/socket.yaml sys/socket.h DEPENDS .llvm_libc_common_h @@ -616,8 +570,7 @@ add_header_macro( add_header_macro( sys_statvfs - ../libc/hdrgen/yaml/sys/statvfs.yaml - sys/statvfs.h.def + ../libc/include/sys/statvfs.yaml sys/statvfs.h DEPENDS .llvm_libc_common_h @@ -626,16 +579,14 @@ add_header_macro( add_header_macro( sys_syscall - ../libc/hdrgen/yaml/sys/syscall.yaml - sys/syscall.h.def + ../libc/include/sys/syscall.yaml sys/syscall.h DEPENDS ) add_header_macro( sys_time - ../libc/hdrgen/yaml/sys/time.yaml - sys/time.h.def + ../libc/include/sys/time.yaml sys/time.h DEPENDS .llvm_libc_common_h @@ -645,8 +596,7 @@ add_header_macro( add_header_macro( sys_types - ../libc/hdrgen/yaml/sys/types.yaml - sys/types.h.def + ../libc/include/sys/types.yaml sys/types.h DEPENDS .llvm_libc_common_h @@ -675,8 +625,7 @@ add_header_macro( add_header_macro( sys_utsname - ../libc/hdrgen/yaml/sys/utsname.yaml - sys/utsname.h.def + ../libc/include/sys/utsname.yaml sys/utsname.h DEPENDS .llvm_libc_common_h @@ -685,8 +634,7 @@ add_header_macro( add_header_macro( sys_wait - ../libc/hdrgen/yaml/sys/wait.yaml - sys/wait.h.def + ../libc/include/sys/wait.yaml sys/wait.h DEPENDS .llvm_libc_common_h @@ -698,8 +646,7 @@ add_header_macro( add_header_macro( termios - ../libc/hdrgen/yaml/termios.yaml - termios.h.def + ../libc/include/termios.yaml termios.h DEPENDS .llvm_libc_common_h @@ -713,8 +660,7 @@ add_header_macro( add_header_macro( uchar - ../libc/hdrgen/yaml/uchar.yaml - uchar.h.def + ../libc/include/uchar.yaml uchar.h DEPENDS .llvm_libc_common_h @@ -726,8 +672,7 @@ add_header_macro( add_header_macro( wchar - ../libc/hdrgen/yaml/wchar.yaml - wchar.h.def + ../libc/include/wchar.yaml wchar.h DEPENDS .llvm_libc_common_h @@ -740,8 +685,7 @@ add_header_macro( add_header_macro( locale - ../libc/hdrgen/yaml/locale.yaml - locale.h.def + ../libc/include/locale.yaml locale.h DEPENDS .llvm_libc_common_h diff --git a/libc/include/__llvm-libc-common.h b/libc/include/__llvm-libc-common.h index d54ee7b..c63eb13 100644 --- a/libc/include/__llvm-libc-common.h +++ b/libc/include/__llvm-libc-common.h @@ -50,7 +50,24 @@ #define __END_C_DECLS #undef __restrict -#define __restrict restrict // C99 and above support the restrict keyword. +#if __STDC_VERSION__ >= 199901L +// C99 and above support the restrict keyword. +#define __restrict restrict +#elif !defined(__GNUC__) +// GNU-compatible compilers accept the __ spelling in all modes. +// Otherwise, omit the qualifier for pure C89 compatibility. +#define __restrict +#endif + +#undef _Noreturn +#if __STDC_VERSION__ >= 201112L +// In C11 and later, _Noreturn is a keyword. +#elif defined(__GNUC__) +// GNU-compatible compilers have an equivalent attribute. +#define _Noreturn __attribute__((__noreturn__)) +#else +#define _Noreturn +#endif #undef __NOEXCEPT #ifdef __GNUC__ diff --git a/libc/hdrgen/yaml/arpa/inet.yaml b/libc/include/arpa/inet.yaml index cb366e0..10cd56d 100644 --- a/libc/hdrgen/yaml/arpa/inet.yaml +++ b/libc/include/arpa/inet.yaml @@ -1,4 +1,5 @@ -header: arpa-inet.h +header: arpa/inet.h +header_template: inet.h.def macros: [] types: [] enums: [] diff --git a/libc/hdrgen/yaml/assert.yaml b/libc/include/assert.yaml index f740554..1a3bded 100644 --- a/libc/hdrgen/yaml/assert.yaml +++ b/libc/include/assert.yaml @@ -1,4 +1,5 @@ header: assert.h +header_template: assert.h.def macros: [] types: [] enums: [] diff --git a/libc/hdrgen/yaml/complex.yaml b/libc/include/complex.yaml index cd81de7..0531848 100644 --- a/libc/hdrgen/yaml/complex.yaml +++ b/libc/include/complex.yaml @@ -1,4 +1,5 @@ header: complex.h +header_template: complex.h.def macros: [] types: - type_name: cfloat16 diff --git a/libc/hdrgen/yaml/ctype.yaml b/libc/include/ctype.yaml index b4823c3..6238f1b 100644 --- a/libc/hdrgen/yaml/ctype.yaml +++ b/libc/include/ctype.yaml @@ -1,4 +1,5 @@ header: ctype.h +header_template: ctype.h.def macros: [] types: - type_name: locale_t diff --git a/libc/hdrgen/yaml/dirent.yaml b/libc/include/dirent.yaml index cdccf6a..3fc522f 100644 --- a/libc/hdrgen/yaml/dirent.yaml +++ b/libc/include/dirent.yaml @@ -1,4 +1,5 @@ header: dirent.h +header_template: dirent.h.def macros: [] types: - type_name: struct_dirent diff --git a/libc/hdrgen/yaml/dlfcn.yaml b/libc/include/dlfcn.yaml index 725ee705..9e8803c 100644 --- a/libc/hdrgen/yaml/dlfcn.yaml +++ b/libc/include/dlfcn.yaml @@ -1,4 +1,5 @@ header: dlfcn.h +header_template: dlfcn.h.def macros: - macro_name: RTLD_LAZY macro_value: null diff --git a/libc/hdrgen/yaml/elf.yaml b/libc/include/elf.yaml index 2e9db32..f78ae82 100644 --- a/libc/hdrgen/yaml/elf.yaml +++ b/libc/include/elf.yaml @@ -1,4 +1,5 @@ header: elf.h +header_template: elf.h.def standards: - Linux macros: [] diff --git a/libc/hdrgen/yaml/errno.yaml b/libc/include/errno.yaml index a894063..188a9fa 100644 --- a/libc/hdrgen/yaml/errno.yaml +++ b/libc/include/errno.yaml @@ -1,4 +1,5 @@ header: errno.h +header_template: errno.h.def standards: - stdc - Linux diff --git a/libc/hdrgen/yaml/fcntl.yaml b/libc/include/fcntl.yaml index 71c0df3..78f9353 100644 --- a/libc/hdrgen/yaml/fcntl.yaml +++ b/libc/include/fcntl.yaml @@ -1,4 +1,5 @@ header: fcntl.h +header_template: fcntl.h.def macros: [] types: - type_name: off_t diff --git a/libc/hdrgen/yaml/features.yaml b/libc/include/features.yaml index a18af22..726320a 100644 --- a/libc/hdrgen/yaml/features.yaml +++ b/libc/include/features.yaml @@ -1,4 +1,5 @@ header: features.h +header_template: features.h.def standards: - stdc macros: [] diff --git a/libc/hdrgen/yaml/fenv.yaml b/libc/include/fenv.yaml index 1010efc..1ecaf63 100644 --- a/libc/hdrgen/yaml/fenv.yaml +++ b/libc/include/fenv.yaml @@ -1,4 +1,5 @@ header: fenv.h +header_template: fenv.h.def macros: [] types: - type_name: fenv_t diff --git a/libc/hdrgen/yaml/float.yaml b/libc/include/float.yaml index 63639a6..21df651 100644 --- a/libc/hdrgen/yaml/float.yaml +++ b/libc/include/float.yaml @@ -1,4 +1,5 @@ header: float.h +header_template: float.h.def standards: - stdc macros: [] diff --git a/libc/hdrgen/yaml/inttypes.yaml b/libc/include/inttypes.yaml index ad636cc..d5dec5b 100644 --- a/libc/hdrgen/yaml/inttypes.yaml +++ b/libc/include/inttypes.yaml @@ -1,4 +1,5 @@ header: inttypes.h +header_template: inttypes.h.def macros: [] types: - type_name: imaxdiv_t diff --git a/libc/hdrgen/yaml/limits.yaml b/libc/include/limits.yaml index bf33ed2..b664041 100644 --- a/libc/hdrgen/yaml/limits.yaml +++ b/libc/include/limits.yaml @@ -1,4 +1,5 @@ header: limits.h +header_template: limits.h.def standards: - stdc macros: [] diff --git a/libc/hdrgen/yaml/link.yaml b/libc/include/link.yaml index d1963a8..1cd609e 100644 --- a/libc/hdrgen/yaml/link.yaml +++ b/libc/include/link.yaml @@ -1,4 +1,5 @@ header: link.h +header_template: link.h.def standards: - Linux macros: [] diff --git a/libc/hdrgen/yaml/locale.yaml b/libc/include/locale.yaml index 7da7966..9ff53c1 100644 --- a/libc/hdrgen/yaml/locale.yaml +++ b/libc/include/locale.yaml @@ -1,4 +1,5 @@ header: locale.h +header_template: locale.h.def functions: - name: localeconv standards: diff --git a/libc/hdrgen/yaml/malloc.yaml b/libc/include/malloc.yaml index 8db4f3a..ec73c90 100644 --- a/libc/hdrgen/yaml/malloc.yaml +++ b/libc/include/malloc.yaml @@ -1,4 +1,5 @@ header: malloc.h +header_template: malloc.h.def macros: [] types: [] enums: [] diff --git a/libc/hdrgen/yaml/math.yaml b/libc/include/math.yaml index 3b8caec..831d045 100644 --- a/libc/hdrgen/yaml/math.yaml +++ b/libc/include/math.yaml @@ -1,4 +1,5 @@ header: math.h +header_template: math.h.def macros: [] types: - type_name: float_t diff --git a/libc/hdrgen/yaml/pthread.yaml b/libc/include/pthread.yaml index b9068c3..4f386bd 100644 --- a/libc/hdrgen/yaml/pthread.yaml +++ b/libc/include/pthread.yaml @@ -1,4 +1,5 @@ header: pthread.h +header_template: pthread.h.def macros: [] types: - type_name: pthread_t diff --git a/libc/hdrgen/yaml/sched.yaml b/libc/include/sched.yaml index 2d4876b..57871f5 100644 --- a/libc/hdrgen/yaml/sched.yaml +++ b/libc/include/sched.yaml @@ -1,4 +1,5 @@ header: sched.h +header_template: sched.h.def macros: [] types: - type_name: struct_timespec diff --git a/libc/hdrgen/yaml/search.yaml b/libc/include/search.yaml index a0c73bc..b7ce06d 100644 --- a/libc/hdrgen/yaml/search.yaml +++ b/libc/include/search.yaml @@ -1,4 +1,5 @@ header: search.h +header_template: search.h.def macros: [] types: - type_name: struct_hsearch_data diff --git a/libc/hdrgen/yaml/setjmp.yaml b/libc/include/setjmp.yaml index 68e3ff0..2c4f7fb 100644 --- a/libc/hdrgen/yaml/setjmp.yaml +++ b/libc/include/setjmp.yaml @@ -1,4 +1,5 @@ header: setjmp.h +header_template: setjmp.h.def macros: [] types: - type_name: jmp_buf diff --git a/libc/hdrgen/yaml/signal.yaml b/libc/include/signal.yaml index c66abb1..576e7757 100644 --- a/libc/hdrgen/yaml/signal.yaml +++ b/libc/include/signal.yaml @@ -1,4 +1,5 @@ header: signal.h +header_template: signal.h.def macros: [] types: - type_name: pid_t diff --git a/libc/hdrgen/yaml/spawn.yaml b/libc/include/spawn.yaml index be3f4e9..e725ab9 100644 --- a/libc/hdrgen/yaml/spawn.yaml +++ b/libc/include/spawn.yaml @@ -1,4 +1,5 @@ header: spawn.h +header_template: spawn.h.def macros: [] types: - type_name: posix_spawn_file_actions_t diff --git a/libc/hdrgen/yaml/stdbit.yaml b/libc/include/stdbit.yaml index 25d2d32..e9bd6b3 100644 --- a/libc/hdrgen/yaml/stdbit.yaml +++ b/libc/include/stdbit.yaml @@ -1,4 +1,5 @@ header: stdbit.h +header_template: stdbit.h.def macros: [] types: [] enums: [] diff --git a/libc/hdrgen/yaml/stdckdint.yaml b/libc/include/stdckdint.yaml index ea8fc47..e8b2e80 100644 --- a/libc/hdrgen/yaml/stdckdint.yaml +++ b/libc/include/stdckdint.yaml @@ -1,4 +1,5 @@ header: stdckdint.h +header_template: stdckdint.h.def standards: - stdc macros: [] diff --git a/libc/hdrgen/yaml/stdfix.yaml b/libc/include/stdfix.yaml index 9787eab..7b3bdba 100644 --- a/libc/hdrgen/yaml/stdfix.yaml +++ b/libc/include/stdfix.yaml @@ -1,4 +1,5 @@ header: stdfix.h +header_template: stdfix.h.def macros: [] types: - type_name: stdfix-types diff --git a/libc/hdrgen/yaml/stdint.yaml b/libc/include/stdint.yaml index 8887f59..d583a10 100644 --- a/libc/hdrgen/yaml/stdint.yaml +++ b/libc/include/stdint.yaml @@ -1,4 +1,5 @@ header: stdint.h +header_template: stdint.h.def standards: - stdc macros: [] diff --git a/libc/hdrgen/yaml/stdio.yaml b/libc/include/stdio.yaml index fd116bb..2619984 100644 --- a/libc/hdrgen/yaml/stdio.yaml +++ b/libc/include/stdio.yaml @@ -1,4 +1,5 @@ header: stdio.h +header_template: stdio.h.def macros: - macro_name: stdout macro_value: stdout diff --git a/libc/hdrgen/yaml/stdlib.yaml b/libc/include/stdlib.yaml index c6c95e4..4b68f27 100644 --- a/libc/hdrgen/yaml/stdlib.yaml +++ b/libc/include/stdlib.yaml @@ -1,4 +1,5 @@ header: stdlib.h +header_template: stdlib.h.def standards: - stdc macros: [] diff --git a/libc/hdrgen/yaml/string.yaml b/libc/include/string.yaml index af1750e..deded30 100644 --- a/libc/hdrgen/yaml/string.yaml +++ b/libc/include/string.yaml @@ -1,4 +1,5 @@ header: string.h +header_template: string.h.def macros: [] types: - type_name: size_t diff --git a/libc/hdrgen/yaml/strings.yaml b/libc/include/strings.yaml index ca91b62..e672dca 100644 --- a/libc/hdrgen/yaml/strings.yaml +++ b/libc/include/strings.yaml @@ -1,4 +1,5 @@ header: strings.h +header_template: strings.h.def macros: [] types: [] enums: [] diff --git a/libc/hdrgen/yaml/sys/auxv.yaml b/libc/include/sys/auxv.yaml index 9d546b3..82ecee7 100644 --- a/libc/hdrgen/yaml/sys/auxv.yaml +++ b/libc/include/sys/auxv.yaml @@ -1,4 +1,5 @@ -header: sys-auxv.h +header: sys/auxv.h +header_template: auxv.h.def macros: [] types: [] enums: [] diff --git a/libc/hdrgen/yaml/sys/epoll.yaml b/libc/include/sys/epoll.yaml index ee188c1..996eb78 100644 --- a/libc/hdrgen/yaml/sys/epoll.yaml +++ b/libc/include/sys/epoll.yaml @@ -1,4 +1,5 @@ -header: sys-epoll.h +header: sys/epoll.h +header_template: epoll.h.def macros: [] types: - type_name: struct_epoll_event diff --git a/libc/hdrgen/yaml/sys/ioctl.yaml b/libc/include/sys/ioctl.yaml index ffe73a8..5f7b7f3 100644 --- a/libc/hdrgen/yaml/sys/ioctl.yaml +++ b/libc/include/sys/ioctl.yaml @@ -1,4 +1,5 @@ -header: sys-ioctl.h +header: sys/ioctl.h +header_template: ioctl.h.def standards: POSIX macros: [] types: [] diff --git a/libc/hdrgen/yaml/sys/mman.yaml b/libc/include/sys/mman.yaml index 962ca35..8c20755 100644 --- a/libc/hdrgen/yaml/sys/mman.yaml +++ b/libc/include/sys/mman.yaml @@ -1,4 +1,5 @@ -header: sys-mman.h +header: sys/mman.h +header_template: mman.h.def macros: [] types: - type_name: mode_t diff --git a/libc/hdrgen/yaml/sys/prctl.yaml b/libc/include/sys/prctl.yaml index 82374be..53f5764 100644 --- a/libc/hdrgen/yaml/sys/prctl.yaml +++ b/libc/include/sys/prctl.yaml @@ -1,4 +1,5 @@ -header: sys-prctl.h +header: sys/prctl.h +header_template: prctl.h.def macros: [] types: [] enums: [] diff --git a/libc/hdrgen/yaml/sys/random.yaml b/libc/include/sys/random.yaml index 228bb50..4efb2fb 100644 --- a/libc/hdrgen/yaml/sys/random.yaml +++ b/libc/include/sys/random.yaml @@ -1,4 +1,5 @@ -header: sys-random.h +header: sys/random.h +header_template: random.h.def macros: [] types: - type_name: ssize_t diff --git a/libc/hdrgen/yaml/sys/resource.yaml b/libc/include/sys/resource.yaml index 85ea1ad..3652d6d 100644 --- a/libc/hdrgen/yaml/sys/resource.yaml +++ b/libc/include/sys/resource.yaml @@ -1,4 +1,5 @@ -header: sys-resource.h +header: sys/resource.h +header_template: resource.h.def macros: [] types: - type_name: struct_rlimit diff --git a/libc/hdrgen/yaml/sys/select.yaml b/libc/include/sys/select.yaml index c680612..6066fd3 100644 --- a/libc/hdrgen/yaml/sys/select.yaml +++ b/libc/include/sys/select.yaml @@ -1,4 +1,5 @@ -header: sys-select.h +header: sys/select.h +header_template: select.h.def macros: [] types: - type_name: struct_timeval diff --git a/libc/hdrgen/yaml/sys/sendfile.yaml b/libc/include/sys/sendfile.yaml index 7e45e40..259ab83 100644 --- a/libc/hdrgen/yaml/sys/sendfile.yaml +++ b/libc/include/sys/sendfile.yaml @@ -1,4 +1,5 @@ -header: sys-sendfile.h +header: sys/sendfile.h +header_template: sendfile.h.def macros: [] types: - type_name: ssize_t diff --git a/libc/hdrgen/yaml/sys/socket.yaml b/libc/include/sys/socket.yaml index 47d835f..00d5de6 100644 --- a/libc/hdrgen/yaml/sys/socket.yaml +++ b/libc/include/sys/socket.yaml @@ -1,4 +1,5 @@ -header: sys-socket.h +header: sys/socket.h +header_template: socket.h.def macros: [] types: - type_name: struct_sockaddr_un diff --git a/libc/hdrgen/yaml/sys/stat.yaml b/libc/include/sys/stat.yaml index ed500f8..7f01342 100644 --- a/libc/hdrgen/yaml/sys/stat.yaml +++ b/libc/include/sys/stat.yaml @@ -1,4 +1,5 @@ -header: sys-stat.h +header: sys/stat.h +header_template: stat.h.def macros: [] types: - type_name: blkcnt_t diff --git a/libc/hdrgen/yaml/sys/statvfs.yaml b/libc/include/sys/statvfs.yaml index 22e0ef2..8c1d254 100644 --- a/libc/hdrgen/yaml/sys/statvfs.yaml +++ b/libc/include/sys/statvfs.yaml @@ -1,4 +1,5 @@ -header: sys-statvfs.h +header: sys/statvfs.h +header_template: statvfs.h.def macros: [] types: - type_name: struct_statvfs diff --git a/libc/hdrgen/yaml/sys/syscall.yaml b/libc/include/sys/syscall.yaml index c0a64338..879d95c 100644 --- a/libc/hdrgen/yaml/sys/syscall.yaml +++ b/libc/include/sys/syscall.yaml @@ -1,4 +1,5 @@ -header: sys-syscall.h +header: sys/syscall.h +header_template: syscall.h.def standards: Linux macros: [] types: [] diff --git a/libc/hdrgen/yaml/sys/time.yaml b/libc/include/sys/time.yaml index eb3dd54..687c1f8 100644 --- a/libc/hdrgen/yaml/sys/time.yaml +++ b/libc/include/sys/time.yaml @@ -1,4 +1,5 @@ -header: sys-time.h +header: sys/time.h +header_template: time.h.def standards: Linux macros: [] types: [] diff --git a/libc/hdrgen/yaml/sys/types.yaml b/libc/include/sys/types.yaml index 15eaf10..6fa0b44 100644 --- a/libc/hdrgen/yaml/sys/types.yaml +++ b/libc/include/sys/types.yaml @@ -1,4 +1,5 @@ -header: sys-types.h +header: sys/types.h +header_template: types.h.def standards: POSIX macros: [] types: diff --git a/libc/hdrgen/yaml/sys/utsname.yaml b/libc/include/sys/utsname.yaml index eecd55b..6c7cb71 100644 --- a/libc/hdrgen/yaml/sys/utsname.yaml +++ b/libc/include/sys/utsname.yaml @@ -1,4 +1,5 @@ -header: sys-utsname.h +header: sys/utsname.h +header_template: utsname.h.def macros: [] types: - type_name: struct_utsname diff --git a/libc/hdrgen/yaml/sys/wait.yaml b/libc/include/sys/wait.yaml index 4f0c69b..6257e34 100644 --- a/libc/hdrgen/yaml/sys/wait.yaml +++ b/libc/include/sys/wait.yaml @@ -1,4 +1,5 @@ -header: sys-wait.h +header: sys/wait.h +header_template: wait.h.def macros: [] types: - type_name: siginfo_t diff --git a/libc/hdrgen/yaml/termios.yaml b/libc/include/termios.yaml index e9c4cd3..8815097 100644 --- a/libc/hdrgen/yaml/termios.yaml +++ b/libc/include/termios.yaml @@ -1,4 +1,5 @@ header: termios.h +header_template: termios.h.def macros: [] types: - type_name: tcflag_t diff --git a/libc/hdrgen/yaml/threads.yaml b/libc/include/threads.yaml index aadcaf5..7014822 100644 --- a/libc/hdrgen/yaml/threads.yaml +++ b/libc/include/threads.yaml @@ -1,4 +1,5 @@ header: threads.h +header_template: threads.h.def macros: - macro_name: ONCE_FLAG_INIT macro_value: '{0}' diff --git a/libc/hdrgen/yaml/time.yaml b/libc/include/time.yaml index 3f745e5..b71b9ab 100644 --- a/libc/hdrgen/yaml/time.yaml +++ b/libc/include/time.yaml @@ -1,4 +1,5 @@ header: time.h +header_template: time.h.def macros: [] types: - type_name: struct_timeval diff --git a/libc/hdrgen/yaml/uchar.yaml b/libc/include/uchar.yaml index 18ca840..7139197 100644 --- a/libc/hdrgen/yaml/uchar.yaml +++ b/libc/include/uchar.yaml @@ -1,4 +1,5 @@ header: uchar.h +header_template: uchar.h.def standards: - stdc macros: [] diff --git a/libc/hdrgen/yaml/unistd.yaml b/libc/include/unistd.yaml index c6441c0..fada365 100644 --- a/libc/hdrgen/yaml/unistd.yaml +++ b/libc/include/unistd.yaml @@ -1,4 +1,5 @@ header: unistd.h +header_template: unistd.h.def macros: [] types: - type_name: uid_t diff --git a/libc/hdrgen/yaml/wchar.yaml b/libc/include/wchar.yaml index bc824b2..27a5926b 100644 --- a/libc/hdrgen/yaml/wchar.yaml +++ b/libc/include/wchar.yaml @@ -1,4 +1,5 @@ header: wchar.h +header_template: wchar.h.def macros: [] types: - type_name: size_t diff --git a/libc/shared/rpc_util.h b/libc/shared/rpc_util.h index 9406de5..687814b7 100644 --- a/libc/shared/rpc_util.h +++ b/libc/shared/rpc_util.h @@ -152,10 +152,10 @@ public: /// Suspend the thread briefly to assist the thread scheduler during busy loops. RPC_ATTRS void sleep_briefly() { -#if defined(__NVPTX__) && defined(RPC_TARGET_IS_GPU) +#if __has_builtin(__nvvm_reflect) if (__nvvm_reflect("__CUDA_ARCH") >= 700) asm("nanosleep.u32 64;" ::: "memory"); -#elif defined(__AMDGPU__) && defined(RPC_TARGET_IS_GPU) +#elif __has_builtin(__builtin_amdgcn_s_sleep) __builtin_amdgcn_s_sleep(2); #elif __has_builtin(__builtin_ia32_pause) __builtin_ia32_pause(); diff --git a/libc/src/__support/CMakeLists.txt b/libc/src/__support/CMakeLists.txt index 4e90aad..5090dc2 100644 --- a/libc/src/__support/CMakeLists.txt +++ b/libc/src/__support/CMakeLists.txt @@ -267,7 +267,9 @@ add_header_library( HDRS fixedvector.h DEPENDS + .libc_assert libc.src.__support.CPP.array + libc.src.string.memory_utils.inline_memset ) add_header_library( diff --git a/libc/src/__support/File/file.cpp b/libc/src/__support/File/file.cpp index 972249f..528542c 100644 --- a/libc/src/__support/File/file.cpp +++ b/libc/src/__support/File/file.cpp @@ -42,7 +42,7 @@ FileIOResult File::write_unlocked_nbf(const uint8_t *data, size_t len) { if (pos > 0) { // If the buffer is not empty // Flush the buffer const size_t write_size = pos; - auto write_result = platform_write(this, buf, write_size); + FileIOResult write_result = platform_write(this, buf, write_size); pos = 0; // Buffer is now empty so reset pos to the beginning. // If less bytes were written than expected, then an error occurred. if (write_result < write_size) { @@ -52,7 +52,7 @@ FileIOResult File::write_unlocked_nbf(const uint8_t *data, size_t len) { } } - auto write_result = platform_write(this, data, len); + FileIOResult write_result = platform_write(this, data, len); if (write_result < len) err = true; return write_result; @@ -99,7 +99,7 @@ FileIOResult File::write_unlocked_fbf(const uint8_t *data, size_t len) { // is full. const size_t write_size = pos; - auto buf_result = platform_write(this, buf, write_size); + FileIOResult buf_result = platform_write(this, buf, write_size); size_t bytes_written = buf_result.value; pos = 0; // Buffer is now empty so reset pos to the beginning. @@ -121,7 +121,8 @@ FileIOResult File::write_unlocked_fbf(const uint8_t *data, size_t len) { pos = remainder.size(); } else { - auto result = platform_write(this, remainder.data(), remainder.size()); + FileIOResult result = + platform_write(this, remainder.data(), remainder.size()); size_t bytes_written = buf_result.value; // If less bytes were written than expected, then an error occurred. Return @@ -190,6 +191,17 @@ FileIOResult File::read_unlocked(void *data, size_t len) { prev_op = FileOp::READ; + if (bufmode == _IONBF) { // unbuffered. + return read_unlocked_nbf(static_cast<uint8_t *>(data), len); + } else if (bufmode == _IOFBF) { // fully buffered + return read_unlocked_fbf(static_cast<uint8_t *>(data), len); + } else /*if (bufmode == _IOLBF) */ { // line buffered + // There is no line buffered mode for read. Use fully buffered instead. + return read_unlocked_fbf(static_cast<uint8_t *>(data), len); + } +} + +size_t File::copy_data_from_buf(uint8_t *data, size_t len) { cpp::span<uint8_t> bufref(static_cast<uint8_t *>(buf), bufsize); cpp::span<uint8_t> dataref(static_cast<uint8_t *>(data), len); @@ -209,32 +221,42 @@ FileIOResult File::read_unlocked(void *data, size_t len) { for (size_t i = 0; i < available_data; ++i) dataref[i] = bufref[i + pos]; read_limit = pos = 0; // Reset the pointers. + + return available_data; +} + +FileIOResult File::read_unlocked_fbf(uint8_t *data, size_t len) { + // Read data from the buffer first. + size_t available_data = copy_data_from_buf(data, len); + if (available_data == len) + return available_data; + // Update the dataref to reflect that fact that we have already // copied |available_data| into |data|. - dataref = cpp::span<uint8_t>(dataref.data() + available_data, - dataref.size() - available_data); - size_t to_fetch = len - available_data; + cpp::span<uint8_t> dataref(static_cast<uint8_t *>(data) + available_data, + to_fetch); + if (to_fetch > bufsize) { - auto result = platform_read(this, dataref.data(), to_fetch); + FileIOResult result = platform_read(this, dataref.data(), to_fetch); size_t fetched_size = result.value; if (result.has_error() || fetched_size < to_fetch) { if (!result.has_error()) eof = true; else err = true; - return {available_data + fetched_size, result.has_error()}; + return {available_data + fetched_size, result.error}; } return len; } // Fetch and buffer another buffer worth of data. - auto result = platform_read(this, buf, bufsize); + FileIOResult result = platform_read(this, buf, bufsize); size_t fetched_size = result.value; read_limit += fetched_size; size_t transfer_size = fetched_size >= to_fetch ? to_fetch : fetched_size; for (size_t i = 0; i < transfer_size; ++i) - dataref[i] = bufref[i]; + dataref[i] = buf[i]; pos += transfer_size; if (result.has_error() || fetched_size < to_fetch) { if (!result.has_error()) @@ -245,6 +267,26 @@ FileIOResult File::read_unlocked(void *data, size_t len) { return {transfer_size + available_data, result.error}; } +FileIOResult File::read_unlocked_nbf(uint8_t *data, size_t len) { + // Check whether there is a character in the ungetc buffer. + size_t available_data = copy_data_from_buf(data, len); + if (available_data == len) + return available_data; + + // Directly copy the data into |data|. + cpp::span<uint8_t> dataref(static_cast<uint8_t *>(data) + available_data, + len - available_data); + FileIOResult result = platform_read(this, dataref.data(), dataref.size()); + + if (result.has_error() || result < dataref.size()) { + if (!result.has_error()) + eof = true; + else + err = true; + } + return {result + available_data, result.error}; +} + int File::ungetc_unlocked(int c) { // There is no meaning to unget if: // 1. You are trying to push back EOF. @@ -287,7 +329,7 @@ ErrorOr<int> File::seek(off_t offset, int whence) { FileLock lock(this); if (prev_op == FileOp::WRITE && pos > 0) { - auto buf_result = platform_write(this, buf, pos); + FileIOResult buf_result = platform_write(this, buf, pos); if (buf_result.has_error() || buf_result.value < pos) { err = true; return Error(buf_result.error); @@ -325,7 +367,7 @@ ErrorOr<off_t> File::tell() { int File::flush_unlocked() { if (prev_op == FileOp::WRITE && pos > 0) { - auto buf_result = platform_write(this, buf, pos); + FileIOResult buf_result = platform_write(this, buf, pos); if (buf_result.has_error() || buf_result.value < pos) { err = true; return buf_result.error; diff --git a/libc/src/__support/File/file.h b/libc/src/__support/File/file.h index 42e1d11..5c97a9c 100644 --- a/libc/src/__support/File/file.h +++ b/libc/src/__support/File/file.h @@ -280,6 +280,10 @@ private: FileIOResult write_unlocked_fbf(const uint8_t *data, size_t len); FileIOResult write_unlocked_nbf(const uint8_t *data, size_t len); + FileIOResult read_unlocked_fbf(uint8_t *data, size_t len); + FileIOResult read_unlocked_nbf(uint8_t *data, size_t len); + size_t copy_data_from_buf(uint8_t *data, size_t len); + constexpr void adjust_buf() { if (read_allowed() && (buf == nullptr || bufsize == 0)) { // We should allow atleast one ungetc operation. diff --git a/libc/src/__support/GPU/CMakeLists.txt b/libc/src/__support/GPU/CMakeLists.txt index 28fd9a1..9b359f6 100644 --- a/libc/src/__support/GPU/CMakeLists.txt +++ b/libc/src/__support/GPU/CMakeLists.txt @@ -1,16 +1,12 @@ -if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_ARCHITECTURE}) +# These utilities are GPU only. +if(NOT LIBC_TARGET_OS_IS_GPU) return() endif() -add_subdirectory(${LIBC_TARGET_ARCHITECTURE}) -set(target_gpu_utils libc.src.__support.GPU.${LIBC_TARGET_ARCHITECTURE}.${LIBC_TARGET_ARCHITECTURE}_utils) - add_header_library( utils HDRS utils.h - DEPENDS - ${target_gpu_utils} ) add_object_library( @@ -21,6 +17,6 @@ add_object_library( allocator.h DEPENDS libc.src.__support.common - libc.src.__support.GPU.utils libc.src.__support.RPC.rpc_client + .utils ) diff --git a/libc/src/__support/GPU/amdgpu/CMakeLists.txt b/libc/src/__support/GPU/amdgpu/CMakeLists.txt deleted file mode 100644 index f2b98fc..0000000 --- a/libc/src/__support/GPU/amdgpu/CMakeLists.txt +++ /dev/null @@ -1,7 +0,0 @@ -add_header_library( - amdgpu_utils - HDRS - utils.h - DEPENDS - libc.src.__support.common -) diff --git a/libc/src/__support/GPU/amdgpu/utils.h b/libc/src/__support/GPU/amdgpu/utils.h deleted file mode 100644 index 6ab9540..0000000 --- a/libc/src/__support/GPU/amdgpu/utils.h +++ /dev/null @@ -1,183 +0,0 @@ -//===-------------- AMDGPU implementation of GPU utils ----------*- 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___SUPPORT_GPU_AMDGPU_IO_H -#define LLVM_LIBC_SRC___SUPPORT_GPU_AMDGPU_IO_H - -#include "src/__support/common.h" -#include "src/__support/macros/config.h" - -#include <stdint.h> - -namespace LIBC_NAMESPACE_DECL { -namespace gpu { - -/// Type aliases to the address spaces used by the AMDGPU backend. -template <typename T> using Private = [[clang::opencl_private]] T; -template <typename T> using Constant = [[clang::opencl_constant]] T; -template <typename T> using Local = [[clang::opencl_local]] T; -template <typename T> using Global = [[clang::opencl_global]] T; - -/// Returns the number of workgroups in the 'x' dimension of the grid. -LIBC_INLINE uint32_t get_num_blocks_x() { - return __builtin_amdgcn_grid_size_x() / __builtin_amdgcn_workgroup_size_x(); -} - -/// Returns the number of workgroups in the 'y' dimension of the grid. -LIBC_INLINE uint32_t get_num_blocks_y() { - return __builtin_amdgcn_grid_size_y() / __builtin_amdgcn_workgroup_size_y(); -} - -/// Returns the number of workgroups in the 'z' dimension of the grid. -LIBC_INLINE uint32_t get_num_blocks_z() { - return __builtin_amdgcn_grid_size_z() / __builtin_amdgcn_workgroup_size_z(); -} - -/// Returns the total number of workgruops in the grid. -LIBC_INLINE uint64_t get_num_blocks() { - return get_num_blocks_x() * get_num_blocks_y() * get_num_blocks_z(); -} - -/// Returns the 'x' dimension of the current AMD workgroup's id. -LIBC_INLINE uint32_t get_block_id_x() { - return __builtin_amdgcn_workgroup_id_x(); -} - -/// Returns the 'y' dimension of the current AMD workgroup's id. -LIBC_INLINE uint32_t get_block_id_y() { - return __builtin_amdgcn_workgroup_id_y(); -} - -/// Returns the 'z' dimension of the current AMD workgroup's id. -LIBC_INLINE uint32_t get_block_id_z() { - return __builtin_amdgcn_workgroup_id_z(); -} - -/// Returns the absolute id of the AMD workgroup. -LIBC_INLINE uint64_t get_block_id() { - return get_block_id_x() + get_num_blocks_x() * get_block_id_y() + - get_num_blocks_x() * get_num_blocks_y() * get_block_id_z(); -} - -/// Returns the number of workitems in the 'x' dimension. -LIBC_INLINE uint32_t get_num_threads_x() { - return __builtin_amdgcn_workgroup_size_x(); -} - -/// Returns the number of workitems in the 'y' dimension. -LIBC_INLINE uint32_t get_num_threads_y() { - return __builtin_amdgcn_workgroup_size_y(); -} - -/// Returns the number of workitems in the 'z' dimension. -LIBC_INLINE uint32_t get_num_threads_z() { - return __builtin_amdgcn_workgroup_size_z(); -} - -/// Returns the total number of workitems in the workgroup. -LIBC_INLINE uint64_t get_num_threads() { - return get_num_threads_x() * get_num_threads_y() * get_num_threads_z(); -} - -/// Returns the 'x' dimension id of the workitem in the current AMD workgroup. -LIBC_INLINE uint32_t get_thread_id_x() { - return __builtin_amdgcn_workitem_id_x(); -} - -/// Returns the 'y' dimension id of the workitem in the current AMD workgroup. -LIBC_INLINE uint32_t get_thread_id_y() { - return __builtin_amdgcn_workitem_id_y(); -} - -/// Returns the 'z' dimension id of the workitem in the current AMD workgroup. -LIBC_INLINE uint32_t get_thread_id_z() { - return __builtin_amdgcn_workitem_id_z(); -} - -/// Returns the absolute id of the thread in the current AMD workgroup. -LIBC_INLINE uint64_t get_thread_id() { - return get_thread_id_x() + get_num_threads_x() * get_thread_id_y() + - get_num_threads_x() * get_num_threads_y() * get_thread_id_z(); -} - -/// Returns the size of an AMD wavefront, either 32 or 64 depending on hardware -/// and compilation options. -LIBC_INLINE uint32_t get_lane_size() { - return __builtin_amdgcn_wavefrontsize(); -} - -/// Returns the id of the thread inside of an AMD wavefront executing together. -[[clang::convergent]] LIBC_INLINE uint32_t get_lane_id() { - return __builtin_amdgcn_mbcnt_hi(~0u, __builtin_amdgcn_mbcnt_lo(~0u, 0u)); -} - -/// Returns the bit-mask of active threads in the current wavefront. -[[clang::convergent]] LIBC_INLINE uint64_t get_lane_mask() { - return __builtin_amdgcn_read_exec(); -} - -/// Copies the value from the first active thread in the wavefront to the rest. -[[clang::convergent]] LIBC_INLINE uint32_t broadcast_value(uint64_t, - uint32_t x) { - return __builtin_amdgcn_readfirstlane(x); -} - -/// Returns a bitmask of threads in the current lane for which \p x is true. -[[clang::convergent]] LIBC_INLINE uint64_t ballot(uint64_t lane_mask, bool x) { - // the lane_mask & gives the nvptx semantics when lane_mask is a subset of - // the active threads - return lane_mask & __builtin_amdgcn_ballot_w64(x); -} - -/// Waits for all the threads in the block to converge and issues a fence. -[[clang::convergent]] LIBC_INLINE void sync_threads() { - __builtin_amdgcn_s_barrier(); - __builtin_amdgcn_fence(__ATOMIC_ACQUIRE, "workgroup"); -} - -/// Waits for all pending memory operations to complete in program order. -[[clang::convergent]] LIBC_INLINE void memory_fence() { - __builtin_amdgcn_fence(__ATOMIC_ACQ_REL, ""); -} - -/// Wait for all threads in the wavefront to converge, this is a noop on AMDGPU. -[[clang::convergent]] LIBC_INLINE void sync_lane(uint64_t) { - __builtin_amdgcn_wave_barrier(); -} - -/// Shuffles the the lanes inside the wavefront according to the given index. -[[clang::convergent]] LIBC_INLINE uint32_t shuffle(uint64_t, uint32_t idx, - uint32_t x) { - return __builtin_amdgcn_ds_bpermute(idx << 2, x); -} - -/// Returns the current value of the GPU's processor clock. -/// NOTE: The RDNA3 and RDNA2 architectures use a 20-bit cycle counter. -LIBC_INLINE uint64_t processor_clock() { return __builtin_readcyclecounter(); } - -/// Returns a fixed-frequency timestamp. The actual frequency is dependent on -/// the card and can only be queried via the driver. -LIBC_INLINE uint64_t fixed_frequency_clock() { - return __builtin_readsteadycounter(); -} - -/// Terminates execution of the associated wavefront. -[[noreturn]] LIBC_INLINE void end_program() { __builtin_amdgcn_endpgm(); } - -/// Returns a unique identifier for the process cluster the current wavefront is -/// executing on. Here we use the identifier for the compute unit (CU) and -/// shader engine. -/// FIXME: Currently unimplemented on AMDGPU until we have a simpler interface -/// than the one at -/// https://github.com/ROCm/clr/blob/develop/hipamd/include/hip/amd_detail/amd_device_functions.h#L899 -LIBC_INLINE uint32_t get_cluster_id() { return 0; } - -} // namespace gpu -} // namespace LIBC_NAMESPACE_DECL - -#endif diff --git a/libc/src/__support/GPU/generic/CMakeLists.txt b/libc/src/__support/GPU/generic/CMakeLists.txt deleted file mode 100644 index 68ba7d1..0000000 --- a/libc/src/__support/GPU/generic/CMakeLists.txt +++ /dev/null @@ -1,7 +0,0 @@ -add_header_library( - generic_utils - HDRS - utils.h - DEPENDS - libc.src.__support.common -) diff --git a/libc/src/__support/GPU/generic/utils.h b/libc/src/__support/GPU/generic/utils.h deleted file mode 100644 index 9461ef0..0000000 --- a/libc/src/__support/GPU/generic/utils.h +++ /dev/null @@ -1,84 +0,0 @@ -//===-------------- Generic implementation of GPU utils ---------*- 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___SUPPORT_GPU_GENERIC_UTILS_H -#define LLVM_LIBC_SRC___SUPPORT_GPU_GENERIC_UTILS_H - -#include "src/__support/common.h" -#include "src/__support/macros/config.h" - -#include <stdint.h> - -namespace LIBC_NAMESPACE_DECL { -namespace gpu { - -template <typename T> using Private = T; -template <typename T> using Constant = T; -template <typename T> using Shared = T; -template <typename T> using Global = T; - -LIBC_INLINE uint32_t get_num_blocks_x() { return 1; } - -LIBC_INLINE uint32_t get_num_blocks_y() { return 1; } - -LIBC_INLINE uint32_t get_num_blocks_z() { return 1; } - -LIBC_INLINE uint64_t get_num_blocks() { return 1; } - -LIBC_INLINE uint32_t get_block_id_x() { return 0; } - -LIBC_INLINE uint32_t get_block_id_y() { return 0; } - -LIBC_INLINE uint32_t get_block_id_z() { return 0; } - -LIBC_INLINE uint64_t get_block_id() { return 0; } - -LIBC_INLINE uint32_t get_num_threads_x() { return 1; } - -LIBC_INLINE uint32_t get_num_threads_y() { return 1; } - -LIBC_INLINE uint32_t get_num_threads_z() { return 1; } - -LIBC_INLINE uint64_t get_num_threads() { return 1; } - -LIBC_INLINE uint32_t get_thread_id_x() { return 0; } - -LIBC_INLINE uint32_t get_thread_id_y() { return 0; } - -LIBC_INLINE uint32_t get_thread_id_z() { return 0; } - -LIBC_INLINE uint64_t get_thread_id() { return 0; } - -LIBC_INLINE uint32_t get_lane_size() { return 1; } - -LIBC_INLINE uint32_t get_lane_id() { return 0; } - -LIBC_INLINE uint64_t get_lane_mask() { return 1; } - -LIBC_INLINE uint32_t broadcast_value(uint64_t, uint32_t x) { return x; } - -LIBC_INLINE uint64_t ballot(uint64_t, bool x) { return x; } - -LIBC_INLINE void sync_threads() {} - -LIBC_INLINE void sync_lane(uint64_t) {} - -LIBC_INLINE uint32_t shuffle(uint64_t, uint32_t, uint32_t x) { return x; } - -LIBC_INLINE uint64_t processor_clock() { return 0; } - -LIBC_INLINE uint64_t fixed_frequency_clock() { return 0; } - -[[noreturn]] LIBC_INLINE void end_program() { __builtin_unreachable(); } - -LIBC_INLINE uint32_t get_cluster_id() { return 0; } - -} // namespace gpu -} // namespace LIBC_NAMESPACE_DECL - -#endif // LLVM_LIBC_SRC___SUPPORT_GPU_GENERIC_UTILS_H diff --git a/libc/src/__support/GPU/nvptx/CMakeLists.txt b/libc/src/__support/GPU/nvptx/CMakeLists.txt deleted file mode 100644 index 0d3f8c7..0000000 --- a/libc/src/__support/GPU/nvptx/CMakeLists.txt +++ /dev/null @@ -1,7 +0,0 @@ -add_header_library( - nvptx_utils - HDRS - utils.h - DEPENDS - libc.src.__support.common -) diff --git a/libc/src/__support/GPU/nvptx/utils.h b/libc/src/__support/GPU/nvptx/utils.h deleted file mode 100644 index 1a43a83..0000000 --- a/libc/src/__support/GPU/nvptx/utils.h +++ /dev/null @@ -1,160 +0,0 @@ -//===-------------- NVPTX implementation of GPU utils -----------*- 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-id: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_LIBC_SRC___SUPPORT_GPU_NVPTX_IO_H -#define LLVM_LIBC_SRC___SUPPORT_GPU_NVPTX_IO_H - -#include "src/__support/common.h" -#include "src/__support/macros/config.h" - -#include <stdint.h> - -namespace LIBC_NAMESPACE_DECL { -namespace gpu { - -/// Type aliases to the address spaces used by the NVPTX backend. -template <typename T> using Private = [[clang::opencl_private]] T; -template <typename T> using Constant = [[clang::opencl_constant]] T; -template <typename T> using Local = [[clang::opencl_local]] T; -template <typename T> using Global = [[clang::opencl_global]] T; - -/// Returns the number of CUDA blocks in the 'x' dimension. -LIBC_INLINE uint32_t get_num_blocks_x() { - return __nvvm_read_ptx_sreg_nctaid_x(); -} - -/// Returns the number of CUDA blocks in the 'y' dimension. -LIBC_INLINE uint32_t get_num_blocks_y() { - return __nvvm_read_ptx_sreg_nctaid_y(); -} - -/// Returns the number of CUDA blocks in the 'z' dimension. -LIBC_INLINE uint32_t get_num_blocks_z() { - return __nvvm_read_ptx_sreg_nctaid_z(); -} - -/// Returns the total number of CUDA blocks. -LIBC_INLINE uint64_t get_num_blocks() { - return get_num_blocks_x() * get_num_blocks_y() * get_num_blocks_z(); -} - -/// Returns the 'x' dimension of the current CUDA block's id. -LIBC_INLINE uint32_t get_block_id_x() { return __nvvm_read_ptx_sreg_ctaid_x(); } - -/// Returns the 'y' dimension of the current CUDA block's id. -LIBC_INLINE uint32_t get_block_id_y() { return __nvvm_read_ptx_sreg_ctaid_y(); } - -/// Returns the 'z' dimension of the current CUDA block's id. -LIBC_INLINE uint32_t get_block_id_z() { return __nvvm_read_ptx_sreg_ctaid_z(); } - -/// Returns the absolute id of the CUDA block. -LIBC_INLINE uint64_t get_block_id() { - return get_block_id_x() + get_num_blocks_x() * get_block_id_y() + - get_num_blocks_x() * get_num_blocks_y() * get_block_id_z(); -} - -/// Returns the number of CUDA threads in the 'x' dimension. -LIBC_INLINE uint32_t get_num_threads_x() { - return __nvvm_read_ptx_sreg_ntid_x(); -} - -/// Returns the number of CUDA threads in the 'y' dimension. -LIBC_INLINE uint32_t get_num_threads_y() { - return __nvvm_read_ptx_sreg_ntid_y(); -} - -/// Returns the number of CUDA threads in the 'z' dimension. -LIBC_INLINE uint32_t get_num_threads_z() { - return __nvvm_read_ptx_sreg_ntid_z(); -} - -/// Returns the total number of threads in the block. -LIBC_INLINE uint64_t get_num_threads() { - return get_num_threads_x() * get_num_threads_y() * get_num_threads_z(); -} - -/// Returns the 'x' dimension id of the thread in the current CUDA block. -LIBC_INLINE uint32_t get_thread_id_x() { return __nvvm_read_ptx_sreg_tid_x(); } - -/// Returns the 'y' dimension id of the thread in the current CUDA block. -LIBC_INLINE uint32_t get_thread_id_y() { return __nvvm_read_ptx_sreg_tid_y(); } - -/// Returns the 'z' dimension id of the thread in the current CUDA block. -LIBC_INLINE uint32_t get_thread_id_z() { return __nvvm_read_ptx_sreg_tid_z(); } - -/// Returns the absolute id of the thread in the current CUDA block. -LIBC_INLINE uint64_t get_thread_id() { - return get_thread_id_x() + get_num_threads_x() * get_thread_id_y() + - get_num_threads_x() * get_num_threads_y() * get_thread_id_z(); -} - -/// Returns the size of a CUDA warp, always 32 on NVIDIA hardware. -LIBC_INLINE uint32_t get_lane_size() { return 32; } - -/// Returns the id of the thread inside of a CUDA warp executing together. -[[clang::convergent]] LIBC_INLINE uint32_t get_lane_id() { - return __nvvm_read_ptx_sreg_laneid(); -} - -/// Returns the bit-mask of active threads in the current warp. -[[clang::convergent]] LIBC_INLINE uint64_t get_lane_mask() { - return __nvvm_activemask(); -} - -/// Copies the value from the first active thread in the warp to the rest. -[[clang::convergent]] LIBC_INLINE uint32_t broadcast_value(uint64_t lane_mask, - uint32_t x) { - uint32_t mask = static_cast<uint32_t>(lane_mask); - uint32_t id = __builtin_ffs(mask) - 1; - return __nvvm_shfl_sync_idx_i32(mask, x, id, get_lane_size() - 1); -} - -/// Returns a bitmask of threads in the current lane for which \p x is true. -[[clang::convergent]] LIBC_INLINE uint64_t ballot(uint64_t lane_mask, bool x) { - uint32_t mask = static_cast<uint32_t>(lane_mask); - return __nvvm_vote_ballot_sync(mask, x); -} - -/// Waits for all the threads in the block to converge and issues a fence. -[[clang::convergent]] LIBC_INLINE void sync_threads() { __syncthreads(); } - -/// Waits for all pending memory operations to complete in program order. -[[clang::convergent]] LIBC_INLINE void memory_fence() { __nvvm_membar_sys(); } - -/// Waits for all threads in the warp to reconverge for independent scheduling. -[[clang::convergent]] LIBC_INLINE void sync_lane(uint64_t mask) { - __nvvm_bar_warp_sync(static_cast<uint32_t>(mask)); -} - -/// Shuffles the the lanes inside the warp according to the given index. -[[clang::convergent]] LIBC_INLINE uint32_t shuffle(uint64_t lane_mask, - uint32_t idx, uint32_t x) { - uint32_t mask = static_cast<uint32_t>(lane_mask); - uint32_t bitmask = (mask >> idx) & 1; - return -bitmask & __nvvm_shfl_sync_idx_i32(mask, x, idx, get_lane_size() - 1); -} - -/// Returns the current value of the GPU's processor clock. -LIBC_INLINE uint64_t processor_clock() { return __builtin_readcyclecounter(); } - -/// Returns a global fixed-frequency timer at nanosecond frequency. -LIBC_INLINE uint64_t fixed_frequency_clock() { - return __builtin_readsteadycounter(); -} - -/// Terminates execution of the calling thread. -[[noreturn]] LIBC_INLINE void end_program() { __nvvm_exit(); } - -/// Returns a unique identifier for the process cluster the current warp is -/// executing on. Here we use the identifier for the symmetric multiprocessor. -LIBC_INLINE uint32_t get_cluster_id() { return __nvvm_read_ptx_sreg_smid(); } - -} // namespace gpu -} // namespace LIBC_NAMESPACE_DECL - -#endif diff --git a/libc/src/__support/GPU/utils.h b/libc/src/__support/GPU/utils.h index ae52e7a..e138c84 100644 --- a/libc/src/__support/GPU/utils.h +++ b/libc/src/__support/GPU/utils.h @@ -9,48 +9,108 @@ #ifndef LLVM_LIBC_SRC___SUPPORT_GPU_UTILS_H #define LLVM_LIBC_SRC___SUPPORT_GPU_UTILS_H +#include "src/__support/macros/attributes.h" #include "src/__support/macros/config.h" #include "src/__support/macros/properties/architectures.h" -#if defined(LIBC_TARGET_ARCH_IS_AMDGPU) -#include "amdgpu/utils.h" -#elif defined(LIBC_TARGET_ARCH_IS_NVPTX) -#include "nvptx/utils.h" -#else -#include "generic/utils.h" +#if !__has_include(<gpuintrin.h>) +#error "Unsupported compiler" #endif +#include <gpuintrin.h> + namespace LIBC_NAMESPACE_DECL { namespace gpu { -/// Get the first active thread inside the lane. -LIBC_INLINE uint64_t get_first_lane_id(uint64_t lane_mask) { - return __builtin_ffsll(lane_mask) - 1; + +template <typename T> using Private = __gpu_private T; +template <typename T> using Constant = __gpu_constant T; +template <typename T> using Local = __gpu_local T; +template <typename T> using Global = __gpu_local T; + +LIBC_INLINE uint32_t get_num_blocks_x() { return __gpu_num_blocks(0); } + +LIBC_INLINE uint32_t get_num_blocks_y() { return __gpu_num_blocks(1); } + +LIBC_INLINE uint32_t get_num_blocks_z() { return __gpu_num_blocks(2); } + +LIBC_INLINE uint64_t get_num_blocks() { + return get_num_blocks_x() * get_num_blocks_y() * get_num_blocks_z(); +} + +LIBC_INLINE uint32_t get_block_id_x() { return __gpu_block_id(0); } + +LIBC_INLINE uint32_t get_block_id_y() { return __gpu_block_id(1); } + +LIBC_INLINE uint32_t get_block_id_z() { return __gpu_block_id(2); } + +LIBC_INLINE uint64_t get_block_id() { + return get_block_id_x() + get_num_blocks_x() * get_block_id_y() + + get_num_blocks_x() * get_num_blocks_y() * get_block_id_z(); +} + +LIBC_INLINE uint32_t get_num_threads_x() { return __gpu_num_threads(0); } + +LIBC_INLINE uint32_t get_num_threads_y() { return __gpu_num_threads(1); } + +LIBC_INLINE uint32_t get_num_threads_z() { return __gpu_num_threads(2); } + +LIBC_INLINE uint64_t get_num_threads() { + return get_num_threads_x() * get_num_threads_y() * get_num_threads_z(); +} + +LIBC_INLINE uint32_t get_thread_id_x() { return __gpu_thread_id(0); } + +LIBC_INLINE uint32_t get_thread_id_y() { return __gpu_thread_id(1); } + +LIBC_INLINE uint32_t get_thread_id_z() { return __gpu_thread_id(2); } + +LIBC_INLINE uint64_t get_thread_id() { + return get_thread_id_x() + get_num_threads_x() * get_thread_id_y() + + get_num_threads_x() * get_num_threads_y() * get_thread_id_z(); +} + +LIBC_INLINE uint32_t get_lane_size() { return __gpu_num_lanes(); } + +LIBC_INLINE uint32_t get_lane_id() { return __gpu_lane_id(); } + +LIBC_INLINE uint64_t get_lane_mask() { return __gpu_lane_mask(); } + +LIBC_INLINE uint32_t broadcast_value(uint64_t lane_mask, uint32_t x) { + return __gpu_read_first_lane_u32(lane_mask, x); +} + +LIBC_INLINE uint64_t ballot(uint64_t lane_mask, bool x) { + return __gpu_ballot(lane_mask, x); +} + +LIBC_INLINE void sync_threads() { __gpu_sync_threads(); } + +LIBC_INLINE void sync_lane(uint64_t lane_mask) { __gpu_sync_lane(lane_mask); } + +LIBC_INLINE uint32_t shuffle(uint64_t lane_mask, uint32_t idx, uint32_t x) { + return __gpu_shuffle_idx_u32(lane_mask, idx, x); } -/// Conditional that is only true for a single thread in a lane. +[[noreturn]] LIBC_INLINE void end_program() { __gpu_exit(); } + LIBC_INLINE bool is_first_lane(uint64_t lane_mask) { - return gpu::get_lane_id() == get_first_lane_id(lane_mask); + return __gpu_is_first_in_lane(lane_mask); } -/// Gets the sum of all lanes inside the warp or wavefront. LIBC_INLINE uint32_t reduce(uint64_t lane_mask, uint32_t x) { - for (uint32_t step = gpu::get_lane_size() / 2; step > 0; step /= 2) { - uint32_t index = step + gpu::get_lane_id(); - x += gpu::shuffle(lane_mask, index, x); - } - return gpu::broadcast_value(lane_mask, x); + return __gpu_lane_sum_u32(lane_mask, x); } -/// Gets the accumulator scan of the threads in the warp or wavefront. LIBC_INLINE uint32_t scan(uint64_t lane_mask, uint32_t x) { - for (uint32_t step = 1; step < gpu::get_lane_size(); step *= 2) { - uint32_t index = gpu::get_lane_id() - step; - uint32_t bitmask = gpu::get_lane_id() >= step; - x += -bitmask & gpu::shuffle(lane_mask, index, x); - } - return x; + return __gpu_lane_scan_u32(lane_mask, x); +} + +LIBC_INLINE uint64_t fixed_frequency_clock() { + return __builtin_readsteadycounter(); } +LIBC_INLINE uint64_t processor_clock() { return __builtin_readcyclecounter(); } + } // namespace gpu } // namespace LIBC_NAMESPACE_DECL diff --git a/libc/src/__support/fixedvector.h b/libc/src/__support/fixedvector.h index 7ac0c23..34601f8 100644 --- a/libc/src/__support/fixedvector.h +++ b/libc/src/__support/fixedvector.h @@ -10,9 +10,10 @@ #define LLVM_LIBC_SRC___SUPPORT_FIXEDVECTOR_H #include "src/__support/CPP/array.h" - #include "src/__support/CPP/iterator.h" +#include "src/__support/libc_assert.h" #include "src/__support/macros/config.h" +#include "src/string/memory_utils/inline_memset.h" namespace LIBC_NAMESPACE_DECL { @@ -23,27 +24,32 @@ template <typename T, size_t CAPACITY> class FixedVector { size_t item_count = 0; public: - constexpr FixedVector() = default; + LIBC_INLINE constexpr FixedVector() = default; using iterator = typename cpp::array<T, CAPACITY>::iterator; - constexpr FixedVector(iterator begin, iterator end) : store{}, item_count{} { + LIBC_INLINE constexpr FixedVector(iterator begin, iterator end) + : store{}, item_count{} { + LIBC_ASSERT(begin + CAPACITY >= end); for (; begin != end; ++begin) push_back(*begin); } using const_iterator = typename cpp::array<T, CAPACITY>::const_iterator; - constexpr FixedVector(const_iterator begin, const_iterator end) + LIBC_INLINE constexpr FixedVector(const_iterator begin, const_iterator end) : store{}, item_count{} { + LIBC_ASSERT(begin + CAPACITY >= end); for (; begin != end; ++begin) push_back(*begin); } - constexpr FixedVector(size_t count, const T &value) : store{}, item_count{} { + LIBC_INLINE constexpr FixedVector(size_t count, const T &value) + : store{}, item_count{} { + LIBC_ASSERT(count <= CAPACITY); for (size_t i = 0; i < count; ++i) push_back(value); } - constexpr bool push_back(const T &obj) { + LIBC_INLINE constexpr bool push_back(const T &obj) { if (item_count == CAPACITY) return false; store[item_count] = obj; @@ -51,27 +57,43 @@ public: return true; } - constexpr const T &back() const { return store[item_count - 1]; } + LIBC_INLINE constexpr const T &back() const { + LIBC_ASSERT(!empty()); + return store[item_count - 1]; + } - constexpr T &back() { return store[item_count - 1]; } + LIBC_INLINE constexpr T &back() { + LIBC_ASSERT(!empty()); + return store[item_count - 1]; + } - constexpr bool pop_back() { + LIBC_INLINE constexpr bool pop_back() { if (item_count == 0) return false; + inline_memset(&store[item_count - 1], 0, sizeof(T)); --item_count; return true; } - constexpr T &operator[](size_t idx) { return store[idx]; } + LIBC_INLINE constexpr T &operator[](size_t idx) { + LIBC_ASSERT(idx < item_count); + return store[idx]; + } - constexpr const T &operator[](size_t idx) const { return store[idx]; } + LIBC_INLINE constexpr const T &operator[](size_t idx) const { + LIBC_ASSERT(idx < item_count); + return store[idx]; + } - constexpr bool empty() const { return item_count == 0; } + LIBC_INLINE constexpr bool empty() const { return item_count == 0; } - constexpr size_t size() const { return item_count; } + LIBC_INLINE constexpr size_t size() const { return item_count; } // Empties the store for all practical purposes. - constexpr void reset() { item_count = 0; } + LIBC_INLINE constexpr void reset() { + inline_memset(store.data(), 0, sizeof(T) * item_count); + item_count = 0; + } // This static method does not free up the resources held by |store|, // say by calling `free` or something similar. It just does the equivalent @@ -81,7 +103,9 @@ public: // dynamically allocated storate. So, the `destroy` method like this // matches the `destroy` API of those other data structures so that users // can easily swap one data structure for the other. - static void destroy(FixedVector<T, CAPACITY> *store) { store->reset(); } + LIBC_INLINE static void destroy(FixedVector<T, CAPACITY> *store) { + store->reset(); + } using reverse_iterator = typename cpp::array<T, CAPACITY>::reverse_iterator; LIBC_INLINE constexpr reverse_iterator rbegin() { diff --git a/libc/src/__support/threads/thread.cpp b/libc/src/__support/threads/thread.cpp index dad4f75..6f6b75b 100644 --- a/libc/src/__support/threads/thread.cpp +++ b/libc/src/__support/threads/thread.cpp @@ -117,7 +117,9 @@ public: int add_callback(AtExitCallback *callback, void *obj) { cpp::lock_guard lock(mtx); - return callback_list.push_back({callback, obj}); + if (callback_list.push_back({callback, obj})) + return 0; + return -1; } void call() { diff --git a/libc/src/compiler/generic/__stack_chk_fail.cpp b/libc/src/compiler/generic/__stack_chk_fail.cpp index c76ec14..00e976a 100644 --- a/libc/src/compiler/generic/__stack_chk_fail.cpp +++ b/libc/src/compiler/generic/__stack_chk_fail.cpp @@ -9,9 +9,12 @@ #include "src/compiler/__stack_chk_fail.h" #include "src/__support/OSUtil/io.h" #include "src/stdlib/abort.h" +#include <stdint.h> // For uintptr_t extern "C" { +uintptr_t __stack_chk_guard = static_cast<uintptr_t>(0xa9fff01234); + void __stack_chk_fail(void) { LIBC_NAMESPACE::write_to_stderr("stack smashing detected\n"); LIBC_NAMESPACE::abort(); diff --git a/libc/src/math/docs/add_math_function.md b/libc/src/math/docs/add_math_function.md index f02d502..daaf1a3 100644 --- a/libc/src/math/docs/add_math_function.md +++ b/libc/src/math/docs/add_math_function.md @@ -18,7 +18,7 @@ together with its specifications: ``` - Add function specs to the file: ``` - libc/hdrgen/yaml/math.yaml + libc/include/math.yaml ``` ## Implementation diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt index b3d4612..382f5b3 100644 --- a/libc/src/math/generic/CMakeLists.txt +++ b/libc/src/math/generic/CMakeLists.txt @@ -358,7 +358,6 @@ add_header_library( HDRS sincosf16_utils.h DEPENDS - libc.src.__support.FPUtil.fp_bits libc.src.__support.FPUtil.polyeval libc.src.__support.FPUtil.nearest_integer libc.src.__support.common @@ -1702,8 +1701,6 @@ add_header_library( libc.src.__support.FPUtil.fenv_impl libc.src.__support.FPUtil.fp_bits libc.src.__support.FPUtil.multiply_add - libc.src.__support.FPUtil.nearest_integer - libc.src.__support.FPUtil.polyeval libc.src.__support.FPUtil.rounding_mode libc.src.__support.macros.optimization libc.src.__support.common diff --git a/libc/src/math/generic/exp10f_impl.h b/libc/src/math/generic/exp10f_impl.h index d741318..975fd01 100644 --- a/libc/src/math/generic/exp10f_impl.h +++ b/libc/src/math/generic/exp10f_impl.h @@ -10,12 +10,9 @@ #define LLVM_LIBC_SRC_MATH_GENERIC_EXP10F_IMPL_H #include "explogxf.h" -#include "src/__support/FPUtil/BasicOperations.h" #include "src/__support/FPUtil/FEnvImpl.h" #include "src/__support/FPUtil/FPBits.h" -#include "src/__support/FPUtil/PolyEval.h" #include "src/__support/FPUtil/multiply_add.h" -#include "src/__support/FPUtil/nearest_integer.h" #include "src/__support/FPUtil/rounding_mode.h" #include "src/__support/common.h" #include "src/__support/macros/config.h" diff --git a/libc/src/math/generic/range_reduction_double_common.h b/libc/src/math/generic/range_reduction_double_common.h index bcab82f..06aeb49 100644 --- a/libc/src/math/generic/range_reduction_double_common.h +++ b/libc/src/math/generic/range_reduction_double_common.h @@ -9,7 +9,6 @@ #ifndef LLVM_LIBC_SRC_MATH_GENERIC_RANGE_REDUCTION_DOUBLE_COMMON_H #define LLVM_LIBC_SRC_MATH_GENERIC_RANGE_REDUCTION_DOUBLE_COMMON_H -#include "src/__support/FPUtil/FPBits.h" #include "src/__support/FPUtil/double_double.h" #include "src/__support/FPUtil/dyadic_float.h" #include "src/__support/FPUtil/multiply_add.h" diff --git a/libc/src/math/generic/sincosf16_utils.h b/libc/src/math/generic/sincosf16_utils.h index 5e5edd4..87b1dde 100644 --- a/libc/src/math/generic/sincosf16_utils.h +++ b/libc/src/math/generic/sincosf16_utils.h @@ -9,9 +9,7 @@ #ifndef LLVM_LIBC_SRC_MATH_GENERIC_SINCOSF16_UTILS_H #define LLVM_LIBC_SRC_MATH_GENERIC_SINCOSF16_UTILS_H -#include "src/__support/FPUtil/FPBits.h" #include "src/__support/FPUtil/PolyEval.h" -#include "src/__support/FPUtil/cast.h" #include "src/__support/FPUtil/nearest_integer.h" #include "src/__support/common.h" #include "src/__support/macros/config.h" diff --git a/libc/src/pthread/pthread_condattr_init.cpp b/libc/src/pthread/pthread_condattr_init.cpp index 12005b8..b360804 100644 --- a/libc/src/pthread/pthread_condattr_init.cpp +++ b/libc/src/pthread/pthread_condattr_init.cpp @@ -11,8 +11,8 @@ #include "src/__support/common.h" #include "src/__support/macros/config.h" -#include <pthread.h> // pthread_condattr_t, PTHREAD_PROCESS_PRIVATE -#include <time.h> // CLOCK_REALTIME +#include "hdr/time_macros.h" // CLOCK_REALTIME +#include <pthread.h> // pthread_condattr_t, PTHREAD_PROCESS_PRIVATE namespace LIBC_NAMESPACE_DECL { diff --git a/libc/src/pthread/pthread_condattr_setclock.cpp b/libc/src/pthread/pthread_condattr_setclock.cpp index 37fbd6b..5e825d5 100644 --- a/libc/src/pthread/pthread_condattr_setclock.cpp +++ b/libc/src/pthread/pthread_condattr_setclock.cpp @@ -12,9 +12,9 @@ #include "src/__support/macros/config.h" #include "src/errno/libc_errno.h" -#include <pthread.h> // pthread_condattr_t -#include <sys/types.h> // clockid_t -#include <time.h> // CLOCK_MONOTONIC, CLOCK_REALTIME +#include "hdr/time_macros.h" // CLOCK_MONOTONIC, CLOCK_REALTIME +#include <pthread.h> // pthread_condattr_t +#include <sys/types.h> // clockid_t namespace LIBC_NAMESPACE_DECL { diff --git a/libc/src/stdlib/exit_handler.h b/libc/src/stdlib/exit_handler.h index 9720c54..e9d163d 100644 --- a/libc/src/stdlib/exit_handler.h +++ b/libc/src/stdlib/exit_handler.h @@ -48,7 +48,7 @@ LIBC_INLINE void stdc_at_exit_func(void *payload) { LIBC_INLINE void call_exit_callbacks(ExitCallbackList &callbacks) { handler_list_mtx.lock(); while (!callbacks.empty()) { - AtExitUnit &unit = callbacks.back(); + AtExitUnit unit = callbacks.back(); callbacks.pop_back(); handler_list_mtx.unlock(); unit.callback(unit.payload); diff --git a/libc/src/stdlib/heap_sort.h b/libc/src/stdlib/heap_sort.h index ccb9ec5..b969977 100644 --- a/libc/src/stdlib/heap_sort.h +++ b/libc/src/stdlib/heap_sort.h @@ -18,11 +18,12 @@ namespace internal { // A simple in-place heapsort implementation. // Follow the implementation in https://en.wikipedia.org/wiki/Heapsort. -LIBC_INLINE void heap_sort(const Array &array) { - size_t end = array.size(); +template <typename A, typename F> +LIBC_INLINE void heap_sort(const A &array, const F &is_less) { + size_t end = array.len(); size_t start = end / 2; - auto left_child = [](size_t i) -> size_t { return 2 * i + 1; }; + const auto left_child = [](size_t i) -> size_t { return 2 * i + 1; }; while (end > 1) { if (start > 0) { @@ -40,12 +41,11 @@ LIBC_INLINE void heap_sort(const Array &array) { while (left_child(root) < end) { size_t child = left_child(root); // If there are two children, set child to the greater. - if (child + 1 < end && - array.elem_compare(child, array.get(child + 1)) < 0) + if ((child + 1 < end) && is_less(array.get(child), array.get(child + 1))) ++child; // If the root is less than the greater child - if (array.elem_compare(root, array.get(child)) >= 0) + if (!is_less(array.get(root), array.get(child))) break; // Swap the root with the greater child and continue sifting down. diff --git a/libc/src/stdlib/qsort.cpp b/libc/src/stdlib/qsort.cpp index 65a63c2..0bf5fc7 100644 --- a/libc/src/stdlib/qsort.cpp +++ b/libc/src/stdlib/qsort.cpp @@ -18,14 +18,12 @@ namespace LIBC_NAMESPACE_DECL { LLVM_LIBC_FUNCTION(void, qsort, (void *array, size_t array_size, size_t elem_size, int (*compare)(const void *, const void *))) { - if (array == nullptr || array_size == 0 || elem_size == 0) - return; - internal::Comparator c(compare); - auto arr = internal::Array(reinterpret_cast<uint8_t *>(array), array_size, - elem_size, c); + const auto is_less = [compare](const void *a, const void *b) -> bool { + return compare(a, b) < 0; + }; - internal::sort(arr); + internal::unstable_sort(array, array_size, elem_size, is_less); } } // namespace LIBC_NAMESPACE_DECL diff --git a/libc/src/stdlib/qsort_data.h b/libc/src/stdlib/qsort_data.h index c529d55..aa6d9bb 100644 --- a/libc/src/stdlib/qsort_data.h +++ b/libc/src/stdlib/qsort_data.h @@ -17,91 +17,122 @@ namespace LIBC_NAMESPACE_DECL { namespace internal { -using Compare = int(const void *, const void *); -using CompareWithState = int(const void *, const void *, void *); - -enum class CompType { COMPARE, COMPARE_WITH_STATE }; - -struct Comparator { - union { - Compare *comp_func; - CompareWithState *comp_func_r; - }; - const CompType comp_type; - - void *arg; - - Comparator(Compare *func) - : comp_func(func), comp_type(CompType::COMPARE), arg(nullptr) {} - - Comparator(CompareWithState *func, void *arg_val) - : comp_func_r(func), comp_type(CompType::COMPARE_WITH_STATE), - arg(arg_val) {} - -#if defined(__clang__) - // Recent upstream changes to -fsanitize=function find more instances of - // function type mismatches. One case is with the comparator passed to this - // class. Libraries will tend to pass comparators that take pointers to - // varying types while this comparator expects to accept const void pointers. - // Ideally those tools would pass a function that strictly accepts const - // void*s to avoid UB, or would use qsort_r to pass their own comparator. - [[clang::no_sanitize("function")]] -#endif - int comp_vals(const void *a, const void *b) const { - if (comp_type == CompType::COMPARE) { - return comp_func(a, b); - } else { - return comp_func_r(a, b, arg); +class ArrayGenericSize { + cpp::byte *array_base; + size_t array_len; + size_t elem_size; + + LIBC_INLINE cpp::byte *get_internal(size_t i) const { + return array_base + (i * elem_size); + } + +public: + LIBC_INLINE ArrayGenericSize(void *a, size_t s, size_t e) + : array_base(reinterpret_cast<cpp::byte *>(a)), array_len(s), + elem_size(e) {} + + static constexpr bool has_fixed_size() { return false; } + + LIBC_INLINE void *get(size_t i) const { return get_internal(i); } + + LIBC_INLINE void swap(size_t i, size_t j) const { + // It's possible to use 8 byte blocks with `uint64_t`, but that + // generates more machine code as the remainder loop gets + // unrolled, plus 4 byte operations are more likely to be + // efficient on a wider variety of hardware. On x86 LLVM tends + // to unroll the block loop again into 2 16 byte swaps per + // iteration which is another reason that 4 byte blocks yields + // good performance even for big types. + using block_t = uint32_t; + constexpr size_t BLOCK_SIZE = sizeof(block_t); + + alignas(block_t) cpp::byte tmp_block[BLOCK_SIZE]; + + cpp::byte *elem_i = get_internal(i); + cpp::byte *elem_j = get_internal(j); + + const size_t elem_size_rem = elem_size % BLOCK_SIZE; + const cpp::byte *elem_i_block_end = elem_i + (elem_size - elem_size_rem); + + while (elem_i != elem_i_block_end) { + __builtin_memcpy(tmp_block, elem_i, BLOCK_SIZE); + __builtin_memcpy(elem_i, elem_j, BLOCK_SIZE); + __builtin_memcpy(elem_j, tmp_block, BLOCK_SIZE); + + elem_i += BLOCK_SIZE; + elem_j += BLOCK_SIZE; + } + + for (size_t n = 0; n < elem_size_rem; ++n) { + cpp::byte tmp = elem_i[n]; + elem_i[n] = elem_j[n]; + elem_j[n] = tmp; } } + + LIBC_INLINE size_t len() const { return array_len; } + + // Make an Array starting at index |i| and length |s|. + LIBC_INLINE ArrayGenericSize make_array(size_t i, size_t s) const { + return ArrayGenericSize(get_internal(i), s, elem_size); + } + + // Reset this Array to point at a different interval of the same + // items starting at index |i|. + LIBC_INLINE void reset_bounds(size_t i, size_t s) { + array_base = get_internal(i); + array_len = s; + } }; -class Array { - uint8_t *array; - size_t array_size; - size_t elem_size; - Comparator compare; +// Having a specialized Array type for sorting that knows at +// compile-time what the size of the element is, allows for much more +// efficient swapping and for cheaper offset calculations. +template <size_t ELEM_SIZE> class ArrayFixedSize { + cpp::byte *array_base; + size_t array_len; -public: - Array(uint8_t *a, size_t s, size_t e, Comparator c) - : array(a), array_size(s), elem_size(e), compare(c) {} - - uint8_t *get(size_t i) const { return array + i * elem_size; } - - void swap(size_t i, size_t j) const { - uint8_t *elem_i = get(i); - uint8_t *elem_j = get(j); - for (size_t b = 0; b < elem_size; ++b) { - uint8_t temp = elem_i[b]; - elem_i[b] = elem_j[b]; - elem_j[b] = temp; - } + LIBC_INLINE cpp::byte *get_internal(size_t i) const { + return array_base + (i * ELEM_SIZE); } - int elem_compare(size_t i, const uint8_t *other) const { - // An element must compare equal to itself so we don't need to consult the - // user provided comparator. - if (get(i) == other) - return 0; - return compare.comp_vals(get(i), other); +public: + LIBC_INLINE ArrayFixedSize(void *a, size_t s) + : array_base(reinterpret_cast<cpp::byte *>(a)), array_len(s) {} + + // Beware this function is used a heuristic for cheap to swap types, so + // instantiating `ArrayFixedSize` with `ELEM_SIZE > 100` is probably a bad + // idea perf wise. + static constexpr bool has_fixed_size() { return true; } + + LIBC_INLINE void *get(size_t i) const { return get_internal(i); } + + LIBC_INLINE void swap(size_t i, size_t j) const { + alignas(32) cpp::byte tmp[ELEM_SIZE]; + + cpp::byte *elem_i = get_internal(i); + cpp::byte *elem_j = get_internal(j); + + __builtin_memcpy(tmp, elem_i, ELEM_SIZE); + __builtin_memmove(elem_i, elem_j, ELEM_SIZE); + __builtin_memcpy(elem_j, tmp, ELEM_SIZE); } - size_t size() const { return array_size; } + LIBC_INLINE size_t len() const { return array_len; } - // Make an Array starting at index |i| and size |s|. - LIBC_INLINE Array make_array(size_t i, size_t s) const { - return Array(get(i), s, elem_size, compare); + // Make an Array starting at index |i| and length |s|. + LIBC_INLINE ArrayFixedSize<ELEM_SIZE> make_array(size_t i, size_t s) const { + return ArrayFixedSize<ELEM_SIZE>(get_internal(i), s); } - // Reset this Array to point at a different interval of the same items. - LIBC_INLINE void reset_bounds(uint8_t *a, size_t s) { - array = a; - array_size = s; + // Reset this Array to point at a different interval of the same + // items starting at index |i|. + LIBC_INLINE void reset_bounds(size_t i, size_t s) { + array_base = get_internal(i); + array_len = s; } }; -using SortingRoutine = void(const Array &); - } // namespace internal } // namespace LIBC_NAMESPACE_DECL diff --git a/libc/src/stdlib/qsort_pivot.h b/libc/src/stdlib/qsort_pivot.h new file mode 100644 index 0000000..b27e746 --- /dev/null +++ b/libc/src/stdlib/qsort_pivot.h @@ -0,0 +1,85 @@ +//===-- Implementation header for qsort utilities ---------------*- 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_STDLIB_QSORT_PIVOT_H +#define LLVM_LIBC_SRC_STDLIB_QSORT_PIVOT_H + +#include <stddef.h> // For size_t + +namespace LIBC_NAMESPACE_DECL { +namespace internal { + +// Recursively select a pseudomedian if above this threshold. +constexpr size_t PSEUDO_MEDIAN_REC_THRESHOLD = 64; + +// Selects a pivot from `array`. Algorithm taken from glidesort by Orson Peters. +// +// This chooses a pivot by sampling an adaptive amount of points, approximating +// the quality of a median of sqrt(n) elements. +template <typename A, typename F> +size_t choose_pivot(const A &array, const F &is_less) { + const size_t len = array.len(); + + if (len < 8) { + return 0; + } + + const size_t len_div_8 = len / 8; + + const size_t a = 0; // [0, floor(n/8)) + const size_t b = len_div_8 * 4; // [4*floor(n/8), 5*floor(n/8)) + const size_t c = len_div_8 * 7; // [7*floor(n/8), 8*floor(n/8)) + + if (len < PSEUDO_MEDIAN_REC_THRESHOLD) + return median3(array, a, b, c, is_less); + else + return median3_rec(array, a, b, c, len_div_8, is_less); +} + +// Calculates an approximate median of 3 elements from sections a, b, c, or +// recursively from an approximation of each, if they're large enough. By +// dividing the size of each section by 8 when recursing we have logarithmic +// recursion depth and overall sample from f(n) = 3*f(n/8) -> f(n) = +// O(n^(log(3)/log(8))) ~= O(n^0.528) elements. +template <typename A, typename F> +size_t median3_rec(const A &array, size_t a, size_t b, size_t c, size_t n, + const F &is_less) { + if (n * 8 >= PSEUDO_MEDIAN_REC_THRESHOLD) { + const size_t n8 = n / 8; + a = median3_rec(array, a, a + (n8 * 4), a + (n8 * 7), n8, is_less); + b = median3_rec(array, b, b + (n8 * 4), b + (n8 * 7), n8, is_less); + c = median3_rec(array, c, c + (n8 * 4), c + (n8 * 7), n8, is_less); + } + return median3(array, a, b, c, is_less); +} + +/// Calculates the median of 3 elements. +template <typename A, typename F> +size_t median3(const A &array, size_t a, size_t b, size_t c, const F &is_less) { + const void *a_ptr = array.get(a); + const void *b_ptr = array.get(b); + const void *c_ptr = array.get(c); + + const bool x = is_less(a_ptr, b_ptr); + const bool y = is_less(a_ptr, c_ptr); + if (x == y) { + // If x=y=0 then b, c <= a. In this case we want to return max(b, c). + // If x=y=1 then a < b, c. In this case we want to return min(b, c). + // By toggling the outcome of b < c using XOR x we get this behavior. + const bool z = is_less(b_ptr, c_ptr); + return z ^ x ? c : b; + } else { + // Either c <= a < b or b <= a < c, thus a is our median. + return a; + } +} + +} // namespace internal +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC_STDLIB_QSORT_PIVOT_H diff --git a/libc/src/stdlib/qsort_r.cpp b/libc/src/stdlib/qsort_r.cpp index bf61a40..4e60998 100644 --- a/libc/src/stdlib/qsort_r.cpp +++ b/libc/src/stdlib/qsort_r.cpp @@ -19,13 +19,12 @@ LLVM_LIBC_FUNCTION(void, qsort_r, (void *array, size_t array_size, size_t elem_size, int (*compare)(const void *, const void *, void *), void *arg)) { - if (array == nullptr || array_size == 0 || elem_size == 0) - return; - internal::Comparator c(compare, arg); - auto arr = internal::Array(reinterpret_cast<uint8_t *>(array), array_size, - elem_size, c); - internal::sort(arr); + const auto is_less = [compare, arg](const void *a, const void *b) -> bool { + return compare(a, b, arg) < 0; + }; + + internal::unstable_sort(array, array_size, elem_size, is_less); } } // namespace LIBC_NAMESPACE_DECL diff --git a/libc/src/stdlib/qsort_util.h b/libc/src/stdlib/qsort_util.h index d42adde..7882b82 100644 --- a/libc/src/stdlib/qsort_util.h +++ b/libc/src/stdlib/qsort_util.h @@ -27,11 +27,48 @@ namespace LIBC_NAMESPACE_DECL { namespace internal { -#if LIBC_QSORT_IMPL == LIBC_QSORT_QUICK_SORT -constexpr auto sort = quick_sort; -#elif LIBC_QSORT_IMPL == LIBC_QSORT_HEAP_SORT -constexpr auto sort = heap_sort; -#endif +template <bool USE_QUICKSORT, typename F> +LIBC_INLINE void unstable_sort_impl(void *array, size_t array_len, + size_t elem_size, const F &is_less) { + if (array == nullptr || array_len == 0 || elem_size == 0) + return; + + if constexpr (USE_QUICKSORT) { + switch (elem_size) { + case 4: { + auto arr_fixed_size = internal::ArrayFixedSize<4>(array, array_len); + quick_sort(arr_fixed_size, is_less); + return; + } + case 8: { + auto arr_fixed_size = internal::ArrayFixedSize<8>(array, array_len); + quick_sort(arr_fixed_size, is_less); + return; + } + case 16: { + auto arr_fixed_size = internal::ArrayFixedSize<16>(array, array_len); + quick_sort(arr_fixed_size, is_less); + return; + } + default: + auto arr_generic_size = + internal::ArrayGenericSize(array, array_len, elem_size); + quick_sort(arr_generic_size, is_less); + return; + } + } else { + auto arr_generic_size = + internal::ArrayGenericSize(array, array_len, elem_size); + heap_sort(arr_generic_size, is_less); + } +} + +template <typename F> +LIBC_INLINE void unstable_sort(void *array, size_t array_len, size_t elem_size, + const F &is_less) { +#define USE_QUICK_SORT ((LIBC_QSORT_IMPL) == (LIBC_QSORT_QUICK_SORT)) + unstable_sort_impl<USE_QUICK_SORT, F>(array, array_len, elem_size, is_less); +} } // namespace internal } // namespace LIBC_NAMESPACE_DECL diff --git a/libc/src/stdlib/quick_sort.h b/libc/src/stdlib/quick_sort.h index 82b90a7..9ab2830 100644 --- a/libc/src/stdlib/quick_sort.h +++ b/libc/src/stdlib/quick_sort.h @@ -9,84 +9,175 @@ #ifndef LLVM_LIBC_SRC_STDLIB_QUICK_SORT_H #define LLVM_LIBC_SRC_STDLIB_QUICK_SORT_H -#include "src/__support/macros/attributes.h" +#include "src/__support/CPP/bit.h" +#include "src/__support/CPP/cstddef.h" #include "src/__support/macros/config.h" -#include "src/stdlib/qsort_data.h" +#include "src/stdlib/qsort_pivot.h" #include <stdint.h> namespace LIBC_NAMESPACE_DECL { namespace internal { -// A simple quicksort implementation using the Hoare partition scheme. -LIBC_INLINE size_t partition(const Array &array) { - const size_t array_size = array.size(); - size_t pivot_index = array_size / 2; - uint8_t *pivot = array.get(pivot_index); - size_t i = 0; - size_t j = array_size - 1; +// Branchless Lomuto partition based on the implementation by Lukas +// Bergdoll and Orson Peters +// https://github.com/Voultapher/sort-research-rs/blob/main/writeup/lomcyc_partition/text.md. +// Simplified to avoid having to stack allocate. +template <typename A, typename F> +LIBC_INLINE size_t partition_lomuto_branchless(const A &array, + const void *pivot, + const F &is_less) { + const size_t array_len = array.len(); + + size_t left = 0; + size_t right = 0; + + while (right < array_len) { + const bool right_is_lt = is_less(array.get(right), pivot); + array.swap(left, right); + left += static_cast<size_t>(right_is_lt); + right += 1; + } + + return left; +} + +// Optimized for large types that are expensive to move. Not optimized +// for integers. It's possible to use a cyclic permutation here for +// large types as done in ipnsort but the advantages of this are limited +// as `is_less` is a small wrapper around a call to a function pointer +// and won't incur much binary-size overhead. The other reason to use +// cyclic permutation is to have more efficient swapping, but we don't +// know the element size so this isn't applicable here either. +template <typename A, typename F> +LIBC_INLINE size_t partition_hoare_branchy(const A &array, const void *pivot, + const F &is_less) { + const size_t array_len = array.len(); + + size_t left = 0; + size_t right = array_len; while (true) { - int compare_i, compare_j; - - while ((compare_i = array.elem_compare(i, pivot)) < 0) - ++i; - while ((compare_j = array.elem_compare(j, pivot)) > 0) - --j; - - // At some point i will crossover j so we will definitely break out of - // this while loop. - if (i >= j) - return j + 1; - - array.swap(i, j); - - // The pivot itself might have got swapped so we will update the pivot. - if (i == pivot_index) { - pivot = array.get(j); - pivot_index = j; - } else if (j == pivot_index) { - pivot = array.get(i); - pivot_index = i; + while (left < right && is_less(array.get(left), pivot)) + ++left; + + while (true) { + --right; + if (left >= right || is_less(array.get(right), pivot)) { + break; + } } - if (compare_i == 0 && compare_j == 0) { - // If we do not move the pointers, we will end up with an - // infinite loop as i and j will be stuck without advancing. - ++i; - --j; - } + if (left >= right) + break; + + array.swap(left, right); + ++left; + } + + return left; +} + +template <typename A, typename F> +LIBC_INLINE size_t partition(const A &array, size_t pivot_index, + const F &is_less) { + // Place the pivot at the beginning of the array. + if (pivot_index != 0) { + array.swap(0, pivot_index); } + + const A array_without_pivot = array.make_array(1, array.len() - 1); + const void *pivot = array.get(0); + + size_t num_lt; + if constexpr (A::has_fixed_size()) { + // Branchless Lomuto avoid branch misprediction penalties, but + // it also swaps more often which is only faster if the swap is a fast + // constant operation. + num_lt = partition_lomuto_branchless(array_without_pivot, pivot, is_less); + } else { + num_lt = partition_hoare_branchy(array_without_pivot, pivot, is_less); + } + + // Place the pivot between the two partitions. + array.swap(0, num_lt); + + return num_lt; } -LIBC_INLINE void quick_sort(Array array) { +template <typename A, typename F> +LIBC_INLINE void quick_sort_impl(A &array, const void *ancestor_pivot, + size_t limit, const F &is_less) { while (true) { - const size_t array_size = array.size(); - if (array_size <= 1) + const size_t array_len = array.len(); + if (array_len <= 1) return; - size_t split_index = partition(array); - if (array_size == 2) - // The partition operation sorts the two element array. + + // If too many bad pivot choices were made, simply fall back to + // heapsort in order to guarantee `O(N x log(N))` worst-case. + if (limit == 0) { + heap_sort(array, is_less); return; + } - // Make Arrays describing the two sublists that still need sorting. - Array left = array.make_array(0, split_index); - Array right = array.make_array(split_index, array.size() - split_index); - - // Recurse to sort the smaller of the two, and then loop round within this - // function to sort the larger. This way, recursive call depth is bounded - // by log2 of the total array size, because every recursive call is sorting - // a list at most half the length of the one in its caller. - if (left.size() < right.size()) { - quick_sort(left); - array.reset_bounds(right.get(0), right.size()); - } else { - quick_sort(right); - array.reset_bounds(left.get(0), left.size()); + limit -= 1; + + const size_t pivot_index = choose_pivot(array, is_less); + + // If the chosen pivot is equal to the predecessor, then it's the smallest + // element in the slice. Partition the slice into elements equal to and + // elements greater than the pivot. This case is usually hit when the slice + // contains many duplicate elements. + if (ancestor_pivot) { + if (!is_less(ancestor_pivot, array.get(pivot_index))) { + const size_t num_lt = + partition(array, pivot_index, + [is_less](const void *a, const void *b) -> bool { + return !is_less(b, a); + }); + + // Continue sorting elements greater than the pivot. We know that + // `num_lt` cont + array.reset_bounds(num_lt + 1, array.len() - (num_lt + 1)); + ancestor_pivot = nullptr; + continue; + } } + + size_t split_index = partition(array, pivot_index, is_less); + + if (array_len == 2) + // The partition operation sorts the two element array. + return; + + // Split the array into `left`, `pivot`, and `right`. + A left = array.make_array(0, split_index); + const void *pivot = array.get(split_index); + const size_t right_start = split_index + 1; + A right = array.make_array(right_start, array.len() - right_start); + + // Recurse into the left side. We have a fixed recursion limit, + // testing shows no real benefit for recursing into the shorter + // side. + quick_sort_impl(left, ancestor_pivot, limit, is_less); + + // Continue with the right side. + array = right; + ancestor_pivot = pivot; } } +constexpr size_t ilog2(size_t n) { return cpp::bit_width(n) - 1; } + +template <typename A, typename F> +LIBC_INLINE void quick_sort(A &array, const F &is_less) { + const void *ancestor_pivot = nullptr; + // Limit the number of imbalanced partitions to `2 * floor(log2(len))`. + // The binary OR by one is used to eliminate the zero-check in the logarithm. + const size_t limit = 2 * ilog2((array.len() | 1)); + quick_sort_impl(array, ancestor_pivot, limit, is_less); +} + } // namespace internal } // namespace LIBC_NAMESPACE_DECL diff --git a/libc/src/time/CMakeLists.txt b/libc/src/time/CMakeLists.txt index ae835dc..ef9bfe5 100644 --- a/libc/src/time/CMakeLists.txt +++ b/libc/src/time/CMakeLists.txt @@ -2,6 +2,17 @@ if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS}) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS}) endif() +add_header_library( + time_constants + HDRS + time_constants.h + DEPENDS + libc.include.time + libc.src.__support.CPP.array + libc.src.__support.CPP.string_view + libc.hdr.types.time_t +) + add_object_library( time_utils SRCS @@ -12,6 +23,10 @@ add_object_library( libc.include.time libc.src.__support.CPP.limits libc.src.errno.errno + .time_constants + libc.hdr.types.time_t + libc.hdr.types.size_t + libc.hdr.types.struct_tm ) add_entrypoint_object( @@ -22,7 +37,9 @@ add_entrypoint_object( asctime.h DEPENDS .time_utils + .time_constants libc.include.time + libc.hdr.types.struct_tm ) add_entrypoint_object( @@ -33,7 +50,9 @@ add_entrypoint_object( asctime_r.h DEPENDS .time_utils + .time_constants libc.include.time + libc.hdr.types.struct_tm ) add_entrypoint_object( @@ -44,6 +63,7 @@ add_entrypoint_object( ctime.h DEPENDS .time_utils + .time_constants libc.hdr.types.time_t libc.include.time ) @@ -56,6 +76,7 @@ add_entrypoint_object( ctime_r.h DEPENDS .time_utils + .time_constants libc.hdr.types.time_t libc.include.time ) @@ -68,6 +89,7 @@ add_entrypoint_object( difftime.h DEPENDS libc.include.time + libc.hdr.types.time_t ) add_entrypoint_object( @@ -79,6 +101,8 @@ add_entrypoint_object( DEPENDS .time_utils libc.include.time + libc.hdr.types.time_t + libc.hdr.types.struct_tm ) add_entrypoint_object( @@ -90,6 +114,8 @@ add_entrypoint_object( DEPENDS .time_utils libc.include.time + libc.hdr.types.time_t + libc.hdr.types.struct_tm ) add_entrypoint_object( @@ -100,8 +126,11 @@ add_entrypoint_object( mktime.h DEPENDS .time_utils + .time_constants libc.include.time libc.src.errno.errno + libc.hdr.types.time_t + libc.hdr.types.struct_tm ) add_entrypoint_object( @@ -115,6 +144,7 @@ add_entrypoint_object( libc.hdr.types.time_t libc.src.__support.time.clock_gettime libc.src.errno.errno + libc.hdr.types.struct_tm ) add_entrypoint_object( diff --git a/libc/src/time/asctime.cpp b/libc/src/time/asctime.cpp index d6fbe73..2b00c41 100644 --- a/libc/src/time/asctime.cpp +++ b/libc/src/time/asctime.cpp @@ -9,15 +9,15 @@ #include "src/time/asctime.h" #include "src/__support/common.h" #include "src/__support/macros/config.h" +#include "src/time/time_constants.h" #include "src/time/time_utils.h" namespace LIBC_NAMESPACE_DECL { -using LIBC_NAMESPACE::time_utils::TimeConstants; - LLVM_LIBC_FUNCTION(char *, asctime, (const struct tm *timeptr)) { - static char buffer[TimeConstants::ASCTIME_BUFFER_SIZE]; - return time_utils::asctime(timeptr, buffer, TimeConstants::ASCTIME_MAX_BYTES); + static char buffer[time_constants::ASCTIME_BUFFER_SIZE]; + return time_utils::asctime(timeptr, buffer, + time_constants::ASCTIME_MAX_BYTES); } } // namespace LIBC_NAMESPACE_DECL diff --git a/libc/src/time/asctime.h b/libc/src/time/asctime.h index 623e6df..37325e7 100644 --- a/libc/src/time/asctime.h +++ b/libc/src/time/asctime.h @@ -9,8 +9,8 @@ #ifndef LLVM_LIBC_SRC_TIME_ASCTIME_H #define LLVM_LIBC_SRC_TIME_ASCTIME_H +#include "hdr/types/struct_tm.h" #include "src/__support/macros/config.h" -#include <time.h> namespace LIBC_NAMESPACE_DECL { diff --git a/libc/src/time/asctime_r.cpp b/libc/src/time/asctime_r.cpp index caa22f1..bf53bfd 100644 --- a/libc/src/time/asctime_r.cpp +++ b/libc/src/time/asctime_r.cpp @@ -9,15 +9,15 @@ #include "src/time/asctime_r.h" #include "src/__support/common.h" #include "src/__support/macros/config.h" +#include "src/time/time_constants.h" #include "src/time/time_utils.h" namespace LIBC_NAMESPACE_DECL { -using LIBC_NAMESPACE::time_utils::TimeConstants; - LLVM_LIBC_FUNCTION(char *, asctime_r, (const struct tm *timeptr, char *buffer)) { - return time_utils::asctime(timeptr, buffer, TimeConstants::ASCTIME_MAX_BYTES); + return time_utils::asctime(timeptr, buffer, + time_constants::ASCTIME_MAX_BYTES); } } // namespace LIBC_NAMESPACE_DECL diff --git a/libc/src/time/asctime_r.h b/libc/src/time/asctime_r.h index 328b7df..65a6b84 100644 --- a/libc/src/time/asctime_r.h +++ b/libc/src/time/asctime_r.h @@ -9,8 +9,8 @@ #ifndef LLVM_LIBC_SRC_TIME_ASCTIME_R_H #define LLVM_LIBC_SRC_TIME_ASCTIME_R_H +#include "hdr/types/struct_tm.h" #include "src/__support/macros/config.h" -#include <time.h> namespace LIBC_NAMESPACE_DECL { diff --git a/libc/src/time/ctime.cpp b/libc/src/time/ctime.cpp index 8adae9b..ac0ffe5 100644 --- a/libc/src/time/ctime.cpp +++ b/libc/src/time/ctime.cpp @@ -6,23 +6,22 @@ // //===----------------------------------------------------------------------===// -#include "ctime.h" +#include "src/time/ctime.h" #include "src/__support/CPP/limits.h" #include "src/__support/common.h" #include "src/__support/macros/config.h" -#include "time_utils.h" +#include "src/time/time_constants.h" +#include "src/time/time_utils.h" namespace LIBC_NAMESPACE_DECL { -using LIBC_NAMESPACE::time_utils::TimeConstants; - LLVM_LIBC_FUNCTION(char *, ctime, (const time_t *t_ptr)) { if (t_ptr == nullptr || *t_ptr > cpp::numeric_limits<int32_t>::max()) { return nullptr; } - static char buffer[TimeConstants::ASCTIME_BUFFER_SIZE]; + static char buffer[time_constants::ASCTIME_BUFFER_SIZE]; return time_utils::asctime(time_utils::localtime(t_ptr), buffer, - TimeConstants::ASCTIME_MAX_BYTES); + time_constants::ASCTIME_MAX_BYTES); } } // namespace LIBC_NAMESPACE_DECL diff --git a/libc/src/time/ctime_r.cpp b/libc/src/time/ctime_r.cpp index 63d93c4..7224f77 100644 --- a/libc/src/time/ctime_r.cpp +++ b/libc/src/time/ctime_r.cpp @@ -6,16 +6,15 @@ // //===----------------------------------------------------------------------===// -#include "ctime_r.h" +#include "src/time/ctime_r.h" #include "src/__support/CPP/limits.h" #include "src/__support/common.h" #include "src/__support/macros/config.h" -#include "time_utils.h" +#include "src/time/time_constants.h" +#include "src/time/time_utils.h" namespace LIBC_NAMESPACE_DECL { -using LIBC_NAMESPACE::time_utils::TimeConstants; - LLVM_LIBC_FUNCTION(char *, ctime_r, (const time_t *t_ptr, char *buffer)) { if (t_ptr == nullptr || buffer == nullptr || *t_ptr > cpp::numeric_limits<int32_t>::max()) { @@ -23,7 +22,7 @@ LLVM_LIBC_FUNCTION(char *, ctime_r, (const time_t *t_ptr, char *buffer)) { } return time_utils::asctime(time_utils::localtime(t_ptr), buffer, - TimeConstants::ASCTIME_MAX_BYTES); + time_constants::ASCTIME_MAX_BYTES); } } // namespace LIBC_NAMESPACE_DECL diff --git a/libc/src/time/difftime.h b/libc/src/time/difftime.h index d5cd593..12de567 100644 --- a/libc/src/time/difftime.h +++ b/libc/src/time/difftime.h @@ -9,8 +9,8 @@ #ifndef LLVM_LIBC_SRC_TIME_DIFFTIME_H #define LLVM_LIBC_SRC_TIME_DIFFTIME_H +#include "hdr/types/time_t.h" #include "src/__support/macros/config.h" -#include <time.h> namespace LIBC_NAMESPACE_DECL { diff --git a/libc/src/time/gmtime.h b/libc/src/time/gmtime.h index 3de3ceb..ac7f1be 100644 --- a/libc/src/time/gmtime.h +++ b/libc/src/time/gmtime.h @@ -9,8 +9,9 @@ #ifndef LLVM_LIBC_SRC_TIME_GMTIME_H #define LLVM_LIBC_SRC_TIME_GMTIME_H +#include "hdr/types/struct_tm.h" +#include "hdr/types/time_t.h" #include "src/__support/macros/config.h" -#include <time.h> namespace LIBC_NAMESPACE_DECL { diff --git a/libc/src/time/gmtime_r.h b/libc/src/time/gmtime_r.h index b4f387e..4c88b22 100644 --- a/libc/src/time/gmtime_r.h +++ b/libc/src/time/gmtime_r.h @@ -9,8 +9,9 @@ #ifndef LLVM_LIBC_SRC_TIME_GMTIME_R_H #define LLVM_LIBC_SRC_TIME_GMTIME_R_H +#include "hdr/types/struct_tm.h" +#include "hdr/types/time_t.h" #include "src/__support/macros/config.h" -#include <time.h> namespace LIBC_NAMESPACE_DECL { diff --git a/libc/src/time/gpu/clock.cpp b/libc/src/time/gpu/clock.cpp index add5b27..8609c5c 100644 --- a/libc/src/time/gpu/clock.cpp +++ b/libc/src/time/gpu/clock.cpp @@ -7,6 +7,8 @@ //===----------------------------------------------------------------------===// #include "src/time/clock.h" + +#include "src/__support/common.h" #include "src/__support/macros/config.h" #include "src/__support/time/gpu/time_utils.h" diff --git a/libc/src/time/gpu/nanosleep.cpp b/libc/src/time/gpu/nanosleep.cpp index a92f660..d22d9d6 100644 --- a/libc/src/time/gpu/nanosleep.cpp +++ b/libc/src/time/gpu/nanosleep.cpp @@ -8,6 +8,7 @@ #include "src/time/nanosleep.h" +#include "src/__support/common.h" #include "src/__support/macros/config.h" #include "src/__support/time/gpu/time_utils.h" diff --git a/libc/src/time/mktime.cpp b/libc/src/time/mktime.cpp index 72cd2291..3874cad 100644 --- a/libc/src/time/mktime.cpp +++ b/libc/src/time/mktime.cpp @@ -9,15 +9,11 @@ #include "src/time/mktime.h" #include "src/__support/common.h" #include "src/__support/macros/config.h" +#include "src/time/time_constants.h" #include "src/time/time_utils.h" namespace LIBC_NAMESPACE_DECL { -using LIBC_NAMESPACE::time_utils::TimeConstants; - -static constexpr int NON_LEAP_YEAR_DAYS_IN_MONTH[] = {31, 28, 31, 30, 31, 30, - 31, 31, 30, 31, 30, 31}; - // Returns number of years from (1, year). static constexpr int64_t get_num_of_leap_years_before(int64_t year) { return (year / 4) - (year / 100) + (year / 400); @@ -31,12 +27,12 @@ static constexpr bool is_leap_year(const int64_t year) { LLVM_LIBC_FUNCTION(time_t, mktime, (struct tm * tm_out)) { // Unlike most C Library functions, mktime doesn't just die on bad input. // TODO(rtenneti); Handle leap seconds. - int64_t tm_year_from_base = tm_out->tm_year + TimeConstants::TIME_YEAR_BASE; + int64_t tm_year_from_base = tm_out->tm_year + time_constants::TIME_YEAR_BASE; // 32-bit end-of-the-world is 03:14:07 UTC on 19 January 2038. if (sizeof(time_t) == 4 && - tm_year_from_base >= TimeConstants::END_OF32_BIT_EPOCH_YEAR) { - if (tm_year_from_base > TimeConstants::END_OF32_BIT_EPOCH_YEAR) + tm_year_from_base >= time_constants::END_OF32_BIT_EPOCH_YEAR) { + if (tm_year_from_base > time_constants::END_OF32_BIT_EPOCH_YEAR) return time_utils::out_of_range(); if (tm_out->tm_mon > 0) return time_utils::out_of_range(); @@ -64,7 +60,7 @@ LLVM_LIBC_FUNCTION(time_t, mktime, (struct tm * tm_out)) { // Calculate number of months and years from tm_mon. int64_t month = tm_out->tm_mon; - if (month < 0 || month >= TimeConstants::MONTHS_PER_YEAR - 1) { + if (month < 0 || month >= time_constants::MONTHS_PER_YEAR - 1) { int64_t years = month / 12; month %= 12; if (month < 0) { @@ -78,23 +74,23 @@ LLVM_LIBC_FUNCTION(time_t, mktime, (struct tm * tm_out)) { // Calculate total number of days based on the month and the day (tm_mday). int64_t total_days = tm_out->tm_mday - 1; for (int64_t i = 0; i < month; ++i) - total_days += NON_LEAP_YEAR_DAYS_IN_MONTH[i]; + total_days += time_constants::NON_LEAP_YEAR_DAYS_IN_MONTH[i]; // Add one day if it is a leap year and the month is after February. if (tm_year_is_leap && month > 1) total_days++; // Calculate total numbers of days based on the year. - total_days += (tm_year_from_base - TimeConstants::EPOCH_YEAR) * - TimeConstants::DAYS_PER_NON_LEAP_YEAR; - if (tm_year_from_base >= TimeConstants::EPOCH_YEAR) { + total_days += (tm_year_from_base - time_constants::EPOCH_YEAR) * + time_constants::DAYS_PER_NON_LEAP_YEAR; + if (tm_year_from_base >= time_constants::EPOCH_YEAR) { total_days += get_num_of_leap_years_before(tm_year_from_base - 1) - - get_num_of_leap_years_before(TimeConstants::EPOCH_YEAR); + get_num_of_leap_years_before(time_constants::EPOCH_YEAR); } else if (tm_year_from_base >= 1) { - total_days -= get_num_of_leap_years_before(TimeConstants::EPOCH_YEAR) - + total_days -= get_num_of_leap_years_before(time_constants::EPOCH_YEAR) - get_num_of_leap_years_before(tm_year_from_base - 1); } else { // Calculate number of leap years until 0th year. - total_days -= get_num_of_leap_years_before(TimeConstants::EPOCH_YEAR) - + total_days -= get_num_of_leap_years_before(time_constants::EPOCH_YEAR) - get_num_of_leap_years_before(0); if (tm_year_from_base <= 0) { total_days -= 1; // Subtract 1 for 0th year. @@ -106,11 +102,12 @@ LLVM_LIBC_FUNCTION(time_t, mktime, (struct tm * tm_out)) { } } - // TODO(rtenneti): Need to handle timezone and update of tm_isdst. + // TODO: https://github.com/llvm/llvm-project/issues/121962 + // Need to handle timezone and update of tm_isdst. int64_t seconds = tm_out->tm_sec + - tm_out->tm_min * TimeConstants::SECONDS_PER_MIN + - tm_out->tm_hour * TimeConstants::SECONDS_PER_HOUR + - total_days * TimeConstants::SECONDS_PER_DAY; + tm_out->tm_min * time_constants::SECONDS_PER_MIN + + tm_out->tm_hour * time_constants::SECONDS_PER_HOUR + + total_days * time_constants::SECONDS_PER_DAY; // Update the tm structure's year, month, day, etc. from seconds. if (time_utils::update_from_seconds(seconds, tm_out) < 0) diff --git a/libc/src/time/mktime.h b/libc/src/time/mktime.h index 2b4c679..985c629 100644 --- a/libc/src/time/mktime.h +++ b/libc/src/time/mktime.h @@ -9,8 +9,9 @@ #ifndef LLVM_LIBC_SRC_TIME_MKTIME_H #define LLVM_LIBC_SRC_TIME_MKTIME_H +#include "hdr/types/struct_tm.h" +#include "hdr/types/time_t.h" #include "src/__support/macros/config.h" -#include <time.h> namespace LIBC_NAMESPACE_DECL { diff --git a/libc/src/time/time.cpp b/libc/src/time/time.cpp index 4a0b614..860909a 100644 --- a/libc/src/time/time.cpp +++ b/libc/src/time/time.cpp @@ -6,12 +6,13 @@ // //===----------------------------------------------------------------------===// +#include "src/time/time_func.h" + #include "hdr/time_macros.h" #include "src/__support/common.h" #include "src/__support/macros/config.h" #include "src/__support/time/clock_gettime.h" #include "src/errno/libc_errno.h" -#include "src/time/time_func.h" namespace LIBC_NAMESPACE_DECL { // avoid inconsitent clang-format behavior diff --git a/libc/src/time/time_constants.h b/libc/src/time/time_constants.h new file mode 100644 index 0000000..3e25f74 --- /dev/null +++ b/libc/src/time/time_constants.h @@ -0,0 +1,100 @@ +//===-- Collection of constants for time functions --------------*- 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_TIME_TIME_CONSTANTS_H +#define LLVM_LIBC_SRC_TIME_TIME_CONSTANTS_H + +#include "hdr/types/time_t.h" +#include "src/__support/CPP/array.h" +#include "src/__support/CPP/string_view.h" +#include <stdint.h> + +namespace LIBC_NAMESPACE_DECL { +namespace time_constants { + +enum Month : int { + JANUARY, + FEBRUARY, + MARCH, + APRIL, + MAY, + JUNE, + JULY, + AUGUST, + SEPTEMBER, + OCTOBER, + NOVEMBER, + DECEMBER +}; + +constexpr int SECONDS_PER_MIN = 60; +constexpr int MINUTES_PER_HOUR = 60; +constexpr int HOURS_PER_DAY = 24; +constexpr int DAYS_PER_WEEK = 7; +constexpr int MONTHS_PER_YEAR = 12; +constexpr int DAYS_PER_NON_LEAP_YEAR = 365; +constexpr int DAYS_PER_LEAP_YEAR = 366; + +constexpr int SECONDS_PER_HOUR = SECONDS_PER_MIN * MINUTES_PER_HOUR; +constexpr int SECONDS_PER_DAY = SECONDS_PER_HOUR * HOURS_PER_DAY; +constexpr int NUMBER_OF_SECONDS_IN_LEAP_YEAR = + DAYS_PER_LEAP_YEAR * SECONDS_PER_DAY; + +constexpr int TIME_YEAR_BASE = 1900; +constexpr int EPOCH_YEAR = 1970; +constexpr int EPOCH_WEEK_DAY = 4; + +// For asctime the behavior is undefined if struct tm's tm_wday or tm_mon are +// not within the normal ranges as defined in <time.h>, or if struct tm's +// tm_year exceeds {INT_MAX}-1990, or if the below asctime_internal algorithm +// would attempt to generate more than 26 bytes of output (including the +// terminating null). +constexpr int ASCTIME_BUFFER_SIZE = 256; +constexpr int ASCTIME_MAX_BYTES = 26; + +/* 2000-03-01 (mod 400 year, immediately after feb29 */ +constexpr int64_t SECONDS_UNTIL2000_MARCH_FIRST = + (946684800LL + SECONDS_PER_DAY * (31 + 29)); +constexpr int WEEK_DAY_OF2000_MARCH_FIRST = 3; + +constexpr int DAYS_PER400_YEARS = + (DAYS_PER_NON_LEAP_YEAR * 400) + (400 / 4) - 3; +constexpr int DAYS_PER100_YEARS = + (DAYS_PER_NON_LEAP_YEAR * 100) + (100 / 4) - 1; +constexpr int DAYS_PER4_YEARS = (DAYS_PER_NON_LEAP_YEAR * 4) + 1; + +// The latest time that can be represented in this form is 03:14:07 UTC on +// Tuesday, 19 January 2038 (corresponding to 2,147,483,647 seconds since the +// start of the epoch). This means that systems using a 32-bit time_t type are +// susceptible to the Year 2038 problem. +constexpr int END_OF32_BIT_EPOCH_YEAR = 2038; + +constexpr time_t OUT_OF_RANGE_RETURN_VALUE = -1; + +constexpr cpp::array<cpp::string_view, DAYS_PER_WEEK> WEEK_DAY_NAMES = { + "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; + +constexpr cpp::array<cpp::string_view, DAYS_PER_WEEK> WEEK_DAY_FULL_NAMES = { + "Sunday", "Monday", "Tuesday", "Wednesday", + "Thursday", "Friday", "Saturday"}; + +constexpr cpp::array<cpp::string_view, MONTHS_PER_YEAR> MONTH_NAMES = { + "Jan", "Feb", "Mar", "Apr", "May", "Jun", + "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; + +constexpr cpp::array<cpp::string_view, MONTHS_PER_YEAR> MONTH_FULL_NAMES = { + "January", "February", "March", "April", "May", "June", + "July", "August", "September", "October", "November", "December"}; + +constexpr int NON_LEAP_YEAR_DAYS_IN_MONTH[] = {31, 28, 31, 30, 31, 30, + 31, 31, 30, 31, 30, 31}; + +} // namespace time_constants +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC_TIME_TIME_CONSTANTS_H diff --git a/libc/src/time/time_utils.cpp b/libc/src/time/time_utils.cpp index 509cad8..abc93b8 100644 --- a/libc/src/time/time_utils.cpp +++ b/libc/src/time/time_utils.cpp @@ -10,12 +10,11 @@ #include "src/__support/CPP/limits.h" // INT_MIN, INT_MAX #include "src/__support/common.h" #include "src/__support/macros/config.h" +#include "src/time/time_constants.h" namespace LIBC_NAMESPACE_DECL { namespace time_utils { -using LIBC_NAMESPACE::time_utils::TimeConstants; - static int64_t computeRemainingYears(int64_t daysPerYears, int64_t quotientYears, int64_t *remainingDays) { @@ -52,36 +51,36 @@ int64_t update_from_seconds(int64_t total_seconds, struct tm *tm) { (sizeof(time_t) == 4) ? INT_MIN : INT_MIN * static_cast<int64_t>( - TimeConstants::NUMBER_OF_SECONDS_IN_LEAP_YEAR); + time_constants::NUMBER_OF_SECONDS_IN_LEAP_YEAR); constexpr time_t time_max = (sizeof(time_t) == 4) ? INT_MAX : INT_MAX * static_cast<int64_t>( - TimeConstants::NUMBER_OF_SECONDS_IN_LEAP_YEAR); + time_constants::NUMBER_OF_SECONDS_IN_LEAP_YEAR); time_t ts = static_cast<time_t>(total_seconds); if (ts < time_min || ts > time_max) return time_utils::out_of_range(); int64_t seconds = - total_seconds - TimeConstants::SECONDS_UNTIL2000_MARCH_FIRST; - int64_t days = seconds / TimeConstants::SECONDS_PER_DAY; - int64_t remainingSeconds = seconds % TimeConstants::SECONDS_PER_DAY; + total_seconds - time_constants::SECONDS_UNTIL2000_MARCH_FIRST; + int64_t days = seconds / time_constants::SECONDS_PER_DAY; + int64_t remainingSeconds = seconds % time_constants::SECONDS_PER_DAY; if (remainingSeconds < 0) { - remainingSeconds += TimeConstants::SECONDS_PER_DAY; + remainingSeconds += time_constants::SECONDS_PER_DAY; days--; } - int64_t wday = (TimeConstants::WEEK_DAY_OF2000_MARCH_FIRST + days) % - TimeConstants::DAYS_PER_WEEK; + int64_t wday = (time_constants::WEEK_DAY_OF2000_MARCH_FIRST + days) % + time_constants::DAYS_PER_WEEK; if (wday < 0) - wday += TimeConstants::DAYS_PER_WEEK; + wday += time_constants::DAYS_PER_WEEK; // Compute the number of 400 year cycles. - int64_t numOfFourHundredYearCycles = days / TimeConstants::DAYS_PER400_YEARS; - int64_t remainingDays = days % TimeConstants::DAYS_PER400_YEARS; + int64_t numOfFourHundredYearCycles = days / time_constants::DAYS_PER400_YEARS; + int64_t remainingDays = days % time_constants::DAYS_PER400_YEARS; if (remainingDays < 0) { - remainingDays += TimeConstants::DAYS_PER400_YEARS; + remainingDays += time_constants::DAYS_PER400_YEARS; numOfFourHundredYearCycles--; } @@ -89,17 +88,17 @@ int64_t update_from_seconds(int64_t total_seconds, struct tm *tm) { // "four hundred year cycles" will be 4 hundred year cycles or less in 400 // years. int64_t numOfHundredYearCycles = computeRemainingYears( - TimeConstants::DAYS_PER100_YEARS, 4, &remainingDays); + time_constants::DAYS_PER100_YEARS, 4, &remainingDays); // The remaining number of years after computing the number of // "hundred year cycles" will be 25 four year cycles or less in 100 years. - int64_t numOfFourYearCycles = - computeRemainingYears(TimeConstants::DAYS_PER4_YEARS, 25, &remainingDays); + int64_t numOfFourYearCycles = computeRemainingYears( + time_constants::DAYS_PER4_YEARS, 25, &remainingDays); // The remaining number of years after computing the number of // "four year cycles" will be 4 one year cycles or less in 4 years. int64_t remainingYears = computeRemainingYears( - TimeConstants::DAYS_PER_NON_LEAP_YEAR, 4, &remainingDays); + time_constants::DAYS_PER_NON_LEAP_YEAR, 4, &remainingDays); // Calculate number of years from year 2000. int64_t years = remainingYears + 4 * numOfFourYearCycles + @@ -112,8 +111,8 @@ int64_t update_from_seconds(int64_t total_seconds, struct tm *tm) { // We add 31 and 28 for the number of days in January and February, since our // starting point was March 1st. int64_t yday = remainingDays + 31 + 28 + leapDay; - if (yday >= TimeConstants::DAYS_PER_NON_LEAP_YEAR + leapDay) - yday -= TimeConstants::DAYS_PER_NON_LEAP_YEAR + leapDay; + if (yday >= time_constants::DAYS_PER_NON_LEAP_YEAR + leapDay) + yday -= time_constants::DAYS_PER_NON_LEAP_YEAR + leapDay; int64_t months = 0; while (daysInMonth[months] <= remainingDays) { @@ -121,8 +120,8 @@ int64_t update_from_seconds(int64_t total_seconds, struct tm *tm) { months++; } - if (months >= TimeConstants::MONTHS_PER_YEAR - 2) { - months -= TimeConstants::MONTHS_PER_YEAR; + if (months >= time_constants::MONTHS_PER_YEAR - 2) { + months -= time_constants::MONTHS_PER_YEAR; years++; } @@ -131,19 +130,19 @@ int64_t update_from_seconds(int64_t total_seconds, struct tm *tm) { // All the data (years, month and remaining days) was calculated from // March, 2000. Thus adjust the data to be from January, 1900. - tm->tm_year = static_cast<int>(years + 2000 - TimeConstants::TIME_YEAR_BASE); + tm->tm_year = static_cast<int>(years + 2000 - time_constants::TIME_YEAR_BASE); tm->tm_mon = static_cast<int>(months + 2); tm->tm_mday = static_cast<int>(remainingDays + 1); tm->tm_wday = static_cast<int>(wday); tm->tm_yday = static_cast<int>(yday); tm->tm_hour = - static_cast<int>(remainingSeconds / TimeConstants::SECONDS_PER_HOUR); + static_cast<int>(remainingSeconds / time_constants::SECONDS_PER_HOUR); tm->tm_min = - static_cast<int>(remainingSeconds / TimeConstants::SECONDS_PER_MIN % - TimeConstants::SECONDS_PER_MIN); + static_cast<int>(remainingSeconds / time_constants::SECONDS_PER_MIN % + time_constants::SECONDS_PER_MIN); tm->tm_sec = - static_cast<int>(remainingSeconds % TimeConstants::SECONDS_PER_MIN); + static_cast<int>(remainingSeconds % time_constants::SECONDS_PER_MIN); // TODO(rtenneti): Need to handle timezone and update of tm_isdst. tm->tm_isdst = 0; diff --git a/libc/src/time/time_utils.h b/libc/src/time/time_utils.h index 552ea92..5e0a692 100644 --- a/libc/src/time/time_utils.h +++ b/libc/src/time/time_utils.h @@ -9,79 +9,19 @@ #ifndef LLVM_LIBC_SRC_TIME_TIME_UTILS_H #define LLVM_LIBC_SRC_TIME_TIME_UTILS_H -#include <stddef.h> // For size_t. - +#include "hdr/types/size_t.h" +#include "hdr/types/struct_tm.h" +#include "hdr/types/time_t.h" #include "src/__support/common.h" #include "src/__support/macros/config.h" #include "src/errno/libc_errno.h" -#include "src/time/mktime.h" +#include "time_constants.h" #include <stdint.h> namespace LIBC_NAMESPACE_DECL { namespace time_utils { -enum Month : int { - JANUARY, - FEBRUARY, - MARCH, - APRIL, - MAY, - JUNE, - JULY, - AUGUST, - SEPTEMBER, - OCTOBER, - NOVEMBER, - DECEMBER -}; - -struct TimeConstants { - static constexpr int SECONDS_PER_MIN = 60; - static constexpr int MINUTES_PER_HOUR = 60; - static constexpr int HOURS_PER_DAY = 24; - static constexpr int DAYS_PER_WEEK = 7; - static constexpr int MONTHS_PER_YEAR = 12; - static constexpr int DAYS_PER_NON_LEAP_YEAR = 365; - static constexpr int DAYS_PER_LEAP_YEAR = 366; - - static constexpr int SECONDS_PER_HOUR = SECONDS_PER_MIN * MINUTES_PER_HOUR; - static constexpr int SECONDS_PER_DAY = SECONDS_PER_HOUR * HOURS_PER_DAY; - static constexpr int NUMBER_OF_SECONDS_IN_LEAP_YEAR = - DAYS_PER_LEAP_YEAR * SECONDS_PER_DAY; - - static constexpr int TIME_YEAR_BASE = 1900; - static constexpr int EPOCH_YEAR = 1970; - static constexpr int EPOCH_WEEK_DAY = 4; - - // For asctime the behavior is undefined if struct tm's tm_wday or tm_mon are - // not within the normal ranges as defined in <time.h>, or if struct tm's - // tm_year exceeds {INT_MAX}-1990, or if the below asctime_internal algorithm - // would attempt to generate more than 26 bytes of output (including the - // terminating null). - static constexpr int ASCTIME_BUFFER_SIZE = 256; - static constexpr int ASCTIME_MAX_BYTES = 26; - - /* 2000-03-01 (mod 400 year, immediately after feb29 */ - static constexpr int64_t SECONDS_UNTIL2000_MARCH_FIRST = - (946684800LL + SECONDS_PER_DAY * (31 + 29)); - static constexpr int WEEK_DAY_OF2000_MARCH_FIRST = 3; - - static constexpr int DAYS_PER400_YEARS = - (DAYS_PER_NON_LEAP_YEAR * 400) + (400 / 4) - 3; - static constexpr int DAYS_PER100_YEARS = - (DAYS_PER_NON_LEAP_YEAR * 100) + (100 / 4) - 1; - static constexpr int DAYS_PER4_YEARS = (DAYS_PER_NON_LEAP_YEAR * 4) + 1; - - // The latest time that can be represented in this form is 03:14:07 UTC on - // Tuesday, 19 January 2038 (corresponding to 2,147,483,647 seconds since the - // start of the epoch). This means that systems using a 32-bit time_t type are - // susceptible to the Year 2038 problem. - static constexpr int END_OF32_BIT_EPOCH_YEAR = 2038; - - static constexpr time_t OUT_OF_RANGE_RETURN_VALUE = -1; -}; - // Update the "tm" structure's year, month, etc. members from seconds. // "total_seconds" is the number of seconds since January 1st, 1970. extern int64_t update_from_seconds(int64_t total_seconds, struct tm *tm); @@ -98,7 +38,7 @@ LIBC_INLINE time_t out_of_range() { // require it. libc_errno = EOVERFLOW; #endif - return TimeConstants::OUT_OF_RANGE_RETURN_VALUE; + return time_constants::OUT_OF_RANGE_RETURN_VALUE; } LIBC_INLINE void invalid_value() { libc_errno = EINVAL; } @@ -110,32 +50,23 @@ LIBC_INLINE char *asctime(const struct tm *timeptr, char *buffer, return nullptr; } if (timeptr->tm_wday < 0 || - timeptr->tm_wday > (TimeConstants::DAYS_PER_WEEK - 1)) { + timeptr->tm_wday > (time_constants::DAYS_PER_WEEK - 1)) { invalid_value(); return nullptr; } if (timeptr->tm_mon < 0 || - timeptr->tm_mon > (TimeConstants::MONTHS_PER_YEAR - 1)) { + timeptr->tm_mon > (time_constants::MONTHS_PER_YEAR - 1)) { invalid_value(); return nullptr; } - // TODO(rtenneti): i18n the following strings. - static const char *week_days_name[TimeConstants::DAYS_PER_WEEK] = { - "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; - - static const char *months_name[TimeConstants::MONTHS_PER_YEAR] = { - "Jan", "Feb", "Mar", "Apr", "May", "Jun", - "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; - - // TODO(michaelr): look into removing this call to __builtin_snprintf that may - // be emitted as a call to snprintf. Alternatively, look into using our - // internal printf machinery. + // TODO(michaelr): move this to use the strftime machinery int written_size = __builtin_snprintf( buffer, bufferLength, "%.3s %.3s%3d %.2d:%.2d:%.2d %d\n", - week_days_name[timeptr->tm_wday], months_name[timeptr->tm_mon], - timeptr->tm_mday, timeptr->tm_hour, timeptr->tm_min, timeptr->tm_sec, - TimeConstants::TIME_YEAR_BASE + timeptr->tm_year); + time_constants::WEEK_DAY_NAMES[timeptr->tm_wday].data(), + time_constants::MONTH_NAMES[timeptr->tm_mon].data(), timeptr->tm_mday, + timeptr->tm_hour, timeptr->tm_min, timeptr->tm_sec, + time_constants::TIME_YEAR_BASE + timeptr->tm_year); if (written_size < 0) return nullptr; if (static_cast<size_t>(written_size) >= bufferLength) { diff --git a/libc/src/unistd/linux/dup2.cpp b/libc/src/unistd/linux/dup2.cpp index c7c7c1a..7ffc151 100644 --- a/libc/src/unistd/linux/dup2.cpp +++ b/libc/src/unistd/linux/dup2.cpp @@ -32,7 +32,6 @@ LLVM_LIBC_FUNCTION(int, dup2, (int oldfd, int newfd)) { int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_fcntl, oldfd, F_GETFD); #elif defined(SYS_fcntl64) // Same as fcntl but can handle large offsets - static_assert(sizeof(off_t) == 8); int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_fcntl64, oldfd, F_GETFD); #else #error "SYS_fcntl and SYS_fcntl64 syscalls not available." diff --git a/libc/test/UnitTest/FPMatcher.h b/libc/test/UnitTest/FPMatcher.h index 9f2bae3..b8e240b 100644 --- a/libc/test/UnitTest/FPMatcher.h +++ b/libc/test/UnitTest/FPMatcher.h @@ -131,11 +131,11 @@ public: else if constexpr (cpp::is_complex_type_same<T, _Complex long double>()) return matchComplex<long double>(); #ifdef LIBC_TYPES_HAS_CFLOAT16 - else if constexpr (cpp::is_complex_type_same<T, cfloat16>) + else if constexpr (cpp::is_complex_type_same<T, cfloat16>()) return matchComplex<float16>(); #endif #ifdef LIBC_TYPES_HAS_CFLOAT128 - else if constexpr (cpp::is_complex_type_same<T, cfloat128>) + else if constexpr (cpp::is_complex_type_same<T, cfloat128>()) return matchComplex<float128>(); #endif } @@ -148,11 +148,11 @@ public: else if constexpr (cpp::is_complex_type_same<T, _Complex long double>()) return explainErrorComplex<long double>(); #ifdef LIBC_TYPES_HAS_CFLOAT16 - else if constexpr (cpp::is_complex_type_same<T, cfloat16>) + else if constexpr (cpp::is_complex_type_same<T, cfloat16>()) return explainErrorComplex<float16>(); #endif #ifdef LIBC_TYPES_HAS_CFLOAT128 - else if constexpr (cpp::is_complex_type_same<T, cfloat128>) + else if constexpr (cpp::is_complex_type_same<T, cfloat128>()) return explainErrorComplex<float128>(); #endif } diff --git a/libc/test/src/stdlib/CMakeLists.txt b/libc/test/src/stdlib/CMakeLists.txt index 4ca2043..8cc0428 100644 --- a/libc/test/src/stdlib/CMakeLists.txt +++ b/libc/test/src/stdlib/CMakeLists.txt @@ -301,18 +301,6 @@ add_libc_test( ) add_libc_test( - quick_sort_test - SUITE - libc-stdlib-tests - SRCS - quick_sort_test.cpp - HDRS - SortingTest.h - DEPENDS - libc.src.stdlib.qsort_util -) - -add_libc_test( heap_sort_test SUITE libc-stdlib-tests @@ -321,15 +309,15 @@ add_libc_test( HDRS SortingTest.h DEPENDS - libc.src.stdlib.qsort_util + libc.src.stdlib.qsort ) add_libc_test( - qsort_test + quick_sort_test SUITE libc-stdlib-tests SRCS - qsort_test.cpp + quick_sort_test.cpp HDRS SortingTest.h DEPENDS diff --git a/libc/test/src/stdlib/SortingTest.h b/libc/test/src/stdlib/SortingTest.h index d34584e..681a420 100644 --- a/libc/test/src/stdlib/SortingTest.h +++ b/libc/test/src/stdlib/SortingTest.h @@ -7,19 +7,19 @@ //===----------------------------------------------------------------------===// #include "src/__support/macros/config.h" -#include "src/stdlib/qsort_data.h" +#include "src/stdlib/qsort.h" #include "test/UnitTest/Test.h" class SortingTest : public LIBC_NAMESPACE::testing::Test { - using Array = LIBC_NAMESPACE::internal::Array; - using Comparator = LIBC_NAMESPACE::internal::Comparator; - using SortingRoutine = LIBC_NAMESPACE::internal::SortingRoutine; + using SortingRoutine = void (*)(void *array, size_t array_len, + size_t elem_size, + int (*compare)(const void *, const void *)); -public: static int int_compare(const void *l, const void *r) { int li = *reinterpret_cast<const int *>(l); int ri = *reinterpret_cast<const int *>(r); + if (li == ri) return 0; else if (li > ri) @@ -28,16 +28,19 @@ public: return -1; } + static void int_sort(SortingRoutine sort_func, int *array, size_t array_len) { + sort_func(reinterpret_cast<void *>(array), array_len, sizeof(int), + int_compare); + } + +public: void test_sorted_array(SortingRoutine sort_func) { int array[25] = {10, 23, 33, 35, 55, 70, 71, 100, 110, 123, 133, 135, 155, 170, 171, 1100, 1110, 1123, 1133, 1135, 1155, 1170, 1171, 11100, 12310}; - constexpr size_t ARRAY_SIZE = sizeof(array) / sizeof(int); - - auto arr = Array(reinterpret_cast<uint8_t *>(array), ARRAY_SIZE, - sizeof(int), Comparator(int_compare)); + constexpr size_t ARRAY_LEN = sizeof(array) / sizeof(int); - sort_func(arr); + int_sort(sort_func, array, ARRAY_LEN); ASSERT_LE(array[0], 10); ASSERT_LE(array[1], 23); @@ -69,14 +72,11 @@ public: void test_reversed_sorted_array(SortingRoutine sort_func) { int array[] = {25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}; - constexpr size_t ARRAY_SIZE = sizeof(array) / sizeof(int); + constexpr size_t ARRAY_LEN = sizeof(array) / sizeof(int); - auto arr = Array(reinterpret_cast<uint8_t *>(array), ARRAY_SIZE, - sizeof(int), Comparator(int_compare)); + int_sort(sort_func, array, ARRAY_LEN); - sort_func(arr); - - for (int i = 0; i < int(ARRAY_SIZE - 1); ++i) + for (int i = 0; i < int(ARRAY_LEN - 1); ++i) ASSERT_EQ(array[i], i + 1); } @@ -84,14 +84,11 @@ public: int array[] = {100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100}; - constexpr size_t ARRAY_SIZE = sizeof(array) / sizeof(int); - - auto arr = Array(reinterpret_cast<uint8_t *>(array), ARRAY_SIZE, - sizeof(int), Comparator(int_compare)); + constexpr size_t ARRAY_LEN = sizeof(array) / sizeof(int); - sort_func(arr); + int_sort(sort_func, array, ARRAY_LEN); - for (size_t i = 0; i < ARRAY_SIZE; ++i) + for (size_t i = 0; i < ARRAY_LEN; ++i) ASSERT_EQ(array[i], 100); } @@ -99,12 +96,9 @@ public: int array[25] = {10, 23, 8, 35, 55, 45, 40, 100, 110, 123, 90, 80, 70, 60, 171, 11, 1, -1, -5, -10, 1155, 1170, 1171, 12, -100}; - constexpr size_t ARRAY_SIZE = sizeof(array) / sizeof(int); - - auto arr = Array(reinterpret_cast<uint8_t *>(array), ARRAY_SIZE, - sizeof(int), Comparator(int_compare)); + constexpr size_t ARRAY_LEN = sizeof(array) / sizeof(int); - sort_func(arr); + int_sort(sort_func, array, ARRAY_LEN); ASSERT_EQ(array[0], -100); ASSERT_EQ(array[1], -10); @@ -135,12 +129,9 @@ public: void test_unsorted_array_2(SortingRoutine sort_func) { int array[7] = {10, 40, 45, 55, 35, 23, 60}; - constexpr size_t ARRAY_SIZE = sizeof(array) / sizeof(int); + constexpr size_t ARRAY_LEN = sizeof(array) / sizeof(int); - auto arr = Array(reinterpret_cast<uint8_t *>(array), ARRAY_SIZE, - sizeof(int), Comparator(int_compare)); - - sort_func(arr); + int_sort(sort_func, array, ARRAY_LEN); ASSERT_EQ(array[0], 10); ASSERT_EQ(array[1], 23); @@ -153,12 +144,9 @@ public: void test_unsorted_array_duplicated_1(SortingRoutine sort_func) { int array[6] = {10, 10, 20, 20, 5, 5}; - constexpr size_t ARRAY_SIZE = sizeof(array) / sizeof(int); - - auto arr = Array(reinterpret_cast<uint8_t *>(array), ARRAY_SIZE, - sizeof(int), Comparator(int_compare)); + constexpr size_t ARRAY_LEN = sizeof(array) / sizeof(int); - sort_func(arr); + int_sort(sort_func, array, ARRAY_LEN); ASSERT_EQ(array[0], 5); ASSERT_EQ(array[1], 5); @@ -170,12 +158,9 @@ public: void test_unsorted_array_duplicated_2(SortingRoutine sort_func) { int array[10] = {20, 10, 10, 10, 10, 20, 21, 21, 21, 21}; - constexpr size_t ARRAY_SIZE = sizeof(array) / sizeof(int); - - auto arr = Array(reinterpret_cast<uint8_t *>(array), ARRAY_SIZE, - sizeof(int), Comparator(int_compare)); + constexpr size_t ARRAY_LEN = sizeof(array) / sizeof(int); - sort_func(arr); + int_sort(sort_func, array, ARRAY_LEN); ASSERT_EQ(array[0], 10); ASSERT_EQ(array[1], 10); @@ -191,12 +176,9 @@ public: void test_unsorted_array_duplicated_3(SortingRoutine sort_func) { int array[10] = {20, 30, 30, 30, 30, 20, 21, 21, 21, 21}; - constexpr size_t ARRAY_SIZE = sizeof(array) / sizeof(int); + constexpr size_t ARRAY_LEN = sizeof(array) / sizeof(int); - auto arr = Array(reinterpret_cast<uint8_t *>(array), ARRAY_SIZE, - sizeof(int), Comparator(int_compare)); - - sort_func(arr); + int_sort(sort_func, array, ARRAY_LEN); ASSERT_EQ(array[0], 20); ASSERT_EQ(array[1], 20); @@ -213,12 +195,9 @@ public: void test_unsorted_three_element_1(SortingRoutine sort_func) { int array[3] = {14999024, 0, 3}; - constexpr size_t ARRAY_SIZE = sizeof(array) / sizeof(int); - - auto arr = Array(reinterpret_cast<uint8_t *>(array), ARRAY_SIZE, - sizeof(int), Comparator(int_compare)); + constexpr size_t ARRAY_LEN = sizeof(array) / sizeof(int); - sort_func(arr); + int_sort(sort_func, array, ARRAY_LEN); ASSERT_EQ(array[0], 0); ASSERT_EQ(array[1], 3); @@ -228,12 +207,9 @@ public: void test_unsorted_three_element_2(SortingRoutine sort_func) { int array[3] = {3, 14999024, 0}; - constexpr size_t ARRAY_SIZE = sizeof(array) / sizeof(int); - - auto arr = Array(reinterpret_cast<uint8_t *>(array), ARRAY_SIZE, - sizeof(int), Comparator(int_compare)); + constexpr size_t ARRAY_LEN = sizeof(array) / sizeof(int); - sort_func(arr); + int_sort(sort_func, array, ARRAY_LEN); ASSERT_EQ(array[0], 0); ASSERT_EQ(array[1], 3); @@ -243,12 +219,9 @@ public: void test_unsorted_three_element_3(SortingRoutine sort_func) { int array[3] = {3, 0, 14999024}; - constexpr size_t ARRAY_SIZE = sizeof(array) / sizeof(int); + constexpr size_t ARRAY_LEN = sizeof(array) / sizeof(int); - auto arr = Array(reinterpret_cast<uint8_t *>(array), ARRAY_SIZE, - sizeof(int), Comparator(int_compare)); - - sort_func(arr); + int_sort(sort_func, array, ARRAY_LEN); ASSERT_EQ(array[0], 0); ASSERT_EQ(array[1], 3); @@ -258,12 +231,9 @@ public: void test_same_three_element(SortingRoutine sort_func) { int array[3] = {12345, 12345, 12345}; - constexpr size_t ARRAY_SIZE = sizeof(array) / sizeof(int); - - auto arr = Array(reinterpret_cast<uint8_t *>(array), ARRAY_SIZE, - sizeof(int), Comparator(int_compare)); + constexpr size_t ARRAY_LEN = sizeof(array) / sizeof(int); - sort_func(arr); + int_sort(sort_func, array, ARRAY_LEN); ASSERT_EQ(array[0], 12345); ASSERT_EQ(array[1], 12345); @@ -273,12 +243,9 @@ public: void test_unsorted_two_element_1(SortingRoutine sort_func) { int array[] = {14999024, 0}; - constexpr size_t ARRAY_SIZE = sizeof(array) / sizeof(int); - - auto arr = Array(reinterpret_cast<uint8_t *>(array), ARRAY_SIZE, - sizeof(int), Comparator(int_compare)); + constexpr size_t ARRAY_LEN = sizeof(array) / sizeof(int); - sort_func(arr); + int_sort(sort_func, array, ARRAY_LEN); ASSERT_EQ(array[0], 0); ASSERT_EQ(array[1], 14999024); @@ -287,12 +254,9 @@ public: void test_unsorted_two_element_2(SortingRoutine sort_func) { int array[] = {0, 14999024}; - constexpr size_t ARRAY_SIZE = sizeof(array) / sizeof(int); + constexpr size_t ARRAY_LEN = sizeof(array) / sizeof(int); - auto arr = Array(reinterpret_cast<uint8_t *>(array), ARRAY_SIZE, - sizeof(int), Comparator(int_compare)); - - sort_func(arr); + int_sort(sort_func, array, ARRAY_LEN); ASSERT_EQ(array[0], 0); ASSERT_EQ(array[1], 14999024); @@ -301,12 +265,9 @@ public: void test_same_two_element(SortingRoutine sort_func) { int array[] = {12345, 12345}; - constexpr size_t ARRAY_SIZE = sizeof(array) / sizeof(int); - - auto arr = Array(reinterpret_cast<uint8_t *>(array), ARRAY_SIZE, - sizeof(int), Comparator(int_compare)); + constexpr size_t ARRAY_LEN = sizeof(array) / sizeof(int); - sort_func(arr); + int_sort(sort_func, array, ARRAY_LEN); ASSERT_EQ(array[0], 12345); ASSERT_EQ(array[1], 12345); @@ -315,15 +276,80 @@ public: void test_single_element(SortingRoutine sort_func) { int array[] = {12345}; - constexpr size_t ARRAY_SIZE = sizeof(array) / sizeof(int); - - auto arr = Array(reinterpret_cast<uint8_t *>(array), ARRAY_SIZE, - sizeof(int), Comparator(int_compare)); + constexpr size_t ARRAY_LEN = sizeof(array) / sizeof(int); - sort_func(arr); + int_sort(sort_func, array, ARRAY_LEN); ASSERT_EQ(array[0], 12345); } + + void test_different_elem_size(SortingRoutine sort_func) { + // Random order of values [0,50) to avoid only testing pre-sorted handling. + // Long enough to reach interesting code. + constexpr uint8_t ARRAY_INITIAL_VALS[] = { + 42, 13, 8, 4, 17, 28, 20, 32, 22, 29, 7, 2, 46, 37, 26, 49, 24, + 38, 10, 18, 40, 36, 47, 15, 11, 48, 44, 33, 1, 5, 16, 35, 39, 41, + 14, 23, 3, 9, 6, 27, 21, 25, 31, 45, 12, 43, 34, 30, 19, 0}; + + constexpr size_t ARRAY_LEN = sizeof(ARRAY_INITIAL_VALS); + constexpr size_t MAX_ELEM_SIZE = 150; + constexpr size_t BUF_SIZE = ARRAY_LEN * MAX_ELEM_SIZE; + + static_assert(ARRAY_LEN < 256); // so we can encode the values. + + // Minimum alignment to test implementation for bugs related to assuming + // incorrect association between alignment and element size. The buffer is + // 'static' as otherwise it will exhaust the stack on the GPU targets. + alignas(1) static uint8_t buf[BUF_SIZE]; + + // GCC still requires capturing the constant ARRAY_INITIAL_VALS in the + // lambda hence, let's use & to implicitly capture all needed variables + // automatically. + const auto fill_buf = [&](size_t elem_size) { + for (size_t i = 0; i < BUF_SIZE; ++i) { + buf[i] = 0; + } + + for (size_t elem_i = 0, buf_i = 0; elem_i < ARRAY_LEN; ++elem_i) { + const uint8_t elem_val = ARRAY_INITIAL_VALS[elem_i]; + for (size_t elem_byte_i = 0; elem_byte_i < elem_size; ++elem_byte_i) { + buf[buf_i] = elem_val; + buf_i += 1; + } + } + }; + + for (size_t elem_size = 0; elem_size <= MAX_ELEM_SIZE; ++elem_size) { + // Fill all bytes with data to ensure mistakes in elem swap are noticed. + fill_buf(elem_size); + + sort_func(reinterpret_cast<void *>(buf), ARRAY_LEN, elem_size, + [](const void *a, const void *b) -> int { + const uint8_t a_val = *reinterpret_cast<const uint8_t *>(a); + const uint8_t b_val = *reinterpret_cast<const uint8_t *>(b); + + if (a_val < b_val) { + return -1; + } else if (a_val > b_val) { + return 1; + } else { + return 0; + } + }); + + for (size_t elem_i = 0, buf_i = 0; elem_i < ARRAY_LEN; ++elem_i) { + const uint8_t expected_elem_val = static_cast<uint8_t>(elem_i); + + for (size_t elem_byte_i = 0; elem_byte_i < elem_size; ++elem_byte_i) { + const uint8_t buf_val = buf[buf_i]; + // Check that every byte in the element has the expected value. + ASSERT_EQ(buf_val, expected_elem_val) + << "elem_size: " << elem_size << " buf_i: " << buf_i << '\n'; + buf_i += 1; + } + } + } + } }; #define LIST_SORTING_TESTS(Name, Func) \ @@ -374,4 +400,7 @@ public: TEST_F(LlvmLibc##Name##Test, SingleElementArray) { \ test_single_element(Func); \ } \ + TEST_F(LlvmLibc##Name##Test, DifferentElemSizeArray) { \ + test_different_elem_size(Func); \ + } \ static_assert(true) diff --git a/libc/test/src/stdlib/heap_sort_test.cpp b/libc/test/src/stdlib/heap_sort_test.cpp index d70e3dc..18d4244 100644 --- a/libc/test/src/stdlib/heap_sort_test.cpp +++ b/libc/test/src/stdlib/heap_sort_test.cpp @@ -7,10 +7,20 @@ //===----------------------------------------------------------------------===// #include "SortingTest.h" -#include "src/stdlib/heap_sort.h" +#include "src/stdlib/qsort_util.h" -void sort(const LIBC_NAMESPACE::internal::Array &array) { - LIBC_NAMESPACE::internal::heap_sort(array); +void heap_sort(void *array, size_t array_size, size_t elem_size, + int (*compare)(const void *, const void *)) { + + constexpr bool USE_QUICKSORT = false; + + const auto is_less = [compare](const void *a, + const void *b) noexcept -> bool { + return compare(a, b) < 0; + }; + + LIBC_NAMESPACE::internal::unstable_sort_impl<USE_QUICKSORT>( + array, array_size, elem_size, is_less); } -LIST_SORTING_TESTS(HeapSort, sort); +LIST_SORTING_TESTS(HeapSort, heap_sort); diff --git a/libc/test/src/stdlib/qsort_r_test.cpp b/libc/test/src/stdlib/qsort_r_test.cpp index 6893fdc..f189236 100644 --- a/libc/test/src/stdlib/qsort_r_test.cpp +++ b/libc/test/src/stdlib/qsort_r_test.cpp @@ -62,9 +62,9 @@ TEST(LlvmLibcQsortRTest, SortedArray) { ASSERT_LE(array[23], 11100); ASSERT_LE(array[24], 12310); - // This is a sorted list, but there still have to have been at least N + // This is a sorted list, but there still have to have been at least N - 1 // comparisons made. - ASSERT_GE(count, ARRAY_SIZE); + ASSERT_GE(count, ARRAY_SIZE - 1); } TEST(LlvmLibcQsortRTest, ReverseSortedArray) { diff --git a/libc/test/src/stdlib/qsort_test.cpp b/libc/test/src/stdlib/qsort_test.cpp deleted file mode 100644 index 1e921a8..0000000 --- a/libc/test/src/stdlib/qsort_test.cpp +++ /dev/null @@ -1,17 +0,0 @@ -//===-- Unittests for qsort -----------------------------------------------===// -// -// 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 "SortingTest.h" -#include "src/stdlib/qsort.h" - -void sort(const LIBC_NAMESPACE::internal::Array &array) { - LIBC_NAMESPACE::qsort(reinterpret_cast<void *>(array.get(0)), array.size(), - sizeof(int), SortingTest::int_compare); -} - -LIST_SORTING_TESTS(Qsort, sort); diff --git a/libc/test/src/stdlib/quick_sort_test.cpp b/libc/test/src/stdlib/quick_sort_test.cpp index d6bf77e..2832c85 100644 --- a/libc/test/src/stdlib/quick_sort_test.cpp +++ b/libc/test/src/stdlib/quick_sort_test.cpp @@ -1,4 +1,4 @@ -//===-- Unittests for quick sort ------------------------------------------===// +//===-- Unittests for qsort -----------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -7,10 +7,19 @@ //===----------------------------------------------------------------------===// #include "SortingTest.h" -#include "src/stdlib/quick_sort.h" +#include "src/stdlib/qsort_util.h" -void sort(const LIBC_NAMESPACE::internal::Array &array) { - LIBC_NAMESPACE::internal::quick_sort(array); +void quick_sort(void *array, size_t array_size, size_t elem_size, + int (*compare)(const void *, const void *)) { + constexpr bool USE_QUICKSORT = true; + + const auto is_less = [compare](const void *a, + const void *b) noexcept -> bool { + return compare(a, b) < 0; + }; + + LIBC_NAMESPACE::internal::unstable_sort_impl<USE_QUICKSORT>( + array, array_size, elem_size, is_less); } -LIST_SORTING_TESTS(QuickSort, sort); +LIST_SORTING_TESTS(Qsort, quick_sort); diff --git a/libc/test/src/time/CMakeLists.txt b/libc/test/src/time/CMakeLists.txt index da3903f..12add22 100644 --- a/libc/test/src/time/CMakeLists.txt +++ b/libc/test/src/time/CMakeLists.txt @@ -13,6 +13,8 @@ add_libc_unittest( 20 DEPENDS libc.src.time.asctime + libc.hdr.types.struct_tm + libc.src.time.time_constants ) add_libc_unittest( @@ -28,6 +30,8 @@ add_libc_unittest( 20 DEPENDS libc.src.time.asctime_r + libc.hdr.types.struct_tm + libc.src.time.time_constants ) add_libc_unittest( @@ -45,7 +49,8 @@ add_libc_unittest( libc.include.time libc.hdr.types.time_t libc.src.time.ctime - libc.src.time.time_utils + libc.src.time.time_constants + libc.hdr.types.struct_tm ) add_libc_unittest( @@ -63,7 +68,8 @@ add_libc_unittest( libc.include.time libc.hdr.types.time_t libc.src.time.ctime_r - libc.src.time.time_utils + libc.src.time.time_constants + libc.hdr.types.struct_tm ) add_libc_test( @@ -74,6 +80,9 @@ add_libc_test( clock_gettime_test.cpp DEPENDS libc.src.time.clock_gettime + libc.hdr.types.time_t + libc.hdr.types.struct_timespec + libc.hdr.time_macros ) add_libc_test( @@ -94,6 +103,8 @@ add_libc_unittest( difftime_test.cpp DEPENDS libc.src.time.difftime + libc.src.time.time_constants + libc.src.__support.FPUtil.fp_bits ) add_libc_unittest( @@ -105,6 +116,7 @@ add_libc_unittest( DEPENDS libc.include.time libc.src.time.gettimeofday + libc.hdr.types.struct_timeval ) add_libc_unittest( @@ -118,6 +130,8 @@ add_libc_unittest( DEPENDS libc.src.time.gmtime libc.src.__support.CPP.limits + libc.hdr.types.struct_tm + libc.src.time.time_constants ) add_libc_unittest( @@ -130,6 +144,8 @@ add_libc_unittest( TmMatcher.h DEPENDS libc.src.time.gmtime_r + libc.hdr.types.struct_tm + libc.src.time.time_constants ) add_libc_unittest( @@ -146,6 +162,8 @@ add_libc_unittest( DEPENDS libc.src.time.mktime libc.src.__support.CPP.limits + libc.hdr.types.struct_tm + libc.src.time.time_constants ) add_libc_test( @@ -158,6 +176,7 @@ add_libc_test( libc.include.time libc.src.time.nanosleep libc.src.errno.errno + libc.hdr.types.struct_timespec ) add_libc_unittest( @@ -180,6 +199,7 @@ add_libc_test( timespec_get_test.cpp DEPENDS libc.src.time.timespec_get + libc.hdr.types.struct_timespec ) add_libc_test( @@ -192,4 +212,5 @@ add_libc_test( libc.include.time libc.src.time.clock libc.src.errno.errno + libc.hdr.types.clock_t ) diff --git a/libc/test/src/time/TmHelper.h b/libc/test/src/time/TmHelper.h index 5ae2584..1582839 100644 --- a/libc/test/src/time/TmHelper.h +++ b/libc/test/src/time/TmHelper.h @@ -9,12 +9,9 @@ #ifndef LLVM_LIBC_TEST_SRC_TIME_TMHELPER_H #define LLVM_LIBC_TEST_SRC_TIME_TMHELPER_H -#include <time.h> - +#include "hdr/types/struct_tm.h" #include "src/__support/macros/config.h" -#include "src/time/time_utils.h" - -using LIBC_NAMESPACE::time_utils::TimeConstants; +#include "src/time/time_constants.h" namespace LIBC_NAMESPACE_DECL { namespace tmhelper { @@ -30,7 +27,7 @@ static inline void initialize_tm_data(struct tm *tm_data, int year, int month, .tm_mday = mday, .tm_mon = month - 1, // tm_mon starts with 0 for Jan // years since 1900 - .tm_year = year - TimeConstants::TIME_YEAR_BASE, + .tm_year = year - time_constants::TIME_YEAR_BASE, .tm_wday = wday, .tm_yday = yday, .tm_isdst = 0}; diff --git a/libc/test/src/time/TmMatcher.h b/libc/test/src/time/TmMatcher.h index 630956b..d39ee39 100644 --- a/libc/test/src/time/TmMatcher.h +++ b/libc/test/src/time/TmMatcher.h @@ -9,8 +9,7 @@ #ifndef LLVM_LIBC_TEST_SRC_TIME_TM_MATCHER_H #define LLVM_LIBC_TEST_SRC_TIME_TM_MATCHER_H -#include <time.h> - +#include "hdr/types/struct_tm.h" #include "src/__support/macros/config.h" #include "test/UnitTest/Test.h" diff --git a/libc/test/src/time/asctime_r_test.cpp b/libc/test/src/time/asctime_r_test.cpp index f3aadbb..b595cfe 100644 --- a/libc/test/src/time/asctime_r_test.cpp +++ b/libc/test/src/time/asctime_r_test.cpp @@ -8,12 +8,10 @@ #include "src/errno/libc_errno.h" #include "src/time/asctime_r.h" -#include "src/time/time_utils.h" +#include "src/time/time_constants.h" #include "test/UnitTest/Test.h" #include "test/src/time/TmHelper.h" -using LIBC_NAMESPACE::time_utils::TimeConstants; - static inline char *call_asctime_r(struct tm *tm_data, int year, int month, int mday, int hour, int min, int sec, int wday, int yday, char *buffer) { @@ -30,7 +28,7 @@ TEST(LlvmLibcAsctimeR, Nullptr) { ASSERT_ERRNO_EQ(EINVAL); ASSERT_STREQ(nullptr, result); - char buffer[TimeConstants::ASCTIME_BUFFER_SIZE]; + char buffer[LIBC_NAMESPACE::time_constants::ASCTIME_BUFFER_SIZE]; result = LIBC_NAMESPACE::asctime_r(nullptr, buffer); ASSERT_ERRNO_EQ(EINVAL); ASSERT_STREQ(nullptr, result); @@ -42,7 +40,7 @@ TEST(LlvmLibcAsctimeR, Nullptr) { } TEST(LlvmLibcAsctimeR, ValidDate) { - char buffer[TimeConstants::ASCTIME_BUFFER_SIZE]; + char buffer[LIBC_NAMESPACE::time_constants::ASCTIME_BUFFER_SIZE]; struct tm tm_data; char *result; // 1970-01-01 00:00:00. Test with a valid buffer size. diff --git a/libc/test/src/time/clock_gettime_test.cpp b/libc/test/src/time/clock_gettime_test.cpp index 43715c0..d3edcae 100644 --- a/libc/test/src/time/clock_gettime_test.cpp +++ b/libc/test/src/time/clock_gettime_test.cpp @@ -6,12 +6,13 @@ // //===----------------------------------------------------------------------===// +#include "hdr/time_macros.h" +#include "hdr/types/struct_timespec.h" +#include "hdr/types/time_t.h" #include "src/__support/macros/properties/architectures.h" #include "src/time/clock_gettime.h" #include "test/UnitTest/Test.h" -#include <time.h> - TEST(LlvmLibcClockGetTime, RealTime) { timespec tp; int result; diff --git a/libc/test/src/time/clock_test.cpp b/libc/test/src/time/clock_test.cpp index 05082aa..8d8d89d 100644 --- a/libc/test/src/time/clock_test.cpp +++ b/libc/test/src/time/clock_test.cpp @@ -6,11 +6,10 @@ // //===----------------------------------------------------------------------===// +#include "hdr/types/clock_t.h" #include "src/time/clock.h" #include "test/UnitTest/Test.h" -#include <time.h> - TEST(LlvmLibcClockTest, SmokeTest) { clock_t c1 = LIBC_NAMESPACE::clock(); ASSERT_GT(c1, clock_t(0)); diff --git a/libc/test/src/time/ctime_r_test.cpp b/libc/test/src/time/ctime_r_test.cpp index 9ce6f75..27011b7 100644 --- a/libc/test/src/time/ctime_r_test.cpp +++ b/libc/test/src/time/ctime_r_test.cpp @@ -8,18 +8,16 @@ #include "src/errno/libc_errno.h" #include "src/time/ctime_r.h" -#include "src/time/time_utils.h" +#include "src/time/time_constants.h" #include "test/UnitTest/Test.h" #include "test/src/time/TmHelper.h" -using LIBC_NAMESPACE::time_utils::TimeConstants; - TEST(LlvmLibcCtimeR, Nullptr) { char *result; result = LIBC_NAMESPACE::ctime_r(nullptr, nullptr); ASSERT_STREQ(nullptr, result); - char buffer[TimeConstants::ASCTIME_BUFFER_SIZE]; + char buffer[LIBC_NAMESPACE::time_constants::ASCTIME_BUFFER_SIZE]; result = LIBC_NAMESPACE::ctime_r(nullptr, buffer); ASSERT_STREQ(nullptr, result); @@ -29,7 +27,7 @@ TEST(LlvmLibcCtimeR, Nullptr) { } TEST(LlvmLibcCtimeR, ValidUnixTimestamp0) { - char buffer[TimeConstants::ASCTIME_BUFFER_SIZE]; + char buffer[LIBC_NAMESPACE::time_constants::ASCTIME_BUFFER_SIZE]; time_t t; char *result; // 1970-01-01 00:00:00. Test with a valid buffer size. @@ -39,7 +37,7 @@ TEST(LlvmLibcCtimeR, ValidUnixTimestamp0) { } TEST(LlvmLibcCtime, ValidUnixTimestamp32Int) { - char buffer[TimeConstants::ASCTIME_BUFFER_SIZE]; + char buffer[LIBC_NAMESPACE::time_constants::ASCTIME_BUFFER_SIZE]; time_t t; char *result; // 2038-01-19 03:14:07. Test with a valid buffer size. @@ -49,7 +47,7 @@ TEST(LlvmLibcCtime, ValidUnixTimestamp32Int) { } TEST(LlvmLibcCtimeR, InvalidArgument) { - char buffer[TimeConstants::ASCTIME_BUFFER_SIZE]; + char buffer[LIBC_NAMESPACE::time_constants::ASCTIME_BUFFER_SIZE]; time_t t; char *result; t = 2147483648; diff --git a/libc/test/src/time/difftime_test.cpp b/libc/test/src/time/difftime_test.cpp index 68ff463..4dab1ac 100644 --- a/libc/test/src/time/difftime_test.cpp +++ b/libc/test/src/time/difftime_test.cpp @@ -8,15 +8,12 @@ #include "src/__support/FPUtil/FPBits.h" #include "src/time/difftime.h" -#include "src/time/time_utils.h" +#include "src/time/time_constants.h" #include "test/UnitTest/ErrnoSetterMatcher.h" #include "test/UnitTest/Test.h" -using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds; -using LIBC_NAMESPACE::time_utils::TimeConstants; - TEST(LlvmLibcDifftime, SmokeTest) { - time_t t1_seconds = TimeConstants::SECONDS_PER_HOUR; + time_t t1_seconds = LIBC_NAMESPACE::time_constants::SECONDS_PER_HOUR; time_t t2_seconds = 0; LIBC_NAMESPACE::fputil::FPBits<long double> expected_fp = diff --git a/libc/test/src/time/gettimeofday_test.cpp b/libc/test/src/time/gettimeofday_test.cpp index ee934b7..8f9f136 100644 --- a/libc/test/src/time/gettimeofday_test.cpp +++ b/libc/test/src/time/gettimeofday_test.cpp @@ -6,8 +6,7 @@ // //===----------------------------------------------------------------------===// -#include <time.h> - +#include "hdr/types/struct_timeval.h" #include "src/time/gettimeofday.h" #include "test/UnitTest/Test.h" diff --git a/libc/test/src/time/gmtime_r_test.cpp b/libc/test/src/time/gmtime_r_test.cpp index 2276b48..9d466f4 100644 --- a/libc/test/src/time/gmtime_r_test.cpp +++ b/libc/test/src/time/gmtime_r_test.cpp @@ -7,12 +7,10 @@ //===----------------------------------------------------------------------===// #include "src/time/gmtime_r.h" -#include "src/time/time_utils.h" +#include "src/time/time_constants.h" #include "test/UnitTest/Test.h" #include "test/src/time/TmMatcher.h" -using LIBC_NAMESPACE::time_utils::TimeConstants; - // gmtime and gmtime_r share the same code and thus didn't repeat all the tests // from gmtime. Added couple of validation tests. TEST(LlvmLibcGmTimeR, EndOf32BitEpochYear) { @@ -22,16 +20,17 @@ TEST(LlvmLibcGmTimeR, EndOf32BitEpochYear) { struct tm tm_data; struct tm *tm_data_ptr; tm_data_ptr = LIBC_NAMESPACE::gmtime_r(&seconds, &tm_data); - EXPECT_TM_EQ((tm{7, // sec - 14, // min - 3, // hr - 19, // day - 0, // tm_mon starts with 0 for Jan - 2038 - TimeConstants::TIME_YEAR_BASE, // year - 2, // wday - 7, // yday - 0}), - *tm_data_ptr); + EXPECT_TM_EQ( + (tm{7, // sec + 14, // min + 3, // hr + 19, // day + 0, // tm_mon starts with 0 for Jan + 2038 - LIBC_NAMESPACE::time_constants::TIME_YEAR_BASE, // year + 2, // wday + 7, // yday + 0}), + *tm_data_ptr); EXPECT_TM_EQ(*tm_data_ptr, tm_data); } @@ -43,15 +42,16 @@ TEST(LlvmLibcGmTimeR, Max64BitYear) { struct tm tm_data; struct tm *tm_data_ptr; tm_data_ptr = LIBC_NAMESPACE::gmtime_r(&seconds, &tm_data); - EXPECT_TM_EQ((tm{50, // sec - 50, // min - 12, // hr - 1, // day - 0, // tm_mon starts with 0 for Jan - 2147483647 - TimeConstants::TIME_YEAR_BASE, // year - 2, // wday - 50, // yday - 0}), - *tm_data_ptr); + EXPECT_TM_EQ( + (tm{50, // sec + 50, // min + 12, // hr + 1, // day + 0, // tm_mon starts with 0 for Jan + 2147483647 - LIBC_NAMESPACE::time_constants::TIME_YEAR_BASE, // year + 2, // wday + 50, // yday + 0}), + *tm_data_ptr); EXPECT_TM_EQ(*tm_data_ptr, tm_data); } diff --git a/libc/test/src/time/gmtime_test.cpp b/libc/test/src/time/gmtime_test.cpp index 433fbf6..6af5a18 100644 --- a/libc/test/src/time/gmtime_test.cpp +++ b/libc/test/src/time/gmtime_test.cpp @@ -6,32 +6,36 @@ // //===----------------------------------------------------------------------===// +#include "hdr/types/struct_tm.h" #include "src/__support/CPP/limits.h" // INT_MAX, INT_MIN #include "src/errno/libc_errno.h" #include "src/time/gmtime.h" -#include "src/time/time_utils.h" +#include "src/time/time_constants.h" #include "test/UnitTest/ErrnoSetterMatcher.h" #include "test/UnitTest/Test.h" #include "test/src/time/TmMatcher.h" using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails; using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds; -using LIBC_NAMESPACE::time_utils::TimeConstants; TEST(LlvmLibcGmTime, OutOfRange) { if (sizeof(time_t) < sizeof(int64_t)) return; time_t seconds = - 1 + INT_MAX * static_cast<int64_t>( - TimeConstants::NUMBER_OF_SECONDS_IN_LEAP_YEAR); + 1 + + INT_MAX * + static_cast<int64_t>( + LIBC_NAMESPACE::time_constants::NUMBER_OF_SECONDS_IN_LEAP_YEAR); struct tm *tm_data = LIBC_NAMESPACE::gmtime(&seconds); EXPECT_TRUE(tm_data == nullptr); ASSERT_ERRNO_EQ(EOVERFLOW); LIBC_NAMESPACE::libc_errno = 0; - seconds = INT_MIN * static_cast<int64_t>( - TimeConstants::NUMBER_OF_SECONDS_IN_LEAP_YEAR) - - 1; + seconds = + INT_MIN * + static_cast<int64_t>( + LIBC_NAMESPACE::time_constants::NUMBER_OF_SECONDS_IN_LEAP_YEAR) - + 1; tm_data = LIBC_NAMESPACE::gmtime(&seconds); EXPECT_TRUE(tm_data == nullptr); ASSERT_ERRNO_EQ(EOVERFLOW); @@ -43,201 +47,215 @@ TEST(LlvmLibcGmTime, InvalidSeconds) { // -1 second from 1970-01-01 00:00:00 returns 1969-12-31 23:59:59. seconds = -1; tm_data = LIBC_NAMESPACE::gmtime(&seconds); - EXPECT_TM_EQ((tm{59, // sec - 59, // min - 23, // hr - 31, // day - 12 - 1, // tm_mon starts with 0 for Jan - 1969 - TimeConstants::TIME_YEAR_BASE, // year - 3, // wday - 364, // yday - 0}), - *tm_data); + EXPECT_TM_EQ( + (tm{59, // sec + 59, // min + 23, // hr + 31, // day + 12 - 1, // tm_mon starts with 0 for Jan + 1969 - LIBC_NAMESPACE::time_constants::TIME_YEAR_BASE, // year + 3, // wday + 364, // yday + 0}), + *tm_data); // 60 seconds from 1970-01-01 00:00:00 returns 1970-01-01 00:01:00. seconds = 60; tm_data = LIBC_NAMESPACE::gmtime(&seconds); - EXPECT_TM_EQ((tm{0, // sec - 1, // min - 0, // hr - 1, // day - 0, // tm_mon starts with 0 for Jan - 1970 - TimeConstants::TIME_YEAR_BASE, // year - 4, // wday - 0, // yday - 0}), - *tm_data); + EXPECT_TM_EQ( + (tm{0, // sec + 1, // min + 0, // hr + 1, // day + 0, // tm_mon starts with 0 for Jan + 1970 - LIBC_NAMESPACE::time_constants::TIME_YEAR_BASE, // year + 4, // wday + 0, // yday + 0}), + *tm_data); } TEST(LlvmLibcGmTime, InvalidMinutes) { time_t seconds = 0; struct tm *tm_data = nullptr; // -1 minute from 1970-01-01 00:00:00 returns 1969-12-31 23:59:00. - seconds = -TimeConstants::SECONDS_PER_MIN; + seconds = -LIBC_NAMESPACE::time_constants::SECONDS_PER_MIN; tm_data = LIBC_NAMESPACE::gmtime(&seconds); - EXPECT_TM_EQ((tm{0, // sec - 59, // min - 23, // hr - 31, // day - 11, // tm_mon starts with 0 for Jan - 1969 - TimeConstants::TIME_YEAR_BASE, // year - 3, // wday - 0, // yday - 0}), - *tm_data); + EXPECT_TM_EQ( + (tm{0, // sec + 59, // min + 23, // hr + 31, // day + 11, // tm_mon starts with 0 for Jan + 1969 - LIBC_NAMESPACE::time_constants::TIME_YEAR_BASE, // year + 3, // wday + 0, // yday + 0}), + *tm_data); // 60 minutes from 1970-01-01 00:00:00 returns 1970-01-01 01:00:00. - seconds = 60 * TimeConstants::SECONDS_PER_MIN; + seconds = 60 * LIBC_NAMESPACE::time_constants::SECONDS_PER_MIN; tm_data = LIBC_NAMESPACE::gmtime(&seconds); - EXPECT_TM_EQ((tm{0, // sec - 0, // min - 1, // hr - 1, // day - 0, // tm_mon starts with 0 for Jan - 1970 - TimeConstants::TIME_YEAR_BASE, // year - 4, // wday - 0, // yday - 0}), - *tm_data); + EXPECT_TM_EQ( + (tm{0, // sec + 0, // min + 1, // hr + 1, // day + 0, // tm_mon starts with 0 for Jan + 1970 - LIBC_NAMESPACE::time_constants::TIME_YEAR_BASE, // year + 4, // wday + 0, // yday + 0}), + *tm_data); } TEST(LlvmLibcGmTime, InvalidHours) { time_t seconds = 0; struct tm *tm_data = nullptr; // -1 hour from 1970-01-01 00:00:00 returns 1969-12-31 23:00:00. - seconds = -TimeConstants::SECONDS_PER_HOUR; + seconds = -LIBC_NAMESPACE::time_constants::SECONDS_PER_HOUR; tm_data = LIBC_NAMESPACE::gmtime(&seconds); - EXPECT_TM_EQ((tm{0, // sec - 0, // min - 23, // hr - 31, // day - 11, // tm_mon starts with 0 for Jan - 1969 - TimeConstants::TIME_YEAR_BASE, // year - 3, // wday - 0, // yday - 0}), - *tm_data); + EXPECT_TM_EQ( + (tm{0, // sec + 0, // min + 23, // hr + 31, // day + 11, // tm_mon starts with 0 for Jan + 1969 - LIBC_NAMESPACE::time_constants::TIME_YEAR_BASE, // year + 3, // wday + 0, // yday + 0}), + *tm_data); // 24 hours from 1970-01-01 00:00:00 returns 1970-01-02 00:00:00. - seconds = 24 * TimeConstants::SECONDS_PER_HOUR; + seconds = 24 * LIBC_NAMESPACE::time_constants::SECONDS_PER_HOUR; tm_data = LIBC_NAMESPACE::gmtime(&seconds); - EXPECT_TM_EQ((tm{0, // sec - 0, // min - 0, // hr - 2, // day - 0, // tm_mon starts with 0 for Jan - 1970 - TimeConstants::TIME_YEAR_BASE, // year - 5, // wday - 0, // yday - 0}), - *tm_data); + EXPECT_TM_EQ( + (tm{0, // sec + 0, // min + 0, // hr + 2, // day + 0, // tm_mon starts with 0 for Jan + 1970 - LIBC_NAMESPACE::time_constants::TIME_YEAR_BASE, // year + 5, // wday + 0, // yday + 0}), + *tm_data); } TEST(LlvmLibcGmTime, InvalidYear) { // -1 year from 1970-01-01 00:00:00 returns 1969-01-01 00:00:00. - time_t seconds = - -TimeConstants::DAYS_PER_NON_LEAP_YEAR * TimeConstants::SECONDS_PER_DAY; + time_t seconds = -LIBC_NAMESPACE::time_constants::DAYS_PER_NON_LEAP_YEAR * + LIBC_NAMESPACE::time_constants::SECONDS_PER_DAY; struct tm *tm_data = LIBC_NAMESPACE::gmtime(&seconds); - EXPECT_TM_EQ((tm{0, // sec - 0, // min - 0, // hr - 1, // day - 0, // tm_mon starts with 0 for Jan - 1969 - TimeConstants::TIME_YEAR_BASE, // year - 3, // wday - 0, // yday - 0}), - *tm_data); + EXPECT_TM_EQ( + (tm{0, // sec + 0, // min + 0, // hr + 1, // day + 0, // tm_mon starts with 0 for Jan + 1969 - LIBC_NAMESPACE::time_constants::TIME_YEAR_BASE, // year + 3, // wday + 0, // yday + 0}), + *tm_data); } TEST(LlvmLibcGmTime, InvalidMonths) { time_t seconds = 0; struct tm *tm_data = nullptr; // -1 month from 1970-01-01 00:00:00 returns 1969-12-01 00:00:00. - seconds = -31 * TimeConstants::SECONDS_PER_DAY; + seconds = -31 * LIBC_NAMESPACE::time_constants::SECONDS_PER_DAY; tm_data = LIBC_NAMESPACE::gmtime(&seconds); - EXPECT_TM_EQ((tm{0, // sec - 0, // min - 0, // hr - 1, // day - 12 - 1, // tm_mon starts with 0 for Jan - 1969 - TimeConstants::TIME_YEAR_BASE, // year - 1, // wday - 0, // yday - 0}), - *tm_data); + EXPECT_TM_EQ( + (tm{0, // sec + 0, // min + 0, // hr + 1, // day + 12 - 1, // tm_mon starts with 0 for Jan + 1969 - LIBC_NAMESPACE::time_constants::TIME_YEAR_BASE, // year + 1, // wday + 0, // yday + 0}), + *tm_data); // 1970-13-01 00:00:00 returns 1971-01-01 00:00:00. - seconds = - TimeConstants::DAYS_PER_NON_LEAP_YEAR * TimeConstants::SECONDS_PER_DAY; + seconds = LIBC_NAMESPACE::time_constants::DAYS_PER_NON_LEAP_YEAR * + LIBC_NAMESPACE::time_constants::SECONDS_PER_DAY; tm_data = LIBC_NAMESPACE::gmtime(&seconds); - EXPECT_TM_EQ((tm{0, // sec - 0, // min - 0, // hr - 1, // day - 0, // tm_mon starts with 0 for Jan - 1971 - TimeConstants::TIME_YEAR_BASE, // year - 5, // wday - 0, // yday - 0}), - *tm_data); + EXPECT_TM_EQ( + (tm{0, // sec + 0, // min + 0, // hr + 1, // day + 0, // tm_mon starts with 0 for Jan + 1971 - LIBC_NAMESPACE::time_constants::TIME_YEAR_BASE, // year + 5, // wday + 0, // yday + 0}), + *tm_data); } TEST(LlvmLibcGmTime, InvalidDays) { time_t seconds = 0; struct tm *tm_data = nullptr; // -1 day from 1970-01-01 00:00:00 returns 1969-12-31 00:00:00. - seconds = -1 * TimeConstants::SECONDS_PER_DAY; + seconds = -1 * LIBC_NAMESPACE::time_constants::SECONDS_PER_DAY; tm_data = LIBC_NAMESPACE::gmtime(&seconds); - EXPECT_TM_EQ((tm{0, // sec - 0, // min - 0, // hr - 31, // day - 11, // tm_mon starts with 0 for Jan - 1969 - TimeConstants::TIME_YEAR_BASE, // year - 3, // wday - 0, // yday - 0}), - *tm_data); + EXPECT_TM_EQ( + (tm{0, // sec + 0, // min + 0, // hr + 31, // day + 11, // tm_mon starts with 0 for Jan + 1969 - LIBC_NAMESPACE::time_constants::TIME_YEAR_BASE, // year + 3, // wday + 0, // yday + 0}), + *tm_data); // 1970-01-32 00:00:00 returns 1970-02-01 00:00:00. - seconds = 31 * TimeConstants::SECONDS_PER_DAY; + seconds = 31 * LIBC_NAMESPACE::time_constants::SECONDS_PER_DAY; tm_data = LIBC_NAMESPACE::gmtime(&seconds); - EXPECT_TM_EQ((tm{0, // sec - 0, // min - 0, // hr - 1, // day - 0, // tm_mon starts with 0 for Jan - 1970 - TimeConstants::TIME_YEAR_BASE, // year - 0, // wday - 0, // yday - 0}), - *tm_data); + EXPECT_TM_EQ( + (tm{0, // sec + 0, // min + 0, // hr + 1, // day + 0, // tm_mon starts with 0 for Jan + 1970 - LIBC_NAMESPACE::time_constants::TIME_YEAR_BASE, // year + 0, // wday + 0, // yday + 0}), + *tm_data); // 1970-02-29 00:00:00 returns 1970-03-01 00:00:00. - seconds = 59 * TimeConstants::SECONDS_PER_DAY; + seconds = 59 * LIBC_NAMESPACE::time_constants::SECONDS_PER_DAY; tm_data = LIBC_NAMESPACE::gmtime(&seconds); - EXPECT_TM_EQ((tm{0, // sec - 0, // min - 0, // hr - 1, // day - 2, // tm_mon starts with 0 for Jan - 1970 - TimeConstants::TIME_YEAR_BASE, // year - 0, // wday - 0, // yday - 0}), - *tm_data); + EXPECT_TM_EQ( + (tm{0, // sec + 0, // min + 0, // hr + 1, // day + 2, // tm_mon starts with 0 for Jan + 1970 - LIBC_NAMESPACE::time_constants::TIME_YEAR_BASE, // year + 0, // wday + 0, // yday + 0}), + *tm_data); // 1972-02-30 00:00:00 returns 1972-03-01 00:00:00. - seconds = ((2 * TimeConstants::DAYS_PER_NON_LEAP_YEAR) + 60) * - TimeConstants::SECONDS_PER_DAY; + seconds = + ((2 * LIBC_NAMESPACE::time_constants::DAYS_PER_NON_LEAP_YEAR) + 60) * + LIBC_NAMESPACE::time_constants::SECONDS_PER_DAY; tm_data = LIBC_NAMESPACE::gmtime(&seconds); - EXPECT_TM_EQ((tm{0, // sec - 0, // min - 0, // hr - 1, // day - 2, // tm_mon starts with 0 for Jan - 1972 - TimeConstants::TIME_YEAR_BASE, // year - 3, // wday - 0, // yday - 0}), - *tm_data); + EXPECT_TM_EQ( + (tm{0, // sec + 0, // min + 0, // hr + 1, // day + 2, // tm_mon starts with 0 for Jan + 1972 - LIBC_NAMESPACE::time_constants::TIME_YEAR_BASE, // year + 3, // wday + 0, // yday + 0}), + *tm_data); } TEST(LlvmLibcGmTime, EndOf32BitEpochYear) { @@ -245,16 +263,17 @@ TEST(LlvmLibcGmTime, EndOf32BitEpochYear) { // Test implementation can encode time for Tue 19 January 2038 03:14:07 UTC. time_t seconds = 0x7FFFFFFF; struct tm *tm_data = LIBC_NAMESPACE::gmtime(&seconds); - EXPECT_TM_EQ((tm{7, // sec - 14, // min - 3, // hr - 19, // day - 0, // tm_mon starts with 0 for Jan - 2038 - TimeConstants::TIME_YEAR_BASE, // year - 2, // wday - 7, // yday - 0}), - *tm_data); + EXPECT_TM_EQ( + (tm{7, // sec + 14, // min + 3, // hr + 19, // day + 0, // tm_mon starts with 0 for Jan + 2038 - LIBC_NAMESPACE::time_constants::TIME_YEAR_BASE, // year + 2, // wday + 7, // yday + 0}), + *tm_data); } TEST(LlvmLibcGmTime, Max64BitYear) { @@ -263,28 +282,30 @@ TEST(LlvmLibcGmTime, Max64BitYear) { // Mon Jan 1 12:50:50 2170 (200 years from 1970), time_t seconds = 6311479850; struct tm *tm_data = LIBC_NAMESPACE::gmtime(&seconds); - EXPECT_TM_EQ((tm{50, // sec - 50, // min - 12, // hr - 1, // day - 0, // tm_mon starts with 0 for Jan - 2170 - TimeConstants::TIME_YEAR_BASE, // year - 1, // wday - 50, // yday - 0}), - *tm_data); + EXPECT_TM_EQ( + (tm{50, // sec + 50, // min + 12, // hr + 1, // day + 0, // tm_mon starts with 0 for Jan + 2170 - LIBC_NAMESPACE::time_constants::TIME_YEAR_BASE, // year + 1, // wday + 50, // yday + 0}), + *tm_data); // Test for Tue Jan 1 12:50:50 in 2,147,483,647th year. seconds = 67767976202043050; tm_data = LIBC_NAMESPACE::gmtime(&seconds); - EXPECT_TM_EQ((tm{50, // sec - 50, // min - 12, // hr - 1, // day - 0, // tm_mon starts with 0 for Jan - 2147483647 - TimeConstants::TIME_YEAR_BASE, // year - 2, // wday - 50, // yday - 0}), - *tm_data); + EXPECT_TM_EQ( + (tm{50, // sec + 50, // min + 12, // hr + 1, // day + 0, // tm_mon starts with 0 for Jan + 2147483647 - LIBC_NAMESPACE::time_constants::TIME_YEAR_BASE, // year + 2, // wday + 50, // yday + 0}), + *tm_data); } diff --git a/libc/test/src/time/mktime_test.cpp b/libc/test/src/time/mktime_test.cpp index 84e6c7e..fe1116f 100644 --- a/libc/test/src/time/mktime_test.cpp +++ b/libc/test/src/time/mktime_test.cpp @@ -8,7 +8,7 @@ #include "src/__support/CPP/limits.h" // INT_MAX #include "src/time/mktime.h" -#include "src/time/time_utils.h" +#include "src/time/time_constants.h" #include "test/UnitTest/ErrnoSetterMatcher.h" #include "test/UnitTest/Test.h" #include "test/src/time/TmHelper.h" @@ -16,29 +16,37 @@ using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails; using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds; -using LIBC_NAMESPACE::time_utils::Month; +using LIBC_NAMESPACE::time_constants::Month; static inline constexpr int tm_year(int year) { - return year - TimeConstants::TIME_YEAR_BASE; + return year - LIBC_NAMESPACE::time_constants::TIME_YEAR_BASE; } TEST(LlvmLibcMkTime, FailureSetsErrno) { - struct tm tm_data { - .tm_sec = INT_MAX, .tm_min = INT_MAX, .tm_hour = INT_MAX, - .tm_mday = INT_MAX, .tm_mon = INT_MAX - 1, .tm_year = tm_year(INT_MAX), - .tm_wday = 0, .tm_yday = 0, .tm_isdst = 0 - }; + struct tm tm_data{.tm_sec = INT_MAX, + .tm_min = INT_MAX, + .tm_hour = INT_MAX, + .tm_mday = INT_MAX, + .tm_mon = INT_MAX - 1, + .tm_year = tm_year(INT_MAX), + .tm_wday = 0, + .tm_yday = 0, + .tm_isdst = 0}; EXPECT_THAT(LIBC_NAMESPACE::mktime(&tm_data), Fails(EOVERFLOW)); } TEST(LlvmLibcMkTime, InvalidSeconds) { { // -1 second from 1970-01-01 00:00:00 returns 1969-12-31 23:59:59. - struct tm tm_data { - .tm_sec = -1, .tm_min = 0, .tm_hour = 0, .tm_mday = 1, - .tm_mon = Month::JANUARY, .tm_year = tm_year(1970), .tm_wday = 0, - .tm_yday = 0, .tm_isdst = 0 - }; + struct tm tm_data{.tm_sec = -1, + .tm_min = 0, + .tm_hour = 0, + .tm_mday = 1, + .tm_mon = Month::JANUARY, + .tm_year = tm_year(1970), + .tm_wday = 0, + .tm_yday = 0, + .tm_isdst = 0}; EXPECT_THAT(LIBC_NAMESPACE::mktime(&tm_data), Succeeds(-1)); EXPECT_TM_EQ((tm{.tm_sec = 59, .tm_min = 59, @@ -54,11 +62,15 @@ TEST(LlvmLibcMkTime, InvalidSeconds) { { // 60 seconds from 1970-01-01 00:00:00 returns 1970-01-01 00:01:00. - struct tm tm_data { - .tm_sec = 60, .tm_min = 0, .tm_hour = 0, .tm_mday = 1, - .tm_mon = Month::JANUARY, .tm_year = tm_year(1970), .tm_wday = 0, - .tm_yday = 0, .tm_isdst = 0 - }; + struct tm tm_data{.tm_sec = 60, + .tm_min = 0, + .tm_hour = 0, + .tm_mday = 1, + .tm_mon = Month::JANUARY, + .tm_year = tm_year(1970), + .tm_wday = 0, + .tm_yday = 0, + .tm_isdst = 0}; EXPECT_THAT(LIBC_NAMESPACE::mktime(&tm_data), Succeeds(60)); EXPECT_TM_EQ((tm{.tm_sec = 0, .tm_min = 1, @@ -76,13 +88,17 @@ TEST(LlvmLibcMkTime, InvalidSeconds) { TEST(LlvmLibcMkTime, InvalidMinutes) { { // -1 minute from 1970-01-01 00:00:00 returns 1969-12-31 23:59:00. - struct tm tm_data { - .tm_sec = 0, .tm_min = -1, .tm_hour = 0, .tm_mday = 1, - .tm_mon = Month::JANUARY, .tm_year = tm_year(1970), .tm_wday = 0, - .tm_yday = 0, .tm_isdst = 0 - }; + struct tm tm_data{.tm_sec = 0, + .tm_min = -1, + .tm_hour = 0, + .tm_mday = 1, + .tm_mon = Month::JANUARY, + .tm_year = tm_year(1970), + .tm_wday = 0, + .tm_yday = 0, + .tm_isdst = 0}; EXPECT_THAT(LIBC_NAMESPACE::mktime(&tm_data), - Succeeds(-TimeConstants::SECONDS_PER_MIN)); + Succeeds(-LIBC_NAMESPACE::time_constants::SECONDS_PER_MIN)); EXPECT_TM_EQ((tm{.tm_sec = 0, .tm_min = 59, .tm_hour = 23, @@ -97,13 +113,17 @@ TEST(LlvmLibcMkTime, InvalidMinutes) { { // 60 minutes from 1970-01-01 00:00:00 returns 1970-01-01 01:00:00. - struct tm tm_data { - .tm_sec = 0, .tm_min = 60, .tm_hour = 0, .tm_mday = 1, - .tm_mon = Month::JANUARY, .tm_year = tm_year(1970), .tm_wday = 0, - .tm_yday = 0, .tm_isdst = 0 - }; + struct tm tm_data{.tm_sec = 0, + .tm_min = 60, + .tm_hour = 0, + .tm_mday = 1, + .tm_mon = Month::JANUARY, + .tm_year = tm_year(1970), + .tm_wday = 0, + .tm_yday = 0, + .tm_isdst = 0}; EXPECT_THAT(LIBC_NAMESPACE::mktime(&tm_data), - Succeeds(60 * TimeConstants::SECONDS_PER_MIN)); + Succeeds(60 * LIBC_NAMESPACE::time_constants::SECONDS_PER_MIN)); EXPECT_TM_EQ((tm{.tm_sec = 0, .tm_min = 0, .tm_hour = 1, @@ -120,13 +140,17 @@ TEST(LlvmLibcMkTime, InvalidMinutes) { TEST(LlvmLibcMkTime, InvalidHours) { { // -1 hour from 1970-01-01 00:00:00 returns 1969-12-31 23:00:00. - struct tm tm_data { - .tm_sec = 0, .tm_min = 0, .tm_hour = -1, .tm_mday = 1, - .tm_mon = Month::JANUARY, .tm_year = tm_year(1970), .tm_wday = 0, - .tm_yday = 0, .tm_isdst = 0 - }; + struct tm tm_data{.tm_sec = 0, + .tm_min = 0, + .tm_hour = -1, + .tm_mday = 1, + .tm_mon = Month::JANUARY, + .tm_year = tm_year(1970), + .tm_wday = 0, + .tm_yday = 0, + .tm_isdst = 0}; EXPECT_THAT(LIBC_NAMESPACE::mktime(&tm_data), - Succeeds(-TimeConstants::SECONDS_PER_HOUR)); + Succeeds(-LIBC_NAMESPACE::time_constants::SECONDS_PER_HOUR)); EXPECT_TM_EQ((tm{.tm_sec = 0, .tm_min = 0, .tm_hour = 23, @@ -141,13 +165,18 @@ TEST(LlvmLibcMkTime, InvalidHours) { { // 24 hours from 1970-01-01 00:00:00 returns 1970-01-02 00:00:00. - struct tm tm_data { - .tm_sec = 0, .tm_min = 0, .tm_hour = 24, .tm_mday = 1, - .tm_mon = Month::JANUARY, .tm_year = tm_year(1970), .tm_wday = 0, - .tm_yday = 0, .tm_isdst = 0 - }; - EXPECT_THAT(LIBC_NAMESPACE::mktime(&tm_data), - Succeeds(24 * TimeConstants::SECONDS_PER_HOUR)); + struct tm tm_data{.tm_sec = 0, + .tm_min = 0, + .tm_hour = 24, + .tm_mday = 1, + .tm_mon = Month::JANUARY, + .tm_year = tm_year(1970), + .tm_wday = 0, + .tm_yday = 0, + .tm_isdst = 0}; + EXPECT_THAT( + LIBC_NAMESPACE::mktime(&tm_data), + Succeeds(24 * LIBC_NAMESPACE::time_constants::SECONDS_PER_HOUR)); EXPECT_TM_EQ((tm{.tm_sec = 0, .tm_min = 0, .tm_hour = 0, @@ -163,14 +192,18 @@ TEST(LlvmLibcMkTime, InvalidHours) { TEST(LlvmLibcMkTime, InvalidYear) { // -1 year from 1970-01-01 00:00:00 returns 1969-01-01 00:00:00. - struct tm tm_data { - .tm_sec = 0, .tm_min = 0, .tm_hour = 0, .tm_mday = 1, - .tm_mon = Month::JANUARY, .tm_year = tm_year(1969), .tm_wday = 0, - .tm_yday = 0, .tm_isdst = 0 - }; + struct tm tm_data{.tm_sec = 0, + .tm_min = 0, + .tm_hour = 0, + .tm_mday = 1, + .tm_mon = Month::JANUARY, + .tm_year = tm_year(1969), + .tm_wday = 0, + .tm_yday = 0, + .tm_isdst = 0}; EXPECT_THAT(LIBC_NAMESPACE::mktime(&tm_data), - Succeeds(-TimeConstants::DAYS_PER_NON_LEAP_YEAR * - TimeConstants::SECONDS_PER_DAY)); + Succeeds(-LIBC_NAMESPACE::time_constants::DAYS_PER_NON_LEAP_YEAR * + LIBC_NAMESPACE::time_constants::SECONDS_PER_DAY)); EXPECT_TM_EQ((tm{.tm_sec = 0, .tm_min = 0, .tm_hour = 0, @@ -188,61 +221,85 @@ TEST(LlvmLibcMkTime, InvalidEndOf32BitEpochYear) { return; { // 2038-01-19 03:14:08 tests overflow of the second in 2038. - struct tm tm_data { - .tm_sec = 8, .tm_min = 14, .tm_hour = 3, .tm_mday = 19, - .tm_mon = Month::JANUARY, .tm_year = tm_year(2038), .tm_wday = 0, - .tm_yday = 0, .tm_isdst = 0 - }; + struct tm tm_data{.tm_sec = 8, + .tm_min = 14, + .tm_hour = 3, + .tm_mday = 19, + .tm_mon = Month::JANUARY, + .tm_year = tm_year(2038), + .tm_wday = 0, + .tm_yday = 0, + .tm_isdst = 0}; EXPECT_THAT(LIBC_NAMESPACE::mktime(&tm_data), Fails(EOVERFLOW)); } { // 2038-01-19 03:15:07 tests overflow of the minute in 2038. - struct tm tm_data { - .tm_sec = 7, .tm_min = 15, .tm_hour = 3, .tm_mday = 19, - .tm_mon = Month::JANUARY, .tm_year = tm_year(2038), .tm_wday = 0, - .tm_yday = 0, .tm_isdst = 0 - }; + struct tm tm_data{.tm_sec = 7, + .tm_min = 15, + .tm_hour = 3, + .tm_mday = 19, + .tm_mon = Month::JANUARY, + .tm_year = tm_year(2038), + .tm_wday = 0, + .tm_yday = 0, + .tm_isdst = 0}; EXPECT_THAT(LIBC_NAMESPACE::mktime(&tm_data), Fails(EOVERFLOW)); } { // 2038-01-19 04:14:07 tests overflow of the hour in 2038. - struct tm tm_data { - .tm_sec = 7, .tm_min = 14, .tm_hour = 4, .tm_mday = 19, - .tm_mon = Month::JANUARY, .tm_year = tm_year(2038), .tm_wday = 0, - .tm_yday = 0, .tm_isdst = 0 - }; + struct tm tm_data{.tm_sec = 7, + .tm_min = 14, + .tm_hour = 4, + .tm_mday = 19, + .tm_mon = Month::JANUARY, + .tm_year = tm_year(2038), + .tm_wday = 0, + .tm_yday = 0, + .tm_isdst = 0}; EXPECT_THAT(LIBC_NAMESPACE::mktime(&tm_data), Fails(EOVERFLOW)); } { // 2038-01-20 03:14:07 tests overflow of the day in 2038. - struct tm tm_data { - .tm_sec = 7, .tm_min = 14, .tm_hour = 3, .tm_mday = 20, - .tm_mon = Month::JANUARY, .tm_year = tm_year(2038), .tm_wday = 0, - .tm_yday = 0, .tm_isdst = 0 - }; + struct tm tm_data{.tm_sec = 7, + .tm_min = 14, + .tm_hour = 3, + .tm_mday = 20, + .tm_mon = Month::JANUARY, + .tm_year = tm_year(2038), + .tm_wday = 0, + .tm_yday = 0, + .tm_isdst = 0}; EXPECT_THAT(LIBC_NAMESPACE::mktime(&tm_data), Fails(EOVERFLOW)); } { // 2038-02-19 03:14:07 tests overflow of the month in 2038. - struct tm tm_data { - .tm_sec = 7, .tm_min = 14, .tm_hour = 3, .tm_mday = 19, - .tm_mon = Month::FEBRUARY, .tm_year = tm_year(2038), .tm_wday = 0, - .tm_yday = 0, .tm_isdst = 0 - }; + struct tm tm_data{.tm_sec = 7, + .tm_min = 14, + .tm_hour = 3, + .tm_mday = 19, + .tm_mon = Month::FEBRUARY, + .tm_year = tm_year(2038), + .tm_wday = 0, + .tm_yday = 0, + .tm_isdst = 0}; EXPECT_THAT(LIBC_NAMESPACE::mktime(&tm_data), Fails(EOVERFLOW)); } { // 2039-01-19 03:14:07 tests overflow of the year. - struct tm tm_data { - .tm_sec = 7, .tm_min = 14, .tm_hour = 3, .tm_mday = 19, - .tm_mon = Month::JANUARY, .tm_year = tm_year(2039), .tm_wday = 0, - .tm_yday = 0, .tm_isdst = 0 - }; + struct tm tm_data{.tm_sec = 7, + .tm_min = 14, + .tm_hour = 3, + .tm_mday = 19, + .tm_mon = Month::JANUARY, + .tm_year = tm_year(2039), + .tm_wday = 0, + .tm_yday = 0, + .tm_isdst = 0}; EXPECT_THAT(LIBC_NAMESPACE::mktime(&tm_data), Fails(EOVERFLOW)); } } @@ -250,12 +307,18 @@ TEST(LlvmLibcMkTime, InvalidEndOf32BitEpochYear) { TEST(LlvmLibcMkTime, InvalidMonths) { { // -1 month from 1970-01-01 00:00:00 returns 1969-12-01 00:00:00. - struct tm tm_data { - .tm_sec = 0, .tm_min = 0, .tm_hour = 0, .tm_mday = 0, .tm_mon = -1, - .tm_year = tm_year(1970), .tm_wday = 0, .tm_yday = 0, .tm_isdst = 0 - }; - EXPECT_THAT(LIBC_NAMESPACE::mktime(&tm_data), - Succeeds(-32 * TimeConstants::SECONDS_PER_DAY)); + struct tm tm_data{.tm_sec = 0, + .tm_min = 0, + .tm_hour = 0, + .tm_mday = 0, + .tm_mon = -1, + .tm_year = tm_year(1970), + .tm_wday = 0, + .tm_yday = 0, + .tm_isdst = 0}; + EXPECT_THAT( + LIBC_NAMESPACE::mktime(&tm_data), + Succeeds(-32 * LIBC_NAMESPACE::time_constants::SECONDS_PER_DAY)); EXPECT_TM_EQ((tm{.tm_sec = 0, .tm_min = 0, .tm_hour = 0, @@ -270,13 +333,19 @@ TEST(LlvmLibcMkTime, InvalidMonths) { { // 1970-13-01 00:00:00 returns 1971-01-01 00:00:00. - struct tm tm_data { - .tm_sec = 0, .tm_min = 0, .tm_hour = 0, .tm_mday = 1, .tm_mon = 12, - .tm_year = tm_year(1970), .tm_wday = 0, .tm_yday = 0, .tm_isdst = 0 - }; - EXPECT_THAT(LIBC_NAMESPACE::mktime(&tm_data), - Succeeds(TimeConstants::DAYS_PER_NON_LEAP_YEAR * - TimeConstants::SECONDS_PER_DAY)); + struct tm tm_data{.tm_sec = 0, + .tm_min = 0, + .tm_hour = 0, + .tm_mday = 1, + .tm_mon = 12, + .tm_year = tm_year(1970), + .tm_wday = 0, + .tm_yday = 0, + .tm_isdst = 0}; + EXPECT_THAT( + LIBC_NAMESPACE::mktime(&tm_data), + Succeeds(LIBC_NAMESPACE::time_constants::DAYS_PER_NON_LEAP_YEAR * + LIBC_NAMESPACE::time_constants::SECONDS_PER_DAY)); EXPECT_TM_EQ((tm{.tm_sec = 0, .tm_min = 0, .tm_hour = 0, @@ -293,13 +362,17 @@ TEST(LlvmLibcMkTime, InvalidMonths) { TEST(LlvmLibcMkTime, InvalidDays) { { // -1 day from 1970-01-01 00:00:00 returns 1969-12-31 00:00:00. - struct tm tm_data { - .tm_sec = 0, .tm_min = 0, .tm_hour = 0, .tm_mday = (1 - 1), - .tm_mon = Month::JANUARY, .tm_year = tm_year(1970), .tm_wday = 0, - .tm_yday = 0, .tm_isdst = 0 - }; + struct tm tm_data{.tm_sec = 0, + .tm_min = 0, + .tm_hour = 0, + .tm_mday = (1 - 1), + .tm_mon = Month::JANUARY, + .tm_year = tm_year(1970), + .tm_wday = 0, + .tm_yday = 0, + .tm_isdst = 0}; EXPECT_THAT(LIBC_NAMESPACE::mktime(&tm_data), - Succeeds(-1 * TimeConstants::SECONDS_PER_DAY)); + Succeeds(-1 * LIBC_NAMESPACE::time_constants::SECONDS_PER_DAY)); EXPECT_TM_EQ((tm{.tm_sec = 0, .tm_min = 0, .tm_hour = 0, @@ -314,13 +387,17 @@ TEST(LlvmLibcMkTime, InvalidDays) { { // 1970-01-32 00:00:00 returns 1970-02-01 00:00:00. - struct tm tm_data { - .tm_sec = 0, .tm_min = 0, .tm_hour = 0, .tm_mday = 32, - .tm_mon = Month::JANUARY, .tm_year = tm_year(1970), .tm_wday = 0, - .tm_yday = 0, .tm_isdst = 0 - }; + struct tm tm_data{.tm_sec = 0, + .tm_min = 0, + .tm_hour = 0, + .tm_mday = 32, + .tm_mon = Month::JANUARY, + .tm_year = tm_year(1970), + .tm_wday = 0, + .tm_yday = 0, + .tm_isdst = 0}; EXPECT_THAT(LIBC_NAMESPACE::mktime(&tm_data), - Succeeds(31 * TimeConstants::SECONDS_PER_DAY)); + Succeeds(31 * LIBC_NAMESPACE::time_constants::SECONDS_PER_DAY)); EXPECT_TM_EQ((tm{.tm_sec = 0, .tm_min = 0, .tm_hour = 0, @@ -335,13 +412,17 @@ TEST(LlvmLibcMkTime, InvalidDays) { { // 1970-02-29 00:00:00 returns 1970-03-01 00:00:00. - struct tm tm_data { - .tm_sec = 0, .tm_min = 0, .tm_hour = 0, .tm_mday = 29, - .tm_mon = Month::FEBRUARY, .tm_year = tm_year(1970), .tm_wday = 0, - .tm_yday = 0, .tm_isdst = 0 - }; + struct tm tm_data{.tm_sec = 0, + .tm_min = 0, + .tm_hour = 0, + .tm_mday = 29, + .tm_mon = Month::FEBRUARY, + .tm_year = tm_year(1970), + .tm_wday = 0, + .tm_yday = 0, + .tm_isdst = 0}; EXPECT_THAT(LIBC_NAMESPACE::mktime(&tm_data), - Succeeds(59 * TimeConstants::SECONDS_PER_DAY)); + Succeeds(59 * LIBC_NAMESPACE::time_constants::SECONDS_PER_DAY)); EXPECT_TM_EQ((tm{.tm_sec = 0, .tm_min = 0, .tm_hour = 0, @@ -356,14 +437,20 @@ TEST(LlvmLibcMkTime, InvalidDays) { { // 1972-02-30 00:00:00 returns 1972-03-01 00:00:00. - struct tm tm_data { - .tm_sec = 0, .tm_min = 0, .tm_hour = 0, .tm_mday = 30, - .tm_mon = Month::FEBRUARY, .tm_year = tm_year(1972), .tm_wday = 0, - .tm_yday = 0, .tm_isdst = 0 - }; - EXPECT_THAT(LIBC_NAMESPACE::mktime(&tm_data), - Succeeds(((2 * TimeConstants::DAYS_PER_NON_LEAP_YEAR) + 60) * - TimeConstants::SECONDS_PER_DAY)); + struct tm tm_data{.tm_sec = 0, + .tm_min = 0, + .tm_hour = 0, + .tm_mday = 30, + .tm_mon = Month::FEBRUARY, + .tm_year = tm_year(1972), + .tm_wday = 0, + .tm_yday = 0, + .tm_isdst = 0}; + EXPECT_THAT( + LIBC_NAMESPACE::mktime(&tm_data), + Succeeds(((2 * LIBC_NAMESPACE::time_constants::DAYS_PER_NON_LEAP_YEAR) + + 60) * + LIBC_NAMESPACE::time_constants::SECONDS_PER_DAY)); EXPECT_TM_EQ((tm{.tm_sec = 0, .tm_min = 0, .tm_hour = 0, @@ -381,11 +468,15 @@ TEST(LlvmLibcMkTime, EndOf32BitEpochYear) { // Test for maximum value of a signed 32-bit integer. // Test implementation can encode time for Tue 19 January 2038 03:14:07 UTC. { - struct tm tm_data { - .tm_sec = 7, .tm_min = 14, .tm_hour = 3, .tm_mday = 19, - .tm_mon = Month::JANUARY, .tm_year = tm_year(2038), .tm_wday = 0, - .tm_yday = 0, .tm_isdst = 0 - }; + struct tm tm_data{.tm_sec = 7, + .tm_min = 14, + .tm_hour = 3, + .tm_mday = 19, + .tm_mon = Month::JANUARY, + .tm_year = tm_year(2038), + .tm_wday = 0, + .tm_yday = 0, + .tm_isdst = 0}; EXPECT_THAT(LIBC_NAMESPACE::mktime(&tm_data), Succeeds(0x7FFFFFFF)); EXPECT_TM_EQ((tm{.tm_sec = 7, .tm_min = 14, @@ -403,11 +494,15 @@ TEST(LlvmLibcMkTime, EndOf32BitEpochYear) { { // 2038-01-19 03:13:59 tests that even a large seconds field is // accepted if the minutes field is smaller. - struct tm tm_data { - .tm_sec = 59, .tm_min = 13, .tm_hour = 3, .tm_mday = 19, - .tm_mon = Month::JANUARY, .tm_year = tm_year(2038), .tm_wday = 0, - .tm_yday = 0, .tm_isdst = 0 - }; + struct tm tm_data{.tm_sec = 59, + .tm_min = 13, + .tm_hour = 3, + .tm_mday = 19, + .tm_mon = Month::JANUARY, + .tm_year = tm_year(2038), + .tm_wday = 0, + .tm_yday = 0, + .tm_isdst = 0}; EXPECT_THAT(LIBC_NAMESPACE::mktime(&tm_data), Succeeds(0x7FFFFFFF - 8)); EXPECT_TM_EQ((tm{.tm_sec = 59, .tm_min = 13, @@ -424,13 +519,18 @@ TEST(LlvmLibcMkTime, EndOf32BitEpochYear) { { // 2038-01-19 02:59:59 tests that large seconds and minutes are // accepted if the hours field is smaller. - struct tm tm_data { - .tm_sec = 59, .tm_min = 59, .tm_hour = 2, .tm_mday = 19, - .tm_mon = Month::JANUARY, .tm_year = tm_year(2038), .tm_wday = 0, - .tm_yday = 0, .tm_isdst = 0 - }; + struct tm tm_data{.tm_sec = 59, + .tm_min = 59, + .tm_hour = 2, + .tm_mday = 19, + .tm_mon = Month::JANUARY, + .tm_year = tm_year(2038), + .tm_wday = 0, + .tm_yday = 0, + .tm_isdst = 0}; EXPECT_THAT(LIBC_NAMESPACE::mktime(&tm_data), - Succeeds(0x7FFFFFFF - 8 - 14 * TimeConstants::SECONDS_PER_MIN)); + Succeeds(0x7FFFFFFF - 8 - + 14 * LIBC_NAMESPACE::time_constants::SECONDS_PER_MIN)); EXPECT_TM_EQ((tm{.tm_sec = 59, .tm_min = 59, .tm_hour = 2, @@ -446,14 +546,19 @@ TEST(LlvmLibcMkTime, EndOf32BitEpochYear) { { // 2038-01-18 23:59:59 tests that large seconds, minutes and hours // are accepted if the days field is smaller. - struct tm tm_data { - .tm_sec = 59, .tm_min = 59, .tm_hour = 23, .tm_mday = 18, - .tm_mon = Month::JANUARY, .tm_year = tm_year(2038), .tm_wday = 0, - .tm_yday = 0, .tm_isdst = 0 - }; + struct tm tm_data{.tm_sec = 59, + .tm_min = 59, + .tm_hour = 23, + .tm_mday = 18, + .tm_mon = Month::JANUARY, + .tm_year = tm_year(2038), + .tm_wday = 0, + .tm_yday = 0, + .tm_isdst = 0}; EXPECT_THAT(LIBC_NAMESPACE::mktime(&tm_data), - Succeeds(0x7FFFFFFF - 8 - 14 * TimeConstants::SECONDS_PER_MIN - - 3 * TimeConstants::SECONDS_PER_HOUR)); + Succeeds(0x7FFFFFFF - 8 - + 14 * LIBC_NAMESPACE::time_constants::SECONDS_PER_MIN - + 3 * LIBC_NAMESPACE::time_constants::SECONDS_PER_HOUR)); EXPECT_TM_EQ((tm{.tm_sec = 59, .tm_min = 59, .tm_hour = 23, @@ -469,15 +574,20 @@ TEST(LlvmLibcMkTime, EndOf32BitEpochYear) { { // 2038-01-18 23:59:59 tests that the final second of 2037 is // accepted. - struct tm tm_data { - .tm_sec = 59, .tm_min = 59, .tm_hour = 23, .tm_mday = 31, - .tm_mon = Month::DECEMBER, .tm_year = tm_year(2037), .tm_wday = 0, - .tm_yday = 0, .tm_isdst = 0 - }; + struct tm tm_data{.tm_sec = 59, + .tm_min = 59, + .tm_hour = 23, + .tm_mday = 31, + .tm_mon = Month::DECEMBER, + .tm_year = tm_year(2037), + .tm_wday = 0, + .tm_yday = 0, + .tm_isdst = 0}; EXPECT_THAT(LIBC_NAMESPACE::mktime(&tm_data), - Succeeds(0x7FFFFFFF - 8 - 14 * TimeConstants::SECONDS_PER_MIN - - 3 * TimeConstants::SECONDS_PER_HOUR - - 18 * TimeConstants::SECONDS_PER_DAY)); + Succeeds(0x7FFFFFFF - 8 - + 14 * LIBC_NAMESPACE::time_constants::SECONDS_PER_MIN - + 3 * LIBC_NAMESPACE::time_constants::SECONDS_PER_HOUR - + 18 * LIBC_NAMESPACE::time_constants::SECONDS_PER_DAY)); EXPECT_TM_EQ((tm{.tm_sec = 59, .tm_min = 59, .tm_hour = 23, @@ -496,11 +606,15 @@ TEST(LlvmLibcMkTime, Max64BitYear) { return; { // Mon Jan 1 12:50:50 2170 (200 years from 1970), - struct tm tm_data { - .tm_sec = 50, .tm_min = 50, .tm_hour = 12, .tm_mday = 1, - .tm_mon = Month::JANUARY, .tm_year = tm_year(2170), .tm_wday = 0, - .tm_yday = 0, .tm_isdst = 0 - }; + struct tm tm_data{.tm_sec = 50, + .tm_min = 50, + .tm_hour = 12, + .tm_mday = 1, + .tm_mon = Month::JANUARY, + .tm_year = tm_year(2170), + .tm_wday = 0, + .tm_yday = 0, + .tm_isdst = 0}; EXPECT_THAT(LIBC_NAMESPACE::mktime(&tm_data), Succeeds(6311479850)); EXPECT_TM_EQ((tm{.tm_sec = 50, .tm_min = 50, @@ -516,11 +630,15 @@ TEST(LlvmLibcMkTime, Max64BitYear) { { // Test for Tue Jan 1 12:50:50 in 2,147,483,647th year. - struct tm tm_data { - .tm_sec = 50, .tm_min = 50, .tm_hour = 12, .tm_mday = 1, - .tm_mon = Month::JANUARY, .tm_year = tm_year(2147483647), .tm_wday = 0, - .tm_yday = 0, .tm_isdst = 0 - }; + struct tm tm_data{.tm_sec = 50, + .tm_min = 50, + .tm_hour = 12, + .tm_mday = 1, + .tm_mon = Month::JANUARY, + .tm_year = tm_year(2147483647), + .tm_wday = 0, + .tm_yday = 0, + .tm_isdst = 0}; EXPECT_THAT(LIBC_NAMESPACE::mktime(&tm_data), Succeeds(67767976202043050)); EXPECT_TM_EQ((tm{.tm_sec = 50, .tm_min = 50, diff --git a/libc/test/src/time/nanosleep_test.cpp b/libc/test/src/time/nanosleep_test.cpp index 2a6eea4..d4f98e2 100644 --- a/libc/test/src/time/nanosleep_test.cpp +++ b/libc/test/src/time/nanosleep_test.cpp @@ -6,8 +6,7 @@ // //===----------------------------------------------------------------------===// -#include <time.h> - +#include "hdr/types/struct_timespec.h" #include "src/errno/libc_errno.h" #include "src/time/nanosleep.h" #include "test/UnitTest/ErrnoSetterMatcher.h" diff --git a/libc/utils/CMakeLists.txt b/libc/utils/CMakeLists.txt index 11f2550..a33c13a 100644 --- a/libc/utils/CMakeLists.txt +++ b/libc/utils/CMakeLists.txt @@ -1,3 +1,5 @@ +add_subdirectory(hdrgen) + if(LLVM_INCLUDE_TESTS) add_subdirectory(MPFRWrapper) endif() diff --git a/libc/utils/docgen/arpa/inet.yaml b/libc/utils/docgen/arpa/inet.yaml index 7f388cb..d725759 100644 --- a/libc/utils/docgen/arpa/inet.yaml +++ b/libc/utils/docgen/arpa/inet.yaml @@ -1,18 +1,18 @@ functions: htonl: - posix-definition: '' + in-latest-posix: '' htons: - posix-definition: '' + in-latest-posix: '' inet_addr: - posix-definition: '' + in-latest-posix: '' inet_ntoa: - posix-definition: '' + in-latest-posix: '' inet_ntop: - posix-definition: '' + in-latest-posix: '' inet_pton: - posix-definition: '' + in-latest-posix: '' ntohl: - posix-definition: '' + in-latest-posix: '' ntohs: - posix-definition: '' + in-latest-posix: '' diff --git a/libc/utils/docgen/strings.yaml b/libc/utils/docgen/strings.yaml new file mode 100644 index 0000000..082b92c --- /dev/null +++ b/libc/utils/docgen/strings.yaml @@ -0,0 +1,26 @@ +functions: + bcmp: + removed-in-posix-2008: '' + bcopy: + removed-in-posix-2008: '' + bzero: + removed-in-posix-2008: '' + ffs: + in-latest-posix: '' + ffsl: + in-latest-posix: '' + ffsll: + in-latest-posix: '' + index: + removed-in-posix-2008: '' + rindex: + removed-in-posix-2008: '' + strcasecmp: + in-latest-posix: '' + strcasecmp_l: + in-latest-posix: '' + strncasecmp: + in-latest-posix: '' + strncasecmp_l: + in-latest-posix: '' + diff --git a/libc/utils/docgen/sys/mman.yaml b/libc/utils/docgen/sys/mman.yaml index dba26ca..94c6b9b 100644 --- a/libc/utils/docgen/sys/mman.yaml +++ b/libc/utils/docgen/sys/mman.yaml @@ -1,77 +1,77 @@ functions: mlock: - posix-definition: '' + in-latest-posix: '' mlockall: - posix-definition: '' + in-latest-posix: '' mmap: - posix-definition: '' + in-latest-posix: '' mprotect: - posix-definition: '' + in-latest-posix: '' msync: - posix-definition: '' + in-latest-posix: '' munlock: - posix-definition: '' + in-latest-posix: '' munlockall: - posix-definition: '' + in-latest-posix: '' munmap: - posix-definition: '' + in-latest-posix: '' posix_madvise: - posix-definition: '' + in-latest-posix: '' posix_mem_offset: - posix-definition: '' + in-latest-posix: '' posix_typed_mem_get_info: - posix-definition: '' + in-latest-posix: '' posix_typed_mem_open: - posix-definition: '' + in-latest-posix: '' shm_open: - posix-definition: '' + in-latest-posix: '' shm_unlink: - posix-definition: '' + in-latest-posix: '' macros: MAP_ANON: - posix-definition: '' + in-latest-posix: '' MAP_ANONYMOUS: - posix-definition: '' + in-latest-posix: '' MAP_FAILED: - posix-definition: '' + in-latest-posix: '' MAP_FIXED: - posix-definition: '' + in-latest-posix: '' MAP_PRIVATE: - posix-definition: '' + in-latest-posix: '' MAP_SHARED: - posix-definition: '' + in-latest-posix: '' MCL_CURRENT: - posix-definition: '' + in-latest-posix: '' MCL_FUTURE: - posix-definition: '' + in-latest-posix: '' MS_ASYNC: - posix-definition: '' + in-latest-posix: '' MS_INVALIDATE: - posix-definition: '' + in-latest-posix: '' MS_SYNC: - posix-definition: '' + in-latest-posix: '' POSIX_MADV_DONTNEED: - posix-definition: '' + in-latest-posix: '' POSIX_MADV_NORMAL: - posix-definition: '' + in-latest-posix: '' POSIX_MADV_RANDOM: - posix-definition: '' + in-latest-posix: '' POSIX_MADV_SEQUENTIAL: - posix-definition: '' + in-latest-posix: '' POSIX_MADV_WILLNEED: - posix-definition: '' + in-latest-posix: '' POSIX_TYPED_MEM_ALLOCATE: - posix-definition: '' + in-latest-posix: '' POSIX_TYPED_MEM_ALLOCATE_CONTIG: - posix-definition: '' + in-latest-posix: '' POSIX_TYPED_MEM_MAP_ALLOCATABLE: - posix-definition: '' + in-latest-posix: '' PROT_EXEC: - posix-definition: '' + in-latest-posix: '' PROT_NONE: - posix-definition: '' + in-latest-posix: '' PROT_READ: - posix-definition: '' + in-latest-posix: '' PROT_WRITE: - posix-definition: '' + in-latest-posix: '' diff --git a/libc/hdrgen/CMakeLists.txt b/libc/utils/hdrgen/CMakeLists.txt index 8ebde4e3..c6827da 100644 --- a/libc/hdrgen/CMakeLists.txt +++ b/libc/utils/hdrgen/CMakeLists.txt @@ -1,12 +1,12 @@ if(LLVM_LIBC_FULL_BUILD) enable_testing() - set(NEWHDGEN_TESTS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/tests) + set(HDRGEN_TESTS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/tests) set(TEST_OUTPUT_DIR ${CMAKE_BINARY_DIR}/hdrgen/output) add_test( NAME hdrgen_integration_test - COMMAND python3 ${NEWHDGEN_TESTS_DIR}/test_integration.py --output_dir ${TEST_OUTPUT_DIR} + COMMAND python3 ${HDRGEN_TESTS_DIR}/test_integration.py --output_dir ${TEST_OUTPUT_DIR} ) add_custom_target(check-hdrgen diff --git a/libc/utils/hdrgen/README.rst b/libc/utils/hdrgen/README.rst new file mode 100644 index 0000000..6db2968 --- /dev/null +++ b/libc/utils/hdrgen/README.rst @@ -0,0 +1,4 @@ +This directory also contains the Python sources for hdrgen, which is +what generates the headers public libc headers. The definitions for these +headers are in the ``include`` directory. The ``.h.def`` files are the bases +and the ``.yaml`` files are the contents. diff --git a/libc/hdrgen/class_implementation/classes/enumeration.py b/libc/utils/hdrgen/enumeration.py index b9848c0..b9848c0 100644 --- a/libc/hdrgen/class_implementation/classes/enumeration.py +++ b/libc/utils/hdrgen/enumeration.py diff --git a/libc/hdrgen/class_implementation/classes/function.py b/libc/utils/hdrgen/function.py index d97df7f..d97df7f 100644 --- a/libc/hdrgen/class_implementation/classes/function.py +++ b/libc/utils/hdrgen/function.py diff --git a/libc/hdrgen/gpu_headers.py b/libc/utils/hdrgen/gpu_headers.py index b26b3a8..8c4ff6e 100644 --- a/libc/hdrgen/gpu_headers.py +++ b/libc/utils/hdrgen/gpu_headers.py @@ -6,31 +6,9 @@ # # ==-------------------------------------------------------------------------==# +from header import HeaderFile -class GpuHeaderFile: - def __init__(self, name): - self.name = name - self.macros = [] - self.types = [] - self.enumerations = [] - self.objects = [] - self.functions = [] - - def add_macro(self, macro): - self.macros.append(macro) - - def add_type(self, type_): - self.types.append(type_) - - def add_enumeration(self, enumeration): - self.enumerations.append(enumeration) - - def add_object(self, object): - self.objects.append(object) - - def add_function(self, function): - self.functions.append(function) - +class GpuHeaderFile(HeaderFile): def __str__(self): content = [] diff --git a/libc/hdrgen/header.py b/libc/utils/hdrgen/header.py index df8ce61..9339acc 100644 --- a/libc/hdrgen/header.py +++ b/libc/utils/hdrgen/header.py @@ -9,6 +9,7 @@ class HeaderFile: def __init__(self, name): + self.template_file = None self.name = name self.macros = [] self.types = [] @@ -31,7 +32,7 @@ class HeaderFile: def add_function(self, function): self.functions.append(function) - def __str__(self): + def public_api(self): content = [""] for macro in self.macros: diff --git a/libc/hdrgen/class_implementation/classes/macro.py b/libc/utils/hdrgen/macro.py index 9a712f2..9a712f2 100644 --- a/libc/hdrgen/class_implementation/classes/macro.py +++ b/libc/utils/hdrgen/macro.py diff --git a/libc/utils/hdrgen/main.py b/libc/utils/hdrgen/main.py new file mode 100755 index 0000000..5dd392a --- /dev/null +++ b/libc/utils/hdrgen/main.py @@ -0,0 +1,91 @@ +#!/usr/bin/env python3 +# +# ===- Generate headers for libc functions ------------------*- python -*--==# +# +# 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 +# +# ==------------------------------------------------------------------------==# + +import argparse +import sys +from pathlib import Path + +from header import HeaderFile +from yaml_to_classes import load_yaml_file, fill_public_api + + +def main(): + parser = argparse.ArgumentParser(description="Generate header files from YAML") + parser.add_argument( + "yaml_file", + help="Path to the YAML file containing header specification", + metavar="FILE", + type=Path, + nargs=1, + ) + parser.add_argument( + "-o", + "--output", + help="Path to write generated header file", + type=Path, + required=True, + ) + parser.add_argument( + "--depfile", + help="Path to write a depfile", + type=Path, + ) + parser.add_argument( + "--write-if-changed", + help="Write the output file only if its contents have changed", + action="store_true", + default=False, + ) + parser.add_argument( + "-e", + "--entry-point", + help="Entry point to include; may be given many times", + metavar="SYMBOL", + action="append", + ) + args = parser.parse_args() + + [yaml_file] = args.yaml_file + files_read = {yaml_file} + + def write_depfile(): + if not args.depfile: + return + deps = " ".join(str(f) for f in sorted(files_read)) + args.depfile.parent.mkdir(parents=True, exist_ok=True) + with open(args.depfile, "w") as depfile: + depfile.write(f"{args.output}: {deps}\n") + + header = load_yaml_file(yaml_file, HeaderFile, args.entry_point) + + if not header.template_file: + print(f"{yaml_file}: Missing header_template", sys.stderr) + return 2 + + # The header_template path is relative to the containing YAML file. + template_path = yaml_file.parent / header.template_file + + files_read.add(template_path) + with open(template_path) as template: + contents = fill_public_api(header.public_api(), template.read()) + + write_depfile() + + if ( + not args.write_if_changed + or not args.output.exists() + or args.output.read_text() != contents + ): + args.output.parent.mkdir(parents=True, exist_ok=True) + args.output.write_text(contents) + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/libc/hdrgen/class_implementation/classes/object.py b/libc/utils/hdrgen/object.py index f521445..f521445 100644 --- a/libc/hdrgen/class_implementation/classes/object.py +++ b/libc/utils/hdrgen/object.py diff --git a/libc/hdrgen/tests/expected_output/test_header.h b/libc/utils/hdrgen/tests/expected_output/test_header.h index a777976..a777976 100644 --- a/libc/hdrgen/tests/expected_output/test_header.h +++ b/libc/utils/hdrgen/tests/expected_output/test_header.h diff --git a/libc/hdrgen/tests/input/test_small.h.def b/libc/utils/hdrgen/tests/input/test_small.h.def index 075be95..075be95 100644 --- a/libc/hdrgen/tests/input/test_small.h.def +++ b/libc/utils/hdrgen/tests/input/test_small.h.def diff --git a/libc/hdrgen/tests/input/test_small.yaml b/libc/utils/hdrgen/tests/input/test_small.yaml index 772552f..1d4b299 100644 --- a/libc/hdrgen/tests/input/test_small.yaml +++ b/libc/utils/hdrgen/tests/input/test_small.yaml @@ -1,4 +1,5 @@ -header: test_header.h +header: test_small.h +header_template: test_small.h.def macros: - macro_name: MACRO_A macro_value: 1 @@ -62,5 +63,3 @@ functions: - type: float standards: - stdc - - diff --git a/libc/hdrgen/tests/test_integration.py b/libc/utils/hdrgen/tests/test_integration.py index 8ea6d8a..49cb08cd 100644 --- a/libc/hdrgen/tests/test_integration.py +++ b/libc/utils/hdrgen/tests/test_integration.py @@ -1,36 +1,27 @@ +import argparse import subprocess +import sys import unittest from pathlib import Path -import os -import argparse -import sys class TestHeaderGenIntegration(unittest.TestCase): def setUp(self): - self.output_dir = Path( - args.output_dir if args.output_dir else "libc/hdrgen/tests/output" - ) - - self.maxDiff = None - - self.source_dir = Path(__file__).resolve().parent.parent.parent.parent + self.output_dir = TestHeaderGenIntegration.output_dir + self.source_dir = Path(__file__).parent + self.main_script = self.source_dir.parent / "main.py" - def run_script(self, yaml_file, h_def_file, output_dir, entry_points): - yaml_file = self.source_dir / yaml_file - h_def_file = self.source_dir / h_def_file + def run_script(self, yaml_file, output_file, entry_points): command = [ "python3", - str(self.source_dir / "libc/hdrgen/yaml_to_classes.py"), + str(self.main_script), str(yaml_file), - "--h_def_file", - str(h_def_file), - "--output_dir", - str(output_dir), + "--output", + str(output_file), ] for entry_point in entry_points: - command.extend(["--e", entry_point]) + command.extend(["--entry-point", entry_point]) result = subprocess.run( command, @@ -51,26 +42,23 @@ class TestHeaderGenIntegration(unittest.TestCase): self.assertEqual(gen_content, exp_content) def test_generate_header(self): - yaml_file = "libc/hdrgen/tests/input/test_small.yaml" - h_def_file = "libc/hdrgen/tests/input/test_small.h.def" - expected_output_file = ( - self.source_dir / "libc/hdrgen/tests/expected_output/test_header.h" - ) + yaml_file = self.source_dir / "input/test_small.yaml" + expected_output_file = self.source_dir / "expected_output/test_header.h" output_file = self.output_dir / "test_small.h" entry_points = {"func_b", "func_a", "func_c", "func_d", "func_e"} - if not self.output_dir.exists(): - self.output_dir.mkdir(parents=True) - - self.run_script(yaml_file, h_def_file, self.output_dir, entry_points) + self.run_script(yaml_file, output_file, entry_points) self.compare_files(output_file, expected_output_file) -if __name__ == "__main__": +def main(): parser = argparse.ArgumentParser(description="TestHeaderGenIntegration arguments") parser.add_argument( - "--output_dir", type=str, help="Output directory for generated headers" + "--output_dir", + type=Path, + help="Output directory for generated headers", + required=True, ) args, remaining_argv = parser.parse_known_args() @@ -79,3 +67,7 @@ if __name__ == "__main__": sys.argv[1:] = remaining_argv unittest.main() + + +if __name__ == "__main__": + main() diff --git a/libc/hdrgen/class_implementation/classes/type.py b/libc/utils/hdrgen/type.py index 4ebf803..4ebf803 100644 --- a/libc/hdrgen/class_implementation/classes/type.py +++ b/libc/utils/hdrgen/type.py diff --git a/libc/hdrgen/yaml_functions_sorted.py b/libc/utils/hdrgen/yaml_functions_sorted.py index b960ecaf..b960ecaf 100644 --- a/libc/hdrgen/yaml_functions_sorted.py +++ b/libc/utils/hdrgen/yaml_functions_sorted.py diff --git a/libc/hdrgen/yaml_to_classes.py b/libc/utils/hdrgen/yaml_to_classes.py index 0e8ca2d..d64feaf 100644 --- a/libc/hdrgen/yaml_to_classes.py +++ b/libc/utils/hdrgen/yaml_to_classes.py @@ -11,13 +11,14 @@ import yaml import argparse from pathlib import Path -from header import HeaderFile + +from enumeration import Enumeration +from function import Function from gpu_headers import GpuHeaderFile as GpuHeader -from class_implementation.classes.macro import Macro -from class_implementation.classes.type import Type -from class_implementation.classes.function import Function -from class_implementation.classes.enumeration import Enumeration -from class_implementation.classes.object import Object +from header import HeaderFile +from macro import Macro +from object import Object +from type import Type def yaml_to_classes(yaml_data, header_class, entry_points=None): @@ -34,6 +35,7 @@ def yaml_to_classes(yaml_data, header_class, entry_points=None): """ header_name = yaml_data.get("header") header = header_class(header_name) + header.template_file = yaml_data.get("header_template") for macro_data in yaml_data.get("macros", []): header.add_macro(Macro(macro_data["macro_name"], macro_data["macro_value"])) @@ -226,10 +228,6 @@ def main(): help="Directory to output the generated header file", ) parser.add_argument( - "--h_def_file", - help="Path to the .h.def template file (required if not using --export_decls)", - ) - parser.add_argument( "--add_function", nargs=6, metavar=( @@ -243,7 +241,10 @@ def main(): help="Add a function to the YAML file", ) parser.add_argument( - "--e", action="append", help="Entry point to include", dest="entry_points" + "--entry-point", + action="append", + help="Entry point to include", + dest="entry_points", ) parser.add_argument( "--export-decls", @@ -267,13 +268,7 @@ def main(): else: output_file_path = Path(f"{Path(args.yaml_file).stem}.h") - if not args.export_decls and args.h_def_file: - with open(args.h_def_file, "r") as f: - h_def_content = f.read() - final_header_content = fill_public_api(header_str, h_def_content) - with open(output_file_path, "w") as f: - f.write(final_header_content) - else: + if args.export_decls: with open(output_file_path, "w") as f: f.write(header_str) |