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_hexdec.S | 36 ++++++++++++++++++------------------ src/u_strncmp.S | 33 +++++++++++++++++++++++++++++---- 2 files changed, 47 insertions(+), 22 deletions(-) diff --git a/src/u_hexdec.S b/src/u_hexdec.S index a362ba6..5e0f019 100644 --- a/src/u_hexdec.S +++ b/src/u_hexdec.S @@ -49,24 +49,24 @@ .globl u_hexdec u_hexdec: - xor %r10, %r10 - xor %r9, %r9 - xor %r8, %r8 - mov $0xa, %rbx - clc + xor %r10, %r10 + xor %r9, %r9 + xor %r8, %r8 + mov $0xa, %rbx + clc .u.repeat: - xor %rdx, %rdx - idiv %rbx - or $0x0, %dl - mov $0x8, %rcx + xor %rdx, %rdx + idiv %rbx + or $0x0, %dl + mov $0x8, %rcx .u.shift: - rcrb $0x1, %dl - rcr $0x1, %r10 - rcr $0x1, %r9 - rcr $0x1, %r8 - dec %rcx - and %rcx, %rcx - jnz .u.shift - and %rax, %rax - jnz .u.repeat + rcrb $0x1, %dl + rcr $0x1, %r10 + rcr $0x1, %r9 + rcr $0x1, %r8 + dec %rcx + and %rcx, %rcx + jnz .u.shift + and %rax, %rax + jnz .u.repeat ret 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