blob: 87fec4cbe10c50eb5b570dfebc7d941940bbe760 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/* bzero.S: Simple prefetching memset, bzero, and clear_user
3 * implementations.
4 *
5 * Copyright (C) 2005 David S. Miller <davem@davemloft.net>
6 */
7
David S. Miller8695c372012-05-11 20:33:22 -07008#include <linux/linkage.h>
Al Virod3867f042016-01-16 21:39:30 -05009#include <asm/export.h>
David S. Miller8695c372012-05-11 20:33:22 -070010
Linus Torvalds1da177e2005-04-16 15:20:36 -070011 .text
12
David S. Miller8695c372012-05-11 20:33:22 -070013ENTRY(memset) /* %o0=buf, %o1=pat, %o2=len */
Linus Torvalds1da177e2005-04-16 15:20:36 -070014 and %o1, 0xff, %o3
15 mov %o2, %o1
16 sllx %o3, 8, %g1
17 or %g1, %o3, %o2
18 sllx %o2, 16, %g1
19 or %g1, %o2, %o2
20 sllx %o2, 32, %g1
21 ba,pt %xcc, 1f
22 or %g1, %o2, %o2
23
David S. Miller8695c372012-05-11 20:33:22 -070024ENTRY(__bzero) /* %o0=buf, %o1=len */
Linus Torvalds1da177e2005-04-16 15:20:36 -070025 clr %o2
261: mov %o0, %o3
27 brz,pn %o1, __bzero_done
28 cmp %o1, 16
29 bl,pn %icc, __bzero_tiny
30 prefetch [%o0 + 0x000], #n_writes
31 andcc %o0, 0x3, %g0
32 be,pt %icc, 2f
331: stb %o2, [%o0 + 0x00]
34 add %o0, 1, %o0
35 andcc %o0, 0x3, %g0
36 bne,pn %icc, 1b
37 sub %o1, 1, %o1
382: andcc %o0, 0x7, %g0
39 be,pt %icc, 3f
40 stw %o2, [%o0 + 0x00]
41 sub %o1, 4, %o1
42 add %o0, 4, %o0
433: and %o1, 0x38, %g1
44 cmp %o1, 0x40
45 andn %o1, 0x3f, %o4
46 bl,pn %icc, 5f
47 and %o1, 0x7, %o1
48 prefetch [%o0 + 0x040], #n_writes
49 prefetch [%o0 + 0x080], #n_writes
50 prefetch [%o0 + 0x0c0], #n_writes
51 prefetch [%o0 + 0x100], #n_writes
52 prefetch [%o0 + 0x140], #n_writes
534: prefetch [%o0 + 0x180], #n_writes
54 stx %o2, [%o0 + 0x00]
55 stx %o2, [%o0 + 0x08]
56 stx %o2, [%o0 + 0x10]
57 stx %o2, [%o0 + 0x18]
58 stx %o2, [%o0 + 0x20]
59 stx %o2, [%o0 + 0x28]
60 stx %o2, [%o0 + 0x30]
61 stx %o2, [%o0 + 0x38]
62 subcc %o4, 0x40, %o4
63 bne,pt %icc, 4b
64 add %o0, 0x40, %o0
65 brz,pn %g1, 6f
66 nop
675: stx %o2, [%o0 + 0x00]
68 subcc %g1, 8, %g1
69 bne,pt %icc, 5b
70 add %o0, 0x8, %o0
716: brz,pt %o1, __bzero_done
72 nop
73__bzero_tiny:
741: stb %o2, [%o0 + 0x00]
75 subcc %o1, 1, %o1
76 bne,pt %icc, 1b
77 add %o0, 1, %o0
78__bzero_done:
79 retl
80 mov %o3, %o0
David S. Miller8695c372012-05-11 20:33:22 -070081ENDPROC(__bzero)
82ENDPROC(memset)
Al Virod3867f042016-01-16 21:39:30 -050083EXPORT_SYMBOL(__bzero)
84EXPORT_SYMBOL(memset)
Linus Torvalds1da177e2005-04-16 15:20:36 -070085
86#define EX_ST(x,y) \
8798: x,y; \
David S. Miller4d000d52006-03-04 23:23:56 -080088 .section __ex_table,"a";\
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 .align 4; \
David S. Miller40bdac72009-02-08 22:00:55 -080090 .word 98b, __retl_o1; \
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 .text; \
92 .align 4;
93
David S. Miller8695c372012-05-11 20:33:22 -070094ENTRY(__clear_user) /* %o0=buf, %o1=len */
David S. Millerc857e3f2006-02-17 10:35:23 -080095 brz,pn %o1, __clear_user_done
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 cmp %o1, 16
David S. Millerc857e3f2006-02-17 10:35:23 -080097 bl,pn %icc, __clear_user_tiny
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 EX_ST(prefetcha [%o0 + 0x00] %asi, #n_writes)
99 andcc %o0, 0x3, %g0
100 be,pt %icc, 2f
1011: EX_ST(stba %g0, [%o0 + 0x00] %asi)
102 add %o0, 1, %o0
103 andcc %o0, 0x3, %g0
104 bne,pn %icc, 1b
105 sub %o1, 1, %o1
1062: andcc %o0, 0x7, %g0
107 be,pt %icc, 3f
108 EX_ST(stwa %g0, [%o0 + 0x00] %asi)
109 sub %o1, 4, %o1
110 add %o0, 4, %o0
1113: and %o1, 0x38, %g1
112 cmp %o1, 0x40
113 andn %o1, 0x3f, %o4
114 bl,pn %icc, 5f
115 and %o1, 0x7, %o1
116 EX_ST(prefetcha [%o0 + 0x040] %asi, #n_writes)
117 EX_ST(prefetcha [%o0 + 0x080] %asi, #n_writes)
118 EX_ST(prefetcha [%o0 + 0x0c0] %asi, #n_writes)
119 EX_ST(prefetcha [%o0 + 0x100] %asi, #n_writes)
120 EX_ST(prefetcha [%o0 + 0x140] %asi, #n_writes)
1214: EX_ST(prefetcha [%o0 + 0x180] %asi, #n_writes)
122 EX_ST(stxa %g0, [%o0 + 0x00] %asi)
123 EX_ST(stxa %g0, [%o0 + 0x08] %asi)
124 EX_ST(stxa %g0, [%o0 + 0x10] %asi)
125 EX_ST(stxa %g0, [%o0 + 0x18] %asi)
126 EX_ST(stxa %g0, [%o0 + 0x20] %asi)
127 EX_ST(stxa %g0, [%o0 + 0x28] %asi)
128 EX_ST(stxa %g0, [%o0 + 0x30] %asi)
129 EX_ST(stxa %g0, [%o0 + 0x38] %asi)
130 subcc %o4, 0x40, %o4
131 bne,pt %icc, 4b
132 add %o0, 0x40, %o0
133 brz,pn %g1, 6f
134 nop
1355: EX_ST(stxa %g0, [%o0 + 0x00] %asi)
136 subcc %g1, 8, %g1
137 bne,pt %icc, 5b
138 add %o0, 0x8, %o0
David S. Millerc857e3f2006-02-17 10:35:23 -08001396: brz,pt %o1, __clear_user_done
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 nop
David S. Millerc857e3f2006-02-17 10:35:23 -0800141__clear_user_tiny:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421: EX_ST(stba %g0, [%o0 + 0x00] %asi)
143 subcc %o1, 1, %o1
144 bne,pt %icc, 1b
145 add %o0, 1, %o0
David S. Millerc857e3f2006-02-17 10:35:23 -0800146__clear_user_done:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 retl
148 clr %o0
David S. Miller8695c372012-05-11 20:33:22 -0700149ENDPROC(__clear_user)
Al Virod3867f042016-01-16 21:39:30 -0500150EXPORT_SYMBOL(__clear_user)