AVR: Bitpacked record inefficent evaluation
Original Reporter info from Mantis: Timm Thaler
-
Reporter name: Timm Thaler
Original Reporter info from Mantis: Timm Thaler
- Reporter name: Timm Thaler
Description:
Using boolean in a bitpacked record leads to inefficent evaluation and unneccesary code.
type
tflags = bitpacked record // Flags
bit0,bit1,bit2,bit3,bit4,bit5,bit6,bit7 : boolean);
end;
var
flags : tflags;
code
if flags.bit6 then...
compiles to
lds r18,(U_sDEFINE_ss_FLAGS)
lsr r18
lsr r18
lsr r18
lsr r18
lsr r18
lsr r18
sbrs r18,0
rjmp .Lj19
but could be
lds r18,(U_sDEFINE_ss_FLAGS)
sbrs r18,6
rjmp .Lj19
Also
if not flags.bit6 then begin
compiles to
lds r18,(U_sDEFINE_ss_FLAGS)
lsr r18
...
andi r18,1
cpi r18,0
brne .Lj19
but could be
lds r18,(U_sDEFINE_ss_FLAGS)
sbrc r18,6
rjmp .Lj19
As sbrs Rr,b and sbrc Rr,b are available in all AVR microcontrollers there should be no constraint in using them.
Additional information:
The multiple shift does not happen if bit7 or bit0 is used, only with bit1 to bit6.
Mantis conversion info:
- Mantis ID: 33417
- OS: AVR
- OS Build: AVR5
- Build: FPC 3.1.1-r38241 [2018/02/14]
- Platform: Embedded
- Version: 3.1.1
- Fixed in version: 3.1.1
- Fixed in revision: 38509 (#a6601602)