summaryrefslogtreecommitdiff
path: root/arch/x64/linux/memory/cmp.S
diff options
context:
space:
mode:
Diffstat (limited to 'arch/x64/linux/memory/cmp.S')
-rw-r--r--arch/x64/linux/memory/cmp.S67
1 files changed, 67 insertions, 0 deletions
diff --git a/arch/x64/linux/memory/cmp.S b/arch/x64/linux/memory/cmp.S
new file mode 100644
index 0000000..169e2eb
--- /dev/null
+++ b/arch/x64/linux/memory/cmp.S
@@ -0,0 +1,67 @@
+ .text
+
+/*
+ * cmpMemory.
+ *
+ * rdi - r1 length
+ * rsi - r1 data.
+ * rdx - r2 length.
+ * rcx - r2 data.
+ */
+ .globl _D5tanya6memory2op9cmpMemoryFNaNbNixAvxAvZi
+ .type _D5tanya6memory2op9cmpMemoryFNaNbNixAvxAvZi, @function
+
+_D5tanya6memory2op9cmpMemoryFNaNbNixAvxAvZi:
+ // 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
+
+ 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