[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-libc-dev] [patch #7909] Adding __volatile__ to __asm__ within p

From: David Brown
Subject: Re: [avr-libc-dev] [patch #7909] Adding __volatile__ to __asm__ within pgmspace header
Date: Mon, 31 Dec 2012 14:36:43 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:15.0) Gecko/20120912 Thunderbird/15.0.1

On 31/12/12 06:54, Alex Crawford wrote:

                  Summary: Adding __volatile__ to __asm__ within pgmspace
                  Project: AVR C Runtime Library
             Submitted by: crawford
             Submitted on: Mon 31 Dec 2012 05:54:17 AM GMT
                 Category: None
                 Priority: 5 - Normal
                   Status: None
                  Privacy: Public
              Assigned to: None
         Originator Email:
              Open/Closed: Open
          Discussion Lock: Any



I noticed that gcc was optimizing out calls to pgm_read_word_far() that were
within a while loop. Adding the volatile directive fixes the underlying
problem. I've added the directive to each of the LPM and ELPM calls (20 in

The patch was generated from avr-libc-1.8.0.


Could you post an example of the original C code and generated assembly code demonstrating that there is actually a problem? I would very much hope that the compiler will optimise out calls to read program memory within a loop if it does not have to repeat them. Program memory is not volatile (baring the unusual case of re-programming), and forcing the compiler to re-read data is a waste of time and space. On the other hand, if the compiler is making an illegal optimisation here then perhaps this patch is just hiding a bigger problem.




File Attachments:

Date: Mon 31 Dec 2012 05:54:17 AM GMT  Name: volatile.patch  Size: 13kB   By:
Patch for avr/pgmspace.h


Reply to this item at:


   Message sent via/by Savannah

AVR-libc-dev mailing list

reply via email to

[Prev in Thread] Current Thread [Next in Thread]