Hello everyone!
I have just checked the ASM output for the C source below and found out that in some cases where a type conversion from 16- to 8-bit integer or vice versa is performed, the compiler produces a redundant MOV.B instruction. This only seems to be the case when SWPB instruction is used on a register (not a memory location), but not always...
uint8_t shift_right_toU8(uint16_t val)
{
return val >> 8U;
}
uint16_t shift_right_toU16(uint16_t val)
{
return val >> 8U;
}
uint16_t shift_left_fromU8(uint8_t val)
{
return val << 8U;
}
uint16_t shift_left_fromU16(uint16_t val)
{
return val << 8U;
}
ASM output (stripped of additional info):
shift_right_toU8:
;* --------------------------------------------------------------------------*
SWPB r12 ; [] |46|
MOV.B r12,r12 ; [] |46|
MOV.B r12,r12 ; [] |46|
RET ; []
shift_right_toU16:
;* --------------------------------------------------------------------------*
SWPB r12 ; [] |51|
MOV.B r12,r12 ; [] |51|
RET ; []
shift_left_fromU8:
;* --------------------------------------------------------------------------*
MOV.B r12,r12 ; [] |56|
MOV.B r12,r12 ; [] |56|
SWPB r12 ; [] |56|
RET ; []
shift_left_fromU16:
;* --------------------------------------------------------------------------*
MOV.B r12,r12 ; [] |61|
SWPB r12 ; [] |61|
RET ; []
Cheers!
Michal