shithub: libvpx

Download patch

ref: c02a4beed882521dd1ddcecbda88934868ea5844
parent: f14c323b4ca8c15ad3f8a2dcf69c75845399cb66
parent: 63a37d16f332350ae79620543dcb6bf5cd6d19ec
author: Yaowu Xu <[email protected]>
date: Wed Jun 29 16:53:36 EDT 2016

Merge "Prevent negative variance"

--- a/vpx_dsp/x86/highbd_variance_sse2.c
+++ b/vpx_dsp/x86/highbd_variance_sse2.c
@@ -143,12 +143,14 @@
     const uint8_t *src8, int src_stride, \
     const uint8_t *ref8, int ref_stride, uint32_t *sse) { \
   int sum; \
+  int64_t var; \
   uint16_t *src = CONVERT_TO_SHORTPTR(src8); \
   uint16_t *ref = CONVERT_TO_SHORTPTR(ref8); \
   highbd_10_variance_sse2( \
       src, src_stride, ref, ref_stride, w, h, sse, &sum, \
       vpx_highbd_calc##block_size##x##block_size##var_sse2, block_size); \
-  return *sse - (((int64_t)sum * sum) >> shift); \
+  var = (int64_t)(*sse) - (((int64_t)sum * sum) >> shift); \
+  return (var >= 0) ? (uint32_t)var : 0; \
 } \
 \
 uint32_t vpx_highbd_12_variance##w##x##h##_sse2( \
@@ -155,12 +157,14 @@
     const uint8_t *src8, int src_stride, \
     const uint8_t *ref8, int ref_stride, uint32_t *sse) { \
   int sum; \
+  int64_t var; \
   uint16_t *src = CONVERT_TO_SHORTPTR(src8); \
   uint16_t *ref = CONVERT_TO_SHORTPTR(ref8); \
   highbd_12_variance_sse2( \
       src, src_stride, ref, ref_stride, w, h, sse, &sum, \
       vpx_highbd_calc##block_size##x##block_size##var_sse2, block_size); \
-  return *sse - (((int64_t)sum * sum) >> shift); \
+  var = (int64_t)(*sse) - (((int64_t)sum * sum) >> shift); \
+  return (var >= 0) ? (uint32_t)var : 0; \
 }
 
 VAR_FN(64, 64, 16, 12);