]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
fix 64 bit upper/lower
authorAnthony Minessale <anthm@freeswitch.org>
Tue, 8 Jan 2013 20:48:16 +0000 (14:48 -0600)
committerAnthony Minessale <anthm@freeswitch.org>
Tue, 8 Jan 2013 20:48:16 +0000 (14:48 -0600)
src/include/switch_utils.h

index 485d7c3495b2e05934ffc740e8ac2dff785231bd..11839ee660424d32a809637cf540d7f703fff6a5 100644 (file)
@@ -47,10 +47,10 @@ SWITCH_BEGIN_EXTERN_C
 */
 static inline uint32_t switch_toupper(uint32_t eax)
 {
-       uint32_t ebx = (0x7f7f7f7ful & eax) + 0x05050505ul;
-       ebx = (0x7f7f7f7ful & ebx) + 0x1a1a1a1aul;
      ebx = ((ebx & ~eax) >> 2 ) & 0x20202020ul;
      return eax - ebx;
+uint32_t ebx = (0x7f7f7f7ful & eax) + 0x05050505ul;
+ebx = (0x7f7f7f7ful & ebx) + 0x1a1a1a1aul;
+ ebx = ((ebx & ~eax) >> 2 ) & 0x20202020ul;
+ return eax - ebx;
 }
 
 /* https://code.google.com/p/stringencoders/wiki/PerformanceAscii 
@@ -64,8 +64,31 @@ static inline uint32_t switch_tolower(uint32_t eax)
        return eax + ebx;
 }
 
+
 #ifdef FS_64BIT
 
+/* https://code.google.com/p/stringencoders/wiki/PerformanceAscii 
+   http://www.azillionmonkeys.com/qed/asmexample.html
+*/
+static inline uint64_t switch_toupper64(uint64_t eax)
+{
+uint64_t ebx = (0x7f7f7f7f7f7f7f7full & eax) + 0x0505050505050505ull;
+ ebx = (0x7f7f7f7f7f7f7f7full & ebx) + 0x1a1a1a1a1a1a1a1aull;
+ ebx = ((ebx & ~eax) >> 2 ) & 0x2020202020202020ull;
+ return eax - ebx;
+}
+
+/* https://code.google.com/p/stringencoders/wiki/PerformanceAscii 
+   http://www.azillionmonkeys.com/qed/asmexample.html
+*/
+static inline uint64_t switch_tolower64(uint64_t eax)
+{
+       uint64_t ebx = (0x7f7f7f7f7f7f7f7full & eax) + 0x2525252525252525ull;
+       ebx = (0x7f7f7f7f7f7f7f7full & ebx) + 0x1a1a1a1a1a1a1a1aull;
+       ebx = ((ebx & ~eax) >> 2)  & 0x2020202020202020ull;
+       return eax + ebx;
+}
+
 static inline void switch_toupper_max(char *s)
 {
        uint64_t *b,*p;
@@ -78,7 +101,7 @@ static inline void switch_toupper_max(char *s)
 
        while (l > 8) {
                b = p;
-               *b = (uint32_t) switch_toupper(*b);
+               *b = (uint64_t) switch_toupper64(*b);
                b++;
                p++;
                l -= 8;
@@ -106,7 +129,7 @@ static inline void switch_tolower_max(char *s)
 
        while (l > 8) {
                b = p;
-               *b = (uint32_t) switch_tolower(*b);
+               *b = (uint64_t) switch_tolower64(*b);
                b++;
                p++;
                l -= 8;
@@ -182,6 +205,8 @@ static inline void switch_tolower_max(char *s)
 #endif
 
 
+
+
 SWITCH_DECLARE(int) old_switch_toupper(int c);
 SWITCH_DECLARE(int) old_switch_tolower(int c);
 SWITCH_DECLARE(int) switch_isalnum(int c);