Commit Graph

2119 Commits

Author SHA1 Message Date
Trevor Gross
1bbf8b12da Add extensive and exhaustive tests
Add a generator that will test all inputs for input spaces `u32::MAX` or
smaller (e.g. single-argument `f32` routines).  For anything larger,
still run approximately `u32::MAX` tests, but distribute inputs evenly
across the function domain.

Since we often only want to run one of these tests at a time, this
implementation parallelizes within each test using `rayon`. A custom
test runner is used so a progress bar is possible.

Specific tests must be enabled by setting the `LIBM_EXTENSIVE_TESTS`
environment variable, e.g.

    LIBM_EXTENSIVE_TESTS=all_f16,cos,cosf cargo run ...

Testing on a recent machine, most tests take about two minutes or less.
The Bessel functions are quite slow and take closer to 10 minutes, and
FMA is increased to run for about the same.
2025-01-06 08:22:13 +00:00
Trevor Gross
7c04b1916a Add more detailed definition output for update-api-list.py
Update the script to produce, in addition to the simple text list, a
JSON file listing routine names, the types they work with, and the
source files that contain a function with the routine name. This gets
consumed by another script and will be used to determine which extensive
CI jobs to run.
2025-01-06 02:25:59 -05:00
Trevor Gross
f453f5e5b5 Add tests against MPFR for ilogb and ilogbf 2025-01-06 01:29:22 -05:00
Trevor Gross
206bf326d5 Increase the precision for jn and jnf
New random seeds seem to indicate that this test does have some more
failures, this is a recent failure on i586:

    ---- musl_random_jnf stdout ----
    Random Musl jnf arg 1/2: 100 iterations (10000 total) using `LIBM_SEED=nLfzQ3U1OBVvqWaMBcto84UTMsC5FIaC`
    Random Musl jnf arg 2/2: 100 iterations (10000 total) using `LIBM_SEED=nLfzQ3U1OBVvqWaMBcto84UTMsC5FIaC`

    thread 'musl_random_jnf' panicked at crates/libm-test/tests/compare_built_musl.rs:43:51:
    called `Result::unwrap()` on an `Err` value:
        input:    (205, 5497.891) (0x000000cd, 0x45abcf21)
        expected: 7.3291517e-6           0x36f5ecef
        actual:   7.331668e-6            0x36f6028c

    Caused by:
        ulp 5533 > 4000

It seems unlikely that `jn` would somehow have better precision than
`j0`/`j1`, so just use the same precision.
2025-01-05 23:37:12 -05:00
Trevor Gross
ea21b6045f Rename unstable-test-support to unstable-public-internals
The `support` module that this feature makes public will be useful for
implementations in `compiler-builtins`, not only for testing. Give this
feature a more accurate name.
2025-01-05 22:13:11 -05:00
Trevor Gross
cc6a84bf43 Update precision based on new test results 2025-01-06 01:51:37 +00:00
Trevor Gross
37dbc534cb Rewrite the random test generator
Currently, all inputs are generated and then cached. This works
reasonably well but it isn't very configurable or extensible (adding
`f16` and `f128` is awkward).

Replace this with a trait for generating random sequences of tuples.
This also removes possible storage limitations of caching all inputs.
2025-01-06 00:32:21 +00:00
Trevor Gross
b78f7b7b48 Add an iterator that ensures known size
Introduce the `KnownSize` iterator wrapper, which allows providing the
size at construction time. This provides an `ExactSizeIterator`
implemenation so we can check a generator's value count during testing.
2025-01-06 00:32:21 +00:00
Trevor Gross
9a7a519370 Streamline the way that test iteration count is determined
Currently, tests use a handful of constants to determine how many
iterations to perform: `NTESTS`, `AROUND`, and `MAX_CHECK_POINTS`. This
configuration is not very straightforward to adjust and needs to be
repeated everywhere it is used.

Replace this with new functions in the `run_cfg` module that determine
iteration counts in a more reusable and documented way.

This only updates `edge_cases` and `domain_logspace`, `random` is
refactored in a later commit.
2025-01-06 00:32:21 +00:00
Trevor Gross
b7b22b54c0 Add a way for tests to log to a file
Occasionally it is useful to see some information from running tests
without making everything noisy from `--nocapture`. Add a function to
log this kind of output to a file, and print the file as part of CI.
2025-01-06 00:32:21 +00:00
Trevor Gross
4b15d9e5e3 Add tests against MPFR for scalbn{f} and ldexp{f} 2025-01-05 18:49:54 -05:00
Trevor Gross
e9bc33e8d3 Add tests against MPFR for frexp and frexpf
This implementation comes from `rug::Float::to_f32_exp` [1].

[1]: https://docs.rs/rug/1.26.1/rug/struct.Float.html#method.to_f32_exp
2025-01-05 18:33:20 -05:00
Trevor Gross
59964fbbca Add tests against MPFR for modf and modff
Rug provides `trunc_fract_round`, which implements `modf`, use it to add
a test.
2025-01-05 18:17:27 -05:00
Trevor Gross
f99d8acc20 Clean up integers stored in MpTy
There isn't any need to cache the integer since it gets provided as an
argument anyway. Simplify this in `jn` and `yn`.
2025-01-04 21:25:22 -05:00
Trevor Gross
d50c12b219 precision: Sort ilogb with other precise operations
This is a nonfunctional change.
2025-01-04 06:32:38 -05:00
Trevor Gross
3030182c66 Change to exhaustive matching for default_ulp
Make it more obvious what the expected ULP for a given routine is. This
also narrows ULP to 0 for operations that require exact results.
2025-01-03 18:47:34 -05:00
Trevor Gross
14e6d05dfb Use intrinsics for abs and copysign when available
Currently our implementations for `abs` and `copysign` are defined on
the trait, and these are then called from `generic`. It would be better
to call core's `.abs()` / `.copysign(y)`, but we can't do this in the
generic because calling the standalone function could become recursive
(`fabsf` becomes `intrinsics::fabsf32`, that may lower to a call to
`fabsf`).

Change this so the traits uses the call to `core` if available, falling
back to a call to the standalone generic function.

In practice the recursion isn't likely to be a problem since LLVM
probably always lowers `abs`/`copysign` to assembly, but this pattern
should be more correct for functions that we will add in the future
(e.g. `fma`).

This should eventually be followed by a change to call the trait methods
rather than `fabs`/`copysign` directly.
2025-01-03 07:50:56 -05:00
Trevor Gross
5d60d2a905 Fix new clippy::precedence errors
`clippy::precedence` now applies to bitwise `&` and `|`. Update with all
of its suggestions, including a separate elided lifetime suggestion.
2025-01-03 03:09:07 +00:00
Trevor Gross
7065cd0420 Rename EXP_MAX to EXP_SAT
"Maximum" is technically correct here with regards to what the
bitpattern can represent, but it is not the numeric maximum value of the
exponent which has a relationship with the bias. So, replace the maximum
terminology with "saturated" to indicate it only means the full
bitpattern.

This change is more relevant to `libm` than `compiler-builtins`.
2025-01-03 02:56:34 +00:00
Trevor Gross
b47d3cc2f8 Shorten prefixes for float constants
Change `SIGNIFICAND_*` to `SIG_*` and `EXPONENT_*` to `EXP_*`. This
makes things more consistent with `libm`, and terseness is convenient
here since there isn't anything to confuse.
2025-01-03 02:54:56 +00:00
Trevor Gross
a277ec6954 Rename generic abs to fabs
Using the same name as the routines themselves means this will correctly
get picked up by the CI job looking for exhaustive tests.
2025-01-02 18:01:45 -05:00
Trevor Gross
3fb16fbdbe macros: Always emit f16_enabled and f128_enabled attributes
Once we start addinf `f16` and `f128` routines, we will need to have
this cfg for almost all uses of `for_each_function`. Rather than needing
to specify this each time, always emit `#[cfg(f16_enabled)]` or
`#[cfg(f128_enabled)]` for each function that uses `f16` or `f128`,
respectively.
2025-01-02 17:38:09 -05:00
Trevor Gross
e754ecb6d9 Add missing functions to the macro list
Now that we are using rustdoc output to locate public functions, the
test is indicating a few that were missed since they don't have their
own function. Update everything to now include the following routines:

* `erfc`
* `erfcf`
* `y0`
* `y0f`
* `y1`
* `y1f`
* `yn`
* `ynf`
2025-01-01 11:15:48 +00:00
Trevor Gross
ed72c4ec69 Use rustdoc output to create a list of public API
Rather than collecting a list of file names in `libm-test/build.rs`,
just use a script to parse rustdoc's JSON output.
2025-01-01 11:01:50 +00:00
Trevor Gross
489524413b Forward the CI environment variable when running in Docker
We want to be able to adjust our configuration based on whether we are
running in CI, propagate this so our tests can use it.
2025-01-01 10:56:56 +00:00
Trevor Gross
cf58a7ce90 Remove lossy casting in logspace
Currently `logspace` does a lossy cast from `F::Int` to `usize`. This
could be problematic in the rare cases that this is called with a step
count exceeding what is representable in `usize`.

Resolve this by instead adding bounds so the float's integer type itself
can be iterated.
2024-12-30 01:11:59 -05:00
Trevor Gross
e8c501861a Set the allowed FMA ULP to 0
It is currently getting the default of 1 or 2. Since this operation
should always be infinite precision, no deviation is allowed.
2024-12-29 21:10:57 -05:00
Trevor Gross
a93f659d7c Don't run push CI on anything other than master 2024-12-29 04:18:15 -05:00
Trevor Gross
7082f9baf7 Use CheckCtx in more places
Rather than passing names or identifiers, just pass `CheckCtx` in a few
more places.
2024-12-29 03:23:57 -05:00
Trevor Gross
86aeee818b Move CheckBasis and CheckCtx to a new run_cfg module
These are used more places than just test traits, so this new module
should be a better home. `run_cfg` will also be expanded in the near
future.
2024-12-29 03:23:57 -05:00
Trevor Gross
6e97fef9c9 Add ALL, from_str and math_op to Identifier
Introduce new API to iterate the function list and associate items with
their `MathOp`.
2024-12-29 08:07:40 +00:00
Trevor Gross
b9ecacf03b Add new trait implementations for Identifier and BaseName
These allow for more convenient printing, as well as storage in map
types.
2024-12-29 08:07:21 +00:00
Trevor Gross
fc4b88aecd Include shared.rs in libm_test::op
These types from `libm-macros` provide a way to get information about an
operation at runtime, rather than only being encoded in the type system.
Include the file and reexport relevant types.
2024-12-29 08:06:46 +00:00
Trevor Gross
1069346b6d Move the macro's input function list to a new module shared
This will enable us to `include!` the file to access these types in
`libm-test`, rather than somehow reproducing the types as part of the
macro. Ideally `libm-test` would just `use` the types from `libm-macros`
but proc macro crates cannot currently export anything else.

This also adjusts naming to closer match the scheme described in
`libm_test::op`.
2024-12-29 08:03:19 +00:00
Trevor Gross
d86f8bee8b Add a way to plot the output from generators
For visualization, add a simple script for generating scatter plots and
a binary (via examples) to plot the inputs given various domains.
2024-12-29 07:47:21 +00:00
Trevor Gross
3c61c560ac Update allowed precision to account for new tests 2024-12-29 07:47:21 +00:00
Trevor Gross
13611a1b76 Add tests for edge cases
Introduce a generator that will tests various points of interest
including zeros, infinities, and NaNs.
2024-12-29 07:47:21 +00:00
Trevor Gross
a8a2f70ae6 Add interfaces and tests based on function domains
Create a type representing a function's domain and a test that does a
logarithmic sweep of points within the domain.
2024-12-29 07:47:21 +00:00
Trevor Gross
163ed2a133 Introduce a float extension trait and some numerical routines 2024-12-29 07:47:21 +00:00
Trevor Gross
8d224a0de0 Add an 8-bit float type for testing purposes
Introduce `f8`, which is an 8-bit float compliant with IEEE-754. This
type is useful for testing since it is easily possible to enumerate all
values.
2024-12-29 07:47:21 +00:00
beetrees
bae68206fa Remove an is_nan workaround that is no longer needed 2024-12-29 07:47:21 +00:00
Trevor Gross
5e6b813e51 Update and slightly refactor some of the Float trait
Add a constant for negative pi and provide a standalone const
`from_bits`, which can be combined with what we already had in
`hex_float`. Also provide another default method to reduce what needs to
be provided by the macro.
2024-12-29 07:47:21 +00:00
Trevor Gross
2323d3a2e3 Always enable unstable-float in CI
Since these add new API but do not affect runtime, we can enable it for
all tests that run with nightly.
2024-12-29 07:47:21 +00:00
Trevor Gross
f2e16b6ac1 Add f16 and f128 configuration from compiler-builtins
In preparation of adding routines from these two types, duplicate the
`compiler-builtins` configuration here.
2024-12-29 02:33:41 -05:00
Trevor Gross
b9871da445 Introduce generic abs and copysign
Add generic versions of `abs` and `copysign`, which will provide an
entrypoint for adding `f16` and `f128`. Since this implementation is
identical to the existing type-specific implementations, make use of it
for `f32` and `f64`.
2024-12-29 02:22:30 -05:00
Trevor Gross
51956a53c3 Change from -latest to named CI images
GitHub will be upgrading the `-latest` tags of these images in the near
future. Change all images to specify the latest version.
2024-12-29 01:59:49 -05:00
Trevor Gross
4e5a156cd0 Allow Clippy lints in compiler-builtins-smoke-test
Rather than always needing to exclude `cb` when running `cargo clippy`,
just disable Clippy for the included module.
2024-12-27 11:02:40 +00:00
Trevor Gross
80dca45a80 Fix new clippy::precedence lints
[1] extends Clippy's `precedence` lint to cover `&`, `|`, and bitshifts.
Update cases that are flagged by this in the most recent nightly.

[1]: https://github.com/rust-lang/rust-clippy/pull/13743
2024-12-27 10:58:36 +00:00
Trevor Gross
723e68d137 Replace string function name matching with enums where possible 2024-12-26 09:30:47 +00:00
github-actions[bot]
a078f5a0c5 chore: release v0.1.140 2024-12-26 00:16:33 -05:00