[flac-dev] Q: test for CPUID instruction presence

lvqcl.mail lvqcl.mail at gmail.com
Sat Dec 3 23:47:00 UTC 2016


I found that FLAC__cpu_have_cpuid_x86() was removed in the commit
<http://git.xiph.org/?p=flac.git;a=commitdiff;h=fa24613ad94ba8fb8e23bcb9ca80b4548bb617e6>
with the message:
  "Remove `FLAC__cpu_have_cpuid_x86` altogether as it wasn't actually
   being used but that was difficult to tell because of all the #ifdef
   nonsense."

But FLAC__cpu_have_cpuid_x86() actually WAS used in the code

   #if !defined FLAC__NO_ASM && (defined FLAC__HAS_NASM ||  
FLAC__HAS_X86INTRIN)
             info->use_asm = true; /* we assume a minimum of 80386 with  
FLAC__CPU_IA32 */
     #if FLAC__HAS_X86INTRIN
             if(!FLAC__cpu_have_cpuid_x86())
                     return;
     #else
             if(!FLAC__cpu_have_cpuid_asm_ia32())
                     return;
     #endif


I'll try to explain it:

   #if !defined FLAC__NO_ASM && (defined FLAC__HAS_NASM ||  
FLAC__HAS_X86INTRIN)
             /* FLAC__HAS_NASM is defined,
                             or FLAC__HAS_X86INTRIN is set to 1, or both */
             /* Now we want to test availability of CPUID instruction: */
     #if FLAC__HAS_X86INTRIN
             /* FLAC__cpu_have_cpuid_x86() is available, and we call it */
     #else
             /* FLAC__HAS_X86INTRIN is 0, this means that FLAC__HAS_NASM is  
defined
               so we can use asm functions, and we call  
FLAC__cpu_have_cpuid_asm_ia32() */
     #endif


Currently libFLAC doesn't check the existence of CPUID instruction if
FLAC__HAS_X86INTRIN is set to 1.
It's not a real problem because x86 CPUs without CPUID are probably
extinct, but if libFLAC performs this check then it should do it
in all cases (when NASM is available or intrinsics are available).


More information about the flac-dev mailing list