Menu ▾ ▴

#3237 MCS-51 bitwise ops suboptimal

closed-rejected
None
MCS51
5
2021-05-17
2021-05-15
No

A simple bitwise operation such as: WDT_EN &= ~1 compiles to suboptimal code, such as:

    mov r7,_WDT_EN
    mov a,#0xFE
    anl a,r7
    mov _WDT_EN,a

This is especially troublesome when the operation is expected to be atomic (such as clearing interrupt flags). I've hit this issue when porting code which originally targeted Keil C51.

Casting the RHS to an 8-bit type solves the problem, as seen below:

;   main.c:29: WDT_EN&=(unsigned char)~1;
    anl _WDT_EN,#0xFE
;   main.c:30: WDT_EN&=0xfe;
    anl _WDT_EN,#0xFE

Tested on SDCC 4.1.0 #12072

Discussion

  • Andrzej Szombierski

    Sorry, it seems that I've mixed something up. I've re-tested it and I see that SDCC 4.1.0 produces the expected optimal code. The bug can be closed.

     
  • Philipp Klaus Krause

    • status: open --> closed-rejected
    • assigned_to: Philipp Klaus Krause
     

Log in to post a comment.