Skip to content

Commit fb4cac5

Browse files
rhvgoyalH. Peter Anvin
authored andcommitted
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>
1 parent 820e8fe commit fb4cac5

4 files changed

Lines changed: 16 additions & 19 deletions

File tree

‎arch/x86/boot/boot.h‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -177,14 +177,6 @@ static inline void wrgs32(u32 v, addr_t addr)
177177
}
178178

179179
/* 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-
188180
static inline int memcmp_fs(const void *s1, addr_t s2, size_t len)
189181
{
190182
u8 diff;

‎arch/x86/boot/compressed/string.c‎

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,4 @@
11
#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-
132
#include "../string.c"
143

154
/* misc.h might pull in string_32.h which has a macro for memcpy. undef that */

‎arch/x86/boot/string.c‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,20 @@
1414

1515
#include "boot.h"
1616

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+
1731
int strcmp(const char *str1, const char *str2)
1832
{
1933
const unsigned char *s1 = (const unsigned char *)str1;

‎arch/x86/boot/string.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88

99
void *memcpy(void *dst, const void *src, size_t len);
1010
void *memset(void *dst, int c, size_t len);
11+
int memcmp(const void *s1, const void *s2, size_t len);
1112

1213
/*
1314
* Access builtin version by default. If one needs to use optimized version,
1415
* do "undef memcpy" in .c file and link against right string.c
1516
*/
1617
#define memcpy(d,s,l) __builtin_memcpy(d,s,l)
1718
#define memset(d,c,l) __builtin_memset(d,c,l)
19+
#define memcmp __builtin_memcmp
1820

1921
#endif /* BOOT_STRING_H */

0 commit comments

Comments
 (0)