clarify the purpose of this project
[nyanglibc.git] / string / memmem.s
blobfa6af252beafcecb238ce918ab8f1b87ef7a45be
1 .text
2 .p2align 4,,15
3 .type two_way_long_needle, @function
4 two_way_long_needle:
5 pushq %r15
6 pushq %r14
7 movq %rdi, %r15
8 pushq %r13
9 pushq %r12
10 movq %rsi, %r14
11 pushq %rbp
12 pushq %rbx
13 movq %rdx, %rbp
14 movq %rcx, %rbx
15 movl $1, %edi
16 movl $1, %edx
17 subq $2088, %rsp
18 xorl %ecx, %ecx
19 movq $-1, %rsi
20 .L2:
21 leaq (%rdx,%rcx), %rax
22 cmpq %rax, %rbx
23 jbe .L71
24 .L7:
25 leaq 0(%rbp,%rsi), %r8
26 movzbl (%r8,%rdx), %r11d
27 cmpb %r11b, 0(%rbp,%rax)
28 jnb .L3
29 movq %rax, %rcx
30 movl $1, %edx
31 movq %rax, %rdi
32 leaq (%rdx,%rcx), %rax
33 subq %rsi, %rdi
34 cmpq %rax, %rbx
35 ja .L7
36 .L71:
37 movl $1, %r8d
38 movl $1, %edx
39 xorl %ecx, %ecx
40 movq $-1, %r13
41 .L8:
42 leaq (%rdx,%rcx), %rax
43 cmpq %rax, %rbx
44 jbe .L72
45 .L13:
46 leaq 0(%rbp,%r13), %r9
47 movzbl (%r9,%rdx), %r10d
48 cmpb %r10b, 0(%rbp,%rax)
49 jbe .L9
50 movq %rax, %rcx
51 movl $1, %edx
52 movq %rax, %r8
53 leaq (%rdx,%rcx), %rax
54 subq %r13, %r8
55 cmpq %rax, %rbx
56 ja .L13
57 .L72:
58 addq $1, %r13
59 addq $1, %rsi
60 cmpq %rsi, %r13
61 jnb .L14
62 movq %rdi, %r8
63 movq %rsi, %r13
64 .L14:
65 leaq 32(%rsp), %rax
66 leaq 2080(%rsp), %rdx
67 .p2align 4,,10
68 .p2align 3
69 .L15:
70 movq %rbx, (%rax)
71 addq $8, %rax
72 cmpq %rax, %rdx
73 jne .L15
74 testq %rbx, %rbx
75 leaq -1(%rbx), %r12
76 je .L16
77 movq %rbp, %rdx
78 movq %r12, %rax
79 .p2align 4,,10
80 .p2align 3
81 .L17:
82 movzbl (%rdx), %ecx
83 addq $1, %rdx
84 movq %rax, 32(%rsp,%rcx,8)
85 subq $1, %rax
86 cmpq $-1, %rax
87 jne .L17
88 .L16:
89 leaq 0(%rbp,%r8), %rsi
90 movq %r13, %rdx
91 movq %rbp, %rdi
92 movq %r8, 8(%rsp)
93 call memcmp@PLT
94 testl %eax, %eax
95 jne .L18
96 leaq -1(%r13), %r11
97 movq 8(%rsp), %r8
98 movq %rbx, %r10
99 xorl %esi, %esi
100 xorl %edx, %edx
101 subq %rbx, %r14
102 leaq 0(%rbp,%r11), %rax
103 subq %r8, %r10
104 movq %rax, 24(%rsp)
105 movl $1, %eax
106 subq %r13, %rax
107 movq %rax, 8(%rsp)
108 jmp .L29
109 .p2align 4,,10
110 .p2align 3
111 .L73:
112 cmpq %r8, %rcx
113 jnb .L67
114 testq %rsi, %rsi
115 cmovne %r10, %rcx
116 .L67:
117 addq %rcx, %rdx
118 xorl %esi, %esi
119 cmpq %rdx, %r14
120 jb .L69
121 .L29:
122 leaq (%r15,%rdx), %rax
123 movzbl (%rax,%r12), %ecx
124 movq 32(%rsp,%rcx,8), %rcx
125 testq %rcx, %rcx
126 jne .L73
127 cmpq %rsi, %r13
128 movq %rsi, %rcx
129 cmovnb %r13, %rcx
130 leaq (%rcx,%rdx), %rdi
131 leaq 0(%rbp,%rcx), %r9
132 addq %r15, %rdi
133 cmpq %rcx, %r12
134 jbe .L22
135 movzbl (%r9), %ebx
136 cmpb %bl, (%rdi)
137 je .L24
138 jmp .L23
139 .p2align 4,,10
140 .p2align 3
141 .L74:
142 movzbl (%rax,%rcx), %edi
143 cmpb %dil, 0(%rbp,%rcx)
144 jne .L23
145 .L24:
146 addq $1, %rcx
147 cmpq %rcx, %r12
148 ja .L74
149 .L22:
150 leaq (%r11,%rdx), %r9
151 movq %r11, %rdi
152 addq %r15, %r9
153 cmpq %rsi, %r13
154 jbe .L40
155 movq 24(%rsp), %rbx
156 movzbl (%rbx), %ebx
157 cmpb %bl, (%r9)
158 jne .L40
159 leaq -1(%rsi), %rbx
160 subq %r13, %r9
161 movq %rax, 16(%rsp)
162 jmp .L26
163 .p2align 4,,10
164 .p2align 3
165 .L75:
166 movzbl 1(%rcx,%r9), %eax
167 cmpb %al, 0(%rbp,%rcx)
168 jne .L65
169 movq %rcx, %rdi
170 .L26:
171 leaq -1(%rdi), %rcx
172 cmpq %rcx, %rbx
173 jne .L75
174 .L65:
175 movq 16(%rsp), %rax
176 .L25:
177 addq $1, %rsi
178 cmpq %rdi, %rsi
179 ja .L1
180 addq %r8, %rdx
181 movq %r10, %rsi
182 cmpq %rdx, %r14
183 jnb .L29
184 .L69:
185 xorl %eax, %eax
186 .L1:
187 addq $2088, %rsp
188 popq %rbx
189 popq %rbp
190 popq %r12
191 popq %r13
192 popq %r14
193 popq %r15
195 .p2align 4,,10
196 .p2align 3
197 .L3:
198 je .L76
199 movq %rcx, %rsi
200 movl $1, %edi
201 addq $1, %rcx
202 movl $1, %edx
203 jmp .L2
204 .p2align 4,,10
205 .p2align 3
206 .L9:
207 je .L77
208 movq %rcx, %r13
209 movl $1, %r8d
210 addq $1, %rcx
211 movl $1, %edx
212 jmp .L8
213 .p2align 4,,10
214 .p2align 3
215 .L23:
216 addq 8(%rsp), %rdx
217 jmp .L67
218 .L77:
219 cmpq %r8, %rdx
220 je .L12
221 addq $1, %rdx
222 jmp .L8
223 .L76:
224 cmpq %rdi, %rdx
225 je .L6
226 addq $1, %rdx
227 jmp .L2
228 .L18:
229 movq %rbx, %rax
230 movl $1, %edi
231 leaq 0(%rbp,%r13), %r8
232 subq %r13, %rax
233 cmpq %r13, %rax
234 cmovb %r13, %rax
235 xorl %ecx, %ecx
236 subq %r13, %rdi
237 leaq 1(%rax), %rsi
238 subq %rbx, %r14
239 .p2align 4,,10
240 .p2align 3
241 .L38:
242 leaq (%r15,%rcx), %rax
243 movzbl (%rax,%r12), %edx
244 movq 32(%rsp,%rdx,8), %rdx
245 testq %rdx, %rdx
246 jne .L68
247 leaq (%rcx,%r13), %rdx
248 addq %r15, %rdx
249 cmpq %r13, %r12
250 jbe .L32
251 movzbl (%rdx), %ebx
252 movq %r13, %rdx
253 cmpb %bl, (%r8)
254 je .L34
255 jmp .L33
256 .p2align 4,,10
257 .p2align 3
258 .L78:
259 movzbl (%rax,%rdx), %ebx
260 cmpb %bl, 0(%rbp,%rdx)
261 jne .L33
262 .L34:
263 addq $1, %rdx
264 cmpq %rdx, %r12
265 ja .L78
266 .L32:
267 leaq -1(%r13), %rdx
268 leaq (%rcx,%rdx), %r9
269 leaq 0(%rbp,%rdx), %r10
270 addq %r15, %r9
271 cmpq $-1, %rdx
272 je .L1
273 movzbl (%r10), %ebx
274 cmpb %bl, (%r9)
275 jne .L36
276 subq %r13, %r9
277 jmp .L37
278 .p2align 4,,10
279 .p2align 3
280 .L79:
281 movzbl 1(%rdx,%r9), %ebx
282 cmpb %bl, 0(%rbp,%rdx)
283 jne .L36
284 .L37:
285 subq $1, %rdx
286 cmpq $-1, %rdx
287 jne .L79
288 jmp .L1
289 .p2align 4,,10
290 .p2align 3
291 .L33:
292 addq %rdi, %rcx
293 .L68:
294 addq %rdx, %rcx
295 .L31:
296 cmpq %r14, %rcx
297 jbe .L38
298 xorl %eax, %eax
299 jmp .L1
300 .L36:
301 addq %rsi, %rcx
302 jmp .L31
303 .L12:
304 movq %rax, %rcx
305 movl $1, %edx
306 jmp .L8
307 .L6:
308 movq %rax, %rcx
309 movl $1, %edx
310 jmp .L2
311 .L40:
312 movq %r13, %rdi
313 jmp .L25
314 .size two_way_long_needle, .-two_way_long_needle
315 .p2align 4,,15
316 .globl __memmem
317 .hidden __memmem
318 .type __memmem, @function
319 __memmem:
320 pushq %r15
321 pushq %r14
322 pushq %r13
323 pushq %r12
324 pushq %rbp
325 pushq %rbx
326 movq %rdi, %rbx
327 subq $280, %rsp
328 testq %rcx, %rcx
329 je .L100
330 cmpq $1, %rcx
331 movq %rdx, %r15
332 movq %rcx, %rbp
333 je .L123
334 cmpq %rsi, %rcx
335 ja .L101
336 movq %rsi, %r14
337 subq %rcx, %r14
338 addq %rdi, %r14
339 cmpq $2, %rcx
340 je .L124
341 cmpq $256, %rcx
342 ja .L125
343 leaq -1(%rcx), %r13
344 leaq 16(%rsp), %rdx
345 xorl %eax, %eax
346 movl $32, %ecx
347 movq %rdx, %rdi
348 cmpq $1, %r13
349 rep stosq
350 jbe .L90
351 movl $1, %eax
352 .p2align 4,,10
353 .p2align 3
354 .L91:
355 movzbl -1(%r15,%rax), %ecx
356 movzbl (%r15,%rax), %edx
357 salq $3, %rcx
358 subq %rcx, %rdx
359 movzbl %dl, %edx
360 movb %al, 16(%rsp,%rdx)
361 addq $1, %rax
362 cmpq %rax, %r13
363 jne .L91
364 .L90:
365 movzbl -2(%r15,%rbp), %edx
366 movzbl -1(%r15,%rbp), %eax
367 movq %r13, %rdi
368 xorl %r12d, %r12d
369 subq $9, %rbp
370 salq $3, %rdx
371 subq %rdx, %rax
372 movzbl %al, %eax
373 movzbl 16(%rsp,%rax), %edx
374 movb %r13b, 16(%rsp,%rax)
375 subq %rdx, %rdi
376 movq %rdi, 8(%rsp)
377 .L95:
378 cmpq %rbx, %r14
379 jnb .L93
380 jmp .L101
381 .p2align 4,,10
382 .p2align 3
383 .L126:
384 cmpq %rbx, %r14
385 jb .L103
386 .L93:
387 addq %r13, %rbx
388 movzbl -1(%rbx), %edx
389 movzbl (%rbx), %eax
390 salq $3, %rdx
391 subq %rdx, %rax
392 movzbl %al, %eax
393 movzbl 16(%rsp,%rax), %eax
394 testq %rax, %rax
395 je .L126
396 .L103:
397 subq %rax, %rbx
398 cmpq %rax, %r13
399 ja .L95
400 cmpq $14, %r13
401 jbe .L96
402 movq (%r15,%r12), %rax
403 cmpq %rax, (%rbx,%r12)
404 jne .L97
405 .L96:
406 movq %r13, %rdx
407 movq %r15, %rsi
408 movq %rbx, %rdi
409 call memcmp@PLT
410 testl %eax, %eax
411 je .L100
412 leaq -8(%r12), %rax
413 cmpq $8, %r12
414 cmovb %rbp, %rax
415 movq %rax, %r12
416 .L97:
417 addq 8(%rsp), %rbx
418 cmpq %rbx, %r14
419 jnb .L93
420 .L101:
421 xorl %eax, %eax
422 jmp .L80
423 .p2align 4,,10
424 .p2align 3
425 .L100:
426 movq %rbx, %rax
427 .L80:
428 addq $280, %rsp
429 popq %rbx
430 popq %rbp
431 popq %r12
432 popq %r13
433 popq %r14
434 popq %r15
436 .p2align 4,,10
437 .p2align 3
438 .L123:
439 movzbl (%rdx), %eax
440 addq $280, %rsp
441 movq %rsi, %rdx
442 popq %rbx
443 popq %rbp
444 popq %r12
445 popq %r13
446 popq %r14
447 popq %r15
448 movl %eax, %esi
449 jmp memchr
450 .p2align 4,,10
451 .p2align 3
452 .L124:
453 movzbl (%rdx), %edx
454 movzbl 1(%r15), %eax
455 addq $1, %rbx
456 movzbl 1(%rdi), %ecx
457 sall $16, %edx
458 orl %eax, %edx
459 movzbl (%rdi), %eax
460 sall $16, %eax
461 orl %ecx, %eax
462 cmpq %rbx, %r14
463 jnb .L122
464 jmp .L84
465 .p2align 4,,10
466 .p2align 3
467 .L127:
468 addq $1, %rbx
469 movzbl (%rbx), %ecx
470 sall $16, %eax
471 orl %ecx, %eax
472 cmpq %rbx, %r14
473 jb .L84
474 .L122:
475 cmpl %eax, %edx
476 jne .L127
477 .L84:
478 cmpl %eax, %edx
479 jne .L101
480 leaq -1(%rbx), %rax
481 jmp .L80
482 .L125:
483 addq $280, %rsp
484 popq %rbx
485 popq %rbp
486 popq %r12
487 popq %r13
488 popq %r14
489 popq %r15
490 jmp two_way_long_needle
491 .size __memmem, .-__memmem
492 .weak memmem
493 .hidden memmem
494 .set memmem,__memmem
495 .hidden memchr