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