From 772e87739c848a10a014d3118ff14bd0ca48b2d0 Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Tue, 2 Oct 2018 08:55:29 +0200 Subject: Replace memory.op.cmp with optimized equal version Deprecate cmp. Fix #68. --- arch/build.ninja | 4 +-- arch/x64/linux/memory/cmp.S | 67 ------------------------------------------- arch/x64/linux/memory/equal.S | 59 +++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 69 deletions(-) delete mode 100644 arch/x64/linux/memory/cmp.S create mode 100644 arch/x64/linux/memory/equal.S (limited to 'arch') diff --git a/arch/build.ninja b/arch/build.ninja index 824efa4..cf05696 100644 --- a/arch/build.ninja +++ b/arch/build.ninja @@ -6,9 +6,9 @@ rule archive build abs.o: gas x64/linux/math/abs.S build log.o: gas x64/linux/math/log.S -build cmp.o: gas x64/linux/memory/cmp.S +build equal.o: gas x64/linux/memory/equal.S build fill.o: gas x64/linux/memory/fill.S build copy.o: gas x64/linux/memory/copy.S build syscall.o: gas x64/linux/syscall.S -build tanya.a: archive syscall.o copy.o fill.o cmp.o log.o abs.o +build tanya.a: archive syscall.o copy.o fill.o equal.o log.o abs.o diff --git a/arch/x64/linux/memory/cmp.S b/arch/x64/linux/memory/cmp.S deleted file mode 100644 index bd9f02e..0000000 --- a/arch/x64/linux/memory/cmp.S +++ /dev/null @@ -1,67 +0,0 @@ - .text - -/* - * cmpMemory. - * - * rdi - r1 length - * rsi - r1 data. - * rdx - r2 length. - * rcx - r2 data. - */ - .globl _D5tanya6memory2op9cmpMemoryFNaNbNixAvxQdZi - .type _D5tanya6memory2op9cmpMemoryFNaNbNixAvxQdZi, @function -_D5tanya6memory2op9cmpMemoryFNaNbNixAvxQdZi: - // Compare the lengths - cmp %rdx, %rdi - jl less - jg greater - - mov %rcx, %rdi - - // Check if we're aligned - cmp $0x08, %rdx - jc aligned_1 - test $0x07, %edi - jz aligned_8 - - naligned: - cmpsb - jl less - jg greater - - dec %rdx - test $0x07, %edi - jnz naligned - - aligned_8: - mov %rdx, %rcx - shr $0x03, %rcx - - repe cmpsq - jl less - jg greater - - and $0x07, %edx - jz equal - - aligned_1: // Compare the remaining bytes - mov %rdx, %rcx - cmp $0x0, %rcx - - repe cmpsb - jl less - jg greater - - equal: - xor %rax, %rax // Return 0 - jmp end - - greater: - mov $0x01, %rax - jmp end - - less: - mov $-0x01, %rax - - end: - ret diff --git a/arch/x64/linux/memory/equal.S b/arch/x64/linux/memory/equal.S new file mode 100644 index 0000000..37a906a --- /dev/null +++ b/arch/x64/linux/memory/equal.S @@ -0,0 +1,59 @@ + .text + +/* + * equalMemory. + * + * rdi - r1 length + * rsi - r1 data. + * rdx - r2 length. + * rcx - r2 data. + */ + .globl _D5tanya6memory2op11equalMemoryFNaNbNixAvxQdZb + .type _D5tanya6memory2op11equalMemoryFNaNbNixAvxQdZb, @function +_D5tanya6memory2op11equalMemoryFNaNbNixAvxQdZb: + // Compare the lengths + cmp %rdx, %rdi + jne not_equal + + mov %rcx, %rdi + + // Check if we're aligned + cmp $0x08, %rdx + jc aligned_1 + test $0x07, %edi + jz aligned_8 + + naligned: + cmpsb + jne not_equal + + dec %rdx + test $0x07, %edi + jnz naligned + + aligned_8: + mov %rdx, %rcx + shr $0x03, %rcx + + repe cmpsq + jne not_equal + + and $0x07, %edx + jz equal + + aligned_1: // Compare the remaining bytes + mov %rdx, %rcx + cmp $0x0, %rcx + + repe cmpsb + jne not_equal + + equal: + mov $0x01, %rax // Return 1 + jmp end + + not_equal: + xor %rax, %rax // Return 0 + + end: + ret -- cgit v1.2.3