From c08c4e921efd160c10837a285b861d7b856af9c1 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Sat, 21 Nov 2020 17:12:07 +0000 Subject: Good strncmp FossilOrigin-Name: 13514fe09602541bff74c6af14bbf6db06f5030e --- src/u_strncmp.S | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) (limited to 'src/u_strncmp.S') diff --git a/src/u_strncmp.S b/src/u_strncmp.S index 9c90cd0..aafa721 100644 --- a/src/u_strncmp.S +++ b/src/u_strncmp.S @@ -49,8 +49,33 @@ .globl u_strncmp u_strncmp: -# xor %rcx, %rcx -# dec %rdx -#.u.loop -# cmpb (%rsi) + xor %rcx, %rcx + dec %rdx +.u.loop: + xor %r8, %r8 + xor %r9, %r9 + movb (%rdi, %rcx), %r8b + movb (%rsi, %rcx), %r9b + cmpb %r8b, %r9b + jne .u.retdiff + cmp %rdx, %rcx + jge .u.retdiff + cmpb $0x0, (%rdi, %rcx) + jne .u.inc + cmpb $0x0, (%rsi, %rcx) + je .u.retzer +.u.inc: + inc %rcx + jmp .u.loop +.u.retdiff: + xor %r8, %r8 + xor %r9, %r9 + movb (%rdi, %rcx), %r8b + movb (%rsi, %rcx), %r9b + sub %r9, %r8 + xor %rax, %rax + movl %r8d, %eax + ret +.u.retzer: + xor %rax, %rax ret -- cgit v1.2.3