summaryrefslogtreecommitdiffstats
path: root/arch/sparc64/lib/memscan.S
blob: 83abe4040bce258d9cf9eea30afa58857000d0cb (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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/* $Id: memscan.S,v 1.1 1997/03/14 21:04:24 jj Exp $
 * memscan.S: Optimized memscan for the Sparc64.
 *
 * Copyright (C) 1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
 */

/* In essence, this is just a fancy strlen. */

#define LO_MAGIC 0x01010101
#define HI_MAGIC 0x80808080

	.text
	.align	4
	.globl	__memscan_zero, __memscan_generic
	.globl	memscan
__memscan_zero:
	/* %o0 = addr, %o1 = size */
	brlez,pn %o1, 0f
	 andcc	%o0, 3, %g0
	be,pt	%icc, 9f
	 sethi	%hi(HI_MAGIC), %o4
	ldub	[%o0], %o5
	subcc	%o1, 1, %o1
	brz,pn	%o5, 10f
	 add	%o0, 1, %o0
	be,pn	%xcc, 0f
	 andcc	%o0, 3, %g0
	be,pn	%icc, 4f
	 or	%o4, %lo(HI_MAGIC), %o3
	ldub	[%o0], %o5
	subcc	%o1, 1, %o1
	brz,pn	%o5, 10f
	 add	%o0, 1, %o0
	be,pn	%xcc, 0f
	 andcc	%o0, 3, %g0
	be,pt	%icc, 5f
	 sethi	%hi(LO_MAGIC), %o4
	ldub	[%o0], %o5
	subcc	%o1, 1, %o1
	brz,pn	%o5, 10f
	 add	%o0, 1, %o0
	be,pn	%xcc, 0f
	 or	%o4, %lo(LO_MAGIC), %o2
	ba,pt	%xcc, 2f
	 ld	[%o0], %o5
9:
	or	%o4, %lo(HI_MAGIC), %o3
4:
	sethi	%hi(LO_MAGIC), %o4
5:
	or	%o4, %lo(LO_MAGIC), %o2
	ld	[%o0], %o5
2:
	sub	%o5, %o2, %o4
	sub	%o1, 4, %o1
	andcc	%o4, %o3, %g0
	be,pn	%icc, 1f
	 add	%o0, 4, %o0
	brgz,pt	%o1, 2b
	 ld	[%o0], %o5

	retl
	 add	%o0, %o1, %o0
1:
	/* Check every byte. */
	srl	%o5, 24, %g5
	andcc	%g5, 0xff, %g0
	be,pn	%icc, 1f
	 add	%o0, -4, %o4
	srl	%o5, 16, %g5
	andcc	%g5, 0xff, %g0
	be,pn	%icc, 1f
	 add	%o4, 1, %o4
	srl	%o5, 8, %g5
	andcc	%g5, 0xff, %g0
	be,pn	%icc, 1f
	 add	%o4, 1, %o4
	andcc	%o5, 0xff, %g0
	be,pn	%icc, 1f
	 add	%o4, 1, %o4
	brgz,pt	%o1, 2b
	 ld	[%o0], %o5
1:
	add	%o0, %o1, %o0
	cmp	%o4, %o0
	retl
	 movle	%xcc, %o4, %o0
0:
	retl
	 nop
10:
	retl
	 sub	%o0, 1, %o0

memscan:
__memscan_generic:
	/* %o0 = addr, %o1 = c, %o2 = size */
	brz,pn	%o2, 3f
	 add	%o0, %o2, %o3
	ldub	[%o0], %o5
	sub	%g0, %o2, %o4
1:
	cmp	%o5, %o1
	be,pn	%icc, 2f
	 addcc	%o4, 1, %o4
	bne,a,pt %xcc, 1b
	 ldub	[%o3 + %o4], %o5
	retl
	/* The delay slot is the same as the next insn, this is just to make it look more awful */
2:
	 add	%o3, %o4, %o0
	retl
	 sub	%o0, 1, %o0
3:
	retl
	 nop