1/* $OpenBSD: strcmp.S,v 1.7 2015/11/14 21:53:03 guenther Exp $ */ 2/* $NetBSD: strcmp.S,v 1.2 2014/03/22 19:16:34 jakllsch Exp $ */ 3 4/* 5 * Written by J.T. Conklin <jtc@acorntoolworks.com> 6 * Public domain. 7 */ 8 9#include "DEFS.h" 10 11ENTRY(strcmp) 12 /* 13 * Align s1 to word boundary. 14 * Consider unrolling loop? 15 */ 16.Ls1align: 17 testb $7,%dil 18 je .Ls1aligned 19 movb (%rdi),%al 20 incq %rdi 21 movb (%rsi),%dl 22 incq %rsi 23 testb %al,%al 24 je .Ldone 25 cmpb %al,%dl 26 je .Ls1align 27 jmp .Ldone 28 29 /* 30 * Check whether s2 is aligned to a word boundary. If it is, we 31 * can compare by words. Otherwise we have to compare by bytes. 32 */ 33.Ls1aligned: 34 testb $7,%sil 35 jne .Lbyte_loop 36 37 movabsq $0x0101010101010101,%r8 38 subq $8,%rdi 39 movabsq $0x8080808080808080,%r9 40 subq $8,%rsi 41 42 _ALIGN_TEXT 43.Lword_loop: 44 movq 8(%rdi),%rax 45 addq $8,%rdi 46 movq 8(%rsi),%rdx 47 addq $8,%rsi 48 cmpq %rax,%rdx 49 jne .Lbyte_loop 50 subq %r8,%rdx 51 notq %rax 52 andq %rax,%rdx 53 testq %r9,%rdx 54 je .Lword_loop 55 56 _ALIGN_TEXT 57.Lbyte_loop: 58 movb (%rdi),%al 59 incq %rdi 60 movb (%rsi),%dl 61 incq %rsi 62 testb %al,%al 63 je .Ldone 64 cmpb %al,%dl 65 je .Lbyte_loop 66 67.Ldone: 68 movzbq %al,%rax 69 movzbq %dl,%rdx 70 subq %rdx,%rax 71 ret 72END_STRONG(strcmp) 73