VirtualBox

source: vbox/trunk/src/VBox/Runtime/common/string/memcmp.asm@ 96407

Last change on this file since 96407 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.7 KB
Line 
1; $Id: memcmp.asm 96407 2022-08-22 17:43:14Z vboxsync $
2;; @file
3; IPRT - No-CRT memcmp - 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 pv1 gcc: rdi msc: rcx x86:[esp+4] wcall: eax
43; @param pv2 gcc: rsi msc: rdx x86:[esp+8] wcall: edx
44; @param cb gcc: rdx msc: r8 x86:[esp+0ch] wcall: ebx
45RT_NOCRT_BEGINPROC memcmp
46 cld
47
48 ; Do the bulk of the work.
49%ifdef RT_ARCH_AMD64
50 %ifdef ASM_CALL64_MSC
51 mov r10, rdi ; save
52 mov r11, rsi ; save
53 mov rdi, rcx
54 mov rsi, rdx
55 mov rcx, r8
56 mov rdx, r8
57 %else
58 mov rcx, rdx
59 %endif
60 shr rcx, 3
61 xor eax, eax
62 repe cmpsq
63 jne .not_equal_qword
64%else
65 push edi
66 push esi
67
68 %ifdef ASM_CALL32_WATCOM
69 mov edi, eax
70 mov esi, edx
71 mov ecx, ebx
72 mov edx, ebx
73 %else
74 mov ecx, [esp + 0ch + 8]
75 mov edi, [esp + 04h + 8]
76 mov esi, [esp + 08h + 8]
77 mov edx, ecx
78 %endif
79 jecxz .done
80 shr ecx, 2
81 xor eax, eax
82 repe cmpsd
83 jne .not_equal_dword
84%endif
85
86 ; The remaining bytes.
87%ifdef RT_ARCH_AMD64
88 test dl, 4
89 jz .dont_cmp_dword
90 cmpsd
91 jne .not_equal_dword
92%endif
93.dont_cmp_dword:
94 test dl, 2
95 jz .dont_cmp_word
96 cmpsw
97 jne .not_equal_word
98.dont_cmp_word:
99 test dl, 1
100 jz .dont_cmp_byte
101 cmpsb
102 jne .not_equal_byte
103.dont_cmp_byte:
104
105.done:
106%ifdef RT_ARCH_AMD64
107 %ifdef ASM_CALL64_MSC
108 mov rdi, r10
109 mov rsi, r11
110 %endif
111%else
112 pop esi
113 pop edi
114%endif
115 ret
116
117;
118; Mismatches.
119;
120%ifdef RT_ARCH_AMD64
121.not_equal_qword:
122 mov ecx, 8
123 sub rsi, 8
124 sub rdi, 8
125 repe cmpsb
126.not_equal_byte:
127 mov al, [xDI-1]
128 movzx ecx, byte [xSI-1]
129 sub eax, ecx
130 jmp .done
131%endif
132
133.not_equal_dword:
134 mov ecx, 4
135 sub xSI, 4
136 sub xDI, 4
137 repe cmpsb
138%ifdef RT_ARCH_AMD64
139 jmp .not_equal_byte
140%else
141.not_equal_byte:
142 mov al, [xDI-1]
143 movzx ecx, byte [xSI-1]
144 sub eax, ecx
145 jmp .done
146%endif
147
148.not_equal_word:
149 mov ecx, 2
150 sub xSI, 2
151 sub xDI, 2
152 repe cmpsb
153 jmp .not_equal_byte
154ENDPROC RT_NOCRT(memcmp)
155
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