Subject: Re: how to avoid re-ordering?
To: Luke Mewburn <firstname.lastname@example.org>
From: Gregory McGarry <email@example.com>
Date: 12/17/2001 15:48:19
Luke Mewburn wrote:
> > > > > I noticed that spl*/splx are inlined and re-orderd
> > > > > with "-O3 -march=pentium", and it produce bad codes as a result.
> > > > > I actually experienced panics due to this.
> > > >
> > > > I'll commit attached patch some days later if no objection.
> > > > thanks.
> > >
> > > Should't we just declare "cpl" as __volatile?
> > cpl is already volatile, isn't it?
> > am I missing something important?
> (Note: I am not a gcc guru.)
> What if ncpl or ocpl (local variables to the appropriate functions)
> are marked volatile as well, because as far as I can tell, it's the
> reordering of access to those variables which is what's causing the
> problem, not the access to the volatile cpl.
It seems that __asm statements are atomic and gcc won't reschedule
around them. This seems to work:
static __inline int
__asm __volatile(" \
movl %1, %%edx; \
movl %%edx, %0; \
orl %2,%%edx; \
movl %%edx, %1" : "=&r" (ocpl), "=m" (cpl) \
: "r" (ncpl) : "%edx" );
static __inline void
__asm __volatile("movl %1, %0" : "=m" (cpl) : "r" (ncpl));
-- Gregory McGarry <firstname.lastname@example.org>