Commit Graph

110 Commits

Author SHA1 Message Date
Job Henandez Lara
49561181bd [libc] Add proxy header for fenv.h macro constants. #87863 (#87896)
Hello, this addresses #87863.
2024-04-09 12:55:10 -04:00
lntue
312b9297bb [libc] Increase timeout for death tests. (#87959)
Fix test timeout on RISCV bots.
Fixes https://github.com/llvm/llvm-project/issues/87096
2024-04-08 11:31:07 -04:00
Guillaume Chatelet
09efe848cf [libc][NFC] Rename UInt.h to big_int.h and UInt128.h to uint128.h for consistency (#87808) 2024-04-06 10:39:55 +02:00
lntue
5748ad84e5 [libc] Add proxy header math_macros.h. (#87598)
Context: https://github.com/llvm/llvm-project/pull/87017

- Add proxy header `libc/hdr/math_macros.h` that will:
  - include `<math.h>` in overlay mode,
- include `"include/llvm-libc-macros/math-macros.h"` in full build mode.
- Its corresponding CMake target `libc.hdr.math_macros` will only depend
on `libc.include.math` and `libc.include.llvm-libc-macros.math_macros`
in full build mode.
- Replace all `#include "include/llvm-libc-macros/math-macros.h"` with
`#include "hdr/math_macros.h"`.
- Add dependency to `libc.hdr.math_macros` CMake target when using
`add_fp_unittest`.
- Update the remaining dependency.
- Update bazel overlay: add `libc:hdr_math_macros` target, and replacing
all dependency on `libc:llvm_libc_macros_math_macros` with
`libc:hdr_math_macros`.
2024-04-05 18:21:16 -04:00
Om Prakaash
fdef5c4f45 Add bit width length modifier to printf (#82461)
Resolves #81685. This adds support for wN and wfN length modifiers in
fprintf.
2024-03-29 10:15:22 -07:00
OverMighty
b282259711 [libc][math][c23] Add {,u}fromfp{,x}{,f,l,f128} functions (#86003)
Fixes #85279.

cc @lntue
2024-03-25 10:26:22 -04:00
Guillaume Chatelet
2137894a6f [libc][NFC] Move Sign type to separate header (#85930) 2024-03-20 15:10:19 +01:00
Michael Jones
5d56b34807 [libc] Remove direct math.h includes (#85324)
Reland of #84991

A downstream overlay mode user ran into issues with the isnan macro not
working in our sources with a specific libc configuration. This patch
replaces the last direct includes of math.h with our internal
math_macros.h, along with the necessary build system changes.
2024-03-18 14:19:33 -07:00
OverMighty
8ff96eb100 [libc][math][c23] Add nextup{,f,f128} and nextdown{,f,f128} functions (#85431)
See https://github.com/llvm/llvm-project/issues/85283.

I had a test for `nextdownl` that was failing and I thought I should add
`nextupl` and `nextdownl` later and first make a PR for the other
functions.

cc @lntue
2024-03-15 16:46:48 -04:00
Guillaume Chatelet
23c397c7c9 [libc] Provide LIBC_TYPES_HAS_INT128 (#84149)
Umbrella bug #83182
2024-03-08 16:06:56 +01:00
Guillaume Chatelet
6a8e6c9a31 [libc][NFC] Move BigInt out of the cpp namespace (#84445)
As noted in
https://github.com/llvm/llvm-project/pull/84035#discussion_r1516817755
only files under the CPP folder should be in the `cpp` namespace.
2024-03-08 09:41:23 +01:00
Guillaume Chatelet
c103d573e7 [libc] Fix forward missing BigInt specialization of mask_leading_ones / mask_trailing_ones (#84325)
#84299 broke the arm32 build, this patch fixes it forward.
2024-03-07 20:00:05 +01:00
Guillaume Chatelet
245d669f1d [reland][libc] Remove UB specializations of type traits for BigInt (#84299)
Note: This is a reland of #84035.

The standard specifies that it it UB to specialize the following traits:
 - `std::is_integral`
 - `std::is_unsigned`
 - `std::make_unsigned`
 - `std::make_signed`

This patch:
 - Removes specializations for `BigInt`
 - Transforms SFINAE for `bit.h` functions from template parameter to
   return type (This makes specialization easier).
 - Adds `BigInt` specialization for `bit.h` functions.
 - Fixes code depending on previous specializations.
2024-03-07 11:41:35 +01:00
Guillaume Chatelet
27844cb2fa Revert "[libc] Remove UB specializations of type traits for BigInt" (#84297)
Reverts llvm/llvm-project#84035

Several bots are failing:
 - https://lab.llvm.org/buildbot/#/builders/223/builds/37522
 - https://lab.llvm.org/buildbot/#/builders/162/builds/51978
 - https://lab.llvm.org/buildbot/#/builders/163/builds/52560
 - https://lab.llvm.org/buildbot/#/builders/250/builds/19619
2024-03-07 11:06:50 +01:00
Guillaume Chatelet
84f483dbee [libc] Remove UB specializations of type traits for BigInt (#84035)
The standard specifies that it it UB to specialize the following traits:
 - `std::is_integral`
 - `std::is_unsigned`
 - `std::make_unsigned`
 - `std::make_signed`

This patch:
 - Removes specializations for `BigInt`
 - Transforms SFINAE for `bit.h` functions from template parameter to
   return type (This makes specialization easier).
 - Adds `BigInt` specialization for `bit.h` functions.
 - Fixes code depending on previous specializations.
2024-03-07 11:01:09 +01:00
lntue
73aab2f697 [libc] Revert https://github.com/llvm/llvm-project/pull/83199 since it broke Fuchsia. (#83374)
With some header fix forward for GPU builds.
2024-02-29 14:43:53 -05:00
Nick Desaulniers
330793c91d [libc] fix clang-tidy llvm-header-guard warnings (#82679)
Towards the goal of getting `ninja libc-lint` back to green, fix the numerous
instances of:

    warning: header guard does not follow preferred style [llvm-header-guard]

This is because many of our header guards start with `__LLVM` rather than
`LLVM`.

To filter just these warnings:

    $ ninja -k2000 libc-lint 2>&1 | grep llvm-header-guard

To automatically apply fixits:

    $ find libc/src libc/include libc/test -name \*.h | \
        xargs -n1 -I {} clang-tidy {} -p build/compile_commands.json \
        -checks='-*,llvm-header-guard' --fix --quiet

Some manual cleanup is still necessary as headers that were missing header
guards outright will have them inserted before the license block (we prefer
them after).
2024-02-28 12:53:56 -08:00
Joseph Huber
04e8653f18 [libc] Add "include/" to the LLVM include directories (#83199)
Summary:
Recent changes added an include path in the float128 type that used the
internal `libc` path to find the macro. This doesn't work once it's
installed because we need to search from the root of the install dir.
This patch adds "include/" to the include path so that our inclusion
of installed headers always match the internal use.
2024-02-27 17:45:15 -06:00
Joseph Huber
47b7c91abe [libc] Rework the GPU build to be a regular target (#81921)
Summary:
This is a massive patch because it reworks the entire build and
everything that depends on it. This is not split up because various bots
would fail otherwise. I will attempt to describe the necessary changes
here.

This patch completely reworks how the GPU build is built and targeted.
Previously, we used a standard runtimes build and handled both NVPTX and
AMDGPU in a single build via multi-targeting. This added a lot of
divergence in the build system and prevented us from doing various
things like building for the CPU / GPU at the same time, or exporting
the startup libraries or running tests without a full rebuild.

The new appraoch is to handle the GPU builds as strict cross-compiling
runtimes. The first step required
https://github.com/llvm/llvm-project/pull/81557 to allow the `LIBC`
target to build for the GPU without touching the other targets. This
means that the GPU uses all the same handling as the other builds in
`libc`.

The new expected way to build the GPU libc is with
`LLVM_LIBC_RUNTIME_TARGETS=amdgcn-amd-amdhsa;nvptx64-nvidia-cuda`.

The second step was reworking how we generated the embedded GPU library
by moving it into the library install step. Where we previously had one
`libcgpu.a` we now have `libcgpu-amdgpu.a` and `libcgpu-nvptx.a`. This
patch includes the necessary clang / OpenMP changes to make that not
break the bots when this lands.

We unfortunately still require that the NVPTX target has an `internal`
target for tests. This is because the NVPTX target needs to do LTO for
the provided version (The offloading toolchain can handle it) but cannot
use it for the native toolchain which is used for making tests.

This approach is vastly superior in every way, allowing us to treat the
GPU as a standard cross-compiling target. We can now install the GPU
utilities to do things like use the offload tests and other fun things.

Some certain utilities need to be built with 
`--target=${LLVM_HOST_TRIPLE}` as well. I think this is a fine
workaround as we
will always assume that the GPU `libc` is a cross-build with a
functioning host.

Depends on https://github.com/llvm/llvm-project/pull/81557
2024-02-22 15:29:29 -06:00
Joseph Huber
5454991c29 [libc] Cleanup of hermetic test flag handling (#82384)
Summary:
This cleans up the handling of hermetic test flags. Primarily done to
simplify the GPU rework patch.
2024-02-20 12:23:48 -06:00
Michael Jones
d0c2c0ab6d [libc] Move compile options to new cmake file (#81917)
The cmake test generator needed to be updated to support the same flags
as the source. To simplify the code, I moved it to a new file.
2024-02-15 16:07:21 -08:00
lntue
82a4a41614 [libc][stdfix] Add support for fixed point types in the testing infrastructure. (#81819) 2024-02-15 14:55:20 -05:00
lntue
271e07321b [libc] Fix fixed point detection and add compile option. (#81788) 2024-02-14 17:12:51 -05:00
michaelrj-google
3eb1e6d8e9 [libc] Move libc_errno inside of LIBC_NAMESPACE (#80774)
Having libc_errno outside of the namespace causes versioning issues when
trying to link the tests against LLVM-libc. Most of this patch is just
moving libc_errno inside the namespace in tests. This isn't necessary in
the function implementations since those are already inside the
namespace.
2024-02-06 10:36:05 +01:00
Guillaume Chatelet
ace383df52 [libc][NFC] Rename FPBits nan functions (#79998)
- [libc][NFC] Rename FPBits nan functions
- rename build_signaling_nan in signaling_nan
- rename build_quiet_nan to quiet_nan
2024-01-30 15:01:27 +01:00
Guillaume Chatelet
eb56bc2b10 [libc] Remove specific nan payload in math functions (#79165) 2024-01-29 15:28:46 +01:00
Caslyn Tonelli
6f97e6bcf7 [fuchsia][libc] Include missing macro definitions (#79639)
PR 79573 introduced `ASSERT_ERRNO_*` macros for use in libc tests.
Introduce these macro definitions to FuchsiaTest.h for string tests to
compile on Fuchsia.
2024-01-26 13:20:57 -08:00
Guillaume Chatelet
73874f7a39 [libc][NFC] Use specific ASSERT macros to test errno (#79573)
This patch provides specific test macros to deal with `errno`.
This will help abstract away the differences between unit test and integration/hermetic tests in #79319.
In one case we use `libc_errno` which is a struct, in the other case we deal directly with `errno`.
2024-01-26 15:18:22 +01:00
Guillaume Chatelet
2856db0d3b [libc][NFC] Remove FPBits cast operator (#79142)
The semantics for casting can range from "bitcast" (same representation)
to "different representation", to "type promotion". Here we remove the
cast operator and force usage of `get_val` as the only function to get
the floating point value, making the intent clearer and more consistent.
2024-01-23 17:30:19 +01:00
Schrodinger ZHU Yifan
2cff46f8c0 [libc][NFC] use builder pattern for ErrnoSetterMatcher (#79153)
ErrnoSetterMatcher::returns can be misleading as it does not initialize
the errno. This is made worse as later on there is a switch statement on
the errno comparator using __builtin_unreachable(). This patch make
ErrnoSetterMatcher::returns give back a builder that is nomially
different from ErrnoSetterMatcher.
2024-01-23 10:43:24 -05:00
Guillaume Chatelet
dffa8039b1 [libc] Remove specific nan payload in math functions (#79133) 2024-01-23 16:37:36 +01:00
Guillaume Chatelet
6b02d2f863 [reland][libc] Remove unnecessary FPBits functions and properties (#79128)
- reland #79113
- Fix aarch64 RISC-V build
2024-01-23 13:48:03 +01:00
Guillaume Chatelet
b524eed925 Revert "[libc] Remove unnecessary FPBits functions and properties" (#79118)
Reverts llvm/llvm-project#79113
It broke aarch64 build bot machines.
2024-01-23 11:51:18 +01:00
Guillaume Chatelet
3bc86bf3bf [libc] Remove unnecessary FPBits functions and properties (#79113)
This patch reduces the surface of `FPBits`.
2024-01-23 11:48:28 +01:00
lntue
029bfd6329 [libc] Replace -nostdlib++ flag when building with gcc and add placement new operator to HermeticTestUtils.cpp. (#78906)
`-nostdlib++` is a clang-only flag. Replacing it with `-nostdlib` when
building with gcc.
2024-01-22 19:27:27 -05:00
Guillaume Chatelet
11ec512f44 [libc][NFC] Introduce a Sign type for FPBits (#78500)
Another patch is needed to cover `DyadicFloat` and `NormalFloat`
constructors.
2024-01-18 13:40:49 +01:00
michaelrj-google
b932f03bda [libc] Disable Death Tests While Hermetic (#77388)
The death test infrastructure seems to depend on operator new, which
isn't currently supported in our hermetic tests. This patch just
disables the death tests in hermetic mode since they only overlap in the
nan tests.
2024-01-09 15:04:22 -08:00
Guillaume Chatelet
57fcc23896 [libc] Fix improper initialization of StorageType (#75610)
`StorageType` may be a `BigInt` under the hood. Initializing it with
`-1` does not yields the maximum value.
2023-12-15 15:51:10 +01:00
Guillaume Chatelet
3546f4da19 [libc][NFC] Rename MANTISSA_WIDTH in FRACTION_LEN (#75489)
This one might be a bit controversial since the terminology has been
introduced from the start but I think `FRACTION_LEN` is a better name
here. AFAICT it really is "the number of bits after the decimal dot when
the number is in normal form."

`MANTISSA_WIDTH` is less precise as it's unclear whether we take the
leading bit into account.
This patch also renames most of the properties to use the `_LEN` suffix
and fixes useless casts or variables.
2023-12-15 13:57:35 +01:00
Nishant Mittal
18fd6df885 [libc][math] Add unit tests for raising excepts in nextafter (#73556)
Follow up to
https://github.com/llvm/llvm-project/pull/72763#discussion_r1398277962.

### Summary
- Add unit tests for raising excepts in `nextafter`. 
- Fixed a bug in testing code for `nexttoward`.  

cc: @lntue
2023-11-28 00:50:17 -05:00
lntue
d2361b2048 [libc][math] Add min/max/min_denorm/max_denorm constants to FPBits and clean up its constants return types. (#71298) 2023-11-06 18:22:34 -05:00
lntue
bc7a3bd864 [libc][math] Implement powf function correctly rounded to all rounding modes. (#71188)
We compute `pow(x, y)` using the formula
```
  pow(x, y) = x^y = 2^(y * log2(x))
```
We follow similar steps as in `log2f(x)` and `exp2f(x)`, by breaking
down into `hi + mid + lo` parts, in which `hi` parts are computed using
the exponent field directly, `mid` parts will use look-up tables, and
`lo` parts are approximated by polynomials.

We add some speedup for common use-cases:
```
  pow(2, y) = exp2(y)
  pow(10, y) = exp10(y)
  pow(x, 2) = x * x
  pow(x, 1/2) = sqrt(x)
  pow(x, -1/2) = rsqrt(x) - to be added
```
2023-11-06 16:54:25 -05:00
Joseph Huber
158d7b8c23 [libc] Allow hermetic timing if the clock function is built (#71092)
Summary:
This patch fixes some code duplication on the GPU. The GPU build wanted
to enable timing for hermetic tests so it built some special case
handling into the test suite. Now that `clock` is supported on the
target we can simply link against the external interface. Because we
include `clock.h` for the CLOCKS_PER_SEC macro we remap the C entrypoint
to the internal one if it ends up called. This should allow hermetic
tests to run with timing if it is supported.
2023-11-02 15:03:17 -05:00
alfredfo
f350532099 [libc] Fix accidental LIBC_NAMESPACE_clock_freq (#69620)
See-also: https://github.com/llvm/llvm-project/pull/69548
2023-10-19 19:39:02 +02:00
lntue
3fd5113cba [libc][math][NFC] Remove global scope constants declaration in math tests (#69558)
Clean up usage of `DECLARE_SPECIAL_CONSTANTS` in global scope.
2023-10-19 10:30:11 -04:00
Mikhail R. Gadelha
714b4c82bb [libc][NFC] Fix -Wdangling-else when compiling libc with gcc >= 7 (#67833)
Explicit braces were added to fix the "suggest explicit braces to avoid
ambiguous ‘else’" warning since the current solution (switch (0) case 0:
default:) doesn't work since gcc 7 (see
https://github.com/google/googletest/issues/1119)

gcc 13 generates about 5000 of these warnings when building libc without
this patch.
2023-10-04 11:44:42 -04:00
Mikhail R. Gadelha
8fc87f54a8 [libc][NFC] Couple of small warning fixes (#67847)
This patch fixes a couple of warnings when compiling with gcc 13:

* CPP/type_traits_test.cpp: 'apply' overrides a member function but is
not marked 'override'
* UnitTest/LibcTest.cpp:98: control reaches end of non-void function
* MPFRWrapper/MPFRUtils.cpp:75: control reaches end of non-void function
* smoke/FrexpTest.h:92: backslash-newline at end of file
* __support/float_to_string.h:118: comparison of unsigned expression in ‘>= 0’ is always true
* test/src/__support/CPP/bitset_test.cpp:197: comparison of unsigned expression in ‘>= 0’ is always true

---------

Signed-off-by: Mikhail R. Gadelha <mikhail@igalia.com>
2023-10-02 19:29:26 -04:00
Siva Chandra
425defd810 [libc][Obvious] Remove the previous ErrnoSetterMatcher target. (#67469)
A target still depending on the old target has been updated.
2023-09-26 11:01:21 -07:00
Guillaume Chatelet
b6bc9d72f6 [libc] Mass replace enclosing namespace (#67032)
This is step 4 of
https://discourse.llvm.org/t/rfc-customizable-namespace-to-allow-testing-the-libc-when-the-system-libc-is-also-llvms-libc/73079
2023-09-26 11:45:04 +02:00
Joseph Huber
b5440e443a [libc] Fix cyclical dependency on errno matcher for NVPTX architectures
Summary:
The NVPTX backend cannot handle cyclical dependencies on global variable
initializers. That is, a global variable cannot be used to initialize or
reference another global variable inside of it. This situation was
encountered with the new errno tests. This patch simply replaces the
offending function with a constant version to break the dependency and
alllow the tests to run again.
2023-09-23 08:59:34 -05:00