Skip to content

Commit

Permalink
inline-asm: Update for new style (#623)
Browse files Browse the repository at this point in the history
* inline-asm: Update for new style

rust-lang/rust#73364 implemented support for
providing multiple lines of assembly as separate arguments to `asm!`;
update the blog post to use that new syntax, so that people who find it
will use that style as an example.

* inline-asm: Outdent

* inline asm: Update play link
  • Loading branch information
joshtriplett authored Jun 22, 2020
1 parent a4e773c commit f46beea
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions posts/inside-rust/2020-06-08-new-inline-asm.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,16 @@ fn main() {
for value in 0..=1024u64 {
let popcnt;
unsafe {
asm!("
popcnt {popcnt}, {v}
2:
blsi rax, {v}
jz 1f
xor {v}, rax
tzcnt rax, rax
stosb
jmp 2b
1:
",
asm!(
"popcnt {popcnt}, {v}",
"2:",
"blsi rax, {v}",
"jz 1f",
"xor {v}, rax",
"tzcnt rax, rax",
"stosb",
"jmp 2b",
"1:",
v = inout(reg) value => _,
popcnt = out(reg) popcnt,
out("rax") _, // scratch
Expand All @@ -117,7 +116,7 @@ fn main() {
```

(You can [try this example on the
playground](https://play.rust-lang.org/?version=nightly&mode=release&edition=2018&gist=38874735e48aa20289f23f5a3cbeae0c).
playground](https://play.rust-lang.org/?version=nightly&mode=release&edition=2018&gist=894a407f0fe858559aa378edf6ec4801).
Note that this code serves to demonstrate inline assembly, not to demonstrate
an efficient implementation of any particular algorithm.)

Expand Down

0 comments on commit f46beea

Please sign in to comment.