fix 64 bit upper/lower

This commit is contained in:
Anthony Minessale 2013-01-08 14:48:16 -06:00
parent 11a7f42459
commit 8e892abdef
1 changed files with 31 additions and 6 deletions

View 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);