summaryrefslogtreecommitdiffstats
path: root/include/linux
diff options
context:
space:
mode:
authorAhmad Fatoum <a.fatoum@pengutronix.de>2023-11-22 18:29:39 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2023-11-23 15:50:35 +0100
commitdde1c3e59b88a74a2eb85e9874384936ae20cb57 (patch)
tree06fc76c2535ddae56085ef42b8888d7adb14eef7 /include/linux
parent2376924e24c003def53712d91524f8ffaa6903e7 (diff)
downloadbarebox-dde1c3e59b88a74a2eb85e9874384936ae20cb57.tar.gz
barebox-dde1c3e59b88a74a2eb85e9874384936ae20cb57.tar.xz
include: import Linux word-at-a-time.h
The Linux <linux/word-at-a-time.h> interface is used to optimize searching for bytes in strings by doing word-size comparisons. This will be used in the implementation of strscpy in a follow-up commit, so import the generic version here. A good overview on the interface is available at LWN[1]. Note that it discuss Linux v3.5. The asm-generic version imported here works also on little-endian and not only big-endian[2]. [1]: https://lwn.net/Articles/501492/ [2]: Linux kernel commit a6e2f029ae34 ("Make asm/word-at-a-time.h available on all architectures"). Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20231122172951.376531-9-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'include/linux')
-rw-r--r--include/linux/kernel.h8
1 files changed, 8 insertions, 0 deletions
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index da6121888e..4e50f60751 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -11,6 +11,14 @@
#include <linux/instruction_pointer.h>
#include <linux/minmax.h>
+/**
+ * REPEAT_BYTE - repeat the value @x multiple times as an unsigned long value
+ * @x: value to repeat
+ *
+ * NOTE: @x is not checked for > 0xff; larger values produce odd results.
+ */
+#define REPEAT_BYTE(x) ((~0ul / 0xff) * (x))
+
#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a) - 1)
#define ALIGN_DOWN(x, a) ALIGN((x) - ((a) - 1), (a))
#define __ALIGN_MASK(x, mask) (((x) + (mask)) & ~(mask))