1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericopenlibs/liboil/src/c/swab_c.c Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,263 @@
1.4 +/*
1.5 + * LIBOIL - Library of Optimized Inner Loops
1.6 + * Copyright (c) 2005 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 +
1.36 +#include <liboil/liboil.h>
1.37 +#include <liboil/liboilfunction.h>
1.38 +#include <liboil/liboilclasses.h>
1.39 +
1.40 +#ifdef HAVE_UNISTD_H
1.41 +#include <unistd.h>
1.42 +#endif
1.43 +#include <string.h>
1.44 +
1.45 +
1.46 +static void
1.47 +swab_u16_libc (uint16_t *d, const uint16_t *s, int n)
1.48 +{
1.49 + swab ((void *)s, (void *)d, n*2);
1.50 +}
1.51 +OIL_DEFINE_IMPL (swab_u16_libc, swab_u16);
1.52 +
1.53 +static void
1.54 +swab_u16_ptr (uint16_t *d, const uint16_t *s, int n)
1.55 +{
1.56 + int i;
1.57 +
1.58 + for(i=0;i<n;i++){
1.59 + *d++ = (*s<<8) | (*s>>8);
1.60 + s++;
1.61 + }
1.62 +}
1.63 +OIL_DEFINE_IMPL (swab_u16_ptr, swab_u16);
1.64 +
1.65 +static void
1.66 +swab_u32_ptr (uint32_t *d, const uint32_t *s, int n)
1.67 +{
1.68 + int i;
1.69 +
1.70 + for(i=0;i<n;i++){
1.71 + *d++ = (*s<<24) | ((*s&0x0000ff00)<<8) |
1.72 + ((*s&0x00ff0000)>>8) | (*s>>24);
1.73 + s++;
1.74 + }
1.75 +}
1.76 +OIL_DEFINE_IMPL (swab_u32_ptr, swab_u32);
1.77 +
1.78 +static void
1.79 +swab_u16_unroll2 (uint16_t *d, const uint16_t *s, int n)
1.80 +{
1.81 + int i;
1.82 +
1.83 + if (n&1) {
1.84 + *d++ = (*s<<8) | (*s>>8);
1.85 + s++;
1.86 + }
1.87 + n>>=1;
1.88 + for(i=0;i<n;i++){
1.89 + *d++ = (*s<<8) | (*s>>8);
1.90 + s++;
1.91 + *d++ = (*s<<8) | (*s>>8);
1.92 + s++;
1.93 + }
1.94 +}
1.95 +OIL_DEFINE_IMPL (swab_u16_unroll2, swab_u16);
1.96 +
1.97 +static void
1.98 +swab_u16_unroll4 (uint16_t *d, const uint16_t *s, int n)
1.99 +{
1.100 + int i;
1.101 +
1.102 + while (n&3) {
1.103 + *d++ = (*s<<8) | (*s>>8);
1.104 + s++;
1.105 + n--;
1.106 + }
1.107 + n>>=2;
1.108 + for(i=0;i<n;i++){
1.109 + *d++ = (*s<<8) | (*s>>8);
1.110 + s++;
1.111 + *d++ = (*s<<8) | (*s>>8);
1.112 + s++;
1.113 + *d++ = (*s<<8) | (*s>>8);
1.114 + s++;
1.115 + *d++ = (*s<<8) | (*s>>8);
1.116 + s++;
1.117 + }
1.118 +}
1.119 +OIL_DEFINE_IMPL (swab_u16_unroll4, swab_u16);
1.120 +
1.121 +static void
1.122 +swab_u32_unroll2 (uint32_t *d, const uint32_t *s, int n)
1.123 +{
1.124 + int i;
1.125 +
1.126 + if (n&1) {
1.127 + *d++ = (*s<<24) | ((*s&0x0000ff00)<<8) |
1.128 + ((*s&0x00ff0000)>>8) | (*s>>24);
1.129 + s++;
1.130 + }
1.131 + n>>=1;
1.132 + for(i=0;i<n;i++){
1.133 + *d++ = (*s<<24) | ((*s&0x0000ff00)<<8) |
1.134 + ((*s&0x00ff0000)>>8) | (*s>>24);
1.135 + s++;
1.136 + *d++ = (*s<<24) | ((*s&0x0000ff00)<<8) |
1.137 + ((*s&0x00ff0000)>>8) | (*s>>24);
1.138 + s++;
1.139 + }
1.140 +}
1.141 +OIL_DEFINE_IMPL (swab_u32_unroll2, swab_u32);
1.142 +
1.143 +
1.144 +static void
1.145 +swab_u16_char (uint16_t *d, const uint16_t *s, int n)
1.146 +{
1.147 + int i;
1.148 + uint8_t *bd = (uint8_t *)d;
1.149 + uint8_t *bs = (uint8_t *)s;
1.150 + int x;
1.151 +
1.152 + for(i=0;i<n;i++){
1.153 + x = bs[0];
1.154 + bd[0] = bs[1];
1.155 + bd[1] = x;
1.156 + bd += 2;
1.157 + bs += 2;
1.158 + }
1.159 +}
1.160 +OIL_DEFINE_IMPL (swab_u16_char, swab_u16);
1.161 +
1.162 +static void
1.163 +swab_u32_char (uint32_t *d, const uint32_t *s, int n)
1.164 +{
1.165 + int i;
1.166 +
1.167 + for(i=0;i<n;i++){
1.168 + *d++ = (*s<<24) | ((*s&0x0000ff00)<<8) |
1.169 + ((*s&0x00ff0000)>>8) | (*s>>24);
1.170 + s++;
1.171 + }
1.172 +}
1.173 +OIL_DEFINE_IMPL (swab_u32_char, swab_u32);
1.174 +
1.175 +
1.176 +
1.177 +
1.178 +
1.179 +
1.180 +
1.181 +#if 0
1.182 +static void
1.183 +swab_u32_asm (uint32_t *d, uint32_t *s, int n)
1.184 +{
1.185 + asm volatile ("\n"
1.186 + "1:\n"
1.187 + " mov 0(%1), %%eax\n"
1.188 + " bswap %%eax\n"
1.189 + " mov %%eax, 0(%0)\n"
1.190 + " add $4, %0\n"
1.191 + " add $4, %1\n"
1.192 + " decl %2\n"
1.193 + " jne 1b\n"
1.194 + : "+r" (d), "+r" (s), "+r" (n)
1.195 + :
1.196 + : "eax");
1.197 +}
1.198 +OIL_DEFINE_IMPL (swab_u32_asm, swab_u32);
1.199 +#endif
1.200 +
1.201 +
1.202 +
1.203 +#ifdef __SYMBIAN32__
1.204 +
1.205 +OilFunctionImpl* __oil_function_impl_swab_u16_libc() {
1.206 + return &_oil_function_impl_swab_u16_libc;
1.207 +}
1.208 +#endif
1.209 +
1.210 +#ifdef __SYMBIAN32__
1.211 +
1.212 +OilFunctionImpl* __oil_function_impl_swab_u16_ptr() {
1.213 + return &_oil_function_impl_swab_u16_ptr;
1.214 +}
1.215 +#endif
1.216 +
1.217 +#ifdef __SYMBIAN32__
1.218 +
1.219 +OilFunctionImpl* __oil_function_impl_swab_u32_ptr() {
1.220 + return &_oil_function_impl_swab_u32_ptr;
1.221 +}
1.222 +#endif
1.223 +
1.224 +#ifdef __SYMBIAN32__
1.225 +
1.226 +OilFunctionImpl* __oil_function_impl_swab_u16_unroll2() {
1.227 + return &_oil_function_impl_swab_u16_unroll2;
1.228 +}
1.229 +#endif
1.230 +
1.231 +#ifdef __SYMBIAN32__
1.232 +
1.233 +OilFunctionImpl* __oil_function_impl_swab_u16_unroll4() {
1.234 + return &_oil_function_impl_swab_u16_unroll4;
1.235 +}
1.236 +#endif
1.237 +
1.238 +#ifdef __SYMBIAN32__
1.239 +
1.240 +OilFunctionImpl* __oil_function_impl_swab_u32_unroll2() {
1.241 + return &_oil_function_impl_swab_u32_unroll2;
1.242 +}
1.243 +#endif
1.244 +
1.245 +#ifdef __SYMBIAN32__
1.246 +
1.247 +OilFunctionImpl* __oil_function_impl_swab_u16_char() {
1.248 + return &_oil_function_impl_swab_u16_char;
1.249 +}
1.250 +#endif
1.251 +
1.252 +#ifdef __SYMBIAN32__
1.253 +
1.254 +OilFunctionImpl* __oil_function_impl_swab_u32_char() {
1.255 + return &_oil_function_impl_swab_u32_char;
1.256 +}
1.257 +#endif
1.258 +
1.259 +#if 0
1.260 +#ifdef __SYMBIAN32__
1.261 +
1.262 +OilFunctionImpl* __oil_function_impl_swab_u32_asm() {
1.263 + return &_oil_function_impl_swab_u32_asm;
1.264 +}
1.265 +#endif
1.266 +#endif