Commit e95f5491bc4172f76d98f79de40a36098152937c
1 parent
7d019980
hw/apic.c: use __builtin funtions instead of assembly code
Suggested by malc. Signed-off-by: Aurelien Jarno <aurelien@aurel32.net> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5465 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
1 changed file
with
8 additions
and
10 deletions
hw/apic.c
... | ... | @@ -104,15 +104,14 @@ static void apic_init_ipi(APICState *s); |
104 | 104 | static void apic_set_irq(APICState *s, int vector_num, int trigger_mode); |
105 | 105 | static void apic_update_irq(APICState *s); |
106 | 106 | |
107 | -/* Find first bit starting from msb. Return 0 if value = 0 */ | |
107 | +/* Find first bit starting from msb */ | |
108 | 108 | static int fls_bit(uint32_t value) |
109 | 109 | { |
110 | +#if defined(__GNUC__) | |
111 | + return 31 - __builtin_clz(value); | |
112 | +#else | |
110 | 113 | unsigned int ret = 0; |
111 | 114 | |
112 | -#if defined(HOST_I386) || defined(HOST_X86_64) | |
113 | - __asm__ __volatile__ ("bsr %1, %0\n" : "+r" (ret) : "rm" (value)); | |
114 | - return ret; | |
115 | -#else | |
116 | 115 | if (value > 0xffff) |
117 | 116 | value >>= 16, ret = 16; |
118 | 117 | if (value > 0xff) |
... | ... | @@ -125,15 +124,14 @@ static int fls_bit(uint32_t value) |
125 | 124 | #endif |
126 | 125 | } |
127 | 126 | |
128 | -/* Find first bit starting from lsb. Return 0 if value = 0 */ | |
127 | +/* Find first bit starting from lsb */ | |
129 | 128 | static int ffs_bit(uint32_t value) |
130 | 129 | { |
130 | +#if defined(__GNUC__) | |
131 | + return __builtin_ffs(value) - 1; | |
132 | +#else | |
131 | 133 | unsigned int ret = 0; |
132 | 134 | |
133 | -#if defined(HOST_I386) || defined(HOST_X86_64) | |
134 | - __asm__ __volatile__ ("bsf %1, %0\n" : "+r" (ret) : "rm" (value)); | |
135 | - return ret; | |
136 | -#else | |
137 | 135 | if (!value) |
138 | 136 | return 0; |
139 | 137 | if (!(value & 0xffff)) | ... | ... |