Assembly x86-64 - movupd with -O3

Viewed 65

I'm doing an exercise about x86-64 assembly, so I generated assembly code with GCC, using -O3 option.

The original code written in C:

double dotprod(double *a, double *b, unsigned long long n)
{
  double d1 = 0.0;
  double d2 = 0.0;

  for (unsigned long long i = 0; i < n; i += 2) {
    d1 += a[i] * b[i];
    d2 += a[i + 1] * b[i + 1];
  }

  return (d1 + d2);
}

Part of assembly code:

.L4:
    movupd  (%rdi,%rax), %xmm3
    movupd  (%rsi,%rax), %xmm2
    movupd  16(%rdi,%rax), %xmm1
    movlpd  8(%rdi,%rax), %xmm1
    movhpd  16(%rdi,%rax), %xmm3
    movhpd  16(%rsi,%rax), %xmm2
    mulpd   %xmm3, %xmm2
    addsd   %xmm2, %xmm4
    unpckhpd    %xmm2, %xmm2
    addsd   %xmm2, %xmm4
    movupd  16(%rsi,%rax), %xmm2
    movlpd  8(%rsi,%rax), %xmm2
    addq    $32, %rax
    mulpd   %xmm2, %xmm1
    movapd  %xmm1, %xmm2
    unpckhpd    %xmm1, %xmm1
    addsd   %xmm0, %xmm2
    movapd  %xmm1, %xmm0
    addsd   %xmm2, %xmm0
    cmpq    %rdx, %rax
    jne .L4
    movq    %rcx, %rdx
    andq    $-2, %rdx
    leaq    (%rdx,%rdx), %rax
    cmpq    %rcx, %rdx
    je  .L5

I wonder what is the int we can read in some instructions like movupd 16(%rdi,%rax), %xmm1

0 Answers
Related