0

I am a student learning assemble language.
I am studying a sample that get abs(), but I am not clear source.
Could you explain about 'vandpd xmm1, xmm0, xmmword ptr[AbsMask]', please?
Main question is why AbsMask is a array and how does it to get abs()?
Thank you.


.MODEL flat, c

.CONST
    AbsMask qword 7fffffffffffffffh, 7fffffffffffffffh

.CODE
AVX_fp_Arith PROC
    push ebp
    mov ebp, esp
        
    vmovsd xmm0, real8 ptr[ebp+8]   ; xmm0 = -15
    vandpd xmm1, xmm0, xmmword ptr[AbsMask] ; xmm0 = fabs(b) = 15

    pop ebp
    ret
AVX_fp_Arith ENDP

END
  • https://en.wikipedia.org/wiki/Double-precision_floating-point_format – hobbs Feb 21 '23 at 01:38
  • 1
    `vandpd` has a 16-byte memory source operand. Instead of using another `vmovsd` to load an 8-byte mask (or `pcmpeqd xmm0,xmm0` / `psrlq xmm0,1` to generate it), they chose to save an instruction. (Ironic that they saved that but still wasted 3 setting up EBP instead of using `[esp+4]`.) Since they're using a 16-byte memory operand anyway, might as well use a constant that also works for doing 2 `double`s in parallel, for a SIMD version of this. – Peter Cordes Feb 21 '23 at 01:42

0 Answers0