/* Copyright 2022 Gabriel Jensen This file is part of rgo. rgo is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. rgo is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with rgo. If not, see . */ #include .global rgo_memeq rgo_memeq: #if defined(__x86_64__) /* rdi: void const * lptr rsi: size_t num rdx: void const * rptr */ /* rcx: Address of the current left element. */ movq %rdi,%rcx /* r8: Address of the current right element. */ movq %rdx,%r8 /* r9: Number of remaining elements. */ movq %rsi,%r9 /* r10: Temporary. */ /* r11: Temporary. */ .wrdeq: cmpq $0x8,%r9 jl .byteeq movq (%rcx),%r10 movq (%r8),%r11 cmpq %r10,%r11 jz .neq addq $0x8,%rcx addq $0x8,%r8 subq $0x8,%r9 jmp .wrdeq .byteeq: testq %r9,%r9 jz .eq /* If we have reached the final element, all previous elements have compared equal, and the memory sequences are equal. */ movb (%rcx),%r10b movb (%r8),%r11b cmpb %r10b,%r11b jne .neq incq %rcx incq %r8 decq %r9 jmp .byteeq .eq: mov $0x1,%rax ret .neq: mov $0x0,%rax ret #endif