]> git.lizzy.rs Git - plan9front.git/blob - sys/src/libc/sparc/memcmp.s
fltfmt: %.ng is supposed to print a number with n significant figures, but it prints...
[plan9front.git] / sys / src / libc / sparc / memcmp.s
1         TEXT    memcmp(SB), $0
2
3 /*
4  * performance:
5  *      (tba)
6  */
7
8         MOVW    R7, 0(FP)
9         MOVW    n+8(FP), R9             /* R9 is count */
10         MOVW    s1+0(FP), R10           /* R10 is pointer1 */
11         MOVW    s2+4(FP), R11           /* R11 is pointer2 */
12         ADD     R9,R10, R12             /* R12 is end pointer1 */
13
14 /*
15  * if not at least 4 chars,
16  * dont even mess around.
17  * 3 chars to guarantee any
18  * rounding up to a word
19  * boundary and 4 characters
20  * to get at least maybe one
21  * full word cmp.
22  */
23         SUBCC   $4,R9, R0
24         BL      out
25
26 /*
27  * test if both pointers
28  * are similarly word alligned
29  */
30         XOR     R10,R11, R7
31         ANDCC   $3,R7, R0
32         BNE     out
33
34 /*
35  * byte at a time to word allign
36  */
37 l1:
38         ANDCC   $3,R10, R0
39         BE      l2
40         MOVBU   0(R10), R16
41         MOVBU   0(R11), R17
42         ADD     $1, R10
43         SUBCC   R16,R17, R0
44         BNE     ne
45         ADD     $1, R11
46         JMP     l1
47
48 /*
49  * turn R9 into end pointer1-15
50  * cmp 16 at a time while theres room
51  */
52 l2:
53         SUB     $15,R12, R9
54 l3:
55         SUBCC   R10,R9, R0
56         BLEU    l4
57         MOVW    0(R10), R16
58         MOVW    0(R11), R17
59         MOVW    4(R10), R18
60         SUBCC   R16,R17, R0
61         BNE     ne
62         MOVW    4(R11), R19
63         MOVW    8(R10), R16
64         SUBCC   R18,R19, R0
65         BNE     ne
66         MOVW    8(R11), R17
67         MOVW    12(R10), R18
68         SUBCC   R16,R17, R0
69         BNE     ne
70         MOVW    12(R11), R19
71         ADD     $16, R10
72         SUBCC   R18,R19, R0
73         BNE     ne
74         SUBCC   R16,R17, R0
75         BNE     ne
76         ADD     $16, R11
77         JMP     l3
78
79 /*
80  * turn R9 into end pointer1-3
81  * cmp 4 at a time while theres room
82  */
83 l4:
84         SUB     $3,R12, R9
85 l5:
86         SUBCC   R10,R9, R0
87         BLEU    out
88         MOVW    0(R10), R16
89         MOVW    0(R11), R17
90         ADD     $4, R10
91         SUBCC   R16,R17, R0             /* only works because big endian */
92         BNE     ne
93         ADD     $4, R11
94         JMP     l5
95
96 /*
97  * last loop, cmp byte at a time
98  */
99 out:
100         SUBCC   R10,R12, R0
101         BE      zero
102         MOVBU   0(R10), R16
103         MOVBU   0(R11), R17
104         ADD     $1, R10
105         SUBCC   R16,R17, R0
106         BNE     ne
107         ADD     $1, R11
108         JMP     out
109
110 ne:
111         BGU     plus
112         MOVW    $1, R7
113         RETURN
114 plus:
115         MOVW    $-1, R7
116         RETURN
117
118 zero:
119         MOVW    R0, R7
120         RETURN