Commit Graph

117 Commits

Author SHA1 Message Date
Siva Chandra Reddy 66d92efc66 [libc] Add trigonometric and exponential functions to the windows config. 2021-07-31 01:30:26 +00:00
Michael Jones c6d03b583b [libc] add strncmp to strings
Add strncmp as a function to strings.h. Also adds unit tests, and adds
strncmp as an entrypoint for all current platforms.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D106901
2021-07-28 21:37:12 +00:00
Siva Chandra Reddy dd8b93a9e7 [libc] Fix x86_64 fenv implementation for windows
All fenv functions are also enabled for windows. Since two tests,
enabled_exceptions_test and feholdexcept_test are still failing on
windows, they have been disabled.

Reviewed By: aeubanks

Differential Revision: https://reviews.llvm.org/D106808
2021-07-27 20:53:01 +00:00
Hedin Garca 8baa87d918 [libc] Enable MPFR library for math functions test
Included more math functions to Windows's entrypoints
and made a cmake option (-DLLVM_LIBC_MPFR_INSTALL_PATH)
where the user can specify the install path where the MPFR
library was built so it can be linked. The try_compile was
moved to LLVMLibCCheckMPFR.cmake, so the variable that is
set after this process can retain its value in other files
of the same parent file. A direct reason for this is for
LIBC_TESTS_CAN_USE_MPFR to be true when the user specifies
MPFR's path and retain its value even after leaving the file.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D106894
2021-07-27 20:40:04 +00:00
Hedin Garca efa2115266 [libc] Include nextafter's functions to Windows's entrypoints
Incorporated the varied functions for nextafter and refactored
NextAfterTest.h to correctly define bitWidthOfType for both
Linux and Windows; by letting FloatProperties take care
of the directives' logic based on the platform being used.
This allows to successfully run nextafter's tests.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D106395
2021-07-21 13:28:01 +00:00
Hedin Garca f49f2e2d1f [libc] Append math functions to Window's entrypoints
Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D106391
2021-07-21 13:21:55 +00:00
Caitlyn Cano e4b9fecd39 [libc] Add minimal Windows config
A README file with procedure for building/testing LLVM libc on Windows
has also been added.

Reviewed By: sivachandra, aeubanks

Differential Revision: https://reviews.llvm.org/D105231
2021-07-01 20:45:57 +00:00
Tue Ly 4e5f8b4d8d [libc] Add implementation of expm1f.
Use expm1f(x) = exp(x) - 1 for |x| > ln(2).
For |x| <= ln(2), divide it into 3 subintervals: [-ln2, -1/8], [-1/8, 1/8], [1/8, ln2]
and use a degree-6 polynomial approximation generated by Sollya's fpminmax for each interval.
Errors < 1.5 ULPs when we use fma to evaluate the polynomials.

Differential Revision: https://reviews.llvm.org/D101134
2021-06-10 14:58:34 -04:00
Siva Chandra Reddy b47539a14d [libc] Enable fmaf and fma on x86_64.
They require clang-11 or above for building and hence had to be disabled
as the bots did not have clang-11 or higher. Bots have now been upgraded
so we can enable these functions now.
2021-05-13 20:51:15 +00:00
Siva Chandra Reddy 861dc75906 [libc] Add x86_64 implementations of double precision cos, sin and tan.
The implementations use the x86_64 FPU instructions. These instructions
are extremely slow compared to a polynomial based software
implementation. Also, their accuracy falls drastically once the input
goes beyond 2PI. To improve both the speed and accuracy, we will be
taking the following approach going forward:
1. As a follow up to this CL, we will implement a range reduction algorithm
which will expand the accuracy to the entire double precision range.
2. After that, we will replace the HW instructions with a polynomial
implementation to improve the run time.

After step 2, the implementations will be accurate, performant and target
architecture independent.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D102384
2021-05-13 19:02:00 +00:00
Guillaume Chatelet 7c2ece523d [libc] Normalize LIBC_TARGET_MACHINE
Current implementation defines LIBC_TARGET_MACHINE with the use of CMAKE_SYSTEM_PROCESSOR.
Unfortunately CMAKE_SYSTEM_PROCESSOR is OS dependent and can produce different results.
An evidence of this is the various matchers used to detect whether the architecture is x86.

This patch normalizes LIBC_TARGET_MACHINE and renames it LIBC_TARGET_ARCHITECTURE.
I've added many architectures but we may want to limit ourselves to x86 and ARM.

Differential Revision: https://reviews.llvm.org/D101524
2021-05-05 15:52:42 +00:00
Raman Tenneti a72499e475 [libc] Introduce asctime, asctime_r to LLVM libc
[libc] Introduce asctime, asctime_r to LLVM libc

asctime and asctime_r share the same common code. They call asctime_internal
a static inline function.

asctime uses snprintf to return the string representation in a buffer.
It uses the following format (26 characters is the buffer size) as per
7.27.3.1 section in http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2478.pdf.
The buf parameter for asctime_r shall point to a buffer of at least 26 bytes.

snprintf(buf, 26, "%.3s %.3s%3d %.2d:%.2d:%.2d %d\n",...)

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D99686
2021-05-03 17:15:00 -07:00
Siva Chandra Reddy 653345155a [libc] Disable fma and fmaf for x86_64.
The version of clang installed on the buildbot workers is not able to
compile them. However, the version of gcc installed is able to compile
them fine. So, this change disables them until we can find a way to
compile them using clang on the buildbot workers.
2021-04-21 05:01:15 +00:00
Siva Chandra 95934c3a37 [libc] Add hardware implementations of fma and fmaf for x86_64 and aarch64.
The current generic implementation of the fmaf function has been moved
to the FPUtil directory. This allows one use the fma operation from
implementations of other math functions like the trignometric functions
without depending on/requiring the fma/fmaf/fmal function targets. If
this pattern ends being convenient, we will switch all generic math
implementations to this pattern.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D100811
2021-04-21 04:31:27 +00:00
Raman Tenneti 8b35159ac7 [libc] Introduces gmtime_r to LLVM libc, based on C99/C2X/Single Unix Sp.
gmtime and gmtime_r share the same common code. They call gmtime_internal
a static inline function. Thus added only validation tests for gmtime_r.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D99046
2021-03-22 14:04:05 -07:00
Raman Tenneti eaae52c1fd This introduces gmtime to LLVM libc, based on C99/C2X/Single Unix Spec.
This change doesn't handle TIMEZONE, tm_isdst and leap seconds.

Moved shared code between mktime and gmtime into time_utils.cpp.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D98467
2021-03-16 16:44:48 -07:00
Siva Chandra 954a7289d2 [libc] Adjust full build entrypoints for aarch64. 2021-03-12 13:50:56 -08:00
Siva Chandra Reddy e9e788d145 [libc] Introduce a full build mode CMake option.
This option will build LLVM libc as a full libc by itself. In this mode,
it is not expected that it will be mixed with other libcs. The
non-full-build mode will be the default LLVM libc build mode. In a future
where LLVM libc is complete enough, the full libc build will be made the
default mode.
2021-03-12 13:28:40 -08:00
Siva Chandra Reddy 8d4ac5337f [libc][NFC] Merge llvmlibc and llvmlibm targets in to a single target.
The single target is called llvmlibc. We can add back smaller libm and
other targets in future if required.
2021-02-23 21:29:06 -08:00
Siva Chandra Reddy b7e05c874b [libc] Add implementations of the remaining fenv functions.
Namely, implementations of fegetexceptfflag, fesetexceptflag,
fegetenv, fesetenv, feholdexcept and feupdateenv have been added.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D96935
2021-02-18 13:29:40 -08:00
Siva Chandra 53fcf6bb62 [libc][aarch64] Enable a bunch of math functions.
Namely, these are the functions enabled: rint*, lrint*, llrint*, lround*,
llround*, nearbyint*. They were previously not enabled because they
required rounding mode and FP exception support. Now that rounding mode
and FP exception support is available for Aarch64, they can be enabled.
2021-02-05 15:11:17 -08:00
Siva Chandra ec5a782c10 [libc] Fix list of public headers usable on aarch64. 2021-01-27 12:43:18 -08:00
Siva Chandra e958d49157 [libc] Fix the CMake var name of the list of public headers. 2021-01-27 12:13:35 -08:00
Siva Chandra d90bb66dd9 [libc] Include only the relevant header files in the integration test. 2021-01-27 11:15:12 -08:00
Siva Chandra 7bd3702b64 [libc] Extend the current fenv functions to aarch64.
This change does not try to move the common parts of x86 and aarch64 and
build few abstractions over them. While this is possible, x86 story
needs a bit of cleanup, especially around manipulation of the mxcsr
register. Moreover, on x86 one can raise exceptions without performing
exception raising operations. So, all of this can be done in follow up
patches.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D94947
2021-01-19 12:47:54 -08:00
Cheng Wang 2423ec5837 [libc] Add memmove implementation.
Use `memcpy` rather than copying bytes one by one, for there might be large
size structs to move.

Reviewed By: gchatelet, sivachandra

Differential Revision: https://reviews.llvm.org/D93195
2021-01-15 12:08:25 +08:00
Michael Jones 04edcc0263 [libc] add isascii and toascii implementations
adding both at once since these are trivial functions.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D94558
2021-01-12 23:41:20 +00:00
Tue Ly 4726bec8f2 [libc] Add implementation of fmaf.
Differential Revision: https://reviews.llvm.org/D94018
2021-01-06 17:14:20 -05:00
Siva Chandra Reddy 7f7b0dc4e1 [libc] Add implementations of nextafter[f|l] functions.
A differential fuzzer for these functions has also been added.
Along the way, a small correction has been done to the normal/subnormal
limits of x86 long double values.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D94109
2021-01-05 22:32:39 -08:00
Siva Chandra Reddy 993d8ac5cb [libc] Add implementations of nearbyint[f|l].
The implementation is exactly the same as rint* as even rint does not
raise any floating point exceptions currently. [Note that the standards
do not specify that floating point exceptions must be raised - they
leave it up to the implementation to choose to raise FE_INEXACT when
rounding non-integral values.]

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D94112
2021-01-05 21:51:10 -08:00
Siva Chandra Reddy ff6fd38552 [libc] Add implementations of rounding functions which depend rounding mode.
Namely, implementations for rint, rintf, rintl, lrint, lrintf, lrintl,
llrint, llrintf and llrintl have been added.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D93889
2020-12-29 22:22:02 -08:00
Siva Chandra f0cd6aa614 [libc] Add remainder[f|l] and remquo[f|l] to the list of aarch64 entrypoints. 2020-12-14 18:06:05 -08:00
Cheng Wang af68c3b892 [libc] Add memcmp implementation.
Reviewed By: gchatelet

Differential Revision: https://reviews.llvm.org/D93009
2020-12-15 09:47:29 +08:00
Siva Chandra Reddy 7aeb3804c4 [libc] Add implementations of lround[f|l] and llround[f|l].
A new function to MPFRWrapper has been added, which is used to set up
the unit tests.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D93007
2020-12-11 11:12:40 -08:00
Cheng Wang 1fd32dcb29 [libc] Add [l|ll]abs implementation.
Implement abs, labs and llabs with template.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D92626
2020-12-11 09:25:20 +08:00
Siva Chandra Reddy 4fff2a7e89 [libc] Add simple x86_64 floating point exception and rounding mode support.
Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D92546
2020-12-03 12:55:12 -08:00
Tue Ly 3b487d51e2 [libc] Add implementation of hypot.
Refactor src/math/hypotf.cpp and test/src/math/hypotf_test.cpp and reuse them for hypot and hypot_test

Differential Revision: https://reviews.llvm.org/D91831
2020-12-03 11:08:20 -05:00
Cheng Wang 60cef89362 [libc] Add strncpy implementation.
Add libc strncpy implementation.

Reviewed By: sivachandra, gchatelet

Differential Revision: https://reviews.llvm.org/D91399
2020-12-02 20:45:51 +08:00
Raman Tenneti 6f0f844e9a Initial commit of mktime.
This introduces mktime to LLVM libc, based on C99/C2X/Single Unix Spec.

Co-authored-by: Jeff Bailey <jeffbailey@google.com>

This change doesn't handle TIMEZONE,  tm_isdst and leap seconds.  It returns -1 for invalid dates. I have verified the return results for all the possible dates with glibc's mktime.

TODO:
+ Handle leap seconds.
+ Handle out of range time and date values that don't overflow or underflow.
+ Implement the following suggestion Siva - As we start accumulating the seconds, we should be able to check if the next amount of seconds to be added can lead to an overflow. If it does, return the overflow value.  If not keep accumulating. The benefit is that, we don't have to validate every input, and also do not need the special cases for sizeof(time_t) == 4.
+ Handle timezone and update of tm_isdst

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D91551
2020-11-30 21:07:16 -08:00
Siva Chandra Reddy bb8f2585c6 [libc] Add implementations of ldexp[f|l].
The rounding behavior of NormalFloat to float format has been changed
to round to nearest. Also, a bug in NormalFloat to subnormal number
conversion has been fixed.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D91591
2020-11-17 15:05:42 -08:00
Tue Ly d41280467d [libc] Add implementations of fdim[f|l].
Implementing fdim, fdimf, and fdiml for llvm-libc.

Differential Revision: https://reviews.llvm.org/D90906
2020-11-10 18:48:11 -05:00
Siva Chandra Reddy 930cf1cb9f [libc] Add implementations of ilogb[f|l].
Depends on D90805.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D90806
2020-11-05 16:27:44 -08:00
Michael Jones f6bf2823c4 [libc] Use entrypoints.txt as the single source of list of functions for a platform.
The function listings in api.td are removed. The same lists are now deduced using the information
in entrypoints.txt.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D89267
2020-10-15 20:46:13 +00:00
Tue Ly f55963d501 [libc] Add implementation for hypotf
Truncating the sum of squares, and then use shift-and-add algorithm to compute its square root.
Required MPFR testing infra is updated in https://reviews.llvm.org/D87514

Differential Revision: https://reviews.llvm.org/D87516
2020-09-17 23:28:36 -04:00
Guillaume Chatelet 85763e0758 [libc] Fix typo in platform_defs.h.inc
Differential Revision: https://reviews.llvm.org/D87687
2020-09-15 14:25:01 +00:00
Siva Chandra Reddy 8514ecb02d [libc] Add implementations of remquo[f|l] and remainder[f|l].
The implementation is not fully standards compliant in the sense that
errno is not set on error, and floating point exceptions are not raised.

Subnormal range and normal range are tested separately in the tests.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D86666
2020-09-03 22:00:17 -07:00
Tue Ly 5078825aa9 [libc] Add implementations for sqrt, sqrtf, and sqrtl.
Differential Revision: https://reviews.llvm.org/D84726
2020-08-26 09:46:18 -04:00
parallels bc45bab7eb [libc] Add strtok_r implementation.
Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D85779
2020-08-13 15:51:38 -04:00
cgyurgyik 667843cc07 [libc] Add strtok implementation.
Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D85615
2020-08-11 13:44:53 -04:00
Siva Chandra Reddy 5d59385ba6 [libc] Setup TLS in x86_64 loader.
The new code added is still very x86_64 specific. AArch64 support will
be added very soon and refactoring of the loader code will be done as
part of the patches adding it.

Reviewed By: asteinhauser

Differential Revision: https://reviews.llvm.org/D82700
2020-08-07 23:19:03 -07:00