Project Ne10
An open, optimized software library for the ARM architecture.
NE10_fft_cplx_ops.h
Go to the documentation of this file.
1 /*
2  * Copyright 2014-16 ARM Limited and Contributors.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of ARM Limited nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY ARM LIMITED AND CONTRIBUTORS "AS IS" AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL ARM LIMITED BE LIABLE FOR ANY
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 /* license of Kiss FFT */
29 /*
30 Copyright (c) 2003-2010, Mark Borgerding
31 
32 All rights reserved.
33 
34 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
35 
36  * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
37  * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
38  * Neither the author nor the names of any contributors may be used to endorse or promote products derived from this software without specific prior written permission.
39 
40 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 */
42 
43 /*
44  * NE10 Library : dsp/NE10_fft_cplx_ops.h
45  */
46 
47 #include "NE10_types.h"
48 
49 #ifndef NE10_FFT_CPLX_OPS_H
50 #define NE10_FFT_CPLX_OPS_H
51 
52 #ifdef __cplusplus
53 template<class T>
54 static inline void ne10_swap_ptr(T *&ptr_a, T *&ptr_b)
55 {
56  ptr_a = (T *)((intptr_t)(ptr_a) ^ (intptr_t)(ptr_b));
57  ptr_b = (T *)((intptr_t)(ptr_a) ^ (intptr_t)(ptr_b));
58  ptr_a = (T *)((intptr_t)(ptr_a) ^ (intptr_t)(ptr_b));
59 }
60 #else
61 #define ne10_swap_ptr(X,Y) \
62  do { \
63  X = (void *)((intptr_t)(X) ^ (intptr_t)(Y)); \
64  Y = (void *)((intptr_t)(X) ^ (intptr_t)(Y)); \
65  X = (void *)((intptr_t)(X) ^ (intptr_t)(Y)); \
66  } while (0)
67 #endif
68 
69 // Multiply scalar X by scalar Y
70 #define NE10_S_MUL(X,Y) ((X) * (Y))
71 
72 #define NE10_CPX_ADD(Z,A,B) \
73  do { \
74  Z.r = A.r + B.r; \
75  Z.i = A.i + B.i; \
76  } while (0)
77 
78 #define NE10_CPX_SUB(Z,A,B) \
79  do { \
80  Z.r = A.r - B.r; \
81  Z.i = A.i - B.i; \
82  } while (0)
83 
84 #define NE10_CPX_ADDTO(Z,X) NE10_CPX_ADD(Z,X,Z)
85 
86 #define NE10_CPX_MUL_F32(Z,A,B) \
87  do { \
88  ne10_float32_t ARBR = A.r * B.r; \
89  ne10_float32_t AIBI = A.i * B.i; \
90  ne10_float32_t ARBI = A.r * B.i; \
91  ne10_float32_t AIBR = A.i * B.r; \
92  Z.r = ARBR - AIBI; \
93  Z.i = AIBR + ARBI; \
94  } while (0)
95 
96 #define NE10_CPX_CONJ_MUL_F32(Z,A,B) \
97  do { \
98  ne10_float32_t ARBR = A.r * B.r; \
99  ne10_float32_t AIBI = A.i * B.i; \
100  ne10_float32_t ARBI = A.r * B.i; \
101  ne10_float32_t AIBR = A.i * B.r; \
102  Z.r = ARBR + AIBI; \
103  Z.i = AIBR - ARBI; \
104  } while (0)
105 
106 #define NE10_CPX_MUL_TW_F32(Z,TW) \
107  do { \
108  ne10_fft_cpx_float32_t tmp; \
109  NE10_CPX_MUL(tmp,Z,TW); \
110  Z = tmp; \
111  } while (0)
112 
113 #define NE10_CPX_MUL_INV_TW_F32(Z,TW) \
114  do { \
115  ne10_fft_cpx_float32_t tmp; \
116  NE10_CPX_CONJ_MUL(tmp,Z,TW); \
117  Z = tmp; \
118  } while (0)
119 
120 #endif // NE10_FFT_CPLX_OPS_H
#define ne10_swap_ptr(X, Y)