Skip to content
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

Tracking Issue for asm_const #93332

Closed
Tracked by #483 ...
Amanieu opened this issue Jan 26, 2022 · 21 comments
Closed
Tracked by #483 ...

Tracking Issue for asm_const #93332

Amanieu opened this issue Jan 26, 2022 · 21 comments
Labels
A-inline-assembly Area: Inline assembly (`asm!(…)`) B-unstable Blocker: Implemented in the nightly compiler and unstable. C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. F-asm `#![feature(asm)]` (not `llvm_asm`) finished-final-comment-period The final comment period is finished for this PR / Issue. T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@Amanieu
Copy link
Member

Amanieu commented Jan 26, 2022

The feature gate for the issue is #![feature(asm_const)].

Summary

This feature adds a const <expr> operand type to asm! and global_asm!.

  • <expr> must be an integer constant expression.
  • The value of the expression is formatted as a string and substituted directly into the asm template string.

Status

Blocked on the stabilization of inline consts (#76001).

@Amanieu Amanieu added A-inline-assembly Area: Inline assembly (`asm!(…)`) B-unstable Blocker: Implemented in the nightly compiler and unstable. C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. F-asm `#![feature(asm)]` (not `llvm_asm`) labels Jan 26, 2022
@bstrie
Copy link
Contributor

bstrie commented Jan 28, 2022

Is it possible that this may not actually be blocked on inline_const? AIUI, the concern was that stabilizing asm_const would expose the semantics of inline_const to stable, so any change to the semantics of the yet-unstable inline_const would potentially break stable users of asm_const. But AFAICT there are no more foreseen semantic changes coming to inline_const, and the only remaining question is a syntactic one, specifically with regard to how macros would consume const {} blocks, which seems irrelevant to asm! which is providing its own syntax over inline_const anyway. Of course, it's worth asking to determine whether or not it's correct that the semantics of inline_const have truly solidified.

nooop3 added a commit to LearningOS/lab0-1-run-os2-nooop3 that referenced this issue Jul 10, 2022
nooop3 added a commit to LearningOS/lab0-1-run-os2-nooop3 that referenced this issue Jul 16, 2022
retrage added a commit to retrage/rust-hypervisor-firmware that referenced this issue Oct 16, 2022
This commit adds initial paging support for aarch64. This implementation
creates identity mapping translation tables for Cloud Hypervisor. The
most of paging implementation is based on [1]. It also introduces use of
`asm_const` [2] to parameterize FDT base address and stack base address.

[1]
https://github.com/rust-embedded/rust-raspberrypi-OS-tutorials/tree/master/10_virtual_mem_part1_identity_mapping
[2] rust-lang/rust#93332

Signed-off-by: Akira Moroo <[email protected]>
retrage added a commit to retrage/rust-hypervisor-firmware that referenced this issue Oct 16, 2022
This commit adds initial paging support for aarch64. This implementation
creates identity mapping translation tables for Cloud Hypervisor. The
most of paging implementation is based on [1]. It also introduces use of
`asm_const` [2] to parameterize FDT base address and stack base address.

[1]
https://github.com/rust-embedded/rust-raspberrypi-OS-tutorials/tree/master/10_virtual_mem_part1_identity_mapping
[2] rust-lang/rust#93332

Signed-off-by: Akira Moroo <[email protected]>
retrage added a commit to retrage/rust-hypervisor-firmware that referenced this issue Oct 23, 2022
This commit adds initial paging support for aarch64. This implementation
creates identity mapping translation tables for Cloud Hypervisor. The
most of paging implementation is based on [1]. It also introduces use of
`asm_const` [2] to parameterize FDT base address and stack base address.

[1]
https://github.com/rust-embedded/rust-raspberrypi-OS-tutorials/tree/master/10_virtual_mem_part1_identity_mapping
[2] rust-lang/rust#93332

Signed-off-by: Akira Moroo <[email protected]>
retrage added a commit to retrage/rust-hypervisor-firmware that referenced this issue Oct 23, 2022
This commit adds initial paging support for aarch64. This implementation
creates identity mapping translation tables for Cloud Hypervisor. The
most of paging implementation is based on [1]. It also introduces use of
`asm_const` [2] to parameterize FDT base address and stack base address.

[1]
https://github.com/rust-embedded/rust-raspberrypi-OS-tutorials/tree/master/10_virtual_mem_part1_identity_mapping
[2] rust-lang/rust#93332

Signed-off-by: Akira Moroo <[email protected]>
retrage added a commit to retrage/rust-hypervisor-firmware that referenced this issue Oct 23, 2022
This commit adds initial paging support for aarch64. This implementation
creates identity mapping translation tables for Cloud Hypervisor. The
most of paging implementation is based on [1]. It also introduces use of
`asm_const` [2] to parameterize FDT base address and stack base address.

[1]
https://github.com/rust-embedded/rust-raspberrypi-OS-tutorials/tree/master/10_virtual_mem_part1_identity_mapping
[2] rust-lang/rust#93332

Signed-off-by: Akira Moroo <[email protected]>
retrage added a commit to retrage/rust-hypervisor-firmware that referenced this issue Nov 3, 2022
This commit adds initial paging support for aarch64. This implementation
creates identity mapping translation tables for Cloud Hypervisor. The
most of paging implementation is based on [1]. It also introduces use of
`asm_const` [2] to parameterize FDT base address and stack base address.

[1]
https://github.com/rust-embedded/rust-raspberrypi-OS-tutorials/tree/master/10_virtual_mem_part1_identity_mapping
[2] rust-lang/rust#93332

Signed-off-by: Akira Moroo <[email protected]>
@tiagomanczak
Copy link

Any progress on this issue? We are working in a project were it is necessary, and the stabilization is important for future use in productive code. Any forms we can contribute to the stabilization of asm_const?

@nbdd0121
Copy link
Contributor

nbdd0121 commented May 10, 2023

asm_const is blocked on stabilisation of inline_const because it shares a lot of the same issue (e.g. post-mono errors)

@asquared31415
Copy link
Contributor

#121099 is probably a blocker, a trivial to encounter ICE

@tgross35
Copy link
Contributor

I think this should be unblocked since inline_const just merged #104087. Could somebody update the top post with an example? I don't think we have use of this documented anywhere.

@luojia65
Copy link
Contributor

I suggest we can push forward on stabilization, since inline_const has been stabilized a short period of time ago. Feature asm_const is useful on bare-metal development like system, kernel development, bootloader, firmware and embedded Rust etc.

@joshtriplett
Copy link
Member

joshtriplett commented May 1, 2024

👍 for pushing forwards with this. Could we get a brief stabilization report on the current state of this and whether there's any other blocker to stabilization? (Please tag this I-lang-nominated when that stabilization report is available.) I'm happy to start an FCP as soon as that happens.

@rfcbot rfcbot added disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. and removed proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. labels May 15, 2024
@rfcbot
Copy link

rfcbot commented May 15, 2024

🔔 This is now entering its final comment period, as per the review above. 🔔

@tmandry
Copy link
Member

tmandry commented May 15, 2024

We discussed this in today's lang meeting and I wanted to document the reasons for allowing const without braces here:

  • The expression always goes to the next comma; there's no more complex expressions where you would want to have, e.g. const { FOO / 2 } - bar.
  • It's consistent with other non-bracy things like inout.

An example:

    asm!(
        "mov {tmp}, {x}",
        "shl {tmp}, {one}",
        "shl {x}, {two}",
        "add {x}, {tmp}",
        x = inout(reg) x,
        tmp = out(reg) _,
        one = const 1,
        two = const 1 + 1,
        thing = in(reg) 2 * f(), // already valid. 
    );

Allowing arbitrary string substitution (including, e.g., in the middle of a label like jmp label_{my_const}) is interesting, but feels consistent since the syntax is shared by format strings, and seems like a natural extension of the substitution we already do for asm!.

@rfcbot reviewed

@RalfJung
Copy link
Member

RalfJung commented May 16, 2024 via email

@RalfJung
Copy link
Member

Looks like yes these are normal consts:

}
InlineAsmOperand::Const { value }
| InlineAsmOperand::SymFn { value } => {
self.visit_constant(value, location);
}
InlineAsmOperand::Out { place: None, .. }
| InlineAsmOperand::SymStatic { def_id: _ }

@tgross35
Copy link
Contributor

Is there any reason this couldn't eventually be extended to take strings rather than just integers? This would be nice for creating named functions.

const FN_NAME: &str = "foo";
const FN_IDX: u32 = 10;

// works
core::arch::global_asm!(
    ".global lab_{label}"
    "lab_{label}:",
    "ret",
    label = const FN_IDX
);

// does not work
core::arch::global_asm!("
    ".global lab_{label}"
    "lab_{label}:",
    "ret",
    label = const FN_NAME
);

@nbdd0121
Copy link
Contributor

nbdd0121 commented May 20, 2024

Good point. If we want to reserve the ability to do that in the future then we need to tweak type inference a bit to stop constraining const operand to integers,

@rfcbot rfcbot added finished-final-comment-period The final comment period is finished for this PR / Issue. and removed final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. labels May 25, 2024
@rfcbot
Copy link

rfcbot commented May 25, 2024

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.

This will be merged soon.

@rfcbot rfcbot added the to-announce Announce this issue on triage meeting label May 25, 2024
@Lokathor
Copy link
Contributor

@nbdd0121 is that a change that would need to happen now before stabilization, or would it be part of a later update allowing const str support?

@Amanieu
Copy link
Member Author

Amanieu commented May 25, 2024

I have a draft PR up (#125558) but I'm hitting the same ICE as #96304 but with const operands.

@apiraino apiraino removed the to-announce Announce this issue on triage meeting label Jun 7, 2024
jieyouxu added a commit to jieyouxu/rust that referenced this issue Aug 14, 2024
…Amanieu

Stabilize `asm_const`

tracking issue: rust-lang#93332

reference PR: rust-lang/reference#1556

this will probably require some CI wrangling (and a rebase), so let's get that over with even though the final required PR is not merged yet.

r? `@ghost`
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Aug 14, 2024
Rollup merge of rust-lang#128570 - folkertdev:stabilize-asm-const, r=Amanieu

Stabilize `asm_const`

tracking issue: rust-lang#93332

reference PR: rust-lang/reference#1556

this will probably require some CI wrangling (and a rebase), so let's get that over with even though the final required PR is not merged yet.

r? `@ghost`
@ehuss
Copy link
Contributor

ehuss commented Aug 14, 2024

@Amanieu Can this be closed now?

@Amanieu Amanieu closed this as completed Aug 16, 2024
antoyo pushed a commit to rust-lang/rustc_codegen_gcc that referenced this issue Oct 9, 2024
Stabilize `asm_const`

tracking issue: rust-lang/rust#93332

reference PR: rust-lang/reference#1556

this will probably require some CI wrangling (and a rebase), so let's get that over with even though the final required PR is not merged yet.

r? `@ghost`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-inline-assembly Area: Inline assembly (`asm!(…)`) B-unstable Blocker: Implemented in the nightly compiler and unstable. C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. F-asm `#![feature(asm)]` (not `llvm_asm`) finished-final-comment-period The final comment period is finished for this PR / Issue. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests