diff options
author | Chris Metcalf <cmetcalf@tilera.com> | 2011-05-04 14:38:26 -0400 |
---|---|---|
committer | Chris Metcalf <cmetcalf@tilera.com> | 2011-05-12 15:52:12 -0400 |
commit | 18aecc2b645bbb07851b196452a2af314222069b (patch) | |
tree | 959f765f69af01046c6e26db12b45c3390799d3e /arch/tile/lib/memchr_64.c | |
parent | be84cb43833ee40a42e08f5425d20310f16229c7 (diff) |
arch/tile: finish enabling support for TILE-Gx 64-bit chip
This support was partially present in the existing code (look for
"__tilegx__" ifdefs) but with this change you can build a working
kernel using the TILE-Gx toolchain and ARCH=tilegx.
Most of these files are new, generally adding a foo_64.c file
where previously there was just a foo_32.c file.
The ARCH=tilegx directive redirects to arch/tile, not arch/tilegx,
using the existing SRCARCH mechanism in the top-level Makefile.
Changes to existing files:
- <asm/bitops.h> and <asm/bitops_32.h> changed to factor the
include of <asm-generic/bitops/non-atomic.h> in the common header.
- <asm/compat.h> and arch/tile/kernel/compat.c changed to remove
the "const" markers I had put on compat_sys_execve() when trying
to match some recent similar changes to the non-compat execve.
It turns out the compat version wasn't "upgraded" to use const.
- <asm/opcode-tile_64.h> and <asm/opcode_constants_64.h> were
previously included accidentally, with the 32-bit contents. Now
they have the proper 64-bit contents.
Finally, I had to hack the existing hacky drivers/input/input-compat.h
to add yet another "#ifdef" for INPUT_COMPAT_TEST (same as x86_64).
Signed-off-by: Chris Metcalf <cmetcalf@tilera.com>
Acked-by: Dmitry Torokhov <dmitry.torokhov@gmail.com> [drivers/input]
Diffstat (limited to 'arch/tile/lib/memchr_64.c')
-rw-r--r-- | arch/tile/lib/memchr_64.c | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/arch/tile/lib/memchr_64.c b/arch/tile/lib/memchr_64.c new file mode 100644 index 000000000000..84fdc8d8e735 --- /dev/null +++ b/arch/tile/lib/memchr_64.c | |||
@@ -0,0 +1,71 @@ | |||
1 | /* | ||
2 | * Copyright 2011 Tilera Corporation. All Rights Reserved. | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or | ||
5 | * modify it under the terms of the GNU General Public License | ||
6 | * as published by the Free Software Foundation, version 2. | ||
7 | * | ||
8 | * This program is distributed in the hope that it will be useful, but | ||
9 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or | ||
11 | * NON INFRINGEMENT. See the GNU General Public License for | ||
12 | * more details. | ||
13 | */ | ||
14 | |||
15 | #include <linux/types.h> | ||
16 | #include <linux/string.h> | ||
17 | #include <linux/module.h> | ||
18 | |||
19 | void *memchr(const void *s, int c, size_t n) | ||
20 | { | ||
21 | const uint64_t *last_word_ptr; | ||
22 | const uint64_t *p; | ||
23 | const char *last_byte_ptr; | ||
24 | uintptr_t s_int; | ||
25 | uint64_t goal, before_mask, v, bits; | ||
26 | char *ret; | ||
27 | |||
28 | if (__builtin_expect(n == 0, 0)) { | ||
29 | /* Don't dereference any memory if the array is empty. */ | ||
30 | return NULL; | ||
31 | } | ||
32 | |||
33 | /* Get an aligned pointer. */ | ||
34 | s_int = (uintptr_t) s; | ||
35 | p = (const uint64_t *)(s_int & -8); | ||
36 | |||
37 | /* Create eight copies of the byte for which we are looking. */ | ||
38 | goal = 0x0101010101010101ULL * (uint8_t) c; | ||
39 | |||
40 | /* Read the first word, but munge it so that bytes before the array | ||
41 | * will not match goal. | ||
42 | * | ||
43 | * Note that this shift count expression works because we know | ||
44 | * shift counts are taken mod 64. | ||
45 | */ | ||
46 | before_mask = (1ULL << (s_int << 3)) - 1; | ||
47 | v = (*p | before_mask) ^ (goal & before_mask); | ||
48 | |||
49 | /* Compute the address of the last byte. */ | ||
50 | last_byte_ptr = (const char *)s + n - 1; | ||
51 | |||
52 | /* Compute the address of the word containing the last byte. */ | ||
53 | last_word_ptr = (const uint64_t *)((uintptr_t) last_byte_ptr & -8); | ||
54 | |||
55 | while ((bits = __insn_v1cmpeq(v, goal)) == 0) { | ||
56 | if (__builtin_expect(p == last_word_ptr, 0)) { | ||
57 | /* We already read the last word in the array, | ||
58 | * so give up. | ||
59 | */ | ||
60 | return NULL; | ||
61 | } | ||
62 | v = *++p; | ||
63 | } | ||
64 | |||
65 | /* We found a match, but it might be in a byte past the end | ||
66 | * of the array. | ||
67 | */ | ||
68 | ret = ((char *)p) + (__insn_ctz(bits) >> 3); | ||
69 | return (ret <= last_byte_ptr) ? ret : NULL; | ||
70 | } | ||
71 | EXPORT_SYMBOL(memchr); | ||