[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240214155408.1569-1-michal.wajdeczko@intel.com>
Date: Wed, 14 Feb 2024 16:54:08 +0100
From: Michal Wajdeczko <michal.wajdeczko@...el.com>
To: linux-kernel@...r.kernel.org
Cc: Michal Wajdeczko <michal.wajdeczko@...el.com>,
Andy Shevchenko <andriy.shevchenko@...ux.intel.com>,
Rodrigo Vivi <rodrigo.vivi@...el.com>,
Jani Nikula <jani.nikula@...el.com>
Subject: [RFC] include/linux/make_type.h: Helpers for making u16/u32/u64 values
It is quite common practice to make u16, u32 or u64 values from
smaller words. Add simple helpers for that.
Signed-off-by: Michal Wajdeczko <michal.wajdeczko@...el.com>
Cc: Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
Cc: Rodrigo Vivi <rodrigo.vivi@...el.com>
Cc: Jani Nikula <jani.nikula@...el.com>
---
include/linux/make_type.h | 29 +++++++++++++++++++++++++++++
1 file changed, 29 insertions(+)
create mode 100644 include/linux/make_type.h
diff --git a/include/linux/make_type.h b/include/linux/make_type.h
new file mode 100644
index 000000000000..60e2e091ea3c
--- /dev/null
+++ b/include/linux/make_type.h
@@ -0,0 +1,29 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifndef _LINUX_MAKE_TYPE_H
+#define _LINUX_MAKE_TYPE_H
+
+#include <linux/types.h>
+
+/**
+ * make_u16 - make u16 value from two u8 values
+ * @hi__: value representing upper 8 bits
+ * @lo__: value representing lower 8 bits
+ */
+#define make_u16(hi__, lo__) ((u16)(u8)(hi__) << 8 | (u8)(lo__))
+
+/**
+ * make_u32 - make u32 value from two u16 values
+ * @hi__: value representing upper 16 bits
+ * @lo__: value representing lower 16 bits
+ */
+#define make_u32(hi__, lo__) ((u32)(u16)(hi__) << 16 | (u16)(lo__))
+
+/**
+ * make_u64 - make u64 value from two u32 values
+ * @hi__: value representing upper 32 bits
+ * @lo__: value representing lower 32 bits
+ */
+#define make_u64(hi__, lo__) ((u64)(hi__) << 32 | (u32)(lo__))
+
+#endif
--
2.43.0
Powered by blists - more mailing lists