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

Windows CE

开发平台:

C/C++

  1. /*
  2.  * Alpha optimized DSP utils
  3.  * Copyright (c) 2002 Falk Hueffner <falk@debian.org>
  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 "asm.h"
  20. #include "../dsputil.h"
  21. extern void simple_idct_axp(DCTELEM *block);
  22. extern void simple_idct_put_axp(uint8_t *dest, int line_size, DCTELEM *block);
  23. extern void simple_idct_add_axp(uint8_t *dest, int line_size, DCTELEM *block);
  24. void put_pixels_axp_asm(uint8_t *block, const uint8_t *pixels,
  25.                         int line_size, int h);
  26. void put_pixels_clamped_mvi_asm(const DCTELEM *block, uint8_t *pixels,
  27.                                 int line_size);
  28. void add_pixels_clamped_mvi_asm(const DCTELEM *block, uint8_t *pixels, 
  29.                                 int line_size);
  30. void (*put_pixels_clamped_axp_p)(const DCTELEM *block, uint8_t *pixels,
  31.                                  int line_size);
  32. void (*add_pixels_clamped_axp_p)(const DCTELEM *block, uint8_t *pixels, 
  33.                                  int line_size);
  34. void get_pixels_mvi(DCTELEM *restrict block,
  35.                     const uint8_t *restrict pixels, int line_size);
  36. void diff_pixels_mvi(DCTELEM *block, const uint8_t *s1, const uint8_t *s2,
  37.                      int stride);
  38. int pix_abs8x8_mvi(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h);
  39. int pix_abs16x16_mvi_asm(uint8_t *pix1, uint8_t *pix2, int line_size);
  40. int pix_abs16x16_x2_mvi(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h);
  41. int pix_abs16x16_y2_mvi(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h);
  42. int pix_abs16x16_xy2_mvi(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h);
  43. #if 0
  44. /* These functions were the base for the optimized assembler routines,
  45.    and remain here for documentation purposes.  */
  46. static void put_pixels_clamped_mvi(const DCTELEM *block, uint8_t *pixels, 
  47.                                    int line_size)
  48. {
  49.     int i = 8;
  50.     uint64_t clampmask = zap(-1, 0xaa); /* 0x00ff00ff00ff00ff */
  51.     do {
  52.         uint64_t shorts0, shorts1;
  53.         shorts0 = ldq(block);
  54.         shorts0 = maxsw4(shorts0, 0);
  55.         shorts0 = minsw4(shorts0, clampmask);
  56.         stl(pkwb(shorts0), pixels);
  57.         shorts1 = ldq(block + 4);
  58.         shorts1 = maxsw4(shorts1, 0);
  59.         shorts1 = minsw4(shorts1, clampmask);
  60.         stl(pkwb(shorts1), pixels + 4);
  61.         pixels += line_size;
  62.         block += 8;
  63.     } while (--i);
  64. }
  65. void add_pixels_clamped_mvi(const DCTELEM *block, uint8_t *pixels, 
  66.                             int line_size)
  67. {
  68.     int h = 8;
  69.     /* Keep this function a leaf function by generating the constants
  70.        manually (mainly for the hack value ;-).  */
  71.     uint64_t clampmask = zap(-1, 0xaa); /* 0x00ff00ff00ff00ff */
  72.     uint64_t signmask  = zap(-1, 0x33);
  73.     signmask ^= signmask >> 1;  /* 0x8000800080008000 */
  74.     do {
  75.         uint64_t shorts0, pix0, signs0;
  76.         uint64_t shorts1, pix1, signs1;
  77.         shorts0 = ldq(block);
  78.         shorts1 = ldq(block + 4);
  79.         pix0    = unpkbw(ldl(pixels));
  80.         /* Signed subword add (MMX paddw).  */
  81.         signs0  = shorts0 & signmask;
  82.         shorts0 &= ~signmask;
  83.         shorts0 += pix0;
  84.         shorts0 ^= signs0;
  85.         /* Clamp. */
  86.         shorts0 = maxsw4(shorts0, 0);
  87.         shorts0 = minsw4(shorts0, clampmask);   
  88.         /* Next 4.  */
  89.         pix1    = unpkbw(ldl(pixels + 4));
  90.         signs1  = shorts1 & signmask;
  91.         shorts1 &= ~signmask;
  92.         shorts1 += pix1;
  93.         shorts1 ^= signs1;
  94.         shorts1 = maxsw4(shorts1, 0);
  95.         shorts1 = minsw4(shorts1, clampmask);
  96.         stl(pkwb(shorts0), pixels);
  97.         stl(pkwb(shorts1), pixels + 4);
  98.         pixels += line_size;
  99.         block += 8;
  100.     } while (--h);
  101. }
  102. #endif
  103. static void clear_blocks_axp(DCTELEM *blocks) {
  104.     uint64_t *p = (uint64_t *) blocks;
  105.     int n = sizeof(DCTELEM) * 6 * 64;
  106.     do {
  107.         p[0] = 0;
  108.         p[1] = 0;
  109.         p[2] = 0;
  110.         p[3] = 0;
  111.         p[4] = 0;
  112.         p[5] = 0;
  113.         p[6] = 0;
  114.         p[7] = 0;
  115.         p += 8;
  116.         n -= 8 * 8;
  117.     } while (n);
  118. }
  119. static inline uint64_t avg2_no_rnd(uint64_t a, uint64_t b)
  120. {
  121.     return (a & b) + (((a ^ b) & BYTE_VEC(0xfe)) >> 1);
  122. }
  123. static inline uint64_t avg2(uint64_t a, uint64_t b)
  124. {
  125.     return (a | b) - (((a ^ b) & BYTE_VEC(0xfe)) >> 1);    
  126. }
  127. #if 0
  128. /* The XY2 routines basically utilize this scheme, but reuse parts in
  129.    each iteration.  */
  130. static inline uint64_t avg4(uint64_t l1, uint64_t l2, uint64_t l3, uint64_t l4)
  131. {
  132.     uint64_t r1 = ((l1 & ~BYTE_VEC(0x03)) >> 2)
  133.                 + ((l2 & ~BYTE_VEC(0x03)) >> 2)
  134.                 + ((l3 & ~BYTE_VEC(0x03)) >> 2)
  135.                 + ((l4 & ~BYTE_VEC(0x03)) >> 2);
  136.     uint64_t r2 = ((  (l1 & BYTE_VEC(0x03))
  137.                     + (l2 & BYTE_VEC(0x03))
  138.                     + (l3 & BYTE_VEC(0x03))
  139.                     + (l4 & BYTE_VEC(0x03))
  140.                     + BYTE_VEC(0x02)) >> 2) & BYTE_VEC(0x03);
  141.     return r1 + r2;
  142. }
  143. #endif
  144. #define OP(LOAD, STORE)                         
  145.     do {                                        
  146.         STORE(LOAD(pixels), block);             
  147.         pixels += line_size;                    
  148.         block += line_size;                     
  149.     } while (--h)
  150. #define OP_X2(LOAD, STORE)                                      
  151.     do {                                                        
  152.         uint64_t pix1, pix2;                                    
  153.                                                                 
  154.         pix1 = LOAD(pixels);                                    
  155.         pix2 = pix1 >> 8 | ((uint64_t) pixels[8] << 56);        
  156.         STORE(AVG2(pix1, pix2), block);                         
  157.         pixels += line_size;                                    
  158.         block += line_size;                                     
  159.     } while (--h)
  160. #define OP_Y2(LOAD, STORE)                      
  161.     do {                                        
  162.         uint64_t pix = LOAD(pixels);            
  163.         do {                                    
  164.             uint64_t next_pix;                  
  165.                                                 
  166.             pixels += line_size;                
  167.             next_pix = LOAD(pixels);            
  168.             STORE(AVG2(pix, next_pix), block);  
  169.             block += line_size;                 
  170.             pix = next_pix;                     
  171.         } while (--h);                          
  172.     } while (0)
  173. #define OP_XY2(LOAD, STORE)                                                 
  174.     do {                                                                    
  175.         uint64_t pix1 = LOAD(pixels);                                       
  176.         uint64_t pix2 = pix1 >> 8 | ((uint64_t) pixels[8] << 56);           
  177.         uint64_t pix_l = (pix1 & BYTE_VEC(0x03))                            
  178.                        + (pix2 & BYTE_VEC(0x03));                           
  179.         uint64_t pix_h = ((pix1 & ~BYTE_VEC(0x03)) >> 2)                    
  180.                        + ((pix2 & ~BYTE_VEC(0x03)) >> 2);                   
  181.                                                                             
  182.         do {                                                                
  183.             uint64_t npix1, npix2;                                          
  184.             uint64_t npix_l, npix_h;                                        
  185.             uint64_t avg;                                                   
  186.                                                                             
  187.             pixels += line_size;                                            
  188.             npix1 = LOAD(pixels);                                           
  189.             npix2 = npix1 >> 8 | ((uint64_t) pixels[8] << 56);              
  190.             npix_l = (npix1 & BYTE_VEC(0x03))                               
  191.                    + (npix2 & BYTE_VEC(0x03));                              
  192.             npix_h = ((npix1 & ~BYTE_VEC(0x03)) >> 2)                       
  193.                    + ((npix2 & ~BYTE_VEC(0x03)) >> 2);                      
  194.             avg = (((pix_l + npix_l + AVG4_ROUNDER) >> 2) & BYTE_VEC(0x03)) 
  195.                 + pix_h + npix_h;                                           
  196.             STORE(avg, block);                                              
  197.                                                                             
  198.             block += line_size;                                             
  199.             pix_l = npix_l;                                                 
  200.             pix_h = npix_h;                                                 
  201.         } while (--h);                                                      
  202.     } while (0)
  203. #define MAKE_OP(OPNAME, SUFF, OPKIND, STORE)                                
  204. static void OPNAME ## _pixels ## SUFF ## _axp                               
  205.         (uint8_t *restrict block, const uint8_t *restrict pixels,           
  206.          int line_size, int h)                                              
  207. {                                                                           
  208.     if ((size_t) pixels & 0x7) {                                            
  209.         OPKIND(uldq, STORE);                                                
  210.     } else {                                                                
  211.         OPKIND(ldq, STORE);                                                 
  212.     }                                                                       
  213. }                                                                           
  214.                                                                             
  215. static void OPNAME ## _pixels16 ## SUFF ## _axp                             
  216.         (uint8_t *restrict block, const uint8_t *restrict pixels,           
  217.          int line_size, int h)                                              
  218. {                                                                           
  219.     OPNAME ## _pixels ## SUFF ## _axp(block,     pixels,     line_size, h); 
  220.     OPNAME ## _pixels ## SUFF ## _axp(block + 8, pixels + 8, line_size, h); 
  221. }
  222. #define PIXOP(OPNAME, STORE)                    
  223.     MAKE_OP(OPNAME, ,     OP,     STORE)        
  224.     MAKE_OP(OPNAME, _x2,  OP_X2,  STORE)        
  225.     MAKE_OP(OPNAME, _y2,  OP_Y2,  STORE)        
  226.     MAKE_OP(OPNAME, _xy2, OP_XY2, STORE)
  227. /* Rounding primitives.  */
  228. #define AVG2 avg2
  229. #define AVG4 avg4
  230. #define AVG4_ROUNDER BYTE_VEC(0x02)
  231. #define STORE(l, b) stq(l, b)
  232. PIXOP(put, STORE);
  233. #undef STORE
  234. #define STORE(l, b) stq(AVG2(l, ldq(b)), b);
  235. PIXOP(avg, STORE);
  236. /* Not rounding primitives.  */
  237. #undef AVG2
  238. #undef AVG4
  239. #undef AVG4_ROUNDER
  240. #undef STORE
  241. #define AVG2 avg2_no_rnd
  242. #define AVG4 avg4_no_rnd
  243. #define AVG4_ROUNDER BYTE_VEC(0x01)
  244. #define STORE(l, b) stq(l, b)
  245. PIXOP(put_no_rnd, STORE);
  246. #undef STORE
  247. #define STORE(l, b) stq(AVG2(l, ldq(b)), b);
  248. PIXOP(avg_no_rnd, STORE);
  249. void put_pixels16_axp_asm(uint8_t *block, const uint8_t *pixels,
  250.                           int line_size, int h)
  251. {
  252.     put_pixels_axp_asm(block,     pixels,     line_size, h);
  253.     put_pixels_axp_asm(block + 8, pixels + 8, line_size, h);
  254. }
  255. static int sad16x16_mvi(void *s, uint8_t *a, uint8_t *b, int stride)
  256. {
  257.     return pix_abs16x16_mvi_asm(a, b, stride);
  258. }
  259. void dsputil_init_alpha(DSPContext* c, AVCodecContext *avctx)
  260. {
  261.     c->put_pixels_tab[0][0] = put_pixels16_axp_asm;
  262.     c->put_pixels_tab[0][1] = put_pixels16_x2_axp;
  263.     c->put_pixels_tab[0][2] = put_pixels16_y2_axp;
  264.     c->put_pixels_tab[0][3] = put_pixels16_xy2_axp;
  265.     c->put_no_rnd_pixels_tab[0][0] = put_pixels16_axp_asm;
  266.     c->put_no_rnd_pixels_tab[0][1] = put_no_rnd_pixels16_x2_axp;
  267.     c->put_no_rnd_pixels_tab[0][2] = put_no_rnd_pixels16_y2_axp;
  268.     c->put_no_rnd_pixels_tab[0][3] = put_no_rnd_pixels16_xy2_axp;
  269.     c->avg_pixels_tab[0][0] = avg_pixels16_axp;
  270.     c->avg_pixels_tab[0][1] = avg_pixels16_x2_axp;
  271.     c->avg_pixels_tab[0][2] = avg_pixels16_y2_axp;
  272.     c->avg_pixels_tab[0][3] = avg_pixels16_xy2_axp;
  273.     c->avg_no_rnd_pixels_tab[0][0] = avg_no_rnd_pixels16_axp;
  274.     c->avg_no_rnd_pixels_tab[0][1] = avg_no_rnd_pixels16_x2_axp;
  275.     c->avg_no_rnd_pixels_tab[0][2] = avg_no_rnd_pixels16_y2_axp;
  276.     c->avg_no_rnd_pixels_tab[0][3] = avg_no_rnd_pixels16_xy2_axp;
  277.     c->put_pixels_tab[1][0] = put_pixels_axp_asm;
  278.     c->put_pixels_tab[1][1] = put_pixels_x2_axp;
  279.     c->put_pixels_tab[1][2] = put_pixels_y2_axp;
  280.     c->put_pixels_tab[1][3] = put_pixels_xy2_axp;
  281.     c->put_no_rnd_pixels_tab[1][0] = put_pixels_axp_asm;
  282.     c->put_no_rnd_pixels_tab[1][1] = put_no_rnd_pixels_x2_axp;
  283.     c->put_no_rnd_pixels_tab[1][2] = put_no_rnd_pixels_y2_axp;
  284.     c->put_no_rnd_pixels_tab[1][3] = put_no_rnd_pixels_xy2_axp;
  285.     c->avg_pixels_tab[1][0] = avg_pixels_axp;
  286.     c->avg_pixels_tab[1][1] = avg_pixels_x2_axp;
  287.     c->avg_pixels_tab[1][2] = avg_pixels_y2_axp;
  288.     c->avg_pixels_tab[1][3] = avg_pixels_xy2_axp;
  289.     c->avg_no_rnd_pixels_tab[1][0] = avg_no_rnd_pixels_axp;
  290.     c->avg_no_rnd_pixels_tab[1][1] = avg_no_rnd_pixels_x2_axp;
  291.     c->avg_no_rnd_pixels_tab[1][2] = avg_no_rnd_pixels_y2_axp;
  292.     c->avg_no_rnd_pixels_tab[1][3] = avg_no_rnd_pixels_xy2_axp;
  293.     c->clear_blocks = clear_blocks_axp;
  294.     /* amask clears all bits that correspond to present features.  */
  295.     if (amask(AMASK_MVI) == 0) {
  296.         c->put_pixels_clamped = put_pixels_clamped_mvi_asm;
  297.         c->add_pixels_clamped = add_pixels_clamped_mvi_asm;
  298.         c->get_pixels       = get_pixels_mvi;
  299.         c->diff_pixels      = diff_pixels_mvi;
  300.         c->sad[0]           = sad16x16_mvi;
  301.         c->sad[1]           = pix_abs8x8_mvi;
  302. //        c->pix_abs[0][0]    = pix_abs16x16_mvi_asm; //FIXME function arguments for the asm must be fixed
  303.         c->pix_abs[0][0]    = sad16x16_mvi;
  304.         c->pix_abs[1][0]    = pix_abs8x8_mvi;
  305.         c->pix_abs[0][1]    = pix_abs16x16_x2_mvi;
  306.         c->pix_abs[0][2]    = pix_abs16x16_y2_mvi;
  307.         c->pix_abs[0][3]    = pix_abs16x16_xy2_mvi;
  308.     }
  309.     put_pixels_clamped_axp_p = c->put_pixels_clamped;
  310.     add_pixels_clamped_axp_p = c->add_pixels_clamped;
  311.     
  312.     c->idct_put = simple_idct_put_axp;
  313.     c->idct_add = simple_idct_add_axp;
  314.     c->idct = simple_idct_axp;
  315. }