aboutsummaryrefslogtreecommitdiff
path: root/libc/src
AgeCommit message (Collapse)AuthorFilesLines
2024-04-01[libc][math] Implement atan2f correctly rounded to all rounding modes. (#86716)lntue5-71/+399
We compute atan2f(y, x) in 2 stages: - Fast step: perform computations in double precision , with relative errors < 2^-50 - Accurate step: if the result from the Fast step fails Ziv's rounding test, then we perform computations in double-double precision, with relative errors < 2^-100. On Ryzen 5900X, worst-case latency is ~ 200 clocks, compared to average latency ~ 60 clocks, and average reciprocal throughput ~ 20 clocks.
2024-04-01[libc] fixup missing include for fullbuild (#87266)Nick Desaulniers2-0/+2
Fixes #86928
2024-04-01[libc][POSIX] implement fseeko, ftello (#86928)Shourya Goel8-4/+117
Fixes: #85287
2024-04-01[libc] Include algorithm.h to parser.h (#87125)Caslyn Tonelli2-0/+2
This includes algorithm.h directly to provide the definition for `cpp:max` in parser.h. This will define `max(...)` in the libc namespace for build systems that pull in parser.h explicitly.
2024-03-29[libc][math][c23] Fix impl and tests for X86_80 canonicalize function. (#87103)Shourya Goel1-9/+12
In continuation to: #87097
2024-03-29Add bit width length modifier to printf (#82461)Om Prakaash5-18/+83
Resolves #81685. This adds support for wN and wfN length modifiers in fprintf.
2024-03-28Revert "[libc][math][c23] Fix X86_Binary80 special cases for canonicalize ↵Nick Desaulniers1-12/+9
functions. (#86924)" This reverts commit 7c1c07c92099d3e36e8f362706a5824ab04bdf38. Fails in presubmit. Link: https://lab.llvm.org/buildbot/#/builders/90/builds/67461 Link: https://lab.llvm.org/buildbot/#/builders/225/builds/33519 Link: https://lab.llvm.org/buildbot/#/builders/163/builds/53858 Link: https://lab.llvm.org/buildbot/#/builders/250/builds/20983 Link: #86924
2024-03-28[libc][math][c23] Fix X86_Binary80 special cases for canonicalize functions. ↵Shourya Goel1-9/+12
(#86924) Updates the special case of pseudo infinty as pointed in #85940
2024-03-28[libc][math][c23] Fix bounds checking and add FE_INVALID raising in ↵OverMighty1-5/+47
{,u}fromfp{,x}* (#86892) See https://github.com/llvm/llvm-project/pull/86692#issuecomment-2024044889 and https://github.com/llvm/llvm-project/pull/86892#discussion_r1542276037. cc @lntue @nickdesaulniers
2024-03-28[libc][support][FixedVector] add reverse iterator (#86732)Nick Desaulniers1-0/+8
Critically, we don't want to return an iterator to the end of the underlying cpp::array "store." Add a test to catch this issue. This will be used by __cxa_finalize to iterate backwards through a FixedVector. Link: #85651
2024-03-28[libc] s/NULL/nullptr (#86867)Nick Desaulniers5-8/+8
Otherwise we need to pull in stddef.h for the declaration of NULL.
2024-03-27[libc] Move baremetal write_to_stderr implementation to io.cpp (#86890)Petr Hosek3-6/+24
This is required to avoid multiple definitions error.
2024-03-27[libc][NFC] refactor fmin and fmax (#86718)Job Henandez Lara1-14/+10
Hello, So, I worked on the fmaximum and fminimum functions recently and the reviewers suggested the structure: ``` if (bitsx ...) return ...; if (bitsy ..) return ... return ...; ``` So I went ahead and did the same for fmin and fmax. I hope this isnt an issue for you all. thanks. --------- Co-authored-by: Job Hernandez <h93@protonmail.com>
2024-03-27[libc] Remove obsolete LIBC_HAS_BUILTIN macro (#86554)Marc Auberer23-102/+71
Fixes #86546 and removes the macro `LIBC_HAS_BUILTIN`. This was necessary to support older compilers that did not support `__has_builtin`. All of the compilers we support already have this builtin. See: https://libc.llvm.org/compiler_support.html All uses now use `__has_builtin` directly cc @nickdesaulniers
2024-03-27[libc][support][UInt] implement 128b math helpers (#86531)Nick Desaulniers2-1/+63
Flush out the remaining UInt<128> support and add test coverage. We could have used cpp::popcount in the implementation of UInt::has_single_bit, but has_single_bit has a perhaps useful early return.
2024-03-26[libc][FPUtil] fixup missing explicit cast (#86736)Nick Desaulniers1-1/+1
The arm32 buildbot reports an error because UInt::operator bool() is explicit, thus an explicit cast is necessary. Link: #85940
2024-03-26[libc] Fix misplaced `[[noreturn]]` attribute.Joseph Huber1-1/+1
Summary: This needs to go after `extern "C"`.
2024-03-26[libc] Remove LIBC_HAS_ATTRIBUTE macro (#86656)Vinayak Dev1-8/+0
Resolves #86547 Replace occurrences of the macro `LIBC_HAS_ATTRIBUTE` with `__has_attribute`.
2024-03-26[libc]: Remove unused includes from strfrom*.cpp (#86657)Vinayak Dev3-9/+0
Removes unused header includes from `strfrom*()` implementation files.
2024-03-26[libc][OSUtil] refactor quick_exit to be an object library everywhere (#85955)Nick Desaulniers14-111/+31
The usage of __builtin_unreachable after calls to quick_exit were distressing. If a function is properly marked [[noreturn]] then __builtin_unreachable is not necessary. Looking into this further, we seem to have header only implementations for CPU targets. The inline nature of these functions is curious; we're going to exit, it doesn't matter if we need to pay the call of a function or not. If we just make these functions have distinct TUs rather than be header only, we can clean up the cmake rules for quick_exit which were different between CPU and GPU. Remove darwin support for quick_exit. This isn't being tested, and we can bring it back when necessary.
2024-03-26[libc][math][c23] Implement canonicalize functions (#85940)Shourya Goel12-0/+270
Fixes: #85286
2024-03-25[libc][math][c23] add c23 floating point fmaximum and fminimum functions. ↵Job Henandez Lara67-0/+1773
(#86016) Fixes https://github.com/llvm/llvm-project/issues/85496. --------- Co-authored-by: Job Hernandez <h93@protonmail.com>
2024-03-25[libc] add statvfs/fstatvfs (#86169)Schrodinger ZHU Yifan8-0/+243
fixes #86449
2024-03-25[libc][NFC] fix typo (#86540)Alan Zhao1-2/+2
2024-03-25[libc][math][c23] Add {,u}fromfp{,x}{,f,l,f128} functions (#86003)OverMighty35-15/+903
Fixes #85279. cc @lntue
2024-03-22[libc] Implement strfromd() and strfroml() (#86113)Vinayak Dev6-1/+152
Follow up to #85438. Implements the functions `strfromd()` and `strfroml()` introduced in C23, and unifies the testing framework for `strfrom*()` functions.
2024-03-22Fix typo (#86319)Job Henandez Lara1-1/+1
Im working on the floating point fmaximum and fminimum functions right now in a different pr and I ran the individual tests by doing ``` ninja libc.test.src.math.smoke.<func>_test.__unit__ ```
2024-03-22[libc][stdlib] initial support for __cxa_finalize (#85865)Nick Desaulniers2-17/+22
I'm trying to break up the pieces of supporting __cxa_finalize into smaller commits. Provide this symbol first, and make use of it from exit. Next will be to store __dso_handle, then finally to only run callbacks that were registered from a specific dso. Link: #85651 Link: https://itanium-cxx-abi.github.io/cxx-abi/abi.html#dso-dtor
2024-03-22[reland][libc] Add reverse_iterator comparisons (#86188)Guillaume Chatelet1-0/+35
This is a reland of #86147 but with a proper `base()` function. https://en.cppreference.com/w/cpp/iterator/reverse_iterator/operator_cmp
2024-03-21Revert "[libc] Add reverse_iterator comparisons" (#86186)Guillaume Chatelet1-35/+0
Reverts llvm/llvm-project#86147
2024-03-21[libc] Add reverse_iterator comparisons (#86147)Guillaume Chatelet1-0/+35
https://en.cppreference.com/w/cpp/iterator/reverse_iterator/operator_cmp
2024-03-21[libc][stdio] implement rename via SYS_renameat2 (#86140)Nick Desaulniers1-1/+3
SYS_rename may be unavailable on architectures such as aarch64 and riscv. rename can be implemented in terms of SYS_rename, SYS_renameat, or SYS_renameat2. I don't have a full picture of the history here, but it seems that SYS_renameat might also be unavailable on some platforms. `man 2 rename` mentions that SYS_renameat2 was added in Linux 3.15. We don't need to support such ancient kernel versions prior. Link: #84980 Link: #85068
2024-03-21[libc] Add `is_constant_evaluated` type_traits (#86139)Guillaume Chatelet3-2/+25
This will replace `__builtin_is_constant_evaluated` in math_extras.h.
2024-03-21[libc][c11] Add stdio.h's rename() function (#85068)aniplcc4-0/+63
Adds stdio.h's rename() function as defined in n3096. Fixes #84980.
2024-03-20[libc]: Implement strfromf() and shared utilities (#85438)Vinayak Dev4-0/+223
Fixes #84244. Implements the function `strfromf()` introduced in C23, and adds shared utilities for implementation of other `strfrom*()` functions, including `strfromd()` and `strfroml()`.
2024-03-20[libc][NFC] Move `Sign` type to separate header (#85930)Guillaume Chatelet27-57/+76
2024-03-19[libc] Make 'printf' converter output "(null)" instead of "null" (#85845)Joseph Huber1-1/+1
Summary: Currently we print `null` for the null pointer in a `%s` expression. Although it's not defined by the standard, other implementations choose to use `(null)` to indicate this. We also currently print `(nullptr)` so I think it's more consistent to use parens in both cases.
2024-03-19[libc][cpp] reverse_iterator support (#85702)Nick Desaulniers2-0/+86
Towards the goal of implementing __cxa_finalize (#85651) I'd like to be able to reverse iterate over cpp::arrays such as the one used in FixedVector. Implement the enough iterator support to be able to iterate a cpp::array in reverse, and add tests. Of note, reverse iterator's begin() refers to forward iterator's end() (and vice versa). When dereferenced (operator*), the reverse iterator returns a copy that's been pre-decremented (the underlying forward iterator is advanced).
2024-03-19[libc] Prevent constant propagation for atanf(+-Inf) in gcc. (#85733)lntue1-2/+4
gcc bot failures with `atanf(+-Inf)`: https://lab.llvm.org/buildbot/#/builders/250/builds/20331/steps/8/logs/stdio
2024-03-18[libc] Remove constexpr from atan_eval and asin_eval. (#85725)lntue1-2/+2
Fix aarch64 and gcc full build bots: https://lab.llvm.org/buildbot/#/builders/223/builds/38235/steps/4/logs/stdio
2024-03-18[libc][math] Improve atanf performance. (#85463)lntue4-126/+176
Simplify the range reduction logic and computations. Performance test using `perf.sh` from CORE-MATH project on Ryzen 5900X: Before: ``` $ ./perf.sh atanf --rdtsc --path1 LIBC-location: /home/lnt/experiment/llvm-project/build/projects/libc/lib/libllvmlibc.a GNU libc version: 2.35 GNU libc release: stable -- CORE-MATH reciprocal throughput -- [####################] 100 % Ntrial = 20 ; Min = 14.369 + 0.556 clc/call; Median-Min = 0.613 clc/call; Max = 15.061 clc/call; -- System LIBC reciprocal throughput -- [####################] 100 % Ntrial = 20 ; Min = 26.180 + 0.015 clc/call; Median-Min = 0.014 clc/call; Max = 26.260 clc/call; -- LIBC reciprocal throughput -- [####################] 100 % Ntrial = 20 ; Min = 21.237 + 0.022 clc/call; Median-Min = 0.020 clc/call; Max = 21.272 clc/call; $ ./perf.sh atanf --rdtsc --path1 --latency LIBC-location: /home/lnt/experiment/llvm-project/build/projects/libc/lib/libllvmlibc.a GNU libc version: 2.35 GNU libc release: stable -- CORE-MATH latency -- [####################] 100 % Ntrial = 20 ; Min = 50.505 + 0.045 clc/call; Median-Min = 0.037 clc/call; Max = 50.579 clc/call; -- System LIBC latency -- [####################] 100 % Ntrial = 20 ; Min = 62.438 + 0.836 clc/call; Median-Min = 0.049 clc/call; Max = 64.498 clc/call; -- LIBC latency -- [####################] 100 % Ntrial = 20 ; Min = 67.781 + 0.546 clc/call; Median-Min = 0.028 clc/call; Max = 68.844 clc/call; ``` After: ``` $ ./perf.sh atanf --rdtsc --path2 LIBC-location: /home/lnt/experiment/llvm/llvm-project/build/projects/libc/lib/libllvmlibc.a GNU libc version: 2.35 GNU libc release: stable -- CORE-MATH reciprocal throughput -- [####################] 100 % Ntrial = 20 ; Min = 14.400 + 0.353 clc/call; Median-Min = 0.404 clc/call; Max = 14.863 clc/call; -- System LIBC reciprocal throughput -- [####################] 100 % Ntrial = 20 ; Min = 25.247 + 0.783 clc/call; Median-Min = 0.714 clc/call; Max = 26.238 clc/call; -- LIBC reciprocal throughput -- [####################] 100 % Ntrial = 20 ; Min = 13.751 + 0.158 clc/call; Median-Min = 0.140 clc/call; Max = 14.006 clc/call; $ ./perf.sh atanf --rdtsc --path2 --latency LIBC-location: /home/lnt/experiment/llvm/llvm-project/build/projects/libc/lib/libllvmlibc.a GNU libc version: 2.35 GNU libc release: stable -- CORE-MATH latency -- [####################] 100 % Ntrial = 20 ; Min = 51.837 + 0.073 clc/call; Median-Min = 0.058 clc/call; Max = 52.000 clc/call; -- System LIBC latency -- [####################] 100 % Ntrial = 20 ; Min = 62.487 + 1.878 clc/call; Median-Min = 1.965 clc/call; Max = 64.569 clc/call; OK -- LIBC latency -- [####################] 100 % Ntrial = 20 ; Min = 55.414 + 1.312 clc/call; Median-Min = 0.345 clc/call; Max = 58.362 clc/call; ```
2024-03-18[libc] Remove direct math.h includes (#85324)Michael Jones4-8/+4
Reland of #84991 A downstream overlay mode user ran into issues with the isnan macro not working in our sources with a specific libc configuration. This patch replaces the last direct includes of math.h with our internal math_macros.h, along with the necessary build system changes.
2024-03-18[libc] Implement fileno (#85628)Shourya Goel4-0/+64
fixes: #85150
2024-03-18[libc] Add `shm_open/shm_unlink` (#84974)Schrodinger ZHU Yifan8-2/+208
2024-03-17[libc] remove.cpp dependency on libc.include.stdioPetr Hosek2-0/+3
This addresses a build error introduced by 5a75242bc898886b9833e328ad5f656246424a81.
2024-03-16[libc] Include empty remove in baremetal stdio.h (#85336)Petr Hosek2-0/+26
This is required to avoid compilation error in libc++. See #85335 for more details.
2024-03-16[libc][math][c23] Add nextupl and nextdownl functions (#85484)OverMighty8-0/+161
Fixes #85283. cc @lntue
2024-03-15[libc][math][c23] Add nextup{,f,f128} and nextdown{,f,f128} functions (#85431)OverMighty15-0/+332
See https://github.com/llvm/llvm-project/issues/85283. I had a test for `nextdownl` that was failing and I thought I should add `nextupl` and `nextdownl` later and first make a PR for the other functions. cc @lntue
2024-03-15[libc][math][c23] adds `nanf128` (#85201)Michael Flanders8-42/+153
Continuing #84689, this one required more changes than the others, so I am making it a separate PR. Extends some stuff in `str_to_float.h`, `str_to_integer.h` to work on types wider than `unsigned long long` and `uint64_t`. cc @lntue for review.
2024-03-15[libc] remove BlockStore from cpp namespace (#85312)Nick Desaulniers2-3/+1
The cpp namespace should only be used to mirror APIs from C++'s std:: namespace (at least until we share more code with libc++, see https://discourse.llvm.org/t/rfc-project-hand-in-hand-llvm-libc-libc-code-sharing/77701)