3 * Copyright 2008 Free Software Foundation, Inc.
5 * This file is part of GNU Radio
7 * GNU Radio is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3, or (at your option)
12 * GNU Radio is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include <gcell/spu/gc_spu_macs.h>
27 * Computes this, only a lot faster...
30 * memset(void *pv, int c, size_t n)
32 * unsigned char *p = (unsigned char *) pv;
34 * for (i = 0; i < n; i++)
41 #define p_arg arg1 // we're going to clobber arg1 w/ the return value
42 #define c arg2 // the constant we're writing
43 #define n arg3 // how many bytes to write
45 #define p r13 // where we're writing
50 #define an r18 // aligned n (n rounded down to mod 16 boundary)
59 // Hint the return from do_head, in case we go that way.
60 // There's pretty much nothing to can do to hint the branch to it.
61 hbrr do_head_br, head_complete
63 MR(p, p_arg) // leaves p, the return value, in the correct reg (r3)
66 MODULO(t0, p, 16) // is p%16 == 0?
67 VSPLTB(c, c, 3) // splat byte in preferred slot of c into all slots
68 brnz t0, do_head // no, handle it
75 hbrr middle_loop_br, middle_loop
77 ROUND_DOWN(an, n, 16) // an is "aligned n"
78 MODULO(n, n, 16) // what's left over in the last quad
79 brz an, do_tail // no whole quad words; skip to tail
80 clgti t0, an, 127 // an >= 128?
81 brz t0, middle2 // nope, go handle the cases between 0 and 112
84 * 128 bytes / iteration
101 stqd c, 7*16-128(next_p)
104 brnz cond1, middle_loop
107 * if an and n are both zero, return now
112 * otherwise handle last of full quad words
114 * 0 <= an < 128, p%16 == 0
118 * if an == 0, go handle the final non-full quadword
121 hbrr middle2_loop_br, middle2_loop
130 brnz an, middle2_loop
132 /* We're done with the full quadwords. */
135 * Handle the final partial quadword.
136 * We'll be modifying only the left hand portion of the quad.
139 * an == 0, 0 <= n < 16, p%16 == 0
142 HINT_RETURN(do_tail_ret)
144 sfi t1, n, 16 // t1 = 16 - n
146 shlqby mask, mask, t1
147 selb t0, old, c, mask
153 * ----------------------------------------------------------------
154 * Handle the first partial quadword
160 * p%16 == 0 or n == 0
163 * +----------------+----------------+
165 * +----------------+----------------+
168 * ----------------------------------------------------------------
175 shlqby mask, mask, m // 1's in the top, m*8 0's in the bottom
177 sf t0, m, r // t0 = r - m
179 rotqby mask, mask, t0 // rotate 0's to the right place
181 selb t0, c, old, mask // merge