This is a implementation of find remainder fmod function from standard libm.
The underline algorithm is developed by myself, but probably it was first
invented before.
Some features of the implementation:
1. The code is written on more-or-less modern C++.
2. One general implementation for both float and double precision numbers.
3. Spitted platform/architecture dependent and independent code and tests.
4. Tests covers 100% of the code for both float and double numbers. Tests cases with NaN/Inf etc is copied from glibc.
5. The new implementation in general 2-4 times faster for “regular” x,y values. It can be 20 times faster for x/y huge value, but can also be 2 times slower for double denormalized range (according to perf tests provided).
6. Two different implementation of division loop are provided. In some platforms division can be very time consuming operation. Depend on platform it can be 3-10 times slower than multiplication.
Performance tests:
The test is based on core-math project (https://gitlab.inria.fr/core-math/core-math). By Tue Ly suggestion I took hypot function and use it as template for fmod. Preserving all test cases.
`./check.sh <--special|--worst> fmodf` passed.
`CORE_MATH_PERF_MODE=rdtsc ./perf.sh fmodf` results are
```
GNU libc version: 2.35
GNU libc release: stable
21.166 <-- FPU
51.031 <-- current glibc
37.659 <-- this fmod version.
```
Tests for pthread_detach and thrd_detach have not been added. Instead, a
test for the underlying implementation has been added as it makes use of
an internal wait method to synchronize with detached threads.
Reviewed By: lntue, michaelrj
Differential Revision: https://reviews.llvm.org/D127479
Previously all FILE objects were fully buffered, this patch adds line
buffering and unbuffered output, as well as applying them to stdout and
stderr.
Reviewed By: sivachandra
Differential Revision: https://reviews.llvm.org/D126829
They do not yet support all the feature/attributes in pthread_attr_t.
Future changes will add such support.
Reviewed By: lntue
Differential Revision: https://reviews.llvm.org/D126718
They are added as entrypoint object targets. The header-gen
infrastructure has been extended to enable handling standard required
global objects. The libc-api-test has also been extended to verify the
global object declarations.
Reviewed By: lntue
Differential Revision: https://reviews.llvm.org/D126329
Simple implementations of the functions pthread_mutex_init,
pthread_mutex_destroy, pthread_mutex_lock and pthread_mutex_unlock have
have also been added. Future patches will extend these functions to add
features required by the POSIX specification.
Reviewed By: lntue
Differential Revision: https://reviews.llvm.org/D126235
After adding sprintf, snprintf is simple. The functions are very
similar. The tests only cover the behavior of the max length since the
sprintf tests should cover the other behavior.
Reviewed By: lntue
Differential Revision: https://reviews.llvm.org/D125826
This adds the sprintf entrypoint, as well as unit tests. Currently
sprintf only supports %%, %s, and %c, but the other conversions are on
the way.
Reviewed By: sivachandra, lntue
Differential Revision: https://reviews.llvm.org/D125573
Note that the underlying flush implementation does not yet fully implement
the POSIX standard. It is complete with respect to the C standard
however. A future change will add the POSIX behavior. It should not affect
the implementation of the fflush function however as the POSIX behavior
will be added in a lower layer.
Reviewed By: lntue
Differential Revision: https://reviews.llvm.org/D124073
POSIX locking and unlocking functions flockfile and funlockfile have
also been added. The locking is not recursive yet. A future patch will
make the underlying lock a recursive lock.
Reviewed By: lntue
Differential Revision: https://reviews.llvm.org/D123986
Not all attributes have been added to phtread_attr_t in this patch. They
will be added gradually in future patches.
Reviewed By: lntue
Differential Revision: https://reviews.llvm.org/D123423
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
This patch adds aligned_alloc as an entrypoint. Previously it was being
included implicitly.
Reviewed By: sivachandra
Differential Revision: https://reviews.llvm.org/D122362
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
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
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
They are implemented as simple syscall wrappers. The file creation
macros have been put in a header file as a temporary solution until we
have a cleaner approach to listing platform relevant macros.
Reviewed By: abrachet
Differential Revision: https://reviews.llvm.org/D118396
The type names in the spec are just sugar used by the header generator to
generate the function prototype. Giving the VarArgType a name of "..."
allows the header generator to treat and generate the "type name" for var
arg parameters similar to how it does for any other type.
Based on RLIBM implementation similar to logf and log2f. Most of the exceptional inputs are the exact powers of 10.
Reviewed By: sivachandra, zimmermann6, santoshn, jpl169
Differential Revision: https://reviews.llvm.org/D118093
Due to the differences between the types of long double, this function
is effectively three functions in one. This patch adds basic support for
the types of long double, although it's just using the fast path and the
fallback for the moment. I still need to implement a version of
Eisel-Lemire for performance, but the existing algorithms should be
correct.
Reviewed By: sivachandra, lntue
Differential Revision: https://reviews.llvm.org/D113710
Adds an implementation for stpcpy and stpncpy, which are posix extension
functions.
Reviewed By: sivachandra, lntue
Differential Revision: https://reviews.llvm.org/D111913
malloc, calloc, realloc, and free are all functions that other libc
functions depend on, but are pulled from external sources, instead of
having an internal implementation. This patch adds a way to include
functions like that as entrypoints in the list of external entrypoints,
and includes the malloc functions using this new path.
Reviewed By: sivachandra
Differential Revision: https://reviews.llvm.org/D112104
Add an implementation for memccpy and mempcpy. These functions are
posix extensions for the moment.
Reviewed By: lntue
Differential Revision: https://reviews.llvm.org/D111762
This patch adds a skeleton as a preparatory step for the next patch which
adds the actual implementations of the condition variable functions.
Reviewed By: michaelrj
Differential Revision: https://reviews.llvm.org/D108947
Add inttypes.h to llvm libc. As its first functions strtoimax and
strtoumax are included.
Reviewed By: sivachandra
Differential Revision: https://reviews.llvm.org/D108736