summaryrefslogtreecommitdiff
path: root/lib/std/memops-impl+posixy-x64.s
blob: c2a3d141f3fcf064fe83f0798e5b6c8296d6588f (plain)
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
/*
std.memblit	: (dst : byte#, src : byte#, len : std.size -> void)
std.memfill	: (dst : byte#, val : byte, len : std.size -> void)
*/
.globl _std$memblit
.globl std$memblit
_std$memblit:
std$memblit:
	cmpq	%rdi,%rsi
	movq	%rdx,%rcx
	jz	.done
	jg	.fwdcpy
	movq	%rsi,%rax
	subq	%rdi,%rax
	cmpq	%rax,%rcx
	jg	.revcpy
.fwdcpy:
	shrq	$3,%rcx
	rep  movsq
	movq	%rdx,%rcx
	andq	$7,%rcx
	rep  movsb
	jmp	.done
.revcpy:
	std
	leaq	-1(%rdx,%rsi),%rsi
	leaq	-1(%rdx,%rdi),%rdi
	rep movsb
	cld
.done:
	ret

.globl _std$memfill
.globl std$memfill
_std$memfill:
std$memfill:
	/* generate 8 bytes of fill */
	movzbq	%sil,%rbx
	mov	$0x101010101010101,%rax
	imul	%rbx,%rax

	/* and fill */
	movq	%rdx,%rcx
	shrq	$3,%rcx
	rep stosq
	movq	%rdx,%rcx
	andq	$7,%rcx
	rep stosb 
	ret