1 | ; $Id: strchr.asm 56290 2015-06-09 14:01:31Z vboxsync $
|
---|
2 | ;; @file
|
---|
3 | ; IPRT - No-CRT strchr - AMD64 & X86.
|
---|
4 | ;
|
---|
5 |
|
---|
6 | ;
|
---|
7 | ; Copyright (C) 2006-2015 Oracle Corporation
|
---|
8 | ;
|
---|
9 | ; This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | ; available from http://www.virtualbox.org. This file is free software;
|
---|
11 | ; you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | ; General Public License (GPL) as published by the Free Software
|
---|
13 | ; Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | ; VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | ; hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | ;
|
---|
17 | ; The contents of this file may alternatively be used under the terms
|
---|
18 | ; of the Common Development and Distribution License Version 1.0
|
---|
19 | ; (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
20 | ; VirtualBox OSE distribution, in which case the provisions of the
|
---|
21 | ; CDDL are applicable instead of those of the GPL.
|
---|
22 | ;
|
---|
23 | ; You may elect to license modified versions of this file under the
|
---|
24 | ; terms and conditions of either the GPL or the CDDL or both.
|
---|
25 | ;
|
---|
26 |
|
---|
27 | %include "iprt/asmdefs.mac"
|
---|
28 |
|
---|
29 | BEGINCODE
|
---|
30 |
|
---|
31 | ;;
|
---|
32 | ; @param psz gcc: rdi msc: rcx x86:[esp+4]
|
---|
33 | ; @param ch gcc: esi msc: edx x86:[esp+8]
|
---|
34 | RT_NOCRT_BEGINPROC strchr
|
---|
35 | cld
|
---|
36 |
|
---|
37 | ; check for ch == 0 and setup normal strchr.
|
---|
38 | %ifdef RT_ARCH_AMD64
|
---|
39 | %ifdef ASM_CALL64_MSC
|
---|
40 | or dl, dl
|
---|
41 | jz near .strlen
|
---|
42 | mov r9, rsi ; save rsi
|
---|
43 | mov rsi, rcx
|
---|
44 | %else
|
---|
45 | or sil, sil
|
---|
46 | jz near .strlen
|
---|
47 | mov edx, esi
|
---|
48 | mov rsi, rdi
|
---|
49 | %endif
|
---|
50 | %else
|
---|
51 | mov edx, [esp + 8]
|
---|
52 | or dl, dl
|
---|
53 | jz near .strlen
|
---|
54 | mov ecx, esi ; save esi
|
---|
55 | mov esi, [esp + 4]
|
---|
56 | %endif
|
---|
57 |
|
---|
58 | ; do the search
|
---|
59 | .next:
|
---|
60 | lodsb
|
---|
61 | cmp al, dl
|
---|
62 | je .found
|
---|
63 | test al, al
|
---|
64 | jz .not_found
|
---|
65 |
|
---|
66 | lodsb
|
---|
67 | cmp al, dl
|
---|
68 | je .found
|
---|
69 | test al, al
|
---|
70 | jz .not_found
|
---|
71 |
|
---|
72 | lodsb
|
---|
73 | cmp al, dl
|
---|
74 | je .found
|
---|
75 | test al, al
|
---|
76 | jz .not_found
|
---|
77 |
|
---|
78 | lodsb
|
---|
79 | cmp al, dl
|
---|
80 | je .found
|
---|
81 | test al, al
|
---|
82 | jz .not_found
|
---|
83 | jmp .next
|
---|
84 |
|
---|
85 | .found:
|
---|
86 | lea xAX, [xSI - 1]
|
---|
87 | %ifdef ASM_CALL64_MSC
|
---|
88 | mov rsi, r9
|
---|
89 | %endif
|
---|
90 | %ifdef RT_ARCH_X86
|
---|
91 | mov esi, ecx
|
---|
92 | %endif
|
---|
93 | ret
|
---|
94 |
|
---|
95 | .not_found:
|
---|
96 | %ifdef ASM_CALL64_MSC
|
---|
97 | mov rsi, r9
|
---|
98 | %endif
|
---|
99 | %ifdef RT_ARCH_X86
|
---|
100 | mov esi, ecx
|
---|
101 | %endif
|
---|
102 | xor eax, eax
|
---|
103 | ret
|
---|
104 |
|
---|
105 | ;
|
---|
106 | ; Special case: strchr(str, '\0');
|
---|
107 | ;
|
---|
108 | align 16
|
---|
109 | .strlen:
|
---|
110 | %ifdef RT_ARCH_AMD64
|
---|
111 | %ifdef ASM_CALL64_MSC
|
---|
112 | mov r9, rdi ; save rdi
|
---|
113 | mov rdi, rcx
|
---|
114 | %endif
|
---|
115 | %else
|
---|
116 | mov edx, edi ; save edi
|
---|
117 | mov edi, [esp + 4]
|
---|
118 | %endif
|
---|
119 | mov xCX, -1
|
---|
120 | xor eax, eax
|
---|
121 | repne scasb
|
---|
122 |
|
---|
123 | lea xAX, [xDI - 1]
|
---|
124 | %ifdef ASM_CALL64_MSC
|
---|
125 | mov rdi, r9
|
---|
126 | %endif
|
---|
127 | %ifdef RT_ARCH_X86
|
---|
128 | mov edi, edx
|
---|
129 | %endif
|
---|
130 | ret
|
---|
131 | ENDPROC RT_NOCRT(strchr)
|
---|
132 |
|
---|