os/ossrv/genericopenlibs/liboil/src/conv/conv_bitstuff.c
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/genericopenlibs/liboil/src/conv/conv_bitstuff.c	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,315 @@
     1.4 +/*
     1.5 + * LIBOIL - Library of Optimized Inner Loops
     1.6 + * Copyright (c) 2003,2004 David A. Schleef <ds@schleef.org>
     1.7 + * All rights reserved.
     1.8 + *
     1.9 + * Redistribution and use in source and binary forms, with or without
    1.10 + * modification, are permitted provided that the following conditions
    1.11 + * are met:
    1.12 + * 1. Redistributions of source code must retain the above copyright
    1.13 + *    notice, this list of conditions and the following disclaimer.
    1.14 + * 2. Redistributions in binary form must reproduce the above copyright
    1.15 + *    notice, this list of conditions and the following disclaimer in the
    1.16 + *    documentation and/or other materials provided with the distribution.
    1.17 + * 
    1.18 + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
    1.19 + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
    1.20 + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    1.21 + * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
    1.22 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    1.23 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
    1.24 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    1.25 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
    1.26 + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
    1.27 + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    1.28 + * POSSIBILITY OF SUCH DAMAGE.
    1.29 + */
    1.30 +//Portions Copyright (c)  2008-2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. 
    1.31 +
    1.32 +#ifdef HAVE_CONFIG_H
    1.33 +#include "config.h"
    1.34 +#endif
    1.35 +#include <liboil/liboilfunction.h>
    1.36 +#include "conv.h"
    1.37 +
    1.38 +#ifdef HAVE_IEEE754_H
    1.39 +
    1.40 +#include <ieee754.h>   
    1.41 +
    1.42 +static void conv_f32_u8_bitstuff(float *dst, int dest_stride, const uint8_t *src,
    1.43 +	int src_stride, int n)
    1.44 +{
    1.45 +	const float offset = -65536;
    1.46 +	union ieee754_float id;
    1.47 +	int i;
    1.48 +
    1.49 +	id.f = 0x1ffff;
    1.50 +	for(i=0;i<n;i++){
    1.51 +		id.ieee.mantissa = (*src<<7);
    1.52 +		*dst = id.f + offset;
    1.53 +		OIL_INCREMENT(dst, dest_stride);
    1.54 +		OIL_INCREMENT(src, src_stride);
    1.55 +	}
    1.56 +}
    1.57 +OIL_DEFINE_IMPL(conv_f32_u8_bitstuff, conv_f32_u8);
    1.58 +
    1.59 +static void conv_f32_s8_bitstuff(float *dst, int dest_stride, const int8_t *src,
    1.60 +	int src_stride, int n)
    1.61 +{
    1.62 +	const float offset = -384;
    1.63 +	union ieee754_float id;
    1.64 +	int i;
    1.65 +
    1.66 +	id.f = 0x1ff;
    1.67 +	for(i=0;i<n;i++){
    1.68 +		id.ieee.mantissa = ((*src^0x80)<<15);
    1.69 +		*dst = id.f + offset;
    1.70 +		OIL_INCREMENT(dst, dest_stride);
    1.71 +		OIL_INCREMENT(src, src_stride);
    1.72 +	}
    1.73 +}
    1.74 +OIL_DEFINE_IMPL(conv_f32_s8_bitstuff, conv_f32_s8);
    1.75 +
    1.76 +static void conv_f32_u16_bitstuff(float *dst, int dest_stride, const uint16_t *src,
    1.77 +	int src_stride, int n)
    1.78 +{
    1.79 +	const float offset = -65536;
    1.80 +	union ieee754_float id;
    1.81 +	int i;
    1.82 +
    1.83 +	id.f = 0x1ffff;
    1.84 +	for(i=0;i<n;i++){
    1.85 +		id.ieee.mantissa = (*src<<7);
    1.86 +		*dst = id.f + offset;
    1.87 +		OIL_INCREMENT(dst, dest_stride);
    1.88 +		OIL_INCREMENT(src, src_stride);
    1.89 +	}
    1.90 +}
    1.91 +OIL_DEFINE_IMPL(conv_f32_u16_bitstuff, conv_f32_u16);
    1.92 +
    1.93 +#ifdef ENABLE_BROKEN_IMPLS
    1.94 +/* This is intermittently broken on powerpc for unknown reasons */
    1.95 +static void conv_f32_s16_bitstuff(float *dst, int dest_stride, const int16_t *src,
    1.96 +	int src_stride, int n)
    1.97 +{
    1.98 +	const float offset = -98304;
    1.99 +	union ieee754_float id;
   1.100 +	int i;
   1.101 +
   1.102 +	id.f = 0x1ffff;
   1.103 +	for(i=0;i<n;i++){
   1.104 +		id.ieee.mantissa = ((*src^0x8000)<<7);
   1.105 +		*dst = id.f + offset;
   1.106 +		OIL_INCREMENT(dst, dest_stride);
   1.107 +		OIL_INCREMENT(src, src_stride);
   1.108 +	}
   1.109 +}
   1.110 +OIL_DEFINE_IMPL(conv_f32_s16_bitstuff, conv_f32_s16);
   1.111 +#endif
   1.112 +
   1.113 +
   1.114 +#define signbit_S32(x) (((uint32_t)(x))>>31)
   1.115 +
   1.116 +#if 0
   1.117 +/* broken */
   1.118 +/* This implementation is slightly inaccurate */
   1.119 +static void conv_s16_f32_bitstuff(int16_t *dst, int dest_stride, const float *src,
   1.120 +	int src_stride, int n)
   1.121 +{
   1.122 +	const float offset = 98304.5;
   1.123 +	union ieee754_double id;
   1.124 +	int i;
   1.125 +	int16_t d;
   1.126 +
   1.127 +	for(i=0;i<n;i++){
   1.128 +		id.d = offset + *src;
   1.129 +		d = 0x8000 | (id.ieee.mantissa0 >> 4);
   1.130 +		d += (-32768-d)*signbit_S32(id.ieee.exponent-1039);
   1.131 +		d += (32767-d)*signbit_S32(1039-id.ieee.exponent);
   1.132 +		*dst = d;
   1.133 +		OIL_INCREMENT(dst, dest_stride);
   1.134 +		OIL_INCREMENT(src, src_stride);
   1.135 +	}
   1.136 +}
   1.137 +OIL_DEFINE_IMPL(conv_s16_f32_bitstuff, conv_s16_f32);
   1.138 +#endif
   1.139 +
   1.140 +
   1.141 +#if 0
   1.142 +static void conv_f64_u8_bitstuff(float *dst, int dest_stride, const uint8_t *src,
   1.143 +	int src_stride, int n)
   1.144 +{
   1.145 +	const float offset = -65536;
   1.146 +	union ieee754_float id;
   1.147 +	int i;
   1.148 +
   1.149 +	id.f = 0x1ffff;
   1.150 +	for(i=0;i<n;i++){
   1.151 +		id.ieee.mantissa = (*src<<7);
   1.152 +		*dst = id.f + offset;
   1.153 +		OIL_INCREMENT(dst, dest_stride);
   1.154 +		OIL_INCREMENT(src, src_stride);
   1.155 +	}
   1.156 +}
   1.157 +OIL_DEFINE_IMPL(conv_f64_u8_bitstuff, conv_f64_u8);
   1.158 +
   1.159 +static void conv_f64_s8_bitstuff(float *dst, int dest_stride, const int8_t *src,
   1.160 +	int src_stride, int n)
   1.161 +{
   1.162 +	const float offset = -384;
   1.163 +	union ieee754_float id;
   1.164 +	int i;
   1.165 +
   1.166 +	id.f = 0x1ff;
   1.167 +	for(i=0;i<n;i++){
   1.168 +		id.ieee.mantissa = ((*src^0x80)<<15);
   1.169 +		*dst = id.f + offset;
   1.170 +		OIL_INCREMENT(dst, dest_stride);
   1.171 +		OIL_INCREMENT(src, src_stride);
   1.172 +	}
   1.173 +}
   1.174 +OIL_DEFINE_IMPL(conv_f64_s8_bitstuff, conv_f64_s8);
   1.175 +
   1.176 +static void conv_f64_u16_bitstuff(float *dst, int dest_stride, const uint16_t *src,
   1.177 +	int src_stride, int n)
   1.178 +{
   1.179 +	const float offset = -65536;
   1.180 +	union ieee754_float id;
   1.181 +	int i;
   1.182 +
   1.183 +	id.f = 0x1ffff;
   1.184 +	for(i=0;i<n;i++){
   1.185 +		id.ieee.mantissa = (*src<<7);
   1.186 +		*dst = id.f + offset;
   1.187 +		OIL_INCREMENT(dst, dest_stride);
   1.188 +		OIL_INCREMENT(src, src_stride);
   1.189 +	}
   1.190 +}
   1.191 +OIL_DEFINE_IMPL(conv_f64_u16_bitstuff, conv_f64_u16);
   1.192 +
   1.193 +static void conv_f64_s16_bitstuff(float *dst, int dest_stride, const int16_t *src,
   1.194 +	int src_stride, int n)
   1.195 +{
   1.196 +	const float offset = -98304;
   1.197 +	union ieee754_float id;
   1.198 +	int i;
   1.199 +
   1.200 +	id.f = 0x1ffff;
   1.201 +	for(i=0;i<n;i++){
   1.202 +		id.ieee.mantissa = ((*src^0x8000)<<7);
   1.203 +		*dst = id.f + offset;
   1.204 +		OIL_INCREMENT(dst, dest_stride);
   1.205 +		OIL_INCREMENT(src, src_stride);
   1.206 +	}
   1.207 +}
   1.208 +OIL_DEFINE_IMPL(conv_f64_s16_bitstuff, conv_f64_s16);
   1.209 +#endif
   1.210 +
   1.211 +#if 0
   1.212 +/* broken */
   1.213 +/* This implementation is slightly inaccurate */
   1.214 +static void conv_s16_f64_bitstuff(int16_t *dst, int dest_stride, const float *src,
   1.215 +	int src_stride, int n)
   1.216 +{
   1.217 +	const float offset = 98304.5;
   1.218 +	union ieee754_double id;
   1.219 +	int i;
   1.220 +	int16_t d;
   1.221 +
   1.222 +	for(i=0;i<n;i++){
   1.223 +		id.d = offset + *src;
   1.224 +		d = 0x8000 ^ (id.ieee.mantissa0 >> 4);
   1.225 +		d += (-32768-d)*signbit_S32(id.ieee.exponent-1039);
   1.226 +		d += (32767-d)*signbit_S32(1039-id.ieee.exponent);
   1.227 +#if 0
   1.228 +/* for clipping */
   1.229 +		if (id.ieee.exponent < 1039) {
   1.230 +		  d = -32768;
   1.231 +		}
   1.232 +		if (id.ieee.exponent > 1039) {
   1.233 +		  d = 32767;
   1.234 +		}
   1.235 +#endif
   1.236 +		*dst = d;
   1.237 +		OIL_INCREMENT (dst, dest_stride);
   1.238 +		OIL_INCREMENT (src, src_stride);
   1.239 +	}
   1.240 +}
   1.241 +OIL_DEFINE_IMPL(conv_s16_f64_bitstuff, conv_s16_f64);
   1.242 +#endif
   1.243 +
   1.244 +
   1.245 +
   1.246 +
   1.247 +
   1.248 +#ifdef	__SYMBIAN32__
   1.249 + 
   1.250 +OilFunctionImpl* __oil_function_impl_conv_f32_u8_bitstuff() {
   1.251 +		return &_oil_function_impl_conv_f32_u8_bitstuff;
   1.252 +}
   1.253 +#endif
   1.254 +
   1.255 +#ifdef	__SYMBIAN32__
   1.256 + 
   1.257 +OilFunctionImpl* __oil_function_impl_conv_f32_s8_bitstuff() {
   1.258 +		return &_oil_function_impl_conv_f32_s8_bitstuff;
   1.259 +}
   1.260 +#endif
   1.261 +
   1.262 +#ifdef	__SYMBIAN32__
   1.263 + 
   1.264 +OilFunctionImpl* __oil_function_impl_conv_f32_u16_bitstuff() {
   1.265 +		return &_oil_function_impl_conv_f32_u16_bitstuff;
   1.266 +}
   1.267 +#endif
   1.268 +
   1.269 +#ifdef	__SYMBIAN32__
   1.270 + 
   1.271 +OilFunctionImpl* __oil_function_impl_conv_f32_s16_bitstuff() {
   1.272 +		return &_oil_function_impl_conv_f32_s16_bitstuff;
   1.273 +}
   1.274 +#endif
   1.275 +
   1.276 +#ifdef	__SYMBIAN32__
   1.277 + 
   1.278 +OilFunctionImpl* __oil_function_impl_conv_s16_f32_bitstuff() {
   1.279 +		return &_oil_function_impl_conv_s16_f32_bitstuff;
   1.280 +}
   1.281 +#endif
   1.282 +
   1.283 +#ifdef	__SYMBIAN32__
   1.284 + 
   1.285 +OilFunctionImpl* __oil_function_impl_conv_f64_u8_bitstuff() {
   1.286 +		return &_oil_function_impl_conv_f64_u8_bitstuff;
   1.287 +}
   1.288 +#endif
   1.289 +
   1.290 +#ifdef	__SYMBIAN32__
   1.291 + 
   1.292 +OilFunctionImpl* __oil_function_impl_conv_f64_s8_bitstuff() {
   1.293 +		return &_oil_function_impl_conv_f64_s8_bitstuff;
   1.294 +}
   1.295 +#endif
   1.296 +
   1.297 +#ifdef	__SYMBIAN32__
   1.298 + 
   1.299 +OilFunctionImpl* __oil_function_impl_conv_f64_u16_bitstuff() {
   1.300 +		return &_oil_function_impl_conv_f64_u16_bitstuff;
   1.301 +}
   1.302 +#endif
   1.303 +
   1.304 +#ifdef	__SYMBIAN32__
   1.305 + 
   1.306 +OilFunctionImpl* __oil_function_impl_conv_f64_s16_bitstuff() {
   1.307 +		return &_oil_function_impl_conv_f64_s16_bitstuff;
   1.308 +}
   1.309 +#endif
   1.310 +
   1.311 +#ifdef	__SYMBIAN32__
   1.312 + 
   1.313 +OilFunctionImpl* __oil_function_impl_conv_s16_f64_bitstuff() {
   1.314 +		return &_oil_function_impl_conv_s16_f64_bitstuff;
   1.315 +}
   1.316 +#endif
   1.317 +
   1.318 +#endif