summaryrefslogtreecommitdiff
path: root/rgo/src/memeq.S
blob: c3a9a63420b7880aa9dd56a4816a7d4e2dcab85e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
	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 <https://www.gnu.org/licenses/>. 
*/

#include <rgo.h>

.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