Convert 16x16 dct/idct to integer forms

Converted vp9_short_fdct16x16_c and vp9_short_idct16x16_c to
integer versions.

Change-Id: Ie3ec985a890ac0f4f4f5818e6f0122e00c8af69f
This commit is contained in:
Yunqing Wang 2012-11-01 09:04:28 -07:00
parent 0078d2f3dc
commit 4626faf1e7
2 changed files with 458 additions and 0 deletions

View File

@ -1013,6 +1013,8 @@ void vp9_short_idct16x16_c(short *input, short *output, int pitch) {
}
#endif
#define TEST_INT_16x16_IDCT 1
#if !TEST_INT_16x16_IDCT
static const double C1 = 0.995184726672197;
static const double C2 = 0.98078528040323;
static const double C3 = 0.956940335732209;
@ -1273,3 +1275,235 @@ void vp9_short_idct16x16_c(short *input, short *output, int pitch) {
}
vp9_clear_system_state(); // Make it simd safe : __asm emms;
}
#else
static const int16_t C1 = 16305;
static const int16_t C2 = 16069;
static const int16_t C3 = 15679;
static const int16_t C4 = 15137;
static const int16_t C5 = 14449;
static const int16_t C6 = 13623;
static const int16_t C7 = 12665;
static const int16_t C8 = 11585;
static const int16_t C9 = 10394;
static const int16_t C10 = 9102;
static const int16_t C11 = 7723;
static const int16_t C12 = 6270;
static const int16_t C13 = 4756;
static const int16_t C14 = 3196;
static const int16_t C15 = 1606;
#define INITIAL_SHIFT 2
#define INITIAL_ROUNDING (1 << (INITIAL_SHIFT - 1))
#define RIGHT_SHIFT 14
#define RIGHT_ROUNDING (1 << (RIGHT_SHIFT - 1))
static void butterfly_16x16_idct_1d(int16_t input[16], int16_t output[16],
int last_shift_bits) {
int16_t step[16];
int intermediate[16];
int temp1, temp2;
int step1_shift = RIGHT_SHIFT + INITIAL_SHIFT;
int step1_rounding = 1 << (step1_shift - 1);
int last_rounding = 0;
if (last_shift_bits > 0)
last_rounding = 1 << (last_shift_bits - 1);
// step 1 and 2
step[ 0] = (input[0] + input[8] + INITIAL_ROUNDING) >> INITIAL_SHIFT;
step[ 1] = (input[0] - input[8] + INITIAL_ROUNDING) >> INITIAL_SHIFT;
temp1 = input[4] * C12;
temp2 = input[12] * C4;
temp1 = (temp1 - temp2 + RIGHT_ROUNDING) >> RIGHT_SHIFT;
temp1 *= C8;
step[ 2] = (2 * (temp1) + step1_rounding) >> step1_shift;
temp1 = input[4] * C4;
temp2 = input[12] * C12;
temp1 = (temp1 + temp2 + RIGHT_ROUNDING) >> RIGHT_SHIFT;
temp1 *= C8;
step[ 3] = (2 * (temp1) + step1_rounding) >> step1_shift;
temp1 = input[2] * C8;
temp1 = (2 * (temp1) + RIGHT_ROUNDING) >> RIGHT_SHIFT;
temp2 = input[6] + input[10];
step[ 4] = (temp1 + temp2 + INITIAL_ROUNDING) >> INITIAL_SHIFT;
step[ 5] = (temp1 - temp2 + INITIAL_ROUNDING) >> INITIAL_SHIFT;
temp1 = input[14] * C8;
temp1 = (2 * (temp1) + RIGHT_ROUNDING) >> RIGHT_SHIFT;
temp2 = input[6] - input[10];
step[ 6] = (temp2 - temp1 + INITIAL_ROUNDING) >> INITIAL_SHIFT;
step[ 7] = (temp2 + temp1 + INITIAL_ROUNDING) >> INITIAL_SHIFT;
// for odd input
temp1 = input[3] * C12;
temp2 = input[13] * C4;
temp1 = (temp1 + temp2 + RIGHT_ROUNDING) >> RIGHT_SHIFT;
temp1 *= C8;
intermediate[ 8] = (2 * (temp1) + RIGHT_ROUNDING) >> RIGHT_SHIFT;
temp1 = input[3] * C4;
temp2 = input[13] * C12;
temp2 = (temp2 - temp1 + RIGHT_ROUNDING) >> RIGHT_SHIFT;
temp2 *= C8;
intermediate[ 9] = (2 * (temp2) + RIGHT_ROUNDING) >> RIGHT_SHIFT;
intermediate[10] = (2 * (input[9] * C8) + RIGHT_ROUNDING) >> RIGHT_SHIFT;
intermediate[11] = input[15] - input[1];
intermediate[12] = input[15] + input[1];
intermediate[13] = (2 * (input[7] * C8) + RIGHT_ROUNDING) >> RIGHT_SHIFT;
temp1 = input[11] * C12;
temp2 = input[5] * C4;
temp2 = (temp2 - temp1 + RIGHT_ROUNDING) >> RIGHT_SHIFT;
temp2 *= C8;
intermediate[14] = (2 * (temp2) + RIGHT_ROUNDING) >> RIGHT_SHIFT;
temp1 = input[11] * C4;
temp2 = input[5] * C12;
temp1 = (temp1 + temp2 + RIGHT_ROUNDING) >> RIGHT_SHIFT;
temp1 *= C8;
intermediate[15] = (2 * (temp1) + RIGHT_ROUNDING) >> RIGHT_SHIFT;
step[ 8] = (intermediate[ 8] + intermediate[14] + INITIAL_ROUNDING)
>> INITIAL_SHIFT;
step[ 9] = (intermediate[ 9] + intermediate[15] + INITIAL_ROUNDING)
>> INITIAL_SHIFT;
step[10] = (intermediate[10] + intermediate[11] + INITIAL_ROUNDING)
>> INITIAL_SHIFT;
step[11] = (intermediate[10] - intermediate[11] + INITIAL_ROUNDING)
>> INITIAL_SHIFT;
step[12] = (intermediate[12] + intermediate[13] + INITIAL_ROUNDING)
>> INITIAL_SHIFT;
step[13] = (intermediate[12] - intermediate[13] + INITIAL_ROUNDING)
>> INITIAL_SHIFT;
step[14] = (intermediate[ 8] - intermediate[14] + INITIAL_ROUNDING)
>> INITIAL_SHIFT;
step[15] = (intermediate[ 9] - intermediate[15] + INITIAL_ROUNDING)
>> INITIAL_SHIFT;
// step 3
output[0] = step[ 0] + step[ 3];
output[1] = step[ 1] + step[ 2];
output[2] = step[ 1] - step[ 2];
output[3] = step[ 0] - step[ 3];
temp1 = step[ 4] * C14;
temp2 = step[ 7] * C2;
output[4] = (temp1 - temp2 + RIGHT_ROUNDING) >> RIGHT_SHIFT;
temp1 = step[ 4] * C2;
temp2 = step[ 7] * C14;
output[7] = (temp1 + temp2 + RIGHT_ROUNDING) >> RIGHT_SHIFT;
temp1 = step[ 5] * C10;
temp2 = step[ 6] * C6;
output[5] = (temp1 - temp2 + RIGHT_ROUNDING) >> RIGHT_SHIFT;
temp1 = step[ 5] * C6;
temp2 = step[ 6] * C10;
output[6] = (temp1 + temp2 + RIGHT_ROUNDING) >> RIGHT_SHIFT;
output[8] = step[ 8] + step[11];
output[9] = step[ 9] + step[10];
output[10] = step[ 9] - step[10];
output[11] = step[ 8] - step[11];
output[12] = step[12] + step[15];
output[13] = step[13] + step[14];
output[14] = step[13] - step[14];
output[15] = step[12] - step[15];
// output 4
step[ 0] = output[0] + output[7];
step[ 1] = output[1] + output[6];
step[ 2] = output[2] + output[5];
step[ 3] = output[3] + output[4];
step[ 4] = output[3] - output[4];
step[ 5] = output[2] - output[5];
step[ 6] = output[1] - output[6];
step[ 7] = output[0] - output[7];
temp1 = output[8] * C7;
temp2 = output[15] * C9;
step[ 8] = (temp1 - temp2 + RIGHT_ROUNDING) >> RIGHT_SHIFT;
temp1 = output[9] * C11;
temp2 = output[14] * C5;
step[ 9] = (temp1 + temp2 + RIGHT_ROUNDING) >> RIGHT_SHIFT;
temp1 = output[10] * C3;
temp2 = output[13] * C13;
step[10] = (temp1 - temp2 + RIGHT_ROUNDING) >> RIGHT_SHIFT;
temp1 = output[11] * C15;
temp2 = output[12] * C1;
step[11] = (temp1 + temp2 + RIGHT_ROUNDING) >> RIGHT_SHIFT;
temp1 = output[11] * C1;
temp2 = output[12] * C15;
step[12] = (temp2 - temp1 + RIGHT_ROUNDING) >> RIGHT_SHIFT;
temp1 = output[10] * C13;
temp2 = output[13] * C3;
step[13] = (temp1 + temp2 + RIGHT_ROUNDING) >> RIGHT_SHIFT;
temp1 = output[9] * C5;
temp2 = output[14] * C11;
step[14] = (temp2 - temp1 + RIGHT_ROUNDING) >> RIGHT_SHIFT;
temp1 = output[8] * C9;
temp2 = output[15] * C7;
step[15] = (temp1 + temp2 + RIGHT_ROUNDING) >> RIGHT_SHIFT;
// step 5
output[0] = (step[0] + step[15] + last_rounding) >> last_shift_bits;
output[1] = (step[1] + step[14] + last_rounding) >> last_shift_bits;
output[2] = (step[2] + step[13] + last_rounding) >> last_shift_bits;
output[3] = (step[3] + step[12] + last_rounding) >> last_shift_bits;
output[4] = (step[4] + step[11] + last_rounding) >> last_shift_bits;
output[5] = (step[5] + step[10] + last_rounding) >> last_shift_bits;
output[6] = (step[6] + step[ 9] + last_rounding) >> last_shift_bits;
output[7] = (step[7] + step[ 8] + last_rounding) >> last_shift_bits;
output[15] = (step[0] - step[15] + last_rounding) >> last_shift_bits;
output[14] = (step[1] - step[14] + last_rounding) >> last_shift_bits;
output[13] = (step[2] - step[13] + last_rounding) >> last_shift_bits;
output[12] = (step[3] - step[12] + last_rounding) >> last_shift_bits;
output[11] = (step[4] - step[11] + last_rounding) >> last_shift_bits;
output[10] = (step[5] - step[10] + last_rounding) >> last_shift_bits;
output[9] = (step[6] - step[ 9] + last_rounding) >> last_shift_bits;
output[8] = (step[7] - step[ 8] + last_rounding) >> last_shift_bits;
}
void vp9_short_idct16x16_c(int16_t *input, int16_t *output, int pitch) {
int16_t out[16 * 16];
int16_t *outptr = &out[0];
const int short_pitch = pitch >> 1;
int i, j;
int16_t temp_in[16], temp_out[16];
// First transform rows
for (i = 0; i < 16; ++i) {
butterfly_16x16_idct_1d(input, outptr, 0);
input += short_pitch;
outptr += 16;
}
// Then transform columns
for (i = 0; i < 16; ++i) {
for (j = 0; j < 16; ++j)
temp_in[j] = out[j * 16 + i];
butterfly_16x16_idct_1d(temp_in, temp_out, 3);
for (j = 0; j < 16; ++j)
output[j * 16 + i] = temp_out[j];
}
}
#undef INITIAL_SHIFT
#undef INITIAL_ROUNDING
#undef RIGHT_SHIFT
#undef RIGHT_ROUNDING
#endif

View File

@ -901,6 +901,8 @@ void vp9_short_walsh8x4_x8_c(short *input, short *output, int pitch) {
}
#endif
#define TEST_INT_16x16_DCT 1
#if !TEST_INT_16x16_DCT
static const double C1 = 0.995184726672197;
static const double C2 = 0.98078528040323;
static const double C3 = 0.956940335732209;
@ -1107,3 +1109,225 @@ void vp9_short_fdct16x16_c(short *input, short *out, int pitch) {
}
vp9_clear_system_state(); // Make it simd safe : __asm emms;
}
#else
static const int16_t C1 = 16305;
static const int16_t C2 = 16069;
static const int16_t C3 = 15679;
static const int16_t C4 = 15137;
static const int16_t C5 = 14449;
static const int16_t C6 = 13623;
static const int16_t C7 = 12665;
static const int16_t C8 = 11585;
static const int16_t C9 = 10394;
static const int16_t C10 = 9102;
static const int16_t C11 = 7723;
static const int16_t C12 = 6270;
static const int16_t C13 = 4756;
static const int16_t C14 = 3196;
static const int16_t C15 = 1606;
#define RIGHT_SHIFT 14
#define ROUNDING (1 << (RIGHT_SHIFT - 1))
static void dct16x16_1d(int16_t input[16], int16_t output[16],
int last_shift_bits) {
int16_t step[16];
int intermediate[16];
int temp1, temp2;
int final_shift = RIGHT_SHIFT;
int final_rounding = ROUNDING;
int output_shift = 0;
int output_rounding = 0;
final_shift += last_shift_bits;
if (final_shift > 0)
final_rounding = 1 << (final_shift - 1);
output_shift += last_shift_bits;
if (output_shift > 0)
output_rounding = 1 << (output_shift - 1);
// step 1
step[ 0] = input[0] + input[15];
step[ 1] = input[1] + input[14];
step[ 2] = input[2] + input[13];
step[ 3] = input[3] + input[12];
step[ 4] = input[4] + input[11];
step[ 5] = input[5] + input[10];
step[ 6] = input[6] + input[ 9];
step[ 7] = input[7] + input[ 8];
step[ 8] = input[7] - input[ 8];
step[ 9] = input[6] - input[ 9];
step[10] = input[5] - input[10];
step[11] = input[4] - input[11];
step[12] = input[3] - input[12];
step[13] = input[2] - input[13];
step[14] = input[1] - input[14];
step[15] = input[0] - input[15];
// step 2
output[0] = step[0] + step[7];
output[1] = step[1] + step[6];
output[2] = step[2] + step[5];
output[3] = step[3] + step[4];
output[4] = step[3] - step[4];
output[5] = step[2] - step[5];
output[6] = step[1] - step[6];
output[7] = step[0] - step[7];
temp1 = step[ 8] * C7;
temp2 = step[15] * C9;
output[ 8] = (temp1 + temp2 + ROUNDING) >> RIGHT_SHIFT;
temp1 = step[ 9] * C11;
temp2 = step[14] * C5;
output[ 9] = (temp1 - temp2 + ROUNDING) >> RIGHT_SHIFT;
temp1 = step[10] * C3;
temp2 = step[13] * C13;
output[10] = (temp1 + temp2 + ROUNDING) >> RIGHT_SHIFT;
temp1 = step[11] * C15;
temp2 = step[12] * C1;
output[11] = (temp1 - temp2 + ROUNDING) >> RIGHT_SHIFT;
temp1 = step[11] * C1;
temp2 = step[12] * C15;
output[12] = (temp2 + temp1 + ROUNDING) >> RIGHT_SHIFT;
temp1 = step[10] * C13;
temp2 = step[13] * C3;
output[13] = (temp2 - temp1 + ROUNDING) >> RIGHT_SHIFT;
temp1 = step[ 9] * C5;
temp2 = step[14] * C11;
output[14] = (temp2 + temp1 + ROUNDING) >> RIGHT_SHIFT;
temp1 = step[ 8] * C9;
temp2 = step[15] * C7;
output[15] = (temp2 - temp1 + ROUNDING) >> RIGHT_SHIFT;
// step 3
step[ 0] = output[0] + output[3];
step[ 1] = output[1] + output[2];
step[ 2] = output[1] - output[2];
step[ 3] = output[0] - output[3];
temp1 = output[4] * C14;
temp2 = output[7] * C2;
step[ 4] = (temp1 + temp2 + ROUNDING) >> RIGHT_SHIFT;
temp1 = output[5] * C10;
temp2 = output[6] * C6;
step[ 5] = (temp1 + temp2 + ROUNDING) >> RIGHT_SHIFT;
temp1 = output[5] * C6;
temp2 = output[6] * C10;
step[ 6] = (temp2 - temp1 + ROUNDING) >> RIGHT_SHIFT;
temp1 = output[4] * C2;
temp2 = output[7] * C14;
step[ 7] = (temp2 - temp1 + ROUNDING) >> RIGHT_SHIFT;
step[ 8] = output[ 8] + output[11];
step[ 9] = output[ 9] + output[10];
step[10] = output[ 9] - output[10];
step[11] = output[ 8] - output[11];
step[12] = output[12] + output[15];
step[13] = output[13] + output[14];
step[14] = output[13] - output[14];
step[15] = output[12] - output[15];
// step 4
output[ 0] = (step[ 0] + step[ 1] + output_rounding) >> output_shift;
output[ 8] = (step[ 0] - step[ 1] + output_rounding) >> output_shift;
temp1 = step[2] * C12;
temp2 = step[3] * C4;
temp1 = (temp1 + temp2 + final_rounding) >> final_shift;
output[ 4] = (2 * (temp1 * C8) + ROUNDING) >> RIGHT_SHIFT;
temp1 = step[2] * C4;
temp2 = step[3] * C12;
temp1 = (temp2 - temp1 + final_rounding) >> final_shift;
output[12] = (2 * (temp1 * C8) + ROUNDING) >> RIGHT_SHIFT;
output[ 2] = (2 * ((step[4] + step[ 5]) * C8) + final_rounding)
>> final_shift;
output[14] = (2 * ((step[7] - step[ 6]) * C8) + final_rounding)
>> final_shift;
temp1 = step[4] - step[5];
temp2 = step[6] + step[7];
output[ 6] = (temp1 + temp2 + output_rounding) >> output_shift;
output[10] = (temp1 - temp2 + output_rounding) >> output_shift;
intermediate[8] = step[8] + step[14];
intermediate[9] = step[9] + step[15];
temp1 = intermediate[8] * C12;
temp2 = intermediate[9] * C4;
temp1 = (temp1 - temp2 + final_rounding) >> final_shift;
output[3] = (2 * (temp1 * C8) + ROUNDING) >> RIGHT_SHIFT;
temp1 = intermediate[8] * C4;
temp2 = intermediate[9] * C12;
temp1 = (temp2 + temp1 + final_rounding) >> final_shift;
output[13] = (2 * (temp1 * C8) + ROUNDING) >> RIGHT_SHIFT;
output[ 9] = (2 * ((step[10] + step[11]) * C8) + final_rounding)
>> final_shift;
intermediate[11] = step[10] - step[11];
intermediate[12] = step[12] + step[13];
intermediate[13] = step[12] - step[13];
intermediate[14] = step[ 8] - step[14];
intermediate[15] = step[ 9] - step[15];
output[15] = (intermediate[11] + intermediate[12] + output_rounding)
>> output_shift;
output[ 1] = -(intermediate[11] - intermediate[12] + output_rounding)
>> output_shift;
output[ 7] = (2 * (intermediate[13] * C8) + final_rounding) >> final_shift;
temp1 = intermediate[14] * C12;
temp2 = intermediate[15] * C4;
temp1 = (temp1 - temp2 + final_rounding) >> final_shift;
output[11] = (-2 * (temp1 * C8) + ROUNDING) >> RIGHT_SHIFT;
temp1 = intermediate[14] * C4;
temp2 = intermediate[15] * C12;
temp1 = (temp2 + temp1 + final_rounding) >> final_shift;
output[ 5] = (2 * (temp1 * C8) + ROUNDING) >> RIGHT_SHIFT;
}
void vp9_short_fdct16x16_c(int16_t *input, int16_t *out, int pitch) {
int shortpitch = pitch >> 1;
int i, j;
int16_t output[256];
int16_t *outptr = &output[0];
// First transform columns
for (i = 0; i < 16; i++) {
int16_t temp_in[16];
int16_t temp_out[16];
for (j = 0; j < 16; j++)
temp_in[j] = input[j * shortpitch + i];
dct16x16_1d(temp_in, temp_out, 0);
for (j = 0; j < 16; j++)
output[j * 16 + i] = temp_out[j];
}
// Then transform rows
for (i = 0; i < 16; ++i) {
dct16x16_1d(outptr, out, 1);
outptr += 16;
out += 16;
}
}
#undef RIGHT_SHIFT
#undef ROUNDING
#endif