Commit Graph

2119 Commits

Author SHA1 Message Date
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
Trevor Gross
05c9691f15 Add a test that for_each_fn correctly lists all functions
Create a new test that checks `for_each_fn` against `ALL_FUNCTIONS`,
i.e. the manually entered function list against the automatically
collected list. If any are missing (e.g. new symbol added), then this
will produce an error.
2024-10-28 12:59:38 -05:00
Trevor Gross
0acb3e2b50 Collect all function names to an array
Use a build script for `libm-test` to enumerate all symbols provided by
`libm` and provide this list in a variable. This will allow us to make
sure no functions are missed anytime they must be manually listed.

Additionally, introduce some helper config options.
2024-10-28 12:59:38 -05:00
Trevor Gross
56deb13bd4 Add a procedural macro for expanding all function signatures
Introduce `libm_test::for_each_function`. which macro takes a callback
macro and invokes it once per function signature. This provides an
easier way of registering various tests and benchmarks without
duplicating the function names and signatures each time.
2024-10-28 12:59:38 -05:00
Trevor Gross
5fc3068762 Add a script for downloading musl 2024-10-28 12:59:38 -05:00
Trevor Gross
36b52c7d1b Introduce musl-math-sys for bindings to musl math symbols
This crate builds math symbols from a musl checkout and provides a Rust
interface. The intent is that we will be able to compare our
implementations against musl on more than just linux (which are the only
currently the only targets we run `*-musl` targets against for
comparison).

Musl libc can't compile on anything other than Linux; however, the
routines in `src/math` are cross platform enough to build on MacOS and
windows-gnu with only minor adjustments. We take advantage of this and
build only needed files using `cc`.

The build script also performs remapping (via defines) so that e.g.
`cos` gets defined as `musl_cos`. This gives us more certainty that we
are actually testing against the intended symbol; without it, it is easy
to unknowingly link to system libraries or even Rust's `libm` itself and
wind up with an ineffective test. There is also a small procedure to
verify remapping worked correctly by checking symbols in object files.
2024-10-28 12:59:38 -05:00
quaternic
750027cbbe fix type of constants in ported sincosf (#331)
* fix type of constants in ported sincosf
2024-10-28 12:59:21 -05:00
Johanna Sörngård
db55857a73 Add basic docstrings to some functions (#337)
* Add docstring to Bessel functions
* Add docstrings to logarithm functions
* Add docstrings to pow functions
* Specify argument bit-size of the Bessel functions
* Specify argument bit-size for pow functions
* Specify argument bit-size for logarithms
* Add docstrings to sin, cos, sincos and sinh functions
* Add docstrings to sqrt
* Add docstrings to tan and tanh functions
* Add an inline link to https://en.wikipedia.org/wiki/Bessel_function to the docstrings of all Bessel functions.
2024-10-28 12:12:45 -05:00
Trevor Gross
a3fd7732f0 ci: rustup --no-self-update and reuqire MSRV checks
Pass `--no-self-update` to `rustup`, which is typical for CI. Also add
the MSRV job to `success` so GitHub won't merge without it passing.
2024-10-27 23:41:29 -05:00
Trevor Gross
b49ef8c510 Don't deny warnings when checking MSRV
1.63 reports some false positive lints that we don't need to worry
about. Make sure we don't fail CI for this.
2024-10-27 23:28:24 -05:00
github-actions[bot]
476585d6a0 chore: release v0.2.10 2024-10-27 22:51:02 -05:00
Trevor Gross
3541e834df Set the MSRV to 1.63 and document it as such
Fixes: https://github.com/rust-lang/libm/issues/330
2024-10-27 22:47:06 -05:00
Trevor Gross
3180b04aa3 Change build.rs to use the older : rather than ::
This allows supporting Rust < 1.77.
2024-10-27 22:46:17 -05:00
Trevor Gross
4d6aeca6b3 Add a CI test that the crate builds on stable
Currently everything we have runs with nightly Rust. Add a stable test
to make sure we don't accidentally make use of behavior that isn't yet
stable without gating it.
2024-10-27 01:10:26 -05:00
Trevor Gross
79f065ab24 Add a .git-blame-ignore-revs file
Include the recent formatting commit.
2024-10-26 20:30:41 -05:00
Trevor Gross
ab0c8e84fb Run cargo fmt with new settings
Apply the changes from the `.rustfmt.toml` file added in the previous
commit.
2024-10-26 20:28:28 -05:00
Trevor Gross
710ca6e38e Add a rustfmt.toml file matching rust-lang/rust
Duplicate the settings from rust-lang/rust to this repository. This is
mostly for consistency, but `use_small_heuristics = "Max"` does make a
large difference with lookup tables.

Also apply the needed CI changes to run nightly rustfmt.
2024-10-26 20:28:28 -05:00
github-actions[bot]
f9914e98b3 chore: release v0.1.136 2024-10-26 23:29:14 +00:00
Trevor Gross
01a2a13a01 Update the libm submodule 2024-10-26 18:22:14 -05:00
github-actions[bot]
4f3418a4d7 chore: release v0.2.9 2024-10-26 18:10:21 -05:00
Trevor Gross
0433caa0ba Fix release-plz workflow configuration 2024-10-26 18:01:56 -05:00
Trevor Gross
47961340db Add release-plz for automated releases 2024-10-26 17:58:38 -05:00
Trevor Gross
6399bed36c Update licensing to MIT AND Apache-2.0 WITH LLVM-exception
Currently, Cargo.toml specifies Apache-2.0 OR MIT, but LICENSE.txt
describes MIT OR NCSA. compiler-builtins is derived from LLVM's
compiler-rt. LICENSE.txt correctly reflects the state of compiler-rt
prior to relicensing on 2019-01-19, during which time software was
available for use under either MIT or the University of Illinois NCSA
license. After relicensing, however, compiler-rt is available for use
only under Apache-2.0 with the LLVM exception; this is not reflected
anywhere in the repository.

Update the SPDX license identifier to `MIT AND Apache-2.0 WITH
LLVM-exception AND (MIT OR Apache-2.0)`. Each AND portion covers
something specific:

* Apache-2.0 WITH LLVM-exception: this covers work that is derived from
  the LLVM repository since after the LLVM relicensing.
* MIT: This covers work that is derived from LLVM before the LLVM
  relicensing (under MIT OR NCSA), as well as the vendored `libm`
  components.
* MIT AND Apache-2.0: This ensures that any contributions to this
  repository, in addition to meeting the above required licenses, is
  also released for use under the Rust-standard Apache-2.0 with no LLVM
  exception.

See also the parallel license update in rust-lang/libm [1].

Fixes: https://github.com/rust-lang/compiler-builtins/issues/307
Closes: https://github.com/rust-lang/compiler-builtins/pull/511
Link: https://rust-lang.zulipchat.com/#narrow/channel/335408-foundation/topic/Request.20for.20legal.20team.20input.20on.20crate.20licensing
Link: https://github.com/rust-lang/libm/pull/317 [1]
2024-10-26 17:35:26 -05:00
Trevor Gross
bd82e67afc Update licensing to MIT AND (MIT OR Apache-2.0)
Currently both Cargo.toml and the license files indicate that this
library may be used under either MIT or Apache-2.0. However, this is not
accurate; since portions of this library were derived from musl libc,
which is available under the MIT license, this terms of use for this
library must also include use under the MIT license. That is, it is not
correct that this library may be used under only the Apache-2.0 license.

Update the SPDX license identifier to `MIT OR (MIT AND Apache-2.0)` to
indicate that use must include the MIT license, but to clarify that
contributions are made under `MIT OR Apache-2.0`. This is compatible
with the current state of this repository since it has always contained
both license files, and the `Cargo.toml` license field has indicated
`MIT OR Apache-2.0` since it was added.

In accordance with the above, replace the two license files with a
combined LICENSE.txt that makes these terms clear and gives attribution
to works from which this library is derived.

Fixes: https://github.com/rust-lang/libm/issues/215
Link: https://rust-lang.zulipchat.com/#narrow/channel/335408-foundation/topic/Request.20for.20legal.20team.20input.20on.20crate.20licensing
Link: https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
2024-10-26 17:09:57 -05:00
Trevor Gross
79bf4fe1f2 Don't deny warnings in lib.rs
Having `#![deny(warnings)]` for the entire crate is a bit of a
development annoyance. We already run CI with `RUSTFLAGS=-Dwarnings` so
there isn't much of a reason to check this locally. Thus, remove the
attribute.

Additionally, sort the clippy allows.
2024-10-26 00:54:26 -05:00
Trevor Gross
a68516ed6a Rename the musl-bitwise-tests feature to test-musl-serialized
We will have more test features in the near future, and it would be nice
for them all to have a common `test-` prefix. Reverse the existing
feature so this is the case.
2024-10-25 20:57:19 -04:00
Trevor Gross
394fb9f2bc Add an abs function to the Float trait
There is no in-crate use for this yet, but we will make use of it in
`libm`.
2024-10-25 14:30:03 -05:00
Trevor Gross
2f7fafd182 Rename Float::repr and Float::from_repr
`to_bits` and `from_bits` are builtin methods on float types. Rename
`repr` to `to_bits` and `from_repr` to `from_bits` so this is consistent
with usage that doesn't go through the trait.
2024-10-25 14:18:53 -05:00