public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Issue with __sync_synchronize() or asm volatile("": : :"memory")
@ 2019-10-25  3:23 William Tambe
  2019-10-25  7:30 ` Florian Weimer
  0 siblings, 1 reply; 2+ messages in thread
From: William Tambe @ 2019-10-25  3:23 UTC (permalink / raw)
  To: gcc-help

I am using the following assembly where timer_intr is a function that
I am calling within the assembly.

__sync_synchronize();
asm volatile("": : :"memory")
asm volatile (
    "jl %%rp, %0\n"
    :: "r"(timer_intr)
    :  "memory");

The issue that I am having is that, despite the use of the "memory"
clobber or __sync_synchronize() or asm volatile("": : :"memory"),
registers holding local variables are not flushed to memory; which
causes them to have a different value after the assembly because the
function timer_intr() modified them.

Any idea ?

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Issue with __sync_synchronize() or asm volatile("": : :"memory")
  2019-10-25  3:23 Issue with __sync_synchronize() or asm volatile("": : :"memory") William Tambe
@ 2019-10-25  7:30 ` Florian Weimer
  0 siblings, 0 replies; 2+ messages in thread
From: Florian Weimer @ 2019-10-25  7:30 UTC (permalink / raw)
  To: William Tambe; +Cc: gcc-help

* William Tambe:

> I am using the following assembly where timer_intr is a function that
> I am calling within the assembly.
>
> __sync_synchronize();
> asm volatile("": : :"memory")
> asm volatile (
>     "jl %%rp, %0\n"
>     :: "r"(timer_intr)
>     :  "memory");
>
> The issue that I am having is that, despite the use of the "memory"
> clobber or __sync_synchronize() or asm volatile("": : :"memory"),
> registers holding local variables are not flushed to memory;

Variables do not necessarily reside in memory, so there is no flushing
to be done.

> which causes them to have a different value after the assembly because
> the function timer_intr() modified them.

Which ABI is this?

timer_intr needs to follow the calling convention and not clobber
callee-saved registers.  You might be able to work around this by adding
register clobbers to the extended asm statement, but calling functions
from inline assembly is problematic on other targets.

The right fix would be to have an assembler wrapper for timer_intr which
adapts it to the ABI calling convention.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-10-25  7:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-25  3:23 Issue with __sync_synchronize() or asm volatile("": : :"memory") William Tambe
2019-10-25  7:30 ` Florian Weimer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).