Bad code generated by Z80 peephole optimizer

Anonymous
2011-02-12
2013-03-12
  • Anonymous

    Anonymous - 2011-02-12

    Compiled with options  -mz80 -data-loc 0xC001
    SDCC v 3.0.0 #6037

    #include <z80/types.h>
    typedef struct
    {
        WORD firstShown;
        WORD highlighted;
        WORD count;
    } FileList;
    FileList games;
    void move_to_next()
    {
        if (games.highlighted < (games.count - 1))
            games.highlighted++;
        // Check if the games list needs to be scrolled
        if ( ((games.highlighted - games.firstShown) >= (9 >> 1)) &&
             ((games.firstShown + 9) < games.count) )
            games.firstShown++;
    }
    void asic_cmd(BYTE cmd, WORD data)
    {
        volatile BYTE dummy;
        *(volatile BYTE*)0xBFC0 = cmd;
        *(volatile BYTE*)0xFFFE = data >> 13;
        dummy = *(volatile BYTE *)(0x4000 | ((data & 0x1FFF) << 1));
    }
    

    /////////////////////

    In the first function the optimized code will increment firstShown by 10 instead of 1.
    In the second function the optimized code will write both cmd and data>>13 to the same address (0xBFC0).

    When compiling with -no-peep the code works fine.

     
  • Maarten Brock

    Maarten Brock - 2011-02-17

    Please file this as a bug in the bug tracker. Out here on the forum it is bound to get lost and forgotten.

     

Log in to post a comment.