predict.c 6.86 KB
Newer Older
1
/*****************************************************************************
2
 * predict.c: ppc intra prediction
3
 *****************************************************************************
Anton Mitrofanov's avatar
Anton Mitrofanov committed
4
 * Copyright (C) 2007-2015 x264 project
5 6
 *
 * Authors: Guillaume Poirier <gpoirier@mplayerhq.hu>
7 8 9 10 11 12 13 14 15 16 17 18 19
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111, USA.
21 22 23
 *
 * This program is also available under a commercial proprietary license.
 * For more information, contact us at licensing@x264.com.
24 25 26 27 28 29 30
 *****************************************************************************/

#include "common/common.h"
#include "predict.h"
#include "pixel.h"
#include "ppccommon.h"

31
#if !HIGH_BIT_DEPTH
32 33
static void predict_8x8c_p_altivec( uint8_t *src )
{
34
    int H = 0, V = 0;
35

36
    for( int i = 0; i < 4; i++ )
37 38 39 40 41
    {
        H += ( i + 1 ) * ( src[4+i - FDEC_STRIDE] - src[2 - i -FDEC_STRIDE] );
        V += ( i + 1 ) * ( src[-1 +(i+4)*FDEC_STRIDE] - src[-1+(2-i)*FDEC_STRIDE] );
    }

42 43 44 45
    int a = 16 * ( src[-1+7*FDEC_STRIDE] + src[7 - FDEC_STRIDE] );
    int b = ( 17 * H + 16 ) >> 5;
    int c = ( 17 * V + 16 ) >> 5;
    int i00 = a -3*b -3*c + 16;
46 47 48 49 50 51 52 53 54 55 56 57 58

    vec_s16_u i00_u, b_u, c_u;
    i00_u.s[0] = i00;
    b_u.s[0]   = b;
    c_u.s[0]   = c;

    vec_u16_t val5_v = vec_splat_u16(5);
    vec_s16_t i00_v, b_v, c_v;
    i00_v = vec_splat(i00_u.v, 0);
    b_v = vec_splat(b_u.v, 0);
    c_v = vec_splat(c_u.v, 0);

    vec_s16_t induc_v  = (vec_s16_t) CV(0, 1, 2, 3, 4, 5, 6, 7);
59
    vec_s16_t add_i0_b_0v = vec_mladd(induc_v, b_v, i00_v);
60 61 62

    PREP_STORE8;

63
    for( int i = 0; i < 8; ++i )
64 65 66 67 68 69 70 71 72 73 74
    {
        vec_s16_t shift_0_v = vec_sra(add_i0_b_0v, val5_v);
        vec_u8_t com_sat_v = vec_packsu(shift_0_v, shift_0_v);
        VEC_STORE8(com_sat_v, &src[0]);
        src += FDEC_STRIDE;
        add_i0_b_0v = vec_adds(add_i0_b_0v, c_v);

    }
}


75 76 77 78
/****************************************************************************
 * 16x16 prediction for intra luma block
 ****************************************************************************/

79 80
static void predict_16x16_p_altivec( uint8_t *src )
{
81
    int H = 0, V = 0;
82

83
    for( int i = 1; i <= 8; i++ )
84 85 86 87 88
    {
        H += i * ( src[7+i - FDEC_STRIDE ]  - src[7-i - FDEC_STRIDE ] );
        V += i * ( src[(7+i)*FDEC_STRIDE -1] - src[(7-i)*FDEC_STRIDE -1] );
    }

89 90 91 92
    int a = 16 * ( src[15*FDEC_STRIDE -1] + src[15 - FDEC_STRIDE] );
    int b = ( 5 * H + 32 ) >> 6;
    int c = ( 5 * V + 32 ) >> 6;
    int i00 = a - b * 7 - c * 7 + 16;
93

94
    vec_s16_u i00_u, b_u, c_u;
95 96 97 98 99 100 101 102 103 104 105
    i00_u.s[0] = i00;
    b_u.s[0]   = b;
    c_u.s[0]   = c;

    vec_u16_t val5_v = vec_splat_u16(5);
    vec_s16_t i00_v, b_v, c_v;
    i00_v = vec_splat(i00_u.v, 0);
    b_v = vec_splat(b_u.v, 0);
    c_v = vec_splat(c_u.v, 0);
    vec_s16_t induc_v  = (vec_s16_t) CV(0,  1,  2,  3,  4,  5,  6,  7);
    vec_s16_t b8_v = vec_sl(b_v, vec_splat_u16(3));
106
    vec_s16_t add_i0_b_0v = vec_mladd(induc_v, b_v, i00_v);
107 108
    vec_s16_t add_i0_b_8v = vec_adds(b8_v, add_i0_b_0v);

109
    for( int y = 0; y < 16; y++ )
110 111 112 113 114 115 116 117 118 119 120
    {
        vec_s16_t shift_0_v = vec_sra(add_i0_b_0v, val5_v);
        vec_s16_t shift_8_v = vec_sra(add_i0_b_8v, val5_v);
        vec_u8_t com_sat_v = vec_packsu(shift_0_v, shift_8_v);
        vec_st( com_sat_v, 0, &src[0]);
        src += FDEC_STRIDE;
        add_i0_b_0v = vec_adds(add_i0_b_0v, c_v);
        add_i0_b_8v = vec_adds(add_i0_b_8v, c_v);
    }
}

121
#define PREDICT_16x16_DC_ALTIVEC(v) \
122
for( int i = 0; i < 16; i += 2)     \
123 124 125 126 127 128 129 130 131 132
{                                   \
    vec_st(v, 0, src);              \
    vec_st(v, FDEC_STRIDE, src);    \
    src += FDEC_STRIDE*2;           \
}

static void predict_16x16_dc_altivec( uint8_t *src )
{
    uint32_t dc = 0;

133
    for( int i = 0; i < 16; i++ )
134 135 136 137 138 139 140 141 142 143 144 145 146 147
    {
        dc += src[-1 + i * FDEC_STRIDE];
        dc += src[i - FDEC_STRIDE];
    }
    vec_u8_u v ; v.s[0] = (( dc + 16 ) >> 5);
    vec_u8_t bc_v = vec_splat(v.v, 0);

    PREDICT_16x16_DC_ALTIVEC(bc_v);
}

static void predict_16x16_dc_left_altivec( uint8_t *src )
{
    uint32_t dc = 0;

148
    for( int i = 0; i < 16; i++ )
149 150 151 152 153 154 155 156 157 158 159
        dc += src[-1 + i * FDEC_STRIDE];
    vec_u8_u v ; v.s[0] = (( dc + 8 ) >> 4);
    vec_u8_t bc_v = vec_splat(v.v, 0);

    PREDICT_16x16_DC_ALTIVEC(bc_v);
}

static void predict_16x16_dc_top_altivec( uint8_t *src )
{
    uint32_t dc = 0;

160
    for( int i = 0; i < 16; i++ )
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
        dc += src[i - FDEC_STRIDE];
    vec_u8_u v ; v.s[0] = (( dc + 8 ) >> 4);
    vec_u8_t bc_v = vec_splat(v.v, 0);

    PREDICT_16x16_DC_ALTIVEC(bc_v);
}

static void predict_16x16_dc_128_altivec( uint8_t *src )
{
    /* test if generating the constant is faster than loading it.
    vector unsigned int bc_v = (vector unsigned int)CV(0x80808080, 0x80808080, 0x80808080, 0x80808080);
    */
    vec_u8_t bc_v = vec_vslb((vec_u8_t)vec_splat_u8(1),(vec_u8_t)vec_splat_u8(7));
    PREDICT_16x16_DC_ALTIVEC(bc_v);
}

static void predict_16x16_h_altivec( uint8_t *src )
{
179
    for( int i = 0; i < 16; i++ )
180 181 182 183 184 185 186 187 188 189 190
    {
        vec_u8_t v = vec_ld(-1, src);
        vec_u8_t v_v = vec_splat(v, 15);
        vec_st(v_v, 0, src);

        src += FDEC_STRIDE;
    }
}

static void predict_16x16_v_altivec( uint8_t *src )
{
191
    vec_u32_u v;
192 193 194 195 196
    v.s[0] = *(uint32_t*)&src[ 0-FDEC_STRIDE];
    v.s[1] = *(uint32_t*)&src[ 4-FDEC_STRIDE];
    v.s[2] = *(uint32_t*)&src[ 8-FDEC_STRIDE];
    v.s[3] = *(uint32_t*)&src[12-FDEC_STRIDE];

197
    for( int i = 0; i < 16; i++ )
198 199 200 201 202
    {
        vec_st(v.v, 0, (uint32_t*)src);
        src += FDEC_STRIDE;
    }
}
203
#endif // !HIGH_BIT_DEPTH
204 205


206 207 208 209 210
/****************************************************************************
 * Exported functions:
 ****************************************************************************/
void x264_predict_16x16_init_altivec( x264_predict_t pf[7] )
{
211
#if !HIGH_BIT_DEPTH
212 213 214 215 216 217 218
    pf[I_PRED_16x16_V ]      = predict_16x16_v_altivec;
    pf[I_PRED_16x16_H ]      = predict_16x16_h_altivec;
    pf[I_PRED_16x16_DC]      = predict_16x16_dc_altivec;
    pf[I_PRED_16x16_P ]      = predict_16x16_p_altivec;
    pf[I_PRED_16x16_DC_LEFT] = predict_16x16_dc_left_altivec;
    pf[I_PRED_16x16_DC_TOP ] = predict_16x16_dc_top_altivec;
    pf[I_PRED_16x16_DC_128 ] = predict_16x16_dc_128_altivec;
219
#endif // !HIGH_BIT_DEPTH
220
}
221 222 223

void x264_predict_8x8c_init_altivec( x264_predict_t pf[7] )
{
224
#if !HIGH_BIT_DEPTH
225
    pf[I_PRED_CHROMA_P]       = predict_8x8c_p_altivec;
226
#endif // !HIGH_BIT_DEPTH
227
}