Page 1 of 1

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

Posted: Fri Aug 23, 2024 6:39 pm
by Bryght-Richard
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.

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

Posted: Sat Aug 24, 2024 6:35 am
by ccrause
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.