1 /* Copyright (C) 2000, 2003 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 EV6 optimized by Rick Gorton <rick.gorton@alpha-processor.com>.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21 * Much of the information about 21264 scheduling/coding comes from:
22 * Compiler Writer's Guide for the Alpha 21264
23 * abbreviated as 'CWG' in other comments here
24 * ftp.digital.com/pub/Digital/info/semiconductor/literature/dsc-library.html
25 * Scheduling notation:
27 * U - upper subcluster; U0 - subcluster U0; U1 - subcluster U1
28 * L - lower subcluster; L0 - subcluster L0; L1 - subcluster L1
31 * $0 - destination address
44 mov $16, $0 # E : copy dest to return
45 ble $18, $nomoredata # U : done with the copy?
46 xor $16, $17, $1 # E : are source and dest alignments the same?
47 and $1, 7, $1 # E : are they the same mod 8?
49 bne $1, $misaligned # U : Nope - gotta do this the slow way
50 /* source and dest are same mod 8 address */
51 and $16, 7, $1 # E : Are both 0mod8?
52 beq $1, $both_0mod8 # U : Yes
56 * source and dest are same misalignment. move a byte at a time
57 * until a 0mod8 alignment for both is reached.
58 * At least one byte more to move
62 ldbu $1, 0($17) # L : grab a byte
63 subq $18, 1, $18 # E : count--
64 addq $17, 1, $17 # E : src++
66 addq $16, 1, $16 # E : dest++
67 and $16, 7, $1 # E : Are we at 0mod8 yet?
68 ble $18, $nomoredata # U : done with the copy?
69 bne $1, $head_align # U :
72 cmple $18, 127, $1 # E : Can we unroll the loop?
73 bne $1, $no_unroll # U :
74 and $16, 63, $1 # E : get mod64 alignment
75 beq $1, $do_unroll # U : no single quads to fiddle
78 ldq $1, 0($17) # L : get 8 bytes
79 subq $18, 8, $18 # E : count -= 8
80 addq $17, 8, $17 # E : src += 8
83 stq $1, 0($16) # L : store
84 addq $16, 8, $16 # E : dest += 8
85 and $16, 63, $1 # E : get mod64 alignment
86 bne $1, $single_head_quad # U : still not fully aligned
89 addq $16, 64, $7 # E : Initial (+1 trip) wh64 address
90 cmple $18, 127, $1 # E : Can we go through the unrolled loop?
91 bne $1, $tail_quads # U : Nope
95 wh64 ($7) # L1 : memory subsystem hint: 64 bytes at
96 # ($7) are about to be over-written
97 ldq $6, 0($17) # L0 : bytes 0..7
101 ldq $4, 8($17) # L : bytes 8..15
102 ldq $5, 16($17) # L : bytes 16..23
103 addq $7, 64, $7 # E : Update next wh64 address
106 ldq $3, 24($17) # L : bytes 24..31
107 addq $16, 64, $1 # E : fallback value for wh64
111 addq $17, 32, $17 # E : src += 32 bytes
112 stq $6, 0($16) # L : bytes 0..7
116 stq $4, 8($16) # L : bytes 8..15
117 stq $5, 16($16) # L : bytes 16..23
118 subq $18, 192, $2 # E : At least two more trips to go?
121 stq $3, 24($16) # L : bytes 24..31
122 addq $16, 32, $16 # E : dest += 32 bytes
126 ldq $6, 0($17) # L : bytes 0..7
127 ldq $4, 8($17) # L : bytes 8..15
128 cmovlt $2, $1, $7 # E : Latency 2, extra map slot - Use
129 # fallback wh64 address if < 2 more trips
132 ldq $5, 16($17) # L : bytes 16..23
133 ldq $3, 24($17) # L : bytes 24..31
134 addq $16, 32, $16 # E : dest += 32
135 subq $18, 64, $18 # E : count -= 64
137 addq $17, 32, $17 # E : src += 32
138 stq $6, -32($16) # L : bytes 0..7
139 stq $4, -24($16) # L : bytes 8..15
140 cmple $18, 63, $1 # E : At least one more trip?
142 stq $5, -16($16) # L : bytes 16..23
143 stq $3, -8($16) # L : bytes 24..31
150 subq $18, 8, $18 # E : At least a quad left?
151 blt $18, $less_than_8 # U : Nope
156 ldq $1, 0($17) # L : fetch 8
157 subq $18, 8, $18 # E : count -= 8
158 addq $17, 8, $17 # E : src += 8
161 stq $1, 0($16) # L : store 8
162 addq $16, 8, $16 # E : dest += 8
163 bge $18, $move_a_quad # U :
168 addq $18, 8, $18 # E : add back for trailing bytes
169 ble $18, $nomoredata # U : All-done
175 subq $18, 1, $18 # E : count--
176 ldbu $1, 0($17) # L : fetch a byte
177 addq $17, 1, $17 # E : src++
180 stb $1, 0($16) # L : store a byte
181 addq $16, 1, $16 # E : dest++
182 bgt $18, $tail_bytes # U : more to be done?
185 /* branching to exit takes 3 extra cycles, so replicate exit here */
186 ret $31, ($26), 1 # L0 :
192 mov $0, $4 # E : dest temp
193 and $0, 7, $1 # E : dest alignment mod8
194 beq $1, $dest_0mod8 # U : life doesnt totally suck
198 ble $18, $nomoredata # U :
199 ldbu $1, 0($17) # L : fetch a byte
200 subq $18, 1, $18 # E : count--
201 addq $17, 1, $17 # E : src++
203 stb $1, 0($4) # L : store it
204 addq $4, 1, $4 # E : dest++
205 and $4, 7, $1 # E : dest 0mod8 yet?
206 bne $1, $aligndest # U : go until we are aligned.
208 /* Source has unknown alignment, but dest is known to be 0mod8 */
210 subq $18, 8, $18 # E : At least a quad left?
211 blt $18, $misalign_tail # U : Nope
212 ldq_u $3, 0($17) # L : seed (rotating load) of 8 bytes
216 ldq_u $16, 8($17) # L : Fetch next 8
217 extql $3, $17, $3 # U : masking
218 extqh $16, $17, $1 # U : masking
219 bis $3, $1, $1 # E : merged bytes to store
221 subq $18, 8, $18 # E : count -= 8
222 addq $17, 8, $17 # E : src += 8
223 stq $1, 0($4) # L : store 8 (aligned)
224 mov $16, $3 # E : "rotate" source data
226 addq $4, 8, $4 # E : dest += 8
227 bge $18, $mis_quad # U : More quads to move
232 addq $18, 8, $18 # E : account for tail stuff
233 ble $18, $nomoredata # U :
238 ldbu $1, 0($17) # L : fetch 1
239 subq $18, 1, $18 # E : count--
240 addq $17, 1, $17 # E : src++
243 stb $1, 0($4) # L : store
244 addq $4, 1, $4 # E : dest++
245 bgt $18, $misalign_byte # U : more to go?
250 ret $31, ($26), 1 # L0 :
256 libc_hidden_builtin_def (memcpy)