Commit Graph

2119 Commits

Author SHA1 Message Date
Sebastian Neubauer
e8eb76a45a Disable f128 for amdgpu (#737)
`compiler_builtins` fails to compile to amdgpu if f128 is enabled.
The reason seems to be that compiler_builtins uses libcalls in the
implementation. I’m not really familiar with what libcalls are, but the
LLVM amdgpu backend explicitly does not support them.

Error message:
```
LLVM ERROR: unsupported libcall legalization
```
2024-12-26 00:01:14 -05: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
2cbacf89af Fix a bug in abs_diff
These were taken from `compiler-builtins` but the implementation has a
bug near the integer limits. Fixed in `compiler-builtins` by using
`core`'s implementation at [1], this is the corresponding fix for
`libm`.

[1]: https://github.com/rust-lang/compiler-builtins/pull/736
2024-12-22 22:24:38 +00:00
Trevor Gross
a4d9b4a6a2 Fix a bug in abs_diff
These implementations of `abs_diff` were added in c2ff1b3119
("Completely overhaul fuzz testing"), but the signed implementation is
wrong when |x| + |y| exceeds the integer's limits (e.g.
`(-128).abs_diff(1)` should be 128 but currently these return 127.

Resolve this by just using `std`'s implementation since that is stable
now. This isn't used anywhere critical, we probably just weren't hitting
the edge case.
2024-12-22 22:08:31 +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
beetrees
7c1072e3fc Use https: links in README.md 2024-11-14 18:13:10 +00:00
Trevor Gross
04ccb683d9 Disable f16 on platforms that have recursion problems
CI in [1] seems to indicate that there are cases where the `f16`
infinite recursion bug ([2], [3]) can make its way into what gets called
during tests, even though this doesn't seem to be the usual case. In
order to make sure that we avoid these completely, just unset
`f16_enabled` on any platforms that have the recursion problem.

This also refactors the `match` statement to be more in line with
`library/std/build.rs`.

[1]: https://github.com/rust-lang/compiler-builtins/pull/729
[2]: https://github.com/llvm/llvm-project/issues/97981
[3]: https://github.com/rust-lang/compiler-builtins/issues/651
2024-11-05 02:57:34 -06: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
github-actions[bot]
c33f521bb5 chore: release v0.1.139 2024-11-03 23:08:41 +00:00
beetrees
10bdf3b6c1 Remove incorrect sparcv9 match pattern from configure_f16_f128 2024-11-03 22:54:01 +00: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
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
github-actions[bot]
4c7450d10c chore: release v0.1.138 2024-11-01 11:00:27 +00:00
Trevor Gross
28fb4bc868 Enable the changelog for release-plz
This crate isn't meant for direct use, but having an easy way to see
what changed between versions would still be helpful when this crate is
updated in rust-lang/rust.
2024-11-01 05:59:57 -05:00
WANG Rui
ec673535f7 ci: add support for loongarch64-unknown-linux-gnu 2024-11-01 05:48:47 -05:00
hev
ca996df5c1 Use f16_enabled/f128_enabled in examples/intrinsics.rs (#724)
Enable conditional compilation for intrinsics with `f16_enabled` and `f128_enabled`
2024-11-01 10:34:51 +00:00
hev
53b3e71bbc Disable f16 for LoongArch64 (#722)
Disable `f161` for LoongArch64 due to incorrect code generation on LLVM 19,
which causes failures in `testcrate/tests/conv.rs`. This workaround will
remain in place until llvm/llvm-project#109093 is merged or we upgrade to
LLVM 20.
2024-11-01 10:00:00 +00: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
github-actions[bot]
94e6ed373a chore: release v0.1.137 2024-10-31 19:13:38 -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
9818afad7c Remove the unneeded isqrt feature gate
[1] has been stabilized so we no longer need to enable it.

[1]: https://github.com/rust-lang/rust/issues/116226
2024-10-30 12:27:59 -05:00
Trevor Gross
fbd6907358 Add integer to f128 conversions 2024-10-30 12:25:24 -05:00
Trevor Gross
51dd4da053 Refactor integer to float conversion
Extract some common routines to separate functions in order to
deduplicate code and remove some of the magic.
2024-10-30 12:25:22 -05:00
Trevor Gross
1dc50415cd Add an apfloat fallback for int to float tests 2024-10-30 12:22:57 -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