From: Peter Maydell <peter.maydell@linaro.org>
To: Jason Fan <fanjason@google.com>
Cc: philmd@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org
Subject: Re: [PATCH 1/1] include/qemu/bitops.h: Add deposit8 for uint8_t bit operation
Date: Tue, 27 Aug 2024 10:22:59 +0100 [thread overview]
Message-ID: <CAFEAcA_ErHypGHM_Gbh3dt35WSuAn5CworUiE5OcY9M2dDOGmA@mail.gmail.com> (raw)
In-Reply-To: <20240826204628.3541850-2-fanjason@google.com>
On Mon, 26 Aug 2024 at 22:01, Jason Fan <fanjason@google.com> wrote:
>
> Signed-off-by: Jason Fan <fanjason@google.com>
> ---
> include/qemu/bitops.h | 26 ++++++++++++++++++++++++++
> 1 file changed, 26 insertions(+)
>
> diff --git a/include/qemu/bitops.h b/include/qemu/bitops.h
> index 2c0a2fe751..d01c4b42f2 100644
> --- a/include/qemu/bitops.h
> +++ b/include/qemu/bitops.h
> @@ -459,6 +459,32 @@ static inline int64_t sextract64(uint64_t value, int start, int length)
> return ((int64_t)(value << (64 - length - start))) >> (64 - length);
> }
>
> +/**
> + * deposit8:
> + * @value: initial value to insert bit field into
> + * @start: the lowest bit in the bit field (numbered from 0)
> + * @length: the length of the bit field
> + * @fieldval: the value to insert into the bit field
> + *
> + * Deposit @fieldval into the 8 bit @value at the bit field specified
> + * by the @start and @length parameters, and return the modified
> + * @value. Bits of @value outside the bit field are not modified.
> + * Bits of @fieldval above the least significant @length bits are
> + * ignored. The bit field must lie entirely within the 8 bit word.
> + * It is valid to request that all 8 bits are modified (ie @length
> + * 8 and @start 0).
> + *
> + * Returns: the modified @value.
> + */
> +static inline uint8_t deposit8(uint8_t value, int start, int length,
> + uint8_t fieldval)
> +{
> + uint8_t mask = 0xFF;
> + assert(start >= 0 && length > 0 && length <= 8 - start);
> + mask = (mask >> (8 - length)) << start;
> + return (value & ~mask) | ((fieldval << start) & mask);
> +}
What's the use case for this? Where would you need this
and not be able to use "deposit32" instead?
thanks
-- PMM
next prev parent reply other threads:[~2024-08-27 9:23 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-26 20:46 [PATCH 0/1] Subject: Support deposit8 in include/qemu/bitops.h Jason Fan
2024-08-26 20:46 ` [PATCH 1/1] include/qemu/bitops.h: Add deposit8 for uint8_t bit operation Jason Fan
2024-08-27 9:22 ` Peter Maydell [this message]
2024-08-28 15:59 ` Jason Fan
2024-08-28 16:07 ` Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAFEAcA_ErHypGHM_Gbh3dt35WSuAn5CworUiE5OcY9M2dDOGmA@mail.gmail.com \
--to=peter.maydell@linaro.org \
--cc=fanjason@google.com \
--cc=philmd@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).