summaryrefslogtreecommitdiff
path: root/strings/ptr_cmp.asm
blob: 6106016ee324d2a9a2fc101571af0ea97d46d284 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
; Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
; 
; This library is free software; you can redistribute it and/or
; modify it under the terms of the GNU Library General Public
; License as published by the Free Software Foundation; either
; version 2 of the License, or (at your option) any later version.
; 
; This library is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
; Library General Public License for more details.
; 
; You should have received a copy of the GNU Library General Public
; License along with this library; if not, write to the Free
; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
; MA 02111-1307, USA

	TITLE   Optimized cmp of pointer to strings of unsigned chars

ifndef M_I386
	.8087
	DOSSEG
	.MODEL LARGE
	.DATA
compare_length dw	0
	.CODE STRINGS

	PUBLIC	_get_ptr_compare
_get_ptr_compare	PROC
	mov	bx,sp
	mov	cx,ss:[BX+4]
	mov	compare_length,cx
	mov	dx,seg strings:_ptr_cmp
	mov	ax,offset _ptr_cmp_0
	jcxz	@F
	mov	ax,offset _ptr_cmp_1
	dec	cx
	jz	@F
	mov	ax,offset _ptr_cmp
@@:	ret
_get_ptr_compare ENDP

_ptr_cmp_0	PROC
	mov	AX,0			; Emptyt strings are always equal
	ret
_ptr_cmp_0	ENDP


_ptr_cmp_1	PROC
	mov	bx,sp
	mov	dx,si			; Save si and ds
	mov	cx,ds
	lds	si,DWORD PTR ss:[bx+4]	; s1
	lds	si,DWORD PTR ds:[si]
	mov	al,ds:[si]
	xor	ah,ah
	lds	si,DWORD PTR ss:[bx+8]	; s2
	lds	si,DWORD PTR ds:[si]
	mov	bl,ds:[si]
	mov	bh,ah
	sub	ax,bx
	mov	ds,cx			; restore si and ds
	mov	si,dx
	ret
_ptr_cmp_1 ENDP

_ptr_cmp	PROC
	mov	bx,bp			; Save bp
	mov	dx,di			; Save di
	mov	bp,sp
	push	ds
	push	si
	mov	cx,compare_length	; Length of memory-area
	lds	si,DWORD PTR [bp+4]	; s1
	lds	si,DWORD PTR ds:[si]
	les	di,DWORD PTR [bp+8]	; s2
	les	di,DWORD PTR es:[di]
;	cld				; Work uppward
	xor	ax,ax
	repe	cmpsb			; Compare strings
	je	@F			; Strings are equal
	sbb	ax,ax
	cmc
	adc	ax,0

@@:	pop	si
	pop	ds
	mov	di,dx
	mov	bp,bx
	ret
_ptr_cmp ENDP

else

include macros.asm

fix_es  MACRO   fix_cld                 ; Load ES if neaded
  ife ESeqDS
        mov     ax,ds
        mov     es,ax
  endif
  ifnb <fix_cld>
        cld
  endif
        ENDM

	begdata
compare_length dd	0		; Length of strings
	enddata

	begcode get_ptr_compare
	public	_get_ptr_compare
_get_ptr_compare	proc near
	mov	ecx,P-SIZEPTR[esp]
	mov	compare_length,ecx
	mov	eax,offset _TEXT:_ptr_cmp_0
	jecxz	@F
	mov	eax,offset _TEXT:_ptr_cmp_1
	dec	ecx
	jz	@F
	mov	eax,offset _TEXT:_ptr_cmp
@@:	ret
_get_ptr_compare endp
	endcode _get_ptr_compare


	begcode	ptr_cmp_0
_ptr_cmp_0	PROC
	mov	EAX,0			; Emptyt strings are always equal
	ret
_ptr_cmp_0	ENDP
	endcode	ptr_cmp_0


	begcode	ptr_cmp_1
_ptr_cmp_1	proc near
	mov	edx,esi			; Save esi
	mov	esi,P-SIZEPTR[esp]	; *s1
	mov	esi,[esi]
	movzx	eax,[esi]
	mov	esi,P[esp]		; *s2
	mov	esi,[esi]
	movzx	ecx,[esi]
	sub	eax,ecx
	mov	esi,edx			; Restore esi
	ret
_ptr_cmp_1 ENDP
	endcode ptr_cmp_1


	begcode	ptr_cmp
_ptr_cmp	proc near
	fix_es	1
	push	ebp
	mov	ebp,esp
	mov	edx,edi			; Save esi
	push	esi
	mov	esi,P[ebp]		; *s1
	mov	esi,[esi]
	mov	edi,P+SIZEPTR[ebp]	; *s2
	mov	edi,[edi]
	mov	ecx,compare_length	; Length of memory-area
	xor	eax,eax
	repe	cmpsb			; Compare strings
	je	@F			; Strings are equal

	sbb	eax,eax
	cmc
	adc	eax,0

@@:	pop	esi
	mov	edi,edx
	pop	ebp
	ret
_ptr_cmp ENDP
	endcode	ptr_cmp

endif

	END