Merge fabsf16/32/64/128 into fabs::<F>#153834
Conversation
|
Some changes occurred to the CTFE machinery Some changes occurred to the CTFE / Miri interpreter cc @rust-lang/miri Some changes occurred in compiler/rustc_codegen_gcc Some changes occurred in compiler/rustc_codegen_cranelift cc @bjorn3 Some changes occurred to the intrinsics. Make sure the CTFE / Miri interpreter |
|
r? @TaKO8Ki rustbot has assigned @TaKO8Ki. Use Why was this reviewer chosen?The reviewer was selected based on:
|
fabsfN into fabs::<F>fabsf16/32/64/128 into fabs::<F>
|
r? tgross35 |
This comment has been minimized.
This comment has been minimized.
|
ah oops i was wondering why gcc wasn't working locally, guess it never installed :') ill fix this soon |
library/core/src/intrinsics/mod.rs
Outdated
| #[rustc_nounwind] | ||
| #[rustc_intrinsic] | ||
| pub const fn fabsf128(x: f128) -> f128; | ||
| pub const fn fabs<T: Copy>(x: T) -> T; |
There was a problem hiding this comment.
suggestion: like there's
rust/library/core/src/intrinsics/bounds.rs
Lines 5 to 25 in f1ceedf
| pub const fn fabs<T: Copy>(x: T) -> T; | |
| pub const fn fabs<T: bounds::FloatPrimitive>(x: T) -> T; |
or similar.
There was a problem hiding this comment.
Fixed in 74114c9; also added it to the other generic float intrinsics
There was a problem hiding this comment.
note this changes the diagnostic when these intrinsics are misused: it now gives a type error (see 043f9ad) rather than a monomorphization error; i think this is a good thing :)
| ty::Float(FloatTy::F32) | ty::Float(FloatTy::F64) => fx.bcx.ins().fabs(x), | ||
| // FIXME(bytecodealliance/wasmtime#8312): Use `fabsf16` once Cranelift | ||
| // backend lowerings are implemented. | ||
| ty::Float(FloatTy::F16) => codegen_f16_f128::abs_f16(fx, x), |
There was a problem hiding this comment.
pondering: these make me wonder if it'd be worth just having fallback mir for this?
See how there's
pub const unsafe fn disjoint_bitor<T: [const] fallback::DisjointBitOr>(a: T, b: T) -> T {for example to give that one a fallback; might be reasonable to do the same for fabs (since it's easy to implement) and backends can just fallback to that if they haven't implemented it natively for f16/f128 yet.
There was a problem hiding this comment.
(That said, it's a copysign+fabs thing only, really, since fallback MIR for most float ops is probably not a good idea. fpow is hard.)
There was a problem hiding this comment.
I'd like to have fallbacks for all of these via libcalls; have some of that in progress at #150946.
abs and copysign probably shouldn't use the libcalls though, they can copy the implementation from https://github.com/rust-lang/compiler-builtins/blob/85db9f1923007c287b894d392b880545ec70d05e/libm/src/math/generic/fabs.rs and https://github.com/rust-lang/compiler-builtins/blob/85db9f1923007c287b894d392b880545ec70d05e/libm/src/math/generic/copysign.rs.
This comment has been minimized.
This comment has been minimized.
|
btw; I saw in rust/compiler/rustc_codegen_ssa/src/errors.rs Lines 718 to 724 in 620e36a rust/compiler/rustc_codegen_ssa/src/errors.rs Lines 742 to 748 in 620e36a |
|
The diagnostic error types are quite the mess there, feel free to adjust or replace them by string-based errors if that simplifies the code. |
This comment has been minimized.
This comment has been minimized.
69be112 to
9210d78
Compare
fair enough :) removed the duplicate in ebb6dfb |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Misuse of intrinsics falls under rust-lang/compiler-team#620 -- you can feel free to rip out any inconvenient errors entirely and just have them ICE. |
| #[rustc_nounwind] | ||
| #[rustc_intrinsic] | ||
| pub const fn fabsf128(x: f128) -> f128; | ||
| pub const fn fabs<T: bounds::FloatPrimitive>(x: T) -> T; |
There was a problem hiding this comment.
@rust-lang/lang this would mark fabs as indirectly const stable for all float types, not just f32 and f64. The const implementation is uniform across all types so I have no concerns about this -- the f16 and f128 implementation is and has been ready for stable for a while, it's the non-const implementation of f16 and f128 that's not ready. ;)
Nevertheless, new intrinsics being available to stable const code requires lang approval. Not sure if you think a full FCP is required for a trivial case like this.
There was a problem hiding this comment.
btw if a FCP is required, we should throw in copysign in there, which is in the same situation: const stable for f32/f64 but not for f16/f128, and it's also a binary operation
There was a problem hiding this comment.
We should probably throw in all the intrinsics you intend to generalize that are easily implemented with apfloat. Do you have a list of them?
There was a problem hiding this comment.
Oh, I didn't realize all the f16/f128 rounding methods have already been allowed in const-stable since #143604. That may have been an accident, but it's also not really a problem.
There was a problem hiding this comment.
yep, it's fabs, copysign, minnum and maxnum; all other float intrinsics are all const stable across all float types or not const stable for any
There was a problem hiding this comment.
Personally (with my lang hat on but not speaking as team consensus) I would be fine treating this as "the previous FCP was saying that floating-point abs is allowed to be const-stable -- because it's easy to do reliably in const, being that it's only bitwise (without even NAN nondet, IIRC?) -- and how exactly that translates to specific intrinsics is a compiler/ctfe question without needing addtional lang FCPs".
But we'll see what the meeting says on Wed.
There was a problem hiding this comment.
without even NAN nondet, IIRC?
Correct, fabs just mutates the sign bit and nothing else.
|
The final comment period, with a disposition to merge, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. |
|
@bors r=tgross35,RalfJung |
|
📋 This PR cannot be approved because it currently has the following label: |
|
@bors r=tgross35,RalfJung |
…tgross35,RalfJung Merge `fabsf16/32/64/128` into `fabs::<F>` Following [a small conversation on Zulip](https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/Float.20intrinsics/with/521501401) (and because I'd be interested in starting to contribute on Rust), I thought I'd give a try at merging the float intrinsics :) This PR just merges `fabsf16`, `fabsf32`, `fabsf64`, `fabsf128`, as it felt like an easy first target. Notes: - I'm opening the PR for one intrinsic as it's probably easier if the shift is done one intrinsic at a time, but let me know if you'd rather I do several at a time to reduce the number of PRs. - Currently this PR increases LOCs, despite being an attempt at simplifying the intrinsics/compilers. I believe this increase is a one time thing as I had to define new functions and move some things around, and hopefully future PRs/commits will reduce overall LoCs - `fabsf32` and `fabsf64` are `#[rustc_intrinsic_const_stable_indirect]`, while `fabsf16` and `fabsf128` aren't; because `f32`/`f64` expect the function to be const, the generic version must be made indirectly stable too. We'd need to check with T-lang this change is ok; the only other intrinsics where there is such a mismatch is `minnum`, `maxnum` and `copysign`. - I haven't touched libm because I'm not familiar with how it works; any guidance would be welcome!
…uwer Rollup of 7 pull requests Successful merges: - #147811 (naked functions: respect `function-sections`) - #153834 (Merge `fabsf16/32/64/128` into `fabs::<F>`) - #154043 (simd_fmin/fmax: make semantics and name consistent with scalar intrinsics) - #154494 (triagebot: add reminder for bumping CI LLVM stamp) - #153374 (Fix LegacyKeyValueFormat report from docker build: dist-x86_64) - #154320 (`trim_prefix` for paths) - #154453 (Fix ice in rustdoc of private reexport)
…tgross35,RalfJung Merge `fabsf16/32/64/128` into `fabs::<F>` Following [a small conversation on Zulip](https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/Float.20intrinsics/with/521501401) (and because I'd be interested in starting to contribute on Rust), I thought I'd give a try at merging the float intrinsics :) This PR just merges `fabsf16`, `fabsf32`, `fabsf64`, `fabsf128`, as it felt like an easy first target. Notes: - I'm opening the PR for one intrinsic as it's probably easier if the shift is done one intrinsic at a time, but let me know if you'd rather I do several at a time to reduce the number of PRs. - Currently this PR increases LOCs, despite being an attempt at simplifying the intrinsics/compilers. I believe this increase is a one time thing as I had to define new functions and move some things around, and hopefully future PRs/commits will reduce overall LoCs - `fabsf32` and `fabsf64` are `#[rustc_intrinsic_const_stable_indirect]`, while `fabsf16` and `fabsf128` aren't; because `f32`/`f64` expect the function to be const, the generic version must be made indirectly stable too. We'd need to check with T-lang this change is ok; the only other intrinsics where there is such a mismatch is `minnum`, `maxnum` and `copysign`. - I haven't touched libm because I'm not familiar with how it works; any guidance would be welcome!
…uwer Rollup of 9 pull requests Successful merges: - #150752 (Update libc to v0.2.183) - #153380 (stabilize new RangeFrom type and iterator) - #153834 (Merge `fabsf16/32/64/128` into `fabs::<F>`) - #154043 (simd_fmin/fmax: make semantics and name consistent with scalar intrinsics) - #154494 (triagebot: add reminder for bumping CI LLVM stamp) - #153374 (Fix LegacyKeyValueFormat report from docker build: dist-x86_64) - #154320 (`trim_prefix` for paths) - #154453 (Fix ice in rustdoc of private reexport) - #154515 (Notify stdarch maintainers on changes in std_detect)
Rollup of 9 pull requests Successful merges: - #153380 (stabilize new RangeFrom type and iterator) - #153834 (Merge `fabsf16/32/64/128` into `fabs::<F>`) - #154043 (simd_fmin/fmax: make semantics and name consistent with scalar intrinsics) - #154494 (triagebot: add reminder for bumping CI LLVM stamp) - #153374 (Fix LegacyKeyValueFormat report from docker build: dist-x86_64) - #154320 (`trim_prefix` for paths) - #154453 (Fix ice in rustdoc of private reexport) - #154504 (move many tests from `structs-enums` to `structs` or `enum`) - #154515 (Notify stdarch maintainers on changes in std_detect)
Rollup merge of #153834 - N1ark:generic-float-intrinsics, r=tgross35,RalfJung Merge `fabsf16/32/64/128` into `fabs::<F>` Following [a small conversation on Zulip](https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/Float.20intrinsics/with/521501401) (and because I'd be interested in starting to contribute on Rust), I thought I'd give a try at merging the float intrinsics :) This PR just merges `fabsf16`, `fabsf32`, `fabsf64`, `fabsf128`, as it felt like an easy first target. Notes: - I'm opening the PR for one intrinsic as it's probably easier if the shift is done one intrinsic at a time, but let me know if you'd rather I do several at a time to reduce the number of PRs. - Currently this PR increases LOCs, despite being an attempt at simplifying the intrinsics/compilers. I believe this increase is a one time thing as I had to define new functions and move some things around, and hopefully future PRs/commits will reduce overall LoCs - `fabsf32` and `fabsf64` are `#[rustc_intrinsic_const_stable_indirect]`, while `fabsf16` and `fabsf128` aren't; because `f32`/`f64` expect the function to be const, the generic version must be made indirectly stable too. We'd need to check with T-lang this change is ok; the only other intrinsics where there is such a mismatch is `minnum`, `maxnum` and `copysign`. - I haven't touched libm because I'm not familiar with how it works; any guidance would be welcome!
Rollup of 9 pull requests Successful merges: - rust-lang/rust#153380 (stabilize new RangeFrom type and iterator) - rust-lang/rust#153834 (Merge `fabsf16/32/64/128` into `fabs::<F>`) - rust-lang/rust#154043 (simd_fmin/fmax: make semantics and name consistent with scalar intrinsics) - rust-lang/rust#154494 (triagebot: add reminder for bumping CI LLVM stamp) - rust-lang/rust#153374 (Fix LegacyKeyValueFormat report from docker build: dist-x86_64) - rust-lang/rust#154320 (`trim_prefix` for paths) - rust-lang/rust#154453 (Fix ice in rustdoc of private reexport) - rust-lang/rust#154504 (move many tests from `structs-enums` to `structs` or `enum`) - rust-lang/rust#154515 (Notify stdarch maintainers on changes in std_detect)
View all comments
Following a small conversation on Zulip (and because I'd be interested in starting to contribute on Rust), I thought I'd give a try at merging the float intrinsics :)
This PR just merges
fabsf16,fabsf32,fabsf64,fabsf128, as it felt like an easy first target.Notes:
fabsf32andfabsf64are#[rustc_intrinsic_const_stable_indirect], whilefabsf16andfabsf128aren't; becausef32/f64expect the function to be const, the generic version must be made indirectly stable too. We'd need to check with T-lang this change is ok; the only other intrinsics where there is such a mismatch isminnum,maxnumandcopysign.