~kris/9p

9hist

ref: 05490cdb1d38889d0d0e0fed6e5e48ee209cd86f 9hist/carrera/memset.s -rw-r--r-- 1.4 KiB
05490cdb — David du Colombier Plan 9 from Bell Labs 2001-04-07 25 years ago
                                                                                
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
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
 * R4000-compatible memset uses V instructions.
 * The kernel uses the 3000 compilers, but we can
 * use this procedure for speed.
 */
	TEXT	memset(SB),$16
	MOVW	R1, 0(FP)

	MOVW	n+8(FP), R3		/* R3 is count */
	MOVW	p+0(FP), R4		/* R4 is pointer */
	MOVW	c+4(FP), R5		/* R5 is char */
	ADDU	R3,R4, R6		/* R6 is end pointer */

/*
 * if not at least 8 chars,
 * dont even mess around.
 * 7 chars to guarantee any
 * rounding up to a word
 * boundary and 8 characters
 * to get at least maybe one
 * full word store.
 */
	SGT	$8,R3, R1
	BNE	R1, out

/*
 * turn R5 into a doubleword of characters
 */
	AND	$0xff, R5
	SLLV	$8,R5, R1
	OR	R1, R5
	SLLV	$16,R5, R1
	OR	R1, R5
	SLLV	$32,R5, R1
	OR	R1, R5

/*
 * store one byte at a time until pointer
 * is alligned on a doubleword boundary
 */
l1:
	AND	$7,R4, R1
	BEQ	R1, l2
	MOVB	R5, 0(R4)
	ADDU	$1, R4
	JMP	l1

/*
 * turn R3 into end pointer-31
 * store 32 at a time while theres room
 */
l2:
	ADDU	$-31,R6, R3
l3:
	SGTU	R3,R4, R1
	BEQ	R1, l4
	MOVV	R5, 0(R4)
	MOVV	R5, 8(R4)
	ADDU	$32, R4
	MOVV	R5, -16(R4)
	MOVV	R5, -8(R4)
	JMP	l3

/*
 * turn R3 into end pointer-3
 * store 4 at a time while theres room
 */
l4:
	ADDU	$-3,R6, R3
l5:
	SGTU	R3,R4, R1
	BEQ	R1, out
	MOVW	R5, 0(R4)
	ADDU	$4, R4
	JMP	l5

/*
 * last loop, store byte at a time
 */
out:
	SGTU	R6,R4 ,R1
	BEQ	R1, ret
	MOVB	R5, 0(R4)
	ADDU	$1, R4
	JMP	out

ret:
	MOVW	s1+0(FP), R1
	RET
	END