xtensa calling convention: arguments pre-extended, post-extended, or both?

Bryght-Richard
Posts: 43
Joined: Thu Feb 22, 2024 3:59 pm

xtensa calling convention: arguments pre-extended, post-extended, or both?

Postby Bryght-Richard » Fri Aug 23, 2024 6:39 pm

More notes here: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116467

Code: Select all

    #include <stdint.h>

    __attribute__ ((noinline)) uint32_t callee(uint32_t x, uint16_t y){
        return x + y;
    }

    __attribute__ ((noinline)) uint32_t caller(uint32_t x, uint32_t y){
        return callee(x, y);
    }
In the above code, both caller() and callee() will zero-extend the `y` parameter. On many other 32-bit systems, only one of the two functions would need to zero-extend `y` (with `extui` instruction). I looked through the calling convention information but haven't found a definitive source for this for xtensa. If parameters only need zero-extended once, it would be good to update GCC to take advantage of this.

ccrause
Posts: 15
Joined: Wed Feb 27, 2019 7:42 am

Re: xtensa calling convention: arguments pre-extended, post-extended, or both?

Postby ccrause » Sat Aug 24, 2024 6:35 am

In the ISA summary for LX architectures, there is a section (10.1.4 Argument passing) that states:
All arguments consist of an integral number of 4-byte words. Thus, the minimum argument size is one word. Integer values smaller than a word (that is, char and short) are stored in the least significant portion of the argument word, with the upper bits set to zero for unsigned values or sign-extended for signed values.
Given the above, my interpretation is that the argument to be passed must be extended. So a variable passed to a function should be extended before calling the function, while a return value should be extended inside the function, before returning to the caller. Thus no further extension should be necessary when such a parameter is received.

Who is online

Users browsing this forum: Baidu [Spider], Google [Bot] and 264 guests