[5466] Only use __builtin_* with GCC >= 3.4
Revision: 5466
http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=5466 Author: aurel32 Date: 2008-10-12 11:44:36 +0000 (Sun, 12 Oct 2008)
Log Message:
-----------
Only use __builtin_* with GCC >= 3.4
Fix gcc 3.3 builds, broken in revision 5465.
Revision Links:
--------------
http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=5465
Modified Paths:
--------------
trunk/host-utils.h
trunk/hw/apic.c
Modified: trunk/host-utils.h
===================================================================
host-utils.h +6 -6
@@ -51,7 +51,7 @@ static always_inline int clz32(uint32_t val) { -#if defined(__GNUC__) +#if defined(__GNUC__) && ((__GNUC__ >3 ) || (__GNUC__ ==3 && __GNUC_MINOR__ >=4 ))if (val)return __builtin_clz (val);else
@@ -93,7 +93,7 @@ static always_inline int clz64(uint64_t val) { -#if defined(__GNUC__) +#if defined(__GNUC__) && ((__GNUC__ >3 ) || (__GNUC__ ==3 && __GNUC_MINOR__ >=4 ))if (val)return __builtin_clzll (val);else
@@ -118,7 +118,7 @@ static always_inline int ctz32 (uint32_t val) { -#if defined(__GNUC__) +#if defined(__GNUC__) && ((__GNUC__ >3 ) || (__GNUC__ ==3 && __GNUC_MINOR__ >=4 ))if (val)return __builtin_ctz (val);else
@@ -162,7 +162,7 @@ static always_inline int ctz64 (uint64_t val) { -#if defined(__GNUC__) +#if defined(__GNUC__) && ((__GNUC__ >3 ) || (__GNUC__ ==3 && __GNUC_MINOR__ >=4 ))if (val)return __builtin_ctz (val);else
@@ -206,7 +206,7 @@ static always_inline int ctpop32 (uint32_t val) { -#if defined(__GNUC__) +#if defined(__GNUC__) && ((__GNUC__ >3 ) || (__GNUC__ ==3 && __GNUC_MINOR__ >=4 ))return __builtin_popcount (val);#else val = (val &0x55555555 ) + ((val >>1 ) &0x55555555 );
@@ -221,7 +221,7 @@ static always_inline int ctpop64 (uint64_t val) { -#if defined(__GNUC__) +#if defined(__GNUC__) && ((__GNUC__ >3 ) || (__GNUC__ ==3 && __GNUC_MINOR__ >=4 ))return __builtin_popcountll (val);#else val = (val &0x5555555555555555ULL ) + ((val >>1 ) &0x5555555555555555ULL );
Modified: trunk/hw/apic.c
===================================================================
hw/apic.c +2 -2
@@ -107,7 +107,7 @@/* Find first bit starting from msb */ static int fls_bit (uint32_t value) { -#if defined(__GNUC__) +#if defined(__GNUC__) && ((__GNUC__ >3 ) || (__GNUC__ ==3 && __GNUC_MINOR__ >=4 ))return 31 -__builtin_clz (value);#else unsigned int ret =0 ;
@@ -127,7 +127,7 @@/* Find first bit starting from lsb */ static int ffs_bit (uint32_t value) { -#if defined(__GNUC__) +#if defined(__GNUC__) && ((__GNUC__ >3 ) || (__GNUC__ ==3 && __GNUC_MINOR__ >=4 ))return __builtin_ffs (value) -1 ;#else unsigned int ret =0 ;
Quoted 15 lines · Aurelien Jarno
Revision: 5466
http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=5466 Author: aurel32 Date: 2008-10-12 11:44:36 +0000 (Sun, 12 Oct 2008)Log Message:
-----------
Only use __builtin_* with GCC >= 3.4Fix gcc 3.3 builds, broken in revision 5465.
static
always_inlineintclz32(uint32_t val)
{
Review
Quoted 2 lines
(quoted diff) +1
-1-#if defined(__GNUC__) +#if defined(__GNUC__) && ((__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
Couldn't this be wrapped in GCC_BUILTINS_AVAILABLE or GCC_ATLEAST_3_4? My eyes hurt.
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 6 lines · Avi Kivity
Quoted 3 lines
(quoted diff) +1
-1-#if defined(__GNUC__) +#if defined(__GNUC__) && ((__GNUC__ > 3) || (__GNUC__ == 3 &&
__GNUC_MINOR__>= 4))Couldn't this be wrapped in
GCC_BUILTINS_AVAILABLEorGCC_ATLEAST_3_4? My eyes hurt.
Glibc uses "#if __GNUC_PREREQ (3,4)" which is quite neat. Do "grep -R GNUC_PREREQ /usr/include".
I use (and define if not already defined) the same macro in my programs, on the assumption that the macro's meaning is unlikely to ever change or be different elsewhere.
-- Jamie
Quoted 7 lines · Jamie Lokier
Glibc uses "#if
__GNUC_PREREQ(3,4)" which is quite neat. Do "grep -RGNUC_PREREQ/usr/include".I use (and define if not already defined) the same macro in my programs, on the assumption that the macro's meaning is unlikely to ever change or be different elsewhere.
It's illegal to define or use an identifier beginning with two underscores, unless it's documented by the implementation. What if glibc adds a third argument? All your apps wil break.
You should define your own macros for this, with a non-__ name.
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 5 lines · Avi Kivity
It's illegal to define or use an identifier beginning with two underscores, unless it's documented by the implementation. What if glibc adds a third argument? All your apps wil break.
You should define your own macros for this, with a non-__ name.
I agree. Portable apps especially should use their own names.
Same applies with just one underscore, I think: they're reserved in the "implementation" namespace.
But I'd add that avoiding underscore is advisable but not a guarantee. Sometimes Glibc defines a new macro/variable/function _without_ the preceding underscore, when you've requested all Glibc extensions by defining _GNU_SOURCE. It's not likely for this macro, and conflicts are obviously much more likely with underscore prefixes.
I've also seen ugly link-time or run-time errors: E.g. defining a function called dprintf' or warn' in the app can break some parts of Glibc at run-time, with no compile-time error.
This is awkward for third party _libs_ used with a lot of other libs and apps, as the only realistic protection comes from making sure every non-static symbol (including internal-use-only ones) has a prefix that no other lib or app is likely to use. Fingers crossed. Once you're dependent on prefix uniqueness, it's a matter of debate or maybe taste whether using `_myownlib_symbol' (i.e. underscore prefix before unique prefix) is advisable for internal-use-only names.
-- Jamie
In message: <[email protected]>
Avi Kivity <[email protected]> writes:
: Jamie Lokier wrote:
: > Glibc uses "#if __GNUC_PREREQ (3,4)" which is quite neat. : > Do "grep -R GNUC_PREREQ /usr/include".
: >
: > I use (and define if not already defined) the same macro in my : > programs, on the assumption that the macro's meaning is unlikely to : > ever change or be different elsewhere.
: >
:
: It's illegal to define or use an identifier beginning with two : underscores, unless it's documented by the implementation. What if : glibc adds a third argument? All your apps wil break.
Lots of things would break :-(
: You should define your own macros for this, with a non-__ name.
Identifiers starting with __ are reserved for the implementation. They aren't illegal, per se, just reserved.
Warner