This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Request for discussion: Rewrite of inline assembler docs
- From: Andrew Haley <aph at redhat dot com>
- To: Hannes Frederic Sowa <hannes at stressinduktion dot org>
- Cc: dw <limegreensocks at yahoo dot com>, gcc at gcc dot gnu dot org, rdsandiford at googlemail dot com
- Date: Fri, 28 Mar 2014 15:03:11 +0000
- Subject: Re: Request for discussion: Rewrite of inline assembler docs
- Authentication-results: sourceware.org; auth=none
- References: <5332823B dot 10805 at yahoo dot com> <87d2h94cr8 dot fsf at talisman dot default> <5333A135 dot 4060007 at yahoo dot com> <87y4zw138j dot fsf at talisman dot default> <533514C7 dot 3040402 at yahoo dot com> <53353C73 dot 8050708 at redhat dot com> <20140328093031 dot GG29498 at order dot stressinduktion dot org> <533543D5 dot 2000401 at redhat dot com> <20140328104615 dot GH29498 at order dot stressinduktion dot org> <533575FB dot 2070700 at redhat dot com> <20140328144838 dot GI29498 at order dot stressinduktion dot org>
On 03/28/2014 02:48 PM, Hannes Frederic Sowa wrote:
> On Fri, Mar 28, 2014 at 01:15:39PM +0000, Andrew Haley wrote:
>> On 03/28/2014 10:46 AM, Hannes Frederic Sowa wrote:
>>> On Fri, Mar 28, 2014 at 09:41:41AM +0000, Andrew Haley wrote:
>>>> On 03/28/2014 09:30 AM, Hannes Frederic Sowa wrote:
>>>>> On Fri, Mar 28, 2014 at 09:10:11AM +0000, Andrew Haley wrote:
>>>>>> On 03/28/2014 06:20 AM, dw wrote:
>
>>>> What is true here is that all registers used to cache variables that
>>>> are reachable from pointers in the program are flushed. Anything that
>>>> is statically allocated is reachable, as is anything dynamically
>>>> allocated by malloc; auto variables are not reachable unless their
>>>> address is taken.
>>>
>>> One would have to go into detail of various optimizations which could
>>> remove the address taking
>>
>> One would not: any such optimization would be incorrect. Any memory
>> reachable from an inline asm statement with a memory clobber must
>> be flushed to memory.
>
> If I extend your example with an additional pointer and take the address of s
> it still doesn't allocate s in memory and as such cannot flush out the
> register content, which is perfectly legal. The pointer is completley
> eliminated (this is an extreme example).
>
> int sum(int a[], int l) {
> int i;
> int s = 0;
> int *sp = &s;
> for (i = 0; i < l; i++) {
> asm volatile("nop # Nothing at all":::"memory");
> *sp += a[i];
> }
> return s;
> }
But that's not reachable from the asm. Reachability is key here. The
address of s is taken, but not used; GCC knows that it is not
reachable.
>>> e.g. IMHO the last sentence of the paragraph already
>>> deals with this.
>>
>> Which last sentence of what paragraph?
>
> This one:
>
> | For performance reasons, some variables only exist in registers
> | and never get written to memory. The "memory" clobber does not
> | force these values to get written to memory.
Except when it does; this is why the technical language has to be
*precise*.
The memory clobber will force all reachable variables into memory: it
must.
If we're going to avoid precise technical terms like "reachable" we
have to find some other way of saying this, or not mention is at all.
We must not say things that are misleading.
Andrew.