NO

Author Topic: Optimizations  (Read 213 times)

Offline HellOfMice

  • Member
  • *
  • Posts: 228
  • Never be pleased, always improve
Optimizations
« on: December 20, 2024, 07:52:11 PM »
Here are some routnones I found in Agner Frog documentation


Quote
                     xorpd      xmm0,xmm0
                     shufpd      xmm0,xmm0,0
                     movdqu      [rsp + 32],xmm0
                     movdqa      OWORD ptr [rsp],xmm0


; Example 9.16, Calculate absolute value of eax
cdq ; Copy sign bit of eax to all bits of edx
xor eax, edx ; Invert all bits if negative
sub eax, edx ; Add 1 if negative


The following example finds the minimum of two unsigned numbers: if (b > a) b = a;
; Example 9.17a, Find minimum of eax and ebx (unsigned):
sub eax, ebx ; = a-b
sbb edx, edx ; = (b > a) ? 0xFFFFFFFF : 0
and edx, eax ; = (b > a) ? a-b : 0
add ebx, edx ; Result is in ebx


The next example chooses between two numbers: if (a < 0) d = b; else d = c;
; Example 9.18a, Choose between two numbers
test eax, eax
mov edx, ecx
cmovs edx, ebx ; = (a < 0) ? b : c
--------------------------------
Kenavo