[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH v2 for-next 2/2] x86/string: Use compiler __builtin_str*() where possible



The use of -fno-builtin inhibits this automatic transformation.  Manually
transform the callsites.  This causes constructs such as strlen("literal") to
be evaluated at compile time, and certain simple operations to be replaced
with repeated string operations.

Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
---
CC: Jan Beulich <JBeulich@xxxxxxxx>

v2:
 * Fix the build with Clang, which objects when the define renames the
   underlying implementation.
---
 xen/common/string.c          | 14 +++++++-------
 xen/include/asm-x86/string.h |  8 ++++++++
 2 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/xen/common/string.c b/xen/common/string.c
index 9a5a4ba..5302db0 100644
--- a/xen/common/string.c
+++ b/xen/common/string.c
@@ -42,7 +42,7 @@ int strnicmp(const char *s1, const char *s2, size_t len)
 #endif
 
 #ifndef __HAVE_ARCH_STRCASECMP
-int strcasecmp(const char *s1, const char *s2)
+int (strcasecmp)(const char *s1, const char *s2)
 {
     int c1, c2;
 
@@ -117,7 +117,7 @@ EXPORT_SYMBOL(strlcat);
  * @cs: One string
  * @ct: Another string
  */
-int strcmp(const char * cs,const char * ct)
+int (strcmp)(const char *cs, const char *ct)
 {
        register signed char __res;
 
@@ -137,7 +137,7 @@ int strcmp(const char * cs,const char * ct)
  * @ct: Another string
  * @count: The maximum number of bytes to compare
  */
-int strncmp(const char * cs,const char * ct,size_t count)
+int (strncmp)(const char *cs, const char *ct, size_t count)
 {
        register signed char __res = 0;
 
@@ -157,7 +157,7 @@ int strncmp(const char * cs,const char * ct,size_t count)
  * @s: The string to be searched
  * @c: The character to search for
  */
-char * strchr(const char * s, int c)
+char *(strchr)(const char *s, int c)
 {
        for(; *s != (char) c; ++s)
                if (*s == '\0')
@@ -172,7 +172,7 @@ char * strchr(const char * s, int c)
  * @s: The string to be searched
  * @c: The character to search for
  */
-char * strrchr(const char * s, int c)
+char *(strrchr)(const char *s, int c)
 {
        const char *p = s + strlen(s);
        do {
@@ -188,7 +188,7 @@ char * strrchr(const char * s, int c)
  * strlen - Find the length of a string
  * @s: The string to be sized
  */
-size_t strlen(const char * s)
+size_t (strlen)(const char * s)
 {
        const char *sc;
 
@@ -409,7 +409,7 @@ void * memscan(void * addr, int c, size_t size)
  * @s1: The string to be searched
  * @s2: The string to search for
  */
-char * strstr(const char * s1,const char * s2)
+char *(strstr)(const char *s1, const char *s2)
 {
        int l1, l2;
 
diff --git a/xen/include/asm-x86/string.h b/xen/include/asm-x86/string.h
index d636e82..535fc0e 100644
--- a/xen/include/asm-x86/string.h
+++ b/xen/include/asm-x86/string.h
@@ -10,4 +10,12 @@
 #define __HAVE_ARCH_MEMSET
 #define memset(s, c, n)       __builtin_memset(s, c, n)
 
+#define strcmp(s1, s2)        __builtin_strcmp(s1, s2)
+#define strncmp(s1, s2, n)    __builtin_strncmp(s1, s2, n)
+#define strcasecmp(s1, s2)    __builtin_strcasecmp(s1, s2)
+#define strchr(s1, c)         __builtin_strchr(s1, c)
+#define strrchr(s1, c)        __builtin_strrchr(s1, c)
+#define strstr(s1, s2)        __builtin_strstr(s1, s2)
+#define strlen(s1)            __builtin_strlen(s1)
+
 #endif /* __X86_STRING_H__ */
-- 
2.1.4


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
https://lists.xen.org/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.