Menu

#918 STM8S103: register bits set/clear optimization bug when __asm__('nop\n') inserted

None
open
nobody
None
5
2024-05-22
2024-05-22
Andrew
No

I have a code for port bit-banging (all unnecessary is removed in debugging purposes)

#define NOP                    __asm__("nop\n")
    while(count--) {
        SPI_PORT->ODR |= SPI_CLK;
        NOP;
        SPI_PORT->ODR &= ~SPI_CLK;
        NOP;
    };

it's translated as

00101$:
    ld  a, xl
    decw    x
    tnz a
    jreq    00103$
;   src/spi.c: 44: SPI_PORT->ODR |= SPI_CLK;
    ld  a, 0x500a
    or  a, #0x20
    ld  0x500a, a
;   src/spi.c: 45: NOP;
    nop
;   src/spi.c: 46: SPI_PORT->ODR &= ~SPI_CLK;
    ld  a, 0x500a
    and a, #0xdf
    ld  0x500a, a
;   src/spi.c: 47: NOP;
    nop
    jra 00101$

when I remove NOP - all is translated as expected:

00101$:
    ld  a, xl
    decw    x
    tnz a
    jreq    00103$
;   src/spi.c: 44: SPI_PORT->ODR |= SPI_CLK;
    bset    0x500a, #5
;   src/spi.c: 46: SPI_PORT->ODR &= ~SPI_CLK;
    bres    0x500a, #5
    jra 00101$

it seems like there's optimization bug...

Discussion

  • Maarten Brock

    Maarten Brock - 2024-05-22

    Ticket moved from /p/sdcc/bugs/3736/

    Can't be converted:

    • _category: other
     
    • Maarten Brock

      Maarten Brock - 2024-05-22

      Suboptimal code generation is not a bug.

       

Log in to post a comment.