[Top][All Lists]

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

Re: AW: [avr-libc-dev] eeprom_read_word causes problems for the compiler

From: Wouter van Gulik
Subject: Re: AW: [avr-libc-dev] eeprom_read_word causes problems for the compiler
Date: Mon, 15 Oct 2007 12:05:49 +0200
User-agent: Thunderbird (Windows/20070728)

Haase Bjoern (PT/EMM1) schreef:
Yes I will try to put together a patch with the minimal changes. I only
to know one thing; can I assume that using this construction:

/** \ingroup avr_eeprom
   Read one 16-bit word (little endian) from EEPROM address \c addr.
eeprom_read_word (const uint16_t *addr)
 register uint16_t result asm("r24"); //I can specify r24 only

 __asm__ __volatile__ (
       XCALL " __eeprom_read_word_" _REG_LOCATION_SUFFIX CR_TAB
      : "+x" (addr),
        "=w" (result) //Use w restrict to adiw capable registers
      : );
 return result;

I fear that this will not be guaranteed to be correct! The compiler
might reorder code and might be tempted to optimize away your result
variable so that it could be placed in another register. The dangerous
thing is, that your code might work sometimes!

I was afraid so, but I look it up in the GCC documentation
"This option does not guarantee that GCC will generate code that has this variable in the register you specify at all times. You may not code an explicit reference to this register in the assembler instruction template part of an asm statement and assume it will always refer to this variable. However, using the variable as an asm operand guarantees that the specified register is used for the operand."

Also on:
" These local variables are sometimes convenient for use with the extended asm feature (see Extended Asm), if you want to write one output of the assembler instruction directly into a particular register. (This will work provided the register you specify fits the constraints specified for that operand in the asm.)"

So it seems to me that it used as it was intended. So I think it's legal after all.



reply via email to

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