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