~ubuntu-branches/ubuntu/precise/eglibc/precise

« back to all changes in this revision

Viewing changes to sysdeps/i386/i686/multiarch/strrchr-sse2-bsf.S

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2011-10-04 17:48:26 UTC
  • mfrom: (216.1.23 oneiric)
  • Revision ID: package-import@ubuntu.com-20111004174826-2cyb9ewn3ucymlsx
Tags: 2.13-20ubuntu5
libc6-dev: Don't break the current {gnat,gcj}-4.4-base versons. LP: #853688.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* strrchr with SSE2 with bsf and bsr
2
 
   Copyright (C) 2011 Free Software Foundation, Inc.
3
 
   Contributed by Intel Corporation.
4
 
   This file is part of the GNU C Library.
5
 
 
6
 
   The GNU C Library is free software; you can redistribute it and/or
7
 
   modify it under the terms of the GNU Lesser General Public
8
 
   License as published by the Free Software Foundation; either
9
 
   version 2.1 of the License, or (at your option) any later version.
10
 
 
11
 
   The GNU C Library is distributed in the hope that it will be useful,
12
 
   but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
 
   Lesser General Public License for more details.
15
 
 
16
 
   You should have received a copy of the GNU Lesser General Public
17
 
   License along with the GNU C Library; if not, write to the Free
18
 
   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19
 
   02111-1307 USA.  */
20
 
 
21
 
#ifndef NOT_IN_libc
22
 
 
23
 
# include <sysdep.h>
24
 
 
25
 
# define CFI_PUSH(REG)  \
26
 
        cfi_adjust_cfa_offset (4);      \
27
 
        cfi_rel_offset (REG, 0)
28
 
 
29
 
# define CFI_POP(REG)   \
30
 
        cfi_adjust_cfa_offset (-4);     \
31
 
        cfi_restore (REG)
32
 
 
33
 
# define PUSH(REG) pushl REG; CFI_PUSH (REG)
34
 
# define POP(REG) popl REG; CFI_POP (REG)
35
 
 
36
 
# define PARMS  4
37
 
# define STR1  PARMS
38
 
# define STR2  STR1+4
39
 
 
40
 
        .text
41
 
ENTRY (__strrchr_sse2_bsf)
42
 
 
43
 
        mov     STR1(%esp), %ecx
44
 
        movd    STR2(%esp), %xmm1
45
 
 
46
 
        PUSH    (%edi)
47
 
        pxor    %xmm2, %xmm2
48
 
        mov     %ecx, %edi
49
 
        punpcklbw %xmm1, %xmm1
50
 
        punpcklbw %xmm1, %xmm1
51
 
        /* ECX has OFFSET. */
52
 
        and     $63, %ecx
53
 
        cmp     $48, %ecx
54
 
        pshufd  $0, %xmm1, %xmm1
55
 
        ja      L(crosscashe)
56
 
 
57
 
/* unaligned string. */
58
 
        movdqu  (%edi), %xmm0
59
 
        pcmpeqb %xmm0, %xmm2
60
 
        pcmpeqb %xmm1, %xmm0
61
 
        /* Find where NULL is.  */
62
 
        pmovmskb %xmm2, %edx
63
 
        /* Check if there is a match.  */
64
 
        pmovmskb %xmm0, %eax
65
 
 
66
 
        test    %eax, %eax
67
 
        jnz     L(unaligned_match1)
68
 
 
69
 
        test    %edx, %edx
70
 
        jnz     L(return_null)
71
 
 
72
 
        and     $-16, %edi
73
 
        add     $16, %edi
74
 
 
75
 
        PUSH    (%esi)
76
 
        PUSH    (%ebx)
77
 
 
78
 
        xor     %ebx, %ebx
79
 
        jmp     L(loop)
80
 
 
81
 
        CFI_POP (%esi)
82
 
        CFI_POP (%ebx)
83
 
 
84
 
        .p2align 4
85
 
L(unaligned_return_value1):
86
 
        bsf     %edx, %ecx
87
 
        mov     $2, %edx
88
 
        shl     %cl, %edx
89
 
        sub     $1, %edx
90
 
        and     %edx, %eax
91
 
        jz      L(return_null)
92
 
        bsr     %eax, %eax
93
 
        add     %edi, %eax
94
 
        POP     (%edi)
95
 
        ret
96
 
        CFI_PUSH        (%edi)
97
 
 
98
 
        .p2align 4
99
 
L(unaligned_match1):
100
 
        test    %edx, %edx
101
 
        jnz     L(unaligned_return_value1)
102
 
 
103
 
        PUSH    (%esi)
104
 
        PUSH    (%ebx)
105
 
 
106
 
        mov     %eax, %ebx
107
 
        lea     16(%edi), %esi
108
 
        and     $-16, %edi
109
 
        add     $16, %edi
110
 
        jmp     L(loop)
111
 
 
112
 
        CFI_POP (%esi)
113
 
        CFI_POP (%ebx)
114
 
 
115
 
        .p2align 4
116
 
        L(crosscashe):
117
 
/* Hancle unaligned string.  */
118
 
        and     $15, %ecx
119
 
        and     $-16, %edi
120
 
        pxor    %xmm3, %xmm3
121
 
        movdqa  (%edi), %xmm0
122
 
        pcmpeqb %xmm0, %xmm3
123
 
        pcmpeqb %xmm1, %xmm0
124
 
        /* Find where NULL is.  */
125
 
        pmovmskb %xmm3, %edx
126
 
        /* Check if there is a match.  */
127
 
        pmovmskb %xmm0, %eax
128
 
        /* Remove the leading bytes.  */
129
 
        shr     %cl, %edx
130
 
        shr     %cl, %eax
131
 
 
132
 
        test    %eax, %eax
133
 
        jnz     L(unaligned_match)
134
 
 
135
 
        test    %edx, %edx
136
 
        jnz     L(return_null)
137
 
 
138
 
        add     $16, %edi
139
 
 
140
 
        PUSH    (%esi)
141
 
        PUSH    (%ebx)
142
 
 
143
 
        xor     %ebx, %ebx
144
 
        jmp     L(loop)
145
 
 
146
 
        CFI_POP (%esi)
147
 
        CFI_POP (%ebx)
148
 
 
149
 
        .p2align 4
150
 
L(unaligned_return_value):
151
 
        add     %ecx, %edi
152
 
        bsf     %edx, %ecx
153
 
        mov     $2, %edx
154
 
        shl     %cl, %edx
155
 
        sub     $1, %edx
156
 
        and     %edx, %eax
157
 
        jz      L(return_null)
158
 
        bsr     %eax, %eax
159
 
        add     %edi, %eax
160
 
        POP     (%edi)
161
 
        ret
162
 
        CFI_PUSH        (%edi)
163
 
 
164
 
        .p2align 4
165
 
L(unaligned_match):
166
 
        test    %edx, %edx
167
 
        jnz     L(unaligned_return_value)
168
 
 
169
 
        PUSH    (%esi)
170
 
        PUSH    (%ebx)
171
 
 
172
 
        mov     %eax, %ebx
173
 
        add     $16, %edi
174
 
        lea     (%edi, %ecx), %esi
175
 
 
176
 
/* Loop start on aligned string.  */
177
 
        .p2align 4
178
 
L(loop):
179
 
        movdqa  (%edi), %xmm0
180
 
        pcmpeqb %xmm0, %xmm2
181
 
        add     $16, %edi
182
 
        pcmpeqb %xmm1, %xmm0
183
 
        pmovmskb %xmm2, %ecx
184
 
        pmovmskb %xmm0, %eax
185
 
        or      %eax, %ecx
186
 
        jnz     L(matches)
187
 
 
188
 
        movdqa  (%edi), %xmm0
189
 
        pcmpeqb %xmm0, %xmm2
190
 
        add     $16, %edi
191
 
        pcmpeqb %xmm1, %xmm0
192
 
        pmovmskb %xmm2, %ecx
193
 
        pmovmskb %xmm0, %eax
194
 
        or      %eax, %ecx
195
 
        jnz     L(matches)
196
 
 
197
 
        movdqa  (%edi), %xmm0
198
 
        pcmpeqb %xmm0, %xmm2
199
 
        add     $16, %edi
200
 
        pcmpeqb %xmm1, %xmm0
201
 
        pmovmskb %xmm2, %ecx
202
 
        pmovmskb %xmm0, %eax
203
 
        or      %eax, %ecx
204
 
        jnz     L(matches)
205
 
 
206
 
        movdqa  (%edi), %xmm0
207
 
        pcmpeqb %xmm0, %xmm2
208
 
        add     $16, %edi
209
 
        pcmpeqb %xmm1, %xmm0
210
 
        pmovmskb %xmm2, %ecx
211
 
        pmovmskb %xmm0, %eax
212
 
        or      %eax, %ecx
213
 
        jz      L(loop)
214
 
 
215
 
L(matches):
216
 
        test    %eax, %eax
217
 
        jnz     L(match)
218
 
L(return_value):
219
 
        test    %ebx, %ebx
220
 
        jz      L(return_null_1)
221
 
        bsr     %ebx, %eax
222
 
        add     %esi, %eax
223
 
 
224
 
        POP     (%ebx)
225
 
        POP     (%esi)
226
 
 
227
 
        sub     $16, %eax
228
 
        POP     (%edi)
229
 
        ret
230
 
 
231
 
        CFI_PUSH        (%edi)
232
 
        CFI_PUSH        (%ebx)
233
 
        CFI_PUSH        (%esi)
234
 
 
235
 
        .p2align 4
236
 
L(match):
237
 
        pmovmskb %xmm2, %ecx
238
 
        test    %ecx, %ecx
239
 
        jnz     L(return_value_1)
240
 
        mov     %eax, %ebx
241
 
        mov     %edi, %esi
242
 
        jmp     L(loop)
243
 
 
244
 
        .p2align 4
245
 
L(return_value_1):
246
 
        bsf     %ecx, %ecx
247
 
        mov     $2, %edx
248
 
        shl     %cl, %edx
249
 
        sub     $1, %edx
250
 
        and     %edx, %eax
251
 
        jz      L(return_value)
252
 
 
253
 
        POP     (%ebx)
254
 
        POP     (%esi)
255
 
 
256
 
        bsr     %eax, %eax
257
 
        add     %edi, %eax
258
 
        sub     $16, %eax
259
 
        POP     (%edi)
260
 
        ret
261
 
 
262
 
        CFI_PUSH        (%edi)
263
 
/* Return NULL.  */
264
 
        .p2align 4
265
 
L(return_null):
266
 
        xor     %eax, %eax
267
 
        POP     (%edi)
268
 
        ret
269
 
 
270
 
        CFI_PUSH        (%edi)
271
 
        CFI_PUSH        (%ebx)
272
 
        CFI_PUSH        (%esi)
273
 
/* Return NULL.  */
274
 
        .p2align 4
275
 
L(return_null_1):
276
 
        POP     (%ebx)
277
 
        POP     (%esi)
278
 
        POP     (%edi)
279
 
        xor     %eax, %eax
280
 
        ret
281
 
 
282
 
END (__strrchr_sse2_bsf)
283
 
#endif