~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to strings/ptr_cmp.asm

  • Committer: brian
  • Date: 2008-06-25 05:29:13 UTC
  • Revision ID: brian@localhost.localdomain-20080625052913-6upwo0jsrl4lnapl
clean slate

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
; Copyright (C) 2000 MySQL AB
 
2
 
3
; This library is free software; you can redistribute it and/or
 
4
; modify it under the terms of the GNU Library General Public
 
5
; License as published by the Free Software Foundation; version 2
 
6
; of the License.
 
7
 
8
; This library is distributed in the hope that it will be useful,
 
9
; but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
11
; Library General Public License for more details.
 
12
 
13
; You should have received a copy of the GNU Library General Public
 
14
; License along with this library; if not, write to the Free
 
15
; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
 
16
; MA 02111-1307, USA
 
17
 
 
18
        TITLE   Optimized cmp of pointer to strings of unsigned chars
 
19
 
 
20
ifndef M_I386
 
21
        .8087
 
22
        DOSSEG
 
23
        .MODEL LARGE
 
24
        .DATA
 
25
compare_length dw       0
 
26
        .CODE STRINGS
 
27
 
 
28
        PUBLIC  _get_ptr_compare
 
29
_get_ptr_compare        PROC
 
30
        mov     bx,sp
 
31
        mov     cx,ss:[BX+4]
 
32
        mov     compare_length,cx
 
33
        mov     dx,seg strings:_ptr_cmp
 
34
        mov     ax,offset _ptr_cmp_0
 
35
        jcxz    @F
 
36
        mov     ax,offset _ptr_cmp_1
 
37
        dec     cx
 
38
        jz      @F
 
39
        mov     ax,offset _ptr_cmp
 
40
@@:     ret
 
41
_get_ptr_compare ENDP
 
42
 
 
43
_ptr_cmp_0      PROC
 
44
        mov     AX,0                    ; Emptyt strings are always equal
 
45
        ret
 
46
_ptr_cmp_0      ENDP
 
47
 
 
48
 
 
49
_ptr_cmp_1      PROC
 
50
        mov     bx,sp
 
51
        mov     dx,si                   ; Save si and ds
 
52
        mov     cx,ds
 
53
        lds     si,DWORD PTR ss:[bx+4]  ; s1
 
54
        lds     si,DWORD PTR ds:[si]
 
55
        mov     al,ds:[si]
 
56
        xor     ah,ah
 
57
        lds     si,DWORD PTR ss:[bx+8]  ; s2
 
58
        lds     si,DWORD PTR ds:[si]
 
59
        mov     bl,ds:[si]
 
60
        mov     bh,ah
 
61
        sub     ax,bx
 
62
        mov     ds,cx                   ; restore si and ds
 
63
        mov     si,dx
 
64
        ret
 
65
_ptr_cmp_1 ENDP
 
66
 
 
67
_ptr_cmp        PROC
 
68
        mov     bx,bp                   ; Save bp
 
69
        mov     dx,di                   ; Save di
 
70
        mov     bp,sp
 
71
        push    ds
 
72
        push    si
 
73
        mov     cx,compare_length       ; Length of memory-area
 
74
        lds     si,DWORD PTR [bp+4]     ; s1
 
75
        lds     si,DWORD PTR ds:[si]
 
76
        les     di,DWORD PTR [bp+8]     ; s2
 
77
        les     di,DWORD PTR es:[di]
 
78
;       cld                             ; Work uppward
 
79
        xor     ax,ax
 
80
        repe    cmpsb                   ; Compare strings
 
81
        je      @F                      ; Strings are equal
 
82
        sbb     ax,ax
 
83
        cmc
 
84
        adc     ax,0
 
85
 
 
86
@@:     pop     si
 
87
        pop     ds
 
88
        mov     di,dx
 
89
        mov     bp,bx
 
90
        ret
 
91
_ptr_cmp ENDP
 
92
 
 
93
else
 
94
 
 
95
include macros.asm
 
96
 
 
97
fix_es  MACRO   fix_cld                 ; Load ES if neaded
 
98
  ife ESeqDS
 
99
        mov     ax,ds
 
100
        mov     es,ax
 
101
  endif
 
102
  ifnb <fix_cld>
 
103
        cld
 
104
  endif
 
105
        ENDM
 
106
 
 
107
        begdata
 
108
compare_length dd       0               ; Length of strings
 
109
        enddata
 
110
 
 
111
        begcode get_ptr_compare
 
112
        public  _get_ptr_compare
 
113
_get_ptr_compare        proc near
 
114
        mov     ecx,P-SIZEPTR[esp]
 
115
        mov     compare_length,ecx
 
116
        mov     eax,offset _TEXT:_ptr_cmp_0
 
117
        jecxz   @F
 
118
        mov     eax,offset _TEXT:_ptr_cmp_1
 
119
        dec     ecx
 
120
        jz      @F
 
121
        mov     eax,offset _TEXT:_ptr_cmp
 
122
@@:     ret
 
123
_get_ptr_compare endp
 
124
        endcode _get_ptr_compare
 
125
 
 
126
 
 
127
        begcode ptr_cmp_0
 
128
_ptr_cmp_0      PROC
 
129
        mov     EAX,0                   ; Emptyt strings are always equal
 
130
        ret
 
131
_ptr_cmp_0      ENDP
 
132
        endcode ptr_cmp_0
 
133
 
 
134
 
 
135
        begcode ptr_cmp_1
 
136
_ptr_cmp_1      proc near
 
137
        mov     edx,esi                 ; Save esi
 
138
        mov     esi,P-SIZEPTR[esp]      ; *s1
 
139
        mov     esi,[esi]
 
140
        movzx   eax,[esi]
 
141
        mov     esi,P[esp]              ; *s2
 
142
        mov     esi,[esi]
 
143
        movzx   ecx,[esi]
 
144
        sub     eax,ecx
 
145
        mov     esi,edx                 ; Restore esi
 
146
        ret
 
147
_ptr_cmp_1 ENDP
 
148
        endcode ptr_cmp_1
 
149
 
 
150
 
 
151
        begcode ptr_cmp
 
152
_ptr_cmp        proc near
 
153
        fix_es  1
 
154
        push    ebp
 
155
        mov     ebp,esp
 
156
        mov     edx,edi                 ; Save esi
 
157
        push    esi
 
158
        mov     esi,P[ebp]              ; *s1
 
159
        mov     esi,[esi]
 
160
        mov     edi,P+SIZEPTR[ebp]      ; *s2
 
161
        mov     edi,[edi]
 
162
        mov     ecx,compare_length      ; Length of memory-area
 
163
        xor     eax,eax
 
164
        repe    cmpsb                   ; Compare strings
 
165
        je      @F                      ; Strings are equal
 
166
 
 
167
        sbb     eax,eax
 
168
        cmc
 
169
        adc     eax,0
 
170
 
 
171
@@:     pop     esi
 
172
        mov     edi,edx
 
173
        pop     ebp
 
174
        ret
 
175
_ptr_cmp ENDP
 
176
        endcode ptr_cmp
 
177
 
 
178
endif
 
179
 
 
180
        END