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

« back to all changes in this revision

Viewing changes to sysdeps/x86_64/memrchr.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
 
/* fast SSE2 memrchr with 64 byte loop and pmaxub instruction using
2
 
 
3
 
   Copyright (C) 2011 Free Software Foundation, Inc.
4
 
   Contributed by Intel Corporation.
5
 
   This file is part of the GNU C Library.
6
 
 
7
 
   The GNU C Library is free software; you can redistribute it and/or
8
 
   modify it under the terms of the GNU Lesser General Public
9
 
   License as published by the Free Software Foundation; either
10
 
   version 2.1 of the License, or (at your option) any later version.
11
 
 
12
 
   The GNU C Library is distributed in the hope that it will be useful,
13
 
   but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
 
   Lesser General Public License for more details.
16
 
 
17
 
   You should have received a copy of the GNU Lesser General Public
18
 
   License along with the GNU C Library; if not, write to the Free
19
 
   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20
 
   02111-1307 USA.  */
21
 
 
22
 
#include <sysdep.h>
23
 
 
24
 
        .text
25
 
ENTRY (memrchr)
26
 
        movd    %rsi, %xmm1
27
 
 
28
 
        sub     $16, %rdx
29
 
        jbe     L(length_less16)
30
 
 
31
 
        punpcklbw       %xmm1, %xmm1
32
 
        punpcklbw       %xmm1, %xmm1
33
 
 
34
 
        add     %rdx, %rdi
35
 
        pshufd  $0, %xmm1, %xmm1
36
 
 
37
 
        movdqu  (%rdi), %xmm0
38
 
        pcmpeqb %xmm1, %xmm0
39
 
 
40
 
/* Check if there is a match.  */
41
 
        pmovmskb        %xmm0, %eax
42
 
        test    %eax, %eax
43
 
        jnz     L(matches0)
44
 
 
45
 
        sub     $64, %rdi
46
 
        mov     %rdi, %rcx
47
 
        and     $15, %rcx
48
 
        jz      L(loop_prolog)
49
 
 
50
 
        add     $16, %rdi
51
 
        add     $16, %rdx
52
 
        and     $-16, %rdi
53
 
        sub     %rcx, %rdx
54
 
 
55
 
        .p2align 4
56
 
L(loop_prolog):
57
 
        sub     $64, %rdx
58
 
        jbe     L(exit_loop)
59
 
 
60
 
        movdqa  48(%rdi), %xmm0
61
 
        pcmpeqb %xmm1, %xmm0
62
 
        pmovmskb        %xmm0, %eax
63
 
        test    %eax, %eax
64
 
        jnz     L(matches48)
65
 
 
66
 
        movdqa  32(%rdi), %xmm2
67
 
        pcmpeqb %xmm1, %xmm2
68
 
        pmovmskb        %xmm2, %eax
69
 
        test    %eax, %eax
70
 
        jnz     L(matches32)
71
 
 
72
 
        movdqa  16(%rdi), %xmm3
73
 
        pcmpeqb %xmm1, %xmm3
74
 
        pmovmskb        %xmm3, %eax
75
 
        test    %eax, %eax
76
 
        jnz     L(matches16)
77
 
 
78
 
        movdqa  (%rdi), %xmm4
79
 
        pcmpeqb %xmm1, %xmm4
80
 
        pmovmskb        %xmm4, %eax
81
 
        test    %eax, %eax
82
 
        jnz     L(matches0)
83
 
 
84
 
        sub     $64, %rdi
85
 
        sub     $64, %rdx
86
 
        jbe     L(exit_loop)
87
 
 
88
 
        movdqa  48(%rdi), %xmm0
89
 
        pcmpeqb %xmm1, %xmm0
90
 
        pmovmskb        %xmm0, %eax
91
 
        test    %eax, %eax
92
 
        jnz     L(matches48)
93
 
 
94
 
        movdqa  32(%rdi), %xmm2
95
 
        pcmpeqb %xmm1, %xmm2
96
 
        pmovmskb        %xmm2, %eax
97
 
        test    %eax, %eax
98
 
        jnz     L(matches32)
99
 
 
100
 
        movdqa  16(%rdi), %xmm3
101
 
        pcmpeqb %xmm1, %xmm3
102
 
        pmovmskb        %xmm3, %eax
103
 
        test    %eax, %eax
104
 
        jnz     L(matches16)
105
 
 
106
 
        movdqa  (%rdi), %xmm3
107
 
        pcmpeqb %xmm1, %xmm3
108
 
        pmovmskb        %xmm3, %eax
109
 
        test    %eax, %eax
110
 
        jnz     L(matches0)
111
 
 
112
 
        mov     %rdi, %rcx
113
 
        and     $63, %rcx
114
 
        jz      L(align64_loop)
115
 
 
116
 
        add     $64, %rdi
117
 
        add     $64, %rdx
118
 
        and     $-64, %rdi
119
 
        sub     %rcx, %rdx
120
 
 
121
 
        .p2align 4
122
 
L(align64_loop):
123
 
        sub     $64, %rdi
124
 
        sub     $64, %rdx
125
 
        jbe     L(exit_loop)
126
 
 
127
 
        movdqa  (%rdi), %xmm0
128
 
        movdqa  16(%rdi), %xmm2
129
 
        movdqa  32(%rdi), %xmm3
130
 
        movdqa  48(%rdi), %xmm4
131
 
 
132
 
        pcmpeqb %xmm1, %xmm0
133
 
        pcmpeqb %xmm1, %xmm2
134
 
        pcmpeqb %xmm1, %xmm3
135
 
        pcmpeqb %xmm1, %xmm4
136
 
 
137
 
        pmaxub  %xmm3, %xmm0
138
 
        pmaxub  %xmm4, %xmm2
139
 
        pmaxub  %xmm0, %xmm2
140
 
        pmovmskb        %xmm2, %eax
141
 
 
142
 
        test    %eax, %eax
143
 
        jz      L(align64_loop)
144
 
 
145
 
        pmovmskb        %xmm4, %eax
146
 
        test    %eax, %eax
147
 
        jnz     L(matches48)
148
 
 
149
 
        pmovmskb        %xmm3, %eax
150
 
        test    %eax, %eax
151
 
        jnz     L(matches32)
152
 
 
153
 
        movdqa  16(%rdi), %xmm2
154
 
 
155
 
        pcmpeqb %xmm1, %xmm2
156
 
        pcmpeqb (%rdi), %xmm1
157
 
 
158
 
        pmovmskb        %xmm2, %eax
159
 
        test    %eax, %eax
160
 
        jnz     L(matches16)
161
 
 
162
 
        pmovmskb        %xmm1, %eax
163
 
        bsr     %eax, %eax
164
 
 
165
 
        add     %rdi, %rax
166
 
        ret
167
 
 
168
 
        .p2align 4
169
 
L(exit_loop):
170
 
        add     $64, %rdx
171
 
        cmp     $32, %rdx
172
 
        jbe     L(exit_loop_32)
173
 
 
174
 
        movdqa  48(%rdi), %xmm0
175
 
        pcmpeqb %xmm1, %xmm0
176
 
        pmovmskb        %xmm0, %eax
177
 
        test    %eax, %eax
178
 
        jnz     L(matches48)
179
 
 
180
 
        movdqa  32(%rdi), %xmm2
181
 
        pcmpeqb %xmm1, %xmm2
182
 
        pmovmskb        %xmm2, %eax
183
 
        test    %eax, %eax
184
 
        jnz     L(matches32)
185
 
 
186
 
        movdqa  16(%rdi), %xmm3
187
 
        pcmpeqb %xmm1, %xmm3
188
 
        pmovmskb        %xmm3, %eax
189
 
        test    %eax, %eax
190
 
        jnz     L(matches16_1)
191
 
        cmp     $48, %rdx
192
 
        jbe     L(return_null)
193
 
 
194
 
        pcmpeqb (%rdi), %xmm1
195
 
        pmovmskb        %xmm1, %eax
196
 
        test    %eax, %eax
197
 
        jnz     L(matches0_1)
198
 
        xor     %eax, %eax
199
 
        ret
200
 
 
201
 
        .p2align 4
202
 
L(exit_loop_32):
203
 
        movdqa  48(%rdi), %xmm0
204
 
        pcmpeqb %xmm1, %xmm0
205
 
        pmovmskb        %xmm0, %eax
206
 
        test    %eax, %eax
207
 
        jnz     L(matches48_1)
208
 
        cmp     $16, %rdx
209
 
        jbe     L(return_null)
210
 
 
211
 
        pcmpeqb 32(%rdi), %xmm1
212
 
        pmovmskb        %xmm1, %eax
213
 
        test    %eax, %eax
214
 
        jnz     L(matches32_1)
215
 
        xor     %eax, %eax
216
 
        ret
217
 
 
218
 
        .p2align 4
219
 
L(matches0):
220
 
        bsr     %eax, %eax
221
 
        add     %rdi, %rax
222
 
        ret
223
 
 
224
 
        .p2align 4
225
 
L(matches16):
226
 
        bsr     %eax, %eax
227
 
        lea     16(%rax, %rdi), %rax
228
 
        ret
229
 
 
230
 
        .p2align 4
231
 
L(matches32):
232
 
        bsr     %eax, %eax
233
 
        lea     32(%rax, %rdi), %rax
234
 
        ret
235
 
 
236
 
        .p2align 4
237
 
L(matches48):
238
 
        bsr     %eax, %eax
239
 
        lea     48(%rax, %rdi), %rax
240
 
        ret
241
 
 
242
 
        .p2align 4
243
 
L(matches0_1):
244
 
        bsr     %eax, %eax
245
 
        sub     $64, %rdx
246
 
        add     %rax, %rdx
247
 
        jl      L(return_null)
248
 
        add     %rdi, %rax
249
 
        ret
250
 
 
251
 
        .p2align 4
252
 
L(matches16_1):
253
 
        bsr     %eax, %eax
254
 
        sub     $48, %rdx
255
 
        add     %rax, %rdx
256
 
        jl      L(return_null)
257
 
        lea     16(%rdi, %rax), %rax
258
 
        ret
259
 
 
260
 
        .p2align 4
261
 
L(matches32_1):
262
 
        bsr     %eax, %eax
263
 
        sub     $32, %rdx
264
 
        add     %rax, %rdx
265
 
        jl      L(return_null)
266
 
        lea     32(%rdi, %rax), %rax
267
 
        ret
268
 
 
269
 
        .p2align 4
270
 
L(matches48_1):
271
 
        bsr     %eax, %eax
272
 
        sub     $16, %rdx
273
 
        add     %rax, %rdx
274
 
        jl      L(return_null)
275
 
        lea     48(%rdi, %rax), %rax
276
 
        ret
277
 
 
278
 
        .p2align 4
279
 
L(return_null):
280
 
        xor     %rax, %rax
281
 
        ret
282
 
 
283
 
        .p2align 4
284
 
L(length_less16_offset0):
285
 
        test    %edx, %edx
286
 
        jz      L(return_null)
287
 
 
288
 
        mov     %dl, %cl
289
 
        pcmpeqb (%rdi), %xmm1
290
 
 
291
 
        mov     $1, %edx
292
 
        sal     %cl, %edx
293
 
        sub     $1, %edx
294
 
 
295
 
        pmovmskb        %xmm1, %eax
296
 
 
297
 
        and     %edx, %eax
298
 
        test    %eax, %eax
299
 
        jz      L(return_null)
300
 
 
301
 
        bsr     %eax, %eax
302
 
        add     %rdi, %rax
303
 
        ret
304
 
 
305
 
        .p2align 4
306
 
L(length_less16):
307
 
        punpcklbw       %xmm1, %xmm1
308
 
        punpcklbw       %xmm1, %xmm1
309
 
 
310
 
        add     $16, %rdx
311
 
 
312
 
        pshufd  $0, %xmm1, %xmm1
313
 
 
314
 
        mov     %rdi, %rcx
315
 
        and     $15, %rcx
316
 
        jz      L(length_less16_offset0)
317
 
 
318
 
        mov     %rdi, %rcx
319
 
        and     $15, %rcx
320
 
        mov     %cl, %dh
321
 
        mov     %rcx, %r8
322
 
        add     %dl, %dh
323
 
        and     $-16, %rdi
324
 
 
325
 
        sub     $16, %dh
326
 
        ja      L(length_less16_part2)
327
 
 
328
 
        pcmpeqb (%rdi), %xmm1
329
 
        pmovmskb        %xmm1, %eax
330
 
 
331
 
        sar     %cl, %eax
332
 
        mov     %dl, %cl
333
 
 
334
 
        mov     $1, %edx
335
 
        sal     %cl, %edx
336
 
        sub     $1, %edx
337
 
 
338
 
        and     %edx, %eax
339
 
        test    %eax, %eax
340
 
        jz      L(return_null)
341
 
 
342
 
        bsr     %eax, %eax
343
 
        add     %rdi, %rax
344
 
        add     %r8, %rax
345
 
        ret
346
 
 
347
 
        .p2align 4
348
 
L(length_less16_part2):
349
 
        movdqa  16(%rdi), %xmm2
350
 
        pcmpeqb %xmm1, %xmm2
351
 
        pmovmskb        %xmm2, %eax
352
 
 
353
 
        mov     %dh, %cl
354
 
        mov     $1, %edx
355
 
        sal     %cl, %edx
356
 
        sub     $1, %edx
357
 
 
358
 
        and     %edx, %eax
359
 
 
360
 
        test    %eax, %eax
361
 
        jnz     L(length_less16_part2_return)
362
 
 
363
 
        pcmpeqb (%rdi), %xmm1
364
 
        pmovmskb        %xmm1, %eax
365
 
 
366
 
        mov     %r8, %rcx
367
 
        sar     %cl, %eax
368
 
        test    %eax, %eax
369
 
        jz      L(return_null)
370
 
 
371
 
        bsr     %eax, %eax
372
 
        add     %rdi, %rax
373
 
        add     %r8, %rax
374
 
        ret
375
 
 
376
 
        .p2align 4
377
 
L(length_less16_part2_return):
378
 
        bsr     %eax, %eax
379
 
        lea     16(%rax, %rdi), %rax
380
 
        ret
381
 
 
382
 
END (memrchr)
383
 
strong_alias (memrchr, __memrchr)