-
Notifications
You must be signed in to change notification settings - Fork 11
Closed
Description
It is not permitted for the asm to write to any input register or memory location (unless that input is tied to an output). This is because the compiler will assume that you haven't mutated the input. And can therefore reuse the register with its value.
Additionally, you must add the option volatile. Otherwise the compiler is free to remove the piece of inline asm since you do not care about the output value!
Here is an example that I believe to be correct:
fn busy_loop_4_cycles(count: u16) {
let mut _count = count; // Quiet the linter with underscore.
unsafe {
llvm_asm!(r#"
1: sbiw $0,1
brne 1b
"#
:"=w" (_count) // output
:"0" (_count) // input
: // clobbers
: "volatile" // options
)
}
}
links:
Line 37 in 7925367
: "w" (0) |
https://llvm.org/docs/LangRef.html#input-constraints
Metadata
Metadata
Assignees
Labels
No labels