minilogue xd SDK  v1.1-0
buffer_ops.h
Go to the documentation of this file.
1 /*
2  BSD 3-Clause License
3 
4  Copyright (c) 2018, KORG INC.
5  All rights reserved.
6 
7  Redistribution and use in source and binary forms, with or without
8  modification, are permitted provided that the following conditions are met:
9 
10  * Redistributions of source code must retain the above copyright notice, this
11  list of conditions and the following disclaimer.
12 
13  * Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17  * Neither the name of the copyright holder nor the names of its
18  contributors may be used to endorse or promote products derived from
19  this software without specific prior written permission.
20 
21  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 
32 //*/
33 
46 #ifndef __buffer_ops_h
47 #define __buffer_ops_h
48 
49 #include "fixed_math.h"
50 #include "int_math.h"
51 #include "float_math.h"
52 
53 #define REP4(expr) (expr);(expr);(expr);(expr);
54 
62 static inline __attribute__((optimize("Ofast"),always_inline))
63 void buf_q31_to_f32(const q31_t *q31,
64  float * __restrict__ flt,
65  const size_t len)
66 {
67  const float *end = flt + ((len>>2)<<2);
68  for (; flt != end; ) {
69  REP4(*(flt++) = q31_to_f32(*(q31++)));
70  };
71  end += len & 0x3;
72  for (; flt != end; ) {
73  *(flt++) = q31_to_f32(*(q31++));
74  }
75 }
76 
79 static inline __attribute__((optimize("Ofast"),always_inline))
80 void buf_f32_to_q31(const float *flt,
81  q31_t * __restrict__ q31,
82  const size_t len)
83 {
84  const float *end = flt + ((len>>2)<<2);
85  for (; flt != end; ) {
86  REP4(*(q31++) = f32_to_q31(*(flt++)));
87  }
88  end += len & 0x3;
89  for (; flt != end; ) {
90  *(q31++) = f32_to_q31(*(flt++));
91  }
92 }
93 
94 //** @} */
95 
103 static inline __attribute__((optimize("Ofast"),always_inline))
104 void buf_clr_f32(float * __restrict__ ptr,
105  const uint32_t len)
106 {
107  const float *end = ptr + ((len>>2)<<2);
108  for (; ptr != end; ) {
109  REP4(*(ptr++) = 0);
110  }
111  end += len & 0x3;
112  for (; ptr != end; ) {
113  *(ptr++) = 0;
114  }
115 }
116 
119 static inline __attribute__((optimize("Ofast"),always_inline))
120 void buf_clr_u32(uint32_t * __restrict__ ptr,
121  const size_t len)
122 {
123  const uint32_t *end = ptr + ((len>>2)<<2);
124  for (; ptr != end; ) {
125  REP4(*(ptr++) = 0);
126  }
127  end += len & 0x3;
128  for (; ptr != end; ) {
129  *(ptr++) = 0;
130  }
131 }
132 
133 //** @} */
134 
142 static inline __attribute__((optimize("Ofast"),always_inline))
143 void buf_cpy_f32(const float *src,
144  float * __restrict__ dst,
145  const size_t len)
146 {
147  const float *end = src + ((len>>2)<<2);
148  for (; src != end; ) {
149  REP4(*(dst++) = *(src++));
150  }
151  end += len & 0x3;
152  for (; src != end; ) {
153  *(dst++) = *(src++);
154  }
155 }
156 
159 static inline __attribute__((optimize("Ofast"),always_inline))
160 void buf_cpy_u32(const uint32_t *src,
161  uint32_t * __restrict__ dst,
162  const size_t len)
163 {
164  const uint32_t *end = src + ((len>>2)<<2);
165  for (; src != end; ) {
166  REP4(*(dst++) = *(src++));
167  }
168  end += len & 0x3;
169  for (; src != end; ) {
170  *(dst++) = *(src++);
171  }
172 }
173 
174 //** @} */
175 
176 #endif // __buffer_ops_h
177 
buf_cpy_f32
static void buf_cpy_f32(const float *src, float *__restrict__ dst, const size_t len)
Buffer copy (float version).
Definition: buffer_ops.h:143
fixed_math.h
Fixed Point Math Utilities.
buf_q31_to_f32
static void buf_q31_to_f32(const q31_t *q31, float *__restrict__ flt, const size_t len)
Buffer-wise Q31 to float conversion.
Definition: buffer_ops.h:63
int_math.h
Integer Math Utilities.
float_math.h
Floating Point Math Utilities.
buf_clr_u32
static void buf_clr_u32(uint32_t *__restrict__ ptr, const size_t len)
Buffer clear (32bit unsigned integer version).
Definition: buffer_ops.h:120
buf_cpy_u32
static void buf_cpy_u32(const uint32_t *src, uint32_t *__restrict__ dst, const size_t len)
Buffer copy (32bit unsigned integer version).
Definition: buffer_ops.h:160
buf_clr_f32
static void buf_clr_f32(float *__restrict__ ptr, const uint32_t len)
Buffer clear (float version)
Definition: buffer_ops.h:104
buf_f32_to_q31
static void buf_f32_to_q31(const float *flt, q31_t *__restrict__ q31, const size_t len)
Buffer-wise float to Q31 conversion.
Definition: buffer_ops.h:80