os/ossrv/genericopenlibs/liboil/src/c/swab_c.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) 2005 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 
    33 #include <liboil/liboil.h>
    34 #include <liboil/liboilfunction.h>
    35 #include <liboil/liboilclasses.h>
    36 
    37 #ifdef HAVE_UNISTD_H
    38 #include <unistd.h>
    39 #endif
    40 #include <string.h>
    41 
    42 
    43 static void
    44 swab_u16_libc (uint16_t *d, const uint16_t *s, int n)
    45 {
    46   swab ((void *)s, (void *)d, n*2);
    47 }
    48 OIL_DEFINE_IMPL (swab_u16_libc, swab_u16);
    49 
    50 static void
    51 swab_u16_ptr (uint16_t *d, const uint16_t *s, int n)
    52 {
    53   int i;
    54 
    55   for(i=0;i<n;i++){
    56     *d++ = (*s<<8) | (*s>>8);
    57     s++;
    58   }
    59 }
    60 OIL_DEFINE_IMPL (swab_u16_ptr, swab_u16);
    61 
    62 static void
    63 swab_u32_ptr (uint32_t *d, const uint32_t *s, int n)
    64 {
    65   int i;
    66 
    67   for(i=0;i<n;i++){
    68     *d++ = (*s<<24) | ((*s&0x0000ff00)<<8) |
    69       ((*s&0x00ff0000)>>8) | (*s>>24);
    70     s++;
    71   }
    72 }
    73 OIL_DEFINE_IMPL (swab_u32_ptr, swab_u32);
    74 
    75 static void
    76 swab_u16_unroll2 (uint16_t *d, const uint16_t *s, int n)
    77 {
    78   int i;
    79 
    80   if (n&1) {
    81     *d++ = (*s<<8) | (*s>>8);
    82     s++;
    83   }
    84   n>>=1;
    85   for(i=0;i<n;i++){
    86     *d++ = (*s<<8) | (*s>>8);
    87     s++;
    88     *d++ = (*s<<8) | (*s>>8);
    89     s++;
    90   }
    91 }
    92 OIL_DEFINE_IMPL (swab_u16_unroll2, swab_u16);
    93 
    94 static void
    95 swab_u16_unroll4 (uint16_t *d, const uint16_t *s, int n)
    96 {
    97   int i;
    98 
    99   while (n&3) {
   100     *d++ = (*s<<8) | (*s>>8);
   101     s++;
   102     n--;
   103   }
   104   n>>=2;
   105   for(i=0;i<n;i++){
   106     *d++ = (*s<<8) | (*s>>8);
   107     s++;
   108     *d++ = (*s<<8) | (*s>>8);
   109     s++;
   110     *d++ = (*s<<8) | (*s>>8);
   111     s++;
   112     *d++ = (*s<<8) | (*s>>8);
   113     s++;
   114   }
   115 }
   116 OIL_DEFINE_IMPL (swab_u16_unroll4, swab_u16);
   117 
   118 static void
   119 swab_u32_unroll2 (uint32_t *d, const uint32_t *s, int n)
   120 {
   121   int i;
   122 
   123   if (n&1) {
   124     *d++ = (*s<<24) | ((*s&0x0000ff00)<<8) |
   125       ((*s&0x00ff0000)>>8) | (*s>>24);
   126     s++;
   127   }
   128   n>>=1;
   129   for(i=0;i<n;i++){
   130     *d++ = (*s<<24) | ((*s&0x0000ff00)<<8) |
   131       ((*s&0x00ff0000)>>8) | (*s>>24);
   132     s++;
   133     *d++ = (*s<<24) | ((*s&0x0000ff00)<<8) |
   134       ((*s&0x00ff0000)>>8) | (*s>>24);
   135     s++;
   136   }
   137 }
   138 OIL_DEFINE_IMPL (swab_u32_unroll2, swab_u32);
   139 
   140 
   141 static void
   142 swab_u16_char (uint16_t *d, const uint16_t *s, int n)
   143 {
   144   int i;
   145   uint8_t *bd = (uint8_t *)d;
   146   uint8_t *bs = (uint8_t *)s;
   147   int x;
   148 
   149   for(i=0;i<n;i++){
   150     x = bs[0];
   151     bd[0] = bs[1];
   152     bd[1] = x;
   153     bd += 2;
   154     bs += 2;
   155   }
   156 }
   157 OIL_DEFINE_IMPL (swab_u16_char, swab_u16);
   158 
   159 static void
   160 swab_u32_char (uint32_t *d, const uint32_t *s, int n)
   161 {
   162   int i;
   163 
   164   for(i=0;i<n;i++){
   165     *d++ = (*s<<24) | ((*s&0x0000ff00)<<8) |
   166       ((*s&0x00ff0000)>>8) | (*s>>24);
   167     s++;
   168   }
   169 }
   170 OIL_DEFINE_IMPL (swab_u32_char, swab_u32);
   171 
   172 
   173 
   174 
   175 
   176 
   177 
   178 #if 0
   179 static void
   180 swab_u32_asm (uint32_t *d, uint32_t *s, int n)
   181 {
   182   asm volatile ("\n"
   183       "1:\n"
   184       "  mov 0(%1), %%eax\n"
   185       "  bswap %%eax\n"
   186       "  mov %%eax, 0(%0)\n"
   187       "  add $4, %0\n"
   188       "  add $4, %1\n"
   189       "  decl %2\n"
   190       "  jne 1b\n"
   191       : "+r" (d), "+r" (s), "+r" (n)
   192       :
   193       : "eax");
   194 }
   195 OIL_DEFINE_IMPL (swab_u32_asm, swab_u32);
   196 #endif
   197 
   198 
   199 
   200 #ifdef	__SYMBIAN32__
   201  
   202 OilFunctionImpl* __oil_function_impl_swab_u16_libc() {
   203 		return &_oil_function_impl_swab_u16_libc;
   204 }
   205 #endif
   206 
   207 #ifdef	__SYMBIAN32__
   208  
   209 OilFunctionImpl* __oil_function_impl_swab_u16_ptr() {
   210 		return &_oil_function_impl_swab_u16_ptr;
   211 }
   212 #endif
   213 
   214 #ifdef	__SYMBIAN32__
   215  
   216 OilFunctionImpl* __oil_function_impl_swab_u32_ptr() {
   217 		return &_oil_function_impl_swab_u32_ptr;
   218 }
   219 #endif
   220 
   221 #ifdef	__SYMBIAN32__
   222  
   223 OilFunctionImpl* __oil_function_impl_swab_u16_unroll2() {
   224 		return &_oil_function_impl_swab_u16_unroll2;
   225 }
   226 #endif
   227 
   228 #ifdef	__SYMBIAN32__
   229  
   230 OilFunctionImpl* __oil_function_impl_swab_u16_unroll4() {
   231 		return &_oil_function_impl_swab_u16_unroll4;
   232 }
   233 #endif
   234 
   235 #ifdef	__SYMBIAN32__
   236  
   237 OilFunctionImpl* __oil_function_impl_swab_u32_unroll2() {
   238 		return &_oil_function_impl_swab_u32_unroll2;
   239 }
   240 #endif
   241 
   242 #ifdef	__SYMBIAN32__
   243  
   244 OilFunctionImpl* __oil_function_impl_swab_u16_char() {
   245 		return &_oil_function_impl_swab_u16_char;
   246 }
   247 #endif
   248 
   249 #ifdef	__SYMBIAN32__
   250  
   251 OilFunctionImpl* __oil_function_impl_swab_u32_char() {
   252 		return &_oil_function_impl_swab_u32_char;
   253 }
   254 #endif
   255 
   256 #if 0
   257 #ifdef	__SYMBIAN32__
   258  
   259 OilFunctionImpl* __oil_function_impl_swab_u32_asm() {
   260 		return &_oil_function_impl_swab_u32_asm;
   261 }
   262 #endif
   263 #endif