Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
16 years ago

gcc generates bad code for volatile data

If you look at the generated code for reads of volatile char and short data, it seems that gcc assumes that the high bits of the register are undefined.

For instance:

int fubar(volatile char *bar) { return *bar; }

Generates:

ldbu r5, 0(r4)

andi r3, r5, 255

xori r2, r3, 128

addi r2, r2, -128

ret

Without the volatile the expected 'ldb r2, 0(r4)' is generated.

I've tried buiding gcc with PROMOTE_MODE defined (to its typical value) - but that has no effect.

Any other thoughts??

David

1 Reply

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Some further info:

    With 'volatile unsigned char *bar' both the 'ldbu' and 'andi rx,rx,0xff' instructions come from the 'zero_extendqisi2' pattern.

    David