Skip to content

Instantly share code, notes, and snippets.

@ChristopherBiscardi
Created December 5, 2023 02:04
Show Gist options
  • Save ChristopherBiscardi/210ae3adcfd682760b820735423413c4 to your computer and use it in GitHub Desktop.
Save ChristopherBiscardi/210ae3adcfd682760b820735423413c4 to your computer and use it in GitHub Desktop.
Assembly output of the detailed rust files using godbolt rust 1.73
# Compilation provided by Compiler Explorer at https://godbolt.org/
example::no_pow:
push rax
mov eax, edi
sub eax, 1
mov dword ptr [rsp + 4], eax
cmp edi, 1
setb al
test al, 1
jne .LBB0_2
mov eax, dword ptr [rsp + 4]
cmp eax, 32
setb al
test al, 1
jne .LBB0_3
jmp .LBB0_4
.LBB0_2:
lea rdi, [rip + str.0]
lea rdx, [rip + .L__unnamed_1]
mov rax, qword ptr [rip + core::panicking::panic@GOTPCREL]
mov esi, 33
call rax
ud2
.LBB0_3:
mov ecx, dword ptr [rsp + 4]
and ecx, 31
mov eax, 2
shl eax, cl
pop rcx
ret
.LBB0_4:
lea rdi, [rip + str.1]
lea rdx, [rip + .L__unnamed_2]
mov rax, qword ptr [rip + core::panicking::panic@GOTPCREL]
mov esi, 35
call rax
ud2
.L__unnamed_3:
.ascii "/app/example.rs"
.L__unnamed_1:
.quad .L__unnamed_3
.asciz "\017\000\000\000\000\000\000\000\002\000\000\000\n\000\000"
str.0:
.ascii "attempt to subtract with overflow"
.L__unnamed_2:
.quad .L__unnamed_3
.asciz "\017\000\000\000\000\000\000\000\002\000\000\000\005\000\000"
str.1:
.ascii "attempt to shift left with overflow"
pub fn no_pow(x: u32) -> u32 {
2 << (x - 1)
}
# Compilation provided by Compiler Explorer at https://godbolt.org/
example::pow:
push rax
mov esi, edi
mov edi, 2
call core::num::<impl u32>::pow
pop rcx
ret
.L__unnamed_2:
.ascii "/rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/num/mod.rs"
.L__unnamed_1:
.quad .L__unnamed_2
.asciz "K\000\000\000\000\000\000\000w\004\000\000\005\000\000"
str.0:
.ascii "attempt to multiply with overflow"
pub fn pow(x: u32) -> u32 {
2u32.pow(x)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment