Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
12748 Discussions

gcc generates bad code for volatile data

Altera_Forum
Honored Contributor II
1,061 Views

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
0 Kudos
1 Reply
Altera_Forum
Honored Contributor II
365 Views

Some further info: 

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

 

David
0 Kudos
Reply