OpenWrt – Blame information for rev 2
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | From: Felix Fietkau <nbd@nbd.name> |
2 | Subject: [PATCH] mips: allow the compiler to optimize memset, memcmp, memcpy for better performance and (in some instances) smaller code |
||
3 | |||
4 | lede-commit: 07e59c7bc7f375f792ec9734be42fe4fa391a8bb |
||
5 | Signed-off-by: Felix Fietkau <nbd@nbd.name> |
||
6 | --- |
||
7 | arch/mips/boot/compressed/Makefile | 3 ++- |
||
8 | arch/mips/include/asm/string.h | 38 ++++++++++++++++++++++++++++++++++++++ |
||
9 | arch/mips/lib/Makefile | 2 +- |
||
10 | arch/mips/lib/memcmp.c | 22 ++++++++++++++++++++++ |
||
11 | 4 files changed, 63 insertions(+), 2 deletions(-) |
||
12 | create mode 100644 arch/mips/lib/memcmp.c |
||
13 | |||
14 | --- a/arch/mips/boot/compressed/Makefile |
||
15 | +++ b/arch/mips/boot/compressed/Makefile |
||
16 | @@ -23,7 +23,8 @@ KBUILD_CFLAGS := $(filter-out -pg, $(KBU |
||
17 | KBUILD_CFLAGS := $(filter-out -fstack-protector, $(KBUILD_CFLAGS)) |
||
18 | |||
19 | KBUILD_CFLAGS := $(KBUILD_CFLAGS) -D__KERNEL__ \ |
||
20 | - -DBOOT_HEAP_SIZE=$(BOOT_HEAP_SIZE) -D"VMLINUX_LOAD_ADDRESS_ULL=$(VMLINUX_LOAD_ADDRESS)ull" |
||
21 | + -DBOOT_HEAP_SIZE=$(BOOT_HEAP_SIZE) -D"VMLINUX_LOAD_ADDRESS_ULL=$(VMLINUX_LOAD_ADDRESS)ull" \ |
||
22 | + -D__ZBOOT__ |
||
23 | |||
24 | KBUILD_AFLAGS := $(KBUILD_AFLAGS) -D__ASSEMBLY__ \ |
||
25 | -DBOOT_HEAP_SIZE=$(BOOT_HEAP_SIZE) \ |
||
26 | --- a/arch/mips/include/asm/string.h |
||
27 | +++ b/arch/mips/include/asm/string.h |
||
28 | @@ -140,4 +140,42 @@ extern void *memcpy(void *__to, __const_ |
||
29 | #define __HAVE_ARCH_MEMMOVE |
||
30 | extern void *memmove(void *__dest, __const__ void *__src, size_t __n); |
||
31 | |||
32 | +#ifndef __ZBOOT__ |
||
33 | +#define memset(__s, __c, len) \ |
||
34 | +({ \ |
||
35 | + size_t __len = (len); \ |
||
36 | + void *__ret; \ |
||
37 | + if (__builtin_constant_p(len) && __len >= 64) \ |
||
38 | + __ret = memset((__s), (__c), __len); \ |
||
39 | + else \ |
||
40 | + __ret = __builtin_memset((__s), (__c), __len); \ |
||
41 | + __ret; \ |
||
42 | +}) |
||
43 | + |
||
44 | +#define memcpy(dst, src, len) \ |
||
45 | +({ \ |
||
46 | + size_t __len = (len); \ |
||
47 | + void *__ret; \ |
||
48 | + if (__builtin_constant_p(len) && __len >= 64) \ |
||
49 | + __ret = memcpy((dst), (src), __len); \ |
||
50 | + else \ |
||
51 | + __ret = __builtin_memcpy((dst), (src), __len); \ |
||
52 | + __ret; \ |
||
53 | +}) |
||
54 | + |
||
55 | +#define memmove(dst, src, len) \ |
||
56 | +({ \ |
||
57 | + size_t __len = (len); \ |
||
58 | + void *__ret; \ |
||
59 | + if (__builtin_constant_p(len) && __len >= 64) \ |
||
60 | + __ret = memmove((dst), (src), __len); \ |
||
61 | + else \ |
||
62 | + __ret = __builtin_memmove((dst), (src), __len); \ |
||
63 | + __ret; \ |
||
64 | +}) |
||
65 | + |
||
66 | +#define __HAVE_ARCH_MEMCMP |
||
67 | +#define memcmp(src1, src2, len) __builtin_memcmp((src1), (src2), (len)) |
||
68 | +#endif |
||
69 | + |
||
70 | #endif /* _ASM_STRING_H */ |
||
71 | --- a/arch/mips/lib/Makefile |
||
72 | +++ b/arch/mips/lib/Makefile |
||
73 | @@ -5,7 +5,7 @@ |
||
74 | |||
75 | lib-y += bitops.o csum_partial.o delay.o memcpy.o memset.o \ |
||
76 | mips-atomic.o strncpy_user.o \ |
||
77 | - strnlen_user.o uncached.o |
||
78 | + strnlen_user.o uncached.o memcmp.o |
||
79 | |||
80 | obj-y += iomap.o iomap_copy.o |
||
81 | obj-$(CONFIG_PCI) += iomap-pci.o |
||
82 | --- /dev/null |
||
83 | +++ b/arch/mips/lib/memcmp.c |
||
84 | @@ -0,0 +1,22 @@ |
||
85 | +/* |
||
86 | + * copied from linux/lib/string.c |
||
87 | + * |
||
88 | + * Copyright (C) 1991, 1992 Linus Torvalds |
||
89 | + */ |
||
90 | + |
||
91 | +#include <linux/module.h> |
||
92 | +#include <linux/string.h> |
||
93 | + |
||
94 | +#undef memcmp |
||
95 | +int memcmp(const void *cs, const void *ct, size_t count) |
||
96 | +{ |
||
97 | + const unsigned char *su1, *su2; |
||
98 | + int res = 0; |
||
99 | + |
||
100 | + for (su1 = cs, su2 = ct; 0 < count; ++su1, ++su2, count--) |
||
101 | + if ((res = *su1 - *su2) != 0) |
||
102 | + break; |
||
103 | + return res; |
||
104 | +} |
||
105 | +EXPORT_SYMBOL(memcmp); |
||
106 | + |