Created
April 14, 2019 01:29
-
-
Save kohnakagawa/0b6a6779aa313af91a1ed558343696aa to your computer and use it in GitHub Desktop.
Rustの最適化の強力さ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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