Skip to content

Commit 911c306

Browse files
authored
Merge pull request #1548 from PeterWrighten/master
unsafe::asm.md: add some explicit declarations
2 parents 291e2bc + 7777275 commit 911c306

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/unsafe/asm.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ To achieve this Rust provides a `lateout` specifier. This can be used on any out
132132
written only after all inputs have been consumed.
133133
There is also a `inlateout` variant of this specifier.
134134

135-
Here is an example where `inlateout` *cannot* be used:
135+
Here is an example where `inlateout` *cannot* be used in `release` mode or other optimized cases:
136136

137137
```rust
138138
use std::arch::asm;
@@ -151,8 +151,9 @@ unsafe {
151151
}
152152
assert_eq!(a, 12);
153153
```
154+
The above could work well in unoptimized cases (`Debug` mode), but if you want optimized performance (`release` mode or other optimized cases), it could not work.
154155

155-
Here the compiler is free to allocate the same register for inputs `b` and `c` since it knows they have the same value. However it must allocate a separate register for `a` since it uses `inout` and not `inlateout`. If `inlateout` was used, then `a` and `c` could be allocated to the same register, in which case the first instruction to overwrite the value of `c` and cause the assembly code to produce the wrong result.
156+
That is because in optimized cases, the compiler is free to allocate the same register for inputs `b` and `c` since it knows they have the same value. However it must allocate a separate register for `a` since it uses `inout` and not `inlateout`. If `inlateout` was used, then `a` and `c` could be allocated to the same register, in which case the first instruction to overwrite the value of `c` and cause the assembly code to produce the wrong result.
156157

157158
However the following example can use `inlateout` since the output is only modified after all input registers have been read:
158159

0 commit comments

Comments
 (0)