This class is intended to be used in cases where a class is being used
on a va_list. It provides destruction and copy semantics with small
overhead. This is intended to be used in printf.
Reviewed By: sivachandra, lntue
Differential Revision: https://reviews.llvm.org/D123061
A simple implementation of the getters and setters has been added. More
logic can be added to them in future as required.
Reviewed By: michaelrj
Differential Revision: https://reviews.llvm.org/D122969
Reduce the polynomial's degree from 7 down to 4.
Currently we use a degree-7 minimax polynomial on an interval of length 2^-7
around 0 to compute `expf`. Based on the suggestion of @santoshn and the RLIBM
project (https://github.com/rutgers-apl/rlibm-all/blob/main/source/float/exp.c)
and the improvement we made with `exp2f` in https://reviews.llvm.org/D122346,
it is possible to have a good polynomial of degree-4 on a subinterval of length
2^(-7) to approximate e^x.
We did try to either reduce the degree of the polynomial down to 3 or increase
the interval size to 2^(-6), but in both cases the number of exceptional values
exploded. So we settle with using a degree-4 polynomial of the interval of
size 2^(-7) around 0.
Reviewed By: sivachandra, zimmermann6, santoshn
Differential Revision: https://reviews.llvm.org/D122418
Reduce the range-reduction table size from 128 entries down to 64 entries, and
reduce the polynomial's degree from 6 down to 4.
Currently we use a degree-6 minimax polynomial on an interval of length 2^-7
around 0 to compute exp2f. Based on the suggestion of @santoshn and the RLIBM
project (https://github.com/rutgers-apl/rlibm-prog/blob/main/libm/float/exp2.c)
it is possible to have a good polynomial of degree-4 on a subinterval of length
2^(-6) to approximate 2^x.
We did try to either reduce the degree of the polynomial down to 3 or increase
the interval size to 2^(-5), but in both cases the number of exceptional values
exploded. So we settle with using a degree-4 polynomial of the interval of
size 2^(-6) around 0.
Reviewed By: michaelrj, sivachandra, zimmermann6, santoshn
Differential Revision: https://reviews.llvm.org/D122346
The main code for the FILE struct is only enabled on platforms that it
works on, but before this patch the tests were included unconditionally.
Reviewed By: sivachandra, lntue
Differential Revision: https://reviews.llvm.org/D122363
Previously, we used empty, non-ELF crti.o, crtn.o, libm.a and libc++.a
files. Instead, we now still use dummies but they are real ELF object
files and archives.
This patch adds aligned_alloc as an entrypoint. Previously it was being
included implicitly.
Reviewed By: sivachandra
Differential Revision: https://reviews.llvm.org/D122362
We were previously linking to libllvmlibc.a. But, with libllvmlibc.a now
including functions which depend on the loader, we will have to use the
LLVM libc loader as well. To avoid this, we will link to a special
library which is just a collection of SCUDO allocator entrypoints.
Reviewed By: michaelrj
Differential Revision: https://reviews.llvm.org/D122360
This patch primarily fixes the fenv implementation on Windows, since
Windows uses the MXCSR in place of the x87 status registers for storing
information about the floating point environment. This allows FEnv to
work correctly on Windows, and successfully build.
Reviewed By: lntue
Differential Revision: https://reviews.llvm.org/D121839
All existing loader tests are switched to an integration test added with
the new rule. Also, the getenv test is now enabled as an integration test.
All loader tests have been moved to test/integration. Also, the simple
checker library for the previous loader tests has been moved to a
separate directory of its own.
A follow up change will perform more cleanup of the loader CMake rules
to eliminate now redundent options.
Reviewed By: lntue, michaelrj
Differential Revision: https://reviews.llvm.org/D122266
This is now possible because we have a platform independent abstraction
for mutexes.
Reviewed By: lntue, michaelrj
Differential Revision: https://reviews.llvm.org/D121773
Implement expm1f function that is correctly rounded for all rounding modes. This is based on expf implementation.
From exhaustive testings, using expf implementation, and subtract 1.0 before rounding the final result to single precision
gives correctly rounded results for all |x| > 2^-4 with 1 exception. When |x| < 2^-25, we use x + x^2 (implemented with a
single fma). And for 2^-25 <= |x| <= 2^-4, we use a single degree-8 minimax polynomial generated by Sollya.
Reviewed By: sivachandra, zimmermann6
Differential Revision: https://reviews.llvm.org/D121574
Implement exp2f function that is correctly rounded for all rounding modes.
Reviewed By: sivachandra, zimmermann6
Differential Revision: https://reviews.llvm.org/D121463
Implement expf function that is correctly rounded for all rounding modes.
Reviewed By: sivachandra, zimmermann6
Differential Revision: https://reviews.llvm.org/D121440
The new container is used to store atexit callbacks. This way, we avoid
the possibility of the destructor of the container itself getting added
as an at exit callback.
Reviewed By: abrachet
Differential Revision: https://reviews.llvm.org/D121350
Add initial support for darwin-aarch64 (macOS M1).
Some differences compared to linux-aarch64:
- `math.h` defined `math_errhandling` by the compiler builtin `__math_errhandling()` but Apple Clang 13.0.0 on M1 does not support `__math_errhandling()` builtin as a macro function or a constexpr function.
- `math.h` defines `UNDERFLOW` and `OVERFLOW` macros.
- Besides 5 usual floating point exceptions: `FE_INEXACT`, `FE_UNDERFLOW`, `FE_OVERFLOW`, `FE_DIVBYZERO`, and `FE_INVALID`, `fenv.h` also has another floating point exception: `FE_FLUSHTOZERO`. The corresponding trap for `FE_FLUSHTOZERO` in the control register is at the different location compared to the status register.
- `FE_FLUSHTOZERO` exception flag cannot be raised with the default CPU floating point operation mode.
Reviewed By: sivachandra
Differential Revision: https://reviews.llvm.org/D120914
There were some "TODO" messages that were for things that I have already
completed. This patch removes those.
Reviewed By: michaelrj
Differential Revision: https://reviews.llvm.org/D121232
Previously, the entire support/CPP folder was in one header library,
which meant that a lot of headers were included where they shouldn't be.
This patch splits each header into its own target, as well as adjusting
each place they were included to only include what is used.
Reviewed By: sivachandra, lntue
Differential Revision: https://reviews.llvm.org/D121237
The loader TLS test for x86_64, which now passes, has been enabled.
A future change should enable the test for aarch64 as well.
Reviewed By: jeffbailey
Differential Revision: https://reviews.llvm.org/D121091
With modern architectures having a thread pointer and language supporting
thread locals, there is no reason to use a function intermediary to access
the thread local errno value.
The entrypoint corresponding to errno has been replaced with an object
library as there is no formal entrypoint for errno anymore.
Reviewed By: jeffbailey, michaelrj
Differential Revision: https://reviews.llvm.org/D120920
The upstream project ships CMake rules for building vanilla gtest/gmock which conflict with the names chosen by LLVM. Since LLVM's build rules here are quite specific to LLVM, prefixing them to avoid collision is the right thing (i.e. there does not appear to be a path to letting someone *replace* LLVM's googletest with one they bring, so co-existence should be the goal).
This allows LLVM to be included with testing enabled within projects that themselves have a dependency on an official gtest release.
Reviewed By: mehdi_amini
Differential Revision: https://reviews.llvm.org/D120789
New methods to the Atomic class have been added as required. Futex
related types have been consolidated at a common place.
Reviewed By: lntue
Differential Revision: https://reviews.llvm.org/D120705
Only the methods currently required by the libc have been added.
Most of the existing uses of atomic operations have been switched over
to this new class. A future change will clean up the rest of uses.
This change now allows building mutex and condition variable code with a
C++ compiler which does not have stdatomic.h, for example g++.
Reviewed By: lntue
Differential Revision: https://reviews.llvm.org/D120642
Often atexit is implemented using __cxa_atexit. I have not implemented __cxa_atexit here because it potentially requires more discussion. It is unique for llvm-libc (I think) that it is an exported symbol that wouldn’t be defined in any spec file because it doesn’t have a header. Implementing it will be trivial given what is here already, but I figured it would be more contentious so it can be implemented later.
Reviewed By: lntue
Differential Revision: https://reviews.llvm.org/D119512
Algorithm for hypotf: compute (a*a + b*b) in double precision, then use Dekker's algorithm to find the rounding error, and then correcting it after taking its square-root.
Reviewed By: sivachandra
Differential Revision: https://reviews.llvm.org/D118157
Add support for getenv as defined by the Open Group's "System Interface &
Header" in https://pubs.opengroup.org/onlinepubs/7908799/xsh/getenv.html
getenv requires a standard way of accessing the environment,
so a pointer to the environment is added to the startup in crt1.
Consquently, this function is not usable on top of other libcs.
Added starts_with method to StringView. getenv function uses it.
Co-authored-by: Jeff Bailey <jeffbailey@google.com>
Reviewed By: sivachandra, rtenneti
Differential Revision: https://reviews.llvm.org/D119403
Previously, allocator functions were only available if they were included
from scudo or by using the system libc headers (i.e. by turning off the
full build). This patch changes the logic to include the prototypes for
the allocator functitons in all cases, which allows the linker to link
in the system's allocator.
Reviewed By: sivachandra, abrachet
Differential Revision: https://reviews.llvm.org/D119587
the vector class, due to being dynamically resized, needs malloc. This
fixes the build so that it only includes it when malloc should be
available.
Differential Revision: https://reviews.llvm.org/D119464
Add a basic implementation of the vector class for use internally to
LLVM-libc.
Reviewed By: sivachandra
Differential Revision: https://reviews.llvm.org/D118954
Although type punning is defined for union in C, it is UB in C++.
This patch introduces a bit_cast function to convert between types in a safe way.
This is necessary to get llvm-libc compile with GCC.
This patch is extracted from D119002.
Differential Revision: https://reviews.llvm.org/D119145