[bug #50987] Not all registers need to be declared volatile

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[bug #50987] Not all registers need to be declared volatile

Joerg Wunsch-6
URL:
  <http://savannah.nongnu.org/bugs/?50987>

                 Summary: Not all registers need to be declared volatile
                 Project: AVR C Runtime Library
            Submitted by: e_l_tang
            Submitted on: Tue 09 May 2017 08:20:25 PM UTC
                Category: None
                Severity: 3 - Normal
                Priority: 5 - Normal
              Item Group: None
                  Status: None
        Percent Complete: 0%
             Assigned to: None
        Originator Email:
             Open/Closed: Open
         Discussion Lock: Any
                 Release: 2.0.0
           Fixed Release: None

    _______________________________________________________

Details:

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.




    _______________________________________________________

Reply to this item at:

  <http://savannah.nongnu.org/bugs/?50987>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.nongnu.org/


_______________________________________________
AVR-libc-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/avr-libc-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[bug #50987] Not all registers need to be declared volatile

Joerg Wunsch-6
Follow-up Comment #1, bug #50987 (project avr-libc):

Would you be a /bit/ more specific?

    _______________________________________________________

Reply to this item at:

  <http://savannah.nongnu.org/bugs/?50987>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.nongnu.org/


_______________________________________________
AVR-libc-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/avr-libc-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[bug #50987] Not all registers need to be declared volatile

Joerg Wunsch-6
Follow-up Comment #2, bug #50987 (project avr-libc):

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.

    _______________________________________________________

Reply to this item at:

  <http://savannah.nongnu.org/bugs/?50987>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.nongnu.org/


_______________________________________________
AVR-libc-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/avr-libc-dev
Loading...