summaryrefslogtreecommitdiff
path: root/arch/tile/include/asm/word-at-a-time.h
diff options
context:
space:
mode:
authorChris Metcalf <cmetcalf@ezchip.com>2015-04-30 19:12:42 (GMT)
committerChris Metcalf <cmetcalf@ezchip.com>2015-04-30 19:23:37 (GMT)
commit5bf6c07a1843813d0065feaaecba622d49148d7e (patch)
tree18118d48ffe123ce6f6d3eaa67dba135adafbc1a /arch/tile/include/asm/word-at-a-time.h
parent627ae54854edfbf29d5997015c190de22eef497f (diff)
downloadlinux-5bf6c07a1843813d0065feaaecba622d49148d7e.tar.xz
tile: add <asm/word-at-a-time.h> and enable support functions
This change enables the generic strncpy_from_user() and strnlen_user() using word-at-a-time.h. The tile implementation is trivial since both tilepro and tilegx have SIMD operations that do byte-wise comparisons against immediate zero for each byte, and return an 0x01 byte in each position where there is a 0x00 byte. Signed-off-by: Chris Metcalf <cmetcalf@ezchip.com>
Diffstat (limited to 'arch/tile/include/asm/word-at-a-time.h')
-rw-r--r--arch/tile/include/asm/word-at-a-time.h36
1 files changed, 36 insertions, 0 deletions
diff --git a/arch/tile/include/asm/word-at-a-time.h b/arch/tile/include/asm/word-at-a-time.h
new file mode 100644
index 0000000..9e5ce0d
--- /dev/null
+++ b/arch/tile/include/asm/word-at-a-time.h
@@ -0,0 +1,36 @@
+#ifndef _ASM_WORD_AT_A_TIME_H
+#define _ASM_WORD_AT_A_TIME_H
+
+#include <asm/byteorder.h>
+
+struct word_at_a_time { /* unused */ };
+#define WORD_AT_A_TIME_CONSTANTS {}
+
+/* Generate 0x01 byte values for non-zero bytes using a SIMD instruction. */
+static inline unsigned long has_zero(unsigned long val, unsigned long *data,
+ const struct word_at_a_time *c)
+{
+#ifdef __tilegx__
+ unsigned long mask = __insn_v1cmpeqi(val, 0);
+#else /* tilepro */
+ unsigned long mask = __insn_seqib(val, 0);
+#endif
+ *data = mask;
+ return mask;
+}
+
+/* These operations are both nops. */
+#define prep_zero_mask(val, data, c) (data)
+#define create_zero_mask(data) (data)
+
+/* And this operation just depends on endianness. */
+static inline long find_zero(unsigned long mask)
+{
+#ifdef __BIG_ENDIAN
+ return __builtin_clzl(mask) >> 3;
+#else
+ return __builtin_ctzl(mask) >> 3;
+#endif
+}
+
+#endif /* _ASM_WORD_AT_A_TIME_H */