Skip to content

Instantly share code, notes, and snippets.

@sugar700
Created June 4, 2018 06:07
Show Gist options
  • Save sugar700/d970facb89c5e76add50698da44d8ec8 to your computer and use it in GitHub Desktop.
Save sugar700/d970facb89c5e76add50698da44d8ec8 to your computer and use it in GitHub Desktop.
struct X {
int x[100];
};
X hi() {
return {0};
}
hi():
mov rdx, rdi
mov QWORD PTR [rdi], 0
lea rdi, [rdi+8]
xor eax, eax
mov QWORD PTR [rdi+384], 0
mov rcx, rdx
and rdi, -8
sub rcx, rdi
add ecx, 400
shr ecx, 3
rep stosq
mov rax, rdx
ret
pub fn hi() -> [i32; 100] {
[0; 100]
}
example::hi:
push rbx
mov rbx, rdi
xor esi, esi
mov edx, 400
call memset@PLT
mov rax, rbx
pop rbx
ret
@sssilver
Copy link

sssilver commented Jun 4, 2018

C++ strictly follows the calling convention when returning huge objects
not the case for Rust
where the function is transformed into something likevoid hi(int *p);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment