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

[Xen-changelog] [xen master] xen/string: Use compiler __builtin_*() where possible



commit b9088aa7e8959566b9c27fb9e225b3a7efa882eb
Author:     Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
AuthorDate: Tue Aug 2 19:55:12 2016 +0000
Commit:     Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
CommitDate: Wed May 31 14:05:21 2017 +0100

    xen/string: Use compiler __builtin_*() where possible
    
    The use of -fno-builtin inhibits these automatic transformations.  This 
causes
    constructs such as strlen("literal") to be evaluated at compile time, and
    certain simple operations to be replaced with repeated string operations.
    
    To avoid the macro altering the function names, use the method recommended 
by
    the C specification by enclosing the function name in brackets to avoid the
    macro being expanded.  This means that optimisation opportunities continue 
to
    work in the rest of the translation unit.
    
    Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
    Reviewed-by: Jan Beulich <jbeulich@xxxxxxxx>
---
 xen/common/string.c      | 24 ++++++++++++------------
 xen/include/xen/string.h | 12 ++++++++++++
 2 files changed, 24 insertions(+), 12 deletions(-)

diff --git a/xen/common/string.c b/xen/common/string.c
index 9a5a4ba..1e122ab 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;
 
@@ -298,7 +298,7 @@ char * strsep(char **s, const char *ct)
  *
  * Do not use memset() to access IO space, use memset_io() instead.
  */
-void * memset(void * s,int c,size_t count)
+void *(memset)(void *s, int c, size_t count)
 {
        char *xs = (char *) s;
 
@@ -319,7 +319,7 @@ void * memset(void * s,int c,size_t count)
  * You should not use this function to access IO space, use memcpy_toio()
  * or memcpy_fromio() instead.
  */
-void * memcpy(void * dest,const void *src,size_t count)
+void *(memcpy)(void *dest, const void *src, size_t count)
 {
        char *tmp = (char *) dest, *s = (char *) src;
 
@@ -339,7 +339,7 @@ void * memcpy(void * dest,const void *src,size_t count)
  *
  * Unlike memcpy(), memmove() copes with overlapping areas.
  */
-void * memmove(void * dest,const void *src,size_t count)
+void *(memmove)(void *dest, const void *src, size_t count)
 {
        char *tmp, *s;
 
@@ -367,7 +367,7 @@ void * memmove(void * dest,const void *src,size_t count)
  * @ct: Another area of memory
  * @count: The size of the area.
  */
-int memcmp(const void * cs,const void * ct,size_t count)
+int (memcmp)(const void *cs, const void *ct, size_t count)
 {
        const unsigned char *su1, *su2;
        int res = 0;
@@ -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;
 
@@ -437,7 +437,7 @@ char * strstr(const char * s1,const char * s2)
  * returns the address of the first occurrence of @c, or %NULL
  * if @c is not found
  */
-void *memchr(const void *s, int c, size_t n)
+void *(memchr)(const void *s, int c, size_t n)
 {
        const unsigned char *p = s;
        while (n-- != 0) {
diff --git a/xen/include/xen/string.h b/xen/include/xen/string.h
index eb7aeaa..853db2f 100644
--- a/xen/include/xen/string.h
+++ b/xen/include/xen/string.h
@@ -27,10 +27,12 @@ size_t strlcat(char *, const char *, size_t);
 
 #ifndef __HAVE_ARCH_STRCMP
 int strcmp(const char *, const char *);
+#define strcmp(s1, s2) __builtin_strcmp(s1, s2)
 #endif
 
 #ifndef __HAVE_ARCH_STRNCMP
 int strncmp(const char *, const char *, size_t);
+#define strncmp(s1, s2, n) __builtin_strncmp(s1, s2, n)
 #endif
 
 #ifndef __HAVE_ARCH_STRNICMP
@@ -39,22 +41,27 @@ int strnicmp(const char *, const char *, size_t);
 
 #ifndef __HAVE_ARCH_STRCASECMP
 int strcasecmp(const char *, const char *);
+#define strcasecmp(s1, s2) __builtin_strcasecmp(s1, s2)
 #endif
 
 #ifndef __HAVE_ARCH_STRCHR
 char *strchr(const char *, int);
+#define strchr(s1, c) __builtin_strchr(s1, c)
 #endif
 
 #ifndef __HAVE_ARCH_STRRCHR
 char *strrchr(const char *, int);
+#define strrchr(s1, c) __builtin_strrchr(s1, c)
 #endif
 
 #ifndef __HAVE_ARCH_STRSTR
 char *strstr(const char *, const char *);
+#define strstr(s1, s2) __builtin_strstr(s1, s2)
 #endif
 
 #ifndef __HAVE_ARCH_STRLEN
 size_t strlen(const char *);
+#define strlen(s1) __builtin_strlen(s1)
 #endif
 
 #ifndef __HAVE_ARCH_STRNLEN
@@ -76,14 +83,17 @@ size_t strspn(const char *, const char *);
 
 #ifndef __HAVE_ARCH_MEMSET
 void *memset(void *, int, size_t);
+#define memset(s, c, n) __builtin_memset(s, c, n)
 #endif
 
 #ifndef __HAVE_ARCH_MEMCPY
 void *memcpy(void *, const void *, size_t);
+#define memcpy(d, s, n) __builtin_memcpy(d, s, n)
 #endif
 
 #ifndef __HAVE_ARCH_MEMMOVE
 void *memmove(void *, const void *, size_t);
+#define memmove(d, s, n) __builtin_memmove(d, s, n)
 #endif
 
 #ifndef __HAVE_ARCH_MEMSCAN
@@ -92,10 +102,12 @@ void *memscan(void *, int, size_t);
 
 #ifndef __HAVE_ARCH_MEMCMP
 int memcmp(const void *, const void *, size_t);
+#define memcmp(s1, s2, n) __builtin_memcmp(s1, s2, n)
 #endif
 
 #ifndef __HAVE_ARCH_MEMCHR
 void *memchr(const void *, int, size_t);
+#define memchr(s, c, n) __builtin_memchr(s, c, n)
 #endif
 
 #define is_char_array(x) __builtin_types_compatible_p(typeof(x), char[])
--
generated by git-patchbot for /home/xen/git/xen.git#master

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

 


Rackspace

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