summaryrefslogtreecommitdiff
path: root/lib/std/memops-impl+plan9-x64.s
blob: 2d216ed77207cc59fbd17a4c9c411d0cc1066485 (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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
std.memblit	: (dst : byte#, src : byte#, len : std.size -> void)
std.memfill	: (dst : byte#, val : byte, len : std.size -> void)
*/
TEXT std$memblit+0(SB),$0
	CMPQ	SI,DI
	JZ	.done
	JG	.fwdcpy
	MOVQ	SI,AX
	SUBQ	DI,AX
	CMPQ	CX,AX
	JG	.revcpy
.fwdcpy:
	MOVQ	DX,CX
	SHRQ	$3,CX
	REP; MOVSQ
	MOVQ	DX,CX
	ANDQ	$7,CX
	REP; MOVSB
	JMP	.done
.revcpy:
	STD
	MOVQ	DX,CX
	LEAQ	-1(DX)(SI*1),SI
	LEAQ	-1(DX)(DI*1),DI
	REP; MOVSB
	CLD
.done:
	RET

TEXT std$memfill+0(SB),$0
	/* generate 8 bytes of fill */
	MOVBQZX	SI,BX
	MOVQ	$0x101010101010101,AX
	IMULQ	BX,AX

	/* and fill */
	MOVQ	DX,CX
	SHRQ	$3,CX
	REP; STOSQ
	MOVQ	DX,CX
	ANDQ	$7,CX
	REP; STOSB 
	RET

TEXT std$memeq+0(SB),$0
	MOVQ	DX,R8
	ANDQ	$~0x7,R8
	JZ	.dotail
.nextquad:
	MOVQ	(DI),R9
	MOVQ	(SI),R10
	XORQ	R10,R9
	JNZ .unequal
	ADDQ	$8,SI
	ADDQ	$8,DI
	SUBQ	$8,R8
	JNZ .nextquad
.dotail:
	ANDQ	$0x7,DX
	TESTQ	DX,DX
	JZ .equal
.nextbyte:
	MOVBLZX	(DI),R9
	MOVBLZX	(SI),R10
	XORL	R10,R9
	JNZ .unequal
	ADDQ	$1,SI
	ADDQ	$1,DI
	SUBQ	$1,DX
	JNZ .nextbyte
.equal:
	MOVQ	$1,AX
	RET
.unequal:
	MOVQ	$0,AX
	RET