# Copyright 2022 Gabriel Jensen. # This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. # If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/. .globl zap_memeq zap_memeq: /* rdi: Left pointer. */ /* rsi: Number of remaining elements. */ /* rdx: Right pointer. */ /* rax: Current left element. */ /* rcx: Current right element. */ /* Compare words: */ .wrdcmp: /* Check if there's at least one word left: */ cmpq $0x8,%rsi jl .bytecmp /* If not, skip to byte checks: */ /* Copy the values into registers: */ movq (%rdi),%rax movq (%rdx),%rcx /* Check if the words are equal: */ cmpq %rax,%rcx jne .neq /* Mark eight more bytes as equal: */ addq $0x8,%rdi addq $0x8,%rdx subq $0x8,%rsi /* Continue to the next word: */ jmp .wrdcmp /* 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. */ /* Copy the values into registers: */ movb (%rdi),%al movb (%rdx),%cl cmpb %al,%cl jne .neq /* Mark another byte as equal: */ incq %rdi incq %rdx decq %rsi /* Continue to the next byte: */ jmp .bytecmp /* The memory sequences have compared equal: */ .eq: movb $0xFF,%al ret /* The memory sequences have compared NOT equal: */ .neq: movb $0x0,%al ret