sl@0
|
1 |
/*
|
sl@0
|
2 |
* LIBOIL - Library of Optimized Inner Loops
|
sl@0
|
3 |
* Copyright (c) 2003,2004 David A. Schleef <ds@schleef.org>
|
sl@0
|
4 |
* All rights reserved.
|
sl@0
|
5 |
*
|
sl@0
|
6 |
* Redistribution and use in source and binary forms, with or without
|
sl@0
|
7 |
* modification, are permitted provided that the following conditions
|
sl@0
|
8 |
* are met:
|
sl@0
|
9 |
* 1. Redistributions of source code must retain the above copyright
|
sl@0
|
10 |
* notice, this list of conditions and the following disclaimer.
|
sl@0
|
11 |
* 2. Redistributions in binary form must reproduce the above copyright
|
sl@0
|
12 |
* notice, this list of conditions and the following disclaimer in the
|
sl@0
|
13 |
* documentation and/or other materials provided with the distribution.
|
sl@0
|
14 |
*
|
sl@0
|
15 |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
sl@0
|
16 |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
sl@0
|
17 |
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
sl@0
|
18 |
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
sl@0
|
19 |
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
sl@0
|
20 |
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
sl@0
|
21 |
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
sl@0
|
22 |
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
sl@0
|
23 |
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
sl@0
|
24 |
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
sl@0
|
25 |
* POSSIBILITY OF SUCH DAMAGE.
|
sl@0
|
26 |
*/
|
sl@0
|
27 |
//Portions Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
|
sl@0
|
28 |
|
sl@0
|
29 |
#ifdef HAVE_CONFIG_H
|
sl@0
|
30 |
#include "config.h"
|
sl@0
|
31 |
#endif
|
sl@0
|
32 |
#include <liboil/liboilfunction.h>
|
sl@0
|
33 |
#include "conv.h"
|
sl@0
|
34 |
|
sl@0
|
35 |
#ifdef HAVE_IEEE754_H
|
sl@0
|
36 |
|
sl@0
|
37 |
#include <ieee754.h>
|
sl@0
|
38 |
|
sl@0
|
39 |
static void conv_f32_u8_bitstuff(float *dst, int dest_stride, const uint8_t *src,
|
sl@0
|
40 |
int src_stride, int n)
|
sl@0
|
41 |
{
|
sl@0
|
42 |
const float offset = -65536;
|
sl@0
|
43 |
union ieee754_float id;
|
sl@0
|
44 |
int i;
|
sl@0
|
45 |
|
sl@0
|
46 |
id.f = 0x1ffff;
|
sl@0
|
47 |
for(i=0;i<n;i++){
|
sl@0
|
48 |
id.ieee.mantissa = (*src<<7);
|
sl@0
|
49 |
*dst = id.f + offset;
|
sl@0
|
50 |
OIL_INCREMENT(dst, dest_stride);
|
sl@0
|
51 |
OIL_INCREMENT(src, src_stride);
|
sl@0
|
52 |
}
|
sl@0
|
53 |
}
|
sl@0
|
54 |
OIL_DEFINE_IMPL(conv_f32_u8_bitstuff, conv_f32_u8);
|
sl@0
|
55 |
|
sl@0
|
56 |
static void conv_f32_s8_bitstuff(float *dst, int dest_stride, const int8_t *src,
|
sl@0
|
57 |
int src_stride, int n)
|
sl@0
|
58 |
{
|
sl@0
|
59 |
const float offset = -384;
|
sl@0
|
60 |
union ieee754_float id;
|
sl@0
|
61 |
int i;
|
sl@0
|
62 |
|
sl@0
|
63 |
id.f = 0x1ff;
|
sl@0
|
64 |
for(i=0;i<n;i++){
|
sl@0
|
65 |
id.ieee.mantissa = ((*src^0x80)<<15);
|
sl@0
|
66 |
*dst = id.f + offset;
|
sl@0
|
67 |
OIL_INCREMENT(dst, dest_stride);
|
sl@0
|
68 |
OIL_INCREMENT(src, src_stride);
|
sl@0
|
69 |
}
|
sl@0
|
70 |
}
|
sl@0
|
71 |
OIL_DEFINE_IMPL(conv_f32_s8_bitstuff, conv_f32_s8);
|
sl@0
|
72 |
|
sl@0
|
73 |
static void conv_f32_u16_bitstuff(float *dst, int dest_stride, const uint16_t *src,
|
sl@0
|
74 |
int src_stride, int n)
|
sl@0
|
75 |
{
|
sl@0
|
76 |
const float offset = -65536;
|
sl@0
|
77 |
union ieee754_float id;
|
sl@0
|
78 |
int i;
|
sl@0
|
79 |
|
sl@0
|
80 |
id.f = 0x1ffff;
|
sl@0
|
81 |
for(i=0;i<n;i++){
|
sl@0
|
82 |
id.ieee.mantissa = (*src<<7);
|
sl@0
|
83 |
*dst = id.f + offset;
|
sl@0
|
84 |
OIL_INCREMENT(dst, dest_stride);
|
sl@0
|
85 |
OIL_INCREMENT(src, src_stride);
|
sl@0
|
86 |
}
|
sl@0
|
87 |
}
|
sl@0
|
88 |
OIL_DEFINE_IMPL(conv_f32_u16_bitstuff, conv_f32_u16);
|
sl@0
|
89 |
|
sl@0
|
90 |
#ifdef ENABLE_BROKEN_IMPLS
|
sl@0
|
91 |
/* This is intermittently broken on powerpc for unknown reasons */
|
sl@0
|
92 |
static void conv_f32_s16_bitstuff(float *dst, int dest_stride, const int16_t *src,
|
sl@0
|
93 |
int src_stride, int n)
|
sl@0
|
94 |
{
|
sl@0
|
95 |
const float offset = -98304;
|
sl@0
|
96 |
union ieee754_float id;
|
sl@0
|
97 |
int i;
|
sl@0
|
98 |
|
sl@0
|
99 |
id.f = 0x1ffff;
|
sl@0
|
100 |
for(i=0;i<n;i++){
|
sl@0
|
101 |
id.ieee.mantissa = ((*src^0x8000)<<7);
|
sl@0
|
102 |
*dst = id.f + offset;
|
sl@0
|
103 |
OIL_INCREMENT(dst, dest_stride);
|
sl@0
|
104 |
OIL_INCREMENT(src, src_stride);
|
sl@0
|
105 |
}
|
sl@0
|
106 |
}
|
sl@0
|
107 |
OIL_DEFINE_IMPL(conv_f32_s16_bitstuff, conv_f32_s16);
|
sl@0
|
108 |
#endif
|
sl@0
|
109 |
|
sl@0
|
110 |
|
sl@0
|
111 |
#define signbit_S32(x) (((uint32_t)(x))>>31)
|
sl@0
|
112 |
|
sl@0
|
113 |
#if 0
|
sl@0
|
114 |
/* broken */
|
sl@0
|
115 |
/* This implementation is slightly inaccurate */
|
sl@0
|
116 |
static void conv_s16_f32_bitstuff(int16_t *dst, int dest_stride, const float *src,
|
sl@0
|
117 |
int src_stride, int n)
|
sl@0
|
118 |
{
|
sl@0
|
119 |
const float offset = 98304.5;
|
sl@0
|
120 |
union ieee754_double id;
|
sl@0
|
121 |
int i;
|
sl@0
|
122 |
int16_t d;
|
sl@0
|
123 |
|
sl@0
|
124 |
for(i=0;i<n;i++){
|
sl@0
|
125 |
id.d = offset + *src;
|
sl@0
|
126 |
d = 0x8000 | (id.ieee.mantissa0 >> 4);
|
sl@0
|
127 |
d += (-32768-d)*signbit_S32(id.ieee.exponent-1039);
|
sl@0
|
128 |
d += (32767-d)*signbit_S32(1039-id.ieee.exponent);
|
sl@0
|
129 |
*dst = d;
|
sl@0
|
130 |
OIL_INCREMENT(dst, dest_stride);
|
sl@0
|
131 |
OIL_INCREMENT(src, src_stride);
|
sl@0
|
132 |
}
|
sl@0
|
133 |
}
|
sl@0
|
134 |
OIL_DEFINE_IMPL(conv_s16_f32_bitstuff, conv_s16_f32);
|
sl@0
|
135 |
#endif
|
sl@0
|
136 |
|
sl@0
|
137 |
|
sl@0
|
138 |
#if 0
|
sl@0
|
139 |
static void conv_f64_u8_bitstuff(float *dst, int dest_stride, const uint8_t *src,
|
sl@0
|
140 |
int src_stride, int n)
|
sl@0
|
141 |
{
|
sl@0
|
142 |
const float offset = -65536;
|
sl@0
|
143 |
union ieee754_float id;
|
sl@0
|
144 |
int i;
|
sl@0
|
145 |
|
sl@0
|
146 |
id.f = 0x1ffff;
|
sl@0
|
147 |
for(i=0;i<n;i++){
|
sl@0
|
148 |
id.ieee.mantissa = (*src<<7);
|
sl@0
|
149 |
*dst = id.f + offset;
|
sl@0
|
150 |
OIL_INCREMENT(dst, dest_stride);
|
sl@0
|
151 |
OIL_INCREMENT(src, src_stride);
|
sl@0
|
152 |
}
|
sl@0
|
153 |
}
|
sl@0
|
154 |
OIL_DEFINE_IMPL(conv_f64_u8_bitstuff, conv_f64_u8);
|
sl@0
|
155 |
|
sl@0
|
156 |
static void conv_f64_s8_bitstuff(float *dst, int dest_stride, const int8_t *src,
|
sl@0
|
157 |
int src_stride, int n)
|
sl@0
|
158 |
{
|
sl@0
|
159 |
const float offset = -384;
|
sl@0
|
160 |
union ieee754_float id;
|
sl@0
|
161 |
int i;
|
sl@0
|
162 |
|
sl@0
|
163 |
id.f = 0x1ff;
|
sl@0
|
164 |
for(i=0;i<n;i++){
|
sl@0
|
165 |
id.ieee.mantissa = ((*src^0x80)<<15);
|
sl@0
|
166 |
*dst = id.f + offset;
|
sl@0
|
167 |
OIL_INCREMENT(dst, dest_stride);
|
sl@0
|
168 |
OIL_INCREMENT(src, src_stride);
|
sl@0
|
169 |
}
|
sl@0
|
170 |
}
|
sl@0
|
171 |
OIL_DEFINE_IMPL(conv_f64_s8_bitstuff, conv_f64_s8);
|
sl@0
|
172 |
|
sl@0
|
173 |
static void conv_f64_u16_bitstuff(float *dst, int dest_stride, const uint16_t *src,
|
sl@0
|
174 |
int src_stride, int n)
|
sl@0
|
175 |
{
|
sl@0
|
176 |
const float offset = -65536;
|
sl@0
|
177 |
union ieee754_float id;
|
sl@0
|
178 |
int i;
|
sl@0
|
179 |
|
sl@0
|
180 |
id.f = 0x1ffff;
|
sl@0
|
181 |
for(i=0;i<n;i++){
|
sl@0
|
182 |
id.ieee.mantissa = (*src<<7);
|
sl@0
|
183 |
*dst = id.f + offset;
|
sl@0
|
184 |
OIL_INCREMENT(dst, dest_stride);
|
sl@0
|
185 |
OIL_INCREMENT(src, src_stride);
|
sl@0
|
186 |
}
|
sl@0
|
187 |
}
|
sl@0
|
188 |
OIL_DEFINE_IMPL(conv_f64_u16_bitstuff, conv_f64_u16);
|
sl@0
|
189 |
|
sl@0
|
190 |
static void conv_f64_s16_bitstuff(float *dst, int dest_stride, const int16_t *src,
|
sl@0
|
191 |
int src_stride, int n)
|
sl@0
|
192 |
{
|
sl@0
|
193 |
const float offset = -98304;
|
sl@0
|
194 |
union ieee754_float id;
|
sl@0
|
195 |
int i;
|
sl@0
|
196 |
|
sl@0
|
197 |
id.f = 0x1ffff;
|
sl@0
|
198 |
for(i=0;i<n;i++){
|
sl@0
|
199 |
id.ieee.mantissa = ((*src^0x8000)<<7);
|
sl@0
|
200 |
*dst = id.f + offset;
|
sl@0
|
201 |
OIL_INCREMENT(dst, dest_stride);
|
sl@0
|
202 |
OIL_INCREMENT(src, src_stride);
|
sl@0
|
203 |
}
|
sl@0
|
204 |
}
|
sl@0
|
205 |
OIL_DEFINE_IMPL(conv_f64_s16_bitstuff, conv_f64_s16);
|
sl@0
|
206 |
#endif
|
sl@0
|
207 |
|
sl@0
|
208 |
#if 0
|
sl@0
|
209 |
/* broken */
|
sl@0
|
210 |
/* This implementation is slightly inaccurate */
|
sl@0
|
211 |
static void conv_s16_f64_bitstuff(int16_t *dst, int dest_stride, const float *src,
|
sl@0
|
212 |
int src_stride, int n)
|
sl@0
|
213 |
{
|
sl@0
|
214 |
const float offset = 98304.5;
|
sl@0
|
215 |
union ieee754_double id;
|
sl@0
|
216 |
int i;
|
sl@0
|
217 |
int16_t d;
|
sl@0
|
218 |
|
sl@0
|
219 |
for(i=0;i<n;i++){
|
sl@0
|
220 |
id.d = offset + *src;
|
sl@0
|
221 |
d = 0x8000 ^ (id.ieee.mantissa0 >> 4);
|
sl@0
|
222 |
d += (-32768-d)*signbit_S32(id.ieee.exponent-1039);
|
sl@0
|
223 |
d += (32767-d)*signbit_S32(1039-id.ieee.exponent);
|
sl@0
|
224 |
#if 0
|
sl@0
|
225 |
/* for clipping */
|
sl@0
|
226 |
if (id.ieee.exponent < 1039) {
|
sl@0
|
227 |
d = -32768;
|
sl@0
|
228 |
}
|
sl@0
|
229 |
if (id.ieee.exponent > 1039) {
|
sl@0
|
230 |
d = 32767;
|
sl@0
|
231 |
}
|
sl@0
|
232 |
#endif
|
sl@0
|
233 |
*dst = d;
|
sl@0
|
234 |
OIL_INCREMENT (dst, dest_stride);
|
sl@0
|
235 |
OIL_INCREMENT (src, src_stride);
|
sl@0
|
236 |
}
|
sl@0
|
237 |
}
|
sl@0
|
238 |
OIL_DEFINE_IMPL(conv_s16_f64_bitstuff, conv_s16_f64);
|
sl@0
|
239 |
#endif
|
sl@0
|
240 |
|
sl@0
|
241 |
|
sl@0
|
242 |
|
sl@0
|
243 |
|
sl@0
|
244 |
|
sl@0
|
245 |
#ifdef __SYMBIAN32__
|
sl@0
|
246 |
|
sl@0
|
247 |
OilFunctionImpl* __oil_function_impl_conv_f32_u8_bitstuff() {
|
sl@0
|
248 |
return &_oil_function_impl_conv_f32_u8_bitstuff;
|
sl@0
|
249 |
}
|
sl@0
|
250 |
#endif
|
sl@0
|
251 |
|
sl@0
|
252 |
#ifdef __SYMBIAN32__
|
sl@0
|
253 |
|
sl@0
|
254 |
OilFunctionImpl* __oil_function_impl_conv_f32_s8_bitstuff() {
|
sl@0
|
255 |
return &_oil_function_impl_conv_f32_s8_bitstuff;
|
sl@0
|
256 |
}
|
sl@0
|
257 |
#endif
|
sl@0
|
258 |
|
sl@0
|
259 |
#ifdef __SYMBIAN32__
|
sl@0
|
260 |
|
sl@0
|
261 |
OilFunctionImpl* __oil_function_impl_conv_f32_u16_bitstuff() {
|
sl@0
|
262 |
return &_oil_function_impl_conv_f32_u16_bitstuff;
|
sl@0
|
263 |
}
|
sl@0
|
264 |
#endif
|
sl@0
|
265 |
|
sl@0
|
266 |
#ifdef __SYMBIAN32__
|
sl@0
|
267 |
|
sl@0
|
268 |
OilFunctionImpl* __oil_function_impl_conv_f32_s16_bitstuff() {
|
sl@0
|
269 |
return &_oil_function_impl_conv_f32_s16_bitstuff;
|
sl@0
|
270 |
}
|
sl@0
|
271 |
#endif
|
sl@0
|
272 |
|
sl@0
|
273 |
#ifdef __SYMBIAN32__
|
sl@0
|
274 |
|
sl@0
|
275 |
OilFunctionImpl* __oil_function_impl_conv_s16_f32_bitstuff() {
|
sl@0
|
276 |
return &_oil_function_impl_conv_s16_f32_bitstuff;
|
sl@0
|
277 |
}
|
sl@0
|
278 |
#endif
|
sl@0
|
279 |
|
sl@0
|
280 |
#ifdef __SYMBIAN32__
|
sl@0
|
281 |
|
sl@0
|
282 |
OilFunctionImpl* __oil_function_impl_conv_f64_u8_bitstuff() {
|
sl@0
|
283 |
return &_oil_function_impl_conv_f64_u8_bitstuff;
|
sl@0
|
284 |
}
|
sl@0
|
285 |
#endif
|
sl@0
|
286 |
|
sl@0
|
287 |
#ifdef __SYMBIAN32__
|
sl@0
|
288 |
|
sl@0
|
289 |
OilFunctionImpl* __oil_function_impl_conv_f64_s8_bitstuff() {
|
sl@0
|
290 |
return &_oil_function_impl_conv_f64_s8_bitstuff;
|
sl@0
|
291 |
}
|
sl@0
|
292 |
#endif
|
sl@0
|
293 |
|
sl@0
|
294 |
#ifdef __SYMBIAN32__
|
sl@0
|
295 |
|
sl@0
|
296 |
OilFunctionImpl* __oil_function_impl_conv_f64_u16_bitstuff() {
|
sl@0
|
297 |
return &_oil_function_impl_conv_f64_u16_bitstuff;
|
sl@0
|
298 |
}
|
sl@0
|
299 |
#endif
|
sl@0
|
300 |
|
sl@0
|
301 |
#ifdef __SYMBIAN32__
|
sl@0
|
302 |
|
sl@0
|
303 |
OilFunctionImpl* __oil_function_impl_conv_f64_s16_bitstuff() {
|
sl@0
|
304 |
return &_oil_function_impl_conv_f64_s16_bitstuff;
|
sl@0
|
305 |
}
|
sl@0
|
306 |
#endif
|
sl@0
|
307 |
|
sl@0
|
308 |
#ifdef __SYMBIAN32__
|
sl@0
|
309 |
|
sl@0
|
310 |
OilFunctionImpl* __oil_function_impl_conv_s16_f64_bitstuff() {
|
sl@0
|
311 |
return &_oil_function_impl_conv_s16_f64_bitstuff;
|
sl@0
|
312 |
}
|
sl@0
|
313 |
#endif
|
sl@0
|
314 |
|
sl@0
|
315 |
#endif
|