[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH v2] bitops.h: Add field32() and field64() functi
From: |
Avi Kivity |
Subject: |
Re: [Qemu-devel] [PATCH v2] bitops.h: Add field32() and field64() functions to extract bitfields |
Date: |
Wed, 27 Jun 2012 16:20:22 +0300 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:13.0) Gecko/20120605 Thunderbird/13.0 |
On 06/27/2012 04:15 PM, Avi Kivity wrote:
> On 06/27/2012 01:29 PM, Peter Maydell wrote:
>> Add field32() and field64() functions which extract a particular
>> bit field from a word and return it. Based on an idea by Jia Liu.
>>
>>
>> +/**
>> + * field64 - return a specified bit field from a uint64_t value
>> + * @value: The value to extract the bit field from
>> + * @start: The lowest bit in the bit field (numbered from 0)
>> + * @length: The length of the bit field
>> + *
>> + * Returns the value of the bit field extracted from the input value.
>> + */
>> +static inline uint64_t field64(uint64_t value, int start, int length)
>> +{
>> + assert(start >= 0 && start <= 63 && length > 0 && start + length <= 64);
>> + return (value >> start) & (~0ULL >> (64 - length));
>> +}
>> +
>
> Undefined for length == 64, so better add that to the assert.
Er, please ignore. It's undefined for length == 0, but that's
uninteresting and protected by the assert.
--
error compiling committee.c: too many arguments to function