Why is there a calling convention for arrays?

I am reading the System V Application Binary Application Interface , and there is one part that I cannot understand about.

First, the document states that

No attempt was made to specify ABI for languages โ€‹โ€‹other than C

(p. 10).

Later, on page 20, arrays are classified as MEMORY, POINTER, etc .:

The classification of aggregates (structures and arrays) and types of trade unions as follows:
...

Classification is then used to determine the calling conventions โ€” how values โ€‹โ€‹and boundaries on them are passed and returned from functions. If I read the algorithm correctly, the array can be classified as INTEGER, MEMORY or SSE.

But in C, arrays are always passed and returned as pointers. So, why is it useful to classify arrays and in what situation does the class of the array matter?

+5
source share
1 answer

I realized: if an array is part of a structure or union, it can be passed to a register.

This code is C

#include <stdint.h> struct somebytes { uint8_t bytes[8]; }; uint8_t plus(struct somebytes p) { return p.bytes[3]+p.bytes[5]; } 

translates to this assembly:

 mov %rdi,%rax shr $0x28,%rdi shr $0x18,%rax add %edi,%eax retq 
+1
source

Source: https://habr.com/ru/post/1263332/


All Articles