]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - ep-processor-libraries/dsplib.git/blob - ti/dsplib/src/DSP_blk_eswap16/c66/DSP_blk_eswap16_d.c
DSPLIB: optimized signal processing functions for TI DSPs
[ep-processor-libraries/dsplib.git] / ti / dsplib / src / DSP_blk_eswap16 / c66 / DSP_blk_eswap16_d.c
1 /* ======================================================================= */
2 /* DSP_blk_eswap16_d.c -- Endian-swap a block of 16-bit values             */
3 /*                        Driver code implementation                       */
4 /*                                                                         */
5 /* Rev 0.0.1                                                               */
6 /*                                                                         */
7 /*                                                                         */
8 /* Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/  */ 
9 /*                                                                         */
10 /*                                                                         */
11 /*  Redistribution and use in source and binary forms, with or without     */
12 /*  modification, are permitted provided that the following conditions     */
13 /*  are met:                                                               */
14 /*                                                                         */
15 /*    Redistributions of source code must retain the above copyright       */
16 /*    notice, this list of conditions and the following disclaimer.        */
17 /*                                                                         */
18 /*    Redistributions in binary form must reproduce the above copyright    */
19 /*    notice, this list of conditions and the following disclaimer in the  */
20 /*    documentation and/or other materials provided with the               */
21 /*    distribution.                                                        */
22 /*                                                                         */
23 /*    Neither the name of Texas Instruments Incorporated nor the names of  */
24 /*    its contributors may be used to endorse or promote products derived  */
25 /*    from this software without specific prior written permission.        */
26 /*                                                                         */
27 /*  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS    */
28 /*  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT      */
29 /*  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR  */
30 /*  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT   */
31 /*  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,  */
32 /*  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT       */
33 /*  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,  */
34 /*  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY  */
35 /*  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT    */
36 /*  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE  */
37 /*  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.   */
38 /*                                                                         */
39 /* ======================================================================= */
41 #include <stdio.h>
42 #include <time.h>
43 #include <stdlib.h>
44 #include <limits.h>
45 #include <c6x.h>
47 #include "DSP_blk_eswap16_cn.h"
48 #include "DSP_blk_eswap16.h"
50 /* Defines */
51 #if defined(__TI_EABI__)
52 #define kernel_size _kernel_size
53 #endif
55 extern char kernel_size;
57 #define FORMULA_SIZE          2
58 #define FORMULA_DEVIDE        4
59 #define CYCLE_FORMULA_NX_PT1  64
60 #define CYCLE_FORMULA_NX_PT2  128
61 /* inverse of [ 64 1] */
62 /*            [128 1] */
63 float form_inv[FORMULA_SIZE][FORMULA_SIZE] = 
64 {{-0.0156,  0.0156},
65  { 2.0000, -1.0000}
66 };
67 float form_temp  [FORMULA_SIZE];
68 int   form_cycle [FORMULA_SIZE];
69 int   form_result[FORMULA_SIZE];
71 /* ======================================================================== */
72 /*  Parameters of fixed dataset.                                            */
73 /* ======================================================================== */
74 #define NX (128)
75 #define PAD (16)
78 /* ======================================================================== */
79 /*  Initialized arrays with fixed test data.                                */
80 /* ======================================================================== */
81 short x[NX + 2*PAD] =
82 {
83      0x032C, -0x544D, -0x6A9D,  0x09C4,  0x5226,  0x6A85,  0x6EDE,  0x1463,
84     -0x158A,  0x75BC,  0x7407,  0x160B, -0x0E16, -0x3F82,  0x5F6D, -0x567B,
86      0x453E, -0x321D,  0x2DBB,  0x77C7, -0x57B9, -0x4ADD,  0x10B7, -0x113F,
87     -0x1A92,  0x7CA7,  0x4A14,  0x719D,  0x3E61,  0x1858, -0x0D4C,  0x3D94,
88     -0x32B8, -0x14B2,  0x1B6A,  0x7A1D,  0x0D5B,  0x1D2C,  0x55D8, -0x5459,
89      0x5030, -0x5CBD,  0x0180,  0x059B,  0x4D97,  0x49E3,  0x68A4, -0x3629,
90     -0x7AA5, -0x582E,  0x1D05,  0x3A65, -0x4734,  0x3D6B, -0x6CE3,  0x4A99,
91      0x1D54, -0x50B4,  0x62F5, -0x75A7, -0x6AFA,  0x5D26,  0x3C1A, -0x793D,
92     -0x6493,  0x4282, -0x0020,  0x1BE0,  0x1A7F,  0x621B, -0x1C86, -0x254E,
93     -0x12FB, -0x4E5B,  0x3409,  0x223E,  0x3856, -0x4179, -0x60C9, -0x102C,
94      0x5EB6, -0x097B,  0x7A6E,  0x1450, -0x41CD, -0x133A,  0x0358, -0x2677,
95     -0x0BA0,  0x6732,  0x19A5, -0x4961, -0x1E47, -0x6657,  0x57C6,  0x1E70,
96      0x1F12,  0x59F9,  0x13A4,  0x16D9,  0x26E6, -0x4FE0,  0x39FA, -0x6AF4,
97     -0x2829, -0x673F,  0x7460,  0x57A6, -0x5BB4,  0x424C, -0x6068,  0x2CC9,
98      0x0F61, -0x4030, -0x00AD,  0x6AE1, -0x4FD3,  0x56ED,  0x2FDA, -0x759C,
99     -0x726F,  0x78E3,  0x42DF, -0x63D3, -0x1F88, -0x71D0,  0x07E8, -0x6D4A,
100      0x21E5, -0x6C4D, -0x0072,  0x0EEE,  0x749D, -0x4622, -0x2AF7, -0x3A2B,
101      0x3DC4,  0x05D0, -0x00C7,  0x059F,  0x1C52,  0x36EE,  0x58B6, -0x7864,
103     -0x56B3, -0x3AA9,  0x438B,  0x1C64,  0x62BE, -0x5E6A,  0x7A07,  0x0D08,
104      0x6089, -0x5D4D,  0x0B27,  0x4A2C,  0x79F5,  0x5A86,  0x4061, -0x4411
105 };
107 short x_cn[NX + 2*PAD];
108 short x_i[NX + 2*PAD];
110 short r_cn[NX + 2*PAD];
111 short r_i[NX + 2*PAD];
113 /* ======================================================================== */
114 /*  Generate pointers to skip beyond array padding                          */
115 /* ======================================================================== */
116 short *const ptr_x_cn = x_cn + PAD;
117 short *const ptr_r_cn = r_cn + PAD;
119 short *const ptr_x_i = x_i + PAD;
120 short *const ptr_r_i = r_i + PAD;
122 /* ======================================================================== */
123 /*  Prototypes for timing functions.                                        */
124 /* ======================================================================== */
125 clock_t time_cn(int nx);
126 clock_t time_i(int nx);
128 /* ======================================================================== */
129 /*  MAIN -- Top level driver for the test.                                  */
130 /* ======================================================================== */
131 int main()
132 {   
133     clock_t t_overhead, t_start, t_stop;
134     clock_t t_cn, t_i;
135     int i, j, nx, fail = 0;
136     int form_error = 0;
138     /* -------------------------------------------------------------------- */
139     /* Initialize timer for clock */
140     TSCL= 0,TSCH=0;
141     /*  Compute the overhead of calling _itoll(TSCH, TSCL) twice to get timing info.   */
142     /* -------------------------------------------------------------------- */
143     t_start = _itoll(TSCH, TSCL);
144     t_stop = _itoll(TSCH, TSCL);
145     t_overhead = t_stop - t_start;
147     for(nx = 8, i = 1; nx <= NX; i++, nx += 8) {
148         /* -------------------------------------------------------------------- */
149         /*  Copy vector to all inputs.                                          */
150         /* -------------------------------------------------------------------- */
151         memcpy(x_cn, x, sizeof(x_cn));
152         memcpy(x_i, x, sizeof(x_i));
154         /* -------------------------------------------------------------------- */
155         /*  Force uninitialized arrays to fixed values.                         */
156         /* -------------------------------------------------------------------- */
157         memset(r_cn, 0xA5, sizeof(r_cn));
158         memset(r_i, 0xA5, sizeof(r_i));
160         /* -------------------------------------------------------------------- */
161         /*  Call the individual timing routines, and subtract off overhead.     */
162         /* -------------------------------------------------------------------- */
163         t_cn = time_cn(nx) - t_overhead;
164         t_i = time_i(nx) - t_overhead;
166         /* -------------------------------------------------------------------- */
167         /*  Print timing results.                                               */
168         /* -------------------------------------------------------------------- */
169         printf("DSP_blk_eswap16\tIter#: %d\t", i);
171         /* -------------------------------------------------------------------- */
172         /*  Check the results arrays, and report any failures.                  */
173         /* -------------------------------------------------------------------- */
174         if (memcmp(x_i, x_cn, sizeof(x_cn))) {
175             fail++;
176             printf("Result Failure (x_i)\t");
177         }
178         else
179             printf("Result Successful (x_i)\t");
181         if (memcmp(r_i, r_cn, sizeof(r_cn))) {
182             fail++;
183             printf("Result Failure (r_i)");
184         }
185         else
186             printf("Result Successful (r_i)");
188         printf("\tNX = %d\tnatC: %d\tintC: %d\n", nx, t_cn, t_i);
190         if (nx == CYCLE_FORMULA_NX_PT1)
191           form_cycle[0] = t_i;
192         if (nx == CYCLE_FORMULA_NX_PT2)
193           form_cycle[1] = t_i;
194     }
196     /* Provide memory information */
197 #ifdef __TI_COMPILER_VERSION__            // for TI compiler only
198     printf("Memory:  %d bytes\n", &kernel_size);
199 #endif
201     /* Provide profiling information */
202     for (i = 0; i < FORMULA_SIZE; i++) {
203         form_temp[i] = 0;
204         for (j = 0; j < FORMULA_SIZE; j++) {
205             form_temp[i] += form_inv[i][j] * form_cycle[j];
206         }
207         if (i != (FORMULA_SIZE-1)) {
208             form_result[i] = (int) (form_temp[i] * FORMULA_DEVIDE + 0.5);
209             if ((form_result[i] - form_temp[i] * FORMULA_DEVIDE) >  0.1 ||
210                 (form_result[i] - form_temp[i] * FORMULA_DEVIDE) < -0.1) {
211                 form_error = 1;
212             }
213         }
214         else {
215             form_result[i] = (int) (form_temp[i] + 0.5);
216         }
217     }
219     if (!form_error)
220       printf("Cycles:  %d/%d*n_hwords + %d \n", form_result[0], FORMULA_DEVIDE, form_result[1]);
221     else
222       printf("Cycles Formula Not Available\n");
224     return (fail);
227 /* ======================================================================== */
228 /*  TIME_CN  -- Measure elapsed time for natural C version.                 */
229 /* ======================================================================== */
230 clock_t time_cn(int nx)
232     clock_t t_start, t_stop;
234     t_start = _itoll(TSCH, TSCL);
235     DSP_blk_eswap16_cn(ptr_x_cn, ptr_r_cn, nx);
236     t_stop = _itoll(TSCH, TSCL);
237     DSP_blk_eswap16_cn(ptr_x_cn, NULL, nx);
238     return t_stop - t_start;
241 /* ======================================================================== */
242 /*  TIME_I   -- Measure elapsed time for intrinsic C version.               */
243 /* ======================================================================== */
244 clock_t time_i(int nx)
246     clock_t t_start, t_stop;
248     t_start = _itoll(TSCH, TSCL);
249     DSP_blk_eswap16(ptr_x_i, ptr_r_i, nx);
250     t_stop = _itoll(TSCH, TSCL);
251     DSP_blk_eswap16(ptr_x_i, NULL, nx);
252     return t_stop - t_start;
255 /* ======================================================================== */
256 /*  End of file:  DSP_blk_eswap16_d.c                                       */
257 /* ------------------------------------------------------------------------ */
258 /*          Copyright (C) 2011 Texas Instruments, Incorporated.             */
259 /*                          All Rights Reserved.                            */
260 /* ======================================================================== */