dsputil_arm.c
上传用户:wstnjxml
上传日期:2014-04-03
资源大小:7248k
文件大小:9k
源码类别:

Windows CE

开发平台:

C/C++

  1. /*
  2.  * ARMv4L optimized DSP utils
  3.  * Copyright (c) 2001 Lionel Ulmer.
  4.  *
  5.  * This library is free software; you can redistribute it and/or
  6.  * modify it under the terms of the GNU Lesser General Public
  7.  * License as published by the Free Software Foundation; either
  8.  * version 2 of the License, or (at your option) any later version.
  9.  *
  10.  * This library is distributed in the hope that it will be useful,
  11.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.  * Lesser General Public License for more details.
  14.  *
  15.  * You should have received a copy of the GNU Lesser General Public
  16.  * License along with this library; if not, write to the Free Software
  17.  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  18.  */
  19. #include "../dsputil.h"
  20. #ifdef HAVE_IPP
  21. #include "ipp.h"
  22. #endif
  23. extern void dsputil_init_iwmmxt(DSPContext* c, AVCodecContext *avctx);
  24. extern void j_rev_dct_ARM(DCTELEM *data);
  25. extern void simple_idct_ARM(DCTELEM *data);
  26. /* XXX: local hack */
  27. static void (*ff_put_pixels_clamped)(const DCTELEM *block, uint8_t *pixels, int line_size);
  28. static void (*ff_add_pixels_clamped)(const DCTELEM *block, uint8_t *pixels, int line_size);
  29. void put_pixels8_arm(uint8_t *block, const uint8_t *pixels, int line_size, int h);
  30. void put_pixels8_x2_arm(uint8_t *block, const uint8_t *pixels, int line_size, int h);
  31. void put_pixels8_y2_arm(uint8_t *block, const uint8_t *pixels, int line_size, int h);
  32. void put_pixels8_xy2_arm(uint8_t *block, const uint8_t *pixels, int line_size, int h);
  33. void put_no_rnd_pixels8_x2_arm(uint8_t *block, const uint8_t *pixels, int line_size, int h);
  34. void put_no_rnd_pixels8_y2_arm(uint8_t *block, const uint8_t *pixels, int line_size, int h);
  35. void put_no_rnd_pixels8_xy2_arm(uint8_t *block, const uint8_t *pixels, int line_size, int h);
  36. void put_pixels16_arm(uint8_t *block, const uint8_t *pixels, int line_size, int h);
  37. CALL_2X_PIXELS(put_pixels16_x2_arm , put_pixels8_x2_arm , 8)
  38. CALL_2X_PIXELS(put_pixels16_y2_arm , put_pixels8_y2_arm , 8)
  39. CALL_2X_PIXELS(put_pixels16_xy2_arm, put_pixels8_xy2_arm, 8)
  40. CALL_2X_PIXELS(put_no_rnd_pixels16_x2_arm , put_no_rnd_pixels8_x2_arm , 8)
  41. CALL_2X_PIXELS(put_no_rnd_pixels16_y2_arm , put_no_rnd_pixels8_y2_arm , 8)
  42. CALL_2X_PIXELS(put_no_rnd_pixels16_xy2_arm, put_no_rnd_pixels8_xy2_arm, 8)
  43. static void add_pixels_clamped_ARM(short *block, unsigned char *dest, int line_size)
  44. {
  45.     asm volatile (
  46.                   "mov r10, #8 nt"
  47.                   "1: nt"
  48.                   /* load dest */
  49.                   "ldr r4, [%1] nt"
  50.                   /* block[0] and block[1]*/
  51.                   "ldrsh r5, [%0] nt"
  52.                   "ldrsh r7, [%0, #2] nt"
  53.                   "and r6, r4, #0xFF nt"
  54.                   "and r8, r4, #0xFF00 nt"
  55.                   "add r6, r5, r6 nt"
  56.                   "add r8, r7, r8, lsr #8 nt"
  57.                   "mvn r5, r5 nt"
  58.                   "mvn r7, r7 nt"
  59.                   "tst r6, #0x100 nt"
  60.                   "movne r6, r5, lsr #24 nt"
  61.                   "tst r8, #0x100 nt"
  62.                   "movne r8, r7, lsr #24 nt"
  63.                   "mov r9, r6 nt"
  64.                   "ldrsh r5, [%0, #4] nt" /* moved form [A] */
  65.                   "orr r9, r9, r8, lsl #8 nt"
  66.                   /* block[2] and block[3] */
  67.                   /* [A] */
  68.                   "ldrsh r7, [%0, #6] nt"
  69.                   "and r6, r4, #0xFF0000 nt"
  70.                   "and r8, r4, #0xFF000000 nt"
  71.                   "add r6, r5, r6, lsr #16 nt"
  72.                   "add r8, r7, r8, lsr #24 nt"
  73.                   "mvn r5, r5 nt"
  74.                   "mvn r7, r7 nt"
  75.                   "tst r6, #0x100 nt"
  76.                   "movne r6, r5, lsr #24 nt"
  77.                   "tst r8, #0x100 nt"
  78.                   "movne r8, r7, lsr #24 nt"
  79.                   "orr r9, r9, r6, lsl #16 nt"
  80.                   "ldr r4, [%1, #4] nt"       /* moved form [B] */
  81.                   "orr r9, r9, r8, lsl #24 nt"
  82.                   /* store dest */
  83.                   "ldrsh r5, [%0, #8] nt" /* moved form [C] */
  84.                   "str r9, [%1] nt"
  85.                   /* load dest */
  86.                   /* [B] */
  87.                   /* block[4] and block[5] */
  88.                   /* [C] */
  89.                   "ldrsh r7, [%0, #10] nt"
  90.                   "and r6, r4, #0xFF nt"
  91.                   "and r8, r4, #0xFF00 nt"
  92.                   "add r6, r5, r6 nt"
  93.                   "add r8, r7, r8, lsr #8 nt"
  94.                   "mvn r5, r5 nt"
  95.                   "mvn r7, r7 nt"
  96.                   "tst r6, #0x100 nt"
  97.                   "movne r6, r5, lsr #24 nt"
  98.                   "tst r8, #0x100 nt"
  99.                   "movne r8, r7, lsr #24 nt"
  100.                   "mov r9, r6 nt"
  101.                   "ldrsh r5, [%0, #12] nt" /* moved from [D] */
  102.                   "orr r9, r9, r8, lsl #8 nt"
  103.                   /* block[6] and block[7] */
  104.                   /* [D] */
  105.                   "ldrsh r7, [%0, #14] nt"
  106.                   "and r6, r4, #0xFF0000 nt"
  107.                   "and r8, r4, #0xFF000000 nt"
  108.                   "add r6, r5, r6, lsr #16 nt"
  109.                   "add r8, r7, r8, lsr #24 nt"
  110.                   "mvn r5, r5 nt"
  111.                   "mvn r7, r7 nt"
  112.                   "tst r6, #0x100 nt"
  113.                   "movne r6, r5, lsr #24 nt"
  114.                   "tst r8, #0x100 nt"
  115.                   "movne r8, r7, lsr #24 nt"
  116.                   "orr r9, r9, r6, lsl #16 nt"
  117.                   "add %0, %0, #16 nt" /* moved from [E] */
  118.                   "orr r9, r9, r8, lsl #24 nt"
  119.                   "subs r10, r10, #1 nt" /* moved from [F] */
  120.                   /* store dest */
  121.                   "str r9, [%1, #4] nt"
  122.                   /* [E] */
  123.                   /* [F] */
  124.                   "add %1, %1, %2 nt"
  125.                   "bne 1b nt"
  126.                   : "+r"(block),
  127.                     "+r"(dest)
  128.                   : "r"(line_size)
  129.                   : "r4", "r5", "r6", "r7", "r8", "r9", "r10", "cc", "memory" );
  130. }
  131. /* XXX: those functions should be suppressed ASAP when all IDCTs are
  132.    converted */
  133. static void j_rev_dct_ARM_put(uint8_t *dest, int line_size, DCTELEM *block)
  134. {
  135.     j_rev_dct_ARM (block);
  136.     ff_put_pixels_clamped(block, dest, line_size);
  137. }
  138. static void j_rev_dct_ARM_add(uint8_t *dest, int line_size, DCTELEM *block)
  139. {
  140.     j_rev_dct_ARM (block);
  141.     ff_add_pixels_clamped(block, dest, line_size);
  142. }
  143. static void simple_idct_ARM_put(uint8_t *dest, int line_size, DCTELEM *block)
  144. {
  145.     simple_idct_ARM (block);
  146.     ff_put_pixels_clamped(block, dest, line_size);
  147. }
  148. static void simple_idct_ARM_add(uint8_t *dest, int line_size, DCTELEM *block)
  149. {
  150.     simple_idct_ARM (block);
  151.     ff_add_pixels_clamped(block, dest, line_size);
  152. }
  153. static void simple_idct_ipp(DCTELEM *block)
  154. {
  155. #ifdef HAVE_IPP
  156.     ippiDCT8x8Inv_Video_16s_C1I(block);
  157. #endif
  158. }
  159. static void simple_idct_ipp_put(uint8_t *dest, int line_size, DCTELEM *block)
  160. {
  161. #ifdef HAVE_IPP
  162.     ippiDCT8x8Inv_Video_16s8u_C1R(block, dest, line_size);
  163. #endif
  164. }
  165. void add_pixels_clamped_iwmmxt(const DCTELEM *block, uint8_t *pixels, int line_size);
  166. static void simple_idct_ipp_add(uint8_t *dest, int line_size, DCTELEM *block)
  167. {
  168. #ifdef HAVE_IPP
  169.     ippiDCT8x8Inv_Video_16s_C1I(block);
  170. #ifdef HAVE_IWMMXT
  171.     add_pixels_clamped_iwmmxt(block, dest, line_size);
  172. #else
  173.     add_pixels_clamped_ARM(block, dest, line_size);
  174. #endif
  175. #endif
  176. }
  177. void dsputil_init_armv4l(DSPContext* c, AVCodecContext *avctx)
  178. {
  179.     const int idct_algo= avctx->idct_algo;
  180.     ff_put_pixels_clamped = c->put_pixels_clamped;
  181.     ff_add_pixels_clamped = c->add_pixels_clamped;
  182. #ifdef HAVE_IPP
  183.     if(idct_algo==FF_IDCT_ARM){
  184. #else
  185.     if(idct_algo==FF_IDCT_AUTO || idct_algo==FF_IDCT_ARM){
  186. #endif
  187.         c->idct_put= j_rev_dct_ARM_put;
  188.         c->idct_add= j_rev_dct_ARM_add;
  189. c->idct    = j_rev_dct_ARM;
  190.         c->idct_permutation_type= FF_LIBMPEG2_IDCT_PERM;/* FF_NO_IDCT_PERM */
  191.     } else if (idct_algo==FF_IDCT_SIMPLEARM){
  192. c->idct_put= simple_idct_ARM_put;
  193. c->idct_add= simple_idct_ARM_add;
  194. c->idct    = simple_idct_ARM;
  195. c->idct_permutation_type= FF_NO_IDCT_PERM;
  196. #ifdef HAVE_IPP
  197.     } else if (idct_algo==FF_IDCT_AUTO || idct_algo==FF_IDCT_IPP){
  198. #else
  199.     } else if (idct_algo==FF_IDCT_IPP){
  200. #endif
  201.         c->idct_put= simple_idct_ipp_put;
  202.         c->idct_add= simple_idct_ipp_add;
  203.         c->idct    = simple_idct_ipp;
  204.         c->idct_permutation_type= FF_NO_IDCT_PERM;
  205.     }
  206. /*     c->put_pixels_tab[0][0] = put_pixels16_arm; */ // NG!
  207.     c->put_pixels_tab[0][1] = put_pixels16_x2_arm; //OK!
  208.     c->put_pixels_tab[0][2] = put_pixels16_y2_arm; //OK!
  209. /*     c->put_pixels_tab[0][3] = put_pixels16_xy2_arm; /* NG */ */
  210. /*     c->put_no_rnd_pixels_tab[0][0] = put_pixels16_arm; // ?(蝗われない) */
  211.     c->put_no_rnd_pixels_tab[0][1] = put_no_rnd_pixels16_x2_arm; // OK
  212.     c->put_no_rnd_pixels_tab[0][2] = put_no_rnd_pixels16_y2_arm; //OK
  213. /*     c->put_no_rnd_pixels_tab[0][3] = put_no_rnd_pixels16_xy2_arm; //NG */
  214.     c->put_pixels_tab[1][0] = put_pixels8_arm; //OK
  215.     c->put_pixels_tab[1][1] = put_pixels8_x2_arm; //OK
  216. /*     c->put_pixels_tab[1][2] = put_pixels8_y2_arm; //NG */
  217. /*     c->put_pixels_tab[1][3] = put_pixels8_xy2_arm; //NG */
  218.     c->put_no_rnd_pixels_tab[1][0] = put_pixels8_arm;//OK
  219.     c->put_no_rnd_pixels_tab[1][1] = put_no_rnd_pixels8_x2_arm; //OK
  220.     c->put_no_rnd_pixels_tab[1][2] = put_no_rnd_pixels8_y2_arm; //OK
  221. /*     c->put_no_rnd_pixels_tab[1][3] = put_no_rnd_pixels8_xy2_arm;//NG */
  222. #ifdef HAVE_IWMMXT
  223.     dsputil_init_iwmmxt(c, avctx);
  224. #endif
  225. }