Skip to content

Instantly share code, notes, and snippets.

@kohnakagawa
Created April 14, 2019 01:29
Show Gist options
  • Save kohnakagawa/0b6a6779aa313af91a1ed558343696aa to your computer and use it in GitHub Desktop.
Save kohnakagawa/0b6a6779aa313af91a1ed558343696aa to your computer and use it in GitHub Desktop.
Rustの最適化の強力さ
example::sum:
xor eax, eax
cmp edi, 2
jl .LBB0_2
lea eax, [rdi - 2]
lea ecx, [rdi - 3]
imul rcx, rax
shr rcx
lea eax, [rcx + 2*rdi]
add eax, -3
.LBB0_2:
ret
pub fn sum(n: i32) -> i32 {
(1..n).fold(0, |sum, item| sum + item)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment