From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Tomi Valkeinen <tomi.valkeinen+renesas@ideasonboard.com>
Cc: linux-renesas-soc@vger.kernel.org,
Kieran Bingham <kieran.bingham@ideasonboard.com>
Subject: Re: [PATCH kms++ v2 3/4] kms++util: Add endian.h
Date: Mon, 5 Dec 2022 10:17:45 +0200 [thread overview]
Message-ID: <Y42pKde1E+FzeL9P@pendragon.ideasonboard.com> (raw)
In-Reply-To: <20221205080339.12801-4-tomi.valkeinen+renesas@ideasonboard.com>
Hi Tomi,
Thank you for the patch.
On Mon, Dec 05, 2022 at 10:03:38AM +0200, Tomi Valkeinen wrote:
> Add simple endianness supporting write function, and, for now, only one
> shortcut helper, write16le().
>
> Signed-off-by: Tomi Valkeinen <tomi.valkeinen+renesas@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---
> kms++util/inc/kms++util/endian.h | 46 ++++++++++++++++++++++++++++++++
> 1 file changed, 46 insertions(+)
> create mode 100644 kms++util/inc/kms++util/endian.h
>
> diff --git a/kms++util/inc/kms++util/endian.h b/kms++util/inc/kms++util/endian.h
> new file mode 100644
> index 0000000..0f7aecd
> --- /dev/null
> +++ b/kms++util/inc/kms++util/endian.h
> @@ -0,0 +1,46 @@
> +#pragma once
> +
> +#include <type_traits>
> +#include <byteswap.h>
> +#include <stdint.h>
> +
> +static_assert((__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) ||
> + (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__),
> + "Unable to detect endianness");
> +
> +enum class endian {
> + little = __ORDER_LITTLE_ENDIAN__,
> + big = __ORDER_BIG_ENDIAN__,
> + native = __BYTE_ORDER__
> +};
> +
> +template<typename T>
> +constexpr T byteswap(T value) noexcept
> +{
> + static_assert(std::is_integral<T>(), "Type is not integral");
> + static_assert(sizeof(T) == 2 ||
> + sizeof(T) == 4 ||
> + sizeof(T) == 8,
> + "Illegal value size");
> +
> + switch (sizeof(T)) {
> + case 2: return bswap_16(value);
> + case 4: return bswap_32(value);
> + case 8: return bswap_64(value);
> + }
> +}
> +
> +template<endian E, typename T>
> +static void write_endian(T* dst, T val)
> +{
> + if constexpr (E != endian::native)
> + val = byteswap(val);
> +
> + *dst = val;
> +}
> +
> +[[maybe_unused]]
> +static void write16le(uint16_t* dst, uint16_t val)
> +{
> + write_endian<endian::little, uint16_t>(dst, val);
> +}
--
Regards,
Laurent Pinchart
next prev parent reply other threads:[~2022-12-05 8:18 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-05 8:03 [PATCH kms++ v2 0/4] Support Y210, Y212, Y216 Tomi Valkeinen
2022-12-05 8:03 ` [PATCH kms++ v2 1/4] kms++: PixelFormats: Fix formatting Tomi Valkeinen
2022-12-05 8:03 ` [PATCH kms++ v2 2/4] kms++: PixelFormats: Add Y21x formats Tomi Valkeinen
2022-12-05 8:18 ` Laurent Pinchart
2022-12-05 8:03 ` [PATCH kms++ v2 3/4] kms++util: Add endian.h Tomi Valkeinen
2022-12-05 8:17 ` Laurent Pinchart [this message]
2022-12-05 8:03 ` [PATCH kms++ v2 4/4] kms++util: Add Y21x drawing support Tomi Valkeinen
2022-12-05 8:17 ` Laurent Pinchart
2022-12-05 8:24 ` Tomi Valkeinen
2022-12-05 8:34 ` Geert Uytterhoeven
2022-12-05 8:43 ` Tomi Valkeinen
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=Y42pKde1E+FzeL9P@pendragon.ideasonboard.com \
--to=laurent.pinchart@ideasonboard.com \
--cc=kieran.bingham@ideasonboard.com \
--cc=linux-renesas-soc@vger.kernel.org \
--cc=tomi.valkeinen+renesas@ideasonboard.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.