1 /* SPDX-License-Identifier: GPL-2.0-only */ !! 1 /* linux/arch/sparc/lib/memset.S: Sparc optimized memset, bzero and clear_user code 2 /* !! 2 * Copyright (C) 1991,1996 Free Software Foundation 3 * Copyright (c) 2011, The Linux Foundation. A !! 3 * Copyright (C) 1996,1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz) >> 4 * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu) >> 5 * >> 6 * Calls to memset returns initial %o0. Calls to bzero returns 0, if ok, and >> 7 * number of bytes not yet set if exception occurs and we were called as >> 8 * clear_user. 4 */ 9 */ 5 10 >> 11 #include <asm/ptrace.h> >> 12 #include <asm/export.h> 6 13 7 /* HEXAGON assembly optimized memset */ !! 14 /* Work around cpp -rob */ 8 /* Replaces the standard library function mems !! 15 #define ALLOC #alloc >> 16 #define EXECINSTR #execinstr >> 17 #define EX(x,y,a,b) \ >> 18 98: x,y; \ >> 19 .section .fixup,ALLOC,EXECINSTR; \ >> 20 .align 4; \ >> 21 99: ba 30f; \ >> 22 a, b, %o0; \ >> 23 .section __ex_table,ALLOC; \ >> 24 .align 4; \ >> 25 .word 98b, 99b; \ >> 26 .text; \ >> 27 .align 4 >> 28 >> 29 #define EXT(start,end,handler) \ >> 30 .section __ex_table,ALLOC; \ >> 31 .align 4; \ >> 32 .word start, 0, end, handler; \ >> 33 .text; \ >> 34 .align 4 >> 35 >> 36 /* Please don't change these macros, unless you change the logic >> 37 * in the .fixup section below as well. >> 38 * Store 64 bytes at (BASE + OFFSET) using value SOURCE. */ >> 39 #define ZERO_BIG_BLOCK(base, offset, source) \ >> 40 std source, [base + offset + 0x00]; \ >> 41 std source, [base + offset + 0x08]; \ >> 42 std source, [base + offset + 0x10]; \ >> 43 std source, [base + offset + 0x18]; \ >> 44 std source, [base + offset + 0x20]; \ >> 45 std source, [base + offset + 0x28]; \ >> 46 std source, [base + offset + 0x30]; \ >> 47 std source, [base + offset + 0x38]; >> 48 >> 49 #define ZERO_LAST_BLOCKS(base, offset, source) \ >> 50 std source, [base - offset - 0x38]; \ >> 51 std source, [base - offset - 0x30]; \ >> 52 std source, [base - offset - 0x28]; \ >> 53 std source, [base - offset - 0x20]; \ >> 54 std source, [base - offset - 0x18]; \ >> 55 std source, [base - offset - 0x10]; \ >> 56 std source, [base - offset - 0x08]; \ >> 57 std source, [base - offset - 0x00]; 9 58 10 << 11 .macro HEXAGON_OPT_FUNC_BEGIN name << 12 .text 59 .text 13 .p2align 4 !! 60 .align 4 14 .globl \name !! 61 15 .type \name, @function !! 62 .globl __bzero_begin 16 \name: !! 63 __bzero_begin: 17 .endm !! 64 18 !! 65 .globl __bzero 19 .macro HEXAGON_OPT_FUNC_FINISH name !! 66 .type __bzero,#function 20 .size \name, . - \name !! 67 .globl memset 21 .endm !! 68 EXPORT_SYMBOL(__bzero) 22 !! 69 EXPORT_SYMBOL(memset) 23 /* FUNCTION: memset (v2 version) */ !! 70 .globl __memset_start, __memset_end 24 #if __HEXAGON_ARCH__ < 3 !! 71 __memset_start: 25 HEXAGON_OPT_FUNC_BEGIN memset !! 72 memset: 26 { !! 73 mov %o0, %g1 27 r6 = #8 !! 74 mov 1, %g4 28 r7 = extractu(r0, #3 , #0) !! 75 and %o1, 0xff, %g3 29 p0 = cmp.eq(r2, #0) !! 76 sll %g3, 8, %g2 30 p1 = cmp.gtu(r2, #7) !! 77 or %g3, %g2, %g3 31 } !! 78 sll %g3, 16, %g2 32 { !! 79 or %g3, %g2, %g3 33 r4 = vsplatb(r1) !! 80 b 1f 34 r8 = r0 /* leave r0 !! 81 mov %o2, %o1 35 r9 = sub(r6, r7) /* bytes unt !! 82 3: 36 if p0 jumpr r31 /* count == !! 83 cmp %o2, 3 37 } !! 84 be 2f 38 { !! 85 EX(stb %g3, [%o0], sub %o1, 0) 39 r3 = #0 !! 86 40 r7 = #0 !! 87 cmp %o2, 2 41 p0 = tstbit(r9, #0) !! 88 be 2f 42 if p1 jump 2f /* skip byte loo !! 89 EX(stb %g3, [%o0 + 0x01], sub %o1, 1) 43 } !! 90 44 !! 91 EX(stb %g3, [%o0 + 0x02], sub %o1, 2) 45 /* less than 8 bytes to set, so just set a byt !! 92 2: 46 !! 93 sub %o2, 4, %o2 47 loop0(1f, r2) /* byte loop */ !! 94 add %o1, %o2, %o1 48 .falign !! 95 b 4f 49 1: /* byte loop */ !! 96 sub %o0, %o2, %o0 50 { !! 97 51 memb(r8++#1) = r4 !! 98 __bzero: 52 }:endloop0 !! 99 clr %g4 53 jumpr r31 !! 100 mov %g0, %g3 54 .falign !! 101 1: 55 2: /* skip byte loop */ !! 102 cmp %o1, 7 56 { !! 103 bleu 7f 57 r6 = #1 !! 104 andcc %o0, 3, %o2 58 p0 = tstbit(r9, #1) !! 105 59 p1 = cmp.eq(r2, #1) !! 106 bne 3b 60 if !p0 jump 3f /* skip initial !! 107 4: 61 } !! 108 andcc %o0, 4, %g0 62 { !! 109 63 memb(r8++#1) = r4 !! 110 be 2f 64 r3:2 = sub(r3:2, r7:6) !! 111 mov %g3, %g2 65 if p1 jumpr r31 !! 112 66 } !! 113 EX(st %g3, [%o0], sub %o1, 0) 67 .falign !! 114 sub %o1, 4, %o1 68 3: /* skip initial byte store */ !! 115 add %o0, 4, %o0 69 { !! 116 2: 70 r6 = #2 !! 117 andcc %o1, 0xffffff80, %o3 ! Now everything is 8 aligned and o1 is len to run 71 p0 = tstbit(r9, #2) !! 118 be 9f 72 p1 = cmp.eq(r2, #2) !! 119 andcc %o1, 0x78, %o2 73 if !p0 jump 4f /* skip initial !! 120 10: 74 } !! 121 ZERO_BIG_BLOCK(%o0, 0x00, %g2) 75 { !! 122 subcc %o3, 128, %o3 76 memh(r8++#2) = r4 !! 123 ZERO_BIG_BLOCK(%o0, 0x40, %g2) 77 r3:2 = sub(r3:2, r7:6) !! 124 11: 78 if p1 jumpr r31 !! 125 EXT(10b, 11b, 20f) 79 } !! 126 bne 10b 80 .falign !! 127 add %o0, 128, %o0 81 4: /* skip initial half store */ !! 128 82 { !! 129 orcc %o2, %g0, %g0 83 r6 = #4 !! 130 9: 84 p0 = cmp.gtu(r2, #7) !! 131 be 13f 85 p1 = cmp.eq(r2, #4) !! 132 andcc %o1, 7, %o1 86 if !p0 jump 5f /* skip initial !! 133 87 } !! 134 srl %o2, 1, %o3 88 { !! 135 set 13f, %o4 89 memw(r8++#4) = r4 !! 136 sub %o4, %o3, %o4 90 r3:2 = sub(r3:2, r7:6) !! 137 jmp %o4 91 p0 = cmp.gtu(r2, #11) !! 138 add %o0, %o2, %o0 92 if p1 jumpr r31 !! 139 93 } !! 140 12: 94 .falign !! 141 ZERO_LAST_BLOCKS(%o0, 0x48, %g2) 95 5: /* skip initial word store */ !! 142 ZERO_LAST_BLOCKS(%o0, 0x08, %g2) 96 { !! 143 13: 97 r10 = lsr(r2, #3) !! 144 be 8f 98 p1 = cmp.eq(r3, #1) !! 145 andcc %o1, 4, %g0 99 if !p0 jump 7f /* skip double !! 146 100 } !! 147 be 1f 101 { !! 148 andcc %o1, 2, %g0 102 r5 = r4 !! 149 103 r6 = #8 !! 150 EX(st %g3, [%o0], and %o1, 7) 104 loop0(6f, r10) /* double loop !! 151 add %o0, 4, %o0 105 } !! 152 1: 106 !! 153 be 1f 107 /* set bytes a double word at a time */ !! 154 andcc %o1, 1, %g0 108 !! 155 109 .falign !! 156 EX(sth %g3, [%o0], and %o1, 3) 110 6: /* double loop */ !! 157 add %o0, 2, %o0 111 { !! 158 1: 112 memd(r8++#8) = r5:4 !! 159 bne,a 8f 113 r3:2 = sub(r3:2, r7:6) !! 160 EX(stb %g3, [%o0], and %o1, 1) 114 p1 = cmp.eq(r2, #8) !! 161 8: 115 }:endloop0 !! 162 b 0f 116 .falign !! 163 nop 117 7: /* skip double loop */ !! 164 7: 118 { !! 165 be 13b 119 p0 = tstbit(r2, #2) !! 166 orcc %o1, 0, %g0 120 if p1 jumpr r31 !! 167 121 } !! 168 be 0f 122 { !! 169 8: 123 r6 = #4 !! 170 add %o0, 1, %o0 124 p0 = tstbit(r2, #1) !! 171 subcc %o1, 1, %o1 125 p1 = cmp.eq(r2, #4) !! 172 bne 8b 126 if !p0 jump 8f /* skip final w !! 173 EX(stb %g3, [%o0 - 1], add %o1, 1) 127 } !! 174 0: 128 { !! 175 andcc %g4, 1, %g0 129 memw(r8++#4) = r4 !! 176 be 5f 130 r3:2 = sub(r3:2, r7:6) !! 177 nop 131 if p1 jumpr r31 !! 178 retl 132 } !! 179 mov %g1, %o0 133 .falign !! 180 5: 134 8: /* skip final word store */ !! 181 retl 135 { !! 182 clr %o0 136 p1 = cmp.eq(r2, #2) !! 183 __memset_end: 137 if !p0 jump 9f /* skip final h !! 184 138 } !! 185 .section .fixup,#alloc,#execinstr 139 { !! 186 .align 4 140 memh(r8++#2) = r4 !! 187 20: 141 if p1 jumpr r31 !! 188 cmp %g2, 8 142 } !! 189 bleu 1f 143 .falign !! 190 and %o1, 0x7f, %o1 144 9: /* skip final half store */ !! 191 sub %g2, 9, %g2 145 { !! 192 add %o3, 64, %o3 146 memb(r8++#1) = r4 !! 193 1: 147 jumpr r31 !! 194 sll %g2, 3, %g2 148 } !! 195 add %o3, %o1, %o0 149 HEXAGON_OPT_FUNC_FINISH memset !! 196 b 30f 150 #endif !! 197 sub %o0, %g2, %o0 151 !! 198 21: 152 !! 199 mov 8, %o0 153 /* FUNCTION: memset (v3 and higher version) !! 200 and %o1, 7, %o1 154 #if __HEXAGON_ARCH__ >= 3 !! 201 sub %o0, %g2, %o0 155 HEXAGON_OPT_FUNC_BEGIN memset !! 202 sll %o0, 3, %o0 156 { !! 203 b 30f 157 r7=vsplatb(r1) !! 204 add %o0, %o1, %o0 158 r6 = r0 !! 205 30: 159 if (r2==#0) jump:nt .L1 !! 206 /* %o4 is faulting address, %o5 is %pc where fault occurred */ 160 } !! 207 save %sp, -104, %sp 161 { !! 208 mov %i5, %o0 162 r5:4=combine(r7,r7) !! 209 mov %i7, %o1 163 p0 = cmp.gtu(r2,#8) !! 210 call lookup_fault 164 if (p0.new) jump:nt .L3 !! 211 mov %i4, %o2 165 } !! 212 ret 166 { !! 213 restore 167 r3 = r0 !! 214 168 loop0(.L47,r2) !! 215 .globl __bzero_end 169 } !! 216 __bzero_end: 170 .falign << 171 .L47: << 172 { << 173 memb(r3++#1) = r1 << 174 }:endloop0 /* start=.L47 */ << 175 jumpr r31 << 176 .L3: << 177 { << 178 p0 = tstbit(r0,#0) << 179 if (!p0.new) jump:nt .L8 << 180 p1 = cmp.eq(r2, #1) << 181 } << 182 { << 183 r6 = add(r0, #1) << 184 r2 = add(r2,#-1) << 185 memb(r0) = r1 << 186 if (p1) jump .L1 << 187 } << 188 .L8: << 189 { << 190 p0 = tstbit(r6,#1) << 191 if (!p0.new) jump:nt .L10 << 192 } << 193 { << 194 r2 = add(r2,#-2) << 195 memh(r6++#2) = r7 << 196 p0 = cmp.eq(r2, #2) << 197 if (p0.new) jump:nt .L1 << 198 } << 199 .L10: << 200 { << 201 p0 = tstbit(r6,#2) << 202 if (!p0.new) jump:nt .L12 << 203 } << 204 { << 205 r2 = add(r2,#-4) << 206 memw(r6++#4) = r7 << 207 p0 = cmp.eq(r2, #4) << 208 if (p0.new) jump:nt .L1 << 209 } << 210 .L12: << 211 { << 212 p0 = cmp.gtu(r2,#127) << 213 if (!p0.new) jump:nt .L14 << 214 } << 215 r3 = and(r6,#31) << 216 if (r3==#0) jump:nt .L17 << 217 { << 218 memd(r6++#8) = r5:4 << 219 r2 = add(r2,#-8) << 220 } << 221 r3 = and(r6,#31) << 222 if (r3==#0) jump:nt .L17 << 223 { << 224 memd(r6++#8) = r5:4 << 225 r2 = add(r2,#-8) << 226 } << 227 r3 = and(r6,#31) << 228 if (r3==#0) jump:nt .L17 << 229 { << 230 memd(r6++#8) = r5:4 << 231 r2 = add(r2,#-8) << 232 } << 233 .L17: << 234 { << 235 r3 = lsr(r2,#5) << 236 if (r1!=#0) jump:nt .L18 << 237 } << 238 { << 239 r8 = r3 << 240 r3 = r6 << 241 loop0(.L46,r3) << 242 } << 243 .falign << 244 .L46: << 245 { << 246 dczeroa(r6) << 247 r6 = add(r6,#32) << 248 r2 = add(r2,#-32) << 249 }:endloop0 /* start=.L46 */ << 250 .L14: << 251 { << 252 p0 = cmp.gtu(r2,#7) << 253 if (!p0.new) jump:nt .L28 << 254 r8 = lsr(r2,#3) << 255 } << 256 loop0(.L44,r8) << 257 .falign << 258 .L44: << 259 { << 260 memd(r6++#8) = r5:4 << 261 r2 = add(r2,#-8) << 262 }:endloop0 /* start=.L44 */ << 263 .L28: << 264 { << 265 p0 = tstbit(r2,#2) << 266 if (!p0.new) jump:nt .L33 << 267 } << 268 { << 269 r2 = add(r2,#-4) << 270 memw(r6++#4) = r7 << 271 } << 272 .L33: << 273 { << 274 p0 = tstbit(r2,#1) << 275 if (!p0.new) jump:nt .L35 << 276 } << 277 { << 278 r2 = add(r2,#-2) << 279 memh(r6++#2) = r7 << 280 } << 281 .L35: << 282 p0 = cmp.eq(r2,#1) << 283 if (p0) memb(r6) = r1 << 284 .L1: << 285 jumpr r31 << 286 .L18: << 287 loop0(.L45,r3) << 288 .falign << 289 .L45: << 290 dczeroa(r6) << 291 { << 292 memd(r6++#8) = r5:4 << 293 r2 = add(r2,#-32) << 294 } << 295 memd(r6++#8) = r5:4 << 296 memd(r6++#8) = r5:4 << 297 { << 298 memd(r6++#8) = r5:4 << 299 }:endloop0 /* start=.L45 */ << 300 jump .L14 << 301 HEXAGON_OPT_FUNC_FINISH memset << 302 #endif <<
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.