From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: Jonathan Cameron <Jonathan.Cameron@huawei.com>,
qemu-devel@nongnu.org, Michael Tsirkin <mst@redhat.com>,
Fan Ni <fan.ni@samsung.com>
Cc: linux-cxl@vger.kernel.org, linuxarm@huawei.com,
"Ira Weiny" <ira.weiny@intel.com>,
"Alison Schofield" <alison.schofield@intel.com>,
"Michael Roth" <michael.roth@amd.com>,
"Dave Jiang" <dave.jiang@intel.com>,
"Markus Armbruster" <armbru@redhat.com>,
"Daniel P . Berrangé" <berrange@redhat.com>,
"Eric Blake" <eblake@redhat.com>,
"Mike Maslenkin" <mike.maslenkin@gmail.com>,
"Marc-André Lureau" <marcandre.lureau@redhat.com>,
"Thomas Huth" <thuth@redhat.com>,
"Peter Maydell" <peter.maydell@linaro.org>,
"Richard Henderson" <richard.henderson@linaro.org>
Subject: Re: [PATCH v4 3/6] bswap: Add the ability to store to an unaligned 24 bit field
Date: Tue, 14 Mar 2023 07:13:03 +0100 [thread overview]
Message-ID: <28a9d97a-b252-a33f-1ac0-cd36264b29ab@linaro.org> (raw)
In-Reply-To: <20230303150908.27889-4-Jonathan.Cameron@huawei.com>
On 3/3/23 16:09, Jonathan Cameron wrote:
> From: Ira Weiny <ira.weiny@intel.com>
>
> CXL has 24 bit unaligned fields which need to be stored to. CXL is
> specified as little endian.
>
> Define st24_le_p() and the supporting functions to store such a field
> from a 32 bit host native value.
>
> The use of b, w, l, q as the size specifier is limiting. So "24" was
> used for the size part of the function name.
>
> Reviewed-by: Fan Ni <fan.ni@samsung.com>
> Signed-off-by: Ira Weiny <ira.weiny@intel.com>
> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
>
> ---
> v8:
> - Picked up tag from Fan Ni.
> ---
> include/qemu/bswap.h | 23 +++++++++++++++++++++++
> 1 file changed, 23 insertions(+)
>
> diff --git a/include/qemu/bswap.h b/include/qemu/bswap.h
> index 15a78c0db5..ee71cbeaaa 100644
> --- a/include/qemu/bswap.h
> +++ b/include/qemu/bswap.h
> @@ -8,11 +8,23 @@
> #undef bswap64
> #define bswap64(_x) __builtin_bswap64(_x)
>
> +static inline uint32_t bswap24(uint32_t x)
> +{
Could it be safer to add:
assert(x & 0xff000000U == 0);
...
> + return (((x & 0x000000ffU) << 16) |
> + ((x & 0x0000ff00U) << 0) |
> + ((x & 0x00ff0000U) >> 16));
> +}
> +
> static inline void bswap16s(uint16_t *s)
> {
> *s = __builtin_bswap16(*s);
> }
>
> +static inline void bswap24s(uint32_t *s)
> +{
> + *s = bswap24(*s);
... and here use:
*s = bswap24(*s & 0x00ffffffU);
?
> +}
> +
> static inline void bswap32s(uint32_t *s)
> {
> *s = __builtin_bswap32(*s);
> @@ -176,6 +188,7 @@ CPU_CONVERT(le, 64, uint64_t)
> * size is:
> * b: 8 bits
> * w: 16 bits
> + * 24: 24 bits
Following the pattern, shouldn't this be 's' for sēsquiword?
Regardless you need to update the doc in docs/devel/loads-stores.rst.
> * l: 32 bits
> * q: 64 bits
> *
> @@ -248,6 +261,11 @@ static inline void stw_he_p(void *ptr, uint16_t v)
> __builtin_memcpy(ptr, &v, sizeof(v));
> }
>
> +static inline void st24_he_p(void *ptr, uint32_t v)
> +{
> + __builtin_memcpy(ptr, &v, 3);
> +}
> +
> static inline int ldl_he_p(const void *ptr)
> {
> int32_t r;
> @@ -297,6 +315,11 @@ static inline void stw_le_p(void *ptr, uint16_t v)
> stw_he_p(ptr, le_bswap(v, 16));
> }
>
> +static inline void st24_le_p(void *ptr, uint32_t v)
> +{
> + st24_he_p(ptr, le_bswap(v, 24));
> +}
next prev parent reply other threads:[~2023-03-14 6:14 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-03 15:09 [PATCH v4 0/6] hw/cxl: Poison get, inject, clear Jonathan Cameron via
2023-03-03 15:09 ` [PATCH v4 1/6] hw/cxl: rename mailbox return code type from ret_code to CXLRetCode Jonathan Cameron via
2023-03-14 5:55 ` Philippe Mathieu-Daudé
2023-03-03 15:09 ` [PATCH v4 2/6] hw/cxl: Introduce cxl_device_get_timestamp() utility function Jonathan Cameron via
2023-03-03 15:09 ` [PATCH v4 3/6] bswap: Add the ability to store to an unaligned 24 bit field Jonathan Cameron via
2023-03-14 6:13 ` Philippe Mathieu-Daudé [this message]
2023-03-03 15:09 ` [PATCH v4 4/6] hw/cxl: QMP based poison injection support Jonathan Cameron via
2023-03-03 21:21 ` Ira Weiny
2023-03-14 5:21 ` Fan Ni
2023-03-14 6:22 ` Philippe Mathieu-Daudé
2023-03-03 15:09 ` [PATCH v4 5/6] hw/cxl: Add poison injection via the mailbox Jonathan Cameron via
2023-03-14 5:22 ` Fan Ni
2023-03-14 6:27 ` Philippe Mathieu-Daudé
2023-04-21 17:33 ` Jonathan Cameron via
2023-03-03 15:09 ` [PATCH v4 6/6] hw/cxl: Add clear poison mailbox command support Jonathan Cameron via
2023-03-04 6:47 ` Ira Weiny
2023-03-06 10:03 ` Jonathan Cameron via
2023-03-13 16:16 ` Jonathan Cameron via
2023-03-14 5:29 ` Fan Ni
2023-03-14 6:32 ` [PATCH v4 0/6] hw/cxl: Poison get, inject, clear Philippe Mathieu-Daudé
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=28a9d97a-b252-a33f-1ac0-cd36264b29ab@linaro.org \
--to=philmd@linaro.org \
--cc=Jonathan.Cameron@huawei.com \
--cc=alison.schofield@intel.com \
--cc=armbru@redhat.com \
--cc=berrange@redhat.com \
--cc=dave.jiang@intel.com \
--cc=eblake@redhat.com \
--cc=fan.ni@samsung.com \
--cc=ira.weiny@intel.com \
--cc=linux-cxl@vger.kernel.org \
--cc=linuxarm@huawei.com \
--cc=marcandre.lureau@redhat.com \
--cc=michael.roth@amd.com \
--cc=mike.maslenkin@gmail.com \
--cc=mst@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
--cc=thuth@redhat.com \
/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).