VirtualBox

source: vbox/trunk/src/VBox/Runtime/common/string/strchr.asm@ 96563

Last change on this file since 96563 was 96407, checked in by vboxsync, 2 years ago

scm copyright and license note update

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 3.5 KB
Line 
1; $Id: strchr.asm 96407 2022-08-22 17:43:14Z vboxsync $
2;; @file
3; IPRT - No-CRT strchr - AMD64 & X86.
4;
5
6;
7; Copyright (C) 2006-2022 Oracle and/or its affiliates.
8;
9; This file is part of VirtualBox base platform packages, as
10; available from https://www.virtualbox.org.
11;
12; This program is free software; you can redistribute it and/or
13; modify it under the terms of the GNU General Public License
14; as published by the Free Software Foundation, in version 3 of the
15; License.
16;
17; This program is distributed in the hope that it will be useful, but
18; WITHOUT ANY WARRANTY; without even the implied warranty of
19; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20; General Public License for more details.
21;
22; You should have received a copy of the GNU General Public License
23; along with this program; if not, see <https://www.gnu.org/licenses>.
24;
25; The contents of this file may alternatively be used under the terms
26; of the Common Development and Distribution License Version 1.0
27; (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
28; in the VirtualBox distribution, in which case the provisions of the
29; CDDL are applicable instead of those of the GPL.
30;
31; You may elect to license modified versions of this file under the
32; terms and conditions of either the GPL or the CDDL or both.
33;
34; SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
35;
36
37%include "iprt/asmdefs.mac"
38
39BEGINCODE
40
41;;
42; @param psz gcc: rdi msc: rcx x86:[esp+4] wcall: eax
43; @param ch gcc: esi msc: edx x86:[esp+8] wcall: edx
44RT_NOCRT_BEGINPROC strchr
45 cld
46
47 ; check for ch == 0 and setup normal strchr.
48%ifdef RT_ARCH_AMD64
49 %ifdef ASM_CALL64_MSC
50 or dl, dl
51 jz near .strlen
52 mov r9, rsi ; save rsi
53 mov rsi, rcx
54 %else
55 or sil, sil
56 jz near .strlen
57 mov edx, esi
58 mov rsi, rdi
59 %endif
60%else
61 %ifndef ASM_CALL32_WATCOM
62 mov edx, [esp + 8]
63 %endif
64 or dl, dl
65 jz near .strlen
66 mov ecx, esi ; save esi
67 %ifdef ASM_CALL32_WATCOM
68 mov esi, eax
69 %else
70 mov esi, [esp + 4]
71 %endif
72%endif
73
74 ; do the search
75.next:
76 lodsb
77 cmp al, dl
78 je .found
79 test al, al
80 jz .not_found
81
82 lodsb
83 cmp al, dl
84 je .found
85 test al, al
86 jz .not_found
87
88 lodsb
89 cmp al, dl
90 je .found
91 test al, al
92 jz .not_found
93
94 lodsb
95 cmp al, dl
96 je .found
97 test al, al
98 jz .not_found
99 jmp .next
100
101.found:
102 lea xAX, [xSI - 1]
103%ifdef ASM_CALL64_MSC
104 mov rsi, r9
105%endif
106%ifdef RT_ARCH_X86
107 mov esi, ecx
108%endif
109 ret
110
111.not_found:
112%ifdef ASM_CALL64_MSC
113 mov rsi, r9
114%endif
115%ifdef RT_ARCH_X86
116 mov esi, ecx
117%endif
118 xor eax, eax
119 ret
120
121;
122; Special case: strchr(str, '\0');
123;
124align 16
125.strlen:
126%ifdef RT_ARCH_AMD64
127 %ifdef ASM_CALL64_MSC
128 mov r9, rdi ; save rdi
129 mov rdi, rcx
130 %endif
131%else
132 mov edx, edi ; save edi
133 %ifdef ASM_CALL32_WATCOM
134 mov edi, eax
135 %else
136 mov edi, [esp + 4]
137 %endif
138%endif
139 mov xCX, -1
140 xor eax, eax
141 repne scasb
142
143 lea xAX, [xDI - 1]
144%ifdef ASM_CALL64_MSC
145 mov rdi, r9
146%endif
147%ifdef RT_ARCH_X86
148 mov edi, edx
149%endif
150 ret
151ENDPROC RT_NOCRT(strchr)
152
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette