Re: cpuid_eax damages registers (2.4.7pre7)

H. Peter Anvin
2001-07-19T18:37:06Z

Followup to: <Pine.LNX.4.10.10107191113080.2341-100000@l>
By author: Julian Anastasov <ja@ssi.bg>
In newsgroup: linux.dev.kernel
>
> This patch works for me too (I checked all cpuid_XXX calls).
> After some thinking I produced another patch. The interesting part is
> that __volatile__ solves the problem. Patch appended. I see in other
> kernel files that volatile solves gcc bugs. The question is whether
> the volatile is needed only as a work-around or it is needed in this
> case particulary, i.e. where the output registers are not used and are
> optimized.
>

It certainly shouldn't; obviously, the assembly code is clearly
declaring that it is outputting multiple things. "volatile" on an
"asm" statement basically means "do this even if you don't need the
output values" (i.e. don't assume you're doing this just for the
computation), which is incorrect in this case (we *are* doing it just
for the output values, not for any side effects), but it is not really
surprising that it works around this bug.

The problem seems to be that gcc 2.91.66 thinks it can optimize away
half of an indivisible operation, which cannot be called anything but
a bug.

-hpa
--
<hpa@transmeta.com> at work, <hpa@zytor.com> in private!
"Unix gives you enough rope to shoot yourself in the foot."