Google
  Web www.spinics.net

Re: [PATCH] ARMv7 Oprofile support

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


Russell King - ARM Linux <linux@xxxxxxxxxxxxxxxx> writes:

> On Thu, Sep 04, 2008 at 10:32:02AM -0500, Woodruff, Richard wrote:
>> 
>> > > One thing I noticed was I think the patch should add the "memory"
>> > > qualifier to clobber list for asm's calls with output operands (=r).
>> > > There is a little bit of mixed C where the compiler should be told to
>> > > make sure to update local variables which may be in memory.
>> >
>> > Why?  Merely reading a register doesn't affect memory.
>> 
>> The comment was if the local variable 'val' which could be allocated in
>> memory needs updating.
>> 
>>         u32 val;
>>         asm volatile("mrc p15, 0, %0, c9, c12, 3" : "=r" (val));
>>         val &= FLAG_MASK;
>>         volatile("mrc p15, 0, %0, c9, c12, 3" : "=r" (val));
>> 
>> Can you always be assured that val will stick in a register and not be
>> pushed on the stack (memory)?
>
> Don't you think that gcc should know that an output operand would be
> modified by the assembly, no matter where it happens to be stored?

With an "=r" constraint the compiler to allocates a register, and
after the asm block the value of this register is copied to whatever
location "val" references.  If "val" has already been allocated a
register, the same register is (usually) used in the asm block.

>> I had rearranged some of the code and was seeing values not propagating
>> as expected.

One easy mistake to make is that of using "=r" constraints where "=&r"
should be used.  Basically, this is necessary when the register is
used more than once in the asm block.  Also remember that registers
allocated as output operands are not initialised.  If the initial
value is needed by the asm code, a "+r" (input/output) constraint
should be used.

The clobber list should include "memory" when the asm code modifies
memory locations not otherwise referenced as operands.

-- 
Måns Rullgård
mans@xxxxxxxxx


-------------------------------------------------------------------
List admin: http://lists.arm.linux.org.uk/mailman/listinfo/linux-arm-kernel
FAQ:        http://www.arm.linux.org.uk/mailinglists/faq.php
Etiquette:  http://www.arm.linux.org.uk/mailinglists/etiquette.php


[Site Home]     [Linux Arm]     [Fedora ARM]     [Gcc Help]     [Git]     [DCCP]     [IETF Announce]     [Security]     [PDAs]     [Linux]     [Linux Book List]     [Linux MIPS]     [Yosemite Campsites]     [Photos]

Add to Google Google PageRank Checking tool