Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

x86, boot: Move memcmp() into string.h and string.c

Try to treat memcmp() in same way as memcpy() and memset(). Provide a
declaration in boot/string.h and by default user gets a memcmp() which
maps to builtin function.

Move optimized definition of memcmp() in boot/string.c. Now a user can
do #undef memcmp and link against string.c to use optimzied memcmp().

It also simplifies boot/compressed/string.c where we had to redefine
memcmp(). That extra definition is gone now.

Signed-off-by: Vivek Goyal <vgoyal@redhat.com>
Link: http://lkml.kernel.org/r/1395170800-11059-5-git-send-email-vgoyal@redhat.com
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>

authored by

Vivek Goyal and committed by
H. Peter Anvin
fb4cac57 820e8fec

+16 -19
-8
arch/x86/boot/boot.h
··· 177 177 } 178 178 179 179 /* Note: these only return true/false, not a signed return value! */ 180 - static inline int memcmp(const void *s1, const void *s2, size_t len) 181 - { 182 - u8 diff; 183 - asm("repe; cmpsb; setnz %0" 184 - : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len)); 185 - return diff; 186 - } 187 - 188 180 static inline int memcmp_fs(const void *s1, addr_t s2, size_t len) 189 181 { 190 182 u8 diff;
-11
arch/x86/boot/compressed/string.c
··· 1 1 #include "misc.h" 2 - 3 - /* Avoid intereference from any defines in string_32.h */ 4 - #undef memcmp 5 - int memcmp(const void *s1, const void *s2, size_t len) 6 - { 7 - u8 diff; 8 - asm("repe; cmpsb; setnz %0" 9 - : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len)); 10 - return diff; 11 - } 12 - 13 2 #include "../string.c" 14 3 15 4 /* misc.h might pull in string_32.h which has a macro for memcpy. undef that */
+14
arch/x86/boot/string.c
··· 14 14 15 15 #include "boot.h" 16 16 17 + /* 18 + * This file gets included in compressed/string.c which might pull in 19 + * string_32.h and which in turn maps memcmp to __builtin_memcmp(). Undo 20 + * that first. 21 + */ 22 + #undef memcmp 23 + int memcmp(const void *s1, const void *s2, size_t len) 24 + { 25 + u8 diff; 26 + asm("repe; cmpsb; setnz %0" 27 + : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len)); 28 + return diff; 29 + } 30 + 17 31 int strcmp(const char *str1, const char *str2) 18 32 { 19 33 const unsigned char *s1 = (const unsigned char *)str1;
+2
arch/x86/boot/string.h
··· 8 8 9 9 void *memcpy(void *dst, const void *src, size_t len); 10 10 void *memset(void *dst, int c, size_t len); 11 + int memcmp(const void *s1, const void *s2, size_t len); 11 12 12 13 /* 13 14 * Access builtin version by default. If one needs to use optimized version, ··· 16 15 */ 17 16 #define memcpy(d,s,l) __builtin_memcpy(d,s,l) 18 17 #define memset(d,c,l) __builtin_memset(d,c,l) 18 + #define memcmp __builtin_memcmp 19 19 20 20 #endif /* BOOT_STRING_H */