Re: [flac-dev] How to check for 64-bit CPU?
Thomas Zander wrote: > I 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)") Its *is* detected and defined by autoconf at configure time. Erik -- -- Erik de Castro Lopo http://www.mega-nerd.com/ ___ flac-dev mailing list flac-dev@xiph.org http://lists.xiph.org/mailman/listinfo/flac-dev
Re: [flac-dev] How to check for 64-bit CPU?
LRN wrote: > Guys, you do know that there are canned, portable autoconf macros for > checking things like variable sizes at configuration/compilation time, right? Indeed! Erik -- -- Erik de Castro Lopo http://www.mega-nerd.com/ ___ flac-dev mailing list flac-dev@xiph.org http://lists.xiph.org/mailman/listinfo/flac-dev
Re: [flac-dev] How to check for 64-bit CPU?
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, lvqclwrote: > In stream_encoder.c there's the following code: > > #if defined FLAC__CPU_X86_64 /* and other 64-bit arch, too */ > if(mean <= 0x8000/512) { /* 512: more or less optimal for both 16- > and 24-bit input */ > #else > if(mean <= 0x8000/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 ___ flac-dev mailing list flac-dev@xiph.org http://lists.xiph.org/mailman/listinfo/flac-dev
Re: [flac-dev] How to check for 64-bit CPU?
On 29 December 2015 at 08:08, Erik de Castro Lopowrote: > I would suggest: > >#if SIZEOF_VOIDP == 8 I 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 ___ flac-dev mailing list flac-dev@xiph.org http://lists.xiph.org/mailman/listinfo/flac-dev
Re: [flac-dev] How to check for 64-bit CPU?
On 30.12.2015 13:57, Thomas Zander wrote: > On 29 December 2015 at 08:08, Erik de Castro Lopo wrote: > >> I would suggest: >> >>#if SIZEOF_VOIDP == 8 > > I 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 > Guys, you do know that there are canned, portable autoconf macros for checking things like variable sizes at configuration/compilation time, right? -- O< ascii ribbon - stop html email! - www.asciiribbon.org signature.asc Description: OpenPGP digital signature ___ flac-dev mailing list flac-dev@xiph.org http://lists.xiph.org/mailman/listinfo/flac-dev
Re: [flac-dev] How to check for 64-bit CPU?
Le 29 déc. 2015 20:31, "Erik de Castro Lopo"a écrit : > > Rafaël Carré wrote: > > > That would need a special case for Linux x32 which is x86_64 with 32 > > bits pointers > > It won't be wrong for x32, just sub-optimal. > > Please feel free to suggest a way to detect x32. >From https://sourceware.org/glibc/wiki/x32 x86-64 C/C++ compiler predefines macro__LP64__ while x32 C/C++ compiler predefines macro __ILP32__. ___ flac-dev mailing list flac-dev@xiph.org http://lists.xiph.org/mailman/listinfo/flac-dev
Re: [flac-dev] How to check for 64-bit CPU?
On 12/29/15 11:31 AM, Erik de Castro Lopo wrote: > Rafaël Carré wrote: > >> That would need a special case for Linux x32 which is x86_64 with 32 >> bits pointers > > It won't be wrong for x32, just sub-optimal. > > Please feel free to suggest a way to detect x32. > Shouldn't these tests be in configure and at worst x32 can be passed as target. Dave > ___ flac-dev mailing list flac-dev@xiph.org http://lists.xiph.org/mailman/listinfo/flac-dev
Re: [flac-dev] How to check for 64-bit CPU?
Rafaël Carré wrote: > That would need a special case for Linux x32 which is x86_64 with 32 > bits pointers It 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/ ___ flac-dev mailing list flac-dev@xiph.org http://lists.xiph.org/mailman/listinfo/flac-dev
Re: [flac-dev] How to check for 64-bit CPU?
Rafaël Carré wrote: > From https://sourceware.org/glibc/wiki/x32 > > x86-64 C/C++ compiler predefines macro__LP64__ while x32 C/C++ compiler > predefines macro __ILP32__. What compiler defines these? GCC? Clang? The Intel compiler? Erik -- -- Erik de Castro Lopo http://www.mega-nerd.com/ ___ flac-dev mailing list flac-dev@xiph.org http://lists.xiph.org/mailman/listinfo/flac-dev
Re: [flac-dev] How to check for 64-bit CPU?
Dave Yeo wrote: > Shouldn't these tests be in configure and at worst x32 can be passed as > target. Indeed! Erik -- -- Erik de Castro Lopo http://www.mega-nerd.com/ ___ flac-dev mailing list flac-dev@xiph.org http://lists.xiph.org/mailman/listinfo/flac-dev
Re: [flac-dev] How to check for 64-bit CPU?
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 <= 0x8000/512) { /* 512: more or less optimal for both 16- > and 24-bit input */ > #else > if(mean <= 0x8000/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 ___ flac-dev mailing list flac-dev@xiph.org http://lists.xiph.org/mailman/listinfo/flac-dev
Re: [flac-dev] How to check for 64-bit CPU?
On 29 December 2015 at 13:33, Rafaël Carré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 <= 0x8000/512) { /* 512: more or less optimal for both 16- >> and 24-bit input */ >> #else >> if(mean <= 0x8000/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 ___ flac-dev mailing list flac-dev@xiph.org http://lists.xiph.org/mailman/listinfo/flac-dev
Re: [flac-dev] How to check for 64-bit CPU?
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 > #endif I 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/ ___ flac-dev mailing list flac-dev@xiph.org http://lists.xiph.org/mailman/listinfo/flac-dev