Skip to contentSkip to conversation

[5465] hw/apic.c: use __builtin funtions instead of assembly code

Qemu-devel Aurelien Jarno 3 participants 4 messages Oct 12, 2008

lore
Share & tools
lore
#0 lore raw

Revision: 5465

          http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=5465
Author:   aurel32
Date:     2008-10-12 00:53:17 +0000 (Sun, 12 Oct 2008)

Log Message:
-----------
hw/apic.c: use __builtin funtions instead of assembly code

Suggested by malc.

Modified Paths:
--------------
trunk/hw/apic.c

Modified: trunk/hw/apic.c
===================================================================

hw/apic.c +8 -10
@@ -104,15 +104,14 @@
 static void apic_set_irq(APICState *s, int vector_num, int trigger_mode);
 static void apic_update_irq(APICState *s);
 
-/* Find first bit starting from msb. Return 0 if value = 0 */
+/* Find first bit starting from msb */
 static int fls_bit(uint32_t value)
 {
+#if defined(__GNUC__)
+    return 31 - __builtin_clz(value);
+#else
     unsigned int ret = 0;
 
-#if defined(HOST_I386) || defined(HOST_X86_64)
-    __asm__ __volatile__ ("bsr %1, %0\n" : "+r" (ret) : "rm" (value));
-    return ret;
-#else
     if (value > 0xffff)
         value >>= 16, ret = 16;
     if (value > 0xff)
@@ -125,15 +124,14 @@
 #endif
 }
 
-/* Find first bit starting from lsb. Return 0 if value = 0 */
+/* Find first bit starting from lsb */
 static int ffs_bit(uint32_t value)
 {
+#if defined(__GNUC__)
+    return __builtin_ffs(value) - 1;
+#else
     unsigned int ret = 0;
 
-#if defined(HOST_I386) || defined(HOST_X86_64)
-    __asm__ __volatile__ ("bsf %1, %0\n" : "+r" (ret) : "rm" (value));
-    return ret;
-#else
     if (!value)
         return 0;
     if (!(value & 0xffff))
#1 lore raw
Quoted 22 lines · Aurelien Jarno

Revision: 5465

          http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=5465
Author:   aurel32
Date:     2008-10-12 00:53:17 +0000 (Sun, 12 Oct 2008)

Log Message:
-----------
hw/apic.c: use __builtin funtions instead of assembly code

Suggested by malc.

Modified Paths:
--------------
trunk/hw/apic.c

Modified: trunk/hw/apic.c
===================================================================

hw/apic.c line 111

Quoted 9 lines
hw/apic.c +3 -1
@@ -104,15 +104,14 @@
 static void apic_set_irq(APICState *s, int vector_num, int trigger_mode);
 static void apic_update_irq(APICState *s);
 
-/* Find first bit starting from msb. Return 0 if value = 0 */
+/* Find first bit starting from msb */
 static int fls_bit(uint32_t value)
 {
+#if defined(__GNUC__)
+    return 31 - __builtin_clz(value);

That as well as most (if not all) of the __builtin_* changes are gcc3.4+ stuff. Thus gcc3.3 builds are unfortunately broken now.

Jan

#2 lore raw
Quoted 26 lines · Jan Kiszka
Quoted 25 lines · Aurelien Jarno

Revision: 5465

          http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=5465
Author:   aurel32
Date:     2008-10-12 00:53:17 +0000 (Sun, 12 Oct 2008)

Log Message:
-----------
hw/apic.c: use __builtin funtions instead of assembly code

Suggested by malc.

Modified Paths:
--------------
trunk/hw/apic.c

Modified: trunk/hw/apic.c
===================================================================

hw/apic.c +0 -0
@@ -104,15 +104,14 @@
 static void apic_set_irq(APICState *s, int vector_num, int trigger_mode);
 static void apic_update_irq(APICState *s);
 
Quoted 10 lines

hw/apic.c line 111

Quoted 6 lines
hw/apic.c +3 -1
-/* Find first bit starting from msb. Return 0 if value = 0 */
+/* Find first bit starting from msb */
 static int fls_bit(uint32_t value)
 {
+#if defined(__GNUC__)
+    return 31 - __builtin_clz(value);

That as well as most (if not all) of the __builtin_* changes are gcc3.4+ stuff. Thus gcc3.3 builds are unfortunately broken now.

That should be fixed now.

Signature · 4 lines
  .''`.  Aurelien Jarno	            | GPG: 1024D/F1BCDB73
 : :' :  Debian developer           | Electrical Engineer
 `. `'   [email protected]         | [email protected]
   `-    people.debian.org/~aurel32 | www.aurel32.net
#3 lore raw
In reply to Aurelien Jarno
Quoted 4 lines · Aurelien Jarno

 static int fls_bit(uint32_t value)
 {
+#if defined(__GNUC__)
+    return 31 - __builtin_clz(value);

This should be using clz32, not duplicating this code.

Paul