1 /* ======================================================================= */
2 /* DSP_add16_d.c -- add16 driver code implementation */
3 /* */
4 /* Rev 0.0.1 */
5 /* */
6 /* Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ */
7 /* */
8 /* */
9 /* Redistribution and use in source and binary forms, with or without */
10 /* modification, are permitted provided that the following conditions */
11 /* are met: */
12 /* */
13 /* Redistributions of source code must retain the above copyright */
14 /* notice, this list of conditions and the following disclaimer. */
15 /* */
16 /* Redistributions in binary form must reproduce the above copyright */
17 /* notice, this list of conditions and the following disclaimer in the */
18 /* documentation and/or other materials provided with the */
19 /* distribution. */
20 /* */
21 /* Neither the name of Texas Instruments Incorporated nor the names of */
22 /* its contributors may be used to endorse or promote products derived */
23 /* from this software without specific prior written permission. */
24 /* */
25 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS */
26 /* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT */
27 /* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR */
28 /* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT */
29 /* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
30 /* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */
31 /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, */
32 /* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY */
33 /* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */
34 /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE */
35 /* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
36 /* */
37 /* ======================================================================= */
39 #include <stdio.h>
40 #include <time.h>
41 #include <stdlib.h>
42 #include <c6x.h>
44 /* Interface header files for the natural C and optimized C code */
45 #include "DSP_add16_cn.h"
46 #include "DSP_add16.h"
48 #define MAXARRAYSIZE 128
50 #pragma DATA_ALIGN(x, 8);
51 #pragma DATA_ALIGN(y, 8);
52 #pragma DATA_ALIGN(r1, 8);
53 #pragma DATA_ALIGN(r2, 8);
55 /* Defines */
56 #if defined(__TI_EABI__)
57 #define kernel_size _kernel_size
58 #endif
60 extern char kernel_size;
62 #define FORMULA_SIZE 2
63 #define FORMULA_DEVIDE 8
64 #define CYCLE_FORMULA_NX_PT1 64
65 #define CYCLE_FORMULA_NX_PT2 128
66 /* inverse of [ 64 1] */
67 /* [128 1] */
68 float form_inv[FORMULA_SIZE][FORMULA_SIZE] =
69 {{-0.0156, 0.0156},
70 { 2.0000, -1.0000}
71 };
72 float form_temp [FORMULA_SIZE];
73 int form_cycle [FORMULA_SIZE];
74 int form_result[FORMULA_SIZE];
76 /* ======================================================================= */
77 /* Initilized arrays with fixed test data */
78 /* ======================================================================= */
79 short x[MAXARRAYSIZE]=
80 {
81 0x5A0A, 0xCD7B, 0x8397, 0xA5BC, 0xB196, 0x963C, 0x61C8, 0xE43A,
82 0x1C8B, 0x55F2, 0x32B9, 0xB3DD, 0xE468, 0x64CE, 0x3F29, 0x2815,
83 0x99CB, 0x813E, 0xCAB7, 0xE031, 0xE954, 0x8AF2, 0x9943, 0x2780,
84 0x8DC1, 0x2C18, 0xA0EA, 0x6371, 0x9033, 0x2F1F, 0xF36D, 0xB972,
85 0x5B46, 0x9837, 0x6009, 0x7354, 0x7CBB, 0xCB4E, 0x4D5F, 0x90E4,
86 0x27B1, 0xCBF3, 0xD4CD, 0xCA53, 0xD3A7, 0xDD56, 0xEF72, 0x866E,
87 0x637B, 0x6CE5, 0x084D, 0x3A65, 0xCA8D, 0x45D0, 0x8A5D, 0xB246,
88 0x031B, 0xBC84, 0xB401, 0x9DC2, 0xB285, 0xE273, 0x6C99, 0xE626,
89 0x3D8A, 0x5E49, 0x0742, 0xDAE3, 0x7488, 0x5DF7, 0x36BD, 0xA466,
90 0xBE5F, 0x8DAB, 0x6647, 0xCF7F, 0x8A8D, 0xBFF5, 0x3E81, 0x867D,
91 0x1CD2, 0x1103, 0xF7C9, 0x8B0F, 0xAE8D, 0x03A4, 0x22BE, 0x7CC3,
92 0x739C, 0x9D08, 0xC9DF, 0xB2AA, 0x155F, 0x2D3D, 0x80AC, 0xD731,
93 0x9654, 0x0273, 0x9582, 0x5C69, 0xBC3B, 0xB957, 0x3641, 0x293F,
94 0x3533, 0x94DA, 0x1E69, 0xE5A3, 0xD45A, 0xC82B, 0x8758, 0xFAC3,
95 0x7ED0, 0x3E98, 0x4E2C, 0x3C10, 0xDED3, 0x0110, 0x3666, 0xD178,
96 0x9683, 0xD6E3, 0x3A24, 0x22E9, 0xFC9F, 0xCD7F, 0x3DE5, 0x2133,
97 };
99 short y[MAXARRAYSIZE] =
100 {
101 0x6DE5, 0xD5F3, 0x86A9, 0x8805, 0x8695, 0x54AF, 0xE1AD, 0x5BEE,
102 0x856E, 0x8261, 0x0052, 0xA09D, 0xCBAE, 0x9EF8, 0x01F5, 0x52E1,
103 0xE2D5, 0xC8A4, 0x55F7, 0xB8A8, 0x1121, 0x6813, 0xE576, 0xBCE3,
104 0x1112, 0xB2B4, 0x4070, 0x4C3F, 0x5407, 0xF997, 0x9346, 0xD36C,
105 0xDFDE, 0x428A, 0xB497, 0x7E59, 0x5157, 0x6DBD, 0x20E0, 0x23F5,
106 0x0D70, 0x34BE, 0x8481, 0x744F, 0xD429, 0x4CBC, 0xC51A, 0xBE15,
107 0x9F01, 0xD327, 0x8468, 0xF118, 0x3D36, 0x8B2D, 0xF0EC, 0x4CA5,
108 0xEDE8, 0xCE3D, 0x3A04, 0xF5AC, 0x5EB5, 0x2187, 0x7BCE, 0x077C,
109 0xFCFD, 0xDF80, 0xC98B, 0xE564, 0xE27F, 0xE342, 0xB89A, 0xF7D3,
110 0x4F39, 0xBA12, 0xF418, 0x0337, 0x6F4B, 0x13D7, 0x4B05, 0x54A1,
111 0x2394, 0x5020, 0xFC80, 0x913E, 0x8252, 0x889D, 0x1FE9, 0xEBDE,
112 0x96A4, 0x07DD, 0x959E, 0x80B0, 0x56EB, 0xF72D, 0xA67D, 0xCFC3,
113 0xBD24, 0x437E, 0x08C7, 0xE546, 0xFC8E, 0x7F3E, 0x5B7A, 0x85A7,
114 0x5609, 0xCF9D, 0xFB15, 0x6ED7, 0x9BF4, 0x3289, 0x5037, 0x0443,
115 0x9B2D, 0x1E91, 0x0DE0, 0x60DB, 0xF474, 0xAC45, 0x0A2D, 0xBFCE,
116 0x4848, 0x8093, 0x577F, 0x75CB, 0x2727, 0x898B, 0xF1D3, 0x2781,
117 };
119 short r1[MAXARRAYSIZE];
120 short r2[MAXARRAYSIZE];
122 void main(void)
123 {
124 clock_t t_overhead, time, time_n;
125 int i, j, arraySize;
126 int fail = 0;
127 int form_error = 0;
129 /* Initialize timer for clock */
130 TSCL= 0,TSCH=0;
131 /* Compute the overhead of calling _itoll(TSCH, TSCL) twice to get timing info. */
132 t_overhead = _itoll(TSCH, TSCL);
133 t_overhead = _itoll(TSCH, TSCL) - t_overhead;
135 /* Test arrays with size from 8 to 2048 elements. */
136 /* Fill each array with random data and do add16. */
137 for(i = 1, arraySize = 8; arraySize <= MAXARRAYSIZE; arraySize *= 2, i++) {
139 /* And now measure the performance for an array size of 2048 elements. */
140 time_n = _itoll(TSCH, TSCL);
141 DSP_add16_cn(x, y, r2, arraySize);
142 time_n = _itoll(TSCH, TSCL) - time_n - t_overhead;
144 time = _itoll(TSCH, TSCL);
145 DSP_add16(x, y, r1, arraySize);
146 time = _itoll(TSCH, TSCL) - time - t_overhead;
148 /* =================================================================== */
149 /* Print timing results */
150 /* =================================================================== */
151 printf("DSP_add16\tIter#: %d\t", i);
153 /* =================================================================== */
154 /* Check the results arrays, and report any failures */
155 /* =================================================================== */
156 if (memcmp(r1, r2, arraySize)) {
157 fail++;
158 printf("Result Failure (r_i)");
159 }
160 else
161 printf("Result Successful (r_i)");
163 printf("\tNX = %d\tnatC: %d\toptC: %d\n", arraySize, time_n, time);
165 if (arraySize == CYCLE_FORMULA_NX_PT1)
166 form_cycle[0] = time;
167 if (arraySize == CYCLE_FORMULA_NX_PT2)
168 form_cycle[1] = time;
169 }
171 /* Provide memory information */
172 #ifdef __TI_COMPILER_VERSION__ // for TI compiler only
173 printf("Memory: %d bytes\n", &kernel_size);
174 #endif
176 /* Provide profiling information */
177 for (i = 0; i < FORMULA_SIZE; i++) {
178 form_temp[i] = 0;
179 for (j = 0; j < FORMULA_SIZE; j++) {
180 form_temp[i] += form_inv[i][j] * form_cycle[j];
181 }
182 if (i != (FORMULA_SIZE-1)) {
183 form_result[i] = (int) (form_temp[i] * FORMULA_DEVIDE + 0.5);
184 if ((form_result[i] - form_temp[i] * FORMULA_DEVIDE) > 0.1 ||
185 (form_result[i] - form_temp[i] * FORMULA_DEVIDE) < -0.1) {
186 form_error = 1;
187 }
188 }
189 else {
190 form_result[i] = (int) (form_temp[i] + 0.5);
191 }
192 }
194 if (!form_error)
195 printf("Cycles: %d/%d*Nx + %d \n", form_result[0], FORMULA_DEVIDE, form_result[1]);
196 else
197 printf("Cycles Formula Not Available\n");
198 }
200 /* ======================================================================== */
201 /* End of file: DSP_add16_d.c */
202 /* ------------------------------------------------------------------------ */
203 /* Copyright (c) 2011 Texas Instruments, Incorporated. */
204 /* All Rights Reserved. */
205 /* ======================================================================== */