avr-gcc-list
[Top][All Lists]
Advanced

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

Re: Subject: Reordering of __builtin functions around inline asm volatil


From: Georg-Johann Lay
Subject: Re: Subject: Reordering of __builtin functions around inline asm volatile
Date: Sun, 24 Sep 2023 15:18:08 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1

Am 24.09.23 um 03:48 schrieb Ricardo Cosme:
Hi,

I have a question regarding the reordering of statements involving a builtin function and extended asm volatile expressions in avr-gcc.

Consider the following code snippet:

//C++
{
   asm volatile(/* template plus operands */);
   __builtin_avr_delay_cycles(cycles);
   asm volatile(/* template plus operands */);
}

I understand that the compiler is allowed to reorder statements as long as it doesn't affect the observable behavior of the program. However, in this specific case, the __builtin_avr_delay_cycles function is a compiler intrinsic.

Assuming there are no other expressions on the above block, is it possible for the compiler to reorder the three statements?

Cheers,
Ricardo Cosme

No. __builtin_avr_delay_cycles is implicitly volatile, so it may not
be reordered against other volatile statements.

This also applies to built-ins like __builtin_avr_sei/cli/nop/nops/wdr/sleep,
whereas arithmetic built-ins like __builtin_avr_swap/fmul/insert_bits
etc. are purely arithmetic any may be reordered or optimized out.

The volatile built-ins also have a memory clobber similar to

__asm volatile ("" ::: "memory");

so they may not be reordered against memory accesses.  They may be
reordered against arithmetic operations like divisions though, cf.

https://stackoverflow.com/q/37897848/1556746


Johann



reply via email to

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