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/gc_declare_proc.h>
23 #include <spu_intrinsics.h>
24 #include <spu_mfcio.h>
29 #define MAX_QA_BYTES 1024
34 // FIXME should be passed at gcell init time
35 //static const int TIMEBASE = 79800000; // ps3
36 static const int TIMEBASE = 26666666; // qs21
38 typedef void* (*memset_fptr)(void *s, int val, size_t n);
41 memset_ref(void *sv, int c, size_t n)
43 unsigned char *s = (unsigned char *) sv;
45 for (i = 0; i < n; i++)
52 check_before(unsigned char *buf, size_t len, size_t offset)
54 unsigned char *p = buf + sizeof(vector unsigned char) + offset;
58 for (i = -16; i < 0; i++){
59 unsigned char expected = (&p[i] - buf) & 0xff;
60 if (p[i] != expected){
61 printf("b:memset(%p, 0x%x, %zu) <offset %2zd> [%3d] expected %02x, got %02x\n",
62 p, K, len, offset, i, K, p[i]);
70 check_middle(unsigned char *buf, size_t len, size_t offset)
72 unsigned char *p = buf + sizeof(vector unsigned char) + offset;
76 for (i = 0; i < len; i++){
77 unsigned char expected = K;
78 if (p[i] != expected){
79 printf("m:memset(%p, 0x%x, %zu) <offset %2zd> [%3zd] expected %02x, got %02x\n",
80 p, K, len, offset, i, expected, p[i]);
88 check_after(unsigned char *buf, size_t len, size_t offset)
90 unsigned char *p = buf + sizeof(vector unsigned char) + offset;
94 for (i = len; i < len + 16; i++){
95 unsigned char expected = (&p[i] - buf) & 0xff;
96 if (p[i] != expected){
97 printf("a:memset(%p, 0x%x, %zu) <offset %2zd> [%3zd] expected %02x, got %02x\n",
98 p, K, len, offset, i, expected, p[i]);
107 test_memset_aux(memset_fptr f,
108 unsigned char *buf, size_t buflen, size_t len, size_t offset)
112 // init buffer to non-zero known state
113 for (i = 0; i < buflen; i++)
116 // Our working buffer. Starts 16 bytes + offset into buf.
117 // We offset by 16 so that we can see if data before is getting damaged.
118 unsigned char *p = buf + sizeof(vector unsigned char) + offset;
123 ok &= check_before(buf, len, offset);
124 ok &= check_middle(buf, len, offset);
125 ok &= check_after(buf, len, offset);
131 test_memset(memset_fptr f)
133 size_t BUFLEN = MAX_QA_BYTES + 2*sizeof(vector unsigned char) + MAX_OFFSET;
134 unsigned char unaligned_buf[BUFLEN + ALIGNMENT -1];
135 unsigned char *aligned_buf =
136 (unsigned char *)((((intptr_t) unaligned_buf) + ALIGNMENT - 1) & -ALIGNMENT);
138 // printf("unaligned = %p\n", unaligned_buf);
139 // printf("aligned = %p\n", aligned_buf);
145 for (len = 0; len < MAX_QA_BYTES; len++){
146 for (offset = 0; offset <= MAX_OFFSET; offset++){
147 ok &= test_memset_aux(f, aligned_buf, BUFLEN, len, offset);
156 benchmark_memset(memset_fptr f, bool aligned)
158 static const int SIZE = 32768;
159 unsigned char buf[SIZE];
163 spu_write_decrementer(0xffffffff);
167 t0 = spu_read_decrementer();
168 (*f)(buf, 0x55, nbytes);
169 (*f)(buf, 0x55, nbytes);
170 (*f)(buf, 0x55, nbytes);
171 (*f)(buf, 0x55, nbytes);
172 t1 = spu_read_decrementer();
176 t0 = spu_read_decrementer();
177 (*f)(buf + 1, 0x55, nbytes);
178 (*f)(buf + 1, 0x55, nbytes);
179 (*f)(buf + 1, 0x55, nbytes);
180 (*f)(buf + 1, 0x55, nbytes);
181 t1 = spu_read_decrementer();
184 //printf("delta ticks: %d\n", t0 - t1);
185 return (float) nbytes * 4 / ((t0 - t1) * 1.0/TIMEBASE);
189 * Implement the standard QA stub.
190 * No input arguments, 1 bool output.
193 gcs_qa_memset(const gc_job_direct_args_t *input _UNUSED,
194 gc_job_direct_args_t *output,
195 const gc_job_ea_args_t *eaa _UNUSED)
197 bool ok = test_memset(memset);
198 output->arg[0].u32 = ok;
201 GC_DECLARE_PROC(gcs_qa_memset, "qa_memset");