aboutsummaryrefslogtreecommitdiff
path: root/libvpx/vp8/encoder/mcomp.c
diff options
context:
space:
mode:
Diffstat (limited to 'libvpx/vp8/encoder/mcomp.c')
-rw-r--r--libvpx/vp8/encoder/mcomp.c334
1 files changed, 35 insertions, 299 deletions
diff --git a/libvpx/vp8/encoder/mcomp.c b/libvpx/vp8/encoder/mcomp.c
index 9e7f5c7ac..ae092c66e 100644
--- a/libvpx/vp8/encoder/mcomp.c
+++ b/libvpx/vp8/encoder/mcomp.c
@@ -204,19 +204,21 @@ void vp8_init3smotion_compensation(MACROBLOCK *x, int stride) {
/* returns distortion + motion vector cost */
#define ERR(r, c) (MVC(r, c) + DIST(r, c))
/* checks if (r,c) has better score than previous best */
-#define CHECK_BETTER(v, r, c) \
- IFMVCV(r, c, \
- { \
- thismse = DIST(r, c); \
- if ((v = (MVC(r, c) + thismse)) < besterr) { \
- besterr = v; \
- br = r; \
- bc = c; \
- *distortion = thismse; \
- *sse1 = sse; \
- } \
- }, \
- v = UINT_MAX;)
+#define CHECK_BETTER(v, r, c) \
+ do { \
+ IFMVCV(r, c, \
+ { \
+ thismse = DIST(r, c); \
+ if ((v = (MVC(r, c) + thismse)) < besterr) { \
+ besterr = v; \
+ br = r; \
+ bc = c; \
+ *distortion = thismse; \
+ *sse1 = sse; \
+ } \
+ }, \
+ v = UINT_MAX;) \
+ } while (0)
int vp8_find_best_sub_pixel_step_iteratively(MACROBLOCK *x, BLOCK *b, BLOCKD *d,
int_mv *bestmv, int_mv *ref_mv,
@@ -800,13 +802,13 @@ int vp8_find_best_half_pixel_step(MACROBLOCK *x, BLOCK *b, BLOCKD *d,
}
#define CHECK_BOUNDS(range) \
- { \
+ do { \
all_in = 1; \
all_in &= ((br - range) >= x->mv_row_min); \
all_in &= ((br + range) <= x->mv_row_max); \
all_in &= ((bc - range) >= x->mv_col_min); \
all_in &= ((bc + range) <= x->mv_col_max); \
- }
+ } while (0)
#define CHECK_POINT \
{ \
@@ -817,7 +819,7 @@ int vp8_find_best_half_pixel_step(MACROBLOCK *x, BLOCK *b, BLOCKD *d,
}
#define CHECK_BETTER \
- { \
+ do { \
if (thissad < bestsad) { \
thissad += \
mvsad_err_cost(&this_mv, &fcenter_mv, mvsadcost, sad_per_bit); \
@@ -826,7 +828,7 @@ int vp8_find_best_half_pixel_step(MACROBLOCK *x, BLOCK *b, BLOCKD *d,
best_site = i; \
} \
} \
- }
+ } while (0)
static const MV next_chkpts[6][3] = {
{ { -2, 0 }, { -1, -2 }, { 1, -2 } }, { { -1, -2 }, { 1, -2 }, { 2, 0 } },
@@ -901,7 +903,7 @@ int vp8_hex_search(MACROBLOCK *x, BLOCK *b, BLOCKD *d, int_mv *ref_mv,
#endif
/* hex search */
- CHECK_BOUNDS(2)
+ CHECK_BOUNDS(2);
if (all_in) {
for (i = 0; i < 6; ++i) {
@@ -910,7 +912,7 @@ int vp8_hex_search(MACROBLOCK *x, BLOCK *b, BLOCKD *d, int_mv *ref_mv,
this_offset = base_offset + (this_mv.as_mv.row * in_what_stride) +
this_mv.as_mv.col;
thissad = vfp->sdf(what, what_stride, this_offset, in_what_stride);
- CHECK_BETTER
+ CHECK_BETTER;
}
} else {
for (i = 0; i < 6; ++i) {
@@ -920,7 +922,7 @@ int vp8_hex_search(MACROBLOCK *x, BLOCK *b, BLOCKD *d, int_mv *ref_mv,
this_offset = base_offset + (this_mv.as_mv.row * in_what_stride) +
this_mv.as_mv.col;
thissad = vfp->sdf(what, what_stride, this_offset, in_what_stride);
- CHECK_BETTER
+ CHECK_BETTER;
}
}
@@ -934,7 +936,7 @@ int vp8_hex_search(MACROBLOCK *x, BLOCK *b, BLOCKD *d, int_mv *ref_mv,
for (j = 1; j < hex_range; ++j) {
best_site = -1;
- CHECK_BOUNDS(2)
+ CHECK_BOUNDS(2);
if (all_in) {
for (i = 0; i < 3; ++i) {
@@ -943,7 +945,7 @@ int vp8_hex_search(MACROBLOCK *x, BLOCK *b, BLOCKD *d, int_mv *ref_mv,
this_offset = base_offset + (this_mv.as_mv.row * (in_what_stride)) +
this_mv.as_mv.col;
thissad = vfp->sdf(what, what_stride, this_offset, in_what_stride);
- CHECK_BETTER
+ CHECK_BETTER;
}
} else {
for (i = 0; i < 3; ++i) {
@@ -953,7 +955,7 @@ int vp8_hex_search(MACROBLOCK *x, BLOCK *b, BLOCKD *d, int_mv *ref_mv,
this_offset = base_offset + (this_mv.as_mv.row * (in_what_stride)) +
this_mv.as_mv.col;
thissad = vfp->sdf(what, what_stride, this_offset, in_what_stride);
- CHECK_BETTER
+ CHECK_BETTER;
}
}
@@ -975,7 +977,7 @@ int vp8_hex_search(MACROBLOCK *x, BLOCK *b, BLOCKD *d, int_mv *ref_mv,
cal_neighbors:
for (j = 0; j < dia_range; ++j) {
best_site = -1;
- CHECK_BOUNDS(1)
+ CHECK_BOUNDS(1);
if (all_in) {
for (i = 0; i < 4; ++i) {
@@ -984,7 +986,7 @@ cal_neighbors:
this_offset = base_offset + (this_mv.as_mv.row * (in_what_stride)) +
this_mv.as_mv.col;
thissad = vfp->sdf(what, what_stride, this_offset, in_what_stride);
- CHECK_BETTER
+ CHECK_BETTER;
}
} else {
for (i = 0; i < 4; ++i) {
@@ -994,7 +996,7 @@ cal_neighbors:
this_offset = base_offset + (this_mv.as_mv.row * (in_what_stride)) +
this_mv.as_mv.col;
thissad = vfp->sdf(what, what_stride, this_offset, in_what_stride);
- CHECK_BETTER
+ CHECK_BETTER;
}
}
@@ -1127,7 +1129,7 @@ int vp8_diamond_search_sad_c(MACROBLOCK *x, BLOCK *b, BLOCKD *d, int_mv *ref_mv,
mv_err_cost(&this_mv, center_mv, mvcost, x->errorperbit);
}
-#if HAVE_SSE2 || HAVE_MSA
+#if HAVE_SSE2 || HAVE_MSA || HAVE_LSX
int vp8_diamond_search_sadx4(MACROBLOCK *x, BLOCK *b, BLOCKD *d, int_mv *ref_mv,
int_mv *best_mv, int search_param, int sad_per_bit,
int *num00, vp8_variance_fn_ptr_t *fn_ptr,
@@ -1276,99 +1278,12 @@ int vp8_diamond_search_sadx4(MACROBLOCK *x, BLOCK *b, BLOCKD *d, int_mv *ref_mv,
return fn_ptr->vf(what, what_stride, best_address, in_what_stride, &thissad) +
mv_err_cost(&this_mv, center_mv, mvcost, x->errorperbit);
}
-#endif // HAVE_SSE2 || HAVE_MSA
-
-int vp8_full_search_sad_c(MACROBLOCK *x, BLOCK *b, BLOCKD *d, int_mv *ref_mv,
- int sad_per_bit, int distance,
- vp8_variance_fn_ptr_t *fn_ptr, int *mvcost[2],
- int_mv *center_mv) {
- unsigned char *what = (*(b->base_src) + b->src);
- int what_stride = b->src_stride;
- unsigned char *in_what;
- int pre_stride = x->e_mbd.pre.y_stride;
- unsigned char *base_pre = x->e_mbd.pre.y_buffer;
- int in_what_stride = pre_stride;
- int mv_stride = pre_stride;
- unsigned char *bestaddress;
- int_mv *best_mv = &d->bmi.mv;
- int_mv this_mv;
- unsigned int bestsad;
- unsigned int thissad;
- int r, c;
-
- unsigned char *check_here;
-
- int ref_row = ref_mv->as_mv.row;
- int ref_col = ref_mv->as_mv.col;
-
- int row_min = ref_row - distance;
- int row_max = ref_row + distance;
- int col_min = ref_col - distance;
- int col_max = ref_col + distance;
-
- int *mvsadcost[2];
- int_mv fcenter_mv;
-
- mvsadcost[0] = x->mvsadcost[0];
- mvsadcost[1] = x->mvsadcost[1];
- fcenter_mv.as_mv.row = center_mv->as_mv.row >> 3;
- fcenter_mv.as_mv.col = center_mv->as_mv.col >> 3;
-
- /* Work out the mid point for the search */
- in_what = base_pre + d->offset;
- bestaddress = in_what + (ref_row * pre_stride) + ref_col;
-
- best_mv->as_mv.row = ref_row;
- best_mv->as_mv.col = ref_col;
-
- /* Baseline value at the centre */
- bestsad = fn_ptr->sdf(what, what_stride, bestaddress, in_what_stride) +
- mvsad_err_cost(best_mv, &fcenter_mv, mvsadcost, sad_per_bit);
-
- /* Apply further limits to prevent us looking using vectors that
- * stretch beyiond the UMV border
- */
- if (col_min < x->mv_col_min) col_min = x->mv_col_min;
-
- if (col_max > x->mv_col_max) col_max = x->mv_col_max;
-
- if (row_min < x->mv_row_min) row_min = x->mv_row_min;
-
- if (row_max > x->mv_row_max) row_max = x->mv_row_max;
-
- for (r = row_min; r < row_max; ++r) {
- this_mv.as_mv.row = r;
- check_here = r * mv_stride + in_what + col_min;
-
- for (c = col_min; c < col_max; ++c) {
- thissad = fn_ptr->sdf(what, what_stride, check_here, in_what_stride);
-
- this_mv.as_mv.col = c;
- thissad += mvsad_err_cost(&this_mv, &fcenter_mv, mvsadcost, sad_per_bit);
-
- if (thissad < bestsad) {
- bestsad = thissad;
- best_mv->as_mv.row = r;
- best_mv->as_mv.col = c;
- bestaddress = check_here;
- }
-
- check_here++;
- }
- }
-
- this_mv.as_mv.row = best_mv->as_mv.row << 3;
- this_mv.as_mv.col = best_mv->as_mv.col << 3;
-
- return fn_ptr->vf(what, what_stride, bestaddress, in_what_stride, &thissad) +
- mv_err_cost(&this_mv, center_mv, mvcost, x->errorperbit);
-}
+#endif // HAVE_SSE2 || HAVE_MSA || HAVE_LSX
-#if HAVE_SSSE3
-int vp8_full_search_sadx3(MACROBLOCK *x, BLOCK *b, BLOCKD *d, int_mv *ref_mv,
- int sad_per_bit, int distance,
- vp8_variance_fn_ptr_t *fn_ptr, int *mvcost[2],
- int_mv *center_mv) {
+int vp8_full_search_sad(MACROBLOCK *x, BLOCK *b, BLOCKD *d, int_mv *ref_mv,
+ int sad_per_bit, int distance,
+ vp8_variance_fn_ptr_t *fn_ptr, int *mvcost[2],
+ int_mv *center_mv) {
unsigned char *what = (*(b->base_src) + b->src);
int what_stride = b->src_stride;
unsigned char *in_what;
@@ -1393,130 +1308,6 @@ int vp8_full_search_sadx3(MACROBLOCK *x, BLOCK *b, BLOCKD *d, int_mv *ref_mv,
int col_min = ref_col - distance;
int col_max = ref_col + distance;
- unsigned int sad_array[3];
-
- int *mvsadcost[2];
- int_mv fcenter_mv;
-
- mvsadcost[0] = x->mvsadcost[0];
- mvsadcost[1] = x->mvsadcost[1];
- fcenter_mv.as_mv.row = center_mv->as_mv.row >> 3;
- fcenter_mv.as_mv.col = center_mv->as_mv.col >> 3;
-
- /* Work out the mid point for the search */
- in_what = base_pre + d->offset;
- bestaddress = in_what + (ref_row * pre_stride) + ref_col;
-
- best_mv->as_mv.row = ref_row;
- best_mv->as_mv.col = ref_col;
-
- /* Baseline value at the centre */
- bestsad = fn_ptr->sdf(what, what_stride, bestaddress, in_what_stride) +
- mvsad_err_cost(best_mv, &fcenter_mv, mvsadcost, sad_per_bit);
-
- /* Apply further limits to prevent us looking using vectors that stretch
- * beyond the UMV border
- */
- if (col_min < x->mv_col_min) col_min = x->mv_col_min;
-
- if (col_max > x->mv_col_max) col_max = x->mv_col_max;
-
- if (row_min < x->mv_row_min) row_min = x->mv_row_min;
-
- if (row_max > x->mv_row_max) row_max = x->mv_row_max;
-
- for (r = row_min; r < row_max; ++r) {
- this_mv.as_mv.row = r;
- check_here = r * mv_stride + in_what + col_min;
- c = col_min;
-
- while ((c + 2) < col_max) {
- int i;
-
- fn_ptr->sdx3f(what, what_stride, check_here, in_what_stride, sad_array);
-
- for (i = 0; i < 3; ++i) {
- thissad = sad_array[i];
-
- if (thissad < bestsad) {
- this_mv.as_mv.col = c;
- thissad +=
- mvsad_err_cost(&this_mv, &fcenter_mv, mvsadcost, sad_per_bit);
-
- if (thissad < bestsad) {
- bestsad = thissad;
- best_mv->as_mv.row = r;
- best_mv->as_mv.col = c;
- bestaddress = check_here;
- }
- }
-
- check_here++;
- c++;
- }
- }
-
- while (c < col_max) {
- thissad = fn_ptr->sdf(what, what_stride, check_here, in_what_stride);
-
- if (thissad < bestsad) {
- this_mv.as_mv.col = c;
- thissad +=
- mvsad_err_cost(&this_mv, &fcenter_mv, mvsadcost, sad_per_bit);
-
- if (thissad < bestsad) {
- bestsad = thissad;
- best_mv->as_mv.row = r;
- best_mv->as_mv.col = c;
- bestaddress = check_here;
- }
- }
-
- check_here++;
- c++;
- }
- }
-
- this_mv.as_mv.row = best_mv->as_mv.row << 3;
- this_mv.as_mv.col = best_mv->as_mv.col << 3;
-
- return fn_ptr->vf(what, what_stride, bestaddress, in_what_stride, &thissad) +
- mv_err_cost(&this_mv, center_mv, mvcost, x->errorperbit);
-}
-#endif // HAVE_SSSE3
-
-#if HAVE_SSE4_1
-int vp8_full_search_sadx8(MACROBLOCK *x, BLOCK *b, BLOCKD *d, int_mv *ref_mv,
- int sad_per_bit, int distance,
- vp8_variance_fn_ptr_t *fn_ptr, int *mvcost[2],
- int_mv *center_mv) {
- unsigned char *what = (*(b->base_src) + b->src);
- int what_stride = b->src_stride;
- int pre_stride = x->e_mbd.pre.y_stride;
- unsigned char *base_pre = x->e_mbd.pre.y_buffer;
- unsigned char *in_what;
- int in_what_stride = pre_stride;
- int mv_stride = pre_stride;
- unsigned char *bestaddress;
- int_mv *best_mv = &d->bmi.mv;
- int_mv this_mv;
- unsigned int bestsad;
- unsigned int thissad;
- int r, c;
-
- unsigned char *check_here;
-
- int ref_row = ref_mv->as_mv.row;
- int ref_col = ref_mv->as_mv.col;
-
- int row_min = ref_row - distance;
- int row_max = ref_row + distance;
- int col_min = ref_col - distance;
- int col_max = ref_col + distance;
-
- DECLARE_ALIGNED(16, unsigned int, sad_array8[8]);
- unsigned int sad_array[3];
-
int *mvsadcost[2];
int_mv fcenter_mv;
@@ -1550,61 +1341,8 @@ int vp8_full_search_sadx8(MACROBLOCK *x, BLOCK *b, BLOCKD *d, int_mv *ref_mv,
for (r = row_min; r < row_max; ++r) {
this_mv.as_mv.row = r;
check_here = r * mv_stride + in_what + col_min;
- c = col_min;
- while ((c + 7) < col_max) {
- int i;
-
- fn_ptr->sdx8f(what, what_stride, check_here, in_what_stride, sad_array8);
-
- for (i = 0; i < 8; ++i) {
- thissad = sad_array8[i];
-
- if (thissad < bestsad) {
- this_mv.as_mv.col = c;
- thissad +=
- mvsad_err_cost(&this_mv, &fcenter_mv, mvsadcost, sad_per_bit);
-
- if (thissad < bestsad) {
- bestsad = thissad;
- best_mv->as_mv.row = r;
- best_mv->as_mv.col = c;
- bestaddress = check_here;
- }
- }
-
- check_here++;
- c++;
- }
- }
-
- while ((c + 2) < col_max) {
- int i;
-
- fn_ptr->sdx3f(what, what_stride, check_here, in_what_stride, sad_array);
-
- for (i = 0; i < 3; ++i) {
- thissad = sad_array[i];
-
- if (thissad < bestsad) {
- this_mv.as_mv.col = c;
- thissad +=
- mvsad_err_cost(&this_mv, &fcenter_mv, mvsadcost, sad_per_bit);
-
- if (thissad < bestsad) {
- bestsad = thissad;
- best_mv->as_mv.row = r;
- best_mv->as_mv.col = c;
- bestaddress = check_here;
- }
- }
-
- check_here++;
- c++;
- }
- }
-
- while (c < col_max) {
+ for (c = col_min; c < col_max; ++c) {
thissad = fn_ptr->sdf(what, what_stride, check_here, in_what_stride);
if (thissad < bestsad) {
@@ -1621,7 +1359,6 @@ int vp8_full_search_sadx8(MACROBLOCK *x, BLOCK *b, BLOCKD *d, int_mv *ref_mv,
}
check_here++;
- c++;
}
}
@@ -1631,7 +1368,6 @@ int vp8_full_search_sadx8(MACROBLOCK *x, BLOCK *b, BLOCKD *d, int_mv *ref_mv,
return fn_ptr->vf(what, what_stride, bestaddress, in_what_stride, &thissad) +
mv_err_cost(&this_mv, center_mv, mvcost, x->errorperbit);
}
-#endif // HAVE_SSE4_1
int vp8_refining_search_sad_c(MACROBLOCK *x, BLOCK *b, BLOCKD *d,
int_mv *ref_mv, int error_per_bit,