diff --git a/host-utils.h b/host-utils.h
index 2a46c9baff0e36eb2eb3cb072d87e768d02aef1f..3cfb4e09e87f980ae80630de81cddffe8793d12a 100644
--- a/host-utils.h
+++ b/host-utils.h
@@ -51,7 +51,7 @@ void mulu64(uint64_t *phigh, uint64_t *plow, uint64_t a, uint64_t b);
 
 static always_inline int clz32(uint32_t val)
 {
-#if defined(__GNUC__) && ((__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
+#if QEMU_GNUC_PREREQ(3, 4)
     if (val)
         return __builtin_clz(val);
     else
@@ -93,7 +93,7 @@ static always_inline int clo32(uint32_t val)
 
 static always_inline int clz64(uint64_t val)
 {
-#if defined(__GNUC__) && ((__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
+#if QEMU_GNUC_PREREQ(3, 4)
     if (val)
         return __builtin_clzll(val);
     else
@@ -118,7 +118,7 @@ static always_inline int clo64(uint64_t val)
 
 static always_inline int ctz32 (uint32_t val)
 {
-#if defined(__GNUC__) && ((__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
+#if QEMU_GNUC_PREREQ(3, 4)
     if (val)
         return __builtin_ctz(val);
     else
@@ -162,7 +162,7 @@ static always_inline int cto32 (uint32_t val)
 
 static always_inline int ctz64 (uint64_t val)
 {
-#if defined(__GNUC__) && ((__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
+#if QEMU_GNUC_PREREQ(3, 4)
     if (val)
         return __builtin_ctz(val);
     else
@@ -206,7 +206,7 @@ static always_inline int ctpop16 (uint16_t val)
 
 static always_inline int ctpop32 (uint32_t val)
 {
-#if defined(__GNUC__) && ((__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
+#if QEMU_GNUC_PREREQ(3, 4)
     return __builtin_popcount(val);
 #else
     val = (val & 0x55555555) + ((val >>  1) & 0x55555555);
@@ -221,7 +221,7 @@ static always_inline int ctpop32 (uint32_t val)
 
 static always_inline int ctpop64 (uint64_t val)
 {
-#if defined(__GNUC__) && ((__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
+#if QEMU_GNUC_PREREQ(3, 4)
     return __builtin_popcountll(val);
 #else
     val = (val & 0x5555555555555555ULL) + ((val >>  1) & 0x5555555555555555ULL);
diff --git a/hw/apic.c b/hw/apic.c
index 42920869c182370c887764d2c6aeffa375025f2e..762852e90fe0a3a1ccfcc87464e9f249cf7b5a0c 100644
--- a/hw/apic.c
+++ b/hw/apic.c
@@ -20,6 +20,7 @@
 #include "hw.h"
 #include "pc.h"
 #include "qemu-timer.h"
+#include "osdep.h"
 
 //#define DEBUG_APIC
 //#define DEBUG_IOAPIC
@@ -107,7 +108,7 @@ static void apic_update_irq(APICState *s);
 /* Find first bit starting from msb */
 static int fls_bit(uint32_t value)
 {
-#if defined(__GNUC__) && ((__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
+#if QEMU_GNUC_PREREQ(3, 4)
     return 31 - __builtin_clz(value);
 #else
     unsigned int ret = 0;
@@ -127,7 +128,7 @@ static int fls_bit(uint32_t value)
 /* Find first bit starting from lsb */
 static int ffs_bit(uint32_t value)
 {
-#if defined(__GNUC__) && ((__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
+#if QEMU_GNUC_PREREQ(3, 4)
     return __builtin_ffs(value) - 1;
 #else
     unsigned int ret = 0;
diff --git a/osdep.h b/osdep.h
index 9e8547cea41667e59069334902fe5e1522ba1afc..87f024b127ce2a75c1d315dff89c69ca0206cb81 100644
--- a/osdep.h
+++ b/osdep.h
@@ -62,6 +62,13 @@
 
 #define qemu_printf printf
 
+#if defined (__GNUC__) && defined (__GNUC_MINOR_)
+# define QEMU_GNUC_PREREQ(maj, min) \
+         ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
+#else
+# define QEMU_GNUC_PREREQ(maj, min) 0
+#endif
+
 void *qemu_memalign(size_t alignment, size_t size);
 void *qemu_vmalloc(size_t size);
 void qemu_vfree(void *ptr);