417 Commits

Author SHA1 Message Date
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
c0f7b95e43 Resolve clippy errors in libm tests and check this in CI 2024-11-02 10:10:52 -05:00
Johanna Sörngård
9a9e47798f Add some more basic docstrings (#352)
* Add docstrings to the tgamma functions
* Add docstrings to the lgamma functions
* Add docstrings to trunc
* Add docstrings to exp10 functions
2024-11-01 12:29:03 +00:00
Trevor Gross
0f9503532b Introduce hf32! and hf64! macros for hex float support
Rust does not have any native way to parse hex floats, but they are
heavily used in the C algorithms that we derive from. Introduce a const
function that can parse these, as well as macros `hf32!` and `hf64!`
that ensure the string literals get handled at compiler time.

These are currently not used but making everything available now will
ease future development.

Co-authored-by: quaternic <57393910+quaternic@users.noreply.github.com>
2024-11-01 07:15:40 -05:00
Trevor Gross
659cdcad33 Enable clippy for libm in CI 2024-11-01 06:42:39 -05:00
Trevor Gross
c2402e4d3c Fix errors reported by Clippy in libm 2024-11-01 06:31:09 -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
5f54ad6389 Update libm Float and Int with functions from the test traits
The test versions of `Float` and `Int` have a few more methods and
constants availablee. Update the in `libm` with everything missing from
`libm_test` so we will be able to merge these.
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
be72d14ed5 Check benchmarks in CI 2024-10-31 22:40:30 -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
WANG Rui
baae082fc5 ci: add support for loongarch64-unknown-linux-gnu 2024-10-31 13:20:07 -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
360d3ee184 Add float and integer traits from compiler-builtins
In preparation of adding generic algorithms to `libm`, add the traits
from `compiler-builtins`.

Eventually we should be able to unify the two crates so we don't have
duplicate implementations.
2024-10-29 03:46:45 -05:00
Trevor Gross
d6646ae2d1 Move architecture-specific code to src/math/arch
Move the code and call into its new location with
`select_implementation`.
2024-10-28 22:12:13 -05:00
Trevor Gross
7108e80dc2 Update select_implementation to accept arch configuration 2024-10-28 22:12:13 -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
ec1ca51298 Vendor cfg_if::cfg_if!
`cfg_if` is helpful for applying `cfg` attributes to groups of items,
like we will need to do with architecture-specific modules of `f16` and
`f128`. However, `libm` can't have dependencies.

The `cfg_if` macro is complex but small, so just vendor it here.
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
54c8ae0980 Run tests against MPFR on CI where possible
This effectively gives us tests against infinite-precision results on
MacOS and x86+sse Linux.
2024-10-28 21:29:31 -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
3502d8eff6 Combine the WASM CI job with the others
There isn't any reason to be distinct here, and it would be better to
test with all feature configurations in run.sh anyway.
2024-10-28 20:53:35 -05:00
Trevor Gross
60e7e3b338 Make use of select_implementation
Replace all uses of `llvm_intrinsically` with select_implementation`.
2024-10-28 19:41:11 -05:00
Trevor Gross
d54896343c Introduce a select_implementation macro
Currently there is a macro called `llvm_intrinsically_optimized` that
uses an intrinsic rather than the function implementation if the
configuration is correct. Add a new macro `select_implementation` that
is somewhat cleaner to use.

In the future, we can update this macro with more fields to specify
other implementations that may be selected, such as something
architecture-specific or e.g. using a generic implementation for `f32`
routines, rather than those that convert to `f64`.

This introduces a `macros` module within `math/support`. We will be able
to move more things here later.
2024-10-28 19:40:32 -05:00
Trevor Gross
1b7346bf5f Introduce math::arch::intrinsics
This module provides implementations of basic functions that defer to
LLVM for what to do, rather than either using a builtin operation or
calling another function in this library.

`math::arch` will become the home of anything architecture-specific in
the future.
2024-10-28 19:40:31 -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
github-actions[bot]
c14fac725a chore: release v0.2.11 2024-10-28 20:08:07 +00:00
Trevor Gross
0109445d59 Enable caching on all CI jobs that build the crate (#341) 2024-10-28 20:07:34 +00: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
f5d30ecc3b Enable more targets on CI
This brings the targets tested here in line with those tested in
`compiler-builtins`.
2024-10-28 12:59:38 -05:00
Trevor Gross
ee131ffa47 Disable a unit test that is failing on i586 2024-10-28 12:59:38 -05:00
Trevor Gross
31d0132ac1 Add dockerfiles for i586, riscv, and thumb
These targets are tested in `compiler-builtins`, but not yet `libm`. Add
dockerfiles to prepare for this.
2024-10-28 12:59:38 -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
Trevor Gross
128e572054 Add a helper for cached test inputs
Add a type that caches values used to implement `GenerateInput` on a
variety of signatures.
2024-10-28 12:59:38 -05:00
Trevor Gross
d45f6f6fad Add traits for testing
These traits give us a more generic way to interface with tuples used
for (1) test input, (2) function arguments, and (3) test input.
2024-10-28 12:59:38 -05:00
Trevor Gross
8be6ef1e0a Add numeric traits
These traits are simplified versions of what we have in
`compiler_builtins` and will be used for tests.
2024-10-28 12:59:38 -05:00