csky: Add C based string functions
Subsystems (2)
[email protected]
maintainerPATCH 1/1 csky: Add C based string functions
From: Matteo Croce <[email protected]>
Try to access RAM with the largest bit width possible, but without doing unaligned accesses.
A further improvement could be to use multiple read and writes as the assembly version was trying to do.
Tested on a BeagleV Starlight with a SiFive U74 core, where the improvement is noticeable.
--- arch/csky/Kconfig | 8 + arch/csky/abiv1/Makefile | 1 - arch/csky/abiv1/memcpy.S | 347 --------------------------------------- arch/csky/abiv2/Makefile | 2 + arch/csky/lib/Makefile | 3 + arch/csky/lib/string.c | 143 ++++++++++++++++ 6 files changed, 156 insertions(+), 348 deletions(-) delete mode 100644 arch/csky/abiv1/memcpy.S create mode 100644 arch/csky/lib/string.c
arch/csky/Kconfig +8 -0
@@ -320,6 +320,14 @@ config HOTPLUG_CPU controlled through /sys/devices/system/cpu/cpu1/hotplug/target. Say N if you want to disable CPU hotplug. + +config HAVE_EFFICIENT_UNALIGNED_ACCESS + bool "Enable EFFICIENT_UNALIGNED_ACCESS for abiv2" + depends on CPU_CK807 || CPU_CK810 || CPU_CK860 + help + Say Y here to enable EFFICIENT_UNALIGNED_ACCESS. Some CPU models could + deal with unaligned access by hardware. + endmenu source "arch/csky/Kconfig.platforms"
arch/csky/abiv1/Makefile +0 -1
@@ -4,5 +4,4 @@ obj-y += bswapdi.o obj-y += bswapsi.o obj-y += cacheflush.o obj-y += mmap.o -obj-y += memcpy.o obj-y += strksyms.o
arch/csky/abiv1/memcpy.S deleted +0 -347
347 lines not on this page · raw message
arch/csky/abiv2/Makefile +2 -0
@@ -2,9 +2,11 @@ obj-y += cacheflush.o obj-$(CONFIG_CPU_HAS_FPU) += fpu.o obj-y += memcmp.o +ifeq ($(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS), y) obj-y += memcpy.o obj-y += memmove.o obj-y += memset.o +endif obj-y += strcmp.o obj-y += strcpy.o obj-y += strlen.o
arch/csky/lib/Makefile +3 -0
@@ -1,3 +1,6 @@ # SPDX-License-Identifier: GPL-2.0-only lib-y := usercopy.o delay.o obj-$(CONFIG_FUNCTION_ERROR_INJECTION) += error-inject.o +ifneq ($(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS), y) +lib-y += string.o +endif
arch/csky/lib/string.c new file +143 -0
143 lines not on this page · raw message
Signature · 1 line
2.25.1
kernel test robot
build botThank you for the patch! Perhaps something to improve:
Hi,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on soc/for-next]
[also build test WARNING on linus/master linux/master v5.18-rc1 next-20220404] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/intel-lab-lkp/linux/commits/guoren-kernel-org/csky-Add-C-based-string-functions/20220404-222518 base: https://git.kernel.org/pub/scm/linux/kernel/git/soc/soc.git for-next config: csky-defconfig (https://download.01.org/0day-ci/archive/20220405/[email protected]/config) compiler: csky-linux-gcc (GCC) 11.2.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/e8231df5e8121c094f8668e0c850381873aa4249
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review guoren-kernel-org/csky-Add-C-based-string-functions/20220404-222518 git checkout e8231df5e8121c094f8668e0c850381873aa4249
# save the config file to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=csky SHELL=/bin/bash
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
>> arch/csky/lib/string.c:30:7: warning: no previous prototype for '__memcpy' [-Wmissing-prototypes]
30 | void *__memcpy(void *dest, const void *src, size_t count)
| ^~~~~~~~
>> arch/csky/lib/string.c:94:7: warning: no previous prototype for '__memmove' [-Wmissing-prototypes]
94 | void *__memmove(void *dest, const void *src, size_t count)
| ^~~~~~~~~
>> arch/csky/lib/string.c:113:7: warning: no previous prototype for '__memset' [-Wmissing-prototypes]
113 | void *__memset(void *s, int c, size_t count)
| ^~~~~~~~vim +/__memcpy +30 arch/csky/lib/string.c
29
> 30 void *__memcpy(void *dest, const void *src, size_t count)
31 {
32 union const_types s = { .as_u8 = src };
33 union types d = { .as_u8 = dest };
34 int distance = 0;
35
36 if (count < MIN_THRESHOLD)
37 goto copy_remainder;
38
39 /* Copy a byte at time until destination is aligned. */
40 for (; d.as_uptr & WORD_MASK; count--)
41 *d.as_u8++ = *s.as_u8++;
42
43 distance = s.as_uptr & WORD_MASK;
44
45 if (distance) {
46 unsigned long last, next;
47
48 /*
49 * s is distance bytes ahead of d, and d just reached
50 * the alignment boundary. Move s backward to word align it
51 * and shift data to compensate for distance, in order to do
52 * word-by-word copy.
53 */
54 s.as_u8 -= distance;
55
56 next = s.as_ulong[0];
57 for (; count >= BYTES_LONG; count -= BYTES_LONG) {
58 last = next;
59 next = s.as_ulong[1];
60
61 d.as_ulong[0] = last >> (distance * 8) |
62 next << ((BYTES_LONG - distance) * 8);
63
64 d.as_ulong++;
65 s.as_ulong++;
66 }
67
68 /* Restore s with the original offset. */
69 s.as_u8 += distance;
70 } else {
71 /*
72 * If the source and dest lower bits are the same, do a simple
73 * 32/64 bit wide copy.
74 */
75 for (; count >= BYTES_LONG; count -= BYTES_LONG)
76 *d.as_ulong++ = *s.as_ulong++;
77 }
78
79 copy_remainder:
80 while (count--)
81 *d.as_u8++ = *s.as_u8++;
82
83 return dest;
84 }
85 EXPORT_SYMBOL(__memcpy);
86
87 void *memcpy(void *dest, const void *src, size_t count) __weak __alias(__memcpy);
88 EXPORT_SYMBOL(memcpy);
89
90 /*
91 * Simply check if the buffer overlaps an call memcpy() in case,
92 * otherwise do a simple one byte at time backward copy.
93 */
> 94 void *__memmove(void *dest, const void *src, size_t count)
95 {
96 if (dest < src || src + count <= dest)
97 return memcpy(dest, src, count);
98
99 if (dest > src) {
100 const char *s = src + count;
101 char *tmp = dest + count;
102
103 while (count--)
104 *--tmp = *--s;
105 }
106 return dest;
107 }
108 EXPORT_SYMBOL(__memmove);
109
110 void *memmove(void *dest, const void *src, size_t count) __weak __alias(__memmove);
111 EXPORT_SYMBOL(memmove);
112
> 113 void *__memset(void *s, int c, size_t count) 114 {
115 union types dest = { .as_u8 = s };
116
117 if (count >= MIN_THRESHOLD) {
118 unsigned long cu = (unsigned long)c;
119
120 /* Compose an ulong with 'c' repeated 4/8 times */
121 cu |= cu << 8;
122 cu |= cu << 16;
123 /* Suppress warning on 32 bit machines */
124 cu |= (cu << 16) << 16;
125
126 for (; count && dest.as_uptr & WORD_MASK; count--)
127 *dest.as_u8++ = c;
128
129 /* Copy using the largest size allowed */
130 for (; count >= BYTES_LONG; count -= BYTES_LONG)
131 *dest.as_ulong++ = cu;
132 }
133
134 /* copy the remainder */
135 while (count--)
136 *dest.as_u8++ = c;
137
138 return s;
139 }
140 EXPORT_SYMBOL(__memset);
141
Signature · 2 lines
0-DAY CI Kernel Test Service https://01.org/lkp