1 | ; $Id: memcmp.asm 75129 2018-10-28 17:00:27Z vboxsync $
|
---|
2 | ;; @file
|
---|
3 | ; IPRT - No-CRT memcmp - AMD64 & X86.
|
---|
4 | ;
|
---|
5 |
|
---|
6 | ;
|
---|
7 | ; Copyright (C) 2006-2017 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 | xor eax, eax
|
---|
38 |
|
---|
39 | ; Do the bulk of the work.
|
---|
40 | %ifdef RT_ARCH_AMD64
|
---|
41 | %ifdef ASM_CALL64_MSC
|
---|
42 | mov r10, rdi ; save
|
---|
43 | mov r11, rsi ; save
|
---|
44 | mov rdi, rcx
|
---|
45 | mov rsi, rdx
|
---|
46 | mov rcx, r8
|
---|
47 | mov rdx, r8
|
---|
48 | %else
|
---|
49 | mov rcx, rdx
|
---|
50 | %endif
|
---|
51 | shr rcx, 3
|
---|
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 | repe cmpsd
|
---|
72 | jne .not_equal_dword
|
---|
73 | %endif
|
---|
74 |
|
---|
75 | ; The remaining bytes.
|
---|
76 | %ifdef RT_ARCH_AMD64
|
---|
77 | test dl, 4
|
---|
78 | jz .dont_cmp_dword
|
---|
79 | cmpsd
|
---|
80 | jne .not_equal_dword
|
---|
81 | %endif
|
---|
82 | .dont_cmp_dword:
|
---|
83 | test dl, 2
|
---|
84 | jz .dont_cmp_word
|
---|
85 | cmpsw
|
---|
86 | jne .not_equal_word
|
---|
87 | .dont_cmp_word:
|
---|
88 | test dl, 1
|
---|
89 | jz .dont_cmp_byte
|
---|
90 | cmpsb
|
---|
91 | jne .not_equal_byte
|
---|
92 | .dont_cmp_byte:
|
---|
93 |
|
---|
94 | .done:
|
---|
95 | %ifdef RT_ARCH_AMD64
|
---|
96 | %ifdef ASM_CALL64_MSC
|
---|
97 | mov rdi, r10
|
---|
98 | mov rsi, r11
|
---|
99 | %endif
|
---|
100 | %else
|
---|
101 | pop esi
|
---|
102 | pop edi
|
---|
103 | %endif
|
---|
104 | ret
|
---|
105 |
|
---|
106 | ;
|
---|
107 | ; Mismatches.
|
---|
108 | ;
|
---|
109 | %ifdef RT_ARCH_AMD64
|
---|
110 | .not_equal_qword:
|
---|
111 | mov ecx, 8
|
---|
112 | sub rsi, 8
|
---|
113 | sub rdi, 8
|
---|
114 | repe cmpsb
|
---|
115 | .not_equal_byte:
|
---|
116 | mov al, [xDI-1]
|
---|
117 | movzx ecx, byte [xSI-1]
|
---|
118 | sub eax, ecx
|
---|
119 | jmp .done
|
---|
120 | %endif
|
---|
121 |
|
---|
122 | .not_equal_dword:
|
---|
123 | mov ecx, 4
|
---|
124 | sub xSI, 4
|
---|
125 | sub xDI, 4
|
---|
126 | repe cmpsb
|
---|
127 | %ifdef RT_ARCH_AMD64
|
---|
128 | jmp .not_equal_byte
|
---|
129 | %else
|
---|
130 | .not_equal_byte:
|
---|
131 | mov al, [xDI-1]
|
---|
132 | movzx ecx, byte [xSI-1]
|
---|
133 | sub eax, ecx
|
---|
134 | jmp .done
|
---|
135 | %endif
|
---|
136 |
|
---|
137 | .not_equal_word:
|
---|
138 | mov ecx, 2
|
---|
139 | sub xSI, 2
|
---|
140 | sub xDI, 2
|
---|
141 | repe cmpsb
|
---|
142 | jmp .not_equal_byte
|
---|
143 | ENDPROC RT_NOCRT(memcmp)
|
---|
144 |
|
---|