Commit Graph

1213 Commits

Author SHA1 Message Date
Siva Chandra Reddy 1ceafe5e0f [libc] Add implementation of ungetc.
A bug in the file read logic has also been fixed along the way. Parts
of the ungetc tests will fail without that bug fixed.

Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D137286
2022-11-02 22:45:57 +00:00
Siva Chandra Reddy 136b927c9e [libc] Add a doc about the libc fullbuild mode.
Reviewed By: jeffbailey

Differential Revision: https://reviews.llvm.org/D137061
2022-11-02 08:18:48 -07:00
Siva Chandra Reddy f7fd4f319a [libc] Add links to libc Discourse and to the libc Discord channel.
Reviewed By: jeffbailey

Differential Revision: https://reviews.llvm.org/D137229
2022-11-02 08:03:53 -07:00
Siva Chandra Reddy a2a87ee7e9 [libc] Add a contributing guide to the docs.
Reviewed By: jeffbailey

Differential Revision: https://reviews.llvm.org/D136961
2022-11-02 08:02:11 -07:00
Siva Chandra Reddy 9dd7388668 [libc] Add a porting guide to the docs.
Reviewed By: jeffbailey

Differential Revision: https://reviews.llvm.org/D136960
2022-11-02 07:59:07 -07:00
Guillaume Chatelet 67437dd014 [reland][libc] Switch to new implementation of mem* functions
The new framework makes it explicit which processor feature is being
used and allows for easier per platform customization:
 - ARM cpu now uses trivial implementations to reduce code size.
 - Memcmp, Bcmp and Memmove have been optimized for x86
 - Bcmp has been optimized for aarch64.

This is a reland of https://reviews.llvm.org/D135134 (b3f1d58, 0284148813)

Reviewed By: courbet

Differential Revision: https://reviews.llvm.org/D136595
2022-11-02 09:09:46 +00:00
Guillaume Chatelet 3635195e0d [libc] Improve testing of mem functions
This patch extracts the testing logic from `op_tests.cpp` into
`memory_check_utils.h` so we can reuse it for mem* function integration
tests.

This makes testing consistent and thorough.
For instance this catches a bug that got unnoticed during submission of
D136595 and D135134. Integration test for memcmp was only testing a
single size.

This also leverages ASAN to make sure that data is not read / written
outside permitted boundaries

Differential Revision: https://reviews.llvm.org/D136865
2022-11-02 08:55:46 +00:00
Siva Chandra Reddy 15ae08c1a1 [libc] Add definitions of a few missing macros and types. 2022-11-02 07:17:33 +00:00
Siva Chandra Reddy f357a41265 [libc][Obvious] Fix a typo in a CMake file. 2022-11-01 23:18:34 +00:00
Siva Chandra Reddy 3756227ef6 [libc] Skip setjmp tests under sanitizers. 2022-11-01 23:13:57 +00:00
Siva Chandra Reddy 3b82b4fbd5 [libc] Add x86_64 implementation of setjmp and longjmp.
Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D137147
2022-11-01 22:58:35 +00:00
Tue Ly 45233cc1ca [libc][math] Add place-holder implementation for pow function.
Add place-holder implementation for pow function to unblock libc demo
examples.

Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D137109
2022-10-31 17:23:33 -04:00
Tue Ly 97b4cc83e1 [libc][math] Add place-holder implementation for asin to unblock demo examples.
Add a place-holder implementation for asin to unblock libc demo
examples.

Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D137105
2022-10-31 17:22:12 -04:00
Alex Brachet 5fd03c8176 [libc] Implement getopt
Differential Revision: https://reviews.llvm.org/D133487
2022-10-31 16:55:53 +00:00
Siva Chandra Reddy 53c251bd05 [libc] Fix the return value of fread and fwrite.
They were previously returning the number of bytes read. They should
instead be returning the number of objects read.
2022-10-29 06:10:35 +00:00
Michael Jones f418f88824 [libc] add locale free strcoll
The strcoll function is intended to compare strings based on their
ordering in the current locale. Since the locale facilities have not yet
been added, a simple implementation that is the same as strcmp has been
added as a placeholder.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D136802
2022-10-28 11:13:07 -07:00
Michael Jones 1f54641d33 [libc][obvious] fix scanf parser test
One of the expected values wasn't being initialized correctly.

Differential Revision: https://reviews.llvm.org/D136965
2022-10-28 11:02:15 -07:00
Michael Jones 7a129f0756 [libc] add scanf parser and core utilities
This is the first piece of scanf. It's very similar in design to printf,
and so much of the code is copied from that. There were potential issues
with conflicting macros so I've also renamed the "ASSERT_FORMAT_EQ"
macro for printf to "ASSERT_PFORMAT_EQ".

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D136288
2022-10-28 10:52:51 -07:00
Michael Jones 374cebe8df [libc] add features to bitset
This patch adds the flip, set_range, and operator== functions to bitset.
These will be used in scanf.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D136881
2022-10-28 10:52:48 -07:00
Michael Jones 2d52283391 [libc] add fgets
This adds the fgets function and its unit tests.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D136785
2022-10-27 10:27:24 -07:00
Guillaume Chatelet b6d3ae3d3d Revert D136595 "[libc] Switch to new implementation of mem* functions"
This patch seems to introduce bugs on aarch64.
Reverting while we investigate the root cause.

This reverts commit 0284148813.
2022-10-27 08:38:46 +00:00
Alex Brachet d6ac84bce8 Revert "[libc] Implement getopt"
This reverts commit a678f86351.
2022-10-27 06:47:24 +00:00
Alex Brachet a678f86351 [libc] Implement getopt
Differential Revision: https://reviews.llvm.org/D133487
2022-10-27 06:23:33 +00:00
Siva Chandra 227eb3d72d [libc] Cleanup stale documentation. 2022-10-26 22:53:15 -07:00
Siva Chandra Reddy 89ba240f4b [libc] Add a doc about the libc overlay mode.
Reviewed By: jeffbailey

Differential Revision: https://reviews.llvm.org/D136810
2022-10-26 21:53:29 -07:00
Tue Ly 1427550151 [libc] Add a testing macro for MPFR matchers skipping `explainError` calls.
Adding `EXPECT_MPFR_MATCH_ROUNDING_SILENTLY` macro that does not call
`explainError` when the tests fail.  This is useful to check the passing or
failing rates, such as hitting percentages of fast passes in math
implementations.

Reviewed By: michaelrj, sivachandra

Differential Revision: https://reviews.llvm.org/D136731
2022-10-26 18:11:45 -04:00
Siva Chandra 07b7023181 [libc] Enable more entrypoints on aarch64. 2022-10-26 14:03:15 -07:00
Michael Jones 2cd20ad90e [libc] tighten strtofloat cutoffs
When a number for strtofloat has an exponent that's too big or small, it
doesn't need to be calculated precisely since it is guaranteed to be
either INF or 0.0. This tightens those cutoffs to improve performance.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D136699
2022-10-26 11:17:15 -07:00
Siva Chandra f8490601c2 [libc] Enable a few entrypoints on aarch64 already available on x86_64. 2022-10-25 15:41:41 -07:00
Siva Chandra Reddy 22ea0e5d9b [libc] Add Linux implementations of time and clock functions.
Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D136666
2022-10-25 18:06:05 +00:00
Guillaume Chatelet 0284148813 [libc] Switch to new implementation of mem* functions
The new framework makes it explicit which processor feature is being
used and allows for easier per platform customization:
 - ARM cpu now uses trivial implementations to reduce code size.
 - Memcmp, Bcmp and Memmove have been optimized for x86
 - Bcmp has been optimized for aarch64.

This is a reland of https://reviews.llvm.org/D135134 (b3f1d58)

Differential Revision: https://reviews.llvm.org/D136595
2022-10-25 10:49:34 +00:00
Siva Chandra Reddy 6faf40bb75 [libc] Add the header sys/types.h.
Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D136642
2022-10-25 00:24:49 +00:00
Raman Tenneti cec276ac91 [libc] Build fix.
Build fix.

Reviewed By: rtenneti

Differential Revision: https://reviews.llvm.org/D136647
2022-10-24 16:18:52 -07:00
Raman Tenneti 12204429f2 [libc] Add implementation of difftime function.
The difftime function computes the difference between two calendar
times: time1 - time0 as per as per 7.27.2.2 section in
http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2478.pdf.

  double difftime(time_t time1, time_t time0);

Tested:
Unit tests

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

Reviewed By: jeffbailey

Differential Revision: https://reviews.llvm.org/D136631
2022-10-24 15:14:26 -07:00
Michael Jones 551c7aed70 [libc] add performance options for string to float
This allows the client to set compile flags to disable the passes that
the string to float function uses. A client may be willing to trade off
performance for a reduction in code size, and this allows for that
fine-tuning.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D136495
2022-10-24 11:36:16 -07:00
Guillaume Chatelet d7917fdc0f [libc] Use cpp::byte instead of char in mem* functions
`cpp::byte` is better than `char` which -depending on platform- can be `signed char` or `unsigned char`.  This has introduced subtle arithmetic errors.
2022-10-24 10:30:32 +00:00
Guillaume Chatelet 282fe5084d [libc] Fix generic 32-bit implementation of Bcmp/Memcmp 2022-10-24 10:15:28 +00:00
Guillaume Chatelet 55509b1136 [libc] Fix broken tests on arm32 2022-10-24 09:54:19 +00:00
Guillaume Chatelet 69090143f5 [libc] mem* framework v3
This version is more composable and also simpler at the expense of being more explicit and more verbose.

This patch provides rationale for the framework, implementation and unit tests but the functions themselves are still using the previous version. The change in implementation will come in a follow up patch.

Differential Revision: https://reviews.llvm.org/D136292
2022-10-24 09:13:46 +00:00
Schrodinger ZHU Yifan 12c62a6718 clean up std::iterator in LibcBenchmark.h
Reviewed By: gchatelet

Differential Revision: https://reviews.llvm.org/D135540
2022-10-23 10:33:45 +00:00
Guillaume Chatelet 6abea7a17e
[libc] Add missing is_unsigned in type_traits.h 2022-10-23 12:08:44 +02:00
Guillaume Chatelet d02525cab7 [libc] Add cpp::byte
This provides the equivalent of std::byte.
std::byte is a distinct type that implements the concept of byte as specified in the C++ language definition.
https://en.cppreference.com/w/cpp/types/byte

Differential Revision: https://reviews.llvm.org/D136294
2022-10-22 20:54:14 +00:00
Siva Chandra Reddy 0480b45e9e [libc] Add implementation of fgetc.
Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D136421
2022-10-22 03:34:44 +00:00
Siva Chandra Reddy 2a038f9138 [libc] Add stdin definition.
Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D136398
2022-10-22 03:27:31 +00:00
Siva Chandra Reddy be4e425758 [libc] Add select.h and the implementation of the select function for Linux.
Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D136375
2022-10-22 03:17:48 +00:00
Siva Chandra Reddy 52d707d9fd [libc][Obvious] Add few missing license headers. 2022-10-21 00:01:36 +00:00
Michael Jones f1190bc0db [libc][obvious] fix comparison test cmake
The name of the libc target changed, this patch updates the cmake for
the string to float comparison test to use the correct name.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D136388
2022-10-20 16:23:32 -07:00
Guillaume Chatelet 3c438f6119 Revert D136292 "[libc] mem* framework v3"
This breaks llvm-libc build bots:
 - libc-x86_64-debian-dbg-asan
 - libc-x86_64-debian-fullbuild-dbg-asan
Address sanitizers fail with "AddressSanitizer: invalid alignment requested in aligned_alloc: 64, alignment must be a power of two and the requested size 0x41 must be a multiple of alignment (thread T0)"
 - libc-aarch64-ubuntu-dbg
 - libc-aarch64-ubuntu-fullbuild-dbg
https://lab.llvm.org/buildbot/#/builders/223/builds/8877/steps/7/logs/stdio
 - libc-arm32-debian-dbg
https://lab.llvm.org/buildbot/#/builders/229/builds/5201/steps/7/logs/stdio

This reverts commit 903cc71a82.
2022-10-20 13:59:05 +00:00
Guillaume Chatelet 903cc71a82 [libc] mem* framework v3
This version is more composable and also simpler at the expense of being more explicit and more verbose.

This patch provides rationale for the framework, implementation and unit tests but the functions themselves are still using the previous version. The change in implementation will come in a follow up patch.

Differential Revision: https://reviews.llvm.org/D136292
2022-10-20 13:44:07 +00:00
Guillaume Chatelet 35fb67a995 [libc][automemcpy] fix build after change in Arg enum 2022-10-20 11:59:19 +00:00