Changeset 1174 in vbox for trunk/src/VBox/Runtime/string
- Timestamp:
- Mar 3, 2007 11:49:53 PM (18 years ago)
- Location:
- trunk/src/VBox/Runtime/string
- Files:
-
- 6 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/string/memcmp.asm
r1060 r1174 1 1 ; $Id$ 2 2 ;; @file 3 ; InnoTek Portable Runtime - No-CRT memc py- AMD64 & X86.3 ; InnoTek Portable Runtime - No-CRT memcmp - AMD64 & X86. 4 4 ; 5 5 … … 22 22 %include "iprt/asmdefs.mac" 23 23 24 BEGINCODE 25 24 26 ;; 25 ; @param pv Dstgcc: rdi msc: rcx x86:[esp+4]26 ; @param pv Srcgcc: rsi msc: rdx x86:[esp+8]27 ; @param pv1 gcc: rdi msc: rcx x86:[esp+4] 28 ; @param pv2 gcc: rsi msc: rdx x86:[esp+8] 27 29 ; @param cb gcc: rdx msc: r8 x86:[esp+0ch] 28 BEGINPROC RT_NOCRT(memc py)30 BEGINPROC RT_NOCRT(memcmp) 29 31 cld 30 32 … … 43 45 mov rax, rdi ; save the return value 44 46 shr rcx, 3 45 rep movsq 47 repe cmpsq 48 jne .not_equal_qword 46 49 %else 47 50 push edi … … 52 55 mov esi, [esp + 08h + 8] 53 56 mov edx, ecx 54 mov eax, edi ; save the return value 55 shl ecx, 2 56 rep movsd 57 xor eax, eax 58 jecxz .done 59 shr ecx, 2 60 repe cmpsd 61 jne .not_equal_dword 57 62 %endif 58 63 … … 60 65 %ifdef __AMD64__ 61 66 test dl, 4 62 jz .dont_move_dword 63 movsd 67 jz .dont_cmp_dword 68 cmpsd 69 jne .not_equal_dword 64 70 %endif 65 .dont_ move_dword:71 .dont_cmp_dword: 66 72 test dl, 2 67 jz .dont_move_word 68 movsw 69 .dont_move_word: 73 jz .dont_cmp_word 74 cmpsw 75 jne .not_equal_word 76 .dont_cmp_word: 70 77 test dl, 1 71 jz .dont_move_byte 72 movsb 73 .dont_move_byte: 78 jz .dont_cmp_byte 79 cmpsb 80 jne .not_equal_byte 81 .dont_cmp_byte: 74 82 83 .done: 75 84 %ifdef __AMD64__ 76 85 %ifdef ASM_CALL64_MSC … … 83 92 %endif 84 93 ret 85 ENDPROC RT_NOCRT(memcpy)86 94 95 ; 96 ; Mismatches. 97 ; 98 %ifdef __AMD64__ 99 .not_equal_qword: 100 mov ecx, 8 101 sub rsi, 8 102 sub rdi, 8 103 .not_equal_byte: 104 repe cmpsb 105 mov al, [xDI-1] 106 movzx ecx, byte [xSI-1] 107 sub eax, ecx 108 jmp .done 109 %endif 110 111 .not_equal_dword: 112 mov ecx, 4 113 sub xSI, 4 114 sub xDI, 4 115 repe cmpsb 116 %ifdef __AMD64__ 117 jmp .not_equal_byte 118 %else 119 .not_equal_byte: 120 mov al, [xDI-1] 121 movzx ecx, byte [xSI-1] 122 sub eax, ecx 123 jmp .done 124 %endif 125 126 .not_equal_word: 127 mov ecx, 2 128 sub xSI, 2 129 sub xDI, 2 130 repe cmpsb 131 jmp .not_equal_byte 132 ENDPROC RT_NOCRT(memcmp) 133 -
trunk/src/VBox/Runtime/string/memcmp_alias.c
r1060 r1174 1 /* $Id: memc py.cpp 17216 2007-01-10 16:40:30Z bird $ */1 /* $Id: memcmp.cpp 17216 2007-01-10 16:40:30Z bird $ */ 2 2 /** @file 3 * InnoTek Portable Runtime - No-CRT memc py() alias for gcc.3 * InnoTek Portable Runtime - No-CRT memcmp() alias for gcc. 4 4 */ 5 5 … … 25 25 *******************************************************************************/ 26 26 #include <iprt/nocrt/string.h> 27 #undef memc py27 #undef memcmp 28 28 29 29 #if defined(__DARWIN__) || defined(__WIN__) 30 30 # ifndef __MINGW32__ 31 # pragma weak memc py31 # pragma weak memcmp 32 32 # endif 33 33 34 34 /* No alias support here (yet in the ming case). */ 35 extern void *(memcpy)(void *pvDst, const void *pvSrc, size_t cb)35 extern int (memcmp)(const void *pv1, const void *pv2, size_t cb) 36 36 { 37 return RT_NOCRT(memc py)(pvDst, pvSrc, cb);37 return RT_NOCRT(memcmp)(pv1, pv2, cb); 38 38 } 39 39 40 40 #elif __GNUC__ >= 4 41 41 /* create a weak alias. */ 42 __asm__(".weak memc py\t\n"43 " .set memc py," RT_NOCRT_STR(memcpy) "\t\n");42 __asm__(".weak memcmp\t\n" 43 " .set memcmp," RT_NOCRT_STR(memcmp) "\t\n"); 44 44 #else 45 45 /* create a weak alias. */ 46 extern __typeof(RT_NOCRT(memc py)) memcpy __attribute__((weak, alias(RT_NOCRT_STR(memcpy))));46 extern __typeof(RT_NOCRT(memcmp)) memcmp __attribute__((weak, alias(RT_NOCRT_STR(memcmp)))); 47 47 #endif 48 48 -
trunk/src/VBox/Runtime/string/strchr.asm
r1060 r1174 1 1 ; $Id$ 2 2 ;; @file 3 ; InnoTek Portable Runtime - No-CRT memchr - AMD64 & X86.3 ; InnoTek Portable Runtime - No-CRT strchr - AMD64 & X86. 4 4 ; 5 5 … … 22 22 %include "iprt/asmdefs.mac" 23 23 24 BEGINCODE 25 24 26 ;; 25 ; @param p v gcc: rdi msc: ecx x86:[esp+4]27 ; @param psz gcc: rdi msc: rcx x86:[esp+4] 26 28 ; @param ch gcc: esi msc: edx x86:[esp+8] 27 ; @param cb gcc: rdx msc: r8 x86:[esp+0ch] 28 BEGINPROC RT_NOCRT(memchr) 29 BEGINPROC RT_NOCRT(strchr) 29 30 cld 31 32 ; check for ch == 0 and setup normal strchr. 30 33 %ifdef __AMD64__ 31 34 %ifdef ASM_CALL64_MSC 32 or r8, r8 33 jz .not_found_early 34 35 mov r9, rdi ; save rdi 36 mov eax, edx 37 mov rdi, rcx 38 mov rcx, r8 35 or dl, dl 36 jz near .strlen 37 mov r9, rsi ; save rsi 38 mov rsi, rcx 39 39 %else 40 mov rcx, rdx41 j rcxz .not_found_early42 43 mov eax, esi40 or sil, sil 41 jz near .strlen 42 mov edx, esi 43 mov rsi, rdi 44 44 %endif 45 46 45 %else 47 mov e cx, [esp + 0ch]48 jecxz .not_found_early49 mov edx, edi ; save edi50 mov e ax, [esp + 8]51 mov e di, [esp + 4]46 mov edx, [esp + 8] 47 or dl, dl 48 jz near .strlen 49 mov ecx, esi ; save esi 50 mov esi, [esp + 4] 52 51 %endif 53 52 54 53 ; do the search 55 repne scasb 56 jne .not_found 54 .next: 55 lodsb 56 cmp al, dl 57 je .found 58 test al, al 59 jz .not_found 57 60 58 ; found it 61 lodsb 62 cmp al, dl 63 je .found 64 test al, al 65 jz .not_found 66 67 lodsb 68 cmp al, dl 69 je .found 70 test al, al 71 jz .not_found 72 73 lodsb 74 cmp al, dl 75 je .found 76 test al, al 77 jz .not_found 78 jmp .next 79 80 .found: 81 lea xAX, [xSI - 1] 82 %ifdef ASM_CALL64_MSC 83 mov rsi, r9 84 %endif 85 %ifdef __X86__ 86 mov esi, ecx 87 %endif 88 ret 89 90 .not_found: 91 %ifdef ASM_CALL64_MSC 92 mov rsi, r9 93 %endif 94 %ifdef __X86__ 95 mov esi, ecx 96 %endif 97 xor eax, eax 98 ret 99 100 ; 101 ; Special case: strchr(str, '\0'); 102 ; 103 align 16 104 .strlen: 105 %ifdef __AMD64__ 106 %ifdef ASM_CALL64_MSC 107 mov r9, rdi ; save rdi 108 mov rdi, rcx 109 %endif 110 %else 111 mov edx, edi ; save edi 112 mov edi, [esp + 4] 113 %endif 114 mov xCX, -1 115 xor eax, eax 116 repne scasb 117 59 118 lea xAX, [xDI - 1] 60 119 %ifdef ASM_CALL64_MSC … … 65 124 %endif 66 125 ret 126 ENDPROC RT_NOCRT(strchr) 67 127 68 .not_found:69 %ifdef ASM_CALL64_MSC70 mov rdi, r971 %endif72 %ifdef __X86__73 mov edi, edx74 %endif75 .not_found_early:76 xor eax, eax77 ret78 ENDPROC RT_NOCRT(memchr)79 -
trunk/src/VBox/Runtime/string/strchr_alias.c
r1060 r1174 1 1 /* $Id: $ */ 2 2 /** @file 3 * InnoTek Portable Runtime - No-CRT memchr() alias for gcc.3 * InnoTek Portable Runtime - No-CRT strchr() alias for gcc. 4 4 */ 5 5 … … 25 25 *******************************************************************************/ 26 26 #include <iprt/nocrt/string.h> 27 #undef memchr27 #undef strchr 28 28 29 29 #if defined(__DARWIN__) || defined(__WIN__) 30 30 # ifndef __MINGW32__ 31 # pragma weak memchr31 # pragma weak strchr 32 32 # endif 33 33 34 34 /* No alias support here (yet in the ming case). */ 35 extern void *(memchr)(const void *pv, int ch, size_t cb)35 extern char *(strchr)(const char *psz, int ch) 36 36 { 37 return RT_NOCRT( memchr)(pv, ch, cb);37 return RT_NOCRT(strchr)(pv, ch); 38 38 } 39 39 40 40 #elif __GNUC__ >= 4 41 41 /* create a weak alias. */ 42 __asm__(".weak memchr\t\n"43 " .set memchr," RT_NOCRT_STR(memchr) "\t\n");42 __asm__(".weak strchr\t\n" 43 " .set strchr," RT_NOCRT_STR(strchr) "\t\n"); 44 44 #else 45 45 /* create a weak alias. */ 46 extern __typeof(RT_NOCRT( memchr)) memchr __attribute__((weak, alias(RT_NOCRT_STR(memchr))));46 extern __typeof(RT_NOCRT(strchr)) strchr __attribute__((weak, alias(RT_NOCRT_STR(strchr)))); 47 47 #endif 48 48 -
trunk/src/VBox/Runtime/string/strcmp.asm
r1060 r1174 1 1 ; $Id$ 2 2 ;; @file 3 ; InnoTek Portable Runtime - No-CRT memcpy- AMD64 & X86.3 ; InnoTek Portable Runtime - No-CRT strcmp - AMD64 & X86. 4 4 ; 5 5 … … 22 22 %include "iprt/asmdefs.mac" 23 23 24 BEGINCODE 25 24 26 ;; 25 ; @param pvDst gcc: rdi msc: rcx x86:[esp+4] 26 ; @param pvSrc gcc: rsi msc: rdx x86:[esp+8] 27 ; @param cb gcc: rdx msc: r8 x86:[esp+0ch] 28 BEGINPROC RT_NOCRT(memcpy) 29 cld 30 31 ; Do the bulk of the work. 27 ; @param psz1 gcc: rdi msc: rcx x86:[esp+4] 28 ; @param psz2 gcc: rsi msc: rdx x86:[esp+8] 29 BEGINPROC RT_NOCRT(strcmp) 30 ; input 32 31 %ifdef __AMD64__ 33 32 %ifdef ASM_CALL64_MSC 34 mov r10, rdi ; save 35 mov r11, rsi ; save 36 mov rdi, rcx 37 mov rsi, rdx 38 mov rcx, r8 39 mov rdx, r8 33 %define psz1 rcx 34 %define psz2 rdx 40 35 %else 41 mov rcx, rdx 36 %define psz1 rdi 37 %define psz2 rsi 42 38 %endif 43 mov rax, rdi ; save the return value44 shr rcx, 345 rep movsq46 39 %else 47 push edi 48 push esi 49 50 mov ecx, [esp + 0ch + 8] 51 mov edi, [esp + 04h + 8] 52 mov esi, [esp + 08h + 8] 53 mov edx, ecx 54 mov eax, edi ; save the return value 55 shl ecx, 2 56 rep movsd 40 mov ecx, [esp + 4] 41 mov edx, [esp + 8] 42 %define psz1 ecx 43 %define psz2 edx 57 44 %endif 58 45 59 ; The remaining bytes. 60 %ifdef __AMD64__ 61 test dl, 4 62 jz .dont_move_dword 63 movsd 64 %endif 65 .dont_move_dword: 66 test dl, 2 67 jz .dont_move_word 68 movsw 69 .dont_move_word: 70 test dl, 1 71 jz .dont_move_byte 72 movsb 73 .dont_move_byte: 46 ; 47 ; The loop. 48 ; 49 .next: 50 mov al, [psz1] 51 mov ah, [psz2] 52 cmp al, ah 53 jne .not_equal 54 test al, al 55 jz .equal 74 56 75 %ifdef __AMD64__ 76 %ifdef ASM_CALL64_MSC 77 mov rdi, r10 78 mov rsi, r11 79 %endif 80 %else 81 pop esi 82 pop edi 83 %endif 57 mov al, [psz1 + 1] 58 mov ah, [psz2 + 1] 59 cmp al, ah 60 jne .not_equal 61 test al, al 62 jz .equal 63 inc psz1 64 inc psz2 65 66 mov al, [psz1 + 2] 67 mov ah, [psz2 + 2] 68 cmp al, ah 69 jne .not_equal 70 test al, al 71 jz .equal 72 inc psz1 73 inc psz2 74 75 mov al, [psz1 + 3] 76 mov ah, [psz2 + 3] 77 cmp al, ah 78 jne .not_equal 79 test al, al 80 jz .equal 81 82 add psz1, 4 83 add psz2, 4 84 jmp .next 85 86 .equal: 87 xor eax, eax 84 88 ret 85 ENDPROC RT_NOCRT(memcpy)86 89 90 .not_equal: 91 movzx ecx, ah 92 and eax, 0ffh 93 sub eax, ecx 94 ret 95 ENDPROC RT_NOCRT(strcmp) 96 -
trunk/src/VBox/Runtime/string/strcmp_alias.c
r1060 r1174 1 /* $Id: memcpy.cpp 17216 2007-01-10 16:40:30Z bird $ */1 /* $Id: strcmp.cpp 17216 2007-01-10 16:40:30Z bird $ */ 2 2 /** @file 3 * InnoTek Portable Runtime - No-CRT memcpy() alias for gcc.3 * InnoTek Portable Runtime - No-CRT strcmp() alias for gcc. 4 4 */ 5 5 … … 25 25 *******************************************************************************/ 26 26 #include <iprt/nocrt/string.h> 27 #undef memcpy27 #undef strcmp 28 28 29 29 #if defined(__DARWIN__) || defined(__WIN__) 30 30 # ifndef __MINGW32__ 31 # pragma weak memcpy31 # pragma weak strcmp 32 32 # endif 33 33 34 34 /* No alias support here (yet in the ming case). */ 35 extern void *(memcpy)(void *pvDst, const void *pvSrc, size_t cb)35 extern int (strcmp)(const char *psz1, const char *psz2) 36 36 { 37 return RT_NOCRT( memcpy)(pvDst, pvSrc, cb);37 return RT_NOCRT(strcmp)(psz1, psz2); 38 38 } 39 39 40 40 #elif __GNUC__ >= 4 41 41 /* create a weak alias. */ 42 __asm__(".weak memcpy\t\n"43 " .set memcpy," RT_NOCRT_STR(memcpy) "\t\n");42 __asm__(".weak strcmp\t\n" 43 " .set strcmp," RT_NOCRT_STR(strcmp) "\t\n"); 44 44 #else 45 45 /* create a weak alias. */ 46 extern __typeof(RT_NOCRT( memcpy)) memcpy __attribute__((weak, alias(RT_NOCRT_STR(memcpy))));46 extern __typeof(RT_NOCRT(strcmp)) strcmp __attribute__((weak, alias(RT_NOCRT_STR(strcmp)))); 47 47 #endif 48 48
Note:
See TracChangeset
for help on using the changeset viewer.