os/ossrv/genericopenlibs/liboil/src/i386/rowcolsad8x8_i386.c
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
/*
sl@0
     2
 * LIBOIL - Library of Optimized Inner Loops
sl@0
     3
 * Copyright (c) 2003,2004 David A. Schleef <ds@schleef.org>
sl@0
     4
 * All rights reserved.
sl@0
     5
 *
sl@0
     6
 * Redistribution and use in source and binary forms, with or without
sl@0
     7
 * modification, are permitted provided that the following conditions
sl@0
     8
 * are met:
sl@0
     9
 * 1. Redistributions of source code must retain the above copyright
sl@0
    10
 *    notice, this list of conditions and the following disclaimer.
sl@0
    11
 * 2. Redistributions in binary form must reproduce the above copyright
sl@0
    12
 *    notice, this list of conditions and the following disclaimer in the
sl@0
    13
 *    documentation and/or other materials provided with the distribution.
sl@0
    14
 * 
sl@0
    15
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
sl@0
    16
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
sl@0
    17
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
sl@0
    18
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
sl@0
    19
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
sl@0
    20
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
sl@0
    21
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
sl@0
    22
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
sl@0
    23
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
sl@0
    24
 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
sl@0
    25
 * POSSIBILITY OF SUCH DAMAGE.
sl@0
    26
 */
sl@0
    27
//Portions Copyright (c)  2008-2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. 
sl@0
    28
sl@0
    29
#ifdef HAVE_CONFIG_H
sl@0
    30
#include "config.h"
sl@0
    31
#endif
sl@0
    32
sl@0
    33
#include <liboil/liboilfunction.h>
sl@0
    34
sl@0
    35
OIL_DECLARE_CLASS (rowsad8x8_u8);
sl@0
    36
OIL_DECLARE_CLASS (colsad8x8_u8);
sl@0
    37
sl@0
    38
static void
sl@0
    39
rowsad8x8_u8_mmx (uint32_t *dest, uint8_t *src1, uint8_t *src2)
sl@0
    40
{
sl@0
    41
  uint32_t MaxSad;
sl@0
    42
#if !defined(__WINSCW__) && !defined(__WINS__)      
sl@0
    43
  __asm__ __volatile__ (
sl@0
    44
    "  pxor        %%mm6, %%mm6     \n\t"	/* zero out mm6 for unpack */
sl@0
    45
    "  pxor        %%mm7, %%mm7     \n\t" 	/* zero out mm7 for unpack */
sl@0
    46
    "  movq        (%1), %%mm0      \n\t"	/* take 8 bytes */
sl@0
    47
    "  movq        (%2), %%mm1      \n\t"
sl@0
    48
sl@0
    49
    "  movq        %%mm0, %%mm2     \n\t"
sl@0
    50
    "  psubusb     %%mm1, %%mm0     \n\t" 	/* A - B */
sl@0
    51
    "  psubusb     %%mm2, %%mm1     \n\t"	/* B - A */
sl@0
    52
    "  por         %%mm1, %%mm0     \n\t"      	/* and or gives abs difference */
sl@0
    53
sl@0
    54
    "  movq        %%mm0, %%mm1     \n\t"
sl@0
    55
sl@0
    56
    "  punpcklbw   %%mm6, %%mm0     \n\t"       /* ; unpack low four bytes to higher precision */
sl@0
    57
    "  punpckhbw   %%mm7, %%mm1     \n\t"       /* ; unpack high four bytes to higher precision */
sl@0
    58
sl@0
    59
    "  movq        %%mm0, %%mm2     \n\t"
sl@0
    60
    "  movq        %%mm1, %%mm3     \n\t"
sl@0
    61
    "  psrlq       $32, %%mm2       \n\t"	/* fold and add */
sl@0
    62
    "  psrlq       $32, %%mm3       \n\t"
sl@0
    63
    "  paddw       %%mm2, %%mm0     \n\t"
sl@0
    64
    "  paddw       %%mm3, %%mm1     \n\t"
sl@0
    65
    "  movq        %%mm0, %%mm2     \n\t"
sl@0
    66
    "  movq        %%mm1, %%mm3     \n\t"
sl@0
    67
    "  psrlq       $16, %%mm2       \n\t"
sl@0
    68
    "  psrlq       $16, %%mm3       \n\t"
sl@0
    69
    "  paddw       %%mm2, %%mm0     \n\t"
sl@0
    70
    "  paddw       %%mm3, %%mm1     \n\t"
sl@0
    71
sl@0
    72
    "  psubusw     %%mm0, %%mm1     \n\t"
sl@0
    73
    "  paddw       %%mm0, %%mm1     \n\t" 	/* mm1 = max(mm1, mm0) */
sl@0
    74
    "  movd        %%mm1, %0        \n\t"
sl@0
    75
    "  andl        $0xffff, %0      \n\t"
sl@0
    76
    "  emms                         \n\t"
sl@0
    77
sl@0
    78
     : "=m" (MaxSad),
sl@0
    79
       "+r" (src1), 
sl@0
    80
       "+r" (src2) 
sl@0
    81
     :
sl@0
    82
     : "memory"
sl@0
    83
  );
sl@0
    84
  *dest = MaxSad;
sl@0
    85
#endif  
sl@0
    86
}
sl@0
    87
OIL_DEFINE_IMPL_FULL (rowsad8x8_u8_mmx, rowsad8x8_u8, OIL_IMPL_FLAG_MMX);
sl@0
    88
sl@0
    89
static void
sl@0
    90
rowsad8x8_u8_mmxext (uint32_t *dest, uint8_t *src1, uint8_t *src2)
sl@0
    91
{
sl@0
    92
#if !defined(__WINSCW__) && !defined(__WINS__)      
sl@0
    93
  uint32_t MaxSad;
sl@0
    94
sl@0
    95
  __asm__ __volatile__ (
sl@0
    96
    "  movd        (%1), %%mm0      \n\t"
sl@0
    97
    "  movd        (%2), %%mm1      \n\t"
sl@0
    98
    "  psadbw      %%mm0, %%mm1     \n\t"
sl@0
    99
    "  movd        4(%1), %%mm2     \n\t"
sl@0
   100
    "  movd        4(%2), %%mm3     \n\t"
sl@0
   101
    "  psadbw      %%mm2, %%mm3     \n\t"
sl@0
   102
sl@0
   103
    "  pmaxsw      %%mm1, %%mm3     \n\t"
sl@0
   104
    "  movd        %%mm3, %0        \n\t"
sl@0
   105
    "  andl        $0xffff, %0      \n\t"
sl@0
   106
    "  emms                         \n\t"
sl@0
   107
sl@0
   108
     : "=m" (MaxSad),
sl@0
   109
       "+r" (src1), 
sl@0
   110
       "+r" (src2) 
sl@0
   111
     :
sl@0
   112
     : "memory"
sl@0
   113
  );
sl@0
   114
  *dest = MaxSad;
sl@0
   115
#endif  
sl@0
   116
}
sl@0
   117
OIL_DEFINE_IMPL_FULL (rowsad8x8_u8_mmxext, rowsad8x8_u8, OIL_IMPL_FLAG_MMX | OIL_IMPL_FLAG_MMXEXT);
sl@0
   118
sl@0
   119
static void
sl@0
   120
colsad8x8_u8_mmx (uint32_t *dest, uint8_t *src1, int ss1, uint8_t *src2, int ss2)
sl@0
   121
{
sl@0
   122
#if !defined(__WINSCW__) && !defined(__WINS__)      
sl@0
   123
  uint32_t MaxSad;
sl@0
   124
sl@0
   125
  __asm__ __volatile__ (
sl@0
   126
    "  pxor        %%mm3, %%mm3     \n\t"	/* zero out mm3 for unpack */
sl@0
   127
    "  pxor        %%mm4, %%mm4     \n\t"	/* mm4 low sum */
sl@0
   128
    "  pxor        %%mm5, %%mm5     \n\t" 	/* mm5 high sum */
sl@0
   129
    "  pxor        %%mm6, %%mm6     \n\t"	/* mm6 low sum */
sl@0
   130
    "  pxor        %%mm7, %%mm7     \n\t" 	/* mm7 high sum */
sl@0
   131
    "  mov         $4, %%edi        \n\t"	/* 4 rows */
sl@0
   132
    "1:                             \n\t"
sl@0
   133
    "  movq        (%1), %%mm0      \n\t"	/* take 8 bytes */
sl@0
   134
    "  movq        (%2), %%mm1      \n\t"	/* take 8 bytes */
sl@0
   135
sl@0
   136
    "  movq        %%mm0, %%mm2     \n\t"
sl@0
   137
    "  psubusb     %%mm1, %%mm0     \n\t" 	/* A - B */
sl@0
   138
    "  psubusb     %%mm2, %%mm1     \n\t"	/* B - A */
sl@0
   139
    "  por         %%mm1, %%mm0     \n\t"      	/* and or gives abs difference */
sl@0
   140
    "  movq        %%mm0, %%mm1     \n\t"
sl@0
   141
sl@0
   142
    "  punpcklbw   %%mm3, %%mm0     \n\t"	/* unpack to higher precision for accumulation */
sl@0
   143
    "  paddw       %%mm0, %%mm4     \n\t"	/* accumulate difference... */
sl@0
   144
    "  punpckhbw   %%mm3, %%mm1     \n\t"	/* unpack high four bytes to higher precision */
sl@0
   145
    "  paddw       %%mm1, %%mm5     \n\t"	/* accumulate difference... */
sl@0
   146
    "  add         %3, %1           \n\t"	/* Inc pointer into the new data */
sl@0
   147
    "  add         %3, %2           \n\t"	/* Inc pointer into the new data */
sl@0
   148
sl@0
   149
    "  dec         %%edi            \n\t"
sl@0
   150
    "  jnz 1b                       \n\t"
sl@0
   151
sl@0
   152
    "  mov         $4, %%edi        \n\t"	/* 4 rows */
sl@0
   153
    "2:                             \n\t"
sl@0
   154
    "  movq        (%1), %%mm0      \n\t"	/* take 8 bytes */
sl@0
   155
    "  movq        (%2), %%mm1      \n\t"	/* take 8 bytes */
sl@0
   156
sl@0
   157
    "  movq        %%mm0, %%mm2     \n\t"
sl@0
   158
    "  psubusb     %%mm1, %%mm0     \n\t" 	/* A - B */
sl@0
   159
    "  psubusb     %%mm2, %%mm1     \n\t"	/* B - A */
sl@0
   160
    "  por         %%mm1, %%mm0     \n\t"      	/* and or gives abs difference */
sl@0
   161
    "  movq        %%mm0, %%mm1     \n\t"
sl@0
   162
sl@0
   163
    "  punpcklbw   %%mm3, %%mm0     \n\t"	/* unpack to higher precision for accumulation */
sl@0
   164
    "  paddw       %%mm0, %%mm6     \n\t"	/* accumulate difference... */
sl@0
   165
    "  punpckhbw   %%mm3, %%mm1     \n\t"	/* unpack high four bytes to higher precision */
sl@0
   166
    "  paddw       %%mm1, %%mm7     \n\t"	/* accumulate difference... */
sl@0
   167
    "  add         %3, %1           \n\t"	/* Inc pointer into the new data */
sl@0
   168
    "  add         %3, %2           \n\t"	/* Inc pointer into the new data */
sl@0
   169
sl@0
   170
    "  dec         %%edi            \n\t"
sl@0
   171
    "  jnz 2b                       \n\t"
sl@0
   172
sl@0
   173
    "  psubusw     %%mm6, %%mm7     \n\t"
sl@0
   174
    "  paddw       %%mm6, %%mm7     \n\t" 	/* mm7 = max(mm7, mm6) */
sl@0
   175
    "  psubusw     %%mm4, %%mm5     \n\t" 	
sl@0
   176
    "  paddw       %%mm4, %%mm5     \n\t" 	/* mm5 = max(mm5, mm4) */
sl@0
   177
    "  psubusw     %%mm5, %%mm7     \n\t" 	
sl@0
   178
    "  paddw       %%mm5, %%mm7     \n\t" 	/* mm7 = max(mm5, mm7) */
sl@0
   179
    "  movq        %%mm7, %%mm6     \n\t"
sl@0
   180
    "  psrlq       $32, %%mm6       \n\t"
sl@0
   181
    "  psubusw     %%mm6, %%mm7     \n\t" 	
sl@0
   182
    "  paddw       %%mm6, %%mm7     \n\t" 	/* mm7 = max(mm5, mm7) */
sl@0
   183
    "  movq        %%mm7, %%mm6     \n\t"
sl@0
   184
    "  psrlq       $16, %%mm6       \n\t"
sl@0
   185
    "  psubusw     %%mm6, %%mm7     \n\t" 	
sl@0
   186
    "  paddw       %%mm6, %%mm7     \n\t" 	/* mm7 = max(mm5, mm7) */
sl@0
   187
    "  movd        %%mm7, %0        \n\t"
sl@0
   188
    "  andl        $0xffff, %0      \n\t"
sl@0
   189
    "  emms                         \n\t"
sl@0
   190
sl@0
   191
     : "=r" (MaxSad),
sl@0
   192
       "+r" (src1), 
sl@0
   193
       "+r" (src2) 
sl@0
   194
     : "r" (ss1)
sl@0
   195
     : "memory", "edi"
sl@0
   196
  );
sl@0
   197
  *dest = MaxSad;
sl@0
   198
#endif  
sl@0
   199
}
sl@0
   200
OIL_DEFINE_IMPL_FULL (colsad8x8_u8_mmx, colsad8x8_u8, OIL_IMPL_FLAG_MMX);
sl@0
   201
sl@0
   202
static void
sl@0
   203
colsad8x8_u8_mmxext (uint32_t *dest, uint8_t *src1, int ss1, uint8_t *src2, int ss2)
sl@0
   204
{
sl@0
   205
#if !defined(__WINSCW__) && !defined(__WINS__)      
sl@0
   206
  uint32_t MaxSad;
sl@0
   207
sl@0
   208
  __asm__ __volatile__ (
sl@0
   209
    "  pxor        %%mm3, %%mm3     \n\t"	/* zero out mm3 for unpack */
sl@0
   210
    "  pxor        %%mm4, %%mm4     \n\t"	/* mm4 low sum */
sl@0
   211
    "  pxor        %%mm5, %%mm5     \n\t" 	/* mm5 high sum */
sl@0
   212
    "  pxor        %%mm6, %%mm6     \n\t"	/* mm6 low sum */
sl@0
   213
    "  pxor        %%mm7, %%mm7     \n\t" 	/* mm7 high sum */
sl@0
   214
    "  mov         $4, %%edi        \n\t"	/* 4 rows */
sl@0
   215
    "1:                             \n\t"
sl@0
   216
    "  movq        (%1), %%mm0      \n\t"	/* take 8 bytes */
sl@0
   217
    "  movq        (%2), %%mm1      \n\t"	/* take 8 bytes */
sl@0
   218
sl@0
   219
    "  movq        %%mm0, %%mm2     \n\t"
sl@0
   220
    "  psubusb     %%mm1, %%mm0     \n\t" 	/* A - B */
sl@0
   221
    "  psubusb     %%mm2, %%mm1     \n\t"	/* B - A */
sl@0
   222
    "  por         %%mm1, %%mm0     \n\t"      	/* and or gives abs difference */
sl@0
   223
    "  movq        %%mm0, %%mm1     \n\t"
sl@0
   224
sl@0
   225
    "  punpcklbw   %%mm3, %%mm0     \n\t"	/* unpack to higher precision for accumulation */
sl@0
   226
    "  paddw       %%mm0, %%mm4     \n\t"	/* accumulate difference... */
sl@0
   227
    "  punpckhbw   %%mm3, %%mm1     \n\t"	/* unpack high four bytes to higher precision */
sl@0
   228
    "  paddw       %%mm1, %%mm5     \n\t"	/* accumulate difference... */
sl@0
   229
    "  add         %3, %1           \n\t"	/* Inc pointer into the new data */
sl@0
   230
    "  add         %3, %2           \n\t"	/* Inc pointer into the new data */
sl@0
   231
sl@0
   232
    "  dec         %%edi            \n\t"
sl@0
   233
    "  jnz 1b                       \n\t"
sl@0
   234
sl@0
   235
    "  mov         $4, %%edi        \n\t"	/* 4 rows */
sl@0
   236
    "2:                             \n\t"
sl@0
   237
    "  movq        (%1), %%mm0      \n\t"	/* take 8 bytes */
sl@0
   238
    "  movq        (%2), %%mm1      \n\t"	/* take 8 bytes */
sl@0
   239
sl@0
   240
    "  movq        %%mm0, %%mm2     \n\t"
sl@0
   241
    "  psubusb     %%mm1, %%mm0     \n\t" 	/* A - B */
sl@0
   242
    "  psubusb     %%mm2, %%mm1     \n\t"	/* B - A */
sl@0
   243
    "  por         %%mm1, %%mm0     \n\t"      	/* and or gives abs difference */
sl@0
   244
    "  movq        %%mm0, %%mm1     \n\t"
sl@0
   245
sl@0
   246
    "  punpcklbw   %%mm3, %%mm0     \n\t"	/* unpack to higher precision for accumulation */
sl@0
   247
    "  paddw       %%mm0, %%mm6     \n\t"	/* accumulate difference... */
sl@0
   248
    "  punpckhbw   %%mm3, %%mm1     \n\t"	/* unpack high four bytes to higher precision */
sl@0
   249
    "  paddw       %%mm1, %%mm7     \n\t"	/* accumulate difference... */
sl@0
   250
    "  add         %3, %1           \n\t"	/* Inc pointer into the new data */
sl@0
   251
    "  add         %3, %2           \n\t"	/* Inc pointer into the new data */
sl@0
   252
sl@0
   253
    "  dec         %%edi            \n\t"
sl@0
   254
    "  jnz 2b                       \n\t"
sl@0
   255
sl@0
   256
    "  pmaxsw      %%mm6, %%mm7     \n\t"
sl@0
   257
    "  pmaxsw      %%mm4, %%mm5     \n\t"
sl@0
   258
    "  pmaxsw      %%mm5, %%mm7     \n\t"
sl@0
   259
    "  movq        %%mm7, %%mm6     \n\t"
sl@0
   260
    "  psrlq       $32, %%mm6       \n\t"
sl@0
   261
    "  pmaxsw      %%mm6, %%mm7     \n\t"
sl@0
   262
    "  movq        %%mm7, %%mm6     \n\t"
sl@0
   263
    "  psrlq       $16, %%mm6       \n\t"
sl@0
   264
    "  pmaxsw      %%mm6, %%mm7     \n\t"
sl@0
   265
    "  movd        %%mm7, %0        \n\t"
sl@0
   266
    "  andl        $0xffff, %0      \n\t"
sl@0
   267
    "  emms                         \n\t"
sl@0
   268
sl@0
   269
     : "=r" (MaxSad),
sl@0
   270
       "+r" (src1), 
sl@0
   271
       "+r" (src2) 
sl@0
   272
     : "r" (ss1)
sl@0
   273
     : "memory", "edi"
sl@0
   274
  );
sl@0
   275
sl@0
   276
  *dest = MaxSad;
sl@0
   277
#endif
sl@0
   278
}
sl@0
   279
OIL_DEFINE_IMPL_FULL (colsad8x8_u8_mmxext, colsad8x8_u8, OIL_IMPL_FLAG_MMX | OIL_IMPL_FLAG_MMXEXT);
sl@0
   280
sl@0
   281
sl@0
   282
sl@0
   283
#ifdef	__SYMBIAN32__
sl@0
   284
 
sl@0
   285
OilFunctionImpl* __oil_function_impl_rowsad8x8_u8_mmx, rowsad8x8_u8() {
sl@0
   286
		return &_oil_function_impl_rowsad8x8_u8_mmx, rowsad8x8_u8;
sl@0
   287
}
sl@0
   288
#endif
sl@0
   289
sl@0
   290
#ifdef	__SYMBIAN32__
sl@0
   291
 
sl@0
   292
OilFunctionImpl* __oil_function_impl_rowsad8x8_u8_mmxext, rowsad8x8_u8() {
sl@0
   293
		return &_oil_function_impl_rowsad8x8_u8_mmxext, rowsad8x8_u8;
sl@0
   294
}
sl@0
   295
#endif
sl@0
   296
sl@0
   297
#ifdef	__SYMBIAN32__
sl@0
   298
 
sl@0
   299
OilFunctionImpl* __oil_function_impl_colsad8x8_u8_mmx, colsad8x8_u8() {
sl@0
   300
		return &_oil_function_impl_colsad8x8_u8_mmx, colsad8x8_u8;
sl@0
   301
}
sl@0
   302
#endif
sl@0
   303
sl@0
   304
#ifdef	__SYMBIAN32__
sl@0
   305
 
sl@0
   306
OilFunctionImpl* __oil_function_impl_colsad8x8_u8_mmxext, colsad8x8_u8() {
sl@0
   307
		return &_oil_function_impl_colsad8x8_u8_mmxext, colsad8x8_u8;
sl@0
   308
}
sl@0
   309
#endif
sl@0
   310