Commit graph

729 commits

Author SHA1 Message Date
Trevor Gross
9d62bd0636 Merge pull request rust-lang/libm#483 from tgross35/hex-print
Add support for printing hex float syntax
2025-01-29 23:58:57 -06:00
Trevor Gross
e283c25602 Util: also print the hex float format for outputs 2025-01-29 00:17:19 +00:00
Trevor Gross
f767b58ba4 Introduce a wrapper type for IEEE hex float formatting 2025-01-29 00:17:19 +00:00
Trevor Gross
99c1080556 Support parsing NaN and infinities from the hf* functions
This isn't very useful for constants since the trait constants are
available, but does enable roundtripping via hex float syntax.
2025-01-29 00:12:31 +00:00
Trevor Gross
396725e146 Revert "Temporarily pin indicatif to 0.17.9"
This reverts commit 1dacdabdb6186f97144c50f8952575576deb3730.
2025-01-28 14:21:23 -06:00
Trevor Gross
176d22db12 Temporarily pin indicatif to 0.17.9
0.17.10 introduced a change that removes `Sync` from `ProgressStyle`,
which makes it more difficult to share in a callback. Pin the dependency
for now until we see if `indicatif` will change this back or if we need
to find a workaround.
2025-01-28 05:00:15 -06:00
Trevor Gross
259e544192 Switch musl from a script download to a submodule
Rather than keeping a script that downloads the tarball, we can just add
musl as a submodule and let git handle the synchronizatoin. Do so here.
2025-01-28 00:39:45 -06:00
Trevor Gross
98fd72b62a Merge pull request rust-lang/libm#479 from tgross35/cargo-profile-updates
Rework the available Cargo profiles
2025-01-27 20:16:39 -06:00
Trevor Gross
90c76ad3cb Ignore specific atan2 and sin tests on i586
There seems to be a case of unsoundness with the `i586` version of
`atan2`. For the following test:

    assert_eq!(atan2(2.0, -1.0), atan(2.0 / -1.0) + PI);atan2(2.0, -1.0)

The output is optimization-dependent. The new `release-checked` profile
produces the following failure:

    thread 'math::atan2::sanity_check' panicked at src/math/atan2.rs:123:5:
    assertion `left == right` failed
      left: 2.0344439357957027
     right: 2.0344439357957027

Similarly, `sin::test_near_pi` fails with the following:

    thread 'math::sin::test_near_pi' panicked at src/math/sin.rs:91:5:
    assertion `left == right` failed
      left: 6.273720864039203e-7
     right: 6.273720864039205e-7

Mark the tests ignored on `i586` for now.
2025-01-27 12:34:27 +00:00
Trevor Gross
f0b932e723 Rework the available Cargo profiles
Currently the default release profile enables LTO and single CGU builds,
which is very slow to build. Most tests are better run with
optimizations enabled since it allows testing a much larger number of
inputs, so it is inconvenient that building can sometimes take
significantly longer than the tests.

Remedy this by doing the following:

* Move the existing `release` profile to `release-opt`.
* With the above, the default `release` profile is untouched (16 CGUs
  and thin local LTO).
* `release-checked` inherits `release`, so no LTO or single CGU.

This means that the simple `cargo test --release` becomes much faster
for local development. We are able to enable the other profiles as
needed in CI.

Tests should ideally still be run with `--profile release-checked` to
ensure there are no debug assetions or unexpected wrapping math hit.

`no-panic` still needs a single CGU, so must be run with `--profile
release-opt`. Since it is not possible to detect CGU or profilel
configuration from within build scripts, the `ENSURE_NO_PANIC`
environment variable must now always be set.
2025-01-25 07:38:15 +00:00
Trevor Gross
4a98907b8a Remove remnants of the checked feature
The Cargo feature `checked` was added in 410b0633a6b9 ("Overhaul tests")
and later removed in e4ac1399062c ("swap stable to be unstable, checked
is now debug_assertions"). However, there are a few remaining uses of
`feature = "checked"` that did not get removed. Clean these up here.
2025-01-25 04:18:44 +00:00
Trevor Gross
9c6548e448 Merge pull request rust-lang/libm#477 from tgross35/upgrade-dependencies
Upgrade all dependencies to the latest version
2025-01-24 20:01:27 -06:00
Trevor Gross
b9bd107a67 Use remquo from Rug
Rug 1.27.0 exposes `remquo`; make use of it for our tests. Removing our
workaround also allows removing the direct dependency on `gmp-mpfr-sys`
2025-01-25 01:08:31 +00:00
Trevor Gross
edd1289341 Use frexp from Rug
Rug 1.27.0 exposes `frexp`. Make use of it for our tests.
2025-01-25 01:00:01 +00:00
Trevor Gross
62f0fd40d1 Use az exported from Rug
Since Rug 1.27.0, `az` is reexported. This means we no longer need to
track it as a separate dependency.
2025-01-25 00:55:03 +00:00
Trevor Gross
7c6c0c1b79 Upgrade all dependencies to the latest version
In particular, this includes updates to Rug that we can make use of [1],
[2], [3], [4].

[1]: https://gitlab.com/tspiteri/rug/-/issues/78
[2]: https://gitlab.com/tspiteri/rug/-/issues/80
[3]: https://gitlab.com/tspiteri/rug/-/issues/76
[4]: https://gitlab.com/tspiteri/rug/-/issues/73
2025-01-25 00:50:02 +00:00
Trevor Gross
173a48ce8c Enable missing icount benchmarks
A few new functions were added but this list did not get updated. Do so
here.
2025-01-24 03:39:49 -06:00
Trevor Gross
3524632b0b Merge pull request rust-lang/libm#470 from tgross35/f128-fmod
Add `fmodf128`
2025-01-24 02:51:12 -06:00
Trevor Gross
71200bc3ce Add fmodf128
This function is significantly slower than all others so includes an
override in `EXTREMELY_SLOW_TESTS`. Without it, PR CI takes ~1hour and
the extensive tests in CI take ~1day.
2025-01-24 08:23:15 +00:00
Trevor Gross
b863308979 Add way to override the number of iterations for specific tests
Certain functions (`fmodf128`) are significantly slower than others,
to the point that running the default number of tests adds tens of
minutes to PR CI and extensive test time increases to ~1day. It does not
make sense to do this by default; so, introduce `EXTREMELY_SLOW_TESTS`
to test configuration that allows setting specific tests that need to
have a reduced iteration count.
2025-01-24 08:23:15 +00:00
Trevor Gross
9d38c93fb0 Increase or set CI timeouts
With the new routines, some of our tests are running close to their
timeouts. Increase the timeout for test jobs, and set a short timeout
for all other jobs that did not have one.
2025-01-24 01:13:16 -06:00
Trevor Gross
ddffab3a2f Merge pull request rust-lang/libm#469 from tgross35/generic-mod
Add `fmodf16`
2025-01-24 00:41:19 -06:00
Trevor Gross
67218cbaa5 Add fmodf16 using the generic implementation 2025-01-24 06:03:59 +00:00
Trevor Gross
08eda86de2 Add a generic version of fmod
This can replace `fmod` and `fmodf`. As part of this change I was able
to replace some of the `while` loops with `leading_zeros`.
2025-01-24 05:55:15 +00:00
Trevor Gross
df5ac49390 Merge pull request rust-lang/libm#466 from tgross35/generic-fmin-fmax
Add `fminf16`, `fmaxf16`, `fminf128`, and `fmaxf128`
2025-01-23 22:30:39 -06:00
Trevor Gross
6d5105c006 Add fminf16, fmaxf16, fminf128, and fmaxf128 2025-01-24 03:01:36 +00:00
Trevor Gross
f94df5d524 Add a generic version of fmin and fmax
These can be used for `fmin`, `fminf`, `fmax`, and `fmaxf`. No changes
to the implementation are made, so [1] is not fixed.

[1]: https://github.com/rust-lang/libm/issues/439
2025-01-24 02:58:00 +00:00
Trevor Gross
453bebf7c1 Merge pull request rust-lang/libm#465 from tgross35/generic-round
Add `roundf16` and `roundf128`
2025-01-23 20:28:04 -06:00
Trevor Gross
357ee34abb Remove an outdated note about precision 2025-01-24 01:59:10 +00:00
Trevor Gross
d20a5e82a5 Add roundf16 and roundf128 2025-01-24 01:59:10 +00:00
Trevor Gross
cdbe65b503 Add a generic version of round
This replaces `round` and `roundf`.
2025-01-24 01:49:23 +00:00
Trevor Gross
3aa2d1cfc2 Add a generic version of scalbn
This replaces the `f32` and `f64` versions of `scalbn` and `ldexp`.
2025-01-23 16:59:44 -06:00
Trevor Gross
b8da1919f9 Change from_parts to take a u32 exponent rather than i32
Make things more consistent with other API that works with a bitwise
representation of the exponent. That is, use `u32` when working with a
bitwise (biased) representation, use `i32` when the bitwise
representation has been adjusted for bias and ay be negative.

Every place this has been used so far has an `as i32`, so this change
makes things cleaner anyway.
2025-01-23 03:46:46 -06:00
Trevor Gross
ca8dccc5b6 Introduce XFAILs that assert failure
Currently our XFAILs are open ended; we do not check that it actually
fails, so we have no easy way of knowing that a previously-failing test
starts passing. Introduce a new enum that we return from overrides to
give us more flexibility here, including the ability to assert that
expected failures happen.

With the new enum, it is also possible to specify ULP via return value
rather than passing a `&mut u32` parameter.

This includes refactoring of `precision.rs` to be more accurate about
where errors come from, if possible.

Fixes: https://github.com/rust-lang/libm/issues/455
2025-01-23 01:15:21 -06:00
Trevor Gross
8dc4ef6f0f Add hf16! and hf128!
Expand the existing hex float functions and macros with versions that
work with `f16` and `f128`.
2025-01-22 21:57:23 -06:00
Trevor Gross
42e22132b4 Fix the parsing of three-item tuples in util 2025-01-22 18:28:57 -05:00
Trevor Gross
c788ced502 Add the ability to parse hex, binary, and float hex with util 2025-01-22 17:03:34 -05:00
Trevor Gross
6c6354bbe1 Merge pull request rust-lang/libm#454 from tgross35/generic-rint
Add `rintf16` and `rintf128`
2025-01-22 06:31:35 -05:00
Trevor Gross
b22398d658 Add rintf16 and rintf128
Use the generic algorithms to provide implementations for these
routines.
2025-01-22 11:04:39 +00:00
Trevor Gross
bf2d171b1a Add a generic version of rint
Use this to implement `rint` and `rintf`.
2025-01-22 11:04:36 +00:00
Trevor Gross
3a96a55e70 Merge pull request rust-lang/libm#437 from tgross35/generic-floor
Add `floorf16` and `floorf128`
2025-01-22 06:02:17 -05:00
Trevor Gross
3ae70a4a6c Adjust ceil style to be more similar to floor 2025-01-22 08:54:21 +00:00
Trevor Gross
6a8bb0fa80 Add floorf16 and floorf128
Use the generic algorithms to provide implementations for these
routines.
2025-01-22 08:50:06 +00:00
Trevor Gross
42fce292ab Add a generic version of floor
Additionally, make use of this version to implement `floor` and
`floorf`.

Similar to `ceil`, musl'f `ceilf` routine seems to work better for all
float widths than the `ceil` algorithm. Trying with the `ceil` (`f64`)
algorithm produced the following regressions:

    icount::icount_bench_floor_group::icount_bench_floor logspace:setup_floor()
    Performance has regressed: Instructions (14064 > 13171) regressed by +6.78005% (>+5.00000)
      Baselines:                      softfloat|softfloat
      Instructions:                       14064|13171                (+6.78005%) [+1.06780x]
      L1 Hits:                            16821|15802                (+6.44855%) [+1.06449x]
      L2 Hits:                                0|0                    (No change)
      RAM Hits:                               8|9                    (-11.1111%) [-1.12500x]
      Total read+write:                   16829|15811                (+6.43856%) [+1.06439x]
      Estimated Cycles:                   17101|16117                (+6.10535%) [+1.06105x]
    icount::icount_bench_floorf128_group::icount_bench_floorf128 logspace:setup_floorf128()
      Baselines:                      softfloat|softfloat
      Instructions:                      166868|N/A                  (*********)
      L1 Hits:                           221429|N/A                  (*********)
      L2 Hits:                                1|N/A                  (*********)
      RAM Hits:                              34|N/A                  (*********)
      Total read+write:                  221464|N/A                  (*********)
      Estimated Cycles:                  222624|N/A                  (*********)
    icount::icount_bench_floorf16_group::icount_bench_floorf16 logspace:setup_floorf16()
      Baselines:                      softfloat|softfloat
      Instructions:                      143029|N/A                  (*********)
      L1 Hits:                           176517|N/A                  (*********)
      L2 Hits:                                1|N/A                  (*********)
      RAM Hits:                              13|N/A                  (*********)
      Total read+write:                  176531|N/A                  (*********)
      Estimated Cycles:                  176977|N/A                  (*********)
    icount::icount_bench_floorf_group::icount_bench_floorf logspace:setup_floorf()
    Performance has regressed: Instructions (14732 > 10441) regressed by +41.0976% (>+5.00000)
      Baselines:                      softfloat|softfloat
      Instructions:                       14732|10441                (+41.0976%) [+1.41098x]
      L1 Hits:                            17616|13027                (+35.2268%) [+1.35227x]
      L2 Hits:                                0|0                    (No change)
      RAM Hits:                               8|6                    (+33.3333%) [+1.33333x]
      Total read+write:                   17624|13033                (+35.2260%) [+1.35226x]
      Estimated Cycles:                   17896|13237                (+35.1968%) [+1.35197x]
2025-01-22 08:48:11 +00:00
Trevor Gross
7a357b96c0 Merge pull request rust-lang/libm#436 from tgross35/generic-ceil
Add `ceilf16` and `ceilf128`
2025-01-22 02:48:28 -05:00
Trevor Gross
9064c42abe Add ceilf16 and ceilf128
Use the generic algorithms to provide implementations for these
routines.
2025-01-22 07:22:32 +00:00
Trevor Gross
c00f119166 Add a generic version of ceil
Additionally, make use of this version to implement `ceil` and `ceilf`.

Musl's `ceilf` algorithm seems to work better for all versions of the
functions. Testing with a generic version of musl's `ceil` routine
showed the following regressions:

    icount::icount_bench_ceil_group::icount_bench_ceil logspace:setup_ceil()
    Performance has regressed: Instructions (14064 > 13171) regressed by +6.78005% (>+5.00000)
      Baselines:                      softfloat|softfloat
      Instructions:                       14064|13171                (+6.78005%) [+1.06780x]
      L1 Hits:                            16697|15803                (+5.65715%) [+1.05657x]
      L2 Hits:                                0|0                    (No change)
      RAM Hits:                               7|8                    (-12.5000%) [-1.14286x]
      Total read+write:                   16704|15811                (+5.64797%) [+1.05648x]
      Estimated Cycles:                   16942|16083                (+5.34104%) [+1.05341x]
    icount::icount_bench_ceilf_group::icount_bench_ceilf logspace:setup_ceilf()
    Performance has regressed: Instructions (14732 > 9901) regressed by +48.7931% (>+5.00000)
      Baselines:                      softfloat|softfloat
      Instructions:                       14732|9901                 (+48.7931%) [+1.48793x]
      L1 Hits:                            17494|12611                (+38.7202%) [+1.38720x]
      L2 Hits:                                0|0                    (No change)
      RAM Hits:                               6|6                    (No change)
      Total read+write:                   17500|12617                (+38.7018%) [+1.38702x]
      Estimated Cycles:                   17704|12821                (+38.0860%) [+1.38086x]
2025-01-22 07:22:32 +00:00
Trevor Gross
a7cd13b6a3 Make Float::exp return an unsigned integer
`exp` does not perform any form of unbiasing, so there isn't any reason
it should be signed. Change this.

Additionally, add `EPSILON` to the `Float` trait.
2025-01-22 07:15:39 +00:00
Trevor Gross
5ac2f99954 Shift then mask, rather than mask then shift
This may allow for small optimizations with larger float types since
`u32` math can be used after shifting. LLVM may be already getting this
anyway.
2025-01-22 07:09:37 +00:00
Trevor Gross
51496423b5 Merge pull request rust-lang/libm#431 from tgross35/generic-sqrt
Port musl's Goldschmidt `sqrt`; add `sqrtf16` and `sqrtf128`
2025-01-22 00:59:34 -05:00