77 Commits

Author SHA1 Message Date
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
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
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
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
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
723e68d137 Replace string function name matching with enums where possible 2024-12-26 09:30:47 +00:00
Trevor Gross
ba1d271158 Rename associated type helpers, add OpITy
Change the names to make them less ambiguous. Additionally add `OpITy`
for accessing the same-sized integer of an operation's float type.
2024-12-22 23:56:45 +00:00
Trevor Gross
4cdb9ec674 Introduce helper types for accessing trait items
The ambiguous associated types error sometimes fires in cases where it
shouldn't be ambiguous ([1]), which can make things clunky when working
with chained associated types (e.g. `Op::FTy::Int::*` does not work).
Add helper types that we can use instead of the full syntax.

There aren't too many cases in-crate now but this is relevant for some
open PRs.

[1]: https://github.com/rust-lang/rust/issues/38078
2024-12-22 23:33:02 +00:00
Trevor Gross
76f37552e7 Remove tests against system musl
We now have tests against our custom-built musl as well as tests against
MPFR. The tests against system musl covers less than those against
custom-built musl, and are less portable; there isn't much benefit to
keeping them around so just remove them.
2024-12-22 12:39:27 +00:00
Trevor Gross
9a2774a0ae Move some numeric trait logic to default implementations
There are a handful of functions we can move out of the macro and to the
numeric traits as default implementations; do that here.

Additionally, add some bounds that make sense for completeness.
2024-11-03 21:11:34 -06:00
Trevor Gross
fcf8670668 Change the multiprec_ prefix to mp_
Currently there is a combination of names starting with
`multiprecision_`, `mp_` and `multiprec_`. Update so `multiprecision_`
is always used when a long form makes sense, `mp_` otherwise
(eliminating `multiprec_`).
2024-11-03 20:42:10 -06:00
Trevor Gross
5032fcf139 Change default ULP to use enum matching
Migrate from string to enum matching and tie this to `CheckCtx::new`, so
no tests need to explicitly set ULP.
2024-11-02 23:22:09 -05:00
Trevor Gross
f113f2be1e Rename Name to Identifier to avoid some ambiguity of "name" 2024-11-02 22:42:05 -05:00
Trevor Gross
2fab4f4580 Change the CheckCtx constructor to take a Name enum
This prepares to eliminate some reliance on string matching but does not
yet make those changes.
2024-11-02 22:35:30 -05:00
Trevor Gross
6aef9e17c8 Correct the proc macro to emit pub functions 2024-11-02 17:01:39 -05:00
Trevor Gross
f7f24a4ed8 Rework tests to make use of the new MathOp trait 2024-11-02 16:36:17 -05:00
Trevor Gross
7db74d78e8 Introduce a op module with struct representations of each routine
This contains:

1. Per-function and per-operation enums created by the proc macro
2. The `MathOp` trait which is implemented once per struct representing
   a function
3. Submodules for each function, each containing a `Routine` struct that
   implements `MathOp`
2024-11-02 16:36:17 -05:00
Trevor Gross
5b0a775c12 Adjust how the proc macro emits types and add an enum
Currently the macro always provides `CFn`, `RustFn`, `RustArgs`, etc.
Change this so that:

1. This information must be explicily requested in the invocation.
2. There is a new `FTy` field available that emits a single float type,
   rather than a tuple or signature.

Additionally, add two new macros that create enums representing function
names.
2024-11-02 10:54:00 -05:00
Trevor Gross
2411357947 Fix clippy lints in crates/ and enable this on CI 2024-11-02 10:33:23 -05:00
Trevor Gross
dbf8a4ebe5 Replace libm_test::{Float, Int} with libm::{Float, Int}
This involves moving some things from full generic implementations (e.g.
`impl<F: Float> SomeTrait for F { /* ... */ }` to generic functions and
macros to implement traits that call them, due to orphan rule violations
after `Float` became a not-in-crate trait.

`Hex` was moved to `test_traits` so we can eliminate `num_traits`.
2024-11-01 00:06:04 -05:00
Trevor Gross
4b12a8404f Expose the support module publicly with a test feature 2024-11-01 00:06:04 -05:00
Trevor Gross
4c1772ed85 Change prefixes used by the Float trait
Change `EXPONENT_` to `EXP_` and `SIGNIFICAND_` to `SIG_`. These are
pretty unambiguous, and just makes for less to type once these get used.
2024-11-01 00:06:04 -05:00
Trevor Gross
f770ec04b0 Remove libm-bench
This has been superseded by the benchmarks in `libm-test`.
2024-10-31 22:40:30 -05:00
Trevor Gross
abff7cd82a Add benchmarks against musl libm
Add a benchmark for each function that checks against `musl_math_sys`.
2024-10-31 22:40:30 -05:00
Trevor Gross
5523607045 Rename canonical_name to base_name
"Canonical" isn't really the right word here, update to "base".
2024-10-30 14:01:39 -05:00
Trevor Gross
6d1033e7fc Add an "arch" Cargo feature that is on by default
Introduce a Cargo feature to enable or disable architecture-specific
features (SIMD, assembly), which is on by default. This allows for more
fine grained control compared to relying on the `force-soft-floats`
feature.

Similar to "unstable-intrinsics", introduce a build.rs config option for
`unstable-intrinsics AND NOT force-soft-floats`, which makes this easier
to work with in code.

Effectively, this allows moving our non-additive Cargo feature
(force-soft-floats) to a positive one by default, allowing for an
override when needed.
2024-10-28 22:12:13 -05:00
Trevor Gross
ad1c652293 Update libm-test/build.rs to skip directories
Don't try to generate tests for directories, or for files that contain
`f16` or `f128` (as these types are not provided by musl's math
implementations).

(cherry picked from commit fd7ad36b70d0bbc0f0b9bc7e54d10258423fda29)
2024-10-28 22:12:13 -05:00
Trevor Gross
395419d2d2 Rename the special_case module to precision and move default ULP
Having the default ULP in lib.rs doesn't make much sense when everything
else precision-related is in special_case.rs. Rename `special_case` to
`precision` and move the `*_allowed_ulp` functions there.
2024-10-28 21:55:49 -05:00
Trevor Gross
64131ec5cd Add a test against MPFR using random inputs 2024-10-28 21:29:29 -05:00
Trevor Gross
c09e58be46 Create interfaces for testing against MPFR
Add a way to call MPFR versions of functions in a predictable way, using
the `MpOp` trait.

Everything new here is guarded by the feature `test-multiprecision`
since MPFR cannot easily build on Windows or any cross compiled targets.
2024-10-28 20:56:11 -05:00
Trevor Gross
e6f7053c2e Replace feature = "unstable-intrinsics" with intrinsics_enabled
We currently have a non-additive feature, "force-soft-floats", and we
will need to gain another "no-f16-f128". This makes `cfg` usage in code
somewhat confusing and redundant.

Use `build.rs` to figure out if "unstable-intrinsics" is enabled while
"force-soft-floats" is not enabled and if so, emit a cfg
`intrinsics_enabled`. This is cleaner to use and should make adding more
features easier to reason about.

Also use this as an opportunity to eliminate the build.rs from the
compiler-builtins test crate, replaced with the `[lints]` table in
Cargo.toml.
2024-10-28 18:37:09 -05:00
Trevor Gross
66f8906862 Move the existing "unstable" feature to "unstable-intrinsics"
Currently there is a single feature called "unstable" that is used to
control whether intrinsics may be called. In anticipation of adding
other unstable features that we will want to control separately, create
a new feature called "unstable-intrinsics" that is enabled by
"unstable". Then move everything gated by "unstable" to
"unstable-intrinsics".
2024-10-28 18:37:09 -05:00
Trevor Gross
ebb2dc11d8 Reduce the number of iterations on emulated aarch64 Linux
CI for aarch64 Linux is significantly slower than the others. Adjust how
iteration selection is done to better handle this case, which also
simplifies things.

Also set the `EMULATED` environment variable in Docker to be more
accurate, and reindents run-docker.sh.
2024-10-28 14:04:19 -05:00
Trevor Gross
bf757e3a7b Mark libm-macros and musl-math-sys as publish=false 2024-10-28 13:36:00 -05:00
Trevor Gross
1073858c72 Add a test against musl libm
Check our functions against `musl-math-sys`. This is similar to the
existing musl tests that go through binary serialization, but works on
more platforms.
2024-10-28 12:59:38 -05:00
Trevor Gross
98647ddc2f Introduce a generic way to control checks for specific cases
Sometimes we want to be able to xfail specific inputs without changing
the checked ULP for all cases or skipping the tests. There are also some
cases where we need to perform extra checks for only specific functions.

Add a trait that provides a hook for providing extra checks or skipping
existing checks on a per-function or per-input basis.
2024-10-28 12:59:38 -05:00
Trevor Gross
593fa8f3cb Add a deterministic random generator
Create a test generator that creates a known number of random inputs and
caches them, such that the same inputs are used for all functions.
2024-10-28 12:59:38 -05:00