bebbo / gcc

Bebbo's gcc-6-branch for m68k-amigaos
GNU General Public License v2.0
33 stars 11 forks source link

Optimization opportunity #208

Closed mheyer32 closed 10 months ago

mheyer32 commented 10 months ago

Consider: http://franke.ms/cex/z/oYqroh

The compiler will do a lot of extra work, while I was expecting to see just to swap the first argument and move.w the second argument into the lower word.

bebbo commented 10 months ago

not worth the effort. please use some asm instead.

bebbo commented 10 months ago
#define MKWORD(hi,lo) \
    asm ("swap %0" : "=r"(hi) : "r"(hi)); \
    asm ("move.w %2,%0": "=r"(hi) : "r"(hi), "rm"(lo))
mheyer32 commented 10 months ago

Fair enough. I was just surprised that this seemingly simple operation turned into relatively many instructions.

bebbo commented 10 months ago

Fair enough. I was just surprised that this seemingly simple operation turned into relatively many instructions.

because the short's need an extension to int to apply shift and or.

mheyer32 commented 10 months ago

For completeness sake, after lots of trial and error, I have no settled on:

static inline int makeDWORD(short hi, short lo)
{
    int res;
    __asm __volatile ("swap %0 \n"
                      "move.w %2,%0"
                      : "=&r"(res)
                      : "0"(hi), "g"(lo)
                      : "cc");
    return res;
}

Feel free to critique, I'm really not well versed in GCC inline assembly