Commit 378cef14 authored by hui su's avatar hui su
Browse files

Merge part of misc-fixes experiment

Merge the part for intra prediction reference data. It makes the
codebase easier to read, and also improves coding performance
slightly.

Change-Id: I15fa7bd43fb1bae596c43e88327abb37bc6145f7
parent 9dd0b898
......@@ -22,7 +22,6 @@
#include "av1/common/reconintra.h"
#include "av1/common/onyxc_int.h"
#if CONFIG_MISC_FIXES
enum {
NEED_LEFT = 1 << 1,
NEED_ABOVE = 1 << 2,
......@@ -43,28 +42,7 @@ static const uint8_t extend_modes[INTRA_MODES] = {
NEED_ABOVE | NEED_ABOVERIGHT, // D63
NEED_LEFT | NEED_ABOVE | NEED_ABOVELEFT, // TM
};
#else
enum {
NEED_LEFT = 1 << 1,
NEED_ABOVE = 1 << 2,
NEED_ABOVERIGHT = 1 << 3,
};
static const uint8_t extend_modes[INTRA_MODES] = {
NEED_ABOVE | NEED_LEFT, // DC
NEED_ABOVE, // V
NEED_LEFT, // H
NEED_ABOVERIGHT, // D45
NEED_LEFT | NEED_ABOVE, // D135
NEED_LEFT | NEED_ABOVE, // D117
NEED_LEFT | NEED_ABOVE, // D153
NEED_LEFT, // D207
NEED_ABOVERIGHT, // D63
NEED_LEFT | NEED_ABOVE, // TM
};
#endif
#if CONFIG_MISC_FIXES
static const uint8_t orders_64x64[1] = { 0 };
static const uint8_t orders_64x32[2] = { 0, 1 };
static const uint8_t orders_32x64[2] = { 0, 1 };
......@@ -163,7 +141,6 @@ static int av1_has_bottom(BLOCK_SIZE bsize, int mi_row, int mi_col,
return 0;
}
}
#endif
typedef void (*intra_pred_fn)(uint8_t *dst, ptrdiff_t stride,
const uint8_t *above, const uint8_t *left);
......@@ -236,55 +213,33 @@ static void av1_init_intra_predictors_internal(void) {
#undef intra_pred_allsizes
}
#if CONFIG_MISC_FIXES
static INLINE void memset16(uint16_t *dst, int val, int n) {
while (n--) *dst++ = val;
}
#endif
#if CONFIG_AOM_HIGHBITDEPTH
static void build_intra_predictors_high(const MACROBLOCKD *xd,
const uint8_t *ref8, int ref_stride,
uint8_t *dst8, int dst_stride,
PREDICTION_MODE mode, TX_SIZE tx_size,
#if CONFIG_MISC_FIXES
int n_top_px, int n_topright_px,
int n_left_px, int n_bottomleft_px,
#else
int up_available, int left_available,
int right_available,
#endif
int x, int y, int plane, int bd) {
int i;
uint16_t *dst = CONVERT_TO_SHORTPTR(dst8);
uint16_t *ref = CONVERT_TO_SHORTPTR(ref8);
#if CONFIG_MISC_FIXES
DECLARE_ALIGNED(16, uint16_t, left_col[32]);
#else
DECLARE_ALIGNED(16, uint16_t, left_col[64]);
#endif
DECLARE_ALIGNED(16, uint16_t, above_data[64 + 16]);
uint16_t *above_row = above_data + 16;
const uint16_t *const_above_row = above_row;
const int bs = 4 << tx_size;
#if CONFIG_MISC_FIXES
const uint16_t *above_ref = ref - ref_stride;
#else
int frame_width, frame_height;
int x0, y0;
const struct macroblockd_plane *const pd = &xd->plane[plane];
#endif
const int need_left = extend_modes[mode] & NEED_LEFT;
const int need_above = extend_modes[mode] & NEED_ABOVE;
const int need_aboveright = extend_modes[mode] & NEED_ABOVERIGHT;
int base = 128 << (bd - 8);
// 127 127 127 .. 127 127 127 127 127 127
// 129 A B .. Y Z
// 129 C D .. W X
// 129 E F .. U V
// 129 G H .. S T T T T T
// 127 127 127 .. 127 127 127 127 127 127
// 129 A B .. Y Z
// 129 C D .. W X
// 129 E F .. U V
// 129 G H .. S T T T T T
#if CONFIG_MISC_FIXES
(void)x;
(void)y;
(void)plane;
......@@ -304,9 +259,9 @@ static void build_intra_predictors_high(const MACROBLOCKD *xd,
left_col[i] = ref[i * ref_stride - 1];
}
if (i < (bs << need_bottom))
memset16(&left_col[i], left_col[i - 1], (bs << need_bottom) - i);
aom_memset16(&left_col[i], left_col[i - 1], (bs << need_bottom) - i);
} else {
memset16(left_col, base + 1, bs << need_bottom);
aom_memset16(left_col, base + 1, bs << need_bottom);
}
}
......@@ -322,9 +277,9 @@ static void build_intra_predictors_high(const MACROBLOCKD *xd,
i += n_topright_px;
}
if (i < (bs << need_right))
memset16(&above_row[i], above_row[i - 1], (bs << need_right) - i);
aom_memset16(&above_row[i], above_row[i - 1], (bs << need_right) - i);
} else {
memset16(above_row, base - 1, bs << need_right);
aom_memset16(above_row, base - 1, bs << need_right);
}
}
......@@ -332,134 +287,11 @@ static void build_intra_predictors_high(const MACROBLOCKD *xd,
above_row[-1] =
n_top_px > 0 ? (n_left_px > 0 ? above_ref[-1] : base + 1) : base - 1;
}
#else
// Get current frame pointer, width and height.
if (plane == 0) {
frame_width = xd->cur_buf->y_width;
frame_height = xd->cur_buf->y_height;
} else {
frame_width = xd->cur_buf->uv_width;
frame_height = xd->cur_buf->uv_height;
}
// Get block position in current frame.
x0 = (-xd->mb_to_left_edge >> (3 + pd->subsampling_x)) + x;
y0 = (-xd->mb_to_top_edge >> (3 + pd->subsampling_y)) + y;
// NEED_LEFT
if (need_left) {
if (left_available) {
if (xd->mb_to_bottom_edge < 0) {
/* slower path if the block needs border extension */
if (y0 + bs <= frame_height) {
for (i = 0; i < bs; ++i) left_col[i] = ref[i * ref_stride - 1];
} else {
const int extend_bottom = frame_height - y0;
for (i = 0; i < extend_bottom; ++i)
left_col[i] = ref[i * ref_stride - 1];
for (; i < bs; ++i)
left_col[i] = ref[(extend_bottom - 1) * ref_stride - 1];
}
} else {
/* faster path if the block does not need extension */
for (i = 0; i < bs; ++i) left_col[i] = ref[i * ref_stride - 1];
}
} else {
// TODO(Peter): this value should probably change for high bitdepth
aom_memset16(left_col, base + 1, bs);
}
}
// NEED_ABOVE
if (need_above) {
if (up_available) {
const uint16_t *above_ref = ref - ref_stride;
if (xd->mb_to_right_edge < 0) {
/* slower path if the block needs border extension */
if (x0 + bs <= frame_width) {
memcpy(above_row, above_ref, bs * sizeof(above_row[0]));
} else if (x0 <= frame_width) {
const int r = frame_width - x0;
memcpy(above_row, above_ref, r * sizeof(above_row[0]));
aom_memset16(above_row + r, above_row[r - 1], x0 + bs - frame_width);
}
} else {
/* faster path if the block does not need extension */
if (bs == 4 && right_available && left_available) {
const_above_row = above_ref;
} else {
memcpy(above_row, above_ref, bs * sizeof(above_row[0]));
}
}
above_row[-1] = left_available ? above_ref[-1] : (base + 1);
} else {
aom_memset16(above_row, base - 1, bs);
above_row[-1] = base - 1;
}
}
// NEED_ABOVERIGHT
if (need_aboveright) {
if (up_available) {
const uint16_t *above_ref = ref - ref_stride;
if (xd->mb_to_right_edge < 0) {
/* slower path if the block needs border extension */
if (x0 + 2 * bs <= frame_width) {
if (right_available && bs == 4) {
memcpy(above_row, above_ref, 2 * bs * sizeof(above_row[0]));
} else {
memcpy(above_row, above_ref, bs * sizeof(above_row[0]));
aom_memset16(above_row + bs, above_row[bs - 1], bs);
}
} else if (x0 + bs <= frame_width) {
const int r = frame_width - x0;
if (right_available && bs == 4) {
memcpy(above_row, above_ref, r * sizeof(above_row[0]));
aom_memset16(above_row + r, above_row[r - 1],
x0 + 2 * bs - frame_width);
} else {
memcpy(above_row, above_ref, bs * sizeof(above_row[0]));
aom_memset16(above_row + bs, above_row[bs - 1], bs);
}
} else if (x0 <= frame_width) {
const int r = frame_width - x0;
memcpy(above_row, above_ref, r * sizeof(above_row[0]));
aom_memset16(above_row + r, above_row[r - 1],
x0 + 2 * bs - frame_width);
}
// TODO(Peter) this value should probably change for high bitdepth
above_row[-1] = left_available ? above_ref[-1] : (base + 1);
} else {
/* faster path if the block does not need extension */
if (bs == 4 && right_available && left_available) {
const_above_row = above_ref;
} else {
memcpy(above_row, above_ref, bs * sizeof(above_row[0]));
if (bs == 4 && right_available)
memcpy(above_row + bs, above_ref + bs, bs * sizeof(above_row[0]));
else
aom_memset16(above_row + bs, above_row[bs - 1], bs);
// TODO(Peter): this value should probably change for high bitdepth
above_row[-1] = left_available ? above_ref[-1] : (base + 1);
}
}
} else {
aom_memset16(above_row, base - 1, bs * 2);
// TODO(Peter): this value should probably change for high bitdepth
above_row[-1] = base - 1;
}
}
#endif
// predict
if (mode == DC_PRED) {
#if CONFIG_MISC_FIXES
dc_pred_high[n_left_px > 0][n_top_px > 0][tx_size](
dst, dst_stride, const_above_row, left_col, xd->bd);
#else
dc_pred_high[left_available][up_available][tx_size](
dst, dst_stride, const_above_row, left_col, xd->bd);
#endif
} else {
pred_high[mode][tx_size](dst, dst_stride, const_above_row, left_col,
xd->bd);
......@@ -470,37 +302,24 @@ static void build_intra_predictors_high(const MACROBLOCKD *xd,
static void build_intra_predictors(const MACROBLOCKD *xd, const uint8_t *ref,
int ref_stride, uint8_t *dst, int dst_stride,
PREDICTION_MODE mode, TX_SIZE tx_size,
#if CONFIG_MISC_FIXES
int n_top_px, int n_topright_px,
int n_left_px, int n_bottomleft_px,
#else
int up_available, int left_available,
int right_available,
#endif
int x, int y, int plane) {
int n_left_px, int n_bottomleft_px, int x,
int y, int plane) {
int i;
#if CONFIG_MISC_FIXES
DECLARE_ALIGNED(16, uint8_t, left_col[64]);
const uint8_t *above_ref = ref - ref_stride;
#else
DECLARE_ALIGNED(16, uint8_t, left_col[32]);
int frame_width, frame_height;
int x0, y0;
const struct macroblockd_plane *const pd = &xd->plane[plane];
#endif
DECLARE_ALIGNED(16, uint8_t, above_data[64 + 16]);
uint8_t *above_row = above_data + 16;
const uint8_t *const_above_row = above_row;
const int bs = 4 << tx_size;
// 127 127 127 .. 127 127 127 127 127 127
// 129 A B .. Y Z
// 129 C D .. W X
// 129 E F .. U V
// 129 G H .. S T T T T T
// ..
// 127 127 127 .. 127 127 127 127 127 127
// 129 A B .. Y Z
// 129 C D .. W X
// 129 E F .. U V
// 129 G H .. S T T T T T
// ..
#if CONFIG_MISC_FIXES
(void)xd;
(void)x;
(void)y;
......@@ -509,24 +328,9 @@ static void build_intra_predictors(const MACROBLOCKD *xd, const uint8_t *ref,
assert(n_topright_px >= 0);
assert(n_left_px >= 0);
assert(n_bottomleft_px >= 0);
#else
// Get current frame pointer, width and height.
if (plane == 0) {
frame_width = xd->cur_buf->y_width;
frame_height = xd->cur_buf->y_height;
} else {
frame_width = xd->cur_buf->uv_width;
frame_height = xd->cur_buf->uv_height;
}
// Get block position in current frame.
x0 = (-xd->mb_to_left_edge >> (3 + pd->subsampling_x)) + x;
y0 = (-xd->mb_to_top_edge >> (3 + pd->subsampling_y)) + y;
#endif
// NEED_LEFT
if (extend_modes[mode] & NEED_LEFT) {
#if CONFIG_MISC_FIXES
const int need_bottom = !!(extend_modes[mode] & NEED_BOTTOMLEFT);
i = 0;
if (n_left_px > 0) {
......@@ -541,32 +345,10 @@ static void build_intra_predictors(const MACROBLOCKD *xd, const uint8_t *ref,
} else {
memset(left_col, 129, bs << need_bottom);
}
#else
if (left_available) {
if (xd->mb_to_bottom_edge < 0) {
/* slower path if the block needs border extension */
if (y0 + bs <= frame_height) {
for (i = 0; i < bs; ++i) left_col[i] = ref[i * ref_stride - 1];
} else {
const int extend_bottom = frame_height - y0;
for (i = 0; i < extend_bottom; ++i)
left_col[i] = ref[i * ref_stride - 1];
for (; i < bs; ++i)
left_col[i] = ref[(extend_bottom - 1) * ref_stride - 1];
}
} else {
/* faster path if the block does not need extension */
for (i = 0; i < bs; ++i) left_col[i] = ref[i * ref_stride - 1];
}
} else {
memset(left_col, 129, bs);
}
#endif
}
// NEED_ABOVE
if (extend_modes[mode] & NEED_ABOVE) {
#if CONFIG_MISC_FIXES
const int need_right = !!(extend_modes[mode] & NEED_ABOVERIGHT);
if (n_top_px > 0) {
memcpy(above_row, above_ref, n_top_px);
......@@ -581,95 +363,16 @@ static void build_intra_predictors(const MACROBLOCKD *xd, const uint8_t *ref,
} else {
memset(above_row, 127, bs << need_right);
}
#else
if (up_available) {
const uint8_t *above_ref = ref - ref_stride;
if (xd->mb_to_right_edge < 0) {
/* slower path if the block needs border extension */
if (x0 + bs <= frame_width) {
memcpy(above_row, above_ref, bs);
} else if (x0 <= frame_width) {
const int r = frame_width - x0;
memcpy(above_row, above_ref, r);
memset(above_row + r, above_row[r - 1], x0 + bs - frame_width);
}
} else {
/* faster path if the block does not need extension */
if (bs == 4 && right_available && left_available) {
const_above_row = above_ref;
} else {
memcpy(above_row, above_ref, bs);
}
}
above_row[-1] = left_available ? above_ref[-1] : 129;
} else {
memset(above_row, 127, bs);
above_row[-1] = 127;
}
#endif
}
#if CONFIG_MISC_FIXES
if (extend_modes[mode] & NEED_ABOVELEFT) {
above_row[-1] = n_top_px > 0 ? (n_left_px > 0 ? above_ref[-1] : 129) : 127;
}
#else
// NEED_ABOVERIGHT
if (extend_modes[mode] & NEED_ABOVERIGHT) {
if (up_available) {
const uint8_t *above_ref = ref - ref_stride;
if (xd->mb_to_right_edge < 0) {
/* slower path if the block needs border extension */
if (x0 + 2 * bs <= frame_width) {
if (right_available && bs == 4) {
memcpy(above_row, above_ref, 2 * bs);
} else {
memcpy(above_row, above_ref, bs);
memset(above_row + bs, above_row[bs - 1], bs);
}
} else if (x0 + bs <= frame_width) {
const int r = frame_width - x0;
if (right_available && bs == 4) {
memcpy(above_row, above_ref, r);
memset(above_row + r, above_row[r - 1], x0 + 2 * bs - frame_width);
} else {
memcpy(above_row, above_ref, bs);
memset(above_row + bs, above_row[bs - 1], bs);
}
} else if (x0 <= frame_width) {
const int r = frame_width - x0;
memcpy(above_row, above_ref, r);
memset(above_row + r, above_row[r - 1], x0 + 2 * bs - frame_width);
}
} else {
/* faster path if the block does not need extension */
if (bs == 4 && right_available && left_available) {
const_above_row = above_ref;
} else {
memcpy(above_row, above_ref, bs);
if (bs == 4 && right_available)
memcpy(above_row + bs, above_ref + bs, bs);
else
memset(above_row + bs, above_row[bs - 1], bs);
}
}
above_row[-1] = left_available ? above_ref[-1] : 129;
} else {
memset(above_row, 127, bs * 2);
above_row[-1] = 127;
}
}
#endif
// predict
if (mode == DC_PRED) {
#if CONFIG_MISC_FIXES
dc_pred[n_left_px > 0][n_top_px > 0][tx_size](dst, dst_stride,
const_above_row, left_col);
#else
dc_pred[left_available][up_available][tx_size](dst, dst_stride,
const_above_row, left_col);
#endif
} else {
pred[mode][tx_size](dst, dst_stride, const_above_row, left_col);
}
......@@ -684,7 +387,6 @@ void av1_predict_intra_block(const MACROBLOCKD *xd, int bwl_in, int bhl_in,
const int have_left = aoff || xd->left_available;
const int x = aoff * 4;
const int y = loff * 4;
#if CONFIG_MISC_FIXES
const int bw = AOMMAX(2, 1 << bwl_in);
const int bh = AOMMAX(2, 1 << bhl_in);
const int mi_row = -xd->mb_to_top_edge >> 6;
......@@ -705,12 +407,7 @@ void av1_predict_intra_block(const MACROBLOCKD *xd, int bwl_in, int bhl_in,
int xr = (xd->mb_to_right_edge >> (3 + pd->subsampling_x)) + (wpx - x - txpx);
int yd =
(xd->mb_to_bottom_edge >> (3 + pd->subsampling_y)) + (hpx - y - txpx);
#else
const int bw = (1 << bwl_in);
const int have_right = (aoff + txw) < bw;
#endif // CONFIG_MISC_FIXES
#if CONFIG_MISC_FIXES
#if CONFIG_AOM_HIGHBITDEPTH
if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
build_intra_predictors_high(xd, ref, ref_stride, dst, dst_stride, mode,
......@@ -728,19 +425,6 @@ void av1_predict_intra_block(const MACROBLOCKD *xd, int bwl_in, int bhl_in,
have_left ? AOMMIN(txpx, yd + txpx) : 0,
have_bottom && have_left ? AOMMIN(txpx, yd) : 0, x, y,
plane);
#else // CONFIG_MISC_FIXES
(void)bhl_in;
#if CONFIG_AOM_HIGHBITDEPTH
if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
build_intra_predictors_high(xd, ref, ref_stride, dst, dst_stride, mode,
tx_size, have_top, have_left, have_right, x, y,
plane, xd->bd);
return;
}
#endif
build_intra_predictors(xd, ref, ref_stride, dst, dst_stride, mode, tx_size,
have_top, have_left, have_right, x, y, plane);
#endif // CONFIG_MISC_FIXES
}
void av1_init_intra_predictors(void) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment