- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
pub struct Vec { x: u32, y: u32, z: u32, }
pub extern "C" fn sum_c(a: &Vec, b: &Vec) -> Vec {
return Vec {x: a.x + b.x, y: a.y + b.y, z: a.z + b.z };
}
pub fn sum_rust(a: &Vec, b: &Vec) -> Vec {
return Vec {x: a.x + b.x, y: a.y + b.y, z: a.z + b.z };
}
Выхлоп:
example::sum_c:
mov eax, dword ptr [rsi]
add eax, dword ptr [rdi]
mov ecx, dword ptr [rsi + 4]
add ecx, dword ptr [rdi + 4]
mov edx, dword ptr [rsi + 8]
add edx, dword ptr [rdi + 8]
shl rcx, 32
or rax, rcx
ret
example::sum_rust:
mov ecx, dword ptr [rdx]
mov r8d, dword ptr [rdx + 4]
add ecx, dword ptr [rsi]
add r8d, dword ptr [rsi + 4]
mov edx, dword ptr [rdx + 8]
add edx, dword ptr [rsi + 8]
mov rax, rdi
mov dword ptr [rdi], ecx
mov dword ptr [rdi + 4], r8d
mov dword ptr [rdi + 8], edx
ret