[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-ppc] [PATCH v3 5/6] bitops: add BITNR macro
From: |
Alexey Kardashevskiy |
Subject: |
Re: [Qemu-ppc] [PATCH v3 5/6] bitops: add BITNR macro |
Date: |
Wed, 13 Nov 2013 13:40:53 +1100 |
User-agent: |
Mozilla/5.0 (X11; Linux i686 on x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.1.0 |
On 11/11/2013 10:57 PM, Andreas Färber wrote:
> Am 11.11.2013 08:44, schrieb Alexey Kardashevskiy:
>> This adds a macro to calculate the highest bit set.
>
> Isn't that already available as ffs / clz GCC builtin with wrapper in
> qemu/bitops.h? What's the difference to your macro? CC'ing Paolo.
I looked further and did not find any use of ffs/clz so I wonder what did
you mean about bitops.h and what did I miss? I am confused.
So I would suggest the following instead (if I really needed this BITNR but
I really do not :) )
===
bitops: add BITNR macro
This adds a macro to calculate the highest single bit set. If more than
one bit is set, returns -1.
Signed-off-by: Alexey Kardashevskiy <address@hidden>
diff --git a/include/qemu/bitops.h b/include/qemu/bitops.h
index 304c90c..24361b2 100644
--- a/include/qemu/bitops.h
+++ b/include/qemu/bitops.h
@@ -23,6 +23,8 @@
#define BIT_WORD(nr) ((nr) / BITS_PER_LONG)
#define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long))
+#define BITNR(m) (__builtin_popcount(m) == 1)?(__builtin_ffs(m) - 1) : -1
+
/**
* set_bit - Set a bit in memory
* @nr: the bit to set
===
>
> Andreas
>
>> If used on constant
>> values, no code will be generated.
>>
>> Signed-off-by: Alexey Kardashevskiy <address@hidden>
>> ---
>> include/qemu/bitops.h | 12 ++++++++++++
>> 1 file changed, 12 insertions(+)
>>
>> diff --git a/include/qemu/bitops.h b/include/qemu/bitops.h
>> index 304c90c..98ba42a 100644
>> --- a/include/qemu/bitops.h
>> +++ b/include/qemu/bitops.h
>> @@ -23,6 +23,18 @@
>> #define BIT_WORD(nr) ((nr) / BITS_PER_LONG)
>> #define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long))
>>
>> +#define __BITNR(m, n) ((m) == ((m) & (1<<(n)))) ? (n) :
>> +#define BITNR(m) \
>> + __BITNR((m), 31) __BITNR((m), 30) __BITNR((m), 29) __BITNR((m), 28) \
>> + __BITNR((m), 27) __BITNR((m), 26) __BITNR((m), 25) __BITNR((m), 24) \
>> + __BITNR((m), 23) __BITNR((m), 22) __BITNR((m), 21) __BITNR((m), 20) \
>> + __BITNR((m), 19) __BITNR((m), 18) __BITNR((m), 17) __BITNR((m), 16) \
>> + __BITNR((m), 15) __BITNR((m), 14) __BITNR((m), 13) __BITNR((m), 12) \
>> + __BITNR((m), 11) __BITNR((m), 10) __BITNR((m), 9) __BITNR((m), 8) \
>> + __BITNR((m), 7) __BITNR((m), 6) __BITNR((m), 5) __BITNR((m), 4) \
>> + __BITNR((m), 3) __BITNR((m), 2) __BITNR((m), 1) __BITNR((m), 0) \
>> + -1
>> +
>> /**
>> * set_bit - Set a bit in memory
>> * @nr: the bit to set
>>
>
>
--
Alexey
- Re: [Qemu-ppc] [Qemu-devel] [PATCH v3 4/6] qemu-option: support +foo/-foo command line agruments, (continued)
- Re: [Qemu-ppc] [Qemu-devel] [PATCH v3 4/6] qemu-option: support +foo/-foo command line agruments, Alexey Kardashevskiy, 2013/11/12
- Re: [Qemu-ppc] [PATCH v3 4/6] qemu-option: support +foo/-foo command line agruments, Paolo Bonzini, 2013/11/13
- Re: [Qemu-ppc] [Qemu-devel] [PATCH v3 4/6] qemu-option: support +foo/-foo command line agruments, Igor Mammedov, 2013/11/12
- Re: [Qemu-ppc] [Qemu-devel] [PATCH v3 4/6] qemu-option: support +foo/-foo command line agruments, Alexey Kardashevskiy, 2013/11/12
- Re: [Qemu-ppc] [Qemu-devel] [PATCH v3 4/6] qemu-option: support +foo/-foo command line agruments, Igor Mammedov, 2013/11/13
- Re: [Qemu-ppc] [PATCH v3 4/6] qemu-option: support +foo/-foo command line agruments, Paolo Bonzini, 2013/11/13
[Qemu-ppc] [PATCH v3 3/6] target-ppc: add "compat" CPU option, Alexey Kardashevskiy, 2013/11/11
[Qemu-ppc] [PATCH v3 5/6] bitops: add BITNR macro, Alexey Kardashevskiy, 2013/11/11
[Qemu-ppc] [PATCH v3 2/6] target-ppc: make use of new -cpu suboptions handling, Alexey Kardashevskiy, 2013/11/11
[Qemu-ppc] [PATCH v3 6/6] target-ppc: demonstrate new "vsx" property, Alexey Kardashevskiy, 2013/11/11