3.75 Complex

ISO C99 includes extensions to support complex numbers. Any floating-point type can be modified with the keyword complex. Here are some sample functions that work with complex data and that call some of the associated library functions:

#include <complex.h>

double c_imag(double complex x) {
    return cimag(x);
}

double c_real(double complex x) {
    return creal(x);
}

double complex c_sub(double complex x, double complex y) {
    return x - y;
}

When compiled, GCC generates the following assembly code for these functions:

c_imag:
    movapd    %xmm1, %xmm0
    ret
c_real:
    rep; ret
c_sub:
    subsd    %xmm2, %xmm0
    subsd    %xmm3, %xmm1
    ret

Based on these examples, determine the following:

A. How are complex arguments passed to a function?

param #

real part

img part

1

%xmm0

%xmm1

2

%xmm2

%xmm3

3

%xmm4

%xmm5

B. How are complex values returned from a function?

return %xmm0 as real part, %xmm1 as img part.

Last updated