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
lvqcl wrote:> A) How to properly check for 64-bit architectures? > I can check for "defined FLAC__CPU_X86_64" or "defined _WIN64".Eww :)> Is it possible to use SIZEOF_VOIDP? such as "#if SIZEOF_VOIDP == 8" ?That would work.> 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 > #endifI would suggest: #if SIZEOF_VOIDP == 8 #define FLAC__64BIT_ARCH 1 #else #define FLAC__64BIT_ARCH 0 #endif Setting a #define to either `0` or `1` means that it can be used in code like if (FLAC__64BIT_ARCH) { // 64 bit code } else { // 32 bit code } and the compiler will syntax/type check both branches but optimises one away completely. Erik -- ---------------------------------------------------------------------- Erik de Castro Lopo http://www.mega-nerd.com/
On 12/28/2015 08:35 PM, lvqcl 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" ?That would need a special case for Linux x32 which is x86_64 with 32 bits pointers
On 29 December 2015 at 13:33, Rafa?l Carr? <funman at videolan.org> wrote:> On 12/28/2015 08:35 PM, lvqcl 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" ? > > That would need a special case for Linux x32 which is x86_64 with 32 > bits pointers... and this probably won't be the last time we'd need to handle special cases. Do we really need to handle this at all? Entangling CPU-arch-dependent #ifdefs with input sample size (see "tuned for N-bit input" a few lines below" seems weird. IMHO finding the rice parameter should be independent of the cpu arch unless there is a spectacular benefit by distinguishing. Best regards Riggs
Rafa?l Carr? wrote:> That would need a special case for Linux x32 which is x86_64 with 32 > bits pointersIt won't be wrong for x32, just sub-optimal. Please feel free to suggest a way to detect x32. Erik -- ---------------------------------------------------------------------- Erik de Castro Lopo http://www.mega-nerd.com/
On 29 December 2015 at 08:08, Erik de Castro Lopo <mle+la at mega-nerd.com> wrote:> I would suggest: > > #if SIZEOF_VOIDP == 8I believe this is not portable. At least on my machine ("4.2.1 Compatible FreeBSD Clang 3.4.1 (tags/RELEASE_34/dot1-final 208032)") it's not defined. Probably this one comes closest: #define __SIZEOF_POINTER__ 8 Riggs
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