Merge "Allocate source buffers to be multiples of 16"
diff --git a/vp8/decoder/threading.c b/vp8/decoder/threading.c
index 271249a..2388909 100644
--- a/vp8/decoder/threading.c
+++ b/vp8/decoder/threading.c
@@ -473,22 +473,16 @@
 
     if (pbi->b_multithreaded_rd)
     {
-        if (pbi->mt_current_mb_col)
-        {
             vpx_free(pbi->mt_current_mb_col);
             pbi->mt_current_mb_col = NULL ;
-        }
 
         /* Free above_row buffers. */
         if (pbi->mt_yabove_row)
         {
             for (i=0; i< mb_rows; i++)
             {
-                if (pbi->mt_yabove_row[i])
-                {
                     vpx_free(pbi->mt_yabove_row[i]);
                     pbi->mt_yabove_row[i] = NULL ;
-                }
             }
             vpx_free(pbi->mt_yabove_row);
             pbi->mt_yabove_row = NULL ;
@@ -498,11 +492,8 @@
         {
             for (i=0; i< mb_rows; i++)
             {
-                if (pbi->mt_uabove_row[i])
-                {
                     vpx_free(pbi->mt_uabove_row[i]);
                     pbi->mt_uabove_row[i] = NULL ;
-                }
             }
             vpx_free(pbi->mt_uabove_row);
             pbi->mt_uabove_row = NULL ;
@@ -512,11 +503,8 @@
         {
             for (i=0; i< mb_rows; i++)
             {
-                if (pbi->mt_vabove_row[i])
-                {
                     vpx_free(pbi->mt_vabove_row[i]);
                     pbi->mt_vabove_row[i] = NULL ;
-                }
             }
             vpx_free(pbi->mt_vabove_row);
             pbi->mt_vabove_row = NULL ;
@@ -527,11 +515,8 @@
         {
             for (i=0; i< mb_rows; i++)
             {
-                if (pbi->mt_yleft_col[i])
-                {
                     vpx_free(pbi->mt_yleft_col[i]);
                     pbi->mt_yleft_col[i] = NULL ;
-                }
             }
             vpx_free(pbi->mt_yleft_col);
             pbi->mt_yleft_col = NULL ;
@@ -541,11 +526,8 @@
         {
             for (i=0; i< mb_rows; i++)
             {
-                if (pbi->mt_uleft_col[i])
-                {
                     vpx_free(pbi->mt_uleft_col[i]);
                     pbi->mt_uleft_col[i] = NULL ;
-                }
             }
             vpx_free(pbi->mt_uleft_col);
             pbi->mt_uleft_col = NULL ;
@@ -555,11 +537,8 @@
         {
             for (i=0; i< mb_rows; i++)
             {
-                if (pbi->mt_vleft_col[i])
-                {
                     vpx_free(pbi->mt_vleft_col[i]);
                     pbi->mt_vleft_col[i] = NULL ;
-                }
             }
             vpx_free(pbi->mt_vleft_col);
             pbi->mt_vleft_col = NULL ;
@@ -644,29 +623,17 @@
 
         sem_destroy(&pbi->h_event_end_decoding);
 
-        if (pbi->h_decoding_thread)
-        {
             vpx_free(pbi->h_decoding_thread);
             pbi->h_decoding_thread = NULL;
-        }
 
-        if (pbi->h_event_start_decoding)
-        {
             vpx_free(pbi->h_event_start_decoding);
             pbi->h_event_start_decoding = NULL;
-        }
 
-        if (pbi->mb_row_di)
-        {
             vpx_free(pbi->mb_row_di);
             pbi->mb_row_di = NULL ;
-        }
 
-        if (pbi->de_thread_data)
-        {
             vpx_free(pbi->de_thread_data);
             pbi->de_thread_data = NULL;
-        }
     }
 }
 
diff --git a/vp8/encoder/arm/arm_csystemdependent.c b/vp8/encoder/arm/arm_csystemdependent.c
index 6c17a79..cec35d5 100644
--- a/vp8/encoder/arm/arm_csystemdependent.c
+++ b/vp8/encoder/arm/arm_csystemdependent.c
@@ -29,8 +29,8 @@
 #if HAVE_ARMV6
     if (has_media)
     {
-        /*cpi->rtcd.variance.sad16x16              = vp8_sad16x16_c;
-        cpi->rtcd.variance.sad16x8               = vp8_sad16x8_c;
+        cpi->rtcd.variance.sad16x16              = vp8_sad16x16_armv6;
+        /*cpi->rtcd.variance.sad16x8               = vp8_sad16x8_c;
         cpi->rtcd.variance.sad8x16               = vp8_sad8x16_c;
         cpi->rtcd.variance.sad8x8                = vp8_sad8x8_c;
         cpi->rtcd.variance.sad4x4                = vp8_sad4x4_c;*/
diff --git a/vp8/encoder/arm/armv6/vp8_sad16x16_armv6.asm b/vp8/encoder/arm/armv6/vp8_sad16x16_armv6.asm
new file mode 100644
index 0000000..c759f7c
--- /dev/null
+++ b/vp8/encoder/arm/armv6/vp8_sad16x16_armv6.asm
@@ -0,0 +1,84 @@
+;
+;  Copyright (c) 2011 The WebM project authors. All Rights Reserved.
+;
+;  Use of this source code is governed by a BSD-style license
+;  that can be found in the LICENSE file in the root of the source
+;  tree. An additional intellectual property rights grant can be found
+;  in the file PATENTS.  All contributing project authors may
+;  be found in the AUTHORS file in the root of the source tree.
+;
+
+
+    EXPORT  |vp8_sad16x16_armv6|
+
+    ARM
+    REQUIRE8
+    PRESERVE8
+
+    AREA ||.text||, CODE, READONLY, ALIGN=2
+
+; r0    const unsigned char *src_ptr
+; r1    int  src_stride
+; r2    const unsigned char *ref_ptr
+; r3    int  ref_stride
+; stack max_sad (not used)
+|vp8_sad16x16_armv6| PROC
+    stmfd   sp!, {r4-r12, lr}
+    mov     r4, #0              ; sad = 0;
+    mov     r5, #8              ; loop count
+
+loop
+    ; 1st row
+    ldr     r6, [r0, #0x0]      ; load 4 src pixels (1A)
+    ldr     r8, [r2, #0x0]      ; load 4 ref pixels (1A)
+    ldr     r7, [r0, #0x4]      ; load 4 src pixels (1A)
+    ldr     r9, [r2, #0x4]      ; load 4 ref pixels (1A)
+    ldr     r10, [r0, #0x8]     ; load 4 src pixels (1B)
+    ldr     r11, [r0, #0xC]     ; load 4 src pixels (1B)
+
+    usada8  r4, r8, r6, r4      ; calculate sad for 4 pixels
+    usad8   r8, r7, r9          ; calculate sad for 4 pixels
+
+    ldr     r12, [r2, #0x8]     ; load 4 ref pixels (1B)
+    ldr     lr, [r2, #0xC]      ; load 4 ref pixels (1B)
+
+    add     r0, r0, r1          ; set src pointer to next row
+    add     r2, r2, r3          ; set dst pointer to next row
+
+    usada8  r4, r10, r12, r4    ; calculate sad for 4 pixels
+    usada8  r8, r11, lr, r8     ; calculate sad for 4 pixels
+
+    ldr     r6, [r0, #0x0]      ; load 4 src pixels (2A)
+    ldr     r7, [r0, #0x4]      ; load 4 src pixels (2A)
+    add     r4, r4, r8          ; add partial sad values
+
+    ; 2nd row
+    ldr     r8, [r2, #0x0]      ; load 4 ref pixels (2A)
+    ldr     r9, [r2, #0x4]      ; load 4 ref pixels (2A)
+    ldr     r10, [r0, #0x8]     ; load 4 src pixels (2B)
+    ldr     r11, [r0, #0xC]     ; load 4 src pixels (2B)
+
+    usada8  r4, r6, r8, r4      ; calculate sad for 4 pixels
+    usad8   r8, r7, r9          ; calculate sad for 4 pixels
+
+    ldr     r12, [r2, #0x8]     ; load 4 ref pixels (2B)
+    ldr     lr, [r2, #0xC]      ; load 4 ref pixels (2B)
+
+    add     r0, r0, r1          ; set src pointer to next row
+    add     r2, r2, r3          ; set dst pointer to next row
+
+    usada8  r4, r10, r12, r4    ; calculate sad for 4 pixels
+    usada8  r8, r11, lr, r8     ; calculate sad for 4 pixels
+
+    subs    r5, r5, #1          ; decrement loop counter
+    add     r4, r4, r8          ; add partial sad values
+
+    bne     loop
+
+    mov     r0, r4              ; return sad
+    ldmfd   sp!, {r4-r12, pc}
+
+    ENDP
+
+    END
+
diff --git a/vp8/encoder/arm/variance_arm.h b/vp8/encoder/arm/variance_arm.h
index 06d7287..c807e29 100644
--- a/vp8/encoder/arm/variance_arm.h
+++ b/vp8/encoder/arm/variance_arm.h
@@ -14,11 +14,15 @@
 
 #if HAVE_ARMV6
 
+extern prototype_sad(vp8_sad16x16_armv6);
 extern prototype_variance(vp8_variance16x16_armv6);
 extern prototype_subpixvariance(vp8_sub_pixel_variance16x16_armv6);
 
 #if !CONFIG_RUNTIME_CPU_DETECT
 
+#undef  vp8_variance_sad16x16
+#define vp8_variance_sad16x16 vp8_sad16x16_armv6
+
 #undef  vp8_variance_subpixvar16x16
 #define vp8_variance_subpixvar16x16 vp8_sub_pixel_variance16x16_armv6
 
diff --git a/vp8/encoder/onyx_if.c b/vp8/encoder/onyx_if.c
index 47c46ca..8baa001 100644
--- a/vp8/encoder/onyx_if.c
+++ b/vp8/encoder/onyx_if.c
@@ -262,39 +262,32 @@
 
 void vp8_dealloc_compressor_data(VP8_COMP *cpi)
 {
-    if(cpi->tplist!=0)
         vpx_free(cpi->tplist);
     cpi->tplist = NULL;
 
     // Delete last frame MV storage buffers
-    if (cpi->lfmv != 0)
         vpx_free(cpi->lfmv);
 
     cpi->lfmv = 0;
 
-    if (cpi->lf_ref_frame_sign_bias != 0)
         vpx_free(cpi->lf_ref_frame_sign_bias);
 
     cpi->lf_ref_frame_sign_bias = 0;
 
-    if (cpi->lf_ref_frame != 0)
         vpx_free(cpi->lf_ref_frame);
 
     cpi->lf_ref_frame = 0;
 
     // Delete sementation map
-    if (cpi->segmentation_map != 0)
         vpx_free(cpi->segmentation_map);
 
     cpi->segmentation_map = 0;
 
-    if (cpi->active_map != 0)
         vpx_free(cpi->active_map);
 
     cpi->active_map = 0;
 
     // Delete first pass motion map
-    if (cpi->fp_motion_map != 0)
         vpx_free(cpi->fp_motion_map);
 
     cpi->fp_motion_map = 0;
@@ -319,23 +312,19 @@
     cpi->tok = 0;
 
     // Structure used to monitor GF usage
-    if (cpi->gf_active_flags != 0)
         vpx_free(cpi->gf_active_flags);
 
     cpi->gf_active_flags = 0;
 
-    if(cpi->mb.pip)
         vpx_free(cpi->mb.pip);
 
     cpi->mb.pip = 0;
 
 #if !(CONFIG_REALTIME_ONLY)
-    if(cpi->total_stats)
         vpx_free(cpi->total_stats);
 
     cpi->total_stats = 0;
 
-    if(cpi->this_frame_stats)
         vpx_free(cpi->this_frame_stats);
 
     cpi->this_frame_stats = 0;
@@ -442,7 +431,6 @@
     set_segment_data(ptr, &feature_data[0][0], SEGMENT_DELTADATA);
 
     // Delete sementation map
-    if (seg_map != 0)
         vpx_free(seg_map);
 
     seg_map = 0;
@@ -536,7 +524,6 @@
     set_segment_data((VP8_PTR)cpi, &feature_data[0][0], SEGMENT_DELTADATA);
 
     // Delete sementation map
-    if (seg_map != 0)
         vpx_free(seg_map);
 
     seg_map = 0;
@@ -1312,7 +1299,6 @@
 
 static int vp8_alloc_partition_data(VP8_COMP *cpi)
 {
-    if(cpi->mb.pip)
         vpx_free(cpi->mb.pip);
 
     cpi->mb.pip = vpx_calloc((cpi->common.mb_cols + 1) *
@@ -1359,7 +1345,6 @@
                            "Failed to allocate scaled source buffer");
 
 
-    if (cpi->tok != 0)
         vpx_free(cpi->tok);
 
     {
@@ -1375,7 +1360,6 @@
 
 
     // Structures used to minitor GF usage
-    if (cpi->gf_active_flags != 0)
         vpx_free(cpi->gf_active_flags);
 
     CHECK_MEM_ERROR(cpi->gf_active_flags, vpx_calloc(1, cm->mb_rows * cm->mb_cols));
@@ -1383,12 +1367,10 @@
     cpi->gf_active_count = cm->mb_rows * cm->mb_cols;
 
 #if !(CONFIG_REALTIME_ONLY)
-    if(cpi->total_stats)
         vpx_free(cpi->total_stats);
 
     cpi->total_stats = vpx_calloc(1, vp8_firstpass_stats_sz(cpi->common.MBs));
 
-    if(cpi->this_frame_stats)
         vpx_free(cpi->this_frame_stats);
 
     cpi->this_frame_stats = vpx_calloc(1, vp8_firstpass_stats_sz(cpi->common.MBs));
@@ -1409,7 +1391,6 @@
         cpi->mt_sync_range = 16;
 #endif
 
-    if(cpi->tplist);
         vpx_free(cpi->tplist);
 
     CHECK_MEM_ERROR(cpi->tplist, vpx_malloc(sizeof(TOKENLIST) * cpi->common.mb_rows));
diff --git a/vp8/vp8cx_arm.mk b/vp8/vp8cx_arm.mk
index abc5dc8..7980a0f 100644
--- a/vp8/vp8cx_arm.mk
+++ b/vp8/vp8cx_arm.mk
@@ -34,6 +34,7 @@
 
 #File list for armv6
 # encoder
+VP8_CX_SRCS-$(HAVE_ARMV6)  += encoder/arm/armv6/vp8_sad16x16_armv6$(ASM)
 VP8_CX_SRCS-$(HAVE_ARMV6)  += encoder/arm/armv6/vp8_variance16x16_armv6$(ASM)
 VP8_CX_SRCS-$(HAVE_ARMV6)  += encoder/arm/armv6/walsh_v6$(ASM)
 
diff --git a/vpx_scale/blackfin/yv12config.c b/vpx_scale/blackfin/yv12config.c
index 42538af..c404202 100644
--- a/vpx_scale/blackfin/yv12config.c
+++ b/vpx_scale/blackfin/yv12config.c
@@ -39,10 +39,7 @@
 {
     if (ybf)
     {
-        if (ybf->buffer_alloc)
-        {
             duck_free(ybf->buffer_alloc);
-        }
 
         ybf->buffer_alloc = 0;
     }
diff --git a/vpx_scale/generic/bicubic_scaler.c b/vpx_scale/generic/bicubic_scaler.c
index 420f719..4468e9d 100644
--- a/vpx_scale/generic/bicubic_scaler.c
+++ b/vpx_scale/generic/bicubic_scaler.c
@@ -271,17 +271,17 @@
 {
     if (!g_first_time)
     {
-        if (g_b_scaler.l_w) vpx_free(g_b_scaler.l_w);
+        vpx_free(g_b_scaler.l_w);
 
-        if (g_b_scaler.l_h) vpx_free(g_b_scaler.l_h);
+        vpx_free(g_b_scaler.l_h);
 
-        if (g_b_scaler.l_h_uv) vpx_free(g_b_scaler.l_h_uv);
+        vpx_free(g_b_scaler.l_h_uv);
 
-        if (g_b_scaler.c_w) vpx_free(g_b_scaler.c_w);
+        vpx_free(g_b_scaler.c_w);
 
-        if (g_b_scaler.c_h) vpx_free(g_b_scaler.c_h);
+        vpx_free(g_b_scaler.c_h);
 
-        if (g_b_scaler.c_h_uv) vpx_free(g_b_scaler.c_h_uv);
+        vpx_free(g_b_scaler.c_h_uv);
 
         vpx_memset(&g_b_scaler, 0, sizeof(BICUBIC_SCALER_STRUCT));
     }
@@ -342,21 +342,21 @@
     d_h_uv = (in_height / 2) / gcd_h_uv;
 
     // allocate memory for the coefficents
-    if (g_b_scaler.l_w) vpx_free(g_b_scaler.l_w);
+    vpx_free(g_b_scaler.l_w);
 
-    if (g_b_scaler.l_h) vpx_free(g_b_scaler.l_h);
+    vpx_free(g_b_scaler.l_h);
 
-    if (g_b_scaler.l_h_uv) vpx_free(g_b_scaler.l_h_uv);
+    vpx_free(g_b_scaler.l_h_uv);
 
     g_b_scaler.l_w = (short *)vpx_memalign(32, out_width * 2);
     g_b_scaler.l_h = (short *)vpx_memalign(32, out_height * 2);
     g_b_scaler.l_h_uv = (short *)vpx_memalign(32, out_height * 2);
 
-    if (g_b_scaler.c_w) vpx_free(g_b_scaler.c_w);
+    vpx_free(g_b_scaler.c_w);
 
-    if (g_b_scaler.c_h) vpx_free(g_b_scaler.c_h);
+    vpx_free(g_b_scaler.c_h);
 
-    if (g_b_scaler.c_h_uv) vpx_free(g_b_scaler.c_h_uv);
+    vpx_free(g_b_scaler.c_h_uv);
 
     g_b_scaler.c_w = (short *)vpx_memalign(32, g_b_scaler.nw * 4 * 2);
     g_b_scaler.c_h = (short *)vpx_memalign(32, g_b_scaler.nh * 4 * 2);
diff --git a/vpx_scale/generic/yv12config.c b/vpx_scale/generic/yv12config.c
index e7c5b18..9539dca 100644
--- a/vpx_scale/generic/yv12config.c
+++ b/vpx_scale/generic/yv12config.c
@@ -24,10 +24,7 @@
 {
     if (ybf)
     {
-        if (ybf->buffer_alloc)
-        {
             duck_free(ybf->buffer_alloc);
-        }
 
         ybf->buffer_alloc = 0;
     }