1 /* memset.S: optimised assembly memset
3 * Copyright (C) 2003 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
16 ###############################################################################
18 # void *memset(void *p, char ch, size_t count)
20 # - NOTE: must not use any stack. exception detection performs function return
21 # to caller's fixup routine, aborting the remainder of the set
22 # GR4, GR7, GR8, and GR11 must be managed
24 ###############################################################################
25 .globl memset,__memset_end
26 .type memset,@function
28 orcc.p gr10,gr0,gr5,icc3 ; GR5 = count
30 or.p gr8,gr0,gr4 ; GR4 = address
33 # conditionally write a byte to 2b-align the address
35 andicc gr4,#1,gr0,icc0
37 cstb.p gr9,@(gr4,gr0) ,cc7,#1
38 csubcc gr5,gr6,gr5 ,cc7,#1 ; also set ICC3
39 cadd.p gr4,gr6,gr4 ,cc7,#1
42 # conditionally write a word to 4b-align the address
43 andicc.p gr4,#2,gr0,icc0
44 subicc gr5,#2,gr0,icc1
47 slli.p gr9,#8,gr12 ; need to double up the pattern
52 csth.p gr12,@(gr4,gr0) ,cc7,#1
53 csubcc gr5,gr6,gr5 ,cc7,#1 ; also set ICC3
54 cadd.p gr4,gr6,gr4 ,cc7,#1
57 # conditionally write a dword to 8b-align the address
58 andicc.p gr4,#4,gr0,icc0
59 subicc gr5,#4,gr0,icc1
62 slli.p gr12,#16,gr13 ; need to quadruple-up the pattern
67 cst.p gr12,@(gr4,gr0) ,cc7,#1
68 csubcc gr5,gr6,gr5 ,cc7,#1 ; also set ICC3
69 cadd.p gr4,gr6,gr4 ,cc7,#1
72 or.p gr12,gr12,gr13 ; need to octuple-up the pattern
74 # the address is now 8b-aligned - loop around writing 64b chunks
76 subi.p gr4,#8,gr4 ; store with update index does weird stuff
79 subicc gr5,#64,gr0,icc0
81 cstdu gr12,@(gr4,gr7) ,cc7,#1
82 cstdu gr12,@(gr4,gr7) ,cc7,#1
83 cstdu gr12,@(gr4,gr7) ,cc7,#1
84 cstdu gr12,@(gr4,gr7) ,cc7,#1
85 cstdu gr12,@(gr4,gr7) ,cc7,#1
86 cstdu.p gr12,@(gr4,gr7) ,cc7,#1
87 csubcc gr5,gr6,gr5 ,cc7,#1 ; also set ICC3
88 cstdu.p gr12,@(gr4,gr7) ,cc7,#1
89 subicc gr5,#64,gr0,icc0
90 cstdu.p gr12,@(gr4,gr7) ,cc7,#1
94 # now do 32-byte remnant
95 subicc.p gr5,#32,gr0,icc0
98 cstdu.p gr12,@(gr4,gr7) ,cc7,#1
99 csubcc gr5,gr6,gr5 ,cc7,#1 ; also set ICC3
100 cstdu.p gr12,@(gr4,gr7) ,cc7,#1
102 cstdu.p gr12,@(gr4,gr7) ,cc7,#1
103 subicc gr5,#16,gr0,icc0
104 cstdu.p gr12,@(gr4,gr7) ,cc7,#1
107 # now do 16-byte remnant
109 cstdu.p gr12,@(gr4,gr7) ,cc7,#1
110 csubcc gr5,gr6,gr5 ,cc7,#1 ; also set ICC3
111 cstdu.p gr12,@(gr4,gr7) ,cc7,#1
114 # now do 8-byte remnant
115 subicc gr5,#8,gr0,icc1
117 cstdu.p gr12,@(gr4,gr7) ,cc7,#1
118 csubcc gr5,gr7,gr5 ,cc7,#1 ; also set ICC3
122 # now do 4-byte remnant
123 subicc gr5,#4,gr0,icc0
126 cstu.p gr12,@(gr4,gr7) ,cc7,#1
127 csubcc gr5,gr7,gr5 ,cc7,#1 ; also set ICC3
128 subicc.p gr5,#2,gr0,icc1
131 # now do 2-byte remnant
135 csthu.p gr12,@(gr4,gr7) ,cc7,#1
136 csubcc gr5,gr7,gr5 ,cc7,#1 ; also set ICC3
137 subicc.p gr5,#1,gr0,icc0
140 # now do 1-byte remnant
144 cstb.p gr12,@(gr4,gr0) ,cc7,#1
148 .size memset, __memset_end-memset
150 ###############################################################################
152 # clear memory in userspace
153 # - return the number of bytes that could not be cleared (0 on complete success)
155 # long __memset_user(void *p, size_t count)
157 ###############################################################################
158 .globl __memset_user, __memset_user_error_lr, __memset_user_error_handler
159 .type __memset_user,@function
163 # abuse memset to do the dirty work
167 __memset_user_error_lr:
171 # deal any exception generated by memset
172 # GR4 - memset's address tracking pointer
173 # GR7 - memset's step value (index register for store insns)
174 # GR8 - memset's original start address
175 # GR10 - memset's original count
176 __memset_user_error_handler:
180 sub gr8,gr4,gr8 ; we return the amount left uncleared
182 .size __memset_user, .-__memset_user