Hi all,
I have been attempting to write some custom STM8 peephole optimiser
rules, but have run up against a perplexing issue. For what are
ostensibly the same operations in C code, I have seen
differently-formatted assembly code being emitted by SDCC, and I can't
figure out why.
An example:
In one piece of code from one project, I have the following:
typedef struct {
bool : 1;
bool can : 1;
bool : 1;
bool : 1;
bool erase_full : 1;
bool write_flash_eeprom: 1;
bool write_flash_block : 1;
bool checksum_ok : 1;
} status_t;
extern status_t global_0x8e; // Location is fixed, specified at link-time
void erase(void) {
if(global_0x8e.erase_full) {
/* ... */
}
}
Which yields the following assembly for the if-statement test:
ldw x, #_global_0x8e+0
ld a, (x)
swap a
and a, #0x01
jreq 00116$
Note the formatting of the second operand of "ldw".
In another piece of code from I created as a bare-bones test for my
custom peephole rules, I have:
typedef struct {
_Bool b0 : 1;
_Bool b1 : 1;
_Bool b2 : 1;
_Bool b3 : 1;
_Bool b4 : 1;
_Bool b5 : 1;
_Bool b6 : 1;
_Bool b7 : 1;
} bitfield_t;
static volatile bitfield_t blah;
void main(void) {
if(blah.b4) {
/* ... */
}
}
Which yields the following assembly:
ldw x, #(_blah + 0)
ld a, (x)
swap a
and a, #0x01
jreq 00121$
The formatting of the second operand to "ldw" is different! There is
additional spacing and parenthesis.
I can't track down or figure out what is making SDCC use different
formatting. Why is this occurring?
It means that I will have to handle both these cases with separate
peephole rules - one to match "ldw x, #(%1 + %3)", and one to match
"ldw x, #%1+%3", which is a whole lot of duplication for no good reason.
Regards,
Basil Hussain
_______________________________________________
Sdcc-user mailing list
Sdcc-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sdcc-user