abrown requested cfallin for a review on PR #2251.
abrown opened PR #2251 from access-immediates
to main
:
@cfallin, here is what I came up with after we discussed this last week. This change:
- moves
DataValue
into cranelift-codegen so that I can use it as a value wrapper- gives
InstructionData
the ability to find immediate values in the format structures- reworks
LowerCtx::get_immediate
to grab the value from the instruction (and the DataFlowGraph for vector immediates)I felt like this approach provides the new backend a more abstract view of immediates instead of munging directly in the
InstructionData
but I didn't perform the refactor on the rest of the places the new backend grabs immediates because I wanted to get some feedback first.
abrown submitted PR Review.
abrown created PR Review Comment:
Here and on line 295 I had to switch unsigned to signed--there are other ways to do this (bump up the bit width, e.g.) but I'm not really sure it matters (users of this probably know what to do?)
cfallin submitted PR Review.
cfallin submitted PR Review.
cfallin created PR Review Comment:
I'm not sure about
unimplemented!()
here -- usually that implies it would be possible but we just haven't done it -- perhapsNone
here, since we wrapimm_value()
at a higher level? Or better, would it make sense to require a borrow ofdfg.immediates
as an argument to this function? Then we wouldn't need the two-level split logic between this match andLowerCtx
's...
cfallin created PR Review Comment:
For clarity, maybe
let imm: u32 = imm.into();
then we can writeDataValue::from(imm as i32)
?
abrown updated PR #2251 from access-immediates
to main
:
@cfallin, here is what I came up with after we discussed this last week. This change:
- moves
DataValue
into cranelift-codegen so that I can use it as a value wrapper- gives
InstructionData
the ability to find immediate values in the format structures- reworks
LowerCtx::get_immediate
to grab the value from the instruction (and the DataFlowGraph for vector immediates)I felt like this approach provides the new backend a more abstract view of immediates instead of munging directly in the
InstructionData
but I didn't perform the refactor on the rest of the places the new backend grabs immediates because I wanted to get some feedback first.
abrown updated PR #2251 from access-immediates
to main
:
@cfallin, here is what I came up with after we discussed this last week. This change:
- moves
DataValue
into cranelift-codegen so that I can use it as a value wrapper- gives
InstructionData
the ability to find immediate values in the format structures- reworks
LowerCtx::get_immediate
to grab the value from the instruction (and the DataFlowGraph for vector immediates)I felt like this approach provides the new backend a more abstract view of immediates instead of munging directly in the
InstructionData
but I didn't perform the refactor on the rest of the places the new backend grabs immediates because I wanted to get some feedback first.
abrown submitted PR Review.
abrown created PR Review Comment:
Yeah, I was dubious about which way to go here. I felt like it was nice that this function didn't depend on the
DataFlowGraph
so I went withNone
.
abrown submitted PR Review.
abrown created PR Review Comment:
...And documented it some more.
abrown updated PR #2251 from access-immediates
to main
:
@cfallin, here is what I came up with after we discussed this last week. This change:
- moves
DataValue
into cranelift-codegen so that I can use it as a value wrapper- gives
InstructionData
the ability to find immediate values in the format structures- reworks
LowerCtx::get_immediate
to grab the value from the instruction (and the DataFlowGraph for vector immediates)I felt like this approach provides the new backend a more abstract view of immediates instead of munging directly in the
InstructionData
but I didn't perform the refactor on the rest of the places the new backend grabs immediates because I wanted to get some feedback first.
bjorn3 submitted PR Review.
bjorn3 submitted PR Review.
bjorn3 created PR Review Comment:
Please use
Ieee32
/Ieee64
instead of f32/f64. Otherwise NaN bits could get changed.
abrown submitted PR Review.
abrown created PR Review Comment:
What do you think of https://doc.rust-lang.org/std/primitive.f32.html#method.from_bits? Looks to me like
f32::from_bits
(which is how we get fromIeee32
for this value) is not going to change NaN bits at all.
bjorn3 submitted PR Review.
bjorn3 created PR Review Comment:
The
to_bits
method can change it. x86 processors normalize it when moving out of an SSE register I think.
abrown submitted PR Review.
abrown created PR Review Comment:
I don't know... Rust devs think the issue is "overblown": https://doc.rust-lang.org/src/core/num/f32.rs.html#700-702.
bjorn3 submitted PR Review.
bjorn3 created PR Review Comment:
That is a different issue. What I am talking about here is that for example when the user intended an sNaN it would quietly get turned into a regular NaN.
abrown submitted PR Review.
abrown created PR Review Comment:
Zulip?
cfallin submitted PR Review.
cfallin created PR Review Comment:
To add my 2¢ here: I don't think there's much cost to using
Ieee32
/Ieee64
(just some bitcasts), it has accessors to give us float values when we need them, it guarantees bit-for-bit accuracy otherwise as we manipulate code, and we already use it elsewhere for constants. I'd prefer the whole lowering path, from CLIF to the final point that we emit constants into theMachBuffer
, to avoid potential machine-specific issues withf32
/f64
. Possiblyl @sunfishcode has thoughts (I know you've talked about NaNs and determinism before)?
cfallin edited PR Review Comment.
abrown submitted PR Review.
abrown created PR Review Comment:
I'm not opposed to using
Ieee32/Ieee64
here but I do want to sort out whether there are real issues that they avoid or not; if not, then I think Rust'sf32/f64
are a bit simpler and perhaps we should be using those other places, e.g., for CLIF parsing.
abrown submitted PR Review.
abrown created PR Review Comment:
Here is a summary of what @bjorn3 and I discussed on Zulip: because ARM machines might have default NaN mode set during compilation but not during runtime, the
f32
, if operated on (@bjorn3 thinks even possibly by moving to a register), could lose its signalling bit. This makes me lean toward switching to useIeee32
but I would still like to hear @sunfishcode's opinion.I'm still a bit mystified on why Rust core thinks this will not be an issue in their case: https://github.com/rust-lang/rust/commit/a2cdeb58f680b87b5bdb6a17cba857ac51307c8f#diff-14f327fd5e3b91eb2e9af0690596d156R284.
bjorn3 submitted PR Review.
bjorn3 created PR Review Comment:
I think what was thought to be a safety issue is sNaN causing a floating point trap as opposed to return sNaN or qNaN bits or even LLVM returning poison.
sunfishcode submitted PR Review.
sunfishcode created PR Review Comment:
I favor
Ieee32
/Ieee64
here too.It's my understanding that Rust as a language is still figuring out its strategy for NaN bits: https://github.com/rust-lang/unsafe-code-guidelines/issues/237 (to be sure, it's a hard problem). Until that's resolved, I'd prefer not to skate near the edge :-).
abrown updated PR #2251 from access-immediates
to main
:
@cfallin, here is what I came up with after we discussed this last week. This change:
- moves
DataValue
into cranelift-codegen so that I can use it as a value wrapper- gives
InstructionData
the ability to find immediate values in the format structures- reworks
LowerCtx::get_immediate
to grab the value from the instruction (and the DataFlowGraph for vector immediates)I felt like this approach provides the new backend a more abstract view of immediates instead of munging directly in the
InstructionData
but I didn't perform the refactor on the rest of the places the new backend grabs immediates because I wanted to get some feedback first.
abrown created PR Review Comment:
This is the only change (and similarly on lines 237-238) that might be a bit risky in this commit: these functions are used to store and load values for the trampoline into a compiled function and I could
repr(C)
bothIeee32
andIeee64
if there are doubts about the data layout.
abrown submitted PR Review.
abrown updated PR #2251 from access-immediates
to main
:
@cfallin, here is what I came up with after we discussed this last week. This change:
- moves
DataValue
into cranelift-codegen so that I can use it as a value wrapper- gives
InstructionData
the ability to find immediate values in the format structures- reworks
LowerCtx::get_immediate
to grab the value from the instruction (and the DataFlowGraph for vector immediates)I felt like this approach provides the new backend a more abstract view of immediates instead of munging directly in the
InstructionData
but I didn't perform the refactor on the rest of the places the new backend grabs immediates because I wanted to get some feedback first.
abrown submitted PR Review.
abrown created PR Review Comment:
I added a
repr(C)
toIeee32
andIeee64
in the latest version of this commit; if they truly aren't necessary we can remove them later.
abrown merged PR #2251.
Last updated: Dec 23 2024 at 13:07 UTC