Hi, I'm doing something a bit non-standard. I'm trying to use DPL and DPH to pass 2 8-bit data into a function, to prevent SDCC from using memory for the 2nd parameter.
I tried to use a 16bit parameter, but using "shift" and "or" logic to do the combine process, SDCC generated unnecessary code trying to do ORL with 0 for the unused bytes.
using code like (swap1<<8|swap2) will convert 2 8bit vlaue into one 16 bit. But SDCC insists on doing the OR logic with 2 16bit value, which creates ORL intruction with 0. I also tried to use union but SDCC said compound literals are not supported.
C code:
void test16bit(uint16_t a){
}
void setup() {
volatile uint8_t swap0 = 1;
uint8_t swap1 = swap0;
uint8_t swap2 = swap0+1;
test16bit(swap1<<8|swap2);
}
Assembly code:
0000BF 634 _setup:
635 ; /var/folders/l6/28chlnbn66b1nflyprjgv26h0000gn/T/arduino_modified_sketch_134383/Blink.ino:33: volatile uint8_t swap0 = 1;
0000BF 75 12 01 [24] 636 mov _setup_swap0_65536_133,#0x01
637 ; /var/folders/l6/28chlnbn66b1nflyprjgv26h0000gn/T/arduino_modified_sketch_134383/Blink.ino:34: uint8_t swap1 = swap0;
0000C2 AF 12 [24] 638 mov r7,_setup_swap0_65536_133
639 ; /var/folders/l6/28chlnbn66b1nflyprjgv26h0000gn/T/arduino_modified_sketch_134383/Blink.ino:35: uint8_t swap2 = swap0+1;
0000C4 AE 12 [24] 640 mov r6,_setup_swap0_65536_133
0000C6 0E [12] 641 inc r6
642 ; /var/folders/l6/28chlnbn66b1nflyprjgv26h0000gn/T/arduino_modified_sketch_134383/Blink.ino:37: test16bit(swap1<<8|swap2);
0000C7 8F 05 [24] 643 mov ar5,r7
0000C9 E4 [12] 644 clr a
0000CA FF [12] 645 mov r7,a
0000CB FC [12] 646 mov r4,a
0000CC EE [12] 647 mov a,r6
0000CD 42 07 [12] 648 orl ar7,a
0000CF EC [12] 649 mov a,r4
0000D0 42 05 [12] 650 orl ar5,a
0000D2 8F 82 [24] 651 mov dpl,r7
0000D4 8D 83 [24] 652 mov dph,r5
653 ; /var/folders/l6/28chlnbn66b1nflyprjgv26h0000gn/T/arduino_modified_sketch_134383/Blink.ino:38: }
0000D6 02 00 BE [24] 654 ljmp _test16bit
It seems peeph.def didn't handle this issue, maybe it can be improved with additional peephole rule?
You may inline test16bit function or even better to replace 'volatile' with 'const'.
Last edit: Konstantin Kim 2020-11-03
Here's another (maybe simpler) case which shows a nice roundtrip of nops
Should be:
Ticket moved from /p/sdcc/bugs/3125/
Can't be converted:
There is no bug here, only a missed optimization.