qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH] Use ctz64 in favor of ffsll


From: Jan Kiszka
Subject: [Qemu-devel] [PATCH] Use ctz64 in favor of ffsll
Date: Thu, 02 Jul 2009 09:04:46 +0200
User-agent: Mozilla/5.0 (X11; U; Linux i686 (x86_64); de; rv:1.8.1.12) Gecko/20080226 SUSE/2.0.0.12-1.1 Thunderbird/2.0.0.12 Mnenhy/0.7.5.666

Stuart Brady wrote:
> On Wed, Jul 01, 2009 at 01:58:02PM -0700, Nathan Froyd wrote:
>> On Wed, Jul 01, 2009 at 10:55:02PM +0200, Jan Kiszka wrote:
>>> -    for (i = 0; i < ARRAY_SIZE(env->interrupt_bitmap); i++) {
>>> -        bit = ffsll(env->interrupt_bitmap[i]);
>>> +    for (i = 0; i < sizeof(env->interrupt_bitmap) / sizeof(int); i++) {
>>> +        /* Note: This assumes little endian host, which is true in KVM 
>>> mode.
>>> +           In TCG mode it must be zero anyway. */
>>> +        bit = ffs(((int *)env->interrupt_bitmap)[i]);
>> ISTR that some PPC hosts support KVM...
> 
> FWIW, I notice we currently have a qemu_fls() defined in cutils.c, which 
> uses the clz32() defined in host-utils.h.
> 
> qemu_ffsll() could be implemented fairly easily in terms of ctz64(),
> although note that ffsll(n) == (ctz64(n) + 1) % 65.

ctz64 - that's what I wanted! (No need to introduce qemu_ffsll, at least
not for this use case.)

Jan

--------->

Not all host platforms support ffsll.

Signed-off-by: Jan Kiszka <address@hidden>
---

 target-i386/machine.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/target-i386/machine.c b/target-i386/machine.c
index 259302c..e4099ca 100644
--- a/target-i386/machine.c
+++ b/target-i386/machine.c
@@ -148,9 +148,9 @@ void cpu_save(QEMUFile *f, void *opaque)
        to find it and save its number instead (-1 for none). */
     pending_irq = -1;
     for (i = 0; i < ARRAY_SIZE(env->interrupt_bitmap); i++) {
-        bit = ffsll(env->interrupt_bitmap[i]);
-        if (bit) {
-            pending_irq = i * 64 + bit - 1;
+        if (env->interrupt_bitmap[i]) {
+            bit = ctz64(env->interrupt_bitmap[i]);
+            pending_irq = i * 64 + bit;
             break;
         }
     }

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]