Previous | Next --- Slide 25 of 65
Back to Lecture Thumbnails
alex

Unfortunately, merely the use of these %xmmN registers in a compiled binary is not sufficient to show that a program is actually performing vector arithmetic. The x86-64 calling convention uses the %xmm0-3 registers when passing floating point numbers and gcc will use them for simple floating point arithmetic. For example, the following code:

double foo(double x) {
    return x + 0.0;
}

produces the following assembly:

00000000004004b4 <foo>:
4004b4: 55                    push   %rbp
4004b5: 48 89 e5              mov    %rsp,%rbp
4004b8: f2 0f 11 45 f8        movsd  %xmm0,-0x8(%rbp)
4004bd: f2 0f 10 4d f8        movsd  -0x8(%rbp),%xmm1
4004c2: 66 0f 57 c0           xorpd  %xmm0,%xmm0
4004c6: f2 0f 58 c1           addsd  %xmm1,%xmm0
4004ca: 5d                    pop    %rbp
4004cb: c3                    retq 

Note how even though the %xmmN registers are used, the math instructions generated only operate on one element of the registers. (See addsd above.)