bugAVR C Runtime Library - Bugs: bug #50987, Not all registers need to be...

 
 

bug #50987: Not all registers need to be declared volatile

Submitted by:  Eric Tang <e_l_tang>
Submitted on:  Tue 09 May 2017 08:20:25 PM UTC  
 
Category: NoneSeverity: 3 - Normal
Priority: 5 - NormalItem Group: None
Status: NonePercent Complete: 0%
Assigned to: NoneOpen/Closed: Open
Release: 2.0.0Fixed Release: None

Add a New Comment(Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

Tue 09 May 2017 08:51:41 PM UTC, comment #2:

I think it is generally not a good idea to remove volatile from registers because writing/reading registers generally still has a side effect in addition to just changing the value.

For example, with volatile register accesses are never reordered (a different order may have different semantics).

Another example is that some infinite loops like while(1){REG=1;} would become undefined behavior (at least in C++) without REG being volatile. See: http://en.cppreference.com/w/cpp/language/memory_model (Progress guarantee).

In summary I think the only case where removing volatile from a register is where it has no specific hardware semantics at all - reading or writing has no side effect and the value itself does not influence anything.

Ambroz Bizjak <abizjak>
Tue 09 May 2017 08:33:26 PM UTC, comment #1:

Would you be a /bit/ more specific?

Georg-Johann Lay <gjlayde>
Tue 09 May 2017 08:20:25 PM UTC, original submission:

Many registers are no different from a global 8-bit variables in that they will always contain the values which were last written to them. The compiler will be able to better optimize code which accesses them if they are not declared volatile.

Eric Tang <e_l_tang>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach File(s):
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by abizjak (Posted a comment)
  • -unavailable- added by gjlayde (Posted a comment)
  • -unavailable- added by e_l_tang (Submitted the item)
  •  

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    No Changes Have Been Made to This Item

    Back to the top


    Powered by Savane 3.1-cleanup1