https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97688

--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
Hmm, it doesn't work on a i7-8565U either ...

Doesn't work means check_vect () does exit (0).  Those do not end up
UNSUPPORTED (not sure if using a magic exit code to communicate this
would be possible).

Looks like $rcx is not cleared before 'cpuid' and we get garbage?!

If I set $rcx to zero it works.  The comment in cpuid.h says

/* At least one cpu (Winchip 2) does not set %ebx and %ecx
   for cpuid leaf 1. Forcibly zero the two registers before
   calling cpuid as a precaution.  */

but it does the clearing only for constant level (doesn't work at -O0
which is where I debugged check_vect).  At -O2 I see

Dump of assembler code for function check_vect:
   0x0000000000400680 <+0>:     push   %rbx
   0x0000000000400681 <+1>:     mov    $0x4006c0,%esi
   0x0000000000400686 <+6>:     mov    $0x4,%edi
   0x000000000040068b <+11>:    callq  0x400490 <signal@plt>
=> 0x0000000000400690 <+16>:    xor    %eax,%eax
   0x0000000000400692 <+18>:    cpuid  
   0x0000000000400694 <+20>:    cmp    $0x6,%eax
   0x0000000000400697 <+23>:    jbe    0x4006a5 <check_vect+37>
   0x0000000000400699 <+25>:    mov    $0x7,%eax
   0x000000000040069e <+30>:    cpuid  
   0x00000000004006a0 <+32>:    and    $0x20,%ebx
   0x00000000004006a3 <+35>:    jne    0x4006ac <check_vect+44>
   0x00000000004006a5 <+37>:    xor    %edi,%edi
   0x00000000004006a7 <+39>:    callq  0x4004a0 <exit@plt>
   0x00000000004006ac <+44>:    xor    %esi,%esi
   0x00000000004006ae <+46>:    mov    $0x4,%edi
   0x00000000004006b3 <+51>:    pop    %rbx
   0x00000000004006b4 <+52>:    jmpq   0x400490 <signal@plt>

so no zeroing of the regs of the result of the __maxlevel call and
we call cpuid with

rax            0x7                 7
rbx            0x68747541          1752462657
rcx            0x444d4163          1145913699
rdx            0x69746e65          1769238117
rsi            0x7fffffffd8b0      140737488345264
rdi            0x0                 0

and on zen2 get

rax            0x0                 0
rbx            0x0                 0
rcx            0x0                 0
rdx            0x0                 0

on i7-8565U the garbage is similar:

rax  0x7
rbx  0x756e6547
rcx  0x6c65746e
rdx  0x49656e69

with same all-zero result.

Reply via email to