On Tue, 21 May 2019, Uros Bizjak wrote:

> --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

 Hmm, I wonder why this produces larger code which relies on a single 
`xor' instruction where it could save two bytes by doing all the zeroing 
inline:

        xor    %eax,%eax
        cpuid
        test   %eax,%eax
        je     39 <main+0x39>
        sub    $0xc,%esp
        xor    %ebx,%ebx
        xor    %ecx,%ecx
        mov    $0x1,%eax
        cpuid

Is `xor' considered more computatively expensive than `mov' on the i386?

  Maciej

Reply via email to