Menu

#587 8051 redundant calculations

open
nobody
None
5
2019-04-29
2018-10-18
No

*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

Discussion

  • Konstantin Kim

    Konstantin Kim - 2018-10-19

    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
    }

     
  • Frieder Ferlemann

    you can get to the intended code:

    rfe_587.c:13: length = ((uint8_t)note >> 4) & 0xf;
          000016 E5*01            [12]  167     mov a,_note
          000018 C4               [12]  168     swap    a
          000019 54 0F            [12]  169     anl a,#0x0f
          00001B F5*00            [12]  170     mov _length,a
    

    by giving the compiler an (uint8_t) hint. Appending a compilable snippet.

     
  • Konstantin Kim

    Konstantin Kim - 2019-04-29

    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.

     

Log in to post a comment.