blob: ec5e1fa51610217447be79500e956c8e4f03472f (
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
|
/*
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/.
*/
#include <rgo-priv.h>
#if defined(rgo_priv_fastimpl)
__asm__ (
".global rgo_memfill\n"
"rgo_memfill:\n"
/*
void const * ptr
sus_typ_usz num
sus_typ_u8 val
*/
#if defined(sus_arch_amd64)
/* rdi: Address of the current element. */
/* rsi: Address of the element after the last element. */
"addq %rdi,%rsi\n"
".loop:\n"
"cmpq %rsi,%rdi\n"
"je .done\n" /* Exit loop if we have reached the final element. */
"movb %dl,(%rdi)\n"
"incq %rdi\n"
"jmp .loop\n" /* Continue to next element. */
".done:\n"
"ret\n"
#elif defined(sus_arch_ia32)
/* eax: Address of the current element. */
"movl 0x4(%esp),%eax\n"
/* ecx: Address of the element after the last element. */
"movl 0x4(%esp),%ecx\n"
"addl 0x8(%esp),%ecx\n"
/* edx: Byte value. */
"movb 0xC(%esp),%dl\n"
".loop:\n"
"cmpl %eax,%ecx\n"
"je .done\n" /* Exit loop if we have reached the final element. */
"movb %dl,(%eax)\n"
"incl %eax\n"
"jmp .loop\n" /* Continue to next element. */
".done:\n"
"ret\n"
#endif
);
#else
void rgo_memfill(void * const sus_restr _ptr,sus_typ_usz const _num,sus_typ_u8 const _byte) {
sus_typ_u8 * pos = (sus_typ_u8 *)_ptr;
sus_typ_u8 * const afterbuf = pos + _num;
for (;pos != afterbuf;++pos) {*pos = _byte;}
}
#endif
|