Skip to content

Instantly share code, notes, and snippets.

@LucianoPAlmeida
Created February 5, 2023 14:00
Show Gist options
  • Save LucianoPAlmeida/90f3fe51ec3ee10946b06c06a4c01493 to your computer and use it in GitHub Desktop.
Save LucianoPAlmeida/90f3fe51ec3ee10946b06c06a4c01493 to your computer and use it in GitHub Desktop.
sumBy(int*, int): # @sumBy(int*, int)
movd xmm0, esi
pshufd xmm1, xmm0, 0 # xmm1 = xmm0[0,0,0,0]
movdqu xmm2, xmmword ptr [rdi]
movdqu xmm3, xmmword ptr [rdi + 16]
paddd xmm2, xmm1
movdqu xmmword ptr [rdi], xmm2
paddd xmm3, xmm1
movdqu xmmword ptr [rdi + 16], xmm3
movq xmm1, qword ptr [rdi + 32] # xmm1 = mem[0],zero
pshufd xmm0, xmm0, 80 # xmm0 = xmm0[0,0,1,1]
paddd xmm0, xmm1
movq qword ptr [rdi + 32], xmm0
ret
sumByRef(int*, int const&): # @sumByRef(int*, int const&)
mov eax, dword ptr [rsi]
add dword ptr [rdi], eax
mov eax, dword ptr [rsi]
add dword ptr [rdi + 4], eax
mov eax, dword ptr [rsi]
add dword ptr [rdi + 8], eax
mov eax, dword ptr [rsi]
add dword ptr [rdi + 12], eax
mov eax, dword ptr [rsi]
add dword ptr [rdi + 16], eax
mov eax, dword ptr [rsi]
add dword ptr [rdi + 20], eax
mov eax, dword ptr [rsi]
add dword ptr [rdi + 24], eax
mov eax, dword ptr [rsi]
add dword ptr [rdi + 28], eax
mov eax, dword ptr [rsi]
add dword ptr [rdi + 32], eax
mov eax, dword ptr [rsi]
add dword ptr [rdi + 36], eax
ret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment