os/ossrv/genericopenlibs/liboil/src/copy/copy.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) 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 
    33 #include <string.h>
    34 
    35 #include <liboil/liboilfunction.h>
    36 
    37 OIL_DECLARE_CLASS (copy_u8);
    38 
    39 static void
    40 copy_u8_libc (uint8_t *dest, const uint8_t *src, int n)
    41 {
    42   memcpy (dest, src, n);
    43 }
    44 OIL_DEFINE_IMPL (copy_u8_libc, copy_u8);
    45 
    46 static void
    47 copy_u8_ptr (uint8_t *dest, const uint8_t *src, int n)
    48 {
    49   while(n--) {
    50     *dest++ = *src++;
    51   }
    52 }
    53 OIL_DEFINE_IMPL (copy_u8_ptr, copy_u8);
    54 
    55 #ifdef HAVE_UNALIGNED_ACCESS
    56 static void
    57 copy_u8_ints (uint8_t *dest, const uint8_t *src, int n)
    58 {
    59   int i;
    60   for(i=0;i<(n&3);i++){
    61     *dest++ = *src++;
    62   }
    63   n >>= 2;
    64   for(i=0;i<n;i++){
    65     *(uint32_t *)dest = *(uint32_t *)src;
    66     dest += 4;
    67     src += 4;
    68   }
    69 }
    70 OIL_DEFINE_IMPL (copy_u8_ints, copy_u8);
    71 #endif
    72 
    73 #ifdef HAVE_UNALIGNED_ACCESS
    74 /* Submitted by Adam Moss */
    75 static void
    76 copy_u8_llints (uint8_t *dest, const uint8_t *src, int n)
    77 {
    78   int i;
    79   for(i=0;i<(n&7);i++){
    80     *dest++ = *src++;
    81   }
    82   n >>= 3;
    83   for(i=0;i<n;i++){
    84     *(uint64_t *)dest = *(uint64_t *)src;
    85     dest += 8;
    86     src += 8;
    87   }
    88 }
    89 OIL_DEFINE_IMPL (copy_u8_llints, copy_u8);
    90 #endif
    91 
    92 #ifdef HAVE_UNALIGNED_ACCESS
    93 /* Submitted by Adam Moss */
    94 static void
    95 copy_u8_llints_duff (uint8_t *dest, const uint8_t *src, int n)
    96 {
    97   switch(n&7) {
    98   case 7: *dest++ = *src++;
    99   case 6: *dest++ = *src++;
   100   case 5: *dest++ = *src++;
   101   case 4: *dest++ = *src++;
   102   case 3: *dest++ = *src++;
   103   case 2: *dest++ = *src++;
   104   case 1: *dest++ = *src++;
   105   default: ;
   106   }
   107   n >>= 3;
   108   while (n) {
   109     switch (n & 15) {
   110     default:
   111     case 0: *(uint64_t *)dest = *(uint64_t *)src; dest += 8; src += 8;
   112     case 15: *(uint64_t *)dest = *(uint64_t *)src; dest += 8; src += 8;
   113     case 14: *(uint64_t *)dest = *(uint64_t *)src; dest += 8; src += 8;
   114     case 13: *(uint64_t *)dest = *(uint64_t *)src; dest += 8; src += 8;
   115     case 12: *(uint64_t *)dest = *(uint64_t *)src; dest += 8; src += 8;
   116     case 11: *(uint64_t *)dest = *(uint64_t *)src; dest += 8; src += 8;
   117     case 10: *(uint64_t *)dest = *(uint64_t *)src; dest += 8; src += 8;
   118     case 9: *(uint64_t *)dest = *(uint64_t *)src; dest += 8; src += 8;
   119     case 8: *(uint64_t *)dest = *(uint64_t *)src; dest += 8; src += 8;
   120     case 7: *(uint64_t *)dest = *(uint64_t *)src; dest += 8; src += 8;
   121     case 6: *(uint64_t *)dest = *(uint64_t *)src; dest += 8; src += 8;
   122     case 5: *(uint64_t *)dest = *(uint64_t *)src; dest += 8; src += 8;
   123     case 4: *(uint64_t *)dest = *(uint64_t *)src; dest += 8; src += 8;
   124     case 3: *(uint64_t *)dest = *(uint64_t *)src; dest += 8; src += 8;
   125     case 2: *(uint64_t *)dest = *(uint64_t *)src; dest += 8; src += 8;
   126     case 1: *(uint64_t *)dest = *(uint64_t *)src; dest += 8; src += 8;
   127     }
   128     n = (n - 1) & ~(int)15;
   129   }
   130 }
   131 OIL_DEFINE_IMPL (copy_u8_llints_duff, copy_u8);
   132 #endif
   133 
   134 
   135 
   136 #ifdef	__SYMBIAN32__
   137  
   138 OilFunctionImpl* __oil_function_impl_copy_u8_libc() {
   139 		return &_oil_function_impl_copy_u8_libc;
   140 }
   141 #endif
   142 
   143 #ifdef	__SYMBIAN32__
   144  
   145 OilFunctionImpl* __oil_function_impl_copy_u8_ptr() {
   146 		return &_oil_function_impl_copy_u8_ptr;
   147 }
   148 #endif
   149 
   150 #ifdef HAVE_UNALIGNED_ACCESS
   151 #ifdef	__SYMBIAN32__
   152  
   153 OilFunctionImpl* __oil_function_impl_copy_u8_ints() {
   154 		return &_oil_function_impl_copy_u8_ints;
   155 }
   156 #endif
   157 #endif
   158 
   159 #ifdef HAVE_UNALIGNED_ACCESS
   160 #ifdef	__SYMBIAN32__
   161  
   162 OilFunctionImpl* __oil_function_impl_copy_u8_llints() {
   163 		return &_oil_function_impl_copy_u8_llints;
   164 }
   165 #endif
   166 #endif
   167 
   168 #ifdef HAVE_UNALIGNED_ACCESS
   169 #ifdef	__SYMBIAN32__
   170  
   171 OilFunctionImpl* __oil_function_impl_copy_u8_llints_duff() {
   172 		return &_oil_function_impl_copy_u8_llints_duff;
   173 }
   174 #endif
   175 #endif