summaryrefslogtreecommitdiff
path: root/zap/source/amd64/mem/memeq.S
diff options
context:
space:
mode:
Diffstat (limited to 'zap/source/amd64/mem/memeq.S')
-rw-r--r--zap/source/amd64/mem/memeq.S87
1 files changed, 47 insertions, 40 deletions
diff --git a/zap/source/amd64/mem/memeq.S b/zap/source/amd64/mem/memeq.S
index ba43dfc..b30a884 100644
--- a/zap/source/amd64/mem/memeq.S
+++ b/zap/source/amd64/mem/memeq.S
@@ -5,63 +5,70 @@
.globl zap_memeq
zap_memeq:
- /* rdi: Left pointer. */
- /* rsi: Number of remaining elements. */
- /* rdx: Right pointer. */
- /* rax: Current left element. */
- /* rcx: Current right element. */
+# Left pointer:
+#define laddr %rdi
+# Number of remaining elements:
+#define rem %rsi
+# Right pointer:
+#define raddr %rdx
+# Current left element:
+#define lval8 %rax
+#define lval1 %al
+# Current right element:
+#define rval8 %rcx
+#define rval1 %cl
- /* Compare words: */
+ # Compare words:
.wrdcmp:
- /* Check if there's at least one word left: */
- cmpq $0x8,%rsi
- jl .bytecmp /* If not, skip to byte checks: */
+ # Check if there's at least one word left:
+ cmpq $0x8,rem # if (rem == 8)
+ jl .bytecmp # goto bytecmp
- /* Copy the values into registers: */
- movq (%rdi),%rax
- movq (%rdx),%rcx
+ # Copy the values into registers:
+ movq (laddr),lval8 # lval8 = *laddr
+ movq (raddr),rval8 # rval8 = *raddr
- /* Check if the words are equal: */
- cmpq %rax,%rcx
- jne .neq
+ # Check if the words are equal:
+ cmpq lval8,rval8 # if (lval8 != rval8)
+ jne .neq # goto neq
- /* Mark eight more bytes as equal: */
- addq $0x8,%rdi
- addq $0x8,%rdx
- subq $0x8,%rsi
+ # Mark eight more bytes as equal:
+ addq $0x8,laddr # laddr += 0x8
+ addq $0x8,raddr # raddr += 0x8
+ subq $0x8,rem # rem -= 0x8
- /* Continue to the next word: */
- jmp .wrdcmp
+ # Continue to the next word:
+ jmp .wrdcmp # goto wrdcmp
- /* Compare bytes: */
+ # Compare bytes:
.bytecmp:
- /* Check if there are any bytes left: */
- testq %rsi,%rsi
- jz .eq /* If we have reached the final element, all previous elements have compared equal, and the memory sequences are equal. */
+ # Check if there are any bytes left:
+ testq rem,rem # if (rem == 0x0)
+ jz .eq # goto eq // If we have reached the final element, all previous elements have compared equal, and the memory sequences are equal.
- /* Copy the values into registers: */
- movb (%rdi),%al
- movb (%rdx),%cl
+ # Copy the values into registers:
+ movb (laddr),lval1 # lval1 = *laddr
+ movb (raddr),rval1 # rval1 = *raddr
- cmpb %al,%cl
- jne .neq
+ cmpb lval1,rval1 # if (lval1 != rval1)
+ jne .neq # goto neq
- /* Mark another byte as equal: */
- incq %rdi
- incq %rdx
- decq %rsi
+ # Mark another byte as equal:
+ incq laddr # ++laddr
+ incq raddr # ++raddr
+ decq rem # --rem
- /* Continue to the next byte: */
- jmp .bytecmp
+ # Continue to the next byte:
+ jmp .bytecmp # goto bytecmp
- /* The memory sequences have compared equal: */
+ # The memory sequences have compared equal:
.eq:
movb $0xFF,%al
- ret
+ ret # return FF
- /* The memory sequences have compared NOT equal: */
+ # The memory sequences have compared NOT equal:
.neq:
movb $0x0,%al
- ret
+ ret # return 0