Challenging conventions with composite date types

I understand the calling conventions for passing 32bit and 64bit integers (and pointers), floats and doubles for 64bit code for Micrsoft and System V AMD64 ABI. But it is not clear to me what conditional conventions exist for composite data types.

To be clearer, what are the conventions for passing structures, classes, and unions by value in externally linked functions (i.e. not static inline

functions)? I am especially interested in simple structures like

typedef struct doublefloat { float hi; float lo; } doublefloat;
typedef struct doubledouble { double hi; double lo; } doubledouble;
typedef struct int128 { int64_t hi; int64_t lo; } int128; 

doublefloat foof(float a, float b);    
doubledouble food(double a, double b);
float foo3(doubledouble a, doubledouble b);    
int128 fooi(int64_t a, int64_t b);

      

This is what I observed in GCC (with -O3)

  • foof

    returns hi

    and lo

    packed into the first 64 bits XMM0

    .
  • food

    returns hi

    both lo

    to XMM0

    and XMM1

    .
  • foo3

    passes hi

    and lo

    out a

    and b

    in XMM0

    , XMM1

    , XMM2

    and XMM3

    .
  • fooi

    returns hi

    and lo

    in rda and rdx

Agner Fog describes the details (which are consistent with observations) for each compiler at http://www.agner.org/optimize/calling_conventions.pdf

See Table 6. Methods for passing structure, class and union objects and Table 7. Return methods for structure, class and union objects.

For 64-bit code, its tables are split on Windows and Linux / BSD / Mac, not compiler, so this means that there is some standard for composite data types. Whether this is correct or whether it is passing and returning a composite data type potentially defined by each compiler or by each compiler version (i.e., may change with the next version).

Note that I understand that in practice, in many of these cases static inline

, it would probably be best to use anyway. Also note that although C has no classes, I'm still curious about how structures and unions are passed by value in C, not just C ++, so I included the C tag.

+3


source to share


1 answer


Some standards exist. For example, the SystemV AMD64 ABI document details parameter passing for aggregates (starting on page 17). I will not copy the relevant portion of the text here, as there are several pages.



Not all platforms are likely to be well documented.

+2


source







All Articles