Skip to content

Instantly share code, notes, and snippets.

@64kramsystem
Created September 17, 2021 20:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 64kramsystem/4d4c211f9912c7756298da2dbcc2d971 to your computer and use it in GitHub Desktop.
Save 64kramsystem/4d4c211f9912c7756298da2dbcc2d971 to your computer and use it in GitHub Desktop.
~/code/benchmarking-lesson(master)$ for fx in mq_1 mq_2 mq_3 c_1 c_2 c_3; do echo; cargo asm --rust playground::$fx; done
pub fn mq_1() -> f32 {
push rax
T::gen_range(low, high) (/home/saverio/.cargo/registry/src/github.com-1ecc6299db9ec823/quad-rand-0.2.1/src/lib.rs:104)
xor edi, edi
mov esi, 2
call qword, ptr, [rip, +, _ZN46_$LT$u32$u20$as$u20$quad_rand..RandomRange$GT$9gen_range17h968310cefd11fee0E@GOTPCREL]
xor ecx, ecx
test eax, eax
sete cl
lea rax, [rip, +, .LCPI0_0]
if gen_random_mq_01() > 0 {
movss xmm0, dword, ptr, [rax, +, 4*rcx]
}
pop rax
ret
pub fn mq_2() -> f32 {
push rax
T::gen_range(low, high) (/home/saverio/.cargo/registry/src/github.com-1ecc6299db9ec823/quad-rand-0.2.1/src/lib.rs:104)
xor edi, edi
mov esi, 2
call qword, ptr, [rip, +, _ZN46_$LT$u32$u20$as$u20$quad_rand..RandomRange$GT$9gen_range17h968310cefd11fee0E@GOTPCREL]
(gen_random_mq_01() as f32 - 0.5) * 2.
mov eax, eax
cvtsi2ss xmm0, rax
(gen_random_mq_01() as f32 - 0.5) * 2.
addss xmm0, dword, ptr, [rip, +, .LCPI1_0]
addss xmm0, xmm0
}
pop rax
ret
file /rustc/c3c0f80d6081092faff801542dd82f0e2420152b/library/core/src/num/f32.rs does not exist!
pub fn mq_3() -> f32 {
push rax
T::gen_range(low, high) (/home/saverio/.cargo/registry/src/github.com-1ecc6299db9ec823/quad-rand-0.2.1/src/lib.rs:104)
xor edi, edi
mov esi, -1
call qword, ptr, [rip, +, _ZN46_$LT$u32$u20$as$u20$quad_rand..RandomRange$GT$9gen_range17h968310cefd11fee0E@GOTPCREL]
f32::from_bits((gen_random_mq_full() & F32_SIGN_BITMASK) | F32_EXP_BITMASK)
and eax, -2147483648
or eax, 1065353216
movd xmm0, eax
}
pop rax
ret
pub fn c_1() -> f32 {
push rax
unsafe { rand() % 2 }
call qword, ptr, [rip, +, rand@GOTPCREL]
xor ecx, ecx
test al, 1
sete cl
lea rax, [rip, +, .LCPI3_0]
if gen_random_c_01() > 0 {
movss xmm0, dword, ptr, [rax, +, 4*rcx]
}
pop rax
ret
pub fn c_2() -> f32 {
push rax
unsafe { rand() % 2 }
call qword, ptr, [rip, +, rand@GOTPCREL]
and eax, 1
(gen_random_c_01() as f32 - 0.5) * 2.
cvtsi2ss xmm0, eax
(gen_random_c_01() as f32 - 0.5) * 2.
addss xmm0, dword, ptr, [rip, +, .LCPI4_0]
addss xmm0, xmm0
}
pop rax
ret
file /rustc/c3c0f80d6081092faff801542dd82f0e2420152b/library/core/src/num/f32.rs does not exist!
pub fn c_3() -> f32 {
push rax
unsafe { rand() << 1 }
call qword, ptr, [rip, +, rand@GOTPCREL]
f32::from_bits((gen_random_c_full() & F32_SIGN_BITMASK) | F32_EXP_BITMASK)
and eax, -1073741824
add eax, eax
add eax, 1065353216
movd xmm0, eax
}
pop rax
ret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment