1 | ; $Id: strncmp.asm 76553 2019-01-01 01:45:53Z vboxsync $
|
---|
2 | ;; @file
|
---|
3 | ; IPRT - No-CRT strncmp - AMD64 & X86.
|
---|
4 | ;
|
---|
5 |
|
---|
6 | ;
|
---|
7 | ; Copyright (C) 2006-2019 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 psz1 gcc: rdi msc: rcx x86:[esp+4] wcall: eax
|
---|
33 | ; @param psz2 gcc: rsi msc: rdx x86:[esp+8] wcall: edx
|
---|
34 | ; @param cch gcc: rdx msc: r8 x86:[esp+12] wcall: ebx
|
---|
35 | RT_NOCRT_BEGINPROC strncmp
|
---|
36 | ; input
|
---|
37 | %ifdef RT_ARCH_AMD64
|
---|
38 | %ifdef ASM_CALL64_MSC
|
---|
39 | %define psz1 rcx
|
---|
40 | %define psz2 rdx
|
---|
41 | %define cch r8
|
---|
42 | %else
|
---|
43 | %define psz1 rdi
|
---|
44 | %define psz2 rsi
|
---|
45 | %define cch rdx
|
---|
46 | %endif
|
---|
47 | %elifdef ASM_CALL32_WATCOM
|
---|
48 | mov ecx, eax
|
---|
49 | %define psz1 ecx
|
---|
50 | %define psz2 edx
|
---|
51 | %define cch ebx
|
---|
52 |
|
---|
53 | %elifdef RT_ARCH_X86
|
---|
54 | mov ecx, [esp + 4]
|
---|
55 | mov edx, [esp + 8]
|
---|
56 | push ebx
|
---|
57 | mov ebx, [esp + 12+4]
|
---|
58 | %define psz1 ecx
|
---|
59 | %define psz2 edx
|
---|
60 | %define cch ebx
|
---|
61 | %else
|
---|
62 | %error "Unknown arch"
|
---|
63 | %endif
|
---|
64 |
|
---|
65 | ;
|
---|
66 | ; The loop.
|
---|
67 | ;
|
---|
68 | test cch, cch
|
---|
69 | jz .equal
|
---|
70 | .next:
|
---|
71 | mov al, [psz1]
|
---|
72 | mov ah, [psz2]
|
---|
73 | cmp al, ah
|
---|
74 | jne .not_equal
|
---|
75 | test al, al
|
---|
76 | jz .equal
|
---|
77 | dec cch
|
---|
78 | jz .equal
|
---|
79 |
|
---|
80 | mov al, [psz1 + 1]
|
---|
81 | mov ah, [psz2 + 1]
|
---|
82 | cmp al, ah
|
---|
83 | jne .not_equal
|
---|
84 | test al, al
|
---|
85 | jz .equal
|
---|
86 | dec cch
|
---|
87 | jz .equal
|
---|
88 |
|
---|
89 | mov al, [psz1 + 2]
|
---|
90 | mov ah, [psz2 + 2]
|
---|
91 | cmp al, ah
|
---|
92 | jne .not_equal
|
---|
93 | test al, al
|
---|
94 | jz .equal
|
---|
95 | dec cch
|
---|
96 | jz .equal
|
---|
97 |
|
---|
98 | mov al, [psz1 + 3]
|
---|
99 | mov ah, [psz2 + 3]
|
---|
100 | cmp al, ah
|
---|
101 | jne .not_equal
|
---|
102 | test al, al
|
---|
103 | jz .equal
|
---|
104 | dec cch
|
---|
105 | jz .equal
|
---|
106 |
|
---|
107 | add psz1, 4
|
---|
108 | add psz2, 4
|
---|
109 | jmp .next
|
---|
110 |
|
---|
111 | .equal:
|
---|
112 | xor eax, eax
|
---|
113 | %ifndef ASM_CALL32_WATCOM
|
---|
114 | %ifdef RT_ARCH_X86
|
---|
115 | pop ebx
|
---|
116 | %endif
|
---|
117 | %endif
|
---|
118 | ret
|
---|
119 |
|
---|
120 | .not_equal:
|
---|
121 | movzx ecx, ah
|
---|
122 | and eax, 0ffh
|
---|
123 | sub eax, ecx
|
---|
124 | %ifndef ASM_CALL32_WATCOM
|
---|
125 | %ifdef RT_ARCH_X86
|
---|
126 | pop ebx
|
---|
127 | %endif
|
---|
128 | %endif
|
---|
129 | ret
|
---|
130 | ENDPROC RT_NOCRT(strncmp)
|
---|
131 |
|
---|