[vlc-devel] [PATCH 02/25] cpu: detect AVX and AVX2 on Windows / macOS

Rémi Denis-Courmont remi at remlab.net
Tue Apr 14 16:25:22 CEST 2020


Le tiistaina 14. huhtikuuta 2020, 13.40.13 EEST Victorien Le Couviour--Tuffet a 
écrit :
> ---
>  src/misc/cpu.c | 26 +++++++++++++++++---------
>  1 file changed, 17 insertions(+), 9 deletions(-)
> 
> diff --git a/src/misc/cpu.c b/src/misc/cpu.c
> index 3bf4f8c63f..504492280d 100644
> --- a/src/misc/cpu.c
> +++ b/src/misc/cpu.c
> @@ -125,18 +125,18 @@ VLC_WEAK unsigned vlc_CPU_raw(void)
> 
>      /* Needed for x86 CPU capabilities detection */
>  # if defined (__i386__) && defined (__PIC__)
> -#  define cpuid(reg) \
> +#  define cpuid(eax, ecx) \
>      asm volatile ("xchgl %%ebx,%1\n\t" \
>                    "cpuid\n\t" \
>                    "xchgl %%ebx,%1\n\t" \
> 
>                    : "=a" (i_eax), "=r" (i_ebx), "=c" (i_ecx), "=d" (i_edx)
>                    : \
> 
> -                  : "a" (reg) \
> +                  : "a" (eax), "c"(ecx) \
> 
>                    : "cc");
> 
>  # else
> -#  define cpuid(reg) \
> +#  define cpuid(eax, ecx) \
>      asm volatile ("cpuid\n\t" \
> 
>                    : "=a" (i_eax), "=b" (i_ebx), "=c" (i_ecx), "=d" (i_edx)
>                    : \
> 
> -                  : "a" (reg) \
> +                  : "a" (eax), "c"(ecx) \
> 
>                    : "cc");
> 
>  # endif
>       /* Check if the OS really supports the requested instructions */
> @@ -164,7 +164,7 @@ VLC_WEAK unsigned vlc_CPU_raw(void)
>  # endif
> 
>      /* the CPU supports the CPUID instruction - get its level */
> -    cpuid( 0x00000000 );
> +    cpuid( 0x00000000, 0x00000000 );
> 
>  # if defined (__i386__) && !defined (__i586__) \
>    && !defined (__i686__) && !defined (__pentium4__) \
> @@ -177,8 +177,8 @@ VLC_WEAK unsigned vlc_CPU_raw(void)
>      b_amd = ( i_ebx == 0x68747541 ) && ( i_ecx == 0x444d4163 )
>                      && ( i_edx == 0x69746e65 );
> 
> -    /* test for the MMX flag */
> -    cpuid( 0x00000001 );
> +    /* test for the basic proc feature bits */
> +    cpuid( 0x00000001, 0x00000000 );
>  # if !defined (__MMX__)
>      if( ! (i_edx & 0x00800000) )
>          goto out;
> @@ -203,16 +203,24 @@ VLC_WEAK unsigned vlc_CPU_raw(void)
>              i_capabilities |= VLC_CPU_SSE4_1;
>          if (i_ecx & 0x00100000)
>              i_capabilities |= VLC_CPU_SSE4_2;
> +        if (i_ecx & 0x04000000)
> +            i_capabilities |= VLC_CPU_AVX;

As far as I understand the CPUID documentation, this is incorrect.

Also 1 << XX is far more readable notation for single bits. It took me a while 
just to count that this was testing ECX bit 26 / XSAVE...

-- 
Rémi Denis-Courmont
Ville neuve de Tapiola, République d´Uusimaa





More information about the vlc-devel mailing list