-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for const operands and options to global_asm! #84107
Conversation
Some changes occured to rustc_codegen_cranelift cc @bjorn3 |
This comment has been minimized.
This comment has been minimized.
☔ The latest upstream changes (presumably #84112) made this pull request unmergeable. Please resolve the merge conflicts. |
122c1a0
to
0d3ca4d
Compare
This comment has been minimized.
This comment has been minimized.
This is now ready for review. |
I do have this on my list and meant to get through this last weekend, but was busy with more pressing business throughout it, so didn't really have an opportunity to spend any time reviewing. |
There's quite a few changes, but a large part of it is making If you don't think that is appropriate then I can change |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Welp, that took way longer than I expected it would.
See comments inline. No major issues other than the one with the collector.
r=me once comments are acknowledged/resolved.
ty::IntTy::I128 => (value as i128).to_string(), | ||
ty::IntTy::Isize => unreachable!(), | ||
}, | ||
ty::Float(ty::FloatTy::F32) => f32::from_bits(value as u32).to_string(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it intended that this uses a decimal representation of the float as opposed to writing out a hex value representing the encoding of the float? I don't recall seeing any other way to represent floats in assembly than their hex encoding.
I'm worried mostly that encoding a float here could lead to double-rounding resembling issues – we had some of those in the past where the Rust
's formatting algorithm used to produce very slightly different results than those produced by C, but both still "correct". Encoding the bits representation of the float would make me much more comfortable with this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That said it seems preexisting… so 🤷
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm actually considering getting rid of float constants and only supporting integers. It would work better with typeck too.
}; | ||
let value = scalar.assert_bits(ty_and_layout.size); | ||
match ty_and_layout.ty.kind() { | ||
ty::Uint(_) => value.to_string(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, so I have questions about this. Many architectures have separate instructions that sign-extend or zero-extend the constant operands from, say, 12-bits to the register bit width. Do i recall correctly that otherwise the assembler implementations don't particularly care about whether the constant is represented as a wrapped signed integer or a unsigned integer, as far as it is in range of the maximum bit width for the instruction?
This is probably the correct implementation regardless, but it seems like it could result in some weird action at a distance behaviour.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Our job in rustc is to emit the given constant as a string. The actual interpretation of that string is up to the assembler and is not our problem.
The most sensible way of handling this is to format based on the original type of the value, just like format!
does.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem is exactly in how different pieces of software interpret the same decimal float string. There's very often a difference between different interpretations. Outputting the float as a hexadecimal bit representation avoids this issue entirely and the only party in control of what float ends up being encoded in the binary is Rust. Which sounds like an improvement to me.
global_asm!("{}", const 0); | ||
global_asm!("{}", const 0i32); | ||
global_asm!("{}", const 0f32); | ||
global_asm!("{}", const 0 as *mut u8); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Allowing pointers may be useful for e.g. embedded use-cases where people might want to refer to e.g. peripherals.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a separate sym
operand type for this which inserts a symbol name. It is not supported in global_asm!
yet but will be in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I meant something different. Like
const GPIOA: *const u32 = 0x8000_4200;
and then users trying to use that pointer as-is. Symbol isn't quite usable here because placing the symbol in the right place would require linker shenanigans people don't generally love all that much.
☔ The latest upstream changes (presumably #77246) made this pull request unmergeable. Please resolve the merge conflicts. |
@bors r+ rollup=never but also see the comments. I think those could still be something for a future improvement. |
📌 Commit 59479edc12a54054c6e3a00d4fb80b79fa257bb9 has been approved by |
⌛ Testing commit 59479edc12a54054c6e3a00d4fb80b79fa257bb9 with merge 4def5812b498a6b2c87604c9f3bd7868bb01018a... |
This comment has been minimized.
This comment has been minimized.
On x86, the default syntax is also switched to Intel to match asm!
@bors r=nagisa |
📌 Commit d9cf2ce has been approved by |
This comment has been minimized.
This comment has been minimized.
@bors r=nagisa |
📌 Commit a7ed6a5 has been approved by |
☀️ Test successful - checks-actions |
Performance triage indicates that this PR introduced a 1.4% regression when fully compiling I don't think any performance hit was expected. However, it also seems like this may be just noise. |
On x86, the default syntax is also switched to Intel to match asm!.
Currently
global_asm!
only supportsconst
operands and theatt_syntax
option. In the future,sym
operands will also be supported. However there is no plan to support any of the other operand types or options since they don't make sense in the context ofglobal_asm!
.r? @nagisa