[ep-processor-libraries/dsplib.git] / ti / dsplib / src / DSPF_sp_mat_trans_cplx / c66 / DSPF_sp_mat_trans_cplx_d.c
1 /* ======================================================================= */
2 /* DSPF_sp_mat_trans_cplx_d.c -- Complex Matrix Transpose */
3 /* Driver code; tests kernel and reports result in stdout */
4 /* */
5 /* Rev 0.0.2 */
6 /* */
7 /* Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ */
8 /* */
9 /* */
10 /* Redistribution and use in source and binary forms, with or without */
11 /* modification, are permitted provided that the following conditions */
12 /* are met: */
13 /* */
14 /* Redistributions of source code must retain the above copyright */
15 /* notice, this list of conditions and the following disclaimer. */
16 /* */
17 /* Redistributions in binary form must rep roduce the above copyright */
18 /* notice, this list of conditions and the following disclaimer in the */
19 /* documentation and/or other materials provided with the */
20 /* distribution. */
21 /* */
22 /* Neither the name of Texas Instruments Incorporated nor the names of */
23 /* its contributors may be used to endorse or promote products derived */
24 /* from this software without specific prior written permission. */
25 /* */
26 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS */
27 /* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT */
28 /* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR */
29 /* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT */
30 /* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
31 /* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */
32 /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, */
33 /* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY */
34 /* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */
35 /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE */
36 /* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
37 /* */
38 /* ======================================================================= */
40 #include <stdio.h>
41 #include <time.h>
42 #include <stdlib.h>
43 #include <limits.h>
44 #include <c6x.h>
46 /* ======================================================================= */
47 /* Interface header files for the natural C and optimized C code */
48 /* ======================================================================= */
49 #include "DSPF_sp_mat_trans_cplx_cn.h"
50 #include "DSPF_sp_mat_trans_cplx.h"
52 /* Defines */
53 #if defined(__TI_EABI__)
54 #define kernel_size _kernel_size
55 #endif
57 extern char kernel_size;
59 #define FORMULA_SIZE 4
60 #define FORMULA_DEVIDE 1
61 #define CYCLE_FORMULA_NX_PT1 32
62 #define CYCLE_FORMULA_NX_PT2 16
63 #define CYCLE_FORMULA_NR_PT1 32
64 #define CYCLE_FORMULA_NR_PT2 16
65 /* inverse of [32*32 32 32 1] */
66 /* [32*16 32 16 1] */
67 /* [16*32 16 32 1] */
68 /* [16*16 16 16 1] */
69 float form_inv[FORMULA_SIZE][FORMULA_SIZE] =
70 {{ 0.0039, -0.0039, -0.0039, 0.0039},
71 {-0.0625, 0.1250, 0.0625, -0.1250},
72 {-0.0625, 0.0625, 0.1250, -0.1250},
73 { 1.0000, -2.0000, -2.0000, 4.0000}
74 };
75 float form_temp [FORMULA_SIZE];
76 int form_cycle [FORMULA_SIZE];
77 int form_result[FORMULA_SIZE];
79 /* ======================================================================= */
80 /* Tell compiler arrays are double word alligned */
81 /* ======================================================================= */
82 #pragma DATA_ALIGN(ptr_y_opt, 8);
83 #pragma DATA_ALIGN(ptr_y_cn, 8);
84 #pragma DATA_ALIGN(ptr_x, 8);
86 /* ======================================================================= */
87 /* Parameters of fixed dataset */
88 /* ======================================================================= */
89 #define NRmax (64)
90 #define NCmax (64)
92 float ptr_y_opt[2* NCmax * NRmax];
93 float ptr_y_cn[2 * NCmax * NRmax];
94 float ptr_x[2* NRmax * NCmax];
96 int NR, NC;
98 /* ======================================================================= */
99 /* Prototypes for timing functions */
100 /* ======================================================================= */
101 clock_t time_opt();
102 clock_t time_cn();
104 /* ======================================================================= */
105 /* Main -- Top level driver for testing the algorithm */
106 /* ======================================================================= */
107 int main()
108 {
109 clock_t t_overhead, t_start, t_stop, t_opt, t_cn;
110 float pct_diff, max_pct_diff = 0;
111 int fail = 0, k = 1, i, j, form_error = 0;
113 /* ------------------------------------------------------------------- */
114 /* Compute the overhead of calling clock twice to get timing info */
115 /* ------------------------------------------------------------------- */
116 /* Initialize timer for clock */
117 TSCL= 0,TSCH=0;
118 t_start = _itoll(TSCH, TSCL);
119 t_stop = _itoll(TSCH, TSCL);
120 t_overhead = t_stop - t_start;
122 /* ------------------------------------------------------------------- */
123 /* Fill input array with randomized data in range (-10, 10). */
124 /* ------------------------------------------------------------------- */
125 for (i = 0; i < 2* NRmax * NCmax; i++)
126 ptr_x[i] = ((rand() - (RAND_MAX / 2.0)) / (RAND_MAX / 2.0)) * 10.0;
128 for (NR = 2; NR <= NRmax; NR *= 2) {
129 for (NC = 2; NC <= NCmax; NC *= 2)
130 {
131 /* ----------------------------------------------------------- */
132 /* Clear state/output buffers with fixed values. */
133 /* ----------------------------------------------------------- */
134 memset(ptr_y_opt, 0, sizeof(ptr_y_opt));
135 memset(ptr_y_cn, 0, sizeof(ptr_y_cn));
137 /* ----------------------------------------------------------- */
138 /* Call the individual timing routines */
139 /* ----------------------------------------------------------- */
140 t_opt = time_opt() - t_overhead;
141 t_cn = time_cn() - t_overhead;
143 printf("DSPF_sp_mat_trans_cplx\tIter#: %d\t", k++);
145 /* ------------------------------------------------------------- */
146 /* compute percent difference and track max difference */
147 /* ------------------------------------------------------------- */
148 for (i = 0; i < NR * NC; i++) {
149 pct_diff = (ptr_y_cn[i] - ptr_y_opt[i]) / ptr_y_cn[i] * 100.0;
150 if (pct_diff < 0) pct_diff *= -1;
151 if (pct_diff > max_pct_diff) max_pct_diff = pct_diff;
152 }
153 if (max_pct_diff > 0.02)
154 printf("Result Failure, max_pct_diff=%f\n", max_pct_diff);
155 else
156 printf("Result Successful ");
158 /* ----------------------------------------------------------- */
159 /* Print timing results */
160 /* ----------------------------------------------------------- */
161 printf("\tNR = %d\tNC = %d\tnatC: %d\toptC: %d\n", NR, NC, t_cn, t_opt);
163 if (NR == CYCLE_FORMULA_NX_PT1 && NC == CYCLE_FORMULA_NR_PT1)
164 form_cycle[0] = t_opt;
165 if (NR == CYCLE_FORMULA_NX_PT1 && NC == CYCLE_FORMULA_NR_PT2)
166 form_cycle[1] = t_opt;
167 if (NR == CYCLE_FORMULA_NX_PT2 && NC == CYCLE_FORMULA_NR_PT1)
168 form_cycle[2] = t_opt;
169 if (NR == CYCLE_FORMULA_NX_PT2 && NC == CYCLE_FORMULA_NR_PT2)
170 form_cycle[3] = t_opt;
171 }
172 }
174 /* Provide memory information */
175 #ifdef __TI_COMPILER_VERSION__ // for TI compiler only
176 printf("Memory: %d bytes\n", &kernel_size);
177 #endif
179 /* Provide profiling information */
180 for (i = 0; i < FORMULA_SIZE; i++) {
181 form_temp[i] = 0;
182 for (j = 0; j < FORMULA_SIZE; j++) {
183 form_temp[i] += form_inv[i][j] * form_cycle[j];
184 }
185 if (i != (FORMULA_SIZE-1)) {
186 form_result[i] = (int) (form_temp[i] * FORMULA_DEVIDE + 0.5);
187 if ((form_result[i] - form_temp[i] * FORMULA_DEVIDE) > 0.1 ||
188 (form_result[i] - form_temp[i] * FORMULA_DEVIDE) < -0.1) {
189 form_error = 1;
190 }
191 }
192 else {
193 form_result[i] = (int) (form_temp[i] + 0.5);
194 }
195 }
197 if (!form_error) {
198 if (FORMULA_DEVIDE == 1) {
199 printf("Cycles: ");
200 if (form_result[0])
201 printf("%d*R*C + ", form_result[0]);
202 if (form_result[1])
203 printf("%d*R + ", form_result[1]);
204 if (form_result[2])
205 printf("%d*C + ", form_result[2]);
206 if (form_result[3])
207 printf("%d\n", form_result[3]);
208 }
209 else {
210 printf("Cycles: ");
211 if (form_result[0])
212 printf("%d/%d*R*C + ", form_result[0], FORMULA_DEVIDE);
213 if (form_result[1])
214 printf("%d/%d*R + ", form_result[1], FORMULA_DEVIDE);
215 if (form_result[2])
216 printf("%d/%d*C + ", form_result[2], FORMULA_DEVIDE);
217 if (form_result[3])
218 printf("%d\n", form_result[3]);
219 }
220 }
221 else
222 printf("Cycles Formula Not Available\n");
224 return (fail);
225 }
227 /* ======================================================================= */
228 /* Prototypes for timing functions */
229 /* ======================================================================= */
230 clock_t time_cn()
231 {
232 clock_t t_start, t_stop;
234 /* ------------------------------------------------------------------- */
235 /* Measure the cycle count */
236 /* ------------------------------------------------------------------- */
237 t_start = _itoll(TSCH, TSCL);
238 DSPF_sp_mat_trans_cplx_cn(ptr_x, NR, NC, ptr_y_cn);
239 t_stop = _itoll(TSCH, TSCL);
241 return t_stop - t_start;
242 }
244 clock_t time_opt()
245 {
246 clock_t t_start, t_stop;
248 /* ------------------------------------------------------------------- */
249 /* Measure the cycle count */
250 /* ------------------------------------------------------------------- */
251 t_start = _itoll(TSCH, TSCL);
252 DSPF_sp_mat_trans_cplx(ptr_x, NR, NC, ptr_y_opt);
253 t_stop = _itoll(TSCH, TSCL);
255 return t_stop - t_start;
256 }
258 /* ======================================================================= */
259 /* End of file: DSPF_sp_mat_submat_copy_cplx_d.c */
260 /* ----------------------------------------------------------------------- */
261 /* Copyright (c) 2011 Texas Instruments, Incorporated. */
262 /* All Rights Reserved. */
263 /* ======================================================================= */