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_blk_eswap64.c -- Endian-swap a block of 64-bit values */
19 /* Intrinsic C Implementation */
20 /* */
21 /* Rev 0.0.1 */
22 /* */
23 /* USAGE */
24 /* This routine has the following C prototype: */
25 /* */
26 /* void DSP_blk_eswap64 */
27 /* ( */
28 /* double *restrict src, // Source data */
29 /* double *restrict dst, // Destination array */
30 /* int n_dbls // Number of double-words to swap */
31 /* ); */
32 /* */
33 /* This function performs an endian-swap on the data in the "src" */
34 /* array, writing the results to "dst". If NULL is passed in for */
35 /* the destination, then the endian-swap is performed in-place. */
36 /* The "n_dbls" argument gives the total length of the array. */
37 /* */
38 /* DESCRIPTION */
39 /* The data in the "src" array is endian swapped, meaning that the */
40 /* byte-order of the bytes within each word of the src[] array is */
41 /* reversed. This is meant to facilitate moving big-endian data */
42 /* to a little-endian system or vice-versa. */
43 /* */
44 /* When the "dst" pointer is non-NULL, the endian-swap occurs */
45 /* out-of-place, similar to a block move. When the "dst" pointer */
46 /* is NULL, the endian-swap occurs in-place, allowing the swap to */
47 /* occur without using any additional storage. */
48 /* */
49 /* ASSUMPTIONS */
50 /* Input and output arrays do not overlap, except in the very */
51 /* specific case that "dst == NULL" so that the operation occurs */
52 /* in-place. */
53 /* */
54 /* The input array and output array are expected to be double-word */
55 /* aligned, and a multiple of 2 double-words must be processed. */
56 /* */
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_blk_eswap64, ".text:optimized");
93 #include "DSP_blk_eswap64.h"
95 void DSP_blk_eswap64 (
96 void *restrict src,
97 void *restrict dst,
98 int n_dbls
99 )
100 {
101 int i;
102 char *_src, *_dst;
104 _nassert(n_dbls >= 2);
105 _nassert(n_dbls % 2 == 0);
107 _src = (char *)src;
108 _dst = (char *)dst;
110 if (dst) {
111 _nassert((int)_src % 8 == 0);
112 _nassert((int)_dst % 8 == 0);
113 #pragma UNROLL(2);
114 for (i = 0; i < n_dbls; i++)
115 _amemd8(&_dst[i * 8]) =
116 _itod(_rotl(_swap4(_lo(_amemd8(&_src[i * 8]))),16),
117 _rotl(_swap4(_hi(_amemd8(&_src[i * 8]))),16));
118 }
119 else {
120 _nassert((int)_src % 8 == 0);
121 #pragma UNROLL(2);
122 for (i = 0; i < n_dbls; i++)
123 _amemd8(&_src[i * 8]) =
124 _itod(_rotl(_swap4(_lo(_amemd8(&_src[i * 8]))),16),
125 _rotl(_swap4(_hi(_amemd8(&_src[i * 8]))),16));
126 }
127 }
129 /* ======================================================================== */
130 /* End of file: DSP_blk_eswap64.c */
131 /* ------------------------------------------------------------------------ */
132 /* Copyright (c) 2011 Texas Instruments, Incorporated. */
133 /* All Rights Reserved. */
134 /* ======================================================================== */