Commit Graph

1231 Commits

Author SHA1 Message Date
Raman Tenneti 35155ee7d3 Removed tabs. 2022-11-11 18:11:06 -08:00
Raman Tenneti 78f172e45a [libc] Implement gettimeofday
Implement gettimeofday per
.../onlinepubs/9699919799/functions/gettimeofday.html.
This call clock_gettime to implement gettimeofday function.

Tested:
Limited unit test: This makes a call and checks that no error was
returned. Used nanosleep for 100 microseconds and verfified it
returns a value that elapses more than 100 microseconds and less
than 300 microseconds.

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

Differential Revision: https://reviews.llvm.org/D137881
2022-11-11 18:02:33 -08:00
Michael Jones 4d25761b07 [libc] move fork into threads folder
Fork, as a thread function, should go in the threads folder.
Additionally, it depends on the thread mutex, and it was causing build
issues for targets where we don't support threads.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D137867
2022-11-11 16:01:39 -08:00
Michael Jones 430ca14af8 [libc][obvious] fix tests using wrong size for string
In the code
const char *str = "abc"
if you do sizeof(str) you get the size of the pointer, not the string.
This patch fixes that mistake.

Differential Revision: https://reviews.llvm.org/D137586
2022-11-07 14:04:39 -08:00
Michael Jones 1c40d5ec7d [libc] add scanf string converters
This patch adds the basic conversion facilities to scanf as well as unit
tests for them. It also adds scanf_main which will be used for the
eventual scanf entrypoints.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D137376
2022-11-07 13:49:01 -08:00
Michael Jones 0c8db885f6 [libc] add scanf reader
This is the interface that will be used to read from a file or string in
scanf. This patch also adds the string and file implementations of the
reader, although the file reader is not yet complete since ungetc has
not yet been implemented.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D137117
2022-11-07 13:48:58 -08:00
Siva Chandra Reddy 6a6101958a [libc] Add implementation of getc, getc_unlocked and fgetc_unlocked.
Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D137507
2022-11-07 21:47:29 +00:00
Siva Chandra Reddy 43e52ad553 [libc] Add implementations of ftell.
Reviewed By: michaelrj, lntue

Differential Revision: https://reviews.llvm.org/D137395
2022-11-07 21:38:53 +00:00
Michael Jones 28e312cbf0 [libc][obvious] fix printf failing to stop on %\0
Previously, the printf parser would treat "%\0" as a conversion with the
name "\0", and advance past the null byte causing a buffer overflow.
This patch corrects that in both printf and scanf.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D137367
2022-11-07 10:44:30 -08:00
Siva Chandra Reddy b12c677033 [libc][docs] Add a build and test document. 2022-11-05 01:06:01 -07:00
Siva Chandra Reddy 64821f178e [libc][docs] Fix typos. 2022-11-05 00:21:09 -07:00
Siva Chandra Reddy 1bb6f1bb8f [libc][docs] Move links to internal developer guides out of the main side bar.
The links are all now from a "Developer Guides" page which is linked from the
main side bar.
2022-11-05 00:04:50 -07:00
Tue Ly 6c6dff7e2c [libc] Add add_with_carry to builtin wrapper.
Add add_with_carry to builtin wrapper to be used by UInt class.

Reviewed By: orex

Differential Revision: https://reviews.llvm.org/D137453
2022-11-04 23:20:37 -04:00
Siva Chandra Reddy 086757a47a [libc][NFC] Remove "$>" from another command block on examples/README.md. 2022-11-04 08:37:05 +00:00
Siva Chandra Reddy 3d2165f738 [libc][NFC] Remove "$>" from recipe commands blocks in examples/README.md.
The blocks come with a copy button so removing the "$>" makes it easy to
copy paste the commands.
2022-11-04 08:35:39 +00:00
Siva Chandra Reddy 9145bf13b7 [libc] Add example programs and their CMake build and instructions.
These examples are serve as an examples for people wanting to start
using the libc.

Reviewed By: michaelrj, jeffbailey

Differential Revision: https://reviews.llvm.org/D137090
2022-11-04 08:31:06 +00:00
Siva Chandra Reddy 4eea884959 [libc] Add implementation of setbuf and setvbuf.
Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D137356
2022-11-04 07:15:13 +00:00
Siva Chandra Reddy c9da0352a3 [libc] Convert the api-test in to an integration test.
It used to pass but showed an annoying message about _start not being
available. That will not happen anymore.
2022-11-04 07:09:18 +00:00
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