[flac-dev] How to check for 64-bit CPU?

Brian Willoughby brianw at audiobanshee.com
Wed Dec 30 12:50:44 PST 2015


It seems that most compilers define some sort of architecture values, but they're not necessarily consistent across all compilers. I believe that the original point of the FLAC__CPU_X86_64 and similar defines was to make these consistent within the FLAC sources, but not to reinvent the wheel entirely.

As others have pointed out, there are autoconf solutions for architecture detection, and it would make sense to leverage these and set FLAC__CPU_X86_64 and related defines in the headers based on config.

Don't forget cross-compiling. Sometimes a developer wants to build for a different architecture than the one running.

Brian


On Dec 28, 2015, at 11:35 AM, lvqcl <lvqcl.mail at gmail.com> wrote:
> In stream_encoder.c there's the following code:
> 
>  #if defined FLAC__CPU_X86_64 /* and other 64-bit arch, too */
>      if(mean <= 0x80000000/512) { /* 512: more or less optimal for both 16- and 24-bit input */
>  #else
>      if(mean <= 0x80000000/8) { /* 32-bit arch: use 32-bit math if possible */
>  #endif
> 
> A) How to properly check for 64-bit architectures?
> I can check for "defined FLAC__CPU_X86_64" or "defined _WIN64".
> Is it possible to use SIZEOF_VOIDP? such as "#if SIZEOF_VOIDP == 8" ?
> 
> B) Does it make sense to put the following code into some header file?
> (if yes, what header file should be used?)
> 
> 
>  #if (defined FLAC__CPU_X86_64) || ...something else here...
>  #define FLAC__64BIT_ARCH 1
>  #else
>  #undef FLAC__64BIT_ARCH
>  #endif


More information about the flac-dev mailing list