Fixed to pass distcheck, except QA test operates differently during distcheck vs...
[debian/gnuradio] / gcell / src / lib / runtime / spu / gcell_qa.c
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2008 Free Software Foundation, Inc.
4  * 
5  * This file is part of GNU Radio
6  * 
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)
10  * any later version.
11  * 
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.
16  * 
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.
20  */
21
22 #include <gc_delay.h>
23 #include <gc_declare_proc.h>
24 #include <string.h>
25
26
27 #define _UNUSED __attribute__((unused))
28
29 // FIXME move these out of here; only for QA usage
30
31 static void
32 qa_nop(const gc_job_direct_args_t *input _UNUSED,
33        gc_job_direct_args_t *output _UNUSED,
34        const gc_job_ea_args_t *eaa _UNUSED)
35 {
36 }
37
38 GC_DECLARE_PROC(qa_nop, "qa_nop");
39
40 static int
41 sum_shorts(short *p, int nshorts)
42 {
43   int total = 0;
44   for (int i = 0; i < nshorts; i++)
45     total += p[i];
46
47   return total;
48 }
49
50 static void
51 qa_sum_shorts(const gc_job_direct_args_t *input _UNUSED,
52               gc_job_direct_args_t *output,
53               const gc_job_ea_args_t *eaa)
54 {
55   for (unsigned int i = 0; i < eaa->nargs; i++){
56     short *p = eaa->arg[i].ls_addr;
57     int n = eaa->arg[i].get_size / sizeof(short);
58     output->arg[i].s32 = sum_shorts(p, n);
59     //printf("qa_sum_shorts(%p, %d) = %d\n",  p, n, output->arg[i].s32);
60   }
61 }
62
63 GC_DECLARE_PROC(qa_sum_shorts, "qa_sum_shorts");
64
65 static void
66 write_seq(unsigned char *p, int nbytes, int counter)
67 {
68   for (int i = 0; i < nbytes; i++)
69     p[i] = counter++;
70 }
71
72 static void
73 qa_put_seq(const gc_job_direct_args_t *input,
74            gc_job_direct_args_t *output _UNUSED,
75            const gc_job_ea_args_t *eaa)
76 {
77   int counter = input->arg[0].s32;
78
79   for (unsigned int i = 0; i < eaa->nargs; i++){
80     unsigned char *p = eaa->arg[i].ls_addr;
81     int n = eaa->arg[i].put_size;
82     write_seq(p, n, counter);
83     counter += n;
84   }
85 }
86
87 GC_DECLARE_PROC(qa_put_seq, "qa_put_seq");
88
89 static void
90 qa_copy(const gc_job_direct_args_t *input _UNUSED,
91         gc_job_direct_args_t *output,
92         const gc_job_ea_args_t *eaa)
93 {
94   if (eaa->nargs != 2
95       || eaa->arg[0].direction != GCJD_DMA_PUT
96       || eaa->arg[1].direction != GCJD_DMA_GET){
97     output->arg[0].s32 = -1;
98     return;
99   }
100
101   output->arg[0].s32 = 0;
102   unsigned n = eaa->arg[0].put_size;
103   if (eaa->arg[1].get_size < n)
104     n = eaa->arg[1].get_size;
105   
106   memcpy(eaa->arg[0].ls_addr, eaa->arg[1].ls_addr, n);
107 }
108
109 GC_DECLARE_PROC(qa_copy, "qa_copy");