]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - ep-processor-libraries/dsplib.git/blob - ti/dsplib/src/DSP_q15tofl/c66/DSP_q15tofl.c
DSPLIB: optimized signal processing functions for TI DSPs
[ep-processor-libraries/dsplib.git] / ti / dsplib / src / DSP_q15tofl / c66 / DSP_q15tofl.c
1 /* ======================================================================= */
2 /*  TEXAS INSTRUMENTS, INC.                                                */
3 /*                                                                         */
4 /*  DSPLIB  DSP Signal Processing Library                                  */
5 /*                                                                         */
6 /*  This library contains proprietary intellectual property of Texas       */
7 /*  Instruments, Inc.  The library and its source code are protected by    */
8 /*  various copyrights, and portions may also be protected by patents or   */
9 /*  other legal protections.                                               */
10 /*                                                                         */
11 /*  This software is licensed for use with Texas Instruments TMS320        */
12 /*  family DSPs.  This license was provided to you prior to installing     */
13 /*  the software.  You may review this license by consulting the file      */
14 /*  TI_license.PDF which accompanies the files in this library.            */
15 /*                                                                         */
16 /* ----------------------------------------------------------------------- */
17 /*                                                                         */
18 /* DSP_q15tofl.c -- Float to Q15 conversion                                */
19 /*                  Optimized C Implementation (w/ Intrinsics)             */
20 /*                                                                         */
21 /* Rev 0.0.1                                                               */
22 /*                                                                         */
23 /*  Usage                                                                  */
24 /*     This routine is C-callable and can be called as:                    */
25 /*                                                                         */
26 /*     void DSP_q15tofl (                                                  */
27 /*         const short *restrict q15, // Input Q15 array                   */
28 /*         float *restrict flt,       // Output float array                */
29 /*         short nx                   // Number of elements                */
30 /*     );                                                                  */
31 /*                                                                         */
32 /*     x[nx]  ---  Pointer to Q15 input vector of size nx                  */
33 /*     r[nx]  ---  Pointer to floating-point output data vector            */
34 /*                 of size nx containing the floating-point equivalent     */
35 /*                 of vector input                                         */
36 /*     nx     ---  length of input and output data vectors                 */
37 /*                                                                         */
38 /*  Description                                                            */
39 /*     Converts the Q15 stored in vector input to IEEE floating point      */
40 /*     numbers stored in vector output.                                    */
41 /*                                                                         */
42 /*     void q15tofl (short *q15, float *flt, int nx)                       */
43 /*     {                                                                   */
44 /*      int i;                                                             */
45 /*                                                                         */
46 /*      for (i=0;i<nx;i++)                                                 */
47 /*           flt[i]=(float)q15[i]/0x8000;                                  */
48 /*     }                                                                   */
49 /*                                                                         */
50 /*     The above C code is a general implementation without                */
51 /*     restrictions.  The assembly code may have some restrictions, as     */
52 /*     noted below.                                                        */
53 /*                                                                         */
54 /*  Assumptions                                                            */
55 /*     Arrays q15 and flt do not overlap                                   */
56 /*     nx >= 4;   nx % 4 == 0;                                             */
57 /*                                                                         */
58 /* Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/  */ 
59 /*                                                                         */
60 /*                                                                         */
61 /*  Redistribution and use in source and binary forms, with or without     */
62 /*  modification, are permitted provided that the following conditions     */
63 /*  are met:                                                               */
64 /*                                                                         */
65 /*    Redistributions of source code must retain the above copyright       */
66 /*    notice, this list of conditions and the following disclaimer.        */
67 /*                                                                         */
68 /*    Redistributions in binary form must reproduce the above copyright    */
69 /*    notice, this list of conditions and the following disclaimer in the  */
70 /*    documentation and/or other materials provided with the               */
71 /*    distribution.                                                        */
72 /*                                                                         */
73 /*    Neither the name of Texas Instruments Incorporated nor the names of  */
74 /*    its contributors may be used to endorse or promote products derived  */
75 /*    from this software without specific prior written permission.        */
76 /*                                                                         */
77 /*  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS    */
78 /*  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT      */
79 /*  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR  */
80 /*  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT   */
81 /*  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,  */
82 /*  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT       */
83 /*  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,  */
84 /*  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY  */
85 /*  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT    */
86 /*  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE  */
87 /*  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.   */
88 /*                                                                         */
89 /* ======================================================================= */
91 #pragma CODE_SECTION(DSP_q15tofl, ".text:optimized");
93 #include "DSP_q15tofl.h"
94 #ifdef __TI_COMPILER_VERSION__
95 #include "c6x.h"
96 #endif
98 #ifdef _LITTLE_ENDIAN
99 void DSP_q15tofl (
100     const short *restrict q15,  /* Input Q15 array      */
101     float *restrict flt,        /* Output float array   */
102     int   nx                    /* Number of elements   */
105     int       i;
106     long long input, ones;
107     float     temp;
108     __float2_t scale;
109     __x128_t  in_int;
111     /* to expand short into int with dmpy2 */
112     ones  = _itoll(0x00010001, 0x00010001);
114     /* scaling factor for Q15 */
115     temp  = 1./32768;
116     scale = _ftof2(temp, temp);
118     #pragma MUST_ITERATE(1,,1)
119     for (i = 0; i < nx; i += 4) {
120         input  = _amem8((void*)&q15[i]);
121         in_int = _dmpy2(input, ones);
122         _amem8_f2((void*)&flt[i+0]) = _dmpysp(_dintsp(_lo128(in_int)), scale);
123         _amem8_f2((void*)&flt[i+2]) = _dmpysp(_dintsp(_hi128(in_int)), scale);
124     }
126 #else
127 void DSP_q15tofl (
128     const short *restrict q15,  /* Input Q15 array      */
129     float *restrict flt,        /* Output float array   */
130     int   nx                    /* Number of elements   */
133     int       i;
134     long long input, ones;
135     float     temp;
136     __float2_t scale;
137     __x128_t  in_int;
139     /* to expand short into int with dmpy2 */
140     ones  = _itoll(0x00010001, 0x00010001);
142     /* scaling factor for Q15 */
143     temp  = 1./32768;
144     scale = _ftof2(temp, temp);
146     #pragma MUST_ITERATE(1,,1)
147     for (i = 0; i < nx; i += 4) {
148         input  = _amem8((void*)&q15[i]);
149         in_int = _dmpy2(input, ones);
150         _amem8_f2((void*)&flt[i+0]) = _dmpysp(_dintsp(_hi128(in_int)), scale);
151         _amem8_f2((void*)&flt[i+2]) = _dmpysp(_dintsp(_lo128(in_int)), scale);
152     }
154 #endif
155 /* ======================================================================= */
156 /*  End of file:  DSP_q15tofl.c                                            */
157 /* ----------------------------------------------------------------------- */
158 /*            Copyright (c) 2011 Texas Instruments, Incorporated.          */
159 /*                           All Rights Reserved.                          */
160 /* ======================================================================= */