On Tue, May 21, 2019 at 9:46 AM Uros Bizjak <ubiz...@gmail.com> wrote: > > On Tue, May 21, 2019 at 12:20 AM tedheadster <tedheads...@gmail.com> wrote: > > > > On Mon, May 20, 2019 at 2:57 PM Uros Bizjak <ubiz...@gmail.com> wrote: > > > > > > On Mon, May 20, 2019 at 6:12 PM tedheadster <tedheads...@gmail.com> wrote: > > > > Did you instead mean "zeroing %EBX and %ECX regs should be enough"? > > > > > > Ah, yes. This is what I meant to say. The patch clears %ebx and %ecx. > > > > > > > Uros, > > your patch worked on real 32-bit hardware. The assembly output is > > nearly identical to mine, with merely a re-ordering when setting the > > %eax, %ebx, and %ecx registers. > > Attached patch fixes the core of the problem. We can change __cpuid > itself to use zeroing, unless we can prove that we use constant > argument, different than 1. __cpuid is mostly used with constant > argument, so constant propagation does its job. As an example: > > --cut here-- > #include "cpuid.h" > > int main () > { > unsigned int eax, ebx, ecx, edx; > > if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx)) > __builtin_abort (); > > printf ("%#x, %#x, %#x, %#x\n", eax, ebx, ecx, edx); > return 0; > } > --cut here-- > > results in: > > 2f: 31 f6 xor %esi,%esi > 31: 89 f0 mov %esi,%eax > 33: 0f a2 cpuid > 35: 85 c0 test %eax,%eax > 37: 0f 84 fc ff ff ff je 39 <main+0x39> > 3d: 83 ec 0c sub $0xc,%esp > 40: 89 f3 mov %esi,%ebx > 42: 89 f1 mov %esi,%ecx > 44: b8 01 00 00 00 mov $0x1,%eax > 49: 0f a2 cpuid
2019-05-21 Uroš Bizjak <ubiz...@gmail.com> * config/i386/cpuid.h (__cpuid): For 32bit targets, zero %ebx and %ecx bafore calling cpuid with leaf 1 or non-constant leaf argument. Bootstrapped and regression tested on x86_64-linux-gnu {,-m32}. Committed to mainline SVN, will be backported to all active branches. Uros.