(This is a followup from "Getting GCC to optimize hand assembly")
I've been trying to get GCC (3.3.6-m68hc1x-20060122) to emit bset
and bclr
assembly instructions using indexed addressing, but no set of constraints I use seems to work.
The asm
:
#define bset(base, offset, mask) { \
volatile unsigned char *__base = base; \
const unsigned char __offset = offset; \
const char __mask = mask; \
asm volatile ("bset %0 %1" : "=o" (__base[__offset]) : "X" (__mask),
"x" (__base)); }
The C:
inline void spi_init()
{
bset(_io_ports, M6811_DDRD, 0x38);
bset(_io_ports, M6811_PORTD, 0x20);
bset(_io_ports, M6811_SPCR, (M6811_SPE | M6811_DWOM | M6811_MSTR));
}
The assembly code result:
spi_init:
ldx #_io_ports
; Begin inline assembler code
#APP
bset _io_ports+9 #56
bset _io_ports+8 #32
bset _io_ports+40 #112
; End of inline assembler code
#NO_APP
rts
Now this is really, really close. But unfortunately it's completely invalid. It must read as follows:
spi_init:
ldx #_io_ports
; Begin inline assembler code
#APP
bset 9,x #56
bset 8,x #32
bset 40,x #112
; End of inline assembler code
#NO_APP
rts
What constraints must I use in order to direct GCC to emit that assembly code?
GCC 3.3.6 extended assembly documentation
GCC 3.3.6 constraint documentation