1 | ; $Id: strchr.asm 93115 2022-01-01 11:31:46Z vboxsync $
|
---|
2 | ;; @file
|
---|
3 | ; IPRT - No-CRT strchr - AMD64 & X86.
|
---|
4 | ;
|
---|
5 |
|
---|
6 | ;
|
---|
7 | ; Copyright (C) 2006-2022 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] wcall: eax
|
---|
33 | ; @param ch gcc: esi msc: edx x86:[esp+8] wcall: edx
|
---|
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 | %ifndef ASM_CALL32_WATCOM
|
---|
52 | mov edx, [esp + 8]
|
---|
53 | %endif
|
---|
54 | or dl, dl
|
---|
55 | jz near .strlen
|
---|
56 | mov ecx, esi ; save esi
|
---|
57 | %ifdef ASM_CALL32_WATCOM
|
---|
58 | mov esi, eax
|
---|
59 | %else
|
---|
60 | mov esi, [esp + 4]
|
---|
61 | %endif
|
---|
62 | %endif
|
---|
63 |
|
---|
64 | ; do the search
|
---|
65 | .next:
|
---|
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 |
|
---|
84 | lodsb
|
---|
85 | cmp al, dl
|
---|
86 | je .found
|
---|
87 | test al, al
|
---|
88 | jz .not_found
|
---|
89 | jmp .next
|
---|
90 |
|
---|
91 | .found:
|
---|
92 | lea xAX, [xSI - 1]
|
---|
93 | %ifdef ASM_CALL64_MSC
|
---|
94 | mov rsi, r9
|
---|
95 | %endif
|
---|
96 | %ifdef RT_ARCH_X86
|
---|
97 | mov esi, ecx
|
---|
98 | %endif
|
---|
99 | ret
|
---|
100 |
|
---|
101 | .not_found:
|
---|
102 | %ifdef ASM_CALL64_MSC
|
---|
103 | mov rsi, r9
|
---|
104 | %endif
|
---|
105 | %ifdef RT_ARCH_X86
|
---|
106 | mov esi, ecx
|
---|
107 | %endif
|
---|
108 | xor eax, eax
|
---|
109 | ret
|
---|
110 |
|
---|
111 | ;
|
---|
112 | ; Special case: strchr(str, '\0');
|
---|
113 | ;
|
---|
114 | align 16
|
---|
115 | .strlen:
|
---|
116 | %ifdef RT_ARCH_AMD64
|
---|
117 | %ifdef ASM_CALL64_MSC
|
---|
118 | mov r9, rdi ; save rdi
|
---|
119 | mov rdi, rcx
|
---|
120 | %endif
|
---|
121 | %else
|
---|
122 | mov edx, edi ; save edi
|
---|
123 | %ifdef ASM_CALL32_WATCOM
|
---|
124 | mov edi, eax
|
---|
125 | %else
|
---|
126 | mov edi, [esp + 4]
|
---|
127 | %endif
|
---|
128 | %endif
|
---|
129 | mov xCX, -1
|
---|
130 | xor eax, eax
|
---|
131 | repne scasb
|
---|
132 |
|
---|
133 | lea xAX, [xDI - 1]
|
---|
134 | %ifdef ASM_CALL64_MSC
|
---|
135 | mov rdi, r9
|
---|
136 | %endif
|
---|
137 | %ifdef RT_ARCH_X86
|
---|
138 | mov edi, edx
|
---|
139 | %endif
|
---|
140 | ret
|
---|
141 | ENDPROC RT_NOCRT(strchr)
|
---|
142 |
|
---|