Imported Upstream version 3.2.2
[debian/gnuradio] / gcell / lib / runtime / spu / gcell_runtime_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 <gcell/gc_declare_proc.h>
23 #include <gcell/spu/gc_delay.h>
24 #include <string.h>
25
26
27 static void
28 qa_nop(const gc_job_direct_args_t *input _UNUSED,
29        gc_job_direct_args_t *output _UNUSED,
30        const gc_job_ea_args_t *eaa _UNUSED)
31 {
32 }
33
34 GC_DECLARE_PROC(qa_nop, "qa_nop");
35
36 static int
37 sum_shorts(short *p, int nshorts)
38 {
39   int total = 0;
40   for (int i = 0; i < nshorts; i++)
41     total += p[i];
42
43   return total;
44 }
45
46 static void
47 qa_sum_shorts(const gc_job_direct_args_t *input _UNUSED,
48               gc_job_direct_args_t *output,
49               const gc_job_ea_args_t *eaa)
50 {
51   for (unsigned int i = 0; i < eaa->nargs; i++){
52     short *p = eaa->arg[i].ls_addr;
53     int n = eaa->arg[i].get_size / sizeof(short);
54     output->arg[i].s32 = sum_shorts(p, n);
55     //printf("qa_sum_shorts(%p, %d) = %d\n",  p, n, output->arg[i].s32);
56   }
57 }
58
59 GC_DECLARE_PROC(qa_sum_shorts, "qa_sum_shorts");
60
61 static void
62 write_seq(unsigned char *p, int nbytes, int counter)
63 {
64   for (int i = 0; i < nbytes; i++)
65     p[i] = counter++;
66 }
67
68 static void
69 qa_put_seq(const gc_job_direct_args_t *input,
70            gc_job_direct_args_t *output _UNUSED,
71            const gc_job_ea_args_t *eaa)
72 {
73   int counter = input->arg[0].s32;
74
75   for (unsigned int i = 0; i < eaa->nargs; i++){
76     unsigned char *p = eaa->arg[i].ls_addr;
77     int n = eaa->arg[i].put_size;
78     write_seq(p, n, counter);
79     counter += n;
80   }
81 }
82
83 GC_DECLARE_PROC(qa_put_seq, "qa_put_seq");
84
85 static void
86 qa_copy(const gc_job_direct_args_t *input _UNUSED,
87         gc_job_direct_args_t *output,
88         const gc_job_ea_args_t *eaa)
89 {
90   if (eaa->nargs != 2
91       || eaa->arg[0].direction != GCJD_DMA_PUT
92       || eaa->arg[1].direction != GCJD_DMA_GET){
93     output->arg[0].s32 = -1;
94     return;
95   }
96
97   output->arg[0].s32 = 0;
98   unsigned n = eaa->arg[0].put_size;
99   if (eaa->arg[1].get_size < n)
100     n = eaa->arg[1].get_size;
101   
102   memcpy(eaa->arg[0].ls_addr, eaa->arg[1].ls_addr, n);
103 }
104
105 GC_DECLARE_PROC(qa_copy, "qa_copy");