diff mbox

[v6,01/13] bitops: Add MAKE_64BIT_MASK macro

Message ID fbef0a4b03aec3dd86034cbcad3d1a4e8878b7b9.1463093051.git.alistair.francis@xilinx.com
State New
Headers show

Commit Message

Alistair Francis May 12, 2016, 10:45 p.m. UTC
Add a macro that creates a 64bit value which has length number of ones
shifted acrros by the value of shift.

Signed-off-by: Alistair Francis <alistair.francis@xilinx.com>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
---
V5:
 - Re-write to a 64-bit mask instead of ONES()
 - Re-order this patch in the series

 include/qemu/bitops.h | 3 +++
 1 file changed, 3 insertions(+)

Comments

Peter Maydell June 9, 2016, 6:46 p.m. UTC | #1
On 12 May 2016 at 23:45, Alistair Francis <alistair.francis@xilinx.com> wrote:
> Add a macro that creates a 64bit value which has length number of ones
> shifted acrros by the value of shift.

"across"

>
> Signed-off-by: Alistair Francis <alistair.francis@xilinx.com>
> Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
> ---
> V5:
>  - Re-write to a 64-bit mask instead of ONES()
>  - Re-order this patch in the series
>
>  include/qemu/bitops.h | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/include/qemu/bitops.h b/include/qemu/bitops.h
> index 755fdd1..3c45791 100644
> --- a/include/qemu/bitops.h
> +++ b/include/qemu/bitops.h
> @@ -24,6 +24,9 @@
>  #define BIT_WORD(nr)            ((nr) / BITS_PER_LONG)
>  #define BITS_TO_LONGS(nr)       DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long))
>
> +#define MAKE_64BIT_MASK(shift, length) \
> +    (((1ull << (length)) - 1) << shift)
> +

This is undefined behaviour for a 64-bit length. The expression
we use in deposit64() to create a mask is
   ((~0ULL >> (64 - length)) << start)

thanks
-- PMM
Alistair Francis June 13, 2016, 8:57 p.m. UTC | #2
On Thu, Jun 9, 2016 at 11:46 AM, Peter Maydell <peter.maydell@linaro.org> wrote:
> On 12 May 2016 at 23:45, Alistair Francis <alistair.francis@xilinx.com> wrote:
>> Add a macro that creates a 64bit value which has length number of ones
>> shifted acrros by the value of shift.
>
> "across"
>
>>
>> Signed-off-by: Alistair Francis <alistair.francis@xilinx.com>
>> Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
>> ---
>> V5:
>>  - Re-write to a 64-bit mask instead of ONES()
>>  - Re-order this patch in the series
>>
>>  include/qemu/bitops.h | 3 +++
>>  1 file changed, 3 insertions(+)
>>
>> diff --git a/include/qemu/bitops.h b/include/qemu/bitops.h
>> index 755fdd1..3c45791 100644
>> --- a/include/qemu/bitops.h
>> +++ b/include/qemu/bitops.h
>> @@ -24,6 +24,9 @@
>>  #define BIT_WORD(nr)            ((nr) / BITS_PER_LONG)
>>  #define BITS_TO_LONGS(nr)       DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long))
>>
>> +#define MAKE_64BIT_MASK(shift, length) \
>> +    (((1ull << (length)) - 1) << shift)
>> +
>
> This is undefined behaviour for a 64-bit length. The expression
> we use in deposit64() to create a mask is
>    ((~0ULL >> (64 - length)) << start)

Fixed both.

Thanks,

Alistair

>
> thanks
> -- PMM
>
diff mbox

Patch

diff --git a/include/qemu/bitops.h b/include/qemu/bitops.h
index 755fdd1..3c45791 100644
--- a/include/qemu/bitops.h
+++ b/include/qemu/bitops.h
@@ -24,6 +24,9 @@ 
 #define BIT_WORD(nr)            ((nr) / BITS_PER_LONG)
 #define BITS_TO_LONGS(nr)       DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long))
 
+#define MAKE_64BIT_MASK(shift, length) \
+    (((1ull << (length)) - 1) << shift)
+
 /**
  * set_bit - Set a bit in memory
  * @nr: the bit to set