On 06/27/2012 04:22 PM, Peter Maydell wrote:
> On 27 June 2012 14:15, Avi Kivity <[email protected]> wrote:
>> I suggest adding the analogous functions for writing. I believe the
>> common naming is extract/deposit.
>>
>> static inline uint64_t deposit64(uint64_t *pvalue, unsigned start,
>> unsigned length, uint64_t fieldval)
>> {
>> uint64_t mask = (((uint64_t)1 << length) - 1) << start;
>> *pvalue = (*pvalue & ~mask) | ((fieldval << start) & mask);
>> }
>>
>> Useful for setting a bit to a specific value.
>
> Do you have a use case in mind for this one?
A fast grep:
hw/alpha_typhoon.c- if (level) {
hw/alpha_typhoon.c: drir |= 1ull << irq;
hw/alpha_typhoon.c- } else {
hw/alpha_typhoon.c: drir &= ~(1ull << irq);
hw/alpha_typhoon.c- }
hw/cbus.c- if (state)
hw/cbus.c: s->status &= ~(1 << 5);
hw/cbus.c- else
hw/cbus.c: s->status |= 1 << 5;
hw/dma.c- case 0x09:
hw/dma.c- ichan = data & 3;
hw/dma.c- if (data & 4) {
hw/dma.c: d->status |= 1 << (ichan + 4);
hw/dma.c- }
hw/dma.c- else {
hw/dma.c: d->status &= ~(1 << (ichan + 4));
hw/dma.c- }
hw/dma.c: d->status &= ~(1 << ichan);
hw/dma.c- DMA_run();
hw/dma.c- break;
hw/dma.c-
hw/dma.c- case 0x0a: /* single mask */
hw/dma.c- if (data & 4)
hw/dma.c: d->mask |= 1 << (data & 3);
hw/dma.c- else
hw/dma.c: d->mask &= ~(1 << (data & 3));
hw/dma.c- DMA_run();
hw/exynos4210_combiner.c- if (level) {
hw/exynos4210_combiner.c: s->group[group_n].src_pending |= 1 << bit_n;
hw/exynos4210_combiner.c- } else {
hw/exynos4210_combiner.c: s->group[group_n].src_pending &= ~(1 << bit_n);
hw/exynos4210_combiner.c- }
hw/exynos4210_combiner.c-
I stopped here, but I'm sure there are plenty others. Bitfields are common in
hardware.
--
error compiling committee.c: too many arguments to function