{
int y;
vec_u8_t src1v, src2v;
+ PREP_LOAD;
+ PREP_STORE16;
for( y = 0; y < i_height; y++ )
{
- src1v = vec_load16( src1 );
- src2v = vec_load16( src2 );
+ VEC_LOAD( src1, src1v, 16 );
+ VEC_LOAD( src2, src2v, 16 );
src1v = vec_avg( src1v, src2v );
- vec_store16( src1v, dst );
+ VEC_STORE16( src1v, dst );
dst += i_dst;
src1 += i_src1;
MC_COPY( mc_copy_w8, 8 )
MC_COPY( mc_copy_w16, 16 )
-/* TAP_FILTER:
- a is source (vec_s16_t [6])
- b is a temporary vec_s16_t
- c is the result
-
- c = src[0] + a[5] - 5 * ( a[1] + a[4] ) + 20 * ( a[2] + a[3] );
- c += 16;
- c >>= 5;
- c += 80; */
-#define TAP_FILTER( a, b, c ) \
- c = vec_add( a[0], a[5] ); \
- b = vec_add( a[1], a[4] ); \
- c = vec_sub( c, b ); \
- b = vec_sl( b, vec_splat_u16( 2 ) ); \
- c = vec_sub( c, b ); \
- b = vec_add( a[2], a[3] ); \
- b = vec_sl( b, vec_splat_u16( 2 ) ); \
- c = vec_add( c, b ); \
- b = vec_sl( b, vec_splat_u16( 2 ) ); \
- c = vec_add( c, b ); \
- c = vec_add( c, vec_splat_s16( 8 ) ); \
- c = vec_add( c, vec_splat_s16( 8 ) ); \
- c = vec_sr( c, vec_splat_u16( 5 ) ); \
- c = vec_add( c, vec_sl( vec_splat_s16( 5 ), \
- vec_splat_u16( 4 ) ) );
-
-/* mc_hh */
-static inline void mc_hh_w4( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- int x, y;
- for( y = 0; y < i_height; y++ )
- {
- for( x = 0; x < 4; x++ )
- {
- dst[x] = x264_mc_clip1( ( x264_tapfilter1( &src[x] ) +
- 16 ) >> 5 );
- }
- src += i_src;
- dst += i_dst;
- }
-}
-static inline void mc_hh_w8( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- long x, y;
- DECLARE_ALIGNED( int16_t, tmp[8], 16 );
-
- LOAD_ZERO;
- vec_u8_t loadv;
- vec_s16_t srcv[6];
- vec_u8_t * _srcv = (vec_u8_t*) srcv;
- vec_s16_t dstv;
- vec_s16_t tmpv;
-
- for( y = 0; y < i_height; y++ )
- {
- loadv = vec_load16( &src[-2] );
-
- for( x = 0; x < 6; x++ )
- {
- _srcv[x] = vec_perm( loadv, zero_u8v,
- vec_lvsl( 0, (int*) x ) );
- srcv[x] = vec_u8_to_s16( _srcv[x] );
- }
-
- TAP_FILTER( srcv, tmpv, dstv );
- vec_st( dstv, 0, tmp );
-
- for( x = 0; x < 8; x++ )
- {
- dst[x] = x264_mc_clip1_table[tmp[x]];
- }
-
- src += i_src;
- dst += i_dst;
- }
-}
-static inline void mc_hh_w16( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- mc_hh_w8( &src[0], i_src, &dst[0], i_dst, i_height );
- mc_hh_w8( &src[8], i_src, &dst[8], i_dst, i_height );
-}
-
-/* mc_hv */
-static inline void mc_hv_w4( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- int x, y;
- for( y = 0; y < i_height; y++ )
- {
- for( x = 0; x < 4; x++ )
- {
- dst[x] = x264_mc_clip1( ( x264_tapfilter( &src[x], i_src ) +
- 16 ) >> 5 );
- }
- src += i_src;
- dst += i_dst;
- }
-}
-static inline void mc_hv_w8( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- int x, y;
- DECLARE_ALIGNED( int16_t, tmp[8], 16 );
-
- vec_s16_t srcv[6];
- vec_u8_t * _srcv = (vec_u8_t*) srcv;
- vec_s16_t dstv;
- vec_s16_t tmpv;
-
- for( y = 0; y < i_height; y++ )
- {
- if( y )
- {
- for( x = 0; x < 5; x++ )
- {
- srcv[x] = srcv[x+1];
- }
- _srcv[5] = vec_load8( &src[3*i_src] );
- srcv[5] = vec_u8_to_s16( _srcv[5] );
- }
- else
- {
- for( x = 0; x < 6; x++ )
- {
- _srcv[x] = vec_load8( &src[(x-2)*i_src] );
- srcv[x] = vec_u8_to_s16( _srcv[x] );
- }
- }
-
- TAP_FILTER( srcv, tmpv, dstv );
- vec_st( dstv, 0, tmp );
-
- for( x = 0; x < 8; x++ )
- {
- dst[x] = x264_mc_clip1_table[tmp[x]];
- }
- src += i_src;
- dst += i_dst;
- }
-}
-static inline void mc_hv_w16( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- mc_hv_w8( &src[0], i_src, &dst[0], i_dst, i_height );
- mc_hv_w8( &src[8], i_src, &dst[8], i_dst, i_height );
-}
-
-/* mc_hc */
-static inline void mc_hc_w4( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- uint8_t *out;
- uint8_t *pix;
- int x, y;
-
- for( x = 0; x < 4; x++ )
- {
- int tap[6];
-
- pix = &src[x];
- out = &dst[x];
-
- tap[0] = x264_tapfilter1( &pix[-2*i_src] );
- tap[1] = x264_tapfilter1( &pix[-1*i_src] );
- tap[2] = x264_tapfilter1( &pix[ 0*i_src] );
- tap[3] = x264_tapfilter1( &pix[ 1*i_src] );
- tap[4] = x264_tapfilter1( &pix[ 2*i_src] );
-
- for( y = 0; y < i_height; y++ )
- {
- tap[5] = x264_tapfilter1( &pix[ 3*i_src] );
-
- *out = x264_mc_clip1( ( tap[0] - 5*tap[1] + 20 * tap[2] +
- 20 * tap[3] -5*tap[4] + tap[5] +
- 512 ) >> 10 );
-
- /* Next line */
- pix += i_src;
- out += i_dst;
- tap[0] = tap[1];
- tap[1] = tap[2];
- tap[2] = tap[3];
- tap[3] = tap[4];
- tap[4] = tap[5];
- }
- }
-}
-static inline void mc_hc_w8( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- /* TODO: optimize */
- mc_hc_w4( &src[0], i_src, &dst[0], i_dst, i_height );
- mc_hc_w4( &src[4], i_src, &dst[4], i_dst, i_height );
-}
-static inline void mc_hc_w16( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- mc_hc_w8( &src[0], i_src, &dst[0], i_dst, i_height );
- mc_hc_w8( &src[8], i_src, &dst[8], i_dst, i_height );
-}
-
-/* mc I+H */
-static void mc_xy10_w4( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- uint8_t tmp[16*4];
- mc_hh_w4( src, i_src, tmp, 4, i_height );
- pixel_avg_w4( dst, i_dst, src, i_src, tmp, 4, i_height );
-}
-static void mc_xy10_w8( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- uint8_t tmp[16*8];
- mc_hh_w8( src, i_src, tmp, 8, i_height );
- pixel_avg_w8( dst, i_dst, src, i_src, tmp, 8, i_height );
-}
-static void mc_xy10_w16( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- uint8_t tmp[16*16];
- mc_hh_w16( src, i_src, tmp, 16, i_height );
- pixel_avg_w16( dst, i_dst, src, i_src, tmp, 16, i_height );
-}
-
-static void mc_xy30_w4( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- uint8_t tmp[16*4];
- mc_hh_w4( src, i_src, tmp, 4, i_height );
- pixel_avg_w4( dst, i_dst, src + 1, i_src, tmp, 4, i_height );
-}
-static void mc_xy30_w8( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- uint8_t tmp[16*8];
- mc_hh_w8( src, i_src, tmp, 8, i_height );
- pixel_avg_w8( dst, i_dst, src + 1, i_src, tmp, 8, i_height );
-}
-static void mc_xy30_w16( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- uint8_t tmp[16*16];
- mc_hh_w16( src, i_src, tmp, 16, i_height );
- pixel_avg_w16( dst, i_dst, src + 1, i_src, tmp, 16, i_height );
-}
-
-/* mc I+V */
-static void mc_xy01_w4( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- uint8_t tmp[16*4];
- mc_hv_w4( src, i_src, tmp, 4, i_height );
- pixel_avg_w4( dst, i_dst, src, i_src, tmp, 4, i_height );
-}
-static void mc_xy01_w8( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- uint8_t tmp[16*8];
- mc_hv_w8( src, i_src, tmp, 8, i_height );
- pixel_avg_w8( dst, i_dst, src, i_src, tmp, 8, i_height );
-}
-static void mc_xy01_w16( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- uint8_t tmp[16*16];
- mc_hv_w16( src, i_src, tmp, 16, i_height );
- pixel_avg_w16( dst, i_dst, src, i_src, tmp, 16, i_height );
-}
-
-static void mc_xy03_w4( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- uint8_t tmp[16*4];
- mc_hv_w4( src, i_src, tmp, 4, i_height );
- pixel_avg_w4( dst, i_dst, src + i_src, i_src, tmp, 4, i_height );
-}
-static void mc_xy03_w8( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- uint8_t tmp[16*8];
- mc_hv_w8( src, i_src, tmp, 8, i_height );
- pixel_avg_w8( dst, i_dst, src + i_src, i_src, tmp, 8, i_height );
-}
-static void mc_xy03_w16( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- uint8_t tmp[16*16];
- mc_hv_w16( src, i_src, tmp, 16, i_height );
- pixel_avg_w16( dst, i_dst, src + i_src, i_src, tmp, 16, i_height );
-}
-
-/* H+V */
-static void mc_xy11_w4( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- uint8_t tmp1[16*4];
- uint8_t tmp2[16*4];
- mc_hv_w4( src, i_src, tmp1, 4, i_height );
- mc_hh_w4( src, i_src, tmp2, 4, i_height );
- pixel_avg_w4( dst, i_dst, tmp1, 4, tmp2, 4, i_height );
-}
-static void mc_xy11_w8( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- uint8_t tmp1[16*8];
- uint8_t tmp2[16*8];
- mc_hv_w8( src, i_src, tmp1, 8, i_height );
- mc_hh_w8( src, i_src, tmp2, 8, i_height );
- pixel_avg_w8( dst, i_dst, tmp1, 8, tmp2, 8, i_height );
-}
-static void mc_xy11_w16( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- uint8_t tmp1[16*16];
- uint8_t tmp2[16*16];
- mc_hv_w16( src, i_src, tmp1, 16, i_height );
- mc_hh_w16( src, i_src, tmp2, 16, i_height );
- pixel_avg_w16( dst, i_dst, tmp1, 16, tmp2, 16, i_height );
-}
-
-static void mc_xy31_w4( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- uint8_t tmp1[16*4];
- uint8_t tmp2[16*4];
- mc_hv_w4( src+1, i_src, tmp1, 4, i_height );
- mc_hh_w4( src, i_src, tmp2, 4, i_height );
- pixel_avg_w4( dst, i_dst, tmp1, 4, tmp2, 4, i_height );
-}
-static void mc_xy31_w8( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- uint8_t tmp1[16*8];
- uint8_t tmp2[16*8];
- mc_hv_w8( src+1, i_src, tmp1, 8, i_height );
- mc_hh_w8( src, i_src, tmp2, 8, i_height );
- pixel_avg_w8( dst, i_dst, tmp1, 8, tmp2, 8, i_height );
-}
-static void mc_xy31_w16( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- uint8_t tmp1[16*16];
- uint8_t tmp2[16*16];
- mc_hv_w16( src+1, i_src, tmp1, 16, i_height );
- mc_hh_w16( src, i_src, tmp2, 16, i_height );
- pixel_avg_w16( dst, i_dst, tmp1, 16, tmp2, 16, i_height );
-}
-
-static void mc_xy13_w4( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- uint8_t tmp1[16*4];
- uint8_t tmp2[16*4];
- mc_hv_w4( src, i_src, tmp1, 4, i_height );
- mc_hh_w4( src+i_src, i_src, tmp2, 4, i_height );
- pixel_avg_w4( dst, i_dst, tmp1, 4, tmp2, 4, i_height );
-}
-static void mc_xy13_w8( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- uint8_t tmp1[16*8];
- uint8_t tmp2[16*8];
- mc_hv_w8( src, i_src, tmp1, 8, i_height );
- mc_hh_w8( src+i_src, i_src, tmp2, 8, i_height );
- pixel_avg_w8( dst, i_dst, tmp1, 8, tmp2, 8, i_height );
-}
-static void mc_xy13_w16( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- uint8_t tmp1[16*16];
- uint8_t tmp2[16*16];
- mc_hv_w16( src, i_src, tmp1, 16, i_height );
- mc_hh_w16( src+i_src, i_src, tmp2, 16, i_height );
- pixel_avg_w16( dst, i_dst, tmp1, 16, tmp2, 16, i_height );
-}
-
-static void mc_xy33_w4( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- uint8_t tmp1[16*4];
- uint8_t tmp2[16*4];
- mc_hv_w4( src+1, i_src, tmp1, 4, i_height );
- mc_hh_w4( src+i_src, i_src, tmp2, 4, i_height );
- pixel_avg_w4( dst, i_dst, tmp1, 4, tmp2, 4, i_height );
-}
-static void mc_xy33_w8( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- uint8_t tmp1[16*8];
- uint8_t tmp2[16*8];
- mc_hv_w8( src+1, i_src, tmp1, 8, i_height );
- mc_hh_w8( src+i_src, i_src, tmp2, 8, i_height );
- pixel_avg_w8( dst, i_dst, tmp1, 8, tmp2, 8, i_height );
-}
-static void mc_xy33_w16( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- uint8_t tmp1[16*16];
- uint8_t tmp2[16*16];
- mc_hv_w16( src+1, i_src, tmp1, 16, i_height );
- mc_hh_w16( src+i_src, i_src, tmp2, 16, i_height );
- pixel_avg_w16( dst, i_dst, tmp1, 16, tmp2, 16, i_height );
-}
-
-static void mc_xy21_w4( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- uint8_t tmp1[16*4];
- uint8_t tmp2[16*4];
- mc_hc_w4( src, i_src, tmp1, 4, i_height );
- mc_hh_w4( src, i_src, tmp2, 4, i_height );
- pixel_avg_w4( dst, i_dst, tmp1, 4, tmp2, 4, i_height );
-}
-static void mc_xy21_w8( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- uint8_t tmp1[16*8];
- uint8_t tmp2[16*8];
- mc_hc_w8( src, i_src, tmp1, 8, i_height );
- mc_hh_w8( src, i_src, tmp2, 8, i_height );
- pixel_avg_w8( dst, i_dst, tmp1, 8, tmp2, 8, i_height );
-}
-static void mc_xy21_w16( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- uint8_t tmp1[16*16];
- uint8_t tmp2[16*16];
- mc_hc_w16( src, i_src, tmp1, 16, i_height );
- mc_hh_w16( src, i_src, tmp2, 16, i_height );
- pixel_avg_w16( dst, i_dst, tmp1, 16, tmp2, 16, i_height );
-}
-
-static void mc_xy12_w4( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- uint8_t tmp1[16*4];
- uint8_t tmp2[16*4];
- mc_hc_w4( src, i_src, tmp1, 4, i_height );
- mc_hv_w4( src, i_src, tmp2, 4, i_height );
- pixel_avg_w4( dst, i_dst, tmp1, 4, tmp2, 4, i_height );
-}
-static void mc_xy12_w8( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- uint8_t tmp1[16*8];
- uint8_t tmp2[16*8];
- mc_hc_w8( src, i_src, tmp1, 8, i_height );
- mc_hv_w8( src, i_src, tmp2, 8, i_height );
- pixel_avg_w8( dst, i_dst, tmp1, 8, tmp2, 8, i_height );
-}
-static void mc_xy12_w16( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- uint8_t tmp1[16*16];
- uint8_t tmp2[16*16];
- mc_hc_w16( src, i_src, tmp1, 16, i_height );
- mc_hv_w16( src, i_src, tmp2, 16, i_height );
- pixel_avg_w16( dst, i_dst, tmp1, 16, tmp2, 16, i_height );
-}
-
-static void mc_xy32_w4( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- uint8_t tmp1[16*4];
- uint8_t tmp2[16*4];
- mc_hc_w4( src, i_src, tmp1, 4, i_height );
- mc_hv_w4( src+1, i_src, tmp2, 4, i_height );
- pixel_avg_w4( dst, i_dst, tmp1, 4, tmp2, 4, i_height );
-}
-static void mc_xy32_w8( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- uint8_t tmp1[16*8];
- uint8_t tmp2[16*8];
- mc_hc_w8( src, i_src, tmp1, 8, i_height );
- mc_hv_w8( src+1, i_src, tmp2, 8, i_height );
- pixel_avg_w8( dst, i_dst, tmp1, 8, tmp2, 8, i_height );
-}
-static void mc_xy32_w16( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- uint8_t tmp1[16*16];
- uint8_t tmp2[16*16];
- mc_hc_w16( src, i_src, tmp1, 16, i_height );
- mc_hv_w16( src+1, i_src, tmp2, 16, i_height );
- pixel_avg_w16( dst, i_dst, tmp1, 16, tmp2, 16, i_height );
-}
-
-static void mc_xy23_w4( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- uint8_t tmp1[16*4];
- uint8_t tmp2[16*4];
- mc_hc_w4( src, i_src, tmp1, 4, i_height );
- mc_hh_w4( src+i_src, i_src, tmp2, 4, i_height );
- pixel_avg_w4( dst, i_dst, tmp1, 4, tmp2, 4, i_height );
-}
-static void mc_xy23_w8( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- uint8_t tmp1[16*8];
- uint8_t tmp2[16*8];
- mc_hc_w8( src, i_src, tmp1, 8, i_height );
- mc_hh_w8( src+i_src, i_src, tmp2, 8, i_height );
- pixel_avg_w8( dst, i_dst, tmp1, 8, tmp2, 8, i_height );
-}
-static void mc_xy23_w16( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- uint8_t tmp1[16*16];
- uint8_t tmp2[16*16];
- mc_hc_w16( src, i_src, tmp1, 16, i_height );
- mc_hh_w16( src+i_src, i_src, tmp2, 16, i_height );
- pixel_avg_w16( dst, i_dst, tmp1, 16, tmp2, 16, i_height );
-}
-
-static void motion_compensation_luma( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst,
- int mvx,int mvy,
- int i_width, int i_height )
-{
- static const pf_mc_t pf_mc[3][4][4] = /*XXX [dqy][dqx] */
- {
- {
- { mc_copy_w4, mc_xy10_w4, mc_hh_w4, mc_xy30_w4 },
- { mc_xy01_w4, mc_xy11_w4, mc_xy21_w4, mc_xy31_w4 },
- { mc_hv_w4, mc_xy12_w4, mc_hc_w4, mc_xy32_w4 },
- { mc_xy03_w4, mc_xy13_w4, mc_xy23_w4, mc_xy33_w4 },
- },
- {
- { mc_copy_w8, mc_xy10_w8, mc_hh_w8, mc_xy30_w8 },
- { mc_xy01_w8, mc_xy11_w8, mc_xy21_w8, mc_xy31_w8 },
- { mc_hv_w8, mc_xy12_w8, mc_hc_w8, mc_xy32_w8 },
- { mc_xy03_w8, mc_xy13_w8, mc_xy23_w8, mc_xy33_w8 },
- },
- {
- { mc_copy_w16, mc_xy10_w16, mc_hh_w16, mc_xy30_w16 },
- { mc_xy01_w16, mc_xy11_w16, mc_xy21_w16, mc_xy31_w16 },
- { mc_hv_w16, mc_xy12_w16, mc_hc_w16, mc_xy32_w16 },
- { mc_xy03_w16, mc_xy13_w16, mc_xy23_w16, mc_xy33_w16 },
- }
- };
-
- src += (mvy >> 2) * i_src + (mvx >> 2);
- if( i_width == 4 )
- {
- pf_mc[0][mvy&0x03][mvx&0x03]( src, i_src, dst, i_dst, i_height );
- }
- else if( i_width == 8 )
- {
- pf_mc[1][mvy&0x03][mvx&0x03]( src, i_src, dst, i_dst, i_height );
- }
- else if( i_width == 16 )
- {
- pf_mc[2][mvy&0x03][mvx&0x03]( src, i_src, dst, i_dst, i_height );
- }
-}
-
void mc_luma_altivec( uint8_t *src[4], int i_src_stride,
uint8_t *dst, int i_dst_stride,
int mvx, int mvy,
uint8_t *src1, *src2;
/* todo : fixme... */
- int correction = ((mvx&3) == 3 && (mvy&3) == 1 || (mvx&3) == 1 && (mvy&3) == 3) ? 1:0;
+ int correction = (((mvx&3) == 3 && (mvy&3) == 1) || ((mvx&3) == 1 && (mvy&3) == 3)) ? 1:0;
int hpel1x = mvx>>1;
int hpel1y = (mvy+1-correction)>>1;
uint8_t *src1, *src2;
/* todo : fixme... */
- int correction = ((mvx&3) == 3 && (mvy&3) == 1 || (mvx&3) == 1 && (mvy&3) == 3) ? 1:0;
+ int correction = (((mvx&3) == 3 && (mvy&3) == 1) || ((mvx&3) == 1 && (mvy&3) == 3)) ? 1:0;
int hpel1x = mvx>>1;
int hpel1y = (mvy+1-correction)>>1;
}
}
-static void mc_chroma_altivec( uint8_t *src, int i_src_stride,
- uint8_t *dst, int i_dst_stride,
- int mvx, int mvy,
- int i_width, int i_height )
+static void mc_chroma_c( uint8_t *src, int i_src_stride,
+ uint8_t *dst, int i_dst_stride,
+ int mvx, int mvy,
+ int i_width, int i_height )
{
uint8_t *srcp;
int x, y;
src += (mvy >> 3) * i_src_stride + (mvx >> 3);
srcp = &src[i_src_stride];
- if( i_width < 8 )
+ /* TODO: optimize */
+ for( y = 0; y < i_height; y++ )
{
- /* TODO: optimize */
- for( y = 0; y < i_height; y++ )
+ for( x = 0; x < i_width; x++ )
{
- for( x = 0; x < i_width; x++ )
- {
- dst[x] = ( coeff[0]*src[x] + coeff[1]*src[x+1] +
- coeff[2]*srcp[x] + coeff[3]*srcp[x+1] + 32 ) >> 6;
- }
- dst += i_dst_stride;
-
- src = srcp;
- srcp += i_src_stride;
+ dst[x] = ( coeff[0]*src[x] + coeff[1]*src[x+1] +
+ coeff[2]*srcp[x] + coeff[3]*srcp[x+1] + 32 ) >> 6;
}
- return;
+ dst += i_dst_stride;
+
+ src = srcp;
+ srcp += i_src_stride;
}
+}
+
+#define DO_PROCESS(a) \
+ src##a##v_16 = vec_u8_to_u16( src##a##v_8 ); \
+ src##a##v_16 = vec_mladd( coeff##a##v, src##a##v_16, zero_u16v ); \
+ dstv_16 = vec_add( dstv_16, src##a##v_16 )
+
+static void mc_chroma_altivec_4xh( uint8_t *src, int i_src_stride,
+ uint8_t *dst, int i_dst_stride,
+ int mvx, int mvy,
+ int i_height )
+{
+ uint8_t *srcp;
+ int y;
+ int d8x = mvx & 0x07;
+ int d8y = mvy & 0x07;
+
+ DECLARE_ALIGNED( uint16_t, coeff[4], 16 );
+ coeff[0] = (8-d8x)*(8-d8y);
+ coeff[1] = d8x *(8-d8y);
+ coeff[2] = (8-d8x)*d8y;
+ coeff[3] = d8x *d8y;
+
+ src += (mvy >> 3) * i_src_stride + (mvx >> 3);
+ srcp = &src[i_src_stride];
- /* We now assume that i_width == 8 */
LOAD_ZERO;
- vec_u16_t coeffv[4];
- vec_u16_t k32v;
- vec_u8_t srcv_8[4];
- vec_u16_t srcv_16[4];
+ PREP_LOAD;
+ PREP_STORE4;
+ vec_u16_t coeff0v, coeff1v, coeff2v, coeff3v;
+ vec_u8_t src0v_8, src1v_8, src2v_8, src3v_8;
+ vec_u16_t src0v_16, src1v_16, src2v_16, src3v_16;
vec_u8_t dstv_8;
vec_u16_t dstv_16;
vec_u8_t permv;
vec_u16_t shiftv;
+ vec_u16_t k32v;
- coeffv[0] = vec_ld( 0, coeff );
- coeffv[3] = vec_splat( coeffv[0], 3 );
- coeffv[2] = vec_splat( coeffv[0], 2 );
- coeffv[1] = vec_splat( coeffv[0], 1 );
- coeffv[0] = vec_splat( coeffv[0], 0 );
- k32v = vec_sl( vec_splat_u16( 1 ), vec_splat_u16( 5 ) );
- permv = vec_lvsl( 0, (uint8_t *) 1 );
- shiftv = vec_splat_u16( 6 );
-
- srcv_8[2] = vec_load16( src );
- srcv_8[3] = vec_perm( srcv_8[2], srcv_8[2], permv );
+ coeff0v = vec_ld( 0, coeff );
+ coeff3v = vec_splat( coeff0v, 3 );
+ coeff2v = vec_splat( coeff0v, 2 );
+ coeff1v = vec_splat( coeff0v, 1 );
+ coeff0v = vec_splat( coeff0v, 0 );
+ k32v = vec_sl( vec_splat_u16( 1 ), vec_splat_u16( 5 ) );
+ permv = vec_lvsl( 0, (uint8_t *) 1 );
+ shiftv = vec_splat_u16( 6 );
+
+ VEC_LOAD( src, src2v_8, 5 );
+ src3v_8 = vec_perm( src2v_8, src2v_8, permv );
for( y = 0; y < i_height; y++ )
{
- int i;
+ src0v_8 = src2v_8;
+ src1v_8 = src3v_8;
+ VEC_LOAD( srcp, src2v_8, 5 );
+ src3v_8 = vec_perm( src2v_8, src2v_8, permv );
+
+ dstv_16 = k32v;
+
+ DO_PROCESS( 0 );
+ DO_PROCESS( 1 );
+ DO_PROCESS( 2 );
+ DO_PROCESS( 3 );
+
+ dstv_16 = vec_sr( dstv_16, shiftv );
+ dstv_8 = vec_u16_to_u8( dstv_16 );
+ VEC_STORE4( dstv_8, dst );
+
+ dst += i_dst_stride;
+ srcp += i_src_stride;
+ }
+}
+
+static void mc_chroma_altivec_8xh( uint8_t *src, int i_src_stride,
+ uint8_t *dst, int i_dst_stride,
+ int mvx, int mvy,
+ int i_height )
+{
+ uint8_t *srcp;
+ int y;
+ int d8x = mvx & 0x07;
+ int d8y = mvy & 0x07;
+
+ DECLARE_ALIGNED( uint16_t, coeff[4], 16 );
+ coeff[0] = (8-d8x)*(8-d8y);
+ coeff[1] = d8x *(8-d8y);
+ coeff[2] = (8-d8x)*d8y;
+ coeff[3] = d8x *d8y;
- srcv_8[0] = srcv_8[2];
- srcv_8[1] = srcv_8[3];
- srcv_8[2] = vec_load16( srcp );
- srcv_8[3] = vec_perm( srcv_8[2], srcv_8[2], permv );
+ src += (mvy >> 3) * i_src_stride + (mvx >> 3);
+ srcp = &src[i_src_stride];
+
+ LOAD_ZERO;
+ PREP_LOAD;
+ PREP_STORE8;
+ vec_u16_t coeff0v, coeff1v, coeff2v, coeff3v;
+ vec_u8_t src0v_8, src1v_8, src2v_8, src3v_8;
+ vec_u16_t src0v_16, src1v_16, src2v_16, src3v_16;
+ vec_u8_t dstv_8;
+ vec_u16_t dstv_16;
+ vec_u8_t permv;
+ vec_u16_t shiftv;
+ vec_u16_t k32v;
+
+ coeff0v = vec_ld( 0, coeff );
+ coeff3v = vec_splat( coeff0v, 3 );
+ coeff2v = vec_splat( coeff0v, 2 );
+ coeff1v = vec_splat( coeff0v, 1 );
+ coeff0v = vec_splat( coeff0v, 0 );
+ k32v = vec_sl( vec_splat_u16( 1 ), vec_splat_u16( 5 ) );
+ permv = vec_lvsl( 0, (uint8_t *) 1 );
+ shiftv = vec_splat_u16( 6 );
+
+ VEC_LOAD( src, src2v_8, 9 );
+ src3v_8 = vec_perm( src2v_8, src2v_8, permv );
+
+ for( y = 0; y < i_height; y++ )
+ {
+ src0v_8 = src2v_8;
+ src1v_8 = src3v_8;
+ VEC_LOAD( srcp, src2v_8, 9 );
+ src3v_8 = vec_perm( src2v_8, src2v_8, permv );
dstv_16 = k32v;
- for( i = 0; i < 4; i++ )
- {
- srcv_16[i] = vec_u8_to_u16( srcv_8[i] );
- srcv_16[i] = vec_mladd( coeffv[i], srcv_16[i], zero_u16v );
- dstv_16 = vec_add( dstv_16, srcv_16[i] );
- }
+
+ DO_PROCESS( 0 );
+ DO_PROCESS( 1 );
+ DO_PROCESS( 2 );
+ DO_PROCESS( 3 );
+
dstv_16 = vec_sr( dstv_16, shiftv );
dstv_8 = vec_u16_to_u8( dstv_16 );
- vec_store8( dstv_8, dst );
+ VEC_STORE8( dstv_8, dst );
dst += i_dst_stride;
srcp += i_src_stride;
}
}
+static void mc_chroma_altivec( uint8_t *src, int i_src_stride,
+ uint8_t *dst, int i_dst_stride,
+ int mvx, int mvy,
+ int i_width, int i_height )
+{
+ if( i_width == 8 )
+ {
+ mc_chroma_altivec_8xh( src, i_src_stride, dst, i_dst_stride,
+ mvx, mvy, i_height );
+ return;
+ }
+ if( i_width == 4 )
+ {
+ mc_chroma_altivec_4xh( src, i_src_stride, dst, i_dst_stride,
+ mvx, mvy, i_height );
+ return;
+ }
+
+ mc_chroma_c( src, i_src_stride, dst, i_dst_stride,
+ mvx, mvy, i_width, i_height );
+}
+
void x264_mc_altivec_init( x264_mc_functions_t *pf )
{
pf->mc_luma = mc_luma_altivec;
DECLARE_ALIGNED( int, sum, 16 ); \
\
LOAD_ZERO; \
+ PREP_LOAD; \
vec_u8_t pix1v, pix2v; \
vec_s32_t sumv = zero_s32v; \
for( y = 0; y < ly; y++ ) \
{ \
- pix1v = vec_load##lx( pix1 ); \
- pix2v = vec_load##lx( pix2 ); \
+ VEC_LOAD( pix1, pix1v, lx ); \
+ VEC_LOAD( pix2, pix2v, lx ); \
sumv = (vec_s32_t) vec_sum4s( \
vec_sub( vec_max( pix1v, pix2v ), \
vec_min( pix1v, pix2v ) ), \
PIXEL_SAD_ALTIVEC( pixel_sad_8x8_altivec, 8, 8, 2s, 1 )
/* satd routines */
-static inline int pixel_satd_8x8_altivec( uint8_t *pix1, int i_pix1,
+
+#define DO_DIFF(a,b) \
+ VEC_LOAD( pix1, pix1v, b ); \
+ pix1v = vec_u8_to_s16( pix1v ); \
+ VEC_LOAD( pix2, pix2v, b ); \
+ pix2v = vec_u8_to_s16( pix2v ); \
+ diff##a##v = vec_sub( pix1v, pix2v ); \
+ pix1 += i_pix1; \
+ pix2 += i_pix2
+
+#define ADD_ABS_TO_SATD(a,b) \
+ temp##a##v = vec_abs( temp##a##v ); \
+ satdv = vec_sum4s( temp##a##v, b )
+
+static inline int pixel_satd_4x4_altivec( uint8_t *pix1, int i_pix1,
uint8_t *pix2, int i_pix2 )
{
- int i;
DECLARE_ALIGNED( int, i_satd, 16 );
LOAD_ZERO;
- vec_s32_t satdv = zero_s32v;
- vec_u8_t pix1u8v, pix2u8v;
- vec_s16_t pix1s16v, pix2s16v;
- vec_s16_t diffv[8];
- vec_s16_t tmpv[8];
+ PREP_LOAD;
+ vec_s16_t pix1v, pix2v;
+ vec_s16_t diff0v, diff1v, diff2v, diff3v;
+ vec_s16_t temp0v, temp1v, temp2v, temp3v;
+ vec_s32_t satdv;
- /* Diff 8x8 */
- for( i = 0; i < 8; i++ )
- {
- pix1u8v = vec_load8( pix1 );
- pix2u8v = vec_load8( pix2 );
+ DO_DIFF( 0, 4 );
+ DO_DIFF( 1, 4 );
+ DO_DIFF( 2, 4 );
+ DO_DIFF( 3, 4 );
- pix1s16v = vec_u8_to_s16( pix1u8v );
- pix2s16v = vec_u8_to_s16( pix2u8v );
+ /* Hadamar H */
+ vec_hadamar( diff0v, diff1v, diff2v, diff3v,
+ temp0v, temp1v, temp2v, temp3v );
+
+ vec_transpose4x4( temp0v, temp1v, temp2v, temp3v,
+ diff0v, diff1v, diff2v, diff3v );
+ /* Hadamar V */
+ vec_hadamar( diff0v, diff1v, diff2v, diff3v,
+ temp0v, temp1v, temp2v, temp3v );
+
+ ADD_ABS_TO_SATD( 0, zero_s32v );
+ ADD_ABS_TO_SATD( 1, satdv );
+ ADD_ABS_TO_SATD( 2, satdv );
+ ADD_ABS_TO_SATD( 3, satdv );
+
+ satdv = vec_sum2s( satdv, zero_s32v );
+ satdv = vec_splat( satdv, 1 );
+ vec_ste( satdv, 0, &i_satd );
+
+ return i_satd / 2;
+}
- diffv[i] = vec_sub( pix1s16v, pix2s16v );
+static inline int pixel_satd_8x8_altivec( uint8_t *pix1, int i_pix1,
+ uint8_t *pix2, int i_pix2 )
+{
+ DECLARE_ALIGNED( int, i_satd, 16 );
- pix1 += i_pix1;
- pix2 += i_pix2;
- }
+ LOAD_ZERO;
+ PREP_LOAD;
+ vec_s32_t satdv;
+ vec_s16_t pix1v, pix2v;
+ vec_s16_t diff0v, diff1v, diff2v, diff3v,
+ diff4v, diff5v, diff6v, diff7v;
+ vec_s16_t temp0v, temp1v, temp2v, temp3v,
+ temp4v, temp5v, temp6v, temp7v;
+
+ DO_DIFF( 0, 8 );
+ DO_DIFF( 1, 8 );
+ DO_DIFF( 2, 8 );
+ DO_DIFF( 3, 8 );
+ DO_DIFF( 4, 8 );
+ DO_DIFF( 5, 8 );
+ DO_DIFF( 6, 8 );
+ DO_DIFF( 7, 8 );
/* Hadamar H */
- vec_hadamar( &diffv[0], &tmpv[0] );
- vec_hadamar( &diffv[4], &tmpv[4] );
+ vec_hadamar( diff0v, diff1v, diff2v, diff3v,
+ temp0v, temp1v, temp2v, temp3v );
+ vec_hadamar( diff4v, diff5v, diff6v, diff7v,
+ temp4v, temp5v, temp6v, temp7v );
- /* Transpose */
- vec_transpose8x8( tmpv, diffv );
+ vec_transpose8x8( temp0v, temp1v, temp2v, temp3v,
+ temp4v, temp5v, temp6v, temp7v,
+ diff0v, diff1v, diff2v, diff3v,
+ diff4v, diff5v, diff6v, diff7v );
/* Hadamar V */
- vec_hadamar( &diffv[0], &tmpv[0] );
- vec_hadamar( &diffv[4], &tmpv[4] );
-
- /* Sum of absolute values */
- for( i = 0; i < 8; i++ )
- {
- satdv = vec_sum4s( vec_abs( tmpv[i] ), satdv );
- }
+ vec_hadamar( diff0v, diff1v, diff2v, diff3v,
+ temp0v, temp1v, temp2v, temp3v );
+ vec_hadamar( diff4v, diff5v, diff6v, diff7v,
+ temp4v, temp5v, temp6v, temp7v );
+
+ ADD_ABS_TO_SATD( 0, zero_s32v );
+ ADD_ABS_TO_SATD( 1, satdv );
+ ADD_ABS_TO_SATD( 2, satdv );
+ ADD_ABS_TO_SATD( 3, satdv );
+ ADD_ABS_TO_SATD( 4, satdv );
+ ADD_ABS_TO_SATD( 5, satdv );
+ ADD_ABS_TO_SATD( 6, satdv );
+ ADD_ABS_TO_SATD( 7, satdv );
+
satdv = vec_sums( satdv, zero_s32v );
+ satdv = vec_splat( satdv, 3 );
+ vec_ste( satdv, 0, &i_satd );
- /* Done */
- vec_ste( vec_splat( satdv, 3 ), 0, &i_satd );
return i_satd / 2;
}
-static int pixel_satd_16x8_altivec( uint8_t *pix1, int i_pix1,
- uint8_t *pix2, int i_pix2 )
+static int pixel_satd_8x4_altivec( uint8_t *pix1, int i_pix1,
+ uint8_t *pix2, int i_pix2 )
+{
+ return pixel_satd_4x4_altivec( &pix1[0], i_pix1,
+ &pix2[0], i_pix2 ) +
+ pixel_satd_4x4_altivec( &pix1[4], i_pix1,
+ &pix2[4], i_pix2 );
+}
+
+static int pixel_satd_4x8_altivec( uint8_t *pix1, int i_pix1,
+ uint8_t *pix2, int i_pix2 )
+{
+ return pixel_satd_4x4_altivec( &pix1[0], i_pix1,
+ &pix2[0], i_pix2 ) +
+ pixel_satd_4x4_altivec( &pix1[4*i_pix1], i_pix1,
+ &pix2[4*i_pix2], i_pix2 );
+}
+static inline int pixel_satd_16x8_altivec( uint8_t *pix1, int i_pix1,
+ uint8_t *pix2, int i_pix2 )
{
return pixel_satd_8x8_altivec( &pix1[0], i_pix1,
&pix2[0], i_pix2 ) +
static int pixel_satd_16x16_altivec( uint8_t *pix1, int i_pix1,
uint8_t *pix2, int i_pix2 )
{
- return pixel_satd_8x8_altivec( &pix1[0], i_pix1,
- &pix2[0], i_pix2 ) +
- pixel_satd_8x8_altivec( &pix1[8], i_pix1,
- &pix2[8], i_pix2 ) +
- pixel_satd_8x8_altivec( &pix1[8*i_pix1], i_pix1,
- &pix2[8*i_pix2], i_pix2 ) +
- pixel_satd_8x8_altivec( &pix1[8*i_pix1+8], i_pix1,
- &pix2[8*i_pix2+8], i_pix2 );
-}
-
-static inline int pixel_satd_4x4_altivec( uint8_t *pix1, int i_pix1,
- uint8_t *pix2, int i_pix2 )
-{
- int i;
- DECLARE_ALIGNED( int, i_satd, 16 );
-
- LOAD_ZERO;
- vec_s32_t satdv = zero_s32v;
- vec_u8_t pix1u8v, pix2u8v;
- vec_s16_t pix1s16v, pix2s16v;
- vec_s16_t diffv[4];
- vec_s16_t tmpv[4];
-
- /* Diff 4x8 */
- for( i = 0; i < 4; i++ )
- {
- pix1u8v = vec_load4( pix1 );
- pix2u8v = vec_load4( pix2 );
-
- pix1s16v = vec_u8_to_s16( pix1u8v );
- pix2s16v = vec_u8_to_s16( pix2u8v );
-
- diffv[i] = vec_sub( pix1s16v, pix2s16v );
-
- pix1 += i_pix1;
- pix2 += i_pix2;
- }
-
- /* Hadamar H */
- vec_hadamar( diffv, tmpv );
-
- /* Transpose */
- vec_transpose4x4( tmpv, diffv );
-
- /* Hadamar V */
- vec_hadamar( diffv, tmpv );
-
- /* Sum of absolute values */
- for( i = 0; i < 4; i++ )
- {
- satdv = vec_sum4s( vec_abs( tmpv[i] ), satdv );
- }
- satdv = vec_sum2s( satdv, zero_s32v );
-
- /* Done */
- vec_ste( vec_splat( satdv, 1 ), 0, &i_satd );
- return i_satd / 2;
+ return pixel_satd_16x8_altivec( &pix1[0], i_pix1,
+ &pix2[0], i_pix2 ) +
+ pixel_satd_16x8_altivec( &pix1[8*i_pix1], i_pix1,
+ &pix2[8*i_pix2], i_pix2 );
}
/****************************************************************************
pixf->satd[PIXEL_8x16] = pixel_satd_8x16_altivec;
pixf->satd[PIXEL_16x8] = pixel_satd_16x8_altivec;
pixf->satd[PIXEL_8x8] = pixel_satd_8x8_altivec;
+ pixf->satd[PIXEL_8x4] = pixel_satd_8x4_altivec;
+ pixf->satd[PIXEL_4x8] = pixel_satd_4x8_altivec;
pixf->satd[PIXEL_4x4] = pixel_satd_4x4_altivec;
}
/***********************************************************************
* Null vector
**********************************************************************/
-#define LOAD_ZERO vec_u8_t zerov = vec_splat_u8( 0 )
+#define LOAD_ZERO const vec_u8_t zerov = vec_splat_u8( 0 )
#define zero_u8v (vec_u8_t) zerov
#define zero_s8v (vec_s8_t) zerov
#define zero_s32v (vec_s32_t) zerov
/***********************************************************************
- * Conversions
+ * 8 <-> 16 bits conversions
**********************************************************************/
-static inline vec_u16_t vec_u8_to_u16( vec_u8_t v )
-{
- LOAD_ZERO;
- return (vec_u16_t) vec_mergeh( zero_u8v, v );
-}
-static inline vec_u8_t vec_u16_to_u8( vec_u16_t v )
-{
- LOAD_ZERO;
- return (vec_u8_t) vec_pack( v, zero_u16v );
-}
-#define vec_u8_to_s16(v) (vec_s16_t) vec_u8_to_u16(v)
-#define vec_s16_to_u8(v) vec_u16_to_u8( (vec_u16_t) v )
+#define vec_u8_to_u16_h(v) (vec_u16_t) vec_mergeh( zero_u8v, (vec_u8_t) v )
+#define vec_u8_to_u16_l(v) (vec_u16_t) vec_mergel( zero_u8v, (vec_u8_t) v )
+#define vec_u8_to_s16_h(v) (vec_s16_t) vec_mergeh( zero_u8v, (vec_u8_t) v )
+#define vec_u8_to_s16_l(v) (vec_s16_t) vec_mergel( zero_u8v, (vec_u8_t) v )
-/***********************************************************************
- * vec_load16
- **********************************************************************/
-static inline vec_u8_t vec_load16( uint8_t * p )
-{
- if( (long) p & 0xF )
- {
- vec_u8_t hv, lv, perm;
- hv = vec_ld( 0, p );
- lv = vec_ld( 16, p );
- perm = vec_lvsl( 0, p );
- return vec_perm( hv, lv, perm );
- }
- return vec_ld( 0, p );
-}
-
-/***********************************************************************
- * vec_load8
- **********************************************************************/
-static inline vec_u8_t vec_load8( uint8_t * p )
-{
- long align = (long) p & 0xF;
+#define vec_u8_to_u16(v) vec_u8_to_u16_h(v)
+#define vec_u8_to_s16(v) vec_u8_to_s16_h(v)
- if( align )
- {
- vec_u8_t hv, perm;
- hv = vec_ld( 0, p );
- perm = vec_lvsl( 0, p );
- if( align > 8 )
- {
- vec_u8_t lv;
- lv = vec_ld( 16, p );
- return vec_perm( hv, lv, perm );
- }
- return vec_perm( hv, hv, perm );
- }
- return vec_ld( 0, p );
-}
+#define vec_u16_to_u8(v) vec_pack( v, zero_u16v )
+#define vec_s16_to_u8(v) vec_pack( v, zero_u16v )
/***********************************************************************
- * vec_load4
+ * PREP_LOAD: declares two vectors required to perform unaligned loads
+ * VEC_LOAD: loads n bytes from address p into vector v
**********************************************************************/
-static inline vec_u8_t vec_load4( uint8_t * p )
-{
- long align = (long) p & 0xF;
+#define PREP_LOAD \
+ vec_u8_t _hv, _lv
- if( align )
- {
- vec_u8_t hv, perm;
- hv = vec_ld( 0, p );
- perm = vec_lvsl( 0, p );
- if( align > 12 )
- {
- vec_u8_t lv;
- lv = vec_ld( 16, p );
- return vec_perm( hv, lv, perm );
- }
- return vec_perm( hv, hv, perm );
- }
- return vec_ld( 0, p );
-}
+#define VEC_LOAD( p, v, n ) \
+ _hv = vec_ld( 0, p ); \
+ v = vec_lvsl( 0, p ); \
+ _lv = vec_ld( n - 1, p ); \
+ v = vec_perm( _hv, _lv, v )
/***********************************************************************
- * vec_store16
+ * PREP_STORE##n: declares required vectors to store n bytes to a
+ * potentially unaligned address
+ * VEC_STORE##n: stores n bytes from vector v to address p
**********************************************************************/
-static inline void vec_store16( vec_u8_t v, uint8_t * p )
-{
- if( (long) p & 0xF )
- {
- vec_u8_t hv, lv, tmp1, tmp2;
- hv = vec_ld( 0, p );
- lv = vec_ld( 16, p );
- tmp2 = vec_lvsl( 0, p );
- tmp1 = vec_perm( lv, hv, tmp2 );
- tmp2 = vec_lvsr( 0, p );
- hv = vec_perm( tmp1, v, tmp2 );
- lv = vec_perm( v, tmp1, tmp2 );
- vec_st( lv, 16, p );
- vec_st( hv, 0, p );
- return;
- }
- vec_st( v, 0, p );
-}
-
-/***********************************************************************
- * vec_store8
- **********************************************************************/
-static inline void vec_store8( vec_u8_t v, uint8_t * p )
-{
- LOAD_ZERO;
- long align;
- vec_u8_t hv, sel;
-
- align = (long) p & 0xF;
- hv = vec_ld( 0, p );
- sel = (vec_u8_t) CV(-1,-1,-1,-1,-1,-1,-1,-1,0,0,0,0,0,0,0,0);
-
- if( align )
- {
- vec_u8_t perm;
- perm = vec_lvsr( 0, p );
- v = vec_perm( v, v, perm );
- if( align > 8 )
- {
- vec_u8_t lv, hsel, lsel;
- lv = vec_ld( 16, p );
- hsel = vec_perm( zero_u8v, sel, perm );
- lsel = vec_perm( sel, zero_u8v, perm );
- hv = vec_sel( hv, v, hsel );
- lv = vec_sel( lv, v, lsel );
- vec_st( lv, 16, p );
- }
- else
- {
- sel = vec_perm( sel, sel, perm );
- hv = vec_sel( hv, v, sel );
- }
- }
- else
- {
- hv = vec_sel( hv, v, sel );
- }
- vec_st( hv, 0, p );
-}
+#define PREP_STORE16 \
+ vec_u8_t _tmp1v, _tmp2v \
+
+#define VEC_STORE16( v, p ) \
+ _hv = vec_ld( 0, p ); \
+ _tmp2v = vec_lvsl( 0, p ); \
+ _lv = vec_ld( 15, p ); \
+ _tmp1v = vec_perm( _lv, _hv, _tmp2v ); \
+ _tmp2v = vec_lvsr( 0, p ); \
+ _lv = vec_perm( v, _tmp1v, _tmp2v ); \
+ vec_st( _lv, 15, p ); \
+ _hv = vec_perm( _tmp1v, v, _tmp2v ); \
+ vec_st( _hv, 0, p )
+
+#define PREP_STORE8 \
+ PREP_STORE16; \
+ vec_u8_t _tmp3v; \
+ const vec_u8_t sel = \
+ (vec_u8_t) CV(-1,-1,-1,-1,-1,-1,-1,-1,0,0,0,0,0,0,0,0)
+
+#define VEC_STORE8( v, p ) \
+ _tmp3v = vec_lvsr( 0, p ); \
+ v = vec_perm( v, v, _tmp3v ); \
+ _lv = vec_ld( 7, p ); \
+ _tmp1v = vec_perm( sel, zero_u8v, _tmp3v ); \
+ _lv = vec_sel( _lv, v, _tmp1v ); \
+ vec_st( _lv, 7, p ); \
+ _hv = vec_ld( 0, p ); \
+ _tmp2v = vec_perm( zero_u8v, sel, _tmp3v ); \
+ _hv = vec_sel( _hv, v, _tmp2v ); \
+ vec_st( _hv, 0, p )
+
+#define PREP_STORE4 \
+ PREP_STORE16; \
+ vec_u8_t _tmp3v; \
+ const vec_u8_t sel = \
+ (vec_u8_t) CV(-1,-1,-1,-1,0,0,0,0,0,0,0,0,0,0,0,0)
+
+#define VEC_STORE4( v, p ) \
+ _tmp3v = vec_lvsr( 0, p ); \
+ v = vec_perm( v, v, _tmp3v ); \
+ _lv = vec_ld( 3, p ); \
+ _tmp1v = vec_perm( sel, zero_u8v, _tmp3v ); \
+ _lv = vec_sel( _lv, v, _tmp1v ); \
+ vec_st( _lv, 3, p ); \
+ _hv = vec_ld( 0, p ); \
+ _tmp2v = vec_perm( zero_u8v, sel, _tmp3v ); \
+ _hv = vec_sel( _hv, v, _tmp2v ); \
+ vec_st( _hv, 0, p )
/***********************************************************************
* vec_transpose8x8
**********************************************************************/
-static inline void vec_transpose8x8( vec_s16_t * a, vec_s16_t * b )
-{
- b[0] = vec_mergeh( a[0], a[4] );
- b[1] = vec_mergel( a[0], a[4] );
- b[2] = vec_mergeh( a[1], a[5] );
- b[3] = vec_mergel( a[1], a[5] );
- b[4] = vec_mergeh( a[2], a[6] );
- b[5] = vec_mergel( a[2], a[6] );
- b[6] = vec_mergeh( a[3], a[7] );
- b[7] = vec_mergel( a[3], a[7] );
- a[0] = vec_mergeh( b[0], b[4] );
- a[1] = vec_mergel( b[0], b[4] );
- a[2] = vec_mergeh( b[1], b[5] );
- a[3] = vec_mergel( b[1], b[5] );
- a[4] = vec_mergeh( b[2], b[6] );
- a[5] = vec_mergel( b[2], b[6] );
- a[6] = vec_mergeh( b[3], b[7] );
- a[7] = vec_mergel( b[3], b[7] );
- b[0] = vec_mergeh( a[0], a[4] );
- b[1] = vec_mergel( a[0], a[4] );
- b[2] = vec_mergeh( a[1], a[5] );
- b[3] = vec_mergel( a[1], a[5] );
- b[4] = vec_mergeh( a[2], a[6] );
- b[5] = vec_mergel( a[2], a[6] );
- b[6] = vec_mergeh( a[3], a[7] );
- b[7] = vec_mergel( a[3], a[7] );
-}
+#define vec_transpose8x8(a0,a1,a2,a3,a4,a5,a6,a7,b0,b1,b2,b3,b4,b5,b6,b7) \
+ b0 = vec_mergeh( a0, a4 ); \
+ b1 = vec_mergel( a0, a4 ); \
+ b2 = vec_mergeh( a1, a5 ); \
+ b3 = vec_mergel( a1, a5 ); \
+ b4 = vec_mergeh( a2, a6 ); \
+ b5 = vec_mergel( a2, a6 ); \
+ b6 = vec_mergeh( a3, a7 ); \
+ b7 = vec_mergel( a3, a7 ); \
+ a0 = vec_mergeh( b0, b4 ); \
+ a1 = vec_mergel( b0, b4 ); \
+ a2 = vec_mergeh( b1, b5 ); \
+ a3 = vec_mergel( b1, b5 ); \
+ a4 = vec_mergeh( b2, b6 ); \
+ a5 = vec_mergel( b2, b6 ); \
+ a6 = vec_mergeh( b3, b7 ); \
+ a7 = vec_mergel( b3, b7 ); \
+ b0 = vec_mergeh( a0, a4 ); \
+ b1 = vec_mergel( a0, a4 ); \
+ b2 = vec_mergeh( a1, a5 ); \
+ b3 = vec_mergel( a1, a5 ); \
+ b4 = vec_mergeh( a2, a6 ); \
+ b5 = vec_mergel( a2, a6 ); \
+ b6 = vec_mergeh( a3, a7 ); \
+ b7 = vec_mergel( a3, a7 )
/***********************************************************************
* vec_transpose4x4
**********************************************************************/
-static inline void vec_transpose4x4( vec_s16_t * a, vec_s16_t * b )
-{
-#define WHATEVER a[0]
- b[0] = vec_mergeh( a[0], WHATEVER );
- b[1] = vec_mergeh( a[1], WHATEVER );
- b[2] = vec_mergeh( a[2], WHATEVER );
- b[3] = vec_mergeh( a[3], WHATEVER );
- a[0] = vec_mergeh( b[0], b[2] );
- a[1] = vec_mergel( b[0], b[2] );
- a[2] = vec_mergeh( b[1], b[3] );
- a[3] = vec_mergel( b[1], b[3] );
- b[0] = vec_mergeh( a[0], a[2] );
- b[1] = vec_mergel( a[0], a[2] );
- b[2] = vec_mergeh( a[1], a[3] );
- b[3] = vec_mergel( a[1], a[3] );
-#undef WHATEVER
-}
+#define vec_transpose4x4(a0,a1,a2,a3,b0,b1,b2,b3) \
+ b0 = vec_mergeh( a0, a0 ); \
+ b1 = vec_mergeh( a1, a0 ); \
+ b2 = vec_mergeh( a2, a0 ); \
+ b3 = vec_mergeh( a3, a0 ); \
+ a0 = vec_mergeh( b0, b2 ); \
+ a1 = vec_mergel( b0, b2 ); \
+ a2 = vec_mergeh( b1, b3 ); \
+ a3 = vec_mergel( b1, b3 ); \
+ b0 = vec_mergeh( a0, a2 ); \
+ b1 = vec_mergel( a0, a2 ); \
+ b2 = vec_mergeh( a1, a3 ); \
+ b3 = vec_mergel( a1, a3 )
/***********************************************************************
* vec_hadamar
* b[2] = a[0] - a[1] - a[2] + a[3]
* b[3] = a[0] - a[1] + a[2] - a[3]
**********************************************************************/
-static inline void vec_hadamar( vec_s16_t * a, vec_s16_t * b )
-{
- b[2] = vec_add( a[0], a[1] );
- b[3] = vec_add( a[2], a[3] );
- a[0] = vec_sub( a[0], a[1] );
- a[2] = vec_sub( a[2], a[3] );
- b[0] = vec_add( b[2], b[3] );
- b[1] = vec_sub( b[2], b[3] );
- b[2] = vec_sub( a[0], a[2] );
- b[3] = vec_add( a[0], a[2] );
-}
+#define vec_hadamar(a0,a1,a2,a3,b0,b1,b2,b3) \
+ b2 = vec_add( a0, a1 ); \
+ b3 = vec_add( a2, a3 ); \
+ a0 = vec_sub( a0, a1 ); \
+ a2 = vec_sub( a2, a3 ); \
+ b0 = vec_add( b2, b3 ); \
+ b1 = vec_sub( b2, b3 ); \
+ b2 = vec_sub( a0, a2 ); \
+ b3 = vec_add( a0, a2 )
+