*redundant calculations for simple "char = (short>>4)&0x04"
; play_music.c:50: length = (note >> 4) & 0xf;
mov r1,_cvu_play_music_note_131072_8
mov a,(_cvu_play_music_note_131072_8 + 1)
swap a
xch a,r1
swap a
anl a,#0x0f
xrl a,r1
xch a,r1
anl a,#0x0f
xch a,r1
xrl a,r1
xch a,r1
anl ar1,#0x0f
Ideally it should be managed on side of code generation.
Temporally we can patch particular cases by peephole rules
replace {
mov r%1,%2
mov a,(%2 + 1)
swap a
xch a,r%1
swap a
anl a,#0x0f
xrl a,r%1
xch a,r%1
anl a,#0x0f
xch a,r%1
xrl a,r%1
xch a,r%1
anl ar%1,#0x0f
mov a,r%1
} by {
; Peephole XXX5 (play_music.c) char = (short>>4)&0xf;
mov a,%2
swap a
anl a,#0x0f
}
replace {
mov r%1,%2
mov a,(%2 + 1)
clr c
rrc a
xch a,r%1
rrc a
xch a,r%1
clr c
rrc a
xch a,r%1
rrc a
xch a,r%1
mov a,#0x03
anl a,r%1
} by {
; Peephole XXX5 (play_music.c) char = (short>>2)&0x3;
mov a,%2
rr a
rr a
anl a,#0x03
}
you can get to the intended code:
by giving the compiler an (uint8_t) hint. Appending a compilable snippet.
Test code is rerefenced here https://github.com/roybaer/sdcc-wiki/wiki/Stm8-code-size
Hint is correct. At same time it is not so good idea to adjust existig test code to satisfy compiler.