Re: Is clobber "memory" in include/asm-i386/system.h necessary?

Matthias Urlichs (smurf@smurf.noris.de)
Fri, 3 May 1996 00:54:00 +0100


In linux.dev.kernel, article <199605020246.TAA20865@netcom18.netcom.com=
>,
ftom@netcom.com (Tom May) writes:
>=20
> #define mb() __asm__ __volatile__ ("" : : :"memory")
> #define sti() __asm__ __volatile__ ("sti": : :"memory")
> #define cli() __asm__ __volatile__ ("cli": : :"memory")
>=20
> This clobber seems unnecessary since none of these instructions modif=
y
> memory that gcc doesn't know about, and any memory that is modified b=
y
> other means (hardware, interrupt handlers, etc.) is (should be?)
> accounted for in other ways such as by using volatile.
>=20
These memory references prevent gcc from moving other statements around
these statements. Obviously that's rather important when you try to loc=
k
interrupts out. "volatile" itself causes suboptimal code to be generate=
d
even in places where it's unnecessary, such as between cli() and sti().

> As an experiment, I removed the clobbers, built a kernel, and it ran
> fine (but if you try this at home, you will trigger the gcc common
> subexpression elimination bug, so until it is fixed for real, your
> kernel may or may not work).
>=20
Umm, that's not a proof that you didn't cause a bug by doing that.

Presumably, Linus (or whoever) has found at least one instance where th=
ese
memory references are necessary...

--=20
Come quickly, I am tasting stars!
-- Dom Perignon (1638-1715) at the moment of his discovery of champagn=
e
--=20
Matthias Urlichs \ Noris Network GmbH i.Gr/ Xlink-POP N=FCrnberg=
=20
Schleiermacherstra=DFe 12 \ Linux+Internet / EMail: urlichs@nor=
is.de
90491 N=FCrnberg (Germany) \ Consulting+Programming+Networking+etc'i=
ng
PGP: 1B 89 E2 1C 43 EA 80 44 15 D2 29 CF C6 C7 E0 DE=20
Click <A HREF=3D"http://info.noris.de/~smurf/finger">here</A>. =
42