* [Qemu-devel] [5466] Only use __builtin_* with GCC >= 3.4
@ 2008-10-12 11:44 Aurelien Jarno
2008-10-12 12:33 ` Avi Kivity
0 siblings, 1 reply; 6+ messages in thread
From: Aurelien Jarno @ 2008-10-12 11:44 UTC (permalink / raw)
To: qemu-devel
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.
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
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
===================================================================
--- trunk/host-utils.h 2008-10-12 00:53:17 UTC (rev 5465)
+++ trunk/host-utils.h 2008-10-12 11:44:36 UTC (rev 5466)
@@ -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
===================================================================
--- trunk/hw/apic.c 2008-10-12 00:53:17 UTC (rev 5465)
+++ trunk/hw/apic.c 2008-10-12 11:44:36 UTC (rev 5466)
@@ -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;
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [5466] Only use __builtin_* with GCC >= 3.4
2008-10-12 11:44 [Qemu-devel] [5466] Only use __builtin_* with GCC >= 3.4 Aurelien Jarno
@ 2008-10-12 12:33 ` Avi Kivity
2008-10-12 14:23 ` Jamie Lokier
0 siblings, 1 reply; 6+ messages in thread
From: Avi Kivity @ 2008-10-12 12:33 UTC (permalink / raw)
To: qemu-devel
Aurelien Jarno wrote:
> 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.
>
>
> static always_inline int clz32(uint32_t val)
> {
> -#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.
--
error compiling committee.c: too many arguments to function
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [5466] Only use __builtin_* with GCC >= 3.4
2008-10-12 12:33 ` Avi Kivity
@ 2008-10-12 14:23 ` Jamie Lokier
2008-10-12 15:02 ` Avi Kivity
0 siblings, 1 reply; 6+ messages in thread
From: Jamie Lokier @ 2008-10-12 14:23 UTC (permalink / raw)
To: qemu-devel
Avi Kivity wrote:
> >-#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.
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [5466] Only use __builtin_* with GCC >= 3.4
2008-10-12 14:23 ` Jamie Lokier
@ 2008-10-12 15:02 ` Avi Kivity
2008-10-12 15:33 ` Jamie Lokier
2008-10-12 19:10 ` M. Warner Losh
0 siblings, 2 replies; 6+ messages in thread
From: Avi Kivity @ 2008-10-12 15:02 UTC (permalink / raw)
To: qemu-devel
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.
You should define your own macros for this, with a non-__ name.
--
error compiling committee.c: too many arguments to function
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [5466] Only use __builtin_* with GCC >= 3.4
2008-10-12 15:02 ` Avi Kivity
@ 2008-10-12 15:33 ` Jamie Lokier
2008-10-12 19:10 ` M. Warner Losh
1 sibling, 0 replies; 6+ messages in thread
From: Jamie Lokier @ 2008-10-12 15:33 UTC (permalink / raw)
To: qemu-devel
Avi Kivity wrote:
> 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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [5466] Only use __builtin_* with GCC >= 3.4
2008-10-12 15:02 ` Avi Kivity
2008-10-12 15:33 ` Jamie Lokier
@ 2008-10-12 19:10 ` M. Warner Losh
1 sibling, 0 replies; 6+ messages in thread
From: M. Warner Losh @ 2008-10-12 19:10 UTC (permalink / raw)
To: qemu-devel, avi
In message: <48F21193.3000809@redhat.com>
Avi Kivity <avi@redhat.com> 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
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2008-10-12 19:13 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-10-12 11:44 [Qemu-devel] [5466] Only use __builtin_* with GCC >= 3.4 Aurelien Jarno
2008-10-12 12:33 ` Avi Kivity
2008-10-12 14:23 ` Jamie Lokier
2008-10-12 15:02 ` Avi Kivity
2008-10-12 15:33 ` Jamie Lokier
2008-10-12 19:10 ` M. Warner Losh
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).