]> granicus.if.org Git - libvpx/commitdiff
Remove vp8, vp9 folders
authorYaowu Xu <yaowu@google.com>
Mon, 25 Jul 2016 22:39:46 +0000 (15:39 -0700)
committerYaowu Xu <yaowu@google.com>
Thu, 28 Jul 2016 14:33:21 +0000 (14:33 +0000)
Change-Id: I09b8acd22d031ece52e1fee18b998349bf1cf06b

433 files changed:
configure
examples.mk
libs.mk
test/blockiness_test.cc
test/consistency_test.cc
test/convolve_test.cc
test/dct16x16_test.cc
test/dct32x32_test.cc
test/encode_api_test.cc
test/fdct4x4_test.cc
test/fdct8x8_test.cc
test/idct_test.cc
test/partial_idct_test.cc
test/quantize_test.cc
test/sixtap_predict_test.cc
test/test.mk
test/vp10_convolve_test.cc
test/vp10_inv_txfm_test.cc
test/vp8_fdct4x4_test.cc
test/vp9_error_block_test.cc
tools_common.c
vp10/vp10_common.mk
vp8/common/alloccommon.c [deleted file]
vp8/common/alloccommon.h [deleted file]
vp8/common/arm/armv6/bilinearfilter_v6.asm [deleted file]
vp8/common/arm/armv6/copymem16x16_v6.asm [deleted file]
vp8/common/arm/armv6/copymem8x4_v6.asm [deleted file]
vp8/common/arm/armv6/copymem8x8_v6.asm [deleted file]
vp8/common/arm/armv6/dc_only_idct_add_v6.asm [deleted file]
vp8/common/arm/armv6/dequant_idct_v6.asm [deleted file]
vp8/common/arm/armv6/dequantize_v6.asm [deleted file]
vp8/common/arm/armv6/filter_v6.asm [deleted file]
vp8/common/arm/armv6/idct_blk_v6.c [deleted file]
vp8/common/arm/armv6/idct_v6.asm [deleted file]
vp8/common/arm/armv6/iwalsh_v6.asm [deleted file]
vp8/common/arm/armv6/loopfilter_v6.asm [deleted file]
vp8/common/arm/armv6/simpleloopfilter_v6.asm [deleted file]
vp8/common/arm/armv6/sixtappredict8x4_v6.asm [deleted file]
vp8/common/arm/bilinearfilter_arm.c [deleted file]
vp8/common/arm/bilinearfilter_arm.h [deleted file]
vp8/common/arm/dequantize_arm.c [deleted file]
vp8/common/arm/filter_arm.c [deleted file]
vp8/common/arm/loopfilter_arm.c [deleted file]
vp8/common/arm/neon/bilinearpredict_neon.c [deleted file]
vp8/common/arm/neon/copymem_neon.c [deleted file]
vp8/common/arm/neon/dc_only_idct_add_neon.c [deleted file]
vp8/common/arm/neon/dequant_idct_neon.c [deleted file]
vp8/common/arm/neon/dequantizeb_neon.c [deleted file]
vp8/common/arm/neon/idct_blk_neon.c [deleted file]
vp8/common/arm/neon/idct_dequant_0_2x_neon.c [deleted file]
vp8/common/arm/neon/idct_dequant_full_2x_neon.c [deleted file]
vp8/common/arm/neon/iwalsh_neon.c [deleted file]
vp8/common/arm/neon/loopfiltersimplehorizontaledge_neon.c [deleted file]
vp8/common/arm/neon/loopfiltersimpleverticaledge_neon.c [deleted file]
vp8/common/arm/neon/mbloopfilter_neon.c [deleted file]
vp8/common/arm/neon/shortidct4x4llm_neon.c [deleted file]
vp8/common/arm/neon/sixtappredict_neon.c [deleted file]
vp8/common/arm/neon/vp8_loopfilter_neon.c [deleted file]
vp8/common/blockd.c [deleted file]
vp8/common/blockd.h [deleted file]
vp8/common/coefupdateprobs.h [deleted file]
vp8/common/common.h [deleted file]
vp8/common/context.c [deleted file]
vp8/common/copy_c.c [deleted file]
vp8/common/debugmodes.c [deleted file]
vp8/common/default_coef_probs.h [deleted file]
vp8/common/dequantize.c [deleted file]
vp8/common/entropy.c [deleted file]
vp8/common/entropy.h [deleted file]
vp8/common/entropymode.c [deleted file]
vp8/common/entropymode.h [deleted file]
vp8/common/entropymv.c [deleted file]
vp8/common/entropymv.h [deleted file]
vp8/common/extend.c [deleted file]
vp8/common/extend.h [deleted file]
vp8/common/filter.c [deleted file]
vp8/common/filter.h [deleted file]
vp8/common/findnearmv.c [deleted file]
vp8/common/findnearmv.h [deleted file]
vp8/common/generic/systemdependent.c [deleted file]
vp8/common/header.h [deleted file]
vp8/common/idct_blk.c [deleted file]
vp8/common/idctllm.c [deleted file]
vp8/common/invtrans.h [deleted file]
vp8/common/loopfilter.h [deleted file]
vp8/common/loopfilter_filters.c [deleted file]
vp8/common/mbpitch.c [deleted file]
vp8/common/mfqe.c [deleted file]
vp8/common/mips/dspr2/dequantize_dspr2.c [deleted file]
vp8/common/mips/dspr2/filter_dspr2.c [deleted file]
vp8/common/mips/dspr2/idct_blk_dspr2.c [deleted file]
vp8/common/mips/dspr2/idctllm_dspr2.c [deleted file]
vp8/common/mips/dspr2/reconinter_dspr2.c [deleted file]
vp8/common/mips/dspr2/vp8_loopfilter_filters_dspr2.c [deleted file]
vp8/common/mips/msa/bilinear_filter_msa.c [deleted file]
vp8/common/mips/msa/copymem_msa.c [deleted file]
vp8/common/mips/msa/idct_msa.c [deleted file]
vp8/common/mips/msa/loopfilter_filters_msa.c [deleted file]
vp8/common/mips/msa/mfqe_msa.c [deleted file]
vp8/common/mips/msa/sixtap_filter_msa.c [deleted file]
vp8/common/mips/msa/vp8_macros_msa.h [deleted file]
vp8/common/modecont.c [deleted file]
vp8/common/modecont.h [deleted file]
vp8/common/mv.h [deleted file]
vp8/common/onyx.h [deleted file]
vp8/common/onyxc_int.h [deleted file]
vp8/common/onyxd.h [deleted file]
vp8/common/postproc.c [deleted file]
vp8/common/postproc.h [deleted file]
vp8/common/ppflags.h [deleted file]
vp8/common/quant_common.c [deleted file]
vp8/common/quant_common.h [deleted file]
vp8/common/reconinter.c [deleted file]
vp8/common/reconinter.h [deleted file]
vp8/common/reconintra.c [deleted file]
vp8/common/reconintra.h [deleted file]
vp8/common/reconintra4x4.c [deleted file]
vp8/common/reconintra4x4.h [deleted file]
vp8/common/rtcd.c [deleted file]
vp8/common/rtcd_defs.pl [deleted file]
vp8/common/setupintrarecon.c [deleted file]
vp8/common/setupintrarecon.h [deleted file]
vp8/common/swapyv12buffer.c [deleted file]
vp8/common/swapyv12buffer.h [deleted file]
vp8/common/systemdependent.h [deleted file]
vp8/common/textblit.c [deleted file]
vp8/common/threading.h [deleted file]
vp8/common/treecoder.c [deleted file]
vp8/common/treecoder.h [deleted file]
vp8/common/vp8_entropymodedata.h [deleted file]
vp8/common/vp8_loopfilter.c [deleted file]
vp8/common/x86/copy_sse2.asm [deleted file]
vp8/common/x86/copy_sse3.asm [deleted file]
vp8/common/x86/dequantize_mmx.asm [deleted file]
vp8/common/x86/filter_x86.c [deleted file]
vp8/common/x86/filter_x86.h [deleted file]
vp8/common/x86/idct_blk_mmx.c [deleted file]
vp8/common/x86/idct_blk_sse2.c [deleted file]
vp8/common/x86/idctllm_mmx.asm [deleted file]
vp8/common/x86/idctllm_sse2.asm [deleted file]
vp8/common/x86/iwalsh_mmx.asm [deleted file]
vp8/common/x86/iwalsh_sse2.asm [deleted file]
vp8/common/x86/loopfilter_block_sse2_x86_64.asm [deleted file]
vp8/common/x86/loopfilter_sse2.asm [deleted file]
vp8/common/x86/loopfilter_x86.c [deleted file]
vp8/common/x86/mfqe_sse2.asm [deleted file]
vp8/common/x86/recon_mmx.asm [deleted file]
vp8/common/x86/recon_sse2.asm [deleted file]
vp8/common/x86/subpixel_mmx.asm [deleted file]
vp8/common/x86/subpixel_sse2.asm [deleted file]
vp8/common/x86/subpixel_ssse3.asm [deleted file]
vp8/common/x86/vp8_asm_stubs.c [deleted file]
vp8/common/x86/vp8_loopfilter_mmx.asm [deleted file]
vp8/decoder/dboolhuff.c [deleted file]
vp8/decoder/dboolhuff.h [deleted file]
vp8/decoder/decodeframe.c [deleted file]
vp8/decoder/decodemv.c [deleted file]
vp8/decoder/decodemv.h [deleted file]
vp8/decoder/decoderthreading.h [deleted file]
vp8/decoder/detokenize.c [deleted file]
vp8/decoder/detokenize.h [deleted file]
vp8/decoder/ec_types.h [deleted file]
vp8/decoder/error_concealment.c [deleted file]
vp8/decoder/error_concealment.h [deleted file]
vp8/decoder/onyxd_if.c [deleted file]
vp8/decoder/onyxd_int.h [deleted file]
vp8/decoder/threading.c [deleted file]
vp8/decoder/treereader.h [deleted file]
vp8/encoder/arm/armv6/vp8_short_fdct4x4_armv6.asm [deleted file]
vp8/encoder/arm/armv6/walsh_v6.asm [deleted file]
vp8/encoder/arm/dct_arm.c [deleted file]
vp8/encoder/arm/neon/denoising_neon.c [deleted file]
vp8/encoder/arm/neon/fastquantizeb_neon.c [deleted file]
vp8/encoder/arm/neon/shortfdct_neon.c [deleted file]
vp8/encoder/arm/neon/vp8_shortwalsh4x4_neon.c [deleted file]
vp8/encoder/bitstream.c [deleted file]
vp8/encoder/bitstream.h [deleted file]
vp8/encoder/block.h [deleted file]
vp8/encoder/boolhuff.c [deleted file]
vp8/encoder/boolhuff.h [deleted file]
vp8/encoder/dct.c [deleted file]
vp8/encoder/dct_value_cost.h [deleted file]
vp8/encoder/dct_value_tokens.h [deleted file]
vp8/encoder/defaultcoefcounts.h [deleted file]
vp8/encoder/denoising.c [deleted file]
vp8/encoder/denoising.h [deleted file]
vp8/encoder/encodeframe.c [deleted file]
vp8/encoder/encodeframe.h [deleted file]
vp8/encoder/encodeintra.c [deleted file]
vp8/encoder/encodeintra.h [deleted file]
vp8/encoder/encodemb.c [deleted file]
vp8/encoder/encodemb.h [deleted file]
vp8/encoder/encodemv.c [deleted file]
vp8/encoder/encodemv.h [deleted file]
vp8/encoder/ethreading.c [deleted file]
vp8/encoder/firstpass.c [deleted file]
vp8/encoder/firstpass.h [deleted file]
vp8/encoder/lookahead.c [deleted file]
vp8/encoder/lookahead.h [deleted file]
vp8/encoder/mcomp.c [deleted file]
vp8/encoder/mcomp.h [deleted file]
vp8/encoder/mips/msa/dct_msa.c [deleted file]
vp8/encoder/mips/msa/denoising_msa.c [deleted file]
vp8/encoder/mips/msa/encodeopt_msa.c [deleted file]
vp8/encoder/mips/msa/quantize_msa.c [deleted file]
vp8/encoder/mips/msa/temporal_filter_msa.c [deleted file]
vp8/encoder/modecosts.c [deleted file]
vp8/encoder/modecosts.h [deleted file]
vp8/encoder/mr_dissim.c [deleted file]
vp8/encoder/mr_dissim.h [deleted file]
vp8/encoder/onyx_if.c [deleted file]
vp8/encoder/onyx_int.h [deleted file]
vp8/encoder/pickinter.c [deleted file]
vp8/encoder/pickinter.h [deleted file]
vp8/encoder/picklpf.c [deleted file]
vp8/encoder/quantize.h [deleted file]
vp8/encoder/ratectrl.c [deleted file]
vp8/encoder/ratectrl.h [deleted file]
vp8/encoder/rdopt.c [deleted file]
vp8/encoder/rdopt.h [deleted file]
vp8/encoder/segmentation.c [deleted file]
vp8/encoder/segmentation.h [deleted file]
vp8/encoder/temporal_filter.c [deleted file]
vp8/encoder/tokenize.c [deleted file]
vp8/encoder/tokenize.h [deleted file]
vp8/encoder/treewriter.c [deleted file]
vp8/encoder/treewriter.h [deleted file]
vp8/encoder/vp8_quantize.c [deleted file]
vp8/encoder/x86/dct_mmx.asm [deleted file]
vp8/encoder/x86/dct_sse2.asm [deleted file]
vp8/encoder/x86/denoising_sse2.c [deleted file]
vp8/encoder/x86/encodeopt.asm [deleted file]
vp8/encoder/x86/fwalsh_sse2.asm [deleted file]
vp8/encoder/x86/quantize_mmx.asm [deleted file]
vp8/encoder/x86/quantize_sse4.c [deleted file]
vp8/encoder/x86/quantize_ssse3.c [deleted file]
vp8/encoder/x86/temporal_filter_apply_sse2.asm [deleted file]
vp8/encoder/x86/vp8_enc_stubs_mmx.c [deleted file]
vp8/encoder/x86/vp8_enc_stubs_sse2.c [deleted file]
vp8/encoder/x86/vp8_quantize_sse2.c [deleted file]
vp8/exports_dec [deleted file]
vp8/exports_enc [deleted file]
vp8/vp8_common.mk [deleted file]
vp8/vp8_cx_iface.c [deleted file]
vp8/vp8_dx_iface.c [deleted file]
vp8/vp8cx.mk [deleted file]
vp8/vp8cx_arm.mk [deleted file]
vp8/vp8dx.mk [deleted file]
vp9/common/arm/neon/vp9_iht4x4_add_neon.c [deleted file]
vp9/common/arm/neon/vp9_iht8x8_add_neon.c [deleted file]
vp9/common/mips/dspr2/vp9_itrans16_dspr2.c [deleted file]
vp9/common/mips/dspr2/vp9_itrans4_dspr2.c [deleted file]
vp9/common/mips/dspr2/vp9_itrans8_dspr2.c [deleted file]
vp9/common/mips/msa/vp9_idct16x16_msa.c [deleted file]
vp9/common/mips/msa/vp9_idct4x4_msa.c [deleted file]
vp9/common/mips/msa/vp9_idct8x8_msa.c [deleted file]
vp9/common/mips/msa/vp9_mfqe_msa.c [deleted file]
vp9/common/vp9_alloccommon.c [deleted file]
vp9/common/vp9_alloccommon.h [deleted file]
vp9/common/vp9_blockd.c [deleted file]
vp9/common/vp9_blockd.h [deleted file]
vp9/common/vp9_common.h [deleted file]
vp9/common/vp9_common_data.c [deleted file]
vp9/common/vp9_common_data.h [deleted file]
vp9/common/vp9_debugmodes.c [deleted file]
vp9/common/vp9_entropy.c [deleted file]
vp9/common/vp9_entropy.h [deleted file]
vp9/common/vp9_entropymode.c [deleted file]
vp9/common/vp9_entropymode.h [deleted file]
vp9/common/vp9_entropymv.c [deleted file]
vp9/common/vp9_entropymv.h [deleted file]
vp9/common/vp9_enums.h [deleted file]
vp9/common/vp9_filter.c [deleted file]
vp9/common/vp9_filter.h [deleted file]
vp9/common/vp9_frame_buffers.c [deleted file]
vp9/common/vp9_frame_buffers.h [deleted file]
vp9/common/vp9_idct.c [deleted file]
vp9/common/vp9_idct.h [deleted file]
vp9/common/vp9_loopfilter.c [deleted file]
vp9/common/vp9_loopfilter.h [deleted file]
vp9/common/vp9_mfqe.c [deleted file]
vp9/common/vp9_mfqe.h [deleted file]
vp9/common/vp9_mv.h [deleted file]
vp9/common/vp9_mvref_common.c [deleted file]
vp9/common/vp9_mvref_common.h [deleted file]
vp9/common/vp9_onyxc_int.h [deleted file]
vp9/common/vp9_postproc.c [deleted file]
vp9/common/vp9_postproc.h [deleted file]
vp9/common/vp9_ppflags.h [deleted file]
vp9/common/vp9_pred_common.c [deleted file]
vp9/common/vp9_pred_common.h [deleted file]
vp9/common/vp9_quant_common.c [deleted file]
vp9/common/vp9_quant_common.h [deleted file]
vp9/common/vp9_reconinter.c [deleted file]
vp9/common/vp9_reconinter.h [deleted file]
vp9/common/vp9_reconintra.c [deleted file]
vp9/common/vp9_reconintra.h [deleted file]
vp9/common/vp9_rtcd.c [deleted file]
vp9/common/vp9_rtcd_defs.pl [deleted file]
vp9/common/vp9_scale.c [deleted file]
vp9/common/vp9_scale.h [deleted file]
vp9/common/vp9_scan.c [deleted file]
vp9/common/vp9_scan.h [deleted file]
vp9/common/vp9_seg_common.c [deleted file]
vp9/common/vp9_seg_common.h [deleted file]
vp9/common/vp9_textblit.c [deleted file]
vp9/common/vp9_textblit.h [deleted file]
vp9/common/vp9_thread_common.c [deleted file]
vp9/common/vp9_thread_common.h [deleted file]
vp9/common/vp9_tile_common.c [deleted file]
vp9/common/vp9_tile_common.h [deleted file]
vp9/common/x86/vp9_idct_intrin_sse2.c [deleted file]
vp9/common/x86/vp9_mfqe_sse2.asm [deleted file]
vp9/decoder/vp9_decodeframe.c [deleted file]
vp9/decoder/vp9_decodeframe.h [deleted file]
vp9/decoder/vp9_decodemv.c [deleted file]
vp9/decoder/vp9_decodemv.h [deleted file]
vp9/decoder/vp9_decoder.c [deleted file]
vp9/decoder/vp9_decoder.h [deleted file]
vp9/decoder/vp9_detokenize.c [deleted file]
vp9/decoder/vp9_detokenize.h [deleted file]
vp9/decoder/vp9_dsubexp.c [deleted file]
vp9/decoder/vp9_dsubexp.h [deleted file]
vp9/decoder/vp9_dthread.c [deleted file]
vp9/decoder/vp9_dthread.h [deleted file]
vp9/encoder/arm/neon/vp9_dct_neon.c [deleted file]
vp9/encoder/arm/neon/vp9_error_neon.c [deleted file]
vp9/encoder/arm/neon/vp9_quantize_neon.c [deleted file]
vp9/encoder/mips/msa/vp9_error_msa.c [deleted file]
vp9/encoder/mips/msa/vp9_fdct16x16_msa.c [deleted file]
vp9/encoder/mips/msa/vp9_fdct4x4_msa.c [deleted file]
vp9/encoder/mips/msa/vp9_fdct8x8_msa.c [deleted file]
vp9/encoder/mips/msa/vp9_fdct_msa.h [deleted file]
vp9/encoder/mips/msa/vp9_temporal_filter_msa.c [deleted file]
vp9/encoder/vp9_aq_360.c [deleted file]
vp9/encoder/vp9_aq_360.h [deleted file]
vp9/encoder/vp9_aq_complexity.c [deleted file]
vp9/encoder/vp9_aq_complexity.h [deleted file]
vp9/encoder/vp9_aq_cyclicrefresh.c [deleted file]
vp9/encoder/vp9_aq_cyclicrefresh.h [deleted file]
vp9/encoder/vp9_aq_variance.c [deleted file]
vp9/encoder/vp9_aq_variance.h [deleted file]
vp9/encoder/vp9_bitstream.c [deleted file]
vp9/encoder/vp9_bitstream.h [deleted file]
vp9/encoder/vp9_block.h [deleted file]
vp9/encoder/vp9_blockiness.c [deleted file]
vp9/encoder/vp9_context_tree.c [deleted file]
vp9/encoder/vp9_context_tree.h [deleted file]
vp9/encoder/vp9_cost.c [deleted file]
vp9/encoder/vp9_cost.h [deleted file]
vp9/encoder/vp9_dct.c [deleted file]
vp9/encoder/vp9_denoiser.c [deleted file]
vp9/encoder/vp9_denoiser.h [deleted file]
vp9/encoder/vp9_encodeframe.c [deleted file]
vp9/encoder/vp9_encodeframe.h [deleted file]
vp9/encoder/vp9_encodemb.c [deleted file]
vp9/encoder/vp9_encodemb.h [deleted file]
vp9/encoder/vp9_encodemv.c [deleted file]
vp9/encoder/vp9_encodemv.h [deleted file]
vp9/encoder/vp9_encoder.c [deleted file]
vp9/encoder/vp9_encoder.h [deleted file]
vp9/encoder/vp9_ethread.c [deleted file]
vp9/encoder/vp9_ethread.h [deleted file]
vp9/encoder/vp9_extend.c [deleted file]
vp9/encoder/vp9_extend.h [deleted file]
vp9/encoder/vp9_firstpass.c [deleted file]
vp9/encoder/vp9_firstpass.h [deleted file]
vp9/encoder/vp9_lookahead.c [deleted file]
vp9/encoder/vp9_lookahead.h [deleted file]
vp9/encoder/vp9_mbgraph.c [deleted file]
vp9/encoder/vp9_mbgraph.h [deleted file]
vp9/encoder/vp9_mcomp.c [deleted file]
vp9/encoder/vp9_mcomp.h [deleted file]
vp9/encoder/vp9_noise_estimate.c [deleted file]
vp9/encoder/vp9_noise_estimate.h [deleted file]
vp9/encoder/vp9_picklpf.c [deleted file]
vp9/encoder/vp9_picklpf.h [deleted file]
vp9/encoder/vp9_pickmode.c [deleted file]
vp9/encoder/vp9_pickmode.h [deleted file]
vp9/encoder/vp9_quantize.c [deleted file]
vp9/encoder/vp9_quantize.h [deleted file]
vp9/encoder/vp9_ratectrl.c [deleted file]
vp9/encoder/vp9_ratectrl.h [deleted file]
vp9/encoder/vp9_rd.c [deleted file]
vp9/encoder/vp9_rd.h [deleted file]
vp9/encoder/vp9_rdopt.c [deleted file]
vp9/encoder/vp9_rdopt.h [deleted file]
vp9/encoder/vp9_resize.c [deleted file]
vp9/encoder/vp9_resize.h [deleted file]
vp9/encoder/vp9_segmentation.c [deleted file]
vp9/encoder/vp9_segmentation.h [deleted file]
vp9/encoder/vp9_skin_detection.c [deleted file]
vp9/encoder/vp9_skin_detection.h [deleted file]
vp9/encoder/vp9_speed_features.c [deleted file]
vp9/encoder/vp9_speed_features.h [deleted file]
vp9/encoder/vp9_subexp.c [deleted file]
vp9/encoder/vp9_subexp.h [deleted file]
vp9/encoder/vp9_svc_layercontext.c [deleted file]
vp9/encoder/vp9_svc_layercontext.h [deleted file]
vp9/encoder/vp9_temporal_filter.c [deleted file]
vp9/encoder/vp9_temporal_filter.h [deleted file]
vp9/encoder/vp9_tokenize.c [deleted file]
vp9/encoder/vp9_tokenize.h [deleted file]
vp9/encoder/vp9_treewriter.c [deleted file]
vp9/encoder/vp9_treewriter.h [deleted file]
vp9/encoder/x86/vp9_dct_intrin_sse2.c [deleted file]
vp9/encoder/x86/vp9_dct_sse2.asm [deleted file]
vp9/encoder/x86/vp9_dct_ssse3.c [deleted file]
vp9/encoder/x86/vp9_denoiser_sse2.c [deleted file]
vp9/encoder/x86/vp9_diamond_search_sad_avx.c [deleted file]
vp9/encoder/x86/vp9_error_intrin_avx2.c [deleted file]
vp9/encoder/x86/vp9_error_sse2.asm [deleted file]
vp9/encoder/x86/vp9_frame_scale_ssse3.c [deleted file]
vp9/encoder/x86/vp9_highbd_block_error_intrin_sse2.c [deleted file]
vp9/encoder/x86/vp9_highbd_error_avx.asm [deleted file]
vp9/encoder/x86/vp9_highbd_error_sse2.asm [deleted file]
vp9/encoder/x86/vp9_quantize_sse2.c [deleted file]
vp9/encoder/x86/vp9_quantize_ssse3_x86_64.asm [deleted file]
vp9/encoder/x86/vp9_temporal_filter_apply_sse2.asm [deleted file]
vp9/exports_dec [deleted file]
vp9/exports_enc [deleted file]
vp9/vp9_common.mk [deleted file]
vp9/vp9_cx_iface.c [deleted file]
vp9/vp9_dx_iface.c [deleted file]
vp9/vp9_dx_iface.h [deleted file]
vp9/vp9_iface_common.h [deleted file]
vp9/vp9cx.mk [deleted file]
vp9/vp9dx.mk [deleted file]
vpx_dsp/variance.h
vpx_dsp/vpx_dsp.mk
vpx_scale/generic/yv12extend.c
vpxdec.c
vpxenc.c

index 473d35e02abaa90d3a8f6706dd9ceccbe4ba412e..8a846d197b50b91cf4c6d80bec9f9033686ddb02 100755 (executable)
--- a/configure
+++ b/configure
@@ -38,8 +38,6 @@ Advanced options:
   ${toggle_better_hw_compatibility}
                                   enable encoder to produce streams with better
                                   hardware decoder compatibility
-  ${toggle_vp8}                   VP8 codec support
-  ${toggle_vp9}                   VP9 codec support
   ${toggle_vp10}                  VP10 codec support
   ${toggle_internal_stats}        output of encoder internal stats for debug, if supported (encoders)
   ${toggle_postproc}              postprocessing
@@ -191,13 +189,8 @@ if [ ${doxy_major:-0} -ge 1 ]; then
 fi
 
 # disable codecs when their source directory does not exist
-[ -d "${source_path}/vp8" ] || disable_codec vp8
-[ -d "${source_path}/vp9" ] || disable_codec vp9
 [ -d "${source_path}/vp10" ] || disable_codec vp10
 
-# disable vp10 codec by default
-disable_codec vp10
-
 # install everything except the sources, by default. sources will have
 # to be enabled when doing dist builds, since that's no longer a common
 # case.
@@ -214,16 +207,10 @@ enable_feature os_support
 enable_feature temporal_denoising
 
 CODECS="
-    vp8_encoder
-    vp8_decoder
-    vp9_encoder
-    vp9_decoder
     vp10_encoder
     vp10_decoder
 "
 CODEC_FAMILIES="
-    vp8
-    vp9
     vp10
 "
 
index cf98b99885e0baf8d1cf5e47bb4f3bb0a582aa0e..b3581fdb101326bf632ff4ed35f1ec5de59fbdc3 100644 (file)
@@ -248,10 +248,12 @@ endif
 ifeq ($(CONFIG_OS_SUPPORT), yes)
 CODEC_EXTRA_LIBS-$(CONFIG_VP8)         += m
 CODEC_EXTRA_LIBS-$(CONFIG_VP9)         += m
+CODEC_EXTRA_LIBS-$(CONFIG_VP10)        += m
 else
     ifeq ($(CONFIG_GCC), yes)
     CODEC_EXTRA_LIBS-$(CONFIG_VP8)         += m
     CODEC_EXTRA_LIBS-$(CONFIG_VP9)         += m
+    CODEC_EXTRA_LIBS-$(CONFIG_VP10)        += m
     endif
 endif
 #
diff --git a/libs.mk b/libs.mk
index f563bd32aa403747b3e2adcc7894938f8f157972..13c33ca3bf6a525beaec0cf1a49c8d131831ee26 100644 (file)
--- a/libs.mk
+++ b/libs.mk
@@ -53,62 +53,6 @@ CODEC_SRCS-yes += $(addprefix vpx_dsp/,$(call enabled,DSP_SRCS))
 include $(SRC_PATH_BARE)/vpx_util/vpx_util.mk
 CODEC_SRCS-yes += $(addprefix vpx_util/,$(call enabled,UTIL_SRCS))
 
-ifeq ($(CONFIG_VP8),yes)
-  VP8_PREFIX=vp8/
-  include $(SRC_PATH_BARE)/$(VP8_PREFIX)vp8_common.mk
-endif
-
-ifeq ($(CONFIG_VP8_ENCODER),yes)
-  include $(SRC_PATH_BARE)/$(VP8_PREFIX)vp8cx.mk
-  CODEC_SRCS-yes += $(addprefix $(VP8_PREFIX),$(call enabled,VP8_CX_SRCS))
-  CODEC_EXPORTS-yes += $(addprefix $(VP8_PREFIX),$(VP8_CX_EXPORTS))
-  INSTALL-LIBS-yes += include/vpx/vp8.h include/vpx/vp8cx.h
-  INSTALL_MAPS += include/vpx/% $(SRC_PATH_BARE)/$(VP8_PREFIX)/%
-  CODEC_DOC_SECTIONS += vp8 vp8_encoder
-endif
-
-ifeq ($(CONFIG_VP8_DECODER),yes)
-  include $(SRC_PATH_BARE)/$(VP8_PREFIX)vp8dx.mk
-  CODEC_SRCS-yes += $(addprefix $(VP8_PREFIX),$(call enabled,VP8_DX_SRCS))
-  CODEC_EXPORTS-yes += $(addprefix $(VP8_PREFIX),$(VP8_DX_EXPORTS))
-  INSTALL-LIBS-yes += include/vpx/vp8.h include/vpx/vp8dx.h
-  INSTALL_MAPS += include/vpx/% $(SRC_PATH_BARE)/$(VP8_PREFIX)/%
-  CODEC_DOC_SECTIONS += vp8 vp8_decoder
-endif
-
-ifeq ($(CONFIG_VP9),yes)
-  VP9_PREFIX=vp9/
-  include $(SRC_PATH_BARE)/$(VP9_PREFIX)vp9_common.mk
-endif
-
-ifeq ($(CONFIG_VP9_ENCODER),yes)
-  VP9_PREFIX=vp9/
-  include $(SRC_PATH_BARE)/$(VP9_PREFIX)vp9cx.mk
-  CODEC_SRCS-yes += $(addprefix $(VP9_PREFIX),$(call enabled,VP9_CX_SRCS))
-  CODEC_EXPORTS-yes += $(addprefix $(VP9_PREFIX),$(VP9_CX_EXPORTS))
-  CODEC_SRCS-yes += $(VP9_PREFIX)vp9cx.mk vpx/vp8.h vpx/vp8cx.h
-  INSTALL-LIBS-yes += include/vpx/vp8.h include/vpx/vp8cx.h
-  INSTALL-LIBS-$(CONFIG_SPATIAL_SVC) += include/vpx/svc_context.h
-  INSTALL_MAPS += include/vpx/% $(SRC_PATH_BARE)/$(VP9_PREFIX)/%
-  CODEC_DOC_SRCS += vpx/vp8.h vpx/vp8cx.h
-  CODEC_DOC_SECTIONS += vp9 vp9_encoder
-endif
-
-ifeq ($(CONFIG_VP9_DECODER),yes)
-  VP9_PREFIX=vp9/
-  include $(SRC_PATH_BARE)/$(VP9_PREFIX)vp9dx.mk
-  CODEC_SRCS-yes += $(addprefix $(VP9_PREFIX),$(call enabled,VP9_DX_SRCS))
-  CODEC_EXPORTS-yes += $(addprefix $(VP9_PREFIX),$(VP9_DX_EXPORTS))
-  CODEC_SRCS-yes += $(VP9_PREFIX)vp9dx.mk vpx/vp8.h vpx/vp8dx.h
-  INSTALL-LIBS-yes += include/vpx/vp8.h include/vpx/vp8dx.h
-  INSTALL_MAPS += include/vpx/% $(SRC_PATH_BARE)/$(VP9_PREFIX)/%
-  CODEC_DOC_SRCS += vpx/vp8.h vpx/vp8dx.h
-  CODEC_DOC_SECTIONS += vp9 vp9_decoder
-endif
-
-VP9_PREFIX=vp9/
-$(BUILD_PFX)$(VP9_PREFIX)%.c.o: CFLAGS += -Wextra
-
 #  VP10 make file
 ifeq ($(CONFIG_VP10),yes)
   VP10_PREFIX=vp10/
index 8c608f7316c3e3286cc21f0b72097d8e224ba206..3b947beb7e492ba4a597f41a9dc7a438be5e2da7 100644 (file)
@@ -15,9 +15,6 @@
 #include "third_party/googletest/src/include/gtest/gtest.h"
 
 #include "./vpx_config.h"
-#if CONFIG_VP9_ENCODER
-#include "./vp9_rtcd.h"
-#endif
 
 #include "test/acm_random.h"
 #include "test/clear_system_state.h"
index 9c2fd55084f8165fec7d87ecac75e7bc361b66fd..010c9b063f77a6d24bcdc03b6439d7a6401c5d43 100644 (file)
@@ -15,9 +15,6 @@
 #include "third_party/googletest/src/include/gtest/gtest.h"
 
 #include "./vpx_config.h"
-#if CONFIG_VP9_ENCODER
-#include "./vp9_rtcd.h"
-#endif
 
 #include "test/acm_random.h"
 #include "test/clear_system_state.h"
@@ -132,78 +129,10 @@ class ConsistencyTestBase : public ::testing::Test {
   ACMRandom rnd_;
 };
 
-#if CONFIG_VP9_ENCODER
-typedef std::tr1::tuple<int, int> ConsistencyParam;
-class ConsistencyVP9Test
-    : public ConsistencyTestBase,
-      public ::testing::WithParamInterface<ConsistencyParam> {
- public:
-  ConsistencyVP9Test() : ConsistencyTestBase(GET_PARAM(0), GET_PARAM(1)) {}
-
- protected:
-  double CheckConsistency(int frame) {
-    EXPECT_LT(frame, 2)<< "Frame to check has to be less than 2.";
-    return
-        vpx_get_ssim_metrics(source_data_[frame], source_stride_,
-                             reference_data_[frame], reference_stride_,
-                             width_, height_, ssim_array_, &metrics_, 1);
-  }
-};
-#endif  // CONFIG_VP9_ENCODER
-
 uint8_t* ConsistencyTestBase::source_data_[2] = {NULL, NULL};
 uint8_t* ConsistencyTestBase::reference_data_[2] = {NULL, NULL};
 Ssimv* ConsistencyTestBase::ssim_array_ = NULL;
 
-#if CONFIG_VP9_ENCODER
-TEST_P(ConsistencyVP9Test, ConsistencyIsZero) {
-  FillRandom(source_data_[0], source_stride_);
-  Copy(source_data_[1], source_data_[0]);
-  Copy(reference_data_[0], source_data_[0]);
-  Blur(reference_data_[0], reference_stride_, 3);
-  Copy(reference_data_[1], source_data_[0]);
-  Blur(reference_data_[1], reference_stride_, 3);
-
-  double inconsistency = CheckConsistency(1);
-  inconsistency = CheckConsistency(0);
-  EXPECT_EQ(inconsistency, 0.0)
-      << "Should have 0 inconsistency if they are exactly the same.";
-
-  // If sources are not consistent reference frames inconsistency should
-  // be less than if the source is consistent.
-  FillRandom(source_data_[0], source_stride_);
-  FillRandom(source_data_[1], source_stride_);
-  FillRandom(reference_data_[0], reference_stride_);
-  FillRandom(reference_data_[1], reference_stride_);
-  CheckConsistency(0);
-  inconsistency = CheckConsistency(1);
-
-  Copy(source_data_[1], source_data_[0]);
-  CheckConsistency(0);
-  double inconsistency2 = CheckConsistency(1);
-  EXPECT_LT(inconsistency, inconsistency2)
-      << "Should have less inconsistency if source itself is inconsistent.";
-
-  // Less of a blur should be less inconsistent than more blur coming off a
-  // a frame with no blur.
-  ClearSsim();
-  FillRandom(source_data_[0], source_stride_);
-  Copy(source_data_[1], source_data_[0]);
-  Copy(reference_data_[0], source_data_[0]);
-  Copy(reference_data_[1], source_data_[0]);
-  Blur(reference_data_[1], reference_stride_, 4);
-  CheckConsistency(0);
-  inconsistency = CheckConsistency(1);
-  ClearSsim();
-  Copy(reference_data_[1], source_data_[0]);
-  Blur(reference_data_[1], reference_stride_, 8);
-  CheckConsistency(0);
-  inconsistency2 = CheckConsistency(1);
-
-  EXPECT_LT(inconsistency, inconsistency2)
-      << "Stronger Blur should produce more inconsistency.";
-}
-#endif  // CONFIG_VP9_ENCODER
 
 
 using std::tr1::make_tuple;
@@ -211,14 +140,4 @@ using std::tr1::make_tuple;
 //------------------------------------------------------------------------------
 // C functions
 
-#if CONFIG_VP9_ENCODER
-const ConsistencyParam c_vp9_tests[] = {
-  make_tuple(320, 240),
-  make_tuple(318, 242),
-  make_tuple(318, 238),
-};
-INSTANTIATE_TEST_CASE_P(C, ConsistencyVP9Test,
-                        ::testing::ValuesIn(c_vp9_tests));
-#endif
-
 }  // namespace
index 70802ecc568955b61b0fa238741d7382e9f71ffd..f9bea218ac9a3e04dfe2a112ff542358b4265df9 100644 (file)
 #include "third_party/googletest/src/include/gtest/gtest.h"
 
 #include "./vpx_config.h"
-#include "./vp9_rtcd.h"
 #include "./vpx_dsp_rtcd.h"
 #include "test/acm_random.h"
 #include "test/clear_system_state.h"
 #include "test/register_state_check.h"
 #include "test/util.h"
-#include "vp9/common/vp9_common.h"
-#include "vp9/common/vp9_filter.h"
 #include "vpx_dsp/vpx_dsp_common.h"
 #include "vpx_dsp/vpx_filter.h"
 #include "vpx_mem/vpx_mem.h"
index e6224b21a8663f40cea589d36ae501a9b2c4eb3f..8fefa0b115fa23de113f90342c48574b8f1cf45c 100644 (file)
 
 #include "third_party/googletest/src/include/gtest/gtest.h"
 
-#include "./vp9_rtcd.h"
 #include "./vpx_dsp_rtcd.h"
 #include "test/acm_random.h"
 #include "test/clear_system_state.h"
 #include "test/register_state_check.h"
 #include "test/util.h"
-#include "vp9/common/vp9_entropy.h"
-#include "vp9/common/vp9_scan.h"
 #include "vpx/vpx_codec.h"
 #include "vpx/vpx_integer.h"
 #include "vpx_ports/mem.h"
index 278d72dfa7976ac9f298cc6aea2ceb7314c91253..ad31ab632b4b45274fd55d2b4e06931c3e4b929a 100644 (file)
 
 #include "third_party/googletest/src/include/gtest/gtest.h"
 
-#include "./vp9_rtcd.h"
 #include "./vpx_config.h"
 #include "./vpx_dsp_rtcd.h"
 #include "test/acm_random.h"
 #include "test/clear_system_state.h"
 #include "test/register_state_check.h"
 #include "test/util.h"
-#include "vp9/common/vp9_entropy.h"
 #include "vpx/vpx_codec.h"
 #include "vpx/vpx_integer.h"
 #include "vpx_ports/mem.h"
index a7200e653a0d63fa10d00a5151bab5df81c7bd9b..9e99bb8d9de15c960939d0039646a7bd8c48f93d 100644 (file)
@@ -20,12 +20,6 @@ namespace {
 
 TEST(EncodeAPI, InvalidParams) {
   static const vpx_codec_iface_t *kCodecs[] = {
-#if CONFIG_VP8_ENCODER
-    &vpx_codec_vp8_cx_algo,
-#endif
-#if CONFIG_VP9_ENCODER
-    &vpx_codec_vp9_cx_algo,
-#endif
 #if CONFIG_VP10_ENCODER
     &vpx_codec_vp10_cx_algo,
 #endif
index 236f75e3b4f1b0efb14c89a241747a9dfbd0b557..d7b0ab954440598264e1fa67c6454810e028dbe1 100644 (file)
@@ -14,7 +14,6 @@
 
 #include "third_party/googletest/src/include/gtest/gtest.h"
 
-#include "./vp9_rtcd.h"
 #include "./vpx_dsp_rtcd.h"
 #include "test/acm_random.h"
 #include "test/clear_system_state.h"
index 083ee66282fbfda4fe8c53104be2cb8108649a50..70db91d5c715339ab7205ba2c479c6acd5accb27 100644 (file)
 
 #include "third_party/googletest/src/include/gtest/gtest.h"
 
-#include "./vp9_rtcd.h"
 #include "./vpx_dsp_rtcd.h"
 #include "test/acm_random.h"
 #include "test/clear_system_state.h"
 #include "test/register_state_check.h"
 #include "test/util.h"
-#include "vp9/common/vp9_entropy.h"
-#include "vp9/common/vp9_scan.h"
 #include "vpx/vpx_codec.h"
 #include "vpx/vpx_integer.h"
 #include "vpx_ports/mem.h"
index 39db3e4c6115f66fb1c4b553abdd5390b3a32e1b..6b619a0193c4208655e71526ff04496abd70b412 100644 (file)
@@ -9,7 +9,6 @@
  */
 
 #include "./vpx_config.h"
-#include "./vp8_rtcd.h"
 
 #include "third_party/googletest/src/include/gtest/gtest.h"
 
index 1efb1a4eb99ec3203d94240056d278d77fb6c730..51c2b53390894394ad3107556ac97383e67fda99 100644 (file)
 
 #include "third_party/googletest/src/include/gtest/gtest.h"
 
-#include "./vp9_rtcd.h"
 #include "./vpx_dsp_rtcd.h"
 #include "test/acm_random.h"
 #include "test/clear_system_state.h"
 #include "test/register_state_check.h"
 #include "test/util.h"
-#include "vp9/common/vp9_blockd.h"
-#include "vp9/common/vp9_scan.h"
 #include "vpx/vpx_integer.h"
 
 using libvpx_test::ACMRandom;
index 69da8994ca1d3b876195eac13fc0fac74bf5f348..2f4526da02012fbf65e461e049e6533aa295f7ed 100644 (file)
@@ -13,7 +13,6 @@
 #include "third_party/googletest/src/include/gtest/gtest.h"
 
 #include "./vpx_config.h"
-#include "./vp8_rtcd.h"
 #include "test/acm_random.h"
 #include "test/clear_system_state.h"
 #include "test/register_state_check.h"
index 304a1484aff70c86350028159520fcb1b20dc6ba..eeacbb4fb128714113735dfa574b59f726b972bb 100644 (file)
@@ -15,7 +15,6 @@
 #include "third_party/googletest/src/include/gtest/gtest.h"
 
 #include "./vpx_config.h"
-#include "./vp8_rtcd.h"
 #include "test/acm_random.h"
 #include "test/clear_system_state.h"
 #include "test/register_state_check.h"
index 94091f0220c00b2f299b509959df329a48dcbb23..4a7821b5df888621a9aec08db2e7dc8866fa078c 100644 (file)
@@ -10,6 +10,7 @@ LIBVPX_TEST_SRCS-yes += test_vectors.h
 LIBVPX_TEST_SRCS-yes += util.h
 LIBVPX_TEST_SRCS-yes += video_source.h
 LIBVPX_TEST_SRCS-yes += transform_test_base.h
+LIBVPX_TEST_SRCS-yes += function_equivalence_test.h
 
 ##
 ## BLACK BOX TESTS
@@ -142,7 +143,7 @@ LIBVPX_TEST_SRCS-yes                   += vp9_boolcoder_test.cc
 LIBVPX_TEST_SRCS-yes                   += vp9_encoder_parms_get_to_decoder.cc
 endif
 
-LIBVPX_TEST_SRCS-yes                   += convolve_test.cc
+#LIBVPX_TEST_SRCS-yes                   += convolve_test.cc
 LIBVPX_TEST_SRCS-yes                   += lpf_8_test.cc
 LIBVPX_TEST_SRCS-yes                   += vp9_intrapred_test.cc
 LIBVPX_TEST_SRCS-$(CONFIG_VP9_DECODER) += vp9_decrypt_test.cc
@@ -173,7 +174,7 @@ endif # VP9
 
 ## VP10
 ifeq ($(CONFIG_VP10),yes)
-LIBVPX_TEST_SRCS-yes                    += vp10_inv_txfm_test.cc
+LIBVPX_TEST_SRCS-$(CONFIG_VP10_ENCODER) += vp10_inv_txfm_test.cc
 LIBVPX_TEST_SRCS-$(CONFIG_VP10_ENCODER) += vp10_dct_test.cc
 LIBVPX_TEST_SRCS-$(CONFIG_VP10_ENCODER) += vp10_fht4x4_test.cc
 LIBVPX_TEST_SRCS-$(CONFIG_VP10_ENCODER) += vp10_fht8x8_test.cc
index 0d6bbcded51be7f89c63303a1309d2e40cae5041..9d9ae7f991efaa9f540f46c6a623b0604668313d 100644 (file)
@@ -12,7 +12,7 @@ using libvpx_test::ACMRandom;
 
 namespace {
 void setup_convolve() {
-#if HAVE_SSSE3
+#if HAVE_SSSE3 && CONFIG_RUNTIME_CPU_DETECT
   vp10_convolve_horiz = vp10_convolve_horiz_c;
   vp10_convolve_vert = vp10_convolve_vert_c;
 #endif
index e37b906ca982d8aad92fcbcdc833fbc28c41770d..917e6e9700eed81bd2759e6f1a0f7239ee41008e 100644 (file)
@@ -289,31 +289,31 @@ using std::tr1::make_tuple;
 INSTANTIATE_TEST_CASE_P(
     C, Vp10PartialIDctTest,
     ::testing::Values(
-        make_tuple(&vpx_fdct32x32_c,
+        make_tuple(&vp10_fdct32x32_c,
                    &vp10_idct32x32_1024_add_c,
                    &vp10_idct32x32_34_add_c,
                    TX_32X32, 34),
-        make_tuple(&vpx_fdct32x32_c,
+        make_tuple(&vp10_fdct32x32_c,
                    &vp10_idct32x32_1024_add_c,
                    &vp10_idct32x32_1_add_c,
                    TX_32X32, 1),
-        make_tuple(&vpx_fdct16x16_c,
+        make_tuple(&vp10_fdct16x16_c,
                    &vp10_idct16x16_256_add_c,
                    &vp10_idct16x16_10_add_c,
                    TX_16X16, 10),
-        make_tuple(&vpx_fdct16x16_c,
+        make_tuple(&vp10_fdct16x16_c,
                    &vp10_idct16x16_256_add_c,
                    &vp10_idct16x16_1_add_c,
                    TX_16X16, 1),
-        make_tuple(&vpx_fdct8x8_c,
+        make_tuple(&vp10_fdct8x8_c,
                    &vp10_idct8x8_64_add_c,
                    &vp10_idct8x8_12_add_c,
                    TX_8X8, 12),
-        make_tuple(&vpx_fdct8x8_c,
+        make_tuple(&vp10_fdct8x8_c,
                    &vp10_idct8x8_64_add_c,
                    &vp10_idct8x8_1_add_c,
                    TX_8X8, 1),
-        make_tuple(&vpx_fdct4x4_c,
+        make_tuple(&vp10_fdct4x4_c,
                    &vp10_idct4x4_16_add_c,
                    &vp10_idct4x4_1_add_c,
                    TX_4X4, 1)));
index 11a653deccb6688e0c7f4f57659752100b0482c0..f10b6f58c533c84c1f2c72a03c000bf283833a48 100644 (file)
@@ -17,7 +17,6 @@
 
 #include "third_party/googletest/src/include/gtest/gtest.h"
 
-#include "./vp8_rtcd.h"
 #include "test/acm_random.h"
 #include "vpx/vpx_integer.h"
 
index 341cc19cb9982e5954d5c81a76018f63dcb26eb8..049a83b62b2aace20c6c0145bec386a915fda12d 100644 (file)
 #include "third_party/googletest/src/include/gtest/gtest.h"
 
 #include "./vpx_config.h"
-#include "./vp9_rtcd.h"
 #include "test/acm_random.h"
 #include "test/clear_system_state.h"
 #include "test/register_state_check.h"
 #include "test/util.h"
-#include "vp9/common/vp9_entropy.h"
 #include "vpx/vpx_codec.h"
 #include "vpx/vpx_integer.h"
 
index 20b259ca94b8405868c06c1a321dc868cc5dcf5c..83eec5013f5a3d6b20b393fdb82f234752e0f68b 100644 (file)
 
 #include "./tools_common.h"
 
-#if CONFIG_VP8_ENCODER || CONFIG_VP9_ENCODER || CONFIG_VP10_ENCODER
+#if CONFIG_VP10_ENCODER
 #include "vpx/vp8cx.h"
 #endif
 
-#if CONFIG_VP8_DECODER || CONFIG_VP9_DECODER || CONFIG_VP10_DECODER
+#if CONFIG_VP10_DECODER
 #include "vpx/vp8dx.h"
 #endif
 
@@ -136,14 +136,6 @@ static const VpxInterface vpx_encoders[] = {
 #if CONFIG_VP10_ENCODER
   {"vp10", VP10_FOURCC, &vpx_codec_vp10_cx},
 #endif
-
-#if CONFIG_VP8_ENCODER
-  {"vp8", VP8_FOURCC, &vpx_codec_vp8_cx},
-#endif
-
-#if CONFIG_VP9_ENCODER
-  {"vp9", VP9_FOURCC, &vpx_codec_vp9_cx},
-#endif
 };
 
 int get_vpx_encoder_count(void) {
@@ -171,13 +163,6 @@ const VpxInterface *get_vpx_encoder_by_name(const char *name) {
 #if CONFIG_DECODERS
 
 static const VpxInterface vpx_decoders[] = {
-#if CONFIG_VP8_DECODER
-  {"vp8", VP8_FOURCC, &vpx_codec_vp8_dx},
-#endif
-
-#if CONFIG_VP9_DECODER
-  {"vp9", VP9_FOURCC, &vpx_codec_vp9_dx},
-#endif
 
 #if CONFIG_VP10_DECODER
   {"vp10", VP10_FOURCC, &vpx_codec_vp10_dx},
index e68e0833d8bb1a0a224f0e90147c1c1276a43448..80e7ddcb49e242490de3d0c90a0dcbfa812cf183 100644 (file)
 
 VP10_COMMON_SRCS-yes += vp10_common.mk
 VP10_COMMON_SRCS-yes += vp10_iface_common.h
+VP10_COMMON_SRCS-yes += common/ans.h
 VP10_COMMON_SRCS-yes += common/ppflags.h
 VP10_COMMON_SRCS-yes += common/alloccommon.c
 VP10_COMMON_SRCS-yes += common/blockd.c
 VP10_COMMON_SRCS-yes += common/debugmodes.c
+VP10_COMMON_SRCS-yes += common/divide.h
 VP10_COMMON_SRCS-yes += common/entropy.c
 VP10_COMMON_SRCS-yes += common/entropymode.c
 VP10_COMMON_SRCS-yes += common/entropymv.c
@@ -57,6 +59,7 @@ VP10_COMMON_SRCS-yes += common/mvref_common.h
 VP10_COMMON_SRCS-yes += common/quant_common.c
 VP10_COMMON_SRCS-yes += common/reconinter.c
 VP10_COMMON_SRCS-yes += common/reconintra.c
+VP10_COMMON_SRCS-yes += common/restoration.h
 VP10_COMMON_SRCS-$(CONFIG_POSTPROC_VISUALIZER) += common/textblit.c
 VP10_COMMON_SRCS-yes += common/common_data.h
 VP10_COMMON_SRCS-yes += common/scan.c
diff --git a/vp8/common/alloccommon.c b/vp8/common/alloccommon.c
deleted file mode 100644 (file)
index 8dfd4ce..0000000
+++ /dev/null
@@ -1,190 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#include "vpx_config.h"
-#include "alloccommon.h"
-#include "blockd.h"
-#include "vpx_mem/vpx_mem.h"
-#include "onyxc_int.h"
-#include "findnearmv.h"
-#include "entropymode.h"
-#include "systemdependent.h"
-
-void vp8_de_alloc_frame_buffers(VP8_COMMON *oci)
-{
-    int i;
-    for (i = 0; i < NUM_YV12_BUFFERS; i++)
-        vp8_yv12_de_alloc_frame_buffer(&oci->yv12_fb[i]);
-
-    vp8_yv12_de_alloc_frame_buffer(&oci->temp_scale_frame);
-#if CONFIG_POSTPROC
-    vp8_yv12_de_alloc_frame_buffer(&oci->post_proc_buffer);
-    if (oci->post_proc_buffer_int_used)
-        vp8_yv12_de_alloc_frame_buffer(&oci->post_proc_buffer_int);
-
-    vpx_free(oci->pp_limits_buffer);
-    oci->pp_limits_buffer = NULL;
-#endif
-
-    vpx_free(oci->above_context);
-    vpx_free(oci->mip);
-#if CONFIG_ERROR_CONCEALMENT
-    vpx_free(oci->prev_mip);
-    oci->prev_mip = NULL;
-#endif
-
-    oci->above_context = NULL;
-    oci->mip = NULL;
-}
-
-int vp8_alloc_frame_buffers(VP8_COMMON *oci, int width, int height)
-{
-    int i;
-
-    vp8_de_alloc_frame_buffers(oci);
-
-    /* our internal buffers are always multiples of 16 */
-    if ((width & 0xf) != 0)
-        width += 16 - (width & 0xf);
-
-    if ((height & 0xf) != 0)
-        height += 16 - (height & 0xf);
-
-
-    for (i = 0; i < NUM_YV12_BUFFERS; i++)
-    {
-        oci->fb_idx_ref_cnt[i] = 0;
-        oci->yv12_fb[i].flags = 0;
-        if (vp8_yv12_alloc_frame_buffer(&oci->yv12_fb[i], width, height, VP8BORDERINPIXELS) < 0)
-            goto allocation_fail;
-    }
-
-    oci->new_fb_idx = 0;
-    oci->lst_fb_idx = 1;
-    oci->gld_fb_idx = 2;
-    oci->alt_fb_idx = 3;
-
-    oci->fb_idx_ref_cnt[0] = 1;
-    oci->fb_idx_ref_cnt[1] = 1;
-    oci->fb_idx_ref_cnt[2] = 1;
-    oci->fb_idx_ref_cnt[3] = 1;
-
-    if (vp8_yv12_alloc_frame_buffer(&oci->temp_scale_frame,   width, 16, VP8BORDERINPIXELS) < 0)
-        goto allocation_fail;
-
-    oci->mb_rows = height >> 4;
-    oci->mb_cols = width >> 4;
-    oci->MBs = oci->mb_rows * oci->mb_cols;
-    oci->mode_info_stride = oci->mb_cols + 1;
-    oci->mip = vpx_calloc((oci->mb_cols + 1) * (oci->mb_rows + 1), sizeof(MODE_INFO));
-
-    if (!oci->mip)
-        goto allocation_fail;
-
-    oci->mi = oci->mip + oci->mode_info_stride + 1;
-
-    /* Allocation of previous mode info will be done in vp8_decode_frame()
-     * as it is a decoder only data */
-
-    oci->above_context = vpx_calloc(sizeof(ENTROPY_CONTEXT_PLANES) * oci->mb_cols, 1);
-
-    if (!oci->above_context)
-        goto allocation_fail;
-
-#if CONFIG_POSTPROC
-    if (vp8_yv12_alloc_frame_buffer(&oci->post_proc_buffer, width, height, VP8BORDERINPIXELS) < 0)
-        goto allocation_fail;
-
-    oci->post_proc_buffer_int_used = 0;
-    memset(&oci->postproc_state, 0, sizeof(oci->postproc_state));
-    memset(oci->post_proc_buffer.buffer_alloc, 128,
-           oci->post_proc_buffer.frame_size);
-
-    /* Allocate buffer to store post-processing filter coefficients.
-     *
-     * Note: Round up mb_cols to support SIMD reads
-     */
-    oci->pp_limits_buffer = vpx_memalign(16, 24 * ((oci->mb_cols + 1) & ~1));
-    if (!oci->pp_limits_buffer)
-        goto allocation_fail;
-#endif
-
-    return 0;
-
-allocation_fail:
-    vp8_de_alloc_frame_buffers(oci);
-    return 1;
-}
-
-void vp8_setup_version(VP8_COMMON *cm)
-{
-    switch (cm->version)
-    {
-    case 0:
-        cm->no_lpf = 0;
-        cm->filter_type = NORMAL_LOOPFILTER;
-        cm->use_bilinear_mc_filter = 0;
-        cm->full_pixel = 0;
-        break;
-    case 1:
-        cm->no_lpf = 0;
-        cm->filter_type = SIMPLE_LOOPFILTER;
-        cm->use_bilinear_mc_filter = 1;
-        cm->full_pixel = 0;
-        break;
-    case 2:
-        cm->no_lpf = 1;
-        cm->filter_type = NORMAL_LOOPFILTER;
-        cm->use_bilinear_mc_filter = 1;
-        cm->full_pixel = 0;
-        break;
-    case 3:
-        cm->no_lpf = 1;
-        cm->filter_type = SIMPLE_LOOPFILTER;
-        cm->use_bilinear_mc_filter = 1;
-        cm->full_pixel = 1;
-        break;
-    default:
-        /*4,5,6,7 are reserved for future use*/
-        cm->no_lpf = 0;
-        cm->filter_type = NORMAL_LOOPFILTER;
-        cm->use_bilinear_mc_filter = 0;
-        cm->full_pixel = 0;
-        break;
-    }
-}
-void vp8_create_common(VP8_COMMON *oci)
-{
-    vp8_machine_specific_config(oci);
-
-    vp8_init_mbmode_probs(oci);
-    vp8_default_bmode_probs(oci->fc.bmode_prob);
-
-    oci->mb_no_coeff_skip = 1;
-    oci->no_lpf = 0;
-    oci->filter_type = NORMAL_LOOPFILTER;
-    oci->use_bilinear_mc_filter = 0;
-    oci->full_pixel = 0;
-    oci->multi_token_partition = ONE_PARTITION;
-    oci->clamp_type = RECON_CLAMP_REQUIRED;
-
-    /* Initialize reference frame sign bias structure to defaults */
-    memset(oci->ref_frame_sign_bias, 0, sizeof(oci->ref_frame_sign_bias));
-
-    /* Default disable buffer to buffer copying */
-    oci->copy_buffer_to_gf = 0;
-    oci->copy_buffer_to_arf = 0;
-}
-
-void vp8_remove_common(VP8_COMMON *oci)
-{
-    vp8_de_alloc_frame_buffers(oci);
-}
diff --git a/vp8/common/alloccommon.h b/vp8/common/alloccommon.h
deleted file mode 100644 (file)
index 93e99d7..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#ifndef VP8_COMMON_ALLOCCOMMON_H_
-#define VP8_COMMON_ALLOCCOMMON_H_
-
-#include "onyxc_int.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-void vp8_create_common(VP8_COMMON *oci);
-void vp8_remove_common(VP8_COMMON *oci);
-void vp8_de_alloc_frame_buffers(VP8_COMMON *oci);
-int vp8_alloc_frame_buffers(VP8_COMMON *oci, int width, int height);
-void vp8_setup_version(VP8_COMMON *oci);
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP8_COMMON_ALLOCCOMMON_H_
diff --git a/vp8/common/arm/armv6/bilinearfilter_v6.asm b/vp8/common/arm/armv6/bilinearfilter_v6.asm
deleted file mode 100644 (file)
index 9704b42..0000000
+++ /dev/null
@@ -1,237 +0,0 @@
-;
-;  Copyright (c) 2010 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_filter_block2d_bil_first_pass_armv6|
-    EXPORT  |vp8_filter_block2d_bil_second_pass_armv6|
-
-    AREA    |.text|, CODE, READONLY  ; name this block of code
-
-;-------------------------------------
-; r0    unsigned char  *src_ptr,
-; r1    unsigned short *dst_ptr,
-; r2    unsigned int    src_pitch,
-; r3    unsigned int    height,
-; stack unsigned int    width,
-; stack const short    *vp8_filter
-;-------------------------------------
-; The output is transposed stroed in output array to make it easy for second pass filtering.
-|vp8_filter_block2d_bil_first_pass_armv6| PROC
-    stmdb   sp!, {r4 - r11, lr}
-
-    ldr     r11, [sp, #40]                  ; vp8_filter address
-    ldr     r4, [sp, #36]                   ; width
-
-    mov     r12, r3                         ; outer-loop counter
-
-    add     r7, r2, r4                      ; preload next row
-    pld     [r0, r7]
-
-    sub     r2, r2, r4                      ; src increment for height loop
-
-    ldr     r5, [r11]                       ; load up filter coefficients
-
-    mov     r3, r3, lsl #1                  ; height*2
-    add     r3, r3, #2                      ; plus 2 to make output buffer 4-bit aligned since height is actually (height+1)
-
-    mov     r11, r1                         ; save dst_ptr for each row
-
-    cmp     r5, #128                        ; if filter coef = 128, then skip the filter
-    beq     bil_null_1st_filter
-
-|bil_height_loop_1st_v6|
-    ldrb    r6, [r0]                        ; load source data
-    ldrb    r7, [r0, #1]
-    ldrb    r8, [r0, #2]
-    mov     lr, r4, lsr #2                  ; 4-in-parellel loop counter
-
-|bil_width_loop_1st_v6|
-    ldrb    r9, [r0, #3]
-    ldrb    r10, [r0, #4]
-
-    pkhbt   r6, r6, r7, lsl #16             ; src[1] | src[0]
-    pkhbt   r7, r7, r8, lsl #16             ; src[2] | src[1]
-
-    smuad   r6, r6, r5                      ; apply the filter
-    pkhbt   r8, r8, r9, lsl #16             ; src[3] | src[2]
-    smuad   r7, r7, r5
-    pkhbt   r9, r9, r10, lsl #16            ; src[4] | src[3]
-
-    smuad   r8, r8, r5
-    smuad   r9, r9, r5
-
-    add     r0, r0, #4
-    subs    lr, lr, #1
-
-    add     r6, r6, #0x40                   ; round_shift_and_clamp
-    add     r7, r7, #0x40
-    usat    r6, #16, r6, asr #7
-    usat    r7, #16, r7, asr #7
-
-    strh    r6, [r1], r3                    ; result is transposed and stored
-
-    add     r8, r8, #0x40                   ; round_shift_and_clamp
-    strh    r7, [r1], r3
-    add     r9, r9, #0x40
-    usat    r8, #16, r8, asr #7
-    usat    r9, #16, r9, asr #7
-
-    strh    r8, [r1], r3                    ; result is transposed and stored
-
-    ldrneb  r6, [r0]                        ; load source data
-    strh    r9, [r1], r3
-
-    ldrneb  r7, [r0, #1]
-    ldrneb  r8, [r0, #2]
-
-    bne     bil_width_loop_1st_v6
-
-    add     r0, r0, r2                      ; move to next input row
-    subs    r12, r12, #1
-
-    add     r9, r2, r4, lsl #1              ; adding back block width
-    pld     [r0, r9]                        ; preload next row
-
-    add     r11, r11, #2                    ; move over to next column
-    mov     r1, r11
-
-    bne     bil_height_loop_1st_v6
-
-    ldmia   sp!, {r4 - r11, pc}
-
-|bil_null_1st_filter|
-|bil_height_loop_null_1st|
-    mov     lr, r4, lsr #2                  ; loop counter
-
-|bil_width_loop_null_1st|
-    ldrb    r6, [r0]                        ; load data
-    ldrb    r7, [r0, #1]
-    ldrb    r8, [r0, #2]
-    ldrb    r9, [r0, #3]
-
-    strh    r6, [r1], r3                    ; store it to immediate buffer
-    add     r0, r0, #4
-    strh    r7, [r1], r3
-    subs    lr, lr, #1
-    strh    r8, [r1], r3
-    strh    r9, [r1], r3
-
-    bne     bil_width_loop_null_1st
-
-    subs    r12, r12, #1
-    add     r0, r0, r2                      ; move to next input line
-    add     r11, r11, #2                    ; move over to next column
-    mov     r1, r11
-
-    bne     bil_height_loop_null_1st
-
-    ldmia   sp!, {r4 - r11, pc}
-
-    ENDP  ; |vp8_filter_block2d_bil_first_pass_armv6|
-
-
-;---------------------------------
-; r0    unsigned short *src_ptr,
-; r1    unsigned char  *dst_ptr,
-; r2    int             dst_pitch,
-; r3    unsigned int    height,
-; stack unsigned int    width,
-; stack const short    *vp8_filter
-;---------------------------------
-|vp8_filter_block2d_bil_second_pass_armv6| PROC
-    stmdb   sp!, {r4 - r11, lr}
-
-    ldr     r11, [sp, #40]                  ; vp8_filter address
-    ldr     r4, [sp, #36]                   ; width
-
-    ldr     r5, [r11]                       ; load up filter coefficients
-    mov     r12, r4                         ; outer-loop counter = width, since we work on transposed data matrix
-    mov     r11, r1
-
-    cmp     r5, #128                        ; if filter coef = 128, then skip the filter
-    beq     bil_null_2nd_filter
-
-|bil_height_loop_2nd|
-    ldr     r6, [r0]                        ; load the data
-    ldr     r8, [r0, #4]
-    ldrh    r10, [r0, #8]
-    mov     lr, r3, lsr #2                  ; loop counter
-
-|bil_width_loop_2nd|
-    pkhtb   r7, r6, r8                      ; src[1] | src[2]
-    pkhtb   r9, r8, r10                     ; src[3] | src[4]
-
-    smuad   r6, r6, r5                      ; apply filter
-    smuad   r8, r8, r5                      ; apply filter
-
-    subs    lr, lr, #1
-
-    smuadx  r7, r7, r5                      ; apply filter
-    smuadx  r9, r9, r5                      ; apply filter
-
-    add     r0, r0, #8
-
-    add     r6, r6, #0x40                   ; round_shift_and_clamp
-    add     r7, r7, #0x40
-    usat    r6, #8, r6, asr #7
-    usat    r7, #8, r7, asr #7
-    strb    r6, [r1], r2                    ; the result is transposed back and stored
-
-    add     r8, r8, #0x40                   ; round_shift_and_clamp
-    strb    r7, [r1], r2
-    add     r9, r9, #0x40
-    usat    r8, #8, r8, asr #7
-    usat    r9, #8, r9, asr #7
-    strb    r8, [r1], r2                    ; the result is transposed back and stored
-
-    ldrne   r6, [r0]                        ; load data
-    strb    r9, [r1], r2
-    ldrne   r8, [r0, #4]
-    ldrneh  r10, [r0, #8]
-
-    bne     bil_width_loop_2nd
-
-    subs    r12, r12, #1
-    add     r0, r0, #4                      ; update src for next row
-    add     r11, r11, #1
-    mov     r1, r11
-
-    bne     bil_height_loop_2nd
-    ldmia   sp!, {r4 - r11, pc}
-
-|bil_null_2nd_filter|
-|bil_height_loop_null_2nd|
-    mov     lr, r3, lsr #2
-
-|bil_width_loop_null_2nd|
-    ldr     r6, [r0], #4                    ; load data
-    subs    lr, lr, #1
-    ldr     r8, [r0], #4
-
-    strb    r6, [r1], r2                    ; store data
-    mov     r7, r6, lsr #16
-    strb    r7, [r1], r2
-    mov     r9, r8, lsr #16
-    strb    r8, [r1], r2
-    strb    r9, [r1], r2
-
-    bne     bil_width_loop_null_2nd
-
-    subs    r12, r12, #1
-    add     r0, r0, #4
-    add     r11, r11, #1
-    mov     r1, r11
-
-    bne     bil_height_loop_null_2nd
-
-    ldmia   sp!, {r4 - r11, pc}
-    ENDP  ; |vp8_filter_block2d_second_pass_armv6|
-
-    END
diff --git a/vp8/common/arm/armv6/copymem16x16_v6.asm b/vp8/common/arm/armv6/copymem16x16_v6.asm
deleted file mode 100644 (file)
index abf048c..0000000
+++ /dev/null
@@ -1,186 +0,0 @@
-;
-;  Copyright (c) 2010 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_copy_mem16x16_v6|
-    ; ARM
-    ; REQUIRE8
-    ; PRESERVE8
-
-    AREA    Block, CODE, READONLY ; name this block of code
-;void copy_mem16x16_v6( unsigned char *src, int src_stride, unsigned char *dst, int dst_stride)
-;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-|vp8_copy_mem16x16_v6| PROC
-    stmdb       sp!, {r4 - r7}
-    ;push   {r4-r7}
-
-    ;preload
-    pld     [r0, #31]                ; preload for next 16x16 block
-
-    ands    r4, r0, #15
-    beq     copy_mem16x16_fast
-
-    ands    r4, r0, #7
-    beq     copy_mem16x16_8
-
-    ands    r4, r0, #3
-    beq     copy_mem16x16_4
-
-    ;copy one byte each time
-    ldrb    r4, [r0]
-    ldrb    r5, [r0, #1]
-    ldrb    r6, [r0, #2]
-    ldrb    r7, [r0, #3]
-
-    mov     r12, #16
-
-copy_mem16x16_1_loop
-    strb    r4, [r2]
-    strb    r5, [r2, #1]
-    strb    r6, [r2, #2]
-    strb    r7, [r2, #3]
-
-    ldrb    r4, [r0, #4]
-    ldrb    r5, [r0, #5]
-    ldrb    r6, [r0, #6]
-    ldrb    r7, [r0, #7]
-
-    subs    r12, r12, #1
-
-    strb    r4, [r2, #4]
-    strb    r5, [r2, #5]
-    strb    r6, [r2, #6]
-    strb    r7, [r2, #7]
-
-    ldrb    r4, [r0, #8]
-    ldrb    r5, [r0, #9]
-    ldrb    r6, [r0, #10]
-    ldrb    r7, [r0, #11]
-
-    strb    r4, [r2, #8]
-    strb    r5, [r2, #9]
-    strb    r6, [r2, #10]
-    strb    r7, [r2, #11]
-
-    ldrb    r4, [r0, #12]
-    ldrb    r5, [r0, #13]
-    ldrb    r6, [r0, #14]
-    ldrb    r7, [r0, #15]
-
-    add     r0, r0, r1
-
-    strb    r4, [r2, #12]
-    strb    r5, [r2, #13]
-    strb    r6, [r2, #14]
-    strb    r7, [r2, #15]
-
-    add     r2, r2, r3
-
-    ldrneb  r4, [r0]
-    ldrneb  r5, [r0, #1]
-    ldrneb  r6, [r0, #2]
-    ldrneb  r7, [r0, #3]
-
-    pld     [r0, #31]               ; preload for next 16x16 block
-
-    bne     copy_mem16x16_1_loop
-
-    ldmia       sp!, {r4 - r7}
-    ;pop        {r4-r7}
-    mov     pc, lr
-
-;copy 4 bytes each time
-copy_mem16x16_4
-    ldr     r4, [r0]
-    ldr     r5, [r0, #4]
-    ldr     r6, [r0, #8]
-    ldr     r7, [r0, #12]
-
-    mov     r12, #16
-
-copy_mem16x16_4_loop
-    subs    r12, r12, #1
-    add     r0, r0, r1
-
-    str     r4, [r2]
-    str     r5, [r2, #4]
-    str     r6, [r2, #8]
-    str     r7, [r2, #12]
-
-    add     r2, r2, r3
-
-    ldrne   r4, [r0]
-    ldrne   r5, [r0, #4]
-    ldrne   r6, [r0, #8]
-    ldrne   r7, [r0, #12]
-
-    pld     [r0, #31]               ; preload for next 16x16 block
-
-    bne     copy_mem16x16_4_loop
-
-    ldmia       sp!, {r4 - r7}
-    ;pop        {r4-r7}
-    mov     pc, lr
-
-;copy 8 bytes each time
-copy_mem16x16_8
-    sub     r1, r1, #16
-    sub     r3, r3, #16
-
-    mov     r12, #16
-
-copy_mem16x16_8_loop
-    ldmia   r0!, {r4-r5}
-    ;ldm        r0, {r4-r5}
-    ldmia   r0!, {r6-r7}
-
-    add     r0, r0, r1
-
-    stmia   r2!, {r4-r5}
-    subs    r12, r12, #1
-    ;stm        r2, {r4-r5}
-    stmia   r2!, {r6-r7}
-
-    add     r2, r2, r3
-
-    pld     [r0, #31]               ; preload for next 16x16 block
-    bne     copy_mem16x16_8_loop
-
-    ldmia       sp!, {r4 - r7}
-    ;pop        {r4-r7}
-    mov     pc, lr
-
-;copy 16 bytes each time
-copy_mem16x16_fast
-    ;sub        r1, r1, #16
-    ;sub        r3, r3, #16
-
-    mov     r12, #16
-
-copy_mem16x16_fast_loop
-    ldmia   r0, {r4-r7}
-    ;ldm        r0, {r4-r7}
-    add     r0, r0, r1
-
-    subs    r12, r12, #1
-    stmia   r2, {r4-r7}
-    ;stm        r2, {r4-r7}
-    add     r2, r2, r3
-
-    pld     [r0, #31]               ; preload for next 16x16 block
-    bne     copy_mem16x16_fast_loop
-
-    ldmia       sp!, {r4 - r7}
-    ;pop        {r4-r7}
-    mov     pc, lr
-
-    ENDP  ; |vp8_copy_mem16x16_v6|
-
-    END
diff --git a/vp8/common/arm/armv6/copymem8x4_v6.asm b/vp8/common/arm/armv6/copymem8x4_v6.asm
deleted file mode 100644 (file)
index d8362ef..0000000
+++ /dev/null
@@ -1,128 +0,0 @@
-;
-;  Copyright (c) 2010 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_copy_mem8x4_v6|
-    ; ARM
-    ; REQUIRE8
-    ; PRESERVE8
-
-    AREA    Block, CODE, READONLY ; name this block of code
-;void vp8_copy_mem8x4_v6( unsigned char *src, int src_stride, unsigned char *dst, int dst_stride)
-;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-|vp8_copy_mem8x4_v6| PROC
-    ;push   {r4-r5}
-    stmdb  sp!, {r4-r5}
-
-    ;preload
-    pld     [r0]
-    pld     [r0, r1]
-    pld     [r0, r1, lsl #1]
-
-    ands    r4, r0, #7
-    beq     copy_mem8x4_fast
-
-    ands    r4, r0, #3
-    beq     copy_mem8x4_4
-
-    ;copy 1 byte each time
-    ldrb    r4, [r0]
-    ldrb    r5, [r0, #1]
-
-    mov     r12, #4
-
-copy_mem8x4_1_loop
-    strb    r4, [r2]
-    strb    r5, [r2, #1]
-
-    ldrb    r4, [r0, #2]
-    ldrb    r5, [r0, #3]
-
-    subs    r12, r12, #1
-
-    strb    r4, [r2, #2]
-    strb    r5, [r2, #3]
-
-    ldrb    r4, [r0, #4]
-    ldrb    r5, [r0, #5]
-
-    strb    r4, [r2, #4]
-    strb    r5, [r2, #5]
-
-    ldrb    r4, [r0, #6]
-    ldrb    r5, [r0, #7]
-
-    add     r0, r0, r1
-
-    strb    r4, [r2, #6]
-    strb    r5, [r2, #7]
-
-    add     r2, r2, r3
-
-    ldrneb  r4, [r0]
-    ldrneb  r5, [r0, #1]
-
-    bne     copy_mem8x4_1_loop
-
-    ldmia       sp!, {r4 - r5}
-    ;pop        {r4-r5}
-    mov     pc, lr
-
-;copy 4 bytes each time
-copy_mem8x4_4
-    ldr     r4, [r0]
-    ldr     r5, [r0, #4]
-
-    mov     r12, #4
-
-copy_mem8x4_4_loop
-    subs    r12, r12, #1
-    add     r0, r0, r1
-
-    str     r4, [r2]
-    str     r5, [r2, #4]
-
-    add     r2, r2, r3
-
-    ldrne   r4, [r0]
-    ldrne   r5, [r0, #4]
-
-    bne     copy_mem8x4_4_loop
-
-    ldmia  sp!, {r4-r5}
-    ;pop        {r4-r5}
-    mov     pc, lr
-
-;copy 8 bytes each time
-copy_mem8x4_fast
-    ;sub        r1, r1, #8
-    ;sub        r3, r3, #8
-
-    mov     r12, #4
-
-copy_mem8x4_fast_loop
-    ldmia   r0, {r4-r5}
-    ;ldm        r0, {r4-r5}
-    add     r0, r0, r1
-
-    subs    r12, r12, #1
-    stmia   r2, {r4-r5}
-    ;stm        r2, {r4-r5}
-    add     r2, r2, r3
-
-    bne     copy_mem8x4_fast_loop
-
-    ldmia  sp!, {r4-r5}
-    ;pop        {r4-r5}
-    mov     pc, lr
-
-    ENDP  ; |vp8_copy_mem8x4_v6|
-
-    END
diff --git a/vp8/common/arm/armv6/copymem8x8_v6.asm b/vp8/common/arm/armv6/copymem8x8_v6.asm
deleted file mode 100644 (file)
index c6a60c6..0000000
+++ /dev/null
@@ -1,128 +0,0 @@
-;
-;  Copyright (c) 2010 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_copy_mem8x8_v6|
-    ; ARM
-    ; REQUIRE8
-    ; PRESERVE8
-
-    AREA    Block, CODE, READONLY ; name this block of code
-;void copy_mem8x8_v6( unsigned char *src, int src_stride, unsigned char *dst, int dst_stride)
-;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-|vp8_copy_mem8x8_v6| PROC
-    ;push   {r4-r5}
-    stmdb  sp!, {r4-r5}
-
-    ;preload
-    pld     [r0]
-    pld     [r0, r1]
-    pld     [r0, r1, lsl #1]
-
-    ands    r4, r0, #7
-    beq     copy_mem8x8_fast
-
-    ands    r4, r0, #3
-    beq     copy_mem8x8_4
-
-    ;copy 1 byte each time
-    ldrb    r4, [r0]
-    ldrb    r5, [r0, #1]
-
-    mov     r12, #8
-
-copy_mem8x8_1_loop
-    strb    r4, [r2]
-    strb    r5, [r2, #1]
-
-    ldrb    r4, [r0, #2]
-    ldrb    r5, [r0, #3]
-
-    subs    r12, r12, #1
-
-    strb    r4, [r2, #2]
-    strb    r5, [r2, #3]
-
-    ldrb    r4, [r0, #4]
-    ldrb    r5, [r0, #5]
-
-    strb    r4, [r2, #4]
-    strb    r5, [r2, #5]
-
-    ldrb    r4, [r0, #6]
-    ldrb    r5, [r0, #7]
-
-    add     r0, r0, r1
-
-    strb    r4, [r2, #6]
-    strb    r5, [r2, #7]
-
-    add     r2, r2, r3
-
-    ldrneb  r4, [r0]
-    ldrneb  r5, [r0, #1]
-
-    bne     copy_mem8x8_1_loop
-
-    ldmia       sp!, {r4 - r5}
-    ;pop        {r4-r5}
-    mov     pc, lr
-
-;copy 4 bytes each time
-copy_mem8x8_4
-    ldr     r4, [r0]
-    ldr     r5, [r0, #4]
-
-    mov     r12, #8
-
-copy_mem8x8_4_loop
-    subs    r12, r12, #1
-    add     r0, r0, r1
-
-    str     r4, [r2]
-    str     r5, [r2, #4]
-
-    add     r2, r2, r3
-
-    ldrne   r4, [r0]
-    ldrne   r5, [r0, #4]
-
-    bne     copy_mem8x8_4_loop
-
-    ldmia       sp!, {r4 - r5}
-    ;pop        {r4-r5}
-    mov     pc, lr
-
-;copy 8 bytes each time
-copy_mem8x8_fast
-    ;sub        r1, r1, #8
-    ;sub        r3, r3, #8
-
-    mov     r12, #8
-
-copy_mem8x8_fast_loop
-    ldmia   r0, {r4-r5}
-    ;ldm        r0, {r4-r5}
-    add     r0, r0, r1
-
-    subs    r12, r12, #1
-    stmia   r2, {r4-r5}
-    ;stm        r2, {r4-r5}
-    add     r2, r2, r3
-
-    bne     copy_mem8x8_fast_loop
-
-    ldmia  sp!, {r4-r5}
-    ;pop        {r4-r5}
-    mov     pc, lr
-
-    ENDP  ; |vp8_copy_mem8x8_v6|
-
-    END
diff --git a/vp8/common/arm/armv6/dc_only_idct_add_v6.asm b/vp8/common/arm/armv6/dc_only_idct_add_v6.asm
deleted file mode 100644 (file)
index 9aa659f..0000000
+++ /dev/null
@@ -1,70 +0,0 @@
-;
-;  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
-;
-;  Use of this source code is governed by a BSD-style license and patent
-;  grant that can be found in the LICENSE file in the root of the source
-;  tree. All contributing project authors may be found in the AUTHORS
-;  file in the root of the source tree.
-;
-
-    EXPORT  |vp8_dc_only_idct_add_v6|
-
-    AREA    |.text|, CODE, READONLY
-
-;void vp8_dc_only_idct_add_c(short input_dc, unsigned char *pred_ptr,
-;                            int pred_stride, unsigned char *dst_ptr,
-;                            int dst_stride)
-; r0  input_dc
-; r1  pred_ptr
-; r2  pred_stride
-; r3  dst_ptr
-; sp  dst_stride
-
-|vp8_dc_only_idct_add_v6| PROC
-    stmdb       sp!, {r4 - r7}
-
-    add         r0, r0, #4                ; input_dc += 4
-    ldr         r12, c0x0000FFFF
-    ldr         r4, [r1], r2
-    and         r0, r12, r0, asr #3       ; input_dc >> 3 + mask
-    ldr         r6, [r1], r2
-    orr         r0, r0, r0, lsl #16       ; a1 | a1
-
-    ldr         r12, [sp, #16]            ; dst stride
-
-    uxtab16     r5, r0, r4                ; a1+2 | a1+0
-    uxtab16     r4, r0, r4, ror #8        ; a1+3 | a1+1
-    uxtab16     r7, r0, r6
-    uxtab16     r6, r0, r6, ror #8
-    usat16      r5, #8, r5
-    usat16      r4, #8, r4
-    usat16      r7, #8, r7
-    usat16      r6, #8, r6
-    orr         r5, r5, r4, lsl #8
-    orr         r7, r7, r6, lsl #8
-    ldr         r4, [r1], r2
-    str         r5, [r3], r12
-    ldr         r6, [r1]
-    str         r7, [r3], r12
-
-    uxtab16     r5, r0, r4
-    uxtab16     r4, r0, r4, ror #8
-    uxtab16     r7, r0, r6
-    uxtab16     r6, r0, r6, ror #8
-    usat16      r5, #8, r5
-    usat16      r4, #8, r4
-    usat16      r7, #8, r7
-    usat16      r6, #8, r6
-    orr         r5, r5, r4, lsl #8
-    orr         r7, r7, r6, lsl #8
-    str         r5, [r3], r12
-    str         r7, [r3]
-
-    ldmia       sp!, {r4 - r7}
-    bx          lr
-
-    ENDP  ; |vp8_dc_only_idct_add_v6|
-
-; Constant Pool
-c0x0000FFFF DCD 0x0000FFFF
-    END
diff --git a/vp8/common/arm/armv6/dequant_idct_v6.asm b/vp8/common/arm/armv6/dequant_idct_v6.asm
deleted file mode 100644 (file)
index db48ded..0000000
+++ /dev/null
@@ -1,190 +0,0 @@
-;
-;  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
-;
-;  Use of this source code is governed by a BSD-style license and patent
-;  grant that can be found in the LICENSE file in the root of the source
-;  tree. All contributing project authors may be found in the AUTHORS
-;  file in the root of the source tree.
-;
-
-    EXPORT |vp8_dequant_idct_add_v6|
-
-    AREA |.text|, CODE, READONLY
-;void vp8_dequant_idct_v6(short *input, short *dq,
-;                         unsigned char *dest, int stride)
-; r0 = q
-; r1 = dq
-; r2 = dst
-; r3 = stride
-
-|vp8_dequant_idct_add_v6| PROC
-    stmdb   sp!, {r4-r11, lr}
-
-    ldr     r4, [r0]                ;input
-    ldr     r5, [r1], #4            ;dq
-
-    sub     sp, sp, #4
-    str     r3, [sp]
-
-    mov     r12, #4
-
-vp8_dequant_add_loop
-    smulbb  r6, r4, r5
-    smultt  r7, r4, r5
-
-    ldr     r4, [r0, #4]            ;input
-    ldr     r5, [r1], #4            ;dq
-
-    strh    r6, [r0], #2
-    strh    r7, [r0], #2
-
-    smulbb  r6, r4, r5
-    smultt  r7, r4, r5
-
-    subs    r12, r12, #1
-
-    ldrne   r4, [r0, #4]
-    ldrne   r5, [r1], #4
-
-    strh    r6, [r0], #2
-    strh    r7, [r0], #2
-
-    bne     vp8_dequant_add_loop
-
-    sub     r0, r0, #32
-    mov     r1, r0
-
-; short_idct4x4llm_v6_dual
-    ldr     r3, cospi8sqrt2minus1
-    ldr     r4, sinpi8sqrt2
-    ldr     r6, [r0, #8]
-    mov     r5, #2
-vp8_dequant_idct_loop1_v6
-    ldr     r12, [r0, #24]
-    ldr     r14, [r0, #16]
-    smulwt  r9, r3, r6
-    smulwb  r7, r3, r6
-    smulwt  r10, r4, r6
-    smulwb  r8, r4, r6
-    pkhbt   r7, r7, r9, lsl #16
-    smulwt  r11, r3, r12
-    pkhbt   r8, r8, r10, lsl #16
-    uadd16  r6, r6, r7
-    smulwt  r7, r4, r12
-    smulwb  r9, r3, r12
-    smulwb  r10, r4, r12
-    subs    r5, r5, #1
-    pkhbt   r9, r9, r11, lsl #16
-    ldr     r11, [r0], #4
-    pkhbt   r10, r10, r7, lsl #16
-    uadd16  r7, r12, r9
-    usub16  r7, r8, r7
-    uadd16  r6, r6, r10
-    uadd16  r10, r11, r14
-    usub16  r8, r11, r14
-    uadd16  r9, r10, r6
-    usub16  r10, r10, r6
-    uadd16  r6, r8, r7
-    usub16  r7, r8, r7
-    str     r6, [r1, #8]
-    ldrne   r6, [r0, #8]
-    str     r7, [r1, #16]
-    str     r10, [r1, #24]
-    str     r9, [r1], #4
-    bne     vp8_dequant_idct_loop1_v6
-
-    mov     r5, #2
-    sub     r0, r1, #8
-vp8_dequant_idct_loop2_v6
-    ldr     r6, [r0], #4
-    ldr     r7, [r0], #4
-    ldr     r8, [r0], #4
-    ldr     r9, [r0], #4
-    smulwt  r1, r3, r6
-    smulwt  r12, r4, r6
-    smulwt  lr, r3, r8
-    smulwt  r10, r4, r8
-    pkhbt   r11, r8, r6, lsl #16
-    pkhbt   r1, lr, r1, lsl #16
-    pkhbt   r12, r10, r12, lsl #16
-    pkhtb   r6, r6, r8, asr #16
-    uadd16  r6, r1, r6
-    pkhbt   lr, r9, r7, lsl #16
-    uadd16  r10, r11, lr
-    usub16  lr, r11, lr
-    pkhtb   r8, r7, r9, asr #16
-    subs    r5, r5, #1
-    smulwt  r1, r3, r8
-    smulwb  r7, r3, r8
-    smulwt  r11, r4, r8
-    smulwb  r9, r4, r8
-    pkhbt   r1, r7, r1, lsl #16
-    uadd16  r8, r1, r8
-    pkhbt   r11, r9, r11, lsl #16
-    usub16  r1, r12, r8
-    uadd16  r8, r11, r6
-    ldr     r9, c0x00040004
-    ldr     r12, [sp]               ; get stride from stack
-    uadd16  r6, r10, r8
-    usub16  r7, r10, r8
-    uadd16  r7, r7, r9
-    uadd16  r6, r6, r9
-    uadd16  r10, r14, r1
-    usub16  r1, r14, r1
-    uadd16  r10, r10, r9
-    uadd16  r1, r1, r9
-    ldr     r11, [r2]               ; load input from dst
-    mov     r8, r7, asr #3
-    pkhtb   r9, r8, r10, asr #19
-    mov     r8, r1, asr #3
-    pkhtb   r8, r8, r6, asr #19
-    uxtb16  lr, r11, ror #8
-    qadd16  r9, r9, lr
-    uxtb16  lr, r11
-    qadd16  r8, r8, lr
-    usat16  r9, #8, r9
-    usat16  r8, #8, r8
-    orr     r9, r8, r9, lsl #8
-    ldr     r11, [r2, r12]          ; load input from dst
-    mov     r7, r7, lsl #16
-    mov     r1, r1, lsl #16
-    mov     r10, r10, lsl #16
-    mov     r6, r6, lsl #16
-    mov     r7, r7, asr #3
-    pkhtb   r7, r7, r10, asr #19
-    mov     r1, r1, asr #3
-    pkhtb   r1, r1, r6, asr #19
-    uxtb16  r8, r11, ror #8
-    qadd16  r7, r7, r8
-    uxtb16  r8, r11
-    qadd16  r1, r1, r8
-    usat16  r7, #8, r7
-    usat16  r1, #8, r1
-    orr     r1, r1, r7, lsl #8
-    str     r9, [r2], r12           ; store output to dst
-    str     r1, [r2], r12           ; store output to dst
-    bne     vp8_dequant_idct_loop2_v6
-
-; memset
-    sub     r0, r0, #32
-    add     sp, sp, #4
-
-    mov     r12, #0
-    str     r12, [r0]
-    str     r12, [r0, #4]
-    str     r12, [r0, #8]
-    str     r12, [r0, #12]
-    str     r12, [r0, #16]
-    str     r12, [r0, #20]
-    str     r12, [r0, #24]
-    str     r12, [r0, #28]
-
-    ldmia   sp!, {r4 - r11, pc}
-    ENDP    ; |vp8_dequant_idct_add_v6|
-
-; Constant Pool
-cospi8sqrt2minus1 DCD 0x00004E7B
-sinpi8sqrt2       DCD 0x00008A8C
-c0x00040004       DCD 0x00040004
-
-    END
diff --git a/vp8/common/arm/armv6/dequantize_v6.asm b/vp8/common/arm/armv6/dequantize_v6.asm
deleted file mode 100644 (file)
index 72f7e0e..0000000
+++ /dev/null
@@ -1,69 +0,0 @@
-;
-;  Copyright (c) 2010 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_dequantize_b_loop_v6|
-
-    AREA    |.text|, CODE, READONLY  ; name this block of code
-;-------------------------------
-;void   vp8_dequantize_b_loop_v6(short *Q, short *DQC, short *DQ);
-; r0    short *Q,
-; r1    short *DQC
-; r2    short *DQ
-|vp8_dequantize_b_loop_v6| PROC
-    stmdb   sp!, {r4-r9, lr}
-
-    ldr     r3, [r0]                ;load Q
-    ldr     r4, [r1]                ;load DQC
-    ldr     r5, [r0, #4]
-    ldr     r6, [r1, #4]
-
-    mov     r12, #2                 ;loop counter
-
-dequant_loop
-    smulbb  r7, r3, r4              ;multiply
-    smultt  r8, r3, r4
-    smulbb  r9, r5, r6
-    smultt  lr, r5, r6
-
-    ldr     r3, [r0, #8]
-    ldr     r4, [r1, #8]
-    ldr     r5, [r0, #12]
-    ldr     r6, [r1, #12]
-
-    strh    r7, [r2], #2            ;store result
-    smulbb  r7, r3, r4              ;multiply
-    strh    r8, [r2], #2
-    smultt  r8, r3, r4
-    strh    r9, [r2], #2
-    smulbb  r9, r5, r6
-    strh    lr, [r2], #2
-    smultt  lr, r5, r6
-
-    subs    r12, r12, #1
-
-    add     r0, r0, #16
-    add     r1, r1, #16
-
-    ldrne       r3, [r0]
-    strh    r7, [r2], #2            ;store result
-    ldrne       r4, [r1]
-    strh    r8, [r2], #2
-    ldrne       r5, [r0, #4]
-    strh    r9, [r2], #2
-    ldrne       r6, [r1, #4]
-    strh    lr, [r2], #2
-
-    bne     dequant_loop
-
-    ldmia   sp!, {r4-r9, pc}
-    ENDP    ;|vp8_dequantize_b_loop_v6|
-
-    END
diff --git a/vp8/common/arm/armv6/filter_v6.asm b/vp8/common/arm/armv6/filter_v6.asm
deleted file mode 100644 (file)
index eb4b75b..0000000
+++ /dev/null
@@ -1,624 +0,0 @@
-;
-;  Copyright (c) 2010 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_filter_block2d_first_pass_armv6|
-    EXPORT  |vp8_filter_block2d_first_pass_16x16_armv6|
-    EXPORT  |vp8_filter_block2d_first_pass_8x8_armv6|
-    EXPORT  |vp8_filter_block2d_second_pass_armv6|
-    EXPORT  |vp8_filter4_block2d_second_pass_armv6|
-    EXPORT  |vp8_filter_block2d_first_pass_only_armv6|
-    EXPORT  |vp8_filter_block2d_second_pass_only_armv6|
-
-    AREA    |.text|, CODE, READONLY  ; name this block of code
-;-------------------------------------
-; r0    unsigned char *src_ptr
-; r1    short         *output_ptr
-; r2    unsigned int src_pixels_per_line
-; r3    unsigned int output_width
-; stack unsigned int output_height
-; stack const short *vp8_filter
-;-------------------------------------
-; vp8_filter the input and put in the output array.  Apply the 6 tap FIR filter with
-; the output being a 2 byte value and the intput being a 1 byte value.
-|vp8_filter_block2d_first_pass_armv6| PROC
-    stmdb   sp!, {r4 - r11, lr}
-
-    ldr     r11, [sp, #40]                  ; vp8_filter address
-    ldr     r7, [sp, #36]                   ; output height
-
-    sub     r2, r2, r3                      ; inside loop increments input array,
-                                            ; so the height loop only needs to add
-                                            ; r2 - width to the input pointer
-
-    mov     r3, r3, lsl #1                  ; multiply width by 2 because using shorts
-    add     r12, r3, #16                    ; square off the output
-    sub     sp, sp, #4
-
-    ldr     r4, [r11]                       ; load up packed filter coefficients
-    ldr     r5, [r11, #4]
-    ldr     r6, [r11, #8]
-
-    str     r1, [sp]                        ; push destination to stack
-    mov     r7, r7, lsl #16                 ; height is top part of counter
-
-; six tap filter
-|height_loop_1st_6|
-    ldrb    r8, [r0, #-2]                   ; load source data
-    ldrb    r9, [r0, #-1]
-    ldrb    r10, [r0], #2
-    orr     r7, r7, r3, lsr #2              ; construct loop counter
-
-|width_loop_1st_6|
-    ldrb    r11, [r0, #-1]
-
-    pkhbt   lr, r8, r9, lsl #16             ; r9 | r8
-    pkhbt   r8, r9, r10, lsl #16            ; r10 | r9
-
-    ldrb    r9, [r0]
-
-    smuad   lr, lr, r4                      ; apply the filter
-    pkhbt   r10, r10, r11, lsl #16          ; r11 | r10
-    smuad   r8, r8, r4
-    pkhbt   r11, r11, r9, lsl #16           ; r9 | r11
-
-    smlad   lr, r10, r5, lr
-    ldrb    r10, [r0, #1]
-    smlad   r8, r11, r5, r8
-    ldrb    r11, [r0, #2]
-
-    sub     r7, r7, #1
-
-    pkhbt   r9, r9, r10, lsl #16            ; r10 | r9
-    pkhbt   r10, r10, r11, lsl #16          ; r11 | r10
-
-    smlad   lr, r9, r6, lr
-    smlad   r11, r10, r6, r8
-
-    ands    r10, r7, #0xff                  ; test loop counter
-
-    add     lr, lr, #0x40                   ; round_shift_and_clamp
-    ldrneb  r8, [r0, #-2]                   ; load data for next loop
-    usat    lr, #8, lr, asr #7
-    add     r11, r11, #0x40
-    ldrneb  r9, [r0, #-1]
-    usat    r11, #8, r11, asr #7
-
-    strh    lr, [r1], r12                   ; result is transposed and stored, which
-                                            ; will make second pass filtering easier.
-    ldrneb  r10, [r0], #2
-    strh    r11, [r1], r12
-
-    bne     width_loop_1st_6
-
-    ldr     r1, [sp]                        ; load and update dst address
-    subs    r7, r7, #0x10000
-    add     r0, r0, r2                      ; move to next input line
-
-    add     r1, r1, #2                      ; move over to next column
-    str     r1, [sp]
-
-    bne     height_loop_1st_6
-
-    add     sp, sp, #4
-    ldmia   sp!, {r4 - r11, pc}
-
-    ENDP
-
-; --------------------------
-; 16x16 version
-; -----------------------------
-|vp8_filter_block2d_first_pass_16x16_armv6| PROC
-    stmdb   sp!, {r4 - r11, lr}
-
-    ldr     r11, [sp, #40]                  ; vp8_filter address
-    ldr     r7, [sp, #36]                   ; output height
-
-    add     r4, r2, #18                     ; preload next low
-    pld     [r0, r4]
-
-    sub     r2, r2, r3                      ; inside loop increments input array,
-                                            ; so the height loop only needs to add
-                                            ; r2 - width to the input pointer
-
-    mov     r3, r3, lsl #1                  ; multiply width by 2 because using shorts
-    add     r12, r3, #16                    ; square off the output
-    sub     sp, sp, #4
-
-    ldr     r4, [r11]                       ; load up packed filter coefficients
-    ldr     r5, [r11, #4]
-    ldr     r6, [r11, #8]
-
-    str     r1, [sp]                        ; push destination to stack
-    mov     r7, r7, lsl #16                 ; height is top part of counter
-
-; six tap filter
-|height_loop_1st_16_6|
-    ldrb    r8, [r0, #-2]                   ; load source data
-    ldrb    r9, [r0, #-1]
-    ldrb    r10, [r0], #2
-    orr     r7, r7, r3, lsr #2              ; construct loop counter
-
-|width_loop_1st_16_6|
-    ldrb    r11, [r0, #-1]
-
-    pkhbt   lr, r8, r9, lsl #16             ; r9 | r8
-    pkhbt   r8, r9, r10, lsl #16            ; r10 | r9
-
-    ldrb    r9, [r0]
-
-    smuad   lr, lr, r4                      ; apply the filter
-    pkhbt   r10, r10, r11, lsl #16          ; r11 | r10
-    smuad   r8, r8, r4
-    pkhbt   r11, r11, r9, lsl #16           ; r9 | r11
-
-    smlad   lr, r10, r5, lr
-    ldrb    r10, [r0, #1]
-    smlad   r8, r11, r5, r8
-    ldrb    r11, [r0, #2]
-
-    sub     r7, r7, #1
-
-    pkhbt   r9, r9, r10, lsl #16            ; r10 | r9
-    pkhbt   r10, r10, r11, lsl #16          ; r11 | r10
-
-    smlad   lr, r9, r6, lr
-    smlad   r11, r10, r6, r8
-
-    ands    r10, r7, #0xff                  ; test loop counter
-
-    add     lr, lr, #0x40                   ; round_shift_and_clamp
-    ldrneb  r8, [r0, #-2]                   ; load data for next loop
-    usat    lr, #8, lr, asr #7
-    add     r11, r11, #0x40
-    ldrneb  r9, [r0, #-1]
-    usat    r11, #8, r11, asr #7
-
-    strh    lr, [r1], r12                   ; result is transposed and stored, which
-                                            ; will make second pass filtering easier.
-    ldrneb  r10, [r0], #2
-    strh    r11, [r1], r12
-
-    bne     width_loop_1st_16_6
-
-    ldr     r1, [sp]                        ; load and update dst address
-    subs    r7, r7, #0x10000
-    add     r0, r0, r2                      ; move to next input line
-
-    add     r11, r2, #34                    ; adding back block width(=16)
-    pld     [r0, r11]                       ; preload next low
-
-    add     r1, r1, #2                      ; move over to next column
-    str     r1, [sp]
-
-    bne     height_loop_1st_16_6
-
-    add     sp, sp, #4
-    ldmia   sp!, {r4 - r11, pc}
-
-    ENDP
-
-; --------------------------
-; 8x8 version
-; -----------------------------
-|vp8_filter_block2d_first_pass_8x8_armv6| PROC
-    stmdb   sp!, {r4 - r11, lr}
-
-    ldr     r11, [sp, #40]                  ; vp8_filter address
-    ldr     r7, [sp, #36]                   ; output height
-
-    add     r4, r2, #10                     ; preload next low
-    pld     [r0, r4]
-
-    sub     r2, r2, r3                      ; inside loop increments input array,
-                                            ; so the height loop only needs to add
-                                            ; r2 - width to the input pointer
-
-    mov     r3, r3, lsl #1                  ; multiply width by 2 because using shorts
-    add     r12, r3, #16                    ; square off the output
-    sub     sp, sp, #4
-
-    ldr     r4, [r11]                       ; load up packed filter coefficients
-    ldr     r5, [r11, #4]
-    ldr     r6, [r11, #8]
-
-    str     r1, [sp]                        ; push destination to stack
-    mov     r7, r7, lsl #16                 ; height is top part of counter
-
-; six tap filter
-|height_loop_1st_8_6|
-    ldrb    r8, [r0, #-2]                   ; load source data
-    ldrb    r9, [r0, #-1]
-    ldrb    r10, [r0], #2
-    orr     r7, r7, r3, lsr #2              ; construct loop counter
-
-|width_loop_1st_8_6|
-    ldrb    r11, [r0, #-1]
-
-    pkhbt   lr, r8, r9, lsl #16             ; r9 | r8
-    pkhbt   r8, r9, r10, lsl #16            ; r10 | r9
-
-    ldrb    r9, [r0]
-
-    smuad   lr, lr, r4                      ; apply the filter
-    pkhbt   r10, r10, r11, lsl #16          ; r11 | r10
-    smuad   r8, r8, r4
-    pkhbt   r11, r11, r9, lsl #16           ; r9 | r11
-
-    smlad   lr, r10, r5, lr
-    ldrb    r10, [r0, #1]
-    smlad   r8, r11, r5, r8
-    ldrb    r11, [r0, #2]
-
-    sub     r7, r7, #1
-
-    pkhbt   r9, r9, r10, lsl #16            ; r10 | r9
-    pkhbt   r10, r10, r11, lsl #16          ; r11 | r10
-
-    smlad   lr, r9, r6, lr
-    smlad   r11, r10, r6, r8
-
-    ands    r10, r7, #0xff                  ; test loop counter
-
-    add     lr, lr, #0x40                   ; round_shift_and_clamp
-    ldrneb  r8, [r0, #-2]                   ; load data for next loop
-    usat    lr, #8, lr, asr #7
-    add     r11, r11, #0x40
-    ldrneb  r9, [r0, #-1]
-    usat    r11, #8, r11, asr #7
-
-    strh    lr, [r1], r12                   ; result is transposed and stored, which
-                                            ; will make second pass filtering easier.
-    ldrneb  r10, [r0], #2
-    strh    r11, [r1], r12
-
-    bne     width_loop_1st_8_6
-
-    ldr     r1, [sp]                        ; load and update dst address
-    subs    r7, r7, #0x10000
-    add     r0, r0, r2                      ; move to next input line
-
-    add     r11, r2, #18                    ; adding back block width(=8)
-    pld     [r0, r11]                       ; preload next low
-
-    add     r1, r1, #2                      ; move over to next column
-    str     r1, [sp]
-
-    bne     height_loop_1st_8_6
-
-    add     sp, sp, #4
-    ldmia   sp!, {r4 - r11, pc}
-
-    ENDP
-
-;---------------------------------
-; r0    short         *src_ptr,
-; r1    unsigned char *output_ptr,
-; r2    unsigned int output_pitch,
-; r3    unsigned int cnt,
-; stack const short *vp8_filter
-;---------------------------------
-|vp8_filter_block2d_second_pass_armv6| PROC
-    stmdb   sp!, {r4 - r11, lr}
-
-    ldr     r11, [sp, #36]                  ; vp8_filter address
-    sub     sp, sp, #4
-    mov     r7, r3, lsl #16                 ; height is top part of counter
-    str     r1, [sp]                        ; push destination to stack
-
-    ldr     r4, [r11]                       ; load up packed filter coefficients
-    ldr     r5, [r11, #4]
-    ldr     r6, [r11, #8]
-
-    pkhbt   r12, r5, r4                     ; pack the filter differently
-    pkhbt   r11, r6, r5
-
-    sub     r0, r0, #4                      ; offset input buffer
-
-|height_loop_2nd|
-    ldr     r8, [r0]                        ; load the data
-    ldr     r9, [r0, #4]
-    orr     r7, r7, r3, lsr #1              ; loop counter
-
-|width_loop_2nd|
-    smuad   lr, r4, r8                      ; apply filter
-    sub     r7, r7, #1
-    smulbt  r8, r4, r8
-
-    ldr     r10, [r0, #8]
-
-    smlad   lr, r5, r9, lr
-    smladx  r8, r12, r9, r8
-
-    ldrh    r9, [r0, #12]
-
-    smlad   lr, r6, r10, lr
-    smladx  r8, r11, r10, r8
-
-    add     r0, r0, #4
-    smlatb  r10, r6, r9, r8
-
-    add     lr, lr, #0x40                   ; round_shift_and_clamp
-    ands    r8, r7, #0xff
-    usat    lr, #8, lr, asr #7
-    add     r10, r10, #0x40
-    strb    lr, [r1], r2                    ; the result is transposed back and stored
-    usat    r10, #8, r10, asr #7
-
-    ldrne   r8, [r0]                        ; load data for next loop
-    ldrne   r9, [r0, #4]
-    strb    r10, [r1], r2
-
-    bne     width_loop_2nd
-
-    ldr     r1, [sp]                        ; update dst for next loop
-    subs    r7, r7, #0x10000
-    add     r0, r0, #16                     ; updata src for next loop
-    add     r1, r1, #1
-    str     r1, [sp]
-
-    bne     height_loop_2nd
-
-    add     sp, sp, #4
-    ldmia   sp!, {r4 - r11, pc}
-
-    ENDP
-
-;---------------------------------
-; r0    short         *src_ptr,
-; r1    unsigned char *output_ptr,
-; r2    unsigned int output_pitch,
-; r3    unsigned int cnt,
-; stack const short *vp8_filter
-;---------------------------------
-|vp8_filter4_block2d_second_pass_armv6| PROC
-    stmdb   sp!, {r4 - r11, lr}
-
-    ldr     r11, [sp, #36]                  ; vp8_filter address
-    mov     r7, r3, lsl #16                 ; height is top part of counter
-
-    ldr     r4, [r11]                       ; load up packed filter coefficients
-    add     lr, r1, r3                      ; save final destination pointer
-    ldr     r5, [r11, #4]
-    ldr     r6, [r11, #8]
-
-    pkhbt   r12, r5, r4                     ; pack the filter differently
-    pkhbt   r11, r6, r5
-    mov     r4, #0x40                       ; rounding factor (for smlad{x})
-
-|height_loop_2nd_4|
-    ldrd    r8, r9, [r0, #-4]               ; load the data
-    orr     r7, r7, r3, lsr #1              ; loop counter
-
-|width_loop_2nd_4|
-    ldr     r10, [r0, #4]!
-    smladx  r6, r9, r12, r4                 ; apply filter
-    pkhbt   r8, r9, r8
-    smlad   r5, r8, r12, r4
-    pkhbt   r8, r10, r9
-    smladx  r6, r10, r11, r6
-    sub     r7, r7, #1
-    smlad   r5, r8, r11, r5
-
-    mov     r8, r9                          ; shift the data for the next loop
-    mov     r9, r10
-
-    usat    r6, #8, r6, asr #7              ; shift and clamp
-    usat    r5, #8, r5, asr #7
-
-    strb    r5, [r1], r2                    ; the result is transposed back and stored
-    tst     r7, #0xff
-    strb    r6, [r1], r2
-
-    bne     width_loop_2nd_4
-
-    subs    r7, r7, #0x10000
-    add     r0, r0, #16                     ; update src for next loop
-    sub     r1, lr, r7, lsr #16             ; update dst for next loop
-
-    bne     height_loop_2nd_4
-
-    ldmia   sp!, {r4 - r11, pc}
-
-    ENDP
-
-;------------------------------------
-; r0    unsigned char *src_ptr
-; r1    unsigned char *output_ptr,
-; r2    unsigned int src_pixels_per_line
-; r3    unsigned int cnt,
-; stack unsigned int output_pitch,
-; stack const short *vp8_filter
-;------------------------------------
-|vp8_filter_block2d_first_pass_only_armv6| PROC
-    stmdb   sp!, {r4 - r11, lr}
-
-    add     r7, r2, r3                      ; preload next low
-    add     r7, r7, #2
-    pld     [r0, r7]
-
-    ldr     r4, [sp, #36]                   ; output pitch
-    ldr     r11, [sp, #40]                  ; HFilter address
-    sub     sp, sp, #8
-
-    mov     r7, r3
-    sub     r2, r2, r3                      ; inside loop increments input array,
-                                            ; so the height loop only needs to add
-                                            ; r2 - width to the input pointer
-
-    sub     r4, r4, r3
-    str     r4, [sp]                        ; save modified output pitch
-    str     r2, [sp, #4]
-
-    mov     r2, #0x40
-
-    ldr     r4, [r11]                       ; load up packed filter coefficients
-    ldr     r5, [r11, #4]
-    ldr     r6, [r11, #8]
-
-; six tap filter
-|height_loop_1st_only_6|
-    ldrb    r8, [r0, #-2]                   ; load data
-    ldrb    r9, [r0, #-1]
-    ldrb    r10, [r0], #2
-
-    mov     r12, r3, lsr #1                 ; loop counter
-
-|width_loop_1st_only_6|
-    ldrb    r11, [r0, #-1]
-
-    pkhbt   lr, r8, r9, lsl #16             ; r9 | r8
-    pkhbt   r8, r9, r10, lsl #16            ; r10 | r9
-
-    ldrb    r9, [r0]
-
-;;  smuad   lr, lr, r4
-    smlad   lr, lr, r4, r2
-    pkhbt   r10, r10, r11, lsl #16          ; r11 | r10
-;;  smuad   r8, r8, r4
-    smlad   r8, r8, r4, r2
-    pkhbt   r11, r11, r9, lsl #16           ; r9 | r11
-
-    smlad   lr, r10, r5, lr
-    ldrb    r10, [r0, #1]
-    smlad   r8, r11, r5, r8
-    ldrb    r11, [r0, #2]
-
-    subs    r12, r12, #1
-
-    pkhbt   r9, r9, r10, lsl #16            ; r10 | r9
-    pkhbt   r10, r10, r11, lsl #16          ; r11 | r10
-
-    smlad   lr, r9, r6, lr
-    smlad   r10, r10, r6, r8
-
-;;  add     lr, lr, #0x40                   ; round_shift_and_clamp
-    ldrneb  r8, [r0, #-2]                   ; load data for next loop
-    usat    lr, #8, lr, asr #7
-;;  add     r10, r10, #0x40
-    strb    lr, [r1], #1                    ; store the result
-    usat    r10, #8, r10, asr #7
-
-    ldrneb  r9, [r0, #-1]
-    strb    r10, [r1], #1
-    ldrneb  r10, [r0], #2
-
-    bne     width_loop_1st_only_6
-
-    ldr     lr, [sp]                        ; load back output pitch
-    ldr     r12, [sp, #4]                   ; load back output pitch
-    subs    r7, r7, #1
-    add     r0, r0, r12                     ; updata src for next loop
-
-    add     r11, r12, r3                    ; preload next low
-    add     r11, r11, #2
-    pld     [r0, r11]
-
-    add     r1, r1, lr                      ; update dst for next loop
-
-    bne     height_loop_1st_only_6
-
-    add     sp, sp, #8
-    ldmia   sp!, {r4 - r11, pc}
-    ENDP  ; |vp8_filter_block2d_first_pass_only_armv6|
-
-
-;------------------------------------
-; r0    unsigned char *src_ptr,
-; r1    unsigned char *output_ptr,
-; r2    unsigned int src_pixels_per_line
-; r3    unsigned int cnt,
-; stack unsigned int output_pitch,
-; stack const short *vp8_filter
-;------------------------------------
-|vp8_filter_block2d_second_pass_only_armv6| PROC
-    stmdb   sp!, {r4 - r11, lr}
-
-    ldr     r11, [sp, #40]                  ; VFilter address
-    ldr     r12, [sp, #36]                  ; output pitch
-
-    mov     r7, r3, lsl #16                 ; height is top part of counter
-    sub     r0, r0, r2, lsl #1              ; need 6 elements for filtering, 2 before, 3 after
-
-    sub     sp, sp, #8
-
-    ldr     r4, [r11]                       ; load up packed filter coefficients
-    ldr     r5, [r11, #4]
-    ldr     r6, [r11, #8]
-
-    str     r0, [sp]                        ; save r0 to stack
-    str     r1, [sp, #4]                    ; save dst to stack
-
-; six tap filter
-|width_loop_2nd_only_6|
-    ldrb    r8, [r0], r2                    ; load data
-    orr     r7, r7, r3                      ; loop counter
-    ldrb    r9, [r0], r2
-    ldrb    r10, [r0], r2
-
-|height_loop_2nd_only_6|
-    ; filter first column in this inner loop, than, move to next colum.
-    ldrb    r11, [r0], r2
-
-    pkhbt   lr, r8, r9, lsl #16             ; r9 | r8
-    pkhbt   r8, r9, r10, lsl #16            ; r10 | r9
-
-    ldrb    r9, [r0], r2
-
-    smuad   lr, lr, r4
-    pkhbt   r10, r10, r11, lsl #16          ; r11 | r10
-    smuad   r8, r8, r4
-    pkhbt   r11, r11, r9, lsl #16           ; r9 | r11
-
-    smlad   lr, r10, r5, lr
-    ldrb    r10, [r0], r2
-    smlad   r8, r11, r5, r8
-    ldrb    r11, [r0]
-
-    sub     r7, r7, #2
-    sub     r0, r0, r2, lsl #2
-
-    pkhbt   r9, r9, r10, lsl #16            ; r10 | r9
-    pkhbt   r10, r10, r11, lsl #16          ; r11 | r10
-
-    smlad   lr, r9, r6, lr
-    smlad   r10, r10, r6, r8
-
-    ands    r9, r7, #0xff
-
-    add     lr, lr, #0x40                   ; round_shift_and_clamp
-    ldrneb  r8, [r0], r2                    ; load data for next loop
-    usat    lr, #8, lr, asr #7
-    add     r10, r10, #0x40
-    strb    lr, [r1], r12                   ; store the result for the column
-    usat    r10, #8, r10, asr #7
-
-    ldrneb  r9, [r0], r2
-    strb    r10, [r1], r12
-    ldrneb  r10, [r0], r2
-
-    bne     height_loop_2nd_only_6
-
-    ldr     r0, [sp]
-    ldr     r1, [sp, #4]
-    subs    r7, r7, #0x10000
-    add     r0, r0, #1                      ; move to filter next column
-    str     r0, [sp]
-    add     r1, r1, #1
-    str     r1, [sp, #4]
-
-    bne     width_loop_2nd_only_6
-
-    add     sp, sp, #8
-
-    ldmia   sp!, {r4 - r11, pc}
-    ENDP  ; |vp8_filter_block2d_second_pass_only_armv6|
-
-    END
diff --git a/vp8/common/arm/armv6/idct_blk_v6.c b/vp8/common/arm/armv6/idct_blk_v6.c
deleted file mode 100644 (file)
index c94f84a..0000000
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#include "vpx_config.h"
-#include "vp8_rtcd.h"
-
-
-void vp8_dequant_idct_add_y_block_v6(short *q, short *dq,
-                                     unsigned char *dst,
-                                     int stride, char *eobs)
-{
-    int i;
-
-    for (i = 0; i < 4; i++)
-    {
-        if (eobs[0] > 1)
-            vp8_dequant_idct_add_v6 (q, dq, dst, stride);
-        else if (eobs[0] == 1)
-        {
-            vp8_dc_only_idct_add_v6 (q[0]*dq[0], dst, stride, dst, stride);
-            ((int *)q)[0] = 0;
-        }
-
-        if (eobs[1] > 1)
-            vp8_dequant_idct_add_v6 (q+16, dq, dst+4, stride);
-        else if (eobs[1] == 1)
-        {
-            vp8_dc_only_idct_add_v6 (q[16]*dq[0], dst+4, stride, dst+4, stride);
-            ((int *)(q+16))[0] = 0;
-        }
-
-        if (eobs[2] > 1)
-            vp8_dequant_idct_add_v6 (q+32, dq, dst+8, stride);
-        else if (eobs[2] == 1)
-        {
-            vp8_dc_only_idct_add_v6 (q[32]*dq[0], dst+8, stride, dst+8, stride);
-            ((int *)(q+32))[0] = 0;
-        }
-
-        if (eobs[3] > 1)
-            vp8_dequant_idct_add_v6 (q+48, dq, dst+12, stride);
-        else if (eobs[3] == 1)
-        {
-            vp8_dc_only_idct_add_v6 (q[48]*dq[0], dst+12, stride,dst+12,stride);
-            ((int *)(q+48))[0] = 0;
-        }
-
-        q    += 64;
-        dst  += 4*stride;
-        eobs += 4;
-    }
-}
-
-void vp8_dequant_idct_add_uv_block_v6(short *q, short *dq,
-                                      unsigned char *dstu,
-                                      unsigned char *dstv,
-                                      int stride, char *eobs)
-{
-    int i;
-
-    for (i = 0; i < 2; i++)
-    {
-        if (eobs[0] > 1)
-            vp8_dequant_idct_add_v6 (q, dq, dstu, stride);
-        else if (eobs[0] == 1)
-        {
-            vp8_dc_only_idct_add_v6 (q[0]*dq[0], dstu, stride, dstu, stride);
-            ((int *)q)[0] = 0;
-        }
-
-        if (eobs[1] > 1)
-            vp8_dequant_idct_add_v6 (q+16, dq, dstu+4, stride);
-        else if (eobs[1] == 1)
-        {
-            vp8_dc_only_idct_add_v6 (q[16]*dq[0], dstu+4, stride,
-                                                  dstu+4, stride);
-            ((int *)(q+16))[0] = 0;
-        }
-
-        q    += 32;
-        dstu += 4*stride;
-        eobs += 2;
-    }
-
-    for (i = 0; i < 2; i++)
-    {
-        if (eobs[0] > 1)
-            vp8_dequant_idct_add_v6 (q, dq, dstv, stride);
-        else if (eobs[0] == 1)
-        {
-            vp8_dc_only_idct_add_v6 (q[0]*dq[0], dstv, stride, dstv, stride);
-            ((int *)q)[0] = 0;
-        }
-
-        if (eobs[1] > 1)
-            vp8_dequant_idct_add_v6 (q+16, dq, dstv+4, stride);
-        else if (eobs[1] == 1)
-        {
-            vp8_dc_only_idct_add_v6 (q[16]*dq[0], dstv+4, stride,
-                                                  dstv+4, stride);
-            ((int *)(q+16))[0] = 0;
-        }
-
-        q    += 32;
-        dstv += 4*stride;
-        eobs += 2;
-    }
-}
diff --git a/vp8/common/arm/armv6/idct_v6.asm b/vp8/common/arm/armv6/idct_v6.asm
deleted file mode 100644 (file)
index b4d44cb..0000000
+++ /dev/null
@@ -1,202 +0,0 @@
-;
-;  Copyright (c) 2010 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_short_idct4x4llm_v6_dual|
-
-    AREA    |.text|, CODE, READONLY
-
-
-; void vp8_short_idct4x4llm_c(short *input, unsigned char *pred, int pitch,
-;                             unsigned char *dst, int stride)
-; r0    short* input
-; r1    unsigned char* pred
-; r2    int pitch
-; r3    unsigned char* dst
-; sp    int stride
-
-|vp8_short_idct4x4llm_v6_dual| PROC
-    stmdb   sp!, {r4-r11, lr}
-
-    sub     sp, sp, #4
-
-    mov     r4, #0x00008A00         ; sin
-    orr     r4, r4, #0x0000008C     ; sinpi8sqrt2
-
-    mov     r5, #0x00004E00         ; cos
-    orr     r5, r5, #0x0000007B     ; cospi8sqrt2minus1
-    orr     r5, r5, #1<<31          ; loop counter on top bit
-
-loop1_dual
-    ldr     r6, [r0, #(4*2)]        ; i5 | i4
-    ldr     r12, [r0, #(12*2)]      ; i13|i12
-    ldr     r14, [r0, #(8*2)]       ; i9 | i8
-
-    smulbt  r9, r5, r6              ; (ip[5] * cospi8sqrt2minus1) >> 16
-    smulbb  r7, r5, r6              ; (ip[4] * cospi8sqrt2minus1) >> 16
-    smulwt  r10, r4, r6             ; (ip[5] * sinpi8sqrt2) >> 16
-    smulwb  r8, r4, r6              ; (ip[4] * sinpi8sqrt2) >> 16
-
-    smulbt  r11, r5, r12            ; (ip[13] * cospi8sqrt2minus1) >> 16
-    pkhtb   r7, r9, r7, asr #16     ; 5c | 4c
-    pkhbt   r8, r8, r10, lsl #16    ; 5s | 4s
-    uadd16  r6, r6, r7              ; 5c+5 | 4c+4
-
-    smulwt  r7, r4, r12             ; (ip[13] * sinpi8sqrt2) >> 16
-    smulbb  r9, r5, r12             ; (ip[12] * cospi8sqrt2minus1) >> 16
-    smulwb  r10, r4, r12            ; (ip[12] * sinpi8sqrt2) >> 16
-
-    subs    r5, r5, #1<<31          ; i--
-
-    pkhtb   r9, r11, r9, asr #16    ; 13c | 12c
-    ldr     r11, [r0]               ; i1 | i0
-    pkhbt   r10, r10, r7, lsl #16   ; 13s | 12s
-    uadd16  r7, r12, r9             ; 13c+13 | 12c+12
-
-    usub16  r7, r8, r7              ; c
-    uadd16  r6, r6, r10             ; d
-    uadd16  r10, r11, r14           ; a
-    usub16  r8, r11, r14            ; b
-
-    uadd16  r9, r10, r6             ; a+d
-    usub16  r10, r10, r6            ; a-d
-    uadd16  r6, r8, r7              ; b+c
-    usub16  r7, r8, r7              ; b-c
-
-    ; use input buffer to store intermediate results
-    str      r6, [r0, #(4*2)]       ; o5 | o4
-    str      r7, [r0, #(8*2)]       ; o9 | o8
-    str      r10,[r0, #(12*2)]      ; o13|o12
-    str      r9, [r0], #4           ; o1 | o0
-
-    bcs loop1_dual
-
-    sub     r0, r0, #8              ; reset input/output
-    str     r0, [sp]
-
-loop2_dual
-
-    ldr     r6, [r0, #(4*2)]        ; i5 | i4
-    ldr     r12,[r0, #(2*2)]        ; i3 | i2
-    ldr     r14,[r0, #(6*2)]        ; i7 | i6
-    ldr     r0, [r0, #(0*2)]        ; i1 | i0
-
-    smulbt  r9, r5, r6              ; (ip[5] * cospi8sqrt2minus1) >> 16
-    smulbt  r7, r5, r0              ; (ip[1] * cospi8sqrt2minus1) >> 16
-    smulwt  r10, r4, r6             ; (ip[5] * sinpi8sqrt2) >> 16
-    smulwt  r8, r4, r0              ; (ip[1] * sinpi8sqrt2) >> 16
-
-    pkhbt   r11, r6, r0, lsl #16    ; i0 | i4
-    pkhtb   r7, r7, r9, asr #16     ; 1c | 5c
-    pkhtb   r0, r0, r6, asr #16     ; i1 | i5
-    pkhbt   r8, r10, r8, lsl #16    ; 1s | 5s = temp1
-
-    uadd16  r0, r7, r0              ; 1c+1 | 5c+5 = temp2
-    pkhbt   r9, r14, r12, lsl #16   ; i2 | i6
-    uadd16  r10, r11, r9            ; a
-    usub16  r9, r11, r9             ; b
-    pkhtb   r6, r12, r14, asr #16   ; i3 | i7
-
-    subs    r5, r5, #1<<31          ; i--
-
-    smulbt  r7, r5, r6              ; (ip[3] * cospi8sqrt2minus1) >> 16
-    smulwt  r11, r4, r6             ; (ip[3] * sinpi8sqrt2) >> 16
-    smulbb  r12, r5, r6             ; (ip[7] * cospi8sqrt2minus1) >> 16
-    smulwb  r14, r4, r6             ; (ip[7] * sinpi8sqrt2) >> 16
-
-    pkhtb   r7, r7, r12, asr #16    ; 3c | 7c
-    pkhbt   r11, r14, r11, lsl #16  ; 3s | 7s = temp1
-
-    uadd16  r6, r7, r6              ; 3c+3 | 7c+7 = temp2
-    usub16  r12, r8, r6             ; c (o1 | o5)
-    uadd16  r6, r11, r0             ; d (o3 | o7)
-    uadd16  r7, r10, r6             ; a+d
-
-    mov     r8, #4                  ; set up 4's
-    orr     r8, r8, #0x40000        ; 4|4
-
-    usub16  r6, r10, r6             ; a-d
-    uadd16  r6, r6, r8              ; a-d+4, 3|7
-    uadd16  r7, r7, r8              ; a+d+4, 0|4
-    uadd16  r10, r9, r12            ; b+c
-    usub16  r0, r9, r12             ; b-c
-    uadd16  r10, r10, r8            ; b+c+4, 1|5
-    uadd16  r8, r0, r8              ; b-c+4, 2|6
-
-    ldr     lr, [sp, #40]           ; dst stride
-
-    ldrb    r0, [r1]                ; pred p0
-    ldrb    r11, [r1, #1]           ; pred p1
-    ldrb    r12, [r1, #2]           ; pred p2
-
-    add     r0, r0, r7, asr #19     ; p0 + o0
-    add     r11, r11, r10, asr #19  ; p1 + o1
-    add     r12, r12, r8, asr #19   ; p2 + o2
-
-    usat    r0, #8, r0              ; d0 = clip8(p0 + o0)
-    usat    r11, #8, r11            ; d1 = clip8(p1 + o1)
-    usat    r12, #8, r12            ; d2 = clip8(p2 + o2)
-
-    add     r0, r0, r11, lsl #8     ; |--|--|d1|d0|
-
-    ldrb    r11, [r1, #3]           ; pred p3
-
-    add     r0, r0, r12, lsl #16    ; |--|d2|d1|d0|
-
-    add     r11, r11, r6, asr #19   ; p3 + o3
-
-    sxth    r7, r7                  ;
-    sxth    r10, r10                ;
-
-    usat    r11, #8, r11            ; d3 = clip8(p3 + o3)
-
-    sxth    r8, r8                  ;
-    sxth    r6, r6                  ;
-
-    add     r0, r0, r11, lsl #24    ; |d3|d2|d1|d0|
-
-    ldrb    r12, [r1, r2]!          ; pred p4
-    str     r0, [r3], lr
-    ldrb    r11, [r1, #1]           ; pred p5
-
-    add     r12, r12, r7, asr #3    ; p4 + o4
-    add     r11, r11, r10, asr #3   ; p5 + o5
-
-    usat    r12, #8, r12            ; d4 = clip8(p4 + o4)
-    usat    r11, #8, r11            ; d5 = clip8(p5 + o5)
-
-    ldrb    r7, [r1, #2]            ; pred p6
-    ldrb    r10, [r1, #3]           ; pred p6
-
-    add     r12, r12, r11, lsl #8   ; |--|--|d5|d4|
-
-    add     r7, r7, r8, asr #3      ; p6 + o6
-    add     r10, r10, r6, asr #3    ; p7 + o7
-
-    ldr     r0, [sp]                ; load input pointer
-
-    usat    r7, #8, r7              ; d6 = clip8(p6 + o6)
-    usat    r10, #8, r10            ; d7 = clip8(p7 + o7)
-
-    add     r12, r12, r7, lsl #16   ; |--|d6|d5|d4|
-    add     r12, r12, r10, lsl #24  ; |d7|d6|d5|d4|
-
-    str     r12, [r3], lr
-    add     r0, r0, #16
-    add     r1, r1, r2              ; pred + pitch
-
-    bcs loop2_dual
-
-    add     sp, sp, #4              ; idct_output buffer
-    ldmia   sp!, {r4 - r11, pc}
-
-    ENDP
-
-    END
diff --git a/vp8/common/arm/armv6/iwalsh_v6.asm b/vp8/common/arm/armv6/iwalsh_v6.asm
deleted file mode 100644 (file)
index 31ef09c..0000000
+++ /dev/null
@@ -1,136 +0,0 @@
-;
-;  Copyright (c) 2010 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_short_inv_walsh4x4_v6|
-
-    ARM
-    REQUIRE8
-    PRESERVE8
-
-    AREA    |.text|, CODE, READONLY  ; name this block of code
-
-;short vp8_short_inv_walsh4x4_v6(short *input, short *mb_dqcoeff)
-|vp8_short_inv_walsh4x4_v6| PROC
-
-    stmdb       sp!, {r4 - r12, lr}
-
-    ldr         r2, [r0, #0]         ; [1  |  0]
-    ldr         r3, [r0, #4]         ; [3  |  2]
-    ldr         r4, [r0, #8]         ; [5  |  4]
-    ldr         r5, [r0, #12]        ; [7  |  6]
-    ldr         r6, [r0, #16]        ; [9  |  8]
-    ldr         r7, [r0, #20]        ; [11 | 10]
-    ldr         r8, [r0, #24]        ; [13 | 12]
-    ldr         r9, [r0, #28]        ; [15 | 14]
-
-    qadd16      r10, r2, r8          ; a1 [1+13  |  0+12]
-    qadd16      r11, r4, r6          ; b1 [5+9   |  4+8]
-    qsub16      r12, r4, r6          ; c1 [5-9   |  4-8]
-    qsub16      lr, r2, r8           ; d1 [1-13  |  0-12]
-
-    qadd16      r2, r10, r11         ; a1 + b1 [1  |  0]
-    qadd16      r4, r12, lr          ; c1 + d1 [5  |  4]
-    qsub16      r6, r10, r11         ; a1 - b1 [9  |  8]
-    qsub16      r8, lr, r12          ; d1 - c1 [13 | 12]
-
-    qadd16      r10, r3, r9          ; a1 [3+15  |  2+14]
-    qadd16      r11, r5, r7          ; b1 [7+11  |  6+10]
-    qsub16      r12, r5, r7          ; c1 [7-11  |  6-10]
-    qsub16      lr, r3, r9           ; d1 [3-15  |  2-14]
-
-    qadd16      r3, r10, r11         ; a1 + b1 [3  |  2]
-    qadd16      r5, r12, lr          ; c1 + d1 [7  |  6]
-    qsub16      r7, r10, r11         ; a1 - b1 [11 | 10]
-    qsub16      r9, lr, r12          ; d1 - c1 [15 | 14]
-
-    ; first transform complete
-
-    qsubaddx    r10, r2, r3          ; [c1|a1] [1-2   |   0+3]
-    qaddsubx    r11, r2, r3          ; [b1|d1] [1+2   |   0-3]
-    qsubaddx    r12, r4, r5          ; [c1|a1] [5-6   |   4+7]
-    qaddsubx    lr, r4, r5           ; [b1|d1] [5+6   |   4-7]
-
-    qaddsubx    r2, r10, r11         ; [b2|c2] [c1+d1 | a1-b1]
-    qaddsubx    r3, r11, r10         ; [a2|d2] [b1+a1 | d1-c1]
-    ldr         r10, c0x00030003
-    qaddsubx    r4, r12, lr          ; [b2|c2] [c1+d1 | a1-b1]
-    qaddsubx    r5, lr, r12          ; [a2|d2] [b1+a1 | d1-c1]
-
-    qadd16      r2, r2, r10          ; [b2+3|c2+3]
-    qadd16      r3, r3, r10          ; [a2+3|d2+3]
-    qadd16      r4, r4, r10          ; [b2+3|c2+3]
-    qadd16      r5, r5, r10          ; [a2+3|d2+3]
-
-    asr         r12, r3, #19         ; [0]
-    strh        r12, [r1], #32
-    asr         lr, r2, #19          ; [1]
-    strh        lr, [r1], #32
-    sxth        r2, r2
-    sxth        r3, r3
-    asr         r2, r2, #3           ; [2]
-    strh        r2, [r1], #32
-    asr         r3, r3, #3           ; [3]
-    strh        r3, [r1], #32
-
-    asr         r12, r5, #19         ; [4]
-    strh        r12, [r1], #32
-    asr         lr, r4, #19          ; [5]
-    strh        lr, [r1], #32
-    sxth        r4, r4
-    sxth        r5, r5
-    asr         r4, r4, #3           ; [6]
-    strh        r4, [r1], #32
-    asr         r5, r5, #3           ; [7]
-    strh        r5, [r1], #32
-
-    qsubaddx    r2, r6, r7           ; [c1|a1] [9-10  |  8+11]
-    qaddsubx    r3, r6, r7           ; [b1|d1] [9+10  |  8-11]
-    qsubaddx    r4, r8, r9           ; [c1|a1] [13-14 | 12+15]
-    qaddsubx    r5, r8, r9           ; [b1|d1] [13+14 | 12-15]
-
-    qaddsubx    r6, r2, r3           ; [b2|c2] [c1+d1 | a1-b1]
-    qaddsubx    r7, r3, r2           ; [a2|d2] [b1+a1 | d1-c1]
-    qaddsubx    r8, r4, r5           ; [b2|c2] [c1+d1 | a1-b1]
-    qaddsubx    r9, r5, r4           ; [a2|d2] [b1+a1 | d1-c1]
-
-    qadd16      r6, r6, r10          ; [b2+3|c2+3]
-    qadd16      r7, r7, r10          ; [a2+3|d2+3]
-    qadd16      r8, r8, r10          ; [b2+3|c2+3]
-    qadd16      r9, r9, r10          ; [a2+3|d2+3]
-
-    asr         r12, r7, #19         ; [8]
-    strh        r12, [r1], #32
-    asr         lr, r6, #19          ; [9]
-    strh        lr, [r1], #32
-    sxth        r6, r6
-    sxth        r7, r7
-    asr         r6, r6, #3           ; [10]
-    strh        r6, [r1], #32
-    asr         r7, r7, #3           ; [11]
-    strh        r7, [r1], #32
-
-    asr         r12, r9, #19         ; [12]
-    strh        r12, [r1], #32
-    asr         lr, r8, #19          ; [13]
-    strh        lr, [r1], #32
-    sxth        r8, r8
-    sxth        r9, r9
-    asr         r8, r8, #3           ; [14]
-    strh        r8, [r1], #32
-    asr         r9, r9, #3           ; [15]
-    strh        r9, [r1], #32
-
-    ldmia       sp!, {r4 - r12, pc}
-    ENDP        ; |vp8_short_inv_walsh4x4_v6|
-
-
-; Constant Pool
-c0x00030003 DCD 0x00030003
-    END
diff --git a/vp8/common/arm/armv6/loopfilter_v6.asm b/vp8/common/arm/armv6/loopfilter_v6.asm
deleted file mode 100644 (file)
index 1cbbbcd..0000000
+++ /dev/null
@@ -1,1282 +0,0 @@
-;
-;  Copyright (c) 2010 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_loop_filter_horizontal_edge_armv6|
-    EXPORT |vp8_mbloop_filter_horizontal_edge_armv6|
-    EXPORT |vp8_loop_filter_vertical_edge_armv6|
-    EXPORT |vp8_mbloop_filter_vertical_edge_armv6|
-
-    AREA    |.text|, CODE, READONLY  ; name this block of code
-
-    MACRO
-    TRANSPOSE_MATRIX $a0, $a1, $a2, $a3, $b0, $b1, $b2, $b3
-    ; input: $a0, $a1, $a2, $a3; output: $b0, $b1, $b2, $b3
-    ; a0: 03 02 01 00
-    ; a1: 13 12 11 10
-    ; a2: 23 22 21 20
-    ; a3: 33 32 31 30
-    ;     b3 b2 b1 b0
-
-    uxtb16      $b1, $a1                    ; xx 12 xx 10
-    uxtb16      $b0, $a0                    ; xx 02 xx 00
-    uxtb16      $b3, $a3                    ; xx 32 xx 30
-    uxtb16      $b2, $a2                    ; xx 22 xx 20
-    orr         $b1, $b0, $b1, lsl #8       ; 12 02 10 00
-    orr         $b3, $b2, $b3, lsl #8       ; 32 22 30 20
-
-    uxtb16      $a1, $a1, ror #8            ; xx 13 xx 11
-    uxtb16      $a3, $a3, ror #8            ; xx 33 xx 31
-    uxtb16      $a0, $a0, ror #8            ; xx 03 xx 01
-    uxtb16      $a2, $a2, ror #8            ; xx 23 xx 21
-    orr         $a0, $a0, $a1, lsl #8       ; 13 03 11 01
-    orr         $a2, $a2, $a3, lsl #8       ; 33 23 31 21
-
-    pkhtb       $b2, $b3, $b1, asr #16      ; 32 22 12 02   -- p1
-    pkhbt       $b0, $b1, $b3, lsl #16      ; 30 20 10 00   -- p3
-
-    pkhtb       $b3, $a2, $a0, asr #16      ; 33 23 13 03   -- p0
-    pkhbt       $b1, $a0, $a2, lsl #16      ; 31 21 11 01   -- p2
-    MEND
-
-
-src         RN  r0
-pstep       RN  r1
-count       RN  r5
-
-;r0     unsigned char *src_ptr,
-;r1     int src_pixel_step,
-;r2     const char *blimit,
-;r3     const char *limit,
-;stack  const char *thresh,
-;stack  int  count
-
-;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
-|vp8_loop_filter_horizontal_edge_armv6| PROC
-;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
-    stmdb       sp!, {r4 - r11, lr}
-
-    sub         src, src, pstep, lsl #2     ; move src pointer down by 4 lines
-    ldr         count, [sp, #40]            ; count for 8-in-parallel
-    ldr         r6, [sp, #36]               ; load thresh address
-    sub         sp, sp, #16                 ; create temp buffer
-
-    ldr         r9, [src], pstep            ; p3
-    ldrb        r4, [r2]                    ; blimit
-    ldr         r10, [src], pstep           ; p2
-    ldrb        r2, [r3]                    ; limit
-    ldr         r11, [src], pstep           ; p1
-    orr         r4, r4, r4, lsl #8
-    ldrb        r3, [r6]                    ; thresh
-    orr         r2, r2, r2, lsl #8
-    mov         count, count, lsl #1        ; 4-in-parallel
-    orr         r4, r4, r4, lsl #16
-    orr         r3, r3, r3, lsl #8
-    orr         r2, r2, r2, lsl #16
-    orr         r3, r3, r3, lsl #16
-
-|Hnext8|
-    ; vp8_filter_mask() function
-    ; calculate breakout conditions
-    ldr         r12, [src], pstep           ; p0
-
-    uqsub8      r6, r9, r10                 ; p3 - p2
-    uqsub8      r7, r10, r9                 ; p2 - p3
-    uqsub8      r8, r10, r11                ; p2 - p1
-    uqsub8      r10, r11, r10               ; p1 - p2
-
-    orr         r6, r6, r7                  ; abs (p3-p2)
-    orr         r8, r8, r10                 ; abs (p2-p1)
-    uqsub8      lr, r6, r2                  ; compare to limit. lr: vp8_filter_mask
-    uqsub8      r8, r8, r2                  ; compare to limit
-    uqsub8      r6, r11, r12                ; p1 - p0
-    orr         lr, lr, r8
-    uqsub8      r7, r12, r11                ; p0 - p1
-    ldr         r9, [src], pstep            ; q0
-    ldr         r10, [src], pstep           ; q1
-    orr         r6, r6, r7                  ; abs (p1-p0)
-    uqsub8      r7, r6, r2                  ; compare to limit
-    uqsub8      r8, r6, r3                  ; compare to thresh  -- save r8 for later
-    orr         lr, lr, r7
-
-    uqsub8      r6, r11, r10                ; p1 - q1
-    uqsub8      r7, r10, r11                ; q1 - p1
-    uqsub8      r11, r12, r9                ; p0 - q0
-    uqsub8      r12, r9, r12                ; q0 - p0
-    orr         r6, r6, r7                  ; abs (p1-q1)
-    ldr         r7, c0x7F7F7F7F
-    orr         r12, r11, r12               ; abs (p0-q0)
-    ldr         r11, [src], pstep           ; q2
-    uqadd8      r12, r12, r12               ; abs (p0-q0) * 2
-    and         r6, r7, r6, lsr #1          ; abs (p1-q1) / 2
-    uqsub8      r7, r9, r10                 ; q0 - q1
-    uqadd8      r12, r12, r6                ; abs (p0-q0)*2 + abs (p1-q1)/2
-    uqsub8      r6, r10, r9                 ; q1 - q0
-    uqsub8      r12, r12, r4                ; compare to flimit
-    uqsub8      r9, r11, r10                ; q2 - q1
-
-    orr         lr, lr, r12
-
-    ldr         r12, [src], pstep           ; q3
-    uqsub8      r10, r10, r11               ; q1 - q2
-    orr         r6, r7, r6                  ; abs (q1-q0)
-    orr         r10, r9, r10                ; abs (q2-q1)
-    uqsub8      r7, r6, r2                  ; compare to limit
-    uqsub8      r10, r10, r2                ; compare to limit
-    uqsub8      r6, r6, r3                  ; compare to thresh -- save r6 for later
-    orr         lr, lr, r7
-    orr         lr, lr, r10
-
-    uqsub8      r10, r12, r11               ; q3 - q2
-    uqsub8      r9, r11, r12                ; q2 - q3
-
-    mvn         r11, #0                     ; r11 == -1
-
-    orr         r10, r10, r9                ; abs (q3-q2)
-    uqsub8      r10, r10, r2                ; compare to limit
-
-    mov         r12, #0
-    orr         lr, lr, r10
-    sub         src, src, pstep, lsl #2
-
-    usub8       lr, r12, lr                 ; use usub8 instead of ssub8
-    sel         lr, r11, r12                ; filter mask: lr
-
-    cmp         lr, #0
-    beq         hskip_filter                 ; skip filtering
-
-    sub         src, src, pstep, lsl #1     ; move src pointer down by 6 lines
-
-    ;vp8_hevmask() function
-    ;calculate high edge variance
-    orr         r10, r6, r8                 ; calculate vp8_hevmask
-
-    ldr         r7, [src], pstep            ; p1
-
-    usub8       r10, r12, r10               ; use usub8 instead of ssub8
-    sel         r6, r12, r11                ; obtain vp8_hevmask: r6
-
-    ;vp8_filter() function
-    ldr         r8, [src], pstep            ; p0
-    ldr         r12, c0x80808080
-    ldr         r9, [src], pstep            ; q0
-    ldr         r10, [src], pstep           ; q1
-
-    eor         r7, r7, r12                 ; p1 offset to convert to a signed value
-    eor         r8, r8, r12                 ; p0 offset to convert to a signed value
-    eor         r9, r9, r12                 ; q0 offset to convert to a signed value
-    eor         r10, r10, r12               ; q1 offset to convert to a signed value
-
-    str         r9, [sp]                    ; store qs0 temporarily
-    str         r8, [sp, #4]                ; store ps0 temporarily
-    str         r10, [sp, #8]               ; store qs1 temporarily
-    str         r7, [sp, #12]               ; store ps1 temporarily
-
-    qsub8       r7, r7, r10                 ; vp8_signed_char_clamp(ps1-qs1)
-    qsub8       r8, r9, r8                  ; vp8_signed_char_clamp(vp8_filter + 3 * ( qs0 - ps0))
-
-    and         r7, r7, r6                  ; vp8_filter (r7) &= hev
-
-    qadd8       r7, r7, r8
-    ldr         r9, c0x03030303             ; r9 = 3 --modified for vp8
-
-    qadd8       r7, r7, r8
-    ldr         r10, c0x04040404
-
-    qadd8       r7, r7, r8
-    and         r7, r7, lr                  ; vp8_filter &= mask;
-
-    ;modify code for vp8 -- Filter1 = vp8_filter (r7)
-    qadd8       r8 , r7 , r9                ; Filter2 (r8) = vp8_signed_char_clamp(vp8_filter+3)
-    qadd8       r7 , r7 , r10               ; vp8_filter = vp8_signed_char_clamp(vp8_filter+4)
-
-    mov         r9, #0
-    shadd8      r8 , r8 , r9                ; Filter2 >>= 3
-    shadd8      r7 , r7 , r9                ; vp8_filter >>= 3
-    shadd8      r8 , r8 , r9
-    shadd8      r7 , r7 , r9
-    shadd8      lr , r8 , r9                ; lr: Filter2
-    shadd8      r7 , r7 , r9                ; r7: filter
-
-    ;usub8      lr, r8, r10                 ; s = (s==4)*-1
-    ;sel        lr, r11, r9
-    ;usub8      r8, r10, r8
-    ;sel        r8, r11, r9
-    ;and        r8, r8, lr                  ; -1 for each element that equals 4
-
-    ;calculate output
-    ;qadd8      lr, r8, r7                  ; u = vp8_signed_char_clamp(s + vp8_filter)
-
-    ldr         r8, [sp]                    ; load qs0
-    ldr         r9, [sp, #4]                ; load ps0
-
-    ldr         r10, c0x01010101
-
-    qsub8       r8 ,r8, r7                  ; u = vp8_signed_char_clamp(qs0 - vp8_filter)
-    qadd8       r9, r9, lr                  ; u = vp8_signed_char_clamp(ps0 + Filter2)
-
-    ;end of modification for vp8
-
-    mov         lr, #0
-    sadd8       r7, r7 , r10                ; vp8_filter += 1
-    shadd8      r7, r7, lr                  ; vp8_filter >>= 1
-
-    ldr         r11, [sp, #12]              ; load ps1
-    ldr         r10, [sp, #8]               ; load qs1
-
-    bic         r7, r7, r6                  ; vp8_filter &= ~hev
-    sub         src, src, pstep, lsl #2
-
-    qadd8       r11, r11, r7                ; u = vp8_signed_char_clamp(ps1 + vp8_filter)
-    qsub8       r10, r10,r7                 ; u = vp8_signed_char_clamp(qs1 - vp8_filter)
-
-    eor         r11, r11, r12               ; *op1 = u^0x80
-    str         r11, [src], pstep           ; store op1
-    eor         r9, r9, r12                 ; *op0 = u^0x80
-    str         r9, [src], pstep            ; store op0 result
-    eor         r8, r8, r12                 ; *oq0 = u^0x80
-    str         r8, [src], pstep            ; store oq0 result
-    eor         r10, r10, r12               ; *oq1 = u^0x80
-    str         r10, [src], pstep           ; store oq1
-
-    sub         src, src, pstep, lsl #1
-
-|hskip_filter|
-    add         src, src, #4
-    sub         src, src, pstep, lsl #2
-
-    subs        count, count, #1
-
-    ldrne       r9, [src], pstep            ; p3
-    ldrne       r10, [src], pstep           ; p2
-    ldrne       r11, [src], pstep           ; p1
-
-    bne         Hnext8
-
-    add         sp, sp, #16
-    ldmia       sp!, {r4 - r11, pc}
-    ENDP        ; |vp8_loop_filter_horizontal_edge_armv6|
-
-
-;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
-|vp8_mbloop_filter_horizontal_edge_armv6| PROC
-;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
-    stmdb       sp!, {r4 - r11, lr}
-
-    sub         src, src, pstep, lsl #2     ; move src pointer down by 4 lines
-    ldr         count, [sp, #40]            ; count for 8-in-parallel
-    ldr         r6, [sp, #36]               ; load thresh address
-    sub         sp, sp, #16                 ; create temp buffer
-
-    ldr         r9, [src], pstep            ; p3
-    ldrb        r4, [r2]                    ; blimit
-    ldr         r10, [src], pstep           ; p2
-    ldrb        r2, [r3]                    ; limit
-    ldr         r11, [src], pstep           ; p1
-    orr         r4, r4, r4, lsl #8
-    ldrb        r3, [r6]                    ; thresh
-    orr         r2, r2, r2, lsl #8
-    mov         count, count, lsl #1        ; 4-in-parallel
-    orr         r4, r4, r4, lsl #16
-    orr         r3, r3, r3, lsl #8
-    orr         r2, r2, r2, lsl #16
-    orr         r3, r3, r3, lsl #16
-
-|MBHnext8|
-
-    ; vp8_filter_mask() function
-    ; calculate breakout conditions
-    ldr         r12, [src], pstep           ; p0
-
-    uqsub8      r6, r9, r10                 ; p3 - p2
-    uqsub8      r7, r10, r9                 ; p2 - p3
-    uqsub8      r8, r10, r11                ; p2 - p1
-    uqsub8      r10, r11, r10               ; p1 - p2
-
-    orr         r6, r6, r7                  ; abs (p3-p2)
-    orr         r8, r8, r10                 ; abs (p2-p1)
-    uqsub8      lr, r6, r2                  ; compare to limit. lr: vp8_filter_mask
-    uqsub8      r8, r8, r2                  ; compare to limit
-
-    uqsub8      r6, r11, r12                ; p1 - p0
-    orr         lr, lr, r8
-    uqsub8      r7, r12, r11                ; p0 - p1
-    ldr         r9, [src], pstep            ; q0
-    ldr         r10, [src], pstep           ; q1
-    orr         r6, r6, r7                  ; abs (p1-p0)
-    uqsub8      r7, r6, r2                  ; compare to limit
-    uqsub8      r8, r6, r3                  ; compare to thresh  -- save r8 for later
-    orr         lr, lr, r7
-
-    uqsub8      r6, r11, r10                ; p1 - q1
-    uqsub8      r7, r10, r11                ; q1 - p1
-    uqsub8      r11, r12, r9                ; p0 - q0
-    uqsub8      r12, r9, r12                ; q0 - p0
-    orr         r6, r6, r7                  ; abs (p1-q1)
-    ldr         r7, c0x7F7F7F7F
-    orr         r12, r11, r12               ; abs (p0-q0)
-    ldr         r11, [src], pstep           ; q2
-    uqadd8      r12, r12, r12               ; abs (p0-q0) * 2
-    and         r6, r7, r6, lsr #1          ; abs (p1-q1) / 2
-    uqsub8      r7, r9, r10                 ; q0 - q1
-    uqadd8      r12, r12, r6                ; abs (p0-q0)*2 + abs (p1-q1)/2
-    uqsub8      r6, r10, r9                 ; q1 - q0
-    uqsub8      r12, r12, r4                ; compare to flimit
-    uqsub8      r9, r11, r10                ; q2 - q1
-
-    orr         lr, lr, r12
-
-    ldr         r12, [src], pstep           ; q3
-
-    uqsub8      r10, r10, r11               ; q1 - q2
-    orr         r6, r7, r6                  ; abs (q1-q0)
-    orr         r10, r9, r10                ; abs (q2-q1)
-    uqsub8      r7, r6, r2                  ; compare to limit
-    uqsub8      r10, r10, r2                ; compare to limit
-    uqsub8      r6, r6, r3                  ; compare to thresh -- save r6 for later
-    orr         lr, lr, r7
-    orr         lr, lr, r10
-
-    uqsub8      r10, r12, r11               ; q3 - q2
-    uqsub8      r9, r11, r12                ; q2 - q3
-
-    mvn         r11, #0                     ; r11 == -1
-
-    orr         r10, r10, r9                ; abs (q3-q2)
-    uqsub8      r10, r10, r2                ; compare to limit
-
-    mov         r12, #0
-
-    orr         lr, lr, r10
-
-    usub8       lr, r12, lr                 ; use usub8 instead of ssub8
-    sel         lr, r11, r12                ; filter mask: lr
-
-    cmp         lr, #0
-    beq         mbhskip_filter               ; skip filtering
-
-    ;vp8_hevmask() function
-    ;calculate high edge variance
-    sub         src, src, pstep, lsl #2     ; move src pointer down by 6 lines
-    sub         src, src, pstep, lsl #1
-
-    orr         r10, r6, r8
-    ldr         r7, [src], pstep            ; p1
-
-    usub8       r10, r12, r10
-    sel         r6, r12, r11                ; hev mask: r6
-
-    ;vp8_mbfilter() function
-    ;p2, q2 are only needed at the end. Don't need to load them in now.
-    ldr         r8, [src], pstep            ; p0
-    ldr         r12, c0x80808080
-    ldr         r9, [src], pstep            ; q0
-    ldr         r10, [src]                  ; q1
-
-    eor         r7, r7, r12                 ; ps1
-    eor         r8, r8, r12                 ; ps0
-    eor         r9, r9, r12                 ; qs0
-    eor         r10, r10, r12               ; qs1
-
-    qsub8       r12, r9, r8                 ; vp8_signed_char_clamp(vp8_filter + 3 * ( qs0 - ps0))
-    str         r7, [sp, #12]               ; store ps1 temporarily
-    qsub8       r7, r7, r10                 ; vp8_signed_char_clamp(ps1-qs1)
-    str         r10, [sp, #8]               ; store qs1 temporarily
-    qadd8       r7, r7, r12
-    str         r9, [sp]                    ; store qs0 temporarily
-    qadd8       r7, r7, r12
-    str         r8, [sp, #4]                ; store ps0 temporarily
-    qadd8       r7, r7, r12                 ; vp8_filter: r7
-
-    ldr         r10, c0x03030303            ; r10 = 3 --modified for vp8
-    ldr         r9, c0x04040404
-
-    and         r7, r7, lr                  ; vp8_filter &= mask (lr is free)
-
-    mov         r12, r7                     ; Filter2: r12
-    and         r12, r12, r6                ; Filter2 &= hev
-
-    ;modify code for vp8
-    ;save bottom 3 bits so that we round one side +4 and the other +3
-    qadd8       r8 , r12 , r9               ; Filter1 (r8) = vp8_signed_char_clamp(Filter2+4)
-    qadd8       r12 , r12 , r10             ; Filter2 (r12) = vp8_signed_char_clamp(Filter2+3)
-
-    mov         r10, #0
-    shadd8      r8 , r8 , r10               ; Filter1 >>= 3
-    shadd8      r12 , r12 , r10             ; Filter2 >>= 3
-    shadd8      r8 , r8 , r10
-    shadd8      r12 , r12 , r10
-    shadd8      r8 , r8 , r10               ; r8: Filter1
-    shadd8      r12 , r12 , r10             ; r12: Filter2
-
-    ldr         r9, [sp]                    ; load qs0
-    ldr         r11, [sp, #4]               ; load ps0
-
-    qsub8       r9 , r9, r8                 ; qs0 = vp8_signed_char_clamp(qs0 - Filter1)
-    qadd8       r11, r11, r12               ; ps0 = vp8_signed_char_clamp(ps0 + Filter2)
-
-    ;save bottom 3 bits so that we round one side +4 and the other +3
-    ;and            r8, r12, r10                ; s = Filter2 & 7 (s: r8)
-    ;qadd8      r12 , r12 , r9              ; Filter2 = vp8_signed_char_clamp(Filter2+4)
-    ;mov            r10, #0
-    ;shadd8     r12 , r12 , r10             ; Filter2 >>= 3
-    ;usub8      lr, r8, r9                  ; s = (s==4)*-1
-    ;sel            lr, r11, r10
-    ;shadd8     r12 , r12 , r10
-    ;usub8      r8, r9, r8
-    ;sel            r8, r11, r10
-    ;ldr            r9, [sp]                    ; load qs0
-    ;ldr            r11, [sp, #4]               ; load ps0
-    ;shadd8     r12 , r12 , r10
-    ;and            r8, r8, lr                  ; -1 for each element that equals 4
-    ;qadd8      r10, r8, r12                ; u = vp8_signed_char_clamp(s + Filter2)
-    ;qsub8      r9 , r9, r12                ; qs0 = vp8_signed_char_clamp(qs0 - Filter2)
-    ;qadd8      r11, r11, r10               ; ps0 = vp8_signed_char_clamp(ps0 + u)
-
-    ;end of modification for vp8
-
-    bic         r12, r7, r6                 ; vp8_filter &= ~hev    ( r6 is free)
-    ;mov        r12, r7
-
-    ;roughly 3/7th difference across boundary
-    mov         lr, #0x1b                   ; 27
-    mov         r7, #0x3f                   ; 63
-
-    sxtb16      r6, r12
-    sxtb16      r10, r12, ror #8
-    smlabb      r8, r6, lr, r7
-    smlatb      r6, r6, lr, r7
-    smlabb      r7, r10, lr, r7
-    smultb      r10, r10, lr
-    ssat        r8, #8, r8, asr #7
-    ssat        r6, #8, r6, asr #7
-    add         r10, r10, #63
-    ssat        r7, #8, r7, asr #7
-    ssat        r10, #8, r10, asr #7
-
-    ldr         lr, c0x80808080
-
-    pkhbt       r6, r8, r6, lsl #16
-    pkhbt       r10, r7, r10, lsl #16
-    uxtb16      r6, r6
-    uxtb16      r10, r10
-
-    sub         src, src, pstep
-
-    orr         r10, r6, r10, lsl #8        ; u = vp8_signed_char_clamp((63 + Filter2 * 27)>>7)
-
-    qsub8       r8, r9, r10                 ; s = vp8_signed_char_clamp(qs0 - u)
-    qadd8       r10, r11, r10               ; s = vp8_signed_char_clamp(ps0 + u)
-    eor         r8, r8, lr                  ; *oq0 = s^0x80
-    str         r8, [src]                   ; store *oq0
-    sub         src, src, pstep
-    eor         r10, r10, lr                ; *op0 = s^0x80
-    str         r10, [src]                  ; store *op0
-
-    ;roughly 2/7th difference across boundary
-    mov         lr, #0x12                   ; 18
-    mov         r7, #0x3f                   ; 63
-
-    sxtb16      r6, r12
-    sxtb16      r10, r12, ror #8
-    smlabb      r8, r6, lr, r7
-    smlatb      r6, r6, lr, r7
-    smlabb      r9, r10, lr, r7
-    smlatb      r10, r10, lr, r7
-    ssat        r8, #8, r8, asr #7
-    ssat        r6, #8, r6, asr #7
-    ssat        r9, #8, r9, asr #7
-    ssat        r10, #8, r10, asr #7
-
-    ldr         lr, c0x80808080
-
-    pkhbt       r6, r8, r6, lsl #16
-    pkhbt       r10, r9, r10, lsl #16
-
-    ldr         r9, [sp, #8]                ; load qs1
-    ldr         r11, [sp, #12]              ; load ps1
-
-    uxtb16      r6, r6
-    uxtb16      r10, r10
-
-    sub         src, src, pstep
-
-    orr         r10, r6, r10, lsl #8        ; u = vp8_signed_char_clamp((63 + Filter2 * 18)>>7)
-
-    qadd8       r11, r11, r10               ; s = vp8_signed_char_clamp(ps1 + u)
-    qsub8       r8, r9, r10                 ; s = vp8_signed_char_clamp(qs1 - u)
-    eor         r11, r11, lr                ; *op1 = s^0x80
-    str         r11, [src], pstep           ; store *op1
-    eor         r8, r8, lr                  ; *oq1 = s^0x80
-    add         src, src, pstep, lsl #1
-
-    mov         r7, #0x3f                   ; 63
-
-    str         r8, [src], pstep            ; store *oq1
-
-    ;roughly 1/7th difference across boundary
-    mov         lr, #0x9                    ; 9
-    ldr         r9, [src]                   ; load q2
-
-    sxtb16      r6, r12
-    sxtb16      r10, r12, ror #8
-    smlabb      r8, r6, lr, r7
-    smlatb      r6, r6, lr, r7
-    smlabb      r12, r10, lr, r7
-    smlatb      r10, r10, lr, r7
-    ssat        r8, #8, r8, asr #7
-    ssat        r6, #8, r6, asr #7
-    ssat        r12, #8, r12, asr #7
-    ssat        r10, #8, r10, asr #7
-
-    sub         src, src, pstep, lsl #2
-
-    pkhbt       r6, r8, r6, lsl #16
-    pkhbt       r10, r12, r10, lsl #16
-
-    sub         src, src, pstep
-    ldr         lr, c0x80808080
-
-    ldr         r11, [src]                  ; load p2
-
-    uxtb16      r6, r6
-    uxtb16      r10, r10
-
-    eor         r9, r9, lr
-    eor         r11, r11, lr
-
-    orr         r10, r6, r10, lsl #8        ; u = vp8_signed_char_clamp((63 + Filter2 * 9)>>7)
-
-    qadd8       r8, r11, r10                ; s = vp8_signed_char_clamp(ps2 + u)
-    qsub8       r10, r9, r10                ; s = vp8_signed_char_clamp(qs2 - u)
-    eor         r8, r8, lr                  ; *op2 = s^0x80
-    str         r8, [src], pstep, lsl #2    ; store *op2
-    add         src, src, pstep
-    eor         r10, r10, lr                ; *oq2 = s^0x80
-    str         r10, [src], pstep, lsl #1   ; store *oq2
-
-|mbhskip_filter|
-    add         src, src, #4
-    sub         src, src, pstep, lsl #3
-    subs        count, count, #1
-
-    ldrne       r9, [src], pstep            ; p3
-    ldrne       r10, [src], pstep           ; p2
-    ldrne       r11, [src], pstep           ; p1
-
-    bne         MBHnext8
-
-    add         sp, sp, #16
-    ldmia       sp!, {r4 - r11, pc}
-    ENDP        ; |vp8_mbloop_filter_horizontal_edge_armv6|
-
-
-;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
-|vp8_loop_filter_vertical_edge_armv6| PROC
-;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
-    stmdb       sp!, {r4 - r11, lr}
-
-    sub         src, src, #4                ; move src pointer down by 4
-    ldr         count, [sp, #40]            ; count for 8-in-parallel
-    ldr         r12, [sp, #36]              ; load thresh address
-    sub         sp, sp, #16                 ; create temp buffer
-
-    ldr         r6, [src], pstep            ; load source data
-    ldrb        r4, [r2]                    ; blimit
-    ldr         r7, [src], pstep
-    ldrb        r2, [r3]                    ; limit
-    ldr         r8, [src], pstep
-    orr         r4, r4, r4, lsl #8
-    ldrb        r3, [r12]                   ; thresh
-    orr         r2, r2, r2, lsl #8
-    ldr         lr, [src], pstep
-    mov         count, count, lsl #1        ; 4-in-parallel
-    orr         r4, r4, r4, lsl #16
-    orr         r3, r3, r3, lsl #8
-    orr         r2, r2, r2, lsl #16
-    orr         r3, r3, r3, lsl #16
-
-|Vnext8|
-
-    ; vp8_filter_mask() function
-    ; calculate breakout conditions
-    ; transpose the source data for 4-in-parallel operation
-    TRANSPOSE_MATRIX r6, r7, r8, lr, r9, r10, r11, r12
-
-    uqsub8      r7, r9, r10                 ; p3 - p2
-    uqsub8      r8, r10, r9                 ; p2 - p3
-    uqsub8      r9, r10, r11                ; p2 - p1
-    uqsub8      r10, r11, r10               ; p1 - p2
-    orr         r7, r7, r8                  ; abs (p3-p2)
-    orr         r10, r9, r10                ; abs (p2-p1)
-    uqsub8      lr, r7, r2                  ; compare to limit. lr: vp8_filter_mask
-    uqsub8      r10, r10, r2                ; compare to limit
-
-    sub         src, src, pstep, lsl #2     ; move src pointer down by 4 lines
-
-    orr         lr, lr, r10
-
-    uqsub8      r6, r11, r12                ; p1 - p0
-    uqsub8      r7, r12, r11                ; p0 - p1
-    add         src, src, #4                ; move src pointer up by 4
-    orr         r6, r6, r7                  ; abs (p1-p0)
-    str         r11, [sp, #12]              ; save p1
-    uqsub8      r10, r6, r2                 ; compare to limit
-    uqsub8      r11, r6, r3                 ; compare to thresh
-    orr         lr, lr, r10
-
-    ; transpose uses 8 regs(r6 - r12 and lr). Need to save reg value now
-    ; transpose the source data for 4-in-parallel operation
-    ldr         r6, [src], pstep            ; load source data
-    str         r11, [sp]                   ; push r11 to stack
-    ldr         r7, [src], pstep
-    str         r12, [sp, #4]               ; save current reg before load q0 - q3 data
-    ldr         r8, [src], pstep
-    str         lr, [sp, #8]
-    ldr         lr, [src], pstep
-
-    TRANSPOSE_MATRIX r6, r7, r8, lr, r9, r10, r11, r12
-
-    ldr         lr, [sp, #8]                ; load back (f)limit accumulator
-
-    uqsub8      r6, r12, r11                ; q3 - q2
-    uqsub8      r7, r11, r12                ; q2 - q3
-    uqsub8      r12, r11, r10               ; q2 - q1
-    uqsub8      r11, r10, r11               ; q1 - q2
-    orr         r6, r6, r7                  ; abs (q3-q2)
-    orr         r7, r12, r11                ; abs (q2-q1)
-    uqsub8      r6, r6, r2                  ; compare to limit
-    uqsub8      r7, r7, r2                  ; compare to limit
-    ldr         r11, [sp, #4]               ; load back p0
-    ldr         r12, [sp, #12]              ; load back p1
-    orr         lr, lr, r6
-    orr         lr, lr, r7
-
-    uqsub8      r6, r11, r9                 ; p0 - q0
-    uqsub8      r7, r9, r11                 ; q0 - p0
-    uqsub8      r8, r12, r10                ; p1 - q1
-    uqsub8      r11, r10, r12               ; q1 - p1
-    orr         r6, r6, r7                  ; abs (p0-q0)
-    ldr         r7, c0x7F7F7F7F
-    orr         r8, r8, r11                 ; abs (p1-q1)
-    uqadd8      r6, r6, r6                  ; abs (p0-q0) * 2
-    and         r8, r7, r8, lsr #1          ; abs (p1-q1) / 2
-    uqsub8      r11, r10, r9                ; q1 - q0
-    uqadd8      r6, r8, r6                  ; abs (p0-q0)*2 + abs (p1-q1)/2
-    uqsub8      r12, r9, r10                ; q0 - q1
-    uqsub8      r6, r6, r4                  ; compare to flimit
-
-    orr         r9, r11, r12                ; abs (q1-q0)
-    uqsub8      r8, r9, r2                  ; compare to limit
-    uqsub8      r10, r9, r3                 ; compare to thresh
-    orr         lr, lr, r6
-    orr         lr, lr, r8
-
-    mvn         r11, #0                     ; r11 == -1
-    mov         r12, #0
-
-    usub8       lr, r12, lr
-    ldr         r9, [sp]                    ; load the compared result
-    sel         lr, r11, r12                ; filter mask: lr
-
-    cmp         lr, #0
-    beq         vskip_filter                 ; skip filtering
-
-    ;vp8_hevmask() function
-    ;calculate high edge variance
-
-    sub         src, src, pstep, lsl #2     ; move src pointer down by 4 lines
-
-    orr         r9, r9, r10
-
-    ldrh        r7, [src, #-2]
-    ldrh        r8, [src], pstep
-
-    usub8       r9, r12, r9
-    sel         r6, r12, r11                ; hev mask: r6
-
-    ;vp8_filter() function
-    ; load soure data to r6, r11, r12, lr
-    ldrh        r9, [src, #-2]
-    ldrh        r10, [src], pstep
-
-    pkhbt       r12, r7, r8, lsl #16
-
-    ldrh        r7, [src, #-2]
-    ldrh        r8, [src], pstep
-
-    pkhbt       r11, r9, r10, lsl #16
-
-    ldrh        r9, [src, #-2]
-    ldrh        r10, [src], pstep
-
-    ; Transpose needs 8 regs(r6 - r12, and lr). Save r6 and lr first
-    str         r6, [sp]
-    str         lr, [sp, #4]
-
-    pkhbt       r6, r7, r8, lsl #16
-    pkhbt       lr, r9, r10, lsl #16
-
-    ;transpose r12, r11, r6, lr to r7, r8, r9, r10
-    TRANSPOSE_MATRIX r12, r11, r6, lr, r7, r8, r9, r10
-
-    ;load back hev_mask r6 and filter_mask lr
-    ldr         r12, c0x80808080
-    ldr         r6, [sp]
-    ldr         lr, [sp, #4]
-
-    eor         r7, r7, r12                 ; p1 offset to convert to a signed value
-    eor         r8, r8, r12                 ; p0 offset to convert to a signed value
-    eor         r9, r9, r12                 ; q0 offset to convert to a signed value
-    eor         r10, r10, r12               ; q1 offset to convert to a signed value
-
-    str         r9, [sp]                    ; store qs0 temporarily
-    str         r8, [sp, #4]                ; store ps0 temporarily
-    str         r10, [sp, #8]               ; store qs1 temporarily
-    str         r7, [sp, #12]               ; store ps1 temporarily
-
-    qsub8       r7, r7, r10                 ; vp8_signed_char_clamp(ps1-qs1)
-    qsub8       r8, r9, r8                  ; vp8_signed_char_clamp(vp8_filter + 3 * ( qs0 - ps0))
-
-    and         r7, r7, r6                  ;  vp8_filter (r7) &= hev (r7 : filter)
-
-    qadd8       r7, r7, r8
-    ldr         r9, c0x03030303             ; r9 = 3 --modified for vp8
-
-    qadd8       r7, r7, r8
-    ldr         r10, c0x04040404
-
-    qadd8       r7, r7, r8
-    ;mvn         r11, #0                     ; r11 == -1
-
-    and         r7, r7, lr                  ; vp8_filter &= mask
-
-    ;modify code for vp8 -- Filter1 = vp8_filter (r7)
-    qadd8       r8 , r7 , r9                ; Filter2 (r8) = vp8_signed_char_clamp(vp8_filter+3)
-    qadd8       r7 , r7 , r10               ; vp8_filter = vp8_signed_char_clamp(vp8_filter+4)
-
-    mov         r9, #0
-    shadd8      r8 , r8 , r9                ; Filter2 >>= 3
-    shadd8      r7 , r7 , r9                ; vp8_filter >>= 3
-    shadd8      r8 , r8 , r9
-    shadd8      r7 , r7 , r9
-    shadd8      lr , r8 , r9                ; lr: filter2
-    shadd8      r7 , r7 , r9                ; r7: filter
-
-    ;usub8      lr, r8, r10                 ; s = (s==4)*-1
-    ;sel            lr, r11, r9
-    ;usub8      r8, r10, r8
-    ;sel            r8, r11, r9
-    ;and            r8, r8, lr                  ; -1 for each element that equals 4 -- r8: s
-
-    ;calculate output
-    ;qadd8      lr, r8, r7                  ; u = vp8_signed_char_clamp(s + vp8_filter)
-
-    ldr         r8, [sp]                    ; load qs0
-    ldr         r9, [sp, #4]                ; load ps0
-
-    ldr         r10, c0x01010101
-
-    qsub8       r8, r8, r7                  ; u = vp8_signed_char_clamp(qs0 - vp8_filter)
-    qadd8       r9, r9, lr                  ; u = vp8_signed_char_clamp(ps0 + Filter2)
-    ;end of modification for vp8
-
-    eor         r8, r8, r12
-    eor         r9, r9, r12
-
-    mov         lr, #0
-
-    sadd8       r7, r7, r10
-    shadd8      r7, r7, lr
-
-    ldr         r10, [sp, #8]               ; load qs1
-    ldr         r11, [sp, #12]              ; load ps1
-
-    bic         r7, r7, r6                  ; r7: vp8_filter
-
-    qsub8       r10 , r10, r7               ; u = vp8_signed_char_clamp(qs1 - vp8_filter)
-    qadd8       r11, r11, r7                ; u = vp8_signed_char_clamp(ps1 + vp8_filter)
-    eor         r10, r10, r12
-    eor         r11, r11, r12
-
-    sub         src, src, pstep, lsl #2
-
-    ;we can use TRANSPOSE_MATRIX macro to transpose output - input: q1, q0, p0, p1
-    ;output is b0, b1, b2, b3
-    ;b0: 03 02 01 00
-    ;b1: 13 12 11 10
-    ;b2: 23 22 21 20
-    ;b3: 33 32 31 30
-    ;    p1 p0 q0 q1
-    ;   (a3 a2 a1 a0)
-    TRANSPOSE_MATRIX r11, r9, r8, r10, r6, r7, r12, lr
-
-    strh        r6, [src, #-2]              ; store the result
-    mov         r6, r6, lsr #16
-    strh        r6, [src], pstep
-
-    strh        r7, [src, #-2]
-    mov         r7, r7, lsr #16
-    strh        r7, [src], pstep
-
-    strh        r12, [src, #-2]
-    mov         r12, r12, lsr #16
-    strh        r12, [src], pstep
-
-    strh        lr, [src, #-2]
-    mov         lr, lr, lsr #16
-    strh        lr, [src], pstep
-
-|vskip_filter|
-    sub         src, src, #4
-    subs        count, count, #1
-
-    ldrne       r6, [src], pstep            ; load source data
-    ldrne       r7, [src], pstep
-    ldrne       r8, [src], pstep
-    ldrne       lr, [src], pstep
-
-    bne         Vnext8
-
-    add         sp, sp, #16
-
-    ldmia       sp!, {r4 - r11, pc}
-    ENDP        ; |vp8_loop_filter_vertical_edge_armv6|
-
-
-
-;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
-|vp8_mbloop_filter_vertical_edge_armv6| PROC
-;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
-    stmdb       sp!, {r4 - r11, lr}
-
-    sub         src, src, #4                ; move src pointer down by 4
-    ldr         count, [sp, #40]            ; count for 8-in-parallel
-    ldr         r12, [sp, #36]              ; load thresh address
-    pld         [src, #23]                  ; preload for next block
-    sub         sp, sp, #16                 ; create temp buffer
-
-    ldr         r6, [src], pstep            ; load source data
-    ldrb        r4, [r2]                    ; blimit
-    pld         [src, #23]
-    ldr         r7, [src], pstep
-    ldrb        r2, [r3]                    ; limit
-    pld         [src, #23]
-    ldr         r8, [src], pstep
-    orr         r4, r4, r4, lsl #8
-    ldrb        r3, [r12]                   ; thresh
-    orr         r2, r2, r2, lsl #8
-    pld         [src, #23]
-    ldr         lr, [src], pstep
-    mov         count, count, lsl #1        ; 4-in-parallel
-    orr         r4, r4, r4, lsl #16
-    orr         r3, r3, r3, lsl #8
-    orr         r2, r2, r2, lsl #16
-    orr         r3, r3, r3, lsl #16
-
-|MBVnext8|
-    ; vp8_filter_mask() function
-    ; calculate breakout conditions
-    ; transpose the source data for 4-in-parallel operation
-    TRANSPOSE_MATRIX r6, r7, r8, lr, r9, r10, r11, r12
-
-    uqsub8      r7, r9, r10                 ; p3 - p2
-    uqsub8      r8, r10, r9                 ; p2 - p3
-    uqsub8      r9, r10, r11                ; p2 - p1
-    uqsub8      r10, r11, r10               ; p1 - p2
-    orr         r7, r7, r8                  ; abs (p3-p2)
-    orr         r10, r9, r10                ; abs (p2-p1)
-    uqsub8      lr, r7, r2                  ; compare to limit. lr: vp8_filter_mask
-    uqsub8      r10, r10, r2                ; compare to limit
-
-    sub         src, src, pstep, lsl #2     ; move src pointer down by 4 lines
-
-    orr         lr, lr, r10
-
-    uqsub8      r6, r11, r12                ; p1 - p0
-    uqsub8      r7, r12, r11                ; p0 - p1
-    add         src, src, #4                ; move src pointer up by 4
-    orr         r6, r6, r7                  ; abs (p1-p0)
-    str         r11, [sp, #12]              ; save p1
-    uqsub8      r10, r6, r2                 ; compare to limit
-    uqsub8      r11, r6, r3                 ; compare to thresh
-    orr         lr, lr, r10
-
-    ; transpose uses 8 regs(r6 - r12 and lr). Need to save reg value now
-    ; transpose the source data for 4-in-parallel operation
-    ldr         r6, [src], pstep            ; load source data
-    str         r11, [sp]                   ; push r11 to stack
-    ldr         r7, [src], pstep
-    str         r12, [sp, #4]               ; save current reg before load q0 - q3 data
-    ldr         r8, [src], pstep
-    str         lr, [sp, #8]
-    ldr         lr, [src], pstep
-
-
-    TRANSPOSE_MATRIX r6, r7, r8, lr, r9, r10, r11, r12
-
-    ldr         lr, [sp, #8]                ; load back (f)limit accumulator
-
-    uqsub8      r6, r12, r11                ; q3 - q2
-    uqsub8      r7, r11, r12                ; q2 - q3
-    uqsub8      r12, r11, r10               ; q2 - q1
-    uqsub8      r11, r10, r11               ; q1 - q2
-    orr         r6, r6, r7                  ; abs (q3-q2)
-    orr         r7, r12, r11                ; abs (q2-q1)
-    uqsub8      r6, r6, r2                  ; compare to limit
-    uqsub8      r7, r7, r2                  ; compare to limit
-    ldr         r11, [sp, #4]               ; load back p0
-    ldr         r12, [sp, #12]              ; load back p1
-    orr         lr, lr, r6
-    orr         lr, lr, r7
-
-    uqsub8      r6, r11, r9                 ; p0 - q0
-    uqsub8      r7, r9, r11                 ; q0 - p0
-    uqsub8      r8, r12, r10                ; p1 - q1
-    uqsub8      r11, r10, r12               ; q1 - p1
-    orr         r6, r6, r7                  ; abs (p0-q0)
-    ldr         r7, c0x7F7F7F7F
-    orr         r8, r8, r11                 ; abs (p1-q1)
-    uqadd8      r6, r6, r6                  ; abs (p0-q0) * 2
-    and         r8, r7, r8, lsr #1          ; abs (p1-q1) / 2
-    uqsub8      r11, r10, r9                ; q1 - q0
-    uqadd8      r6, r8, r6                  ; abs (p0-q0)*2 + abs (p1-q1)/2
-    uqsub8      r12, r9, r10                ; q0 - q1
-    uqsub8      r6, r6, r4                  ; compare to flimit
-
-    orr         r9, r11, r12                ; abs (q1-q0)
-    uqsub8      r8, r9, r2                  ; compare to limit
-    uqsub8      r10, r9, r3                 ; compare to thresh
-    orr         lr, lr, r6
-    orr         lr, lr, r8
-
-    mvn         r11, #0                     ; r11 == -1
-    mov         r12, #0
-
-    usub8       lr, r12, lr
-    ldr         r9, [sp]                    ; load the compared result
-    sel         lr, r11, r12                ; filter mask: lr
-
-    cmp         lr, #0
-    beq         mbvskip_filter               ; skip filtering
-
-
-
-    ;vp8_hevmask() function
-    ;calculate high edge variance
-
-    sub         src, src, pstep, lsl #2     ; move src pointer down by 4 lines
-
-    orr         r9, r9, r10
-
-    ldrh        r7, [src, #-2]
-    ldrh        r8, [src], pstep
-
-    usub8       r9, r12, r9
-    sel         r6, r12, r11                ; hev mask: r6
-
-
-    ; vp8_mbfilter() function
-    ; p2, q2 are only needed at the end. Don't need to load them in now.
-    ; Transpose needs 8 regs(r6 - r12, and lr). Save r6 and lr first
-    ; load soure data to r6, r11, r12, lr
-    ldrh        r9, [src, #-2]
-    ldrh        r10, [src], pstep
-
-    pkhbt       r12, r7, r8, lsl #16
-
-    ldrh        r7, [src, #-2]
-    ldrh        r8, [src], pstep
-
-    pkhbt       r11, r9, r10, lsl #16
-
-    ldrh        r9, [src, #-2]
-    ldrh        r10, [src], pstep
-
-    str         r6, [sp]                    ; save r6
-    str         lr, [sp, #4]                ; save lr
-
-    pkhbt       r6, r7, r8, lsl #16
-    pkhbt       lr, r9, r10, lsl #16
-
-    ;transpose r12, r11, r6, lr to p1, p0, q0, q1
-    TRANSPOSE_MATRIX r12, r11, r6, lr, r7, r8, r9, r10
-
-    ;load back hev_mask r6 and filter_mask lr
-    ldr         r12, c0x80808080
-    ldr         r6, [sp]
-    ldr         lr, [sp, #4]
-
-    eor         r7, r7, r12                 ; ps1
-    eor         r8, r8, r12                 ; ps0
-    eor         r9, r9, r12                 ; qs0
-    eor         r10, r10, r12               ; qs1
-
-    qsub8       r12, r9, r8                 ; vp8_signed_char_clamp(vp8_filter + 3 * ( qs0 - ps0))
-    str         r7, [sp, #12]               ; store ps1 temporarily
-    qsub8       r7, r7, r10                 ; vp8_signed_char_clamp(ps1-qs1)
-    str         r10, [sp, #8]               ; store qs1 temporarily
-    qadd8       r7, r7, r12
-    str         r9, [sp]                    ; store qs0 temporarily
-    qadd8       r7, r7, r12
-    str         r8, [sp, #4]                ; store ps0 temporarily
-    qadd8       r7, r7, r12                 ; vp8_filter: r7
-
-    ldr         r10, c0x03030303            ; r10 = 3 --modified for vp8
-    ldr         r9, c0x04040404
-    ;mvn         r11, #0                     ; r11 == -1
-
-    and         r7, r7, lr                  ; vp8_filter &= mask (lr is free)
-
-    mov         r12, r7                     ; Filter2: r12
-    and         r12, r12, r6                ; Filter2 &= hev
-
-    ;modify code for vp8
-    ;save bottom 3 bits so that we round one side +4 and the other +3
-    qadd8       r8 , r12 , r9               ; Filter1 (r8) = vp8_signed_char_clamp(Filter2+4)
-    qadd8       r12 , r12 , r10             ; Filter2 (r12) = vp8_signed_char_clamp(Filter2+3)
-
-    mov         r10, #0
-    shadd8      r8 , r8 , r10               ; Filter1 >>= 3
-    shadd8      r12 , r12 , r10             ; Filter2 >>= 3
-    shadd8      r8 , r8 , r10
-    shadd8      r12 , r12 , r10
-    shadd8      r8 , r8 , r10               ; r8: Filter1
-    shadd8      r12 , r12 , r10             ; r12: Filter2
-
-    ldr         r9, [sp]                    ; load qs0
-    ldr         r11, [sp, #4]               ; load ps0
-
-    qsub8       r9 , r9, r8                 ; qs0 = vp8_signed_char_clamp(qs0 - Filter1)
-    qadd8       r11, r11, r12               ; ps0 = vp8_signed_char_clamp(ps0 + Filter2)
-
-    ;save bottom 3 bits so that we round one side +4 and the other +3
-    ;and            r8, r12, r10                ; s = Filter2 & 7 (s: r8)
-    ;qadd8      r12 , r12 , r9              ; Filter2 = vp8_signed_char_clamp(Filter2+4)
-    ;mov            r10, #0
-    ;shadd8     r12 , r12 , r10             ; Filter2 >>= 3
-    ;usub8      lr, r8, r9                  ; s = (s==4)*-1
-    ;sel            lr, r11, r10
-    ;shadd8     r12 , r12 , r10
-    ;usub8      r8, r9, r8
-    ;sel            r8, r11, r10
-    ;ldr            r9, [sp]                    ; load qs0
-    ;ldr            r11, [sp, #4]               ; load ps0
-    ;shadd8     r12 , r12 , r10
-    ;and            r8, r8, lr                  ; -1 for each element that equals 4
-    ;qadd8      r10, r8, r12                ; u = vp8_signed_char_clamp(s + Filter2)
-    ;qsub8      r9 , r9, r12                ; qs0 = vp8_signed_char_clamp(qs0 - Filter2)
-    ;qadd8      r11, r11, r10               ; ps0 = vp8_signed_char_clamp(ps0 + u)
-
-    ;end of modification for vp8
-
-    bic         r12, r7, r6                 ;vp8_filter &= ~hev    ( r6 is free)
-    ;mov            r12, r7
-
-    ;roughly 3/7th difference across boundary
-    mov         lr, #0x1b                   ; 27
-    mov         r7, #0x3f                   ; 63
-
-    sxtb16      r6, r12
-    sxtb16      r10, r12, ror #8
-    smlabb      r8, r6, lr, r7
-    smlatb      r6, r6, lr, r7
-    smlabb      r7, r10, lr, r7
-    smultb      r10, r10, lr
-    ssat        r8, #8, r8, asr #7
-    ssat        r6, #8, r6, asr #7
-    add         r10, r10, #63
-    ssat        r7, #8, r7, asr #7
-    ssat        r10, #8, r10, asr #7
-
-    ldr         lr, c0x80808080
-
-    pkhbt       r6, r8, r6, lsl #16
-    pkhbt       r10, r7, r10, lsl #16
-    uxtb16      r6, r6
-    uxtb16      r10, r10
-
-    sub         src, src, pstep, lsl #2     ; move src pointer down by 4 lines
-
-    orr         r10, r6, r10, lsl #8        ; u = vp8_signed_char_clamp((63 + Filter2 * 27)>>7)
-
-    qsub8       r8, r9, r10                 ; s = vp8_signed_char_clamp(qs0 - u)
-    qadd8       r10, r11, r10               ; s = vp8_signed_char_clamp(ps0 + u)
-    eor         r8, r8, lr                  ; *oq0 = s^0x80
-    eor         r10, r10, lr                ; *op0 = s^0x80
-
-    strb        r10, [src, #-1]             ; store op0 result
-    strb        r8, [src], pstep            ; store oq0 result
-    mov         r10, r10, lsr #8
-    mov         r8, r8, lsr #8
-    strb        r10, [src, #-1]
-    strb        r8, [src], pstep
-    mov         r10, r10, lsr #8
-    mov         r8, r8, lsr #8
-    strb        r10, [src, #-1]
-    strb        r8, [src], pstep
-    mov         r10, r10, lsr #8
-    mov         r8, r8, lsr #8
-    strb        r10, [src, #-1]
-    strb        r8, [src], pstep
-
-    ;roughly 2/7th difference across boundary
-    mov         lr, #0x12                   ; 18
-    mov         r7, #0x3f                   ; 63
-
-    sxtb16      r6, r12
-    sxtb16      r10, r12, ror #8
-    smlabb      r8, r6, lr, r7
-    smlatb      r6, r6, lr, r7
-    smlabb      r9, r10, lr, r7
-
-    smlatb      r10, r10, lr, r7
-    ssat        r8, #8, r8, asr #7
-    ssat        r6, #8, r6, asr #7
-    ssat        r9, #8, r9, asr #7
-    ssat        r10, #8, r10, asr #7
-
-    sub         src, src, pstep, lsl #2     ; move src pointer down by 4 lines
-
-    pkhbt       r6, r8, r6, lsl #16
-    pkhbt       r10, r9, r10, lsl #16
-
-    ldr         r9, [sp, #8]                ; load qs1
-    ldr         r11, [sp, #12]              ; load ps1
-    ldr         lr, c0x80808080
-
-    uxtb16      r6, r6
-    uxtb16      r10, r10
-
-    add         src, src, #2
-
-    orr         r10, r6, r10, lsl #8        ; u = vp8_signed_char_clamp((63 + Filter2 * 18)>>7)
-
-    qsub8       r8, r9, r10                 ; s = vp8_signed_char_clamp(qs1 - u)
-    qadd8       r10, r11, r10               ; s = vp8_signed_char_clamp(ps1 + u)
-    eor         r8, r8, lr                  ; *oq1 = s^0x80
-    eor         r10, r10, lr                ; *op1 = s^0x80
-
-    ldrb        r11, [src, #-5]             ; load p2 for 1/7th difference across boundary
-    strb        r10, [src, #-4]             ; store op1
-    strb        r8, [src, #-1]              ; store oq1
-    ldrb        r9, [src], pstep            ; load q2 for 1/7th difference across boundary
-
-    mov         r10, r10, lsr #8
-    mov         r8, r8, lsr #8
-
-    ldrb        r6, [src, #-5]
-    strb        r10, [src, #-4]
-    strb        r8, [src, #-1]
-    ldrb        r7, [src], pstep
-
-    mov         r10, r10, lsr #8
-    mov         r8, r8, lsr #8
-    orr         r11, r11, r6, lsl #8
-    orr         r9, r9, r7, lsl #8
-
-    ldrb        r6, [src, #-5]
-    strb        r10, [src, #-4]
-    strb        r8, [src, #-1]
-    ldrb        r7, [src], pstep
-
-    mov         r10, r10, lsr #8
-    mov         r8, r8, lsr #8
-    orr         r11, r11, r6, lsl #16
-    orr         r9, r9, r7, lsl #16
-
-    ldrb        r6, [src, #-5]
-    strb        r10, [src, #-4]
-    strb        r8, [src, #-1]
-    ldrb        r7, [src], pstep
-    orr         r11, r11, r6, lsl #24
-    orr         r9, r9, r7, lsl #24
-
-    ;roughly 1/7th difference across boundary
-    eor         r9, r9, lr
-    eor         r11, r11, lr
-
-    mov         lr, #0x9                    ; 9
-    mov         r7, #0x3f                   ; 63
-
-    sxtb16      r6, r12
-    sxtb16      r10, r12, ror #8
-    smlabb      r8, r6, lr, r7
-    smlatb      r6, r6, lr, r7
-    smlabb      r12, r10, lr, r7
-    smlatb      r10, r10, lr, r7
-    ssat        r8, #8, r8, asr #7
-    ssat        r6, #8, r6, asr #7
-    ssat        r12, #8, r12, asr #7
-    ssat        r10, #8, r10, asr #7
-
-    sub         src, src, pstep, lsl #2
-
-    pkhbt       r6, r8, r6, lsl #16
-    pkhbt       r10, r12, r10, lsl #16
-
-    uxtb16      r6, r6
-    uxtb16      r10, r10
-
-    ldr         lr, c0x80808080
-
-    orr         r10, r6, r10, lsl #8        ; u = vp8_signed_char_clamp((63 + Filter2 * 9)>>7)
-
-    qadd8       r8, r11, r10                ; s = vp8_signed_char_clamp(ps2 + u)
-    qsub8       r10, r9, r10                ; s = vp8_signed_char_clamp(qs2 - u)
-    eor         r8, r8, lr                  ; *op2 = s^0x80
-    eor         r10, r10, lr                ; *oq2 = s^0x80
-
-    strb        r8, [src, #-5]              ; store *op2
-    strb        r10, [src], pstep           ; store *oq2
-    mov         r8, r8, lsr #8
-    mov         r10, r10, lsr #8
-    strb        r8, [src, #-5]
-    strb        r10, [src], pstep
-    mov         r8, r8, lsr #8
-    mov         r10, r10, lsr #8
-    strb        r8, [src, #-5]
-    strb        r10, [src], pstep
-    mov         r8, r8, lsr #8
-    mov         r10, r10, lsr #8
-    strb        r8, [src, #-5]
-    strb        r10, [src], pstep
-
-    ;adjust src pointer for next loop
-    sub         src, src, #2
-
-|mbvskip_filter|
-    sub         src, src, #4
-    subs        count, count, #1
-
-    pld         [src, #23]                  ; preload for next block
-    ldrne       r6, [src], pstep            ; load source data
-    pld         [src, #23]
-    ldrne       r7, [src], pstep
-    pld         [src, #23]
-    ldrne       r8, [src], pstep
-    pld         [src, #23]
-    ldrne       lr, [src], pstep
-
-    bne         MBVnext8
-
-    add         sp, sp, #16
-
-    ldmia       sp!, {r4 - r11, pc}
-    ENDP        ; |vp8_mbloop_filter_vertical_edge_armv6|
-
-; Constant Pool
-c0x80808080 DCD     0x80808080
-c0x03030303 DCD     0x03030303
-c0x04040404 DCD     0x04040404
-c0x01010101 DCD     0x01010101
-c0x7F7F7F7F DCD     0x7F7F7F7F
-
-    END
diff --git a/vp8/common/arm/armv6/simpleloopfilter_v6.asm b/vp8/common/arm/armv6/simpleloopfilter_v6.asm
deleted file mode 100644 (file)
index 5e00cf0..0000000
+++ /dev/null
@@ -1,286 +0,0 @@
-;
-;  Copyright (c) 2010 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_loop_filter_simple_horizontal_edge_armv6|
-    EXPORT |vp8_loop_filter_simple_vertical_edge_armv6|
-
-    AREA    |.text|, CODE, READONLY  ; name this block of code
-
-    MACRO
-    TRANSPOSE_MATRIX $a0, $a1, $a2, $a3, $b0, $b1, $b2, $b3
-    ; input: $a0, $a1, $a2, $a3; output: $b0, $b1, $b2, $b3
-    ; a0: 03 02 01 00
-    ; a1: 13 12 11 10
-    ; a2: 23 22 21 20
-    ; a3: 33 32 31 30
-    ;     b3 b2 b1 b0
-
-    uxtb16      $b1, $a1                    ; xx 12 xx 10
-    uxtb16      $b0, $a0                    ; xx 02 xx 00
-    uxtb16      $b3, $a3                    ; xx 32 xx 30
-    uxtb16      $b2, $a2                    ; xx 22 xx 20
-    orr         $b1, $b0, $b1, lsl #8       ; 12 02 10 00
-    orr         $b3, $b2, $b3, lsl #8       ; 32 22 30 20
-
-    uxtb16      $a1, $a1, ror #8            ; xx 13 xx 11
-    uxtb16      $a3, $a3, ror #8            ; xx 33 xx 31
-    uxtb16      $a0, $a0, ror #8            ; xx 03 xx 01
-    uxtb16      $a2, $a2, ror #8            ; xx 23 xx 21
-    orr         $a0, $a0, $a1, lsl #8       ; 13 03 11 01
-    orr         $a2, $a2, $a3, lsl #8       ; 33 23 31 21
-
-    pkhtb       $b2, $b3, $b1, asr #16      ; 32 22 12 02   -- p1
-    pkhbt       $b0, $b1, $b3, lsl #16      ; 30 20 10 00   -- p3
-
-    pkhtb       $b3, $a2, $a0, asr #16      ; 33 23 13 03   -- p0
-    pkhbt       $b1, $a0, $a2, lsl #16      ; 31 21 11 01   -- p2
-    MEND
-
-
-
-src         RN  r0
-pstep       RN  r1
-
-;r0     unsigned char *src_ptr,
-;r1     int src_pixel_step,
-;r2     const char *blimit
-
-;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
-|vp8_loop_filter_simple_horizontal_edge_armv6| PROC
-;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
-    stmdb       sp!, {r4 - r11, lr}
-
-    ldrb        r12, [r2]                   ; blimit
-    ldr         r3, [src, -pstep, lsl #1]   ; p1
-    ldr         r4, [src, -pstep]           ; p0
-    ldr         r5, [src]                   ; q0
-    ldr         r6, [src, pstep]            ; q1
-    orr         r12, r12, r12, lsl #8       ; blimit
-    ldr         r2, c0x80808080
-    orr         r12, r12, r12, lsl #16      ; blimit
-    mov         r9, #4                      ; double the count. we're doing 4 at a time
-    mov         lr, #0                      ; need 0 in a couple places
-
-|simple_hnext8|
-    ; vp8_simple_filter_mask()
-
-    uqsub8      r7, r3, r6                  ; p1 - q1
-    uqsub8      r8, r6, r3                  ; q1 - p1
-    uqsub8      r10, r4, r5                 ; p0 - q0
-    uqsub8      r11, r5, r4                 ; q0 - p0
-    orr         r8, r8, r7                  ; abs(p1 - q1)
-    orr         r10, r10, r11               ; abs(p0 - q0)
-    uqadd8      r10, r10, r10               ; abs(p0 - q0) * 2
-    uhadd8      r8, r8, lr                  ; abs(p1 - q2) >> 1
-    uqadd8      r10, r10, r8                ; abs(p0 - q0)*2 + abs(p1 - q1)/2
-    mvn         r8, #0
-    usub8       r10, r12, r10               ; compare to flimit. usub8 sets GE flags
-    sel         r10, r8, lr                 ; filter mask: F or 0
-    cmp         r10, #0
-    beq         simple_hskip_filter         ; skip filtering if all masks are 0x00
-
-    ;vp8_simple_filter()
-
-    eor         r3, r3, r2                  ; p1 offset to convert to a signed value
-    eor         r6, r6, r2                  ; q1 offset to convert to a signed value
-    eor         r4, r4, r2                  ; p0 offset to convert to a signed value
-    eor         r5, r5, r2                  ; q0 offset to convert to a signed value
-
-    qsub8       r3, r3, r6                  ; vp8_filter = p1 - q1
-    qsub8       r6, r5, r4                  ; q0 - p0
-    qadd8       r3, r3, r6                  ; += q0 - p0
-    ldr         r7, c0x04040404
-    qadd8       r3, r3, r6                  ; += q0 - p0
-    ldr         r8, c0x03030303
-    qadd8       r3, r3, r6                  ; vp8_filter = p1-q1 + 3*(q0-p0))
-    ;STALL
-    and         r3, r3, r10                 ; vp8_filter &= mask
-
-    qadd8       r7 , r3 , r7                ; Filter1 = vp8_filter + 4
-    qadd8       r8 , r3 , r8                ; Filter2 = vp8_filter + 3
-
-    shadd8      r7 , r7 , lr
-    shadd8      r8 , r8 , lr
-    shadd8      r7 , r7 , lr
-    shadd8      r8 , r8 , lr
-    shadd8      r7 , r7 , lr                ; Filter1 >>= 3
-    shadd8      r8 , r8 , lr                ; Filter2 >>= 3
-
-    qsub8       r5 ,r5, r7                  ; u = q0 - Filter1
-    qadd8       r4, r4, r8                  ; u = p0 + Filter2
-    eor         r5, r5, r2                  ; *oq0 = u^0x80
-    str         r5, [src]                   ; store oq0 result
-    eor         r4, r4, r2                  ; *op0 = u^0x80
-    str         r4, [src, -pstep]           ; store op0 result
-
-|simple_hskip_filter|
-    subs        r9, r9, #1
-    addne       src, src, #4                ; next row
-
-    ldrne       r3, [src, -pstep, lsl #1]   ; p1
-    ldrne       r4, [src, -pstep]           ; p0
-    ldrne       r5, [src]                   ; q0
-    ldrne       r6, [src, pstep]            ; q1
-
-    bne         simple_hnext8
-
-    ldmia       sp!, {r4 - r11, pc}
-    ENDP        ; |vp8_loop_filter_simple_horizontal_edge_armv6|
-
-
-;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
-|vp8_loop_filter_simple_vertical_edge_armv6| PROC
-;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
-    stmdb       sp!, {r4 - r11, lr}
-
-    ldrb        r12, [r2]                   ; r12: blimit
-    ldr         r2, c0x80808080
-    orr         r12, r12, r12, lsl #8
-
-    ; load soure data to r7, r8, r9, r10
-    ldrh        r3, [src, #-2]
-    pld         [src, #23]                  ; preload for next block
-    ldrh        r4, [src], pstep
-    orr         r12, r12, r12, lsl #16
-
-    ldrh        r5, [src, #-2]
-    pld         [src, #23]
-    ldrh        r6, [src], pstep
-
-    pkhbt       r7, r3, r4, lsl #16
-
-    ldrh        r3, [src, #-2]
-    pld         [src, #23]
-    ldrh        r4, [src], pstep
-
-    pkhbt       r8, r5, r6, lsl #16
-
-    ldrh        r5, [src, #-2]
-    pld         [src, #23]
-    ldrh        r6, [src], pstep
-    mov         r11, #4                     ; double the count. we're doing 4 at a time
-
-|simple_vnext8|
-    ; vp8_simple_filter_mask() function
-    pkhbt       r9, r3, r4, lsl #16
-    pkhbt       r10, r5, r6, lsl #16
-
-    ;transpose r7, r8, r9, r10 to r3, r4, r5, r6
-    TRANSPOSE_MATRIX r7, r8, r9, r10, r3, r4, r5, r6
-
-    uqsub8      r7, r3, r6                  ; p1 - q1
-    uqsub8      r8, r6, r3                  ; q1 - p1
-    uqsub8      r9, r4, r5                  ; p0 - q0
-    uqsub8      r10, r5, r4                 ; q0 - p0
-    orr         r7, r7, r8                  ; abs(p1 - q1)
-    orr         r9, r9, r10                 ; abs(p0 - q0)
-    mov         r8, #0
-    uqadd8      r9, r9, r9                  ; abs(p0 - q0) * 2
-    uhadd8      r7, r7, r8                  ; abs(p1 - q1) / 2
-    uqadd8      r7, r7, r9                  ; abs(p0 - q0)*2 + abs(p1 - q1)/2
-    mvn         r10, #0                     ; r10 == -1
-
-    usub8       r7, r12, r7                 ; compare to flimit
-    sel         lr, r10, r8                 ; filter mask
-
-    cmp         lr, #0
-    beq         simple_vskip_filter         ; skip filtering
-
-    ;vp8_simple_filter() function
-    eor         r3, r3, r2                  ; p1 offset to convert to a signed value
-    eor         r6, r6, r2                  ; q1 offset to convert to a signed value
-    eor         r4, r4, r2                  ; p0 offset to convert to a signed value
-    eor         r5, r5, r2                  ; q0 offset to convert to a signed value
-
-    qsub8       r3, r3, r6                  ; vp8_filter = p1 - q1
-    qsub8       r6, r5, r4                  ; q0 - p0
-
-    qadd8       r3, r3, r6                  ; vp8_filter += q0 - p0
-    ldr         r9, c0x03030303             ; r9 = 3
-
-    qadd8       r3, r3, r6                  ; vp8_filter += q0 - p0
-    ldr         r7, c0x04040404
-
-    qadd8       r3, r3, r6                  ; vp8_filter = p1-q1 + 3*(q0-p0))
-    ;STALL
-    and         r3, r3, lr                  ; vp8_filter &= mask
-
-    qadd8       r9 , r3 , r9                ; Filter2 = vp8_filter + 3
-    qadd8       r3 , r3 , r7                ; Filter1 = vp8_filter + 4
-
-    shadd8      r9 , r9 , r8
-    shadd8      r3 , r3 , r8
-    shadd8      r9 , r9 , r8
-    shadd8      r3 , r3 , r8
-    shadd8      r9 , r9 , r8                ; Filter2 >>= 3
-    shadd8      r3 , r3 , r8                ; Filter1 >>= 3
-
-    ;calculate output
-    sub         src, src, pstep, lsl #2
-
-    qadd8       r4, r4, r9                  ; u = p0 + Filter2
-    qsub8       r5, r5, r3                  ; u = q0 - Filter1
-    eor         r4, r4, r2                  ; *op0 = u^0x80
-    eor         r5, r5, r2                  ; *oq0 = u^0x80
-
-    strb        r4, [src, #-1]              ; store the result
-    mov         r4, r4, lsr #8
-    strb        r5, [src], pstep
-    mov         r5, r5, lsr #8
-
-    strb        r4, [src, #-1]
-    mov         r4, r4, lsr #8
-    strb        r5, [src], pstep
-    mov         r5, r5, lsr #8
-
-    strb        r4, [src, #-1]
-    mov         r4, r4, lsr #8
-    strb        r5, [src], pstep
-    mov         r5, r5, lsr #8
-
-    strb        r4, [src, #-1]
-    strb        r5, [src], pstep
-
-|simple_vskip_filter|
-    subs        r11, r11, #1
-
-    ; load soure data to r7, r8, r9, r10
-    ldrneh      r3, [src, #-2]
-    pld         [src, #23]                  ; preload for next block
-    ldrneh      r4, [src], pstep
-
-    ldrneh      r5, [src, #-2]
-    pld         [src, #23]
-    ldrneh      r6, [src], pstep
-
-    pkhbt       r7, r3, r4, lsl #16
-
-    ldrneh      r3, [src, #-2]
-    pld         [src, #23]
-    ldrneh      r4, [src], pstep
-
-    pkhbt       r8, r5, r6, lsl #16
-
-    ldrneh      r5, [src, #-2]
-    pld         [src, #23]
-    ldrneh      r6, [src], pstep
-
-    bne         simple_vnext8
-
-    ldmia       sp!, {r4 - r11, pc}
-    ENDP        ; |vp8_loop_filter_simple_vertical_edge_armv6|
-
-; Constant Pool
-c0x80808080 DCD     0x80808080
-c0x03030303 DCD     0x03030303
-c0x04040404 DCD     0x04040404
-
-    END
diff --git a/vp8/common/arm/armv6/sixtappredict8x4_v6.asm b/vp8/common/arm/armv6/sixtappredict8x4_v6.asm
deleted file mode 100644 (file)
index e81aef5..0000000
+++ /dev/null
@@ -1,273 +0,0 @@
-;
-;  Copyright (c) 2010 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_sixtap_predict8x4_armv6|
-
-    AREA    |.text|, CODE, READONLY  ; name this block of code
-;-------------------------------------
-; r0    unsigned char *src_ptr,
-; r1    int  src_pixels_per_line,
-; r2    int  xoffset,
-; r3    int  yoffset,
-; stack unsigned char *dst_ptr,
-; stack int  dst_pitch
-;-------------------------------------
-;note: In first pass, store the result in transpose(8linesx9columns) on stack. Temporary stack size is 184.
-;Line width is 20 that is 9 short data plus 2 to make it 4bytes aligned. In second pass, load data from stack,
-;and the result is stored in transpose.
-|vp8_sixtap_predict8x4_armv6| PROC
-    stmdb       sp!, {r4 - r11, lr}
-    str         r3, [sp, #-184]!            ;reserve space on stack for temporary storage, store yoffset
-
-    cmp         r2, #0                      ;skip first_pass filter if xoffset=0
-    add         lr, sp, #4                  ;point to temporary buffer
-    beq         skip_firstpass_filter
-
-;first-pass filter
-    adr         r12, filter8_coeff
-    sub         r0, r0, r1, lsl #1
-
-    add         r3, r1, #10                 ; preload next low
-    pld         [r0, r3]
-
-    add         r2, r12, r2, lsl #4         ;calculate filter location
-    add         r0, r0, #3                  ;adjust src only for loading convinience
-
-    ldr         r3, [r2]                    ; load up packed filter coefficients
-    ldr         r4, [r2, #4]
-    ldr         r5, [r2, #8]
-
-    mov         r2, #0x90000                ; height=9 is top part of counter
-
-    sub         r1, r1, #8
-
-|first_pass_hloop_v6|
-    ldrb        r6, [r0, #-5]               ; load source data
-    ldrb        r7, [r0, #-4]
-    ldrb        r8, [r0, #-3]
-    ldrb        r9, [r0, #-2]
-    ldrb        r10, [r0, #-1]
-
-    orr         r2, r2, #0x4                ; construct loop counter. width=8=4x2
-
-    pkhbt       r6, r6, r7, lsl #16         ; r7 | r6
-    pkhbt       r7, r7, r8, lsl #16         ; r8 | r7
-
-    pkhbt       r8, r8, r9, lsl #16         ; r9 | r8
-    pkhbt       r9, r9, r10, lsl #16        ; r10 | r9
-
-|first_pass_wloop_v6|
-    smuad       r11, r6, r3                 ; vp8_filter[0], vp8_filter[1]
-    smuad       r12, r7, r3
-
-    ldrb        r6, [r0], #1
-
-    smlad       r11, r8, r4, r11            ; vp8_filter[2], vp8_filter[3]
-    ldrb        r7, [r0], #1
-    smlad       r12, r9, r4, r12
-
-    pkhbt       r10, r10, r6, lsl #16       ; r10 | r9
-    pkhbt       r6, r6, r7, lsl #16         ; r11 | r10
-    smlad       r11, r10, r5, r11           ; vp8_filter[4], vp8_filter[5]
-    smlad       r12, r6, r5, r12
-
-    sub         r2, r2, #1
-
-    add         r11, r11, #0x40             ; round_shift_and_clamp
-    tst         r2, #0xff                   ; test loop counter
-    usat        r11, #8, r11, asr #7
-    add         r12, r12, #0x40
-    strh        r11, [lr], #20              ; result is transposed and stored, which
-    usat        r12, #8, r12, asr #7
-
-    strh        r12, [lr], #20
-
-    movne       r11, r6
-    movne       r12, r7
-
-    movne       r6, r8
-    movne       r7, r9
-    movne       r8, r10
-    movne       r9, r11
-    movne       r10, r12
-
-    bne         first_pass_wloop_v6
-
-    ;;add       r9, ppl, #30                ; attempt to load 2 adjacent cache lines
-    ;;IF ARCHITECTURE=6
-    ;pld        [src, ppl]
-    ;;pld       [src, r9]
-    ;;ENDIF
-
-    subs        r2, r2, #0x10000
-
-    sub         lr, lr, #158
-
-    add         r0, r0, r1                  ; move to next input line
-
-    add         r11, r1, #18                ; preload next low. adding back block width(=8), which is subtracted earlier
-    pld         [r0, r11]
-
-    bne         first_pass_hloop_v6
-
-;second pass filter
-secondpass_filter
-    ldr         r3, [sp], #4                ; load back yoffset
-    ldr         r0, [sp, #216]              ; load dst address from stack 180+36
-    ldr         r1, [sp, #220]              ; load dst stride from stack 180+40
-
-    cmp         r3, #0
-    beq         skip_secondpass_filter
-
-    adr         r12, filter8_coeff
-    add         lr, r12, r3, lsl #4         ;calculate filter location
-
-    mov         r2, #0x00080000
-
-    ldr         r3, [lr]                    ; load up packed filter coefficients
-    ldr         r4, [lr, #4]
-    ldr         r5, [lr, #8]
-
-    pkhbt       r12, r4, r3                 ; pack the filter differently
-    pkhbt       r11, r5, r4
-
-second_pass_hloop_v6
-    ldr         r6, [sp]                    ; load the data
-    ldr         r7, [sp, #4]
-
-    orr         r2, r2, #2                  ; loop counter
-
-second_pass_wloop_v6
-    smuad       lr, r3, r6                  ; apply filter
-    smulbt      r10, r3, r6
-
-    ldr         r8, [sp, #8]
-
-    smlad       lr, r4, r7, lr
-    smladx      r10, r12, r7, r10
-
-    ldrh        r9, [sp, #12]
-
-    smlad       lr, r5, r8, lr
-    smladx      r10, r11, r8, r10
-
-    add         sp, sp, #4
-    smlatb      r10, r5, r9, r10
-
-    sub         r2, r2, #1
-
-    add         lr, lr, #0x40               ; round_shift_and_clamp
-    tst         r2, #0xff
-    usat        lr, #8, lr, asr #7
-    add         r10, r10, #0x40
-    strb        lr, [r0], r1                ; the result is transposed back and stored
-    usat        r10, #8, r10, asr #7
-
-    strb        r10, [r0],r1
-
-    movne       r6, r7
-    movne       r7, r8
-
-    bne         second_pass_wloop_v6
-
-    subs        r2, r2, #0x10000
-    add         sp, sp, #12                 ; updata src for next loop (20-8)
-    sub         r0, r0, r1, lsl #2
-    add         r0, r0, #1
-
-    bne         second_pass_hloop_v6
-
-    add         sp, sp, #20
-    ldmia       sp!, {r4 - r11, pc}
-
-;--------------------
-skip_firstpass_filter
-    sub         r0, r0, r1, lsl #1
-    sub         r1, r1, #8
-    mov         r2, #9
-
-skip_firstpass_hloop
-    ldrb        r4, [r0], #1                ; load data
-    subs        r2, r2, #1
-    ldrb        r5, [r0], #1
-    strh        r4, [lr], #20               ; store it to immediate buffer
-    ldrb        r6, [r0], #1                ; load data
-    strh        r5, [lr], #20
-    ldrb        r7, [r0], #1
-    strh        r6, [lr], #20
-    ldrb        r8, [r0], #1
-    strh        r7, [lr], #20
-    ldrb        r9, [r0], #1
-    strh        r8, [lr], #20
-    ldrb        r10, [r0], #1
-    strh        r9, [lr], #20
-    ldrb        r11, [r0], #1
-    strh        r10, [lr], #20
-    add         r0, r0, r1                  ; move to next input line
-    strh        r11, [lr], #20
-
-    sub         lr, lr, #158                ; move over to next column
-    bne         skip_firstpass_hloop
-
-    b           secondpass_filter
-
-;--------------------
-skip_secondpass_filter
-    mov         r2, #8
-    add         sp, sp, #4                  ;start from src[0] instead of src[-2]
-
-skip_secondpass_hloop
-    ldr         r6, [sp], #4
-    subs        r2, r2, #1
-    ldr         r8, [sp], #4
-
-    mov         r7, r6, lsr #16             ; unpack
-    strb        r6, [r0], r1
-    mov         r9, r8, lsr #16
-    strb        r7, [r0], r1
-    add         sp, sp, #12                 ; 20-8
-    strb        r8, [r0], r1
-    strb        r9, [r0], r1
-
-    sub         r0, r0, r1, lsl #2
-    add         r0, r0, #1
-
-    bne         skip_secondpass_hloop
-
-    add         sp, sp, #16                 ; 180 - (160 +4)
-
-    ldmia       sp!, {r4 - r11, pc}
-
-    ENDP
-
-;-----------------
-;One word each is reserved. Label filter_coeff can be used to access the data.
-;Data address: filter_coeff, filter_coeff+4, filter_coeff+8 ...
-filter8_coeff
-    DCD     0x00000000,     0x00000080,     0x00000000,     0x00000000
-    DCD     0xfffa0000,     0x000c007b,     0x0000ffff,     0x00000000
-    DCD     0xfff50002,     0x0024006c,     0x0001fff8,     0x00000000
-    DCD     0xfff70000,     0x0032005d,     0x0000fffa,     0x00000000
-    DCD     0xfff00003,     0x004d004d,     0x0003fff0,     0x00000000
-    DCD     0xfffa0000,     0x005d0032,     0x0000fff7,     0x00000000
-    DCD     0xfff80001,     0x006c0024,     0x0002fff5,     0x00000000
-    DCD     0xffff0000,     0x007b000c,     0x0000fffa,     0x00000000
-
-    ;DCD        0,  0,  128,    0,   0,  0
-    ;DCD        0, -6,  123,   12,  -1,  0
-    ;DCD        2, -11, 108,   36,  -8,  1
-    ;DCD        0, -9,   93,   50,  -6,  0
-    ;DCD        3, -16,  77,   77, -16,  3
-    ;DCD        0, -6,   50,   93,  -9,  0
-    ;DCD        1, -8,   36,  108, -11,  2
-    ;DCD        0, -1,   12,  123,  -6,  0
-
-    END
diff --git a/vp8/common/arm/bilinearfilter_arm.c b/vp8/common/arm/bilinearfilter_arm.c
deleted file mode 100644 (file)
index 799c8bd..0000000
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#include "vpx_config.h"
-#include "vp8_rtcd.h"
-#include <math.h>
-#include "vp8/common/filter.h"
-#include "bilinearfilter_arm.h"
-
-void vp8_filter_block2d_bil_armv6
-(
-    unsigned char *src_ptr,
-    unsigned char *dst_ptr,
-    unsigned int   src_pitch,
-    unsigned int   dst_pitch,
-    const short   *HFilter,
-    const short   *VFilter,
-    int            Width,
-    int            Height
-)
-{
-    unsigned short FData[36*16]; /* Temp data buffer used in filtering */
-
-    /* First filter 1-D horizontally... */
-    vp8_filter_block2d_bil_first_pass_armv6(src_ptr, FData, src_pitch, Height + 1, Width, HFilter);
-
-    /* then 1-D vertically... */
-    vp8_filter_block2d_bil_second_pass_armv6(FData, dst_ptr, dst_pitch, Height, Width, VFilter);
-}
-
-
-void vp8_bilinear_predict4x4_armv6
-(
-    unsigned char  *src_ptr,
-    int   src_pixels_per_line,
-    int  xoffset,
-    int  yoffset,
-    unsigned char *dst_ptr,
-    int dst_pitch
-)
-{
-    const short  *HFilter;
-    const short  *VFilter;
-
-    HFilter = vp8_bilinear_filters[xoffset];
-    VFilter = vp8_bilinear_filters[yoffset];
-
-    vp8_filter_block2d_bil_armv6(src_ptr, dst_ptr, src_pixels_per_line, dst_pitch, HFilter, VFilter, 4, 4);
-}
-
-void vp8_bilinear_predict8x8_armv6
-(
-    unsigned char  *src_ptr,
-    int  src_pixels_per_line,
-    int  xoffset,
-    int  yoffset,
-    unsigned char *dst_ptr,
-    int  dst_pitch
-)
-{
-    const short  *HFilter;
-    const short  *VFilter;
-
-    HFilter = vp8_bilinear_filters[xoffset];
-    VFilter = vp8_bilinear_filters[yoffset];
-
-    vp8_filter_block2d_bil_armv6(src_ptr, dst_ptr, src_pixels_per_line, dst_pitch, HFilter, VFilter, 8, 8);
-}
-
-void vp8_bilinear_predict8x4_armv6
-(
-    unsigned char  *src_ptr,
-    int  src_pixels_per_line,
-    int  xoffset,
-    int  yoffset,
-    unsigned char *dst_ptr,
-    int  dst_pitch
-)
-{
-    const short  *HFilter;
-    const short  *VFilter;
-
-    HFilter = vp8_bilinear_filters[xoffset];
-    VFilter = vp8_bilinear_filters[yoffset];
-
-    vp8_filter_block2d_bil_armv6(src_ptr, dst_ptr, src_pixels_per_line, dst_pitch, HFilter, VFilter, 8, 4);
-}
-
-void vp8_bilinear_predict16x16_armv6
-(
-    unsigned char  *src_ptr,
-    int  src_pixels_per_line,
-    int  xoffset,
-    int  yoffset,
-    unsigned char *dst_ptr,
-    int  dst_pitch
-)
-{
-    const short  *HFilter;
-    const short  *VFilter;
-
-    HFilter = vp8_bilinear_filters[xoffset];
-    VFilter = vp8_bilinear_filters[yoffset];
-
-    vp8_filter_block2d_bil_armv6(src_ptr, dst_ptr, src_pixels_per_line, dst_pitch, HFilter, VFilter, 16, 16);
-}
diff --git a/vp8/common/arm/bilinearfilter_arm.h b/vp8/common/arm/bilinearfilter_arm.h
deleted file mode 100644 (file)
index 6b84e6f..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- *  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.
- */
-
-
-#ifndef VP8_COMMON_ARM_BILINEARFILTER_ARM_H_
-#define VP8_COMMON_ARM_BILINEARFILTER_ARM_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-extern void vp8_filter_block2d_bil_first_pass_armv6
-(
-    const unsigned char  *src_ptr,
-    unsigned short       *dst_ptr,
-    unsigned int          src_pitch,
-    unsigned int          height,
-    unsigned int          width,
-    const short          *vp8_filter
-);
-
-extern void vp8_filter_block2d_bil_second_pass_armv6
-(
-    const unsigned short *src_ptr,
-    unsigned char        *dst_ptr,
-    int                   dst_pitch,
-    unsigned int          height,
-    unsigned int          width,
-    const short         *vp8_filter
-);
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP8_COMMON_ARM_BILINEARFILTER_ARM_H_
diff --git a/vp8/common/arm/dequantize_arm.c b/vp8/common/arm/dequantize_arm.c
deleted file mode 100644 (file)
index 1f8157f..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#include "vpx_config.h"
-#include "vp8/common/blockd.h"
-
-#if HAVE_MEDIA
-extern void vp8_dequantize_b_loop_v6(short *Q, short *DQC, short *DQ);
-
-void vp8_dequantize_b_v6(BLOCKD *d, short *DQC)
-{
-    short *DQ  = d->dqcoeff;
-    short *Q   = d->qcoeff;
-
-    vp8_dequantize_b_loop_v6(Q, DQC, DQ);
-}
-#endif
diff --git a/vp8/common/arm/filter_arm.c b/vp8/common/arm/filter_arm.c
deleted file mode 100644 (file)
index d6a6781..0000000
+++ /dev/null
@@ -1,221 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#include "vpx_config.h"
-#include "vp8_rtcd.h"
-#include <math.h>
-#include "vp8/common/filter.h"
-#include "vpx_ports/mem.h"
-
-extern void vp8_filter_block2d_first_pass_armv6
-(
-    unsigned char *src_ptr,
-    short         *output_ptr,
-    unsigned int src_pixels_per_line,
-    unsigned int output_width,
-    unsigned int output_height,
-    const short *vp8_filter
-);
-
-// 8x8
-extern void vp8_filter_block2d_first_pass_8x8_armv6
-(
-    unsigned char *src_ptr,
-    short         *output_ptr,
-    unsigned int src_pixels_per_line,
-    unsigned int output_width,
-    unsigned int output_height,
-    const short *vp8_filter
-);
-
-// 16x16
-extern void vp8_filter_block2d_first_pass_16x16_armv6
-(
-    unsigned char *src_ptr,
-    short         *output_ptr,
-    unsigned int src_pixels_per_line,
-    unsigned int output_width,
-    unsigned int output_height,
-    const short *vp8_filter
-);
-
-extern void vp8_filter_block2d_second_pass_armv6
-(
-    short         *src_ptr,
-    unsigned char *output_ptr,
-    unsigned int output_pitch,
-    unsigned int cnt,
-    const short *vp8_filter
-);
-
-extern void vp8_filter4_block2d_second_pass_armv6
-(
-    short         *src_ptr,
-    unsigned char *output_ptr,
-    unsigned int output_pitch,
-    unsigned int cnt,
-    const short *vp8_filter
-);
-
-extern void vp8_filter_block2d_first_pass_only_armv6
-(
-    unsigned char *src_ptr,
-    unsigned char *output_ptr,
-    unsigned int src_pixels_per_line,
-    unsigned int cnt,
-    unsigned int output_pitch,
-    const short *vp8_filter
-);
-
-
-extern void vp8_filter_block2d_second_pass_only_armv6
-(
-    unsigned char *src_ptr,
-    unsigned char *output_ptr,
-    unsigned int src_pixels_per_line,
-    unsigned int cnt,
-    unsigned int output_pitch,
-    const short *vp8_filter
-);
-
-#if HAVE_MEDIA
-void vp8_sixtap_predict4x4_armv6
-(
-    unsigned char  *src_ptr,
-    int  src_pixels_per_line,
-    int  xoffset,
-    int  yoffset,
-    unsigned char *dst_ptr,
-    int  dst_pitch
-)
-{
-    const short  *HFilter;
-    const short  *VFilter;
-    DECLARE_ALIGNED(4, short, FData[12*4]); /* Temp data buffer used in filtering */
-
-
-    HFilter = vp8_sub_pel_filters[xoffset];   /* 6 tap */
-    VFilter = vp8_sub_pel_filters[yoffset];   /* 6 tap */
-
-    /* Vfilter is null. First pass only */
-    if (xoffset && !yoffset)
-    {
-        /*vp8_filter_block2d_first_pass_armv6 ( src_ptr, FData+2, src_pixels_per_line, 4, 4, HFilter );
-        vp8_filter_block2d_second_pass_armv6 ( FData+2, dst_ptr, dst_pitch, 4, VFilter );*/
-
-        vp8_filter_block2d_first_pass_only_armv6(src_ptr, dst_ptr, src_pixels_per_line, 4, dst_pitch, HFilter);
-    }
-    /* Hfilter is null. Second pass only */
-    else if (!xoffset && yoffset)
-    {
-        vp8_filter_block2d_second_pass_only_armv6(src_ptr, dst_ptr, src_pixels_per_line, 4, dst_pitch, VFilter);
-    }
-    else
-    {
-        /* Vfilter is a 4 tap filter */
-        if (yoffset & 0x1)
-        {
-            vp8_filter_block2d_first_pass_armv6(src_ptr - src_pixels_per_line, FData + 1, src_pixels_per_line, 4, 7, HFilter);
-            vp8_filter4_block2d_second_pass_armv6(FData + 2, dst_ptr, dst_pitch, 4, VFilter);
-        }
-        /* Vfilter is 6 tap filter */
-        else
-        {
-            vp8_filter_block2d_first_pass_armv6(src_ptr - (2 * src_pixels_per_line), FData, src_pixels_per_line, 4, 9, HFilter);
-            vp8_filter_block2d_second_pass_armv6(FData + 2, dst_ptr, dst_pitch, 4, VFilter);
-        }
-    }
-}
-
-void vp8_sixtap_predict8x8_armv6
-(
-    unsigned char  *src_ptr,
-    int  src_pixels_per_line,
-    int  xoffset,
-    int  yoffset,
-    unsigned char *dst_ptr,
-    int  dst_pitch
-)
-{
-    const short  *HFilter;
-    const short  *VFilter;
-    DECLARE_ALIGNED(4, short, FData[16*8]); /* Temp data buffer used in filtering */
-
-    HFilter = vp8_sub_pel_filters[xoffset];   /* 6 tap */
-    VFilter = vp8_sub_pel_filters[yoffset];   /* 6 tap */
-
-    if (xoffset && !yoffset)
-    {
-        vp8_filter_block2d_first_pass_only_armv6(src_ptr, dst_ptr, src_pixels_per_line, 8, dst_pitch, HFilter);
-    }
-    /* Hfilter is null. Second pass only */
-    else if (!xoffset && yoffset)
-    {
-        vp8_filter_block2d_second_pass_only_armv6(src_ptr, dst_ptr, src_pixels_per_line, 8, dst_pitch, VFilter);
-    }
-    else
-    {
-        if (yoffset & 0x1)
-        {
-            vp8_filter_block2d_first_pass_8x8_armv6(src_ptr - src_pixels_per_line, FData + 1, src_pixels_per_line, 8, 11, HFilter);
-            vp8_filter4_block2d_second_pass_armv6(FData + 2, dst_ptr, dst_pitch, 8, VFilter);
-        }
-        else
-        {
-            vp8_filter_block2d_first_pass_8x8_armv6(src_ptr - (2 * src_pixels_per_line), FData, src_pixels_per_line, 8, 13, HFilter);
-            vp8_filter_block2d_second_pass_armv6(FData + 2, dst_ptr, dst_pitch, 8, VFilter);
-        }
-    }
-}
-
-
-void vp8_sixtap_predict16x16_armv6
-(
-    unsigned char  *src_ptr,
-    int  src_pixels_per_line,
-    int  xoffset,
-    int  yoffset,
-    unsigned char *dst_ptr,
-    int  dst_pitch
-)
-{
-    const short  *HFilter;
-    const short  *VFilter;
-    DECLARE_ALIGNED(4, short, FData[24*16]);    /* Temp data buffer used in filtering */
-
-    HFilter = vp8_sub_pel_filters[xoffset];   /* 6 tap */
-    VFilter = vp8_sub_pel_filters[yoffset];   /* 6 tap */
-
-    if (xoffset && !yoffset)
-    {
-        vp8_filter_block2d_first_pass_only_armv6(src_ptr, dst_ptr, src_pixels_per_line, 16, dst_pitch, HFilter);
-    }
-    /* Hfilter is null. Second pass only */
-    else if (!xoffset && yoffset)
-    {
-        vp8_filter_block2d_second_pass_only_armv6(src_ptr, dst_ptr, src_pixels_per_line, 16, dst_pitch, VFilter);
-    }
-    else
-    {
-        if (yoffset & 0x1)
-        {
-            vp8_filter_block2d_first_pass_16x16_armv6(src_ptr - src_pixels_per_line, FData + 1, src_pixels_per_line, 16, 19, HFilter);
-            vp8_filter4_block2d_second_pass_armv6(FData + 2, dst_ptr, dst_pitch, 16, VFilter);
-        }
-        else
-        {
-            vp8_filter_block2d_first_pass_16x16_armv6(src_ptr - (2 * src_pixels_per_line), FData, src_pixels_per_line, 16, 21, HFilter);
-            vp8_filter_block2d_second_pass_armv6(FData + 2, dst_ptr, dst_pitch, 16, VFilter);
-        }
-    }
-
-}
-#endif
diff --git a/vp8/common/arm/loopfilter_arm.c b/vp8/common/arm/loopfilter_arm.c
deleted file mode 100644 (file)
index 5840c2b..0000000
+++ /dev/null
@@ -1,181 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#include "vpx_config.h"
-#include "vp8_rtcd.h"
-#include "vp8/common/loopfilter.h"
-#include "vp8/common/onyxc_int.h"
-
-#define prototype_loopfilter(sym) \
-    void sym(unsigned char *src, int pitch, const unsigned char *blimit,\
-             const unsigned char *limit, const unsigned char *thresh, int count)
-
-#if HAVE_MEDIA
-extern prototype_loopfilter(vp8_loop_filter_horizontal_edge_armv6);
-extern prototype_loopfilter(vp8_loop_filter_vertical_edge_armv6);
-extern prototype_loopfilter(vp8_mbloop_filter_horizontal_edge_armv6);
-extern prototype_loopfilter(vp8_mbloop_filter_vertical_edge_armv6);
-#endif
-
-#if HAVE_NEON
-typedef void loopfilter_y_neon(unsigned char *src, int pitch,
-        unsigned char blimit, unsigned char limit, unsigned char thresh);
-typedef void loopfilter_uv_neon(unsigned char *u, int pitch,
-        unsigned char blimit, unsigned char limit, unsigned char thresh,
-        unsigned char *v);
-
-extern loopfilter_y_neon vp8_loop_filter_horizontal_edge_y_neon;
-extern loopfilter_y_neon vp8_loop_filter_vertical_edge_y_neon;
-extern loopfilter_uv_neon vp8_loop_filter_horizontal_edge_uv_neon;
-extern loopfilter_uv_neon vp8_loop_filter_vertical_edge_uv_neon;
-
-extern loopfilter_y_neon vp8_mbloop_filter_horizontal_edge_y_neon;
-extern loopfilter_y_neon vp8_mbloop_filter_vertical_edge_y_neon;
-extern loopfilter_uv_neon vp8_mbloop_filter_horizontal_edge_uv_neon;
-extern loopfilter_uv_neon vp8_mbloop_filter_vertical_edge_uv_neon;
-#endif
-
-#if HAVE_MEDIA
-/* ARMV6/MEDIA loopfilter functions*/
-/* Horizontal MB filtering */
-void vp8_loop_filter_mbh_armv6(unsigned char *y_ptr, unsigned char *u_ptr, unsigned char *v_ptr,
-                               int y_stride, int uv_stride, loop_filter_info *lfi)
-{
-    vp8_mbloop_filter_horizontal_edge_armv6(y_ptr, y_stride, lfi->mblim, lfi->lim, lfi->hev_thr, 2);
-
-    if (u_ptr)
-        vp8_mbloop_filter_horizontal_edge_armv6(u_ptr, uv_stride, lfi->mblim, lfi->lim, lfi->hev_thr, 1);
-
-    if (v_ptr)
-        vp8_mbloop_filter_horizontal_edge_armv6(v_ptr, uv_stride, lfi->mblim, lfi->lim, lfi->hev_thr, 1);
-}
-
-/* Vertical MB Filtering */
-void vp8_loop_filter_mbv_armv6(unsigned char *y_ptr, unsigned char *u_ptr, unsigned char *v_ptr,
-                               int y_stride, int uv_stride, loop_filter_info *lfi)
-{
-    vp8_mbloop_filter_vertical_edge_armv6(y_ptr, y_stride, lfi->mblim, lfi->lim, lfi->hev_thr, 2);
-
-    if (u_ptr)
-        vp8_mbloop_filter_vertical_edge_armv6(u_ptr, uv_stride, lfi->mblim, lfi->lim, lfi->hev_thr, 1);
-
-    if (v_ptr)
-        vp8_mbloop_filter_vertical_edge_armv6(v_ptr, uv_stride, lfi->mblim, lfi->lim, lfi->hev_thr, 1);
-}
-
-/* Horizontal B Filtering */
-void vp8_loop_filter_bh_armv6(unsigned char *y_ptr, unsigned char *u_ptr, unsigned char *v_ptr,
-                              int y_stride, int uv_stride, loop_filter_info *lfi)
-{
-    vp8_loop_filter_horizontal_edge_armv6(y_ptr + 4 * y_stride, y_stride, lfi->blim, lfi->lim, lfi->hev_thr, 2);
-    vp8_loop_filter_horizontal_edge_armv6(y_ptr + 8 * y_stride, y_stride, lfi->blim, lfi->lim, lfi->hev_thr, 2);
-    vp8_loop_filter_horizontal_edge_armv6(y_ptr + 12 * y_stride, y_stride, lfi->blim, lfi->lim, lfi->hev_thr, 2);
-
-    if (u_ptr)
-        vp8_loop_filter_horizontal_edge_armv6(u_ptr + 4 * uv_stride, uv_stride, lfi->blim, lfi->lim, lfi->hev_thr, 1);
-
-    if (v_ptr)
-        vp8_loop_filter_horizontal_edge_armv6(v_ptr + 4 * uv_stride, uv_stride, lfi->blim, lfi->lim, lfi->hev_thr, 1);
-}
-
-void vp8_loop_filter_bhs_armv6(unsigned char *y_ptr, int y_stride,
-                               const unsigned char *blimit)
-{
-    vp8_loop_filter_simple_horizontal_edge_armv6(y_ptr + 4 * y_stride, y_stride, blimit);
-    vp8_loop_filter_simple_horizontal_edge_armv6(y_ptr + 8 * y_stride, y_stride, blimit);
-    vp8_loop_filter_simple_horizontal_edge_armv6(y_ptr + 12 * y_stride, y_stride, blimit);
-}
-
-/* Vertical B Filtering */
-void vp8_loop_filter_bv_armv6(unsigned char *y_ptr, unsigned char *u_ptr, unsigned char *v_ptr,
-                              int y_stride, int uv_stride, loop_filter_info *lfi)
-{
-    vp8_loop_filter_vertical_edge_armv6(y_ptr + 4, y_stride, lfi->blim, lfi->lim, lfi->hev_thr, 2);
-    vp8_loop_filter_vertical_edge_armv6(y_ptr + 8, y_stride, lfi->blim, lfi->lim, lfi->hev_thr, 2);
-    vp8_loop_filter_vertical_edge_armv6(y_ptr + 12, y_stride, lfi->blim, lfi->lim, lfi->hev_thr, 2);
-
-    if (u_ptr)
-        vp8_loop_filter_vertical_edge_armv6(u_ptr + 4, uv_stride, lfi->blim, lfi->lim, lfi->hev_thr, 1);
-
-    if (v_ptr)
-        vp8_loop_filter_vertical_edge_armv6(v_ptr + 4, uv_stride, lfi->blim, lfi->lim, lfi->hev_thr, 1);
-}
-
-void vp8_loop_filter_bvs_armv6(unsigned char *y_ptr, int y_stride,
-                               const unsigned char *blimit)
-{
-    vp8_loop_filter_simple_vertical_edge_armv6(y_ptr + 4, y_stride, blimit);
-    vp8_loop_filter_simple_vertical_edge_armv6(y_ptr + 8, y_stride, blimit);
-    vp8_loop_filter_simple_vertical_edge_armv6(y_ptr + 12, y_stride, blimit);
-}
-#endif
-
-#if HAVE_NEON
-/* NEON loopfilter functions */
-/* Horizontal MB filtering */
-void vp8_loop_filter_mbh_neon(unsigned char *y_ptr, unsigned char *u_ptr, unsigned char *v_ptr,
-                              int y_stride, int uv_stride, loop_filter_info *lfi)
-{
-    unsigned char mblim = *lfi->mblim;
-    unsigned char lim = *lfi->lim;
-    unsigned char hev_thr = *lfi->hev_thr;
-    vp8_mbloop_filter_horizontal_edge_y_neon(y_ptr, y_stride, mblim, lim, hev_thr);
-
-    if (u_ptr)
-        vp8_mbloop_filter_horizontal_edge_uv_neon(u_ptr, uv_stride, mblim, lim, hev_thr, v_ptr);
-}
-
-/* Vertical MB Filtering */
-void vp8_loop_filter_mbv_neon(unsigned char *y_ptr, unsigned char *u_ptr, unsigned char *v_ptr,
-                              int y_stride, int uv_stride, loop_filter_info *lfi)
-{
-    unsigned char mblim = *lfi->mblim;
-    unsigned char lim = *lfi->lim;
-    unsigned char hev_thr = *lfi->hev_thr;
-
-    vp8_mbloop_filter_vertical_edge_y_neon(y_ptr, y_stride, mblim, lim, hev_thr);
-
-    if (u_ptr)
-        vp8_mbloop_filter_vertical_edge_uv_neon(u_ptr, uv_stride, mblim, lim, hev_thr, v_ptr);
-}
-
-/* Horizontal B Filtering */
-void vp8_loop_filter_bh_neon(unsigned char *y_ptr, unsigned char *u_ptr, unsigned char *v_ptr,
-                             int y_stride, int uv_stride, loop_filter_info *lfi)
-{
-    unsigned char blim = *lfi->blim;
-    unsigned char lim = *lfi->lim;
-    unsigned char hev_thr = *lfi->hev_thr;
-
-    vp8_loop_filter_horizontal_edge_y_neon(y_ptr + 4 * y_stride, y_stride, blim, lim, hev_thr);
-    vp8_loop_filter_horizontal_edge_y_neon(y_ptr + 8 * y_stride, y_stride, blim, lim, hev_thr);
-    vp8_loop_filter_horizontal_edge_y_neon(y_ptr + 12 * y_stride, y_stride, blim, lim, hev_thr);
-
-    if (u_ptr)
-        vp8_loop_filter_horizontal_edge_uv_neon(u_ptr + 4 * uv_stride, uv_stride, blim, lim, hev_thr, v_ptr + 4 * uv_stride);
-}
-
-/* Vertical B Filtering */
-void vp8_loop_filter_bv_neon(unsigned char *y_ptr, unsigned char *u_ptr, unsigned char *v_ptr,
-                             int y_stride, int uv_stride, loop_filter_info *lfi)
-{
-    unsigned char blim = *lfi->blim;
-    unsigned char lim = *lfi->lim;
-    unsigned char hev_thr = *lfi->hev_thr;
-
-    vp8_loop_filter_vertical_edge_y_neon(y_ptr + 4, y_stride, blim, lim, hev_thr);
-    vp8_loop_filter_vertical_edge_y_neon(y_ptr + 8, y_stride, blim, lim, hev_thr);
-    vp8_loop_filter_vertical_edge_y_neon(y_ptr + 12, y_stride, blim, lim, hev_thr);
-
-    if (u_ptr)
-        vp8_loop_filter_vertical_edge_uv_neon(u_ptr + 4, uv_stride, blim, lim, hev_thr, v_ptr + 4);
-}
-#endif
diff --git a/vp8/common/arm/neon/bilinearpredict_neon.c b/vp8/common/arm/neon/bilinearpredict_neon.c
deleted file mode 100644 (file)
index bb6ea76..0000000
+++ /dev/null
@@ -1,591 +0,0 @@
-/*
- *  Copyright (c) 2014 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.
- */
-
-#include <arm_neon.h>
-
-static const uint8_t bifilter4_coeff[8][2] = {
-    {128,   0},
-    {112,  16},
-    { 96,  32},
-    { 80,  48},
-    { 64,  64},
-    { 48,  80},
-    { 32,  96},
-    { 16, 112}
-};
-
-void vp8_bilinear_predict8x4_neon(
-        unsigned char *src_ptr,
-        int src_pixels_per_line,
-        int xoffset,
-        int yoffset,
-        unsigned char *dst_ptr,
-        int dst_pitch) {
-    uint8x8_t d0u8, d1u8, d2u8, d3u8, d4u8, d5u8;
-    uint8x8_t d7u8, d9u8, d11u8, d22u8, d23u8, d24u8, d25u8, d26u8;
-    uint8x16_t q1u8, q2u8, q3u8, q4u8, q5u8;
-    uint16x8_t q1u16, q2u16, q3u16, q4u16;
-    uint16x8_t q6u16, q7u16, q8u16, q9u16, q10u16;
-
-    if (xoffset == 0) {  // skip_1stpass_filter
-        d22u8 = vld1_u8(src_ptr); src_ptr += src_pixels_per_line;
-        d23u8 = vld1_u8(src_ptr); src_ptr += src_pixels_per_line;
-        d24u8 = vld1_u8(src_ptr); src_ptr += src_pixels_per_line;
-        d25u8 = vld1_u8(src_ptr); src_ptr += src_pixels_per_line;
-        d26u8 = vld1_u8(src_ptr);
-    } else {
-        q1u8 = vld1q_u8(src_ptr); src_ptr += src_pixels_per_line;
-        q2u8 = vld1q_u8(src_ptr); src_ptr += src_pixels_per_line;
-        q3u8 = vld1q_u8(src_ptr); src_ptr += src_pixels_per_line;
-        q4u8 = vld1q_u8(src_ptr); src_ptr += src_pixels_per_line;
-        q5u8 = vld1q_u8(src_ptr);
-
-        d0u8 = vdup_n_u8(bifilter4_coeff[xoffset][0]);
-        d1u8 = vdup_n_u8(bifilter4_coeff[xoffset][1]);
-
-        q6u16 = vmull_u8(vget_low_u8(q1u8), d0u8);
-        q7u16 = vmull_u8(vget_low_u8(q2u8), d0u8);
-        q8u16 = vmull_u8(vget_low_u8(q3u8), d0u8);
-        q9u16 = vmull_u8(vget_low_u8(q4u8), d0u8);
-        q10u16 = vmull_u8(vget_low_u8(q5u8), d0u8);
-
-        d3u8 = vext_u8(vget_low_u8(q1u8), vget_high_u8(q1u8), 1);
-        d5u8 = vext_u8(vget_low_u8(q2u8), vget_high_u8(q2u8), 1);
-        d7u8 = vext_u8(vget_low_u8(q3u8), vget_high_u8(q3u8), 1);
-        d9u8 = vext_u8(vget_low_u8(q4u8), vget_high_u8(q4u8), 1);
-        d11u8 = vext_u8(vget_low_u8(q5u8), vget_high_u8(q5u8), 1);
-
-        q6u16 = vmlal_u8(q6u16, d3u8, d1u8);
-        q7u16 = vmlal_u8(q7u16, d5u8, d1u8);
-        q8u16 = vmlal_u8(q8u16, d7u8, d1u8);
-        q9u16 = vmlal_u8(q9u16, d9u8, d1u8);
-        q10u16 = vmlal_u8(q10u16, d11u8, d1u8);
-
-        d22u8 = vqrshrn_n_u16(q6u16, 7);
-        d23u8 = vqrshrn_n_u16(q7u16, 7);
-        d24u8 = vqrshrn_n_u16(q8u16, 7);
-        d25u8 = vqrshrn_n_u16(q9u16, 7);
-        d26u8 = vqrshrn_n_u16(q10u16, 7);
-    }
-
-    // secondpass_filter
-    if (yoffset == 0) {  // skip_2ndpass_filter
-        vst1_u8((uint8_t *)dst_ptr, d22u8); dst_ptr += dst_pitch;
-        vst1_u8((uint8_t *)dst_ptr, d23u8); dst_ptr += dst_pitch;
-        vst1_u8((uint8_t *)dst_ptr, d24u8); dst_ptr += dst_pitch;
-        vst1_u8((uint8_t *)dst_ptr, d25u8);
-    } else {
-        d0u8 = vdup_n_u8(bifilter4_coeff[yoffset][0]);
-        d1u8 = vdup_n_u8(bifilter4_coeff[yoffset][1]);
-
-        q1u16 = vmull_u8(d22u8, d0u8);
-        q2u16 = vmull_u8(d23u8, d0u8);
-        q3u16 = vmull_u8(d24u8, d0u8);
-        q4u16 = vmull_u8(d25u8, d0u8);
-
-        q1u16 = vmlal_u8(q1u16, d23u8, d1u8);
-        q2u16 = vmlal_u8(q2u16, d24u8, d1u8);
-        q3u16 = vmlal_u8(q3u16, d25u8, d1u8);
-        q4u16 = vmlal_u8(q4u16, d26u8, d1u8);
-
-        d2u8 = vqrshrn_n_u16(q1u16, 7);
-        d3u8 = vqrshrn_n_u16(q2u16, 7);
-        d4u8 = vqrshrn_n_u16(q3u16, 7);
-        d5u8 = vqrshrn_n_u16(q4u16, 7);
-
-        vst1_u8((uint8_t *)dst_ptr, d2u8); dst_ptr += dst_pitch;
-        vst1_u8((uint8_t *)dst_ptr, d3u8); dst_ptr += dst_pitch;
-        vst1_u8((uint8_t *)dst_ptr, d4u8); dst_ptr += dst_pitch;
-        vst1_u8((uint8_t *)dst_ptr, d5u8);
-    }
-    return;
-}
-
-void vp8_bilinear_predict8x8_neon(
-        unsigned char *src_ptr,
-        int src_pixels_per_line,
-        int xoffset,
-        int yoffset,
-        unsigned char *dst_ptr,
-        int dst_pitch) {
-    uint8x8_t d0u8, d1u8, d2u8, d3u8, d4u8, d5u8, d6u8, d7u8, d8u8, d9u8, d11u8;
-    uint8x8_t d22u8, d23u8, d24u8, d25u8, d26u8, d27u8, d28u8, d29u8, d30u8;
-    uint8x16_t q1u8, q2u8, q3u8, q4u8, q5u8;
-    uint16x8_t q1u16, q2u16, q3u16, q4u16, q5u16;
-    uint16x8_t q6u16, q7u16, q8u16, q9u16, q10u16;
-
-    if (xoffset == 0) {  // skip_1stpass_filter
-        d22u8 = vld1_u8(src_ptr); src_ptr += src_pixels_per_line;
-        d23u8 = vld1_u8(src_ptr); src_ptr += src_pixels_per_line;
-        d24u8 = vld1_u8(src_ptr); src_ptr += src_pixels_per_line;
-        d25u8 = vld1_u8(src_ptr); src_ptr += src_pixels_per_line;
-        d26u8 = vld1_u8(src_ptr); src_ptr += src_pixels_per_line;
-        d27u8 = vld1_u8(src_ptr); src_ptr += src_pixels_per_line;
-        d28u8 = vld1_u8(src_ptr); src_ptr += src_pixels_per_line;
-        d29u8 = vld1_u8(src_ptr); src_ptr += src_pixels_per_line;
-        d30u8 = vld1_u8(src_ptr);
-    } else {
-        q1u8 = vld1q_u8(src_ptr); src_ptr += src_pixels_per_line;
-        q2u8 = vld1q_u8(src_ptr); src_ptr += src_pixels_per_line;
-        q3u8 = vld1q_u8(src_ptr); src_ptr += src_pixels_per_line;
-        q4u8 = vld1q_u8(src_ptr); src_ptr += src_pixels_per_line;
-
-        d0u8 = vdup_n_u8(bifilter4_coeff[xoffset][0]);
-        d1u8 = vdup_n_u8(bifilter4_coeff[xoffset][1]);
-
-        q6u16 = vmull_u8(vget_low_u8(q1u8), d0u8);
-        q7u16 = vmull_u8(vget_low_u8(q2u8), d0u8);
-        q8u16 = vmull_u8(vget_low_u8(q3u8), d0u8);
-        q9u16 = vmull_u8(vget_low_u8(q4u8), d0u8);
-
-        d3u8 = vext_u8(vget_low_u8(q1u8), vget_high_u8(q1u8), 1);
-        d5u8 = vext_u8(vget_low_u8(q2u8), vget_high_u8(q2u8), 1);
-        d7u8 = vext_u8(vget_low_u8(q3u8), vget_high_u8(q3u8), 1);
-        d9u8 = vext_u8(vget_low_u8(q4u8), vget_high_u8(q4u8), 1);
-
-        q6u16 = vmlal_u8(q6u16, d3u8, d1u8);
-        q7u16 = vmlal_u8(q7u16, d5u8, d1u8);
-        q8u16 = vmlal_u8(q8u16, d7u8, d1u8);
-        q9u16 = vmlal_u8(q9u16, d9u8, d1u8);
-
-        d22u8 = vqrshrn_n_u16(q6u16, 7);
-        d23u8 = vqrshrn_n_u16(q7u16, 7);
-        d24u8 = vqrshrn_n_u16(q8u16, 7);
-        d25u8 = vqrshrn_n_u16(q9u16, 7);
-
-        // first_pass filtering on the rest 5-line data
-        q1u8 = vld1q_u8(src_ptr); src_ptr += src_pixels_per_line;
-        q2u8 = vld1q_u8(src_ptr); src_ptr += src_pixels_per_line;
-        q3u8 = vld1q_u8(src_ptr); src_ptr += src_pixels_per_line;
-        q4u8 = vld1q_u8(src_ptr); src_ptr += src_pixels_per_line;
-        q5u8 = vld1q_u8(src_ptr);
-
-        q6u16 = vmull_u8(vget_low_u8(q1u8), d0u8);
-        q7u16 = vmull_u8(vget_low_u8(q2u8), d0u8);
-        q8u16 = vmull_u8(vget_low_u8(q3u8), d0u8);
-        q9u16 = vmull_u8(vget_low_u8(q4u8), d0u8);
-        q10u16 = vmull_u8(vget_low_u8(q5u8), d0u8);
-
-        d3u8 = vext_u8(vget_low_u8(q1u8), vget_high_u8(q1u8), 1);
-        d5u8 = vext_u8(vget_low_u8(q2u8), vget_high_u8(q2u8), 1);
-        d7u8 = vext_u8(vget_low_u8(q3u8), vget_high_u8(q3u8), 1);
-        d9u8 = vext_u8(vget_low_u8(q4u8), vget_high_u8(q4u8), 1);
-        d11u8 = vext_u8(vget_low_u8(q5u8), vget_high_u8(q5u8), 1);
-
-        q6u16 = vmlal_u8(q6u16, d3u8, d1u8);
-        q7u16 = vmlal_u8(q7u16, d5u8, d1u8);
-        q8u16 = vmlal_u8(q8u16, d7u8, d1u8);
-        q9u16 = vmlal_u8(q9u16, d9u8, d1u8);
-        q10u16 = vmlal_u8(q10u16, d11u8, d1u8);
-
-        d26u8 = vqrshrn_n_u16(q6u16, 7);
-        d27u8 = vqrshrn_n_u16(q7u16, 7);
-        d28u8 = vqrshrn_n_u16(q8u16, 7);
-        d29u8 = vqrshrn_n_u16(q9u16, 7);
-        d30u8 = vqrshrn_n_u16(q10u16, 7);
-    }
-
-    // secondpass_filter
-    if (yoffset == 0) {  // skip_2ndpass_filter
-        vst1_u8((uint8_t *)dst_ptr, d22u8); dst_ptr += dst_pitch;
-        vst1_u8((uint8_t *)dst_ptr, d23u8); dst_ptr += dst_pitch;
-        vst1_u8((uint8_t *)dst_ptr, d24u8); dst_ptr += dst_pitch;
-        vst1_u8((uint8_t *)dst_ptr, d25u8); dst_ptr += dst_pitch;
-        vst1_u8((uint8_t *)dst_ptr, d26u8); dst_ptr += dst_pitch;
-        vst1_u8((uint8_t *)dst_ptr, d27u8); dst_ptr += dst_pitch;
-        vst1_u8((uint8_t *)dst_ptr, d28u8); dst_ptr += dst_pitch;
-        vst1_u8((uint8_t *)dst_ptr, d29u8);
-    } else {
-        d0u8 = vdup_n_u8(bifilter4_coeff[yoffset][0]);
-        d1u8 = vdup_n_u8(bifilter4_coeff[yoffset][1]);
-
-        q1u16 = vmull_u8(d22u8, d0u8);
-        q2u16 = vmull_u8(d23u8, d0u8);
-        q3u16 = vmull_u8(d24u8, d0u8);
-        q4u16 = vmull_u8(d25u8, d0u8);
-        q5u16 = vmull_u8(d26u8, d0u8);
-        q6u16 = vmull_u8(d27u8, d0u8);
-        q7u16 = vmull_u8(d28u8, d0u8);
-        q8u16 = vmull_u8(d29u8, d0u8);
-
-        q1u16 = vmlal_u8(q1u16, d23u8, d1u8);
-        q2u16 = vmlal_u8(q2u16, d24u8, d1u8);
-        q3u16 = vmlal_u8(q3u16, d25u8, d1u8);
-        q4u16 = vmlal_u8(q4u16, d26u8, d1u8);
-        q5u16 = vmlal_u8(q5u16, d27u8, d1u8);
-        q6u16 = vmlal_u8(q6u16, d28u8, d1u8);
-        q7u16 = vmlal_u8(q7u16, d29u8, d1u8);
-        q8u16 = vmlal_u8(q8u16, d30u8, d1u8);
-
-        d2u8 = vqrshrn_n_u16(q1u16, 7);
-        d3u8 = vqrshrn_n_u16(q2u16, 7);
-        d4u8 = vqrshrn_n_u16(q3u16, 7);
-        d5u8 = vqrshrn_n_u16(q4u16, 7);
-        d6u8 = vqrshrn_n_u16(q5u16, 7);
-        d7u8 = vqrshrn_n_u16(q6u16, 7);
-        d8u8 = vqrshrn_n_u16(q7u16, 7);
-        d9u8 = vqrshrn_n_u16(q8u16, 7);
-
-        vst1_u8((uint8_t *)dst_ptr, d2u8); dst_ptr += dst_pitch;
-        vst1_u8((uint8_t *)dst_ptr, d3u8); dst_ptr += dst_pitch;
-        vst1_u8((uint8_t *)dst_ptr, d4u8); dst_ptr += dst_pitch;
-        vst1_u8((uint8_t *)dst_ptr, d5u8); dst_ptr += dst_pitch;
-        vst1_u8((uint8_t *)dst_ptr, d6u8); dst_ptr += dst_pitch;
-        vst1_u8((uint8_t *)dst_ptr, d7u8); dst_ptr += dst_pitch;
-        vst1_u8((uint8_t *)dst_ptr, d8u8); dst_ptr += dst_pitch;
-        vst1_u8((uint8_t *)dst_ptr, d9u8);
-    }
-    return;
-}
-
-void vp8_bilinear_predict16x16_neon(
-        unsigned char *src_ptr,
-        int src_pixels_per_line,
-        int xoffset,
-        int yoffset,
-        unsigned char *dst_ptr,
-        int dst_pitch) {
-    int i;
-    unsigned char tmp[272];
-    unsigned char *tmpp;
-    uint8x8_t d0u8, d1u8, d2u8, d3u8, d4u8, d5u8, d6u8, d7u8, d8u8, d9u8;
-    uint8x8_t d10u8, d11u8, d12u8, d13u8, d14u8, d15u8, d16u8, d17u8, d18u8;
-    uint8x8_t d19u8, d20u8, d21u8;
-    uint8x16_t q1u8, q2u8, q3u8, q4u8, q5u8, q6u8, q7u8, q8u8, q9u8, q10u8;
-    uint8x16_t q11u8, q12u8, q13u8, q14u8, q15u8;
-    uint16x8_t q1u16, q2u16, q3u16, q4u16, q5u16, q6u16, q7u16, q8u16;
-    uint16x8_t q9u16, q10u16, q11u16, q12u16, q13u16, q14u16;
-
-    if (xoffset == 0) {  // secondpass_bfilter16x16_only
-        d0u8 = vdup_n_u8(bifilter4_coeff[yoffset][0]);
-        d1u8 = vdup_n_u8(bifilter4_coeff[yoffset][1]);
-
-        q11u8 = vld1q_u8(src_ptr);
-        src_ptr += src_pixels_per_line;
-        for (i = 4; i > 0; i--) {
-            q12u8 = vld1q_u8(src_ptr); src_ptr += src_pixels_per_line;
-            q13u8 = vld1q_u8(src_ptr); src_ptr += src_pixels_per_line;
-            q14u8 = vld1q_u8(src_ptr); src_ptr += src_pixels_per_line;
-            q15u8 = vld1q_u8(src_ptr); src_ptr += src_pixels_per_line;
-
-            q1u16 = vmull_u8(vget_low_u8(q11u8), d0u8);
-            q2u16 = vmull_u8(vget_high_u8(q11u8), d0u8);
-            q3u16 = vmull_u8(vget_low_u8(q12u8), d0u8);
-            q4u16 = vmull_u8(vget_high_u8(q12u8), d0u8);
-            q5u16 = vmull_u8(vget_low_u8(q13u8), d0u8);
-            q6u16 = vmull_u8(vget_high_u8(q13u8), d0u8);
-            q7u16 = vmull_u8(vget_low_u8(q14u8), d0u8);
-            q8u16 = vmull_u8(vget_high_u8(q14u8), d0u8);
-
-            q1u16 = vmlal_u8(q1u16, vget_low_u8(q12u8), d1u8);
-            q2u16 = vmlal_u8(q2u16, vget_high_u8(q12u8), d1u8);
-            q3u16 = vmlal_u8(q3u16, vget_low_u8(q13u8), d1u8);
-            q4u16 = vmlal_u8(q4u16, vget_high_u8(q13u8), d1u8);
-            q5u16 = vmlal_u8(q5u16, vget_low_u8(q14u8), d1u8);
-            q6u16 = vmlal_u8(q6u16, vget_high_u8(q14u8), d1u8);
-            q7u16 = vmlal_u8(q7u16, vget_low_u8(q15u8), d1u8);
-            q8u16 = vmlal_u8(q8u16, vget_high_u8(q15u8), d1u8);
-
-            d2u8 = vqrshrn_n_u16(q1u16, 7);
-            d3u8 = vqrshrn_n_u16(q2u16, 7);
-            d4u8 = vqrshrn_n_u16(q3u16, 7);
-            d5u8 = vqrshrn_n_u16(q4u16, 7);
-            d6u8 = vqrshrn_n_u16(q5u16, 7);
-            d7u8 = vqrshrn_n_u16(q6u16, 7);
-            d8u8 = vqrshrn_n_u16(q7u16, 7);
-            d9u8 = vqrshrn_n_u16(q8u16, 7);
-
-            q1u8 = vcombine_u8(d2u8, d3u8);
-            q2u8 = vcombine_u8(d4u8, d5u8);
-            q3u8 = vcombine_u8(d6u8, d7u8);
-            q4u8 = vcombine_u8(d8u8, d9u8);
-
-            q11u8 = q15u8;
-
-            vst1q_u8((uint8_t *)dst_ptr, q1u8); dst_ptr += dst_pitch;
-            vst1q_u8((uint8_t *)dst_ptr, q2u8); dst_ptr += dst_pitch;
-            vst1q_u8((uint8_t *)dst_ptr, q3u8); dst_ptr += dst_pitch;
-            vst1q_u8((uint8_t *)dst_ptr, q4u8); dst_ptr += dst_pitch;
-        }
-        return;
-    }
-
-    if (yoffset == 0) {  // firstpass_bfilter16x16_only
-        d0u8 = vdup_n_u8(bifilter4_coeff[xoffset][0]);
-        d1u8 = vdup_n_u8(bifilter4_coeff[xoffset][1]);
-
-        for (i = 4; i > 0 ; i--) {
-            d2u8 = vld1_u8(src_ptr);
-            d3u8 = vld1_u8(src_ptr + 8);
-            d4u8 = vld1_u8(src_ptr + 16); src_ptr += src_pixels_per_line;
-            d5u8 = vld1_u8(src_ptr);
-            d6u8 = vld1_u8(src_ptr + 8);
-            d7u8 = vld1_u8(src_ptr + 16); src_ptr += src_pixels_per_line;
-            d8u8 = vld1_u8(src_ptr);
-            d9u8 = vld1_u8(src_ptr + 8);
-            d10u8 = vld1_u8(src_ptr + 16); src_ptr += src_pixels_per_line;
-            d11u8 = vld1_u8(src_ptr);
-            d12u8 = vld1_u8(src_ptr + 8);
-            d13u8 = vld1_u8(src_ptr + 16); src_ptr += src_pixels_per_line;
-
-            q7u16  = vmull_u8(d2u8, d0u8);
-            q8u16  = vmull_u8(d3u8, d0u8);
-            q9u16  = vmull_u8(d5u8, d0u8);
-            q10u16 = vmull_u8(d6u8, d0u8);
-            q11u16 = vmull_u8(d8u8, d0u8);
-            q12u16 = vmull_u8(d9u8, d0u8);
-            q13u16 = vmull_u8(d11u8, d0u8);
-            q14u16 = vmull_u8(d12u8, d0u8);
-
-            d2u8  = vext_u8(d2u8, d3u8, 1);
-            d5u8  = vext_u8(d5u8, d6u8, 1);
-            d8u8  = vext_u8(d8u8, d9u8, 1);
-            d11u8 = vext_u8(d11u8, d12u8, 1);
-
-            q7u16  = vmlal_u8(q7u16, d2u8, d1u8);
-            q9u16  = vmlal_u8(q9u16, d5u8, d1u8);
-            q11u16 = vmlal_u8(q11u16, d8u8, d1u8);
-            q13u16 = vmlal_u8(q13u16, d11u8, d1u8);
-
-            d3u8  = vext_u8(d3u8, d4u8, 1);
-            d6u8  = vext_u8(d6u8, d7u8, 1);
-            d9u8  = vext_u8(d9u8, d10u8, 1);
-            d12u8 = vext_u8(d12u8, d13u8, 1);
-
-            q8u16  = vmlal_u8(q8u16,  d3u8, d1u8);
-            q10u16 = vmlal_u8(q10u16, d6u8, d1u8);
-            q12u16 = vmlal_u8(q12u16, d9u8, d1u8);
-            q14u16 = vmlal_u8(q14u16, d12u8, d1u8);
-
-            d14u8 = vqrshrn_n_u16(q7u16, 7);
-            d15u8 = vqrshrn_n_u16(q8u16, 7);
-            d16u8 = vqrshrn_n_u16(q9u16, 7);
-            d17u8 = vqrshrn_n_u16(q10u16, 7);
-            d18u8 = vqrshrn_n_u16(q11u16, 7);
-            d19u8 = vqrshrn_n_u16(q12u16, 7);
-            d20u8 = vqrshrn_n_u16(q13u16, 7);
-            d21u8 = vqrshrn_n_u16(q14u16, 7);
-
-            q7u8 = vcombine_u8(d14u8, d15u8);
-            q8u8 = vcombine_u8(d16u8, d17u8);
-            q9u8 = vcombine_u8(d18u8, d19u8);
-            q10u8 =vcombine_u8(d20u8, d21u8);
-
-            vst1q_u8((uint8_t *)dst_ptr, q7u8); dst_ptr += dst_pitch;
-            vst1q_u8((uint8_t *)dst_ptr, q8u8); dst_ptr += dst_pitch;
-            vst1q_u8((uint8_t *)dst_ptr, q9u8); dst_ptr += dst_pitch;
-            vst1q_u8((uint8_t *)dst_ptr, q10u8); dst_ptr += dst_pitch;
-        }
-        return;
-    }
-
-    d0u8 = vdup_n_u8(bifilter4_coeff[xoffset][0]);
-    d1u8 = vdup_n_u8(bifilter4_coeff[xoffset][1]);
-
-    d2u8 = vld1_u8(src_ptr);
-    d3u8 = vld1_u8(src_ptr + 8);
-    d4u8 = vld1_u8(src_ptr + 16); src_ptr += src_pixels_per_line;
-    d5u8 = vld1_u8(src_ptr);
-    d6u8 = vld1_u8(src_ptr + 8);
-    d7u8 = vld1_u8(src_ptr + 16); src_ptr += src_pixels_per_line;
-    d8u8 = vld1_u8(src_ptr);
-    d9u8 = vld1_u8(src_ptr + 8);
-    d10u8 = vld1_u8(src_ptr + 16); src_ptr += src_pixels_per_line;
-    d11u8 = vld1_u8(src_ptr);
-    d12u8 = vld1_u8(src_ptr + 8);
-    d13u8 = vld1_u8(src_ptr + 16); src_ptr += src_pixels_per_line;
-
-    // First Pass: output_height lines x output_width columns (17x16)
-    tmpp = tmp;
-    for (i = 3; i > 0; i--) {
-        q7u16  = vmull_u8(d2u8, d0u8);
-        q8u16  = vmull_u8(d3u8, d0u8);
-        q9u16  = vmull_u8(d5u8, d0u8);
-        q10u16 = vmull_u8(d6u8, d0u8);
-        q11u16 = vmull_u8(d8u8, d0u8);
-        q12u16 = vmull_u8(d9u8, d0u8);
-        q13u16 = vmull_u8(d11u8, d0u8);
-        q14u16 = vmull_u8(d12u8, d0u8);
-
-        d2u8  = vext_u8(d2u8, d3u8, 1);
-        d5u8  = vext_u8(d5u8, d6u8, 1);
-        d8u8  = vext_u8(d8u8, d9u8, 1);
-        d11u8 = vext_u8(d11u8, d12u8, 1);
-
-        q7u16  = vmlal_u8(q7u16, d2u8, d1u8);
-        q9u16  = vmlal_u8(q9u16, d5u8, d1u8);
-        q11u16 = vmlal_u8(q11u16, d8u8, d1u8);
-        q13u16 = vmlal_u8(q13u16, d11u8, d1u8);
-
-        d3u8  = vext_u8(d3u8, d4u8, 1);
-        d6u8  = vext_u8(d6u8, d7u8, 1);
-        d9u8  = vext_u8(d9u8, d10u8, 1);
-        d12u8 = vext_u8(d12u8, d13u8, 1);
-
-        q8u16  = vmlal_u8(q8u16,  d3u8, d1u8);
-        q10u16 = vmlal_u8(q10u16, d6u8, d1u8);
-        q12u16 = vmlal_u8(q12u16, d9u8, d1u8);
-        q14u16 = vmlal_u8(q14u16, d12u8, d1u8);
-
-        d14u8 = vqrshrn_n_u16(q7u16, 7);
-        d15u8 = vqrshrn_n_u16(q8u16, 7);
-        d16u8 = vqrshrn_n_u16(q9u16, 7);
-        d17u8 = vqrshrn_n_u16(q10u16, 7);
-        d18u8 = vqrshrn_n_u16(q11u16, 7);
-        d19u8 = vqrshrn_n_u16(q12u16, 7);
-        d20u8 = vqrshrn_n_u16(q13u16, 7);
-        d21u8 = vqrshrn_n_u16(q14u16, 7);
-
-        d2u8 = vld1_u8(src_ptr);
-        d3u8 = vld1_u8(src_ptr + 8);
-        d4u8 = vld1_u8(src_ptr + 16); src_ptr += src_pixels_per_line;
-        d5u8 = vld1_u8(src_ptr);
-        d6u8 = vld1_u8(src_ptr + 8);
-        d7u8 = vld1_u8(src_ptr + 16); src_ptr += src_pixels_per_line;
-        d8u8 = vld1_u8(src_ptr);
-        d9u8 = vld1_u8(src_ptr + 8);
-        d10u8 = vld1_u8(src_ptr + 16); src_ptr += src_pixels_per_line;
-        d11u8 = vld1_u8(src_ptr);
-        d12u8 = vld1_u8(src_ptr + 8);
-        d13u8 = vld1_u8(src_ptr + 16); src_ptr += src_pixels_per_line;
-
-        q7u8 = vcombine_u8(d14u8, d15u8);
-        q8u8 = vcombine_u8(d16u8, d17u8);
-        q9u8 = vcombine_u8(d18u8, d19u8);
-        q10u8 = vcombine_u8(d20u8, d21u8);
-
-        vst1q_u8((uint8_t *)tmpp, q7u8); tmpp += 16;
-        vst1q_u8((uint8_t *)tmpp, q8u8); tmpp += 16;
-        vst1q_u8((uint8_t *)tmpp, q9u8); tmpp += 16;
-        vst1q_u8((uint8_t *)tmpp, q10u8); tmpp += 16;
-    }
-
-    // First-pass filtering for rest 5 lines
-    d14u8 = vld1_u8(src_ptr);
-    d15u8 = vld1_u8(src_ptr + 8);
-    d16u8 = vld1_u8(src_ptr + 16); src_ptr += src_pixels_per_line;
-
-    q9u16  = vmull_u8(d2u8, d0u8);
-    q10u16 = vmull_u8(d3u8, d0u8);
-    q11u16 = vmull_u8(d5u8, d0u8);
-    q12u16 = vmull_u8(d6u8, d0u8);
-    q13u16 = vmull_u8(d8u8, d0u8);
-    q14u16 = vmull_u8(d9u8, d0u8);
-
-    d2u8  = vext_u8(d2u8, d3u8, 1);
-    d5u8  = vext_u8(d5u8, d6u8, 1);
-    d8u8  = vext_u8(d8u8, d9u8, 1);
-
-    q9u16  = vmlal_u8(q9u16, d2u8, d1u8);
-    q11u16 = vmlal_u8(q11u16, d5u8, d1u8);
-    q13u16 = vmlal_u8(q13u16, d8u8, d1u8);
-
-    d3u8  = vext_u8(d3u8, d4u8, 1);
-    d6u8  = vext_u8(d6u8, d7u8, 1);
-    d9u8  = vext_u8(d9u8, d10u8, 1);
-
-    q10u16 = vmlal_u8(q10u16, d3u8, d1u8);
-    q12u16 = vmlal_u8(q12u16, d6u8, d1u8);
-    q14u16 = vmlal_u8(q14u16, d9u8, d1u8);
-
-    q1u16 = vmull_u8(d11u8, d0u8);
-    q2u16 = vmull_u8(d12u8, d0u8);
-    q3u16 = vmull_u8(d14u8, d0u8);
-    q4u16 = vmull_u8(d15u8, d0u8);
-
-    d11u8 = vext_u8(d11u8, d12u8, 1);
-    d14u8 = vext_u8(d14u8, d15u8, 1);
-
-    q1u16 = vmlal_u8(q1u16, d11u8, d1u8);
-    q3u16 = vmlal_u8(q3u16, d14u8, d1u8);
-
-    d12u8 = vext_u8(d12u8, d13u8, 1);
-    d15u8 = vext_u8(d15u8, d16u8, 1);
-
-    q2u16 = vmlal_u8(q2u16, d12u8, d1u8);
-    q4u16 = vmlal_u8(q4u16, d15u8, d1u8);
-
-    d10u8 = vqrshrn_n_u16(q9u16, 7);
-    d11u8 = vqrshrn_n_u16(q10u16, 7);
-    d12u8 = vqrshrn_n_u16(q11u16, 7);
-    d13u8 = vqrshrn_n_u16(q12u16, 7);
-    d14u8 = vqrshrn_n_u16(q13u16, 7);
-    d15u8 = vqrshrn_n_u16(q14u16, 7);
-    d16u8 = vqrshrn_n_u16(q1u16, 7);
-    d17u8 = vqrshrn_n_u16(q2u16, 7);
-    d18u8 = vqrshrn_n_u16(q3u16, 7);
-    d19u8 = vqrshrn_n_u16(q4u16, 7);
-
-    q5u8 = vcombine_u8(d10u8, d11u8);
-    q6u8 = vcombine_u8(d12u8, d13u8);
-    q7u8 = vcombine_u8(d14u8, d15u8);
-    q8u8 = vcombine_u8(d16u8, d17u8);
-    q9u8 = vcombine_u8(d18u8, d19u8);
-
-    vst1q_u8((uint8_t *)tmpp, q5u8); tmpp += 16;
-    vst1q_u8((uint8_t *)tmpp, q6u8); tmpp += 16;
-    vst1q_u8((uint8_t *)tmpp, q7u8); tmpp += 16;
-    vst1q_u8((uint8_t *)tmpp, q8u8); tmpp += 16;
-    vst1q_u8((uint8_t *)tmpp, q9u8);
-
-    // secondpass_filter
-    d0u8 = vdup_n_u8(bifilter4_coeff[yoffset][0]);
-    d1u8 = vdup_n_u8(bifilter4_coeff[yoffset][1]);
-
-    tmpp = tmp;
-    q11u8 = vld1q_u8(tmpp);
-    tmpp += 16;
-    for (i = 4; i > 0; i--) {
-        q12u8 = vld1q_u8(tmpp); tmpp += 16;
-        q13u8 = vld1q_u8(tmpp); tmpp += 16;
-        q14u8 = vld1q_u8(tmpp); tmpp += 16;
-        q15u8 = vld1q_u8(tmpp); tmpp += 16;
-
-        q1u16 = vmull_u8(vget_low_u8(q11u8), d0u8);
-        q2u16 = vmull_u8(vget_high_u8(q11u8), d0u8);
-        q3u16 = vmull_u8(vget_low_u8(q12u8), d0u8);
-        q4u16 = vmull_u8(vget_high_u8(q12u8), d0u8);
-        q5u16 = vmull_u8(vget_low_u8(q13u8), d0u8);
-        q6u16 = vmull_u8(vget_high_u8(q13u8), d0u8);
-        q7u16 = vmull_u8(vget_low_u8(q14u8), d0u8);
-        q8u16 = vmull_u8(vget_high_u8(q14u8), d0u8);
-
-        q1u16 = vmlal_u8(q1u16, vget_low_u8(q12u8), d1u8);
-        q2u16 = vmlal_u8(q2u16, vget_high_u8(q12u8), d1u8);
-        q3u16 = vmlal_u8(q3u16, vget_low_u8(q13u8), d1u8);
-        q4u16 = vmlal_u8(q4u16, vget_high_u8(q13u8), d1u8);
-        q5u16 = vmlal_u8(q5u16, vget_low_u8(q14u8), d1u8);
-        q6u16 = vmlal_u8(q6u16, vget_high_u8(q14u8), d1u8);
-        q7u16 = vmlal_u8(q7u16, vget_low_u8(q15u8), d1u8);
-        q8u16 = vmlal_u8(q8u16, vget_high_u8(q15u8), d1u8);
-
-        d2u8 = vqrshrn_n_u16(q1u16, 7);
-        d3u8 = vqrshrn_n_u16(q2u16, 7);
-        d4u8 = vqrshrn_n_u16(q3u16, 7);
-        d5u8 = vqrshrn_n_u16(q4u16, 7);
-        d6u8 = vqrshrn_n_u16(q5u16, 7);
-        d7u8 = vqrshrn_n_u16(q6u16, 7);
-        d8u8 = vqrshrn_n_u16(q7u16, 7);
-        d9u8 = vqrshrn_n_u16(q8u16, 7);
-
-        q1u8 = vcombine_u8(d2u8, d3u8);
-        q2u8 = vcombine_u8(d4u8, d5u8);
-        q3u8 = vcombine_u8(d6u8, d7u8);
-        q4u8 = vcombine_u8(d8u8, d9u8);
-
-        q11u8 = q15u8;
-
-        vst1q_u8((uint8_t *)dst_ptr, q1u8); dst_ptr += dst_pitch;
-        vst1q_u8((uint8_t *)dst_ptr, q2u8); dst_ptr += dst_pitch;
-        vst1q_u8((uint8_t *)dst_ptr, q3u8); dst_ptr += dst_pitch;
-        vst1q_u8((uint8_t *)dst_ptr, q4u8); dst_ptr += dst_pitch;
-    }
-    return;
-}
diff --git a/vp8/common/arm/neon/copymem_neon.c b/vp8/common/arm/neon/copymem_neon.c
deleted file mode 100644 (file)
index deced11..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- *  Copyright (c) 2014 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.
- */
-
-#include <arm_neon.h>
-
-void vp8_copy_mem8x4_neon(
-        unsigned char *src,
-        int src_stride,
-        unsigned char *dst,
-        int dst_stride) {
-    uint8x8_t vtmp;
-    int r;
-
-    for (r = 0; r < 4; r++) {
-        vtmp = vld1_u8(src);
-        vst1_u8(dst, vtmp);
-        src += src_stride;
-        dst += dst_stride;
-    }
-}
-
-void vp8_copy_mem8x8_neon(
-        unsigned char *src,
-        int src_stride,
-        unsigned char *dst,
-        int dst_stride) {
-    uint8x8_t vtmp;
-    int r;
-
-    for (r = 0; r < 8; r++) {
-        vtmp = vld1_u8(src);
-        vst1_u8(dst, vtmp);
-        src += src_stride;
-        dst += dst_stride;
-    }
-}
-
-void vp8_copy_mem16x16_neon(
-        unsigned char *src,
-        int src_stride,
-        unsigned char *dst,
-        int dst_stride) {
-    int r;
-    uint8x16_t qtmp;
-
-    for (r = 0; r < 16; r++) {
-        qtmp = vld1q_u8(src);
-        vst1q_u8(dst, qtmp);
-        src += src_stride;
-        dst += dst_stride;
-    }
-}
diff --git a/vp8/common/arm/neon/dc_only_idct_add_neon.c b/vp8/common/arm/neon/dc_only_idct_add_neon.c
deleted file mode 100644 (file)
index ad5f41d..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- *  Copyright (c) 2014 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.
- */
-
-#include <arm_neon.h>
-
-void vp8_dc_only_idct_add_neon(
-        int16_t input_dc,
-        unsigned char *pred_ptr,
-        int pred_stride,
-        unsigned char *dst_ptr,
-        int dst_stride) {
-    int i;
-    uint16_t a1 = ((input_dc + 4) >> 3);
-    uint32x2_t d2u32 = vdup_n_u32(0);
-    uint8x8_t d2u8;
-    uint16x8_t q1u16;
-    uint16x8_t qAdd;
-
-    qAdd = vdupq_n_u16(a1);
-
-    for (i = 0; i < 2; i++) {
-        d2u32 = vld1_lane_u32((const uint32_t *)pred_ptr, d2u32, 0);
-        pred_ptr += pred_stride;
-        d2u32 = vld1_lane_u32((const uint32_t *)pred_ptr, d2u32, 1);
-        pred_ptr += pred_stride;
-
-        q1u16 = vaddw_u8(qAdd, vreinterpret_u8_u32(d2u32));
-        d2u8 = vqmovun_s16(vreinterpretq_s16_u16(q1u16));
-
-        vst1_lane_u32((uint32_t *)dst_ptr, vreinterpret_u32_u8(d2u8), 0);
-        dst_ptr += dst_stride;
-        vst1_lane_u32((uint32_t *)dst_ptr, vreinterpret_u32_u8(d2u8), 1);
-        dst_ptr += dst_stride;
-    }
-}
diff --git a/vp8/common/arm/neon/dequant_idct_neon.c b/vp8/common/arm/neon/dequant_idct_neon.c
deleted file mode 100644 (file)
index 58e1192..0000000
+++ /dev/null
@@ -1,142 +0,0 @@
-/*
- *  Copyright (c) 2014 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.
- */
-
-#include <arm_neon.h>
-
-static const int16_t cospi8sqrt2minus1 = 20091;
-static const int16_t sinpi8sqrt2       = 35468;
-
-void vp8_dequant_idct_add_neon(
-        int16_t *input,
-        int16_t *dq,
-        unsigned char *dst,
-        int stride) {
-    unsigned char *dst0;
-    int32x2_t d14, d15;
-    int16x4_t d2, d3, d4, d5, d10, d11, d12, d13;
-    int16x8_t q1, q2, q3, q4, q5, q6;
-    int16x8_t qEmpty = vdupq_n_s16(0);
-    int32x2x2_t d2tmp0, d2tmp1;
-    int16x4x2_t d2tmp2, d2tmp3;
-
-    d14 = d15 = vdup_n_s32(0);
-
-    // load input
-    q3 = vld1q_s16(input);
-    vst1q_s16(input, qEmpty);
-    input += 8;
-    q4 = vld1q_s16(input);
-    vst1q_s16(input, qEmpty);
-
-    // load dq
-    q5 = vld1q_s16(dq);
-    dq += 8;
-    q6 = vld1q_s16(dq);
-
-    // load src from dst
-    dst0 = dst;
-    d14 = vld1_lane_s32((const int32_t *)dst0, d14, 0);
-    dst0 += stride;
-    d14 = vld1_lane_s32((const int32_t *)dst0, d14, 1);
-    dst0 += stride;
-    d15 = vld1_lane_s32((const int32_t *)dst0, d15, 0);
-    dst0 += stride;
-    d15 = vld1_lane_s32((const int32_t *)dst0, d15, 1);
-
-    q1 = vreinterpretq_s16_u16(vmulq_u16(vreinterpretq_u16_s16(q3),
-                                         vreinterpretq_u16_s16(q5)));
-    q2 = vreinterpretq_s16_u16(vmulq_u16(vreinterpretq_u16_s16(q4),
-                                         vreinterpretq_u16_s16(q6)));
-
-    d12 = vqadd_s16(vget_low_s16(q1), vget_low_s16(q2));
-    d13 = vqsub_s16(vget_low_s16(q1), vget_low_s16(q2));
-
-    q2 = vcombine_s16(vget_high_s16(q1), vget_high_s16(q2));
-
-    q3 = vqdmulhq_n_s16(q2, sinpi8sqrt2);
-    q4 = vqdmulhq_n_s16(q2, cospi8sqrt2minus1);
-
-    q3 = vshrq_n_s16(q3, 1);
-    q4 = vshrq_n_s16(q4, 1);
-
-    q3 = vqaddq_s16(q3, q2);
-    q4 = vqaddq_s16(q4, q2);
-
-    d10 = vqsub_s16(vget_low_s16(q3), vget_high_s16(q4));
-    d11 = vqadd_s16(vget_high_s16(q3), vget_low_s16(q4));
-
-    d2 = vqadd_s16(d12, d11);
-    d3 = vqadd_s16(d13, d10);
-    d4 = vqsub_s16(d13, d10);
-    d5 = vqsub_s16(d12, d11);
-
-    d2tmp0 = vtrn_s32(vreinterpret_s32_s16(d2), vreinterpret_s32_s16(d4));
-    d2tmp1 = vtrn_s32(vreinterpret_s32_s16(d3), vreinterpret_s32_s16(d5));
-    d2tmp2 = vtrn_s16(vreinterpret_s16_s32(d2tmp0.val[0]),
-                      vreinterpret_s16_s32(d2tmp1.val[0]));
-    d2tmp3 = vtrn_s16(vreinterpret_s16_s32(d2tmp0.val[1]),
-                      vreinterpret_s16_s32(d2tmp1.val[1]));
-
-    // loop 2
-    q2 = vcombine_s16(d2tmp2.val[1], d2tmp3.val[1]);
-
-    q3 = vqdmulhq_n_s16(q2, sinpi8sqrt2);
-    q4 = vqdmulhq_n_s16(q2, cospi8sqrt2minus1);
-
-    d12 = vqadd_s16(d2tmp2.val[0], d2tmp3.val[0]);
-    d13 = vqsub_s16(d2tmp2.val[0], d2tmp3.val[0]);
-
-    q3 = vshrq_n_s16(q3, 1);
-    q4 = vshrq_n_s16(q4, 1);
-
-    q3 = vqaddq_s16(q3, q2);
-    q4 = vqaddq_s16(q4, q2);
-
-    d10 = vqsub_s16(vget_low_s16(q3), vget_high_s16(q4));
-    d11 = vqadd_s16(vget_high_s16(q3), vget_low_s16(q4));
-
-    d2 = vqadd_s16(d12, d11);
-    d3 = vqadd_s16(d13, d10);
-    d4 = vqsub_s16(d13, d10);
-    d5 = vqsub_s16(d12, d11);
-
-    d2 = vrshr_n_s16(d2, 3);
-    d3 = vrshr_n_s16(d3, 3);
-    d4 = vrshr_n_s16(d4, 3);
-    d5 = vrshr_n_s16(d5, 3);
-
-    d2tmp0 = vtrn_s32(vreinterpret_s32_s16(d2), vreinterpret_s32_s16(d4));
-    d2tmp1 = vtrn_s32(vreinterpret_s32_s16(d3), vreinterpret_s32_s16(d5));
-    d2tmp2 = vtrn_s16(vreinterpret_s16_s32(d2tmp0.val[0]),
-                      vreinterpret_s16_s32(d2tmp1.val[0]));
-    d2tmp3 = vtrn_s16(vreinterpret_s16_s32(d2tmp0.val[1]),
-                      vreinterpret_s16_s32(d2tmp1.val[1]));
-
-    q1 = vcombine_s16(d2tmp2.val[0], d2tmp2.val[1]);
-    q2 = vcombine_s16(d2tmp3.val[0], d2tmp3.val[1]);
-
-    q1 = vreinterpretq_s16_u16(vaddw_u8(vreinterpretq_u16_s16(q1),
-                                        vreinterpret_u8_s32(d14)));
-    q2 = vreinterpretq_s16_u16(vaddw_u8(vreinterpretq_u16_s16(q2),
-                                        vreinterpret_u8_s32(d15)));
-
-    d14 = vreinterpret_s32_u8(vqmovun_s16(q1));
-    d15 = vreinterpret_s32_u8(vqmovun_s16(q2));
-
-    dst0 = dst;
-    vst1_lane_s32((int32_t *)dst0, d14, 0);
-    dst0 += stride;
-    vst1_lane_s32((int32_t *)dst0, d14, 1);
-    dst0 += stride;
-    vst1_lane_s32((int32_t *)dst0, d15, 0);
-    dst0 += stride;
-    vst1_lane_s32((int32_t *)dst0, d15, 1);
-    return;
-}
diff --git a/vp8/common/arm/neon/dequantizeb_neon.c b/vp8/common/arm/neon/dequantizeb_neon.c
deleted file mode 100644 (file)
index 54e709d..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- *  Copyright (c) 2014 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.
- */
-
-#include <arm_neon.h>
-
-#include "vp8/common/blockd.h"
-
-void vp8_dequantize_b_neon(BLOCKD *d, short *DQC) {
-    int16x8x2_t qQ, qDQC, qDQ;
-
-    qQ   = vld2q_s16(d->qcoeff);
-    qDQC = vld2q_s16(DQC);
-
-    qDQ.val[0] = vmulq_s16(qQ.val[0], qDQC.val[0]);
-    qDQ.val[1] = vmulq_s16(qQ.val[1], qDQC.val[1]);
-
-    vst2q_s16(d->dqcoeff, qDQ);
-}
diff --git a/vp8/common/arm/neon/idct_blk_neon.c b/vp8/common/arm/neon/idct_blk_neon.c
deleted file mode 100644 (file)
index fb327a7..0000000
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#include "vpx_config.h"
-#include "vp8_rtcd.h"
-
-/* place these declarations here because we don't want to maintain them
- * outside of this scope
- */
-void idct_dequant_full_2x_neon(short *q, short *dq,
-                               unsigned char *dst, int stride);
-void idct_dequant_0_2x_neon(short *q, short dq,
-                            unsigned char *dst, int stride);
-
-
-void vp8_dequant_idct_add_y_block_neon(short *q, short *dq,
-                                       unsigned char *dst,
-                                       int stride, char *eobs)
-{
-    int i;
-
-    for (i = 0; i < 4; i++)
-    {
-        if (((short *)(eobs))[0])
-        {
-            if (((short *)eobs)[0] & 0xfefe)
-                idct_dequant_full_2x_neon (q, dq, dst, stride);
-            else
-                idct_dequant_0_2x_neon (q, dq[0], dst, stride);
-        }
-
-        if (((short *)(eobs))[1])
-        {
-            if (((short *)eobs)[1] & 0xfefe)
-                idct_dequant_full_2x_neon (q+32, dq, dst+8, stride);
-            else
-                idct_dequant_0_2x_neon (q+32, dq[0], dst+8, stride);
-        }
-        q    += 64;
-        dst  += 4*stride;
-        eobs += 4;
-    }
-}
-
-void vp8_dequant_idct_add_uv_block_neon(short *q, short *dq,
-                                        unsigned char *dstu,
-                                        unsigned char *dstv,
-                                        int stride, char *eobs)
-{
-    if (((short *)(eobs))[0])
-    {
-        if (((short *)eobs)[0] & 0xfefe)
-            idct_dequant_full_2x_neon (q, dq, dstu, stride);
-        else
-            idct_dequant_0_2x_neon (q, dq[0], dstu, stride);
-    }
-
-    q    += 32;
-    dstu += 4*stride;
-
-    if (((short *)(eobs))[1])
-    {
-        if (((short *)eobs)[1] & 0xfefe)
-            idct_dequant_full_2x_neon (q, dq, dstu, stride);
-        else
-            idct_dequant_0_2x_neon (q, dq[0], dstu, stride);
-    }
-
-    q += 32;
-
-    if (((short *)(eobs))[2])
-    {
-        if (((short *)eobs)[2] & 0xfefe)
-            idct_dequant_full_2x_neon (q, dq, dstv, stride);
-        else
-            idct_dequant_0_2x_neon (q, dq[0], dstv, stride);
-    }
-
-    q    += 32;
-    dstv += 4*stride;
-
-    if (((short *)(eobs))[3])
-    {
-        if (((short *)eobs)[3] & 0xfefe)
-            idct_dequant_full_2x_neon (q, dq, dstv, stride);
-        else
-            idct_dequant_0_2x_neon (q, dq[0], dstv, stride);
-    }
-}
diff --git a/vp8/common/arm/neon/idct_dequant_0_2x_neon.c b/vp8/common/arm/neon/idct_dequant_0_2x_neon.c
deleted file mode 100644 (file)
index e6f862f..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- *  Copyright (c) 2014 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.
- */
-
-#include <arm_neon.h>
-
-void idct_dequant_0_2x_neon(
-        int16_t *q,
-        int16_t dq,
-        unsigned char *dst,
-        int stride) {
-    unsigned char *dst0;
-    int i, a0, a1;
-    int16x8x2_t q2Add;
-    int32x2_t d2s32 = vdup_n_s32(0),
-              d4s32 = vdup_n_s32(0);
-    uint8x8_t d2u8, d4u8;
-    uint16x8_t q1u16, q2u16;
-
-    a0 = ((q[0] * dq) + 4) >> 3;
-    a1 = ((q[16] * dq) + 4) >> 3;
-    q[0] = q[16] = 0;
-    q2Add.val[0] = vdupq_n_s16((int16_t)a0);
-    q2Add.val[1] = vdupq_n_s16((int16_t)a1);
-
-    for (i = 0; i < 2; i++, dst += 4) {
-        dst0 = dst;
-        d2s32 = vld1_lane_s32((const int32_t *)dst0, d2s32, 0);
-        dst0 += stride;
-        d2s32 = vld1_lane_s32((const int32_t *)dst0, d2s32, 1);
-        dst0 += stride;
-        d4s32 = vld1_lane_s32((const int32_t *)dst0, d4s32, 0);
-        dst0 += stride;
-        d4s32 = vld1_lane_s32((const int32_t *)dst0, d4s32, 1);
-
-        q1u16 = vaddw_u8(vreinterpretq_u16_s16(q2Add.val[i]),
-                         vreinterpret_u8_s32(d2s32));
-        q2u16 = vaddw_u8(vreinterpretq_u16_s16(q2Add.val[i]),
-                         vreinterpret_u8_s32(d4s32));
-
-        d2u8 = vqmovun_s16(vreinterpretq_s16_u16(q1u16));
-        d4u8 = vqmovun_s16(vreinterpretq_s16_u16(q2u16));
-
-        d2s32 = vreinterpret_s32_u8(d2u8);
-        d4s32 = vreinterpret_s32_u8(d4u8);
-
-        dst0 = dst;
-        vst1_lane_s32((int32_t *)dst0, d2s32, 0);
-        dst0 += stride;
-        vst1_lane_s32((int32_t *)dst0, d2s32, 1);
-        dst0 += stride;
-        vst1_lane_s32((int32_t *)dst0, d4s32, 0);
-        dst0 += stride;
-        vst1_lane_s32((int32_t *)dst0, d4s32, 1);
-    }
-    return;
-}
diff --git a/vp8/common/arm/neon/idct_dequant_full_2x_neon.c b/vp8/common/arm/neon/idct_dequant_full_2x_neon.c
deleted file mode 100644 (file)
index a60ed46..0000000
+++ /dev/null
@@ -1,185 +0,0 @@
-/*
- *  Copyright (c) 2014 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.
- */
-
-#include <arm_neon.h>
-
-static const int16_t cospi8sqrt2minus1 = 20091;
-static const int16_t sinpi8sqrt2       = 17734;
-// because the lowest bit in 0x8a8c is 0, we can pre-shift this
-
-void idct_dequant_full_2x_neon(
-        int16_t *q,
-        int16_t *dq,
-        unsigned char *dst,
-        int stride) {
-    unsigned char *dst0, *dst1;
-    int32x2_t d28, d29, d30, d31;
-    int16x8_t q0, q1, q2, q3, q4, q5, q6, q7, q8, q9, q10, q11;
-    int16x8_t qEmpty = vdupq_n_s16(0);
-    int32x4x2_t q2tmp0, q2tmp1;
-    int16x8x2_t q2tmp2, q2tmp3;
-    int16x4_t dLow0, dLow1, dHigh0, dHigh1;
-
-    d28 = d29 = d30 = d31 = vdup_n_s32(0);
-
-    // load dq
-    q0 = vld1q_s16(dq);
-    dq += 8;
-    q1 = vld1q_s16(dq);
-
-    // load q
-    q2 = vld1q_s16(q);
-    vst1q_s16(q, qEmpty);
-    q += 8;
-    q3 = vld1q_s16(q);
-    vst1q_s16(q, qEmpty);
-    q += 8;
-    q4 = vld1q_s16(q);
-    vst1q_s16(q, qEmpty);
-    q += 8;
-    q5 = vld1q_s16(q);
-    vst1q_s16(q, qEmpty);
-
-    // load src from dst
-    dst0 = dst;
-    dst1 = dst + 4;
-    d28 = vld1_lane_s32((const int32_t *)dst0, d28, 0);
-    dst0 += stride;
-    d28 = vld1_lane_s32((const int32_t *)dst1, d28, 1);
-    dst1 += stride;
-    d29 = vld1_lane_s32((const int32_t *)dst0, d29, 0);
-    dst0 += stride;
-    d29 = vld1_lane_s32((const int32_t *)dst1, d29, 1);
-    dst1 += stride;
-
-    d30 = vld1_lane_s32((const int32_t *)dst0, d30, 0);
-    dst0 += stride;
-    d30 = vld1_lane_s32((const int32_t *)dst1, d30, 1);
-    dst1 += stride;
-    d31 = vld1_lane_s32((const int32_t *)dst0, d31, 0);
-    d31 = vld1_lane_s32((const int32_t *)dst1, d31, 1);
-
-    q2 = vmulq_s16(q2, q0);
-    q3 = vmulq_s16(q3, q1);
-    q4 = vmulq_s16(q4, q0);
-    q5 = vmulq_s16(q5, q1);
-
-    // vswp
-    dLow0 = vget_low_s16(q2);
-    dHigh0 = vget_high_s16(q2);
-    dLow1 = vget_low_s16(q4);
-    dHigh1 = vget_high_s16(q4);
-    q2 = vcombine_s16(dLow0, dLow1);
-    q4 = vcombine_s16(dHigh0, dHigh1);
-
-    dLow0 = vget_low_s16(q3);
-    dHigh0 = vget_high_s16(q3);
-    dLow1 = vget_low_s16(q5);
-    dHigh1 = vget_high_s16(q5);
-    q3 = vcombine_s16(dLow0, dLow1);
-    q5 = vcombine_s16(dHigh0, dHigh1);
-
-    q6 = vqdmulhq_n_s16(q4, sinpi8sqrt2);
-    q7 = vqdmulhq_n_s16(q5, sinpi8sqrt2);
-    q8 = vqdmulhq_n_s16(q4, cospi8sqrt2minus1);
-    q9 = vqdmulhq_n_s16(q5, cospi8sqrt2minus1);
-
-    q10 = vqaddq_s16(q2, q3);
-    q11 = vqsubq_s16(q2, q3);
-
-    q8 = vshrq_n_s16(q8, 1);
-    q9 = vshrq_n_s16(q9, 1);
-
-    q4 = vqaddq_s16(q4, q8);
-    q5 = vqaddq_s16(q5, q9);
-
-    q2 = vqsubq_s16(q6, q5);
-    q3 = vqaddq_s16(q7, q4);
-
-    q4 = vqaddq_s16(q10, q3);
-    q5 = vqaddq_s16(q11, q2);
-    q6 = vqsubq_s16(q11, q2);
-    q7 = vqsubq_s16(q10, q3);
-
-    q2tmp0 = vtrnq_s32(vreinterpretq_s32_s16(q4), vreinterpretq_s32_s16(q6));
-    q2tmp1 = vtrnq_s32(vreinterpretq_s32_s16(q5), vreinterpretq_s32_s16(q7));
-    q2tmp2 = vtrnq_s16(vreinterpretq_s16_s32(q2tmp0.val[0]),
-                       vreinterpretq_s16_s32(q2tmp1.val[0]));
-    q2tmp3 = vtrnq_s16(vreinterpretq_s16_s32(q2tmp0.val[1]),
-                       vreinterpretq_s16_s32(q2tmp1.val[1]));
-
-    // loop 2
-    q8  = vqdmulhq_n_s16(q2tmp2.val[1], sinpi8sqrt2);
-    q9  = vqdmulhq_n_s16(q2tmp3.val[1], sinpi8sqrt2);
-    q10 = vqdmulhq_n_s16(q2tmp2.val[1], cospi8sqrt2minus1);
-    q11 = vqdmulhq_n_s16(q2tmp3.val[1], cospi8sqrt2minus1);
-
-    q2 = vqaddq_s16(q2tmp2.val[0], q2tmp3.val[0]);
-    q3 = vqsubq_s16(q2tmp2.val[0], q2tmp3.val[0]);
-
-    q10 = vshrq_n_s16(q10, 1);
-    q11 = vshrq_n_s16(q11, 1);
-
-    q10 = vqaddq_s16(q2tmp2.val[1], q10);
-    q11 = vqaddq_s16(q2tmp3.val[1], q11);
-
-    q8 = vqsubq_s16(q8, q11);
-    q9 = vqaddq_s16(q9, q10);
-
-    q4 = vqaddq_s16(q2, q9);
-    q5 = vqaddq_s16(q3, q8);
-    q6 = vqsubq_s16(q3, q8);
-    q7 = vqsubq_s16(q2, q9);
-
-    q4 = vrshrq_n_s16(q4, 3);
-    q5 = vrshrq_n_s16(q5, 3);
-    q6 = vrshrq_n_s16(q6, 3);
-    q7 = vrshrq_n_s16(q7, 3);
-
-    q2tmp0 = vtrnq_s32(vreinterpretq_s32_s16(q4), vreinterpretq_s32_s16(q6));
-    q2tmp1 = vtrnq_s32(vreinterpretq_s32_s16(q5), vreinterpretq_s32_s16(q7));
-    q2tmp2 = vtrnq_s16(vreinterpretq_s16_s32(q2tmp0.val[0]),
-                       vreinterpretq_s16_s32(q2tmp1.val[0]));
-    q2tmp3 = vtrnq_s16(vreinterpretq_s16_s32(q2tmp0.val[1]),
-                       vreinterpretq_s16_s32(q2tmp1.val[1]));
-
-    q4 = vreinterpretq_s16_u16(vaddw_u8(vreinterpretq_u16_s16(q2tmp2.val[0]),
-                                          vreinterpret_u8_s32(d28)));
-    q5 = vreinterpretq_s16_u16(vaddw_u8(vreinterpretq_u16_s16(q2tmp2.val[1]),
-                                          vreinterpret_u8_s32(d29)));
-    q6 = vreinterpretq_s16_u16(vaddw_u8(vreinterpretq_u16_s16(q2tmp3.val[0]),
-                                          vreinterpret_u8_s32(d30)));
-    q7 = vreinterpretq_s16_u16(vaddw_u8(vreinterpretq_u16_s16(q2tmp3.val[1]),
-                                          vreinterpret_u8_s32(d31)));
-
-    d28 = vreinterpret_s32_u8(vqmovun_s16(q4));
-    d29 = vreinterpret_s32_u8(vqmovun_s16(q5));
-    d30 = vreinterpret_s32_u8(vqmovun_s16(q6));
-    d31 = vreinterpret_s32_u8(vqmovun_s16(q7));
-
-    dst0 = dst;
-    dst1 = dst + 4;
-    vst1_lane_s32((int32_t *)dst0, d28, 0);
-    dst0 += stride;
-    vst1_lane_s32((int32_t *)dst1, d28, 1);
-    dst1 += stride;
-    vst1_lane_s32((int32_t *)dst0, d29, 0);
-    dst0 += stride;
-    vst1_lane_s32((int32_t *)dst1, d29, 1);
-    dst1 += stride;
-
-    vst1_lane_s32((int32_t *)dst0, d30, 0);
-    dst0 += stride;
-    vst1_lane_s32((int32_t *)dst1, d30, 1);
-    dst1 += stride;
-    vst1_lane_s32((int32_t *)dst0, d31, 0);
-    vst1_lane_s32((int32_t *)dst1, d31, 1);
-    return;
-}
diff --git a/vp8/common/arm/neon/iwalsh_neon.c b/vp8/common/arm/neon/iwalsh_neon.c
deleted file mode 100644 (file)
index 6ea9dd7..0000000
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- *  Copyright (c) 2014 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.
- */
-
-#include <arm_neon.h>
-
-void vp8_short_inv_walsh4x4_neon(
-        int16_t *input,
-        int16_t *mb_dqcoeff) {
-    int16x8_t q0s16, q1s16, q2s16, q3s16;
-    int16x4_t d4s16, d5s16, d6s16, d7s16;
-    int16x4x2_t v2tmp0, v2tmp1;
-    int32x2x2_t v2tmp2, v2tmp3;
-    int16x8_t qAdd3;
-
-    q0s16 = vld1q_s16(input);
-    q1s16 = vld1q_s16(input + 8);
-
-    // 1st for loop
-    d4s16 = vadd_s16(vget_low_s16(q0s16), vget_high_s16(q1s16));
-    d6s16 = vadd_s16(vget_high_s16(q0s16), vget_low_s16(q1s16));
-    d5s16 = vsub_s16(vget_low_s16(q0s16), vget_high_s16(q1s16));
-    d7s16 = vsub_s16(vget_high_s16(q0s16), vget_low_s16(q1s16));
-
-    q2s16 = vcombine_s16(d4s16, d5s16);
-    q3s16 = vcombine_s16(d6s16, d7s16);
-
-    q0s16 = vaddq_s16(q2s16, q3s16);
-    q1s16 = vsubq_s16(q2s16, q3s16);
-
-    v2tmp2 = vtrn_s32(vreinterpret_s32_s16(vget_low_s16(q0s16)),
-                      vreinterpret_s32_s16(vget_low_s16(q1s16)));
-    v2tmp3 = vtrn_s32(vreinterpret_s32_s16(vget_high_s16(q0s16)),
-                      vreinterpret_s32_s16(vget_high_s16(q1s16)));
-    v2tmp0 = vtrn_s16(vreinterpret_s16_s32(v2tmp2.val[0]),
-                      vreinterpret_s16_s32(v2tmp3.val[0]));
-    v2tmp1 = vtrn_s16(vreinterpret_s16_s32(v2tmp2.val[1]),
-                      vreinterpret_s16_s32(v2tmp3.val[1]));
-
-    // 2nd for loop
-    d4s16 = vadd_s16(v2tmp0.val[0], v2tmp1.val[1]);
-    d6s16 = vadd_s16(v2tmp0.val[1], v2tmp1.val[0]);
-    d5s16 = vsub_s16(v2tmp0.val[0], v2tmp1.val[1]);
-    d7s16 = vsub_s16(v2tmp0.val[1], v2tmp1.val[0]);
-    q2s16 = vcombine_s16(d4s16, d5s16);
-    q3s16 = vcombine_s16(d6s16, d7s16);
-
-    qAdd3 = vdupq_n_s16(3);
-
-    q0s16 = vaddq_s16(q2s16, q3s16);
-    q1s16 = vsubq_s16(q2s16, q3s16);
-
-    q0s16 = vaddq_s16(q0s16, qAdd3);
-    q1s16 = vaddq_s16(q1s16, qAdd3);
-
-    q0s16 = vshrq_n_s16(q0s16, 3);
-    q1s16 = vshrq_n_s16(q1s16, 3);
-
-    // store
-    vst1_lane_s16(mb_dqcoeff, vget_low_s16(q0s16),  0);
-    mb_dqcoeff += 16;
-    vst1_lane_s16(mb_dqcoeff, vget_high_s16(q0s16), 0);
-    mb_dqcoeff += 16;
-    vst1_lane_s16(mb_dqcoeff, vget_low_s16(q1s16),  0);
-    mb_dqcoeff += 16;
-    vst1_lane_s16(mb_dqcoeff, vget_high_s16(q1s16), 0);
-    mb_dqcoeff += 16;
-
-    vst1_lane_s16(mb_dqcoeff, vget_low_s16(q0s16),  1);
-    mb_dqcoeff += 16;
-    vst1_lane_s16(mb_dqcoeff, vget_high_s16(q0s16), 1);
-    mb_dqcoeff += 16;
-    vst1_lane_s16(mb_dqcoeff, vget_low_s16(q1s16),  1);
-    mb_dqcoeff += 16;
-    vst1_lane_s16(mb_dqcoeff, vget_high_s16(q1s16), 1);
-    mb_dqcoeff += 16;
-
-    vst1_lane_s16(mb_dqcoeff, vget_low_s16(q0s16),  2);
-    mb_dqcoeff += 16;
-    vst1_lane_s16(mb_dqcoeff, vget_high_s16(q0s16), 2);
-    mb_dqcoeff += 16;
-    vst1_lane_s16(mb_dqcoeff, vget_low_s16(q1s16),  2);
-    mb_dqcoeff += 16;
-    vst1_lane_s16(mb_dqcoeff, vget_high_s16(q1s16), 2);
-    mb_dqcoeff += 16;
-
-    vst1_lane_s16(mb_dqcoeff, vget_low_s16(q0s16),  3);
-    mb_dqcoeff += 16;
-    vst1_lane_s16(mb_dqcoeff, vget_high_s16(q0s16), 3);
-    mb_dqcoeff += 16;
-    vst1_lane_s16(mb_dqcoeff, vget_low_s16(q1s16),  3);
-    mb_dqcoeff += 16;
-    vst1_lane_s16(mb_dqcoeff, vget_high_s16(q1s16), 3);
-    mb_dqcoeff += 16;
-    return;
-}
diff --git a/vp8/common/arm/neon/loopfiltersimplehorizontaledge_neon.c b/vp8/common/arm/neon/loopfiltersimplehorizontaledge_neon.c
deleted file mode 100644 (file)
index b25686f..0000000
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- *  Copyright (c) 2014 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.
- */
-
-#include <arm_neon.h>
-#include "./vpx_config.h"
-
-static INLINE void vp8_loop_filter_simple_horizontal_edge_neon(
-        unsigned char *s,
-        int p,
-        const unsigned char *blimit) {
-    uint8_t *sp;
-    uint8x16_t qblimit, q0u8;
-    uint8x16_t q5u8, q6u8, q7u8, q8u8, q9u8, q10u8, q14u8, q15u8;
-    int16x8_t q2s16, q3s16, q13s16;
-    int8x8_t d8s8, d9s8;
-    int8x16_t q2s8, q3s8, q4s8, q10s8, q11s8, q14s8;
-
-    qblimit = vdupq_n_u8(*blimit);
-
-    sp = s - (p << 1);
-    q5u8 = vld1q_u8(sp);
-    sp += p;
-    q6u8 = vld1q_u8(sp);
-    sp += p;
-    q7u8 = vld1q_u8(sp);
-    sp += p;
-    q8u8 = vld1q_u8(sp);
-
-    q15u8 = vabdq_u8(q6u8, q7u8);
-    q14u8 = vabdq_u8(q5u8, q8u8);
-
-    q15u8 = vqaddq_u8(q15u8, q15u8);
-    q14u8 = vshrq_n_u8(q14u8, 1);
-    q0u8 = vdupq_n_u8(0x80);
-    q13s16 = vdupq_n_s16(3);
-    q15u8 = vqaddq_u8(q15u8, q14u8);
-
-    q5u8 = veorq_u8(q5u8, q0u8);
-    q6u8 = veorq_u8(q6u8, q0u8);
-    q7u8 = veorq_u8(q7u8, q0u8);
-    q8u8 = veorq_u8(q8u8, q0u8);
-
-    q15u8 = vcgeq_u8(qblimit, q15u8);
-
-    q2s16 = vsubl_s8(vget_low_s8(vreinterpretq_s8_u8(q7u8)),
-                     vget_low_s8(vreinterpretq_s8_u8(q6u8)));
-    q3s16 = vsubl_s8(vget_high_s8(vreinterpretq_s8_u8(q7u8)),
-                     vget_high_s8(vreinterpretq_s8_u8(q6u8)));
-
-    q4s8 = vqsubq_s8(vreinterpretq_s8_u8(q5u8),
-                     vreinterpretq_s8_u8(q8u8));
-
-    q2s16 = vmulq_s16(q2s16, q13s16);
-    q3s16 = vmulq_s16(q3s16, q13s16);
-
-    q10u8 = vdupq_n_u8(3);
-    q9u8 = vdupq_n_u8(4);
-
-    q2s16 = vaddw_s8(q2s16, vget_low_s8(q4s8));
-    q3s16 = vaddw_s8(q3s16, vget_high_s8(q4s8));
-
-    d8s8 = vqmovn_s16(q2s16);
-    d9s8 = vqmovn_s16(q3s16);
-    q4s8 = vcombine_s8(d8s8, d9s8);
-
-    q14s8 = vandq_s8(q4s8, vreinterpretq_s8_u8(q15u8));
-
-    q2s8 = vqaddq_s8(q14s8, vreinterpretq_s8_u8(q10u8));
-    q3s8 = vqaddq_s8(q14s8, vreinterpretq_s8_u8(q9u8));
-    q2s8 = vshrq_n_s8(q2s8, 3);
-    q3s8 = vshrq_n_s8(q3s8, 3);
-
-    q11s8 = vqaddq_s8(vreinterpretq_s8_u8(q6u8), q2s8);
-    q10s8 = vqsubq_s8(vreinterpretq_s8_u8(q7u8), q3s8);
-
-    q6u8 = veorq_u8(vreinterpretq_u8_s8(q11s8), q0u8);
-    q7u8 = veorq_u8(vreinterpretq_u8_s8(q10s8), q0u8);
-
-    vst1q_u8(s, q7u8);
-    s -= p;
-    vst1q_u8(s, q6u8);
-    return;
-}
-
-void vp8_loop_filter_bhs_neon(
-        unsigned char *y_ptr,
-        int y_stride,
-        const unsigned char *blimit) {
-    y_ptr += y_stride * 4;
-    vp8_loop_filter_simple_horizontal_edge_neon(y_ptr, y_stride, blimit);
-    y_ptr += y_stride * 4;
-    vp8_loop_filter_simple_horizontal_edge_neon(y_ptr, y_stride, blimit);
-    y_ptr += y_stride * 4;
-    vp8_loop_filter_simple_horizontal_edge_neon(y_ptr, y_stride, blimit);
-    return;
-}
-
-void vp8_loop_filter_mbhs_neon(
-        unsigned char *y_ptr,
-        int y_stride,
-        const unsigned char *blimit) {
-    vp8_loop_filter_simple_horizontal_edge_neon(y_ptr, y_stride, blimit);
-    return;
-}
diff --git a/vp8/common/arm/neon/loopfiltersimpleverticaledge_neon.c b/vp8/common/arm/neon/loopfiltersimpleverticaledge_neon.c
deleted file mode 100644 (file)
index 921bcad..0000000
+++ /dev/null
@@ -1,283 +0,0 @@
-/*
- *  Copyright (c) 2014 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.
- */
-
-#include <arm_neon.h>
-#include "./vpx_config.h"
-#include "vpx_ports/arm.h"
-
-#ifdef VPX_INCOMPATIBLE_GCC
-static INLINE void write_2x4(unsigned char *dst, int pitch,
-                             const uint8x8x2_t result) {
-    /*
-     * uint8x8x2_t result
-    00 01 02 03 | 04 05 06 07
-    10 11 12 13 | 14 15 16 17
-    ---
-    * after vtrn_u8
-    00 10 02 12 | 04 14 06 16
-    01 11 03 13 | 05 15 07 17
-    */
-    const uint8x8x2_t r01_u8 = vtrn_u8(result.val[0],
-                                       result.val[1]);
-    const uint16x4_t x_0_4 = vreinterpret_u16_u8(r01_u8.val[0]);
-    const uint16x4_t x_1_5 = vreinterpret_u16_u8(r01_u8.val[1]);
-    vst1_lane_u16((uint16_t *)dst, x_0_4, 0);
-    dst += pitch;
-    vst1_lane_u16((uint16_t *)dst, x_1_5, 0);
-    dst += pitch;
-    vst1_lane_u16((uint16_t *)dst, x_0_4, 1);
-    dst += pitch;
-    vst1_lane_u16((uint16_t *)dst, x_1_5, 1);
-    dst += pitch;
-    vst1_lane_u16((uint16_t *)dst, x_0_4, 2);
-    dst += pitch;
-    vst1_lane_u16((uint16_t *)dst, x_1_5, 2);
-    dst += pitch;
-    vst1_lane_u16((uint16_t *)dst, x_0_4, 3);
-    dst += pitch;
-    vst1_lane_u16((uint16_t *)dst, x_1_5, 3);
-}
-
-static INLINE void write_2x8(unsigned char *dst, int pitch,
-                             const uint8x8x2_t result,
-                             const uint8x8x2_t result2) {
-  write_2x4(dst, pitch, result);
-  dst += pitch * 8;
-  write_2x4(dst, pitch, result2);
-}
-#else
-static INLINE void write_2x8(unsigned char *dst, int pitch,
-                             const uint8x8x2_t result,
-                             const uint8x8x2_t result2) {
-  vst2_lane_u8(dst, result, 0);
-  dst += pitch;
-  vst2_lane_u8(dst, result, 1);
-  dst += pitch;
-  vst2_lane_u8(dst, result, 2);
-  dst += pitch;
-  vst2_lane_u8(dst, result, 3);
-  dst += pitch;
-  vst2_lane_u8(dst, result, 4);
-  dst += pitch;
-  vst2_lane_u8(dst, result, 5);
-  dst += pitch;
-  vst2_lane_u8(dst, result, 6);
-  dst += pitch;
-  vst2_lane_u8(dst, result, 7);
-  dst += pitch;
-
-  vst2_lane_u8(dst, result2, 0);
-  dst += pitch;
-  vst2_lane_u8(dst, result2, 1);
-  dst += pitch;
-  vst2_lane_u8(dst, result2, 2);
-  dst += pitch;
-  vst2_lane_u8(dst, result2, 3);
-  dst += pitch;
-  vst2_lane_u8(dst, result2, 4);
-  dst += pitch;
-  vst2_lane_u8(dst, result2, 5);
-  dst += pitch;
-  vst2_lane_u8(dst, result2, 6);
-  dst += pitch;
-  vst2_lane_u8(dst, result2, 7);
-}
-#endif  // VPX_INCOMPATIBLE_GCC
-
-
-#ifdef VPX_INCOMPATIBLE_GCC
-static INLINE
-uint8x8x4_t read_4x8(unsigned char *src, int pitch) {
-    uint8x8x4_t x;
-    const uint8x8_t a = vld1_u8(src);
-    const uint8x8_t b = vld1_u8(src + pitch * 1);
-    const uint8x8_t c = vld1_u8(src + pitch * 2);
-    const uint8x8_t d = vld1_u8(src + pitch * 3);
-    const uint8x8_t e = vld1_u8(src + pitch * 4);
-    const uint8x8_t f = vld1_u8(src + pitch * 5);
-    const uint8x8_t g = vld1_u8(src + pitch * 6);
-    const uint8x8_t h = vld1_u8(src + pitch * 7);
-    const uint32x2x2_t r04_u32 = vtrn_u32(vreinterpret_u32_u8(a),
-                                          vreinterpret_u32_u8(e));
-    const uint32x2x2_t r15_u32 = vtrn_u32(vreinterpret_u32_u8(b),
-                                          vreinterpret_u32_u8(f));
-    const uint32x2x2_t r26_u32 = vtrn_u32(vreinterpret_u32_u8(c),
-                                          vreinterpret_u32_u8(g));
-    const uint32x2x2_t r37_u32 = vtrn_u32(vreinterpret_u32_u8(d),
-                                          vreinterpret_u32_u8(h));
-    const uint16x4x2_t r02_u16 = vtrn_u16(vreinterpret_u16_u32(r04_u32.val[0]),
-                                          vreinterpret_u16_u32(r26_u32.val[0]));
-    const uint16x4x2_t r13_u16 = vtrn_u16(vreinterpret_u16_u32(r15_u32.val[0]),
-                                          vreinterpret_u16_u32(r37_u32.val[0]));
-    const uint8x8x2_t r01_u8 = vtrn_u8(vreinterpret_u8_u16(r02_u16.val[0]),
-                                       vreinterpret_u8_u16(r13_u16.val[0]));
-    const uint8x8x2_t r23_u8 = vtrn_u8(vreinterpret_u8_u16(r02_u16.val[1]),
-                                       vreinterpret_u8_u16(r13_u16.val[1]));
-    /*
-     * after vtrn_u32
-    00 01 02 03 | 40 41 42 43
-    10 11 12 13 | 50 51 52 53
-    20 21 22 23 | 60 61 62 63
-    30 31 32 33 | 70 71 72 73
-    ---
-    * after vtrn_u16
-    00 01 20 21 | 40 41 60 61
-    02 03 22 23 | 42 43 62 63
-    10 11 30 31 | 50 51 70 71
-    12 13 32 33 | 52 52 72 73
-
-    00 01 20 21 | 40 41 60 61
-    10 11 30 31 | 50 51 70 71
-    02 03 22 23 | 42 43 62 63
-    12 13 32 33 | 52 52 72 73
-    ---
-    * after vtrn_u8
-    00 10 20 30 | 40 50 60 70
-    01 11 21 31 | 41 51 61 71
-    02 12 22 32 | 42 52 62 72
-    03 13 23 33 | 43 53 63 73
-    */
-    x.val[0] = r01_u8.val[0];
-    x.val[1] = r01_u8.val[1];
-    x.val[2] = r23_u8.val[0];
-    x.val[3] = r23_u8.val[1];
-
-    return x;
-}
-#else
-static INLINE
-uint8x8x4_t read_4x8(unsigned char *src, int pitch) {
-    uint8x8x4_t x;
-    x.val[0] = x.val[1] = x.val[2] = x.val[3] = vdup_n_u8(0);
-    x = vld4_lane_u8(src, x, 0);
-    src += pitch;
-    x = vld4_lane_u8(src, x, 1);
-    src += pitch;
-    x = vld4_lane_u8(src, x, 2);
-    src += pitch;
-    x = vld4_lane_u8(src, x, 3);
-    src += pitch;
-    x = vld4_lane_u8(src, x, 4);
-    src += pitch;
-    x = vld4_lane_u8(src, x, 5);
-    src += pitch;
-    x = vld4_lane_u8(src, x, 6);
-    src += pitch;
-    x = vld4_lane_u8(src, x, 7);
-    return x;
-}
-#endif  // VPX_INCOMPATIBLE_GCC
-
-static INLINE void vp8_loop_filter_simple_vertical_edge_neon(
-        unsigned char *s,
-        int p,
-        const unsigned char *blimit) {
-    unsigned char *src1;
-    uint8x16_t qblimit, q0u8;
-    uint8x16_t q3u8, q4u8, q5u8, q6u8, q7u8, q11u8, q12u8, q14u8, q15u8;
-    int16x8_t q2s16, q13s16, q11s16;
-    int8x8_t d28s8, d29s8;
-    int8x16_t q2s8, q3s8, q10s8, q11s8, q14s8;
-    uint8x8x4_t d0u8x4;  // d6, d7, d8, d9
-    uint8x8x4_t d1u8x4;  // d10, d11, d12, d13
-    uint8x8x2_t d2u8x2;  // d12, d13
-    uint8x8x2_t d3u8x2;  // d14, d15
-
-    qblimit = vdupq_n_u8(*blimit);
-
-    src1 = s - 2;
-    d0u8x4 = read_4x8(src1, p);
-    src1 += p * 8;
-    d1u8x4 = read_4x8(src1, p);
-
-    q3u8 = vcombine_u8(d0u8x4.val[0], d1u8x4.val[0]);  // d6 d10
-    q4u8 = vcombine_u8(d0u8x4.val[2], d1u8x4.val[2]);  // d8 d12
-    q5u8 = vcombine_u8(d0u8x4.val[1], d1u8x4.val[1]);  // d7 d11
-    q6u8 = vcombine_u8(d0u8x4.val[3], d1u8x4.val[3]);  // d9 d13
-
-    q15u8 = vabdq_u8(q5u8, q4u8);
-    q14u8 = vabdq_u8(q3u8, q6u8);
-
-    q15u8 = vqaddq_u8(q15u8, q15u8);
-    q14u8 = vshrq_n_u8(q14u8, 1);
-    q0u8 = vdupq_n_u8(0x80);
-    q11s16 = vdupq_n_s16(3);
-    q15u8 = vqaddq_u8(q15u8, q14u8);
-
-    q3u8 = veorq_u8(q3u8, q0u8);
-    q4u8 = veorq_u8(q4u8, q0u8);
-    q5u8 = veorq_u8(q5u8, q0u8);
-    q6u8 = veorq_u8(q6u8, q0u8);
-
-    q15u8 = vcgeq_u8(qblimit, q15u8);
-
-    q2s16 = vsubl_s8(vget_low_s8(vreinterpretq_s8_u8(q4u8)),
-                     vget_low_s8(vreinterpretq_s8_u8(q5u8)));
-    q13s16 = vsubl_s8(vget_high_s8(vreinterpretq_s8_u8(q4u8)),
-                      vget_high_s8(vreinterpretq_s8_u8(q5u8)));
-
-    q14s8 = vqsubq_s8(vreinterpretq_s8_u8(q3u8),
-                      vreinterpretq_s8_u8(q6u8));
-
-    q2s16 = vmulq_s16(q2s16, q11s16);
-    q13s16 = vmulq_s16(q13s16, q11s16);
-
-    q11u8 = vdupq_n_u8(3);
-    q12u8 = vdupq_n_u8(4);
-
-    q2s16 = vaddw_s8(q2s16, vget_low_s8(q14s8));
-    q13s16 = vaddw_s8(q13s16, vget_high_s8(q14s8));
-
-    d28s8 = vqmovn_s16(q2s16);
-    d29s8 = vqmovn_s16(q13s16);
-    q14s8 = vcombine_s8(d28s8, d29s8);
-
-    q14s8 = vandq_s8(q14s8, vreinterpretq_s8_u8(q15u8));
-
-    q2s8 = vqaddq_s8(q14s8, vreinterpretq_s8_u8(q11u8));
-    q3s8 = vqaddq_s8(q14s8, vreinterpretq_s8_u8(q12u8));
-    q2s8 = vshrq_n_s8(q2s8, 3);
-    q14s8 = vshrq_n_s8(q3s8, 3);
-
-    q11s8 = vqaddq_s8(vreinterpretq_s8_u8(q5u8), q2s8);
-    q10s8 = vqsubq_s8(vreinterpretq_s8_u8(q4u8), q14s8);
-
-    q6u8 = veorq_u8(vreinterpretq_u8_s8(q11s8), q0u8);
-    q7u8 = veorq_u8(vreinterpretq_u8_s8(q10s8), q0u8);
-
-    d2u8x2.val[0] = vget_low_u8(q6u8);   // d12
-    d2u8x2.val[1] = vget_low_u8(q7u8);   // d14
-    d3u8x2.val[0] = vget_high_u8(q6u8);  // d13
-    d3u8x2.val[1] = vget_high_u8(q7u8);  // d15
-
-    src1 = s - 1;
-    write_2x8(src1, p, d2u8x2, d3u8x2);
-}
-
-void vp8_loop_filter_bvs_neon(
-        unsigned char *y_ptr,
-        int y_stride,
-        const unsigned char *blimit) {
-    y_ptr += 4;
-    vp8_loop_filter_simple_vertical_edge_neon(y_ptr, y_stride, blimit);
-    y_ptr += 4;
-    vp8_loop_filter_simple_vertical_edge_neon(y_ptr, y_stride, blimit);
-    y_ptr += 4;
-    vp8_loop_filter_simple_vertical_edge_neon(y_ptr, y_stride, blimit);
-    return;
-}
-
-void vp8_loop_filter_mbvs_neon(
-        unsigned char *y_ptr,
-        int y_stride,
-        const unsigned char *blimit) {
-    vp8_loop_filter_simple_vertical_edge_neon(y_ptr, y_stride, blimit);
-    return;
-}
diff --git a/vp8/common/arm/neon/mbloopfilter_neon.c b/vp8/common/arm/neon/mbloopfilter_neon.c
deleted file mode 100644 (file)
index 5351f4b..0000000
+++ /dev/null
@@ -1,625 +0,0 @@
-/*
- *  Copyright (c) 2014 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.
- */
-
-#include <arm_neon.h>
-#include "./vpx_config.h"
-
-static INLINE void vp8_mbloop_filter_neon(
-        uint8x16_t qblimit,  // mblimit
-        uint8x16_t qlimit,   // limit
-        uint8x16_t qthresh,  // thresh
-        uint8x16_t q3,       // p2
-        uint8x16_t q4,       // p2
-        uint8x16_t q5,       // p1
-        uint8x16_t q6,       // p0
-        uint8x16_t q7,       // q0
-        uint8x16_t q8,       // q1
-        uint8x16_t q9,       // q2
-        uint8x16_t q10,      // q3
-        uint8x16_t *q4r,     // p1
-        uint8x16_t *q5r,     // p1
-        uint8x16_t *q6r,     // p0
-        uint8x16_t *q7r,     // q0
-        uint8x16_t *q8r,     // q1
-        uint8x16_t *q9r) {   // q1
-    uint8x16_t q0u8, q1u8, q11u8, q12u8, q13u8, q14u8, q15u8;
-    int16x8_t q0s16, q2s16, q11s16, q12s16, q13s16, q14s16, q15s16;
-    int8x16_t q1s8, q6s8, q7s8, q2s8, q11s8, q13s8;
-    uint16x8_t q0u16, q11u16, q12u16, q13u16, q14u16, q15u16;
-    int8x16_t q0s8, q12s8, q14s8, q15s8;
-    int8x8_t d0, d1, d2, d3, d4, d5, d24, d25, d28, d29;
-
-    q11u8 = vabdq_u8(q3, q4);
-    q12u8 = vabdq_u8(q4, q5);
-    q13u8 = vabdq_u8(q5, q6);
-    q14u8 = vabdq_u8(q8, q7);
-    q1u8  = vabdq_u8(q9, q8);
-    q0u8  = vabdq_u8(q10, q9);
-
-    q11u8 = vmaxq_u8(q11u8, q12u8);
-    q12u8 = vmaxq_u8(q13u8, q14u8);
-    q1u8  = vmaxq_u8(q1u8, q0u8);
-    q15u8 = vmaxq_u8(q11u8, q12u8);
-
-    q12u8 = vabdq_u8(q6, q7);
-
-    // vp8_hevmask
-    q13u8 = vcgtq_u8(q13u8, qthresh);
-    q14u8 = vcgtq_u8(q14u8, qthresh);
-    q15u8 = vmaxq_u8(q15u8, q1u8);
-
-    q15u8 = vcgeq_u8(qlimit, q15u8);
-
-    q1u8 = vabdq_u8(q5, q8);
-    q12u8 = vqaddq_u8(q12u8, q12u8);
-
-    // vp8_filter() function
-    // convert to signed
-    q0u8 = vdupq_n_u8(0x80);
-    q9 = veorq_u8(q9, q0u8);
-    q8 = veorq_u8(q8, q0u8);
-    q7 = veorq_u8(q7, q0u8);
-    q6 = veorq_u8(q6, q0u8);
-    q5 = veorq_u8(q5, q0u8);
-    q4 = veorq_u8(q4, q0u8);
-
-    q1u8 = vshrq_n_u8(q1u8, 1);
-    q12u8 = vqaddq_u8(q12u8, q1u8);
-
-    q14u8 = vorrq_u8(q13u8, q14u8);
-    q12u8 = vcgeq_u8(qblimit, q12u8);
-
-    q2s16 = vsubl_s8(vget_low_s8(vreinterpretq_s8_u8(q7)),
-                     vget_low_s8(vreinterpretq_s8_u8(q6)));
-    q13s16 = vsubl_s8(vget_high_s8(vreinterpretq_s8_u8(q7)),
-                      vget_high_s8(vreinterpretq_s8_u8(q6)));
-
-    q1s8 = vqsubq_s8(vreinterpretq_s8_u8(q5),
-                     vreinterpretq_s8_u8(q8));
-
-    q11s16 = vdupq_n_s16(3);
-    q2s16  = vmulq_s16(q2s16, q11s16);
-    q13s16 = vmulq_s16(q13s16, q11s16);
-
-    q15u8 = vandq_u8(q15u8, q12u8);
-
-    q2s16  = vaddw_s8(q2s16, vget_low_s8(q1s8));
-    q13s16 = vaddw_s8(q13s16, vget_high_s8(q1s8));
-
-    q12u8 = vdupq_n_u8(3);
-    q11u8 = vdupq_n_u8(4);
-    // vp8_filter = clamp(vp8_filter + 3 * ( qs0 - ps0))
-    d2 = vqmovn_s16(q2s16);
-    d3 = vqmovn_s16(q13s16);
-    q1s8 = vcombine_s8(d2, d3);
-    q1s8 = vandq_s8(q1s8, vreinterpretq_s8_u8(q15u8));
-    q13s8 = vandq_s8(q1s8, vreinterpretq_s8_u8(q14u8));
-
-    q2s8 = vqaddq_s8(q13s8, vreinterpretq_s8_u8(q11u8));
-    q13s8 = vqaddq_s8(q13s8, vreinterpretq_s8_u8(q12u8));
-    q2s8 = vshrq_n_s8(q2s8, 3);
-    q13s8 = vshrq_n_s8(q13s8, 3);
-
-    q7s8 = vqsubq_s8(vreinterpretq_s8_u8(q7), q2s8);
-    q6s8 = vqaddq_s8(vreinterpretq_s8_u8(q6), q13s8);
-
-    q1s8 = vbicq_s8(q1s8, vreinterpretq_s8_u8(q14u8));
-
-    q0u16 = q11u16 = q12u16 = q13u16 = q14u16 = q15u16 = vdupq_n_u16(63);
-    d5 = vdup_n_s8(9);
-    d4 = vdup_n_s8(18);
-
-    q0s16  = vmlal_s8(vreinterpretq_s16_u16(q0u16),  vget_low_s8(q1s8),  d5);
-    q11s16 = vmlal_s8(vreinterpretq_s16_u16(q11u16), vget_high_s8(q1s8), d5);
-    d5 = vdup_n_s8(27);
-    q12s16 = vmlal_s8(vreinterpretq_s16_u16(q12u16), vget_low_s8(q1s8),  d4);
-    q13s16 = vmlal_s8(vreinterpretq_s16_u16(q13u16), vget_high_s8(q1s8), d4);
-    q14s16 = vmlal_s8(vreinterpretq_s16_u16(q14u16), vget_low_s8(q1s8),  d5);
-    q15s16 = vmlal_s8(vreinterpretq_s16_u16(q15u16), vget_high_s8(q1s8), d5);
-
-    d0  = vqshrn_n_s16(q0s16 , 7);
-    d1  = vqshrn_n_s16(q11s16, 7);
-    d24 = vqshrn_n_s16(q12s16, 7);
-    d25 = vqshrn_n_s16(q13s16, 7);
-    d28 = vqshrn_n_s16(q14s16, 7);
-    d29 = vqshrn_n_s16(q15s16, 7);
-
-    q0s8  = vcombine_s8(d0, d1);
-    q12s8 = vcombine_s8(d24, d25);
-    q14s8 = vcombine_s8(d28, d29);
-
-    q11s8 = vqsubq_s8(vreinterpretq_s8_u8(q9), q0s8);
-    q0s8  = vqaddq_s8(vreinterpretq_s8_u8(q4), q0s8);
-    q13s8 = vqsubq_s8(vreinterpretq_s8_u8(q8), q12s8);
-    q12s8 = vqaddq_s8(vreinterpretq_s8_u8(q5), q12s8);
-    q15s8 = vqsubq_s8((q7s8), q14s8);
-    q14s8 = vqaddq_s8((q6s8), q14s8);
-
-    q1u8 = vdupq_n_u8(0x80);
-    *q9r = veorq_u8(vreinterpretq_u8_s8(q11s8), q1u8);
-    *q8r = veorq_u8(vreinterpretq_u8_s8(q13s8), q1u8);
-    *q7r = veorq_u8(vreinterpretq_u8_s8(q15s8), q1u8);
-    *q6r = veorq_u8(vreinterpretq_u8_s8(q14s8), q1u8);
-    *q5r = veorq_u8(vreinterpretq_u8_s8(q12s8), q1u8);
-    *q4r = veorq_u8(vreinterpretq_u8_s8(q0s8), q1u8);
-    return;
-}
-
-void vp8_mbloop_filter_horizontal_edge_y_neon(
-        unsigned char *src,
-        int pitch,
-        unsigned char blimit,
-        unsigned char limit,
-        unsigned char thresh) {
-    uint8x16_t qblimit, qlimit, qthresh, q3, q4;
-    uint8x16_t q5, q6, q7, q8, q9, q10;
-
-    qblimit = vdupq_n_u8(blimit);
-    qlimit = vdupq_n_u8(limit);
-    qthresh = vdupq_n_u8(thresh);
-
-    src -= (pitch << 2);
-
-    q3 = vld1q_u8(src);
-    src += pitch;
-    q4 = vld1q_u8(src);
-    src += pitch;
-    q5 = vld1q_u8(src);
-    src += pitch;
-    q6 = vld1q_u8(src);
-    src += pitch;
-    q7 = vld1q_u8(src);
-    src += pitch;
-    q8 = vld1q_u8(src);
-    src += pitch;
-    q9 = vld1q_u8(src);
-    src += pitch;
-    q10 = vld1q_u8(src);
-
-    vp8_mbloop_filter_neon(qblimit, qlimit, qthresh, q3, q4,
-                         q5, q6, q7, q8, q9, q10,
-                         &q4, &q5, &q6, &q7, &q8, &q9);
-
-    src -= (pitch * 6);
-    vst1q_u8(src, q4);
-    src += pitch;
-    vst1q_u8(src, q5);
-    src += pitch;
-    vst1q_u8(src, q6);
-    src += pitch;
-    vst1q_u8(src, q7);
-    src += pitch;
-    vst1q_u8(src, q8);
-    src += pitch;
-    vst1q_u8(src, q9);
-    return;
-}
-
-void vp8_mbloop_filter_horizontal_edge_uv_neon(
-        unsigned char *u,
-        int pitch,
-        unsigned char blimit,
-        unsigned char limit,
-        unsigned char thresh,
-        unsigned char *v) {
-    uint8x16_t qblimit, qlimit, qthresh, q3, q4;
-    uint8x16_t q5, q6, q7, q8, q9, q10;
-    uint8x8_t d6, d7, d8, d9, d10, d11, d12, d13, d14;
-    uint8x8_t d15, d16, d17, d18, d19, d20, d21;
-
-    qblimit = vdupq_n_u8(blimit);
-    qlimit = vdupq_n_u8(limit);
-    qthresh = vdupq_n_u8(thresh);
-
-    u -= (pitch << 2);
-    v -= (pitch << 2);
-
-    d6 = vld1_u8(u);
-    u += pitch;
-    d7 = vld1_u8(v);
-    v += pitch;
-    d8 = vld1_u8(u);
-    u += pitch;
-    d9 = vld1_u8(v);
-    v += pitch;
-    d10 = vld1_u8(u);
-    u += pitch;
-    d11 = vld1_u8(v);
-    v += pitch;
-    d12 = vld1_u8(u);
-    u += pitch;
-    d13 = vld1_u8(v);
-    v += pitch;
-    d14 = vld1_u8(u);
-    u += pitch;
-    d15 = vld1_u8(v);
-    v += pitch;
-    d16 = vld1_u8(u);
-    u += pitch;
-    d17 = vld1_u8(v);
-    v += pitch;
-    d18 = vld1_u8(u);
-    u += pitch;
-    d19 = vld1_u8(v);
-    v += pitch;
-    d20 = vld1_u8(u);
-    d21 = vld1_u8(v);
-
-    q3 = vcombine_u8(d6, d7);
-    q4 = vcombine_u8(d8, d9);
-    q5 = vcombine_u8(d10, d11);
-    q6 = vcombine_u8(d12, d13);
-    q7 = vcombine_u8(d14, d15);
-    q8 = vcombine_u8(d16, d17);
-    q9 = vcombine_u8(d18, d19);
-    q10 = vcombine_u8(d20, d21);
-
-    vp8_mbloop_filter_neon(qblimit, qlimit, qthresh, q3, q4,
-                         q5, q6, q7, q8, q9, q10,
-                         &q4, &q5, &q6, &q7, &q8, &q9);
-
-    u -= (pitch * 6);
-    v -= (pitch * 6);
-    vst1_u8(u, vget_low_u8(q4));
-    u += pitch;
-    vst1_u8(v, vget_high_u8(q4));
-    v += pitch;
-    vst1_u8(u, vget_low_u8(q5));
-    u += pitch;
-    vst1_u8(v, vget_high_u8(q5));
-    v += pitch;
-    vst1_u8(u, vget_low_u8(q6));
-    u += pitch;
-    vst1_u8(v, vget_high_u8(q6));
-    v += pitch;
-    vst1_u8(u, vget_low_u8(q7));
-    u += pitch;
-    vst1_u8(v, vget_high_u8(q7));
-    v += pitch;
-    vst1_u8(u, vget_low_u8(q8));
-    u += pitch;
-    vst1_u8(v, vget_high_u8(q8));
-    v += pitch;
-    vst1_u8(u, vget_low_u8(q9));
-    vst1_u8(v, vget_high_u8(q9));
-    return;
-}
-
-void vp8_mbloop_filter_vertical_edge_y_neon(
-        unsigned char *src,
-        int pitch,
-        unsigned char blimit,
-        unsigned char limit,
-        unsigned char thresh) {
-    unsigned char *s1, *s2;
-    uint8x16_t qblimit, qlimit, qthresh, q3, q4;
-    uint8x16_t q5, q6, q7, q8, q9, q10;
-    uint8x8_t d6, d7, d8, d9, d10, d11, d12, d13, d14;
-    uint8x8_t d15, d16, d17, d18, d19, d20, d21;
-    uint32x4x2_t q2tmp0, q2tmp1, q2tmp2, q2tmp3;
-    uint16x8x2_t q2tmp4, q2tmp5, q2tmp6, q2tmp7;
-    uint8x16x2_t q2tmp8, q2tmp9, q2tmp10, q2tmp11;
-
-    qblimit = vdupq_n_u8(blimit);
-    qlimit = vdupq_n_u8(limit);
-    qthresh = vdupq_n_u8(thresh);
-
-    s1 = src - 4;
-    s2 = s1 + 8 * pitch;
-    d6  = vld1_u8(s1);
-    s1 += pitch;
-    d7  = vld1_u8(s2);
-    s2 += pitch;
-    d8  = vld1_u8(s1);
-    s1 += pitch;
-    d9  = vld1_u8(s2);
-    s2 += pitch;
-    d10 = vld1_u8(s1);
-    s1 += pitch;
-    d11 = vld1_u8(s2);
-    s2 += pitch;
-    d12 = vld1_u8(s1);
-    s1 += pitch;
-    d13 = vld1_u8(s2);
-    s2 += pitch;
-    d14 = vld1_u8(s1);
-    s1 += pitch;
-    d15 = vld1_u8(s2);
-    s2 += pitch;
-    d16 = vld1_u8(s1);
-    s1 += pitch;
-    d17 = vld1_u8(s2);
-    s2 += pitch;
-    d18 = vld1_u8(s1);
-    s1 += pitch;
-    d19 = vld1_u8(s2);
-    s2 += pitch;
-    d20 = vld1_u8(s1);
-    d21 = vld1_u8(s2);
-
-    q3 = vcombine_u8(d6, d7);
-    q4 = vcombine_u8(d8, d9);
-    q5 = vcombine_u8(d10, d11);
-    q6 = vcombine_u8(d12, d13);
-    q7 = vcombine_u8(d14, d15);
-    q8 = vcombine_u8(d16, d17);
-    q9 = vcombine_u8(d18, d19);
-    q10 = vcombine_u8(d20, d21);
-
-    q2tmp0 = vtrnq_u32(vreinterpretq_u32_u8(q3), vreinterpretq_u32_u8(q7));
-    q2tmp1 = vtrnq_u32(vreinterpretq_u32_u8(q4), vreinterpretq_u32_u8(q8));
-    q2tmp2 = vtrnq_u32(vreinterpretq_u32_u8(q5), vreinterpretq_u32_u8(q9));
-    q2tmp3 = vtrnq_u32(vreinterpretq_u32_u8(q6), vreinterpretq_u32_u8(q10));
-
-    q2tmp4 = vtrnq_u16(vreinterpretq_u16_u32(q2tmp0.val[0]),
-                       vreinterpretq_u16_u32(q2tmp2.val[0]));
-    q2tmp5 = vtrnq_u16(vreinterpretq_u16_u32(q2tmp1.val[0]),
-                       vreinterpretq_u16_u32(q2tmp3.val[0]));
-    q2tmp6 = vtrnq_u16(vreinterpretq_u16_u32(q2tmp0.val[1]),
-                       vreinterpretq_u16_u32(q2tmp2.val[1]));
-    q2tmp7 = vtrnq_u16(vreinterpretq_u16_u32(q2tmp1.val[1]),
-                       vreinterpretq_u16_u32(q2tmp3.val[1]));
-
-    q2tmp8  = vtrnq_u8(vreinterpretq_u8_u16(q2tmp4.val[0]),
-                       vreinterpretq_u8_u16(q2tmp5.val[0]));
-    q2tmp9  = vtrnq_u8(vreinterpretq_u8_u16(q2tmp4.val[1]),
-                       vreinterpretq_u8_u16(q2tmp5.val[1]));
-    q2tmp10 = vtrnq_u8(vreinterpretq_u8_u16(q2tmp6.val[0]),
-                       vreinterpretq_u8_u16(q2tmp7.val[0]));
-    q2tmp11 = vtrnq_u8(vreinterpretq_u8_u16(q2tmp6.val[1]),
-                       vreinterpretq_u8_u16(q2tmp7.val[1]));
-
-    q3 = q2tmp8.val[0];
-    q4 = q2tmp8.val[1];
-    q5 = q2tmp9.val[0];
-    q6 = q2tmp9.val[1];
-    q7 = q2tmp10.val[0];
-    q8 = q2tmp10.val[1];
-    q9 = q2tmp11.val[0];
-    q10 = q2tmp11.val[1];
-
-    vp8_mbloop_filter_neon(qblimit, qlimit, qthresh, q3, q4,
-                         q5, q6, q7, q8, q9, q10,
-                         &q4, &q5, &q6, &q7, &q8, &q9);
-
-    q2tmp0 = vtrnq_u32(vreinterpretq_u32_u8(q3), vreinterpretq_u32_u8(q7));
-    q2tmp1 = vtrnq_u32(vreinterpretq_u32_u8(q4), vreinterpretq_u32_u8(q8));
-    q2tmp2 = vtrnq_u32(vreinterpretq_u32_u8(q5), vreinterpretq_u32_u8(q9));
-    q2tmp3 = vtrnq_u32(vreinterpretq_u32_u8(q6), vreinterpretq_u32_u8(q10));
-
-    q2tmp4 = vtrnq_u16(vreinterpretq_u16_u32(q2tmp0.val[0]),
-                       vreinterpretq_u16_u32(q2tmp2.val[0]));
-    q2tmp5 = vtrnq_u16(vreinterpretq_u16_u32(q2tmp1.val[0]),
-                       vreinterpretq_u16_u32(q2tmp3.val[0]));
-    q2tmp6 = vtrnq_u16(vreinterpretq_u16_u32(q2tmp0.val[1]),
-                       vreinterpretq_u16_u32(q2tmp2.val[1]));
-    q2tmp7 = vtrnq_u16(vreinterpretq_u16_u32(q2tmp1.val[1]),
-                       vreinterpretq_u16_u32(q2tmp3.val[1]));
-
-    q2tmp8  = vtrnq_u8(vreinterpretq_u8_u16(q2tmp4.val[0]),
-                       vreinterpretq_u8_u16(q2tmp5.val[0]));
-    q2tmp9  = vtrnq_u8(vreinterpretq_u8_u16(q2tmp4.val[1]),
-                       vreinterpretq_u8_u16(q2tmp5.val[1]));
-    q2tmp10 = vtrnq_u8(vreinterpretq_u8_u16(q2tmp6.val[0]),
-                       vreinterpretq_u8_u16(q2tmp7.val[0]));
-    q2tmp11 = vtrnq_u8(vreinterpretq_u8_u16(q2tmp6.val[1]),
-                       vreinterpretq_u8_u16(q2tmp7.val[1]));
-
-    q3 = q2tmp8.val[0];
-    q4 = q2tmp8.val[1];
-    q5 = q2tmp9.val[0];
-    q6 = q2tmp9.val[1];
-    q7 = q2tmp10.val[0];
-    q8 = q2tmp10.val[1];
-    q9 = q2tmp11.val[0];
-    q10 = q2tmp11.val[1];
-
-    s1 -= 7 * pitch;
-    s2 -= 7 * pitch;
-
-    vst1_u8(s1, vget_low_u8(q3));
-    s1 += pitch;
-    vst1_u8(s2, vget_high_u8(q3));
-    s2 += pitch;
-    vst1_u8(s1, vget_low_u8(q4));
-    s1 += pitch;
-    vst1_u8(s2, vget_high_u8(q4));
-    s2 += pitch;
-    vst1_u8(s1, vget_low_u8(q5));
-    s1 += pitch;
-    vst1_u8(s2, vget_high_u8(q5));
-    s2 += pitch;
-    vst1_u8(s1, vget_low_u8(q6));
-    s1 += pitch;
-    vst1_u8(s2, vget_high_u8(q6));
-    s2 += pitch;
-    vst1_u8(s1, vget_low_u8(q7));
-    s1 += pitch;
-    vst1_u8(s2, vget_high_u8(q7));
-    s2 += pitch;
-    vst1_u8(s1, vget_low_u8(q8));
-    s1 += pitch;
-    vst1_u8(s2, vget_high_u8(q8));
-    s2 += pitch;
-    vst1_u8(s1, vget_low_u8(q9));
-    s1 += pitch;
-    vst1_u8(s2, vget_high_u8(q9));
-    s2 += pitch;
-    vst1_u8(s1, vget_low_u8(q10));
-    vst1_u8(s2, vget_high_u8(q10));
-    return;
-}
-
-void vp8_mbloop_filter_vertical_edge_uv_neon(
-        unsigned char *u,
-        int pitch,
-        unsigned char blimit,
-        unsigned char limit,
-        unsigned char thresh,
-        unsigned char *v) {
-    unsigned char *us, *ud;
-    unsigned char *vs, *vd;
-    uint8x16_t qblimit, qlimit, qthresh, q3, q4;
-    uint8x16_t q5, q6, q7, q8, q9, q10;
-    uint8x8_t d6, d7, d8, d9, d10, d11, d12, d13, d14;
-    uint8x8_t d15, d16, d17, d18, d19, d20, d21;
-    uint32x4x2_t q2tmp0, q2tmp1, q2tmp2, q2tmp3;
-    uint16x8x2_t q2tmp4, q2tmp5, q2tmp6, q2tmp7;
-    uint8x16x2_t q2tmp8, q2tmp9, q2tmp10, q2tmp11;
-
-    qblimit = vdupq_n_u8(blimit);
-    qlimit = vdupq_n_u8(limit);
-    qthresh = vdupq_n_u8(thresh);
-
-    us = u - 4;
-    vs = v - 4;
-    d6 = vld1_u8(us);
-    us += pitch;
-    d7 = vld1_u8(vs);
-    vs += pitch;
-    d8 = vld1_u8(us);
-    us += pitch;
-    d9 = vld1_u8(vs);
-    vs += pitch;
-    d10 = vld1_u8(us);
-    us += pitch;
-    d11 = vld1_u8(vs);
-    vs += pitch;
-    d12 = vld1_u8(us);
-    us += pitch;
-    d13 = vld1_u8(vs);
-    vs += pitch;
-    d14 = vld1_u8(us);
-    us += pitch;
-    d15 = vld1_u8(vs);
-    vs += pitch;
-    d16 = vld1_u8(us);
-    us += pitch;
-    d17 = vld1_u8(vs);
-    vs += pitch;
-    d18 = vld1_u8(us);
-    us += pitch;
-    d19 = vld1_u8(vs);
-    vs += pitch;
-    d20 = vld1_u8(us);
-    d21 = vld1_u8(vs);
-
-    q3 = vcombine_u8(d6, d7);
-    q4 = vcombine_u8(d8, d9);
-    q5 = vcombine_u8(d10, d11);
-    q6 = vcombine_u8(d12, d13);
-    q7 = vcombine_u8(d14, d15);
-    q8 = vcombine_u8(d16, d17);
-    q9 = vcombine_u8(d18, d19);
-    q10 = vcombine_u8(d20, d21);
-
-    q2tmp0 = vtrnq_u32(vreinterpretq_u32_u8(q3), vreinterpretq_u32_u8(q7));
-    q2tmp1 = vtrnq_u32(vreinterpretq_u32_u8(q4), vreinterpretq_u32_u8(q8));
-    q2tmp2 = vtrnq_u32(vreinterpretq_u32_u8(q5), vreinterpretq_u32_u8(q9));
-    q2tmp3 = vtrnq_u32(vreinterpretq_u32_u8(q6), vreinterpretq_u32_u8(q10));
-
-    q2tmp4 = vtrnq_u16(vreinterpretq_u16_u32(q2tmp0.val[0]),
-                       vreinterpretq_u16_u32(q2tmp2.val[0]));
-    q2tmp5 = vtrnq_u16(vreinterpretq_u16_u32(q2tmp1.val[0]),
-                       vreinterpretq_u16_u32(q2tmp3.val[0]));
-    q2tmp6 = vtrnq_u16(vreinterpretq_u16_u32(q2tmp0.val[1]),
-                       vreinterpretq_u16_u32(q2tmp2.val[1]));
-    q2tmp7 = vtrnq_u16(vreinterpretq_u16_u32(q2tmp1.val[1]),
-                       vreinterpretq_u16_u32(q2tmp3.val[1]));
-
-    q2tmp8  = vtrnq_u8(vreinterpretq_u8_u16(q2tmp4.val[0]),
-                       vreinterpretq_u8_u16(q2tmp5.val[0]));
-    q2tmp9  = vtrnq_u8(vreinterpretq_u8_u16(q2tmp4.val[1]),
-                       vreinterpretq_u8_u16(q2tmp5.val[1]));
-    q2tmp10 = vtrnq_u8(vreinterpretq_u8_u16(q2tmp6.val[0]),
-                       vreinterpretq_u8_u16(q2tmp7.val[0]));
-    q2tmp11 = vtrnq_u8(vreinterpretq_u8_u16(q2tmp6.val[1]),
-                       vreinterpretq_u8_u16(q2tmp7.val[1]));
-
-    q3 = q2tmp8.val[0];
-    q4 = q2tmp8.val[1];
-    q5 = q2tmp9.val[0];
-    q6 = q2tmp9.val[1];
-    q7 = q2tmp10.val[0];
-    q8 = q2tmp10.val[1];
-    q9 = q2tmp11.val[0];
-    q10 = q2tmp11.val[1];
-
-    vp8_mbloop_filter_neon(qblimit, qlimit, qthresh, q3, q4,
-                         q5, q6, q7, q8, q9, q10,
-                         &q4, &q5, &q6, &q7, &q8, &q9);
-
-    q2tmp0 = vtrnq_u32(vreinterpretq_u32_u8(q3), vreinterpretq_u32_u8(q7));
-    q2tmp1 = vtrnq_u32(vreinterpretq_u32_u8(q4), vreinterpretq_u32_u8(q8));
-    q2tmp2 = vtrnq_u32(vreinterpretq_u32_u8(q5), vreinterpretq_u32_u8(q9));
-    q2tmp3 = vtrnq_u32(vreinterpretq_u32_u8(q6), vreinterpretq_u32_u8(q10));
-
-    q2tmp4 = vtrnq_u16(vreinterpretq_u16_u32(q2tmp0.val[0]),
-                       vreinterpretq_u16_u32(q2tmp2.val[0]));
-    q2tmp5 = vtrnq_u16(vreinterpretq_u16_u32(q2tmp1.val[0]),
-                       vreinterpretq_u16_u32(q2tmp3.val[0]));
-    q2tmp6 = vtrnq_u16(vreinterpretq_u16_u32(q2tmp0.val[1]),
-                       vreinterpretq_u16_u32(q2tmp2.val[1]));
-    q2tmp7 = vtrnq_u16(vreinterpretq_u16_u32(q2tmp1.val[1]),
-                       vreinterpretq_u16_u32(q2tmp3.val[1]));
-
-    q2tmp8  = vtrnq_u8(vreinterpretq_u8_u16(q2tmp4.val[0]),
-                       vreinterpretq_u8_u16(q2tmp5.val[0]));
-    q2tmp9  = vtrnq_u8(vreinterpretq_u8_u16(q2tmp4.val[1]),
-                       vreinterpretq_u8_u16(q2tmp5.val[1]));
-    q2tmp10 = vtrnq_u8(vreinterpretq_u8_u16(q2tmp6.val[0]),
-                       vreinterpretq_u8_u16(q2tmp7.val[0]));
-    q2tmp11 = vtrnq_u8(vreinterpretq_u8_u16(q2tmp6.val[1]),
-                       vreinterpretq_u8_u16(q2tmp7.val[1]));
-
-    q3 = q2tmp8.val[0];
-    q4 = q2tmp8.val[1];
-    q5 = q2tmp9.val[0];
-    q6 = q2tmp9.val[1];
-    q7 = q2tmp10.val[0];
-    q8 = q2tmp10.val[1];
-    q9 = q2tmp11.val[0];
-    q10 = q2tmp11.val[1];
-
-    ud = u - 4;
-    vst1_u8(ud, vget_low_u8(q3));
-    ud += pitch;
-    vst1_u8(ud, vget_low_u8(q4));
-    ud += pitch;
-    vst1_u8(ud, vget_low_u8(q5));
-    ud += pitch;
-    vst1_u8(ud, vget_low_u8(q6));
-    ud += pitch;
-    vst1_u8(ud, vget_low_u8(q7));
-    ud += pitch;
-    vst1_u8(ud, vget_low_u8(q8));
-    ud += pitch;
-    vst1_u8(ud, vget_low_u8(q9));
-    ud += pitch;
-    vst1_u8(ud, vget_low_u8(q10));
-
-    vd = v - 4;
-    vst1_u8(vd, vget_high_u8(q3));
-    vd += pitch;
-    vst1_u8(vd, vget_high_u8(q4));
-    vd += pitch;
-    vst1_u8(vd, vget_high_u8(q5));
-    vd += pitch;
-    vst1_u8(vd, vget_high_u8(q6));
-    vd += pitch;
-    vst1_u8(vd, vget_high_u8(q7));
-    vd += pitch;
-    vst1_u8(vd, vget_high_u8(q8));
-    vd += pitch;
-    vst1_u8(vd, vget_high_u8(q9));
-    vd += pitch;
-    vst1_u8(vd, vget_high_u8(q10));
-    return;
-}
diff --git a/vp8/common/arm/neon/shortidct4x4llm_neon.c b/vp8/common/arm/neon/shortidct4x4llm_neon.c
deleted file mode 100644 (file)
index 373afa6..0000000
+++ /dev/null
@@ -1,123 +0,0 @@
-/*
- *  Copyright (c) 2014 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.
- */
-
-#include <arm_neon.h>
-
-static const int16_t cospi8sqrt2minus1 = 20091;
-static const int16_t sinpi8sqrt2       = 35468;
-
-void vp8_short_idct4x4llm_neon(
-        int16_t *input,
-        unsigned char *pred_ptr,
-        int pred_stride,
-        unsigned char *dst_ptr,
-        int dst_stride) {
-    int i;
-    uint32x2_t d6u32 = vdup_n_u32(0);
-    uint8x8_t d1u8;
-    int16x4_t d2, d3, d4, d5, d10, d11, d12, d13;
-    uint16x8_t q1u16;
-    int16x8_t q1s16, q2s16, q3s16, q4s16;
-    int32x2x2_t v2tmp0, v2tmp1;
-    int16x4x2_t v2tmp2, v2tmp3;
-
-    d2 = vld1_s16(input);
-    d3 = vld1_s16(input + 4);
-    d4 = vld1_s16(input + 8);
-    d5 = vld1_s16(input + 12);
-
-    // 1st for loop
-    q1s16 = vcombine_s16(d2, d4);  // Swap d3 d4 here
-    q2s16 = vcombine_s16(d3, d5);
-
-    q3s16 = vqdmulhq_n_s16(q2s16, sinpi8sqrt2);
-    q4s16 = vqdmulhq_n_s16(q2s16, cospi8sqrt2minus1);
-
-    d12 = vqadd_s16(vget_low_s16(q1s16), vget_high_s16(q1s16));  // a1
-    d13 = vqsub_s16(vget_low_s16(q1s16), vget_high_s16(q1s16));  // b1
-
-    q3s16 = vshrq_n_s16(q3s16, 1);
-    q4s16 = vshrq_n_s16(q4s16, 1);
-
-    q3s16 = vqaddq_s16(q3s16, q2s16);
-    q4s16 = vqaddq_s16(q4s16, q2s16);
-
-    d10 = vqsub_s16(vget_low_s16(q3s16), vget_high_s16(q4s16));  // c1
-    d11 = vqadd_s16(vget_high_s16(q3s16), vget_low_s16(q4s16));  // d1
-
-    d2 = vqadd_s16(d12, d11);
-    d3 = vqadd_s16(d13, d10);
-    d4 = vqsub_s16(d13, d10);
-    d5 = vqsub_s16(d12, d11);
-
-    v2tmp0 = vtrn_s32(vreinterpret_s32_s16(d2), vreinterpret_s32_s16(d4));
-    v2tmp1 = vtrn_s32(vreinterpret_s32_s16(d3), vreinterpret_s32_s16(d5));
-    v2tmp2 = vtrn_s16(vreinterpret_s16_s32(v2tmp0.val[0]),
-                      vreinterpret_s16_s32(v2tmp1.val[0]));
-    v2tmp3 = vtrn_s16(vreinterpret_s16_s32(v2tmp0.val[1]),
-                      vreinterpret_s16_s32(v2tmp1.val[1]));
-
-    // 2nd for loop
-    q1s16 = vcombine_s16(v2tmp2.val[0], v2tmp3.val[0]);
-    q2s16 = vcombine_s16(v2tmp2.val[1], v2tmp3.val[1]);
-
-    q3s16 = vqdmulhq_n_s16(q2s16, sinpi8sqrt2);
-    q4s16 = vqdmulhq_n_s16(q2s16, cospi8sqrt2minus1);
-
-    d12 = vqadd_s16(vget_low_s16(q1s16), vget_high_s16(q1s16));  // a1
-    d13 = vqsub_s16(vget_low_s16(q1s16), vget_high_s16(q1s16));  // b1
-
-    q3s16 = vshrq_n_s16(q3s16, 1);
-    q4s16 = vshrq_n_s16(q4s16, 1);
-
-    q3s16 = vqaddq_s16(q3s16, q2s16);
-    q4s16 = vqaddq_s16(q4s16, q2s16);
-
-    d10 = vqsub_s16(vget_low_s16(q3s16), vget_high_s16(q4s16));  // c1
-    d11 = vqadd_s16(vget_high_s16(q3s16), vget_low_s16(q4s16));  // d1
-
-    d2 = vqadd_s16(d12, d11);
-    d3 = vqadd_s16(d13, d10);
-    d4 = vqsub_s16(d13, d10);
-    d5 = vqsub_s16(d12, d11);
-
-    d2 = vrshr_n_s16(d2, 3);
-    d3 = vrshr_n_s16(d3, 3);
-    d4 = vrshr_n_s16(d4, 3);
-    d5 = vrshr_n_s16(d5, 3);
-
-    v2tmp0 = vtrn_s32(vreinterpret_s32_s16(d2), vreinterpret_s32_s16(d4));
-    v2tmp1 = vtrn_s32(vreinterpret_s32_s16(d3), vreinterpret_s32_s16(d5));
-    v2tmp2 = vtrn_s16(vreinterpret_s16_s32(v2tmp0.val[0]),
-                      vreinterpret_s16_s32(v2tmp1.val[0]));
-    v2tmp3 = vtrn_s16(vreinterpret_s16_s32(v2tmp0.val[1]),
-                      vreinterpret_s16_s32(v2tmp1.val[1]));
-
-    q1s16 = vcombine_s16(v2tmp2.val[0], v2tmp2.val[1]);
-    q2s16 = vcombine_s16(v2tmp3.val[0], v2tmp3.val[1]);
-
-    // dc_only_idct_add
-    for (i = 0; i < 2; i++, q1s16 = q2s16) {
-        d6u32 = vld1_lane_u32((const uint32_t *)pred_ptr, d6u32, 0);
-        pred_ptr += pred_stride;
-        d6u32 = vld1_lane_u32((const uint32_t *)pred_ptr, d6u32, 1);
-        pred_ptr += pred_stride;
-
-        q1u16 = vaddw_u8(vreinterpretq_u16_s16(q1s16),
-                         vreinterpret_u8_u32(d6u32));
-        d1u8 = vqmovun_s16(vreinterpretq_s16_u16(q1u16));
-
-        vst1_lane_u32((uint32_t *)dst_ptr, vreinterpret_u32_u8(d1u8), 0);
-        dst_ptr += dst_stride;
-        vst1_lane_u32((uint32_t *)dst_ptr, vreinterpret_u32_u8(d1u8), 1);
-        dst_ptr += dst_stride;
-    }
-    return;
-}
diff --git a/vp8/common/arm/neon/sixtappredict_neon.c b/vp8/common/arm/neon/sixtappredict_neon.c
deleted file mode 100644 (file)
index 49d8d22..0000000
+++ /dev/null
@@ -1,1377 +0,0 @@
-/*
- *  Copyright (c) 2014 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.
- */
-
-#include <arm_neon.h>
-#include "vpx_ports/mem.h"
-
-static const int8_t vp8_sub_pel_filters[8][8] = {
-    {0,  0,  128,   0,   0, 0, 0, 0},  /* note that 1/8 pel positionyys are */
-    {0, -6,  123,  12,  -1, 0, 0, 0},  /*    just as per alpha -0.5 bicubic */
-    {2, -11, 108,  36,  -8, 1, 0, 0},  /* New 1/4 pel 6 tap filter */
-    {0, -9,   93,  50,  -6, 0, 0, 0},
-    {3, -16,  77,  77, -16, 3, 0, 0},  /* New 1/2 pel 6 tap filter */
-    {0, -6,   50,  93,  -9, 0, 0, 0},
-    {1, -8,   36, 108, -11, 2, 0, 0},  /* New 1/4 pel 6 tap filter */
-    {0, -1,   12, 123,  -6, 0, 0, 0},
-};
-
-void vp8_sixtap_predict8x4_neon(
-        unsigned char *src_ptr,
-        int src_pixels_per_line,
-        int xoffset,
-        int yoffset,
-        unsigned char *dst_ptr,
-        int dst_pitch) {
-    unsigned char *src;
-    uint8x8_t d0u8, d1u8, d2u8, d3u8, d4u8, d5u8, d6u8, d7u8, d8u8, d9u8;
-    uint8x8_t d22u8, d23u8, d24u8, d25u8, d26u8;
-    uint8x8_t d27u8, d28u8, d29u8, d30u8, d31u8;
-    int8x8_t dtmps8, d0s8, d1s8, d2s8, d3s8, d4s8, d5s8;
-    uint16x8_t q3u16, q4u16, q5u16, q6u16, q7u16;
-    uint16x8_t q8u16, q9u16, q10u16, q11u16, q12u16;
-    int16x8_t q3s16, q4s16, q5s16, q6s16, q7s16;
-    int16x8_t q8s16, q9s16, q10s16, q11s16, q12s16;
-    uint8x16_t q3u8, q4u8, q5u8, q6u8, q7u8;
-
-    if (xoffset == 0) {  // secondpass_filter8x4_only
-        // load second_pass filter
-        dtmps8 = vld1_s8(vp8_sub_pel_filters[yoffset]);
-        d0s8 = vdup_lane_s8(dtmps8, 0);
-        d1s8 = vdup_lane_s8(dtmps8, 1);
-        d2s8 = vdup_lane_s8(dtmps8, 2);
-        d3s8 = vdup_lane_s8(dtmps8, 3);
-        d4s8 = vdup_lane_s8(dtmps8, 4);
-        d5s8 = vdup_lane_s8(dtmps8, 5);
-        d0u8 = vreinterpret_u8_s8(vabs_s8(d0s8));
-        d1u8 = vreinterpret_u8_s8(vabs_s8(d1s8));
-        d2u8 = vreinterpret_u8_s8(vabs_s8(d2s8));
-        d3u8 = vreinterpret_u8_s8(vabs_s8(d3s8));
-        d4u8 = vreinterpret_u8_s8(vabs_s8(d4s8));
-        d5u8 = vreinterpret_u8_s8(vabs_s8(d5s8));
-
-        // load src data
-        src = src_ptr - src_pixels_per_line * 2;
-        d22u8 = vld1_u8(src);
-        src += src_pixels_per_line;
-        d23u8 = vld1_u8(src);
-        src += src_pixels_per_line;
-        d24u8 = vld1_u8(src);
-        src += src_pixels_per_line;
-        d25u8 = vld1_u8(src);
-        src += src_pixels_per_line;
-        d26u8 = vld1_u8(src);
-        src += src_pixels_per_line;
-        d27u8 = vld1_u8(src);
-        src += src_pixels_per_line;
-        d28u8 = vld1_u8(src);
-        src += src_pixels_per_line;
-        d29u8 = vld1_u8(src);
-        src += src_pixels_per_line;
-        d30u8 = vld1_u8(src);
-
-        q3u16 = vmull_u8(d22u8, d0u8);
-        q4u16 = vmull_u8(d23u8, d0u8);
-        q5u16 = vmull_u8(d24u8, d0u8);
-        q6u16 = vmull_u8(d25u8, d0u8);
-
-        q3u16 = vmlsl_u8(q3u16, d23u8, d1u8);
-        q4u16 = vmlsl_u8(q4u16, d24u8, d1u8);
-        q5u16 = vmlsl_u8(q5u16, d25u8, d1u8);
-        q6u16 = vmlsl_u8(q6u16, d26u8, d1u8);
-
-        q3u16 = vmlsl_u8(q3u16, d26u8, d4u8);
-        q4u16 = vmlsl_u8(q4u16, d27u8, d4u8);
-        q5u16 = vmlsl_u8(q5u16, d28u8, d4u8);
-        q6u16 = vmlsl_u8(q6u16, d29u8, d4u8);
-
-        q3u16 = vmlal_u8(q3u16, d24u8, d2u8);
-        q4u16 = vmlal_u8(q4u16, d25u8, d2u8);
-        q5u16 = vmlal_u8(q5u16, d26u8, d2u8);
-        q6u16 = vmlal_u8(q6u16, d27u8, d2u8);
-
-        q3u16 = vmlal_u8(q3u16, d27u8, d5u8);
-        q4u16 = vmlal_u8(q4u16, d28u8, d5u8);
-        q5u16 = vmlal_u8(q5u16, d29u8, d5u8);
-        q6u16 = vmlal_u8(q6u16, d30u8, d5u8);
-
-        q7u16 = vmull_u8(d25u8, d3u8);
-        q8u16 = vmull_u8(d26u8, d3u8);
-        q9u16 = vmull_u8(d27u8, d3u8);
-        q10u16 = vmull_u8(d28u8, d3u8);
-
-        q3s16 = vreinterpretq_s16_u16(q3u16);
-        q4s16 = vreinterpretq_s16_u16(q4u16);
-        q5s16 = vreinterpretq_s16_u16(q5u16);
-        q6s16 = vreinterpretq_s16_u16(q6u16);
-        q7s16 = vreinterpretq_s16_u16(q7u16);
-        q8s16 = vreinterpretq_s16_u16(q8u16);
-        q9s16 = vreinterpretq_s16_u16(q9u16);
-        q10s16 = vreinterpretq_s16_u16(q10u16);
-
-        q7s16 = vqaddq_s16(q7s16, q3s16);
-        q8s16 = vqaddq_s16(q8s16, q4s16);
-        q9s16 = vqaddq_s16(q9s16, q5s16);
-        q10s16 = vqaddq_s16(q10s16, q6s16);
-
-        d6u8 = vqrshrun_n_s16(q7s16, 7);
-        d7u8 = vqrshrun_n_s16(q8s16, 7);
-        d8u8 = vqrshrun_n_s16(q9s16, 7);
-        d9u8 = vqrshrun_n_s16(q10s16, 7);
-
-        vst1_u8(dst_ptr, d6u8);
-        dst_ptr += dst_pitch;
-        vst1_u8(dst_ptr, d7u8);
-        dst_ptr += dst_pitch;
-        vst1_u8(dst_ptr, d8u8);
-        dst_ptr += dst_pitch;
-        vst1_u8(dst_ptr, d9u8);
-        return;
-    }
-
-    // load first_pass filter
-    dtmps8 = vld1_s8(vp8_sub_pel_filters[xoffset]);
-    d0s8 = vdup_lane_s8(dtmps8, 0);
-    d1s8 = vdup_lane_s8(dtmps8, 1);
-    d2s8 = vdup_lane_s8(dtmps8, 2);
-    d3s8 = vdup_lane_s8(dtmps8, 3);
-    d4s8 = vdup_lane_s8(dtmps8, 4);
-    d5s8 = vdup_lane_s8(dtmps8, 5);
-    d0u8 = vreinterpret_u8_s8(vabs_s8(d0s8));
-    d1u8 = vreinterpret_u8_s8(vabs_s8(d1s8));
-    d2u8 = vreinterpret_u8_s8(vabs_s8(d2s8));
-    d3u8 = vreinterpret_u8_s8(vabs_s8(d3s8));
-    d4u8 = vreinterpret_u8_s8(vabs_s8(d4s8));
-    d5u8 = vreinterpret_u8_s8(vabs_s8(d5s8));
-
-    // First pass: output_height lines x output_width columns (9x4)
-    if (yoffset == 0)  // firstpass_filter4x4_only
-        src = src_ptr - 2;
-    else
-        src = src_ptr - 2 - (src_pixels_per_line * 2);
-    q3u8 = vld1q_u8(src);
-    src += src_pixels_per_line;
-    q4u8 = vld1q_u8(src);
-    src += src_pixels_per_line;
-    q5u8 = vld1q_u8(src);
-    src += src_pixels_per_line;
-    q6u8 = vld1q_u8(src);
-
-    q7u16  = vmull_u8(vget_low_u8(q3u8), d0u8);
-    q8u16  = vmull_u8(vget_low_u8(q4u8), d0u8);
-    q9u16  = vmull_u8(vget_low_u8(q5u8), d0u8);
-    q10u16 = vmull_u8(vget_low_u8(q6u8), d0u8);
-
-    d28u8 = vext_u8(vget_low_u8(q3u8), vget_high_u8(q3u8), 1);
-    d29u8 = vext_u8(vget_low_u8(q4u8), vget_high_u8(q4u8), 1);
-    d30u8 = vext_u8(vget_low_u8(q5u8), vget_high_u8(q5u8), 1);
-    d31u8 = vext_u8(vget_low_u8(q6u8), vget_high_u8(q6u8), 1);
-
-    q7u16  = vmlsl_u8(q7u16, d28u8, d1u8);
-    q8u16  = vmlsl_u8(q8u16, d29u8, d1u8);
-    q9u16  = vmlsl_u8(q9u16, d30u8, d1u8);
-    q10u16 = vmlsl_u8(q10u16, d31u8, d1u8);
-
-    d28u8 = vext_u8(vget_low_u8(q3u8), vget_high_u8(q3u8), 4);
-    d29u8 = vext_u8(vget_low_u8(q4u8), vget_high_u8(q4u8), 4);
-    d30u8 = vext_u8(vget_low_u8(q5u8), vget_high_u8(q5u8), 4);
-    d31u8 = vext_u8(vget_low_u8(q6u8), vget_high_u8(q6u8), 4);
-
-    q7u16  = vmlsl_u8(q7u16, d28u8, d4u8);
-    q8u16  = vmlsl_u8(q8u16, d29u8, d4u8);
-    q9u16  = vmlsl_u8(q9u16, d30u8, d4u8);
-    q10u16 = vmlsl_u8(q10u16, d31u8, d4u8);
-
-    d28u8 = vext_u8(vget_low_u8(q3u8), vget_high_u8(q3u8), 2);
-    d29u8 = vext_u8(vget_low_u8(q4u8), vget_high_u8(q4u8), 2);
-    d30u8 = vext_u8(vget_low_u8(q5u8), vget_high_u8(q5u8), 2);
-    d31u8 = vext_u8(vget_low_u8(q6u8), vget_high_u8(q6u8), 2);
-
-    q7u16  = vmlal_u8(q7u16, d28u8, d2u8);
-    q8u16  = vmlal_u8(q8u16, d29u8, d2u8);
-    q9u16  = vmlal_u8(q9u16, d30u8, d2u8);
-    q10u16 = vmlal_u8(q10u16, d31u8, d2u8);
-
-    d28u8 = vext_u8(vget_low_u8(q3u8), vget_high_u8(q3u8), 5);
-    d29u8 = vext_u8(vget_low_u8(q4u8), vget_high_u8(q4u8), 5);
-    d30u8 = vext_u8(vget_low_u8(q5u8), vget_high_u8(q5u8), 5);
-    d31u8 = vext_u8(vget_low_u8(q6u8), vget_high_u8(q6u8), 5);
-
-    q7u16 = vmlal_u8(q7u16, d28u8, d5u8);
-    q8u16 = vmlal_u8(q8u16, d29u8, d5u8);
-    q9u16 = vmlal_u8(q9u16, d30u8, d5u8);
-    q10u16 = vmlal_u8(q10u16, d31u8, d5u8);
-
-    d28u8 = vext_u8(vget_low_u8(q3u8), vget_high_u8(q3u8), 3);
-    d29u8 = vext_u8(vget_low_u8(q4u8), vget_high_u8(q4u8), 3);
-    d30u8 = vext_u8(vget_low_u8(q5u8), vget_high_u8(q5u8), 3);
-    d31u8 = vext_u8(vget_low_u8(q6u8), vget_high_u8(q6u8), 3);
-
-    q3u16 = vmull_u8(d28u8, d3u8);
-    q4u16 = vmull_u8(d29u8, d3u8);
-    q5u16 = vmull_u8(d30u8, d3u8);
-    q6u16 = vmull_u8(d31u8, d3u8);
-
-    q3s16 = vreinterpretq_s16_u16(q3u16);
-    q4s16 = vreinterpretq_s16_u16(q4u16);
-    q5s16 = vreinterpretq_s16_u16(q5u16);
-    q6s16 = vreinterpretq_s16_u16(q6u16);
-    q7s16 = vreinterpretq_s16_u16(q7u16);
-    q8s16 = vreinterpretq_s16_u16(q8u16);
-    q9s16 = vreinterpretq_s16_u16(q9u16);
-    q10s16 = vreinterpretq_s16_u16(q10u16);
-
-    q7s16 = vqaddq_s16(q7s16, q3s16);
-    q8s16 = vqaddq_s16(q8s16, q4s16);
-    q9s16 = vqaddq_s16(q9s16, q5s16);
-    q10s16 = vqaddq_s16(q10s16, q6s16);
-
-    d22u8 = vqrshrun_n_s16(q7s16, 7);
-    d23u8 = vqrshrun_n_s16(q8s16, 7);
-    d24u8 = vqrshrun_n_s16(q9s16, 7);
-    d25u8 = vqrshrun_n_s16(q10s16, 7);
-
-    if (yoffset == 0) {  // firstpass_filter8x4_only
-        vst1_u8(dst_ptr, d22u8);
-        dst_ptr += dst_pitch;
-        vst1_u8(dst_ptr, d23u8);
-        dst_ptr += dst_pitch;
-        vst1_u8(dst_ptr, d24u8);
-        dst_ptr += dst_pitch;
-        vst1_u8(dst_ptr, d25u8);
-        return;
-    }
-
-    // First Pass on rest 5-line data
-    src += src_pixels_per_line;
-    q3u8 = vld1q_u8(src);
-    src += src_pixels_per_line;
-    q4u8 = vld1q_u8(src);
-    src += src_pixels_per_line;
-    q5u8 = vld1q_u8(src);
-    src += src_pixels_per_line;
-    q6u8 = vld1q_u8(src);
-    src += src_pixels_per_line;
-    q7u8 = vld1q_u8(src);
-
-    q8u16 = vmull_u8(vget_low_u8(q3u8), d0u8);
-    q9u16 = vmull_u8(vget_low_u8(q4u8), d0u8);
-    q10u16 = vmull_u8(vget_low_u8(q5u8), d0u8);
-    q11u16 = vmull_u8(vget_low_u8(q6u8), d0u8);
-    q12u16 = vmull_u8(vget_low_u8(q7u8), d0u8);
-
-    d27u8 = vext_u8(vget_low_u8(q3u8), vget_high_u8(q3u8), 1);
-    d28u8 = vext_u8(vget_low_u8(q4u8), vget_high_u8(q4u8), 1);
-    d29u8 = vext_u8(vget_low_u8(q5u8), vget_high_u8(q5u8), 1);
-    d30u8 = vext_u8(vget_low_u8(q6u8), vget_high_u8(q6u8), 1);
-    d31u8 = vext_u8(vget_low_u8(q7u8), vget_high_u8(q7u8), 1);
-
-    q8u16  = vmlsl_u8(q8u16, d27u8, d1u8);
-    q9u16  = vmlsl_u8(q9u16, d28u8, d1u8);
-    q10u16 = vmlsl_u8(q10u16, d29u8, d1u8);
-    q11u16 = vmlsl_u8(q11u16, d30u8, d1u8);
-    q12u16 = vmlsl_u8(q12u16, d31u8, d1u8);
-
-    d27u8 = vext_u8(vget_low_u8(q3u8), vget_high_u8(q3u8), 4);
-    d28u8 = vext_u8(vget_low_u8(q4u8), vget_high_u8(q4u8), 4);
-    d29u8 = vext_u8(vget_low_u8(q5u8), vget_high_u8(q5u8), 4);
-    d30u8 = vext_u8(vget_low_u8(q6u8), vget_high_u8(q6u8), 4);
-    d31u8 = vext_u8(vget_low_u8(q7u8), vget_high_u8(q7u8), 4);
-
-    q8u16  = vmlsl_u8(q8u16, d27u8, d4u8);
-    q9u16  = vmlsl_u8(q9u16, d28u8, d4u8);
-    q10u16 = vmlsl_u8(q10u16, d29u8, d4u8);
-    q11u16 = vmlsl_u8(q11u16, d30u8, d4u8);
-    q12u16 = vmlsl_u8(q12u16, d31u8, d4u8);
-
-    d27u8 = vext_u8(vget_low_u8(q3u8), vget_high_u8(q3u8), 2);
-    d28u8 = vext_u8(vget_low_u8(q4u8), vget_high_u8(q4u8), 2);
-    d29u8 = vext_u8(vget_low_u8(q5u8), vget_high_u8(q5u8), 2);
-    d30u8 = vext_u8(vget_low_u8(q6u8), vget_high_u8(q6u8), 2);
-    d31u8 = vext_u8(vget_low_u8(q7u8), vget_high_u8(q7u8), 2);
-
-    q8u16  = vmlal_u8(q8u16, d27u8, d2u8);
-    q9u16  = vmlal_u8(q9u16, d28u8, d2u8);
-    q10u16 = vmlal_u8(q10u16, d29u8, d2u8);
-    q11u16 = vmlal_u8(q11u16, d30u8, d2u8);
-    q12u16 = vmlal_u8(q12u16, d31u8, d2u8);
-
-    d27u8 = vext_u8(vget_low_u8(q3u8), vget_high_u8(q3u8), 5);
-    d28u8 = vext_u8(vget_low_u8(q4u8), vget_high_u8(q4u8), 5);
-    d29u8 = vext_u8(vget_low_u8(q5u8), vget_high_u8(q5u8), 5);
-    d30u8 = vext_u8(vget_low_u8(q6u8), vget_high_u8(q6u8), 5);
-    d31u8 = vext_u8(vget_low_u8(q7u8), vget_high_u8(q7u8), 5);
-
-    q8u16  = vmlal_u8(q8u16, d27u8, d5u8);
-    q9u16  = vmlal_u8(q9u16, d28u8, d5u8);
-    q10u16 = vmlal_u8(q10u16, d29u8, d5u8);
-    q11u16 = vmlal_u8(q11u16, d30u8, d5u8);
-    q12u16 = vmlal_u8(q12u16, d31u8, d5u8);
-
-    d27u8 = vext_u8(vget_low_u8(q3u8), vget_high_u8(q3u8), 3);
-    d28u8 = vext_u8(vget_low_u8(q4u8), vget_high_u8(q4u8), 3);
-    d29u8 = vext_u8(vget_low_u8(q5u8), vget_high_u8(q5u8), 3);
-    d30u8 = vext_u8(vget_low_u8(q6u8), vget_high_u8(q6u8), 3);
-    d31u8 = vext_u8(vget_low_u8(q7u8), vget_high_u8(q7u8), 3);
-
-    q3u16 = vmull_u8(d27u8, d3u8);
-    q4u16 = vmull_u8(d28u8, d3u8);
-    q5u16 = vmull_u8(d29u8, d3u8);
-    q6u16 = vmull_u8(d30u8, d3u8);
-    q7u16 = vmull_u8(d31u8, d3u8);
-
-    q3s16 = vreinterpretq_s16_u16(q3u16);
-    q4s16 = vreinterpretq_s16_u16(q4u16);
-    q5s16 = vreinterpretq_s16_u16(q5u16);
-    q6s16 = vreinterpretq_s16_u16(q6u16);
-    q7s16 = vreinterpretq_s16_u16(q7u16);
-    q8s16 = vreinterpretq_s16_u16(q8u16);
-    q9s16 = vreinterpretq_s16_u16(q9u16);
-    q10s16 = vreinterpretq_s16_u16(q10u16);
-    q11s16 = vreinterpretq_s16_u16(q11u16);
-    q12s16 = vreinterpretq_s16_u16(q12u16);
-
-    q8s16 = vqaddq_s16(q8s16, q3s16);
-    q9s16 = vqaddq_s16(q9s16, q4s16);
-    q10s16 = vqaddq_s16(q10s16, q5s16);
-    q11s16 = vqaddq_s16(q11s16, q6s16);
-    q12s16 = vqaddq_s16(q12s16, q7s16);
-
-    d26u8 = vqrshrun_n_s16(q8s16, 7);
-    d27u8 = vqrshrun_n_s16(q9s16, 7);
-    d28u8 = vqrshrun_n_s16(q10s16, 7);
-    d29u8 = vqrshrun_n_s16(q11s16, 7);
-    d30u8 = vqrshrun_n_s16(q12s16, 7);
-
-    // Second pass: 8x4
-    dtmps8 = vld1_s8(vp8_sub_pel_filters[yoffset]);
-    d0s8 = vdup_lane_s8(dtmps8, 0);
-    d1s8 = vdup_lane_s8(dtmps8, 1);
-    d2s8 = vdup_lane_s8(dtmps8, 2);
-    d3s8 = vdup_lane_s8(dtmps8, 3);
-    d4s8 = vdup_lane_s8(dtmps8, 4);
-    d5s8 = vdup_lane_s8(dtmps8, 5);
-    d0u8 = vreinterpret_u8_s8(vabs_s8(d0s8));
-    d1u8 = vreinterpret_u8_s8(vabs_s8(d1s8));
-    d2u8 = vreinterpret_u8_s8(vabs_s8(d2s8));
-    d3u8 = vreinterpret_u8_s8(vabs_s8(d3s8));
-    d4u8 = vreinterpret_u8_s8(vabs_s8(d4s8));
-    d5u8 = vreinterpret_u8_s8(vabs_s8(d5s8));
-
-    q3u16 = vmull_u8(d22u8, d0u8);
-    q4u16 = vmull_u8(d23u8, d0u8);
-    q5u16 = vmull_u8(d24u8, d0u8);
-    q6u16 = vmull_u8(d25u8, d0u8);
-
-    q3u16 = vmlsl_u8(q3u16, d23u8, d1u8);
-    q4u16 = vmlsl_u8(q4u16, d24u8, d1u8);
-    q5u16 = vmlsl_u8(q5u16, d25u8, d1u8);
-    q6u16 = vmlsl_u8(q6u16, d26u8, d1u8);
-
-    q3u16 = vmlsl_u8(q3u16, d26u8, d4u8);
-    q4u16 = vmlsl_u8(q4u16, d27u8, d4u8);
-    q5u16 = vmlsl_u8(q5u16, d28u8, d4u8);
-    q6u16 = vmlsl_u8(q6u16, d29u8, d4u8);
-
-    q3u16 = vmlal_u8(q3u16, d24u8, d2u8);
-    q4u16 = vmlal_u8(q4u16, d25u8, d2u8);
-    q5u16 = vmlal_u8(q5u16, d26u8, d2u8);
-    q6u16 = vmlal_u8(q6u16, d27u8, d2u8);
-
-    q3u16 = vmlal_u8(q3u16, d27u8, d5u8);
-    q4u16 = vmlal_u8(q4u16, d28u8, d5u8);
-    q5u16 = vmlal_u8(q5u16, d29u8, d5u8);
-    q6u16 = vmlal_u8(q6u16, d30u8, d5u8);
-
-    q7u16 = vmull_u8(d25u8, d3u8);
-    q8u16 = vmull_u8(d26u8, d3u8);
-    q9u16 = vmull_u8(d27u8, d3u8);
-    q10u16 = vmull_u8(d28u8, d3u8);
-
-    q3s16 = vreinterpretq_s16_u16(q3u16);
-    q4s16 = vreinterpretq_s16_u16(q4u16);
-    q5s16 = vreinterpretq_s16_u16(q5u16);
-    q6s16 = vreinterpretq_s16_u16(q6u16);
-    q7s16 = vreinterpretq_s16_u16(q7u16);
-    q8s16 = vreinterpretq_s16_u16(q8u16);
-    q9s16 = vreinterpretq_s16_u16(q9u16);
-    q10s16 = vreinterpretq_s16_u16(q10u16);
-
-    q7s16 = vqaddq_s16(q7s16, q3s16);
-    q8s16 = vqaddq_s16(q8s16, q4s16);
-    q9s16 = vqaddq_s16(q9s16, q5s16);
-    q10s16 = vqaddq_s16(q10s16, q6s16);
-
-    d6u8 = vqrshrun_n_s16(q7s16, 7);
-    d7u8 = vqrshrun_n_s16(q8s16, 7);
-    d8u8 = vqrshrun_n_s16(q9s16, 7);
-    d9u8 = vqrshrun_n_s16(q10s16, 7);
-
-    vst1_u8(dst_ptr, d6u8);
-    dst_ptr += dst_pitch;
-    vst1_u8(dst_ptr, d7u8);
-    dst_ptr += dst_pitch;
-    vst1_u8(dst_ptr, d8u8);
-    dst_ptr += dst_pitch;
-    vst1_u8(dst_ptr, d9u8);
-    return;
-}
-
-void vp8_sixtap_predict8x8_neon(
-        unsigned char *src_ptr,
-        int src_pixels_per_line,
-        int xoffset,
-        int yoffset,
-        unsigned char *dst_ptr,
-        int dst_pitch) {
-    unsigned char *src, *tmpp;
-    unsigned char tmp[64];
-    int i;
-    uint8x8_t d0u8, d1u8, d2u8, d3u8, d4u8, d5u8, d6u8, d7u8, d8u8, d9u8;
-    uint8x8_t d18u8, d19u8, d20u8, d21u8, d22u8, d23u8, d24u8, d25u8;
-    uint8x8_t d26u8, d27u8, d28u8, d29u8, d30u8, d31u8;
-    int8x8_t dtmps8, d0s8, d1s8, d2s8, d3s8, d4s8, d5s8;
-    uint16x8_t q3u16, q4u16, q5u16, q6u16, q7u16;
-    uint16x8_t q8u16, q9u16, q10u16, q11u16, q12u16;
-    int16x8_t q3s16, q4s16, q5s16, q6s16, q7s16;
-    int16x8_t q8s16, q9s16, q10s16, q11s16, q12s16;
-    uint8x16_t q3u8, q4u8, q5u8, q6u8, q7u8, q9u8, q10u8, q11u8, q12u8;
-
-    if (xoffset == 0) {  // secondpass_filter8x8_only
-        // load second_pass filter
-        dtmps8 = vld1_s8(vp8_sub_pel_filters[yoffset]);
-        d0s8 = vdup_lane_s8(dtmps8, 0);
-        d1s8 = vdup_lane_s8(dtmps8, 1);
-        d2s8 = vdup_lane_s8(dtmps8, 2);
-        d3s8 = vdup_lane_s8(dtmps8, 3);
-        d4s8 = vdup_lane_s8(dtmps8, 4);
-        d5s8 = vdup_lane_s8(dtmps8, 5);
-        d0u8 = vreinterpret_u8_s8(vabs_s8(d0s8));
-        d1u8 = vreinterpret_u8_s8(vabs_s8(d1s8));
-        d2u8 = vreinterpret_u8_s8(vabs_s8(d2s8));
-        d3u8 = vreinterpret_u8_s8(vabs_s8(d3s8));
-        d4u8 = vreinterpret_u8_s8(vabs_s8(d4s8));
-        d5u8 = vreinterpret_u8_s8(vabs_s8(d5s8));
-
-        // load src data
-        src = src_ptr - src_pixels_per_line * 2;
-        d18u8 = vld1_u8(src);
-        src += src_pixels_per_line;
-        d19u8 = vld1_u8(src);
-        src += src_pixels_per_line;
-        d20u8 = vld1_u8(src);
-        src += src_pixels_per_line;
-        d21u8 = vld1_u8(src);
-        src += src_pixels_per_line;
-        d22u8 = vld1_u8(src);
-        src += src_pixels_per_line;
-        d23u8 = vld1_u8(src);
-        src += src_pixels_per_line;
-        d24u8 = vld1_u8(src);
-        src += src_pixels_per_line;
-        d25u8 = vld1_u8(src);
-        src += src_pixels_per_line;
-        d26u8 = vld1_u8(src);
-        src += src_pixels_per_line;
-        d27u8 = vld1_u8(src);
-        src += src_pixels_per_line;
-        d28u8 = vld1_u8(src);
-        src += src_pixels_per_line;
-        d29u8 = vld1_u8(src);
-        src += src_pixels_per_line;
-        d30u8 = vld1_u8(src);
-
-        for (i = 2; i > 0; i--) {
-            q3u16 = vmull_u8(d18u8, d0u8);
-            q4u16 = vmull_u8(d19u8, d0u8);
-            q5u16 = vmull_u8(d20u8, d0u8);
-            q6u16 = vmull_u8(d21u8, d0u8);
-
-            q3u16 = vmlsl_u8(q3u16, d19u8, d1u8);
-            q4u16 = vmlsl_u8(q4u16, d20u8, d1u8);
-            q5u16 = vmlsl_u8(q5u16, d21u8, d1u8);
-            q6u16 = vmlsl_u8(q6u16, d22u8, d1u8);
-
-            q3u16 = vmlsl_u8(q3u16, d22u8, d4u8);
-            q4u16 = vmlsl_u8(q4u16, d23u8, d4u8);
-            q5u16 = vmlsl_u8(q5u16, d24u8, d4u8);
-            q6u16 = vmlsl_u8(q6u16, d25u8, d4u8);
-
-            q3u16 = vmlal_u8(q3u16, d20u8, d2u8);
-            q4u16 = vmlal_u8(q4u16, d21u8, d2u8);
-            q5u16 = vmlal_u8(q5u16, d22u8, d2u8);
-            q6u16 = vmlal_u8(q6u16, d23u8, d2u8);
-
-            q3u16 = vmlal_u8(q3u16, d23u8, d5u8);
-            q4u16 = vmlal_u8(q4u16, d24u8, d5u8);
-            q5u16 = vmlal_u8(q5u16, d25u8, d5u8);
-            q6u16 = vmlal_u8(q6u16, d26u8, d5u8);
-
-            q7u16 = vmull_u8(d21u8, d3u8);
-            q8u16 = vmull_u8(d22u8, d3u8);
-            q9u16 = vmull_u8(d23u8, d3u8);
-            q10u16 = vmull_u8(d24u8, d3u8);
-
-            q3s16 = vreinterpretq_s16_u16(q3u16);
-            q4s16 = vreinterpretq_s16_u16(q4u16);
-            q5s16 = vreinterpretq_s16_u16(q5u16);
-            q6s16 = vreinterpretq_s16_u16(q6u16);
-            q7s16 = vreinterpretq_s16_u16(q7u16);
-            q8s16 = vreinterpretq_s16_u16(q8u16);
-            q9s16 = vreinterpretq_s16_u16(q9u16);
-            q10s16 = vreinterpretq_s16_u16(q10u16);
-
-            q7s16 = vqaddq_s16(q7s16, q3s16);
-            q8s16 = vqaddq_s16(q8s16, q4s16);
-            q9s16 = vqaddq_s16(q9s16, q5s16);
-            q10s16 = vqaddq_s16(q10s16, q6s16);
-
-            d6u8 = vqrshrun_n_s16(q7s16, 7);
-            d7u8 = vqrshrun_n_s16(q8s16, 7);
-            d8u8 = vqrshrun_n_s16(q9s16, 7);
-            d9u8 = vqrshrun_n_s16(q10s16, 7);
-
-            d18u8 = d22u8;
-            d19u8 = d23u8;
-            d20u8 = d24u8;
-            d21u8 = d25u8;
-            d22u8 = d26u8;
-            d23u8 = d27u8;
-            d24u8 = d28u8;
-            d25u8 = d29u8;
-            d26u8 = d30u8;
-
-            vst1_u8(dst_ptr, d6u8);
-            dst_ptr += dst_pitch;
-            vst1_u8(dst_ptr, d7u8);
-            dst_ptr += dst_pitch;
-            vst1_u8(dst_ptr, d8u8);
-            dst_ptr += dst_pitch;
-            vst1_u8(dst_ptr, d9u8);
-            dst_ptr += dst_pitch;
-        }
-        return;
-    }
-
-    // load first_pass filter
-    dtmps8 = vld1_s8(vp8_sub_pel_filters[xoffset]);
-    d0s8 = vdup_lane_s8(dtmps8, 0);
-    d1s8 = vdup_lane_s8(dtmps8, 1);
-    d2s8 = vdup_lane_s8(dtmps8, 2);
-    d3s8 = vdup_lane_s8(dtmps8, 3);
-    d4s8 = vdup_lane_s8(dtmps8, 4);
-    d5s8 = vdup_lane_s8(dtmps8, 5);
-    d0u8 = vreinterpret_u8_s8(vabs_s8(d0s8));
-    d1u8 = vreinterpret_u8_s8(vabs_s8(d1s8));
-    d2u8 = vreinterpret_u8_s8(vabs_s8(d2s8));
-    d3u8 = vreinterpret_u8_s8(vabs_s8(d3s8));
-    d4u8 = vreinterpret_u8_s8(vabs_s8(d4s8));
-    d5u8 = vreinterpret_u8_s8(vabs_s8(d5s8));
-
-    // First pass: output_height lines x output_width columns (9x4)
-    if (yoffset == 0)  // firstpass_filter4x4_only
-        src = src_ptr - 2;
-    else
-        src = src_ptr - 2 - (src_pixels_per_line * 2);
-
-    tmpp = tmp;
-    for (i = 2; i > 0; i--) {
-        q3u8 = vld1q_u8(src);
-        src += src_pixels_per_line;
-        q4u8 = vld1q_u8(src);
-        src += src_pixels_per_line;
-        q5u8 = vld1q_u8(src);
-        src += src_pixels_per_line;
-        q6u8 = vld1q_u8(src);
-        src += src_pixels_per_line;
-
-        __builtin_prefetch(src);
-        __builtin_prefetch(src + src_pixels_per_line);
-        __builtin_prefetch(src + src_pixels_per_line * 2);
-
-        q7u16 = vmull_u8(vget_low_u8(q3u8), d0u8);
-        q8u16 = vmull_u8(vget_low_u8(q4u8), d0u8);
-        q9u16 = vmull_u8(vget_low_u8(q5u8), d0u8);
-        q10u16 = vmull_u8(vget_low_u8(q6u8), d0u8);
-
-        d28u8 = vext_u8(vget_low_u8(q3u8), vget_high_u8(q3u8), 1);
-        d29u8 = vext_u8(vget_low_u8(q4u8), vget_high_u8(q4u8), 1);
-        d30u8 = vext_u8(vget_low_u8(q5u8), vget_high_u8(q5u8), 1);
-        d31u8 = vext_u8(vget_low_u8(q6u8), vget_high_u8(q6u8), 1);
-
-        q7u16 = vmlsl_u8(q7u16, d28u8, d1u8);
-        q8u16 = vmlsl_u8(q8u16, d29u8, d1u8);
-        q9u16 = vmlsl_u8(q9u16, d30u8, d1u8);
-        q10u16 = vmlsl_u8(q10u16, d31u8, d1u8);
-
-        d28u8 = vext_u8(vget_low_u8(q3u8), vget_high_u8(q3u8), 4);
-        d29u8 = vext_u8(vget_low_u8(q4u8), vget_high_u8(q4u8), 4);
-        d30u8 = vext_u8(vget_low_u8(q5u8), vget_high_u8(q5u8), 4);
-        d31u8 = vext_u8(vget_low_u8(q6u8), vget_high_u8(q6u8), 4);
-
-        q7u16 = vmlsl_u8(q7u16, d28u8, d4u8);
-        q8u16 = vmlsl_u8(q8u16, d29u8, d4u8);
-        q9u16 = vmlsl_u8(q9u16, d30u8, d4u8);
-        q10u16 = vmlsl_u8(q10u16, d31u8, d4u8);
-
-        d28u8 = vext_u8(vget_low_u8(q3u8), vget_high_u8(q3u8), 2);
-        d29u8 = vext_u8(vget_low_u8(q4u8), vget_high_u8(q4u8), 2);
-        d30u8 = vext_u8(vget_low_u8(q5u8), vget_high_u8(q5u8), 2);
-        d31u8 = vext_u8(vget_low_u8(q6u8), vget_high_u8(q6u8), 2);
-
-        q7u16 = vmlal_u8(q7u16, d28u8, d2u8);
-        q8u16 = vmlal_u8(q8u16, d29u8, d2u8);
-        q9u16 = vmlal_u8(q9u16, d30u8, d2u8);
-        q10u16 = vmlal_u8(q10u16, d31u8, d2u8);
-
-        d28u8 = vext_u8(vget_low_u8(q3u8), vget_high_u8(q3u8), 5);
-        d29u8 = vext_u8(vget_low_u8(q4u8), vget_high_u8(q4u8), 5);
-        d30u8 = vext_u8(vget_low_u8(q5u8), vget_high_u8(q5u8), 5);
-        d31u8 = vext_u8(vget_low_u8(q6u8), vget_high_u8(q6u8), 5);
-
-        q7u16 = vmlal_u8(q7u16, d28u8, d5u8);
-        q8u16 = vmlal_u8(q8u16, d29u8, d5u8);
-        q9u16 = vmlal_u8(q9u16, d30u8, d5u8);
-        q10u16 = vmlal_u8(q10u16, d31u8, d5u8);
-
-        d28u8 = vext_u8(vget_low_u8(q3u8), vget_high_u8(q3u8), 3);
-        d29u8 = vext_u8(vget_low_u8(q4u8), vget_high_u8(q4u8), 3);
-        d30u8 = vext_u8(vget_low_u8(q5u8), vget_high_u8(q5u8), 3);
-        d31u8 = vext_u8(vget_low_u8(q6u8), vget_high_u8(q6u8), 3);
-
-        q3u16 = vmull_u8(d28u8, d3u8);
-        q4u16 = vmull_u8(d29u8, d3u8);
-        q5u16 = vmull_u8(d30u8, d3u8);
-        q6u16 = vmull_u8(d31u8, d3u8);
-
-        q3s16 = vreinterpretq_s16_u16(q3u16);
-        q4s16 = vreinterpretq_s16_u16(q4u16);
-        q5s16 = vreinterpretq_s16_u16(q5u16);
-        q6s16 = vreinterpretq_s16_u16(q6u16);
-        q7s16 = vreinterpretq_s16_u16(q7u16);
-        q8s16 = vreinterpretq_s16_u16(q8u16);
-        q9s16 = vreinterpretq_s16_u16(q9u16);
-        q10s16 = vreinterpretq_s16_u16(q10u16);
-
-        q7s16 = vqaddq_s16(q7s16, q3s16);
-        q8s16 = vqaddq_s16(q8s16, q4s16);
-        q9s16 = vqaddq_s16(q9s16, q5s16);
-        q10s16 = vqaddq_s16(q10s16, q6s16);
-
-        d22u8 = vqrshrun_n_s16(q7s16, 7);
-        d23u8 = vqrshrun_n_s16(q8s16, 7);
-        d24u8 = vqrshrun_n_s16(q9s16, 7);
-        d25u8 = vqrshrun_n_s16(q10s16, 7);
-
-        if (yoffset == 0) {  // firstpass_filter8x4_only
-            vst1_u8(dst_ptr, d22u8);
-            dst_ptr += dst_pitch;
-            vst1_u8(dst_ptr, d23u8);
-            dst_ptr += dst_pitch;
-            vst1_u8(dst_ptr, d24u8);
-            dst_ptr += dst_pitch;
-            vst1_u8(dst_ptr, d25u8);
-            dst_ptr += dst_pitch;
-        } else {
-            vst1_u8(tmpp, d22u8);
-            tmpp += 8;
-            vst1_u8(tmpp, d23u8);
-            tmpp += 8;
-            vst1_u8(tmpp, d24u8);
-            tmpp += 8;
-            vst1_u8(tmpp, d25u8);
-            tmpp += 8;
-        }
-    }
-    if (yoffset == 0)
-        return;
-
-    // First Pass on rest 5-line data
-    q3u8 = vld1q_u8(src);
-    src += src_pixels_per_line;
-    q4u8 = vld1q_u8(src);
-    src += src_pixels_per_line;
-    q5u8 = vld1q_u8(src);
-    src += src_pixels_per_line;
-    q6u8 = vld1q_u8(src);
-    src += src_pixels_per_line;
-    q7u8 = vld1q_u8(src);
-
-    q8u16 = vmull_u8(vget_low_u8(q3u8), d0u8);
-    q9u16 = vmull_u8(vget_low_u8(q4u8), d0u8);
-    q10u16 = vmull_u8(vget_low_u8(q5u8), d0u8);
-    q11u16 = vmull_u8(vget_low_u8(q6u8), d0u8);
-    q12u16 = vmull_u8(vget_low_u8(q7u8), d0u8);
-
-    d27u8 = vext_u8(vget_low_u8(q3u8), vget_high_u8(q3u8), 1);
-    d28u8 = vext_u8(vget_low_u8(q4u8), vget_high_u8(q4u8), 1);
-    d29u8 = vext_u8(vget_low_u8(q5u8), vget_high_u8(q5u8), 1);
-    d30u8 = vext_u8(vget_low_u8(q6u8), vget_high_u8(q6u8), 1);
-    d31u8 = vext_u8(vget_low_u8(q7u8), vget_high_u8(q7u8), 1);
-
-    q8u16 = vmlsl_u8(q8u16, d27u8, d1u8);
-    q9u16 = vmlsl_u8(q9u16, d28u8, d1u8);
-    q10u16 = vmlsl_u8(q10u16, d29u8, d1u8);
-    q11u16 = vmlsl_u8(q11u16, d30u8, d1u8);
-    q12u16 = vmlsl_u8(q12u16, d31u8, d1u8);
-
-    d27u8 = vext_u8(vget_low_u8(q3u8), vget_high_u8(q3u8), 4);
-    d28u8 = vext_u8(vget_low_u8(q4u8), vget_high_u8(q4u8), 4);
-    d29u8 = vext_u8(vget_low_u8(q5u8), vget_high_u8(q5u8), 4);
-    d30u8 = vext_u8(vget_low_u8(q6u8), vget_high_u8(q6u8), 4);
-    d31u8 = vext_u8(vget_low_u8(q7u8), vget_high_u8(q7u8), 4);
-
-    q8u16 = vmlsl_u8(q8u16, d27u8, d4u8);
-    q9u16 = vmlsl_u8(q9u16, d28u8, d4u8);
-    q10u16 = vmlsl_u8(q10u16, d29u8, d4u8);
-    q11u16 = vmlsl_u8(q11u16, d30u8, d4u8);
-    q12u16 = vmlsl_u8(q12u16, d31u8, d4u8);
-
-    d27u8 = vext_u8(vget_low_u8(q3u8), vget_high_u8(q3u8), 2);
-    d28u8 = vext_u8(vget_low_u8(q4u8), vget_high_u8(q4u8), 2);
-    d29u8 = vext_u8(vget_low_u8(q5u8), vget_high_u8(q5u8), 2);
-    d30u8 = vext_u8(vget_low_u8(q6u8), vget_high_u8(q6u8), 2);
-    d31u8 = vext_u8(vget_low_u8(q7u8), vget_high_u8(q7u8), 2);
-
-    q8u16 = vmlal_u8(q8u16, d27u8, d2u8);
-    q9u16 = vmlal_u8(q9u16, d28u8, d2u8);
-    q10u16 = vmlal_u8(q10u16, d29u8, d2u8);
-    q11u16 = vmlal_u8(q11u16, d30u8, d2u8);
-    q12u16 = vmlal_u8(q12u16, d31u8, d2u8);
-
-    d27u8 = vext_u8(vget_low_u8(q3u8), vget_high_u8(q3u8), 5);
-    d28u8 = vext_u8(vget_low_u8(q4u8), vget_high_u8(q4u8), 5);
-    d29u8 = vext_u8(vget_low_u8(q5u8), vget_high_u8(q5u8), 5);
-    d30u8 = vext_u8(vget_low_u8(q6u8), vget_high_u8(q6u8), 5);
-    d31u8 = vext_u8(vget_low_u8(q7u8), vget_high_u8(q7u8), 5);
-
-    q8u16 = vmlal_u8(q8u16, d27u8, d5u8);
-    q9u16 = vmlal_u8(q9u16, d28u8, d5u8);
-    q10u16 = vmlal_u8(q10u16, d29u8, d5u8);
-    q11u16 = vmlal_u8(q11u16, d30u8, d5u8);
-    q12u16 = vmlal_u8(q12u16, d31u8, d5u8);
-
-    d27u8 = vext_u8(vget_low_u8(q3u8), vget_high_u8(q3u8), 3);
-    d28u8 = vext_u8(vget_low_u8(q4u8), vget_high_u8(q4u8), 3);
-    d29u8 = vext_u8(vget_low_u8(q5u8), vget_high_u8(q5u8), 3);
-    d30u8 = vext_u8(vget_low_u8(q6u8), vget_high_u8(q6u8), 3);
-    d31u8 = vext_u8(vget_low_u8(q7u8), vget_high_u8(q7u8), 3);
-
-    q3u16 = vmull_u8(d27u8, d3u8);
-    q4u16 = vmull_u8(d28u8, d3u8);
-    q5u16 = vmull_u8(d29u8, d3u8);
-    q6u16 = vmull_u8(d30u8, d3u8);
-    q7u16 = vmull_u8(d31u8, d3u8);
-
-    q3s16 = vreinterpretq_s16_u16(q3u16);
-    q4s16 = vreinterpretq_s16_u16(q4u16);
-    q5s16 = vreinterpretq_s16_u16(q5u16);
-    q6s16 = vreinterpretq_s16_u16(q6u16);
-    q7s16 = vreinterpretq_s16_u16(q7u16);
-    q8s16 = vreinterpretq_s16_u16(q8u16);
-    q9s16 = vreinterpretq_s16_u16(q9u16);
-    q10s16 = vreinterpretq_s16_u16(q10u16);
-    q11s16 = vreinterpretq_s16_u16(q11u16);
-    q12s16 = vreinterpretq_s16_u16(q12u16);
-
-    q8s16 = vqaddq_s16(q8s16, q3s16);
-    q9s16 = vqaddq_s16(q9s16, q4s16);
-    q10s16 = vqaddq_s16(q10s16, q5s16);
-    q11s16 = vqaddq_s16(q11s16, q6s16);
-    q12s16 = vqaddq_s16(q12s16, q7s16);
-
-    d26u8 = vqrshrun_n_s16(q8s16, 7);
-    d27u8 = vqrshrun_n_s16(q9s16, 7);
-    d28u8 = vqrshrun_n_s16(q10s16, 7);
-    d29u8 = vqrshrun_n_s16(q11s16, 7);
-    d30u8 = vqrshrun_n_s16(q12s16, 7);
-
-    // Second pass: 8x8
-    dtmps8 = vld1_s8(vp8_sub_pel_filters[yoffset]);
-    d0s8 = vdup_lane_s8(dtmps8, 0);
-    d1s8 = vdup_lane_s8(dtmps8, 1);
-    d2s8 = vdup_lane_s8(dtmps8, 2);
-    d3s8 = vdup_lane_s8(dtmps8, 3);
-    d4s8 = vdup_lane_s8(dtmps8, 4);
-    d5s8 = vdup_lane_s8(dtmps8, 5);
-    d0u8 = vreinterpret_u8_s8(vabs_s8(d0s8));
-    d1u8 = vreinterpret_u8_s8(vabs_s8(d1s8));
-    d2u8 = vreinterpret_u8_s8(vabs_s8(d2s8));
-    d3u8 = vreinterpret_u8_s8(vabs_s8(d3s8));
-    d4u8 = vreinterpret_u8_s8(vabs_s8(d4s8));
-    d5u8 = vreinterpret_u8_s8(vabs_s8(d5s8));
-
-    tmpp = tmp;
-    q9u8 = vld1q_u8(tmpp);
-    tmpp += 16;
-    q10u8 = vld1q_u8(tmpp);
-    tmpp += 16;
-    q11u8 = vld1q_u8(tmpp);
-    tmpp += 16;
-    q12u8 = vld1q_u8(tmpp);
-
-    d18u8 = vget_low_u8(q9u8);
-    d19u8 = vget_high_u8(q9u8);
-    d20u8 = vget_low_u8(q10u8);
-    d21u8 = vget_high_u8(q10u8);
-    d22u8 = vget_low_u8(q11u8);
-    d23u8 = vget_high_u8(q11u8);
-    d24u8 = vget_low_u8(q12u8);
-    d25u8 = vget_high_u8(q12u8);
-
-    for (i = 2; i > 0; i--) {
-        q3u16 = vmull_u8(d18u8, d0u8);
-        q4u16 = vmull_u8(d19u8, d0u8);
-        q5u16 = vmull_u8(d20u8, d0u8);
-        q6u16 = vmull_u8(d21u8, d0u8);
-
-        q3u16 = vmlsl_u8(q3u16, d19u8, d1u8);
-        q4u16 = vmlsl_u8(q4u16, d20u8, d1u8);
-        q5u16 = vmlsl_u8(q5u16, d21u8, d1u8);
-        q6u16 = vmlsl_u8(q6u16, d22u8, d1u8);
-
-        q3u16 = vmlsl_u8(q3u16, d22u8, d4u8);
-        q4u16 = vmlsl_u8(q4u16, d23u8, d4u8);
-        q5u16 = vmlsl_u8(q5u16, d24u8, d4u8);
-        q6u16 = vmlsl_u8(q6u16, d25u8, d4u8);
-
-        q3u16 = vmlal_u8(q3u16, d20u8, d2u8);
-        q4u16 = vmlal_u8(q4u16, d21u8, d2u8);
-        q5u16 = vmlal_u8(q5u16, d22u8, d2u8);
-        q6u16 = vmlal_u8(q6u16, d23u8, d2u8);
-
-        q3u16 = vmlal_u8(q3u16, d23u8, d5u8);
-        q4u16 = vmlal_u8(q4u16, d24u8, d5u8);
-        q5u16 = vmlal_u8(q5u16, d25u8, d5u8);
-        q6u16 = vmlal_u8(q6u16, d26u8, d5u8);
-
-        q7u16 = vmull_u8(d21u8, d3u8);
-        q8u16 = vmull_u8(d22u8, d3u8);
-        q9u16 = vmull_u8(d23u8, d3u8);
-        q10u16 = vmull_u8(d24u8, d3u8);
-
-        q3s16 = vreinterpretq_s16_u16(q3u16);
-        q4s16 = vreinterpretq_s16_u16(q4u16);
-        q5s16 = vreinterpretq_s16_u16(q5u16);
-        q6s16 = vreinterpretq_s16_u16(q6u16);
-        q7s16 = vreinterpretq_s16_u16(q7u16);
-        q8s16 = vreinterpretq_s16_u16(q8u16);
-        q9s16 = vreinterpretq_s16_u16(q9u16);
-        q10s16 = vreinterpretq_s16_u16(q10u16);
-
-        q7s16 = vqaddq_s16(q7s16, q3s16);
-        q8s16 = vqaddq_s16(q8s16, q4s16);
-        q9s16 = vqaddq_s16(q9s16, q5s16);
-        q10s16 = vqaddq_s16(q10s16, q6s16);
-
-        d6u8 = vqrshrun_n_s16(q7s16, 7);
-        d7u8 = vqrshrun_n_s16(q8s16, 7);
-        d8u8 = vqrshrun_n_s16(q9s16, 7);
-        d9u8 = vqrshrun_n_s16(q10s16, 7);
-
-        d18u8 = d22u8;
-        d19u8 = d23u8;
-        d20u8 = d24u8;
-        d21u8 = d25u8;
-        d22u8 = d26u8;
-        d23u8 = d27u8;
-        d24u8 = d28u8;
-        d25u8 = d29u8;
-        d26u8 = d30u8;
-
-        vst1_u8(dst_ptr, d6u8);
-        dst_ptr += dst_pitch;
-        vst1_u8(dst_ptr, d7u8);
-        dst_ptr += dst_pitch;
-        vst1_u8(dst_ptr, d8u8);
-        dst_ptr += dst_pitch;
-        vst1_u8(dst_ptr, d9u8);
-        dst_ptr += dst_pitch;
-    }
-    return;
-}
-
-void vp8_sixtap_predict16x16_neon(
-        unsigned char *src_ptr,
-        int src_pixels_per_line,
-        int xoffset,
-        int yoffset,
-        unsigned char *dst_ptr,
-        int dst_pitch) {
-    unsigned char *src, *src_tmp, *dst, *tmpp;
-    unsigned char tmp[336];
-    int i, j;
-    uint8x8_t d0u8, d1u8, d2u8, d3u8, d4u8, d5u8, d6u8, d7u8, d8u8, d9u8;
-    uint8x8_t d10u8, d11u8, d12u8, d13u8, d14u8, d15u8, d18u8, d19u8;
-    uint8x8_t d20u8, d21u8, d22u8, d23u8, d24u8, d25u8, d26u8, d27u8;
-    uint8x8_t d28u8, d29u8, d30u8, d31u8;
-    int8x8_t dtmps8, d0s8, d1s8, d2s8, d3s8, d4s8, d5s8;
-    uint8x16_t q3u8, q4u8;
-    uint16x8_t q3u16, q4u16, q5u16, q6u16, q7u16, q8u16, q9u16, q10u16;
-    uint16x8_t q11u16, q12u16, q13u16, q15u16;
-    int16x8_t q3s16, q4s16, q5s16, q6s16, q7s16, q8s16, q9s16, q10s16;
-    int16x8_t q11s16, q12s16, q13s16, q15s16;
-
-    if (xoffset == 0) {  // secondpass_filter8x8_only
-        // load second_pass filter
-        dtmps8 = vld1_s8(vp8_sub_pel_filters[yoffset]);
-        d0s8 = vdup_lane_s8(dtmps8, 0);
-        d1s8 = vdup_lane_s8(dtmps8, 1);
-        d2s8 = vdup_lane_s8(dtmps8, 2);
-        d3s8 = vdup_lane_s8(dtmps8, 3);
-        d4s8 = vdup_lane_s8(dtmps8, 4);
-        d5s8 = vdup_lane_s8(dtmps8, 5);
-        d0u8 = vreinterpret_u8_s8(vabs_s8(d0s8));
-        d1u8 = vreinterpret_u8_s8(vabs_s8(d1s8));
-        d2u8 = vreinterpret_u8_s8(vabs_s8(d2s8));
-        d3u8 = vreinterpret_u8_s8(vabs_s8(d3s8));
-        d4u8 = vreinterpret_u8_s8(vabs_s8(d4s8));
-        d5u8 = vreinterpret_u8_s8(vabs_s8(d5s8));
-
-        // load src data
-        src_tmp = src_ptr - src_pixels_per_line * 2;
-        for (i = 0; i < 2; i++) {
-            src = src_tmp + i * 8;
-            dst = dst_ptr + i * 8;
-            d18u8 = vld1_u8(src);
-            src += src_pixels_per_line;
-            d19u8 = vld1_u8(src);
-            src += src_pixels_per_line;
-            d20u8 = vld1_u8(src);
-            src += src_pixels_per_line;
-            d21u8 = vld1_u8(src);
-            src += src_pixels_per_line;
-            d22u8 = vld1_u8(src);
-            src += src_pixels_per_line;
-            for (j = 0; j < 4; j++) {
-                d23u8 = vld1_u8(src);
-                src += src_pixels_per_line;
-                d24u8 = vld1_u8(src);
-                src += src_pixels_per_line;
-                d25u8 = vld1_u8(src);
-                src += src_pixels_per_line;
-                d26u8 = vld1_u8(src);
-                src += src_pixels_per_line;
-
-                q3u16 = vmull_u8(d18u8, d0u8);
-                q4u16 = vmull_u8(d19u8, d0u8);
-                q5u16 = vmull_u8(d20u8, d0u8);
-                q6u16 = vmull_u8(d21u8, d0u8);
-
-                q3u16 = vmlsl_u8(q3u16, d19u8, d1u8);
-                q4u16 = vmlsl_u8(q4u16, d20u8, d1u8);
-                q5u16 = vmlsl_u8(q5u16, d21u8, d1u8);
-                q6u16 = vmlsl_u8(q6u16, d22u8, d1u8);
-
-                q3u16 = vmlsl_u8(q3u16, d22u8, d4u8);
-                q4u16 = vmlsl_u8(q4u16, d23u8, d4u8);
-                q5u16 = vmlsl_u8(q5u16, d24u8, d4u8);
-                q6u16 = vmlsl_u8(q6u16, d25u8, d4u8);
-
-                q3u16 = vmlal_u8(q3u16, d20u8, d2u8);
-                q4u16 = vmlal_u8(q4u16, d21u8, d2u8);
-                q5u16 = vmlal_u8(q5u16, d22u8, d2u8);
-                q6u16 = vmlal_u8(q6u16, d23u8, d2u8);
-
-                q3u16 = vmlal_u8(q3u16, d23u8, d5u8);
-                q4u16 = vmlal_u8(q4u16, d24u8, d5u8);
-                q5u16 = vmlal_u8(q5u16, d25u8, d5u8);
-                q6u16 = vmlal_u8(q6u16, d26u8, d5u8);
-
-                q7u16 = vmull_u8(d21u8, d3u8);
-                q8u16 = vmull_u8(d22u8, d3u8);
-                q9u16 = vmull_u8(d23u8, d3u8);
-                q10u16 = vmull_u8(d24u8, d3u8);
-
-                q3s16 = vreinterpretq_s16_u16(q3u16);
-                q4s16 = vreinterpretq_s16_u16(q4u16);
-                q5s16 = vreinterpretq_s16_u16(q5u16);
-                q6s16 = vreinterpretq_s16_u16(q6u16);
-                q7s16 = vreinterpretq_s16_u16(q7u16);
-                q8s16 = vreinterpretq_s16_u16(q8u16);
-                q9s16 = vreinterpretq_s16_u16(q9u16);
-                q10s16 = vreinterpretq_s16_u16(q10u16);
-
-                q7s16 = vqaddq_s16(q7s16, q3s16);
-                q8s16 = vqaddq_s16(q8s16, q4s16);
-                q9s16 = vqaddq_s16(q9s16, q5s16);
-                q10s16 = vqaddq_s16(q10s16, q6s16);
-
-                d6u8 = vqrshrun_n_s16(q7s16, 7);
-                d7u8 = vqrshrun_n_s16(q8s16, 7);
-                d8u8 = vqrshrun_n_s16(q9s16, 7);
-                d9u8 = vqrshrun_n_s16(q10s16, 7);
-
-                d18u8 = d22u8;
-                d19u8 = d23u8;
-                d20u8 = d24u8;
-                d21u8 = d25u8;
-                d22u8 = d26u8;
-
-                vst1_u8(dst, d6u8);
-                dst += dst_pitch;
-                vst1_u8(dst, d7u8);
-                dst += dst_pitch;
-                vst1_u8(dst, d8u8);
-                dst += dst_pitch;
-                vst1_u8(dst, d9u8);
-                dst += dst_pitch;
-            }
-        }
-        return;
-    }
-
-    // load first_pass filter
-    dtmps8 = vld1_s8(vp8_sub_pel_filters[xoffset]);
-    d0s8 = vdup_lane_s8(dtmps8, 0);
-    d1s8 = vdup_lane_s8(dtmps8, 1);
-    d2s8 = vdup_lane_s8(dtmps8, 2);
-    d3s8 = vdup_lane_s8(dtmps8, 3);
-    d4s8 = vdup_lane_s8(dtmps8, 4);
-    d5s8 = vdup_lane_s8(dtmps8, 5);
-    d0u8 = vreinterpret_u8_s8(vabs_s8(d0s8));
-    d1u8 = vreinterpret_u8_s8(vabs_s8(d1s8));
-    d2u8 = vreinterpret_u8_s8(vabs_s8(d2s8));
-    d3u8 = vreinterpret_u8_s8(vabs_s8(d3s8));
-    d4u8 = vreinterpret_u8_s8(vabs_s8(d4s8));
-    d5u8 = vreinterpret_u8_s8(vabs_s8(d5s8));
-
-    // First pass: output_height lines x output_width columns (9x4)
-    if (yoffset == 0) {  // firstpass_filter4x4_only
-        src = src_ptr - 2;
-        dst = dst_ptr;
-        for (i = 0; i < 8; i++) {
-            d6u8 = vld1_u8(src);
-            d7u8 = vld1_u8(src + 8);
-            d8u8 = vld1_u8(src + 16);
-            src += src_pixels_per_line;
-            d9u8 = vld1_u8(src);
-            d10u8 = vld1_u8(src + 8);
-            d11u8 = vld1_u8(src + 16);
-            src += src_pixels_per_line;
-
-            __builtin_prefetch(src);
-            __builtin_prefetch(src + src_pixels_per_line);
-
-            q6u16 = vmull_u8(d6u8, d0u8);
-            q7u16 = vmull_u8(d7u8, d0u8);
-            q8u16 = vmull_u8(d9u8, d0u8);
-            q9u16 = vmull_u8(d10u8, d0u8);
-
-            d20u8 = vext_u8(d6u8, d7u8, 1);
-            d21u8 = vext_u8(d9u8, d10u8, 1);
-            d22u8 = vext_u8(d7u8, d8u8, 1);
-            d23u8 = vext_u8(d10u8, d11u8, 1);
-            d24u8 = vext_u8(d6u8, d7u8, 4);
-            d25u8 = vext_u8(d9u8, d10u8, 4);
-            d26u8 = vext_u8(d7u8, d8u8, 4);
-            d27u8 = vext_u8(d10u8, d11u8, 4);
-            d28u8 = vext_u8(d6u8, d7u8, 5);
-            d29u8 = vext_u8(d9u8, d10u8, 5);
-
-            q6u16 = vmlsl_u8(q6u16, d20u8, d1u8);
-            q8u16 = vmlsl_u8(q8u16, d21u8, d1u8);
-            q7u16 = vmlsl_u8(q7u16, d22u8, d1u8);
-            q9u16 = vmlsl_u8(q9u16, d23u8, d1u8);
-            q6u16 = vmlsl_u8(q6u16, d24u8, d4u8);
-            q8u16 = vmlsl_u8(q8u16, d25u8, d4u8);
-            q7u16 = vmlsl_u8(q7u16, d26u8, d4u8);
-            q9u16 = vmlsl_u8(q9u16, d27u8, d4u8);
-            q6u16 = vmlal_u8(q6u16, d28u8, d5u8);
-            q8u16 = vmlal_u8(q8u16, d29u8, d5u8);
-
-            d20u8 = vext_u8(d7u8, d8u8, 5);
-            d21u8 = vext_u8(d10u8, d11u8, 5);
-            d22u8 = vext_u8(d6u8, d7u8, 2);
-            d23u8 = vext_u8(d9u8, d10u8, 2);
-            d24u8 = vext_u8(d7u8, d8u8, 2);
-            d25u8 = vext_u8(d10u8, d11u8, 2);
-            d26u8 = vext_u8(d6u8, d7u8, 3);
-            d27u8 = vext_u8(d9u8, d10u8, 3);
-            d28u8 = vext_u8(d7u8, d8u8, 3);
-            d29u8 = vext_u8(d10u8, d11u8, 3);
-
-            q7u16 = vmlal_u8(q7u16, d20u8, d5u8);
-            q9u16 = vmlal_u8(q9u16, d21u8, d5u8);
-            q6u16 = vmlal_u8(q6u16, d22u8, d2u8);
-            q8u16 = vmlal_u8(q8u16, d23u8, d2u8);
-            q7u16 = vmlal_u8(q7u16, d24u8, d2u8);
-            q9u16 = vmlal_u8(q9u16, d25u8, d2u8);
-
-            q10u16 = vmull_u8(d26u8, d3u8);
-            q11u16 = vmull_u8(d27u8, d3u8);
-            q12u16 = vmull_u8(d28u8, d3u8);
-            q15u16 = vmull_u8(d29u8, d3u8);
-
-            q6s16 = vreinterpretq_s16_u16(q6u16);
-            q7s16 = vreinterpretq_s16_u16(q7u16);
-            q8s16 = vreinterpretq_s16_u16(q8u16);
-            q9s16 = vreinterpretq_s16_u16(q9u16);
-            q10s16 = vreinterpretq_s16_u16(q10u16);
-            q11s16 = vreinterpretq_s16_u16(q11u16);
-            q12s16 = vreinterpretq_s16_u16(q12u16);
-            q15s16 = vreinterpretq_s16_u16(q15u16);
-
-            q6s16 = vqaddq_s16(q6s16, q10s16);
-            q8s16 = vqaddq_s16(q8s16, q11s16);
-            q7s16 = vqaddq_s16(q7s16, q12s16);
-            q9s16 = vqaddq_s16(q9s16, q15s16);
-
-            d6u8 = vqrshrun_n_s16(q6s16, 7);
-            d7u8 = vqrshrun_n_s16(q7s16, 7);
-            d8u8 = vqrshrun_n_s16(q8s16, 7);
-            d9u8 = vqrshrun_n_s16(q9s16, 7);
-
-            q3u8 = vcombine_u8(d6u8, d7u8);
-            q4u8 = vcombine_u8(d8u8, d9u8);
-            vst1q_u8(dst, q3u8);
-            dst += dst_pitch;
-            vst1q_u8(dst, q4u8);
-            dst += dst_pitch;
-        }
-        return;
-    }
-
-    src = src_ptr - 2 - src_pixels_per_line * 2;
-    tmpp = tmp;
-    for (i = 0; i < 7; i++) {
-        d6u8 = vld1_u8(src);
-        d7u8 = vld1_u8(src + 8);
-        d8u8 = vld1_u8(src + 16);
-        src += src_pixels_per_line;
-        d9u8 = vld1_u8(src);
-        d10u8 = vld1_u8(src + 8);
-        d11u8 = vld1_u8(src + 16);
-        src += src_pixels_per_line;
-        d12u8 = vld1_u8(src);
-        d13u8 = vld1_u8(src + 8);
-        d14u8 = vld1_u8(src + 16);
-        src += src_pixels_per_line;
-
-        __builtin_prefetch(src);
-        __builtin_prefetch(src + src_pixels_per_line);
-        __builtin_prefetch(src + src_pixels_per_line * 2);
-
-        q8u16 = vmull_u8(d6u8, d0u8);
-        q9u16 = vmull_u8(d7u8, d0u8);
-        q10u16 = vmull_u8(d9u8, d0u8);
-        q11u16 = vmull_u8(d10u8, d0u8);
-        q12u16 = vmull_u8(d12u8, d0u8);
-        q13u16 = vmull_u8(d13u8, d0u8);
-
-        d28u8 = vext_u8(d6u8, d7u8, 1);
-        d29u8 = vext_u8(d9u8, d10u8, 1);
-        d30u8 = vext_u8(d12u8, d13u8, 1);
-        q8u16 = vmlsl_u8(q8u16, d28u8, d1u8);
-        q10u16 = vmlsl_u8(q10u16, d29u8, d1u8);
-        q12u16 = vmlsl_u8(q12u16, d30u8, d1u8);
-        d28u8 = vext_u8(d7u8, d8u8, 1);
-        d29u8 = vext_u8(d10u8, d11u8, 1);
-        d30u8 = vext_u8(d13u8, d14u8, 1);
-        q9u16  = vmlsl_u8(q9u16, d28u8, d1u8);
-        q11u16 = vmlsl_u8(q11u16, d29u8, d1u8);
-        q13u16 = vmlsl_u8(q13u16, d30u8, d1u8);
-
-        d28u8 = vext_u8(d6u8, d7u8, 4);
-        d29u8 = vext_u8(d9u8, d10u8, 4);
-        d30u8 = vext_u8(d12u8, d13u8, 4);
-        q8u16 = vmlsl_u8(q8u16, d28u8, d4u8);
-        q10u16 = vmlsl_u8(q10u16, d29u8, d4u8);
-        q12u16 = vmlsl_u8(q12u16, d30u8, d4u8);
-        d28u8 = vext_u8(d7u8, d8u8, 4);
-        d29u8 = vext_u8(d10u8, d11u8, 4);
-        d30u8 = vext_u8(d13u8, d14u8, 4);
-        q9u16 = vmlsl_u8(q9u16, d28u8, d4u8);
-        q11u16 = vmlsl_u8(q11u16, d29u8, d4u8);
-        q13u16 = vmlsl_u8(q13u16, d30u8, d4u8);
-
-        d28u8 = vext_u8(d6u8, d7u8, 5);
-        d29u8 = vext_u8(d9u8, d10u8, 5);
-        d30u8 = vext_u8(d12u8, d13u8, 5);
-        q8u16 = vmlal_u8(q8u16, d28u8, d5u8);
-        q10u16 = vmlal_u8(q10u16, d29u8, d5u8);
-        q12u16 = vmlal_u8(q12u16, d30u8, d5u8);
-        d28u8 = vext_u8(d7u8, d8u8, 5);
-        d29u8 = vext_u8(d10u8, d11u8, 5);
-        d30u8 = vext_u8(d13u8, d14u8, 5);
-        q9u16 = vmlal_u8(q9u16, d28u8, d5u8);
-        q11u16 = vmlal_u8(q11u16, d29u8, d5u8);
-        q13u16 = vmlal_u8(q13u16, d30u8, d5u8);
-
-        d28u8 = vext_u8(d6u8, d7u8, 2);
-        d29u8 = vext_u8(d9u8, d10u8, 2);
-        d30u8 = vext_u8(d12u8, d13u8, 2);
-        q8u16 = vmlal_u8(q8u16, d28u8, d2u8);
-        q10u16 = vmlal_u8(q10u16, d29u8, d2u8);
-        q12u16 = vmlal_u8(q12u16, d30u8, d2u8);
-        d28u8 = vext_u8(d7u8, d8u8, 2);
-        d29u8 = vext_u8(d10u8, d11u8, 2);
-        d30u8 = vext_u8(d13u8, d14u8, 2);
-        q9u16 = vmlal_u8(q9u16, d28u8, d2u8);
-        q11u16 = vmlal_u8(q11u16, d29u8, d2u8);
-        q13u16 = vmlal_u8(q13u16, d30u8, d2u8);
-
-        d28u8 = vext_u8(d6u8, d7u8, 3);
-        d29u8 = vext_u8(d9u8, d10u8, 3);
-        d30u8 = vext_u8(d12u8, d13u8, 3);
-        d15u8 = vext_u8(d7u8, d8u8, 3);
-        d31u8 = vext_u8(d10u8, d11u8, 3);
-        d6u8  = vext_u8(d13u8, d14u8, 3);
-        q4u16 = vmull_u8(d28u8, d3u8);
-        q5u16 = vmull_u8(d29u8, d3u8);
-        q6u16 = vmull_u8(d30u8, d3u8);
-        q4s16 = vreinterpretq_s16_u16(q4u16);
-        q5s16 = vreinterpretq_s16_u16(q5u16);
-        q6s16 = vreinterpretq_s16_u16(q6u16);
-        q8s16 = vreinterpretq_s16_u16(q8u16);
-        q10s16 = vreinterpretq_s16_u16(q10u16);
-        q12s16 = vreinterpretq_s16_u16(q12u16);
-        q8s16 = vqaddq_s16(q8s16, q4s16);
-        q10s16 = vqaddq_s16(q10s16, q5s16);
-        q12s16 = vqaddq_s16(q12s16, q6s16);
-
-        q6u16 = vmull_u8(d15u8, d3u8);
-        q7u16 = vmull_u8(d31u8, d3u8);
-        q3u16 = vmull_u8(d6u8, d3u8);
-        q3s16 = vreinterpretq_s16_u16(q3u16);
-        q6s16 = vreinterpretq_s16_u16(q6u16);
-        q7s16 = vreinterpretq_s16_u16(q7u16);
-        q9s16 = vreinterpretq_s16_u16(q9u16);
-        q11s16 = vreinterpretq_s16_u16(q11u16);
-        q13s16 = vreinterpretq_s16_u16(q13u16);
-        q9s16 = vqaddq_s16(q9s16, q6s16);
-        q11s16 = vqaddq_s16(q11s16, q7s16);
-        q13s16 = vqaddq_s16(q13s16, q3s16);
-
-        d6u8 = vqrshrun_n_s16(q8s16, 7);
-        d7u8 = vqrshrun_n_s16(q9s16, 7);
-        d8u8 = vqrshrun_n_s16(q10s16, 7);
-        d9u8 = vqrshrun_n_s16(q11s16, 7);
-        d10u8 = vqrshrun_n_s16(q12s16, 7);
-        d11u8 = vqrshrun_n_s16(q13s16, 7);
-
-        vst1_u8(tmpp, d6u8);
-        tmpp += 8;
-        vst1_u8(tmpp, d7u8);
-        tmpp += 8;
-        vst1_u8(tmpp, d8u8);
-        tmpp += 8;
-        vst1_u8(tmpp, d9u8);
-        tmpp += 8;
-        vst1_u8(tmpp, d10u8);
-        tmpp += 8;
-        vst1_u8(tmpp, d11u8);
-        tmpp += 8;
-    }
-
-    // Second pass: 16x16
-    dtmps8 = vld1_s8(vp8_sub_pel_filters[yoffset]);
-    d0s8 = vdup_lane_s8(dtmps8, 0);
-    d1s8 = vdup_lane_s8(dtmps8, 1);
-    d2s8 = vdup_lane_s8(dtmps8, 2);
-    d3s8 = vdup_lane_s8(dtmps8, 3);
-    d4s8 = vdup_lane_s8(dtmps8, 4);
-    d5s8 = vdup_lane_s8(dtmps8, 5);
-    d0u8 = vreinterpret_u8_s8(vabs_s8(d0s8));
-    d1u8 = vreinterpret_u8_s8(vabs_s8(d1s8));
-    d2u8 = vreinterpret_u8_s8(vabs_s8(d2s8));
-    d3u8 = vreinterpret_u8_s8(vabs_s8(d3s8));
-    d4u8 = vreinterpret_u8_s8(vabs_s8(d4s8));
-    d5u8 = vreinterpret_u8_s8(vabs_s8(d5s8));
-
-    for (i = 0; i < 2; i++) {
-        dst = dst_ptr + 8 * i;
-        tmpp = tmp + 8 * i;
-        d18u8 = vld1_u8(tmpp);
-        tmpp += 16;
-        d19u8 = vld1_u8(tmpp);
-        tmpp += 16;
-        d20u8 = vld1_u8(tmpp);
-        tmpp += 16;
-        d21u8 = vld1_u8(tmpp);
-        tmpp += 16;
-        d22u8 = vld1_u8(tmpp);
-        tmpp += 16;
-        for (j = 0; j < 4; j++) {
-            d23u8 = vld1_u8(tmpp);
-            tmpp += 16;
-            d24u8 = vld1_u8(tmpp);
-            tmpp += 16;
-            d25u8 = vld1_u8(tmpp);
-            tmpp += 16;
-            d26u8 = vld1_u8(tmpp);
-            tmpp += 16;
-
-            q3u16 = vmull_u8(d18u8, d0u8);
-            q4u16 = vmull_u8(d19u8, d0u8);
-            q5u16 = vmull_u8(d20u8, d0u8);
-            q6u16 = vmull_u8(d21u8, d0u8);
-
-            q3u16 = vmlsl_u8(q3u16, d19u8, d1u8);
-            q4u16 = vmlsl_u8(q4u16, d20u8, d1u8);
-            q5u16 = vmlsl_u8(q5u16, d21u8, d1u8);
-            q6u16 = vmlsl_u8(q6u16, d22u8, d1u8);
-
-            q3u16 = vmlsl_u8(q3u16, d22u8, d4u8);
-            q4u16 = vmlsl_u8(q4u16, d23u8, d4u8);
-            q5u16 = vmlsl_u8(q5u16, d24u8, d4u8);
-            q6u16 = vmlsl_u8(q6u16, d25u8, d4u8);
-
-            q3u16 = vmlal_u8(q3u16, d20u8, d2u8);
-            q4u16 = vmlal_u8(q4u16, d21u8, d2u8);
-            q5u16 = vmlal_u8(q5u16, d22u8, d2u8);
-            q6u16 = vmlal_u8(q6u16, d23u8, d2u8);
-
-            q3u16 = vmlal_u8(q3u16, d23u8, d5u8);
-            q4u16 = vmlal_u8(q4u16, d24u8, d5u8);
-            q5u16 = vmlal_u8(q5u16, d25u8, d5u8);
-            q6u16 = vmlal_u8(q6u16, d26u8, d5u8);
-
-            q7u16 = vmull_u8(d21u8, d3u8);
-            q8u16 = vmull_u8(d22u8, d3u8);
-            q9u16 = vmull_u8(d23u8, d3u8);
-            q10u16 = vmull_u8(d24u8, d3u8);
-
-            q3s16 = vreinterpretq_s16_u16(q3u16);
-            q4s16 = vreinterpretq_s16_u16(q4u16);
-            q5s16 = vreinterpretq_s16_u16(q5u16);
-            q6s16 = vreinterpretq_s16_u16(q6u16);
-            q7s16 = vreinterpretq_s16_u16(q7u16);
-            q8s16 = vreinterpretq_s16_u16(q8u16);
-            q9s16 = vreinterpretq_s16_u16(q9u16);
-            q10s16 = vreinterpretq_s16_u16(q10u16);
-
-            q7s16 = vqaddq_s16(q7s16, q3s16);
-            q8s16 = vqaddq_s16(q8s16, q4s16);
-            q9s16 = vqaddq_s16(q9s16, q5s16);
-            q10s16 = vqaddq_s16(q10s16, q6s16);
-
-            d6u8 = vqrshrun_n_s16(q7s16, 7);
-            d7u8 = vqrshrun_n_s16(q8s16, 7);
-            d8u8 = vqrshrun_n_s16(q9s16, 7);
-            d9u8 = vqrshrun_n_s16(q10s16, 7);
-
-            d18u8 = d22u8;
-            d19u8 = d23u8;
-            d20u8 = d24u8;
-            d21u8 = d25u8;
-            d22u8 = d26u8;
-
-            vst1_u8(dst, d6u8);
-            dst += dst_pitch;
-            vst1_u8(dst, d7u8);
-            dst += dst_pitch;
-            vst1_u8(dst, d8u8);
-            dst += dst_pitch;
-            vst1_u8(dst, d9u8);
-            dst += dst_pitch;
-        }
-    }
-    return;
-}
diff --git a/vp8/common/arm/neon/vp8_loopfilter_neon.c b/vp8/common/arm/neon/vp8_loopfilter_neon.c
deleted file mode 100644 (file)
index 9d6807a..0000000
+++ /dev/null
@@ -1,550 +0,0 @@
-/*
- *  Copyright (c) 2014 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.
- */
-
-#include <arm_neon.h>
-#include "./vpx_config.h"
-#include "vpx_ports/arm.h"
-
-static INLINE void vp8_loop_filter_neon(
-        uint8x16_t qblimit,  // flimit
-        uint8x16_t qlimit,   // limit
-        uint8x16_t qthresh,  // thresh
-        uint8x16_t q3,       // p3
-        uint8x16_t q4,       // p2
-        uint8x16_t q5,       // p1
-        uint8x16_t q6,       // p0
-        uint8x16_t q7,       // q0
-        uint8x16_t q8,       // q1
-        uint8x16_t q9,       // q2
-        uint8x16_t q10,      // q3
-        uint8x16_t *q5r,     // p1
-        uint8x16_t *q6r,     // p0
-        uint8x16_t *q7r,     // q0
-        uint8x16_t *q8r) {   // q1
-    uint8x16_t q0u8, q1u8, q2u8, q11u8, q12u8, q13u8, q14u8, q15u8;
-    int16x8_t q2s16, q11s16;
-    uint16x8_t q4u16;
-    int8x16_t q1s8, q2s8, q10s8, q11s8, q12s8, q13s8;
-    int8x8_t d2s8, d3s8;
-
-    q11u8 = vabdq_u8(q3, q4);
-    q12u8 = vabdq_u8(q4, q5);
-    q13u8 = vabdq_u8(q5, q6);
-    q14u8 = vabdq_u8(q8, q7);
-    q3    = vabdq_u8(q9, q8);
-    q4    = vabdq_u8(q10, q9);
-
-    q11u8 = vmaxq_u8(q11u8, q12u8);
-    q12u8 = vmaxq_u8(q13u8, q14u8);
-    q3    = vmaxq_u8(q3, q4);
-    q15u8 = vmaxq_u8(q11u8, q12u8);
-
-    q9 = vabdq_u8(q6, q7);
-
-    // vp8_hevmask
-    q13u8 = vcgtq_u8(q13u8, qthresh);
-    q14u8 = vcgtq_u8(q14u8, qthresh);
-    q15u8 = vmaxq_u8(q15u8, q3);
-
-    q2u8 = vabdq_u8(q5, q8);
-    q9 = vqaddq_u8(q9, q9);
-
-    q15u8 = vcgeq_u8(qlimit, q15u8);
-
-    // vp8_filter() function
-    // convert to signed
-    q10 = vdupq_n_u8(0x80);
-    q8 = veorq_u8(q8, q10);
-    q7 = veorq_u8(q7, q10);
-    q6 = veorq_u8(q6, q10);
-    q5 = veorq_u8(q5, q10);
-
-    q2u8 = vshrq_n_u8(q2u8, 1);
-    q9 = vqaddq_u8(q9, q2u8);
-
-    q10 = vdupq_n_u8(3);
-
-    q2s16 = vsubl_s8(vget_low_s8(vreinterpretq_s8_u8(q7)),
-                     vget_low_s8(vreinterpretq_s8_u8(q6)));
-    q11s16 = vsubl_s8(vget_high_s8(vreinterpretq_s8_u8(q7)),
-                      vget_high_s8(vreinterpretq_s8_u8(q6)));
-
-    q9 = vcgeq_u8(qblimit, q9);
-
-    q1s8 = vqsubq_s8(vreinterpretq_s8_u8(q5),
-                    vreinterpretq_s8_u8(q8));
-
-    q14u8 = vorrq_u8(q13u8, q14u8);
-
-    q4u16 = vmovl_u8(vget_low_u8(q10));
-    q2s16 = vmulq_s16(q2s16, vreinterpretq_s16_u16(q4u16));
-    q11s16 = vmulq_s16(q11s16, vreinterpretq_s16_u16(q4u16));
-
-    q1u8 = vandq_u8(vreinterpretq_u8_s8(q1s8), q14u8);
-    q15u8 = vandq_u8(q15u8, q9);
-
-    q1s8 = vreinterpretq_s8_u8(q1u8);
-    q2s16 = vaddw_s8(q2s16, vget_low_s8(q1s8));
-    q11s16 = vaddw_s8(q11s16, vget_high_s8(q1s8));
-
-    q9 = vdupq_n_u8(4);
-    // vp8_filter = clamp(vp8_filter + 3 * ( qs0 - ps0))
-    d2s8 = vqmovn_s16(q2s16);
-    d3s8 = vqmovn_s16(q11s16);
-    q1s8 = vcombine_s8(d2s8, d3s8);
-    q1u8 = vandq_u8(vreinterpretq_u8_s8(q1s8), q15u8);
-    q1s8 = vreinterpretq_s8_u8(q1u8);
-
-    q2s8 = vqaddq_s8(q1s8, vreinterpretq_s8_u8(q10));
-    q1s8 = vqaddq_s8(q1s8, vreinterpretq_s8_u8(q9));
-    q2s8 = vshrq_n_s8(q2s8, 3);
-    q1s8 = vshrq_n_s8(q1s8, 3);
-
-    q11s8 = vqaddq_s8(vreinterpretq_s8_u8(q6), q2s8);
-    q10s8 = vqsubq_s8(vreinterpretq_s8_u8(q7), q1s8);
-
-    q1s8 = vrshrq_n_s8(q1s8, 1);
-    q1s8 = vbicq_s8(q1s8, vreinterpretq_s8_u8(q14u8));
-
-    q13s8 = vqaddq_s8(vreinterpretq_s8_u8(q5), q1s8);
-    q12s8 = vqsubq_s8(vreinterpretq_s8_u8(q8), q1s8);
-
-    q0u8 = vdupq_n_u8(0x80);
-    *q8r = veorq_u8(vreinterpretq_u8_s8(q12s8), q0u8);
-    *q7r = veorq_u8(vreinterpretq_u8_s8(q10s8), q0u8);
-    *q6r = veorq_u8(vreinterpretq_u8_s8(q11s8), q0u8);
-    *q5r = veorq_u8(vreinterpretq_u8_s8(q13s8), q0u8);
-    return;
-}
-
-void vp8_loop_filter_horizontal_edge_y_neon(
-        unsigned char *src,
-        int pitch,
-        unsigned char blimit,
-        unsigned char limit,
-        unsigned char thresh) {
-    uint8x16_t qblimit, qlimit, qthresh, q3, q4;
-    uint8x16_t q5, q6, q7, q8, q9, q10;
-
-    qblimit = vdupq_n_u8(blimit);
-    qlimit  = vdupq_n_u8(limit);
-    qthresh = vdupq_n_u8(thresh);
-    src -= (pitch << 2);
-
-    q3 = vld1q_u8(src);
-    src += pitch;
-    q4 = vld1q_u8(src);
-    src += pitch;
-    q5 = vld1q_u8(src);
-    src += pitch;
-    q6 = vld1q_u8(src);
-    src += pitch;
-    q7 = vld1q_u8(src);
-    src += pitch;
-    q8 = vld1q_u8(src);
-    src += pitch;
-    q9 = vld1q_u8(src);
-    src += pitch;
-    q10 = vld1q_u8(src);
-
-    vp8_loop_filter_neon(qblimit, qlimit, qthresh, q3, q4,
-                         q5, q6, q7, q8, q9, q10,
-                         &q5, &q6, &q7, &q8);
-
-    src -= (pitch * 5);
-    vst1q_u8(src, q5);
-    src += pitch;
-    vst1q_u8(src, q6);
-    src += pitch;
-    vst1q_u8(src, q7);
-    src += pitch;
-    vst1q_u8(src, q8);
-    return;
-}
-
-void vp8_loop_filter_horizontal_edge_uv_neon(
-        unsigned char *u,
-        int pitch,
-        unsigned char blimit,
-        unsigned char limit,
-        unsigned char thresh,
-        unsigned char *v) {
-    uint8x16_t qblimit, qlimit, qthresh, q3, q4;
-    uint8x16_t q5, q6, q7, q8, q9, q10;
-    uint8x8_t d6, d7, d8, d9, d10, d11, d12, d13, d14;
-    uint8x8_t d15, d16, d17, d18, d19, d20, d21;
-
-    qblimit = vdupq_n_u8(blimit);
-    qlimit  = vdupq_n_u8(limit);
-    qthresh = vdupq_n_u8(thresh);
-
-    u -= (pitch << 2);
-    v -= (pitch << 2);
-
-    d6  = vld1_u8(u);
-    u += pitch;
-    d7  = vld1_u8(v);
-    v += pitch;
-    d8  = vld1_u8(u);
-    u += pitch;
-    d9  = vld1_u8(v);
-    v += pitch;
-    d10 = vld1_u8(u);
-    u += pitch;
-    d11 = vld1_u8(v);
-    v += pitch;
-    d12 = vld1_u8(u);
-    u += pitch;
-    d13 = vld1_u8(v);
-    v += pitch;
-    d14 = vld1_u8(u);
-    u += pitch;
-    d15 = vld1_u8(v);
-    v += pitch;
-    d16 = vld1_u8(u);
-    u += pitch;
-    d17 = vld1_u8(v);
-    v += pitch;
-    d18 = vld1_u8(u);
-    u += pitch;
-    d19 = vld1_u8(v);
-    v += pitch;
-    d20 = vld1_u8(u);
-    d21 = vld1_u8(v);
-
-    q3 = vcombine_u8(d6, d7);
-    q4 = vcombine_u8(d8, d9);
-    q5 = vcombine_u8(d10, d11);
-    q6 = vcombine_u8(d12, d13);
-    q7 = vcombine_u8(d14, d15);
-    q8 = vcombine_u8(d16, d17);
-    q9 = vcombine_u8(d18, d19);
-    q10 = vcombine_u8(d20, d21);
-
-    vp8_loop_filter_neon(qblimit, qlimit, qthresh, q3, q4,
-                         q5, q6, q7, q8, q9, q10,
-                         &q5, &q6, &q7, &q8);
-
-    u -= (pitch * 5);
-    vst1_u8(u, vget_low_u8(q5));
-    u += pitch;
-    vst1_u8(u, vget_low_u8(q6));
-    u += pitch;
-    vst1_u8(u, vget_low_u8(q7));
-    u += pitch;
-    vst1_u8(u, vget_low_u8(q8));
-
-    v -= (pitch * 5);
-    vst1_u8(v, vget_high_u8(q5));
-    v += pitch;
-    vst1_u8(v, vget_high_u8(q6));
-    v += pitch;
-    vst1_u8(v, vget_high_u8(q7));
-    v += pitch;
-    vst1_u8(v, vget_high_u8(q8));
-    return;
-}
-
-static INLINE void write_4x8(unsigned char *dst, int pitch,
-                             const uint8x8x4_t result) {
-#ifdef VPX_INCOMPATIBLE_GCC
-    /*
-     * uint8x8x4_t result
-    00 01 02 03 | 04 05 06 07
-    10 11 12 13 | 14 15 16 17
-    20 21 22 23 | 24 25 26 27
-    30 31 32 33 | 34 35 36 37
-    ---
-    * after vtrn_u16
-    00 01 20 21 | 04 05 24 25
-    02 03 22 23 | 06 07 26 27
-    10 11 30 31 | 14 15 34 35
-    12 13 32 33 | 16 17 36 37
-    ---
-    * after vtrn_u8
-    00 10 20 30 | 04 14 24 34
-    01 11 21 31 | 05 15 25 35
-    02 12 22 32 | 06 16 26 36
-    03 13 23 33 | 07 17 27 37
-    */
-    const uint16x4x2_t r02_u16 = vtrn_u16(vreinterpret_u16_u8(result.val[0]),
-                                          vreinterpret_u16_u8(result.val[2]));
-    const uint16x4x2_t r13_u16 = vtrn_u16(vreinterpret_u16_u8(result.val[1]),
-                                          vreinterpret_u16_u8(result.val[3]));
-    const uint8x8x2_t r01_u8 = vtrn_u8(vreinterpret_u8_u16(r02_u16.val[0]),
-                                       vreinterpret_u8_u16(r13_u16.val[0]));
-    const uint8x8x2_t r23_u8 = vtrn_u8(vreinterpret_u8_u16(r02_u16.val[1]),
-                                       vreinterpret_u8_u16(r13_u16.val[1]));
-    const uint32x2_t x_0_4 = vreinterpret_u32_u8(r01_u8.val[0]);
-    const uint32x2_t x_1_5 = vreinterpret_u32_u8(r01_u8.val[1]);
-    const uint32x2_t x_2_6 = vreinterpret_u32_u8(r23_u8.val[0]);
-    const uint32x2_t x_3_7 = vreinterpret_u32_u8(r23_u8.val[1]);
-    vst1_lane_u32((uint32_t *)dst, x_0_4, 0);
-    dst += pitch;
-    vst1_lane_u32((uint32_t *)dst, x_1_5, 0);
-    dst += pitch;
-    vst1_lane_u32((uint32_t *)dst, x_2_6, 0);
-    dst += pitch;
-    vst1_lane_u32((uint32_t *)dst, x_3_7, 0);
-    dst += pitch;
-    vst1_lane_u32((uint32_t *)dst, x_0_4, 1);
-    dst += pitch;
-    vst1_lane_u32((uint32_t *)dst, x_1_5, 1);
-    dst += pitch;
-    vst1_lane_u32((uint32_t *)dst, x_2_6, 1);
-    dst += pitch;
-    vst1_lane_u32((uint32_t *)dst, x_3_7, 1);
-#else
-    vst4_lane_u8(dst, result, 0);
-    dst += pitch;
-    vst4_lane_u8(dst, result, 1);
-    dst += pitch;
-    vst4_lane_u8(dst, result, 2);
-    dst += pitch;
-    vst4_lane_u8(dst, result, 3);
-    dst += pitch;
-    vst4_lane_u8(dst, result, 4);
-    dst += pitch;
-    vst4_lane_u8(dst, result, 5);
-    dst += pitch;
-    vst4_lane_u8(dst, result, 6);
-    dst += pitch;
-    vst4_lane_u8(dst, result, 7);
-#endif  // VPX_INCOMPATIBLE_GCC
-}
-
-void vp8_loop_filter_vertical_edge_y_neon(
-        unsigned char *src,
-        int pitch,
-        unsigned char blimit,
-        unsigned char limit,
-        unsigned char thresh) {
-    unsigned char *s, *d;
-    uint8x16_t qblimit, qlimit, qthresh, q3, q4;
-    uint8x16_t q5, q6, q7, q8, q9, q10;
-    uint8x8_t d6, d7, d8, d9, d10, d11, d12, d13, d14;
-    uint8x8_t d15, d16, d17, d18, d19, d20, d21;
-    uint32x4x2_t q2tmp0, q2tmp1, q2tmp2, q2tmp3;
-    uint16x8x2_t q2tmp4, q2tmp5, q2tmp6, q2tmp7;
-    uint8x16x2_t q2tmp8, q2tmp9, q2tmp10, q2tmp11;
-    uint8x8x4_t q4ResultH, q4ResultL;
-
-    qblimit = vdupq_n_u8(blimit);
-    qlimit  = vdupq_n_u8(limit);
-    qthresh = vdupq_n_u8(thresh);
-
-    s = src - 4;
-    d6  = vld1_u8(s);
-    s += pitch;
-    d8  = vld1_u8(s);
-    s += pitch;
-    d10 = vld1_u8(s);
-    s += pitch;
-    d12 = vld1_u8(s);
-    s += pitch;
-    d14 = vld1_u8(s);
-    s += pitch;
-    d16 = vld1_u8(s);
-    s += pitch;
-    d18 = vld1_u8(s);
-    s += pitch;
-    d20 = vld1_u8(s);
-    s += pitch;
-    d7  = vld1_u8(s);
-    s += pitch;
-    d9  = vld1_u8(s);
-    s += pitch;
-    d11 = vld1_u8(s);
-    s += pitch;
-    d13 = vld1_u8(s);
-    s += pitch;
-    d15 = vld1_u8(s);
-    s += pitch;
-    d17 = vld1_u8(s);
-    s += pitch;
-    d19 = vld1_u8(s);
-    s += pitch;
-    d21 = vld1_u8(s);
-
-    q3 = vcombine_u8(d6, d7);
-    q4 = vcombine_u8(d8, d9);
-    q5 = vcombine_u8(d10, d11);
-    q6 = vcombine_u8(d12, d13);
-    q7 = vcombine_u8(d14, d15);
-    q8 = vcombine_u8(d16, d17);
-    q9 = vcombine_u8(d18, d19);
-    q10 = vcombine_u8(d20, d21);
-
-    q2tmp0 = vtrnq_u32(vreinterpretq_u32_u8(q3), vreinterpretq_u32_u8(q7));
-    q2tmp1 = vtrnq_u32(vreinterpretq_u32_u8(q4), vreinterpretq_u32_u8(q8));
-    q2tmp2 = vtrnq_u32(vreinterpretq_u32_u8(q5), vreinterpretq_u32_u8(q9));
-    q2tmp3 = vtrnq_u32(vreinterpretq_u32_u8(q6), vreinterpretq_u32_u8(q10));
-
-    q2tmp4 = vtrnq_u16(vreinterpretq_u16_u32(q2tmp0.val[0]),
-                       vreinterpretq_u16_u32(q2tmp2.val[0]));
-    q2tmp5 = vtrnq_u16(vreinterpretq_u16_u32(q2tmp1.val[0]),
-                       vreinterpretq_u16_u32(q2tmp3.val[0]));
-    q2tmp6 = vtrnq_u16(vreinterpretq_u16_u32(q2tmp0.val[1]),
-                       vreinterpretq_u16_u32(q2tmp2.val[1]));
-    q2tmp7 = vtrnq_u16(vreinterpretq_u16_u32(q2tmp1.val[1]),
-                       vreinterpretq_u16_u32(q2tmp3.val[1]));
-
-    q2tmp8  = vtrnq_u8(vreinterpretq_u8_u16(q2tmp4.val[0]),
-                       vreinterpretq_u8_u16(q2tmp5.val[0]));
-    q2tmp9  = vtrnq_u8(vreinterpretq_u8_u16(q2tmp4.val[1]),
-                       vreinterpretq_u8_u16(q2tmp5.val[1]));
-    q2tmp10 = vtrnq_u8(vreinterpretq_u8_u16(q2tmp6.val[0]),
-                       vreinterpretq_u8_u16(q2tmp7.val[0]));
-    q2tmp11 = vtrnq_u8(vreinterpretq_u8_u16(q2tmp6.val[1]),
-                       vreinterpretq_u8_u16(q2tmp7.val[1]));
-
-    q3 = q2tmp8.val[0];
-    q4 = q2tmp8.val[1];
-    q5 = q2tmp9.val[0];
-    q6 = q2tmp9.val[1];
-    q7 = q2tmp10.val[0];
-    q8 = q2tmp10.val[1];
-    q9 = q2tmp11.val[0];
-    q10 = q2tmp11.val[1];
-
-    vp8_loop_filter_neon(qblimit, qlimit, qthresh, q3, q4,
-                         q5, q6, q7, q8, q9, q10,
-                         &q5, &q6, &q7, &q8);
-
-    q4ResultL.val[0] = vget_low_u8(q5);   // d10
-    q4ResultL.val[1] = vget_low_u8(q6);   // d12
-    q4ResultL.val[2] = vget_low_u8(q7);   // d14
-    q4ResultL.val[3] = vget_low_u8(q8);   // d16
-    q4ResultH.val[0] = vget_high_u8(q5);  // d11
-    q4ResultH.val[1] = vget_high_u8(q6);  // d13
-    q4ResultH.val[2] = vget_high_u8(q7);  // d15
-    q4ResultH.val[3] = vget_high_u8(q8);  // d17
-
-    d = src - 2;
-    write_4x8(d, pitch, q4ResultL);
-    d += pitch * 8;
-    write_4x8(d, pitch, q4ResultH);
-}
-
-void vp8_loop_filter_vertical_edge_uv_neon(
-        unsigned char *u,
-        int pitch,
-        unsigned char blimit,
-        unsigned char limit,
-        unsigned char thresh,
-        unsigned char *v) {
-    unsigned char *us, *ud;
-    unsigned char *vs, *vd;
-    uint8x16_t qblimit, qlimit, qthresh, q3, q4;
-    uint8x16_t q5, q6, q7, q8, q9, q10;
-    uint8x8_t d6, d7, d8, d9, d10, d11, d12, d13, d14;
-    uint8x8_t d15, d16, d17, d18, d19, d20, d21;
-    uint32x4x2_t q2tmp0, q2tmp1, q2tmp2, q2tmp3;
-    uint16x8x2_t q2tmp4, q2tmp5, q2tmp6, q2tmp7;
-    uint8x16x2_t q2tmp8, q2tmp9, q2tmp10, q2tmp11;
-    uint8x8x4_t q4ResultH, q4ResultL;
-
-    qblimit = vdupq_n_u8(blimit);
-    qlimit  = vdupq_n_u8(limit);
-    qthresh = vdupq_n_u8(thresh);
-
-    us = u - 4;
-    d6 = vld1_u8(us);
-    us += pitch;
-    d8 = vld1_u8(us);
-    us += pitch;
-    d10 = vld1_u8(us);
-    us += pitch;
-    d12 = vld1_u8(us);
-    us += pitch;
-    d14 = vld1_u8(us);
-    us += pitch;
-    d16 = vld1_u8(us);
-    us += pitch;
-    d18 = vld1_u8(us);
-    us += pitch;
-    d20 = vld1_u8(us);
-
-    vs = v - 4;
-    d7 = vld1_u8(vs);
-    vs += pitch;
-    d9 = vld1_u8(vs);
-    vs += pitch;
-    d11 = vld1_u8(vs);
-    vs += pitch;
-    d13 = vld1_u8(vs);
-    vs += pitch;
-    d15 = vld1_u8(vs);
-    vs += pitch;
-    d17 = vld1_u8(vs);
-    vs += pitch;
-    d19 = vld1_u8(vs);
-    vs += pitch;
-    d21 = vld1_u8(vs);
-
-    q3 = vcombine_u8(d6, d7);
-    q4 = vcombine_u8(d8, d9);
-    q5 = vcombine_u8(d10, d11);
-    q6 = vcombine_u8(d12, d13);
-    q7 = vcombine_u8(d14, d15);
-    q8 = vcombine_u8(d16, d17);
-    q9 = vcombine_u8(d18, d19);
-    q10 = vcombine_u8(d20, d21);
-
-    q2tmp0 = vtrnq_u32(vreinterpretq_u32_u8(q3), vreinterpretq_u32_u8(q7));
-    q2tmp1 = vtrnq_u32(vreinterpretq_u32_u8(q4), vreinterpretq_u32_u8(q8));
-    q2tmp2 = vtrnq_u32(vreinterpretq_u32_u8(q5), vreinterpretq_u32_u8(q9));
-    q2tmp3 = vtrnq_u32(vreinterpretq_u32_u8(q6), vreinterpretq_u32_u8(q10));
-
-    q2tmp4 = vtrnq_u16(vreinterpretq_u16_u32(q2tmp0.val[0]),
-                       vreinterpretq_u16_u32(q2tmp2.val[0]));
-    q2tmp5 = vtrnq_u16(vreinterpretq_u16_u32(q2tmp1.val[0]),
-                       vreinterpretq_u16_u32(q2tmp3.val[0]));
-    q2tmp6 = vtrnq_u16(vreinterpretq_u16_u32(q2tmp0.val[1]),
-                       vreinterpretq_u16_u32(q2tmp2.val[1]));
-    q2tmp7 = vtrnq_u16(vreinterpretq_u16_u32(q2tmp1.val[1]),
-                       vreinterpretq_u16_u32(q2tmp3.val[1]));
-
-    q2tmp8  = vtrnq_u8(vreinterpretq_u8_u16(q2tmp4.val[0]),
-                       vreinterpretq_u8_u16(q2tmp5.val[0]));
-    q2tmp9  = vtrnq_u8(vreinterpretq_u8_u16(q2tmp4.val[1]),
-                       vreinterpretq_u8_u16(q2tmp5.val[1]));
-    q2tmp10 = vtrnq_u8(vreinterpretq_u8_u16(q2tmp6.val[0]),
-                       vreinterpretq_u8_u16(q2tmp7.val[0]));
-    q2tmp11 = vtrnq_u8(vreinterpretq_u8_u16(q2tmp6.val[1]),
-                       vreinterpretq_u8_u16(q2tmp7.val[1]));
-
-    q3 = q2tmp8.val[0];
-    q4 = q2tmp8.val[1];
-    q5 = q2tmp9.val[0];
-    q6 = q2tmp9.val[1];
-    q7 = q2tmp10.val[0];
-    q8 = q2tmp10.val[1];
-    q9 = q2tmp11.val[0];
-    q10 = q2tmp11.val[1];
-
-    vp8_loop_filter_neon(qblimit, qlimit, qthresh, q3, q4,
-                         q5, q6, q7, q8, q9, q10,
-                         &q5, &q6, &q7, &q8);
-
-    q4ResultL.val[0] = vget_low_u8(q5);   // d10
-    q4ResultL.val[1] = vget_low_u8(q6);   // d12
-    q4ResultL.val[2] = vget_low_u8(q7);   // d14
-    q4ResultL.val[3] = vget_low_u8(q8);   // d16
-    ud = u - 2;
-    write_4x8(ud, pitch, q4ResultL);
-
-    q4ResultH.val[0] = vget_high_u8(q5);  // d11
-    q4ResultH.val[1] = vget_high_u8(q6);  // d13
-    q4ResultH.val[2] = vget_high_u8(q7);  // d15
-    q4ResultH.val[3] = vget_high_u8(q8);  // d17
-    vd = v - 2;
-    write_4x8(vd, pitch, q4ResultH);
-}
diff --git a/vp8/common/blockd.c b/vp8/common/blockd.c
deleted file mode 100644 (file)
index 1fc3cd0..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#include "blockd.h"
-#include "vpx_mem/vpx_mem.h"
-
-const unsigned char vp8_block2left[25] =
-{
-    0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8
-};
-const unsigned char vp8_block2above[25] =
-{
-    0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 4, 5, 4, 5, 6, 7, 6, 7, 8
-};
diff --git a/vp8/common/blockd.h b/vp8/common/blockd.h
deleted file mode 100644 (file)
index 192108a..0000000
+++ /dev/null
@@ -1,312 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#ifndef VP8_COMMON_BLOCKD_H_
-#define VP8_COMMON_BLOCKD_H_
-
-void vpx_log(const char *format, ...);
-
-#include "vpx_config.h"
-#include "vpx_scale/yv12config.h"
-#include "mv.h"
-#include "treecoder.h"
-#include "vpx_ports/mem.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/*#define DCPRED 1*/
-#define DCPREDSIMTHRESH 0
-#define DCPREDCNTTHRESH 3
-
-#define MB_FEATURE_TREE_PROBS   3
-#define MAX_MB_SEGMENTS         4
-
-#define MAX_REF_LF_DELTAS       4
-#define MAX_MODE_LF_DELTAS      4
-
-/* Segment Feature Masks */
-#define SEGMENT_DELTADATA   0
-#define SEGMENT_ABSDATA     1
-
-typedef struct
-{
-    int r, c;
-} POS;
-
-#define PLANE_TYPE_Y_NO_DC    0
-#define PLANE_TYPE_Y2         1
-#define PLANE_TYPE_UV         2
-#define PLANE_TYPE_Y_WITH_DC  3
-
-
-typedef char ENTROPY_CONTEXT;
-typedef struct
-{
-    ENTROPY_CONTEXT y1[4];
-    ENTROPY_CONTEXT u[2];
-    ENTROPY_CONTEXT v[2];
-    ENTROPY_CONTEXT y2;
-} ENTROPY_CONTEXT_PLANES;
-
-extern const unsigned char vp8_block2left[25];
-extern const unsigned char vp8_block2above[25];
-
-#define VP8_COMBINEENTROPYCONTEXTS( Dest, A, B) \
-    Dest = (A)+(B);
-
-
-typedef enum
-{
-    KEY_FRAME = 0,
-    INTER_FRAME = 1
-} FRAME_TYPE;
-
-typedef enum
-{
-    DC_PRED,            /* average of above and left pixels */
-    V_PRED,             /* vertical prediction */
-    H_PRED,             /* horizontal prediction */
-    TM_PRED,            /* Truemotion prediction */
-    B_PRED,             /* block based prediction, each block has its own prediction mode */
-
-    NEARESTMV,
-    NEARMV,
-    ZEROMV,
-    NEWMV,
-    SPLITMV,
-
-    MB_MODE_COUNT
-} MB_PREDICTION_MODE;
-
-/* Macroblock level features */
-typedef enum
-{
-    MB_LVL_ALT_Q = 0,               /* Use alternate Quantizer .... */
-    MB_LVL_ALT_LF = 1,              /* Use alternate loop filter value... */
-    MB_LVL_MAX = 2                  /* Number of MB level features supported */
-
-} MB_LVL_FEATURES;
-
-/* Segment Feature Masks */
-#define SEGMENT_ALTQ    0x01
-#define SEGMENT_ALT_LF  0x02
-
-#define VP8_YMODES  (B_PRED + 1)
-#define VP8_UV_MODES (TM_PRED + 1)
-
-#define VP8_MVREFS (1 + SPLITMV - NEARESTMV)
-
-typedef enum
-{
-    B_DC_PRED,          /* average of above and left pixels */
-    B_TM_PRED,
-
-    B_VE_PRED,           /* vertical prediction */
-    B_HE_PRED,           /* horizontal prediction */
-
-    B_LD_PRED,
-    B_RD_PRED,
-
-    B_VR_PRED,
-    B_VL_PRED,
-    B_HD_PRED,
-    B_HU_PRED,
-
-    LEFT4X4,
-    ABOVE4X4,
-    ZERO4X4,
-    NEW4X4,
-
-    B_MODE_COUNT
-} B_PREDICTION_MODE;
-
-#define VP8_BINTRAMODES (B_HU_PRED + 1)  /* 10 */
-#define VP8_SUBMVREFS (1 + NEW4X4 - LEFT4X4)
-
-/* For keyframes, intra block modes are predicted by the (already decoded)
-   modes for the Y blocks to the left and above us; for interframes, there
-   is a single probability table. */
-
-union b_mode_info
-{
-    B_PREDICTION_MODE as_mode;
-    int_mv mv;
-};
-
-typedef enum
-{
-    INTRA_FRAME = 0,
-    LAST_FRAME = 1,
-    GOLDEN_FRAME = 2,
-    ALTREF_FRAME = 3,
-    MAX_REF_FRAMES = 4
-} MV_REFERENCE_FRAME;
-
-typedef struct
-{
-    uint8_t mode, uv_mode;
-    uint8_t ref_frame;
-    uint8_t is_4x4;
-    int_mv mv;
-
-    uint8_t partitioning;
-    uint8_t mb_skip_coeff;                                /* does this mb has coefficients at all, 1=no coefficients, 0=need decode tokens */
-    uint8_t need_to_clamp_mvs;
-    uint8_t segment_id;                  /* Which set of segmentation parameters should be used for this MB */
-} MB_MODE_INFO;
-
-typedef struct modeinfo
-{
-    MB_MODE_INFO mbmi;
-    union b_mode_info bmi[16];
-} MODE_INFO;
-
-#if CONFIG_MULTI_RES_ENCODING
-/* The mb-level information needed to be stored for higher-resolution encoder */
-typedef struct
-{
-    MB_PREDICTION_MODE mode;
-    MV_REFERENCE_FRAME ref_frame;
-    int_mv mv;
-    int dissim;    /* dissimilarity level of the macroblock */
-} LOWER_RES_MB_INFO;
-
-/* The frame-level information needed to be stored for higher-resolution
- *  encoder */
-typedef struct
-{
-    FRAME_TYPE frame_type;
-    int is_frame_dropped;
-    // The frame rate for the lowest resolution.
-    double low_res_framerate;
-    /* The frame number of each reference frames */
-    unsigned int low_res_ref_frames[MAX_REF_FRAMES];
-    // The video frame counter value for the key frame, for lowest resolution.
-    unsigned int key_frame_counter_value;
-    LOWER_RES_MB_INFO *mb_info;
-} LOWER_RES_FRAME_INFO;
-#endif
-
-typedef struct blockd
-{
-    short *qcoeff;
-    short *dqcoeff;
-    unsigned char  *predictor;
-    short *dequant;
-
-    int offset;
-    char *eob;
-
-    union b_mode_info bmi;
-} BLOCKD;
-
-typedef void (*vp8_subpix_fn_t)(unsigned char *src, int src_pitch, int xofst, int yofst, unsigned char *dst, int dst_pitch);
-
-typedef struct macroblockd
-{
-    DECLARE_ALIGNED(16, unsigned char,  predictor[384]);
-    DECLARE_ALIGNED(16, short, qcoeff[400]);
-    DECLARE_ALIGNED(16, short, dqcoeff[400]);
-    DECLARE_ALIGNED(16, char,  eobs[25]);
-
-    DECLARE_ALIGNED(16, short,  dequant_y1[16]);
-    DECLARE_ALIGNED(16, short,  dequant_y1_dc[16]);
-    DECLARE_ALIGNED(16, short,  dequant_y2[16]);
-    DECLARE_ALIGNED(16, short,  dequant_uv[16]);
-
-    /* 16 Y blocks, 4 U, 4 V, 1 DC 2nd order block, each with 16 entries. */
-    BLOCKD block[25];
-    int fullpixel_mask;
-
-    YV12_BUFFER_CONFIG pre; /* Filtered copy of previous frame reconstruction */
-    YV12_BUFFER_CONFIG dst;
-
-    MODE_INFO *mode_info_context;
-    int mode_info_stride;
-
-    FRAME_TYPE frame_type;
-
-    int up_available;
-    int left_available;
-
-    unsigned char *recon_above[3];
-    unsigned char *recon_left[3];
-    int recon_left_stride[2];
-
-    /* Y,U,V,Y2 */
-    ENTROPY_CONTEXT_PLANES *above_context;
-    ENTROPY_CONTEXT_PLANES *left_context;
-
-    /* 0 indicates segmentation at MB level is not enabled. Otherwise the individual bits indicate which features are active. */
-    unsigned char segmentation_enabled;
-
-    /* 0 (do not update) 1 (update) the macroblock segmentation map. */
-    unsigned char update_mb_segmentation_map;
-
-    /* 0 (do not update) 1 (update) the macroblock segmentation feature data. */
-    unsigned char update_mb_segmentation_data;
-
-    /* 0 (do not update) 1 (update) the macroblock segmentation feature data. */
-    unsigned char mb_segement_abs_delta;
-
-    /* Per frame flags that define which MB level features (such as quantizer or loop filter level) */
-    /* are enabled and when enabled the proabilities used to decode the per MB flags in MB_MODE_INFO */
-    vp8_prob mb_segment_tree_probs[MB_FEATURE_TREE_PROBS];         /* Probability Tree used to code Segment number */
-
-    signed char segment_feature_data[MB_LVL_MAX][MAX_MB_SEGMENTS];            /* Segment parameters */
-
-    /* mode_based Loop filter adjustment */
-    unsigned char mode_ref_lf_delta_enabled;
-    unsigned char mode_ref_lf_delta_update;
-
-    /* Delta values have the range +/- MAX_LOOP_FILTER */
-    signed char last_ref_lf_deltas[MAX_REF_LF_DELTAS];                /* 0 = Intra, Last, GF, ARF */
-    signed char ref_lf_deltas[MAX_REF_LF_DELTAS];                     /* 0 = Intra, Last, GF, ARF */
-    signed char last_mode_lf_deltas[MAX_MODE_LF_DELTAS];                      /* 0 = BPRED, ZERO_MV, MV, SPLIT */
-    signed char mode_lf_deltas[MAX_MODE_LF_DELTAS];                           /* 0 = BPRED, ZERO_MV, MV, SPLIT */
-
-    /* Distance of MB away from frame edges */
-    int mb_to_left_edge;
-    int mb_to_right_edge;
-    int mb_to_top_edge;
-    int mb_to_bottom_edge;
-
-
-
-    vp8_subpix_fn_t  subpixel_predict;
-    vp8_subpix_fn_t  subpixel_predict8x4;
-    vp8_subpix_fn_t  subpixel_predict8x8;
-    vp8_subpix_fn_t  subpixel_predict16x16;
-
-    void *current_bc;
-
-    int corrupted;
-
-#if ARCH_X86 || ARCH_X86_64
-    /* This is an intermediate buffer currently used in sub-pixel motion search
-     * to keep a copy of the reference area. This buffer can be used for other
-     * purpose.
-     */
-    DECLARE_ALIGNED(32, unsigned char, y_buf[22*32]);
-#endif
-} MACROBLOCKD;
-
-
-extern void vp8_build_block_doffsets(MACROBLOCKD *x);
-extern void vp8_setup_block_dptrs(MACROBLOCKD *x);
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP8_COMMON_BLOCKD_H_
diff --git a/vp8/common/coefupdateprobs.h b/vp8/common/coefupdateprobs.h
deleted file mode 100644 (file)
index d96a19e..0000000
+++ /dev/null
@@ -1,197 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#ifndef VP8_COMMON_COEFUPDATEPROBS_H_
-#define VP8_COMMON_COEFUPDATEPROBS_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* Update probabilities for the nodes in the token entropy tree.
-   Generated file included by entropy.c */
-
-const vp8_prob vp8_coef_update_probs [BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [ENTROPY_NODES] =
-{
-    {
-        {
-            {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-        },
-        {
-            {176, 246, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {223, 241, 252, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {249, 253, 253, 255, 255, 255, 255, 255, 255, 255, 255, },
-        },
-        {
-            {255, 244, 252, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {234, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {253, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-        },
-        {
-            {255, 246, 254, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {239, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {254, 255, 254, 255, 255, 255, 255, 255, 255, 255, 255, },
-        },
-        {
-            {255, 248, 254, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {251, 255, 254, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-        },
-        {
-            {255, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {251, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {254, 255, 254, 255, 255, 255, 255, 255, 255, 255, 255, },
-        },
-        {
-            {255, 254, 253, 255, 254, 255, 255, 255, 255, 255, 255, },
-            {250, 255, 254, 255, 254, 255, 255, 255, 255, 255, 255, },
-            {254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-        },
-        {
-            {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-        },
-    },
-    {
-        {
-            {217, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {225, 252, 241, 253, 255, 255, 254, 255, 255, 255, 255, },
-            {234, 250, 241, 250, 253, 255, 253, 254, 255, 255, 255, },
-        },
-        {
-            {255, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {223, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {238, 253, 254, 254, 255, 255, 255, 255, 255, 255, 255, },
-        },
-        {
-            {255, 248, 254, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {249, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-        },
-        {
-            {255, 253, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {247, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-        },
-        {
-            {255, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {252, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-        },
-        {
-            {255, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {253, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-        },
-        {
-            {255, 254, 253, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {250, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-        },
-        {
-            {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-        },
-    },
-    {
-        {
-            {186, 251, 250, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {234, 251, 244, 254, 255, 255, 255, 255, 255, 255, 255, },
-            {251, 251, 243, 253, 254, 255, 254, 255, 255, 255, 255, },
-        },
-        {
-            {255, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {236, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {251, 253, 253, 254, 254, 255, 255, 255, 255, 255, 255, },
-        },
-        {
-            {255, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {254, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-        },
-        {
-            {255, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {254, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-        },
-        {
-            {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-        },
-        {
-            {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-        },
-        {
-            {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-        },
-        {
-            {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-        },
-    },
-    {
-        {
-            {248, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {250, 254, 252, 254, 255, 255, 255, 255, 255, 255, 255, },
-            {248, 254, 249, 253, 255, 255, 255, 255, 255, 255, 255, },
-        },
-        {
-            {255, 253, 253, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {246, 253, 253, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {252, 254, 251, 254, 254, 255, 255, 255, 255, 255, 255, },
-        },
-        {
-            {255, 254, 252, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {248, 254, 253, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {253, 255, 254, 254, 255, 255, 255, 255, 255, 255, 255, },
-        },
-        {
-            {255, 251, 254, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {245, 251, 254, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {253, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255, },
-        },
-        {
-            {255, 251, 253, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {252, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {255, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-        },
-        {
-            {255, 252, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {249, 255, 254, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {255, 255, 254, 255, 255, 255, 255, 255, 255, 255, 255, },
-        },
-        {
-            {255, 255, 253, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {250, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-        },
-        {
-            {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-        },
-    },
-};
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP8_COMMON_COEFUPDATEPROBS_H_
diff --git a/vp8/common/common.h b/vp8/common/common.h
deleted file mode 100644 (file)
index c42e875..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#ifndef VP8_COMMON_COMMON_H_
-#define VP8_COMMON_COMMON_H_
-
-#include <assert.h>
-
-/* Interface header for common constant data structures and lookup tables */
-
-#include "vpx_mem/vpx_mem.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* Only need this for fixed-size arrays, for structs just assign. */
-
-#define vp8_copy( Dest, Src) { \
-        assert( sizeof( Dest) == sizeof( Src)); \
-        memcpy( Dest, Src, sizeof( Src)); \
-    }
-
-/* Use this for variably-sized arrays. */
-
-#define vp8_copy_array( Dest, Src, N) { \
-        assert( sizeof( *(Dest)) == sizeof( *(Src))); \
-        memcpy( Dest, Src, N * sizeof( *(Src))); \
-    }
-
-#define vp8_zero( Dest)  memset( &(Dest), 0, sizeof( Dest));
-
-#define vp8_zero_array( Dest, N)  memset( Dest, 0, N * sizeof( *(Dest)));
-
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP8_COMMON_COMMON_H_
diff --git a/vp8/common/context.c b/vp8/common/context.c
deleted file mode 100644 (file)
index 99e95d3..0000000
+++ /dev/null
@@ -1,399 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#include "entropy.h"
-
-/* *** GENERATED FILE: DO NOT EDIT *** */
-
-#if 0
-int Contexts[vp8_coef_counter_dimen];
-
-const int default_contexts[vp8_coef_counter_dimen] =
-{
-    {
-        // Block Type ( 0 )
-        {
-            // Coeff Band ( 0 )
-            {   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,},
-            {   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,},
-            {   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,},
-        },
-        {
-            // Coeff Band ( 1 )
-            {30190, 26544, 225,  24,   4,   0,   0,   0,   0,   0,   0, 4171593,},
-            {26846, 25157, 1241, 130,  26,   6,   1,   0,   0,   0,   0, 149987,},
-            {10484, 9538, 1006, 160,  36,  18,   0,   0,   0,   0,   0, 15104,},
-        },
-        {
-            // Coeff Band ( 2 )
-            {25842, 40456, 1126,  83,  11,   2,   0,   0,   0,   0,   0,   0,},
-            {9338, 8010, 512,  73,   7,   3,   2,   0,   0,   0,   0, 43294,},
-            {1047, 751, 149,  31,  13,   6,   1,   0,   0,   0,   0, 879,},
-        },
-        {
-            // Coeff Band ( 3 )
-            {26136, 9826, 252,  13,   0,   0,   0,   0,   0,   0,   0,   0,},
-            {8134, 5574, 191,  14,   2,   0,   0,   0,   0,   0,   0, 35302,},
-            { 605, 677, 116,   9,   1,   0,   0,   0,   0,   0,   0, 611,},
-        },
-        {
-            // Coeff Band ( 4 )
-            {10263, 15463, 283,  17,   0,   0,   0,   0,   0,   0,   0,   0,},
-            {2773, 2191, 128,   9,   2,   2,   0,   0,   0,   0,   0, 10073,},
-            { 134, 125,  32,   4,   0,   2,   0,   0,   0,   0,   0,  50,},
-        },
-        {
-            // Coeff Band ( 5 )
-            {10483, 2663,  23,   1,   0,   0,   0,   0,   0,   0,   0,   0,},
-            {2137, 1251,  27,   1,   1,   0,   0,   0,   0,   0,   0, 14362,},
-            { 116, 156,  14,   2,   1,   0,   0,   0,   0,   0,   0, 190,},
-        },
-        {
-            // Coeff Band ( 6 )
-            {40977, 27614, 412,  28,   0,   0,   0,   0,   0,   0,   0,   0,},
-            {6113, 5213, 261,  22,   3,   0,   0,   0,   0,   0,   0, 26164,},
-            { 382, 312,  50,  14,   2,   0,   0,   0,   0,   0,   0, 345,},
-        },
-        {
-            // Coeff Band ( 7 )
-            {   0,  26,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,},
-            {   0,  13,   0,   0,   0,   0,   0,   0,   0,   0,   0, 319,},
-            {   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   8,},
-        },
-    },
-    {
-        // Block Type ( 1 )
-        {
-            // Coeff Band ( 0 )
-            {3268, 19382, 1043, 250,  93,  82,  49,  26,  17,   8,  25, 82289,},
-            {8758, 32110, 5436, 1832, 827, 668, 420, 153,  24,   0,   3, 52914,},
-            {9337, 23725, 8487, 3954, 2107, 1836, 1069, 399,  59,   0,   0, 18620,},
-        },
-        {
-            // Coeff Band ( 1 )
-            {12419, 8420, 452,  62,   9,   1,   0,   0,   0,   0,   0,   0,},
-            {11715, 8705, 693,  92,  15,   7,   2,   0,   0,   0,   0, 53988,},
-            {7603, 8585, 2306, 778, 270, 145,  39,   5,   0,   0,   0, 9136,},
-        },
-        {
-            // Coeff Band ( 2 )
-            {15938, 14335, 1207, 184,  55,  13,   4,   1,   0,   0,   0,   0,},
-            {7415, 6829, 1138, 244,  71,  26,   7,   0,   0,   0,   0, 9980,},
-            {1580, 1824, 655, 241,  89,  46,  10,   2,   0,   0,   0, 429,},
-        },
-        {
-            // Coeff Band ( 3 )
-            {19453, 5260, 201,  19,   0,   0,   0,   0,   0,   0,   0,   0,},
-            {9173, 3758, 213,  22,   1,   1,   0,   0,   0,   0,   0, 9820,},
-            {1689, 1277, 276,  51,  17,   4,   0,   0,   0,   0,   0, 679,},
-        },
-        {
-            // Coeff Band ( 4 )
-            {12076, 10667, 620,  85,  19,   9,   5,   0,   0,   0,   0,   0,},
-            {4665, 3625, 423,  55,  19,   9,   0,   0,   0,   0,   0, 5127,},
-            { 415, 440, 143,  34,  20,   7,   2,   0,   0,   0,   0, 101,},
-        },
-        {
-            // Coeff Band ( 5 )
-            {12183, 4846, 115,  11,   1,   0,   0,   0,   0,   0,   0,   0,},
-            {4226, 3149, 177,  21,   2,   0,   0,   0,   0,   0,   0, 7157,},
-            { 375, 621, 189,  51,  11,   4,   1,   0,   0,   0,   0, 198,},
-        },
-        {
-            // Coeff Band ( 6 )
-            {61658, 37743, 1203,  94,  10,   3,   0,   0,   0,   0,   0,   0,},
-            {15514, 11563, 903, 111,  14,   5,   0,   0,   0,   0,   0, 25195,},
-            { 929, 1077, 291,  78,  14,   7,   1,   0,   0,   0,   0, 507,},
-        },
-        {
-            // Coeff Band ( 7 )
-            {   0, 990,  15,   3,   0,   0,   0,   0,   0,   0,   0,   0,},
-            {   0, 412,  13,   0,   0,   0,   0,   0,   0,   0,   0, 1641,},
-            {   0,  18,   7,   1,   0,   0,   0,   0,   0,   0,   0,  30,},
-        },
-    },
-    {
-        // Block Type ( 2 )
-        {
-            // Coeff Band ( 0 )
-            { 953, 24519, 628, 120,  28,  12,   4,   0,   0,   0,   0, 2248798,},
-            {1525, 25654, 2647, 617, 239, 143,  42,   5,   0,   0,   0, 66837,},
-            {1180, 11011, 3001, 1237, 532, 448, 239,  54,   5,   0,   0, 7122,},
-        },
-        {
-            // Coeff Band ( 1 )
-            {1356, 2220,  67,  10,   4,   1,   0,   0,   0,   0,   0,   0,},
-            {1450, 2544, 102,  18,   4,   3,   0,   0,   0,   0,   0, 57063,},
-            {1182, 2110, 470, 130,  41,  21,   0,   0,   0,   0,   0, 6047,},
-        },
-        {
-            // Coeff Band ( 2 )
-            { 370, 3378, 200,  30,   5,   4,   1,   0,   0,   0,   0,   0,},
-            { 293, 1006, 131,  29,  11,   0,   0,   0,   0,   0,   0, 5404,},
-            { 114, 387,  98,  23,   4,   8,   1,   0,   0,   0,   0, 236,},
-        },
-        {
-            // Coeff Band ( 3 )
-            { 579, 194,   4,   0,   0,   0,   0,   0,   0,   0,   0,   0,},
-            { 395, 213,   5,   1,   0,   0,   0,   0,   0,   0,   0, 4157,},
-            { 119, 122,   4,   0,   0,   0,   0,   0,   0,   0,   0, 300,},
-        },
-        {
-            // Coeff Band ( 4 )
-            {  38, 557,  19,   0,   0,   0,   0,   0,   0,   0,   0,   0,},
-            {  21, 114,  12,   1,   0,   0,   0,   0,   0,   0,   0, 427,},
-            {   0,   5,   0,   0,   0,   0,   0,   0,   0,   0,   0,   7,},
-        },
-        {
-            // Coeff Band ( 5 )
-            {  52,   7,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,},
-            {  18,   6,   0,   0,   0,   0,   0,   0,   0,   0,   0, 652,},
-            {   1,   1,   0,   0,   0,   0,   0,   0,   0,   0,   0,  30,},
-        },
-        {
-            // Coeff Band ( 6 )
-            { 640, 569,  10,   0,   0,   0,   0,   0,   0,   0,   0,   0,},
-            {  25,  77,   2,   0,   0,   0,   0,   0,   0,   0,   0, 517,},
-            {   4,   7,   0,   0,   0,   0,   0,   0,   0,   0,   0,   3,},
-        },
-        {
-            // Coeff Band ( 7 )
-            {   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,},
-            {   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,},
-            {   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,},
-        },
-    },
-    {
-        // Block Type ( 3 )
-        {
-            // Coeff Band ( 0 )
-            {2506, 20161, 2707, 767, 261, 178, 107,  30,  14,   3,   0, 100694,},
-            {8806, 36478, 8817, 3268, 1280, 850, 401, 114,  42,   0,   0, 58572,},
-            {11003, 27214, 11798, 5716, 2482, 2072, 1048, 175,  32,   0,   0, 19284,},
-        },
-        {
-            // Coeff Band ( 1 )
-            {9738, 11313, 959, 205,  70,  18,  11,   1,   0,   0,   0,   0,},
-            {12628, 15085, 1507, 273,  52,  19,   9,   0,   0,   0,   0, 54280,},
-            {10701, 15846, 5561, 1926, 813, 570, 249,  36,   0,   0,   0, 6460,},
-        },
-        {
-            // Coeff Band ( 2 )
-            {6781, 22539, 2784, 634, 182, 123,  20,   4,   0,   0,   0,   0,},
-            {6263, 11544, 2649, 790, 259, 168,  27,   5,   0,   0,   0, 20539,},
-            {3109, 4075, 2031, 896, 457, 386, 158,  29,   0,   0,   0, 1138,},
-        },
-        {
-            // Coeff Band ( 3 )
-            {11515, 4079, 465,  73,   5,  14,   2,   0,   0,   0,   0,   0,},
-            {9361, 5834, 650,  96,  24,   8,   4,   0,   0,   0,   0, 22181,},
-            {4343, 3974, 1360, 415, 132,  96,  14,   1,   0,   0,   0, 1267,},
-        },
-        {
-            // Coeff Band ( 4 )
-            {4787, 9297, 823, 168,  44,  12,   4,   0,   0,   0,   0,   0,},
-            {3619, 4472, 719, 198,  60,  31,   3,   0,   0,   0,   0, 8401,},
-            {1157, 1175, 483, 182,  88,  31,   8,   0,   0,   0,   0, 268,},
-        },
-        {
-            // Coeff Band ( 5 )
-            {8299, 1226,  32,   5,   1,   0,   0,   0,   0,   0,   0,   0,},
-            {3502, 1568,  57,   4,   1,   1,   0,   0,   0,   0,   0, 9811,},
-            {1055, 1070, 166,  29,   6,   1,   0,   0,   0,   0,   0, 527,},
-        },
-        {
-            // Coeff Band ( 6 )
-            {27414, 27927, 1989, 347,  69,  26,   0,   0,   0,   0,   0,   0,},
-            {5876, 10074, 1574, 341,  91,  24,   4,   0,   0,   0,   0, 21954,},
-            {1571, 2171, 778, 324, 124,  65,  16,   0,   0,   0,   0, 979,},
-        },
-        {
-            // Coeff Band ( 7 )
-            {   0,  29,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,},
-            {   0,  23,   0,   0,   0,   0,   0,   0,   0,   0,   0, 459,},
-            {   0,   1,   0,   0,   0,   0,   0,   0,   0,   0,   0,  13,},
-        },
-    },
-};
-
-//Update probabilities for the nodes in the token entropy tree.
-const vp8_prob tree_update_probs[vp8_coef_tree_dimen] =
-{
-    {
-        {
-            {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-        },
-        {
-            {176, 246, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {223, 241, 252, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {249, 253, 253, 255, 255, 255, 255, 255, 255, 255, 255, },
-        },
-        {
-            {255, 244, 252, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {234, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {253, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-        },
-        {
-            {255, 246, 254, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {239, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {254, 255, 254, 255, 255, 255, 255, 255, 255, 255, 255, },
-        },
-        {
-            {255, 248, 254, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {251, 255, 254, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-        },
-        {
-            {255, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {251, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {254, 255, 254, 255, 255, 255, 255, 255, 255, 255, 255, },
-        },
-        {
-            {255, 254, 253, 255, 254, 255, 255, 255, 255, 255, 255, },
-            {250, 255, 254, 255, 254, 255, 255, 255, 255, 255, 255, },
-            {254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-        },
-        {
-            {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-        },
-    },
-    {
-        {
-            {217, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {225, 252, 241, 253, 255, 255, 254, 255, 255, 255, 255, },
-            {234, 250, 241, 250, 253, 255, 253, 254, 255, 255, 255, },
-        },
-        {
-            {255, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {223, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {238, 253, 254, 254, 255, 255, 255, 255, 255, 255, 255, },
-        },
-        {
-            {255, 248, 254, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {249, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-        },
-        {
-            {255, 253, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {247, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-        },
-        {
-            {255, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {252, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-        },
-        {
-            {255, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {253, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-        },
-        {
-            {255, 254, 253, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {250, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-        },
-        {
-            {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-        },
-    },
-    {
-        {
-            {186, 251, 250, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {234, 251, 244, 254, 255, 255, 255, 255, 255, 255, 255, },
-            {251, 251, 243, 253, 254, 255, 254, 255, 255, 255, 255, },
-        },
-        {
-            {255, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {236, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {251, 253, 253, 254, 254, 255, 255, 255, 255, 255, 255, },
-        },
-        {
-            {255, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {254, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-        },
-        {
-            {255, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {254, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-        },
-        {
-            {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-        },
-        {
-            {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-        },
-        {
-            {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-        },
-        {
-            {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-        },
-    },
-    {
-        {
-            {248, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {250, 254, 252, 254, 255, 255, 255, 255, 255, 255, 255, },
-            {248, 254, 249, 253, 255, 255, 255, 255, 255, 255, 255, },
-        },
-        {
-            {255, 253, 253, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {246, 253, 253, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {252, 254, 251, 254, 254, 255, 255, 255, 255, 255, 255, },
-        },
-        {
-            {255, 254, 252, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {248, 254, 253, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {253, 255, 254, 254, 255, 255, 255, 255, 255, 255, 255, },
-        },
-        {
-            {255, 251, 254, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {245, 251, 254, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {253, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255, },
-        },
-        {
-            {255, 251, 253, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {252, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {255, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-        },
-        {
-            {255, 252, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {249, 255, 254, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {255, 255, 254, 255, 255, 255, 255, 255, 255, 255, 255, },
-        },
-        {
-            {255, 255, 253, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {250, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-        },
-        {
-            {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-            {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
-        },
-    },
-};
-#endif
diff --git a/vp8/common/copy_c.c b/vp8/common/copy_c.c
deleted file mode 100644 (file)
index e339291..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#include <string.h>
-
-#include "./vp8_rtcd.h"
-#include "vpx/vpx_integer.h"
-
-/* Copy 2 macroblocks to a buffer */
-void vp8_copy32xn_c(const unsigned char *src_ptr, int src_stride,
-                    unsigned char *dst_ptr, int dst_stride,
-                    int height)
-{
-    int r;
-
-    for (r = 0; r < height; r++)
-    {
-        memcpy(dst_ptr, src_ptr, 32);
-
-        src_ptr += src_stride;
-        dst_ptr += dst_stride;
-
-    }
-}
diff --git a/vp8/common/debugmodes.c b/vp8/common/debugmodes.c
deleted file mode 100644 (file)
index 159fddc..0000000
+++ /dev/null
@@ -1,155 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#include <stdio.h>
-#include "blockd.h"
-
-
-void vp8_print_modes_and_motion_vectors(MODE_INFO *mi, int rows, int cols, int frame)
-{
-
-    int mb_row;
-    int mb_col;
-    int mb_index = 0;
-    FILE *mvs = fopen("mvs.stt", "a");
-
-    /* print out the macroblock Y modes */
-    mb_index = 0;
-    fprintf(mvs, "Mb Modes for Frame %d\n", frame);
-
-    for (mb_row = 0; mb_row < rows; mb_row++)
-    {
-        for (mb_col = 0; mb_col < cols; mb_col++)
-        {
-
-            fprintf(mvs, "%2d ", mi[mb_index].mbmi.mode);
-
-            mb_index++;
-        }
-
-        fprintf(mvs, "\n");
-        mb_index++;
-    }
-
-    fprintf(mvs, "\n");
-
-    mb_index = 0;
-    fprintf(mvs, "Mb mv ref for Frame %d\n", frame);
-
-    for (mb_row = 0; mb_row < rows; mb_row++)
-    {
-        for (mb_col = 0; mb_col < cols; mb_col++)
-        {
-
-            fprintf(mvs, "%2d ", mi[mb_index].mbmi.ref_frame);
-
-            mb_index++;
-        }
-
-        fprintf(mvs, "\n");
-        mb_index++;
-    }
-
-    fprintf(mvs, "\n");
-
-    /* print out the macroblock UV modes */
-    mb_index = 0;
-    fprintf(mvs, "UV Modes for Frame %d\n", frame);
-
-    for (mb_row = 0; mb_row < rows; mb_row++)
-    {
-        for (mb_col = 0; mb_col < cols; mb_col++)
-        {
-
-            fprintf(mvs, "%2d ", mi[mb_index].mbmi.uv_mode);
-
-            mb_index++;
-        }
-
-        mb_index++;
-        fprintf(mvs, "\n");
-    }
-
-    fprintf(mvs, "\n");
-
-    /* print out the block modes */
-    fprintf(mvs, "Mbs for Frame %d\n", frame);
-    {
-        int b_row;
-
-        for (b_row = 0; b_row < 4 * rows; b_row++)
-        {
-            int b_col;
-            int bindex;
-
-            for (b_col = 0; b_col < 4 * cols; b_col++)
-            {
-                mb_index = (b_row >> 2) * (cols + 1) + (b_col >> 2);
-                bindex = (b_row & 3) * 4 + (b_col & 3);
-
-                if (mi[mb_index].mbmi.mode == B_PRED)
-                    fprintf(mvs, "%2d ", mi[mb_index].bmi[bindex].as_mode);
-                else
-                    fprintf(mvs, "xx ");
-
-            }
-
-            fprintf(mvs, "\n");
-        }
-    }
-    fprintf(mvs, "\n");
-
-    /* print out the macroblock mvs */
-    mb_index = 0;
-    fprintf(mvs, "MVs for Frame %d\n", frame);
-
-    for (mb_row = 0; mb_row < rows; mb_row++)
-    {
-        for (mb_col = 0; mb_col < cols; mb_col++)
-        {
-            fprintf(mvs, "%5d:%-5d", mi[mb_index].mbmi.mv.as_mv.row / 2, mi[mb_index].mbmi.mv.as_mv.col / 2);
-
-            mb_index++;
-        }
-
-        mb_index++;
-        fprintf(mvs, "\n");
-    }
-
-    fprintf(mvs, "\n");
-
-
-    /* print out the block modes */
-    fprintf(mvs, "MVs for Frame %d\n", frame);
-    {
-        int b_row;
-
-        for (b_row = 0; b_row < 4 * rows; b_row++)
-        {
-            int b_col;
-            int bindex;
-
-            for (b_col = 0; b_col < 4 * cols; b_col++)
-            {
-                mb_index = (b_row >> 2) * (cols + 1) + (b_col >> 2);
-                bindex = (b_row & 3) * 4 + (b_col & 3);
-                fprintf(mvs, "%3d:%-3d ", mi[mb_index].bmi[bindex].mv.as_mv.row, mi[mb_index].bmi[bindex].mv.as_mv.col);
-
-            }
-
-            fprintf(mvs, "\n");
-        }
-    }
-    fprintf(mvs, "\n");
-
-
-    fclose(mvs);
-}
diff --git a/vp8/common/default_coef_probs.h b/vp8/common/default_coef_probs.h
deleted file mode 100644 (file)
index 4d69e4b..0000000
+++ /dev/null
@@ -1,200 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
-*/
-
-#ifndef VP8_COMMON_DEFAULT_COEF_PROBS_H_
-#define VP8_COMMON_DEFAULT_COEF_PROBS_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/*Generated file, included by entropy.c*/
-
-
-static const vp8_prob default_coef_probs [BLOCK_TYPES]
-                                         [COEF_BANDS]
-                                         [PREV_COEF_CONTEXTS]
-                                         [ENTROPY_NODES] =
-{
-    { /* Block Type ( 0 ) */
-        { /* Coeff Band ( 0 )*/
-            { 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128 },
-            { 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128 },
-            { 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128 }
-        },
-        { /* Coeff Band ( 1 )*/
-            { 253, 136, 254, 255, 228, 219, 128, 128, 128, 128, 128 },
-            { 189, 129, 242, 255, 227, 213, 255, 219, 128, 128, 128 },
-            { 106, 126, 227, 252, 214, 209, 255, 255, 128, 128, 128 }
-        },
-        { /* Coeff Band ( 2 )*/
-            {   1,  98, 248, 255, 236, 226, 255, 255, 128, 128, 128 },
-            { 181, 133, 238, 254, 221, 234, 255, 154, 128, 128, 128 },
-            {  78, 134, 202, 247, 198, 180, 255, 219, 128, 128, 128 }
-        },
-        { /* Coeff Band ( 3 )*/
-            {   1, 185, 249, 255, 243, 255, 128, 128, 128, 128, 128 },
-            { 184, 150, 247, 255, 236, 224, 128, 128, 128, 128, 128 },
-            {  77, 110, 216, 255, 236, 230, 128, 128, 128, 128, 128 }
-        },
-        { /* Coeff Band ( 4 )*/
-            {   1, 101, 251, 255, 241, 255, 128, 128, 128, 128, 128 },
-            { 170, 139, 241, 252, 236, 209, 255, 255, 128, 128, 128 },
-            {  37, 116, 196, 243, 228, 255, 255, 255, 128, 128, 128 }
-        },
-        { /* Coeff Band ( 5 )*/
-            {   1, 204, 254, 255, 245, 255, 128, 128, 128, 128, 128 },
-            { 207, 160, 250, 255, 238, 128, 128, 128, 128, 128, 128 },
-            { 102, 103, 231, 255, 211, 171, 128, 128, 128, 128, 128 }
-        },
-        { /* Coeff Band ( 6 )*/
-            {   1, 152, 252, 255, 240, 255, 128, 128, 128, 128, 128 },
-            { 177, 135, 243, 255, 234, 225, 128, 128, 128, 128, 128 },
-            {  80, 129, 211, 255, 194, 224, 128, 128, 128, 128, 128 }
-        },
-        { /* Coeff Band ( 7 )*/
-            {   1,   1, 255, 128, 128, 128, 128, 128, 128, 128, 128 },
-            { 246,   1, 255, 128, 128, 128, 128, 128, 128, 128, 128 },
-            { 255, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128 }
-        }
-    },
-    { /* Block Type ( 1 ) */
-        { /* Coeff Band ( 0 )*/
-            { 198,  35, 237, 223, 193, 187, 162, 160, 145, 155,  62 },
-            { 131,  45, 198, 221, 172, 176, 220, 157, 252, 221,   1 },
-            {  68,  47, 146, 208, 149, 167, 221, 162, 255, 223, 128 }
-        },
-        { /* Coeff Band ( 1 )*/
-            {   1, 149, 241, 255, 221, 224, 255, 255, 128, 128, 128 },
-            { 184, 141, 234, 253, 222, 220, 255, 199, 128, 128, 128 },
-            {  81,  99, 181, 242, 176, 190, 249, 202, 255, 255, 128 }
-        },
-        { /* Coeff Band ( 2 )*/
-            {   1, 129, 232, 253, 214, 197, 242, 196, 255, 255, 128 },
-            {  99, 121, 210, 250, 201, 198, 255, 202, 128, 128, 128 },
-            {  23,  91, 163, 242, 170, 187, 247, 210, 255, 255, 128 }
-        },
-        { /* Coeff Band ( 3 )*/
-            {   1, 200, 246, 255, 234, 255, 128, 128, 128, 128, 128 },
-            { 109, 178, 241, 255, 231, 245, 255, 255, 128, 128, 128 },
-            {  44, 130, 201, 253, 205, 192, 255, 255, 128, 128, 128 }
-        },
-        { /* Coeff Band ( 4 )*/
-            {   1, 132, 239, 251, 219, 209, 255, 165, 128, 128, 128 },
-            {  94, 136, 225, 251, 218, 190, 255, 255, 128, 128, 128 },
-            {  22, 100, 174, 245, 186, 161, 255, 199, 128, 128, 128 }
-        },
-        { /* Coeff Band ( 5 )*/
-            {   1, 182, 249, 255, 232, 235, 128, 128, 128, 128, 128 },
-            { 124, 143, 241, 255, 227, 234, 128, 128, 128, 128, 128 },
-            {  35,  77, 181, 251, 193, 211, 255, 205, 128, 128, 128 }
-        },
-        { /* Coeff Band ( 6 )*/
-            {   1, 157, 247, 255, 236, 231, 255, 255, 128, 128, 128 },
-            { 121, 141, 235, 255, 225, 227, 255, 255, 128, 128, 128 },
-            {  45,  99, 188, 251, 195, 217, 255, 224, 128, 128, 128 }
-        },
-        { /* Coeff Band ( 7 )*/
-            {   1,   1, 251, 255, 213, 255, 128, 128, 128, 128, 128 },
-            { 203,   1, 248, 255, 255, 128, 128, 128, 128, 128, 128 },
-            { 137,   1, 177, 255, 224, 255, 128, 128, 128, 128, 128 }
-        }
-    },
-    { /* Block Type ( 2 ) */
-        { /* Coeff Band ( 0 )*/
-            { 253,   9, 248, 251, 207, 208, 255, 192, 128, 128, 128 },
-            { 175,  13, 224, 243, 193, 185, 249, 198, 255, 255, 128 },
-            {  73,  17, 171, 221, 161, 179, 236, 167, 255, 234, 128 }
-        },
-        { /* Coeff Band ( 1 )*/
-            {   1,  95, 247, 253, 212, 183, 255, 255, 128, 128, 128 },
-            { 239,  90, 244, 250, 211, 209, 255, 255, 128, 128, 128 },
-            { 155,  77, 195, 248, 188, 195, 255, 255, 128, 128, 128 }
-        },
-        { /* Coeff Band ( 2 )*/
-            {   1,  24, 239, 251, 218, 219, 255, 205, 128, 128, 128 },
-            { 201,  51, 219, 255, 196, 186, 128, 128, 128, 128, 128 },
-            {  69,  46, 190, 239, 201, 218, 255, 228, 128, 128, 128 }
-        },
-        { /* Coeff Band ( 3 )*/
-            {   1, 191, 251, 255, 255, 128, 128, 128, 128, 128, 128 },
-            { 223, 165, 249, 255, 213, 255, 128, 128, 128, 128, 128 },
-            { 141, 124, 248, 255, 255, 128, 128, 128, 128, 128, 128 }
-        },
-        { /* Coeff Band ( 4 )*/
-            {   1,  16, 248, 255, 255, 128, 128, 128, 128, 128, 128 },
-            { 190,  36, 230, 255, 236, 255, 128, 128, 128, 128, 128 },
-            { 149,   1, 255, 128, 128, 128, 128, 128, 128, 128, 128 }
-        },
-        { /* Coeff Band ( 5 )*/
-            {   1, 226, 255, 128, 128, 128, 128, 128, 128, 128, 128 },
-            { 247, 192, 255, 128, 128, 128, 128, 128, 128, 128, 128 },
-            { 240, 128, 255, 128, 128, 128, 128, 128, 128, 128, 128 }
-        },
-        { /* Coeff Band ( 6 )*/
-            {   1, 134, 252, 255, 255, 128, 128, 128, 128, 128, 128 },
-            { 213,  62, 250, 255, 255, 128, 128, 128, 128, 128, 128 },
-            {  55,  93, 255, 128, 128, 128, 128, 128, 128, 128, 128 }
-        },
-        { /* Coeff Band ( 7 )*/
-            { 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128 },
-            { 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128 },
-            { 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128 }
-        }
-    },
-    { /* Block Type ( 3 ) */
-        { /* Coeff Band ( 0 )*/
-            { 202,  24, 213, 235, 186, 191, 220, 160, 240, 175, 255 },
-            { 126,  38, 182, 232, 169, 184, 228, 174, 255, 187, 128 },
-            {  61,  46, 138, 219, 151, 178, 240, 170, 255, 216, 128 }
-        },
-        { /* Coeff Band ( 1 )*/
-            {   1, 112, 230, 250, 199, 191, 247, 159, 255, 255, 128 },
-            { 166, 109, 228, 252, 211, 215, 255, 174, 128, 128, 128 },
-            {  39,  77, 162, 232, 172, 180, 245, 178, 255, 255, 128 }
-        },
-        { /* Coeff Band ( 2 )*/
-            {   1,  52, 220, 246, 198, 199, 249, 220, 255, 255, 128 },
-            { 124,  74, 191, 243, 183, 193, 250, 221, 255, 255, 128 },
-            {  24,  71, 130, 219, 154, 170, 243, 182, 255, 255, 128 }
-        },
-        { /* Coeff Band ( 3 )*/
-            {   1, 182, 225, 249, 219, 240, 255, 224, 128, 128, 128 },
-            { 149, 150, 226, 252, 216, 205, 255, 171, 128, 128, 128 },
-            {  28, 108, 170, 242, 183, 194, 254, 223, 255, 255, 128 }
-        },
-        { /* Coeff Band ( 4 )*/
-            {   1,  81, 230, 252, 204, 203, 255, 192, 128, 128, 128 },
-            { 123, 102, 209, 247, 188, 196, 255, 233, 128, 128, 128 },
-            {  20,  95, 153, 243, 164, 173, 255, 203, 128, 128, 128 }
-        },
-        { /* Coeff Band ( 5 )*/
-            {   1, 222, 248, 255, 216, 213, 128, 128, 128, 128, 128 },
-            { 168, 175, 246, 252, 235, 205, 255, 255, 128, 128, 128 },
-            {  47, 116, 215, 255, 211, 212, 255, 255, 128, 128, 128 }
-        },
-        { /* Coeff Band ( 6 )*/
-            {   1, 121, 236, 253, 212, 214, 255, 255, 128, 128, 128 },
-            { 141,  84, 213, 252, 201, 202, 255, 219, 128, 128, 128 },
-            {  42,  80, 160, 240, 162, 185, 255, 205, 128, 128, 128 }
-        },
-        { /* Coeff Band ( 7 )*/
-            {   1,   1, 255, 128, 128, 128, 128, 128, 128, 128, 128 },
-            { 244,   1, 255, 128, 128, 128, 128, 128, 128, 128, 128 },
-            { 238,   1, 255, 128, 128, 128, 128, 128, 128, 128, 128 }
-        }
-    }
-};
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP8_COMMON_DEFAULT_COEF_PROBS_H_
diff --git a/vp8/common/dequantize.c b/vp8/common/dequantize.c
deleted file mode 100644 (file)
index f8b04fa..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#include "vpx_config.h"
-#include "vp8_rtcd.h"
-#include "vp8/common/blockd.h"
-#include "vpx_mem/vpx_mem.h"
-
-void vp8_dequantize_b_c(BLOCKD *d, short *DQC)
-{
-    int i;
-    short *DQ  = d->dqcoeff;
-    short *Q   = d->qcoeff;
-
-    for (i = 0; i < 16; i++)
-    {
-        DQ[i] = Q[i] * DQC[i];
-    }
-}
-
-void vp8_dequant_idct_add_c(short *input, short *dq,
-                            unsigned char *dest, int stride)
-{
-    int i;
-
-    for (i = 0; i < 16; i++)
-    {
-        input[i] = dq[i] * input[i];
-    }
-
-    vp8_short_idct4x4llm_c(input, dest, stride, dest, stride);
-
-    memset(input, 0, 32);
-
-}
diff --git a/vp8/common/entropy.c b/vp8/common/entropy.c
deleted file mode 100644 (file)
index c00e565..0000000
+++ /dev/null
@@ -1,188 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#include "entropy.h"
-#include "blockd.h"
-#include "onyxc_int.h"
-#include "vpx_mem/vpx_mem.h"
-
-#include "coefupdateprobs.h"
-
-DECLARE_ALIGNED(16, const unsigned char, vp8_norm[256]) =
-{
-    0, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4,
-    3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
-    2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
-    2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
-    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
-    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
-    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
-    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
-    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
-};
-
-DECLARE_ALIGNED(16, const unsigned char, vp8_coef_bands[16]) =
-{ 0, 1, 2, 3, 6, 4, 5, 6, 6, 6, 6, 6, 6, 6, 6, 7};
-
-DECLARE_ALIGNED(16, const unsigned char,
-                vp8_prev_token_class[MAX_ENTROPY_TOKENS]) =
-{ 0, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0};
-
-DECLARE_ALIGNED(16, const int, vp8_default_zig_zag1d[16]) =
-{
-    0,  1,  4,  8,
-    5,  2,  3,  6,
-    9, 12, 13, 10,
-    7, 11, 14, 15,
-};
-
-DECLARE_ALIGNED(16, const short, vp8_default_inv_zig_zag[16]) =
-{
-    1,  2,  6,  7,
-    3,  5,  8, 13,
-    4,  9, 12, 14,
-   10, 11, 15, 16
-};
-
-/* vp8_default_zig_zag_mask generated with:
-
-    void vp8_init_scan_order_mask()
-    {
-        int i;
-
-        for (i = 0; i < 16; i++)
-        {
-            vp8_default_zig_zag_mask[vp8_default_zig_zag1d[i]] = 1 << i;
-        }
-
-    }
-*/
-DECLARE_ALIGNED(16, const short, vp8_default_zig_zag_mask[16]) =
-{
-     1,    2,    32,     64,
-     4,   16,   128,   4096,
-     8,  256,  2048,   8192,
-   512, 1024, 16384, -32768
-};
-
-const int vp8_mb_feature_data_bits[MB_LVL_MAX] = {7, 6};
-
-/* Array indices are identical to previously-existing CONTEXT_NODE indices */
-
-const vp8_tree_index vp8_coef_tree[ 22] =     /* corresponding _CONTEXT_NODEs */
-{
-    -DCT_EOB_TOKEN, 2,                             /* 0 = EOB */
-    -ZERO_TOKEN, 4,                               /* 1 = ZERO */
-    -ONE_TOKEN, 6,                               /* 2 = ONE */
-    8, 12,                                      /* 3 = LOW_VAL */
-    -TWO_TOKEN, 10,                            /* 4 = TWO */
-    -THREE_TOKEN, -FOUR_TOKEN,                /* 5 = THREE */
-    14, 16,                                    /* 6 = HIGH_LOW */
-    -DCT_VAL_CATEGORY1, -DCT_VAL_CATEGORY2,   /* 7 = CAT_ONE */
-    18, 20,                                   /* 8 = CAT_THREEFOUR */
-    -DCT_VAL_CATEGORY3, -DCT_VAL_CATEGORY4,  /* 9 = CAT_THREE */
-    -DCT_VAL_CATEGORY5, -DCT_VAL_CATEGORY6   /* 10 = CAT_FIVE */
-};
-
-/* vp8_coef_encodings generated with:
-    vp8_tokens_from_tree(vp8_coef_encodings, vp8_coef_tree);
-*/
-vp8_token vp8_coef_encodings[MAX_ENTROPY_TOKENS] =
-{
-    {2, 2},
-    {6, 3},
-    {28, 5},
-    {58, 6},
-    {59, 6},
-    {60, 6},
-    {61, 6},
-    {124, 7},
-    {125, 7},
-    {126, 7},
-    {127, 7},
-    {0, 1}
-};
-
-/* Trees for extra bits.  Probabilities are constant and
-   do not depend on previously encoded bits */
-
-static const vp8_prob Pcat1[] = { 159};
-static const vp8_prob Pcat2[] = { 165, 145};
-static const vp8_prob Pcat3[] = { 173, 148, 140};
-static const vp8_prob Pcat4[] = { 176, 155, 140, 135};
-static const vp8_prob Pcat5[] = { 180, 157, 141, 134, 130};
-static const vp8_prob Pcat6[] =
-{ 254, 254, 243, 230, 196, 177, 153, 140, 133, 130, 129};
-
-
-/* tree index tables generated with:
-
-    void init_bit_tree(vp8_tree_index *p, int n)
-    {
-        int i = 0;
-
-        while (++i < n)
-        {
-            p[0] = p[1] = i << 1;
-            p += 2;
-        }
-
-        p[0] = p[1] = 0;
-    }
-
-    void init_bit_trees()
-    {
-        init_bit_tree(cat1, 1);
-        init_bit_tree(cat2, 2);
-        init_bit_tree(cat3, 3);
-        init_bit_tree(cat4, 4);
-        init_bit_tree(cat5, 5);
-        init_bit_tree(cat6, 11);
-    }
-*/
-
-static const vp8_tree_index cat1[2] = { 0, 0 };
-static const vp8_tree_index cat2[4] = { 2, 2, 0, 0 };
-static const vp8_tree_index cat3[6] = { 2, 2, 4, 4, 0, 0 };
-static const vp8_tree_index cat4[8] = { 2, 2, 4, 4, 6, 6, 0, 0 };
-static const vp8_tree_index cat5[10] = { 2, 2, 4, 4, 6, 6, 8, 8, 0, 0 };
-static const vp8_tree_index cat6[22] = { 2, 2, 4, 4, 6, 6, 8, 8, 10, 10, 12, 12,
-                                        14, 14, 16, 16, 18, 18, 20, 20, 0, 0 };
-
-const vp8_extra_bit_struct vp8_extra_bits[12] =
-{
-    { 0, 0, 0, 0},
-    { 0, 0, 0, 1},
-    { 0, 0, 0, 2},
-    { 0, 0, 0, 3},
-    { 0, 0, 0, 4},
-    { cat1, Pcat1, 1, 5},
-    { cat2, Pcat2, 2, 7},
-    { cat3, Pcat3, 3, 11},
-    { cat4, Pcat4, 4, 19},
-    { cat5, Pcat5, 5, 35},
-    { cat6, Pcat6, 11, 67},
-    { 0, 0, 0, 0}
-};
-
-#include "default_coef_probs.h"
-
-void vp8_default_coef_probs(VP8_COMMON *pc)
-{
-    memcpy(pc->fc.coef_probs, default_coef_probs, sizeof(default_coef_probs));
-}
-
diff --git a/vp8/common/entropy.h b/vp8/common/entropy.h
deleted file mode 100644 (file)
index a90bab4..0000000
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#ifndef VP8_COMMON_ENTROPY_H_
-#define VP8_COMMON_ENTROPY_H_
-
-#include "treecoder.h"
-#include "blockd.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* Coefficient token alphabet */
-
-#define ZERO_TOKEN              0       /* 0         Extra Bits 0+0 */
-#define ONE_TOKEN               1       /* 1         Extra Bits 0+1 */
-#define TWO_TOKEN               2       /* 2         Extra Bits 0+1 */
-#define THREE_TOKEN             3       /* 3         Extra Bits 0+1 */
-#define FOUR_TOKEN              4       /* 4         Extra Bits 0+1 */
-#define DCT_VAL_CATEGORY1       5       /* 5-6       Extra Bits 1+1 */
-#define DCT_VAL_CATEGORY2       6       /* 7-10      Extra Bits 2+1 */
-#define DCT_VAL_CATEGORY3       7       /* 11-18     Extra Bits 3+1 */
-#define DCT_VAL_CATEGORY4       8       /* 19-34     Extra Bits 4+1 */
-#define DCT_VAL_CATEGORY5       9       /* 35-66     Extra Bits 5+1 */
-#define DCT_VAL_CATEGORY6       10      /* 67+       Extra Bits 11+1 */
-#define DCT_EOB_TOKEN           11      /* EOB       Extra Bits 0+0 */
-
-#define MAX_ENTROPY_TOKENS 12
-#define ENTROPY_NODES 11
-
-extern const vp8_tree_index vp8_coef_tree[];
-
-extern const struct vp8_token_struct vp8_coef_encodings[MAX_ENTROPY_TOKENS];
-
-typedef struct
-{
-    vp8_tree_p tree;
-    const vp8_prob *prob;
-    int Len;
-    int base_val;
-} vp8_extra_bit_struct;
-
-extern const vp8_extra_bit_struct vp8_extra_bits[12];    /* indexed by token value */
-
-#define PROB_UPDATE_BASELINE_COST   7
-
-#define MAX_PROB                255
-#define DCT_MAX_VALUE           2048
-
-
-/* Coefficients are predicted via a 3-dimensional probability table. */
-
-/* Outside dimension.  0 = Y no DC, 1 = Y2, 2 = UV, 3 = Y with DC */
-
-#define BLOCK_TYPES 4
-
-/* Middle dimension is a coarsening of the coefficient's
-   position within the 4x4 DCT. */
-
-#define COEF_BANDS 8
-extern DECLARE_ALIGNED(16, const unsigned char, vp8_coef_bands[16]);
-
-/* Inside dimension is 3-valued measure of nearby complexity, that is,
-   the extent to which nearby coefficients are nonzero.  For the first
-   coefficient (DC, unless block type is 0), we look at the (already encoded)
-   blocks above and to the left of the current block.  The context index is
-   then the number (0,1,or 2) of these blocks having nonzero coefficients.
-   After decoding a coefficient, the measure is roughly the size of the
-   most recently decoded coefficient (0 for 0, 1 for 1, 2 for >1).
-   Note that the intuitive meaning of this measure changes as coefficients
-   are decoded, e.g., prior to the first token, a zero means that my neighbors
-   are empty while, after the first token, because of the use of end-of-block,
-   a zero means we just decoded a zero and hence guarantees that a non-zero
-   coefficient will appear later in this block.  However, this shift
-   in meaning is perfectly OK because our context depends also on the
-   coefficient band (and since zigzag positions 0, 1, and 2 are in
-   distinct bands). */
-
-/*# define DC_TOKEN_CONTEXTS        3*/ /* 00, 0!0, !0!0 */
-#   define PREV_COEF_CONTEXTS       3
-
-extern DECLARE_ALIGNED(16, const unsigned char, vp8_prev_token_class[MAX_ENTROPY_TOKENS]);
-
-extern const vp8_prob vp8_coef_update_probs [BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [ENTROPY_NODES];
-
-
-struct VP8Common;
-void vp8_default_coef_probs(struct VP8Common *);
-
-extern DECLARE_ALIGNED(16, const int, vp8_default_zig_zag1d[16]);
-extern DECLARE_ALIGNED(16, const short, vp8_default_inv_zig_zag[16]);
-extern DECLARE_ALIGNED(16, const short, vp8_default_zig_zag_mask[16]);
-extern const int vp8_mb_feature_data_bits[MB_LVL_MAX];
-
-void vp8_coef_tree_initialize(void);
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP8_COMMON_ENTROPY_H_
diff --git a/vp8/common/entropymode.c b/vp8/common/entropymode.c
deleted file mode 100644 (file)
index 8981a8d..0000000
+++ /dev/null
@@ -1,171 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#define USE_PREBUILT_TABLES
-
-#include "entropymode.h"
-#include "entropy.h"
-#include "vpx_mem/vpx_mem.h"
-
-#include "vp8_entropymodedata.h"
-
-int vp8_mv_cont(const int_mv *l, const int_mv *a)
-{
-    int lez = (l->as_int == 0);
-    int aez = (a->as_int == 0);
-    int lea = (l->as_int == a->as_int);
-
-    if (lea && lez)
-        return SUBMVREF_LEFT_ABOVE_ZED;
-
-    if (lea)
-        return SUBMVREF_LEFT_ABOVE_SAME;
-
-    if (aez)
-        return SUBMVREF_ABOVE_ZED;
-
-    if (lez)
-        return SUBMVREF_LEFT_ZED;
-
-    return SUBMVREF_NORMAL;
-}
-
-static const vp8_prob sub_mv_ref_prob [VP8_SUBMVREFS-1] = { 180, 162, 25};
-
-const vp8_prob vp8_sub_mv_ref_prob2 [SUBMVREF_COUNT][VP8_SUBMVREFS-1] =
-{
-    { 147, 136, 18 },
-    { 106, 145, 1  },
-    { 179, 121, 1  },
-    { 223, 1  , 34 },
-    { 208, 1  , 1  }
-};
-
-
-
-const vp8_mbsplit vp8_mbsplits [VP8_NUMMBSPLITS] =
-{
-    {
-        0,  0,  0,  0,
-        0,  0,  0,  0,
-        1,  1,  1,  1,
-        1,  1,  1,  1,
-    },
-    {
-        0,  0,  1,  1,
-        0,  0,  1,  1,
-        0,  0,  1,  1,
-        0,  0,  1,  1,
-    },
-    {
-        0,  0,  1,  1,
-        0,  0,  1,  1,
-        2,  2,  3,  3,
-        2,  2,  3,  3,
-    },
-    {
-        0,  1,  2,  3,
-        4,  5,  6,  7,
-        8,  9,  10, 11,
-        12, 13, 14, 15,
-    }
-};
-
-const int vp8_mbsplit_count [VP8_NUMMBSPLITS] = { 2, 2, 4, 16};
-
-const vp8_prob vp8_mbsplit_probs [VP8_NUMMBSPLITS-1] = { 110, 111, 150};
-
-
-/* Array indices are identical to previously-existing INTRAMODECONTEXTNODES. */
-
-const vp8_tree_index vp8_bmode_tree[18] =     /* INTRAMODECONTEXTNODE value */
-{
-    -B_DC_PRED, 2,                             /* 0 = DC_NODE */
-    -B_TM_PRED, 4,                            /* 1 = TM_NODE */
-    -B_VE_PRED, 6,                           /* 2 = VE_NODE */
-    8, 12,                                  /* 3 = COM_NODE */
-    -B_HE_PRED, 10,                        /* 4 = HE_NODE */
-    -B_RD_PRED, -B_VR_PRED,               /* 5 = RD_NODE */
-    -B_LD_PRED, 14,                        /* 6 = LD_NODE */
-    -B_VL_PRED, 16,                      /* 7 = VL_NODE */
-    -B_HD_PRED, -B_HU_PRED             /* 8 = HD_NODE */
-};
-
-/* Again, these trees use the same probability indices as their
-   explicitly-programmed predecessors. */
-
-const vp8_tree_index vp8_ymode_tree[8] =
-{
-    -DC_PRED, 2,
-    4, 6,
-    -V_PRED, -H_PRED,
-    -TM_PRED, -B_PRED
-};
-
-const vp8_tree_index vp8_kf_ymode_tree[8] =
-{
-    -B_PRED, 2,
-    4, 6,
-    -DC_PRED, -V_PRED,
-    -H_PRED, -TM_PRED
-};
-
-const vp8_tree_index vp8_uv_mode_tree[6] =
-{
-    -DC_PRED, 2,
-    -V_PRED, 4,
-    -H_PRED, -TM_PRED
-};
-
-const vp8_tree_index vp8_mbsplit_tree[6] =
-{
-    -3, 2,
-    -2, 4,
-    -0, -1
-};
-
-const vp8_tree_index vp8_mv_ref_tree[8] =
-{
-    -ZEROMV, 2,
-    -NEARESTMV, 4,
-    -NEARMV, 6,
-    -NEWMV, -SPLITMV
-};
-
-const vp8_tree_index vp8_sub_mv_ref_tree[6] =
-{
-    -LEFT4X4, 2,
-    -ABOVE4X4, 4,
-    -ZERO4X4, -NEW4X4
-};
-
-const vp8_tree_index vp8_small_mvtree [14] =
-{
-    2, 8,
-    4, 6,
-    -0, -1,
-    -2, -3,
-    10, 12,
-    -4, -5,
-    -6, -7
-};
-
-void vp8_init_mbmode_probs(VP8_COMMON *x)
-{
-    memcpy(x->fc.ymode_prob, vp8_ymode_prob, sizeof(vp8_ymode_prob));
-    memcpy(x->fc.uv_mode_prob, vp8_uv_mode_prob, sizeof(vp8_uv_mode_prob));
-    memcpy(x->fc.sub_mv_ref_prob, sub_mv_ref_prob, sizeof(sub_mv_ref_prob));
-}
-
-void vp8_default_bmode_probs(vp8_prob p [VP8_BINTRAMODES-1])
-{
-    memcpy(p, vp8_bmode_prob, sizeof(vp8_bmode_prob));
-}
-
diff --git a/vp8/common/entropymode.h b/vp8/common/entropymode.h
deleted file mode 100644 (file)
index 81bdfc4..0000000
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#ifndef VP8_COMMON_ENTROPYMODE_H_
-#define VP8_COMMON_ENTROPYMODE_H_
-
-#include "onyxc_int.h"
-#include "treecoder.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef enum
-{
-    SUBMVREF_NORMAL,
-    SUBMVREF_LEFT_ZED,
-    SUBMVREF_ABOVE_ZED,
-    SUBMVREF_LEFT_ABOVE_SAME,
-    SUBMVREF_LEFT_ABOVE_ZED
-} sumvfref_t;
-
-typedef int vp8_mbsplit[16];
-
-#define VP8_NUMMBSPLITS 4
-
-extern const vp8_mbsplit vp8_mbsplits [VP8_NUMMBSPLITS];
-
-extern const int vp8_mbsplit_count [VP8_NUMMBSPLITS];    /* # of subsets */
-
-extern const vp8_prob vp8_mbsplit_probs [VP8_NUMMBSPLITS-1];
-
-extern int vp8_mv_cont(const int_mv *l, const int_mv *a);
-#define SUBMVREF_COUNT 5
-extern const vp8_prob vp8_sub_mv_ref_prob2 [SUBMVREF_COUNT][VP8_SUBMVREFS-1];
-
-
-extern const unsigned int vp8_kf_default_bmode_counts [VP8_BINTRAMODES] [VP8_BINTRAMODES] [VP8_BINTRAMODES];
-
-
-extern const vp8_tree_index vp8_bmode_tree[];
-
-extern const vp8_tree_index  vp8_ymode_tree[];
-extern const vp8_tree_index  vp8_kf_ymode_tree[];
-extern const vp8_tree_index  vp8_uv_mode_tree[];
-
-extern const vp8_tree_index  vp8_mbsplit_tree[];
-extern const vp8_tree_index  vp8_mv_ref_tree[];
-extern const vp8_tree_index  vp8_sub_mv_ref_tree[];
-
-extern const struct vp8_token_struct vp8_bmode_encodings[VP8_BINTRAMODES];
-extern const struct vp8_token_struct vp8_ymode_encodings[VP8_YMODES];
-extern const struct vp8_token_struct vp8_kf_ymode_encodings[VP8_YMODES];
-extern const struct vp8_token_struct vp8_uv_mode_encodings[VP8_UV_MODES];
-extern const struct vp8_token_struct vp8_mbsplit_encodings[VP8_NUMMBSPLITS];
-
-/* Inter mode values do not start at zero */
-
-extern const struct vp8_token_struct vp8_mv_ref_encoding_array[VP8_MVREFS];
-extern const struct vp8_token_struct vp8_sub_mv_ref_encoding_array[VP8_SUBMVREFS];
-
-extern const vp8_tree_index vp8_small_mvtree[];
-
-extern const struct vp8_token_struct vp8_small_mvencodings[8];
-
-/* Key frame default mode probs */
-extern const vp8_prob vp8_kf_bmode_prob[VP8_BINTRAMODES][VP8_BINTRAMODES]
-[VP8_BINTRAMODES-1];
-extern const vp8_prob vp8_kf_uv_mode_prob[VP8_UV_MODES-1];
-extern const vp8_prob vp8_kf_ymode_prob[VP8_YMODES-1];
-
-void vp8_init_mbmode_probs(VP8_COMMON *x);
-void vp8_default_bmode_probs(vp8_prob dest [VP8_BINTRAMODES-1]);
-void vp8_kf_default_bmode_probs(vp8_prob dest [VP8_BINTRAMODES] [VP8_BINTRAMODES] [VP8_BINTRAMODES-1]);
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP8_COMMON_ENTROPYMODE_H_
diff --git a/vp8/common/entropymv.c b/vp8/common/entropymv.c
deleted file mode 100644 (file)
index e5df1f0..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#include "entropymv.h"
-
-const MV_CONTEXT vp8_mv_update_probs[2] =
-{
-    {{
-        237,
-        246,
-        253, 253, 254, 254, 254, 254, 254,
-        254, 254, 254, 254, 254, 250, 250, 252, 254, 254
-    }},
-    {{
-        231,
-        243,
-        245, 253, 254, 254, 254, 254, 254,
-        254, 254, 254, 254, 254, 251, 251, 254, 254, 254
-    }}
-};
-const MV_CONTEXT vp8_default_mv_context[2] =
-{
-    {{
-        /* row */
-        162,                                        /* is short */
-        128,                                        /* sign */
-        225, 146, 172, 147, 214,  39, 156,          /* short tree */
-        128, 129, 132,  75, 145, 178, 206, 239, 254, 254 /* long bits */
-    }},
-
-
-
-    {{
-        /* same for column */
-        164,                                        /* is short */
-        128,
-        204, 170, 119, 235, 140, 230, 228,
-        128, 130, 130,  74, 148, 180, 203, 236, 254, 254 /* long bits */
-
-    }}
-};
diff --git a/vp8/common/entropymv.h b/vp8/common/entropymv.h
deleted file mode 100644 (file)
index 42840d5..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#ifndef VP8_COMMON_ENTROPYMV_H_
-#define VP8_COMMON_ENTROPYMV_H_
-
-#include "treecoder.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-enum
-{
-    mv_max  = 1023,              /* max absolute value of a MV component */
-    MVvals = (2 * mv_max) + 1,   /* # possible values "" */
-    mvfp_max  = 255,              /* max absolute value of a full pixel MV component */
-    MVfpvals = (2 * mvfp_max) +1, /* # possible full pixel MV values */
-
-    mvlong_width = 10,       /* Large MVs have 9 bit magnitudes */
-    mvnum_short = 8,         /* magnitudes 0 through 7 */
-
-    /* probability offsets for coding each MV component */
-
-    mvpis_short = 0,         /* short (<= 7) vs long (>= 8) */
-    MVPsign,                /* sign for non-zero */
-    MVPshort,               /* 8 short values = 7-position tree */
-
-    MVPbits = MVPshort + mvnum_short - 1, /* mvlong_width long value bits */
-    MVPcount = MVPbits + mvlong_width    /* (with independent probabilities) */
-};
-
-typedef struct mv_context
-{
-    vp8_prob prob[MVPcount];  /* often come in row, col pairs */
-} MV_CONTEXT;
-
-extern const MV_CONTEXT vp8_mv_update_probs[2], vp8_default_mv_context[2];
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP8_COMMON_ENTROPYMV_H_
diff --git a/vp8/common/extend.c b/vp8/common/extend.c
deleted file mode 100644 (file)
index 2d938ad..0000000
+++ /dev/null
@@ -1,188 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#include "extend.h"
-#include "vpx_mem/vpx_mem.h"
-
-
-static void copy_and_extend_plane
-(
-    unsigned char *s, /* source */
-    int sp,           /* source pitch */
-    unsigned char *d, /* destination */
-    int dp,           /* destination pitch */
-    int h,            /* height */
-    int w,            /* width */
-    int et,           /* extend top border */
-    int el,           /* extend left border */
-    int eb,           /* extend bottom border */
-    int er            /* extend right border */
-)
-{
-    int i;
-    unsigned char *src_ptr1, *src_ptr2;
-    unsigned char *dest_ptr1, *dest_ptr2;
-    int linesize;
-
-    /* copy the left and right most columns out */
-    src_ptr1 = s;
-    src_ptr2 = s + w - 1;
-    dest_ptr1 = d - el;
-    dest_ptr2 = d + w;
-
-    for (i = 0; i < h; i++)
-    {
-        memset(dest_ptr1, src_ptr1[0], el);
-        memcpy(dest_ptr1 + el, src_ptr1, w);
-        memset(dest_ptr2, src_ptr2[0], er);
-        src_ptr1  += sp;
-        src_ptr2  += sp;
-        dest_ptr1 += dp;
-        dest_ptr2 += dp;
-    }
-
-    /* Now copy the top and bottom lines into each line of the respective
-     * borders
-     */
-    src_ptr1 = d - el;
-    src_ptr2 = d + dp * (h - 1) - el;
-    dest_ptr1 = d + dp * (-et) - el;
-    dest_ptr2 = d + dp * (h) - el;
-    linesize = el + er + w;
-
-    for (i = 0; i < et; i++)
-    {
-        memcpy(dest_ptr1, src_ptr1, linesize);
-        dest_ptr1 += dp;
-    }
-
-    for (i = 0; i < eb; i++)
-    {
-        memcpy(dest_ptr2, src_ptr2, linesize);
-        dest_ptr2 += dp;
-    }
-}
-
-
-void vp8_copy_and_extend_frame(YV12_BUFFER_CONFIG *src,
-                               YV12_BUFFER_CONFIG *dst)
-{
-    int et = dst->border;
-    int el = dst->border;
-    int eb = dst->border + dst->y_height - src->y_height;
-    int er = dst->border + dst->y_width - src->y_width;
-
-    copy_and_extend_plane(src->y_buffer, src->y_stride,
-                          dst->y_buffer, dst->y_stride,
-                          src->y_height, src->y_width,
-                          et, el, eb, er);
-
-    et = dst->border >> 1;
-    el = dst->border >> 1;
-    eb = (dst->border >> 1) + dst->uv_height - src->uv_height;
-    er = (dst->border >> 1) + dst->uv_width - src->uv_width;
-
-    copy_and_extend_plane(src->u_buffer, src->uv_stride,
-                          dst->u_buffer, dst->uv_stride,
-                          src->uv_height, src->uv_width,
-                          et, el, eb, er);
-
-    copy_and_extend_plane(src->v_buffer, src->uv_stride,
-                          dst->v_buffer, dst->uv_stride,
-                          src->uv_height, src->uv_width,
-                          et, el, eb, er);
-}
-
-
-void vp8_copy_and_extend_frame_with_rect(YV12_BUFFER_CONFIG *src,
-                                         YV12_BUFFER_CONFIG *dst,
-                                         int srcy, int srcx,
-                                         int srch, int srcw)
-{
-    int et = dst->border;
-    int el = dst->border;
-    int eb = dst->border + dst->y_height - src->y_height;
-    int er = dst->border + dst->y_width - src->y_width;
-    int src_y_offset = srcy * src->y_stride + srcx;
-    int dst_y_offset = srcy * dst->y_stride + srcx;
-    int src_uv_offset = ((srcy * src->uv_stride) >> 1) + (srcx >> 1);
-    int dst_uv_offset = ((srcy * dst->uv_stride) >> 1) + (srcx >> 1);
-
-    /* If the side is not touching the bounder then don't extend. */
-    if (srcy)
-      et = 0;
-    if (srcx)
-      el = 0;
-    if (srcy + srch != src->y_height)
-      eb = 0;
-    if (srcx + srcw != src->y_width)
-      er = 0;
-
-    copy_and_extend_plane(src->y_buffer + src_y_offset,
-                          src->y_stride,
-                          dst->y_buffer + dst_y_offset,
-                          dst->y_stride,
-                          srch, srcw,
-                          et, el, eb, er);
-
-    et = (et + 1) >> 1;
-    el = (el + 1) >> 1;
-    eb = (eb + 1) >> 1;
-    er = (er + 1) >> 1;
-    srch = (srch + 1) >> 1;
-    srcw = (srcw + 1) >> 1;
-
-    copy_and_extend_plane(src->u_buffer + src_uv_offset,
-                          src->uv_stride,
-                          dst->u_buffer + dst_uv_offset,
-                          dst->uv_stride,
-                          srch, srcw,
-                          et, el, eb, er);
-
-    copy_and_extend_plane(src->v_buffer + src_uv_offset,
-                          src->uv_stride,
-                          dst->v_buffer + dst_uv_offset,
-                          dst->uv_stride,
-                          srch, srcw,
-                          et, el, eb, er);
-}
-
-
-/* note the extension is only for the last row, for intra prediction purpose */
-void vp8_extend_mb_row(YV12_BUFFER_CONFIG *ybf,
-                       unsigned char *YPtr,
-                       unsigned char *UPtr,
-                       unsigned char *VPtr)
-{
-    int i;
-
-    YPtr += ybf->y_stride * 14;
-    UPtr += ybf->uv_stride * 6;
-    VPtr += ybf->uv_stride * 6;
-
-    for (i = 0; i < 4; i++)
-    {
-        YPtr[i] = YPtr[-1];
-        UPtr[i] = UPtr[-1];
-        VPtr[i] = VPtr[-1];
-    }
-
-    YPtr += ybf->y_stride;
-    UPtr += ybf->uv_stride;
-    VPtr += ybf->uv_stride;
-
-    for (i = 0; i < 4; i++)
-    {
-        YPtr[i] = YPtr[-1];
-        UPtr[i] = UPtr[-1];
-        VPtr[i] = VPtr[-1];
-    }
-}
diff --git a/vp8/common/extend.h b/vp8/common/extend.h
deleted file mode 100644 (file)
index 068f4ac..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#ifndef VP8_COMMON_EXTEND_H_
-#define VP8_COMMON_EXTEND_H_
-
-#include "vpx_scale/yv12config.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-void vp8_extend_mb_row(YV12_BUFFER_CONFIG *ybf, unsigned char *YPtr, unsigned char *UPtr, unsigned char *VPtr);
-void vp8_copy_and_extend_frame(YV12_BUFFER_CONFIG *src,
-                               YV12_BUFFER_CONFIG *dst);
-void vp8_copy_and_extend_frame_with_rect(YV12_BUFFER_CONFIG *src,
-                                         YV12_BUFFER_CONFIG *dst,
-                                         int srcy, int srcx,
-                                         int srch, int srcw);
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP8_COMMON_EXTEND_H_
diff --git a/vp8/common/filter.c b/vp8/common/filter.c
deleted file mode 100644 (file)
index 84c608e..0000000
+++ /dev/null
@@ -1,493 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#include "filter.h"
-#include "./vp8_rtcd.h"
-
-DECLARE_ALIGNED(16, const short, vp8_bilinear_filters[8][2]) =
-{
-    { 128,   0 },
-    { 112,  16 },
-    {  96,  32 },
-    {  80,  48 },
-    {  64,  64 },
-    {  48,  80 },
-    {  32,  96 },
-    {  16, 112 }
-};
-
-DECLARE_ALIGNED(16, const short, vp8_sub_pel_filters[8][6]) =
-{
-
-    { 0,  0,  128,    0,   0,  0 },         /* note that 1/8 pel positions are just as per alpha -0.5 bicubic */
-    { 0, -6,  123,   12,  -1,  0 },
-    { 2, -11, 108,   36,  -8,  1 },         /* New 1/4 pel 6 tap filter */
-    { 0, -9,   93,   50,  -6,  0 },
-    { 3, -16,  77,   77, -16,  3 },         /* New 1/2 pel 6 tap filter */
-    { 0, -6,   50,   93,  -9,  0 },
-    { 1, -8,   36,  108, -11,  2 },         /* New 1/4 pel 6 tap filter */
-    { 0, -1,   12,  123,  -6,  0 },
-};
-
-static void filter_block2d_first_pass
-(
-    unsigned char *src_ptr,
-    int *output_ptr,
-    unsigned int src_pixels_per_line,
-    unsigned int pixel_step,
-    unsigned int output_height,
-    unsigned int output_width,
-    const short *vp8_filter
-)
-{
-    unsigned int i, j;
-    int  Temp;
-
-    for (i = 0; i < output_height; i++)
-    {
-        for (j = 0; j < output_width; j++)
-        {
-            Temp = ((int)src_ptr[-2 * (int)pixel_step] * vp8_filter[0]) +
-                   ((int)src_ptr[-1 * (int)pixel_step] * vp8_filter[1]) +
-                   ((int)src_ptr[0]                 * vp8_filter[2]) +
-                   ((int)src_ptr[pixel_step]         * vp8_filter[3]) +
-                   ((int)src_ptr[2*pixel_step]       * vp8_filter[4]) +
-                   ((int)src_ptr[3*pixel_step]       * vp8_filter[5]) +
-                   (VP8_FILTER_WEIGHT >> 1);      /* Rounding */
-
-            /* Normalize back to 0-255 */
-            Temp = Temp >> VP8_FILTER_SHIFT;
-
-            if (Temp < 0)
-                Temp = 0;
-            else if (Temp > 255)
-                Temp = 255;
-
-            output_ptr[j] = Temp;
-            src_ptr++;
-        }
-
-        /* Next row... */
-        src_ptr    += src_pixels_per_line - output_width;
-        output_ptr += output_width;
-    }
-}
-
-static void filter_block2d_second_pass
-(
-    int *src_ptr,
-    unsigned char *output_ptr,
-    int output_pitch,
-    unsigned int src_pixels_per_line,
-    unsigned int pixel_step,
-    unsigned int output_height,
-    unsigned int output_width,
-    const short *vp8_filter
-)
-{
-    unsigned int i, j;
-    int  Temp;
-
-    for (i = 0; i < output_height; i++)
-    {
-        for (j = 0; j < output_width; j++)
-        {
-            /* Apply filter */
-            Temp = ((int)src_ptr[-2 * (int)pixel_step] * vp8_filter[0]) +
-                   ((int)src_ptr[-1 * (int)pixel_step] * vp8_filter[1]) +
-                   ((int)src_ptr[0]                 * vp8_filter[2]) +
-                   ((int)src_ptr[pixel_step]         * vp8_filter[3]) +
-                   ((int)src_ptr[2*pixel_step]       * vp8_filter[4]) +
-                   ((int)src_ptr[3*pixel_step]       * vp8_filter[5]) +
-                   (VP8_FILTER_WEIGHT >> 1);   /* Rounding */
-
-            /* Normalize back to 0-255 */
-            Temp = Temp >> VP8_FILTER_SHIFT;
-
-            if (Temp < 0)
-                Temp = 0;
-            else if (Temp > 255)
-                Temp = 255;
-
-            output_ptr[j] = (unsigned char)Temp;
-            src_ptr++;
-        }
-
-        /* Start next row */
-        src_ptr    += src_pixels_per_line - output_width;
-        output_ptr += output_pitch;
-    }
-}
-
-
-static void filter_block2d
-(
-    unsigned char  *src_ptr,
-    unsigned char  *output_ptr,
-    unsigned int src_pixels_per_line,
-    int output_pitch,
-    const short  *HFilter,
-    const short  *VFilter
-)
-{
-    int FData[9*4]; /* Temp data buffer used in filtering */
-
-    /* First filter 1-D horizontally... */
-    filter_block2d_first_pass(src_ptr - (2 * src_pixels_per_line), FData, src_pixels_per_line, 1, 9, 4, HFilter);
-
-    /* then filter verticaly... */
-    filter_block2d_second_pass(FData + 8, output_ptr, output_pitch, 4, 4, 4, 4, VFilter);
-}
-
-
-void vp8_sixtap_predict4x4_c
-(
-    unsigned char  *src_ptr,
-    int   src_pixels_per_line,
-    int  xoffset,
-    int  yoffset,
-    unsigned char *dst_ptr,
-    int dst_pitch
-)
-{
-    const short  *HFilter;
-    const short  *VFilter;
-
-    HFilter = vp8_sub_pel_filters[xoffset];   /* 6 tap */
-    VFilter = vp8_sub_pel_filters[yoffset];   /* 6 tap */
-
-    filter_block2d(src_ptr, dst_ptr, src_pixels_per_line, dst_pitch, HFilter, VFilter);
-}
-void vp8_sixtap_predict8x8_c
-(
-    unsigned char  *src_ptr,
-    int  src_pixels_per_line,
-    int  xoffset,
-    int  yoffset,
-    unsigned char *dst_ptr,
-    int  dst_pitch
-)
-{
-    const short  *HFilter;
-    const short  *VFilter;
-    int FData[13*16];   /* Temp data buffer used in filtering */
-
-    HFilter = vp8_sub_pel_filters[xoffset];   /* 6 tap */
-    VFilter = vp8_sub_pel_filters[yoffset];   /* 6 tap */
-
-    /* First filter 1-D horizontally... */
-    filter_block2d_first_pass(src_ptr - (2 * src_pixels_per_line), FData, src_pixels_per_line, 1, 13, 8, HFilter);
-
-
-    /* then filter verticaly... */
-    filter_block2d_second_pass(FData + 16, dst_ptr, dst_pitch, 8, 8, 8, 8, VFilter);
-
-}
-
-void vp8_sixtap_predict8x4_c
-(
-    unsigned char  *src_ptr,
-    int  src_pixels_per_line,
-    int  xoffset,
-    int  yoffset,
-    unsigned char *dst_ptr,
-    int  dst_pitch
-)
-{
-    const short  *HFilter;
-    const short  *VFilter;
-    int FData[13*16];   /* Temp data buffer used in filtering */
-
-    HFilter = vp8_sub_pel_filters[xoffset];   /* 6 tap */
-    VFilter = vp8_sub_pel_filters[yoffset];   /* 6 tap */
-
-    /* First filter 1-D horizontally... */
-    filter_block2d_first_pass(src_ptr - (2 * src_pixels_per_line), FData, src_pixels_per_line, 1, 9, 8, HFilter);
-
-
-    /* then filter verticaly... */
-    filter_block2d_second_pass(FData + 16, dst_ptr, dst_pitch, 8, 8, 4, 8, VFilter);
-
-}
-
-void vp8_sixtap_predict16x16_c
-(
-    unsigned char  *src_ptr,
-    int  src_pixels_per_line,
-    int  xoffset,
-    int  yoffset,
-    unsigned char *dst_ptr,
-    int  dst_pitch
-)
-{
-    const short  *HFilter;
-    const short  *VFilter;
-    int FData[21*24];   /* Temp data buffer used in filtering */
-
-
-    HFilter = vp8_sub_pel_filters[xoffset];   /* 6 tap */
-    VFilter = vp8_sub_pel_filters[yoffset];   /* 6 tap */
-
-    /* First filter 1-D horizontally... */
-    filter_block2d_first_pass(src_ptr - (2 * src_pixels_per_line), FData, src_pixels_per_line, 1, 21, 16, HFilter);
-
-    /* then filter verticaly... */
-    filter_block2d_second_pass(FData + 32, dst_ptr, dst_pitch, 16, 16, 16, 16, VFilter);
-
-}
-
-
-/****************************************************************************
- *
- *  ROUTINE       : filter_block2d_bil_first_pass
- *
- *  INPUTS        : UINT8  *src_ptr    : Pointer to source block.
- *                  UINT32  src_stride : Stride of source block.
- *                  UINT32  height     : Block height.
- *                  UINT32  width      : Block width.
- *                  INT32  *vp8_filter : Array of 2 bi-linear filter taps.
- *
- *  OUTPUTS       : INT32  *dst_ptr    : Pointer to filtered block.
- *
- *  RETURNS       : void
- *
- *  FUNCTION      : Applies a 1-D 2-tap bi-linear filter to the source block
- *                  in the horizontal direction to produce the filtered output
- *                  block. Used to implement first-pass of 2-D separable filter.
- *
- *  SPECIAL NOTES : Produces INT32 output to retain precision for next pass.
- *                  Two filter taps should sum to VP8_FILTER_WEIGHT.
- *
- ****************************************************************************/
-static void filter_block2d_bil_first_pass
-(
-    unsigned char  *src_ptr,
-    unsigned short *dst_ptr,
-    unsigned int    src_stride,
-    unsigned int    height,
-    unsigned int    width,
-    const short    *vp8_filter
-)
-{
-    unsigned int i, j;
-
-    for (i = 0; i < height; i++)
-    {
-        for (j = 0; j < width; j++)
-        {
-            /* Apply bilinear filter */
-            dst_ptr[j] = (((int)src_ptr[0] * vp8_filter[0]) +
-                          ((int)src_ptr[1] * vp8_filter[1]) +
-                          (VP8_FILTER_WEIGHT / 2)) >> VP8_FILTER_SHIFT;
-            src_ptr++;
-        }
-
-        /* Next row... */
-        src_ptr += src_stride - width;
-        dst_ptr += width;
-    }
-}
-
-/****************************************************************************
- *
- *  ROUTINE       : filter_block2d_bil_second_pass
- *
- *  INPUTS        : INT32  *src_ptr    : Pointer to source block.
- *                  UINT32  dst_pitch  : Destination block pitch.
- *                  UINT32  height     : Block height.
- *                  UINT32  width      : Block width.
- *                  INT32  *vp8_filter : Array of 2 bi-linear filter taps.
- *
- *  OUTPUTS       : UINT16 *dst_ptr    : Pointer to filtered block.
- *
- *  RETURNS       : void
- *
- *  FUNCTION      : Applies a 1-D 2-tap bi-linear filter to the source block
- *                  in the vertical direction to produce the filtered output
- *                  block. Used to implement second-pass of 2-D separable filter.
- *
- *  SPECIAL NOTES : Requires 32-bit input as produced by filter_block2d_bil_first_pass.
- *                  Two filter taps should sum to VP8_FILTER_WEIGHT.
- *
- ****************************************************************************/
-static void filter_block2d_bil_second_pass
-(
-    unsigned short *src_ptr,
-    unsigned char  *dst_ptr,
-    int             dst_pitch,
-    unsigned int    height,
-    unsigned int    width,
-    const short    *vp8_filter
-)
-{
-    unsigned int  i, j;
-    int  Temp;
-
-    for (i = 0; i < height; i++)
-    {
-        for (j = 0; j < width; j++)
-        {
-            /* Apply filter */
-            Temp = ((int)src_ptr[0]     * vp8_filter[0]) +
-                   ((int)src_ptr[width] * vp8_filter[1]) +
-                   (VP8_FILTER_WEIGHT / 2);
-            dst_ptr[j] = (unsigned int)(Temp >> VP8_FILTER_SHIFT);
-            src_ptr++;
-        }
-
-        /* Next row... */
-        dst_ptr += dst_pitch;
-    }
-}
-
-
-/****************************************************************************
- *
- *  ROUTINE       : filter_block2d_bil
- *
- *  INPUTS        : UINT8  *src_ptr          : Pointer to source block.
- *                  UINT32  src_pitch        : Stride of source block.
- *                  UINT32  dst_pitch        : Stride of destination block.
- *                  INT32  *HFilter          : Array of 2 horizontal filter taps.
- *                  INT32  *VFilter          : Array of 2 vertical filter taps.
- *                  INT32  Width             : Block width
- *                  INT32  Height            : Block height
- *
- *  OUTPUTS       : UINT16 *dst_ptr       : Pointer to filtered block.
- *
- *  RETURNS       : void
- *
- *  FUNCTION      : 2-D filters an input block by applying a 2-tap
- *                  bi-linear filter horizontally followed by a 2-tap
- *                  bi-linear filter vertically on the result.
- *
- *  SPECIAL NOTES : The largest block size can be handled here is 16x16
- *
- ****************************************************************************/
-static void filter_block2d_bil
-(
-    unsigned char *src_ptr,
-    unsigned char *dst_ptr,
-    unsigned int   src_pitch,
-    unsigned int   dst_pitch,
-    const short   *HFilter,
-    const short   *VFilter,
-    int            Width,
-    int            Height
-)
-{
-
-    unsigned short FData[17*16];    /* Temp data buffer used in filtering */
-
-    /* First filter 1-D horizontally... */
-    filter_block2d_bil_first_pass(src_ptr, FData, src_pitch, Height + 1, Width, HFilter);
-
-    /* then 1-D vertically... */
-    filter_block2d_bil_second_pass(FData, dst_ptr, dst_pitch, Height, Width, VFilter);
-}
-
-
-void vp8_bilinear_predict4x4_c
-(
-    unsigned char  *src_ptr,
-    int   src_pixels_per_line,
-    int  xoffset,
-    int  yoffset,
-    unsigned char *dst_ptr,
-    int dst_pitch
-)
-{
-    const short *HFilter;
-    const short *VFilter;
-
-    HFilter = vp8_bilinear_filters[xoffset];
-    VFilter = vp8_bilinear_filters[yoffset];
-#if 0
-    {
-        int i;
-        unsigned char temp1[16];
-        unsigned char temp2[16];
-
-        bilinear_predict4x4_mmx(src_ptr, src_pixels_per_line, xoffset, yoffset, temp1, 4);
-        filter_block2d_bil(src_ptr, temp2, src_pixels_per_line, 4, HFilter, VFilter, 4, 4);
-
-        for (i = 0; i < 16; i++)
-        {
-            if (temp1[i] != temp2[i])
-            {
-                bilinear_predict4x4_mmx(src_ptr, src_pixels_per_line, xoffset, yoffset, temp1, 4);
-                filter_block2d_bil(src_ptr, temp2, src_pixels_per_line, 4, HFilter, VFilter, 4, 4);
-            }
-        }
-    }
-#endif
-    filter_block2d_bil(src_ptr, dst_ptr, src_pixels_per_line, dst_pitch, HFilter, VFilter, 4, 4);
-
-}
-
-void vp8_bilinear_predict8x8_c
-(
-    unsigned char  *src_ptr,
-    int  src_pixels_per_line,
-    int  xoffset,
-    int  yoffset,
-    unsigned char *dst_ptr,
-    int  dst_pitch
-)
-{
-    const short *HFilter;
-    const short *VFilter;
-
-    HFilter = vp8_bilinear_filters[xoffset];
-    VFilter = vp8_bilinear_filters[yoffset];
-
-    filter_block2d_bil(src_ptr, dst_ptr, src_pixels_per_line, dst_pitch, HFilter, VFilter, 8, 8);
-
-}
-
-void vp8_bilinear_predict8x4_c
-(
-    unsigned char  *src_ptr,
-    int  src_pixels_per_line,
-    int  xoffset,
-    int  yoffset,
-    unsigned char *dst_ptr,
-    int  dst_pitch
-)
-{
-    const short *HFilter;
-    const short *VFilter;
-
-    HFilter = vp8_bilinear_filters[xoffset];
-    VFilter = vp8_bilinear_filters[yoffset];
-
-    filter_block2d_bil(src_ptr, dst_ptr, src_pixels_per_line, dst_pitch, HFilter, VFilter, 8, 4);
-
-}
-
-void vp8_bilinear_predict16x16_c
-(
-    unsigned char  *src_ptr,
-    int  src_pixels_per_line,
-    int  xoffset,
-    int  yoffset,
-    unsigned char *dst_ptr,
-    int  dst_pitch
-)
-{
-    const short *HFilter;
-    const short *VFilter;
-
-    HFilter = vp8_bilinear_filters[xoffset];
-    VFilter = vp8_bilinear_filters[yoffset];
-
-    filter_block2d_bil(src_ptr, dst_ptr, src_pixels_per_line, dst_pitch, HFilter, VFilter, 16, 16);
-}
diff --git a/vp8/common/filter.h b/vp8/common/filter.h
deleted file mode 100644 (file)
index cfba775..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- *  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.
- */
-
-
-#ifndef VP8_COMMON_FILTER_H_
-#define VP8_COMMON_FILTER_H_
-
-#include "vpx_ports/mem.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define BLOCK_HEIGHT_WIDTH 4
-#define VP8_FILTER_WEIGHT 128
-#define VP8_FILTER_SHIFT  7
-
-extern DECLARE_ALIGNED(16, const short, vp8_bilinear_filters[8][2]);
-extern DECLARE_ALIGNED(16, const short, vp8_sub_pel_filters[8][6]);
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP8_COMMON_FILTER_H_
diff --git a/vp8/common/findnearmv.c b/vp8/common/findnearmv.c
deleted file mode 100644 (file)
index e8ee40f..0000000
+++ /dev/null
@@ -1,193 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#include "findnearmv.h"
-
-const unsigned char vp8_mbsplit_offset[4][16] = {
-    { 0,  8,  0,  0,  0,  0,  0,  0,  0,  0,   0,  0,  0,  0,  0,  0},
-    { 0,  2,  0,  0,  0,  0,  0,  0,  0,  0,   0,  0,  0,  0,  0,  0},
-    { 0,  2,  8, 10,  0,  0,  0,  0,  0,  0,   0,  0,  0,  0,  0,  0},
-    { 0,  1,  2,  3,  4,  5,  6,  7,  8,  9,  10, 11, 12, 13, 14, 15}
-};
-
-/* Predict motion vectors using those from already-decoded nearby blocks.
-   Note that we only consider one 4x4 subblock from each candidate 16x16
-   macroblock.   */
-void vp8_find_near_mvs
-(
-    MACROBLOCKD *xd,
-    const MODE_INFO *here,
-    int_mv *nearest,
-    int_mv *nearby,
-    int_mv *best_mv,
-    int cnt[4],
-    int refframe,
-    int *ref_frame_sign_bias
-)
-{
-    const MODE_INFO *above = here - xd->mode_info_stride;
-    const MODE_INFO *left = here - 1;
-    const MODE_INFO *aboveleft = above - 1;
-    int_mv            near_mvs[4];
-    int_mv           *mv = near_mvs;
-    int             *cntx = cnt;
-    enum {CNT_INTRA, CNT_NEAREST, CNT_NEAR, CNT_SPLITMV};
-
-    /* Zero accumulators */
-    mv[0].as_int = mv[1].as_int = mv[2].as_int = 0;
-    cnt[0] = cnt[1] = cnt[2] = cnt[3] = 0;
-
-    /* Process above */
-    if (above->mbmi.ref_frame != INTRA_FRAME)
-    {
-        if (above->mbmi.mv.as_int)
-        {
-            (++mv)->as_int = above->mbmi.mv.as_int;
-            mv_bias(ref_frame_sign_bias[above->mbmi.ref_frame], refframe, mv, ref_frame_sign_bias);
-            ++cntx;
-        }
-
-        *cntx += 2;
-    }
-
-    /* Process left */
-    if (left->mbmi.ref_frame != INTRA_FRAME)
-    {
-        if (left->mbmi.mv.as_int)
-        {
-            int_mv this_mv;
-
-            this_mv.as_int = left->mbmi.mv.as_int;
-            mv_bias(ref_frame_sign_bias[left->mbmi.ref_frame], refframe, &this_mv, ref_frame_sign_bias);
-
-            if (this_mv.as_int != mv->as_int)
-            {
-                (++mv)->as_int = this_mv.as_int;
-                ++cntx;
-            }
-
-            *cntx += 2;
-        }
-        else
-            cnt[CNT_INTRA] += 2;
-    }
-
-    /* Process above left */
-    if (aboveleft->mbmi.ref_frame != INTRA_FRAME)
-    {
-        if (aboveleft->mbmi.mv.as_int)
-        {
-            int_mv this_mv;
-
-            this_mv.as_int = aboveleft->mbmi.mv.as_int;
-            mv_bias(ref_frame_sign_bias[aboveleft->mbmi.ref_frame], refframe, &this_mv, ref_frame_sign_bias);
-
-            if (this_mv.as_int != mv->as_int)
-            {
-                (++mv)->as_int = this_mv.as_int;
-                ++cntx;
-            }
-
-            *cntx += 1;
-        }
-        else
-            cnt[CNT_INTRA] += 1;
-    }
-
-    /* If we have three distinct MV's ... */
-    if (cnt[CNT_SPLITMV])
-    {
-        /* See if above-left MV can be merged with NEAREST */
-        if (mv->as_int == near_mvs[CNT_NEAREST].as_int)
-            cnt[CNT_NEAREST] += 1;
-    }
-
-    cnt[CNT_SPLITMV] = ((above->mbmi.mode == SPLITMV)
-                        + (left->mbmi.mode == SPLITMV)) * 2
-                       + (aboveleft->mbmi.mode == SPLITMV);
-
-    /* Swap near and nearest if necessary */
-    if (cnt[CNT_NEAR] > cnt[CNT_NEAREST])
-    {
-        int tmp;
-        tmp = cnt[CNT_NEAREST];
-        cnt[CNT_NEAREST] = cnt[CNT_NEAR];
-        cnt[CNT_NEAR] = tmp;
-        tmp = near_mvs[CNT_NEAREST].as_int;
-        near_mvs[CNT_NEAREST].as_int = near_mvs[CNT_NEAR].as_int;
-        near_mvs[CNT_NEAR].as_int = tmp;
-    }
-
-    /* Use near_mvs[0] to store the "best" MV */
-    if (cnt[CNT_NEAREST] >= cnt[CNT_INTRA])
-        near_mvs[CNT_INTRA] = near_mvs[CNT_NEAREST];
-
-    /* Set up return values */
-    best_mv->as_int = near_mvs[0].as_int;
-    nearest->as_int = near_mvs[CNT_NEAREST].as_int;
-    nearby->as_int = near_mvs[CNT_NEAR].as_int;
-}
-
-
-static void invert_and_clamp_mvs(int_mv *inv, int_mv *src, MACROBLOCKD *xd)
-{
-    inv->as_mv.row = src->as_mv.row * -1;
-    inv->as_mv.col = src->as_mv.col * -1;
-    vp8_clamp_mv2(inv, xd);
-    vp8_clamp_mv2(src, xd);
-}
-
-
-int vp8_find_near_mvs_bias
-(
-    MACROBLOCKD *xd,
-    const MODE_INFO *here,
-    int_mv mode_mv_sb[2][MB_MODE_COUNT],
-    int_mv best_mv_sb[2],
-    int cnt[4],
-    int refframe,
-    int *ref_frame_sign_bias
-)
-{
-    int sign_bias = ref_frame_sign_bias[refframe];
-
-    vp8_find_near_mvs(xd,
-                      here,
-                      &mode_mv_sb[sign_bias][NEARESTMV],
-                      &mode_mv_sb[sign_bias][NEARMV],
-                      &best_mv_sb[sign_bias],
-                      cnt,
-                      refframe,
-                      ref_frame_sign_bias);
-
-    invert_and_clamp_mvs(&mode_mv_sb[!sign_bias][NEARESTMV],
-                         &mode_mv_sb[sign_bias][NEARESTMV], xd);
-    invert_and_clamp_mvs(&mode_mv_sb[!sign_bias][NEARMV],
-                         &mode_mv_sb[sign_bias][NEARMV], xd);
-    invert_and_clamp_mvs(&best_mv_sb[!sign_bias],
-                         &best_mv_sb[sign_bias], xd);
-
-    return sign_bias;
-}
-
-
-vp8_prob *vp8_mv_ref_probs(
-    vp8_prob p[VP8_MVREFS-1], const int near_mv_ref_ct[4]
-)
-{
-    p[0] = vp8_mode_contexts [near_mv_ref_ct[0]] [0];
-    p[1] = vp8_mode_contexts [near_mv_ref_ct[1]] [1];
-    p[2] = vp8_mode_contexts [near_mv_ref_ct[2]] [2];
-    p[3] = vp8_mode_contexts [near_mv_ref_ct[3]] [3];
-    /*p[3] = vp8_mode_contexts [near_mv_ref_ct[1] + near_mv_ref_ct[2] + near_mv_ref_ct[3]] [3];*/
-    return p;
-}
-
diff --git a/vp8/common/findnearmv.h b/vp8/common/findnearmv.h
deleted file mode 100644 (file)
index 472a7b5..0000000
+++ /dev/null
@@ -1,195 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#ifndef VP8_COMMON_FINDNEARMV_H_
-#define VP8_COMMON_FINDNEARMV_H_
-
-#include "./vpx_config.h"
-#include "mv.h"
-#include "blockd.h"
-#include "modecont.h"
-#include "treecoder.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-static INLINE void mv_bias(int refmb_ref_frame_sign_bias, int refframe,
-                           int_mv *mvp, const int *ref_frame_sign_bias)
-{
-    if (refmb_ref_frame_sign_bias != ref_frame_sign_bias[refframe])
-    {
-        mvp->as_mv.row *= -1;
-        mvp->as_mv.col *= -1;
-    }
-}
-
-#define LEFT_TOP_MARGIN (16 << 3)
-#define RIGHT_BOTTOM_MARGIN (16 << 3)
-static INLINE void vp8_clamp_mv2(int_mv *mv, const MACROBLOCKD *xd)
-{
-    if (mv->as_mv.col < (xd->mb_to_left_edge - LEFT_TOP_MARGIN))
-        mv->as_mv.col = xd->mb_to_left_edge - LEFT_TOP_MARGIN;
-    else if (mv->as_mv.col > xd->mb_to_right_edge + RIGHT_BOTTOM_MARGIN)
-        mv->as_mv.col = xd->mb_to_right_edge + RIGHT_BOTTOM_MARGIN;
-
-    if (mv->as_mv.row < (xd->mb_to_top_edge - LEFT_TOP_MARGIN))
-        mv->as_mv.row = xd->mb_to_top_edge - LEFT_TOP_MARGIN;
-    else if (mv->as_mv.row > xd->mb_to_bottom_edge + RIGHT_BOTTOM_MARGIN)
-        mv->as_mv.row = xd->mb_to_bottom_edge + RIGHT_BOTTOM_MARGIN;
-}
-
-static INLINE void vp8_clamp_mv(int_mv *mv, int mb_to_left_edge,
-                                int mb_to_right_edge, int mb_to_top_edge,
-                                int mb_to_bottom_edge)
-{
-    mv->as_mv.col = (mv->as_mv.col < mb_to_left_edge) ?
-        mb_to_left_edge : mv->as_mv.col;
-    mv->as_mv.col = (mv->as_mv.col > mb_to_right_edge) ?
-        mb_to_right_edge : mv->as_mv.col;
-    mv->as_mv.row = (mv->as_mv.row < mb_to_top_edge) ?
-        mb_to_top_edge : mv->as_mv.row;
-    mv->as_mv.row = (mv->as_mv.row > mb_to_bottom_edge) ?
-        mb_to_bottom_edge : mv->as_mv.row;
-}
-static INLINE unsigned int vp8_check_mv_bounds(int_mv *mv, int mb_to_left_edge,
-                                               int mb_to_right_edge,
-                                               int mb_to_top_edge,
-                                               int mb_to_bottom_edge)
-{
-    unsigned int need_to_clamp;
-    need_to_clamp = (mv->as_mv.col < mb_to_left_edge);
-    need_to_clamp |= (mv->as_mv.col > mb_to_right_edge);
-    need_to_clamp |= (mv->as_mv.row < mb_to_top_edge);
-    need_to_clamp |= (mv->as_mv.row > mb_to_bottom_edge);
-    return need_to_clamp;
-}
-
-void vp8_find_near_mvs
-(
-    MACROBLOCKD *xd,
-    const MODE_INFO *here,
-    int_mv *nearest, int_mv *nearby, int_mv *best,
-    int near_mv_ref_cts[4],
-    int refframe,
-    int *ref_frame_sign_bias
-);
-
-
-int vp8_find_near_mvs_bias
-(
-    MACROBLOCKD *xd,
-    const MODE_INFO *here,
-    int_mv mode_mv_sb[2][MB_MODE_COUNT],
-    int_mv best_mv_sb[2],
-    int cnt[4],
-    int refframe,
-    int *ref_frame_sign_bias
-);
-
-
-vp8_prob *vp8_mv_ref_probs(
-    vp8_prob p[VP8_MVREFS-1], const int near_mv_ref_ct[4]
-);
-
-extern const unsigned char vp8_mbsplit_offset[4][16];
-
-
-static INLINE uint32_t left_block_mv(const MODE_INFO *cur_mb, int b)
-{
-    if (!(b & 3))
-    {
-        /* On L edge, get from MB to left of us */
-        --cur_mb;
-
-        if(cur_mb->mbmi.mode != SPLITMV)
-            return cur_mb->mbmi.mv.as_int;
-        b += 4;
-    }
-
-    return (cur_mb->bmi + b - 1)->mv.as_int;
-}
-
-static INLINE uint32_t above_block_mv(const MODE_INFO *cur_mb, int b,
-                                      int mi_stride)
-{
-    if (!(b >> 2))
-    {
-        /* On top edge, get from MB above us */
-        cur_mb -= mi_stride;
-
-        if(cur_mb->mbmi.mode != SPLITMV)
-            return cur_mb->mbmi.mv.as_int;
-        b += 16;
-    }
-
-    return (cur_mb->bmi + (b - 4))->mv.as_int;
-}
-static INLINE B_PREDICTION_MODE left_block_mode(const MODE_INFO *cur_mb, int b)
-{
-    if (!(b & 3))
-    {
-        /* On L edge, get from MB to left of us */
-        --cur_mb;
-        switch (cur_mb->mbmi.mode)
-        {
-            case B_PRED:
-              return (cur_mb->bmi + b + 3)->as_mode;
-            case DC_PRED:
-                return B_DC_PRED;
-            case V_PRED:
-                return B_VE_PRED;
-            case H_PRED:
-                return B_HE_PRED;
-            case TM_PRED:
-                return B_TM_PRED;
-            default:
-                return B_DC_PRED;
-        }
-    }
-
-    return (cur_mb->bmi + b - 1)->as_mode;
-}
-
-static INLINE B_PREDICTION_MODE above_block_mode(const MODE_INFO *cur_mb, int b,
-                                                 int mi_stride)
-{
-    if (!(b >> 2))
-    {
-        /* On top edge, get from MB above us */
-        cur_mb -= mi_stride;
-
-        switch (cur_mb->mbmi.mode)
-        {
-            case B_PRED:
-              return (cur_mb->bmi + b + 12)->as_mode;
-            case DC_PRED:
-                return B_DC_PRED;
-            case V_PRED:
-                return B_VE_PRED;
-            case H_PRED:
-                return B_HE_PRED;
-            case TM_PRED:
-                return B_TM_PRED;
-            default:
-                return B_DC_PRED;
-        }
-    }
-
-    return (cur_mb->bmi + b - 4)->as_mode;
-}
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP8_COMMON_FINDNEARMV_H_
diff --git a/vp8/common/generic/systemdependent.c b/vp8/common/generic/systemdependent.c
deleted file mode 100644 (file)
index 28dc262..0000000
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#include "vpx_config.h"
-#include "vp8_rtcd.h"
-#if ARCH_ARM
-#include "vpx_ports/arm.h"
-#elif ARCH_X86 || ARCH_X86_64
-#include "vpx_ports/x86.h"
-#endif
-#include "vp8/common/onyxc_int.h"
-#include "vp8/common/systemdependent.h"
-
-#if CONFIG_MULTITHREAD
-#if HAVE_UNISTD_H && !defined(__OS2__)
-#include <unistd.h>
-#elif defined(_WIN32)
-#include <windows.h>
-typedef void (WINAPI *PGNSI)(LPSYSTEM_INFO);
-#elif defined(__OS2__)
-#define INCL_DOS
-#define INCL_DOSSPINLOCK
-#include <os2.h>
-#endif
-#endif
-
-#if CONFIG_MULTITHREAD
-static int get_cpu_count()
-{
-    int core_count = 16;
-
-#if HAVE_UNISTD_H && !defined(__OS2__)
-#if defined(_SC_NPROCESSORS_ONLN)
-    core_count = sysconf(_SC_NPROCESSORS_ONLN);
-#elif defined(_SC_NPROC_ONLN)
-    core_count = sysconf(_SC_NPROC_ONLN);
-#endif
-#elif defined(_WIN32)
-    {
-#if _WIN32_WINNT >= 0x0501
-        SYSTEM_INFO sysinfo;
-        GetNativeSystemInfo(&sysinfo);
-#else
-        PGNSI pGNSI;
-        SYSTEM_INFO sysinfo;
-
-        /* Call GetNativeSystemInfo if supported or
-         * GetSystemInfo otherwise. */
-
-        pGNSI = (PGNSI) GetProcAddress(
-                GetModuleHandle(TEXT("kernel32.dll")), "GetNativeSystemInfo");
-        if (pGNSI != NULL)
-            pGNSI(&sysinfo);
-        else
-            GetSystemInfo(&sysinfo);
-#endif
-
-        core_count = sysinfo.dwNumberOfProcessors;
-    }
-#elif defined(__OS2__)
-    {
-        ULONG proc_id;
-        ULONG status;
-
-        core_count = 0;
-        for (proc_id = 1; ; proc_id++)
-        {
-            if (DosGetProcessorStatus(proc_id, &status))
-                break;
-
-            if (status == PROC_ONLINE)
-                core_count++;
-        }
-    }
-#else
-    /* other platforms */
-#endif
-
-    return core_count > 0 ? core_count : 1;
-}
-#endif
-
-void vp8_clear_system_state_c() {};
-
-void vp8_machine_specific_config(VP8_COMMON *ctx)
-{
-#if CONFIG_MULTITHREAD
-    ctx->processor_core_count = get_cpu_count();
-#endif /* CONFIG_MULTITHREAD */
-
-#if ARCH_ARM
-    ctx->cpu_caps = arm_cpu_caps();
-#elif ARCH_X86 || ARCH_X86_64
-    ctx->cpu_caps = x86_simd_caps();
-#endif
-}
diff --git a/vp8/common/header.h b/vp8/common/header.h
deleted file mode 100644 (file)
index e27bca1..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#ifndef VP8_COMMON_HEADER_H_
-#define VP8_COMMON_HEADER_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* 24 bits total */
-typedef struct
-{
-    unsigned int type: 1;
-    unsigned int version: 3;
-    unsigned int show_frame: 1;
-
-    /* Allow 2^20 bytes = 8 megabits for first partition */
-
-    unsigned int first_partition_length_in_bytes: 19;
-
-#ifdef PACKET_TESTING
-    unsigned int frame_number;
-    unsigned int update_gold: 1;
-    unsigned int uses_gold: 1;
-    unsigned int update_last: 1;
-    unsigned int uses_last: 1;
-#endif
-
-} VP8_HEADER;
-
-#ifdef PACKET_TESTING
-#define VP8_HEADER_SIZE 8
-#else
-#define VP8_HEADER_SIZE 3
-#endif
-
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP8_COMMON_HEADER_H_
diff --git a/vp8/common/idct_blk.c b/vp8/common/idct_blk.c
deleted file mode 100644 (file)
index 8aa7d9b..0000000
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#include "vpx_config.h"
-#include "vp8_rtcd.h"
-#include "vpx_mem/vpx_mem.h"
-
-void vp8_dequant_idct_add_c(short *input, short *dq,
-                            unsigned char *dest, int stride);
-void vp8_dc_only_idct_add_c(short input_dc, unsigned char * pred,
-                            int pred_stride, unsigned char *dst_ptr,
-                            int dst_stride);
-
-void vp8_dequant_idct_add_y_block_c
-            (short *q, short *dq,
-             unsigned char *dst, int stride, char *eobs)
-{
-    int i, j;
-
-    for (i = 0; i < 4; i++)
-    {
-        for (j = 0; j < 4; j++)
-        {
-            if (*eobs++ > 1)
-                vp8_dequant_idct_add_c (q, dq, dst, stride);
-            else
-            {
-                vp8_dc_only_idct_add_c (q[0]*dq[0], dst, stride, dst, stride);
-                memset(q, 0, 2 * sizeof(q[0]));
-            }
-
-            q   += 16;
-            dst += 4;
-        }
-
-        dst += 4*stride - 16;
-    }
-}
-
-void vp8_dequant_idct_add_uv_block_c
-            (short *q, short *dq,
-             unsigned char *dstu, unsigned char *dstv, int stride, char *eobs)
-{
-    int i, j;
-
-    for (i = 0; i < 2; i++)
-    {
-        for (j = 0; j < 2; j++)
-        {
-            if (*eobs++ > 1)
-                vp8_dequant_idct_add_c (q, dq, dstu, stride);
-            else
-            {
-                vp8_dc_only_idct_add_c (q[0]*dq[0], dstu, stride, dstu, stride);
-                memset(q, 0, 2 * sizeof(q[0]));
-            }
-
-            q    += 16;
-            dstu += 4;
-        }
-
-        dstu += 4*stride - 8;
-    }
-
-    for (i = 0; i < 2; i++)
-    {
-        for (j = 0; j < 2; j++)
-        {
-            if (*eobs++ > 1)
-                vp8_dequant_idct_add_c (q, dq, dstv, stride);
-            else
-            {
-                vp8_dc_only_idct_add_c (q[0]*dq[0], dstv, stride, dstv, stride);
-                memset(q, 0, 2 * sizeof(q[0]));
-            }
-
-            q    += 16;
-            dstv += 4;
-        }
-
-        dstv += 4*stride - 8;
-    }
-}
diff --git a/vp8/common/idctllm.c b/vp8/common/idctllm.c
deleted file mode 100644 (file)
index f5403c5..0000000
+++ /dev/null
@@ -1,205 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#include "./vp8_rtcd.h"
-
-/****************************************************************************
- * Notes:
- *
- * This implementation makes use of 16 bit fixed point verio of two multiply
- * constants:
- *         1.   sqrt(2) * cos (pi/8)
- *         2.   sqrt(2) * sin (pi/8)
- * Becuase the first constant is bigger than 1, to maintain the same 16 bit
- * fixed point precision as the second one, we use a trick of
- *         x * a = x + x*(a-1)
- * so
- *         x * sqrt(2) * cos (pi/8) = x + x * (sqrt(2) *cos(pi/8)-1).
- **************************************************************************/
-static const int cospi8sqrt2minus1 = 20091;
-static const int sinpi8sqrt2      = 35468;
-
-void vp8_short_idct4x4llm_c(short *input, unsigned char *pred_ptr,
-                            int pred_stride, unsigned char *dst_ptr,
-                            int dst_stride)
-{
-    int i;
-    int r, c;
-    int a1, b1, c1, d1;
-    short output[16];
-    short *ip = input;
-    short *op = output;
-    int temp1, temp2;
-    int shortpitch = 4;
-
-    for (i = 0; i < 4; i++)
-    {
-        a1 = ip[0] + ip[8];
-        b1 = ip[0] - ip[8];
-
-        temp1 = (ip[4] * sinpi8sqrt2) >> 16;
-        temp2 = ip[12] + ((ip[12] * cospi8sqrt2minus1) >> 16);
-        c1 = temp1 - temp2;
-
-        temp1 = ip[4] + ((ip[4] * cospi8sqrt2minus1) >> 16);
-        temp2 = (ip[12] * sinpi8sqrt2) >> 16;
-        d1 = temp1 + temp2;
-
-        op[shortpitch*0] = a1 + d1;
-        op[shortpitch*3] = a1 - d1;
-
-        op[shortpitch*1] = b1 + c1;
-        op[shortpitch*2] = b1 - c1;
-
-        ip++;
-        op++;
-    }
-
-    ip = output;
-    op = output;
-
-    for (i = 0; i < 4; i++)
-    {
-        a1 = ip[0] + ip[2];
-        b1 = ip[0] - ip[2];
-
-        temp1 = (ip[1] * sinpi8sqrt2) >> 16;
-        temp2 = ip[3] + ((ip[3] * cospi8sqrt2minus1) >> 16);
-        c1 = temp1 - temp2;
-
-        temp1 = ip[1] + ((ip[1] * cospi8sqrt2minus1) >> 16);
-        temp2 = (ip[3] * sinpi8sqrt2) >> 16;
-        d1 = temp1 + temp2;
-
-
-        op[0] = (a1 + d1 + 4) >> 3;
-        op[3] = (a1 - d1 + 4) >> 3;
-
-        op[1] = (b1 + c1 + 4) >> 3;
-        op[2] = (b1 - c1 + 4) >> 3;
-
-        ip += shortpitch;
-        op += shortpitch;
-    }
-
-    ip = output;
-    for (r = 0; r < 4; r++)
-    {
-        for (c = 0; c < 4; c++)
-        {
-            int a = ip[c] + pred_ptr[c] ;
-
-            if (a < 0)
-                a = 0;
-
-            if (a > 255)
-                a = 255;
-
-            dst_ptr[c] = (unsigned char) a ;
-        }
-        ip += 4;
-        dst_ptr += dst_stride;
-        pred_ptr += pred_stride;
-    }
-}
-
-void vp8_dc_only_idct_add_c(short input_dc, unsigned char *pred_ptr,
-                            int pred_stride, unsigned char *dst_ptr,
-                            int dst_stride)
-{
-    int a1 = ((input_dc + 4) >> 3);
-    int r, c;
-
-    for (r = 0; r < 4; r++)
-    {
-        for (c = 0; c < 4; c++)
-        {
-            int a = a1 + pred_ptr[c] ;
-
-            if (a < 0)
-                a = 0;
-
-            if (a > 255)
-                a = 255;
-
-            dst_ptr[c] = (unsigned char) a ;
-        }
-
-        dst_ptr += dst_stride;
-        pred_ptr += pred_stride;
-    }
-
-}
-
-void vp8_short_inv_walsh4x4_c(short *input, short *mb_dqcoeff)
-{
-    short output[16];
-    int i;
-    int a1, b1, c1, d1;
-    int a2, b2, c2, d2;
-    short *ip = input;
-    short *op = output;
-
-    for (i = 0; i < 4; i++)
-    {
-        a1 = ip[0] + ip[12];
-        b1 = ip[4] + ip[8];
-        c1 = ip[4] - ip[8];
-        d1 = ip[0] - ip[12];
-
-        op[0] = a1 + b1;
-        op[4] = c1 + d1;
-        op[8] = a1 - b1;
-        op[12] = d1 - c1;
-        ip++;
-        op++;
-    }
-
-    ip = output;
-    op = output;
-
-    for (i = 0; i < 4; i++)
-    {
-        a1 = ip[0] + ip[3];
-        b1 = ip[1] + ip[2];
-        c1 = ip[1] - ip[2];
-        d1 = ip[0] - ip[3];
-
-        a2 = a1 + b1;
-        b2 = c1 + d1;
-        c2 = a1 - b1;
-        d2 = d1 - c1;
-
-        op[0] = (a2 + 3) >> 3;
-        op[1] = (b2 + 3) >> 3;
-        op[2] = (c2 + 3) >> 3;
-        op[3] = (d2 + 3) >> 3;
-
-        ip += 4;
-        op += 4;
-    }
-
-    for(i = 0; i < 16; i++)
-    {
-        mb_dqcoeff[i * 16] = output[i];
-    }
-}
-
-void vp8_short_inv_walsh4x4_1_c(short *input, short *mb_dqcoeff)
-{
-    int i;
-    int a1;
-
-    a1 = ((input[0] + 3) >> 3);
-    for(i = 0; i < 16; i++)
-    {
-        mb_dqcoeff[i * 16] = a1;
-    }
-}
diff --git a/vp8/common/invtrans.h b/vp8/common/invtrans.h
deleted file mode 100644 (file)
index 9cfea8d..0000000
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#ifndef VP8_COMMON_INVTRANS_H_
-#define VP8_COMMON_INVTRANS_H_
-
-#include "./vpx_config.h"
-#include "vp8_rtcd.h"
-#include "blockd.h"
-#include "onyxc_int.h"
-
-#if CONFIG_MULTITHREAD
-#include "vpx_mem/vpx_mem.h"
-#endif
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-static void eob_adjust(char *eobs, short *diff)
-{
-    /* eob adjust.... the idct can only skip if both the dc and eob are zero */
-    int js;
-    for(js = 0; js < 16; js++)
-    {
-        if((eobs[js] == 0) && (diff[0] != 0))
-            eobs[js]++;
-        diff+=16;
-    }
-}
-
-static INLINE void vp8_inverse_transform_mby(MACROBLOCKD *xd)
-{
-    short *DQC = xd->dequant_y1;
-
-    if (xd->mode_info_context->mbmi.mode != SPLITMV)
-    {
-        /* do 2nd order transform on the dc block */
-        if (xd->eobs[24] > 1)
-        {
-            vp8_short_inv_walsh4x4
-                (&xd->block[24].dqcoeff[0], xd->qcoeff);
-        }
-        else
-        {
-            vp8_short_inv_walsh4x4_1
-                (&xd->block[24].dqcoeff[0], xd->qcoeff);
-        }
-        eob_adjust(xd->eobs, xd->qcoeff);
-
-        DQC = xd->dequant_y1_dc;
-    }
-    vp8_dequant_idct_add_y_block
-                    (xd->qcoeff, DQC,
-                     xd->dst.y_buffer,
-                     xd->dst.y_stride, xd->eobs);
-}
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP8_COMMON_INVTRANS_H_
diff --git a/vp8/common/loopfilter.h b/vp8/common/loopfilter.h
deleted file mode 100644 (file)
index 20a6bd3..0000000
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#ifndef VP8_COMMON_LOOPFILTER_H_
-#define VP8_COMMON_LOOPFILTER_H_
-
-#include "vpx_ports/mem.h"
-#include "vpx_config.h"
-#include "vp8_rtcd.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define MAX_LOOP_FILTER             63
-/* fraction of total macroblock rows to be used in fast filter level picking */
-/* has to be > 2 */
-#define PARTIAL_FRAME_FRACTION      8
-
-typedef enum
-{
-    NORMAL_LOOPFILTER = 0,
-    SIMPLE_LOOPFILTER = 1
-} LOOPFILTERTYPE;
-
-#if ARCH_ARM
-#define SIMD_WIDTH 1
-#else
-#define SIMD_WIDTH 16
-#endif
-
-/* Need to align this structure so when it is declared and
- * passed it can be loaded into vector registers.
- */
-typedef struct
-{
-    DECLARE_ALIGNED(SIMD_WIDTH, unsigned char, mblim[MAX_LOOP_FILTER + 1][SIMD_WIDTH]);
-    DECLARE_ALIGNED(SIMD_WIDTH, unsigned char, blim[MAX_LOOP_FILTER + 1][SIMD_WIDTH]);
-    DECLARE_ALIGNED(SIMD_WIDTH, unsigned char, lim[MAX_LOOP_FILTER + 1][SIMD_WIDTH]);
-    DECLARE_ALIGNED(SIMD_WIDTH, unsigned char, hev_thr[4][SIMD_WIDTH]);
-    unsigned char lvl[4][4][4];
-    unsigned char hev_thr_lut[2][MAX_LOOP_FILTER + 1];
-    unsigned char mode_lf_lut[10];
-} loop_filter_info_n;
-
-typedef struct loop_filter_info
-{
-    const unsigned char * mblim;
-    const unsigned char * blim;
-    const unsigned char * lim;
-    const unsigned char * hev_thr;
-} loop_filter_info;
-
-
-typedef void loop_filter_uvfunction
-(
-    unsigned char *u,   /* source pointer */
-    int p,              /* pitch */
-    const unsigned char *blimit,
-    const unsigned char *limit,
-    const unsigned char *thresh,
-    unsigned char *v
-);
-
-/* assorted loopfilter functions which get used elsewhere */
-struct VP8Common;
-struct macroblockd;
-struct modeinfo;
-
-void vp8_loop_filter_init(struct VP8Common *cm);
-
-void vp8_loop_filter_frame_init(struct VP8Common *cm,
-                                struct macroblockd *mbd,
-                                int default_filt_lvl);
-
-void vp8_loop_filter_frame(struct VP8Common *cm, struct macroblockd *mbd,
-                           int frame_type);
-
-void vp8_loop_filter_partial_frame(struct VP8Common *cm,
-                                   struct macroblockd *mbd,
-                                   int default_filt_lvl);
-
-void vp8_loop_filter_frame_yonly(struct VP8Common *cm,
-                                 struct macroblockd *mbd,
-                                 int default_filt_lvl);
-
-void vp8_loop_filter_update_sharpness(loop_filter_info_n *lfi,
-                                      int sharpness_lvl);
-
-void vp8_loop_filter_row_normal(struct VP8Common *cm,
-                                struct modeinfo *mode_info_context,
-                                int mb_row, int post_ystride, int post_uvstride,
-                                unsigned char *y_ptr, unsigned char *u_ptr,
-                                unsigned char *v_ptr);
-
-void vp8_loop_filter_row_simple(struct VP8Common *cm,
-                                struct modeinfo *mode_info_context,
-                                int mb_row, int post_ystride, int post_uvstride,
-                                unsigned char *y_ptr, unsigned char *u_ptr,
-                                unsigned char *v_ptr);
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP8_COMMON_LOOPFILTER_H_
diff --git a/vp8/common/loopfilter_filters.c b/vp8/common/loopfilter_filters.c
deleted file mode 100644 (file)
index 1d51696..0000000
+++ /dev/null
@@ -1,430 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#include <stdlib.h>
-#include "loopfilter.h"
-#include "onyxc_int.h"
-
-typedef unsigned char uc;
-
-static signed char vp8_signed_char_clamp(int t)
-{
-    t = (t < -128 ? -128 : t);
-    t = (t > 127 ? 127 : t);
-    return (signed char) t;
-}
-
-
-/* should we apply any filter at all ( 11111111 yes, 00000000 no) */
-static signed char vp8_filter_mask(uc limit, uc blimit,
-                            uc p3, uc p2, uc p1, uc p0,
-                            uc q0, uc q1, uc q2, uc q3)
-{
-    signed char mask = 0;
-    mask |= (abs(p3 - p2) > limit);
-    mask |= (abs(p2 - p1) > limit);
-    mask |= (abs(p1 - p0) > limit);
-    mask |= (abs(q1 - q0) > limit);
-    mask |= (abs(q2 - q1) > limit);
-    mask |= (abs(q3 - q2) > limit);
-    mask |= (abs(p0 - q0) * 2 + abs(p1 - q1) / 2  > blimit);
-    return mask - 1;
-}
-
-/* is there high variance internal edge ( 11111111 yes, 00000000 no) */
-static signed char vp8_hevmask(uc thresh, uc p1, uc p0, uc q0, uc q1)
-{
-    signed char hev = 0;
-    hev  |= (abs(p1 - p0) > thresh) * -1;
-    hev  |= (abs(q1 - q0) > thresh) * -1;
-    return hev;
-}
-
-static void vp8_filter(signed char mask, uc hev, uc *op1,
-        uc *op0, uc *oq0, uc *oq1)
-
-{
-    signed char ps0, qs0;
-    signed char ps1, qs1;
-    signed char filter_value, Filter1, Filter2;
-    signed char u;
-
-    ps1 = (signed char) * op1 ^ 0x80;
-    ps0 = (signed char) * op0 ^ 0x80;
-    qs0 = (signed char) * oq0 ^ 0x80;
-    qs1 = (signed char) * oq1 ^ 0x80;
-
-    /* add outer taps if we have high edge variance */
-    filter_value = vp8_signed_char_clamp(ps1 - qs1);
-    filter_value &= hev;
-
-    /* inner taps */
-    filter_value = vp8_signed_char_clamp(filter_value + 3 * (qs0 - ps0));
-    filter_value &= mask;
-
-    /* save bottom 3 bits so that we round one side +4 and the other +3
-     * if it equals 4 we'll set to adjust by -1 to account for the fact
-     * we'd round 3 the other way
-     */
-    Filter1 = vp8_signed_char_clamp(filter_value + 4);
-    Filter2 = vp8_signed_char_clamp(filter_value + 3);
-    Filter1 >>= 3;
-    Filter2 >>= 3;
-    u = vp8_signed_char_clamp(qs0 - Filter1);
-    *oq0 = u ^ 0x80;
-    u = vp8_signed_char_clamp(ps0 + Filter2);
-    *op0 = u ^ 0x80;
-    filter_value = Filter1;
-
-    /* outer tap adjustments */
-    filter_value += 1;
-    filter_value >>= 1;
-    filter_value &= ~hev;
-
-    u = vp8_signed_char_clamp(qs1 - filter_value);
-    *oq1 = u ^ 0x80;
-    u = vp8_signed_char_clamp(ps1 + filter_value);
-    *op1 = u ^ 0x80;
-
-}
-void vp8_loop_filter_horizontal_edge_c
-(
-    unsigned char *s,
-    int p, /* pitch */
-    const unsigned char *blimit,
-    const unsigned char *limit,
-    const unsigned char *thresh,
-    int count
-)
-{
-    int  hev = 0; /* high edge variance */
-    signed char mask = 0;
-    int i = 0;
-
-    /* loop filter designed to work using chars so that we can make maximum use
-     * of 8 bit simd instructions.
-     */
-    do
-    {
-        mask = vp8_filter_mask(limit[0], blimit[0],
-                               s[-4*p], s[-3*p], s[-2*p], s[-1*p],
-                               s[0*p], s[1*p], s[2*p], s[3*p]);
-
-        hev = vp8_hevmask(thresh[0], s[-2*p], s[-1*p], s[0*p], s[1*p]);
-
-        vp8_filter(mask, hev, s - 2 * p, s - 1 * p, s, s + 1 * p);
-
-        ++s;
-    }
-    while (++i < count * 8);
-}
-
-void vp8_loop_filter_vertical_edge_c
-(
-    unsigned char *s,
-    int p,
-    const unsigned char *blimit,
-    const unsigned char *limit,
-    const unsigned char *thresh,
-    int count
-)
-{
-    int  hev = 0; /* high edge variance */
-    signed char mask = 0;
-    int i = 0;
-
-    /* loop filter designed to work using chars so that we can make maximum use
-     * of 8 bit simd instructions.
-     */
-    do
-    {
-        mask = vp8_filter_mask(limit[0], blimit[0],
-                               s[-4], s[-3], s[-2], s[-1], s[0], s[1], s[2], s[3]);
-
-        hev = vp8_hevmask(thresh[0], s[-2], s[-1], s[0], s[1]);
-
-        vp8_filter(mask, hev, s - 2, s - 1, s, s + 1);
-
-        s += p;
-    }
-    while (++i < count * 8);
-}
-
-static void vp8_mbfilter(signed char mask, uc hev,
-                           uc *op2, uc *op1, uc *op0, uc *oq0, uc *oq1, uc *oq2)
-{
-    signed char s, u;
-    signed char filter_value, Filter1, Filter2;
-    signed char ps2 = (signed char) * op2 ^ 0x80;
-    signed char ps1 = (signed char) * op1 ^ 0x80;
-    signed char ps0 = (signed char) * op0 ^ 0x80;
-    signed char qs0 = (signed char) * oq0 ^ 0x80;
-    signed char qs1 = (signed char) * oq1 ^ 0x80;
-    signed char qs2 = (signed char) * oq2 ^ 0x80;
-
-    /* add outer taps if we have high edge variance */
-    filter_value = vp8_signed_char_clamp(ps1 - qs1);
-    filter_value = vp8_signed_char_clamp(filter_value + 3 * (qs0 - ps0));
-    filter_value &= mask;
-
-    Filter2 = filter_value;
-    Filter2 &= hev;
-
-    /* save bottom 3 bits so that we round one side +4 and the other +3 */
-    Filter1 = vp8_signed_char_clamp(Filter2 + 4);
-    Filter2 = vp8_signed_char_clamp(Filter2 + 3);
-    Filter1 >>= 3;
-    Filter2 >>= 3;
-    qs0 = vp8_signed_char_clamp(qs0 - Filter1);
-    ps0 = vp8_signed_char_clamp(ps0 + Filter2);
-
-
-    /* only apply wider filter if not high edge variance */
-    filter_value &= ~hev;
-    Filter2 = filter_value;
-
-    /* roughly 3/7th difference across boundary */
-    u = vp8_signed_char_clamp((63 + Filter2 * 27) >> 7);
-    s = vp8_signed_char_clamp(qs0 - u);
-    *oq0 = s ^ 0x80;
-    s = vp8_signed_char_clamp(ps0 + u);
-    *op0 = s ^ 0x80;
-
-    /* roughly 2/7th difference across boundary */
-    u = vp8_signed_char_clamp((63 + Filter2 * 18) >> 7);
-    s = vp8_signed_char_clamp(qs1 - u);
-    *oq1 = s ^ 0x80;
-    s = vp8_signed_char_clamp(ps1 + u);
-    *op1 = s ^ 0x80;
-
-    /* roughly 1/7th difference across boundary */
-    u = vp8_signed_char_clamp((63 + Filter2 * 9) >> 7);
-    s = vp8_signed_char_clamp(qs2 - u);
-    *oq2 = s ^ 0x80;
-    s = vp8_signed_char_clamp(ps2 + u);
-    *op2 = s ^ 0x80;
-}
-
-void vp8_mbloop_filter_horizontal_edge_c
-(
-    unsigned char *s,
-    int p,
-    const unsigned char *blimit,
-    const unsigned char *limit,
-    const unsigned char *thresh,
-    int count
-)
-{
-    signed char hev = 0; /* high edge variance */
-    signed char mask = 0;
-    int i = 0;
-
-    /* loop filter designed to work using chars so that we can make maximum use
-     * of 8 bit simd instructions.
-     */
-    do
-    {
-
-        mask = vp8_filter_mask(limit[0], blimit[0],
-                               s[-4*p], s[-3*p], s[-2*p], s[-1*p],
-                               s[0*p], s[1*p], s[2*p], s[3*p]);
-
-        hev = vp8_hevmask(thresh[0], s[-2*p], s[-1*p], s[0*p], s[1*p]);
-
-        vp8_mbfilter(mask, hev, s - 3 * p, s - 2 * p, s - 1 * p, s, s + 1 * p, s + 2 * p);
-
-        ++s;
-    }
-    while (++i < count * 8);
-
-}
-
-
-void vp8_mbloop_filter_vertical_edge_c
-(
-    unsigned char *s,
-    int p,
-    const unsigned char *blimit,
-    const unsigned char *limit,
-    const unsigned char *thresh,
-    int count
-)
-{
-    signed char hev = 0; /* high edge variance */
-    signed char mask = 0;
-    int i = 0;
-
-    do
-    {
-
-        mask = vp8_filter_mask(limit[0], blimit[0],
-                               s[-4], s[-3], s[-2], s[-1], s[0], s[1], s[2], s[3]);
-
-        hev = vp8_hevmask(thresh[0], s[-2], s[-1], s[0], s[1]);
-
-        vp8_mbfilter(mask, hev, s - 3, s - 2, s - 1, s, s + 1, s + 2);
-
-        s += p;
-    }
-    while (++i < count * 8);
-
-}
-
-/* should we apply any filter at all ( 11111111 yes, 00000000 no) */
-static signed char vp8_simple_filter_mask(uc blimit, uc p1, uc p0, uc q0, uc q1)
-{
-/* Why does this cause problems for win32?
- * error C2143: syntax error : missing ';' before 'type'
- *  (void) limit;
- */
-    signed char mask = (abs(p0 - q0) * 2 + abs(p1 - q1) / 2  <= blimit) * -1;
-    return mask;
-}
-
-static void vp8_simple_filter(signed char mask, uc *op1, uc *op0, uc *oq0, uc *oq1)
-{
-    signed char filter_value, Filter1, Filter2;
-    signed char p1 = (signed char) * op1 ^ 0x80;
-    signed char p0 = (signed char) * op0 ^ 0x80;
-    signed char q0 = (signed char) * oq0 ^ 0x80;
-    signed char q1 = (signed char) * oq1 ^ 0x80;
-    signed char u;
-
-    filter_value = vp8_signed_char_clamp(p1 - q1);
-    filter_value = vp8_signed_char_clamp(filter_value + 3 * (q0 - p0));
-    filter_value &= mask;
-
-    /* save bottom 3 bits so that we round one side +4 and the other +3 */
-    Filter1 = vp8_signed_char_clamp(filter_value + 4);
-    Filter1 >>= 3;
-    u = vp8_signed_char_clamp(q0 - Filter1);
-    *oq0  = u ^ 0x80;
-
-    Filter2 = vp8_signed_char_clamp(filter_value + 3);
-    Filter2 >>= 3;
-    u = vp8_signed_char_clamp(p0 + Filter2);
-    *op0 = u ^ 0x80;
-}
-
-void vp8_loop_filter_simple_horizontal_edge_c
-(
-    unsigned char *s,
-    int p,
-    const unsigned char *blimit
-)
-{
-    signed char mask = 0;
-    int i = 0;
-
-    do
-    {
-        mask = vp8_simple_filter_mask(blimit[0], s[-2*p], s[-1*p], s[0*p], s[1*p]);
-        vp8_simple_filter(mask, s - 2 * p, s - 1 * p, s, s + 1 * p);
-        ++s;
-    }
-    while (++i < 16);
-}
-
-void vp8_loop_filter_simple_vertical_edge_c
-(
-    unsigned char *s,
-    int p,
-    const unsigned char *blimit
-)
-{
-    signed char mask = 0;
-    int i = 0;
-
-    do
-    {
-        mask = vp8_simple_filter_mask(blimit[0], s[-2], s[-1], s[0], s[1]);
-        vp8_simple_filter(mask, s - 2, s - 1, s, s + 1);
-        s += p;
-    }
-    while (++i < 16);
-
-}
-
-/* Horizontal MB filtering */
-void vp8_loop_filter_mbh_c(unsigned char *y_ptr, unsigned char *u_ptr,
-                           unsigned char *v_ptr, int y_stride, int uv_stride,
-                           loop_filter_info *lfi)
-{
-    vp8_mbloop_filter_horizontal_edge_c(y_ptr, y_stride, lfi->mblim, lfi->lim, lfi->hev_thr, 2);
-
-    if (u_ptr)
-        vp8_mbloop_filter_horizontal_edge_c(u_ptr, uv_stride, lfi->mblim, lfi->lim, lfi->hev_thr, 1);
-
-    if (v_ptr)
-        vp8_mbloop_filter_horizontal_edge_c(v_ptr, uv_stride, lfi->mblim, lfi->lim, lfi->hev_thr, 1);
-}
-
-/* Vertical MB Filtering */
-void vp8_loop_filter_mbv_c(unsigned char *y_ptr, unsigned char *u_ptr,
-                           unsigned char *v_ptr, int y_stride, int uv_stride,
-                           loop_filter_info *lfi)
-{
-    vp8_mbloop_filter_vertical_edge_c(y_ptr, y_stride, lfi->mblim, lfi->lim, lfi->hev_thr, 2);
-
-    if (u_ptr)
-        vp8_mbloop_filter_vertical_edge_c(u_ptr, uv_stride, lfi->mblim, lfi->lim, lfi->hev_thr, 1);
-
-    if (v_ptr)
-        vp8_mbloop_filter_vertical_edge_c(v_ptr, uv_stride, lfi->mblim, lfi->lim, lfi->hev_thr, 1);
-}
-
-/* Horizontal B Filtering */
-void vp8_loop_filter_bh_c(unsigned char *y_ptr, unsigned char *u_ptr,
-                          unsigned char *v_ptr, int y_stride, int uv_stride,
-                          loop_filter_info *lfi)
-{
-    vp8_loop_filter_horizontal_edge_c(y_ptr + 4 * y_stride, y_stride, lfi->blim, lfi->lim, lfi->hev_thr, 2);
-    vp8_loop_filter_horizontal_edge_c(y_ptr + 8 * y_stride, y_stride, lfi->blim, lfi->lim, lfi->hev_thr, 2);
-    vp8_loop_filter_horizontal_edge_c(y_ptr + 12 * y_stride, y_stride, lfi->blim, lfi->lim, lfi->hev_thr, 2);
-
-    if (u_ptr)
-        vp8_loop_filter_horizontal_edge_c(u_ptr + 4 * uv_stride, uv_stride, lfi->blim, lfi->lim, lfi->hev_thr, 1);
-
-    if (v_ptr)
-        vp8_loop_filter_horizontal_edge_c(v_ptr + 4 * uv_stride, uv_stride, lfi->blim, lfi->lim, lfi->hev_thr, 1);
-}
-
-void vp8_loop_filter_bhs_c(unsigned char *y_ptr, int y_stride,
-                           const unsigned char *blimit)
-{
-    vp8_loop_filter_simple_horizontal_edge_c(y_ptr + 4 * y_stride, y_stride, blimit);
-    vp8_loop_filter_simple_horizontal_edge_c(y_ptr + 8 * y_stride, y_stride, blimit);
-    vp8_loop_filter_simple_horizontal_edge_c(y_ptr + 12 * y_stride, y_stride, blimit);
-}
-
-/* Vertical B Filtering */
-void vp8_loop_filter_bv_c(unsigned char *y_ptr, unsigned char *u_ptr,
-                          unsigned char *v_ptr, int y_stride, int uv_stride,
-                          loop_filter_info *lfi)
-{
-    vp8_loop_filter_vertical_edge_c(y_ptr + 4, y_stride, lfi->blim, lfi->lim, lfi->hev_thr, 2);
-    vp8_loop_filter_vertical_edge_c(y_ptr + 8, y_stride, lfi->blim, lfi->lim, lfi->hev_thr, 2);
-    vp8_loop_filter_vertical_edge_c(y_ptr + 12, y_stride, lfi->blim, lfi->lim, lfi->hev_thr, 2);
-
-    if (u_ptr)
-        vp8_loop_filter_vertical_edge_c(u_ptr + 4, uv_stride, lfi->blim, lfi->lim, lfi->hev_thr, 1);
-
-    if (v_ptr)
-        vp8_loop_filter_vertical_edge_c(v_ptr + 4, uv_stride, lfi->blim, lfi->lim, lfi->hev_thr, 1);
-}
-
-void vp8_loop_filter_bvs_c(unsigned char *y_ptr, int y_stride,
-                           const unsigned char *blimit)
-{
-    vp8_loop_filter_simple_vertical_edge_c(y_ptr + 4, y_stride, blimit);
-    vp8_loop_filter_simple_vertical_edge_c(y_ptr + 8, y_stride, blimit);
-    vp8_loop_filter_simple_vertical_edge_c(y_ptr + 12, y_stride, blimit);
-}
diff --git a/vp8/common/mbpitch.c b/vp8/common/mbpitch.c
deleted file mode 100644 (file)
index 32e1b66..0000000
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#include "blockd.h"
-
-void vp8_setup_block_dptrs(MACROBLOCKD *x)
-{
-    int r, c;
-
-    for (r = 0; r < 4; r++)
-    {
-        for (c = 0; c < 4; c++)
-        {
-            x->block[r*4+c].predictor = x->predictor + r * 4 * 16 + c * 4;
-        }
-    }
-
-    for (r = 0; r < 2; r++)
-    {
-        for (c = 0; c < 2; c++)
-        {
-            x->block[16+r*2+c].predictor = x->predictor + 256 + r * 4 * 8 + c * 4;
-
-        }
-    }
-
-    for (r = 0; r < 2; r++)
-    {
-        for (c = 0; c < 2; c++)
-        {
-            x->block[20+r*2+c].predictor = x->predictor + 320 + r * 4 * 8 + c * 4;
-
-        }
-    }
-
-    for (r = 0; r < 25; r++)
-    {
-        x->block[r].qcoeff  = x->qcoeff  + r * 16;
-        x->block[r].dqcoeff = x->dqcoeff + r * 16;
-        x->block[r].eob     = x->eobs + r;
-    }
-}
-
-void vp8_build_block_doffsets(MACROBLOCKD *x)
-{
-    int block;
-
-    for (block = 0; block < 16; block++) /* y blocks */
-    {
-        x->block[block].offset =
-            (block >> 2) * 4 * x->dst.y_stride + (block & 3) * 4;
-    }
-
-    for (block = 16; block < 20; block++) /* U and V blocks */
-    {
-        x->block[block+4].offset =
-        x->block[block].offset =
-            ((block - 16) >> 1) * 4 * x->dst.uv_stride + (block & 1) * 4;
-    }
-}
diff --git a/vp8/common/mfqe.c b/vp8/common/mfqe.c
deleted file mode 100644 (file)
index 2bfefb1..0000000
+++ /dev/null
@@ -1,386 +0,0 @@
-/*
- *  Copyright (c) 2012 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.
- */
-
-
-/* MFQE: Multiframe Quality Enhancement
- * In rate limited situations keyframes may cause significant visual artifacts
- * commonly referred to as "popping." This file implements a postproccesing
- * algorithm which blends data from the preceeding frame when there is no
- * motion and the q from the previous frame is lower which indicates that it is
- * higher quality.
- */
-
-#include "./vp8_rtcd.h"
-#include "./vpx_dsp_rtcd.h"
-#include "vp8/common/postproc.h"
-#include "vpx_dsp/variance.h"
-#include "vpx_mem/vpx_mem.h"
-#include "vpx_scale/yv12config.h"
-
-#include <limits.h>
-#include <stdlib.h>
-
-static void filter_by_weight(unsigned char *src, int src_stride,
-                             unsigned char *dst, int dst_stride,
-                             int block_size, int src_weight)
-{
-    int dst_weight = (1 << MFQE_PRECISION) - src_weight;
-    int rounding_bit = 1 << (MFQE_PRECISION - 1);
-    int r, c;
-
-    for (r = 0; r < block_size; r++)
-    {
-        for (c = 0; c < block_size; c++)
-        {
-            dst[c] = (src[c] * src_weight +
-                      dst[c] * dst_weight +
-                      rounding_bit) >> MFQE_PRECISION;
-        }
-        src += src_stride;
-        dst += dst_stride;
-    }
-}
-
-void vp8_filter_by_weight16x16_c(unsigned char *src, int src_stride,
-                                 unsigned char *dst, int dst_stride,
-                                 int src_weight)
-{
-    filter_by_weight(src, src_stride, dst, dst_stride, 16, src_weight);
-}
-
-void vp8_filter_by_weight8x8_c(unsigned char *src, int src_stride,
-                               unsigned char *dst, int dst_stride,
-                               int src_weight)
-{
-    filter_by_weight(src, src_stride, dst, dst_stride, 8, src_weight);
-}
-
-void vp8_filter_by_weight4x4_c(unsigned char *src, int src_stride,
-                               unsigned char *dst, int dst_stride,
-                               int src_weight)
-{
-    filter_by_weight(src, src_stride, dst, dst_stride, 4, src_weight);
-}
-
-static void apply_ifactor(unsigned char *y_src,
-                          int y_src_stride,
-                          unsigned char *y_dst,
-                          int y_dst_stride,
-                          unsigned char *u_src,
-                          unsigned char *v_src,
-                          int uv_src_stride,
-                          unsigned char *u_dst,
-                          unsigned char *v_dst,
-                          int uv_dst_stride,
-                          int block_size,
-                          int src_weight)
-{
-    if (block_size == 16)
-    {
-        vp8_filter_by_weight16x16(y_src, y_src_stride, y_dst, y_dst_stride, src_weight);
-        vp8_filter_by_weight8x8(u_src, uv_src_stride, u_dst, uv_dst_stride, src_weight);
-        vp8_filter_by_weight8x8(v_src, uv_src_stride, v_dst, uv_dst_stride, src_weight);
-    }
-    else /* if (block_size == 8) */
-    {
-        vp8_filter_by_weight8x8(y_src, y_src_stride, y_dst, y_dst_stride, src_weight);
-        vp8_filter_by_weight4x4(u_src, uv_src_stride, u_dst, uv_dst_stride, src_weight);
-        vp8_filter_by_weight4x4(v_src, uv_src_stride, v_dst, uv_dst_stride, src_weight);
-    }
-}
-
-static unsigned int int_sqrt(unsigned int x)
-{
-    unsigned int y = x;
-    unsigned int guess;
-    int p = 1;
-    while (y>>=1) p++;
-    p>>=1;
-
-    guess=0;
-    while (p>=0)
-    {
-        guess |= (1<<p);
-        if (x<guess*guess)
-            guess -= (1<<p);
-        p--;
-    }
-    /* choose between guess or guess+1 */
-    return guess+(guess*guess+guess+1<=x);
-}
-
-#define USE_SSD
-static void multiframe_quality_enhance_block
-(
-    int blksize, /* Currently only values supported are 16, 8 */
-    int qcurr,
-    int qprev,
-    unsigned char *y,
-    unsigned char *u,
-    unsigned char *v,
-    int y_stride,
-    int uv_stride,
-    unsigned char *yd,
-    unsigned char *ud,
-    unsigned char *vd,
-    int yd_stride,
-    int uvd_stride
-)
-{
-    static const unsigned char VP8_ZEROS[16]=
-    {
-         0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
-    };
-    int uvblksize = blksize >> 1;
-    int qdiff = qcurr - qprev;
-
-    int i;
-    unsigned char *up;
-    unsigned char *udp;
-    unsigned char *vp;
-    unsigned char *vdp;
-
-    unsigned int act, actd, sad, usad, vsad, sse, thr, thrsq, actrisk;
-
-    if (blksize == 16)
-    {
-        actd = (vpx_variance16x16(yd, yd_stride, VP8_ZEROS, 0, &sse)+128)>>8;
-        act = (vpx_variance16x16(y, y_stride, VP8_ZEROS, 0, &sse)+128)>>8;
-#ifdef USE_SSD
-        vpx_variance16x16(y, y_stride, yd, yd_stride, &sse);
-        sad = (sse + 128)>>8;
-        vpx_variance8x8(u, uv_stride, ud, uvd_stride, &sse);
-        usad = (sse + 32)>>6;
-        vpx_variance8x8(v, uv_stride, vd, uvd_stride, &sse);
-        vsad = (sse + 32)>>6;
-#else
-        sad = (vpx_sad16x16(y, y_stride, yd, yd_stride) + 128) >> 8;
-        usad = (vpx_sad8x8(u, uv_stride, ud, uvd_stride) + 32) >> 6;
-        vsad = (vpx_sad8x8(v, uv_stride, vd, uvd_stride)+ 32) >> 6;
-#endif
-    }
-    else /* if (blksize == 8) */
-    {
-        actd = (vpx_variance8x8(yd, yd_stride, VP8_ZEROS, 0, &sse)+32)>>6;
-        act = (vpx_variance8x8(y, y_stride, VP8_ZEROS, 0, &sse)+32)>>6;
-#ifdef USE_SSD
-        vpx_variance8x8(y, y_stride, yd, yd_stride, &sse);
-        sad = (sse + 32)>>6;
-        vpx_variance4x4(u, uv_stride, ud, uvd_stride, &sse);
-        usad = (sse + 8)>>4;
-        vpx_variance4x4(v, uv_stride, vd, uvd_stride, &sse);
-        vsad = (sse + 8)>>4;
-#else
-        sad = (vpx_sad8x8(y, y_stride, yd, yd_stride) + 32) >> 6;
-        usad = (vpx_sad4x4(u, uv_stride, ud, uvd_stride) + 8) >> 4;
-        vsad = (vpx_sad4x4(v, uv_stride, vd, uvd_stride) + 8) >> 4;
-#endif
-    }
-
-    actrisk = (actd > act * 5);
-
-    /* thr = qdiff/16 + log2(act) + log4(qprev) */
-    thr = (qdiff >> 4);
-    while (actd >>= 1) thr++;
-    while (qprev >>= 2) thr++;
-
-#ifdef USE_SSD
-    thrsq = thr * thr;
-    if (sad < thrsq &&
-        /* additional checks for color mismatch and excessive addition of
-         * high-frequencies */
-        4 * usad < thrsq && 4 * vsad < thrsq && !actrisk)
-#else
-    if (sad < thr &&
-        /* additional checks for color mismatch and excessive addition of
-         * high-frequencies */
-        2 * usad < thr && 2 * vsad < thr && !actrisk)
-#endif
-    {
-        int ifactor;
-#ifdef USE_SSD
-        /* TODO: optimize this later to not need sqr root */
-        sad = int_sqrt(sad);
-#endif
-        ifactor = (sad << MFQE_PRECISION) / thr;
-        ifactor >>= (qdiff >> 5);
-
-        if (ifactor)
-        {
-            apply_ifactor(y, y_stride, yd, yd_stride,
-                          u, v, uv_stride,
-                          ud, vd, uvd_stride,
-                          blksize, ifactor);
-        }
-    }
-    else  /* else implicitly copy from previous frame */
-    {
-        if (blksize == 16)
-        {
-            vp8_copy_mem16x16(y, y_stride, yd, yd_stride);
-            vp8_copy_mem8x8(u, uv_stride, ud, uvd_stride);
-            vp8_copy_mem8x8(v, uv_stride, vd, uvd_stride);
-        }
-        else  /* if (blksize == 8) */
-        {
-            vp8_copy_mem8x8(y, y_stride, yd, yd_stride);
-            for (up = u, udp = ud, i = 0; i < uvblksize; ++i, up += uv_stride, udp += uvd_stride)
-                memcpy(udp, up, uvblksize);
-            for (vp = v, vdp = vd, i = 0; i < uvblksize; ++i, vp += uv_stride, vdp += uvd_stride)
-                memcpy(vdp, vp, uvblksize);
-        }
-    }
-}
-
-static int qualify_inter_mb(const MODE_INFO *mode_info_context, int *map)
-{
-    if (mode_info_context->mbmi.mb_skip_coeff)
-        map[0] = map[1] = map[2] = map[3] = 1;
-    else if (mode_info_context->mbmi.mode==SPLITMV)
-    {
-        static int ndx[4][4] =
-        {
-            {0, 1, 4, 5},
-            {2, 3, 6, 7},
-            {8, 9, 12, 13},
-            {10, 11, 14, 15}
-        };
-        int i, j;
-        for (i=0; i<4; ++i)
-        {
-            map[i] = 1;
-            for (j=0; j<4 && map[j]; ++j)
-                map[i] &= (mode_info_context->bmi[ndx[i][j]].mv.as_mv.row <= 2 &&
-                           mode_info_context->bmi[ndx[i][j]].mv.as_mv.col <= 2);
-        }
-    }
-    else
-    {
-        map[0] = map[1] = map[2] = map[3] =
-            (mode_info_context->mbmi.mode > B_PRED &&
-             abs(mode_info_context->mbmi.mv.as_mv.row) <= 2 &&
-             abs(mode_info_context->mbmi.mv.as_mv.col) <= 2);
-    }
-    return (map[0]+map[1]+map[2]+map[3]);
-}
-
-void vp8_multiframe_quality_enhance
-(
-    VP8_COMMON *cm
-)
-{
-    YV12_BUFFER_CONFIG *show = cm->frame_to_show;
-    YV12_BUFFER_CONFIG *dest = &cm->post_proc_buffer;
-
-    FRAME_TYPE frame_type = cm->frame_type;
-    /* Point at base of Mb MODE_INFO list has motion vectors etc */
-    const MODE_INFO *mode_info_context = cm->show_frame_mi;
-    int mb_row;
-    int mb_col;
-    int totmap, map[4];
-    int qcurr = cm->base_qindex;
-    int qprev = cm->postproc_state.last_base_qindex;
-
-    unsigned char *y_ptr, *u_ptr, *v_ptr;
-    unsigned char *yd_ptr, *ud_ptr, *vd_ptr;
-
-    /* Set up the buffer pointers */
-    y_ptr = show->y_buffer;
-    u_ptr = show->u_buffer;
-    v_ptr = show->v_buffer;
-    yd_ptr = dest->y_buffer;
-    ud_ptr = dest->u_buffer;
-    vd_ptr = dest->v_buffer;
-
-    /* postprocess each macro block */
-    for (mb_row = 0; mb_row < cm->mb_rows; mb_row++)
-    {
-        for (mb_col = 0; mb_col < cm->mb_cols; mb_col++)
-        {
-            /* if motion is high there will likely be no benefit */
-            if (frame_type == INTER_FRAME) totmap = qualify_inter_mb(mode_info_context, map);
-            else totmap = (frame_type == KEY_FRAME ? 4 : 0);
-            if (totmap)
-            {
-                if (totmap < 4)
-                {
-                    int i, j;
-                    for (i=0; i<2; ++i)
-                        for (j=0; j<2; ++j)
-                        {
-                            if (map[i*2+j])
-                            {
-                                multiframe_quality_enhance_block(8, qcurr, qprev,
-                                                                 y_ptr + 8*(i*show->y_stride+j),
-                                                                 u_ptr + 4*(i*show->uv_stride+j),
-                                                                 v_ptr + 4*(i*show->uv_stride+j),
-                                                                 show->y_stride,
-                                                                 show->uv_stride,
-                                                                 yd_ptr + 8*(i*dest->y_stride+j),
-                                                                 ud_ptr + 4*(i*dest->uv_stride+j),
-                                                                 vd_ptr + 4*(i*dest->uv_stride+j),
-                                                                 dest->y_stride,
-                                                                 dest->uv_stride);
-                            }
-                            else
-                            {
-                                /* copy a 8x8 block */
-                                int k;
-                                unsigned char *up = u_ptr + 4*(i*show->uv_stride+j);
-                                unsigned char *udp = ud_ptr + 4*(i*dest->uv_stride+j);
-                                unsigned char *vp = v_ptr + 4*(i*show->uv_stride+j);
-                                unsigned char *vdp = vd_ptr + 4*(i*dest->uv_stride+j);
-                                vp8_copy_mem8x8(y_ptr + 8*(i*show->y_stride+j), show->y_stride,
-                                                yd_ptr + 8*(i*dest->y_stride+j), dest->y_stride);
-                                for (k = 0; k < 4; ++k, up += show->uv_stride, udp += dest->uv_stride,
-                                                        vp += show->uv_stride, vdp += dest->uv_stride)
-                                {
-                                    memcpy(udp, up, 4);
-                                    memcpy(vdp, vp, 4);
-                                }
-                            }
-                        }
-                }
-                else /* totmap = 4 */
-                {
-                    multiframe_quality_enhance_block(16, qcurr, qprev, y_ptr,
-                                                     u_ptr, v_ptr,
-                                                     show->y_stride,
-                                                     show->uv_stride,
-                                                     yd_ptr, ud_ptr, vd_ptr,
-                                                     dest->y_stride,
-                                                     dest->uv_stride);
-                }
-            }
-            else
-            {
-                vp8_copy_mem16x16(y_ptr, show->y_stride, yd_ptr, dest->y_stride);
-                vp8_copy_mem8x8(u_ptr, show->uv_stride, ud_ptr, dest->uv_stride);
-                vp8_copy_mem8x8(v_ptr, show->uv_stride, vd_ptr, dest->uv_stride);
-            }
-            y_ptr += 16;
-            u_ptr += 8;
-            v_ptr += 8;
-            yd_ptr += 16;
-            ud_ptr += 8;
-            vd_ptr += 8;
-            mode_info_context++;     /* step to next MB */
-        }
-
-        y_ptr += show->y_stride  * 16 - 16 * cm->mb_cols;
-        u_ptr += show->uv_stride *  8 - 8 * cm->mb_cols;
-        v_ptr += show->uv_stride *  8 - 8 * cm->mb_cols;
-        yd_ptr += dest->y_stride  * 16 - 16 * cm->mb_cols;
-        ud_ptr += dest->uv_stride *  8 - 8 * cm->mb_cols;
-        vd_ptr += dest->uv_stride *  8 - 8 * cm->mb_cols;
-
-        mode_info_context++;         /* Skip border mb */
-    }
-}
diff --git a/vp8/common/mips/dspr2/dequantize_dspr2.c b/vp8/common/mips/dspr2/dequantize_dspr2.c
deleted file mode 100644 (file)
index fc3bb8a..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- *  Copyright (c) 2012 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.
- */
-
-
-#include "vpx_config.h"
-#include "vp8_rtcd.h"
-#include "vpx_mem/vpx_mem.h"
-
-#if HAVE_DSPR2
-void vp8_dequant_idct_add_dspr2(short *input, short *dq,
-                                unsigned char *dest, int stride)
-{
-    int i;
-
-    for (i = 0; i < 16; i++)
-    {
-        input[i] = dq[i] * input[i];
-    }
-
-    vp8_short_idct4x4llm_dspr2(input, dest, stride, dest, stride);
-
-    memset(input, 0, 32);
-
-}
-
-#endif
diff --git a/vp8/common/mips/dspr2/filter_dspr2.c b/vp8/common/mips/dspr2/filter_dspr2.c
deleted file mode 100644 (file)
index ace5d40..0000000
+++ /dev/null
@@ -1,2823 +0,0 @@
-/*
- *  Copyright (c) 2012 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.
- */
-
-
-#include <stdlib.h>
-#include "vp8_rtcd.h"
-#include "vpx_ports/mem.h"
-
-#if HAVE_DSPR2
-#define CROP_WIDTH 256
-unsigned char ff_cropTbl[256 + 2 * CROP_WIDTH];
-
-static const unsigned short sub_pel_filterss[8][3] =
-{
-    {      0,      0,      0},
-    {      0, 0x0601, 0x7b0c},
-    { 0x0201, 0x0b08, 0x6c24},
-    {      0, 0x0906, 0x5d32},
-    { 0x0303, 0x1010, 0x4d4d},
-    {      0, 0x0609, 0x325d},
-    { 0x0102, 0x080b, 0x246c},
-    {      0, 0x0106, 0x0c7b},
-};
-
-
-static const int sub_pel_filters_int[8][3] =
-{
-    {          0,          0,          0},
-    { 0x0000fffa, 0x007b000c, 0xffff0000},
-    { 0x0002fff5, 0x006c0024, 0xfff80001},
-    { 0x0000fff7, 0x005d0032, 0xfffa0000},
-    { 0x0003fff0, 0x004d004d, 0xfff00003},
-    { 0x0000fffa, 0x0032005d, 0xfff70000},
-    { 0x0001fff8, 0x0024006c, 0xfff50002},
-    { 0x0000ffff, 0x000c007b, 0xfffa0000},
-};
-
-
-static const int sub_pel_filters_inv[8][3] =
-{
-    {          0,          0,          0},
-    { 0xfffa0000, 0x000c007b, 0x0000ffff},
-    { 0xfff50002, 0x0024006c, 0x0001fff8},
-    { 0xfff70000, 0x0032005d, 0x0000fffa},
-    { 0xfff00003, 0x004d004d, 0x0003fff0},
-    { 0xfffa0000, 0x005d0032, 0x0000fff7},
-    { 0xfff80001, 0x006c0024, 0x0002fff5},
-    { 0xffff0000, 0x007b000c, 0x0000fffa},
-};
-
-
-static const int sub_pel_filters_int_tap_4[8][2] =
-{
-    {          0,          0},
-    { 0xfffa007b, 0x000cffff},
-    {          0,          0},
-    { 0xfff7005d, 0x0032fffa},
-    {          0,          0},
-    { 0xfffa0032, 0x005dfff7},
-    {          0,          0},
-    { 0xffff000c, 0x007bfffa},
-};
-
-
-static const int sub_pel_filters_inv_tap_4[8][2] =
-{
-    {          0,          0},
-    { 0x007bfffa, 0xffff000c},
-    {          0,          0},
-    { 0x005dfff7, 0xfffa0032},
-    {          0,          0},
-    { 0x0032fffa, 0xfff7005d},
-    {          0,          0},
-    { 0x000cffff, 0xfffa007b},
-};
-
-inline void prefetch_load(unsigned char *src)
-{
-    __asm__ __volatile__ (
-        "pref   0,  0(%[src])   \n\t"
-        :
-        : [src] "r" (src)
-    );
-}
-
-
-inline void prefetch_store(unsigned char *dst)
-{
-    __asm__ __volatile__ (
-        "pref   1,  0(%[dst])   \n\t"
-        :
-        : [dst] "r" (dst)
-    );
-}
-
-void dsputil_static_init(void)
-{
-    int i;
-
-    for (i = 0; i < 256; i++) ff_cropTbl[i + CROP_WIDTH] = i;
-
-    for (i = 0; i < CROP_WIDTH; i++)
-    {
-        ff_cropTbl[i] = 0;
-        ff_cropTbl[i + CROP_WIDTH + 256] = 255;
-    }
-}
-
-void vp8_filter_block2d_first_pass_4
-(
-    unsigned char *RESTRICT src_ptr,
-    unsigned char *RESTRICT dst_ptr,
-    unsigned int src_pixels_per_line,
-    unsigned int output_height,
-    int xoffset,
-    int pitch
-)
-{
-    unsigned int i;
-    int Temp1, Temp2, Temp3, Temp4;
-
-    unsigned int vector4a = 64;
-    int vector1b, vector2b, vector3b;
-    unsigned int tp1, tp2, tn1, tn2;
-    unsigned int p1, p2, p3;
-    unsigned int n1, n2, n3;
-    unsigned char *cm = ff_cropTbl + CROP_WIDTH;
-
-    vector3b = sub_pel_filters_inv[xoffset][2];
-
-    /* if (xoffset == 0) we don't need any filtering */
-    if (vector3b == 0)
-    {
-        for (i = 0; i < output_height; i++)
-        {
-            /* prefetch src_ptr data to cache memory */
-            prefetch_load(src_ptr + src_pixels_per_line);
-            dst_ptr[0] = src_ptr[0];
-            dst_ptr[1] = src_ptr[1];
-            dst_ptr[2] = src_ptr[2];
-            dst_ptr[3] = src_ptr[3];
-
-            /* next row... */
-            src_ptr += src_pixels_per_line;
-            dst_ptr += 4;
-        }
-    }
-    else
-    {
-        if (vector3b > 65536)
-        {
-            /* 6 tap filter */
-
-            vector1b = sub_pel_filters_inv[xoffset][0];
-            vector2b = sub_pel_filters_inv[xoffset][1];
-
-            /* prefetch src_ptr data to cache memory */
-            prefetch_load(src_ptr + src_pixels_per_line);
-
-            for (i = output_height; i--;)
-            {
-                /* apply filter with vectors pairs */
-                __asm__ __volatile__ (
-                    "ulw              %[tp1],      -2(%[src_ptr])                 \n\t"
-                    "ulw              %[tp2],      2(%[src_ptr])                  \n\t"
-
-                    /* even 1. pixel */
-                    "mtlo             %[vector4a], $ac3                           \n\t"
-                    "preceu.ph.qbr    %[p1],       %[tp1]                         \n\t"
-                    "preceu.ph.qbl    %[p2],       %[tp1]                         \n\t"
-                    "preceu.ph.qbr    %[p3],       %[tp2]                         \n\t"
-                    "dpa.w.ph         $ac3,        %[p1],          %[vector1b]    \n\t"
-                    "dpa.w.ph         $ac3,        %[p2],          %[vector2b]    \n\t"
-                    "dpa.w.ph         $ac3,        %[p3],          %[vector3b]    \n\t"
-
-                    /* even 2. pixel */
-                    "mtlo             %[vector4a], $ac2                           \n\t"
-                    "preceu.ph.qbl    %[p1],       %[tp2]                         \n\t"
-                    "balign           %[tp2],      %[tp1],         3              \n\t"
-                    "extp             %[Temp1],    $ac3,           9              \n\t"
-                    "dpa.w.ph         $ac2,        %[p2],          %[vector1b]    \n\t"
-                    "dpa.w.ph         $ac2,        %[p3],          %[vector2b]    \n\t"
-                    "dpa.w.ph         $ac2,        %[p1],          %[vector3b]    \n\t"
-
-                    /* odd 1. pixel */
-                    "ulw              %[tn2],      3(%[src_ptr])                  \n\t"
-                    "mtlo             %[vector4a], $ac3                           \n\t"
-                    "preceu.ph.qbr    %[n1],       %[tp2]                         \n\t"
-                    "preceu.ph.qbl    %[n2],       %[tp2]                         \n\t"
-                    "preceu.ph.qbr    %[n3],       %[tn2]                         \n\t"
-                    "extp             %[Temp3],    $ac2,           9              \n\t"
-                    "dpa.w.ph         $ac3,        %[n1],          %[vector1b]    \n\t"
-                    "dpa.w.ph         $ac3,        %[n2],          %[vector2b]    \n\t"
-                    "dpa.w.ph         $ac3,        %[n3],          %[vector3b]    \n\t"
-
-                    /* even 2. pixel */
-                    "mtlo             %[vector4a], $ac2                           \n\t"
-                    "preceu.ph.qbl    %[n1],       %[tn2]                         \n\t"
-                    "extp             %[Temp2],    $ac3,           9              \n\t"
-                    "dpa.w.ph         $ac2,        %[n2],          %[vector1b]    \n\t"
-                    "dpa.w.ph         $ac2,        %[n3],          %[vector2b]    \n\t"
-                    "dpa.w.ph         $ac2,        %[n1],          %[vector3b]    \n\t"
-                    "extp             %[Temp4],    $ac2,           9              \n\t"
-
-                    /* clamp */
-                    "lbux             %[tp1],      %[Temp1](%[cm])                \n\t"
-                    "lbux             %[tn1],      %[Temp2](%[cm])                \n\t"
-                    "lbux             %[tp2],      %[Temp3](%[cm])                \n\t"
-                    "lbux             %[n2],       %[Temp4](%[cm])                \n\t"
-
-                    /* store bytes */
-                    "sb               %[tp1],      0(%[dst_ptr])                  \n\t"
-                    "sb               %[tn1],      1(%[dst_ptr])                  \n\t"
-                    "sb               %[tp2],      2(%[dst_ptr])                  \n\t"
-                    "sb               %[n2],       3(%[dst_ptr])                  \n\t"
-
-                    : [tp1] "=&r" (tp1), [tp2] "=&r" (tp2), [tn1] "=&r" (tn1),
-                      [tn2] "=&r" (tn2), [p1] "=&r" (p1), [p2] "=&r" (p2),
-                      [p3] "=&r" (p3), [n1] "=&r" (n1), [n2] "=&r" (n2),
-                      [n3] "=&r" (n3), [Temp1] "=&r" (Temp1), [Temp2] "=&r" (Temp2),
-                      [Temp3] "=&r" (Temp3), [Temp4] "=&r" (Temp4)
-                    : [vector1b] "r" (vector1b), [vector2b] "r" (vector2b),
-                      [vector4a] "r" (vector4a), [cm] "r" (cm), [dst_ptr] "r" (dst_ptr),
-                      [vector3b] "r" (vector3b), [src_ptr] "r" (src_ptr)
-                );
-
-                /* Next row... */
-                src_ptr += src_pixels_per_line;
-                dst_ptr += pitch;
-            }
-        }
-        else
-        {
-            /* 4 tap filter */
-
-            vector1b = sub_pel_filters_inv_tap_4[xoffset][0];
-            vector2b = sub_pel_filters_inv_tap_4[xoffset][1];
-
-            for (i = output_height; i--;)
-            {
-                /* apply filter with vectors pairs */
-                __asm__ __volatile__ (
-                    "ulw              %[tp1],      -1(%[src_ptr])                 \n\t"
-                    "ulw              %[tp2],      3(%[src_ptr])                  \n\t"
-
-                    /* even 1. pixel */
-                    "mtlo             %[vector4a], $ac3                           \n\t"
-                    "preceu.ph.qbr    %[p1],       %[tp1]                         \n\t"
-                    "preceu.ph.qbl    %[p2],       %[tp1]                         \n\t"
-                    "preceu.ph.qbr    %[p3],       %[tp2]                         \n\t"
-                    "dpa.w.ph         $ac3,        %[p1],          %[vector1b]    \n\t"
-                    "dpa.w.ph         $ac3,        %[p2],          %[vector2b]    \n\t"
-
-                    /* even 2. pixel */
-                    "mtlo             %[vector4a], $ac2                           \n\t"
-                    "dpa.w.ph         $ac2,        %[p2],          %[vector1b]    \n\t"
-                    "dpa.w.ph         $ac2,        %[p3],          %[vector2b]    \n\t"
-                    "extp             %[Temp1],    $ac3,           9              \n\t"
-
-                    /* odd 1. pixel */
-                    "srl              %[tn1],      %[tp2],         8              \n\t"
-                    "balign           %[tp2],      %[tp1],         3              \n\t"
-                    "mtlo             %[vector4a], $ac3                           \n\t"
-                    "preceu.ph.qbr    %[n1],       %[tp2]                         \n\t"
-                    "preceu.ph.qbl    %[n2],       %[tp2]                         \n\t"
-                    "preceu.ph.qbr    %[n3],       %[tn1]                         \n\t"
-                    "extp             %[Temp3],    $ac2,           9              \n\t"
-                    "dpa.w.ph         $ac3,        %[n1],          %[vector1b]    \n\t"
-                    "dpa.w.ph         $ac3,        %[n2],          %[vector2b]    \n\t"
-
-                    /* odd 2. pixel */
-                    "mtlo             %[vector4a], $ac2                           \n\t"
-                    "extp             %[Temp2],    $ac3,           9              \n\t"
-                    "dpa.w.ph         $ac2,        %[n2],          %[vector1b]    \n\t"
-                    "dpa.w.ph         $ac2,        %[n3],          %[vector2b]    \n\t"
-                    "extp             %[Temp4],    $ac2,           9              \n\t"
-
-                    /* clamp and store results */
-                    "lbux             %[tp1],      %[Temp1](%[cm])                \n\t"
-                    "lbux             %[tn1],      %[Temp2](%[cm])                \n\t"
-                    "lbux             %[tp2],      %[Temp3](%[cm])                \n\t"
-                    "sb               %[tp1],      0(%[dst_ptr])                  \n\t"
-                    "sb               %[tn1],      1(%[dst_ptr])                  \n\t"
-                    "lbux             %[n2],       %[Temp4](%[cm])                \n\t"
-                    "sb               %[tp2],      2(%[dst_ptr])                  \n\t"
-                    "sb               %[n2],       3(%[dst_ptr])                  \n\t"
-
-                    : [tp1] "=&r" (tp1), [tp2] "=&r" (tp2), [tn1] "=&r" (tn1),
-                      [p1] "=&r" (p1), [p2] "=&r" (p2), [p3] "=&r" (p3),
-                      [n1] "=&r" (n1), [n2] "=&r" (n2), [n3] "=&r" (n3),
-                      [Temp1] "=&r" (Temp1), [Temp2] "=&r" (Temp2),
-                      [Temp3] "=&r" (Temp3), [Temp4] "=&r" (Temp4)
-                    : [vector1b] "r" (vector1b), [vector2b] "r" (vector2b),
-                      [vector4a] "r" (vector4a), [cm] "r" (cm), [dst_ptr] "r" (dst_ptr),
-                      [src_ptr] "r" (src_ptr)
-                );
-                /*  Next row... */
-                src_ptr += src_pixels_per_line;
-                dst_ptr += pitch;
-            }
-        }
-    }
-}
-
-void vp8_filter_block2d_first_pass_8_all
-(
-    unsigned char *RESTRICT src_ptr,
-    unsigned char *RESTRICT dst_ptr,
-    unsigned int src_pixels_per_line,
-    unsigned int output_height,
-    int xoffset,
-    int pitch
-)
-{
-    unsigned int i;
-    int Temp1, Temp2, Temp3, Temp4;
-
-    unsigned int vector4a = 64;
-    unsigned int vector1b, vector2b, vector3b;
-    unsigned int tp1, tp2, tn1, tn2;
-    unsigned int p1, p2, p3, p4;
-    unsigned int n1, n2, n3, n4;
-
-    unsigned char *cm = ff_cropTbl + CROP_WIDTH;
-
-    /* if (xoffset == 0) we don't need any filtering */
-    if (xoffset == 0)
-    {
-        for (i = 0; i < output_height; i++)
-        {
-            /* prefetch src_ptr data to cache memory */
-            prefetch_load(src_ptr + src_pixels_per_line);
-
-            dst_ptr[0] = src_ptr[0];
-            dst_ptr[1] = src_ptr[1];
-            dst_ptr[2] = src_ptr[2];
-            dst_ptr[3] = src_ptr[3];
-            dst_ptr[4] = src_ptr[4];
-            dst_ptr[5] = src_ptr[5];
-            dst_ptr[6] = src_ptr[6];
-            dst_ptr[7] = src_ptr[7];
-
-            /* next row... */
-            src_ptr += src_pixels_per_line;
-            dst_ptr += 8;
-        }
-    }
-    else
-    {
-        vector3b = sub_pel_filters_inv[xoffset][2];
-
-        if (vector3b > 65536)
-        {
-            /* 6 tap filter */
-
-            vector1b = sub_pel_filters_inv[xoffset][0];
-            vector2b = sub_pel_filters_inv[xoffset][1];
-
-            for (i = output_height; i--;)
-            {
-                /* prefetch src_ptr data to cache memory */
-                prefetch_load(src_ptr + src_pixels_per_line);
-
-                /* apply filter with vectors pairs */
-                __asm__ __volatile__ (
-                    "ulw              %[tp1],      -2(%[src_ptr])                 \n\t"
-                    "ulw              %[tp2],      2(%[src_ptr])                  \n\t"
-
-                    /* even 1. pixel */
-                    "mtlo             %[vector4a], $ac3                           \n\t"
-                    "preceu.ph.qbr    %[p1],       %[tp1]                         \n\t"
-                    "preceu.ph.qbl    %[p2],       %[tp1]                         \n\t"
-                    "preceu.ph.qbr    %[p3],       %[tp2]                         \n\t"
-                    "dpa.w.ph         $ac3,        %[p1],          %[vector1b]    \n\t"
-                    "dpa.w.ph         $ac3,        %[p2],          %[vector2b]    \n\t"
-                    "dpa.w.ph         $ac3,        %[p3],          %[vector3b]    \n\t"
-
-                    /* even 2. pixel */
-                    "mtlo             %[vector4a], $ac2                           \n\t"
-                    "preceu.ph.qbl    %[p1],       %[tp2]                         \n\t"
-                    "dpa.w.ph         $ac2,        %[p2],          %[vector1b]    \n\t"
-                    "dpa.w.ph         $ac2,        %[p3],          %[vector2b]    \n\t"
-                    "dpa.w.ph         $ac2,        %[p1],          %[vector3b]    \n\t"
-
-                    "balign           %[tp2],      %[tp1],         3              \n\t"
-                    "extp             %[Temp1],    $ac3,           9              \n\t"
-                    "ulw              %[tn2],      3(%[src_ptr])                  \n\t"
-
-                    /* odd 1. pixel */
-                    "mtlo             %[vector4a], $ac3                           \n\t"
-                    "preceu.ph.qbr    %[n1],       %[tp2]                         \n\t"
-                    "preceu.ph.qbl    %[n2],       %[tp2]                         \n\t"
-                    "preceu.ph.qbr    %[n3],       %[tn2]                         \n\t"
-                    "extp             %[Temp3],    $ac2,           9              \n\t"
-                    "dpa.w.ph         $ac3,        %[n1],          %[vector1b]    \n\t"
-                    "dpa.w.ph         $ac3,        %[n2],          %[vector2b]    \n\t"
-                    "dpa.w.ph         $ac3,        %[n3],          %[vector3b]    \n\t"
-
-                    /* odd 2. pixel */
-                    "mtlo             %[vector4a], $ac2                           \n\t"
-                    "preceu.ph.qbl    %[n1],       %[tn2]                         \n\t"
-                    "dpa.w.ph         $ac2,        %[n2],          %[vector1b]    \n\t"
-                    "dpa.w.ph         $ac2,        %[n3],          %[vector2b]    \n\t"
-                    "dpa.w.ph         $ac2,        %[n1],          %[vector3b]    \n\t"
-                    "ulw              %[tp1],      6(%[src_ptr])                  \n\t"
-                    "extp             %[Temp2],    $ac3,           9              \n\t"
-                    "mtlo             %[vector4a], $ac3                           \n\t"
-                    "preceu.ph.qbr    %[p2],       %[tp1]                         \n\t"
-                    "extp             %[Temp4],    $ac2,           9              \n\t"
-
-                    : [tp1] "=&r" (tp1), [tp2] "=&r" (tp2), [tn2] "=&r" (tn2),
-                      [p1] "=&r" (p1), [p2] "=&r" (p2), [p3] "=&r" (p3),
-                      [n1] "=&r" (n1), [n2] "=&r" (n2), [n3] "=&r" (n3),
-                      [Temp1] "=&r" (Temp1), [Temp2] "=&r" (Temp2),
-                      [Temp3] "=&r" (Temp3), [Temp4] "=r" (Temp4)
-                    : [vector1b] "r" (vector1b), [vector2b] "r" (vector2b),
-                      [vector4a] "r" (vector4a), [vector3b] "r" (vector3b),
-                      [src_ptr] "r" (src_ptr)
-                );
-
-                /* clamp and store results */
-                dst_ptr[0] = cm[Temp1];
-                dst_ptr[1] = cm[Temp2];
-                dst_ptr[2] = cm[Temp3];
-                dst_ptr[3] = cm[Temp4];
-
-                /* next 4 pixels */
-                __asm__ __volatile__ (
-                    /* even 3. pixel */
-                    "dpa.w.ph         $ac3,        %[p3],          %[vector1b]    \n\t"
-                    "dpa.w.ph         $ac3,        %[p1],          %[vector2b]    \n\t"
-                    "dpa.w.ph         $ac3,        %[p2],          %[vector3b]    \n\t"
-
-                    /* even 4. pixel */
-                    "mtlo             %[vector4a], $ac2                           \n\t"
-                    "preceu.ph.qbl    %[p4],       %[tp1]                         \n\t"
-                    "dpa.w.ph         $ac2,        %[p1],          %[vector1b]    \n\t"
-                    "dpa.w.ph         $ac2,        %[p2],          %[vector2b]    \n\t"
-                    "dpa.w.ph         $ac2,        %[p4],          %[vector3b]    \n\t"
-
-                    "ulw              %[tn1],      7(%[src_ptr])                  \n\t"
-                    "extp             %[Temp1],    $ac3,           9              \n\t"
-
-                    /* odd 3. pixel */
-                    "mtlo             %[vector4a], $ac3                           \n\t"
-                    "preceu.ph.qbr    %[n2],       %[tn1]                         \n\t"
-                    "dpa.w.ph         $ac3,        %[n3],          %[vector1b]    \n\t"
-                    "dpa.w.ph         $ac3,        %[n1],          %[vector2b]    \n\t"
-                    "dpa.w.ph         $ac3,        %[n2],          %[vector3b]    \n\t"
-                    "extp             %[Temp3],    $ac2,           9              \n\t"
-
-                    /* odd 4. pixel */
-                    "mtlo             %[vector4a], $ac2                           \n\t"
-                    "preceu.ph.qbl    %[n4],       %[tn1]                         \n\t"
-                    "dpa.w.ph         $ac2,        %[n1],          %[vector1b]    \n\t"
-                    "dpa.w.ph         $ac2,        %[n2],          %[vector2b]    \n\t"
-                    "dpa.w.ph         $ac2,        %[n4],          %[vector3b]    \n\t"
-                    "extp             %[Temp2],    $ac3,           9              \n\t"
-                    "extp             %[Temp4],    $ac2,           9              \n\t"
-
-                    : [tn1] "=&r" (tn1), [n2] "=&r" (n2),
-                      [p4] "=&r" (p4), [n4] "=&r" (n4),
-                      [Temp1] "=&r" (Temp1), [Temp2] "=&r" (Temp2),
-                      [Temp3] "=&r" (Temp3), [Temp4] "=r" (Temp4)
-                    : [tp1] "r" (tp1), [vector1b] "r" (vector1b), [p2] "r" (p2),
-                      [vector2b] "r" (vector2b), [n1] "r" (n1), [p1] "r" (p1),
-                      [vector4a] "r" (vector4a), [vector3b] "r" (vector3b),
-                      [p3] "r" (p3), [n3] "r" (n3), [src_ptr] "r" (src_ptr)
-                );
-
-                /* clamp and store results */
-                dst_ptr[4] = cm[Temp1];
-                dst_ptr[5] = cm[Temp2];
-                dst_ptr[6] = cm[Temp3];
-                dst_ptr[7] = cm[Temp4];
-
-                src_ptr += src_pixels_per_line;
-                dst_ptr += pitch;
-            }
-        }
-        else
-        {
-            /* 4 tap filter */
-
-            vector1b = sub_pel_filters_inv_tap_4[xoffset][0];
-            vector2b = sub_pel_filters_inv_tap_4[xoffset][1];
-
-            for (i = output_height; i--;)
-            {
-                /* prefetch src_ptr data to cache memory */
-                prefetch_load(src_ptr + src_pixels_per_line);
-
-                /* apply filter with vectors pairs */
-                __asm__ __volatile__ (
-                    "ulw              %[tp1],      -1(%[src_ptr])                 \n\t"
-
-                    /* even 1. pixel */
-                    "mtlo             %[vector4a], $ac3                           \n\t"
-                    "preceu.ph.qbr    %[p1],       %[tp1]                         \n\t"
-                    "preceu.ph.qbl    %[p2],       %[tp1]                         \n\t"
-                    "dpa.w.ph         $ac3,        %[p1],          %[vector1b]    \n\t"
-                    "dpa.w.ph         $ac3,        %[p2],          %[vector2b]    \n\t"
-
-                    "ulw              %[tp2],      3(%[src_ptr])                  \n\t"
-
-                    /* even 2. pixel  */
-                    "mtlo             %[vector4a], $ac2                           \n\t"
-                    "preceu.ph.qbr    %[p3],       %[tp2]                         \n\t"
-                    "preceu.ph.qbl    %[p4],       %[tp2]                         \n\t"
-                    "dpa.w.ph         $ac2,        %[p2],          %[vector1b]    \n\t"
-                    "dpa.w.ph         $ac2,        %[p3],          %[vector2b]    \n\t"
-                    "extp             %[Temp1],    $ac3,           9              \n\t"
-
-                    "balign           %[tp2],      %[tp1],         3              \n\t"
-
-                    /* odd 1. pixel */
-                    "mtlo             %[vector4a], $ac3                           \n\t"
-                    "preceu.ph.qbr    %[n1],       %[tp2]                         \n\t"
-                    "preceu.ph.qbl    %[n2],       %[tp2]                         \n\t"
-                    "dpa.w.ph         $ac3,        %[n1],          %[vector1b]    \n\t"
-                    "dpa.w.ph         $ac3,        %[n2],          %[vector2b]    \n\t"
-                    "extp             %[Temp3],    $ac2,           9              \n\t"
-
-                    "ulw              %[tn2],      4(%[src_ptr])                  \n\t"
-
-                    /* odd 2. pixel */
-                    "mtlo             %[vector4a], $ac2                           \n\t"
-                    "preceu.ph.qbr    %[n3],       %[tn2]                         \n\t"
-                    "preceu.ph.qbl    %[n4],       %[tn2]                         \n\t"
-                    "dpa.w.ph         $ac2,        %[n2],          %[vector1b]    \n\t"
-                    "dpa.w.ph         $ac2,        %[n3],          %[vector2b]    \n\t"
-                    "ulw              %[tp1],      7(%[src_ptr])                  \n\t"
-                    "extp             %[Temp2],    $ac3,           9              \n\t"
-                    "mtlo             %[vector4a], $ac3                           \n\t"
-                    "extp             %[Temp4],    $ac2,           9              \n\t"
-
-                    : [tp1] "=&r" (tp1), [tp2] "=&r" (tp2),
-                      [tn2] "=&r" (tn2), [p1] "=&r" (p1), [p2] "=&r" (p2),
-                      [p3] "=&r" (p3), [p4] "=&r" (p4), [n1] "=&r" (n1),
-                      [n2] "=&r" (n2), [n3] "=&r" (n3), [n4] "=&r" (n4),
-                      [Temp1] "=&r" (Temp1), [Temp2] "=&r" (Temp2),
-                      [Temp3] "=&r" (Temp3), [Temp4] "=r" (Temp4)
-                    : [vector1b] "r" (vector1b), [vector2b] "r" (vector2b),
-                      [vector4a] "r" (vector4a), [src_ptr] "r" (src_ptr)
-                );
-
-                /* clamp and store results */
-                dst_ptr[0] = cm[Temp1];
-                dst_ptr[1] = cm[Temp2];
-                dst_ptr[2] = cm[Temp3];
-                dst_ptr[3] = cm[Temp4];
-
-                /* next 4 pixels */
-                __asm__ __volatile__ (
-                    /* even 3. pixel */
-                    "dpa.w.ph         $ac3,        %[p3],          %[vector1b]    \n\t"
-                    "dpa.w.ph         $ac3,        %[p4],          %[vector2b]    \n\t"
-
-                    /* even 4. pixel */
-                    "mtlo             %[vector4a], $ac2                           \n\t"
-                    "preceu.ph.qbr    %[p2],       %[tp1]                         \n\t"
-                    "dpa.w.ph         $ac2,        %[p4],          %[vector1b]    \n\t"
-                    "dpa.w.ph         $ac2,        %[p2],          %[vector2b]    \n\t"
-                    "extp             %[Temp1],    $ac3,           9              \n\t"
-
-                    /* odd 3. pixel */
-                    "mtlo             %[vector4a], $ac3                           \n\t"
-                    "dpa.w.ph         $ac3,        %[n3],          %[vector1b]    \n\t"
-                    "dpa.w.ph         $ac3,        %[n4],          %[vector2b]    \n\t"
-                    "ulw              %[tn1],      8(%[src_ptr])                  \n\t"
-                    "extp             %[Temp3],    $ac2,           9              \n\t"
-
-                    /* odd 4. pixel */
-                    "mtlo             %[vector4a], $ac2                           \n\t"
-                    "preceu.ph.qbr    %[n2],       %[tn1]                         \n\t"
-                    "dpa.w.ph         $ac2,        %[n4],          %[vector1b]    \n\t"
-                    "dpa.w.ph         $ac2,        %[n2],          %[vector2b]    \n\t"
-                    "extp             %[Temp2],    $ac3,           9              \n\t"
-                    "extp             %[Temp4],    $ac2,           9              \n\t"
-
-                    : [tn1] "=&r" (tn1), [p2] "=&r" (p2), [n2] "=&r" (n2),
-                      [Temp1] "=&r" (Temp1), [Temp2] "=&r" (Temp2),
-                      [Temp3] "=&r" (Temp3), [Temp4] "=r" (Temp4)
-                    : [tp1] "r" (tp1), [p3] "r" (p3), [p4] "r" (p4),
-                      [vector1b] "r" (vector1b), [vector2b] "r" (vector2b),
-                      [vector4a] "r" (vector4a), [src_ptr] "r" (src_ptr),
-                      [n3] "r" (n3), [n4] "r" (n4)
-                );
-
-                /* clamp and store results */
-                dst_ptr[4] = cm[Temp1];
-                dst_ptr[5] = cm[Temp2];
-                dst_ptr[6] = cm[Temp3];
-                dst_ptr[7] = cm[Temp4];
-
-                /* next row... */
-                src_ptr += src_pixels_per_line;
-                dst_ptr += pitch;
-            }
-        }
-    }
-}
-
-
-void vp8_filter_block2d_first_pass16_6tap
-(
-    unsigned char *RESTRICT src_ptr,
-    unsigned char *RESTRICT dst_ptr,
-    unsigned int src_pixels_per_line,
-    unsigned int output_height,
-    int xoffset,
-    int pitch
-)
-{
-    unsigned int i;
-    int Temp1, Temp2, Temp3, Temp4;
-
-    unsigned int vector4a;
-    unsigned int vector1b, vector2b, vector3b;
-    unsigned int tp1, tp2, tn1, tn2;
-    unsigned int p1, p2, p3, p4;
-    unsigned int n1, n2, n3, n4;
-    unsigned char *cm = ff_cropTbl + CROP_WIDTH;
-
-    vector1b = sub_pel_filters_inv[xoffset][0];
-    vector2b = sub_pel_filters_inv[xoffset][1];
-    vector3b = sub_pel_filters_inv[xoffset][2];
-    vector4a = 64;
-
-    for (i = output_height; i--;)
-    {
-        /* prefetch src_ptr data to cache memory */
-        prefetch_load(src_ptr + src_pixels_per_line);
-
-        /* apply filter with vectors pairs */
-        __asm__ __volatile__ (
-            "ulw                %[tp1],      -2(%[src_ptr])                 \n\t"
-            "ulw                %[tp2],      2(%[src_ptr])                  \n\t"
-
-            /* even 1. pixel */
-            "mtlo               %[vector4a], $ac3                           \n\t"
-            "preceu.ph.qbr      %[p1],       %[tp1]                         \n\t"
-            "preceu.ph.qbl      %[p2],       %[tp1]                         \n\t"
-            "preceu.ph.qbr      %[p3],       %[tp2]                         \n\t"
-            "dpa.w.ph           $ac3,        %[p1],           %[vector1b]   \n\t"
-            "dpa.w.ph           $ac3,        %[p2],           %[vector2b]   \n\t"
-            "dpa.w.ph           $ac3,        %[p3],           %[vector3b]   \n\t"
-
-            /* even 2. pixel */
-            "mtlo               %[vector4a], $ac2                           \n\t"
-            "preceu.ph.qbl      %[p1],       %[tp2]                         \n\t"
-            "dpa.w.ph           $ac2,        %[p2],           %[vector1b]   \n\t"
-            "dpa.w.ph           $ac2,        %[p3],           %[vector2b]   \n\t"
-            "dpa.w.ph           $ac2,        %[p1],           %[vector3b]   \n\t"
-
-            "balign             %[tp2],      %[tp1],          3             \n\t"
-            "ulw                %[tn2],      3(%[src_ptr])                  \n\t"
-            "extp               %[Temp1],    $ac3,            9             \n\t"
-
-            /* odd 1. pixel */
-            "mtlo               %[vector4a], $ac3                           \n\t"
-            "preceu.ph.qbr      %[n1],       %[tp2]                         \n\t"
-            "preceu.ph.qbl      %[n2],       %[tp2]                         \n\t"
-            "preceu.ph.qbr      %[n3],       %[tn2]                         \n\t"
-            "extp               %[Temp3],    $ac2,            9             \n\t"
-            "dpa.w.ph           $ac3,        %[n1],           %[vector1b]   \n\t"
-            "dpa.w.ph           $ac3,        %[n2],           %[vector2b]   \n\t"
-            "dpa.w.ph           $ac3,        %[n3],           %[vector3b]   \n\t"
-
-            /* odd 2. pixel */
-            "mtlo               %[vector4a], $ac2                           \n\t"
-            "preceu.ph.qbl      %[n1],       %[tn2]                         \n\t"
-            "dpa.w.ph           $ac2,        %[n2],           %[vector1b]   \n\t"
-            "dpa.w.ph           $ac2,        %[n3],           %[vector2b]   \n\t"
-            "dpa.w.ph           $ac2,        %[n1],           %[vector3b]   \n\t"
-            "ulw                %[tp1],      6(%[src_ptr])                  \n\t"
-            "extp               %[Temp2],    $ac3,            9             \n\t"
-            "mtlo               %[vector4a], $ac3                           \n\t"
-            "preceu.ph.qbr      %[p2],       %[tp1]                         \n\t"
-            "extp               %[Temp4],    $ac2,            9             \n\t"
-
-            : [tp1] "=&r" (tp1), [tp2] "=&r" (tp2), [tn2] "=&r" (tn2),
-              [p1] "=&r" (p1), [p2] "=&r" (p2), [p3] "=&r" (p3),
-              [n1] "=&r" (n1), [n2] "=&r" (n2), [n3] "=&r" (n3),
-              [Temp1] "=&r" (Temp1), [Temp2] "=&r" (Temp2),
-              [Temp3] "=&r" (Temp3), [Temp4] "=r" (Temp4)
-            : [vector1b] "r" (vector1b), [vector2b] "r" (vector2b),
-              [vector4a] "r" (vector4a), [vector3b] "r" (vector3b),
-              [src_ptr] "r" (src_ptr)
-        );
-
-        /* clamp and store results */
-        dst_ptr[0] = cm[Temp1];
-        dst_ptr[1] = cm[Temp2];
-        dst_ptr[2] = cm[Temp3];
-        dst_ptr[3] = cm[Temp4];
-
-        /* next 4 pixels */
-        __asm__ __volatile__ (
-            /* even 3. pixel */
-            "dpa.w.ph           $ac3,        %[p3],           %[vector1b]   \n\t"
-            "dpa.w.ph           $ac3,        %[p1],           %[vector2b]   \n\t"
-            "dpa.w.ph           $ac3,        %[p2],           %[vector3b]   \n\t"
-
-            /* even 4. pixel */
-            "mtlo               %[vector4a], $ac2                           \n\t"
-            "preceu.ph.qbl      %[p4],       %[tp1]                         \n\t"
-            "dpa.w.ph           $ac2,        %[p1],           %[vector1b]   \n\t"
-            "dpa.w.ph           $ac2,        %[p2],           %[vector2b]   \n\t"
-            "dpa.w.ph           $ac2,        %[p4],           %[vector3b]   \n\t"
-            "ulw                %[tn1],      7(%[src_ptr])                  \n\t"
-            "extp               %[Temp1],    $ac3,            9             \n\t"
-
-            /* odd 3. pixel */
-            "mtlo               %[vector4a], $ac3                           \n\t"
-            "preceu.ph.qbr      %[n2],       %[tn1]                         \n\t"
-            "dpa.w.ph           $ac3,        %[n3],           %[vector1b]   \n\t"
-            "dpa.w.ph           $ac3,        %[n1],           %[vector2b]   \n\t"
-            "dpa.w.ph           $ac3,        %[n2],           %[vector3b]   \n\t"
-            "extp               %[Temp3],    $ac2,            9             \n\t"
-
-            /* odd 4. pixel */
-            "mtlo               %[vector4a], $ac2                           \n\t"
-            "preceu.ph.qbl      %[n4],       %[tn1]                         \n\t"
-            "dpa.w.ph           $ac2,        %[n1],           %[vector1b]   \n\t"
-            "dpa.w.ph           $ac2,        %[n2],           %[vector2b]   \n\t"
-            "dpa.w.ph           $ac2,        %[n4],           %[vector3b]   \n\t"
-            "ulw                %[tp2],      10(%[src_ptr])                 \n\t"
-            "extp               %[Temp2],    $ac3,            9             \n\t"
-            "mtlo               %[vector4a], $ac3                           \n\t"
-            "preceu.ph.qbr      %[p1],       %[tp2]                         \n\t"
-            "extp               %[Temp4],    $ac2,            9             \n\t"
-
-            : [tn1] "=&r" (tn1), [tp2] "=&r" (tp2), [n2] "=&r" (n2),
-              [p4] "=&r" (p4), [n4] "=&r" (n4),
-              [Temp1] "=&r" (Temp1), [Temp2] "=&r" (Temp2),
-              [Temp3] "=&r" (Temp3), [Temp4] "=r" (Temp4)
-            : [vector1b] "r" (vector1b), [vector2b] "r" (vector2b),
-              [tp1] "r" (tp1), [n1] "r" (n1), [p1] "r" (p1),
-              [vector4a] "r" (vector4a), [p2] "r" (p2), [vector3b] "r" (vector3b),
-              [p3] "r" (p3), [n3] "r" (n3), [src_ptr] "r" (src_ptr)
-        );
-
-        /* clamp and store results */
-        dst_ptr[4] = cm[Temp1];
-        dst_ptr[5] = cm[Temp2];
-        dst_ptr[6] = cm[Temp3];
-        dst_ptr[7] = cm[Temp4];
-
-        /* next 4 pixels */
-        __asm__ __volatile__ (
-            /* even 5. pixel */
-            "dpa.w.ph           $ac3,        %[p2],           %[vector1b]   \n\t"
-            "dpa.w.ph           $ac3,        %[p4],           %[vector2b]   \n\t"
-            "dpa.w.ph           $ac3,        %[p1],           %[vector3b]   \n\t"
-
-            /* even 6. pixel */
-            "mtlo               %[vector4a], $ac2                           \n\t"
-            "preceu.ph.qbl      %[p3],       %[tp2]                         \n\t"
-            "dpa.w.ph           $ac2,        %[p4],           %[vector1b]   \n\t"
-            "dpa.w.ph           $ac2,        %[p1],           %[vector2b]   \n\t"
-            "dpa.w.ph           $ac2,        %[p3],           %[vector3b]   \n\t"
-
-            "ulw                %[tn1],      11(%[src_ptr])                 \n\t"
-            "extp               %[Temp1],    $ac3,            9             \n\t"
-
-            /* odd 5. pixel */
-            "mtlo               %[vector4a], $ac3                           \n\t"
-            "preceu.ph.qbr      %[n1],       %[tn1]                         \n\t"
-            "dpa.w.ph           $ac3,        %[n2],           %[vector1b]   \n\t"
-            "dpa.w.ph           $ac3,        %[n4],           %[vector2b]   \n\t"
-            "dpa.w.ph           $ac3,        %[n1],           %[vector3b]   \n\t"
-            "extp               %[Temp3],    $ac2,            9             \n\t"
-
-            /* odd 6. pixel */
-            "mtlo               %[vector4a], $ac2                           \n\t"
-            "preceu.ph.qbl      %[n3],       %[tn1]                         \n\t"
-            "dpa.w.ph           $ac2,        %[n4],           %[vector1b]   \n\t"
-            "dpa.w.ph           $ac2,        %[n1],           %[vector2b]   \n\t"
-            "dpa.w.ph           $ac2,        %[n3],           %[vector3b]   \n\t"
-            "ulw                %[tp1],      14(%[src_ptr])                 \n\t"
-            "extp               %[Temp2],    $ac3,            9             \n\t"
-            "mtlo               %[vector4a], $ac3                           \n\t"
-            "preceu.ph.qbr      %[p4],       %[tp1]                         \n\t"
-            "extp               %[Temp4],    $ac2,            9             \n\t"
-
-            : [tn1] "=&r" (tn1), [tp1] "=&r" (tp1),
-              [n1] "=&r" (n1), [p3] "=&r" (p3), [n3] "=&r" (n3),
-              [Temp1] "=&r" (Temp1), [Temp2] "=&r" (Temp2),
-              [Temp3] "=&r" (Temp3), [Temp4] "=r" (Temp4)
-            : [vector1b] "r" (vector1b), [vector2b] "r" (vector2b),
-              [tp2] "r" (tp2), [p2] "r" (p2), [n2] "r" (n2),
-              [p4] "r" (p4), [n4] "r" (n4), [p1] "r" (p1), [src_ptr] "r" (src_ptr),
-              [vector4a] "r" (vector4a), [vector3b] "r" (vector3b)
-        );
-
-        /* clamp and store results */
-        dst_ptr[8] = cm[Temp1];
-        dst_ptr[9] = cm[Temp2];
-        dst_ptr[10] = cm[Temp3];
-        dst_ptr[11] = cm[Temp4];
-
-        /* next 4 pixels */
-        __asm__ __volatile__ (
-            /* even 7. pixel */
-            "dpa.w.ph           $ac3,        %[p1],           %[vector1b]   \n\t"
-            "dpa.w.ph           $ac3,        %[p3],           %[vector2b]   \n\t"
-            "dpa.w.ph           $ac3,        %[p4],           %[vector3b]   \n\t"
-
-            /* even 8. pixel */
-            "mtlo               %[vector4a], $ac2                           \n\t"
-            "preceu.ph.qbl      %[p2],       %[tp1]                         \n\t"
-            "dpa.w.ph           $ac2,        %[p3],           %[vector1b]   \n\t"
-            "dpa.w.ph           $ac2,        %[p4],           %[vector2b]   \n\t"
-            "dpa.w.ph           $ac2,        %[p2],           %[vector3b]   \n\t"
-            "ulw                %[tn1],      15(%[src_ptr])                 \n\t"
-            "extp               %[Temp1],    $ac3,            9             \n\t"
-
-            /* odd 7. pixel */
-            "mtlo               %[vector4a], $ac3                           \n\t"
-            "preceu.ph.qbr      %[n4],       %[tn1]                         \n\t"
-            "dpa.w.ph           $ac3,        %[n1],           %[vector1b]   \n\t"
-            "dpa.w.ph           $ac3,        %[n3],           %[vector2b]   \n\t"
-            "dpa.w.ph           $ac3,        %[n4],           %[vector3b]   \n\t"
-            "extp               %[Temp3],    $ac2,            9             \n\t"
-
-            /* odd 8. pixel */
-            "mtlo               %[vector4a], $ac2                           \n\t"
-            "preceu.ph.qbl      %[n2],       %[tn1]                         \n\t"
-            "dpa.w.ph           $ac2,        %[n3],           %[vector1b]   \n\t"
-            "dpa.w.ph           $ac2,        %[n4],           %[vector2b]   \n\t"
-            "dpa.w.ph           $ac2,        %[n2],           %[vector3b]   \n\t"
-            "extp               %[Temp2],    $ac3,            9             \n\t"
-            "extp               %[Temp4],    $ac2,            9             \n\t"
-
-            /* clamp and store results */
-            "lbux               %[tp1],      %[Temp1](%[cm])                \n\t"
-            "lbux               %[tn1],      %[Temp2](%[cm])                \n\t"
-            "lbux               %[p2],       %[Temp3](%[cm])                \n\t"
-            "sb                 %[tp1],      12(%[dst_ptr])                 \n\t"
-            "sb                 %[tn1],      13(%[dst_ptr])                 \n\t"
-            "lbux               %[n2],       %[Temp4](%[cm])                \n\t"
-            "sb                 %[p2],       14(%[dst_ptr])                 \n\t"
-            "sb                 %[n2],       15(%[dst_ptr])                 \n\t"
-
-            : [tn1] "=&r" (tn1), [p2] "=&r" (p2), [n2] "=&r" (n2), [n4] "=&r" (n4),
-              [Temp1] "=&r" (Temp1), [Temp2] "=&r" (Temp2),
-              [Temp3] "=&r" (Temp3), [Temp4] "=r" (Temp4)
-            : [vector1b] "r" (vector1b), [vector2b] "r" (vector2b),
-              [tp1] "r" (tp1), [p4] "r" (p4), [n1] "r" (n1), [p1] "r" (p1),
-              [vector4a] "r" (vector4a), [vector3b] "r" (vector3b), [p3] "r" (p3),
-              [n3] "r" (n3), [src_ptr] "r" (src_ptr),
-              [cm] "r" (cm), [dst_ptr] "r" (dst_ptr)
-        );
-
-        src_ptr += src_pixels_per_line;
-        dst_ptr += pitch;
-    }
-}
-
-
-void vp8_filter_block2d_first_pass16_0
-(
-    unsigned char *RESTRICT src_ptr,
-    unsigned char *RESTRICT output_ptr,
-    unsigned int src_pixels_per_line
-)
-{
-    int Temp1, Temp2, Temp3, Temp4;
-    int i;
-
-    /* prefetch src_ptr data to cache memory */
-    prefetch_store(output_ptr + 32);
-
-    /* copy memory from src buffer to dst buffer */
-    for (i = 0; i < 7; i++)
-    {
-        __asm__ __volatile__ (
-            "ulw    %[Temp1],   0(%[src_ptr])                               \n\t"
-            "ulw    %[Temp2],   4(%[src_ptr])                               \n\t"
-            "ulw    %[Temp3],   8(%[src_ptr])                               \n\t"
-            "ulw    %[Temp4],   12(%[src_ptr])                              \n\t"
-            "sw     %[Temp1],   0(%[output_ptr])                            \n\t"
-            "sw     %[Temp2],   4(%[output_ptr])                            \n\t"
-            "sw     %[Temp3],   8(%[output_ptr])                            \n\t"
-            "sw     %[Temp4],   12(%[output_ptr])                           \n\t"
-            "addu   %[src_ptr], %[src_ptr],        %[src_pixels_per_line]   \n\t"
-
-            : [Temp1] "=&r" (Temp1), [Temp2] "=&r" (Temp2), [Temp3] "=&r" (Temp3),
-              [Temp4] "=&r" (Temp4), [src_ptr] "+r" (src_ptr)
-            : [src_pixels_per_line] "r" (src_pixels_per_line),
-              [output_ptr] "r" (output_ptr)
-        );
-
-        __asm__ __volatile__ (
-            "ulw    %[Temp1],   0(%[src_ptr])                               \n\t"
-            "ulw    %[Temp2],   4(%[src_ptr])                               \n\t"
-            "ulw    %[Temp3],   8(%[src_ptr])                               \n\t"
-            "ulw    %[Temp4],   12(%[src_ptr])                              \n\t"
-            "sw     %[Temp1],   16(%[output_ptr])                           \n\t"
-            "sw     %[Temp2],   20(%[output_ptr])                           \n\t"
-            "sw     %[Temp3],   24(%[output_ptr])                           \n\t"
-            "sw     %[Temp4],   28(%[output_ptr])                           \n\t"
-            "addu   %[src_ptr], %[src_ptr],        %[src_pixels_per_line]   \n\t"
-
-            : [Temp1] "=&r" (Temp1), [Temp2] "=&r" (Temp2), [Temp3] "=&r" (Temp3),
-              [Temp4] "=&r" (Temp4), [src_ptr] "+r" (src_ptr)
-            : [src_pixels_per_line] "r" (src_pixels_per_line),
-              [output_ptr] "r" (output_ptr)
-        );
-
-        __asm__ __volatile__ (
-            "ulw    %[Temp1],   0(%[src_ptr])                               \n\t"
-            "ulw    %[Temp2],   4(%[src_ptr])                               \n\t"
-            "ulw    %[Temp3],   8(%[src_ptr])                               \n\t"
-            "ulw    %[Temp4],   12(%[src_ptr])                              \n\t"
-            "sw     %[Temp1],   32(%[output_ptr])                           \n\t"
-            "sw     %[Temp2],   36(%[output_ptr])                           \n\t"
-            "sw     %[Temp3],   40(%[output_ptr])                           \n\t"
-            "sw     %[Temp4],   44(%[output_ptr])                           \n\t"
-            "addu   %[src_ptr], %[src_ptr],        %[src_pixels_per_line]   \n\t"
-
-            : [Temp1] "=&r" (Temp1), [Temp2] "=&r" (Temp2), [Temp3] "=&r" (Temp3),
-              [Temp4] "=&r" (Temp4), [src_ptr] "+r" (src_ptr)
-            : [src_pixels_per_line] "r" (src_pixels_per_line),
-              [output_ptr] "r" (output_ptr)
-        );
-
-        output_ptr += 48;
-    }
-}
-
-
-void vp8_filter_block2d_first_pass16_4tap
-(
-    unsigned char *RESTRICT src_ptr,
-    unsigned char *RESTRICT output_ptr,
-    unsigned int src_pixels_per_line,
-    unsigned int output_width,
-    unsigned int output_height,
-    int xoffset,
-    int yoffset,
-    unsigned char *RESTRICT dst_ptr,
-    int pitch
-)
-{
-    unsigned int i, j;
-    int Temp1, Temp2, Temp3, Temp4;
-
-    unsigned int vector4a;
-    int vector1b, vector2b;
-    unsigned int tp1, tp2, tp3, tn1;
-    unsigned int p1, p2, p3;
-    unsigned int n1, n2, n3;
-    unsigned char *cm = ff_cropTbl + CROP_WIDTH;
-
-    vector4a = 64;
-
-    vector1b = sub_pel_filters_inv_tap_4[xoffset][0];
-    vector2b = sub_pel_filters_inv_tap_4[xoffset][1];
-
-    /* if (yoffset == 0) don't need temp buffer, data will be stored in dst_ptr */
-    if (yoffset == 0)
-    {
-        output_height -= 5;
-        src_ptr += (src_pixels_per_line + src_pixels_per_line);
-
-        for (i = output_height; i--;)
-        {
-            __asm__ __volatile__ (
-                "ulw     %[tp3],   -1(%[src_ptr])               \n\t"
-                : [tp3] "=&r" (tp3)
-                : [src_ptr] "r" (src_ptr)
-            );
-
-            /* processing 4 adjacent pixels */
-            for (j = 0; j < 16; j += 4)
-            {
-                /* apply filter with vectors pairs */
-                __asm__ __volatile__ (
-                    "ulw              %[tp2],      3(%[src_ptr])                    \n\t"
-                    "move             %[tp1],      %[tp3]                           \n\t"
-
-                    /* even 1. pixel */
-                    "mtlo             %[vector4a], $ac3                             \n\t"
-                    "mthi             $0,          $ac3                             \n\t"
-                    "move             %[tp3],      %[tp2]                           \n\t"
-                    "preceu.ph.qbr    %[p1],       %[tp1]                           \n\t"
-                    "preceu.ph.qbl    %[p2],       %[tp1]                           \n\t"
-                    "preceu.ph.qbr    %[p3],       %[tp2]                           \n\t"
-                    "dpa.w.ph         $ac3,        %[p1],           %[vector1b]     \n\t"
-                    "dpa.w.ph         $ac3,        %[p2],           %[vector2b]     \n\t"
-
-                    /* even 2. pixel */
-                    "mtlo             %[vector4a], $ac2                             \n\t"
-                    "mthi             $0,          $ac2                             \n\t"
-                    "dpa.w.ph         $ac2,        %[p2],           %[vector1b]     \n\t"
-                    "dpa.w.ph         $ac2,        %[p3],           %[vector2b]     \n\t"
-                    "extr.w           %[Temp1],    $ac3,            7               \n\t"
-
-                    /* odd 1. pixel */
-                    "ulw              %[tn1],      4(%[src_ptr])                    \n\t"
-                    "balign           %[tp2],      %[tp1],          3               \n\t"
-                    "mtlo             %[vector4a], $ac3                             \n\t"
-                    "mthi             $0,          $ac3                             \n\t"
-                    "preceu.ph.qbr    %[n1],       %[tp2]                           \n\t"
-                    "preceu.ph.qbl    %[n2],       %[tp2]                           \n\t"
-                    "preceu.ph.qbr    %[n3],       %[tn1]                           \n\t"
-                    "extr.w           %[Temp3],    $ac2,            7               \n\t"
-                    "dpa.w.ph         $ac3,        %[n1],           %[vector1b]     \n\t"
-                    "dpa.w.ph         $ac3,        %[n2],           %[vector2b]     \n\t"
-
-                    /* odd 2. pixel */
-                    "mtlo             %[vector4a], $ac2                             \n\t"
-                    "mthi             $0,          $ac2                             \n\t"
-                    "extr.w           %[Temp2],    $ac3,            7               \n\t"
-                    "dpa.w.ph         $ac2,        %[n2],           %[vector1b]     \n\t"
-                    "dpa.w.ph         $ac2,        %[n3],           %[vector2b]     \n\t"
-                    "extr.w           %[Temp4],    $ac2,            7               \n\t"
-
-                    /* clamp and store results */
-                    "lbux             %[tp1],      %[Temp1](%[cm])                  \n\t"
-                    "lbux             %[tn1],      %[Temp2](%[cm])                  \n\t"
-                    "lbux             %[tp2],      %[Temp3](%[cm])                  \n\t"
-                    "sb               %[tp1],      0(%[dst_ptr])                    \n\t"
-                    "sb               %[tn1],      1(%[dst_ptr])                    \n\t"
-                    "lbux             %[n2],       %[Temp4](%[cm])                  \n\t"
-                    "sb               %[tp2],      2(%[dst_ptr])                    \n\t"
-                    "sb               %[n2],       3(%[dst_ptr])                    \n\t"
-
-                    : [tp1] "=&r" (tp1), [tp2] "=&r" (tp2), [tp3] "=&r" (tp3),
-                      [tn1] "=&r" (tn1), [p1] "=&r" (p1), [p2] "=&r" (p2),
-                      [n1] "=&r" (n1), [n2] "=&r" (n2), [n3] "=&r" (n3),
-                      [Temp1] "=&r" (Temp1), [Temp2] "=&r" (Temp2), [p3] "=&r" (p3),
-                      [Temp3] "=&r" (Temp3), [Temp4] "=&r" (Temp4)
-                    : [vector1b] "r" (vector1b), [vector2b] "r" (vector2b),
-                      [vector4a] "r" (vector4a), [cm] "r" (cm), [dst_ptr] "r" (dst_ptr),
-                      [src_ptr] "r" (src_ptr)
-                );
-
-                src_ptr += 4;
-            }
-
-            /* Next row... */
-            src_ptr += src_pixels_per_line - 16;
-            dst_ptr += pitch;
-        }
-    }
-    else
-    {
-        for (i = output_height; i--;)
-        {
-            /* processing 4 adjacent pixels */
-            for (j = 0; j < 16; j += 4)
-            {
-                /* apply filter with vectors pairs */
-                __asm__ __volatile__ (
-                    "ulw              %[tp1],      -1(%[src_ptr])                   \n\t"
-                    "ulw              %[tp2],      3(%[src_ptr])                    \n\t"
-
-                    /* even 1. pixel */
-                    "mtlo             %[vector4a], $ac3                             \n\t"
-                    "mthi             $0,          $ac3                             \n\t"
-                    "preceu.ph.qbr    %[p1],       %[tp1]                           \n\t"
-                    "preceu.ph.qbl    %[p2],       %[tp1]                           \n\t"
-                    "preceu.ph.qbr    %[p3],       %[tp2]                           \n\t"
-                    "dpa.w.ph         $ac3,        %[p1],           %[vector1b]     \n\t"
-                    "dpa.w.ph         $ac3,        %[p2],           %[vector2b]     \n\t"
-
-                    /* even 2. pixel */
-                    "mtlo             %[vector4a], $ac2                             \n\t"
-                    "mthi             $0,          $ac2                             \n\t"
-                    "dpa.w.ph         $ac2,        %[p2],           %[vector1b]     \n\t"
-                    "dpa.w.ph         $ac2,        %[p3],           %[vector2b]     \n\t"
-                    "extr.w           %[Temp1],    $ac3,            7               \n\t"
-
-                    /* odd 1. pixel */
-                    "ulw              %[tn1],      4(%[src_ptr])                    \n\t"
-                    "balign           %[tp2],      %[tp1],          3               \n\t"
-                    "mtlo             %[vector4a], $ac3                             \n\t"
-                    "mthi             $0,          $ac3                             \n\t"
-                    "preceu.ph.qbr    %[n1],       %[tp2]                           \n\t"
-                    "preceu.ph.qbl    %[n2],       %[tp2]                           \n\t"
-                    "preceu.ph.qbr    %[n3],       %[tn1]                           \n\t"
-                    "extr.w           %[Temp3],    $ac2,            7               \n\t"
-                    "dpa.w.ph         $ac3,        %[n1],           %[vector1b]     \n\t"
-                    "dpa.w.ph         $ac3,        %[n2],           %[vector2b]     \n\t"
-
-                    /* odd 2. pixel */
-                    "mtlo             %[vector4a], $ac2                             \n\t"
-                    "mthi             $0,          $ac2                             \n\t"
-                    "extr.w           %[Temp2],    $ac3,            7               \n\t"
-                    "dpa.w.ph         $ac2,        %[n2],           %[vector1b]     \n\t"
-                    "dpa.w.ph         $ac2,        %[n3],           %[vector2b]     \n\t"
-                    "extr.w           %[Temp4],    $ac2,            7               \n\t"
-
-                    /* clamp and store results */
-                    "lbux             %[tp1],      %[Temp1](%[cm])                  \n\t"
-                    "lbux             %[tn1],      %[Temp2](%[cm])                  \n\t"
-                    "lbux             %[tp2],      %[Temp3](%[cm])                  \n\t"
-                    "sb               %[tp1],      0(%[output_ptr])                 \n\t"
-                    "sb               %[tn1],      1(%[output_ptr])                 \n\t"
-                    "lbux             %[n2],       %[Temp4](%[cm])                  \n\t"
-                    "sb               %[tp2],      2(%[output_ptr])                 \n\t"
-                    "sb               %[n2],       3(%[output_ptr])                 \n\t"
-
-                    : [tp1] "=&r" (tp1), [tp2] "=&r" (tp2), [tn1] "=&r" (tn1),
-                      [p1] "=&r" (p1), [p2] "=&r" (p2), [p3] "=&r" (p3),
-                      [n1] "=&r" (n1), [n2] "=&r" (n2), [n3] "=&r" (n3),
-                      [Temp1] "=&r" (Temp1), [Temp2] "=&r" (Temp2),
-                      [Temp3] "=&r" (Temp3), [Temp4] "=&r" (Temp4)
-                    : [vector1b] "r" (vector1b), [vector2b] "r" (vector2b),
-                      [vector4a] "r" (vector4a), [cm] "r" (cm),
-                      [output_ptr] "r" (output_ptr), [src_ptr] "r" (src_ptr)
-                );
-
-                src_ptr += 4;
-            }
-
-            /* next row... */
-            src_ptr += src_pixels_per_line;
-            output_ptr += output_width;
-        }
-    }
-}
-
-
-void vp8_filter_block2d_second_pass4
-(
-    unsigned char *RESTRICT src_ptr,
-    unsigned char *RESTRICT output_ptr,
-    int output_pitch,
-    int yoffset
-)
-{
-    unsigned int i;
-
-    int Temp1, Temp2, Temp3, Temp4;
-    unsigned int vector1b, vector2b, vector3b, vector4a;
-
-    unsigned char src_ptr_l2;
-    unsigned char src_ptr_l1;
-    unsigned char src_ptr_0;
-    unsigned char src_ptr_r1;
-    unsigned char src_ptr_r2;
-    unsigned char src_ptr_r3;
-
-    unsigned char *cm = ff_cropTbl + CROP_WIDTH;
-
-    vector4a = 64;
-
-    /* load filter coefficients */
-    vector1b = sub_pel_filterss[yoffset][0];
-    vector2b = sub_pel_filterss[yoffset][2];
-    vector3b = sub_pel_filterss[yoffset][1];
-
-    if (vector1b)
-    {
-        /* 6 tap filter */
-
-        for (i = 2; i--;)
-        {
-            /* prefetch src_ptr data to cache memory */
-            prefetch_load(src_ptr);
-
-            /* do not allow compiler to reorder instructions */
-            __asm__ __volatile__ (
-                ".set noreorder                                                 \n\t"
-                :
-                :
-            );
-
-            /* apply filter with vectors pairs */
-            __asm__ __volatile__ (
-                "lbu            %[src_ptr_l2],  -8(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_l1],  -4(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_0],   0(%[src_ptr])                   \n\t"
-                "lbu            %[src_ptr_r1],  4(%[src_ptr])                   \n\t"
-                "lbu            %[src_ptr_r2],  8(%[src_ptr])                   \n\t"
-                "lbu            %[src_ptr_r3],  12(%[src_ptr])                  \n\t"
-                "mtlo           %[vector4a],    $ac2                            \n\t"
-
-                "append         %[src_ptr_l2],  %[src_ptr_r3],  8               \n\t"
-                "append         %[src_ptr_0],   %[src_ptr_r1],  8               \n\t"
-                "append         %[src_ptr_l1],  %[src_ptr_r2],  8               \n\t"
-                "dpau.h.qbr     $ac2,           %[src_ptr_l2],  %[vector1b]     \n\t"
-                "dpau.h.qbr     $ac2,           %[src_ptr_0],   %[vector2b]     \n\t"
-                "dpsu.h.qbr     $ac2,           %[src_ptr_l1],  %[vector3b]     \n\t"
-
-                "lbu            %[src_ptr_l2],  -7(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_l1],  -3(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_0],   1(%[src_ptr])                   \n\t"
-                "lbu            %[src_ptr_r1],  5(%[src_ptr])                   \n\t"
-                "lbu            %[src_ptr_r2],  9(%[src_ptr])                   \n\t"
-                "lbu            %[src_ptr_r3],  13(%[src_ptr])                  \n\t"
-                "mtlo           %[vector4a],    $ac3                            \n\t"
-                "extp           %[Temp1],       $ac2,           9               \n\t"
-
-                "append         %[src_ptr_l2],  %[src_ptr_r3],  8               \n\t"
-                "append         %[src_ptr_0],   %[src_ptr_r1],  8               \n\t"
-                "append         %[src_ptr_l1],  %[src_ptr_r2],  8               \n\t"
-                "dpau.h.qbr     $ac3,           %[src_ptr_l2],  %[vector1b]     \n\t"
-                "dpau.h.qbr     $ac3,           %[src_ptr_0],   %[vector2b]     \n\t"
-                "dpsu.h.qbr     $ac3,           %[src_ptr_l1],  %[vector3b]     \n\t"
-
-                "lbu            %[src_ptr_l2],  -6(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_l1],  -2(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_0],   2(%[src_ptr])                   \n\t"
-                "lbu            %[src_ptr_r1],  6(%[src_ptr])                   \n\t"
-                "lbu            %[src_ptr_r2],  10(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_r3],  14(%[src_ptr])                  \n\t"
-                "mtlo           %[vector4a],    $ac0                            \n\t"
-                "extp           %[Temp2],       $ac3,           9               \n\t"
-
-                "append         %[src_ptr_l2],  %[src_ptr_r3],  8               \n\t"
-                "append         %[src_ptr_0],   %[src_ptr_r1],  8               \n\t"
-                "append         %[src_ptr_l1],  %[src_ptr_r2],  8               \n\t"
-                "dpau.h.qbr     $ac0,           %[src_ptr_l2],  %[vector1b]     \n\t"
-                "dpau.h.qbr     $ac0,           %[src_ptr_0],   %[vector2b]     \n\t"
-                "dpsu.h.qbr     $ac0,           %[src_ptr_l1],  %[vector3b]     \n\t"
-
-                "lbu            %[src_ptr_l2],  -5(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_l1],  -1(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_0],   3(%[src_ptr])                   \n\t"
-                "lbu            %[src_ptr_r1],  7(%[src_ptr])                   \n\t"
-                "lbu            %[src_ptr_r2],  11(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_r3],  15(%[src_ptr])                  \n\t"
-                "mtlo           %[vector4a],    $ac1                            \n\t"
-                "extp           %[Temp3],       $ac0,           9               \n\t"
-
-                "append         %[src_ptr_l2],  %[src_ptr_r3],  8               \n\t"
-                "append         %[src_ptr_0],   %[src_ptr_r1],  8               \n\t"
-                "append         %[src_ptr_l1],  %[src_ptr_r2],  8               \n\t"
-                "dpau.h.qbr     $ac1,           %[src_ptr_l2],  %[vector1b]     \n\t"
-                "dpau.h.qbr     $ac1,           %[src_ptr_0],   %[vector2b]     \n\t"
-                "dpsu.h.qbr     $ac1,           %[src_ptr_l1],  %[vector3b]     \n\t"
-                "extp           %[Temp4],       $ac1,           9               \n\t"
-
-                : [Temp1] "=&r" (Temp1), [Temp2] "=&r" (Temp2),
-                  [Temp3] "=&r" (Temp3), [Temp4] "=r" (Temp4),
-                  [src_ptr_l1] "=&r" (src_ptr_l1), [src_ptr_0] "=&r" (src_ptr_0),
-                  [src_ptr_r1] "=&r" (src_ptr_r1), [src_ptr_r2] "=&r" (src_ptr_r2),
-                  [src_ptr_l2] "=&r" (src_ptr_l2), [src_ptr_r3] "=&r" (src_ptr_r3)
-                : [vector1b] "r" (vector1b), [vector2b] "r" (vector2b),
-                  [vector3b] "r" (vector3b), [vector4a] "r" (vector4a),
-                  [src_ptr] "r" (src_ptr)
-            );
-
-            /* clamp and store results */
-            output_ptr[0] = cm[Temp1];
-            output_ptr[1] = cm[Temp2];
-            output_ptr[2] = cm[Temp3];
-            output_ptr[3] = cm[Temp4];
-
-            output_ptr += output_pitch;
-
-            /* apply filter with vectors pairs */
-            __asm__ __volatile__ (
-                "lbu            %[src_ptr_l2],  -4(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_l1],  0(%[src_ptr])                   \n\t"
-                "lbu            %[src_ptr_0],   4(%[src_ptr])                   \n\t"
-                "lbu            %[src_ptr_r1],  8(%[src_ptr])                   \n\t"
-                "lbu            %[src_ptr_r2],  12(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_r3],  16(%[src_ptr])                  \n\t"
-                "mtlo           %[vector4a],    $ac2                            \n\t"
-                "append         %[src_ptr_l2],  %[src_ptr_r3],  8               \n\t"
-                "append         %[src_ptr_0],   %[src_ptr_r1],  8               \n\t"
-                "append         %[src_ptr_l1],  %[src_ptr_r2],  8               \n\t"
-                "dpau.h.qbr     $ac2,           %[src_ptr_l2],  %[vector1b]     \n\t"
-                "dpau.h.qbr     $ac2,           %[src_ptr_0],   %[vector2b]     \n\t"
-                "dpsu.h.qbr     $ac2,           %[src_ptr_l1],  %[vector3b]     \n\t"
-
-                "lbu            %[src_ptr_l2],  -3(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_l1],  1(%[src_ptr])                   \n\t"
-                "lbu            %[src_ptr_0],   5(%[src_ptr])                   \n\t"
-                "lbu            %[src_ptr_r1],  9(%[src_ptr])                   \n\t"
-                "lbu            %[src_ptr_r2],  13(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_r3],  17(%[src_ptr])                  \n\t"
-                "mtlo           %[vector4a],    $ac3                            \n\t"
-                "extp           %[Temp1],       $ac2,           9               \n\t"
-
-                "append         %[src_ptr_l2],  %[src_ptr_r3],  8               \n\t"
-                "append         %[src_ptr_0],   %[src_ptr_r1],  8               \n\t"
-                "append         %[src_ptr_l1],  %[src_ptr_r2],  8               \n\t"
-                "dpau.h.qbr     $ac3,           %[src_ptr_l2],  %[vector1b]     \n\t"
-                "dpau.h.qbr     $ac3,           %[src_ptr_0],   %[vector2b]     \n\t"
-                "dpsu.h.qbr     $ac3,           %[src_ptr_l1],  %[vector3b]     \n\t"
-
-                "lbu            %[src_ptr_l2],  -2(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_l1],  2(%[src_ptr])                   \n\t"
-                "lbu            %[src_ptr_0],   6(%[src_ptr])                   \n\t"
-                "lbu            %[src_ptr_r1],  10(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_r2],  14(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_r3],  18(%[src_ptr])                  \n\t"
-                "mtlo           %[vector4a],    $ac0                            \n\t"
-                "extp           %[Temp2],       $ac3,           9               \n\t"
-
-                "append         %[src_ptr_l2],  %[src_ptr_r3],  8               \n\t"
-                "append         %[src_ptr_0],   %[src_ptr_r1],  8               \n\t"
-                "append         %[src_ptr_l1],  %[src_ptr_r2],  8               \n\t"
-                "dpau.h.qbr     $ac0,           %[src_ptr_l2],  %[vector1b]     \n\t"
-                "dpau.h.qbr     $ac0,           %[src_ptr_0],   %[vector2b]     \n\t"
-                "dpsu.h.qbr     $ac0,           %[src_ptr_l1],  %[vector3b]     \n\t"
-
-                "lbu            %[src_ptr_l2],  -1(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_l1],  3(%[src_ptr])                   \n\t"
-                "lbu            %[src_ptr_0],   7(%[src_ptr])                   \n\t"
-                "lbu            %[src_ptr_r1],  11(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_r2],  15(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_r3],  19(%[src_ptr])                  \n\t"
-                "mtlo           %[vector4a],    $ac1                            \n\t"
-                "extp           %[Temp3],       $ac0,           9               \n\t"
-
-                "append         %[src_ptr_l2],  %[src_ptr_r3],  8               \n\t"
-                "append         %[src_ptr_0],   %[src_ptr_r1],  8               \n\t"
-                "append         %[src_ptr_l1],  %[src_ptr_r2],  8               \n\t"
-                "dpau.h.qbr     $ac1,           %[src_ptr_l2],  %[vector1b]     \n\t"
-                "dpau.h.qbr     $ac1,           %[src_ptr_0],   %[vector2b]     \n\t"
-                "dpsu.h.qbr     $ac1,           %[src_ptr_l1],  %[vector3b]     \n\t"
-                "extp           %[Temp4],       $ac1,           9               \n\t"
-
-                : [Temp1] "=&r" (Temp1), [Temp2] "=&r" (Temp2),
-                  [Temp3] "=&r" (Temp3), [Temp4] "=r" (Temp4),
-                  [src_ptr_l1] "=&r" (src_ptr_l1), [src_ptr_0] "=&r" (src_ptr_0),
-                  [src_ptr_r1] "=&r" (src_ptr_r1), [src_ptr_r2] "=&r" (src_ptr_r2),
-                  [src_ptr_l2] "=&r" (src_ptr_l2), [src_ptr_r3] "=&r" (src_ptr_r3)
-                : [vector1b] "r" (vector1b), [vector2b] "r" (vector2b),
-                  [vector3b] "r" (vector3b), [vector4a] "r" (vector4a),
-                  [src_ptr] "r" (src_ptr)
-            );
-
-            /* clamp and store results */
-            output_ptr[0] = cm[Temp1];
-            output_ptr[1] = cm[Temp2];
-            output_ptr[2] = cm[Temp3];
-            output_ptr[3] = cm[Temp4];
-
-            src_ptr += 8;
-            output_ptr += output_pitch;
-        }
-    }
-    else
-    {
-        /* 4 tap filter */
-
-        /* prefetch src_ptr data to cache memory */
-        prefetch_load(src_ptr);
-
-        for (i = 2; i--;)
-        {
-            /* do not allow compiler to reorder instructions */
-            __asm__ __volatile__ (
-                ".set noreorder                                                 \n\t"
-                :
-                :
-            );
-
-            /* apply filter with vectors pairs */
-            __asm__ __volatile__ (
-                "lbu            %[src_ptr_l1],  -4(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_0],   0(%[src_ptr])                   \n\t"
-                "lbu            %[src_ptr_r1],  4(%[src_ptr])                   \n\t"
-                "lbu            %[src_ptr_r2],  8(%[src_ptr])                   \n\t"
-                "mtlo           %[vector4a],    $ac2                            \n\t"
-                "append         %[src_ptr_0],   %[src_ptr_r1],  8               \n\t"
-                "append         %[src_ptr_l1],  %[src_ptr_r2],  8               \n\t"
-                "dpau.h.qbr     $ac2,           %[src_ptr_0],   %[vector2b]     \n\t"
-                "dpsu.h.qbr     $ac2,           %[src_ptr_l1],  %[vector3b]     \n\t"
-
-                "lbu            %[src_ptr_l1],  -3(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_0],   1(%[src_ptr])                   \n\t"
-                "lbu            %[src_ptr_r1],  5(%[src_ptr])                   \n\t"
-                "lbu            %[src_ptr_r2],  9(%[src_ptr])                   \n\t"
-                "mtlo           %[vector4a],    $ac3                            \n\t"
-                "extp           %[Temp1],       $ac2,           9               \n\t"
-
-                "append         %[src_ptr_0],   %[src_ptr_r1],  8               \n\t"
-                "append         %[src_ptr_l1],  %[src_ptr_r2],  8               \n\t"
-                "dpau.h.qbr     $ac3,           %[src_ptr_0],   %[vector2b]     \n\t"
-                "dpsu.h.qbr     $ac3,           %[src_ptr_l1],  %[vector3b]     \n\t"
-
-                "lbu            %[src_ptr_l1],  -2(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_0],   2(%[src_ptr])                   \n\t"
-                "lbu            %[src_ptr_r1],  6(%[src_ptr])                   \n\t"
-                "lbu            %[src_ptr_r2],  10(%[src_ptr])                  \n\t"
-                "mtlo           %[vector4a],    $ac0                            \n\t"
-                "extp           %[Temp2],       $ac3,           9               \n\t"
-
-                "append         %[src_ptr_0],   %[src_ptr_r1],  8               \n\t"
-                "append         %[src_ptr_l1],  %[src_ptr_r2],  8               \n\t"
-                "dpau.h.qbr     $ac0,           %[src_ptr_0],   %[vector2b]     \n\t"
-                "dpsu.h.qbr     $ac0,           %[src_ptr_l1],  %[vector3b]     \n\t"
-
-                "lbu            %[src_ptr_l1],  -1(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_0],   3(%[src_ptr])                   \n\t"
-                "lbu            %[src_ptr_r1],  7(%[src_ptr])                   \n\t"
-                "lbu            %[src_ptr_r2],  11(%[src_ptr])                  \n\t"
-                "mtlo           %[vector4a],    $ac1                            \n\t"
-                "extp           %[Temp3],       $ac0,           9               \n\t"
-                "append         %[src_ptr_0],   %[src_ptr_r1],  8               \n\t"
-                "append         %[src_ptr_l1],  %[src_ptr_r2],  8               \n\t"
-                "dpau.h.qbr     $ac1,           %[src_ptr_0],   %[vector2b]     \n\t"
-                "dpsu.h.qbr     $ac1,           %[src_ptr_l1],  %[vector3b]     \n\t"
-                "extp           %[Temp4],       $ac1,           9               \n\t"
-
-                : [Temp1] "=&r" (Temp1), [Temp2] "=&r" (Temp2),
-                  [Temp3] "=&r" (Temp3), [Temp4] "=r" (Temp4),
-                  [src_ptr_l1] "=&r" (src_ptr_l1), [src_ptr_0] "=&r" (src_ptr_0),
-                  [src_ptr_r1] "=&r" (src_ptr_r1), [src_ptr_r2] "=&r" (src_ptr_r2)
-                : [vector2b] "r" (vector2b), [vector3b] "r" (vector3b),
-                  [vector4a] "r" (vector4a), [src_ptr] "r" (src_ptr)
-            );
-
-            /* clamp and store results */
-            output_ptr[0] = cm[Temp1];
-            output_ptr[1] = cm[Temp2];
-            output_ptr[2] = cm[Temp3];
-            output_ptr[3] = cm[Temp4];
-
-            output_ptr += output_pitch;
-
-            /* apply filter with vectors pairs */
-            __asm__ __volatile__ (
-                "lbu            %[src_ptr_l1],  0(%[src_ptr])                   \n\t"
-                "lbu            %[src_ptr_0],   4(%[src_ptr])                   \n\t"
-                "lbu            %[src_ptr_r1],  8(%[src_ptr])                   \n\t"
-                "lbu            %[src_ptr_r2],  12(%[src_ptr])                  \n\t"
-                "mtlo           %[vector4a],    $ac2                            \n\t"
-                "append         %[src_ptr_0],   %[src_ptr_r1],  8               \n\t"
-                "append         %[src_ptr_l1],  %[src_ptr_r2],  8               \n\t"
-                "dpau.h.qbr     $ac2,           %[src_ptr_0],   %[vector2b]     \n\t"
-                "dpsu.h.qbr     $ac2,           %[src_ptr_l1],  %[vector3b]     \n\t"
-
-                "lbu            %[src_ptr_l1],  1(%[src_ptr])                   \n\t"
-                "lbu            %[src_ptr_0],   5(%[src_ptr])                   \n\t"
-                "lbu            %[src_ptr_r1],  9(%[src_ptr])                   \n\t"
-                "lbu            %[src_ptr_r2],  13(%[src_ptr])                  \n\t"
-                "mtlo           %[vector4a],    $ac3                            \n\t"
-                "extp           %[Temp1],       $ac2,           9               \n\t"
-
-                "append         %[src_ptr_0],   %[src_ptr_r1],  8               \n\t"
-                "append         %[src_ptr_l1],  %[src_ptr_r2],  8               \n\t"
-                "dpau.h.qbr     $ac3,           %[src_ptr_0],   %[vector2b]     \n\t"
-                "dpsu.h.qbr     $ac3,           %[src_ptr_l1],  %[vector3b]     \n\t"
-
-                "lbu            %[src_ptr_l1],  2(%[src_ptr])                   \n\t"
-                "lbu            %[src_ptr_0],   6(%[src_ptr])                   \n\t"
-                "lbu            %[src_ptr_r1],  10(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_r2],  14(%[src_ptr])                  \n\t"
-                "mtlo           %[vector4a],    $ac0                            \n\t"
-                "extp           %[Temp2],       $ac3,           9               \n\t"
-
-                "append         %[src_ptr_0],   %[src_ptr_r1],  8               \n\t"
-                "append         %[src_ptr_l1],  %[src_ptr_r2],  8               \n\t"
-                "dpau.h.qbr     $ac0,           %[src_ptr_0],   %[vector2b]     \n\t"
-                "dpsu.h.qbr     $ac0,           %[src_ptr_l1],  %[vector3b]     \n\t"
-
-                "lbu            %[src_ptr_l1],  3(%[src_ptr])                   \n\t"
-                "lbu            %[src_ptr_0],   7(%[src_ptr])                   \n\t"
-                "lbu            %[src_ptr_r1],  11(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_r2],  15(%[src_ptr])                  \n\t"
-                "mtlo           %[vector4a],    $ac1                            \n\t"
-                "extp           %[Temp3],       $ac0,           9               \n\t"
-                "append         %[src_ptr_0],   %[src_ptr_r1],  8               \n\t"
-                "append         %[src_ptr_l1],  %[src_ptr_r2],  8               \n\t"
-                "dpau.h.qbr     $ac1,           %[src_ptr_0],   %[vector2b]     \n\t"
-                "dpsu.h.qbr     $ac1,           %[src_ptr_l1],  %[vector3b]     \n\t"
-                "extp           %[Temp4],       $ac1,           9               \n\t"
-
-                : [Temp1] "=&r" (Temp1), [Temp2] "=&r" (Temp2),
-                  [Temp3] "=&r" (Temp3), [Temp4] "=r" (Temp4),
-                  [src_ptr_l1] "=&r" (src_ptr_l1), [src_ptr_0] "=&r" (src_ptr_0),
-                  [src_ptr_r1] "=&r" (src_ptr_r1), [src_ptr_r2] "=&r" (src_ptr_r2)
-                : [vector2b] "r" (vector2b), [vector3b] "r" (vector3b),
-                  [vector4a] "r" (vector4a), [src_ptr] "r" (src_ptr)
-            );
-
-            /* clamp and store results */
-            output_ptr[0] = cm[Temp1];
-            output_ptr[1] = cm[Temp2];
-            output_ptr[2] = cm[Temp3];
-            output_ptr[3] = cm[Temp4];
-
-            src_ptr += 8;
-            output_ptr += output_pitch;
-        }
-    }
-}
-
-
-void vp8_filter_block2d_second_pass_8
-(
-    unsigned char *RESTRICT src_ptr,
-    unsigned char *RESTRICT output_ptr,
-    int output_pitch,
-    unsigned int output_height,
-    unsigned int output_width,
-    unsigned int yoffset
-)
-{
-    unsigned int i;
-
-    int Temp1, Temp2, Temp3, Temp4, Temp5, Temp6, Temp7, Temp8;
-    unsigned int vector1b, vector2b, vector3b, vector4a;
-
-    unsigned char src_ptr_l2;
-    unsigned char src_ptr_l1;
-    unsigned char src_ptr_0;
-    unsigned char src_ptr_r1;
-    unsigned char src_ptr_r2;
-    unsigned char src_ptr_r3;
-    unsigned char *cm = ff_cropTbl + CROP_WIDTH;
-
-    vector4a = 64;
-
-    vector1b = sub_pel_filterss[yoffset][0];
-    vector2b = sub_pel_filterss[yoffset][2];
-    vector3b = sub_pel_filterss[yoffset][1];
-
-    if (vector1b)
-    {
-        /* 6 tap filter */
-
-        /* prefetch src_ptr data to cache memory */
-        prefetch_load(src_ptr);
-
-        for (i = output_height; i--;)
-        {
-            /* apply filter with vectors pairs */
-            __asm__ __volatile__ (
-                "lbu            %[src_ptr_l2],  -16(%[src_ptr])                 \n\t"
-                "lbu            %[src_ptr_l1],  -8(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_0],   0(%[src_ptr])                   \n\t"
-                "lbu            %[src_ptr_r1],  8(%[src_ptr])                   \n\t"
-                "lbu            %[src_ptr_r2],  16(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_r3],  24(%[src_ptr])                  \n\t"
-                "mtlo           %[vector4a],    $ac2                            \n\t"
-
-                "append         %[src_ptr_0],   %[src_ptr_r1],  8               \n\t"
-                "append         %[src_ptr_l1],  %[src_ptr_r2],  8               \n\t"
-                "append         %[src_ptr_l2],  %[src_ptr_r3],  8               \n\t"
-                "dpau.h.qbr     $ac2,           %[src_ptr_l2],  %[vector1b]     \n\t"
-                "dpau.h.qbr     $ac2,           %[src_ptr_0],   %[vector2b]     \n\t"
-                "dpsu.h.qbr     $ac2,           %[src_ptr_l1],  %[vector3b]     \n\t"
-
-                "lbu            %[src_ptr_l2],  -15(%[src_ptr])                 \n\t"
-                "lbu            %[src_ptr_l1],  -7(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_0],   1(%[src_ptr])                   \n\t"
-                "lbu            %[src_ptr_r1],  9(%[src_ptr])                   \n\t"
-                "lbu            %[src_ptr_r2],  17(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_r3],  25(%[src_ptr])                  \n\t"
-                "mtlo           %[vector4a],    $ac3                            \n\t"
-                "extp           %[Temp1],       $ac2,           9               \n\t"
-
-                "append         %[src_ptr_l2],  %[src_ptr_r3],  8               \n\t"
-                "append         %[src_ptr_0],   %[src_ptr_r1],  8               \n\t"
-                "append         %[src_ptr_l1],  %[src_ptr_r2],  8               \n\t"
-                "dpau.h.qbr     $ac3,           %[src_ptr_l2],  %[vector1b]     \n\t"
-                "dpau.h.qbr     $ac3,           %[src_ptr_0],   %[vector2b]     \n\t"
-                "dpsu.h.qbr     $ac3,           %[src_ptr_l1],  %[vector3b]     \n\t"
-
-                "lbu            %[src_ptr_l2],  -14(%[src_ptr])                 \n\t"
-                "lbu            %[src_ptr_l1],  -6(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_0],   2(%[src_ptr])                   \n\t"
-                "lbu            %[src_ptr_r1],  10(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_r2],  18(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_r3],  26(%[src_ptr])                  \n\t"
-                "mtlo           %[vector4a],    $ac0                            \n\t"
-                "extp           %[Temp2],       $ac3,           9               \n\t"
-
-                "append         %[src_ptr_l2],  %[src_ptr_r3],  8               \n\t"
-                "append         %[src_ptr_0],   %[src_ptr_r1],  8               \n\t"
-                "append         %[src_ptr_l1],  %[src_ptr_r2],  8               \n\t"
-                "dpau.h.qbr     $ac0,           %[src_ptr_l2],  %[vector1b]     \n\t"
-                "dpau.h.qbr     $ac0,           %[src_ptr_0],   %[vector2b]     \n\t"
-                "dpsu.h.qbr     $ac0,           %[src_ptr_l1],  %[vector3b]     \n\t"
-
-                "lbu            %[src_ptr_l2],  -13(%[src_ptr])                 \n\t"
-                "lbu            %[src_ptr_l1],  -5(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_0],   3(%[src_ptr])                   \n\t"
-                "lbu            %[src_ptr_r1],  11(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_r2],  19(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_r3],  27(%[src_ptr])                  \n\t"
-                "mtlo           %[vector4a],    $ac1                            \n\t"
-                "extp           %[Temp3],       $ac0,           9               \n\t"
-
-                "append         %[src_ptr_l2],  %[src_ptr_r3],  8               \n\t"
-                "append         %[src_ptr_0],   %[src_ptr_r1],  8               \n\t"
-                "append         %[src_ptr_l1],  %[src_ptr_r2],  8               \n\t"
-                "dpau.h.qbr     $ac1,           %[src_ptr_l2],  %[vector1b]     \n\t"
-                "dpau.h.qbr     $ac1,           %[src_ptr_0],   %[vector2b]     \n\t"
-                "dpsu.h.qbr     $ac1,           %[src_ptr_l1],  %[vector3b]     \n\t"
-
-                : [Temp1] "=&r" (Temp1), [Temp2] "=&r" (Temp2), [Temp3] "=&r" (Temp3),
-                  [src_ptr_l1] "=&r" (src_ptr_l1), [src_ptr_0] "=&r" (src_ptr_0),
-                  [src_ptr_r1] "=&r" (src_ptr_r1), [src_ptr_r2] "=&r" (src_ptr_r2),
-                  [src_ptr_l2] "=&r" (src_ptr_l2), [src_ptr_r3] "=&r" (src_ptr_r3)
-                : [vector1b] "r" (vector1b), [vector2b] "r" (vector2b),
-                  [vector3b] "r" (vector3b), [vector4a] "r" (vector4a),
-                  [src_ptr] "r" (src_ptr)
-            );
-
-            /* apply filter with vectors pairs */
-            __asm__ __volatile__ (
-                "lbu            %[src_ptr_l2],  -12(%[src_ptr])                 \n\t"
-                "lbu            %[src_ptr_l1],  -4(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_0],   4(%[src_ptr])                   \n\t"
-                "lbu            %[src_ptr_r1],  12(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_r2],  20(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_r3],  28(%[src_ptr])                  \n\t"
-                "mtlo           %[vector4a],    $ac2                            \n\t"
-
-                "append         %[src_ptr_l2],  %[src_ptr_r3],  8               \n\t"
-                "append         %[src_ptr_0],   %[src_ptr_r1],  8               \n\t"
-                "append         %[src_ptr_l1],  %[src_ptr_r2],  8               \n\t"
-                "dpau.h.qbr     $ac2,           %[src_ptr_l2],  %[vector1b]     \n\t"
-                "dpau.h.qbr     $ac2,           %[src_ptr_0],   %[vector2b]     \n\t"
-                "dpsu.h.qbr     $ac2,           %[src_ptr_l1],  %[vector3b]     \n\t"
-                "extp           %[Temp4],       $ac1,           9               \n\t"
-
-                "lbu            %[src_ptr_l2],  -11(%[src_ptr])                 \n\t"
-                "lbu            %[src_ptr_l1],  -3(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_0],   5(%[src_ptr])                   \n\t"
-                "lbu            %[src_ptr_r1],  13(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_r2],  21(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_r3],  29(%[src_ptr])                  \n\t"
-                "mtlo           %[vector4a],    $ac3                            \n\t"
-                "extp           %[Temp5],       $ac2,           9               \n\t"
-
-                "append         %[src_ptr_l2],  %[src_ptr_r3],  8               \n\t"
-                "append         %[src_ptr_0],   %[src_ptr_r1],  8               \n\t"
-                "append         %[src_ptr_l1],  %[src_ptr_r2],  8               \n\t"
-                "dpau.h.qbr     $ac3,           %[src_ptr_l2],  %[vector1b]     \n\t"
-                "dpau.h.qbr     $ac3,           %[src_ptr_0],   %[vector2b]     \n\t"
-                "dpsu.h.qbr     $ac3,           %[src_ptr_l1],  %[vector3b]     \n\t"
-
-                "lbu            %[src_ptr_l2],  -10(%[src_ptr])                 \n\t"
-                "lbu            %[src_ptr_l1],  -2(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_0],   6(%[src_ptr])                   \n\t"
-                "lbu            %[src_ptr_r1],  14(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_r2],  22(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_r3],  30(%[src_ptr])                  \n\t"
-                "mtlo           %[vector4a],    $ac0                            \n\t"
-                "extp           %[Temp6],       $ac3,           9               \n\t"
-
-                "append         %[src_ptr_l2],  %[src_ptr_r3],  8               \n\t"
-                "append         %[src_ptr_0],   %[src_ptr_r1],  8               \n\t"
-                "append         %[src_ptr_l1],  %[src_ptr_r2],  8               \n\t"
-                "dpau.h.qbr     $ac0,           %[src_ptr_l2],  %[vector1b]     \n\t"
-                "dpau.h.qbr     $ac0,           %[src_ptr_0],   %[vector2b]     \n\t"
-                "dpsu.h.qbr     $ac0,           %[src_ptr_l1],  %[vector3b]     \n\t"
-
-                "lbu            %[src_ptr_l2],  -9(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_l1],  -1(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_0],   7(%[src_ptr])                   \n\t"
-                "lbu            %[src_ptr_r1],  15(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_r2],  23(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_r3],  31(%[src_ptr])                  \n\t"
-                "mtlo           %[vector4a],    $ac1                            \n\t"
-                "extp           %[Temp7],       $ac0,           9               \n\t"
-
-                "append         %[src_ptr_l2],  %[src_ptr_r3],  8               \n\t"
-                "append         %[src_ptr_0],   %[src_ptr_r1],  8               \n\t"
-                "append         %[src_ptr_l1],  %[src_ptr_r2],  8               \n\t"
-                "dpau.h.qbr     $ac1,           %[src_ptr_l2],  %[vector1b]     \n\t"
-                "dpau.h.qbr     $ac1,           %[src_ptr_0],   %[vector2b]     \n\t"
-                "dpsu.h.qbr     $ac1,           %[src_ptr_l1],  %[vector3b]     \n\t"
-                "extp           %[Temp8],       $ac1,           9               \n\t"
-
-                : [Temp4] "=&r" (Temp4), [Temp5] "=&r" (Temp5),
-                  [Temp6] "=&r" (Temp6), [Temp7] "=&r" (Temp7), [Temp8] "=r" (Temp8),
-                  [src_ptr_l1] "=&r" (src_ptr_l1), [src_ptr_0] "=&r" (src_ptr_0),
-                  [src_ptr_r1] "=&r" (src_ptr_r1), [src_ptr_r2] "=&r" (src_ptr_r2),
-                  [src_ptr_l2] "=&r" (src_ptr_l2),[src_ptr_r3] "=&r" (src_ptr_r3)
-                : [vector1b] "r" (vector1b), [vector2b] "r" (vector2b),
-                  [vector3b] "r" (vector3b), [vector4a] "r" (vector4a),
-                  [src_ptr] "r" (src_ptr)
-            );
-
-            /* clamp and store results */
-            output_ptr[0] = cm[Temp1];
-            output_ptr[1] = cm[Temp2];
-            output_ptr[2] = cm[Temp3];
-            output_ptr[3] = cm[Temp4];
-            output_ptr[4] = cm[Temp5];
-            output_ptr[5] = cm[Temp6];
-            output_ptr[6] = cm[Temp7];
-            output_ptr[7] = cm[Temp8];
-
-            src_ptr += 8;
-            output_ptr += output_pitch;
-        }
-    }
-    else
-    {
-        /* 4 tap filter */
-
-        /* prefetch src_ptr data to cache memory */
-        prefetch_load(src_ptr);
-
-        for (i = output_height; i--;)
-        {
-            __asm__ __volatile__ (
-                "lbu            %[src_ptr_l1],  -8(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_0],   0(%[src_ptr])                   \n\t"
-                "lbu            %[src_ptr_r1],  8(%[src_ptr])                   \n\t"
-                "lbu            %[src_ptr_r2],  16(%[src_ptr])                  \n\t"
-                "mtlo           %[vector4a],    $ac2                            \n\t"
-                "append         %[src_ptr_0],   %[src_ptr_r1],  8               \n\t"
-                "append         %[src_ptr_l1],  %[src_ptr_r2],  8               \n\t"
-                "dpau.h.qbr     $ac2,           %[src_ptr_0],   %[vector2b]     \n\t"
-                "dpsu.h.qbr     $ac2,           %[src_ptr_l1],  %[vector3b]     \n\t"
-
-                : [src_ptr_l1] "=&r" (src_ptr_l1), [src_ptr_0] "=&r" (src_ptr_0),
-                  [src_ptr_r1] "=&r" (src_ptr_r1), [src_ptr_r2] "=&r" (src_ptr_r2)
-                : [vector2b] "r" (vector2b), [vector3b] "r" (vector3b),
-                  [vector4a] "r" (vector4a), [src_ptr] "r" (src_ptr)
-            );
-
-            __asm__ __volatile__ (
-                "lbu            %[src_ptr_l1],  -7(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_0],   1(%[src_ptr])                   \n\t"
-                "lbu            %[src_ptr_r1],  9(%[src_ptr])                   \n\t"
-                "lbu            %[src_ptr_r2],  17(%[src_ptr])                  \n\t"
-                "mtlo           %[vector4a],    $ac3                            \n\t"
-                "append         %[src_ptr_0],   %[src_ptr_r1],  8               \n\t"
-                "append         %[src_ptr_l1],  %[src_ptr_r2],  8               \n\t"
-                "dpau.h.qbr     $ac3,           %[src_ptr_0],   %[vector2b]     \n\t"
-                "dpsu.h.qbr     $ac3,           %[src_ptr_l1],  %[vector3b]     \n\t"
-                "extp           %[Temp1],       $ac2,           9               \n\t"
-
-                : [Temp1] "=r" (Temp1),
-                  [src_ptr_l1] "=&r" (src_ptr_l1), [src_ptr_0] "=&r" (src_ptr_0),
-                  [src_ptr_r1] "=&r" (src_ptr_r1), [src_ptr_r2] "=&r" (src_ptr_r2)
-                : [vector2b] "r" (vector2b), [vector3b] "r" (vector3b),
-                  [vector4a] "r" (vector4a), [src_ptr] "r" (src_ptr)
-            );
-
-            src_ptr_l1 = src_ptr[-6];
-            src_ptr_0  = src_ptr[2];
-            src_ptr_r1 = src_ptr[10];
-            src_ptr_r2 = src_ptr[18];
-
-            __asm__ __volatile__ (
-                "mtlo           %[vector4a],    $ac0                            \n\t"
-                "append         %[src_ptr_0],   %[src_ptr_r1],  8               \n\t"
-                "append         %[src_ptr_l1],  %[src_ptr_r2],  8               \n\t"
-                "dpau.h.qbr     $ac0,           %[src_ptr_0],   %[vector2b]     \n\t"
-                "dpsu.h.qbr     $ac0,           %[src_ptr_l1],  %[vector3b]     \n\t"
-                "extp           %[Temp2],       $ac3,           9               \n\t"
-
-                : [Temp2] "=r" (Temp2)
-                : [vector2b] "r" (vector2b), [vector3b] "r" (vector3b),
-                  [src_ptr_l1] "r" (src_ptr_l1), [src_ptr_0] "r" (src_ptr_0),
-                  [src_ptr_r1] "r" (src_ptr_r1), [src_ptr_r2] "r" (src_ptr_r2),
-                  [vector4a] "r" (vector4a)
-            );
-
-            src_ptr_l1 = src_ptr[-5];
-            src_ptr_0  = src_ptr[3];
-            src_ptr_r1 = src_ptr[11];
-            src_ptr_r2 = src_ptr[19];
-
-            __asm__ __volatile__ (
-                "mtlo           %[vector4a],    $ac1                            \n\t"
-                "append         %[src_ptr_0],   %[src_ptr_r1],  8               \n\t"
-                "append         %[src_ptr_l1],  %[src_ptr_r2],  8               \n\t"
-                "dpau.h.qbr     $ac1,           %[src_ptr_0],   %[vector2b]     \n\t"
-                "dpsu.h.qbr     $ac1,           %[src_ptr_l1],  %[vector3b]     \n\t"
-                "extp           %[Temp3],       $ac0,           9               \n\t"
-
-                : [Temp3] "=r" (Temp3)
-                : [vector2b] "r" (vector2b), [vector3b] "r" (vector3b),
-                  [src_ptr_l1] "r" (src_ptr_l1), [src_ptr_0] "r" (src_ptr_0),
-                  [src_ptr_r1] "r" (src_ptr_r1), [src_ptr_r2] "r" (src_ptr_r2),
-                  [vector4a] "r" (vector4a)
-            );
-
-            src_ptr_l1 = src_ptr[-4];
-            src_ptr_0  = src_ptr[4];
-            src_ptr_r1 = src_ptr[12];
-            src_ptr_r2 = src_ptr[20];
-
-            __asm__ __volatile__ (
-                "mtlo           %[vector4a],    $ac2                            \n\t"
-                "append         %[src_ptr_0],   %[src_ptr_r1],  8               \n\t"
-                "append         %[src_ptr_l1],  %[src_ptr_r2],  8               \n\t"
-                "dpau.h.qbr     $ac2,           %[src_ptr_0],   %[vector2b]     \n\t"
-                "dpsu.h.qbr     $ac2,           %[src_ptr_l1],  %[vector3b]     \n\t"
-                "extp           %[Temp4],       $ac1,           9               \n\t"
-
-                : [Temp4] "=r" (Temp4)
-                : [vector2b] "r" (vector2b), [vector3b] "r" (vector3b),
-                  [src_ptr_l1] "r" (src_ptr_l1), [src_ptr_0] "r" (src_ptr_0),
-                  [src_ptr_r1] "r" (src_ptr_r1), [src_ptr_r2] "r" (src_ptr_r2),
-                  [vector4a] "r" (vector4a)
-            );
-
-            src_ptr_l1 = src_ptr[-3];
-            src_ptr_0  = src_ptr[5];
-            src_ptr_r1 = src_ptr[13];
-            src_ptr_r2 = src_ptr[21];
-
-            __asm__ __volatile__ (
-                "mtlo           %[vector4a],    $ac3                            \n\t"
-                "append         %[src_ptr_0],   %[src_ptr_r1],  8               \n\t"
-                "append         %[src_ptr_l1],  %[src_ptr_r2],  8               \n\t"
-                "dpau.h.qbr     $ac3,           %[src_ptr_0],   %[vector2b]     \n\t"
-                "dpsu.h.qbr     $ac3,           %[src_ptr_l1],  %[vector3b]     \n\t"
-                "extp           %[Temp5],       $ac2,           9               \n\t"
-
-                : [Temp5] "=&r" (Temp5)
-                : [vector2b] "r" (vector2b), [vector3b] "r" (vector3b),
-                  [src_ptr_l1] "r" (src_ptr_l1), [src_ptr_0] "r" (src_ptr_0),
-                  [src_ptr_r1] "r" (src_ptr_r1), [src_ptr_r2] "r" (src_ptr_r2),
-                  [vector4a] "r" (vector4a)
-            );
-
-            src_ptr_l1 = src_ptr[-2];
-            src_ptr_0  = src_ptr[6];
-            src_ptr_r1 = src_ptr[14];
-            src_ptr_r2 = src_ptr[22];
-
-            __asm__ __volatile__ (
-                "mtlo           %[vector4a],    $ac0                            \n\t"
-                "append         %[src_ptr_0],   %[src_ptr_r1],  8               \n\t"
-                "append         %[src_ptr_l1],  %[src_ptr_r2],  8               \n\t"
-                "dpau.h.qbr     $ac0,           %[src_ptr_0],   %[vector2b]     \n\t"
-                "dpsu.h.qbr     $ac0,           %[src_ptr_l1],  %[vector3b]     \n\t"
-                "extp           %[Temp6],       $ac3,           9               \n\t"
-
-                : [Temp6] "=r" (Temp6)
-                : [vector2b] "r" (vector2b), [vector3b] "r" (vector3b),
-                  [src_ptr_l1] "r" (src_ptr_l1), [src_ptr_0] "r" (src_ptr_0),
-                  [src_ptr_r1] "r" (src_ptr_r1), [src_ptr_r2] "r" (src_ptr_r2),
-                  [vector4a] "r" (vector4a)
-            );
-
-            src_ptr_l1 = src_ptr[-1];
-            src_ptr_0  = src_ptr[7];
-            src_ptr_r1 = src_ptr[15];
-            src_ptr_r2 = src_ptr[23];
-
-            __asm__ __volatile__ (
-                "mtlo           %[vector4a],    $ac1                            \n\t"
-                "append         %[src_ptr_0],   %[src_ptr_r1],  8               \n\t"
-                "append         %[src_ptr_l1],  %[src_ptr_r2],  8               \n\t"
-                "dpau.h.qbr     $ac1,           %[src_ptr_0],   %[vector2b]     \n\t"
-                "dpsu.h.qbr     $ac1,           %[src_ptr_l1],  %[vector3b]     \n\t"
-                "extp           %[Temp7],       $ac0,           9               \n\t"
-                "extp           %[Temp8],       $ac1,           9               \n\t"
-
-                : [Temp7] "=&r" (Temp7), [Temp8] "=r" (Temp8)
-                : [vector2b] "r" (vector2b), [vector3b] "r" (vector3b),
-                  [src_ptr_l1] "r" (src_ptr_l1), [src_ptr_0] "r" (src_ptr_0),
-                  [src_ptr_r1] "r" (src_ptr_r1), [src_ptr_r2] "r" (src_ptr_r2),
-                  [vector4a] "r" (vector4a)
-            );
-
-            /* clamp and store results */
-            output_ptr[0] = cm[Temp1];
-            output_ptr[1] = cm[Temp2];
-            output_ptr[2] = cm[Temp3];
-            output_ptr[3] = cm[Temp4];
-            output_ptr[4] = cm[Temp5];
-            output_ptr[5] = cm[Temp6];
-            output_ptr[6] = cm[Temp7];
-            output_ptr[7] = cm[Temp8];
-
-            src_ptr += 8;
-            output_ptr += output_pitch;
-        }
-    }
-}
-
-
-void vp8_filter_block2d_second_pass161
-(
-    unsigned char *RESTRICT src_ptr,
-    unsigned char *RESTRICT output_ptr,
-    int output_pitch,
-    const unsigned short *vp8_filter
-)
-{
-    unsigned int i, j;
-
-    int Temp1, Temp2, Temp3, Temp4, Temp5, Temp6, Temp7, Temp8;
-    unsigned int vector4a;
-    unsigned int vector1b, vector2b, vector3b;
-
-    unsigned char src_ptr_l2;
-    unsigned char src_ptr_l1;
-    unsigned char src_ptr_0;
-    unsigned char src_ptr_r1;
-    unsigned char src_ptr_r2;
-    unsigned char src_ptr_r3;
-    unsigned char *cm = ff_cropTbl + CROP_WIDTH;
-
-    vector4a = 64;
-
-    vector1b = vp8_filter[0];
-    vector2b = vp8_filter[2];
-    vector3b = vp8_filter[1];
-
-    if (vector1b == 0)
-    {
-        /* 4 tap filter */
-
-        /* prefetch src_ptr data to cache memory */
-        prefetch_load(src_ptr + 16);
-
-        for (i = 16; i--;)
-        {
-            /* unrolling for loop */
-            for (j = 0; j < 16; j += 8)
-            {
-                /* apply filter with vectors pairs */
-                __asm__ __volatile__ (
-                    "lbu            %[src_ptr_l1],  -16(%[src_ptr])                 \n\t"
-                    "lbu            %[src_ptr_0],   0(%[src_ptr])                   \n\t"
-                    "lbu            %[src_ptr_r1],  16(%[src_ptr])                  \n\t"
-                    "lbu            %[src_ptr_r2],  32(%[src_ptr])                  \n\t"
-                    "mtlo           %[vector4a],    $ac2                            \n\t"
-                    "append         %[src_ptr_0],   %[src_ptr_r1],  8               \n\t"
-                    "append         %[src_ptr_l1],  %[src_ptr_r2],  8               \n\t"
-                    "dpau.h.qbr     $ac2,           %[src_ptr_0],   %[vector2b]     \n\t"
-                    "dpsu.h.qbr     $ac2,           %[src_ptr_l1],  %[vector3b]     \n\t"
-
-                    "lbu            %[src_ptr_l1],  -15(%[src_ptr])                 \n\t"
-                    "lbu            %[src_ptr_0],   1(%[src_ptr])                   \n\t"
-                    "lbu            %[src_ptr_r1],  17(%[src_ptr])                  \n\t"
-                    "lbu            %[src_ptr_r2],  33(%[src_ptr])                  \n\t"
-                    "mtlo           %[vector4a],    $ac3                            \n\t"
-                    "extp           %[Temp1],       $ac2,           9               \n\t"
-
-                    "append         %[src_ptr_0],   %[src_ptr_r1],  8               \n\t"
-                    "append         %[src_ptr_l1],  %[src_ptr_r2],  8               \n\t"
-                    "dpau.h.qbr     $ac3,           %[src_ptr_0],   %[vector2b]     \n\t"
-                    "dpsu.h.qbr     $ac3,           %[src_ptr_l1],  %[vector3b]     \n\t"
-
-                    "lbu            %[src_ptr_l1],  -14(%[src_ptr])                 \n\t"
-                    "lbu            %[src_ptr_0],   2(%[src_ptr])                   \n\t"
-                    "lbu            %[src_ptr_r1],  18(%[src_ptr])                  \n\t"
-                    "lbu            %[src_ptr_r2],  34(%[src_ptr])                  \n\t"
-                    "mtlo           %[vector4a],    $ac1                            \n\t"
-                    "extp           %[Temp2],       $ac3,           9               \n\t"
-
-                    "append         %[src_ptr_0],   %[src_ptr_r1],  8               \n\t"
-                    "append         %[src_ptr_l1],  %[src_ptr_r2],  8               \n\t"
-                    "dpau.h.qbr     $ac1,           %[src_ptr_0],   %[vector2b]     \n\t"
-                    "dpsu.h.qbr     $ac1,           %[src_ptr_l1],  %[vector3b]     \n\t"
-
-                    "lbu            %[src_ptr_l1],  -13(%[src_ptr])                 \n\t"
-                    "lbu            %[src_ptr_0],   3(%[src_ptr])                   \n\t"
-                    "lbu            %[src_ptr_r1],  19(%[src_ptr])                  \n\t"
-                    "lbu            %[src_ptr_r2],  35(%[src_ptr])                  \n\t"
-                    "mtlo           %[vector4a],    $ac3                            \n\t"
-                    "extp           %[Temp3],       $ac1,           9               \n\t"
-
-                    "append         %[src_ptr_0],   %[src_ptr_r1],  8               \n\t"
-                    "append         %[src_ptr_l1],  %[src_ptr_r2],  8               \n\t"
-                    "dpau.h.qbr     $ac3,           %[src_ptr_0],   %[vector2b]     \n\t"
-                    "dpsu.h.qbr     $ac3,           %[src_ptr_l1],  %[vector3b]     \n\t"
-
-                    "lbu            %[src_ptr_l1],  -12(%[src_ptr])                 \n\t"
-                    "lbu            %[src_ptr_0],   4(%[src_ptr])                   \n\t"
-                    "lbu            %[src_ptr_r1],  20(%[src_ptr])                  \n\t"
-                    "lbu            %[src_ptr_r2],  36(%[src_ptr])                  \n\t"
-                    "mtlo           %[vector4a],    $ac2                            \n\t"
-                    "extp           %[Temp4],       $ac3,           9               \n\t"
-
-                    "append         %[src_ptr_0],   %[src_ptr_r1],  8               \n\t"
-                    "append         %[src_ptr_l1],  %[src_ptr_r2],  8               \n\t"
-                    "dpau.h.qbr     $ac2,           %[src_ptr_0],   %[vector2b]     \n\t"
-                    "dpsu.h.qbr     $ac2,           %[src_ptr_l1],  %[vector3b]     \n\t"
-
-                    "lbu            %[src_ptr_l1],  -11(%[src_ptr])                 \n\t"
-                    "lbu            %[src_ptr_0],   5(%[src_ptr])                   \n\t"
-                    "lbu            %[src_ptr_r1],  21(%[src_ptr])                  \n\t"
-                    "lbu            %[src_ptr_r2],  37(%[src_ptr])                  \n\t"
-                    "mtlo           %[vector4a],    $ac3                            \n\t"
-                    "extp           %[Temp5],       $ac2,           9               \n\t"
-
-                    "append         %[src_ptr_0],   %[src_ptr_r1],  8               \n\t"
-                    "append         %[src_ptr_l1],  %[src_ptr_r2],  8               \n\t"
-                    "dpau.h.qbr     $ac3,           %[src_ptr_0],   %[vector2b]     \n\t"
-                    "dpsu.h.qbr     $ac3,           %[src_ptr_l1],  %[vector3b]     \n\t"
-
-                    "lbu            %[src_ptr_l1],  -10(%[src_ptr])                 \n\t"
-                    "lbu            %[src_ptr_0],   6(%[src_ptr])                   \n\t"
-                    "lbu            %[src_ptr_r1],  22(%[src_ptr])                  \n\t"
-                    "lbu            %[src_ptr_r2],  38(%[src_ptr])                  \n\t"
-                    "mtlo           %[vector4a],    $ac1                            \n\t"
-                    "extp           %[Temp6],       $ac3,           9               \n\t"
-
-                    "append         %[src_ptr_0],   %[src_ptr_r1],  8               \n\t"
-                    "append         %[src_ptr_l1],  %[src_ptr_r2],  8               \n\t"
-                    "dpau.h.qbr     $ac1,           %[src_ptr_0],   %[vector2b]     \n\t"
-                    "dpsu.h.qbr     $ac1,           %[src_ptr_l1],  %[vector3b]     \n\t"
-
-                    "lbu            %[src_ptr_l1],  -9(%[src_ptr])                  \n\t"
-                    "lbu            %[src_ptr_0],   7(%[src_ptr])                   \n\t"
-                    "lbu            %[src_ptr_r1],  23(%[src_ptr])                  \n\t"
-                    "lbu            %[src_ptr_r2],  39(%[src_ptr])                  \n\t"
-                    "mtlo           %[vector4a],    $ac3                            \n\t"
-                    "extp           %[Temp7],       $ac1,           9               \n\t"
-
-                    "append         %[src_ptr_0],   %[src_ptr_r1],  8               \n\t"
-                    "append         %[src_ptr_l1],  %[src_ptr_r2],  8               \n\t"
-                    "dpau.h.qbr     $ac3,           %[src_ptr_0],   %[vector2b]     \n\t"
-                    "dpsu.h.qbr     $ac3,           %[src_ptr_l1],  %[vector3b]     \n\t"
-                    "extp           %[Temp8],       $ac3,           9               \n\t"
-
-                    : [Temp1] "=&r" (Temp1), [Temp2] "=&r" (Temp2),
-                      [Temp3] "=&r" (Temp3), [Temp4] "=&r" (Temp4),
-                      [Temp5] "=&r" (Temp5), [Temp6] "=&r" (Temp6),
-                      [Temp7] "=&r" (Temp7), [Temp8] "=r" (Temp8),
-                      [src_ptr_l1] "=&r" (src_ptr_l1), [src_ptr_0] "=&r" (src_ptr_0),
-                      [src_ptr_r1] "=&r" (src_ptr_r1), [src_ptr_r2] "=&r" (src_ptr_r2)
-                    : [vector2b] "r" (vector2b), [vector3b] "r" (vector3b),
-                      [vector4a] "r" (vector4a), [src_ptr] "r" (src_ptr)
-                );
-
-                /* clamp and store results */
-                output_ptr[j] = cm[Temp1];
-                output_ptr[j + 1] = cm[Temp2];
-                output_ptr[j + 2] = cm[Temp3];
-                output_ptr[j + 3] = cm[Temp4];
-                output_ptr[j + 4] = cm[Temp5];
-                output_ptr[j + 5] = cm[Temp6];
-                output_ptr[j + 6] = cm[Temp7];
-                output_ptr[j + 7] = cm[Temp8];
-
-                src_ptr += 8;
-            }
-
-            output_ptr += output_pitch;
-        }
-    }
-    else
-    {
-        /* 4 tap filter */
-
-        /* prefetch src_ptr data to cache memory */
-        prefetch_load(src_ptr + 16);
-
-        /* unroll for loop */
-        for (i = 16; i--;)
-        {
-            /* apply filter with vectors pairs */
-            __asm__ __volatile__ (
-                "lbu            %[src_ptr_l2],  -32(%[src_ptr])                 \n\t"
-                "lbu            %[src_ptr_l1],  -16(%[src_ptr])                 \n\t"
-                "lbu            %[src_ptr_0],   0(%[src_ptr])                   \n\t"
-                "lbu            %[src_ptr_r1],  16(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_r2],  32(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_r3],  48(%[src_ptr])                  \n\t"
-                "mtlo           %[vector4a],    $ac2                            \n\t"
-
-                "append         %[src_ptr_l2],  %[src_ptr_r3],  8               \n\t"
-                "append         %[src_ptr_0],   %[src_ptr_r1],  8               \n\t"
-                "append         %[src_ptr_l1],  %[src_ptr_r2],  8               \n\t"
-                "dpau.h.qbr     $ac2,           %[src_ptr_l2],  %[vector1b]     \n\t"
-                "dpau.h.qbr     $ac2,           %[src_ptr_0],   %[vector2b]     \n\t"
-                "dpsu.h.qbr     $ac2,           %[src_ptr_l1],  %[vector3b]     \n\t"
-
-                "lbu            %[src_ptr_l2],  -31(%[src_ptr])                 \n\t"
-                "lbu            %[src_ptr_l1],  -15(%[src_ptr])                 \n\t"
-                "lbu            %[src_ptr_0],   1(%[src_ptr])                   \n\t"
-                "lbu            %[src_ptr_r1],  17(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_r2],  33(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_r3],  49(%[src_ptr])                  \n\t"
-                "mtlo           %[vector4a],    $ac0                            \n\t"
-                "extp           %[Temp1],       $ac2,           9               \n\t"
-
-                "append         %[src_ptr_l2],  %[src_ptr_r3],  8               \n\t"
-                "append         %[src_ptr_0],   %[src_ptr_r1],  8               \n\t"
-                "append         %[src_ptr_l1],  %[src_ptr_r2],  8               \n\t"
-                "dpau.h.qbr     $ac0,           %[src_ptr_l2],  %[vector1b]     \n\t"
-                "dpau.h.qbr     $ac0,           %[src_ptr_0],   %[vector2b]     \n\t"
-                "dpsu.h.qbr     $ac0,           %[src_ptr_l1],  %[vector3b]     \n\t"
-
-                "lbu            %[src_ptr_l2],  -30(%[src_ptr])                 \n\t"
-                "lbu            %[src_ptr_l1],  -14(%[src_ptr])                 \n\t"
-                "lbu            %[src_ptr_0],   2(%[src_ptr])                   \n\t"
-                "lbu            %[src_ptr_r1],  18(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_r2],  34(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_r3],  50(%[src_ptr])                  \n\t"
-                "mtlo           %[vector4a],    $ac1                            \n\t"
-                "extp           %[Temp2],       $ac0,           9               \n\t"
-
-                "append         %[src_ptr_l2],  %[src_ptr_r3],  8               \n\t"
-                "append         %[src_ptr_0],   %[src_ptr_r1],  8               \n\t"
-                "append         %[src_ptr_l1],  %[src_ptr_r2],  8               \n\t"
-                "dpau.h.qbr     $ac1,           %[src_ptr_l2],  %[vector1b]     \n\t"
-                "dpau.h.qbr     $ac1,           %[src_ptr_0],   %[vector2b]     \n\t"
-                "dpsu.h.qbr     $ac1,           %[src_ptr_l1],  %[vector3b]     \n\t"
-
-                "lbu            %[src_ptr_l2],  -29(%[src_ptr])                 \n\t"
-                "lbu            %[src_ptr_l1],  -13(%[src_ptr])                 \n\t"
-                "lbu            %[src_ptr_0],   3(%[src_ptr])                   \n\t"
-                "lbu            %[src_ptr_r1],  19(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_r2],  35(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_r3],  51(%[src_ptr])                  \n\t"
-                "mtlo           %[vector4a],    $ac3                            \n\t"
-                "extp           %[Temp3],       $ac1,           9               \n\t"
-
-                "append         %[src_ptr_l2],  %[src_ptr_r3],  8               \n\t"
-                "append         %[src_ptr_0],   %[src_ptr_r1],  8               \n\t"
-                "append         %[src_ptr_l1],  %[src_ptr_r2],  8               \n\t"
-                "dpau.h.qbr     $ac3,           %[src_ptr_l2],  %[vector1b]     \n\t"
-                "dpau.h.qbr     $ac3,           %[src_ptr_0],   %[vector2b]     \n\t"
-                "dpsu.h.qbr     $ac3,           %[src_ptr_l1],  %[vector3b]     \n\t"
-
-                "lbu            %[src_ptr_l2],  -28(%[src_ptr])                 \n\t"
-                "lbu            %[src_ptr_l1],  -12(%[src_ptr])                 \n\t"
-                "lbu            %[src_ptr_0],   4(%[src_ptr])                   \n\t"
-                "lbu            %[src_ptr_r1],  20(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_r2],  36(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_r3],  52(%[src_ptr])                  \n\t"
-                "mtlo           %[vector4a],    $ac2                            \n\t"
-                "extp           %[Temp4],       $ac3,           9               \n\t"
-
-                "append         %[src_ptr_l2],  %[src_ptr_r3],  8               \n\t"
-                "append         %[src_ptr_0],   %[src_ptr_r1],  8               \n\t"
-                "append         %[src_ptr_l1],  %[src_ptr_r2],  8               \n\t"
-                "dpau.h.qbr     $ac2,           %[src_ptr_l2],  %[vector1b]     \n\t"
-                "dpau.h.qbr     $ac2,           %[src_ptr_0],   %[vector2b]     \n\t"
-                "dpsu.h.qbr     $ac2,           %[src_ptr_l1],  %[vector3b]     \n\t"
-
-                "lbu            %[src_ptr_l2],  -27(%[src_ptr])                 \n\t"
-                "lbu            %[src_ptr_l1],  -11(%[src_ptr])                 \n\t"
-                "lbu            %[src_ptr_0],   5(%[src_ptr])                   \n\t"
-                "lbu            %[src_ptr_r1],  21(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_r2],  37(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_r3],  53(%[src_ptr])                  \n\t"
-                "mtlo           %[vector4a],    $ac0                            \n\t"
-                "extp           %[Temp5],       $ac2,           9               \n\t"
-
-                "append         %[src_ptr_l2],  %[src_ptr_r3],  8               \n\t"
-                "append         %[src_ptr_0],   %[src_ptr_r1],  8               \n\t"
-                "append         %[src_ptr_l1],  %[src_ptr_r2],  8               \n\t"
-                "dpau.h.qbr     $ac0,           %[src_ptr_l2],  %[vector1b]     \n\t"
-                "dpau.h.qbr     $ac0,           %[src_ptr_0],   %[vector2b]     \n\t"
-                "dpsu.h.qbr     $ac0,           %[src_ptr_l1],  %[vector3b]     \n\t"
-
-                "lbu            %[src_ptr_l2],  -26(%[src_ptr])                 \n\t"
-                "lbu            %[src_ptr_l1],  -10(%[src_ptr])                 \n\t"
-                "lbu            %[src_ptr_0],   6(%[src_ptr])                   \n\t"
-                "lbu            %[src_ptr_r1],  22(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_r2],  38(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_r3],  54(%[src_ptr])                  \n\t"
-                "mtlo           %[vector4a],    $ac1                            \n\t"
-                "extp           %[Temp6],       $ac0,           9               \n\t"
-
-                "append         %[src_ptr_l2],  %[src_ptr_r3],  8               \n\t"
-                "append         %[src_ptr_0],   %[src_ptr_r1],  8               \n\t"
-                "append         %[src_ptr_l1],  %[src_ptr_r2],  8               \n\t"
-                "dpau.h.qbr     $ac1,           %[src_ptr_l2],  %[vector1b]     \n\t"
-                "dpau.h.qbr     $ac1,           %[src_ptr_0],   %[vector2b]     \n\t"
-                "dpsu.h.qbr     $ac1,           %[src_ptr_l1],  %[vector3b]     \n\t"
-
-                "lbu            %[src_ptr_l2],  -25(%[src_ptr])                 \n\t"
-                "lbu            %[src_ptr_l1],  -9(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_0],   7(%[src_ptr])                   \n\t"
-                "lbu            %[src_ptr_r1],  23(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_r2],  39(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_r3],  55(%[src_ptr])                  \n\t"
-                "mtlo           %[vector4a],    $ac3                            \n\t"
-                "extp           %[Temp7],       $ac1,           9               \n\t"
-
-                "append         %[src_ptr_l2],  %[src_ptr_r3],  8               \n\t"
-                "append         %[src_ptr_0],   %[src_ptr_r1],  8               \n\t"
-                "append         %[src_ptr_l1],  %[src_ptr_r2],  8               \n\t"
-                "dpau.h.qbr     $ac3,           %[src_ptr_l2],  %[vector1b]     \n\t"
-                "dpau.h.qbr     $ac3,           %[src_ptr_0],   %[vector2b]     \n\t"
-                "dpsu.h.qbr     $ac3,           %[src_ptr_l1],  %[vector3b]     \n\t"
-                "extp           %[Temp8],       $ac3,           9               \n\t"
-
-                : [Temp1] "=&r" (Temp1), [Temp2] "=&r" (Temp2),
-                  [Temp3] "=&r" (Temp3), [Temp4] "=&r" (Temp4),
-                  [Temp5] "=&r" (Temp5), [Temp6] "=&r" (Temp6),
-                  [Temp7] "=&r" (Temp7), [Temp8] "=r" (Temp8),
-                  [src_ptr_l1] "=&r" (src_ptr_l1), [src_ptr_0] "=&r" (src_ptr_0),
-                  [src_ptr_r1] "=&r" (src_ptr_r1), [src_ptr_r2] "=&r" (src_ptr_r2),
-                  [src_ptr_l2] "=&r" (src_ptr_l2),[src_ptr_r3] "=&r" (src_ptr_r3)
-                : [vector1b] "r" (vector1b), [vector2b] "r" (vector2b),
-                  [vector3b] "r" (vector3b), [vector4a] "r" (vector4a),
-                  [src_ptr] "r" (src_ptr)
-            );
-
-            /* clamp and store results */
-            output_ptr[0] = cm[Temp1];
-            output_ptr[1] = cm[Temp2];
-            output_ptr[2] = cm[Temp3];
-            output_ptr[3] = cm[Temp4];
-            output_ptr[4] = cm[Temp5];
-            output_ptr[5] = cm[Temp6];
-            output_ptr[6] = cm[Temp7];
-            output_ptr[7] = cm[Temp8];
-
-            /* apply filter with vectors pairs */
-            __asm__ __volatile__ (
-                "lbu            %[src_ptr_l2],  -24(%[src_ptr])                 \n\t"
-                "lbu            %[src_ptr_l1],  -8(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_0],   8(%[src_ptr])                   \n\t"
-                "lbu            %[src_ptr_r1],  24(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_r2],  40(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_r3],  56(%[src_ptr])                  \n\t"
-                "mtlo           %[vector4a],    $ac2                            \n\t"
-
-                "append         %[src_ptr_l2],  %[src_ptr_r3],  8               \n\t"
-                "append         %[src_ptr_0],   %[src_ptr_r1],  8               \n\t"
-                "append         %[src_ptr_l1],  %[src_ptr_r2],  8               \n\t"
-                "dpau.h.qbr     $ac2,           %[src_ptr_l2],  %[vector1b]     \n\t"
-                "dpau.h.qbr     $ac2,           %[src_ptr_0],   %[vector2b]     \n\t"
-                "dpsu.h.qbr     $ac2,           %[src_ptr_l1],  %[vector3b]     \n\t"
-
-                "lbu            %[src_ptr_l2],  -23(%[src_ptr])                 \n\t"
-                "lbu            %[src_ptr_l1],  -7(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_0],   9(%[src_ptr])                   \n\t"
-                "lbu            %[src_ptr_r1],  25(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_r2],  41(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_r3],  57(%[src_ptr])                  \n\t"
-                "mtlo           %[vector4a],    $ac0                            \n\t"
-                "extp           %[Temp1],       $ac2,           9               \n\t"
-
-                "append         %[src_ptr_l2],  %[src_ptr_r3],  8               \n\t"
-                "append         %[src_ptr_0],   %[src_ptr_r1],  8               \n\t"
-                "append         %[src_ptr_l1],  %[src_ptr_r2],  8               \n\t"
-                "dpau.h.qbr     $ac0,           %[src_ptr_l2],  %[vector1b]     \n\t"
-                "dpau.h.qbr     $ac0,           %[src_ptr_0],   %[vector2b]     \n\t"
-                "dpsu.h.qbr     $ac0,           %[src_ptr_l1],  %[vector3b]     \n\t"
-
-                "lbu            %[src_ptr_l2],  -22(%[src_ptr])                 \n\t"
-                "lbu            %[src_ptr_l1],  -6(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_0],   10(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_r1],  26(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_r2],  42(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_r3],  58(%[src_ptr])                  \n\t"
-                "mtlo           %[vector4a],    $ac1                            \n\t"
-                "extp           %[Temp2],       $ac0,           9               \n\t"
-
-                "append         %[src_ptr_l2],  %[src_ptr_r3],  8               \n\t"
-                "append         %[src_ptr_0],   %[src_ptr_r1],  8               \n\t"
-                "append         %[src_ptr_l1],  %[src_ptr_r2],  8               \n\t"
-                "dpau.h.qbr     $ac1,           %[src_ptr_l2],  %[vector1b]     \n\t"
-                "dpau.h.qbr     $ac1,           %[src_ptr_0],   %[vector2b]     \n\t"
-                "dpsu.h.qbr     $ac1,           %[src_ptr_l1],  %[vector3b]     \n\t"
-
-                "lbu            %[src_ptr_l2],  -21(%[src_ptr])                 \n\t"
-                "lbu            %[src_ptr_l1],  -5(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_0],   11(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_r1],  27(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_r2],  43(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_r3],  59(%[src_ptr])                  \n\t"
-                "mtlo           %[vector4a],    $ac3                            \n\t"
-                "extp           %[Temp3],       $ac1,           9               \n\t"
-
-                "append         %[src_ptr_l2],  %[src_ptr_r3],  8               \n\t"
-                "append         %[src_ptr_0],   %[src_ptr_r1],  8               \n\t"
-                "append         %[src_ptr_l1],  %[src_ptr_r2],  8               \n\t"
-                "dpau.h.qbr     $ac3,           %[src_ptr_l2],  %[vector1b]     \n\t"
-                "dpau.h.qbr     $ac3,           %[src_ptr_0],   %[vector2b]     \n\t"
-                "dpsu.h.qbr     $ac3,           %[src_ptr_l1],  %[vector3b]     \n\t"
-
-                "lbu            %[src_ptr_l2],  -20(%[src_ptr])                 \n\t"
-                "lbu            %[src_ptr_l1],  -4(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_0],   12(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_r1],  28(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_r2],  44(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_r3],  60(%[src_ptr])                  \n\t"
-                "mtlo           %[vector4a],    $ac2                            \n\t"
-                "extp           %[Temp4],       $ac3,           9               \n\t"
-
-                "append         %[src_ptr_l2],  %[src_ptr_r3],  8               \n\t"
-                "append         %[src_ptr_0],   %[src_ptr_r1],  8               \n\t"
-                "append         %[src_ptr_l1],  %[src_ptr_r2],  8               \n\t"
-                "dpau.h.qbr     $ac2,           %[src_ptr_l2],  %[vector1b]     \n\t"
-                "dpau.h.qbr     $ac2,           %[src_ptr_0],   %[vector2b]     \n\t"
-                "dpsu.h.qbr     $ac2,           %[src_ptr_l1],  %[vector3b]     \n\t"
-
-                "lbu            %[src_ptr_l2],  -19(%[src_ptr])                 \n\t"
-                "lbu            %[src_ptr_l1],  -3(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_0],   13(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_r1],  29(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_r2],  45(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_r3],  61(%[src_ptr])                  \n\t"
-                "mtlo           %[vector4a],    $ac0                            \n\t"
-                "extp           %[Temp5],       $ac2,           9               \n\t"
-
-                "append         %[src_ptr_l2],  %[src_ptr_r3],  8               \n\t"
-                "append         %[src_ptr_0],   %[src_ptr_r1],  8               \n\t"
-                "append         %[src_ptr_l1],  %[src_ptr_r2],  8               \n\t"
-                "dpau.h.qbr     $ac0,           %[src_ptr_l2],  %[vector1b]     \n\t"
-                "dpau.h.qbr     $ac0,           %[src_ptr_0],   %[vector2b]     \n\t"
-                "dpsu.h.qbr     $ac0,           %[src_ptr_l1],  %[vector3b]     \n\t"
-
-                "lbu            %[src_ptr_l2],  -18(%[src_ptr])                 \n\t"
-                "lbu            %[src_ptr_l1],  -2(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_0],   14(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_r1],  30(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_r2],  46(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_r3],  62(%[src_ptr])                  \n\t"
-                "mtlo           %[vector4a],    $ac1                            \n\t"
-                "extp           %[Temp6],       $ac0,           9               \n\t"
-
-                "append         %[src_ptr_l2],  %[src_ptr_r3],  8               \n\t"
-                "append         %[src_ptr_0],   %[src_ptr_r1],  8               \n\t"
-                "append         %[src_ptr_l1],  %[src_ptr_r2],  8               \n\t"
-                "dpau.h.qbr     $ac1,           %[src_ptr_l2],  %[vector1b]     \n\t"
-                "dpau.h.qbr     $ac1,           %[src_ptr_0],   %[vector2b]     \n\t"
-                "dpsu.h.qbr     $ac1,           %[src_ptr_l1],  %[vector3b]     \n\t"
-
-                "lbu            %[src_ptr_l2],  -17(%[src_ptr])                 \n\t"
-                "lbu            %[src_ptr_l1],  -1(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_0],   15(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_r1],  31(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_r2],  47(%[src_ptr])                  \n\t"
-                "lbu            %[src_ptr_r3],  63(%[src_ptr])                  \n\t"
-                "mtlo           %[vector4a],    $ac3                            \n\t"
-                "extp           %[Temp7],       $ac1,           9               \n\t"
-
-                "append         %[src_ptr_l2],  %[src_ptr_r3],  8               \n\t"
-                "append         %[src_ptr_0],   %[src_ptr_r1],  8               \n\t"
-                "append         %[src_ptr_l1],  %[src_ptr_r2],  8               \n\t"
-                "dpau.h.qbr     $ac3,           %[src_ptr_l2],  %[vector1b]     \n\t"
-                "dpau.h.qbr     $ac3,           %[src_ptr_0],   %[vector2b]     \n\t"
-                "dpsu.h.qbr     $ac3,           %[src_ptr_l1],  %[vector3b]     \n\t"
-                "extp           %[Temp8],       $ac3,           9               \n\t"
-
-                : [Temp1] "=&r" (Temp1), [Temp2] "=&r" (Temp2),
-                  [Temp3] "=&r" (Temp3), [Temp4] "=&r" (Temp4),
-                  [Temp5] "=&r" (Temp5), [Temp6] "=&r" (Temp6),
-                  [Temp7] "=&r" (Temp7), [Temp8] "=r" (Temp8),
-                  [src_ptr_l1] "=&r" (src_ptr_l1), [src_ptr_0] "=&r" (src_ptr_0),
-                  [src_ptr_r1] "=&r" (src_ptr_r1), [src_ptr_r2] "=&r" (src_ptr_r2),
-                  [src_ptr_l2] "=&r" (src_ptr_l2), [src_ptr_r3] "=&r" (src_ptr_r3)
-                : [vector1b] "r" (vector1b), [vector2b] "r" (vector2b),
-                  [vector3b] "r" (vector3b), [vector4a] "r" (vector4a),
-                  [src_ptr] "r" (src_ptr)
-            );
-
-            src_ptr += 16;
-            output_ptr[8] = cm[Temp1];
-            output_ptr[9] = cm[Temp2];
-            output_ptr[10] = cm[Temp3];
-            output_ptr[11] = cm[Temp4];
-            output_ptr[12] = cm[Temp5];
-            output_ptr[13] = cm[Temp6];
-            output_ptr[14] = cm[Temp7];
-            output_ptr[15] = cm[Temp8];
-
-            output_ptr += output_pitch;
-        }
-    }
-}
-
-
-void vp8_sixtap_predict4x4_dspr2
-(
-    unsigned char *RESTRICT src_ptr,
-    int   src_pixels_per_line,
-    int  xoffset,
-    int  yoffset,
-    unsigned char *RESTRICT dst_ptr,
-    int dst_pitch
-)
-{
-    unsigned char FData[9 * 4]; /* Temp data bufffer used in filtering */
-    unsigned int pos = 16;
-
-    /* bit positon for extract from acc */
-    __asm__ __volatile__ (
-        "wrdsp      %[pos],     1           \n\t"
-        :
-        : [pos] "r" (pos)
-    );
-
-    if (yoffset)
-    {
-        /* First filter 1-D horizontally... */
-        vp8_filter_block2d_first_pass_4(src_ptr - (2 * src_pixels_per_line), FData,
-                                        src_pixels_per_line, 9, xoffset, 4);
-        /* then filter verticaly... */
-        vp8_filter_block2d_second_pass4(FData + 8, dst_ptr, dst_pitch, yoffset);
-    }
-    else
-        /* if (yoffsset == 0) vp8_filter_block2d_first_pass save data to dst_ptr */
-        vp8_filter_block2d_first_pass_4(src_ptr, dst_ptr, src_pixels_per_line,
-                                        4, xoffset, dst_pitch);
-}
-
-
-void vp8_sixtap_predict8x8_dspr2
-(
-    unsigned char   *RESTRICT src_ptr,
-    int  src_pixels_per_line,
-    int  xoffset,
-    int  yoffset,
-    unsigned char *RESTRICT dst_ptr,
-    int  dst_pitch
-)
-{
-
-    unsigned char FData[13 * 8]; /* Temp data bufffer used in filtering */
-    unsigned int pos, Temp1, Temp2;
-
-    pos = 16;
-
-    /* bit positon for extract from acc */
-    __asm__ __volatile__ (
-        "wrdsp      %[pos],     1               \n\t"
-        :
-        : [pos] "r" (pos)
-    );
-
-    if (yoffset)
-    {
-
-        src_ptr = src_ptr - (2 * src_pixels_per_line);
-
-        if (xoffset)
-            /* filter 1-D horizontally... */
-            vp8_filter_block2d_first_pass_8_all(src_ptr, FData, src_pixels_per_line,
-                                                13, xoffset, 8);
-
-        else
-        {
-            /* prefetch src_ptr data to cache memory */
-            prefetch_load(src_ptr + 2 * src_pixels_per_line);
-
-            __asm__ __volatile__ (
-                "ulw    %[Temp1],   0(%[src_ptr])                           \n\t"
-                "ulw    %[Temp2],   4(%[src_ptr])                           \n\t"
-                "sw     %[Temp1],   0(%[FData])                             \n\t"
-                "sw     %[Temp2],   4(%[FData])                             \n\t"
-                "addu   %[src_ptr], %[src_ptr],    %[src_pixels_per_line]   \n\t"
-
-                "ulw    %[Temp1],   0(%[src_ptr])                           \n\t"
-                "ulw    %[Temp2],   4(%[src_ptr])                           \n\t"
-                "sw     %[Temp1],   8(%[FData])                             \n\t"
-                "sw     %[Temp2],   12(%[FData])                            \n\t"
-                "addu   %[src_ptr], %[src_ptr],    %[src_pixels_per_line]   \n\t"
-
-                "ulw    %[Temp1],   0(%[src_ptr])                           \n\t"
-                "ulw    %[Temp2],   4(%[src_ptr])                           \n\t"
-                "sw     %[Temp1],   16(%[FData])                            \n\t"
-                "sw     %[Temp2],   20(%[FData])                            \n\t"
-                "addu   %[src_ptr], %[src_ptr],    %[src_pixels_per_line]   \n\t"
-
-                "ulw    %[Temp1],   0(%[src_ptr])                           \n\t"
-                "ulw    %[Temp2],   4(%[src_ptr])                           \n\t"
-                "sw     %[Temp1],   24(%[FData])                            \n\t"
-                "sw     %[Temp2],   28(%[FData])                            \n\t"
-                "addu   %[src_ptr], %[src_ptr],    %[src_pixels_per_line]   \n\t"
-
-                "ulw    %[Temp1],   0(%[src_ptr])                           \n\t"
-                "ulw    %[Temp2],   4(%[src_ptr])                           \n\t"
-                "sw     %[Temp1],   32(%[FData])                            \n\t"
-                "sw     %[Temp2],   36(%[FData])                            \n\t"
-                "addu   %[src_ptr], %[src_ptr],    %[src_pixels_per_line]   \n\t"
-
-                "ulw    %[Temp1],   0(%[src_ptr])                           \n\t"
-                "ulw    %[Temp2],   4(%[src_ptr])                           \n\t"
-                "sw     %[Temp1],   40(%[FData])                            \n\t"
-                "sw     %[Temp2],   44(%[FData])                            \n\t"
-                "addu   %[src_ptr], %[src_ptr],    %[src_pixels_per_line]   \n\t"
-
-                "ulw    %[Temp1],   0(%[src_ptr])                           \n\t"
-                "ulw    %[Temp2],   4(%[src_ptr])                           \n\t"
-                "sw     %[Temp1],   48(%[FData])                            \n\t"
-                "sw     %[Temp2],   52(%[FData])                            \n\t"
-                "addu   %[src_ptr], %[src_ptr],    %[src_pixels_per_line]   \n\t"
-
-                "ulw    %[Temp1],   0(%[src_ptr])                           \n\t"
-                "ulw    %[Temp2],   4(%[src_ptr])                           \n\t"
-                "sw     %[Temp1],   56(%[FData])                            \n\t"
-                "sw     %[Temp2],   60(%[FData])                            \n\t"
-                "addu   %[src_ptr], %[src_ptr],    %[src_pixels_per_line]   \n\t"
-
-                "ulw    %[Temp1],   0(%[src_ptr])                           \n\t"
-                "ulw    %[Temp2],   4(%[src_ptr])                           \n\t"
-                "sw     %[Temp1],   64(%[FData])                            \n\t"
-                "sw     %[Temp2],   68(%[FData])                            \n\t"
-                "addu   %[src_ptr], %[src_ptr],    %[src_pixels_per_line]   \n\t"
-
-                "ulw    %[Temp1],   0(%[src_ptr])                           \n\t"
-                "ulw    %[Temp2],   4(%[src_ptr])                           \n\t"
-                "sw     %[Temp1],   72(%[FData])                            \n\t"
-                "sw     %[Temp2],   76(%[FData])                            \n\t"
-                "addu   %[src_ptr], %[src_ptr],    %[src_pixels_per_line]   \n\t"
-
-                "ulw    %[Temp1],   0(%[src_ptr])                           \n\t"
-                "ulw    %[Temp2],   4(%[src_ptr])                           \n\t"
-                "sw     %[Temp1],   80(%[FData])                            \n\t"
-                "sw     %[Temp2],   84(%[FData])                            \n\t"
-                "addu   %[src_ptr], %[src_ptr],    %[src_pixels_per_line]   \n\t"
-
-                "ulw    %[Temp1],   0(%[src_ptr])                           \n\t"
-                "ulw    %[Temp2],   4(%[src_ptr])                           \n\t"
-                "sw     %[Temp1],   88(%[FData])                            \n\t"
-                "sw     %[Temp2],   92(%[FData])                            \n\t"
-                "addu   %[src_ptr], %[src_ptr],    %[src_pixels_per_line]   \n\t"
-
-                "ulw    %[Temp1],   0(%[src_ptr])                           \n\t"
-                "ulw    %[Temp2],   4(%[src_ptr])                           \n\t"
-                "sw     %[Temp1],   96(%[FData])                            \n\t"
-                "sw     %[Temp2],   100(%[FData])                           \n\t"
-
-                : [Temp1] "=&r" (Temp1), [Temp2] "=&r" (Temp2)
-                : [FData] "r" (FData), [src_ptr] "r" (src_ptr),
-                  [src_pixels_per_line] "r" (src_pixels_per_line)
-            );
-        }
-
-        /* filter verticaly... */
-        vp8_filter_block2d_second_pass_8(FData + 16, dst_ptr, dst_pitch, 8, 8, yoffset);
-    }
-
-    /* if (yoffsset == 0) vp8_filter_block2d_first_pass save data to dst_ptr */
-    else
-    {
-        if (xoffset)
-            vp8_filter_block2d_first_pass_8_all(src_ptr, dst_ptr, src_pixels_per_line,
-                                                8, xoffset, dst_pitch);
-
-        else
-        {
-            /* copy from src buffer to dst buffer */
-            __asm__ __volatile__ (
-                "ulw    %[Temp1],   0(%[src_ptr])                           \n\t"
-                "ulw    %[Temp2],   4(%[src_ptr])                           \n\t"
-                "sw     %[Temp1],   0(%[dst_ptr])                           \n\t"
-                "sw     %[Temp2],   4(%[dst_ptr])                           \n\t"
-                "addu   %[src_ptr], %[src_ptr],    %[src_pixels_per_line]   \n\t"
-
-                "ulw    %[Temp1],   0(%[src_ptr])                           \n\t"
-                "ulw    %[Temp2],   4(%[src_ptr])                           \n\t"
-                "sw     %[Temp1],   8(%[dst_ptr])                           \n\t"
-                "sw     %[Temp2],   12(%[dst_ptr])                          \n\t"
-                "addu   %[src_ptr], %[src_ptr],    %[src_pixels_per_line]   \n\t"
-
-                "ulw    %[Temp1],   0(%[src_ptr])                           \n\t"
-                "ulw    %[Temp2],   4(%[src_ptr])                           \n\t"
-                "sw     %[Temp1],   16(%[dst_ptr])                          \n\t"
-                "sw     %[Temp2],   20(%[dst_ptr])                          \n\t"
-                "addu   %[src_ptr], %[src_ptr],    %[src_pixels_per_line]   \n\t"
-
-                "ulw    %[Temp1],   0(%[src_ptr])                           \n\t"
-                "ulw    %[Temp2],   4(%[src_ptr])                           \n\t"
-                "sw     %[Temp1],   24(%[dst_ptr])                          \n\t"
-                "sw     %[Temp2],   28(%[dst_ptr])                          \n\t"
-                "addu   %[src_ptr], %[src_ptr],   %[src_pixels_per_line]    \n\t"
-
-                "ulw    %[Temp1],   0(%[src_ptr])                           \n\t"
-                "ulw    %[Temp2],   4(%[src_ptr])                           \n\t"
-                "sw     %[Temp1],   32(%[dst_ptr])                          \n\t"
-                "sw     %[Temp2],   36(%[dst_ptr])                          \n\t"
-                "addu   %[src_ptr], %[src_ptr],    %[src_pixels_per_line]   \n\t"
-
-                "ulw    %[Temp1],   0(%[src_ptr])                           \n\t"
-                "ulw    %[Temp2],   4(%[src_ptr])                           \n\t"
-                "sw     %[Temp1],   40(%[dst_ptr])                          \n\t"
-                "sw     %[Temp2],   44(%[dst_ptr])                          \n\t"
-                "addu   %[src_ptr], %[src_ptr],    %[src_pixels_per_line]   \n\t"
-
-                "ulw    %[Temp1],   0(%[src_ptr])                           \n\t"
-                "ulw    %[Temp2],   4(%[src_ptr])                           \n\t"
-                "sw     %[Temp1],   48(%[dst_ptr])                          \n\t"
-                "sw     %[Temp2],   52(%[dst_ptr])                          \n\t"
-                "addu   %[src_ptr], %[src_ptr],    %[src_pixels_per_line]   \n\t"
-
-                "ulw    %[Temp1],   0(%[src_ptr])                           \n\t"
-                "ulw    %[Temp2],   4(%[src_ptr])                           \n\t"
-                "sw     %[Temp1],   56(%[dst_ptr])                          \n\t"
-                "sw     %[Temp2],   60(%[dst_ptr])                          \n\t"
-
-                : [Temp1] "=&r" (Temp1), [Temp2] "=&r" (Temp2)
-                : [dst_ptr] "r" (dst_ptr), [src_ptr] "r" (src_ptr),
-                  [src_pixels_per_line] "r" (src_pixels_per_line)
-            );
-        }
-    }
-}
-
-
-void vp8_sixtap_predict8x4_dspr2
-(
-    unsigned char   *RESTRICT src_ptr,
-    int  src_pixels_per_line,
-    int  xoffset,
-    int  yoffset,
-    unsigned char *RESTRICT dst_ptr,
-    int  dst_pitch
-)
-{
-    unsigned char FData[9 * 8]; /* Temp data bufffer used in filtering */
-    unsigned int pos, Temp1, Temp2;
-
-    pos = 16;
-
-    /* bit positon for extract from acc */
-    __asm__ __volatile__ (
-        "wrdsp      %[pos],     1           \n\t"
-        :
-        : [pos] "r" (pos)
-    );
-
-    if (yoffset)
-    {
-
-        src_ptr = src_ptr - (2 * src_pixels_per_line);
-
-        if (xoffset)
-            /* filter 1-D horizontally... */
-            vp8_filter_block2d_first_pass_8_all(src_ptr, FData, src_pixels_per_line,
-                                                9, xoffset, 8);
-
-        else
-        {
-            /* prefetch src_ptr data to cache memory */
-            prefetch_load(src_ptr + 2 * src_pixels_per_line);
-
-            __asm__ __volatile__ (
-                "ulw    %[Temp1],   0(%[src_ptr])                           \n\t"
-                "ulw    %[Temp2],   4(%[src_ptr])                           \n\t"
-                "sw     %[Temp1],   0(%[FData])                             \n\t"
-                "sw     %[Temp2],   4(%[FData])                             \n\t"
-                "addu   %[src_ptr], %[src_ptr],    %[src_pixels_per_line]   \n\t"
-
-                "ulw    %[Temp1],   0(%[src_ptr])                           \n\t"
-                "ulw    %[Temp2],   4(%[src_ptr])                           \n\t"
-                "sw     %[Temp1],   8(%[FData])                             \n\t"
-                "sw     %[Temp2],   12(%[FData])                            \n\t"
-                "addu   %[src_ptr], %[src_ptr],    %[src_pixels_per_line]   \n\t"
-
-                "ulw    %[Temp1],   0(%[src_ptr])                           \n\t"
-                "ulw    %[Temp2],   4(%[src_ptr])                           \n\t"
-                "sw     %[Temp1],   16(%[FData])                            \n\t"
-                "sw     %[Temp2],   20(%[FData])                            \n\t"
-                "addu   %[src_ptr], %[src_ptr],    %[src_pixels_per_line]   \n\t"
-
-                "ulw    %[Temp1],   0(%[src_ptr])                           \n\t"
-                "ulw    %[Temp2],   4(%[src_ptr])                           \n\t"
-                "sw     %[Temp1],   24(%[FData])                            \n\t"
-                "sw     %[Temp2],   28(%[FData])                            \n\t"
-                "addu   %[src_ptr], %[src_ptr],    %[src_pixels_per_line]   \n\t"
-
-                "ulw    %[Temp1],   0(%[src_ptr])                           \n\t"
-                "ulw    %[Temp2],   4(%[src_ptr])                           \n\t"
-                "sw     %[Temp1],   32(%[FData])                            \n\t"
-                "sw     %[Temp2],   36(%[FData])                            \n\t"
-                "addu   %[src_ptr], %[src_ptr],    %[src_pixels_per_line]   \n\t"
-
-                "ulw    %[Temp1],   0(%[src_ptr])                           \n\t"
-                "ulw    %[Temp2],   4(%[src_ptr])                           \n\t"
-                "sw     %[Temp1],   40(%[FData])                            \n\t"
-                "sw     %[Temp2],   44(%[FData])                            \n\t"
-                "addu   %[src_ptr], %[src_ptr],    %[src_pixels_per_line]   \n\t"
-
-                "ulw    %[Temp1],   0(%[src_ptr])                           \n\t"
-                "ulw    %[Temp2],   4(%[src_ptr])                           \n\t"
-                "sw     %[Temp1],   48(%[FData])                            \n\t"
-                "sw     %[Temp2],   52(%[FData])                            \n\t"
-                "addu   %[src_ptr], %[src_ptr],    %[src_pixels_per_line]   \n\t"
-
-                "ulw    %[Temp1],   0(%[src_ptr])                           \n\t"
-                "ulw    %[Temp2],   4(%[src_ptr])                           \n\t"
-                "sw     %[Temp1],   56(%[FData])                            \n\t"
-                "sw     %[Temp2],   60(%[FData])                            \n\t"
-                "addu   %[src_ptr], %[src_ptr],    %[src_pixels_per_line]   \n\t"
-
-                "ulw    %[Temp1],   0(%[src_ptr])                           \n\t"
-                "ulw    %[Temp2],   4(%[src_ptr])                           \n\t"
-                "sw     %[Temp1],   64(%[FData])                            \n\t"
-                "sw     %[Temp2],   68(%[FData])                            \n\t"
-
-                : [Temp1] "=&r" (Temp1), [Temp2] "=&r" (Temp2)
-                : [FData] "r" (FData), [src_ptr] "r" (src_ptr),
-                  [src_pixels_per_line] "r" (src_pixels_per_line)
-            );
-        }
-
-        /* filter verticaly... */
-        vp8_filter_block2d_second_pass_8(FData + 16, dst_ptr, dst_pitch, 4, 8, yoffset);
-    }
-
-    /* if (yoffsset == 0) vp8_filter_block2d_first_pass save data to dst_ptr */
-    else
-    {
-        if (xoffset)
-            vp8_filter_block2d_first_pass_8_all(src_ptr, dst_ptr, src_pixels_per_line,
-                                                4, xoffset, dst_pitch);
-
-        else
-        {
-            /* copy from src buffer to dst buffer */
-            __asm__ __volatile__ (
-                "ulw    %[Temp1],   0(%[src_ptr])                           \n\t"
-                "ulw    %[Temp2],   4(%[src_ptr])                           \n\t"
-                "sw     %[Temp1],   0(%[dst_ptr])                           \n\t"
-                "sw     %[Temp2],   4(%[dst_ptr])                           \n\t"
-                "addu   %[src_ptr], %[src_ptr],    %[src_pixels_per_line]   \n\t"
-
-                "ulw    %[Temp1],   0(%[src_ptr])                           \n\t"
-                "ulw    %[Temp2],   4(%[src_ptr])                           \n\t"
-                "sw     %[Temp1],   8(%[dst_ptr])                           \n\t"
-                "sw     %[Temp2],   12(%[dst_ptr])                          \n\t"
-                "addu   %[src_ptr], %[src_ptr],    %[src_pixels_per_line]   \n\t"
-
-                "ulw    %[Temp1],   0(%[src_ptr])                           \n\t"
-                "ulw    %[Temp2],   4(%[src_ptr])                           \n\t"
-                "sw     %[Temp1],   16(%[dst_ptr])                          \n\t"
-                "sw     %[Temp2],   20(%[dst_ptr])                          \n\t"
-                "addu   %[src_ptr], %[src_ptr],    %[src_pixels_per_line]   \n\t"
-
-                "ulw    %[Temp1],   0(%[src_ptr])                           \n\t"
-                "ulw    %[Temp2],   4(%[src_ptr])                           \n\t"
-                "sw     %[Temp1],   24(%[dst_ptr])                          \n\t"
-                "sw     %[Temp2],   28(%[dst_ptr])                          \n\t"
-
-                : [Temp1] "=&r" (Temp1), [Temp2] "=&r" (Temp2)
-                : [dst_ptr] "r" (dst_ptr), [src_ptr] "r" (src_ptr),
-                  [src_pixels_per_line] "r" (src_pixels_per_line)
-            );
-        }
-    }
-}
-
-
-void vp8_sixtap_predict16x16_dspr2
-(
-    unsigned char   *RESTRICT src_ptr,
-    int  src_pixels_per_line,
-    int  xoffset,
-    int  yoffset,
-    unsigned char *RESTRICT dst_ptr,
-    int  dst_pitch
-)
-{
-    const unsigned short *VFilter;
-    unsigned char FData[21 * 16]; /* Temp data bufffer used in filtering */
-    unsigned int pos;
-
-    VFilter = sub_pel_filterss[yoffset];
-
-    pos = 16;
-
-    /* bit positon for extract from acc */
-    __asm__ __volatile__ (
-        "wrdsp      %[pos],     1           \n\t"
-        :
-        : [pos] "r" (pos)
-    );
-
-    if (yoffset)
-    {
-
-        src_ptr = src_ptr - (2 * src_pixels_per_line);
-
-        switch (xoffset)
-        {
-            /* filter 1-D horizontally... */
-        case 2:
-        case 4:
-        case 6:
-            /* 6 tap filter */
-            vp8_filter_block2d_first_pass16_6tap(src_ptr, FData, src_pixels_per_line,
-                                                 21, xoffset, 16);
-            break;
-
-        case 0:
-            /* only copy buffer */
-            vp8_filter_block2d_first_pass16_0(src_ptr, FData, src_pixels_per_line);
-            break;
-
-        case 1:
-        case 3:
-        case 5:
-        case 7:
-            /* 4 tap filter */
-            vp8_filter_block2d_first_pass16_4tap(src_ptr, FData, src_pixels_per_line, 16,
-                                                 21, xoffset, yoffset, dst_ptr, dst_pitch);
-            break;
-        }
-
-        /* filter verticaly... */
-        vp8_filter_block2d_second_pass161(FData + 32, dst_ptr, dst_pitch, VFilter);
-    }
-    else
-    {
-        /* if (yoffsset == 0) vp8_filter_block2d_first_pass save data to dst_ptr */
-        switch (xoffset)
-        {
-        case 2:
-        case 4:
-        case 6:
-            /* 6 tap filter */
-            vp8_filter_block2d_first_pass16_6tap(src_ptr, dst_ptr, src_pixels_per_line,
-                                                 16, xoffset, dst_pitch);
-            break;
-
-        case 1:
-        case 3:
-        case 5:
-        case 7:
-            /* 4 tap filter */
-            vp8_filter_block2d_first_pass16_4tap(src_ptr, dst_ptr, src_pixels_per_line, 16,
-                                                 21, xoffset, yoffset, dst_ptr, dst_pitch);
-            break;
-        }
-    }
-}
-
-#endif
diff --git a/vp8/common/mips/dspr2/idct_blk_dspr2.c b/vp8/common/mips/dspr2/idct_blk_dspr2.c
deleted file mode 100644 (file)
index ab938cd..0000000
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- *  Copyright (c) 2012 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.
- */
-
-#include "vpx_config.h"
-#include "vp8_rtcd.h"
-
-#if HAVE_DSPR2
-
-void vp8_dequant_idct_add_y_block_dspr2
-(short *q, short *dq,
- unsigned char *dst, int stride, char *eobs)
-{
-    int i, j;
-
-    for (i = 0; i < 4; i++)
-    {
-        for (j = 0; j < 4; j++)
-        {
-            if (*eobs++ > 1)
-                vp8_dequant_idct_add_dspr2(q, dq, dst, stride);
-            else
-            {
-                vp8_dc_only_idct_add_dspr2(q[0]*dq[0], dst, stride, dst, stride);
-                ((int *)q)[0] = 0;
-            }
-
-            q   += 16;
-            dst += 4;
-        }
-
-        dst += 4 * stride - 16;
-    }
-}
-
-void vp8_dequant_idct_add_uv_block_dspr2
-(short *q, short *dq,
- unsigned char *dstu, unsigned char *dstv, int stride, char *eobs)
-{
-    int i, j;
-
-    for (i = 0; i < 2; i++)
-    {
-        for (j = 0; j < 2; j++)
-        {
-            if (*eobs++ > 1)
-                vp8_dequant_idct_add_dspr2(q, dq, dstu, stride);
-            else
-            {
-                vp8_dc_only_idct_add_dspr2(q[0]*dq[0], dstu, stride, dstu, stride);
-                ((int *)q)[0] = 0;
-            }
-
-            q    += 16;
-            dstu += 4;
-        }
-
-        dstu += 4 * stride - 8;
-    }
-
-    for (i = 0; i < 2; i++)
-    {
-        for (j = 0; j < 2; j++)
-        {
-            if (*eobs++ > 1)
-                vp8_dequant_idct_add_dspr2(q, dq, dstv, stride);
-            else
-            {
-                vp8_dc_only_idct_add_dspr2(q[0]*dq[0], dstv, stride, dstv, stride);
-                ((int *)q)[0] = 0;
-            }
-
-            q    += 16;
-            dstv += 4;
-        }
-
-        dstv += 4 * stride - 8;
-    }
-}
-
-#endif
-
diff --git a/vp8/common/mips/dspr2/idctllm_dspr2.c b/vp8/common/mips/dspr2/idctllm_dspr2.c
deleted file mode 100644 (file)
index 2eff710..0000000
+++ /dev/null
@@ -1,369 +0,0 @@
-/*
- *  Copyright (c) 2012 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.
- */
-
-#include "vp8_rtcd.h"
-
-#if HAVE_DSPR2
-#define CROP_WIDTH 256
-
-/******************************************************************************
- * Notes:
- *
- * This implementation makes use of 16 bit fixed point version of two multiply
- * constants:
- *         1.   sqrt(2) * cos (pi/8)
- *         2.   sqrt(2) * sin (pi/8)
- * Since the first constant is bigger than 1, to maintain the same 16 bit
- * fixed point precision as the second one, we use a trick of
- *         x * a = x + x*(a-1)
- * so
- *         x * sqrt(2) * cos (pi/8) = x + x * (sqrt(2) *cos(pi/8)-1).
- ****************************************************************************/
-extern unsigned char ff_cropTbl[256 + 2 * CROP_WIDTH];
-static const int cospi8sqrt2minus1 = 20091;
-static const int sinpi8sqrt2      = 35468;
-
-inline void prefetch_load_short(short *src)
-{
-    __asm__ __volatile__ (
-        "pref   0,  0(%[src])   \n\t"
-        :
-        : [src] "r" (src)
-    );
-}
-
-void vp8_short_idct4x4llm_dspr2(short *input, unsigned char *pred_ptr,
-                                int pred_stride, unsigned char *dst_ptr,
-                                int dst_stride)
-{
-    int r, c;
-    int a1, b1, c1, d1;
-    short output[16];
-    short *ip = input;
-    short *op = output;
-    int temp1, temp2;
-    int shortpitch = 4;
-
-    int c2, d2;
-    int temp3, temp4;
-    unsigned char *cm = ff_cropTbl + CROP_WIDTH;
-
-    /* prepare data for load */
-    prefetch_load_short(ip + 8);
-
-    /* first loop is unrolled */
-    a1 = ip[0] + ip[8];
-    b1 = ip[0] - ip[8];
-
-    temp1 = (ip[4] * sinpi8sqrt2) >> 16;
-    temp2 = ip[12] + ((ip[12] * cospi8sqrt2minus1) >> 16);
-    c1 = temp1 - temp2;
-
-    temp1 = ip[4] + ((ip[4] * cospi8sqrt2minus1) >> 16);
-    temp2 = (ip[12] * sinpi8sqrt2) >> 16;
-    d1 = temp1 + temp2;
-
-    temp3 = (ip[5] * sinpi8sqrt2) >> 16;
-    temp4 = ip[13] + ((ip[13] * cospi8sqrt2minus1) >> 16);
-    c2 = temp3 - temp4;
-
-    temp3 = ip[5] + ((ip[5] * cospi8sqrt2minus1) >> 16);
-    temp4 = (ip[13] * sinpi8sqrt2) >> 16;
-    d2 = temp3 + temp4;
-
-    op[0] = a1 + d1;
-    op[12] = a1 - d1;
-    op[4] = b1 + c1;
-    op[8] = b1 - c1;
-
-    a1 = ip[1] + ip[9];
-    b1 = ip[1] - ip[9];
-
-    op[1] = a1 + d2;
-    op[13] = a1 - d2;
-    op[5] = b1 + c2;
-    op[9] = b1 - c2;
-
-    a1 = ip[2] + ip[10];
-    b1 = ip[2] - ip[10];
-
-    temp1 = (ip[6] * sinpi8sqrt2) >> 16;
-    temp2 = ip[14] + ((ip[14] * cospi8sqrt2minus1) >> 16);
-    c1 = temp1 - temp2;
-
-    temp1 = ip[6] + ((ip[6] * cospi8sqrt2minus1) >> 16);
-    temp2 = (ip[14] * sinpi8sqrt2) >> 16;
-    d1 = temp1 + temp2;
-
-    temp3 = (ip[7] * sinpi8sqrt2) >> 16;
-    temp4 = ip[15] + ((ip[15] * cospi8sqrt2minus1) >> 16);
-    c2 = temp3 - temp4;
-
-    temp3 = ip[7] + ((ip[7] * cospi8sqrt2minus1) >> 16);
-    temp4 = (ip[15] * sinpi8sqrt2) >> 16;
-    d2 = temp3 + temp4;
-
-    op[2] = a1 + d1;
-    op[14] = a1 - d1;
-    op[6] = b1 + c1;
-    op[10] = b1 - c1;
-
-    a1 = ip[3] + ip[11];
-    b1 = ip[3] - ip[11];
-
-    op[3] = a1 + d2;
-    op[15] = a1 - d2;
-    op[7] = b1 + c2;
-    op[11] = b1 - c2;
-
-    ip = output;
-
-    /* prepare data for load */
-    prefetch_load_short(ip + shortpitch);
-
-    /* second loop is unrolled */
-    a1 = ip[0] + ip[2];
-    b1 = ip[0] - ip[2];
-
-    temp1 = (ip[1] * sinpi8sqrt2) >> 16;
-    temp2 = ip[3] + ((ip[3] * cospi8sqrt2minus1) >> 16);
-    c1 = temp1 - temp2;
-
-    temp1 = ip[1] + ((ip[1] * cospi8sqrt2minus1) >> 16);
-    temp2 = (ip[3] * sinpi8sqrt2) >> 16;
-    d1 = temp1 + temp2;
-
-    temp3 = (ip[5] * sinpi8sqrt2) >> 16;
-    temp4 = ip[7] + ((ip[7] * cospi8sqrt2minus1) >> 16);
-    c2 = temp3 - temp4;
-
-    temp3 = ip[5] + ((ip[5] * cospi8sqrt2minus1) >> 16);
-    temp4 = (ip[7] * sinpi8sqrt2) >> 16;
-    d2 = temp3 + temp4;
-
-    op[0] = (a1 + d1 + 4) >> 3;
-    op[3] = (a1 - d1 + 4) >> 3;
-    op[1] = (b1 + c1 + 4) >> 3;
-    op[2] = (b1 - c1 + 4) >> 3;
-
-    a1 = ip[4] + ip[6];
-    b1 = ip[4] - ip[6];
-
-    op[4] = (a1 + d2 + 4) >> 3;
-    op[7] = (a1 - d2 + 4) >> 3;
-    op[5] = (b1 + c2 + 4) >> 3;
-    op[6] = (b1 - c2 + 4) >> 3;
-
-    a1 = ip[8] + ip[10];
-    b1 = ip[8] - ip[10];
-
-    temp1 = (ip[9] * sinpi8sqrt2) >> 16;
-    temp2 = ip[11] + ((ip[11] * cospi8sqrt2minus1) >> 16);
-    c1 = temp1 - temp2;
-
-    temp1 = ip[9] + ((ip[9] * cospi8sqrt2minus1) >> 16);
-    temp2 = (ip[11] * sinpi8sqrt2) >> 16;
-    d1 = temp1 + temp2;
-
-    temp3 = (ip[13] * sinpi8sqrt2) >> 16;
-    temp4 = ip[15] + ((ip[15] * cospi8sqrt2minus1) >> 16);
-    c2 = temp3 - temp4;
-
-    temp3 = ip[13] + ((ip[13] * cospi8sqrt2minus1) >> 16);
-    temp4 = (ip[15] * sinpi8sqrt2) >> 16;
-    d2 = temp3 + temp4;
-
-    op[8] = (a1 + d1 + 4) >> 3;
-    op[11] = (a1 - d1 + 4) >> 3;
-    op[9] = (b1 + c1 + 4) >> 3;
-    op[10] = (b1 - c1 + 4) >> 3;
-
-    a1 = ip[12] + ip[14];
-    b1 = ip[12] - ip[14];
-
-    op[12] = (a1 + d2 + 4) >> 3;
-    op[15] = (a1 - d2 + 4) >> 3;
-    op[13] = (b1 + c2 + 4) >> 3;
-    op[14] = (b1 - c2 + 4) >> 3;
-
-    ip = output;
-
-    for (r = 0; r < 4; r++)
-    {
-        for (c = 0; c < 4; c++)
-        {
-            short a = ip[c] + pred_ptr[c] ;
-            dst_ptr[c] = cm[a] ;
-        }
-
-        ip += 4;
-        dst_ptr += dst_stride;
-        pred_ptr += pred_stride;
-    }
-}
-
-void vp8_dc_only_idct_add_dspr2(short input_dc, unsigned char *pred_ptr, int pred_stride, unsigned char *dst_ptr, int dst_stride)
-{
-    int a1;
-    int i, absa1;
-    int t2, vector_a1, vector_a;
-
-    /* a1 = ((input_dc + 4) >> 3); */
-    __asm__ __volatile__ (
-        "addi  %[a1], %[input_dc], 4   \n\t"
-        "sra   %[a1], %[a1],       3   \n\t"
-        : [a1] "=r" (a1)
-        : [input_dc] "r" (input_dc)
-    );
-
-    if (a1 < 0)
-    {
-        /* use quad-byte
-         * input and output memory are four byte aligned
-         */
-        __asm__ __volatile__ (
-            "abs        %[absa1],     %[a1]         \n\t"
-            "replv.qb   %[vector_a1], %[absa1]      \n\t"
-            : [absa1] "=r" (absa1), [vector_a1] "=r" (vector_a1)
-            : [a1] "r" (a1)
-        );
-
-        /* use (a1 - predptr[c]) instead a1 + predptr[c] */
-        for (i = 4; i--;)
-        {
-            __asm__ __volatile__ (
-                "lw             %[t2],       0(%[pred_ptr])                     \n\t"
-                "add            %[pred_ptr], %[pred_ptr],    %[pred_stride]     \n\t"
-                "subu_s.qb      %[vector_a], %[t2],          %[vector_a1]       \n\t"
-                "sw             %[vector_a], 0(%[dst_ptr])                      \n\t"
-                "add            %[dst_ptr],  %[dst_ptr],     %[dst_stride]      \n\t"
-                : [t2] "=&r" (t2), [vector_a] "=&r" (vector_a),
-                  [dst_ptr] "+&r" (dst_ptr), [pred_ptr] "+&r" (pred_ptr)
-                : [dst_stride] "r" (dst_stride), [pred_stride] "r" (pred_stride), [vector_a1] "r" (vector_a1)
-            );
-        }
-    }
-    else
-    {
-        /* use quad-byte
-         * input and output memory are four byte aligned
-         */
-        __asm__ __volatile__ (
-            "replv.qb       %[vector_a1], %[a1]     \n\t"
-            : [vector_a1] "=r" (vector_a1)
-            : [a1] "r" (a1)
-        );
-
-        for (i = 4; i--;)
-        {
-            __asm__ __volatile__ (
-                "lw             %[t2],       0(%[pred_ptr])                 \n\t"
-                "add            %[pred_ptr], %[pred_ptr],    %[pred_stride] \n\t"
-                "addu_s.qb      %[vector_a], %[vector_a1],   %[t2]          \n\t"
-                "sw             %[vector_a], 0(%[dst_ptr])                  \n\t"
-                "add            %[dst_ptr],  %[dst_ptr],     %[dst_stride]  \n\t"
-                : [t2] "=&r" (t2), [vector_a] "=&r" (vector_a),
-                  [dst_ptr] "+&r" (dst_ptr), [pred_ptr] "+&r" (pred_ptr)
-                : [dst_stride] "r" (dst_stride), [pred_stride] "r" (pred_stride), [vector_a1] "r" (vector_a1)
-            );
-        }
-    }
-
-}
-
-void vp8_short_inv_walsh4x4_dspr2(short *input, short *mb_dqcoeff)
-{
-    short output[16];
-    int i;
-    int a1, b1, c1, d1;
-    int a2, b2, c2, d2;
-    short *ip = input;
-    short *op = output;
-
-    prefetch_load_short(ip);
-
-    for (i = 4; i--;)
-    {
-        a1 = ip[0] + ip[12];
-        b1 = ip[4] + ip[8];
-        c1 = ip[4] - ip[8];
-        d1 = ip[0] - ip[12];
-
-        op[0] = a1 + b1;
-        op[4] = c1 + d1;
-        op[8] = a1 - b1;
-        op[12] = d1 - c1;
-
-        ip++;
-        op++;
-    }
-
-    ip = output;
-    op = output;
-
-    prefetch_load_short(ip);
-
-    for (i = 4; i--;)
-    {
-        a1 = ip[0] + ip[3] + 3;
-        b1 = ip[1] + ip[2];
-        c1 = ip[1] - ip[2];
-        d1 = ip[0] - ip[3] + 3;
-
-        a2 = a1 + b1;
-        b2 = d1 + c1;
-        c2 = a1 - b1;
-        d2 = d1 - c1;
-
-        op[0] = a2 >> 3;
-        op[1] = b2 >> 3;
-        op[2] = c2 >> 3;
-        op[3] = d2 >> 3;
-
-        ip += 4;
-        op += 4;
-    }
-
-    for (i = 0; i < 16; i++)
-    {
-        mb_dqcoeff[i * 16] = output[i];
-    }
-}
-
-void vp8_short_inv_walsh4x4_1_dspr2(short *input, short *mb_dqcoeff)
-{
-    int a1;
-
-    a1 = ((input[0] + 3) >> 3);
-
-    __asm__ __volatile__ (
-        "sh             %[a1], 0(%[mb_dqcoeff])                    \n\t"
-        "sh             %[a1], 32(%[mb_dqcoeff])                   \n\t"
-        "sh             %[a1], 64(%[mb_dqcoeff])                   \n\t"
-        "sh             %[a1], 96(%[mb_dqcoeff])                   \n\t"
-        "sh             %[a1], 128(%[mb_dqcoeff])                  \n\t"
-        "sh             %[a1], 160(%[mb_dqcoeff])                  \n\t"
-        "sh             %[a1], 192(%[mb_dqcoeff])                  \n\t"
-        "sh             %[a1], 224(%[mb_dqcoeff])                  \n\t"
-        "sh             %[a1], 256(%[mb_dqcoeff])                  \n\t"
-        "sh             %[a1], 288(%[mb_dqcoeff])                  \n\t"
-        "sh             %[a1], 320(%[mb_dqcoeff])                  \n\t"
-        "sh             %[a1], 352(%[mb_dqcoeff])                  \n\t"
-        "sh             %[a1], 384(%[mb_dqcoeff])                  \n\t"
-        "sh             %[a1], 416(%[mb_dqcoeff])                  \n\t"
-        "sh             %[a1], 448(%[mb_dqcoeff])                  \n\t"
-        "sh             %[a1], 480(%[mb_dqcoeff])                  \n\t"
-
-        :
-        : [a1] "r" (a1), [mb_dqcoeff] "r" (mb_dqcoeff)
-    );
-}
-
-#endif
diff --git a/vp8/common/mips/dspr2/reconinter_dspr2.c b/vp8/common/mips/dspr2/reconinter_dspr2.c
deleted file mode 100644 (file)
index a14b397..0000000
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- *  Copyright (c) 2012 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.
- */
-
-
-#include "vpx_config.h"
-#include "vp8_rtcd.h"
-#include "vpx/vpx_integer.h"
-
-#if HAVE_DSPR2
-inline void prefetch_load_int(unsigned char *src)
-{
-    __asm__ __volatile__ (
-        "pref   0,  0(%[src])   \n\t"
-        :
-        : [src] "r" (src)
-    );
-}
-
-
-__inline void vp8_copy_mem16x16_dspr2(
-    unsigned char *RESTRICT src,
-    int src_stride,
-    unsigned char *RESTRICT dst,
-    int dst_stride)
-{
-    int r;
-    unsigned int a0, a1, a2, a3;
-
-    for (r = 16; r--;)
-    {
-        /* load src data in cache memory */
-        prefetch_load_int(src + src_stride);
-
-        /* use unaligned memory load and store */
-        __asm__ __volatile__ (
-            "ulw    %[a0], 0(%[src])            \n\t"
-            "ulw    %[a1], 4(%[src])            \n\t"
-            "ulw    %[a2], 8(%[src])            \n\t"
-            "ulw    %[a3], 12(%[src])           \n\t"
-            "sw     %[a0], 0(%[dst])            \n\t"
-            "sw     %[a1], 4(%[dst])            \n\t"
-            "sw     %[a2], 8(%[dst])            \n\t"
-            "sw     %[a3], 12(%[dst])           \n\t"
-            : [a0] "=&r" (a0), [a1] "=&r" (a1),
-              [a2] "=&r" (a2), [a3] "=&r" (a3)
-            : [src] "r" (src), [dst] "r" (dst)
-        );
-
-        src += src_stride;
-        dst += dst_stride;
-    }
-}
-
-
-__inline void vp8_copy_mem8x8_dspr2(
-    unsigned char *RESTRICT src,
-    int src_stride,
-    unsigned char *RESTRICT dst,
-    int dst_stride)
-{
-    int r;
-    unsigned int a0, a1;
-
-    /* load src data in cache memory */
-    prefetch_load_int(src + src_stride);
-
-    for (r = 8; r--;)
-    {
-        /* use unaligned memory load and store */
-        __asm__ __volatile__ (
-            "ulw    %[a0], 0(%[src])            \n\t"
-            "ulw    %[a1], 4(%[src])            \n\t"
-            "sw     %[a0], 0(%[dst])            \n\t"
-            "sw     %[a1], 4(%[dst])            \n\t"
-            : [a0] "=&r" (a0), [a1] "=&r" (a1)
-            : [src] "r" (src), [dst] "r" (dst)
-        );
-
-        src += src_stride;
-        dst += dst_stride;
-    }
-}
-
-
-__inline void vp8_copy_mem8x4_dspr2(
-    unsigned char *RESTRICT src,
-    int src_stride,
-    unsigned char *RESTRICT dst,
-    int dst_stride)
-{
-    int r;
-    unsigned int a0, a1;
-
-    /* load src data in cache memory */
-    prefetch_load_int(src + src_stride);
-
-    for (r = 4; r--;)
-    {
-        /* use unaligned memory load and store */
-        __asm__ __volatile__ (
-            "ulw    %[a0], 0(%[src])            \n\t"
-            "ulw    %[a1], 4(%[src])            \n\t"
-            "sw     %[a0], 0(%[dst])            \n\t"
-            "sw     %[a1], 4(%[dst])            \n\t"
-           : [a0] "=&r" (a0), [a1] "=&r" (a1)
-           : [src] "r" (src), [dst] "r" (dst)
-        );
-
-        src += src_stride;
-        dst += dst_stride;
-    }
-}
-
-#endif
diff --git a/vp8/common/mips/dspr2/vp8_loopfilter_filters_dspr2.c b/vp8/common/mips/dspr2/vp8_loopfilter_filters_dspr2.c
deleted file mode 100644 (file)
index 9ae6bc8..0000000
+++ /dev/null
@@ -1,2622 +0,0 @@
-/*
- *  Copyright (c) 2012 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.
- */
-
-
-#include <stdlib.h>
-#include "vp8_rtcd.h"
-#include "vp8/common/onyxc_int.h"
-
-#if HAVE_DSPR2
-typedef unsigned char uc;
-
-/* prefetch data for load */
-inline void prefetch_load_lf(unsigned char *src)
-{
-    __asm__ __volatile__ (
-        "pref   0,  0(%[src])   \n\t"
-        :
-        : [src] "r" (src)
-    );
-}
-
-
-/* prefetch data for store */
-inline void prefetch_store_lf(unsigned char *dst)
-{
-    __asm__ __volatile__ (
-        "pref   1,  0(%[dst])   \n\t"
-        :
-        : [dst] "r" (dst)
-    );
-}
-
-/* processing 4 pixels at the same time
- * compute hev and mask in the same function
- */
-static __inline void vp8_filter_mask_vec_mips
-(
-    uint32_t limit,
-    uint32_t flimit,
-    uint32_t p1,
-    uint32_t p0,
-    uint32_t p3,
-    uint32_t p2,
-    uint32_t q0,
-    uint32_t q1,
-    uint32_t q2,
-    uint32_t q3,
-    uint32_t thresh,
-    uint32_t *hev,
-    uint32_t *mask
-)
-{
-    uint32_t c, r, r3, r_k;
-    uint32_t s1, s2, s3;
-    uint32_t ones = 0xFFFFFFFF;
-    uint32_t hev1;
-
-    __asm__ __volatile__ (
-        /* mask |= (abs(p3 - p2) > limit) */
-        "subu_s.qb      %[c],   %[p3],     %[p2]        \n\t"
-        "subu_s.qb      %[r_k], %[p2],     %[p3]        \n\t"
-        "or             %[r_k], %[r_k],    %[c]         \n\t"
-        "cmpgu.lt.qb    %[c],   %[limit],  %[r_k]       \n\t"
-        "or             %[r],   $0,        %[c]         \n\t"
-
-        /* mask |= (abs(p2 - p1) > limit) */
-        "subu_s.qb      %[c],   %[p2],     %[p1]        \n\t"
-        "subu_s.qb      %[r_k], %[p1],     %[p2]        \n\t"
-        "or             %[r_k], %[r_k],    %[c]         \n\t"
-        "cmpgu.lt.qb    %[c],   %[limit],  %[r_k]       \n\t"
-        "or             %[r],   %[r],      %[c]         \n\t"
-
-        /* mask |= (abs(p1 - p0) > limit)
-         * hev  |= (abs(p1 - p0) > thresh)
-         */
-        "subu_s.qb      %[c],   %[p1],     %[p0]        \n\t"
-        "subu_s.qb      %[r_k], %[p0],     %[p1]        \n\t"
-        "or             %[r_k], %[r_k],    %[c]         \n\t"
-        "cmpgu.lt.qb    %[c],   %[thresh], %[r_k]       \n\t"
-        "or             %[r3],  $0,        %[c]         \n\t"
-        "cmpgu.lt.qb    %[c],   %[limit],  %[r_k]       \n\t"
-        "or             %[r],   %[r],      %[c]         \n\t"
-
-        /* mask |= (abs(q1 - q0) > limit)
-         * hev  |= (abs(q1 - q0) > thresh)
-         */
-        "subu_s.qb      %[c],   %[q1],     %[q0]        \n\t"
-        "subu_s.qb      %[r_k], %[q0],     %[q1]        \n\t"
-        "or             %[r_k], %[r_k],    %[c]         \n\t"
-        "cmpgu.lt.qb    %[c],   %[thresh], %[r_k]       \n\t"
-        "or             %[r3],  %[r3],     %[c]         \n\t"
-        "cmpgu.lt.qb    %[c],   %[limit],  %[r_k]       \n\t"
-        "or             %[r],   %[r],      %[c]         \n\t"
-
-        /* mask |= (abs(q2 - q1) > limit) */
-        "subu_s.qb      %[c],   %[q2],     %[q1]        \n\t"
-        "subu_s.qb      %[r_k], %[q1],     %[q2]        \n\t"
-        "or             %[r_k], %[r_k],    %[c]         \n\t"
-        "cmpgu.lt.qb    %[c],   %[limit],  %[r_k]       \n\t"
-        "or             %[r],   %[r],      %[c]         \n\t"
-        "sll            %[r3],    %[r3],    24          \n\t"
-
-        /* mask |= (abs(q3 - q2) > limit) */
-        "subu_s.qb      %[c],   %[q3],     %[q2]        \n\t"
-        "subu_s.qb      %[r_k], %[q2],     %[q3]        \n\t"
-        "or             %[r_k], %[r_k],    %[c]         \n\t"
-        "cmpgu.lt.qb    %[c],   %[limit],  %[r_k]       \n\t"
-        "or             %[r],   %[r],      %[c]         \n\t"
-
-        : [c] "=&r" (c), [r_k] "=&r" (r_k),
-          [r] "=&r" (r), [r3] "=&r" (r3)
-        : [limit] "r" (limit), [p3] "r" (p3), [p2] "r" (p2),
-          [p1] "r" (p1), [p0] "r" (p0), [q1] "r" (q1), [q0] "r" (q0),
-          [q2] "r" (q2), [q3] "r" (q3), [thresh] "r" (thresh)
-    );
-
-    __asm__ __volatile__ (
-        /* abs(p0 - q0) */
-        "subu_s.qb      %[c],   %[p0],     %[q0]        \n\t"
-        "subu_s.qb      %[r_k], %[q0],     %[p0]        \n\t"
-        "wrdsp          %[r3]                           \n\t"
-        "or             %[s1],  %[r_k],    %[c]         \n\t"
-
-        /* abs(p1 - q1) */
-        "subu_s.qb      %[c],    %[p1],    %[q1]        \n\t"
-        "addu_s.qb      %[s3],   %[s1],    %[s1]        \n\t"
-        "pick.qb        %[hev1], %[ones],  $0           \n\t"
-        "subu_s.qb      %[r_k],  %[q1],    %[p1]        \n\t"
-        "or             %[s2],   %[r_k],   %[c]         \n\t"
-
-        /* abs(p0 - q0) * 2 + abs(p1 - q1) / 2  > flimit * 2 + limit */
-        "shrl.qb        %[s2],   %[s2],     1           \n\t"
-        "addu_s.qb      %[s1],   %[s2],     %[s3]       \n\t"
-        "cmpgu.lt.qb    %[c],    %[flimit], %[s1]       \n\t"
-        "or             %[r],    %[r],      %[c]        \n\t"
-        "sll            %[r],    %[r],      24          \n\t"
-
-        "wrdsp          %[r]                            \n\t"
-        "pick.qb        %[s2],  $0,         %[ones]     \n\t"
-
-        : [c] "=&r" (c), [r_k] "=&r" (r_k), [s1] "=&r" (s1), [hev1] "=&r" (hev1),
-          [s2] "=&r" (s2), [r] "+r" (r), [s3] "=&r" (s3)
-        : [p0] "r" (p0), [q0] "r" (q0), [p1] "r" (p1), [r3] "r" (r3),
-          [q1] "r" (q1), [ones] "r" (ones), [flimit] "r" (flimit)
-    );
-
-    *hev = hev1;
-    *mask = s2;
-}
-
-
-/* inputs & outputs are quad-byte vectors */
-static __inline void vp8_filter_mips
-(
-    uint32_t mask,
-    uint32_t hev,
-    uint32_t *ps1,
-    uint32_t *ps0,
-    uint32_t *qs0,
-    uint32_t *qs1
-)
-{
-    int32_t vp8_filter_l, vp8_filter_r;
-    int32_t Filter1_l, Filter1_r, Filter2_l, Filter2_r;
-    int32_t subr_r, subr_l;
-    uint32_t t1, t2, HWM, t3;
-    uint32_t hev_l, hev_r, mask_l, mask_r, invhev_l, invhev_r;
-
-    int32_t vps1, vps0, vqs0, vqs1;
-    int32_t vps1_l, vps1_r, vps0_l, vps0_r, vqs0_l, vqs0_r, vqs1_l, vqs1_r;
-    uint32_t N128;
-
-    N128 = 0x80808080;
-    t1  = 0x03000300;
-    t2  = 0x04000400;
-    t3  = 0x01000100;
-    HWM = 0xFF00FF00;
-
-    vps0 = (*ps0) ^ N128;
-    vps1 = (*ps1) ^ N128;
-    vqs0 = (*qs0) ^ N128;
-    vqs1 = (*qs1) ^ N128;
-
-    /* use halfword pairs instead quad-bytes because of accuracy */
-    vps0_l = vps0 & HWM;
-    vps0_r = vps0 << 8;
-    vps0_r = vps0_r & HWM;
-
-    vps1_l = vps1 & HWM;
-    vps1_r = vps1 << 8;
-    vps1_r = vps1_r & HWM;
-
-    vqs0_l = vqs0 & HWM;
-    vqs0_r = vqs0 << 8;
-    vqs0_r = vqs0_r & HWM;
-
-    vqs1_l = vqs1 & HWM;
-    vqs1_r = vqs1 << 8;
-    vqs1_r = vqs1_r & HWM;
-
-    mask_l = mask & HWM;
-    mask_r = mask << 8;
-    mask_r = mask_r & HWM;
-
-    hev_l = hev & HWM;
-    hev_r = hev << 8;
-    hev_r = hev_r & HWM;
-
-    __asm__ __volatile__ (
-        /* vp8_filter = vp8_signed_char_clamp(ps1 - qs1); */
-        "subq_s.ph    %[vp8_filter_l], %[vps1_l],       %[vqs1_l]       \n\t"
-        "subq_s.ph    %[vp8_filter_r], %[vps1_r],       %[vqs1_r]       \n\t"
-
-        /* qs0 - ps0 */
-        "subq_s.ph    %[subr_l],       %[vqs0_l],       %[vps0_l]       \n\t"
-        "subq_s.ph    %[subr_r],       %[vqs0_r],       %[vps0_r]       \n\t"
-
-        /* vp8_filter &= hev; */
-        "and          %[vp8_filter_l], %[vp8_filter_l], %[hev_l]        \n\t"
-        "and          %[vp8_filter_r], %[vp8_filter_r], %[hev_r]        \n\t"
-
-        /* vp8_filter = vp8_signed_char_clamp(vp8_filter + 3 * (qs0 - ps0)); */
-        "addq_s.ph    %[vp8_filter_l], %[vp8_filter_l], %[subr_l]       \n\t"
-        "addq_s.ph    %[vp8_filter_r], %[vp8_filter_r], %[subr_r]       \n\t"
-        "xor          %[invhev_l],     %[hev_l],        %[HWM]          \n\t"
-        "addq_s.ph    %[vp8_filter_l], %[vp8_filter_l], %[subr_l]       \n\t"
-        "addq_s.ph    %[vp8_filter_r], %[vp8_filter_r], %[subr_r]       \n\t"
-        "xor          %[invhev_r],     %[hev_r],        %[HWM]          \n\t"
-        "addq_s.ph    %[vp8_filter_l], %[vp8_filter_l], %[subr_l]       \n\t"
-        "addq_s.ph    %[vp8_filter_r], %[vp8_filter_r], %[subr_r]       \n\t"
-
-        /* vp8_filter &= mask; */
-        "and          %[vp8_filter_l], %[vp8_filter_l], %[mask_l]       \n\t"
-        "and          %[vp8_filter_r], %[vp8_filter_r], %[mask_r]       \n\t"
-
-        : [vp8_filter_l] "=&r" (vp8_filter_l), [vp8_filter_r] "=&r" (vp8_filter_r),
-          [subr_l] "=&r" (subr_l), [subr_r] "=&r" (subr_r),
-          [invhev_l] "=&r" (invhev_l), [invhev_r] "=&r" (invhev_r)
-
-        : [vps0_l] "r" (vps0_l), [vps0_r] "r" (vps0_r), [vps1_l] "r" (vps1_l),
-          [vps1_r] "r" (vps1_r), [vqs0_l] "r" (vqs0_l), [vqs0_r] "r" (vqs0_r),
-          [vqs1_l] "r" (vqs1_l), [vqs1_r] "r" (vqs1_r),
-          [mask_l] "r" (mask_l), [mask_r] "r" (mask_r),
-          [hev_l] "r" (hev_l), [hev_r] "r" (hev_r),
-          [HWM] "r" (HWM)
-    );
-
-    /* save bottom 3 bits so that we round one side +4 and the other +3 */
-    __asm__ __volatile__ (
-        /* Filter2 = vp8_signed_char_clamp(vp8_filter + 3) >>= 3; */
-        "addq_s.ph    %[Filter1_l],    %[vp8_filter_l], %[t2]           \n\t"
-        "addq_s.ph    %[Filter1_r],    %[vp8_filter_r], %[t2]           \n\t"
-
-        /* Filter1 = vp8_signed_char_clamp(vp8_filter + 4) >>= 3; */
-        "addq_s.ph    %[Filter2_l],    %[vp8_filter_l], %[t1]           \n\t"
-        "addq_s.ph    %[Filter2_r],    %[vp8_filter_r], %[t1]           \n\t"
-        "shra.ph      %[Filter1_r],    %[Filter1_r],    3               \n\t"
-        "shra.ph      %[Filter1_l],    %[Filter1_l],    3               \n\t"
-
-        "shra.ph      %[Filter2_l],    %[Filter2_l],    3               \n\t"
-        "shra.ph      %[Filter2_r],    %[Filter2_r],    3               \n\t"
-
-        "and          %[Filter1_l],    %[Filter1_l],    %[HWM]          \n\t"
-        "and          %[Filter1_r],    %[Filter1_r],    %[HWM]          \n\t"
-
-        /* vps0 = vp8_signed_char_clamp(ps0 + Filter2); */
-        "addq_s.ph    %[vps0_l],       %[vps0_l],       %[Filter2_l]    \n\t"
-        "addq_s.ph    %[vps0_r],       %[vps0_r],       %[Filter2_r]    \n\t"
-
-        /* vqs0 = vp8_signed_char_clamp(qs0 - Filter1); */
-        "subq_s.ph    %[vqs0_l],       %[vqs0_l],       %[Filter1_l]    \n\t"
-        "subq_s.ph    %[vqs0_r],       %[vqs0_r],       %[Filter1_r]    \n\t"
-
-        : [Filter1_l] "=&r" (Filter1_l), [Filter1_r] "=&r" (Filter1_r),
-          [Filter2_l] "=&r" (Filter2_l), [Filter2_r] "=&r" (Filter2_r),
-          [vps0_l] "+r" (vps0_l), [vps0_r] "+r" (vps0_r),
-          [vqs0_l] "+r" (vqs0_l), [vqs0_r] "+r" (vqs0_r)
-
-        : [t1] "r" (t1), [t2] "r" (t2),
-          [vp8_filter_l] "r" (vp8_filter_l), [vp8_filter_r] "r" (vp8_filter_r),
-          [HWM] "r" (HWM)
-    );
-
-    __asm__ __volatile__ (
-        /* (vp8_filter += 1) >>= 1 */
-        "addqh.ph    %[Filter1_l],    %[Filter1_l],     %[t3]           \n\t"
-        "addqh.ph    %[Filter1_r],    %[Filter1_r],     %[t3]           \n\t"
-
-        /* vp8_filter &= ~hev; */
-        "and          %[Filter1_l],    %[Filter1_l],    %[invhev_l]     \n\t"
-        "and          %[Filter1_r],    %[Filter1_r],    %[invhev_r]     \n\t"
-
-        /* vps1 = vp8_signed_char_clamp(ps1 + vp8_filter); */
-        "addq_s.ph    %[vps1_l],       %[vps1_l],       %[Filter1_l]    \n\t"
-        "addq_s.ph    %[vps1_r],       %[vps1_r],       %[Filter1_r]    \n\t"
-
-        /* vqs1 = vp8_signed_char_clamp(qs1 - vp8_filter); */
-        "subq_s.ph    %[vqs1_l],       %[vqs1_l],       %[Filter1_l]    \n\t"
-        "subq_s.ph    %[vqs1_r],       %[vqs1_r],       %[Filter1_r]    \n\t"
-
-        : [Filter1_l] "+r" (Filter1_l), [Filter1_r] "+r" (Filter1_r),
-          [vps1_l] "+r" (vps1_l), [vps1_r] "+r" (vps1_r),
-          [vqs1_l] "+r" (vqs1_l), [vqs1_r] "+r" (vqs1_r)
-
-        : [t3] "r" (t3), [invhev_l] "r" (invhev_l), [invhev_r] "r" (invhev_r)
-    );
-
-    /* Create quad-bytes from halfword pairs */
-    vqs0_l = vqs0_l & HWM;
-    vqs1_l = vqs1_l & HWM;
-    vps0_l = vps0_l & HWM;
-    vps1_l = vps1_l & HWM;
-
-    __asm__ __volatile__ (
-        "shrl.ph      %[vqs0_r],       %[vqs0_r],       8               \n\t"
-        "shrl.ph      %[vps0_r],       %[vps0_r],       8               \n\t"
-        "shrl.ph      %[vqs1_r],       %[vqs1_r],       8               \n\t"
-        "shrl.ph      %[vps1_r],       %[vps1_r],       8               \n\t"
-
-        : [vps1_r] "+r" (vps1_r), [vqs1_r] "+r" (vqs1_r),
-          [vps0_r] "+r" (vps0_r), [vqs0_r] "+r" (vqs0_r)
-        :
-    );
-
-    vqs0 = vqs0_l | vqs0_r;
-    vqs1 = vqs1_l | vqs1_r;
-    vps0 = vps0_l | vps0_r;
-    vps1 = vps1_l | vps1_r;
-
-    *ps0 = vps0 ^ N128;
-    *ps1 = vps1 ^ N128;
-    *qs0 = vqs0 ^ N128;
-    *qs1 = vqs1 ^ N128;
-}
-
-void vp8_loop_filter_horizontal_edge_mips
-(
-    unsigned char *s,
-    int p,
-    unsigned int flimit,
-    unsigned int limit,
-    unsigned int thresh,
-    int count
-)
-{
-    uint32_t mask;
-    uint32_t hev;
-    uint32_t pm1, p0, p1, p2, p3, p4, p5, p6;
-    unsigned char *sm1, *s0, *s1, *s2, *s3, *s4, *s5, *s6;
-
-    mask = 0;
-    hev = 0;
-    p1 = 0;
-    p2 = 0;
-    p3 = 0;
-    p4 = 0;
-
-    /* prefetch data for store */
-    prefetch_store_lf(s);
-
-    /* loop filter designed to work using chars so that we can make maximum use
-     * of 8 bit simd instructions.
-     */
-
-    sm1 = s - (p << 2);
-    s0 = s - p - p - p;
-    s1 = s - p - p ;
-    s2 = s - p;
-    s3 = s;
-    s4 = s + p;
-    s5 = s + p + p;
-    s6 = s + p + p + p;
-
-    /* load quad-byte vectors
-     * memory is 4 byte aligned
-     */
-    p1 = *((uint32_t *)(s1));
-    p2 = *((uint32_t *)(s2));
-    p3 = *((uint32_t *)(s3));
-    p4 = *((uint32_t *)(s4));
-
-    /* if (p1 - p4 == 0) and (p2 - p3 == 0)
-     * mask will be zero and filtering is not needed
-     */
-    if (!(((p1 - p4) == 0) && ((p2 - p3) == 0)))
-    {
-
-        pm1 = *((uint32_t *)(sm1));
-        p0  = *((uint32_t *)(s0));
-        p5  = *((uint32_t *)(s5));
-        p6  = *((uint32_t *)(s6));
-
-        vp8_filter_mask_vec_mips(limit, flimit, p1, p2, pm1, p0, p3, p4, p5, p6,
-                                 thresh, &hev, &mask);
-
-        /* if mask == 0 do filtering is not needed */
-        if (mask)
-        {
-            /* filtering */
-            vp8_filter_mips(mask, hev, &p1, &p2, &p3, &p4);
-
-            /* unpack processed 4x4 neighborhood */
-            *((uint32_t *)s1) = p1;
-            *((uint32_t *)s2) = p2;
-            *((uint32_t *)s3) = p3;
-            *((uint32_t *)s4) = p4;
-        }
-    }
-
-    sm1 += 4;
-    s0  += 4;
-    s1  += 4;
-    s2  += 4;
-    s3  += 4;
-    s4  += 4;
-    s5  += 4;
-    s6  += 4;
-
-    /* load quad-byte vectors
-     * memory is 4 byte aligned
-     */
-    p1 = *((uint32_t *)(s1));
-    p2 = *((uint32_t *)(s2));
-    p3 = *((uint32_t *)(s3));
-    p4 = *((uint32_t *)(s4));
-
-    /* if (p1 - p4 == 0) and (p2 - p3 == 0)
-     * mask will be zero and filtering is not needed
-     */
-    if (!(((p1 - p4) == 0) && ((p2 - p3) == 0)))
-    {
-
-        pm1 = *((uint32_t *)(sm1));
-        p0  = *((uint32_t *)(s0));
-        p5  = *((uint32_t *)(s5));
-        p6  = *((uint32_t *)(s6));
-
-        vp8_filter_mask_vec_mips(limit, flimit, p1, p2, pm1, p0, p3, p4, p5, p6,
-                                 thresh, &hev, &mask);
-
-        /* if mask == 0 do filtering is not needed */
-        if (mask)
-        {
-            /* filtering */
-            vp8_filter_mips(mask, hev, &p1, &p2, &p3, &p4);
-
-            /* unpack processed 4x4 neighborhood */
-            *((uint32_t *)s1) = p1;
-            *((uint32_t *)s2) = p2;
-            *((uint32_t *)s3) = p3;
-            *((uint32_t *)s4) = p4;
-        }
-    }
-
-    sm1 += 4;
-    s0  += 4;
-    s1  += 4;
-    s2  += 4;
-    s3  += 4;
-    s4  += 4;
-    s5  += 4;
-    s6  += 4;
-
-    /* load quad-byte vectors
-     * memory is 4 byte aligned
-     */
-    p1 = *((uint32_t *)(s1));
-    p2 = *((uint32_t *)(s2));
-    p3 = *((uint32_t *)(s3));
-    p4 = *((uint32_t *)(s4));
-
-    /* if (p1 - p4 == 0) and (p2 - p3 == 0)
-     * mask will be zero and filtering is not needed
-     */
-    if (!(((p1 - p4) == 0) && ((p2 - p3) == 0)))
-    {
-
-        pm1 = *((uint32_t *)(sm1));
-        p0  = *((uint32_t *)(s0));
-        p5  = *((uint32_t *)(s5));
-        p6  = *((uint32_t *)(s6));
-
-        vp8_filter_mask_vec_mips(limit, flimit, p1, p2, pm1, p0, p3, p4, p5, p6,
-                                 thresh, &hev, &mask);
-
-        /* if mask == 0 do filtering is not needed */
-        if (mask)
-        {
-            /* filtering */
-            vp8_filter_mips(mask, hev, &p1, &p2, &p3, &p4);
-
-            /* unpack processed 4x4 neighborhood */
-            *((uint32_t *)s1) = p1;
-            *((uint32_t *)s2) = p2;
-            *((uint32_t *)s3) = p3;
-            *((uint32_t *)s4) = p4;
-        }
-    }
-
-    sm1 += 4;
-    s0  += 4;
-    s1  += 4;
-    s2  += 4;
-    s3  += 4;
-    s4  += 4;
-    s5  += 4;
-    s6  += 4;
-
-    /* load quad-byte vectors
-     * memory is 4 byte aligned
-     */
-    p1 = *((uint32_t *)(s1));
-    p2 = *((uint32_t *)(s2));
-    p3 = *((uint32_t *)(s3));
-    p4 = *((uint32_t *)(s4));
-
-    /* if (p1 - p4 == 0) and (p2 - p3 == 0)
-     * mask will be zero and filtering is not needed
-     */
-    if (!(((p1 - p4) == 0) && ((p2 - p3) == 0)))
-    {
-
-        pm1 = *((uint32_t *)(sm1));
-        p0  = *((uint32_t *)(s0));
-        p5  = *((uint32_t *)(s5));
-        p6  = *((uint32_t *)(s6));
-
-        vp8_filter_mask_vec_mips(limit, flimit, p1, p2, pm1, p0, p3, p4, p5, p6,
-                                 thresh, &hev, &mask);
-
-        /* if mask == 0 do filtering is not needed */
-        if (mask)
-        {
-            /* filtering */
-            vp8_filter_mips(mask, hev, &p1, &p2, &p3, &p4);
-
-            /* unpack processed 4x4 neighborhood */
-            *((uint32_t *)s1) = p1;
-            *((uint32_t *)s2) = p2;
-            *((uint32_t *)s3) = p3;
-            *((uint32_t *)s4) = p4;
-        }
-    }
-}
-
-void vp8_loop_filter_uvhorizontal_edge_mips
-(
-    unsigned char *s,
-    int p,
-    unsigned int flimit,
-    unsigned int limit,
-    unsigned int thresh,
-    int count
-)
-{
-    uint32_t mask;
-    uint32_t hev;
-    uint32_t pm1, p0, p1, p2, p3, p4, p5, p6;
-    unsigned char *sm1, *s0, *s1, *s2, *s3, *s4, *s5, *s6;
-
-    mask = 0;
-    hev = 0;
-    p1 = 0;
-    p2 = 0;
-    p3 = 0;
-    p4 = 0;
-
-    /* loop filter designed to work using chars so that we can make maximum use
-     * of 8 bit simd instructions.
-     */
-
-    sm1 = s - (p << 2);
-    s0  = s - p - p - p;
-    s1  = s - p - p ;
-    s2  = s - p;
-    s3  = s;
-    s4  = s + p;
-    s5  = s + p + p;
-    s6  = s + p + p + p;
-
-    /* load quad-byte vectors
-     * memory is 4 byte aligned
-     */
-    p1 = *((uint32_t *)(s1));
-    p2 = *((uint32_t *)(s2));
-    p3 = *((uint32_t *)(s3));
-    p4 = *((uint32_t *)(s4));
-
-    /* if (p1 - p4 == 0) and (p2 - p3 == 0)
-     * mask will be zero and filtering is not needed
-     */
-    if (!(((p1 - p4) == 0) && ((p2 - p3) == 0)))
-    {
-
-        pm1 = *((uint32_t *)(sm1));
-        p0  = *((uint32_t *)(s0));
-        p5  = *((uint32_t *)(s5));
-        p6  = *((uint32_t *)(s6));
-
-        vp8_filter_mask_vec_mips(limit, flimit, p1, p2, pm1, p0, p3, p4, p5, p6,
-                                 thresh, &hev, &mask);
-
-        /* if mask == 0 do filtering is not needed */
-        if (mask)
-        {
-            /* filtering */
-            vp8_filter_mips(mask, hev, &p1, &p2, &p3, &p4);
-
-            /* unpack processed 4x4 neighborhood */
-            *((uint32_t *)s1) = p1;
-            *((uint32_t *)s2) = p2;
-            *((uint32_t *)s3) = p3;
-            *((uint32_t *)s4) = p4;
-        }
-    }
-
-    sm1 += 4;
-    s0  += 4;
-    s1  += 4;
-    s2  += 4;
-    s3  += 4;
-    s4  += 4;
-    s5  += 4;
-    s6  += 4;
-
-    /* load quad-byte vectors
-     * memory is 4 byte aligned
-     */
-    p1 = *((uint32_t *)(s1));
-    p2 = *((uint32_t *)(s2));
-    p3 = *((uint32_t *)(s3));
-    p4 = *((uint32_t *)(s4));
-
-    /* if (p1 - p4 == 0) and (p2 - p3 == 0)
-     * mask will be zero and filtering is not needed
-     */
-    if (!(((p1 - p4) == 0) && ((p2 - p3) == 0)))
-    {
-
-        pm1 = *((uint32_t *)(sm1));
-        p0  = *((uint32_t *)(s0));
-        p5  = *((uint32_t *)(s5));
-        p6  = *((uint32_t *)(s6));
-
-        vp8_filter_mask_vec_mips(limit, flimit, p1, p2, pm1, p0, p3, p4, p5, p6,
-                                 thresh, &hev, &mask);
-
-        /* if mask == 0 do filtering is not needed */
-        if (mask)
-        {
-            /* filtering */
-            vp8_filter_mips(mask, hev, &p1, &p2, &p3, &p4);
-
-            /* unpack processed 4x4 neighborhood */
-            *((uint32_t *)s1) = p1;
-            *((uint32_t *)s2) = p2;
-            *((uint32_t *)s3) = p3;
-            *((uint32_t *)s4) = p4;
-        }
-    }
-}
-
-void vp8_loop_filter_vertical_edge_mips
-(
-    unsigned char *s,
-    int p,
-    const unsigned int flimit,
-    const unsigned int limit,
-    const unsigned int thresh,
-    int count
-)
-{
-    int i;
-    uint32_t mask, hev;
-    uint32_t pm1, p0, p1, p2, p3, p4, p5, p6;
-    unsigned char *s1, *s2, *s3, *s4;
-    uint32_t prim1, prim2, sec3, sec4, prim3, prim4;
-
-    hev = 0;
-    mask = 0;
-    i = 0;
-    pm1 = 0;
-    p0 = 0;
-    p1 = 0;
-    p2 = 0;
-    p3 = 0;
-    p4 = 0;
-    p5 = 0;
-    p6 = 0;
-
-    /* loop filter designed to work using chars so that we can make maximum use
-     * of 8 bit simd instructions.
-     */
-
-    /* apply filter on 4 pixesl at the same time */
-    do
-    {
-
-        /* prefetch data for store */
-        prefetch_store_lf(s + p);
-
-        s1 = s;
-        s2 = s + p;
-        s3 = s2 + p;
-        s4 = s3 + p;
-        s  = s4 + p;
-
-        /* load quad-byte vectors
-         * memory is 4 byte aligned
-         */
-        p2  = *((uint32_t *)(s1 - 4));
-        p6  = *((uint32_t *)(s1));
-        p1  = *((uint32_t *)(s2 - 4));
-        p5  = *((uint32_t *)(s2));
-        p0  = *((uint32_t *)(s3 - 4));
-        p4  = *((uint32_t *)(s3));
-        pm1 = *((uint32_t *)(s4 - 4));
-        p3  = *((uint32_t *)(s4));
-
-        /* transpose pm1, p0, p1, p2 */
-        __asm__ __volatile__ (
-            "precrq.qb.ph   %[prim1],   %[p2],      %[p1]       \n\t"
-            "precr.qb.ph    %[prim2],   %[p2],      %[p1]       \n\t"
-            "precrq.qb.ph   %[prim3],   %[p0],      %[pm1]      \n\t"
-            "precr.qb.ph    %[prim4],   %[p0],      %[pm1]      \n\t"
-
-            "precrq.qb.ph   %[p1],      %[prim1],   %[prim2]    \n\t"
-            "precr.qb.ph    %[pm1],     %[prim1],   %[prim2]    \n\t"
-            "precrq.qb.ph   %[sec3],    %[prim3],   %[prim4]    \n\t"
-            "precr.qb.ph    %[sec4],    %[prim3],   %[prim4]    \n\t"
-
-            "precrq.ph.w    %[p2],      %[p1],      %[sec3]     \n\t"
-            "precrq.ph.w    %[p0],      %[pm1],     %[sec4]     \n\t"
-            "append         %[p1],      %[sec3],    16          \n\t"
-            "append         %[pm1],     %[sec4],    16          \n\t"
-
-            : [prim1] "=&r" (prim1), [prim2] "=&r" (prim2),
-              [prim3] "=&r" (prim3), [prim4] "=&r" (prim4),
-              [p2] "+r" (p2), [p1] "+r" (p1), [p0] "+r" (p0), [pm1] "+r" (pm1),
-              [sec3] "=&r" (sec3), [sec4] "=&r" (sec4)
-            :
-        );
-
-        /* transpose p3, p4, p5, p6 */
-        __asm__ __volatile__ (
-            "precrq.qb.ph   %[prim1],   %[p6],      %[p5]       \n\t"
-            "precr.qb.ph    %[prim2],   %[p6],      %[p5]       \n\t"
-            "precrq.qb.ph   %[prim3],   %[p4],      %[p3]       \n\t"
-            "precr.qb.ph    %[prim4],   %[p4],      %[p3]       \n\t"
-
-            "precrq.qb.ph   %[p5],      %[prim1],   %[prim2]    \n\t"
-            "precr.qb.ph    %[p3],      %[prim1],   %[prim2]    \n\t"
-            "precrq.qb.ph   %[sec3],    %[prim3],   %[prim4]    \n\t"
-            "precr.qb.ph    %[sec4],    %[prim3],   %[prim4]    \n\t"
-
-            "precrq.ph.w    %[p6],      %[p5],      %[sec3]     \n\t"
-            "precrq.ph.w    %[p4],      %[p3],      %[sec4]     \n\t"
-            "append         %[p5],      %[sec3],    16          \n\t"
-            "append         %[p3],      %[sec4],    16          \n\t"
-
-            : [prim1] "=&r" (prim1), [prim2] "=&r" (prim2),
-              [prim3] "=&r" (prim3), [prim4] "=&r" (prim4),
-              [p6] "+r" (p6), [p5] "+r" (p5), [p4] "+r" (p4), [p3] "+r" (p3),
-              [sec3] "=&r" (sec3), [sec4] "=&r" (sec4)
-            :
-        );
-
-        /* if (p1 - p4 == 0) and (p2 - p3 == 0)
-         * mask will be zero and filtering is not needed
-         */
-        if (!(((p1 - p4) == 0) && ((p2 - p3) == 0)))
-        {
-
-            vp8_filter_mask_vec_mips(limit, flimit, p1, p2, pm1, p0, p3, p4, p5, p6,
-                                     thresh, &hev, &mask);
-
-            /* if mask == 0 do filtering is not needed */
-            if (mask)
-            {
-                /* filtering */
-                vp8_filter_mips(mask, hev, &p1, &p2, &p3, &p4);
-
-                /* unpack processed 4x4 neighborhood
-                 * don't use transpose on output data
-                 * because memory isn't aligned
-                 */
-                __asm__ __volatile__ (
-                    "sb         %[p4],  1(%[s4])    \n\t"
-                    "sb         %[p3],  0(%[s4])    \n\t"
-                    "sb         %[p2], -1(%[s4])    \n\t"
-                    "sb         %[p1], -2(%[s4])    \n\t"
-                    :
-                    : [p4] "r" (p4), [p3] "r" (p3), [s4] "r" (s4),
-                      [p2] "r" (p2), [p1] "r" (p1)
-                );
-
-                __asm__ __volatile__ (
-                    "srl        %[p4], %[p4], 8     \n\t"
-                    "srl        %[p3], %[p3], 8     \n\t"
-                    "srl        %[p2], %[p2], 8     \n\t"
-                    "srl        %[p1], %[p1], 8     \n\t"
-                    : [p4] "+r" (p4), [p3] "+r" (p3), [p2] "+r" (p2), [p1] "+r" (p1)
-                    :
-                );
-
-                __asm__ __volatile__ (
-                    "sb         %[p4],  1(%[s3])    \n\t"
-                    "sb         %[p3],  0(%[s3])    \n\t"
-                    "sb         %[p2], -1(%[s3])    \n\t"
-                    "sb         %[p1], -2(%[s3])    \n\t"
-                    : [p1] "+r" (p1)
-                    : [p4] "r" (p4), [p3] "r" (p3), [s3] "r" (s3), [p2] "r" (p2)
-                );
-
-                __asm__ __volatile__ (
-                    "srl        %[p4], %[p4], 8     \n\t"
-                    "srl        %[p3], %[p3], 8     \n\t"
-                    "srl        %[p2], %[p2], 8     \n\t"
-                    "srl        %[p1], %[p1], 8     \n\t"
-                    : [p4] "+r" (p4), [p3] "+r" (p3), [p2] "+r" (p2), [p1] "+r" (p1)
-                    :
-                );
-
-                __asm__ __volatile__ (
-                    "sb         %[p4],  1(%[s2])    \n\t"
-                    "sb         %[p3],  0(%[s2])    \n\t"
-                    "sb         %[p2], -1(%[s2])    \n\t"
-                    "sb         %[p1], -2(%[s2])    \n\t"
-                    :
-                    : [p4] "r" (p4), [p3] "r" (p3), [s2] "r" (s2),
-                      [p2] "r" (p2), [p1] "r" (p1)
-                );
-
-                __asm__ __volatile__ (
-                    "srl        %[p4], %[p4], 8     \n\t"
-                    "srl        %[p3], %[p3], 8     \n\t"
-                    "srl        %[p2], %[p2], 8     \n\t"
-                    "srl        %[p1], %[p1], 8     \n\t"
-                    : [p4] "+r" (p4), [p3] "+r" (p3), [p2] "+r" (p2), [p1] "+r" (p1)
-                    :
-                );
-
-                __asm__ __volatile__ (
-                    "sb         %[p4],  1(%[s1])    \n\t"
-                    "sb         %[p3],  0(%[s1])    \n\t"
-                    "sb         %[p2], -1(%[s1])    \n\t"
-                    "sb         %[p1], -2(%[s1])    \n\t"
-                    :
-                    : [p4] "r" (p4), [p3] "r" (p3), [s1] "r" (s1),
-                      [p2] "r" (p2), [p1] "r" (p1)
-                );
-            }
-        }
-
-        s1 = s;
-        s2 = s + p;
-        s3 = s2 + p;
-        s4 = s3 + p;
-        s  = s4 + p;
-
-        /* load quad-byte vectors
-         * memory is 4 byte aligned
-         */
-        p2  = *((uint32_t *)(s1 - 4));
-        p6  = *((uint32_t *)(s1));
-        p1  = *((uint32_t *)(s2 - 4));
-        p5  = *((uint32_t *)(s2));
-        p0  = *((uint32_t *)(s3 - 4));
-        p4  = *((uint32_t *)(s3));
-        pm1 = *((uint32_t *)(s4 - 4));
-        p3  = *((uint32_t *)(s4));
-
-        /* transpose pm1, p0, p1, p2 */
-        __asm__ __volatile__ (
-            "precrq.qb.ph   %[prim1],   %[p2],      %[p1]       \n\t"
-            "precr.qb.ph    %[prim2],   %[p2],      %[p1]       \n\t"
-            "precrq.qb.ph   %[prim3],   %[p0],      %[pm1]      \n\t"
-            "precr.qb.ph    %[prim4],   %[p0],      %[pm1]      \n\t"
-
-            "precrq.qb.ph   %[p1],      %[prim1],   %[prim2]    \n\t"
-            "precr.qb.ph    %[pm1],     %[prim1],   %[prim2]    \n\t"
-            "precrq.qb.ph   %[sec3],    %[prim3],   %[prim4]    \n\t"
-            "precr.qb.ph    %[sec4],    %[prim3],   %[prim4]    \n\t"
-
-            "precrq.ph.w    %[p2],      %[p1],      %[sec3]     \n\t"
-            "precrq.ph.w    %[p0],      %[pm1],     %[sec4]     \n\t"
-            "append         %[p1],      %[sec3],    16          \n\t"
-            "append         %[pm1],     %[sec4],    16          \n\t"
-
-            : [prim1] "=&r" (prim1), [prim2] "=&r" (prim2),
-              [prim3] "=&r" (prim3), [prim4] "=&r" (prim4),
-              [p2] "+r" (p2), [p1] "+r" (p1), [p0] "+r" (p0), [pm1] "+r" (pm1),
-              [sec3] "=&r" (sec3), [sec4] "=&r" (sec4)
-            :
-        );
-
-        /* transpose p3, p4, p5, p6 */
-        __asm__ __volatile__ (
-            "precrq.qb.ph   %[prim1],   %[p6],      %[p5]       \n\t"
-            "precr.qb.ph    %[prim2],   %[p6],      %[p5]       \n\t"
-            "precrq.qb.ph   %[prim3],   %[p4],      %[p3]       \n\t"
-            "precr.qb.ph    %[prim4],   %[p4],      %[p3]       \n\t"
-
-            "precrq.qb.ph   %[p5],      %[prim1],   %[prim2]    \n\t"
-            "precr.qb.ph    %[p3],      %[prim1],   %[prim2]    \n\t"
-            "precrq.qb.ph   %[sec3],    %[prim3],   %[prim4]    \n\t"
-            "precr.qb.ph    %[sec4],    %[prim3],   %[prim4]    \n\t"
-
-            "precrq.ph.w    %[p6],      %[p5],      %[sec3]     \n\t"
-            "precrq.ph.w    %[p4],      %[p3],      %[sec4]     \n\t"
-            "append         %[p5],      %[sec3],    16          \n\t"
-            "append         %[p3],      %[sec4],    16          \n\t"
-
-            : [prim1] "=&r" (prim1), [prim2] "=&r" (prim2),
-              [prim3] "=&r" (prim3), [prim4] "=&r" (prim4),
-              [p6] "+r" (p6), [p5] "+r" (p5), [p4] "+r" (p4), [p3] "+r" (p3),
-              [sec3] "=&r" (sec3), [sec4] "=&r" (sec4)
-            :
-        );
-
-        /* if (p1 - p4 == 0) and (p2 - p3 == 0)
-         * mask will be zero and filtering is not needed
-         */
-        if (!(((p1 - p4) == 0) && ((p2 - p3) == 0)))
-        {
-
-            vp8_filter_mask_vec_mips(limit, flimit, p1, p2, pm1, p0, p3, p4, p5, p6,
-                                     thresh, &hev, &mask);
-
-            /* if mask == 0 do filtering is not needed */
-            if (mask)
-            {
-                /* filtering */
-                vp8_filter_mips(mask, hev, &p1, &p2, &p3, &p4);
-
-                /* unpack processed 4x4 neighborhood
-                 * don't use transpose on output data
-                 * because memory isn't aligned
-                 */
-                __asm__ __volatile__ (
-                    "sb         %[p4],  1(%[s4])    \n\t"
-                    "sb         %[p3],  0(%[s4])    \n\t"
-                    "sb         %[p2], -1(%[s4])    \n\t"
-                    "sb         %[p1], -2(%[s4])    \n\t"
-                    :
-                    : [p4] "r" (p4), [p3] "r" (p3), [s4] "r" (s4),
-                      [p2] "r" (p2), [p1] "r" (p1)
-                );
-
-                __asm__ __volatile__ (
-                    "srl        %[p4], %[p4], 8     \n\t"
-                    "srl        %[p3], %[p3], 8     \n\t"
-                    "srl        %[p2], %[p2], 8     \n\t"
-                    "srl        %[p1], %[p1], 8     \n\t"
-                    : [p4] "+r" (p4), [p3] "+r" (p3), [p2] "+r" (p2), [p1] "+r" (p1)
-                    :
-                );
-
-                __asm__ __volatile__ (
-                    "sb         %[p4],  1(%[s3])    \n\t"
-                    "sb         %[p3],  0(%[s3])    \n\t"
-                    "sb         %[p2], -1(%[s3])    \n\t"
-                    "sb         %[p1], -2(%[s3])    \n\t"
-                    : [p1] "+r" (p1)
-                    : [p4] "r" (p4), [p3] "r" (p3), [s3] "r" (s3), [p2] "r" (p2)
-                );
-
-                __asm__ __volatile__ (
-                    "srl        %[p4], %[p4], 8     \n\t"
-                    "srl        %[p3], %[p3], 8     \n\t"
-                    "srl        %[p2], %[p2], 8     \n\t"
-                    "srl        %[p1], %[p1], 8     \n\t"
-                    : [p4] "+r" (p4), [p3] "+r" (p3), [p2] "+r" (p2), [p1] "+r" (p1)
-                    :
-                );
-
-                __asm__ __volatile__ (
-                    "sb         %[p4],  1(%[s2])    \n\t"
-                    "sb         %[p3],  0(%[s2])    \n\t"
-                    "sb         %[p2], -1(%[s2])    \n\t"
-                    "sb         %[p1], -2(%[s2])    \n\t"
-                    :
-                    : [p4] "r" (p4), [p3] "r" (p3), [s2] "r" (s2),
-                      [p2] "r" (p2), [p1] "r" (p1)
-                );
-
-                __asm__ __volatile__ (
-                    "srl        %[p4], %[p4], 8     \n\t"
-                    "srl        %[p3], %[p3], 8     \n\t"
-                    "srl        %[p2], %[p2], 8     \n\t"
-                    "srl        %[p1], %[p1], 8     \n\t"
-                    : [p4] "+r" (p4), [p3] "+r" (p3), [p2] "+r" (p2), [p1] "+r" (p1)
-                    :
-                );
-
-                __asm__ __volatile__ (
-                    "sb         %[p4],  1(%[s1])    \n\t"
-                    "sb         %[p3],  0(%[s1])    \n\t"
-                    "sb         %[p2], -1(%[s1])    \n\t"
-                    "sb         %[p1], -2(%[s1])    \n\t"
-                    :
-                    : [p4] "r" (p4), [p3] "r" (p3), [s1] "r" (s1),
-                      [p2] "r" (p2), [p1] "r" (p1)
-                );
-            }
-        }
-
-        i += 8;
-    }
-
-    while (i < count);
-}
-
-void vp8_loop_filter_uvvertical_edge_mips
-(
-    unsigned char *s,
-    int p,
-    unsigned int flimit,
-    unsigned int limit,
-    unsigned int thresh,
-    int count
-)
-{
-    uint32_t mask, hev;
-    uint32_t pm1, p0, p1, p2, p3, p4, p5, p6;
-    unsigned char *s1, *s2, *s3, *s4;
-    uint32_t prim1, prim2, sec3, sec4, prim3, prim4;
-
-    /* loop filter designed to work using chars so that we can make maximum use
-     * of 8 bit simd instructions.
-     */
-
-    /* apply filter on 4 pixesl at the same time */
-
-    s1 = s;
-    s2 = s + p;
-    s3 = s2 + p;
-    s4 = s3 + p;
-
-    /* load quad-byte vectors
-    * memory is 4 byte aligned
-    */
-    p2  = *((uint32_t *)(s1 - 4));
-    p6  = *((uint32_t *)(s1));
-    p1  = *((uint32_t *)(s2 - 4));
-    p5  = *((uint32_t *)(s2));
-    p0  = *((uint32_t *)(s3 - 4));
-    p4  = *((uint32_t *)(s3));
-    pm1 = *((uint32_t *)(s4 - 4));
-    p3  = *((uint32_t *)(s4));
-
-    /* transpose pm1, p0, p1, p2 */
-    __asm__ __volatile__ (
-        "precrq.qb.ph   %[prim1],   %[p2],      %[p1]       \n\t"
-        "precr.qb.ph    %[prim2],   %[p2],      %[p1]       \n\t"
-        "precrq.qb.ph   %[prim3],   %[p0],      %[pm1]      \n\t"
-        "precr.qb.ph    %[prim4],   %[p0],      %[pm1]      \n\t"
-
-        "precrq.qb.ph   %[p1],      %[prim1],   %[prim2]    \n\t"
-        "precr.qb.ph    %[pm1],     %[prim1],   %[prim2]    \n\t"
-        "precrq.qb.ph   %[sec3],    %[prim3],   %[prim4]    \n\t"
-        "precr.qb.ph    %[sec4],    %[prim3],   %[prim4]    \n\t"
-
-        "precrq.ph.w    %[p2],      %[p1],      %[sec3]     \n\t"
-        "precrq.ph.w    %[p0],      %[pm1],     %[sec4]     \n\t"
-        "append         %[p1],      %[sec3],    16          \n\t"
-        "append         %[pm1],     %[sec4],    16          \n\t"
-
-        : [prim1] "=&r" (prim1), [prim2] "=&r" (prim2),
-          [prim3] "=&r" (prim3), [prim4] "=&r" (prim4),
-          [p2] "+r" (p2), [p1] "+r" (p1), [p0] "+r" (p0), [pm1] "+r" (pm1),
-          [sec3] "=&r" (sec3), [sec4] "=&r" (sec4)
-        :
-    );
-
-    /* transpose p3, p4, p5, p6 */
-    __asm__ __volatile__ (
-        "precrq.qb.ph   %[prim1],   %[p6],      %[p5]       \n\t"
-        "precr.qb.ph    %[prim2],   %[p6],      %[p5]       \n\t"
-        "precrq.qb.ph   %[prim3],   %[p4],      %[p3]       \n\t"
-        "precr.qb.ph    %[prim4],   %[p4],      %[p3]       \n\t"
-
-        "precrq.qb.ph   %[p5],      %[prim1],   %[prim2]    \n\t"
-        "precr.qb.ph    %[p3],      %[prim1],   %[prim2]    \n\t"
-        "precrq.qb.ph   %[sec3],    %[prim3],   %[prim4]    \n\t"
-        "precr.qb.ph    %[sec4],    %[prim3],   %[prim4]    \n\t"
-
-        "precrq.ph.w    %[p6],      %[p5],      %[sec3]     \n\t"
-        "precrq.ph.w    %[p4],      %[p3],      %[sec4]     \n\t"
-        "append         %[p5],      %[sec3],    16          \n\t"
-        "append         %[p3],      %[sec4],    16          \n\t"
-
-        : [prim1] "=&r" (prim1), [prim2] "=&r" (prim2),
-          [prim3] "=&r" (prim3), [prim4] "=&r" (prim4),
-          [p6] "+r" (p6), [p5] "+r" (p5), [p4] "+r" (p4), [p3] "+r" (p3),
-          [sec3] "=&r" (sec3), [sec4] "=&r" (sec4)
-        :
-    );
-
-    /* if (p1 - p4 == 0) and (p2 - p3 == 0)
-    * mask will be zero and filtering is not needed
-    */
-    if (!(((p1 - p4) == 0) && ((p2 - p3) == 0)))
-    {
-
-        vp8_filter_mask_vec_mips(limit, flimit, p1, p2, pm1, p0, p3, p4, p5, p6,
-                                 thresh, &hev, &mask);
-
-        /* if mask == 0 do filtering is not needed */
-        if (mask)
-        {
-            /* filtering */
-            vp8_filter_mips(mask, hev, &p1, &p2, &p3, &p4);
-
-            /* unpack processed 4x4 neighborhood
-             * don't use transpose on output data
-             * because memory isn't aligned
-             */
-            __asm__ __volatile__ (
-                "sb         %[p4],  1(%[s4])    \n\t"
-                "sb         %[p3],  0(%[s4])    \n\t"
-                "sb         %[p2], -1(%[s4])    \n\t"
-                "sb         %[p1], -2(%[s4])    \n\t"
-                :
-                : [p4] "r" (p4), [p3] "r" (p3), [s4] "r" (s4),
-                  [p2] "r" (p2), [p1] "r" (p1)
-            );
-
-            __asm__ __volatile__ (
-                "srl        %[p4], %[p4], 8     \n\t"
-                "srl        %[p3], %[p3], 8     \n\t"
-                "srl        %[p2], %[p2], 8     \n\t"
-                "srl        %[p1], %[p1], 8     \n\t"
-                : [p4] "+r" (p4), [p3] "+r" (p3), [p2] "+r" (p2), [p1] "+r" (p1)
-                :
-            );
-
-            __asm__ __volatile__ (
-                "sb         %[p4],  1(%[s3])    \n\t"
-                "sb         %[p3],  0(%[s3])    \n\t"
-                "sb         %[p2], -1(%[s3])    \n\t"
-                "sb         %[p1], -2(%[s3])    \n\t"
-                : [p1] "+r" (p1)
-                : [p4] "r" (p4), [p3] "r" (p3), [s3] "r" (s3), [p2] "r" (p2)
-            );
-
-            __asm__ __volatile__ (
-                "srl        %[p4], %[p4], 8     \n\t"
-                "srl        %[p3], %[p3], 8     \n\t"
-                "srl        %[p2], %[p2], 8     \n\t"
-                "srl        %[p1], %[p1], 8     \n\t"
-                : [p4] "+r" (p4), [p3] "+r" (p3), [p2] "+r" (p2), [p1] "+r" (p1)
-                :
-            );
-
-            __asm__ __volatile__ (
-                "sb         %[p4],  1(%[s2])    \n\t"
-                "sb         %[p3],  0(%[s2])    \n\t"
-                "sb         %[p2], -1(%[s2])    \n\t"
-                "sb         %[p1], -2(%[s2])    \n\t"
-                :
-                : [p4] "r" (p4), [p3] "r" (p3), [s2] "r" (s2),
-                  [p2] "r" (p2), [p1] "r" (p1)
-            );
-
-            __asm__ __volatile__ (
-                "srl        %[p4], %[p4], 8     \n\t"
-                "srl        %[p3], %[p3], 8     \n\t"
-                "srl        %[p2], %[p2], 8     \n\t"
-                "srl        %[p1], %[p1], 8     \n\t"
-                : [p4] "+r" (p4), [p3] "+r" (p3), [p2] "+r" (p2), [p1] "+r" (p1)
-                :
-            );
-
-            __asm__ __volatile__ (
-                "sb         %[p4],  1(%[s1])    \n\t"
-                "sb         %[p3],  0(%[s1])    \n\t"
-                "sb         %[p2], -1(%[s1])    \n\t"
-                "sb         %[p1], -2(%[s1])    \n\t"
-                :
-                : [p4] "r" (p4), [p3] "r" (p3), [s1] "r" (s1), [p2] "r" (p2), [p1] "r" (p1)
-            );
-        }
-    }
-
-    s1 = s4 + p;
-    s2 = s1 + p;
-    s3 = s2 + p;
-    s4 = s3 + p;
-
-    /* load quad-byte vectors
-     * memory is 4 byte aligned
-     */
-    p2  = *((uint32_t *)(s1 - 4));
-    p6  = *((uint32_t *)(s1));
-    p1  = *((uint32_t *)(s2 - 4));
-    p5  = *((uint32_t *)(s2));
-    p0  = *((uint32_t *)(s3 - 4));
-    p4  = *((uint32_t *)(s3));
-    pm1 = *((uint32_t *)(s4 - 4));
-    p3  = *((uint32_t *)(s4));
-
-    /* transpose pm1, p0, p1, p2 */
-    __asm__ __volatile__ (
-        "precrq.qb.ph   %[prim1],   %[p2],      %[p1]       \n\t"
-        "precr.qb.ph    %[prim2],   %[p2],      %[p1]       \n\t"
-        "precrq.qb.ph   %[prim3],   %[p0],      %[pm1]      \n\t"
-        "precr.qb.ph    %[prim4],   %[p0],      %[pm1]      \n\t"
-
-        "precrq.qb.ph   %[p1],      %[prim1],   %[prim2]    \n\t"
-        "precr.qb.ph    %[pm1],     %[prim1],   %[prim2]    \n\t"
-        "precrq.qb.ph   %[sec3],    %[prim3],   %[prim4]    \n\t"
-        "precr.qb.ph    %[sec4],    %[prim3],   %[prim4]    \n\t"
-
-        "precrq.ph.w    %[p2],      %[p1],      %[sec3]     \n\t"
-        "precrq.ph.w    %[p0],      %[pm1],     %[sec4]     \n\t"
-        "append         %[p1],      %[sec3],    16          \n\t"
-        "append         %[pm1],     %[sec4],    16          \n\t"
-
-        : [prim1] "=&r" (prim1), [prim2] "=&r" (prim2),
-          [prim3] "=&r" (prim3), [prim4] "=&r" (prim4),
-          [p2] "+r" (p2), [p1] "+r" (p1), [p0] "+r" (p0), [pm1] "+r" (pm1),
-          [sec3] "=&r" (sec3), [sec4] "=&r" (sec4)
-        :
-    );
-
-    /* transpose p3, p4, p5, p6 */
-    __asm__ __volatile__ (
-        "precrq.qb.ph   %[prim1],   %[p6],      %[p5]       \n\t"
-        "precr.qb.ph    %[prim2],   %[p6],      %[p5]       \n\t"
-        "precrq.qb.ph   %[prim3],   %[p4],      %[p3]       \n\t"
-        "precr.qb.ph    %[prim4],   %[p4],      %[p3]       \n\t"
-
-        "precrq.qb.ph   %[p5],      %[prim1],   %[prim2]    \n\t"
-        "precr.qb.ph    %[p3],      %[prim1],   %[prim2]    \n\t"
-        "precrq.qb.ph   %[sec3],    %[prim3],   %[prim4]    \n\t"
-        "precr.qb.ph    %[sec4],    %[prim3],   %[prim4]    \n\t"
-
-        "precrq.ph.w    %[p6],      %[p5],      %[sec3]     \n\t"
-        "precrq.ph.w    %[p4],      %[p3],      %[sec4]     \n\t"
-        "append         %[p5],      %[sec3],    16          \n\t"
-        "append         %[p3],      %[sec4],    16          \n\t"
-
-        : [prim1] "=&r" (prim1), [prim2] "=&r" (prim2),
-          [prim3] "=&r" (prim3), [prim4] "=&r" (prim4),
-          [p6] "+r" (p6), [p5] "+r" (p5), [p4] "+r" (p4), [p3] "+r" (p3),
-          [sec3] "=&r" (sec3), [sec4] "=&r" (sec4)
-        :
-    );
-
-    /* if (p1 - p4 == 0) and (p2 - p3 == 0)
-     * mask will be zero and filtering is not needed
-     */
-    if (!(((p1 - p4) == 0) && ((p2 - p3) == 0)))
-    {
-
-        vp8_filter_mask_vec_mips(limit, flimit, p1, p2, pm1, p0, p3, p4, p5, p6,
-                                 thresh, &hev, &mask);
-
-        /* if mask == 0 do filtering is not needed */
-        if (mask)
-        {
-            /* filtering */
-            vp8_filter_mips(mask, hev, &p1, &p2, &p3, &p4);
-
-            /* unpack processed 4x4 neighborhood
-             * don't use transpose on output data
-             * because memory isn't aligned
-             */
-            __asm__ __volatile__ (
-                "sb         %[p4],  1(%[s4])    \n\t"
-                "sb         %[p3],  0(%[s4])    \n\t"
-                "sb         %[p2], -1(%[s4])    \n\t"
-                "sb         %[p1], -2(%[s4])    \n\t"
-                :
-                : [p4] "r" (p4), [p3] "r" (p3), [s4] "r" (s4),
-                  [p2] "r" (p2), [p1] "r" (p1)
-            );
-
-            __asm__ __volatile__ (
-                "srl        %[p4], %[p4], 8     \n\t"
-                "srl        %[p3], %[p3], 8     \n\t"
-                "srl        %[p2], %[p2], 8     \n\t"
-                "srl        %[p1], %[p1], 8     \n\t"
-                : [p4] "+r" (p4), [p3] "+r" (p3), [p2] "+r" (p2), [p1] "+r" (p1)
-                :
-            );
-
-            __asm__ __volatile__ (
-                "sb         %[p4],  1(%[s3])    \n\t"
-                "sb         %[p3],  0(%[s3])    \n\t"
-                "sb         %[p2], -1(%[s3])    \n\t"
-                "sb         %[p1], -2(%[s3])    \n\t"
-                : [p1] "+r" (p1)
-                : [p4] "r" (p4), [p3] "r" (p3), [s3] "r" (s3), [p2] "r" (p2)
-            );
-
-            __asm__ __volatile__ (
-                "srl        %[p4], %[p4], 8     \n\t"
-                "srl        %[p3], %[p3], 8     \n\t"
-                "srl        %[p2], %[p2], 8     \n\t"
-                "srl        %[p1], %[p1], 8     \n\t"
-                : [p4] "+r" (p4), [p3] "+r" (p3), [p2] "+r" (p2), [p1] "+r" (p1)
-                :
-            );
-
-            __asm__ __volatile__ (
-                "sb         %[p4],  1(%[s2])    \n\t"
-                "sb         %[p3],  0(%[s2])    \n\t"
-                "sb         %[p2], -1(%[s2])    \n\t"
-                "sb         %[p1], -2(%[s2])    \n\t"
-                :
-                : [p4] "r" (p4), [p3] "r" (p3), [s2] "r" (s2),
-                  [p2] "r" (p2), [p1] "r" (p1)
-            );
-
-            __asm__ __volatile__ (
-                "srl        %[p4], %[p4], 8     \n\t"
-                "srl        %[p3], %[p3], 8     \n\t"
-                "srl        %[p2], %[p2], 8     \n\t"
-                "srl        %[p1], %[p1], 8     \n\t"
-                : [p4] "+r" (p4), [p3] "+r" (p3), [p2] "+r" (p2), [p1] "+r" (p1)
-                :
-            );
-
-            __asm__ __volatile__ (
-                "sb         %[p4],  1(%[s1])    \n\t"
-                "sb         %[p3],  0(%[s1])    \n\t"
-                "sb         %[p2], -1(%[s1])    \n\t"
-                "sb         %[p1], -2(%[s1])    \n\t"
-                :
-                : [p4] "r" (p4), [p3] "r" (p3), [s1] "r" (s1),
-                  [p2] "r" (p2), [p1] "r" (p1)
-            );
-        }
-    }
-}
-
-/* inputs & outputs are quad-byte vectors */
-static __inline void vp8_mbfilter_mips
-(
-    uint32_t mask,
-    uint32_t hev,
-    uint32_t *ps2,
-    uint32_t *ps1,
-    uint32_t *ps0,
-    uint32_t *qs0,
-    uint32_t *qs1,
-    uint32_t *qs2
-)
-{
-    int32_t vps2, vps1, vps0, vqs0, vqs1, vqs2;
-    int32_t vps2_l, vps1_l, vps0_l, vqs0_l, vqs1_l, vqs2_l;
-    int32_t vps2_r, vps1_r, vps0_r, vqs0_r, vqs1_r, vqs2_r;
-    uint32_t HWM, vp8_filter_l, vp8_filter_r, mask_l, mask_r, hev_l, hev_r, subr_r, subr_l;
-    uint32_t Filter2_l, Filter2_r, t1, t2, Filter1_l, Filter1_r, invhev_l, invhev_r;
-    uint32_t N128, R63;
-    uint32_t u1_l, u1_r, u2_l, u2_r, u3_l, u3_r;
-
-    R63  = 0x003F003F;
-    HWM  = 0xFF00FF00;
-    N128 = 0x80808080;
-    t1   = 0x03000300;
-    t2   = 0x04000400;
-
-    vps0 = (*ps0) ^ N128;
-    vps1 = (*ps1) ^ N128;
-    vps2 = (*ps2) ^ N128;
-    vqs0 = (*qs0) ^ N128;
-    vqs1 = (*qs1) ^ N128;
-    vqs2 = (*qs2) ^ N128;
-
-    /* use halfword pairs instead quad-bytes because of accuracy */
-    vps0_l = vps0 & HWM;
-    vps0_r = vps0 << 8;
-    vps0_r = vps0_r & HWM;
-
-    vqs0_l = vqs0 & HWM;
-    vqs0_r = vqs0 << 8;
-    vqs0_r = vqs0_r & HWM;
-
-    vps1_l = vps1 & HWM;
-    vps1_r = vps1 << 8;
-    vps1_r = vps1_r & HWM;
-
-    vqs1_l = vqs1 & HWM;
-    vqs1_r = vqs1 << 8;
-    vqs1_r = vqs1_r & HWM;
-
-    vqs2_l = vqs2 & HWM;
-    vqs2_r = vqs2 << 8;
-    vqs2_r = vqs2_r & HWM;
-
-    __asm__ __volatile__ (
-        /* qs0 - ps0 */
-        "subq_s.ph    %[subr_l],       %[vqs0_l],       %[vps0_l]       \n\t"
-        "subq_s.ph    %[subr_r],       %[vqs0_r],       %[vps0_r]       \n\t"
-
-        /* vp8_filter = vp8_signed_char_clamp(ps1 - qs1); */
-        "subq_s.ph    %[vp8_filter_l], %[vps1_l],       %[vqs1_l]       \n\t"
-        "subq_s.ph    %[vp8_filter_r], %[vps1_r],       %[vqs1_r]       \n\t"
-
-        : [vp8_filter_l] "=&r" (vp8_filter_l), [vp8_filter_r] "=r" (vp8_filter_r),
-          [subr_l] "=&r" (subr_l), [subr_r] "=&r" (subr_r)
-        : [vps0_l] "r" (vps0_l), [vps0_r] "r" (vps0_r), [vps1_l] "r" (vps1_l),
-          [vps1_r] "r" (vps1_r), [vqs0_l] "r" (vqs0_l), [vqs0_r] "r" (vqs0_r),
-          [vqs1_l] "r" (vqs1_l), [vqs1_r] "r" (vqs1_r)
-    );
-
-    vps2_l = vps2 & HWM;
-    vps2_r = vps2 << 8;
-    vps2_r = vps2_r & HWM;
-
-    /* add outer taps if we have high edge variance */
-    __asm__ __volatile__ (
-        /* vp8_filter = vp8_signed_char_clamp(vp8_filter + 3 * (qs0 - ps0)); */
-        "addq_s.ph    %[vp8_filter_l], %[vp8_filter_l], %[subr_l]       \n\t"
-        "addq_s.ph    %[vp8_filter_r], %[vp8_filter_r], %[subr_r]       \n\t"
-        "and          %[mask_l],       %[HWM],          %[mask]         \n\t"
-        "sll          %[mask_r],       %[mask],         8               \n\t"
-        "and          %[mask_r],       %[HWM],          %[mask_r]       \n\t"
-        "addq_s.ph    %[vp8_filter_l], %[vp8_filter_l], %[subr_l]       \n\t"
-        "addq_s.ph    %[vp8_filter_r], %[vp8_filter_r], %[subr_r]       \n\t"
-        "and          %[hev_l],        %[HWM],          %[hev]          \n\t"
-        "sll          %[hev_r],        %[hev],          8               \n\t"
-        "and          %[hev_r],        %[HWM],          %[hev_r]        \n\t"
-        "addq_s.ph    %[vp8_filter_l], %[vp8_filter_l], %[subr_l]       \n\t"
-        "addq_s.ph    %[vp8_filter_r], %[vp8_filter_r], %[subr_r]       \n\t"
-
-        /* vp8_filter &= mask; */
-        "and          %[vp8_filter_l], %[vp8_filter_l], %[mask_l]       \n\t"
-        "and          %[vp8_filter_r], %[vp8_filter_r], %[mask_r]       \n\t"
-
-        /* Filter2 = vp8_filter & hev; */
-        "and          %[Filter2_l],    %[vp8_filter_l], %[hev_l]        \n\t"
-        "and          %[Filter2_r],    %[vp8_filter_r], %[hev_r]        \n\t"
-
-        : [vp8_filter_l] "+r" (vp8_filter_l), [vp8_filter_r] "+r" (vp8_filter_r),
-          [hev_l] "=&r" (hev_l), [hev_r] "=&r" (hev_r),
-          [mask_l] "=&r" (mask_l), [mask_r] "=&r" (mask_r),
-          [Filter2_l] "=&r" (Filter2_l), [Filter2_r] "=&r" (Filter2_r)
-        : [subr_l] "r" (subr_l), [subr_r] "r" (subr_r),
-          [HWM] "r" (HWM), [hev]  "r" (hev), [mask] "r" (mask)
-    );
-
-    /* save bottom 3 bits so that we round one side +4 and the other +3 */
-    __asm__ __volatile__ (
-        /* Filter1 = vp8_signed_char_clamp(Filter2 + 4) >>= 3; */
-        "addq_s.ph    %[Filter1_l],    %[Filter2_l],    %[t2]           \n\t"
-        "xor          %[invhev_l],     %[hev_l],        %[HWM]          \n\t"
-        "addq_s.ph    %[Filter1_r],    %[Filter2_r],    %[t2]           \n\t"
-
-        /* Filter2 = vp8_signed_char_clamp(Filter2 + 3) >>= 3; */
-        "addq_s.ph    %[Filter2_l],    %[Filter2_l],    %[t1]           \n\t"
-        "addq_s.ph    %[Filter2_r],    %[Filter2_r],    %[t1]           \n\t"
-
-        "shra.ph      %[Filter1_l],    %[Filter1_l],    3               \n\t"
-        "shra.ph      %[Filter1_r],    %[Filter1_r],    3               \n\t"
-
-        "shra.ph      %[Filter2_l],    %[Filter2_l],    3               \n\t"
-        "shra.ph      %[Filter2_r],    %[Filter2_r],    3               \n\t"
-        "and          %[Filter1_l],    %[Filter1_l],    %[HWM]          \n\t"
-        "and          %[Filter1_r],    %[Filter1_r],    %[HWM]          \n\t"
-        "xor          %[invhev_r],     %[hev_r],        %[HWM]          \n\t"
-
-        /* qs0 = vp8_signed_char_clamp(qs0 - Filter1); */
-        "subq_s.ph    %[vqs0_l],       %[vqs0_l],       %[Filter1_l]    \n\t"
-        "subq_s.ph    %[vqs0_r],       %[vqs0_r],       %[Filter1_r]    \n\t"
-
-        /* ps0 = vp8_signed_char_clamp(ps0 + Filter2); */
-        "addq_s.ph    %[vps0_l],       %[vps0_l],       %[Filter2_l]    \n\t"
-        "addq_s.ph    %[vps0_r],       %[vps0_r],       %[Filter2_r]    \n\t"
-
-        : [invhev_l] "=&r" (invhev_l), [invhev_r] "=&r" (invhev_r),
-          [Filter1_l] "=&r" (Filter1_l), [Filter1_r] "=&r" (Filter1_r),
-          [Filter2_l] "+r" (Filter2_l), [Filter2_r] "+r" (Filter2_r),
-          [vps0_l] "+r" (vps0_l), [vps0_r] "+r" (vps0_r),
-          [vqs0_l] "+r" (vqs0_l), [vqs0_r] "+r" (vqs0_r)
-        : [t1] "r" (t1), [t2] "r" (t2), [HWM] "r" (HWM),
-          [hev_l] "r" (hev_l), [hev_r] "r" (hev_r)
-    );
-
-    /* only apply wider filter if not high edge variance */
-    __asm__ __volatile__ (
-        /* vp8_filter &= ~hev; */
-        "and          %[Filter2_l],    %[vp8_filter_l], %[invhev_l]     \n\t"
-        "and          %[Filter2_r],    %[vp8_filter_r], %[invhev_r]     \n\t"
-
-        "shra.ph      %[Filter2_l],    %[Filter2_l],    8               \n\t"
-        "shra.ph      %[Filter2_r],    %[Filter2_r],    8               \n\t"
-
-        : [Filter2_l] "=&r" (Filter2_l), [Filter2_r] "=&r" (Filter2_r)
-        : [vp8_filter_l] "r" (vp8_filter_l), [vp8_filter_r] "r" (vp8_filter_r),
-          [invhev_l] "r" (invhev_l), [invhev_r] "r" (invhev_r)
-    );
-
-    /* roughly 3/7th difference across boundary */
-    __asm__ __volatile__ (
-        "shll.ph      %[u3_l],         %[Filter2_l],    3               \n\t"
-        "shll.ph      %[u3_r],         %[Filter2_r],    3               \n\t"
-
-        "addq.ph      %[u3_l],         %[u3_l],         %[Filter2_l]    \n\t"
-        "addq.ph      %[u3_r],         %[u3_r],         %[Filter2_r]    \n\t"
-
-        "shll.ph      %[u2_l],         %[u3_l],         1               \n\t"
-        "shll.ph      %[u2_r],         %[u3_r],         1               \n\t"
-
-        "addq.ph      %[u1_l],         %[u3_l],         %[u2_l]         \n\t"
-        "addq.ph      %[u1_r],         %[u3_r],         %[u2_r]         \n\t"
-
-        "addq.ph      %[u2_l],         %[u2_l],         %[R63]          \n\t"
-        "addq.ph      %[u2_r],         %[u2_r],         %[R63]          \n\t"
-
-        "addq.ph      %[u3_l],         %[u3_l],         %[R63]          \n\t"
-        "addq.ph      %[u3_r],         %[u3_r],         %[R63]          \n\t"
-
-        /* vp8_signed_char_clamp((63 + Filter2 * 27) >> 7)
-         * vp8_signed_char_clamp((63 + Filter2 * 18) >> 7)
-         */
-        "addq.ph      %[u1_l],         %[u1_l],         %[R63]          \n\t"
-        "addq.ph      %[u1_r],         %[u1_r],         %[R63]          \n\t"
-        "shra.ph      %[u1_l],         %[u1_l],         7               \n\t"
-        "shra.ph      %[u1_r],         %[u1_r],         7               \n\t"
-        "shra.ph      %[u2_l],         %[u2_l],         7               \n\t"
-        "shra.ph      %[u2_r],         %[u2_r],         7               \n\t"
-        "shll.ph      %[u1_l],         %[u1_l],         8               \n\t"
-        "shll.ph      %[u1_r],         %[u1_r],         8               \n\t"
-        "shll.ph      %[u2_l],         %[u2_l],         8               \n\t"
-        "shll.ph      %[u2_r],         %[u2_r],         8               \n\t"
-
-        /* vqs0 = vp8_signed_char_clamp(qs0 - u); */
-        "subq_s.ph    %[vqs0_l],       %[vqs0_l],       %[u1_l]         \n\t"
-        "subq_s.ph    %[vqs0_r],       %[vqs0_r],       %[u1_r]         \n\t"
-
-        /* vps0 = vp8_signed_char_clamp(ps0 + u); */
-        "addq_s.ph    %[vps0_l],       %[vps0_l],       %[u1_l]         \n\t"
-        "addq_s.ph    %[vps0_r],       %[vps0_r],       %[u1_r]         \n\t"
-
-        : [u1_l] "=&r" (u1_l), [u1_r] "=&r" (u1_r), [u2_l] "=&r" (u2_l),
-          [u2_r] "=&r" (u2_r), [u3_l] "=&r" (u3_l), [u3_r] "=&r" (u3_r),
-          [vps0_l] "+r" (vps0_l), [vps0_r] "+r" (vps0_r),
-          [vqs0_l] "+r" (vqs0_l), [vqs0_r] "+r" (vqs0_r)
-        : [R63]  "r" (R63),
-          [Filter2_l] "r" (Filter2_l), [Filter2_r] "r" (Filter2_r)
-    );
-
-    __asm__ __volatile__ (
-        /* vqs1 = vp8_signed_char_clamp(qs1 - u); */
-        "subq_s.ph    %[vqs1_l],       %[vqs1_l],       %[u2_l]         \n\t"
-        "addq_s.ph    %[vps1_l],       %[vps1_l],       %[u2_l]         \n\t"
-
-        /* vps1 = vp8_signed_char_clamp(ps1 + u); */
-        "addq_s.ph    %[vps1_r],       %[vps1_r],       %[u2_r]         \n\t"
-        "subq_s.ph    %[vqs1_r],       %[vqs1_r],       %[u2_r]         \n\t"
-
-        : [vps1_l] "+r" (vps1_l), [vps1_r] "+r" (vps1_r),
-          [vqs1_l] "+r" (vqs1_l), [vqs1_r] "+r" (vqs1_r)
-        : [u2_l] "r" (u2_l), [u2_r] "r" (u2_r)
-    );
-
-    /* roughly 1/7th difference across boundary */
-    __asm__ __volatile__ (
-        /* u = vp8_signed_char_clamp((63 + Filter2 * 9) >> 7); */
-        "shra.ph      %[u3_l],         %[u3_l],         7               \n\t"
-        "shra.ph      %[u3_r],         %[u3_r],         7               \n\t"
-        "shll.ph      %[u3_l],         %[u3_l],         8               \n\t"
-        "shll.ph      %[u3_r],         %[u3_r],         8               \n\t"
-
-        /* vqs2 = vp8_signed_char_clamp(qs2 - u); */
-        "subq_s.ph    %[vqs2_l],       %[vqs2_l],       %[u3_l]         \n\t"
-        "subq_s.ph    %[vqs2_r],       %[vqs2_r],       %[u3_r]         \n\t"
-
-        /* vps2 = vp8_signed_char_clamp(ps2 + u); */
-        "addq_s.ph    %[vps2_l],       %[vps2_l],       %[u3_l]         \n\t"
-        "addq_s.ph    %[vps2_r],       %[vps2_r],       %[u3_r]         \n\t"
-
-        : [u3_l] "+r" (u3_l), [u3_r] "+r" (u3_r), [vps2_l] "+r" (vps2_l),
-          [vps2_r] "+r" (vps2_r), [vqs2_l] "+r" (vqs2_l), [vqs2_r] "+r" (vqs2_r)
-        :
-    );
-
-    /* Create quad-bytes from halfword pairs */
-    __asm__ __volatile__ (
-        "and          %[vqs0_l],       %[vqs0_l],       %[HWM]          \n\t"
-        "shrl.ph      %[vqs0_r],       %[vqs0_r],       8               \n\t"
-
-        "and          %[vps0_l],       %[vps0_l],       %[HWM]          \n\t"
-        "shrl.ph      %[vps0_r],       %[vps0_r],       8               \n\t"
-
-        "and          %[vqs1_l],       %[vqs1_l],       %[HWM]          \n\t"
-        "shrl.ph      %[vqs1_r],       %[vqs1_r],       8               \n\t"
-
-        "and          %[vps1_l],       %[vps1_l],       %[HWM]          \n\t"
-        "shrl.ph      %[vps1_r],       %[vps1_r],       8               \n\t"
-
-        "and          %[vqs2_l],       %[vqs2_l],       %[HWM]          \n\t"
-        "shrl.ph      %[vqs2_r],       %[vqs2_r],       8               \n\t"
-
-        "and          %[vps2_l],       %[vps2_l],       %[HWM]          \n\t"
-        "shrl.ph      %[vps2_r],       %[vps2_r],       8               \n\t"
-
-        "or           %[vqs0_r],       %[vqs0_l],       %[vqs0_r]       \n\t"
-        "or           %[vps0_r],       %[vps0_l],       %[vps0_r]       \n\t"
-        "or           %[vqs1_r],       %[vqs1_l],       %[vqs1_r]       \n\t"
-        "or           %[vps1_r],       %[vps1_l],       %[vps1_r]       \n\t"
-        "or           %[vqs2_r],       %[vqs2_l],       %[vqs2_r]       \n\t"
-        "or           %[vps2_r],       %[vps2_l],       %[vps2_r]       \n\t"
-
-        : [vps1_l] "+r" (vps1_l), [vps1_r] "+r" (vps1_r), [vqs1_l] "+r" (vqs1_l),
-          [vqs1_r] "+r" (vqs1_r), [vps0_l] "+r" (vps0_l), [vps0_r] "+r" (vps0_r),
-          [vqs0_l] "+r" (vqs0_l), [vqs0_r] "+r" (vqs0_r), [vqs2_l] "+r" (vqs2_l),
-          [vqs2_r] "+r" (vqs2_r), [vps2_r] "+r" (vps2_r), [vps2_l] "+r" (vps2_l)
-        : [HWM] "r" (HWM)
-    );
-
-    *ps0 = vps0_r ^ N128;
-    *ps1 = vps1_r ^ N128;
-    *ps2 = vps2_r ^ N128;
-    *qs0 = vqs0_r ^ N128;
-    *qs1 = vqs1_r ^ N128;
-    *qs2 = vqs2_r ^ N128;
-}
-
-void vp8_mbloop_filter_horizontal_edge_mips
-(
-    unsigned char *s,
-    int p,
-    unsigned int flimit,
-    unsigned int limit,
-    unsigned int thresh,
-    int count
-)
-{
-    int i;
-    uint32_t mask, hev;
-    uint32_t pm1, p0, p1, p2, p3, p4, p5, p6;
-    unsigned char *sm1, *s0, *s1, *s2, *s3, *s4, *s5, *s6;
-
-    mask = 0;
-    hev = 0;
-    i = 0;
-    p1 = 0;
-    p2 = 0;
-    p3 = 0;
-    p4 = 0;
-
-    /* loop filter designed to work using chars so that we can make maximum use
-     * of 8 bit simd instructions.
-     */
-
-    sm1 = s - (p << 2);
-    s0  = s - p - p - p;
-    s1  = s - p - p;
-    s2  = s - p;
-    s3  = s;
-    s4  = s + p;
-    s5  = s + p + p;
-    s6  = s + p + p + p;
-
-    /* prefetch data for load */
-    prefetch_load_lf(s + p);
-
-    /* apply filter on 4 pixesl at the same time */
-    do
-    {
-        /* load quad-byte vectors
-         * memory is 4 byte aligned
-         */
-        p1 = *((uint32_t *)(s1));
-        p2 = *((uint32_t *)(s2));
-        p3 = *((uint32_t *)(s3));
-        p4 = *((uint32_t *)(s4));
-
-        /* if (p1 - p4 == 0) and (p2 - p3 == 0)
-         * mask will be zero and filtering is not needed
-         */
-        if (!(((p1 - p4) == 0) && ((p2 - p3) == 0)))
-        {
-
-            pm1 = *((uint32_t *)(sm1));
-            p0  = *((uint32_t *)(s0));
-            p5  = *((uint32_t *)(s5));
-            p6  = *((uint32_t *)(s6));
-
-            vp8_filter_mask_vec_mips(limit, flimit, p1, p2, pm1, p0, p3, p4, p5, p6,
-                                     thresh, &hev, &mask);
-
-            /* if mask == 0 do filtering is not needed */
-            if (mask)
-            {
-                /* filtering */
-                vp8_mbfilter_mips(mask, hev, &p0, &p1, &p2, &p3, &p4, &p5);
-
-                /* unpack processed 4x4 neighborhood
-                 * memory is 4 byte aligned
-                 */
-                *((uint32_t *)s0) = p0;
-                *((uint32_t *)s1) = p1;
-                *((uint32_t *)s2) = p2;
-                *((uint32_t *)s3) = p3;
-                *((uint32_t *)s4) = p4;
-                *((uint32_t *)s5) = p5;
-            }
-        }
-
-        sm1 += 4;
-        s0  += 4;
-        s1  += 4;
-        s2  += 4;
-        s3  += 4;
-        s4  += 4;
-        s5  += 4;
-        s6  += 4;
-
-        /* load quad-byte vectors
-         * memory is 4 byte aligned
-         */
-        p1 = *((uint32_t *)(s1));
-        p2 = *((uint32_t *)(s2));
-        p3 = *((uint32_t *)(s3));
-        p4 = *((uint32_t *)(s4));
-
-        /* if (p1 - p4 == 0) and (p2 - p3 == 0)
-         * mask will be zero and filtering is not needed
-         */
-        if (!(((p1 - p4) == 0) && ((p2 - p3) == 0)))
-        {
-
-            pm1 = *((uint32_t *)(sm1));
-            p0  = *((uint32_t *)(s0));
-            p5  = *((uint32_t *)(s5));
-            p6  = *((uint32_t *)(s6));
-
-            vp8_filter_mask_vec_mips(limit, flimit, p1, p2, pm1, p0, p3, p4, p5, p6,
-                                     thresh, &hev, &mask);
-
-            /* if mask == 0 do filtering is not needed */
-            if (mask)
-            {
-                /* filtering */
-                vp8_mbfilter_mips(mask, hev, &p0, &p1, &p2, &p3, &p4, &p5);
-
-                /* unpack processed 4x4 neighborhood
-                 * memory is 4 byte aligned
-                 */
-                *((uint32_t *)s0) = p0;
-                *((uint32_t *)s1) = p1;
-                *((uint32_t *)s2) = p2;
-                *((uint32_t *)s3) = p3;
-                *((uint32_t *)s4) = p4;
-                *((uint32_t *)s5) = p5;
-            }
-        }
-
-        sm1 += 4;
-        s0  += 4;
-        s1  += 4;
-        s2  += 4;
-        s3  += 4;
-        s4  += 4;
-        s5  += 4;
-        s6  += 4;
-
-        i += 8;
-    }
-
-    while (i < count);
-}
-
-void vp8_mbloop_filter_uvhorizontal_edge_mips
-(
-    unsigned char *s,
-    int p,
-    unsigned int flimit,
-    unsigned int limit,
-    unsigned int thresh,
-    int count
-)
-{
-    uint32_t mask, hev;
-    uint32_t pm1, p0, p1, p2, p3, p4, p5, p6;
-    unsigned char *sm1, *s0, *s1, *s2, *s3, *s4, *s5, *s6;
-
-    mask = 0;
-    hev = 0;
-    p1 = 0;
-    p2 = 0;
-    p3 = 0;
-    p4 = 0;
-
-    /* loop filter designed to work using chars so that we can make maximum use
-     * of 8 bit simd instructions.
-     */
-
-    sm1 = s - (p << 2);
-    s0  = s - p - p - p;
-    s1  = s - p - p;
-    s2  = s - p;
-    s3  = s;
-    s4  = s + p;
-    s5  = s + p + p;
-    s6  = s + p + p + p;
-
-    /* load quad-byte vectors
-     * memory is 4 byte aligned
-     */
-    p1 = *((uint32_t *)(s1));
-    p2 = *((uint32_t *)(s2));
-    p3 = *((uint32_t *)(s3));
-    p4 = *((uint32_t *)(s4));
-
-    /* if (p1 - p4 == 0) and (p2 - p3 == 0)
-     * mask will be zero and filtering is not needed
-     */
-    if (!(((p1 - p4) == 0) && ((p2 - p3) == 0)))
-    {
-
-        pm1 = *((uint32_t *)(sm1));
-        p0  = *((uint32_t *)(s0));
-        p5  = *((uint32_t *)(s5));
-        p6  = *((uint32_t *)(s6));
-
-        /* if mask == 0 do filtering is not needed */
-        vp8_filter_mask_vec_mips(limit, flimit, p1, p2, pm1, p0, p3, p4, p5, p6,
-                                 thresh, &hev, &mask);
-
-        if (mask)
-        {
-            /* filtering */
-            vp8_mbfilter_mips(mask, hev, &p0, &p1, &p2, &p3, &p4, &p5);
-
-            /* unpack processed 4x4 neighborhood
-             * memory is 4 byte aligned
-             */
-            *((uint32_t *)s0) = p0;
-            *((uint32_t *)s1) = p1;
-            *((uint32_t *)s2) = p2;
-            *((uint32_t *)s3) = p3;
-            *((uint32_t *)s4) = p4;
-            *((uint32_t *)s5) = p5;
-        }
-    }
-
-    sm1 += 4;
-    s0  += 4;
-    s1  += 4;
-    s2  += 4;
-    s3  += 4;
-    s4  += 4;
-    s5  += 4;
-    s6  += 4;
-
-    /* load quad-byte vectors
-     * memory is 4 byte aligned
-     */
-    p1 = *((uint32_t *)(s1));
-    p2 = *((uint32_t *)(s2));
-    p3 = *((uint32_t *)(s3));
-    p4 = *((uint32_t *)(s4));
-
-    /* if (p1 - p4 == 0) and (p2 - p3 == 0)
-     * mask will be zero and filtering is not needed
-     */
-    if (!(((p1 - p4) == 0) && ((p2 - p3) == 0)))
-    {
-
-        pm1 = *((uint32_t *)(sm1));
-        p0  = *((uint32_t *)(s0));
-        p5  = *((uint32_t *)(s5));
-        p6  = *((uint32_t *)(s6));
-
-        vp8_filter_mask_vec_mips(limit, flimit, p1, p2, pm1, p0, p3, p4, p5, p6,
-                                 thresh, &hev, &mask);
-
-        /* if mask == 0 do filtering is not needed */
-        if (mask)
-        {
-            /* filtering */
-            vp8_mbfilter_mips(mask, hev, &p0, &p1, &p2, &p3, &p4, &p5);
-
-            /* unpack processed 4x4 neighborhood
-             * memory is 4 byte aligned
-             */
-            *((uint32_t *)s0) = p0;
-            *((uint32_t *)s1) = p1;
-            *((uint32_t *)s2) = p2;
-            *((uint32_t *)s3) = p3;
-            *((uint32_t *)s4) = p4;
-            *((uint32_t *)s5) = p5;
-        }
-    }
-}
-
-
-void vp8_mbloop_filter_vertical_edge_mips
-(
-    unsigned char *s,
-    int p,
-    unsigned int flimit,
-    unsigned int limit,
-    unsigned int thresh,
-    int count
-)
-{
-
-    int i;
-    uint32_t mask, hev;
-    uint32_t pm1, p0, p1, p2, p3, p4, p5, p6;
-    unsigned char *s1, *s2, *s3, *s4;
-    uint32_t prim1, prim2, sec3, sec4, prim3, prim4;
-
-    mask = 0;
-    hev = 0;
-    i = 0;
-    pm1 = 0;
-    p0 = 0;
-    p1 = 0;
-    p2 = 0;
-    p3 = 0;
-    p4 = 0;
-    p5 = 0;
-    p6 = 0;
-
-    /* loop filter designed to work using chars so that we can make maximum use
-     * of 8 bit simd instructions.
-     */
-
-    /* apply filter on 4 pixesl at the same time */
-    do
-    {
-        s1 = s;
-        s2 = s + p;
-        s3 = s2 + p;
-        s4 = s3 + p;
-        s  = s4 + p;
-
-        /* load quad-byte vectors
-         * memory is 4 byte aligned
-         */
-        p2  = *((uint32_t *)(s1 - 4));
-        p6  = *((uint32_t *)(s1));
-        p1  = *((uint32_t *)(s2 - 4));
-        p5  = *((uint32_t *)(s2));
-        p0  = *((uint32_t *)(s3 - 4));
-        p4  = *((uint32_t *)(s3));
-        pm1 = *((uint32_t *)(s4 - 4));
-        p3  = *((uint32_t *)(s4));
-
-        /* transpose pm1, p0, p1, p2 */
-        __asm__ __volatile__ (
-            "precrq.qb.ph   %[prim1],   %[p2],      %[p1]       \n\t"
-            "precr.qb.ph    %[prim2],   %[p2],      %[p1]       \n\t"
-            "precrq.qb.ph   %[prim3],   %[p0],      %[pm1]      \n\t"
-            "precr.qb.ph    %[prim4],   %[p0],      %[pm1]      \n\t"
-
-            "precrq.qb.ph   %[p1],      %[prim1],   %[prim2]    \n\t"
-            "precr.qb.ph    %[pm1],     %[prim1],   %[prim2]    \n\t"
-            "precrq.qb.ph   %[sec3],    %[prim3],   %[prim4]    \n\t"
-            "precr.qb.ph    %[sec4],    %[prim3],   %[prim4]    \n\t"
-
-            "precrq.ph.w    %[p2],      %[p1],      %[sec3]     \n\t"
-            "precrq.ph.w    %[p0],      %[pm1],     %[sec4]     \n\t"
-            "append         %[p1],      %[sec3],    16          \n\t"
-            "append         %[pm1],     %[sec4],    16          \n\t"
-
-            : [prim1] "=&r" (prim1), [prim2] "=&r" (prim2),
-              [prim3] "=&r" (prim3), [prim4] "=&r" (prim4),
-              [p2] "+r" (p2), [p1] "+r" (p1), [p0] "+r" (p0), [pm1] "+r" (pm1),
-              [sec3] "=&r" (sec3), [sec4] "=&r" (sec4)
-            :
-        );
-
-        /* transpose p3, p4, p5, p6 */
-        __asm__ __volatile__ (
-            "precrq.qb.ph   %[prim1],   %[p6],      %[p5]       \n\t"
-            "precr.qb.ph    %[prim2],   %[p6],      %[p5]       \n\t"
-            "precrq.qb.ph   %[prim3],   %[p4],      %[p3]       \n\t"
-            "precr.qb.ph    %[prim4],   %[p4],      %[p3]       \n\t"
-
-            "precrq.qb.ph   %[p5],      %[prim1],   %[prim2]    \n\t"
-            "precr.qb.ph    %[p3],      %[prim1],   %[prim2]    \n\t"
-            "precrq.qb.ph   %[sec3],    %[prim3],   %[prim4]    \n\t"
-            "precr.qb.ph    %[sec4],    %[prim3],   %[prim4]    \n\t"
-
-            "precrq.ph.w    %[p6],      %[p5],      %[sec3]     \n\t"
-            "precrq.ph.w    %[p4],      %[p3],      %[sec4]     \n\t"
-            "append         %[p5],      %[sec3],    16          \n\t"
-            "append         %[p3],      %[sec4],    16          \n\t"
-
-            : [prim1] "=&r" (prim1), [prim2] "=&r" (prim2),
-              [prim3] "=&r" (prim3), [prim4] "=&r" (prim4),
-              [p6] "+r" (p6), [p5] "+r" (p5), [p4] "+r" (p4), [p3] "+r" (p3),
-              [sec3] "=&r" (sec3), [sec4] "=&r" (sec4)
-            :
-        );
-
-        /* if (p1 - p4 == 0) and (p2 - p3 == 0)
-         * mask will be zero and filtering is not needed
-         */
-        if (!(((p1 - p4) == 0) && ((p2 - p3) == 0)))
-        {
-
-            vp8_filter_mask_vec_mips(limit, flimit, p1, p2, pm1, p0, p3, p4, p5, p6,
-                                     thresh, &hev, &mask);
-
-            /* if mask == 0 do filtering is not needed */
-            if (mask)
-            {
-                /* filtering */
-                vp8_mbfilter_mips(mask, hev, &p0, &p1, &p2, &p3, &p4, &p5);
-
-                /* don't use transpose on output data
-                 * because memory isn't aligned
-                 */
-                __asm__ __volatile__ (
-                    "sb         %[p5],  2(%[s4])        \n\t"
-                    "sb         %[p4],  1(%[s4])        \n\t"
-                    "sb         %[p3],  0(%[s4])        \n\t"
-                    "sb         %[p2], -1(%[s4])        \n\t"
-                    "sb         %[p1], -2(%[s4])        \n\t"
-                    "sb         %[p0], -3(%[s4])        \n\t"
-                    :
-                    : [p5] "r" (p5), [p4] "r" (p4), [p3] "r" (p3), [s4] "r" (s4),
-                      [p2] "r" (p2), [p1] "r" (p1), [p0] "r" (p0)
-                );
-
-                __asm__ __volatile__ (
-                    "srl        %[p5], %[p5], 8         \n\t"
-                    "srl        %[p4], %[p4], 8         \n\t"
-                    "srl        %[p3], %[p3], 8         \n\t"
-                    "srl        %[p2], %[p2], 8         \n\t"
-                    "srl        %[p1], %[p1], 8         \n\t"
-                    "srl        %[p0], %[p0], 8         \n\t"
-                    : [p5] "+r" (p5), [p4] "+r" (p4), [p3] "+r" (p3),
-                      [p2] "+r" (p2), [p1] "+r" (p1), [p0] "+r" (p0)
-                    :
-                );
-
-                __asm__ __volatile__ (
-                    "sb         %[p5],  2(%[s3])        \n\t"
-                    "sb         %[p4],  1(%[s3])        \n\t"
-                    "sb         %[p3],  0(%[s3])        \n\t"
-                    "sb         %[p2], -1(%[s3])        \n\t"
-                    "sb         %[p1], -2(%[s3])        \n\t"
-                    "sb         %[p0], -3(%[s3])        \n\t"
-                    :
-                    : [p5] "r" (p5), [p4] "r" (p4), [p3] "r" (p3), [s3] "r" (s3),
-                      [p2] "r" (p2), [p1] "r" (p1), [p0] "r" (p0)
-                );
-
-                __asm__ __volatile__ (
-                    "srl        %[p5], %[p5], 8         \n\t"
-                    "srl        %[p4], %[p4], 8         \n\t"
-                    "srl        %[p3], %[p3], 8         \n\t"
-                    "srl        %[p2], %[p2], 8         \n\t"
-                    "srl        %[p1], %[p1], 8         \n\t"
-                    "srl        %[p0], %[p0], 8         \n\t"
-                    : [p5] "+r" (p5), [p4] "+r" (p4), [p3] "+r" (p3),
-                      [p2] "+r" (p2), [p1] "+r" (p1), [p0] "+r" (p0)
-                    :
-                );
-
-                __asm__ __volatile__ (
-                    "sb         %[p5],  2(%[s2])        \n\t"
-                    "sb         %[p4],  1(%[s2])        \n\t"
-                    "sb         %[p3],  0(%[s2])        \n\t"
-                    "sb         %[p2], -1(%[s2])        \n\t"
-                    "sb         %[p1], -2(%[s2])        \n\t"
-                    "sb         %[p0], -3(%[s2])        \n\t"
-                    :
-                    : [p5] "r" (p5), [p4] "r" (p4), [p3] "r" (p3), [s2] "r" (s2),
-                      [p2] "r" (p2), [p1] "r" (p1), [p0] "r" (p0)
-                );
-
-                __asm__ __volatile__ (
-                    "srl        %[p5], %[p5], 8         \n\t"
-                    "srl        %[p4], %[p4], 8         \n\t"
-                    "srl        %[p3], %[p3], 8         \n\t"
-                    "srl        %[p2], %[p2], 8         \n\t"
-                    "srl        %[p1], %[p1], 8         \n\t"
-                    "srl        %[p0], %[p0], 8         \n\t"
-                    : [p5] "+r" (p5), [p4] "+r" (p4), [p3] "+r" (p3),
-                      [p2] "+r" (p2), [p1] "+r" (p1), [p0] "+r" (p0)
-                    :
-                );
-
-                __asm__ __volatile__ (
-                    "sb         %[p5],  2(%[s1])        \n\t"
-                    "sb         %[p4],  1(%[s1])        \n\t"
-                    "sb         %[p3],  0(%[s1])        \n\t"
-                    "sb         %[p2], -1(%[s1])        \n\t"
-                    "sb         %[p1], -2(%[s1])        \n\t"
-                    "sb         %[p0], -3(%[s1])        \n\t"
-                    :
-                    : [p5] "r" (p5), [p4] "r" (p4), [p3] "r" (p3), [s1] "r" (s1),
-                      [p2] "r" (p2), [p1] "r" (p1), [p0] "r" (p0)
-                );
-            }
-        }
-
-        i += 4;
-    }
-
-    while (i < count);
-}
-
-void vp8_mbloop_filter_uvvertical_edge_mips
-(
-    unsigned char *s,
-    int p,
-    unsigned int flimit,
-    unsigned int limit,
-    unsigned int thresh,
-    int count
-)
-{
-    uint32_t mask, hev;
-    uint32_t pm1, p0, p1, p2, p3, p4, p5, p6;
-    unsigned char *s1, *s2, *s3, *s4;
-    uint32_t prim1, prim2, sec3, sec4, prim3, prim4;
-
-    mask = 0;
-    hev = 0;
-    pm1 = 0;
-    p0 = 0;
-    p1 = 0;
-    p2 = 0;
-    p3 = 0;
-    p4 = 0;
-    p5 = 0;
-    p6 = 0;
-
-    /* loop filter designed to work using chars so that we can make maximum use
-     * of 8 bit simd instructions.
-     */
-
-    /* apply filter on 4 pixesl at the same time */
-
-    s1 = s;
-    s2 = s + p;
-    s3 = s2 + p;
-    s4 = s3 + p;
-
-    /* prefetch data for load */
-    prefetch_load_lf(s + 2 * p);
-
-    /* load quad-byte vectors
-     * memory is 4 byte aligned
-     */
-    p2  = *((uint32_t *)(s1 - 4));
-    p6  = *((uint32_t *)(s1));
-    p1  = *((uint32_t *)(s2 - 4));
-    p5  = *((uint32_t *)(s2));
-    p0  = *((uint32_t *)(s3 - 4));
-    p4  = *((uint32_t *)(s3));
-    pm1 = *((uint32_t *)(s4 - 4));
-    p3  = *((uint32_t *)(s4));
-
-    /* transpose pm1, p0, p1, p2 */
-    __asm__ __volatile__ (
-        "precrq.qb.ph   %[prim1],   %[p2],      %[p1]       \n\t"
-        "precr.qb.ph    %[prim2],   %[p2],      %[p1]       \n\t"
-        "precrq.qb.ph   %[prim3],   %[p0],      %[pm1]      \n\t"
-        "precr.qb.ph    %[prim4],   %[p0],      %[pm1]      \n\t"
-
-        "precrq.qb.ph   %[p1],      %[prim1],   %[prim2]    \n\t"
-        "precr.qb.ph    %[pm1],     %[prim1],   %[prim2]    \n\t"
-        "precrq.qb.ph   %[sec3],    %[prim3],   %[prim4]    \n\t"
-        "precr.qb.ph    %[sec4],    %[prim3],   %[prim4]    \n\t"
-
-        "precrq.ph.w    %[p2],      %[p1],      %[sec3]     \n\t"
-        "precrq.ph.w    %[p0],      %[pm1],     %[sec4]     \n\t"
-        "append         %[p1],      %[sec3],    16          \n\t"
-        "append         %[pm1],     %[sec4],    16          \n\t"
-
-        : [prim1] "=&r" (prim1), [prim2] "=&r" (prim2),
-          [prim3] "=&r" (prim3), [prim4] "=&r" (prim4),
-          [p2] "+r" (p2), [p1] "+r" (p1), [p0] "+r" (p0), [pm1] "+r" (pm1),
-          [sec3] "=&r" (sec3), [sec4] "=&r" (sec4)
-        :
-    );
-
-    /* transpose p3, p4, p5, p6 */
-    __asm__ __volatile__ (
-        "precrq.qb.ph   %[prim1],   %[p6],      %[p5]       \n\t"
-        "precr.qb.ph    %[prim2],   %[p6],      %[p5]       \n\t"
-        "precrq.qb.ph   %[prim3],   %[p4],      %[p3]       \n\t"
-        "precr.qb.ph    %[prim4],   %[p4],      %[p3]       \n\t"
-
-        "precrq.qb.ph   %[p5],      %[prim1],   %[prim2]    \n\t"
-        "precr.qb.ph    %[p3],      %[prim1],   %[prim2]    \n\t"
-        "precrq.qb.ph   %[sec3],    %[prim3],   %[prim4]    \n\t"
-        "precr.qb.ph    %[sec4],    %[prim3],   %[prim4]    \n\t"
-
-        "precrq.ph.w    %[p6],      %[p5],      %[sec3]     \n\t"
-        "precrq.ph.w    %[p4],      %[p3],      %[sec4]     \n\t"
-        "append         %[p5],      %[sec3],    16          \n\t"
-        "append         %[p3],      %[sec4],    16          \n\t"
-
-        : [prim1] "=&r" (prim1), [prim2] "=&r" (prim2),
-          [prim3] "=&r" (prim3), [prim4] "=&r" (prim4),
-          [p6] "+r" (p6), [p5] "+r" (p5), [p4] "+r" (p4), [p3] "+r" (p3),
-          [sec3] "=&r" (sec3), [sec4] "=&r" (sec4)
-        :
-    );
-
-    /* if (p1 - p4 == 0) and (p2 - p3 == 0)
-     * mask will be zero and filtering is not needed
-     */
-    if (!(((p1 - p4) == 0) && ((p2 - p3) == 0)))
-    {
-
-        vp8_filter_mask_vec_mips(limit, flimit, p1, p2, pm1, p0, p3, p4, p5, p6,
-                                 thresh, &hev, &mask);
-
-        /* if mask == 0 do filtering is not needed */
-        if (mask)
-        {
-            /* filtering */
-            vp8_mbfilter_mips(mask, hev, &p0, &p1, &p2, &p3, &p4, &p5);
-
-            /* don't use transpose on output data
-             * because memory isn't aligned
-             */
-            __asm__ __volatile__ (
-                "sb         %[p5],  2(%[s4])        \n\t"
-                "sb         %[p4],  1(%[s4])        \n\t"
-                "sb         %[p3],  0(%[s4])        \n\t"
-                "sb         %[p2], -1(%[s4])        \n\t"
-                "sb         %[p1], -2(%[s4])        \n\t"
-                "sb         %[p0], -3(%[s4])        \n\t"
-                :
-                : [p5] "r" (p5), [p4] "r" (p4), [p3] "r" (p3), [s4] "r" (s4),
-                  [p2] "r" (p2), [p1] "r" (p1), [p0] "r" (p0)
-            );
-
-            __asm__ __volatile__ (
-                "srl        %[p5], %[p5], 8         \n\t"
-                "srl        %[p4], %[p4], 8         \n\t"
-                "srl        %[p3], %[p3], 8         \n\t"
-                "srl        %[p2], %[p2], 8         \n\t"
-                "srl        %[p1], %[p1], 8         \n\t"
-                "srl        %[p0], %[p0], 8         \n\t"
-                : [p5] "+r" (p5), [p4] "+r" (p4), [p3] "+r" (p3),
-                  [p2] "+r" (p2), [p1] "+r" (p1), [p0] "+r" (p0)
-                :
-            );
-
-            __asm__ __volatile__ (
-                "sb         %[p5],  2(%[s3])        \n\t"
-                "sb         %[p4],  1(%[s3])        \n\t"
-                "sb         %[p3],  0(%[s3])        \n\t"
-                "sb         %[p2], -1(%[s3])        \n\t"
-                "sb         %[p1], -2(%[s3])        \n\t"
-                "sb         %[p0], -3(%[s3])        \n\t"
-                :
-                : [p5] "r" (p5), [p4] "r" (p4), [p3] "r" (p3), [s3] "r" (s3),
-                  [p2] "r" (p2), [p1] "r" (p1), [p0] "r" (p0)
-            );
-
-            __asm__ __volatile__ (
-                "srl        %[p5], %[p5], 8         \n\t"
-                "srl        %[p4], %[p4], 8         \n\t"
-                "srl        %[p3], %[p3], 8         \n\t"
-                "srl        %[p2], %[p2], 8         \n\t"
-                "srl        %[p1], %[p1], 8         \n\t"
-                "srl        %[p0], %[p0], 8         \n\t"
-                : [p5] "+r" (p5), [p4] "+r" (p4), [p3] "+r" (p3),
-                  [p2] "+r" (p2), [p1] "+r" (p1), [p0] "+r" (p0)
-                :
-            );
-
-            __asm__ __volatile__ (
-                "sb         %[p5],  2(%[s2])        \n\t"
-                "sb         %[p4],  1(%[s2])        \n\t"
-                "sb         %[p3],  0(%[s2])        \n\t"
-                "sb         %[p2], -1(%[s2])        \n\t"
-                "sb         %[p1], -2(%[s2])        \n\t"
-                "sb         %[p0], -3(%[s2])        \n\t"
-                :
-                : [p5] "r" (p5), [p4] "r" (p4), [p3] "r" (p3), [s2] "r" (s2),
-                  [p2] "r" (p2), [p1] "r" (p1), [p0] "r" (p0)
-            );
-
-            __asm__ __volatile__ (
-                "srl        %[p5], %[p5], 8         \n\t"
-                "srl        %[p4], %[p4], 8         \n\t"
-                "srl        %[p3], %[p3], 8         \n\t"
-                "srl        %[p2], %[p2], 8         \n\t"
-                "srl        %[p1], %[p1], 8         \n\t"
-                "srl        %[p0], %[p0], 8         \n\t"
-                : [p5] "+r" (p5), [p4] "+r" (p4), [p3] "+r" (p3),
-                  [p2] "+r" (p2), [p1] "+r" (p1), [p0] "+r" (p0)
-                :
-            );
-
-            __asm__ __volatile__ (
-                "sb         %[p5],  2(%[s1])        \n\t"
-                "sb         %[p4],  1(%[s1])        \n\t"
-                "sb         %[p3],  0(%[s1])        \n\t"
-                "sb         %[p2], -1(%[s1])        \n\t"
-                "sb         %[p1], -2(%[s1])        \n\t"
-                "sb         %[p0], -3(%[s1])        \n\t"
-                :
-                : [p5] "r" (p5), [p4] "r" (p4), [p3] "r" (p3), [s1] "r" (s1),
-                  [p2] "r" (p2), [p1] "r" (p1), [p0] "r" (p0)
-            );
-        }
-    }
-
-    s1 = s4 + p;
-    s2 = s1 + p;
-    s3 = s2 + p;
-    s4 = s3 + p;
-
-    /* load quad-byte vectors
-    * memory is 4 byte aligned
-    */
-    p2  = *((uint32_t *)(s1 - 4));
-    p6  = *((uint32_t *)(s1));
-    p1  = *((uint32_t *)(s2 - 4));
-    p5  = *((uint32_t *)(s2));
-    p0  = *((uint32_t *)(s3 - 4));
-    p4  = *((uint32_t *)(s3));
-    pm1 = *((uint32_t *)(s4 - 4));
-    p3  = *((uint32_t *)(s4));
-
-    /* transpose pm1, p0, p1, p2 */
-    __asm__ __volatile__ (
-        "precrq.qb.ph   %[prim1],   %[p2],      %[p1]       \n\t"
-        "precr.qb.ph    %[prim2],   %[p2],      %[p1]       \n\t"
-        "precrq.qb.ph   %[prim3],   %[p0],      %[pm1]      \n\t"
-        "precr.qb.ph    %[prim4],   %[p0],      %[pm1]      \n\t"
-
-        "precrq.qb.ph   %[p1],      %[prim1],   %[prim2]    \n\t"
-        "precr.qb.ph    %[pm1],     %[prim1],   %[prim2]    \n\t"
-        "precrq.qb.ph   %[sec3],    %[prim3],   %[prim4]    \n\t"
-        "precr.qb.ph    %[sec4],    %[prim3],   %[prim4]    \n\t"
-
-        "precrq.ph.w    %[p2],      %[p1],      %[sec3]     \n\t"
-        "precrq.ph.w    %[p0],      %[pm1],     %[sec4]     \n\t"
-        "append         %[p1],      %[sec3],    16          \n\t"
-        "append         %[pm1],     %[sec4],    16          \n\t"
-
-        : [prim1] "=&r" (prim1), [prim2] "=&r" (prim2),
-          [prim3] "=&r" (prim3), [prim4] "=&r" (prim4),
-          [p2] "+r" (p2), [p1] "+r" (p1), [p0] "+r" (p0), [pm1] "+r" (pm1),
-          [sec3] "=&r" (sec3), [sec4] "=&r" (sec4)
-        :
-    );
-
-    /* transpose p3, p4, p5, p6 */
-    __asm__ __volatile__ (
-        "precrq.qb.ph   %[prim1],   %[p6],      %[p5]       \n\t"
-        "precr.qb.ph    %[prim2],   %[p6],      %[p5]       \n\t"
-        "precrq.qb.ph   %[prim3],   %[p4],      %[p3]       \n\t"
-        "precr.qb.ph    %[prim4],   %[p4],      %[p3]       \n\t"
-
-        "precrq.qb.ph   %[p5],      %[prim1],   %[prim2]    \n\t"
-        "precr.qb.ph    %[p3],      %[prim1],   %[prim2]    \n\t"
-        "precrq.qb.ph   %[sec3],    %[prim3],   %[prim4]    \n\t"
-        "precr.qb.ph    %[sec4],    %[prim3],   %[prim4]    \n\t"
-
-        "precrq.ph.w    %[p6],      %[p5],      %[sec3]     \n\t"
-        "precrq.ph.w    %[p4],      %[p3],      %[sec4]     \n\t"
-        "append         %[p5],      %[sec3],    16          \n\t"
-        "append         %[p3],      %[sec4],    16          \n\t"
-
-        : [prim1] "=&r" (prim1), [prim2] "=&r" (prim2),
-          [prim3] "=&r" (prim3), [prim4] "=&r" (prim4),
-          [p6] "+r" (p6), [p5] "+r" (p5), [p4] "+r" (p4), [p3] "+r" (p3),
-          [sec3] "=&r" (sec3), [sec4] "=&r" (sec4)
-        :
-    );
-
-    /* if (p1 - p4 == 0) and (p2 - p3 == 0)
-     * mask will be zero and filtering is not needed
-     */
-    if (!(((p1 - p4) == 0) && ((p2 - p3) == 0)))
-    {
-
-        vp8_filter_mask_vec_mips(limit, flimit, p1, p2, pm1, p0, p3, p4, p5, p6, thresh, &hev, &mask);
-
-        /* if mask == 0 do filtering is not needed */
-        if (mask)
-        {
-            /* filtering */
-            vp8_mbfilter_mips(mask, hev, &p0, &p1, &p2, &p3, &p4, &p5);
-
-            /* don't use transpose on output data
-             * because memory isn't aligned
-             */
-            __asm__ __volatile__ (
-                "sb         %[p5],  2(%[s4])        \n\t"
-                "sb         %[p4],  1(%[s4])        \n\t"
-                "sb         %[p3],  0(%[s4])        \n\t"
-                "sb         %[p2], -1(%[s4])        \n\t"
-                "sb         %[p1], -2(%[s4])        \n\t"
-                "sb         %[p0], -3(%[s4])        \n\t"
-                :
-                : [p5] "r" (p5), [p4] "r" (p4), [p3] "r" (p3), [s4] "r" (s4),
-                  [p2] "r" (p2), [p1] "r" (p1), [p0] "r" (p0)
-            );
-
-            __asm__ __volatile__ (
-                "srl        %[p5], %[p5], 8         \n\t"
-                "srl        %[p4], %[p4], 8         \n\t"
-                "srl        %[p3], %[p3], 8         \n\t"
-                "srl        %[p2], %[p2], 8         \n\t"
-                "srl        %[p1], %[p1], 8         \n\t"
-                "srl        %[p0], %[p0], 8         \n\t"
-                : [p5] "+r" (p5), [p4] "+r" (p4), [p3] "+r" (p3),
-                  [p2] "+r" (p2), [p1] "+r" (p1), [p0] "+r" (p0)
-                :
-            );
-
-            __asm__ __volatile__ (
-                "sb         %[p5],  2(%[s3])        \n\t"
-                "sb         %[p4],  1(%[s3])        \n\t"
-                "sb         %[p3],  0(%[s3])        \n\t"
-                "sb         %[p2], -1(%[s3])        \n\t"
-                "sb         %[p1], -2(%[s3])        \n\t"
-                "sb         %[p0], -3(%[s3])        \n\t"
-                :
-                : [p5] "r" (p5), [p4] "r" (p4), [p3] "r" (p3), [s3] "r" (s3),
-                  [p2] "r" (p2), [p1] "r" (p1), [p0] "r" (p0)
-            );
-
-            __asm__ __volatile__ (
-                "srl        %[p5], %[p5], 8         \n\t"
-                "srl        %[p4], %[p4], 8         \n\t"
-                "srl        %[p3], %[p3], 8         \n\t"
-                "srl        %[p2], %[p2], 8         \n\t"
-                "srl        %[p1], %[p1], 8         \n\t"
-                "srl        %[p0], %[p0], 8         \n\t"
-                : [p5] "+r" (p5), [p4] "+r" (p4), [p3] "+r" (p3),
-                  [p2] "+r" (p2), [p1] "+r" (p1), [p0] "+r" (p0)
-                :
-            );
-
-            __asm__ __volatile__ (
-                "sb         %[p5],  2(%[s2])        \n\t"
-                "sb         %[p4],  1(%[s2])        \n\t"
-                "sb         %[p3],  0(%[s2])        \n\t"
-                "sb         %[p2], -1(%[s2])        \n\t"
-                "sb         %[p1], -2(%[s2])        \n\t"
-                "sb         %[p0], -3(%[s2])        \n\t"
-                :
-                : [p5] "r" (p5), [p4] "r" (p4), [p3] "r" (p3), [s2] "r" (s2),
-                  [p2] "r" (p2), [p1] "r" (p1), [p0] "r" (p0)
-            );
-
-            __asm__ __volatile__ (
-                "srl        %[p5], %[p5], 8         \n\t"
-                "srl        %[p4], %[p4], 8         \n\t"
-                "srl        %[p3], %[p3], 8         \n\t"
-                "srl        %[p2], %[p2], 8         \n\t"
-                "srl        %[p1], %[p1], 8         \n\t"
-                "srl        %[p0], %[p0], 8         \n\t"
-                : [p5] "+r" (p5), [p4] "+r" (p4), [p3] "+r" (p3),
-                  [p2] "+r" (p2), [p1] "+r" (p1), [p0] "+r" (p0)
-                :
-            );
-
-            __asm__ __volatile__ (
-                "sb         %[p5],  2(%[s1])        \n\t"
-                "sb         %[p4],  1(%[s1])        \n\t"
-                "sb         %[p3],  0(%[s1])        \n\t"
-                "sb         %[p2], -1(%[s1])        \n\t"
-                "sb         %[p1], -2(%[s1])        \n\t"
-                "sb         %[p0], -3(%[s1])        \n\t"
-                :
-                : [p5] "r" (p5), [p4] "r" (p4), [p3] "r" (p3), [s1] "r" (s1),
-                  [p2] "r" (p2), [p1] "r" (p1), [p0] "r" (p0)
-            );
-        }
-    }
-}
-
-/* Horizontal MB filtering */
-void vp8_loop_filter_mbh_dspr2(unsigned char *y_ptr, unsigned char *u_ptr, unsigned char *v_ptr,
-                               int y_stride, int uv_stride, loop_filter_info *lfi)
-{
-    unsigned int thresh_vec, flimit_vec, limit_vec;
-    unsigned char thresh, flimit, limit, flimit_temp;
-
-    /* use direct value instead pointers */
-    limit = *(lfi->lim);
-    flimit_temp = *(lfi->mblim);
-    thresh = *(lfi->hev_thr);
-    flimit = flimit_temp;
-
-    /* create quad-byte */
-    __asm__ __volatile__ (
-        "replv.qb       %[thresh_vec], %[thresh]    \n\t"
-        "replv.qb       %[flimit_vec], %[flimit]    \n\t"
-        "replv.qb       %[limit_vec],  %[limit]     \n\t"
-        : [thresh_vec] "=&r" (thresh_vec), [flimit_vec] "=&r" (flimit_vec), [limit_vec] "=r" (limit_vec)
-        : [thresh] "r" (thresh), [flimit] "r" (flimit), [limit] "r" (limit)
-    );
-
-    vp8_mbloop_filter_horizontal_edge_mips(y_ptr, y_stride, flimit_vec, limit_vec, thresh_vec, 16);
-
-    if (u_ptr)
-    {
-        vp8_mbloop_filter_uvhorizontal_edge_mips(u_ptr, uv_stride, flimit_vec, limit_vec, thresh_vec, 0);
-    }
-
-    if (v_ptr)
-    {
-        vp8_mbloop_filter_uvhorizontal_edge_mips(v_ptr, uv_stride, flimit_vec, limit_vec, thresh_vec, 0);
-    }
-}
-
-
-/* Vertical MB Filtering */
-void vp8_loop_filter_mbv_dspr2(unsigned char *y_ptr, unsigned char *u_ptr, unsigned char *v_ptr,
-                               int y_stride, int uv_stride, loop_filter_info *lfi)
-{
-    unsigned int thresh_vec, flimit_vec, limit_vec;
-    unsigned char thresh, flimit, limit, flimit_temp;
-
-    /* use direct value instead pointers */
-    limit = *(lfi->lim);
-    flimit_temp = *(lfi->mblim);
-    thresh = *(lfi->hev_thr);
-    flimit = flimit_temp;
-
-    /* create quad-byte */
-    __asm__ __volatile__ (
-        "replv.qb       %[thresh_vec], %[thresh]    \n\t"
-        "replv.qb       %[flimit_vec], %[flimit]    \n\t"
-        "replv.qb       %[limit_vec],  %[limit]     \n\t"
-        : [thresh_vec] "=&r" (thresh_vec), [flimit_vec] "=&r" (flimit_vec), [limit_vec] "=r" (limit_vec)
-        : [thresh] "r" (thresh), [flimit] "r" (flimit), [limit] "r" (limit)
-    );
-
-    vp8_mbloop_filter_vertical_edge_mips(y_ptr, y_stride, flimit_vec, limit_vec, thresh_vec, 16);
-
-    if (u_ptr)
-        vp8_mbloop_filter_uvvertical_edge_mips(u_ptr, uv_stride, flimit_vec, limit_vec, thresh_vec, 0);
-
-    if (v_ptr)
-        vp8_mbloop_filter_uvvertical_edge_mips(v_ptr, uv_stride, flimit_vec, limit_vec, thresh_vec, 0);
-}
-
-
-/* Horizontal B Filtering */
-void vp8_loop_filter_bh_dspr2(unsigned char *y_ptr, unsigned char *u_ptr, unsigned char *v_ptr,
-                              int y_stride, int uv_stride, loop_filter_info *lfi)
-{
-    unsigned int thresh_vec, flimit_vec, limit_vec;
-    unsigned char thresh, flimit, limit, flimit_temp;
-
-    /* use direct value instead pointers */
-    limit = *(lfi->lim);
-    flimit_temp = *(lfi->blim);
-    thresh = *(lfi->hev_thr);
-    flimit = flimit_temp;
-
-    /* create quad-byte */
-    __asm__ __volatile__ (
-        "replv.qb       %[thresh_vec], %[thresh]    \n\t"
-        "replv.qb       %[flimit_vec], %[flimit]    \n\t"
-        "replv.qb       %[limit_vec],  %[limit]     \n\t"
-        : [thresh_vec] "=&r" (thresh_vec), [flimit_vec] "=&r" (flimit_vec), [limit_vec] "=r" (limit_vec)
-        : [thresh] "r" (thresh), [flimit] "r" (flimit), [limit] "r" (limit)
-    );
-
-    vp8_loop_filter_horizontal_edge_mips(y_ptr + 4 * y_stride, y_stride, flimit_vec, limit_vec, thresh_vec, 16);
-    vp8_loop_filter_horizontal_edge_mips(y_ptr + 8 * y_stride, y_stride, flimit_vec, limit_vec, thresh_vec, 16);
-    vp8_loop_filter_horizontal_edge_mips(y_ptr + 12 * y_stride, y_stride, flimit_vec, limit_vec, thresh_vec, 16);
-
-    if (u_ptr)
-        vp8_loop_filter_uvhorizontal_edge_mips(u_ptr + 4 * uv_stride, uv_stride, flimit_vec, limit_vec, thresh_vec, 0);
-
-    if (v_ptr)
-        vp8_loop_filter_uvhorizontal_edge_mips(v_ptr + 4 * uv_stride, uv_stride, flimit_vec, limit_vec, thresh_vec, 0);
-}
-
-
-/* Vertical B Filtering */
-void vp8_loop_filter_bv_dspr2(unsigned char *y_ptr, unsigned char *u_ptr, unsigned char *v_ptr,
-                              int y_stride, int uv_stride, loop_filter_info *lfi)
-{
-    unsigned int thresh_vec, flimit_vec, limit_vec;
-    unsigned char thresh, flimit, limit, flimit_temp;
-
-    /* use direct value instead pointers */
-    limit = *(lfi->lim);
-    flimit_temp = *(lfi->blim);
-    thresh = *(lfi->hev_thr);
-    flimit = flimit_temp;
-
-    /* create quad-byte */
-    __asm__ __volatile__ (
-        "replv.qb       %[thresh_vec], %[thresh]    \n\t"
-        "replv.qb       %[flimit_vec], %[flimit]    \n\t"
-        "replv.qb       %[limit_vec],  %[limit]     \n\t"
-        : [thresh_vec] "=&r" (thresh_vec), [flimit_vec] "=&r" (flimit_vec), [limit_vec] "=r" (limit_vec)
-        : [thresh] "r" (thresh), [flimit] "r" (flimit), [limit] "r" (limit)
-    );
-
-    vp8_loop_filter_vertical_edge_mips(y_ptr + 4, y_stride, flimit_vec, limit_vec, thresh_vec, 16);
-    vp8_loop_filter_vertical_edge_mips(y_ptr + 8, y_stride, flimit_vec, limit_vec, thresh_vec, 16);
-    vp8_loop_filter_vertical_edge_mips(y_ptr + 12, y_stride, flimit_vec, limit_vec, thresh_vec, 16);
-
-    if (u_ptr)
-        vp8_loop_filter_uvvertical_edge_mips(u_ptr + 4, uv_stride, flimit_vec, limit_vec, thresh_vec, 0);
-
-    if (v_ptr)
-        vp8_loop_filter_uvvertical_edge_mips(v_ptr + 4, uv_stride, flimit_vec, limit_vec, thresh_vec, 0);
-}
-
-#endif
diff --git a/vp8/common/mips/msa/bilinear_filter_msa.c b/vp8/common/mips/msa/bilinear_filter_msa.c
deleted file mode 100644 (file)
index 1054ed3..0000000
+++ /dev/null
@@ -1,911 +0,0 @@
-/*
- *  Copyright (c) 2015 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.
- */
-
-#include "./vp8_rtcd.h"
-#include "vpx_ports/mem.h"
-#include "vp8/common/filter.h"
-#include "vp8/common/mips/msa/vp8_macros_msa.h"
-
-DECLARE_ALIGNED(16, static const int8_t, vp8_bilinear_filters_msa[7][2]) =
-{
-    { 112, 16 },
-    { 96, 32 },
-    { 80, 48 },
-    { 64, 64 },
-    { 48, 80 },
-    { 32, 96 },
-    { 16, 112 }
-};
-
-static const uint8_t vp8_mc_filt_mask_arr[16 * 3] =
-{
-    /* 8 width cases */
-    0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8,
-    /* 4 width cases */
-    0, 1, 1, 2, 2, 3, 3, 4, 16, 17, 17, 18, 18, 19, 19, 20,
-    /* 4 width cases */
-    8, 9, 9, 10, 10, 11, 11, 12, 24, 25, 25, 26, 26, 27, 27, 28
-};
-
-static void common_hz_2t_4x4_msa(uint8_t *RESTRICT src, int32_t src_stride,
-                                 uint8_t *RESTRICT dst, int32_t dst_stride,
-                                 const int8_t *filter)
-{
-    v16i8 src0, src1, src2, src3, mask;
-    v16u8 filt0, vec0, vec1, res0, res1;
-    v8u16 vec2, vec3, filt;
-
-    mask = LD_SB(&vp8_mc_filt_mask_arr[16]);
-
-    filt = LD_UH(filter);
-    filt0 = (v16u8)__msa_splati_h((v8i16)filt, 0);
-
-    LD_SB4(src, src_stride, src0, src1, src2, src3);
-    VSHF_B2_UB(src0, src1, src2, src3, mask, mask, vec0, vec1);
-    DOTP_UB2_UH(vec0, vec1, filt0, filt0, vec2, vec3);
-    SRARI_H2_UH(vec2, vec3, VP8_FILTER_SHIFT);
-    PCKEV_B2_UB(vec2, vec2, vec3, vec3, res0, res1);
-    ST4x4_UB(res0, res1, 0, 1, 0, 1, dst, dst_stride);
-}
-
-static void common_hz_2t_4x8_msa(uint8_t *RESTRICT src, int32_t src_stride,
-                                 uint8_t *RESTRICT dst, int32_t dst_stride,
-                                 const int8_t *filter)
-{
-    v16u8 vec0, vec1, vec2, vec3, filt0;
-    v16i8 src0, src1, src2, src3, src4, src5, src6, src7, mask;
-    v16i8 res0, res1, res2, res3;
-    v8u16 vec4, vec5, vec6, vec7, filt;
-
-    mask = LD_SB(&vp8_mc_filt_mask_arr[16]);
-
-    filt = LD_UH(filter);
-    filt0 = (v16u8)__msa_splati_h((v8i16)filt, 0);
-
-    LD_SB8(src, src_stride, src0, src1, src2, src3, src4, src5, src6, src7);
-    VSHF_B2_UB(src0, src1, src2, src3, mask, mask, vec0, vec1);
-    VSHF_B2_UB(src4, src5, src6, src7, mask, mask, vec2, vec3);
-    DOTP_UB4_UH(vec0, vec1, vec2, vec3, filt0, filt0, filt0, filt0,
-                vec4, vec5, vec6, vec7);
-    SRARI_H4_UH(vec4, vec5, vec6, vec7, VP8_FILTER_SHIFT);
-    PCKEV_B4_SB(vec4, vec4, vec5, vec5, vec6, vec6, vec7, vec7,
-                res0, res1, res2, res3);
-    ST4x4_UB(res0, res1, 0, 1, 0, 1, dst, dst_stride);
-    dst += (4 * dst_stride);
-    ST4x4_UB(res2, res3, 0, 1, 0, 1, dst, dst_stride);
-}
-
-static void common_hz_2t_4w_msa(uint8_t *RESTRICT src, int32_t src_stride,
-                                uint8_t *RESTRICT dst, int32_t dst_stride,
-                                const int8_t *filter, int32_t height)
-{
-    if (4 == height)
-    {
-        common_hz_2t_4x4_msa(src, src_stride, dst, dst_stride, filter);
-    }
-    else if (8 == height)
-    {
-        common_hz_2t_4x8_msa(src, src_stride, dst, dst_stride, filter);
-    }
-}
-
-static void common_hz_2t_8x4_msa(uint8_t *RESTRICT src, int32_t src_stride,
-                                 uint8_t *RESTRICT dst, int32_t dst_stride,
-                                 const int8_t *filter)
-{
-    v16u8 filt0;
-    v16i8 src0, src1, src2, src3, mask;
-    v8u16 vec0, vec1, vec2, vec3, filt;
-
-    mask = LD_SB(&vp8_mc_filt_mask_arr[0]);
-
-    filt = LD_UH(filter);
-    filt0 = (v16u8)__msa_splati_h((v8i16)filt, 0);
-
-    LD_SB4(src, src_stride, src0, src1, src2, src3);
-    VSHF_B2_UH(src0, src0, src1, src1, mask, mask, vec0, vec1);
-    VSHF_B2_UH(src2, src2, src3, src3, mask, mask, vec2, vec3);
-    DOTP_UB4_UH(vec0, vec1, vec2, vec3, filt0, filt0, filt0, filt0,
-                vec0, vec1, vec2, vec3);
-    SRARI_H4_UH(vec0, vec1, vec2, vec3, VP8_FILTER_SHIFT);
-    PCKEV_B2_SB(vec1, vec0, vec3, vec2, src0, src1);
-    ST8x4_UB(src0, src1, dst, dst_stride);
-}
-
-static void common_hz_2t_8x8mult_msa(uint8_t *RESTRICT src, int32_t src_stride,
-                                     uint8_t *RESTRICT dst, int32_t dst_stride,
-                                     const int8_t *filter, int32_t height)
-{
-    v16u8 filt0;
-    v16i8 src0, src1, src2, src3, mask, out0, out1;
-    v8u16 vec0, vec1, vec2, vec3, filt;
-
-    mask = LD_SB(&vp8_mc_filt_mask_arr[0]);
-
-    filt = LD_UH(filter);
-    filt0 = (v16u8)__msa_splati_h((v8i16)filt, 0);
-
-    LD_SB4(src, src_stride, src0, src1, src2, src3);
-    src += (4 * src_stride);
-
-    VSHF_B2_UH(src0, src0, src1, src1, mask, mask, vec0, vec1);
-    VSHF_B2_UH(src2, src2, src3, src3, mask, mask, vec2, vec3);
-    DOTP_UB4_UH(vec0, vec1, vec2, vec3, filt0, filt0, filt0, filt0,
-                vec0, vec1, vec2, vec3);
-    SRARI_H4_UH(vec0, vec1, vec2, vec3, VP8_FILTER_SHIFT);
-
-    LD_SB4(src, src_stride, src0, src1, src2, src3);
-    src += (4 * src_stride);
-
-    PCKEV_B2_SB(vec1, vec0, vec3, vec2, out0, out1);
-    ST8x4_UB(out0, out1, dst, dst_stride);
-    dst += (4 * dst_stride);
-
-    VSHF_B2_UH(src0, src0, src1, src1, mask, mask, vec0, vec1);
-    VSHF_B2_UH(src2, src2, src3, src3, mask, mask, vec2, vec3);
-    DOTP_UB4_UH(vec0, vec1, vec2, vec3, filt0, filt0, filt0, filt0,
-                vec0, vec1, vec2, vec3);
-    SRARI_H4_UH(vec0, vec1, vec2, vec3, VP8_FILTER_SHIFT);
-    PCKEV_B2_SB(vec1, vec0, vec3, vec2, out0, out1);
-    ST8x4_UB(out0, out1, dst, dst_stride);
-    dst += (4 * dst_stride);
-
-    if (16 == height)
-    {
-        LD_SB4(src, src_stride, src0, src1, src2, src3);
-        src += (4 * src_stride);
-
-        VSHF_B2_UH(src0, src0, src1, src1, mask, mask, vec0, vec1);
-        VSHF_B2_UH(src2, src2, src3, src3, mask, mask, vec2, vec3);
-        DOTP_UB4_UH(vec0, vec1, vec2, vec3, filt0, filt0, filt0, filt0,
-                    vec0, vec1, vec2, vec3);
-        SRARI_H4_UH(vec0, vec1, vec2, vec3, VP8_FILTER_SHIFT);
-        LD_SB4(src, src_stride, src0, src1, src2, src3);
-        src += (4 * src_stride);
-
-        PCKEV_B2_SB(vec1, vec0, vec3, vec2, out0, out1);
-        ST8x4_UB(out0, out1, dst, dst_stride);
-
-        VSHF_B2_UH(src0, src0, src1, src1, mask, mask, vec0, vec1);
-        VSHF_B2_UH(src2, src2, src3, src3, mask, mask, vec2, vec3);
-        DOTP_UB4_UH(vec0, vec1, vec2, vec3, filt0, filt0, filt0, filt0,
-                    vec0, vec1, vec2, vec3);
-        SRARI_H4_UH(vec0, vec1, vec2, vec3, VP8_FILTER_SHIFT);
-        PCKEV_B2_SB(vec1, vec0, vec3, vec2, out0, out1);
-        ST8x4_UB(out0, out1, dst + 4 * dst_stride, dst_stride);
-    }
-}
-
-static void common_hz_2t_8w_msa(uint8_t *RESTRICT src, int32_t src_stride,
-                                uint8_t *RESTRICT dst, int32_t dst_stride,
-                                const int8_t *filter, int32_t height)
-{
-    if (4 == height)
-    {
-        common_hz_2t_8x4_msa(src, src_stride, dst, dst_stride, filter);
-    }
-    else
-    {
-        common_hz_2t_8x8mult_msa(src, src_stride, dst, dst_stride, filter, height);
-    }
-}
-
-static void common_hz_2t_16w_msa(uint8_t *RESTRICT src, int32_t src_stride,
-                                 uint8_t *RESTRICT dst, int32_t dst_stride,
-                                 const int8_t *filter, int32_t height)
-{
-    uint32_t loop_cnt;
-    v16i8 src0, src1, src2, src3, src4, src5, src6, src7, mask;
-    v16u8 filt0, vec0, vec1, vec2, vec3, vec4, vec5, vec6, vec7;
-    v8u16 out0, out1, out2, out3, out4, out5, out6, out7, filt;
-
-    mask = LD_SB(&vp8_mc_filt_mask_arr[0]);
-
-    loop_cnt = (height >> 2) - 1;
-
-    filt = LD_UH(filter);
-    filt0 = (v16u8)__msa_splati_h((v8i16)filt, 0);
-
-    LD_SB4(src, src_stride, src0, src2, src4, src6);
-    LD_SB4(src + 8, src_stride, src1, src3, src5, src7);
-    src += (4 * src_stride);
-
-    VSHF_B2_UB(src0, src0, src1, src1, mask, mask, vec0, vec1);
-    VSHF_B2_UB(src2, src2, src3, src3, mask, mask, vec2, vec3);
-    VSHF_B2_UB(src4, src4, src5, src5, mask, mask, vec4, vec5);
-    VSHF_B2_UB(src6, src6, src7, src7, mask, mask, vec6, vec7);
-    DOTP_UB4_UH(vec0, vec1, vec2, vec3, filt0, filt0, filt0, filt0,
-                out0, out1, out2, out3);
-    DOTP_UB4_UH(vec4, vec5, vec6, vec7, filt0, filt0, filt0, filt0,
-                out4, out5, out6, out7);
-    SRARI_H4_UH(out0, out1, out2, out3, VP8_FILTER_SHIFT);
-    SRARI_H4_UH(out4, out5, out6, out7, VP8_FILTER_SHIFT);
-    PCKEV_ST_SB(out0, out1, dst);
-    dst += dst_stride;
-    PCKEV_ST_SB(out2, out3, dst);
-    dst += dst_stride;
-    PCKEV_ST_SB(out4, out5, dst);
-    dst += dst_stride;
-    PCKEV_ST_SB(out6, out7, dst);
-    dst += dst_stride;
-
-    for (; loop_cnt--;)
-    {
-        LD_SB4(src, src_stride, src0, src2, src4, src6);
-        LD_SB4(src + 8, src_stride, src1, src3, src5, src7);
-        src += (4 * src_stride);
-
-        VSHF_B2_UB(src0, src0, src1, src1, mask, mask, vec0, vec1);
-        VSHF_B2_UB(src2, src2, src3, src3, mask, mask, vec2, vec3);
-        VSHF_B2_UB(src4, src4, src5, src5, mask, mask, vec4, vec5);
-        VSHF_B2_UB(src6, src6, src7, src7, mask, mask, vec6, vec7);
-        DOTP_UB4_UH(vec0, vec1, vec2, vec3, filt0, filt0, filt0, filt0,
-                    out0, out1, out2, out3);
-        DOTP_UB4_UH(vec4, vec5, vec6, vec7, filt0, filt0, filt0, filt0,
-                    out4, out5, out6, out7);
-        SRARI_H4_UH(out0, out1, out2, out3, VP8_FILTER_SHIFT);
-        SRARI_H4_UH(out4, out5, out6, out7, VP8_FILTER_SHIFT);
-        PCKEV_ST_SB(out0, out1, dst);
-        dst += dst_stride;
-        PCKEV_ST_SB(out2, out3, dst);
-        dst += dst_stride;
-        PCKEV_ST_SB(out4, out5, dst);
-        dst += dst_stride;
-        PCKEV_ST_SB(out6, out7, dst);
-        dst += dst_stride;
-    }
-}
-
-static void common_vt_2t_4x4_msa(uint8_t *RESTRICT src, int32_t src_stride,
-                                 uint8_t *RESTRICT dst, int32_t dst_stride,
-                                 const int8_t *filter)
-{
-    v16i8 src0, src1, src2, src3, src4;
-    v16i8 src10_r, src32_r, src21_r, src43_r, src2110, src4332;
-    v16u8 filt0;
-    v8i16 filt;
-    v8u16 tmp0, tmp1;
-
-    filt = LD_SH(filter);
-    filt0 = (v16u8)__msa_splati_h(filt, 0);
-
-    LD_SB5(src, src_stride, src0, src1, src2, src3, src4);
-    src += (5 * src_stride);
-
-    ILVR_B4_SB(src1, src0, src2, src1, src3, src2, src4, src3,
-               src10_r, src21_r, src32_r, src43_r);
-    ILVR_D2_SB(src21_r, src10_r, src43_r, src32_r, src2110, src4332);
-    DOTP_UB2_UH(src2110, src4332, filt0, filt0, tmp0, tmp1);
-    SRARI_H2_UH(tmp0, tmp1, VP8_FILTER_SHIFT);
-    src2110 = __msa_pckev_b((v16i8)tmp1, (v16i8)tmp0);
-    ST4x4_UB(src2110, src2110, 0, 1, 2, 3, dst, dst_stride);
-}
-
-static void common_vt_2t_4x8_msa(uint8_t *RESTRICT src, int32_t src_stride,
-                                 uint8_t *RESTRICT dst, int32_t dst_stride,
-                                 const int8_t *filter)
-{
-    v16i8 src0, src1, src2, src3, src4, src5, src6, src7, src8;
-    v16i8 src10_r, src32_r, src54_r, src76_r, src21_r, src43_r;
-    v16i8 src65_r, src87_r, src2110, src4332, src6554, src8776;
-    v8u16 tmp0, tmp1, tmp2, tmp3;
-    v16u8 filt0;
-    v8i16 filt;
-
-    filt = LD_SH(filter);
-    filt0 = (v16u8)__msa_splati_h(filt, 0);
-
-    LD_SB8(src, src_stride, src0, src1, src2, src3, src4, src5, src6, src7);
-    src += (8 * src_stride);
-
-    src8 = LD_SB(src);
-    src += src_stride;
-
-    ILVR_B4_SB(src1, src0, src2, src1, src3, src2, src4, src3, src10_r, src21_r,
-               src32_r, src43_r);
-    ILVR_B4_SB(src5, src4, src6, src5, src7, src6, src8, src7, src54_r, src65_r,
-               src76_r, src87_r);
-    ILVR_D4_SB(src21_r, src10_r, src43_r, src32_r, src65_r, src54_r,
-               src87_r, src76_r, src2110, src4332, src6554, src8776);
-    DOTP_UB4_UH(src2110, src4332, src6554, src8776, filt0, filt0, filt0, filt0,
-                tmp0, tmp1, tmp2, tmp3);
-    SRARI_H4_UH(tmp0, tmp1, tmp2, tmp3, VP8_FILTER_SHIFT);
-    PCKEV_B2_SB(tmp1, tmp0, tmp3, tmp2, src2110, src4332);
-    ST4x4_UB(src2110, src2110, 0, 1, 2, 3, dst, dst_stride);
-    ST4x4_UB(src4332, src4332, 0, 1, 2, 3, dst + 4 * dst_stride, dst_stride);
-}
-
-static void common_vt_2t_4w_msa(uint8_t *RESTRICT src, int32_t src_stride,
-                                uint8_t *RESTRICT dst, int32_t dst_stride,
-                                const int8_t *filter, int32_t height)
-{
-    if (4 == height)
-    {
-        common_vt_2t_4x4_msa(src, src_stride, dst, dst_stride, filter);
-    }
-    else if (8 == height)
-    {
-        common_vt_2t_4x8_msa(src, src_stride, dst, dst_stride, filter);
-    }
-}
-
-static void common_vt_2t_8x4_msa(uint8_t *RESTRICT src, int32_t src_stride,
-                                 uint8_t *RESTRICT dst, int32_t dst_stride,
-                                 const int8_t *filter)
-{
-    v16u8 src0, src1, src2, src3, src4, vec0, vec1, vec2, vec3, filt0;
-    v16i8 out0, out1;
-    v8u16 tmp0, tmp1, tmp2, tmp3;
-    v8i16 filt;
-
-    filt = LD_SH(filter);
-    filt0 = (v16u8)__msa_splati_h(filt, 0);
-
-    LD_UB5(src, src_stride, src0, src1, src2, src3, src4);
-    ILVR_B2_UB(src1, src0, src2, src1, vec0, vec1);
-    ILVR_B2_UB(src3, src2, src4, src3, vec2, vec3);
-    DOTP_UB4_UH(vec0, vec1, vec2, vec3, filt0, filt0, filt0, filt0,
-                tmp0, tmp1, tmp2, tmp3);
-    SRARI_H4_UH(tmp0, tmp1, tmp2, tmp3, VP8_FILTER_SHIFT);
-    PCKEV_B2_SB(tmp1, tmp0, tmp3, tmp2, out0, out1);
-    ST8x4_UB(out0, out1, dst, dst_stride);
-}
-
-static void common_vt_2t_8x8mult_msa(uint8_t *RESTRICT src, int32_t src_stride,
-                                     uint8_t *RESTRICT dst, int32_t dst_stride,
-                                     const int8_t *filter, int32_t height)
-{
-    uint32_t loop_cnt;
-    v16u8 src0, src1, src2, src3, src4, src5, src6, src7, src8;
-    v16u8 vec0, vec1, vec2, vec3, vec4, vec5, vec6, vec7, filt0;
-    v16i8 out0, out1;
-    v8u16 tmp0, tmp1, tmp2, tmp3;
-    v8i16 filt;
-
-    filt = LD_SH(filter);
-    filt0 = (v16u8)__msa_splati_h(filt, 0);
-
-    src0 = LD_UB(src);
-    src += src_stride;
-
-    for (loop_cnt = (height >> 3); loop_cnt--;)
-    {
-        LD_UB8(src, src_stride, src1, src2, src3, src4, src5, src6, src7, src8);
-        src += (8 * src_stride);
-
-        ILVR_B4_UB(src1, src0, src2, src1, src3, src2, src4, src3,
-                   vec0, vec1, vec2, vec3);
-        ILVR_B4_UB(src5, src4, src6, src5, src7, src6, src8, src7,
-                   vec4, vec5, vec6, vec7);
-        DOTP_UB4_UH(vec0, vec1, vec2, vec3, filt0, filt0, filt0, filt0,
-                    tmp0, tmp1, tmp2, tmp3);
-        SRARI_H4_UH(tmp0, tmp1, tmp2, tmp3, VP8_FILTER_SHIFT);
-        PCKEV_B2_SB(tmp1, tmp0, tmp3, tmp2, out0, out1);
-        ST8x4_UB(out0, out1, dst, dst_stride);
-        dst += (4 * dst_stride);
-
-        DOTP_UB4_UH(vec4, vec5, vec6, vec7, filt0, filt0, filt0, filt0,
-                    tmp0, tmp1, tmp2, tmp3);
-        SRARI_H4_UH(tmp0, tmp1, tmp2, tmp3, VP8_FILTER_SHIFT);
-        PCKEV_B2_SB(tmp1, tmp0, tmp3, tmp2, out0, out1);
-        ST8x4_UB(out0, out1, dst, dst_stride);
-        dst += (4 * dst_stride);
-
-        src0 = src8;
-    }
-}
-
-static void common_vt_2t_8w_msa(uint8_t *RESTRICT src, int32_t src_stride,
-                                uint8_t *RESTRICT dst, int32_t dst_stride,
-                                const int8_t *filter, int32_t height)
-{
-    if (4 == height)
-    {
-        common_vt_2t_8x4_msa(src, src_stride, dst, dst_stride, filter);
-    }
-    else
-    {
-        common_vt_2t_8x8mult_msa(src, src_stride, dst, dst_stride, filter,
-                                 height);
-    }
-}
-
-static void common_vt_2t_16w_msa(uint8_t *RESTRICT src, int32_t src_stride,
-                                 uint8_t *RESTRICT dst, int32_t dst_stride,
-                                 const int8_t *filter, int32_t height)
-{
-    uint32_t loop_cnt;
-    v16u8 src0, src1, src2, src3, src4;
-    v16u8 vec0, vec1, vec2, vec3, vec4, vec5, vec6, vec7, filt0;
-    v8u16 tmp0, tmp1, tmp2, tmp3;
-    v8i16 filt;
-
-    filt = LD_SH(filter);
-    filt0 = (v16u8)__msa_splati_h(filt, 0);
-
-    src0 = LD_UB(src);
-    src += src_stride;
-
-    for (loop_cnt = (height >> 2); loop_cnt--;)
-    {
-        LD_UB4(src, src_stride, src1, src2, src3, src4);
-        src += (4 * src_stride);
-
-        ILVR_B2_UB(src1, src0, src2, src1, vec0, vec2);
-        ILVL_B2_UB(src1, src0, src2, src1, vec1, vec3);
-        DOTP_UB2_UH(vec0, vec1, filt0, filt0, tmp0, tmp1);
-        SRARI_H2_UH(tmp0, tmp1, VP8_FILTER_SHIFT);
-        PCKEV_ST_SB(tmp0, tmp1, dst);
-        dst += dst_stride;
-
-        ILVR_B2_UB(src3, src2, src4, src3, vec4, vec6);
-        ILVL_B2_UB(src3, src2, src4, src3, vec5, vec7);
-        DOTP_UB2_UH(vec2, vec3, filt0, filt0, tmp2, tmp3);
-        SRARI_H2_UH(tmp2, tmp3, VP8_FILTER_SHIFT);
-        PCKEV_ST_SB(tmp2, tmp3, dst);
-        dst += dst_stride;
-
-        DOTP_UB2_UH(vec4, vec5, filt0, filt0, tmp0, tmp1);
-        SRARI_H2_UH(tmp0, tmp1, VP8_FILTER_SHIFT);
-        PCKEV_ST_SB(tmp0, tmp1, dst);
-        dst += dst_stride;
-
-        DOTP_UB2_UH(vec6, vec7, filt0, filt0, tmp2, tmp3);
-        SRARI_H2_UH(tmp2, tmp3, VP8_FILTER_SHIFT);
-        PCKEV_ST_SB(tmp2, tmp3, dst);
-        dst += dst_stride;
-
-        src0 = src4;
-    }
-}
-
-static void common_hv_2ht_2vt_4x4_msa(uint8_t *RESTRICT src, int32_t src_stride,
-                                      uint8_t *RESTRICT dst, int32_t dst_stride,
-                                      const int8_t *filter_horiz,
-                                      const int8_t *filter_vert)
-{
-    v16i8 src0, src1, src2, src3, src4, mask;
-    v16u8 filt_vt, filt_hz, vec0, vec1, res0, res1;
-    v8u16 hz_out0, hz_out1, hz_out2, hz_out3, hz_out4, filt, tmp0, tmp1;
-
-    mask = LD_SB(&vp8_mc_filt_mask_arr[16]);
-
-    filt = LD_UH(filter_horiz);
-    filt_hz = (v16u8)__msa_splati_h((v8i16)filt, 0);
-    filt = LD_UH(filter_vert);
-    filt_vt = (v16u8)__msa_splati_h((v8i16)filt, 0);
-
-    LD_SB5(src, src_stride, src0, src1, src2, src3, src4);
-    hz_out0 = HORIZ_2TAP_FILT_UH(src0, src1, mask, filt_hz, VP8_FILTER_SHIFT);
-    hz_out2 = HORIZ_2TAP_FILT_UH(src2, src3, mask, filt_hz, VP8_FILTER_SHIFT);
-    hz_out4 = HORIZ_2TAP_FILT_UH(src4, src4, mask, filt_hz, VP8_FILTER_SHIFT);
-    hz_out1 = (v8u16)__msa_sldi_b((v16i8)hz_out2, (v16i8)hz_out0, 8);
-    hz_out3 = (v8u16)__msa_pckod_d((v2i64)hz_out4, (v2i64)hz_out2);
-
-    ILVEV_B2_UB(hz_out0, hz_out1, hz_out2, hz_out3, vec0, vec1);
-    DOTP_UB2_UH(vec0, vec1, filt_vt, filt_vt, tmp0, tmp1);
-    SRARI_H2_UH(tmp0, tmp1, VP8_FILTER_SHIFT);
-    PCKEV_B2_UB(tmp0, tmp0, tmp1, tmp1, res0, res1);
-    ST4x4_UB(res0, res1, 0, 1, 0, 1, dst, dst_stride);
-}
-
-static void common_hv_2ht_2vt_4x8_msa(uint8_t *RESTRICT src, int32_t src_stride,
-                                      uint8_t *RESTRICT dst, int32_t dst_stride,
-                                      const int8_t *filter_horiz,
-                                      const int8_t *filter_vert)
-{
-    v16i8 src0, src1, src2, src3, src4, src5, src6, src7, src8, mask;
-    v16i8 res0, res1, res2, res3;
-    v16u8 filt_hz, filt_vt, vec0, vec1, vec2, vec3;
-    v8u16 hz_out0, hz_out1, hz_out2, hz_out3, hz_out4, hz_out5, hz_out6;
-    v8u16 hz_out7, hz_out8, vec4, vec5, vec6, vec7, filt;
-
-    mask = LD_SB(&vp8_mc_filt_mask_arr[16]);
-
-    filt = LD_UH(filter_horiz);
-    filt_hz = (v16u8)__msa_splati_h((v8i16)filt, 0);
-    filt = LD_UH(filter_vert);
-    filt_vt = (v16u8)__msa_splati_h((v8i16)filt, 0);
-
-    LD_SB8(src, src_stride, src0, src1, src2, src3, src4, src5, src6, src7);
-    src += (8 * src_stride);
-    src8 = LD_SB(src);
-
-    hz_out0 = HORIZ_2TAP_FILT_UH(src0, src1, mask, filt_hz, VP8_FILTER_SHIFT);
-    hz_out2 = HORIZ_2TAP_FILT_UH(src2, src3, mask, filt_hz, VP8_FILTER_SHIFT);
-    hz_out4 = HORIZ_2TAP_FILT_UH(src4, src5, mask, filt_hz, VP8_FILTER_SHIFT);
-    hz_out6 = HORIZ_2TAP_FILT_UH(src6, src7, mask, filt_hz, VP8_FILTER_SHIFT);
-    hz_out8 = HORIZ_2TAP_FILT_UH(src8, src8, mask, filt_hz, VP8_FILTER_SHIFT);
-    SLDI_B3_UH(hz_out2, hz_out4, hz_out6, hz_out0, hz_out2, hz_out4, hz_out1,
-               hz_out3, hz_out5, 8);
-    hz_out7 = (v8u16)__msa_pckod_d((v2i64)hz_out8, (v2i64)hz_out6);
-
-    ILVEV_B2_UB(hz_out0, hz_out1, hz_out2, hz_out3, vec0, vec1);
-    ILVEV_B2_UB(hz_out4, hz_out5, hz_out6, hz_out7, vec2, vec3);
-    DOTP_UB4_UH(vec0, vec1, vec2, vec3, filt_vt, filt_vt, filt_vt, filt_vt,
-                vec4, vec5, vec6, vec7);
-    SRARI_H4_UH(vec4, vec5, vec6, vec7, VP8_FILTER_SHIFT);
-    PCKEV_B4_SB(vec4, vec4, vec5, vec5, vec6, vec6, vec7, vec7,
-                res0, res1, res2, res3);
-    ST4x4_UB(res0, res1, 0, 1, 0, 1, dst, dst_stride);
-    dst += (4 * dst_stride);
-    ST4x4_UB(res2, res3, 0, 1, 0, 1, dst, dst_stride);
-}
-
-static void common_hv_2ht_2vt_4w_msa(uint8_t *RESTRICT src, int32_t src_stride,
-                                     uint8_t *RESTRICT dst, int32_t dst_stride,
-                                     const int8_t *filter_horiz,
-                                     const int8_t *filter_vert,
-                                     int32_t height)
-{
-    if (4 == height)
-    {
-        common_hv_2ht_2vt_4x4_msa(src, src_stride, dst, dst_stride,
-                                  filter_horiz, filter_vert);
-    }
-    else if (8 == height)
-    {
-        common_hv_2ht_2vt_4x8_msa(src, src_stride, dst, dst_stride,
-                                  filter_horiz, filter_vert);
-    }
-}
-
-static void common_hv_2ht_2vt_8x4_msa(uint8_t *RESTRICT src, int32_t src_stride,
-                                      uint8_t *RESTRICT dst, int32_t dst_stride,
-                                      const int8_t *filter_horiz,
-                                      const int8_t *filter_vert)
-{
-    v16i8 src0, src1, src2, src3, src4, mask, out0, out1;
-    v16u8 filt_hz, filt_vt, vec0, vec1, vec2, vec3;
-    v8u16 hz_out0, hz_out1, tmp0, tmp1, tmp2, tmp3;
-    v8i16 filt;
-
-    mask = LD_SB(&vp8_mc_filt_mask_arr[0]);
-
-    filt = LD_SH(filter_horiz);
-    filt_hz = (v16u8)__msa_splati_h(filt, 0);
-    filt = LD_SH(filter_vert);
-    filt_vt = (v16u8)__msa_splati_h(filt, 0);
-
-    LD_SB5(src, src_stride, src0, src1, src2, src3, src4);
-
-    hz_out0 = HORIZ_2TAP_FILT_UH(src0, src0, mask, filt_hz, VP8_FILTER_SHIFT);
-    hz_out1 = HORIZ_2TAP_FILT_UH(src1, src1, mask, filt_hz, VP8_FILTER_SHIFT);
-    vec0 = (v16u8)__msa_ilvev_b((v16i8)hz_out1, (v16i8)hz_out0);
-    tmp0 = __msa_dotp_u_h(vec0, filt_vt);
-
-    hz_out0 = HORIZ_2TAP_FILT_UH(src2, src2, mask, filt_hz, VP8_FILTER_SHIFT);
-    vec1 = (v16u8)__msa_ilvev_b((v16i8)hz_out0, (v16i8)hz_out1);
-    tmp1 = __msa_dotp_u_h(vec1, filt_vt);
-
-    hz_out1 = HORIZ_2TAP_FILT_UH(src3, src3, mask, filt_hz, VP8_FILTER_SHIFT);
-    vec2 = (v16u8)__msa_ilvev_b((v16i8)hz_out1, (v16i8)hz_out0);
-    tmp2 = __msa_dotp_u_h(vec2, filt_vt);
-
-    hz_out0 = HORIZ_2TAP_FILT_UH(src4, src4, mask, filt_hz, VP8_FILTER_SHIFT);
-    vec3 = (v16u8)__msa_ilvev_b((v16i8)hz_out0, (v16i8)hz_out1);
-    tmp3 = __msa_dotp_u_h(vec3, filt_vt);
-
-    SRARI_H4_UH(tmp0, tmp1, tmp2, tmp3, VP8_FILTER_SHIFT);
-    PCKEV_B2_SB(tmp1, tmp0, tmp3, tmp2, out0, out1);
-    ST8x4_UB(out0, out1, dst, dst_stride);
-}
-
-static void common_hv_2ht_2vt_8x8mult_msa(uint8_t *RESTRICT src,
-                                          int32_t src_stride,
-                                          uint8_t *RESTRICT dst,
-                                          int32_t dst_stride,
-                                          const int8_t *filter_horiz,
-                                          const int8_t *filter_vert,
-                                          int32_t height)
-{
-    uint32_t loop_cnt;
-    v16i8 src0, src1, src2, src3, src4, mask, out0, out1;
-    v16u8 filt_hz, filt_vt, vec0;
-    v8u16 hz_out0, hz_out1, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7, tmp8;
-    v8i16 filt;
-
-    mask = LD_SB(&vp8_mc_filt_mask_arr[0]);
-
-    filt = LD_SH(filter_horiz);
-    filt_hz = (v16u8)__msa_splati_h(filt, 0);
-    filt = LD_SH(filter_vert);
-    filt_vt = (v16u8)__msa_splati_h(filt, 0);
-
-    src0 = LD_SB(src);
-    src += src_stride;
-
-    hz_out0 = HORIZ_2TAP_FILT_UH(src0, src0, mask, filt_hz, VP8_FILTER_SHIFT);
-
-    for (loop_cnt = (height >> 3); loop_cnt--;)
-    {
-        LD_SB4(src, src_stride, src1, src2, src3, src4);
-        src += (4 * src_stride);
-
-        hz_out1 = HORIZ_2TAP_FILT_UH(src1, src1, mask, filt_hz,
-                                     VP8_FILTER_SHIFT);
-        vec0 = (v16u8)__msa_ilvev_b((v16i8)hz_out1, (v16i8)hz_out0);
-        tmp1 = __msa_dotp_u_h(vec0, filt_vt);
-
-        hz_out0 = HORIZ_2TAP_FILT_UH(src2, src2, mask, filt_hz,
-                                     VP8_FILTER_SHIFT);
-        vec0 = (v16u8)__msa_ilvev_b((v16i8)hz_out0, (v16i8)hz_out1);
-        tmp2 = __msa_dotp_u_h(vec0, filt_vt);
-
-        SRARI_H2_UH(tmp1, tmp2, VP8_FILTER_SHIFT);
-
-        hz_out1 = HORIZ_2TAP_FILT_UH(src3, src3, mask, filt_hz,
-                                     VP8_FILTER_SHIFT);
-        vec0 = (v16u8)__msa_ilvev_b((v16i8)hz_out1, (v16i8)hz_out0);
-        tmp3 = __msa_dotp_u_h(vec0, filt_vt);
-
-        hz_out0 = HORIZ_2TAP_FILT_UH(src4, src4, mask, filt_hz,
-                                     VP8_FILTER_SHIFT);
-        LD_SB4(src, src_stride, src1, src2, src3, src4);
-        src += (4 * src_stride);
-        vec0 = (v16u8)__msa_ilvev_b((v16i8)hz_out0, (v16i8)hz_out1);
-        tmp4 = __msa_dotp_u_h(vec0, filt_vt);
-
-        SRARI_H2_UH(tmp3, tmp4, VP8_FILTER_SHIFT);
-        PCKEV_B2_SB(tmp2, tmp1, tmp4, tmp3, out0, out1);
-        ST8x4_UB(out0, out1, dst, dst_stride);
-        dst += (4 * dst_stride);
-
-        hz_out1 = HORIZ_2TAP_FILT_UH(src1, src1, mask, filt_hz,
-                                     VP8_FILTER_SHIFT);
-        vec0 = (v16u8)__msa_ilvev_b((v16i8)hz_out1, (v16i8)hz_out0);
-        tmp5 = __msa_dotp_u_h(vec0, filt_vt);
-
-        hz_out0 = HORIZ_2TAP_FILT_UH(src2, src2, mask, filt_hz,
-                                     VP8_FILTER_SHIFT);
-        vec0 = (v16u8)__msa_ilvev_b((v16i8)hz_out0, (v16i8)hz_out1);
-        tmp6 = __msa_dotp_u_h(vec0, filt_vt);
-
-        hz_out1 = HORIZ_2TAP_FILT_UH(src3, src3, mask, filt_hz,
-                                     VP8_FILTER_SHIFT);
-        vec0 = (v16u8)__msa_ilvev_b((v16i8)hz_out1, (v16i8)hz_out0);
-        tmp7 = __msa_dotp_u_h(vec0, filt_vt);
-
-        hz_out0 = HORIZ_2TAP_FILT_UH(src4, src4, mask, filt_hz,
-                                     VP8_FILTER_SHIFT);
-        vec0 = (v16u8)__msa_ilvev_b((v16i8)hz_out0, (v16i8)hz_out1);
-        tmp8 = __msa_dotp_u_h(vec0, filt_vt);
-
-        SRARI_H4_UH(tmp5, tmp6, tmp7, tmp8, VP8_FILTER_SHIFT);
-        PCKEV_B2_SB(tmp6, tmp5, tmp8, tmp7, out0, out1);
-        ST8x4_UB(out0, out1, dst, dst_stride);
-        dst += (4 * dst_stride);
-    }
-}
-
-static void common_hv_2ht_2vt_8w_msa(uint8_t *RESTRICT src, int32_t src_stride,
-                                     uint8_t *RESTRICT dst, int32_t dst_stride,
-                                     const int8_t *filter_horiz,
-                                     const int8_t *filter_vert,
-                                     int32_t height)
-{
-    if (4 == height)
-    {
-        common_hv_2ht_2vt_8x4_msa(src, src_stride, dst, dst_stride,
-                                  filter_horiz, filter_vert);
-    }
-    else
-    {
-        common_hv_2ht_2vt_8x8mult_msa(src, src_stride, dst, dst_stride,
-                                      filter_horiz, filter_vert, height);
-    }
-}
-
-static void common_hv_2ht_2vt_16w_msa(uint8_t *RESTRICT src, int32_t src_stride,
-                                      uint8_t *RESTRICT dst, int32_t dst_stride,
-                                      const int8_t *filter_horiz,
-                                      const int8_t *filter_vert,
-                                      int32_t height)
-{
-    uint32_t loop_cnt;
-    v16i8 src0, src1, src2, src3, src4, src5, src6, src7, mask;
-    v16u8 filt_hz, filt_vt, vec0, vec1;
-    v8u16 tmp1, tmp2, hz_out0, hz_out1, hz_out2, hz_out3;
-    v8i16 filt;
-
-    mask = LD_SB(&vp8_mc_filt_mask_arr[0]);
-
-    /* rearranging filter */
-    filt = LD_SH(filter_horiz);
-    filt_hz = (v16u8)__msa_splati_h(filt, 0);
-    filt = LD_SH(filter_vert);
-    filt_vt = (v16u8)__msa_splati_h(filt, 0);
-
-    LD_SB2(src, 8, src0, src1);
-    src += src_stride;
-
-    hz_out0 = HORIZ_2TAP_FILT_UH(src0, src0, mask, filt_hz, VP8_FILTER_SHIFT);
-    hz_out2 = HORIZ_2TAP_FILT_UH(src1, src1, mask, filt_hz, VP8_FILTER_SHIFT);
-
-    for (loop_cnt = (height >> 2); loop_cnt--;)
-    {
-        LD_SB4(src, src_stride, src0, src2, src4, src6);
-        LD_SB4(src + 8, src_stride, src1, src3, src5, src7);
-        src += (4 * src_stride);
-
-        hz_out1 = HORIZ_2TAP_FILT_UH(src0, src0, mask, filt_hz,
-                                     VP8_FILTER_SHIFT);
-        hz_out3 = HORIZ_2TAP_FILT_UH(src1, src1, mask, filt_hz,
-                                     VP8_FILTER_SHIFT);
-        ILVEV_B2_UB(hz_out0, hz_out1, hz_out2, hz_out3, vec0, vec1);
-        DOTP_UB2_UH(vec0, vec1, filt_vt, filt_vt, tmp1, tmp2);
-        SRARI_H2_UH(tmp1, tmp2, VP8_FILTER_SHIFT);
-        PCKEV_ST_SB(tmp1, tmp2, dst);
-        dst += dst_stride;
-
-        hz_out0 = HORIZ_2TAP_FILT_UH(src2, src2, mask, filt_hz,
-                                     VP8_FILTER_SHIFT);
-        hz_out2 = HORIZ_2TAP_FILT_UH(src3, src3, mask, filt_hz,
-                                     VP8_FILTER_SHIFT);
-        ILVEV_B2_UB(hz_out1, hz_out0, hz_out3, hz_out2, vec0, vec1);
-        DOTP_UB2_UH(vec0, vec1, filt_vt, filt_vt, tmp1, tmp2);
-        SRARI_H2_UH(tmp1, tmp2, VP8_FILTER_SHIFT);
-        PCKEV_ST_SB(tmp1, tmp2, dst);
-        dst += dst_stride;
-
-        hz_out1 = HORIZ_2TAP_FILT_UH(src4, src4, mask, filt_hz,
-                                     VP8_FILTER_SHIFT);
-        hz_out3 = HORIZ_2TAP_FILT_UH(src5, src5, mask, filt_hz,
-                                     VP8_FILTER_SHIFT);
-        ILVEV_B2_UB(hz_out0, hz_out1, hz_out2, hz_out3, vec0, vec1);
-        DOTP_UB2_UH(vec0, vec1, filt_vt, filt_vt, tmp1, tmp2);
-        SRARI_H2_UH(tmp1, tmp2, VP8_FILTER_SHIFT);
-        PCKEV_ST_SB(tmp1, tmp2, dst);
-        dst += dst_stride;
-
-        hz_out0 = HORIZ_2TAP_FILT_UH(src6, src6, mask, filt_hz,
-                                     VP8_FILTER_SHIFT);
-        hz_out2 = HORIZ_2TAP_FILT_UH(src7, src7, mask, filt_hz,
-                                     VP8_FILTER_SHIFT);
-        ILVEV_B2_UB(hz_out1, hz_out0, hz_out3, hz_out2, vec0, vec1);
-        DOTP_UB2_UH(vec0, vec1, filt_vt, filt_vt, tmp1, tmp2);
-        SRARI_H2_UH(tmp1, tmp2, VP8_FILTER_SHIFT);
-        PCKEV_ST_SB(tmp1, tmp2, dst);
-        dst += dst_stride;
-    }
-}
-
-void vp8_bilinear_predict4x4_msa(uint8_t *RESTRICT src, int32_t src_stride,
-                                 int32_t xoffset, int32_t yoffset,
-                                 uint8_t *RESTRICT dst, int32_t dst_stride)
-{
-    const int8_t *h_filter = vp8_bilinear_filters_msa[xoffset - 1];
-    const int8_t *v_filter = vp8_bilinear_filters_msa[yoffset - 1];
-
-    if (yoffset)
-    {
-        if (xoffset)
-        {
-            common_hv_2ht_2vt_4w_msa(src, src_stride, dst, dst_stride,
-                                     h_filter, v_filter, 4);
-        }
-        else
-        {
-            common_vt_2t_4w_msa(src, src_stride, dst, dst_stride, v_filter, 4);
-        }
-    }
-    else
-    {
-        if (xoffset)
-        {
-            common_hz_2t_4w_msa(src, src_stride, dst, dst_stride, h_filter, 4);
-        }
-        else
-        {
-            uint32_t tp0, tp1, tp2, tp3;
-
-            LW4(src, src_stride, tp0, tp1, tp2, tp3);
-            SW4(tp0, tp1, tp2, tp3, dst, dst_stride);
-        }
-    }
-}
-
-void vp8_bilinear_predict8x4_msa(uint8_t *RESTRICT src, int32_t src_stride,
-                                 int32_t xoffset, int32_t yoffset,
-                                 uint8_t *RESTRICT dst, int32_t dst_stride)
-{
-    const int8_t *h_filter = vp8_bilinear_filters_msa[xoffset - 1];
-    const int8_t *v_filter = vp8_bilinear_filters_msa[yoffset - 1];
-
-    if (yoffset)
-    {
-        if (xoffset)
-        {
-            common_hv_2ht_2vt_8w_msa(src, src_stride, dst, dst_stride,
-                                     h_filter, v_filter, 4);
-        }
-        else
-        {
-            common_vt_2t_8w_msa(src, src_stride, dst, dst_stride, v_filter, 4);
-        }
-    }
-    else
-    {
-        if (xoffset)
-        {
-            common_hz_2t_8w_msa(src, src_stride, dst, dst_stride, h_filter, 4);
-        }
-        else
-        {
-            vp8_copy_mem8x4(src, src_stride, dst, dst_stride);
-        }
-    }
-}
-
-void vp8_bilinear_predict8x8_msa(uint8_t *RESTRICT src, int32_t src_stride,
-                                 int32_t xoffset, int32_t yoffset,
-                                 uint8_t *RESTRICT dst, int32_t dst_stride)
-{
-    const int8_t *h_filter = vp8_bilinear_filters_msa[xoffset - 1];
-    const int8_t *v_filter = vp8_bilinear_filters_msa[yoffset - 1];
-
-    if (yoffset)
-    {
-        if (xoffset)
-        {
-            common_hv_2ht_2vt_8w_msa(src, src_stride, dst, dst_stride,
-                                     h_filter, v_filter, 8);
-        }
-        else
-        {
-            common_vt_2t_8w_msa(src, src_stride, dst, dst_stride, v_filter, 8);
-        }
-    }
-    else
-    {
-        if (xoffset)
-        {
-            common_hz_2t_8w_msa(src, src_stride, dst, dst_stride, h_filter, 8);
-        }
-        else
-        {
-            vp8_copy_mem8x8(src, src_stride, dst, dst_stride);
-        }
-    }
-}
-
-void vp8_bilinear_predict16x16_msa(uint8_t *RESTRICT src, int32_t src_stride,
-                                   int32_t xoffset, int32_t yoffset,
-                                   uint8_t *RESTRICT dst, int32_t dst_stride)
-{
-    const int8_t *h_filter = vp8_bilinear_filters_msa[xoffset - 1];
-    const int8_t *v_filter = vp8_bilinear_filters_msa[yoffset - 1];
-
-    if (yoffset)
-    {
-        if (xoffset)
-        {
-            common_hv_2ht_2vt_16w_msa(src, src_stride, dst, dst_stride,
-                                      h_filter, v_filter, 16);
-        }
-        else
-        {
-            common_vt_2t_16w_msa(src, src_stride, dst, dst_stride, v_filter,
-                                 16);
-        }
-    }
-    else
-    {
-        if (xoffset)
-        {
-            common_hz_2t_16w_msa(src, src_stride, dst, dst_stride, h_filter,
-                                 16);
-        }
-        else
-        {
-            vp8_copy_mem16x16(src, src_stride, dst, dst_stride);
-        }
-    }
-}
diff --git a/vp8/common/mips/msa/copymem_msa.c b/vp8/common/mips/msa/copymem_msa.c
deleted file mode 100644 (file)
index 002a5ed..0000000
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- *  Copyright (c) 2015 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.
- */
-
-#include "./vp8_rtcd.h"
-#include "vp8/common/mips/msa/vp8_macros_msa.h"
-
-static void copy_8x4_msa(uint8_t *src, int32_t src_stride,
-                         uint8_t *dst, int32_t dst_stride)
-{
-    uint64_t src0, src1, src2, src3;
-
-    LD4(src, src_stride, src0, src1, src2, src3);
-    SD4(src0, src1, src2, src3, dst, dst_stride);
-}
-
-static void copy_8x8_msa(uint8_t *src, int32_t src_stride,
-                         uint8_t *dst, int32_t dst_stride)
-{
-    uint64_t src0, src1, src2, src3;
-
-    LD4(src, src_stride, src0, src1, src2, src3);
-    src += (4 * src_stride);
-    SD4(src0, src1, src2, src3, dst, dst_stride);
-    dst += (4 * dst_stride);
-
-    LD4(src, src_stride, src0, src1, src2, src3);
-    SD4(src0, src1, src2, src3, dst, dst_stride);
-}
-
-static void copy_16x16_msa(uint8_t *src, int32_t src_stride,
-                           uint8_t *dst, int32_t dst_stride)
-{
-    v16u8 src0, src1, src2, src3, src4, src5, src6, src7;
-    v16u8 src8, src9, src10, src11, src12, src13, src14, src15;
-
-    LD_UB8(src, src_stride, src0, src1, src2, src3, src4, src5, src6, src7);
-    src += (8 * src_stride);
-    LD_UB8(src, src_stride, src8, src9, src10, src11, src12, src13, src14,
-           src15);
-
-    ST_UB8(src0, src1, src2, src3, src4, src5, src6, src7, dst, dst_stride);
-    dst += (8 * dst_stride);
-    ST_UB8(src8, src9, src10, src11, src12, src13, src14, src15, dst,
-           dst_stride);
-}
-
-void vp8_copy_mem16x16_msa(uint8_t *src, int32_t src_stride,
-                           uint8_t *dst, int32_t dst_stride)
-{
-    copy_16x16_msa(src, src_stride, dst, dst_stride);
-}
-
-void vp8_copy_mem8x8_msa(uint8_t *src, int32_t src_stride,
-                         uint8_t *dst, int32_t dst_stride)
-{
-    copy_8x8_msa(src, src_stride, dst, dst_stride);
-}
-
-void vp8_copy_mem8x4_msa(uint8_t *src, int32_t src_stride,
-                         uint8_t *dst, int32_t dst_stride)
-{
-    copy_8x4_msa(src, src_stride, dst, dst_stride);
-}
diff --git a/vp8/common/mips/msa/idct_msa.c b/vp8/common/mips/msa/idct_msa.c
deleted file mode 100644 (file)
index e537a3f..0000000
+++ /dev/null
@@ -1,457 +0,0 @@
-/*
- *  Copyright (c) 2015 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.
- */
-
-#include "./vp8_rtcd.h"
-#include "vp8/common/blockd.h"
-#include "vp8/common/mips/msa/vp8_macros_msa.h"
-
-static const int32_t cospi8sqrt2minus1 = 20091;
-static const int32_t sinpi8sqrt2 = 35468;
-
-#define TRANSPOSE_TWO_4x4_H(in0, in1, in2, in3, out0, out1, out2, out3)  \
-{                                                                        \
-    v8i16 s4_m, s5_m, s6_m, s7_m;                                        \
-                                                                         \
-    TRANSPOSE8X4_SH_SH(in0, in1, in2, in3, s4_m, s5_m, s6_m, s7_m);      \
-    ILVR_D2_SH(s6_m, s4_m, s7_m, s5_m, out0, out2);                      \
-    out1 = (v8i16)__msa_ilvl_d((v2i64)s6_m, (v2i64)s4_m);                \
-    out3 = (v8i16)__msa_ilvl_d((v2i64)s7_m, (v2i64)s5_m);                \
-}
-
-#define EXPAND_TO_H_MULTIPLY_SINPI8SQRT2_PCK_TO_W(in)     \
-({                                                        \
-    v8i16 out_m;                                          \
-    v8i16 zero_m = { 0 };                                 \
-    v4i32 tmp1_m, tmp2_m;                                 \
-    v4i32 sinpi8_sqrt2_m = __msa_fill_w(sinpi8sqrt2);     \
-                                                          \
-    ILVRL_H2_SW(in, zero_m, tmp1_m, tmp2_m);              \
-    tmp1_m >>= 16;                                        \
-    tmp2_m >>= 16;                                        \
-    tmp1_m = (tmp1_m * sinpi8_sqrt2_m) >> 16;             \
-    tmp2_m = (tmp2_m * sinpi8_sqrt2_m) >> 16;             \
-    out_m = __msa_pckev_h((v8i16)tmp2_m, (v8i16)tmp1_m);  \
-                                                          \
-    out_m;                                                \
-})
-
-#define VP8_IDCT_1D_H(in0, in1, in2, in3, out0, out1, out2, out3)  \
-{                                                                  \
-    v8i16 a1_m, b1_m, c1_m, d1_m;                                  \
-    v8i16 c_tmp1_m, c_tmp2_m, d_tmp1_m, d_tmp2_m;                  \
-    v8i16 const_cospi8sqrt2minus1_m;                               \
-                                                                   \
-    const_cospi8sqrt2minus1_m = __msa_fill_h(cospi8sqrt2minus1);   \
-    a1_m = in0 + in2;                                              \
-    b1_m = in0 - in2;                                              \
-    c_tmp1_m = EXPAND_TO_H_MULTIPLY_SINPI8SQRT2_PCK_TO_W(in1);     \
-    c_tmp2_m = __msa_mul_q_h(in3, const_cospi8sqrt2minus1_m);      \
-    c_tmp2_m = c_tmp2_m >> 1;                                      \
-    c_tmp2_m = in3 + c_tmp2_m;                                     \
-    c1_m = c_tmp1_m - c_tmp2_m;                                    \
-    d_tmp1_m = __msa_mul_q_h(in1, const_cospi8sqrt2minus1_m);      \
-    d_tmp1_m = d_tmp1_m >> 1;                                      \
-    d_tmp1_m = in1 + d_tmp1_m;                                     \
-    d_tmp2_m = EXPAND_TO_H_MULTIPLY_SINPI8SQRT2_PCK_TO_W(in3);     \
-    d1_m = d_tmp1_m + d_tmp2_m;                                    \
-    BUTTERFLY_4(a1_m, b1_m, c1_m, d1_m, out0, out1, out2, out3);   \
-}
-
-#define VP8_IDCT_1D_W(in0, in1, in2, in3, out0, out1, out2, out3)  \
-{                                                                  \
-    v4i32 a1_m, b1_m, c1_m, d1_m;                                  \
-    v4i32 c_tmp1_m, c_tmp2_m, d_tmp1_m, d_tmp2_m;                  \
-    v4i32 const_cospi8sqrt2minus1_m, sinpi8_sqrt2_m;               \
-                                                                   \
-    const_cospi8sqrt2minus1_m = __msa_fill_w(cospi8sqrt2minus1);   \
-    sinpi8_sqrt2_m = __msa_fill_w(sinpi8sqrt2);                    \
-    a1_m = in0 + in2;                                              \
-    b1_m = in0 - in2;                                              \
-    c_tmp1_m = (in1 * sinpi8_sqrt2_m) >> 16;                       \
-    c_tmp2_m = in3 + ((in3 * const_cospi8sqrt2minus1_m) >> 16);    \
-    c1_m = c_tmp1_m - c_tmp2_m;                                    \
-    d_tmp1_m = in1 + ((in1 * const_cospi8sqrt2minus1_m) >> 16);    \
-    d_tmp2_m = (in3 * sinpi8_sqrt2_m) >> 16;                       \
-    d1_m = d_tmp1_m + d_tmp2_m;                                    \
-    BUTTERFLY_4(a1_m, b1_m, c1_m, d1_m, out0, out1, out2, out3);   \
-}
-
-static void idct4x4_addblk_msa(int16_t *input, uint8_t *pred,
-                               int32_t pred_stride,
-                               uint8_t *dest, int32_t dest_stride)
-{
-    v8i16 input0, input1;
-    v4i32 in0, in1, in2, in3, hz0, hz1, hz2, hz3, vt0, vt1, vt2, vt3;
-    v4i32 res0, res1, res2, res3;
-    v16i8 zero = { 0 };
-    v16i8 pred0, pred1, pred2, pred3, dest0, dest1, dest2, dest3;
-    v16i8 mask = { 0, 4, 8, 12, 20, 21, 22, 23, 24,
-                   25, 26, 27, 28, 29, 30, 31 };
-
-    LD_SH2(input, 8, input0, input1);
-    UNPCK_SH_SW(input0, in0, in1);
-    UNPCK_SH_SW(input1, in2, in3);
-    VP8_IDCT_1D_W(in0, in1, in2, in3, hz0, hz1, hz2, hz3);
-    TRANSPOSE4x4_SW_SW(hz0, hz1, hz2, hz3, hz0, hz1, hz2, hz3);
-    VP8_IDCT_1D_W(hz0, hz1, hz2, hz3, vt0, vt1, vt2, vt3);
-    SRARI_W4_SW(vt0, vt1, vt2, vt3, 3);
-    TRANSPOSE4x4_SW_SW(vt0, vt1, vt2, vt3, vt0, vt1, vt2, vt3);
-    LD_SB4(pred, pred_stride, pred0, pred1, pred2, pred3);
-    ILVR_B4_SW(zero, pred0, zero, pred1, zero, pred2, zero, pred3, res0, res1,
-               res2, res3);
-    ILVR_H4_SW(zero, res0, zero, res1, zero, res2, zero, res3, res0, res1,
-               res2, res3);
-    ADD4(res0, vt0, res1, vt1, res2, vt2, res3, vt3, res0, res1, res2, res3);
-    res0 = CLIP_SW_0_255(res0);
-    res1 = CLIP_SW_0_255(res1);
-    res2 = CLIP_SW_0_255(res2);
-    res3 = CLIP_SW_0_255(res3);
-    LD_SB4(dest, dest_stride, dest0, dest1, dest2, dest3);
-    VSHF_B2_SB(res0, dest0, res1, dest1, mask, mask, dest0, dest1);
-    VSHF_B2_SB(res2, dest2, res3, dest3, mask, mask, dest2, dest3);
-    ST_SB4(dest0, dest1, dest2, dest3, dest, dest_stride);
-}
-
-static void idct4x4_addconst_msa(int16_t in_dc, uint8_t *pred,
-                                 int32_t pred_stride,
-                                 uint8_t *dest, int32_t dest_stride)
-{
-    v8i16 vec;
-    v8i16 res0, res1, res2, res3;
-    v16i8 zero = { 0 };
-    v16i8 pred0, pred1, pred2, pred3, dest0, dest1, dest2, dest3;
-    v16i8 mask = { 0, 2, 4, 6, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 };
-
-    vec = __msa_fill_h(in_dc);
-    vec = __msa_srari_h(vec, 3);
-    LD_SB4(pred, pred_stride, pred0, pred1, pred2, pred3);
-    ILVR_B4_SH(zero, pred0, zero, pred1, zero, pred2, zero, pred3, res0, res1,
-               res2, res3);
-    ADD4(res0, vec, res1, vec, res2, vec, res3, vec, res0, res1, res2, res3);
-    CLIP_SH4_0_255(res0, res1, res2, res3);
-    LD_SB4(dest, dest_stride, dest0, dest1, dest2, dest3);
-    VSHF_B2_SB(res0, dest0, res1, dest1, mask, mask, dest0, dest1);
-    VSHF_B2_SB(res2, dest2, res3, dest3, mask, mask, dest2, dest3);
-    ST_SB4(dest0, dest1, dest2, dest3, dest, dest_stride);
-}
-
-void vp8_short_inv_walsh4x4_msa(int16_t *input, int16_t *mb_dq_coeff)
-{
-    v8i16 input0, input1;
-    v4i32 in0, in1, in2, in3, a1, b1, c1, d1;
-    v4i32 hz0, hz1, hz2, hz3, vt0, vt1, vt2, vt3;
-
-    LD_SH2(input, 8, input0, input1);
-    UNPCK_SH_SW(input0, in0, in1);
-    UNPCK_SH_SW(input1, in2, in3);
-    BUTTERFLY_4(in0, in1, in2, in3, a1, b1, c1, d1);
-    BUTTERFLY_4(a1, d1, c1, b1, hz0, hz1, hz3, hz2);
-    TRANSPOSE4x4_SW_SW(hz0, hz1, hz2, hz3, hz0, hz1, hz2, hz3);
-    BUTTERFLY_4(hz0, hz1, hz2, hz3, a1, b1, c1, d1);
-    BUTTERFLY_4(a1, d1, c1, b1, vt0, vt1, vt3, vt2);
-    ADD4(vt0, 3, vt1, 3, vt2, 3, vt3, 3, vt0, vt1, vt2, vt3);
-    SRA_4V(vt0, vt1, vt2, vt3, 3);
-    mb_dq_coeff[0] = __msa_copy_s_h((v8i16)vt0, 0);
-    mb_dq_coeff[16] = __msa_copy_s_h((v8i16)vt1, 0);
-    mb_dq_coeff[32] = __msa_copy_s_h((v8i16)vt2, 0);
-    mb_dq_coeff[48] = __msa_copy_s_h((v8i16)vt3, 0);
-    mb_dq_coeff[64] = __msa_copy_s_h((v8i16)vt0, 2);
-    mb_dq_coeff[80] = __msa_copy_s_h((v8i16)vt1, 2);
-    mb_dq_coeff[96] = __msa_copy_s_h((v8i16)vt2, 2);
-    mb_dq_coeff[112] = __msa_copy_s_h((v8i16)vt3, 2);
-    mb_dq_coeff[128] = __msa_copy_s_h((v8i16)vt0, 4);
-    mb_dq_coeff[144] = __msa_copy_s_h((v8i16)vt1, 4);
-    mb_dq_coeff[160] = __msa_copy_s_h((v8i16)vt2, 4);
-    mb_dq_coeff[176] = __msa_copy_s_h((v8i16)vt3, 4);
-    mb_dq_coeff[192] = __msa_copy_s_h((v8i16)vt0, 6);
-    mb_dq_coeff[208] = __msa_copy_s_h((v8i16)vt1, 6);
-    mb_dq_coeff[224] = __msa_copy_s_h((v8i16)vt2, 6);
-    mb_dq_coeff[240] = __msa_copy_s_h((v8i16)vt3, 6);
-}
-
-static void dequant_idct4x4_addblk_msa(int16_t *input, int16_t *dequant_input,
-                                       uint8_t *dest, int32_t dest_stride)
-{
-    v8i16 input0, input1, dequant_in0, dequant_in1, mul0, mul1;
-    v8i16 in0, in1, in2, in3;
-    v8i16 hz0_h, hz1_h, hz2_h, hz3_h;
-    v16i8 dest0, dest1, dest2, dest3;
-    v4i32 hz0_w, hz1_w, hz2_w, hz3_w;
-    v4i32 vt0, vt1, vt2, vt3, res0, res1, res2, res3;
-    v2i64 zero = { 0 };
-    v16i8 mask = { 0, 4, 8, 12, 20, 21, 22, 23, 24,
-                   25, 26, 27, 28, 29, 30, 31 };
-
-    LD_SH2(input, 8, input0, input1);
-    LD_SH2(dequant_input, 8, dequant_in0, dequant_in1);
-    MUL2(input0, dequant_in0, input1, dequant_in1, mul0, mul1);
-    PCKEV_D2_SH(zero, mul0, zero, mul1, in0, in2);
-    PCKOD_D2_SH(zero, mul0, zero, mul1, in1, in3);
-    VP8_IDCT_1D_H(in0, in1, in2, in3, hz0_h, hz1_h, hz2_h, hz3_h);
-    PCKEV_D2_SH(hz1_h, hz0_h, hz3_h, hz2_h, mul0, mul1);
-    UNPCK_SH_SW(mul0, hz0_w, hz1_w);
-    UNPCK_SH_SW(mul1, hz2_w, hz3_w);
-    TRANSPOSE4x4_SW_SW(hz0_w, hz1_w, hz2_w, hz3_w, hz0_w, hz1_w, hz2_w, hz3_w);
-    VP8_IDCT_1D_W(hz0_w, hz1_w, hz2_w, hz3_w, vt0, vt1, vt2, vt3);
-    SRARI_W4_SW(vt0, vt1, vt2, vt3, 3);
-    TRANSPOSE4x4_SW_SW(vt0, vt1, vt2, vt3, vt0, vt1, vt2, vt3);
-    LD_SB4(dest, dest_stride, dest0, dest1, dest2, dest3);
-    ILVR_B4_SW(zero, dest0, zero, dest1, zero, dest2, zero, dest3, res0, res1,
-               res2, res3);
-    ILVR_H4_SW(zero, res0, zero, res1, zero, res2, zero, res3, res0, res1,
-               res2, res3);
-    ADD4(res0, vt0, res1, vt1, res2, vt2, res3, vt3, res0, res1, res2, res3);
-    res0 = CLIP_SW_0_255(res0);
-    res1 = CLIP_SW_0_255(res1);
-    res2 = CLIP_SW_0_255(res2);
-    res3 = CLIP_SW_0_255(res3);
-    VSHF_B2_SB(res0, dest0, res1, dest1, mask, mask, dest0, dest1);
-    VSHF_B2_SB(res2, dest2, res3, dest3, mask, mask, dest2, dest3);
-    ST_SB4(dest0, dest1, dest2, dest3, dest, dest_stride);
-}
-
-static void dequant_idct4x4_addblk_2x_msa(int16_t *input,
-                                          int16_t *dequant_input,
-                                          uint8_t *dest, int32_t dest_stride)
-{
-    v16u8 dest0, dest1, dest2, dest3;
-    v8i16 in0, in1, in2, in3;
-    v8i16 mul0, mul1, mul2, mul3, dequant_in0, dequant_in1;
-    v8i16 hz0, hz1, hz2, hz3, vt0, vt1, vt2, vt3;
-    v8i16 res0, res1, res2, res3;
-    v4i32 hz0l, hz1l, hz2l, hz3l, hz0r, hz1r, hz2r, hz3r;
-    v4i32 vt0l, vt1l, vt2l, vt3l, vt0r, vt1r, vt2r, vt3r;
-    v16i8 zero = { 0 };
-
-    LD_SH4(input, 8, in0, in1, in2, in3);
-    LD_SH2(dequant_input, 8, dequant_in0, dequant_in1);
-    MUL4(in0, dequant_in0, in1, dequant_in1, in2, dequant_in0, in3, dequant_in1,
-         mul0, mul1, mul2, mul3);
-    PCKEV_D2_SH(mul2, mul0, mul3, mul1, in0, in2);
-    PCKOD_D2_SH(mul2, mul0, mul3, mul1, in1, in3);
-    VP8_IDCT_1D_H(in0, in1, in2, in3, hz0, hz1, hz2, hz3);
-    TRANSPOSE_TWO_4x4_H(hz0, hz1, hz2, hz3, hz0, hz1, hz2, hz3);
-    UNPCK_SH_SW(hz0, hz0r, hz0l);
-    UNPCK_SH_SW(hz1, hz1r, hz1l);
-    UNPCK_SH_SW(hz2, hz2r, hz2l);
-    UNPCK_SH_SW(hz3, hz3r, hz3l);
-    VP8_IDCT_1D_W(hz0l, hz1l, hz2l, hz3l, vt0l, vt1l, vt2l, vt3l);
-    SRARI_W4_SW(vt0l, vt1l, vt2l, vt3l, 3);
-    VP8_IDCT_1D_W(hz0r, hz1r, hz2r, hz3r, vt0r, vt1r, vt2r, vt3r);
-    SRARI_W4_SW(vt0r, vt1r, vt2r, vt3r, 3);
-    PCKEV_H4_SH(vt0l, vt0r, vt1l, vt1r, vt2l, vt2r, vt3l, vt3r, vt0, vt1, vt2,
-                vt3);
-    TRANSPOSE_TWO_4x4_H(vt0, vt1, vt2, vt3, vt0, vt1, vt2, vt3);
-    LD_UB4(dest, dest_stride, dest0, dest1, dest2, dest3);
-    ILVR_B4_SH(zero, dest0, zero, dest1, zero, dest2, zero, dest3, res0, res1,
-               res2, res3);
-    ADD4(res0, vt0, res1, vt1, res2, vt2, res3, vt3, res0, res1, res2, res3);
-    CLIP_SH4_0_255(res0, res1, res2, res3);
-    PCKEV_B4_SH(res0, res0, res1, res1, res2, res2, res3, res3, res0, res1,
-                res2, res3);
-    PCKOD_D2_UB(dest0, res0, dest1, res1, dest0, dest1);
-    PCKOD_D2_UB(dest2, res2, dest3, res3, dest2, dest3);
-    ST_UB4(dest0, dest1, dest2, dest3, dest, dest_stride);
-
-    __asm__ __volatile__(
-        "sw   $zero,    0(%[input])  \n\t"
-        "sw   $zero,    4(%[input])  \n\t"
-        "sw   $zero,    8(%[input])  \n\t"
-        "sw   $zero,   12(%[input])  \n\t"
-        "sw   $zero,   16(%[input])  \n\t"
-        "sw   $zero,   20(%[input])  \n\t"
-        "sw   $zero,   24(%[input])  \n\t"
-        "sw   $zero,   28(%[input])  \n\t"
-        "sw   $zero,   32(%[input])  \n\t"
-        "sw   $zero,   36(%[input])  \n\t"
-        "sw   $zero,   40(%[input])  \n\t"
-        "sw   $zero,   44(%[input])  \n\t"
-        "sw   $zero,   48(%[input])  \n\t"
-        "sw   $zero,   52(%[input])  \n\t"
-        "sw   $zero,   56(%[input])  \n\t"
-        "sw   $zero,   60(%[input])  \n\t"::
-
-        [input] "r"(input)
-    );
-}
-
-static void dequant_idct_addconst_2x_msa(int16_t *input, int16_t *dequant_input,
-                                         uint8_t *dest, int32_t dest_stride)
-{
-    v8i16 input_dc0, input_dc1, vec;
-    v16u8 dest0, dest1, dest2, dest3;
-    v16i8 zero = { 0 };
-    v8i16 res0, res1, res2, res3;
-
-    input_dc0 = __msa_fill_h(input[0] * dequant_input[0]);
-    input_dc1 = __msa_fill_h(input[16] * dequant_input[0]);
-    SRARI_H2_SH(input_dc0, input_dc1, 3);
-    vec = (v8i16)__msa_pckev_d((v2i64)input_dc1, (v2i64)input_dc0);
-    input[0] = 0;
-    input[16] = 0;
-    LD_UB4(dest, dest_stride, dest0, dest1, dest2, dest3);
-    ILVR_B4_SH(zero, dest0, zero, dest1, zero, dest2, zero, dest3, res0,
-               res1, res2, res3);
-    ADD4(res0, vec, res1, vec, res2, vec, res3, vec, res0, res1, res2, res3);
-    CLIP_SH4_0_255(res0, res1, res2, res3);
-    PCKEV_B4_SH(res0, res0, res1, res1, res2, res2, res3, res3, res0, res1,
-                res2, res3);
-    PCKOD_D2_UB(dest0, res0, dest1, res1, dest0, dest1);
-    PCKOD_D2_UB(dest2, res2, dest3, res3, dest2, dest3);
-    ST_UB4(dest0, dest1, dest2, dest3, dest, dest_stride);
-}
-
-void vp8_short_idct4x4llm_msa(int16_t *input, uint8_t *pred_ptr,
-                              int32_t pred_stride, uint8_t *dst_ptr,
-                              int32_t dst_stride)
-{
-    idct4x4_addblk_msa(input, pred_ptr, pred_stride, dst_ptr, dst_stride);
-}
-
-void vp8_dc_only_idct_add_msa(int16_t input_dc, uint8_t *pred_ptr,
-                              int32_t pred_stride, uint8_t *dst_ptr,
-                              int32_t dst_stride)
-{
-    idct4x4_addconst_msa(input_dc, pred_ptr, pred_stride, dst_ptr, dst_stride);
-}
-
-void vp8_dequantize_b_msa(BLOCKD *d, int16_t *DQC)
-{
-    v8i16 dqc0, dqc1, q0, q1, dq0, dq1;
-
-    LD_SH2(DQC, 8, dqc0, dqc1);
-    LD_SH2(d->qcoeff, 8, q0, q1);
-    MUL2(dqc0, q0, dqc1, q1, dq0, dq1);
-    ST_SH2(dq0, dq1, d->dqcoeff, 8);
-}
-
-void vp8_dequant_idct_add_msa(int16_t *input, int16_t *dq,
-                              uint8_t *dest, int32_t stride)
-{
-    dequant_idct4x4_addblk_msa(input, dq, dest, stride);
-
-    __asm__ __volatile__ (
-        "sw     $zero,    0(%[input])     \n\t"
-        "sw     $zero,    4(%[input])     \n\t"
-        "sw     $zero,    8(%[input])     \n\t"
-        "sw     $zero,   12(%[input])     \n\t"
-        "sw     $zero,   16(%[input])     \n\t"
-        "sw     $zero,   20(%[input])     \n\t"
-        "sw     $zero,   24(%[input])     \n\t"
-        "sw     $zero,   28(%[input])     \n\t"
-
-        :
-        : [input] "r" (input)
-    );
-}
-
-void vp8_dequant_idct_add_y_block_msa(int16_t *q, int16_t *dq,
-                                      uint8_t *dst, int32_t stride,
-                                      char *eobs)
-{
-    int16_t *eobs_h = (int16_t *)eobs;
-    uint8_t i;
-
-    for (i = 4; i--;)
-    {
-        if (eobs_h[0])
-        {
-            if (eobs_h[0] & 0xfefe)
-            {
-                dequant_idct4x4_addblk_2x_msa(q, dq, dst, stride);
-            }
-            else
-            {
-                dequant_idct_addconst_2x_msa(q, dq, dst, stride);
-            }
-        }
-
-        q += 32;
-
-        if (eobs_h[1])
-        {
-            if (eobs_h[1] & 0xfefe)
-            {
-                dequant_idct4x4_addblk_2x_msa(q, dq, dst + 8, stride);
-            }
-            else
-            {
-                dequant_idct_addconst_2x_msa(q, dq, dst + 8, stride);
-            }
-        }
-
-        q += 32;
-        dst += (4 * stride);
-        eobs_h += 2;
-    }
-}
-
-void vp8_dequant_idct_add_uv_block_msa(int16_t *q, int16_t *dq,
-                                       uint8_t *dstu, uint8_t *dstv,
-                                       int32_t stride, char *eobs)
-{
-    int16_t *eobs_h = (int16_t *)eobs;
-
-    if (eobs_h[0])
-    {
-        if (eobs_h[0] & 0xfefe)
-        {
-            dequant_idct4x4_addblk_2x_msa(q, dq, dstu, stride);
-        }
-        else
-        {
-            dequant_idct_addconst_2x_msa(q, dq, dstu, stride);
-        }
-    }
-
-    q += 32;
-    dstu += (stride * 4);
-
-    if (eobs_h[1])
-    {
-        if (eobs_h[1] & 0xfefe)
-        {
-            dequant_idct4x4_addblk_2x_msa(q, dq, dstu, stride);
-        }
-        else
-        {
-            dequant_idct_addconst_2x_msa(q, dq, dstu, stride);
-        }
-    }
-
-    q += 32;
-
-    if (eobs_h[2])
-    {
-        if (eobs_h[2] & 0xfefe)
-        {
-            dequant_idct4x4_addblk_2x_msa(q, dq, dstv, stride);
-        }
-        else
-        {
-            dequant_idct_addconst_2x_msa(q, dq, dstv, stride);
-        }
-    }
-
-    q += 32;
-    dstv += (stride * 4);
-
-    if (eobs_h[3])
-    {
-        if (eobs_h[3] & 0xfefe)
-        {
-            dequant_idct4x4_addblk_2x_msa(q, dq, dstv, stride);
-        }
-        else
-        {
-            dequant_idct_addconst_2x_msa(q, dq, dstv, stride);
-        }
-    }
-}
diff --git a/vp8/common/mips/msa/loopfilter_filters_msa.c b/vp8/common/mips/msa/loopfilter_filters_msa.c
deleted file mode 100644 (file)
index a40f378..0000000
+++ /dev/null
@@ -1,826 +0,0 @@
-/*
- *  Copyright (c) 2015 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.
- */
-
-#include "./vp8_rtcd.h"
-#include "vp8/common/loopfilter.h"
-#include "vp8/common/mips/msa/vp8_macros_msa.h"
-
-#define VP8_SIMPLE_MASK(p1, p0, q0, q1, b_limit, mask)         \
-{                                                              \
-    v16u8 p1_a_sub_q1, p0_a_sub_q0;                            \
-                                                               \
-    p0_a_sub_q0 = __msa_asub_u_b(p0, q0);                      \
-    p1_a_sub_q1 = __msa_asub_u_b(p1, q1);                      \
-    p1_a_sub_q1 = (v16u8)__msa_srli_b((v16i8)p1_a_sub_q1, 1);  \
-    p0_a_sub_q0 = __msa_adds_u_b(p0_a_sub_q0, p0_a_sub_q0);    \
-    mask = __msa_adds_u_b(p0_a_sub_q0, p1_a_sub_q1);           \
-    mask = ((v16u8)mask <= b_limit);                           \
-}
-
-#define VP8_LPF_FILTER4_4W(p1_in_out, p0_in_out, q0_in_out, q1_in_out,  \
-                           mask_in, hev_in)                             \
-{                                                                       \
-    v16i8 p1_m, p0_m, q0_m, q1_m, q0_sub_p0, filt_sign;                 \
-    v16i8 filt, filt1, filt2, cnst4b, cnst3b;                           \
-    v8i16 q0_sub_p0_r, q0_sub_p0_l, filt_l, filt_r, cnst3h;             \
-                                                                        \
-    p1_m = (v16i8)__msa_xori_b(p1_in_out, 0x80);                        \
-    p0_m = (v16i8)__msa_xori_b(p0_in_out, 0x80);                        \
-    q0_m = (v16i8)__msa_xori_b(q0_in_out, 0x80);                        \
-    q1_m = (v16i8)__msa_xori_b(q1_in_out, 0x80);                        \
-                                                                        \
-    filt = __msa_subs_s_b(p1_m, q1_m);                                  \
-                                                                        \
-    filt = filt & (v16i8)hev_in;                                        \
-                                                                        \
-    q0_sub_p0 = q0_m - p0_m;                                            \
-    filt_sign = __msa_clti_s_b(filt, 0);                                \
-                                                                        \
-    cnst3h = __msa_ldi_h(3);                                            \
-    q0_sub_p0_r = (v8i16)__msa_ilvr_b(q0_sub_p0, q0_sub_p0);            \
-    q0_sub_p0_r = __msa_dotp_s_h((v16i8)q0_sub_p0_r, (v16i8)cnst3h);    \
-    filt_r = (v8i16)__msa_ilvr_b(filt_sign, filt);                      \
-    filt_r += q0_sub_p0_r;                                              \
-    filt_r = __msa_sat_s_h(filt_r, 7);                                  \
-                                                                        \
-    q0_sub_p0_l = (v8i16)__msa_ilvl_b(q0_sub_p0, q0_sub_p0);            \
-    q0_sub_p0_l = __msa_dotp_s_h((v16i8)q0_sub_p0_l, (v16i8)cnst3h);    \
-    filt_l = (v8i16)__msa_ilvl_b(filt_sign, filt);                      \
-    filt_l += q0_sub_p0_l;                                              \
-    filt_l = __msa_sat_s_h(filt_l, 7);                                  \
-                                                                        \
-    filt = __msa_pckev_b((v16i8)filt_l, (v16i8)filt_r);                 \
-    filt = filt & (v16i8)mask_in;                                       \
-                                                                        \
-    cnst4b = __msa_ldi_b(4);                                            \
-    filt1 = __msa_adds_s_b(filt, cnst4b);                               \
-    filt1 >>= 3;                                                        \
-                                                                        \
-    cnst3b = __msa_ldi_b(3);                                            \
-    filt2 = __msa_adds_s_b(filt, cnst3b);                               \
-    filt2 >>= 3;                                                        \
-                                                                        \
-    q0_m = __msa_subs_s_b(q0_m, filt1);                                 \
-    q0_in_out = __msa_xori_b((v16u8)q0_m, 0x80);                        \
-    p0_m = __msa_adds_s_b(p0_m, filt2);                                 \
-    p0_in_out = __msa_xori_b((v16u8)p0_m, 0x80);                        \
-                                                                        \
-    filt = __msa_srari_b(filt1, 1);                                     \
-    hev_in = __msa_xori_b((v16u8)hev_in, 0xff);                         \
-    filt = filt & (v16i8)hev_in;                                        \
-                                                                        \
-    q1_m = __msa_subs_s_b(q1_m, filt);                                  \
-    q1_in_out = __msa_xori_b((v16u8)q1_m, 0x80);                        \
-    p1_m = __msa_adds_s_b(p1_m, filt);                                  \
-    p1_in_out = __msa_xori_b((v16u8)p1_m, 0x80);                        \
-}
-
-#define VP8_SIMPLE_FILT(p1_in, p0_in, q0_in, q1_in, mask)          \
-{                                                                  \
-    v16i8 p1_m, p0_m, q0_m, q1_m, q0_sub_p0, q0_sub_p0_sign;       \
-    v16i8 filt, filt1, filt2, cnst4b, cnst3b, filt_sign;           \
-    v8i16 q0_sub_p0_r, q0_sub_p0_l, filt_l, filt_r, cnst3h;        \
-                                                                   \
-    p1_m = (v16i8)__msa_xori_b(p1_in, 0x80);                       \
-    p0_m = (v16i8)__msa_xori_b(p0_in, 0x80);                       \
-    q0_m = (v16i8)__msa_xori_b(q0_in, 0x80);                       \
-    q1_m = (v16i8)__msa_xori_b(q1_in, 0x80);                       \
-                                                                   \
-    filt = __msa_subs_s_b(p1_m, q1_m);                             \
-                                                                   \
-    q0_sub_p0 = q0_m - p0_m;                                       \
-    filt_sign = __msa_clti_s_b(filt, 0);                           \
-                                                                   \
-    cnst3h = __msa_ldi_h(3);                                       \
-    q0_sub_p0_sign = __msa_clti_s_b(q0_sub_p0, 0);                 \
-    q0_sub_p0_r = (v8i16)__msa_ilvr_b(q0_sub_p0_sign, q0_sub_p0);  \
-    q0_sub_p0_r *= cnst3h;                                         \
-    filt_r = (v8i16)__msa_ilvr_b(filt_sign, filt);                 \
-    filt_r += q0_sub_p0_r;                                         \
-    filt_r = __msa_sat_s_h(filt_r, 7);                             \
-                                                                   \
-    q0_sub_p0_l = (v8i16)__msa_ilvl_b(q0_sub_p0_sign, q0_sub_p0);  \
-    q0_sub_p0_l *= cnst3h;                                         \
-    filt_l = (v8i16)__msa_ilvl_b(filt_sign, filt);                 \
-    filt_l += q0_sub_p0_l;                                         \
-    filt_l = __msa_sat_s_h(filt_l, 7);                             \
-                                                                   \
-    filt = __msa_pckev_b((v16i8)filt_l, (v16i8)filt_r);            \
-    filt = filt & (v16i8)(mask);                                   \
-                                                                   \
-    cnst4b = __msa_ldi_b(4);                                       \
-    filt1 = __msa_adds_s_b(filt, cnst4b);                          \
-    filt1 >>= 3;                                                   \
-                                                                   \
-    cnst3b = __msa_ldi_b(3);                                       \
-    filt2 = __msa_adds_s_b(filt, cnst3b);                          \
-    filt2 >>= 3;                                                   \
-                                                                   \
-    q0_m = __msa_subs_s_b(q0_m, filt1);                            \
-    p0_m = __msa_adds_s_b(p0_m, filt2);                            \
-    q0_in = __msa_xori_b((v16u8)q0_m, 0x80);                       \
-    p0_in = __msa_xori_b((v16u8)p0_m, 0x80);                       \
-}
-
-#define VP8_MBFILTER(p2, p1, p0, q0, q1, q2, mask, hev)            \
-{                                                                  \
-    v16i8 p2_m, p1_m, p0_m, q2_m, q1_m, q0_m;                      \
-    v16i8 filt, q0_sub_p0, cnst4b, cnst3b;                         \
-    v16i8 u, filt1, filt2, filt_sign, q0_sub_p0_sign;              \
-    v8i16 q0_sub_p0_r, q0_sub_p0_l, filt_r, u_r, u_l, filt_l;      \
-    v8i16 cnst3h, cnst27h, cnst18h, cnst63h;                       \
-                                                                   \
-    cnst3h = __msa_ldi_h(3);                                       \
-                                                                   \
-    p2_m = (v16i8)__msa_xori_b(p2, 0x80);                          \
-    p1_m = (v16i8)__msa_xori_b(p1, 0x80);                          \
-    p0_m = (v16i8)__msa_xori_b(p0, 0x80);                          \
-    q0_m = (v16i8)__msa_xori_b(q0, 0x80);                          \
-    q1_m = (v16i8)__msa_xori_b(q1, 0x80);                          \
-    q2_m = (v16i8)__msa_xori_b(q2, 0x80);                          \
-                                                                   \
-    filt = __msa_subs_s_b(p1_m, q1_m);                             \
-    q0_sub_p0 = q0_m - p0_m;                                       \
-    q0_sub_p0_sign = __msa_clti_s_b(q0_sub_p0, 0);                 \
-    filt_sign = __msa_clti_s_b(filt, 0);                           \
-                                                                   \
-    q0_sub_p0_r = (v8i16)__msa_ilvr_b(q0_sub_p0_sign, q0_sub_p0);  \
-    q0_sub_p0_r *= cnst3h;                                         \
-    filt_r = (v8i16)__msa_ilvr_b(filt_sign, filt);                 \
-    filt_r = filt_r + q0_sub_p0_r;                                 \
-    filt_r = __msa_sat_s_h(filt_r, 7);                             \
-                                                                   \
-    q0_sub_p0_l = (v8i16)__msa_ilvl_b(q0_sub_p0_sign, q0_sub_p0);  \
-    q0_sub_p0_l *= cnst3h;                                         \
-    filt_l = (v8i16)__msa_ilvl_b(filt_sign, filt);                 \
-    filt_l = filt_l + q0_sub_p0_l;                                 \
-    filt_l = __msa_sat_s_h(filt_l, 7);                             \
-                                                                   \
-    filt = __msa_pckev_b((v16i8)filt_l, (v16i8)filt_r);            \
-    filt = filt & (v16i8)mask;                                     \
-    filt2 = filt & (v16i8)hev;                                     \
-                                                                   \
-    hev = __msa_xori_b(hev, 0xff);                                 \
-    filt = filt & (v16i8)hev;                                      \
-    cnst4b = __msa_ldi_b(4);                                       \
-    filt1 = __msa_adds_s_b(filt2, cnst4b);                         \
-    filt1 >>= 3;                                                   \
-    cnst3b = __msa_ldi_b(3);                                       \
-    filt2 = __msa_adds_s_b(filt2, cnst3b);                         \
-    filt2 >>= 3;                                                   \
-    q0_m = __msa_subs_s_b(q0_m, filt1);                            \
-    p0_m = __msa_adds_s_b(p0_m, filt2);                            \
-                                                                   \
-    filt_sign = __msa_clti_s_b(filt, 0);                           \
-    ILVRL_B2_SH(filt_sign, filt, filt_r, filt_l);                  \
-                                                                   \
-    cnst27h = __msa_ldi_h(27);                                     \
-    cnst63h = __msa_ldi_h(63);                                     \
-                                                                   \
-    u_r = filt_r * cnst27h;                                        \
-    u_r += cnst63h;                                                \
-    u_r >>= 7;                                                     \
-    u_r = __msa_sat_s_h(u_r, 7);                                   \
-    u_l = filt_l * cnst27h;                                        \
-    u_l += cnst63h;                                                \
-    u_l >>= 7;                                                     \
-    u_l = __msa_sat_s_h(u_l, 7);                                   \
-    u = __msa_pckev_b((v16i8)u_l, (v16i8)u_r);                     \
-    q0_m = __msa_subs_s_b(q0_m, u);                                \
-    q0 = __msa_xori_b((v16u8)q0_m, 0x80);                          \
-    p0_m = __msa_adds_s_b(p0_m, u);                                \
-    p0 = __msa_xori_b((v16u8)p0_m, 0x80);                          \
-    cnst18h = __msa_ldi_h(18);                                     \
-    u_r = filt_r * cnst18h;                                        \
-    u_r += cnst63h;                                                \
-    u_r >>= 7;                                                     \
-    u_r = __msa_sat_s_h(u_r, 7);                                   \
-                                                                   \
-    u_l = filt_l * cnst18h;                                        \
-    u_l += cnst63h;                                                \
-    u_l >>= 7;                                                     \
-    u_l = __msa_sat_s_h(u_l, 7);                                   \
-    u = __msa_pckev_b((v16i8)u_l, (v16i8)u_r);                     \
-    q1_m = __msa_subs_s_b(q1_m, u);                                \
-    q1 = __msa_xori_b((v16u8)q1_m, 0x80);                          \
-    p1_m = __msa_adds_s_b(p1_m, u);                                \
-    p1 = __msa_xori_b((v16u8)p1_m, 0x80);                          \
-    u_r = filt_r << 3;                                             \
-    u_r += filt_r + cnst63h;                                       \
-    u_r >>= 7;                                                     \
-    u_r = __msa_sat_s_h(u_r, 7);                                   \
-                                                                   \
-    u_l = filt_l << 3;                                             \
-    u_l += filt_l + cnst63h;                                       \
-    u_l >>= 7;                                                     \
-    u_l = __msa_sat_s_h(u_l, 7);                                   \
-    u = __msa_pckev_b((v16i8)u_l, (v16i8)u_r);                     \
-    q2_m = __msa_subs_s_b(q2_m, u);                                \
-    q2 = __msa_xori_b((v16u8)q2_m, 0x80);                          \
-    p2_m = __msa_adds_s_b(p2_m, u);                                \
-    p2 = __msa_xori_b((v16u8)p2_m, 0x80);                          \
-}
-
-#define LPF_MASK_HEV(p3_in, p2_in, p1_in, p0_in,                   \
-                     q0_in, q1_in, q2_in, q3_in,                   \
-                     limit_in, b_limit_in, thresh_in,              \
-                     hev_out, mask_out, flat_out)                  \
-{                                                                  \
-    v16u8 p3_asub_p2_m, p2_asub_p1_m, p1_asub_p0_m, q1_asub_q0_m;  \
-    v16u8 p1_asub_q1_m, p0_asub_q0_m, q3_asub_q2_m, q2_asub_q1_m;  \
-                                                                   \
-    p3_asub_p2_m = __msa_asub_u_b((p3_in), (p2_in));               \
-    p2_asub_p1_m = __msa_asub_u_b((p2_in), (p1_in));               \
-    p1_asub_p0_m = __msa_asub_u_b((p1_in), (p0_in));               \
-    q1_asub_q0_m = __msa_asub_u_b((q1_in), (q0_in));               \
-    q2_asub_q1_m = __msa_asub_u_b((q2_in), (q1_in));               \
-    q3_asub_q2_m = __msa_asub_u_b((q3_in), (q2_in));               \
-    p0_asub_q0_m = __msa_asub_u_b((p0_in), (q0_in));               \
-    p1_asub_q1_m = __msa_asub_u_b((p1_in), (q1_in));               \
-    flat_out = __msa_max_u_b(p1_asub_p0_m, q1_asub_q0_m);          \
-    hev_out = (thresh_in) < (v16u8)flat_out;                       \
-    p0_asub_q0_m = __msa_adds_u_b(p0_asub_q0_m, p0_asub_q0_m);     \
-    p1_asub_q1_m >>= 1;                                            \
-    p0_asub_q0_m = __msa_adds_u_b(p0_asub_q0_m, p1_asub_q1_m);     \
-    mask_out = (b_limit_in) < p0_asub_q0_m;                        \
-    mask_out = __msa_max_u_b(flat_out, mask_out);                  \
-    p3_asub_p2_m = __msa_max_u_b(p3_asub_p2_m, p2_asub_p1_m);      \
-    mask_out = __msa_max_u_b(p3_asub_p2_m, mask_out);              \
-    q2_asub_q1_m = __msa_max_u_b(q2_asub_q1_m, q3_asub_q2_m);      \
-    mask_out = __msa_max_u_b(q2_asub_q1_m, mask_out);              \
-    mask_out = (limit_in) < (v16u8)mask_out;                       \
-    mask_out = __msa_xori_b(mask_out, 0xff);                       \
-}
-
-#define VP8_ST6x1_UB(in0, in0_idx, in1, in1_idx, pdst, stride)  \
-{                                                               \
-    uint16_t tmp0_h;                                            \
-    uint32_t tmp0_w;                                            \
-                                                                \
-    tmp0_w = __msa_copy_u_w((v4i32)in0, in0_idx);               \
-    tmp0_h = __msa_copy_u_h((v8i16)in1, in1_idx);               \
-    SW(tmp0_w, pdst);                                           \
-    SH(tmp0_h, pdst + stride);                                  \
-}
-
-
-static void loop_filter_horizontal_4_dual_msa(uint8_t *src, int32_t pitch,
-                                              const uint8_t *b_limit0_ptr,
-                                              const uint8_t *limit0_ptr,
-                                              const uint8_t *thresh0_ptr,
-                                              const uint8_t *b_limit1_ptr,
-                                              const uint8_t *limit1_ptr,
-                                              const uint8_t *thresh1_ptr)
-{
-    v16u8 mask, hev, flat;
-    v16u8 thresh0, b_limit0, limit0, thresh1, b_limit1, limit1;
-    v16u8 p3, p2, p1, p0, q3, q2, q1, q0;
-
-    LD_UB8((src - 4 * pitch), pitch, p3, p2, p1, p0, q0, q1, q2, q3);
-    thresh0 = (v16u8)__msa_fill_b(*thresh0_ptr);
-    thresh1 = (v16u8)__msa_fill_b(*thresh1_ptr);
-    thresh0 = (v16u8)__msa_ilvr_d((v2i64)thresh1, (v2i64)thresh0);
-
-    b_limit0 = (v16u8)__msa_fill_b(*b_limit0_ptr);
-    b_limit1 = (v16u8)__msa_fill_b(*b_limit1_ptr);
-    b_limit0 = (v16u8)__msa_ilvr_d((v2i64)b_limit1, (v2i64)b_limit0);
-
-    limit0 = (v16u8)__msa_fill_b(*limit0_ptr);
-    limit1 = (v16u8)__msa_fill_b(*limit1_ptr);
-    limit0 = (v16u8)__msa_ilvr_d((v2i64)limit1, (v2i64)limit0);
-
-    LPF_MASK_HEV(p3, p2, p1, p0, q0, q1, q2, q3, limit0, b_limit0, thresh0,
-                 hev, mask, flat);
-    VP8_LPF_FILTER4_4W(p1, p0, q0, q1, mask, hev);
-
-    ST_UB4(p1, p0, q0, q1, (src - 2 * pitch), pitch);
-}
-
-static void loop_filter_vertical_4_dual_msa(uint8_t *src, int32_t pitch,
-                                            const uint8_t *b_limit0_ptr,
-                                            const uint8_t *limit0_ptr,
-                                            const uint8_t *thresh0_ptr,
-                                            const uint8_t *b_limit1_ptr,
-                                            const uint8_t *limit1_ptr,
-                                            const uint8_t *thresh1_ptr)
-{
-    v16u8 mask, hev, flat;
-    v16u8 thresh0, b_limit0, limit0, thresh1, b_limit1, limit1;
-    v16u8 p3, p2, p1, p0, q3, q2, q1, q0;
-    v16u8 row0, row1, row2, row3, row4, row5, row6, row7;
-    v16u8 row8, row9, row10, row11, row12, row13, row14, row15;
-    v8i16 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5;
-
-    LD_UB8(src - 4, pitch, row0, row1, row2, row3, row4, row5, row6, row7);
-    LD_UB8(src - 4 + (8 * pitch), pitch,
-           row8, row9, row10, row11, row12, row13, row14, row15);
-    TRANSPOSE16x8_UB_UB(row0, row1, row2, row3, row4, row5, row6, row7,
-                        row8, row9, row10, row11, row12, row13, row14, row15,
-                        p3, p2, p1, p0, q0, q1, q2, q3);
-
-    thresh0 = (v16u8)__msa_fill_b(*thresh0_ptr);
-    thresh1 = (v16u8)__msa_fill_b(*thresh1_ptr);
-    thresh0 = (v16u8)__msa_ilvr_d((v2i64)thresh1, (v2i64)thresh0);
-
-    b_limit0 = (v16u8)__msa_fill_b(*b_limit0_ptr);
-    b_limit1 = (v16u8)__msa_fill_b(*b_limit1_ptr);
-    b_limit0 = (v16u8)__msa_ilvr_d((v2i64)b_limit1, (v2i64)b_limit0);
-
-    limit0 = (v16u8)__msa_fill_b(*limit0_ptr);
-    limit1 = (v16u8)__msa_fill_b(*limit1_ptr);
-    limit0 = (v16u8)__msa_ilvr_d((v2i64)limit1, (v2i64)limit0);
-
-    LPF_MASK_HEV(p3, p2, p1, p0, q0, q1, q2, q3, limit0, b_limit0, thresh0,
-                 hev, mask, flat);
-    VP8_LPF_FILTER4_4W(p1, p0, q0, q1, mask, hev);
-    ILVR_B2_SH(p0, p1, q1, q0, tmp0, tmp1);
-    ILVRL_H2_SH(tmp1, tmp0, tmp2, tmp3);
-    ILVL_B2_SH(p0, p1, q1, q0, tmp0, tmp1);
-    ILVRL_H2_SH(tmp1, tmp0, tmp4, tmp5);
-
-    src -= 2;
-    ST4x8_UB(tmp2, tmp3, src, pitch);
-    src += (8 * pitch);
-    ST4x8_UB(tmp4, tmp5, src, pitch);
-}
-
-static void mbloop_filter_horizontal_edge_y_msa(uint8_t *src, int32_t pitch,
-                                                const uint8_t b_limit_in,
-                                                const uint8_t limit_in,
-                                                const uint8_t thresh_in)
-{
-    uint8_t *temp_src;
-    v16u8 p3, p2, p1, p0, q3, q2, q1, q0;
-    v16u8 mask, hev, flat, thresh, limit, b_limit;
-
-    b_limit = (v16u8)__msa_fill_b(b_limit_in);
-    limit = (v16u8)__msa_fill_b(limit_in);
-    thresh = (v16u8)__msa_fill_b(thresh_in);
-    temp_src = src - (pitch << 2);
-    LD_UB8(temp_src, pitch, p3, p2, p1, p0, q0, q1, q2, q3);
-    LPF_MASK_HEV(p3, p2, p1, p0, q0, q1, q2, q3, limit, b_limit, thresh,
-                 hev, mask, flat);
-    VP8_MBFILTER(p2, p1, p0, q0, q1, q2, mask, hev);
-    temp_src = src - 3 * pitch;
-    ST_UB4(p2, p1, p0, q0, temp_src, pitch);
-    temp_src += (4 * pitch);
-    ST_UB2(q1, q2, temp_src, pitch);
-}
-
-static void mbloop_filter_horizontal_edge_uv_msa(uint8_t *src_u, uint8_t *src_v,
-                                                 int32_t pitch,
-                                                 const uint8_t b_limit_in,
-                                                 const uint8_t limit_in,
-                                                 const uint8_t thresh_in)
-{
-    uint8_t *temp_src;
-    uint64_t p2_d, p1_d, p0_d, q0_d, q1_d, q2_d;
-    v16u8 p3, p2, p1, p0, q3, q2, q1, q0;
-    v16u8 mask, hev, flat, thresh, limit, b_limit;
-    v16u8 p3_u, p2_u, p1_u, p0_u, q3_u, q2_u, q1_u, q0_u;
-    v16u8 p3_v, p2_v, p1_v, p0_v, q3_v, q2_v, q1_v, q0_v;
-
-    b_limit = (v16u8)__msa_fill_b(b_limit_in);
-    limit = (v16u8)__msa_fill_b(limit_in);
-    thresh = (v16u8)__msa_fill_b(thresh_in);
-
-    temp_src = src_u - (pitch << 2);
-    LD_UB8(temp_src, pitch, p3_u, p2_u, p1_u, p0_u, q0_u, q1_u, q2_u, q3_u);
-    temp_src = src_v - (pitch << 2);
-    LD_UB8(temp_src, pitch, p3_v, p2_v, p1_v, p0_v, q0_v, q1_v, q2_v, q3_v);
-
-    ILVR_D4_UB(p3_v, p3_u, p2_v, p2_u, p1_v, p1_u, p0_v, p0_u, p3, p2, p1, p0);
-    ILVR_D4_UB(q0_v, q0_u, q1_v, q1_u, q2_v, q2_u, q3_v, q3_u, q0, q1, q2, q3);
-    LPF_MASK_HEV(p3, p2, p1, p0, q0, q1, q2, q3, limit, b_limit, thresh,
-                 hev, mask, flat);
-    VP8_MBFILTER(p2, p1, p0, q0, q1, q2, mask, hev);
-
-    p2_d = __msa_copy_u_d((v2i64)p2, 0);
-    p1_d = __msa_copy_u_d((v2i64)p1, 0);
-    p0_d = __msa_copy_u_d((v2i64)p0, 0);
-    q0_d = __msa_copy_u_d((v2i64)q0, 0);
-    q1_d = __msa_copy_u_d((v2i64)q1, 0);
-    q2_d = __msa_copy_u_d((v2i64)q2, 0);
-    src_u -= (pitch * 3);
-    SD4(p2_d, p1_d, p0_d, q0_d, src_u, pitch);
-    src_u += 4 * pitch;
-    SD(q1_d, src_u);
-    src_u += pitch;
-    SD(q2_d, src_u);
-
-    p2_d = __msa_copy_u_d((v2i64)p2, 1);
-    p1_d = __msa_copy_u_d((v2i64)p1, 1);
-    p0_d = __msa_copy_u_d((v2i64)p0, 1);
-    q0_d = __msa_copy_u_d((v2i64)q0, 1);
-    q1_d = __msa_copy_u_d((v2i64)q1, 1);
-    q2_d = __msa_copy_u_d((v2i64)q2, 1);
-    src_v -= (pitch * 3);
-    SD4(p2_d, p1_d, p0_d, q0_d, src_v, pitch);
-    src_v += 4 * pitch;
-    SD(q1_d, src_v);
-    src_v += pitch;
-    SD(q2_d, src_v);
-}
-
-static void mbloop_filter_vertical_edge_y_msa(uint8_t *src, int32_t pitch,
-                                              const uint8_t b_limit_in,
-                                              const uint8_t limit_in,
-                                              const uint8_t thresh_in)
-{
-    uint8_t *temp_src;
-    v16u8 p3, p2, p1, p0, q3, q2, q1, q0;
-    v16u8 mask, hev, flat, thresh, limit, b_limit;
-    v16u8 row0, row1, row2, row3, row4, row5, row6, row7, row8;
-    v16u8 row9, row10, row11, row12, row13, row14, row15;
-    v8i16 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
-
-    b_limit = (v16u8)__msa_fill_b(b_limit_in);
-    limit = (v16u8)__msa_fill_b(limit_in);
-    thresh = (v16u8)__msa_fill_b(thresh_in);
-    temp_src = src - 4;
-    LD_UB8(temp_src, pitch, row0, row1, row2, row3, row4, row5, row6, row7);
-    temp_src += (8 * pitch);
-    LD_UB8(temp_src, pitch,
-           row8, row9, row10, row11, row12, row13, row14, row15);
-    TRANSPOSE16x8_UB_UB(row0, row1, row2, row3, row4, row5, row6, row7,
-                        row8, row9, row10, row11, row12, row13, row14, row15,
-                        p3, p2, p1, p0, q0, q1, q2, q3);
-
-    LPF_MASK_HEV(p3, p2, p1, p0, q0, q1, q2, q3, limit, b_limit, thresh,
-                 hev, mask, flat);
-    VP8_MBFILTER(p2, p1, p0, q0, q1, q2, mask, hev);
-    ILVR_B2_SH(p1, p2, q0, p0, tmp0, tmp1);
-    ILVRL_H2_SH(tmp1, tmp0, tmp3, tmp4);
-    ILVL_B2_SH(p1, p2, q0, p0, tmp0, tmp1);
-    ILVRL_H2_SH(tmp1, tmp0, tmp6, tmp7);
-    ILVRL_B2_SH(q2, q1, tmp2, tmp5);
-
-    temp_src = src - 3;
-    VP8_ST6x1_UB(tmp3, 0, tmp2, 0, temp_src, 4);
-    temp_src += pitch;
-    VP8_ST6x1_UB(tmp3, 1, tmp2, 1, temp_src, 4);
-    temp_src += pitch;
-    VP8_ST6x1_UB(tmp3, 2, tmp2, 2, temp_src, 4);
-    temp_src += pitch;
-    VP8_ST6x1_UB(tmp3, 3, tmp2, 3, temp_src, 4);
-    temp_src += pitch;
-    VP8_ST6x1_UB(tmp4, 0, tmp2, 4, temp_src, 4);
-    temp_src += pitch;
-    VP8_ST6x1_UB(tmp4, 1, tmp2, 5, temp_src, 4);
-    temp_src += pitch;
-    VP8_ST6x1_UB(tmp4, 2, tmp2, 6, temp_src, 4);
-    temp_src += pitch;
-    VP8_ST6x1_UB(tmp4, 3, tmp2, 7, temp_src, 4);
-    temp_src += pitch;
-    VP8_ST6x1_UB(tmp6, 0, tmp5, 0, temp_src, 4);
-    temp_src += pitch;
-    VP8_ST6x1_UB(tmp6, 1, tmp5, 1, temp_src, 4);
-    temp_src += pitch;
-    VP8_ST6x1_UB(tmp6, 2, tmp5, 2, temp_src, 4);
-    temp_src += pitch;
-    VP8_ST6x1_UB(tmp6, 3, tmp5, 3, temp_src, 4);
-    temp_src += pitch;
-    VP8_ST6x1_UB(tmp7, 0, tmp5, 4, temp_src, 4);
-    temp_src += pitch;
-    VP8_ST6x1_UB(tmp7, 1, tmp5, 5, temp_src, 4);
-    temp_src += pitch;
-    VP8_ST6x1_UB(tmp7, 2, tmp5, 6, temp_src, 4);
-    temp_src += pitch;
-    VP8_ST6x1_UB(tmp7, 3, tmp5, 7, temp_src, 4);
-}
-
-static void mbloop_filter_vertical_edge_uv_msa(uint8_t *src_u, uint8_t *src_v,
-                                               int32_t pitch,
-                                               const uint8_t b_limit_in,
-                                               const uint8_t limit_in,
-                                               const uint8_t thresh_in)
-{
-    v16u8 p3, p2, p1, p0, q3, q2, q1, q0;
-    v16u8 mask, hev, flat, thresh, limit, b_limit;
-    v16u8 row0, row1, row2, row3, row4, row5, row6, row7, row8;
-    v16u8 row9, row10, row11, row12, row13, row14, row15;
-    v8i16 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
-
-    b_limit = (v16u8)__msa_fill_b(b_limit_in);
-    limit = (v16u8)__msa_fill_b(limit_in);
-    thresh = (v16u8)__msa_fill_b(thresh_in);
-
-    LD_UB8(src_u - 4, pitch, row0, row1, row2, row3, row4, row5, row6, row7);
-    LD_UB8(src_v - 4, pitch,
-           row8, row9, row10, row11, row12, row13, row14, row15);
-    TRANSPOSE16x8_UB_UB(row0, row1, row2, row3, row4, row5, row6, row7,
-                        row8, row9, row10, row11, row12, row13, row14, row15,
-                        p3, p2, p1, p0, q0, q1, q2, q3);
-
-    LPF_MASK_HEV(p3, p2, p1, p0, q0, q1, q2, q3, limit, b_limit, thresh,
-                 hev, mask, flat);
-    VP8_MBFILTER(p2, p1, p0, q0, q1, q2, mask, hev);
-
-    ILVR_B2_SH(p1, p2, q0, p0, tmp0, tmp1);
-    ILVRL_H2_SH(tmp1, tmp0, tmp3, tmp4);
-    ILVL_B2_SH(p1, p2, q0, p0, tmp0, tmp1);
-    ILVRL_H2_SH(tmp1, tmp0, tmp6, tmp7);
-    ILVRL_B2_SH(q2, q1, tmp2, tmp5);
-
-    src_u -= 3;
-    VP8_ST6x1_UB(tmp3, 0, tmp2, 0, src_u, 4);
-    src_u += pitch;
-    VP8_ST6x1_UB(tmp3, 1, tmp2, 1, src_u, 4);
-    src_u += pitch;
-    VP8_ST6x1_UB(tmp3, 2, tmp2, 2, src_u, 4);
-    src_u += pitch;
-    VP8_ST6x1_UB(tmp3, 3, tmp2, 3, src_u, 4);
-    src_u += pitch;
-    VP8_ST6x1_UB(tmp4, 0, tmp2, 4, src_u, 4);
-    src_u += pitch;
-    VP8_ST6x1_UB(tmp4, 1, tmp2, 5, src_u, 4);
-    src_u += pitch;
-    VP8_ST6x1_UB(tmp4, 2, tmp2, 6, src_u, 4);
-    src_u += pitch;
-    VP8_ST6x1_UB(tmp4, 3, tmp2, 7, src_u, 4);
-
-    src_v -= 3;
-    VP8_ST6x1_UB(tmp6, 0, tmp5, 0, src_v, 4);
-    src_v += pitch;
-    VP8_ST6x1_UB(tmp6, 1, tmp5, 1, src_v, 4);
-    src_v += pitch;
-    VP8_ST6x1_UB(tmp6, 2, tmp5, 2, src_v, 4);
-    src_v += pitch;
-    VP8_ST6x1_UB(tmp6, 3, tmp5, 3, src_v, 4);
-    src_v += pitch;
-    VP8_ST6x1_UB(tmp7, 0, tmp5, 4, src_v, 4);
-    src_v += pitch;
-    VP8_ST6x1_UB(tmp7, 1, tmp5, 5, src_v, 4);
-    src_v += pitch;
-    VP8_ST6x1_UB(tmp7, 2, tmp5, 6, src_v, 4);
-    src_v += pitch;
-    VP8_ST6x1_UB(tmp7, 3, tmp5, 7, src_v, 4);
-}
-
-void vp8_loop_filter_simple_horizontal_edge_msa(uint8_t *src, int32_t pitch,
-                                                const uint8_t *b_limit_ptr)
-{
-    v16u8 p1, p0, q1, q0;
-    v16u8 mask, b_limit;
-
-    b_limit = (v16u8)__msa_fill_b(*b_limit_ptr);
-    LD_UB4(src - (pitch << 1), pitch, p1, p0, q0, q1);
-    VP8_SIMPLE_MASK(p1, p0, q0, q1, b_limit, mask);
-    VP8_SIMPLE_FILT(p1, p0, q0, q1, mask);
-    ST_UB2(p0, q0, (src - pitch), pitch);
-}
-
-void vp8_loop_filter_simple_vertical_edge_msa(uint8_t *src, int32_t pitch,
-                                              const uint8_t *b_limit_ptr)
-{
-    uint8_t *temp_src;
-    v16u8 p1, p0, q1, q0;
-    v16u8 mask, b_limit;
-    v16u8 row0, row1, row2, row3, row4, row5, row6, row7, row8;
-    v16u8 row9, row10, row11, row12, row13, row14, row15;
-    v8i16 tmp0, tmp1;
-
-    b_limit = (v16u8)__msa_fill_b(*b_limit_ptr);
-    temp_src = src - 2;
-    LD_UB8(temp_src, pitch, row0, row1, row2, row3, row4, row5, row6, row7);
-    temp_src += (8 * pitch);
-    LD_UB8(temp_src, pitch,
-           row8, row9, row10, row11, row12, row13, row14, row15);
-    TRANSPOSE16x4_UB_UB(row0, row1, row2, row3, row4, row5, row6, row7,
-                        row8, row9, row10, row11, row12, row13, row14, row15,
-                        p1, p0, q0, q1);
-    VP8_SIMPLE_MASK(p1, p0, q0, q1, b_limit, mask);
-    VP8_SIMPLE_FILT(p1, p0, q0, q1, mask);
-    ILVRL_B2_SH(q0, p0, tmp1, tmp0);
-
-    src -= 1;
-    ST2x4_UB(tmp1, 0, src, pitch);
-    src += 4 * pitch;
-    ST2x4_UB(tmp1, 4, src, pitch);
-    src += 4 * pitch;
-    ST2x4_UB(tmp0, 0, src, pitch);
-    src += 4 * pitch;
-    ST2x4_UB(tmp0, 4, src, pitch);
-    src += 4 * pitch;
-}
-
-static void loop_filter_horizontal_edge_uv_msa(uint8_t *src_u, uint8_t *src_v,
-                                               int32_t pitch,
-                                               const uint8_t b_limit_in,
-                                               const uint8_t limit_in,
-                                               const uint8_t thresh_in)
-{
-    uint64_t p1_d, p0_d, q0_d, q1_d;
-    v16u8 p3, p2, p1, p0, q3, q2, q1, q0;
-    v16u8 mask, hev, flat, thresh, limit, b_limit;
-    v16u8 p3_u, p2_u, p1_u, p0_u, q3_u, q2_u, q1_u, q0_u;
-    v16u8 p3_v, p2_v, p1_v, p0_v, q3_v, q2_v, q1_v, q0_v;
-
-    thresh = (v16u8)__msa_fill_b(thresh_in);
-    limit = (v16u8)__msa_fill_b(limit_in);
-    b_limit = (v16u8)__msa_fill_b(b_limit_in);
-
-    src_u = src_u - (pitch << 2);
-    LD_UB8(src_u, pitch, p3_u, p2_u, p1_u, p0_u, q0_u, q1_u, q2_u, q3_u);
-    src_u += (5 * pitch);
-    src_v = src_v - (pitch << 2);
-    LD_UB8(src_v, pitch, p3_v, p2_v, p1_v, p0_v, q0_v, q1_v, q2_v, q3_v);
-    src_v += (5 * pitch);
-
-    /* right 8 element of p3 are u pixel and
-       left 8 element of p3 are v pixel */
-    ILVR_D4_UB(p3_v, p3_u, p2_v, p2_u, p1_v, p1_u, p0_v, p0_u, p3, p2, p1, p0);
-    ILVR_D4_UB(q0_v, q0_u, q1_v, q1_u, q2_v, q2_u, q3_v, q3_u, q0, q1, q2, q3);
-    LPF_MASK_HEV(p3, p2, p1, p0, q0, q1, q2, q3, limit, b_limit, thresh,
-                 hev, mask, flat);
-    VP8_LPF_FILTER4_4W(p1, p0, q0, q1, mask, hev);
-
-    p1_d = __msa_copy_u_d((v2i64)p1, 0);
-    p0_d = __msa_copy_u_d((v2i64)p0, 0);
-    q0_d = __msa_copy_u_d((v2i64)q0, 0);
-    q1_d = __msa_copy_u_d((v2i64)q1, 0);
-    SD4(q1_d, q0_d, p0_d, p1_d, src_u, (- pitch));
-
-    p1_d = __msa_copy_u_d((v2i64)p1, 1);
-    p0_d = __msa_copy_u_d((v2i64)p0, 1);
-    q0_d = __msa_copy_u_d((v2i64)q0, 1);
-    q1_d = __msa_copy_u_d((v2i64)q1, 1);
-    SD4(q1_d, q0_d, p0_d, p1_d, src_v, (- pitch));
-}
-
-static void loop_filter_vertical_edge_uv_msa(uint8_t *src_u, uint8_t *src_v,
-                                             int32_t pitch,
-                                             const uint8_t b_limit_in,
-                                             const uint8_t limit_in,
-                                             const uint8_t thresh_in)
-{
-    uint8_t *temp_src_u, *temp_src_v;
-    v16u8 p3, p2, p1, p0, q3, q2, q1, q0;
-    v16u8 mask, hev, flat, thresh, limit, b_limit;
-    v16u8 row0, row1, row2, row3, row4, row5, row6, row7, row8;
-    v16u8 row9, row10, row11, row12, row13, row14, row15;
-    v4i32 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5;
-
-    thresh = (v16u8)__msa_fill_b(thresh_in);
-    limit = (v16u8)__msa_fill_b(limit_in);
-    b_limit = (v16u8)__msa_fill_b(b_limit_in);
-
-    LD_UB8(src_u - 4, pitch, row0, row1, row2, row3, row4, row5, row6, row7);
-    LD_UB8(src_v - 4, pitch,
-           row8, row9, row10, row11, row12, row13, row14, row15);
-    TRANSPOSE16x8_UB_UB(row0, row1, row2, row3, row4, row5, row6, row7,
-                        row8, row9, row10, row11, row12, row13, row14, row15,
-                        p3, p2, p1, p0, q0, q1, q2, q3);
-
-    LPF_MASK_HEV(p3, p2, p1, p0, q0, q1, q2, q3, limit, b_limit, thresh,
-                 hev, mask, flat);
-    VP8_LPF_FILTER4_4W(p1, p0, q0, q1, mask, hev);
-    ILVR_B2_SW(p0, p1, q1, q0, tmp0, tmp1);
-    ILVRL_H2_SW(tmp1, tmp0, tmp2, tmp3);
-    tmp0 = (v4i32)__msa_ilvl_b((v16i8)p0, (v16i8)p1);
-    tmp1 = (v4i32)__msa_ilvl_b((v16i8)q1, (v16i8)q0);
-    ILVRL_H2_SW(tmp1, tmp0, tmp4, tmp5);
-
-    temp_src_u = src_u - 2;
-    ST4x4_UB(tmp2, tmp2, 0, 1, 2, 3, temp_src_u, pitch);
-    temp_src_u += 4 * pitch;
-    ST4x4_UB(tmp3, tmp3, 0, 1, 2, 3, temp_src_u, pitch);
-
-    temp_src_v = src_v - 2;
-    ST4x4_UB(tmp4, tmp4, 0, 1, 2, 3, temp_src_v, pitch);
-    temp_src_v += 4 * pitch;
-    ST4x4_UB(tmp5, tmp5, 0, 1, 2, 3, temp_src_v, pitch);
-}
-
-void vp8_loop_filter_mbh_msa(uint8_t *src_y, uint8_t *src_u,
-                             uint8_t *src_v, int32_t pitch_y,
-                             int32_t pitch_u_v,
-                             loop_filter_info *lpf_info_ptr)
-{
-    mbloop_filter_horizontal_edge_y_msa(src_y, pitch_y,
-                                        *lpf_info_ptr->mblim,
-                                        *lpf_info_ptr->lim,
-                                        *lpf_info_ptr->hev_thr);
-    if (src_u)
-    {
-        mbloop_filter_horizontal_edge_uv_msa(src_u, src_v, pitch_u_v,
-                                             *lpf_info_ptr->mblim,
-                                             *lpf_info_ptr->lim,
-                                             *lpf_info_ptr->hev_thr);
-    }
-}
-
-void vp8_loop_filter_mbv_msa(uint8_t *src_y, uint8_t *src_u,
-                             uint8_t *src_v, int32_t pitch_y,
-                             int32_t pitch_u_v,
-                             loop_filter_info *lpf_info_ptr)
-{
-    mbloop_filter_vertical_edge_y_msa(src_y, pitch_y,
-                                      *lpf_info_ptr->mblim,
-                                      *lpf_info_ptr->lim,
-                                      *lpf_info_ptr->hev_thr);
-    if (src_u)
-    {
-        mbloop_filter_vertical_edge_uv_msa(src_u, src_v, pitch_u_v,
-                                           *lpf_info_ptr->mblim,
-                                           *lpf_info_ptr->lim,
-                                           *lpf_info_ptr->hev_thr);
-    }
-}
-
-void vp8_loop_filter_bh_msa(uint8_t *src_y, uint8_t *src_u,
-                            uint8_t *src_v, int32_t pitch_y,
-                            int32_t pitch_u_v,
-                            loop_filter_info *lpf_info_ptr)
-{
-    loop_filter_horizontal_4_dual_msa(src_y + 4 * pitch_y, pitch_y,
-                                      lpf_info_ptr->blim,
-                                      lpf_info_ptr->lim,
-                                      lpf_info_ptr->hev_thr,
-                                      lpf_info_ptr->blim,
-                                      lpf_info_ptr->lim,
-                                      lpf_info_ptr->hev_thr);
-    loop_filter_horizontal_4_dual_msa(src_y + 8 * pitch_y, pitch_y,
-                                      lpf_info_ptr->blim,
-                                      lpf_info_ptr->lim,
-                                      lpf_info_ptr->hev_thr,
-                                      lpf_info_ptr->blim,
-                                      lpf_info_ptr->lim,
-                                      lpf_info_ptr->hev_thr);
-    loop_filter_horizontal_4_dual_msa(src_y + 12 * pitch_y, pitch_y,
-                                      lpf_info_ptr->blim,
-                                      lpf_info_ptr->lim,
-                                      lpf_info_ptr->hev_thr,
-                                      lpf_info_ptr->blim,
-                                      lpf_info_ptr->lim,
-                                      lpf_info_ptr->hev_thr);
-    if (src_u)
-    {
-        loop_filter_horizontal_edge_uv_msa(src_u + (4 * pitch_u_v),
-                                           src_v + (4 * pitch_u_v),
-                                           pitch_u_v,
-                                           *lpf_info_ptr->blim,
-                                           *lpf_info_ptr->lim,
-                                           *lpf_info_ptr->hev_thr);
-    }
-}
-
-void vp8_loop_filter_bv_msa(uint8_t *src_y, uint8_t *src_u,
-                            uint8_t *src_v, int32_t pitch_y,
-                            int32_t pitch_u_v,
-                            loop_filter_info *lpf_info_ptr)
-{
-    loop_filter_vertical_4_dual_msa(src_y + 4, pitch_y, lpf_info_ptr->blim,
-                                    lpf_info_ptr->lim,
-                                    lpf_info_ptr->hev_thr,
-                                    lpf_info_ptr->blim,
-                                    lpf_info_ptr->lim,
-                                    lpf_info_ptr->hev_thr);
-    loop_filter_vertical_4_dual_msa(src_y + 8, pitch_y,
-                                    lpf_info_ptr->blim,
-                                    lpf_info_ptr->lim,
-                                    lpf_info_ptr->hev_thr,
-                                    lpf_info_ptr->blim,
-                                    lpf_info_ptr->lim,
-                                    lpf_info_ptr->hev_thr);
-    loop_filter_vertical_4_dual_msa(src_y + 12, pitch_y,
-                                    lpf_info_ptr->blim,
-                                    lpf_info_ptr->lim,
-                                    lpf_info_ptr->hev_thr,
-                                    lpf_info_ptr->blim,
-                                    lpf_info_ptr->lim,
-                                    lpf_info_ptr->hev_thr);
-    if (src_u)
-    {
-        loop_filter_vertical_edge_uv_msa(src_u + 4, src_v + 4, pitch_u_v,
-                                         *lpf_info_ptr->blim,
-                                         *lpf_info_ptr->lim,
-                                         *lpf_info_ptr->hev_thr);
-    }
-}
-
-void vp8_loop_filter_bhs_msa(uint8_t *src_y, int32_t pitch_y,
-                             const uint8_t *b_limit_ptr)
-{
-    vp8_loop_filter_simple_horizontal_edge_msa(src_y + (4 * pitch_y),
-                                               pitch_y, b_limit_ptr);
-    vp8_loop_filter_simple_horizontal_edge_msa(src_y + (8 * pitch_y),
-                                               pitch_y, b_limit_ptr);
-    vp8_loop_filter_simple_horizontal_edge_msa(src_y + (12 * pitch_y),
-                                               pitch_y, b_limit_ptr);
-}
-
-void vp8_loop_filter_bvs_msa(uint8_t *src_y, int32_t pitch_y,
-                             const uint8_t *b_limit_ptr)
-{
-    vp8_loop_filter_simple_vertical_edge_msa(src_y + 4, pitch_y, b_limit_ptr);
-    vp8_loop_filter_simple_vertical_edge_msa(src_y + 8, pitch_y, b_limit_ptr);
-    vp8_loop_filter_simple_vertical_edge_msa(src_y + 12, pitch_y, b_limit_ptr);
-}
diff --git a/vp8/common/mips/msa/mfqe_msa.c b/vp8/common/mips/msa/mfqe_msa.c
deleted file mode 100644 (file)
index 3e7629f..0000000
+++ /dev/null
@@ -1,146 +0,0 @@
-/*
- *  Copyright (c) 2015 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.
- */
-
-#include "./vp8_rtcd.h"
-#include "vp8/common/postproc.h"
-#include "vp8/common/mips/msa/vp8_macros_msa.h"
-
-static void filter_by_weight8x8_msa(uint8_t *src_ptr, int32_t src_stride,
-                                    uint8_t *dst_ptr, int32_t dst_stride,
-                                    int32_t src_weight)
-{
-    int32_t dst_weight = (1 << MFQE_PRECISION) - src_weight;
-    int32_t row;
-    uint64_t src0_d, src1_d, dst0_d, dst1_d;
-    v16i8 src0 = { 0 };
-    v16i8 src1 = { 0 };
-    v16i8 dst0 = { 0 };
-    v16i8 dst1 = { 0 };
-    v8i16 src_wt, dst_wt, res_h_r, res_h_l, src_r, src_l, dst_r, dst_l;
-
-    src_wt = __msa_fill_h(src_weight);
-    dst_wt = __msa_fill_h(dst_weight);
-
-    for (row = 2; row--;)
-    {
-        LD2(src_ptr, src_stride, src0_d, src1_d);
-        src_ptr += (2 * src_stride);
-        LD2(dst_ptr, dst_stride, dst0_d, dst1_d);
-        INSERT_D2_SB(src0_d, src1_d, src0);
-        INSERT_D2_SB(dst0_d, dst1_d, dst0);
-
-        LD2(src_ptr, src_stride, src0_d, src1_d);
-        src_ptr += (2 * src_stride);
-        LD2((dst_ptr + 2 * dst_stride), dst_stride, dst0_d, dst1_d);
-        INSERT_D2_SB(src0_d, src1_d, src1);
-        INSERT_D2_SB(dst0_d, dst1_d, dst1);
-
-        UNPCK_UB_SH(src0, src_r, src_l);
-        UNPCK_UB_SH(dst0, dst_r, dst_l);
-        res_h_r = (src_r * src_wt);
-        res_h_r += (dst_r * dst_wt);
-        res_h_l = (src_l * src_wt);
-        res_h_l += (dst_l * dst_wt);
-        SRARI_H2_SH(res_h_r, res_h_l, MFQE_PRECISION);
-        dst0 = (v16i8)__msa_pckev_b((v16i8)res_h_l, (v16i8)res_h_r);
-        ST8x2_UB(dst0, dst_ptr, dst_stride);
-        dst_ptr += (2 * dst_stride);
-
-        UNPCK_UB_SH(src1, src_r, src_l);
-        UNPCK_UB_SH(dst1, dst_r, dst_l);
-        res_h_r = (src_r * src_wt);
-        res_h_r += (dst_r * dst_wt);
-        res_h_l = (src_l * src_wt);
-        res_h_l += (dst_l * dst_wt);
-        SRARI_H2_SH(res_h_r, res_h_l, MFQE_PRECISION);
-        dst1 = (v16i8)__msa_pckev_b((v16i8)res_h_l, (v16i8)res_h_r);
-        ST8x2_UB(dst1, dst_ptr, dst_stride);
-        dst_ptr += (2 * dst_stride);
-    }
-}
-
-static void filter_by_weight16x16_msa(uint8_t *src_ptr, int32_t src_stride,
-                                      uint8_t *dst_ptr, int32_t dst_stride,
-                                      int32_t src_weight)
-{
-    int32_t dst_weight = (1 << MFQE_PRECISION) - src_weight;
-    int32_t row;
-    v16i8 src0, src1, src2, src3;
-    v16i8 dst0, dst1, dst2, dst3;
-    v8i16 src_wt, dst_wt;
-    v8i16 res_h_r, res_h_l;
-    v8i16 src_r, src_l, dst_r, dst_l;
-
-    src_wt = __msa_fill_h(src_weight);
-    dst_wt = __msa_fill_h(dst_weight);
-
-    for (row = 4; row--;)
-    {
-        LD_SB4(src_ptr, src_stride, src0, src1, src2, src3);
-        src_ptr += (4 * src_stride);
-        LD_SB4(dst_ptr, dst_stride, dst0, dst1, dst2, dst3);
-
-        UNPCK_UB_SH(src0, src_r, src_l);
-        UNPCK_UB_SH(dst0, dst_r, dst_l);
-        res_h_r = (src_r * src_wt);
-        res_h_r += (dst_r * dst_wt);
-        res_h_l = (src_l * src_wt);
-        res_h_l += (dst_l * dst_wt);
-        SRARI_H2_SH(res_h_r, res_h_l, MFQE_PRECISION);
-        PCKEV_ST_SB(res_h_r, res_h_l, dst_ptr);
-        dst_ptr += dst_stride;
-
-        UNPCK_UB_SH(src1, src_r, src_l);
-        UNPCK_UB_SH(dst1, dst_r, dst_l);
-        res_h_r = (src_r * src_wt);
-        res_h_r += (dst_r * dst_wt);
-        res_h_l = (src_l * src_wt);
-        res_h_l += (dst_l * dst_wt);
-        SRARI_H2_SH(res_h_r, res_h_l, MFQE_PRECISION);
-        PCKEV_ST_SB(res_h_r, res_h_l, dst_ptr);
-        dst_ptr += dst_stride;
-
-        UNPCK_UB_SH(src2, src_r, src_l);
-        UNPCK_UB_SH(dst2, dst_r, dst_l);
-        res_h_r = (src_r * src_wt);
-        res_h_r += (dst_r * dst_wt);
-        res_h_l = (src_l * src_wt);
-        res_h_l += (dst_l * dst_wt);
-        SRARI_H2_SH(res_h_r, res_h_l, MFQE_PRECISION);
-        PCKEV_ST_SB(res_h_r, res_h_l, dst_ptr);
-        dst_ptr += dst_stride;
-
-        UNPCK_UB_SH(src3, src_r, src_l);
-        UNPCK_UB_SH(dst3, dst_r, dst_l);
-        res_h_r = (src_r * src_wt);
-        res_h_r += (dst_r * dst_wt);
-        res_h_l = (src_l * src_wt);
-        res_h_l += (dst_l * dst_wt);
-        SRARI_H2_SH(res_h_r, res_h_l, MFQE_PRECISION);
-        PCKEV_ST_SB(res_h_r, res_h_l, dst_ptr);
-        dst_ptr += dst_stride;
-    }
-}
-
-void vp8_filter_by_weight16x16_msa(uint8_t *src_ptr, int32_t src_stride,
-                                   uint8_t *dst_ptr, int32_t dst_stride,
-                                   int32_t src_weight)
-{
-    filter_by_weight16x16_msa(src_ptr, src_stride, dst_ptr, dst_stride,
-                              src_weight);
-}
-
-void vp8_filter_by_weight8x8_msa(uint8_t *src_ptr, int32_t src_stride,
-                                 uint8_t *dst_ptr, int32_t dst_stride,
-                                 int32_t src_weight)
-{
-    filter_by_weight8x8_msa(src_ptr, src_stride, dst_ptr, dst_stride,
-                            src_weight);
-}
diff --git a/vp8/common/mips/msa/sixtap_filter_msa.c b/vp8/common/mips/msa/sixtap_filter_msa.c
deleted file mode 100644 (file)
index fb60fc1..0000000
+++ /dev/null
@@ -1,1850 +0,0 @@
-/*
- *  Copyright (c) 2015 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.
- */
-
-#include "./vp8_rtcd.h"
-#include "vpx_ports/mem.h"
-#include "vp8/common/filter.h"
-#include "vp8/common/mips/msa/vp8_macros_msa.h"
-
-DECLARE_ALIGNED(16, static const int8_t, vp8_subpel_filters_msa[7][8]) =
-{
-    { 0, -6, 123, 12, -1, 0, 0, 0 },
-    { 2, -11, 108, 36, -8, 1, 0, 0 },  /* New 1/4 pel 6 tap filter */
-    { 0, -9, 93, 50, -6, 0, 0, 0 },
-    { 3, -16, 77, 77, -16, 3, 0, 0 },  /* New 1/2 pel 6 tap filter */
-    { 0, -6, 50, 93, -9, 0, 0, 0 },
-    { 1, -8, 36, 108, -11, 2, 0, 0 },  /* New 1/4 pel 6 tap filter */
-    { 0, -1, 12, 123, -6, 0, 0, 0 },
-};
-
-static const uint8_t vp8_mc_filt_mask_arr[16 * 3] =
-{
-    /* 8 width cases */
-    0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8,
-    /* 4 width cases */
-    0, 1, 1, 2, 2, 3, 3, 4, 16, 17, 17, 18, 18, 19, 19, 20,
-    /* 4 width cases */
-    8, 9, 9, 10, 10, 11, 11, 12, 24, 25, 25, 26, 26, 27, 27, 28
-};
-
-#define HORIZ_6TAP_FILT(src0, src1, mask0, mask1, mask2,                 \
-                        filt_h0, filt_h1, filt_h2)                       \
-({                                                                       \
-    v16i8 vec0_m, vec1_m, vec2_m;                                        \
-    v8i16 hz_out_m;                                                      \
-                                                                         \
-    VSHF_B3_SB(src0, src1, src0, src1, src0, src1, mask0, mask1, mask2,  \
-               vec0_m, vec1_m, vec2_m);                                  \
-    hz_out_m = DPADD_SH3_SH(vec0_m, vec1_m, vec2_m,                      \
-                            filt_h0, filt_h1, filt_h2);                  \
-                                                                         \
-    hz_out_m = __msa_srari_h(hz_out_m, VP8_FILTER_SHIFT);                \
-    hz_out_m = __msa_sat_s_h(hz_out_m, 7);                               \
-                                                                         \
-    hz_out_m;                                                            \
-})
-
-#define HORIZ_6TAP_4WID_4VECS_FILT(src0, src1, src2, src3,             \
-                                   mask0, mask1, mask2,                \
-                                   filt0, filt1, filt2,                \
-                                   out0, out1)                         \
-{                                                                      \
-    v16i8 vec0_m, vec1_m, vec2_m, vec3_m, vec4_m, vec5_m;              \
-                                                                       \
-    VSHF_B2_SB(src0, src1, src2, src3, mask0, mask0, vec0_m, vec1_m);  \
-    DOTP_SB2_SH(vec0_m, vec1_m, filt0, filt0, out0, out1);             \
-    VSHF_B2_SB(src0, src1, src2, src3, mask1, mask1, vec2_m, vec3_m);  \
-    DPADD_SB2_SH(vec2_m, vec3_m, filt1, filt1, out0, out1);            \
-    VSHF_B2_SB(src0, src1, src2, src3, mask2, mask2, vec4_m, vec5_m);  \
-    DPADD_SB2_SH(vec4_m, vec5_m, filt2, filt2, out0, out1);            \
-}
-
-#define HORIZ_6TAP_8WID_4VECS_FILT(src0, src1, src2, src3,                    \
-                                   mask0, mask1, mask2,                       \
-                                   filt0, filt1, filt2,                       \
-                                   out0, out1, out2, out3)                    \
-{                                                                             \
-    v16i8 vec0_m, vec1_m, vec2_m, vec3_m, vec4_m, vec5_m, vec6_m, vec7_m;     \
-                                                                              \
-    VSHF_B2_SB(src0, src0, src1, src1, mask0, mask0, vec0_m, vec1_m);         \
-    VSHF_B2_SB(src2, src2, src3, src3, mask0, mask0, vec2_m, vec3_m);         \
-    DOTP_SB4_SH(vec0_m, vec1_m, vec2_m, vec3_m, filt0, filt0, filt0, filt0,   \
-                out0, out1, out2, out3);                                      \
-    VSHF_B2_SB(src0, src0, src1, src1, mask1, mask1, vec0_m, vec1_m);         \
-    VSHF_B2_SB(src2, src2, src3, src3, mask1, mask1, vec2_m, vec3_m);         \
-    VSHF_B2_SB(src0, src0, src1, src1, mask2, mask2, vec4_m, vec5_m);         \
-    VSHF_B2_SB(src2, src2, src3, src3, mask2, mask2, vec6_m, vec7_m);         \
-    DPADD_SB4_SH(vec0_m, vec1_m, vec2_m, vec3_m, filt1, filt1, filt1, filt1,  \
-                 out0, out1, out2, out3);                                     \
-    DPADD_SB4_SH(vec4_m, vec5_m, vec6_m, vec7_m, filt2, filt2, filt2, filt2,  \
-                 out0, out1, out2, out3);                                     \
-}
-
-#define FILT_4TAP_DPADD_S_H(vec0, vec1, filt0, filt1)         \
-({                                                            \
-    v8i16 tmp0;                                               \
-                                                              \
-    tmp0 = __msa_dotp_s_h((v16i8)vec0, (v16i8)filt0);         \
-    tmp0 = __msa_dpadd_s_h(tmp0, (v16i8)vec1, (v16i8)filt1);  \
-                                                              \
-    tmp0;                                                     \
-})
-
-#define HORIZ_4TAP_FILT(src0, src1, mask0, mask1, filt_h0, filt_h1)    \
-({                                                                     \
-    v16i8 vec0_m, vec1_m;                                              \
-    v8i16 hz_out_m;                                                    \
-                                                                       \
-    VSHF_B2_SB(src0, src1, src0, src1, mask0, mask1, vec0_m, vec1_m);  \
-    hz_out_m = FILT_4TAP_DPADD_S_H(vec0_m, vec1_m, filt_h0, filt_h1);  \
-                                                                       \
-    hz_out_m = __msa_srari_h(hz_out_m, VP8_FILTER_SHIFT);              \
-    hz_out_m = __msa_sat_s_h(hz_out_m, 7);                             \
-                                                                       \
-    hz_out_m;                                                          \
-})
-
-#define HORIZ_4TAP_4WID_4VECS_FILT(src0, src1, src2, src3,             \
-                                   mask0, mask1, filt0, filt1,         \
-                                   out0, out1)                         \
-{                                                                      \
-    v16i8 vec0_m, vec1_m, vec2_m, vec3_m;                              \
-                                                                       \
-    VSHF_B2_SB(src0, src1, src2, src3, mask0, mask0, vec0_m, vec1_m);  \
-    DOTP_SB2_SH(vec0_m, vec1_m, filt0, filt0, out0, out1);             \
-    VSHF_B2_SB(src0, src1, src2, src3, mask1, mask1, vec2_m, vec3_m);  \
-    DPADD_SB2_SH(vec2_m, vec3_m, filt1, filt1, out0, out1);            \
-}
-
-#define HORIZ_4TAP_8WID_4VECS_FILT(src0, src1, src2, src3,                    \
-                                   mask0, mask1, filt0, filt1,                \
-                                   out0, out1, out2, out3)                    \
-{                                                                             \
-    v16i8 vec0_m, vec1_m, vec2_m, vec3_m;                                     \
-                                                                              \
-    VSHF_B2_SB(src0, src0, src1, src1, mask0, mask0, vec0_m, vec1_m);         \
-    VSHF_B2_SB(src2, src2, src3, src3, mask0, mask0, vec2_m, vec3_m);         \
-    DOTP_SB4_SH(vec0_m, vec1_m, vec2_m, vec3_m, filt0, filt0, filt0, filt0,   \
-                out0, out1, out2, out3);                                      \
-    VSHF_B2_SB(src0, src0, src1, src1, mask1, mask1, vec0_m, vec1_m);         \
-    VSHF_B2_SB(src2, src2, src3, src3, mask1, mask1, vec2_m, vec3_m);         \
-    DPADD_SB4_SH(vec0_m, vec1_m, vec2_m, vec3_m, filt1, filt1, filt1, filt1,  \
-                 out0, out1, out2, out3);                                     \
-}
-
-static void common_hz_6t_4x4_msa(uint8_t *RESTRICT src, int32_t src_stride,
-                                 uint8_t *RESTRICT dst, int32_t dst_stride,
-                                 const int8_t *filter)
-{
-    v16i8 src0, src1, src2, src3, filt0, filt1, filt2;
-    v16u8 mask0, mask1, mask2, out;
-    v8i16 filt, out0, out1;
-
-    mask0 = LD_UB(&vp8_mc_filt_mask_arr[16]);
-    src -= 2;
-
-    filt = LD_SH(filter);
-    SPLATI_H3_SB(filt, 0, 1, 2, filt0, filt1, filt2);
-
-    mask1 = mask0 + 2;
-    mask2 = mask0 + 4;
-
-    LD_SB4(src, src_stride, src0, src1, src2, src3);
-    XORI_B4_128_SB(src0, src1, src2, src3);
-    HORIZ_6TAP_4WID_4VECS_FILT(src0, src1, src2, src3, mask0, mask1, mask2,
-                               filt0, filt1, filt2, out0, out1);
-    SRARI_H2_SH(out0, out1, VP8_FILTER_SHIFT);
-    SAT_SH2_SH(out0, out1, 7);
-    out = PCKEV_XORI128_UB(out0, out1);
-    ST4x4_UB(out, out, 0, 1, 2, 3, dst, dst_stride);
-}
-
-static void common_hz_6t_4x8_msa(uint8_t *RESTRICT src, int32_t src_stride,
-                                 uint8_t *RESTRICT dst, int32_t dst_stride,
-                                 const int8_t *filter)
-{
-    v16i8 src0, src1, src2, src3, filt0, filt1, filt2;
-    v16u8 mask0, mask1, mask2, out;
-    v8i16 filt, out0, out1, out2, out3;
-
-    mask0 = LD_UB(&vp8_mc_filt_mask_arr[16]);
-    src -= 2;
-
-    filt = LD_SH(filter);
-    SPLATI_H3_SB(filt, 0, 1, 2, filt0, filt1, filt2);
-
-    mask1 = mask0 + 2;
-    mask2 = mask0 + 4;
-
-    LD_SB4(src, src_stride, src0, src1, src2, src3);
-    XORI_B4_128_SB(src0, src1, src2, src3);
-    src += (4 * src_stride);
-    HORIZ_6TAP_4WID_4VECS_FILT(src0, src1, src2, src3, mask0, mask1, mask2,
-                               filt0, filt1, filt2, out0, out1);
-    LD_SB4(src, src_stride, src0, src1, src2, src3);
-    XORI_B4_128_SB(src0, src1, src2, src3);
-    HORIZ_6TAP_4WID_4VECS_FILT(src0, src1, src2, src3, mask0, mask1, mask2,
-                               filt0, filt1, filt2, out2, out3);
-    SRARI_H4_SH(out0, out1, out2, out3, VP8_FILTER_SHIFT);
-    SAT_SH4_SH(out0, out1, out2, out3, 7);
-    out = PCKEV_XORI128_UB(out0, out1);
-    ST4x4_UB(out, out, 0, 1, 2, 3, dst, dst_stride);
-    dst += (4 * dst_stride);
-    out = PCKEV_XORI128_UB(out2, out3);
-    ST4x4_UB(out, out, 0, 1, 2, 3, dst, dst_stride);
-}
-
-static void common_hz_6t_4w_msa(uint8_t *RESTRICT src, int32_t src_stride,
-                                uint8_t *RESTRICT dst, int32_t dst_stride,
-                                const int8_t *filter, int32_t height)
-{
-    if (4 == height)
-    {
-        common_hz_6t_4x4_msa(src, src_stride, dst, dst_stride, filter);
-    }
-    else if (8 == height)
-    {
-        common_hz_6t_4x8_msa(src, src_stride, dst, dst_stride, filter);
-    }
-}
-
-static void common_hz_6t_8w_msa(uint8_t *RESTRICT src, int32_t src_stride,
-                                uint8_t *RESTRICT dst, int32_t dst_stride,
-                                const int8_t *filter, int32_t height)
-{
-    uint32_t loop_cnt;
-    v16i8 src0, src1, src2, src3, filt0, filt1, filt2;
-    v16u8 mask0, mask1, mask2, tmp0, tmp1;
-    v8i16 filt, out0, out1, out2, out3;
-
-    mask0 = LD_UB(&vp8_mc_filt_mask_arr[0]);
-    src -= 2;
-
-    filt = LD_SH(filter);
-    SPLATI_H3_SB(filt, 0, 1, 2, filt0, filt1, filt2);
-
-    mask1 = mask0 + 2;
-    mask2 = mask0 + 4;
-
-    LD_SB4(src, src_stride, src0, src1, src2, src3);
-    XORI_B4_128_SB(src0, src1, src2, src3);
-    src += (4 * src_stride);
-    HORIZ_6TAP_8WID_4VECS_FILT(src0, src1, src2, src3, mask0, mask1, mask2,
-                               filt0, filt1, filt2, out0, out1, out2, out3);
-    SRARI_H4_SH(out0, out1, out2, out3, VP8_FILTER_SHIFT);
-    SAT_SH4_SH(out0, out1, out2, out3, 7);
-    tmp0 = PCKEV_XORI128_UB(out0, out1);
-    tmp1 = PCKEV_XORI128_UB(out2, out3);
-    ST8x4_UB(tmp0, tmp1, dst, dst_stride);
-    dst += (4 * dst_stride);
-
-    for (loop_cnt = (height >> 2) - 1; loop_cnt--;)
-    {
-        LD_SB4(src, src_stride, src0, src1, src2, src3);
-        XORI_B4_128_SB(src0, src1, src2, src3);
-        src += (4 * src_stride);
-        HORIZ_6TAP_8WID_4VECS_FILT(src0, src1, src2, src3, mask0, mask1, mask2,
-                                   filt0, filt1, filt2, out0, out1, out2, out3);
-        SRARI_H4_SH(out0, out1, out2, out3, VP8_FILTER_SHIFT);
-        SAT_SH4_SH(out0, out1, out2, out3, 7);
-        tmp0 = PCKEV_XORI128_UB(out0, out1);
-        tmp1 = PCKEV_XORI128_UB(out2, out3);
-        ST8x4_UB(tmp0, tmp1, dst, dst_stride);
-        dst += (4 * dst_stride);
-    }
-}
-
-static void common_hz_6t_16w_msa(uint8_t *RESTRICT src, int32_t src_stride,
-                                 uint8_t *RESTRICT dst, int32_t dst_stride,
-                                 const int8_t *filter, int32_t height)
-{
-    uint32_t loop_cnt;
-    v16i8 src0, src1, src2, src3, src4, src5, src6, src7, filt0, filt1, filt2;
-    v16u8 mask0, mask1, mask2, out;
-    v8i16 filt, out0, out1, out2, out3, out4, out5, out6, out7;
-
-    mask0 = LD_UB(&vp8_mc_filt_mask_arr[0]);
-    src -= 2;
-
-    filt = LD_SH(filter);
-    SPLATI_H3_SB(filt, 0, 1, 2, filt0, filt1, filt2);
-
-    mask1 = mask0 + 2;
-    mask2 = mask0 + 4;
-
-    for (loop_cnt = (height >> 2); loop_cnt--;)
-    {
-        LD_SB4(src, src_stride, src0, src2, src4, src6);
-        LD_SB4(src + 8, src_stride, src1, src3, src5, src7);
-        XORI_B8_128_SB(src0, src1, src2, src3, src4, src5, src6, src7);
-        src += (4 * src_stride);
-
-        HORIZ_6TAP_8WID_4VECS_FILT(src0, src1, src2, src3, mask0, mask1, mask2,
-                                   filt0, filt1, filt2, out0, out1, out2, out3);
-        HORIZ_6TAP_8WID_4VECS_FILT(src4, src5, src6, src7, mask0, mask1, mask2,
-                                   filt0, filt1, filt2, out4, out5, out6, out7);
-        SRARI_H4_SH(out0, out1, out2, out3, VP8_FILTER_SHIFT);
-        SRARI_H4_SH(out4, out5, out6, out7, VP8_FILTER_SHIFT);
-        SAT_SH4_SH(out0, out1, out2, out3, 7);
-        SAT_SH4_SH(out4, out5, out6, out7, 7);
-        out = PCKEV_XORI128_UB(out0, out1);
-        ST_UB(out, dst);
-        dst += dst_stride;
-        out = PCKEV_XORI128_UB(out2, out3);
-        ST_UB(out, dst);
-        dst += dst_stride;
-        out = PCKEV_XORI128_UB(out4, out5);
-        ST_UB(out, dst);
-        dst += dst_stride;
-        out = PCKEV_XORI128_UB(out6, out7);
-        ST_UB(out, dst);
-        dst += dst_stride;
-    }
-}
-
-static void common_vt_6t_4w_msa(uint8_t *RESTRICT src, int32_t src_stride,
-                                uint8_t *RESTRICT dst, int32_t dst_stride,
-                                const int8_t *filter, int32_t height)
-{
-    uint32_t loop_cnt;
-    v16i8 src0, src1, src2, src3, src4, src5, src6, src7, src8;
-    v16i8 src10_r, src32_r, src54_r, src76_r, src21_r, src43_r, src65_r;
-    v16i8 src87_r, src2110, src4332, src6554, src8776, filt0, filt1, filt2;
-    v16u8 out;
-    v8i16 filt, out10, out32;
-
-    src -= (2 * src_stride);
-
-    filt = LD_SH(filter);
-    SPLATI_H3_SB(filt, 0, 1, 2, filt0, filt1, filt2);
-
-    LD_SB5(src, src_stride, src0, src1, src2, src3, src4);
-    src += (5 * src_stride);
-
-    ILVR_B4_SB(src1, src0, src2, src1, src3, src2, src4, src3, src10_r, src21_r,
-               src32_r, src43_r);
-    ILVR_D2_SB(src21_r, src10_r, src43_r, src32_r, src2110, src4332);
-    XORI_B2_128_SB(src2110, src4332);
-
-    for (loop_cnt = (height >> 2); loop_cnt--;)
-    {
-        LD_SB4(src, src_stride, src5, src6, src7, src8);
-        src += (4 * src_stride);
-
-        ILVR_B4_SB(src5, src4, src6, src5, src7, src6, src8, src7, src54_r,
-                   src65_r, src76_r, src87_r);
-        ILVR_D2_SB(src65_r, src54_r, src87_r, src76_r, src6554, src8776);
-        XORI_B2_128_SB(src6554, src8776);
-        out10 = DPADD_SH3_SH(src2110, src4332, src6554, filt0, filt1, filt2);
-        out32 = DPADD_SH3_SH(src4332, src6554, src8776, filt0, filt1, filt2);
-        SRARI_H2_SH(out10, out32, VP8_FILTER_SHIFT);
-        SAT_SH2_SH(out10, out32, 7);
-        out = PCKEV_XORI128_UB(out10, out32);
-        ST4x4_UB(out, out, 0, 1, 2, 3, dst, dst_stride);
-        dst += (4 * dst_stride);
-
-        src2110 = src6554;
-        src4332 = src8776;
-        src4 = src8;
-    }
-}
-
-static void common_vt_6t_8w_msa(uint8_t *RESTRICT src, int32_t src_stride,
-                                uint8_t *RESTRICT dst, int32_t dst_stride,
-                                const int8_t *filter, int32_t height)
-{
-    uint32_t loop_cnt;
-    v16i8 src0, src1, src2, src3, src4, src7, src8, src9, src10;
-    v16i8 src10_r, src32_r, src76_r, src98_r, src21_r, src43_r, src87_r;
-    v16i8 src109_r, filt0, filt1, filt2;
-    v16u8 tmp0, tmp1;
-    v8i16 filt, out0_r, out1_r, out2_r, out3_r;
-
-    src -= (2 * src_stride);
-
-    filt = LD_SH(filter);
-    SPLATI_H3_SB(filt, 0, 1, 2, filt0, filt1, filt2);
-
-    LD_SB5(src, src_stride, src0, src1, src2, src3, src4);
-    src += (5 * src_stride);
-
-    XORI_B5_128_SB(src0, src1, src2, src3, src4);
-    ILVR_B4_SB(src1, src0, src3, src2, src2, src1, src4, src3, src10_r, src32_r,
-               src21_r, src43_r);
-
-    for (loop_cnt = (height >> 2); loop_cnt--;)
-    {
-        LD_SB4(src, src_stride, src7, src8, src9, src10);
-        XORI_B4_128_SB(src7, src8, src9, src10);
-        src += (4 * src_stride);
-
-        ILVR_B4_SB(src7, src4, src8, src7, src9, src8, src10, src9, src76_r,
-                   src87_r, src98_r, src109_r);
-        out0_r = DPADD_SH3_SH(src10_r, src32_r, src76_r, filt0, filt1, filt2);
-        out1_r = DPADD_SH3_SH(src21_r, src43_r, src87_r, filt0, filt1, filt2);
-        out2_r = DPADD_SH3_SH(src32_r, src76_r, src98_r, filt0, filt1, filt2);
-        out3_r = DPADD_SH3_SH(src43_r, src87_r, src109_r, filt0, filt1, filt2);
-        SRARI_H4_SH(out0_r, out1_r, out2_r, out3_r, VP8_FILTER_SHIFT);
-        SAT_SH4_SH(out0_r, out1_r, out2_r, out3_r, 7);
-        tmp0 = PCKEV_XORI128_UB(out0_r, out1_r);
-        tmp1 = PCKEV_XORI128_UB(out2_r, out3_r);
-        ST8x4_UB(tmp0, tmp1, dst, dst_stride);
-        dst += (4 * dst_stride);
-
-        src10_r = src76_r;
-        src32_r = src98_r;
-        src21_r = src87_r;
-        src43_r = src109_r;
-        src4 = src10;
-    }
-}
-
-static void common_vt_6t_16w_msa(uint8_t *RESTRICT src, int32_t src_stride,
-                                 uint8_t *RESTRICT dst, int32_t dst_stride,
-                                 const int8_t *filter, int32_t height)
-{
-    uint32_t loop_cnt;
-    v16i8 src0, src1, src2, src3, src4, src5, src6, src7, src8;
-    v16i8 src10_r, src32_r, src54_r, src76_r, src21_r, src43_r, src65_r;
-    v16i8 src87_r, src10_l, src32_l, src54_l, src76_l, src21_l, src43_l;
-    v16i8 src65_l, src87_l, filt0, filt1, filt2;
-    v16u8 tmp0, tmp1, tmp2, tmp3;
-    v8i16 out0_r, out1_r, out2_r, out3_r, out0_l, out1_l, out2_l, out3_l, filt;
-
-    src -= (2 * src_stride);
-
-    filt = LD_SH(filter);
-    SPLATI_H3_SB(filt, 0, 1, 2, filt0, filt1, filt2);
-
-    LD_SB5(src, src_stride, src0, src1, src2, src3, src4);
-    src += (5 * src_stride);
-
-    XORI_B5_128_SB(src0, src1, src2, src3, src4);
-    ILVR_B4_SB(src1, src0, src3, src2, src4, src3, src2, src1, src10_r,
-               src32_r, src43_r, src21_r);
-    ILVL_B4_SB(src1, src0, src3, src2, src4, src3, src2, src1, src10_l,
-               src32_l, src43_l, src21_l);
-
-    for (loop_cnt = (height >> 2); loop_cnt--;)
-    {
-        LD_SB4(src, src_stride, src5, src6, src7, src8);
-        src += (4 * src_stride);
-
-        XORI_B4_128_SB(src5, src6, src7, src8);
-        ILVR_B4_SB(src5, src4, src6, src5, src7, src6, src8, src7, src54_r,
-                   src65_r, src76_r, src87_r);
-        ILVL_B4_SB(src5, src4, src6, src5, src7, src6, src8, src7, src54_l,
-                   src65_l, src76_l, src87_l);
-        out0_r = DPADD_SH3_SH(src10_r, src32_r, src54_r, filt0, filt1, filt2);
-        out1_r = DPADD_SH3_SH(src21_r, src43_r, src65_r, filt0, filt1, filt2);
-        out2_r = DPADD_SH3_SH(src32_r, src54_r, src76_r, filt0, filt1, filt2);
-        out3_r = DPADD_SH3_SH(src43_r, src65_r, src87_r, filt0, filt1, filt2);
-        out0_l = DPADD_SH3_SH(src10_l, src32_l, src54_l, filt0, filt1, filt2);
-        out1_l = DPADD_SH3_SH(src21_l, src43_l, src65_l, filt0, filt1, filt2);
-        out2_l = DPADD_SH3_SH(src32_l, src54_l, src76_l, filt0, filt1, filt2);
-        out3_l = DPADD_SH3_SH(src43_l, src65_l, src87_l, filt0, filt1, filt2);
-        SRARI_H4_SH(out0_r, out1_r, out2_r, out3_r, VP8_FILTER_SHIFT);
-        SRARI_H4_SH(out0_l, out1_l, out2_l, out3_l, VP8_FILTER_SHIFT);
-        SAT_SH4_SH(out0_r, out1_r, out2_r, out3_r, 7);
-        SAT_SH4_SH(out0_l, out1_l, out2_l, out3_l, 7);
-        PCKEV_B4_UB(out0_l, out0_r, out1_l, out1_r, out2_l, out2_r, out3_l,
-                    out3_r, tmp0, tmp1, tmp2, tmp3);
-        XORI_B4_128_UB(tmp0, tmp1, tmp2, tmp3);
-        ST_UB4(tmp0, tmp1, tmp2, tmp3, dst, dst_stride);
-        dst += (4 * dst_stride);
-
-        src10_r = src54_r;
-        src32_r = src76_r;
-        src21_r = src65_r;
-        src43_r = src87_r;
-        src10_l = src54_l;
-        src32_l = src76_l;
-        src21_l = src65_l;
-        src43_l = src87_l;
-        src4 = src8;
-    }
-}
-
-static void common_hv_6ht_6vt_4w_msa(uint8_t *RESTRICT src, int32_t src_stride,
-                                     uint8_t *RESTRICT dst, int32_t dst_stride,
-                                     const int8_t *filter_horiz,
-                                     const int8_t *filter_vert,
-                                     int32_t height)
-{
-    uint32_t loop_cnt;
-    v16i8 src0, src1, src2, src3, src4, src5, src6, src7, src8;
-    v16i8 filt_hz0, filt_hz1, filt_hz2;
-    v16u8 mask0, mask1, mask2, out;
-    v8i16 tmp0, tmp1;
-    v8i16 hz_out0, hz_out1, hz_out2, hz_out3, hz_out4, hz_out5, hz_out6;
-    v8i16 hz_out7, filt, filt_vt0, filt_vt1, filt_vt2, out0, out1, out2, out3;
-
-    mask0 = LD_UB(&vp8_mc_filt_mask_arr[16]);
-    src -= (2 + 2 * src_stride);
-
-    filt = LD_SH(filter_horiz);
-    SPLATI_H3_SB(filt, 0, 1, 2, filt_hz0, filt_hz1, filt_hz2);
-    filt = LD_SH(filter_vert);
-    SPLATI_H3_SH(filt, 0, 1, 2, filt_vt0, filt_vt1, filt_vt2);
-
-    mask1 = mask0 + 2;
-    mask2 = mask0 + 4;
-
-    LD_SB5(src, src_stride, src0, src1, src2, src3, src4);
-    src += (5 * src_stride);
-
-    XORI_B5_128_SB(src0, src1, src2, src3, src4);
-    hz_out0 = HORIZ_6TAP_FILT(src0, src1, mask0, mask1, mask2, filt_hz0,
-                              filt_hz1, filt_hz2);
-    hz_out2 = HORIZ_6TAP_FILT(src2, src3, mask0, mask1, mask2, filt_hz0,
-                              filt_hz1, filt_hz2);
-    hz_out1 = (v8i16)__msa_sldi_b((v16i8)hz_out2, (v16i8)hz_out0, 8);
-    hz_out3 = HORIZ_6TAP_FILT(src3, src4, mask0, mask1, mask2, filt_hz0,
-                              filt_hz1, filt_hz2);
-    ILVEV_B2_SH(hz_out0, hz_out1, hz_out2, hz_out3, out0, out1);
-
-    for (loop_cnt = (height >> 2); loop_cnt--;)
-    {
-        LD_SB2(src, src_stride, src5, src6);
-        src += (2 * src_stride);
-
-        XORI_B2_128_SB(src5, src6);
-        hz_out5 = HORIZ_6TAP_FILT(src5, src6, mask0, mask1, mask2, filt_hz0,
-                                  filt_hz1, filt_hz2);
-        hz_out4 = (v8i16)__msa_sldi_b((v16i8)hz_out5, (v16i8)hz_out3, 8);
-
-        LD_SB2(src, src_stride, src7, src8);
-        src += (2 * src_stride);
-
-        XORI_B2_128_SB(src7, src8);
-        hz_out7 = HORIZ_6TAP_FILT(src7, src8, mask0, mask1, mask2, filt_hz0,
-                                  filt_hz1, filt_hz2);
-        hz_out6 = (v8i16)__msa_sldi_b((v16i8)hz_out7, (v16i8)hz_out5, 8);
-
-        out2 = (v8i16)__msa_ilvev_b((v16i8)hz_out5, (v16i8)hz_out4);
-        tmp0 = DPADD_SH3_SH(out0, out1, out2, filt_vt0, filt_vt1, filt_vt2);
-
-        out3 = (v8i16)__msa_ilvev_b((v16i8)hz_out7, (v16i8)hz_out6);
-        tmp1 = DPADD_SH3_SH(out1, out2, out3, filt_vt0, filt_vt1, filt_vt2);
-
-        SRARI_H2_SH(tmp0, tmp1, 7);
-        SAT_SH2_SH(tmp0, tmp1, 7);
-        out = PCKEV_XORI128_UB(tmp0, tmp1);
-        ST4x4_UB(out, out, 0, 1, 2, 3, dst, dst_stride);
-        dst += (4 * dst_stride);
-
-        hz_out3 = hz_out7;
-        out0 = out2;
-        out1 = out3;
-    }
-}
-
-static void common_hv_6ht_6vt_8w_msa(uint8_t *RESTRICT src, int32_t src_stride,
-                                     uint8_t *RESTRICT dst, int32_t dst_stride,
-                                     const int8_t *filter_horiz,
-                                     const int8_t *filter_vert,
-                                     int32_t height)
-{
-    uint32_t loop_cnt;
-    v16i8 src0, src1, src2, src3, src4, src5, src6, src7, src8;
-    v16i8 filt_hz0, filt_hz1, filt_hz2;
-    v16u8 mask0, mask1, mask2, vec0, vec1;
-    v8i16 filt, filt_vt0, filt_vt1, filt_vt2;
-    v8i16 hz_out0, hz_out1, hz_out2, hz_out3, hz_out4,  hz_out5, hz_out6;
-    v8i16 hz_out7, hz_out8, out0, out1, out2, out3, out4, out5, out6, out7;
-    v8i16 tmp0, tmp1, tmp2, tmp3;
-
-    mask0 = LD_UB(&vp8_mc_filt_mask_arr[0]);
-    src -= (2 + 2 * src_stride);
-
-    filt = LD_SH(filter_horiz);
-    SPLATI_H3_SB(filt, 0, 1, 2, filt_hz0, filt_hz1, filt_hz2);
-
-    mask1 = mask0 + 2;
-    mask2 = mask0 + 4;
-
-    LD_SB5(src, src_stride, src0, src1, src2, src3, src4);
-    src += (5 * src_stride);
-
-    XORI_B5_128_SB(src0, src1, src2, src3, src4);
-    hz_out0 = HORIZ_6TAP_FILT(src0, src0, mask0, mask1, mask2, filt_hz0,
-                              filt_hz1, filt_hz2);
-    hz_out1 = HORIZ_6TAP_FILT(src1, src1, mask0, mask1, mask2, filt_hz0,
-                              filt_hz1, filt_hz2);
-    hz_out2 = HORIZ_6TAP_FILT(src2, src2, mask0, mask1, mask2, filt_hz0,
-                              filt_hz1, filt_hz2);
-    hz_out3 = HORIZ_6TAP_FILT(src3, src3, mask0, mask1, mask2, filt_hz0,
-                              filt_hz1, filt_hz2);
-    hz_out4 = HORIZ_6TAP_FILT(src4, src4, mask0, mask1, mask2, filt_hz0,
-                              filt_hz1, filt_hz2);
-
-    filt = LD_SH(filter_vert);
-    SPLATI_H3_SH(filt, 0, 1, 2, filt_vt0, filt_vt1, filt_vt2);
-
-    ILVEV_B2_SH(hz_out0, hz_out1, hz_out2, hz_out3, out0, out1);
-    ILVEV_B2_SH(hz_out1, hz_out2, hz_out3, hz_out4, out3, out4);
-
-    for (loop_cnt = (height >> 2); loop_cnt--;)
-    {
-        LD_SB4(src, src_stride, src5, src6, src7, src8);
-        src += (4 * src_stride);
-
-        XORI_B4_128_SB(src5, src6, src7, src8);
-        hz_out5 = HORIZ_6TAP_FILT(src5, src5, mask0, mask1, mask2, filt_hz0,
-                                  filt_hz1, filt_hz2);
-        out2 = (v8i16)__msa_ilvev_b((v16i8)hz_out5, (v16i8)hz_out4);
-        tmp0 = DPADD_SH3_SH(out0, out1, out2, filt_vt0, filt_vt1, filt_vt2);
-
-        hz_out6 = HORIZ_6TAP_FILT(src6, src6, mask0, mask1, mask2, filt_hz0,
-                                  filt_hz1, filt_hz2);
-        out5 = (v8i16)__msa_ilvev_b((v16i8)hz_out6, (v16i8)hz_out5);
-        tmp1 = DPADD_SH3_SH(out3, out4, out5, filt_vt0, filt_vt1, filt_vt2);
-
-        hz_out7 = HORIZ_6TAP_FILT(src7, src7, mask0, mask1, mask2, filt_hz0,
-                                  filt_hz1, filt_hz2);
-        out7 = (v8i16)__msa_ilvev_b((v16i8)hz_out7, (v16i8)hz_out6);
-        tmp2 = DPADD_SH3_SH(out1, out2, out7, filt_vt0, filt_vt1, filt_vt2);
-
-        hz_out8 = HORIZ_6TAP_FILT(src8, src8, mask0, mask1, mask2, filt_hz0,
-                                  filt_hz1, filt_hz2);
-        out6 = (v8i16)__msa_ilvev_b((v16i8)hz_out8, (v16i8)hz_out7);
-        tmp3 = DPADD_SH3_SH(out4, out5, out6, filt_vt0, filt_vt1, filt_vt2);
-
-        SRARI_H4_SH(tmp0, tmp1, tmp2, tmp3, 7);
-        SAT_SH4_SH(tmp0, tmp1, tmp2, tmp3, 7);
-        vec0 = PCKEV_XORI128_UB(tmp0, tmp1);
-        vec1 = PCKEV_XORI128_UB(tmp2, tmp3);
-        ST8x4_UB(vec0, vec1, dst, dst_stride);
-        dst += (4 * dst_stride);
-
-        hz_out4 = hz_out8;
-        out0 = out2;
-        out1 = out7;
-        out3 = out5;
-        out4 = out6;
-    }
-}
-
-static void common_hv_6ht_6vt_16w_msa(uint8_t *RESTRICT src, int32_t src_stride,
-                                      uint8_t *RESTRICT dst, int32_t dst_stride,
-                                      const int8_t *filter_horiz,
-                                      const int8_t *filter_vert,
-                                      int32_t height)
-{
-    int32_t multiple8_cnt;
-    for (multiple8_cnt = 2; multiple8_cnt--;)
-    {
-        common_hv_6ht_6vt_8w_msa(src, src_stride, dst, dst_stride, filter_horiz,
-                                 filter_vert, height);
-        src += 8;
-        dst += 8;
-    }
-}
-
-static void common_hz_4t_4x4_msa(uint8_t *RESTRICT src, int32_t src_stride,
-                                 uint8_t *RESTRICT dst, int32_t dst_stride,
-                                 const int8_t *filter)
-{
-    v16i8 src0, src1, src2, src3, filt0, filt1, mask0, mask1;
-    v8i16 filt, out0, out1;
-    v16u8 out;
-
-    mask0 = LD_SB(&vp8_mc_filt_mask_arr[16]);
-    src -= 1;
-
-    filt = LD_SH(filter);
-    SPLATI_H2_SB(filt, 0, 1, filt0, filt1);
-
-    mask1 = mask0 + 2;
-
-    LD_SB4(src, src_stride, src0, src1, src2, src3);
-    XORI_B4_128_SB(src0, src1, src2, src3);
-    HORIZ_4TAP_4WID_4VECS_FILT(src0, src1, src2, src3, mask0, mask1,
-                               filt0, filt1, out0, out1);
-    SRARI_H2_SH(out0, out1, VP8_FILTER_SHIFT);
-    SAT_SH2_SH(out0, out1, 7);
-    out = PCKEV_XORI128_UB(out0, out1);
-    ST4x4_UB(out, out, 0, 1, 2, 3, dst, dst_stride);
-}
-
-static void common_hz_4t_4x8_msa(uint8_t *RESTRICT src, int32_t src_stride,
-                                 uint8_t *RESTRICT dst, int32_t dst_stride,
-                                 const int8_t *filter)
-{
-    v16i8 src0, src1, src2, src3, filt0, filt1, mask0, mask1;
-    v16u8 out;
-    v8i16 filt, out0, out1, out2, out3;
-
-    mask0 = LD_SB(&vp8_mc_filt_mask_arr[16]);
-    src -= 1;
-
-    filt = LD_SH(filter);
-    SPLATI_H2_SB(filt, 0, 1, filt0, filt1);
-
-    mask1 = mask0 + 2;
-
-    LD_SB4(src, src_stride, src0, src1, src2, src3);
-    src += (4 * src_stride);
-
-    XORI_B4_128_SB(src0, src1, src2, src3);
-    HORIZ_4TAP_4WID_4VECS_FILT(src0, src1, src2, src3, mask0, mask1,
-                               filt0, filt1, out0, out1);
-    LD_SB4(src, src_stride, src0, src1, src2, src3);
-    XORI_B4_128_SB(src0, src1, src2, src3);
-    HORIZ_4TAP_4WID_4VECS_FILT(src0, src1, src2, src3, mask0, mask1,
-                               filt0, filt1, out2, out3);
-    SRARI_H4_SH(out0, out1, out2, out3, VP8_FILTER_SHIFT);
-    SAT_SH4_SH(out0, out1, out2, out3, 7);
-    out = PCKEV_XORI128_UB(out0, out1);
-    ST4x4_UB(out, out, 0, 1, 2, 3, dst, dst_stride);
-    dst += (4 * dst_stride);
-    out = PCKEV_XORI128_UB(out2, out3);
-    ST4x4_UB(out, out, 0, 1, 2, 3, dst, dst_stride);
-}
-
-static void common_hz_4t_4w_msa(uint8_t *RESTRICT src, int32_t src_stride,
-                                uint8_t *RESTRICT dst, int32_t dst_stride,
-                                const int8_t *filter, int32_t height)
-{
-    if (4 == height)
-    {
-        common_hz_4t_4x4_msa(src, src_stride, dst, dst_stride, filter);
-    }
-    else if (8 == height)
-    {
-        common_hz_4t_4x8_msa(src, src_stride, dst, dst_stride, filter);
-    }
-}
-
-static void common_hz_4t_8w_msa(uint8_t *RESTRICT src, int32_t src_stride,
-                                uint8_t *RESTRICT dst, int32_t dst_stride,
-                                const int8_t *filter, int32_t height)
-{
-    uint32_t loop_cnt;
-    v16i8 src0, src1, src2, src3, filt0, filt1, mask0, mask1;
-    v16u8 tmp0, tmp1;
-    v8i16 filt, out0, out1, out2, out3;
-
-    mask0 = LD_SB(&vp8_mc_filt_mask_arr[0]);
-    src -= 1;
-
-    filt = LD_SH(filter);
-    SPLATI_H2_SB(filt, 0, 1, filt0, filt1);
-
-    mask1 = mask0 + 2;
-
-    for (loop_cnt = (height >> 2); loop_cnt--;)
-    {
-        LD_SB4(src, src_stride, src0, src1, src2, src3);
-        src += (4 * src_stride);
-
-        XORI_B4_128_SB(src0, src1, src2, src3);
-        HORIZ_4TAP_8WID_4VECS_FILT(src0, src1, src2, src3, mask0, mask1, filt0,
-                                   filt1, out0, out1, out2, out3);
-        SRARI_H4_SH(out0, out1, out2, out3, VP8_FILTER_SHIFT);
-        SAT_SH4_SH(out0, out1, out2, out3, 7);
-        tmp0 = PCKEV_XORI128_UB(out0, out1);
-        tmp1 = PCKEV_XORI128_UB(out2, out3);
-        ST8x4_UB(tmp0, tmp1, dst, dst_stride);
-        dst += (4 * dst_stride);
-    }
-}
-
-static void common_hz_4t_16w_msa(uint8_t *RESTRICT src, int32_t src_stride,
-                                 uint8_t *RESTRICT dst, int32_t dst_stride,
-                                 const int8_t *filter, int32_t height)
-{
-    uint32_t loop_cnt;
-    v16i8 src0, src1, src2, src3, src4, src5, src6, src7;
-    v16i8 filt0, filt1, mask0, mask1;
-    v8i16 filt, out0, out1, out2, out3, out4, out5, out6, out7;
-    v16u8 out;
-
-    mask0 = LD_SB(&vp8_mc_filt_mask_arr[0]);
-    src -= 1;
-
-    filt = LD_SH(filter);
-    SPLATI_H2_SB(filt, 0, 1, filt0, filt1);
-
-    mask1 = mask0 + 2;
-
-    for (loop_cnt = (height >> 2); loop_cnt--;)
-    {
-        LD_SB4(src, src_stride, src0, src2, src4, src6);
-        LD_SB4(src + 8, src_stride, src1, src3, src5, src7);
-        src += (4 * src_stride);
-
-        XORI_B8_128_SB(src0, src1, src2, src3, src4, src5, src6, src7);
-        HORIZ_4TAP_8WID_4VECS_FILT(src0, src1, src2, src3, mask0, mask1, filt0,
-                                   filt1, out0, out1, out2, out3);
-        HORIZ_4TAP_8WID_4VECS_FILT(src4, src5, src6, src7, mask0, mask1, filt0,
-                                   filt1, out4, out5, out6, out7);
-        SRARI_H4_SH(out0, out1, out2, out3, VP8_FILTER_SHIFT);
-        SRARI_H4_SH(out4, out5, out6, out7, VP8_FILTER_SHIFT);
-        SAT_SH4_SH(out0, out1, out2, out3, 7);
-        SAT_SH4_SH(out4, out5, out6, out7, 7);
-        out = PCKEV_XORI128_UB(out0, out1);
-        ST_UB(out, dst);
-        dst += dst_stride;
-        out = PCKEV_XORI128_UB(out2, out3);
-        ST_UB(out, dst);
-        dst += dst_stride;
-        out = PCKEV_XORI128_UB(out4, out5);
-        ST_UB(out, dst);
-        dst += dst_stride;
-        out = PCKEV_XORI128_UB(out6, out7);
-        ST_UB(out, dst);
-        dst += dst_stride;
-    }
-}
-
-static void common_vt_4t_4w_msa(uint8_t *RESTRICT src, int32_t src_stride,
-                                uint8_t *RESTRICT dst, int32_t dst_stride,
-                                const int8_t *filter, int32_t height)
-{
-    uint32_t loop_cnt;
-    v16i8 src0, src1, src2, src3, src4, src5;
-    v16i8 src10_r, src32_r, src54_r, src21_r, src43_r, src65_r;
-    v16i8 src2110, src4332, filt0, filt1;
-    v8i16 filt, out10, out32;
-    v16u8 out;
-
-    src -= src_stride;
-
-    filt = LD_SH(filter);
-    SPLATI_H2_SB(filt, 0, 1, filt0, filt1);
-
-    LD_SB3(src, src_stride, src0, src1, src2);
-    src += (3 * src_stride);
-
-    ILVR_B2_SB(src1, src0, src2, src1, src10_r, src21_r);
-
-    src2110 = (v16i8)__msa_ilvr_d((v2i64)src21_r, (v2i64)src10_r);
-    src2110 = (v16i8)__msa_xori_b((v16u8)src2110, 128);
-
-    for (loop_cnt = (height >> 2); loop_cnt--;)
-    {
-        LD_SB3(src, src_stride, src3, src4, src5);
-        src += (3 * src_stride);
-        ILVR_B2_SB(src3, src2, src4, src3, src32_r, src43_r);
-        src4332 = (v16i8)__msa_ilvr_d((v2i64)src43_r, (v2i64)src32_r);
-        src4332 = (v16i8)__msa_xori_b((v16u8)src4332, 128);
-        out10 = FILT_4TAP_DPADD_S_H(src2110, src4332, filt0, filt1);
-
-        src2 = LD_SB(src);
-        src += (src_stride);
-        ILVR_B2_SB(src5, src4, src2, src5, src54_r, src65_r);
-        src2110 = (v16i8)__msa_ilvr_d((v2i64)src65_r, (v2i64)src54_r);
-        src2110 = (v16i8)__msa_xori_b((v16u8)src2110, 128);
-        out32 = FILT_4TAP_DPADD_S_H(src4332, src2110, filt0, filt1);
-        SRARI_H2_SH(out10, out32, VP8_FILTER_SHIFT);
-        SAT_SH2_SH(out10, out32, 7);
-        out = PCKEV_XORI128_UB(out10, out32);
-        ST4x4_UB(out, out, 0, 1, 2, 3, dst, dst_stride);
-        dst += (4 * dst_stride);
-    }
-}
-
-static void common_vt_4t_8w_msa(uint8_t *RESTRICT src, int32_t src_stride,
-                                uint8_t *RESTRICT dst, int32_t dst_stride,
-                                const int8_t *filter, int32_t height)
-{
-    uint32_t loop_cnt;
-    v16i8 src0, src1, src2, src7, src8, src9, src10;
-    v16i8 src10_r, src72_r, src98_r, src21_r, src87_r, src109_r, filt0, filt1;
-    v16u8 tmp0, tmp1;
-    v8i16 filt, out0_r, out1_r, out2_r, out3_r;
-
-    src -= src_stride;
-
-    filt = LD_SH(filter);
-    SPLATI_H2_SB(filt, 0, 1, filt0, filt1);
-
-    LD_SB3(src, src_stride, src0, src1, src2);
-    src += (3 * src_stride);
-
-    XORI_B3_128_SB(src0, src1, src2);
-    ILVR_B2_SB(src1, src0, src2, src1, src10_r, src21_r);
-
-    for (loop_cnt = (height >> 2); loop_cnt--;)
-    {
-        LD_SB4(src, src_stride, src7, src8, src9, src10);
-        src += (4 * src_stride);
-
-        XORI_B4_128_SB(src7, src8, src9, src10);
-        ILVR_B4_SB(src7, src2, src8, src7, src9, src8, src10, src9,
-                   src72_r, src87_r, src98_r, src109_r);
-        out0_r = FILT_4TAP_DPADD_S_H(src10_r, src72_r, filt0, filt1);
-        out1_r = FILT_4TAP_DPADD_S_H(src21_r, src87_r, filt0, filt1);
-        out2_r = FILT_4TAP_DPADD_S_H(src72_r, src98_r, filt0, filt1);
-        out3_r = FILT_4TAP_DPADD_S_H(src87_r, src109_r, filt0, filt1);
-        SRARI_H4_SH(out0_r, out1_r, out2_r, out3_r, VP8_FILTER_SHIFT);
-        SAT_SH4_SH(out0_r, out1_r, out2_r, out3_r, 7);
-        tmp0 = PCKEV_XORI128_UB(out0_r, out1_r);
-        tmp1 = PCKEV_XORI128_UB(out2_r, out3_r);
-        ST8x4_UB(tmp0, tmp1, dst, dst_stride);
-        dst += (4 * dst_stride);
-
-        src10_r = src98_r;
-        src21_r = src109_r;
-        src2 = src10;
-    }
-}
-
-static void common_vt_4t_16w_msa(uint8_t *RESTRICT src, int32_t src_stride,
-                                 uint8_t *RESTRICT dst, int32_t dst_stride,
-                                 const int8_t *filter, int32_t height)
-{
-    uint32_t loop_cnt;
-    v16i8 src0, src1, src2, src3, src4, src5, src6;
-    v16i8 src10_r, src32_r, src54_r, src21_r, src43_r, src65_r, src10_l;
-    v16i8 src32_l, src54_l, src21_l, src43_l, src65_l, filt0, filt1;
-    v16u8 tmp0, tmp1, tmp2, tmp3;
-    v8i16 filt, out0_r, out1_r, out2_r, out3_r, out0_l, out1_l, out2_l, out3_l;
-
-    src -= src_stride;
-
-    filt = LD_SH(filter);
-    SPLATI_H2_SB(filt, 0, 1, filt0, filt1);
-
-    LD_SB3(src, src_stride, src0, src1, src2);
-    src += (3 * src_stride);
-
-    XORI_B3_128_SB(src0, src1, src2);
-    ILVR_B2_SB(src1, src0, src2, src1, src10_r, src21_r);
-    ILVL_B2_SB(src1, src0, src2, src1, src10_l, src21_l);
-
-    for (loop_cnt = (height >> 2); loop_cnt--;)
-    {
-        LD_SB4(src, src_stride, src3, src4, src5, src6);
-        src += (4 * src_stride);
-
-        XORI_B4_128_SB(src3, src4, src5, src6);
-        ILVR_B4_SB(src3, src2, src4, src3, src5, src4, src6, src5,
-                   src32_r, src43_r, src54_r, src65_r);
-        ILVL_B4_SB(src3, src2, src4, src3, src5, src4, src6, src5,
-                   src32_l, src43_l, src54_l, src65_l);
-        out0_r = FILT_4TAP_DPADD_S_H(src10_r, src32_r, filt0, filt1);
-        out1_r = FILT_4TAP_DPADD_S_H(src21_r, src43_r, filt0, filt1);
-        out2_r = FILT_4TAP_DPADD_S_H(src32_r, src54_r, filt0, filt1);
-        out3_r = FILT_4TAP_DPADD_S_H(src43_r, src65_r, filt0, filt1);
-        out0_l = FILT_4TAP_DPADD_S_H(src10_l, src32_l, filt0, filt1);
-        out1_l = FILT_4TAP_DPADD_S_H(src21_l, src43_l, filt0, filt1);
-        out2_l = FILT_4TAP_DPADD_S_H(src32_l, src54_l, filt0, filt1);
-        out3_l = FILT_4TAP_DPADD_S_H(src43_l, src65_l, filt0, filt1);
-        SRARI_H4_SH(out0_r, out1_r, out2_r, out3_r, VP8_FILTER_SHIFT);
-        SRARI_H4_SH(out0_l, out1_l, out2_l, out3_l, VP8_FILTER_SHIFT);
-        SAT_SH4_SH(out0_r, out1_r, out2_r, out3_r, 7);
-        SAT_SH4_SH(out0_l, out1_l, out2_l, out3_l, 7);
-        PCKEV_B4_UB(out0_l, out0_r, out1_l, out1_r, out2_l, out2_r, out3_l,
-                    out3_r, tmp0, tmp1, tmp2, tmp3);
-        XORI_B4_128_UB(tmp0, tmp1, tmp2, tmp3);
-        ST_UB4(tmp0, tmp1, tmp2, tmp3, dst, dst_stride);
-        dst += (4 * dst_stride);
-
-        src10_r = src54_r;
-        src21_r = src65_r;
-        src10_l = src54_l;
-        src21_l = src65_l;
-        src2 = src6;
-    }
-}
-
-static void common_hv_4ht_4vt_4w_msa(uint8_t *RESTRICT src, int32_t src_stride,
-                                     uint8_t *RESTRICT dst, int32_t dst_stride,
-                                     const int8_t *filter_horiz,
-                                     const int8_t *filter_vert,
-                                     int32_t height)
-{
-    uint32_t loop_cnt;
-    v16i8 src0, src1, src2, src3, src4, src5, src6, filt_hz0, filt_hz1;
-    v16u8 mask0, mask1, out;
-    v8i16 filt, filt_vt0, filt_vt1, tmp0, tmp1, vec0, vec1, vec2;
-    v8i16 hz_out0, hz_out1, hz_out2, hz_out3, hz_out4, hz_out5;
-
-    mask0 = LD_UB(&vp8_mc_filt_mask_arr[16]);
-    src -= (1 + 1 * src_stride);
-
-    filt = LD_SH(filter_horiz);
-    SPLATI_H2_SB(filt, 0, 1, filt_hz0, filt_hz1);
-
-    mask1 = mask0 + 2;
-
-    LD_SB3(src, src_stride, src0, src1, src2);
-    src += (3 * src_stride);
-
-    XORI_B3_128_SB(src0, src1, src2);
-    hz_out0 = HORIZ_4TAP_FILT(src0, src1, mask0, mask1, filt_hz0, filt_hz1);
-    hz_out1 = HORIZ_4TAP_FILT(src1, src2, mask0, mask1, filt_hz0, filt_hz1);
-    vec0 = (v8i16)__msa_ilvev_b((v16i8)hz_out1, (v16i8)hz_out0);
-
-    filt = LD_SH(filter_vert);
-    SPLATI_H2_SH(filt, 0, 1, filt_vt0, filt_vt1);
-
-    for (loop_cnt = (height >> 2); loop_cnt--;)
-    {
-        LD_SB4(src, src_stride, src3, src4, src5, src6);
-        src += (4 * src_stride);
-
-        XORI_B2_128_SB(src3, src4);
-        hz_out3 = HORIZ_4TAP_FILT(src3, src4, mask0, mask1, filt_hz0, filt_hz1);
-        hz_out2 = (v8i16)__msa_sldi_b((v16i8)hz_out3, (v16i8)hz_out1, 8);
-        vec1 = (v8i16)__msa_ilvev_b((v16i8)hz_out3, (v16i8)hz_out2);
-        tmp0 = FILT_4TAP_DPADD_S_H(vec0, vec1, filt_vt0, filt_vt1);
-
-        XORI_B2_128_SB(src5, src6);
-        hz_out5 = HORIZ_4TAP_FILT(src5, src6, mask0, mask1, filt_hz0, filt_hz1);
-        hz_out4 = (v8i16)__msa_sldi_b((v16i8)hz_out5, (v16i8)hz_out3, 8);
-        vec2 = (v8i16)__msa_ilvev_b((v16i8)hz_out5, (v16i8)hz_out4);
-        tmp1 = FILT_4TAP_DPADD_S_H(vec1, vec2, filt_vt0, filt_vt1);
-
-        SRARI_H2_SH(tmp0, tmp1, 7);
-        SAT_SH2_SH(tmp0, tmp1, 7);
-        out = PCKEV_XORI128_UB(tmp0, tmp1);
-        ST4x4_UB(out, out, 0, 1, 2, 3, dst, dst_stride);
-        dst += (4 * dst_stride);
-
-        hz_out1 = hz_out5;
-        vec0 = vec2;
-    }
-}
-
-static void common_hv_4ht_4vt_8w_msa(uint8_t *RESTRICT src, int32_t src_stride,
-                                     uint8_t *RESTRICT dst, int32_t dst_stride,
-                                     const int8_t *filter_horiz,
-                                     const int8_t *filter_vert,
-                                     int32_t height)
-{
-    uint32_t loop_cnt;
-    v16i8 src0, src1, src2, src3, src4, src5, src6, filt_hz0, filt_hz1;
-    v16u8 mask0, mask1, out0, out1;
-    v8i16 filt, filt_vt0, filt_vt1, tmp0, tmp1, tmp2, tmp3;
-    v8i16 hz_out0, hz_out1, hz_out2, hz_out3;
-    v8i16 vec0, vec1, vec2, vec3, vec4;
-
-    mask0 = LD_UB(&vp8_mc_filt_mask_arr[0]);
-    src -= (1 + 1 * src_stride);
-
-    filt = LD_SH(filter_horiz);
-    SPLATI_H2_SB(filt, 0, 1, filt_hz0, filt_hz1);
-
-    mask1 = mask0 + 2;
-
-    LD_SB3(src, src_stride, src0, src1, src2);
-    src += (3 * src_stride);
-
-    XORI_B3_128_SB(src0, src1, src2);
-    hz_out0 = HORIZ_4TAP_FILT(src0, src0, mask0, mask1, filt_hz0, filt_hz1);
-    hz_out1 = HORIZ_4TAP_FILT(src1, src1, mask0, mask1, filt_hz0, filt_hz1);
-    hz_out2 = HORIZ_4TAP_FILT(src2, src2, mask0, mask1, filt_hz0, filt_hz1);
-    ILVEV_B2_SH(hz_out0, hz_out1, hz_out1, hz_out2, vec0, vec2);
-
-    filt = LD_SH(filter_vert);
-    SPLATI_H2_SH(filt, 0, 1, filt_vt0, filt_vt1);
-
-    for (loop_cnt = (height >> 2); loop_cnt--;)
-    {
-        LD_SB4(src, src_stride, src3, src4, src5, src6);
-        src += (4 * src_stride);
-
-        XORI_B4_128_SB(src3, src4, src5, src6);
-        hz_out3 = HORIZ_4TAP_FILT(src3, src3, mask0, mask1, filt_hz0, filt_hz1);
-        vec1 = (v8i16)__msa_ilvev_b((v16i8)hz_out3, (v16i8)hz_out2);
-        tmp0 = FILT_4TAP_DPADD_S_H(vec0, vec1, filt_vt0, filt_vt1);
-
-        hz_out0 = HORIZ_4TAP_FILT(src4, src4, mask0, mask1, filt_hz0, filt_hz1);
-        vec3 = (v8i16)__msa_ilvev_b((v16i8)hz_out0, (v16i8)hz_out3);
-        tmp1 = FILT_4TAP_DPADD_S_H(vec2, vec3, filt_vt0, filt_vt1);
-
-        hz_out1 = HORIZ_4TAP_FILT(src5, src5, mask0, mask1, filt_hz0, filt_hz1);
-        vec4 = (v8i16)__msa_ilvev_b((v16i8)hz_out1, (v16i8)hz_out0);
-        tmp2 = FILT_4TAP_DPADD_S_H(vec1, vec4, filt_vt0, filt_vt1);
-
-        hz_out2 = HORIZ_4TAP_FILT(src6, src6, mask0, mask1, filt_hz0, filt_hz1);
-        ILVEV_B2_SH(hz_out3, hz_out0, hz_out1, hz_out2, vec0, vec1);
-        tmp3 = FILT_4TAP_DPADD_S_H(vec0, vec1, filt_vt0, filt_vt1);
-
-        SRARI_H4_SH(tmp0, tmp1, tmp2, tmp3, 7);
-        SAT_SH4_SH(tmp0, tmp1, tmp2, tmp3, 7);
-        out0 = PCKEV_XORI128_UB(tmp0, tmp1);
-        out1 = PCKEV_XORI128_UB(tmp2, tmp3);
-        ST8x4_UB(out0, out1, dst, dst_stride);
-        dst += (4 * dst_stride);
-
-        vec0 = vec4;
-        vec2 = vec1;
-    }
-}
-
-static void common_hv_4ht_4vt_16w_msa(uint8_t *RESTRICT src, int32_t src_stride,
-                                      uint8_t *RESTRICT dst, int32_t dst_stride,
-                                      const int8_t *filter_horiz,
-                                      const int8_t *filter_vert,
-                                      int32_t height)
-{
-    int32_t multiple8_cnt;
-    for (multiple8_cnt = 2; multiple8_cnt--;)
-    {
-        common_hv_4ht_4vt_8w_msa(src, src_stride, dst, dst_stride, filter_horiz,
-                                 filter_vert, height);
-        src += 8;
-        dst += 8;
-    }
-}
-
-static void common_hv_6ht_4vt_4w_msa(uint8_t *RESTRICT src, int32_t src_stride,
-                                     uint8_t *RESTRICT dst, int32_t dst_stride,
-                                     const int8_t *filter_horiz,
-                                     const int8_t *filter_vert,
-                                     int32_t height)
-{
-    uint32_t loop_cnt;
-    v16i8 src0, src1, src2, src3, src4, src5, src6;
-    v16i8 filt_hz0, filt_hz1, filt_hz2;
-    v16u8 res0, res1, mask0, mask1, mask2;
-    v8i16 filt, filt_vt0, filt_vt1, tmp0, tmp1, vec0, vec1, vec2;
-    v8i16 hz_out0, hz_out1, hz_out2, hz_out3, hz_out4, hz_out5;
-
-    mask0 = LD_UB(&vp8_mc_filt_mask_arr[16]);
-    src -= (2 + 1 * src_stride);
-
-    filt = LD_SH(filter_horiz);
-    SPLATI_H3_SB(filt, 0, 1, 2, filt_hz0, filt_hz1, filt_hz2);
-
-    mask1 = mask0 + 2;
-    mask2 = mask0 + 4;
-
-    LD_SB3(src, src_stride, src0, src1, src2);
-    src += (3 * src_stride);
-
-    XORI_B3_128_SB(src0, src1, src2);
-    hz_out0 = HORIZ_6TAP_FILT(src0, src1, mask0, mask1, mask2, filt_hz0,
-                              filt_hz1, filt_hz2);
-    hz_out1 = HORIZ_6TAP_FILT(src1, src2, mask0, mask1, mask2, filt_hz0,
-                              filt_hz1, filt_hz2);
-    vec0 = (v8i16)__msa_ilvev_b((v16i8)hz_out1, (v16i8)hz_out0);
-
-    filt = LD_SH(filter_vert);
-    SPLATI_H2_SH(filt, 0, 1, filt_vt0, filt_vt1);
-
-    for (loop_cnt = (height >> 2); loop_cnt--;)
-    {
-        LD_SB4(src, src_stride, src3, src4, src5, src6);
-        src += (4 * src_stride);
-
-        XORI_B4_128_SB(src3, src4, src5, src6);
-        hz_out3 = HORIZ_6TAP_FILT(src3, src4, mask0, mask1, mask2, filt_hz0,
-                                  filt_hz1, filt_hz2);
-        hz_out2 = (v8i16)__msa_sldi_b((v16i8)hz_out3, (v16i8)hz_out1, 8);
-        vec1 = (v8i16)__msa_ilvev_b((v16i8)hz_out3, (v16i8)hz_out2);
-        tmp0 = FILT_4TAP_DPADD_S_H(vec0, vec1, filt_vt0, filt_vt1);
-
-        hz_out5 = HORIZ_6TAP_FILT(src5, src6, mask0, mask1, mask2, filt_hz0,
-                                  filt_hz1, filt_hz2);
-        hz_out4 = (v8i16)__msa_sldi_b((v16i8)hz_out5, (v16i8)hz_out3, 8);
-        vec2 = (v8i16)__msa_ilvev_b((v16i8)hz_out5, (v16i8)hz_out4);
-        tmp1 = FILT_4TAP_DPADD_S_H(vec1, vec2, filt_vt0, filt_vt1);
-
-        SRARI_H2_SH(tmp0, tmp1, 7);
-        SAT_SH2_SH(tmp0, tmp1, 7);
-        PCKEV_B2_UB(tmp0, tmp0, tmp1, tmp1, res0, res1);
-        XORI_B2_128_UB(res0, res1);
-        ST4x4_UB(res0, res1, 0, 1, 0, 1, dst, dst_stride);
-        dst += (4 * dst_stride);
-
-        hz_out1 = hz_out5;
-        vec0 = vec2;
-    }
-}
-
-static void common_hv_6ht_4vt_8w_msa(uint8_t *RESTRICT src, int32_t src_stride,
-                                     uint8_t *RESTRICT dst, int32_t dst_stride,
-                                     const int8_t *filter_horiz,
-                                     const int8_t *filter_vert,
-                                     int32_t height)
-{
-    uint32_t loop_cnt;
-    v16i8 src0, src1, src2, src3, src4, src5, src6;
-    v16i8 filt_hz0, filt_hz1, filt_hz2, mask0, mask1, mask2;
-    v8i16 filt, filt_vt0, filt_vt1, hz_out0, hz_out1, hz_out2, hz_out3;
-    v8i16 tmp0, tmp1, tmp2, tmp3, vec0, vec1, vec2, vec3;
-    v16u8 out0, out1;
-
-    mask0 = LD_SB(&vp8_mc_filt_mask_arr[0]);
-    src -= (2 + src_stride);
-
-    filt = LD_SH(filter_horiz);
-    SPLATI_H3_SB(filt, 0, 1, 2, filt_hz0, filt_hz1, filt_hz2);
-
-    mask1 = mask0 + 2;
-    mask2 = mask0 + 4;
-
-    LD_SB3(src, src_stride, src0, src1, src2);
-    src += (3 * src_stride);
-
-    XORI_B3_128_SB(src0, src1, src2);
-    hz_out0 = HORIZ_6TAP_FILT(src0, src0, mask0, mask1, mask2, filt_hz0,
-                              filt_hz1, filt_hz2);
-    hz_out1 = HORIZ_6TAP_FILT(src1, src1, mask0, mask1, mask2, filt_hz0,
-                              filt_hz1, filt_hz2);
-    hz_out2 = HORIZ_6TAP_FILT(src2, src2, mask0, mask1, mask2, filt_hz0,
-                              filt_hz1, filt_hz2);
-    ILVEV_B2_SH(hz_out0, hz_out1, hz_out1, hz_out2, vec0, vec2);
-
-    filt = LD_SH(filter_vert);
-    SPLATI_H2_SH(filt, 0, 1, filt_vt0, filt_vt1);
-
-    for (loop_cnt = (height >> 2); loop_cnt--;)
-    {
-        LD_SB4(src, src_stride, src3, src4, src5, src6);
-        src += (4 * src_stride);
-
-        XORI_B4_128_SB(src3, src4, src5, src6);
-
-        hz_out3 = HORIZ_6TAP_FILT(src3, src3, mask0, mask1, mask2, filt_hz0,
-                                  filt_hz1, filt_hz2);
-        vec1 = (v8i16)__msa_ilvev_b((v16i8)hz_out3, (v16i8)hz_out2);
-        tmp0 = FILT_4TAP_DPADD_S_H(vec0, vec1, filt_vt0, filt_vt1);
-
-        hz_out0 = HORIZ_6TAP_FILT(src4, src4, mask0, mask1, mask2, filt_hz0,
-                                  filt_hz1, filt_hz2);
-        vec3 = (v8i16)__msa_ilvev_b((v16i8)hz_out0, (v16i8)hz_out3);
-        tmp1 = FILT_4TAP_DPADD_S_H(vec2, vec3, filt_vt0, filt_vt1);
-
-        hz_out1 = HORIZ_6TAP_FILT(src5, src5, mask0, mask1, mask2, filt_hz0,
-                                  filt_hz1, filt_hz2);
-        vec0 = (v8i16)__msa_ilvev_b((v16i8)hz_out1, (v16i8)hz_out0);
-        tmp2 = FILT_4TAP_DPADD_S_H(vec1, vec0, filt_vt0, filt_vt1);
-
-        hz_out2 = HORIZ_6TAP_FILT(src6, src6, mask0, mask1, mask2, filt_hz0,
-                                  filt_hz1, filt_hz2);
-        ILVEV_B2_SH(hz_out3, hz_out0, hz_out1, hz_out2, vec1, vec2);
-        tmp3 = FILT_4TAP_DPADD_S_H(vec1, vec2, filt_vt0, filt_vt1);
-
-        SRARI_H4_SH(tmp0, tmp1, tmp2, tmp3, 7);
-        SAT_SH4_SH(tmp0, tmp1, tmp2, tmp3, 7);
-        out0 = PCKEV_XORI128_UB(tmp0, tmp1);
-        out1 = PCKEV_XORI128_UB(tmp2, tmp3);
-        ST8x4_UB(out0, out1, dst, dst_stride);
-        dst += (4 * dst_stride);
-    }
-}
-
-static void common_hv_6ht_4vt_16w_msa(uint8_t *RESTRICT src, int32_t src_stride,
-                                      uint8_t *RESTRICT dst, int32_t dst_stride,
-                                      const int8_t *filter_horiz,
-                                      const int8_t *filter_vert,
-                                      int32_t height)
-{
-    int32_t multiple8_cnt;
-    for (multiple8_cnt = 2; multiple8_cnt--;)
-    {
-        common_hv_6ht_4vt_8w_msa(src, src_stride, dst, dst_stride, filter_horiz,
-                                 filter_vert, height);
-        src += 8;
-        dst += 8;
-    }
-}
-
-static void common_hv_4ht_6vt_4w_msa(uint8_t *RESTRICT src, int32_t src_stride,
-                                     uint8_t *RESTRICT dst, int32_t dst_stride,
-                                     const int8_t *filter_horiz,
-                                     const int8_t *filter_vert,
-                                     int32_t height)
-{
-    uint32_t loop_cnt;
-    v16i8 src0, src1, src2, src3, src4, src5, src6, src7, src8;
-    v16i8 filt_hz0, filt_hz1, mask0, mask1;
-    v16u8 out;
-    v8i16 hz_out0, hz_out1, hz_out2, hz_out3, hz_out4, hz_out5, hz_out6;
-    v8i16 hz_out7, tmp0, tmp1, out0, out1, out2, out3;
-    v8i16 filt, filt_vt0, filt_vt1, filt_vt2;
-
-    mask0 = LD_SB(&vp8_mc_filt_mask_arr[16]);
-
-    src -= (1 + 2 * src_stride);
-
-    filt = LD_SH(filter_horiz);
-    SPLATI_H2_SB(filt, 0, 1, filt_hz0, filt_hz1);
-
-    mask1 = mask0 + 2;
-
-    LD_SB5(src, src_stride, src0, src1, src2, src3, src4);
-    src += (5 * src_stride);
-
-    XORI_B5_128_SB(src0, src1, src2, src3, src4);
-    hz_out0 = HORIZ_4TAP_FILT(src0, src1, mask0, mask1, filt_hz0, filt_hz1);
-    hz_out2 = HORIZ_4TAP_FILT(src2, src3, mask0, mask1, filt_hz0, filt_hz1);
-    hz_out3 = HORIZ_4TAP_FILT(src3, src4, mask0, mask1, filt_hz0, filt_hz1);
-    hz_out1 = (v8i16)__msa_sldi_b((v16i8)hz_out2, (v16i8)hz_out0, 8);
-    ILVEV_B2_SH(hz_out0, hz_out1, hz_out2, hz_out3, out0, out1);
-
-    filt = LD_SH(filter_vert);
-    SPLATI_H3_SH(filt, 0, 1, 2, filt_vt0, filt_vt1, filt_vt2);
-
-    for (loop_cnt = (height >> 2); loop_cnt--;)
-    {
-        LD_SB4(src, src_stride, src5, src6, src7, src8);
-        XORI_B4_128_SB(src5, src6, src7, src8);
-        src += (4 * src_stride);
-
-        hz_out5 = HORIZ_4TAP_FILT(src5, src6, mask0, mask1, filt_hz0, filt_hz1);
-        hz_out4 = (v8i16)__msa_sldi_b((v16i8)hz_out5, (v16i8)hz_out3, 8);
-        out2 = (v8i16)__msa_ilvev_b((v16i8)hz_out5, (v16i8)hz_out4);
-        tmp0 = DPADD_SH3_SH(out0, out1, out2, filt_vt0, filt_vt1, filt_vt2);
-
-        hz_out7 = HORIZ_4TAP_FILT(src7, src8, mask0, mask1, filt_hz0, filt_hz1);
-        hz_out6 = (v8i16)__msa_sldi_b((v16i8)hz_out7, (v16i8)hz_out5, 8);
-        out3 = (v8i16)__msa_ilvev_b((v16i8)hz_out7, (v16i8)hz_out6);
-        tmp1 = DPADD_SH3_SH(out1, out2, out3, filt_vt0, filt_vt1, filt_vt2);
-
-        SRARI_H2_SH(tmp0, tmp1, 7);
-        SAT_SH2_SH(tmp0, tmp1, 7);
-        out = PCKEV_XORI128_UB(tmp0, tmp1);
-        ST4x4_UB(out, out, 0, 1, 2, 3, dst, dst_stride);
-        dst += (4 * dst_stride);
-
-        hz_out3 = hz_out7;
-        out0 = out2;
-        out1 = out3;
-    }
-}
-
-static void common_hv_4ht_6vt_8w_msa(uint8_t *RESTRICT src, int32_t src_stride,
-                                     uint8_t *RESTRICT dst, int32_t dst_stride,
-                                     const int8_t *filter_horiz,
-                                     const int8_t *filter_vert,
-                                     int32_t height)
-{
-    uint32_t loop_cnt;
-    v16i8 src0, src1, src2, src3, src4, src5, src6, src7, src8;
-    v16i8 filt_hz0, filt_hz1, mask0, mask1;
-    v8i16 filt, filt_vt0, filt_vt1, filt_vt2, tmp0, tmp1, tmp2, tmp3;
-    v8i16 hz_out0, hz_out1, hz_out2, hz_out3, hz_out4, hz_out5, hz_out6;
-    v8i16 hz_out7, hz_out8, out0, out1, out2, out3, out4, out5, out6, out7;
-    v16u8 vec0, vec1;
-
-    mask0 = LD_SB(&vp8_mc_filt_mask_arr[0]);
-    src -= (1 + 2 * src_stride);
-
-    filt = LD_SH(filter_horiz);
-    SPLATI_H2_SB(filt, 0, 1, filt_hz0, filt_hz1);
-
-    mask1 = mask0 + 2;
-
-    LD_SB5(src, src_stride, src0, src1, src2, src3, src4);
-    src += (5 * src_stride);
-
-    XORI_B5_128_SB(src0, src1, src2, src3, src4);
-    hz_out0 = HORIZ_4TAP_FILT(src0, src0, mask0, mask1, filt_hz0, filt_hz1);
-    hz_out1 = HORIZ_4TAP_FILT(src1, src1, mask0, mask1, filt_hz0, filt_hz1);
-    hz_out2 = HORIZ_4TAP_FILT(src2, src2, mask0, mask1, filt_hz0, filt_hz1);
-    hz_out3 = HORIZ_4TAP_FILT(src3, src3, mask0, mask1, filt_hz0, filt_hz1);
-    hz_out4 = HORIZ_4TAP_FILT(src4, src4, mask0, mask1, filt_hz0, filt_hz1);
-    ILVEV_B2_SH(hz_out0, hz_out1, hz_out2, hz_out3, out0, out1);
-    ILVEV_B2_SH(hz_out1, hz_out2, hz_out3, hz_out4, out3, out4);
-
-    filt = LD_SH(filter_vert);
-    SPLATI_H3_SH(filt, 0, 1, 2, filt_vt0, filt_vt1, filt_vt2);
-
-    for (loop_cnt = (height >> 2); loop_cnt--;)
-    {
-        LD_SB4(src, src_stride, src5, src6, src7, src8);
-        src += (4 * src_stride);
-
-        XORI_B4_128_SB(src5, src6, src7, src8);
-
-        hz_out5 = HORIZ_4TAP_FILT(src5, src5, mask0, mask1, filt_hz0, filt_hz1);
-        out2 = (v8i16)__msa_ilvev_b((v16i8)hz_out5, (v16i8)hz_out4);
-        tmp0 = DPADD_SH3_SH(out0, out1, out2, filt_vt0, filt_vt1, filt_vt2);
-
-        hz_out6 = HORIZ_4TAP_FILT(src6, src6, mask0, mask1, filt_hz0, filt_hz1);
-        out5 = (v8i16)__msa_ilvev_b((v16i8)hz_out6, (v16i8)hz_out5);
-        tmp1 = DPADD_SH3_SH(out3, out4, out5, filt_vt0, filt_vt1, filt_vt2);
-
-        hz_out7 = HORIZ_4TAP_FILT(src7, src7, mask0, mask1, filt_hz0, filt_hz1);
-        out6 = (v8i16)__msa_ilvev_b((v16i8)hz_out7, (v16i8)hz_out6);
-        tmp2 = DPADD_SH3_SH(out1, out2, out6, filt_vt0, filt_vt1, filt_vt2);
-
-        hz_out8 = HORIZ_4TAP_FILT(src8, src8, mask0, mask1, filt_hz0, filt_hz1);
-        out7 = (v8i16)__msa_ilvev_b((v16i8)hz_out8, (v16i8)hz_out7);
-        tmp3 = DPADD_SH3_SH(out4, out5, out7, filt_vt0, filt_vt1, filt_vt2);
-
-        SRARI_H4_SH(tmp0, tmp1, tmp2, tmp3, 7);
-        SAT_SH4_SH(tmp0, tmp1, tmp2, tmp3, 7);
-        vec0 = PCKEV_XORI128_UB(tmp0, tmp1);
-        vec1 = PCKEV_XORI128_UB(tmp2, tmp3);
-        ST8x4_UB(vec0, vec1, dst, dst_stride);
-        dst += (4 * dst_stride);
-
-        hz_out4 = hz_out8;
-        out0 = out2;
-        out1 = out6;
-        out3 = out5;
-        out4 = out7;
-    }
-}
-
-static void common_hv_4ht_6vt_16w_msa(uint8_t *RESTRICT src, int32_t src_stride,
-                                      uint8_t *RESTRICT dst, int32_t dst_stride,
-                                      const int8_t *filter_horiz,
-                                      const int8_t *filter_vert,
-                                      int32_t height)
-{
-    int32_t multiple8_cnt;
-    for (multiple8_cnt = 2; multiple8_cnt--;)
-    {
-        common_hv_4ht_6vt_8w_msa(src, src_stride, dst, dst_stride, filter_horiz,
-                                 filter_vert, height);
-        src += 8;
-        dst += 8;
-    }
-}
-
-void vp8_sixtap_predict4x4_msa(uint8_t *RESTRICT src, int32_t src_stride,
-                               int32_t xoffset, int32_t yoffset,
-                               uint8_t *RESTRICT dst, int32_t dst_stride)
-{
-    const int8_t *h_filter = vp8_subpel_filters_msa[xoffset - 1];
-    const int8_t *v_filter = vp8_subpel_filters_msa[yoffset - 1];
-
-    if (yoffset)
-    {
-        if (xoffset)
-        {
-            switch (xoffset)
-            {
-                case 2:
-                case 4:
-                case 6:
-                    switch (yoffset)
-                    {
-                        case 2:
-                        case 4:
-                        case 6:
-                            common_hv_6ht_6vt_4w_msa(src, src_stride, dst,
-                                                     dst_stride, h_filter,
-                                                     v_filter, 4);
-                            break;
-
-                        case 1:
-                        case 3:
-                        case 5:
-                        case 7:
-                            common_hv_6ht_4vt_4w_msa(src, src_stride, dst,
-                                                     dst_stride, h_filter,
-                                                     v_filter + 1, 4);
-                            break;
-                    }
-                    break;
-
-                case 1:
-                case 3:
-                case 5:
-                case 7:
-                    switch (yoffset)
-                    {
-                        case 2:
-                        case 4:
-                        case 6:
-                            common_hv_4ht_6vt_4w_msa(src, src_stride, dst,
-                                                     dst_stride, h_filter + 1,
-                                                     v_filter, 4);
-                            break;
-
-                        case 1:
-                        case 3:
-                        case 5:
-                        case 7:
-                            common_hv_4ht_4vt_4w_msa(src, src_stride, dst,
-                                                     dst_stride, h_filter + 1,
-                                                     v_filter + 1, 4);
-                            break;
-                    }
-                    break;
-            }
-        }
-        else
-        {
-            switch (yoffset)
-            {
-                case 2:
-                case 4:
-                case 6:
-                    common_vt_6t_4w_msa(src, src_stride, dst, dst_stride,
-                                        v_filter, 4);
-                    break;
-
-                case 1:
-                case 3:
-                case 5:
-                case 7:
-                    common_vt_4t_4w_msa(src, src_stride, dst, dst_stride,
-                                        v_filter + 1, 4);
-                    break;
-            }
-        }
-    }
-    else
-    {
-        switch (xoffset)
-        {
-            case 0:
-                {
-                uint32_t tp0, tp1, tp2, tp3;
-
-                LW4(src, src_stride, tp0, tp1, tp2, tp3);
-                SW4(tp0, tp1, tp2, tp3, dst, dst_stride);
-                break;
-                }
-            case 2:
-            case 4:
-            case 6:
-                common_hz_6t_4w_msa(src, src_stride, dst, dst_stride,
-                                    h_filter, 4);
-                break;
-
-            case 1:
-            case 3:
-            case 5:
-            case 7:
-                common_hz_4t_4w_msa(src, src_stride, dst, dst_stride,
-                                    h_filter + 1, 4);
-                break;
-        }
-    }
-}
-
-void vp8_sixtap_predict8x4_msa(uint8_t *RESTRICT src, int32_t src_stride,
-                               int32_t xoffset, int32_t yoffset,
-                               uint8_t *RESTRICT dst, int32_t dst_stride)
-{
-    const int8_t *h_filter = vp8_subpel_filters_msa[xoffset - 1];
-    const int8_t *v_filter = vp8_subpel_filters_msa[yoffset - 1];
-
-    if (yoffset)
-    {
-        if (xoffset)
-        {
-            switch (xoffset)
-            {
-                case 2:
-                case 4:
-                case 6:
-                    switch (yoffset)
-                    {
-                        case 2:
-                        case 4:
-                        case 6:
-                            common_hv_6ht_6vt_8w_msa(src, src_stride, dst,
-                                                     dst_stride, h_filter,
-                                                     v_filter, 4);
-                            break;
-
-                        case 1:
-                        case 3:
-                        case 5:
-                        case 7:
-                            common_hv_6ht_4vt_8w_msa(src, src_stride, dst,
-                                                     dst_stride, h_filter,
-                                                     v_filter + 1, 4);
-                            break;
-                    }
-                    break;
-
-                case 1:
-                case 3:
-                case 5:
-                case 7:
-                    switch (yoffset)
-                    {
-                        case 2:
-                        case 4:
-                        case 6:
-                            common_hv_4ht_6vt_8w_msa(src, src_stride, dst,
-                                                     dst_stride, h_filter + 1,
-                                                     v_filter, 4);
-                            break;
-
-                        case 1:
-                        case 3:
-                        case 5:
-                        case 7:
-                            common_hv_4ht_4vt_8w_msa(src, src_stride, dst,
-                                                     dst_stride, h_filter + 1,
-                                                     v_filter + 1, 4);
-                            break;
-                    }
-                    break;
-            }
-        }
-        else
-        {
-            switch (yoffset)
-            {
-                case 2:
-                case 4:
-                case 6:
-                    common_vt_6t_8w_msa(src, src_stride, dst, dst_stride,
-                                        v_filter, 4);
-                    break;
-
-                case 1:
-                case 3:
-                case 5:
-                case 7:
-                    common_vt_4t_8w_msa(src, src_stride, dst, dst_stride,
-                                        v_filter + 1, 4);
-                    break;
-            }
-        }
-    }
-    else
-    {
-        switch (xoffset)
-        {
-            case 0:
-                vp8_copy_mem8x4(src, src_stride, dst, dst_stride);
-                break;
-            case 2:
-            case 4:
-            case 6:
-                common_hz_6t_8w_msa(src, src_stride, dst, dst_stride,
-                                    h_filter, 4);
-                break;
-
-            case 1:
-            case 3:
-            case 5:
-            case 7:
-                common_hz_4t_8w_msa(src, src_stride, dst, dst_stride,
-                                    h_filter + 1, 4);
-                break;
-        }
-    }
-}
-
-void vp8_sixtap_predict8x8_msa(uint8_t *RESTRICT src, int32_t src_stride,
-                               int32_t xoffset, int32_t yoffset,
-                               uint8_t *RESTRICT dst, int32_t dst_stride)
-{
-    const int8_t *h_filter = vp8_subpel_filters_msa[xoffset - 1];
-    const int8_t *v_filter = vp8_subpel_filters_msa[yoffset - 1];
-
-    if (yoffset)
-    {
-        if (xoffset)
-        {
-            switch (xoffset)
-            {
-                case 2:
-                case 4:
-                case 6:
-                    switch (yoffset)
-                    {
-                        case 2:
-                        case 4:
-                        case 6:
-                            common_hv_6ht_6vt_8w_msa(src, src_stride, dst,
-                                                     dst_stride, h_filter,
-                                                     v_filter, 8);
-                            break;
-
-                        case 1:
-                        case 3:
-                        case 5:
-                        case 7:
-                            common_hv_6ht_4vt_8w_msa(src, src_stride, dst,
-                                                     dst_stride, h_filter,
-                                                     v_filter + 1, 8);
-                            break;
-                    }
-                    break;
-
-                case 1:
-                case 3:
-                case 5:
-                case 7:
-                    switch (yoffset)
-                    {
-                        case 2:
-                        case 4:
-                        case 6:
-                            common_hv_4ht_6vt_8w_msa(src, src_stride, dst,
-                                                     dst_stride, h_filter + 1,
-                                                     v_filter, 8);
-                            break;
-
-                        case 1:
-                        case 3:
-                        case 5:
-                        case 7:
-                            common_hv_4ht_4vt_8w_msa(src, src_stride, dst,
-                                                     dst_stride, h_filter + 1,
-                                                     v_filter + 1, 8);
-                            break;
-                    }
-                    break;
-                }
-        }
-        else
-        {
-            switch (yoffset)
-            {
-                case 2:
-                case 4:
-                case 6:
-                    common_vt_6t_8w_msa(src, src_stride, dst, dst_stride,
-                                        v_filter, 8);
-                    break;
-
-                case 1:
-                case 3:
-                case 5:
-                case 7:
-                    common_vt_4t_8w_msa(src, src_stride, dst, dst_stride,
-                                        v_filter + 1, 8);
-                    break;
-            }
-        }
-    }
-    else
-    {
-        switch (xoffset)
-        {
-            case 0:
-                vp8_copy_mem8x8(src, src_stride, dst, dst_stride);
-                break;
-            case 2:
-            case 4:
-            case 6:
-                common_hz_6t_8w_msa(src, src_stride, dst, dst_stride, h_filter,
-                                    8);
-                break;
-
-            case 1:
-            case 3:
-            case 5:
-            case 7:
-                common_hz_4t_8w_msa(src, src_stride, dst, dst_stride,
-                                    h_filter + 1, 8);
-                break;
-        }
-    }
-}
-
-void vp8_sixtap_predict16x16_msa(uint8_t *RESTRICT src, int32_t src_stride,
-                                 int32_t xoffset, int32_t yoffset,
-                                 uint8_t *RESTRICT dst, int32_t dst_stride)
-{
-    const int8_t *h_filter = vp8_subpel_filters_msa[xoffset - 1];
-    const int8_t *v_filter = vp8_subpel_filters_msa[yoffset - 1];
-
-    if (yoffset)
-    {
-        if (xoffset)
-        {
-            switch (xoffset)
-            {
-                case 2:
-                case 4:
-                case 6:
-                    switch (yoffset)
-                    {
-                        case 2:
-                        case 4:
-                        case 6:
-                            common_hv_6ht_6vt_16w_msa(src, src_stride, dst,
-                                                      dst_stride, h_filter,
-                                                      v_filter, 16);
-                            break;
-
-                        case 1:
-                        case 3:
-                        case 5:
-                        case 7:
-                            common_hv_6ht_4vt_16w_msa(src, src_stride, dst,
-                                                      dst_stride, h_filter,
-                                                      v_filter + 1, 16);
-                            break;
-                    }
-                    break;
-
-                case 1:
-                case 3:
-                case 5:
-                case 7:
-                    switch (yoffset)
-                    {
-                        case 2:
-                        case 4:
-                        case 6:
-                            common_hv_4ht_6vt_16w_msa(src, src_stride, dst,
-                                                      dst_stride, h_filter + 1,
-                                                      v_filter, 16);
-                            break;
-
-                        case 1:
-                        case 3:
-                        case 5:
-                        case 7:
-                            common_hv_4ht_4vt_16w_msa(src, src_stride, dst,
-                                                      dst_stride, h_filter + 1,
-                                                      v_filter + 1, 16);
-                            break;
-                    }
-                    break;
-            }
-        }
-        else
-        {
-            switch (yoffset)
-            {
-                case 2:
-                case 4:
-                case 6:
-                    common_vt_6t_16w_msa(src, src_stride, dst, dst_stride,
-                                         v_filter, 16);
-                    break;
-
-                case 1:
-                case 3:
-                case 5:
-                case 7:
-                    common_vt_4t_16w_msa(src, src_stride, dst, dst_stride,
-                                         v_filter + 1, 16);
-                    break;
-            }
-        }
-    }
-    else
-    {
-        switch (xoffset)
-        {
-            case 0:
-                vp8_copy_mem16x16(src, src_stride, dst, dst_stride);
-                break;
-            case 2:
-            case 4:
-            case 6:
-                common_hz_6t_16w_msa(src, src_stride, dst, dst_stride,
-                                     h_filter, 16);
-                break;
-
-            case 1:
-            case 3:
-            case 5:
-            case 7:
-                common_hz_4t_16w_msa(src, src_stride, dst, dst_stride,
-                                     h_filter + 1, 16);
-                break;
-        }
-    }
-}
diff --git a/vp8/common/mips/msa/vp8_macros_msa.h b/vp8/common/mips/msa/vp8_macros_msa.h
deleted file mode 100644 (file)
index 27d5929..0000000
+++ /dev/null
@@ -1,1783 +0,0 @@
-/*
- *  Copyright (c) 2015 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.
- */
-
-#ifndef VP8_COMMON_MIPS_MSA_VP8_MACROS_MSA_H_
-#define VP8_COMMON_MIPS_MSA_VP8_MACROS_MSA_H_
-
-#include <msa.h>
-
-#include "./vpx_config.h"
-#include "vpx/vpx_integer.h"
-
-#define LD_B(RTYPE, psrc) *((const RTYPE *)(psrc))
-#define LD_UB(...) LD_B(v16u8, __VA_ARGS__)
-#define LD_SB(...) LD_B(v16i8, __VA_ARGS__)
-
-#define LD_H(RTYPE, psrc) *((const RTYPE *)(psrc))
-#define LD_UH(...) LD_H(v8u16, __VA_ARGS__)
-#define LD_SH(...) LD_H(v8i16, __VA_ARGS__)
-
-#define LD_W(RTYPE, psrc) *((const RTYPE *)(psrc))
-#define LD_UW(...) LD_W(v4u32, __VA_ARGS__)
-#define LD_SW(...) LD_W(v4i32, __VA_ARGS__)
-
-#define ST_B(RTYPE, in, pdst) *((RTYPE *)(pdst)) = (in)
-#define ST_UB(...) ST_B(v16u8, __VA_ARGS__)
-#define ST_SB(...) ST_B(v16i8, __VA_ARGS__)
-
-#define ST_H(RTYPE, in, pdst) *((RTYPE *)(pdst)) = (in)
-#define ST_UH(...) ST_H(v8u16, __VA_ARGS__)
-#define ST_SH(...) ST_H(v8i16, __VA_ARGS__)
-
-#define ST_W(RTYPE, in, pdst) *((RTYPE *)(pdst)) = (in)
-#define ST_SW(...) ST_W(v4i32, __VA_ARGS__)
-
-#if (__mips_isa_rev >= 6)
-#define LW(psrc)                                      \
-({                                                    \
-    const uint8_t *psrc_m = (const uint8_t *)(psrc);  \
-    uint32_t val_m;                                   \
-                                                      \
-    asm volatile (                                    \
-        "lw  %[val_m],  %[psrc_m]  \n\t"              \
-                                                      \
-        : [val_m] "=r" (val_m)                        \
-        : [psrc_m] "m" (*psrc_m)                      \
-    );                                                \
-                                                      \
-    val_m;                                            \
-})
-
-#if (__mips == 64)
-#define LD(psrc)                                      \
-({                                                    \
-    const uint8_t *psrc_m = (const uint8_t *)(psrc);  \
-    uint64_t val_m = 0;                               \
-                                                      \
-    asm volatile (                                    \
-        "ld  %[val_m],  %[psrc_m]  \n\t"              \
-                                                      \
-        : [val_m] "=r" (val_m)                        \
-        : [psrc_m] "m" (*psrc_m)                      \
-    );                                                \
-                                                      \
-    val_m;                                            \
-})
-#else  // !(__mips == 64)
-#define LD(psrc)                                             \
-({                                                           \
-    const uint8_t *psrc_m = (const uint8_t *)(psrc);         \
-    uint32_t val0_m, val1_m;                                 \
-    uint64_t val_m = 0;                                      \
-                                                             \
-    val0_m = LW(psrc_m);                                     \
-    val1_m = LW(psrc_m + 4);                                 \
-                                                             \
-    val_m = (uint64_t)(val1_m);                              \
-    val_m = (uint64_t)((val_m << 32) & 0xFFFFFFFF00000000);  \
-    val_m = (uint64_t)(val_m | (uint64_t)val0_m);            \
-                                                             \
-    val_m;                                                   \
-})
-#endif  // (__mips == 64)
-
-#define SH(val, pdst)                     \
-{                                         \
-    uint8_t *pdst_m = (uint8_t *)(pdst);  \
-    const uint16_t val_m = (val);         \
-                                          \
-    asm volatile (                        \
-        "sh  %[val_m],  %[pdst_m]  \n\t"  \
-                                          \
-        : [pdst_m] "=m" (*pdst_m)         \
-        : [val_m] "r" (val_m)             \
-    );                                    \
-}
-
-#define SW(val, pdst)                     \
-{                                         \
-    uint8_t *pdst_m = (uint8_t *)(pdst);  \
-    const uint32_t val_m = (val);         \
-                                          \
-    asm volatile (                        \
-        "sw  %[val_m],  %[pdst_m]  \n\t"  \
-                                          \
-        : [pdst_m] "=m" (*pdst_m)         \
-        : [val_m] "r" (val_m)             \
-    );                                    \
-}
-
-#define SD(val, pdst)                     \
-{                                         \
-    uint8_t *pdst_m = (uint8_t *)(pdst);  \
-    const uint64_t val_m = (val);         \
-                                          \
-    asm volatile (                        \
-        "sd  %[val_m],  %[pdst_m]  \n\t"  \
-                                          \
-        : [pdst_m] "=m" (*pdst_m)         \
-        : [val_m] "r" (val_m)             \
-    );                                    \
-}
-#else  // !(__mips_isa_rev >= 6)
-#define LW(psrc)                                      \
-({                                                    \
-    const uint8_t *psrc_m = (const uint8_t *)(psrc);  \
-    uint32_t val_m;                                   \
-                                                      \
-    asm volatile (                                    \
-        "ulw  %[val_m],  %[psrc_m]  \n\t"             \
-                                                      \
-        : [val_m] "=r" (val_m)                        \
-        : [psrc_m] "m" (*psrc_m)                      \
-    );                                                \
-                                                      \
-    val_m;                                            \
-})
-
-#if (__mips == 64)
-#define LD(psrc)                                      \
-({                                                    \
-    const uint8_t *psrc_m = (const uint8_t *)(psrc);  \
-    uint64_t val_m = 0;                               \
-                                                      \
-    asm volatile (                                    \
-        "uld  %[val_m],  %[psrc_m]  \n\t"             \
-                                                      \
-        : [val_m] "=r" (val_m)                        \
-        : [psrc_m] "m" (*psrc_m)                      \
-    );                                                \
-                                                      \
-    val_m;                                            \
-})
-#else  // !(__mips == 64)
-#define LD(psrc)                                             \
-({                                                           \
-    const uint8_t *psrc_m1 = (const uint8_t *)(psrc);        \
-    uint32_t val0_m, val1_m;                                 \
-    uint64_t val_m = 0;                                      \
-                                                             \
-    val0_m = LW(psrc_m1);                                    \
-    val1_m = LW(psrc_m1 + 4);                                \
-                                                             \
-    val_m = (uint64_t)(val1_m);                              \
-    val_m = (uint64_t)((val_m << 32) & 0xFFFFFFFF00000000);  \
-    val_m = (uint64_t)(val_m | (uint64_t)val0_m);            \
-                                                             \
-    val_m;                                                   \
-})
-#endif  // (__mips == 64)
-#define SH(val, pdst)                      \
-{                                          \
-    uint8_t *pdst_m = (uint8_t *)(pdst);   \
-    const uint16_t val_m = (val);          \
-                                           \
-    asm volatile (                         \
-        "ush  %[val_m],  %[pdst_m]  \n\t"  \
-                                           \
-        : [pdst_m] "=m" (*pdst_m)          \
-        : [val_m] "r" (val_m)              \
-    );                                     \
-}
-
-#define SW(val, pdst)                      \
-{                                          \
-    uint8_t *pdst_m = (uint8_t *)(pdst);   \
-    const uint32_t val_m = (val);          \
-                                           \
-    asm volatile (                         \
-        "usw  %[val_m],  %[pdst_m]  \n\t"  \
-                                           \
-        : [pdst_m] "=m" (*pdst_m)          \
-        : [val_m] "r" (val_m)              \
-    );                                     \
-}
-
-#define SD(val, pdst)                                         \
-{                                                             \
-    uint8_t *pdst_m1 = (uint8_t *)(pdst);                     \
-    uint32_t val0_m, val1_m;                                  \
-                                                              \
-    val0_m = (uint32_t)((val) & 0x00000000FFFFFFFF);          \
-    val1_m = (uint32_t)(((val) >> 32) & 0x00000000FFFFFFFF);  \
-                                                              \
-    SW(val0_m, pdst_m1);                                      \
-    SW(val1_m, pdst_m1 + 4);                                  \
-}
-#endif  // (__mips_isa_rev >= 6)
-
-/* Description : Load 4 words with stride
-   Arguments   : Inputs  - psrc, stride
-                 Outputs - out0, out1, out2, out3
-   Details     : Load word in 'out0' from (psrc)
-                 Load word in 'out1' from (psrc + stride)
-                 Load word in 'out2' from (psrc + 2 * stride)
-                 Load word in 'out3' from (psrc + 3 * stride)
-*/
-#define LW4(psrc, stride, out0, out1, out2, out3)  \
-{                                                  \
-    out0 = LW((psrc));                             \
-    out1 = LW((psrc) + stride);                    \
-    out2 = LW((psrc) + 2 * stride);                \
-    out3 = LW((psrc) + 3 * stride);                \
-}
-
-/* Description : Load double words with stride
-   Arguments   : Inputs  - psrc, stride
-                 Outputs - out0, out1
-   Details     : Load double word in 'out0' from (psrc)
-                 Load double word in 'out1' from (psrc + stride)
-*/
-#define LD2(psrc, stride, out0, out1)  \
-{                                      \
-    out0 = LD((psrc));                 \
-    out1 = LD((psrc) + stride);        \
-}
-#define LD4(psrc, stride, out0, out1, out2, out3)  \
-{                                                  \
-    LD2((psrc), stride, out0, out1);               \
-    LD2((psrc) + 2 * stride, stride, out2, out3);  \
-}
-
-/* Description : Store 4 words with stride
-   Arguments   : Inputs - in0, in1, in2, in3, pdst, stride
-   Details     : Store word from 'in0' to (pdst)
-                 Store word from 'in1' to (pdst + stride)
-                 Store word from 'in2' to (pdst + 2 * stride)
-                 Store word from 'in3' to (pdst + 3 * stride)
-*/
-#define SW4(in0, in1, in2, in3, pdst, stride)  \
-{                                              \
-    SW(in0, (pdst));                           \
-    SW(in1, (pdst) + stride);                  \
-    SW(in2, (pdst) + 2 * stride);              \
-    SW(in3, (pdst) + 3 * stride);              \
-}
-
-/* Description : Store 4 double words with stride
-   Arguments   : Inputs - in0, in1, in2, in3, pdst, stride
-   Details     : Store double word from 'in0' to (pdst)
-                 Store double word from 'in1' to (pdst + stride)
-                 Store double word from 'in2' to (pdst + 2 * stride)
-                 Store double word from 'in3' to (pdst + 3 * stride)
-*/
-#define SD4(in0, in1, in2, in3, pdst, stride)  \
-{                                              \
-    SD(in0, (pdst));                           \
-    SD(in1, (pdst) + stride);                  \
-    SD(in2, (pdst) + 2 * stride);              \
-    SD(in3, (pdst) + 3 * stride);              \
-}
-
-/* Description : Load vectors with 16 byte elements with stride
-   Arguments   : Inputs  - psrc, stride
-                 Outputs - out0, out1
-                 Return Type - as per RTYPE
-   Details     : Load 16 byte elements in 'out0' from (psrc)
-                 Load 16 byte elements in 'out1' from (psrc + stride)
-*/
-#define LD_B2(RTYPE, psrc, stride, out0, out1)  \
-{                                               \
-    out0 = LD_B(RTYPE, (psrc));                 \
-    out1 = LD_B(RTYPE, (psrc) + stride);        \
-}
-#define LD_UB2(...) LD_B2(v16u8, __VA_ARGS__)
-#define LD_SB2(...) LD_B2(v16i8, __VA_ARGS__)
-
-#define LD_B3(RTYPE, psrc, stride, out0, out1, out2)  \
-{                                                     \
-    LD_B2(RTYPE, (psrc), stride, out0, out1);         \
-    out2 = LD_B(RTYPE, (psrc) + 2 * stride);          \
-}
-#define LD_UB3(...) LD_B3(v16u8, __VA_ARGS__)
-#define LD_SB3(...) LD_B3(v16i8, __VA_ARGS__)
-
-#define LD_B4(RTYPE, psrc, stride, out0, out1, out2, out3)   \
-{                                                            \
-    LD_B2(RTYPE, (psrc), stride, out0, out1);                \
-    LD_B2(RTYPE, (psrc) + 2 * stride , stride, out2, out3);  \
-}
-#define LD_UB4(...) LD_B4(v16u8, __VA_ARGS__)
-#define LD_SB4(...) LD_B4(v16i8, __VA_ARGS__)
-
-#define LD_B5(RTYPE, psrc, stride, out0, out1, out2, out3, out4)  \
-{                                                                 \
-    LD_B4(RTYPE, (psrc), stride, out0, out1, out2, out3);         \
-    out4 = LD_B(RTYPE, (psrc) + 4 * stride);                      \
-}
-#define LD_UB5(...) LD_B5(v16u8, __VA_ARGS__)
-#define LD_SB5(...) LD_B5(v16i8, __VA_ARGS__)
-
-#define LD_B8(RTYPE, psrc, stride,                                      \
-              out0, out1, out2, out3, out4, out5, out6, out7)           \
-{                                                                       \
-    LD_B4(RTYPE, (psrc), stride, out0, out1, out2, out3);               \
-    LD_B4(RTYPE, (psrc) + 4 * stride, stride, out4, out5, out6, out7);  \
-}
-#define LD_UB8(...) LD_B8(v16u8, __VA_ARGS__)
-#define LD_SB8(...) LD_B8(v16i8, __VA_ARGS__)
-
-/* Description : Load vectors with 8 halfword elements with stride
-   Arguments   : Inputs  - psrc, stride
-                 Outputs - out0, out1
-   Details     : Load 8 halfword elements in 'out0' from (psrc)
-                 Load 8 halfword elements in 'out1' from (psrc + stride)
-*/
-#define LD_H2(RTYPE, psrc, stride, out0, out1)  \
-{                                               \
-    out0 = LD_H(RTYPE, (psrc));                 \
-    out1 = LD_H(RTYPE, (psrc) + (stride));      \
-}
-#define LD_SH2(...) LD_H2(v8i16, __VA_ARGS__)
-
-#define LD_H4(RTYPE, psrc, stride, out0, out1, out2, out3)  \
-{                                                           \
-    LD_H2(RTYPE, (psrc), stride, out0, out1);               \
-    LD_H2(RTYPE, (psrc) + 2 * stride, stride, out2, out3);  \
-}
-#define LD_SH4(...) LD_H4(v8i16, __VA_ARGS__)
-
-/* Description : Load 2 vectors of signed word elements with stride
-   Arguments   : Inputs  - psrc, stride
-                 Outputs - out0, out1
-                 Return Type - signed word
-*/
-#define LD_SW2(psrc, stride, out0, out1)  \
-{                                         \
-    out0 = LD_SW((psrc));                 \
-    out1 = LD_SW((psrc) + stride);        \
-}
-
-/* Description : Store vectors of 16 byte elements with stride
-   Arguments   : Inputs - in0, in1, pdst, stride
-   Details     : Store 16 byte elements from 'in0' to (pdst)
-                 Store 16 byte elements from 'in1' to (pdst + stride)
-*/
-#define ST_B2(RTYPE, in0, in1, pdst, stride)  \
-{                                             \
-    ST_B(RTYPE, in0, (pdst));                 \
-    ST_B(RTYPE, in1, (pdst) + stride);        \
-}
-#define ST_UB2(...) ST_B2(v16u8, __VA_ARGS__)
-
-#define ST_B4(RTYPE, in0, in1, in2, in3, pdst, stride)    \
-{                                                         \
-    ST_B2(RTYPE, in0, in1, (pdst), stride);               \
-    ST_B2(RTYPE, in2, in3, (pdst) + 2 * stride, stride);  \
-}
-#define ST_UB4(...) ST_B4(v16u8, __VA_ARGS__)
-#define ST_SB4(...) ST_B4(v16i8, __VA_ARGS__)
-
-#define ST_B8(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7,        \
-              pdst, stride)                                         \
-{                                                                   \
-    ST_B4(RTYPE, in0, in1, in2, in3, pdst, stride);                 \
-    ST_B4(RTYPE, in4, in5, in6, in7, (pdst) + 4 * stride, stride);  \
-}
-#define ST_UB8(...) ST_B8(v16u8, __VA_ARGS__)
-
-/* Description : Store vectors of 8 halfword elements with stride
-   Arguments   : Inputs - in0, in1, pdst, stride
-   Details     : Store 8 halfword elements from 'in0' to (pdst)
-                 Store 8 halfword elements from 'in1' to (pdst + stride)
-*/
-#define ST_H2(RTYPE, in0, in1, pdst, stride)  \
-{                                             \
-    ST_H(RTYPE, in0, (pdst));                 \
-    ST_H(RTYPE, in1, (pdst) + stride);        \
-}
-#define ST_SH2(...) ST_H2(v8i16, __VA_ARGS__)
-
-/* Description : Store vectors of word elements with stride
-   Arguments   : Inputs - in0, in1, pdst, stride
-   Details     : Store 4 word elements from 'in0' to (pdst)
-                 Store 4 word elements from 'in1' to (pdst + stride)
-*/
-#define ST_SW2(in0, in1, pdst, stride)  \
-{                                       \
-    ST_SW(in0, (pdst));                 \
-    ST_SW(in1, (pdst) + stride);        \
-}
-
-/* Description : Store 2x4 byte block to destination memory from input vector
-   Arguments   : Inputs - in, stidx, pdst, stride
-   Details     : Index 'stidx' halfword element from 'in' vector is copied to
-                 the GP register and stored to (pdst)
-                 Index 'stidx+1' halfword element from 'in' vector is copied to
-                 the GP register and stored to (pdst + stride)
-                 Index 'stidx+2' halfword element from 'in' vector is copied to
-                 the GP register and stored to (pdst + 2 * stride)
-                 Index 'stidx+3' halfword element from 'in' vector is copied to
-                 the GP register and stored to (pdst + 3 * stride)
-*/
-#define ST2x4_UB(in, stidx, pdst, stride)             \
-{                                                     \
-    uint16_t out0_m, out1_m, out2_m, out3_m;          \
-    uint8_t *pblk_2x4_m = (uint8_t *)(pdst);          \
-                                                      \
-    out0_m = __msa_copy_u_h((v8i16)in, (stidx));      \
-    out1_m = __msa_copy_u_h((v8i16)in, (stidx + 1));  \
-    out2_m = __msa_copy_u_h((v8i16)in, (stidx + 2));  \
-    out3_m = __msa_copy_u_h((v8i16)in, (stidx + 3));  \
-                                                      \
-    SH(out0_m, pblk_2x4_m);                           \
-    SH(out1_m, pblk_2x4_m + stride);                  \
-    SH(out2_m, pblk_2x4_m + 2 * stride);              \
-    SH(out3_m, pblk_2x4_m + 3 * stride);              \
-}
-
-/* Description : Store 4x4 byte block to destination memory from input vector
-   Arguments   : Inputs - in0, in1, pdst, stride
-   Details     : 'Idx0' word element from input vector 'in0' is copied to the
-                 GP register and stored to (pdst)
-                 'Idx1' word element from input vector 'in0' is copied to the
-                 GP register and stored to (pdst + stride)
-                 'Idx2' word element from input vector 'in0' is copied to the
-                 GP register and stored to (pdst + 2 * stride)
-                 'Idx3' word element from input vector 'in0' is copied to the
-                 GP register and stored to (pdst + 3 * stride)
-*/
-#define ST4x4_UB(in0, in1, idx0, idx1, idx2, idx3, pdst, stride)  \
-{                                                                 \
-    uint32_t out0_m, out1_m, out2_m, out3_m;                      \
-    uint8_t *pblk_4x4_m = (uint8_t *)(pdst);                      \
-                                                                  \
-    out0_m = __msa_copy_u_w((v4i32)in0, idx0);                    \
-    out1_m = __msa_copy_u_w((v4i32)in0, idx1);                    \
-    out2_m = __msa_copy_u_w((v4i32)in1, idx2);                    \
-    out3_m = __msa_copy_u_w((v4i32)in1, idx3);                    \
-                                                                  \
-    SW4(out0_m, out1_m, out2_m, out3_m, pblk_4x4_m, stride);      \
-}
-#define ST4x8_UB(in0, in1, pdst, stride)                            \
-{                                                                   \
-    uint8_t *pblk_4x8 = (uint8_t *)(pdst);                          \
-                                                                    \
-    ST4x4_UB(in0, in0, 0, 1, 2, 3, pblk_4x8, stride);               \
-    ST4x4_UB(in1, in1, 0, 1, 2, 3, pblk_4x8 + 4 * stride, stride);  \
-}
-
-/* Description : Store 8x1 byte block to destination memory from input vector
-   Arguments   : Inputs - in, pdst
-   Details     : Index 0 double word element from 'in' vector is copied to the
-                 GP register and stored to (pdst)
-*/
-#define ST8x1_UB(in, pdst)                  \
-{                                           \
-    uint64_t out0_m;                        \
-                                            \
-    out0_m = __msa_copy_u_d((v2i64)in, 0);  \
-    SD(out0_m, pdst);                       \
-}
-
-/* Description : Store 8x2 byte block to destination memory from input vector
-   Arguments   : Inputs - in, pdst, stride
-   Details     : Index 0 double word element from 'in' vector is copied to the
-                 GP register and stored to (pdst)
-                 Index 1 double word element from 'in' vector is copied to the
-                 GP register and stored to (pdst + stride)
-*/
-#define ST8x2_UB(in, pdst, stride)            \
-{                                             \
-    uint64_t out0_m, out1_m;                  \
-    uint8_t *pblk_8x2_m = (uint8_t *)(pdst);  \
-                                              \
-    out0_m = __msa_copy_u_d((v2i64)in, 0);    \
-    out1_m = __msa_copy_u_d((v2i64)in, 1);    \
-                                              \
-    SD(out0_m, pblk_8x2_m);                   \
-    SD(out1_m, pblk_8x2_m + stride);          \
-}
-
-/* Description : Store 8x4 byte block to destination memory from input
-                 vectors
-   Arguments   : Inputs - in0, in1, pdst, stride
-   Details     : Index 0 double word element from 'in0' vector is copied to the
-                 GP register and stored to (pdst)
-                 Index 1 double word element from 'in0' vector is copied to the
-                 GP register and stored to (pdst + stride)
-                 Index 0 double word element from 'in1' vector is copied to the
-                 GP register and stored to (pdst + 2 * stride)
-                 Index 1 double word element from 'in1' vector is copied to the
-                 GP register and stored to (pdst + 3 * stride)
-*/
-#define ST8x4_UB(in0, in1, pdst, stride)                      \
-{                                                             \
-    uint64_t out0_m, out1_m, out2_m, out3_m;                  \
-    uint8_t *pblk_8x4_m = (uint8_t *)(pdst);                  \
-                                                              \
-    out0_m = __msa_copy_u_d((v2i64)in0, 0);                   \
-    out1_m = __msa_copy_u_d((v2i64)in0, 1);                   \
-    out2_m = __msa_copy_u_d((v2i64)in1, 0);                   \
-    out3_m = __msa_copy_u_d((v2i64)in1, 1);                   \
-                                                              \
-    SD4(out0_m, out1_m, out2_m, out3_m, pblk_8x4_m, stride);  \
-}
-
-/* Description : Immediate number of elements to slide with zero
-   Arguments   : Inputs  - in0, in1, slide_val
-                 Outputs - out0, out1
-                 Return Type - as per RTYPE
-   Details     : Byte elements from 'zero_m' vector are slid into 'in0' by
-                 value specified in the 'slide_val'
-*/
-#define SLDI_B2_0(RTYPE, in0, in1, out0, out1, slide_val)              \
-{                                                                      \
-    v16i8 zero_m = { 0 };                                              \
-                                                                       \
-    out0 = (RTYPE)__msa_sldi_b((v16i8)zero_m, (v16i8)in0, slide_val);  \
-    out1 = (RTYPE)__msa_sldi_b((v16i8)zero_m, (v16i8)in1, slide_val);  \
-}
-#define SLDI_B2_0_UB(...) SLDI_B2_0(v16u8, __VA_ARGS__)
-
-/* Description : Immediate number of elements to slide
-   Arguments   : Inputs  - in0_0, in0_1, in1_0, in1_1, slide_val
-                 Outputs - out0, out1
-                 Return Type - as per RTYPE
-   Details     : Byte elements from 'in0_0' vector are slid into 'in1_0' by
-                 value specified in the 'slide_val'
-*/
-#define SLDI_B2(RTYPE, in0_0, in0_1, in1_0, in1_1, out0, out1, slide_val)  \
-{                                                                          \
-    out0 = (RTYPE)__msa_sldi_b((v16i8)in0_0, (v16i8)in1_0, slide_val);     \
-    out1 = (RTYPE)__msa_sldi_b((v16i8)in0_1, (v16i8)in1_1, slide_val);     \
-}
-
-#define SLDI_B3(RTYPE, in0_0, in0_1, in0_2, in1_0, in1_1, in1_2,        \
-                out0, out1, out2, slide_val)                            \
-{                                                                       \
-    SLDI_B2(RTYPE, in0_0, in0_1, in1_0, in1_1, out0, out1, slide_val);  \
-    out2 = (RTYPE)__msa_sldi_b((v16i8)in0_2, (v16i8)in1_2, slide_val);  \
-}
-#define SLDI_B3_UH(...) SLDI_B3(v8u16, __VA_ARGS__)
-
-/* Description : Shuffle byte vector elements as per mask vector
-   Arguments   : Inputs  - in0, in1, in2, in3, mask0, mask1
-                 Outputs - out0, out1
-                 Return Type - as per RTYPE
-   Details     : Byte elements from 'in0' & 'in1' are copied selectively to
-                 'out0' as per control vector 'mask0'
-*/
-#define VSHF_B2(RTYPE, in0, in1, in2, in3, mask0, mask1, out0, out1)   \
-{                                                                      \
-    out0 = (RTYPE)__msa_vshf_b((v16i8)mask0, (v16i8)in1, (v16i8)in0);  \
-    out1 = (RTYPE)__msa_vshf_b((v16i8)mask1, (v16i8)in3, (v16i8)in2);  \
-}
-#define VSHF_B2_UB(...) VSHF_B2(v16u8, __VA_ARGS__)
-#define VSHF_B2_SB(...) VSHF_B2(v16i8, __VA_ARGS__)
-#define VSHF_B2_UH(...) VSHF_B2(v8u16, __VA_ARGS__)
-
-#define VSHF_B3(RTYPE, in0, in1, in2, in3, in4, in5, mask0, mask1, mask2,  \
-                out0, out1, out2)                                          \
-{                                                                          \
-    VSHF_B2(RTYPE, in0, in1, in2, in3, mask0, mask1, out0, out1);          \
-    out2 = (RTYPE)__msa_vshf_b((v16i8)mask2, (v16i8)in5, (v16i8)in4);      \
-}
-#define VSHF_B3_SB(...) VSHF_B3(v16i8, __VA_ARGS__)
-
-/* Description : Shuffle halfword vector elements as per mask vector
-   Arguments   : Inputs  - in0, in1, in2, in3, mask0, mask1
-                 Outputs - out0, out1
-                 Return Type - as per RTYPE
-   Details     : halfword elements from 'in0' & 'in1' are copied selectively to
-                 'out0' as per control vector 'mask0'
-*/
-#define VSHF_H2(RTYPE, in0, in1, in2, in3, mask0, mask1, out0, out1)   \
-{                                                                      \
-    out0 = (RTYPE)__msa_vshf_h((v8i16)mask0, (v8i16)in1, (v8i16)in0);  \
-    out1 = (RTYPE)__msa_vshf_h((v8i16)mask1, (v8i16)in3, (v8i16)in2);  \
-}
-#define VSHF_H2_SH(...) VSHF_H2(v8i16, __VA_ARGS__)
-
-/* Description : Dot product of byte vector elements
-   Arguments   : Inputs  - mult0, mult1, cnst0, cnst1
-                 Outputs - out0, out1
-                 Return Type - as per RTYPE
-   Details     : Unsigned byte elements from 'mult0' are multiplied with
-                 unsigned byte elements from 'cnst0' producing a result
-                 twice the size of input i.e. unsigned halfword.
-                 The multiplication result of adjacent odd-even elements
-                 are added together and written to the 'out0' vector
-*/
-#define DOTP_UB2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1)  \
-{                                                                \
-    out0 = (RTYPE)__msa_dotp_u_h((v16u8)mult0, (v16u8)cnst0);    \
-    out1 = (RTYPE)__msa_dotp_u_h((v16u8)mult1, (v16u8)cnst1);    \
-}
-#define DOTP_UB2_UH(...) DOTP_UB2(v8u16, __VA_ARGS__)
-
-#define DOTP_UB4(RTYPE, mult0, mult1, mult2, mult3,           \
-                 cnst0, cnst1, cnst2, cnst3,                  \
-                 out0, out1, out2, out3)                      \
-{                                                             \
-    DOTP_UB2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1);  \
-    DOTP_UB2(RTYPE, mult2, mult3, cnst2, cnst3, out2, out3);  \
-}
-#define DOTP_UB4_UH(...) DOTP_UB4(v8u16, __VA_ARGS__)
-
-/* Description : Dot product of byte vector elements
-   Arguments   : Inputs  - mult0, mult1, cnst0, cnst1
-                 Outputs - out0, out1
-                 Return Type - as per RTYPE
-   Details     : Signed byte elements from 'mult0' are multiplied with
-                 signed byte elements from 'cnst0' producing a result
-                 twice the size of input i.e. signed halfword.
-                 The multiplication result of adjacent odd-even elements
-                 are added together and written to the 'out0' vector
-*/
-#define DOTP_SB2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1)  \
-{                                                                \
-    out0 = (RTYPE)__msa_dotp_s_h((v16i8)mult0, (v16i8)cnst0);    \
-    out1 = (RTYPE)__msa_dotp_s_h((v16i8)mult1, (v16i8)cnst1);    \
-}
-#define DOTP_SB2_SH(...) DOTP_SB2(v8i16, __VA_ARGS__)
-
-#define DOTP_SB4(RTYPE, mult0, mult1, mult2, mult3,                   \
-                 cnst0, cnst1, cnst2, cnst3, out0, out1, out2, out3)  \
-{                                                                     \
-    DOTP_SB2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1);          \
-    DOTP_SB2(RTYPE, mult2, mult3, cnst2, cnst3, out2, out3);          \
-}
-#define DOTP_SB4_SH(...) DOTP_SB4(v8i16, __VA_ARGS__)
-
-/* Description : Dot product of halfword vector elements
-   Arguments   : Inputs  - mult0, mult1, cnst0, cnst1
-                 Outputs - out0, out1
-                 Return Type - as per RTYPE
-   Details     : Signed halfword elements from 'mult0' are multiplied with
-                 signed halfword elements from 'cnst0' producing a result
-                 twice the size of input i.e. signed word.
-                 The multiplication result of adjacent odd-even elements
-                 are added together and written to the 'out0' vector
-*/
-#define DOTP_SH2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1)  \
-{                                                                \
-    out0 = (RTYPE)__msa_dotp_s_w((v8i16)mult0, (v8i16)cnst0);    \
-    out1 = (RTYPE)__msa_dotp_s_w((v8i16)mult1, (v8i16)cnst1);    \
-}
-
-#define DOTP_SH4(RTYPE, mult0, mult1, mult2, mult3,           \
-                 cnst0, cnst1, cnst2, cnst3,                  \
-                 out0, out1, out2, out3)                      \
-{                                                             \
-    DOTP_SH2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1);  \
-    DOTP_SH2(RTYPE, mult2, mult3, cnst2, cnst3, out2, out3);  \
-}
-#define DOTP_SH4_SW(...) DOTP_SH4(v4i32, __VA_ARGS__)
-
-/* Description : Dot product of word vector elements
-   Arguments   : Inputs  - mult0, mult1, cnst0, cnst1
-                 Outputs - out0, out1
-                 Return Type - as per RTYPE
-   Details     : Signed word elements from 'mult0' are multiplied with
-                 signed word elements from 'cnst0' producing a result
-                 twice the size of input i.e. signed double word.
-                 The multiplication result of adjacent odd-even elements
-                 are added together and written to the 'out0' vector
-*/
-#define DOTP_SW2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1)  \
-{                                                                \
-    out0 = (RTYPE)__msa_dotp_s_d((v4i32)mult0, (v4i32)cnst0);    \
-    out1 = (RTYPE)__msa_dotp_s_d((v4i32)mult1, (v4i32)cnst1);    \
-}
-#define DOTP_SW2_SD(...) DOTP_SW2(v2i64, __VA_ARGS__)
-
-/* Description : Dot product & addition of byte vector elements
-   Arguments   : Inputs  - mult0, mult1, cnst0, cnst1
-                 Outputs - out0, out1
-                 Return Type - as per RTYPE
-   Details     : Signed byte elements from 'mult0' are multiplied with
-                 signed byte elements from 'cnst0' producing a result
-                 twice the size of input i.e. signed halfword.
-                 The multiplication result of adjacent odd-even elements
-                 are added to the 'out0' vector
-*/
-#define DPADD_SB2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1)             \
-{                                                                            \
-    out0 = (RTYPE)__msa_dpadd_s_h((v8i16)out0, (v16i8)mult0, (v16i8)cnst0);  \
-    out1 = (RTYPE)__msa_dpadd_s_h((v8i16)out1, (v16i8)mult1, (v16i8)cnst1);  \
-}
-#define DPADD_SB2_SH(...) DPADD_SB2(v8i16, __VA_ARGS__)
-
-#define DPADD_SB4(RTYPE, mult0, mult1, mult2, mult3,                   \
-                  cnst0, cnst1, cnst2, cnst3, out0, out1, out2, out3)  \
-{                                                                      \
-    DPADD_SB2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1);          \
-    DPADD_SB2(RTYPE, mult2, mult3, cnst2, cnst3, out2, out3);          \
-}
-#define DPADD_SB4_SH(...) DPADD_SB4(v8i16, __VA_ARGS__)
-
-/* Description : Dot product & addition of halfword vector elements
-   Arguments   : Inputs  - mult0, mult1, cnst0, cnst1
-                 Outputs - out0, out1
-                 Return Type - as per RTYPE
-   Details     : Signed halfword elements from 'mult0' are multiplied with
-                 signed halfword elements from 'cnst0' producing a result
-                 twice the size of input i.e. signed word.
-                 The multiplication result of adjacent odd-even elements
-                 are added to the 'out0' vector
-*/
-#define DPADD_SH2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1)             \
-{                                                                            \
-    out0 = (RTYPE)__msa_dpadd_s_w((v4i32)out0, (v8i16)mult0, (v8i16)cnst0);  \
-    out1 = (RTYPE)__msa_dpadd_s_w((v4i32)out1, (v8i16)mult1, (v8i16)cnst1);  \
-}
-#define DPADD_SH2_SW(...) DPADD_SH2(v4i32, __VA_ARGS__)
-
-#define DPADD_SH4(RTYPE, mult0, mult1, mult2, mult3,                   \
-                  cnst0, cnst1, cnst2, cnst3, out0, out1, out2, out3)  \
-{                                                                      \
-    DPADD_SH2(RTYPE, mult0, mult1, cnst0, cnst1, out0, out1);          \
-    DPADD_SH2(RTYPE, mult2, mult3, cnst2, cnst3, out2, out3);          \
-}
-#define DPADD_SH4_SW(...) DPADD_SH4(v4i32, __VA_ARGS__)
-
-/* Description : Dot product & addition of double word vector elements
-   Arguments   : Inputs  - mult0, mult1
-                 Outputs - out0, out1
-                 Return Type - as per RTYPE
-   Details     : Each signed word element from 'mult0' is multiplied with itself
-                 producing an intermediate result twice the size of it
-                 i.e. signed double word
-                 The multiplication result of adjacent odd-even elements
-                 are added to the 'out0' vector
-*/
-#define DPADD_SD2(RTYPE, mult0, mult1, out0, out1)                           \
-{                                                                            \
-    out0 = (RTYPE)__msa_dpadd_s_d((v2i64)out0, (v4i32)mult0, (v4i32)mult0);  \
-    out1 = (RTYPE)__msa_dpadd_s_d((v2i64)out1, (v4i32)mult1, (v4i32)mult1);  \
-}
-#define DPADD_SD2_SD(...) DPADD_SD2(v2i64, __VA_ARGS__)
-
-/* Description : Clips all signed halfword elements of input vector
-                 between 0 & 255
-   Arguments   : Input  - in
-                 Output - out_m
-                 Return Type - signed halfword
-*/
-#define CLIP_SH_0_255(in)                               \
-({                                                      \
-    v8i16 max_m = __msa_ldi_h(255);                     \
-    v8i16 out_m;                                        \
-                                                        \
-    out_m = __msa_maxi_s_h((v8i16)in, 0);               \
-    out_m = __msa_min_s_h((v8i16)max_m, (v8i16)out_m);  \
-    out_m;                                              \
-})
-#define CLIP_SH2_0_255(in0, in1)  \
-{                                 \
-    in0 = CLIP_SH_0_255(in0);     \
-    in1 = CLIP_SH_0_255(in1);     \
-}
-#define CLIP_SH4_0_255(in0, in1, in2, in3)  \
-{                                           \
-    CLIP_SH2_0_255(in0, in1);               \
-    CLIP_SH2_0_255(in2, in3);               \
-}
-
-/* Description : Clips all signed word elements of input vector
-                 between 0 & 255
-   Arguments   : Input  - in
-                 Output - out_m
-                 Return Type - signed word
-*/
-#define CLIP_SW_0_255(in)                               \
-({                                                      \
-    v4i32 max_m = __msa_ldi_w(255);                     \
-    v4i32 out_m;                                        \
-                                                        \
-    out_m = __msa_maxi_s_w((v4i32)in, 0);               \
-    out_m = __msa_min_s_w((v4i32)max_m, (v4i32)out_m);  \
-    out_m;                                              \
-})
-
-/* Description : Horizontal addition of 4 signed word elements of input vector
-   Arguments   : Input  - in       (signed word vector)
-                 Output - sum_m    (i32 sum)
-                 Return Type - signed word (GP)
-   Details     : 4 signed word elements of 'in' vector are added together and
-                 the resulting integer sum is returned
-*/
-#define HADD_SW_S32(in)                             \
-({                                                  \
-    v2i64 res0_m, res1_m;                           \
-    int32_t sum_m;                                  \
-                                                    \
-    res0_m = __msa_hadd_s_d((v4i32)in, (v4i32)in);  \
-    res1_m = __msa_splati_d(res0_m, 1);             \
-    res0_m = res0_m + res1_m;                       \
-    sum_m = __msa_copy_s_w((v4i32)res0_m, 0);       \
-    sum_m;                                          \
-})
-
-/* Description : Horizontal addition of 8 unsigned halfword elements
-   Arguments   : Inputs  - in       (unsigned halfword vector)
-                 Outputs - sum_m    (u32 sum)
-                 Return Type - unsigned word
-   Details     : 8 unsigned halfword elements of input vector are added
-                 together and the resulting integer sum is returned
-*/
-#define HADD_UH_U32(in)                                \
-({                                                     \
-    v4u32 res_m;                                       \
-    v2u64 res0_m, res1_m;                              \
-    uint32_t sum_m;                                    \
-                                                       \
-    res_m = __msa_hadd_u_w((v8u16)in, (v8u16)in);      \
-    res0_m = __msa_hadd_u_d(res_m, res_m);             \
-    res1_m = (v2u64)__msa_splati_d((v2i64)res0_m, 1);  \
-    res0_m = res0_m + res1_m;                          \
-    sum_m = __msa_copy_u_w((v4i32)res0_m, 0);          \
-    sum_m;                                             \
-})
-
-/* Description : Horizontal addition of unsigned byte vector elements
-   Arguments   : Inputs  - in0, in1
-                 Outputs - out0, out1
-                 Return Type - as per RTYPE
-   Details     : Each unsigned odd byte element from 'in0' is added to
-                 even unsigned byte element from 'in0' (pairwise) and the
-                 halfword result is written to 'out0'
-*/
-#define HADD_UB2(RTYPE, in0, in1, out0, out1)              \
-{                                                          \
-    out0 = (RTYPE)__msa_hadd_u_h((v16u8)in0, (v16u8)in0);  \
-    out1 = (RTYPE)__msa_hadd_u_h((v16u8)in1, (v16u8)in1);  \
-}
-#define HADD_UB2_UH(...) HADD_UB2(v8u16, __VA_ARGS__)
-
-/* Description : Horizontal subtraction of unsigned byte vector elements
-   Arguments   : Inputs  - in0, in1
-                 Outputs - out0, out1
-                 Return Type - as per RTYPE
-   Details     : Each unsigned odd byte element from 'in0' is subtracted from
-                 even unsigned byte element from 'in0' (pairwise) and the
-                 halfword result is written to 'out0'
-*/
-#define HSUB_UB2(RTYPE, in0, in1, out0, out1)              \
-{                                                          \
-    out0 = (RTYPE)__msa_hsub_u_h((v16u8)in0, (v16u8)in0);  \
-    out1 = (RTYPE)__msa_hsub_u_h((v16u8)in1, (v16u8)in1);  \
-}
-#define HSUB_UB2_SH(...) HSUB_UB2(v8i16, __VA_ARGS__)
-
-/* Description : Horizontal subtraction of signed halfword vector elements
-   Arguments   : Inputs  - in0, in1
-                 Outputs - out0, out1
-                 Return Type - as per RTYPE
-   Details     : Each signed odd halfword element from 'in0' is subtracted from
-                 even signed halfword element from 'in0' (pairwise) and the
-                 word result is written to 'out0'
-*/
-#define HSUB_UH2(RTYPE, in0, in1, out0, out1)              \
-{                                                          \
-    out0 = (RTYPE)__msa_hsub_s_w((v8i16)in0, (v8i16)in0);  \
-    out1 = (RTYPE)__msa_hsub_s_w((v8i16)in1, (v8i16)in1);  \
-}
-#define HSUB_UH2_SW(...) HSUB_UH2(v4i32, __VA_ARGS__)
-
-/* Description : Set element n input vector to GPR value
-   Arguments   : Inputs - in0, in1, in2, in3
-                 Output - out
-                 Return Type - as per RTYPE
-   Details     : Set element 0 in vector 'out' to value specified in 'in0'
-*/
-#define INSERT_D2(RTYPE, in0, in1, out)               \
-{                                                     \
-    out = (RTYPE)__msa_insert_d((v2i64)out, 0, in0);  \
-    out = (RTYPE)__msa_insert_d((v2i64)out, 1, in1);  \
-}
-#define INSERT_D2_SB(...) INSERT_D2(v16i8, __VA_ARGS__)
-
-/* Description : Interleave even byte elements from vectors
-   Arguments   : Inputs  - in0, in1, in2, in3
-                 Outputs - out0, out1
-                 Return Type - as per RTYPE
-   Details     : Even byte elements of 'in0' and 'in1' are interleaved
-                 and written to 'out0'
-*/
-#define ILVEV_B2(RTYPE, in0, in1, in2, in3, out0, out1)   \
-{                                                         \
-    out0 = (RTYPE)__msa_ilvev_b((v16i8)in1, (v16i8)in0);  \
-    out1 = (RTYPE)__msa_ilvev_b((v16i8)in3, (v16i8)in2);  \
-}
-#define ILVEV_B2_UB(...) ILVEV_B2(v16u8, __VA_ARGS__)
-#define ILVEV_B2_SH(...) ILVEV_B2(v8i16, __VA_ARGS__)
-#define ILVEV_B2_SD(...) ILVEV_B2(v2i64, __VA_ARGS__)
-
-/* Description : Interleave even halfword elements from vectors
-   Arguments   : Inputs  - in0, in1, in2, in3
-                 Outputs - out0, out1
-                 Return Type - as per RTYPE
-   Details     : Even halfword elements of 'in0' and 'in1' are interleaved
-                 and written to 'out0'
-*/
-#define ILVEV_H2(RTYPE, in0, in1, in2, in3, out0, out1)   \
-{                                                         \
-    out0 = (RTYPE)__msa_ilvev_h((v8i16)in1, (v8i16)in0);  \
-    out1 = (RTYPE)__msa_ilvev_h((v8i16)in3, (v8i16)in2);  \
-}
-#define ILVEV_H2_UB(...) ILVEV_H2(v16u8, __VA_ARGS__)
-#define ILVEV_H2_SH(...) ILVEV_H2(v8i16, __VA_ARGS__)
-
-/* Description : Interleave even word elements from vectors
-   Arguments   : Inputs  - in0, in1, in2, in3
-                 Outputs - out0, out1
-                 Return Type - as per RTYPE
-   Details     : Even word elements of 'in0' and 'in1' are interleaved
-                 and written to 'out0'
-*/
-#define ILVEV_W2(RTYPE, in0, in1, in2, in3, out0, out1)   \
-{                                                         \
-    out0 = (RTYPE)__msa_ilvev_w((v4i32)in1, (v4i32)in0);  \
-    out1 = (RTYPE)__msa_ilvev_w((v4i32)in3, (v4i32)in2);  \
-}
-#define ILVEV_W2_SD(...) ILVEV_W2(v2i64, __VA_ARGS__)
-
-/* Description : Interleave even double word elements from vectors
-   Arguments   : Inputs  - in0, in1, in2, in3
-                 Outputs - out0, out1
-                 Return Type - as per RTYPE
-   Details     : Even double word elements of 'in0' and 'in1' are interleaved
-                 and written to 'out0'
-*/
-#define ILVEV_D2(RTYPE, in0, in1, in2, in3, out0, out1)   \
-{                                                         \
-    out0 = (RTYPE)__msa_ilvev_d((v2i64)in1, (v2i64)in0);  \
-    out1 = (RTYPE)__msa_ilvev_d((v2i64)in3, (v2i64)in2);  \
-}
-#define ILVEV_D2_UB(...) ILVEV_D2(v16u8, __VA_ARGS__)
-
-/* Description : Interleave left half of byte elements from vectors
-   Arguments   : Inputs  - in0, in1, in2, in3
-                 Outputs - out0, out1
-                 Return Type - as per RTYPE
-   Details     : Left half of byte elements of 'in0' and 'in1' are interleaved
-                 and written to 'out0'.
-*/
-#define ILVL_B2(RTYPE, in0, in1, in2, in3, out0, out1)   \
-{                                                        \
-    out0 = (RTYPE)__msa_ilvl_b((v16i8)in0, (v16i8)in1);  \
-    out1 = (RTYPE)__msa_ilvl_b((v16i8)in2, (v16i8)in3);  \
-}
-#define ILVL_B2_UB(...) ILVL_B2(v16u8, __VA_ARGS__)
-#define ILVL_B2_SB(...) ILVL_B2(v16i8, __VA_ARGS__)
-#define ILVL_B2_SH(...) ILVL_B2(v8i16, __VA_ARGS__)
-
-#define ILVL_B4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7,  \
-                out0, out1, out2, out3)                         \
-{                                                               \
-    ILVL_B2(RTYPE, in0, in1, in2, in3, out0, out1);             \
-    ILVL_B2(RTYPE, in4, in5, in6, in7, out2, out3);             \
-}
-#define ILVL_B4_SB(...) ILVL_B4(v16i8, __VA_ARGS__)
-#define ILVL_B4_SH(...) ILVL_B4(v8i16, __VA_ARGS__)
-
-/* Description : Interleave left half of halfword elements from vectors
-   Arguments   : Inputs  - in0, in1, in2, in3
-                 Outputs - out0, out1
-                 Return Type - as per RTYPE
-   Details     : Left half of halfword elements of 'in0' and 'in1' are
-                 interleaved and written to 'out0'.
-*/
-#define ILVL_H2(RTYPE, in0, in1, in2, in3, out0, out1)   \
-{                                                        \
-    out0 = (RTYPE)__msa_ilvl_h((v8i16)in0, (v8i16)in1);  \
-    out1 = (RTYPE)__msa_ilvl_h((v8i16)in2, (v8i16)in3);  \
-}
-#define ILVL_H2_SH(...) ILVL_H2(v8i16, __VA_ARGS__)
-#define ILVL_H2_SW(...) ILVL_H2(v4i32, __VA_ARGS__)
-
-/* Description : Interleave left half of word elements from vectors
-   Arguments   : Inputs  - in0, in1, in2, in3
-                 Outputs - out0, out1
-                 Return Type - as per RTYPE
-   Details     : Left half of word elements of 'in0' and 'in1' are interleaved
-                 and written to 'out0'.
-*/
-#define ILVL_W2(RTYPE, in0, in1, in2, in3, out0, out1)   \
-{                                                        \
-    out0 = (RTYPE)__msa_ilvl_w((v4i32)in0, (v4i32)in1);  \
-    out1 = (RTYPE)__msa_ilvl_w((v4i32)in2, (v4i32)in3);  \
-}
-#define ILVL_W2_SH(...) ILVL_W2(v8i16, __VA_ARGS__)
-
-/* Description : Interleave right half of byte elements from vectors
-   Arguments   : Inputs  - in0, in1, in2, in3
-                 Outputs - out0, out1
-                 Return Type - as per RTYPE
-   Details     : Right half of byte elements of 'in0' and 'in1' are interleaved
-                 and written to out0.
-*/
-#define ILVR_B2(RTYPE, in0, in1, in2, in3, out0, out1)   \
-{                                                        \
-    out0 = (RTYPE)__msa_ilvr_b((v16i8)in0, (v16i8)in1);  \
-    out1 = (RTYPE)__msa_ilvr_b((v16i8)in2, (v16i8)in3);  \
-}
-#define ILVR_B2_UB(...) ILVR_B2(v16u8, __VA_ARGS__)
-#define ILVR_B2_SB(...) ILVR_B2(v16i8, __VA_ARGS__)
-#define ILVR_B2_SH(...) ILVR_B2(v8i16, __VA_ARGS__)
-#define ILVR_B2_SW(...) ILVR_B2(v4i32, __VA_ARGS__)
-
-#define ILVR_B4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7,  \
-                out0, out1, out2, out3)                         \
-{                                                               \
-    ILVR_B2(RTYPE, in0, in1, in2, in3, out0, out1);             \
-    ILVR_B2(RTYPE, in4, in5, in6, in7, out2, out3);             \
-}
-#define ILVR_B4_UB(...) ILVR_B4(v16u8, __VA_ARGS__)
-#define ILVR_B4_SB(...) ILVR_B4(v16i8, __VA_ARGS__)
-#define ILVR_B4_UH(...) ILVR_B4(v8u16, __VA_ARGS__)
-#define ILVR_B4_SH(...) ILVR_B4(v8i16, __VA_ARGS__)
-#define ILVR_B4_SW(...) ILVR_B4(v4i32, __VA_ARGS__)
-
-/* Description : Interleave right half of halfword elements from vectors
-   Arguments   : Inputs  - in0, in1, in2, in3
-                 Outputs - out0, out1
-                 Return Type - as per RTYPE
-   Details     : Right half of halfword elements of 'in0' and 'in1' are
-                 interleaved and written to 'out0'.
-*/
-#define ILVR_H2(RTYPE, in0, in1, in2, in3, out0, out1)   \
-{                                                        \
-    out0 = (RTYPE)__msa_ilvr_h((v8i16)in0, (v8i16)in1);  \
-    out1 = (RTYPE)__msa_ilvr_h((v8i16)in2, (v8i16)in3);  \
-}
-#define ILVR_H2_SH(...) ILVR_H2(v8i16, __VA_ARGS__)
-#define ILVR_H2_SW(...) ILVR_H2(v4i32, __VA_ARGS__)
-
-#define ILVR_H4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7,  \
-                out0, out1, out2, out3)                         \
-{                                                               \
-    ILVR_H2(RTYPE, in0, in1, in2, in3, out0, out1);             \
-    ILVR_H2(RTYPE, in4, in5, in6, in7, out2, out3);             \
-}
-#define ILVR_H4_SH(...) ILVR_H4(v8i16, __VA_ARGS__)
-#define ILVR_H4_SW(...) ILVR_H4(v4i32, __VA_ARGS__)
-
-#define ILVR_W2(RTYPE, in0, in1, in2, in3, out0, out1)   \
-{                                                        \
-    out0 = (RTYPE)__msa_ilvr_w((v4i32)in0, (v4i32)in1);  \
-    out1 = (RTYPE)__msa_ilvr_w((v4i32)in2, (v4i32)in3);  \
-}
-#define ILVR_W2_SH(...) ILVR_W2(v8i16, __VA_ARGS__)
-
-/* Description : Interleave right half of double word elements from vectors
-   Arguments   : Inputs  - in0, in1, in2, in3
-                 Outputs - out0, out1
-                 Return Type - as per RTYPE
-   Details     : Right half of double word elements of 'in0' and 'in1' are
-                 interleaved and written to 'out0'.
-*/
-#define ILVR_D2(RTYPE, in0, in1, in2, in3, out0, out1)       \
-{                                                            \
-    out0 = (RTYPE)__msa_ilvr_d((v2i64)(in0), (v2i64)(in1));  \
-    out1 = (RTYPE)__msa_ilvr_d((v2i64)(in2), (v2i64)(in3));  \
-}
-#define ILVR_D2_UB(...) ILVR_D2(v16u8, __VA_ARGS__)
-#define ILVR_D2_SB(...) ILVR_D2(v16i8, __VA_ARGS__)
-#define ILVR_D2_SH(...) ILVR_D2(v8i16, __VA_ARGS__)
-
-#define ILVR_D4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7,  \
-                out0, out1, out2, out3)                         \
-{                                                               \
-    ILVR_D2(RTYPE, in0, in1, in2, in3, out0, out1);             \
-    ILVR_D2(RTYPE, in4, in5, in6, in7, out2, out3);             \
-}
-#define ILVR_D4_SB(...) ILVR_D4(v16i8, __VA_ARGS__)
-#define ILVR_D4_UB(...) ILVR_D4(v16u8, __VA_ARGS__)
-
-/* Description : Interleave both left and right half of input vectors
-   Arguments   : Inputs  - in0, in1
-                 Outputs - out0, out1
-                 Return Type - as per RTYPE
-   Details     : Right half of byte elements from 'in0' and 'in1' are
-                 interleaved and written to 'out0'
-*/
-#define ILVRL_B2(RTYPE, in0, in1, out0, out1)            \
-{                                                        \
-    out0 = (RTYPE)__msa_ilvr_b((v16i8)in0, (v16i8)in1);  \
-    out1 = (RTYPE)__msa_ilvl_b((v16i8)in0, (v16i8)in1);  \
-}
-#define ILVRL_B2_UB(...) ILVRL_B2(v16u8, __VA_ARGS__)
-#define ILVRL_B2_SB(...) ILVRL_B2(v16i8, __VA_ARGS__)
-#define ILVRL_B2_UH(...) ILVRL_B2(v8u16, __VA_ARGS__)
-#define ILVRL_B2_SH(...) ILVRL_B2(v8i16, __VA_ARGS__)
-
-#define ILVRL_H2(RTYPE, in0, in1, out0, out1)            \
-{                                                        \
-    out0 = (RTYPE)__msa_ilvr_h((v8i16)in0, (v8i16)in1);  \
-    out1 = (RTYPE)__msa_ilvl_h((v8i16)in0, (v8i16)in1);  \
-}
-#define ILVRL_H2_SH(...) ILVRL_H2(v8i16, __VA_ARGS__)
-#define ILVRL_H2_SW(...) ILVRL_H2(v4i32, __VA_ARGS__)
-
-#define ILVRL_W2(RTYPE, in0, in1, out0, out1)            \
-{                                                        \
-    out0 = (RTYPE)__msa_ilvr_w((v4i32)in0, (v4i32)in1);  \
-    out1 = (RTYPE)__msa_ilvl_w((v4i32)in0, (v4i32)in1);  \
-}
-#define ILVRL_W2_UB(...) ILVRL_W2(v16u8, __VA_ARGS__)
-#define ILVRL_W2_SH(...) ILVRL_W2(v8i16, __VA_ARGS__)
-#define ILVRL_W2_SW(...) ILVRL_W2(v4i32, __VA_ARGS__)
-
-/* Description : Maximum values between signed elements of vector and
-                 5-bit signed immediate value are copied to the output vector
-   Arguments   : Inputs  - in0, in1, in2, in3, max_val
-                 Outputs - in place operation
-                 Return Type - unsigned halfword
-   Details     : Maximum of signed halfword element values from 'in0' and
-                 'max_val' are written in place
-*/
-#define MAXI_SH2(RTYPE, in0, in1, max_val)               \
-{                                                        \
-    in0 = (RTYPE)__msa_maxi_s_h((v8i16)in0, (max_val));  \
-    in1 = (RTYPE)__msa_maxi_s_h((v8i16)in1, (max_val));  \
-}
-#define MAXI_SH2_SH(...) MAXI_SH2(v8i16, __VA_ARGS__)
-
-/* Description : Saturate the halfword element values to the max
-                 unsigned value of (sat_val + 1) bits
-                 The element data width remains unchanged
-   Arguments   : Inputs  - in0, in1, sat_val
-                 Outputs - in place operation
-                 Return Type - as per RTYPE
-   Details     : Each unsigned halfword element from 'in0' is saturated to the
-                 value generated with (sat_val + 1) bit range.
-                 The results are written in place
-*/
-#define SAT_UH2(RTYPE, in0, in1, sat_val)             \
-{                                                     \
-    in0 = (RTYPE)__msa_sat_u_h((v8u16)in0, sat_val);  \
-    in1 = (RTYPE)__msa_sat_u_h((v8u16)in1, sat_val);  \
-}
-#define SAT_UH2_SH(...) SAT_UH2(v8i16, __VA_ARGS__)
-
-/* Description : Saturate the halfword element values to the max
-                 unsigned value of (sat_val + 1) bits
-                 The element data width remains unchanged
-   Arguments   : Inputs  - in0, in1, sat_val
-                 Outputs - in place operation
-                 Return Type - as per RTYPE
-   Details     : Each unsigned halfword element from 'in0' is saturated to the
-                 value generated with (sat_val + 1) bit range
-                 The results are written in place
-*/
-#define SAT_SH2(RTYPE, in0, in1, sat_val)             \
-{                                                     \
-    in0 = (RTYPE)__msa_sat_s_h((v8i16)in0, sat_val);  \
-    in1 = (RTYPE)__msa_sat_s_h((v8i16)in1, sat_val);  \
-}
-#define SAT_SH2_SH(...) SAT_SH2(v8i16, __VA_ARGS__)
-
-#define SAT_SH4(RTYPE, in0, in1, in2, in3, sat_val)  \
-{                                                    \
-    SAT_SH2(RTYPE, in0, in1, sat_val);               \
-    SAT_SH2(RTYPE, in2, in3, sat_val);               \
-}
-#define SAT_SH4_SH(...) SAT_SH4(v8i16, __VA_ARGS__)
-
-/* Description : Indexed halfword element values are replicated to all
-                 elements in output vector
-   Arguments   : Inputs  - in, idx0, idx1
-                 Outputs - out0, out1
-                 Return Type - as per RTYPE
-   Details     : 'idx0' element value from 'in' vector is replicated to all
-                  elements in 'out0' vector
-                  Valid index range for halfword operation is 0-7
-*/
-#define SPLATI_H2(RTYPE, in, idx0, idx1, out0, out1)  \
-{                                                     \
-    out0 = (RTYPE)__msa_splati_h((v8i16)in, idx0);    \
-    out1 = (RTYPE)__msa_splati_h((v8i16)in, idx1);    \
-}
-#define SPLATI_H2_SB(...) SPLATI_H2(v16i8, __VA_ARGS__)
-#define SPLATI_H2_SH(...) SPLATI_H2(v8i16, __VA_ARGS__)
-
-#define SPLATI_H3(RTYPE, in, idx0, idx1, idx2,      \
-                  out0, out1, out2)                 \
-{                                                   \
-    SPLATI_H2(RTYPE, in, idx0, idx1, out0, out1);   \
-    out2 = (RTYPE)__msa_splati_h((v8i16)in, idx2);  \
-}
-#define SPLATI_H3_SB(...) SPLATI_H3(v16i8, __VA_ARGS__)
-#define SPLATI_H3_SH(...) SPLATI_H3(v8i16, __VA_ARGS__)
-
-/* Description : Indexed word element values are replicated to all
-                 elements in output vector
-   Arguments   : Inputs  - in, stidx
-                 Outputs - out0, out1
-                 Return Type - as per RTYPE
-   Details     : 'stidx' element value from 'in' vector is replicated to all
-                 elements in 'out0' vector
-                 'stidx + 1' element value from 'in' vector is replicated to all
-                 elements in 'out1' vector
-                 Valid index range for word operation is 0-3
-*/
-#define SPLATI_W2(RTYPE, in, stidx, out0, out1)          \
-{                                                        \
-    out0 = (RTYPE)__msa_splati_w((v4i32)in, stidx);      \
-    out1 = (RTYPE)__msa_splati_w((v4i32)in, (stidx+1));  \
-}
-#define SPLATI_W2_SW(...) SPLATI_W2(v4i32, __VA_ARGS__)
-
-/* Description : Pack even byte elements of vector pairs
-   Arguments   : Inputs  - in0, in1, in2, in3
-                 Outputs - out0, out1
-                 Return Type - as per RTYPE
-   Details     : Even byte elements of 'in0' are copied to the left half of
-                 'out0' & even byte elements of 'in1' are copied to the right
-                 half of 'out0'.
-*/
-#define PCKEV_B2(RTYPE, in0, in1, in2, in3, out0, out1)   \
-{                                                         \
-    out0 = (RTYPE)__msa_pckev_b((v16i8)in0, (v16i8)in1);  \
-    out1 = (RTYPE)__msa_pckev_b((v16i8)in2, (v16i8)in3);  \
-}
-#define PCKEV_B2_SB(...) PCKEV_B2(v16i8, __VA_ARGS__)
-#define PCKEV_B2_UB(...) PCKEV_B2(v16u8, __VA_ARGS__)
-
-#define PCKEV_B4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7,  \
-                 out0, out1, out2, out3)                         \
-{                                                                \
-    PCKEV_B2(RTYPE, in0, in1, in2, in3, out0, out1);             \
-    PCKEV_B2(RTYPE, in4, in5, in6, in7, out2, out3);             \
-}
-#define PCKEV_B4_SB(...) PCKEV_B4(v16i8, __VA_ARGS__)
-#define PCKEV_B4_UB(...) PCKEV_B4(v16u8, __VA_ARGS__)
-#define PCKEV_B4_SH(...) PCKEV_B4(v8i16, __VA_ARGS__)
-
-/* Description : Pack even halfword elements of vector pairs
-   Arguments   : Inputs  - in0, in1, in2, in3
-                 Outputs - out0, out1
-                 Return Type - as per RTYPE
-   Details     : Even halfword elements of 'in0' are copied to the left half of
-                 'out0' & even halfword elements of 'in1' are copied to the
-                 right half of 'out0'.
-*/
-#define PCKEV_H2(RTYPE, in0, in1, in2, in3, out0, out1)   \
-{                                                         \
-    out0 = (RTYPE)__msa_pckev_h((v8i16)in0, (v8i16)in1);  \
-    out1 = (RTYPE)__msa_pckev_h((v8i16)in2, (v8i16)in3);  \
-}
-#define PCKEV_H2_SH(...) PCKEV_H2(v8i16, __VA_ARGS__)
-
-#define PCKEV_H4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7,  \
-                 out0, out1, out2, out3)                         \
-{                                                                \
-    PCKEV_H2(RTYPE, in0, in1, in2, in3, out0, out1);             \
-    PCKEV_H2(RTYPE, in4, in5, in6, in7, out2, out3);             \
-}
-#define PCKEV_H4_SH(...) PCKEV_H4(v8i16, __VA_ARGS__)
-
-/* Description : Pack even double word elements of vector pairs
-   Arguments   : Inputs  - in0, in1, in2, in3
-                 Outputs - out0, out1
-                 Return Type - as per RTYPE
-   Details     : Even double elements of 'in0' are copied to the left half of
-                 'out0' & even double elements of 'in1' are copied to the right
-                 half of 'out0'.
-*/
-#define PCKEV_D2(RTYPE, in0, in1, in2, in3, out0, out1)   \
-{                                                         \
-    out0 = (RTYPE)__msa_pckev_d((v2i64)in0, (v2i64)in1);  \
-    out1 = (RTYPE)__msa_pckev_d((v2i64)in2, (v2i64)in3);  \
-}
-#define PCKEV_D2_UB(...) PCKEV_D2(v16u8, __VA_ARGS__)
-#define PCKEV_D2_SH(...) PCKEV_D2(v8i16, __VA_ARGS__)
-
-/* Description : Pack odd double word elements of vector pairs
-   Arguments   : Inputs  - in0, in1, in2, in3
-                 Outputs - out0, out1
-                 Return Type - as per RTYPE
-   Details     : Odd double word elements of 'in0' are copied to the left half
-                 of 'out0' & odd double word elements of 'in1' are copied to
-                 the right half of 'out0'.
-*/
-#define PCKOD_D2(RTYPE, in0, in1, in2, in3, out0, out1)   \
-{                                                         \
-    out0 = (RTYPE)__msa_pckod_d((v2i64)in0, (v2i64)in1);  \
-    out1 = (RTYPE)__msa_pckod_d((v2i64)in2, (v2i64)in3);  \
-}
-#define PCKOD_D2_UB(...) PCKOD_D2(v16u8, __VA_ARGS__)
-#define PCKOD_D2_SH(...) PCKOD_D2(v8i16, __VA_ARGS__)
-
-/* Description : Each byte element is logically xor'ed with immediate 128
-   Arguments   : Inputs  - in0, in1
-                 Outputs - in place operation
-                 Return Type - as per RTYPE
-   Details     : Each unsigned byte element from input vector 'in0' is
-                 logically xor'ed with 128 and the result is stored in-place.
-*/
-#define XORI_B2_128(RTYPE, in0, in1)             \
-{                                                \
-    in0 = (RTYPE)__msa_xori_b((v16u8)in0, 128);  \
-    in1 = (RTYPE)__msa_xori_b((v16u8)in1, 128);  \
-}
-#define XORI_B2_128_UB(...) XORI_B2_128(v16u8, __VA_ARGS__)
-#define XORI_B2_128_SB(...) XORI_B2_128(v16i8, __VA_ARGS__)
-
-#define XORI_B3_128(RTYPE, in0, in1, in2)        \
-{                                                \
-    XORI_B2_128(RTYPE, in0, in1);                \
-    in2 = (RTYPE)__msa_xori_b((v16u8)in2, 128);  \
-}
-#define XORI_B3_128_SB(...) XORI_B3_128(v16i8, __VA_ARGS__)
-
-#define XORI_B4_128(RTYPE, in0, in1, in2, in3)  \
-{                                               \
-    XORI_B2_128(RTYPE, in0, in1);               \
-    XORI_B2_128(RTYPE, in2, in3);               \
-}
-#define XORI_B4_128_UB(...) XORI_B4_128(v16u8, __VA_ARGS__)
-#define XORI_B4_128_SB(...) XORI_B4_128(v16i8, __VA_ARGS__)
-
-#define XORI_B5_128(RTYPE, in0, in1, in2, in3, in4)  \
-{                                                    \
-    XORI_B3_128(RTYPE, in0, in1, in2);               \
-    XORI_B2_128(RTYPE, in3, in4);                    \
-}
-#define XORI_B5_128_SB(...) XORI_B5_128(v16i8, __VA_ARGS__)
-
-#define XORI_B8_128(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7)  \
-{                                                                   \
-    XORI_B4_128(RTYPE, in0, in1, in2, in3);                         \
-    XORI_B4_128(RTYPE, in4, in5, in6, in7);                         \
-}
-#define XORI_B8_128_SB(...) XORI_B8_128(v16i8, __VA_ARGS__)
-
-/* Description : Shift left all elements of vector (generic for all data types)
-   Arguments   : Inputs  - in0, in1, in2, in3, shift
-                 Outputs - in place operation
-                 Return Type - as per input vector RTYPE
-   Details     : Each element of vector 'in0' is left shifted by 'shift' and
-                 the result is written in-place.
-*/
-#define SLLI_4V(in0, in1, in2, in3, shift)  \
-{                                           \
-    in0 = in0 << shift;                     \
-    in1 = in1 << shift;                     \
-    in2 = in2 << shift;                     \
-    in3 = in3 << shift;                     \
-}
-
-/* Description : Arithmetic shift right all elements of vector
-                 (generic for all data types)
-   Arguments   : Inputs  - in0, in1, in2, in3, shift
-                 Outputs - in place operation
-                 Return Type - as per input vector RTYPE
-   Details     : Each element of vector 'in0' is right shifted by 'shift' and
-                 the result is written in-place. 'shift' is a GP variable.
-*/
-#define SRA_4V(in0, in1, in2, in3, shift)  \
-{                                          \
-    in0 = in0 >> shift;                    \
-    in1 = in1 >> shift;                    \
-    in2 = in2 >> shift;                    \
-    in3 = in3 >> shift;                    \
-}
-
-/* Description : Shift right arithmetic rounded words
-   Arguments   : Inputs  - in0, in1, shift
-                 Outputs - in place operation
-                 Return Type - as per RTYPE
-   Details     : Each element of vector 'in0' is shifted right arithmetically by
-                 the number of bits in the corresponding element in the vector
-                 'shift'. The last discarded bit is added to shifted value for
-                 rounding and the result is written in-place.
-                 'shift' is a vector.
-*/
-#define SRAR_W2(RTYPE, in0, in1, shift)                   \
-{                                                         \
-    in0 = (RTYPE)__msa_srar_w((v4i32)in0, (v4i32)shift);  \
-    in1 = (RTYPE)__msa_srar_w((v4i32)in1, (v4i32)shift);  \
-}
-
-#define SRAR_W4(RTYPE, in0, in1, in2, in3, shift)  \
-{                                                  \
-    SRAR_W2(RTYPE, in0, in1, shift);               \
-    SRAR_W2(RTYPE, in2, in3, shift);               \
-}
-#define SRAR_W4_SW(...) SRAR_W4(v4i32, __VA_ARGS__)
-
-/* Description : Shift right arithmetic rounded (immediate)
-   Arguments   : Inputs  - in0, in1, shift
-                 Outputs - in place operation
-                 Return Type - as per RTYPE
-   Details     : Each element of vector 'in0' is shifted right arithmetically by
-                 the value in 'shift'. The last discarded bit is added to the
-                 shifted value for rounding and the result is written in-place.
-                 'shift' is an immediate value.
-*/
-#define SRARI_H2(RTYPE, in0, in1, shift)            \
-{                                                   \
-    in0 = (RTYPE)__msa_srari_h((v8i16)in0, shift);  \
-    in1 = (RTYPE)__msa_srari_h((v8i16)in1, shift);  \
-}
-#define SRARI_H2_UH(...) SRARI_H2(v8u16, __VA_ARGS__)
-#define SRARI_H2_SH(...) SRARI_H2(v8i16, __VA_ARGS__)
-
-#define SRARI_H4(RTYPE, in0, in1, in2, in3, shift)  \
-{                                                   \
-    SRARI_H2(RTYPE, in0, in1, shift);               \
-    SRARI_H2(RTYPE, in2, in3, shift);               \
-}
-#define SRARI_H4_UH(...) SRARI_H4(v8u16, __VA_ARGS__)
-#define SRARI_H4_SH(...) SRARI_H4(v8i16, __VA_ARGS__)
-
-#define SRARI_W2(RTYPE, in0, in1, shift)            \
-{                                                   \
-    in0 = (RTYPE)__msa_srari_w((v4i32)in0, shift);  \
-    in1 = (RTYPE)__msa_srari_w((v4i32)in1, shift);  \
-}
-
-#define SRARI_W4(RTYPE, in0, in1, in2, in3, shift)  \
-{                                                   \
-    SRARI_W2(RTYPE, in0, in1, shift);               \
-    SRARI_W2(RTYPE, in2, in3, shift);               \
-}
-#define SRARI_W4_SW(...) SRARI_W4(v4i32, __VA_ARGS__)
-
-/* Description : Multiplication of pairs of vectors
-   Arguments   : Inputs  - in0, in1, in2, in3
-                 Outputs - out0, out1
-   Details     : Each element from 'in0' is multiplied with elements from 'in1'
-                 and the result is written to 'out0'
-*/
-#define MUL2(in0, in1, in2, in3, out0, out1)  \
-{                                             \
-    out0 = in0 * in1;                         \
-    out1 = in2 * in3;                         \
-}
-#define MUL4(in0, in1, in2, in3, in4, in5, in6, in7,  \
-             out0, out1, out2, out3)                  \
-{                                                     \
-    MUL2(in0, in1, in2, in3, out0, out1);             \
-    MUL2(in4, in5, in6, in7, out2, out3);             \
-}
-
-/* Description : Addition of 2 pairs of vectors
-   Arguments   : Inputs  - in0, in1, in2, in3
-                 Outputs - out0, out1
-   Details     : Each element in 'in0' is added to 'in1' and result is written
-                 to 'out0'.
-*/
-#define ADD2(in0, in1, in2, in3, out0, out1)  \
-{                                             \
-    out0 = in0 + in1;                         \
-    out1 = in2 + in3;                         \
-}
-#define ADD4(in0, in1, in2, in3, in4, in5, in6, in7,  \
-             out0, out1, out2, out3)                  \
-{                                                     \
-    ADD2(in0, in1, in2, in3, out0, out1);             \
-    ADD2(in4, in5, in6, in7, out2, out3);             \
-}
-
-/* Description : Subtraction of 2 pairs of vectors
-   Arguments   : Inputs  - in0, in1, in2, in3
-                 Outputs - out0, out1
-   Details     : Each element in 'in1' is subtracted from 'in0' and result is
-                 written to 'out0'.
-*/
-#define SUB2(in0, in1, in2, in3, out0, out1)  \
-{                                             \
-    out0 = in0 - in1;                         \
-    out1 = in2 - in3;                         \
-}
-#define SUB4(in0, in1, in2, in3, in4, in5, in6, in7,  \
-             out0, out1, out2, out3)                  \
-{                                                     \
-    out0 = in0 - in1;                                 \
-    out1 = in2 - in3;                                 \
-    out2 = in4 - in5;                                 \
-    out3 = in6 - in7;                                 \
-}
-
-/* Description : Sign extend halfword elements from right half of the vector
-   Arguments   : Input  - in    (halfword vector)
-                 Output - out   (sign extended word vector)
-                 Return Type - signed word
-   Details     : Sign bit of halfword elements from input vector 'in' is
-                 extracted and interleaved with same vector 'in0' to generate
-                 4 word elements keeping sign intact
-*/
-#define UNPCK_R_SH_SW(in, out)                     \
-{                                                  \
-    v8i16 sign_m;                                  \
-                                                   \
-    sign_m = __msa_clti_s_h((v8i16)in, 0);         \
-    out = (v4i32)__msa_ilvr_h(sign_m, (v8i16)in);  \
-}
-
-/* Description : Zero extend unsigned byte elements to halfword elements
-   Arguments   : Input   - in          (unsigned byte vector)
-                 Outputs - out0, out1  (unsigned  halfword vectors)
-                 Return Type - signed halfword
-   Details     : Zero extended right half of vector is returned in 'out0'
-                 Zero extended left half of vector is returned in 'out1'
-*/
-#define UNPCK_UB_SH(in, out0, out1)       \
-{                                         \
-    v16i8 zero_m = { 0 };                 \
-                                          \
-    ILVRL_B2_SH(zero_m, in, out0, out1);  \
-}
-
-/* Description : Sign extend halfword elements from input vector and return
-                 the result in pair of vectors
-   Arguments   : Input   - in            (halfword vector)
-                 Outputs - out0, out1   (sign extended word vectors)
-                 Return Type - signed word
-   Details     : Sign bit of halfword elements from input vector 'in' is
-                 extracted and interleaved right with same vector 'in0' to
-                 generate 4 signed word elements in 'out0'
-                 Then interleaved left with same vector 'in0' to
-                 generate 4 signed word elements in 'out1'
-*/
-#define UNPCK_SH_SW(in, out0, out1)        \
-{                                          \
-    v8i16 tmp_m;                           \
-                                           \
-    tmp_m = __msa_clti_s_h((v8i16)in, 0);  \
-    ILVRL_H2_SW(tmp_m, in, out0, out1);    \
-}
-
-/* Description : Butterfly of 4 input vectors
-   Arguments   : Inputs  - in0, in1, in2, in3
-                 Outputs - out0, out1, out2, out3
-   Details     : Butterfly operation
-*/
-#define BUTTERFLY_4(in0, in1, in2, in3, out0, out1, out2, out3)  \
-{                                                                \
-    out0 = in0 + in3;                                            \
-    out1 = in1 + in2;                                            \
-                                                                 \
-    out2 = in1 - in2;                                            \
-    out3 = in0 - in3;                                            \
-}
-
-/* Description : Transpose input 8x8 byte block
-   Arguments   : Inputs  - in0, in1, in2, in3, in4, in5, in6, in7
-                 Outputs - out0, out1, out2, out3, out4, out5, out6, out7
-                 Return Type - as per RTYPE
-*/
-#define TRANSPOSE8x8_UB(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7,   \
-                        out0, out1, out2, out3, out4, out5, out6, out7)  \
-{                                                                        \
-    v16i8 tmp0_m, tmp1_m, tmp2_m, tmp3_m;                                \
-    v16i8 tmp4_m, tmp5_m, tmp6_m, tmp7_m;                                \
-                                                                         \
-    ILVR_B4_SB(in2, in0, in3, in1, in6, in4, in7, in5,                   \
-               tmp0_m, tmp1_m, tmp2_m, tmp3_m);                          \
-    ILVRL_B2_SB(tmp1_m, tmp0_m, tmp4_m, tmp5_m);                         \
-    ILVRL_B2_SB(tmp3_m, tmp2_m, tmp6_m, tmp7_m);                         \
-    ILVRL_W2(RTYPE, tmp6_m, tmp4_m, out0, out2);                         \
-    ILVRL_W2(RTYPE, tmp7_m, tmp5_m, out4, out6);                         \
-    SLDI_B2_0(RTYPE, out0, out2, out1, out3, 8);                         \
-    SLDI_B2_0(RTYPE, out4, out6, out5, out7, 8);                         \
-}
-#define TRANSPOSE8x8_UB_UB(...) TRANSPOSE8x8_UB(v16u8, __VA_ARGS__)
-
-/* Description : Transpose 16x4 block into 4x16 with byte elements in vectors
-   Arguments   : Inputs  - in0, in1, in2, in3, in4, in5, in6, in7,
-                           in8, in9, in10, in11, in12, in13, in14, in15
-                 Outputs - out0, out1, out2, out3
-                 Return Type - unsigned byte
-*/
-#define TRANSPOSE16x4_UB_UB(in0, in1, in2, in3, in4, in5, in6, in7,        \
-                            in8, in9, in10, in11, in12, in13, in14, in15,  \
-                            out0, out1, out2, out3)                        \
-{                                                                          \
-    v2i64 tmp0_m, tmp1_m, tmp2_m, tmp3_m;                                  \
-                                                                           \
-    ILVEV_W2_SD(in0, in4, in8, in12, tmp0_m, tmp1_m);                      \
-    out1 = (v16u8)__msa_ilvev_d(tmp1_m, tmp0_m);                           \
-                                                                           \
-    ILVEV_W2_SD(in1, in5, in9, in13, tmp0_m, tmp1_m);                      \
-    out3 = (v16u8)__msa_ilvev_d(tmp1_m, tmp0_m);                           \
-                                                                           \
-    ILVEV_W2_SD(in2, in6, in10, in14, tmp0_m, tmp1_m);                     \
-                                                                           \
-    tmp2_m = __msa_ilvev_d(tmp1_m, tmp0_m);                                \
-    ILVEV_W2_SD(in3, in7, in11, in15, tmp0_m, tmp1_m);                     \
-                                                                           \
-    tmp3_m = __msa_ilvev_d(tmp1_m, tmp0_m);                                \
-    ILVEV_B2_SD(out1, out3, tmp2_m, tmp3_m, tmp0_m, tmp1_m);               \
-    out0 = (v16u8)__msa_ilvev_h((v8i16)tmp1_m, (v8i16)tmp0_m);             \
-    out2 = (v16u8)__msa_ilvod_h((v8i16)tmp1_m, (v8i16)tmp0_m);             \
-                                                                           \
-    tmp0_m = (v2i64)__msa_ilvod_b((v16i8)out3, (v16i8)out1);               \
-    tmp1_m = (v2i64)__msa_ilvod_b((v16i8)tmp3_m, (v16i8)tmp2_m);           \
-    out1 = (v16u8)__msa_ilvev_h((v8i16)tmp1_m, (v8i16)tmp0_m);             \
-    out3 = (v16u8)__msa_ilvod_h((v8i16)tmp1_m, (v8i16)tmp0_m);             \
-}
-
-/* Description : Transpose 16x8 block into 8x16 with byte elements in vectors
-   Arguments   : Inputs  - in0, in1, in2, in3, in4, in5, in6, in7,
-                           in8, in9, in10, in11, in12, in13, in14, in15
-                 Outputs - out0, out1, out2, out3, out4, out5, out6, out7
-                 Return Type - unsigned byte
-*/
-#define TRANSPOSE16x8_UB_UB(in0, in1, in2, in3, in4, in5, in6, in7,          \
-                            in8, in9, in10, in11, in12, in13, in14, in15,    \
-                            out0, out1, out2, out3, out4, out5, out6, out7)  \
-{                                                                            \
-    v16u8 tmp0_m, tmp1_m, tmp2_m, tmp3_m;                                    \
-    v16u8 tmp4_m, tmp5_m, tmp6_m, tmp7_m;                                    \
-                                                                             \
-    ILVEV_D2_UB(in0, in8, in1, in9, out7, out6);                             \
-    ILVEV_D2_UB(in2, in10, in3, in11, out5, out4);                           \
-    ILVEV_D2_UB(in4, in12, in5, in13, out3, out2);                           \
-    ILVEV_D2_UB(in6, in14, in7, in15, out1, out0);                           \
-                                                                             \
-    tmp0_m = (v16u8)__msa_ilvev_b((v16i8)out6, (v16i8)out7);                 \
-    tmp4_m = (v16u8)__msa_ilvod_b((v16i8)out6, (v16i8)out7);                 \
-    tmp1_m = (v16u8)__msa_ilvev_b((v16i8)out4, (v16i8)out5);                 \
-    tmp5_m = (v16u8)__msa_ilvod_b((v16i8)out4, (v16i8)out5);                 \
-    out5 = (v16u8)__msa_ilvev_b((v16i8)out2, (v16i8)out3);                   \
-    tmp6_m = (v16u8)__msa_ilvod_b((v16i8)out2, (v16i8)out3);                 \
-    out7 = (v16u8)__msa_ilvev_b((v16i8)out0, (v16i8)out1);                   \
-    tmp7_m = (v16u8)__msa_ilvod_b((v16i8)out0, (v16i8)out1);                 \
-                                                                             \
-    ILVEV_H2_UB(tmp0_m, tmp1_m, out5, out7, tmp2_m, tmp3_m);                 \
-    out0 = (v16u8)__msa_ilvev_w((v4i32)tmp3_m, (v4i32)tmp2_m);               \
-    out4 = (v16u8)__msa_ilvod_w((v4i32)tmp3_m, (v4i32)tmp2_m);               \
-                                                                             \
-    tmp2_m = (v16u8)__msa_ilvod_h((v8i16)tmp1_m, (v8i16)tmp0_m);             \
-    tmp3_m = (v16u8)__msa_ilvod_h((v8i16)out7, (v8i16)out5);                 \
-    out2 = (v16u8)__msa_ilvev_w((v4i32)tmp3_m, (v4i32)tmp2_m);               \
-    out6 = (v16u8)__msa_ilvod_w((v4i32)tmp3_m, (v4i32)tmp2_m);               \
-                                                                             \
-    ILVEV_H2_UB(tmp4_m, tmp5_m, tmp6_m, tmp7_m, tmp2_m, tmp3_m);             \
-    out1 = (v16u8)__msa_ilvev_w((v4i32)tmp3_m, (v4i32)tmp2_m);               \
-    out5 = (v16u8)__msa_ilvod_w((v4i32)tmp3_m, (v4i32)tmp2_m);               \
-                                                                             \
-    tmp2_m = (v16u8)__msa_ilvod_h((v8i16)tmp5_m, (v8i16)tmp4_m);             \
-    tmp2_m = (v16u8)__msa_ilvod_h((v8i16)tmp5_m, (v8i16)tmp4_m);             \
-    tmp3_m = (v16u8)__msa_ilvod_h((v8i16)tmp7_m, (v8i16)tmp6_m);             \
-    tmp3_m = (v16u8)__msa_ilvod_h((v8i16)tmp7_m, (v8i16)tmp6_m);             \
-    out3 = (v16u8)__msa_ilvev_w((v4i32)tmp3_m, (v4i32)tmp2_m);               \
-    out7 = (v16u8)__msa_ilvod_w((v4i32)tmp3_m, (v4i32)tmp2_m);               \
-}
-
-/* Description : Transpose 4x4 block with half word elements in vectors
-   Arguments   : Inputs  - in0, in1, in2, in3
-                 Outputs - out0, out1, out2, out3
-                 Return Type - signed halfword
-*/
-#define TRANSPOSE4x4_SH_SH(in0, in1, in2, in3, out0, out1, out2, out3)  \
-{                                                                       \
-    v8i16 s0_m, s1_m;                                                   \
-                                                                        \
-    ILVR_H2_SH(in1, in0, in3, in2, s0_m, s1_m);                         \
-    ILVRL_W2_SH(s1_m, s0_m, out0, out2);                                \
-    out1 = (v8i16)__msa_ilvl_d((v2i64)out0, (v2i64)out0);               \
-    out3 = (v8i16)__msa_ilvl_d((v2i64)out0, (v2i64)out2);               \
-}
-
-/* Description : Transpose 8x4 block with half word elements in vectors
-   Arguments   : Inputs  - in0, in1, in2, in3, in4, in5, in6, in7
-                 Outputs - out0, out1, out2, out3, out4, out5, out6, out7
-                 Return Type - signed halfword
-*/
-#define TRANSPOSE8X4_SH_SH(in0, in1, in2, in3, out0, out1, out2, out3)  \
-{                                                                       \
-    v8i16 tmp0_m, tmp1_m, tmp2_m, tmp3_m;                               \
-                                                                        \
-    ILVR_H2_SH(in1, in0, in3, in2, tmp0_m, tmp1_m);                     \
-    ILVL_H2_SH(in1, in0, in3, in2, tmp2_m, tmp3_m);                     \
-    ILVR_W2_SH(tmp1_m, tmp0_m, tmp3_m, tmp2_m, out0, out2);             \
-    ILVL_W2_SH(tmp1_m, tmp0_m, tmp3_m, tmp2_m, out1, out3);             \
-}
-
-/* Description : Transpose 4x4 block with word elements in vectors
-   Arguments   : Inputs  - in0, in1, in2, in3
-                 Outputs - out0, out1, out2, out3
-                 Return Type - signed word
-*/
-#define TRANSPOSE4x4_SW_SW(in0, in1, in2, in3, out0, out1, out2, out3)  \
-{                                                                       \
-    v4i32 s0_m, s1_m, s2_m, s3_m;                                       \
-                                                                        \
-    ILVRL_W2_SW(in1, in0, s0_m, s1_m);                                  \
-    ILVRL_W2_SW(in3, in2, s2_m, s3_m);                                  \
-                                                                        \
-    out0 = (v4i32)__msa_ilvr_d((v2i64)s2_m, (v2i64)s0_m);               \
-    out1 = (v4i32)__msa_ilvl_d((v2i64)s2_m, (v2i64)s0_m);               \
-    out2 = (v4i32)__msa_ilvr_d((v2i64)s3_m, (v2i64)s1_m);               \
-    out3 = (v4i32)__msa_ilvl_d((v2i64)s3_m, (v2i64)s1_m);               \
-}
-
-/* Description : Dot product and addition of 3 signed halfword input vectors
-   Arguments   : Inputs - in0, in1, in2, coeff0, coeff1, coeff2
-                 Output - out0_m
-                 Return Type - signed halfword
-   Details     : Dot product of 'in0' with 'coeff0'
-                 Dot product of 'in1' with 'coeff1'
-                 Dot product of 'in2' with 'coeff2'
-                 Addition of all the 3 vector results
-                 out0_m = (in0 * coeff0) + (in1 * coeff1) + (in2 * coeff2)
-*/
-#define DPADD_SH3_SH(in0, in1, in2, coeff0, coeff1, coeff2)       \
-({                                                                \
-    v8i16 tmp1_m;                                                 \
-    v8i16 out0_m;                                                 \
-                                                                  \
-    out0_m = __msa_dotp_s_h((v16i8)in0, (v16i8)coeff0);           \
-    out0_m = __msa_dpadd_s_h(out0_m, (v16i8)in1, (v16i8)coeff1);  \
-    tmp1_m = __msa_dotp_s_h((v16i8)in2, (v16i8)coeff2);           \
-    out0_m = __msa_adds_s_h(out0_m, tmp1_m);                      \
-                                                                  \
-    out0_m;                                                       \
-})
-
-/* Description : Pack even elements of input vectors & xor with 128
-   Arguments   : Inputs - in0, in1
-                 Output - out_m
-                 Return Type - unsigned byte
-   Details     : Signed byte even elements from 'in0' and 'in1' are packed
-                 together in one vector and the resulting vector is xor'ed with
-                 128 to shift the range from signed to unsigned byte
-*/
-#define PCKEV_XORI128_UB(in0, in1)                         \
-({                                                         \
-    v16u8 out_m;                                           \
-    out_m = (v16u8)__msa_pckev_b((v16i8)in1, (v16i8)in0);  \
-    out_m = (v16u8)__msa_xori_b((v16u8)out_m, 128);        \
-    out_m;                                                 \
-})
-
-/* Description : Pack even byte elements and store byte vector in destination
-                 memory
-   Arguments   : Inputs - in0, in1, pdst
-*/
-#define PCKEV_ST_SB(in0, in1, pdst)                 \
-{                                                   \
-    v16i8 tmp_m;                                    \
-    tmp_m = __msa_pckev_b((v16i8)in1, (v16i8)in0);  \
-    ST_SB(tmp_m, (pdst));                           \
-}
-
-/* Description : Horizontal 2 tap filter kernel code
-   Arguments   : Inputs - in0, in1, mask, coeff, shift
-*/
-#define HORIZ_2TAP_FILT_UH(in0, in1, mask, coeff, shift)         \
-({                                                               \
-    v16i8 tmp0_m;                                                \
-    v8u16 tmp1_m;                                                \
-                                                                 \
-    tmp0_m = __msa_vshf_b((v16i8)mask, (v16i8)in1, (v16i8)in0);  \
-    tmp1_m = __msa_dotp_u_h((v16u8)tmp0_m, (v16u8)coeff);        \
-    tmp1_m = (v8u16)__msa_srari_h((v8i16)tmp1_m, shift);         \
-                                                                 \
-    tmp1_m;                                                      \
-})
-#endif  /* VP8_COMMON_MIPS_MSA_VP8_MACROS_MSA_H_ */
diff --git a/vp8/common/modecont.c b/vp8/common/modecont.c
deleted file mode 100644 (file)
index 86a74bc..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#include "entropy.h"
-
-const int vp8_mode_contexts[6][4] =
-{
-    {
-        /* 0 */
-        7,     1,     1,   143,
-    },
-    {
-        /* 1 */
-        14,    18,    14,   107,
-    },
-    {
-        /* 2 */
-        135,    64,    57,    68,
-    },
-    {
-        /* 3 */
-        60,    56,   128,    65,
-    },
-    {
-        /* 4 */
-        159,   134,   128,    34,
-    },
-    {
-        /* 5 */
-        234,   188,   128,    28,
-    },
-};
diff --git a/vp8/common/modecont.h b/vp8/common/modecont.h
deleted file mode 100644 (file)
index ff34c33..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#ifndef VP8_COMMON_MODECONT_H_
-#define VP8_COMMON_MODECONT_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-extern const int vp8_mode_contexts[6][4];
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP8_COMMON_MODECONT_H_
diff --git a/vp8/common/mv.h b/vp8/common/mv.h
deleted file mode 100644 (file)
index 111ccd6..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#ifndef VP8_COMMON_MV_H_
-#define VP8_COMMON_MV_H_
-#include "vpx/vpx_integer.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef struct
-{
-    short row;
-    short col;
-} MV;
-
-typedef union int_mv
-{
-    uint32_t  as_int;
-    MV        as_mv;
-} int_mv;        /* facilitates faster equality tests and copies */
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP8_COMMON_MV_H_
diff --git a/vp8/common/onyx.h b/vp8/common/onyx.h
deleted file mode 100644 (file)
index febe815..0000000
+++ /dev/null
@@ -1,282 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#ifndef VP8_COMMON_ONYX_H_
-#define VP8_COMMON_ONYX_H_
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-#include "vpx_config.h"
-#include "vpx/internal/vpx_codec_internal.h"
-#include "vpx/vp8cx.h"
-#include "vpx/vpx_encoder.h"
-#include "vpx_scale/yv12config.h"
-#include "ppflags.h"
-
-    struct VP8_COMP;
-
-    /* Create/destroy static data structures. */
-
-    typedef enum
-    {
-        NORMAL      = 0,
-        FOURFIVE    = 1,
-        THREEFIVE   = 2,
-        ONETWO      = 3
-
-    } VPX_SCALING;
-
-    typedef enum
-    {
-        USAGE_LOCAL_FILE_PLAYBACK   = 0x0,
-        USAGE_STREAM_FROM_SERVER    = 0x1,
-        USAGE_CONSTRAINED_QUALITY   = 0x2,
-        USAGE_CONSTANT_QUALITY      = 0x3
-    } END_USAGE;
-
-
-    typedef enum
-    {
-        MODE_REALTIME       = 0x0,
-        MODE_GOODQUALITY    = 0x1,
-        MODE_BESTQUALITY    = 0x2,
-        MODE_FIRSTPASS      = 0x3,
-        MODE_SECONDPASS     = 0x4,
-        MODE_SECONDPASS_BEST = 0x5
-    } MODE;
-
-    typedef enum
-    {
-        FRAMEFLAGS_KEY    = 1,
-        FRAMEFLAGS_GOLDEN = 2,
-        FRAMEFLAGS_ALTREF = 4
-    } FRAMETYPE_FLAGS;
-
-
-#include <assert.h>
-    static INLINE void Scale2Ratio(int mode, int *hr, int *hs)
-    {
-        switch (mode)
-        {
-        case    NORMAL:
-            *hr = 1;
-            *hs = 1;
-            break;
-        case    FOURFIVE:
-            *hr = 4;
-            *hs = 5;
-            break;
-        case    THREEFIVE:
-            *hr = 3;
-            *hs = 5;
-            break;
-        case    ONETWO:
-            *hr = 1;
-            *hs = 2;
-            break;
-        default:
-            *hr = 1;
-            *hs = 1;
-            assert(0);
-            break;
-        }
-    }
-
-    typedef struct
-    {
-        /* 4 versions of bitstream defined:
-         *   0 best quality/slowest decode, 3 lowest quality/fastest decode
-         */
-        int Version;
-        int Width;
-        int Height;
-        struct vpx_rational  timebase;
-        unsigned int target_bandwidth;    /* kilobits per second */
-
-        /* Parameter used for applying denoiser.
-         * For temporal denoiser: noise_sensitivity = 0 means off,
-         * noise_sensitivity = 1 means temporal denoiser on for Y channel only,
-         * noise_sensitivity = 2 means temporal denoiser on for all channels.
-         * noise_sensitivity = 3 means aggressive denoising mode.
-         * noise_sensitivity >= 4 means adaptive denoising mode.
-         * Temporal denoiser is enabled via the configuration option:
-         * CONFIG_TEMPORAL_DENOISING.
-         * For spatial denoiser: noise_sensitivity controls the amount of
-         * pre-processing blur: noise_sensitivity = 0 means off.
-         * Spatial denoiser invoked under !CONFIG_TEMPORAL_DENOISING.
-         */
-        int noise_sensitivity;
-
-        /* parameter used for sharpening output: recommendation 0: */
-        int Sharpness;
-        int cpu_used;
-        unsigned int rc_max_intra_bitrate_pct;
-        unsigned int screen_content_mode;
-
-        /* mode ->
-         *(0)=Realtime/Live Encoding. This mode is optimized for realtim
-         *    encoding (for example, capturing a television signal or feed
-         *    from a live camera). ( speed setting controls how fast )
-         *(1)=Good Quality Fast Encoding. The encoder balances quality with
-         *    the amount of time it takes to encode the output. ( speed
-         *    setting controls how fast )
-         *(2)=One Pass - Best Quality. The encoder places priority on the
-         *    quality of the output over encoding speed. The output is
-         *    compressed at the highest possible quality. This option takes
-         *    the longest amount of time to encode. ( speed setting ignored
-         *    )
-         *(3)=Two Pass - First Pass. The encoder generates a file of
-         *    statistics for use in the second encoding pass. ( speed
-         *    setting controls how fast )
-         *(4)=Two Pass - Second Pass. The encoder uses the statistics that
-         *    were generated in the first encoding pass to create the
-         *    compressed output. ( speed setting controls how fast )
-         *(5)=Two Pass - Second Pass Best.  The encoder uses the statistics
-         *    that were generated in the first encoding pass to create the
-         *    compressed output using the highest possible quality, and
-         *    taking a longer amount of time to encode.. ( speed setting
-         *    ignored )
-         */
-        int Mode;
-
-        /* Key Framing Operations */
-        int auto_key;       /* automatically detect cut scenes */
-        int key_freq;       /* maximum distance to key frame. */
-
-        /* lagged compression (if allow_lag == 0 lag_in_frames is ignored) */
-        int allow_lag;
-        int lag_in_frames; /* how many frames lag before we start encoding */
-
-        /*
-         * DATARATE CONTROL OPTIONS
-         */
-
-        int end_usage; /* vbr or cbr */
-
-        /* buffer targeting aggressiveness */
-        int under_shoot_pct;
-        int over_shoot_pct;
-
-        /* buffering parameters */
-        int64_t starting_buffer_level;
-        int64_t optimal_buffer_level;
-        int64_t maximum_buffer_size;
-
-        int64_t starting_buffer_level_in_ms;
-        int64_t optimal_buffer_level_in_ms;
-        int64_t maximum_buffer_size_in_ms;
-
-        /* controlling quality */
-        int fixed_q;
-        int worst_allowed_q;
-        int best_allowed_q;
-        int cq_level;
-
-        /* allow internal resizing */
-        int allow_spatial_resampling;
-        int resample_down_water_mark;
-        int resample_up_water_mark;
-
-        /* allow internal frame rate alterations */
-        int allow_df;
-        int drop_frames_water_mark;
-
-        /* two pass datarate control */
-        int two_pass_vbrbias;
-        int two_pass_vbrmin_section;
-        int two_pass_vbrmax_section;
-
-        /*
-         * END DATARATE CONTROL OPTIONS
-         */
-
-        /* these parameters aren't to be used in final build don't use!!! */
-        int play_alternate;
-        int alt_freq;
-        int alt_q;
-        int key_q;
-        int gold_q;
-
-
-        int multi_threaded;   /* how many threads to run the encoder on */
-        int token_partitions; /* how many token partitions to create */
-
-        /* early breakout threshold: for video conf recommend 800 */
-        int encode_breakout;
-
-        /* Bitfield defining the error resiliency features to enable.
-         * Can provide decodable frames after losses in previous
-         * frames and decodable partitions after losses in the same frame.
-         */
-        unsigned int error_resilient_mode;
-
-        int arnr_max_frames;
-        int arnr_strength;
-        int arnr_type;
-
-        vpx_fixed_buf_t        two_pass_stats_in;
-        struct vpx_codec_pkt_list  *output_pkt_list;
-
-        vp8e_tuning tuning;
-
-        /* Temporal scaling parameters */
-        unsigned int number_of_layers;
-        unsigned int target_bitrate[VPX_TS_MAX_PERIODICITY];
-        unsigned int rate_decimator[VPX_TS_MAX_PERIODICITY];
-        unsigned int periodicity;
-        unsigned int layer_id[VPX_TS_MAX_PERIODICITY];
-
-#if CONFIG_MULTI_RES_ENCODING
-        /* Number of total resolutions encoded */
-        unsigned int mr_total_resolutions;
-
-        /* Current encoder ID */
-        unsigned int mr_encoder_id;
-
-        /* Down-sampling factor */
-        vpx_rational_t mr_down_sampling_factor;
-
-        /* Memory location to store low-resolution encoder's mode info */
-        void* mr_low_res_mode_info;
-#endif
-    } VP8_CONFIG;
-
-
-    void vp8_initialize();
-
-    struct VP8_COMP* vp8_create_compressor(VP8_CONFIG *oxcf);
-    void vp8_remove_compressor(struct VP8_COMP* *comp);
-
-    void vp8_init_config(struct VP8_COMP* onyx, VP8_CONFIG *oxcf);
-    void vp8_change_config(struct VP8_COMP* onyx, VP8_CONFIG *oxcf);
-
-    int vp8_receive_raw_frame(struct VP8_COMP* comp, unsigned int frame_flags, YV12_BUFFER_CONFIG *sd, int64_t time_stamp, int64_t end_time_stamp);
-    int vp8_get_compressed_data(struct VP8_COMP* comp, unsigned int *frame_flags, unsigned long *size, unsigned char *dest, unsigned char *dest_end, int64_t *time_stamp, int64_t *time_end, int flush);
-    int vp8_get_preview_raw_frame(struct VP8_COMP* comp, YV12_BUFFER_CONFIG *dest, vp8_ppflags_t *flags);
-
-    int vp8_use_as_reference(struct VP8_COMP* comp, int ref_frame_flags);
-    int vp8_update_reference(struct VP8_COMP* comp, int ref_frame_flags);
-    int vp8_get_reference(struct VP8_COMP* comp, enum vpx_ref_frame_type ref_frame_flag, YV12_BUFFER_CONFIG *sd);
-    int vp8_set_reference(struct VP8_COMP* comp, enum vpx_ref_frame_type ref_frame_flag, YV12_BUFFER_CONFIG *sd);
-    int vp8_update_entropy(struct VP8_COMP* comp, int update);
-    int vp8_set_roimap(struct VP8_COMP* comp, unsigned char *map, unsigned int rows, unsigned int cols, int delta_q[4], int delta_lf[4], unsigned int threshold[4]);
-    int vp8_set_active_map(struct VP8_COMP* comp, unsigned char *map, unsigned int rows, unsigned int cols);
-    int vp8_set_internal_size(struct VP8_COMP* comp, VPX_SCALING horiz_mode, VPX_SCALING vert_mode);
-    int vp8_get_quantizer(struct VP8_COMP* c);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif  // VP8_COMMON_ONYX_H_
diff --git a/vp8/common/onyxc_int.h b/vp8/common/onyxc_int.h
deleted file mode 100644 (file)
index 6d89865..0000000
+++ /dev/null
@@ -1,185 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#ifndef VP8_COMMON_ONYXC_INT_H_
-#define VP8_COMMON_ONYXC_INT_H_
-
-#include "vpx_config.h"
-#include "vp8_rtcd.h"
-#include "vpx/internal/vpx_codec_internal.h"
-#include "loopfilter.h"
-#include "entropymv.h"
-#include "entropy.h"
-#if CONFIG_POSTPROC
-#include "postproc.h"
-#endif
-
-/*#ifdef PACKET_TESTING*/
-#include "header.h"
-/*#endif*/
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define MINQ 0
-#define MAXQ 127
-#define QINDEX_RANGE (MAXQ + 1)
-
-#define NUM_YV12_BUFFERS 4
-
-#define MAX_PARTITIONS 9
-
-typedef struct frame_contexts
-{
-    vp8_prob bmode_prob [VP8_BINTRAMODES-1];
-    vp8_prob ymode_prob [VP8_YMODES-1];   /* interframe intra mode probs */
-    vp8_prob uv_mode_prob [VP8_UV_MODES-1];
-    vp8_prob sub_mv_ref_prob [VP8_SUBMVREFS-1];
-    vp8_prob coef_probs [BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [ENTROPY_NODES];
-    MV_CONTEXT mvc[2];
-} FRAME_CONTEXT;
-
-typedef enum
-{
-    ONE_PARTITION  = 0,
-    TWO_PARTITION  = 1,
-    FOUR_PARTITION = 2,
-    EIGHT_PARTITION = 3
-} TOKEN_PARTITION;
-
-typedef enum
-{
-    RECON_CLAMP_REQUIRED        = 0,
-    RECON_CLAMP_NOTREQUIRED     = 1
-} CLAMP_TYPE;
-
-typedef struct VP8Common
-
-{
-    struct vpx_internal_error_info  error;
-
-    DECLARE_ALIGNED(16, short, Y1dequant[QINDEX_RANGE][2]);
-    DECLARE_ALIGNED(16, short, Y2dequant[QINDEX_RANGE][2]);
-    DECLARE_ALIGNED(16, short, UVdequant[QINDEX_RANGE][2]);
-
-    int Width;
-    int Height;
-    int horiz_scale;
-    int vert_scale;
-
-    CLAMP_TYPE  clamp_type;
-
-    YV12_BUFFER_CONFIG *frame_to_show;
-
-    YV12_BUFFER_CONFIG yv12_fb[NUM_YV12_BUFFERS];
-    int fb_idx_ref_cnt[NUM_YV12_BUFFERS];
-    int new_fb_idx, lst_fb_idx, gld_fb_idx, alt_fb_idx;
-
-    YV12_BUFFER_CONFIG temp_scale_frame;
-
-#if CONFIG_POSTPROC
-    YV12_BUFFER_CONFIG post_proc_buffer;
-    YV12_BUFFER_CONFIG post_proc_buffer_int;
-    int post_proc_buffer_int_used;
-    unsigned char *pp_limits_buffer;   /* post-processing filter coefficients */
-#endif
-
-    FRAME_TYPE last_frame_type;  /* Save last frame's frame type for motion search. */
-    FRAME_TYPE frame_type;
-
-    int show_frame;
-
-    int frame_flags;
-    int MBs;
-    int mb_rows;
-    int mb_cols;
-    int mode_info_stride;
-
-    /* profile settings */
-    int mb_no_coeff_skip;
-    int no_lpf;
-    int use_bilinear_mc_filter;
-    int full_pixel;
-
-    int base_qindex;
-
-    int y1dc_delta_q;
-    int y2dc_delta_q;
-    int y2ac_delta_q;
-    int uvdc_delta_q;
-    int uvac_delta_q;
-
-    /* We allocate a MODE_INFO struct for each macroblock, together with
-       an extra row on top and column on the left to simplify prediction. */
-
-    MODE_INFO *mip; /* Base of allocated array */
-    MODE_INFO *mi;  /* Corresponds to upper left visible macroblock */
-#if CONFIG_ERROR_CONCEALMENT
-    MODE_INFO *prev_mip; /* MODE_INFO array 'mip' from last decoded frame */
-    MODE_INFO *prev_mi;  /* 'mi' from last frame (points into prev_mip) */
-#endif
-    MODE_INFO *show_frame_mi;  /* MODE_INFO for the last decoded frame
-                                  to show */
-    LOOPFILTERTYPE filter_type;
-
-    loop_filter_info_n lf_info;
-
-    int filter_level;
-    int last_sharpness_level;
-    int sharpness_level;
-
-    int refresh_last_frame;       /* Two state 0 = NO, 1 = YES */
-    int refresh_golden_frame;     /* Two state 0 = NO, 1 = YES */
-    int refresh_alt_ref_frame;     /* Two state 0 = NO, 1 = YES */
-
-    int copy_buffer_to_gf;         /* 0 none, 1 Last to GF, 2 ARF to GF */
-    int copy_buffer_to_arf;        /* 0 none, 1 Last to ARF, 2 GF to ARF */
-
-    int refresh_entropy_probs;    /* Two state 0 = NO, 1 = YES */
-
-    int ref_frame_sign_bias[MAX_REF_FRAMES];    /* Two state 0, 1 */
-
-    /* Y,U,V,Y2 */
-    ENTROPY_CONTEXT_PLANES *above_context;   /* row of context for each plane */
-    ENTROPY_CONTEXT_PLANES left_context;  /* (up to) 4 contexts "" */
-
-    FRAME_CONTEXT lfc; /* last frame entropy */
-    FRAME_CONTEXT fc;  /* this frame entropy */
-
-    unsigned int current_video_frame;
-
-    int version;
-
-    TOKEN_PARTITION multi_token_partition;
-
-#ifdef PACKET_TESTING
-    VP8_HEADER oh;
-#endif
-#if CONFIG_POSTPROC_VISUALIZER
-    double bitrate;
-    double framerate;
-#endif
-
-#if CONFIG_MULTITHREAD
-    int processor_core_count;
-#endif
-#if CONFIG_POSTPROC
-    struct postproc_state  postproc_state;
-#endif
-    int cpu_caps;
-} VP8_COMMON;
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP8_COMMON_ONYXC_INT_H_
diff --git a/vp8/common/onyxd.h b/vp8/common/onyxd.h
deleted file mode 100644 (file)
index e37b29f..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#ifndef VP8_COMMON_ONYXD_H_
-#define VP8_COMMON_ONYXD_H_
-
-
-/* Create/destroy static data structures. */
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-#include "vpx_scale/yv12config.h"
-#include "ppflags.h"
-#include "vpx_ports/mem.h"
-#include "vpx/vpx_codec.h"
-#include "vpx/vp8.h"
-
-    struct VP8D_COMP;
-
-    typedef struct
-    {
-        int     Width;
-        int     Height;
-        int     Version;
-        int     postprocess;
-        int     max_threads;
-        int     error_concealment;
-    } VP8D_CONFIG;
-
-    typedef enum
-    {
-        VP8D_OK = 0
-    } VP8D_SETTING;
-
-    void vp8dx_initialize(void);
-
-    void vp8dx_set_setting(struct VP8D_COMP* comp, VP8D_SETTING oxst, int x);
-
-    int vp8dx_get_setting(struct VP8D_COMP* comp, VP8D_SETTING oxst);
-
-    int vp8dx_receive_compressed_data(struct VP8D_COMP* comp,
-                                      size_t size, const uint8_t *dest,
-                                      int64_t time_stamp);
-    int vp8dx_get_raw_frame(struct VP8D_COMP* comp, YV12_BUFFER_CONFIG *sd, int64_t *time_stamp, int64_t *time_end_stamp, vp8_ppflags_t *flags);
-
-    vpx_codec_err_t vp8dx_get_reference(struct VP8D_COMP* comp, enum vpx_ref_frame_type ref_frame_flag, YV12_BUFFER_CONFIG *sd);
-    vpx_codec_err_t vp8dx_set_reference(struct VP8D_COMP* comp, enum vpx_ref_frame_type ref_frame_flag, YV12_BUFFER_CONFIG *sd);
-
-#ifdef __cplusplus
-}
-#endif
-
-
-#endif  // VP8_COMMON_ONYXD_H_
diff --git a/vp8/common/postproc.c b/vp8/common/postproc.c
deleted file mode 100644 (file)
index 05e2bfc..0000000
+++ /dev/null
@@ -1,888 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#include "vpx_config.h"
-#include "vpx_dsp_rtcd.h"
-#include "vp8_rtcd.h"
-#include "vpx_dsp/postproc.h"
-#include "vpx_scale_rtcd.h"
-#include "vpx_scale/yv12config.h"
-#include "postproc.h"
-#include "common.h"
-#include "vpx_scale/vpx_scale.h"
-#include "systemdependent.h"
-
-#include <limits.h>
-#include <math.h>
-#include <stdlib.h>
-#include <stdio.h>
-
-#define RGB_TO_YUV(t)                                                                       \
-    ( (0.257*(float)(t>>16)) + (0.504*(float)(t>>8&0xff)) + (0.098*(float)(t&0xff)) + 16),  \
-    (-(0.148*(float)(t>>16)) - (0.291*(float)(t>>8&0xff)) + (0.439*(float)(t&0xff)) + 128), \
-    ( (0.439*(float)(t>>16)) - (0.368*(float)(t>>8&0xff)) - (0.071*(float)(t&0xff)) + 128)
-
-/* global constants */
-#if CONFIG_POSTPROC_VISUALIZER
-static const unsigned char MB_PREDICTION_MODE_colors[MB_MODE_COUNT][3] =
-{
-    { RGB_TO_YUV(0x98FB98) },   /* PaleGreen */
-    { RGB_TO_YUV(0x00FF00) },   /* Green */
-    { RGB_TO_YUV(0xADFF2F) },   /* GreenYellow */
-    { RGB_TO_YUV(0x228B22) },   /* ForestGreen */
-    { RGB_TO_YUV(0x006400) },   /* DarkGreen */
-    { RGB_TO_YUV(0x98F5FF) },   /* Cadet Blue */
-    { RGB_TO_YUV(0x6CA6CD) },   /* Sky Blue */
-    { RGB_TO_YUV(0x00008B) },   /* Dark blue */
-    { RGB_TO_YUV(0x551A8B) },   /* Purple */
-    { RGB_TO_YUV(0xFF0000) }    /* Red */
-};
-
-static const unsigned char B_PREDICTION_MODE_colors[B_MODE_COUNT][3] =
-{
-    { RGB_TO_YUV(0x6633ff) },   /* Purple */
-    { RGB_TO_YUV(0xcc33ff) },   /* Magenta */
-    { RGB_TO_YUV(0xff33cc) },   /* Pink */
-    { RGB_TO_YUV(0xff3366) },   /* Coral */
-    { RGB_TO_YUV(0x3366ff) },   /* Blue */
-    { RGB_TO_YUV(0xed00f5) },   /* Dark Blue */
-    { RGB_TO_YUV(0x2e00b8) },   /* Dark Purple */
-    { RGB_TO_YUV(0xff6633) },   /* Orange */
-    { RGB_TO_YUV(0x33ccff) },   /* Light Blue */
-    { RGB_TO_YUV(0x8ab800) },   /* Green */
-    { RGB_TO_YUV(0xffcc33) },   /* Light Orange */
-    { RGB_TO_YUV(0x33ffcc) },   /* Aqua */
-    { RGB_TO_YUV(0x66ff33) },   /* Light Green */
-    { RGB_TO_YUV(0xccff33) },   /* Yellow */
-};
-
-static const unsigned char MV_REFERENCE_FRAME_colors[MAX_REF_FRAMES][3] =
-{
-    { RGB_TO_YUV(0x00ff00) },   /* Blue */
-    { RGB_TO_YUV(0x0000ff) },   /* Green */
-    { RGB_TO_YUV(0xffff00) },   /* Yellow */
-    { RGB_TO_YUV(0xff0000) },   /* Red */
-};
-#endif
-
-
-extern void vp8_blit_text(const char *msg, unsigned char *address, const int pitch);
-extern void vp8_blit_line(int x0, int x1, int y0, int y1, unsigned char *image, const int pitch);
-/***********************************************************************************************************
- */
-static int q2mbl(int x)
-{
-    if (x < 20) x = 20;
-
-    x = 50 + (x - 50) * 10 / 8;
-    return x * x / 3;
-}
-
-#if CONFIG_POSTPROC
-static void vp8_de_mblock(YV12_BUFFER_CONFIG         *post,
-                          int                         q)
-{
-    vpx_mbpost_proc_across_ip(post->y_buffer, post->y_stride, post->y_height,
-                              post->y_width, q2mbl(q));
-    vpx_mbpost_proc_down(post->y_buffer, post->y_stride, post->y_height,
-                         post->y_width, q2mbl(q));
-}
-
-void vp8_deblock(VP8_COMMON                 *cm,
-                 YV12_BUFFER_CONFIG         *source,
-                 YV12_BUFFER_CONFIG         *post,
-                 int                         q,
-                 int                         low_var_thresh,
-                 int                         flag)
-{
-    double level = 6.0e-05 * q * q * q - .0067 * q * q + .306 * q + .0065;
-    int ppl = (int)(level + .5);
-
-    const MODE_INFO *mode_info_context = cm->show_frame_mi;
-    int mbr, mbc;
-
-    /* The pixel thresholds are adjusted according to if or not the macroblock
-     * is a skipped block.  */
-    unsigned char *ylimits = cm->pp_limits_buffer;
-    unsigned char *uvlimits = cm->pp_limits_buffer + 16 * cm->mb_cols;
-    (void) low_var_thresh;
-    (void) flag;
-
-    if (ppl > 0)
-    {
-        for (mbr = 0; mbr < cm->mb_rows; mbr++)
-        {
-            unsigned char *ylptr = ylimits;
-            unsigned char *uvlptr = uvlimits;
-            for (mbc = 0; mbc < cm->mb_cols; mbc++)
-            {
-                unsigned char mb_ppl;
-
-                if (mode_info_context->mbmi.mb_skip_coeff)
-                    mb_ppl = (unsigned char)ppl >> 1;
-                else
-                    mb_ppl = (unsigned char)ppl;
-
-                memset(ylptr, mb_ppl, 16);
-                memset(uvlptr, mb_ppl, 8);
-
-                ylptr += 16;
-                uvlptr += 8;
-                mode_info_context++;
-            }
-            mode_info_context++;
-
-            vpx_post_proc_down_and_across_mb_row(
-                source->y_buffer + 16 * mbr * source->y_stride,
-                post->y_buffer + 16 * mbr * post->y_stride, source->y_stride,
-                post->y_stride, source->y_width, ylimits, 16);
-
-            vpx_post_proc_down_and_across_mb_row(
-                source->u_buffer + 8 * mbr * source->uv_stride,
-                post->u_buffer + 8 * mbr * post->uv_stride, source->uv_stride,
-                post->uv_stride, source->uv_width, uvlimits, 8);
-            vpx_post_proc_down_and_across_mb_row(
-                source->v_buffer + 8 * mbr * source->uv_stride,
-                post->v_buffer + 8 * mbr * post->uv_stride, source->uv_stride,
-                post->uv_stride, source->uv_width, uvlimits, 8);
-        }
-    } else
-    {
-        vp8_yv12_copy_frame(source, post);
-    }
-}
-#endif
-
-void vp8_de_noise(VP8_COMMON                 *cm,
-                  YV12_BUFFER_CONFIG         *source,
-                  YV12_BUFFER_CONFIG         *post,
-                  int                         q,
-                  int                         low_var_thresh,
-                  int                         flag,
-                  int                         uvfilter)
-{
-    int mbr;
-    double level = 6.0e-05 * q * q * q - .0067 * q * q + .306 * q + .0065;
-    int ppl = (int)(level + .5);
-    int mb_rows = cm->mb_rows;
-    int mb_cols = cm->mb_cols;
-    unsigned char *limits = cm->pp_limits_buffer;;
-    (void) post;
-    (void) low_var_thresh;
-    (void) flag;
-
-    memset(limits, (unsigned char)ppl, 16 * mb_cols);
-
-    /* TODO: The original code don't filter the 2 outer rows and columns. */
-    for (mbr = 0; mbr < mb_rows; mbr++)
-    {
-        vpx_post_proc_down_and_across_mb_row(
-            source->y_buffer + 16 * mbr * source->y_stride,
-            source->y_buffer + 16 * mbr * source->y_stride,
-            source->y_stride, source->y_stride, source->y_width, limits, 16);
-        if (uvfilter == 1) {
-          vpx_post_proc_down_and_across_mb_row(
-              source->u_buffer + 8 * mbr * source->uv_stride,
-              source->u_buffer + 8 * mbr * source->uv_stride,
-              source->uv_stride, source->uv_stride, source->uv_width, limits,
-              8);
-          vpx_post_proc_down_and_across_mb_row(
-              source->v_buffer + 8 * mbr * source->uv_stride,
-              source->v_buffer + 8 * mbr * source->uv_stride,
-              source->uv_stride, source->uv_stride, source->uv_width, limits,
-              8);
-        }
-    }
-}
-
-/* Blend the macro block with a solid colored square.  Leave the
- * edges unblended to give distinction to macro blocks in areas
- * filled with the same color block.
- */
-void vp8_blend_mb_inner_c (unsigned char *y, unsigned char *u, unsigned char *v,
-                        int y_1, int u_1, int v_1, int alpha, int stride)
-{
-    int i, j;
-    int y1_const = y_1*((1<<16)-alpha);
-    int u1_const = u_1*((1<<16)-alpha);
-    int v1_const = v_1*((1<<16)-alpha);
-
-    y += 2*stride + 2;
-    for (i = 0; i < 12; i++)
-    {
-        for (j = 0; j < 12; j++)
-        {
-            y[j] = (y[j]*alpha + y1_const)>>16;
-        }
-        y += stride;
-    }
-
-    stride >>= 1;
-
-    u += stride + 1;
-    v += stride + 1;
-
-    for (i = 0; i < 6; i++)
-    {
-        for (j = 0; j < 6; j++)
-        {
-            u[j] = (u[j]*alpha + u1_const)>>16;
-            v[j] = (v[j]*alpha + v1_const)>>16;
-        }
-        u += stride;
-        v += stride;
-    }
-}
-
-/* Blend only the edge of the macro block.  Leave center
- * unblended to allow for other visualizations to be layered.
- */
-void vp8_blend_mb_outer_c (unsigned char *y, unsigned char *u, unsigned char *v,
-                        int y_1, int u_1, int v_1, int alpha, int stride)
-{
-    int i, j;
-    int y1_const = y_1*((1<<16)-alpha);
-    int u1_const = u_1*((1<<16)-alpha);
-    int v1_const = v_1*((1<<16)-alpha);
-
-    for (i = 0; i < 2; i++)
-    {
-        for (j = 0; j < 16; j++)
-        {
-            y[j] = (y[j]*alpha + y1_const)>>16;
-        }
-        y += stride;
-    }
-
-    for (i = 0; i < 12; i++)
-    {
-        y[0]  = (y[0]*alpha  + y1_const)>>16;
-        y[1]  = (y[1]*alpha  + y1_const)>>16;
-        y[14] = (y[14]*alpha + y1_const)>>16;
-        y[15] = (y[15]*alpha + y1_const)>>16;
-        y += stride;
-    }
-
-    for (i = 0; i < 2; i++)
-    {
-        for (j = 0; j < 16; j++)
-        {
-            y[j] = (y[j]*alpha + y1_const)>>16;
-        }
-        y += stride;
-    }
-
-    stride >>= 1;
-
-    for (j = 0; j < 8; j++)
-    {
-        u[j] = (u[j]*alpha + u1_const)>>16;
-        v[j] = (v[j]*alpha + v1_const)>>16;
-    }
-    u += stride;
-    v += stride;
-
-    for (i = 0; i < 6; i++)
-    {
-        u[0] = (u[0]*alpha + u1_const)>>16;
-        v[0] = (v[0]*alpha + v1_const)>>16;
-
-        u[7] = (u[7]*alpha + u1_const)>>16;
-        v[7] = (v[7]*alpha + v1_const)>>16;
-
-        u += stride;
-        v += stride;
-    }
-
-    for (j = 0; j < 8; j++)
-    {
-        u[j] = (u[j]*alpha + u1_const)>>16;
-        v[j] = (v[j]*alpha + v1_const)>>16;
-    }
-}
-
-void vp8_blend_b_c (unsigned char *y, unsigned char *u, unsigned char *v,
-                        int y_1, int u_1, int v_1, int alpha, int stride)
-{
-    int i, j;
-    int y1_const = y_1*((1<<16)-alpha);
-    int u1_const = u_1*((1<<16)-alpha);
-    int v1_const = v_1*((1<<16)-alpha);
-
-    for (i = 0; i < 4; i++)
-    {
-        for (j = 0; j < 4; j++)
-        {
-            y[j] = (y[j]*alpha + y1_const)>>16;
-        }
-        y += stride;
-    }
-
-    stride >>= 1;
-
-    for (i = 0; i < 2; i++)
-    {
-        for (j = 0; j < 2; j++)
-        {
-            u[j] = (u[j]*alpha + u1_const)>>16;
-            v[j] = (v[j]*alpha + v1_const)>>16;
-        }
-        u += stride;
-        v += stride;
-    }
-}
-
-#if CONFIG_POSTPROC_VISUALIZER
-static void constrain_line (int x_0, int *x_1, int y_0, int *y_1, int width, int height)
-{
-    int dx;
-    int dy;
-
-    if (*x_1 > width)
-    {
-        dx = *x_1 - x_0;
-        dy = *y_1 - y_0;
-
-        *x_1 = width;
-        if (dx)
-            *y_1 = ((width-x_0)*dy)/dx + y_0;
-    }
-    if (*x_1 < 0)
-    {
-        dx = *x_1 - x_0;
-        dy = *y_1 - y_0;
-
-        *x_1 = 0;
-        if (dx)
-            *y_1 = ((0-x_0)*dy)/dx + y_0;
-    }
-    if (*y_1 > height)
-    {
-        dx = *x_1 - x_0;
-        dy = *y_1 - y_0;
-
-        *y_1 = height;
-        if (dy)
-            *x_1 = ((height-y_0)*dx)/dy + x_0;
-    }
-    if (*y_1 < 0)
-    {
-        dx = *x_1 - x_0;
-        dy = *y_1 - y_0;
-
-        *y_1 = 0;
-        if (dy)
-            *x_1 = ((0-y_0)*dx)/dy + x_0;
-    }
-}
-#endif  // CONFIG_POSTPROC_VISUALIZER
-
-#if CONFIG_POSTPROC
-int vp8_post_proc_frame(VP8_COMMON *oci, YV12_BUFFER_CONFIG *dest, vp8_ppflags_t *ppflags)
-{
-    int q = oci->filter_level * 10 / 6;
-    int flags = ppflags->post_proc_flag;
-    int deblock_level = ppflags->deblocking_level;
-    int noise_level = ppflags->noise_level;
-
-    if (!oci->frame_to_show)
-        return -1;
-
-    if (q > 63)
-        q = 63;
-
-    if (!flags)
-    {
-        *dest = *oci->frame_to_show;
-
-        /* handle problem with extending borders */
-        dest->y_width = oci->Width;
-        dest->y_height = oci->Height;
-        dest->uv_height = dest->y_height / 2;
-        oci->postproc_state.last_base_qindex = oci->base_qindex;
-        oci->postproc_state.last_frame_valid = 1;
-        return 0;
-    }
-
-    /* Allocate post_proc_buffer_int if needed */
-    if ((flags & VP8D_MFQE) && !oci->post_proc_buffer_int_used)
-    {
-        if ((flags & VP8D_DEBLOCK) || (flags & VP8D_DEMACROBLOCK))
-        {
-            int width = (oci->Width + 15) & ~15;
-            int height = (oci->Height + 15) & ~15;
-
-            if (vp8_yv12_alloc_frame_buffer(&oci->post_proc_buffer_int,
-                                            width, height, VP8BORDERINPIXELS))
-                vpx_internal_error(&oci->error, VPX_CODEC_MEM_ERROR,
-                                   "Failed to allocate MFQE framebuffer");
-
-            oci->post_proc_buffer_int_used = 1;
-
-            /* insure that postproc is set to all 0's so that post proc
-             * doesn't pull random data in from edge
-             */
-            memset((&oci->post_proc_buffer_int)->buffer_alloc,128,(&oci->post_proc_buffer)->frame_size);
-
-        }
-    }
-
-    vp8_clear_system_state();
-
-    if ((flags & VP8D_MFQE) &&
-         oci->postproc_state.last_frame_valid &&
-         oci->current_video_frame >= 2 &&
-         oci->postproc_state.last_base_qindex < 60 &&
-         oci->base_qindex - oci->postproc_state.last_base_qindex >= 20)
-    {
-        vp8_multiframe_quality_enhance(oci);
-        if (((flags & VP8D_DEBLOCK) || (flags & VP8D_DEMACROBLOCK)) &&
-            oci->post_proc_buffer_int_used)
-        {
-            vp8_yv12_copy_frame(&oci->post_proc_buffer, &oci->post_proc_buffer_int);
-            if (flags & VP8D_DEMACROBLOCK)
-            {
-                vp8_deblock(oci, &oci->post_proc_buffer_int, &oci->post_proc_buffer,
-                                               q + (deblock_level - 5) * 10, 1, 0);
-                vp8_de_mblock(&oci->post_proc_buffer,
-                              q + (deblock_level - 5) * 10);
-            }
-            else if (flags & VP8D_DEBLOCK)
-            {
-                vp8_deblock(oci, &oci->post_proc_buffer_int, &oci->post_proc_buffer,
-                            q, 1, 0);
-            }
-        }
-        /* Move partially towards the base q of the previous frame */
-        oci->postproc_state.last_base_qindex = (3*oci->postproc_state.last_base_qindex + oci->base_qindex)>>2;
-    }
-    else if (flags & VP8D_DEMACROBLOCK)
-    {
-        vp8_deblock(oci, oci->frame_to_show, &oci->post_proc_buffer,
-                                     q + (deblock_level - 5) * 10, 1, 0);
-        vp8_de_mblock(&oci->post_proc_buffer, q + (deblock_level - 5) * 10);
-
-        oci->postproc_state.last_base_qindex = oci->base_qindex;
-    }
-    else if (flags & VP8D_DEBLOCK)
-    {
-        vp8_deblock(oci, oci->frame_to_show, &oci->post_proc_buffer,
-                    q, 1, 0);
-        oci->postproc_state.last_base_qindex = oci->base_qindex;
-    }
-    else
-    {
-        vp8_yv12_copy_frame(oci->frame_to_show, &oci->post_proc_buffer);
-        oci->postproc_state.last_base_qindex = oci->base_qindex;
-    }
-    oci->postproc_state.last_frame_valid = 1;
-
-    if (flags & VP8D_ADDNOISE)
-    {
-        if (oci->postproc_state.last_q != q
-            || oci->postproc_state.last_noise != noise_level)
-        {
-            double sigma;
-            int clamp, i;
-            struct postproc_state *ppstate = &oci->postproc_state;
-            vp8_clear_system_state();
-            sigma = noise_level + .5 + .6 * q / 63.0;
-            clamp = vpx_setup_noise(sigma, sizeof(ppstate->noise),
-                                    ppstate->noise);
-            for (i = 0; i < 16; i++)
-            {
-                ppstate->blackclamp[i] = clamp;
-                ppstate->whiteclamp[i] = clamp;
-                ppstate->bothclamp[i] = 2 * clamp;
-            }
-
-            ppstate->last_q = q;
-            ppstate->last_noise = noise_level;
-        }
-
-        vpx_plane_add_noise
-        (oci->post_proc_buffer.y_buffer,
-         oci->postproc_state.noise,
-         oci->postproc_state.blackclamp,
-         oci->postproc_state.whiteclamp,
-         oci->postproc_state.bothclamp,
-         oci->post_proc_buffer.y_width, oci->post_proc_buffer.y_height,
-         oci->post_proc_buffer.y_stride);
-    }
-
-#if CONFIG_POSTPROC_VISUALIZER
-    if (flags & VP8D_DEBUG_TXT_FRAME_INFO)
-    {
-        char message[512];
-        sprintf(message, "F%1dG%1dQ%3dF%3dP%d_s%dx%d",
-                (oci->frame_type == KEY_FRAME),
-                oci->refresh_golden_frame,
-                oci->base_qindex,
-                oci->filter_level,
-                flags,
-                oci->mb_cols, oci->mb_rows);
-        vp8_blit_text(message, oci->post_proc_buffer.y_buffer, oci->post_proc_buffer.y_stride);
-    }
-
-    if (flags & VP8D_DEBUG_TXT_MBLK_MODES)
-    {
-        int i, j;
-        unsigned char *y_ptr;
-        YV12_BUFFER_CONFIG *post = &oci->post_proc_buffer;
-        int mb_rows = post->y_height >> 4;
-        int mb_cols = post->y_width  >> 4;
-        int mb_index = 0;
-        MODE_INFO *mi = oci->mi;
-
-        y_ptr = post->y_buffer + 4 * post->y_stride + 4;
-
-        /* vp8_filter each macro block */
-        for (i = 0; i < mb_rows; i++)
-        {
-            for (j = 0; j < mb_cols; j++)
-            {
-                char zz[4];
-
-                sprintf(zz, "%c", mi[mb_index].mbmi.mode + 'a');
-
-                vp8_blit_text(zz, y_ptr, post->y_stride);
-                mb_index ++;
-                y_ptr += 16;
-            }
-
-            mb_index ++; /* border */
-            y_ptr += post->y_stride  * 16 - post->y_width;
-
-        }
-    }
-
-    if (flags & VP8D_DEBUG_TXT_DC_DIFF)
-    {
-        int i, j;
-        unsigned char *y_ptr;
-        YV12_BUFFER_CONFIG *post = &oci->post_proc_buffer;
-        int mb_rows = post->y_height >> 4;
-        int mb_cols = post->y_width  >> 4;
-        int mb_index = 0;
-        MODE_INFO *mi = oci->mi;
-
-        y_ptr = post->y_buffer + 4 * post->y_stride + 4;
-
-        /* vp8_filter each macro block */
-        for (i = 0; i < mb_rows; i++)
-        {
-            for (j = 0; j < mb_cols; j++)
-            {
-                char zz[4];
-                int dc_diff = !(mi[mb_index].mbmi.mode != B_PRED &&
-                              mi[mb_index].mbmi.mode != SPLITMV &&
-                              mi[mb_index].mbmi.mb_skip_coeff);
-
-                if (oci->frame_type == KEY_FRAME)
-                    sprintf(zz, "a");
-                else
-                    sprintf(zz, "%c", dc_diff + '0');
-
-                vp8_blit_text(zz, y_ptr, post->y_stride);
-                mb_index ++;
-                y_ptr += 16;
-            }
-
-            mb_index ++; /* border */
-            y_ptr += post->y_stride  * 16 - post->y_width;
-
-        }
-    }
-
-    if (flags & VP8D_DEBUG_TXT_RATE_INFO)
-    {
-        char message[512];
-        sprintf(message, "Bitrate: %10.2f framerate: %10.2f ", oci->bitrate, oci->framerate);
-        vp8_blit_text(message, oci->post_proc_buffer.y_buffer, oci->post_proc_buffer.y_stride);
-    }
-
-    /* Draw motion vectors */
-    if ((flags & VP8D_DEBUG_DRAW_MV) && ppflags->display_mv_flag)
-    {
-        YV12_BUFFER_CONFIG *post = &oci->post_proc_buffer;
-        int width  = post->y_width;
-        int height = post->y_height;
-        unsigned char *y_buffer = oci->post_proc_buffer.y_buffer;
-        int y_stride = oci->post_proc_buffer.y_stride;
-        MODE_INFO *mi = oci->mi;
-        int x0, y0;
-
-        for (y0 = 0; y0 < height; y0 += 16)
-        {
-            for (x0 = 0; x0 < width; x0 += 16)
-            {
-                int x1, y1;
-
-                if (!(ppflags->display_mv_flag & (1<<mi->mbmi.mode)))
-                {
-                    mi++;
-                    continue;
-                }
-
-                if (mi->mbmi.mode == SPLITMV)
-                {
-                    switch (mi->mbmi.partitioning)
-                    {
-                        case 0 :    /* mv_top_bottom */
-                        {
-                            union b_mode_info *bmi = &mi->bmi[0];
-                            MV *mv = &bmi->mv.as_mv;
-
-                            x1 = x0 + 8 + (mv->col >> 3);
-                            y1 = y0 + 4 + (mv->row >> 3);
-
-                            constrain_line (x0+8, &x1, y0+4, &y1, width, height);
-                            vp8_blit_line  (x0+8,  x1, y0+4,  y1, y_buffer, y_stride);
-
-                            bmi = &mi->bmi[8];
-
-                            x1 = x0 + 8 + (mv->col >> 3);
-                            y1 = y0 +12 + (mv->row >> 3);
-
-                            constrain_line (x0+8, &x1, y0+12, &y1, width, height);
-                            vp8_blit_line  (x0+8,  x1, y0+12,  y1, y_buffer, y_stride);
-
-                            break;
-                        }
-                        case 1 :    /* mv_left_right */
-                        {
-                            union b_mode_info *bmi = &mi->bmi[0];
-                            MV *mv = &bmi->mv.as_mv;
-
-                            x1 = x0 + 4 + (mv->col >> 3);
-                            y1 = y0 + 8 + (mv->row >> 3);
-
-                            constrain_line (x0+4, &x1, y0+8, &y1, width, height);
-                            vp8_blit_line  (x0+4,  x1, y0+8,  y1, y_buffer, y_stride);
-
-                            bmi = &mi->bmi[2];
-
-                            x1 = x0 +12 + (mv->col >> 3);
-                            y1 = y0 + 8 + (mv->row >> 3);
-
-                            constrain_line (x0+12, &x1, y0+8, &y1, width, height);
-                            vp8_blit_line  (x0+12,  x1, y0+8,  y1, y_buffer, y_stride);
-
-                            break;
-                        }
-                        case 2 :    /* mv_quarters   */
-                        {
-                            union b_mode_info *bmi = &mi->bmi[0];
-                            MV *mv = &bmi->mv.as_mv;
-
-                            x1 = x0 + 4 + (mv->col >> 3);
-                            y1 = y0 + 4 + (mv->row >> 3);
-
-                            constrain_line (x0+4, &x1, y0+4, &y1, width, height);
-                            vp8_blit_line  (x0+4,  x1, y0+4,  y1, y_buffer, y_stride);
-
-                            bmi = &mi->bmi[2];
-
-                            x1 = x0 +12 + (mv->col >> 3);
-                            y1 = y0 + 4 + (mv->row >> 3);
-
-                            constrain_line (x0+12, &x1, y0+4, &y1, width, height);
-                            vp8_blit_line  (x0+12,  x1, y0+4,  y1, y_buffer, y_stride);
-
-                            bmi = &mi->bmi[8];
-
-                            x1 = x0 + 4 + (mv->col >> 3);
-                            y1 = y0 +12 + (mv->row >> 3);
-
-                            constrain_line (x0+4, &x1, y0+12, &y1, width, height);
-                            vp8_blit_line  (x0+4,  x1, y0+12,  y1, y_buffer, y_stride);
-
-                            bmi = &mi->bmi[10];
-
-                            x1 = x0 +12 + (mv->col >> 3);
-                            y1 = y0 +12 + (mv->row >> 3);
-
-                            constrain_line (x0+12, &x1, y0+12, &y1, width, height);
-                            vp8_blit_line  (x0+12,  x1, y0+12,  y1, y_buffer, y_stride);
-                            break;
-                        }
-                        default :
-                        {
-                            union b_mode_info *bmi = mi->bmi;
-                            int bx0, by0;
-
-                            for (by0 = y0; by0 < (y0+16); by0 += 4)
-                            {
-                                for (bx0 = x0; bx0 < (x0+16); bx0 += 4)
-                                {
-                                    MV *mv = &bmi->mv.as_mv;
-
-                                    x1 = bx0 + 2 + (mv->col >> 3);
-                                    y1 = by0 + 2 + (mv->row >> 3);
-
-                                    constrain_line (bx0+2, &x1, by0+2, &y1, width, height);
-                                    vp8_blit_line  (bx0+2,  x1, by0+2,  y1, y_buffer, y_stride);
-
-                                    bmi++;
-                                }
-                            }
-                        }
-                    }
-                }
-                else if (mi->mbmi.mode >= NEARESTMV)
-                {
-                    MV *mv = &mi->mbmi.mv.as_mv;
-                    const int lx0 = x0 + 8;
-                    const int ly0 = y0 + 8;
-
-                    x1 = lx0 + (mv->col >> 3);
-                    y1 = ly0 + (mv->row >> 3);
-
-                    if (x1 != lx0 && y1 != ly0)
-                    {
-                        constrain_line (lx0, &x1, ly0-1, &y1, width, height);
-                        vp8_blit_line  (lx0,  x1, ly0-1,  y1, y_buffer, y_stride);
-
-                        constrain_line (lx0, &x1, ly0+1, &y1, width, height);
-                        vp8_blit_line  (lx0,  x1, ly0+1,  y1, y_buffer, y_stride);
-                    }
-                    else
-                        vp8_blit_line  (lx0,  x1, ly0,  y1, y_buffer, y_stride);
-                }
-
-                mi++;
-            }
-            mi++;
-        }
-    }
-
-    /* Color in block modes */
-    if ((flags & VP8D_DEBUG_CLR_BLK_MODES)
-        && (ppflags->display_mb_modes_flag || ppflags->display_b_modes_flag))
-    {
-        int y, x;
-        YV12_BUFFER_CONFIG *post = &oci->post_proc_buffer;
-        int width  = post->y_width;
-        int height = post->y_height;
-        unsigned char *y_ptr = oci->post_proc_buffer.y_buffer;
-        unsigned char *u_ptr = oci->post_proc_buffer.u_buffer;
-        unsigned char *v_ptr = oci->post_proc_buffer.v_buffer;
-        int y_stride = oci->post_proc_buffer.y_stride;
-        MODE_INFO *mi = oci->mi;
-
-        for (y = 0; y < height; y += 16)
-        {
-            for (x = 0; x < width; x += 16)
-            {
-                int Y = 0, U = 0, V = 0;
-
-                if (mi->mbmi.mode == B_PRED &&
-                    ((ppflags->display_mb_modes_flag & B_PRED) || ppflags->display_b_modes_flag))
-                {
-                    int by, bx;
-                    unsigned char *yl, *ul, *vl;
-                    union b_mode_info *bmi = mi->bmi;
-
-                    yl = y_ptr + x;
-                    ul = u_ptr + (x>>1);
-                    vl = v_ptr + (x>>1);
-
-                    for (by = 0; by < 16; by += 4)
-                    {
-                        for (bx = 0; bx < 16; bx += 4)
-                        {
-                            if ((ppflags->display_b_modes_flag & (1<<mi->mbmi.mode))
-                                || (ppflags->display_mb_modes_flag & B_PRED))
-                            {
-                                Y = B_PREDICTION_MODE_colors[bmi->as_mode][0];
-                                U = B_PREDICTION_MODE_colors[bmi->as_mode][1];
-                                V = B_PREDICTION_MODE_colors[bmi->as_mode][2];
-
-                                vp8_blend_b
-                                    (yl+bx, ul+(bx>>1), vl+(bx>>1), Y, U, V, 0xc000, y_stride);
-                            }
-                            bmi++;
-                        }
-
-                        yl += y_stride*4;
-                        ul += y_stride*1;
-                        vl += y_stride*1;
-                    }
-                }
-                else if (ppflags->display_mb_modes_flag & (1<<mi->mbmi.mode))
-                {
-                    Y = MB_PREDICTION_MODE_colors[mi->mbmi.mode][0];
-                    U = MB_PREDICTION_MODE_colors[mi->mbmi.mode][1];
-                    V = MB_PREDICTION_MODE_colors[mi->mbmi.mode][2];
-
-                    vp8_blend_mb_inner
-                        (y_ptr+x, u_ptr+(x>>1), v_ptr+(x>>1), Y, U, V, 0xc000, y_stride);
-                }
-
-                mi++;
-            }
-            y_ptr += y_stride*16;
-            u_ptr += y_stride*4;
-            v_ptr += y_stride*4;
-
-            mi++;
-        }
-    }
-
-    /* Color in frame reference blocks */
-    if ((flags & VP8D_DEBUG_CLR_FRM_REF_BLKS) && ppflags->display_ref_frame_flag)
-    {
-        int y, x;
-        YV12_BUFFER_CONFIG *post = &oci->post_proc_buffer;
-        int width  = post->y_width;
-        int height = post->y_height;
-        unsigned char *y_ptr = oci->post_proc_buffer.y_buffer;
-        unsigned char *u_ptr = oci->post_proc_buffer.u_buffer;
-        unsigned char *v_ptr = oci->post_proc_buffer.v_buffer;
-        int y_stride = oci->post_proc_buffer.y_stride;
-        MODE_INFO *mi = oci->mi;
-
-        for (y = 0; y < height; y += 16)
-        {
-            for (x = 0; x < width; x +=16)
-            {
-                int Y = 0, U = 0, V = 0;
-
-                if (ppflags->display_ref_frame_flag & (1<<mi->mbmi.ref_frame))
-                {
-                    Y = MV_REFERENCE_FRAME_colors[mi->mbmi.ref_frame][0];
-                    U = MV_REFERENCE_FRAME_colors[mi->mbmi.ref_frame][1];
-                    V = MV_REFERENCE_FRAME_colors[mi->mbmi.ref_frame][2];
-
-                    vp8_blend_mb_outer
-                        (y_ptr+x, u_ptr+(x>>1), v_ptr+(x>>1), Y, U, V, 0xc000, y_stride);
-                }
-
-                mi++;
-            }
-            y_ptr += y_stride*16;
-            u_ptr += y_stride*4;
-            v_ptr += y_stride*4;
-
-            mi++;
-        }
-    }
-#endif
-
-    *dest = oci->post_proc_buffer;
-
-    /* handle problem with extending borders */
-    dest->y_width = oci->Width;
-    dest->y_height = oci->Height;
-    dest->uv_height = dest->y_height / 2;
-    return 0;
-}
-#endif
diff --git a/vp8/common/postproc.h b/vp8/common/postproc.h
deleted file mode 100644 (file)
index 0fa12a7..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#ifndef VP8_COMMON_POSTPROC_H_
-#define VP8_COMMON_POSTPROC_H_
-
-#include "vpx_ports/mem.h"
-struct postproc_state
-{
-    int           last_q;
-    int           last_noise;
-    char          noise[3072];
-    int           last_base_qindex;
-    int           last_frame_valid;
-    DECLARE_ALIGNED(16, char, blackclamp[16]);
-    DECLARE_ALIGNED(16, char, whiteclamp[16]);
-    DECLARE_ALIGNED(16, char, bothclamp[16]);
-};
-#include "onyxc_int.h"
-#include "ppflags.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-int vp8_post_proc_frame(struct VP8Common *oci, YV12_BUFFER_CONFIG *dest,
-                        vp8_ppflags_t *flags);
-
-
-void vp8_de_noise(struct VP8Common           *oci,
-                  YV12_BUFFER_CONFIG         *source,
-                  YV12_BUFFER_CONFIG         *post,
-                  int                         q,
-                  int                         low_var_thresh,
-                  int                         flag,
-                  int                         uvfilter);
-
-void vp8_deblock(struct VP8Common           *oci,
-                 YV12_BUFFER_CONFIG         *source,
-                 YV12_BUFFER_CONFIG         *post,
-                 int                         q,
-                 int                         low_var_thresh,
-                 int                         flag);
-
-#define MFQE_PRECISION 4
-
-void vp8_multiframe_quality_enhance(struct VP8Common *cm);
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP8_COMMON_POSTPROC_H_
diff --git a/vp8/common/ppflags.h b/vp8/common/ppflags.h
deleted file mode 100644 (file)
index 768224a..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#ifndef VP8_COMMON_PPFLAGS_H_
-#define VP8_COMMON_PPFLAGS_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-enum
-{
-    VP8D_NOFILTERING            = 0,
-    VP8D_DEBLOCK                = 1<<0,
-    VP8D_DEMACROBLOCK           = 1<<1,
-    VP8D_ADDNOISE               = 1<<2,
-    VP8D_DEBUG_TXT_FRAME_INFO   = 1<<3,
-    VP8D_DEBUG_TXT_MBLK_MODES   = 1<<4,
-    VP8D_DEBUG_TXT_DC_DIFF      = 1<<5,
-    VP8D_DEBUG_TXT_RATE_INFO    = 1<<6,
-    VP8D_DEBUG_DRAW_MV          = 1<<7,
-    VP8D_DEBUG_CLR_BLK_MODES    = 1<<8,
-    VP8D_DEBUG_CLR_FRM_REF_BLKS = 1<<9,
-    VP8D_MFQE                   = 1<<10
-};
-
-typedef struct
-{
-    int post_proc_flag;
-    int deblocking_level;
-    int noise_level;
-    int display_ref_frame_flag;
-    int display_mb_modes_flag;
-    int display_b_modes_flag;
-    int display_mv_flag;
-} vp8_ppflags_t;
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP8_COMMON_PPFLAGS_H_
diff --git a/vp8/common/quant_common.c b/vp8/common/quant_common.c
deleted file mode 100644 (file)
index 05f9210..0000000
+++ /dev/null
@@ -1,135 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#include "quant_common.h"
-
-static const int dc_qlookup[QINDEX_RANGE] =
-{
-    4,    5,    6,    7,    8,    9,   10,   10,   11,   12,   13,   14,   15,   16,   17,   17,
-    18,   19,   20,   20,   21,   21,   22,   22,   23,   23,   24,   25,   25,   26,   27,   28,
-    29,   30,   31,   32,   33,   34,   35,   36,   37,   37,   38,   39,   40,   41,   42,   43,
-    44,   45,   46,   46,   47,   48,   49,   50,   51,   52,   53,   54,   55,   56,   57,   58,
-    59,   60,   61,   62,   63,   64,   65,   66,   67,   68,   69,   70,   71,   72,   73,   74,
-    75,   76,   76,   77,   78,   79,   80,   81,   82,   83,   84,   85,   86,   87,   88,   89,
-    91,   93,   95,   96,   98,  100,  101,  102,  104,  106,  108,  110,  112,  114,  116,  118,
-    122,  124,  126,  128,  130,  132,  134,  136,  138,  140,  143,  145,  148,  151,  154,  157,
-};
-
-static const int ac_qlookup[QINDEX_RANGE] =
-{
-    4,    5,    6,    7,    8,    9,   10,   11,   12,   13,   14,   15,   16,   17,   18,   19,
-    20,   21,   22,   23,   24,   25,   26,   27,   28,   29,   30,   31,   32,   33,   34,   35,
-    36,   37,   38,   39,   40,   41,   42,   43,   44,   45,   46,   47,   48,   49,   50,   51,
-    52,   53,   54,   55,   56,   57,   58,   60,   62,   64,   66,   68,   70,   72,   74,   76,
-    78,   80,   82,   84,   86,   88,   90,   92,   94,   96,   98,  100,  102,  104,  106,  108,
-    110,  112,  114,  116,  119,  122,  125,  128,  131,  134,  137,  140,  143,  146,  149,  152,
-    155,  158,  161,  164,  167,  170,  173,  177,  181,  185,  189,  193,  197,  201,  205,  209,
-    213,  217,  221,  225,  229,  234,  239,  245,  249,  254,  259,  264,  269,  274,  279,  284,
-};
-
-
-int vp8_dc_quant(int QIndex, int Delta)
-{
-    int retval;
-
-    QIndex = QIndex + Delta;
-
-    if (QIndex > 127)
-        QIndex = 127;
-    else if (QIndex < 0)
-        QIndex = 0;
-
-    retval = dc_qlookup[ QIndex ];
-    return retval;
-}
-
-int vp8_dc2quant(int QIndex, int Delta)
-{
-    int retval;
-
-    QIndex = QIndex + Delta;
-
-    if (QIndex > 127)
-        QIndex = 127;
-    else if (QIndex < 0)
-        QIndex = 0;
-
-    retval = dc_qlookup[ QIndex ] * 2;
-    return retval;
-
-}
-int vp8_dc_uv_quant(int QIndex, int Delta)
-{
-    int retval;
-
-    QIndex = QIndex + Delta;
-
-    if (QIndex > 127)
-        QIndex = 127;
-    else if (QIndex < 0)
-        QIndex = 0;
-
-    retval = dc_qlookup[ QIndex ];
-
-    if (retval > 132)
-        retval = 132;
-
-    return retval;
-}
-
-int vp8_ac_yquant(int QIndex)
-{
-    int retval;
-
-    if (QIndex > 127)
-        QIndex = 127;
-    else if (QIndex < 0)
-        QIndex = 0;
-
-    retval = ac_qlookup[ QIndex ];
-    return retval;
-}
-
-int vp8_ac2quant(int QIndex, int Delta)
-{
-    int retval;
-
-    QIndex = QIndex + Delta;
-
-    if (QIndex > 127)
-        QIndex = 127;
-    else if (QIndex < 0)
-        QIndex = 0;
-
-    /* For all x in [0..284], x*155/100 is bitwise equal to (x*101581) >> 16.
-     * The smallest precision for that is '(x*6349) >> 12' but 16 is a good
-     * word size. */
-    retval = (ac_qlookup[ QIndex ] * 101581) >> 16;
-
-    if (retval < 8)
-        retval = 8;
-
-    return retval;
-}
-int vp8_ac_uv_quant(int QIndex, int Delta)
-{
-    int retval;
-
-    QIndex = QIndex + Delta;
-
-    if (QIndex > 127)
-        QIndex = 127;
-    else if (QIndex < 0)
-        QIndex = 0;
-
-    retval = ac_qlookup[ QIndex ];
-    return retval;
-}
diff --git a/vp8/common/quant_common.h b/vp8/common/quant_common.h
deleted file mode 100644 (file)
index 700b5e6..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#ifndef VP8_COMMON_QUANT_COMMON_H_
-#define VP8_COMMON_QUANT_COMMON_H_
-
-
-#include "string.h"
-#include "blockd.h"
-#include "onyxc_int.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-extern int vp8_ac_yquant(int QIndex);
-extern int vp8_dc_quant(int QIndex, int Delta);
-extern int vp8_dc2quant(int QIndex, int Delta);
-extern int vp8_ac2quant(int QIndex, int Delta);
-extern int vp8_dc_uv_quant(int QIndex, int Delta);
-extern int vp8_ac_uv_quant(int QIndex, int Delta);
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP8_COMMON_QUANT_COMMON_H_
diff --git a/vp8/common/reconinter.c b/vp8/common/reconinter.c
deleted file mode 100644 (file)
index e302595..0000000
+++ /dev/null
@@ -1,544 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#include <limits.h>
-#include <string.h>
-
-#include "vpx_config.h"
-#include "vp8_rtcd.h"
-#include "vpx/vpx_integer.h"
-#include "blockd.h"
-#include "reconinter.h"
-#if CONFIG_RUNTIME_CPU_DETECT
-#include "onyxc_int.h"
-#endif
-
-void vp8_copy_mem16x16_c(
-    unsigned char *src,
-    int src_stride,
-    unsigned char *dst,
-    int dst_stride)
-{
-
-    int r;
-
-    for (r = 0; r < 16; r++)
-    {
-        memcpy(dst, src, 16);
-
-        src += src_stride;
-        dst += dst_stride;
-
-    }
-
-}
-
-void vp8_copy_mem8x8_c(
-    unsigned char *src,
-    int src_stride,
-    unsigned char *dst,
-    int dst_stride)
-{
-    int r;
-
-    for (r = 0; r < 8; r++)
-    {
-        memcpy(dst, src, 8);
-
-        src += src_stride;
-        dst += dst_stride;
-
-    }
-
-}
-
-void vp8_copy_mem8x4_c(
-    unsigned char *src,
-    int src_stride,
-    unsigned char *dst,
-    int dst_stride)
-{
-    int r;
-
-    for (r = 0; r < 4; r++)
-    {
-        memcpy(dst, src, 8);
-
-        src += src_stride;
-        dst += dst_stride;
-
-    }
-
-}
-
-
-void vp8_build_inter_predictors_b(BLOCKD *d, int pitch, unsigned char *base_pre, int pre_stride, vp8_subpix_fn_t sppf)
-{
-    int r;
-    unsigned char *pred_ptr = d->predictor;
-    unsigned char *ptr;
-    ptr = base_pre + d->offset + (d->bmi.mv.as_mv.row >> 3) * pre_stride + (d->bmi.mv.as_mv.col >> 3);
-
-    if (d->bmi.mv.as_mv.row & 7 || d->bmi.mv.as_mv.col & 7)
-    {
-        sppf(ptr, pre_stride, d->bmi.mv.as_mv.col & 7, d->bmi.mv.as_mv.row & 7, pred_ptr, pitch);
-    }
-    else
-    {
-        for (r = 0; r < 4; r++)
-        {
-            pred_ptr[0]  = ptr[0];
-            pred_ptr[1]  = ptr[1];
-            pred_ptr[2]  = ptr[2];
-            pred_ptr[3]  = ptr[3];
-            pred_ptr     += pitch;
-            ptr         += pre_stride;
-        }
-    }
-}
-
-static void build_inter_predictors4b(MACROBLOCKD *x, BLOCKD *d, unsigned char *dst, int dst_stride, unsigned char *base_pre, int pre_stride)
-{
-    unsigned char *ptr;
-    ptr = base_pre + d->offset + (d->bmi.mv.as_mv.row >> 3) * pre_stride + (d->bmi.mv.as_mv.col >> 3);
-
-    if (d->bmi.mv.as_mv.row & 7 || d->bmi.mv.as_mv.col & 7)
-    {
-        x->subpixel_predict8x8(ptr, pre_stride, d->bmi.mv.as_mv.col & 7, d->bmi.mv.as_mv.row & 7, dst, dst_stride);
-    }
-    else
-    {
-        vp8_copy_mem8x8(ptr, pre_stride, dst, dst_stride);
-    }
-}
-
-static void build_inter_predictors2b(MACROBLOCKD *x, BLOCKD *d, unsigned char *dst, int dst_stride, unsigned char *base_pre, int pre_stride)
-{
-    unsigned char *ptr;
-    ptr = base_pre + d->offset + (d->bmi.mv.as_mv.row >> 3) * pre_stride + (d->bmi.mv.as_mv.col >> 3);
-
-    if (d->bmi.mv.as_mv.row & 7 || d->bmi.mv.as_mv.col & 7)
-    {
-        x->subpixel_predict8x4(ptr, pre_stride, d->bmi.mv.as_mv.col & 7, d->bmi.mv.as_mv.row & 7, dst, dst_stride);
-    }
-    else
-    {
-        vp8_copy_mem8x4(ptr, pre_stride, dst, dst_stride);
-    }
-}
-
-static void build_inter_predictors_b(BLOCKD *d, unsigned char *dst, int dst_stride, unsigned char *base_pre, int pre_stride, vp8_subpix_fn_t sppf)
-{
-    int r;
-    unsigned char *ptr;
-    ptr = base_pre + d->offset + (d->bmi.mv.as_mv.row >> 3) * pre_stride + (d->bmi.mv.as_mv.col >> 3);
-
-    if (d->bmi.mv.as_mv.row & 7 || d->bmi.mv.as_mv.col & 7)
-    {
-        sppf(ptr, pre_stride, d->bmi.mv.as_mv.col & 7, d->bmi.mv.as_mv.row & 7, dst, dst_stride);
-    }
-    else
-    {
-        for (r = 0; r < 4; r++)
-        {
-          dst[0]  = ptr[0];
-          dst[1]  = ptr[1];
-          dst[2]  = ptr[2];
-          dst[3]  = ptr[3];
-          dst     += dst_stride;
-          ptr     += pre_stride;
-        }
-    }
-}
-
-
-/*encoder only*/
-void vp8_build_inter16x16_predictors_mbuv(MACROBLOCKD *x)
-{
-    unsigned char *uptr, *vptr;
-    unsigned char *upred_ptr = &x->predictor[256];
-    unsigned char *vpred_ptr = &x->predictor[320];
-
-    int mv_row = x->mode_info_context->mbmi.mv.as_mv.row;
-    int mv_col = x->mode_info_context->mbmi.mv.as_mv.col;
-    int offset;
-    int pre_stride = x->pre.uv_stride;
-
-    /* calc uv motion vectors */
-    mv_row += 1 | (mv_row >> (sizeof(int) * CHAR_BIT - 1));
-    mv_col += 1 | (mv_col >> (sizeof(int) * CHAR_BIT - 1));
-    mv_row /= 2;
-    mv_col /= 2;
-    mv_row &= x->fullpixel_mask;
-    mv_col &= x->fullpixel_mask;
-
-    offset = (mv_row >> 3) * pre_stride + (mv_col >> 3);
-    uptr = x->pre.u_buffer + offset;
-    vptr = x->pre.v_buffer + offset;
-
-    if ((mv_row | mv_col) & 7)
-    {
-        x->subpixel_predict8x8(uptr, pre_stride, mv_col & 7, mv_row & 7, upred_ptr, 8);
-        x->subpixel_predict8x8(vptr, pre_stride, mv_col & 7, mv_row & 7, vpred_ptr, 8);
-    }
-    else
-    {
-        vp8_copy_mem8x8(uptr, pre_stride, upred_ptr, 8);
-        vp8_copy_mem8x8(vptr, pre_stride, vpred_ptr, 8);
-    }
-}
-
-/*encoder only*/
-void vp8_build_inter4x4_predictors_mbuv(MACROBLOCKD *x)
-{
-    int i, j;
-    int pre_stride = x->pre.uv_stride;
-    unsigned char *base_pre;
-
-    /* build uv mvs */
-    for (i = 0; i < 2; i++)
-    {
-        for (j = 0; j < 2; j++)
-        {
-            int yoffset = i * 8 + j * 2;
-            int uoffset = 16 + i * 2 + j;
-            int voffset = 20 + i * 2 + j;
-
-            int temp;
-
-            temp = x->block[yoffset  ].bmi.mv.as_mv.row
-                   + x->block[yoffset+1].bmi.mv.as_mv.row
-                   + x->block[yoffset+4].bmi.mv.as_mv.row
-                   + x->block[yoffset+5].bmi.mv.as_mv.row;
-
-            temp += 4 + ((temp >> (sizeof(temp) * CHAR_BIT - 1)) * 8);
-
-            x->block[uoffset].bmi.mv.as_mv.row = (temp / 8) & x->fullpixel_mask;
-
-            temp = x->block[yoffset  ].bmi.mv.as_mv.col
-                   + x->block[yoffset+1].bmi.mv.as_mv.col
-                   + x->block[yoffset+4].bmi.mv.as_mv.col
-                   + x->block[yoffset+5].bmi.mv.as_mv.col;
-
-            temp += 4 + ((temp >> (sizeof(temp) * CHAR_BIT - 1)) * 8);
-
-            x->block[uoffset].bmi.mv.as_mv.col = (temp / 8) & x->fullpixel_mask;
-
-            x->block[voffset].bmi.mv.as_int = x->block[uoffset].bmi.mv.as_int;
-        }
-    }
-
-    base_pre = x->pre.u_buffer;
-    for (i = 16; i < 20; i += 2)
-    {
-        BLOCKD *d0 = &x->block[i];
-        BLOCKD *d1 = &x->block[i+1];
-
-        if (d0->bmi.mv.as_int == d1->bmi.mv.as_int)
-            build_inter_predictors2b(x, d0, d0->predictor, 8, base_pre, pre_stride);
-        else
-        {
-            vp8_build_inter_predictors_b(d0, 8, base_pre, pre_stride, x->subpixel_predict);
-            vp8_build_inter_predictors_b(d1, 8, base_pre, pre_stride, x->subpixel_predict);
-        }
-    }
-
-    base_pre = x->pre.v_buffer;
-    for (i = 20; i < 24; i += 2)
-    {
-        BLOCKD *d0 = &x->block[i];
-        BLOCKD *d1 = &x->block[i+1];
-
-        if (d0->bmi.mv.as_int == d1->bmi.mv.as_int)
-            build_inter_predictors2b(x, d0, d0->predictor, 8, base_pre, pre_stride);
-        else
-        {
-            vp8_build_inter_predictors_b(d0, 8, base_pre, pre_stride, x->subpixel_predict);
-            vp8_build_inter_predictors_b(d1, 8, base_pre, pre_stride, x->subpixel_predict);
-        }
-    }
-}
-
-
-/*encoder only*/
-void vp8_build_inter16x16_predictors_mby(MACROBLOCKD *x,
-                                         unsigned char *dst_y,
-                                         int dst_ystride)
-{
-    unsigned char *ptr_base;
-    unsigned char *ptr;
-    int mv_row = x->mode_info_context->mbmi.mv.as_mv.row;
-    int mv_col = x->mode_info_context->mbmi.mv.as_mv.col;
-    int pre_stride = x->pre.y_stride;
-
-    ptr_base = x->pre.y_buffer;
-    ptr = ptr_base + (mv_row >> 3) * pre_stride + (mv_col >> 3);
-
-    if ((mv_row | mv_col) & 7)
-    {
-        x->subpixel_predict16x16(ptr, pre_stride, mv_col & 7, mv_row & 7,
-                                 dst_y, dst_ystride);
-    }
-    else
-    {
-        vp8_copy_mem16x16(ptr, pre_stride, dst_y,
-            dst_ystride);
-    }
-}
-
-static void clamp_mv_to_umv_border(MV *mv, const MACROBLOCKD *xd)
-{
-    /* If the MV points so far into the UMV border that no visible pixels
-     * are used for reconstruction, the subpel part of the MV can be
-     * discarded and the MV limited to 16 pixels with equivalent results.
-     *
-     * This limit kicks in at 19 pixels for the top and left edges, for
-     * the 16 pixels plus 3 taps right of the central pixel when subpel
-     * filtering. The bottom and right edges use 16 pixels plus 2 pixels
-     * left of the central pixel when filtering.
-     */
-    if (mv->col < (xd->mb_to_left_edge - (19 << 3)))
-        mv->col = xd->mb_to_left_edge - (16 << 3);
-    else if (mv->col > xd->mb_to_right_edge + (18 << 3))
-        mv->col = xd->mb_to_right_edge + (16 << 3);
-
-    if (mv->row < (xd->mb_to_top_edge - (19 << 3)))
-        mv->row = xd->mb_to_top_edge - (16 << 3);
-    else if (mv->row > xd->mb_to_bottom_edge + (18 << 3))
-        mv->row = xd->mb_to_bottom_edge + (16 << 3);
-}
-
-/* A version of the above function for chroma block MVs.*/
-static void clamp_uvmv_to_umv_border(MV *mv, const MACROBLOCKD *xd)
-{
-    mv->col = (2*mv->col < (xd->mb_to_left_edge - (19 << 3))) ?
-        (xd->mb_to_left_edge - (16 << 3)) >> 1 : mv->col;
-    mv->col = (2*mv->col > xd->mb_to_right_edge + (18 << 3)) ?
-        (xd->mb_to_right_edge + (16 << 3)) >> 1 : mv->col;
-
-    mv->row = (2*mv->row < (xd->mb_to_top_edge - (19 << 3))) ?
-        (xd->mb_to_top_edge - (16 << 3)) >> 1 : mv->row;
-    mv->row = (2*mv->row > xd->mb_to_bottom_edge + (18 << 3)) ?
-        (xd->mb_to_bottom_edge + (16 << 3)) >> 1 : mv->row;
-}
-
-void vp8_build_inter16x16_predictors_mb(MACROBLOCKD *x,
-                                        unsigned char *dst_y,
-                                        unsigned char *dst_u,
-                                        unsigned char *dst_v,
-                                        int dst_ystride,
-                                        int dst_uvstride)
-{
-    int offset;
-    unsigned char *ptr;
-    unsigned char *uptr, *vptr;
-
-    int_mv _16x16mv;
-
-    unsigned char *ptr_base = x->pre.y_buffer;
-    int pre_stride = x->pre.y_stride;
-
-    _16x16mv.as_int = x->mode_info_context->mbmi.mv.as_int;
-
-    if (x->mode_info_context->mbmi.need_to_clamp_mvs)
-    {
-        clamp_mv_to_umv_border(&_16x16mv.as_mv, x);
-    }
-
-    ptr = ptr_base + ( _16x16mv.as_mv.row >> 3) * pre_stride + (_16x16mv.as_mv.col >> 3);
-
-    if ( _16x16mv.as_int & 0x00070007)
-    {
-        x->subpixel_predict16x16(ptr, pre_stride, _16x16mv.as_mv.col & 7,  _16x16mv.as_mv.row & 7, dst_y, dst_ystride);
-    }
-    else
-    {
-        vp8_copy_mem16x16(ptr, pre_stride, dst_y, dst_ystride);
-    }
-
-    /* calc uv motion vectors */
-    _16x16mv.as_mv.row += 1 | (_16x16mv.as_mv.row >> (sizeof(int) * CHAR_BIT - 1));
-    _16x16mv.as_mv.col += 1 | (_16x16mv.as_mv.col >> (sizeof(int) * CHAR_BIT - 1));
-    _16x16mv.as_mv.row /= 2;
-    _16x16mv.as_mv.col /= 2;
-    _16x16mv.as_mv.row &= x->fullpixel_mask;
-    _16x16mv.as_mv.col &= x->fullpixel_mask;
-
-    pre_stride >>= 1;
-    offset = ( _16x16mv.as_mv.row >> 3) * pre_stride + (_16x16mv.as_mv.col >> 3);
-    uptr = x->pre.u_buffer + offset;
-    vptr = x->pre.v_buffer + offset;
-
-    if ( _16x16mv.as_int & 0x00070007)
-    {
-        x->subpixel_predict8x8(uptr, pre_stride, _16x16mv.as_mv.col & 7,  _16x16mv.as_mv.row & 7, dst_u, dst_uvstride);
-        x->subpixel_predict8x8(vptr, pre_stride, _16x16mv.as_mv.col & 7,  _16x16mv.as_mv.row & 7, dst_v, dst_uvstride);
-    }
-    else
-    {
-        vp8_copy_mem8x8(uptr, pre_stride, dst_u, dst_uvstride);
-        vp8_copy_mem8x8(vptr, pre_stride, dst_v, dst_uvstride);
-    }
-}
-
-static void build_inter4x4_predictors_mb(MACROBLOCKD *x)
-{
-    int i;
-    unsigned char *base_dst = x->dst.y_buffer;
-    unsigned char *base_pre = x->pre.y_buffer;
-
-    if (x->mode_info_context->mbmi.partitioning < 3)
-    {
-        BLOCKD *b;
-        int dst_stride = x->dst.y_stride;
-
-        x->block[ 0].bmi = x->mode_info_context->bmi[ 0];
-        x->block[ 2].bmi = x->mode_info_context->bmi[ 2];
-        x->block[ 8].bmi = x->mode_info_context->bmi[ 8];
-        x->block[10].bmi = x->mode_info_context->bmi[10];
-        if (x->mode_info_context->mbmi.need_to_clamp_mvs)
-        {
-            clamp_mv_to_umv_border(&x->block[ 0].bmi.mv.as_mv, x);
-            clamp_mv_to_umv_border(&x->block[ 2].bmi.mv.as_mv, x);
-            clamp_mv_to_umv_border(&x->block[ 8].bmi.mv.as_mv, x);
-            clamp_mv_to_umv_border(&x->block[10].bmi.mv.as_mv, x);
-        }
-
-        b = &x->block[ 0];
-        build_inter_predictors4b(x, b, base_dst + b->offset, dst_stride, base_pre, dst_stride);
-        b = &x->block[ 2];
-        build_inter_predictors4b(x, b, base_dst + b->offset, dst_stride, base_pre, dst_stride);
-        b = &x->block[ 8];
-        build_inter_predictors4b(x, b, base_dst + b->offset, dst_stride, base_pre, dst_stride);
-        b = &x->block[10];
-        build_inter_predictors4b(x, b, base_dst + b->offset, dst_stride, base_pre, dst_stride);
-    }
-    else
-    {
-        for (i = 0; i < 16; i += 2)
-        {
-            BLOCKD *d0 = &x->block[i];
-            BLOCKD *d1 = &x->block[i+1];
-            int dst_stride = x->dst.y_stride;
-
-            x->block[i+0].bmi = x->mode_info_context->bmi[i+0];
-            x->block[i+1].bmi = x->mode_info_context->bmi[i+1];
-            if (x->mode_info_context->mbmi.need_to_clamp_mvs)
-            {
-                clamp_mv_to_umv_border(&x->block[i+0].bmi.mv.as_mv, x);
-                clamp_mv_to_umv_border(&x->block[i+1].bmi.mv.as_mv, x);
-            }
-
-            if (d0->bmi.mv.as_int == d1->bmi.mv.as_int)
-                build_inter_predictors2b(x, d0, base_dst + d0->offset, dst_stride, base_pre, dst_stride);
-            else
-            {
-                build_inter_predictors_b(d0, base_dst + d0->offset, dst_stride, base_pre, dst_stride, x->subpixel_predict);
-                build_inter_predictors_b(d1, base_dst + d1->offset, dst_stride, base_pre, dst_stride, x->subpixel_predict);
-            }
-
-        }
-
-    }
-    base_dst = x->dst.u_buffer;
-    base_pre = x->pre.u_buffer;
-    for (i = 16; i < 20; i += 2)
-    {
-        BLOCKD *d0 = &x->block[i];
-        BLOCKD *d1 = &x->block[i+1];
-        int dst_stride = x->dst.uv_stride;
-
-        /* Note: uv mvs already clamped in build_4x4uvmvs() */
-
-        if (d0->bmi.mv.as_int == d1->bmi.mv.as_int)
-            build_inter_predictors2b(x, d0, base_dst + d0->offset, dst_stride, base_pre, dst_stride);
-        else
-        {
-            build_inter_predictors_b(d0, base_dst + d0->offset, dst_stride, base_pre, dst_stride, x->subpixel_predict);
-            build_inter_predictors_b(d1, base_dst + d1->offset, dst_stride, base_pre, dst_stride, x->subpixel_predict);
-        }
-    }
-
-    base_dst = x->dst.v_buffer;
-    base_pre = x->pre.v_buffer;
-    for (i = 20; i < 24; i += 2)
-    {
-        BLOCKD *d0 = &x->block[i];
-        BLOCKD *d1 = &x->block[i+1];
-        int dst_stride = x->dst.uv_stride;
-
-        /* Note: uv mvs already clamped in build_4x4uvmvs() */
-
-        if (d0->bmi.mv.as_int == d1->bmi.mv.as_int)
-            build_inter_predictors2b(x, d0, base_dst + d0->offset, dst_stride, base_pre, dst_stride);
-        else
-        {
-            build_inter_predictors_b(d0, base_dst + d0->offset, dst_stride, base_pre, dst_stride, x->subpixel_predict);
-            build_inter_predictors_b(d1, base_dst + d1->offset, dst_stride, base_pre, dst_stride, x->subpixel_predict);
-        }
-    }
-}
-
-static
-void build_4x4uvmvs(MACROBLOCKD *x)
-{
-    int i, j;
-
-    for (i = 0; i < 2; i++)
-    {
-        for (j = 0; j < 2; j++)
-        {
-            int yoffset = i * 8 + j * 2;
-            int uoffset = 16 + i * 2 + j;
-            int voffset = 20 + i * 2 + j;
-
-            int temp;
-
-            temp = x->mode_info_context->bmi[yoffset + 0].mv.as_mv.row
-                 + x->mode_info_context->bmi[yoffset + 1].mv.as_mv.row
-                 + x->mode_info_context->bmi[yoffset + 4].mv.as_mv.row
-                 + x->mode_info_context->bmi[yoffset + 5].mv.as_mv.row;
-
-            temp += 4 + ((temp >> (sizeof(temp) * CHAR_BIT - 1)) * 8);
-
-            x->block[uoffset].bmi.mv.as_mv.row = (temp / 8) & x->fullpixel_mask;
-
-            temp = x->mode_info_context->bmi[yoffset + 0].mv.as_mv.col
-                 + x->mode_info_context->bmi[yoffset + 1].mv.as_mv.col
-                 + x->mode_info_context->bmi[yoffset + 4].mv.as_mv.col
-                 + x->mode_info_context->bmi[yoffset + 5].mv.as_mv.col;
-
-            temp += 4 + ((temp >> (sizeof(temp) * CHAR_BIT - 1)) * 8);
-
-            x->block[uoffset].bmi.mv.as_mv.col = (temp / 8) & x->fullpixel_mask;
-
-            if (x->mode_info_context->mbmi.need_to_clamp_mvs)
-                clamp_uvmv_to_umv_border(&x->block[uoffset].bmi.mv.as_mv, x);
-
-            x->block[voffset].bmi.mv.as_int = x->block[uoffset].bmi.mv.as_int;
-        }
-    }
-}
-
-void vp8_build_inter_predictors_mb(MACROBLOCKD *xd)
-{
-    if (xd->mode_info_context->mbmi.mode != SPLITMV)
-    {
-        vp8_build_inter16x16_predictors_mb(xd, xd->dst.y_buffer,
-                                           xd->dst.u_buffer, xd->dst.v_buffer,
-                                           xd->dst.y_stride, xd->dst.uv_stride);
-    }
-    else
-    {
-        build_4x4uvmvs(xd);
-        build_inter4x4_predictors_mb(xd);
-    }
-}
diff --git a/vp8/common/reconinter.h b/vp8/common/reconinter.h
deleted file mode 100644 (file)
index ba979b9..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#ifndef VP8_COMMON_RECONINTER_H_
-#define VP8_COMMON_RECONINTER_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-extern void vp8_build_inter_predictors_mb(MACROBLOCKD *x);
-extern void vp8_build_inter16x16_predictors_mb(MACROBLOCKD *x,
-                                               unsigned char *dst_y,
-                                               unsigned char *dst_u,
-                                               unsigned char *dst_v,
-                                               int dst_ystride,
-                                               int dst_uvstride);
-
-
-extern void vp8_build_inter16x16_predictors_mby(MACROBLOCKD *x,
-                                                unsigned char *dst_y,
-                                                int dst_ystride);
-extern void vp8_build_inter_predictors_b(BLOCKD *d, int pitch,
-                                         unsigned char *base_pre,
-                                         int pre_stride,
-                                         vp8_subpix_fn_t sppf);
-
-extern void vp8_build_inter16x16_predictors_mbuv(MACROBLOCKD *x);
-extern void vp8_build_inter4x4_predictors_mbuv(MACROBLOCKD *x);
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP8_COMMON_RECONINTER_H_
diff --git a/vp8/common/reconintra.c b/vp8/common/reconintra.c
deleted file mode 100644 (file)
index 356655d..0000000
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#include "./vpx_config.h"
-#include "./vpx_dsp_rtcd.h"
-#include "./vp8_rtcd.h"
-#include "vpx_mem/vpx_mem.h"
-#include "vpx_ports/vpx_once.h"
-#include "blockd.h"
-#include "vp8/common/reconintra.h"
-#include "vp8/common/reconintra4x4.h"
-
-enum {
-    SIZE_16,
-    SIZE_8,
-    NUM_SIZES,
-};
-
-typedef void (*intra_pred_fn)(uint8_t *dst, ptrdiff_t stride,
-                              const uint8_t *above, const uint8_t *left);
-
-static intra_pred_fn pred[4][NUM_SIZES];
-static intra_pred_fn dc_pred[2][2][NUM_SIZES];
-
-static void vp8_init_intra_predictors_internal(void)
-{
-#define INIT_SIZE(sz) \
-    pred[V_PRED][SIZE_##sz] = vpx_v_predictor_##sz##x##sz; \
-    pred[H_PRED][SIZE_##sz] = vpx_h_predictor_##sz##x##sz; \
-    pred[TM_PRED][SIZE_##sz] = vpx_tm_predictor_##sz##x##sz; \
- \
-    dc_pred[0][0][SIZE_##sz] = vpx_dc_128_predictor_##sz##x##sz; \
-    dc_pred[0][1][SIZE_##sz] = vpx_dc_top_predictor_##sz##x##sz; \
-    dc_pred[1][0][SIZE_##sz] = vpx_dc_left_predictor_##sz##x##sz; \
-    dc_pred[1][1][SIZE_##sz] = vpx_dc_predictor_##sz##x##sz
-
-    INIT_SIZE(16);
-    INIT_SIZE(8);
-    vp8_init_intra4x4_predictors_internal();
-}
-
-void vp8_build_intra_predictors_mby_s(MACROBLOCKD *x,
-                                      unsigned char * yabove_row,
-                                      unsigned char * yleft,
-                                      int left_stride,
-                                      unsigned char * ypred_ptr,
-                                      int y_stride)
-{
-    MB_PREDICTION_MODE mode = x->mode_info_context->mbmi.mode;
-    DECLARE_ALIGNED(16, uint8_t, yleft_col[16]);
-    int i;
-    intra_pred_fn fn;
-
-    for (i = 0; i < 16; i++)
-    {
-        yleft_col[i] = yleft[i* left_stride];
-    }
-
-    if (mode == DC_PRED)
-    {
-        fn = dc_pred[x->left_available][x->up_available][SIZE_16];
-    }
-    else
-    {
-        fn = pred[mode][SIZE_16];
-    }
-
-    fn(ypred_ptr, y_stride, yabove_row, yleft_col);
-}
-
-void vp8_build_intra_predictors_mbuv_s(MACROBLOCKD *x,
-                                       unsigned char * uabove_row,
-                                       unsigned char * vabove_row,
-                                       unsigned char * uleft,
-                                       unsigned char * vleft,
-                                       int left_stride,
-                                       unsigned char * upred_ptr,
-                                       unsigned char * vpred_ptr,
-                                       int pred_stride)
-{
-    MB_PREDICTION_MODE uvmode = x->mode_info_context->mbmi.uv_mode;
-    unsigned char uleft_col[8];
-    unsigned char vleft_col[8];
-    int i;
-    intra_pred_fn fn;
-
-    for (i = 0; i < 8; i++)
-    {
-        uleft_col[i] = uleft[i * left_stride];
-        vleft_col[i] = vleft[i * left_stride];
-    }
-
-    if (uvmode == DC_PRED)
-    {
-        fn = dc_pred[x->left_available][x->up_available][SIZE_8];
-    }
-    else
-    {
-        fn = pred[uvmode][SIZE_8];
-    }
-
-    fn(upred_ptr, pred_stride, uabove_row, uleft_col);
-    fn(vpred_ptr, pred_stride, vabove_row, vleft_col);
-}
-
-void vp8_init_intra_predictors(void)
-{
-    once(vp8_init_intra_predictors_internal);
-}
diff --git a/vp8/common/reconintra.h b/vp8/common/reconintra.h
deleted file mode 100644 (file)
index b6225a6..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#ifndef VP8_COMMON_RECONINTRA_H_
-#define VP8_COMMON_RECONINTRA_H_
-
-#include "vp8/common/blockd.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-void vp8_build_intra_predictors_mby_s(MACROBLOCKD *x,
-                                      unsigned char *yabove_row,
-                                      unsigned char *yleft,
-                                      int left_stride,
-                                      unsigned char *ypred_ptr,
-                                      int y_stride);
-
-void vp8_build_intra_predictors_mbuv_s(MACROBLOCKD *x,
-                                       unsigned char * uabove_row,
-                                       unsigned char * vabove_row,
-                                       unsigned char * uleft,
-                                       unsigned char * vleft,
-                                       int left_stride,
-                                       unsigned char * upred_ptr,
-                                       unsigned char * vpred_ptr,
-                                       int pred_stride);
-
-void vp8_init_intra_predictors(void);
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP8_COMMON_RECONINTRA_H_
diff --git a/vp8/common/reconintra4x4.c b/vp8/common/reconintra4x4.c
deleted file mode 100644 (file)
index 35ad891..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#include <string.h>
-
-#include "vpx_config.h"
-#include "./vpx_dsp_rtcd.h"
-#include "vp8_rtcd.h"
-#include "blockd.h"
-
-typedef void (*intra_pred_fn)(uint8_t *dst, ptrdiff_t stride,
-                              const uint8_t *above, const uint8_t *left);
-
-static intra_pred_fn pred[10];
-
-void vp8_init_intra4x4_predictors_internal(void)
-{
-    pred[B_DC_PRED] = vpx_dc_predictor_4x4;
-    pred[B_TM_PRED] = vpx_tm_predictor_4x4;
-    pred[B_VE_PRED] = vpx_ve_predictor_4x4;
-    pred[B_HE_PRED] = vpx_he_predictor_4x4;
-    pred[B_LD_PRED] = vpx_d45e_predictor_4x4;
-    pred[B_RD_PRED] = vpx_d135_predictor_4x4;
-    pred[B_VR_PRED] = vpx_d117_predictor_4x4;
-    pred[B_VL_PRED] = vpx_d63f_predictor_4x4;
-    pred[B_HD_PRED] = vpx_d153_predictor_4x4;
-    pred[B_HU_PRED] = vpx_d207_predictor_4x4;
-}
-
-void vp8_intra4x4_predict(unsigned char *above,
-                          unsigned char *yleft, int left_stride,
-                          B_PREDICTION_MODE b_mode,
-                          unsigned char *dst, int dst_stride,
-                          unsigned char top_left)
-{
-    unsigned char Left[4];
-    unsigned char Aboveb[12], *Above = Aboveb + 4;
-
-    Left[0] = yleft[0];
-    Left[1] = yleft[left_stride];
-    Left[2] = yleft[2 * left_stride];
-    Left[3] = yleft[3 * left_stride];
-    memcpy(Above, above, 8);
-    Above[-1] = top_left;
-
-    pred[b_mode](dst, dst_stride, Above, Left);
-}
diff --git a/vp8/common/reconintra4x4.h b/vp8/common/reconintra4x4.h
deleted file mode 100644 (file)
index 5dc5d13..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#ifndef VP8_COMMON_RECONINTRA4X4_H_
-#define VP8_COMMON_RECONINTRA4X4_H_
-#include "vp8/common/blockd.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-static INLINE void intra_prediction_down_copy(MACROBLOCKD *xd,
-                                              unsigned char *above_right_src)
-{
-    int dst_stride = xd->dst.y_stride;
-    unsigned char *above_right_dst = xd->dst.y_buffer - dst_stride + 16;
-
-    unsigned int *src_ptr = (unsigned int *)above_right_src;
-    unsigned int *dst_ptr0 = (unsigned int *)(above_right_dst + 4 * dst_stride);
-    unsigned int *dst_ptr1 = (unsigned int *)(above_right_dst + 8 * dst_stride);
-    unsigned int *dst_ptr2 = (unsigned int *)(above_right_dst + 12 * dst_stride);
-
-    *dst_ptr0 = *src_ptr;
-    *dst_ptr1 = *src_ptr;
-    *dst_ptr2 = *src_ptr;
-}
-
-void vp8_intra4x4_predict(unsigned char *Above,
-                          unsigned char *yleft, int left_stride,
-                          B_PREDICTION_MODE b_mode,
-                          unsigned char *dst, int dst_stride,
-                          unsigned char top_left);
-
-void vp8_init_intra4x4_predictors_internal(void);
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP8_COMMON_RECONINTRA4X4_H_
diff --git a/vp8/common/rtcd.c b/vp8/common/rtcd.c
deleted file mode 100644 (file)
index ab0e9b4..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-/*
- *  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.
- */
-#include "./vpx_config.h"
-#define RTCD_C
-#include "./vp8_rtcd.h"
-#include "vpx_ports/vpx_once.h"
-
-
-void vp8_rtcd()
-{
-    once(setup_rtcd_internal);
-}
diff --git a/vp8/common/rtcd_defs.pl b/vp8/common/rtcd_defs.pl
deleted file mode 100644 (file)
index a440352..0000000
+++ /dev/null
@@ -1,305 +0,0 @@
-sub vp8_common_forward_decls() {
-print <<EOF
-/*
- * VP8
- */
-
-struct blockd;
-struct macroblockd;
-struct loop_filter_info;
-
-/* Encoder forward decls */
-struct block;
-struct macroblock;
-struct variance_vtable;
-union int_mv;
-struct yv12_buffer_config;
-EOF
-}
-forward_decls qw/vp8_common_forward_decls/;
-
-#
-# system state
-#
-add_proto qw/void vp8_clear_system_state/, "";
-specialize qw/vp8_clear_system_state mmx/;
-$vp8_clear_system_state_mmx=vpx_reset_mmx_state;
-
-#
-# Dequant
-#
-add_proto qw/void vp8_dequantize_b/, "struct blockd*, short *dqc";
-specialize qw/vp8_dequantize_b mmx media neon msa/;
-$vp8_dequantize_b_media=vp8_dequantize_b_v6;
-
-add_proto qw/void vp8_dequant_idct_add/, "short *input, short *dq, unsigned char *output, int stride";
-specialize qw/vp8_dequant_idct_add mmx media neon dspr2 msa/;
-$vp8_dequant_idct_add_media=vp8_dequant_idct_add_v6;
-$vp8_dequant_idct_add_dspr2=vp8_dequant_idct_add_dspr2;
-
-add_proto qw/void vp8_dequant_idct_add_y_block/, "short *q, short *dq, unsigned char *dst, int stride, char *eobs";
-specialize qw/vp8_dequant_idct_add_y_block mmx sse2 media neon dspr2 msa/;
-$vp8_dequant_idct_add_y_block_media=vp8_dequant_idct_add_y_block_v6;
-$vp8_dequant_idct_add_y_block_dspr2=vp8_dequant_idct_add_y_block_dspr2;
-
-add_proto qw/void vp8_dequant_idct_add_uv_block/, "short *q, short *dq, unsigned char *dst_u, unsigned char *dst_v, int stride, char *eobs";
-specialize qw/vp8_dequant_idct_add_uv_block mmx sse2 media neon dspr2 msa/;
-$vp8_dequant_idct_add_uv_block_media=vp8_dequant_idct_add_uv_block_v6;
-$vp8_dequant_idct_add_y_block_dspr2=vp8_dequant_idct_add_y_block_dspr2;
-
-#
-# Loopfilter
-#
-add_proto qw/void vp8_loop_filter_mbv/, "unsigned char *y, unsigned char *u, unsigned char *v, int ystride, int uv_stride, struct loop_filter_info *lfi";
-specialize qw/vp8_loop_filter_mbv mmx sse2 media neon dspr2 msa/;
-$vp8_loop_filter_mbv_media=vp8_loop_filter_mbv_armv6;
-$vp8_loop_filter_mbv_dspr2=vp8_loop_filter_mbv_dspr2;
-
-add_proto qw/void vp8_loop_filter_bv/, "unsigned char *y, unsigned char *u, unsigned char *v, int ystride, int uv_stride, struct loop_filter_info *lfi";
-specialize qw/vp8_loop_filter_bv mmx sse2 media neon dspr2 msa/;
-$vp8_loop_filter_bv_media=vp8_loop_filter_bv_armv6;
-$vp8_loop_filter_bv_dspr2=vp8_loop_filter_bv_dspr2;
-
-add_proto qw/void vp8_loop_filter_mbh/, "unsigned char *y, unsigned char *u, unsigned char *v, int ystride, int uv_stride, struct loop_filter_info *lfi";
-specialize qw/vp8_loop_filter_mbh mmx sse2 media neon dspr2 msa/;
-$vp8_loop_filter_mbh_media=vp8_loop_filter_mbh_armv6;
-$vp8_loop_filter_mbh_dspr2=vp8_loop_filter_mbh_dspr2;
-
-add_proto qw/void vp8_loop_filter_bh/, "unsigned char *y, unsigned char *u, unsigned char *v, int ystride, int uv_stride, struct loop_filter_info *lfi";
-specialize qw/vp8_loop_filter_bh mmx sse2 media neon dspr2 msa/;
-$vp8_loop_filter_bh_media=vp8_loop_filter_bh_armv6;
-$vp8_loop_filter_bh_dspr2=vp8_loop_filter_bh_dspr2;
-
-
-add_proto qw/void vp8_loop_filter_simple_mbv/, "unsigned char *y, int ystride, const unsigned char *blimit";
-specialize qw/vp8_loop_filter_simple_mbv mmx sse2 media neon msa/;
-$vp8_loop_filter_simple_mbv_c=vp8_loop_filter_simple_vertical_edge_c;
-$vp8_loop_filter_simple_mbv_mmx=vp8_loop_filter_simple_vertical_edge_mmx;
-$vp8_loop_filter_simple_mbv_sse2=vp8_loop_filter_simple_vertical_edge_sse2;
-$vp8_loop_filter_simple_mbv_media=vp8_loop_filter_simple_vertical_edge_armv6;
-$vp8_loop_filter_simple_mbv_neon=vp8_loop_filter_mbvs_neon;
-$vp8_loop_filter_simple_mbv_msa=vp8_loop_filter_simple_vertical_edge_msa;
-
-add_proto qw/void vp8_loop_filter_simple_mbh/, "unsigned char *y, int ystride, const unsigned char *blimit";
-specialize qw/vp8_loop_filter_simple_mbh mmx sse2 media neon msa/;
-$vp8_loop_filter_simple_mbh_c=vp8_loop_filter_simple_horizontal_edge_c;
-$vp8_loop_filter_simple_mbh_mmx=vp8_loop_filter_simple_horizontal_edge_mmx;
-$vp8_loop_filter_simple_mbh_sse2=vp8_loop_filter_simple_horizontal_edge_sse2;
-$vp8_loop_filter_simple_mbh_media=vp8_loop_filter_simple_horizontal_edge_armv6;
-$vp8_loop_filter_simple_mbh_neon=vp8_loop_filter_mbhs_neon;
-$vp8_loop_filter_simple_mbh_msa=vp8_loop_filter_simple_horizontal_edge_msa;
-
-add_proto qw/void vp8_loop_filter_simple_bv/, "unsigned char *y, int ystride, const unsigned char *blimit";
-specialize qw/vp8_loop_filter_simple_bv mmx sse2 media neon msa/;
-$vp8_loop_filter_simple_bv_c=vp8_loop_filter_bvs_c;
-$vp8_loop_filter_simple_bv_mmx=vp8_loop_filter_bvs_mmx;
-$vp8_loop_filter_simple_bv_sse2=vp8_loop_filter_bvs_sse2;
-$vp8_loop_filter_simple_bv_media=vp8_loop_filter_bvs_armv6;
-$vp8_loop_filter_simple_bv_neon=vp8_loop_filter_bvs_neon;
-$vp8_loop_filter_simple_bv_msa=vp8_loop_filter_bvs_msa;
-
-add_proto qw/void vp8_loop_filter_simple_bh/, "unsigned char *y, int ystride, const unsigned char *blimit";
-specialize qw/vp8_loop_filter_simple_bh mmx sse2 media neon msa/;
-$vp8_loop_filter_simple_bh_c=vp8_loop_filter_bhs_c;
-$vp8_loop_filter_simple_bh_mmx=vp8_loop_filter_bhs_mmx;
-$vp8_loop_filter_simple_bh_sse2=vp8_loop_filter_bhs_sse2;
-$vp8_loop_filter_simple_bh_media=vp8_loop_filter_bhs_armv6;
-$vp8_loop_filter_simple_bh_neon=vp8_loop_filter_bhs_neon;
-$vp8_loop_filter_simple_bh_msa=vp8_loop_filter_bhs_msa;
-
-#
-# IDCT
-#
-#idct16
-add_proto qw/void vp8_short_idct4x4llm/, "short *input, unsigned char *pred, int pitch, unsigned char *dst, int dst_stride";
-specialize qw/vp8_short_idct4x4llm mmx media neon dspr2 msa/;
-$vp8_short_idct4x4llm_media=vp8_short_idct4x4llm_v6_dual;
-$vp8_short_idct4x4llm_dspr2=vp8_short_idct4x4llm_dspr2;
-
-#iwalsh1
-add_proto qw/void vp8_short_inv_walsh4x4_1/, "short *input, short *output";
-specialize qw/vp8_short_inv_walsh4x4_1 dspr2/;
-$vp8_short_inv_walsh4x4_1_dspr2=vp8_short_inv_walsh4x4_1_dspr2;
-# no asm yet
-
-#iwalsh16
-add_proto qw/void vp8_short_inv_walsh4x4/, "short *input, short *output";
-specialize qw/vp8_short_inv_walsh4x4 mmx sse2 media neon dspr2 msa/;
-$vp8_short_inv_walsh4x4_media=vp8_short_inv_walsh4x4_v6;
-$vp8_short_inv_walsh4x4_dspr2=vp8_short_inv_walsh4x4_dspr2;
-
-#idct1_scalar_add
-add_proto qw/void vp8_dc_only_idct_add/, "short input, unsigned char *pred, int pred_stride, unsigned char *dst, int dst_stride";
-specialize qw/vp8_dc_only_idct_add     mmx media neon dspr2 msa/;
-$vp8_dc_only_idct_add_media=vp8_dc_only_idct_add_v6;
-$vp8_dc_only_idct_add_dspr2=vp8_dc_only_idct_add_dspr2;
-
-#
-# RECON
-#
-add_proto qw/void vp8_copy_mem16x16/, "unsigned char *src, int src_pitch, unsigned char *dst, int dst_pitch";
-specialize qw/vp8_copy_mem16x16 mmx sse2 media neon dspr2 msa/;
-$vp8_copy_mem16x16_media=vp8_copy_mem16x16_v6;
-$vp8_copy_mem16x16_dspr2=vp8_copy_mem16x16_dspr2;
-
-add_proto qw/void vp8_copy_mem8x8/, "unsigned char *src, int src_pitch, unsigned char *dst, int dst_pitch";
-specialize qw/vp8_copy_mem8x8 mmx media neon dspr2 msa/;
-$vp8_copy_mem8x8_media=vp8_copy_mem8x8_v6;
-$vp8_copy_mem8x8_dspr2=vp8_copy_mem8x8_dspr2;
-
-add_proto qw/void vp8_copy_mem8x4/, "unsigned char *src, int src_pitch, unsigned char *dst, int dst_pitch";
-specialize qw/vp8_copy_mem8x4 mmx media neon dspr2 msa/;
-$vp8_copy_mem8x4_media=vp8_copy_mem8x4_v6;
-$vp8_copy_mem8x4_dspr2=vp8_copy_mem8x4_dspr2;
-
-#
-# Postproc
-#
-if (vpx_config("CONFIG_POSTPROC") eq "yes") {
-
-    add_proto qw/void vp8_blend_mb_inner/, "unsigned char *y, unsigned char *u, unsigned char *v, int y1, int u1, int v1, int alpha, int stride";
-    # no asm yet
-
-    add_proto qw/void vp8_blend_mb_outer/, "unsigned char *y, unsigned char *u, unsigned char *v, int y1, int u1, int v1, int alpha, int stride";
-    # no asm yet
-
-    add_proto qw/void vp8_blend_b/, "unsigned char *y, unsigned char *u, unsigned char *v, int y1, int u1, int v1, int alpha, int stride";
-    # no asm yet
-
-    add_proto qw/void vp8_filter_by_weight16x16/, "unsigned char *src, int src_stride, unsigned char *dst, int dst_stride, int src_weight";
-    specialize qw/vp8_filter_by_weight16x16 sse2 msa/;
-
-    add_proto qw/void vp8_filter_by_weight8x8/, "unsigned char *src, int src_stride, unsigned char *dst, int dst_stride, int src_weight";
-    specialize qw/vp8_filter_by_weight8x8 sse2 msa/;
-
-    add_proto qw/void vp8_filter_by_weight4x4/, "unsigned char *src, int src_stride, unsigned char *dst, int dst_stride, int src_weight";
-    # no asm yet
-}
-
-#
-# Subpixel
-#
-add_proto qw/void vp8_sixtap_predict16x16/, "unsigned char *src, int src_pitch, int xofst, int yofst, unsigned char *dst, int dst_pitch";
-specialize qw/vp8_sixtap_predict16x16 mmx sse2 ssse3 media neon dspr2 msa/;
-$vp8_sixtap_predict16x16_media=vp8_sixtap_predict16x16_armv6;
-$vp8_sixtap_predict16x16_dspr2=vp8_sixtap_predict16x16_dspr2;
-
-add_proto qw/void vp8_sixtap_predict8x8/, "unsigned char *src, int src_pitch, int xofst, int yofst, unsigned char *dst, int dst_pitch";
-specialize qw/vp8_sixtap_predict8x8 mmx sse2 ssse3 media neon dspr2 msa/;
-$vp8_sixtap_predict8x8_media=vp8_sixtap_predict8x8_armv6;
-$vp8_sixtap_predict8x8_dspr2=vp8_sixtap_predict8x8_dspr2;
-
-add_proto qw/void vp8_sixtap_predict8x4/, "unsigned char *src, int src_pitch, int xofst, int yofst, unsigned char *dst, int dst_pitch";
-specialize qw/vp8_sixtap_predict8x4 mmx sse2 ssse3 media neon dspr2 msa/;
-$vp8_sixtap_predict8x4_media=vp8_sixtap_predict8x4_armv6;
-$vp8_sixtap_predict8x4_dspr2=vp8_sixtap_predict8x4_dspr2;
-
-add_proto qw/void vp8_sixtap_predict4x4/, "unsigned char *src, int src_pitch, int xofst, int yofst, unsigned char *dst, int dst_pitch";
-specialize qw/vp8_sixtap_predict4x4 mmx ssse3 media dspr2 msa/;
-$vp8_sixtap_predict4x4_media=vp8_sixtap_predict4x4_armv6;
-$vp8_sixtap_predict4x4_dspr2=vp8_sixtap_predict4x4_dspr2;
-
-add_proto qw/void vp8_bilinear_predict16x16/, "unsigned char *src, int src_pitch, int xofst, int yofst, unsigned char *dst, int dst_pitch";
-specialize qw/vp8_bilinear_predict16x16 mmx sse2 ssse3 media neon msa/;
-$vp8_bilinear_predict16x16_media=vp8_bilinear_predict16x16_armv6;
-
-add_proto qw/void vp8_bilinear_predict8x8/, "unsigned char *src, int src_pitch, int xofst, int yofst, unsigned char *dst, int dst_pitch";
-specialize qw/vp8_bilinear_predict8x8 mmx sse2 ssse3 media neon msa/;
-$vp8_bilinear_predict8x8_media=vp8_bilinear_predict8x8_armv6;
-
-add_proto qw/void vp8_bilinear_predict8x4/, "unsigned char *src, int src_pitch, int xofst, int yofst, unsigned char *dst, int dst_pitch";
-specialize qw/vp8_bilinear_predict8x4 mmx media neon msa/;
-$vp8_bilinear_predict8x4_media=vp8_bilinear_predict8x4_armv6;
-
-add_proto qw/void vp8_bilinear_predict4x4/, "unsigned char *src, int src_pitch, int xofst, int yofst, unsigned char *dst, int dst_pitch";
-specialize qw/vp8_bilinear_predict4x4 mmx media msa/;
-$vp8_bilinear_predict4x4_media=vp8_bilinear_predict4x4_armv6;
-
-#
-# Encoder functions below this point.
-#
-if (vpx_config("CONFIG_VP8_ENCODER") eq "yes") {
-
-#
-# Block copy
-#
-if ($opts{arch} =~ /x86/) {
-    add_proto qw/void vp8_copy32xn/, "const unsigned char *src_ptr, int source_stride, unsigned char *dst_ptr, int dst_stride, int n";
-    specialize qw/vp8_copy32xn sse2 sse3/;
-}
-
-#
-# Forward DCT
-#
-add_proto qw/void vp8_short_fdct4x4/, "short *input, short *output, int pitch";
-specialize qw/vp8_short_fdct4x4 mmx sse2 media neon msa/;
-$vp8_short_fdct4x4_media=vp8_short_fdct4x4_armv6;
-
-add_proto qw/void vp8_short_fdct8x4/, "short *input, short *output, int pitch";
-specialize qw/vp8_short_fdct8x4 mmx sse2 media neon msa/;
-$vp8_short_fdct8x4_media=vp8_short_fdct8x4_armv6;
-
-add_proto qw/void vp8_short_walsh4x4/, "short *input, short *output, int pitch";
-specialize qw/vp8_short_walsh4x4 sse2 media neon msa/;
-$vp8_short_walsh4x4_media=vp8_short_walsh4x4_armv6;
-
-#
-# Quantizer
-#
-add_proto qw/void vp8_regular_quantize_b/, "struct block *, struct blockd *";
-specialize qw/vp8_regular_quantize_b sse2 sse4_1 msa/;
-
-add_proto qw/void vp8_fast_quantize_b/, "struct block *, struct blockd *";
-specialize qw/vp8_fast_quantize_b sse2 ssse3 neon msa/;
-
-#
-# Block subtraction
-#
-add_proto qw/int vp8_block_error/, "short *coeff, short *dqcoeff";
-specialize qw/vp8_block_error mmx sse2 msa/;
-$vp8_block_error_sse2=vp8_block_error_xmm;
-
-add_proto qw/int vp8_mbblock_error/, "struct macroblock *mb, int dc";
-specialize qw/vp8_mbblock_error mmx sse2 msa/;
-$vp8_mbblock_error_sse2=vp8_mbblock_error_xmm;
-
-add_proto qw/int vp8_mbuverror/, "struct macroblock *mb";
-specialize qw/vp8_mbuverror mmx sse2 msa/;
-$vp8_mbuverror_sse2=vp8_mbuverror_xmm;
-
-#
-# Motion search
-#
-add_proto qw/int vp8_full_search_sad/, "struct macroblock *x, struct block *b, struct blockd *d, union int_mv *ref_mv, int sad_per_bit, int distance, struct variance_vtable *fn_ptr, int *mvcost[2], union int_mv *center_mv";
-specialize qw/vp8_full_search_sad sse3 sse4_1/;
-$vp8_full_search_sad_sse3=vp8_full_search_sadx3;
-$vp8_full_search_sad_sse4_1=vp8_full_search_sadx8;
-
-add_proto qw/int vp8_refining_search_sad/, "struct macroblock *x, struct block *b, struct blockd *d, union int_mv *ref_mv, int sad_per_bit, int distance, struct variance_vtable *fn_ptr, int *mvcost[2], union int_mv *center_mv";
-specialize qw/vp8_refining_search_sad sse3/;
-$vp8_refining_search_sad_sse3=vp8_refining_search_sadx4;
-
-add_proto qw/int vp8_diamond_search_sad/, "struct macroblock *x, struct block *b, struct blockd *d, union int_mv *ref_mv, union int_mv *best_mv, int search_param, int sad_per_bit, int *num00, struct variance_vtable *fn_ptr, int *mvcost[2], union int_mv *center_mv";
-$vp8_diamond_search_sad_sse3=vp8_diamond_search_sadx4;
-
-#
-# Alt-ref Noise Reduction (ARNR)
-#
-if (vpx_config("CONFIG_REALTIME_ONLY") ne "yes") {
-    add_proto qw/void vp8_temporal_filter_apply/, "unsigned char *frame1, unsigned int stride, unsigned char *frame2, unsigned int block_size, int strength, int filter_weight, unsigned int *accumulator, unsigned short *count";
-    specialize qw/vp8_temporal_filter_apply sse2 msa/;
-}
-
-#
-# Denoiser filter
-#
-if (vpx_config("CONFIG_TEMPORAL_DENOISING") eq "yes") {
-    add_proto qw/int vp8_denoiser_filter/, "unsigned char *mc_running_avg_y, int mc_avg_y_stride, unsigned char *running_avg_y, int avg_y_stride, unsigned char *sig, int sig_stride, unsigned int motion_magnitude, int increase_denoising";
-    specialize qw/vp8_denoiser_filter sse2 neon msa/;
-    add_proto qw/int vp8_denoiser_filter_uv/, "unsigned char *mc_running_avg, int mc_avg_stride, unsigned char *running_avg, int avg_stride, unsigned char *sig, int sig_stride, unsigned int motion_magnitude, int increase_denoising";
-    specialize qw/vp8_denoiser_filter_uv sse2 neon msa/;
-}
-
-# End of encoder only functions
-}
-1;
diff --git a/vp8/common/setupintrarecon.c b/vp8/common/setupintrarecon.c
deleted file mode 100644 (file)
index 669564d..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#include "setupintrarecon.h"
-#include "vpx_mem/vpx_mem.h"
-
-void vp8_setup_intra_recon(YV12_BUFFER_CONFIG *ybf)
-{
-    int i;
-
-    /* set up frame new frame for intra coded blocks */
-    memset(ybf->y_buffer - 1 - ybf->y_stride, 127, ybf->y_width + 5);
-    for (i = 0; i < ybf->y_height; i++)
-        ybf->y_buffer[ybf->y_stride *i - 1] = (unsigned char) 129;
-
-    memset(ybf->u_buffer - 1 - ybf->uv_stride, 127, ybf->uv_width + 5);
-    for (i = 0; i < ybf->uv_height; i++)
-        ybf->u_buffer[ybf->uv_stride *i - 1] = (unsigned char) 129;
-
-    memset(ybf->v_buffer - 1 - ybf->uv_stride, 127, ybf->uv_width + 5);
-    for (i = 0; i < ybf->uv_height; i++)
-        ybf->v_buffer[ybf->uv_stride *i - 1] = (unsigned char) 129;
-
-}
-
-void vp8_setup_intra_recon_top_line(YV12_BUFFER_CONFIG *ybf)
-{
-    memset(ybf->y_buffer - 1 - ybf->y_stride, 127, ybf->y_width + 5);
-    memset(ybf->u_buffer - 1 - ybf->uv_stride, 127, ybf->uv_width + 5);
-    memset(ybf->v_buffer - 1 - ybf->uv_stride, 127, ybf->uv_width + 5);
-}
diff --git a/vp8/common/setupintrarecon.h b/vp8/common/setupintrarecon.h
deleted file mode 100644 (file)
index 1857c4e..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#ifndef VP8_COMMON_SETUPINTRARECON_H_
-#define VP8_COMMON_SETUPINTRARECON_H_
-
-#include "./vpx_config.h"
-#include "vpx_scale/yv12config.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-extern void vp8_setup_intra_recon(YV12_BUFFER_CONFIG *ybf);
-extern void vp8_setup_intra_recon_top_line(YV12_BUFFER_CONFIG *ybf);
-
-static INLINE void setup_intra_recon_left(unsigned char *y_buffer,
-                                          unsigned char *u_buffer,
-                                          unsigned char *v_buffer,
-                                          int y_stride,
-                                          int uv_stride)
-{
-    int i;
-
-    for (i = 0; i < 16; i++)
-        y_buffer[y_stride *i] = (unsigned char) 129;
-
-    for (i = 0; i < 8; i++)
-        u_buffer[uv_stride *i] = (unsigned char) 129;
-
-    for (i = 0; i < 8; i++)
-        v_buffer[uv_stride *i] = (unsigned char) 129;
-}
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP8_COMMON_SETUPINTRARECON_H_
diff --git a/vp8/common/swapyv12buffer.c b/vp8/common/swapyv12buffer.c
deleted file mode 100644 (file)
index 73656b3..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#include "swapyv12buffer.h"
-
-void vp8_swap_yv12_buffer(YV12_BUFFER_CONFIG *new_frame, YV12_BUFFER_CONFIG *last_frame)
-{
-    unsigned char *temp;
-
-    temp = last_frame->buffer_alloc;
-    last_frame->buffer_alloc = new_frame->buffer_alloc;
-    new_frame->buffer_alloc = temp;
-
-    temp = last_frame->y_buffer;
-    last_frame->y_buffer = new_frame->y_buffer;
-    new_frame->y_buffer = temp;
-
-    temp = last_frame->u_buffer;
-    last_frame->u_buffer = new_frame->u_buffer;
-    new_frame->u_buffer = temp;
-
-    temp = last_frame->v_buffer;
-    last_frame->v_buffer = new_frame->v_buffer;
-    new_frame->v_buffer = temp;
-
-}
diff --git a/vp8/common/swapyv12buffer.h b/vp8/common/swapyv12buffer.h
deleted file mode 100644 (file)
index 1d66cd3..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#ifndef VP8_COMMON_SWAPYV12BUFFER_H_
-#define VP8_COMMON_SWAPYV12BUFFER_H_
-
-#include "vpx_scale/yv12config.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-void vp8_swap_yv12_buffer(YV12_BUFFER_CONFIG *new_frame, YV12_BUFFER_CONFIG *last_frame);
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP8_COMMON_SWAPYV12BUFFER_H_
diff --git a/vp8/common/systemdependent.h b/vp8/common/systemdependent.h
deleted file mode 100644 (file)
index 3d44e37..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#ifndef VP8_COMMON_SYSTEMDEPENDENT_H_
-#define VP8_COMMON_SYSTEMDEPENDENT_H_
-
-#include "vpx_config.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-struct VP8Common;
-void vp8_machine_specific_config(struct VP8Common *);
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP8_COMMON_SYSTEMDEPENDENT_H_
diff --git a/vp8/common/textblit.c b/vp8/common/textblit.c
deleted file mode 100644 (file)
index 1756100..0000000
+++ /dev/null
@@ -1,130 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#include <stdlib.h>
-
-
-void vp8_blit_text(const char *msg, unsigned char *address, const int pitch)
-{
-    int letter_bitmap;
-    unsigned char *output_pos = address;
-    int colpos;
-    const int font[] =
-    {
-        0x0, 0x5C00, 0x8020, 0xAFABEA, 0xD7EC0, 0x1111111, 0x1855740, 0x18000,
-        0x45C0, 0x74400, 0x51140, 0x23880, 0xC4000, 0x21080, 0x80000, 0x111110,
-        0xE9D72E, 0x87E40, 0x12AD732, 0xAAD62A, 0x4F94C4, 0x4D6B7, 0x456AA,
-        0x3E8423, 0xAAD6AA, 0xAAD6A2, 0x2800, 0x2A00, 0x8A880, 0x52940, 0x22A20,
-        0x15422, 0x6AD62E, 0x1E4A53E, 0xAAD6BF, 0x8C62E, 0xE8C63F, 0x118D6BF,
-        0x1094BF, 0xCAC62E, 0x1F2109F, 0x118FE31, 0xF8C628, 0x8A89F, 0x108421F,
-        0x1F1105F, 0x1F4105F, 0xE8C62E, 0x2294BF, 0x164C62E, 0x12694BF, 0x8AD6A2,
-        0x10FC21, 0x1F8421F, 0x744107, 0xF8220F, 0x1151151, 0x117041, 0x119D731,
-        0x47E0, 0x1041041, 0xFC400, 0x10440, 0x1084210, 0x820
-    };
-    colpos = 0;
-
-    while (msg[colpos] != 0)
-    {
-        char letter = msg[colpos];
-        int fontcol, fontrow;
-
-        if (letter <= 'Z' && letter >= ' ')
-            letter_bitmap = font[letter-' '];
-        else if (letter <= 'z' && letter >= 'a')
-            letter_bitmap = font[letter-'a'+'A' - ' '];
-        else
-            letter_bitmap = font[0];
-
-        for (fontcol = 6; fontcol >= 0 ; fontcol--)
-            for (fontrow = 0; fontrow < 5; fontrow++)
-                output_pos[fontrow *pitch + fontcol] =
-                    ((letter_bitmap >> (fontcol * 5)) & (1 << fontrow) ? 255 : 0);
-
-        output_pos += 7;
-        colpos++;
-    }
-}
-
-static void plot (const int x, const int y, unsigned char *image, const int pitch)
-{
-    image [x+y*pitch] ^= 255;
-}
-
-/* Bresenham line algorithm */
-void vp8_blit_line(int x0, int x1, int y0, int y1, unsigned char *image, const int pitch)
-{
-    int steep = abs(y1 - y0) > abs(x1 - x0);
-    int deltax, deltay;
-    int error, ystep, y, x;
-
-    if (steep)
-    {
-        int t;
-        t = x0;
-        x0 = y0;
-        y0 = t;
-
-        t = x1;
-        x1 = y1;
-        y1 = t;
-    }
-
-    if (x0 > x1)
-    {
-        int t;
-        t = x0;
-        x0 = x1;
-        x1 = t;
-
-        t = y0;
-        y0 = y1;
-        y1 = t;
-    }
-
-    deltax = x1 - x0;
-    deltay = abs(y1 - y0);
-    error  = deltax / 2;
-
-    y = y0;
-
-    if (y0 < y1)
-        ystep = 1;
-    else
-        ystep = -1;
-
-    if (steep)
-    {
-        for (x = x0; x <= x1; x++)
-        {
-            plot(y,x, image, pitch);
-
-            error = error - deltay;
-            if (error < 0)
-            {
-                y = y + ystep;
-                error = error + deltax;
-            }
-        }
-    }
-    else
-    {
-        for (x = x0; x <= x1; x++)
-        {
-            plot(x,y, image, pitch);
-
-            error = error - deltay;
-            if (error < 0)
-            {
-                y = y + ystep;
-                error = error + deltax;
-            }
-        }
-    }
-}
diff --git a/vp8/common/threading.h b/vp8/common/threading.h
deleted file mode 100644 (file)
index 183b49b..0000000
+++ /dev/null
@@ -1,232 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#ifndef VP8_COMMON_THREADING_H_
-#define VP8_COMMON_THREADING_H_
-
-#include "./vpx_config.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#if CONFIG_OS_SUPPORT && CONFIG_MULTITHREAD
-
-/* Thread management macros */
-#if defined(_WIN32) && !HAVE_PTHREAD_H
-/* Win32 */
-#include <process.h>
-#include <windows.h>
-#define THREAD_FUNCTION unsigned int __stdcall
-#define THREAD_FUNCTION_RETURN DWORD
-#define THREAD_SPECIFIC_INDEX DWORD
-#define pthread_t HANDLE
-#define pthread_attr_t DWORD
-#define pthread_detach(thread) if(thread!=NULL)CloseHandle(thread)
-#define thread_sleep(nms) Sleep(nms)
-#define pthread_cancel(thread) terminate_thread(thread,0)
-#define ts_key_create(ts_key, destructor) {ts_key = TlsAlloc();};
-#define pthread_getspecific(ts_key) TlsGetValue(ts_key)
-#define pthread_setspecific(ts_key, value) TlsSetValue(ts_key, (void *)value)
-#define pthread_self() GetCurrentThreadId()
-
-#elif defined(__OS2__)
-/* OS/2 */
-#define INCL_DOS
-#include <os2.h>
-
-#include <stdlib.h>
-#define THREAD_FUNCTION void *
-#define THREAD_FUNCTION_RETURN void *
-#define THREAD_SPECIFIC_INDEX PULONG
-#define pthread_t TID
-#define pthread_attr_t ULONG
-#define pthread_detach(thread) 0
-#define thread_sleep(nms) DosSleep(nms)
-#define pthread_cancel(thread) DosKillThread(thread)
-#define ts_key_create(ts_key, destructor) \
-    DosAllocThreadLocalMemory(1, &(ts_key));
-#define pthread_getspecific(ts_key) ((void *)(*(ts_key)))
-#define pthread_setspecific(ts_key, value) (*(ts_key)=(ULONG)(value))
-#define pthread_self() _gettid()
-#else
-#ifdef __APPLE__
-#include <mach/mach_init.h>
-#include <mach/semaphore.h>
-#include <mach/task.h>
-#include <time.h>
-#include <unistd.h>
-
-#else
-#include <semaphore.h>
-#endif
-
-#include <pthread.h>
-/* pthreads */
-/* Nearly everything is already defined */
-#define THREAD_FUNCTION void *
-#define THREAD_FUNCTION_RETURN void *
-#define THREAD_SPECIFIC_INDEX pthread_key_t
-#define ts_key_create(ts_key, destructor) pthread_key_create (&(ts_key), destructor);
-#endif
-
-/* Synchronization macros: Win32 and Pthreads */
-#if defined(_WIN32) && !HAVE_PTHREAD_H
-#define sem_t HANDLE
-#define pause(voidpara) __asm PAUSE
-#define sem_init(sem, sem_attr1, sem_init_value) (int)((*sem = CreateSemaphore(NULL,0,32768,NULL))==NULL)
-#define sem_wait(sem) (int)(WAIT_OBJECT_0 != WaitForSingleObject(*sem,INFINITE))
-#define sem_post(sem) ReleaseSemaphore(*sem,1,NULL)
-#define sem_destroy(sem) if(*sem)((int)(CloseHandle(*sem))==TRUE)
-#define thread_sleep(nms) Sleep(nms)
-
-#elif defined(__OS2__)
-typedef struct
-{
-    HEV  event;
-    HMTX wait_mutex;
-    HMTX count_mutex;
-    int  count;
-} sem_t;
-
-static inline int sem_init(sem_t *sem, int pshared, unsigned int value)
-{
-    DosCreateEventSem(NULL, &sem->event, pshared ? DC_SEM_SHARED : 0,
-                      value > 0 ? TRUE : FALSE);
-    DosCreateMutexSem(NULL, &sem->wait_mutex, 0, FALSE);
-    DosCreateMutexSem(NULL, &sem->count_mutex, 0, FALSE);
-
-    sem->count = value;
-
-    return 0;
-}
-
-static inline int sem_wait(sem_t * sem)
-{
-    DosRequestMutexSem(sem->wait_mutex, -1);
-
-    DosWaitEventSem(sem->event, -1);
-
-    DosRequestMutexSem(sem->count_mutex, -1);
-
-    sem->count--;
-    if (sem->count == 0)
-    {
-        ULONG post_count;
-
-        DosResetEventSem(sem->event, &post_count);
-    }
-
-    DosReleaseMutexSem(sem->count_mutex);
-
-    DosReleaseMutexSem(sem->wait_mutex);
-
-    return 0;
-}
-
-static inline int sem_post(sem_t * sem)
-{
-    DosRequestMutexSem(sem->count_mutex, -1);
-
-    if (sem->count < 32768)
-    {
-        sem->count++;
-        DosPostEventSem(sem->event);
-    }
-
-    DosReleaseMutexSem(sem->count_mutex);
-
-    return 0;
-}
-
-static inline int sem_destroy(sem_t * sem)
-{
-    DosCloseEventSem(sem->event);
-    DosCloseMutexSem(sem->wait_mutex);
-    DosCloseMutexSem(sem->count_mutex);
-
-    return 0;
-}
-
-#define thread_sleep(nms) DosSleep(nms)
-
-#else
-
-#ifdef __APPLE__
-#define sem_t semaphore_t
-#define sem_init(X,Y,Z) semaphore_create(mach_task_self(), X, SYNC_POLICY_FIFO, Z)
-#define sem_wait(sem) (semaphore_wait(*sem) )
-#define sem_post(sem) semaphore_signal(*sem)
-#define sem_destroy(sem) semaphore_destroy(mach_task_self(),*sem)
-#define thread_sleep(nms) /* { struct timespec ts;ts.tv_sec=0; ts.tv_nsec = 1000*nms;nanosleep(&ts, NULL);} */
-#else
-#include <unistd.h>
-#include <sched.h>
-#define thread_sleep(nms) sched_yield();/* {struct timespec ts;ts.tv_sec=0; ts.tv_nsec = 1000*nms;nanosleep(&ts, NULL);} */
-#endif
-/* Not Windows. Assume pthreads */
-
-#endif
-
-#if ARCH_X86 || ARCH_X86_64
-#include "vpx_ports/x86.h"
-#else
-#define x86_pause_hint()
-#endif
-
-#include "vpx_util/vpx_thread.h"
-
-static INLINE void mutex_lock(pthread_mutex_t *const mutex) {
-    const int kMaxTryLocks = 4000;
-    int locked = 0;
-    int i;
-
-    for (i = 0; i < kMaxTryLocks; ++i) {
-        if (!pthread_mutex_trylock(mutex)) {
-            locked = 1;
-            break;
-        }
-    }
-
-    if (!locked)
-        pthread_mutex_lock(mutex);
-}
-
-static INLINE int protected_read(pthread_mutex_t *const mutex, const int *p) {
-    int ret;
-    mutex_lock(mutex);
-    ret = *p;
-    pthread_mutex_unlock(mutex);
-    return ret;
-}
-
-static INLINE void sync_read(pthread_mutex_t *const mutex, int mb_col,
-                             const int *last_row_current_mb_col,
-                             const int nsync) {
-    while (mb_col > (protected_read(mutex, last_row_current_mb_col) - nsync)) {
-        x86_pause_hint();
-        thread_sleep(0);
-    }
-}
-
-static INLINE void protected_write(pthread_mutex_t *mutex, int *p, int v) {
-    mutex_lock(mutex);
-    *p = v;
-    pthread_mutex_unlock(mutex);
-}
-
-#endif /* CONFIG_OS_SUPPORT && CONFIG_MULTITHREAD */
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP8_COMMON_THREADING_H_
diff --git a/vp8/common/treecoder.c b/vp8/common/treecoder.c
deleted file mode 100644 (file)
index d80c64b..0000000
+++ /dev/null
@@ -1,143 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#if CONFIG_DEBUG
-#include <assert.h>
-#endif
-#include <stdio.h>
-
-#include "treecoder.h"
-
-static void tree2tok(
-    struct vp8_token_struct *const p,
-    vp8_tree t,
-    int i,
-    int v,
-    int L
-)
-{
-    v += v;
-    ++L;
-
-    do
-    {
-        const vp8_tree_index j = t[i++];
-
-        if (j <= 0)
-        {
-            p[-j].value = v;
-            p[-j].Len = L;
-        }
-        else
-            tree2tok(p, t, j, v, L);
-    }
-    while (++v & 1);
-}
-
-void vp8_tokens_from_tree(struct vp8_token_struct *p, vp8_tree t)
-{
-    tree2tok(p, t, 0, 0, 0);
-}
-
-void vp8_tokens_from_tree_offset(struct vp8_token_struct *p, vp8_tree t,
-                                 int offset)
-{
-    tree2tok(p - offset, t, 0, 0, 0);
-}
-
-static void branch_counts(
-    int n,                      /* n = size of alphabet */
-    vp8_token tok               [ /* n */ ],
-    vp8_tree tree,
-    unsigned int branch_ct       [ /* n-1 */ ] [2],
-    const unsigned int num_events[ /* n */ ]
-)
-{
-    const int tree_len = n - 1;
-    int t = 0;
-
-#if CONFIG_DEBUG
-    assert(tree_len);
-#endif
-
-    do
-    {
-        branch_ct[t][0] = branch_ct[t][1] = 0;
-    }
-    while (++t < tree_len);
-
-    t = 0;
-
-    do
-    {
-        int L = tok[t].Len;
-        const int enc = tok[t].value;
-        const unsigned int ct = num_events[t];
-
-        vp8_tree_index i = 0;
-
-        do
-        {
-            const int b = (enc >> --L) & 1;
-            const int j = i >> 1;
-#if CONFIG_DEBUG
-            assert(j < tree_len  &&  0 <= L);
-#endif
-
-            branch_ct [j] [b] += ct;
-            i = tree[ i + b];
-        }
-        while (i > 0);
-
-#if CONFIG_DEBUG
-        assert(!L);
-#endif
-    }
-    while (++t < n);
-
-}
-
-
-void vp8_tree_probs_from_distribution(
-    int n,                      /* n = size of alphabet */
-    vp8_token tok               [ /* n */ ],
-    vp8_tree tree,
-    vp8_prob probs          [ /* n-1 */ ],
-    unsigned int branch_ct       [ /* n-1 */ ] [2],
-    const unsigned int num_events[ /* n */ ],
-    unsigned int Pfac,
-    int rd
-)
-{
-    const int tree_len = n - 1;
-    int t = 0;
-
-    branch_counts(n, tok, tree, branch_ct, num_events);
-
-    do
-    {
-        const unsigned int *const c = branch_ct[t];
-        const unsigned int tot = c[0] + c[1];
-
-#if CONFIG_DEBUG
-        assert(tot < (1 << 24));        /* no overflow below */
-#endif
-
-        if (tot)
-        {
-            const unsigned int p = ((c[0] * Pfac) + (rd ? tot >> 1 : 0)) / tot;
-            probs[t] = p < 256 ? (p ? p : 1) : 255; /* agree w/old version for now */
-        }
-        else
-            probs[t] = vp8_prob_half;
-    }
-    while (++t < tree_len);
-}
diff --git a/vp8/common/treecoder.h b/vp8/common/treecoder.h
deleted file mode 100644 (file)
index d22b7c5..0000000
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#ifndef VP8_COMMON_TREECODER_H_
-#define VP8_COMMON_TREECODER_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef unsigned char vp8bc_index_t; /* probability index */
-
-
-typedef unsigned char vp8_prob;
-
-#define vp8_prob_half ( (vp8_prob) 128)
-
-typedef signed char vp8_tree_index;
-struct bool_coder_spec;
-
-typedef struct bool_coder_spec bool_coder_spec;
-typedef struct bool_writer bool_writer;
-typedef struct bool_reader bool_reader;
-
-typedef const bool_coder_spec c_bool_coder_spec;
-typedef const bool_writer c_bool_writer;
-typedef const bool_reader c_bool_reader;
-
-
-
-# define vp8_complement( x) (255 - x)
-
-
-/* We build coding trees compactly in arrays.
-   Each node of the tree is a pair of vp8_tree_indices.
-   Array index often references a corresponding probability table.
-   Index <= 0 means done encoding/decoding and value = -Index,
-   Index > 0 means need another bit, specification at index.
-   Nonnegative indices are always even;  processing begins at node 0. */
-
-typedef const vp8_tree_index vp8_tree[], *vp8_tree_p;
-
-
-typedef const struct vp8_token_struct
-{
-    int value;
-    int Len;
-} vp8_token;
-
-/* Construct encoding array from tree. */
-
-void vp8_tokens_from_tree(struct vp8_token_struct *, vp8_tree);
-void vp8_tokens_from_tree_offset(struct vp8_token_struct *, vp8_tree,
-                                 int offset);
-
-
-/* Convert array of token occurrence counts into a table of probabilities
-   for the associated binary encoding tree.  Also writes count of branches
-   taken for each node on the tree; this facilitiates decisions as to
-   probability updates. */
-
-void vp8_tree_probs_from_distribution(
-    int n,                      /* n = size of alphabet */
-    vp8_token tok               [ /* n */ ],
-    vp8_tree tree,
-    vp8_prob probs          [ /* n-1 */ ],
-    unsigned int branch_ct       [ /* n-1 */ ] [2],
-    const unsigned int num_events[ /* n */ ],
-    unsigned int Pfactor,
-    int Round
-);
-
-/* Variant of above using coder spec rather than hardwired 8-bit probs. */
-
-void vp8bc_tree_probs_from_distribution(
-    int n,                      /* n = size of alphabet */
-    vp8_token tok               [ /* n */ ],
-    vp8_tree tree,
-    vp8_prob probs          [ /* n-1 */ ],
-    unsigned int branch_ct       [ /* n-1 */ ] [2],
-    const unsigned int num_events[ /* n */ ],
-    c_bool_coder_spec *s
-);
-
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP8_COMMON_TREECODER_H_
diff --git a/vp8/common/vp8_entropymodedata.h b/vp8/common/vp8_entropymodedata.h
deleted file mode 100644 (file)
index c4aed49..0000000
+++ /dev/null
@@ -1,254 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
-*/
-
-#ifndef VP8_COMMON_VP8_ENTROPYMODEDATA_H_
-#define VP8_COMMON_VP8_ENTROPYMODEDATA_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/*Generated file, included by entropymode.c*/
-
-
-const struct vp8_token_struct vp8_bmode_encodings[VP8_BINTRAMODES] =
-{
-    { 0, 1 },
-    { 2, 2 },
-    { 6, 3 },
-    { 28, 5 },
-    { 30, 5 },
-    { 58, 6 },
-    { 59, 6 },
-    { 62, 6 },
-    { 126, 7 },
-    { 127, 7 }
-};
-
-const struct vp8_token_struct vp8_ymode_encodings[VP8_YMODES] =
-{
-    { 0, 1 },
-    { 4, 3 },
-    { 5, 3 },
-    { 6, 3 },
-    { 7, 3 }
-};
-
-const struct vp8_token_struct vp8_kf_ymode_encodings[VP8_YMODES] =
-{
-    { 4, 3 },
-    { 5, 3 },
-    { 6, 3 },
-    { 7, 3 },
-    { 0, 1 }
-};
-
-const struct vp8_token_struct vp8_uv_mode_encodings[VP8_UV_MODES] =
-{
-    { 0, 1 },
-    { 2, 2 },
-    { 6, 3 },
-    { 7, 3 }
-};
-
-const struct vp8_token_struct vp8_mbsplit_encodings[VP8_NUMMBSPLITS] =
-{
-    { 6, 3 },
-    { 7, 3 },
-    { 2, 2 },
-    { 0, 1 }
-};
-
-const struct vp8_token_struct vp8_mv_ref_encoding_array[VP8_MVREFS] =
-{
-    { 2, 2 },
-    { 6, 3 },
-    { 0, 1 },
-    { 14, 4 },
-    { 15, 4 }
-};
-
-const struct vp8_token_struct vp8_sub_mv_ref_encoding_array[VP8_SUBMVREFS] =
-{
-    { 0, 1 },
-    { 2, 2 },
-    { 6, 3 },
-    { 7, 3 }
-};
-
-const struct vp8_token_struct vp8_small_mvencodings[8] =
-{
-    { 0, 3 },
-    { 1, 3 },
-    { 2, 3 },
-    { 3, 3 },
-    { 4, 3 },
-    { 5, 3 },
-    { 6, 3 },
-    { 7, 3 }
-};
-
-const vp8_prob vp8_ymode_prob[VP8_YMODES-1] =
-{
-    112, 86, 140, 37
-};
-
-const vp8_prob vp8_kf_ymode_prob[VP8_YMODES-1] =
-{
-    145, 156, 163, 128
-};
-
-const vp8_prob vp8_uv_mode_prob[VP8_UV_MODES-1] =
-{
-    162, 101, 204
-};
-
-const vp8_prob vp8_kf_uv_mode_prob[VP8_UV_MODES-1] =
-{
-    142, 114, 183
-};
-
-const vp8_prob vp8_bmode_prob[VP8_BINTRAMODES-1] =
-{
-    120, 90, 79, 133, 87, 85, 80, 111, 151
-};
-
-
-
-const vp8_prob vp8_kf_bmode_prob
-[VP8_BINTRAMODES] [VP8_BINTRAMODES] [VP8_BINTRAMODES-1] =
-{
-    {
-        { 231, 120,  48,  89, 115, 113, 120, 152, 112 },
-        { 152, 179,  64, 126, 170, 118,  46,  70,  95 },
-        { 175,  69, 143,  80,  85,  82,  72, 155, 103 },
-        {  56,  58,  10, 171, 218, 189,  17,  13, 152 },
-        { 144,  71,  10,  38, 171, 213, 144,  34,  26 },
-        { 114,  26,  17, 163,  44, 195,  21,  10, 173 },
-        { 121,  24,  80, 195,  26,  62,  44,  64,  85 },
-        { 170,  46,  55,  19, 136, 160,  33, 206,  71 },
-        {  63,  20,   8, 114, 114, 208,  12,   9, 226 },
-        {  81,  40,  11,  96, 182,  84,  29,  16,  36 }
-    },
-    {
-        { 134, 183,  89, 137,  98, 101, 106, 165, 148 },
-        {  72, 187, 100, 130, 157, 111,  32,  75,  80 },
-        {  66, 102, 167,  99,  74,  62,  40, 234, 128 },
-        {  41,  53,   9, 178, 241, 141,  26,   8, 107 },
-        { 104,  79,  12,  27, 217, 255,  87,  17,   7 },
-        {  74,  43,  26, 146,  73, 166,  49,  23, 157 },
-        {  65,  38, 105, 160,  51,  52,  31, 115, 128 },
-        {  87,  68,  71,  44, 114,  51,  15, 186,  23 },
-        {  47,  41,  14, 110, 182, 183,  21,  17, 194 },
-        {  66,  45,  25, 102, 197, 189,  23,  18,  22 }
-    },
-    {
-        {  88,  88, 147, 150,  42,  46,  45, 196, 205 },
-        {  43,  97, 183, 117,  85,  38,  35, 179,  61 },
-        {  39,  53, 200,  87,  26,  21,  43, 232, 171 },
-        {  56,  34,  51, 104, 114, 102,  29,  93,  77 },
-        { 107,  54,  32,  26,  51,   1,  81,  43,  31 },
-        {  39,  28,  85, 171,  58, 165,  90,  98,  64 },
-        {  34,  22, 116, 206,  23,  34,  43, 166,  73 },
-        {  68,  25, 106,  22,  64, 171,  36, 225, 114 },
-        {  34,  19,  21, 102, 132, 188,  16,  76, 124 },
-        {  62,  18,  78,  95,  85,  57,  50,  48,  51 }
-    },
-    {
-        { 193, 101,  35, 159, 215, 111,  89,  46, 111 },
-        {  60, 148,  31, 172, 219, 228,  21,  18, 111 },
-        { 112, 113,  77,  85, 179, 255,  38, 120, 114 },
-        {  40,  42,   1, 196, 245, 209,  10,  25, 109 },
-        { 100,  80,   8,  43, 154,   1,  51,  26,  71 },
-        {  88,  43,  29, 140, 166, 213,  37,  43, 154 },
-        {  61,  63,  30, 155,  67,  45,  68,   1, 209 },
-        { 142,  78,  78,  16, 255, 128,  34, 197, 171 },
-        {  41,  40,   5, 102, 211, 183,   4,   1, 221 },
-        {  51,  50,  17, 168, 209, 192,  23,  25,  82 }
-    },
-    {
-        { 125,  98,  42,  88, 104,  85, 117, 175,  82 },
-        {  95,  84,  53,  89, 128, 100, 113, 101,  45 },
-        {  75,  79, 123,  47,  51, 128,  81, 171,   1 },
-        {  57,  17,   5,  71, 102,  57,  53,  41,  49 },
-        { 115,  21,   2,  10, 102, 255, 166,  23,   6 },
-        {  38,  33,  13, 121,  57,  73,  26,   1,  85 },
-        {  41,  10,  67, 138,  77, 110,  90,  47, 114 },
-        { 101,  29,  16,  10,  85, 128, 101, 196,  26 },
-        {  57,  18,  10, 102, 102, 213,  34,  20,  43 },
-        { 117,  20,  15,  36, 163, 128,  68,   1,  26 }
-    },
-    {
-        { 138,  31,  36, 171,  27, 166,  38,  44, 229 },
-        {  67,  87,  58, 169,  82, 115,  26,  59, 179 },
-        {  63,  59,  90, 180,  59, 166,  93,  73, 154 },
-        {  40,  40,  21, 116, 143, 209,  34,  39, 175 },
-        {  57,  46,  22,  24, 128,   1,  54,  17,  37 },
-        {  47,  15,  16, 183,  34, 223,  49,  45, 183 },
-        {  46,  17,  33, 183,   6,  98,  15,  32, 183 },
-        {  65,  32,  73, 115,  28, 128,  23, 128, 205 },
-        {  40,   3,   9, 115,  51, 192,  18,   6, 223 },
-        {  87,  37,   9, 115,  59,  77,  64,  21,  47 }
-    },
-    {
-        { 104,  55,  44, 218,   9,  54,  53, 130, 226 },
-        {  64,  90,  70, 205,  40,  41,  23,  26,  57 },
-        {  54,  57, 112, 184,   5,  41,  38, 166, 213 },
-        {  30,  34,  26, 133, 152, 116,  10,  32, 134 },
-        {  75,  32,  12,  51, 192, 255, 160,  43,  51 },
-        {  39,  19,  53, 221,  26, 114,  32,  73, 255 },
-        {  31,   9,  65, 234,   2,  15,   1, 118,  73 },
-        {  88,  31,  35,  67, 102,  85,  55, 186,  85 },
-        {  56,  21,  23, 111,  59, 205,  45,  37, 192 },
-        {  55,  38,  70, 124,  73, 102,   1,  34,  98 }
-    },
-    {
-        { 102,  61,  71,  37,  34,  53,  31, 243, 192 },
-        {  69,  60,  71,  38,  73, 119,  28, 222,  37 },
-        {  68,  45, 128,  34,   1,  47,  11, 245, 171 },
-        {  62,  17,  19,  70, 146,  85,  55,  62,  70 },
-        {  75,  15,   9,   9,  64, 255, 184, 119,  16 },
-        {  37,  43,  37, 154, 100, 163,  85, 160,   1 },
-        {  63,   9,  92, 136,  28,  64,  32, 201,  85 },
-        {  86,   6,  28,   5,  64, 255,  25, 248,   1 },
-        {  56,   8,  17, 132, 137, 255,  55, 116, 128 },
-        {  58,  15,  20,  82, 135,  57,  26, 121,  40 }
-    },
-    {
-        { 164,  50,  31, 137, 154, 133,  25,  35, 218 },
-        {  51, 103,  44, 131, 131, 123,  31,   6, 158 },
-        {  86,  40,  64, 135, 148, 224,  45, 183, 128 },
-        {  22,  26,  17, 131, 240, 154,  14,   1, 209 },
-        {  83,  12,  13,  54, 192, 255,  68,  47,  28 },
-        {  45,  16,  21,  91,  64, 222,   7,   1, 197 },
-        {  56,  21,  39, 155,  60, 138,  23, 102, 213 },
-        {  85,  26,  85,  85, 128, 128,  32, 146, 171 },
-        {  18,  11,   7,  63, 144, 171,   4,   4, 246 },
-        {  35,  27,  10, 146, 174, 171,  12,  26, 128 }
-    },
-    {
-        { 190,  80,  35,  99, 180,  80, 126,  54,  45 },
-        {  85, 126,  47,  87, 176,  51,  41,  20,  32 },
-        { 101,  75, 128, 139, 118, 146, 116, 128,  85 },
-        {  56,  41,  15, 176, 236,  85,  37,   9,  62 },
-        { 146,  36,  19,  30, 171, 255,  97,  27,  20 },
-        {  71,  30,  17, 119, 118, 255,  17,  18, 138 },
-        { 101,  38,  60, 138,  55,  70,  43,  26, 142 },
-        { 138,  45,  61,  62, 219,   1,  81, 188,  64 },
-        {  32,  41,  20, 117, 151, 142,  20,  21, 163 },
-        { 112,  19,  12,  61, 195, 128,  48,   4,  24 }
-    }
-};
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP8_COMMON_VP8_ENTROPYMODEDATA_H_
diff --git a/vp8/common/vp8_loopfilter.c b/vp8/common/vp8_loopfilter.c
deleted file mode 100644 (file)
index 756ad48..0000000
+++ /dev/null
@@ -1,661 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#include "vpx_config.h"
-#include "vp8_rtcd.h"
-#include "loopfilter.h"
-#include "onyxc_int.h"
-#include "vpx_mem/vpx_mem.h"
-
-
-static void lf_init_lut(loop_filter_info_n *lfi)
-{
-    int filt_lvl;
-
-    for (filt_lvl = 0; filt_lvl <= MAX_LOOP_FILTER; filt_lvl++)
-    {
-        if (filt_lvl >= 40)
-        {
-            lfi->hev_thr_lut[KEY_FRAME][filt_lvl] = 2;
-            lfi->hev_thr_lut[INTER_FRAME][filt_lvl] = 3;
-        }
-        else if (filt_lvl >= 20)
-        {
-            lfi->hev_thr_lut[KEY_FRAME][filt_lvl] = 1;
-            lfi->hev_thr_lut[INTER_FRAME][filt_lvl] = 2;
-        }
-        else if (filt_lvl >= 15)
-        {
-            lfi->hev_thr_lut[KEY_FRAME][filt_lvl] = 1;
-            lfi->hev_thr_lut[INTER_FRAME][filt_lvl] = 1;
-        }
-        else
-        {
-            lfi->hev_thr_lut[KEY_FRAME][filt_lvl] = 0;
-            lfi->hev_thr_lut[INTER_FRAME][filt_lvl] = 0;
-        }
-    }
-
-    lfi->mode_lf_lut[DC_PRED] = 1;
-    lfi->mode_lf_lut[V_PRED] = 1;
-    lfi->mode_lf_lut[H_PRED] = 1;
-    lfi->mode_lf_lut[TM_PRED] = 1;
-    lfi->mode_lf_lut[B_PRED]  = 0;
-
-    lfi->mode_lf_lut[ZEROMV]  = 1;
-    lfi->mode_lf_lut[NEARESTMV] = 2;
-    lfi->mode_lf_lut[NEARMV] = 2;
-    lfi->mode_lf_lut[NEWMV] = 2;
-    lfi->mode_lf_lut[SPLITMV] = 3;
-
-}
-
-void vp8_loop_filter_update_sharpness(loop_filter_info_n *lfi,
-                                      int sharpness_lvl)
-{
-    int i;
-
-    /* For each possible value for the loop filter fill out limits */
-    for (i = 0; i <= MAX_LOOP_FILTER; i++)
-    {
-        int filt_lvl = i;
-        int block_inside_limit = 0;
-
-        /* Set loop filter paramaeters that control sharpness. */
-        block_inside_limit = filt_lvl >> (sharpness_lvl > 0);
-        block_inside_limit = block_inside_limit >> (sharpness_lvl > 4);
-
-        if (sharpness_lvl > 0)
-        {
-            if (block_inside_limit > (9 - sharpness_lvl))
-                block_inside_limit = (9 - sharpness_lvl);
-        }
-
-        if (block_inside_limit < 1)
-            block_inside_limit = 1;
-
-        memset(lfi->lim[i], block_inside_limit, SIMD_WIDTH);
-        memset(lfi->blim[i], (2 * filt_lvl + block_inside_limit), SIMD_WIDTH);
-        memset(lfi->mblim[i], (2 * (filt_lvl + 2) + block_inside_limit),
-               SIMD_WIDTH);
-    }
-}
-
-void vp8_loop_filter_init(VP8_COMMON *cm)
-{
-    loop_filter_info_n *lfi = &cm->lf_info;
-    int i;
-
-    /* init limits for given sharpness*/
-    vp8_loop_filter_update_sharpness(lfi, cm->sharpness_level);
-    cm->last_sharpness_level = cm->sharpness_level;
-
-    /* init LUT for lvl  and hev thr picking */
-    lf_init_lut(lfi);
-
-    /* init hev threshold const vectors */
-    for(i = 0; i < 4 ; i++)
-    {
-        memset(lfi->hev_thr[i], i, SIMD_WIDTH);
-    }
-}
-
-void vp8_loop_filter_frame_init(VP8_COMMON *cm,
-                                MACROBLOCKD *mbd,
-                                int default_filt_lvl)
-{
-    int seg,  /* segment number */
-        ref,  /* index in ref_lf_deltas */
-        mode; /* index in mode_lf_deltas */
-
-    loop_filter_info_n *lfi = &cm->lf_info;
-
-    /* update limits if sharpness has changed */
-    if(cm->last_sharpness_level != cm->sharpness_level)
-    {
-        vp8_loop_filter_update_sharpness(lfi, cm->sharpness_level);
-        cm->last_sharpness_level = cm->sharpness_level;
-    }
-
-    for(seg = 0; seg < MAX_MB_SEGMENTS; seg++)
-    {
-        int lvl_seg = default_filt_lvl;
-        int lvl_ref, lvl_mode;
-
-        /* Note the baseline filter values for each segment */
-        if (mbd->segmentation_enabled)
-        {
-            /* Abs value */
-            if (mbd->mb_segement_abs_delta == SEGMENT_ABSDATA)
-            {
-                lvl_seg = mbd->segment_feature_data[MB_LVL_ALT_LF][seg];
-            }
-            else  /* Delta Value */
-            {
-                lvl_seg += mbd->segment_feature_data[MB_LVL_ALT_LF][seg];
-            }
-            lvl_seg = (lvl_seg > 0) ? ((lvl_seg > 63) ? 63: lvl_seg) : 0;
-        }
-
-        if (!mbd->mode_ref_lf_delta_enabled)
-        {
-            /* we could get rid of this if we assume that deltas are set to
-             * zero when not in use; encoder always uses deltas
-             */
-            memset(lfi->lvl[seg][0], lvl_seg, 4 * 4 );
-            continue;
-        }
-
-        /* INTRA_FRAME */
-        ref = INTRA_FRAME;
-
-        /* Apply delta for reference frame */
-        lvl_ref = lvl_seg + mbd->ref_lf_deltas[ref];
-
-        /* Apply delta for Intra modes */
-        mode = 0; /* B_PRED */
-        /* Only the split mode BPRED has a further special case */
-        lvl_mode = lvl_ref + mbd->mode_lf_deltas[mode];
-        /* clamp */
-        lvl_mode = (lvl_mode > 0) ? (lvl_mode > 63 ? 63 : lvl_mode) : 0;
-
-        lfi->lvl[seg][ref][mode] = lvl_mode;
-
-        mode = 1; /* all the rest of Intra modes */
-        /* clamp */
-        lvl_mode = (lvl_ref > 0) ? (lvl_ref > 63 ? 63 : lvl_ref) : 0;
-        lfi->lvl[seg][ref][mode] = lvl_mode;
-
-        /* LAST, GOLDEN, ALT */
-        for(ref = 1; ref < MAX_REF_FRAMES; ref++)
-        {
-            /* Apply delta for reference frame */
-            lvl_ref = lvl_seg + mbd->ref_lf_deltas[ref];
-
-            /* Apply delta for Inter modes */
-            for (mode = 1; mode < 4; mode++)
-            {
-                lvl_mode = lvl_ref + mbd->mode_lf_deltas[mode];
-                /* clamp */
-                lvl_mode = (lvl_mode > 0) ? (lvl_mode > 63 ? 63 : lvl_mode) : 0;
-
-                lfi->lvl[seg][ref][mode] = lvl_mode;
-            }
-        }
-    }
-}
-
-
-void vp8_loop_filter_row_normal(VP8_COMMON *cm, MODE_INFO *mode_info_context,
-                         int mb_row, int post_ystride, int post_uvstride,
-                         unsigned char *y_ptr, unsigned char *u_ptr,
-                         unsigned char *v_ptr)
-{
-    int mb_col;
-    int filter_level;
-    loop_filter_info_n *lfi_n = &cm->lf_info;
-    loop_filter_info lfi;
-    FRAME_TYPE frame_type = cm->frame_type;
-
-    for (mb_col = 0; mb_col < cm->mb_cols; mb_col++)
-    {
-        int skip_lf = (mode_info_context->mbmi.mode != B_PRED &&
-                        mode_info_context->mbmi.mode != SPLITMV &&
-                        mode_info_context->mbmi.mb_skip_coeff);
-
-        const int mode_index = lfi_n->mode_lf_lut[mode_info_context->mbmi.mode];
-        const int seg = mode_info_context->mbmi.segment_id;
-        const int ref_frame = mode_info_context->mbmi.ref_frame;
-
-        filter_level = lfi_n->lvl[seg][ref_frame][mode_index];
-
-        if (filter_level)
-        {
-            const int hev_index = lfi_n->hev_thr_lut[frame_type][filter_level];
-            lfi.mblim = lfi_n->mblim[filter_level];
-            lfi.blim = lfi_n->blim[filter_level];
-            lfi.lim = lfi_n->lim[filter_level];
-            lfi.hev_thr = lfi_n->hev_thr[hev_index];
-
-            if (mb_col > 0)
-                vp8_loop_filter_mbv
-                (y_ptr, u_ptr, v_ptr, post_ystride, post_uvstride, &lfi);
-
-            if (!skip_lf)
-                vp8_loop_filter_bv
-                (y_ptr, u_ptr, v_ptr, post_ystride, post_uvstride, &lfi);
-
-            /* don't apply across umv border */
-            if (mb_row > 0)
-                vp8_loop_filter_mbh
-                (y_ptr, u_ptr, v_ptr, post_ystride, post_uvstride, &lfi);
-
-            if (!skip_lf)
-                vp8_loop_filter_bh
-                (y_ptr, u_ptr, v_ptr, post_ystride, post_uvstride, &lfi);
-        }
-
-        y_ptr += 16;
-        u_ptr += 8;
-        v_ptr += 8;
-
-        mode_info_context++;     /* step to next MB */
-    }
-
-}
-
-void vp8_loop_filter_row_simple(VP8_COMMON *cm, MODE_INFO *mode_info_context,
-                         int mb_row, int post_ystride, int post_uvstride,
-                         unsigned char *y_ptr, unsigned char *u_ptr,
-                         unsigned char *v_ptr)
-{
-    int mb_col;
-    int filter_level;
-    loop_filter_info_n *lfi_n = &cm->lf_info;
-    (void)post_uvstride;
-
-    for (mb_col = 0; mb_col < cm->mb_cols; mb_col++)
-    {
-        int skip_lf = (mode_info_context->mbmi.mode != B_PRED &&
-                        mode_info_context->mbmi.mode != SPLITMV &&
-                        mode_info_context->mbmi.mb_skip_coeff);
-
-        const int mode_index = lfi_n->mode_lf_lut[mode_info_context->mbmi.mode];
-        const int seg = mode_info_context->mbmi.segment_id;
-        const int ref_frame = mode_info_context->mbmi.ref_frame;
-
-        filter_level = lfi_n->lvl[seg][ref_frame][mode_index];
-
-        if (filter_level)
-        {
-            if (mb_col > 0)
-                vp8_loop_filter_simple_mbv
-                (y_ptr, post_ystride, lfi_n->mblim[filter_level]);
-
-            if (!skip_lf)
-                vp8_loop_filter_simple_bv
-                (y_ptr, post_ystride, lfi_n->blim[filter_level]);
-
-            /* don't apply across umv border */
-            if (mb_row > 0)
-                vp8_loop_filter_simple_mbh
-                (y_ptr, post_ystride, lfi_n->mblim[filter_level]);
-
-            if (!skip_lf)
-                vp8_loop_filter_simple_bh
-                (y_ptr, post_ystride, lfi_n->blim[filter_level]);
-        }
-
-        y_ptr += 16;
-        u_ptr += 8;
-        v_ptr += 8;
-
-        mode_info_context++;     /* step to next MB */
-    }
-
-}
-void vp8_loop_filter_frame(VP8_COMMON *cm,
-                           MACROBLOCKD *mbd,
-                           int frame_type)
-{
-    YV12_BUFFER_CONFIG *post = cm->frame_to_show;
-    loop_filter_info_n *lfi_n = &cm->lf_info;
-    loop_filter_info lfi;
-
-    int mb_row;
-    int mb_col;
-    int mb_rows = cm->mb_rows;
-    int mb_cols = cm->mb_cols;
-
-    int filter_level;
-
-    unsigned char *y_ptr, *u_ptr, *v_ptr;
-
-    /* Point at base of Mb MODE_INFO list */
-    const MODE_INFO *mode_info_context = cm->mi;
-    int post_y_stride = post->y_stride;
-    int post_uv_stride = post->uv_stride;
-
-    /* Initialize the loop filter for this frame. */
-    vp8_loop_filter_frame_init(cm, mbd, cm->filter_level);
-
-    /* Set up the buffer pointers */
-    y_ptr = post->y_buffer;
-    u_ptr = post->u_buffer;
-    v_ptr = post->v_buffer;
-
-    /* vp8_filter each macro block */
-    if (cm->filter_type == NORMAL_LOOPFILTER)
-    {
-        for (mb_row = 0; mb_row < mb_rows; mb_row++)
-        {
-            for (mb_col = 0; mb_col < mb_cols; mb_col++)
-            {
-                int skip_lf = (mode_info_context->mbmi.mode != B_PRED &&
-                                mode_info_context->mbmi.mode != SPLITMV &&
-                                mode_info_context->mbmi.mb_skip_coeff);
-
-                const int mode_index = lfi_n->mode_lf_lut[mode_info_context->mbmi.mode];
-                const int seg = mode_info_context->mbmi.segment_id;
-                const int ref_frame = mode_info_context->mbmi.ref_frame;
-
-                filter_level = lfi_n->lvl[seg][ref_frame][mode_index];
-
-                if (filter_level)
-                {
-                    const int hev_index = lfi_n->hev_thr_lut[frame_type][filter_level];
-                    lfi.mblim = lfi_n->mblim[filter_level];
-                    lfi.blim = lfi_n->blim[filter_level];
-                    lfi.lim = lfi_n->lim[filter_level];
-                    lfi.hev_thr = lfi_n->hev_thr[hev_index];
-
-                    if (mb_col > 0)
-                        vp8_loop_filter_mbv
-                        (y_ptr, u_ptr, v_ptr, post_y_stride, post_uv_stride, &lfi);
-
-                    if (!skip_lf)
-                        vp8_loop_filter_bv
-                        (y_ptr, u_ptr, v_ptr, post_y_stride, post_uv_stride, &lfi);
-
-                    /* don't apply across umv border */
-                    if (mb_row > 0)
-                        vp8_loop_filter_mbh
-                        (y_ptr, u_ptr, v_ptr, post_y_stride, post_uv_stride, &lfi);
-
-                    if (!skip_lf)
-                        vp8_loop_filter_bh
-                        (y_ptr, u_ptr, v_ptr, post_y_stride, post_uv_stride, &lfi);
-                }
-
-                y_ptr += 16;
-                u_ptr += 8;
-                v_ptr += 8;
-
-                mode_info_context++;     /* step to next MB */
-            }
-            y_ptr += post_y_stride  * 16 - post->y_width;
-            u_ptr += post_uv_stride *  8 - post->uv_width;
-            v_ptr += post_uv_stride *  8 - post->uv_width;
-
-            mode_info_context++;         /* Skip border mb */
-
-        }
-    }
-    else /* SIMPLE_LOOPFILTER */
-    {
-        for (mb_row = 0; mb_row < mb_rows; mb_row++)
-        {
-            for (mb_col = 0; mb_col < mb_cols; mb_col++)
-            {
-                int skip_lf = (mode_info_context->mbmi.mode != B_PRED &&
-                                mode_info_context->mbmi.mode != SPLITMV &&
-                                mode_info_context->mbmi.mb_skip_coeff);
-
-                const int mode_index = lfi_n->mode_lf_lut[mode_info_context->mbmi.mode];
-                const int seg = mode_info_context->mbmi.segment_id;
-                const int ref_frame = mode_info_context->mbmi.ref_frame;
-
-                filter_level = lfi_n->lvl[seg][ref_frame][mode_index];
-                if (filter_level)
-                {
-                    const unsigned char * mblim = lfi_n->mblim[filter_level];
-                    const unsigned char * blim = lfi_n->blim[filter_level];
-
-                    if (mb_col > 0)
-                        vp8_loop_filter_simple_mbv
-                        (y_ptr, post_y_stride, mblim);
-
-                    if (!skip_lf)
-                        vp8_loop_filter_simple_bv
-                        (y_ptr, post_y_stride, blim);
-
-                    /* don't apply across umv border */
-                    if (mb_row > 0)
-                        vp8_loop_filter_simple_mbh
-                        (y_ptr, post_y_stride, mblim);
-
-                    if (!skip_lf)
-                        vp8_loop_filter_simple_bh
-                        (y_ptr, post_y_stride, blim);
-                }
-
-                y_ptr += 16;
-                u_ptr += 8;
-                v_ptr += 8;
-
-                mode_info_context++;     /* step to next MB */
-            }
-            y_ptr += post_y_stride  * 16 - post->y_width;
-            u_ptr += post_uv_stride *  8 - post->uv_width;
-            v_ptr += post_uv_stride *  8 - post->uv_width;
-
-            mode_info_context++;         /* Skip border mb */
-
-        }
-    }
-}
-
-void vp8_loop_filter_frame_yonly
-(
-    VP8_COMMON *cm,
-    MACROBLOCKD *mbd,
-    int default_filt_lvl
-)
-{
-    YV12_BUFFER_CONFIG *post = cm->frame_to_show;
-
-    unsigned char *y_ptr;
-    int mb_row;
-    int mb_col;
-
-    loop_filter_info_n *lfi_n = &cm->lf_info;
-    loop_filter_info lfi;
-
-    int filter_level;
-    FRAME_TYPE frame_type = cm->frame_type;
-
-    /* Point at base of Mb MODE_INFO list */
-    const MODE_INFO *mode_info_context = cm->mi;
-
-#if 0
-    if(default_filt_lvl == 0) /* no filter applied */
-        return;
-#endif
-
-    /* Initialize the loop filter for this frame. */
-    vp8_loop_filter_frame_init( cm, mbd, default_filt_lvl);
-
-    /* Set up the buffer pointers */
-    y_ptr = post->y_buffer;
-
-    /* vp8_filter each macro block */
-    for (mb_row = 0; mb_row < cm->mb_rows; mb_row++)
-    {
-        for (mb_col = 0; mb_col < cm->mb_cols; mb_col++)
-        {
-            int skip_lf = (mode_info_context->mbmi.mode != B_PRED &&
-                            mode_info_context->mbmi.mode != SPLITMV &&
-                            mode_info_context->mbmi.mb_skip_coeff);
-
-            const int mode_index = lfi_n->mode_lf_lut[mode_info_context->mbmi.mode];
-            const int seg = mode_info_context->mbmi.segment_id;
-            const int ref_frame = mode_info_context->mbmi.ref_frame;
-
-            filter_level = lfi_n->lvl[seg][ref_frame][mode_index];
-
-            if (filter_level)
-            {
-                if (cm->filter_type == NORMAL_LOOPFILTER)
-                {
-                    const int hev_index = lfi_n->hev_thr_lut[frame_type][filter_level];
-                    lfi.mblim = lfi_n->mblim[filter_level];
-                    lfi.blim = lfi_n->blim[filter_level];
-                    lfi.lim = lfi_n->lim[filter_level];
-                    lfi.hev_thr = lfi_n->hev_thr[hev_index];
-
-                    if (mb_col > 0)
-                        vp8_loop_filter_mbv
-                        (y_ptr, 0, 0, post->y_stride, 0, &lfi);
-
-                    if (!skip_lf)
-                        vp8_loop_filter_bv
-                        (y_ptr, 0, 0, post->y_stride, 0, &lfi);
-
-                    /* don't apply across umv border */
-                    if (mb_row > 0)
-                        vp8_loop_filter_mbh
-                        (y_ptr, 0, 0, post->y_stride, 0, &lfi);
-
-                    if (!skip_lf)
-                        vp8_loop_filter_bh
-                        (y_ptr, 0, 0, post->y_stride, 0, &lfi);
-                }
-                else
-                {
-                    if (mb_col > 0)
-                        vp8_loop_filter_simple_mbv
-                        (y_ptr, post->y_stride, lfi_n->mblim[filter_level]);
-
-                    if (!skip_lf)
-                        vp8_loop_filter_simple_bv
-                        (y_ptr, post->y_stride, lfi_n->blim[filter_level]);
-
-                    /* don't apply across umv border */
-                    if (mb_row > 0)
-                        vp8_loop_filter_simple_mbh
-                        (y_ptr, post->y_stride, lfi_n->mblim[filter_level]);
-
-                    if (!skip_lf)
-                        vp8_loop_filter_simple_bh
-                        (y_ptr, post->y_stride, lfi_n->blim[filter_level]);
-                }
-            }
-
-            y_ptr += 16;
-            mode_info_context ++;        /* step to next MB */
-
-        }
-
-        y_ptr += post->y_stride  * 16 - post->y_width;
-        mode_info_context ++;            /* Skip border mb */
-    }
-
-}
-
-void vp8_loop_filter_partial_frame
-(
-    VP8_COMMON *cm,
-    MACROBLOCKD *mbd,
-    int default_filt_lvl
-)
-{
-    YV12_BUFFER_CONFIG *post = cm->frame_to_show;
-
-    unsigned char *y_ptr;
-    int mb_row;
-    int mb_col;
-    int mb_cols = post->y_width >> 4;
-    int mb_rows = post->y_height >> 4;
-
-    int linestocopy;
-
-    loop_filter_info_n *lfi_n = &cm->lf_info;
-    loop_filter_info lfi;
-
-    int filter_level;
-    FRAME_TYPE frame_type = cm->frame_type;
-
-    const MODE_INFO *mode_info_context;
-
-#if 0
-    if(default_filt_lvl == 0) /* no filter applied */
-        return;
-#endif
-
-    /* Initialize the loop filter for this frame. */
-    vp8_loop_filter_frame_init( cm, mbd, default_filt_lvl);
-
-    /* number of MB rows to use in partial filtering */
-    linestocopy = mb_rows / PARTIAL_FRAME_FRACTION;
-    linestocopy = linestocopy ? linestocopy << 4 : 16;     /* 16 lines per MB */
-
-    /* Set up the buffer pointers; partial image starts at ~middle of frame */
-    y_ptr = post->y_buffer + ((post->y_height >> 5) * 16) * post->y_stride;
-    mode_info_context = cm->mi + (post->y_height >> 5) * (mb_cols + 1);
-
-    /* vp8_filter each macro block */
-    for (mb_row = 0; mb_row<(linestocopy >> 4); mb_row++)
-    {
-        for (mb_col = 0; mb_col < mb_cols; mb_col++)
-        {
-            int skip_lf = (mode_info_context->mbmi.mode != B_PRED &&
-                           mode_info_context->mbmi.mode != SPLITMV &&
-                           mode_info_context->mbmi.mb_skip_coeff);
-
-            const int mode_index =
-                lfi_n->mode_lf_lut[mode_info_context->mbmi.mode];
-            const int seg = mode_info_context->mbmi.segment_id;
-            const int ref_frame = mode_info_context->mbmi.ref_frame;
-
-            filter_level = lfi_n->lvl[seg][ref_frame][mode_index];
-
-            if (filter_level)
-            {
-                if (cm->filter_type == NORMAL_LOOPFILTER)
-                {
-                    const int hev_index = lfi_n->hev_thr_lut[frame_type][filter_level];
-                    lfi.mblim = lfi_n->mblim[filter_level];
-                    lfi.blim = lfi_n->blim[filter_level];
-                    lfi.lim = lfi_n->lim[filter_level];
-                    lfi.hev_thr = lfi_n->hev_thr[hev_index];
-
-                    if (mb_col > 0)
-                        vp8_loop_filter_mbv
-                        (y_ptr, 0, 0, post->y_stride, 0, &lfi);
-
-                    if (!skip_lf)
-                        vp8_loop_filter_bv
-                        (y_ptr, 0, 0, post->y_stride, 0, &lfi);
-
-                    vp8_loop_filter_mbh
-                        (y_ptr, 0, 0, post->y_stride, 0, &lfi);
-
-                    if (!skip_lf)
-                        vp8_loop_filter_bh
-                        (y_ptr, 0, 0, post->y_stride, 0, &lfi);
-                }
-                else
-                {
-                    if (mb_col > 0)
-                        vp8_loop_filter_simple_mbv
-                        (y_ptr, post->y_stride, lfi_n->mblim[filter_level]);
-
-                    if (!skip_lf)
-                        vp8_loop_filter_simple_bv
-                        (y_ptr, post->y_stride, lfi_n->blim[filter_level]);
-
-                    vp8_loop_filter_simple_mbh
-                        (y_ptr, post->y_stride, lfi_n->mblim[filter_level]);
-
-                    if (!skip_lf)
-                        vp8_loop_filter_simple_bh
-                        (y_ptr, post->y_stride, lfi_n->blim[filter_level]);
-                }
-            }
-
-            y_ptr += 16;
-            mode_info_context += 1;      /* step to next MB */
-        }
-
-        y_ptr += post->y_stride  * 16 - post->y_width;
-        mode_info_context += 1;          /* Skip border mb */
-    }
-}
diff --git a/vp8/common/x86/copy_sse2.asm b/vp8/common/x86/copy_sse2.asm
deleted file mode 100644 (file)
index 86fae26..0000000
+++ /dev/null
@@ -1,93 +0,0 @@
-;
-;  Copyright (c) 2010 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.
-;
-
-
-%include "vpx_ports/x86_abi_support.asm"
-
-
-;void vp8_copy32xn_sse2(
-;    unsigned char *src_ptr,
-;    int  src_stride,
-;    unsigned char *dst_ptr,
-;    int  dst_stride,
-;    int height);
-global sym(vp8_copy32xn_sse2) PRIVATE
-sym(vp8_copy32xn_sse2):
-    push        rbp
-    mov         rbp, rsp
-    SHADOW_ARGS_TO_STACK 5
-    SAVE_XMM 7
-    push        rsi
-    push        rdi
-    ; end prolog
-
-        mov             rsi,        arg(0) ;src_ptr
-        mov             rdi,        arg(2) ;dst_ptr
-
-        movsxd          rax,        dword ptr arg(1) ;src_stride
-        movsxd          rdx,        dword ptr arg(3) ;dst_stride
-        movsxd          rcx,        dword ptr arg(4) ;height
-
-.block_copy_sse2_loopx4:
-        movdqu          xmm0,       XMMWORD PTR [rsi]
-        movdqu          xmm1,       XMMWORD PTR [rsi + 16]
-        movdqu          xmm2,       XMMWORD PTR [rsi + rax]
-        movdqu          xmm3,       XMMWORD PTR [rsi + rax + 16]
-
-        lea             rsi,        [rsi+rax*2]
-
-        movdqu          xmm4,       XMMWORD PTR [rsi]
-        movdqu          xmm5,       XMMWORD PTR [rsi + 16]
-        movdqu          xmm6,       XMMWORD PTR [rsi + rax]
-        movdqu          xmm7,       XMMWORD PTR [rsi + rax + 16]
-
-        lea             rsi,    [rsi+rax*2]
-
-        movdqa          XMMWORD PTR [rdi], xmm0
-        movdqa          XMMWORD PTR [rdi + 16], xmm1
-        movdqa          XMMWORD PTR [rdi + rdx], xmm2
-        movdqa          XMMWORD PTR [rdi + rdx + 16], xmm3
-
-        lea             rdi,    [rdi+rdx*2]
-
-        movdqa          XMMWORD PTR [rdi], xmm4
-        movdqa          XMMWORD PTR [rdi + 16], xmm5
-        movdqa          XMMWORD PTR [rdi + rdx], xmm6
-        movdqa          XMMWORD PTR [rdi + rdx + 16], xmm7
-
-        lea             rdi,    [rdi+rdx*2]
-
-        sub             rcx,     4
-        cmp             rcx,     4
-        jge             .block_copy_sse2_loopx4
-
-        cmp             rcx, 0
-        je              .copy_is_done
-
-.block_copy_sse2_loop:
-        movdqu          xmm0,       XMMWORD PTR [rsi]
-        movdqu          xmm1,       XMMWORD PTR [rsi + 16]
-        lea             rsi,    [rsi+rax]
-
-        movdqa          XMMWORD PTR [rdi], xmm0
-        movdqa          XMMWORD PTR [rdi + 16], xmm1
-        lea             rdi,    [rdi+rdx]
-
-        sub             rcx,     1
-        jne             .block_copy_sse2_loop
-
-.copy_is_done:
-    ; begin epilog
-    pop rdi
-    pop rsi
-    RESTORE_XMM
-    UNSHADOW_ARGS
-    pop         rbp
-    ret
diff --git a/vp8/common/x86/copy_sse3.asm b/vp8/common/x86/copy_sse3.asm
deleted file mode 100644 (file)
index d789a40..0000000
+++ /dev/null
@@ -1,146 +0,0 @@
-;
-;  Copyright (c) 2010 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.
-;
-
-%include "vpx_ports/x86_abi_support.asm"
-
-%macro STACK_FRAME_CREATE_X3 0
-%if ABI_IS_32BIT
-  %define     src_ptr       rsi
-  %define     src_stride    rax
-  %define     ref_ptr       rdi
-  %define     ref_stride    rdx
-  %define     end_ptr       rcx
-  %define     ret_var       rbx
-  %define     result_ptr    arg(4)
-  %define     max_sad       arg(4)
-  %define     height        dword ptr arg(4)
-    push        rbp
-    mov         rbp,        rsp
-    push        rsi
-    push        rdi
-    push        rbx
-
-    mov         rsi,        arg(0)              ; src_ptr
-    mov         rdi,        arg(2)              ; ref_ptr
-
-    movsxd      rax,        dword ptr arg(1)    ; src_stride
-    movsxd      rdx,        dword ptr arg(3)    ; ref_stride
-%else
-  %if LIBVPX_YASM_WIN64
-    SAVE_XMM 7, u
-    %define     src_ptr     rcx
-    %define     src_stride  rdx
-    %define     ref_ptr     r8
-    %define     ref_stride  r9
-    %define     end_ptr     r10
-    %define     ret_var     r11
-    %define     result_ptr  [rsp+xmm_stack_space+8+4*8]
-    %define     max_sad     [rsp+xmm_stack_space+8+4*8]
-    %define     height      dword ptr [rsp+xmm_stack_space+8+4*8]
-  %else
-    %define     src_ptr     rdi
-    %define     src_stride  rsi
-    %define     ref_ptr     rdx
-    %define     ref_stride  rcx
-    %define     end_ptr     r9
-    %define     ret_var     r10
-    %define     result_ptr  r8
-    %define     max_sad     r8
-    %define     height      r8
-  %endif
-%endif
-
-%endmacro
-
-%macro STACK_FRAME_DESTROY_X3 0
-  %define     src_ptr
-  %define     src_stride
-  %define     ref_ptr
-  %define     ref_stride
-  %define     end_ptr
-  %define     ret_var
-  %define     result_ptr
-  %define     max_sad
-  %define     height
-
-%if ABI_IS_32BIT
-    pop         rbx
-    pop         rdi
-    pop         rsi
-    pop         rbp
-%else
-  %if LIBVPX_YASM_WIN64
-    RESTORE_XMM
-  %endif
-%endif
-    ret
-%endmacro
-
-
-;void vp8_copy32xn_sse3(
-;    unsigned char *src_ptr,
-;    int  src_stride,
-;    unsigned char *dst_ptr,
-;    int  dst_stride,
-;    int height);
-global sym(vp8_copy32xn_sse3) PRIVATE
-sym(vp8_copy32xn_sse3):
-
-    STACK_FRAME_CREATE_X3
-
-.block_copy_sse3_loopx4:
-        lea             end_ptr,    [src_ptr+src_stride*2]
-
-        movdqu          xmm0,       XMMWORD PTR [src_ptr]
-        movdqu          xmm1,       XMMWORD PTR [src_ptr + 16]
-        movdqu          xmm2,       XMMWORD PTR [src_ptr + src_stride]
-        movdqu          xmm3,       XMMWORD PTR [src_ptr + src_stride + 16]
-        movdqu          xmm4,       XMMWORD PTR [end_ptr]
-        movdqu          xmm5,       XMMWORD PTR [end_ptr + 16]
-        movdqu          xmm6,       XMMWORD PTR [end_ptr + src_stride]
-        movdqu          xmm7,       XMMWORD PTR [end_ptr + src_stride + 16]
-
-        lea             src_ptr,    [src_ptr+src_stride*4]
-
-        lea             end_ptr,    [ref_ptr+ref_stride*2]
-
-        movdqa          XMMWORD PTR [ref_ptr], xmm0
-        movdqa          XMMWORD PTR [ref_ptr + 16], xmm1
-        movdqa          XMMWORD PTR [ref_ptr + ref_stride], xmm2
-        movdqa          XMMWORD PTR [ref_ptr + ref_stride + 16], xmm3
-        movdqa          XMMWORD PTR [end_ptr], xmm4
-        movdqa          XMMWORD PTR [end_ptr + 16], xmm5
-        movdqa          XMMWORD PTR [end_ptr + ref_stride], xmm6
-        movdqa          XMMWORD PTR [end_ptr + ref_stride + 16], xmm7
-
-        lea             ref_ptr,    [ref_ptr+ref_stride*4]
-
-        sub             height,     4
-        cmp             height,     4
-        jge             .block_copy_sse3_loopx4
-
-        ;Check to see if there is more rows need to be copied.
-        cmp             height, 0
-        je              .copy_is_done
-
-.block_copy_sse3_loop:
-        movdqu          xmm0,       XMMWORD PTR [src_ptr]
-        movdqu          xmm1,       XMMWORD PTR [src_ptr + 16]
-        lea             src_ptr,    [src_ptr+src_stride]
-
-        movdqa          XMMWORD PTR [ref_ptr], xmm0
-        movdqa          XMMWORD PTR [ref_ptr + 16], xmm1
-        lea             ref_ptr,    [ref_ptr+ref_stride]
-
-        sub             height,     1
-        jne             .block_copy_sse3_loop
-
-.copy_is_done:
-    STACK_FRAME_DESTROY_X3
diff --git a/vp8/common/x86/dequantize_mmx.asm b/vp8/common/x86/dequantize_mmx.asm
deleted file mode 100644 (file)
index 4e551f0..0000000
+++ /dev/null
@@ -1,258 +0,0 @@
-;
-;  Copyright (c) 2010 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.
-;
-
-
-%include "vpx_ports/x86_abi_support.asm"
-
-
-;void vp8_dequantize_b_impl_mmx(short *sq, short *dq, short *q)
-global sym(vp8_dequantize_b_impl_mmx) PRIVATE
-sym(vp8_dequantize_b_impl_mmx):
-    push        rbp
-    mov         rbp, rsp
-    SHADOW_ARGS_TO_STACK 3
-    push        rsi
-    push        rdi
-    ; end prolog
-
-        mov       rsi, arg(0) ;sq
-        mov       rdi, arg(1) ;dq
-        mov       rax, arg(2) ;q
-
-        movq      mm1, [rsi]
-        pmullw    mm1, [rax+0]            ; mm4 *= kernel 0 modifiers.
-        movq      [rdi], mm1
-
-        movq      mm1, [rsi+8]
-        pmullw    mm1, [rax+8]            ; mm4 *= kernel 0 modifiers.
-        movq      [rdi+8], mm1
-
-        movq      mm1, [rsi+16]
-        pmullw    mm1, [rax+16]            ; mm4 *= kernel 0 modifiers.
-        movq      [rdi+16], mm1
-
-        movq      mm1, [rsi+24]
-        pmullw    mm1, [rax+24]            ; mm4 *= kernel 0 modifiers.
-        movq      [rdi+24], mm1
-
-    ; begin epilog
-    pop rdi
-    pop rsi
-    UNSHADOW_ARGS
-    pop         rbp
-    ret
-
-
-;void dequant_idct_add_mmx(
-;short *input,            0
-;short *dq,               1
-;unsigned char *dest,     2
-;int stride)              3
-global sym(vp8_dequant_idct_add_mmx) PRIVATE
-sym(vp8_dequant_idct_add_mmx):
-    push        rbp
-    mov         rbp, rsp
-    SHADOW_ARGS_TO_STACK 4
-    GET_GOT     rbx
-    push        rdi
-    ; end prolog
-
-        mov         rax,    arg(0) ;input
-        mov         rdx,    arg(1) ;dq
-
-
-        movq        mm0,    [rax   ]
-        pmullw      mm0,    [rdx]
-
-        movq        mm1,    [rax +8]
-        pmullw      mm1,    [rdx +8]
-
-        movq        mm2,    [rax+16]
-        pmullw      mm2,    [rdx+16]
-
-        movq        mm3,    [rax+24]
-        pmullw      mm3,    [rdx+24]
-
-        mov         rdx,    arg(2) ;dest
-
-        pxor        mm7,    mm7
-
-
-        movq        [rax],   mm7
-        movq        [rax+8], mm7
-
-        movq        [rax+16],mm7
-        movq        [rax+24],mm7
-
-
-        movsxd      rdi,            dword ptr arg(3) ;stride
-
-        psubw       mm0,            mm2             ; b1= 0-2
-        paddw       mm2,            mm2             ;
-
-        movq        mm5,            mm1
-        paddw       mm2,            mm0             ; a1 =0+2
-
-        pmulhw      mm5,            [GLOBAL(x_s1sqr2)];
-        paddw       mm5,            mm1             ; ip1 * sin(pi/8) * sqrt(2)
-
-        movq        mm7,            mm3             ;
-        pmulhw      mm7,            [GLOBAL(x_c1sqr2less1)];
-
-        paddw       mm7,            mm3             ; ip3 * cos(pi/8) * sqrt(2)
-        psubw       mm7,            mm5             ; c1
-
-        movq        mm5,            mm1
-        movq        mm4,            mm3
-
-        pmulhw      mm5,            [GLOBAL(x_c1sqr2less1)]
-        paddw       mm5,            mm1
-
-        pmulhw      mm3,            [GLOBAL(x_s1sqr2)]
-        paddw       mm3,            mm4
-
-        paddw       mm3,            mm5             ; d1
-        movq        mm6,            mm2             ; a1
-
-        movq        mm4,            mm0             ; b1
-        paddw       mm2,            mm3             ;0
-
-        paddw       mm4,            mm7             ;1
-        psubw       mm0,            mm7             ;2
-
-        psubw       mm6,            mm3             ;3
-
-        movq        mm1,            mm2             ; 03 02 01 00
-        movq        mm3,            mm4             ; 23 22 21 20
-
-        punpcklwd   mm1,            mm0             ; 11 01 10 00
-        punpckhwd   mm2,            mm0             ; 13 03 12 02
-
-        punpcklwd   mm3,            mm6             ; 31 21 30 20
-        punpckhwd   mm4,            mm6             ; 33 23 32 22
-
-        movq        mm0,            mm1             ; 11 01 10 00
-        movq        mm5,            mm2             ; 13 03 12 02
-
-        punpckldq   mm0,            mm3             ; 30 20 10 00
-        punpckhdq   mm1,            mm3             ; 31 21 11 01
-
-        punpckldq   mm2,            mm4             ; 32 22 12 02
-        punpckhdq   mm5,            mm4             ; 33 23 13 03
-
-        movq        mm3,            mm5             ; 33 23 13 03
-
-        psubw       mm0,            mm2             ; b1= 0-2
-        paddw       mm2,            mm2             ;
-
-        movq        mm5,            mm1
-        paddw       mm2,            mm0             ; a1 =0+2
-
-        pmulhw      mm5,            [GLOBAL(x_s1sqr2)];
-        paddw       mm5,            mm1             ; ip1 * sin(pi/8) * sqrt(2)
-
-        movq        mm7,            mm3             ;
-        pmulhw      mm7,            [GLOBAL(x_c1sqr2less1)];
-
-        paddw       mm7,            mm3             ; ip3 * cos(pi/8) * sqrt(2)
-        psubw       mm7,            mm5             ; c1
-
-        movq        mm5,            mm1
-        movq        mm4,            mm3
-
-        pmulhw      mm5,            [GLOBAL(x_c1sqr2less1)]
-        paddw       mm5,            mm1
-
-        pmulhw      mm3,            [GLOBAL(x_s1sqr2)]
-        paddw       mm3,            mm4
-
-        paddw       mm3,            mm5             ; d1
-        paddw       mm0,            [GLOBAL(fours)]
-
-        paddw       mm2,            [GLOBAL(fours)]
-        movq        mm6,            mm2             ; a1
-
-        movq        mm4,            mm0             ; b1
-        paddw       mm2,            mm3             ;0
-
-        paddw       mm4,            mm7             ;1
-        psubw       mm0,            mm7             ;2
-
-        psubw       mm6,            mm3             ;3
-        psraw       mm2,            3
-
-        psraw       mm0,            3
-        psraw       mm4,            3
-
-        psraw       mm6,            3
-
-        movq        mm1,            mm2             ; 03 02 01 00
-        movq        mm3,            mm4             ; 23 22 21 20
-
-        punpcklwd   mm1,            mm0             ; 11 01 10 00
-        punpckhwd   mm2,            mm0             ; 13 03 12 02
-
-        punpcklwd   mm3,            mm6             ; 31 21 30 20
-        punpckhwd   mm4,            mm6             ; 33 23 32 22
-
-        movq        mm0,            mm1             ; 11 01 10 00
-        movq        mm5,            mm2             ; 13 03 12 02
-
-        punpckldq   mm0,            mm3             ; 30 20 10 00
-        punpckhdq   mm1,            mm3             ; 31 21 11 01
-
-        punpckldq   mm2,            mm4             ; 32 22 12 02
-        punpckhdq   mm5,            mm4             ; 33 23 13 03
-
-        pxor        mm7,            mm7
-
-        movd        mm4,            [rdx]
-        punpcklbw   mm4,            mm7
-        paddsw      mm0,            mm4
-        packuswb    mm0,            mm7
-        movd        [rdx],          mm0
-
-        movd        mm4,            [rdx+rdi]
-        punpcklbw   mm4,            mm7
-        paddsw      mm1,            mm4
-        packuswb    mm1,            mm7
-        movd        [rdx+rdi],      mm1
-
-        movd        mm4,            [rdx+2*rdi]
-        punpcklbw   mm4,            mm7
-        paddsw      mm2,            mm4
-        packuswb    mm2,            mm7
-        movd        [rdx+rdi*2],    mm2
-
-        add         rdx,            rdi
-
-        movd        mm4,            [rdx+2*rdi]
-        punpcklbw   mm4,            mm7
-        paddsw      mm5,            mm4
-        packuswb    mm5,            mm7
-        movd        [rdx+rdi*2],    mm5
-
-    ; begin epilog
-    pop rdi
-    RESTORE_GOT
-    UNSHADOW_ARGS
-    pop         rbp
-    ret
-
-SECTION_RODATA
-align 16
-x_s1sqr2:
-    times 4 dw 0x8A8C
-align 16
-x_c1sqr2less1:
-    times 4 dw 0x4E7B
-align 16
-fours:
-    times 4 dw 0x0004
diff --git a/vp8/common/x86/filter_x86.c b/vp8/common/x86/filter_x86.c
deleted file mode 100644 (file)
index 7f496ed..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- *  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.
- */
-
-#include "vp8/common/x86/filter_x86.h"
-
-DECLARE_ALIGNED(16, const short, vp8_bilinear_filters_x86_4[8][8]) =
-{
-    { 128, 128, 128, 128,   0,   0,   0,   0 },
-    { 112, 112, 112, 112,  16,  16,  16,  16 },
-    {  96,  96,  96,  96,  32,  32,  32,  32 },
-    {  80,  80,  80,  80,  48,  48,  48,  48 },
-    {  64,  64,  64,  64,  64,  64,  64,  64 },
-    {  48,  48,  48,  48,  80,  80,  80,  80 },
-    {  32,  32,  32,  32,  96,  96,  96,  96 },
-    {  16,  16,  16,  16, 112, 112, 112, 112 }
-};
-
-DECLARE_ALIGNED(16, const short, vp8_bilinear_filters_x86_8[8][16]) =
-{
-    { 128, 128, 128, 128, 128, 128, 128, 128,   0,   0,   0,   0,   0,   0,   0,   0 },
-    { 112, 112, 112, 112, 112, 112, 112, 112,  16,  16,  16,  16,  16,  16,  16,  16 },
-    {  96,  96,  96,  96,  96,  96,  96,  96,  32,  32,  32,  32,  32,  32,  32,  32 },
-    {  80,  80,  80,  80,  80,  80,  80,  80,  48,  48,  48,  48,  48,  48,  48,  48 },
-    {  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64 },
-    {  48,  48,  48,  48,  48,  48,  48,  48,  80,  80,  80,  80,  80,  80,  80,  80 },
-    {  32,  32,  32,  32,  32,  32,  32,  32,  96,  96,  96,  96,  96,  96,  96,  96 },
-    {  16,  16,  16,  16,  16,  16,  16,  16, 112, 112, 112, 112, 112, 112, 112, 112 }
-};
diff --git a/vp8/common/x86/filter_x86.h b/vp8/common/x86/filter_x86.h
deleted file mode 100644 (file)
index d282841..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- *  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.
- */
-
-#ifndef VP8_COMMON_X86_FILTER_X86_H_
-#define VP8_COMMON_X86_FILTER_X86_H_
-
-#include "vpx_ports/mem.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* x86 assembly specific copy of vp8/common/filter.c:vp8_bilinear_filters with
- * duplicated values */
-
-/* duplicated 4x */
-extern DECLARE_ALIGNED(16, const short, vp8_bilinear_filters_x86_4[8][8]);
-
-/* duplicated 8x */
-extern DECLARE_ALIGNED(16, const short, vp8_bilinear_filters_x86_8[8][16]);
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP8_COMMON_X86_FILTER_X86_H_
diff --git a/vp8/common/x86/idct_blk_mmx.c b/vp8/common/x86/idct_blk_mmx.c
deleted file mode 100644 (file)
index f2532b3..0000000
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#include "vpx_config.h"
-#include "vp8_rtcd.h"
-#include "vp8/common/blockd.h"
-#include "vpx_mem/vpx_mem.h"
-
-extern void vp8_dequantize_b_impl_mmx(short *sq, short *dq, short *q);
-
-void vp8_dequantize_b_mmx(BLOCKD *d, short *DQC)
-{
-    short *sq = (short *) d->qcoeff;
-    short *dq = (short *) d->dqcoeff;
-
-    vp8_dequantize_b_impl_mmx(sq, dq, DQC);
-}
-
-void vp8_dequant_idct_add_y_block_mmx
-            (short *q, short *dq,
-             unsigned char *dst, int stride, char *eobs)
-{
-    int i;
-
-    for (i = 0; i < 4; i++)
-    {
-        if (eobs[0] > 1)
-            vp8_dequant_idct_add_mmx (q, dq, dst, stride);
-        else if (eobs[0] == 1)
-        {
-            vp8_dc_only_idct_add_mmx (q[0]*dq[0], dst, stride, dst, stride);
-            memset(q, 0, 2 * sizeof(q[0]));
-        }
-
-        if (eobs[1] > 1)
-            vp8_dequant_idct_add_mmx (q+16, dq, dst+4, stride);
-        else if (eobs[1] == 1)
-        {
-            vp8_dc_only_idct_add_mmx (q[16]*dq[0], dst+4, stride,
-                                      dst+4, stride);
-            memset(q + 16, 0, 2 * sizeof(q[0]));
-        }
-
-        if (eobs[2] > 1)
-            vp8_dequant_idct_add_mmx (q+32, dq, dst+8, stride);
-        else if (eobs[2] == 1)
-        {
-            vp8_dc_only_idct_add_mmx (q[32]*dq[0], dst+8, stride,
-                                      dst+8, stride);
-            memset(q + 32, 0, 2 * sizeof(q[0]));
-        }
-
-        if (eobs[3] > 1)
-            vp8_dequant_idct_add_mmx (q+48, dq, dst+12, stride);
-        else if (eobs[3] == 1)
-        {
-            vp8_dc_only_idct_add_mmx (q[48]*dq[0], dst+12, stride,
-                                      dst+12, stride);
-            memset(q + 48, 0, 2 * sizeof(q[0]));
-        }
-
-        q    += 64;
-        dst  += 4*stride;
-        eobs += 4;
-    }
-}
-
-void vp8_dequant_idct_add_uv_block_mmx
-            (short *q, short *dq,
-             unsigned char *dstu, unsigned char *dstv, int stride, char *eobs)
-{
-    int i;
-
-    for (i = 0; i < 2; i++)
-    {
-        if (eobs[0] > 1)
-            vp8_dequant_idct_add_mmx (q, dq, dstu, stride);
-        else if (eobs[0] == 1)
-        {
-            vp8_dc_only_idct_add_mmx (q[0]*dq[0], dstu, stride, dstu, stride);
-            memset(q, 0, 2 * sizeof(q[0]));
-        }
-
-        if (eobs[1] > 1)
-            vp8_dequant_idct_add_mmx (q+16, dq, dstu+4, stride);
-        else if (eobs[1] == 1)
-        {
-            vp8_dc_only_idct_add_mmx (q[16]*dq[0], dstu+4, stride,
-                                      dstu+4, stride);
-            memset(q + 16, 0, 2 * sizeof(q[0]));
-        }
-
-        q    += 32;
-        dstu += 4*stride;
-        eobs += 2;
-    }
-
-    for (i = 0; i < 2; i++)
-    {
-        if (eobs[0] > 1)
-            vp8_dequant_idct_add_mmx (q, dq, dstv, stride);
-        else if (eobs[0] == 1)
-        {
-            vp8_dc_only_idct_add_mmx (q[0]*dq[0], dstv, stride, dstv, stride);
-            memset(q, 0, 2 * sizeof(q[0]));
-        }
-
-        if (eobs[1] > 1)
-            vp8_dequant_idct_add_mmx (q+16, dq, dstv+4, stride);
-        else if (eobs[1] == 1)
-        {
-            vp8_dc_only_idct_add_mmx (q[16]*dq[0], dstv+4, stride,
-                                      dstv+4, stride);
-            memset(q + 16, 0, 2 * sizeof(q[0]));
-        }
-
-        q    += 32;
-        dstv += 4*stride;
-        eobs += 2;
-    }
-}
diff --git a/vp8/common/x86/idct_blk_sse2.c b/vp8/common/x86/idct_blk_sse2.c
deleted file mode 100644 (file)
index ae96ec8..0000000
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#include "vpx_config.h"
-#include "vp8_rtcd.h"
-
-void vp8_idct_dequant_0_2x_sse2
-            (short *q, short *dq ,
-             unsigned char *dst, int dst_stride);
-void vp8_idct_dequant_full_2x_sse2
-            (short *q, short *dq ,
-             unsigned char *dst, int dst_stride);
-
-void vp8_dequant_idct_add_y_block_sse2
-            (short *q, short *dq,
-             unsigned char *dst, int stride, char *eobs)
-{
-    int i;
-
-    for (i = 0; i < 4; i++)
-    {
-        if (((short *)(eobs))[0])
-        {
-            if (((short *)(eobs))[0] & 0xfefe)
-                vp8_idct_dequant_full_2x_sse2 (q, dq, dst, stride);
-            else
-                vp8_idct_dequant_0_2x_sse2 (q, dq, dst, stride);
-        }
-        if (((short *)(eobs))[1])
-        {
-            if (((short *)(eobs))[1] & 0xfefe)
-                vp8_idct_dequant_full_2x_sse2 (q+32, dq, dst+8, stride);
-            else
-                vp8_idct_dequant_0_2x_sse2 (q+32, dq, dst+8, stride);
-        }
-        q    += 64;
-        dst  += stride*4;
-        eobs += 4;
-    }
-}
-
-void vp8_dequant_idct_add_uv_block_sse2
-            (short *q, short *dq,
-             unsigned char *dstu, unsigned char *dstv, int stride, char *eobs)
-{
-    if (((short *)(eobs))[0])
-    {
-        if (((short *)(eobs))[0] & 0xfefe)
-            vp8_idct_dequant_full_2x_sse2 (q, dq, dstu, stride);
-        else
-            vp8_idct_dequant_0_2x_sse2 (q, dq, dstu, stride);
-    }
-    q    += 32;
-    dstu += stride*4;
-
-    if (((short *)(eobs))[1])
-    {
-        if (((short *)(eobs))[1] & 0xfefe)
-            vp8_idct_dequant_full_2x_sse2 (q, dq, dstu, stride);
-        else
-            vp8_idct_dequant_0_2x_sse2 (q, dq, dstu, stride);
-    }
-    q    += 32;
-
-    if (((short *)(eobs))[2])
-    {
-        if (((short *)(eobs))[2] & 0xfefe)
-            vp8_idct_dequant_full_2x_sse2 (q, dq, dstv, stride);
-        else
-            vp8_idct_dequant_0_2x_sse2 (q, dq, dstv, stride);
-    }
-    q    += 32;
-    dstv += stride*4;
-
-    if (((short *)(eobs))[3])
-    {
-      if (((short *)(eobs))[3] & 0xfefe)
-          vp8_idct_dequant_full_2x_sse2 (q, dq, dstv, stride);
-      else
-          vp8_idct_dequant_0_2x_sse2 (q, dq, dstv, stride);
-    }
-}
diff --git a/vp8/common/x86/idctllm_mmx.asm b/vp8/common/x86/idctllm_mmx.asm
deleted file mode 100644 (file)
index 96fa2c6..0000000
+++ /dev/null
@@ -1,295 +0,0 @@
-;
-;  Copyright (c) 2010 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.
-;
-
-
-%include "vpx_ports/x86_abi_support.asm"
-
-; /****************************************************************************
-; * Notes:
-; *
-; * This implementation makes use of 16 bit fixed point version of two multiply
-; * constants:
-; *        1.   sqrt(2) * cos (pi/8)
-; *        2.   sqrt(2) * sin (pi/8)
-; * Because the first constant is bigger than 1, to maintain the same 16 bit
-; * fixed point precision as the second one, we use a trick of
-; *        x * a = x + x*(a-1)
-; * so
-; *        x * sqrt(2) * cos (pi/8) = x + x * (sqrt(2) *cos(pi/8)-1).
-; *
-; * For the second constant, because of the 16bit version is 35468, which
-; * is bigger than 32768, in signed 16 bit multiply, it becomes a negative
-; * number.
-; *        (x * (unsigned)35468 >> 16) = x * (signed)35468 >> 16 + x
-; *
-; **************************************************************************/
-
-
-;void vp8_short_idct4x4llm_mmx(short *input, unsigned char *pred,
-;int pitch, unsigned char *dest,int stride)
-global sym(vp8_short_idct4x4llm_mmx) PRIVATE
-sym(vp8_short_idct4x4llm_mmx):
-    push        rbp
-    mov         rbp, rsp
-    SHADOW_ARGS_TO_STACK 5
-    GET_GOT     rbx
-    push        rsi
-    push        rdi
-    ; end prolog
-
-    mov         rax,    arg(0)              ;input
-    mov         rsi,    arg(1)              ;pred
-
-    movq        mm0,    [rax   ]
-    movq        mm1,    [rax+ 8]
-    movq        mm2,    [rax+16]
-    movq        mm3,    [rax+24]
-
-%if 0
-    pxor        mm7,    mm7
-    movq        [rax],   mm7
-    movq        [rax+8], mm7
-    movq        [rax+16],mm7
-    movq        [rax+24],mm7
-%endif
-    movsxd      rax,    dword ptr arg(2)    ;pitch
-    mov         rdx,    arg(3)              ;dest
-    movsxd      rdi,    dword ptr arg(4)    ;stride
-
-
-    psubw       mm0,            mm2             ; b1= 0-2
-    paddw       mm2,            mm2             ;
-
-    movq        mm5,            mm1
-    paddw       mm2,            mm0             ; a1 =0+2
-
-    pmulhw      mm5,            [GLOBAL(x_s1sqr2)];
-    paddw       mm5,            mm1             ; ip1 * sin(pi/8) * sqrt(2)
-
-    movq        mm7,            mm3             ;
-    pmulhw      mm7,            [GLOBAL(x_c1sqr2less1)];
-
-    paddw       mm7,            mm3             ; ip3 * cos(pi/8) * sqrt(2)
-    psubw       mm7,            mm5             ; c1
-
-    movq        mm5,            mm1
-    movq        mm4,            mm3
-
-    pmulhw      mm5,            [GLOBAL(x_c1sqr2less1)]
-    paddw       mm5,            mm1
-
-    pmulhw      mm3,            [GLOBAL(x_s1sqr2)]
-    paddw       mm3,            mm4
-
-    paddw       mm3,            mm5             ; d1
-    movq        mm6,            mm2             ; a1
-
-    movq        mm4,            mm0             ; b1
-    paddw       mm2,            mm3             ;0
-
-    paddw       mm4,            mm7             ;1
-    psubw       mm0,            mm7             ;2
-
-    psubw       mm6,            mm3             ;3
-
-    movq        mm1,            mm2             ; 03 02 01 00
-    movq        mm3,            mm4             ; 23 22 21 20
-
-    punpcklwd   mm1,            mm0             ; 11 01 10 00
-    punpckhwd   mm2,            mm0             ; 13 03 12 02
-
-    punpcklwd   mm3,            mm6             ; 31 21 30 20
-    punpckhwd   mm4,            mm6             ; 33 23 32 22
-
-    movq        mm0,            mm1             ; 11 01 10 00
-    movq        mm5,            mm2             ; 13 03 12 02
-
-    punpckldq   mm0,            mm3             ; 30 20 10 00
-    punpckhdq   mm1,            mm3             ; 31 21 11 01
-
-    punpckldq   mm2,            mm4             ; 32 22 12 02
-    punpckhdq   mm5,            mm4             ; 33 23 13 03
-
-    movq        mm3,            mm5             ; 33 23 13 03
-
-    psubw       mm0,            mm2             ; b1= 0-2
-    paddw       mm2,            mm2             ;
-
-    movq        mm5,            mm1
-    paddw       mm2,            mm0             ; a1 =0+2
-
-    pmulhw      mm5,            [GLOBAL(x_s1sqr2)];
-    paddw       mm5,            mm1             ; ip1 * sin(pi/8) * sqrt(2)
-
-    movq        mm7,            mm3             ;
-    pmulhw      mm7,            [GLOBAL(x_c1sqr2less1)];
-
-    paddw       mm7,            mm3             ; ip3 * cos(pi/8) * sqrt(2)
-    psubw       mm7,            mm5             ; c1
-
-    movq        mm5,            mm1
-    movq        mm4,            mm3
-
-    pmulhw      mm5,            [GLOBAL(x_c1sqr2less1)]
-    paddw       mm5,            mm1
-
-    pmulhw      mm3,            [GLOBAL(x_s1sqr2)]
-    paddw       mm3,            mm4
-
-    paddw       mm3,            mm5             ; d1
-    paddw       mm0,            [GLOBAL(fours)]
-
-    paddw       mm2,            [GLOBAL(fours)]
-    movq        mm6,            mm2             ; a1
-
-    movq        mm4,            mm0             ; b1
-    paddw       mm2,            mm3             ;0
-
-    paddw       mm4,            mm7             ;1
-    psubw       mm0,            mm7             ;2
-
-    psubw       mm6,            mm3             ;3
-    psraw       mm2,            3
-
-    psraw       mm0,            3
-    psraw       mm4,            3
-
-    psraw       mm6,            3
-
-    movq        mm1,            mm2             ; 03 02 01 00
-    movq        mm3,            mm4             ; 23 22 21 20
-
-    punpcklwd   mm1,            mm0             ; 11 01 10 00
-    punpckhwd   mm2,            mm0             ; 13 03 12 02
-
-    punpcklwd   mm3,            mm6             ; 31 21 30 20
-    punpckhwd   mm4,            mm6             ; 33 23 32 22
-
-    movq        mm0,            mm1             ; 11 01 10 00
-    movq        mm5,            mm2             ; 13 03 12 02
-
-    punpckldq   mm0,            mm3             ; 30 20 10 00
-    punpckhdq   mm1,            mm3             ; 31 21 11 01
-
-    punpckldq   mm2,            mm4             ; 32 22 12 02
-    punpckhdq   mm5,            mm4             ; 33 23 13 03
-
-    pxor        mm7,            mm7
-
-    movd        mm4,            [rsi]
-    punpcklbw   mm4,            mm7
-    paddsw      mm0,            mm4
-    packuswb    mm0,            mm7
-    movd        [rdx],          mm0
-
-    movd        mm4,            [rsi+rax]
-    punpcklbw   mm4,            mm7
-    paddsw      mm1,            mm4
-    packuswb    mm1,            mm7
-    movd        [rdx+rdi],      mm1
-
-    movd        mm4,            [rsi+2*rax]
-    punpcklbw   mm4,            mm7
-    paddsw      mm2,            mm4
-    packuswb    mm2,            mm7
-    movd        [rdx+rdi*2],    mm2
-
-    add         rdx,            rdi
-    add         rsi,            rax
-
-    movd        mm4,            [rsi+2*rax]
-    punpcklbw   mm4,            mm7
-    paddsw      mm5,            mm4
-    packuswb    mm5,            mm7
-    movd        [rdx+rdi*2],    mm5
-
-    ; begin epilog
-    pop rdi
-    pop rsi
-    RESTORE_GOT
-    UNSHADOW_ARGS
-    pop         rbp
-    ret
-
-;void vp8_dc_only_idct_add_mmx(
-;short input_dc,
-;unsigned char *pred_ptr,
-;int pred_stride,
-;unsigned char *dst_ptr,
-;int stride)
-global sym(vp8_dc_only_idct_add_mmx) PRIVATE
-sym(vp8_dc_only_idct_add_mmx):
-    push        rbp
-    mov         rbp, rsp
-    SHADOW_ARGS_TO_STACK 5
-    GET_GOT     rbx
-    ; end prolog
-
-        movd        mm5,            arg(0) ;input_dc
-        mov         rax,            arg(1) ;pred_ptr
-        movsxd      rdx,            dword ptr arg(2) ;pred_stride
-
-        pxor        mm0,            mm0
-
-        paddw       mm5,            [GLOBAL(fours)]
-        lea         rcx,            [rdx + rdx*2]
-
-        psraw       mm5,            3
-
-        punpcklwd   mm5,            mm5
-
-        punpckldq   mm5,            mm5
-
-        movd        mm1,            [rax]
-        movd        mm2,            [rax+rdx]
-        movd        mm3,            [rax+2*rdx]
-        movd        mm4,            [rax+rcx]
-
-        mov         rax,            arg(3) ;d -- destination
-        movsxd      rdx,            dword ptr arg(4) ;dst_stride
-
-        punpcklbw   mm1,            mm0
-        paddsw      mm1,            mm5
-        packuswb    mm1,            mm0              ; pack and unpack to saturate
-        lea         rcx,            [rdx + rdx*2]
-
-        punpcklbw   mm2,            mm0
-        paddsw      mm2,            mm5
-        packuswb    mm2,            mm0              ; pack and unpack to saturate
-
-        punpcklbw   mm3,            mm0
-        paddsw      mm3,            mm5
-        packuswb    mm3,            mm0              ; pack and unpack to saturate
-
-        punpcklbw   mm4,            mm0
-        paddsw      mm4,            mm5
-        packuswb    mm4,            mm0              ; pack and unpack to saturate
-
-        movd        [rax],          mm1
-        movd        [rax+rdx],      mm2
-        movd        [rax+2*rdx],    mm3
-        movd        [rax+rcx],      mm4
-
-    ; begin epilog
-    RESTORE_GOT
-    UNSHADOW_ARGS
-    pop         rbp
-    ret
-
-SECTION_RODATA
-align 16
-x_s1sqr2:
-    times 4 dw 0x8A8C
-align 16
-x_c1sqr2less1:
-    times 4 dw 0x4E7B
-align 16
-fours:
-    times 4 dw 0x0004
diff --git a/vp8/common/x86/idctllm_sse2.asm b/vp8/common/x86/idctllm_sse2.asm
deleted file mode 100644 (file)
index bf8e2c4..0000000
+++ /dev/null
@@ -1,708 +0,0 @@
-;
-;  Copyright (c) 2010 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.
-;
-
-
-%include "vpx_ports/x86_abi_support.asm"
-
-;void vp8_idct_dequant_0_2x_sse2
-; (
-;   short *qcoeff       - 0
-;   short *dequant      - 1
-;   unsigned char *dst  - 2
-;   int dst_stride      - 3
-; )
-
-global sym(vp8_idct_dequant_0_2x_sse2) PRIVATE
-sym(vp8_idct_dequant_0_2x_sse2):
-    push        rbp
-    mov         rbp, rsp
-    SHADOW_ARGS_TO_STACK 4
-    GET_GOT     rbx
-    ; end prolog
-
-        mov         rdx,            arg(1) ; dequant
-        mov         rax,            arg(0) ; qcoeff
-
-        movd        xmm4,           [rax]
-        movd        xmm5,           [rdx]
-
-        pinsrw      xmm4,           [rax+32],   4
-        pinsrw      xmm5,           [rdx],      4
-
-        pmullw      xmm4,           xmm5
-
-    ; Zero out xmm5, for use unpacking
-        pxor        xmm5,           xmm5
-
-    ; clear coeffs
-        movd        [rax],          xmm5
-        movd        [rax+32],       xmm5
-;pshufb
-        mov         rax,            arg(2) ; dst
-        movsxd      rdx,            dword ptr arg(3) ; dst_stride
-
-        pshuflw     xmm4,           xmm4,       00000000b
-        pshufhw     xmm4,           xmm4,       00000000b
-
-        lea         rcx,            [rdx + rdx*2]
-        paddw       xmm4,           [GLOBAL(fours)]
-
-        psraw       xmm4,           3
-
-        movq        xmm0,           [rax]
-        movq        xmm1,           [rax+rdx]
-        movq        xmm2,           [rax+2*rdx]
-        movq        xmm3,           [rax+rcx]
-
-        punpcklbw   xmm0,           xmm5
-        punpcklbw   xmm1,           xmm5
-        punpcklbw   xmm2,           xmm5
-        punpcklbw   xmm3,           xmm5
-
-
-    ; Add to predict buffer
-        paddw       xmm0,           xmm4
-        paddw       xmm1,           xmm4
-        paddw       xmm2,           xmm4
-        paddw       xmm3,           xmm4
-
-    ; pack up before storing
-        packuswb    xmm0,           xmm5
-        packuswb    xmm1,           xmm5
-        packuswb    xmm2,           xmm5
-        packuswb    xmm3,           xmm5
-
-    ; store blocks back out
-        movq        [rax],          xmm0
-        movq        [rax + rdx],    xmm1
-
-        lea         rax,            [rax + 2*rdx]
-
-        movq        [rax],          xmm2
-        movq        [rax + rdx],    xmm3
-
-    ; begin epilog
-    RESTORE_GOT
-    UNSHADOW_ARGS
-    pop         rbp
-    ret
-
-;void vp8_idct_dequant_full_2x_sse2
-; (
-;   short *qcoeff       - 0
-;   short *dequant      - 1
-;   unsigned char *dst  - 2
-;   int dst_stride      - 3
-; )
-global sym(vp8_idct_dequant_full_2x_sse2) PRIVATE
-sym(vp8_idct_dequant_full_2x_sse2):
-    push        rbp
-    mov         rbp, rsp
-    SHADOW_ARGS_TO_STACK 4
-    SAVE_XMM 7
-    GET_GOT     rbx
-    push        rsi
-    push        rdi
-    ; end prolog
-
-    ; special case when 2 blocks have 0 or 1 coeffs
-    ; dc is set as first coeff, so no need to load qcoeff
-        mov         rax,            arg(0) ; qcoeff
-        mov         rdx,            arg(1)  ; dequant
-        mov         rdi,            arg(2) ; dst
-
-
-    ; Zero out xmm7, for use unpacking
-        pxor        xmm7,           xmm7
-
-
-    ; note the transpose of xmm1 and xmm2, necessary for shuffle
-    ;   to spit out sensicle data
-        movdqa      xmm0,           [rax]
-        movdqa      xmm2,           [rax+16]
-        movdqa      xmm1,           [rax+32]
-        movdqa      xmm3,           [rax+48]
-
-    ; Clear out coeffs
-        movdqa      [rax],          xmm7
-        movdqa      [rax+16],       xmm7
-        movdqa      [rax+32],       xmm7
-        movdqa      [rax+48],       xmm7
-
-    ; dequantize qcoeff buffer
-        pmullw      xmm0,           [rdx]
-        pmullw      xmm2,           [rdx+16]
-        pmullw      xmm1,           [rdx]
-        pmullw      xmm3,           [rdx+16]
-        movsxd      rdx,            dword ptr arg(3) ; dst_stride
-
-    ; repack so block 0 row x and block 1 row x are together
-        movdqa      xmm4,           xmm0
-        punpckldq   xmm0,           xmm1
-        punpckhdq   xmm4,           xmm1
-
-        pshufd      xmm0,           xmm0,       11011000b
-        pshufd      xmm1,           xmm4,       11011000b
-
-        movdqa      xmm4,           xmm2
-        punpckldq   xmm2,           xmm3
-        punpckhdq   xmm4,           xmm3
-
-        pshufd      xmm2,           xmm2,       11011000b
-        pshufd      xmm3,           xmm4,       11011000b
-
-    ; first pass
-        psubw       xmm0,           xmm2        ; b1 = 0-2
-        paddw       xmm2,           xmm2        ;
-
-        movdqa      xmm5,           xmm1
-        paddw       xmm2,           xmm0        ; a1 = 0+2
-
-        pmulhw      xmm5,           [GLOBAL(x_s1sqr2)]
-        lea         rcx,            [rdx + rdx*2]   ;dst_stride * 3
-        paddw       xmm5,           xmm1        ; ip1 * sin(pi/8) * sqrt(2)
-
-        movdqa      xmm7,           xmm3
-        pmulhw      xmm7,           [GLOBAL(x_c1sqr2less1)]
-
-        paddw       xmm7,           xmm3        ; ip3 * cos(pi/8) * sqrt(2)
-        psubw       xmm7,           xmm5        ; c1
-
-        movdqa      xmm5,           xmm1
-        movdqa      xmm4,           xmm3
-
-        pmulhw      xmm5,           [GLOBAL(x_c1sqr2less1)]
-        paddw       xmm5,           xmm1
-
-        pmulhw      xmm3,           [GLOBAL(x_s1sqr2)]
-        paddw       xmm3,           xmm4
-
-        paddw       xmm3,           xmm5        ; d1
-        movdqa      xmm6,           xmm2        ; a1
-
-        movdqa      xmm4,           xmm0        ; b1
-        paddw       xmm2,           xmm3        ;0
-
-        paddw       xmm4,           xmm7        ;1
-        psubw       xmm0,           xmm7        ;2
-
-        psubw       xmm6,           xmm3        ;3
-
-    ; transpose for the second pass
-        movdqa      xmm7,           xmm2        ; 103 102 101 100 003 002 001 000
-        punpcklwd   xmm2,           xmm0        ; 007 003 006 002 005 001 004 000
-        punpckhwd   xmm7,           xmm0        ; 107 103 106 102 105 101 104 100
-
-        movdqa      xmm5,           xmm4        ; 111 110 109 108 011 010 009 008
-        punpcklwd   xmm4,           xmm6        ; 015 011 014 010 013 009 012 008
-        punpckhwd   xmm5,           xmm6        ; 115 111 114 110 113 109 112 108
-
-
-        movdqa      xmm1,           xmm2        ; 007 003 006 002 005 001 004 000
-        punpckldq   xmm2,           xmm4        ; 013 009 005 001 012 008 004 000
-        punpckhdq   xmm1,           xmm4        ; 015 011 007 003 014 010 006 002
-
-        movdqa      xmm6,           xmm7        ; 107 103 106 102 105 101 104 100
-        punpckldq   xmm7,           xmm5        ; 113 109 105 101 112 108 104 100
-        punpckhdq   xmm6,           xmm5        ; 115 111 107 103 114 110 106 102
-
-
-        movdqa      xmm5,           xmm2        ; 013 009 005 001 012 008 004 000
-        punpckldq   xmm2,           xmm7        ; 112 108 012 008 104 100 004 000
-        punpckhdq   xmm5,           xmm7        ; 113 109 013 009 105 101 005 001
-
-        movdqa      xmm7,           xmm1        ; 015 011 007 003 014 010 006 002
-        punpckldq   xmm1,           xmm6        ; 114 110 014 010 106 102 006 002
-        punpckhdq   xmm7,           xmm6        ; 115 111 015 011 107 103 007 003
-
-        pshufd      xmm0,           xmm2,       11011000b
-        pshufd      xmm2,           xmm1,       11011000b
-
-        pshufd      xmm1,           xmm5,       11011000b
-        pshufd      xmm3,           xmm7,       11011000b
-
-    ; second pass
-        psubw       xmm0,           xmm2            ; b1 = 0-2
-        paddw       xmm2,           xmm2
-
-        movdqa      xmm5,           xmm1
-        paddw       xmm2,           xmm0            ; a1 = 0+2
-
-        pmulhw      xmm5,           [GLOBAL(x_s1sqr2)]
-        paddw       xmm5,           xmm1            ; ip1 * sin(pi/8) * sqrt(2)
-
-        movdqa      xmm7,           xmm3
-        pmulhw      xmm7,           [GLOBAL(x_c1sqr2less1)]
-
-        paddw       xmm7,           xmm3            ; ip3 * cos(pi/8) * sqrt(2)
-        psubw       xmm7,           xmm5            ; c1
-
-        movdqa      xmm5,           xmm1
-        movdqa      xmm4,           xmm3
-
-        pmulhw      xmm5,           [GLOBAL(x_c1sqr2less1)]
-        paddw       xmm5,           xmm1
-
-        pmulhw      xmm3,           [GLOBAL(x_s1sqr2)]
-        paddw       xmm3,           xmm4
-
-        paddw       xmm3,           xmm5            ; d1
-        paddw       xmm0,           [GLOBAL(fours)]
-
-        paddw       xmm2,           [GLOBAL(fours)]
-        movdqa      xmm6,           xmm2            ; a1
-
-        movdqa      xmm4,           xmm0            ; b1
-        paddw       xmm2,           xmm3            ;0
-
-        paddw       xmm4,           xmm7            ;1
-        psubw       xmm0,           xmm7            ;2
-
-        psubw       xmm6,           xmm3            ;3
-        psraw       xmm2,           3
-
-        psraw       xmm0,           3
-        psraw       xmm4,           3
-
-        psraw       xmm6,           3
-
-    ; transpose to save
-        movdqa      xmm7,           xmm2        ; 103 102 101 100 003 002 001 000
-        punpcklwd   xmm2,           xmm0        ; 007 003 006 002 005 001 004 000
-        punpckhwd   xmm7,           xmm0        ; 107 103 106 102 105 101 104 100
-
-        movdqa      xmm5,           xmm4        ; 111 110 109 108 011 010 009 008
-        punpcklwd   xmm4,           xmm6        ; 015 011 014 010 013 009 012 008
-        punpckhwd   xmm5,           xmm6        ; 115 111 114 110 113 109 112 108
-
-
-        movdqa      xmm1,           xmm2        ; 007 003 006 002 005 001 004 000
-        punpckldq   xmm2,           xmm4        ; 013 009 005 001 012 008 004 000
-        punpckhdq   xmm1,           xmm4        ; 015 011 007 003 014 010 006 002
-
-        movdqa      xmm6,           xmm7        ; 107 103 106 102 105 101 104 100
-        punpckldq   xmm7,           xmm5        ; 113 109 105 101 112 108 104 100
-        punpckhdq   xmm6,           xmm5        ; 115 111 107 103 114 110 106 102
-
-
-        movdqa      xmm5,           xmm2        ; 013 009 005 001 012 008 004 000
-        punpckldq   xmm2,           xmm7        ; 112 108 012 008 104 100 004 000
-        punpckhdq   xmm5,           xmm7        ; 113 109 013 009 105 101 005 001
-
-        movdqa      xmm7,           xmm1        ; 015 011 007 003 014 010 006 002
-        punpckldq   xmm1,           xmm6        ; 114 110 014 010 106 102 006 002
-        punpckhdq   xmm7,           xmm6        ; 115 111 015 011 107 103 007 003
-
-        pshufd      xmm0,           xmm2,       11011000b
-        pshufd      xmm2,           xmm1,       11011000b
-
-        pshufd      xmm1,           xmm5,       11011000b
-        pshufd      xmm3,           xmm7,       11011000b
-
-        pxor        xmm7,           xmm7
-
-    ; Load up predict blocks
-        movq        xmm4,           [rdi]
-        movq        xmm5,           [rdi+rdx]
-
-        punpcklbw   xmm4,           xmm7
-        punpcklbw   xmm5,           xmm7
-
-        paddw       xmm0,           xmm4
-        paddw       xmm1,           xmm5
-
-        movq        xmm4,           [rdi+2*rdx]
-        movq        xmm5,           [rdi+rcx]
-
-        punpcklbw   xmm4,           xmm7
-        punpcklbw   xmm5,           xmm7
-
-        paddw       xmm2,           xmm4
-        paddw       xmm3,           xmm5
-
-.finish:
-
-    ; pack up before storing
-        packuswb    xmm0,           xmm7
-        packuswb    xmm1,           xmm7
-        packuswb    xmm2,           xmm7
-        packuswb    xmm3,           xmm7
-
-    ; store blocks back out
-        movq        [rdi],          xmm0
-        movq        [rdi + rdx],    xmm1
-        movq        [rdi + rdx*2],  xmm2
-        movq        [rdi + rcx],    xmm3
-
-    ; begin epilog
-    pop         rdi
-    pop         rsi
-    RESTORE_GOT
-    RESTORE_XMM
-    UNSHADOW_ARGS
-    pop         rbp
-    ret
-
-;void vp8_idct_dequant_dc_0_2x_sse2
-; (
-;   short *qcoeff       - 0
-;   short *dequant      - 1
-;   unsigned char *dst  - 2
-;   int dst_stride      - 3
-;   short *dc           - 4
-; )
-global sym(vp8_idct_dequant_dc_0_2x_sse2) PRIVATE
-sym(vp8_idct_dequant_dc_0_2x_sse2):
-    push        rbp
-    mov         rbp, rsp
-    SHADOW_ARGS_TO_STACK 5
-    GET_GOT     rbx
-    push        rdi
-    ; end prolog
-
-    ; special case when 2 blocks have 0 or 1 coeffs
-    ; dc is set as first coeff, so no need to load qcoeff
-        mov         rax,            arg(0) ; qcoeff
-
-        mov         rdi,            arg(2) ; dst
-        mov         rdx,            arg(4) ; dc
-
-    ; Zero out xmm5, for use unpacking
-        pxor        xmm5,           xmm5
-
-    ; load up 2 dc words here == 2*16 = doubleword
-        movd        xmm4,           [rdx]
-
-        movsxd      rdx,            dword ptr arg(3) ; dst_stride
-        lea         rcx, [rdx + rdx*2]
-    ; Load up predict blocks
-        movq        xmm0,           [rdi]
-        movq        xmm1,           [rdi+rdx*1]
-        movq        xmm2,           [rdi+rdx*2]
-        movq        xmm3,           [rdi+rcx]
-
-    ; Duplicate and expand dc across
-        punpcklwd   xmm4,           xmm4
-        punpckldq   xmm4,           xmm4
-
-    ; Rounding to dequant and downshift
-        paddw       xmm4,           [GLOBAL(fours)]
-        psraw       xmm4,           3
-
-    ; Predict buffer needs to be expanded from bytes to words
-        punpcklbw   xmm0,           xmm5
-        punpcklbw   xmm1,           xmm5
-        punpcklbw   xmm2,           xmm5
-        punpcklbw   xmm3,           xmm5
-
-    ; Add to predict buffer
-        paddw       xmm0,           xmm4
-        paddw       xmm1,           xmm4
-        paddw       xmm2,           xmm4
-        paddw       xmm3,           xmm4
-
-    ; pack up before storing
-        packuswb    xmm0,           xmm5
-        packuswb    xmm1,           xmm5
-        packuswb    xmm2,           xmm5
-        packuswb    xmm3,           xmm5
-
-    ; store blocks back out
-        movq        [rdi],          xmm0
-        movq        [rdi + rdx],    xmm1
-        movq        [rdi + rdx*2],  xmm2
-        movq        [rdi + rcx],    xmm3
-
-    ; begin epilog
-    pop         rdi
-    RESTORE_GOT
-    UNSHADOW_ARGS
-    pop         rbp
-    ret
-;void vp8_idct_dequant_dc_full_2x_sse2
-; (
-;   short *qcoeff       - 0
-;   short *dequant      - 1
-;   unsigned char *dst  - 2
-;   int dst_stride      - 3
-;   short *dc           - 4
-; )
-global sym(vp8_idct_dequant_dc_full_2x_sse2) PRIVATE
-sym(vp8_idct_dequant_dc_full_2x_sse2):
-    push        rbp
-    mov         rbp, rsp
-    SHADOW_ARGS_TO_STACK 5
-    SAVE_XMM 7
-    GET_GOT     rbx
-    push        rdi
-    ; end prolog
-
-    ; special case when 2 blocks have 0 or 1 coeffs
-    ; dc is set as first coeff, so no need to load qcoeff
-        mov         rax,            arg(0) ; qcoeff
-        mov         rdx,            arg(1)  ; dequant
-
-        mov         rdi,            arg(2) ; dst
-
-    ; Zero out xmm7, for use unpacking
-        pxor        xmm7,           xmm7
-
-
-    ; note the transpose of xmm1 and xmm2, necessary for shuffle
-    ;   to spit out sensicle data
-        movdqa      xmm0,           [rax]
-        movdqa      xmm2,           [rax+16]
-        movdqa      xmm1,           [rax+32]
-        movdqa      xmm3,           [rax+48]
-
-    ; Clear out coeffs
-        movdqa      [rax],          xmm7
-        movdqa      [rax+16],       xmm7
-        movdqa      [rax+32],       xmm7
-        movdqa      [rax+48],       xmm7
-
-    ; dequantize qcoeff buffer
-        pmullw      xmm0,           [rdx]
-        pmullw      xmm2,           [rdx+16]
-        pmullw      xmm1,           [rdx]
-        pmullw      xmm3,           [rdx+16]
-
-    ; DC component
-        mov         rdx,            arg(4)
-
-    ; repack so block 0 row x and block 1 row x are together
-        movdqa      xmm4,           xmm0
-        punpckldq   xmm0,           xmm1
-        punpckhdq   xmm4,           xmm1
-
-        pshufd      xmm0,           xmm0,       11011000b
-        pshufd      xmm1,           xmm4,       11011000b
-
-        movdqa      xmm4,           xmm2
-        punpckldq   xmm2,           xmm3
-        punpckhdq   xmm4,           xmm3
-
-        pshufd      xmm2,           xmm2,       11011000b
-        pshufd      xmm3,           xmm4,       11011000b
-
-    ; insert DC component
-        pinsrw      xmm0,           [rdx],      0
-        pinsrw      xmm0,           [rdx+2],    4
-
-    ; first pass
-        psubw       xmm0,           xmm2        ; b1 = 0-2
-        paddw       xmm2,           xmm2        ;
-
-        movdqa      xmm5,           xmm1
-        paddw       xmm2,           xmm0        ; a1 = 0+2
-
-        pmulhw      xmm5,           [GLOBAL(x_s1sqr2)]
-        paddw       xmm5,           xmm1        ; ip1 * sin(pi/8) * sqrt(2)
-
-        movdqa      xmm7,           xmm3
-        pmulhw      xmm7,           [GLOBAL(x_c1sqr2less1)]
-
-        paddw       xmm7,           xmm3        ; ip3 * cos(pi/8) * sqrt(2)
-        psubw       xmm7,           xmm5        ; c1
-
-        movdqa      xmm5,           xmm1
-        movdqa      xmm4,           xmm3
-
-        pmulhw      xmm5,           [GLOBAL(x_c1sqr2less1)]
-        paddw       xmm5,           xmm1
-
-        pmulhw      xmm3,           [GLOBAL(x_s1sqr2)]
-        paddw       xmm3,           xmm4
-
-        paddw       xmm3,           xmm5        ; d1
-        movdqa      xmm6,           xmm2        ; a1
-
-        movdqa      xmm4,           xmm0        ; b1
-        paddw       xmm2,           xmm3        ;0
-
-        paddw       xmm4,           xmm7        ;1
-        psubw       xmm0,           xmm7        ;2
-
-        psubw       xmm6,           xmm3        ;3
-
-    ; transpose for the second pass
-        movdqa      xmm7,           xmm2        ; 103 102 101 100 003 002 001 000
-        punpcklwd   xmm2,           xmm0        ; 007 003 006 002 005 001 004 000
-        punpckhwd   xmm7,           xmm0        ; 107 103 106 102 105 101 104 100
-
-        movdqa      xmm5,           xmm4        ; 111 110 109 108 011 010 009 008
-        punpcklwd   xmm4,           xmm6        ; 015 011 014 010 013 009 012 008
-        punpckhwd   xmm5,           xmm6        ; 115 111 114 110 113 109 112 108
-
-
-        movdqa      xmm1,           xmm2        ; 007 003 006 002 005 001 004 000
-        punpckldq   xmm2,           xmm4        ; 013 009 005 001 012 008 004 000
-        punpckhdq   xmm1,           xmm4        ; 015 011 007 003 014 010 006 002
-
-        movdqa      xmm6,           xmm7        ; 107 103 106 102 105 101 104 100
-        punpckldq   xmm7,           xmm5        ; 113 109 105 101 112 108 104 100
-        punpckhdq   xmm6,           xmm5        ; 115 111 107 103 114 110 106 102
-
-
-        movdqa      xmm5,           xmm2        ; 013 009 005 001 012 008 004 000
-        punpckldq   xmm2,           xmm7        ; 112 108 012 008 104 100 004 000
-        punpckhdq   xmm5,           xmm7        ; 113 109 013 009 105 101 005 001
-
-        movdqa      xmm7,           xmm1        ; 015 011 007 003 014 010 006 002
-        punpckldq   xmm1,           xmm6        ; 114 110 014 010 106 102 006 002
-        punpckhdq   xmm7,           xmm6        ; 115 111 015 011 107 103 007 003
-
-        pshufd      xmm0,           xmm2,       11011000b
-        pshufd      xmm2,           xmm1,       11011000b
-
-        pshufd      xmm1,           xmm5,       11011000b
-        pshufd      xmm3,           xmm7,       11011000b
-
-    ; second pass
-        psubw       xmm0,           xmm2            ; b1 = 0-2
-        paddw       xmm2,           xmm2
-
-        movdqa      xmm5,           xmm1
-        paddw       xmm2,           xmm0            ; a1 = 0+2
-
-        pmulhw      xmm5,           [GLOBAL(x_s1sqr2)]
-        paddw       xmm5,           xmm1            ; ip1 * sin(pi/8) * sqrt(2)
-
-        movdqa      xmm7,           xmm3
-        pmulhw      xmm7,           [GLOBAL(x_c1sqr2less1)]
-
-        paddw       xmm7,           xmm3            ; ip3 * cos(pi/8) * sqrt(2)
-        psubw       xmm7,           xmm5            ; c1
-
-        movdqa      xmm5,           xmm1
-        movdqa      xmm4,           xmm3
-
-        pmulhw      xmm5,           [GLOBAL(x_c1sqr2less1)]
-        paddw       xmm5,           xmm1
-
-        pmulhw      xmm3,           [GLOBAL(x_s1sqr2)]
-        paddw       xmm3,           xmm4
-
-        paddw       xmm3,           xmm5            ; d1
-        paddw       xmm0,           [GLOBAL(fours)]
-
-        paddw       xmm2,           [GLOBAL(fours)]
-        movdqa      xmm6,           xmm2            ; a1
-
-        movdqa      xmm4,           xmm0            ; b1
-        paddw       xmm2,           xmm3            ;0
-
-        paddw       xmm4,           xmm7            ;1
-        psubw       xmm0,           xmm7            ;2
-
-        psubw       xmm6,           xmm3            ;3
-        psraw       xmm2,           3
-
-        psraw       xmm0,           3
-        psraw       xmm4,           3
-
-        psraw       xmm6,           3
-
-    ; transpose to save
-        movdqa      xmm7,           xmm2        ; 103 102 101 100 003 002 001 000
-        punpcklwd   xmm2,           xmm0        ; 007 003 006 002 005 001 004 000
-        punpckhwd   xmm7,           xmm0        ; 107 103 106 102 105 101 104 100
-
-        movdqa      xmm5,           xmm4        ; 111 110 109 108 011 010 009 008
-        punpcklwd   xmm4,           xmm6        ; 015 011 014 010 013 009 012 008
-        punpckhwd   xmm5,           xmm6        ; 115 111 114 110 113 109 112 108
-
-
-        movdqa      xmm1,           xmm2        ; 007 003 006 002 005 001 004 000
-        punpckldq   xmm2,           xmm4        ; 013 009 005 001 012 008 004 000
-        punpckhdq   xmm1,           xmm4        ; 015 011 007 003 014 010 006 002
-
-        movdqa      xmm6,           xmm7        ; 107 103 106 102 105 101 104 100
-        punpckldq   xmm7,           xmm5        ; 113 109 105 101 112 108 104 100
-        punpckhdq   xmm6,           xmm5        ; 115 111 107 103 114 110 106 102
-
-
-        movdqa      xmm5,           xmm2        ; 013 009 005 001 012 008 004 000
-        punpckldq   xmm2,           xmm7        ; 112 108 012 008 104 100 004 000
-        punpckhdq   xmm5,           xmm7        ; 113 109 013 009 105 101 005 001
-
-        movdqa      xmm7,           xmm1        ; 015 011 007 003 014 010 006 002
-        punpckldq   xmm1,           xmm6        ; 114 110 014 010 106 102 006 002
-        punpckhdq   xmm7,           xmm6        ; 115 111 015 011 107 103 007 003
-
-        pshufd      xmm0,           xmm2,       11011000b
-        pshufd      xmm2,           xmm1,       11011000b
-
-        pshufd      xmm1,           xmm5,       11011000b
-        pshufd      xmm3,           xmm7,       11011000b
-
-        pxor        xmm7,           xmm7
-
-    ; Load up predict blocks
-        movsxd      rdx,            dword ptr arg(3) ; dst_stride
-        movq        xmm4,           [rdi]
-        movq        xmm5,           [rdi+rdx]
-        lea         rcx,            [rdx + rdx*2]
-
-        punpcklbw   xmm4,           xmm7
-        punpcklbw   xmm5,           xmm7
-
-        paddw       xmm0,           xmm4
-        paddw       xmm1,           xmm5
-
-        movq        xmm4,           [rdi+rdx*2]
-        movq        xmm5,           [rdi+rcx]
-
-        punpcklbw   xmm4,           xmm7
-        punpcklbw   xmm5,           xmm7
-
-        paddw       xmm2,           xmm4
-        paddw       xmm3,           xmm5
-
-.finish:
-
-    ; pack up before storing
-        packuswb    xmm0,           xmm7
-        packuswb    xmm1,           xmm7
-        packuswb    xmm2,           xmm7
-        packuswb    xmm3,           xmm7
-
-    ; Load destination stride before writing out,
-    ;   doesn't need to persist
-        movsxd      rdx,            dword ptr arg(3) ; dst_stride
-
-    ; store blocks back out
-        movq        [rdi],          xmm0
-        movq        [rdi + rdx],    xmm1
-
-        lea         rdi,            [rdi + 2*rdx]
-
-        movq        [rdi],          xmm2
-        movq        [rdi + rdx],    xmm3
-
-
-    ; begin epilog
-    pop         rdi
-    RESTORE_GOT
-    RESTORE_XMM
-    UNSHADOW_ARGS
-    pop         rbp
-    ret
-
-SECTION_RODATA
-align 16
-fours:
-    times 8 dw 0x0004
-align 16
-x_s1sqr2:
-    times 8 dw 0x8A8C
-align 16
-x_c1sqr2less1:
-    times 8 dw 0x4E7B
diff --git a/vp8/common/x86/iwalsh_mmx.asm b/vp8/common/x86/iwalsh_mmx.asm
deleted file mode 100644 (file)
index 158c3b7..0000000
+++ /dev/null
@@ -1,140 +0,0 @@
-;
-;  Copyright (c) 2010 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.
-;
-
-
-%include "vpx_ports/x86_abi_support.asm"
-
-;void vp8_short_inv_walsh4x4_mmx(short *input, short *output)
-global sym(vp8_short_inv_walsh4x4_mmx) PRIVATE
-sym(vp8_short_inv_walsh4x4_mmx):
-    push        rbp
-    mov         rbp, rsp
-    SHADOW_ARGS_TO_STACK 2
-    ; end prolog
-
-    mov         rdx, arg(0)
-    mov         rax, 30003h
-
-    movq        mm0, [rdx + 0]    ;ip[0]
-    movq        mm1, [rdx + 8]    ;ip[4]
-    movq        mm7, rax
-
-    movq        mm2, [rdx + 16]   ;ip[8]
-    movq        mm3, [rdx + 24]   ;ip[12]
-    punpcklwd   mm7, mm7          ;0003000300030003h
-    mov         rdx, arg(1)
-
-    movq        mm4, mm0
-    movq        mm5, mm1
-
-    paddw       mm4, mm3          ;ip[0] + ip[12] aka al
-    paddw       mm5, mm2          ;ip[4] + ip[8] aka bl
-
-    movq        mm6, mm4          ;temp al
-    paddw       mm4, mm5          ;al + bl
-    psubw       mm6, mm5          ;al - bl
-
-    psubw       mm0, mm3          ;ip[0] - ip[12] aka d1
-    psubw       mm1, mm2          ;ip[4] - ip[8] aka c1
-
-    movq        mm5, mm0          ;temp dl
-    paddw       mm0, mm1          ;dl + cl
-    psubw       mm5, mm1          ;dl - cl
-
-    ; 03 02 01 00
-    ; 13 12 11 10
-    ; 23 22 21 20
-    ; 33 32 31 30
-
-    movq        mm3, mm4          ; 03 02 01 00
-    punpcklwd   mm4, mm0          ; 11 01 10 00
-    punpckhwd   mm3, mm0          ; 13 03 12 02
-
-    movq        mm1, mm6          ; 23 22 21 20
-    punpcklwd   mm6, mm5          ; 31 21 30 20
-    punpckhwd   mm1, mm5          ; 33 23 32 22
-
-    movq        mm0, mm4          ; 11 01 10 00
-    movq        mm2, mm3          ; 13 03 12 02
-
-    punpckldq   mm0, mm6          ; 30 20 10 00 aka ip[0]
-    punpckhdq   mm4, mm6          ; 31 21 11 01 aka ip[4]
-
-    punpckldq   mm2, mm1          ; 32 22 12 02 aka ip[8]
-    punpckhdq   mm3, mm1          ; 33 23 13 03 aka ip[12]
-;~~~~~~~~~~~~~~~~~~~~~
-    movq        mm1, mm0
-    movq        mm5, mm4
-    paddw       mm1, mm3          ;ip[0] + ip[12] aka al
-    paddw       mm5, mm2          ;ip[4] + ip[8] aka bl
-
-    movq        mm6, mm1          ;temp al
-    paddw       mm1, mm5          ;al + bl
-    psubw       mm6, mm5          ;al - bl
-    paddw       mm1, mm7
-    paddw       mm6, mm7
-    psraw       mm1, 3
-    psraw       mm6, 3
-
-    psubw       mm0, mm3          ;ip[0] - ip[12] aka d1
-    psubw       mm4, mm2          ;ip[4] - ip[8] aka c1
-
-    movq        mm5, mm0          ;temp dl
-    paddw       mm0, mm4          ;dl + cl
-    psubw       mm5, mm4          ;dl - cl
-    paddw       mm0, mm7
-    paddw       mm5, mm7
-    psraw       mm0, 3
-    psraw       mm5, 3
-;~~~~~~~~~~~~~~~~~~~~~
-
-    movd        eax, mm1
-    movd        ecx, mm0
-    psrlq       mm0, 32
-    psrlq       mm1, 32
-    mov         word ptr[rdx+32*0], ax
-    mov         word ptr[rdx+32*1], cx
-    shr         eax, 16
-    shr         ecx, 16
-    mov         word ptr[rdx+32*4], ax
-    mov         word ptr[rdx+32*5], cx
-    movd        eax, mm1
-    movd        ecx, mm0
-    mov         word ptr[rdx+32*8], ax
-    mov         word ptr[rdx+32*9], cx
-    shr         eax, 16
-    shr         ecx, 16
-    mov         word ptr[rdx+32*12], ax
-    mov         word ptr[rdx+32*13], cx
-
-    movd        eax, mm6
-    movd        ecx, mm5
-    psrlq       mm5, 32
-    psrlq       mm6, 32
-    mov         word ptr[rdx+32*2], ax
-    mov         word ptr[rdx+32*3], cx
-    shr         eax, 16
-    shr         ecx, 16
-    mov         word ptr[rdx+32*6], ax
-    mov         word ptr[rdx+32*7], cx
-    movd        eax, mm6
-    movd        ecx, mm5
-    mov         word ptr[rdx+32*10], ax
-    mov         word ptr[rdx+32*11], cx
-    shr         eax, 16
-    shr         ecx, 16
-    mov         word ptr[rdx+32*14], ax
-    mov         word ptr[rdx+32*15], cx
-
-    ; begin epilog
-    UNSHADOW_ARGS
-    pop         rbp
-    ret
-
diff --git a/vp8/common/x86/iwalsh_sse2.asm b/vp8/common/x86/iwalsh_sse2.asm
deleted file mode 100644 (file)
index 06e86a8..0000000
+++ /dev/null
@@ -1,121 +0,0 @@
-;
-;  Copyright (c) 2010 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.
-;
-
-
-%include "vpx_ports/x86_abi_support.asm"
-
-;void vp8_short_inv_walsh4x4_sse2(short *input, short *output)
-global sym(vp8_short_inv_walsh4x4_sse2) PRIVATE
-sym(vp8_short_inv_walsh4x4_sse2):
-    push        rbp
-    mov         rbp, rsp
-    SHADOW_ARGS_TO_STACK 2
-    ; end prolog
-
-    mov         rcx, arg(0)
-    mov         rdx, arg(1)
-    mov         rax, 30003h
-
-    movdqa      xmm0, [rcx + 0]     ;ip[4] ip[0]
-    movdqa      xmm1, [rcx + 16]    ;ip[12] ip[8]
-
-
-    pshufd      xmm2, xmm1, 4eh     ;ip[8] ip[12]
-    movdqa      xmm3, xmm0          ;ip[4] ip[0]
-
-    paddw       xmm0, xmm2          ;ip[4]+ip[8] ip[0]+ip[12] aka b1 a1
-    psubw       xmm3, xmm2          ;ip[4]-ip[8] ip[0]-ip[12] aka c1 d1
-
-    movdqa      xmm4, xmm0
-    punpcklqdq  xmm0, xmm3          ;d1 a1
-    punpckhqdq  xmm4, xmm3          ;c1 b1
-
-    movdqa      xmm1, xmm4          ;c1 b1
-    paddw       xmm4, xmm0          ;dl+cl a1+b1 aka op[4] op[0]
-    psubw       xmm0, xmm1          ;d1-c1 a1-b1 aka op[12] op[8]
-
-    ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-    ; 13 12 11 10 03 02 01 00
-    ;
-    ; 33 32 31 30 23 22 21 20
-    ;
-    movdqa      xmm3, xmm4          ; 13 12 11 10 03 02 01 00
-    punpcklwd   xmm4, xmm0          ; 23 03 22 02 21 01 20 00
-    punpckhwd   xmm3, xmm0          ; 33 13 32 12 31 11 30 10
-    movdqa      xmm1, xmm4          ; 23 03 22 02 21 01 20 00
-    punpcklwd   xmm4, xmm3          ; 31 21 11 01 30 20 10 00
-    punpckhwd   xmm1, xmm3          ; 33 23 13 03 32 22 12 02
-    ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-    movd        xmm0, eax
-    pshufd      xmm2, xmm1, 4eh     ;ip[8] ip[12]
-    movdqa      xmm3, xmm4          ;ip[4] ip[0]
-
-    pshufd      xmm0, xmm0, 0       ;03 03 03 03 03 03 03 03
-
-    paddw       xmm4, xmm2          ;ip[4]+ip[8] ip[0]+ip[12] aka b1 a1
-    psubw       xmm3, xmm2          ;ip[4]-ip[8] ip[0]-ip[12] aka c1 d1
-
-    movdqa      xmm5, xmm4
-    punpcklqdq  xmm4, xmm3          ;d1 a1
-    punpckhqdq  xmm5, xmm3          ;c1 b1
-
-    movdqa      xmm1, xmm5          ;c1 b1
-    paddw       xmm5, xmm4          ;dl+cl a1+b1 aka op[4] op[0]
-    psubw       xmm4, xmm1          ;d1-c1 a1-b1 aka op[12] op[8]
-
-    paddw       xmm5, xmm0
-    paddw       xmm4, xmm0
-    psraw       xmm5, 3
-    psraw       xmm4, 3
-
-    movd        eax, xmm5
-    movd        ecx, xmm4
-    psrldq      xmm5, 4
-    psrldq      xmm4, 4
-    mov         word ptr[rdx+32*0], ax
-    mov         word ptr[rdx+32*2], cx
-    shr         eax, 16
-    shr         ecx, 16
-    mov         word ptr[rdx+32*4], ax
-    mov         word ptr[rdx+32*6], cx
-    movd        eax, xmm5
-    movd        ecx, xmm4
-    psrldq      xmm5, 4
-    psrldq      xmm4, 4
-    mov         word ptr[rdx+32*8], ax
-    mov         word ptr[rdx+32*10], cx
-    shr         eax, 16
-    shr         ecx, 16
-    mov         word ptr[rdx+32*12], ax
-    mov         word ptr[rdx+32*14], cx
-
-    movd        eax, xmm5
-    movd        ecx, xmm4
-    psrldq      xmm5, 4
-    psrldq      xmm4, 4
-    mov         word ptr[rdx+32*1], ax
-    mov         word ptr[rdx+32*3], cx
-    shr         eax, 16
-    shr         ecx, 16
-    mov         word ptr[rdx+32*5], ax
-    mov         word ptr[rdx+32*7], cx
-    movd        eax, xmm5
-    movd        ecx, xmm4
-    mov         word ptr[rdx+32*9], ax
-    mov         word ptr[rdx+32*11], cx
-    shr         eax, 16
-    shr         ecx, 16
-    mov         word ptr[rdx+32*13], ax
-    mov         word ptr[rdx+32*15], cx
-
-    ; begin epilog
-    UNSHADOW_ARGS
-    pop         rbp
-    ret
diff --git a/vp8/common/x86/loopfilter_block_sse2_x86_64.asm b/vp8/common/x86/loopfilter_block_sse2_x86_64.asm
deleted file mode 100644 (file)
index 6d5aaa1..0000000
+++ /dev/null
@@ -1,815 +0,0 @@
-;
-;  Copyright (c) 2010 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.
-;
-
-
-%include "vpx_ports/x86_abi_support.asm"
-
-%macro LF_ABS 2
-        ; %1 value not preserved
-        ; %2 value preserved
-        ; output in %1
-        movdqa      scratch1, %2            ; v2
-
-        psubusb     scratch1, %1            ; v2 - v1
-        psubusb     %1, %2                  ; v1 - v2
-        por         %1, scratch1            ; abs(v2 - v1)
-%endmacro
-
-%macro LF_FILTER_HEV_MASK 8-9
-
-        LF_ABS      %1, %2                  ; abs(p3 - p2)
-        LF_ABS      %2, %3                  ; abs(p2 - p1)
-        pmaxub      %1, %2                  ; accumulate mask
-%if %0 == 8
-        movdqa      scratch2, %3            ; save p1
-        LF_ABS      scratch2, %4            ; abs(p1 - p0)
-%endif
-        LF_ABS      %4, %5                  ; abs(p0 - q0)
-        LF_ABS      %5, %6                  ; abs(q0 - q1)
-%if %0 == 8
-        pmaxub      %5, scratch2            ; accumulate hev
-%else
-        pmaxub      %5, %9
-%endif
-        pmaxub      %1, %5                  ; accumulate mask
-
-        LF_ABS      %3, %6                  ; abs(p1 - q1)
-        LF_ABS      %6, %7                  ; abs(q1 - q2)
-        pmaxub      %1, %6                  ; accumulate mask
-        LF_ABS      %7, %8                  ; abs(q2 - q3)
-        pmaxub      %1, %7                  ; accumulate mask
-
-        paddusb     %4, %4                  ; 2 * abs(p0 - q0)
-        pand        %3, [GLOBAL(tfe)]
-        psrlw       %3, 1                   ; abs(p1 - q1) / 2
-        paddusb     %4, %3                  ; abs(p0 - q0) * 2 + abs(p1 - q1) / 2
-
-        psubusb     %1, [limit]
-        psubusb     %4, [blimit]
-        por         %1, %4
-        pcmpeqb     %1, zero                ; mask
-
-        psubusb     %5, [thresh]
-        pcmpeqb     %5, zero                ; ~hev
-%endmacro
-
-%macro LF_FILTER 6
-        ; %1-%4: p1-q1
-        ; %5: mask
-        ; %6: hev
-
-        movdqa      scratch2, %6            ; save hev
-
-        pxor        %1, [GLOBAL(t80)]       ; ps1
-        pxor        %4, [GLOBAL(t80)]       ; qs1
-        movdqa      scratch1, %1
-        psubsb      scratch1, %4            ; signed_char_clamp(ps1 - qs1)
-        pandn       scratch2, scratch1      ; vp8_filter &= hev
-
-        pxor        %2, [GLOBAL(t80)]       ; ps0
-        pxor        %3, [GLOBAL(t80)]       ; qs0
-        movdqa      scratch1, %3
-        psubsb      scratch1, %2            ; qs0 - ps0
-        paddsb      scratch2, scratch1      ; vp8_filter += (qs0 - ps0)
-        paddsb      scratch2, scratch1      ; vp8_filter += (qs0 - ps0)
-        paddsb      scratch2, scratch1      ; vp8_filter += (qs0 - ps0)
-        pand        %5, scratch2            ; &= mask
-
-        movdqa      scratch2, %5
-        paddsb      %5, [GLOBAL(t4)]        ; Filter1
-        paddsb      scratch2, [GLOBAL(t3)]  ; Filter2
-
-        ; Filter1 >> 3
-        movdqa      scratch1, zero
-        pcmpgtb     scratch1, %5
-        psrlw       %5, 3
-        pand        scratch1, [GLOBAL(te0)]
-        pand        %5, [GLOBAL(t1f)]
-        por         %5, scratch1
-
-        psubsb      %3, %5                  ; qs0 - Filter1
-        pxor        %3, [GLOBAL(t80)]
-
-        ; Filter2 >> 3
-        movdqa      scratch1, zero
-        pcmpgtb     scratch1, scratch2
-        psrlw       scratch2, 3
-        pand        scratch1, [GLOBAL(te0)]
-        pand        scratch2, [GLOBAL(t1f)]
-        por         scratch2, scratch1
-
-        paddsb      %2, scratch2            ; ps0 + Filter2
-        pxor        %2, [GLOBAL(t80)]
-
-        ; outer tap adjustments
-        paddsb      %5, [GLOBAL(t1)]
-        movdqa      scratch1, zero
-        pcmpgtb     scratch1, %5
-        psrlw       %5, 1
-        pand        scratch1, [GLOBAL(t80)]
-        pand        %5, [GLOBAL(t7f)]
-        por         %5, scratch1
-        pand        %5, %6                  ; vp8_filter &= ~hev
-
-        psubsb      %4, %5                  ; qs1 - vp8_filter
-        pxor        %4, [GLOBAL(t80)]
-
-        paddsb      %1, %5                  ; ps1 + vp8_filter
-        pxor        %1, [GLOBAL(t80)]
-%endmacro
-
-;void vp8_loop_filter_bh_y_sse2
-;(
-;    unsigned char *src_ptr,
-;    int            src_pixel_step,
-;    const char    *blimit,
-;    const char    *limit,
-;    const char    *thresh
-;)
-global sym(vp8_loop_filter_bh_y_sse2) PRIVATE
-sym(vp8_loop_filter_bh_y_sse2):
-
-%if LIBVPX_YASM_WIN64
-    %define src      rcx ; src_ptr
-    %define stride   rdx ; src_pixel_step
-    %define blimit   r8
-    %define limit    r9
-    %define thresh   r10
-
-    %define spp      rax
-    %define stride3  r11
-    %define stride5  r12
-    %define stride7  r13
-
-    push    rbp
-    mov     rbp, rsp
-    SAVE_XMM 11
-    push    r12
-    push    r13
-    mov     thresh, arg(4)
-%else
-    %define src      rdi ; src_ptr
-    %define stride   rsi ; src_pixel_step
-    %define blimit   rdx
-    %define limit    rcx
-    %define thresh   r8
-
-    %define spp      rax
-    %define stride3  r9
-    %define stride5  r10
-    %define stride7  r11
-%endif
-
-    %define scratch1 xmm5
-    %define scratch2 xmm6
-    %define zero     xmm7
-
-    %define i0       [src]
-    %define i1       [spp]
-    %define i2       [src + 2 * stride]
-    %define i3       [spp + 2 * stride]
-    %define i4       [src + 4 * stride]
-    %define i5       [spp + 4 * stride]
-    %define i6       [src + 2 * stride3]
-    %define i7       [spp + 2 * stride3]
-    %define i8       [src + 8 * stride]
-    %define i9       [spp + 8 * stride]
-    %define i10      [src + 2 * stride5]
-    %define i11      [spp + 2 * stride5]
-    %define i12      [src + 4 * stride3]
-    %define i13      [spp + 4 * stride3]
-    %define i14      [src + 2 * stride7]
-    %define i15      [spp + 2 * stride7]
-
-    ; prep work
-    lea         spp, [src + stride]
-    lea         stride3, [stride + 2 * stride]
-    lea         stride5, [stride3 + 2 * stride]
-    lea         stride7, [stride3 + 4 * stride]
-    pxor        zero, zero
-
-        ; load the first set into registers
-        movdqa       xmm0, i0
-        movdqa       xmm1, i1
-        movdqa       xmm2, i2
-        movdqa       xmm3, i3
-        movdqa       xmm4, i4
-        movdqa       xmm8, i5
-        movdqa       xmm9, i6   ; q2, will contain abs(p1-p0)
-        movdqa       xmm10, i7
-LF_FILTER_HEV_MASK xmm0, xmm1, xmm2, xmm3, xmm4, xmm8, xmm9, xmm10
-
-        movdqa       xmm1, i2
-        movdqa       xmm2, i3
-        movdqa       xmm3, i4
-        movdqa       xmm8, i5
-LF_FILTER xmm1, xmm2, xmm3, xmm8, xmm0, xmm4
-        movdqa       i2, xmm1
-        movdqa       i3, xmm2
-
-; second set
-        movdqa       i4, xmm3
-        movdqa       i5, xmm8
-
-        movdqa       xmm0, i6
-        movdqa       xmm1, i7
-        movdqa       xmm2, i8
-        movdqa       xmm4, i9
-        movdqa       xmm10, i10   ; q2, will contain abs(p1-p0)
-        movdqa       xmm11, i11
-LF_FILTER_HEV_MASK xmm3, xmm8, xmm0, xmm1, xmm2, xmm4, xmm10, xmm11, xmm9
-
-        movdqa       xmm0, i6
-        movdqa       xmm1, i7
-        movdqa       xmm4, i8
-        movdqa       xmm8, i9
-LF_FILTER xmm0, xmm1, xmm4, xmm8, xmm3, xmm2
-        movdqa       i6, xmm0
-        movdqa       i7, xmm1
-
-; last set
-        movdqa       i8, xmm4
-        movdqa       i9, xmm8
-
-        movdqa       xmm0, i10
-        movdqa       xmm1, i11
-        movdqa       xmm2, i12
-        movdqa       xmm3, i13
-        movdqa       xmm9, i14   ; q2, will contain abs(p1-p0)
-        movdqa       xmm11, i15
-LF_FILTER_HEV_MASK xmm4, xmm8, xmm0, xmm1, xmm2, xmm3, xmm9, xmm11, xmm10
-
-        movdqa       xmm0, i10
-        movdqa       xmm1, i11
-        movdqa       xmm3, i12
-        movdqa       xmm8, i13
-LF_FILTER xmm0, xmm1, xmm3, xmm8, xmm4, xmm2
-        movdqa       i10, xmm0
-        movdqa       i11, xmm1
-        movdqa       i12, xmm3
-        movdqa       i13, xmm8
-
-%if LIBVPX_YASM_WIN64
-    pop    r13
-    pop    r12
-    RESTORE_XMM
-    pop    rbp
-%endif
-
-    ret
-
-
-;void vp8_loop_filter_bv_y_sse2
-;(
-;    unsigned char *src_ptr,
-;    int            src_pixel_step,
-;    const char    *blimit,
-;    const char    *limit,
-;    const char    *thresh
-;)
-
-global sym(vp8_loop_filter_bv_y_sse2) PRIVATE
-sym(vp8_loop_filter_bv_y_sse2):
-
-%if LIBVPX_YASM_WIN64
-    %define src      rcx ; src_ptr
-    %define stride   rdx ; src_pixel_step
-    %define blimit   r8
-    %define limit    r9
-    %define thresh   r10
-
-    %define spp      rax
-    %define stride3  r11
-    %define stride5  r12
-    %define stride7  r13
-
-    push    rbp
-    mov     rbp, rsp
-    SAVE_XMM 15
-    push    r12
-    push    r13
-    mov     thresh, arg(4)
-%else
-    %define src      rdi
-    %define stride   rsi
-    %define blimit   rdx
-    %define limit    rcx
-    %define thresh   r8
-
-    %define spp      rax
-    %define stride3  r9
-    %define stride5  r10
-    %define stride7  r11
-%endif
-
-    %define scratch1 xmm5
-    %define scratch2 xmm6
-    %define zero     xmm7
-
-    %define s0       [src]
-    %define s1       [spp]
-    %define s2       [src + 2 * stride]
-    %define s3       [spp + 2 * stride]
-    %define s4       [src + 4 * stride]
-    %define s5       [spp + 4 * stride]
-    %define s6       [src + 2 * stride3]
-    %define s7       [spp + 2 * stride3]
-    %define s8       [src + 8 * stride]
-    %define s9       [spp + 8 * stride]
-    %define s10      [src + 2 * stride5]
-    %define s11      [spp + 2 * stride5]
-    %define s12      [src + 4 * stride3]
-    %define s13      [spp + 4 * stride3]
-    %define s14      [src + 2 * stride7]
-    %define s15      [spp + 2 * stride7]
-
-    %define i0       [rsp]
-    %define i1       [rsp + 16]
-    %define i2       [rsp + 32]
-    %define i3       [rsp + 48]
-    %define i4       [rsp + 64]
-    %define i5       [rsp + 80]
-    %define i6       [rsp + 96]
-    %define i7       [rsp + 112]
-    %define i8       [rsp + 128]
-    %define i9       [rsp + 144]
-    %define i10      [rsp + 160]
-    %define i11      [rsp + 176]
-    %define i12      [rsp + 192]
-    %define i13      [rsp + 208]
-    %define i14      [rsp + 224]
-    %define i15      [rsp + 240]
-
-    ALIGN_STACK 16, rax
-
-    ; reserve stack space
-    %define      temp_storage  0 ; size is 256 (16*16)
-    %define      stack_size 256
-    sub          rsp, stack_size
-
-    ; prep work
-    lea         spp, [src + stride]
-    lea         stride3, [stride + 2 * stride]
-    lea         stride5, [stride3 + 2 * stride]
-    lea         stride7, [stride3 + 4 * stride]
-
-        ; 8-f
-        movdqa      xmm0, s8
-        movdqa      xmm1, xmm0
-        punpcklbw   xmm0, s9                ; 80 90
-        punpckhbw   xmm1, s9                ; 88 98
-
-        movdqa      xmm2, s10
-        movdqa      xmm3, xmm2
-        punpcklbw   xmm2, s11 ; a0 b0
-        punpckhbw   xmm3, s11 ; a8 b8
-
-        movdqa      xmm4, xmm0
-        punpcklwd   xmm0, xmm2              ; 80 90 a0 b0
-        punpckhwd   xmm4, xmm2              ; 84 94 a4 b4
-
-        movdqa      xmm2, xmm1
-        punpcklwd   xmm1, xmm3              ; 88 98 a8 b8
-        punpckhwd   xmm2, xmm3              ; 8c 9c ac bc
-
-        ; using xmm[0124]
-        ; work on next 4 rows
-
-        movdqa      xmm3, s12
-        movdqa      xmm5, xmm3
-        punpcklbw   xmm3, s13 ; c0 d0
-        punpckhbw   xmm5, s13 ; c8 d8
-
-        movdqa      xmm6, s14
-        movdqa      xmm7, xmm6
-        punpcklbw   xmm6, s15 ; e0 f0
-        punpckhbw   xmm7, s15 ; e8 f8
-
-        movdqa      xmm8, xmm3
-        punpcklwd   xmm3, xmm6              ; c0 d0 e0 f0
-        punpckhwd   xmm8, xmm6              ; c4 d4 e4 f4
-
-        movdqa      xmm6, xmm5
-        punpcklwd   xmm5, xmm7              ; c8 d8 e8 f8
-        punpckhwd   xmm6, xmm7              ; cc dc ec fc
-
-        ; pull the third and fourth sets together
-
-        movdqa      xmm7, xmm0
-        punpckldq   xmm0, xmm3              ; 80 90 a0 b0 c0 d0 e0 f0
-        punpckhdq   xmm7, xmm3              ; 82 92 a2 b2 c2 d2 e2 f2
-
-        movdqa      xmm3, xmm4
-        punpckldq   xmm4, xmm8              ; 84 94 a4 b4 c4 d4 e4 f4
-        punpckhdq   xmm3, xmm8              ; 86 96 a6 b6 c6 d6 e6 f6
-
-        movdqa      xmm8, xmm1
-        punpckldq   xmm1, xmm5              ; 88 88 a8 b8 c8 d8 e8 f8
-        punpckhdq   xmm8, xmm5              ; 8a 9a aa ba ca da ea fa
-
-        movdqa      xmm5, xmm2
-        punpckldq   xmm2, xmm6              ; 8c 9c ac bc cc dc ec fc
-        punpckhdq   xmm5, xmm6              ; 8e 9e ae be ce de ee fe
-
-        ; save the calculations. we only have 15 registers ...
-        movdqa      i0, xmm0
-        movdqa      i1, xmm7
-        movdqa      i2, xmm4
-        movdqa      i3, xmm3
-        movdqa      i4, xmm1
-        movdqa      i5, xmm8
-        movdqa      i6, xmm2
-        movdqa      i7, xmm5
-
-        ; 0-7
-        movdqa      xmm0, s0
-        movdqa      xmm1, xmm0
-        punpcklbw   xmm0, s1 ; 00 10
-        punpckhbw   xmm1, s1 ; 08 18
-
-        movdqa      xmm2, s2
-        movdqa      xmm3, xmm2
-        punpcklbw   xmm2, s3 ; 20 30
-        punpckhbw   xmm3, s3 ; 28 38
-
-        movdqa      xmm4, xmm0
-        punpcklwd   xmm0, xmm2              ; 00 10 20 30
-        punpckhwd   xmm4, xmm2              ; 04 14 24 34
-
-        movdqa      xmm2, xmm1
-        punpcklwd   xmm1, xmm3              ; 08 18 28 38
-        punpckhwd   xmm2, xmm3              ; 0c 1c 2c 3c
-
-        ; using xmm[0124]
-        ; work on next 4 rows
-
-        movdqa      xmm3, s4
-        movdqa      xmm5, xmm3
-        punpcklbw   xmm3, s5 ; 40 50
-        punpckhbw   xmm5, s5 ; 48 58
-
-        movdqa      xmm6, s6
-        movdqa      xmm7, xmm6
-        punpcklbw   xmm6, s7   ; 60 70
-        punpckhbw   xmm7, s7   ; 68 78
-
-        movdqa      xmm8, xmm3
-        punpcklwd   xmm3, xmm6              ; 40 50 60 70
-        punpckhwd   xmm8, xmm6              ; 44 54 64 74
-
-        movdqa      xmm6, xmm5
-        punpcklwd   xmm5, xmm7              ; 48 58 68 78
-        punpckhwd   xmm6, xmm7              ; 4c 5c 6c 7c
-
-        ; pull the first two sets together
-
-        movdqa      xmm7, xmm0
-        punpckldq   xmm0, xmm3              ; 00 10 20 30 40 50 60 70
-        punpckhdq   xmm7, xmm3              ; 02 12 22 32 42 52 62 72
-
-        movdqa      xmm3, xmm4
-        punpckldq   xmm4, xmm8              ; 04 14 24 34 44 54 64 74
-        punpckhdq   xmm3, xmm8              ; 06 16 26 36 46 56 66 76
-
-        movdqa      xmm8, xmm1
-        punpckldq   xmm1, xmm5              ; 08 18 28 38 48 58 68 78
-        punpckhdq   xmm8, xmm5              ; 0a 1a 2a 3a 4a 5a 6a 7a
-
-        movdqa      xmm5, xmm2
-        punpckldq   xmm2, xmm6              ; 0c 1c 2c 3c 4c 5c 6c 7c
-        punpckhdq   xmm5, xmm6              ; 0e 1e 2e 3e 4e 5e 6e 7e
-        ; final combination
-
-        movdqa      xmm6, xmm0
-        punpcklqdq  xmm0, i0
-        punpckhqdq  xmm6, i0
-
-        movdqa      xmm9, xmm7
-        punpcklqdq  xmm7, i1
-        punpckhqdq  xmm9, i1
-
-        movdqa      xmm10, xmm4
-        punpcklqdq  xmm4, i2
-        punpckhqdq  xmm10, i2
-
-        movdqa      xmm11, xmm3
-        punpcklqdq  xmm3, i3
-        punpckhqdq  xmm11, i3
-
-        movdqa      xmm12, xmm1
-        punpcklqdq  xmm1, i4
-        punpckhqdq  xmm12, i4
-
-        movdqa      xmm13, xmm8
-        punpcklqdq  xmm8, i5
-        punpckhqdq  xmm13, i5
-
-        movdqa      xmm14, xmm2
-        punpcklqdq  xmm2, i6
-        punpckhqdq  xmm14, i6
-
-        movdqa      xmm15, xmm5
-        punpcklqdq  xmm5, i7
-        punpckhqdq  xmm15, i7
-
-        movdqa      i0, xmm0
-        movdqa      i1, xmm6
-        movdqa      i2, xmm7
-        movdqa      i3, xmm9
-        movdqa      i4, xmm4
-        movdqa      i5, xmm10
-        movdqa      i6, xmm3
-        movdqa      i7, xmm11
-        movdqa      i8, xmm1
-        movdqa      i9, xmm12
-        movdqa      i10, xmm8
-        movdqa      i11, xmm13
-        movdqa      i12, xmm2
-        movdqa      i13, xmm14
-        movdqa      i14, xmm5
-        movdqa      i15, xmm15
-
-; TRANSPOSED DATA AVAILABLE ON THE STACK
-
-        movdqa      xmm12, xmm6
-        movdqa      xmm13, xmm7
-
-        pxor        zero, zero
-
-LF_FILTER_HEV_MASK xmm0, xmm12, xmm13, xmm9, xmm4, xmm10, xmm3, xmm11
-
-        movdqa       xmm1, i2
-        movdqa       xmm2, i3
-        movdqa       xmm8, i4
-        movdqa       xmm9, i5
-LF_FILTER xmm1, xmm2, xmm8, xmm9, xmm0, xmm4
-        movdqa       i2, xmm1
-        movdqa       i3, xmm2
-
-; second set
-        movdqa       i4, xmm8
-        movdqa       i5, xmm9
-
-        movdqa       xmm0, i6
-        movdqa       xmm1, i7
-        movdqa       xmm2, i8
-        movdqa       xmm4, i9
-        movdqa       xmm10, i10   ; q2, will contain abs(p1-p0)
-        movdqa       xmm11, i11
-LF_FILTER_HEV_MASK xmm8, xmm9, xmm0, xmm1, xmm2, xmm4, xmm10, xmm11, xmm3
-
-        movdqa       xmm0, i6
-        movdqa       xmm1, i7
-        movdqa       xmm3, i8
-        movdqa       xmm4, i9
-LF_FILTER xmm0, xmm1, xmm3, xmm4, xmm8, xmm2
-        movdqa       i6, xmm0
-        movdqa       i7, xmm1
-
-; last set
-        movdqa       i8, xmm3
-        movdqa       i9, xmm4
-
-        movdqa       xmm0, i10
-        movdqa       xmm1, i11
-        movdqa       xmm2, i12
-        movdqa       xmm8, i13
-        movdqa       xmm9, i14   ; q2, will contain abs(p1-p0)
-        movdqa       xmm11, i15
-LF_FILTER_HEV_MASK xmm3, xmm4, xmm0, xmm1, xmm2, xmm8, xmm9, xmm11, xmm10
-
-        movdqa       xmm0, i10
-        movdqa       xmm1, i11
-        movdqa       xmm4, i12
-        movdqa       xmm8, i13
-LF_FILTER xmm0, xmm1, xmm4, xmm8, xmm3, xmm2
-        movdqa       i10, xmm0
-        movdqa       i11, xmm1
-        movdqa       i12, xmm4
-        movdqa       i13, xmm8
-
-
-; RESHUFFLE AND WRITE OUT
-        ; 8-f
-        movdqa      xmm0, i8
-        movdqa      xmm1, xmm0
-        punpcklbw   xmm0, i9                ; 80 90
-        punpckhbw   xmm1, i9                ; 88 98
-
-        movdqa      xmm2, i10
-        movdqa      xmm3, xmm2
-        punpcklbw   xmm2, i11               ; a0 b0
-        punpckhbw   xmm3, i11               ; a8 b8
-
-        movdqa      xmm4, xmm0
-        punpcklwd   xmm0, xmm2              ; 80 90 a0 b0
-        punpckhwd   xmm4, xmm2              ; 84 94 a4 b4
-
-        movdqa      xmm2, xmm1
-        punpcklwd   xmm1, xmm3              ; 88 98 a8 b8
-        punpckhwd   xmm2, xmm3              ; 8c 9c ac bc
-
-        ; using xmm[0124]
-        ; work on next 4 rows
-
-        movdqa      xmm3, i12
-        movdqa      xmm5, xmm3
-        punpcklbw   xmm3, i13               ; c0 d0
-        punpckhbw   xmm5, i13               ; c8 d8
-
-        movdqa      xmm6, i14
-        movdqa      xmm7, xmm6
-        punpcklbw   xmm6, i15               ; e0 f0
-        punpckhbw   xmm7, i15               ; e8 f8
-
-        movdqa      xmm8, xmm3
-        punpcklwd   xmm3, xmm6              ; c0 d0 e0 f0
-        punpckhwd   xmm8, xmm6              ; c4 d4 e4 f4
-
-        movdqa      xmm6, xmm5
-        punpcklwd   xmm5, xmm7              ; c8 d8 e8 f8
-        punpckhwd   xmm6, xmm7              ; cc dc ec fc
-
-        ; pull the third and fourth sets together
-
-        movdqa      xmm7, xmm0
-        punpckldq   xmm0, xmm3              ; 80 90 a0 b0 c0 d0 e0 f0
-        punpckhdq   xmm7, xmm3              ; 82 92 a2 b2 c2 d2 e2 f2
-
-        movdqa      xmm3, xmm4
-        punpckldq   xmm4, xmm8              ; 84 94 a4 b4 c4 d4 e4 f4
-        punpckhdq   xmm3, xmm8              ; 86 96 a6 b6 c6 d6 e6 f6
-
-        movdqa      xmm8, xmm1
-        punpckldq   xmm1, xmm5              ; 88 88 a8 b8 c8 d8 e8 f8
-        punpckhdq   xmm8, xmm5              ; 8a 9a aa ba ca da ea fa
-
-        movdqa      xmm5, xmm2
-        punpckldq   xmm2, xmm6              ; 8c 9c ac bc cc dc ec fc
-        punpckhdq   xmm5, xmm6              ; 8e 9e ae be ce de ee fe
-
-        ; save the calculations. we only have 15 registers ...
-        movdqa      i8, xmm0
-        movdqa      i9, xmm7
-        movdqa      i10, xmm4
-        movdqa      i11, xmm3
-        movdqa      i12, xmm1
-        movdqa      i13, xmm8
-        movdqa      i14, xmm2
-        movdqa      i15, xmm5
-
-        ; 0-7
-        movdqa      xmm0, i0
-        movdqa      xmm1, xmm0
-        punpcklbw   xmm0, i1                ; 00 10
-        punpckhbw   xmm1, i1                ; 08 18
-
-        movdqa      xmm2, i2
-        movdqa      xmm3, xmm2
-        punpcklbw   xmm2, i3                ; 20 30
-        punpckhbw   xmm3, i3                ; 28 38
-
-        movdqa      xmm4, xmm0
-        punpcklwd   xmm0, xmm2              ; 00 10 20 30
-        punpckhwd   xmm4, xmm2              ; 04 14 24 34
-
-        movdqa      xmm2, xmm1
-        punpcklwd   xmm1, xmm3              ; 08 18 28 38
-        punpckhwd   xmm2, xmm3              ; 0c 1c 2c 3c
-
-        ; using xmm[0124]
-        ; work on next 4 rows
-
-        movdqa      xmm3, i4
-        movdqa      xmm5, xmm3
-        punpcklbw   xmm3, i5                ; 40 50
-        punpckhbw   xmm5, i5                ; 48 58
-
-        movdqa      xmm6, i6
-        movdqa      xmm7, xmm6
-        punpcklbw   xmm6, i7                ; 60 70
-        punpckhbw   xmm7, i7                ; 68 78
-
-        movdqa      xmm8, xmm3
-        punpcklwd   xmm3, xmm6              ; 40 50 60 70
-        punpckhwd   xmm8, xmm6              ; 44 54 64 74
-
-        movdqa      xmm6, xmm5
-        punpcklwd   xmm5, xmm7              ; 48 58 68 78
-        punpckhwd   xmm6, xmm7              ; 4c 5c 6c 7c
-
-        ; pull the first two sets together
-
-        movdqa      xmm7, xmm0
-        punpckldq   xmm0, xmm3              ; 00 10 20 30 40 50 60 70
-        punpckhdq   xmm7, xmm3              ; 02 12 22 32 42 52 62 72
-
-        movdqa      xmm3, xmm4
-        punpckldq   xmm4, xmm8              ; 04 14 24 34 44 54 64 74
-        punpckhdq   xmm3, xmm8              ; 06 16 26 36 46 56 66 76
-
-        movdqa      xmm8, xmm1
-        punpckldq   xmm1, xmm5              ; 08 18 28 38 48 58 68 78
-        punpckhdq   xmm8, xmm5              ; 0a 1a 2a 3a 4a 5a 6a 7a
-
-        movdqa      xmm5, xmm2
-        punpckldq   xmm2, xmm6              ; 0c 1c 2c 3c 4c 5c 6c 7c
-        punpckhdq   xmm5, xmm6              ; 0e 1e 2e 3e 4e 5e 6e 7e
-        ; final combination
-
-        movdqa      xmm6, xmm0
-        punpcklqdq  xmm0, i8
-        punpckhqdq  xmm6, i8
-
-        movdqa      xmm9, xmm7
-        punpcklqdq  xmm7, i9
-        punpckhqdq  xmm9, i9
-
-        movdqa      xmm10, xmm4
-        punpcklqdq  xmm4, i10
-        punpckhqdq  xmm10, i10
-
-        movdqa      xmm11, xmm3
-        punpcklqdq  xmm3, i11
-        punpckhqdq  xmm11, i11
-
-        movdqa      xmm12, xmm1
-        punpcklqdq  xmm1, i12
-        punpckhqdq  xmm12, i12
-
-        movdqa      xmm13, xmm8
-        punpcklqdq  xmm8, i13
-        punpckhqdq  xmm13, i13
-
-        movdqa      xmm14, xmm2
-        punpcklqdq  xmm2, i14
-        punpckhqdq  xmm14, i14
-
-        movdqa      xmm15, xmm5
-        punpcklqdq  xmm5, i15
-        punpckhqdq  xmm15, i15
-
-        movdqa      s0, xmm0
-        movdqa      s1, xmm6
-        movdqa      s2, xmm7
-        movdqa      s3, xmm9
-        movdqa      s4, xmm4
-        movdqa      s5, xmm10
-        movdqa      s6, xmm3
-        movdqa      s7, xmm11
-        movdqa      s8, xmm1
-        movdqa      s9, xmm12
-        movdqa      s10, xmm8
-        movdqa      s11, xmm13
-        movdqa      s12, xmm2
-        movdqa      s13, xmm14
-        movdqa      s14, xmm5
-        movdqa      s15, xmm15
-
-    ; free stack space
-    add          rsp, stack_size
-
-    ; un-ALIGN_STACK
-    pop          rsp
-
-%if LIBVPX_YASM_WIN64
-    pop    r13
-    pop    r12
-    RESTORE_XMM
-    pop    rbp
-%endif
-
-    ret
-
-SECTION_RODATA
-align 16
-te0:
-    times 16 db 0xe0
-align 16
-t7f:
-    times 16 db 0x7f
-align 16
-tfe:
-    times 16 db 0xfe
-align 16
-t1f:
-    times 16 db 0x1f
-align 16
-t80:
-    times 16 db 0x80
-align 16
-t1:
-    times 16 db 0x01
-align 16
-t3:
-    times 16 db 0x03
-align 16
-t4:
-    times 16 db 0x04
diff --git a/vp8/common/x86/loopfilter_sse2.asm b/vp8/common/x86/loopfilter_sse2.asm
deleted file mode 100644 (file)
index 1913abc..0000000
+++ /dev/null
@@ -1,1640 +0,0 @@
-;
-;  Copyright (c) 2010 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.
-;
-
-
-%include "vpx_ports/x86_abi_support.asm"
-%define _t0 0
-%define _t1 _t0 + 16
-%define _p3 _t1 + 16
-%define _p2 _p3 + 16
-%define _p1 _p2 + 16
-%define _p0 _p1 + 16
-%define _q0 _p0 + 16
-%define _q1 _q0 + 16
-%define _q2 _q1 + 16
-%define _q3 _q2 + 16
-%define lf_var_size 160
-
-; Use of pmaxub instead of psubusb to compute filter mask was seen
-; in ffvp8
-
-%macro LFH_FILTER_AND_HEV_MASK 1
-%if %1
-        movdqa      xmm2,                   [rdi+2*rax]       ; q3
-        movdqa      xmm1,                   [rsi+2*rax]       ; q2
-        movdqa      xmm4,                   [rsi+rax]         ; q1
-        movdqa      xmm5,                   [rsi]             ; q0
-        neg         rax                     ; negate pitch to deal with above border
-%else
-        movlps      xmm2,                   [rsi + rcx*2]     ; q3
-        movlps      xmm1,                   [rsi + rcx]       ; q2
-        movlps      xmm4,                   [rsi]             ; q1
-        movlps      xmm5,                   [rsi + rax]       ; q0
-
-        movhps      xmm2,                   [rdi + rcx*2]
-        movhps      xmm1,                   [rdi + rcx]
-        movhps      xmm4,                   [rdi]
-        movhps      xmm5,                   [rdi + rax]
-
-        lea         rsi,                    [rsi + rax*4]
-        lea         rdi,                    [rdi + rax*4]
-
-        movdqa      [rsp+_q2],              xmm1              ; store q2
-        movdqa      [rsp+_q1],              xmm4              ; store q1
-%endif
-        movdqa      xmm7,                   [rdx]             ;limit
-
-        movdqa      xmm6,                   xmm1              ; q2
-        movdqa      xmm3,                   xmm4              ; q1
-
-        psubusb     xmm1,                   xmm2              ; q2-=q3
-        psubusb     xmm2,                   xmm6              ; q3-=q2
-
-        psubusb     xmm4,                   xmm6              ; q1-=q2
-        psubusb     xmm6,                   xmm3              ; q2-=q1
-
-        por         xmm4,                   xmm6              ; abs(q2-q1)
-        por         xmm1,                   xmm2              ; abs(q3-q2)
-
-        movdqa      xmm0,                   xmm5              ; q0
-        pmaxub      xmm1,                   xmm4
-
-        psubusb     xmm5,                   xmm3              ; q0-=q1
-        psubusb     xmm3,                   xmm0              ; q1-=q0
-
-        por         xmm5,                   xmm3              ; abs(q0-q1)
-        movdqa      [rsp+_t0],              xmm5              ; save to t0
-
-        pmaxub      xmm1,                   xmm5
-
-%if %1
-        movdqa      xmm2,                   [rsi+4*rax]       ; p3
-        movdqa      xmm4,                   [rdi+4*rax]       ; p2
-        movdqa      xmm6,                   [rsi+2*rax]       ; p1
-%else
-        movlps      xmm2,                   [rsi + rax]       ; p3
-        movlps      xmm4,                   [rsi]             ; p2
-        movlps      xmm6,                   [rsi + rcx]       ; p1
-
-        movhps      xmm2,                   [rdi + rax]
-        movhps      xmm4,                   [rdi]
-        movhps      xmm6,                   [rdi + rcx]
-
-        movdqa      [rsp+_p2],              xmm4              ; store p2
-        movdqa      [rsp+_p1],              xmm6              ; store p1
-%endif
-
-        movdqa      xmm5,                   xmm4              ; p2
-        movdqa      xmm3,                   xmm6              ; p1
-
-        psubusb     xmm4,                   xmm2              ; p2-=p3
-        psubusb     xmm2,                   xmm5              ; p3-=p2
-
-        psubusb     xmm3,                   xmm5              ; p1-=p2
-        pmaxub      xmm1,                   xmm4              ; abs(p3 - p2)
-
-        psubusb     xmm5,                   xmm6              ; p2-=p1
-        pmaxub      xmm1,                   xmm2              ; abs(p3 - p2)
-
-        pmaxub      xmm1,                   xmm5              ; abs(p2 - p1)
-        movdqa      xmm2,                   xmm6              ; p1
-
-        pmaxub      xmm1,                   xmm3              ; abs(p2 - p1)
-%if %1
-        movdqa      xmm4,                   [rsi+rax]         ; p0
-        movdqa      xmm3,                   [rdi]             ; q1
-%else
-        movlps      xmm4,                   [rsi + rcx*2]     ; p0
-        movhps      xmm4,                   [rdi + rcx*2]
-        movdqa      xmm3,                   [rsp+_q1]                ; q1
-%endif
-
-        movdqa      xmm5,                   xmm4              ; p0
-        psubusb     xmm4,                   xmm6              ; p0-=p1
-
-        psubusb     xmm6,                   xmm5              ; p1-=p0
-
-        por         xmm6,                   xmm4              ; abs(p1 - p0)
-        mov         rdx,                    arg(2)            ; get blimit
-
-        movdqa     [rsp+_t1],               xmm6              ; save to t1
-
-        movdqa      xmm4,                   xmm3              ; q1
-        pmaxub      xmm1,                   xmm6
-
-        psubusb     xmm3,                   xmm2              ; q1-=p1
-        psubusb     xmm2,                   xmm4              ; p1-=q1
-
-        psubusb     xmm1,                   xmm7
-        por         xmm2,                   xmm3              ; abs(p1-q1)
-
-        movdqa      xmm7,                   [rdx]             ; blimit
-        mov         rdx,                    arg(4)            ; hev get thresh
-
-        movdqa      xmm3,                   xmm0              ; q0
-        pand        xmm2,                   [GLOBAL(tfe)]     ; set lsb of each byte to zero
-
-        movdqa      xmm6,                   xmm5              ; p0
-        psrlw       xmm2,                   1                 ; abs(p1-q1)/2
-
-        psubusb     xmm5,                   xmm3              ; p0-=q0
-        psubusb     xmm3,                   xmm6              ; q0-=p0
-        por         xmm5,                   xmm3              ; abs(p0 - q0)
-
-        paddusb     xmm5,                   xmm5              ; abs(p0-q0)*2
-
-        movdqa      xmm4,                   [rsp+_t0]                ; hev get abs (q1 - q0)
-        movdqa      xmm3,                   [rsp+_t1]                ; get abs (p1 - p0)
-
-        paddusb     xmm5,                   xmm2              ; abs (p0 - q0) *2 + abs(p1-q1)/2
-
-        movdqa      xmm2,                   [rdx]             ; hev
-
-        psubusb     xmm5,                   xmm7              ; abs (p0 - q0) *2 + abs(p1-q1)/2  > blimit
-        psubusb     xmm4,                   xmm2              ; hev
-
-        psubusb     xmm3,                   xmm2              ; hev
-        por         xmm1,                   xmm5
-
-        pxor        xmm7,                   xmm7
-        paddb       xmm4,                   xmm3              ; hev abs(q1 - q0) > thresh || abs(p1 - p0) > thresh
-
-        pcmpeqb     xmm4,                   xmm5              ; hev
-        pcmpeqb     xmm3,                   xmm3              ; hev
-
-        pcmpeqb     xmm1,                   xmm7              ; mask xmm1
-        pxor        xmm4,                   xmm3              ; hev
-%endmacro
-
-%macro B_FILTER 1
-        movdqa      xmm3,                   [GLOBAL(t80)]
-%if %1 == 0
-        movdqa      xmm2,                   [rsp+_p1]                ; p1
-        movdqa      xmm7,                   [rsp+_q1]                ; q1
-%elif %1 == 1
-        movdqa      xmm2,                   [rsi+2*rax]       ; p1
-        movdqa      xmm7,                   [rdi]             ; q1
-%elif %1 == 2
-        movdqa      xmm2,                   [rsp+_p1]         ; p1
-        movdqa      xmm6,                   [rsp+_p0]         ; p0
-        movdqa      xmm0,                   [rsp+_q0]         ; q0
-        movdqa      xmm7,                   [rsp+_q1]         ; q1
-%endif
-
-        pxor        xmm2,                   xmm3              ; p1 offset to convert to signed values
-        pxor        xmm7,                   xmm3              ; q1 offset to convert to signed values
-
-        psubsb      xmm2,                   xmm7              ; p1 - q1
-        pxor        xmm6,                   xmm3              ; offset to convert to signed values
-
-        pand        xmm2,                   xmm4              ; high var mask (hvm)(p1 - q1)
-        pxor        xmm0,                   xmm3              ; offset to convert to signed values
-
-        movdqa      xmm3,                   xmm0              ; q0
-        psubsb      xmm0,                   xmm6              ; q0 - p0
-        paddsb      xmm2,                   xmm0              ; 1 * (q0 - p0) + hvm(p1 - q1)
-        paddsb      xmm2,                   xmm0              ; 2 * (q0 - p0) + hvm(p1 - q1)
-        paddsb      xmm2,                   xmm0              ; 3 * (q0 - p0) + hvm(p1 - q1)
-        pand        xmm1,                   xmm2              ; mask filter values we don't care about
-
-        movdqa      xmm2,                   xmm1
-        paddsb      xmm1,                   [GLOBAL(t4)]      ; 3* (q0 - p0) + hvm(p1 - q1) + 4
-        paddsb      xmm2,                   [GLOBAL(t3)]      ; 3* (q0 - p0) + hvm(p1 - q1) + 3
-
-        punpckhbw   xmm5,                   xmm2              ; axbxcxdx
-        punpcklbw   xmm2,                   xmm2              ; exfxgxhx
-
-        punpcklbw   xmm0,                   xmm1              ; exfxgxhx
-        psraw       xmm5,                   11                ; sign extended shift right by 3
-
-        punpckhbw   xmm1,                   xmm1              ; axbxcxdx
-        psraw       xmm2,                   11                ; sign extended shift right by 3
-
-        packsswb    xmm2,                   xmm5              ; (3* (q0 - p0) + hvm(p1 - q1) + 3) >> 3;
-        psraw       xmm0,                   11                ; sign extended shift right by 3
-
-        psraw       xmm1,                   11                ; sign extended shift right by 3
-        movdqa      xmm5,                   xmm0              ; save results
-
-        packsswb    xmm0,                   xmm1              ; (3* (q0 - p0) + hvm(p1 - q1) + 4) >>3
-
-        paddsb      xmm6,                   xmm2              ; p0+= p0 add
-
-        movdqa      xmm2,                   [GLOBAL(ones)]
-        paddsw      xmm5,                   xmm2
-        paddsw      xmm1,                   xmm2
-        psraw       xmm5,                   1                 ; partial shifted one more time for 2nd tap
-        psraw       xmm1,                   1                 ; partial shifted one more time for 2nd tap
-        packsswb    xmm5,                   xmm1              ; (3* (q0 - p0) + hvm(p1 - q1) + 4) >>4
-        movdqa      xmm2,                   [GLOBAL(t80)]
-
-%if %1 == 0
-        movdqa      xmm1,                   [rsp+_p1]         ; p1
-        lea         rsi,                    [rsi + rcx*2]
-        lea         rdi,                    [rdi + rcx*2]
-%elif %1 == 1
-        movdqa      xmm1,                   [rsi+2*rax]       ; p1
-%elif %1 == 2
-        movdqa      xmm1,                   [rsp+_p1]         ; p1
-%endif
-
-        pandn       xmm4,                   xmm5              ; high edge variance additive
-        pxor        xmm6,                   xmm2              ; unoffset
-
-        pxor        xmm1,                   xmm2              ; reoffset
-        psubsb      xmm3,                   xmm0              ; q0-= q0 add
-
-        paddsb      xmm1,                   xmm4              ; p1+= p1 add
-        pxor        xmm3,                   xmm2              ; unoffset
-
-        pxor        xmm1,                   xmm2              ; unoffset
-        psubsb      xmm7,                   xmm4              ; q1-= q1 add
-
-        pxor        xmm7,                   xmm2              ; unoffset
-%if %1 == 0
-        movq        [rsi],                  xmm6              ; p0
-        movhps      [rdi],                  xmm6
-        movq        [rsi + rax],            xmm1              ; p1
-        movhps      [rdi + rax],            xmm1
-        movq        [rsi + rcx],            xmm3              ; q0
-        movhps      [rdi + rcx],            xmm3
-        movq        [rsi + rcx*2],          xmm7              ; q1
-        movhps      [rdi + rcx*2],          xmm7
-%elif %1 == 1
-        movdqa      [rsi+rax],              xmm6              ; write back
-        movdqa      [rsi+2*rax],            xmm1              ; write back
-        movdqa      [rsi],                  xmm3              ; write back
-        movdqa      [rdi],                  xmm7              ; write back
-%endif
-
-%endmacro
-
-%if ABI_IS_32BIT
-
-;void vp8_loop_filter_horizontal_edge_sse2
-;(
-;    unsigned char *src_ptr,
-;    int            src_pixel_step,
-;    const char    *blimit,
-;    const char    *limit,
-;    const char    *thresh,
-;)
-global sym(vp8_loop_filter_horizontal_edge_sse2) PRIVATE
-sym(vp8_loop_filter_horizontal_edge_sse2):
-    push        rbp
-    mov         rbp, rsp
-    SHADOW_ARGS_TO_STACK 5
-    SAVE_XMM 7
-    GET_GOT     rbx
-    push        rsi
-    push        rdi
-    ; end prolog
-
-    ALIGN_STACK 16, rax
-    sub         rsp, lf_var_size
-
-        mov         rsi,                    arg(0)           ;src_ptr
-        movsxd      rax,                    dword ptr arg(1) ;src_pixel_step
-
-        mov         rdx,                    arg(3)           ;limit
-
-        lea         rdi,                    [rsi+rax]        ; rdi points to row +1 for indirect addressing
-
-        ; calculate breakout conditions and high edge variance
-        LFH_FILTER_AND_HEV_MASK 1
-        ; filter and write back the result
-        B_FILTER 1
-
-    add rsp, lf_var_size
-    pop rsp
-    ; begin epilog
-    pop rdi
-    pop rsi
-    RESTORE_GOT
-    RESTORE_XMM
-    UNSHADOW_ARGS
-    pop         rbp
-    ret
-
-%endif
-
-;void vp8_loop_filter_horizontal_edge_uv_sse2
-;(
-;    unsigned char *src_ptr,
-;    int            src_pixel_step,
-;    const char    *blimit,
-;    const char    *limit,
-;    const char    *thresh,
-;    int            count
-;)
-global sym(vp8_loop_filter_horizontal_edge_uv_sse2) PRIVATE
-sym(vp8_loop_filter_horizontal_edge_uv_sse2):
-    push        rbp
-    mov         rbp, rsp
-    SHADOW_ARGS_TO_STACK 6
-    SAVE_XMM 7
-    GET_GOT     rbx
-    push        rsi
-    push        rdi
-    ; end prolog
-
-    ALIGN_STACK 16, rax
-    sub         rsp, lf_var_size
-
-        mov         rsi,                    arg(0)             ; u
-        mov         rdi,                    arg(5)             ; v
-        movsxd      rax,                    dword ptr arg(1)   ; src_pixel_step
-        mov         rcx,                    rax
-        neg         rax                     ; negate pitch to deal with above border
-
-        mov         rdx,                    arg(3)             ;limit
-
-        lea         rsi,                    [rsi + rcx]
-        lea         rdi,                    [rdi + rcx]
-
-        ; calculate breakout conditions and high edge variance
-        LFH_FILTER_AND_HEV_MASK 0
-        ; filter and write back the result
-        B_FILTER 0
-
-    add rsp, lf_var_size
-    pop rsp
-    ; begin epilog
-    pop rdi
-    pop rsi
-    RESTORE_GOT
-    RESTORE_XMM
-    UNSHADOW_ARGS
-    pop         rbp
-    ret
-
-
-%macro MB_FILTER_AND_WRITEBACK 1
-        movdqa      xmm3,                   [GLOBAL(t80)]
-%if %1 == 0
-        movdqa      xmm2,                   [rsp+_p1]              ; p1
-        movdqa      xmm7,                   [rsp+_q1]              ; q1
-%elif %1 == 1
-        movdqa      xmm2,                   [rsi+2*rax]     ; p1
-        movdqa      xmm7,                   [rdi]           ; q1
-
-        mov         rcx,                    rax
-        neg         rcx
-%elif %1 == 2
-        movdqa      xmm2,                   [rsp+_p1]       ; p1
-        movdqa      xmm6,                   [rsp+_p0]       ; p0
-        movdqa      xmm0,                   [rsp+_q0]       ; q0
-        movdqa      xmm7,                   [rsp+_q1]       ; q1
-%endif
-
-        pxor        xmm2,                   xmm3            ; p1 offset to convert to signed values
-        pxor        xmm7,                   xmm3            ; q1 offset to convert to signed values
-        pxor        xmm6,                   xmm3            ; offset to convert to signed values
-        pxor        xmm0,                   xmm3            ; offset to convert to signed values
-
-        psubsb      xmm2,                   xmm7            ; p1 - q1
-
-        movdqa      xmm3,                   xmm0            ; q0
-        psubsb      xmm0,                   xmm6            ; q0 - p0
-        paddsb      xmm2,                   xmm0            ; 1 * (q0 - p0) + (p1 - q1)
-        paddsb      xmm2,                   xmm0            ; 2 * (q0 - p0)
-        paddsb      xmm2,                   xmm0            ; 3 * (q0 - p0) + (p1 - q1)
-        pand        xmm1,                   xmm2            ; mask filter values we don't care about
-
-        movdqa      xmm2,                   xmm1            ; vp8_filter
-
-        pand        xmm2,                   xmm4            ; Filter2 = vp8_filter & hev
-        pxor        xmm0,                   xmm0
-
-        pandn       xmm4,                   xmm1            ; vp8_filter&=~hev
-        pxor        xmm1,                   xmm1
-
-        punpcklbw   xmm0,                   xmm4            ; Filter 2 (hi)
-        punpckhbw   xmm1,                   xmm4            ; Filter 2 (lo)
-
-        movdqa      xmm5,                   xmm2
-
-        movdqa      xmm4,                   [GLOBAL(s9)]
-        paddsb      xmm5,                   [GLOBAL(t3)]    ; vp8_signed_char_clamp(Filter2 + 3)
-        paddsb      xmm2,                   [GLOBAL(t4)]    ; vp8_signed_char_clamp(Filter2 + 4)
-
-        pmulhw      xmm1,                   xmm4            ; Filter 2 (lo) * 9
-        pmulhw      xmm0,                   xmm4            ; Filter 2 (hi) * 9
-
-        punpckhbw   xmm7,                   xmm5            ; axbxcxdx
-        punpcklbw   xmm5,                   xmm5            ; exfxgxhx
-
-        psraw       xmm7,                   11              ; sign extended shift right by 3
-
-        psraw       xmm5,                   11              ; sign extended shift right by 3
-        punpckhbw   xmm4,                   xmm2            ; axbxcxdx
-
-        punpcklbw   xmm2,                   xmm2            ; exfxgxhx
-        psraw       xmm4,                   11              ; sign extended shift right by 3
-
-        packsswb    xmm5,                   xmm7            ; Filter2 >>=3;
-        psraw       xmm2,                   11              ; sign extended shift right by 3
-
-        packsswb    xmm2,                   xmm4            ; Filter1 >>=3;
-
-        paddsb      xmm6,                   xmm5            ; ps0 =ps0 + Fitler2
-
-        psubsb      xmm3,                   xmm2            ; qs0 =qs0 - Filter1
-        movdqa      xmm7,                   xmm1
-
-        movdqa      xmm4,                   [GLOBAL(s63)]
-        movdqa      xmm5,                   xmm0
-        movdqa      xmm2,                   xmm5
-        paddw       xmm0,                   xmm4            ; Filter 2 (hi) * 9 + 63
-        paddw       xmm1,                   xmm4            ; Filter 2 (lo) * 9 + 63
-        movdqa      xmm4,                   xmm7
-
-        paddw       xmm5,                   xmm5            ; Filter 2 (hi) * 18
-
-        paddw       xmm7,                   xmm7            ; Filter 2 (lo) * 18
-        paddw       xmm5,                   xmm0            ; Filter 2 (hi) * 27 + 63
-
-        paddw       xmm7,                   xmm1            ; Filter 2 (lo) * 27 + 63
-        paddw       xmm2,                   xmm0            ; Filter 2 (hi) * 18 + 63
-        psraw       xmm0,                   7               ; (Filter 2 (hi) * 9 + 63) >> 7
-
-        paddw       xmm4,                   xmm1            ; Filter 2 (lo) * 18 + 63
-        psraw       xmm1,                   7               ; (Filter 2 (lo) * 9 + 63) >> 7
-        psraw       xmm2,                   7               ; (Filter 2 (hi) * 18 + 63) >> 7
-
-        packsswb    xmm0,                   xmm1            ; u1 = vp8_signed_char_clamp((63 + Filter2 * 9)>>7)
-
-        psraw       xmm4,                   7               ; (Filter 2 (lo) * 18 + 63) >> 7
-        psraw       xmm5,                   7               ; (Filter 2 (hi) * 27 + 63) >> 7
-        psraw       xmm7,                   7               ; (Filter 2 (lo) * 27 + 63) >> 7
-
-        packsswb    xmm5,                   xmm7            ; u3 = vp8_signed_char_clamp((63 + Filter2 * 27)>>7)
-        packsswb    xmm2,                   xmm4            ; u2 = vp8_signed_char_clamp((63 + Filter2 * 18)>>7)
-        movdqa      xmm7,                   [GLOBAL(t80)]
-
-%if %1 == 0
-        movdqa      xmm1,                   [rsp+_q1]       ; q1
-        movdqa      xmm4,                   [rsp+_p1]       ; p1
-        lea         rsi,                    [rsi+rcx*2]
-        lea         rdi,                    [rdi+rcx*2]
-
-%elif %1 == 1
-        movdqa      xmm1,                   [rdi]           ; q1
-        movdqa      xmm4,                   [rsi+rax*2]     ; p1
-%elif %1 == 2
-        movdqa      xmm4,                   [rsp+_p1]       ; p1
-        movdqa      xmm1,                   [rsp+_q1]       ; q1
-%endif
-
-        pxor        xmm1,                   xmm7
-        pxor        xmm4,                   xmm7
-
-        psubsb      xmm3,                   xmm5            ; sq = vp8_signed_char_clamp(qs0 - u3)
-        paddsb      xmm6,                   xmm5            ; sp = vp8_signed_char_clamp(ps0 - u3)
-        psubsb      xmm1,                   xmm2            ; sq = vp8_signed_char_clamp(qs1 - u2)
-        paddsb      xmm4,                   xmm2            ; sp = vp8_signed_char_clamp(ps1 - u2)
-
-%if %1 == 1
-        movdqa      xmm2,                   [rdi+rax*4]     ; p2
-        movdqa      xmm5,                   [rdi+rcx]       ; q2
-%else
-        movdqa      xmm2,                   [rsp+_p2]       ; p2
-        movdqa      xmm5,                   [rsp+_q2]       ; q2
-%endif
-
-        pxor        xmm1,                   xmm7            ; *oq1 = sq^0x80;
-        pxor        xmm4,                   xmm7            ; *op1 = sp^0x80;
-        pxor        xmm2,                   xmm7
-        pxor        xmm5,                   xmm7
-        paddsb      xmm2,                   xmm0            ; sp = vp8_signed_char_clamp(ps2 - u)
-        psubsb      xmm5,                   xmm0            ; sq = vp8_signed_char_clamp(qs2 - u)
-        pxor        xmm2,                   xmm7            ; *op2 = sp^0x80;
-        pxor        xmm5,                   xmm7            ; *oq2 = sq^0x80;
-        pxor        xmm3,                   xmm7            ; *oq0 = sq^0x80
-        pxor        xmm6,                   xmm7            ; *oq0 = sp^0x80
-%if %1 == 0
-        movq        [rsi],                  xmm6            ; p0
-        movhps      [rdi],                  xmm6
-        movq        [rsi + rcx],            xmm3            ; q0
-        movhps      [rdi + rcx],            xmm3
-        lea         rdx,                    [rcx + rcx*2]
-        movq        [rsi+rcx*2],            xmm1            ; q1
-        movhps      [rdi+rcx*2],            xmm1
-
-        movq        [rsi + rax],            xmm4            ; p1
-        movhps      [rdi + rax],            xmm4
-
-        movq        [rsi+rax*2],            xmm2            ; p2
-        movhps      [rdi+rax*2],            xmm2
-
-        movq        [rsi+rdx],              xmm5            ; q2
-        movhps      [rdi+rdx],              xmm5
-%elif %1 == 1
-        movdqa      [rdi+rcx],              xmm5            ; q2
-        movdqa      [rdi],                  xmm1            ; q1
-        movdqa      [rsi],                  xmm3            ; q0
-        movdqa      [rsi+rax  ],            xmm6            ; p0
-        movdqa      [rsi+rax*2],            xmm4            ; p1
-        movdqa      [rdi+rax*4],            xmm2            ; p2
-%elif %1 == 2
-        movdqa      [rsp+_p1],              xmm4            ; p1
-        movdqa      [rsp+_p0],              xmm6            ; p0
-        movdqa      [rsp+_q0],              xmm3            ; q0
-        movdqa      [rsp+_q1],              xmm1            ; q1
-%endif
-
-%endmacro
-
-
-;void vp8_mbloop_filter_horizontal_edge_sse2
-;(
-;    unsigned char *src_ptr,
-;    int            src_pixel_step,
-;    const char    *blimit,
-;    const char    *limit,
-;    const char    *thresh,
-;)
-global sym(vp8_mbloop_filter_horizontal_edge_sse2) PRIVATE
-sym(vp8_mbloop_filter_horizontal_edge_sse2):
-    push        rbp
-    mov         rbp, rsp
-    SHADOW_ARGS_TO_STACK 5
-    SAVE_XMM 7
-    GET_GOT     rbx
-    push        rsi
-    push        rdi
-    ; end prolog
-
-    ALIGN_STACK 16, rax
-    sub         rsp, lf_var_size
-
-        mov         rsi,                    arg(0)            ;src_ptr
-        movsxd      rax,                    dword ptr arg(1)  ;src_pixel_step
-        mov         rdx,                    arg(3)            ;limit
-
-        lea         rdi,                    [rsi+rax]         ; rdi points to row +1 for indirect addressing
-
-        ; calculate breakout conditions and high edge variance
-        LFH_FILTER_AND_HEV_MASK 1
-        ; filter and write back the results
-        MB_FILTER_AND_WRITEBACK 1
-
-    add rsp, lf_var_size
-    pop rsp
-    ; begin epilog
-    pop rdi
-    pop rsi
-    RESTORE_GOT
-    RESTORE_XMM
-    UNSHADOW_ARGS
-    pop         rbp
-    ret
-
-
-;void vp8_mbloop_filter_horizontal_edge_uv_sse2
-;(
-;    unsigned char *u,
-;    int            src_pixel_step,
-;    const char    *blimit,
-;    const char    *limit,
-;    const char    *thresh,
-;    unsigned char *v
-;)
-global sym(vp8_mbloop_filter_horizontal_edge_uv_sse2) PRIVATE
-sym(vp8_mbloop_filter_horizontal_edge_uv_sse2):
-    push        rbp
-    mov         rbp, rsp
-    SHADOW_ARGS_TO_STACK 6
-    SAVE_XMM 7
-    GET_GOT     rbx
-    push        rsi
-    push        rdi
-    ; end prolog
-
-    ALIGN_STACK 16, rax
-    sub         rsp, lf_var_size
-
-        mov         rsi,                    arg(0)             ; u
-        mov         rdi,                    arg(5)             ; v
-        movsxd      rax,                    dword ptr arg(1)   ; src_pixel_step
-        mov         rcx,                    rax
-        neg         rax                     ; negate pitch to deal with above border
-        mov         rdx,                    arg(3)             ;limit
-
-        lea         rsi,                    [rsi + rcx]
-        lea         rdi,                    [rdi + rcx]
-
-        ; calculate breakout conditions and high edge variance
-        LFH_FILTER_AND_HEV_MASK 0
-        ; filter and write back the results
-        MB_FILTER_AND_WRITEBACK 0
-
-    add rsp, lf_var_size
-    pop rsp
-    ; begin epilog
-    pop rdi
-    pop rsi
-    RESTORE_GOT
-    RESTORE_XMM
-    UNSHADOW_ARGS
-    pop         rbp
-    ret
-
-
-%macro TRANSPOSE_16X8 2
-        movq        xmm4,               [rsi]           ; xx xx xx xx xx xx xx xx 07 06 05 04 03 02 01 00
-        movq        xmm1,               [rdi]           ; xx xx xx xx xx xx xx xx 17 16 15 14 13 12 11 10
-        movq        xmm0,               [rsi+2*rax]     ; xx xx xx xx xx xx xx xx 27 26 25 24 23 22 21 20
-        movq        xmm7,               [rdi+2*rax]     ; xx xx xx xx xx xx xx xx 37 36 35 34 33 32 31 30
-        movq        xmm5,               [rsi+4*rax]     ; xx xx xx xx xx xx xx xx 47 46 45 44 43 42 41 40
-        movq        xmm2,               [rdi+4*rax]     ; xx xx xx xx xx xx xx xx 57 56 55 54 53 52 51 50
-
-        punpcklbw   xmm4,               xmm1            ; 17 07 16 06 15 05 14 04 13 03 12 02 11 01 10 00
-
-        movq        xmm1,               [rdi+2*rcx]     ; xx xx xx xx xx xx xx xx 77 76 75 74 73 72 71 70
-
-        movdqa      xmm3,               xmm4            ; 17 07 16 06 15 05 14 04 13 03 12 02 11 01 10 00
-        punpcklbw   xmm0,               xmm7            ; 37 27 36 36 35 25 34 24 33 23 32 22 31 21 30 20
-
-        movq        xmm7,               [rsi+2*rcx]     ; xx xx xx xx xx xx xx xx 67 66 65 64 63 62 61 60
-
-        punpcklbw   xmm5,               xmm2            ; 57 47 56 46 55 45 54 44 53 43 52 42 51 41 50 40
-%if %1
-        lea         rsi,                [rsi+rax*8]
-        lea         rdi,                [rdi+rax*8]
-%else
-        mov         rsi,                arg(5)          ; v_ptr
-%endif
-
-        movdqa      xmm6,               xmm5            ; 57 47 56 46 55 45 54 44 53 43 52 42 51 41 50 40
-        punpcklbw   xmm7,               xmm1            ; 77 67 76 66 75 65 74 64 73 63 72 62 71 61 70 60
-        punpcklwd   xmm5,               xmm7            ; 73 63 53 43 72 62 52 42 71 61 51 41 70 60 50 40
-        punpckhwd   xmm6,               xmm7            ; 77 67 57 47 76 66 56 46 75 65 55 45 74 64 54 44
-        punpcklwd   xmm3,               xmm0            ; 33 23 13 03 32 22 12 02 31 21 11 01 30 20 10 00
-
-%if %1 == 0
-        lea         rdi,                [rsi + rax - 4] ; rdi points to row +1 for indirect addressing
-        lea         rsi,                [rsi - 4]
-%endif
-
-        movdqa      xmm2,               xmm3            ; 33 23 13 03 32 22 12 02 31 21 11 01 30 20 10 00
-        punpckhwd   xmm4,               xmm0            ; 37 27 17 07 36 26 16 06 35 25 15 05 34 24 14 04
-
-        movdqa      xmm7,               xmm4            ; 37 27 17 07 36 26 16 06 35 25 15 05 34 24 14 04
-        punpckhdq   xmm3,               xmm5            ; 73 63 53 43 33 23 13 03 72 62 52 42 32 22 12 02
-
-        punpckhdq   xmm7,               xmm6            ; 77 67 57 47 37 27 17 07 76 66 56 46 36 26 16 06
-
-        punpckldq   xmm4,               xmm6            ; 75 65 55 45 35 25 15 05 74 64 54 44 34 24 14 04
-
-        punpckldq   xmm2,               xmm5            ; 71 61 51 41 31 21 11 01 70 60 50 40 30 20 10 00
-
-        movdqa      [rsp+_t0],          xmm2            ; save to free XMM2
-
-        movq        xmm2,               [rsi]           ; xx xx xx xx xx xx xx xx 87 86 85 84 83 82 81 80
-        movq        xmm6,               [rdi]           ; xx xx xx xx xx xx xx xx 97 96 95 94 93 92 91 90
-        movq        xmm0,               [rsi+2*rax]     ; xx xx xx xx xx xx xx xx a7 a6 a5 a4 a3 a2 a1 a0
-        movq        xmm5,               [rdi+2*rax]     ; xx xx xx xx xx xx xx xx b7 b6 b5 b4 b3 b2 b1 b0
-        movq        xmm1,               [rsi+4*rax]     ; xx xx xx xx xx xx xx xx c7 c6 c5 c4 c3 c2 c1 c0
-
-        punpcklbw   xmm2,               xmm6            ; 97 87 96 86 95 85 94 84 93 83 92 82 91 81 90 80
-
-        movq        xmm6,               [rdi+4*rax]     ; xx xx xx xx xx xx xx xx d7 d6 d5 d4 d3 d2 d1 d0
-
-        punpcklbw   xmm0,               xmm5            ; b7 a7 b6 a6 b5 a5 b4 a4 b3 a3 b2 a2 b1 a1 b0 a0
-
-        movq        xmm5,               [rsi+2*rcx]     ; xx xx xx xx xx xx xx xx e7 e6 e5 e4 e3 e2 e1 e0
-
-        punpcklbw   xmm1,               xmm6            ; d7 c7 d6 c6 d5 c5 d4 c4 d3 c3 d2 c2 d1 e1 d0 c0
-
-        movq        xmm6,               [rdi+2*rcx]     ; xx xx xx xx xx xx xx xx f7 f6 f5 f4 f3 f2 f1 f0
-
-        punpcklbw   xmm5,               xmm6            ; f7 e7 f6 e6 f5 e5 f4 e4 f3 e3 f2 e2 f1 e1 f0 e0
-
-        movdqa      xmm6,               xmm1            ;
-        punpckhwd   xmm6,               xmm5            ; f7 e7 d7 c7 f6 e6 d6 c6 f5 e5 d5 c5 f4 e4 d4 c4
-
-        punpcklwd   xmm1,               xmm5            ; f3 e3 d3 c3 f2 e2 d2 c2 f1 e1 d1 c1 f0 e0 d0 c0
-        movdqa      xmm5,               xmm2            ; 97 87 96 86 95 85 94 84 93 83 92 82 91 81 90 80
-
-        punpcklwd   xmm5,               xmm0            ; b3 a3 93 83 b2 a2 92 82 b1 a1 91 81 b0 a0 90 80
-
-        punpckhwd   xmm2,               xmm0            ; b7 a7 97 87 b6 a6 96 86 b5 a5 95 85 b4 a4 94 84
-
-        movdqa      xmm0,               xmm5
-        punpckldq   xmm0,               xmm1            ; f1 e1 d1 c1 b1 a1 91 81 f0 e0 d0 c0 b0 a0 90 80
-
-        punpckhdq   xmm5,               xmm1            ; f3 e3 d3 c3 b3 a3 93 83 f2 e2 d2 c2 b2 a2 92 82
-        movdqa      xmm1,               xmm2            ; b7 a7 97 87 b6 a6 96 86 b5 a5 95 85 b4 a4 94 84
-
-        punpckldq   xmm1,               xmm6            ; f5 e5 d5 c5 b5 a5 95 85 f4 e4 d4 c4 b4 a4 94 84
-
-        punpckhdq   xmm2,               xmm6            ; f7 e7 d7 c7 b7 a7 97 87 f6 e6 d6 c6 b6 a6 96 86
-        movdqa      xmm6,               xmm7            ; 77 67 57 47 37 27 17 07 76 66 56 46 36 26 16 06
-
-        punpcklqdq  xmm6,               xmm2            ; f6 e6 d6 c6 b6 a6 96 86 76 66 56 46 36 26 16 06
-
-        punpckhqdq  xmm7,               xmm2            ; f7 e7 d7 c7 b7 a7 97 87 77 67 57 47 37 27 17 07
-
-%if %2 == 0
-        movdqa      [rsp+_q3],          xmm7            ; save 7
-        movdqa      [rsp+_q2],          xmm6            ; save 6
-%endif
-        movdqa      xmm2,               xmm3            ; 73 63 53 43 33 23 13 03 72 62 52 42 32 22 12 02
-        punpckhqdq  xmm3,               xmm5            ; f3 e3 d3 c3 b3 a3 93 83 73 63 53 43 33 23 13 03
-        punpcklqdq  xmm2,               xmm5            ; f2 e2 d2 c2 b2 a2 92 82 72 62 52 42 32 22 12 02
-        movdqa      [rsp+_p1],          xmm2            ; save 2
-
-        movdqa      xmm5,               xmm4            ; 75 65 55 45 35 25 15 05 74 64 54 44 34 24 14 04
-        punpcklqdq  xmm4,               xmm1            ; f4 e4 d4 c4 b4 a4 94 84 74 64 54 44 34 24 14 04
-        movdqa      [rsp+_p0],          xmm3            ; save 3
-
-        punpckhqdq  xmm5,               xmm1            ; f5 e5 d5 c5 b5 a5 95 85 75 65 55 45 35 25 15 05
-
-        movdqa      [rsp+_q0],          xmm4            ; save 4
-        movdqa      [rsp+_q1],          xmm5            ; save 5
-        movdqa      xmm1,               [rsp+_t0]
-
-        movdqa      xmm2,               xmm1            ;
-        punpckhqdq  xmm1,               xmm0            ; f1 e1 d1 c1 b1 a1 91 81 71 61 51 41 31 21 11 01
-        punpcklqdq  xmm2,               xmm0            ; f0 e0 d0 c0 b0 a0 90 80 70 60 50 40 30 20 10 00
-
-%if %2 == 0
-        movdqa      [rsp+_p2],          xmm1
-        movdqa      [rsp+_p3],          xmm2
-%endif
-
-%endmacro
-
-%macro LFV_FILTER_MASK_HEV_MASK 0
-        movdqa      xmm0,               xmm6            ; q2
-        psubusb     xmm0,               xmm7            ; q2-q3
-
-        psubusb     xmm7,               xmm6            ; q3-q2
-        movdqa      xmm4,               xmm5            ; q1
-
-        por         xmm7,               xmm0            ; abs (q3-q2)
-        psubusb     xmm4,               xmm6            ; q1-q2
-
-        movdqa      xmm0,               xmm1
-        psubusb     xmm6,               xmm5            ; q2-q1
-
-        por         xmm6,               xmm4            ; abs (q2-q1)
-        psubusb     xmm0,               xmm2            ; p2 - p3;
-
-        psubusb     xmm2,               xmm1            ; p3 - p2;
-        por         xmm0,               xmm2            ; abs(p2-p3)
-
-        movdqa      xmm5,               [rsp+_p1]       ; p1
-        pmaxub      xmm0,               xmm7
-
-        movdqa      xmm2,               xmm5            ; p1
-        psubusb     xmm5,               xmm1            ; p1-p2
-        psubusb     xmm1,               xmm2            ; p2-p1
-
-        movdqa      xmm7,               xmm3            ; p0
-        psubusb     xmm7,               xmm2            ; p0-p1
-
-        por         xmm1,               xmm5            ; abs(p2-p1)
-        pmaxub      xmm0,               xmm6
-
-        pmaxub      xmm0,               xmm1
-        movdqa      xmm1,               xmm2            ; p1
-
-        psubusb     xmm2,               xmm3            ; p1-p0
-
-        por         xmm2,               xmm7            ; abs(p1-p0)
-
-        pmaxub      xmm0,               xmm2
-
-        movdqa      xmm5,               [rsp+_q0]       ; q0
-        movdqa      xmm7,               [rsp+_q1]       ; q1
-
-        mov         rdx,                arg(3)          ; limit
-
-        movdqa      xmm6,               xmm5            ; q0
-        movdqa      xmm4,               xmm7            ; q1
-
-        psubusb     xmm5,               xmm7            ; q0-q1
-        psubusb     xmm7,               xmm6            ; q1-q0
-
-        por         xmm7,               xmm5            ; abs(q1-q0)
-
-        pmaxub      xmm0,               xmm7
-
-        psubusb     xmm0,               [rdx]           ; limit
-
-        mov         rdx,                arg(2)          ; blimit
-        movdqa      xmm5,               xmm4            ; q1
-
-        psubusb     xmm5,               xmm1            ; q1-=p1
-        psubusb     xmm1,               xmm4            ; p1-=q1
-
-        por         xmm5,               xmm1            ; abs(p1-q1)
-        movdqa      xmm1,               xmm3            ; p0
-
-        pand        xmm5,               [GLOBAL(tfe)]   ; set lsb of each byte to zero
-        psubusb     xmm1,               xmm6            ; p0-q0
-
-        movdqa      xmm4,               [rdx]           ; blimit
-        mov         rdx,                arg(4)          ; get thresh
-
-        psrlw       xmm5,               1               ; abs(p1-q1)/2
-        psubusb     xmm6,               xmm3            ; q0-p0
-
-        por         xmm1,               xmm6            ; abs(q0-p0)
-        paddusb     xmm1,               xmm1            ; abs(q0-p0)*2
-        movdqa      xmm3,               [rdx]
-
-        paddusb     xmm1,               xmm5            ; abs (p0 - q0) *2 + abs(p1-q1)/2
-        psubusb     xmm2,               xmm3            ; abs(q1 - q0) > thresh
-
-        psubusb     xmm7,               xmm3            ; abs(p1 - p0)> thresh
-
-        psubusb     xmm1,               xmm4            ; abs (p0 - q0) *2 + abs(p1-q1)/2  > blimit
-        por         xmm2,               xmm7            ; abs(q1 - q0) > thresh || abs(p1 - p0) > thresh
-
-        por         xmm1,               xmm0            ; mask
-        pcmpeqb     xmm2,               xmm0
-
-        pxor        xmm0,               xmm0
-        pcmpeqb     xmm4,               xmm4
-
-        pcmpeqb     xmm1,               xmm0
-        pxor        xmm4,               xmm2
-%endmacro
-
-%macro BV_TRANSPOSE 0
-        ; xmm1 =    f2 e2 d2 c2 b2 a2 92 82 72 62 52 42 32 22 12 02
-        ; xmm6 =    f3 e3 d3 c3 b3 a3 93 83 73 63 53 43 33 23 13 03
-        ; xmm3 =    f4 e4 d4 c4 b4 a4 94 84 74 64 54 44 34 24 14 04
-        ; xmm7 =    f5 e5 d5 c5 b5 a5 95 85 75 65 55 45 35 25 15 05
-        movdqa      xmm2,               xmm1            ; f2 e2 d2 c2 b2 a2 92 82 72 62 52 42 32 22 12 02
-        punpcklbw   xmm2,               xmm6            ; 73 72 63 62 53 52 43 42 33 32 23 22 13 12 03 02
-
-        movdqa      xmm4,               xmm3            ; f4 e4 d4 c4 b4 a4 94 84 74 64 54 44 34 24 14 04
-        punpckhbw   xmm1,               xmm6            ; f3 f2 e3 e2 d3 d2 c3 c2 b3 b2 a3 a2 93 92 83 82
-
-        punpcklbw   xmm4,               xmm7            ; 75 74 65 64 55 54 45 44 35 34 25 24 15 14 05 04
-
-        punpckhbw   xmm3,               xmm7            ; f5 f4 e5 e4 d5 d4 c5 c4 b5 b4 a5 a4 95 94 85 84
-
-        movdqa      xmm6,               xmm2            ; 73 72 63 62 53 52 43 42 33 32 23 22 13 12 03 02
-        punpcklwd   xmm2,               xmm4            ; 35 34 33 32 25 24 23 22 15 14 13 12 05 04 03 02
-
-        punpckhwd   xmm6,               xmm4            ; 75 74 73 72 65 64 63 62 55 54 53 52 45 44 43 42
-        movdqa      xmm5,               xmm1            ; f3 f2 e3 e2 d3 d2 c3 c2 b3 b2 a3 a2 93 92 83 82
-
-        punpcklwd   xmm1,               xmm3            ; b5 b4 b3 b2 a5 a4 a3 a2 95 94 93 92 85 84 83 82
-
-        punpckhwd   xmm5,               xmm3            ; f5 f4 f3 f2 e5 e4 e3 e2 d5 d4 d3 d2 c5 c4 c3 c2
-        ; xmm2 = 35 34 33 32 25 24 23 22 15 14 13 12 05 04 03 02
-        ; xmm6 = 75 74 73 72 65 64 63 62 55 54 53 52 45 44 43 42
-        ; xmm1 = b5 b4 b3 b2 a5 a4 a3 a2 95 94 93 92 85 84 83 82
-        ; xmm5 = f5 f4 f3 f2 e5 e4 e3 e2 d5 d4 d3 d2 c5 c4 c3 c2
-%endmacro
-
-%macro BV_WRITEBACK 2
-        movd        [rsi+2],            %1
-        movd        [rsi+4*rax+2],      %2
-        psrldq      %1,                 4
-        psrldq      %2,                 4
-        movd        [rdi+2],            %1
-        movd        [rdi+4*rax+2],      %2
-        psrldq      %1,                 4
-        psrldq      %2,                 4
-        movd        [rsi+2*rax+2],      %1
-        movd        [rsi+2*rcx+2],      %2
-        psrldq      %1,                 4
-        psrldq      %2,                 4
-        movd        [rdi+2*rax+2],      %1
-        movd        [rdi+2*rcx+2],      %2
-%endmacro
-
-%if ABI_IS_32BIT
-
-;void vp8_loop_filter_vertical_edge_sse2
-;(
-;    unsigned char *src_ptr,
-;    int            src_pixel_step,
-;    const char    *blimit,
-;    const char    *limit,
-;    const char    *thresh,
-;)
-global sym(vp8_loop_filter_vertical_edge_sse2) PRIVATE
-sym(vp8_loop_filter_vertical_edge_sse2):
-    push        rbp
-    mov         rbp, rsp
-    SHADOW_ARGS_TO_STACK 5
-    SAVE_XMM 7
-    GET_GOT     rbx
-    push        rsi
-    push        rdi
-    ; end prolog
-
-    ALIGN_STACK 16, rax
-    sub             rsp, lf_var_size
-
-        mov         rsi,        arg(0)                  ; src_ptr
-        movsxd      rax,        dword ptr arg(1)        ; src_pixel_step
-
-        lea         rsi,        [rsi - 4]
-        lea         rdi,        [rsi + rax]             ; rdi points to row +1 for indirect addressing
-        lea         rcx,        [rax*2+rax]
-
-        ;transpose 16x8 to 8x16, and store the 8-line result on stack.
-        TRANSPOSE_16X8 1, 1
-
-        ; calculate filter mask and high edge variance
-        LFV_FILTER_MASK_HEV_MASK
-
-        ; start work on filters
-        B_FILTER 2
-
-        ; transpose and write back - only work on q1, q0, p0, p1
-        BV_TRANSPOSE
-        ; store 16-line result
-
-        lea         rdx,        [rax]
-        neg         rdx
-
-        BV_WRITEBACK xmm1, xmm5
-
-        lea         rsi,        [rsi+rdx*8]
-        lea         rdi,        [rdi+rdx*8]
-        BV_WRITEBACK xmm2, xmm6
-
-    add rsp, lf_var_size
-    pop rsp
-    ; begin epilog
-    pop rdi
-    pop rsi
-    RESTORE_GOT
-    RESTORE_XMM
-    UNSHADOW_ARGS
-    pop         rbp
-    ret
-
-%endif
-
-;void vp8_loop_filter_vertical_edge_uv_sse2
-;(
-;    unsigned char *u,
-;    int            src_pixel_step,
-;    const char    *blimit,
-;    const char    *limit,
-;    const char    *thresh,
-;    unsigned char *v
-;)
-global sym(vp8_loop_filter_vertical_edge_uv_sse2) PRIVATE
-sym(vp8_loop_filter_vertical_edge_uv_sse2):
-    push        rbp
-    mov         rbp, rsp
-    SHADOW_ARGS_TO_STACK 6
-    SAVE_XMM 7
-    GET_GOT     rbx
-    push        rsi
-    push        rdi
-    ; end prolog
-
-    ALIGN_STACK 16, rax
-    sub             rsp, lf_var_size
-
-        mov         rsi,        arg(0)                  ; u_ptr
-        movsxd      rax,        dword ptr arg(1)        ; src_pixel_step
-
-        lea         rsi,        [rsi - 4]
-        lea         rdi,        [rsi + rax]             ; rdi points to row +1 for indirect addressing
-        lea         rcx,        [rax+2*rax]
-
-        ;transpose 16x8 to 8x16, and store the 8-line result on stack.
-        TRANSPOSE_16X8 0, 1
-
-        ; calculate filter mask and high edge variance
-        LFV_FILTER_MASK_HEV_MASK
-
-        ; start work on filters
-        B_FILTER 2
-
-        ; transpose and write back - only work on q1, q0, p0, p1
-        BV_TRANSPOSE
-
-        lea         rdi,        [rsi + rax]             ; rdi points to row +1 for indirect addressing
-
-        ; store 16-line result
-        BV_WRITEBACK xmm1, xmm5
-
-        mov         rsi,        arg(0)                  ; u_ptr
-        lea         rsi,        [rsi - 4]
-        lea         rdi,        [rsi + rax]             ; rdi points to row +1 for indirect addressing
-        BV_WRITEBACK xmm2, xmm6
-
-    add rsp, lf_var_size
-    pop rsp
-    ; begin epilog
-    pop rdi
-    pop rsi
-    RESTORE_GOT
-    RESTORE_XMM
-    UNSHADOW_ARGS
-    pop         rbp
-    ret
-
-%macro MBV_TRANSPOSE 0
-        movdqa      xmm0,               [rsp+_p3]           ; f0 e0 d0 c0 b0 a0 90 80 70 60 50 40 30 20 10 00
-        movdqa      xmm1,               xmm0                ; f0 e0 d0 c0 b0 a0 90 80 70 60 50 40 30 20 10 00
-
-        punpcklbw   xmm0,               xmm2                ; 71 70 61 60 51 50 41 40 31 30 21 20 11 10 01 00
-        punpckhbw   xmm1,               xmm2                ; f1 f0 e1 e0 d1 d0 c1 c0 b1 b0 a1 a0 91 90 81 80
-
-        movdqa      xmm7,               [rsp+_p1]           ; f2 e2 d2 c2 b2 a2 92 82 72 62 52 42 32 22 12 02
-        movdqa      xmm6,               xmm7                ; f2 e2 d2 c2 b2 a2 92 82 72 62 52 42 32 22 12 02
-
-        punpcklbw   xmm7,               [rsp+_p0]           ; 73 72 63 62 53 52 43 42 33 32 23 22 13 12 03 02
-        punpckhbw   xmm6,               [rsp+_p0]           ; f3 f2 e3 e2 d3 d2 c3 c2 b3 b2 a3 a2 93 92 83 82
-
-        movdqa      xmm3,               xmm0                ; 71 70 61 60 51 50 41 40 31 30 21 20 11 10 01 00
-        punpcklwd   xmm0,               xmm7                ; 33 32 31 30 23 22 21 20 13 12 11 10 03 02 01 00
-
-        punpckhwd   xmm3,               xmm7                ; 73 72 71 70 63 62 61 60 53 52 51 50 43 42 41 40
-        movdqa      xmm4,               xmm1                ; f1 f0 e1 e0 d1 d0 c1 c0 b1 b0 a1 a0 91 90 81 80
-
-        punpcklwd   xmm1,               xmm6                ; b3 b2 b1 b0 a3 a2 a1 a0 93 92 91 90 83 82 81 80
-        punpckhwd   xmm4,               xmm6                ; f3 f2 f1 f0 e3 e2 e1 e0 d3 d2 d1 d0 c3 c2 c1 c0
-
-        movdqa      xmm7,               [rsp+_q0]           ; f4 e4 d4 c4 b4 a4 94 84 74 64 54 44 34 24 14 04
-        punpcklbw   xmm7,               [rsp+_q1]           ; 75 74 65 64 55 54 45 44 35 34 25 24 15 14 05 04
-
-        movdqa      xmm6,               xmm5                ; f6 e6 d6 c6 b6 a6 96 86 76 66 56 46 36 26 16 06
-        punpcklbw   xmm6,               [rsp+_q3]           ; 77 76 67 66 57 56 47 46 37 36 27 26 17 16 07 06
-
-        movdqa      xmm2,               xmm7                ; 75 74 65 64 55 54 45 44 35 34 25 24 15 14 05 04
-        punpcklwd   xmm7,               xmm6                ; 37 36 35 34 27 26 25 24 17 16 15 14 07 06 05 04
-
-        punpckhwd   xmm2,               xmm6                ; 77 76 75 74 67 66 65 64 57 56 55 54 47 46 45 44
-        movdqa      xmm6,               xmm0                ; 33 32 31 30 23 22 21 20 13 12 11 10 03 02 01 00
-
-        punpckldq   xmm0,               xmm7                ; 17 16 15 14 13 12 11 10 07 06 05 04 03 02 01 00
-        punpckhdq   xmm6,               xmm7                ; 37 36 35 34 33 32 31 30 27 26 25 24 23 22 21 20
-%endmacro
-
-%macro MBV_WRITEBACK_1 0
-        movq        [rsi],              xmm0
-        movhps      [rdi],              xmm0
-
-        movq        [rsi+2*rax],        xmm6
-        movhps      [rdi+2*rax],        xmm6
-
-        movdqa      xmm0,               xmm3                ; 73 72 71 70 63 62 61 60 53 52 51 50 43 42 41 40
-        punpckldq   xmm0,               xmm2                ; 57 56 55 54 53 52 51 50 47 46 45 44 43 42 41 40
-        punpckhdq   xmm3,               xmm2                ; 77 76 75 74 73 72 71 70 67 66 65 64 63 62 61 60
-
-        movq        [rsi+4*rax],        xmm0
-        movhps      [rdi+4*rax],        xmm0
-
-        movq        [rsi+2*rcx],        xmm3
-        movhps      [rdi+2*rcx],        xmm3
-
-        movdqa      xmm7,               [rsp+_q0]           ; f4 e4 d4 c4 b4 a4 94 84 74 64 54 44 34 24 14 04
-        punpckhbw   xmm7,               [rsp+_q1]           ; f5 f4 e5 e4 d5 d4 c5 c4 b5 b4 a5 a4 95 94 85 84
-        punpckhbw   xmm5,               [rsp+_q3]           ; f7 f6 e7 e6 d7 d6 c7 c6 b7 b6 a7 a6 97 96 87 86
-
-        movdqa      xmm0,               xmm7
-        punpcklwd   xmm0,               xmm5                ; b7 b6 b4 b4 a7 a6 a5 a4 97 96 95 94 87 86 85 84
-        punpckhwd   xmm7,               xmm5                ; f7 f6 f5 f4 e7 e6 e5 e4 d7 d6 d5 d4 c7 c6 c5 c4
-
-        movdqa      xmm5,               xmm1                ; b3 b2 b1 b0 a3 a2 a1 a0 93 92 91 90 83 82 81 80
-        punpckldq   xmm1,               xmm0                ; 97 96 95 94 93 92 91 90 87 86 85 83 84 82 81 80
-        punpckhdq   xmm5,               xmm0                ; b7 b6 b5 b4 b3 b2 b1 b0 a7 a6 a5 a4 a3 a2 a1 a0
-%endmacro
-
-%macro MBV_WRITEBACK_2 0
-        movq        [rsi],              xmm1
-        movhps      [rdi],              xmm1
-
-        movq        [rsi+2*rax],        xmm5
-        movhps      [rdi+2*rax],        xmm5
-
-        movdqa      xmm1,               xmm4                ; f3 f2 f1 f0 e3 e2 e1 e0 d3 d2 d1 d0 c3 c2 c1 c0
-        punpckldq   xmm1,               xmm7                ; d7 d6 d5 d4 d3 d2 d1 d0 c7 c6 c5 c4 c3 c2 c1 c0
-        punpckhdq   xmm4,               xmm7                ; f7 f6 f4 f4 f3 f2 f1 f0 e7 e6 e5 e4 e3 e2 e1 e0
-
-        movq        [rsi+4*rax],        xmm1
-        movhps      [rdi+4*rax],        xmm1
-
-        movq        [rsi+2*rcx],        xmm4
-        movhps      [rdi+2*rcx],        xmm4
-%endmacro
-
-
-;void vp8_mbloop_filter_vertical_edge_sse2
-;(
-;    unsigned char *src_ptr,
-;    int            src_pixel_step,
-;    const char    *blimit,
-;    const char    *limit,
-;    const char    *thresh,
-;)
-global sym(vp8_mbloop_filter_vertical_edge_sse2) PRIVATE
-sym(vp8_mbloop_filter_vertical_edge_sse2):
-    push        rbp
-    mov         rbp, rsp
-    SHADOW_ARGS_TO_STACK 5
-    SAVE_XMM 7
-    GET_GOT     rbx
-    push        rsi
-    push        rdi
-    ; end prolog
-
-    ALIGN_STACK 16, rax
-    sub          rsp, lf_var_size
-
-        mov         rsi,                arg(0)              ; src_ptr
-        movsxd      rax,                dword ptr arg(1)    ; src_pixel_step
-
-        lea         rsi,                [rsi - 4]
-        lea         rdi,                [rsi + rax]         ; rdi points to row +1 for indirect addressing
-        lea         rcx,                [rax*2+rax]
-
-        ; Transpose
-        TRANSPOSE_16X8 1, 0
-
-        ; calculate filter mask and high edge variance
-        LFV_FILTER_MASK_HEV_MASK
-
-        neg         rax
-        ; start work on filters
-        MB_FILTER_AND_WRITEBACK 2
-
-        lea         rsi,                [rsi+rax*8]
-        lea         rdi,                [rdi+rax*8]
-
-        ; transpose and write back
-        MBV_TRANSPOSE
-
-        neg         rax
-
-        MBV_WRITEBACK_1
-
-
-        lea         rsi,                [rsi+rax*8]
-        lea         rdi,                [rdi+rax*8]
-        MBV_WRITEBACK_2
-
-    add rsp, lf_var_size
-    pop rsp
-    ; begin epilog
-    pop rdi
-    pop rsi
-    RESTORE_GOT
-    RESTORE_XMM
-    UNSHADOW_ARGS
-    pop         rbp
-    ret
-
-
-;void vp8_mbloop_filter_vertical_edge_uv_sse2
-;(
-;    unsigned char *u,
-;    int            src_pixel_step,
-;    const char    *blimit,
-;    const char    *limit,
-;    const char    *thresh,
-;    unsigned char *v
-;)
-global sym(vp8_mbloop_filter_vertical_edge_uv_sse2) PRIVATE
-sym(vp8_mbloop_filter_vertical_edge_uv_sse2):
-    push        rbp
-    mov         rbp, rsp
-    SHADOW_ARGS_TO_STACK 6
-    SAVE_XMM 7
-    GET_GOT     rbx
-    push        rsi
-    push        rdi
-    ; end prolog
-
-    ALIGN_STACK 16, rax
-    sub          rsp, lf_var_size
-
-        mov         rsi,                arg(0)              ; u_ptr
-        movsxd      rax,                dword ptr arg(1)    ; src_pixel_step
-
-        lea         rsi,                [rsi - 4]
-        lea         rdi,                [rsi + rax]         ; rdi points to row +1 for indirect addressing
-        lea         rcx,                [rax+2*rax]
-
-        ; Transpose
-        TRANSPOSE_16X8 0, 0
-
-        ; calculate filter mask and high edge variance
-        LFV_FILTER_MASK_HEV_MASK
-
-        ; start work on filters
-        MB_FILTER_AND_WRITEBACK 2
-
-        ; transpose and write back
-        MBV_TRANSPOSE
-
-        mov         rsi,                arg(0)             ;u_ptr
-        lea         rsi,                [rsi - 4]
-        lea         rdi,                [rsi + rax]
-        MBV_WRITEBACK_1
-        mov         rsi,                arg(5)             ;v_ptr
-        lea         rsi,                [rsi - 4]
-        lea         rdi,                [rsi + rax]
-        MBV_WRITEBACK_2
-
-    add rsp, lf_var_size
-    pop rsp
-    ; begin epilog
-    pop rdi
-    pop rsi
-    RESTORE_GOT
-    RESTORE_XMM
-    UNSHADOW_ARGS
-    pop         rbp
-    ret
-
-
-;void vp8_loop_filter_simple_horizontal_edge_sse2
-;(
-;    unsigned char *src_ptr,
-;    int  src_pixel_step,
-;    const char *blimit,
-;)
-global sym(vp8_loop_filter_simple_horizontal_edge_sse2) PRIVATE
-sym(vp8_loop_filter_simple_horizontal_edge_sse2):
-    push        rbp
-    mov         rbp, rsp
-    SHADOW_ARGS_TO_STACK 3
-    SAVE_XMM 7
-    GET_GOT     rbx
-    ; end prolog
-
-        mov         rcx, arg(0)             ;src_ptr
-        movsxd      rax, dword ptr arg(1)   ;src_pixel_step     ; destination pitch?
-        movdqa      xmm6, [GLOBAL(tfe)]
-        lea         rdx, [rcx + rax]
-        neg         rax
-
-        ; calculate mask
-        movdqa      xmm0, [rdx]             ; q1
-        mov         rdx, arg(2)             ;blimit
-        movdqa      xmm1, [rcx+2*rax]       ; p1
-
-        movdqa      xmm2, xmm1
-        movdqa      xmm3, xmm0
-
-        psubusb     xmm0, xmm1              ; q1-=p1
-        psubusb     xmm1, xmm3              ; p1-=q1
-        por         xmm1, xmm0              ; abs(p1-q1)
-        pand        xmm1, xmm6              ; set lsb of each byte to zero
-        psrlw       xmm1, 1                 ; abs(p1-q1)/2
-
-        movdqa      xmm7, XMMWORD PTR [rdx]
-
-        movdqa      xmm5, [rcx+rax]         ; p0
-        movdqa      xmm4, [rcx]             ; q0
-        movdqa      xmm0, xmm4              ; q0
-        movdqa      xmm6, xmm5              ; p0
-        psubusb     xmm5, xmm4              ; p0-=q0
-        psubusb     xmm4, xmm6              ; q0-=p0
-        por         xmm5, xmm4              ; abs(p0 - q0)
-
-        movdqa      xmm4, [GLOBAL(t80)]
-
-        paddusb     xmm5, xmm5              ; abs(p0-q0)*2
-        paddusb     xmm5, xmm1              ; abs (p0 - q0) *2 + abs(p1-q1)/2
-        psubusb     xmm5, xmm7              ; abs(p0 - q0) *2 + abs(p1-q1)/2  > blimit
-        pxor        xmm7, xmm7
-        pcmpeqb     xmm5, xmm7
-
-
-        ; start work on filters
-        pxor        xmm2, xmm4     ; p1 offset to convert to signed values
-        pxor        xmm3, xmm4     ; q1 offset to convert to signed values
-        psubsb      xmm2, xmm3              ; p1 - q1
-
-        pxor        xmm6, xmm4     ; offset to convert to signed values
-        pxor        xmm0, xmm4     ; offset to convert to signed values
-        movdqa      xmm3, xmm0              ; q0
-        psubsb      xmm0, xmm6              ; q0 - p0
-        paddsb      xmm2, xmm0              ; p1 - q1 + 1 * (q0 - p0)
-        paddsb      xmm2, xmm0              ; p1 - q1 + 2 * (q0 - p0)
-        paddsb      xmm2, xmm0              ; p1 - q1 + 3 * (q0 - p0)
-        pand        xmm5, xmm2              ; mask filter values we don't care about
-
-        movdqa      xmm0, xmm5
-        paddsb      xmm5,        [GLOBAL(t3)]                  ;  3* (q0 - p0) + (p1 - q1) + 4
-        paddsb      xmm0,        [GLOBAL(t4)]                  ; +3 instead of +4
-
-        movdqa      xmm1, [GLOBAL(te0)]
-        movdqa      xmm2, [GLOBAL(t1f)]
-
-;        pxor        xmm7, xmm7
-        pcmpgtb     xmm7, xmm0              ;save sign
-        pand        xmm7, xmm1              ;preserve the upper 3 bits
-        psrlw       xmm0, 3
-        pand        xmm0, xmm2              ;clear out upper 3 bits
-        por         xmm0, xmm7              ;add sign
-        psubsb      xmm3, xmm0              ; q0-= q0sz add
-
-        pxor        xmm7, xmm7
-        pcmpgtb     xmm7, xmm5              ;save sign
-        pand        xmm7, xmm1              ;preserve the upper 3 bits
-        psrlw       xmm5, 3
-        pand        xmm5, xmm2              ;clear out upper 3 bits
-        por         xmm5, xmm7              ;add sign
-        paddsb      xmm6, xmm5              ; p0+= p0 add
-
-        pxor        xmm3, xmm4     ; unoffset
-        movdqa      [rcx], xmm3             ; write back
-
-        pxor        xmm6, xmm4     ; unoffset
-        movdqa      [rcx+rax], xmm6         ; write back
-
-    ; begin epilog
-    RESTORE_GOT
-    RESTORE_XMM
-    UNSHADOW_ARGS
-    pop         rbp
-    ret
-
-
-;void vp8_loop_filter_simple_vertical_edge_sse2
-;(
-;    unsigned char *src_ptr,
-;    int  src_pixel_step,
-;    const char *blimit,
-;)
-global sym(vp8_loop_filter_simple_vertical_edge_sse2) PRIVATE
-sym(vp8_loop_filter_simple_vertical_edge_sse2):
-    push        rbp         ; save old base pointer value.
-    mov         rbp, rsp    ; set new base pointer value.
-    SHADOW_ARGS_TO_STACK 3
-    SAVE_XMM 7
-    GET_GOT     rbx         ; save callee-saved reg
-    push        rsi
-    push        rdi
-    ; end prolog
-
-    ALIGN_STACK 16, rax
-    sub         rsp, 32                         ; reserve 32 bytes
-    %define t0  [rsp + 0]    ;__declspec(align(16)) char t0[16];
-    %define t1  [rsp + 16]   ;__declspec(align(16)) char t1[16];
-
-        mov         rsi, arg(0) ;src_ptr
-        movsxd      rax, dword ptr arg(1) ;src_pixel_step     ; destination pitch?
-
-        lea         rsi,        [rsi - 2 ]
-        lea         rdi,        [rsi + rax]
-        lea         rdx,        [rsi + rax*4]
-        lea         rcx,        [rdx + rax]
-
-        movd        xmm0,       [rsi]                   ; (high 96 bits unused) 03 02 01 00
-        movd        xmm1,       [rdx]                   ; (high 96 bits unused) 43 42 41 40
-        movd        xmm2,       [rdi]                   ; 13 12 11 10
-        movd        xmm3,       [rcx]                   ; 53 52 51 50
-        punpckldq   xmm0,       xmm1                    ; (high 64 bits unused) 43 42 41 40 03 02 01 00
-        punpckldq   xmm2,       xmm3                    ; 53 52 51 50 13 12 11 10
-
-        movd        xmm4,       [rsi + rax*2]           ; 23 22 21 20
-        movd        xmm5,       [rdx + rax*2]           ; 63 62 61 60
-        movd        xmm6,       [rdi + rax*2]           ; 33 32 31 30
-        movd        xmm7,       [rcx + rax*2]           ; 73 72 71 70
-        punpckldq   xmm4,       xmm5                    ; 63 62 61 60 23 22 21 20
-        punpckldq   xmm6,       xmm7                    ; 73 72 71 70 33 32 31 30
-
-        punpcklbw   xmm0,       xmm2                    ; 53 43 52 42 51 41 50 40 13 03 12 02 11 01 10 00
-        punpcklbw   xmm4,       xmm6                    ; 73 63 72 62 71 61 70 60 33 23 32 22 31 21 30 20
-
-        movdqa      xmm1,       xmm0
-        punpcklwd   xmm0,       xmm4                    ; 33 23 13 03 32 22 12 02 31 21 11 01 30 20 10 00
-        punpckhwd   xmm1,       xmm4                    ; 73 63 53 43 72 62 52 42 71 61 51 41 70 60 50 40
-
-        movdqa      xmm2,       xmm0
-        punpckldq   xmm0,       xmm1                    ; 71 61 51 41 31 21 11 01 70 60 50 40 30 20 10 00
-        punpckhdq   xmm2,       xmm1                    ; 73 63 53 43 33 23 13 03 72 62 52 42 32 22 12 02
-
-        lea         rsi,        [rsi + rax*8]
-        lea         rdi,        [rsi + rax]
-        lea         rdx,        [rsi + rax*4]
-        lea         rcx,        [rdx + rax]
-
-        movd        xmm4,       [rsi]                   ; 83 82 81 80
-        movd        xmm1,       [rdx]                   ; c3 c2 c1 c0
-        movd        xmm6,       [rdi]                   ; 93 92 91 90
-        movd        xmm3,       [rcx]                   ; d3 d2 d1 d0
-        punpckldq   xmm4,       xmm1                    ; c3 c2 c1 c0 83 82 81 80
-        punpckldq   xmm6,       xmm3                    ; d3 d2 d1 d0 93 92 91 90
-
-        movd        xmm1,       [rsi + rax*2]           ; a3 a2 a1 a0
-        movd        xmm5,       [rdx + rax*2]           ; e3 e2 e1 e0
-        movd        xmm3,       [rdi + rax*2]           ; b3 b2 b1 b0
-        movd        xmm7,       [rcx + rax*2]           ; f3 f2 f1 f0
-        punpckldq   xmm1,       xmm5                    ; e3 e2 e1 e0 a3 a2 a1 a0
-        punpckldq   xmm3,       xmm7                    ; f3 f2 f1 f0 b3 b2 b1 b0
-
-        punpcklbw   xmm4,       xmm6                    ; d3 c3 d2 c2 d1 c1 d0 c0 93 83 92 82 91 81 90 80
-        punpcklbw   xmm1,       xmm3                    ; f3 e3 f2 e2 f1 e1 f0 e0 b3 a3 b2 a2 b1 a1 b0 a0
-
-        movdqa      xmm7,       xmm4
-        punpcklwd   xmm4,       xmm1                    ; b3 a3 93 83 b2 a2 92 82 b1 a1 91 81 b0 a0 90 80
-        punpckhwd   xmm7,       xmm1                    ; f3 e3 d3 c3 f2 e2 d2 c2 f1 e1 d1 c1 f0 e0 d0 c0
-
-        movdqa      xmm6,       xmm4
-        punpckldq   xmm4,       xmm7                    ; f1 e1 d1 c1 b1 a1 91 81 f0 e0 d0 c0 b0 a0 90 80
-        punpckhdq   xmm6,       xmm7                    ; f3 e3 d3 c3 b3 a3 93 83 f2 e2 d2 c2 b2 a2 92 82
-
-        movdqa      xmm1,       xmm0
-        movdqa      xmm3,       xmm2
-
-        punpcklqdq  xmm0,       xmm4                    ; p1  f0 e0 d0 c0 b0 a0 90 80 70 60 50 40 30 20 10 00
-        punpckhqdq  xmm1,       xmm4                    ; p0  f1 e1 d1 c1 b1 a1 91 81 71 61 51 41 31 21 11 01
-        punpcklqdq  xmm2,       xmm6                    ; q0  f2 e2 d2 c2 b2 a2 92 82 72 62 52 42 32 22 12 02
-        punpckhqdq  xmm3,       xmm6                    ; q1  f3 e3 d3 c3 b3 a3 93 83 73 63 53 43 33 23 13 03
-
-        mov         rdx,        arg(2)                          ;blimit
-
-        ; calculate mask
-        movdqa      xmm6,       xmm0                            ; p1
-        movdqa      xmm7,       xmm3                            ; q1
-        psubusb     xmm7,       xmm0                            ; q1-=p1
-        psubusb     xmm6,       xmm3                            ; p1-=q1
-        por         xmm6,       xmm7                            ; abs(p1-q1)
-        pand        xmm6,       [GLOBAL(tfe)]                   ; set lsb of each byte to zero
-        psrlw       xmm6,       1                               ; abs(p1-q1)/2
-
-        movdqa      xmm7, [rdx]
-
-        movdqa      xmm5,       xmm1                            ; p0
-        movdqa      xmm4,       xmm2                            ; q0
-        psubusb     xmm5,       xmm2                            ; p0-=q0
-        psubusb     xmm4,       xmm1                            ; q0-=p0
-        por         xmm5,       xmm4                            ; abs(p0 - q0)
-        paddusb     xmm5,       xmm5                            ; abs(p0-q0)*2
-        paddusb     xmm5,       xmm6                            ; abs (p0 - q0) *2 + abs(p1-q1)/2
-
-        movdqa      xmm4, [GLOBAL(t80)]
-
-        psubusb     xmm5,        xmm7                           ; abs(p0 - q0) *2 + abs(p1-q1)/2  > blimit
-        pxor        xmm7,        xmm7
-        pcmpeqb     xmm5,        xmm7                           ; mm5 = mask
-
-        ; start work on filters
-        movdqa        t0,        xmm0
-        movdqa        t1,        xmm3
-
-        pxor        xmm0,        xmm4                  ; p1 offset to convert to signed values
-        pxor        xmm3,        xmm4                  ; q1 offset to convert to signed values
-        psubsb      xmm0,        xmm3                           ; p1 - q1
-
-        pxor        xmm1,        xmm4                  ; offset to convert to signed values
-        pxor        xmm2,        xmm4                  ; offset to convert to signed values
-
-        movdqa      xmm3,        xmm2                           ; offseted ; q0
-        psubsb      xmm2,        xmm1                           ; q0 - p0
-        paddsb      xmm0,        xmm2                           ; p1 - q1 + 1 * (q0 - p0)
-        paddsb      xmm0,        xmm2                           ; p1 - q1 + 2 * (q0 - p0)
-        paddsb      xmm0,        xmm2                           ; p1 - q1 + 3 * (q0 - p0)
-        pand        xmm5,        xmm0                           ; mask filter values we don't care about
-
-        movdqa      xmm0, xmm5
-        paddsb      xmm5,        [GLOBAL(t3)]                  ;  3* (q0 - p0) + (p1 - q1) + 4
-        paddsb      xmm0,        [GLOBAL(t4)]                  ; +3 instead of +4
-
-        movdqa  xmm6, [GLOBAL(te0)]
-        movdqa  xmm2, [GLOBAL(t1f)]
-
-;        pxor        xmm7, xmm7
-        pcmpgtb     xmm7, xmm0              ;save sign
-        pand        xmm7, xmm6              ;preserve the upper 3 bits
-        psrlw       xmm0, 3
-        pand        xmm0, xmm2              ;clear out upper 3 bits
-        por         xmm0, xmm7              ;add sign
-        psubsb      xmm3, xmm0              ; q0-= q0sz add
-
-        pxor        xmm7, xmm7
-        pcmpgtb     xmm7, xmm5              ;save sign
-        pand        xmm7, xmm6              ;preserve the upper 3 bits
-        psrlw       xmm5, 3
-        pand        xmm5, xmm2              ;clear out upper 3 bits
-        por         xmm5, xmm7              ;add sign
-        paddsb      xmm1, xmm5              ; p0+= p0 add
-
-        pxor        xmm3,        xmm4                  ; unoffset   q0
-        pxor        xmm1,        xmm4                  ; unoffset   p0
-
-        movdqa      xmm0,        t0                             ; p1
-        movdqa      xmm4,        t1                             ; q1
-
-        ; write out order: xmm0 xmm2 xmm1 xmm3
-        lea         rdx,        [rsi + rax*4]
-
-        ; transpose back to write out
-        ; p1  f0 e0 d0 c0 b0 a0 90 80 70 60 50 40 30 20 10 00
-        ; p0  f1 e1 d1 c1 b1 a1 91 81 71 61 51 41 31 21 11 01
-        ; q0  f2 e2 d2 c2 b2 a2 92 82 72 62 52 42 32 22 12 02
-        ; q1  f3 e3 d3 c3 b3 a3 93 83 73 63 53 43 33 23 13 03
-        movdqa      xmm6,       xmm0
-        punpcklbw   xmm0,       xmm1                               ; 71 70 61 60 51 50 41 40 31 30 21 20 11 10 01 00
-        punpckhbw   xmm6,       xmm1                               ; f1 f0 e1 e0 d1 d0 c1 c0 b1 b0 a1 a0 91 90 81 80
-
-        movdqa      xmm5,       xmm3
-        punpcklbw   xmm3,       xmm4                               ; 73 72 63 62 53 52 43 42 33 32 23 22 13 12 03 02
-        punpckhbw   xmm5,       xmm4                               ; f3 f2 e3 e2 d3 d2 c3 c2 b3 b2 a3 a2 93 92 83 82
-
-        movdqa      xmm2,       xmm0
-        punpcklwd   xmm0,       xmm3                               ; 33 32 31 30 23 22 21 20 13 12 11 10 03 02 01 00
-        punpckhwd   xmm2,       xmm3                               ; 73 72 71 70 63 62 61 60 53 52 51 50 43 42 41 40
-
-        movdqa      xmm3,       xmm6
-        punpcklwd   xmm6,       xmm5                               ; b3 b2 b1 b0 a3 a2 a1 a0 93 92 91 90 83 82 81 80
-        punpckhwd   xmm3,       xmm5                               ; f3 f2 f1 f0 e3 e2 e1 e0 d3 d2 d1 d0 c3 c2 c1 c0
-
-        movd        [rsi],      xmm6                               ; write the second 8-line result
-        movd        [rdx],      xmm3
-        psrldq      xmm6,       4
-        psrldq      xmm3,       4
-        movd        [rdi],      xmm6
-        movd        [rcx],      xmm3
-        psrldq      xmm6,       4
-        psrldq      xmm3,       4
-        movd        [rsi + rax*2], xmm6
-        movd        [rdx + rax*2], xmm3
-        psrldq      xmm6,       4
-        psrldq      xmm3,       4
-        movd        [rdi + rax*2], xmm6
-        movd        [rcx + rax*2], xmm3
-
-        neg         rax
-        lea         rsi,        [rsi + rax*8]
-        neg         rax
-        lea         rdi,        [rsi + rax]
-        lea         rdx,        [rsi + rax*4]
-        lea         rcx,        [rdx + rax]
-
-        movd        [rsi],      xmm0                                ; write the first 8-line result
-        movd        [rdx],      xmm2
-        psrldq      xmm0,       4
-        psrldq      xmm2,       4
-        movd        [rdi],      xmm0
-        movd        [rcx],      xmm2
-        psrldq      xmm0,       4
-        psrldq      xmm2,       4
-        movd        [rsi + rax*2], xmm0
-        movd        [rdx + rax*2], xmm2
-        psrldq      xmm0,       4
-        psrldq      xmm2,       4
-        movd        [rdi + rax*2], xmm0
-        movd        [rcx + rax*2], xmm2
-
-    add rsp, 32
-    pop rsp
-    ; begin epilog
-    pop rdi
-    pop rsi
-    RESTORE_GOT
-    RESTORE_XMM
-    UNSHADOW_ARGS
-    pop         rbp
-    ret
-
-SECTION_RODATA
-align 16
-tfe:
-    times 16 db 0xfe
-align 16
-t80:
-    times 16 db 0x80
-align 16
-t1s:
-    times 16 db 0x01
-align 16
-t3:
-    times 16 db 0x03
-align 16
-t4:
-    times 16 db 0x04
-align 16
-ones:
-    times 8 dw 0x0001
-align 16
-s9:
-    times 8 dw 0x0900
-align 16
-s63:
-    times 8 dw 0x003f
-align 16
-te0:
-    times 16 db 0xe0
-align 16
-t1f:
-    times 16 db 0x1f
diff --git a/vp8/common/x86/loopfilter_x86.c b/vp8/common/x86/loopfilter_x86.c
deleted file mode 100644 (file)
index 6586004..0000000
+++ /dev/null
@@ -1,198 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#include "vpx_config.h"
-#include "vp8/common/loopfilter.h"
-
-#define prototype_loopfilter(sym) \
-    void sym(unsigned char *src, int pitch, const unsigned char *blimit,\
-             const unsigned char *limit, const unsigned char *thresh, int count)
-
-#define prototype_loopfilter_nc(sym) \
-    void sym(unsigned char *src, int pitch, const unsigned char *blimit,\
-             const unsigned char *limit, const unsigned char *thresh)
-
-#define prototype_simple_loopfilter(sym) \
-    void sym(unsigned char *y, int ystride, const unsigned char *blimit)
-
-prototype_loopfilter(vp8_mbloop_filter_vertical_edge_mmx);
-prototype_loopfilter(vp8_mbloop_filter_horizontal_edge_mmx);
-prototype_loopfilter(vp8_loop_filter_vertical_edge_mmx);
-prototype_loopfilter(vp8_loop_filter_horizontal_edge_mmx);
-prototype_simple_loopfilter(vp8_loop_filter_simple_horizontal_edge_mmx);
-prototype_simple_loopfilter(vp8_loop_filter_simple_vertical_edge_mmx);
-
-#if HAVE_SSE2 && ARCH_X86_64
-prototype_loopfilter(vp8_loop_filter_bv_y_sse2);
-prototype_loopfilter(vp8_loop_filter_bh_y_sse2);
-#else
-prototype_loopfilter_nc(vp8_loop_filter_vertical_edge_sse2);
-prototype_loopfilter_nc(vp8_loop_filter_horizontal_edge_sse2);
-#endif
-prototype_loopfilter_nc(vp8_mbloop_filter_vertical_edge_sse2);
-prototype_loopfilter_nc(vp8_mbloop_filter_horizontal_edge_sse2);
-
-extern loop_filter_uvfunction vp8_loop_filter_horizontal_edge_uv_sse2;
-extern loop_filter_uvfunction vp8_loop_filter_vertical_edge_uv_sse2;
-extern loop_filter_uvfunction vp8_mbloop_filter_horizontal_edge_uv_sse2;
-extern loop_filter_uvfunction vp8_mbloop_filter_vertical_edge_uv_sse2;
-
-#if HAVE_MMX
-/* Horizontal MB filtering */
-void vp8_loop_filter_mbh_mmx(unsigned char *y_ptr, unsigned char *u_ptr, unsigned char *v_ptr,
-                             int y_stride, int uv_stride, loop_filter_info *lfi)
-{
-    vp8_mbloop_filter_horizontal_edge_mmx(y_ptr, y_stride, lfi->mblim, lfi->lim, lfi->hev_thr, 2);
-
-    if (u_ptr)
-        vp8_mbloop_filter_horizontal_edge_mmx(u_ptr, uv_stride, lfi->mblim, lfi->lim, lfi->hev_thr, 1);
-
-    if (v_ptr)
-        vp8_mbloop_filter_horizontal_edge_mmx(v_ptr, uv_stride, lfi->mblim, lfi->lim, lfi->hev_thr, 1);
-}
-
-
-/* Vertical MB Filtering */
-void vp8_loop_filter_mbv_mmx(unsigned char *y_ptr, unsigned char *u_ptr, unsigned char *v_ptr,
-                             int y_stride, int uv_stride, loop_filter_info *lfi)
-{
-    vp8_mbloop_filter_vertical_edge_mmx(y_ptr, y_stride, lfi->mblim, lfi->lim, lfi->hev_thr, 2);
-
-    if (u_ptr)
-        vp8_mbloop_filter_vertical_edge_mmx(u_ptr, uv_stride, lfi->mblim, lfi->lim, lfi->hev_thr, 1);
-
-    if (v_ptr)
-        vp8_mbloop_filter_vertical_edge_mmx(v_ptr, uv_stride, lfi->mblim, lfi->lim, lfi->hev_thr, 1);
-}
-
-
-/* Horizontal B Filtering */
-void vp8_loop_filter_bh_mmx(unsigned char *y_ptr, unsigned char *u_ptr, unsigned char *v_ptr,
-                            int y_stride, int uv_stride, loop_filter_info *lfi)
-{
-    vp8_loop_filter_horizontal_edge_mmx(y_ptr + 4 * y_stride, y_stride, lfi->blim, lfi->lim, lfi->hev_thr, 2);
-    vp8_loop_filter_horizontal_edge_mmx(y_ptr + 8 * y_stride, y_stride, lfi->blim, lfi->lim, lfi->hev_thr, 2);
-    vp8_loop_filter_horizontal_edge_mmx(y_ptr + 12 * y_stride, y_stride, lfi->blim, lfi->lim, lfi->hev_thr, 2);
-
-    if (u_ptr)
-        vp8_loop_filter_horizontal_edge_mmx(u_ptr + 4 * uv_stride, uv_stride, lfi->blim, lfi->lim, lfi->hev_thr, 1);
-
-    if (v_ptr)
-        vp8_loop_filter_horizontal_edge_mmx(v_ptr + 4 * uv_stride, uv_stride, lfi->blim, lfi->lim, lfi->hev_thr, 1);
-}
-
-
-void vp8_loop_filter_bhs_mmx(unsigned char *y_ptr, int y_stride, const unsigned char *blimit)
-{
-    vp8_loop_filter_simple_horizontal_edge_mmx(y_ptr + 4 * y_stride, y_stride, blimit);
-    vp8_loop_filter_simple_horizontal_edge_mmx(y_ptr + 8 * y_stride, y_stride, blimit);
-    vp8_loop_filter_simple_horizontal_edge_mmx(y_ptr + 12 * y_stride, y_stride, blimit);
-}
-
-
-/* Vertical B Filtering */
-void vp8_loop_filter_bv_mmx(unsigned char *y_ptr, unsigned char *u_ptr, unsigned char *v_ptr,
-                            int y_stride, int uv_stride, loop_filter_info *lfi)
-{
-    vp8_loop_filter_vertical_edge_mmx(y_ptr + 4, y_stride, lfi->blim, lfi->lim, lfi->hev_thr, 2);
-    vp8_loop_filter_vertical_edge_mmx(y_ptr + 8, y_stride, lfi->blim, lfi->lim, lfi->hev_thr, 2);
-    vp8_loop_filter_vertical_edge_mmx(y_ptr + 12, y_stride, lfi->blim, lfi->lim, lfi->hev_thr, 2);
-
-    if (u_ptr)
-        vp8_loop_filter_vertical_edge_mmx(u_ptr + 4, uv_stride, lfi->blim, lfi->lim, lfi->hev_thr, 1);
-
-    if (v_ptr)
-        vp8_loop_filter_vertical_edge_mmx(v_ptr + 4, uv_stride, lfi->blim, lfi->lim, lfi->hev_thr, 1);
-}
-
-
-void vp8_loop_filter_bvs_mmx(unsigned char *y_ptr, int y_stride, const unsigned char *blimit)
-{
-    vp8_loop_filter_simple_vertical_edge_mmx(y_ptr + 4, y_stride, blimit);
-    vp8_loop_filter_simple_vertical_edge_mmx(y_ptr + 8, y_stride, blimit);
-    vp8_loop_filter_simple_vertical_edge_mmx(y_ptr + 12, y_stride, blimit);
-}
-#endif
-
-
-/* Horizontal MB filtering */
-#if HAVE_SSE2
-void vp8_loop_filter_mbh_sse2(unsigned char *y_ptr, unsigned char *u_ptr, unsigned char *v_ptr,
-                              int y_stride, int uv_stride, loop_filter_info *lfi)
-{
-    vp8_mbloop_filter_horizontal_edge_sse2(y_ptr, y_stride, lfi->mblim, lfi->lim, lfi->hev_thr);
-
-    if (u_ptr)
-        vp8_mbloop_filter_horizontal_edge_uv_sse2(u_ptr, uv_stride, lfi->mblim, lfi->lim, lfi->hev_thr, v_ptr);
-}
-
-
-/* Vertical MB Filtering */
-void vp8_loop_filter_mbv_sse2(unsigned char *y_ptr, unsigned char *u_ptr, unsigned char *v_ptr,
-                              int y_stride, int uv_stride, loop_filter_info *lfi)
-{
-    vp8_mbloop_filter_vertical_edge_sse2(y_ptr, y_stride, lfi->mblim, lfi->lim, lfi->hev_thr);
-
-    if (u_ptr)
-        vp8_mbloop_filter_vertical_edge_uv_sse2(u_ptr, uv_stride, lfi->mblim, lfi->lim, lfi->hev_thr, v_ptr);
-}
-
-
-/* Horizontal B Filtering */
-void vp8_loop_filter_bh_sse2(unsigned char *y_ptr, unsigned char *u_ptr, unsigned char *v_ptr,
-                             int y_stride, int uv_stride, loop_filter_info *lfi)
-{
-#if ARCH_X86_64
-    vp8_loop_filter_bh_y_sse2(y_ptr, y_stride, lfi->blim, lfi->lim, lfi->hev_thr, 2);
-#else
-    vp8_loop_filter_horizontal_edge_sse2(y_ptr + 4 * y_stride, y_stride, lfi->blim, lfi->lim, lfi->hev_thr);
-    vp8_loop_filter_horizontal_edge_sse2(y_ptr + 8 * y_stride, y_stride, lfi->blim, lfi->lim, lfi->hev_thr);
-    vp8_loop_filter_horizontal_edge_sse2(y_ptr + 12 * y_stride, y_stride, lfi->blim, lfi->lim, lfi->hev_thr);
-#endif
-
-    if (u_ptr)
-        vp8_loop_filter_horizontal_edge_uv_sse2(u_ptr + 4 * uv_stride, uv_stride, lfi->blim, lfi->lim, lfi->hev_thr, v_ptr + 4 * uv_stride);
-}
-
-
-void vp8_loop_filter_bhs_sse2(unsigned char *y_ptr, int y_stride, const unsigned char *blimit)
-{
-    vp8_loop_filter_simple_horizontal_edge_sse2(y_ptr + 4 * y_stride, y_stride, blimit);
-    vp8_loop_filter_simple_horizontal_edge_sse2(y_ptr + 8 * y_stride, y_stride, blimit);
-    vp8_loop_filter_simple_horizontal_edge_sse2(y_ptr + 12 * y_stride, y_stride, blimit);
-}
-
-
-/* Vertical B Filtering */
-void vp8_loop_filter_bv_sse2(unsigned char *y_ptr, unsigned char *u_ptr, unsigned char *v_ptr,
-                             int y_stride, int uv_stride, loop_filter_info *lfi)
-{
-#if ARCH_X86_64
-    vp8_loop_filter_bv_y_sse2(y_ptr, y_stride, lfi->blim, lfi->lim, lfi->hev_thr, 2);
-#else
-    vp8_loop_filter_vertical_edge_sse2(y_ptr + 4, y_stride, lfi->blim, lfi->lim, lfi->hev_thr);
-    vp8_loop_filter_vertical_edge_sse2(y_ptr + 8, y_stride, lfi->blim, lfi->lim, lfi->hev_thr);
-    vp8_loop_filter_vertical_edge_sse2(y_ptr + 12, y_stride, lfi->blim, lfi->lim, lfi->hev_thr);
-#endif
-
-    if (u_ptr)
-        vp8_loop_filter_vertical_edge_uv_sse2(u_ptr + 4, uv_stride, lfi->blim, lfi->lim, lfi->hev_thr, v_ptr + 4);
-}
-
-
-void vp8_loop_filter_bvs_sse2(unsigned char *y_ptr, int y_stride, const unsigned char *blimit)
-{
-    vp8_loop_filter_simple_vertical_edge_sse2(y_ptr + 4, y_stride, blimit);
-    vp8_loop_filter_simple_vertical_edge_sse2(y_ptr + 8, y_stride, blimit);
-    vp8_loop_filter_simple_vertical_edge_sse2(y_ptr + 12, y_stride, blimit);
-}
-
-#endif
diff --git a/vp8/common/x86/mfqe_sse2.asm b/vp8/common/x86/mfqe_sse2.asm
deleted file mode 100644 (file)
index 8177b79..0000000
+++ /dev/null
@@ -1,287 +0,0 @@
-;
-;  Copyright (c) 2012 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.
-;
-
-
-%include "vpx_ports/x86_abi_support.asm"
-
-;void vp8_filter_by_weight16x16_sse2
-;(
-;    unsigned char *src,
-;    int            src_stride,
-;    unsigned char *dst,
-;    int            dst_stride,
-;    int            src_weight
-;)
-global sym(vp8_filter_by_weight16x16_sse2) PRIVATE
-sym(vp8_filter_by_weight16x16_sse2):
-    push        rbp
-    mov         rbp, rsp
-    SHADOW_ARGS_TO_STACK 5
-    SAVE_XMM 6
-    GET_GOT     rbx
-    push        rsi
-    push        rdi
-    ; end prolog
-
-    movd        xmm0, arg(4)                ; src_weight
-    pshuflw     xmm0, xmm0, 0x0             ; replicate to all low words
-    punpcklqdq  xmm0, xmm0                  ; replicate to all hi words
-
-    movdqa      xmm1, [GLOBAL(tMFQE)]
-    psubw       xmm1, xmm0                  ; dst_weight
-
-    mov         rax, arg(0)                 ; src
-    mov         rsi, arg(1)                 ; src_stride
-    mov         rdx, arg(2)                 ; dst
-    mov         rdi, arg(3)                 ; dst_stride
-
-    mov         rcx, 16                     ; loop count
-    pxor        xmm6, xmm6
-
-.combine:
-    movdqa      xmm2, [rax]
-    movdqa      xmm4, [rdx]
-    add         rax, rsi
-
-    ; src * src_weight
-    movdqa      xmm3, xmm2
-    punpcklbw   xmm2, xmm6
-    punpckhbw   xmm3, xmm6
-    pmullw      xmm2, xmm0
-    pmullw      xmm3, xmm0
-
-    ; dst * dst_weight
-    movdqa      xmm5, xmm4
-    punpcklbw   xmm4, xmm6
-    punpckhbw   xmm5, xmm6
-    pmullw      xmm4, xmm1
-    pmullw      xmm5, xmm1
-
-    ; sum, round and shift
-    paddw       xmm2, xmm4
-    paddw       xmm3, xmm5
-    paddw       xmm2, [GLOBAL(tMFQE_round)]
-    paddw       xmm3, [GLOBAL(tMFQE_round)]
-    psrlw       xmm2, 4
-    psrlw       xmm3, 4
-
-    packuswb    xmm2, xmm3
-    movdqa      [rdx], xmm2
-    add         rdx, rdi
-
-    dec         rcx
-    jnz         .combine
-
-    ; begin epilog
-    pop         rdi
-    pop         rsi
-    RESTORE_GOT
-    RESTORE_XMM
-    UNSHADOW_ARGS
-    pop         rbp
-
-    ret
-
-;void vp8_filter_by_weight8x8_sse2
-;(
-;    unsigned char *src,
-;    int            src_stride,
-;    unsigned char *dst,
-;    int            dst_stride,
-;    int            src_weight
-;)
-global sym(vp8_filter_by_weight8x8_sse2) PRIVATE
-sym(vp8_filter_by_weight8x8_sse2):
-    push        rbp
-    mov         rbp, rsp
-    SHADOW_ARGS_TO_STACK 5
-    GET_GOT     rbx
-    push        rsi
-    push        rdi
-    ; end prolog
-
-    movd        xmm0, arg(4)                ; src_weight
-    pshuflw     xmm0, xmm0, 0x0             ; replicate to all low words
-    punpcklqdq  xmm0, xmm0                  ; replicate to all hi words
-
-    movdqa      xmm1, [GLOBAL(tMFQE)]
-    psubw       xmm1, xmm0                  ; dst_weight
-
-    mov         rax, arg(0)                 ; src
-    mov         rsi, arg(1)                 ; src_stride
-    mov         rdx, arg(2)                 ; dst
-    mov         rdi, arg(3)                 ; dst_stride
-
-    mov         rcx, 8                      ; loop count
-    pxor        xmm4, xmm4
-
-.combine:
-    movq        xmm2, [rax]
-    movq        xmm3, [rdx]
-    add         rax, rsi
-
-    ; src * src_weight
-    punpcklbw   xmm2, xmm4
-    pmullw      xmm2, xmm0
-
-    ; dst * dst_weight
-    punpcklbw   xmm3, xmm4
-    pmullw      xmm3, xmm1
-
-    ; sum, round and shift
-    paddw       xmm2, xmm3
-    paddw       xmm2, [GLOBAL(tMFQE_round)]
-    psrlw       xmm2, 4
-
-    packuswb    xmm2, xmm4
-    movq        [rdx], xmm2
-    add         rdx, rdi
-
-    dec         rcx
-    jnz         .combine
-
-    ; begin epilog
-    pop         rdi
-    pop         rsi
-    RESTORE_GOT
-    UNSHADOW_ARGS
-    pop         rbp
-
-    ret
-
-;void vp8_variance_and_sad_16x16_sse2 | arg
-;(
-;    unsigned char *src1,          0
-;    int            stride1,       1
-;    unsigned char *src2,          2
-;    int            stride2,       3
-;    unsigned int  *variance,      4
-;    unsigned int  *sad,           5
-;)
-global sym(vp8_variance_and_sad_16x16_sse2) PRIVATE
-sym(vp8_variance_and_sad_16x16_sse2):
-    push        rbp
-    mov         rbp, rsp
-    SHADOW_ARGS_TO_STACK 6
-    GET_GOT     rbx
-    push        rsi
-    push        rdi
-    ; end prolog
-
-    mov         rax,        arg(0)          ; src1
-    mov         rcx,        arg(1)          ; stride1
-    mov         rdx,        arg(2)          ; src2
-    mov         rdi,        arg(3)          ; stride2
-
-    mov         rsi,        16              ; block height
-
-    ; Prep accumulator registers
-    pxor        xmm3, xmm3                  ; SAD
-    pxor        xmm4, xmm4                  ; sum of src2
-    pxor        xmm5, xmm5                  ; sum of src2^2
-
-    ; Because we're working with the actual output frames
-    ; we can't depend on any kind of data alignment.
-.accumulate:
-    movdqa      xmm0, [rax]                 ; src1
-    movdqa      xmm1, [rdx]                 ; src2
-    add         rax, rcx                    ; src1 + stride1
-    add         rdx, rdi                    ; src2 + stride2
-
-    ; SAD(src1, src2)
-    psadbw      xmm0, xmm1
-    paddusw     xmm3, xmm0
-
-    ; SUM(src2)
-    pxor        xmm2, xmm2
-    psadbw      xmm2, xmm1                  ; sum src2 by misusing SAD against 0
-    paddusw     xmm4, xmm2
-
-    ; pmaddubsw would be ideal if it took two unsigned values. instead,
-    ; it expects a signed and an unsigned value. so instead we zero extend
-    ; and operate on words.
-    pxor        xmm2, xmm2
-    movdqa      xmm0, xmm1
-    punpcklbw   xmm0, xmm2
-    punpckhbw   xmm1, xmm2
-    pmaddwd     xmm0, xmm0
-    pmaddwd     xmm1, xmm1
-    paddd       xmm5, xmm0
-    paddd       xmm5, xmm1
-
-    sub         rsi,        1
-    jnz         .accumulate
-
-    ; phaddd only operates on adjacent double words.
-    ; Finalize SAD and store
-    movdqa      xmm0, xmm3
-    psrldq      xmm0, 8
-    paddusw     xmm0, xmm3
-    paddd       xmm0, [GLOBAL(t128)]
-    psrld       xmm0, 8
-
-    mov         rax,  arg(5)
-    movd        [rax], xmm0
-
-    ; Accumulate sum of src2
-    movdqa      xmm0, xmm4
-    psrldq      xmm0, 8
-    paddusw     xmm0, xmm4
-    ; Square src2. Ignore high value
-    pmuludq     xmm0, xmm0
-    psrld       xmm0, 8
-
-    ; phaddw could be used to sum adjacent values but we want
-    ; all the values summed. promote to doubles, accumulate,
-    ; shift and sum
-    pxor        xmm2, xmm2
-    movdqa      xmm1, xmm5
-    punpckldq   xmm1, xmm2
-    punpckhdq   xmm5, xmm2
-    paddd       xmm1, xmm5
-    movdqa      xmm2, xmm1
-    psrldq      xmm1, 8
-    paddd       xmm1, xmm2
-
-    psubd       xmm1, xmm0
-
-    ; (variance + 128) >> 8
-    paddd       xmm1, [GLOBAL(t128)]
-    psrld       xmm1, 8
-    mov         rax,  arg(4)
-
-    movd        [rax], xmm1
-
-
-    ; begin epilog
-    pop         rdi
-    pop         rsi
-    RESTORE_GOT
-    UNSHADOW_ARGS
-    pop         rbp
-    ret
-
-SECTION_RODATA
-align 16
-t128:
-%ifndef __NASM_VER__
-    ddq 128
-%elif CONFIG_BIG_ENDIAN
-    dq  0, 128
-%else
-    dq  128, 0
-%endif
-align 16
-tMFQE: ; 1 << MFQE_PRECISION
-    times 8 dw 0x10
-align 16
-tMFQE_round: ; 1 << (MFQE_PRECISION - 1)
-    times 8 dw 0x08
-
diff --git a/vp8/common/x86/recon_mmx.asm b/vp8/common/x86/recon_mmx.asm
deleted file mode 100644 (file)
index 15e9871..0000000
+++ /dev/null
@@ -1,274 +0,0 @@
-;
-;  Copyright (c) 2010 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.
-;
-
-
-%include "vpx_ports/x86_abi_support.asm"
-
-
-;void copy_mem8x8_mmx(
-;    unsigned char *src,
-;    int src_stride,
-;    unsigned char *dst,
-;    int dst_stride
-;    )
-global sym(vp8_copy_mem8x8_mmx) PRIVATE
-sym(vp8_copy_mem8x8_mmx):
-    push        rbp
-    mov         rbp, rsp
-    SHADOW_ARGS_TO_STACK 4
-    push        rsi
-    push        rdi
-    ; end prolog
-
-        mov         rsi,        arg(0) ;src;
-        movq        mm0,        [rsi]
-
-        movsxd      rax,        dword ptr arg(1) ;src_stride;
-        mov         rdi,        arg(2) ;dst;
-
-        movq        mm1,        [rsi+rax]
-        movq        mm2,        [rsi+rax*2]
-
-        movsxd      rcx,        dword ptr arg(3) ;dst_stride
-        lea         rsi,        [rsi+rax*2]
-
-        movq        [rdi],      mm0
-        add         rsi,        rax
-
-        movq        [rdi+rcx],      mm1
-        movq        [rdi+rcx*2],    mm2
-
-
-        lea         rdi,        [rdi+rcx*2]
-        movq        mm3,        [rsi]
-
-        add         rdi,        rcx
-        movq        mm4,        [rsi+rax]
-
-        movq        mm5,        [rsi+rax*2]
-        movq        [rdi],      mm3
-
-        lea         rsi,        [rsi+rax*2]
-        movq        [rdi+rcx],  mm4
-
-        movq        [rdi+rcx*2],    mm5
-        lea         rdi,        [rdi+rcx*2]
-
-        movq        mm0,        [rsi+rax]
-        movq        mm1,        [rsi+rax*2]
-
-        movq        [rdi+rcx],  mm0
-        movq        [rdi+rcx*2],mm1
-
-    ; begin epilog
-    pop rdi
-    pop rsi
-    UNSHADOW_ARGS
-    pop         rbp
-    ret
-
-
-;void copy_mem8x4_mmx(
-;    unsigned char *src,
-;    int src_stride,
-;    unsigned char *dst,
-;    int dst_stride
-;    )
-global sym(vp8_copy_mem8x4_mmx) PRIVATE
-sym(vp8_copy_mem8x4_mmx):
-    push        rbp
-    mov         rbp, rsp
-    SHADOW_ARGS_TO_STACK 4
-    push        rsi
-    push        rdi
-    ; end prolog
-
-        mov         rsi,        arg(0) ;src;
-        movq        mm0,        [rsi]
-
-        movsxd      rax,        dword ptr arg(1) ;src_stride;
-        mov         rdi,        arg(2) ;dst;
-
-        movq        mm1,        [rsi+rax]
-        movq        mm2,        [rsi+rax*2]
-
-        movsxd      rcx,        dword ptr arg(3) ;dst_stride
-        lea         rsi,        [rsi+rax*2]
-
-        movq        [rdi],      mm0
-        movq        [rdi+rcx],      mm1
-
-        movq        [rdi+rcx*2],    mm2
-        lea         rdi,        [rdi+rcx*2]
-
-        movq        mm3,        [rsi+rax]
-        movq        [rdi+rcx],      mm3
-
-    ; begin epilog
-    pop rdi
-    pop rsi
-    UNSHADOW_ARGS
-    pop         rbp
-    ret
-
-
-;void copy_mem16x16_mmx(
-;    unsigned char *src,
-;    int src_stride,
-;    unsigned char *dst,
-;    int dst_stride
-;    )
-global sym(vp8_copy_mem16x16_mmx) PRIVATE
-sym(vp8_copy_mem16x16_mmx):
-    push        rbp
-    mov         rbp, rsp
-    SHADOW_ARGS_TO_STACK 4
-    push        rsi
-    push        rdi
-    ; end prolog
-
-        mov         rsi,        arg(0) ;src;
-        movsxd      rax,        dword ptr arg(1) ;src_stride;
-
-        mov         rdi,        arg(2) ;dst;
-        movsxd      rcx,        dword ptr arg(3) ;dst_stride
-
-        movq        mm0,            [rsi]
-        movq        mm3,            [rsi+8];
-
-        movq        mm1,            [rsi+rax]
-        movq        mm4,            [rsi+rax+8]
-
-        movq        mm2,            [rsi+rax*2]
-        movq        mm5,            [rsi+rax*2+8]
-
-        lea         rsi,            [rsi+rax*2]
-        add         rsi,            rax
-
-        movq        [rdi],          mm0
-        movq        [rdi+8],        mm3
-
-        movq        [rdi+rcx],      mm1
-        movq        [rdi+rcx+8],    mm4
-
-        movq        [rdi+rcx*2],    mm2
-        movq        [rdi+rcx*2+8],  mm5
-
-        lea         rdi,            [rdi+rcx*2]
-        add         rdi,            rcx
-
-        movq        mm0,            [rsi]
-        movq        mm3,            [rsi+8];
-
-        movq        mm1,            [rsi+rax]
-        movq        mm4,            [rsi+rax+8]
-
-        movq        mm2,            [rsi+rax*2]
-        movq        mm5,            [rsi+rax*2+8]
-
-        lea         rsi,            [rsi+rax*2]
-        add         rsi,            rax
-
-        movq        [rdi],          mm0
-        movq        [rdi+8],        mm3
-
-        movq        [rdi+rcx],      mm1
-        movq        [rdi+rcx+8],    mm4
-
-        movq        [rdi+rcx*2],    mm2
-        movq        [rdi+rcx*2+8],  mm5
-
-        lea         rdi,            [rdi+rcx*2]
-        add         rdi,            rcx
-
-        movq        mm0,            [rsi]
-        movq        mm3,            [rsi+8];
-
-        movq        mm1,            [rsi+rax]
-        movq        mm4,            [rsi+rax+8]
-
-        movq        mm2,            [rsi+rax*2]
-        movq        mm5,            [rsi+rax*2+8]
-
-        lea         rsi,            [rsi+rax*2]
-        add         rsi,            rax
-
-        movq        [rdi],          mm0
-        movq        [rdi+8],        mm3
-
-        movq        [rdi+rcx],      mm1
-        movq        [rdi+rcx+8],    mm4
-
-        movq        [rdi+rcx*2],    mm2
-        movq        [rdi+rcx*2+8],  mm5
-
-        lea         rdi,            [rdi+rcx*2]
-        add         rdi,            rcx
-
-        movq        mm0,            [rsi]
-        movq        mm3,            [rsi+8];
-
-        movq        mm1,            [rsi+rax]
-        movq        mm4,            [rsi+rax+8]
-
-        movq        mm2,            [rsi+rax*2]
-        movq        mm5,            [rsi+rax*2+8]
-
-        lea         rsi,            [rsi+rax*2]
-        add         rsi,            rax
-
-        movq        [rdi],          mm0
-        movq        [rdi+8],        mm3
-
-        movq        [rdi+rcx],      mm1
-        movq        [rdi+rcx+8],    mm4
-
-        movq        [rdi+rcx*2],    mm2
-        movq        [rdi+rcx*2+8],  mm5
-
-        lea         rdi,            [rdi+rcx*2]
-        add         rdi,            rcx
-
-        movq        mm0,            [rsi]
-        movq        mm3,            [rsi+8];
-
-        movq        mm1,            [rsi+rax]
-        movq        mm4,            [rsi+rax+8]
-
-        movq        mm2,            [rsi+rax*2]
-        movq        mm5,            [rsi+rax*2+8]
-
-        lea         rsi,            [rsi+rax*2]
-        add         rsi,            rax
-
-        movq        [rdi],          mm0
-        movq        [rdi+8],        mm3
-
-        movq        [rdi+rcx],      mm1
-        movq        [rdi+rcx+8],    mm4
-
-        movq        [rdi+rcx*2],    mm2
-        movq        [rdi+rcx*2+8],  mm5
-
-        lea         rdi,            [rdi+rcx*2]
-        add         rdi,            rcx
-
-        movq        mm0,            [rsi]
-        movq        mm3,            [rsi+8];
-
-        movq        [rdi],          mm0
-        movq        [rdi+8],        mm3
-
-    ; begin epilog
-    pop rdi
-    pop rsi
-    UNSHADOW_ARGS
-    pop         rbp
-    ret
diff --git a/vp8/common/x86/recon_sse2.asm b/vp8/common/x86/recon_sse2.asm
deleted file mode 100644 (file)
index cb89537..0000000
+++ /dev/null
@@ -1,116 +0,0 @@
-;
-;  Copyright (c) 2010 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.
-;
-
-
-%include "vpx_ports/x86_abi_support.asm"
-
-;void copy_mem16x16_sse2(
-;    unsigned char *src,
-;    int src_stride,
-;    unsigned char *dst,
-;    int dst_stride
-;    )
-global sym(vp8_copy_mem16x16_sse2) PRIVATE
-sym(vp8_copy_mem16x16_sse2):
-    push        rbp
-    mov         rbp, rsp
-    SHADOW_ARGS_TO_STACK 4
-    push        rsi
-    push        rdi
-    ; end prolog
-
-        mov         rsi,        arg(0) ;src;
-        movdqu      xmm0,       [rsi]
-
-        movsxd      rax,        dword ptr arg(1) ;src_stride;
-        mov         rdi,        arg(2) ;dst;
-
-        movdqu      xmm1,       [rsi+rax]
-        movdqu      xmm2,       [rsi+rax*2]
-
-        movsxd      rcx,        dword ptr arg(3) ;dst_stride
-        lea         rsi,        [rsi+rax*2]
-
-        movdqa      [rdi],      xmm0
-        add         rsi,        rax
-
-        movdqa      [rdi+rcx],  xmm1
-        movdqa      [rdi+rcx*2],xmm2
-
-        lea         rdi,        [rdi+rcx*2]
-        movdqu      xmm3,       [rsi]
-
-        add         rdi,        rcx
-        movdqu      xmm4,       [rsi+rax]
-
-        movdqu      xmm5,       [rsi+rax*2]
-        lea         rsi,        [rsi+rax*2]
-
-        movdqa      [rdi],  xmm3
-        add         rsi,        rax
-
-        movdqa      [rdi+rcx],  xmm4
-        movdqa      [rdi+rcx*2],xmm5
-
-        lea         rdi,        [rdi+rcx*2]
-        movdqu      xmm0,       [rsi]
-
-        add         rdi,        rcx
-        movdqu      xmm1,       [rsi+rax]
-
-        movdqu      xmm2,       [rsi+rax*2]
-        lea         rsi,        [rsi+rax*2]
-
-        movdqa      [rdi],      xmm0
-        add         rsi,        rax
-
-        movdqa      [rdi+rcx],  xmm1
-
-        movdqa      [rdi+rcx*2],    xmm2
-        movdqu      xmm3,       [rsi]
-
-        movdqu      xmm4,       [rsi+rax]
-        lea         rdi,        [rdi+rcx*2]
-
-        add         rdi,        rcx
-        movdqu      xmm5,       [rsi+rax*2]
-
-        lea         rsi,        [rsi+rax*2]
-        movdqa      [rdi],  xmm3
-
-        add         rsi,        rax
-        movdqa      [rdi+rcx],  xmm4
-
-        movdqa      [rdi+rcx*2],xmm5
-        movdqu      xmm0,       [rsi]
-
-        lea         rdi,        [rdi+rcx*2]
-        movdqu      xmm1,       [rsi+rax]
-
-        add         rdi,        rcx
-        movdqu      xmm2,       [rsi+rax*2]
-
-        lea         rsi,        [rsi+rax*2]
-        movdqa      [rdi],      xmm0
-
-        movdqa      [rdi+rcx],  xmm1
-        movdqa      [rdi+rcx*2],xmm2
-
-        movdqu      xmm3,       [rsi+rax]
-        lea         rdi,        [rdi+rcx*2]
-
-        movdqa      [rdi+rcx],  xmm3
-
-    ; begin epilog
-    pop rdi
-    pop rsi
-    UNSHADOW_ARGS
-    pop         rbp
-    ret
diff --git a/vp8/common/x86/subpixel_mmx.asm b/vp8/common/x86/subpixel_mmx.asm
deleted file mode 100644 (file)
index 47dd452..0000000
+++ /dev/null
@@ -1,702 +0,0 @@
-;
-;  Copyright (c) 2010 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.
-;
-
-
-%include "vpx_ports/x86_abi_support.asm"
-extern sym(vp8_bilinear_filters_x86_8)
-
-
-%define BLOCK_HEIGHT_WIDTH 4
-%define vp8_filter_weight 128
-%define VP8_FILTER_SHIFT  7
-
-
-;void vp8_filter_block1d_h6_mmx
-;(
-;    unsigned char   *src_ptr,
-;    unsigned short  *output_ptr,
-;    unsigned int    src_pixels_per_line,
-;    unsigned int    pixel_step,
-;    unsigned int    output_height,
-;    unsigned int    output_width,
-;    short           * vp8_filter
-;)
-global sym(vp8_filter_block1d_h6_mmx) PRIVATE
-sym(vp8_filter_block1d_h6_mmx):
-    push        rbp
-    mov         rbp, rsp
-    SHADOW_ARGS_TO_STACK 7
-    GET_GOT     rbx
-    push        rsi
-    push        rdi
-    ; end prolog
-
-        mov         rdx,    arg(6) ;vp8_filter
-
-        movq        mm1,    [rdx + 16]             ; do both the negative taps first!!!
-        movq        mm2,    [rdx + 32]         ;
-        movq        mm6,    [rdx + 48]        ;
-        movq        mm7,    [rdx + 64]        ;
-
-        mov         rdi,    arg(1) ;output_ptr
-        mov         rsi,    arg(0) ;src_ptr
-        movsxd      rcx,    dword ptr arg(4) ;output_height
-        movsxd      rax,    dword ptr arg(5) ;output_width      ; destination pitch?
-        pxor        mm0,    mm0              ; mm0 = 00000000
-
-.nextrow:
-        movq        mm3,    [rsi-2]          ; mm3 = p-2..p5
-        movq        mm4,    mm3              ; mm4 = p-2..p5
-        psrlq       mm3,    8                ; mm3 = p-1..p5
-        punpcklbw   mm3,    mm0              ; mm3 = p-1..p2
-        pmullw      mm3,    mm1              ; mm3 *= kernel 1 modifiers.
-
-        movq        mm5,    mm4              ; mm5 = p-2..p5
-        punpckhbw   mm4,    mm0              ; mm5 = p2..p5
-        pmullw      mm4,    mm7              ; mm5 *= kernel 4 modifiers
-        paddsw      mm3,    mm4              ; mm3 += mm5
-
-        movq        mm4,    mm5              ; mm4 = p-2..p5;
-        psrlq       mm5,    16               ; mm5 = p0..p5;
-        punpcklbw   mm5,    mm0              ; mm5 = p0..p3
-        pmullw      mm5,    mm2              ; mm5 *= kernel 2 modifiers
-        paddsw      mm3,    mm5              ; mm3 += mm5
-
-        movq        mm5,    mm4              ; mm5 = p-2..p5
-        psrlq       mm4,    24               ; mm4 = p1..p5
-        punpcklbw   mm4,    mm0              ; mm4 = p1..p4
-        pmullw      mm4,    mm6              ; mm5 *= kernel 3 modifiers
-        paddsw      mm3,    mm4              ; mm3 += mm5
-
-        ; do outer positive taps
-        movd        mm4,    [rsi+3]
-        punpcklbw   mm4,    mm0              ; mm5 = p3..p6
-        pmullw      mm4,    [rdx+80]         ; mm5 *= kernel 0 modifiers
-        paddsw      mm3,    mm4              ; mm3 += mm5
-
-        punpcklbw   mm5,    mm0              ; mm5 = p-2..p1
-        pmullw      mm5,    [rdx]            ; mm5 *= kernel 5 modifiers
-        paddsw      mm3,    mm5              ; mm3 += mm5
-
-        paddsw      mm3,    [GLOBAL(rd)]              ; mm3 += round value
-        psraw       mm3,    VP8_FILTER_SHIFT     ; mm3 /= 128
-        packuswb    mm3,    mm0              ; pack and unpack to saturate
-        punpcklbw   mm3,    mm0              ;
-
-        movq        [rdi],  mm3              ; store the results in the destination
-
-%if ABI_IS_32BIT
-        add         rsi,    dword ptr arg(2) ;src_pixels_per_line ; next line
-        add         rdi,    rax;
-%else
-        movsxd      r8,     dword ptr arg(2) ;src_pixels_per_line
-        add         rdi,    rax;
-
-        add         rsi,    r8               ; next line
-%endif
-
-        dec         rcx                      ; decrement count
-        jnz         .nextrow                 ; next row
-
-    ; begin epilog
-    pop rdi
-    pop rsi
-    RESTORE_GOT
-    UNSHADOW_ARGS
-    pop         rbp
-    ret
-
-
-;void vp8_filter_block1dc_v6_mmx
-;(
-;   short *src_ptr,
-;   unsigned char *output_ptr,
-;    int output_pitch,
-;   unsigned int pixels_per_line,
-;   unsigned int pixel_step,
-;   unsigned int output_height,
-;   unsigned int output_width,
-;   short * vp8_filter
-;)
-global sym(vp8_filter_block1dc_v6_mmx) PRIVATE
-sym(vp8_filter_block1dc_v6_mmx):
-    push        rbp
-    mov         rbp, rsp
-    SHADOW_ARGS_TO_STACK 8
-    GET_GOT     rbx
-    push        rsi
-    push        rdi
-    ; end prolog
-
-        movq      mm5, [GLOBAL(rd)]
-        push        rbx
-        mov         rbx, arg(7) ;vp8_filter
-        movq      mm1, [rbx + 16]             ; do both the negative taps first!!!
-        movq      mm2, [rbx + 32]         ;
-        movq      mm6, [rbx + 48]        ;
-        movq      mm7, [rbx + 64]        ;
-
-        movsxd      rdx, dword ptr arg(3) ;pixels_per_line
-        mov         rdi, arg(1) ;output_ptr
-        mov         rsi, arg(0) ;src_ptr
-        sub         rsi, rdx
-        sub         rsi, rdx
-        movsxd      rcx, DWORD PTR arg(5) ;output_height
-        movsxd      rax, DWORD PTR arg(2) ;output_pitch      ; destination pitch?
-        pxor        mm0, mm0              ; mm0 = 00000000
-
-
-.nextrow_cv:
-        movq        mm3, [rsi+rdx]        ; mm3 = p0..p8  = row -1
-        pmullw      mm3, mm1              ; mm3 *= kernel 1 modifiers.
-
-
-        movq        mm4, [rsi + 4*rdx]      ; mm4 = p0..p3  = row 2
-        pmullw      mm4, mm7              ; mm4 *= kernel 4 modifiers.
-        paddsw      mm3, mm4              ; mm3 += mm4
-
-        movq        mm4, [rsi + 2*rdx]           ; mm4 = p0..p3  = row 0
-        pmullw      mm4, mm2              ; mm4 *= kernel 2 modifiers.
-        paddsw      mm3, mm4              ; mm3 += mm4
-
-        movq        mm4, [rsi]            ; mm4 = p0..p3  = row -2
-        pmullw      mm4, [rbx]            ; mm4 *= kernel 0 modifiers.
-        paddsw      mm3, mm4              ; mm3 += mm4
-
-
-        add         rsi, rdx              ; move source forward 1 line to avoid 3 * pitch
-        movq        mm4, [rsi + 2*rdx]     ; mm4 = p0..p3  = row 1
-        pmullw      mm4, mm6              ; mm4 *= kernel 3 modifiers.
-        paddsw      mm3, mm4              ; mm3 += mm4
-
-        movq        mm4, [rsi + 4*rdx]    ; mm4 = p0..p3  = row 3
-        pmullw      mm4, [rbx +80]        ; mm4 *= kernel 3 modifiers.
-        paddsw      mm3, mm4              ; mm3 += mm4
-
-
-        paddsw      mm3, mm5               ; mm3 += round value
-        psraw       mm3, VP8_FILTER_SHIFT     ; mm3 /= 128
-        packuswb    mm3, mm0              ; pack and saturate
-
-        movd        [rdi],mm3             ; store the results in the destination
-        ; the subsequent iterations repeat 3 out of 4 of these reads.  Since the
-        ; recon block should be in cache this shouldn't cost much.  Its obviously
-        ; avoidable!!!.
-        lea         rdi,  [rdi+rax] ;
-        dec         rcx                   ; decrement count
-        jnz         .nextrow_cv           ; next row
-
-        pop         rbx
-
-    ; begin epilog
-    pop rdi
-    pop rsi
-    RESTORE_GOT
-    UNSHADOW_ARGS
-    pop         rbp
-    ret
-
-
-;void bilinear_predict8x8_mmx
-;(
-;    unsigned char  *src_ptr,
-;    int   src_pixels_per_line,
-;    int  xoffset,
-;    int  yoffset,
-;   unsigned char *dst_ptr,
-;    int dst_pitch
-;)
-global sym(vp8_bilinear_predict8x8_mmx) PRIVATE
-sym(vp8_bilinear_predict8x8_mmx):
-    push        rbp
-    mov         rbp, rsp
-    SHADOW_ARGS_TO_STACK 6
-    GET_GOT     rbx
-    push        rsi
-    push        rdi
-    ; end prolog
-
-    ;const short *HFilter = vp8_bilinear_filters_x86_8[xoffset];
-    ;const short *VFilter = vp8_bilinear_filters_x86_8[yoffset];
-
-        movsxd      rax,        dword ptr arg(2) ;xoffset
-        mov         rdi,        arg(4) ;dst_ptr           ;
-
-        shl         rax,        5 ; offset * 32
-        lea         rcx,        [GLOBAL(sym(vp8_bilinear_filters_x86_8))]
-
-        add         rax,        rcx ; HFilter
-        mov         rsi,        arg(0) ;src_ptr              ;
-
-        movsxd      rdx,        dword ptr arg(5) ;dst_pitch
-        movq        mm1,        [rax]               ;
-
-        movq        mm2,        [rax+16]            ;
-        movsxd      rax,        dword ptr arg(3) ;yoffset
-
-        pxor        mm0,        mm0                 ;
-
-        shl         rax,        5 ; offset*32
-        add         rax,        rcx ; VFilter
-
-        lea         rcx,        [rdi+rdx*8]          ;
-        movsxd      rdx,        dword ptr arg(1) ;src_pixels_per_line    ;
-
-
-
-        ; get the first horizontal line done       ;
-        movq        mm3,        [rsi]               ; xx 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14
-        movq        mm4,        mm3                 ; make a copy of current line
-
-        punpcklbw   mm3,        mm0                 ; xx 00 01 02 03 04 05 06
-        punpckhbw   mm4,        mm0                 ;
-
-        pmullw      mm3,        mm1                 ;
-        pmullw      mm4,        mm1                 ;
-
-        movq        mm5,        [rsi+1]             ;
-        movq        mm6,        mm5                 ;
-
-        punpcklbw   mm5,        mm0                 ;
-        punpckhbw   mm6,        mm0                 ;
-
-        pmullw      mm5,        mm2                 ;
-        pmullw      mm6,        mm2                 ;
-
-        paddw       mm3,        mm5                 ;
-        paddw       mm4,        mm6                 ;
-
-        paddw       mm3,        [GLOBAL(rd)]                 ; xmm3 += round value
-        psraw       mm3,        VP8_FILTER_SHIFT        ; xmm3 /= 128
-
-        paddw       mm4,        [GLOBAL(rd)]                 ;
-        psraw       mm4,        VP8_FILTER_SHIFT        ;
-
-        movq        mm7,        mm3                 ;
-        packuswb    mm7,        mm4                 ;
-
-        add         rsi,        rdx                 ; next line
-.next_row_8x8:
-        movq        mm3,        [rsi]               ; xx 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14
-        movq        mm4,        mm3                 ; make a copy of current line
-
-        punpcklbw   mm3,        mm0                 ; xx 00 01 02 03 04 05 06
-        punpckhbw   mm4,        mm0                 ;
-
-        pmullw      mm3,        mm1                 ;
-        pmullw      mm4,        mm1                 ;
-
-        movq        mm5,        [rsi+1]             ;
-        movq        mm6,        mm5                 ;
-
-        punpcklbw   mm5,        mm0                 ;
-        punpckhbw   mm6,        mm0                 ;
-
-        pmullw      mm5,        mm2                 ;
-        pmullw      mm6,        mm2                 ;
-
-        paddw       mm3,        mm5                 ;
-        paddw       mm4,        mm6                 ;
-
-        movq        mm5,        mm7                 ;
-        movq        mm6,        mm7                 ;
-
-        punpcklbw   mm5,        mm0                 ;
-        punpckhbw   mm6,        mm0
-
-        pmullw      mm5,        [rax]               ;
-        pmullw      mm6,        [rax]               ;
-
-        paddw       mm3,        [GLOBAL(rd)]                 ; xmm3 += round value
-        psraw       mm3,        VP8_FILTER_SHIFT        ; xmm3 /= 128
-
-        paddw       mm4,        [GLOBAL(rd)]                 ;
-        psraw       mm4,        VP8_FILTER_SHIFT        ;
-
-        movq        mm7,        mm3                 ;
-        packuswb    mm7,        mm4                 ;
-
-
-        pmullw      mm3,        [rax+16]            ;
-        pmullw      mm4,        [rax+16]            ;
-
-        paddw       mm3,        mm5                 ;
-        paddw       mm4,        mm6                 ;
-
-
-        paddw       mm3,        [GLOBAL(rd)]                 ; xmm3 += round value
-        psraw       mm3,        VP8_FILTER_SHIFT        ; xmm3 /= 128
-
-        paddw       mm4,        [GLOBAL(rd)]                 ;
-        psraw       mm4,        VP8_FILTER_SHIFT        ;
-
-        packuswb    mm3,        mm4
-
-        movq        [rdi],      mm3                 ; store the results in the destination
-
-%if ABI_IS_32BIT
-        add         rsi,        rdx                 ; next line
-        add         rdi,        dword ptr arg(5) ;dst_pitch                   ;
-%else
-        movsxd      r8,         dword ptr arg(5) ;dst_pitch
-        add         rsi,        rdx                 ; next line
-        add         rdi,        r8                  ;dst_pitch
-%endif
-        cmp         rdi,        rcx                 ;
-        jne         .next_row_8x8
-
-    ; begin epilog
-    pop rdi
-    pop rsi
-    RESTORE_GOT
-    UNSHADOW_ARGS
-    pop         rbp
-    ret
-
-
-;void bilinear_predict8x4_mmx
-;(
-;    unsigned char  *src_ptr,
-;    int   src_pixels_per_line,
-;    int  xoffset,
-;    int  yoffset,
-;    unsigned char *dst_ptr,
-;    int dst_pitch
-;)
-global sym(vp8_bilinear_predict8x4_mmx) PRIVATE
-sym(vp8_bilinear_predict8x4_mmx):
-    push        rbp
-    mov         rbp, rsp
-    SHADOW_ARGS_TO_STACK 6
-    GET_GOT     rbx
-    push        rsi
-    push        rdi
-    ; end prolog
-
-    ;const short *HFilter = vp8_bilinear_filters_x86_8[xoffset];
-    ;const short *VFilter = vp8_bilinear_filters_x86_8[yoffset];
-
-        movsxd      rax,        dword ptr arg(2) ;xoffset
-        mov         rdi,        arg(4) ;dst_ptr           ;
-
-        lea         rcx,        [GLOBAL(sym(vp8_bilinear_filters_x86_8))]
-        shl         rax,        5
-
-        mov         rsi,        arg(0) ;src_ptr              ;
-        add         rax,        rcx
-
-        movsxd      rdx,        dword ptr arg(5) ;dst_pitch
-        movq        mm1,        [rax]               ;
-
-        movq        mm2,        [rax+16]            ;
-        movsxd      rax,        dword ptr arg(3) ;yoffset
-
-        pxor        mm0,        mm0                 ;
-        shl         rax,        5
-
-        add         rax,        rcx
-        lea         rcx,        [rdi+rdx*4]          ;
-
-        movsxd      rdx,        dword ptr arg(1) ;src_pixels_per_line    ;
-
-        ; get the first horizontal line done       ;
-        movq        mm3,        [rsi]               ; xx 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14
-        movq        mm4,        mm3                 ; make a copy of current line
-
-        punpcklbw   mm3,        mm0                 ; xx 00 01 02 03 04 05 06
-        punpckhbw   mm4,        mm0                 ;
-
-        pmullw      mm3,        mm1                 ;
-        pmullw      mm4,        mm1                 ;
-
-        movq        mm5,        [rsi+1]             ;
-        movq        mm6,        mm5                 ;
-
-        punpcklbw   mm5,        mm0                 ;
-        punpckhbw   mm6,        mm0                 ;
-
-        pmullw      mm5,        mm2                 ;
-        pmullw      mm6,        mm2                 ;
-
-        paddw       mm3,        mm5                 ;
-        paddw       mm4,        mm6                 ;
-
-        paddw       mm3,        [GLOBAL(rd)]                 ; xmm3 += round value
-        psraw       mm3,        VP8_FILTER_SHIFT        ; xmm3 /= 128
-
-        paddw       mm4,        [GLOBAL(rd)]                 ;
-        psraw       mm4,        VP8_FILTER_SHIFT        ;
-
-        movq        mm7,        mm3                 ;
-        packuswb    mm7,        mm4                 ;
-
-        add         rsi,        rdx                 ; next line
-.next_row_8x4:
-        movq        mm3,        [rsi]               ; xx 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14
-        movq        mm4,        mm3                 ; make a copy of current line
-
-        punpcklbw   mm3,        mm0                 ; xx 00 01 02 03 04 05 06
-        punpckhbw   mm4,        mm0                 ;
-
-        pmullw      mm3,        mm1                 ;
-        pmullw      mm4,        mm1                 ;
-
-        movq        mm5,        [rsi+1]             ;
-        movq        mm6,        mm5                 ;
-
-        punpcklbw   mm5,        mm0                 ;
-        punpckhbw   mm6,        mm0                 ;
-
-        pmullw      mm5,        mm2                 ;
-        pmullw      mm6,        mm2                 ;
-
-        paddw       mm3,        mm5                 ;
-        paddw       mm4,        mm6                 ;
-
-        movq        mm5,        mm7                 ;
-        movq        mm6,        mm7                 ;
-
-        punpcklbw   mm5,        mm0                 ;
-        punpckhbw   mm6,        mm0
-
-        pmullw      mm5,        [rax]               ;
-        pmullw      mm6,        [rax]               ;
-
-        paddw       mm3,        [GLOBAL(rd)]                 ; xmm3 += round value
-        psraw       mm3,        VP8_FILTER_SHIFT        ; xmm3 /= 128
-
-        paddw       mm4,        [GLOBAL(rd)]                 ;
-        psraw       mm4,        VP8_FILTER_SHIFT        ;
-
-        movq        mm7,        mm3                 ;
-        packuswb    mm7,        mm4                 ;
-
-
-        pmullw      mm3,        [rax+16]            ;
-        pmullw      mm4,        [rax+16]            ;
-
-        paddw       mm3,        mm5                 ;
-        paddw       mm4,        mm6                 ;
-
-
-        paddw       mm3,        [GLOBAL(rd)]                 ; xmm3 += round value
-        psraw       mm3,        VP8_FILTER_SHIFT        ; xmm3 /= 128
-
-        paddw       mm4,        [GLOBAL(rd)]                 ;
-        psraw       mm4,        VP8_FILTER_SHIFT        ;
-
-        packuswb    mm3,        mm4
-
-        movq        [rdi],      mm3                 ; store the results in the destination
-
-%if ABI_IS_32BIT
-        add         rsi,        rdx                 ; next line
-        add         rdi,        dword ptr arg(5) ;dst_pitch                   ;
-%else
-        movsxd      r8,         dword ptr arg(5) ;dst_pitch
-        add         rsi,        rdx                 ; next line
-        add         rdi,        r8
-%endif
-        cmp         rdi,        rcx                 ;
-        jne         .next_row_8x4
-
-    ; begin epilog
-    pop rdi
-    pop rsi
-    RESTORE_GOT
-    UNSHADOW_ARGS
-    pop         rbp
-    ret
-
-
-;void bilinear_predict4x4_mmx
-;(
-;    unsigned char  *src_ptr,
-;    int   src_pixels_per_line,
-;    int  xoffset,
-;    int  yoffset,
-;    unsigned char *dst_ptr,
-;    int dst_pitch
-;)
-global sym(vp8_bilinear_predict4x4_mmx) PRIVATE
-sym(vp8_bilinear_predict4x4_mmx):
-    push        rbp
-    mov         rbp, rsp
-    SHADOW_ARGS_TO_STACK 6
-    GET_GOT     rbx
-    push        rsi
-    push        rdi
-    ; end prolog
-
-    ;const short *HFilter = vp8_bilinear_filters_x86_8[xoffset];
-    ;const short *VFilter = vp8_bilinear_filters_x86_8[yoffset];
-
-        movsxd      rax,        dword ptr arg(2) ;xoffset
-        mov         rdi,        arg(4) ;dst_ptr           ;
-
-        lea         rcx,        [GLOBAL(sym(vp8_bilinear_filters_x86_8))]
-        shl         rax,        5
-
-        add         rax,        rcx ; HFilter
-        mov         rsi,        arg(0) ;src_ptr              ;
-
-        movsxd      rdx,        dword ptr arg(5) ;ldst_pitch
-        movq        mm1,        [rax]               ;
-
-        movq        mm2,        [rax+16]            ;
-        movsxd      rax,        dword ptr arg(3) ;yoffset
-
-        pxor        mm0,        mm0                 ;
-        shl         rax,        5
-
-        add         rax,        rcx
-        lea         rcx,        [rdi+rdx*4]          ;
-
-        movsxd      rdx,        dword ptr arg(1) ;src_pixels_per_line    ;
-
-        ; get the first horizontal line done       ;
-        movd        mm3,        [rsi]               ; xx 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14
-        punpcklbw   mm3,        mm0                 ; xx 00 01 02 03 04 05 06
-
-        pmullw      mm3,        mm1                 ;
-        movd        mm5,        [rsi+1]             ;
-
-        punpcklbw   mm5,        mm0                 ;
-        pmullw      mm5,        mm2                 ;
-
-        paddw       mm3,        mm5                 ;
-        paddw       mm3,        [GLOBAL(rd)]                 ; xmm3 += round value
-
-        psraw       mm3,        VP8_FILTER_SHIFT        ; xmm3 /= 128
-
-        movq        mm7,        mm3                 ;
-        packuswb    mm7,        mm0                 ;
-
-        add         rsi,        rdx                 ; next line
-.next_row_4x4:
-        movd        mm3,        [rsi]               ; xx 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14
-        punpcklbw   mm3,        mm0                 ; xx 00 01 02 03 04 05 06
-
-        pmullw      mm3,        mm1                 ;
-        movd        mm5,        [rsi+1]             ;
-
-        punpcklbw   mm5,        mm0                 ;
-        pmullw      mm5,        mm2                 ;
-
-        paddw       mm3,        mm5                 ;
-
-        movq        mm5,        mm7                 ;
-        punpcklbw   mm5,        mm0                 ;
-
-        pmullw      mm5,        [rax]               ;
-        paddw       mm3,        [GLOBAL(rd)]                 ; xmm3 += round value
-
-        psraw       mm3,        VP8_FILTER_SHIFT        ; xmm3 /= 128
-        movq        mm7,        mm3                 ;
-
-        packuswb    mm7,        mm0                 ;
-
-        pmullw      mm3,        [rax+16]            ;
-        paddw       mm3,        mm5                 ;
-
-
-        paddw       mm3,        [GLOBAL(rd)]                 ; xmm3 += round value
-        psraw       mm3,        VP8_FILTER_SHIFT        ; xmm3 /= 128
-
-        packuswb    mm3,        mm0
-        movd        [rdi],      mm3                 ; store the results in the destination
-
-%if ABI_IS_32BIT
-        add         rsi,        rdx                 ; next line
-        add         rdi,        dword ptr arg(5) ;dst_pitch                   ;
-%else
-        movsxd      r8,         dword ptr arg(5) ;dst_pitch                   ;
-        add         rsi,        rdx                 ; next line
-        add         rdi,        r8
-%endif
-
-        cmp         rdi,        rcx                 ;
-        jne         .next_row_4x4
-
-    ; begin epilog
-    pop rdi
-    pop rsi
-    RESTORE_GOT
-    UNSHADOW_ARGS
-    pop         rbp
-    ret
-
-
-
-SECTION_RODATA
-align 16
-rd:
-    times 4 dw 0x40
-
-align 16
-global HIDDEN_DATA(sym(vp8_six_tap_mmx))
-sym(vp8_six_tap_mmx):
-    times 8 dw 0
-    times 8 dw 0
-    times 8 dw 128
-    times 8 dw 0
-    times 8 dw 0
-    times 8 dw 0
-
-    times 8 dw 0
-    times 8 dw -6
-    times 8 dw 123
-    times 8 dw 12
-    times 8 dw -1
-    times 8 dw 0
-
-    times 8 dw 2
-    times 8 dw -11
-    times 8 dw 108
-    times 8 dw 36
-    times 8 dw -8
-    times 8 dw 1
-
-    times 8 dw 0
-    times 8 dw -9
-    times 8 dw 93
-    times 8 dw 50
-    times 8 dw -6
-    times 8 dw 0
-
-    times 8 dw 3
-    times 8 dw -16
-    times 8 dw 77
-    times 8 dw 77
-    times 8 dw -16
-    times 8 dw 3
-
-    times 8 dw 0
-    times 8 dw -6
-    times 8 dw 50
-    times 8 dw 93
-    times 8 dw -9
-    times 8 dw 0
-
-    times 8 dw 1
-    times 8 dw -8
-    times 8 dw 36
-    times 8 dw 108
-    times 8 dw -11
-    times 8 dw 2
-
-    times 8 dw 0
-    times 8 dw -1
-    times 8 dw 12
-    times 8 dw 123
-    times 8 dw -6
-    times 8 dw 0
-
-
diff --git a/vp8/common/x86/subpixel_sse2.asm b/vp8/common/x86/subpixel_sse2.asm
deleted file mode 100644 (file)
index 69f8d10..0000000
+++ /dev/null
@@ -1,1372 +0,0 @@
-;
-;  Copyright (c) 2010 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.
-;
-
-
-%include "vpx_ports/x86_abi_support.asm"
-extern sym(vp8_bilinear_filters_x86_8)
-
-%define BLOCK_HEIGHT_WIDTH 4
-%define VP8_FILTER_WEIGHT 128
-%define VP8_FILTER_SHIFT  7
-
-
-;/************************************************************************************
-; Notes: filter_block1d_h6 applies a 6 tap filter horizontally to the input pixels. The
-; input pixel array has output_height rows. This routine assumes that output_height is an
-; even number. This function handles 8 pixels in horizontal direction, calculating ONE
-; rows each iteration to take advantage of the 128 bits operations.
-;*************************************************************************************/
-;void vp8_filter_block1d8_h6_sse2
-;(
-;    unsigned char  *src_ptr,
-;    unsigned short *output_ptr,
-;    unsigned int    src_pixels_per_line,
-;    unsigned int    pixel_step,
-;    unsigned int    output_height,
-;    unsigned int    output_width,
-;    short           *vp8_filter
-;)
-global sym(vp8_filter_block1d8_h6_sse2) PRIVATE
-sym(vp8_filter_block1d8_h6_sse2):
-    push        rbp
-    mov         rbp, rsp
-    SHADOW_ARGS_TO_STACK 7
-    SAVE_XMM 7
-    GET_GOT     rbx
-    push        rsi
-    push        rdi
-    ; end prolog
-
-        mov         rdx,        arg(6) ;vp8_filter
-        mov         rsi,        arg(0) ;src_ptr
-
-        mov         rdi,        arg(1) ;output_ptr
-
-        movsxd      rcx,        dword ptr arg(4) ;output_height
-        movsxd      rax,        dword ptr arg(2) ;src_pixels_per_line            ; Pitch for Source
-%if ABI_IS_32BIT=0
-        movsxd      r8,         dword ptr arg(5) ;output_width
-%endif
-        pxor        xmm0,       xmm0                        ; clear xmm0 for unpack
-
-.filter_block1d8_h6_rowloop:
-        movq        xmm3,       MMWORD PTR [rsi - 2]
-        movq        xmm1,       MMWORD PTR [rsi + 6]
-
-        prefetcht2  [rsi+rax-2]
-
-        pslldq      xmm1,       8
-        por         xmm1,       xmm3
-
-        movdqa      xmm4,       xmm1
-        movdqa      xmm5,       xmm1
-
-        movdqa      xmm6,       xmm1
-        movdqa      xmm7,       xmm1
-
-        punpcklbw   xmm3,       xmm0                        ; xx05 xx04 xx03 xx02 xx01 xx01 xx-1 xx-2
-        psrldq      xmm4,       1                           ; xx 0d 0c 0b 0a 09 08 07 06 05 04 03 02 01 00 -1
-
-        pmullw      xmm3,       XMMWORD PTR [rdx]           ; x[-2] * H[-2]; Tap 1
-        punpcklbw   xmm4,       xmm0                        ; xx06 xx05 xx04 xx03 xx02 xx01 xx00 xx-1
-
-        psrldq      xmm5,       2                           ; xx xx 0d 0c 0b 0a 09 08 07 06 05 04 03 02 01 00
-        pmullw      xmm4,       XMMWORD PTR [rdx+16]        ; x[-1] * H[-1]; Tap 2
-
-
-        punpcklbw   xmm5,       xmm0                        ; xx07 xx06 xx05 xx04 xx03 xx02 xx01 xx00
-        psrldq      xmm6,       3                           ; xx xx xx 0d 0c 0b 0a 09 08 07 06 05 04 03 02 01
-
-        pmullw      xmm5,       [rdx+32]                    ; x[ 0] * H[ 0]; Tap 3
-
-        punpcklbw   xmm6,       xmm0                        ; xx08 xx07 xx06 xx05 xx04 xx03 xx02 xx01
-        psrldq      xmm7,       4                           ; xx xx xx xx 0d 0c 0b 0a 09 08 07 06 05 04 03 02
-
-        pmullw      xmm6,       [rdx+48]                    ; x[ 1] * h[ 1] ; Tap 4
-
-        punpcklbw   xmm7,       xmm0                        ; xx09 xx08 xx07 xx06 xx05 xx04 xx03 xx02
-        psrldq      xmm1,       5                           ; xx xx xx xx xx 0d 0c 0b 0a 09 08 07 06 05 04 03
-
-
-        pmullw      xmm7,       [rdx+64]                    ; x[ 2] * h[ 2] ; Tap 5
-
-        punpcklbw   xmm1,       xmm0                        ; xx0a xx09 xx08 xx07 xx06 xx05 xx04 xx03
-        pmullw      xmm1,       [rdx+80]                    ; x[ 3] * h[ 3] ; Tap 6
-
-
-        paddsw      xmm4,       xmm7
-        paddsw      xmm4,       xmm5
-
-        paddsw      xmm4,       xmm3
-        paddsw      xmm4,       xmm6
-
-        paddsw      xmm4,       xmm1
-        paddsw      xmm4,       [GLOBAL(rd)]
-
-        psraw       xmm4,       7
-
-        packuswb    xmm4,       xmm0
-        punpcklbw   xmm4,       xmm0
-
-        movdqa      XMMWORD Ptr [rdi],         xmm4
-        lea         rsi,        [rsi + rax]
-
-%if ABI_IS_32BIT
-        add         rdi,        DWORD Ptr arg(5) ;[output_width]
-%else
-        add         rdi,        r8
-%endif
-        dec         rcx
-
-        jnz         .filter_block1d8_h6_rowloop                ; next row
-
-    ; begin epilog
-    pop rdi
-    pop rsi
-    RESTORE_GOT
-    RESTORE_XMM
-    UNSHADOW_ARGS
-    pop         rbp
-    ret
-
-
-;void vp8_filter_block1d16_h6_sse2
-;(
-;    unsigned char  *src_ptr,
-;    unsigned short *output_ptr,
-;    unsigned int    src_pixels_per_line,
-;    unsigned int    pixel_step,
-;    unsigned int    output_height,
-;    unsigned int    output_width,
-;    short           *vp8_filter
-;)
-;/************************************************************************************
-; Notes: filter_block1d_h6 applies a 6 tap filter horizontally to the input pixels. The
-; input pixel array has output_height rows. This routine assumes that output_height is an
-; even number. This function handles 8 pixels in horizontal direction, calculating ONE
-; rows each iteration to take advantage of the 128 bits operations.
-;*************************************************************************************/
-global sym(vp8_filter_block1d16_h6_sse2) PRIVATE
-sym(vp8_filter_block1d16_h6_sse2):
-    push        rbp
-    mov         rbp, rsp
-    SHADOW_ARGS_TO_STACK 7
-    SAVE_XMM 7
-    GET_GOT     rbx
-    push        rsi
-    push        rdi
-    ; end prolog
-
-        mov         rdx,        arg(6) ;vp8_filter
-        mov         rsi,        arg(0) ;src_ptr
-
-        mov         rdi,        arg(1) ;output_ptr
-
-        movsxd      rcx,        dword ptr arg(4) ;output_height
-        movsxd      rax,        dword ptr arg(2) ;src_pixels_per_line            ; Pitch for Source
-%if ABI_IS_32BIT=0
-        movsxd      r8,         dword ptr arg(5) ;output_width
-%endif
-
-        pxor        xmm0,       xmm0                        ; clear xmm0 for unpack
-
-.filter_block1d16_h6_sse2_rowloop:
-        movq        xmm3,       MMWORD PTR [rsi - 2]
-        movq        xmm1,       MMWORD PTR [rsi + 6]
-
-        movq        xmm2,       MMWORD PTR [rsi +14]
-        pslldq      xmm2,       8
-
-        por         xmm2,       xmm1
-        prefetcht2  [rsi+rax-2]
-
-        pslldq      xmm1,       8
-        por         xmm1,       xmm3
-
-        movdqa      xmm4,       xmm1
-        movdqa      xmm5,       xmm1
-
-        movdqa      xmm6,       xmm1
-        movdqa      xmm7,       xmm1
-
-        punpcklbw   xmm3,       xmm0                        ; xx05 xx04 xx03 xx02 xx01 xx01 xx-1 xx-2
-        psrldq      xmm4,       1                           ; xx 0d 0c 0b 0a 09 08 07 06 05 04 03 02 01 00 -1
-
-        pmullw      xmm3,       XMMWORD PTR [rdx]           ; x[-2] * H[-2]; Tap 1
-        punpcklbw   xmm4,       xmm0                        ; xx06 xx05 xx04 xx03 xx02 xx01 xx00 xx-1
-
-        psrldq      xmm5,       2                           ; xx xx 0d 0c 0b 0a 09 08 07 06 05 04 03 02 01 00
-        pmullw      xmm4,       XMMWORD PTR [rdx+16]        ; x[-1] * H[-1]; Tap 2
-
-
-        punpcklbw   xmm5,       xmm0                        ; xx07 xx06 xx05 xx04 xx03 xx02 xx01 xx00
-        psrldq      xmm6,       3                           ; xx xx xx 0d 0c 0b 0a 09 08 07 06 05 04 03 02 01
-
-        pmullw      xmm5,       [rdx+32]                    ; x[ 0] * H[ 0]; Tap 3
-
-        punpcklbw   xmm6,       xmm0                        ; xx08 xx07 xx06 xx05 xx04 xx03 xx02 xx01
-        psrldq      xmm7,       4                           ; xx xx xx xx 0d 0c 0b 0a 09 08 07 06 05 04 03 02
-
-        pmullw      xmm6,       [rdx+48]                    ; x[ 1] * h[ 1] ; Tap 4
-
-        punpcklbw   xmm7,       xmm0                        ; xx09 xx08 xx07 xx06 xx05 xx04 xx03 xx02
-        psrldq      xmm1,       5                           ; xx xx xx xx xx 0d 0c 0b 0a 09 08 07 06 05 04 03
-
-
-        pmullw      xmm7,       [rdx+64]                    ; x[ 2] * h[ 2] ; Tap 5
-
-        punpcklbw   xmm1,       xmm0                        ; xx0a xx09 xx08 xx07 xx06 xx05 xx04 xx03
-        pmullw      xmm1,       [rdx+80]                    ; x[ 3] * h[ 3] ; Tap 6
-
-        paddsw      xmm4,       xmm7
-        paddsw      xmm4,       xmm5
-
-        paddsw      xmm4,       xmm3
-        paddsw      xmm4,       xmm6
-
-        paddsw      xmm4,       xmm1
-        paddsw      xmm4,       [GLOBAL(rd)]
-
-        psraw       xmm4,       7
-
-        packuswb    xmm4,       xmm0
-        punpcklbw   xmm4,       xmm0
-
-        movdqa      XMMWORD Ptr [rdi],         xmm4
-
-        movdqa      xmm3,       xmm2
-        movdqa      xmm4,       xmm2
-
-        movdqa      xmm5,       xmm2
-        movdqa      xmm6,       xmm2
-
-        movdqa      xmm7,       xmm2
-
-        punpcklbw   xmm3,       xmm0                        ; xx05 xx04 xx03 xx02 xx01 xx01 xx-1 xx-2
-        psrldq      xmm4,       1                           ; xx 0d 0c 0b 0a 09 08 07 06 05 04 03 02 01 00 -1
-
-        pmullw      xmm3,       XMMWORD PTR [rdx]           ; x[-2] * H[-2]; Tap 1
-        punpcklbw   xmm4,       xmm0                        ; xx06 xx05 xx04 xx03 xx02 xx01 xx00 xx-1
-
-        psrldq      xmm5,       2                           ; xx xx 0d 0c 0b 0a 09 08 07 06 05 04 03 02 01 00
-        pmullw      xmm4,       XMMWORD PTR [rdx+16]        ; x[-1] * H[-1]; Tap 2
-
-
-        punpcklbw   xmm5,       xmm0                        ; xx07 xx06 xx05 xx04 xx03 xx02 xx01 xx00
-        psrldq      xmm6,       3                           ; xx xx xx 0d 0c 0b 0a 09 08 07 06 05 04 03 02 01
-
-        pmullw      xmm5,       [rdx+32]                    ; x[ 0] * H[ 0]; Tap 3
-
-        punpcklbw   xmm6,       xmm0                        ; xx08 xx07 xx06 xx05 xx04 xx03 xx02 xx01
-        psrldq      xmm7,       4                           ; xx xx xx xx 0d 0c 0b 0a 09 08 07 06 05 04 03 02
-
-        pmullw      xmm6,       [rdx+48]                    ; x[ 1] * h[ 1] ; Tap 4
-
-        punpcklbw   xmm7,       xmm0                        ; xx09 xx08 xx07 xx06 xx05 xx04 xx03 xx02
-        psrldq      xmm2,       5                           ; xx xx xx xx xx 0d 0c 0b 0a 09 08 07 06 05 04 03
-
-        pmullw      xmm7,       [rdx+64]                    ; x[ 2] * h[ 2] ; Tap 5
-
-        punpcklbw   xmm2,       xmm0                        ; xx0a xx09 xx08 xx07 xx06 xx05 xx04 xx03
-        pmullw      xmm2,       [rdx+80]                    ; x[ 3] * h[ 3] ; Tap 6
-
-
-        paddsw      xmm4,       xmm7
-        paddsw      xmm4,       xmm5
-
-        paddsw      xmm4,       xmm3
-        paddsw      xmm4,       xmm6
-
-        paddsw      xmm4,       xmm2
-        paddsw      xmm4,       [GLOBAL(rd)]
-
-        psraw       xmm4,       7
-
-        packuswb    xmm4,       xmm0
-        punpcklbw   xmm4,       xmm0
-
-        movdqa      XMMWORD Ptr [rdi+16],      xmm4
-
-        lea         rsi,        [rsi + rax]
-%if ABI_IS_32BIT
-        add         rdi,        DWORD Ptr arg(5) ;[output_width]
-%else
-        add         rdi,        r8
-%endif
-
-        dec         rcx
-        jnz         .filter_block1d16_h6_sse2_rowloop                ; next row
-
-    ; begin epilog
-    pop rdi
-    pop rsi
-    RESTORE_GOT
-    RESTORE_XMM
-    UNSHADOW_ARGS
-    pop         rbp
-    ret
-
-
-;void vp8_filter_block1d8_v6_sse2
-;(
-;    short *src_ptr,
-;    unsigned char *output_ptr,
-;    int dst_ptich,
-;    unsigned int pixels_per_line,
-;    unsigned int pixel_step,
-;    unsigned int output_height,
-;    unsigned int output_width,
-;    short * vp8_filter
-;)
-;/************************************************************************************
-; Notes: filter_block1d8_v6 applies a 6 tap filter vertically to the input pixels. The
-; input pixel array has output_height rows.
-;*************************************************************************************/
-global sym(vp8_filter_block1d8_v6_sse2) PRIVATE
-sym(vp8_filter_block1d8_v6_sse2):
-    push        rbp
-    mov         rbp, rsp
-    SHADOW_ARGS_TO_STACK 8
-    SAVE_XMM 7
-    GET_GOT     rbx
-    push        rsi
-    push        rdi
-    ; end prolog
-
-        mov         rax,        arg(7) ;vp8_filter
-        movsxd      rdx,        dword ptr arg(3) ;pixels_per_line
-
-        mov         rdi,        arg(1) ;output_ptr
-        mov         rsi,        arg(0) ;src_ptr
-
-        sub         rsi,        rdx
-        sub         rsi,        rdx
-
-        movsxd      rcx,        DWORD PTR arg(5) ;[output_height]
-        pxor        xmm0,       xmm0                        ; clear xmm0
-
-        movdqa      xmm7,       XMMWORD PTR [GLOBAL(rd)]
-%if ABI_IS_32BIT=0
-        movsxd      r8,         dword ptr arg(2) ; dst_ptich
-%endif
-
-.vp8_filter_block1d8_v6_sse2_loop:
-        movdqa      xmm1,       XMMWORD PTR [rsi]
-        pmullw      xmm1,       [rax]
-
-        movdqa      xmm2,       XMMWORD PTR [rsi + rdx]
-        pmullw      xmm2,       [rax + 16]
-
-        movdqa      xmm3,       XMMWORD PTR [rsi + rdx * 2]
-        pmullw      xmm3,       [rax + 32]
-
-        movdqa      xmm5,       XMMWORD PTR [rsi + rdx * 4]
-        pmullw      xmm5,       [rax + 64]
-
-        add         rsi,        rdx
-        movdqa      xmm4,       XMMWORD PTR [rsi + rdx * 2]
-
-        pmullw      xmm4,       [rax + 48]
-        movdqa      xmm6,       XMMWORD PTR [rsi + rdx * 4]
-
-        pmullw      xmm6,       [rax + 80]
-
-        paddsw      xmm2,       xmm5
-        paddsw      xmm2,       xmm3
-
-        paddsw      xmm2,       xmm1
-        paddsw      xmm2,       xmm4
-
-        paddsw      xmm2,       xmm6
-        paddsw      xmm2,       xmm7
-
-        psraw       xmm2,       7
-        packuswb    xmm2,       xmm0              ; pack and saturate
-
-        movq        QWORD PTR [rdi], xmm2         ; store the results in the destination
-%if ABI_IS_32BIT
-        add         rdi,        DWORD PTR arg(2) ;[dst_ptich]
-%else
-        add         rdi,        r8
-%endif
-        dec         rcx         ; decrement count
-        jnz         .vp8_filter_block1d8_v6_sse2_loop               ; next row
-
-    ; begin epilog
-    pop rdi
-    pop rsi
-    RESTORE_GOT
-    RESTORE_XMM
-    UNSHADOW_ARGS
-    pop         rbp
-    ret
-
-
-;void vp8_filter_block1d16_v6_sse2
-;(
-;    unsigned short *src_ptr,
-;    unsigned char *output_ptr,
-;    int dst_ptich,
-;    unsigned int pixels_per_line,
-;    unsigned int pixel_step,
-;    unsigned int output_height,
-;    unsigned int output_width,
-;    const short    *vp8_filter
-;)
-;/************************************************************************************
-; Notes: filter_block1d16_v6 applies a 6 tap filter vertically to the input pixels. The
-; input pixel array has output_height rows.
-;*************************************************************************************/
-global sym(vp8_filter_block1d16_v6_sse2) PRIVATE
-sym(vp8_filter_block1d16_v6_sse2):
-    push        rbp
-    mov         rbp, rsp
-    SHADOW_ARGS_TO_STACK 8
-    SAVE_XMM 7
-    GET_GOT     rbx
-    push        rsi
-    push        rdi
-    ; end prolog
-
-        mov         rax,        arg(7) ;vp8_filter
-        movsxd      rdx,        dword ptr arg(3) ;pixels_per_line
-
-        mov         rdi,        arg(1) ;output_ptr
-        mov         rsi,        arg(0) ;src_ptr
-
-        sub         rsi,        rdx
-        sub         rsi,        rdx
-
-        movsxd      rcx,        DWORD PTR arg(5) ;[output_height]
-%if ABI_IS_32BIT=0
-        movsxd      r8,         dword ptr arg(2) ; dst_ptich
-%endif
-
-.vp8_filter_block1d16_v6_sse2_loop:
-; The order for adding 6-tap is 2 5 3 1 4 6. Read in data in that order.
-        movdqa      xmm1,       XMMWORD PTR [rsi + rdx]       ; line 2
-        movdqa      xmm2,       XMMWORD PTR [rsi + rdx + 16]
-        pmullw      xmm1,       [rax + 16]
-        pmullw      xmm2,       [rax + 16]
-
-        movdqa      xmm3,       XMMWORD PTR [rsi + rdx * 4]       ; line 5
-        movdqa      xmm4,       XMMWORD PTR [rsi + rdx * 4 + 16]
-        pmullw      xmm3,       [rax + 64]
-        pmullw      xmm4,       [rax + 64]
-
-        movdqa      xmm5,       XMMWORD PTR [rsi + rdx * 2]       ; line 3
-        movdqa      xmm6,       XMMWORD PTR [rsi + rdx * 2 + 16]
-        pmullw      xmm5,       [rax + 32]
-        pmullw      xmm6,       [rax + 32]
-
-        movdqa      xmm7,       XMMWORD PTR [rsi]       ; line 1
-        movdqa      xmm0,       XMMWORD PTR [rsi + 16]
-        pmullw      xmm7,       [rax]
-        pmullw      xmm0,       [rax]
-
-        paddsw      xmm1,       xmm3
-        paddsw      xmm2,       xmm4
-        paddsw      xmm1,       xmm5
-        paddsw      xmm2,       xmm6
-        paddsw      xmm1,       xmm7
-        paddsw      xmm2,       xmm0
-
-        add         rsi,        rdx
-
-        movdqa      xmm3,       XMMWORD PTR [rsi + rdx * 2]       ; line 4
-        movdqa      xmm4,       XMMWORD PTR [rsi + rdx * 2 + 16]
-        pmullw      xmm3,       [rax + 48]
-        pmullw      xmm4,       [rax + 48]
-
-        movdqa      xmm5,       XMMWORD PTR [rsi + rdx * 4]       ; line 6
-        movdqa      xmm6,       XMMWORD PTR [rsi + rdx * 4 + 16]
-        pmullw      xmm5,       [rax + 80]
-        pmullw      xmm6,       [rax + 80]
-
-        movdqa      xmm7,       XMMWORD PTR [GLOBAL(rd)]
-        pxor        xmm0,       xmm0                        ; clear xmm0
-
-        paddsw      xmm1,       xmm3
-        paddsw      xmm2,       xmm4
-        paddsw      xmm1,       xmm5
-        paddsw      xmm2,       xmm6
-
-        paddsw      xmm1,       xmm7
-        paddsw      xmm2,       xmm7
-
-        psraw       xmm1,       7
-        psraw       xmm2,       7
-
-        packuswb    xmm1,       xmm2              ; pack and saturate
-        movdqa      XMMWORD PTR [rdi], xmm1       ; store the results in the destination
-%if ABI_IS_32BIT
-        add         rdi,        DWORD PTR arg(2) ;[dst_ptich]
-%else
-        add         rdi,        r8
-%endif
-        dec         rcx         ; decrement count
-        jnz         .vp8_filter_block1d16_v6_sse2_loop              ; next row
-
-    ; begin epilog
-    pop rdi
-    pop rsi
-    RESTORE_GOT
-    RESTORE_XMM
-    UNSHADOW_ARGS
-    pop         rbp
-    ret
-
-
-;void vp8_filter_block1d8_h6_only_sse2
-;(
-;    unsigned char  *src_ptr,
-;    unsigned int    src_pixels_per_line,
-;    unsigned char  *output_ptr,
-;    int dst_ptich,
-;    unsigned int    output_height,
-;    const short    *vp8_filter
-;)
-; First-pass filter only when yoffset==0
-global sym(vp8_filter_block1d8_h6_only_sse2) PRIVATE
-sym(vp8_filter_block1d8_h6_only_sse2):
-    push        rbp
-    mov         rbp, rsp
-    SHADOW_ARGS_TO_STACK 6
-    SAVE_XMM 7
-    GET_GOT     rbx
-    push        rsi
-    push        rdi
-    ; end prolog
-
-        mov         rdx,        arg(5) ;vp8_filter
-        mov         rsi,        arg(0) ;src_ptr
-
-        mov         rdi,        arg(2) ;output_ptr
-
-        movsxd      rcx,        dword ptr arg(4) ;output_height
-        movsxd      rax,        dword ptr arg(1) ;src_pixels_per_line            ; Pitch for Source
-%if ABI_IS_32BIT=0
-        movsxd      r8,         dword ptr arg(3) ;dst_ptich
-%endif
-        pxor        xmm0,       xmm0                        ; clear xmm0 for unpack
-
-.filter_block1d8_h6_only_rowloop:
-        movq        xmm3,       MMWORD PTR [rsi - 2]
-        movq        xmm1,       MMWORD PTR [rsi + 6]
-
-        prefetcht2  [rsi+rax-2]
-
-        pslldq      xmm1,       8
-        por         xmm1,       xmm3
-
-        movdqa      xmm4,       xmm1
-        movdqa      xmm5,       xmm1
-
-        movdqa      xmm6,       xmm1
-        movdqa      xmm7,       xmm1
-
-        punpcklbw   xmm3,       xmm0                        ; xx05 xx04 xx03 xx02 xx01 xx01 xx-1 xx-2
-        psrldq      xmm4,       1                           ; xx 0d 0c 0b 0a 09 08 07 06 05 04 03 02 01 00 -1
-
-        pmullw      xmm3,       XMMWORD PTR [rdx]           ; x[-2] * H[-2]; Tap 1
-        punpcklbw   xmm4,       xmm0                        ; xx06 xx05 xx04 xx03 xx02 xx01 xx00 xx-1
-
-        psrldq      xmm5,       2                           ; xx xx 0d 0c 0b 0a 09 08 07 06 05 04 03 02 01 00
-        pmullw      xmm4,       XMMWORD PTR [rdx+16]        ; x[-1] * H[-1]; Tap 2
-
-
-        punpcklbw   xmm5,       xmm0                        ; xx07 xx06 xx05 xx04 xx03 xx02 xx01 xx00
-        psrldq      xmm6,       3                           ; xx xx xx 0d 0c 0b 0a 09 08 07 06 05 04 03 02 01
-
-        pmullw      xmm5,       [rdx+32]                    ; x[ 0] * H[ 0]; Tap 3
-
-        punpcklbw   xmm6,       xmm0                        ; xx08 xx07 xx06 xx05 xx04 xx03 xx02 xx01
-        psrldq      xmm7,       4                           ; xx xx xx xx 0d 0c 0b 0a 09 08 07 06 05 04 03 02
-
-        pmullw      xmm6,       [rdx+48]                    ; x[ 1] * h[ 1] ; Tap 4
-
-        punpcklbw   xmm7,       xmm0                        ; xx09 xx08 xx07 xx06 xx05 xx04 xx03 xx02
-        psrldq      xmm1,       5                           ; xx xx xx xx xx 0d 0c 0b 0a 09 08 07 06 05 04 03
-
-
-        pmullw      xmm7,       [rdx+64]                    ; x[ 2] * h[ 2] ; Tap 5
-
-        punpcklbw   xmm1,       xmm0                        ; xx0a xx09 xx08 xx07 xx06 xx05 xx04 xx03
-        pmullw      xmm1,       [rdx+80]                    ; x[ 3] * h[ 3] ; Tap 6
-
-
-        paddsw      xmm4,       xmm7
-        paddsw      xmm4,       xmm5
-
-        paddsw      xmm4,       xmm3
-        paddsw      xmm4,       xmm6
-
-        paddsw      xmm4,       xmm1
-        paddsw      xmm4,       [GLOBAL(rd)]
-
-        psraw       xmm4,       7
-
-        packuswb    xmm4,       xmm0
-
-        movq        QWORD PTR [rdi],   xmm4       ; store the results in the destination
-        lea         rsi,        [rsi + rax]
-
-%if ABI_IS_32BIT
-        add         rdi,        DWORD Ptr arg(3) ;dst_ptich
-%else
-        add         rdi,        r8
-%endif
-        dec         rcx
-
-        jnz         .filter_block1d8_h6_only_rowloop               ; next row
-
-    ; begin epilog
-    pop rdi
-    pop rsi
-    RESTORE_GOT
-    RESTORE_XMM
-    UNSHADOW_ARGS
-    pop         rbp
-    ret
-
-
-;void vp8_filter_block1d16_h6_only_sse2
-;(
-;    unsigned char  *src_ptr,
-;    unsigned int    src_pixels_per_line,
-;    unsigned char  *output_ptr,
-;    int dst_ptich,
-;    unsigned int    output_height,
-;    const short    *vp8_filter
-;)
-; First-pass filter only when yoffset==0
-global sym(vp8_filter_block1d16_h6_only_sse2) PRIVATE
-sym(vp8_filter_block1d16_h6_only_sse2):
-    push        rbp
-    mov         rbp, rsp
-    SHADOW_ARGS_TO_STACK 6
-    SAVE_XMM 7
-    GET_GOT     rbx
-    push        rsi
-    push        rdi
-    ; end prolog
-
-        mov         rdx,        arg(5) ;vp8_filter
-        mov         rsi,        arg(0) ;src_ptr
-
-        mov         rdi,        arg(2) ;output_ptr
-
-        movsxd      rcx,        dword ptr arg(4) ;output_height
-        movsxd      rax,        dword ptr arg(1) ;src_pixels_per_line            ; Pitch for Source
-%if ABI_IS_32BIT=0
-        movsxd      r8,         dword ptr arg(3) ;dst_ptich
-%endif
-
-        pxor        xmm0,       xmm0                        ; clear xmm0 for unpack
-
-.filter_block1d16_h6_only_sse2_rowloop:
-        movq        xmm3,       MMWORD PTR [rsi - 2]
-        movq        xmm1,       MMWORD PTR [rsi + 6]
-
-        movq        xmm2,       MMWORD PTR [rsi +14]
-        pslldq      xmm2,       8
-
-        por         xmm2,       xmm1
-        prefetcht2  [rsi+rax-2]
-
-        pslldq      xmm1,       8
-        por         xmm1,       xmm3
-
-        movdqa      xmm4,       xmm1
-        movdqa      xmm5,       xmm1
-
-        movdqa      xmm6,       xmm1
-        movdqa      xmm7,       xmm1
-
-        punpcklbw   xmm3,       xmm0                        ; xx05 xx04 xx03 xx02 xx01 xx01 xx-1 xx-2
-        psrldq      xmm4,       1                           ; xx 0d 0c 0b 0a 09 08 07 06 05 04 03 02 01 00 -1
-
-        pmullw      xmm3,       XMMWORD PTR [rdx]           ; x[-2] * H[-2]; Tap 1
-        punpcklbw   xmm4,       xmm0                        ; xx06 xx05 xx04 xx03 xx02 xx01 xx00 xx-1
-
-        psrldq      xmm5,       2                           ; xx xx 0d 0c 0b 0a 09 08 07 06 05 04 03 02 01 00
-        pmullw      xmm4,       XMMWORD PTR [rdx+16]        ; x[-1] * H[-1]; Tap 2
-
-        punpcklbw   xmm5,       xmm0                        ; xx07 xx06 xx05 xx04 xx03 xx02 xx01 xx00
-        psrldq      xmm6,       3                           ; xx xx xx 0d 0c 0b 0a 09 08 07 06 05 04 03 02 01
-
-        pmullw      xmm5,       [rdx+32]                    ; x[ 0] * H[ 0]; Tap 3
-
-        punpcklbw   xmm6,       xmm0                        ; xx08 xx07 xx06 xx05 xx04 xx03 xx02 xx01
-        psrldq      xmm7,       4                           ; xx xx xx xx 0d 0c 0b 0a 09 08 07 06 05 04 03 02
-
-        pmullw      xmm6,       [rdx+48]                    ; x[ 1] * h[ 1] ; Tap 4
-
-        punpcklbw   xmm7,       xmm0                        ; xx09 xx08 xx07 xx06 xx05 xx04 xx03 xx02
-        psrldq      xmm1,       5                           ; xx xx xx xx xx 0d 0c 0b 0a 09 08 07 06 05 04 03
-
-        pmullw      xmm7,       [rdx+64]                    ; x[ 2] * h[ 2] ; Tap 5
-
-        punpcklbw   xmm1,       xmm0                        ; xx0a xx09 xx08 xx07 xx06 xx05 xx04 xx03
-        pmullw      xmm1,       [rdx+80]                    ; x[ 3] * h[ 3] ; Tap 6
-
-        paddsw      xmm4,       xmm7
-        paddsw      xmm4,       xmm5
-
-        paddsw      xmm4,       xmm3
-        paddsw      xmm4,       xmm6
-
-        paddsw      xmm4,       xmm1
-        paddsw      xmm4,       [GLOBAL(rd)]
-
-        psraw       xmm4,       7
-
-        packuswb    xmm4,       xmm0                        ; lower 8 bytes
-
-        movq        QWORD Ptr [rdi],         xmm4           ; store the results in the destination
-
-        movdqa      xmm3,       xmm2
-        movdqa      xmm4,       xmm2
-
-        movdqa      xmm5,       xmm2
-        movdqa      xmm6,       xmm2
-
-        movdqa      xmm7,       xmm2
-
-        punpcklbw   xmm3,       xmm0                        ; xx05 xx04 xx03 xx02 xx01 xx01 xx-1 xx-2
-        psrldq      xmm4,       1                           ; xx 0d 0c 0b 0a 09 08 07 06 05 04 03 02 01 00 -1
-
-        pmullw      xmm3,       XMMWORD PTR [rdx]           ; x[-2] * H[-2]; Tap 1
-        punpcklbw   xmm4,       xmm0                        ; xx06 xx05 xx04 xx03 xx02 xx01 xx00 xx-1
-
-        psrldq      xmm5,       2                           ; xx xx 0d 0c 0b 0a 09 08 07 06 05 04 03 02 01 00
-        pmullw      xmm4,       XMMWORD PTR [rdx+16]        ; x[-1] * H[-1]; Tap 2
-
-        punpcklbw   xmm5,       xmm0                        ; xx07 xx06 xx05 xx04 xx03 xx02 xx01 xx00
-        psrldq      xmm6,       3                           ; xx xx xx 0d 0c 0b 0a 09 08 07 06 05 04 03 02 01
-
-        pmullw      xmm5,       [rdx+32]                    ; x[ 0] * H[ 0]; Tap 3
-
-        punpcklbw   xmm6,       xmm0                        ; xx08 xx07 xx06 xx05 xx04 xx03 xx02 xx01
-        psrldq      xmm7,       4                           ; xx xx xx xx 0d 0c 0b 0a 09 08 07 06 05 04 03 02
-
-        pmullw      xmm6,       [rdx+48]                    ; x[ 1] * h[ 1] ; Tap 4
-
-        punpcklbw   xmm7,       xmm0                        ; xx09 xx08 xx07 xx06 xx05 xx04 xx03 xx02
-        psrldq      xmm2,       5                           ; xx xx xx xx xx 0d 0c 0b 0a 09 08 07 06 05 04 03
-
-        pmullw      xmm7,       [rdx+64]                    ; x[ 2] * h[ 2] ; Tap 5
-
-        punpcklbw   xmm2,       xmm0                        ; xx0a xx09 xx08 xx07 xx06 xx05 xx04 xx03
-        pmullw      xmm2,       [rdx+80]                    ; x[ 3] * h[ 3] ; Tap 6
-
-        paddsw      xmm4,       xmm7
-        paddsw      xmm4,       xmm5
-
-        paddsw      xmm4,       xmm3
-        paddsw      xmm4,       xmm6
-
-        paddsw      xmm4,       xmm2
-        paddsw      xmm4,       [GLOBAL(rd)]
-
-        psraw       xmm4,       7
-
-        packuswb    xmm4,       xmm0                        ; higher 8 bytes
-
-        movq        QWORD Ptr [rdi+8],      xmm4            ; store the results in the destination
-
-        lea         rsi,        [rsi + rax]
-%if ABI_IS_32BIT
-        add         rdi,        DWORD Ptr arg(3) ;dst_ptich
-%else
-        add         rdi,        r8
-%endif
-
-        dec         rcx
-        jnz         .filter_block1d16_h6_only_sse2_rowloop               ; next row
-
-    ; begin epilog
-    pop rdi
-    pop rsi
-    RESTORE_GOT
-    RESTORE_XMM
-    UNSHADOW_ARGS
-    pop         rbp
-    ret
-
-
-;void vp8_filter_block1d8_v6_only_sse2
-;(
-;    unsigned char *src_ptr,
-;    unsigned int    src_pixels_per_line,
-;    unsigned char *output_ptr,
-;    int dst_ptich,
-;    unsigned int output_height,
-;    const short    *vp8_filter
-;)
-; Second-pass filter only when xoffset==0
-global sym(vp8_filter_block1d8_v6_only_sse2) PRIVATE
-sym(vp8_filter_block1d8_v6_only_sse2):
-    push        rbp
-    mov         rbp, rsp
-    SHADOW_ARGS_TO_STACK 6
-    SAVE_XMM 7
-    GET_GOT     rbx
-    push        rsi
-    push        rdi
-    ; end prolog
-
-        mov         rsi,        arg(0) ;src_ptr
-        mov         rdi,        arg(2) ;output_ptr
-
-        movsxd      rcx,        dword ptr arg(4) ;output_height
-        movsxd      rdx,        dword ptr arg(1) ;src_pixels_per_line
-
-        mov         rax,        arg(5) ;vp8_filter
-
-        pxor        xmm0,       xmm0                        ; clear xmm0
-
-        movdqa      xmm7,       XMMWORD PTR [GLOBAL(rd)]
-%if ABI_IS_32BIT=0
-        movsxd      r8,         dword ptr arg(3) ; dst_ptich
-%endif
-
-.vp8_filter_block1d8_v6_only_sse2_loop:
-        movq        xmm1,       MMWORD PTR [rsi]
-        movq        xmm2,       MMWORD PTR [rsi + rdx]
-        movq        xmm3,       MMWORD PTR [rsi + rdx * 2]
-        movq        xmm5,       MMWORD PTR [rsi + rdx * 4]
-        add         rsi,        rdx
-        movq        xmm4,       MMWORD PTR [rsi + rdx * 2]
-        movq        xmm6,       MMWORD PTR [rsi + rdx * 4]
-
-        punpcklbw   xmm1,       xmm0
-        pmullw      xmm1,       [rax]
-
-        punpcklbw   xmm2,       xmm0
-        pmullw      xmm2,       [rax + 16]
-
-        punpcklbw   xmm3,       xmm0
-        pmullw      xmm3,       [rax + 32]
-
-        punpcklbw   xmm5,       xmm0
-        pmullw      xmm5,       [rax + 64]
-
-        punpcklbw   xmm4,       xmm0
-        pmullw      xmm4,       [rax + 48]
-
-        punpcklbw   xmm6,       xmm0
-        pmullw      xmm6,       [rax + 80]
-
-        paddsw      xmm2,       xmm5
-        paddsw      xmm2,       xmm3
-
-        paddsw      xmm2,       xmm1
-        paddsw      xmm2,       xmm4
-
-        paddsw      xmm2,       xmm6
-        paddsw      xmm2,       xmm7
-
-        psraw       xmm2,       7
-        packuswb    xmm2,       xmm0              ; pack and saturate
-
-        movq        QWORD PTR [rdi], xmm2         ; store the results in the destination
-%if ABI_IS_32BIT
-        add         rdi,        DWORD PTR arg(3) ;[dst_ptich]
-%else
-        add         rdi,        r8
-%endif
-        dec         rcx         ; decrement count
-        jnz         .vp8_filter_block1d8_v6_only_sse2_loop              ; next row
-
-    ; begin epilog
-    pop rdi
-    pop rsi
-    RESTORE_GOT
-    RESTORE_XMM
-    UNSHADOW_ARGS
-    pop         rbp
-    ret
-
-
-;void vp8_unpack_block1d16_h6_sse2
-;(
-;    unsigned char  *src_ptr,
-;    unsigned short *output_ptr,
-;    unsigned int    src_pixels_per_line,
-;    unsigned int    output_height,
-;    unsigned int    output_width
-;)
-global sym(vp8_unpack_block1d16_h6_sse2) PRIVATE
-sym(vp8_unpack_block1d16_h6_sse2):
-    push        rbp
-    mov         rbp, rsp
-    SHADOW_ARGS_TO_STACK 5
-    GET_GOT     rbx
-    push        rsi
-    push        rdi
-    ; end prolog
-
-        mov         rsi,        arg(0) ;src_ptr
-        mov         rdi,        arg(1) ;output_ptr
-
-        movsxd      rcx,        dword ptr arg(3) ;output_height
-        movsxd      rax,        dword ptr arg(2) ;src_pixels_per_line            ; Pitch for Source
-
-        pxor        xmm0,       xmm0                        ; clear xmm0 for unpack
-%if ABI_IS_32BIT=0
-        movsxd      r8,         dword ptr arg(4) ;output_width            ; Pitch for Source
-%endif
-
-.unpack_block1d16_h6_sse2_rowloop:
-        movq        xmm1,       MMWORD PTR [rsi]            ; 0d 0c 0b 0a 09 08 07 06 05 04 03 02 01 00 -1 -2
-        movq        xmm3,       MMWORD PTR [rsi+8]          ; make copy of xmm1
-
-        punpcklbw   xmm3,       xmm0                        ; xx05 xx04 xx03 xx02 xx01 xx01 xx-1 xx-2
-        punpcklbw   xmm1,       xmm0
-
-        movdqa      XMMWORD Ptr [rdi],         xmm1
-        movdqa      XMMWORD Ptr [rdi + 16],    xmm3
-
-        lea         rsi,        [rsi + rax]
-%if ABI_IS_32BIT
-        add         rdi,        DWORD Ptr arg(4) ;[output_width]
-%else
-        add         rdi,        r8
-%endif
-        dec         rcx
-        jnz         .unpack_block1d16_h6_sse2_rowloop               ; next row
-
-    ; begin epilog
-    pop rdi
-    pop rsi
-    RESTORE_GOT
-    UNSHADOW_ARGS
-    pop         rbp
-    ret
-
-
-;void vp8_bilinear_predict16x16_sse2
-;(
-;    unsigned char  *src_ptr,
-;    int   src_pixels_per_line,
-;    int  xoffset,
-;    int  yoffset,
-;    unsigned char *dst_ptr,
-;    int dst_pitch
-;)
-extern sym(vp8_bilinear_filters_x86_8)
-global sym(vp8_bilinear_predict16x16_sse2) PRIVATE
-sym(vp8_bilinear_predict16x16_sse2):
-    push        rbp
-    mov         rbp, rsp
-    SHADOW_ARGS_TO_STACK 6
-    SAVE_XMM 7
-    GET_GOT     rbx
-    push        rsi
-    push        rdi
-    ; end prolog
-
-    ;const short *HFilter = vp8_bilinear_filters_x86_8[xoffset]
-    ;const short *VFilter = vp8_bilinear_filters_x86_8[yoffset]
-
-        lea         rcx,        [GLOBAL(sym(vp8_bilinear_filters_x86_8))]
-        movsxd      rax,        dword ptr arg(2) ;xoffset
-
-        cmp         rax,        0      ;skip first_pass filter if xoffset=0
-        je          .b16x16_sp_only
-
-        shl         rax,        5
-        add         rax,        rcx    ;HFilter
-
-        mov         rdi,        arg(4) ;dst_ptr
-        mov         rsi,        arg(0) ;src_ptr
-        movsxd      rdx,        dword ptr arg(5) ;dst_pitch
-
-        movdqa      xmm1,       [rax]
-        movdqa      xmm2,       [rax+16]
-
-        movsxd      rax,        dword ptr arg(3) ;yoffset
-
-        cmp         rax,        0      ;skip second_pass filter if yoffset=0
-        je          .b16x16_fp_only
-
-        shl         rax,        5
-        add         rax,        rcx    ;VFilter
-
-        lea         rcx,        [rdi+rdx*8]
-        lea         rcx,        [rcx+rdx*8]
-        movsxd      rdx,        dword ptr arg(1) ;src_pixels_per_line
-
-        pxor        xmm0,       xmm0
-
-%if ABI_IS_32BIT=0
-        movsxd      r8,         dword ptr arg(5) ;dst_pitch
-%endif
-        ; get the first horizontal line done
-        movdqu      xmm3,       [rsi]               ; xx 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14
-        movdqa      xmm4,       xmm3                 ; make a copy of current line
-
-        punpcklbw   xmm3,       xmm0                 ; xx 00 01 02 03 04 05 06
-        punpckhbw   xmm4,       xmm0
-
-        pmullw      xmm3,       xmm1
-        pmullw      xmm4,       xmm1
-
-        movdqu      xmm5,       [rsi+1]
-        movdqa      xmm6,       xmm5
-
-        punpcklbw   xmm5,       xmm0
-        punpckhbw   xmm6,       xmm0
-
-        pmullw      xmm5,       xmm2
-        pmullw      xmm6,       xmm2
-
-        paddw       xmm3,       xmm5
-        paddw       xmm4,       xmm6
-
-        paddw       xmm3,       [GLOBAL(rd)]        ; xmm3 += round value
-        psraw       xmm3,       VP8_FILTER_SHIFT        ; xmm3 /= 128
-
-        paddw       xmm4,       [GLOBAL(rd)]
-        psraw       xmm4,       VP8_FILTER_SHIFT
-
-        movdqa      xmm7,       xmm3
-        packuswb    xmm7,       xmm4
-
-        add         rsi,        rdx                 ; next line
-.next_row:
-        movdqu      xmm3,       [rsi]               ; xx 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14
-        movdqa      xmm4,       xmm3                 ; make a copy of current line
-
-        punpcklbw   xmm3,       xmm0                 ; xx 00 01 02 03 04 05 06
-        punpckhbw   xmm4,       xmm0
-
-        pmullw      xmm3,       xmm1
-        pmullw      xmm4,       xmm1
-
-        movdqu      xmm5,       [rsi+1]
-        movdqa      xmm6,       xmm5
-
-        punpcklbw   xmm5,       xmm0
-        punpckhbw   xmm6,       xmm0
-
-        pmullw      xmm5,       xmm2
-        pmullw      xmm6,       xmm2
-
-        paddw       xmm3,       xmm5
-        paddw       xmm4,       xmm6
-
-        movdqa      xmm5,       xmm7
-        movdqa      xmm6,       xmm7
-
-        punpcklbw   xmm5,       xmm0
-        punpckhbw   xmm6,       xmm0
-
-        pmullw      xmm5,       [rax]
-        pmullw      xmm6,       [rax]
-
-        paddw       xmm3,       [GLOBAL(rd)]        ; xmm3 += round value
-        psraw       xmm3,       VP8_FILTER_SHIFT        ; xmm3 /= 128
-
-        paddw       xmm4,       [GLOBAL(rd)]
-        psraw       xmm4,       VP8_FILTER_SHIFT
-
-        movdqa      xmm7,       xmm3
-        packuswb    xmm7,       xmm4
-
-        pmullw      xmm3,       [rax+16]
-        pmullw      xmm4,       [rax+16]
-
-        paddw       xmm3,       xmm5
-        paddw       xmm4,       xmm6
-
-        paddw       xmm3,       [GLOBAL(rd)]        ; xmm3 += round value
-        psraw       xmm3,       VP8_FILTER_SHIFT        ; xmm3 /= 128
-
-        paddw       xmm4,       [GLOBAL(rd)]
-        psraw       xmm4,       VP8_FILTER_SHIFT
-
-        packuswb    xmm3,       xmm4
-        movdqa      [rdi],      xmm3                 ; store the results in the destination
-
-        add         rsi,        rdx                 ; next line
-%if ABI_IS_32BIT
-        add         rdi,        DWORD PTR arg(5) ;dst_pitch
-%else
-        add         rdi,        r8
-%endif
-
-        cmp         rdi,        rcx
-        jne         .next_row
-
-        jmp         .done
-
-.b16x16_sp_only:
-        movsxd      rax,        dword ptr arg(3) ;yoffset
-        shl         rax,        5
-        add         rax,        rcx    ;VFilter
-
-        mov         rdi,        arg(4) ;dst_ptr
-        mov         rsi,        arg(0) ;src_ptr
-        movsxd      rdx,        dword ptr arg(5) ;dst_pitch
-
-        movdqa      xmm1,       [rax]
-        movdqa      xmm2,       [rax+16]
-
-        lea         rcx,        [rdi+rdx*8]
-        lea         rcx,        [rcx+rdx*8]
-        movsxd      rax,        dword ptr arg(1) ;src_pixels_per_line
-
-        pxor        xmm0,       xmm0
-
-        ; get the first horizontal line done
-        movdqu      xmm7,       [rsi]               ; xx 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14
-
-        add         rsi,        rax                 ; next line
-.next_row_spo:
-        movdqu      xmm3,       [rsi]               ; xx 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14
-
-        movdqa      xmm5,       xmm7
-        movdqa      xmm6,       xmm7
-
-        movdqa      xmm4,       xmm3                 ; make a copy of current line
-        movdqa      xmm7,       xmm3
-
-        punpcklbw   xmm5,       xmm0
-        punpckhbw   xmm6,       xmm0
-        punpcklbw   xmm3,       xmm0                 ; xx 00 01 02 03 04 05 06
-        punpckhbw   xmm4,       xmm0
-
-        pmullw      xmm5,       xmm1
-        pmullw      xmm6,       xmm1
-        pmullw      xmm3,       xmm2
-        pmullw      xmm4,       xmm2
-
-        paddw       xmm3,       xmm5
-        paddw       xmm4,       xmm6
-
-        paddw       xmm3,       [GLOBAL(rd)]        ; xmm3 += round value
-        psraw       xmm3,       VP8_FILTER_SHIFT        ; xmm3 /= 128
-
-        paddw       xmm4,       [GLOBAL(rd)]
-        psraw       xmm4,       VP8_FILTER_SHIFT
-
-        packuswb    xmm3,       xmm4
-        movdqa      [rdi],      xmm3                 ; store the results in the destination
-
-        add         rsi,        rax                 ; next line
-        add         rdi,        rdx                 ;dst_pitch
-        cmp         rdi,        rcx
-        jne         .next_row_spo
-
-        jmp         .done
-
-.b16x16_fp_only:
-        lea         rcx,        [rdi+rdx*8]
-        lea         rcx,        [rcx+rdx*8]
-        movsxd      rax,        dword ptr arg(1) ;src_pixels_per_line
-        pxor        xmm0,       xmm0
-
-.next_row_fpo:
-        movdqu      xmm3,       [rsi]               ; xx 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14
-        movdqa      xmm4,       xmm3                 ; make a copy of current line
-
-        punpcklbw   xmm3,       xmm0                 ; xx 00 01 02 03 04 05 06
-        punpckhbw   xmm4,       xmm0
-
-        pmullw      xmm3,       xmm1
-        pmullw      xmm4,       xmm1
-
-        movdqu      xmm5,       [rsi+1]
-        movdqa      xmm6,       xmm5
-
-        punpcklbw   xmm5,       xmm0
-        punpckhbw   xmm6,       xmm0
-
-        pmullw      xmm5,       xmm2
-        pmullw      xmm6,       xmm2
-
-        paddw       xmm3,       xmm5
-        paddw       xmm4,       xmm6
-
-        paddw       xmm3,       [GLOBAL(rd)]        ; xmm3 += round value
-        psraw       xmm3,       VP8_FILTER_SHIFT        ; xmm3 /= 128
-
-        paddw       xmm4,       [GLOBAL(rd)]
-        psraw       xmm4,       VP8_FILTER_SHIFT
-
-        packuswb    xmm3,       xmm4
-        movdqa      [rdi],      xmm3                 ; store the results in the destination
-
-        add         rsi,        rax                 ; next line
-        add         rdi,        rdx                 ; dst_pitch
-        cmp         rdi,        rcx
-        jne         .next_row_fpo
-
-.done:
-    ; begin epilog
-    pop rdi
-    pop rsi
-    RESTORE_GOT
-    RESTORE_XMM
-    UNSHADOW_ARGS
-    pop         rbp
-    ret
-
-
-;void vp8_bilinear_predict8x8_sse2
-;(
-;    unsigned char  *src_ptr,
-;    int   src_pixels_per_line,
-;    int  xoffset,
-;    int  yoffset,
-;    unsigned char *dst_ptr,
-;    int dst_pitch
-;)
-global sym(vp8_bilinear_predict8x8_sse2) PRIVATE
-sym(vp8_bilinear_predict8x8_sse2):
-    push        rbp
-    mov         rbp, rsp
-    SHADOW_ARGS_TO_STACK 6
-    SAVE_XMM 7
-    GET_GOT     rbx
-    push        rsi
-    push        rdi
-    ; end prolog
-
-    ALIGN_STACK 16, rax
-    sub         rsp, 144                         ; reserve 144 bytes
-
-    ;const short *HFilter = vp8_bilinear_filters_x86_8[xoffset]
-    ;const short *VFilter = vp8_bilinear_filters_x86_8[yoffset]
-        lea         rcx,        [GLOBAL(sym(vp8_bilinear_filters_x86_8))]
-
-        mov         rsi,        arg(0) ;src_ptr
-        movsxd      rdx,        dword ptr arg(1) ;src_pixels_per_line
-
-    ;Read 9-line unaligned data in and put them on stack. This gives a big
-    ;performance boost.
-        movdqu      xmm0,       [rsi]
-        lea         rax,        [rdx + rdx*2]
-        movdqu      xmm1,       [rsi+rdx]
-        movdqu      xmm2,       [rsi+rdx*2]
-        add         rsi,        rax
-        movdqu      xmm3,       [rsi]
-        movdqu      xmm4,       [rsi+rdx]
-        movdqu      xmm5,       [rsi+rdx*2]
-        add         rsi,        rax
-        movdqu      xmm6,       [rsi]
-        movdqu      xmm7,       [rsi+rdx]
-
-        movdqa      XMMWORD PTR [rsp],            xmm0
-
-        movdqu      xmm0,       [rsi+rdx*2]
-
-        movdqa      XMMWORD PTR [rsp+16],         xmm1
-        movdqa      XMMWORD PTR [rsp+32],         xmm2
-        movdqa      XMMWORD PTR [rsp+48],         xmm3
-        movdqa      XMMWORD PTR [rsp+64],         xmm4
-        movdqa      XMMWORD PTR [rsp+80],         xmm5
-        movdqa      XMMWORD PTR [rsp+96],         xmm6
-        movdqa      XMMWORD PTR [rsp+112],        xmm7
-        movdqa      XMMWORD PTR [rsp+128],        xmm0
-
-        movsxd      rax,        dword ptr arg(2) ;xoffset
-        shl         rax,        5
-        add         rax,        rcx    ;HFilter
-
-        mov         rdi,        arg(4) ;dst_ptr
-        movsxd      rdx,        dword ptr arg(5) ;dst_pitch
-
-        movdqa      xmm1,       [rax]
-        movdqa      xmm2,       [rax+16]
-
-        movsxd      rax,        dword ptr arg(3) ;yoffset
-        shl         rax,        5
-        add         rax,        rcx    ;VFilter
-
-        lea         rcx,        [rdi+rdx*8]
-
-        movdqa      xmm5,       [rax]
-        movdqa      xmm6,       [rax+16]
-
-        pxor        xmm0,       xmm0
-
-        ; get the first horizontal line done
-        movdqa      xmm3,       XMMWORD PTR [rsp]
-        movdqa      xmm4,       xmm3                 ; make a copy of current line
-        psrldq      xmm4,       1
-
-        punpcklbw   xmm3,       xmm0                 ; 00 01 02 03 04 05 06 07
-        punpcklbw   xmm4,       xmm0                 ; 01 02 03 04 05 06 07 08
-
-        pmullw      xmm3,       xmm1
-        pmullw      xmm4,       xmm2
-
-        paddw       xmm3,       xmm4
-
-        paddw       xmm3,       [GLOBAL(rd)]        ; xmm3 += round value
-        psraw       xmm3,       VP8_FILTER_SHIFT        ; xmm3 /= 128
-
-        movdqa      xmm7,       xmm3
-        add         rsp,        16                 ; next line
-.next_row8x8:
-        movdqa      xmm3,       XMMWORD PTR [rsp]               ; 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15
-        movdqa      xmm4,       xmm3                 ; make a copy of current line
-        psrldq      xmm4,       1
-
-        punpcklbw   xmm3,       xmm0                 ; 00 01 02 03 04 05 06 07
-        punpcklbw   xmm4,       xmm0                 ; 01 02 03 04 05 06 07 08
-
-        pmullw      xmm3,       xmm1
-        pmullw      xmm4,       xmm2
-
-        paddw       xmm3,       xmm4
-        pmullw      xmm7,       xmm5
-
-        paddw       xmm3,       [GLOBAL(rd)]        ; xmm3 += round value
-        psraw       xmm3,       VP8_FILTER_SHIFT        ; xmm3 /= 128
-
-        movdqa      xmm4,       xmm3
-
-        pmullw      xmm3,       xmm6
-        paddw       xmm3,       xmm7
-
-        movdqa      xmm7,       xmm4
-
-        paddw       xmm3,       [GLOBAL(rd)]        ; xmm3 += round value
-        psraw       xmm3,       VP8_FILTER_SHIFT        ; xmm3 /= 128
-
-        packuswb    xmm3,       xmm0
-        movq        [rdi],      xmm3                 ; store the results in the destination
-
-        add         rsp,        16                 ; next line
-        add         rdi,        rdx
-
-        cmp         rdi,        rcx
-        jne         .next_row8x8
-
-    ;add rsp, 144
-    pop rsp
-    ; begin epilog
-    pop rdi
-    pop rsi
-    RESTORE_GOT
-    RESTORE_XMM
-    UNSHADOW_ARGS
-    pop         rbp
-    ret
-
-
-SECTION_RODATA
-align 16
-rd:
-    times 8 dw 0x40
diff --git a/vp8/common/x86/subpixel_ssse3.asm b/vp8/common/x86/subpixel_ssse3.asm
deleted file mode 100644 (file)
index c06f245..0000000
+++ /dev/null
@@ -1,1508 +0,0 @@
-;
-;  Copyright (c) 2010 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.
-;
-
-
-%include "vpx_ports/x86_abi_support.asm"
-
-%define BLOCK_HEIGHT_WIDTH 4
-%define VP8_FILTER_WEIGHT 128
-%define VP8_FILTER_SHIFT  7
-
-
-;/************************************************************************************
-; Notes: filter_block1d_h6 applies a 6 tap filter horizontally to the input pixels. The
-; input pixel array has output_height rows. This routine assumes that output_height is an
-; even number. This function handles 8 pixels in horizontal direction, calculating ONE
-; rows each iteration to take advantage of the 128 bits operations.
-;
-; This is an implementation of some of the SSE optimizations first seen in ffvp8
-;
-;*************************************************************************************/
-;void vp8_filter_block1d8_h6_ssse3
-;(
-;    unsigned char  *src_ptr,
-;    unsigned int    src_pixels_per_line,
-;    unsigned char *output_ptr,
-;    unsigned int    output_pitch,
-;    unsigned int    output_height,
-;    unsigned int    vp8_filter_index
-;)
-global sym(vp8_filter_block1d8_h6_ssse3) PRIVATE
-sym(vp8_filter_block1d8_h6_ssse3):
-    push        rbp
-    mov         rbp, rsp
-    SHADOW_ARGS_TO_STACK 6
-    SAVE_XMM 7
-    GET_GOT     rbx
-    push        rsi
-    push        rdi
-    ; end prolog
-
-    movsxd      rdx, DWORD PTR arg(5)   ;table index
-    xor         rsi, rsi
-    shl         rdx, 4
-
-    movdqa      xmm7, [GLOBAL(rd)]
-
-    lea         rax, [GLOBAL(k0_k5)]
-    add         rax, rdx
-    mov         rdi, arg(2)             ;output_ptr
-
-    cmp         esi, DWORD PTR [rax]
-    je          vp8_filter_block1d8_h4_ssse3
-
-    movdqa      xmm4, XMMWORD PTR [rax]         ;k0_k5
-    movdqa      xmm5, XMMWORD PTR [rax+256]     ;k2_k4
-    movdqa      xmm6, XMMWORD PTR [rax+128]     ;k1_k3
-
-    mov         rsi, arg(0)             ;src_ptr
-    movsxd      rax, dword ptr arg(1)   ;src_pixels_per_line
-    movsxd      rcx, dword ptr arg(4)   ;output_height
-
-    movsxd      rdx, dword ptr arg(3)   ;output_pitch
-
-    sub         rdi, rdx
-;xmm3 free
-.filter_block1d8_h6_rowloop_ssse3:
-    movq        xmm0,   MMWORD PTR [rsi - 2]    ; -2 -1  0  1  2  3  4  5
-
-    movq        xmm2,   MMWORD PTR [rsi + 3]    ;  3  4  5  6  7  8  9 10
-
-    punpcklbw   xmm0,   xmm2                    ; -2  3 -1  4  0  5  1  6  2  7  3  8  4  9  5 10
-
-    movdqa      xmm1,   xmm0
-    pmaddubsw   xmm0,   xmm4
-
-    movdqa      xmm2,   xmm1
-    pshufb      xmm1,   [GLOBAL(shuf2bfrom1)]
-
-    pshufb      xmm2,   [GLOBAL(shuf3bfrom1)]
-    pmaddubsw   xmm1,   xmm5
-
-    lea         rdi,    [rdi + rdx]
-    pmaddubsw   xmm2,   xmm6
-
-    lea         rsi,    [rsi + rax]
-    dec         rcx
-
-    paddsw      xmm0,   xmm1
-    paddsw      xmm2,   xmm7
-
-    paddsw      xmm0,   xmm2
-
-    psraw       xmm0,   7
-
-    packuswb    xmm0,   xmm0
-
-    movq        MMWORD Ptr [rdi], xmm0
-    jnz         .filter_block1d8_h6_rowloop_ssse3
-
-    ; begin epilog
-    pop rdi
-    pop rsi
-    RESTORE_GOT
-    RESTORE_XMM
-    UNSHADOW_ARGS
-    pop         rbp
-    ret
-
-vp8_filter_block1d8_h4_ssse3:
-    movdqa      xmm5, XMMWORD PTR [rax+256]     ;k2_k4
-    movdqa      xmm6, XMMWORD PTR [rax+128]     ;k1_k3
-
-    movdqa      xmm3, XMMWORD PTR [GLOBAL(shuf2bfrom1)]
-    movdqa      xmm4, XMMWORD PTR [GLOBAL(shuf3bfrom1)]
-
-    mov         rsi, arg(0)             ;src_ptr
-
-    movsxd      rax, dword ptr arg(1)   ;src_pixels_per_line
-    movsxd      rcx, dword ptr arg(4)   ;output_height
-
-    movsxd      rdx, dword ptr arg(3)   ;output_pitch
-
-    sub         rdi, rdx
-
-.filter_block1d8_h4_rowloop_ssse3:
-    movq        xmm0,   MMWORD PTR [rsi - 2]    ; -2 -1  0  1  2  3  4  5
-
-    movq        xmm1,   MMWORD PTR [rsi + 3]    ;  3  4  5  6  7  8  9 10
-
-    punpcklbw   xmm0,   xmm1                    ; -2  3 -1  4  0  5  1  6  2  7  3  8  4  9  5 10
-
-    movdqa      xmm2,   xmm0
-    pshufb      xmm0,   xmm3
-
-    pshufb      xmm2,   xmm4
-    pmaddubsw   xmm0,   xmm5
-
-    lea         rdi,    [rdi + rdx]
-    pmaddubsw   xmm2,   xmm6
-
-    lea         rsi,    [rsi + rax]
-    dec         rcx
-
-    paddsw      xmm0,   xmm7
-
-    paddsw      xmm0,   xmm2
-
-    psraw       xmm0,   7
-
-    packuswb    xmm0,   xmm0
-
-    movq        MMWORD Ptr [rdi], xmm0
-
-    jnz         .filter_block1d8_h4_rowloop_ssse3
-
-    ; begin epilog
-    pop rdi
-    pop rsi
-    RESTORE_GOT
-    RESTORE_XMM
-    UNSHADOW_ARGS
-    pop         rbp
-    ret
-;void vp8_filter_block1d16_h6_ssse3
-;(
-;    unsigned char  *src_ptr,
-;    unsigned int    src_pixels_per_line,
-;    unsigned char  *output_ptr,
-;    unsigned int    output_pitch,
-;    unsigned int    output_height,
-;    unsigned int    vp8_filter_index
-;)
-global sym(vp8_filter_block1d16_h6_ssse3) PRIVATE
-sym(vp8_filter_block1d16_h6_ssse3):
-    push        rbp
-    mov         rbp, rsp
-    SHADOW_ARGS_TO_STACK 6
-    SAVE_XMM 7
-    GET_GOT     rbx
-    push        rsi
-    push        rdi
-    ; end prolog
-
-    movsxd      rdx, DWORD PTR arg(5)           ;table index
-    xor         rsi, rsi
-    shl         rdx, 4      ;
-
-    lea         rax, [GLOBAL(k0_k5)]
-    add         rax, rdx
-
-    mov         rdi, arg(2)                     ;output_ptr
-
-    mov         rsi, arg(0)                     ;src_ptr
-
-    movdqa      xmm4, XMMWORD PTR [rax]         ;k0_k5
-    movdqa      xmm5, XMMWORD PTR [rax+256]     ;k2_k4
-    movdqa      xmm6, XMMWORD PTR [rax+128]     ;k1_k3
-
-    movsxd      rax, dword ptr arg(1)           ;src_pixels_per_line
-    movsxd      rcx, dword ptr arg(4)           ;output_height
-    movsxd      rdx, dword ptr arg(3)           ;output_pitch
-
-.filter_block1d16_h6_rowloop_ssse3:
-    movq        xmm0,   MMWORD PTR [rsi - 2]    ; -2 -1  0  1  2  3  4  5
-
-    movq        xmm3,   MMWORD PTR [rsi + 3]    ;  3  4  5  6  7  8  9 10
-
-    punpcklbw   xmm0,   xmm3                    ; -2  3 -1  4  0  5  1  6  2  7  3  8  4  9  5 10
-
-    movdqa      xmm1,   xmm0
-    pmaddubsw   xmm0,   xmm4
-
-    movdqa      xmm2,   xmm1
-    pshufb      xmm1,   [GLOBAL(shuf2bfrom1)]
-
-    pshufb      xmm2,   [GLOBAL(shuf3bfrom1)]
-    movq        xmm3,   MMWORD PTR [rsi +  6]
-
-    pmaddubsw   xmm1,   xmm5
-    movq        xmm7,   MMWORD PTR [rsi + 11]
-
-    pmaddubsw   xmm2,   xmm6
-    punpcklbw   xmm3,   xmm7
-
-    paddsw      xmm0,   xmm1
-    movdqa      xmm1,   xmm3
-
-    pmaddubsw   xmm3,   xmm4
-    paddsw      xmm0,   xmm2
-
-    movdqa      xmm2,   xmm1
-    paddsw      xmm0,   [GLOBAL(rd)]
-
-    pshufb      xmm1,   [GLOBAL(shuf2bfrom1)]
-    pshufb      xmm2,   [GLOBAL(shuf3bfrom1)]
-
-    psraw       xmm0,   7
-    pmaddubsw   xmm1,   xmm5
-
-    pmaddubsw   xmm2,   xmm6
-    packuswb    xmm0,   xmm0
-
-    lea         rsi,    [rsi + rax]
-    paddsw      xmm3,   xmm1
-
-    paddsw      xmm3,   xmm2
-
-    paddsw      xmm3,   [GLOBAL(rd)]
-
-    psraw       xmm3,   7
-
-    packuswb    xmm3,   xmm3
-
-    punpcklqdq  xmm0,   xmm3
-
-    movdqa      XMMWORD Ptr [rdi], xmm0
-
-    lea         rdi,    [rdi + rdx]
-    dec         rcx
-    jnz         .filter_block1d16_h6_rowloop_ssse3
-
-    ; begin epilog
-    pop rdi
-    pop rsi
-    RESTORE_GOT
-    RESTORE_XMM
-    UNSHADOW_ARGS
-    pop         rbp
-    ret
-
-;void vp8_filter_block1d4_h6_ssse3
-;(
-;    unsigned char  *src_ptr,
-;    unsigned int    src_pixels_per_line,
-;    unsigned char  *output_ptr,
-;    unsigned int    output_pitch,
-;    unsigned int    output_height,
-;    unsigned int    vp8_filter_index
-;)
-global sym(vp8_filter_block1d4_h6_ssse3) PRIVATE
-sym(vp8_filter_block1d4_h6_ssse3):
-    push        rbp
-    mov         rbp, rsp
-    SHADOW_ARGS_TO_STACK 6
-    SAVE_XMM 7
-    GET_GOT     rbx
-    push        rsi
-    push        rdi
-    ; end prolog
-
-    movsxd      rdx, DWORD PTR arg(5)   ;table index
-    xor         rsi, rsi
-    shl         rdx, 4      ;
-
-    lea         rax, [GLOBAL(k0_k5)]
-    add         rax, rdx
-    movdqa      xmm7, [GLOBAL(rd)]
-
-    cmp         esi, DWORD PTR [rax]
-    je          .vp8_filter_block1d4_h4_ssse3
-
-    movdqa      xmm4, XMMWORD PTR [rax]         ;k0_k5
-    movdqa      xmm5, XMMWORD PTR [rax+256]     ;k2_k4
-    movdqa      xmm6, XMMWORD PTR [rax+128]     ;k1_k3
-
-    mov         rsi, arg(0)             ;src_ptr
-    mov         rdi, arg(2)             ;output_ptr
-    movsxd      rax, dword ptr arg(1)   ;src_pixels_per_line
-    movsxd      rcx, dword ptr arg(4)   ;output_height
-
-    movsxd      rdx, dword ptr arg(3)   ;output_pitch
-
-;xmm3 free
-.filter_block1d4_h6_rowloop_ssse3:
-    movdqu      xmm0,   XMMWORD PTR [rsi - 2]
-
-    movdqa      xmm1, xmm0
-    pshufb      xmm0, [GLOBAL(shuf1b)]
-
-    movdqa      xmm2, xmm1
-    pshufb      xmm1, [GLOBAL(shuf2b)]
-    pmaddubsw   xmm0, xmm4
-    pshufb      xmm2, [GLOBAL(shuf3b)]
-    pmaddubsw   xmm1, xmm5
-
-;--
-    pmaddubsw   xmm2, xmm6
-
-    lea         rsi,    [rsi + rax]
-;--
-    paddsw      xmm0, xmm1
-    paddsw      xmm0, xmm7
-    pxor        xmm1, xmm1
-    paddsw      xmm0, xmm2
-    psraw       xmm0, 7
-    packuswb    xmm0, xmm0
-
-    movd        DWORD PTR [rdi], xmm0
-
-    add         rdi, rdx
-    dec         rcx
-    jnz         .filter_block1d4_h6_rowloop_ssse3
-
-    ; begin epilog
-    pop rdi
-    pop rsi
-    RESTORE_GOT
-    RESTORE_XMM
-    UNSHADOW_ARGS
-    pop         rbp
-    ret
-
-.vp8_filter_block1d4_h4_ssse3:
-    movdqa      xmm5, XMMWORD PTR [rax+256]     ;k2_k4
-    movdqa      xmm6, XMMWORD PTR [rax+128]     ;k1_k3
-    movdqa      xmm0, XMMWORD PTR [GLOBAL(shuf2b)]
-    movdqa      xmm3, XMMWORD PTR [GLOBAL(shuf3b)]
-
-    mov         rsi, arg(0)             ;src_ptr
-    mov         rdi, arg(2)             ;output_ptr
-    movsxd      rax, dword ptr arg(1)   ;src_pixels_per_line
-    movsxd      rcx, dword ptr arg(4)   ;output_height
-
-    movsxd      rdx, dword ptr arg(3)   ;output_pitch
-
-.filter_block1d4_h4_rowloop_ssse3:
-    movdqu      xmm1,   XMMWORD PTR [rsi - 2]
-
-    movdqa      xmm2, xmm1
-    pshufb      xmm1, xmm0 ;;[GLOBAL(shuf2b)]
-    pshufb      xmm2, xmm3 ;;[GLOBAL(shuf3b)]
-    pmaddubsw   xmm1, xmm5
-
-;--
-    pmaddubsw   xmm2, xmm6
-
-    lea         rsi,    [rsi + rax]
-;--
-    paddsw      xmm1, xmm7
-    paddsw      xmm1, xmm2
-    psraw       xmm1, 7
-    packuswb    xmm1, xmm1
-
-    movd        DWORD PTR [rdi], xmm1
-
-    add         rdi, rdx
-    dec         rcx
-    jnz         .filter_block1d4_h4_rowloop_ssse3
-
-    ; begin epilog
-    pop rdi
-    pop rsi
-    RESTORE_GOT
-    RESTORE_XMM
-    UNSHADOW_ARGS
-    pop         rbp
-    ret
-
-
-
-;void vp8_filter_block1d16_v6_ssse3
-;(
-;    unsigned char *src_ptr,
-;    unsigned int   src_pitch,
-;    unsigned char *output_ptr,
-;    unsigned int   out_pitch,
-;    unsigned int   output_height,
-;    unsigned int   vp8_filter_index
-;)
-global sym(vp8_filter_block1d16_v6_ssse3) PRIVATE
-sym(vp8_filter_block1d16_v6_ssse3):
-    push        rbp
-    mov         rbp, rsp
-    SHADOW_ARGS_TO_STACK 6
-    SAVE_XMM 7
-    GET_GOT     rbx
-    push        rsi
-    push        rdi
-    ; end prolog
-
-    movsxd      rdx, DWORD PTR arg(5)   ;table index
-    xor         rsi, rsi
-    shl         rdx, 4      ;
-
-    lea         rax, [GLOBAL(k0_k5)]
-    add         rax, rdx
-
-    cmp         esi, DWORD PTR [rax]
-    je          .vp8_filter_block1d16_v4_ssse3
-
-    movdqa      xmm5, XMMWORD PTR [rax]         ;k0_k5
-    movdqa      xmm6, XMMWORD PTR [rax+256]     ;k2_k4
-    movdqa      xmm7, XMMWORD PTR [rax+128]     ;k1_k3
-
-    mov         rsi, arg(0)             ;src_ptr
-    movsxd      rdx, DWORD PTR arg(1)   ;pixels_per_line
-    mov         rdi, arg(2)             ;output_ptr
-
-%if ABI_IS_32BIT=0
-    movsxd      r8, DWORD PTR arg(3)    ;out_pitch
-%endif
-    mov         rax, rsi
-    movsxd      rcx, DWORD PTR arg(4)   ;output_height
-    add         rax, rdx
-
-
-.vp8_filter_block1d16_v6_ssse3_loop:
-    movq        xmm1, MMWORD PTR [rsi]                  ;A
-    movq        xmm2, MMWORD PTR [rsi + rdx]            ;B
-    movq        xmm3, MMWORD PTR [rsi + rdx * 2]        ;C
-    movq        xmm4, MMWORD PTR [rax + rdx * 2]        ;D
-    movq        xmm0, MMWORD PTR [rsi + rdx * 4]        ;E
-
-    punpcklbw   xmm2, xmm4                  ;B D
-    punpcklbw   xmm3, xmm0                  ;C E
-
-    movq        xmm0, MMWORD PTR [rax + rdx * 4]        ;F
-
-    pmaddubsw   xmm3, xmm6
-    punpcklbw   xmm1, xmm0                  ;A F
-    pmaddubsw   xmm2, xmm7
-    pmaddubsw   xmm1, xmm5
-
-    paddsw      xmm2, xmm3
-    paddsw      xmm2, xmm1
-    paddsw      xmm2, [GLOBAL(rd)]
-    psraw       xmm2, 7
-    packuswb    xmm2, xmm2
-
-    movq        MMWORD PTR [rdi], xmm2          ;store the results
-
-    movq        xmm1, MMWORD PTR [rsi + 8]                  ;A
-    movq        xmm2, MMWORD PTR [rsi + rdx + 8]            ;B
-    movq        xmm3, MMWORD PTR [rsi + rdx * 2 + 8]        ;C
-    movq        xmm4, MMWORD PTR [rax + rdx * 2 + 8]        ;D
-    movq        xmm0, MMWORD PTR [rsi + rdx * 4 + 8]        ;E
-
-    punpcklbw   xmm2, xmm4                  ;B D
-    punpcklbw   xmm3, xmm0                  ;C E
-
-    movq        xmm0, MMWORD PTR [rax + rdx * 4 + 8]        ;F
-    pmaddubsw   xmm3, xmm6
-    punpcklbw   xmm1, xmm0                  ;A F
-    pmaddubsw   xmm2, xmm7
-    pmaddubsw   xmm1, xmm5
-
-    add         rsi,  rdx
-    add         rax,  rdx
-;--
-;--
-    paddsw      xmm2, xmm3
-    paddsw      xmm2, xmm1
-    paddsw      xmm2, [GLOBAL(rd)]
-    psraw       xmm2, 7
-    packuswb    xmm2, xmm2
-
-    movq        MMWORD PTR [rdi+8], xmm2
-
-%if ABI_IS_32BIT
-    add         rdi,        DWORD PTR arg(3) ;out_pitch
-%else
-    add         rdi,        r8
-%endif
-    dec         rcx
-    jnz         .vp8_filter_block1d16_v6_ssse3_loop
-
-    ; begin epilog
-    pop rdi
-    pop rsi
-    RESTORE_GOT
-    RESTORE_XMM
-    UNSHADOW_ARGS
-    pop         rbp
-    ret
-
-.vp8_filter_block1d16_v4_ssse3:
-    movdqa      xmm6, XMMWORD PTR [rax+256]     ;k2_k4
-    movdqa      xmm7, XMMWORD PTR [rax+128]     ;k1_k3
-
-    mov         rsi, arg(0)             ;src_ptr
-    movsxd      rdx, DWORD PTR arg(1)   ;pixels_per_line
-    mov         rdi, arg(2)             ;output_ptr
-
-%if ABI_IS_32BIT=0
-    movsxd      r8, DWORD PTR arg(3)    ;out_pitch
-%endif
-    mov         rax, rsi
-    movsxd      rcx, DWORD PTR arg(4)   ;output_height
-    add         rax, rdx
-
-.vp8_filter_block1d16_v4_ssse3_loop:
-    movq        xmm2, MMWORD PTR [rsi + rdx]            ;B
-    movq        xmm3, MMWORD PTR [rsi + rdx * 2]        ;C
-    movq        xmm4, MMWORD PTR [rax + rdx * 2]        ;D
-    movq        xmm0, MMWORD PTR [rsi + rdx * 4]        ;E
-
-    punpcklbw   xmm2, xmm4                  ;B D
-    punpcklbw   xmm3, xmm0                  ;C E
-
-    pmaddubsw   xmm3, xmm6
-    pmaddubsw   xmm2, xmm7
-    movq        xmm5, MMWORD PTR [rsi + rdx + 8]            ;B
-    movq        xmm1, MMWORD PTR [rsi + rdx * 2 + 8]        ;C
-    movq        xmm4, MMWORD PTR [rax + rdx * 2 + 8]        ;D
-    movq        xmm0, MMWORD PTR [rsi + rdx * 4 + 8]        ;E
-
-    paddsw      xmm2, [GLOBAL(rd)]
-    paddsw      xmm2, xmm3
-    psraw       xmm2, 7
-    packuswb    xmm2, xmm2
-
-    punpcklbw   xmm5, xmm4                  ;B D
-    punpcklbw   xmm1, xmm0                  ;C E
-
-    pmaddubsw   xmm1, xmm6
-    pmaddubsw   xmm5, xmm7
-
-    movdqa      xmm4, [GLOBAL(rd)]
-    add         rsi,  rdx
-    add         rax,  rdx
-;--
-;--
-    paddsw      xmm5, xmm1
-    paddsw      xmm5, xmm4
-    psraw       xmm5, 7
-    packuswb    xmm5, xmm5
-
-    punpcklqdq  xmm2, xmm5
-
-    movdqa       XMMWORD PTR [rdi], xmm2
-
-%if ABI_IS_32BIT
-    add         rdi,        DWORD PTR arg(3) ;out_pitch
-%else
-    add         rdi,        r8
-%endif
-    dec         rcx
-    jnz         .vp8_filter_block1d16_v4_ssse3_loop
-
-    ; begin epilog
-    pop rdi
-    pop rsi
-    RESTORE_GOT
-    RESTORE_XMM
-    UNSHADOW_ARGS
-    pop         rbp
-    ret
-
-;void vp8_filter_block1d8_v6_ssse3
-;(
-;    unsigned char *src_ptr,
-;    unsigned int   src_pitch,
-;    unsigned char *output_ptr,
-;    unsigned int   out_pitch,
-;    unsigned int   output_height,
-;    unsigned int   vp8_filter_index
-;)
-global sym(vp8_filter_block1d8_v6_ssse3) PRIVATE
-sym(vp8_filter_block1d8_v6_ssse3):
-    push        rbp
-    mov         rbp, rsp
-    SHADOW_ARGS_TO_STACK 6
-    SAVE_XMM 7
-    GET_GOT     rbx
-    push        rsi
-    push        rdi
-    ; end prolog
-
-    movsxd      rdx, DWORD PTR arg(5)   ;table index
-    xor         rsi, rsi
-    shl         rdx, 4      ;
-
-    lea         rax, [GLOBAL(k0_k5)]
-    add         rax, rdx
-
-    movsxd      rdx, DWORD PTR arg(1)   ;pixels_per_line
-    mov         rdi, arg(2)             ;output_ptr
-%if ABI_IS_32BIT=0
-    movsxd      r8, DWORD PTR arg(3)    ; out_pitch
-%endif
-    movsxd      rcx, DWORD PTR arg(4)   ;[output_height]
-
-    cmp         esi, DWORD PTR [rax]
-    je          .vp8_filter_block1d8_v4_ssse3
-
-    movdqa      xmm5, XMMWORD PTR [rax]         ;k0_k5
-    movdqa      xmm6, XMMWORD PTR [rax+256]     ;k2_k4
-    movdqa      xmm7, XMMWORD PTR [rax+128]     ;k1_k3
-
-    mov         rsi, arg(0)             ;src_ptr
-
-    mov         rax, rsi
-    add         rax, rdx
-
-.vp8_filter_block1d8_v6_ssse3_loop:
-    movq        xmm1, MMWORD PTR [rsi]                  ;A
-    movq        xmm2, MMWORD PTR [rsi + rdx]            ;B
-    movq        xmm3, MMWORD PTR [rsi + rdx * 2]        ;C
-    movq        xmm4, MMWORD PTR [rax + rdx * 2]        ;D
-    movq        xmm0, MMWORD PTR [rsi + rdx * 4]        ;E
-
-    punpcklbw   xmm2, xmm4                  ;B D
-    punpcklbw   xmm3, xmm0                  ;C E
-
-    movq        xmm0, MMWORD PTR [rax + rdx * 4]        ;F
-    movdqa      xmm4, [GLOBAL(rd)]
-
-    pmaddubsw   xmm3, xmm6
-    punpcklbw   xmm1, xmm0                  ;A F
-    pmaddubsw   xmm2, xmm7
-    pmaddubsw   xmm1, xmm5
-    add         rsi,  rdx
-    add         rax,  rdx
-;--
-;--
-    paddsw      xmm2, xmm3
-    paddsw      xmm2, xmm1
-    paddsw      xmm2, xmm4
-    psraw       xmm2, 7
-    packuswb    xmm2, xmm2
-
-    movq        MMWORD PTR [rdi], xmm2
-
-%if ABI_IS_32BIT
-    add         rdi,        DWORD PTR arg(3) ;[out_pitch]
-%else
-    add         rdi,        r8
-%endif
-    dec         rcx
-    jnz         .vp8_filter_block1d8_v6_ssse3_loop
-
-    ; begin epilog
-    pop rdi
-    pop rsi
-    RESTORE_GOT
-    RESTORE_XMM
-    UNSHADOW_ARGS
-    pop         rbp
-    ret
-
-.vp8_filter_block1d8_v4_ssse3:
-    movdqa      xmm6, XMMWORD PTR [rax+256]     ;k2_k4
-    movdqa      xmm7, XMMWORD PTR [rax+128]     ;k1_k3
-    movdqa      xmm5, [GLOBAL(rd)]
-
-    mov         rsi, arg(0)             ;src_ptr
-
-    mov         rax, rsi
-    add         rax, rdx
-
-.vp8_filter_block1d8_v4_ssse3_loop:
-    movq        xmm2, MMWORD PTR [rsi + rdx]            ;B
-    movq        xmm3, MMWORD PTR [rsi + rdx * 2]        ;C
-    movq        xmm4, MMWORD PTR [rax + rdx * 2]        ;D
-    movq        xmm0, MMWORD PTR [rsi + rdx * 4]        ;E
-
-    punpcklbw   xmm2, xmm4                  ;B D
-    punpcklbw   xmm3, xmm0                  ;C E
-
-    pmaddubsw   xmm3, xmm6
-    pmaddubsw   xmm2, xmm7
-    add         rsi,  rdx
-    add         rax,  rdx
-;--
-;--
-    paddsw      xmm2, xmm3
-    paddsw      xmm2, xmm5
-    psraw       xmm2, 7
-    packuswb    xmm2, xmm2
-
-    movq        MMWORD PTR [rdi], xmm2
-
-%if ABI_IS_32BIT
-    add         rdi,        DWORD PTR arg(3) ;[out_pitch]
-%else
-    add         rdi,        r8
-%endif
-    dec         rcx
-    jnz         .vp8_filter_block1d8_v4_ssse3_loop
-
-    ; begin epilog
-    pop rdi
-    pop rsi
-    RESTORE_GOT
-    RESTORE_XMM
-    UNSHADOW_ARGS
-    pop         rbp
-    ret
-;void vp8_filter_block1d4_v6_ssse3
-;(
-;    unsigned char *src_ptr,
-;    unsigned int   src_pitch,
-;    unsigned char *output_ptr,
-;    unsigned int   out_pitch,
-;    unsigned int   output_height,
-;    unsigned int   vp8_filter_index
-;)
-global sym(vp8_filter_block1d4_v6_ssse3) PRIVATE
-sym(vp8_filter_block1d4_v6_ssse3):
-    push        rbp
-    mov         rbp, rsp
-    SHADOW_ARGS_TO_STACK 6
-    GET_GOT     rbx
-    push        rsi
-    push        rdi
-    ; end prolog
-
-    movsxd      rdx, DWORD PTR arg(5)   ;table index
-    xor         rsi, rsi
-    shl         rdx, 4      ;
-
-    lea         rax, [GLOBAL(k0_k5)]
-    add         rax, rdx
-
-    movsxd      rdx, DWORD PTR arg(1)   ;pixels_per_line
-    mov         rdi, arg(2)             ;output_ptr
-%if ABI_IS_32BIT=0
-    movsxd      r8, DWORD PTR arg(3)    ; out_pitch
-%endif
-    movsxd      rcx, DWORD PTR arg(4)   ;[output_height]
-
-    cmp         esi, DWORD PTR [rax]
-    je          .vp8_filter_block1d4_v4_ssse3
-
-    movq        mm5, MMWORD PTR [rax]         ;k0_k5
-    movq        mm6, MMWORD PTR [rax+256]     ;k2_k4
-    movq        mm7, MMWORD PTR [rax+128]     ;k1_k3
-
-    mov         rsi, arg(0)             ;src_ptr
-
-    mov         rax, rsi
-    add         rax, rdx
-
-.vp8_filter_block1d4_v6_ssse3_loop:
-    movd        mm1, DWORD PTR [rsi]                  ;A
-    movd        mm2, DWORD PTR [rsi + rdx]            ;B
-    movd        mm3, DWORD PTR [rsi + rdx * 2]        ;C
-    movd        mm4, DWORD PTR [rax + rdx * 2]        ;D
-    movd        mm0, DWORD PTR [rsi + rdx * 4]        ;E
-
-    punpcklbw   mm2, mm4                  ;B D
-    punpcklbw   mm3, mm0                  ;C E
-
-    movd        mm0, DWORD PTR [rax + rdx * 4]        ;F
-
-    movq        mm4, [GLOBAL(rd)]
-
-    pmaddubsw   mm3, mm6
-    punpcklbw   mm1, mm0                  ;A F
-    pmaddubsw   mm2, mm7
-    pmaddubsw   mm1, mm5
-    add         rsi,  rdx
-    add         rax,  rdx
-;--
-;--
-    paddsw      mm2, mm3
-    paddsw      mm2, mm1
-    paddsw      mm2, mm4
-    psraw       mm2, 7
-    packuswb    mm2, mm2
-
-    movd        DWORD PTR [rdi], mm2
-
-%if ABI_IS_32BIT
-    add         rdi,        DWORD PTR arg(3) ;[out_pitch]
-%else
-    add         rdi,        r8
-%endif
-    dec         rcx
-    jnz         .vp8_filter_block1d4_v6_ssse3_loop
-
-    ; begin epilog
-    pop rdi
-    pop rsi
-    RESTORE_GOT
-    UNSHADOW_ARGS
-    pop         rbp
-    ret
-
-.vp8_filter_block1d4_v4_ssse3:
-    movq        mm6, MMWORD PTR [rax+256]     ;k2_k4
-    movq        mm7, MMWORD PTR [rax+128]     ;k1_k3
-    movq        mm5, MMWORD PTR [GLOBAL(rd)]
-
-    mov         rsi, arg(0)             ;src_ptr
-
-    mov         rax, rsi
-    add         rax, rdx
-
-.vp8_filter_block1d4_v4_ssse3_loop:
-    movd        mm2, DWORD PTR [rsi + rdx]            ;B
-    movd        mm3, DWORD PTR [rsi + rdx * 2]        ;C
-    movd        mm4, DWORD PTR [rax + rdx * 2]        ;D
-    movd        mm0, DWORD PTR [rsi + rdx * 4]        ;E
-
-    punpcklbw   mm2, mm4                  ;B D
-    punpcklbw   mm3, mm0                  ;C E
-
-    pmaddubsw   mm3, mm6
-    pmaddubsw   mm2, mm7
-    add         rsi,  rdx
-    add         rax,  rdx
-;--
-;--
-    paddsw      mm2, mm3
-    paddsw      mm2, mm5
-    psraw       mm2, 7
-    packuswb    mm2, mm2
-
-    movd        DWORD PTR [rdi], mm2
-
-%if ABI_IS_32BIT
-    add         rdi,        DWORD PTR arg(3) ;[out_pitch]
-%else
-    add         rdi,        r8
-%endif
-    dec         rcx
-    jnz         .vp8_filter_block1d4_v4_ssse3_loop
-
-    ; begin epilog
-    pop rdi
-    pop rsi
-    RESTORE_GOT
-    UNSHADOW_ARGS
-    pop         rbp
-    ret
-
-;void vp8_bilinear_predict16x16_ssse3
-;(
-;    unsigned char  *src_ptr,
-;    int   src_pixels_per_line,
-;    int  xoffset,
-;    int  yoffset,
-;    unsigned char *dst_ptr,
-;    int dst_pitch
-;)
-global sym(vp8_bilinear_predict16x16_ssse3) PRIVATE
-sym(vp8_bilinear_predict16x16_ssse3):
-    push        rbp
-    mov         rbp, rsp
-    SHADOW_ARGS_TO_STACK 6
-    SAVE_XMM 7
-    GET_GOT     rbx
-    push        rsi
-    push        rdi
-    ; end prolog
-
-        lea         rcx,        [GLOBAL(vp8_bilinear_filters_ssse3)]
-        movsxd      rax,        dword ptr arg(2)    ; xoffset
-
-        cmp         rax,        0                   ; skip first_pass filter if xoffset=0
-        je          .b16x16_sp_only
-
-        shl         rax,        4
-        lea         rax,        [rax + rcx]         ; HFilter
-
-        mov         rdi,        arg(4)              ; dst_ptr
-        mov         rsi,        arg(0)              ; src_ptr
-        movsxd      rdx,        dword ptr arg(5)    ; dst_pitch
-
-        movdqa      xmm1,       [rax]
-
-        movsxd      rax,        dword ptr arg(3)    ; yoffset
-
-        cmp         rax,        0                   ; skip second_pass filter if yoffset=0
-        je          .b16x16_fp_only
-
-        shl         rax,        4
-        lea         rax,        [rax + rcx]         ; VFilter
-
-        lea         rcx,        [rdi+rdx*8]
-        lea         rcx,        [rcx+rdx*8]
-        movsxd      rdx,        dword ptr arg(1)    ; src_pixels_per_line
-
-        movdqa      xmm2,       [rax]
-
-%if ABI_IS_32BIT=0
-        movsxd      r8,         dword ptr arg(5)    ; dst_pitch
-%endif
-        movq        xmm3,       [rsi]               ; 00 01 02 03 04 05 06 07
-        movq        xmm5,       [rsi+1]             ; 01 02 03 04 05 06 07 08
-
-        punpcklbw   xmm3,       xmm5                ; 00 01 01 02 02 03 03 04 04 05 05 06 06 07 07 08
-        movq        xmm4,       [rsi+8]             ; 08 09 10 11 12 13 14 15
-
-        movq        xmm5,       [rsi+9]             ; 09 10 11 12 13 14 15 16
-
-        lea         rsi,        [rsi + rdx]         ; next line
-
-        pmaddubsw   xmm3,       xmm1                ; 00 02 04 06 08 10 12 14
-
-        punpcklbw   xmm4,       xmm5                ; 08 09 09 10 10 11 11 12 12 13 13 14 14 15 15 16
-        pmaddubsw   xmm4,       xmm1                ; 01 03 05 07 09 11 13 15
-
-        paddw       xmm3,       [GLOBAL(rd)]        ; xmm3 += round value
-        psraw       xmm3,       VP8_FILTER_SHIFT    ; xmm3 /= 128
-
-        paddw       xmm4,       [GLOBAL(rd)]        ; xmm4 += round value
-        psraw       xmm4,       VP8_FILTER_SHIFT    ; xmm4 /= 128
-
-        movdqa      xmm7,       xmm3
-        packuswb    xmm7,       xmm4                ; 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15
-
-.next_row:
-        movq        xmm6,       [rsi]               ; 00 01 02 03 04 05 06 07
-        movq        xmm5,       [rsi+1]             ; 01 02 03 04 05 06 07 08
-
-        punpcklbw   xmm6,       xmm5
-        movq        xmm4,       [rsi+8]             ; 08 09 10 11 12 13 14 15
-
-        movq        xmm5,       [rsi+9]             ; 09 10 11 12 13 14 15 16
-        lea         rsi,        [rsi + rdx]         ; next line
-
-        pmaddubsw   xmm6,       xmm1
-
-        punpcklbw   xmm4,       xmm5
-        pmaddubsw   xmm4,       xmm1
-
-        paddw       xmm6,       [GLOBAL(rd)]        ; xmm6 += round value
-        psraw       xmm6,       VP8_FILTER_SHIFT    ; xmm6 /= 128
-
-        paddw       xmm4,       [GLOBAL(rd)]        ; xmm4 += round value
-        psraw       xmm4,       VP8_FILTER_SHIFT    ; xmm4 /= 128
-
-        packuswb    xmm6,       xmm4
-        movdqa      xmm5,       xmm7
-
-        punpcklbw   xmm5,       xmm6
-        pmaddubsw   xmm5,       xmm2
-
-        punpckhbw   xmm7,       xmm6
-        pmaddubsw   xmm7,       xmm2
-
-        paddw       xmm5,       [GLOBAL(rd)]        ; xmm5 += round value
-        psraw       xmm5,       VP8_FILTER_SHIFT    ; xmm5 /= 128
-
-        paddw       xmm7,       [GLOBAL(rd)]        ; xmm7 += round value
-        psraw       xmm7,       VP8_FILTER_SHIFT    ; xmm7 /= 128
-
-        packuswb    xmm5,       xmm7
-        movdqa      xmm7,       xmm6
-
-        movdqa      [rdi],      xmm5                ; store the results in the destination
-%if ABI_IS_32BIT
-        add         rdi,        DWORD PTR arg(5)    ; dst_pitch
-%else
-        add         rdi,        r8
-%endif
-
-        cmp         rdi,        rcx
-        jne         .next_row
-
-        jmp         .done
-
-.b16x16_sp_only:
-        movsxd      rax,        dword ptr arg(3)    ; yoffset
-        shl         rax,        4
-        lea         rax,        [rax + rcx]         ; VFilter
-
-        mov         rdi,        arg(4)              ; dst_ptr
-        mov         rsi,        arg(0)              ; src_ptr
-        movsxd      rdx,        dword ptr arg(5)    ; dst_pitch
-
-        movdqa      xmm1,       [rax]               ; VFilter
-
-        lea         rcx,        [rdi+rdx*8]
-        lea         rcx,        [rcx+rdx*8]
-        movsxd      rax,        dword ptr arg(1)    ; src_pixels_per_line
-
-        ; get the first horizontal line done
-        movq        xmm4,       [rsi]               ; load row 0
-        movq        xmm2,       [rsi + 8]           ; load row 0
-
-        lea         rsi,        [rsi + rax]         ; next line
-.next_row_sp:
-        movq        xmm3,       [rsi]               ; load row + 1
-        movq        xmm5,       [rsi + 8]           ; load row + 1
-
-        punpcklbw   xmm4,       xmm3
-        punpcklbw   xmm2,       xmm5
-
-        pmaddubsw   xmm4,       xmm1
-        movq        xmm7,       [rsi + rax]         ; load row + 2
-
-        pmaddubsw   xmm2,       xmm1
-        movq        xmm6,       [rsi + rax + 8]     ; load row + 2
-
-        punpcklbw   xmm3,       xmm7
-        punpcklbw   xmm5,       xmm6
-
-        pmaddubsw   xmm3,       xmm1
-        paddw       xmm4,       [GLOBAL(rd)]
-
-        pmaddubsw   xmm5,       xmm1
-        paddw       xmm2,       [GLOBAL(rd)]
-
-        psraw       xmm4,       VP8_FILTER_SHIFT
-        psraw       xmm2,       VP8_FILTER_SHIFT
-
-        packuswb    xmm4,       xmm2
-        paddw       xmm3,       [GLOBAL(rd)]
-
-        movdqa      [rdi],      xmm4                ; store row 0
-        paddw       xmm5,       [GLOBAL(rd)]
-
-        psraw       xmm3,       VP8_FILTER_SHIFT
-        psraw       xmm5,       VP8_FILTER_SHIFT
-
-        packuswb    xmm3,       xmm5
-        movdqa      xmm4,       xmm7
-
-        movdqa      [rdi + rdx],xmm3                ; store row 1
-        lea         rsi,        [rsi + 2*rax]
-
-        movdqa      xmm2,       xmm6
-        lea         rdi,        [rdi + 2*rdx]
-
-        cmp         rdi,        rcx
-        jne         .next_row_sp
-
-        jmp         .done
-
-.b16x16_fp_only:
-        lea         rcx,        [rdi+rdx*8]
-        lea         rcx,        [rcx+rdx*8]
-        movsxd      rax,        dword ptr arg(1)    ; src_pixels_per_line
-
-.next_row_fp:
-        movq        xmm2,       [rsi]               ; 00 01 02 03 04 05 06 07
-        movq        xmm4,       [rsi+1]             ; 01 02 03 04 05 06 07 08
-
-        punpcklbw   xmm2,       xmm4
-        movq        xmm3,       [rsi+8]             ; 08 09 10 11 12 13 14 15
-
-        pmaddubsw   xmm2,       xmm1
-        movq        xmm4,       [rsi+9]             ; 09 10 11 12 13 14 15 16
-
-        lea         rsi,        [rsi + rax]         ; next line
-        punpcklbw   xmm3,       xmm4
-
-        pmaddubsw   xmm3,       xmm1
-        movq        xmm5,       [rsi]
-
-        paddw       xmm2,       [GLOBAL(rd)]
-        movq        xmm7,       [rsi+1]
-
-        movq        xmm6,       [rsi+8]
-        psraw       xmm2,       VP8_FILTER_SHIFT
-
-        punpcklbw   xmm5,       xmm7
-        movq        xmm7,       [rsi+9]
-
-        paddw       xmm3,       [GLOBAL(rd)]
-        pmaddubsw   xmm5,       xmm1
-
-        psraw       xmm3,       VP8_FILTER_SHIFT
-        punpcklbw   xmm6,       xmm7
-
-        packuswb    xmm2,       xmm3
-        pmaddubsw   xmm6,       xmm1
-
-        movdqa      [rdi],      xmm2                ; store the results in the destination
-        paddw       xmm5,       [GLOBAL(rd)]
-
-        lea         rdi,        [rdi + rdx]         ; dst_pitch
-        psraw       xmm5,       VP8_FILTER_SHIFT
-
-        paddw       xmm6,       [GLOBAL(rd)]
-        psraw       xmm6,       VP8_FILTER_SHIFT
-
-        packuswb    xmm5,       xmm6
-        lea         rsi,        [rsi + rax]         ; next line
-
-        movdqa      [rdi],      xmm5                ; store the results in the destination
-        lea         rdi,        [rdi + rdx]         ; dst_pitch
-
-        cmp         rdi,        rcx
-
-        jne         .next_row_fp
-
-.done:
-    ; begin epilog
-    pop         rdi
-    pop         rsi
-    RESTORE_GOT
-    RESTORE_XMM
-    UNSHADOW_ARGS
-    pop         rbp
-    ret
-
-;void vp8_bilinear_predict8x8_ssse3
-;(
-;    unsigned char  *src_ptr,
-;    int   src_pixels_per_line,
-;    int  xoffset,
-;    int  yoffset,
-;    unsigned char *dst_ptr,
-;    int dst_pitch
-;)
-global sym(vp8_bilinear_predict8x8_ssse3) PRIVATE
-sym(vp8_bilinear_predict8x8_ssse3):
-    push        rbp
-    mov         rbp, rsp
-    SHADOW_ARGS_TO_STACK 6
-    SAVE_XMM 7
-    GET_GOT     rbx
-    push        rsi
-    push        rdi
-    ; end prolog
-
-    ALIGN_STACK 16, rax
-    sub         rsp, 144                         ; reserve 144 bytes
-
-        lea         rcx,        [GLOBAL(vp8_bilinear_filters_ssse3)]
-
-        mov         rsi,        arg(0) ;src_ptr
-        movsxd      rdx,        dword ptr arg(1) ;src_pixels_per_line
-
-    ;Read 9-line unaligned data in and put them on stack. This gives a big
-    ;performance boost.
-        movdqu      xmm0,       [rsi]
-        lea         rax,        [rdx + rdx*2]
-        movdqu      xmm1,       [rsi+rdx]
-        movdqu      xmm2,       [rsi+rdx*2]
-        add         rsi,        rax
-        movdqu      xmm3,       [rsi]
-        movdqu      xmm4,       [rsi+rdx]
-        movdqu      xmm5,       [rsi+rdx*2]
-        add         rsi,        rax
-        movdqu      xmm6,       [rsi]
-        movdqu      xmm7,       [rsi+rdx]
-
-        movdqa      XMMWORD PTR [rsp],            xmm0
-
-        movdqu      xmm0,       [rsi+rdx*2]
-
-        movdqa      XMMWORD PTR [rsp+16],         xmm1
-        movdqa      XMMWORD PTR [rsp+32],         xmm2
-        movdqa      XMMWORD PTR [rsp+48],         xmm3
-        movdqa      XMMWORD PTR [rsp+64],         xmm4
-        movdqa      XMMWORD PTR [rsp+80],         xmm5
-        movdqa      XMMWORD PTR [rsp+96],         xmm6
-        movdqa      XMMWORD PTR [rsp+112],        xmm7
-        movdqa      XMMWORD PTR [rsp+128],        xmm0
-
-        movsxd      rax,        dword ptr arg(2)    ; xoffset
-        cmp         rax,        0                   ; skip first_pass filter if xoffset=0
-        je          .b8x8_sp_only
-
-        shl         rax,        4
-        add         rax,        rcx                 ; HFilter
-
-        mov         rdi,        arg(4)              ; dst_ptr
-        movsxd      rdx,        dword ptr arg(5)    ; dst_pitch
-
-        movdqa      xmm0,       [rax]
-
-        movsxd      rax,        dword ptr arg(3)    ; yoffset
-        cmp         rax,        0                   ; skip second_pass filter if yoffset=0
-        je          .b8x8_fp_only
-
-        shl         rax,        4
-        lea         rax,        [rax + rcx]         ; VFilter
-
-        lea         rcx,        [rdi+rdx*8]
-
-        movdqa      xmm1,       [rax]
-
-        ; get the first horizontal line done
-        movdqa      xmm3,       [rsp]               ; 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15
-        movdqa      xmm5,       xmm3                ; 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 xx
-
-        psrldq      xmm5,       1
-        lea         rsp,        [rsp + 16]          ; next line
-
-        punpcklbw   xmm3,       xmm5                ; 00 01 01 02 02 03 03 04 04 05 05 06 06 07 07 08
-        pmaddubsw   xmm3,       xmm0                ; 00 02 04 06 08 10 12 14
-
-        paddw       xmm3,       [GLOBAL(rd)]        ; xmm3 += round value
-        psraw       xmm3,       VP8_FILTER_SHIFT    ; xmm3 /= 128
-
-        movdqa      xmm7,       xmm3
-        packuswb    xmm7,       xmm7                ; 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15
-
-.next_row:
-        movdqa      xmm6,       [rsp]               ; 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15
-        lea         rsp,        [rsp + 16]          ; next line
-
-        movdqa      xmm5,       xmm6
-
-        psrldq      xmm5,       1
-
-        punpcklbw   xmm6,       xmm5
-        pmaddubsw   xmm6,       xmm0
-
-        paddw       xmm6,       [GLOBAL(rd)]        ; xmm6 += round value
-        psraw       xmm6,       VP8_FILTER_SHIFT    ; xmm6 /= 128
-
-        packuswb    xmm6,       xmm6
-
-        punpcklbw   xmm7,       xmm6
-        pmaddubsw   xmm7,       xmm1
-
-        paddw       xmm7,       [GLOBAL(rd)]        ; xmm7 += round value
-        psraw       xmm7,       VP8_FILTER_SHIFT    ; xmm7 /= 128
-
-        packuswb    xmm7,       xmm7
-
-        movq        [rdi],      xmm7                ; store the results in the destination
-        lea         rdi,        [rdi + rdx]
-
-        movdqa      xmm7,       xmm6
-
-        cmp         rdi,        rcx
-        jne         .next_row
-
-        jmp         .done8x8
-
-.b8x8_sp_only:
-        movsxd      rax,        dword ptr arg(3)    ; yoffset
-        shl         rax,        4
-        lea         rax,        [rax + rcx]         ; VFilter
-
-        mov         rdi,        arg(4) ;dst_ptr
-        movsxd      rdx,        dword ptr arg(5)    ; dst_pitch
-
-        movdqa      xmm0,       [rax]               ; VFilter
-
-        movq        xmm1,       XMMWORD PTR [rsp]
-        movq        xmm2,       XMMWORD PTR [rsp+16]
-
-        movq        xmm3,       XMMWORD PTR [rsp+32]
-        punpcklbw   xmm1,       xmm2
-
-        movq        xmm4,       XMMWORD PTR [rsp+48]
-        punpcklbw   xmm2,       xmm3
-
-        movq        xmm5,       XMMWORD PTR [rsp+64]
-        punpcklbw   xmm3,       xmm4
-
-        movq        xmm6,       XMMWORD PTR [rsp+80]
-        punpcklbw   xmm4,       xmm5
-
-        movq        xmm7,       XMMWORD PTR [rsp+96]
-        punpcklbw   xmm5,       xmm6
-
-        pmaddubsw   xmm1,       xmm0
-        pmaddubsw   xmm2,       xmm0
-
-        pmaddubsw   xmm3,       xmm0
-        pmaddubsw   xmm4,       xmm0
-
-        pmaddubsw   xmm5,       xmm0
-        punpcklbw   xmm6,       xmm7
-
-        pmaddubsw   xmm6,       xmm0
-        paddw       xmm1,       [GLOBAL(rd)]
-
-        paddw       xmm2,       [GLOBAL(rd)]
-        psraw       xmm1,       VP8_FILTER_SHIFT
-
-        paddw       xmm3,       [GLOBAL(rd)]
-        psraw       xmm2,       VP8_FILTER_SHIFT
-
-        paddw       xmm4,       [GLOBAL(rd)]
-        psraw       xmm3,       VP8_FILTER_SHIFT
-
-        paddw       xmm5,       [GLOBAL(rd)]
-        psraw       xmm4,       VP8_FILTER_SHIFT
-
-        paddw       xmm6,       [GLOBAL(rd)]
-        psraw       xmm5,       VP8_FILTER_SHIFT
-
-        psraw       xmm6,       VP8_FILTER_SHIFT
-        packuswb    xmm1,       xmm1
-
-        packuswb    xmm2,       xmm2
-        movq        [rdi],      xmm1
-
-        packuswb    xmm3,       xmm3
-        movq        [rdi+rdx],  xmm2
-
-        packuswb    xmm4,       xmm4
-        movq        xmm1,       XMMWORD PTR [rsp+112]
-
-        lea         rdi,        [rdi + 2*rdx]
-        movq        xmm2,       XMMWORD PTR [rsp+128]
-
-        packuswb    xmm5,       xmm5
-        movq        [rdi],      xmm3
-
-        packuswb    xmm6,       xmm6
-        movq        [rdi+rdx],  xmm4
-
-        lea         rdi,        [rdi + 2*rdx]
-        punpcklbw   xmm7,       xmm1
-
-        movq        [rdi],      xmm5
-        pmaddubsw   xmm7,       xmm0
-
-        movq        [rdi+rdx],  xmm6
-        punpcklbw   xmm1,       xmm2
-
-        pmaddubsw   xmm1,       xmm0
-        paddw       xmm7,       [GLOBAL(rd)]
-
-        psraw       xmm7,       VP8_FILTER_SHIFT
-        paddw       xmm1,       [GLOBAL(rd)]
-
-        psraw       xmm1,       VP8_FILTER_SHIFT
-        packuswb    xmm7,       xmm7
-
-        packuswb    xmm1,       xmm1
-        lea         rdi,        [rdi + 2*rdx]
-
-        movq        [rdi],      xmm7
-
-        movq        [rdi+rdx],  xmm1
-        lea         rsp,        [rsp + 144]
-
-        jmp         .done8x8
-
-.b8x8_fp_only:
-        lea         rcx,        [rdi+rdx*8]
-
-.next_row_fp:
-        movdqa      xmm1,       XMMWORD PTR [rsp]
-        movdqa      xmm3,       XMMWORD PTR [rsp+16]
-
-        movdqa      xmm2,       xmm1
-        movdqa      xmm5,       XMMWORD PTR [rsp+32]
-
-        psrldq      xmm2,       1
-        movdqa      xmm7,       XMMWORD PTR [rsp+48]
-
-        movdqa      xmm4,       xmm3
-        psrldq      xmm4,       1
-
-        movdqa      xmm6,       xmm5
-        psrldq      xmm6,       1
-
-        punpcklbw   xmm1,       xmm2
-        pmaddubsw   xmm1,       xmm0
-
-        punpcklbw   xmm3,       xmm4
-        pmaddubsw   xmm3,       xmm0
-
-        punpcklbw   xmm5,       xmm6
-        pmaddubsw   xmm5,       xmm0
-
-        movdqa      xmm2,       xmm7
-        psrldq      xmm2,       1
-
-        punpcklbw   xmm7,       xmm2
-        pmaddubsw   xmm7,       xmm0
-
-        paddw       xmm1,       [GLOBAL(rd)]
-        psraw       xmm1,       VP8_FILTER_SHIFT
-
-        paddw       xmm3,       [GLOBAL(rd)]
-        psraw       xmm3,       VP8_FILTER_SHIFT
-
-        paddw       xmm5,       [GLOBAL(rd)]
-        psraw       xmm5,       VP8_FILTER_SHIFT
-
-        paddw       xmm7,       [GLOBAL(rd)]
-        psraw       xmm7,       VP8_FILTER_SHIFT
-
-        packuswb    xmm1,       xmm1
-        packuswb    xmm3,       xmm3
-
-        packuswb    xmm5,       xmm5
-        movq        [rdi],      xmm1
-
-        packuswb    xmm7,       xmm7
-        movq        [rdi+rdx],  xmm3
-
-        lea         rdi,        [rdi + 2*rdx]
-        movq        [rdi],      xmm5
-
-        lea         rsp,        [rsp + 4*16]
-        movq        [rdi+rdx],  xmm7
-
-        lea         rdi,        [rdi + 2*rdx]
-        cmp         rdi,        rcx
-
-        jne         .next_row_fp
-
-        lea         rsp,        [rsp + 16]
-
-.done8x8:
-    ;add rsp, 144
-    pop         rsp
-    ; begin epilog
-    pop         rdi
-    pop         rsi
-    RESTORE_GOT
-    RESTORE_XMM
-    UNSHADOW_ARGS
-    pop         rbp
-    ret
-
-SECTION_RODATA
-align 16
-shuf1b:
-    db 0, 5, 1, 6, 2, 7, 3, 8, 4, 9, 5, 10, 6, 11, 7, 12
-shuf2b:
-    db 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10, 9, 11
-shuf3b:
-    db 1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10
-
-align 16
-shuf2bfrom1:
-    db  4, 8, 6, 1, 8, 3, 1, 5, 3, 7, 5, 9, 7,11, 9,13
-align 16
-shuf3bfrom1:
-    db  2, 6, 4, 8, 6, 1, 8, 3, 1, 5, 3, 7, 5, 9, 7,11
-
-align 16
-rd:
-    times 8 dw 0x40
-
-align 16
-k0_k5:
-    times 8 db 0, 0             ;placeholder
-    times 8 db 0, 0
-    times 8 db 2, 1
-    times 8 db 0, 0
-    times 8 db 3, 3
-    times 8 db 0, 0
-    times 8 db 1, 2
-    times 8 db 0, 0
-k1_k3:
-    times 8 db  0,    0         ;placeholder
-    times 8 db  -6,  12
-    times 8 db -11,  36
-    times 8 db  -9,  50
-    times 8 db -16,  77
-    times 8 db  -6,  93
-    times 8 db  -8, 108
-    times 8 db  -1, 123
-k2_k4:
-    times 8 db 128,    0        ;placeholder
-    times 8 db 123,   -1
-    times 8 db 108,   -8
-    times 8 db  93,   -6
-    times 8 db  77,  -16
-    times 8 db  50,   -9
-    times 8 db  36,  -11
-    times 8 db  12,   -6
-align 16
-vp8_bilinear_filters_ssse3:
-    times 8 db 128, 0
-    times 8 db 112, 16
-    times 8 db 96,  32
-    times 8 db 80,  48
-    times 8 db 64,  64
-    times 8 db 48,  80
-    times 8 db 32,  96
-    times 8 db 16,  112
-
diff --git a/vp8/common/x86/vp8_asm_stubs.c b/vp8/common/x86/vp8_asm_stubs.c
deleted file mode 100644 (file)
index fb0b57e..0000000
+++ /dev/null
@@ -1,625 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#include "vpx_config.h"
-#include "vp8_rtcd.h"
-#include "vpx_ports/mem.h"
-#include "filter_x86.h"
-
-extern const short vp8_six_tap_mmx[8][6*8];
-
-extern void vp8_filter_block1d_h6_mmx
-(
-    unsigned char   *src_ptr,
-    unsigned short  *output_ptr,
-    unsigned int    src_pixels_per_line,
-    unsigned int    pixel_step,
-    unsigned int    output_height,
-    unsigned int    output_width,
-    const short      *vp8_filter
-);
-extern void vp8_filter_block1dc_v6_mmx
-(
-    unsigned short *src_ptr,
-    unsigned char  *output_ptr,
-    int             output_pitch,
-    unsigned int    pixels_per_line,
-    unsigned int    pixel_step,
-    unsigned int    output_height,
-    unsigned int    output_width,
-    const short    *vp8_filter
-);
-extern void vp8_filter_block1d8_h6_sse2
-(
-    unsigned char  *src_ptr,
-    unsigned short *output_ptr,
-    unsigned int    src_pixels_per_line,
-    unsigned int    pixel_step,
-    unsigned int    output_height,
-    unsigned int    output_width,
-    const short    *vp8_filter
-);
-extern void vp8_filter_block1d16_h6_sse2
-(
-    unsigned char  *src_ptr,
-    unsigned short *output_ptr,
-    unsigned int    src_pixels_per_line,
-    unsigned int    pixel_step,
-    unsigned int    output_height,
-    unsigned int    output_width,
-    const short    *vp8_filter
-);
-extern void vp8_filter_block1d8_v6_sse2
-(
-    unsigned short *src_ptr,
-    unsigned char *output_ptr,
-    int dst_ptich,
-    unsigned int pixels_per_line,
-    unsigned int pixel_step,
-    unsigned int output_height,
-    unsigned int output_width,
-    const short    *vp8_filter
-);
-extern void vp8_filter_block1d16_v6_sse2
-(
-    unsigned short *src_ptr,
-    unsigned char *output_ptr,
-    int dst_ptich,
-    unsigned int pixels_per_line,
-    unsigned int pixel_step,
-    unsigned int output_height,
-    unsigned int output_width,
-    const short    *vp8_filter
-);
-extern void vp8_unpack_block1d16_h6_sse2
-(
-    unsigned char  *src_ptr,
-    unsigned short *output_ptr,
-    unsigned int    src_pixels_per_line,
-    unsigned int    output_height,
-    unsigned int    output_width
-);
-extern void vp8_filter_block1d8_h6_only_sse2
-(
-    unsigned char  *src_ptr,
-    unsigned int    src_pixels_per_line,
-    unsigned char  *output_ptr,
-    int dst_ptich,
-    unsigned int    output_height,
-    const short    *vp8_filter
-);
-extern void vp8_filter_block1d16_h6_only_sse2
-(
-    unsigned char  *src_ptr,
-    unsigned int    src_pixels_per_line,
-    unsigned char  *output_ptr,
-    int dst_ptich,
-    unsigned int    output_height,
-    const short    *vp8_filter
-);
-extern void vp8_filter_block1d8_v6_only_sse2
-(
-    unsigned char *src_ptr,
-    unsigned int   src_pixels_per_line,
-    unsigned char *output_ptr,
-    int dst_ptich,
-    unsigned int   output_height,
-    const short   *vp8_filter
-);
-
-
-#if HAVE_MMX
-void vp8_sixtap_predict4x4_mmx
-(
-    unsigned char  *src_ptr,
-    int   src_pixels_per_line,
-    int  xoffset,
-    int  yoffset,
-    unsigned char *dst_ptr,
-    int dst_pitch
-)
-{
-    DECLARE_ALIGNED(16, unsigned short, FData2[16*16]);  /* Temp data bufffer used in filtering */
-    const short *HFilter, *VFilter;
-    HFilter = vp8_six_tap_mmx[xoffset];
-    vp8_filter_block1d_h6_mmx(src_ptr - (2 * src_pixels_per_line), FData2, src_pixels_per_line, 1, 9, 8, HFilter);
-    VFilter = vp8_six_tap_mmx[yoffset];
-    vp8_filter_block1dc_v6_mmx(FData2 + 8, dst_ptr, dst_pitch, 8, 4 , 4, 4, VFilter);
-
-}
-
-
-void vp8_sixtap_predict16x16_mmx
-(
-    unsigned char  *src_ptr,
-    int   src_pixels_per_line,
-    int  xoffset,
-    int  yoffset,
-    unsigned char *dst_ptr,
-    int dst_pitch
-)
-{
-
-    DECLARE_ALIGNED(16, unsigned short, FData2[24*24]);  /* Temp data bufffer used in filtering */
-
-    const short *HFilter, *VFilter;
-
-
-    HFilter = vp8_six_tap_mmx[xoffset];
-
-    vp8_filter_block1d_h6_mmx(src_ptr - (2 * src_pixels_per_line),    FData2,   src_pixels_per_line, 1, 21, 32, HFilter);
-    vp8_filter_block1d_h6_mmx(src_ptr - (2 * src_pixels_per_line) + 4,  FData2 + 4, src_pixels_per_line, 1, 21, 32, HFilter);
-    vp8_filter_block1d_h6_mmx(src_ptr - (2 * src_pixels_per_line) + 8,  FData2 + 8, src_pixels_per_line, 1, 21, 32, HFilter);
-    vp8_filter_block1d_h6_mmx(src_ptr - (2 * src_pixels_per_line) + 12, FData2 + 12, src_pixels_per_line, 1, 21, 32, HFilter);
-
-    VFilter = vp8_six_tap_mmx[yoffset];
-    vp8_filter_block1dc_v6_mmx(FData2 + 32, dst_ptr,   dst_pitch, 32, 16 , 16, 16, VFilter);
-    vp8_filter_block1dc_v6_mmx(FData2 + 36, dst_ptr + 4, dst_pitch, 32, 16 , 16, 16, VFilter);
-    vp8_filter_block1dc_v6_mmx(FData2 + 40, dst_ptr + 8, dst_pitch, 32, 16 , 16, 16, VFilter);
-    vp8_filter_block1dc_v6_mmx(FData2 + 44, dst_ptr + 12, dst_pitch, 32, 16 , 16, 16, VFilter);
-
-}
-
-
-void vp8_sixtap_predict8x8_mmx
-(
-    unsigned char  *src_ptr,
-    int   src_pixels_per_line,
-    int  xoffset,
-    int  yoffset,
-    unsigned char *dst_ptr,
-    int dst_pitch
-)
-{
-
-    DECLARE_ALIGNED(16, unsigned short, FData2[256]);    /* Temp data bufffer used in filtering */
-
-    const short *HFilter, *VFilter;
-
-    HFilter = vp8_six_tap_mmx[xoffset];
-    vp8_filter_block1d_h6_mmx(src_ptr - (2 * src_pixels_per_line),    FData2,   src_pixels_per_line, 1, 13, 16, HFilter);
-    vp8_filter_block1d_h6_mmx(src_ptr - (2 * src_pixels_per_line) + 4,  FData2 + 4, src_pixels_per_line, 1, 13, 16, HFilter);
-
-    VFilter = vp8_six_tap_mmx[yoffset];
-    vp8_filter_block1dc_v6_mmx(FData2 + 16, dst_ptr,   dst_pitch, 16, 8 , 8, 8, VFilter);
-    vp8_filter_block1dc_v6_mmx(FData2 + 20, dst_ptr + 4, dst_pitch, 16, 8 , 8, 8, VFilter);
-
-}
-
-
-void vp8_sixtap_predict8x4_mmx
-(
-    unsigned char  *src_ptr,
-    int   src_pixels_per_line,
-    int  xoffset,
-    int  yoffset,
-    unsigned char *dst_ptr,
-    int dst_pitch
-)
-{
-
-    DECLARE_ALIGNED(16, unsigned short, FData2[256]);    /* Temp data bufffer used in filtering */
-
-    const short *HFilter, *VFilter;
-
-    HFilter = vp8_six_tap_mmx[xoffset];
-    vp8_filter_block1d_h6_mmx(src_ptr - (2 * src_pixels_per_line),    FData2,   src_pixels_per_line, 1, 9, 16, HFilter);
-    vp8_filter_block1d_h6_mmx(src_ptr - (2 * src_pixels_per_line) + 4,  FData2 + 4, src_pixels_per_line, 1, 9, 16, HFilter);
-
-    VFilter = vp8_six_tap_mmx[yoffset];
-    vp8_filter_block1dc_v6_mmx(FData2 + 16, dst_ptr,   dst_pitch, 16, 8 , 4, 8, VFilter);
-    vp8_filter_block1dc_v6_mmx(FData2 + 20, dst_ptr + 4, dst_pitch, 16, 8 , 4, 8, VFilter);
-
-}
-
-
-
-void vp8_bilinear_predict16x16_mmx
-(
-    unsigned char  *src_ptr,
-    int   src_pixels_per_line,
-    int  xoffset,
-    int  yoffset,
-    unsigned char *dst_ptr,
-    int dst_pitch
-)
-{
-    vp8_bilinear_predict8x8_mmx(src_ptr,   src_pixels_per_line, xoffset, yoffset, dst_ptr,   dst_pitch);
-    vp8_bilinear_predict8x8_mmx(src_ptr + 8, src_pixels_per_line, xoffset, yoffset, dst_ptr + 8, dst_pitch);
-    vp8_bilinear_predict8x8_mmx(src_ptr + 8 * src_pixels_per_line,   src_pixels_per_line, xoffset, yoffset, dst_ptr + dst_pitch * 8,   dst_pitch);
-    vp8_bilinear_predict8x8_mmx(src_ptr + 8 * src_pixels_per_line + 8, src_pixels_per_line, xoffset, yoffset, dst_ptr + dst_pitch * 8 + 8, dst_pitch);
-}
-#endif
-
-
-#if HAVE_SSE2
-void vp8_sixtap_predict16x16_sse2
-(
-    unsigned char  *src_ptr,
-    int   src_pixels_per_line,
-    int  xoffset,
-    int  yoffset,
-    unsigned char *dst_ptr,
-    int dst_pitch
-
-)
-{
-    DECLARE_ALIGNED(16, unsigned short, FData2[24*24]);    /* Temp data bufffer used in filtering */
-
-    const short *HFilter, *VFilter;
-
-    if (xoffset)
-    {
-        if (yoffset)
-        {
-            HFilter = vp8_six_tap_mmx[xoffset];
-            vp8_filter_block1d16_h6_sse2(src_ptr - (2 * src_pixels_per_line), FData2,   src_pixels_per_line, 1, 21, 32, HFilter);
-            VFilter = vp8_six_tap_mmx[yoffset];
-            vp8_filter_block1d16_v6_sse2(FData2 + 32, dst_ptr,   dst_pitch, 32, 16 , 16, dst_pitch, VFilter);
-        }
-        else
-        {
-            /* First-pass only */
-            HFilter = vp8_six_tap_mmx[xoffset];
-            vp8_filter_block1d16_h6_only_sse2(src_ptr, src_pixels_per_line, dst_ptr, dst_pitch, 16, HFilter);
-        }
-    }
-    else
-    {
-        /* Second-pass only */
-        VFilter = vp8_six_tap_mmx[yoffset];
-        vp8_unpack_block1d16_h6_sse2(src_ptr - (2 * src_pixels_per_line), FData2,   src_pixels_per_line, 21, 32);
-        vp8_filter_block1d16_v6_sse2(FData2 + 32, dst_ptr,   dst_pitch, 32, 16 , 16, dst_pitch, VFilter);
-    }
-}
-
-
-void vp8_sixtap_predict8x8_sse2
-(
-    unsigned char  *src_ptr,
-    int   src_pixels_per_line,
-    int  xoffset,
-    int  yoffset,
-    unsigned char *dst_ptr,
-    int dst_pitch
-)
-{
-    DECLARE_ALIGNED(16, unsigned short, FData2[256]);  /* Temp data bufffer used in filtering */
-    const short *HFilter, *VFilter;
-
-    if (xoffset)
-    {
-        if (yoffset)
-        {
-            HFilter = vp8_six_tap_mmx[xoffset];
-            vp8_filter_block1d8_h6_sse2(src_ptr - (2 * src_pixels_per_line), FData2,   src_pixels_per_line, 1, 13, 16, HFilter);
-            VFilter = vp8_six_tap_mmx[yoffset];
-            vp8_filter_block1d8_v6_sse2(FData2 + 16, dst_ptr,   dst_pitch, 16, 8 , 8, dst_pitch, VFilter);
-        }
-        else
-        {
-            /* First-pass only */
-            HFilter = vp8_six_tap_mmx[xoffset];
-            vp8_filter_block1d8_h6_only_sse2(src_ptr, src_pixels_per_line, dst_ptr, dst_pitch, 8, HFilter);
-        }
-    }
-    else
-    {
-        /* Second-pass only */
-        VFilter = vp8_six_tap_mmx[yoffset];
-        vp8_filter_block1d8_v6_only_sse2(src_ptr - (2 * src_pixels_per_line), src_pixels_per_line, dst_ptr, dst_pitch, 8, VFilter);
-    }
-}
-
-
-void vp8_sixtap_predict8x4_sse2
-(
-    unsigned char  *src_ptr,
-    int   src_pixels_per_line,
-    int  xoffset,
-    int  yoffset,
-    unsigned char *dst_ptr,
-    int dst_pitch
-)
-{
-    DECLARE_ALIGNED(16, unsigned short, FData2[256]);  /* Temp data bufffer used in filtering */
-    const short *HFilter, *VFilter;
-
-    if (xoffset)
-    {
-        if (yoffset)
-        {
-            HFilter = vp8_six_tap_mmx[xoffset];
-            vp8_filter_block1d8_h6_sse2(src_ptr - (2 * src_pixels_per_line), FData2,   src_pixels_per_line, 1, 9, 16, HFilter);
-            VFilter = vp8_six_tap_mmx[yoffset];
-            vp8_filter_block1d8_v6_sse2(FData2 + 16, dst_ptr,   dst_pitch, 16, 8 , 4, dst_pitch, VFilter);
-        }
-        else
-        {
-            /* First-pass only */
-            HFilter = vp8_six_tap_mmx[xoffset];
-            vp8_filter_block1d8_h6_only_sse2(src_ptr, src_pixels_per_line, dst_ptr, dst_pitch, 4, HFilter);
-        }
-    }
-    else
-    {
-        /* Second-pass only */
-        VFilter = vp8_six_tap_mmx[yoffset];
-        vp8_filter_block1d8_v6_only_sse2(src_ptr - (2 * src_pixels_per_line), src_pixels_per_line, dst_ptr, dst_pitch, 4, VFilter);
-    }
-}
-
-#endif
-
-#if HAVE_SSSE3
-
-extern void vp8_filter_block1d8_h6_ssse3
-(
-    unsigned char  *src_ptr,
-    unsigned int    src_pixels_per_line,
-    unsigned char  *output_ptr,
-    unsigned int    output_pitch,
-    unsigned int    output_height,
-    unsigned int    vp8_filter_index
-);
-
-extern void vp8_filter_block1d16_h6_ssse3
-(
-    unsigned char  *src_ptr,
-    unsigned int    src_pixels_per_line,
-    unsigned char  *output_ptr,
-    unsigned int    output_pitch,
-    unsigned int    output_height,
-    unsigned int    vp8_filter_index
-);
-
-extern void vp8_filter_block1d16_v6_ssse3
-(
-    unsigned char *src_ptr,
-    unsigned int   src_pitch,
-    unsigned char *output_ptr,
-    unsigned int   out_pitch,
-    unsigned int   output_height,
-    unsigned int   vp8_filter_index
-);
-
-extern void vp8_filter_block1d8_v6_ssse3
-(
-    unsigned char *src_ptr,
-    unsigned int   src_pitch,
-    unsigned char *output_ptr,
-    unsigned int   out_pitch,
-    unsigned int   output_height,
-    unsigned int   vp8_filter_index
-);
-
-extern void vp8_filter_block1d4_h6_ssse3
-(
-    unsigned char  *src_ptr,
-    unsigned int    src_pixels_per_line,
-    unsigned char  *output_ptr,
-    unsigned int    output_pitch,
-    unsigned int    output_height,
-    unsigned int    vp8_filter_index
-);
-
-extern void vp8_filter_block1d4_v6_ssse3
-(
-    unsigned char *src_ptr,
-    unsigned int   src_pitch,
-    unsigned char *output_ptr,
-    unsigned int   out_pitch,
-    unsigned int   output_height,
-    unsigned int   vp8_filter_index
-);
-
-void vp8_sixtap_predict16x16_ssse3
-(
-    unsigned char  *src_ptr,
-    int   src_pixels_per_line,
-    int  xoffset,
-    int  yoffset,
-    unsigned char *dst_ptr,
-    int dst_pitch
-
-)
-{
-    DECLARE_ALIGNED(16, unsigned char, FData2[24*24]);
-
-    if (xoffset)
-    {
-        if (yoffset)
-        {
-            vp8_filter_block1d16_h6_ssse3(src_ptr - (2 * src_pixels_per_line),
-                                          src_pixels_per_line, FData2,
-                                          16, 21, xoffset);
-            vp8_filter_block1d16_v6_ssse3(FData2 , 16, dst_ptr, dst_pitch,
-                                          16, yoffset);
-        }
-        else
-        {
-            /* First-pass only */
-            vp8_filter_block1d16_h6_ssse3(src_ptr, src_pixels_per_line,
-                                          dst_ptr, dst_pitch, 16, xoffset);
-        }
-    }
-    else
-    {
-        if (yoffset)
-        {
-            /* Second-pass only */
-            vp8_filter_block1d16_v6_ssse3(src_ptr - (2 * src_pixels_per_line),
-                                          src_pixels_per_line,
-                                          dst_ptr, dst_pitch, 16, yoffset);
-        }
-        else
-        {
-            /* ssse3 second-pass only function couldn't handle (xoffset==0 &&
-             * yoffset==0) case correctly. Add copy function here to guarantee
-             * six-tap function handles all possible offsets. */
-            vp8_copy_mem16x16(src_ptr, src_pixels_per_line, dst_ptr, dst_pitch);
-        }
-    }
-}
-
-void vp8_sixtap_predict8x8_ssse3
-(
-    unsigned char  *src_ptr,
-    int   src_pixels_per_line,
-    int  xoffset,
-    int  yoffset,
-    unsigned char *dst_ptr,
-    int dst_pitch
-)
-{
-    DECLARE_ALIGNED(16, unsigned char, FData2[256]);
-
-    if (xoffset)
-    {
-        if (yoffset)
-        {
-            vp8_filter_block1d8_h6_ssse3(src_ptr - (2 * src_pixels_per_line),
-                                         src_pixels_per_line, FData2,
-                                         8, 13, xoffset);
-            vp8_filter_block1d8_v6_ssse3(FData2, 8, dst_ptr, dst_pitch,
-                                         8, yoffset);
-        }
-        else
-        {
-            vp8_filter_block1d8_h6_ssse3(src_ptr, src_pixels_per_line,
-                                         dst_ptr, dst_pitch, 8, xoffset);
-        }
-    }
-    else
-    {
-        if (yoffset)
-        {
-            /* Second-pass only */
-            vp8_filter_block1d8_v6_ssse3(src_ptr - (2 * src_pixels_per_line),
-                                         src_pixels_per_line,
-                                         dst_ptr, dst_pitch, 8, yoffset);
-        }
-        else
-        {
-            /* ssse3 second-pass only function couldn't handle (xoffset==0 &&
-             * yoffset==0) case correctly. Add copy function here to guarantee
-             * six-tap function handles all possible offsets. */
-            vp8_copy_mem8x8(src_ptr, src_pixels_per_line, dst_ptr, dst_pitch);
-        }
-    }
-}
-
-
-void vp8_sixtap_predict8x4_ssse3
-(
-    unsigned char  *src_ptr,
-    int   src_pixels_per_line,
-    int  xoffset,
-    int  yoffset,
-    unsigned char *dst_ptr,
-    int dst_pitch
-)
-{
-    DECLARE_ALIGNED(16, unsigned char, FData2[256]);
-
-    if (xoffset)
-    {
-        if (yoffset)
-        {
-            vp8_filter_block1d8_h6_ssse3(src_ptr - (2 * src_pixels_per_line),
-                                         src_pixels_per_line, FData2,
-                                         8, 9, xoffset);
-            vp8_filter_block1d8_v6_ssse3(FData2, 8, dst_ptr, dst_pitch,
-                                         4, yoffset);
-        }
-        else
-        {
-            /* First-pass only */
-            vp8_filter_block1d8_h6_ssse3(src_ptr, src_pixels_per_line,
-                                         dst_ptr, dst_pitch, 4, xoffset);
-        }
-    }
-    else
-    {
-        if (yoffset)
-        {
-            /* Second-pass only */
-            vp8_filter_block1d8_v6_ssse3(src_ptr - (2 * src_pixels_per_line),
-                                         src_pixels_per_line,
-                                         dst_ptr, dst_pitch, 4, yoffset);
-        }
-        else
-        {
-            /* ssse3 second-pass only function couldn't handle (xoffset==0 &&
-             * yoffset==0) case correctly. Add copy function here to guarantee
-             * six-tap function handles all possible offsets. */
-            vp8_copy_mem8x4(src_ptr, src_pixels_per_line, dst_ptr, dst_pitch);
-        }
-    }
-}
-
-void vp8_sixtap_predict4x4_ssse3
-(
-    unsigned char  *src_ptr,
-    int   src_pixels_per_line,
-    int  xoffset,
-    int  yoffset,
-    unsigned char *dst_ptr,
-    int dst_pitch
-)
-{
-  DECLARE_ALIGNED(16, unsigned char, FData2[4*9]);
-
-  if (xoffset)
-  {
-      if (yoffset)
-      {
-          vp8_filter_block1d4_h6_ssse3(src_ptr - (2 * src_pixels_per_line),
-                                       src_pixels_per_line,
-                                       FData2, 4, 9, xoffset);
-          vp8_filter_block1d4_v6_ssse3(FData2, 4, dst_ptr, dst_pitch,
-                                       4, yoffset);
-      }
-      else
-      {
-          vp8_filter_block1d4_h6_ssse3(src_ptr, src_pixels_per_line,
-                                       dst_ptr, dst_pitch, 4, xoffset);
-      }
-  }
-  else
-  {
-      if (yoffset)
-      {
-          vp8_filter_block1d4_v6_ssse3(src_ptr - (2 * src_pixels_per_line),
-                                       src_pixels_per_line,
-                                       dst_ptr, dst_pitch, 4, yoffset);
-      }
-      else
-      {
-        /* ssse3 second-pass only function couldn't handle (xoffset==0 &&
-          * yoffset==0) case correctly. Add copy function here to guarantee
-          * six-tap function handles all possible offsets. */
-          int r;
-
-          for (r = 0; r < 4; r++)
-          {
-            dst_ptr[0]  = src_ptr[0];
-            dst_ptr[1]  = src_ptr[1];
-            dst_ptr[2]  = src_ptr[2];
-            dst_ptr[3]  = src_ptr[3];
-            dst_ptr     += dst_pitch;
-            src_ptr     += src_pixels_per_line;
-          }
-      }
-  }
-}
-
-#endif
diff --git a/vp8/common/x86/vp8_loopfilter_mmx.asm b/vp8/common/x86/vp8_loopfilter_mmx.asm
deleted file mode 100644 (file)
index 88a07b9..0000000
+++ /dev/null
@@ -1,1753 +0,0 @@
-;
-;  Copyright (c) 2010 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.
-;
-
-
-%include "vpx_ports/x86_abi_support.asm"
-
-
-;void vp8_loop_filter_horizontal_edge_mmx
-;(
-;    unsigned char *src_ptr,
-;    int src_pixel_step,
-;    const char *blimit,
-;    const char *limit,
-;    const char *thresh,
-;    int  count
-;)
-global sym(vp8_loop_filter_horizontal_edge_mmx) PRIVATE
-sym(vp8_loop_filter_horizontal_edge_mmx):
-    push        rbp
-    mov         rbp, rsp
-    SHADOW_ARGS_TO_STACK 6
-    GET_GOT     rbx
-    push        rsi
-    push        rdi
-    ; end prolog
-
-    ALIGN_STACK 16, rax
-    sub         rsp, 32                         ; reserve 32 bytes
-    %define t0 [rsp + 0]    ;__declspec(align(16)) char t0[8];
-    %define t1 [rsp + 16]   ;__declspec(align(16)) char t1[8];
-
-        mov         rsi, arg(0) ;src_ptr
-        movsxd      rax, dword ptr arg(1) ;src_pixel_step     ; destination pitch?
-
-        movsxd      rcx, dword ptr arg(5) ;count
-.next8_h:
-        mov         rdx, arg(3) ;limit
-        movq        mm7, [rdx]
-        mov         rdi, rsi              ; rdi points to row +1 for indirect addressing
-        add         rdi, rax
-
-        ; calculate breakout conditions
-        movq        mm2, [rdi+2*rax]      ; q3
-        movq        mm1, [rsi+2*rax]      ; q2
-        movq        mm6, mm1              ; q2
-        psubusb     mm1, mm2              ; q2-=q3
-        psubusb     mm2, mm6              ; q3-=q2
-        por         mm1, mm2              ; abs(q3-q2)
-        psubusb     mm1, mm7              ;
-
-
-        movq        mm4, [rsi+rax]        ; q1
-        movq        mm3, mm4              ; q1
-        psubusb     mm4, mm6              ; q1-=q2
-        psubusb     mm6, mm3              ; q2-=q1
-        por         mm4, mm6              ; abs(q2-q1)
-
-        psubusb     mm4, mm7
-        por        mm1, mm4
-
-        movq        mm4, [rsi]            ; q0
-        movq        mm0, mm4              ; q0
-        psubusb     mm4, mm3              ; q0-=q1
-        psubusb     mm3, mm0              ; q1-=q0
-        por         mm4, mm3              ; abs(q0-q1)
-        movq        t0, mm4               ; save to t0
-        psubusb     mm4, mm7
-        por        mm1, mm4
-
-
-        neg         rax                   ; negate pitch to deal with above border
-
-        movq        mm2, [rsi+4*rax]      ; p3
-        movq        mm4, [rdi+4*rax]      ; p2
-        movq        mm5, mm4              ; p2
-        psubusb     mm4, mm2              ; p2-=p3
-        psubusb     mm2, mm5              ; p3-=p2
-        por         mm4, mm2              ; abs(p3 - p2)
-        psubusb     mm4, mm7
-        por        mm1, mm4
-
-
-        movq        mm4, [rsi+2*rax]      ; p1
-        movq        mm3, mm4              ; p1
-        psubusb     mm4, mm5              ; p1-=p2
-        psubusb     mm5, mm3              ; p2-=p1
-        por         mm4, mm5              ; abs(p2 - p1)
-        psubusb     mm4, mm7
-        por        mm1, mm4
-
-        movq        mm2, mm3              ; p1
-
-        movq        mm4, [rsi+rax]        ; p0
-        movq        mm5, mm4              ; p0
-        psubusb     mm4, mm3              ; p0-=p1
-        psubusb     mm3, mm5              ; p1-=p0
-        por         mm4, mm3              ; abs(p1 - p0)
-        movq        t1, mm4               ; save to t1
-        psubusb     mm4, mm7
-        por        mm1, mm4
-
-        movq        mm3, [rdi]            ; q1
-        movq        mm4, mm3              ; q1
-        psubusb     mm3, mm2              ; q1-=p1
-        psubusb     mm2, mm4              ; p1-=q1
-        por         mm2, mm3              ; abs(p1-q1)
-        pand        mm2, [GLOBAL(tfe)]    ; set lsb of each byte to zero
-        psrlw       mm2, 1                ; abs(p1-q1)/2
-
-        movq        mm6, mm5              ; p0
-        movq        mm3, [rsi]            ; q0
-        psubusb     mm5, mm3              ; p0-=q0
-        psubusb     mm3, mm6              ; q0-=p0
-        por         mm5, mm3              ; abs(p0 - q0)
-        paddusb     mm5, mm5              ; abs(p0-q0)*2
-        paddusb     mm5, mm2              ; abs (p0 - q0) *2 + abs(p1-q1)/2
-
-        mov         rdx, arg(2) ;blimit           ; get blimit
-        movq        mm7, [rdx]            ; blimit
-
-        psubusb     mm5,    mm7           ; abs (p0 - q0) *2 + abs(p1-q1)/2  > blimit
-        por         mm1,    mm5
-        pxor        mm5,    mm5
-        pcmpeqb     mm1,    mm5           ; mask mm1
-
-        ; calculate high edge variance
-        mov         rdx, arg(4) ;thresh           ; get thresh
-        movq        mm7, [rdx]            ;
-        movq        mm4, t0               ; get abs (q1 - q0)
-        psubusb     mm4, mm7
-        movq        mm3, t1               ; get abs (p1 - p0)
-        psubusb     mm3, mm7
-        paddb       mm4, mm3              ; abs(q1 - q0) > thresh || abs(p1 - p0) > thresh
-
-        pcmpeqb     mm4,        mm5
-
-        pcmpeqb     mm5,        mm5
-        pxor        mm4,        mm5
-
-
-        ; start work on filters
-        movq        mm2, [rsi+2*rax]      ; p1
-        movq        mm7, [rdi]            ; q1
-        pxor        mm2, [GLOBAL(t80)]    ; p1 offset to convert to signed values
-        pxor        mm7, [GLOBAL(t80)]    ; q1 offset to convert to signed values
-        psubsb      mm2, mm7              ; p1 - q1
-        pand        mm2, mm4              ; high var mask (hvm)(p1 - q1)
-        pxor        mm6, [GLOBAL(t80)]    ; offset to convert to signed values
-        pxor        mm0, [GLOBAL(t80)]    ; offset to convert to signed values
-        movq        mm3, mm0              ; q0
-        psubsb      mm0, mm6              ; q0 - p0
-        paddsb      mm2, mm0              ; 1 * (q0 - p0) + hvm(p1 - q1)
-        paddsb      mm2, mm0              ; 2 * (q0 - p0) + hvm(p1 - q1)
-        paddsb      mm2, mm0              ; 3 * (q0 - p0) + hvm(p1 - q1)
-        pand        mm1, mm2                  ; mask filter values we don't care about
-        movq        mm2, mm1
-        paddsb      mm1, [GLOBAL(t4)]     ; 3* (q0 - p0) + hvm(p1 - q1) + 4
-        paddsb      mm2, [GLOBAL(t3)]     ; 3* (q0 - p0) + hvm(p1 - q1) + 3
-
-        pxor        mm0, mm0             ;
-        pxor        mm5, mm5
-        punpcklbw   mm0, mm2            ;
-        punpckhbw   mm5, mm2            ;
-        psraw       mm0, 11             ;
-        psraw       mm5, 11
-        packsswb    mm0, mm5
-        movq        mm2, mm0            ;  (3* (q0 - p0) + hvm(p1 - q1) + 3) >> 3;
-
-        pxor        mm0, mm0              ; 0
-        movq        mm5, mm1              ; abcdefgh
-        punpcklbw   mm0, mm1              ; e0f0g0h0
-        psraw       mm0, 11               ; sign extended shift right by 3
-        pxor        mm1, mm1              ; 0
-        punpckhbw   mm1, mm5              ; a0b0c0d0
-        psraw       mm1, 11               ; sign extended shift right by 3
-        movq        mm5, mm0              ; save results
-
-        packsswb    mm0, mm1              ; (3* (q0 - p0) + hvm(p1 - q1) + 4) >>3
-        paddsw      mm5, [GLOBAL(ones)]
-        paddsw      mm1, [GLOBAL(ones)]
-        psraw       mm5, 1                ; partial shifted one more time for 2nd tap
-        psraw       mm1, 1                ; partial shifted one more time for 2nd tap
-        packsswb    mm5, mm1              ; (3* (q0 - p0) + hvm(p1 - q1) + 4) >>4
-        pandn       mm4, mm5              ; high edge variance additive
-
-        paddsb      mm6, mm2              ; p0+= p0 add
-        pxor        mm6, [GLOBAL(t80)]    ; unoffset
-        movq        [rsi+rax], mm6        ; write back
-
-        movq        mm6, [rsi+2*rax]      ; p1
-        pxor        mm6, [GLOBAL(t80)]    ; reoffset
-        paddsb      mm6, mm4              ; p1+= p1 add
-        pxor        mm6, [GLOBAL(t80)]    ; unoffset
-        movq        [rsi+2*rax], mm6      ; write back
-
-        psubsb      mm3, mm0              ; q0-= q0 add
-        pxor        mm3, [GLOBAL(t80)]    ; unoffset
-        movq        [rsi], mm3            ; write back
-
-        psubsb      mm7, mm4              ; q1-= q1 add
-        pxor        mm7, [GLOBAL(t80)]    ; unoffset
-        movq        [rdi], mm7            ; write back
-
-        add         rsi,8
-        neg         rax
-        dec         rcx
-        jnz         .next8_h
-
-    add rsp, 32
-    pop rsp
-    ; begin epilog
-    pop rdi
-    pop rsi
-    RESTORE_GOT
-    UNSHADOW_ARGS
-    pop         rbp
-    ret
-
-
-;void vp8_loop_filter_vertical_edge_mmx
-;(
-;    unsigned char *src_ptr,
-;    int  src_pixel_step,
-;    const char *blimit,
-;    const char *limit,
-;    const char *thresh,
-;    int count
-;)
-global sym(vp8_loop_filter_vertical_edge_mmx) PRIVATE
-sym(vp8_loop_filter_vertical_edge_mmx):
-    push        rbp
-    mov         rbp, rsp
-    SHADOW_ARGS_TO_STACK 6
-    GET_GOT     rbx
-    push        rsi
-    push        rdi
-    ; end prolog
-
-    ALIGN_STACK 16, rax
-    sub          rsp, 64      ; reserve 64 bytes
-    %define t0   [rsp + 0]    ;__declspec(align(16)) char t0[8];
-    %define t1   [rsp + 16]   ;__declspec(align(16)) char t1[8];
-    %define srct [rsp + 32]   ;__declspec(align(16)) char srct[32];
-
-        mov         rsi,        arg(0) ;src_ptr
-        movsxd      rax,        dword ptr arg(1) ;src_pixel_step     ; destination pitch?
-
-        lea         rsi,        [rsi + rax*4 - 4]
-
-        movsxd      rcx,        dword ptr arg(5) ;count
-.next8_v:
-        mov         rdi,        rsi           ; rdi points to row +1 for indirect addressing
-        add         rdi,        rax
-
-
-        ;transpose
-        movq        mm6,        [rsi+2*rax]                 ; 67 66 65 64 63 62 61 60
-        movq        mm7,        mm6                         ; 77 76 75 74 73 72 71 70
-
-        punpckhbw   mm7,        [rdi+2*rax]                 ; 77 67 76 66 75 65 74 64
-        punpcklbw   mm6,        [rdi+2*rax]                 ; 73 63 72 62 71 61 70 60
-
-        movq        mm4,        [rsi]                       ; 47 46 45 44 43 42 41 40
-        movq        mm5,        mm4                         ; 47 46 45 44 43 42 41 40
-
-        punpckhbw   mm5,        [rsi+rax]                   ; 57 47 56 46 55 45 54 44
-        punpcklbw   mm4,        [rsi+rax]                   ; 53 43 52 42 51 41 50 40
-
-        movq        mm3,        mm5                         ; 57 47 56 46 55 45 54 44
-        punpckhwd   mm5,        mm7                         ; 77 67 57 47 76 66 56 46
-
-        punpcklwd   mm3,        mm7                         ; 75 65 55 45 74 64 54 44
-        movq        mm2,        mm4                         ; 53 43 52 42 51 41 50 40
-
-        punpckhwd   mm4,        mm6                         ; 73 63 53 43 72 62 52 42
-        punpcklwd   mm2,        mm6                         ; 71 61 51 41 70 60 50 40
-
-        neg         rax
-        movq        mm6,        [rsi+rax*2]                 ; 27 26 25 24 23 22 21 20
-
-        movq        mm1,        mm6                         ; 27 26 25 24 23 22 21 20
-        punpckhbw   mm6,        [rsi+rax]                   ; 37 27 36 36 35 25 34 24
-
-        punpcklbw   mm1,        [rsi+rax]                   ; 33 23 32 22 31 21 30 20
-        movq        mm7,        [rsi+rax*4];                ; 07 06 05 04 03 02 01 00
-
-        punpckhbw   mm7,        [rdi+rax*4]                 ; 17 07 16 06 15 05 14 04
-        movq        mm0,        mm7                         ; 17 07 16 06 15 05 14 04
-
-        punpckhwd   mm7,        mm6                         ; 37 27 17 07 36 26 16 06
-        punpcklwd   mm0,        mm6                         ; 35 25 15 05 34 24 14 04
-
-        movq        mm6,        mm7                         ; 37 27 17 07 36 26 16 06
-        punpckhdq   mm7,        mm5                         ; 77 67 57 47 37 27 17 07  = q3
-
-        punpckldq   mm6,        mm5                         ; 76 66 56 46 36 26 16 06  = q2
-
-        movq        mm5,        mm6                         ; 76 66 56 46 36 26 16 06
-        psubusb     mm5,        mm7                         ; q2-q3
-
-        psubusb     mm7,        mm6                         ; q3-q2
-        por         mm7,        mm5;                        ; mm7=abs (q3-q2)
-
-        movq        mm5,        mm0                         ; 35 25 15 05 34 24 14 04
-        punpckhdq   mm5,        mm3                         ; 75 65 55 45 35 25 15 05 = q1
-
-        punpckldq   mm0,        mm3                         ; 74 64 54 44 34 24 15 04 = q0
-        movq        mm3,        mm5                         ; 75 65 55 45 35 25 15 05 = q1
-
-        psubusb     mm3,        mm6                         ; q1-q2
-        psubusb     mm6,        mm5                         ; q2-q1
-
-        por         mm6,        mm3                         ; mm6=abs(q2-q1)
-        lea         rdx,        srct
-
-        movq        [rdx+24],   mm5                         ; save q1
-        movq        [rdx+16],   mm0                         ; save q0
-
-        movq        mm3,        [rsi+rax*4]                 ; 07 06 05 04 03 02 01 00
-        punpcklbw   mm3,        [rdi+rax*4]                 ; 13 03 12 02 11 01 10 00
-
-        movq        mm0,        mm3                         ; 13 03 12 02 11 01 10 00
-        punpcklwd   mm0,        mm1                         ; 31 21 11 01 30 20 10 00
-
-        punpckhwd   mm3,        mm1                         ; 33 23 13 03 32 22 12 02
-        movq        mm1,        mm0                         ; 31 21 11 01 30 20 10 00
-
-        punpckldq   mm0,        mm2                         ; 70 60 50 40 30 20 10 00  =p3
-        punpckhdq   mm1,        mm2                         ; 71 61 51 41 31 21 11 01  =p2
-
-        movq        mm2,        mm1                         ; 71 61 51 41 31 21 11 01  =p2
-        psubusb     mm2,        mm0                         ; p2-p3
-
-        psubusb     mm0,        mm1                         ; p3-p2
-        por         mm0,        mm2                         ; mm0=abs(p3-p2)
-
-        movq        mm2,        mm3                         ; 33 23 13 03 32 22 12 02
-        punpckldq   mm2,        mm4                         ; 72 62 52 42 32 22 12 02 = p1
-
-        punpckhdq   mm3,        mm4                         ; 73 63 53 43 33 23 13 03 = p0
-        movq        [rdx+8],    mm3                         ; save p0
-
-        movq        [rdx],      mm2                         ; save p1
-        movq        mm5,        mm2                         ; mm5 = p1
-
-        psubusb     mm2,        mm1                         ; p1-p2
-        psubusb     mm1,        mm5                         ; p2-p1
-
-        por         mm1,        mm2                         ; mm1=abs(p2-p1)
-        mov         rdx,        arg(3) ;limit
-
-        movq        mm4,        [rdx]                       ; mm4 = limit
-        psubusb     mm7,        mm4
-
-        psubusb     mm0,        mm4
-        psubusb     mm1,        mm4
-
-        psubusb     mm6,        mm4
-        por         mm7,        mm6
-
-        por         mm0,        mm1
-        por         mm0,        mm7                         ;   abs(q3-q2) > limit || abs(p3-p2) > limit ||abs(p2-p1) > limit || abs(q2-q1) > limit
-
-        movq        mm1,        mm5                         ; p1
-
-        movq        mm7,        mm3                         ; mm3=mm7=p0
-        psubusb     mm7,        mm5                         ; p0 - p1
-
-        psubusb     mm5,        mm3                         ; p1 - p0
-        por         mm5,        mm7                         ; abs(p1-p0)
-
-        movq        t0,         mm5                         ; save abs(p1-p0)
-        lea         rdx,        srct
-
-        psubusb     mm5,        mm4
-        por         mm0,        mm5                         ; mm0=mask
-
-        movq        mm5,        [rdx+16]                    ; mm5=q0
-        movq        mm7,        [rdx+24]                    ; mm7=q1
-
-        movq        mm6,        mm5                         ; mm6=q0
-        movq        mm2,        mm7                         ; q1
-        psubusb     mm5,        mm7                         ; q0-q1
-
-        psubusb     mm7,        mm6                         ; q1-q0
-        por         mm7,        mm5                         ; abs(q1-q0)
-
-        movq        t1,         mm7                         ; save abs(q1-q0)
-        psubusb     mm7,        mm4
-
-        por         mm0,        mm7                         ; mask
-
-        movq        mm5,        mm2                         ; q1
-        psubusb     mm5,        mm1                         ; q1-=p1
-        psubusb     mm1,        mm2                         ; p1-=q1
-        por         mm5,        mm1                         ; abs(p1-q1)
-        pand        mm5,        [GLOBAL(tfe)]               ; set lsb of each byte to zero
-        psrlw       mm5,        1                           ; abs(p1-q1)/2
-
-        mov         rdx,        arg(2) ;blimit                      ;
-
-        movq        mm4,        [rdx]                       ;blimit
-        movq        mm1,        mm3                         ; mm1=mm3=p0
-
-        movq        mm7,        mm6                         ; mm7=mm6=q0
-        psubusb     mm1,        mm7                         ; p0-q0
-
-        psubusb     mm7,        mm3                         ; q0-p0
-        por         mm1,        mm7                         ; abs(q0-p0)
-        paddusb     mm1,        mm1                         ; abs(q0-p0)*2
-        paddusb     mm1,        mm5                         ; abs (p0 - q0) *2 + abs(p1-q1)/2
-
-        psubusb     mm1,        mm4                         ; abs (p0 - q0) *2 + abs(p1-q1)/2  > blimit
-        por         mm1,        mm0;                        ; mask
-
-        pxor        mm0,        mm0
-        pcmpeqb     mm1,        mm0
-
-        ; calculate high edge variance
-        mov         rdx,        arg(4) ;thresh            ; get thresh
-        movq        mm7,        [rdx]
-        ;
-        movq        mm4,        t0              ; get abs (q1 - q0)
-        psubusb     mm4,        mm7
-
-        movq        mm3,        t1              ; get abs (p1 - p0)
-        psubusb     mm3,        mm7
-
-        por         mm4,        mm3             ; abs(q1 - q0) > thresh || abs(p1 - p0) > thresh
-        pcmpeqb     mm4,        mm0
-
-        pcmpeqb     mm0,        mm0
-        pxor        mm4,        mm0
-
-
-
-        ; start work on filters
-        lea         rdx,        srct
-
-        movq        mm2,        [rdx]           ; p1
-        movq        mm7,        [rdx+24]        ; q1
-
-        movq        mm6,        [rdx+8]         ; p0
-        movq        mm0,        [rdx+16]        ; q0
-
-        pxor        mm2,        [GLOBAL(t80)]   ; p1 offset to convert to signed values
-        pxor        mm7,        [GLOBAL(t80)]   ; q1 offset to convert to signed values
-
-        psubsb      mm2,        mm7             ; p1 - q1
-        pand        mm2,        mm4             ; high var mask (hvm)(p1 - q1)
-
-        pxor        mm6,        [GLOBAL(t80)]   ; offset to convert to signed values
-        pxor        mm0,        [GLOBAL(t80)]   ; offset to convert to signed values
-
-        movq        mm3,        mm0             ; q0
-        psubsb      mm0,        mm6             ; q0 - p0
-
-        paddsb      mm2,        mm0             ; 1 * (q0 - p0) + hvm(p1 - q1)
-        paddsb      mm2,        mm0             ; 2 * (q0 - p0) + hvm(p1 - q1)
-
-        paddsb      mm2,        mm0             ; 3 * (q0 - p0) + hvm(p1 - q1)
-        pand       mm1,        mm2              ; mask filter values we don't care about
-
-        movq        mm2,        mm1
-        paddsb      mm1,        [GLOBAL(t4)]      ; 3* (q0 - p0) + hvm(p1 - q1) + 4
-
-        paddsb      mm2,        [GLOBAL(t3)]      ; 3* (q0 - p0) + hvm(p1 - q1) + 3
-        pxor        mm0,        mm0          ;
-
-        pxor        mm5,        mm5
-        punpcklbw   mm0,        mm2         ;
-
-        punpckhbw   mm5,        mm2         ;
-        psraw       mm0,        11              ;
-
-        psraw       mm5,        11
-        packsswb    mm0,        mm5
-
-        movq        mm2,        mm0         ;  (3* (q0 - p0) + hvm(p1 - q1) + 3) >> 3;
-
-        pxor        mm0,        mm0           ; 0
-        movq        mm5,        mm1           ; abcdefgh
-
-        punpcklbw   mm0,        mm1           ; e0f0g0h0
-        psraw       mm0,        11                ; sign extended shift right by 3
-
-        pxor        mm1,        mm1           ; 0
-        punpckhbw   mm1,        mm5           ; a0b0c0d0
-
-        psraw       mm1,        11                ; sign extended shift right by 3
-        movq        mm5,        mm0              ; save results
-
-        packsswb    mm0,        mm1           ; (3* (q0 - p0) + hvm(p1 - q1) + 4) >>3
-        paddsw      mm5,        [GLOBAL(ones)]
-
-        paddsw      mm1,        [GLOBAL(ones)]
-        psraw       mm5,        1                 ; partial shifted one more time for 2nd tap
-
-        psraw       mm1,        1                 ; partial shifted one more time for 2nd tap
-        packsswb    mm5,        mm1           ; (3* (q0 - p0) + hvm(p1 - q1) + 4) >>4
-
-        pandn       mm4,        mm5             ; high edge variance additive
-
-        paddsb      mm6,        mm2             ; p0+= p0 add
-        pxor        mm6,        [GLOBAL(t80)]   ; unoffset
-
-        ; mm6=p0                               ;
-        movq        mm1,        [rdx]           ; p1
-        pxor        mm1,        [GLOBAL(t80)]   ; reoffset
-
-        paddsb      mm1,        mm4                 ; p1+= p1 add
-        pxor        mm1,        [GLOBAL(t80)]       ; unoffset
-        ; mm6 = p0 mm1 = p1
-
-        psubsb      mm3,        mm0                 ; q0-= q0 add
-        pxor        mm3,        [GLOBAL(t80)]       ; unoffset
-
-        ; mm3 = q0
-        psubsb      mm7,        mm4                 ; q1-= q1 add
-        pxor        mm7,        [GLOBAL(t80)]       ; unoffset
-        ; mm7 = q1
-
-        ; transpose and write back
-        ; mm1 =    72 62 52 42 32 22 12 02
-        ; mm6 =    73 63 53 43 33 23 13 03
-        ; mm3 =    74 64 54 44 34 24 14 04
-        ; mm7 =    75 65 55 45 35 25 15 05
-
-        movq        mm2,        mm1             ; 72 62 52 42 32 22 12 02
-        punpcklbw   mm2,        mm6             ; 33 32 23 22 13 12 03 02
-
-        movq        mm4,        mm3             ; 74 64 54 44 34 24 14 04
-        punpckhbw   mm1,        mm6             ; 73 72 63 62 53 52 43 42
-
-        punpcklbw   mm4,        mm7             ; 35 34 25 24 15 14 05 04
-        punpckhbw   mm3,        mm7             ; 75 74 65 64 55 54 45 44
-
-        movq        mm6,        mm2             ; 33 32 23 22 13 12 03 02
-        punpcklwd   mm2,        mm4             ; 15 14 13 12 05 04 03 02
-
-        punpckhwd   mm6,        mm4             ; 35 34 33 32 25 24 23 22
-        movq        mm5,        mm1             ; 73 72 63 62 53 52 43 42
-
-        punpcklwd   mm1,        mm3             ; 55 54 53 52 45 44 43 42
-        punpckhwd   mm5,        mm3             ; 75 74 73 72 65 64 63 62
-
-
-        ; mm2 = 15 14 13 12 05 04 03 02
-        ; mm6 = 35 34 33 32 25 24 23 22
-        ; mm5 = 55 54 53 52 45 44 43 42
-        ; mm1 = 75 74 73 72 65 64 63 62
-
-
-
-        movd        [rsi+rax*4+2], mm2
-        psrlq       mm2,        32
-
-        movd        [rdi+rax*4+2], mm2
-        movd        [rsi+rax*2+2], mm6
-
-        psrlq       mm6,        32
-        movd        [rsi+rax+2],mm6
-
-        movd        [rsi+2],    mm1
-        psrlq       mm1,        32
-
-        movd        [rdi+2],    mm1
-        neg         rax
-
-        movd        [rdi+rax+2],mm5
-        psrlq       mm5,        32
-
-        movd        [rdi+rax*2+2], mm5
-
-        lea         rsi,        [rsi+rax*8]
-        dec         rcx
-        jnz         .next8_v
-
-    add rsp, 64
-    pop rsp
-    ; begin epilog
-    pop rdi
-    pop rsi
-    RESTORE_GOT
-    UNSHADOW_ARGS
-    pop         rbp
-    ret
-
-
-;void vp8_mbloop_filter_horizontal_edge_mmx
-;(
-;    unsigned char *src_ptr,
-;    int  src_pixel_step,
-;    const char *blimit,
-;    const char *limit,
-;    const char *thresh,
-;    int count
-;)
-global sym(vp8_mbloop_filter_horizontal_edge_mmx) PRIVATE
-sym(vp8_mbloop_filter_horizontal_edge_mmx):
-    push        rbp
-    mov         rbp, rsp
-    SHADOW_ARGS_TO_STACK 6
-    GET_GOT     rbx
-    push        rsi
-    push        rdi
-    ; end prolog
-
-    ALIGN_STACK 16, rax
-    sub          rsp, 32      ; reserve 32 bytes
-    %define t0   [rsp + 0]    ;__declspec(align(16)) char t0[8];
-    %define t1   [rsp + 16]   ;__declspec(align(16)) char t1[8];
-
-        mov         rsi, arg(0) ;src_ptr
-        movsxd      rax, dword ptr arg(1) ;src_pixel_step     ; destination pitch?
-
-        movsxd      rcx, dword ptr arg(5) ;count
-.next8_mbh:
-        mov         rdx, arg(3) ;limit
-        movq        mm7, [rdx]
-        mov         rdi, rsi              ; rdi points to row +1 for indirect addressing
-        add         rdi, rax
-
-        ; calculate breakout conditions
-        movq        mm2, [rdi+2*rax]      ; q3
-
-        movq        mm1, [rsi+2*rax]      ; q2
-        movq        mm6, mm1              ; q2
-        psubusb     mm1, mm2              ; q2-=q3
-        psubusb     mm2, mm6              ; q3-=q2
-        por         mm1, mm2              ; abs(q3-q2)
-        psubusb     mm1, mm7
-
-
-        ; mm1 = abs(q3-q2), mm6 =q2, mm7 = limit
-        movq        mm4, [rsi+rax]        ; q1
-        movq        mm3, mm4              ; q1
-        psubusb     mm4, mm6              ; q1-=q2
-        psubusb     mm6, mm3              ; q2-=q1
-        por         mm4, mm6              ; abs(q2-q1)
-        psubusb     mm4, mm7
-        por        mm1, mm4
-
-
-        ; mm1 = mask,      mm3=q1, mm7 = limit
-
-        movq        mm4, [rsi]            ; q0
-        movq        mm0, mm4              ; q0
-        psubusb     mm4, mm3              ; q0-=q1
-        psubusb     mm3, mm0              ; q1-=q0
-        por         mm4, mm3              ; abs(q0-q1)
-        movq        t0, mm4               ; save to t0
-        psubusb     mm4, mm7
-        por        mm1, mm4
-
-
-        ; mm1 = mask, mm0=q0,  mm7 = limit, t0 = abs(q0-q1)
-
-        neg         rax                   ; negate pitch to deal with above border
-
-        movq        mm2, [rsi+4*rax]      ; p3
-        movq        mm4, [rdi+4*rax]      ; p2
-        movq        mm5, mm4              ; p2
-        psubusb     mm4, mm2              ; p2-=p3
-        psubusb     mm2, mm5              ; p3-=p2
-        por         mm4, mm2              ; abs(p3 - p2)
-        psubusb     mm4, mm7
-        por        mm1, mm4
-        ; mm1 = mask, mm0=q0,  mm7 = limit, t0 = abs(q0-q1)
-
-        movq        mm4, [rsi+2*rax]      ; p1
-        movq        mm3, mm4              ; p1
-        psubusb     mm4, mm5              ; p1-=p2
-        psubusb     mm5, mm3              ; p2-=p1
-        por         mm4, mm5              ; abs(p2 - p1)
-        psubusb     mm4, mm7
-        por        mm1, mm4
-
-        movq        mm2, mm3              ; p1
-
-
-        ; mm1 = mask, mm0=q0,  mm7 = limit, t0 = abs(q0-q1)
-
-        movq        mm4, [rsi+rax]        ; p0
-        movq        mm5, mm4              ; p0
-        psubusb     mm4, mm3              ; p0-=p1
-        psubusb     mm3, mm5              ; p1-=p0
-        por         mm4, mm3              ; abs(p1 - p0)
-        movq        t1, mm4               ; save to t1
-        psubusb     mm4, mm7
-        por        mm1, mm4
-        ; mm1 = mask, mm0=q0,  mm7 = limit, t0 = abs(q0-q1) t1 = abs(p1-p0)
-        ; mm5 = p0
-        movq        mm3, [rdi]            ; q1
-        movq        mm4, mm3              ; q1
-        psubusb     mm3, mm2              ; q1-=p1
-        psubusb     mm2, mm4              ; p1-=q1
-        por         mm2, mm3              ; abs(p1-q1)
-        pand        mm2, [GLOBAL(tfe)]    ; set lsb of each byte to zero
-        psrlw       mm2, 1                ; abs(p1-q1)/2
-
-        movq        mm6, mm5              ; p0
-        movq        mm3, mm0              ; q0
-        psubusb     mm5, mm3              ; p0-=q0
-        psubusb     mm3, mm6              ; q0-=p0
-        por         mm5, mm3              ; abs(p0 - q0)
-        paddusb     mm5, mm5              ; abs(p0-q0)*2
-        paddusb     mm5, mm2              ; abs (p0 - q0) *2 + abs(p1-q1)/2
-
-        mov         rdx, arg(2) ;blimit           ; get blimit
-        movq        mm7, [rdx]            ; blimit
-
-        psubusb     mm5,    mm7           ; abs (p0 - q0) *2 + abs(p1-q1)/2  > blimit
-        por         mm1,    mm5
-        pxor        mm5,    mm5
-        pcmpeqb     mm1,    mm5           ; mask mm1
-
-        ; mm1 = mask, mm0=q0,  mm7 = blimit, t0 = abs(q0-q1) t1 = abs(p1-p0)
-        ; mm6 = p0,
-
-        ; calculate high edge variance
-        mov         rdx, arg(4) ;thresh           ; get thresh
-        movq        mm7, [rdx]            ;
-        movq        mm4, t0               ; get abs (q1 - q0)
-        psubusb     mm4, mm7
-        movq        mm3, t1               ; get abs (p1 - p0)
-        psubusb     mm3, mm7
-        paddb       mm4, mm3              ; abs(q1 - q0) > thresh || abs(p1 - p0) > thresh
-
-        pcmpeqb     mm4,        mm5
-
-        pcmpeqb     mm5,        mm5
-        pxor        mm4,        mm5
-
-
-
-        ; mm1 = mask, mm0=q0,  mm7 = thresh, t0 = abs(q0-q1) t1 = abs(p1-p0)
-        ; mm6 = p0, mm4=hev
-        ; start work on filters
-        movq        mm2, [rsi+2*rax]      ; p1
-        movq        mm7, [rdi]            ; q1
-        pxor        mm2, [GLOBAL(t80)]    ; p1 offset to convert to signed values
-        pxor        mm7, [GLOBAL(t80)]    ; q1 offset to convert to signed values
-        psubsb      mm2, mm7              ; p1 - q1
-
-        pxor        mm6, [GLOBAL(t80)]    ; offset to convert to signed values
-        pxor        mm0, [GLOBAL(t80)]    ; offset to convert to signed values
-        movq        mm3, mm0              ; q0
-        psubsb      mm0, mm6              ; q0 - p0
-        paddsb      mm2, mm0              ; 1 * (q0 - p0) + (p1 - q1)
-        paddsb      mm2, mm0              ; 2 * (q0 - p0)
-        paddsb      mm2, mm0              ; 3 * (q0 - p0) + (p1 - q1)
-        pand        mm1, mm2              ; mask filter values we don't care about
-
-
-        ; mm1 = vp8_filter, mm4=hev, mm6=ps0, mm3=qs0
-        movq        mm2, mm1              ; vp8_filter
-        pand        mm2, mm4;             ; Filter2 = vp8_filter & hev
-
-        movq        mm5,        mm2       ;
-        paddsb      mm5,        [GLOBAL(t3)];
-
-        pxor        mm0, mm0              ; 0
-        pxor        mm7, mm7              ; 0
-
-        punpcklbw   mm0, mm5              ; e0f0g0h0
-        psraw       mm0, 11               ; sign extended shift right by 3
-        punpckhbw   mm7, mm5              ; a0b0c0d0
-        psraw       mm7, 11               ; sign extended shift right by 3
-        packsswb    mm0, mm7              ; Filter2 >>=3;
-
-        movq        mm5, mm0              ; Filter2
-
-        paddsb      mm2, [GLOBAL(t4)]     ; vp8_signed_char_clamp(Filter2 + 4)
-        pxor        mm0, mm0              ; 0
-        pxor        mm7, mm7              ; 0
-
-        punpcklbw   mm0, mm2              ; e0f0g0h0
-        psraw       mm0, 11               ; sign extended shift right by 3
-        punpckhbw   mm7, mm2              ; a0b0c0d0
-        psraw       mm7, 11               ; sign extended shift right by 3
-        packsswb    mm0, mm7              ; Filter2 >>=3;
-
-        ; mm0= filter2 mm1 = vp8_filter,  mm3 =qs0 mm5=s mm4 =hev mm6=ps0
-        psubsb      mm3, mm0              ; qs0 =qs0 - filter1
-        paddsb      mm6, mm5              ; ps0 =ps0 + Fitler2
-
-        ; mm1=vp8_filter, mm3=qs0, mm4 =hev mm6=ps0
-        ; vp8_filter &= ~hev;
-        ; Filter2 = vp8_filter;
-        pandn       mm4, mm1              ; vp8_filter&=~hev
-
-
-        ; mm3=qs0, mm4=filter2, mm6=ps0
-
-        ; u = vp8_signed_char_clamp((63 + Filter2 * 27)>>7);
-        ; s = vp8_signed_char_clamp(qs0 - u);
-        ; *oq0 = s^0x80;
-        ; s = vp8_signed_char_clamp(ps0 + u);
-        ; *op0 = s^0x80;
-        pxor        mm0, mm0
-
-        pxor        mm1, mm1
-        pxor        mm2, mm2
-        punpcklbw   mm1, mm4
-        punpckhbw   mm2, mm4
-        pmulhw      mm1, [GLOBAL(s27)]
-        pmulhw      mm2, [GLOBAL(s27)]
-        paddw       mm1, [GLOBAL(s63)]
-        paddw       mm2, [GLOBAL(s63)]
-        psraw       mm1, 7
-        psraw       mm2, 7
-        packsswb    mm1, mm2
-
-        psubsb      mm3, mm1
-        paddsb      mm6, mm1
-
-        pxor        mm3, [GLOBAL(t80)]
-        pxor        mm6, [GLOBAL(t80)]
-        movq        [rsi+rax], mm6
-        movq        [rsi],     mm3
-
-        ; roughly 2/7th difference across boundary
-        ; u = vp8_signed_char_clamp((63 + Filter2 * 18)>>7);
-        ; s = vp8_signed_char_clamp(qs1 - u);
-        ; *oq1 = s^0x80;
-        ; s = vp8_signed_char_clamp(ps1 + u);
-        ; *op1 = s^0x80;
-        pxor        mm1, mm1
-        pxor        mm2, mm2
-        punpcklbw   mm1, mm4
-        punpckhbw   mm2, mm4
-        pmulhw      mm1, [GLOBAL(s18)]
-        pmulhw      mm2, [GLOBAL(s18)]
-        paddw       mm1, [GLOBAL(s63)]
-        paddw       mm2, [GLOBAL(s63)]
-        psraw       mm1, 7
-        psraw       mm2, 7
-        packsswb    mm1, mm2
-
-        movq        mm3, [rdi]
-        movq        mm6, [rsi+rax*2]       ; p1
-
-        pxor        mm3, [GLOBAL(t80)]
-        pxor        mm6, [GLOBAL(t80)]
-
-        paddsb      mm6, mm1
-        psubsb      mm3, mm1
-
-        pxor        mm6, [GLOBAL(t80)]
-        pxor        mm3, [GLOBAL(t80)]
-        movq        [rdi], mm3
-        movq        [rsi+rax*2], mm6
-
-        ; roughly 1/7th difference across boundary
-        ; u = vp8_signed_char_clamp((63 + Filter2 * 9)>>7);
-        ; s = vp8_signed_char_clamp(qs2 - u);
-        ; *oq2 = s^0x80;
-        ; s = vp8_signed_char_clamp(ps2 + u);
-        ; *op2 = s^0x80;
-        pxor        mm1, mm1
-        pxor        mm2, mm2
-        punpcklbw   mm1, mm4
-        punpckhbw   mm2, mm4
-        pmulhw      mm1, [GLOBAL(s9)]
-        pmulhw      mm2, [GLOBAL(s9)]
-        paddw       mm1, [GLOBAL(s63)]
-        paddw       mm2, [GLOBAL(s63)]
-        psraw       mm1, 7
-        psraw       mm2, 7
-        packsswb    mm1, mm2
-
-
-        movq        mm6, [rdi+rax*4]
-        neg         rax
-        movq        mm3, [rdi+rax  ]
-
-        pxor        mm6, [GLOBAL(t80)]
-        pxor        mm3, [GLOBAL(t80)]
-
-        paddsb      mm6, mm1
-        psubsb      mm3, mm1
-
-        pxor        mm6, [GLOBAL(t80)]
-        pxor        mm3, [GLOBAL(t80)]
-        movq        [rdi+rax  ], mm3
-        neg         rax
-        movq        [rdi+rax*4], mm6
-
-;EARLY_BREAK_OUT:
-        neg         rax
-        add         rsi,8
-        dec         rcx
-        jnz         .next8_mbh
-
-    add rsp, 32
-    pop rsp
-    ; begin epilog
-    pop rdi
-    pop rsi
-    RESTORE_GOT
-    UNSHADOW_ARGS
-    pop         rbp
-    ret
-
-
-;void vp8_mbloop_filter_vertical_edge_mmx
-;(
-;    unsigned char *src_ptr,
-;    int  src_pixel_step,
-;    const char *blimit,
-;    const char *limit,
-;    const char *thresh,
-;    int count
-;)
-global sym(vp8_mbloop_filter_vertical_edge_mmx) PRIVATE
-sym(vp8_mbloop_filter_vertical_edge_mmx):
-    push        rbp
-    mov         rbp, rsp
-    SHADOW_ARGS_TO_STACK 6
-    GET_GOT     rbx
-    push        rsi
-    push        rdi
-    ; end prolog
-
-    ALIGN_STACK 16, rax
-    sub          rsp, 96      ; reserve 96 bytes
-    %define t0   [rsp + 0]    ;__declspec(align(16)) char t0[8];
-    %define t1   [rsp + 16]   ;__declspec(align(16)) char t1[8];
-    %define srct [rsp + 32]   ;__declspec(align(16)) char srct[64];
-
-        mov         rsi,        arg(0) ;src_ptr
-        movsxd      rax,        dword ptr arg(1) ;src_pixel_step     ; destination pitch?
-
-        lea         rsi,        [rsi + rax*4 - 4]
-
-        movsxd      rcx,        dword ptr arg(5) ;count
-.next8_mbv:
-        lea         rdi,        [rsi + rax]  ; rdi points to row +1 for indirect addressing
-
-        ;transpose
-        movq        mm0,        [rdi+2*rax]                 ; 77 76 75 74 73 72 71 70
-        movq        mm6,        [rsi+2*rax]                 ; 67 66 65 64 63 62 61 60
-
-        movq        mm7,        mm6                         ; 77 76 75 74 73 72 71 70
-        punpckhbw   mm7,        mm0                         ; 77 67 76 66 75 65 74 64
-
-        punpcklbw   mm6,        mm0                         ; 73 63 72 62 71 61 70 60
-        movq        mm0,        [rsi+rax]                   ; 57 56 55 54 53 52 51 50
-
-        movq        mm4,        [rsi]                       ; 47 46 45 44 43 42 41 40
-        movq        mm5,        mm4                         ; 47 46 45 44 43 42 41 40
-
-        punpckhbw   mm5,        mm0                         ; 57 47 56 46 55 45 54 44
-        punpcklbw   mm4,        mm0                         ; 53 43 52 42 51 41 50 40
-
-        movq        mm3,        mm5                         ; 57 47 56 46 55 45 54 44
-        punpckhwd   mm5,        mm7                         ; 77 67 57 47 76 66 56 46
-
-        punpcklwd   mm3,        mm7                         ; 75 65 55 45 74 64 54 44
-        movq        mm2,        mm4                         ; 53 43 52 42 51 41 50 40
-
-        punpckhwd   mm4,        mm6                         ; 73 63 53 43 72 62 52 42
-        punpcklwd   mm2,        mm6                         ; 71 61 51 41 70 60 50 40
-
-        neg         rax
-
-        movq        mm7,        [rsi+rax]                   ; 37 36 35 34 33 32 31 30
-        movq        mm6,        [rsi+rax*2]                 ; 27 26 25 24 23 22 21 20
-
-        movq        mm1,        mm6                         ; 27 26 25 24 23 22 21 20
-        punpckhbw   mm6,        mm7                         ; 37 27 36 36 35 25 34 24
-
-        punpcklbw   mm1,        mm7                         ; 33 23 32 22 31 21 30 20
-
-        movq        mm7,        [rsi+rax*4];                ; 07 06 05 04 03 02 01 00
-        punpckhbw   mm7,        [rdi+rax*4]                 ; 17 07 16 06 15 05 14 04
-
-        movq        mm0,        mm7                         ; 17 07 16 06 15 05 14 04
-        punpckhwd   mm7,        mm6                         ; 37 27 17 07 36 26 16 06
-
-        punpcklwd   mm0,        mm6                         ; 35 25 15 05 34 24 14 04
-        movq        mm6,        mm7                         ; 37 27 17 07 36 26 16 06
-
-        punpckhdq   mm7,        mm5                         ; 77 67 57 47 37 27 17 07  = q3
-        punpckldq   mm6,        mm5                         ; 76 66 56 46 36 26 16 06  = q2
-
-        lea         rdx,        srct
-        movq        mm5,        mm6                         ; 76 66 56 46 36 26 16 06
-
-        movq        [rdx+56],   mm7
-        psubusb     mm5,        mm7                         ; q2-q3
-
-
-        movq        [rdx+48],   mm6
-        psubusb     mm7,        mm6                         ; q3-q2
-
-        por         mm7,        mm5;                        ; mm7=abs (q3-q2)
-        movq        mm5,        mm0                         ; 35 25 15 05 34 24 14 04
-
-        punpckhdq   mm5,        mm3                         ; 75 65 55 45 35 25 15 05 = q1
-        punpckldq   mm0,        mm3                         ; 74 64 54 44 34 24 15 04 = q0
-
-        movq        mm3,        mm5                         ; 75 65 55 45 35 25 15 05 = q1
-        psubusb     mm3,        mm6                         ; q1-q2
-
-        psubusb     mm6,        mm5                         ; q2-q1
-        por         mm6,        mm3                         ; mm6=abs(q2-q1)
-
-        movq        [rdx+40],   mm5                         ; save q1
-        movq        [rdx+32],   mm0                         ; save q0
-
-        movq        mm3,        [rsi+rax*4]                 ; 07 06 05 04 03 02 01 00
-        punpcklbw   mm3,        [rdi+rax*4]                 ; 13 03 12 02 11 01 10 00
-
-        movq        mm0,        mm3                         ; 13 03 12 02 11 01 10 00
-        punpcklwd   mm0,        mm1                         ; 31 21 11 01 30 20 10 00
-
-        punpckhwd   mm3,        mm1                         ; 33 23 13 03 32 22 12 02
-        movq        mm1,        mm0                         ; 31 21 11 01 30 20 10 00
-
-        punpckldq   mm0,        mm2                         ; 70 60 50 40 30 20 10 00  =p3
-        punpckhdq   mm1,        mm2                         ; 71 61 51 41 31 21 11 01  =p2
-
-        movq        [rdx],      mm0                         ; save p3
-        movq        [rdx+8],    mm1                         ; save p2
-
-        movq        mm2,        mm1                         ; 71 61 51 41 31 21 11 01  =p2
-        psubusb     mm2,        mm0                         ; p2-p3
-
-        psubusb     mm0,        mm1                         ; p3-p2
-        por         mm0,        mm2                         ; mm0=abs(p3-p2)
-
-        movq        mm2,        mm3                         ; 33 23 13 03 32 22 12 02
-        punpckldq   mm2,        mm4                         ; 72 62 52 42 32 22 12 02 = p1
-
-        punpckhdq   mm3,        mm4                         ; 73 63 53 43 33 23 13 03 = p0
-        movq        [rdx+24],   mm3                         ; save p0
-
-        movq        [rdx+16],   mm2                         ; save p1
-        movq        mm5,        mm2                         ; mm5 = p1
-
-        psubusb     mm2,        mm1                         ; p1-p2
-        psubusb     mm1,        mm5                         ; p2-p1
-
-        por         mm1,        mm2                         ; mm1=abs(p2-p1)
-        mov         rdx,        arg(3) ;limit
-
-        movq        mm4,        [rdx]                       ; mm4 = limit
-        psubusb     mm7,        mm4                         ; abs(q3-q2) > limit
-
-        psubusb     mm0,        mm4                         ; abs(p3-p2) > limit
-        psubusb     mm1,        mm4                         ; abs(p2-p1) > limit
-
-        psubusb     mm6,        mm4                         ; abs(q2-q1) > limit
-        por         mm7,        mm6                         ; or
-
-        por         mm0,        mm1                         ;
-        por         mm0,        mm7                         ; abs(q3-q2) > limit || abs(p3-p2) > limit ||abs(p2-p1) > limit || abs(q2-q1) > limit
-
-        movq        mm1,        mm5                         ; p1
-
-        movq        mm7,        mm3                         ; mm3=mm7=p0
-        psubusb     mm7,        mm5                         ; p0 - p1
-
-        psubusb     mm5,        mm3                         ; p1 - p0
-        por         mm5,        mm7                         ; abs(p1-p0)
-
-        movq        t0,         mm5                         ; save abs(p1-p0)
-        lea         rdx,        srct
-
-        psubusb     mm5,        mm4                         ; mm5 = abs(p1-p0) > limit
-        por         mm0,        mm5                         ; mm0=mask
-
-        movq        mm5,        [rdx+32]                    ; mm5=q0
-        movq        mm7,        [rdx+40]                    ; mm7=q1
-
-        movq        mm6,        mm5                         ; mm6=q0
-        movq        mm2,        mm7                         ; q1
-        psubusb     mm5,        mm7                         ; q0-q1
-
-        psubusb     mm7,        mm6                         ; q1-q0
-        por         mm7,        mm5                         ; abs(q1-q0)
-
-        movq        t1,         mm7                         ; save abs(q1-q0)
-        psubusb     mm7,        mm4                         ; mm7=abs(q1-q0)> limit
-
-        por         mm0,        mm7                         ; mask
-
-        movq        mm5,        mm2                         ; q1
-        psubusb     mm5,        mm1                         ; q1-=p1
-        psubusb     mm1,        mm2                         ; p1-=q1
-        por         mm5,        mm1                         ; abs(p1-q1)
-        pand        mm5,        [GLOBAL(tfe)]               ; set lsb of each byte to zero
-        psrlw       mm5,        1                           ; abs(p1-q1)/2
-
-        mov         rdx,        arg(2) ;blimit                      ;
-
-        movq        mm4,        [rdx]                       ;blimit
-        movq        mm1,        mm3                         ; mm1=mm3=p0
-
-        movq        mm7,        mm6                         ; mm7=mm6=q0
-        psubusb     mm1,        mm7                         ; p0-q0
-
-        psubusb     mm7,        mm3                         ; q0-p0
-        por         mm1,        mm7                         ; abs(q0-p0)
-        paddusb     mm1,        mm1                         ; abs(q0-p0)*2
-        paddusb     mm1,        mm5                         ; abs (p0 - q0) *2 + abs(p1-q1)/2
-
-        psubusb     mm1,        mm4                         ; abs (p0 - q0) *2 + abs(p1-q1)/2  > blimit
-        por         mm1,        mm0;                        ; mask
-
-        pxor        mm0,        mm0
-        pcmpeqb     mm1,        mm0
-
-        ; calculate high edge variance
-        mov         rdx,        arg(4) ;thresh            ; get thresh
-        movq        mm7,        [rdx]
-        ;
-        movq        mm4,        t0              ; get abs (q1 - q0)
-        psubusb     mm4,        mm7             ; abs(q1 - q0) > thresh
-
-        movq        mm3,        t1              ; get abs (p1 - p0)
-        psubusb     mm3,        mm7             ; abs(p1 - p0)> thresh
-
-        por         mm4,        mm3             ; abs(q1 - q0) > thresh || abs(p1 - p0) > thresh
-        pcmpeqb     mm4,        mm0
-
-        pcmpeqb     mm0,        mm0
-        pxor        mm4,        mm0
-
-
-
-
-        ; start work on filters
-        lea         rdx,        srct
-
-        ; start work on filters
-        movq        mm2, [rdx+16]         ; p1
-        movq        mm7, [rdx+40]         ; q1
-        pxor        mm2, [GLOBAL(t80)]    ; p1 offset to convert to signed values
-        pxor        mm7, [GLOBAL(t80)]    ; q1 offset to convert to signed values
-        psubsb      mm2, mm7              ; p1 - q1
-
-        movq        mm6, [rdx+24]         ; p0
-        movq        mm0, [rdx+32]         ; q0
-        pxor        mm6, [GLOBAL(t80)]    ; offset to convert to signed values
-        pxor        mm0, [GLOBAL(t80)]    ; offset to convert to signed values
-
-        movq        mm3, mm0              ; q0
-        psubsb      mm0, mm6              ; q0 - p0
-        paddsb      mm2, mm0              ; 1 * (q0 - p0) + (p1 - q1)
-        paddsb      mm2, mm0              ; 2 * (q0 - p0)
-        paddsb      mm2, mm0              ; 3 * (q0 - p0) + (p1 - q1)
-        pand       mm1, mm2           ; mask filter values we don't care about
-
-        ; mm1 = vp8_filter, mm4=hev, mm6=ps0, mm3=qs0
-        movq        mm2, mm1              ; vp8_filter
-        pand        mm2, mm4;             ; Filter2 = vp8_filter & hev
-
-        movq        mm5,        mm2       ;
-        paddsb      mm5,        [GLOBAL(t3)];
-
-        pxor        mm0, mm0              ; 0
-        pxor        mm7, mm7              ; 0
-
-        punpcklbw   mm0, mm5              ; e0f0g0h0
-        psraw       mm0, 11               ; sign extended shift right by 3
-        punpckhbw   mm7, mm5              ; a0b0c0d0
-        psraw       mm7, 11               ; sign extended shift right by 3
-        packsswb    mm0, mm7              ; Filter2 >>=3;
-
-        movq        mm5, mm0              ; Filter2
-
-        paddsb      mm2, [GLOBAL(t4)]     ; vp8_signed_char_clamp(Filter2 + 4)
-        pxor        mm0, mm0              ; 0
-        pxor        mm7, mm7              ; 0
-
-        punpcklbw   mm0, mm2              ; e0f0g0h0
-        psraw       mm0, 11               ; sign extended shift right by 3
-        punpckhbw   mm7, mm2              ; a0b0c0d0
-        psraw       mm7, 11               ; sign extended shift right by 3
-        packsswb    mm0, mm7              ; Filter2 >>=3;
-
-        ; mm0= filter2 mm1 = vp8_filter,  mm3 =qs0 mm5=s mm4 =hev mm6=ps0
-        psubsb      mm3, mm0              ; qs0 =qs0 - filter1
-        paddsb      mm6, mm5              ; ps0 =ps0 + Fitler2
-
-        ; mm1=vp8_filter, mm3=qs0, mm4 =hev mm6=ps0
-        ; vp8_filter &= ~hev;
-        ; Filter2 = vp8_filter;
-        pandn       mm4, mm1              ; vp8_filter&=~hev
-
-
-        ; mm3=qs0, mm4=filter2, mm6=ps0
-
-        ; u = vp8_signed_char_clamp((63 + Filter2 * 27)>>7);
-        ; s = vp8_signed_char_clamp(qs0 - u);
-        ; *oq0 = s^0x80;
-        ; s = vp8_signed_char_clamp(ps0 + u);
-        ; *op0 = s^0x80;
-        pxor        mm0, mm0
-
-        pxor        mm1, mm1
-        pxor        mm2, mm2
-        punpcklbw   mm1, mm4
-        punpckhbw   mm2, mm4
-        pmulhw      mm1, [GLOBAL(s27)]
-        pmulhw      mm2, [GLOBAL(s27)]
-        paddw       mm1, [GLOBAL(s63)]
-        paddw       mm2, [GLOBAL(s63)]
-        psraw       mm1, 7
-        psraw       mm2, 7
-        packsswb    mm1, mm2
-
-        psubsb      mm3, mm1
-        paddsb      mm6, mm1
-
-        pxor        mm3, [GLOBAL(t80)]
-        pxor        mm6, [GLOBAL(t80)]
-        movq        [rdx+24], mm6
-        movq        [rdx+32], mm3
-
-        ; roughly 2/7th difference across boundary
-        ; u = vp8_signed_char_clamp((63 + Filter2 * 18)>>7);
-        ; s = vp8_signed_char_clamp(qs1 - u);
-        ; *oq1 = s^0x80;
-        ; s = vp8_signed_char_clamp(ps1 + u);
-        ; *op1 = s^0x80;
-        pxor        mm1, mm1
-        pxor        mm2, mm2
-        punpcklbw   mm1, mm4
-        punpckhbw   mm2, mm4
-        pmulhw      mm1, [GLOBAL(s18)]
-        pmulhw      mm2, [GLOBAL(s18)]
-        paddw       mm1, [GLOBAL(s63)]
-        paddw       mm2, [GLOBAL(s63)]
-        psraw       mm1, 7
-        psraw       mm2, 7
-        packsswb    mm1, mm2
-
-        movq        mm3, [rdx + 40]
-        movq        mm6, [rdx + 16]       ; p1
-        pxor        mm3, [GLOBAL(t80)]
-        pxor        mm6, [GLOBAL(t80)]
-
-        paddsb      mm6, mm1
-        psubsb      mm3, mm1
-
-        pxor        mm6, [GLOBAL(t80)]
-        pxor        mm3, [GLOBAL(t80)]
-        movq        [rdx + 40], mm3
-        movq        [rdx + 16], mm6
-
-        ; roughly 1/7th difference across boundary
-        ; u = vp8_signed_char_clamp((63 + Filter2 * 9)>>7);
-        ; s = vp8_signed_char_clamp(qs2 - u);
-        ; *oq2 = s^0x80;
-        ; s = vp8_signed_char_clamp(ps2 + u);
-        ; *op2 = s^0x80;
-        pxor        mm1, mm1
-        pxor        mm2, mm2
-        punpcklbw   mm1, mm4
-        punpckhbw   mm2, mm4
-        pmulhw      mm1, [GLOBAL(s9)]
-        pmulhw      mm2, [GLOBAL(s9)]
-        paddw       mm1, [GLOBAL(s63)]
-        paddw       mm2, [GLOBAL(s63)]
-        psraw       mm1, 7
-        psraw       mm2, 7
-        packsswb    mm1, mm2
-
-        movq        mm6, [rdx+ 8]
-        movq        mm3, [rdx+48]
-
-        pxor        mm6, [GLOBAL(t80)]
-        pxor        mm3, [GLOBAL(t80)]
-
-        paddsb      mm6, mm1
-        psubsb      mm3, mm1
-
-        pxor        mm6, [GLOBAL(t80)]          ; mm6 = 71 61 51 41 31 21 11 01
-        pxor        mm3, [GLOBAL(t80)]          ; mm3 = 76 66 56 46 36 26 15 06
-
-        ; transpose and write back
-        movq        mm0,    [rdx]               ; mm0 = 70 60 50 40 30 20 10 00
-        movq        mm1,    mm0                 ; mm0 = 70 60 50 40 30 20 10 00
-
-        punpcklbw   mm0,    mm6                 ; mm0 = 31 30 21 20 11 10 01 00
-        punpckhbw   mm1,    mm6                 ; mm3 = 71 70 61 60 51 50 41 40
-
-        movq        mm2,    [rdx+16]            ; mm2 = 72 62 52 42 32 22 12 02
-        movq        mm6,    mm2                 ; mm3 = 72 62 52 42 32 22 12 02
-
-        punpcklbw   mm2,    [rdx+24]            ; mm2 = 33 32 23 22 13 12 03 02
-        punpckhbw   mm6,    [rdx+24]            ; mm3 = 73 72 63 62 53 52 43 42
-
-        movq        mm5,    mm0                 ; mm5 = 31 30 21 20 11 10 01 00
-        punpcklwd   mm0,    mm2                 ; mm0 = 13 12 11 10 03 02 01 00
-
-        punpckhwd   mm5,    mm2                 ; mm5 = 33 32 31 30 23 22 21 20
-        movq        mm4,    mm1                 ; mm4 = 71 70 61 60 51 50 41 40
-
-        punpcklwd   mm1,    mm6                 ; mm1 = 53 52 51 50 43 42 41 40
-        punpckhwd   mm4,    mm6                 ; mm4 = 73 72 71 70 63 62 61 60
-
-        movq        mm2,    [rdx+32]            ; mm2 = 74 64 54 44 34 24 14 04
-        punpcklbw   mm2,    [rdx+40]            ; mm2 = 35 34 25 24 15 14 05 04
-
-        movq        mm6,    mm3                 ; mm6 = 76 66 56 46 36 26 15 06
-        punpcklbw   mm6,    [rdx+56]            ; mm6 = 37 36 27 26 17 16 07 06
-
-        movq        mm7,    mm2                 ; mm7 = 35 34 25 24 15 14 05 04
-        punpcklwd   mm2,    mm6                 ; mm2 = 17 16 15 14 07 06 05 04
-
-        punpckhwd   mm7,    mm6                 ; mm7 = 37 36 35 34 27 26 25 24
-        movq        mm6,    mm0                 ; mm6 = 13 12 11 10 03 02 01 00
-
-        punpckldq   mm0,    mm2                 ; mm0 = 07 06 05 04 03 02 01 00
-        punpckhdq   mm6,    mm2                 ; mm6 = 17 16 15 14 13 12 11 10
-
-        movq        [rsi+rax*4], mm0            ; write out
-        movq        [rdi+rax*4], mm6            ; write out
-
-        movq        mm0,    mm5                 ; mm0 = 33 32 31 30 23 22 21 20
-        punpckldq   mm0,    mm7                 ; mm0 = 27 26 25 24 23 22 20 20
-
-        punpckhdq   mm5,    mm7                 ; mm5 = 37 36 35 34 33 32 31 30
-        movq        [rsi+rax*2], mm0            ; write out
-
-        movq        [rdi+rax*2], mm5            ; write out
-        movq        mm2,    [rdx+32]            ; mm2 = 74 64 54 44 34 24 14 04
-
-        punpckhbw   mm2,    [rdx+40]            ; mm2 = 75 74 65 64 54 54 45 44
-        punpckhbw   mm3,    [rdx+56]            ; mm3 = 77 76 67 66 57 56 47 46
-
-        movq        mm5,    mm2                 ; mm5 = 75 74 65 64 54 54 45 44
-        punpcklwd   mm2,    mm3                 ; mm2 = 57 56 55 54 47 46 45 44
-
-        punpckhwd   mm5,    mm3                 ; mm5 = 77 76 75 74 67 66 65 64
-        movq        mm0,    mm1                 ; mm0=  53 52 51 50 43 42 41 40
-
-        movq        mm3,    mm4                 ; mm4 = 73 72 71 70 63 62 61 60
-        punpckldq   mm0,    mm2                 ; mm0 = 47 46 45 44 43 42 41 40
-
-        punpckhdq   mm1,    mm2                 ; mm1 = 57 56 55 54 53 52 51 50
-        movq        [rsi],  mm0                 ; write out
-
-        movq        [rdi],  mm1                 ; write out
-        neg         rax
-
-        punpckldq   mm3,    mm5                 ; mm3 = 67 66 65 64 63 62 61 60
-        punpckhdq   mm4,    mm5                 ; mm4 = 77 76 75 74 73 72 71 60
-
-        movq        [rsi+rax*2], mm3
-        movq        [rdi+rax*2], mm4
-
-        lea         rsi,        [rsi+rax*8]
-        dec         rcx
-
-        jnz         .next8_mbv
-
-    add rsp, 96
-    pop rsp
-    ; begin epilog
-    pop rdi
-    pop rsi
-    RESTORE_GOT
-    UNSHADOW_ARGS
-    pop         rbp
-    ret
-
-
-;void vp8_loop_filter_simple_horizontal_edge_mmx
-;(
-;    unsigned char *src_ptr,
-;    int  src_pixel_step,
-;    const char *blimit
-;)
-global sym(vp8_loop_filter_simple_horizontal_edge_mmx) PRIVATE
-sym(vp8_loop_filter_simple_horizontal_edge_mmx):
-    push        rbp
-    mov         rbp, rsp
-    SHADOW_ARGS_TO_STACK 3
-    GET_GOT     rbx
-    push        rsi
-    push        rdi
-    ; end prolog
-
-        mov         rsi, arg(0) ;src_ptr
-        movsxd      rax, dword ptr arg(1) ;src_pixel_step     ; destination pitch?
-
-        mov         rcx, 2                ; count
-.nexts8_h:
-        mov         rdx, arg(2) ;blimit           ; get blimit
-        movq        mm3, [rdx]            ;
-
-        mov         rdi, rsi              ; rdi points to row +1 for indirect addressing
-        add         rdi, rax
-        neg         rax
-
-        ; calculate mask
-        movq        mm1, [rsi+2*rax]      ; p1
-        movq        mm0, [rdi]            ; q1
-        movq        mm2, mm1
-        movq        mm7, mm0
-        movq        mm4, mm0
-        psubusb     mm0, mm1              ; q1-=p1
-        psubusb     mm1, mm4              ; p1-=q1
-        por         mm1, mm0              ; abs(p1-q1)
-        pand        mm1, [GLOBAL(tfe)]    ; set lsb of each byte to zero
-        psrlw       mm1, 1                ; abs(p1-q1)/2
-
-        movq        mm5, [rsi+rax]        ; p0
-        movq        mm4, [rsi]            ; q0
-        movq        mm0, mm4              ; q0
-        movq        mm6, mm5              ; p0
-        psubusb     mm5, mm4              ; p0-=q0
-        psubusb     mm4, mm6              ; q0-=p0
-        por         mm5, mm4              ; abs(p0 - q0)
-        paddusb     mm5, mm5              ; abs(p0-q0)*2
-        paddusb     mm5, mm1              ; abs (p0 - q0) *2 + abs(p1-q1)/2
-
-        psubusb     mm5, mm3              ; abs(p0 - q0) *2 + abs(p1-q1)/2  > blimit
-        pxor        mm3, mm3
-        pcmpeqb     mm5, mm3
-
-        ; start work on filters
-        pxor        mm2, [GLOBAL(t80)]    ; p1 offset to convert to signed values
-        pxor        mm7, [GLOBAL(t80)]    ; q1 offset to convert to signed values
-        psubsb      mm2, mm7              ; p1 - q1
-
-        pxor        mm6, [GLOBAL(t80)]    ; offset to convert to signed values
-        pxor        mm0, [GLOBAL(t80)]    ; offset to convert to signed values
-        movq        mm3, mm0              ; q0
-        psubsb      mm0, mm6              ; q0 - p0
-        paddsb      mm2, mm0              ; p1 - q1 + 1 * (q0 - p0)
-        paddsb      mm2, mm0              ; p1 - q1 + 2 * (q0 - p0)
-        paddsb      mm2, mm0              ; p1 - q1 + 3 * (q0 - p0)
-        pand        mm5, mm2              ; mask filter values we don't care about
-
-        ; do + 4 side
-        paddsb      mm5, [GLOBAL(t4)]     ; 3* (q0 - p0) + (p1 - q1) + 4
-
-        movq        mm0, mm5              ; get a copy of filters
-        psllw       mm0, 8                ; shift left 8
-        psraw       mm0, 3                ; arithmetic shift right 11
-        psrlw       mm0, 8
-        movq        mm1, mm5              ; get a copy of filters
-        psraw       mm1, 11               ; arithmetic shift right 11
-        psllw       mm1, 8                ; shift left 8 to put it back
-
-        por         mm0, mm1              ; put the two together to get result
-
-        psubsb      mm3, mm0              ; q0-= q0 add
-        pxor        mm3, [GLOBAL(t80)]    ; unoffset
-        movq        [rsi], mm3            ; write back
-
-
-        ; now do +3 side
-        psubsb      mm5, [GLOBAL(t1s)]     ; +3 instead of +4
-
-        movq        mm0, mm5              ; get a copy of filters
-        psllw       mm0, 8                ; shift left 8
-        psraw       mm0, 3                ; arithmetic shift right 11
-        psrlw       mm0, 8
-        psraw       mm5, 11               ; arithmetic shift right 11
-        psllw       mm5, 8                ; shift left 8 to put it back
-        por         mm0, mm5              ; put the two together to get result
-
-
-        paddsb      mm6, mm0              ; p0+= p0 add
-        pxor        mm6, [GLOBAL(t80)]    ; unoffset
-        movq        [rsi+rax], mm6        ; write back
-
-        add         rsi,8
-        neg         rax
-        dec         rcx
-        jnz         .nexts8_h
-
-    ; begin epilog
-    pop rdi
-    pop rsi
-    RESTORE_GOT
-    UNSHADOW_ARGS
-    pop         rbp
-    ret
-
-
-;void vp8_loop_filter_simple_vertical_edge_mmx
-;(
-;    unsigned char *src_ptr,
-;    int  src_pixel_step,
-;    const char *blimit
-;)
-global sym(vp8_loop_filter_simple_vertical_edge_mmx) PRIVATE
-sym(vp8_loop_filter_simple_vertical_edge_mmx):
-    push        rbp
-    mov         rbp, rsp
-    SHADOW_ARGS_TO_STACK 3
-    GET_GOT     rbx
-    push        rsi
-    push        rdi
-    ; end prolog
-
-    ALIGN_STACK 16, rax
-    sub          rsp, 32      ; reserve 32 bytes
-    %define t0   [rsp + 0]    ;__declspec(align(16)) char t0[8];
-    %define t1   [rsp + 16]   ;__declspec(align(16)) char t1[8];
-
-        mov         rsi, arg(0) ;src_ptr
-        movsxd      rax, dword ptr arg(1) ;src_pixel_step     ; destination pitch?
-
-        lea         rsi, [rsi + rax*4- 2];  ;
-        mov         rcx, 2                                      ; count
-.nexts8_v:
-
-        lea         rdi,        [rsi + rax];
-        movd        mm0,        [rdi + rax * 2]                 ; xx xx xx xx 73 72 71 70
-
-        movd        mm6,        [rsi + rax * 2]                 ; xx xx xx xx 63 62 61 60
-        punpcklbw   mm6,        mm0                             ; 73 63 72 62 71 61 70 60
-
-        movd        mm0,        [rsi + rax]                     ; xx xx xx xx 53 52 51 50
-        movd        mm4,        [rsi]                           ; xx xx xx xx 43 42 41 40
-
-        punpcklbw   mm4,        mm0                             ; 53 43 52 42 51 41 50 40
-        movq        mm5,        mm4                             ; 53 43 52 42 51 41 50 40
-
-        punpcklwd   mm4,        mm6                             ; 71 61 51 41 70 60 50 40
-        punpckhwd   mm5,        mm6                             ; 73 63 53 43 72 62 52 42
-
-        neg         rax
-
-        movd        mm7,        [rsi + rax]                     ; xx xx xx xx 33 32 31 30
-        movd        mm6,        [rsi + rax * 2]                 ; xx xx xx xx 23 22 21 20
-
-        punpcklbw   mm6,        mm7                             ; 33 23 32 22 31 21 30 20
-        movd        mm1,        [rdi + rax * 4]                 ; xx xx xx xx 13 12 11 10
-
-        movd        mm0,        [rsi + rax * 4]                 ; xx xx xx xx 03 02 01 00
-        punpcklbw   mm0,        mm1                             ; 13 03 12 02 11 01 10 00
-
-        movq        mm2,        mm0                             ; 13 03 12 02 11 01 10 00
-        punpcklwd   mm0,        mm6                             ; 31 21 11 01 30 20 10 00
-
-        punpckhwd   mm2,        mm6                             ; 33 23 13 03 32 22 12 02
-        movq        mm1,        mm0                             ; 13 03 12 02 11 01 10 00
-
-        punpckldq   mm0,        mm4                             ; 70 60 50 40 30 20 10 00       = p1
-        movq        mm3,        mm2                             ; 33 23 13 03 32 22 12 02
-
-        punpckhdq   mm1,        mm4                             ; 71 61 51 41 31 21 11 01       = p0
-        punpckldq   mm2,        mm5                             ; 72 62 52 42 32 22 12 02       = q0
-
-        punpckhdq   mm3,        mm5                             ; 73 63 53 43 33 23 13 03       = q1
-
-
-        ; calculate mask
-        movq        mm6,        mm0                             ; p1
-        movq        mm7,        mm3                             ; q1
-        psubusb     mm7,        mm6                             ; q1-=p1
-        psubusb     mm6,        mm3                             ; p1-=q1
-        por         mm6,        mm7                             ; abs(p1-q1)
-        pand        mm6,        [GLOBAL(tfe)]                   ; set lsb of each byte to zero
-        psrlw       mm6,        1                               ; abs(p1-q1)/2
-
-        movq        mm5,        mm1                             ; p0
-        movq        mm4,        mm2                             ; q0
-
-        psubusb     mm5,        mm2                             ; p0-=q0
-        psubusb     mm4,        mm1                             ; q0-=p0
-
-        por         mm5,        mm4                             ; abs(p0 - q0)
-        paddusb     mm5,        mm5                             ; abs(p0-q0)*2
-        paddusb     mm5,        mm6                             ; abs (p0 - q0) *2 + abs(p1-q1)/2
-
-        mov         rdx,        arg(2) ;blimit                          ; get blimit
-        movq        mm7,        [rdx]
-
-        psubusb     mm5,        mm7                             ; abs(p0 - q0) *2 + abs(p1-q1)/2  > blimit
-        pxor        mm7,        mm7
-        pcmpeqb     mm5,        mm7                             ; mm5 = mask
-
-        ; start work on filters
-        movq        t0,         mm0
-        movq        t1,         mm3
-
-        pxor        mm0,        [GLOBAL(t80)]                   ; p1 offset to convert to signed values
-        pxor        mm3,        [GLOBAL(t80)]                   ; q1 offset to convert to signed values
-
-        psubsb      mm0,        mm3                             ; p1 - q1
-        movq        mm6,        mm1                             ; p0
-
-        movq        mm7,        mm2                             ; q0
-        pxor        mm6,        [GLOBAL(t80)]                   ; offset to convert to signed values
-
-        pxor        mm7,        [GLOBAL(t80)]                   ; offset to convert to signed values
-        movq        mm3,        mm7                             ; offseted ; q0
-
-        psubsb      mm7,        mm6                             ; q0 - p0
-        paddsb      mm0,        mm7                             ; p1 - q1 + 1 * (q0 - p0)
-
-        paddsb      mm0,        mm7                             ; p1 - q1 + 2 * (q0 - p0)
-        paddsb      mm0,        mm7                             ; p1 - q1 + 3 * (q0 - p0)
-
-        pand        mm5,        mm0                             ; mask filter values we don't care about
-
-        paddsb      mm5,        [GLOBAL(t4)]                    ;  3* (q0 - p0) + (p1 - q1) + 4
-
-        movq        mm0,        mm5                             ; get a copy of filters
-        psllw       mm0,        8                               ; shift left 8
-        psraw       mm0,        3                               ; arithmetic shift right 11
-        psrlw       mm0,        8
-
-        movq        mm7,        mm5                             ; get a copy of filters
-        psraw       mm7,        11                              ; arithmetic shift right 11
-        psllw       mm7,        8                               ; shift left 8 to put it back
-
-        por         mm0,        mm7                             ; put the two together to get result
-
-        psubsb      mm3,        mm0                             ; q0-= q0sz add
-        pxor        mm3,        [GLOBAL(t80)]                   ; unoffset
-
-        ; now do +3 side
-        psubsb      mm5, [GLOBAL(t1s)]                          ; +3 instead of +4
-
-        movq        mm0, mm5                                    ; get a copy of filters
-        psllw       mm0, 8                                      ; shift left 8
-        psraw       mm0, 3                                      ; arithmetic shift right 11
-        psrlw       mm0, 8
-
-        psraw       mm5, 11                                     ; arithmetic shift right 11
-        psllw       mm5, 8                                      ; shift left 8 to put it back
-        por         mm0, mm5                                    ; put the two together to get result
-
-        paddsb      mm6, mm0                                    ; p0+= p0 add
-        pxor        mm6, [GLOBAL(t80)]                          ; unoffset
-
-
-        movq        mm0,        t0
-        movq        mm4,        t1
-
-        ; mm0 = 70 60 50 40 30 20 10 00
-        ; mm6 = 71 61 51 41 31 21 11 01
-        ; mm3 = 72 62 52 42 32 22 12 02
-        ; mm4 = 73 63 53 43 33 23 13 03
-        ; transpose back to write out
-
-        movq        mm1,        mm0                         ;
-        punpcklbw   mm0,        mm6                         ; 31 30 21 20 11 10 01 00
-
-        punpckhbw   mm1,        mm6                         ; 71 70 61 60 51 50 41 40
-        movq        mm2,        mm3                         ;
-
-        punpcklbw   mm2,        mm4                         ; 33 32 23 22 13 12 03 02
-        movq        mm5,        mm1                         ; 71 70 61 60 51 50 41 40
-
-        punpckhbw   mm3,        mm4                         ; 73 72 63 62 53 52 43 42
-        movq        mm6,        mm0                         ; 31 30 21 20 11 10 01 00
-
-        punpcklwd   mm0,        mm2                         ; 13 12 11 10 03 02 01 00
-        punpckhwd   mm6,        mm2                         ; 33 32 31 30 23 22 21 20
-
-        movd        [rsi+rax*4], mm0                        ; write 03 02 01 00
-        punpcklwd   mm1,        mm3                         ; 53 52 51 50 43 42 41 40
-
-        psrlq       mm0,        32                          ; xx xx xx xx 13 12 11 10
-        punpckhwd   mm5,        mm3                         ; 73 72 71 70 63 62 61 60
-
-        movd        [rdi+rax*4], mm0                        ; write 13 12 11 10
-        movd        [rsi+rax*2], mm6                        ; write 23 22 21 20
-
-        psrlq       mm6,        32                          ; 33 32 31 30
-        movd        [rsi],      mm1                         ; write 43 42 41 40
-
-        movd        [rsi + rax], mm6                        ; write 33 32 31 30
-        neg         rax
-
-        movd        [rsi + rax*2], mm5                      ; write 63 62 61 60
-        psrlq       mm1,        32                          ; 53 52 51 50
-
-        movd        [rdi],      mm1                         ; write out 53 52 51 50
-        psrlq       mm5,        32                          ; 73 72 71 70
-
-        movd        [rdi + rax*2], mm5                      ; write 73 72 71 70
-
-        lea         rsi,        [rsi+rax*8]                 ; next 8
-
-        dec         rcx
-        jnz         .nexts8_v
-
-    add rsp, 32
-    pop rsp
-    ; begin epilog
-    pop rdi
-    pop rsi
-    RESTORE_GOT
-    UNSHADOW_ARGS
-    pop         rbp
-    ret
-
-
-
-;void fast_loop_filter_vertical_edges_mmx(unsigned char *y_ptr,
-;                  int y_stride,
-;                  loop_filter_info *lfi)
-;{
-;
-;
-;    vp8_loop_filter_simple_vertical_edge_mmx(y_ptr+4, y_stride, lfi->flim,lfi->lim,lfi->thr,2);
-;    vp8_loop_filter_simple_vertical_edge_mmx(y_ptr+8, y_stride, lfi->flim,lfi->lim,lfi->thr,2);
-;    vp8_loop_filter_simple_vertical_edge_mmx(y_ptr+12, y_stride, lfi->flim,lfi->lim,lfi->thr,2);
-;}
-
-SECTION_RODATA
-align 16
-tfe:
-    times 8 db 0xfe
-align 16
-t80:
-    times 8 db 0x80
-align 16
-t1s:
-    times 8 db 0x01
-align 16
-t3:
-    times 8 db 0x03
-align 16
-t4:
-    times 8 db 0x04
-align 16
-ones:
-    times 4 dw 0x0001
-align 16
-s27:
-    times 4 dw 0x1b00
-align 16
-s18:
-    times 4 dw 0x1200
-align 16
-s9:
-    times 4 dw 0x0900
-align 16
-s63:
-    times 4 dw 0x003f
diff --git a/vp8/decoder/dboolhuff.c b/vp8/decoder/dboolhuff.c
deleted file mode 100644 (file)
index 5cdd2a2..0000000
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#include "dboolhuff.h"
-#include "vp8/common/common.h"
-#include "vpx_dsp/vpx_dsp_common.h"
-
-int vp8dx_start_decode(BOOL_DECODER *br,
-                       const unsigned char *source,
-                       unsigned int source_sz,
-                       vpx_decrypt_cb decrypt_cb,
-                       void *decrypt_state)
-{
-    br->user_buffer_end = source+source_sz;
-    br->user_buffer     = source;
-    br->value    = 0;
-    br->count    = -8;
-    br->range    = 255;
-    br->decrypt_cb = decrypt_cb;
-    br->decrypt_state = decrypt_state;
-
-    if (source_sz && !source)
-        return 1;
-
-    /* Populate the buffer */
-    vp8dx_bool_decoder_fill(br);
-
-    return 0;
-}
-
-void vp8dx_bool_decoder_fill(BOOL_DECODER *br)
-{
-    const unsigned char *bufptr = br->user_buffer;
-    VP8_BD_VALUE value = br->value;
-    int count = br->count;
-    int shift = VP8_BD_VALUE_SIZE - CHAR_BIT - (count + CHAR_BIT);
-    size_t bytes_left = br->user_buffer_end - bufptr;
-    size_t bits_left = bytes_left * CHAR_BIT;
-    int x = shift + CHAR_BIT - (int)bits_left;
-    int loop_end = 0;
-    unsigned char decrypted[sizeof(VP8_BD_VALUE) + 1];
-
-    if (br->decrypt_cb) {
-        size_t n = VPXMIN(sizeof(decrypted), bytes_left);
-        br->decrypt_cb(br->decrypt_state, bufptr, decrypted, (int)n);
-        bufptr = decrypted;
-    }
-
-    if(x >= 0)
-    {
-        count += VP8_LOTS_OF_BITS;
-        loop_end = x;
-    }
-
-    if (x < 0 || bits_left)
-    {
-        while(shift >= loop_end)
-        {
-            count += CHAR_BIT;
-            value |= (VP8_BD_VALUE)*bufptr << shift;
-            ++bufptr;
-            ++br->user_buffer;
-            shift -= CHAR_BIT;
-        }
-    }
-
-    br->value = value;
-    br->count = count;
-}
diff --git a/vp8/decoder/dboolhuff.h b/vp8/decoder/dboolhuff.h
deleted file mode 100644 (file)
index 1b1bbf8..0000000
+++ /dev/null
@@ -1,141 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#ifndef VP8_DECODER_DBOOLHUFF_H_
-#define VP8_DECODER_DBOOLHUFF_H_
-
-#include <stddef.h>
-#include <limits.h>
-
-#include "./vpx_config.h"
-#include "vpx_ports/mem.h"
-#include "vpx/vp8dx.h"
-#include "vpx/vpx_integer.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef size_t VP8_BD_VALUE;
-
-#define VP8_BD_VALUE_SIZE ((int)sizeof(VP8_BD_VALUE)*CHAR_BIT)
-
-/*This is meant to be a large, positive constant that can still be efficiently
-   loaded as an immediate (on platforms like ARM, for example).
-  Even relatively modest values like 100 would work fine.*/
-#define VP8_LOTS_OF_BITS (0x40000000)
-
-typedef struct
-{
-    const unsigned char *user_buffer_end;
-    const unsigned char *user_buffer;
-    VP8_BD_VALUE         value;
-    int                  count;
-    unsigned int         range;
-    vpx_decrypt_cb       decrypt_cb;
-    void                *decrypt_state;
-} BOOL_DECODER;
-
-DECLARE_ALIGNED(16, extern const unsigned char, vp8_norm[256]);
-
-int vp8dx_start_decode(BOOL_DECODER *br,
-                       const unsigned char *source,
-                       unsigned int source_sz,
-                       vpx_decrypt_cb decrypt_cb,
-                       void *decrypt_state);
-
-void vp8dx_bool_decoder_fill(BOOL_DECODER *br);
-
-
-static int vp8dx_decode_bool(BOOL_DECODER *br, int probability) {
-    unsigned int bit = 0;
-    VP8_BD_VALUE value;
-    unsigned int split;
-    VP8_BD_VALUE bigsplit;
-    int count;
-    unsigned int range;
-
-    split = 1 + (((br->range - 1) * probability) >> 8);
-
-    if(br->count < 0)
-        vp8dx_bool_decoder_fill(br);
-
-    value = br->value;
-    count = br->count;
-
-    bigsplit = (VP8_BD_VALUE)split << (VP8_BD_VALUE_SIZE - 8);
-
-    range = split;
-
-    if (value >= bigsplit)
-    {
-        range = br->range - split;
-        value = value - bigsplit;
-        bit = 1;
-    }
-
-    {
-        register int shift = vp8_norm[range];
-        range <<= shift;
-        value <<= shift;
-        count -= shift;
-    }
-    br->value = value;
-    br->count = count;
-    br->range = range;
-
-    return bit;
-}
-
-static INLINE int vp8_decode_value(BOOL_DECODER *br, int bits)
-{
-    int z = 0;
-    int bit;
-
-    for (bit = bits - 1; bit >= 0; bit--)
-    {
-        z |= (vp8dx_decode_bool(br, 0x80) << bit);
-    }
-
-    return z;
-}
-
-static INLINE int vp8dx_bool_error(BOOL_DECODER *br)
-{
-    /* Check if we have reached the end of the buffer.
-     *
-     * Variable 'count' stores the number of bits in the 'value' buffer, minus
-     * 8. The top byte is part of the algorithm, and the remainder is buffered
-     * to be shifted into it. So if count == 8, the top 16 bits of 'value' are
-     * occupied, 8 for the algorithm and 8 in the buffer.
-     *
-     * When reading a byte from the user's buffer, count is filled with 8 and
-     * one byte is filled into the value buffer. When we reach the end of the
-     * data, count is additionally filled with VP8_LOTS_OF_BITS. So when
-     * count == VP8_LOTS_OF_BITS - 1, the user's data has been exhausted.
-     */
-    if ((br->count > VP8_BD_VALUE_SIZE) && (br->count < VP8_LOTS_OF_BITS))
-    {
-       /* We have tried to decode bits after the end of
-        * stream was encountered.
-        */
-        return 1;
-    }
-
-    /* No error. */
-    return 0;
-}
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP8_DECODER_DBOOLHUFF_H_
diff --git a/vp8/decoder/decodeframe.c b/vp8/decoder/decodeframe.c
deleted file mode 100644 (file)
index 566972e..0000000
+++ /dev/null
@@ -1,1400 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#include "vpx_config.h"
-#include "vp8_rtcd.h"
-#include "./vpx_scale_rtcd.h"
-#include "onyxd_int.h"
-#include "vp8/common/header.h"
-#include "vp8/common/reconintra4x4.h"
-#include "vp8/common/reconinter.h"
-#include "detokenize.h"
-#include "vp8/common/common.h"
-#include "vp8/common/invtrans.h"
-#include "vp8/common/alloccommon.h"
-#include "vp8/common/entropymode.h"
-#include "vp8/common/quant_common.h"
-#include "vpx_scale/vpx_scale.h"
-#include "vp8/common/reconintra.h"
-#include "vp8/common/setupintrarecon.h"
-
-#include "decodemv.h"
-#include "vp8/common/extend.h"
-#if CONFIG_ERROR_CONCEALMENT
-#include "error_concealment.h"
-#endif
-#include "vpx_mem/vpx_mem.h"
-#include "vp8/common/threading.h"
-#include "decoderthreading.h"
-#include "dboolhuff.h"
-#include "vpx_dsp/vpx_dsp_common.h"
-
-#include <assert.h>
-#include <stdio.h>
-
-void vp8cx_init_de_quantizer(VP8D_COMP *pbi)
-{
-    int Q;
-    VP8_COMMON *const pc = & pbi->common;
-
-    for (Q = 0; Q < QINDEX_RANGE; Q++)
-    {
-        pc->Y1dequant[Q][0] = (short)vp8_dc_quant(Q, pc->y1dc_delta_q);
-        pc->Y2dequant[Q][0] = (short)vp8_dc2quant(Q, pc->y2dc_delta_q);
-        pc->UVdequant[Q][0] = (short)vp8_dc_uv_quant(Q, pc->uvdc_delta_q);
-
-        pc->Y1dequant[Q][1] = (short)vp8_ac_yquant(Q);
-        pc->Y2dequant[Q][1] = (short)vp8_ac2quant(Q, pc->y2ac_delta_q);
-        pc->UVdequant[Q][1] = (short)vp8_ac_uv_quant(Q, pc->uvac_delta_q);
-    }
-}
-
-void vp8_mb_init_dequantizer(VP8D_COMP *pbi, MACROBLOCKD *xd)
-{
-    int i;
-    int QIndex;
-    MB_MODE_INFO *mbmi = &xd->mode_info_context->mbmi;
-    VP8_COMMON *const pc = & pbi->common;
-
-    /* Decide whether to use the default or alternate baseline Q value. */
-    if (xd->segmentation_enabled)
-    {
-        /* Abs Value */
-        if (xd->mb_segement_abs_delta == SEGMENT_ABSDATA)
-            QIndex = xd->segment_feature_data[MB_LVL_ALT_Q][mbmi->segment_id];
-
-        /* Delta Value */
-        else
-            QIndex = pc->base_qindex + xd->segment_feature_data[MB_LVL_ALT_Q][mbmi->segment_id];
-
-        QIndex = (QIndex >= 0) ? ((QIndex <= MAXQ) ? QIndex : MAXQ) : 0;    /* Clamp to valid range */
-    }
-    else
-        QIndex = pc->base_qindex;
-
-    /* Set up the macroblock dequant constants */
-    xd->dequant_y1_dc[0] = 1;
-    xd->dequant_y1[0] = pc->Y1dequant[QIndex][0];
-    xd->dequant_y2[0] = pc->Y2dequant[QIndex][0];
-    xd->dequant_uv[0] = pc->UVdequant[QIndex][0];
-
-    for (i = 1; i < 16; i++)
-    {
-        xd->dequant_y1_dc[i] =
-        xd->dequant_y1[i] = pc->Y1dequant[QIndex][1];
-        xd->dequant_y2[i] = pc->Y2dequant[QIndex][1];
-        xd->dequant_uv[i] = pc->UVdequant[QIndex][1];
-    }
-}
-
-static void decode_macroblock(VP8D_COMP *pbi, MACROBLOCKD *xd,
-                              unsigned int mb_idx)
-{
-    MB_PREDICTION_MODE mode;
-    int i;
-#if CONFIG_ERROR_CONCEALMENT
-    int corruption_detected = 0;
-#else
-    (void)mb_idx;
-#endif
-
-    if (xd->mode_info_context->mbmi.mb_skip_coeff)
-    {
-        vp8_reset_mb_tokens_context(xd);
-    }
-    else if (!vp8dx_bool_error(xd->current_bc))
-    {
-        int eobtotal;
-        eobtotal = vp8_decode_mb_tokens(pbi, xd);
-
-        /* Special case:  Force the loopfilter to skip when eobtotal is zero */
-        xd->mode_info_context->mbmi.mb_skip_coeff = (eobtotal==0);
-    }
-
-    mode = xd->mode_info_context->mbmi.mode;
-
-    if (xd->segmentation_enabled)
-        vp8_mb_init_dequantizer(pbi, xd);
-
-
-#if CONFIG_ERROR_CONCEALMENT
-
-    if(pbi->ec_active)
-    {
-        int throw_residual;
-        /* When we have independent partitions we can apply residual even
-         * though other partitions within the frame are corrupt.
-         */
-        throw_residual = (!pbi->independent_partitions &&
-                          pbi->frame_corrupt_residual);
-        throw_residual = (throw_residual || vp8dx_bool_error(xd->current_bc));
-
-        if ((mb_idx >= pbi->mvs_corrupt_from_mb || throw_residual))
-        {
-            /* MB with corrupt residuals or corrupt mode/motion vectors.
-             * Better to use the predictor as reconstruction.
-             */
-            pbi->frame_corrupt_residual = 1;
-            memset(xd->qcoeff, 0, sizeof(xd->qcoeff));
-            vp8_conceal_corrupt_mb(xd);
-
-
-            corruption_detected = 1;
-
-            /* force idct to be skipped for B_PRED and use the
-             * prediction only for reconstruction
-             * */
-            memset(xd->eobs, 0, 25);
-        }
-    }
-#endif
-
-    /* do prediction */
-    if (xd->mode_info_context->mbmi.ref_frame == INTRA_FRAME)
-    {
-        vp8_build_intra_predictors_mbuv_s(xd,
-                                          xd->recon_above[1],
-                                          xd->recon_above[2],
-                                          xd->recon_left[1],
-                                          xd->recon_left[2],
-                                          xd->recon_left_stride[1],
-                                          xd->dst.u_buffer, xd->dst.v_buffer,
-                                          xd->dst.uv_stride);
-
-        if (mode != B_PRED)
-        {
-            vp8_build_intra_predictors_mby_s(xd,
-                                                 xd->recon_above[0],
-                                                 xd->recon_left[0],
-                                                 xd->recon_left_stride[0],
-                                                 xd->dst.y_buffer,
-                                                 xd->dst.y_stride);
-        }
-        else
-        {
-            short *DQC = xd->dequant_y1;
-            int dst_stride = xd->dst.y_stride;
-
-            /* clear out residual eob info */
-            if(xd->mode_info_context->mbmi.mb_skip_coeff)
-                memset(xd->eobs, 0, 25);
-
-            intra_prediction_down_copy(xd, xd->recon_above[0] + 16);
-
-            for (i = 0; i < 16; i++)
-            {
-                BLOCKD *b = &xd->block[i];
-                unsigned char *dst = xd->dst.y_buffer + b->offset;
-                B_PREDICTION_MODE b_mode =
-                    xd->mode_info_context->bmi[i].as_mode;
-                unsigned char *Above = dst - dst_stride;
-                unsigned char *yleft = dst - 1;
-                int left_stride = dst_stride;
-                unsigned char top_left = Above[-1];
-
-                vp8_intra4x4_predict(Above, yleft, left_stride, b_mode,
-                                     dst, dst_stride, top_left);
-
-                if (xd->eobs[i])
-                {
-                    if (xd->eobs[i] > 1)
-                    {
-                    vp8_dequant_idct_add(b->qcoeff, DQC, dst, dst_stride);
-                    }
-                    else
-                    {
-                        vp8_dc_only_idct_add
-                            (b->qcoeff[0] * DQC[0],
-                                dst, dst_stride,
-                                dst, dst_stride);
-                        memset(b->qcoeff, 0, 2 * sizeof(b->qcoeff[0]));
-                    }
-                }
-            }
-        }
-    }
-    else
-    {
-        vp8_build_inter_predictors_mb(xd);
-    }
-
-
-#if CONFIG_ERROR_CONCEALMENT
-    if (corruption_detected)
-    {
-        return;
-    }
-#endif
-
-    if(!xd->mode_info_context->mbmi.mb_skip_coeff)
-    {
-        /* dequantization and idct */
-        if (mode != B_PRED)
-        {
-            short *DQC = xd->dequant_y1;
-
-            if (mode != SPLITMV)
-            {
-                BLOCKD *b = &xd->block[24];
-
-                /* do 2nd order transform on the dc block */
-                if (xd->eobs[24] > 1)
-                {
-                    vp8_dequantize_b(b, xd->dequant_y2);
-
-                    vp8_short_inv_walsh4x4(&b->dqcoeff[0],
-                        xd->qcoeff);
-                    memset(b->qcoeff, 0, 16 * sizeof(b->qcoeff[0]));
-                }
-                else
-                {
-                    b->dqcoeff[0] = b->qcoeff[0] * xd->dequant_y2[0];
-                    vp8_short_inv_walsh4x4_1(&b->dqcoeff[0],
-                        xd->qcoeff);
-                    memset(b->qcoeff, 0, 2 * sizeof(b->qcoeff[0]));
-                }
-
-                /* override the dc dequant constant in order to preserve the
-                 * dc components
-                 */
-                DQC = xd->dequant_y1_dc;
-            }
-
-            vp8_dequant_idct_add_y_block
-                            (xd->qcoeff, DQC,
-                             xd->dst.y_buffer,
-                             xd->dst.y_stride, xd->eobs);
-        }
-
-        vp8_dequant_idct_add_uv_block
-                        (xd->qcoeff+16*16, xd->dequant_uv,
-                         xd->dst.u_buffer, xd->dst.v_buffer,
-                         xd->dst.uv_stride, xd->eobs+16);
-    }
-}
-
-static int get_delta_q(vp8_reader *bc, int prev, int *q_update)
-{
-    int ret_val = 0;
-
-    if (vp8_read_bit(bc))
-    {
-        ret_val = vp8_read_literal(bc, 4);
-
-        if (vp8_read_bit(bc))
-            ret_val = -ret_val;
-    }
-
-    /* Trigger a quantizer update if the delta-q value has changed */
-    if (ret_val != prev)
-        *q_update = 1;
-
-    return ret_val;
-}
-
-#ifdef PACKET_TESTING
-#include <stdio.h>
-FILE *vpxlog = 0;
-#endif
-
-static void yv12_extend_frame_top_c(YV12_BUFFER_CONFIG *ybf)
-{
-    int i;
-    unsigned char *src_ptr1;
-    unsigned char *dest_ptr1;
-
-    unsigned int Border;
-    int plane_stride;
-
-    /***********/
-    /* Y Plane */
-    /***********/
-    Border = ybf->border;
-    plane_stride = ybf->y_stride;
-    src_ptr1 = ybf->y_buffer - Border;
-    dest_ptr1 = src_ptr1 - (Border * plane_stride);
-
-    for (i = 0; i < (int)Border; i++)
-    {
-        memcpy(dest_ptr1, src_ptr1, plane_stride);
-        dest_ptr1 += plane_stride;
-    }
-
-
-    /***********/
-    /* U Plane */
-    /***********/
-    plane_stride = ybf->uv_stride;
-    Border /= 2;
-    src_ptr1 = ybf->u_buffer - Border;
-    dest_ptr1 = src_ptr1 - (Border * plane_stride);
-
-    for (i = 0; i < (int)(Border); i++)
-    {
-        memcpy(dest_ptr1, src_ptr1, plane_stride);
-        dest_ptr1 += plane_stride;
-    }
-
-    /***********/
-    /* V Plane */
-    /***********/
-
-    src_ptr1 = ybf->v_buffer - Border;
-    dest_ptr1 = src_ptr1 - (Border * plane_stride);
-
-    for (i = 0; i < (int)(Border); i++)
-    {
-        memcpy(dest_ptr1, src_ptr1, plane_stride);
-        dest_ptr1 += plane_stride;
-    }
-}
-
-static void yv12_extend_frame_bottom_c(YV12_BUFFER_CONFIG *ybf)
-{
-    int i;
-    unsigned char *src_ptr1, *src_ptr2;
-    unsigned char *dest_ptr2;
-
-    unsigned int Border;
-    int plane_stride;
-    int plane_height;
-
-    /***********/
-    /* Y Plane */
-    /***********/
-    Border = ybf->border;
-    plane_stride = ybf->y_stride;
-    plane_height = ybf->y_height;
-
-    src_ptr1 = ybf->y_buffer - Border;
-    src_ptr2 = src_ptr1 + (plane_height * plane_stride) - plane_stride;
-    dest_ptr2 = src_ptr2 + plane_stride;
-
-    for (i = 0; i < (int)Border; i++)
-    {
-        memcpy(dest_ptr2, src_ptr2, plane_stride);
-        dest_ptr2 += plane_stride;
-    }
-
-
-    /***********/
-    /* U Plane */
-    /***********/
-    plane_stride = ybf->uv_stride;
-    plane_height = ybf->uv_height;
-    Border /= 2;
-
-    src_ptr1 = ybf->u_buffer - Border;
-    src_ptr2 = src_ptr1 + (plane_height * plane_stride) - plane_stride;
-    dest_ptr2 = src_ptr2 + plane_stride;
-
-    for (i = 0; i < (int)(Border); i++)
-    {
-        memcpy(dest_ptr2, src_ptr2, plane_stride);
-        dest_ptr2 += plane_stride;
-    }
-
-    /***********/
-    /* V Plane */
-    /***********/
-
-    src_ptr1 = ybf->v_buffer - Border;
-    src_ptr2 = src_ptr1 + (plane_height * plane_stride) - plane_stride;
-    dest_ptr2 = src_ptr2 + plane_stride;
-
-    for (i = 0; i < (int)(Border); i++)
-    {
-        memcpy(dest_ptr2, src_ptr2, plane_stride);
-        dest_ptr2 += plane_stride;
-    }
-}
-
-static void yv12_extend_frame_left_right_c(YV12_BUFFER_CONFIG *ybf,
-                                           unsigned char *y_src,
-                                           unsigned char *u_src,
-                                           unsigned char *v_src)
-{
-    int i;
-    unsigned char *src_ptr1, *src_ptr2;
-    unsigned char *dest_ptr1, *dest_ptr2;
-
-    unsigned int Border;
-    int plane_stride;
-    int plane_height;
-    int plane_width;
-
-    /***********/
-    /* Y Plane */
-    /***********/
-    Border = ybf->border;
-    plane_stride = ybf->y_stride;
-    plane_height = 16;
-    plane_width = ybf->y_width;
-
-    /* copy the left and right most columns out */
-    src_ptr1 = y_src;
-    src_ptr2 = src_ptr1 + plane_width - 1;
-    dest_ptr1 = src_ptr1 - Border;
-    dest_ptr2 = src_ptr2 + 1;
-
-    for (i = 0; i < plane_height; i++)
-    {
-        memset(dest_ptr1, src_ptr1[0], Border);
-        memset(dest_ptr2, src_ptr2[0], Border);
-        src_ptr1  += plane_stride;
-        src_ptr2  += plane_stride;
-        dest_ptr1 += plane_stride;
-        dest_ptr2 += plane_stride;
-    }
-
-    /***********/
-    /* U Plane */
-    /***********/
-    plane_stride = ybf->uv_stride;
-    plane_height = 8;
-    plane_width = ybf->uv_width;
-    Border /= 2;
-
-    /* copy the left and right most columns out */
-    src_ptr1 = u_src;
-    src_ptr2 = src_ptr1 + plane_width - 1;
-    dest_ptr1 = src_ptr1 - Border;
-    dest_ptr2 = src_ptr2 + 1;
-
-    for (i = 0; i < plane_height; i++)
-    {
-        memset(dest_ptr1, src_ptr1[0], Border);
-        memset(dest_ptr2, src_ptr2[0], Border);
-        src_ptr1  += plane_stride;
-        src_ptr2  += plane_stride;
-        dest_ptr1 += plane_stride;
-        dest_ptr2 += plane_stride;
-    }
-
-    /***********/
-    /* V Plane */
-    /***********/
-
-    /* copy the left and right most columns out */
-    src_ptr1 = v_src;
-    src_ptr2 = src_ptr1 + plane_width - 1;
-    dest_ptr1 = src_ptr1 - Border;
-    dest_ptr2 = src_ptr2 + 1;
-
-    for (i = 0; i < plane_height; i++)
-    {
-        memset(dest_ptr1, src_ptr1[0], Border);
-        memset(dest_ptr2, src_ptr2[0], Border);
-        src_ptr1  += plane_stride;
-        src_ptr2  += plane_stride;
-        dest_ptr1 += plane_stride;
-        dest_ptr2 += plane_stride;
-    }
-}
-
-static void decode_mb_rows(VP8D_COMP *pbi)
-{
-    VP8_COMMON *const pc = & pbi->common;
-    MACROBLOCKD *const xd  = & pbi->mb;
-
-    MODE_INFO *lf_mic = xd->mode_info_context;
-
-    int ibc = 0;
-    int num_part = 1 << pc->multi_token_partition;
-
-    int recon_yoffset, recon_uvoffset;
-    int mb_row, mb_col;
-    int mb_idx = 0;
-
-    YV12_BUFFER_CONFIG *yv12_fb_new = pbi->dec_fb_ref[INTRA_FRAME];
-
-    int recon_y_stride = yv12_fb_new->y_stride;
-    int recon_uv_stride = yv12_fb_new->uv_stride;
-
-    unsigned char *ref_buffer[MAX_REF_FRAMES][3];
-    unsigned char *dst_buffer[3];
-    unsigned char *lf_dst[3];
-    unsigned char *eb_dst[3];
-    int i;
-    int ref_fb_corrupted[MAX_REF_FRAMES];
-
-    ref_fb_corrupted[INTRA_FRAME] = 0;
-
-    for(i = 1; i < MAX_REF_FRAMES; i++)
-    {
-        YV12_BUFFER_CONFIG *this_fb = pbi->dec_fb_ref[i];
-
-        ref_buffer[i][0] = this_fb->y_buffer;
-        ref_buffer[i][1] = this_fb->u_buffer;
-        ref_buffer[i][2] = this_fb->v_buffer;
-
-        ref_fb_corrupted[i] = this_fb->corrupted;
-    }
-
-    /* Set up the buffer pointers */
-    eb_dst[0] = lf_dst[0] = dst_buffer[0] = yv12_fb_new->y_buffer;
-    eb_dst[1] = lf_dst[1] = dst_buffer[1] = yv12_fb_new->u_buffer;
-    eb_dst[2] = lf_dst[2] = dst_buffer[2] = yv12_fb_new->v_buffer;
-
-    xd->up_available = 0;
-
-    /* Initialize the loop filter for this frame. */
-    if(pc->filter_level)
-        vp8_loop_filter_frame_init(pc, xd, pc->filter_level);
-
-    vp8_setup_intra_recon_top_line(yv12_fb_new);
-
-    /* Decode the individual macro block */
-    for (mb_row = 0; mb_row < pc->mb_rows; mb_row++)
-    {
-        if (num_part > 1)
-        {
-            xd->current_bc = & pbi->mbc[ibc];
-            ibc++;
-
-            if (ibc == num_part)
-                ibc = 0;
-        }
-
-        recon_yoffset = mb_row * recon_y_stride * 16;
-        recon_uvoffset = mb_row * recon_uv_stride * 8;
-
-        /* reset contexts */
-        xd->above_context = pc->above_context;
-        memset(xd->left_context, 0, sizeof(ENTROPY_CONTEXT_PLANES));
-
-        xd->left_available = 0;
-
-        xd->mb_to_top_edge = -((mb_row * 16) << 3);
-        xd->mb_to_bottom_edge = ((pc->mb_rows - 1 - mb_row) * 16) << 3;
-
-        xd->recon_above[0] = dst_buffer[0] + recon_yoffset;
-        xd->recon_above[1] = dst_buffer[1] + recon_uvoffset;
-        xd->recon_above[2] = dst_buffer[2] + recon_uvoffset;
-
-        xd->recon_left[0] = xd->recon_above[0] - 1;
-        xd->recon_left[1] = xd->recon_above[1] - 1;
-        xd->recon_left[2] = xd->recon_above[2] - 1;
-
-        xd->recon_above[0] -= xd->dst.y_stride;
-        xd->recon_above[1] -= xd->dst.uv_stride;
-        xd->recon_above[2] -= xd->dst.uv_stride;
-
-        /* TODO: move to outside row loop */
-        xd->recon_left_stride[0] = xd->dst.y_stride;
-        xd->recon_left_stride[1] = xd->dst.uv_stride;
-
-        setup_intra_recon_left(xd->recon_left[0], xd->recon_left[1],
-                               xd->recon_left[2], xd->dst.y_stride,
-                               xd->dst.uv_stride);
-
-        for (mb_col = 0; mb_col < pc->mb_cols; mb_col++)
-        {
-            /* Distance of Mb to the various image edges.
-             * These are specified to 8th pel as they are always compared to values
-             * that are in 1/8th pel units
-             */
-            xd->mb_to_left_edge = -((mb_col * 16) << 3);
-            xd->mb_to_right_edge = ((pc->mb_cols - 1 - mb_col) * 16) << 3;
-
-#if CONFIG_ERROR_CONCEALMENT
-            {
-                int corrupt_residual = (!pbi->independent_partitions &&
-                                       pbi->frame_corrupt_residual) ||
-                                       vp8dx_bool_error(xd->current_bc);
-                if (pbi->ec_active &&
-                    xd->mode_info_context->mbmi.ref_frame == INTRA_FRAME &&
-                    corrupt_residual)
-                {
-                    /* We have an intra block with corrupt coefficients, better to
-                     * conceal with an inter block. Interpolate MVs from neighboring
-                     * MBs.
-                     *
-                     * Note that for the first mb with corrupt residual in a frame,
-                     * we might not discover that before decoding the residual. That
-                     * happens after this check, and therefore no inter concealment
-                     * will be done.
-                     */
-                    vp8_interpolate_motion(xd,
-                                           mb_row, mb_col,
-                                           pc->mb_rows, pc->mb_cols,
-                                           pc->mode_info_stride);
-                }
-            }
-#endif
-
-            xd->dst.y_buffer = dst_buffer[0] + recon_yoffset;
-            xd->dst.u_buffer = dst_buffer[1] + recon_uvoffset;
-            xd->dst.v_buffer = dst_buffer[2] + recon_uvoffset;
-
-            if (xd->mode_info_context->mbmi.ref_frame >= LAST_FRAME) {
-              const MV_REFERENCE_FRAME ref = xd->mode_info_context->mbmi.ref_frame;
-              xd->pre.y_buffer = ref_buffer[ref][0] + recon_yoffset;
-              xd->pre.u_buffer = ref_buffer[ref][1] + recon_uvoffset;
-              xd->pre.v_buffer = ref_buffer[ref][2] + recon_uvoffset;
-            } else {
-              // ref_frame is INTRA_FRAME, pre buffer should not be used.
-              xd->pre.y_buffer = 0;
-              xd->pre.u_buffer = 0;
-              xd->pre.v_buffer = 0;
-            }
-
-            /* propagate errors from reference frames */
-            xd->corrupted |= ref_fb_corrupted[xd->mode_info_context->mbmi.ref_frame];
-
-            decode_macroblock(pbi, xd, mb_idx);
-
-            mb_idx++;
-            xd->left_available = 1;
-
-            /* check if the boolean decoder has suffered an error */
-            xd->corrupted |= vp8dx_bool_error(xd->current_bc);
-
-            xd->recon_above[0] += 16;
-            xd->recon_above[1] += 8;
-            xd->recon_above[2] += 8;
-            xd->recon_left[0] += 16;
-            xd->recon_left[1] += 8;
-            xd->recon_left[2] += 8;
-
-            recon_yoffset += 16;
-            recon_uvoffset += 8;
-
-            ++xd->mode_info_context;  /* next mb */
-
-            xd->above_context++;
-        }
-
-        /* adjust to the next row of mbs */
-        vp8_extend_mb_row(yv12_fb_new, xd->dst.y_buffer + 16,
-                          xd->dst.u_buffer + 8, xd->dst.v_buffer + 8);
-
-        ++xd->mode_info_context;      /* skip prediction column */
-        xd->up_available = 1;
-
-        if(pc->filter_level)
-        {
-            if(mb_row > 0)
-            {
-                if (pc->filter_type == NORMAL_LOOPFILTER)
-                    vp8_loop_filter_row_normal(pc, lf_mic, mb_row-1,
-                                               recon_y_stride, recon_uv_stride,
-                                               lf_dst[0], lf_dst[1], lf_dst[2]);
-                else
-                    vp8_loop_filter_row_simple(pc, lf_mic, mb_row-1,
-                                               recon_y_stride, recon_uv_stride,
-                                               lf_dst[0], lf_dst[1], lf_dst[2]);
-                if(mb_row > 1)
-                {
-                    yv12_extend_frame_left_right_c(yv12_fb_new,
-                                                   eb_dst[0],
-                                                   eb_dst[1],
-                                                   eb_dst[2]);
-
-                    eb_dst[0] += recon_y_stride  * 16;
-                    eb_dst[1] += recon_uv_stride *  8;
-                    eb_dst[2] += recon_uv_stride *  8;
-                }
-
-                lf_dst[0] += recon_y_stride  * 16;
-                lf_dst[1] += recon_uv_stride *  8;
-                lf_dst[2] += recon_uv_stride *  8;
-                lf_mic += pc->mb_cols;
-                lf_mic++;         /* Skip border mb */
-            }
-        }
-        else
-        {
-            if(mb_row > 0)
-            {
-                /**/
-                yv12_extend_frame_left_right_c(yv12_fb_new,
-                                               eb_dst[0],
-                                               eb_dst[1],
-                                               eb_dst[2]);
-                eb_dst[0] += recon_y_stride  * 16;
-                eb_dst[1] += recon_uv_stride *  8;
-                eb_dst[2] += recon_uv_stride *  8;
-            }
-        }
-    }
-
-    if(pc->filter_level)
-    {
-        if (pc->filter_type == NORMAL_LOOPFILTER)
-            vp8_loop_filter_row_normal(pc, lf_mic, mb_row-1, recon_y_stride,
-                                       recon_uv_stride, lf_dst[0], lf_dst[1],
-                                       lf_dst[2]);
-        else
-            vp8_loop_filter_row_simple(pc, lf_mic, mb_row-1, recon_y_stride,
-                                       recon_uv_stride, lf_dst[0], lf_dst[1],
-                                       lf_dst[2]);
-
-        yv12_extend_frame_left_right_c(yv12_fb_new,
-                                       eb_dst[0],
-                                       eb_dst[1],
-                                       eb_dst[2]);
-        eb_dst[0] += recon_y_stride  * 16;
-        eb_dst[1] += recon_uv_stride *  8;
-        eb_dst[2] += recon_uv_stride *  8;
-    }
-    yv12_extend_frame_left_right_c(yv12_fb_new,
-                                   eb_dst[0],
-                                   eb_dst[1],
-                                   eb_dst[2]);
-    yv12_extend_frame_top_c(yv12_fb_new);
-    yv12_extend_frame_bottom_c(yv12_fb_new);
-
-}
-
-static unsigned int read_partition_size(VP8D_COMP *pbi,
-                                        const unsigned char *cx_size)
-{
-    unsigned char temp[3];
-    if (pbi->decrypt_cb)
-    {
-        pbi->decrypt_cb(pbi->decrypt_state, cx_size, temp, 3);
-        cx_size = temp;
-    }
-    return cx_size[0] + (cx_size[1] << 8) + (cx_size[2] << 16);
-}
-
-static int read_is_valid(const unsigned char *start,
-                         size_t               len,
-                         const unsigned char *end)
-{
-    return (start + len > start && start + len <= end);
-}
-
-static unsigned int read_available_partition_size(
-                                       VP8D_COMP *pbi,
-                                       const unsigned char *token_part_sizes,
-                                       const unsigned char *fragment_start,
-                                       const unsigned char *first_fragment_end,
-                                       const unsigned char *fragment_end,
-                                       int i,
-                                       int num_part)
-{
-    VP8_COMMON* pc = &pbi->common;
-    const unsigned char *partition_size_ptr = token_part_sizes + i * 3;
-    unsigned int partition_size = 0;
-    ptrdiff_t bytes_left = fragment_end - fragment_start;
-    /* Calculate the length of this partition. The last partition
-     * size is implicit. If the partition size can't be read, then
-     * either use the remaining data in the buffer (for EC mode)
-     * or throw an error.
-     */
-    if (i < num_part - 1)
-    {
-        if (read_is_valid(partition_size_ptr, 3, first_fragment_end))
-            partition_size = read_partition_size(pbi, partition_size_ptr);
-        else if (pbi->ec_active)
-            partition_size = (unsigned int)bytes_left;
-        else
-            vpx_internal_error(&pc->error, VPX_CODEC_CORRUPT_FRAME,
-                               "Truncated partition size data");
-    }
-    else
-        partition_size = (unsigned int)bytes_left;
-
-    /* Validate the calculated partition length. If the buffer
-     * described by the partition can't be fully read, then restrict
-     * it to the portion that can be (for EC mode) or throw an error.
-     */
-    if (!read_is_valid(fragment_start, partition_size, fragment_end))
-    {
-        if (pbi->ec_active)
-            partition_size = (unsigned int)bytes_left;
-        else
-            vpx_internal_error(&pc->error, VPX_CODEC_CORRUPT_FRAME,
-                               "Truncated packet or corrupt partition "
-                               "%d length", i + 1);
-    }
-    return partition_size;
-}
-
-
-static void setup_token_decoder(VP8D_COMP *pbi,
-                                const unsigned char* token_part_sizes)
-{
-    vp8_reader *bool_decoder = &pbi->mbc[0];
-    unsigned int partition_idx;
-    unsigned int fragment_idx;
-    unsigned int num_token_partitions;
-    const unsigned char *first_fragment_end = pbi->fragments.ptrs[0] +
-                                          pbi->fragments.sizes[0];
-
-    TOKEN_PARTITION multi_token_partition =
-            (TOKEN_PARTITION)vp8_read_literal(&pbi->mbc[8], 2);
-    if (!vp8dx_bool_error(&pbi->mbc[8]))
-        pbi->common.multi_token_partition = multi_token_partition;
-    num_token_partitions = 1 << pbi->common.multi_token_partition;
-
-    /* Check for partitions within the fragments and unpack the fragments
-     * so that each fragment pointer points to its corresponding partition. */
-    for (fragment_idx = 0; fragment_idx < pbi->fragments.count; ++fragment_idx)
-    {
-        unsigned int fragment_size = pbi->fragments.sizes[fragment_idx];
-        const unsigned char *fragment_end = pbi->fragments.ptrs[fragment_idx] +
-                                            fragment_size;
-        /* Special case for handling the first partition since we have already
-         * read its size. */
-        if (fragment_idx == 0)
-        {
-            /* Size of first partition + token partition sizes element */
-            ptrdiff_t ext_first_part_size = token_part_sizes -
-                pbi->fragments.ptrs[0] + 3 * (num_token_partitions - 1);
-            fragment_size -= (unsigned int)ext_first_part_size;
-            if (fragment_size > 0)
-            {
-                pbi->fragments.sizes[0] = (unsigned int)ext_first_part_size;
-                /* The fragment contains an additional partition. Move to
-                 * next. */
-                fragment_idx++;
-                pbi->fragments.ptrs[fragment_idx] = pbi->fragments.ptrs[0] +
-                  pbi->fragments.sizes[0];
-            }
-        }
-        /* Split the chunk into partitions read from the bitstream */
-        while (fragment_size > 0)
-        {
-            ptrdiff_t partition_size = read_available_partition_size(
-                                                 pbi,
-                                                 token_part_sizes,
-                                                 pbi->fragments.ptrs[fragment_idx],
-                                                 first_fragment_end,
-                                                 fragment_end,
-                                                 fragment_idx - 1,
-                                                 num_token_partitions);
-            pbi->fragments.sizes[fragment_idx] = (unsigned int)partition_size;
-            fragment_size -= (unsigned int)partition_size;
-            assert(fragment_idx <= num_token_partitions);
-            if (fragment_size > 0)
-            {
-                /* The fragment contains an additional partition.
-                 * Move to next. */
-                fragment_idx++;
-                pbi->fragments.ptrs[fragment_idx] =
-                    pbi->fragments.ptrs[fragment_idx - 1] + partition_size;
-            }
-        }
-    }
-
-    pbi->fragments.count = num_token_partitions + 1;
-
-    for (partition_idx = 1; partition_idx < pbi->fragments.count; ++partition_idx)
-    {
-        if (vp8dx_start_decode(bool_decoder,
-                               pbi->fragments.ptrs[partition_idx],
-                               pbi->fragments.sizes[partition_idx],
-                               pbi->decrypt_cb, pbi->decrypt_state))
-            vpx_internal_error(&pbi->common.error, VPX_CODEC_MEM_ERROR,
-                               "Failed to allocate bool decoder %d",
-                               partition_idx);
-
-        bool_decoder++;
-    }
-
-#if CONFIG_MULTITHREAD
-    /* Clamp number of decoder threads */
-    if (pbi->decoding_thread_count > num_token_partitions - 1)
-        pbi->decoding_thread_count = num_token_partitions - 1;
-#endif
-}
-
-
-static void init_frame(VP8D_COMP *pbi)
-{
-    VP8_COMMON *const pc = & pbi->common;
-    MACROBLOCKD *const xd  = & pbi->mb;
-
-    if (pc->frame_type == KEY_FRAME)
-    {
-        /* Various keyframe initializations */
-        memcpy(pc->fc.mvc, vp8_default_mv_context, sizeof(vp8_default_mv_context));
-
-        vp8_init_mbmode_probs(pc);
-
-        vp8_default_coef_probs(pc);
-
-        /* reset the segment feature data to 0 with delta coding (Default state). */
-        memset(xd->segment_feature_data, 0, sizeof(xd->segment_feature_data));
-        xd->mb_segement_abs_delta = SEGMENT_DELTADATA;
-
-        /* reset the mode ref deltasa for loop filter */
-        memset(xd->ref_lf_deltas, 0, sizeof(xd->ref_lf_deltas));
-        memset(xd->mode_lf_deltas, 0, sizeof(xd->mode_lf_deltas));
-
-        /* All buffers are implicitly updated on key frames. */
-        pc->refresh_golden_frame = 1;
-        pc->refresh_alt_ref_frame = 1;
-        pc->copy_buffer_to_gf = 0;
-        pc->copy_buffer_to_arf = 0;
-
-        /* Note that Golden and Altref modes cannot be used on a key frame so
-         * ref_frame_sign_bias[] is undefined and meaningless
-         */
-        pc->ref_frame_sign_bias[GOLDEN_FRAME] = 0;
-        pc->ref_frame_sign_bias[ALTREF_FRAME] = 0;
-    }
-    else
-    {
-        /* To enable choice of different interploation filters */
-        if (!pc->use_bilinear_mc_filter)
-        {
-            xd->subpixel_predict        = vp8_sixtap_predict4x4;
-            xd->subpixel_predict8x4     = vp8_sixtap_predict8x4;
-            xd->subpixel_predict8x8     = vp8_sixtap_predict8x8;
-            xd->subpixel_predict16x16   = vp8_sixtap_predict16x16;
-        }
-        else
-        {
-            xd->subpixel_predict        = vp8_bilinear_predict4x4;
-            xd->subpixel_predict8x4     = vp8_bilinear_predict8x4;
-            xd->subpixel_predict8x8     = vp8_bilinear_predict8x8;
-            xd->subpixel_predict16x16   = vp8_bilinear_predict16x16;
-        }
-
-        if (pbi->decoded_key_frame && pbi->ec_enabled && !pbi->ec_active)
-            pbi->ec_active = 1;
-    }
-
-    xd->left_context = &pc->left_context;
-    xd->mode_info_context = pc->mi;
-    xd->frame_type = pc->frame_type;
-    xd->mode_info_context->mbmi.mode = DC_PRED;
-    xd->mode_info_stride = pc->mode_info_stride;
-    xd->corrupted = 0; /* init without corruption */
-
-    xd->fullpixel_mask = 0xffffffff;
-    if(pc->full_pixel)
-        xd->fullpixel_mask = 0xfffffff8;
-
-}
-
-int vp8_decode_frame(VP8D_COMP *pbi)
-{
-    vp8_reader *const bc = &pbi->mbc[8];
-    VP8_COMMON *const pc = &pbi->common;
-    MACROBLOCKD *const xd  = &pbi->mb;
-    const unsigned char *data = pbi->fragments.ptrs[0];
-    const unsigned int data_sz = pbi->fragments.sizes[0];
-    const unsigned char *data_end = data + data_sz;
-    ptrdiff_t first_partition_length_in_bytes;
-
-    int i, j, k, l;
-    const int *const mb_feature_data_bits = vp8_mb_feature_data_bits;
-    int corrupt_tokens = 0;
-    int prev_independent_partitions = pbi->independent_partitions;
-
-    YV12_BUFFER_CONFIG *yv12_fb_new = pbi->dec_fb_ref[INTRA_FRAME];
-
-    /* start with no corruption of current frame */
-    xd->corrupted = 0;
-    yv12_fb_new->corrupted = 0;
-
-    if (data_end - data < 3)
-    {
-        if (!pbi->ec_active)
-        {
-            vpx_internal_error(&pc->error, VPX_CODEC_CORRUPT_FRAME,
-                               "Truncated packet");
-        }
-
-        /* Declare the missing frame as an inter frame since it will
-           be handled as an inter frame when we have estimated its
-           motion vectors. */
-        pc->frame_type = INTER_FRAME;
-        pc->version = 0;
-        pc->show_frame = 1;
-        first_partition_length_in_bytes = 0;
-    }
-    else
-    {
-        unsigned char clear_buffer[10];
-        const unsigned char *clear = data;
-        if (pbi->decrypt_cb)
-        {
-            int n = (int)VPXMIN(sizeof(clear_buffer), data_sz);
-            pbi->decrypt_cb(pbi->decrypt_state, data, clear_buffer, n);
-            clear = clear_buffer;
-        }
-
-        pc->frame_type = (FRAME_TYPE)(clear[0] & 1);
-        pc->version = (clear[0] >> 1) & 7;
-        pc->show_frame = (clear[0] >> 4) & 1;
-        first_partition_length_in_bytes =
-            (clear[0] | (clear[1] << 8) | (clear[2] << 16)) >> 5;
-
-        if (!pbi->ec_active &&
-            (data + first_partition_length_in_bytes > data_end
-            || data + first_partition_length_in_bytes < data))
-            vpx_internal_error(&pc->error, VPX_CODEC_CORRUPT_FRAME,
-                               "Truncated packet or corrupt partition 0 length");
-
-        data += 3;
-        clear += 3;
-
-        vp8_setup_version(pc);
-
-
-        if (pc->frame_type == KEY_FRAME)
-        {
-            /* vet via sync code */
-            /* When error concealment is enabled we should only check the sync
-             * code if we have enough bits available
-             */
-            if (!pbi->ec_active || data + 3 < data_end)
-            {
-                if (clear[0] != 0x9d || clear[1] != 0x01 || clear[2] != 0x2a)
-                    vpx_internal_error(&pc->error, VPX_CODEC_UNSUP_BITSTREAM,
-                                   "Invalid frame sync code");
-            }
-
-            /* If error concealment is enabled we should only parse the new size
-             * if we have enough data. Otherwise we will end up with the wrong
-             * size.
-             */
-            if (!pbi->ec_active || data + 6 < data_end)
-            {
-                pc->Width = (clear[3] | (clear[4] << 8)) & 0x3fff;
-                pc->horiz_scale = clear[4] >> 6;
-                pc->Height = (clear[5] | (clear[6] << 8)) & 0x3fff;
-                pc->vert_scale = clear[6] >> 6;
-            }
-            data += 7;
-        }
-        else
-        {
-          memcpy(&xd->pre, yv12_fb_new, sizeof(YV12_BUFFER_CONFIG));
-          memcpy(&xd->dst, yv12_fb_new, sizeof(YV12_BUFFER_CONFIG));
-        }
-    }
-    if ((!pbi->decoded_key_frame && pc->frame_type != KEY_FRAME))
-    {
-        return -1;
-    }
-
-    init_frame(pbi);
-
-    if (vp8dx_start_decode(bc, data, (unsigned int)(data_end - data),
-                           pbi->decrypt_cb, pbi->decrypt_state))
-        vpx_internal_error(&pc->error, VPX_CODEC_MEM_ERROR,
-                           "Failed to allocate bool decoder 0");
-    if (pc->frame_type == KEY_FRAME) {
-        (void)vp8_read_bit(bc);  // colorspace
-        pc->clamp_type  = (CLAMP_TYPE)vp8_read_bit(bc);
-    }
-
-    /* Is segmentation enabled */
-    xd->segmentation_enabled = (unsigned char)vp8_read_bit(bc);
-
-    if (xd->segmentation_enabled)
-    {
-        /* Signal whether or not the segmentation map is being explicitly updated this frame. */
-        xd->update_mb_segmentation_map = (unsigned char)vp8_read_bit(bc);
-        xd->update_mb_segmentation_data = (unsigned char)vp8_read_bit(bc);
-
-        if (xd->update_mb_segmentation_data)
-        {
-            xd->mb_segement_abs_delta = (unsigned char)vp8_read_bit(bc);
-
-            memset(xd->segment_feature_data, 0, sizeof(xd->segment_feature_data));
-
-            /* For each segmentation feature (Quant and loop filter level) */
-            for (i = 0; i < MB_LVL_MAX; i++)
-            {
-                for (j = 0; j < MAX_MB_SEGMENTS; j++)
-                {
-                    /* Frame level data */
-                    if (vp8_read_bit(bc))
-                    {
-                        xd->segment_feature_data[i][j] = (signed char)vp8_read_literal(bc, mb_feature_data_bits[i]);
-
-                        if (vp8_read_bit(bc))
-                            xd->segment_feature_data[i][j] = -xd->segment_feature_data[i][j];
-                    }
-                    else
-                        xd->segment_feature_data[i][j] = 0;
-                }
-            }
-        }
-
-        if (xd->update_mb_segmentation_map)
-        {
-            /* Which macro block level features are enabled */
-            memset(xd->mb_segment_tree_probs, 255, sizeof(xd->mb_segment_tree_probs));
-
-            /* Read the probs used to decode the segment id for each macro block. */
-            for (i = 0; i < MB_FEATURE_TREE_PROBS; i++)
-            {
-                /* If not explicitly set value is defaulted to 255 by memset above */
-                if (vp8_read_bit(bc))
-                    xd->mb_segment_tree_probs[i] = (vp8_prob)vp8_read_literal(bc, 8);
-            }
-        }
-    }
-    else
-    {
-        /* No segmentation updates on this frame */
-        xd->update_mb_segmentation_map = 0;
-        xd->update_mb_segmentation_data = 0;
-    }
-
-    /* Read the loop filter level and type */
-    pc->filter_type = (LOOPFILTERTYPE) vp8_read_bit(bc);
-    pc->filter_level = vp8_read_literal(bc, 6);
-    pc->sharpness_level = vp8_read_literal(bc, 3);
-
-    /* Read in loop filter deltas applied at the MB level based on mode or ref frame. */
-    xd->mode_ref_lf_delta_update = 0;
-    xd->mode_ref_lf_delta_enabled = (unsigned char)vp8_read_bit(bc);
-
-    if (xd->mode_ref_lf_delta_enabled)
-    {
-        /* Do the deltas need to be updated */
-        xd->mode_ref_lf_delta_update = (unsigned char)vp8_read_bit(bc);
-
-        if (xd->mode_ref_lf_delta_update)
-        {
-            /* Send update */
-            for (i = 0; i < MAX_REF_LF_DELTAS; i++)
-            {
-                if (vp8_read_bit(bc))
-                {
-                    /*sign = vp8_read_bit( bc );*/
-                    xd->ref_lf_deltas[i] = (signed char)vp8_read_literal(bc, 6);
-
-                    if (vp8_read_bit(bc))        /* Apply sign */
-                        xd->ref_lf_deltas[i] = xd->ref_lf_deltas[i] * -1;
-                }
-            }
-
-            /* Send update */
-            for (i = 0; i < MAX_MODE_LF_DELTAS; i++)
-            {
-                if (vp8_read_bit(bc))
-                {
-                    /*sign = vp8_read_bit( bc );*/
-                    xd->mode_lf_deltas[i] = (signed char)vp8_read_literal(bc, 6);
-
-                    if (vp8_read_bit(bc))        /* Apply sign */
-                        xd->mode_lf_deltas[i] = xd->mode_lf_deltas[i] * -1;
-                }
-            }
-        }
-    }
-
-    setup_token_decoder(pbi, data + first_partition_length_in_bytes);
-
-    xd->current_bc = &pbi->mbc[0];
-
-    /* Read the default quantizers. */
-    {
-        int Q, q_update;
-
-        Q = vp8_read_literal(bc, 7);  /* AC 1st order Q = default */
-        pc->base_qindex = Q;
-        q_update = 0;
-        pc->y1dc_delta_q = get_delta_q(bc, pc->y1dc_delta_q, &q_update);
-        pc->y2dc_delta_q = get_delta_q(bc, pc->y2dc_delta_q, &q_update);
-        pc->y2ac_delta_q = get_delta_q(bc, pc->y2ac_delta_q, &q_update);
-        pc->uvdc_delta_q = get_delta_q(bc, pc->uvdc_delta_q, &q_update);
-        pc->uvac_delta_q = get_delta_q(bc, pc->uvac_delta_q, &q_update);
-
-        if (q_update)
-            vp8cx_init_de_quantizer(pbi);
-
-        /* MB level dequantizer setup */
-        vp8_mb_init_dequantizer(pbi, &pbi->mb);
-    }
-
-    /* Determine if the golden frame or ARF buffer should be updated and how.
-     * For all non key frames the GF and ARF refresh flags and sign bias
-     * flags must be set explicitly.
-     */
-    if (pc->frame_type != KEY_FRAME)
-    {
-        /* Should the GF or ARF be updated from the current frame */
-        pc->refresh_golden_frame = vp8_read_bit(bc);
-#if CONFIG_ERROR_CONCEALMENT
-        /* Assume we shouldn't refresh golden if the bit is missing */
-        xd->corrupted |= vp8dx_bool_error(bc);
-        if (pbi->ec_active && xd->corrupted)
-            pc->refresh_golden_frame = 0;
-#endif
-
-        pc->refresh_alt_ref_frame = vp8_read_bit(bc);
-#if CONFIG_ERROR_CONCEALMENT
-        /* Assume we shouldn't refresh altref if the bit is missing */
-        xd->corrupted |= vp8dx_bool_error(bc);
-        if (pbi->ec_active && xd->corrupted)
-            pc->refresh_alt_ref_frame = 0;
-#endif
-
-        /* Buffer to buffer copy flags. */
-        pc->copy_buffer_to_gf = 0;
-
-        if (!pc->refresh_golden_frame)
-            pc->copy_buffer_to_gf = vp8_read_literal(bc, 2);
-
-#if CONFIG_ERROR_CONCEALMENT
-        /* Assume we shouldn't copy to the golden if the bit is missing */
-        xd->corrupted |= vp8dx_bool_error(bc);
-        if (pbi->ec_active && xd->corrupted)
-            pc->copy_buffer_to_gf = 0;
-#endif
-
-        pc->copy_buffer_to_arf = 0;
-
-        if (!pc->refresh_alt_ref_frame)
-            pc->copy_buffer_to_arf = vp8_read_literal(bc, 2);
-
-#if CONFIG_ERROR_CONCEALMENT
-        /* Assume we shouldn't copy to the alt-ref if the bit is missing */
-        xd->corrupted |= vp8dx_bool_error(bc);
-        if (pbi->ec_active && xd->corrupted)
-            pc->copy_buffer_to_arf = 0;
-#endif
-
-
-        pc->ref_frame_sign_bias[GOLDEN_FRAME] = vp8_read_bit(bc);
-        pc->ref_frame_sign_bias[ALTREF_FRAME] = vp8_read_bit(bc);
-    }
-
-    pc->refresh_entropy_probs = vp8_read_bit(bc);
-#if CONFIG_ERROR_CONCEALMENT
-    /* Assume we shouldn't refresh the probabilities if the bit is
-     * missing */
-    xd->corrupted |= vp8dx_bool_error(bc);
-    if (pbi->ec_active && xd->corrupted)
-        pc->refresh_entropy_probs = 0;
-#endif
-    if (pc->refresh_entropy_probs == 0)
-    {
-        memcpy(&pc->lfc, &pc->fc, sizeof(pc->fc));
-    }
-
-    pc->refresh_last_frame = pc->frame_type == KEY_FRAME  ||  vp8_read_bit(bc);
-
-#if CONFIG_ERROR_CONCEALMENT
-    /* Assume we should refresh the last frame if the bit is missing */
-    xd->corrupted |= vp8dx_bool_error(bc);
-    if (pbi->ec_active && xd->corrupted)
-        pc->refresh_last_frame = 1;
-#endif
-
-    if (0)
-    {
-        FILE *z = fopen("decodestats.stt", "a");
-        fprintf(z, "%6d F:%d,G:%d,A:%d,L:%d,Q:%d\n",
-                pc->current_video_frame,
-                pc->frame_type,
-                pc->refresh_golden_frame,
-                pc->refresh_alt_ref_frame,
-                pc->refresh_last_frame,
-                pc->base_qindex);
-        fclose(z);
-    }
-
-    {
-        pbi->independent_partitions = 1;
-
-        /* read coef probability tree */
-        for (i = 0; i < BLOCK_TYPES; i++)
-            for (j = 0; j < COEF_BANDS; j++)
-                for (k = 0; k < PREV_COEF_CONTEXTS; k++)
-                    for (l = 0; l < ENTROPY_NODES; l++)
-                    {
-
-                        vp8_prob *const p = pc->fc.coef_probs [i][j][k] + l;
-
-                        if (vp8_read(bc, vp8_coef_update_probs [i][j][k][l]))
-                        {
-                            *p = (vp8_prob)vp8_read_literal(bc, 8);
-
-                        }
-                        if (k > 0 && *p != pc->fc.coef_probs[i][j][k-1][l])
-                            pbi->independent_partitions = 0;
-
-                    }
-    }
-
-    /* clear out the coeff buffer */
-    memset(xd->qcoeff, 0, sizeof(xd->qcoeff));
-
-    vp8_decode_mode_mvs(pbi);
-
-#if CONFIG_ERROR_CONCEALMENT
-    if (pbi->ec_active &&
-            pbi->mvs_corrupt_from_mb < (unsigned int)pc->mb_cols * pc->mb_rows)
-    {
-        /* Motion vectors are missing in this frame. We will try to estimate
-         * them and then continue decoding the frame as usual */
-        vp8_estimate_missing_mvs(pbi);
-    }
-#endif
-
-    memset(pc->above_context, 0, sizeof(ENTROPY_CONTEXT_PLANES) * pc->mb_cols);
-    pbi->frame_corrupt_residual = 0;
-
-#if CONFIG_MULTITHREAD
-    if (pbi->b_multithreaded_rd && pc->multi_token_partition != ONE_PARTITION)
-    {
-        unsigned int thread;
-        vp8mt_decode_mb_rows(pbi, xd);
-        vp8_yv12_extend_frame_borders(yv12_fb_new);
-        for (thread = 0; thread < pbi->decoding_thread_count; ++thread)
-            corrupt_tokens |= pbi->mb_row_di[thread].mbd.corrupted;
-    }
-    else
-#endif
-    {
-        decode_mb_rows(pbi);
-        corrupt_tokens |= xd->corrupted;
-    }
-
-    /* Collect information about decoder corruption. */
-    /* 1. Check first boolean decoder for errors. */
-    yv12_fb_new->corrupted = vp8dx_bool_error(bc);
-    /* 2. Check the macroblock information */
-    yv12_fb_new->corrupted |= corrupt_tokens;
-
-    if (!pbi->decoded_key_frame)
-    {
-        if (pc->frame_type == KEY_FRAME &&
-            !yv12_fb_new->corrupted)
-            pbi->decoded_key_frame = 1;
-        else
-            vpx_internal_error(&pbi->common.error, VPX_CODEC_CORRUPT_FRAME,
-                               "A stream must start with a complete key frame");
-    }
-
-    /* vpx_log("Decoder: Frame Decoded, Size Roughly:%d bytes  \n",bc->pos+pbi->bc2.pos); */
-
-    if (pc->refresh_entropy_probs == 0)
-    {
-        memcpy(&pc->fc, &pc->lfc, sizeof(pc->fc));
-        pbi->independent_partitions = prev_independent_partitions;
-    }
-
-#ifdef PACKET_TESTING
-    {
-        FILE *f = fopen("decompressor.VP8", "ab");
-        unsigned int size = pbi->bc2.pos + pbi->bc.pos + 8;
-        fwrite((void *) &size, 4, 1, f);
-        fwrite((void *) pbi->Source, size, 1, f);
-        fclose(f);
-    }
-#endif
-
-    return 0;
-}
diff --git a/vp8/decoder/decodemv.c b/vp8/decoder/decodemv.c
deleted file mode 100644 (file)
index 1d155e7..0000000
+++ /dev/null
@@ -1,670 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#include "treereader.h"
-#include "vp8/common/entropymv.h"
-#include "vp8/common/entropymode.h"
-#include "onyxd_int.h"
-#include "vp8/common/findnearmv.h"
-
-#if CONFIG_DEBUG
-#include <assert.h>
-#endif
-static B_PREDICTION_MODE read_bmode(vp8_reader *bc, const vp8_prob *p)
-{
-    const int i = vp8_treed_read(bc, vp8_bmode_tree, p);
-
-    return (B_PREDICTION_MODE)i;
-}
-
-static MB_PREDICTION_MODE read_ymode(vp8_reader *bc, const vp8_prob *p)
-{
-    const int i = vp8_treed_read(bc, vp8_ymode_tree, p);
-
-    return (MB_PREDICTION_MODE)i;
-}
-
-static MB_PREDICTION_MODE read_kf_ymode(vp8_reader *bc, const vp8_prob *p)
-{
-    const int i = vp8_treed_read(bc, vp8_kf_ymode_tree, p);
-
-    return (MB_PREDICTION_MODE)i;
-}
-
-static MB_PREDICTION_MODE read_uv_mode(vp8_reader *bc, const vp8_prob *p)
-{
-    const int i = vp8_treed_read(bc, vp8_uv_mode_tree, p);
-
-    return (MB_PREDICTION_MODE)i;
-}
-
-static void read_kf_modes(VP8D_COMP *pbi, MODE_INFO *mi)
-{
-    vp8_reader *const bc = & pbi->mbc[8];
-    const int mis = pbi->common.mode_info_stride;
-
-    mi->mbmi.ref_frame = INTRA_FRAME;
-    mi->mbmi.mode = read_kf_ymode(bc, vp8_kf_ymode_prob);
-
-    if (mi->mbmi.mode == B_PRED)
-    {
-        int i = 0;
-        mi->mbmi.is_4x4 = 1;
-
-        do
-        {
-            const B_PREDICTION_MODE A = above_block_mode(mi, i, mis);
-            const B_PREDICTION_MODE L = left_block_mode(mi, i);
-
-            mi->bmi[i].as_mode =
-                read_bmode(bc, vp8_kf_bmode_prob [A] [L]);
-        }
-        while (++i < 16);
-    }
-
-    mi->mbmi.uv_mode = read_uv_mode(bc, vp8_kf_uv_mode_prob);
-}
-
-static int read_mvcomponent(vp8_reader *r, const MV_CONTEXT *mvc)
-{
-    const vp8_prob *const p = (const vp8_prob *) mvc;
-    int x = 0;
-
-    if (vp8_read(r, p [mvpis_short]))  /* Large */
-    {
-        int i = 0;
-
-        do
-        {
-            x += vp8_read(r, p [MVPbits + i]) << i;
-        }
-        while (++i < 3);
-
-        i = mvlong_width - 1;  /* Skip bit 3, which is sometimes implicit */
-
-        do
-        {
-            x += vp8_read(r, p [MVPbits + i]) << i;
-        }
-        while (--i > 3);
-
-        if (!(x & 0xFFF0)  ||  vp8_read(r, p [MVPbits + 3]))
-            x += 8;
-    }
-    else   /* small */
-        x = vp8_treed_read(r, vp8_small_mvtree, p + MVPshort);
-
-    if (x  &&  vp8_read(r, p [MVPsign]))
-        x = -x;
-
-    return x;
-}
-
-static void read_mv(vp8_reader *r, MV *mv, const MV_CONTEXT *mvc)
-{
-    mv->row = (short)(read_mvcomponent(r,   mvc) * 2);
-    mv->col = (short)(read_mvcomponent(r, ++mvc) * 2);
-}
-
-
-static void read_mvcontexts(vp8_reader *bc, MV_CONTEXT *mvc)
-{
-    int i = 0;
-
-    do
-    {
-        const vp8_prob *up = vp8_mv_update_probs[i].prob;
-        vp8_prob *p = (vp8_prob *)(mvc + i);
-        vp8_prob *const pstop = p + MVPcount;
-
-        do
-        {
-            if (vp8_read(bc, *up++))
-            {
-                const vp8_prob x = (vp8_prob)vp8_read_literal(bc, 7);
-
-                *p = x ? x << 1 : 1;
-            }
-        }
-        while (++p < pstop);
-    }
-    while (++i < 2);
-}
-
-static const unsigned char mbsplit_fill_count[4] = {8, 8, 4, 1};
-static const unsigned char mbsplit_fill_offset[4][16] = {
-    { 0,  1,  2,  3,  4,  5,  6,  7,  8,  9,  10, 11, 12, 13, 14, 15},
-    { 0,  1,  4,  5,  8,  9, 12, 13,  2,  3,   6,  7, 10, 11, 14, 15},
-    { 0,  1,  4,  5,  2,  3,  6,  7,  8,  9,  12, 13, 10, 11, 14, 15},
-    { 0,  1,  2,  3,  4,  5,  6,  7,  8,  9,  10, 11, 12, 13, 14, 15}
-};
-
-
-static void mb_mode_mv_init(VP8D_COMP *pbi)
-{
-    vp8_reader *const bc = & pbi->mbc[8];
-    MV_CONTEXT *const mvc = pbi->common.fc.mvc;
-
-#if CONFIG_ERROR_CONCEALMENT
-    /* Default is that no macroblock is corrupt, therefore we initialize
-     * mvs_corrupt_from_mb to something very big, which we can be sure is
-     * outside the frame. */
-    pbi->mvs_corrupt_from_mb = UINT_MAX;
-#endif
-    /* Read the mb_no_coeff_skip flag */
-    pbi->common.mb_no_coeff_skip = (int)vp8_read_bit(bc);
-
-    pbi->prob_skip_false = 0;
-    if (pbi->common.mb_no_coeff_skip)
-        pbi->prob_skip_false = (vp8_prob)vp8_read_literal(bc, 8);
-
-    if(pbi->common.frame_type != KEY_FRAME)
-    {
-        pbi->prob_intra = (vp8_prob)vp8_read_literal(bc, 8);
-        pbi->prob_last  = (vp8_prob)vp8_read_literal(bc, 8);
-        pbi->prob_gf    = (vp8_prob)vp8_read_literal(bc, 8);
-
-        if (vp8_read_bit(bc))
-        {
-            int i = 0;
-
-            do
-            {
-                pbi->common.fc.ymode_prob[i] =
-                    (vp8_prob) vp8_read_literal(bc, 8);
-            }
-            while (++i < 4);
-        }
-
-        if (vp8_read_bit(bc))
-        {
-            int i = 0;
-
-            do
-            {
-                pbi->common.fc.uv_mode_prob[i] =
-                    (vp8_prob) vp8_read_literal(bc, 8);
-            }
-            while (++i < 3);
-        }
-
-        read_mvcontexts(bc, mvc);
-    }
-}
-
-const vp8_prob vp8_sub_mv_ref_prob3 [8][VP8_SUBMVREFS-1] =
-{
-    { 147, 136, 18 },   /* SUBMVREF_NORMAL          */
-    { 223, 1  , 34 },   /* SUBMVREF_LEFT_ABOVE_SAME */
-    { 106, 145, 1  },   /* SUBMVREF_LEFT_ZED        */
-    { 208, 1  , 1  },   /* SUBMVREF_LEFT_ABOVE_ZED  */
-    { 179, 121, 1  },   /* SUBMVREF_ABOVE_ZED       */
-    { 223, 1  , 34 },   /* SUBMVREF_LEFT_ABOVE_SAME */
-    { 179, 121, 1  },   /* SUBMVREF_ABOVE_ZED       */
-    { 208, 1  , 1  }    /* SUBMVREF_LEFT_ABOVE_ZED  */
-};
-
-static
-const vp8_prob * get_sub_mv_ref_prob(const int left, const int above)
-{
-    int lez = (left == 0);
-    int aez = (above == 0);
-    int lea = (left == above);
-    const vp8_prob * prob;
-
-    prob = vp8_sub_mv_ref_prob3[(aez << 2) |
-                                (lez << 1) |
-                                (lea)];
-
-    return prob;
-}
-
-static void decode_split_mv(vp8_reader *const bc, MODE_INFO *mi,
-                        const MODE_INFO *left_mb, const MODE_INFO *above_mb,
-                        MB_MODE_INFO *mbmi, int_mv best_mv,
-                        MV_CONTEXT *const mvc, int mb_to_left_edge,
-                        int mb_to_right_edge, int mb_to_top_edge,
-                        int mb_to_bottom_edge)
-{
-    int s;      /* split configuration (16x8, 8x16, 8x8, 4x4) */
-    int num_p;  /* number of partitions in the split configuration
-                  (see vp8_mbsplit_count) */
-    int j = 0;
-
-    s = 3;
-    num_p = 16;
-    if( vp8_read(bc, 110) )
-    {
-        s = 2;
-        num_p = 4;
-        if( vp8_read(bc, 111) )
-        {
-            s = vp8_read(bc, 150);
-            num_p = 2;
-        }
-    }
-
-    do  /* for each subset j */
-    {
-        int_mv leftmv, abovemv;
-        int_mv blockmv;
-        int k;  /* first block in subset j */
-
-        const vp8_prob *prob;
-        k = vp8_mbsplit_offset[s][j];
-
-        if (!(k & 3))
-        {
-            /* On L edge, get from MB to left of us */
-            if(left_mb->mbmi.mode != SPLITMV)
-                leftmv.as_int =  left_mb->mbmi.mv.as_int;
-            else
-                leftmv.as_int =  (left_mb->bmi + k + 4 - 1)->mv.as_int;
-        }
-        else
-            leftmv.as_int =  (mi->bmi + k - 1)->mv.as_int;
-
-        if (!(k >> 2))
-        {
-            /* On top edge, get from MB above us */
-            if(above_mb->mbmi.mode != SPLITMV)
-                abovemv.as_int =  above_mb->mbmi.mv.as_int;
-            else
-                abovemv.as_int =  (above_mb->bmi + k + 16 - 4)->mv.as_int;
-        }
-        else
-            abovemv.as_int = (mi->bmi + k - 4)->mv.as_int;
-
-        prob = get_sub_mv_ref_prob(leftmv.as_int, abovemv.as_int);
-
-        if( vp8_read(bc, prob[0]) )
-        {
-            if( vp8_read(bc, prob[1]) )
-            {
-                blockmv.as_int = 0;
-                if( vp8_read(bc, prob[2]) )
-                {
-                    blockmv.as_mv.row = read_mvcomponent(bc, &mvc[0]) * 2;
-                    blockmv.as_mv.row += best_mv.as_mv.row;
-                    blockmv.as_mv.col = read_mvcomponent(bc, &mvc[1]) * 2;
-                    blockmv.as_mv.col += best_mv.as_mv.col;
-                }
-            }
-            else
-            {
-                blockmv.as_int = abovemv.as_int;
-            }
-        }
-        else
-        {
-            blockmv.as_int = leftmv.as_int;
-        }
-
-        mbmi->need_to_clamp_mvs |= vp8_check_mv_bounds(&blockmv,
-                                                  mb_to_left_edge,
-                                                  mb_to_right_edge,
-                                                  mb_to_top_edge,
-                                                  mb_to_bottom_edge);
-
-        {
-            /* Fill (uniform) modes, mvs of jth subset.
-             Must do it here because ensuing subsets can
-             refer back to us via "left" or "above". */
-            const unsigned char *fill_offset;
-            unsigned int fill_count = mbsplit_fill_count[s];
-
-            fill_offset = &mbsplit_fill_offset[s]
-                             [(unsigned char)j * mbsplit_fill_count[s]];
-
-            do {
-                mi->bmi[ *fill_offset].mv.as_int = blockmv.as_int;
-                fill_offset++;
-            }while (--fill_count);
-        }
-
-    }
-    while (++j < num_p);
-
-    mbmi->partitioning = s;
-}
-
-static void read_mb_modes_mv(VP8D_COMP *pbi, MODE_INFO *mi, MB_MODE_INFO *mbmi)
-{
-    vp8_reader *const bc = & pbi->mbc[8];
-    mbmi->ref_frame = (MV_REFERENCE_FRAME) vp8_read(bc, pbi->prob_intra);
-    if (mbmi->ref_frame)    /* inter MB */
-    {
-        enum {CNT_INTRA, CNT_NEAREST, CNT_NEAR, CNT_SPLITMV};
-        int cnt[4];
-        int *cntx = cnt;
-        int_mv near_mvs[4];
-        int_mv *nmv = near_mvs;
-        const int mis = pbi->mb.mode_info_stride;
-        const MODE_INFO *above = mi - mis;
-        const MODE_INFO *left = mi - 1;
-        const MODE_INFO *aboveleft = above - 1;
-        int *ref_frame_sign_bias = pbi->common.ref_frame_sign_bias;
-
-        mbmi->need_to_clamp_mvs = 0;
-
-        if (vp8_read(bc, pbi->prob_last))
-        {
-            mbmi->ref_frame =
-                (MV_REFERENCE_FRAME)((int)(2 + vp8_read(bc, pbi->prob_gf)));
-        }
-
-        /* Zero accumulators */
-        nmv[0].as_int = nmv[1].as_int = nmv[2].as_int = 0;
-        cnt[0] = cnt[1] = cnt[2] = cnt[3] = 0;
-
-        /* Process above */
-        if (above->mbmi.ref_frame != INTRA_FRAME)
-        {
-            if (above->mbmi.mv.as_int)
-            {
-                (++nmv)->as_int = above->mbmi.mv.as_int;
-                mv_bias(ref_frame_sign_bias[above->mbmi.ref_frame],
-                        mbmi->ref_frame, nmv, ref_frame_sign_bias);
-                ++cntx;
-            }
-
-            *cntx += 2;
-        }
-
-        /* Process left */
-        if (left->mbmi.ref_frame != INTRA_FRAME)
-        {
-            if (left->mbmi.mv.as_int)
-            {
-                int_mv this_mv;
-
-                this_mv.as_int = left->mbmi.mv.as_int;
-                mv_bias(ref_frame_sign_bias[left->mbmi.ref_frame],
-                        mbmi->ref_frame, &this_mv, ref_frame_sign_bias);
-
-                if (this_mv.as_int != nmv->as_int)
-                {
-                    (++nmv)->as_int = this_mv.as_int;
-                    ++cntx;
-                }
-
-                *cntx += 2;
-            }
-            else
-                cnt[CNT_INTRA] += 2;
-        }
-
-        /* Process above left */
-        if (aboveleft->mbmi.ref_frame != INTRA_FRAME)
-        {
-            if (aboveleft->mbmi.mv.as_int)
-            {
-                int_mv this_mv;
-
-                this_mv.as_int = aboveleft->mbmi.mv.as_int;
-                mv_bias(ref_frame_sign_bias[aboveleft->mbmi.ref_frame],
-                        mbmi->ref_frame, &this_mv, ref_frame_sign_bias);
-
-                if (this_mv.as_int != nmv->as_int)
-                {
-                    (++nmv)->as_int = this_mv.as_int;
-                    ++cntx;
-                }
-
-                *cntx += 1;
-            }
-            else
-                cnt[CNT_INTRA] += 1;
-        }
-
-        if( vp8_read(bc, vp8_mode_contexts [cnt[CNT_INTRA]] [0]) )
-        {
-
-            /* If we have three distinct MV's ... */
-            /* See if above-left MV can be merged with NEAREST */
-            cnt[CNT_NEAREST] += ( (cnt[CNT_SPLITMV] > 0) &
-                (nmv->as_int == near_mvs[CNT_NEAREST].as_int));
-
-            /* Swap near and nearest if necessary */
-            if (cnt[CNT_NEAR] > cnt[CNT_NEAREST])
-            {
-                int tmp;
-                tmp = cnt[CNT_NEAREST];
-                cnt[CNT_NEAREST] = cnt[CNT_NEAR];
-                cnt[CNT_NEAR] = tmp;
-                tmp = near_mvs[CNT_NEAREST].as_int;
-                near_mvs[CNT_NEAREST].as_int = near_mvs[CNT_NEAR].as_int;
-                near_mvs[CNT_NEAR].as_int = tmp;
-            }
-
-            if( vp8_read(bc, vp8_mode_contexts [cnt[CNT_NEAREST]] [1]) )
-            {
-
-                if( vp8_read(bc, vp8_mode_contexts [cnt[CNT_NEAR]] [2]) )
-                {
-                    int mb_to_top_edge;
-                    int mb_to_bottom_edge;
-                    int mb_to_left_edge;
-                    int mb_to_right_edge;
-                    MV_CONTEXT *const mvc = pbi->common.fc.mvc;
-                    int near_index;
-
-                    mb_to_top_edge = pbi->mb.mb_to_top_edge;
-                    mb_to_bottom_edge = pbi->mb.mb_to_bottom_edge;
-                    mb_to_top_edge -= LEFT_TOP_MARGIN;
-                    mb_to_bottom_edge += RIGHT_BOTTOM_MARGIN;
-                    mb_to_right_edge = pbi->mb.mb_to_right_edge;
-                    mb_to_right_edge += RIGHT_BOTTOM_MARGIN;
-                    mb_to_left_edge = pbi->mb.mb_to_left_edge;
-                    mb_to_left_edge -= LEFT_TOP_MARGIN;
-
-                    /* Use near_mvs[0] to store the "best" MV */
-                    near_index = CNT_INTRA +
-                        (cnt[CNT_NEAREST] >= cnt[CNT_INTRA]);
-
-                    vp8_clamp_mv2(&near_mvs[near_index], &pbi->mb);
-
-                    cnt[CNT_SPLITMV] = ((above->mbmi.mode == SPLITMV)
-                                        + (left->mbmi.mode == SPLITMV)) * 2
-                                       + (aboveleft->mbmi.mode == SPLITMV);
-
-                    if( vp8_read(bc, vp8_mode_contexts [cnt[CNT_SPLITMV]] [3]) )
-                    {
-                        decode_split_mv(bc, mi, left, above,
-                                                    mbmi,
-                                                    near_mvs[near_index],
-                                                    mvc, mb_to_left_edge,
-                                                    mb_to_right_edge,
-                                                    mb_to_top_edge,
-                                                    mb_to_bottom_edge);
-                        mbmi->mv.as_int = mi->bmi[15].mv.as_int;
-                        mbmi->mode =  SPLITMV;
-                        mbmi->is_4x4 = 1;
-                    }
-                    else
-                    {
-                        int_mv *const mbmi_mv = & mbmi->mv;
-                        read_mv(bc, &mbmi_mv->as_mv, (const MV_CONTEXT *) mvc);
-                        mbmi_mv->as_mv.row += near_mvs[near_index].as_mv.row;
-                        mbmi_mv->as_mv.col += near_mvs[near_index].as_mv.col;
-
-                        /* Don't need to check this on NEARMV and NEARESTMV
-                         * modes since those modes clamp the MV. The NEWMV mode
-                         * does not, so signal to the prediction stage whether
-                         * special handling may be required.
-                         */
-                        mbmi->need_to_clamp_mvs =
-                            vp8_check_mv_bounds(mbmi_mv, mb_to_left_edge,
-                                                mb_to_right_edge,
-                                                mb_to_top_edge,
-                                                mb_to_bottom_edge);
-                        mbmi->mode =  NEWMV;
-                    }
-                }
-                else
-                {
-                    mbmi->mode =  NEARMV;
-                    mbmi->mv.as_int = near_mvs[CNT_NEAR].as_int;
-                    vp8_clamp_mv2(&mbmi->mv, &pbi->mb);
-                }
-            }
-            else
-            {
-                mbmi->mode =  NEARESTMV;
-                mbmi->mv.as_int = near_mvs[CNT_NEAREST].as_int;
-                vp8_clamp_mv2(&mbmi->mv, &pbi->mb);
-            }
-        }
-        else
-        {
-            mbmi->mode =  ZEROMV;
-            mbmi->mv.as_int = 0;
-        }
-
-#if CONFIG_ERROR_CONCEALMENT
-        if(pbi->ec_enabled && (mbmi->mode != SPLITMV))
-        {
-            mi->bmi[ 0].mv.as_int =
-            mi->bmi[ 1].mv.as_int =
-            mi->bmi[ 2].mv.as_int =
-            mi->bmi[ 3].mv.as_int =
-            mi->bmi[ 4].mv.as_int =
-            mi->bmi[ 5].mv.as_int =
-            mi->bmi[ 6].mv.as_int =
-            mi->bmi[ 7].mv.as_int =
-            mi->bmi[ 8].mv.as_int =
-            mi->bmi[ 9].mv.as_int =
-            mi->bmi[10].mv.as_int =
-            mi->bmi[11].mv.as_int =
-            mi->bmi[12].mv.as_int =
-            mi->bmi[13].mv.as_int =
-            mi->bmi[14].mv.as_int =
-            mi->bmi[15].mv.as_int = mbmi->mv.as_int;
-        }
-#endif
-    }
-    else
-    {
-        /* required for left and above block mv */
-        mbmi->mv.as_int = 0;
-
-        /* MB is intra coded */
-        if ((mbmi->mode = read_ymode(bc, pbi->common.fc.ymode_prob)) == B_PRED)
-        {
-            int j = 0;
-            mbmi->is_4x4 = 1;
-            do
-            {
-                mi->bmi[j].as_mode = read_bmode(bc, pbi->common.fc.bmode_prob);
-            }
-            while (++j < 16);
-        }
-
-        mbmi->uv_mode = read_uv_mode(bc, pbi->common.fc.uv_mode_prob);
-    }
-
-}
-
-static void read_mb_features(vp8_reader *r, MB_MODE_INFO *mi, MACROBLOCKD *x)
-{
-    /* Is segmentation enabled */
-    if (x->segmentation_enabled && x->update_mb_segmentation_map)
-    {
-        /* If so then read the segment id. */
-        if (vp8_read(r, x->mb_segment_tree_probs[0]))
-            mi->segment_id =
-                (unsigned char)(2 + vp8_read(r, x->mb_segment_tree_probs[2]));
-        else
-            mi->segment_id =
-                (unsigned char)(vp8_read(r, x->mb_segment_tree_probs[1]));
-    }
-}
-
-static void decode_mb_mode_mvs(VP8D_COMP *pbi, MODE_INFO *mi,
-                               MB_MODE_INFO *mbmi)
-{
-    (void)mbmi;
-
-    /* Read the Macroblock segmentation map if it is being updated explicitly
-     * this frame (reset to 0 above by default)
-     * By default on a key frame reset all MBs to segment 0
-     */
-    if (pbi->mb.update_mb_segmentation_map)
-        read_mb_features(&pbi->mbc[8], &mi->mbmi, &pbi->mb);
-    else if(pbi->common.frame_type == KEY_FRAME)
-        mi->mbmi.segment_id = 0;
-
-    /* Read the macroblock coeff skip flag if this feature is in use,
-     * else default to 0 */
-    if (pbi->common.mb_no_coeff_skip)
-        mi->mbmi.mb_skip_coeff = vp8_read(&pbi->mbc[8], pbi->prob_skip_false);
-    else
-        mi->mbmi.mb_skip_coeff = 0;
-
-    mi->mbmi.is_4x4 = 0;
-    if(pbi->common.frame_type == KEY_FRAME)
-        read_kf_modes(pbi, mi);
-    else
-        read_mb_modes_mv(pbi, mi, &mi->mbmi);
-
-}
-
-void vp8_decode_mode_mvs(VP8D_COMP *pbi)
-{
-    MODE_INFO *mi = pbi->common.mi;
-    int mb_row = -1;
-    int mb_to_right_edge_start;
-
-    mb_mode_mv_init(pbi);
-
-    pbi->mb.mb_to_top_edge = 0;
-    pbi->mb.mb_to_bottom_edge = ((pbi->common.mb_rows - 1) * 16) << 3;
-    mb_to_right_edge_start = ((pbi->common.mb_cols - 1) * 16) << 3;
-
-    while (++mb_row < pbi->common.mb_rows)
-    {
-        int mb_col = -1;
-
-        pbi->mb.mb_to_left_edge =  0;
-        pbi->mb.mb_to_right_edge = mb_to_right_edge_start;
-
-        while (++mb_col < pbi->common.mb_cols)
-        {
-#if CONFIG_ERROR_CONCEALMENT
-            int mb_num = mb_row * pbi->common.mb_cols + mb_col;
-#endif
-
-            decode_mb_mode_mvs(pbi, mi, &mi->mbmi);
-
-#if CONFIG_ERROR_CONCEALMENT
-            /* look for corruption. set mvs_corrupt_from_mb to the current
-             * mb_num if the frame is corrupt from this macroblock. */
-            if (vp8dx_bool_error(&pbi->mbc[8]) && mb_num <
-                (int)pbi->mvs_corrupt_from_mb)
-            {
-                pbi->mvs_corrupt_from_mb = mb_num;
-                /* no need to continue since the partition is corrupt from
-                 * here on.
-                 */
-                return;
-            }
-#endif
-
-            pbi->mb.mb_to_left_edge -= (16 << 3);
-            pbi->mb.mb_to_right_edge -= (16 << 3);
-            mi++;       /* next macroblock */
-        }
-        pbi->mb.mb_to_top_edge -= (16 << 3);
-        pbi->mb.mb_to_bottom_edge -= (16 << 3);
-
-        mi++;           /* skip left predictor each row */
-    }
-}
diff --git a/vp8/decoder/decodemv.h b/vp8/decoder/decodemv.h
deleted file mode 100644 (file)
index f33b073..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#ifndef VP8_DECODER_DECODEMV_H_
-#define VP8_DECODER_DECODEMV_H_
-
-#include "onyxd_int.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-void vp8_decode_mode_mvs(VP8D_COMP *);
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP8_DECODER_DECODEMV_H_
diff --git a/vp8/decoder/decoderthreading.h b/vp8/decoder/decoderthreading.h
deleted file mode 100644 (file)
index c563cf6..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#ifndef VP8_DECODER_DECODERTHREADING_H_
-#define VP8_DECODER_DECODERTHREADING_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#if CONFIG_MULTITHREAD
-void vp8mt_decode_mb_rows(VP8D_COMP *pbi, MACROBLOCKD *xd);
-void vp8_decoder_remove_threads(VP8D_COMP *pbi);
-void vp8_decoder_create_threads(VP8D_COMP *pbi);
-void vp8mt_alloc_temp_buffers(VP8D_COMP *pbi, int width, int prev_mb_rows);
-void vp8mt_de_alloc_temp_buffers(VP8D_COMP *pbi, int mb_rows);
-#endif
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP8_DECODER_DECODERTHREADING_H_
diff --git a/vp8/decoder/detokenize.c b/vp8/decoder/detokenize.c
deleted file mode 100644 (file)
index fcc7533..0000000
+++ /dev/null
@@ -1,245 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#include "vp8/common/blockd.h"
-#include "onyxd_int.h"
-#include "vpx_mem/vpx_mem.h"
-#include "vpx_ports/mem.h"
-#include "detokenize.h"
-
-void vp8_reset_mb_tokens_context(MACROBLOCKD *x)
-{
-    ENTROPY_CONTEXT *a_ctx = ((ENTROPY_CONTEXT *)x->above_context);
-    ENTROPY_CONTEXT *l_ctx = ((ENTROPY_CONTEXT *)x->left_context);
-
-    memset(a_ctx, 0, sizeof(ENTROPY_CONTEXT_PLANES)-1);
-    memset(l_ctx, 0, sizeof(ENTROPY_CONTEXT_PLANES)-1);
-
-    /* Clear entropy contexts for Y2 blocks */
-    if (!x->mode_info_context->mbmi.is_4x4)
-    {
-        a_ctx[8] = l_ctx[8] = 0;
-    }
-}
-
-/*
-    ------------------------------------------------------------------------------
-    Residual decoding (Paragraph 13.2 / 13.3)
-*/
-static const uint8_t kBands[16 + 1] = {
-  0, 1, 2, 3, 6, 4, 5, 6, 6, 6, 6, 6, 6, 6, 6, 7,
-  0  /* extra entry as sentinel */
-};
-
-static const uint8_t kCat3[] = { 173, 148, 140, 0 };
-static const uint8_t kCat4[] = { 176, 155, 140, 135, 0 };
-static const uint8_t kCat5[] = { 180, 157, 141, 134, 130, 0 };
-static const uint8_t kCat6[] =
-  { 254, 254, 243, 230, 196, 177, 153, 140, 133, 130, 129, 0 };
-static const uint8_t* const kCat3456[] = { kCat3, kCat4, kCat5, kCat6 };
-static const uint8_t kZigzag[16] = {
-  0, 1, 4, 8,  5, 2, 3, 6,  9, 12, 13, 10,  7, 11, 14, 15
-};
-
-#define VP8GetBit vp8dx_decode_bool
-#define NUM_PROBAS  11
-#define NUM_CTX  3
-
-/* for const-casting */
-typedef const uint8_t (*ProbaArray)[NUM_CTX][NUM_PROBAS];
-
-static int GetSigned(BOOL_DECODER *br, int value_to_sign)
-{
-    int split = (br->range + 1) >> 1;
-    VP8_BD_VALUE bigsplit = (VP8_BD_VALUE)split << (VP8_BD_VALUE_SIZE - 8);
-    int v;
-
-    if(br->count < 0)
-        vp8dx_bool_decoder_fill(br);
-
-    if ( br->value < bigsplit )
-    {
-        br->range = split;
-        v= value_to_sign;
-    }
-    else
-    {
-        br->range = br->range-split;
-        br->value = br->value-bigsplit;
-        v = -value_to_sign;
-    }
-    br->range +=br->range;
-    br->value +=br->value;
-    br->count--;
-
-    return v;
-}
-/*
-   Returns the position of the last non-zero coeff plus one
-   (and 0 if there's no coeff at all)
-*/
-static int GetCoeffs(BOOL_DECODER *br, ProbaArray prob,
-                     int ctx, int n, int16_t* out)
-{
-    const uint8_t* p = prob[n][ctx];
-    if (!VP8GetBit(br, p[0]))
-    {   /* first EOB is more a 'CBP' bit. */
-        return 0;
-    }
-    while (1)
-    {
-        ++n;
-        if (!VP8GetBit(br, p[1]))
-        {
-            p = prob[kBands[n]][0];
-        }
-        else
-        {  /* non zero coeff */
-            int v, j;
-            if (!VP8GetBit(br, p[2]))
-            {
-                p = prob[kBands[n]][1];
-                v = 1;
-            }
-            else
-            {
-                if (!VP8GetBit(br, p[3]))
-                {
-                    if (!VP8GetBit(br, p[4]))
-                    {
-                        v = 2;
-                    }
-                    else
-                    {
-                        v = 3 + VP8GetBit(br, p[5]);
-                    }
-                }
-                else
-                {
-                    if (!VP8GetBit(br, p[6]))
-                    {
-                        if (!VP8GetBit(br, p[7]))
-                        {
-                            v = 5 + VP8GetBit(br, 159);
-                        } else
-                        {
-                            v = 7 + 2 * VP8GetBit(br, 165);
-                            v += VP8GetBit(br, 145);
-                        }
-                    }
-                    else
-                    {
-                        const uint8_t* tab;
-                        const int bit1 = VP8GetBit(br, p[8]);
-                        const int bit0 = VP8GetBit(br, p[9 + bit1]);
-                        const int cat = 2 * bit1 + bit0;
-                        v = 0;
-                        for (tab = kCat3456[cat]; *tab; ++tab)
-                        {
-                            v += v + VP8GetBit(br, *tab);
-                        }
-                        v += 3 + (8 << cat);
-                    }
-                }
-                p = prob[kBands[n]][2];
-            }
-            j = kZigzag[n - 1];
-
-            out[j] = GetSigned(br, v);
-
-            if (n == 16 || !VP8GetBit(br, p[0]))
-            {   /* EOB */
-                return n;
-            }
-        }
-        if (n == 16)
-        {
-            return 16;
-        }
-    }
-}
-
-int vp8_decode_mb_tokens(VP8D_COMP *dx, MACROBLOCKD *x)
-{
-    BOOL_DECODER *bc = x->current_bc;
-    const FRAME_CONTEXT * const fc = &dx->common.fc;
-    char *eobs = x->eobs;
-
-    int i;
-    int nonzeros;
-    int eobtotal = 0;
-
-    short *qcoeff_ptr;
-    ProbaArray coef_probs;
-    ENTROPY_CONTEXT *a_ctx = ((ENTROPY_CONTEXT *)x->above_context);
-    ENTROPY_CONTEXT *l_ctx = ((ENTROPY_CONTEXT *)x->left_context);
-    ENTROPY_CONTEXT *a;
-    ENTROPY_CONTEXT *l;
-    int skip_dc = 0;
-
-    qcoeff_ptr = &x->qcoeff[0];
-
-    if (!x->mode_info_context->mbmi.is_4x4)
-    {
-        a = a_ctx + 8;
-        l = l_ctx + 8;
-
-        coef_probs = fc->coef_probs [1];
-
-        nonzeros = GetCoeffs(bc, coef_probs, (*a + *l), 0, qcoeff_ptr + 24 * 16);
-        *a = *l = (nonzeros > 0);
-
-        eobs[24] = nonzeros;
-        eobtotal += nonzeros - 16;
-
-        coef_probs = fc->coef_probs [0];
-        skip_dc = 1;
-    }
-    else
-    {
-        coef_probs = fc->coef_probs [3];
-        skip_dc = 0;
-    }
-
-    for (i = 0; i < 16; ++i)
-    {
-        a = a_ctx + (i&3);
-        l = l_ctx + ((i&0xc)>>2);
-
-        nonzeros = GetCoeffs(bc, coef_probs, (*a + *l), skip_dc, qcoeff_ptr);
-        *a = *l = (nonzeros > 0);
-
-        nonzeros += skip_dc;
-        eobs[i] = nonzeros;
-        eobtotal += nonzeros;
-        qcoeff_ptr += 16;
-    }
-
-    coef_probs = fc->coef_probs [2];
-
-    a_ctx += 4;
-    l_ctx += 4;
-    for (i = 16; i < 24; ++i)
-    {
-        a = a_ctx + ((i > 19)<<1) + (i&1);
-        l = l_ctx + ((i > 19)<<1) + ((i&3)>1);
-
-        nonzeros = GetCoeffs(bc, coef_probs, (*a + *l), 0, qcoeff_ptr);
-        *a = *l = (nonzeros > 0);
-
-        eobs[i] = nonzeros;
-        eobtotal += nonzeros;
-        qcoeff_ptr += 16;
-    }
-
-    return eobtotal;
-}
-
diff --git a/vp8/decoder/detokenize.h b/vp8/decoder/detokenize.h
deleted file mode 100644 (file)
index f0b1254..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#ifndef VP8_DECODER_DETOKENIZE_H_
-#define VP8_DECODER_DETOKENIZE_H_
-
-#include "onyxd_int.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-void vp8_reset_mb_tokens_context(MACROBLOCKD *x);
-int vp8_decode_mb_tokens(VP8D_COMP *, MACROBLOCKD *);
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP8_DECODER_DETOKENIZE_H_
diff --git a/vp8/decoder/ec_types.h b/vp8/decoder/ec_types.h
deleted file mode 100644 (file)
index 3af5ca8..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- *  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.
- */
-
-#ifndef VP8_DECODER_EC_TYPES_H_
-#define VP8_DECODER_EC_TYPES_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define MAX_OVERLAPS 16
-
-
-/* The area (pixel area in Q6) the block pointed to by bmi overlaps
- * another block with.
- */
-typedef struct
-{
-    int overlap;
-    union b_mode_info *bmi;
-} OVERLAP_NODE;
-
-/* Structure to keep track of overlapping blocks on a block level. */
-typedef struct
-{
-    /* TODO(holmer): This array should be exchanged for a linked list */
-    OVERLAP_NODE overlaps[MAX_OVERLAPS];
-} B_OVERLAP;
-
-/* Structure used to hold all the overlaps of a macroblock. The overlaps of a
- * macroblock is further divided into block overlaps.
- */
-typedef struct
-{
-    B_OVERLAP overlaps[16];
-} MB_OVERLAP;
-
-/* Structure for keeping track of motion vectors and which reference frame they
- * refer to. Used for motion vector interpolation.
- */
-typedef struct
-{
-    MV mv;
-    MV_REFERENCE_FRAME ref_frame;
-} EC_BLOCK;
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP8_DECODER_EC_TYPES_H_
diff --git a/vp8/decoder/error_concealment.c b/vp8/decoder/error_concealment.c
deleted file mode 100644 (file)
index fbfae61..0000000
+++ /dev/null
@@ -1,597 +0,0 @@
-/*
- *  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.
- */
-
-#include <assert.h>
-
-#include "error_concealment.h"
-#include "onyxd_int.h"
-#include "decodemv.h"
-#include "vpx_mem/vpx_mem.h"
-#include "vp8/common/findnearmv.h"
-#include "vp8/common/common.h"
-#include "vpx_dsp/vpx_dsp_common.h"
-
-#define FLOOR(x,q) ((x) & -(1 << (q)))
-
-#define NUM_NEIGHBORS 20
-
-typedef struct ec_position
-{
-    int row;
-    int col;
-} EC_POS;
-
-/*
- * Regenerate the table in Matlab with:
- * x = meshgrid((1:4), (1:4));
- * y = meshgrid((1:4), (1:4))';
- * W = round((1./(sqrt(x.^2 + y.^2))*2^7));
- * W(1,1) = 0;
- */
-static const int weights_q7[5][5] = {
-       {  0,   128,    64,    43,    32 },
-       {128,    91,    57,    40,    31 },
-       { 64,    57,    45,    36,    29 },
-       { 43,    40,    36,    30,    26 },
-       { 32,    31,    29,    26,    23 }
-};
-
-int vp8_alloc_overlap_lists(VP8D_COMP *pbi)
-{
-    if (pbi->overlaps != NULL)
-    {
-        vpx_free(pbi->overlaps);
-        pbi->overlaps = NULL;
-    }
-
-    pbi->overlaps = vpx_calloc(pbi->common.mb_rows * pbi->common.mb_cols,
-                               sizeof(MB_OVERLAP));
-
-    if (pbi->overlaps == NULL)
-        return -1;
-
-    return 0;
-}
-
-void vp8_de_alloc_overlap_lists(VP8D_COMP *pbi)
-{
-    vpx_free(pbi->overlaps);
-    pbi->overlaps = NULL;
-}
-
-/* Inserts a new overlap area value to the list of overlaps of a block */
-static void assign_overlap(OVERLAP_NODE* overlaps,
-                           union b_mode_info *bmi,
-                           int overlap)
-{
-    int i;
-    if (overlap <= 0)
-        return;
-    /* Find and assign to the next empty overlap node in the list of overlaps.
-     * Empty is defined as bmi == NULL */
-    for (i = 0; i < MAX_OVERLAPS; i++)
-    {
-        if (overlaps[i].bmi == NULL)
-        {
-            overlaps[i].bmi = bmi;
-            overlaps[i].overlap = overlap;
-            break;
-        }
-    }
-}
-
-/* Calculates the overlap area between two 4x4 squares, where the first
- * square has its upper-left corner at (b1_row, b1_col) and the second
- * square has its upper-left corner at (b2_row, b2_col). Doesn't
- * properly handle squares which do not overlap.
- */
-static int block_overlap(int b1_row, int b1_col, int b2_row, int b2_col)
-{
-    const int int_top = VPXMAX(b1_row, b2_row); // top
-    const int int_left = VPXMAX(b1_col, b2_col); // left
-    /* Since each block is 4x4 pixels, adding 4 (Q3) to the left/top edge
-     * gives us the right/bottom edge.
-     */
-    const int int_right = VPXMIN(b1_col + (4<<3), b2_col + (4<<3)); // right
-    const int int_bottom = VPXMIN(b1_row + (4<<3), b2_row + (4<<3)); // bottom
-    return (int_bottom - int_top) * (int_right - int_left);
-}
-
-/* Calculates the overlap area for all blocks in a macroblock at position
- * (mb_row, mb_col) in macroblocks, which are being overlapped by a given
- * overlapping block at position (new_row, new_col) (in pixels, Q3). The
- * first block being overlapped in the macroblock has position (first_blk_row,
- * first_blk_col) in blocks relative the upper-left corner of the image.
- */
-static void calculate_overlaps_mb(B_OVERLAP *b_overlaps, union b_mode_info *bmi,
-                                  int new_row, int new_col,
-                                  int mb_row, int mb_col,
-                                  int first_blk_row, int first_blk_col)
-{
-    /* Find the blocks within this MB (defined by mb_row, mb_col) which are
-     * overlapped by bmi and calculate and assign overlap for each of those
-     * blocks. */
-
-    /* Block coordinates relative the upper-left block */
-    const int rel_ol_blk_row = first_blk_row - mb_row * 4;
-    const int rel_ol_blk_col = first_blk_col - mb_col * 4;
-    /* If the block partly overlaps any previous MB, these coordinates
-     * can be < 0. We don't want to access blocks in previous MBs.
-     */
-    const int blk_idx = VPXMAX(rel_ol_blk_row,0) * 4 + VPXMAX(rel_ol_blk_col,0);
-    /* Upper left overlapping block */
-    B_OVERLAP *b_ol_ul = &(b_overlaps[blk_idx]);
-
-    /* Calculate and assign overlaps for all blocks in this MB
-     * which the motion compensated block overlaps
-     */
-    /* Avoid calculating overlaps for blocks in later MBs */
-    int end_row = VPXMIN(4 + mb_row * 4 - first_blk_row, 2);
-    int end_col = VPXMIN(4 + mb_col * 4 - first_blk_col, 2);
-    int row, col;
-
-    /* Check if new_row and new_col are evenly divisible by 4 (Q3),
-     * and if so we shouldn't check neighboring blocks
-     */
-    if (new_row >= 0 && (new_row & 0x1F) == 0)
-        end_row = 1;
-    if (new_col >= 0 && (new_col & 0x1F) == 0)
-        end_col = 1;
-
-    /* Check if the overlapping block partly overlaps a previous MB
-     * and if so, we're overlapping fewer blocks in this MB.
-     */
-    if (new_row < (mb_row*16)<<3)
-        end_row = 1;
-    if (new_col < (mb_col*16)<<3)
-        end_col = 1;
-
-    for (row = 0; row < end_row; ++row)
-    {
-        for (col = 0; col < end_col; ++col)
-        {
-            /* input in Q3, result in Q6 */
-            const int overlap = block_overlap(new_row, new_col,
-                                                  (((first_blk_row + row) *
-                                                      4) << 3),
-                                                  (((first_blk_col + col) *
-                                                      4) << 3));
-            assign_overlap(b_ol_ul[row * 4 + col].overlaps, bmi, overlap);
-        }
-    }
-}
-
-void vp8_calculate_overlaps(MB_OVERLAP *overlap_ul,
-                            int mb_rows, int mb_cols,
-                            union b_mode_info *bmi,
-                            int b_row, int b_col)
-{
-    MB_OVERLAP *mb_overlap;
-    int row, col, rel_row, rel_col;
-    int new_row, new_col;
-    int end_row, end_col;
-    int overlap_b_row, overlap_b_col;
-    int overlap_mb_row, overlap_mb_col;
-
-    /* mb subpixel position */
-    row = (4 * b_row) << 3; /* Q3 */
-    col = (4 * b_col) << 3; /* Q3 */
-
-    /* reverse compensate for motion */
-    new_row = row - bmi->mv.as_mv.row;
-    new_col = col - bmi->mv.as_mv.col;
-
-    if (new_row >= ((16*mb_rows) << 3) || new_col >= ((16*mb_cols) << 3))
-    {
-        /* the new block ended up outside the frame */
-        return;
-    }
-
-    if (new_row <= -32 || new_col <= -32)
-    {
-        /* outside the frame */
-        return;
-    }
-    /* overlapping block's position in blocks */
-    overlap_b_row = FLOOR(new_row / 4, 3) >> 3;
-    overlap_b_col = FLOOR(new_col / 4, 3) >> 3;
-
-    /* overlapping block's MB position in MBs
-     * operations are done in Q3
-     */
-    overlap_mb_row = FLOOR((overlap_b_row << 3) / 4, 3) >> 3;
-    overlap_mb_col = FLOOR((overlap_b_col << 3) / 4, 3) >> 3;
-
-    end_row = VPXMIN(mb_rows - overlap_mb_row, 2);
-    end_col = VPXMIN(mb_cols - overlap_mb_col, 2);
-
-    /* Don't calculate overlap for MBs we don't overlap */
-    /* Check if the new block row starts at the last block row of the MB */
-    if (abs(new_row - ((16*overlap_mb_row) << 3)) < ((3*4) << 3))
-        end_row = 1;
-    /* Check if the new block col starts at the last block col of the MB */
-    if (abs(new_col - ((16*overlap_mb_col) << 3)) < ((3*4) << 3))
-        end_col = 1;
-
-    /* find the MB(s) this block is overlapping */
-    for (rel_row = 0; rel_row < end_row; ++rel_row)
-    {
-        for (rel_col = 0; rel_col < end_col; ++rel_col)
-        {
-            if (overlap_mb_row + rel_row < 0 ||
-                overlap_mb_col + rel_col < 0)
-                continue;
-            mb_overlap = overlap_ul + (overlap_mb_row + rel_row) * mb_cols +
-                 overlap_mb_col + rel_col;
-
-            calculate_overlaps_mb(mb_overlap->overlaps, bmi,
-                                  new_row, new_col,
-                                  overlap_mb_row + rel_row,
-                                  overlap_mb_col + rel_col,
-                                  overlap_b_row + rel_row,
-                                  overlap_b_col + rel_col);
-        }
-    }
-}
-
-/* Estimates a motion vector given the overlapping blocks' motion vectors.
- * Filters out all overlapping blocks which do not refer to the correct
- * reference frame type.
- */
-static void estimate_mv(const OVERLAP_NODE *overlaps, union b_mode_info *bmi)
-{
-    int i;
-    int overlap_sum = 0;
-    int row_acc = 0;
-    int col_acc = 0;
-
-    bmi->mv.as_int = 0;
-    for (i=0; i < MAX_OVERLAPS; ++i)
-    {
-        if (overlaps[i].bmi == NULL)
-            break;
-        col_acc += overlaps[i].overlap * overlaps[i].bmi->mv.as_mv.col;
-        row_acc += overlaps[i].overlap * overlaps[i].bmi->mv.as_mv.row;
-        overlap_sum += overlaps[i].overlap;
-    }
-    if (overlap_sum > 0)
-    {
-        /* Q9 / Q6 = Q3 */
-        bmi->mv.as_mv.col = col_acc / overlap_sum;
-        bmi->mv.as_mv.row = row_acc / overlap_sum;
-    }
-    else
-    {
-        bmi->mv.as_mv.col = 0;
-        bmi->mv.as_mv.row = 0;
-    }
-}
-
-/* Estimates all motion vectors for a macroblock given the lists of
- * overlaps for each block. Decides whether or not the MVs must be clamped.
- */
-static void estimate_mb_mvs(const B_OVERLAP *block_overlaps,
-                            MODE_INFO *mi,
-                            int mb_to_left_edge,
-                            int mb_to_right_edge,
-                            int mb_to_top_edge,
-                            int mb_to_bottom_edge)
-{
-    int row, col;
-    int non_zero_count = 0;
-    MV * const filtered_mv = &(mi->mbmi.mv.as_mv);
-    union b_mode_info * const bmi = mi->bmi;
-    filtered_mv->col = 0;
-    filtered_mv->row = 0;
-    mi->mbmi.need_to_clamp_mvs = 0;
-    for (row = 0; row < 4; ++row)
-    {
-        int this_b_to_top_edge = mb_to_top_edge + ((row*4)<<3);
-        int this_b_to_bottom_edge = mb_to_bottom_edge - ((row*4)<<3);
-        for (col = 0; col < 4; ++col)
-        {
-            int i = row * 4 + col;
-            int this_b_to_left_edge = mb_to_left_edge + ((col*4)<<3);
-            int this_b_to_right_edge = mb_to_right_edge - ((col*4)<<3);
-            /* Estimate vectors for all blocks which are overlapped by this */
-            /* type. Interpolate/extrapolate the rest of the block's MVs */
-            estimate_mv(block_overlaps[i].overlaps, &(bmi[i]));
-            mi->mbmi.need_to_clamp_mvs |= vp8_check_mv_bounds(
-                                                         &bmi[i].mv,
-                                                         this_b_to_left_edge,
-                                                         this_b_to_right_edge,
-                                                         this_b_to_top_edge,
-                                                         this_b_to_bottom_edge);
-            if (bmi[i].mv.as_int != 0)
-            {
-                ++non_zero_count;
-                filtered_mv->col += bmi[i].mv.as_mv.col;
-                filtered_mv->row += bmi[i].mv.as_mv.row;
-            }
-        }
-    }
-    if (non_zero_count > 0)
-    {
-        filtered_mv->col /= non_zero_count;
-        filtered_mv->row /= non_zero_count;
-    }
-}
-
-static void calc_prev_mb_overlaps(MB_OVERLAP *overlaps, MODE_INFO *prev_mi,
-                                    int mb_row, int mb_col,
-                                    int mb_rows, int mb_cols)
-{
-    int sub_row;
-    int sub_col;
-    for (sub_row = 0; sub_row < 4; ++sub_row)
-    {
-        for (sub_col = 0; sub_col < 4; ++sub_col)
-        {
-            vp8_calculate_overlaps(
-                                overlaps, mb_rows, mb_cols,
-                                &(prev_mi->bmi[sub_row * 4 + sub_col]),
-                                4 * mb_row + sub_row,
-                                4 * mb_col + sub_col);
-        }
-    }
-}
-
-/* Estimate all missing motion vectors. This function does the same as the one
- * above, but has different input arguments. */
-static void estimate_missing_mvs(MB_OVERLAP *overlaps,
-                                 MODE_INFO *mi, MODE_INFO *prev_mi,
-                                 int mb_rows, int mb_cols,
-                                 unsigned int first_corrupt)
-{
-    int mb_row, mb_col;
-    memset(overlaps, 0, sizeof(MB_OVERLAP) * mb_rows * mb_cols);
-    /* First calculate the overlaps for all blocks */
-    for (mb_row = 0; mb_row < mb_rows; ++mb_row)
-    {
-        for (mb_col = 0; mb_col < mb_cols; ++mb_col)
-        {
-            /* We're only able to use blocks referring to the last frame
-             * when extrapolating new vectors.
-             */
-            if (prev_mi->mbmi.ref_frame == LAST_FRAME)
-            {
-                calc_prev_mb_overlaps(overlaps, prev_mi,
-                                      mb_row, mb_col,
-                                      mb_rows, mb_cols);
-            }
-            ++prev_mi;
-        }
-        ++prev_mi;
-    }
-
-    mb_row = first_corrupt / mb_cols;
-    mb_col = first_corrupt - mb_row * mb_cols;
-    mi += mb_row*(mb_cols + 1) + mb_col;
-    /* Go through all macroblocks in the current image with missing MVs
-     * and calculate new MVs using the overlaps.
-     */
-    for (; mb_row < mb_rows; ++mb_row)
-    {
-        int mb_to_top_edge = -((mb_row * 16)) << 3;
-        int mb_to_bottom_edge = ((mb_rows - 1 - mb_row) * 16) << 3;
-        for (; mb_col < mb_cols; ++mb_col)
-        {
-            int mb_to_left_edge = -((mb_col * 16) << 3);
-            int mb_to_right_edge = ((mb_cols - 1 - mb_col) * 16) << 3;
-            const B_OVERLAP *block_overlaps =
-                    overlaps[mb_row*mb_cols + mb_col].overlaps;
-            mi->mbmi.ref_frame = LAST_FRAME;
-            mi->mbmi.mode = SPLITMV;
-            mi->mbmi.uv_mode = DC_PRED;
-            mi->mbmi.partitioning = 3;
-            mi->mbmi.segment_id = 0;
-            estimate_mb_mvs(block_overlaps,
-                            mi,
-                            mb_to_left_edge,
-                            mb_to_right_edge,
-                            mb_to_top_edge,
-                            mb_to_bottom_edge);
-            ++mi;
-        }
-        mb_col = 0;
-        ++mi;
-    }
-}
-
-void vp8_estimate_missing_mvs(VP8D_COMP *pbi)
-{
-    VP8_COMMON * const pc = &pbi->common;
-    estimate_missing_mvs(pbi->overlaps,
-                         pc->mi, pc->prev_mi,
-                         pc->mb_rows, pc->mb_cols,
-                         pbi->mvs_corrupt_from_mb);
-}
-
-static void assign_neighbor(EC_BLOCK *neighbor, MODE_INFO *mi, int block_idx)
-{
-    assert(mi->mbmi.ref_frame < MAX_REF_FRAMES);
-    neighbor->ref_frame = mi->mbmi.ref_frame;
-    neighbor->mv = mi->bmi[block_idx].mv.as_mv;
-}
-
-/* Finds the neighboring blocks of a macroblocks. In the general case
- * 20 blocks are found. If a fewer number of blocks are found due to
- * image boundaries, those positions in the EC_BLOCK array are left "empty".
- * The neighbors are enumerated with the upper-left neighbor as the first
- * element, the second element refers to the neighbor to right of the previous
- * neighbor, and so on. The last element refers to the neighbor below the first
- * neighbor.
- */
-static void find_neighboring_blocks(MODE_INFO *mi,
-                                    EC_BLOCK *neighbors,
-                                    int mb_row, int mb_col,
-                                    int mb_rows, int mb_cols,
-                                    int mi_stride)
-{
-    int i = 0;
-    int j;
-    if (mb_row > 0)
-    {
-        /* upper left */
-        if (mb_col > 0)
-            assign_neighbor(&neighbors[i], mi - mi_stride - 1, 15);
-        ++i;
-        /* above */
-        for (j = 12; j < 16; ++j, ++i)
-            assign_neighbor(&neighbors[i], mi - mi_stride, j);
-    }
-    else
-        i += 5;
-    if (mb_col < mb_cols - 1)
-    {
-        /* upper right */
-        if (mb_row > 0)
-            assign_neighbor(&neighbors[i], mi - mi_stride + 1, 12);
-        ++i;
-        /* right */
-        for (j = 0; j <= 12; j += 4, ++i)
-            assign_neighbor(&neighbors[i], mi + 1, j);
-    }
-    else
-        i += 5;
-    if (mb_row < mb_rows - 1)
-    {
-        /* lower right */
-        if (mb_col < mb_cols - 1)
-            assign_neighbor(&neighbors[i], mi + mi_stride + 1, 0);
-        ++i;
-        /* below */
-        for (j = 0; j < 4; ++j, ++i)
-            assign_neighbor(&neighbors[i], mi + mi_stride, j);
-    }
-    else
-        i += 5;
-    if (mb_col > 0)
-    {
-        /* lower left */
-        if (mb_row < mb_rows - 1)
-            assign_neighbor(&neighbors[i], mi + mi_stride - 1, 4);
-        ++i;
-        /* left */
-        for (j = 3; j < 16; j += 4, ++i)
-        {
-            assign_neighbor(&neighbors[i], mi - 1, j);
-        }
-    }
-    else
-        i += 5;
-    assert(i == 20);
-}
-
-/* Interpolates all motion vectors for a macroblock from the neighboring blocks'
- * motion vectors.
- */
-static void interpolate_mvs(MACROBLOCKD *mb,
-                         EC_BLOCK *neighbors,
-                         MV_REFERENCE_FRAME dom_ref_frame)
-{
-    int row, col, i;
-    MODE_INFO * const mi = mb->mode_info_context;
-    /* Table with the position of the neighboring blocks relative the position
-     * of the upper left block of the current MB. Starting with the upper left
-     * neighbor and going to the right.
-     */
-    const EC_POS neigh_pos[NUM_NEIGHBORS] = {
-                                        {-1,-1}, {-1,0}, {-1,1}, {-1,2}, {-1,3},
-                                        {-1,4}, {0,4}, {1,4}, {2,4}, {3,4},
-                                        {4,4}, {4,3}, {4,2}, {4,1}, {4,0},
-                                        {4,-1}, {3,-1}, {2,-1}, {1,-1}, {0,-1}
-                                      };
-    mi->mbmi.need_to_clamp_mvs = 0;
-    for (row = 0; row < 4; ++row)
-    {
-        int mb_to_top_edge = mb->mb_to_top_edge + ((row*4)<<3);
-        int mb_to_bottom_edge = mb->mb_to_bottom_edge - ((row*4)<<3);
-        for (col = 0; col < 4; ++col)
-        {
-            int mb_to_left_edge = mb->mb_to_left_edge + ((col*4)<<3);
-            int mb_to_right_edge = mb->mb_to_right_edge - ((col*4)<<3);
-            int w_sum = 0;
-            int mv_row_sum = 0;
-            int mv_col_sum = 0;
-            int_mv * const mv = &(mi->bmi[row*4 + col].mv);
-            mv->as_int = 0;
-            for (i = 0; i < NUM_NEIGHBORS; ++i)
-            {
-                /* Calculate the weighted sum of neighboring MVs referring
-                 * to the dominant frame type.
-                 */
-                const int w = weights_q7[abs(row - neigh_pos[i].row)]
-                                        [abs(col - neigh_pos[i].col)];
-                if (neighbors[i].ref_frame != dom_ref_frame)
-                    continue;
-                w_sum += w;
-                /* Q7 * Q3 = Q10 */
-                mv_row_sum += w*neighbors[i].mv.row;
-                mv_col_sum += w*neighbors[i].mv.col;
-            }
-            if (w_sum > 0)
-            {
-                /* Avoid division by zero.
-                 * Normalize with the sum of the coefficients
-                 * Q3 = Q10 / Q7
-                 */
-                mv->as_mv.row = mv_row_sum / w_sum;
-                mv->as_mv.col = mv_col_sum / w_sum;
-                mi->mbmi.need_to_clamp_mvs |= vp8_check_mv_bounds(
-                                                            mv,
-                                                            mb_to_left_edge,
-                                                            mb_to_right_edge,
-                                                            mb_to_top_edge,
-                                                            mb_to_bottom_edge);
-            }
-        }
-    }
-}
-
-void vp8_interpolate_motion(MACROBLOCKD *mb,
-                        int mb_row, int mb_col,
-                        int mb_rows, int mb_cols,
-                        int mi_stride)
-{
-    /* Find relevant neighboring blocks */
-    EC_BLOCK neighbors[NUM_NEIGHBORS];
-    int i;
-    /* Initialize the array. MAX_REF_FRAMES is interpreted as "doesn't exist" */
-    for (i = 0; i < NUM_NEIGHBORS; ++i)
-    {
-        neighbors[i].ref_frame = MAX_REF_FRAMES;
-        neighbors[i].mv.row = neighbors[i].mv.col = 0;
-    }
-    find_neighboring_blocks(mb->mode_info_context,
-                                neighbors,
-                                mb_row, mb_col,
-                                mb_rows, mb_cols,
-                                mb->mode_info_stride);
-    /* Interpolate MVs for the missing blocks from the surrounding
-     * blocks which refer to the last frame. */
-    interpolate_mvs(mb, neighbors, LAST_FRAME);
-
-    mb->mode_info_context->mbmi.ref_frame = LAST_FRAME;
-    mb->mode_info_context->mbmi.mode = SPLITMV;
-    mb->mode_info_context->mbmi.uv_mode = DC_PRED;
-    mb->mode_info_context->mbmi.partitioning = 3;
-    mb->mode_info_context->mbmi.segment_id = 0;
-}
-
-void vp8_conceal_corrupt_mb(MACROBLOCKD *xd)
-{
-    /* This macroblock has corrupt residual, use the motion compensated
-       image (predictor) for concealment */
-
-    /* The build predictor functions now output directly into the dst buffer,
-     * so the copies are no longer necessary */
-
-}
diff --git a/vp8/decoder/error_concealment.h b/vp8/decoder/error_concealment.h
deleted file mode 100644 (file)
index 9a1e024..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- *  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.
- */
-
-
-#ifndef VP8_DECODER_ERROR_CONCEALMENT_H_
-#define VP8_DECODER_ERROR_CONCEALMENT_H_
-
-#include "onyxd_int.h"
-#include "ec_types.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* Allocate memory for the overlap lists */
-int vp8_alloc_overlap_lists(VP8D_COMP *pbi);
-
-/* Deallocate the overlap lists */
-void vp8_de_alloc_overlap_lists(VP8D_COMP *pbi);
-
-/* Estimate all missing motion vectors. */
-void vp8_estimate_missing_mvs(VP8D_COMP *pbi);
-
-/* Functions for spatial MV interpolation */
-
-/* Interpolates all motion vectors for a macroblock mb at position
- * (mb_row, mb_col). */
-void vp8_interpolate_motion(MACROBLOCKD *mb,
-                            int mb_row, int mb_col,
-                            int mb_rows, int mb_cols,
-                            int mi_stride);
-
-/* Conceal a macroblock with corrupt residual.
- * Copies the prediction signal to the reconstructed image.
- */
-void vp8_conceal_corrupt_mb(MACROBLOCKD *xd);
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP8_DECODER_ERROR_CONCEALMENT_H_
diff --git a/vp8/decoder/onyxd_if.c b/vp8/decoder/onyxd_if.c
deleted file mode 100644 (file)
index 3468268..0000000
+++ /dev/null
@@ -1,521 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#include "vp8/common/onyxc_int.h"
-#if CONFIG_POSTPROC
-#include "vp8/common/postproc.h"
-#endif
-#include "vp8/common/onyxd.h"
-#include "onyxd_int.h"
-#include "vpx_mem/vpx_mem.h"
-#include "vp8/common/alloccommon.h"
-#include "vp8/common/loopfilter.h"
-#include "vp8/common/swapyv12buffer.h"
-#include "vp8/common/threading.h"
-#include "decoderthreading.h"
-#include <stdio.h>
-#include <assert.h>
-
-#include "vp8/common/quant_common.h"
-#include "vp8/common/reconintra.h"
-#include "./vpx_dsp_rtcd.h"
-#include "./vpx_scale_rtcd.h"
-#include "vpx_scale/vpx_scale.h"
-#include "vp8/common/systemdependent.h"
-#include "vpx_ports/vpx_once.h"
-#include "vpx_ports/vpx_timer.h"
-#include "detokenize.h"
-#if CONFIG_ERROR_CONCEALMENT
-#include "error_concealment.h"
-#endif
-#if ARCH_ARM
-#include "vpx_ports/arm.h"
-#endif
-
-extern void vp8_init_loop_filter(VP8_COMMON *cm);
-extern void vp8cx_init_de_quantizer(VP8D_COMP *pbi);
-static int get_free_fb (VP8_COMMON *cm);
-static void ref_cnt_fb (int *buf, int *idx, int new_idx);
-
-static void initialize_dec(void) {
-    static volatile int init_done = 0;
-
-    if (!init_done)
-    {
-        vpx_dsp_rtcd();
-        vp8_init_intra_predictors();
-        init_done = 1;
-    }
-}
-
-static void remove_decompressor(VP8D_COMP *pbi)
-{
-#if CONFIG_ERROR_CONCEALMENT
-    vp8_de_alloc_overlap_lists(pbi);
-#endif
-    vp8_remove_common(&pbi->common);
-    vpx_free(pbi);
-}
-
-static struct VP8D_COMP * create_decompressor(VP8D_CONFIG *oxcf)
-{
-    VP8D_COMP *pbi = vpx_memalign(32, sizeof(VP8D_COMP));
-
-    if (!pbi)
-        return NULL;
-
-    memset(pbi, 0, sizeof(VP8D_COMP));
-
-    if (setjmp(pbi->common.error.jmp))
-    {
-        pbi->common.error.setjmp = 0;
-        remove_decompressor(pbi);
-        return 0;
-    }
-
-    pbi->common.error.setjmp = 1;
-
-    vp8_create_common(&pbi->common);
-
-    pbi->common.current_video_frame = 0;
-    pbi->ready_for_new_data = 1;
-
-    /* vp8cx_init_de_quantizer() is first called here. Add check in frame_init_dequantizer() to avoid
-     *  unnecessary calling of vp8cx_init_de_quantizer() for every frame.
-     */
-    vp8cx_init_de_quantizer(pbi);
-
-    vp8_loop_filter_init(&pbi->common);
-
-    pbi->common.error.setjmp = 0;
-
-#if CONFIG_ERROR_CONCEALMENT
-    pbi->ec_enabled = oxcf->error_concealment;
-    pbi->overlaps = NULL;
-#else
-    (void)oxcf;
-    pbi->ec_enabled = 0;
-#endif
-    /* Error concealment is activated after a key frame has been
-     * decoded without errors when error concealment is enabled.
-     */
-    pbi->ec_active = 0;
-
-    pbi->decoded_key_frame = 0;
-
-    /* Independent partitions is activated when a frame updates the
-     * token probability table to have equal probabilities over the
-     * PREV_COEF context.
-     */
-    pbi->independent_partitions = 0;
-
-    vp8_setup_block_dptrs(&pbi->mb);
-
-    once(initialize_dec);
-
-    return pbi;
-}
-
-vpx_codec_err_t vp8dx_get_reference(VP8D_COMP *pbi, enum vpx_ref_frame_type ref_frame_flag, YV12_BUFFER_CONFIG *sd)
-{
-    VP8_COMMON *cm = &pbi->common;
-    int ref_fb_idx;
-
-    if (ref_frame_flag == VP8_LAST_FRAME)
-        ref_fb_idx = cm->lst_fb_idx;
-    else if (ref_frame_flag == VP8_GOLD_FRAME)
-        ref_fb_idx = cm->gld_fb_idx;
-    else if (ref_frame_flag == VP8_ALTR_FRAME)
-        ref_fb_idx = cm->alt_fb_idx;
-    else{
-        vpx_internal_error(&pbi->common.error, VPX_CODEC_ERROR,
-            "Invalid reference frame");
-        return pbi->common.error.error_code;
-    }
-
-    if(cm->yv12_fb[ref_fb_idx].y_height != sd->y_height ||
-        cm->yv12_fb[ref_fb_idx].y_width != sd->y_width ||
-        cm->yv12_fb[ref_fb_idx].uv_height != sd->uv_height ||
-        cm->yv12_fb[ref_fb_idx].uv_width != sd->uv_width){
-        vpx_internal_error(&pbi->common.error, VPX_CODEC_ERROR,
-            "Incorrect buffer dimensions");
-    }
-    else
-        vp8_yv12_copy_frame(&cm->yv12_fb[ref_fb_idx], sd);
-
-    return pbi->common.error.error_code;
-}
-
-
-vpx_codec_err_t vp8dx_set_reference(VP8D_COMP *pbi, enum vpx_ref_frame_type ref_frame_flag, YV12_BUFFER_CONFIG *sd)
-{
-    VP8_COMMON *cm = &pbi->common;
-    int *ref_fb_ptr = NULL;
-    int free_fb;
-
-    if (ref_frame_flag == VP8_LAST_FRAME)
-        ref_fb_ptr = &cm->lst_fb_idx;
-    else if (ref_frame_flag == VP8_GOLD_FRAME)
-        ref_fb_ptr = &cm->gld_fb_idx;
-    else if (ref_frame_flag == VP8_ALTR_FRAME)
-        ref_fb_ptr = &cm->alt_fb_idx;
-    else{
-        vpx_internal_error(&pbi->common.error, VPX_CODEC_ERROR,
-            "Invalid reference frame");
-        return pbi->common.error.error_code;
-    }
-
-    if(cm->yv12_fb[*ref_fb_ptr].y_height != sd->y_height ||
-        cm->yv12_fb[*ref_fb_ptr].y_width != sd->y_width ||
-        cm->yv12_fb[*ref_fb_ptr].uv_height != sd->uv_height ||
-        cm->yv12_fb[*ref_fb_ptr].uv_width != sd->uv_width){
-        vpx_internal_error(&pbi->common.error, VPX_CODEC_ERROR,
-            "Incorrect buffer dimensions");
-    }
-    else{
-        /* Find an empty frame buffer. */
-        free_fb = get_free_fb(cm);
-        /* Decrease fb_idx_ref_cnt since it will be increased again in
-         * ref_cnt_fb() below. */
-        cm->fb_idx_ref_cnt[free_fb]--;
-
-        /* Manage the reference counters and copy image. */
-        ref_cnt_fb (cm->fb_idx_ref_cnt, ref_fb_ptr, free_fb);
-        vp8_yv12_copy_frame(sd, &cm->yv12_fb[*ref_fb_ptr]);
-    }
-
-   return pbi->common.error.error_code;
-}
-
-static int get_free_fb (VP8_COMMON *cm)
-{
-    int i;
-    for (i = 0; i < NUM_YV12_BUFFERS; i++)
-        if (cm->fb_idx_ref_cnt[i] == 0)
-            break;
-
-    assert(i < NUM_YV12_BUFFERS);
-    cm->fb_idx_ref_cnt[i] = 1;
-    return i;
-}
-
-static void ref_cnt_fb (int *buf, int *idx, int new_idx)
-{
-    if (buf[*idx] > 0)
-        buf[*idx]--;
-
-    *idx = new_idx;
-
-    buf[new_idx]++;
-}
-
-/* If any buffer copy / swapping is signalled it should be done here. */
-static int swap_frame_buffers (VP8_COMMON *cm)
-{
-    int err = 0;
-
-    /* The alternate reference frame or golden frame can be updated
-     *  using the new, last, or golden/alt ref frame.  If it
-     *  is updated using the newly decoded frame it is a refresh.
-     *  An update using the last or golden/alt ref frame is a copy.
-     */
-    if (cm->copy_buffer_to_arf)
-    {
-        int new_fb = 0;
-
-        if (cm->copy_buffer_to_arf == 1)
-            new_fb = cm->lst_fb_idx;
-        else if (cm->copy_buffer_to_arf == 2)
-            new_fb = cm->gld_fb_idx;
-        else
-            err = -1;
-
-        ref_cnt_fb (cm->fb_idx_ref_cnt, &cm->alt_fb_idx, new_fb);
-    }
-
-    if (cm->copy_buffer_to_gf)
-    {
-        int new_fb = 0;
-
-        if (cm->copy_buffer_to_gf == 1)
-            new_fb = cm->lst_fb_idx;
-        else if (cm->copy_buffer_to_gf == 2)
-            new_fb = cm->alt_fb_idx;
-        else
-            err = -1;
-
-        ref_cnt_fb (cm->fb_idx_ref_cnt, &cm->gld_fb_idx, new_fb);
-    }
-
-    if (cm->refresh_golden_frame)
-        ref_cnt_fb (cm->fb_idx_ref_cnt, &cm->gld_fb_idx, cm->new_fb_idx);
-
-    if (cm->refresh_alt_ref_frame)
-        ref_cnt_fb (cm->fb_idx_ref_cnt, &cm->alt_fb_idx, cm->new_fb_idx);
-
-    if (cm->refresh_last_frame)
-    {
-        ref_cnt_fb (cm->fb_idx_ref_cnt, &cm->lst_fb_idx, cm->new_fb_idx);
-
-        cm->frame_to_show = &cm->yv12_fb[cm->lst_fb_idx];
-    }
-    else
-        cm->frame_to_show = &cm->yv12_fb[cm->new_fb_idx];
-
-    cm->fb_idx_ref_cnt[cm->new_fb_idx]--;
-
-    return err;
-}
-
-static int check_fragments_for_errors(VP8D_COMP *pbi)
-{
-    if (!pbi->ec_active &&
-        pbi->fragments.count <= 1 && pbi->fragments.sizes[0] == 0)
-    {
-        VP8_COMMON *cm = &pbi->common;
-
-        /* If error concealment is disabled we won't signal missing frames
-         * to the decoder.
-         */
-        if (cm->fb_idx_ref_cnt[cm->lst_fb_idx] > 1)
-        {
-            /* The last reference shares buffer with another reference
-             * buffer. Move it to its own buffer before setting it as
-             * corrupt, otherwise we will make multiple buffers corrupt.
-             */
-            const int prev_idx = cm->lst_fb_idx;
-            cm->fb_idx_ref_cnt[prev_idx]--;
-            cm->lst_fb_idx = get_free_fb(cm);
-            vp8_yv12_copy_frame(&cm->yv12_fb[prev_idx],
-                                    &cm->yv12_fb[cm->lst_fb_idx]);
-        }
-        /* This is used to signal that we are missing frames.
-         * We do not know if the missing frame(s) was supposed to update
-         * any of the reference buffers, but we act conservative and
-         * mark only the last buffer as corrupted.
-         */
-        cm->yv12_fb[cm->lst_fb_idx].corrupted = 1;
-
-        /* Signal that we have no frame to show. */
-        cm->show_frame = 0;
-
-        /* Nothing more to do. */
-        return 0;
-    }
-
-    return 1;
-}
-
-int vp8dx_receive_compressed_data(VP8D_COMP *pbi, size_t size,
-                                  const uint8_t *source,
-                                  int64_t time_stamp)
-{
-    VP8_COMMON *cm = &pbi->common;
-    int retcode = -1;
-    (void)size;
-    (void)source;
-
-    pbi->common.error.error_code = VPX_CODEC_OK;
-
-    retcode = check_fragments_for_errors(pbi);
-    if(retcode <= 0)
-        return retcode;
-
-    cm->new_fb_idx = get_free_fb (cm);
-
-    /* setup reference frames for vp8_decode_frame */
-    pbi->dec_fb_ref[INTRA_FRAME]  = &cm->yv12_fb[cm->new_fb_idx];
-    pbi->dec_fb_ref[LAST_FRAME]   = &cm->yv12_fb[cm->lst_fb_idx];
-    pbi->dec_fb_ref[GOLDEN_FRAME] = &cm->yv12_fb[cm->gld_fb_idx];
-    pbi->dec_fb_ref[ALTREF_FRAME] = &cm->yv12_fb[cm->alt_fb_idx];
-
-    if (setjmp(pbi->common.error.jmp))
-    {
-       /* We do not know if the missing frame(s) was supposed to update
-        * any of the reference buffers, but we act conservative and
-        * mark only the last buffer as corrupted.
-        */
-        cm->yv12_fb[cm->lst_fb_idx].corrupted = 1;
-
-        if (cm->fb_idx_ref_cnt[cm->new_fb_idx] > 0)
-          cm->fb_idx_ref_cnt[cm->new_fb_idx]--;
-
-        goto decode_exit;
-    }
-
-    pbi->common.error.setjmp = 1;
-
-    retcode = vp8_decode_frame(pbi);
-
-    if (retcode < 0)
-    {
-        if (cm->fb_idx_ref_cnt[cm->new_fb_idx] > 0)
-          cm->fb_idx_ref_cnt[cm->new_fb_idx]--;
-
-        pbi->common.error.error_code = VPX_CODEC_ERROR;
-        goto decode_exit;
-    }
-
-    if (swap_frame_buffers (cm))
-    {
-        pbi->common.error.error_code = VPX_CODEC_ERROR;
-        goto decode_exit;
-    }
-
-    vp8_clear_system_state();
-
-    if (cm->show_frame)
-    {
-        cm->current_video_frame++;
-        cm->show_frame_mi = cm->mi;
-    }
-
-    #if CONFIG_ERROR_CONCEALMENT
-    /* swap the mode infos to storage for future error concealment */
-    if (pbi->ec_enabled && pbi->common.prev_mi)
-    {
-        MODE_INFO* tmp = pbi->common.prev_mi;
-        int row, col;
-        pbi->common.prev_mi = pbi->common.mi;
-        pbi->common.mi = tmp;
-
-        /* Propagate the segment_ids to the next frame */
-        for (row = 0; row < pbi->common.mb_rows; ++row)
-        {
-            for (col = 0; col < pbi->common.mb_cols; ++col)
-            {
-                const int i = row*pbi->common.mode_info_stride + col;
-                pbi->common.mi[i].mbmi.segment_id =
-                        pbi->common.prev_mi[i].mbmi.segment_id;
-            }
-        }
-    }
-#endif
-
-    pbi->ready_for_new_data = 0;
-    pbi->last_time_stamp = time_stamp;
-
-decode_exit:
-    pbi->common.error.setjmp = 0;
-    vp8_clear_system_state();
-    return retcode;
-}
-int vp8dx_get_raw_frame(VP8D_COMP *pbi, YV12_BUFFER_CONFIG *sd, int64_t *time_stamp, int64_t *time_end_stamp, vp8_ppflags_t *flags)
-{
-    int ret = -1;
-
-    if (pbi->ready_for_new_data == 1)
-        return ret;
-
-    /* ie no raw frame to show!!! */
-    if (pbi->common.show_frame == 0)
-        return ret;
-
-    pbi->ready_for_new_data = 1;
-    *time_stamp = pbi->last_time_stamp;
-    *time_end_stamp = 0;
-
-#if CONFIG_POSTPROC
-    ret = vp8_post_proc_frame(&pbi->common, sd, flags);
-#else
-    (void)flags;
-
-    if (pbi->common.frame_to_show)
-    {
-        *sd = *pbi->common.frame_to_show;
-        sd->y_width = pbi->common.Width;
-        sd->y_height = pbi->common.Height;
-        sd->uv_height = pbi->common.Height / 2;
-        ret = 0;
-    }
-    else
-    {
-        ret = -1;
-    }
-
-#endif /*!CONFIG_POSTPROC*/
-    vp8_clear_system_state();
-    return ret;
-}
-
-
-/* This function as written isn't decoder specific, but the encoder has
- * much faster ways of computing this, so it's ok for it to live in a
- * decode specific file.
- */
-int vp8dx_references_buffer( VP8_COMMON *oci, int ref_frame )
-{
-    const MODE_INFO *mi = oci->mi;
-    int mb_row, mb_col;
-
-    for (mb_row = 0; mb_row < oci->mb_rows; mb_row++)
-    {
-        for (mb_col = 0; mb_col < oci->mb_cols; mb_col++,mi++)
-        {
-            if( mi->mbmi.ref_frame == ref_frame)
-              return 1;
-        }
-        mi++;
-    }
-    return 0;
-
-}
-
-int vp8_create_decoder_instances(struct frame_buffers *fb, VP8D_CONFIG *oxcf)
-{
-    if(!fb->use_frame_threads)
-    {
-        /* decoder instance for single thread mode */
-        fb->pbi[0] = create_decompressor(oxcf);
-        if(!fb->pbi[0])
-            return VPX_CODEC_ERROR;
-
-#if CONFIG_MULTITHREAD
-        /* enable row-based threading only when use_frame_threads
-         * is disabled */
-        fb->pbi[0]->max_threads = oxcf->max_threads;
-        vp8_decoder_create_threads(fb->pbi[0]);
-#endif
-    }
-    else
-    {
-        /* TODO : create frame threads and decoder instances for each
-         * thread here */
-    }
-
-    return VPX_CODEC_OK;
-}
-
-int vp8_remove_decoder_instances(struct frame_buffers *fb)
-{
-    if(!fb->use_frame_threads)
-    {
-        VP8D_COMP *pbi = fb->pbi[0];
-
-        if (!pbi)
-            return VPX_CODEC_ERROR;
-#if CONFIG_MULTITHREAD
-        if (pbi->b_multithreaded_rd)
-            vp8mt_de_alloc_temp_buffers(pbi, pbi->common.mb_rows);
-        vp8_decoder_remove_threads(pbi);
-#endif
-
-        /* decoder instance for single thread mode */
-        remove_decompressor(pbi);
-    }
-    else
-    {
-        /* TODO : remove frame threads and decoder instances for each
-         * thread here */
-    }
-
-    return VPX_CODEC_OK;
-}
diff --git a/vp8/decoder/onyxd_int.h b/vp8/decoder/onyxd_int.h
deleted file mode 100644 (file)
index 313fe01..0000000
+++ /dev/null
@@ -1,161 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#ifndef VP8_DECODER_ONYXD_INT_H_
-#define VP8_DECODER_ONYXD_INT_H_
-
-#include "vpx_config.h"
-#include "vp8/common/onyxd.h"
-#include "treereader.h"
-#include "vp8/common/onyxc_int.h"
-#include "vp8/common/threading.h"
-
-#if CONFIG_ERROR_CONCEALMENT
-#include "ec_types.h"
-#endif
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef struct
-{
-    int ithread;
-    void *ptr1;
-    void *ptr2;
-} DECODETHREAD_DATA;
-
-typedef struct
-{
-    MACROBLOCKD  mbd;
-} MB_ROW_DEC;
-
-
-typedef struct
-{
-    int enabled;
-    unsigned int count;
-    const unsigned char *ptrs[MAX_PARTITIONS];
-    unsigned int sizes[MAX_PARTITIONS];
-} FRAGMENT_DATA;
-
-#define MAX_FB_MT_DEC 32
-
-struct frame_buffers
-{
-    /*
-     * this struct will be populated with frame buffer management
-     * info in future commits. */
-
-    /* enable/disable frame-based threading */
-    int     use_frame_threads;
-
-    /* decoder instances */
-    struct VP8D_COMP *pbi[MAX_FB_MT_DEC];
-
-};
-
-typedef struct VP8D_COMP
-{
-    DECLARE_ALIGNED(16, MACROBLOCKD, mb);
-
-    YV12_BUFFER_CONFIG *dec_fb_ref[NUM_YV12_BUFFERS];
-
-    DECLARE_ALIGNED(16, VP8_COMMON, common);
-
-    /* the last partition will be used for the modes/mvs */
-    vp8_reader mbc[MAX_PARTITIONS];
-
-    VP8D_CONFIG oxcf;
-
-    FRAGMENT_DATA fragments;
-
-#if CONFIG_MULTITHREAD
-    /* variable for threading */
-
-    int b_multithreaded_rd;
-    int max_threads;
-    int current_mb_col_main;
-    unsigned int decoding_thread_count;
-    int allocated_decoding_thread_count;
-
-    int mt_baseline_filter_level[MAX_MB_SEGMENTS];
-    int sync_range;
-    int *mt_current_mb_col;                  /* Each row remembers its already decoded column. */
-    pthread_mutex_t *pmutex;
-    pthread_mutex_t mt_mutex;                /* mutex for b_multithreaded_rd */
-
-    unsigned char **mt_yabove_row;           /* mb_rows x width */
-    unsigned char **mt_uabove_row;
-    unsigned char **mt_vabove_row;
-    unsigned char **mt_yleft_col;            /* mb_rows x 16 */
-    unsigned char **mt_uleft_col;            /* mb_rows x 8 */
-    unsigned char **mt_vleft_col;            /* mb_rows x 8 */
-
-    MB_ROW_DEC           *mb_row_di;
-    DECODETHREAD_DATA    *de_thread_data;
-
-    pthread_t           *h_decoding_thread;
-    sem_t               *h_event_start_decoding;
-    sem_t                h_event_end_decoding;
-    /* end of threading data */
-#endif
-
-    int64_t last_time_stamp;
-    int   ready_for_new_data;
-
-    vp8_prob prob_intra;
-    vp8_prob prob_last;
-    vp8_prob prob_gf;
-    vp8_prob prob_skip_false;
-
-#if CONFIG_ERROR_CONCEALMENT
-    MB_OVERLAP *overlaps;
-    /* the mb num from which modes and mvs (first partition) are corrupt */
-    unsigned int mvs_corrupt_from_mb;
-#endif
-    int ec_enabled;
-    int ec_active;
-    int decoded_key_frame;
-    int independent_partitions;
-    int frame_corrupt_residual;
-
-    vpx_decrypt_cb decrypt_cb;
-    void *decrypt_state;
-} VP8D_COMP;
-
-int vp8_decode_frame(VP8D_COMP *cpi);
-
-int vp8_create_decoder_instances(struct frame_buffers *fb, VP8D_CONFIG *oxcf);
-int vp8_remove_decoder_instances(struct frame_buffers *fb);
-
-#if CONFIG_DEBUG
-#define CHECK_MEM_ERROR(lval,expr) do {\
-        lval = (expr); \
-        if(!lval) \
-            vpx_internal_error(&pbi->common.error, VPX_CODEC_MEM_ERROR,\
-                               "Failed to allocate "#lval" at %s:%d", \
-                               __FILE__,__LINE__);\
-    } while(0)
-#else
-#define CHECK_MEM_ERROR(lval,expr) do {\
-        lval = (expr); \
-        if(!lval) \
-            vpx_internal_error(&pbi->common.error, VPX_CODEC_MEM_ERROR,\
-                               "Failed to allocate "#lval);\
-    } while(0)
-#endif
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP8_DECODER_ONYXD_INT_H_
diff --git a/vp8/decoder/threading.c b/vp8/decoder/threading.c
deleted file mode 100644 (file)
index 97979e3..0000000
+++ /dev/null
@@ -1,931 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#include "vpx_config.h"
-#include "vp8_rtcd.h"
-#if !defined(WIN32) && CONFIG_OS_SUPPORT == 1
-# include <unistd.h>
-#endif
-#include "onyxd_int.h"
-#include "vpx_mem/vpx_mem.h"
-#include "vp8/common/threading.h"
-
-#include "vp8/common/loopfilter.h"
-#include "vp8/common/extend.h"
-#include "vpx_ports/vpx_timer.h"
-#include "detokenize.h"
-#include "vp8/common/reconintra4x4.h"
-#include "vp8/common/reconinter.h"
-#include "vp8/common/reconintra.h"
-#include "vp8/common/setupintrarecon.h"
-#if CONFIG_ERROR_CONCEALMENT
-#include "error_concealment.h"
-#endif
-
-#define CALLOC_ARRAY(p, n) CHECK_MEM_ERROR((p), vpx_calloc(sizeof(*(p)), (n)))
-#define CALLOC_ARRAY_ALIGNED(p, n, algn) do {                      \
-  CHECK_MEM_ERROR((p), vpx_memalign((algn), sizeof(*(p)) * (n)));  \
-  memset((p), 0, (n) * sizeof(*(p)));                              \
-} while (0)
-
-
-void vp8_mb_init_dequantizer(VP8D_COMP *pbi, MACROBLOCKD *xd);
-
-static void setup_decoding_thread_data(VP8D_COMP *pbi, MACROBLOCKD *xd, MB_ROW_DEC *mbrd, int count)
-{
-    VP8_COMMON *const pc = & pbi->common;
-    int i;
-
-    for (i = 0; i < count; i++)
-    {
-        MACROBLOCKD *mbd = &mbrd[i].mbd;
-        mbd->subpixel_predict        = xd->subpixel_predict;
-        mbd->subpixel_predict8x4     = xd->subpixel_predict8x4;
-        mbd->subpixel_predict8x8     = xd->subpixel_predict8x8;
-        mbd->subpixel_predict16x16   = xd->subpixel_predict16x16;
-
-        mbd->frame_type = pc->frame_type;
-        mbd->pre = xd->pre;
-        mbd->dst = xd->dst;
-
-        mbd->segmentation_enabled    = xd->segmentation_enabled;
-        mbd->mb_segement_abs_delta     = xd->mb_segement_abs_delta;
-        memcpy(mbd->segment_feature_data, xd->segment_feature_data, sizeof(xd->segment_feature_data));
-
-        /*signed char ref_lf_deltas[MAX_REF_LF_DELTAS];*/
-        memcpy(mbd->ref_lf_deltas, xd->ref_lf_deltas, sizeof(xd->ref_lf_deltas));
-        /*signed char mode_lf_deltas[MAX_MODE_LF_DELTAS];*/
-        memcpy(mbd->mode_lf_deltas, xd->mode_lf_deltas, sizeof(xd->mode_lf_deltas));
-        /*unsigned char mode_ref_lf_delta_enabled;
-        unsigned char mode_ref_lf_delta_update;*/
-        mbd->mode_ref_lf_delta_enabled    = xd->mode_ref_lf_delta_enabled;
-        mbd->mode_ref_lf_delta_update    = xd->mode_ref_lf_delta_update;
-
-        mbd->current_bc = &pbi->mbc[0];
-
-        memcpy(mbd->dequant_y1_dc, xd->dequant_y1_dc, sizeof(xd->dequant_y1_dc));
-        memcpy(mbd->dequant_y1, xd->dequant_y1, sizeof(xd->dequant_y1));
-        memcpy(mbd->dequant_y2, xd->dequant_y2, sizeof(xd->dequant_y2));
-        memcpy(mbd->dequant_uv, xd->dequant_uv, sizeof(xd->dequant_uv));
-
-        mbd->fullpixel_mask = 0xffffffff;
-
-        if (pc->full_pixel)
-            mbd->fullpixel_mask = 0xfffffff8;
-
-    }
-
-    for (i = 0; i < pc->mb_rows; i++)
-        pbi->mt_current_mb_col[i] = -1;
-}
-
-static void mt_decode_macroblock(VP8D_COMP *pbi, MACROBLOCKD *xd,
-                                 unsigned int mb_idx)
-{
-    MB_PREDICTION_MODE mode;
-    int i;
-#if CONFIG_ERROR_CONCEALMENT
-    int corruption_detected = 0;
-#else
-    (void)mb_idx;
-#endif
-
-    if (xd->mode_info_context->mbmi.mb_skip_coeff)
-    {
-        vp8_reset_mb_tokens_context(xd);
-    }
-    else if (!vp8dx_bool_error(xd->current_bc))
-    {
-        int eobtotal;
-        eobtotal = vp8_decode_mb_tokens(pbi, xd);
-
-        /* Special case:  Force the loopfilter to skip when eobtotal is zero */
-        xd->mode_info_context->mbmi.mb_skip_coeff = (eobtotal==0);
-    }
-
-    mode = xd->mode_info_context->mbmi.mode;
-
-    if (xd->segmentation_enabled)
-        vp8_mb_init_dequantizer(pbi, xd);
-
-
-#if CONFIG_ERROR_CONCEALMENT
-
-    if(pbi->ec_active)
-    {
-        int throw_residual;
-        /* When we have independent partitions we can apply residual even
-         * though other partitions within the frame are corrupt.
-         */
-        throw_residual = (!pbi->independent_partitions &&
-                          pbi->frame_corrupt_residual);
-        throw_residual = (throw_residual || vp8dx_bool_error(xd->current_bc));
-
-        if ((mb_idx >= pbi->mvs_corrupt_from_mb || throw_residual))
-        {
-            /* MB with corrupt residuals or corrupt mode/motion vectors.
-             * Better to use the predictor as reconstruction.
-             */
-            pbi->frame_corrupt_residual = 1;
-            memset(xd->qcoeff, 0, sizeof(xd->qcoeff));
-            vp8_conceal_corrupt_mb(xd);
-
-
-            corruption_detected = 1;
-
-            /* force idct to be skipped for B_PRED and use the
-             * prediction only for reconstruction
-             * */
-            memset(xd->eobs, 0, 25);
-        }
-    }
-#endif
-
-    /* do prediction */
-    if (xd->mode_info_context->mbmi.ref_frame == INTRA_FRAME)
-    {
-        vp8_build_intra_predictors_mbuv_s(xd,
-                                          xd->recon_above[1],
-                                          xd->recon_above[2],
-                                          xd->recon_left[1],
-                                          xd->recon_left[2],
-                                          xd->recon_left_stride[1],
-                                          xd->dst.u_buffer, xd->dst.v_buffer,
-                                          xd->dst.uv_stride);
-
-        if (mode != B_PRED)
-        {
-            vp8_build_intra_predictors_mby_s(xd,
-                                                 xd->recon_above[0],
-                                                 xd->recon_left[0],
-                                                 xd->recon_left_stride[0],
-                                                 xd->dst.y_buffer,
-                                                 xd->dst.y_stride);
-        }
-        else
-        {
-            short *DQC = xd->dequant_y1;
-            int dst_stride = xd->dst.y_stride;
-
-            /* clear out residual eob info */
-            if(xd->mode_info_context->mbmi.mb_skip_coeff)
-                memset(xd->eobs, 0, 25);
-
-            intra_prediction_down_copy(xd, xd->recon_above[0] + 16);
-
-            for (i = 0; i < 16; i++)
-            {
-                BLOCKD *b = &xd->block[i];
-                unsigned char *dst = xd->dst.y_buffer + b->offset;
-                B_PREDICTION_MODE b_mode =
-                    xd->mode_info_context->bmi[i].as_mode;
-                unsigned char *Above;
-                unsigned char *yleft;
-                int left_stride;
-                unsigned char top_left;
-
-                /*Caution: For some b_mode, it needs 8 pixels (4 above + 4 above-right).*/
-                if (i < 4 && pbi->common.filter_level)
-                    Above = xd->recon_above[0] + b->offset;
-                else
-                    Above = dst - dst_stride;
-
-                if (i%4==0 && pbi->common.filter_level)
-                {
-                    yleft = xd->recon_left[0] + i;
-                    left_stride = 1;
-                }
-                else
-                {
-                    yleft = dst - 1;
-                    left_stride = dst_stride;
-                }
-
-                if ((i==4 || i==8 || i==12) && pbi->common.filter_level)
-                    top_left = *(xd->recon_left[0] + i - 1);
-                else
-                    top_left = Above[-1];
-
-                vp8_intra4x4_predict(Above, yleft, left_stride,
-                                     b_mode, dst, dst_stride, top_left);
-
-                if (xd->eobs[i] )
-                {
-                    if (xd->eobs[i] > 1)
-                    {
-                        vp8_dequant_idct_add(b->qcoeff, DQC, dst, dst_stride);
-                    }
-                    else
-                    {
-                        vp8_dc_only_idct_add(b->qcoeff[0] * DQC[0],
-                                             dst, dst_stride, dst, dst_stride);
-                        memset(b->qcoeff, 0, 2 * sizeof(b->qcoeff[0]));
-                    }
-                }
-            }
-        }
-    }
-    else
-    {
-        vp8_build_inter_predictors_mb(xd);
-    }
-
-
-#if CONFIG_ERROR_CONCEALMENT
-    if (corruption_detected)
-    {
-        return;
-    }
-#endif
-
-    if(!xd->mode_info_context->mbmi.mb_skip_coeff)
-    {
-        /* dequantization and idct */
-        if (mode != B_PRED)
-        {
-            short *DQC = xd->dequant_y1;
-
-            if (mode != SPLITMV)
-            {
-                BLOCKD *b = &xd->block[24];
-
-                /* do 2nd order transform on the dc block */
-                if (xd->eobs[24] > 1)
-                {
-                    vp8_dequantize_b(b, xd->dequant_y2);
-
-                    vp8_short_inv_walsh4x4(&b->dqcoeff[0],
-                        xd->qcoeff);
-                    memset(b->qcoeff, 0, 16 * sizeof(b->qcoeff[0]));
-                }
-                else
-                {
-                    b->dqcoeff[0] = b->qcoeff[0] * xd->dequant_y2[0];
-                    vp8_short_inv_walsh4x4_1(&b->dqcoeff[0],
-                        xd->qcoeff);
-                    memset(b->qcoeff, 0, 2 * sizeof(b->qcoeff[0]));
-                }
-
-                /* override the dc dequant constant in order to preserve the
-                 * dc components
-                 */
-                DQC = xd->dequant_y1_dc;
-            }
-
-            vp8_dequant_idct_add_y_block
-                            (xd->qcoeff, DQC,
-                             xd->dst.y_buffer,
-                             xd->dst.y_stride, xd->eobs);
-        }
-
-        vp8_dequant_idct_add_uv_block
-                        (xd->qcoeff+16*16, xd->dequant_uv,
-                         xd->dst.u_buffer, xd->dst.v_buffer,
-                         xd->dst.uv_stride, xd->eobs+16);
-    }
-}
-
-static void mt_decode_mb_rows(VP8D_COMP *pbi, MACROBLOCKD *xd, int start_mb_row)
-{
-    const int *last_row_current_mb_col;
-    int *current_mb_col;
-    int mb_row;
-    VP8_COMMON *pc = &pbi->common;
-    const int nsync = pbi->sync_range;
-    const int first_row_no_sync_above = pc->mb_cols + nsync;
-    int num_part = 1 << pbi->common.multi_token_partition;
-    int last_mb_row = start_mb_row;
-
-    YV12_BUFFER_CONFIG *yv12_fb_new = pbi->dec_fb_ref[INTRA_FRAME];
-    YV12_BUFFER_CONFIG *yv12_fb_lst = pbi->dec_fb_ref[LAST_FRAME];
-
-    int recon_y_stride = yv12_fb_new->y_stride;
-    int recon_uv_stride = yv12_fb_new->uv_stride;
-
-    unsigned char *ref_buffer[MAX_REF_FRAMES][3];
-    unsigned char *dst_buffer[3];
-    int i;
-    int ref_fb_corrupted[MAX_REF_FRAMES];
-
-    ref_fb_corrupted[INTRA_FRAME] = 0;
-
-    for(i = 1; i < MAX_REF_FRAMES; i++)
-    {
-        YV12_BUFFER_CONFIG *this_fb = pbi->dec_fb_ref[i];
-
-        ref_buffer[i][0] = this_fb->y_buffer;
-        ref_buffer[i][1] = this_fb->u_buffer;
-        ref_buffer[i][2] = this_fb->v_buffer;
-
-        ref_fb_corrupted[i] = this_fb->corrupted;
-    }
-
-    dst_buffer[0] = yv12_fb_new->y_buffer;
-    dst_buffer[1] = yv12_fb_new->u_buffer;
-    dst_buffer[2] = yv12_fb_new->v_buffer;
-
-    xd->up_available = (start_mb_row != 0);
-
-    xd->mode_info_context = pc->mi + pc->mode_info_stride * start_mb_row;
-    xd->mode_info_stride = pc->mode_info_stride;
-
-    for (mb_row = start_mb_row; mb_row < pc->mb_rows; mb_row += (pbi->decoding_thread_count + 1))
-    {
-       int recon_yoffset, recon_uvoffset;
-       int mb_col;
-       int filter_level;
-       loop_filter_info_n *lfi_n = &pc->lf_info;
-
-       /* save last row processed by this thread */
-       last_mb_row = mb_row;
-       /* select bool coder for current partition */
-       xd->current_bc =  &pbi->mbc[mb_row%num_part];
-
-       if (mb_row > 0)
-           last_row_current_mb_col = &pbi->mt_current_mb_col[mb_row -1];
-       else
-           last_row_current_mb_col = &first_row_no_sync_above;
-
-       current_mb_col = &pbi->mt_current_mb_col[mb_row];
-
-       recon_yoffset = mb_row * recon_y_stride * 16;
-       recon_uvoffset = mb_row * recon_uv_stride * 8;
-
-       /* reset contexts */
-       xd->above_context = pc->above_context;
-       memset(xd->left_context, 0, sizeof(ENTROPY_CONTEXT_PLANES));
-
-       xd->left_available = 0;
-
-       xd->mb_to_top_edge = -((mb_row * 16)) << 3;
-       xd->mb_to_bottom_edge = ((pc->mb_rows - 1 - mb_row) * 16) << 3;
-
-       if (pbi->common.filter_level)
-       {
-          xd->recon_above[0] = pbi->mt_yabove_row[mb_row] + 0*16 +32;
-          xd->recon_above[1] = pbi->mt_uabove_row[mb_row] + 0*8 +16;
-          xd->recon_above[2] = pbi->mt_vabove_row[mb_row] + 0*8 +16;
-
-          xd->recon_left[0] = pbi->mt_yleft_col[mb_row];
-          xd->recon_left[1] = pbi->mt_uleft_col[mb_row];
-          xd->recon_left[2] = pbi->mt_vleft_col[mb_row];
-
-          /* TODO: move to outside row loop */
-          xd->recon_left_stride[0] = 1;
-          xd->recon_left_stride[1] = 1;
-       }
-       else
-       {
-          xd->recon_above[0] = dst_buffer[0] + recon_yoffset;
-          xd->recon_above[1] = dst_buffer[1] + recon_uvoffset;
-          xd->recon_above[2] = dst_buffer[2] + recon_uvoffset;
-
-          xd->recon_left[0] = xd->recon_above[0] - 1;
-          xd->recon_left[1] = xd->recon_above[1] - 1;
-          xd->recon_left[2] = xd->recon_above[2] - 1;
-
-          xd->recon_above[0] -= xd->dst.y_stride;
-          xd->recon_above[1] -= xd->dst.uv_stride;
-          xd->recon_above[2] -= xd->dst.uv_stride;
-
-          /* TODO: move to outside row loop */
-          xd->recon_left_stride[0] = xd->dst.y_stride;
-          xd->recon_left_stride[1] = xd->dst.uv_stride;
-
-          setup_intra_recon_left(xd->recon_left[0], xd->recon_left[1],
-                                 xd->recon_left[2], xd->dst.y_stride,
-                                 xd->dst.uv_stride);
-       }
-
-       for (mb_col = 0; mb_col < pc->mb_cols; mb_col++) {
-           if (((mb_col - 1) % nsync) == 0) {
-               pthread_mutex_t *mutex = &pbi->pmutex[mb_row];
-               protected_write(mutex, current_mb_col, mb_col - 1);
-           }
-
-           if (mb_row && !(mb_col & (nsync - 1))) {
-               pthread_mutex_t *mutex = &pbi->pmutex[mb_row-1];
-               sync_read(mutex, mb_col, last_row_current_mb_col, nsync);
-           }
-
-           /* Distance of MB to the various image edges.
-            * These are specified to 8th pel as they are always
-            * compared to values that are in 1/8th pel units.
-            */
-           xd->mb_to_left_edge = -((mb_col * 16) << 3);
-           xd->mb_to_right_edge = ((pc->mb_cols - 1 - mb_col) * 16) << 3;
-
-    #if CONFIG_ERROR_CONCEALMENT
-           {
-               int corrupt_residual =
-                           (!pbi->independent_partitions &&
-                           pbi->frame_corrupt_residual) ||
-                           vp8dx_bool_error(xd->current_bc);
-               if (pbi->ec_active &&
-                   (xd->mode_info_context->mbmi.ref_frame ==
-                                                    INTRA_FRAME) &&
-                   corrupt_residual)
-               {
-                   /* We have an intra block with corrupt
-                    * coefficients, better to conceal with an inter
-                    * block.
-                    * Interpolate MVs from neighboring MBs
-                    *
-                    * Note that for the first mb with corrupt
-                    * residual in a frame, we might not discover
-                    * that before decoding the residual. That
-                    * happens after this check, and therefore no
-                    * inter concealment will be done.
-                    */
-                   vp8_interpolate_motion(xd,
-                                          mb_row, mb_col,
-                                          pc->mb_rows, pc->mb_cols,
-                                          pc->mode_info_stride);
-               }
-           }
-    #endif
-
-
-           xd->dst.y_buffer = dst_buffer[0] + recon_yoffset;
-           xd->dst.u_buffer = dst_buffer[1] + recon_uvoffset;
-           xd->dst.v_buffer = dst_buffer[2] + recon_uvoffset;
-
-           xd->pre.y_buffer = ref_buffer[xd->mode_info_context->mbmi.ref_frame][0] + recon_yoffset;
-           xd->pre.u_buffer = ref_buffer[xd->mode_info_context->mbmi.ref_frame][1] + recon_uvoffset;
-           xd->pre.v_buffer = ref_buffer[xd->mode_info_context->mbmi.ref_frame][2] + recon_uvoffset;
-
-           /* propagate errors from reference frames */
-           xd->corrupted |= ref_fb_corrupted[xd->mode_info_context->mbmi.ref_frame];
-
-           mt_decode_macroblock(pbi, xd, 0);
-
-           xd->left_available = 1;
-
-           /* check if the boolean decoder has suffered an error */
-           xd->corrupted |= vp8dx_bool_error(xd->current_bc);
-
-           xd->recon_above[0] += 16;
-           xd->recon_above[1] += 8;
-           xd->recon_above[2] += 8;
-
-           if (!pbi->common.filter_level)
-           {
-              xd->recon_left[0] += 16;
-              xd->recon_left[1] += 8;
-              xd->recon_left[2] += 8;
-           }
-
-           if (pbi->common.filter_level)
-           {
-               int skip_lf = (xd->mode_info_context->mbmi.mode != B_PRED &&
-                               xd->mode_info_context->mbmi.mode != SPLITMV &&
-                               xd->mode_info_context->mbmi.mb_skip_coeff);
-
-               const int mode_index = lfi_n->mode_lf_lut[xd->mode_info_context->mbmi.mode];
-               const int seg = xd->mode_info_context->mbmi.segment_id;
-               const int ref_frame = xd->mode_info_context->mbmi.ref_frame;
-
-               filter_level = lfi_n->lvl[seg][ref_frame][mode_index];
-
-               if( mb_row != pc->mb_rows-1 )
-               {
-                   /* Save decoded MB last row data for next-row decoding */
-                   memcpy((pbi->mt_yabove_row[mb_row + 1] + 32 + mb_col*16), (xd->dst.y_buffer + 15 * recon_y_stride), 16);
-                   memcpy((pbi->mt_uabove_row[mb_row + 1] + 16 + mb_col*8), (xd->dst.u_buffer + 7 * recon_uv_stride), 8);
-                   memcpy((pbi->mt_vabove_row[mb_row + 1] + 16 + mb_col*8), (xd->dst.v_buffer + 7 * recon_uv_stride), 8);
-               }
-
-               /* save left_col for next MB decoding */
-               if(mb_col != pc->mb_cols-1)
-               {
-                   MODE_INFO *next = xd->mode_info_context +1;
-
-                   if (next->mbmi.ref_frame == INTRA_FRAME)
-                   {
-                       for (i = 0; i < 16; i++)
-                           pbi->mt_yleft_col[mb_row][i] = xd->dst.y_buffer [i* recon_y_stride + 15];
-                       for (i = 0; i < 8; i++)
-                       {
-                           pbi->mt_uleft_col[mb_row][i] = xd->dst.u_buffer [i* recon_uv_stride + 7];
-                           pbi->mt_vleft_col[mb_row][i] = xd->dst.v_buffer [i* recon_uv_stride + 7];
-                       }
-                   }
-               }
-
-               /* loopfilter on this macroblock. */
-               if (filter_level)
-               {
-                   if(pc->filter_type == NORMAL_LOOPFILTER)
-                   {
-                       loop_filter_info lfi;
-                       FRAME_TYPE frame_type = pc->frame_type;
-                       const int hev_index = lfi_n->hev_thr_lut[frame_type][filter_level];
-                       lfi.mblim = lfi_n->mblim[filter_level];
-                       lfi.blim = lfi_n->blim[filter_level];
-                       lfi.lim = lfi_n->lim[filter_level];
-                       lfi.hev_thr = lfi_n->hev_thr[hev_index];
-
-                       if (mb_col > 0)
-                           vp8_loop_filter_mbv
-                           (xd->dst.y_buffer, xd->dst.u_buffer, xd->dst.v_buffer, recon_y_stride, recon_uv_stride, &lfi);
-
-                       if (!skip_lf)
-                           vp8_loop_filter_bv
-                           (xd->dst.y_buffer, xd->dst.u_buffer, xd->dst.v_buffer, recon_y_stride, recon_uv_stride, &lfi);
-
-                       /* don't apply across umv border */
-                       if (mb_row > 0)
-                           vp8_loop_filter_mbh
-                           (xd->dst.y_buffer, xd->dst.u_buffer, xd->dst.v_buffer, recon_y_stride, recon_uv_stride, &lfi);
-
-                       if (!skip_lf)
-                           vp8_loop_filter_bh
-                           (xd->dst.y_buffer, xd->dst.u_buffer, xd->dst.v_buffer,  recon_y_stride, recon_uv_stride, &lfi);
-                   }
-                   else
-                   {
-                       if (mb_col > 0)
-                           vp8_loop_filter_simple_mbv
-                           (xd->dst.y_buffer, recon_y_stride, lfi_n->mblim[filter_level]);
-
-                       if (!skip_lf)
-                           vp8_loop_filter_simple_bv
-                           (xd->dst.y_buffer, recon_y_stride, lfi_n->blim[filter_level]);
-
-                       /* don't apply across umv border */
-                       if (mb_row > 0)
-                           vp8_loop_filter_simple_mbh
-                           (xd->dst.y_buffer, recon_y_stride, lfi_n->mblim[filter_level]);
-
-                       if (!skip_lf)
-                           vp8_loop_filter_simple_bh
-                           (xd->dst.y_buffer, recon_y_stride, lfi_n->blim[filter_level]);
-                   }
-               }
-
-           }
-
-           recon_yoffset += 16;
-           recon_uvoffset += 8;
-
-           ++xd->mode_info_context;  /* next mb */
-
-           xd->above_context++;
-       }
-
-       /* adjust to the next row of mbs */
-       if (pbi->common.filter_level)
-       {
-           if(mb_row != pc->mb_rows-1)
-           {
-               int lasty = yv12_fb_lst->y_width + VP8BORDERINPIXELS;
-               int lastuv = (yv12_fb_lst->y_width>>1) + (VP8BORDERINPIXELS>>1);
-
-               for (i = 0; i < 4; i++)
-               {
-                   pbi->mt_yabove_row[mb_row +1][lasty + i] = pbi->mt_yabove_row[mb_row +1][lasty -1];
-                   pbi->mt_uabove_row[mb_row +1][lastuv + i] = pbi->mt_uabove_row[mb_row +1][lastuv -1];
-                   pbi->mt_vabove_row[mb_row +1][lastuv + i] = pbi->mt_vabove_row[mb_row +1][lastuv -1];
-               }
-           }
-       }
-       else
-           vp8_extend_mb_row(yv12_fb_new, xd->dst.y_buffer + 16,
-                             xd->dst.u_buffer + 8, xd->dst.v_buffer + 8);
-
-       /* last MB of row is ready just after extension is done */
-       protected_write(&pbi->pmutex[mb_row], current_mb_col, mb_col + nsync);
-
-       ++xd->mode_info_context;      /* skip prediction column */
-       xd->up_available = 1;
-
-       /* since we have multithread */
-       xd->mode_info_context += xd->mode_info_stride * pbi->decoding_thread_count;
-    }
-
-    /* signal end of frame decoding if this thread processed the last mb_row */
-    if (last_mb_row == (pc->mb_rows - 1))
-        sem_post(&pbi->h_event_end_decoding);
-
-}
-
-
-static THREAD_FUNCTION thread_decoding_proc(void *p_data)
-{
-    int ithread = ((DECODETHREAD_DATA *)p_data)->ithread;
-    VP8D_COMP *pbi = (VP8D_COMP *)(((DECODETHREAD_DATA *)p_data)->ptr1);
-    MB_ROW_DEC *mbrd = (MB_ROW_DEC *)(((DECODETHREAD_DATA *)p_data)->ptr2);
-    ENTROPY_CONTEXT_PLANES mb_row_left_context;
-
-    while (1)
-    {
-        if (protected_read(&pbi->mt_mutex, &pbi->b_multithreaded_rd) == 0)
-            break;
-
-        if (sem_wait(&pbi->h_event_start_decoding[ithread]) == 0)
-        {
-            if (protected_read(&pbi->mt_mutex, &pbi->b_multithreaded_rd) == 0)
-                break;
-            else
-            {
-                MACROBLOCKD *xd = &mbrd->mbd;
-                xd->left_context = &mb_row_left_context;
-
-                mt_decode_mb_rows(pbi, xd, ithread+1);
-            }
-        }
-    }
-
-    return 0 ;
-}
-
-
-void vp8_decoder_create_threads(VP8D_COMP *pbi)
-{
-    int core_count = 0;
-    unsigned int ithread;
-
-    pbi->b_multithreaded_rd = 0;
-    pbi->allocated_decoding_thread_count = 0;
-    pthread_mutex_init(&pbi->mt_mutex, NULL);
-
-    /* limit decoding threads to the max number of token partitions */
-    core_count = (pbi->max_threads > 8) ? 8 : pbi->max_threads;
-
-    /* limit decoding threads to the available cores */
-    if (core_count > pbi->common.processor_core_count)
-        core_count = pbi->common.processor_core_count;
-
-    if (core_count > 1)
-    {
-        pbi->b_multithreaded_rd = 1;
-        pbi->decoding_thread_count = core_count - 1;
-
-        CALLOC_ARRAY(pbi->h_decoding_thread, pbi->decoding_thread_count);
-        CALLOC_ARRAY(pbi->h_event_start_decoding, pbi->decoding_thread_count);
-        CALLOC_ARRAY_ALIGNED(pbi->mb_row_di, pbi->decoding_thread_count, 32);
-        CALLOC_ARRAY(pbi->de_thread_data, pbi->decoding_thread_count);
-
-        for (ithread = 0; ithread < pbi->decoding_thread_count; ithread++)
-        {
-            sem_init(&pbi->h_event_start_decoding[ithread], 0, 0);
-
-            vp8_setup_block_dptrs(&pbi->mb_row_di[ithread].mbd);
-
-            pbi->de_thread_data[ithread].ithread  = ithread;
-            pbi->de_thread_data[ithread].ptr1     = (void *)pbi;
-            pbi->de_thread_data[ithread].ptr2     = (void *) &pbi->mb_row_di[ithread];
-
-            pthread_create(&pbi->h_decoding_thread[ithread], 0, thread_decoding_proc, (&pbi->de_thread_data[ithread]));
-        }
-
-        sem_init(&pbi->h_event_end_decoding, 0, 0);
-
-        pbi->allocated_decoding_thread_count = pbi->decoding_thread_count;
-    }
-}
-
-
-void vp8mt_de_alloc_temp_buffers(VP8D_COMP *pbi, int mb_rows)
-{
-    int i;
-
-    if (protected_read(&pbi->mt_mutex, &pbi->b_multithreaded_rd))
-    {
-        /* De-allocate mutex */
-        if (pbi->pmutex != NULL) {
-            for (i = 0; i < mb_rows; i++) {
-                pthread_mutex_destroy(&pbi->pmutex[i]);
-            }
-            vpx_free(pbi->pmutex);
-            pbi->pmutex = NULL;
-        }
-
-            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++)
-            {
-                    vpx_free(pbi->mt_yabove_row[i]);
-                    pbi->mt_yabove_row[i] = NULL ;
-            }
-            vpx_free(pbi->mt_yabove_row);
-            pbi->mt_yabove_row = NULL ;
-        }
-
-        if (pbi->mt_uabove_row)
-        {
-            for (i=0; i< mb_rows; 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 ;
-        }
-
-        if (pbi->mt_vabove_row)
-        {
-            for (i=0; i< mb_rows; 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 ;
-        }
-
-        /* Free left_col buffers. */
-        if (pbi->mt_yleft_col)
-        {
-            for (i=0; i< mb_rows; 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 ;
-        }
-
-        if (pbi->mt_uleft_col)
-        {
-            for (i=0; i< mb_rows; 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 ;
-        }
-
-        if (pbi->mt_vleft_col)
-        {
-            for (i=0; i< mb_rows; 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 ;
-        }
-    }
-}
-
-
-void vp8mt_alloc_temp_buffers(VP8D_COMP *pbi, int width, int prev_mb_rows)
-{
-    VP8_COMMON *const pc = & pbi->common;
-    int i;
-    int uv_width;
-
-    if (protected_read(&pbi->mt_mutex, &pbi->b_multithreaded_rd))
-    {
-        vp8mt_de_alloc_temp_buffers(pbi, prev_mb_rows);
-
-        /* our internal buffers are always multiples of 16 */
-        if ((width & 0xf) != 0)
-            width += 16 - (width & 0xf);
-
-        if (width < 640) pbi->sync_range = 1;
-        else if (width <= 1280) pbi->sync_range = 8;
-        else if (width <= 2560) pbi->sync_range =16;
-        else pbi->sync_range = 32;
-
-        uv_width = width >>1;
-
-        /* Allocate mutex */
-        CHECK_MEM_ERROR(pbi->pmutex, vpx_malloc(sizeof(*pbi->pmutex) *
-                                                pc->mb_rows));
-        if (pbi->pmutex) {
-            for (i = 0; i < pc->mb_rows; i++) {
-                pthread_mutex_init(&pbi->pmutex[i], NULL);
-            }
-        }
-
-        /* Allocate an int for each mb row. */
-        CALLOC_ARRAY(pbi->mt_current_mb_col, pc->mb_rows);
-
-        /* Allocate memory for above_row buffers. */
-        CALLOC_ARRAY(pbi->mt_yabove_row, pc->mb_rows);
-        for (i = 0; i < pc->mb_rows; i++)
-            CHECK_MEM_ERROR(pbi->mt_yabove_row[i], vpx_memalign(16,sizeof(unsigned char) * (width + (VP8BORDERINPIXELS<<1))));
-
-        CALLOC_ARRAY(pbi->mt_uabove_row, pc->mb_rows);
-        for (i = 0; i < pc->mb_rows; i++)
-            CHECK_MEM_ERROR(pbi->mt_uabove_row[i], vpx_memalign(16,sizeof(unsigned char) * (uv_width + VP8BORDERINPIXELS)));
-
-        CALLOC_ARRAY(pbi->mt_vabove_row, pc->mb_rows);
-        for (i = 0; i < pc->mb_rows; i++)
-            CHECK_MEM_ERROR(pbi->mt_vabove_row[i], vpx_memalign(16,sizeof(unsigned char) * (uv_width + VP8BORDERINPIXELS)));
-
-        /* Allocate memory for left_col buffers. */
-        CALLOC_ARRAY(pbi->mt_yleft_col, pc->mb_rows);
-        for (i = 0; i < pc->mb_rows; i++)
-            CHECK_MEM_ERROR(pbi->mt_yleft_col[i], vpx_calloc(sizeof(unsigned char) * 16, 1));
-
-        CALLOC_ARRAY(pbi->mt_uleft_col, pc->mb_rows);
-        for (i = 0; i < pc->mb_rows; i++)
-            CHECK_MEM_ERROR(pbi->mt_uleft_col[i], vpx_calloc(sizeof(unsigned char) * 8, 1));
-
-        CALLOC_ARRAY(pbi->mt_vleft_col, pc->mb_rows);
-        for (i = 0; i < pc->mb_rows; i++)
-            CHECK_MEM_ERROR(pbi->mt_vleft_col[i], vpx_calloc(sizeof(unsigned char) * 8, 1));
-    }
-}
-
-
-void vp8_decoder_remove_threads(VP8D_COMP *pbi)
-{
-    /* shutdown MB Decoding thread; */
-    if (protected_read(&pbi->mt_mutex, &pbi->b_multithreaded_rd))
-    {
-        int i;
-
-        protected_write(&pbi->mt_mutex, &pbi->b_multithreaded_rd, 0);
-
-        /* allow all threads to exit */
-        for (i = 0; i < pbi->allocated_decoding_thread_count; i++)
-        {
-            sem_post(&pbi->h_event_start_decoding[i]);
-            pthread_join(pbi->h_decoding_thread[i], NULL);
-        }
-
-        for (i = 0; i < pbi->allocated_decoding_thread_count; i++)
-        {
-            sem_destroy(&pbi->h_event_start_decoding[i]);
-        }
-
-        sem_destroy(&pbi->h_event_end_decoding);
-
-            vpx_free(pbi->h_decoding_thread);
-            pbi->h_decoding_thread = NULL;
-
-            vpx_free(pbi->h_event_start_decoding);
-            pbi->h_event_start_decoding = NULL;
-
-            vpx_free(pbi->mb_row_di);
-            pbi->mb_row_di = NULL ;
-
-            vpx_free(pbi->de_thread_data);
-            pbi->de_thread_data = NULL;
-    }
-    pthread_mutex_destroy(&pbi->mt_mutex);
-}
-
-void vp8mt_decode_mb_rows( VP8D_COMP *pbi, MACROBLOCKD *xd)
-{
-    VP8_COMMON *pc = &pbi->common;
-    unsigned int i;
-    int j;
-
-    int filter_level = pc->filter_level;
-    YV12_BUFFER_CONFIG *yv12_fb_new = pbi->dec_fb_ref[INTRA_FRAME];
-
-    if (filter_level)
-    {
-        /* Set above_row buffer to 127 for decoding first MB row */
-        memset(pbi->mt_yabove_row[0] + VP8BORDERINPIXELS-1, 127, yv12_fb_new->y_width + 5);
-        memset(pbi->mt_uabove_row[0] + (VP8BORDERINPIXELS>>1)-1, 127, (yv12_fb_new->y_width>>1) +5);
-        memset(pbi->mt_vabove_row[0] + (VP8BORDERINPIXELS>>1)-1, 127, (yv12_fb_new->y_width>>1) +5);
-
-        for (j=1; j<pc->mb_rows; j++)
-        {
-            memset(pbi->mt_yabove_row[j] + VP8BORDERINPIXELS-1, (unsigned char)129, 1);
-            memset(pbi->mt_uabove_row[j] + (VP8BORDERINPIXELS>>1)-1, (unsigned char)129, 1);
-            memset(pbi->mt_vabove_row[j] + (VP8BORDERINPIXELS>>1)-1, (unsigned char)129, 1);
-        }
-
-        /* Set left_col to 129 initially */
-        for (j=0; j<pc->mb_rows; j++)
-        {
-            memset(pbi->mt_yleft_col[j], (unsigned char)129, 16);
-            memset(pbi->mt_uleft_col[j], (unsigned char)129, 8);
-            memset(pbi->mt_vleft_col[j], (unsigned char)129, 8);
-        }
-
-        /* Initialize the loop filter for this frame. */
-        vp8_loop_filter_frame_init(pc, &pbi->mb, filter_level);
-    }
-    else
-        vp8_setup_intra_recon_top_line(yv12_fb_new);
-
-    setup_decoding_thread_data(pbi, xd, pbi->mb_row_di, pbi->decoding_thread_count);
-
-    for (i = 0; i < pbi->decoding_thread_count; i++)
-        sem_post(&pbi->h_event_start_decoding[i]);
-
-    mt_decode_mb_rows(pbi, xd, 0);
-
-    sem_wait(&pbi->h_event_end_decoding);   /* add back for each frame */
-}
diff --git a/vp8/decoder/treereader.h b/vp8/decoder/treereader.h
deleted file mode 100644 (file)
index f7d23c3..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#ifndef VP8_DECODER_TREEREADER_H_
-#define VP8_DECODER_TREEREADER_H_
-
-#include "./vpx_config.h"
-#include "vp8/common/treecoder.h"
-#include "dboolhuff.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef BOOL_DECODER vp8_reader;
-
-#define vp8_read vp8dx_decode_bool
-#define vp8_read_literal vp8_decode_value
-#define vp8_read_bit(R) vp8_read(R, vp8_prob_half)
-
-
-/* Intent of tree data structure is to make decoding trivial. */
-
-static INLINE int vp8_treed_read(
-    vp8_reader *const r,        /* !!! must return a 0 or 1 !!! */
-    vp8_tree t,
-    const vp8_prob *const p
-)
-{
-    register vp8_tree_index i = 0;
-
-    while ((i = t[ i + vp8_read(r, p[i>>1])]) > 0) ;
-
-    return -i;
-}
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP8_DECODER_TREEREADER_H_
diff --git a/vp8/encoder/arm/armv6/vp8_short_fdct4x4_armv6.asm b/vp8/encoder/arm/armv6/vp8_short_fdct4x4_armv6.asm
deleted file mode 100644 (file)
index 8034c1d..0000000
+++ /dev/null
@@ -1,262 +0,0 @@
-;
-;  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_short_fdct4x4_armv6|
-
-    ARM
-    REQUIRE8
-    PRESERVE8
-
-    AREA    |.text|, CODE, READONLY
-; void vp8_short_fdct4x4_c(short *input, short *output, int pitch)
-|vp8_short_fdct4x4_armv6| PROC
-
-    stmfd       sp!, {r4 - r12, lr}
-
-    ; PART 1
-
-    ; coeffs 0-3
-    ldrd        r4, r5, [r0]        ; [i1 | i0] [i3 | i2]
-
-    ldr         r10, c7500
-    ldr         r11, c14500
-    ldr         r12, c0x22a453a0    ; [2217*4 | 5352*4]
-    ldr         lr, c0x00080008
-    ror         r5, r5, #16         ; [i2 | i3]
-
-    qadd16      r6, r4, r5          ; [i1+i2 | i0+i3] = [b1 | a1] without shift
-    qsub16      r7, r4, r5          ; [i1-i2 | i0-i3] = [c1 | d1] without shift
-
-    add         r0, r0, r2          ; update input pointer
-
-    qadd16      r7, r7, r7          ; 2*[c1|d1] --> we can use smlad and smlsd
-                                    ; with 2217*4 and 5352*4 without losing the
-                                    ; sign bit (overflow)
-
-    smuad       r4, r6, lr          ; o0 = (i1+i2)*8 + (i0+i3)*8
-    smusd       r5, r6, lr          ; o2 = (i1+i2)*8 - (i0+i3)*8
-
-    smlad       r6, r7, r12, r11    ; o1 = (c1 * 2217 + d1 * 5352 +  14500)
-    smlsdx      r7, r7, r12, r10    ; o3 = (d1 * 2217 - c1 * 5352 +   7500)
-
-    ldrd        r8, r9, [r0]        ; [i5 | i4] [i7 | i6]
-
-    pkhbt       r3, r4, r6, lsl #4  ; [o1 | o0], keep in register for PART 2
-    pkhbt       r6, r5, r7, lsl #4  ; [o3 | o2]
-
-    str         r6, [r1, #4]
-
-    ; coeffs 4-7
-    ror         r9, r9, #16         ; [i6 | i7]
-
-    qadd16      r6, r8, r9          ; [i5+i6 | i4+i7] = [b1 | a1] without shift
-    qsub16      r7, r8, r9          ; [i5-i6 | i4-i7] = [c1 | d1] without shift
-
-    add         r0, r0, r2          ; update input pointer
-
-    qadd16      r7, r7, r7          ; 2x[c1|d1] --> we can use smlad and smlsd
-                                    ; with 2217*4 and 5352*4 without losing the
-                                    ; sign bit (overflow)
-
-    smuad       r9, r6, lr          ; o4 = (i5+i6)*8 + (i4+i7)*8
-    smusd       r8, r6, lr          ; o6 = (i5+i6)*8 - (i4+i7)*8
-
-    smlad       r6, r7, r12, r11    ; o5 = (c1 * 2217 + d1 * 5352 +  14500)
-    smlsdx      r7, r7, r12, r10    ; o7 = (d1 * 2217 - c1 * 5352 +   7500)
-
-    ldrd        r4, r5, [r0]        ; [i9 | i8] [i11 | i10]
-
-    pkhbt       r9, r9, r6, lsl #4  ; [o5 | o4], keep in register for PART 2
-    pkhbt       r6, r8, r7, lsl #4  ; [o7 | o6]
-
-    str         r6, [r1, #12]
-
-    ; coeffs 8-11
-    ror         r5, r5, #16         ; [i10 | i11]
-
-    qadd16      r6, r4, r5          ; [i9+i10 | i8+i11]=[b1 | a1] without shift
-    qsub16      r7, r4, r5          ; [i9-i10 | i8-i11]=[c1 | d1] without shift
-
-    add         r0, r0, r2          ; update input pointer
-
-    qadd16      r7, r7, r7          ; 2x[c1|d1] --> we can use smlad and smlsd
-                                    ; with 2217*4 and 5352*4 without losing the
-                                    ; sign bit (overflow)
-
-    smuad       r2, r6, lr          ; o8 = (i9+i10)*8 + (i8+i11)*8
-    smusd       r8, r6, lr          ; o10 = (i9+i10)*8 - (i8+i11)*8
-
-    smlad       r6, r7, r12, r11    ; o9 = (c1 * 2217 + d1 * 5352 +  14500)
-    smlsdx      r7, r7, r12, r10    ; o11 = (d1 * 2217 - c1 * 5352 +   7500)
-
-    ldrd        r4, r5, [r0]        ; [i13 | i12] [i15 | i14]
-
-    pkhbt       r2, r2, r6, lsl #4  ; [o9 | o8], keep in register for PART 2
-    pkhbt       r6, r8, r7, lsl #4  ; [o11 | o10]
-
-    str         r6, [r1, #20]
-
-    ; coeffs 12-15
-    ror         r5, r5, #16         ; [i14 | i15]
-
-    qadd16      r6, r4, r5          ; [i13+i14 | i12+i15]=[b1|a1] without shift
-    qsub16      r7, r4, r5          ; [i13-i14 | i12-i15]=[c1|d1] without shift
-
-    qadd16      r7, r7, r7          ; 2x[c1|d1] --> we can use smlad and smlsd
-                                    ; with 2217*4 and 5352*4 without losing the
-                                    ; sign bit (overflow)
-
-    smuad       r4, r6, lr          ; o12 = (i13+i14)*8 + (i12+i15)*8
-    smusd       r5, r6, lr          ; o14 = (i13+i14)*8 - (i12+i15)*8
-
-    smlad       r6, r7, r12, r11    ; o13 = (c1 * 2217 + d1 * 5352 +  14500)
-    smlsdx      r7, r7, r12, r10    ; o15 = (d1 * 2217 - c1 * 5352 +   7500)
-
-    pkhbt       r0, r4, r6, lsl #4  ; [o13 | o12], keep in register for PART 2
-    pkhbt       r6, r5, r7, lsl #4  ; [o15 | o14]
-
-    str         r6, [r1, #28]
-
-
-    ; PART 2 -------------------------------------------------
-    ldr         r11, c12000
-    ldr         r10, c51000
-    ldr         lr, c0x00070007
-
-    qadd16      r4, r3, r0          ; a1 = [i1+i13 | i0+i12]
-    qadd16      r5, r9, r2          ; b1 = [i5+i9  |  i4+i8]
-    qsub16      r6, r9, r2          ; c1 = [i5-i9  |  i4-i8]
-    qsub16      r7, r3, r0          ; d1 = [i1-i13 | i0-i12]
-
-    qadd16      r4, r4, lr          ; a1 + 7
-
-    add         r0, r11, #0x10000   ; add (d!=0)
-
-    qadd16      r2, r4, r5          ; a1 + b1 + 7
-    qsub16      r3, r4, r5          ; a1 - b1 + 7
-
-    ldr         r12, c0x08a914e8    ; [2217 | 5352]
-
-    lsl         r8, r2, #16         ; prepare bottom halfword for scaling
-    asr         r2, r2, #4          ; scale top halfword
-    lsl         r9, r3, #16         ; prepare bottom halfword for scaling
-    asr         r3, r3, #4          ; scale top halfword
-    pkhtb       r4, r2, r8, asr #20 ; pack and scale bottom halfword
-    pkhtb       r5, r3, r9, asr #20 ; pack and scale bottom halfword
-
-    smulbt      r2, r6, r12         ; [ ------ | c1*2217]
-    str         r4, [r1, #0]        ; [     o1 |      o0]
-    smultt      r3, r6, r12         ; [c1*2217 | ------ ]
-    str         r5, [r1, #16]       ; [     o9 |      o8]
-
-    smlabb      r8, r7, r12, r2     ; [ ------ | d1*5352]
-    smlatb      r9, r7, r12, r3     ; [d1*5352 | ------ ]
-
-    smulbb      r2, r6, r12         ; [ ------ | c1*5352]
-    smultb      r3, r6, r12         ; [c1*5352 | ------ ]
-
-    lsls        r6, r7, #16         ; d1 != 0 ?
-    addeq       r8, r8, r11         ; c1_b*2217+d1_b*5352+12000 + (d==0)
-    addne       r8, r8, r0          ; c1_b*2217+d1_b*5352+12000 + (d!=0)
-    asrs        r6, r7, #16
-    addeq       r9, r9, r11         ; c1_t*2217+d1_t*5352+12000 + (d==0)
-    addne       r9, r9, r0          ; c1_t*2217+d1_t*5352+12000 + (d!=0)
-
-    smlabt      r4, r7, r12, r10    ; [ ------ | d1*2217] + 51000
-    smlatt      r5, r7, r12, r10    ; [d1*2217 | ------ ] + 51000
-
-    pkhtb       r9, r9, r8, asr #16
-
-    sub         r4, r4, r2
-    sub         r5, r5, r3
-
-    ldr         r3, [r1, #4]        ; [i3 | i2]
-
-    pkhtb       r5, r5, r4, asr #16 ; [o13|o12]
-
-    str         r9, [r1, #8]        ; [o5 | 04]
-
-    ldr         r9, [r1, #12]       ; [i7 | i6]
-    ldr         r8, [r1, #28]       ; [i15|i14]
-    ldr         r2, [r1, #20]       ; [i11|i10]
-    str         r5, [r1, #24]       ; [o13|o12]
-
-    qadd16      r4, r3, r8          ; a1 = [i3+i15 | i2+i14]
-    qadd16      r5, r9, r2          ; b1 = [i7+i11 | i6+i10]
-
-    qadd16      r4, r4, lr          ; a1 + 7
-
-    qsub16      r6, r9, r2          ; c1 = [i7-i11 | i6-i10]
-    qadd16      r2, r4, r5          ; a1 + b1 + 7
-    qsub16      r7, r3, r8          ; d1 = [i3-i15 | i2-i14]
-    qsub16      r3, r4, r5          ; a1 - b1 + 7
-
-    lsl         r8, r2, #16         ; prepare bottom halfword for scaling
-    asr         r2, r2, #4          ; scale top halfword
-    lsl         r9, r3, #16         ; prepare bottom halfword for scaling
-    asr         r3, r3, #4          ; scale top halfword
-    pkhtb       r4, r2, r8, asr #20 ; pack and scale bottom halfword
-    pkhtb       r5, r3, r9, asr #20 ; pack and scale bottom halfword
-
-    smulbt      r2, r6, r12         ; [ ------ | c1*2217]
-    str         r4, [r1, #4]        ; [     o3 |      o2]
-    smultt      r3, r6, r12         ; [c1*2217 | ------ ]
-    str         r5, [r1, #20]       ; [    o11 |     o10]
-
-    smlabb      r8, r7, r12, r2     ; [ ------ | d1*5352]
-    smlatb      r9, r7, r12, r3     ; [d1*5352 | ------ ]
-
-    smulbb      r2, r6, r12         ; [ ------ | c1*5352]
-    smultb      r3, r6, r12         ; [c1*5352 | ------ ]
-
-    lsls        r6, r7, #16         ; d1 != 0 ?
-    addeq       r8, r8, r11         ; c1_b*2217+d1_b*5352+12000 + (d==0)
-    addne       r8, r8, r0          ; c1_b*2217+d1_b*5352+12000 + (d!=0)
-
-    asrs        r6, r7, #16
-    addeq       r9, r9, r11         ; c1_t*2217+d1_t*5352+12000 + (d==0)
-    addne       r9, r9, r0          ; c1_t*2217+d1_t*5352+12000 + (d!=0)
-
-    smlabt      r4, r7, r12, r10    ; [ ------ | d1*2217] + 51000
-    smlatt      r5, r7, r12, r10    ; [d1*2217 | ------ ] + 51000
-
-    pkhtb       r9, r9, r8, asr #16
-
-    sub         r4, r4, r2
-    sub         r5, r5, r3
-
-    str         r9, [r1, #12]       ; [o7 | o6]
-    pkhtb       r5, r5, r4, asr #16 ; [o15|o14]
-
-    str         r5, [r1, #28]       ; [o15|o14]
-
-    ldmfd       sp!, {r4 - r12, pc}
-
-    ENDP
-
-; Used constants
-c7500
-    DCD     7500
-c14500
-    DCD     14500
-c0x22a453a0
-    DCD     0x22a453a0
-c0x00080008
-    DCD     0x00080008
-c12000
-    DCD     12000
-c51000
-    DCD     51000
-c0x00070007
-    DCD     0x00070007
-c0x08a914e8
-    DCD     0x08a914e8
-
-    END
diff --git a/vp8/encoder/arm/armv6/walsh_v6.asm b/vp8/encoder/arm/armv6/walsh_v6.asm
deleted file mode 100644 (file)
index 5eaf3f2..0000000
+++ /dev/null
@@ -1,212 +0,0 @@
-;
-;  Copyright (c) 2010 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_short_walsh4x4_armv6|
-
-    ARM
-    REQUIRE8
-    PRESERVE8
-
-    AREA    |.text|, CODE, READONLY  ; name this block of code
-
-;short vp8_short_walsh4x4_armv6(short *input, short *output, int pitch)
-; r0    short *input,
-; r1    short *output,
-; r2    int pitch
-|vp8_short_walsh4x4_armv6| PROC
-
-    stmdb       sp!, {r4 - r11, lr}
-
-    ldrd        r4, r5, [r0], r2
-    ldr         lr, c00040004
-    ldrd        r6, r7, [r0], r2
-
-    ; 0-3
-    qadd16      r3, r4, r5          ; [d1|a1] [1+3   |   0+2]
-    qsub16      r4, r4, r5          ; [c1|b1] [1-3   |   0-2]
-
-    ldrd        r8, r9, [r0], r2
-    ; 4-7
-    qadd16      r5, r6, r7          ; [d1|a1] [5+7   |   4+6]
-    qsub16      r6, r6, r7          ; [c1|b1] [5-7   |   4-6]
-
-    ldrd        r10, r11, [r0]
-    ; 8-11
-    qadd16      r7, r8, r9          ; [d1|a1] [9+11  |  8+10]
-    qsub16      r8, r8, r9          ; [c1|b1] [9-11  |  8-10]
-
-    ; 12-15
-    qadd16      r9, r10, r11        ; [d1|a1] [13+15 | 12+14]
-    qsub16      r10, r10, r11       ; [c1|b1] [13-15 | 12-14]
-
-
-    lsls        r2, r3, #16
-    smuad       r11, r3, lr         ; A0 = a1<<2 + d1<<2
-    addne       r11, r11, #1        ; A0 += (a1!=0)
-
-    lsls        r2, r7, #16
-    smuad       r12, r7, lr         ; C0 = a1<<2 + d1<<2
-    addne       r12, r12, #1        ; C0 += (a1!=0)
-
-    add         r0, r11, r12        ; a1_0 = A0 + C0
-    sub         r11, r11, r12       ; b1_0 = A0 - C0
-
-    lsls        r2, r5, #16
-    smuad       r12, r5, lr         ; B0 = a1<<2 + d1<<2
-    addne       r12, r12, #1        ; B0 += (a1!=0)
-
-    lsls        r2, r9, #16
-    smuad       r2, r9, lr          ; D0 = a1<<2 + d1<<2
-    addne       r2, r2, #1          ; D0 += (a1!=0)
-
-    add         lr, r12, r2         ; d1_0 = B0 + D0
-    sub         r12, r12, r2        ; c1_0 = B0 - D0
-
-    ; op[0,4,8,12]
-    adds        r2, r0, lr          ; a2 = a1_0 + d1_0
-    addmi       r2, r2, #1          ; += a2 < 0
-    add         r2, r2, #3          ; += 3
-    subs        r0, r0, lr          ; d2 = a1_0 - d1_0
-    mov         r2, r2, asr #3      ; >> 3
-    strh        r2, [r1]            ; op[0]
-
-    addmi       r0, r0, #1          ; += a2 < 0
-    add         r0, r0, #3          ; += 3
-    ldr         lr, c00040004
-    mov         r0, r0, asr #3      ; >> 3
-    strh        r0, [r1, #24]       ; op[12]
-
-    adds        r2, r11, r12        ; b2 = b1_0 + c1_0
-    addmi       r2, r2, #1          ; += a2 < 0
-    add         r2, r2, #3          ; += 3
-    subs        r0, r11, r12        ; c2 = b1_0 - c1_0
-    mov         r2, r2, asr #3      ; >> 3
-    strh        r2, [r1, #8]        ; op[4]
-
-    addmi       r0, r0, #1          ; += a2 < 0
-    add         r0, r0, #3          ; += 3
-    smusd       r3, r3, lr          ; A3 = a1<<2 - d1<<2
-    smusd       r7, r7, lr          ; C3 = a1<<2 - d1<<2
-    mov         r0, r0, asr #3      ; >> 3
-    strh        r0, [r1, #16]       ; op[8]
-
-
-    ; op[3,7,11,15]
-    add         r0, r3, r7          ; a1_3 = A3 + C3
-    sub         r3, r3, r7          ; b1_3 = A3 - C3
-
-    smusd       r5, r5, lr          ; B3 = a1<<2 - d1<<2
-    smusd       r9, r9, lr          ; D3 = a1<<2 - d1<<2
-    add         r7, r5, r9          ; d1_3 = B3 + D3
-    sub         r5, r5, r9          ; c1_3 = B3 - D3
-
-    adds        r2, r0, r7          ; a2 = a1_3 + d1_3
-    addmi       r2, r2, #1          ; += a2 < 0
-    add         r2, r2, #3          ; += 3
-    adds        r9, r3, r5          ; b2 = b1_3 + c1_3
-    mov         r2, r2, asr #3      ; >> 3
-    strh        r2, [r1, #6]        ; op[3]
-
-    addmi       r9, r9, #1          ; += a2 < 0
-    add         r9, r9, #3          ; += 3
-    subs        r2, r3, r5          ; c2 = b1_3 - c1_3
-    mov         r9, r9, asr #3      ; >> 3
-    strh        r9, [r1, #14]       ; op[7]
-
-    addmi       r2, r2, #1          ; += a2 < 0
-    add         r2, r2, #3          ; += 3
-    subs        r9, r0, r7          ; d2 = a1_3 - d1_3
-    mov         r2, r2, asr #3      ; >> 3
-    strh        r2, [r1, #22]       ; op[11]
-
-    addmi       r9, r9, #1          ; += a2 < 0
-    add         r9, r9, #3          ; += 3
-    smuad       r3, r4, lr          ; A1 = b1<<2 + c1<<2
-    smuad       r5, r8, lr          ; C1 = b1<<2 + c1<<2
-    mov         r9, r9, asr #3      ; >> 3
-    strh        r9, [r1, #30]       ; op[15]
-
-    ; op[1,5,9,13]
-    add         r0, r3, r5          ; a1_1 = A1 + C1
-    sub         r3, r3, r5          ; b1_1 = A1 - C1
-
-    smuad       r7, r6, lr          ; B1 = b1<<2 + c1<<2
-    smuad       r9, r10, lr         ; D1 = b1<<2 + c1<<2
-    add         r5, r7, r9          ; d1_1 = B1 + D1
-    sub         r7, r7, r9          ; c1_1 = B1 - D1
-
-    adds        r2, r0, r5          ; a2 = a1_1 + d1_1
-    addmi       r2, r2, #1          ; += a2 < 0
-    add         r2, r2, #3          ; += 3
-    adds        r9, r3, r7          ; b2 = b1_1 + c1_1
-    mov         r2, r2, asr #3      ; >> 3
-    strh        r2, [r1, #2]        ; op[1]
-
-    addmi       r9, r9, #1          ; += a2 < 0
-    add         r9, r9, #3          ; += 3
-    subs        r2, r3, r7          ; c2 = b1_1 - c1_1
-    mov         r9, r9, asr #3      ; >> 3
-    strh        r9, [r1, #10]       ; op[5]
-
-    addmi       r2, r2, #1          ; += a2 < 0
-    add         r2, r2, #3          ; += 3
-    subs        r9, r0, r5          ; d2 = a1_1 - d1_1
-    mov         r2, r2, asr #3      ; >> 3
-    strh        r2, [r1, #18]       ; op[9]
-
-    addmi       r9, r9, #1          ; += a2 < 0
-    add         r9, r9, #3          ; += 3
-    smusd       r4, r4, lr          ; A2 = b1<<2 - c1<<2
-    smusd       r8, r8, lr          ; C2 = b1<<2 - c1<<2
-    mov         r9, r9, asr #3      ; >> 3
-    strh        r9, [r1, #26]       ; op[13]
-
-
-    ; op[2,6,10,14]
-    add         r11, r4, r8         ; a1_2 = A2 + C2
-    sub         r12, r4, r8         ; b1_2 = A2 - C2
-
-    smusd       r6, r6, lr          ; B2 = b1<<2 - c1<<2
-    smusd       r10, r10, lr        ; D2 = b1<<2 - c1<<2
-    add         r4, r6, r10         ; d1_2 = B2 + D2
-    sub         r8, r6, r10         ; c1_2 = B2 - D2
-
-    adds        r2, r11, r4         ; a2 = a1_2 + d1_2
-    addmi       r2, r2, #1          ; += a2 < 0
-    add         r2, r2, #3          ; += 3
-    adds        r9, r12, r8         ; b2 = b1_2 + c1_2
-    mov         r2, r2, asr #3      ; >> 3
-    strh        r2, [r1, #4]        ; op[2]
-
-    addmi       r9, r9, #1          ; += a2 < 0
-    add         r9, r9, #3          ; += 3
-    subs        r2, r12, r8         ; c2 = b1_2 - c1_2
-    mov         r9, r9, asr #3      ; >> 3
-    strh        r9, [r1, #12]       ; op[6]
-
-    addmi       r2, r2, #1          ; += a2 < 0
-    add         r2, r2, #3          ; += 3
-    subs        r9, r11, r4         ; d2 = a1_2 - d1_2
-    mov         r2, r2, asr #3      ; >> 3
-    strh        r2, [r1, #20]       ; op[10]
-
-    addmi       r9, r9, #1          ; += a2 < 0
-    add         r9, r9, #3          ; += 3
-    mov         r9, r9, asr #3      ; >> 3
-    strh        r9, [r1, #28]       ; op[14]
-
-
-    ldmia       sp!, {r4 - r11, pc}
-    ENDP        ; |vp8_short_walsh4x4_armv6|
-
-c00040004
-    DCD         0x00040004
-
-    END
diff --git a/vp8/encoder/arm/dct_arm.c b/vp8/encoder/arm/dct_arm.c
deleted file mode 100644 (file)
index f71300d..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- *  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.
- */
-
-#include "vpx_config.h"
-#include "vp8_rtcd.h"
-
-#if HAVE_MEDIA
-
-void vp8_short_fdct8x4_armv6(short *input, short *output, int pitch)
-{
-    vp8_short_fdct4x4_armv6(input,   output,    pitch);
-    vp8_short_fdct4x4_armv6(input + 4, output + 16, pitch);
-}
-
-#endif /* HAVE_MEDIA */
diff --git a/vp8/encoder/arm/neon/denoising_neon.c b/vp8/encoder/arm/neon/denoising_neon.c
deleted file mode 100644 (file)
index 08be76e..0000000
+++ /dev/null
@@ -1,478 +0,0 @@
-/*
- *  Copyright (c) 2012 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.
- */
-
-#include <arm_neon.h>
-
-#include "vp8/encoder/denoising.h"
-#include "vpx_mem/vpx_mem.h"
-#include "./vp8_rtcd.h"
-
-/*
- * The filter function was modified to reduce the computational complexity.
- *
- * Step 1:
- *  Instead of applying tap coefficients for each pixel, we calculated the
- *  pixel adjustments vs. pixel diff value ahead of time.
- *     adjustment = filtered_value - current_raw
- *                = (filter_coefficient * diff + 128) >> 8
- *  where
- *     filter_coefficient = (255 << 8) / (256 + ((abs_diff * 330) >> 3));
- *     filter_coefficient += filter_coefficient /
- *                           (3 + motion_magnitude_adjustment);
- *     filter_coefficient is clamped to 0 ~ 255.
- *
- * Step 2:
- *  The adjustment vs. diff curve becomes flat very quick when diff increases.
- *  This allowed us to use only several levels to approximate the curve without
- *  changing the filtering algorithm too much.
- *  The adjustments were further corrected by checking the motion magnitude.
- *  The levels used are:
- *      diff          level       adjustment w/o       adjustment w/
- *                               motion correction    motion correction
- *      [-255, -16]     3              -6                   -7
- *      [-15, -8]       2              -4                   -5
- *      [-7, -4]        1              -3                   -4
- *      [-3, 3]         0              diff                 diff
- *      [4, 7]          1               3                    4
- *      [8, 15]         2               4                    5
- *      [16, 255]       3               6                    7
- */
-
-int vp8_denoiser_filter_neon(unsigned char *mc_running_avg_y,
-                             int mc_running_avg_y_stride,
-                             unsigned char *running_avg_y,
-                             int running_avg_y_stride,
-                             unsigned char *sig, int sig_stride,
-                             unsigned int motion_magnitude,
-                             int increase_denoising) {
-    /* If motion_magnitude is small, making the denoiser more aggressive by
-     * increasing the adjustment for each level, level1 adjustment is
-     * increased, the deltas stay the same.
-     */
-    int shift_inc  = (increase_denoising &&
-        motion_magnitude <= MOTION_MAGNITUDE_THRESHOLD) ? 1 : 0;
-    const uint8x16_t v_level1_adjustment = vmovq_n_u8(
-        (motion_magnitude <= MOTION_MAGNITUDE_THRESHOLD) ? 4 + shift_inc : 3);
-    const uint8x16_t v_delta_level_1_and_2 = vdupq_n_u8(1);
-    const uint8x16_t v_delta_level_2_and_3 = vdupq_n_u8(2);
-    const uint8x16_t v_level1_threshold = vmovq_n_u8(4 + shift_inc);
-    const uint8x16_t v_level2_threshold = vdupq_n_u8(8);
-    const uint8x16_t v_level3_threshold = vdupq_n_u8(16);
-    int64x2_t v_sum_diff_total = vdupq_n_s64(0);
-
-    /* Go over lines. */
-    int r;
-    for (r = 0; r < 16; ++r) {
-        /* Load inputs. */
-        const uint8x16_t v_sig = vld1q_u8(sig);
-        const uint8x16_t v_mc_running_avg_y = vld1q_u8(mc_running_avg_y);
-
-        /* Calculate absolute difference and sign masks. */
-        const uint8x16_t v_abs_diff      = vabdq_u8(v_sig, v_mc_running_avg_y);
-        const uint8x16_t v_diff_pos_mask = vcltq_u8(v_sig, v_mc_running_avg_y);
-        const uint8x16_t v_diff_neg_mask = vcgtq_u8(v_sig, v_mc_running_avg_y);
-
-        /* Figure out which level that put us in. */
-        const uint8x16_t v_level1_mask = vcleq_u8(v_level1_threshold,
-                                                  v_abs_diff);
-        const uint8x16_t v_level2_mask = vcleq_u8(v_level2_threshold,
-                                                  v_abs_diff);
-        const uint8x16_t v_level3_mask = vcleq_u8(v_level3_threshold,
-                                                  v_abs_diff);
-
-        /* Calculate absolute adjustments for level 1, 2 and 3. */
-        const uint8x16_t v_level2_adjustment = vandq_u8(v_level2_mask,
-                                                        v_delta_level_1_and_2);
-        const uint8x16_t v_level3_adjustment = vandq_u8(v_level3_mask,
-                                                        v_delta_level_2_and_3);
-        const uint8x16_t v_level1and2_adjustment = vaddq_u8(v_level1_adjustment,
-            v_level2_adjustment);
-        const uint8x16_t v_level1and2and3_adjustment = vaddq_u8(
-            v_level1and2_adjustment, v_level3_adjustment);
-
-        /* Figure adjustment absolute value by selecting between the absolute
-         * difference if in level0 or the value for level 1, 2 and 3.
-         */
-        const uint8x16_t v_abs_adjustment = vbslq_u8(v_level1_mask,
-            v_level1and2and3_adjustment, v_abs_diff);
-
-        /* Calculate positive and negative adjustments. Apply them to the signal
-         * and accumulate them. Adjustments are less than eight and the maximum
-         * sum of them (7 * 16) can fit in a signed char.
-         */
-        const uint8x16_t v_pos_adjustment = vandq_u8(v_diff_pos_mask,
-                                                     v_abs_adjustment);
-        const uint8x16_t v_neg_adjustment = vandq_u8(v_diff_neg_mask,
-                                                     v_abs_adjustment);
-
-        uint8x16_t v_running_avg_y = vqaddq_u8(v_sig, v_pos_adjustment);
-        v_running_avg_y = vqsubq_u8(v_running_avg_y, v_neg_adjustment);
-
-        /* Store results. */
-        vst1q_u8(running_avg_y, v_running_avg_y);
-
-        /* Sum all the accumulators to have the sum of all pixel differences
-         * for this macroblock.
-         */
-        {
-            const int8x16_t v_sum_diff =
-                vqsubq_s8(vreinterpretq_s8_u8(v_pos_adjustment),
-                          vreinterpretq_s8_u8(v_neg_adjustment));
-
-            const int16x8_t fe_dc_ba_98_76_54_32_10 = vpaddlq_s8(v_sum_diff);
-
-            const int32x4_t fedc_ba98_7654_3210 =
-                vpaddlq_s16(fe_dc_ba_98_76_54_32_10);
-
-            const int64x2_t fedcba98_76543210 =
-                vpaddlq_s32(fedc_ba98_7654_3210);
-
-            v_sum_diff_total = vqaddq_s64(v_sum_diff_total, fedcba98_76543210);
-        }
-
-        /* Update pointers for next iteration. */
-        sig += sig_stride;
-        mc_running_avg_y += mc_running_avg_y_stride;
-        running_avg_y += running_avg_y_stride;
-    }
-
-    /* Too much adjustments => copy block. */
-    {
-        int64x1_t x = vqadd_s64(vget_high_s64(v_sum_diff_total),
-                                      vget_low_s64(v_sum_diff_total));
-        int sum_diff = vget_lane_s32(vabs_s32(vreinterpret_s32_s64(x)), 0);
-        int sum_diff_thresh = SUM_DIFF_THRESHOLD;
-
-        if (increase_denoising) sum_diff_thresh = SUM_DIFF_THRESHOLD_HIGH;
-        if (sum_diff > sum_diff_thresh) {
-          // Before returning to copy the block (i.e., apply no denoising),
-          // checK if we can still apply some (weaker) temporal filtering to
-          // this block, that would otherwise not be denoised at all. Simplest
-          // is to apply an additional adjustment to running_avg_y to bring it
-          // closer to sig. The adjustment is capped by a maximum delta, and
-          // chosen such that in most cases the resulting sum_diff will be
-          // within the accceptable range given by sum_diff_thresh.
-
-          // The delta is set by the excess of absolute pixel diff over the
-          // threshold.
-          int delta = ((sum_diff - sum_diff_thresh) >> 8) + 1;
-          // Only apply the adjustment for max delta up to 3.
-          if (delta < 4) {
-            const uint8x16_t k_delta = vmovq_n_u8(delta);
-            sig -= sig_stride * 16;
-            mc_running_avg_y -= mc_running_avg_y_stride * 16;
-            running_avg_y -= running_avg_y_stride * 16;
-            for (r = 0; r < 16; ++r) {
-              uint8x16_t v_running_avg_y = vld1q_u8(running_avg_y);
-              const uint8x16_t v_sig = vld1q_u8(sig);
-              const uint8x16_t v_mc_running_avg_y = vld1q_u8(mc_running_avg_y);
-
-              /* Calculate absolute difference and sign masks. */
-              const uint8x16_t v_abs_diff      = vabdq_u8(v_sig,
-                                                          v_mc_running_avg_y);
-              const uint8x16_t v_diff_pos_mask = vcltq_u8(v_sig,
-                                                          v_mc_running_avg_y);
-              const uint8x16_t v_diff_neg_mask = vcgtq_u8(v_sig,
-                                                          v_mc_running_avg_y);
-              // Clamp absolute difference to delta to get the adjustment.
-              const uint8x16_t v_abs_adjustment =
-                  vminq_u8(v_abs_diff, (k_delta));
-
-              const uint8x16_t v_pos_adjustment = vandq_u8(v_diff_pos_mask,
-                                                           v_abs_adjustment);
-              const uint8x16_t v_neg_adjustment = vandq_u8(v_diff_neg_mask,
-                                                           v_abs_adjustment);
-
-              v_running_avg_y = vqsubq_u8(v_running_avg_y, v_pos_adjustment);
-              v_running_avg_y = vqaddq_u8(v_running_avg_y, v_neg_adjustment);
-
-              /* Store results. */
-              vst1q_u8(running_avg_y, v_running_avg_y);
-
-              {
-                  const int8x16_t v_sum_diff =
-                      vqsubq_s8(vreinterpretq_s8_u8(v_neg_adjustment),
-                                vreinterpretq_s8_u8(v_pos_adjustment));
-
-                  const int16x8_t fe_dc_ba_98_76_54_32_10 =
-                      vpaddlq_s8(v_sum_diff);
-                  const int32x4_t fedc_ba98_7654_3210 =
-                      vpaddlq_s16(fe_dc_ba_98_76_54_32_10);
-                  const int64x2_t fedcba98_76543210 =
-                      vpaddlq_s32(fedc_ba98_7654_3210);
-
-                  v_sum_diff_total = vqaddq_s64(v_sum_diff_total,
-                                                fedcba98_76543210);
-              }
-              /* Update pointers for next iteration. */
-              sig += sig_stride;
-              mc_running_avg_y += mc_running_avg_y_stride;
-              running_avg_y += running_avg_y_stride;
-            }
-            {
-              // Update the sum of all pixel differences of this MB.
-              x = vqadd_s64(vget_high_s64(v_sum_diff_total),
-                            vget_low_s64(v_sum_diff_total));
-              sum_diff = vget_lane_s32(vabs_s32(vreinterpret_s32_s64(x)), 0);
-
-              if (sum_diff > sum_diff_thresh) {
-                return COPY_BLOCK;
-              }
-            }
-          } else {
-            return COPY_BLOCK;
-          }
-        }
-    }
-
-    /* Tell above level that block was filtered. */
-    running_avg_y -= running_avg_y_stride * 16;
-    sig -= sig_stride * 16;
-
-    vp8_copy_mem16x16(running_avg_y, running_avg_y_stride, sig, sig_stride);
-
-    return FILTER_BLOCK;
-}
-
-int vp8_denoiser_filter_uv_neon(unsigned char *mc_running_avg,
-                             int mc_running_avg_stride,
-                             unsigned char *running_avg,
-                             int running_avg_stride,
-                             unsigned char *sig, int sig_stride,
-                             unsigned int motion_magnitude,
-                             int increase_denoising) {
-    /* If motion_magnitude is small, making the denoiser more aggressive by
-     * increasing the adjustment for each level, level1 adjustment is
-     * increased, the deltas stay the same.
-     */
-    int shift_inc  = (increase_denoising &&
-        motion_magnitude <= MOTION_MAGNITUDE_THRESHOLD_UV) ? 1 : 0;
-    const uint8x16_t v_level1_adjustment = vmovq_n_u8(
-        (motion_magnitude <= MOTION_MAGNITUDE_THRESHOLD_UV) ? 4 + shift_inc : 3);
-
-    const uint8x16_t v_delta_level_1_and_2 = vdupq_n_u8(1);
-    const uint8x16_t v_delta_level_2_and_3 = vdupq_n_u8(2);
-    const uint8x16_t v_level1_threshold = vmovq_n_u8(4 + shift_inc);
-    const uint8x16_t v_level2_threshold = vdupq_n_u8(8);
-    const uint8x16_t v_level3_threshold = vdupq_n_u8(16);
-    int64x2_t v_sum_diff_total = vdupq_n_s64(0);
-    int r;
-
-    {
-      uint16x4_t v_sum_block = vdup_n_u16(0);
-
-      // Avoid denoising color signal if its close to average level.
-      for (r = 0; r < 8; ++r) {
-        const uint8x8_t v_sig = vld1_u8(sig);
-        const uint16x4_t _76_54_32_10 = vpaddl_u8(v_sig);
-        v_sum_block = vqadd_u16(v_sum_block, _76_54_32_10);
-        sig += sig_stride;
-      }
-      sig -= sig_stride * 8;
-      {
-        const uint32x2_t _7654_3210 = vpaddl_u16(v_sum_block);
-        const uint64x1_t _76543210 = vpaddl_u32(_7654_3210);
-        const int sum_block =
-            vget_lane_s32(vreinterpret_s32_u64(_76543210), 0);
-        if (abs(sum_block - (128 * 8 * 8)) < SUM_DIFF_FROM_AVG_THRESH_UV) {
-          return COPY_BLOCK;
-        }
-      }
-    }
-
-    /* Go over lines. */
-    for (r = 0; r < 4; ++r) {
-        /* Load inputs. */
-        const uint8x8_t v_sig_lo = vld1_u8(sig);
-        const uint8x8_t v_sig_hi = vld1_u8(&sig[sig_stride]);
-        const uint8x16_t v_sig = vcombine_u8(v_sig_lo, v_sig_hi);
-        const uint8x8_t v_mc_running_avg_lo = vld1_u8(mc_running_avg);
-        const uint8x8_t v_mc_running_avg_hi =
-            vld1_u8(&mc_running_avg[mc_running_avg_stride]);
-        const uint8x16_t v_mc_running_avg =
-            vcombine_u8(v_mc_running_avg_lo, v_mc_running_avg_hi);
-        /* Calculate absolute difference and sign masks. */
-        const uint8x16_t v_abs_diff      = vabdq_u8(v_sig, v_mc_running_avg);
-        const uint8x16_t v_diff_pos_mask = vcltq_u8(v_sig, v_mc_running_avg);
-        const uint8x16_t v_diff_neg_mask = vcgtq_u8(v_sig, v_mc_running_avg);
-
-        /* Figure out which level that put us in. */
-        const uint8x16_t v_level1_mask = vcleq_u8(v_level1_threshold,
-                                                  v_abs_diff);
-        const uint8x16_t v_level2_mask = vcleq_u8(v_level2_threshold,
-                                                  v_abs_diff);
-        const uint8x16_t v_level3_mask = vcleq_u8(v_level3_threshold,
-                                                  v_abs_diff);
-
-        /* Calculate absolute adjustments for level 1, 2 and 3. */
-        const uint8x16_t v_level2_adjustment = vandq_u8(v_level2_mask,
-                                                        v_delta_level_1_and_2);
-        const uint8x16_t v_level3_adjustment = vandq_u8(v_level3_mask,
-                                                        v_delta_level_2_and_3);
-        const uint8x16_t v_level1and2_adjustment = vaddq_u8(v_level1_adjustment,
-            v_level2_adjustment);
-        const uint8x16_t v_level1and2and3_adjustment = vaddq_u8(
-            v_level1and2_adjustment, v_level3_adjustment);
-
-        /* Figure adjustment absolute value by selecting between the absolute
-         * difference if in level0 or the value for level 1, 2 and 3.
-         */
-        const uint8x16_t v_abs_adjustment = vbslq_u8(v_level1_mask,
-            v_level1and2and3_adjustment, v_abs_diff);
-
-        /* Calculate positive and negative adjustments. Apply them to the signal
-         * and accumulate them. Adjustments are less than eight and the maximum
-         * sum of them (7 * 16) can fit in a signed char.
-         */
-        const uint8x16_t v_pos_adjustment = vandq_u8(v_diff_pos_mask,
-                                                     v_abs_adjustment);
-        const uint8x16_t v_neg_adjustment = vandq_u8(v_diff_neg_mask,
-                                                     v_abs_adjustment);
-
-        uint8x16_t v_running_avg = vqaddq_u8(v_sig, v_pos_adjustment);
-        v_running_avg = vqsubq_u8(v_running_avg, v_neg_adjustment);
-
-        /* Store results. */
-        vst1_u8(running_avg, vget_low_u8(v_running_avg));
-        vst1_u8(&running_avg[running_avg_stride], vget_high_u8(v_running_avg));
-
-        /* Sum all the accumulators to have the sum of all pixel differences
-         * for this macroblock.
-         */
-        {
-            const int8x16_t v_sum_diff =
-                vqsubq_s8(vreinterpretq_s8_u8(v_pos_adjustment),
-                          vreinterpretq_s8_u8(v_neg_adjustment));
-
-            const int16x8_t fe_dc_ba_98_76_54_32_10 = vpaddlq_s8(v_sum_diff);
-
-            const int32x4_t fedc_ba98_7654_3210 =
-                vpaddlq_s16(fe_dc_ba_98_76_54_32_10);
-
-            const int64x2_t fedcba98_76543210 =
-                vpaddlq_s32(fedc_ba98_7654_3210);
-
-            v_sum_diff_total = vqaddq_s64(v_sum_diff_total, fedcba98_76543210);
-        }
-
-        /* Update pointers for next iteration. */
-        sig += sig_stride * 2;
-        mc_running_avg += mc_running_avg_stride * 2;
-        running_avg += running_avg_stride * 2;
-    }
-
-
-    /* Too much adjustments => copy block. */
-    {
-        int64x1_t x = vqadd_s64(vget_high_s64(v_sum_diff_total),
-                                      vget_low_s64(v_sum_diff_total));
-        int sum_diff = vget_lane_s32(vabs_s32(vreinterpret_s32_s64(x)), 0);
-        int sum_diff_thresh = SUM_DIFF_THRESHOLD_UV;
-        if (increase_denoising) sum_diff_thresh = SUM_DIFF_THRESHOLD_HIGH_UV;
-        if (sum_diff > sum_diff_thresh) {
-          // Before returning to copy the block (i.e., apply no denoising),
-          // checK if we can still apply some (weaker) temporal filtering to
-          // this block, that would otherwise not be denoised at all. Simplest
-          // is to apply an additional adjustment to running_avg_y to bring it
-          // closer to sig. The adjustment is capped by a maximum delta, and
-          // chosen such that in most cases the resulting sum_diff will be
-          // within the accceptable range given by sum_diff_thresh.
-
-          // The delta is set by the excess of absolute pixel diff over the
-          // threshold.
-          int delta = ((sum_diff - sum_diff_thresh) >> 8) + 1;
-          // Only apply the adjustment for max delta up to 3.
-          if (delta < 4) {
-            const uint8x16_t k_delta = vmovq_n_u8(delta);
-            sig -= sig_stride * 8;
-            mc_running_avg -= mc_running_avg_stride * 8;
-            running_avg -= running_avg_stride * 8;
-            for (r = 0; r < 4; ++r) {
-              const uint8x8_t v_sig_lo = vld1_u8(sig);
-              const uint8x8_t v_sig_hi = vld1_u8(&sig[sig_stride]);
-              const uint8x16_t v_sig = vcombine_u8(v_sig_lo, v_sig_hi);
-              const uint8x8_t v_mc_running_avg_lo = vld1_u8(mc_running_avg);
-              const uint8x8_t v_mc_running_avg_hi =
-                  vld1_u8(&mc_running_avg[mc_running_avg_stride]);
-              const uint8x16_t v_mc_running_avg =
-                  vcombine_u8(v_mc_running_avg_lo, v_mc_running_avg_hi);
-              /* Calculate absolute difference and sign masks. */
-              const uint8x16_t v_abs_diff      = vabdq_u8(v_sig,
-                                                          v_mc_running_avg);
-              const uint8x16_t v_diff_pos_mask = vcltq_u8(v_sig,
-                                                          v_mc_running_avg);
-              const uint8x16_t v_diff_neg_mask = vcgtq_u8(v_sig,
-                                                          v_mc_running_avg);
-              // Clamp absolute difference to delta to get the adjustment.
-              const uint8x16_t v_abs_adjustment =
-                  vminq_u8(v_abs_diff, (k_delta));
-
-              const uint8x16_t v_pos_adjustment = vandq_u8(v_diff_pos_mask,
-                                                           v_abs_adjustment);
-              const uint8x16_t v_neg_adjustment = vandq_u8(v_diff_neg_mask,
-                                                           v_abs_adjustment);
-              const uint8x8_t v_running_avg_lo = vld1_u8(running_avg);
-              const uint8x8_t v_running_avg_hi =
-                  vld1_u8(&running_avg[running_avg_stride]);
-              uint8x16_t v_running_avg =
-                  vcombine_u8(v_running_avg_lo, v_running_avg_hi);
-
-              v_running_avg = vqsubq_u8(v_running_avg, v_pos_adjustment);
-              v_running_avg = vqaddq_u8(v_running_avg, v_neg_adjustment);
-
-              /* Store results. */
-              vst1_u8(running_avg, vget_low_u8(v_running_avg));
-              vst1_u8(&running_avg[running_avg_stride],
-                      vget_high_u8(v_running_avg));
-
-              {
-                  const int8x16_t v_sum_diff =
-                      vqsubq_s8(vreinterpretq_s8_u8(v_neg_adjustment),
-                                vreinterpretq_s8_u8(v_pos_adjustment));
-
-                  const int16x8_t fe_dc_ba_98_76_54_32_10 =
-                      vpaddlq_s8(v_sum_diff);
-                  const int32x4_t fedc_ba98_7654_3210 =
-                      vpaddlq_s16(fe_dc_ba_98_76_54_32_10);
-                  const int64x2_t fedcba98_76543210 =
-                      vpaddlq_s32(fedc_ba98_7654_3210);
-
-                  v_sum_diff_total = vqaddq_s64(v_sum_diff_total,
-                                                fedcba98_76543210);
-              }
-              /* Update pointers for next iteration. */
-              sig += sig_stride * 2;
-              mc_running_avg += mc_running_avg_stride * 2;
-              running_avg += running_avg_stride * 2;
-            }
-            {
-              // Update the sum of all pixel differences of this MB.
-              x = vqadd_s64(vget_high_s64(v_sum_diff_total),
-                            vget_low_s64(v_sum_diff_total));
-              sum_diff = vget_lane_s32(vabs_s32(vreinterpret_s32_s64(x)), 0);
-
-              if (sum_diff > sum_diff_thresh) {
-                return COPY_BLOCK;
-              }
-            }
-          } else {
-            return COPY_BLOCK;
-          }
-        }
-    }
-
-    /* Tell above level that block was filtered. */
-    running_avg -= running_avg_stride * 8;
-    sig -= sig_stride * 8;
-
-    vp8_copy_mem8x8(running_avg, running_avg_stride, sig, sig_stride);
-
-    return FILTER_BLOCK;
-}
diff --git a/vp8/encoder/arm/neon/fastquantizeb_neon.c b/vp8/encoder/arm/neon/fastquantizeb_neon.c
deleted file mode 100644 (file)
index e5824bf..0000000
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- *  Copyright (c) 2014 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.
- */
-
-#include <arm_neon.h>
-#include "vp8/encoder/block.h"
-
-static const uint16_t inv_zig_zag[16] = {
-    1,  2,  6,   7,
-    3,  5,  8,  13,
-    4,  9,  12, 14,
-    10, 11, 15, 16
-};
-
-void vp8_fast_quantize_b_neon(BLOCK *b, BLOCKD *d) {
-    const int16x8_t one_q = vdupq_n_s16(-1),
-                    z0 = vld1q_s16(b->coeff),
-                    z1 = vld1q_s16(b->coeff + 8),
-                    round0 = vld1q_s16(b->round),
-                    round1 = vld1q_s16(b->round + 8),
-                    quant0 = vld1q_s16(b->quant_fast),
-                    quant1 = vld1q_s16(b->quant_fast + 8),
-                    dequant0 = vld1q_s16(d->dequant),
-                    dequant1 = vld1q_s16(d->dequant + 8);
-    const uint16x8_t zig_zag0 = vld1q_u16(inv_zig_zag),
-                     zig_zag1 = vld1q_u16(inv_zig_zag + 8);
-    int16x8_t x0, x1, sz0, sz1, y0, y1;
-    uint16x8_t eob0, eob1;
-    uint16x4_t eob_d16;
-    uint32x2_t eob_d32;
-    uint32x4_t eob_q32;
-
-    /* sign of z: z >> 15 */
-    sz0 = vshrq_n_s16(z0, 15);
-    sz1 = vshrq_n_s16(z1, 15);
-
-    /* x = abs(z) */
-    x0 = vabsq_s16(z0);
-    x1 = vabsq_s16(z1);
-
-    /* x += round */
-    x0 = vaddq_s16(x0, round0);
-    x1 = vaddq_s16(x1, round1);
-
-    /* y = 2 * (x * quant) >> 16 */
-    y0 = vqdmulhq_s16(x0, quant0);
-    y1 = vqdmulhq_s16(x1, quant1);
-
-    /* Compensate for doubling in vqdmulhq */
-    y0 = vshrq_n_s16(y0, 1);
-    y1 = vshrq_n_s16(y1, 1);
-
-    /* Restore sign bit */
-    y0 = veorq_s16(y0, sz0);
-    y1 = veorq_s16(y1, sz1);
-    x0 = vsubq_s16(y0, sz0);
-    x1 = vsubq_s16(y1, sz1);
-
-    /* find non-zero elements */
-    eob0 = vtstq_s16(x0, one_q);
-    eob1 = vtstq_s16(x1, one_q);
-
-    /* mask zig zag */
-    eob0 = vandq_u16(eob0, zig_zag0);
-    eob1 = vandq_u16(eob1, zig_zag1);
-
-    /* select the largest value */
-    eob0 = vmaxq_u16(eob0, eob1);
-    eob_d16 = vmax_u16(vget_low_u16(eob0), vget_high_u16(eob0));
-    eob_q32 = vmovl_u16(eob_d16);
-    eob_d32 = vmax_u32(vget_low_u32(eob_q32), vget_high_u32(eob_q32));
-    eob_d32 = vpmax_u32(eob_d32, eob_d32);
-
-    /* qcoeff = x */
-    vst1q_s16(d->qcoeff, x0);
-    vst1q_s16(d->qcoeff + 8, x1);
-
-    /* dqcoeff = x * dequant */
-    vst1q_s16(d->dqcoeff, vmulq_s16(dequant0, x0));
-    vst1q_s16(d->dqcoeff + 8, vmulq_s16(dequant1, x1));
-
-    vst1_lane_s8((int8_t *)d->eob, vreinterpret_s8_u32(eob_d32), 0);
-}
diff --git a/vp8/encoder/arm/neon/shortfdct_neon.c b/vp8/encoder/arm/neon/shortfdct_neon.c
deleted file mode 100644 (file)
index 391e5f9..0000000
+++ /dev/null
@@ -1,269 +0,0 @@
-/*
- *  Copyright (c) 2014 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.
- */
-
-#include <arm_neon.h>
-
-void vp8_short_fdct4x4_neon(
-        int16_t *input,
-        int16_t *output,
-        int pitch) {
-    int16x4_t d0s16, d1s16, d2s16, d3s16, d4s16, d5s16, d6s16, d7s16;
-    int16x4_t d16s16, d17s16, d26s16, dEmptys16;
-    uint16x4_t d4u16;
-    int16x8_t q0s16, q1s16;
-    int32x4_t q9s32, q10s32, q11s32, q12s32;
-    int16x4x2_t v2tmp0, v2tmp1;
-    int32x2x2_t v2tmp2, v2tmp3;
-
-    d16s16 = vdup_n_s16(5352);
-    d17s16 = vdup_n_s16(2217);
-    q9s32 = vdupq_n_s32(14500);
-    q10s32 = vdupq_n_s32(7500);
-    q11s32 = vdupq_n_s32(12000);
-    q12s32 = vdupq_n_s32(51000);
-
-    // Part one
-    pitch >>= 1;
-    d0s16 = vld1_s16(input);
-    input += pitch;
-    d1s16 = vld1_s16(input);
-    input += pitch;
-    d2s16 = vld1_s16(input);
-    input += pitch;
-    d3s16 = vld1_s16(input);
-
-    v2tmp2 = vtrn_s32(vreinterpret_s32_s16(d0s16),
-                      vreinterpret_s32_s16(d2s16));
-    v2tmp3 = vtrn_s32(vreinterpret_s32_s16(d1s16),
-                      vreinterpret_s32_s16(d3s16));
-    v2tmp0 = vtrn_s16(vreinterpret_s16_s32(v2tmp2.val[0]),   // d0
-                      vreinterpret_s16_s32(v2tmp3.val[0]));  // d1
-    v2tmp1 = vtrn_s16(vreinterpret_s16_s32(v2tmp2.val[1]),   // d2
-                      vreinterpret_s16_s32(v2tmp3.val[1]));  // d3
-
-    d4s16 = vadd_s16(v2tmp0.val[0], v2tmp1.val[1]);
-    d5s16 = vadd_s16(v2tmp0.val[1], v2tmp1.val[0]);
-    d6s16 = vsub_s16(v2tmp0.val[1], v2tmp1.val[0]);
-    d7s16 = vsub_s16(v2tmp0.val[0], v2tmp1.val[1]);
-
-    d4s16 = vshl_n_s16(d4s16, 3);
-    d5s16 = vshl_n_s16(d5s16, 3);
-    d6s16 = vshl_n_s16(d6s16, 3);
-    d7s16 = vshl_n_s16(d7s16, 3);
-
-    d0s16 = vadd_s16(d4s16, d5s16);
-    d2s16 = vsub_s16(d4s16, d5s16);
-
-    q9s32 = vmlal_s16(q9s32, d7s16, d16s16);
-    q10s32 = vmlal_s16(q10s32, d7s16, d17s16);
-    q9s32 = vmlal_s16(q9s32, d6s16, d17s16);
-    q10s32 = vmlsl_s16(q10s32, d6s16, d16s16);
-
-    d1s16 = vshrn_n_s32(q9s32, 12);
-    d3s16 = vshrn_n_s32(q10s32, 12);
-
-    // Part two
-    v2tmp2 = vtrn_s32(vreinterpret_s32_s16(d0s16),
-                      vreinterpret_s32_s16(d2s16));
-    v2tmp3 = vtrn_s32(vreinterpret_s32_s16(d1s16),
-                      vreinterpret_s32_s16(d3s16));
-    v2tmp0 = vtrn_s16(vreinterpret_s16_s32(v2tmp2.val[0]),   // d0
-                      vreinterpret_s16_s32(v2tmp3.val[0]));  // d1
-    v2tmp1 = vtrn_s16(vreinterpret_s16_s32(v2tmp2.val[1]),   // d2
-                      vreinterpret_s16_s32(v2tmp3.val[1]));  // d3
-
-    d4s16 = vadd_s16(v2tmp0.val[0], v2tmp1.val[1]);
-    d5s16 = vadd_s16(v2tmp0.val[1], v2tmp1.val[0]);
-    d6s16 = vsub_s16(v2tmp0.val[1], v2tmp1.val[0]);
-    d7s16 = vsub_s16(v2tmp0.val[0], v2tmp1.val[1]);
-
-    d26s16 = vdup_n_s16(7);
-    d4s16 = vadd_s16(d4s16, d26s16);
-
-    d0s16 = vadd_s16(d4s16, d5s16);
-    d2s16 = vsub_s16(d4s16, d5s16);
-
-    q11s32 = vmlal_s16(q11s32, d7s16, d16s16);
-    q12s32 = vmlal_s16(q12s32, d7s16, d17s16);
-
-    dEmptys16 = vdup_n_s16(0);
-    d4u16 = vceq_s16(d7s16, dEmptys16);
-
-    d0s16 = vshr_n_s16(d0s16, 4);
-    d2s16 = vshr_n_s16(d2s16, 4);
-
-    q11s32 = vmlal_s16(q11s32, d6s16, d17s16);
-    q12s32 = vmlsl_s16(q12s32, d6s16, d16s16);
-
-    d4u16 = vmvn_u16(d4u16);
-    d1s16 = vshrn_n_s32(q11s32, 16);
-    d1s16 = vsub_s16(d1s16, vreinterpret_s16_u16(d4u16));
-    d3s16 = vshrn_n_s32(q12s32, 16);
-
-    q0s16 = vcombine_s16(d0s16, d1s16);
-    q1s16 = vcombine_s16(d2s16, d3s16);
-
-    vst1q_s16(output, q0s16);
-    vst1q_s16(output + 8, q1s16);
-    return;
-}
-
-void vp8_short_fdct8x4_neon(
-        int16_t *input,
-        int16_t *output,
-        int pitch) {
-    int16x4_t d0s16, d1s16, d2s16, d3s16, d4s16, d5s16, d6s16, d7s16;
-    int16x4_t d16s16, d17s16, d26s16, d27s16, d28s16, d29s16;
-    uint16x4_t d28u16, d29u16;
-    uint16x8_t q14u16;
-    int16x8_t q0s16, q1s16, q2s16, q3s16;
-    int16x8_t q11s16, q12s16, q13s16, q14s16, q15s16, qEmptys16;
-    int32x4_t q9s32, q10s32, q11s32, q12s32;
-    int16x8x2_t v2tmp0, v2tmp1;
-    int32x4x2_t v2tmp2, v2tmp3;
-
-    d16s16 = vdup_n_s16(5352);
-    d17s16 = vdup_n_s16(2217);
-    q9s32 = vdupq_n_s32(14500);
-    q10s32 = vdupq_n_s32(7500);
-
-    // Part one
-    pitch >>= 1;
-    q0s16 = vld1q_s16(input);
-    input += pitch;
-    q1s16 = vld1q_s16(input);
-    input += pitch;
-    q2s16 = vld1q_s16(input);
-    input += pitch;
-    q3s16 = vld1q_s16(input);
-
-    v2tmp2 = vtrnq_s32(vreinterpretq_s32_s16(q0s16),
-                       vreinterpretq_s32_s16(q2s16));
-    v2tmp3 = vtrnq_s32(vreinterpretq_s32_s16(q1s16),
-                       vreinterpretq_s32_s16(q3s16));
-    v2tmp0 = vtrnq_s16(vreinterpretq_s16_s32(v2tmp2.val[0]),   // q0
-                       vreinterpretq_s16_s32(v2tmp3.val[0]));  // q1
-    v2tmp1 = vtrnq_s16(vreinterpretq_s16_s32(v2tmp2.val[1]),   // q2
-                       vreinterpretq_s16_s32(v2tmp3.val[1]));  // q3
-
-    q11s16 = vaddq_s16(v2tmp0.val[0], v2tmp1.val[1]);
-    q12s16 = vaddq_s16(v2tmp0.val[1], v2tmp1.val[0]);
-    q13s16 = vsubq_s16(v2tmp0.val[1], v2tmp1.val[0]);
-    q14s16 = vsubq_s16(v2tmp0.val[0], v2tmp1.val[1]);
-
-    q11s16 = vshlq_n_s16(q11s16, 3);
-    q12s16 = vshlq_n_s16(q12s16, 3);
-    q13s16 = vshlq_n_s16(q13s16, 3);
-    q14s16 = vshlq_n_s16(q14s16, 3);
-
-    q0s16 = vaddq_s16(q11s16, q12s16);
-    q2s16 = vsubq_s16(q11s16, q12s16);
-
-    q11s32 = q9s32;
-    q12s32 = q10s32;
-
-    d26s16 = vget_low_s16(q13s16);
-    d27s16 = vget_high_s16(q13s16);
-    d28s16 = vget_low_s16(q14s16);
-    d29s16 = vget_high_s16(q14s16);
-
-    q9s32 = vmlal_s16(q9s32, d28s16, d16s16);
-    q10s32 = vmlal_s16(q10s32, d28s16, d17s16);
-    q11s32 = vmlal_s16(q11s32, d29s16, d16s16);
-    q12s32 = vmlal_s16(q12s32, d29s16, d17s16);
-
-    q9s32 = vmlal_s16(q9s32, d26s16, d17s16);
-    q10s32 = vmlsl_s16(q10s32, d26s16, d16s16);
-    q11s32 = vmlal_s16(q11s32, d27s16, d17s16);
-    q12s32 = vmlsl_s16(q12s32, d27s16, d16s16);
-
-    d2s16 = vshrn_n_s32(q9s32, 12);
-    d6s16 = vshrn_n_s32(q10s32, 12);
-    d3s16 = vshrn_n_s32(q11s32, 12);
-    d7s16 = vshrn_n_s32(q12s32, 12);
-    q1s16 = vcombine_s16(d2s16, d3s16);
-    q3s16 = vcombine_s16(d6s16, d7s16);
-
-    // Part two
-    q9s32 = vdupq_n_s32(12000);
-    q10s32 = vdupq_n_s32(51000);
-
-    v2tmp2 = vtrnq_s32(vreinterpretq_s32_s16(q0s16),
-                       vreinterpretq_s32_s16(q2s16));
-    v2tmp3 = vtrnq_s32(vreinterpretq_s32_s16(q1s16),
-                       vreinterpretq_s32_s16(q3s16));
-    v2tmp0 = vtrnq_s16(vreinterpretq_s16_s32(v2tmp2.val[0]),   // q0
-                       vreinterpretq_s16_s32(v2tmp3.val[0]));  // q1
-    v2tmp1 = vtrnq_s16(vreinterpretq_s16_s32(v2tmp2.val[1]),   // q2
-                       vreinterpretq_s16_s32(v2tmp3.val[1]));  // q3
-
-    q11s16 = vaddq_s16(v2tmp0.val[0], v2tmp1.val[1]);
-    q12s16 = vaddq_s16(v2tmp0.val[1], v2tmp1.val[0]);
-    q13s16 = vsubq_s16(v2tmp0.val[1], v2tmp1.val[0]);
-    q14s16 = vsubq_s16(v2tmp0.val[0], v2tmp1.val[1]);
-
-    q15s16 = vdupq_n_s16(7);
-    q11s16 = vaddq_s16(q11s16, q15s16);
-    q0s16 = vaddq_s16(q11s16, q12s16);
-    q1s16 = vsubq_s16(q11s16, q12s16);
-
-    q11s32 = q9s32;
-    q12s32 = q10s32;
-
-    d0s16 = vget_low_s16(q0s16);
-    d1s16 = vget_high_s16(q0s16);
-    d2s16 = vget_low_s16(q1s16);
-    d3s16 = vget_high_s16(q1s16);
-
-    d0s16 = vshr_n_s16(d0s16, 4);
-    d4s16 = vshr_n_s16(d1s16, 4);
-    d2s16 = vshr_n_s16(d2s16, 4);
-    d6s16 = vshr_n_s16(d3s16, 4);
-
-    d26s16 = vget_low_s16(q13s16);
-    d27s16 = vget_high_s16(q13s16);
-    d28s16 = vget_low_s16(q14s16);
-    d29s16 = vget_high_s16(q14s16);
-
-    q9s32 = vmlal_s16(q9s32, d28s16, d16s16);
-    q10s32 = vmlal_s16(q10s32, d28s16, d17s16);
-    q11s32 = vmlal_s16(q11s32, d29s16, d16s16);
-    q12s32 = vmlal_s16(q12s32, d29s16, d17s16);
-
-    q9s32 = vmlal_s16(q9s32, d26s16, d17s16);
-    q10s32 = vmlsl_s16(q10s32, d26s16, d16s16);
-    q11s32 = vmlal_s16(q11s32, d27s16, d17s16);
-    q12s32 = vmlsl_s16(q12s32, d27s16, d16s16);
-
-    d1s16 = vshrn_n_s32(q9s32, 16);
-    d3s16 = vshrn_n_s32(q10s32, 16);
-    d5s16 = vshrn_n_s32(q11s32, 16);
-    d7s16 = vshrn_n_s32(q12s32, 16);
-
-    qEmptys16 = vdupq_n_s16(0);
-    q14u16 = vceqq_s16(q14s16, qEmptys16);
-    q14u16 = vmvnq_u16(q14u16);
-
-    d28u16 = vget_low_u16(q14u16);
-    d29u16 = vget_high_u16(q14u16);
-    d1s16 = vsub_s16(d1s16, vreinterpret_s16_u16(d28u16));
-    d5s16 = vsub_s16(d5s16, vreinterpret_s16_u16(d29u16));
-
-    q0s16 = vcombine_s16(d0s16, d1s16);
-    q1s16 = vcombine_s16(d2s16, d3s16);
-    q2s16 = vcombine_s16(d4s16, d5s16);
-    q3s16 = vcombine_s16(d6s16, d7s16);
-
-    vst1q_s16(output, q0s16);
-    vst1q_s16(output + 8, q1s16);
-    vst1q_s16(output + 16, q2s16);
-    vst1q_s16(output + 24, q3s16);
-    return;
-}
diff --git a/vp8/encoder/arm/neon/vp8_shortwalsh4x4_neon.c b/vp8/encoder/arm/neon/vp8_shortwalsh4x4_neon.c
deleted file mode 100644 (file)
index 5ad9465..0000000
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- *  Copyright (c) 2014 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.
- */
-
-#include <arm_neon.h>
-#include "vpx_ports/arm.h"
-
-#ifdef VPX_INCOMPATIBLE_GCC
-#include "./vp8_rtcd.h"
-void vp8_short_walsh4x4_neon(
-        int16_t *input,
-        int16_t *output,
-        int pitch) {
-  vp8_short_walsh4x4_c(input, output, pitch);
-}
-#else
-void vp8_short_walsh4x4_neon(
-        int16_t *input,
-        int16_t *output,
-        int pitch) {
-    uint16x4_t d16u16;
-    int16x8_t q0s16, q1s16;
-    int16x4_t dEmptys16, d0s16, d1s16, d2s16, d3s16, d4s16, d5s16, d6s16, d7s16;
-    int32x4_t qEmptys32, q0s32, q1s32, q2s32, q3s32, q8s32;
-    int32x4_t q9s32, q10s32, q11s32, q15s32;
-    uint32x4_t q8u32, q9u32, q10u32, q11u32;
-    int16x4x2_t v2tmp0, v2tmp1;
-    int32x2x2_t v2tmp2, v2tmp3;
-
-    dEmptys16 = vdup_n_s16(0);
-    qEmptys32 = vdupq_n_s32(0);
-    q15s32 = vdupq_n_s32(3);
-
-    d0s16 = vld1_s16(input);
-    input += pitch/2;
-    d1s16 = vld1_s16(input);
-    input += pitch/2;
-    d2s16 = vld1_s16(input);
-    input += pitch/2;
-    d3s16 = vld1_s16(input);
-
-    v2tmp2 = vtrn_s32(vreinterpret_s32_s16(d0s16),
-                      vreinterpret_s32_s16(d2s16));
-    v2tmp3 = vtrn_s32(vreinterpret_s32_s16(d1s16),
-                      vreinterpret_s32_s16(d3s16));
-    v2tmp0 = vtrn_s16(vreinterpret_s16_s32(v2tmp2.val[0]),   // d0
-                      vreinterpret_s16_s32(v2tmp3.val[0]));  // d1
-    v2tmp1 = vtrn_s16(vreinterpret_s16_s32(v2tmp2.val[1]),   // d2
-                      vreinterpret_s16_s32(v2tmp3.val[1]));  // d3
-
-    d4s16 = vadd_s16(v2tmp0.val[0], v2tmp1.val[0]);
-    d5s16 = vadd_s16(v2tmp0.val[1], v2tmp1.val[1]);
-    d6s16 = vsub_s16(v2tmp0.val[1], v2tmp1.val[1]);
-    d7s16 = vsub_s16(v2tmp0.val[0], v2tmp1.val[0]);
-
-    d4s16 = vshl_n_s16(d4s16, 2);
-    d5s16 = vshl_n_s16(d5s16, 2);
-    d6s16 = vshl_n_s16(d6s16, 2);
-    d7s16 = vshl_n_s16(d7s16, 2);
-
-    d16u16 = vceq_s16(d4s16, dEmptys16);
-    d16u16 = vmvn_u16(d16u16);
-
-    d0s16 = vadd_s16(d4s16, d5s16);
-    d3s16 = vsub_s16(d4s16, d5s16);
-    d1s16 = vadd_s16(d7s16, d6s16);
-    d2s16 = vsub_s16(d7s16, d6s16);
-
-    d0s16 = vsub_s16(d0s16, vreinterpret_s16_u16(d16u16));
-
-    // Second for-loop
-    v2tmp2 = vtrn_s32(vreinterpret_s32_s16(d1s16),
-                      vreinterpret_s32_s16(d3s16));
-    v2tmp3 = vtrn_s32(vreinterpret_s32_s16(d0s16),
-                      vreinterpret_s32_s16(d2s16));
-    v2tmp0 = vtrn_s16(vreinterpret_s16_s32(v2tmp3.val[1]),   // d2
-                      vreinterpret_s16_s32(v2tmp2.val[1]));  // d3
-    v2tmp1 = vtrn_s16(vreinterpret_s16_s32(v2tmp3.val[0]),   // d0
-                      vreinterpret_s16_s32(v2tmp2.val[0]));  // d1
-
-    q8s32  = vaddl_s16(v2tmp1.val[0], v2tmp0.val[0]);
-    q9s32  = vaddl_s16(v2tmp1.val[1], v2tmp0.val[1]);
-    q10s32 = vsubl_s16(v2tmp1.val[1], v2tmp0.val[1]);
-    q11s32 = vsubl_s16(v2tmp1.val[0], v2tmp0.val[0]);
-
-    q0s32 = vaddq_s32(q8s32, q9s32);
-    q1s32 = vaddq_s32(q11s32, q10s32);
-    q2s32 = vsubq_s32(q11s32, q10s32);
-    q3s32 = vsubq_s32(q8s32, q9s32);
-
-    q8u32  = vcltq_s32(q0s32, qEmptys32);
-    q9u32  = vcltq_s32(q1s32, qEmptys32);
-    q10u32 = vcltq_s32(q2s32, qEmptys32);
-    q11u32 = vcltq_s32(q3s32, qEmptys32);
-
-    q8s32  = vreinterpretq_s32_u32(q8u32);
-    q9s32  = vreinterpretq_s32_u32(q9u32);
-    q10s32 = vreinterpretq_s32_u32(q10u32);
-    q11s32 = vreinterpretq_s32_u32(q11u32);
-
-    q0s32 = vsubq_s32(q0s32, q8s32);
-    q1s32 = vsubq_s32(q1s32, q9s32);
-    q2s32 = vsubq_s32(q2s32, q10s32);
-    q3s32 = vsubq_s32(q3s32, q11s32);
-
-    q8s32  = vaddq_s32(q0s32, q15s32);
-    q9s32  = vaddq_s32(q1s32, q15s32);
-    q10s32 = vaddq_s32(q2s32, q15s32);
-    q11s32 = vaddq_s32(q3s32, q15s32);
-
-    d0s16 = vshrn_n_s32(q8s32, 3);
-    d1s16 = vshrn_n_s32(q9s32, 3);
-    d2s16 = vshrn_n_s32(q10s32, 3);
-    d3s16 = vshrn_n_s32(q11s32, 3);
-
-    q0s16 = vcombine_s16(d0s16, d1s16);
-    q1s16 = vcombine_s16(d2s16, d3s16);
-
-    vst1q_s16(output, q0s16);
-    vst1q_s16(output + 8, q1s16);
-    return;
-}
-#endif  // VPX_INCOMPATIBLE_GCC
diff --git a/vp8/encoder/bitstream.c b/vp8/encoder/bitstream.c
deleted file mode 100644 (file)
index 3196422..0000000
+++ /dev/null
@@ -1,1739 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#include "vp8/common/header.h"
-#include "encodemv.h"
-#include "vp8/common/entropymode.h"
-#include "vp8/common/findnearmv.h"
-#include "mcomp.h"
-#include "vp8/common/systemdependent.h"
-#include <assert.h>
-#include <stdio.h>
-#include <limits.h>
-#include "vpx/vpx_encoder.h"
-#include "vpx_mem/vpx_mem.h"
-#include "bitstream.h"
-
-#include "defaultcoefcounts.h"
-#include "vp8/common/common.h"
-
-const int vp8cx_base_skip_false_prob[128] =
-{
-    255, 255, 255, 255, 255, 255, 255, 255,
-    255, 255, 255, 255, 255, 255, 255, 255,
-    255, 255, 255, 255, 255, 255, 255, 255,
-    255, 255, 255, 255, 255, 255, 255, 255,
-    255, 255, 255, 255, 255, 255, 255, 255,
-    255, 255, 255, 255, 255, 255, 255, 255,
-    255, 255, 255, 255, 255, 255, 255, 255,
-    251, 248, 244, 240, 236, 232, 229, 225,
-    221, 217, 213, 208, 204, 199, 194, 190,
-    187, 183, 179, 175, 172, 168, 164, 160,
-    157, 153, 149, 145, 142, 138, 134, 130,
-    127, 124, 120, 117, 114, 110, 107, 104,
-    101, 98,  95,  92,  89,  86,  83, 80,
-    77,  74,  71,  68,  65,  62,  59, 56,
-    53,  50,  47,  44,  41,  38,  35, 32,
-    30,  28,  26,  24,  22,  20,  18, 16,
-};
-
-#if defined(SECTIONBITS_OUTPUT)
-unsigned __int64 Sectionbits[500];
-#endif
-
-#ifdef VP8_ENTROPY_STATS
-int intra_mode_stats[10][10][10];
-static unsigned int tree_update_hist [BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [ENTROPY_NODES] [2];
-extern unsigned int active_section;
-#endif
-
-#ifdef MODE_STATS
-int count_mb_seg[4] = { 0, 0, 0, 0 };
-#endif
-
-
-static void update_mode(
-    vp8_writer *const w,
-    int n,
-    vp8_token tok               [/* n */],
-    vp8_tree tree,
-    vp8_prob Pnew               [/* n-1 */],
-    vp8_prob Pcur               [/* n-1 */],
-    unsigned int bct            [/* n-1 */] [2],
-    const unsigned int num_events[/* n */]
-)
-{
-    unsigned int new_b = 0, old_b = 0;
-    int i = 0;
-
-    vp8_tree_probs_from_distribution(
-        n--, tok, tree,
-        Pnew, bct, num_events,
-        256, 1
-    );
-
-    do
-    {
-        new_b += vp8_cost_branch(bct[i], Pnew[i]);
-        old_b += vp8_cost_branch(bct[i], Pcur[i]);
-    }
-    while (++i < n);
-
-    if (new_b + (n << 8) < old_b)
-    {
-        int j = 0;
-
-        vp8_write_bit(w, 1);
-
-        do
-        {
-            const vp8_prob p = Pnew[j];
-
-            vp8_write_literal(w, Pcur[j] = p ? p : 1, 8);
-        }
-        while (++j < n);
-    }
-    else
-        vp8_write_bit(w, 0);
-}
-
-static void update_mbintra_mode_probs(VP8_COMP *cpi)
-{
-    VP8_COMMON *const x = & cpi->common;
-
-    vp8_writer *const w = cpi->bc;
-
-    {
-        vp8_prob Pnew   [VP8_YMODES-1];
-        unsigned int bct [VP8_YMODES-1] [2];
-
-        update_mode(
-            w, VP8_YMODES, vp8_ymode_encodings, vp8_ymode_tree,
-            Pnew, x->fc.ymode_prob, bct, (unsigned int *)cpi->mb.ymode_count
-        );
-    }
-    {
-        vp8_prob Pnew   [VP8_UV_MODES-1];
-        unsigned int bct [VP8_UV_MODES-1] [2];
-
-        update_mode(
-            w, VP8_UV_MODES, vp8_uv_mode_encodings, vp8_uv_mode_tree,
-            Pnew, x->fc.uv_mode_prob, bct, (unsigned int *)cpi->mb.uv_mode_count
-        );
-    }
-}
-
-static void write_ymode(vp8_writer *bc, int m, const vp8_prob *p)
-{
-    vp8_write_token(bc, vp8_ymode_tree, p, vp8_ymode_encodings + m);
-}
-
-static void kfwrite_ymode(vp8_writer *bc, int m, const vp8_prob *p)
-{
-    vp8_write_token(bc, vp8_kf_ymode_tree, p, vp8_kf_ymode_encodings + m);
-}
-
-static void write_uv_mode(vp8_writer *bc, int m, const vp8_prob *p)
-{
-    vp8_write_token(bc, vp8_uv_mode_tree, p, vp8_uv_mode_encodings + m);
-}
-
-
-static void write_bmode(vp8_writer *bc, int m, const vp8_prob *p)
-{
-    vp8_write_token(bc, vp8_bmode_tree, p, vp8_bmode_encodings + m);
-}
-
-static void write_split(vp8_writer *bc, int x)
-{
-    vp8_write_token(
-        bc, vp8_mbsplit_tree, vp8_mbsplit_probs, vp8_mbsplit_encodings + x
-    );
-}
-
-void vp8_pack_tokens(vp8_writer *w, const TOKENEXTRA *p, int xcount)
-{
-    const TOKENEXTRA *stop = p + xcount;
-    unsigned int split;
-    int shift;
-    int count = w->count;
-    unsigned int range = w->range;
-    unsigned int lowvalue = w->lowvalue;
-
-    while (p < stop)
-    {
-        const int t = p->Token;
-        vp8_token *a = vp8_coef_encodings + t;
-        const vp8_extra_bit_struct *b = vp8_extra_bits + t;
-        int i = 0;
-        const unsigned char *pp = p->context_tree;
-        int v = a->value;
-        int n = a->Len;
-
-        if (p->skip_eob_node)
-        {
-            n--;
-            i = 2;
-        }
-
-        do
-        {
-            const int bb = (v >> --n) & 1;
-            split = 1 + (((range - 1) * pp[i>>1]) >> 8);
-            i = vp8_coef_tree[i+bb];
-
-            if (bb)
-            {
-                lowvalue += split;
-                range = range - split;
-            }
-            else
-            {
-                range = split;
-            }
-
-            shift = vp8_norm[range];
-            range <<= shift;
-            count += shift;
-
-            if (count >= 0)
-            {
-                int offset = shift - count;
-
-                if ((lowvalue << (offset - 1)) & 0x80000000)
-                {
-                    int x = w->pos - 1;
-
-                    while (x >= 0 && w->buffer[x] == 0xff)
-                    {
-                        w->buffer[x] = (unsigned char)0;
-                        x--;
-                    }
-
-                    w->buffer[x] += 1;
-                }
-
-                validate_buffer(w->buffer + w->pos,
-                                1,
-                                w->buffer_end,
-                                w->error);
-
-                w->buffer[w->pos++] = (lowvalue >> (24 - offset));
-                lowvalue <<= offset;
-                shift = count;
-                lowvalue &= 0xffffff;
-                count -= 8 ;
-            }
-
-            lowvalue <<= shift;
-        }
-        while (n);
-
-
-        if (b->base_val)
-        {
-            const int e = p->Extra, L = b->Len;
-
-            if (L)
-            {
-                const unsigned char *proba = b->prob;
-                const int v2 = e >> 1;
-                int n2 = L;              /* number of bits in v2, assumed nonzero */
-                i = 0;
-
-                do
-                {
-                    const int bb = (v2 >> --n2) & 1;
-                    split = 1 + (((range - 1) * proba[i>>1]) >> 8);
-                    i = b->tree[i+bb];
-
-                    if (bb)
-                    {
-                        lowvalue += split;
-                        range = range - split;
-                    }
-                    else
-                    {
-                        range = split;
-                    }
-
-                    shift = vp8_norm[range];
-                    range <<= shift;
-                    count += shift;
-
-                    if (count >= 0)
-                    {
-                        int offset = shift - count;
-
-                        if ((lowvalue << (offset - 1)) & 0x80000000)
-                        {
-                            int x = w->pos - 1;
-
-                            while (x >= 0 && w->buffer[x] == 0xff)
-                            {
-                                w->buffer[x] = (unsigned char)0;
-                                x--;
-                            }
-
-                            w->buffer[x] += 1;
-                        }
-
-                        validate_buffer(w->buffer + w->pos,
-                                        1,
-                                        w->buffer_end,
-                                        w->error);
-
-                        w->buffer[w->pos++] = (lowvalue >> (24 - offset));
-                        lowvalue <<= offset;
-                        shift = count;
-                        lowvalue &= 0xffffff;
-                        count -= 8 ;
-                    }
-
-                    lowvalue <<= shift;
-                }
-                while (n2);
-            }
-
-
-            {
-
-                split = (range + 1) >> 1;
-
-                if (e & 1)
-                {
-                    lowvalue += split;
-                    range = range - split;
-                }
-                else
-                {
-                    range = split;
-                }
-
-                range <<= 1;
-
-                if ((lowvalue & 0x80000000))
-                {
-                    int x = w->pos - 1;
-
-                    while (x >= 0 && w->buffer[x] == 0xff)
-                    {
-                        w->buffer[x] = (unsigned char)0;
-                        x--;
-                    }
-
-                    w->buffer[x] += 1;
-
-                }
-
-                lowvalue  <<= 1;
-
-                if (!++count)
-                {
-                    count = -8;
-
-                    validate_buffer(w->buffer + w->pos,
-                                    1,
-                                    w->buffer_end,
-                                    w->error);
-
-                    w->buffer[w->pos++] = (lowvalue >> 24);
-                    lowvalue &= 0xffffff;
-                }
-            }
-
-        }
-
-        ++p;
-    }
-
-    w->count = count;
-    w->lowvalue = lowvalue;
-    w->range = range;
-
-}
-
-static void write_partition_size(unsigned char *cx_data, int size)
-{
-    signed char csize;
-
-    csize = size & 0xff;
-    *cx_data = csize;
-    csize = (size >> 8) & 0xff;
-    *(cx_data + 1) = csize;
-    csize = (size >> 16) & 0xff;
-    *(cx_data + 2) = csize;
-
-}
-
-static void pack_tokens_into_partitions(VP8_COMP *cpi, unsigned char *cx_data,
-                                          unsigned char * cx_data_end,
-                                          int num_part)
-{
-
-    int i;
-    unsigned char *ptr = cx_data;
-    unsigned char *ptr_end = cx_data_end;
-    vp8_writer * w;
-
-    for (i = 0; i < num_part; i++)
-    {
-        int mb_row;
-
-        w = cpi->bc + i + 1;
-
-        vp8_start_encode(w, ptr, ptr_end);
-
-        for (mb_row = i; mb_row < cpi->common.mb_rows; mb_row += num_part)
-        {
-            const TOKENEXTRA *p    = cpi->tplist[mb_row].start;
-            const TOKENEXTRA *stop = cpi->tplist[mb_row].stop;
-            int tokens = (int)(stop - p);
-
-            vp8_pack_tokens(w, p, tokens);
-        }
-
-        vp8_stop_encode(w);
-        ptr += w->pos;
-    }
-}
-
-
-#if CONFIG_MULTITHREAD
-static void pack_mb_row_tokens(VP8_COMP *cpi, vp8_writer *w)
-{
-    int mb_row;
-
-    for (mb_row = 0; mb_row < cpi->common.mb_rows; mb_row++)
-    {
-        const TOKENEXTRA *p    = cpi->tplist[mb_row].start;
-        const TOKENEXTRA *stop = cpi->tplist[mb_row].stop;
-        int tokens = (int)(stop - p);
-
-        vp8_pack_tokens(w, p, tokens);
-    }
-
-}
-#endif  // CONFIG_MULTITHREAD
-
-static void write_mv_ref
-(
-    vp8_writer *w, MB_PREDICTION_MODE m, const vp8_prob *p
-)
-{
-#if CONFIG_DEBUG
-    assert(NEARESTMV <= m  &&  m <= SPLITMV);
-#endif
-    vp8_write_token(w, vp8_mv_ref_tree, p,
-                    vp8_mv_ref_encoding_array + (m - NEARESTMV));
-}
-
-static void write_sub_mv_ref
-(
-    vp8_writer *w, B_PREDICTION_MODE m, const vp8_prob *p
-)
-{
-#if CONFIG_DEBUG
-    assert(LEFT4X4 <= m  &&  m <= NEW4X4);
-#endif
-    vp8_write_token(w, vp8_sub_mv_ref_tree, p,
-                    vp8_sub_mv_ref_encoding_array + (m - LEFT4X4));
-}
-
-static void write_mv
-(
-    vp8_writer *w, const MV *mv, const int_mv *ref, const MV_CONTEXT *mvc
-)
-{
-    MV e;
-    e.row = mv->row - ref->as_mv.row;
-    e.col = mv->col - ref->as_mv.col;
-
-    vp8_encode_motion_vector(w, &e, mvc);
-}
-
-static void write_mb_features(vp8_writer *w, const MB_MODE_INFO *mi, const MACROBLOCKD *x)
-{
-    /* Encode the MB segment id. */
-    if (x->segmentation_enabled && x->update_mb_segmentation_map)
-    {
-        switch (mi->segment_id)
-        {
-        case 0:
-            vp8_write(w, 0, x->mb_segment_tree_probs[0]);
-            vp8_write(w, 0, x->mb_segment_tree_probs[1]);
-            break;
-        case 1:
-            vp8_write(w, 0, x->mb_segment_tree_probs[0]);
-            vp8_write(w, 1, x->mb_segment_tree_probs[1]);
-            break;
-        case 2:
-            vp8_write(w, 1, x->mb_segment_tree_probs[0]);
-            vp8_write(w, 0, x->mb_segment_tree_probs[2]);
-            break;
-        case 3:
-            vp8_write(w, 1, x->mb_segment_tree_probs[0]);
-            vp8_write(w, 1, x->mb_segment_tree_probs[2]);
-            break;
-
-            /* TRAP.. This should not happen */
-        default:
-            vp8_write(w, 0, x->mb_segment_tree_probs[0]);
-            vp8_write(w, 0, x->mb_segment_tree_probs[1]);
-            break;
-        }
-    }
-}
-void vp8_convert_rfct_to_prob(VP8_COMP *const cpi)
-{
-    const int *const rfct = cpi->mb.count_mb_ref_frame_usage;
-    const int rf_intra = rfct[INTRA_FRAME];
-    const int rf_inter = rfct[LAST_FRAME] + rfct[GOLDEN_FRAME] + rfct[ALTREF_FRAME];
-
-    /* Calculate the probabilities used to code the ref frame based on usage */
-    if (!(cpi->prob_intra_coded = rf_intra * 255 / (rf_intra + rf_inter)))
-        cpi->prob_intra_coded = 1;
-
-    cpi->prob_last_coded = rf_inter ? (rfct[LAST_FRAME] * 255) / rf_inter : 128;
-
-    if (!cpi->prob_last_coded)
-        cpi->prob_last_coded = 1;
-
-    cpi->prob_gf_coded = (rfct[GOLDEN_FRAME] + rfct[ALTREF_FRAME])
-                  ? (rfct[GOLDEN_FRAME] * 255) / (rfct[GOLDEN_FRAME] + rfct[ALTREF_FRAME]) : 128;
-
-    if (!cpi->prob_gf_coded)
-        cpi->prob_gf_coded = 1;
-
-}
-
-static void pack_inter_mode_mvs(VP8_COMP *const cpi)
-{
-    VP8_COMMON *const pc = & cpi->common;
-    vp8_writer *const w = cpi->bc;
-    const MV_CONTEXT *mvc = pc->fc.mvc;
-
-
-    MODE_INFO *m = pc->mi;
-    const int mis = pc->mode_info_stride;
-    int mb_row = -1;
-
-    int prob_skip_false = 0;
-
-    cpi->mb.partition_info = cpi->mb.pi;
-
-    vp8_convert_rfct_to_prob(cpi);
-
-#ifdef VP8_ENTROPY_STATS
-    active_section = 1;
-#endif
-
-    if (pc->mb_no_coeff_skip)
-    {
-        int total_mbs = pc->mb_rows * pc->mb_cols;
-
-        prob_skip_false = (total_mbs - cpi->mb.skip_true_count ) * 256 / total_mbs;
-
-        if (prob_skip_false <= 1)
-            prob_skip_false = 1;
-
-        if (prob_skip_false > 255)
-            prob_skip_false = 255;
-
-        cpi->prob_skip_false = prob_skip_false;
-        vp8_write_literal(w, prob_skip_false, 8);
-    }
-
-    vp8_write_literal(w, cpi->prob_intra_coded, 8);
-    vp8_write_literal(w, cpi->prob_last_coded, 8);
-    vp8_write_literal(w, cpi->prob_gf_coded, 8);
-
-    update_mbintra_mode_probs(cpi);
-
-    vp8_write_mvprobs(cpi);
-
-    while (++mb_row < pc->mb_rows)
-    {
-        int mb_col = -1;
-
-        while (++mb_col < pc->mb_cols)
-        {
-            const MB_MODE_INFO *const mi = & m->mbmi;
-            const MV_REFERENCE_FRAME rf = mi->ref_frame;
-            const MB_PREDICTION_MODE mode = mi->mode;
-
-            MACROBLOCKD *xd = &cpi->mb.e_mbd;
-
-            /* Distance of Mb to the various image edges.
-             * These specified to 8th pel as they are always compared to MV
-             * values that are in 1/8th pel units
-             */
-            xd->mb_to_left_edge = -((mb_col * 16) << 3);
-            xd->mb_to_right_edge = ((pc->mb_cols - 1 - mb_col) * 16) << 3;
-            xd->mb_to_top_edge = -((mb_row * 16) << 3);
-            xd->mb_to_bottom_edge = ((pc->mb_rows - 1 - mb_row) * 16) << 3;
-
-#ifdef VP8_ENTROPY_STATS
-            active_section = 9;
-#endif
-
-            if (cpi->mb.e_mbd.update_mb_segmentation_map)
-                write_mb_features(w, mi, &cpi->mb.e_mbd);
-
-            if (pc->mb_no_coeff_skip)
-                vp8_encode_bool(w, m->mbmi.mb_skip_coeff, prob_skip_false);
-
-            if (rf == INTRA_FRAME)
-            {
-                vp8_write(w, 0, cpi->prob_intra_coded);
-#ifdef VP8_ENTROPY_STATS
-                active_section = 6;
-#endif
-                write_ymode(w, mode, pc->fc.ymode_prob);
-
-                if (mode == B_PRED)
-                {
-                    int j = 0;
-
-                    do
-                        write_bmode(w, m->bmi[j].as_mode, pc->fc.bmode_prob);
-                    while (++j < 16);
-                }
-
-                write_uv_mode(w, mi->uv_mode, pc->fc.uv_mode_prob);
-            }
-            else    /* inter coded */
-            {
-                int_mv best_mv;
-                vp8_prob mv_ref_p [VP8_MVREFS-1];
-
-                vp8_write(w, 1, cpi->prob_intra_coded);
-
-                if (rf == LAST_FRAME)
-                    vp8_write(w, 0, cpi->prob_last_coded);
-                else
-                {
-                    vp8_write(w, 1, cpi->prob_last_coded);
-                    vp8_write(w, (rf == GOLDEN_FRAME) ? 0 : 1, cpi->prob_gf_coded);
-                }
-
-                {
-                    int_mv n1, n2;
-                    int ct[4];
-
-                    vp8_find_near_mvs(xd, m, &n1, &n2, &best_mv, ct, rf, cpi->common.ref_frame_sign_bias);
-                    vp8_clamp_mv2(&best_mv, xd);
-
-                    vp8_mv_ref_probs(mv_ref_p, ct);
-
-#ifdef VP8_ENTROPY_STATS
-                    accum_mv_refs(mode, ct);
-#endif
-
-                }
-
-#ifdef VP8_ENTROPY_STATS
-                active_section = 3;
-#endif
-
-                write_mv_ref(w, mode, mv_ref_p);
-
-                switch (mode)   /* new, split require MVs */
-                {
-                case NEWMV:
-
-#ifdef VP8_ENTROPY_STATS
-                    active_section = 5;
-#endif
-
-                    write_mv(w, &mi->mv.as_mv, &best_mv, mvc);
-                    break;
-
-                case SPLITMV:
-                {
-                    int j = 0;
-
-#ifdef MODE_STATS
-                    ++count_mb_seg [mi->partitioning];
-#endif
-
-                    write_split(w, mi->partitioning);
-
-                    do
-                    {
-                        B_PREDICTION_MODE blockmode;
-                        int_mv blockmv;
-                        const int *const  L = vp8_mbsplits [mi->partitioning];
-                        int k = -1;  /* first block in subset j */
-                        int mv_contz;
-                        int_mv leftmv, abovemv;
-
-                        blockmode =  cpi->mb.partition_info->bmi[j].mode;
-                        blockmv =  cpi->mb.partition_info->bmi[j].mv;
-#if CONFIG_DEBUG
-                        while (j != L[++k])
-                            if (k >= 16)
-                                assert(0);
-#else
-                        while (j != L[++k]);
-#endif
-                        leftmv.as_int = left_block_mv(m, k);
-                        abovemv.as_int = above_block_mv(m, k, mis);
-                        mv_contz = vp8_mv_cont(&leftmv, &abovemv);
-
-                        write_sub_mv_ref(w, blockmode, vp8_sub_mv_ref_prob2 [mv_contz]);
-
-                        if (blockmode == NEW4X4)
-                        {
-#ifdef VP8_ENTROPY_STATS
-                            active_section = 11;
-#endif
-                            write_mv(w, &blockmv.as_mv, &best_mv, (const MV_CONTEXT *) mvc);
-                        }
-                    }
-                    while (++j < cpi->mb.partition_info->count);
-                }
-                break;
-                default:
-                    break;
-                }
-            }
-
-            ++m;
-            cpi->mb.partition_info++;
-        }
-
-        ++m;  /* skip L prediction border */
-        cpi->mb.partition_info++;
-    }
-}
-
-
-static void write_kfmodes(VP8_COMP *cpi)
-{
-    vp8_writer *const bc = cpi->bc;
-    const VP8_COMMON *const c = & cpi->common;
-    /* const */
-    MODE_INFO *m = c->mi;
-
-    int mb_row = -1;
-    int prob_skip_false = 0;
-
-    if (c->mb_no_coeff_skip)
-    {
-        int total_mbs = c->mb_rows * c->mb_cols;
-
-        prob_skip_false = (total_mbs - cpi->mb.skip_true_count ) * 256 / total_mbs;
-
-        if (prob_skip_false <= 1)
-            prob_skip_false = 1;
-
-        if (prob_skip_false >= 255)
-            prob_skip_false = 255;
-
-        cpi->prob_skip_false = prob_skip_false;
-        vp8_write_literal(bc, prob_skip_false, 8);
-    }
-
-    while (++mb_row < c->mb_rows)
-    {
-        int mb_col = -1;
-
-        while (++mb_col < c->mb_cols)
-        {
-            const int ym = m->mbmi.mode;
-
-            if (cpi->mb.e_mbd.update_mb_segmentation_map)
-                write_mb_features(bc, &m->mbmi, &cpi->mb.e_mbd);
-
-            if (c->mb_no_coeff_skip)
-                vp8_encode_bool(bc, m->mbmi.mb_skip_coeff, prob_skip_false);
-
-            kfwrite_ymode(bc, ym, vp8_kf_ymode_prob);
-
-            if (ym == B_PRED)
-            {
-                const int mis = c->mode_info_stride;
-                int i = 0;
-
-                do
-                {
-                    const B_PREDICTION_MODE A = above_block_mode(m, i, mis);
-                    const B_PREDICTION_MODE L = left_block_mode(m, i);
-                    const int bm = m->bmi[i].as_mode;
-
-#ifdef VP8_ENTROPY_STATS
-                    ++intra_mode_stats [A] [L] [bm];
-#endif
-
-                    write_bmode(bc, bm, vp8_kf_bmode_prob [A] [L]);
-                }
-                while (++i < 16);
-            }
-
-            write_uv_mode(bc, (m++)->mbmi.uv_mode, vp8_kf_uv_mode_prob);
-        }
-
-        m++;    /* skip L prediction border */
-    }
-}
-
-#if 0
-/* This function is used for debugging probability trees. */
-static void print_prob_tree(vp8_prob
-     coef_probs[BLOCK_TYPES][COEF_BANDS][PREV_COEF_CONTEXTS][ENTROPY_NODES])
-{
-    /* print coef probability tree */
-    int i,j,k,l;
-    FILE* f = fopen("enc_tree_probs.txt", "a");
-    fprintf(f, "{\n");
-    for (i = 0; i < BLOCK_TYPES; i++)
-    {
-        fprintf(f, "  {\n");
-        for (j = 0; j < COEF_BANDS; j++)
-        {
-            fprintf(f, "    {\n");
-            for (k = 0; k < PREV_COEF_CONTEXTS; k++)
-            {
-                fprintf(f, "      {");
-                for (l = 0; l < ENTROPY_NODES; l++)
-                {
-                    fprintf(f, "%3u, ",
-                            (unsigned int)(coef_probs [i][j][k][l]));
-                }
-                fprintf(f, " }\n");
-            }
-            fprintf(f, "    }\n");
-        }
-        fprintf(f, "  }\n");
-    }
-    fprintf(f, "}\n");
-    fclose(f);
-}
-#endif
-
-static void sum_probs_over_prev_coef_context(
-        const unsigned int probs[PREV_COEF_CONTEXTS][MAX_ENTROPY_TOKENS],
-        unsigned int* out)
-{
-    int i, j;
-    for (i=0; i < MAX_ENTROPY_TOKENS; ++i)
-    {
-        for (j=0; j < PREV_COEF_CONTEXTS; ++j)
-        {
-            const unsigned int tmp = out[i];
-            out[i] += probs[j][i];
-            /* check for wrap */
-            if (out[i] < tmp)
-                out[i] = UINT_MAX;
-        }
-    }
-}
-
-static int prob_update_savings(const unsigned int *ct,
-                                   const vp8_prob oldp, const vp8_prob newp,
-                                   const vp8_prob upd)
-{
-    const int old_b = vp8_cost_branch(ct, oldp);
-    const int new_b = vp8_cost_branch(ct, newp);
-    const int update_b = 8 +
-                         ((vp8_cost_one(upd) - vp8_cost_zero(upd)) >> 8);
-
-    return old_b - new_b - update_b;
-}
-
-static int independent_coef_context_savings(VP8_COMP *cpi)
-{
-    MACROBLOCK *const x = & cpi->mb;
-    int savings = 0;
-    int i = 0;
-    do
-    {
-        int j = 0;
-        do
-        {
-            int k = 0;
-            unsigned int prev_coef_count_sum[MAX_ENTROPY_TOKENS] = {0};
-            int prev_coef_savings[MAX_ENTROPY_TOKENS] = {0};
-            const unsigned int (*probs)[MAX_ENTROPY_TOKENS];
-            /* Calculate new probabilities given the constraint that
-             * they must be equal over the prev coef contexts
-             */
-
-            probs = (const unsigned int (*)[MAX_ENTROPY_TOKENS])
-                x->coef_counts[i][j];
-
-            /* Reset to default probabilities at key frames */
-            if (cpi->common.frame_type == KEY_FRAME)
-                probs = default_coef_counts[i][j];
-
-            sum_probs_over_prev_coef_context(probs, prev_coef_count_sum);
-
-            do
-            {
-                /* at every context */
-
-                /* calc probs and branch cts for this frame only */
-                int t = 0;      /* token/prob index */
-
-                vp8_tree_probs_from_distribution(
-                    MAX_ENTROPY_TOKENS, vp8_coef_encodings, vp8_coef_tree,
-                    cpi->frame_coef_probs[i][j][k],
-                    cpi->frame_branch_ct [i][j][k],
-                    prev_coef_count_sum,
-                    256, 1);
-
-                do
-                {
-                    const unsigned int *ct  = cpi->frame_branch_ct [i][j][k][t];
-                    const vp8_prob newp = cpi->frame_coef_probs [i][j][k][t];
-                    const vp8_prob oldp = cpi->common.fc.coef_probs [i][j][k][t];
-                    const vp8_prob upd = vp8_coef_update_probs [i][j][k][t];
-                    const int s = prob_update_savings(ct, oldp, newp, upd);
-
-                    if (cpi->common.frame_type != KEY_FRAME ||
-                        (cpi->common.frame_type == KEY_FRAME && newp != oldp))
-                        prev_coef_savings[t] += s;
-                }
-                while (++t < ENTROPY_NODES);
-            }
-            while (++k < PREV_COEF_CONTEXTS);
-            k = 0;
-            do
-            {
-                /* We only update probabilities if we can save bits, except
-                 * for key frames where we have to update all probabilities
-                 * to get the equal probabilities across the prev coef
-                 * contexts.
-                 */
-                if (prev_coef_savings[k] > 0 ||
-                    cpi->common.frame_type == KEY_FRAME)
-                    savings += prev_coef_savings[k];
-            }
-            while (++k < ENTROPY_NODES);
-        }
-        while (++j < COEF_BANDS);
-    }
-    while (++i < BLOCK_TYPES);
-    return savings;
-}
-
-static int default_coef_context_savings(VP8_COMP *cpi)
-{
-    MACROBLOCK *const x = & cpi->mb;
-    int savings = 0;
-    int i = 0;
-    do
-    {
-        int j = 0;
-        do
-        {
-            int k = 0;
-            do
-            {
-                /* at every context */
-
-                /* calc probs and branch cts for this frame only */
-                int t = 0;      /* token/prob index */
-
-                vp8_tree_probs_from_distribution(
-                    MAX_ENTROPY_TOKENS, vp8_coef_encodings, vp8_coef_tree,
-                    cpi->frame_coef_probs [i][j][k],
-                    cpi->frame_branch_ct [i][j][k],
-                    x->coef_counts [i][j][k],
-                    256, 1
-                );
-
-                do
-                {
-                    const unsigned int *ct  = cpi->frame_branch_ct [i][j][k][t];
-                    const vp8_prob newp = cpi->frame_coef_probs [i][j][k][t];
-                    const vp8_prob oldp = cpi->common.fc.coef_probs [i][j][k][t];
-                    const vp8_prob upd = vp8_coef_update_probs [i][j][k][t];
-                    const int s = prob_update_savings(ct, oldp, newp, upd);
-
-                    if (s > 0)
-                    {
-                        savings += s;
-                    }
-                }
-                while (++t < ENTROPY_NODES);
-            }
-            while (++k < PREV_COEF_CONTEXTS);
-        }
-        while (++j < COEF_BANDS);
-    }
-    while (++i < BLOCK_TYPES);
-    return savings;
-}
-
-void vp8_calc_ref_frame_costs(int *ref_frame_cost,
-                              int prob_intra,
-                              int prob_last,
-                              int prob_garf
-                             )
-{
-    assert(prob_intra >= 0);
-    assert(prob_intra <= 255);
-    assert(prob_last >= 0);
-    assert(prob_last <= 255);
-    assert(prob_garf >= 0);
-    assert(prob_garf <= 255);
-    ref_frame_cost[INTRA_FRAME]   = vp8_cost_zero(prob_intra);
-    ref_frame_cost[LAST_FRAME]    = vp8_cost_one(prob_intra)
-                                    + vp8_cost_zero(prob_last);
-    ref_frame_cost[GOLDEN_FRAME]  = vp8_cost_one(prob_intra)
-                                    + vp8_cost_one(prob_last)
-                                    + vp8_cost_zero(prob_garf);
-    ref_frame_cost[ALTREF_FRAME]  = vp8_cost_one(prob_intra)
-                                    + vp8_cost_one(prob_last)
-                                    + vp8_cost_one(prob_garf);
-
-}
-
-int vp8_estimate_entropy_savings(VP8_COMP *cpi)
-{
-    int savings = 0;
-
-    const int *const rfct = cpi->mb.count_mb_ref_frame_usage;
-    const int rf_intra = rfct[INTRA_FRAME];
-    const int rf_inter = rfct[LAST_FRAME] + rfct[GOLDEN_FRAME] + rfct[ALTREF_FRAME];
-    int new_intra, new_last, new_garf, oldtotal, newtotal;
-    int ref_frame_cost[MAX_REF_FRAMES];
-
-    vp8_clear_system_state();
-
-    if (cpi->common.frame_type != KEY_FRAME)
-    {
-        if (!(new_intra = rf_intra * 255 / (rf_intra + rf_inter)))
-            new_intra = 1;
-
-        new_last = rf_inter ? (rfct[LAST_FRAME] * 255) / rf_inter : 128;
-
-        new_garf = (rfct[GOLDEN_FRAME] + rfct[ALTREF_FRAME])
-                  ? (rfct[GOLDEN_FRAME] * 255) / (rfct[GOLDEN_FRAME] + rfct[ALTREF_FRAME]) : 128;
-
-
-        vp8_calc_ref_frame_costs(ref_frame_cost,new_intra,new_last,new_garf);
-
-        newtotal =
-            rfct[INTRA_FRAME] * ref_frame_cost[INTRA_FRAME] +
-            rfct[LAST_FRAME] * ref_frame_cost[LAST_FRAME] +
-            rfct[GOLDEN_FRAME] * ref_frame_cost[GOLDEN_FRAME] +
-            rfct[ALTREF_FRAME] * ref_frame_cost[ALTREF_FRAME];
-
-
-        /* old costs */
-        vp8_calc_ref_frame_costs(ref_frame_cost,cpi->prob_intra_coded,
-                                 cpi->prob_last_coded,cpi->prob_gf_coded);
-
-        oldtotal =
-            rfct[INTRA_FRAME] * ref_frame_cost[INTRA_FRAME] +
-            rfct[LAST_FRAME] * ref_frame_cost[LAST_FRAME] +
-            rfct[GOLDEN_FRAME] * ref_frame_cost[GOLDEN_FRAME] +
-            rfct[ALTREF_FRAME] * ref_frame_cost[ALTREF_FRAME];
-
-        savings += (oldtotal - newtotal) / 256;
-    }
-
-
-    if (cpi->oxcf.error_resilient_mode & VPX_ERROR_RESILIENT_PARTITIONS)
-        savings += independent_coef_context_savings(cpi);
-    else
-        savings += default_coef_context_savings(cpi);
-
-
-    return savings;
-}
-
-#if CONFIG_REALTIME_ONLY & CONFIG_ONTHEFLY_BITPACKING
-int vp8_update_coef_context(VP8_COMP *cpi)
-{
-    int savings = 0;
-
-
-    if (cpi->common.frame_type == KEY_FRAME)
-    {
-        /* Reset to default counts/probabilities at key frames */
-        vp8_copy(cpi->mb.coef_counts, default_coef_counts);
-    }
-
-    if (cpi->oxcf.error_resilient_mode & VPX_ERROR_RESILIENT_PARTITIONS)
-        savings += independent_coef_context_savings(cpi);
-    else
-        savings += default_coef_context_savings(cpi);
-
-    return savings;
-}
-#endif
-
-void vp8_update_coef_probs(VP8_COMP *cpi)
-{
-    int i = 0;
-#if !(CONFIG_REALTIME_ONLY & CONFIG_ONTHEFLY_BITPACKING)
-    vp8_writer *const w = cpi->bc;
-#endif
-    int savings = 0;
-
-    vp8_clear_system_state();
-
-    do
-    {
-        int j = 0;
-
-        do
-        {
-            int k = 0;
-            int prev_coef_savings[ENTROPY_NODES] = {0};
-            if (cpi->oxcf.error_resilient_mode & VPX_ERROR_RESILIENT_PARTITIONS)
-            {
-                for (k = 0; k < PREV_COEF_CONTEXTS; ++k)
-                {
-                    int t;      /* token/prob index */
-                    for (t = 0; t < ENTROPY_NODES; ++t)
-                    {
-                        const unsigned int *ct = cpi->frame_branch_ct [i][j]
-                                                                      [k][t];
-                        const vp8_prob newp = cpi->frame_coef_probs[i][j][k][t];
-                        const vp8_prob oldp = cpi->common.fc.coef_probs[i][j]
-                                                                       [k][t];
-                        const vp8_prob upd = vp8_coef_update_probs[i][j][k][t];
-
-                        prev_coef_savings[t] +=
-                                prob_update_savings(ct, oldp, newp, upd);
-                    }
-                }
-                k = 0;
-            }
-            do
-            {
-                /* note: use result from vp8_estimate_entropy_savings, so no
-                 * need to call vp8_tree_probs_from_distribution here.
-                 */
-
-                /* at every context */
-
-                /* calc probs and branch cts for this frame only */
-                int t = 0;      /* token/prob index */
-
-                do
-                {
-                    const vp8_prob newp = cpi->frame_coef_probs [i][j][k][t];
-
-                    vp8_prob *Pold = cpi->common.fc.coef_probs [i][j][k] + t;
-                    const vp8_prob upd = vp8_coef_update_probs [i][j][k][t];
-
-                    int s = prev_coef_savings[t];
-                    int u = 0;
-
-                    if (!(cpi->oxcf.error_resilient_mode &
-                            VPX_ERROR_RESILIENT_PARTITIONS))
-                    {
-                        s = prob_update_savings(
-                                cpi->frame_branch_ct [i][j][k][t],
-                                *Pold, newp, upd);
-                    }
-
-                    if (s > 0)
-                        u = 1;
-
-                    /* Force updates on key frames if the new is different,
-                     * so that we can be sure we end up with equal probabilities
-                     * over the prev coef contexts.
-                     */
-                    if ((cpi->oxcf.error_resilient_mode &
-                            VPX_ERROR_RESILIENT_PARTITIONS) &&
-                        cpi->common.frame_type == KEY_FRAME && newp != *Pold)
-                        u = 1;
-
-#if CONFIG_REALTIME_ONLY & CONFIG_ONTHEFLY_BITPACKING
-                    cpi->update_probs[i][j][k][t] = u;
-#else
-                    vp8_write(w, u, upd);
-#endif
-
-
-#ifdef VP8_ENTROPY_STATS
-                    ++ tree_update_hist [i][j][k][t] [u];
-#endif
-
-                    if (u)
-                    {
-                        /* send/use new probability */
-
-                        *Pold = newp;
-#if !(CONFIG_REALTIME_ONLY & CONFIG_ONTHEFLY_BITPACKING)
-                        vp8_write_literal(w, newp, 8);
-#endif
-
-                        savings += s;
-
-                    }
-
-                }
-                while (++t < ENTROPY_NODES);
-
-                /* Accum token counts for generation of default statistics */
-#ifdef VP8_ENTROPY_STATS
-                t = 0;
-
-                do
-                {
-                    context_counters [i][j][k][t] += cpi->coef_counts [i][j][k][t];
-                }
-                while (++t < MAX_ENTROPY_TOKENS);
-
-#endif
-
-            }
-            while (++k < PREV_COEF_CONTEXTS);
-        }
-        while (++j < COEF_BANDS);
-    }
-    while (++i < BLOCK_TYPES);
-
-}
-
-#if CONFIG_REALTIME_ONLY & CONFIG_ONTHEFLY_BITPACKING
-static void pack_coef_probs(VP8_COMP *cpi)
-{
-    int i = 0;
-    vp8_writer *const w = cpi->bc;
-
-    do
-    {
-        int j = 0;
-
-        do
-        {
-            int k = 0;
-
-            do
-            {
-                int t = 0;      /* token/prob index */
-
-                do
-                {
-                    const vp8_prob newp = cpi->common.fc.coef_probs [i][j][k][t];
-                    const vp8_prob upd = vp8_coef_update_probs [i][j][k][t];
-
-                    const char u = cpi->update_probs[i][j][k][t] ;
-
-                    vp8_write(w, u, upd);
-
-                    if (u)
-                    {
-                        /* send/use new probability */
-                        vp8_write_literal(w, newp, 8);
-                    }
-                }
-                while (++t < ENTROPY_NODES);
-            }
-            while (++k < PREV_COEF_CONTEXTS);
-        }
-        while (++j < COEF_BANDS);
-    }
-    while (++i < BLOCK_TYPES);
-}
-#endif
-
-#ifdef PACKET_TESTING
-FILE *vpxlogc = 0;
-#endif
-
-static void put_delta_q(vp8_writer *bc, int delta_q)
-{
-    if (delta_q != 0)
-    {
-        vp8_write_bit(bc, 1);
-        vp8_write_literal(bc, abs(delta_q), 4);
-
-        if (delta_q < 0)
-            vp8_write_bit(bc, 1);
-        else
-            vp8_write_bit(bc, 0);
-    }
-    else
-        vp8_write_bit(bc, 0);
-}
-
-void vp8_pack_bitstream(VP8_COMP *cpi, unsigned char *dest, unsigned char * dest_end, unsigned long *size)
-{
-    int i, j;
-    VP8_HEADER oh;
-    VP8_COMMON *const pc = & cpi->common;
-    vp8_writer *const bc = cpi->bc;
-    MACROBLOCKD *const xd = & cpi->mb.e_mbd;
-    int extra_bytes_packed = 0;
-
-    unsigned char *cx_data = dest;
-    unsigned char *cx_data_end = dest_end;
-    const int *mb_feature_data_bits;
-
-    oh.show_frame = (int) pc->show_frame;
-    oh.type = (int)pc->frame_type;
-    oh.version = pc->version;
-    oh.first_partition_length_in_bytes = 0;
-
-    mb_feature_data_bits = vp8_mb_feature_data_bits;
-
-    bc[0].error = &pc->error;
-
-    validate_buffer(cx_data, 3, cx_data_end, &cpi->common.error);
-    cx_data += 3;
-
-#if defined(SECTIONBITS_OUTPUT)
-    Sectionbits[active_section = 1] += sizeof(VP8_HEADER) * 8 * 256;
-#endif
-
-    /* every keyframe send startcode, width, height, scale factor, clamp
-     * and color type
-     */
-    if (oh.type == KEY_FRAME)
-    {
-        int v;
-
-        validate_buffer(cx_data, 7, cx_data_end, &cpi->common.error);
-
-        /* Start / synch code */
-        cx_data[0] = 0x9D;
-        cx_data[1] = 0x01;
-        cx_data[2] = 0x2a;
-
-        v = (pc->horiz_scale << 14) | pc->Width;
-        cx_data[3] = v;
-        cx_data[4] = v >> 8;
-
-        v = (pc->vert_scale << 14) | pc->Height;
-        cx_data[5] = v;
-        cx_data[6] = v >> 8;
-
-
-        extra_bytes_packed = 7;
-        cx_data += extra_bytes_packed ;
-
-        vp8_start_encode(bc, cx_data, cx_data_end);
-
-        /* signal clr type */
-        vp8_write_bit(bc, 0);
-        vp8_write_bit(bc, pc->clamp_type);
-
-    }
-    else
-        vp8_start_encode(bc, cx_data, cx_data_end);
-
-
-    /* Signal whether or not Segmentation is enabled */
-    vp8_write_bit(bc, xd->segmentation_enabled);
-
-    /*  Indicate which features are enabled */
-    if (xd->segmentation_enabled)
-    {
-        /* Signal whether or not the segmentation map is being updated. */
-        vp8_write_bit(bc, xd->update_mb_segmentation_map);
-        vp8_write_bit(bc, xd->update_mb_segmentation_data);
-
-        if (xd->update_mb_segmentation_data)
-        {
-            signed char Data;
-
-            vp8_write_bit(bc, xd->mb_segement_abs_delta);
-
-            /* For each segmentation feature (Quant and loop filter level) */
-            for (i = 0; i < MB_LVL_MAX; i++)
-            {
-                /* For each of the segments */
-                for (j = 0; j < MAX_MB_SEGMENTS; j++)
-                {
-                    Data = xd->segment_feature_data[i][j];
-
-                    /* Frame level data */
-                    if (Data)
-                    {
-                        vp8_write_bit(bc, 1);
-
-                        if (Data < 0)
-                        {
-                            Data = - Data;
-                            vp8_write_literal(bc, Data, mb_feature_data_bits[i]);
-                            vp8_write_bit(bc, 1);
-                        }
-                        else
-                        {
-                            vp8_write_literal(bc, Data, mb_feature_data_bits[i]);
-                            vp8_write_bit(bc, 0);
-                        }
-                    }
-                    else
-                        vp8_write_bit(bc, 0);
-                }
-            }
-        }
-
-        if (xd->update_mb_segmentation_map)
-        {
-            /* Write the probs used to decode the segment id for each mb */
-            for (i = 0; i < MB_FEATURE_TREE_PROBS; i++)
-            {
-                int Data = xd->mb_segment_tree_probs[i];
-
-                if (Data != 255)
-                {
-                    vp8_write_bit(bc, 1);
-                    vp8_write_literal(bc, Data, 8);
-                }
-                else
-                    vp8_write_bit(bc, 0);
-            }
-        }
-    }
-
-    vp8_write_bit(bc, pc->filter_type);
-    vp8_write_literal(bc, pc->filter_level, 6);
-    vp8_write_literal(bc, pc->sharpness_level, 3);
-
-    /* Write out loop filter deltas applied at the MB level based on mode
-     * or ref frame (if they are enabled).
-     */
-    vp8_write_bit(bc, xd->mode_ref_lf_delta_enabled);
-
-    if (xd->mode_ref_lf_delta_enabled)
-    {
-        /* Do the deltas need to be updated */
-        int send_update = xd->mode_ref_lf_delta_update
-                          || cpi->oxcf.error_resilient_mode;
-
-        vp8_write_bit(bc, send_update);
-        if (send_update)
-        {
-            int Data;
-
-            /* Send update */
-            for (i = 0; i < MAX_REF_LF_DELTAS; i++)
-            {
-                Data = xd->ref_lf_deltas[i];
-
-                /* Frame level data */
-                if (xd->ref_lf_deltas[i] != xd->last_ref_lf_deltas[i]
-                    || cpi->oxcf.error_resilient_mode)
-                {
-                    xd->last_ref_lf_deltas[i] = xd->ref_lf_deltas[i];
-                    vp8_write_bit(bc, 1);
-
-                    if (Data > 0)
-                    {
-                        vp8_write_literal(bc, (Data & 0x3F), 6);
-                        vp8_write_bit(bc, 0);    /* sign */
-                    }
-                    else
-                    {
-                        Data = -Data;
-                        vp8_write_literal(bc, (Data & 0x3F), 6);
-                        vp8_write_bit(bc, 1);    /* sign */
-                    }
-                }
-                else
-                    vp8_write_bit(bc, 0);
-            }
-
-            /* Send update */
-            for (i = 0; i < MAX_MODE_LF_DELTAS; i++)
-            {
-                Data = xd->mode_lf_deltas[i];
-
-                if (xd->mode_lf_deltas[i] != xd->last_mode_lf_deltas[i]
-                    || cpi->oxcf.error_resilient_mode)
-                {
-                    xd->last_mode_lf_deltas[i] = xd->mode_lf_deltas[i];
-                    vp8_write_bit(bc, 1);
-
-                    if (Data > 0)
-                    {
-                        vp8_write_literal(bc, (Data & 0x3F), 6);
-                        vp8_write_bit(bc, 0);    /* sign */
-                    }
-                    else
-                    {
-                        Data = -Data;
-                        vp8_write_literal(bc, (Data & 0x3F), 6);
-                        vp8_write_bit(bc, 1);    /* sign */
-                    }
-                }
-                else
-                    vp8_write_bit(bc, 0);
-            }
-        }
-    }
-
-    /* signal here is multi token partition is enabled */
-    vp8_write_literal(bc, pc->multi_token_partition, 2);
-
-    /* Frame Qbaseline quantizer index */
-    vp8_write_literal(bc, pc->base_qindex, 7);
-
-    /* Transmit Dc, Second order and Uv quantizer delta information */
-    put_delta_q(bc, pc->y1dc_delta_q);
-    put_delta_q(bc, pc->y2dc_delta_q);
-    put_delta_q(bc, pc->y2ac_delta_q);
-    put_delta_q(bc, pc->uvdc_delta_q);
-    put_delta_q(bc, pc->uvac_delta_q);
-
-    /* When there is a key frame all reference buffers are updated using
-     * the new key frame
-     */
-    if (pc->frame_type != KEY_FRAME)
-    {
-        /* Should the GF or ARF be updated using the transmitted frame
-         * or buffer
-         */
-        vp8_write_bit(bc, pc->refresh_golden_frame);
-        vp8_write_bit(bc, pc->refresh_alt_ref_frame);
-
-        /* If not being updated from current frame should either GF or ARF
-         * be updated from another buffer
-         */
-        if (!pc->refresh_golden_frame)
-            vp8_write_literal(bc, pc->copy_buffer_to_gf, 2);
-
-        if (!pc->refresh_alt_ref_frame)
-            vp8_write_literal(bc, pc->copy_buffer_to_arf, 2);
-
-        /* Indicate reference frame sign bias for Golden and ARF frames
-         * (always 0 for last frame buffer)
-         */
-        vp8_write_bit(bc, pc->ref_frame_sign_bias[GOLDEN_FRAME]);
-        vp8_write_bit(bc, pc->ref_frame_sign_bias[ALTREF_FRAME]);
-    }
-
-#if !(CONFIG_REALTIME_ONLY & CONFIG_ONTHEFLY_BITPACKING)
-    if (cpi->oxcf.error_resilient_mode & VPX_ERROR_RESILIENT_PARTITIONS)
-    {
-        if (pc->frame_type == KEY_FRAME)
-            pc->refresh_entropy_probs = 1;
-        else
-            pc->refresh_entropy_probs = 0;
-    }
-#endif
-
-    vp8_write_bit(bc, pc->refresh_entropy_probs);
-
-    if (pc->frame_type != KEY_FRAME)
-        vp8_write_bit(bc, pc->refresh_last_frame);
-
-#ifdef VP8_ENTROPY_STATS
-
-    if (pc->frame_type == INTER_FRAME)
-        active_section = 0;
-    else
-        active_section = 7;
-
-#endif
-
-    vp8_clear_system_state();
-
-#if CONFIG_REALTIME_ONLY & CONFIG_ONTHEFLY_BITPACKING
-    pack_coef_probs(cpi);
-#else
-    if (pc->refresh_entropy_probs == 0)
-    {
-        /* save a copy for later refresh */
-        memcpy(&cpi->common.lfc, &cpi->common.fc, sizeof(cpi->common.fc));
-    }
-
-    vp8_update_coef_probs(cpi);
-#endif
-
-#ifdef VP8_ENTROPY_STATS
-    active_section = 2;
-#endif
-
-    /* Write out the mb_no_coeff_skip flag */
-    vp8_write_bit(bc, pc->mb_no_coeff_skip);
-
-    if (pc->frame_type == KEY_FRAME)
-    {
-        write_kfmodes(cpi);
-
-#ifdef VP8_ENTROPY_STATS
-        active_section = 8;
-#endif
-    }
-    else
-    {
-        pack_inter_mode_mvs(cpi);
-
-#ifdef VP8_ENTROPY_STATS
-        active_section = 1;
-#endif
-    }
-
-    vp8_stop_encode(bc);
-
-    cx_data += bc->pos;
-
-    oh.first_partition_length_in_bytes = cpi->bc->pos;
-
-    /* update frame tag */
-    {
-        int v = (oh.first_partition_length_in_bytes << 5) |
-                (oh.show_frame << 4) |
-                (oh.version << 1) |
-                oh.type;
-
-        dest[0] = v;
-        dest[1] = v >> 8;
-        dest[2] = v >> 16;
-    }
-
-    *size = VP8_HEADER_SIZE + extra_bytes_packed + cpi->bc->pos;
-
-    cpi->partition_sz[0] = *size;
-
-#if CONFIG_REALTIME_ONLY & CONFIG_ONTHEFLY_BITPACKING
-    {
-        const int num_part = (1 << pc->multi_token_partition);
-        unsigned char * dp = cpi->partition_d[0] + cpi->partition_sz[0];
-
-        if (num_part > 1)
-        {
-            /* write token part sizes (all but last) if more than 1 */
-            validate_buffer(dp, 3 * (num_part - 1), cpi->partition_d_end[0],
-                            &pc->error);
-
-            cpi->partition_sz[0] += 3*(num_part-1);
-
-            for(i = 1; i < num_part; i++)
-            {
-                write_partition_size(dp, cpi->partition_sz[i]);
-                dp += 3;
-            }
-        }
-
-        if (!cpi->output_partition)
-        {
-            /* concatenate partition buffers */
-            for(i = 0; i < num_part; i++)
-            {
-                memmove(dp, cpi->partition_d[i+1], cpi->partition_sz[i+1]);
-                cpi->partition_d[i+1] = dp;
-                dp += cpi->partition_sz[i+1];
-            }
-        }
-
-        /* update total size */
-        *size = 0;
-        for(i = 0; i < num_part+1; i++)
-        {
-            *size += cpi->partition_sz[i];
-        }
-    }
-#else
-    if (pc->multi_token_partition != ONE_PARTITION)
-    {
-        int num_part = 1 << pc->multi_token_partition;
-
-        /* partition size table at the end of first partition */
-        cpi->partition_sz[0] += 3 * (num_part - 1);
-        *size += 3 * (num_part - 1);
-
-        validate_buffer(cx_data, 3 * (num_part - 1), cx_data_end,
-                        &pc->error);
-
-        for(i = 1; i < num_part + 1; i++)
-        {
-            cpi->bc[i].error = &pc->error;
-        }
-
-        pack_tokens_into_partitions(cpi, cx_data + 3 * (num_part - 1),
-                                    cx_data_end, num_part);
-
-        for(i = 1; i < num_part; i++)
-        {
-            cpi->partition_sz[i] = cpi->bc[i].pos;
-            write_partition_size(cx_data, cpi->partition_sz[i]);
-            cx_data += 3;
-            *size += cpi->partition_sz[i]; /* add to total */
-        }
-
-        /* add last partition to total size */
-        cpi->partition_sz[i] = cpi->bc[i].pos;
-        *size += cpi->partition_sz[i];
-    }
-    else
-    {
-        bc[1].error = &pc->error;
-
-        vp8_start_encode(&cpi->bc[1], cx_data, cx_data_end);
-
-#if CONFIG_MULTITHREAD
-        if (cpi->b_multi_threaded)
-            pack_mb_row_tokens(cpi, &cpi->bc[1]);
-        else
-#endif  // CONFIG_MULTITHREAD
-            vp8_pack_tokens(&cpi->bc[1], cpi->tok, cpi->tok_count);
-
-        vp8_stop_encode(&cpi->bc[1]);
-
-        *size += cpi->bc[1].pos;
-        cpi->partition_sz[1] = cpi->bc[1].pos;
-    }
-#endif
-}
-
-#ifdef VP8_ENTROPY_STATS
-void print_tree_update_probs()
-{
-    int i, j, k, l;
-    FILE *f = fopen("context.c", "a");
-    int Sum;
-    fprintf(f, "\n/* Update probabilities for token entropy tree. */\n\n");
-    fprintf(f, "const vp8_prob tree_update_probs[BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [ENTROPY_NODES] = {\n");
-
-    for (i = 0; i < BLOCK_TYPES; i++)
-    {
-        fprintf(f, "  { \n");
-
-        for (j = 0; j < COEF_BANDS; j++)
-        {
-            fprintf(f, "    {\n");
-
-            for (k = 0; k < PREV_COEF_CONTEXTS; k++)
-            {
-                fprintf(f, "      {");
-
-                for (l = 0; l < ENTROPY_NODES; l++)
-                {
-                    Sum = tree_update_hist[i][j][k][l][0] + tree_update_hist[i][j][k][l][1];
-
-                    if (Sum > 0)
-                    {
-                        if (((tree_update_hist[i][j][k][l][0] * 255) / Sum) > 0)
-                            fprintf(f, "%3ld, ", (tree_update_hist[i][j][k][l][0] * 255) / Sum);
-                        else
-                            fprintf(f, "%3ld, ", 1);
-                    }
-                    else
-                        fprintf(f, "%3ld, ", 128);
-                }
-
-                fprintf(f, "},\n");
-            }
-
-            fprintf(f, "    },\n");
-        }
-
-        fprintf(f, "  },\n");
-    }
-
-    fprintf(f, "};\n");
-    fclose(f);
-}
-#endif
diff --git a/vp8/encoder/bitstream.h b/vp8/encoder/bitstream.h
deleted file mode 100644 (file)
index de69805..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#ifndef VP8_ENCODER_BITSTREAM_H_
-#define VP8_ENCODER_BITSTREAM_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-void vp8_pack_tokens(vp8_writer *w, const TOKENEXTRA *p, int xcount);
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP8_ENCODER_BITSTREAM_H_
diff --git a/vp8/encoder/block.h b/vp8/encoder/block.h
deleted file mode 100644 (file)
index 248e795..0000000
+++ /dev/null
@@ -1,175 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#ifndef VP8_ENCODER_BLOCK_H_
-#define VP8_ENCODER_BLOCK_H_
-
-#include "vp8/common/onyx.h"
-#include "vp8/common/blockd.h"
-#include "vp8/common/entropymv.h"
-#include "vp8/common/entropy.h"
-#include "vpx_ports/mem.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define MAX_MODES 20
-#define MAX_ERROR_BINS 1024
-
-/* motion search site */
-typedef struct
-{
-    MV mv;
-    int offset;
-} search_site;
-
-typedef struct block
-{
-    /* 16 Y blocks, 4 U blocks, 4 V blocks each with 16 entries */
-    short *src_diff;
-    short *coeff;
-
-    /* 16 Y blocks, 4 U blocks, 4 V blocks each with 16 entries */
-    short *quant;
-    short *quant_fast;
-    short *quant_shift;
-    short *zbin;
-    short *zrun_zbin_boost;
-    short *round;
-
-    /* Zbin Over Quant value */
-    short zbin_extra;
-
-    unsigned char **base_src;
-    int src;
-    int src_stride;
-} BLOCK;
-
-typedef struct
-{
-    int count;
-    struct
-    {
-        B_PREDICTION_MODE mode;
-        int_mv mv;
-    } bmi[16];
-} PARTITION_INFO;
-
-typedef struct macroblock
-{
-    DECLARE_ALIGNED(16, short, src_diff[400]); /* 25 blocks Y,U,V,Y2 */
-    DECLARE_ALIGNED(16, short, coeff[400]); /* 25 blocks Y,U,V,Y2 */
-    DECLARE_ALIGNED(16, unsigned char, thismb[256]);
-
-    unsigned char *thismb_ptr;
-    /* 16 Y, 4 U, 4 V, 1 DC 2nd order block */
-    BLOCK block[25];
-
-    YV12_BUFFER_CONFIG src;
-
-    MACROBLOCKD e_mbd;
-    PARTITION_INFO *partition_info; /* work pointer */
-    PARTITION_INFO *pi;   /* Corresponds to upper left visible macroblock */
-    PARTITION_INFO *pip;  /* Base of allocated array */
-
-    int ref_frame_cost[MAX_REF_FRAMES];
-
-    search_site *ss;
-    int ss_count;
-    int searches_per_step;
-
-    int errorperbit;
-    int sadperbit16;
-    int sadperbit4;
-    int rddiv;
-    int rdmult;
-    unsigned int * mb_activity_ptr;
-    int * mb_norm_activity_ptr;
-    signed int act_zbin_adj;
-    signed int last_act_zbin_adj;
-
-    int *mvcost[2];
-    int *mvsadcost[2];
-    int (*mbmode_cost)[MB_MODE_COUNT];
-    int (*intra_uv_mode_cost)[MB_MODE_COUNT];
-    int (*bmode_costs)[10][10];
-    int *inter_bmode_costs;
-    int (*token_costs)[COEF_BANDS][PREV_COEF_CONTEXTS]
-    [MAX_ENTROPY_TOKENS];
-
-    /* These define limits to motion vector components to prevent
-     * them from extending outside the UMV borders.
-     */
-    int mv_col_min;
-    int mv_col_max;
-    int mv_row_min;
-    int mv_row_max;
-
-    int skip;
-
-    unsigned int encode_breakout;
-
-    signed char *gf_active_ptr;
-
-    unsigned char *active_ptr;
-    MV_CONTEXT *mvc;
-
-    int optimize;
-    int q_index;
-    int is_skin;
-    int denoise_zeromv;
-
-#if CONFIG_TEMPORAL_DENOISING
-    int increase_denoising;
-    MB_PREDICTION_MODE best_sse_inter_mode;
-    int_mv best_sse_mv;
-    MV_REFERENCE_FRAME best_reference_frame;
-    MV_REFERENCE_FRAME best_zeromv_reference_frame;
-    unsigned char need_to_clamp_best_mvs;
-#endif
-
-    int skip_true_count;
-    unsigned int coef_counts [BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [MAX_ENTROPY_TOKENS];
-    unsigned int MVcount [2] [MVvals];  /* (row,col) MV cts this frame */
-    int ymode_count [VP8_YMODES];        /* intra MB type cts this frame */
-    int uv_mode_count[VP8_UV_MODES];     /* intra MB type cts this frame */
-    int64_t prediction_error;
-    int64_t intra_error;
-    int count_mb_ref_frame_usage[MAX_REF_FRAMES];
-
-    int rd_thresh_mult[MAX_MODES];
-    int rd_threshes[MAX_MODES];
-    unsigned int mbs_tested_so_far;
-    unsigned int mode_test_hit_counts[MAX_MODES];
-    int zbin_mode_boost_enabled;
-    int zbin_mode_boost;
-    int last_zbin_mode_boost;
-
-    int last_zbin_over_quant;
-    int zbin_over_quant;
-    int error_bins[MAX_ERROR_BINS];
-
-    void (*short_fdct4x4)(short *input, short *output, int pitch);
-    void (*short_fdct8x4)(short *input, short *output, int pitch);
-    void (*short_walsh4x4)(short *input, short *output, int pitch);
-    void (*quantize_b)(BLOCK *b, BLOCKD *d);
-
-    unsigned int mbs_zero_last_dot_suppress;
-    int zero_last_dot_suppress;
-} MACROBLOCK;
-
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP8_ENCODER_BLOCK_H_
diff --git a/vp8/encoder/boolhuff.c b/vp8/encoder/boolhuff.c
deleted file mode 100644 (file)
index 3b0c03a..0000000
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#include "boolhuff.h"
-
-#if defined(SECTIONBITS_OUTPUT)
-unsigned __int64 Sectionbits[500];
-
-#endif
-
-#ifdef VP8_ENTROPY_STATS
-unsigned int active_section = 0;
-#endif
-
-const unsigned int vp8_prob_cost[256] =
-{
-    2047, 2047, 1791, 1641, 1535, 1452, 1385, 1328, 1279, 1235, 1196, 1161, 1129, 1099, 1072, 1046,
-    1023, 1000,  979,  959,  940,  922,  905,  889,  873,  858,  843,  829,  816,  803,  790,  778,
-    767,  755,  744,  733,  723,  713,  703,  693,  684,  675,  666,  657,  649,  641,  633,  625,
-    617,  609,  602,  594,  587,  580,  573,  567,  560,  553,  547,  541,  534,  528,  522,  516,
-    511,  505,  499,  494,  488,  483,  477,  472,  467,  462,  457,  452,  447,  442,  437,  433,
-    428,  424,  419,  415,  410,  406,  401,  397,  393,  389,  385,  381,  377,  373,  369,  365,
-    361,  357,  353,  349,  346,  342,  338,  335,  331,  328,  324,  321,  317,  314,  311,  307,
-    304,  301,  297,  294,  291,  288,  285,  281,  278,  275,  272,  269,  266,  263,  260,  257,
-    255,  252,  249,  246,  243,  240,  238,  235,  232,  229,  227,  224,  221,  219,  216,  214,
-    211,  208,  206,  203,  201,  198,  196,  194,  191,  189,  186,  184,  181,  179,  177,  174,
-    172,  170,  168,  165,  163,  161,  159,  156,  154,  152,  150,  148,  145,  143,  141,  139,
-    137,  135,  133,  131,  129,  127,  125,  123,  121,  119,  117,  115,  113,  111,  109,  107,
-    105,  103,  101,   99,   97,   95,   93,   92,   90,   88,   86,   84,   82,   81,   79,   77,
-    75,   73,   72,   70,   68,   66,   65,   63,   61,   60,   58,   56,   55,   53,   51,   50,
-    48,   46,   45,   43,   41,   40,   38,   37,   35,   33,   32,   30,   29,   27,   25,   24,
-    22,   21,   19,   18,   16,   15,   13,   12,   10,    9,    7,    6,    4,    3,    1,   1
-};
-
-void vp8_start_encode(BOOL_CODER *br, unsigned char *source, unsigned char *source_end)
-{
-
-    br->lowvalue   = 0;
-    br->range      = 255;
-    br->count      = -24;
-    br->buffer     = source;
-    br->buffer_end = source_end;
-    br->pos        = 0;
-}
-
-void vp8_stop_encode(BOOL_CODER *br)
-{
-    int i;
-
-    for (i = 0; i < 32; i++)
-        vp8_encode_bool(br, 0, 128);
-}
-
-
-void vp8_encode_value(BOOL_CODER *br, int data, int bits)
-{
-    int bit;
-
-    for (bit = bits - 1; bit >= 0; bit--)
-        vp8_encode_bool(br, (1 & (data >> bit)), 0x80);
-
-}
diff --git a/vp8/encoder/boolhuff.h b/vp8/encoder/boolhuff.h
deleted file mode 100644 (file)
index e66a2db..0000000
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-/****************************************************************************
-*
-*   Module Title :     boolhuff.h
-*
-*   Description  :     Bool Coder header file.
-*
-****************************************************************************/
-#ifndef VP8_ENCODER_BOOLHUFF_H_
-#define VP8_ENCODER_BOOLHUFF_H_
-
-#include "vpx_ports/mem.h"
-#include "vpx/internal/vpx_codec_internal.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef struct
-{
-    unsigned int lowvalue;
-    unsigned int range;
-    int count;
-    unsigned int pos;
-    unsigned char *buffer;
-    unsigned char *buffer_end;
-    struct vpx_internal_error_info *error;
-} BOOL_CODER;
-
-extern void vp8_start_encode(BOOL_CODER *bc, unsigned char *buffer, unsigned char *buffer_end);
-
-extern void vp8_encode_value(BOOL_CODER *br, int data, int bits);
-extern void vp8_stop_encode(BOOL_CODER *bc);
-extern const unsigned int vp8_prob_cost[256];
-
-
-DECLARE_ALIGNED(16, extern const unsigned char, vp8_norm[256]);
-
-static int validate_buffer(const unsigned char *start,
-                           size_t               len,
-                           const unsigned char *end,
-                           struct vpx_internal_error_info *error)
-{
-    if (start + len > start && start + len < end)
-        return 1;
-    else
-        vpx_internal_error(error, VPX_CODEC_CORRUPT_FRAME,
-            "Truncated packet or corrupt partition ");
-
-    return 0;
-}
-static void vp8_encode_bool(BOOL_CODER *br, int bit, int probability)
-{
-    unsigned int split;
-    int count = br->count;
-    unsigned int range = br->range;
-    unsigned int lowvalue = br->lowvalue;
-    register int shift;
-
-#ifdef VP8_ENTROPY_STATS
-#if defined(SECTIONBITS_OUTPUT)
-
-    if (bit)
-        Sectionbits[active_section] += vp8_prob_cost[255-probability];
-    else
-        Sectionbits[active_section] += vp8_prob_cost[probability];
-
-#endif
-#endif
-
-    split = 1 + (((range - 1) * probability) >> 8);
-
-    range = split;
-
-    if (bit)
-    {
-        lowvalue += split;
-        range = br->range - split;
-    }
-
-    shift = vp8_norm[range];
-
-    range <<= shift;
-    count += shift;
-
-    if (count >= 0)
-    {
-        int offset = shift - count;
-
-        if ((lowvalue << (offset - 1)) & 0x80000000)
-        {
-            int x = br->pos - 1;
-
-            while (x >= 0 && br->buffer[x] == 0xff)
-            {
-                br->buffer[x] = (unsigned char)0;
-                x--;
-            }
-
-            br->buffer[x] += 1;
-        }
-
-        validate_buffer(br->buffer + br->pos, 1, br->buffer_end, br->error);
-        br->buffer[br->pos++] = (lowvalue >> (24 - offset));
-
-        lowvalue <<= offset;
-        shift = count;
-        lowvalue &= 0xffffff;
-        count -= 8 ;
-    }
-
-    lowvalue <<= shift;
-    br->count = count;
-    br->lowvalue = lowvalue;
-    br->range = range;
-}
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP8_ENCODER_BOOLHUFF_H_
diff --git a/vp8/encoder/dct.c b/vp8/encoder/dct.c
deleted file mode 100644 (file)
index 0c7198d..0000000
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#include <math.h>
-
-#include "./vp8_rtcd.h"
-
-void vp8_short_fdct4x4_c(short *input, short *output, int pitch)
-{
-    int i;
-    int a1, b1, c1, d1;
-    short *ip = input;
-    short *op = output;
-
-    for (i = 0; i < 4; i++)
-    {
-        a1 = ((ip[0] + ip[3]) * 8);
-        b1 = ((ip[1] + ip[2]) * 8);
-        c1 = ((ip[1] - ip[2]) * 8);
-        d1 = ((ip[0] - ip[3]) * 8);
-
-        op[0] = a1 + b1;
-        op[2] = a1 - b1;
-
-        op[1] = (c1 * 2217 + d1 * 5352 +  14500)>>12;
-        op[3] = (d1 * 2217 - c1 * 5352 +   7500)>>12;
-
-        ip += pitch / 2;
-        op += 4;
-
-    }
-    ip = output;
-    op = output;
-    for (i = 0; i < 4; i++)
-    {
-        a1 = ip[0] + ip[12];
-        b1 = ip[4] + ip[8];
-        c1 = ip[4] - ip[8];
-        d1 = ip[0] - ip[12];
-
-        op[0]  = ( a1 + b1 + 7)>>4;
-        op[8]  = ( a1 - b1 + 7)>>4;
-
-        op[4]  =((c1 * 2217 + d1 * 5352 +  12000)>>16) + (d1!=0);
-        op[12] = (d1 * 2217 - c1 * 5352 +  51000)>>16;
-
-        ip++;
-        op++;
-    }
-}
-
-void vp8_short_fdct8x4_c(short *input, short *output, int pitch)
-{
-    vp8_short_fdct4x4_c(input,   output,    pitch);
-    vp8_short_fdct4x4_c(input + 4, output + 16, pitch);
-}
-
-void vp8_short_walsh4x4_c(short *input, short *output, int pitch)
-{
-    int i;
-    int a1, b1, c1, d1;
-    int a2, b2, c2, d2;
-    short *ip = input;
-    short *op = output;
-
-
-    for (i = 0; i < 4; i++)
-    {
-        a1 = ((ip[0] + ip[2]) * 4);
-        d1 = ((ip[1] + ip[3]) * 4);
-        c1 = ((ip[1] - ip[3]) * 4);
-        b1 = ((ip[0] - ip[2]) * 4);
-
-        op[0] = a1 + d1 + (a1!=0);
-        op[1] = b1 + c1;
-        op[2] = b1 - c1;
-        op[3] = a1 - d1;
-        ip += pitch / 2;
-        op += 4;
-    }
-
-    ip = output;
-    op = output;
-
-    for (i = 0; i < 4; i++)
-    {
-        a1 = ip[0] + ip[8];
-        d1 = ip[4] + ip[12];
-        c1 = ip[4] - ip[12];
-        b1 = ip[0] - ip[8];
-
-        a2 = a1 + d1;
-        b2 = b1 + c1;
-        c2 = b1 - c1;
-        d2 = a1 - d1;
-
-        a2 += a2<0;
-        b2 += b2<0;
-        c2 += c2<0;
-        d2 += d2<0;
-
-        op[0] = (a2+3) >> 3;
-        op[4] = (b2+3) >> 3;
-        op[8] = (c2+3) >> 3;
-        op[12]= (d2+3) >> 3;
-
-        ip++;
-        op++;
-    }
-}
diff --git a/vp8/encoder/dct_value_cost.h b/vp8/encoder/dct_value_cost.h
deleted file mode 100644 (file)
index 1cd3eec..0000000
+++ /dev/null
@@ -1,371 +0,0 @@
-/*
- *  Copyright (c) 2012 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.
- */
-
-#ifndef VP8_ENCODER_DCT_VALUE_COST_H_
-#define VP8_ENCODER_DCT_VALUE_COST_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* Generated file, included by tokenize.c  */
-/* Values generated by fill_value_tokens() */
-
-static const short dct_value_cost[2048*2] =
-{
-    8285, 8277, 8267, 8259, 8253, 8245, 8226, 8218, 8212, 8204, 8194, 8186,
-    8180, 8172, 8150, 8142, 8136, 8128, 8118, 8110, 8104, 8096, 8077, 8069,
-    8063, 8055, 8045, 8037, 8031, 8023, 7997, 7989, 7983, 7975, 7965, 7957,
-    7951, 7943, 7924, 7916, 7910, 7902, 7892, 7884, 7878, 7870, 7848, 7840,
-    7834, 7826, 7816, 7808, 7802, 7794, 7775, 7767, 7761, 7753, 7743, 7735,
-    7729, 7721, 7923, 7915, 7909, 7901, 7891, 7883, 7877, 7869, 7850, 7842,
-    7836, 7828, 7818, 7810, 7804, 7796, 7774, 7766, 7760, 7752, 7742, 7734,
-    7728, 7720, 7701, 7693, 7687, 7679, 7669, 7661, 7655, 7647, 7621, 7613,
-    7607, 7599, 7589, 7581, 7575, 7567, 7548, 7540, 7534, 7526, 7516, 7508,
-    7502, 7494, 7472, 7464, 7458, 7450, 7440, 7432, 7426, 7418, 7399, 7391,
-    7385, 7377, 7367, 7359, 7353, 7345, 7479, 7471, 7465, 7457, 7447, 7439,
-    7433, 7425, 7406, 7398, 7392, 7384, 7374, 7366, 7360, 7352, 7330, 7322,
-    7316, 7308, 7298, 7290, 7284, 7276, 7257, 7249, 7243, 7235, 7225, 7217,
-    7211, 7203, 7177, 7169, 7163, 7155, 7145, 7137, 7131, 7123, 7104, 7096,
-    7090, 7082, 7072, 7064, 7058, 7050, 7028, 7020, 7014, 7006, 6996, 6988,
-    6982, 6974, 6955, 6947, 6941, 6933, 6923, 6915, 6909, 6901, 7632, 7624,
-    7618, 7610, 7600, 7592, 7586, 7578, 7559, 7551, 7545, 7537, 7527, 7519,
-    7513, 7505, 7483, 7475, 7469, 7461, 7451, 7443, 7437, 7429, 7410, 7402,
-    7396, 7388, 7378, 7370, 7364, 7356, 7330, 7322, 7316, 7308, 7298, 7290,
-    7284, 7276, 7257, 7249, 7243, 7235, 7225, 7217, 7211, 7203, 7181, 7173,
-    7167, 7159, 7149, 7141, 7135, 7127, 7108, 7100, 7094, 7086, 7076, 7068,
-    7062, 7054, 7188, 7180, 7174, 7166, 7156, 7148, 7142, 7134, 7115, 7107,
-    7101, 7093, 7083, 7075, 7069, 7061, 7039, 7031, 7025, 7017, 7007, 6999,
-    6993, 6985, 6966, 6958, 6952, 6944, 6934, 6926, 6920, 6912, 6886, 6878,
-    6872, 6864, 6854, 6846, 6840, 6832, 6813, 6805, 6799, 6791, 6781, 6773,
-    6767, 6759, 6737, 6729, 6723, 6715, 6705, 6697, 6691, 6683, 6664, 6656,
-    6650, 6642, 6632, 6624, 6618, 6610, 6812, 6804, 6798, 6790, 6780, 6772,
-    6766, 6758, 6739, 6731, 6725, 6717, 6707, 6699, 6693, 6685, 6663, 6655,
-    6649, 6641, 6631, 6623, 6617, 6609, 6590, 6582, 6576, 6568, 6558, 6550,
-    6544, 6536, 6510, 6502, 6496, 6488, 6478, 6470, 6464, 6456, 6437, 6429,
-    6423, 6415, 6405, 6397, 6391, 6383, 6361, 6353, 6347, 6339, 6329, 6321,
-    6315, 6307, 6288, 6280, 6274, 6266, 6256, 6248, 6242, 6234, 6368, 6360,
-    6354, 6346, 6336, 6328, 6322, 6314, 6295, 6287, 6281, 6273, 6263, 6255,
-    6249, 6241, 6219, 6211, 6205, 6197, 6187, 6179, 6173, 6165, 6146, 6138,
-    6132, 6124, 6114, 6106, 6100, 6092, 6066, 6058, 6052, 6044, 6034, 6026,
-    6020, 6012, 5993, 5985, 5979, 5971, 5961, 5953, 5947, 5939, 5917, 5909,
-    5903, 5895, 5885, 5877, 5871, 5863, 5844, 5836, 5830, 5822, 5812, 5804,
-    5798, 5790, 6697, 6689, 6683, 6675, 6665, 6657, 6651, 6643, 6624, 6616,
-    6610, 6602, 6592, 6584, 6578, 6570, 6548, 6540, 6534, 6526, 6516, 6508,
-    6502, 6494, 6475, 6467, 6461, 6453, 6443, 6435, 6429, 6421, 6395, 6387,
-    6381, 6373, 6363, 6355, 6349, 6341, 6322, 6314, 6308, 6300, 6290, 6282,
-    6276, 6268, 6246, 6238, 6232, 6224, 6214, 6206, 6200, 6192, 6173, 6165,
-    6159, 6151, 6141, 6133, 6127, 6119, 6253, 6245, 6239, 6231, 6221, 6213,
-    6207, 6199, 6180, 6172, 6166, 6158, 6148, 6140, 6134, 6126, 6104, 6096,
-    6090, 6082, 6072, 6064, 6058, 6050, 6031, 6023, 6017, 6009, 5999, 5991,
-    5985, 5977, 5951, 5943, 5937, 5929, 5919, 5911, 5905, 5897, 5878, 5870,
-    5864, 5856, 5846, 5838, 5832, 5824, 5802, 5794, 5788, 5780, 5770, 5762,
-    5756, 5748, 5729, 5721, 5715, 5707, 5697, 5689, 5683, 5675, 5877, 5869,
-    5863, 5855, 5845, 5837, 5831, 5823, 5804, 5796, 5790, 5782, 5772, 5764,
-    5758, 5750, 5728, 5720, 5714, 5706, 5696, 5688, 5682, 5674, 5655, 5647,
-    5641, 5633, 5623, 5615, 5609, 5601, 5575, 5567, 5561, 5553, 5543, 5535,
-    5529, 5521, 5502, 5494, 5488, 5480, 5470, 5462, 5456, 5448, 5426, 5418,
-    5412, 5404, 5394, 5386, 5380, 5372, 5353, 5345, 5339, 5331, 5321, 5313,
-    5307, 5299, 5433, 5425, 5419, 5411, 5401, 5393, 5387, 5379, 5360, 5352,
-    5346, 5338, 5328, 5320, 5314, 5306, 5284, 5276, 5270, 5262, 5252, 5244,
-    5238, 5230, 5211, 5203, 5197, 5189, 5179, 5171, 5165, 5157, 5131, 5123,
-    5117, 5109, 5099, 5091, 5085, 5077, 5058, 5050, 5044, 5036, 5026, 5018,
-    5012, 5004, 4982, 4974, 4968, 4960, 4950, 4942, 4936, 4928, 4909, 4901,
-    4895, 4887, 4877, 4869, 4863, 4855, 5586, 5578, 5572, 5564, 5554, 5546,
-    5540, 5532, 5513, 5505, 5499, 5491, 5481, 5473, 5467, 5459, 5437, 5429,
-    5423, 5415, 5405, 5397, 5391, 5383, 5364, 5356, 5350, 5342, 5332, 5324,
-    5318, 5310, 5284, 5276, 5270, 5262, 5252, 5244, 5238, 5230, 5211, 5203,
-    5197, 5189, 5179, 5171, 5165, 5157, 5135, 5127, 5121, 5113, 5103, 5095,
-    5089, 5081, 5062, 5054, 5048, 5040, 5030, 5022, 5016, 5008, 5142, 5134,
-    5128, 5120, 5110, 5102, 5096, 5088, 5069, 5061, 5055, 5047, 5037, 5029,
-    5023, 5015, 4993, 4985, 4979, 4971, 4961, 4953, 4947, 4939, 4920, 4912,
-    4906, 4898, 4888, 4880, 4874, 4866, 4840, 4832, 4826, 4818, 4808, 4800,
-    4794, 4786, 4767, 4759, 4753, 4745, 4735, 4727, 4721, 4713, 4691, 4683,
-    4677, 4669, 4659, 4651, 4645, 4637, 4618, 4610, 4604, 4596, 4586, 4578,
-    4572, 4564, 4766, 4758, 4752, 4744, 4734, 4726, 4720, 4712, 4693, 4685,
-    4679, 4671, 4661, 4653, 4647, 4639, 4617, 4609, 4603, 4595, 4585, 4577,
-    4571, 4563, 4544, 4536, 4530, 4522, 4512, 4504, 4498, 4490, 4464, 4456,
-    4450, 4442, 4432, 4424, 4418, 4410, 4391, 4383, 4377, 4369, 4359, 4351,
-    4345, 4337, 4315, 4307, 4301, 4293, 4283, 4275, 4269, 4261, 4242, 4234,
-    4228, 4220, 4210, 4202, 4196, 4188, 4322, 4314, 4308, 4300, 4290, 4282,
-    4276, 4268, 4249, 4241, 4235, 4227, 4217, 4209, 4203, 4195, 4173, 4165,
-    4159, 4151, 4141, 4133, 4127, 4119, 4100, 4092, 4086, 4078, 4068, 4060,
-    4054, 4046, 4020, 4012, 4006, 3998, 3988, 3980, 3974, 3966, 3947, 3939,
-    3933, 3925, 3915, 3907, 3901, 3893, 3871, 3863, 3857, 3849, 3839, 3831,
-    3825, 3817, 3798, 3790, 3784, 3776, 3766, 3758, 3752, 3744, 6697, 6689,
-    6683, 6675, 6665, 6657, 6651, 6643, 6624, 6616, 6610, 6602, 6592, 6584,
-    6578, 6570, 6548, 6540, 6534, 6526, 6516, 6508, 6502, 6494, 6475, 6467,
-    6461, 6453, 6443, 6435, 6429, 6421, 6395, 6387, 6381, 6373, 6363, 6355,
-    6349, 6341, 6322, 6314, 6308, 6300, 6290, 6282, 6276, 6268, 6246, 6238,
-    6232, 6224, 6214, 6206, 6200, 6192, 6173, 6165, 6159, 6151, 6141, 6133,
-    6127, 6119, 6253, 6245, 6239, 6231, 6221, 6213, 6207, 6199, 6180, 6172,
-    6166, 6158, 6148, 6140, 6134, 6126, 6104, 6096, 6090, 6082, 6072, 6064,
-    6058, 6050, 6031, 6023, 6017, 6009, 5999, 5991, 5985, 5977, 5951, 5943,
-    5937, 5929, 5919, 5911, 5905, 5897, 5878, 5870, 5864, 5856, 5846, 5838,
-    5832, 5824, 5802, 5794, 5788, 5780, 5770, 5762, 5756, 5748, 5729, 5721,
-    5715, 5707, 5697, 5689, 5683, 5675, 5877, 5869, 5863, 5855, 5845, 5837,
-    5831, 5823, 5804, 5796, 5790, 5782, 5772, 5764, 5758, 5750, 5728, 5720,
-    5714, 5706, 5696, 5688, 5682, 5674, 5655, 5647, 5641, 5633, 5623, 5615,
-    5609, 5601, 5575, 5567, 5561, 5553, 5543, 5535, 5529, 5521, 5502, 5494,
-    5488, 5480, 5470, 5462, 5456, 5448, 5426, 5418, 5412, 5404, 5394, 5386,
-    5380, 5372, 5353, 5345, 5339, 5331, 5321, 5313, 5307, 5299, 5433, 5425,
-    5419, 5411, 5401, 5393, 5387, 5379, 5360, 5352, 5346, 5338, 5328, 5320,
-    5314, 5306, 5284, 5276, 5270, 5262, 5252, 5244, 5238, 5230, 5211, 5203,
-    5197, 5189, 5179, 5171, 5165, 5157, 5131, 5123, 5117, 5109, 5099, 5091,
-    5085, 5077, 5058, 5050, 5044, 5036, 5026, 5018, 5012, 5004, 4982, 4974,
-    4968, 4960, 4950, 4942, 4936, 4928, 4909, 4901, 4895, 4887, 4877, 4869,
-    4863, 4855, 5586, 5578, 5572, 5564, 5554, 5546, 5540, 5532, 5513, 5505,
-    5499, 5491, 5481, 5473, 5467, 5459, 5437, 5429, 5423, 5415, 5405, 5397,
-    5391, 5383, 5364, 5356, 5350, 5342, 5332, 5324, 5318, 5310, 5284, 5276,
-    5270, 5262, 5252, 5244, 5238, 5230, 5211, 5203, 5197, 5189, 5179, 5171,
-    5165, 5157, 5135, 5127, 5121, 5113, 5103, 5095, 5089, 5081, 5062, 5054,
-    5048, 5040, 5030, 5022, 5016, 5008, 5142, 5134, 5128, 5120, 5110, 5102,
-    5096, 5088, 5069, 5061, 5055, 5047, 5037, 5029, 5023, 5015, 4993, 4985,
-    4979, 4971, 4961, 4953, 4947, 4939, 4920, 4912, 4906, 4898, 4888, 4880,
-    4874, 4866, 4840, 4832, 4826, 4818, 4808, 4800, 4794, 4786, 4767, 4759,
-    4753, 4745, 4735, 4727, 4721, 4713, 4691, 4683, 4677, 4669, 4659, 4651,
-    4645, 4637, 4618, 4610, 4604, 4596, 4586, 4578, 4572, 4564, 4766, 4758,
-    4752, 4744, 4734, 4726, 4720, 4712, 4693, 4685, 4679, 4671, 4661, 4653,
-    4647, 4639, 4617, 4609, 4603, 4595, 4585, 4577, 4571, 4563, 4544, 4536,
-    4530, 4522, 4512, 4504, 4498, 4490, 4464, 4456, 4450, 4442, 4432, 4424,
-    4418, 4410, 4391, 4383, 4377, 4369, 4359, 4351, 4345, 4337, 4315, 4307,
-    4301, 4293, 4283, 4275, 4269, 4261, 4242, 4234, 4228, 4220, 4210, 4202,
-    4196, 4188, 4322, 4314, 4308, 4300, 4290, 4282, 4276, 4268, 4249, 4241,
-    4235, 4227, 4217, 4209, 4203, 4195, 4173, 4165, 4159, 4151, 4141, 4133,
-    4127, 4119, 4100, 4092, 4086, 4078, 4068, 4060, 4054, 4046, 4020, 4012,
-    4006, 3998, 3988, 3980, 3974, 3966, 3947, 3939, 3933, 3925, 3915, 3907,
-    3901, 3893, 3871, 3863, 3857, 3849, 3839, 3831, 3825, 3817, 3798, 3790,
-    3784, 3776, 3766, 3758, 3752, 3744, 4651, 4643, 4637, 4629, 4619, 4611,
-    4605, 4597, 4578, 4570, 4564, 4556, 4546, 4538, 4532, 4524, 4502, 4494,
-    4488, 4480, 4470, 4462, 4456, 4448, 4429, 4421, 4415, 4407, 4397, 4389,
-    4383, 4375, 4349, 4341, 4335, 4327, 4317, 4309, 4303, 4295, 4276, 4268,
-    4262, 4254, 4244, 4236, 4230, 4222, 4200, 4192, 4186, 4178, 4168, 4160,
-    4154, 4146, 4127, 4119, 4113, 4105, 4095, 4087, 4081, 4073, 4207, 4199,
-    4193, 4185, 4175, 4167, 4161, 4153, 4134, 4126, 4120, 4112, 4102, 4094,
-    4088, 4080, 4058, 4050, 4044, 4036, 4026, 4018, 4012, 4004, 3985, 3977,
-    3971, 3963, 3953, 3945, 3939, 3931, 3905, 3897, 3891, 3883, 3873, 3865,
-    3859, 3851, 3832, 3824, 3818, 3810, 3800, 3792, 3786, 3778, 3756, 3748,
-    3742, 3734, 3724, 3716, 3710, 3702, 3683, 3675, 3669, 3661, 3651, 3643,
-    3637, 3629, 3831, 3823, 3817, 3809, 3799, 3791, 3785, 3777, 3758, 3750,
-    3744, 3736, 3726, 3718, 3712, 3704, 3682, 3674, 3668, 3660, 3650, 3642,
-    3636, 3628, 3609, 3601, 3595, 3587, 3577, 3569, 3563, 3555, 3529, 3521,
-    3515, 3507, 3497, 3489, 3483, 3475, 3456, 3448, 3442, 3434, 3424, 3416,
-    3410, 3402, 3380, 3372, 3366, 3358, 3348, 3340, 3334, 3326, 3307, 3299,
-    3293, 3285, 3275, 3267, 3261, 3253, 3387, 3379, 3373, 3365, 3355, 3347,
-    3341, 3333, 3314, 3306, 3300, 3292, 3282, 3274, 3268, 3260, 3238, 3230,
-    3224, 3216, 3206, 3198, 3192, 3184, 3165, 3157, 3151, 3143, 3133, 3125,
-    3119, 3111, 3085, 3077, 3071, 3063, 3053, 3045, 3039, 3031, 3012, 3004,
-    2998, 2990, 2980, 2972, 2966, 2958, 2936, 2928, 2922, 2914, 2904, 2896,
-    2890, 2882, 2863, 2855, 2849, 2841, 2831, 2823, 2817, 2809, 3540, 3532,
-    3526, 3518, 3508, 3500, 3494, 3486, 3467, 3459, 3453, 3445, 3435, 3427,
-    3421, 3413, 3391, 3383, 3377, 3369, 3359, 3351, 3345, 3337, 3318, 3310,
-    3304, 3296, 3286, 3278, 3272, 3264, 3238, 3230, 3224, 3216, 3206, 3198,
-    3192, 3184, 3165, 3157, 3151, 3143, 3133, 3125, 3119, 3111, 3089, 3081,
-    3075, 3067, 3057, 3049, 3043, 3035, 3016, 3008, 3002, 2994, 2984, 2976,
-    2970, 2962, 3096, 3088, 3082, 3074, 3064, 3056, 3050, 3042, 3023, 3015,
-    3009, 3001, 2991, 2983, 2977, 2969, 2947, 2939, 2933, 2925, 2915, 2907,
-    2901, 2893, 2874, 2866, 2860, 2852, 2842, 2834, 2828, 2820, 2794, 2786,
-    2780, 2772, 2762, 2754, 2748, 2740, 2721, 2713, 2707, 2699, 2689, 2681,
-    2675, 2667, 2645, 2637, 2631, 2623, 2613, 2605, 2599, 2591, 2572, 2564,
-    2558, 2550, 2540, 2532, 2526, 2518, 2720, 2712, 2706, 2698, 2688, 2680,
-    2674, 2666, 2647, 2639, 2633, 2625, 2615, 2607, 2601, 2593, 2571, 2563,
-    2557, 2549, 2539, 2531, 2525, 2517, 2498, 2490, 2484, 2476, 2466, 2458,
-    2452, 2444, 2418, 2410, 2404, 2396, 2386, 2378, 2372, 2364, 2345, 2337,
-    2331, 2323, 2313, 2305, 2299, 2291, 2269, 2261, 2255, 2247, 2237, 2229,
-    2223, 2215, 2196, 2188, 2182, 2174, 2164, 2156, 2150, 2142, 2276, 2268,
-    2262, 2254, 2244, 2236, 2230, 2222, 2203, 2195, 2189, 2181, 2171, 2163,
-    2157, 2149, 2127, 2119, 2113, 2105, 2095, 2087, 2081, 2073, 2054, 2046,
-    2040, 2032, 2022, 2014, 2008, 2000, 1974, 1966, 1960, 1952, 1942, 1934,
-    1928, 1920, 1901, 1893, 1887, 1879, 1869, 1861, 1855, 1847, 1825, 1817,
-    1811, 1803, 1793, 1785, 1779, 1771, 1752, 1744, 1738, 1730, 1720, 1712,
-    1706, 1698, 1897, 1883, 1860, 1846, 1819, 1805, 1782, 1768, 1723, 1709,
-    1686, 1672, 1645, 1631, 1608, 1594, 1574, 1560, 1537, 1523, 1496, 1482,
-    1459, 1445, 1400, 1386, 1363, 1349, 1322, 1308, 1285, 1271, 1608, 1565,
-    1535, 1492, 1446, 1403, 1373, 1330, 1312, 1269, 1239, 1196, 1150, 1107,
-    1077, 1034, 1291, 1218, 1171, 1098, 1015, 942, 895, 822, 953, 850,
-    729, 626, 618, 431, 257, 257, 257, 257, 0, 255, 255, 255,
-    255, 429, 616, 624, 727, 848, 951, 820, 893, 940, 1013, 1096,
-    1169, 1216, 1289, 1032, 1075, 1105, 1148, 1194, 1237, 1267, 1310, 1328,
-    1371, 1401, 1444, 1490, 1533, 1563, 1606, 1269, 1283, 1306, 1320, 1347,
-    1361, 1384, 1398, 1443, 1457, 1480, 1494, 1521, 1535, 1558, 1572, 1592,
-    1606, 1629, 1643, 1670, 1684, 1707, 1721, 1766, 1780, 1803, 1817, 1844,
-    1858, 1881, 1895, 1696, 1704, 1710, 1718, 1728, 1736, 1742, 1750, 1769,
-    1777, 1783, 1791, 1801, 1809, 1815, 1823, 1845, 1853, 1859, 1867, 1877,
-    1885, 1891, 1899, 1918, 1926, 1932, 1940, 1950, 1958, 1964, 1972, 1998,
-    2006, 2012, 2020, 2030, 2038, 2044, 2052, 2071, 2079, 2085, 2093, 2103,
-    2111, 2117, 2125, 2147, 2155, 2161, 2169, 2179, 2187, 2193, 2201, 2220,
-    2228, 2234, 2242, 2252, 2260, 2266, 2274, 2140, 2148, 2154, 2162, 2172,
-    2180, 2186, 2194, 2213, 2221, 2227, 2235, 2245, 2253, 2259, 2267, 2289,
-    2297, 2303, 2311, 2321, 2329, 2335, 2343, 2362, 2370, 2376, 2384, 2394,
-    2402, 2408, 2416, 2442, 2450, 2456, 2464, 2474, 2482, 2488, 2496, 2515,
-    2523, 2529, 2537, 2547, 2555, 2561, 2569, 2591, 2599, 2605, 2613, 2623,
-    2631, 2637, 2645, 2664, 2672, 2678, 2686, 2696, 2704, 2710, 2718, 2516,
-    2524, 2530, 2538, 2548, 2556, 2562, 2570, 2589, 2597, 2603, 2611, 2621,
-    2629, 2635, 2643, 2665, 2673, 2679, 2687, 2697, 2705, 2711, 2719, 2738,
-    2746, 2752, 2760, 2770, 2778, 2784, 2792, 2818, 2826, 2832, 2840, 2850,
-    2858, 2864, 2872, 2891, 2899, 2905, 2913, 2923, 2931, 2937, 2945, 2967,
-    2975, 2981, 2989, 2999, 3007, 3013, 3021, 3040, 3048, 3054, 3062, 3072,
-    3080, 3086, 3094, 2960, 2968, 2974, 2982, 2992, 3000, 3006, 3014, 3033,
-    3041, 3047, 3055, 3065, 3073, 3079, 3087, 3109, 3117, 3123, 3131, 3141,
-    3149, 3155, 3163, 3182, 3190, 3196, 3204, 3214, 3222, 3228, 3236, 3262,
-    3270, 3276, 3284, 3294, 3302, 3308, 3316, 3335, 3343, 3349, 3357, 3367,
-    3375, 3381, 3389, 3411, 3419, 3425, 3433, 3443, 3451, 3457, 3465, 3484,
-    3492, 3498, 3506, 3516, 3524, 3530, 3538, 2807, 2815, 2821, 2829, 2839,
-    2847, 2853, 2861, 2880, 2888, 2894, 2902, 2912, 2920, 2926, 2934, 2956,
-    2964, 2970, 2978, 2988, 2996, 3002, 3010, 3029, 3037, 3043, 3051, 3061,
-    3069, 3075, 3083, 3109, 3117, 3123, 3131, 3141, 3149, 3155, 3163, 3182,
-    3190, 3196, 3204, 3214, 3222, 3228, 3236, 3258, 3266, 3272, 3280, 3290,
-    3298, 3304, 3312, 3331, 3339, 3345, 3353, 3363, 3371, 3377, 3385, 3251,
-    3259, 3265, 3273, 3283, 3291, 3297, 3305, 3324, 3332, 3338, 3346, 3356,
-    3364, 3370, 3378, 3400, 3408, 3414, 3422, 3432, 3440, 3446, 3454, 3473,
-    3481, 3487, 3495, 3505, 3513, 3519, 3527, 3553, 3561, 3567, 3575, 3585,
-    3593, 3599, 3607, 3626, 3634, 3640, 3648, 3658, 3666, 3672, 3680, 3702,
-    3710, 3716, 3724, 3734, 3742, 3748, 3756, 3775, 3783, 3789, 3797, 3807,
-    3815, 3821, 3829, 3627, 3635, 3641, 3649, 3659, 3667, 3673, 3681, 3700,
-    3708, 3714, 3722, 3732, 3740, 3746, 3754, 3776, 3784, 3790, 3798, 3808,
-    3816, 3822, 3830, 3849, 3857, 3863, 3871, 3881, 3889, 3895, 3903, 3929,
-    3937, 3943, 3951, 3961, 3969, 3975, 3983, 4002, 4010, 4016, 4024, 4034,
-    4042, 4048, 4056, 4078, 4086, 4092, 4100, 4110, 4118, 4124, 4132, 4151,
-    4159, 4165, 4173, 4183, 4191, 4197, 4205, 4071, 4079, 4085, 4093, 4103,
-    4111, 4117, 4125, 4144, 4152, 4158, 4166, 4176, 4184, 4190, 4198, 4220,
-    4228, 4234, 4242, 4252, 4260, 4266, 4274, 4293, 4301, 4307, 4315, 4325,
-    4333, 4339, 4347, 4373, 4381, 4387, 4395, 4405, 4413, 4419, 4427, 4446,
-    4454, 4460, 4468, 4478, 4486, 4492, 4500, 4522, 4530, 4536, 4544, 4554,
-    4562, 4568, 4576, 4595, 4603, 4609, 4617, 4627, 4635, 4641, 4649, 3742,
-    3750, 3756, 3764, 3774, 3782, 3788, 3796, 3815, 3823, 3829, 3837, 3847,
-    3855, 3861, 3869, 3891, 3899, 3905, 3913, 3923, 3931, 3937, 3945, 3964,
-    3972, 3978, 3986, 3996, 4004, 4010, 4018, 4044, 4052, 4058, 4066, 4076,
-    4084, 4090, 4098, 4117, 4125, 4131, 4139, 4149, 4157, 4163, 4171, 4193,
-    4201, 4207, 4215, 4225, 4233, 4239, 4247, 4266, 4274, 4280, 4288, 4298,
-    4306, 4312, 4320, 4186, 4194, 4200, 4208, 4218, 4226, 4232, 4240, 4259,
-    4267, 4273, 4281, 4291, 4299, 4305, 4313, 4335, 4343, 4349, 4357, 4367,
-    4375, 4381, 4389, 4408, 4416, 4422, 4430, 4440, 4448, 4454, 4462, 4488,
-    4496, 4502, 4510, 4520, 4528, 4534, 4542, 4561, 4569, 4575, 4583, 4593,
-    4601, 4607, 4615, 4637, 4645, 4651, 4659, 4669, 4677, 4683, 4691, 4710,
-    4718, 4724, 4732, 4742, 4750, 4756, 4764, 4562, 4570, 4576, 4584, 4594,
-    4602, 4608, 4616, 4635, 4643, 4649, 4657, 4667, 4675, 4681, 4689, 4711,
-    4719, 4725, 4733, 4743, 4751, 4757, 4765, 4784, 4792, 4798, 4806, 4816,
-    4824, 4830, 4838, 4864, 4872, 4878, 4886, 4896, 4904, 4910, 4918, 4937,
-    4945, 4951, 4959, 4969, 4977, 4983, 4991, 5013, 5021, 5027, 5035, 5045,
-    5053, 5059, 5067, 5086, 5094, 5100, 5108, 5118, 5126, 5132, 5140, 5006,
-    5014, 5020, 5028, 5038, 5046, 5052, 5060, 5079, 5087, 5093, 5101, 5111,
-    5119, 5125, 5133, 5155, 5163, 5169, 5177, 5187, 5195, 5201, 5209, 5228,
-    5236, 5242, 5250, 5260, 5268, 5274, 5282, 5308, 5316, 5322, 5330, 5340,
-    5348, 5354, 5362, 5381, 5389, 5395, 5403, 5413, 5421, 5427, 5435, 5457,
-    5465, 5471, 5479, 5489, 5497, 5503, 5511, 5530, 5538, 5544, 5552, 5562,
-    5570, 5576, 5584, 4853, 4861, 4867, 4875, 4885, 4893, 4899, 4907, 4926,
-    4934, 4940, 4948, 4958, 4966, 4972, 4980, 5002, 5010, 5016, 5024, 5034,
-    5042, 5048, 5056, 5075, 5083, 5089, 5097, 5107, 5115, 5121, 5129, 5155,
-    5163, 5169, 5177, 5187, 5195, 5201, 5209, 5228, 5236, 5242, 5250, 5260,
-    5268, 5274, 5282, 5304, 5312, 5318, 5326, 5336, 5344, 5350, 5358, 5377,
-    5385, 5391, 5399, 5409, 5417, 5423, 5431, 5297, 5305, 5311, 5319, 5329,
-    5337, 5343, 5351, 5370, 5378, 5384, 5392, 5402, 5410, 5416, 5424, 5446,
-    5454, 5460, 5468, 5478, 5486, 5492, 5500, 5519, 5527, 5533, 5541, 5551,
-    5559, 5565, 5573, 5599, 5607, 5613, 5621, 5631, 5639, 5645, 5653, 5672,
-    5680, 5686, 5694, 5704, 5712, 5718, 5726, 5748, 5756, 5762, 5770, 5780,
-    5788, 5794, 5802, 5821, 5829, 5835, 5843, 5853, 5861, 5867, 5875, 5673,
-    5681, 5687, 5695, 5705, 5713, 5719, 5727, 5746, 5754, 5760, 5768, 5778,
-    5786, 5792, 5800, 5822, 5830, 5836, 5844, 5854, 5862, 5868, 5876, 5895,
-    5903, 5909, 5917, 5927, 5935, 5941, 5949, 5975, 5983, 5989, 5997, 6007,
-    6015, 6021, 6029, 6048, 6056, 6062, 6070, 6080, 6088, 6094, 6102, 6124,
-    6132, 6138, 6146, 6156, 6164, 6170, 6178, 6197, 6205, 6211, 6219, 6229,
-    6237, 6243, 6251, 6117, 6125, 6131, 6139, 6149, 6157, 6163, 6171, 6190,
-    6198, 6204, 6212, 6222, 6230, 6236, 6244, 6266, 6274, 6280, 6288, 6298,
-    6306, 6312, 6320, 6339, 6347, 6353, 6361, 6371, 6379, 6385, 6393, 6419,
-    6427, 6433, 6441, 6451, 6459, 6465, 6473, 6492, 6500, 6506, 6514, 6524,
-    6532, 6538, 6546, 6568, 6576, 6582, 6590, 6600, 6608, 6614, 6622, 6641,
-    6649, 6655, 6663, 6673, 6681, 6687, 6695, 3742, 3750, 3756, 3764, 3774,
-    3782, 3788, 3796, 3815, 3823, 3829, 3837, 3847, 3855, 3861, 3869, 3891,
-    3899, 3905, 3913, 3923, 3931, 3937, 3945, 3964, 3972, 3978, 3986, 3996,
-    4004, 4010, 4018, 4044, 4052, 4058, 4066, 4076, 4084, 4090, 4098, 4117,
-    4125, 4131, 4139, 4149, 4157, 4163, 4171, 4193, 4201, 4207, 4215, 4225,
-    4233, 4239, 4247, 4266, 4274, 4280, 4288, 4298, 4306, 4312, 4320, 4186,
-    4194, 4200, 4208, 4218, 4226, 4232, 4240, 4259, 4267, 4273, 4281, 4291,
-    4299, 4305, 4313, 4335, 4343, 4349, 4357, 4367, 4375, 4381, 4389, 4408,
-    4416, 4422, 4430, 4440, 4448, 4454, 4462, 4488, 4496, 4502, 4510, 4520,
-    4528, 4534, 4542, 4561, 4569, 4575, 4583, 4593, 4601, 4607, 4615, 4637,
-    4645, 4651, 4659, 4669, 4677, 4683, 4691, 4710, 4718, 4724, 4732, 4742,
-    4750, 4756, 4764, 4562, 4570, 4576, 4584, 4594, 4602, 4608, 4616, 4635,
-    4643, 4649, 4657, 4667, 4675, 4681, 4689, 4711, 4719, 4725, 4733, 4743,
-    4751, 4757, 4765, 4784, 4792, 4798, 4806, 4816, 4824, 4830, 4838, 4864,
-    4872, 4878, 4886, 4896, 4904, 4910, 4918, 4937, 4945, 4951, 4959, 4969,
-    4977, 4983, 4991, 5013, 5021, 5027, 5035, 5045, 5053, 5059, 5067, 5086,
-    5094, 5100, 5108, 5118, 5126, 5132, 5140, 5006, 5014, 5020, 5028, 5038,
-    5046, 5052, 5060, 5079, 5087, 5093, 5101, 5111, 5119, 5125, 5133, 5155,
-    5163, 5169, 5177, 5187, 5195, 5201, 5209, 5228, 5236, 5242, 5250, 5260,
-    5268, 5274, 5282, 5308, 5316, 5322, 5330, 5340, 5348, 5354, 5362, 5381,
-    5389, 5395, 5403, 5413, 5421, 5427, 5435, 5457, 5465, 5471, 5479, 5489,
-    5497, 5503, 5511, 5530, 5538, 5544, 5552, 5562, 5570, 5576, 5584, 4853,
-    4861, 4867, 4875, 4885, 4893, 4899, 4907, 4926, 4934, 4940, 4948, 4958,
-    4966, 4972, 4980, 5002, 5010, 5016, 5024, 5034, 5042, 5048, 5056, 5075,
-    5083, 5089, 5097, 5107, 5115, 5121, 5129, 5155, 5163, 5169, 5177, 5187,
-    5195, 5201, 5209, 5228, 5236, 5242, 5250, 5260, 5268, 5274, 5282, 5304,
-    5312, 5318, 5326, 5336, 5344, 5350, 5358, 5377, 5385, 5391, 5399, 5409,
-    5417, 5423, 5431, 5297, 5305, 5311, 5319, 5329, 5337, 5343, 5351, 5370,
-    5378, 5384, 5392, 5402, 5410, 5416, 5424, 5446, 5454, 5460, 5468, 5478,
-    5486, 5492, 5500, 5519, 5527, 5533, 5541, 5551, 5559, 5565, 5573, 5599,
-    5607, 5613, 5621, 5631, 5639, 5645, 5653, 5672, 5680, 5686, 5694, 5704,
-    5712, 5718, 5726, 5748, 5756, 5762, 5770, 5780, 5788, 5794, 5802, 5821,
-    5829, 5835, 5843, 5853, 5861, 5867, 5875, 5673, 5681, 5687, 5695, 5705,
-    5713, 5719, 5727, 5746, 5754, 5760, 5768, 5778, 5786, 5792, 5800, 5822,
-    5830, 5836, 5844, 5854, 5862, 5868, 5876, 5895, 5903, 5909, 5917, 5927,
-    5935, 5941, 5949, 5975, 5983, 5989, 5997, 6007, 6015, 6021, 6029, 6048,
-    6056, 6062, 6070, 6080, 6088, 6094, 6102, 6124, 6132, 6138, 6146, 6156,
-    6164, 6170, 6178, 6197, 6205, 6211, 6219, 6229, 6237, 6243, 6251, 6117,
-    6125, 6131, 6139, 6149, 6157, 6163, 6171, 6190, 6198, 6204, 6212, 6222,
-    6230, 6236, 6244, 6266, 6274, 6280, 6288, 6298, 6306, 6312, 6320, 6339,
-    6347, 6353, 6361, 6371, 6379, 6385, 6393, 6419, 6427, 6433, 6441, 6451,
-    6459, 6465, 6473, 6492, 6500, 6506, 6514, 6524, 6532, 6538, 6546, 6568,
-    6576, 6582, 6590, 6600, 6608, 6614, 6622, 6641, 6649, 6655, 6663, 6673,
-    6681, 6687, 6695, 5788, 5796, 5802, 5810, 5820, 5828, 5834, 5842, 5861,
-    5869, 5875, 5883, 5893, 5901, 5907, 5915, 5937, 5945, 5951, 5959, 5969,
-    5977, 5983, 5991, 6010, 6018, 6024, 6032, 6042, 6050, 6056, 6064, 6090,
-    6098, 6104, 6112, 6122, 6130, 6136, 6144, 6163, 6171, 6177, 6185, 6195,
-    6203, 6209, 6217, 6239, 6247, 6253, 6261, 6271, 6279, 6285, 6293, 6312,
-    6320, 6326, 6334, 6344, 6352, 6358, 6366, 6232, 6240, 6246, 6254, 6264,
-    6272, 6278, 6286, 6305, 6313, 6319, 6327, 6337, 6345, 6351, 6359, 6381,
-    6389, 6395, 6403, 6413, 6421, 6427, 6435, 6454, 6462, 6468, 6476, 6486,
-    6494, 6500, 6508, 6534, 6542, 6548, 6556, 6566, 6574, 6580, 6588, 6607,
-    6615, 6621, 6629, 6639, 6647, 6653, 6661, 6683, 6691, 6697, 6705, 6715,
-    6723, 6729, 6737, 6756, 6764, 6770, 6778, 6788, 6796, 6802, 6810, 6608,
-    6616, 6622, 6630, 6640, 6648, 6654, 6662, 6681, 6689, 6695, 6703, 6713,
-    6721, 6727, 6735, 6757, 6765, 6771, 6779, 6789, 6797, 6803, 6811, 6830,
-    6838, 6844, 6852, 6862, 6870, 6876, 6884, 6910, 6918, 6924, 6932, 6942,
-    6950, 6956, 6964, 6983, 6991, 6997, 7005, 7015, 7023, 7029, 7037, 7059,
-    7067, 7073, 7081, 7091, 7099, 7105, 7113, 7132, 7140, 7146, 7154, 7164,
-    7172, 7178, 7186, 7052, 7060, 7066, 7074, 7084, 7092, 7098, 7106, 7125,
-    7133, 7139, 7147, 7157, 7165, 7171, 7179, 7201, 7209, 7215, 7223, 7233,
-    7241, 7247, 7255, 7274, 7282, 7288, 7296, 7306, 7314, 7320, 7328, 7354,
-    7362, 7368, 7376, 7386, 7394, 7400, 7408, 7427, 7435, 7441, 7449, 7459,
-    7467, 7473, 7481, 7503, 7511, 7517, 7525, 7535, 7543, 7549, 7557, 7576,
-    7584, 7590, 7598, 7608, 7616, 7622, 7630, 6899, 6907, 6913, 6921, 6931,
-    6939, 6945, 6953, 6972, 6980, 6986, 6994, 7004, 7012, 7018, 7026, 7048,
-    7056, 7062, 7070, 7080, 7088, 7094, 7102, 7121, 7129, 7135, 7143, 7153,
-    7161, 7167, 7175, 7201, 7209, 7215, 7223, 7233, 7241, 7247, 7255, 7274,
-    7282, 7288, 7296, 7306, 7314, 7320, 7328, 7350, 7358, 7364, 7372, 7382,
-    7390, 7396, 7404, 7423, 7431, 7437, 7445, 7455, 7463, 7469, 7477, 7343,
-    7351, 7357, 7365, 7375, 7383, 7389, 7397, 7416, 7424, 7430, 7438, 7448,
-    7456, 7462, 7470, 7492, 7500, 7506, 7514, 7524, 7532, 7538, 7546, 7565,
-    7573, 7579, 7587, 7597, 7605, 7611, 7619, 7645, 7653, 7659, 7667, 7677,
-    7685, 7691, 7699, 7718, 7726, 7732, 7740, 7750, 7758, 7764, 7772, 7794,
-    7802, 7808, 7816, 7826, 7834, 7840, 7848, 7867, 7875, 7881, 7889, 7899,
-    7907, 7913, 7921, 7719, 7727, 7733, 7741, 7751, 7759, 7765, 7773, 7792,
-    7800, 7806, 7814, 7824, 7832, 7838, 7846, 7868, 7876, 7882, 7890, 7900,
-    7908, 7914, 7922, 7941, 7949, 7955, 7963, 7973, 7981, 7987, 7995, 8021,
-    8029, 8035, 8043, 8053, 8061, 8067, 8075, 8094, 8102, 8108, 8116, 8126,
-    8134, 8140, 8148, 8170, 8178, 8184, 8192, 8202, 8210, 8216, 8224, 8243,
-    8251, 8257, 8265, 8275
-};
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP8_ENCODER_DCT_VALUE_COST_H_
diff --git a/vp8/encoder/dct_value_tokens.h b/vp8/encoder/dct_value_tokens.h
deleted file mode 100644 (file)
index c2aadef..0000000
+++ /dev/null
@@ -1,712 +0,0 @@
-/*
- *  Copyright (c) 2012 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.
- */
-
-#ifndef VP8_ENCODER_DCT_VALUE_TOKENS_H_
-#define VP8_ENCODER_DCT_VALUE_TOKENS_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* Generated file, included by tokenize.c  */
-/* Values generated by fill_value_tokens() */
-
-static const TOKENVALUE dct_value_tokens[2048*2] =
-{
-    {10, 3963}, {10, 3961}, {10, 3959}, {10, 3957}, {10, 3955}, {10, 3953},
-    {10, 3951}, {10, 3949}, {10, 3947}, {10, 3945}, {10, 3943}, {10, 3941},
-    {10, 3939}, {10, 3937}, {10, 3935}, {10, 3933}, {10, 3931}, {10, 3929},
-    {10, 3927}, {10, 3925}, {10, 3923}, {10, 3921}, {10, 3919}, {10, 3917},
-    {10, 3915}, {10, 3913}, {10, 3911}, {10, 3909}, {10, 3907}, {10, 3905},
-    {10, 3903}, {10, 3901}, {10, 3899}, {10, 3897}, {10, 3895}, {10, 3893},
-    {10, 3891}, {10, 3889}, {10, 3887}, {10, 3885}, {10, 3883}, {10, 3881},
-    {10, 3879}, {10, 3877}, {10, 3875}, {10, 3873}, {10, 3871}, {10, 3869},
-    {10, 3867}, {10, 3865}, {10, 3863}, {10, 3861}, {10, 3859}, {10, 3857},
-    {10, 3855}, {10, 3853}, {10, 3851}, {10, 3849}, {10, 3847}, {10, 3845},
-    {10, 3843}, {10, 3841}, {10, 3839}, {10, 3837}, {10, 3835}, {10, 3833},
-    {10, 3831}, {10, 3829}, {10, 3827}, {10, 3825}, {10, 3823}, {10, 3821},
-    {10, 3819}, {10, 3817}, {10, 3815}, {10, 3813}, {10, 3811}, {10, 3809},
-    {10, 3807}, {10, 3805}, {10, 3803}, {10, 3801}, {10, 3799}, {10, 3797},
-    {10, 3795}, {10, 3793}, {10, 3791}, {10, 3789}, {10, 3787}, {10, 3785},
-    {10, 3783}, {10, 3781}, {10, 3779}, {10, 3777}, {10, 3775}, {10, 3773},
-    {10, 3771}, {10, 3769}, {10, 3767}, {10, 3765}, {10, 3763}, {10, 3761},
-    {10, 3759}, {10, 3757}, {10, 3755}, {10, 3753}, {10, 3751}, {10, 3749},
-    {10, 3747}, {10, 3745}, {10, 3743}, {10, 3741}, {10, 3739}, {10, 3737},
-    {10, 3735}, {10, 3733}, {10, 3731}, {10, 3729}, {10, 3727}, {10, 3725},
-    {10, 3723}, {10, 3721}, {10, 3719}, {10, 3717}, {10, 3715}, {10, 3713},
-    {10, 3711}, {10, 3709}, {10, 3707}, {10, 3705}, {10, 3703}, {10, 3701},
-    {10, 3699}, {10, 3697}, {10, 3695}, {10, 3693}, {10, 3691}, {10, 3689},
-    {10, 3687}, {10, 3685}, {10, 3683}, {10, 3681}, {10, 3679}, {10, 3677},
-    {10, 3675}, {10, 3673}, {10, 3671}, {10, 3669}, {10, 3667}, {10, 3665},
-    {10, 3663}, {10, 3661}, {10, 3659}, {10, 3657}, {10, 3655}, {10, 3653},
-    {10, 3651}, {10, 3649}, {10, 3647}, {10, 3645}, {10, 3643}, {10, 3641},
-    {10, 3639}, {10, 3637}, {10, 3635}, {10, 3633}, {10, 3631}, {10, 3629},
-    {10, 3627}, {10, 3625}, {10, 3623}, {10, 3621}, {10, 3619}, {10, 3617},
-    {10, 3615}, {10, 3613}, {10, 3611}, {10, 3609}, {10, 3607}, {10, 3605},
-    {10, 3603}, {10, 3601}, {10, 3599}, {10, 3597}, {10, 3595}, {10, 3593},
-    {10, 3591}, {10, 3589}, {10, 3587}, {10, 3585}, {10, 3583}, {10, 3581},
-    {10, 3579}, {10, 3577}, {10, 3575}, {10, 3573}, {10, 3571}, {10, 3569},
-    {10, 3567}, {10, 3565}, {10, 3563}, {10, 3561}, {10, 3559}, {10, 3557},
-    {10, 3555}, {10, 3553}, {10, 3551}, {10, 3549}, {10, 3547}, {10, 3545},
-    {10, 3543}, {10, 3541}, {10, 3539}, {10, 3537}, {10, 3535}, {10, 3533},
-    {10, 3531}, {10, 3529}, {10, 3527}, {10, 3525}, {10, 3523}, {10, 3521},
-    {10, 3519}, {10, 3517}, {10, 3515}, {10, 3513}, {10, 3511}, {10, 3509},
-    {10, 3507}, {10, 3505}, {10, 3503}, {10, 3501}, {10, 3499}, {10, 3497},
-    {10, 3495}, {10, 3493}, {10, 3491}, {10, 3489}, {10, 3487}, {10, 3485},
-    {10, 3483}, {10, 3481}, {10, 3479}, {10, 3477}, {10, 3475}, {10, 3473},
-    {10, 3471}, {10, 3469}, {10, 3467}, {10, 3465}, {10, 3463}, {10, 3461},
-    {10, 3459}, {10, 3457}, {10, 3455}, {10, 3453}, {10, 3451}, {10, 3449},
-    {10, 3447}, {10, 3445}, {10, 3443}, {10, 3441}, {10, 3439}, {10, 3437},
-    {10, 3435}, {10, 3433}, {10, 3431}, {10, 3429}, {10, 3427}, {10, 3425},
-    {10, 3423}, {10, 3421}, {10, 3419}, {10, 3417}, {10, 3415}, {10, 3413},
-    {10, 3411}, {10, 3409}, {10, 3407}, {10, 3405}, {10, 3403}, {10, 3401},
-    {10, 3399}, {10, 3397}, {10, 3395}, {10, 3393}, {10, 3391}, {10, 3389},
-    {10, 3387}, {10, 3385}, {10, 3383}, {10, 3381}, {10, 3379}, {10, 3377},
-    {10, 3375}, {10, 3373}, {10, 3371}, {10, 3369}, {10, 3367}, {10, 3365},
-    {10, 3363}, {10, 3361}, {10, 3359}, {10, 3357}, {10, 3355}, {10, 3353},
-    {10, 3351}, {10, 3349}, {10, 3347}, {10, 3345}, {10, 3343}, {10, 3341},
-    {10, 3339}, {10, 3337}, {10, 3335}, {10, 3333}, {10, 3331}, {10, 3329},
-    {10, 3327}, {10, 3325}, {10, 3323}, {10, 3321}, {10, 3319}, {10, 3317},
-    {10, 3315}, {10, 3313}, {10, 3311}, {10, 3309}, {10, 3307}, {10, 3305},
-    {10, 3303}, {10, 3301}, {10, 3299}, {10, 3297}, {10, 3295}, {10, 3293},
-    {10, 3291}, {10, 3289}, {10, 3287}, {10, 3285}, {10, 3283}, {10, 3281},
-    {10, 3279}, {10, 3277}, {10, 3275}, {10, 3273}, {10, 3271}, {10, 3269},
-    {10, 3267}, {10, 3265}, {10, 3263}, {10, 3261}, {10, 3259}, {10, 3257},
-    {10, 3255}, {10, 3253}, {10, 3251}, {10, 3249}, {10, 3247}, {10, 3245},
-    {10, 3243}, {10, 3241}, {10, 3239}, {10, 3237}, {10, 3235}, {10, 3233},
-    {10, 3231}, {10, 3229}, {10, 3227}, {10, 3225}, {10, 3223}, {10, 3221},
-    {10, 3219}, {10, 3217}, {10, 3215}, {10, 3213}, {10, 3211}, {10, 3209},
-    {10, 3207}, {10, 3205}, {10, 3203}, {10, 3201}, {10, 3199}, {10, 3197},
-    {10, 3195}, {10, 3193}, {10, 3191}, {10, 3189}, {10, 3187}, {10, 3185},
-    {10, 3183}, {10, 3181}, {10, 3179}, {10, 3177}, {10, 3175}, {10, 3173},
-    {10, 3171}, {10, 3169}, {10, 3167}, {10, 3165}, {10, 3163}, {10, 3161},
-    {10, 3159}, {10, 3157}, {10, 3155}, {10, 3153}, {10, 3151}, {10, 3149},
-    {10, 3147}, {10, 3145}, {10, 3143}, {10, 3141}, {10, 3139}, {10, 3137},
-    {10, 3135}, {10, 3133}, {10, 3131}, {10, 3129}, {10, 3127}, {10, 3125},
-    {10, 3123}, {10, 3121}, {10, 3119}, {10, 3117}, {10, 3115}, {10, 3113},
-    {10, 3111}, {10, 3109}, {10, 3107}, {10, 3105}, {10, 3103}, {10, 3101},
-    {10, 3099}, {10, 3097}, {10, 3095}, {10, 3093}, {10, 3091}, {10, 3089},
-    {10, 3087}, {10, 3085}, {10, 3083}, {10, 3081}, {10, 3079}, {10, 3077},
-    {10, 3075}, {10, 3073}, {10, 3071}, {10, 3069}, {10, 3067}, {10, 3065},
-    {10, 3063}, {10, 3061}, {10, 3059}, {10, 3057}, {10, 3055}, {10, 3053},
-    {10, 3051}, {10, 3049}, {10, 3047}, {10, 3045}, {10, 3043}, {10, 3041},
-    {10, 3039}, {10, 3037}, {10, 3035}, {10, 3033}, {10, 3031}, {10, 3029},
-    {10, 3027}, {10, 3025}, {10, 3023}, {10, 3021}, {10, 3019}, {10, 3017},
-    {10, 3015}, {10, 3013}, {10, 3011}, {10, 3009}, {10, 3007}, {10, 3005},
-    {10, 3003}, {10, 3001}, {10, 2999}, {10, 2997}, {10, 2995}, {10, 2993},
-    {10, 2991}, {10, 2989}, {10, 2987}, {10, 2985}, {10, 2983}, {10, 2981},
-    {10, 2979}, {10, 2977}, {10, 2975}, {10, 2973}, {10, 2971}, {10, 2969},
-    {10, 2967}, {10, 2965}, {10, 2963}, {10, 2961}, {10, 2959}, {10, 2957},
-    {10, 2955}, {10, 2953}, {10, 2951}, {10, 2949}, {10, 2947}, {10, 2945},
-    {10, 2943}, {10, 2941}, {10, 2939}, {10, 2937}, {10, 2935}, {10, 2933},
-    {10, 2931}, {10, 2929}, {10, 2927}, {10, 2925}, {10, 2923}, {10, 2921},
-    {10, 2919}, {10, 2917}, {10, 2915}, {10, 2913}, {10, 2911}, {10, 2909},
-    {10, 2907}, {10, 2905}, {10, 2903}, {10, 2901}, {10, 2899}, {10, 2897},
-    {10, 2895}, {10, 2893}, {10, 2891}, {10, 2889}, {10, 2887}, {10, 2885},
-    {10, 2883}, {10, 2881}, {10, 2879}, {10, 2877}, {10, 2875}, {10, 2873},
-    {10, 2871}, {10, 2869}, {10, 2867}, {10, 2865}, {10, 2863}, {10, 2861},
-    {10, 2859}, {10, 2857}, {10, 2855}, {10, 2853}, {10, 2851}, {10, 2849},
-    {10, 2847}, {10, 2845}, {10, 2843}, {10, 2841}, {10, 2839}, {10, 2837},
-    {10, 2835}, {10, 2833}, {10, 2831}, {10, 2829}, {10, 2827}, {10, 2825},
-    {10, 2823}, {10, 2821}, {10, 2819}, {10, 2817}, {10, 2815}, {10, 2813},
-    {10, 2811}, {10, 2809}, {10, 2807}, {10, 2805}, {10, 2803}, {10, 2801},
-    {10, 2799}, {10, 2797}, {10, 2795}, {10, 2793}, {10, 2791}, {10, 2789},
-    {10, 2787}, {10, 2785}, {10, 2783}, {10, 2781}, {10, 2779}, {10, 2777},
-    {10, 2775}, {10, 2773}, {10, 2771}, {10, 2769}, {10, 2767}, {10, 2765},
-    {10, 2763}, {10, 2761}, {10, 2759}, {10, 2757}, {10, 2755}, {10, 2753},
-    {10, 2751}, {10, 2749}, {10, 2747}, {10, 2745}, {10, 2743}, {10, 2741},
-    {10, 2739}, {10, 2737}, {10, 2735}, {10, 2733}, {10, 2731}, {10, 2729},
-    {10, 2727}, {10, 2725}, {10, 2723}, {10, 2721}, {10, 2719}, {10, 2717},
-    {10, 2715}, {10, 2713}, {10, 2711}, {10, 2709}, {10, 2707}, {10, 2705},
-    {10, 2703}, {10, 2701}, {10, 2699}, {10, 2697}, {10, 2695}, {10, 2693},
-    {10, 2691}, {10, 2689}, {10, 2687}, {10, 2685}, {10, 2683}, {10, 2681},
-    {10, 2679}, {10, 2677}, {10, 2675}, {10, 2673}, {10, 2671}, {10, 2669},
-    {10, 2667}, {10, 2665}, {10, 2663}, {10, 2661}, {10, 2659}, {10, 2657},
-    {10, 2655}, {10, 2653}, {10, 2651}, {10, 2649}, {10, 2647}, {10, 2645},
-    {10, 2643}, {10, 2641}, {10, 2639}, {10, 2637}, {10, 2635}, {10, 2633},
-    {10, 2631}, {10, 2629}, {10, 2627}, {10, 2625}, {10, 2623}, {10, 2621},
-    {10, 2619}, {10, 2617}, {10, 2615}, {10, 2613}, {10, 2611}, {10, 2609},
-    {10, 2607}, {10, 2605}, {10, 2603}, {10, 2601}, {10, 2599}, {10, 2597},
-    {10, 2595}, {10, 2593}, {10, 2591}, {10, 2589}, {10, 2587}, {10, 2585},
-    {10, 2583}, {10, 2581}, {10, 2579}, {10, 2577}, {10, 2575}, {10, 2573},
-    {10, 2571}, {10, 2569}, {10, 2567}, {10, 2565}, {10, 2563}, {10, 2561},
-    {10, 2559}, {10, 2557}, {10, 2555}, {10, 2553}, {10, 2551}, {10, 2549},
-    {10, 2547}, {10, 2545}, {10, 2543}, {10, 2541}, {10, 2539}, {10, 2537},
-    {10, 2535}, {10, 2533}, {10, 2531}, {10, 2529}, {10, 2527}, {10, 2525},
-    {10, 2523}, {10, 2521}, {10, 2519}, {10, 2517}, {10, 2515}, {10, 2513},
-    {10, 2511}, {10, 2509}, {10, 2507}, {10, 2505}, {10, 2503}, {10, 2501},
-    {10, 2499}, {10, 2497}, {10, 2495}, {10, 2493}, {10, 2491}, {10, 2489},
-    {10, 2487}, {10, 2485}, {10, 2483}, {10, 2481}, {10, 2479}, {10, 2477},
-    {10, 2475}, {10, 2473}, {10, 2471}, {10, 2469}, {10, 2467}, {10, 2465},
-    {10, 2463}, {10, 2461}, {10, 2459}, {10, 2457}, {10, 2455}, {10, 2453},
-    {10, 2451}, {10, 2449}, {10, 2447}, {10, 2445}, {10, 2443}, {10, 2441},
-    {10, 2439}, {10, 2437}, {10, 2435}, {10, 2433}, {10, 2431}, {10, 2429},
-    {10, 2427}, {10, 2425}, {10, 2423}, {10, 2421}, {10, 2419}, {10, 2417},
-    {10, 2415}, {10, 2413}, {10, 2411}, {10, 2409}, {10, 2407}, {10, 2405},
-    {10, 2403}, {10, 2401}, {10, 2399}, {10, 2397}, {10, 2395}, {10, 2393},
-    {10, 2391}, {10, 2389}, {10, 2387}, {10, 2385}, {10, 2383}, {10, 2381},
-    {10, 2379}, {10, 2377}, {10, 2375}, {10, 2373}, {10, 2371}, {10, 2369},
-    {10, 2367}, {10, 2365}, {10, 2363}, {10, 2361}, {10, 2359}, {10, 2357},
-    {10, 2355}, {10, 2353}, {10, 2351}, {10, 2349}, {10, 2347}, {10, 2345},
-    {10, 2343}, {10, 2341}, {10, 2339}, {10, 2337}, {10, 2335}, {10, 2333},
-    {10, 2331}, {10, 2329}, {10, 2327}, {10, 2325}, {10, 2323}, {10, 2321},
-    {10, 2319}, {10, 2317}, {10, 2315}, {10, 2313}, {10, 2311}, {10, 2309},
-    {10, 2307}, {10, 2305}, {10, 2303}, {10, 2301}, {10, 2299}, {10, 2297},
-    {10, 2295}, {10, 2293}, {10, 2291}, {10, 2289}, {10, 2287}, {10, 2285},
-    {10, 2283}, {10, 2281}, {10, 2279}, {10, 2277}, {10, 2275}, {10, 2273},
-    {10, 2271}, {10, 2269}, {10, 2267}, {10, 2265}, {10, 2263}, {10, 2261},
-    {10, 2259}, {10, 2257}, {10, 2255}, {10, 2253}, {10, 2251}, {10, 2249},
-    {10, 2247}, {10, 2245}, {10, 2243}, {10, 2241}, {10, 2239}, {10, 2237},
-    {10, 2235}, {10, 2233}, {10, 2231}, {10, 2229}, {10, 2227}, {10, 2225},
-    {10, 2223}, {10, 2221}, {10, 2219}, {10, 2217}, {10, 2215}, {10, 2213},
-    {10, 2211}, {10, 2209}, {10, 2207}, {10, 2205}, {10, 2203}, {10, 2201},
-    {10, 2199}, {10, 2197}, {10, 2195}, {10, 2193}, {10, 2191}, {10, 2189},
-    {10, 2187}, {10, 2185}, {10, 2183}, {10, 2181}, {10, 2179}, {10, 2177},
-    {10, 2175}, {10, 2173}, {10, 2171}, {10, 2169}, {10, 2167}, {10, 2165},
-    {10, 2163}, {10, 2161}, {10, 2159}, {10, 2157}, {10, 2155}, {10, 2153},
-    {10, 2151}, {10, 2149}, {10, 2147}, {10, 2145}, {10, 2143}, {10, 2141},
-    {10, 2139}, {10, 2137}, {10, 2135}, {10, 2133}, {10, 2131}, {10, 2129},
-    {10, 2127}, {10, 2125}, {10, 2123}, {10, 2121}, {10, 2119}, {10, 2117},
-    {10, 2115}, {10, 2113}, {10, 2111}, {10, 2109}, {10, 2107}, {10, 2105},
-    {10, 2103}, {10, 2101}, {10, 2099}, {10, 2097}, {10, 2095}, {10, 2093},
-    {10, 2091}, {10, 2089}, {10, 2087}, {10, 2085}, {10, 2083}, {10, 2081},
-    {10, 2079}, {10, 2077}, {10, 2075}, {10, 2073}, {10, 2071}, {10, 2069},
-    {10, 2067}, {10, 2065}, {10, 2063}, {10, 2061}, {10, 2059}, {10, 2057},
-    {10, 2055}, {10, 2053}, {10, 2051}, {10, 2049}, {10, 2047}, {10, 2045},
-    {10, 2043}, {10, 2041}, {10, 2039}, {10, 2037}, {10, 2035}, {10, 2033},
-    {10, 2031}, {10, 2029}, {10, 2027}, {10, 2025}, {10, 2023}, {10, 2021},
-    {10, 2019}, {10, 2017}, {10, 2015}, {10, 2013}, {10, 2011}, {10, 2009},
-    {10, 2007}, {10, 2005}, {10, 2003}, {10, 2001}, {10, 1999}, {10, 1997},
-    {10, 1995}, {10, 1993}, {10, 1991}, {10, 1989}, {10, 1987}, {10, 1985},
-    {10, 1983}, {10, 1981}, {10, 1979}, {10, 1977}, {10, 1975}, {10, 1973},
-    {10, 1971}, {10, 1969}, {10, 1967}, {10, 1965}, {10, 1963}, {10, 1961},
-    {10, 1959}, {10, 1957}, {10, 1955}, {10, 1953}, {10, 1951}, {10, 1949},
-    {10, 1947}, {10, 1945}, {10, 1943}, {10, 1941}, {10, 1939}, {10, 1937},
-    {10, 1935}, {10, 1933}, {10, 1931}, {10, 1929}, {10, 1927}, {10, 1925},
-    {10, 1923}, {10, 1921}, {10, 1919}, {10, 1917}, {10, 1915}, {10, 1913},
-    {10, 1911}, {10, 1909}, {10, 1907}, {10, 1905}, {10, 1903}, {10, 1901},
-    {10, 1899}, {10, 1897}, {10, 1895}, {10, 1893}, {10, 1891}, {10, 1889},
-    {10, 1887}, {10, 1885}, {10, 1883}, {10, 1881}, {10, 1879}, {10, 1877},
-    {10, 1875}, {10, 1873}, {10, 1871}, {10, 1869}, {10, 1867}, {10, 1865},
-    {10, 1863}, {10, 1861}, {10, 1859}, {10, 1857}, {10, 1855}, {10, 1853},
-    {10, 1851}, {10, 1849}, {10, 1847}, {10, 1845}, {10, 1843}, {10, 1841},
-    {10, 1839}, {10, 1837}, {10, 1835}, {10, 1833}, {10, 1831}, {10, 1829},
-    {10, 1827}, {10, 1825}, {10, 1823}, {10, 1821}, {10, 1819}, {10, 1817},
-    {10, 1815}, {10, 1813}, {10, 1811}, {10, 1809}, {10, 1807}, {10, 1805},
-    {10, 1803}, {10, 1801}, {10, 1799}, {10, 1797}, {10, 1795}, {10, 1793},
-    {10, 1791}, {10, 1789}, {10, 1787}, {10, 1785}, {10, 1783}, {10, 1781},
-    {10, 1779}, {10, 1777}, {10, 1775}, {10, 1773}, {10, 1771}, {10, 1769},
-    {10, 1767}, {10, 1765}, {10, 1763}, {10, 1761}, {10, 1759}, {10, 1757},
-    {10, 1755}, {10, 1753}, {10, 1751}, {10, 1749}, {10, 1747}, {10, 1745},
-    {10, 1743}, {10, 1741}, {10, 1739}, {10, 1737}, {10, 1735}, {10, 1733},
-    {10, 1731}, {10, 1729}, {10, 1727}, {10, 1725}, {10, 1723}, {10, 1721},
-    {10, 1719}, {10, 1717}, {10, 1715}, {10, 1713}, {10, 1711}, {10, 1709},
-    {10, 1707}, {10, 1705}, {10, 1703}, {10, 1701}, {10, 1699}, {10, 1697},
-    {10, 1695}, {10, 1693}, {10, 1691}, {10, 1689}, {10, 1687}, {10, 1685},
-    {10, 1683}, {10, 1681}, {10, 1679}, {10, 1677}, {10, 1675}, {10, 1673},
-    {10, 1671}, {10, 1669}, {10, 1667}, {10, 1665}, {10, 1663}, {10, 1661},
-    {10, 1659}, {10, 1657}, {10, 1655}, {10, 1653}, {10, 1651}, {10, 1649},
-    {10, 1647}, {10, 1645}, {10, 1643}, {10, 1641}, {10, 1639}, {10, 1637},
-    {10, 1635}, {10, 1633}, {10, 1631}, {10, 1629}, {10, 1627}, {10, 1625},
-    {10, 1623}, {10, 1621}, {10, 1619}, {10, 1617}, {10, 1615}, {10, 1613},
-    {10, 1611}, {10, 1609}, {10, 1607}, {10, 1605}, {10, 1603}, {10, 1601},
-    {10, 1599}, {10, 1597}, {10, 1595}, {10, 1593}, {10, 1591}, {10, 1589},
-    {10, 1587}, {10, 1585}, {10, 1583}, {10, 1581}, {10, 1579}, {10, 1577},
-    {10, 1575}, {10, 1573}, {10, 1571}, {10, 1569}, {10, 1567}, {10, 1565},
-    {10, 1563}, {10, 1561}, {10, 1559}, {10, 1557}, {10, 1555}, {10, 1553},
-    {10, 1551}, {10, 1549}, {10, 1547}, {10, 1545}, {10, 1543}, {10, 1541},
-    {10, 1539}, {10, 1537}, {10, 1535}, {10, 1533}, {10, 1531}, {10, 1529},
-    {10, 1527}, {10, 1525}, {10, 1523}, {10, 1521}, {10, 1519}, {10, 1517},
-    {10, 1515}, {10, 1513}, {10, 1511}, {10, 1509}, {10, 1507}, {10, 1505},
-    {10, 1503}, {10, 1501}, {10, 1499}, {10, 1497}, {10, 1495}, {10, 1493},
-    {10, 1491}, {10, 1489}, {10, 1487}, {10, 1485}, {10, 1483}, {10, 1481},
-    {10, 1479}, {10, 1477}, {10, 1475}, {10, 1473}, {10, 1471}, {10, 1469},
-    {10, 1467}, {10, 1465}, {10, 1463}, {10, 1461}, {10, 1459}, {10, 1457},
-    {10, 1455}, {10, 1453}, {10, 1451}, {10, 1449}, {10, 1447}, {10, 1445},
-    {10, 1443}, {10, 1441}, {10, 1439}, {10, 1437}, {10, 1435}, {10, 1433},
-    {10, 1431}, {10, 1429}, {10, 1427}, {10, 1425}, {10, 1423}, {10, 1421},
-    {10, 1419}, {10, 1417}, {10, 1415}, {10, 1413}, {10, 1411}, {10, 1409},
-    {10, 1407}, {10, 1405}, {10, 1403}, {10, 1401}, {10, 1399}, {10, 1397},
-    {10, 1395}, {10, 1393}, {10, 1391}, {10, 1389}, {10, 1387}, {10, 1385},
-    {10, 1383}, {10, 1381}, {10, 1379}, {10, 1377}, {10, 1375}, {10, 1373},
-    {10, 1371}, {10, 1369}, {10, 1367}, {10, 1365}, {10, 1363}, {10, 1361},
-    {10, 1359}, {10, 1357}, {10, 1355}, {10, 1353}, {10, 1351}, {10, 1349},
-    {10, 1347}, {10, 1345}, {10, 1343}, {10, 1341}, {10, 1339}, {10, 1337},
-    {10, 1335}, {10, 1333}, {10, 1331}, {10, 1329}, {10, 1327}, {10, 1325},
-    {10, 1323}, {10, 1321}, {10, 1319}, {10, 1317}, {10, 1315}, {10, 1313},
-    {10, 1311}, {10, 1309}, {10, 1307}, {10, 1305}, {10, 1303}, {10, 1301},
-    {10, 1299}, {10, 1297}, {10, 1295}, {10, 1293}, {10, 1291}, {10, 1289},
-    {10, 1287}, {10, 1285}, {10, 1283}, {10, 1281}, {10, 1279}, {10, 1277},
-    {10, 1275}, {10, 1273}, {10, 1271}, {10, 1269}, {10, 1267}, {10, 1265},
-    {10, 1263}, {10, 1261}, {10, 1259}, {10, 1257}, {10, 1255}, {10, 1253},
-    {10, 1251}, {10, 1249}, {10, 1247}, {10, 1245}, {10, 1243}, {10, 1241},
-    {10, 1239}, {10, 1237}, {10, 1235}, {10, 1233}, {10, 1231}, {10, 1229},
-    {10, 1227}, {10, 1225}, {10, 1223}, {10, 1221}, {10, 1219}, {10, 1217},
-    {10, 1215}, {10, 1213}, {10, 1211}, {10, 1209}, {10, 1207}, {10, 1205},
-    {10, 1203}, {10, 1201}, {10, 1199}, {10, 1197}, {10, 1195}, {10, 1193},
-    {10, 1191}, {10, 1189}, {10, 1187}, {10, 1185}, {10, 1183}, {10, 1181},
-    {10, 1179}, {10, 1177}, {10, 1175}, {10, 1173}, {10, 1171}, {10, 1169},
-    {10, 1167}, {10, 1165}, {10, 1163}, {10, 1161}, {10, 1159}, {10, 1157},
-    {10, 1155}, {10, 1153}, {10, 1151}, {10, 1149}, {10, 1147}, {10, 1145},
-    {10, 1143}, {10, 1141}, {10, 1139}, {10, 1137}, {10, 1135}, {10, 1133},
-    {10, 1131}, {10, 1129}, {10, 1127}, {10, 1125}, {10, 1123}, {10, 1121},
-    {10, 1119}, {10, 1117}, {10, 1115}, {10, 1113}, {10, 1111}, {10, 1109},
-    {10, 1107}, {10, 1105}, {10, 1103}, {10, 1101}, {10, 1099}, {10, 1097},
-    {10, 1095}, {10, 1093}, {10, 1091}, {10, 1089}, {10, 1087}, {10, 1085},
-    {10, 1083}, {10, 1081}, {10, 1079}, {10, 1077}, {10, 1075}, {10, 1073},
-    {10, 1071}, {10, 1069}, {10, 1067}, {10, 1065}, {10, 1063}, {10, 1061},
-    {10, 1059}, {10, 1057}, {10, 1055}, {10, 1053}, {10, 1051}, {10, 1049},
-    {10, 1047}, {10, 1045}, {10, 1043}, {10, 1041}, {10, 1039}, {10, 1037},
-    {10, 1035}, {10, 1033}, {10, 1031}, {10, 1029}, {10, 1027}, {10, 1025},
-    {10, 1023}, {10, 1021}, {10, 1019}, {10, 1017}, {10, 1015}, {10, 1013},
-    {10, 1011}, {10, 1009}, {10, 1007}, {10, 1005}, {10, 1003}, {10, 1001},
-    {10, 999}, {10, 997}, {10, 995}, {10, 993}, {10, 991}, {10, 989},
-    {10, 987}, {10, 985}, {10, 983}, {10, 981}, {10, 979}, {10, 977},
-    {10, 975}, {10, 973}, {10, 971}, {10, 969}, {10, 967}, {10, 965},
-    {10, 963}, {10, 961}, {10, 959}, {10, 957}, {10, 955}, {10, 953},
-    {10, 951}, {10, 949}, {10, 947}, {10, 945}, {10, 943}, {10, 941},
-    {10, 939}, {10, 937}, {10, 935}, {10, 933}, {10, 931}, {10, 929},
-    {10, 927}, {10, 925}, {10, 923}, {10, 921}, {10, 919}, {10, 917},
-    {10, 915}, {10, 913}, {10, 911}, {10, 909}, {10, 907}, {10, 905},
-    {10, 903}, {10, 901}, {10, 899}, {10, 897}, {10, 895}, {10, 893},
-    {10, 891}, {10, 889}, {10, 887}, {10, 885}, {10, 883}, {10, 881},
-    {10, 879}, {10, 877}, {10, 875}, {10, 873}, {10, 871}, {10, 869},
-    {10, 867}, {10, 865}, {10, 863}, {10, 861}, {10, 859}, {10, 857},
-    {10, 855}, {10, 853}, {10, 851}, {10, 849}, {10, 847}, {10, 845},
-    {10, 843}, {10, 841}, {10, 839}, {10, 837}, {10, 835}, {10, 833},
-    {10, 831}, {10, 829}, {10, 827}, {10, 825}, {10, 823}, {10, 821},
-    {10, 819}, {10, 817}, {10, 815}, {10, 813}, {10, 811}, {10, 809},
-    {10, 807}, {10, 805}, {10, 803}, {10, 801}, {10, 799}, {10, 797},
-    {10, 795}, {10, 793}, {10, 791}, {10, 789}, {10, 787}, {10, 785},
-    {10, 783}, {10, 781}, {10, 779}, {10, 777}, {10, 775}, {10, 773},
-    {10, 771}, {10, 769}, {10, 767}, {10, 765}, {10, 763}, {10, 761},
-    {10, 759}, {10, 757}, {10, 755}, {10, 753}, {10, 751}, {10, 749},
-    {10, 747}, {10, 745}, {10, 743}, {10, 741}, {10, 739}, {10, 737},
-    {10, 735}, {10, 733}, {10, 731}, {10, 729}, {10, 727}, {10, 725},
-    {10, 723}, {10, 721}, {10, 719}, {10, 717}, {10, 715}, {10, 713},
-    {10, 711}, {10, 709}, {10, 707}, {10, 705}, {10, 703}, {10, 701},
-    {10, 699}, {10, 697}, {10, 695}, {10, 693}, {10, 691}, {10, 689},
-    {10, 687}, {10, 685}, {10, 683}, {10, 681}, {10, 679}, {10, 677},
-    {10, 675}, {10, 673}, {10, 671}, {10, 669}, {10, 667}, {10, 665},
-    {10, 663}, {10, 661}, {10, 659}, {10, 657}, {10, 655}, {10, 653},
-    {10, 651}, {10, 649}, {10, 647}, {10, 645}, {10, 643}, {10, 641},
-    {10, 639}, {10, 637}, {10, 635}, {10, 633}, {10, 631}, {10, 629},
-    {10, 627}, {10, 625}, {10, 623}, {10, 621}, {10, 619}, {10, 617},
-    {10, 615}, {10, 613}, {10, 611}, {10, 609}, {10, 607}, {10, 605},
-    {10, 603}, {10, 601}, {10, 599}, {10, 597}, {10, 595}, {10, 593},
-    {10, 591}, {10, 589}, {10, 587}, {10, 585}, {10, 583}, {10, 581},
-    {10, 579}, {10, 577}, {10, 575}, {10, 573}, {10, 571}, {10, 569},
-    {10, 567}, {10, 565}, {10, 563}, {10, 561}, {10, 559}, {10, 557},
-    {10, 555}, {10, 553}, {10, 551}, {10, 549}, {10, 547}, {10, 545},
-    {10, 543}, {10, 541}, {10, 539}, {10, 537}, {10, 535}, {10, 533},
-    {10, 531}, {10, 529}, {10, 527}, {10, 525}, {10, 523}, {10, 521},
-    {10, 519}, {10, 517}, {10, 515}, {10, 513}, {10, 511}, {10, 509},
-    {10, 507}, {10, 505}, {10, 503}, {10, 501}, {10, 499}, {10, 497},
-    {10, 495}, {10, 493}, {10, 491}, {10, 489}, {10, 487}, {10, 485},
-    {10, 483}, {10, 481}, {10, 479}, {10, 477}, {10, 475}, {10, 473},
-    {10, 471}, {10, 469}, {10, 467}, {10, 465}, {10, 463}, {10, 461},
-    {10, 459}, {10, 457}, {10, 455}, {10, 453}, {10, 451}, {10, 449},
-    {10, 447}, {10, 445}, {10, 443}, {10, 441}, {10, 439}, {10, 437},
-    {10, 435}, {10, 433}, {10, 431}, {10, 429}, {10, 427}, {10, 425},
-    {10, 423}, {10, 421}, {10, 419}, {10, 417}, {10, 415}, {10, 413},
-    {10, 411}, {10, 409}, {10, 407}, {10, 405}, {10, 403}, {10, 401},
-    {10, 399}, {10, 397}, {10, 395}, {10, 393}, {10, 391}, {10, 389},
-    {10, 387}, {10, 385}, {10, 383}, {10, 381}, {10, 379}, {10, 377},
-    {10, 375}, {10, 373}, {10, 371}, {10, 369}, {10, 367}, {10, 365},
-    {10, 363}, {10, 361}, {10, 359}, {10, 357}, {10, 355}, {10, 353},
-    {10, 351}, {10, 349}, {10, 347}, {10, 345}, {10, 343}, {10, 341},
-    {10, 339}, {10, 337}, {10, 335}, {10, 333}, {10, 331}, {10, 329},
-    {10, 327}, {10, 325}, {10, 323}, {10, 321}, {10, 319}, {10, 317},
-    {10, 315}, {10, 313}, {10, 311}, {10, 309}, {10, 307}, {10, 305},
-    {10, 303}, {10, 301}, {10, 299}, {10, 297}, {10, 295}, {10, 293},
-    {10, 291}, {10, 289}, {10, 287}, {10, 285}, {10, 283}, {10, 281},
-    {10, 279}, {10, 277}, {10, 275}, {10, 273}, {10, 271}, {10, 269},
-    {10, 267}, {10, 265}, {10, 263}, {10, 261}, {10, 259}, {10, 257},
-    {10, 255}, {10, 253}, {10, 251}, {10, 249}, {10, 247}, {10, 245},
-    {10, 243}, {10, 241}, {10, 239}, {10, 237}, {10, 235}, {10, 233},
-    {10, 231}, {10, 229}, {10, 227}, {10, 225}, {10, 223}, {10, 221},
-    {10, 219}, {10, 217}, {10, 215}, {10, 213}, {10, 211}, {10, 209},
-    {10, 207}, {10, 205}, {10, 203}, {10, 201}, {10, 199}, {10, 197},
-    {10, 195}, {10, 193}, {10, 191}, {10, 189}, {10, 187}, {10, 185},
-    {10, 183}, {10, 181}, {10, 179}, {10, 177}, {10, 175}, {10, 173},
-    {10, 171}, {10, 169}, {10, 167}, {10, 165}, {10, 163}, {10, 161},
-    {10, 159}, {10, 157}, {10, 155}, {10, 153}, {10, 151}, {10, 149},
-    {10, 147}, {10, 145}, {10, 143}, {10, 141}, {10, 139}, {10, 137},
-    {10, 135}, {10, 133}, {10, 131}, {10, 129}, {10, 127}, {10, 125},
-    {10, 123}, {10, 121}, {10, 119}, {10, 117}, {10, 115}, {10, 113},
-    {10, 111}, {10, 109}, {10, 107}, {10, 105}, {10, 103}, {10, 101},
-    {10, 99}, {10, 97}, {10, 95}, {10, 93}, {10, 91}, {10, 89},
-    {10, 87}, {10, 85}, {10, 83}, {10, 81}, {10, 79}, {10, 77},
-    {10, 75}, {10, 73}, {10, 71}, {10, 69}, {10, 67}, {10, 65},
-    {10, 63}, {10, 61}, {10, 59}, {10, 57}, {10, 55}, {10, 53},
-    {10, 51}, {10, 49}, {10, 47}, {10, 45}, {10, 43}, {10, 41},
-    {10, 39}, {10, 37}, {10, 35}, {10, 33}, {10, 31}, {10, 29},
-    {10, 27}, {10, 25}, {10, 23}, {10, 21}, {10, 19}, {10, 17},
-    {10, 15}, {10, 13}, {10, 11}, {10, 9}, {10, 7}, {10, 5},
-    {10, 3}, {10, 1}, {9, 63}, {9, 61}, {9, 59}, {9, 57},
-    {9, 55}, {9, 53}, {9, 51}, {9, 49}, {9, 47}, {9, 45},
-    {9, 43}, {9, 41}, {9, 39}, {9, 37}, {9, 35}, {9, 33},
-    {9, 31}, {9, 29}, {9, 27}, {9, 25}, {9, 23}, {9, 21},
-    {9, 19}, {9, 17}, {9, 15}, {9, 13}, {9, 11}, {9, 9},
-    {9, 7}, {9, 5}, {9, 3}, {9, 1}, {8, 31}, {8, 29},
-    {8, 27}, {8, 25}, {8, 23}, {8, 21}, {8, 19}, {8, 17},
-    {8, 15}, {8, 13}, {8, 11}, {8, 9}, {8, 7}, {8, 5},
-    {8, 3}, {8, 1}, {7, 15}, {7, 13}, {7, 11}, {7, 9},
-    {7, 7}, {7, 5}, {7, 3}, {7, 1}, {6, 7}, {6, 5},
-    {6, 3}, {6, 1}, {5, 3}, {5, 1}, {4, 1}, {3, 1},
-    {2, 1}, {1, 1}, {0, 0}, {1, 0}, {2, 0}, {3, 0},
-    {4, 0}, {5, 0}, {5, 2}, {6, 0}, {6, 2}, {6, 4},
-    {6, 6}, {7, 0}, {7, 2}, {7, 4}, {7, 6}, {7, 8},
-    {7, 10}, {7, 12}, {7, 14}, {8, 0}, {8, 2}, {8, 4},
-    {8, 6}, {8, 8}, {8, 10}, {8, 12}, {8, 14}, {8, 16},
-    {8, 18}, {8, 20}, {8, 22}, {8, 24}, {8, 26}, {8, 28},
-    {8, 30}, {9, 0}, {9, 2}, {9, 4}, {9, 6}, {9, 8},
-    {9, 10}, {9, 12}, {9, 14}, {9, 16}, {9, 18}, {9, 20},
-    {9, 22}, {9, 24}, {9, 26}, {9, 28}, {9, 30}, {9, 32},
-    {9, 34}, {9, 36}, {9, 38}, {9, 40}, {9, 42}, {9, 44},
-    {9, 46}, {9, 48}, {9, 50}, {9, 52}, {9, 54}, {9, 56},
-    {9, 58}, {9, 60}, {9, 62}, {10, 0}, {10, 2}, {10, 4},
-    {10, 6}, {10, 8}, {10, 10}, {10, 12}, {10, 14}, {10, 16},
-    {10, 18}, {10, 20}, {10, 22}, {10, 24}, {10, 26}, {10, 28},
-    {10, 30}, {10, 32}, {10, 34}, {10, 36}, {10, 38}, {10, 40},
-    {10, 42}, {10, 44}, {10, 46}, {10, 48}, {10, 50}, {10, 52},
-    {10, 54}, {10, 56}, {10, 58}, {10, 60}, {10, 62}, {10, 64},
-    {10, 66}, {10, 68}, {10, 70}, {10, 72}, {10, 74}, {10, 76},
-    {10, 78}, {10, 80}, {10, 82}, {10, 84}, {10, 86}, {10, 88},
-    {10, 90}, {10, 92}, {10, 94}, {10, 96}, {10, 98}, {10, 100},
-    {10, 102}, {10, 104}, {10, 106}, {10, 108}, {10, 110}, {10, 112},
-    {10, 114}, {10, 116}, {10, 118}, {10, 120}, {10, 122}, {10, 124},
-    {10, 126}, {10, 128}, {10, 130}, {10, 132}, {10, 134}, {10, 136},
-    {10, 138}, {10, 140}, {10, 142}, {10, 144}, {10, 146}, {10, 148},
-    {10, 150}, {10, 152}, {10, 154}, {10, 156}, {10, 158}, {10, 160},
-    {10, 162}, {10, 164}, {10, 166}, {10, 168}, {10, 170}, {10, 172},
-    {10, 174}, {10, 176}, {10, 178}, {10, 180}, {10, 182}, {10, 184},
-    {10, 186}, {10, 188}, {10, 190}, {10, 192}, {10, 194}, {10, 196},
-    {10, 198}, {10, 200}, {10, 202}, {10, 204}, {10, 206}, {10, 208},
-    {10, 210}, {10, 212}, {10, 214}, {10, 216}, {10, 218}, {10, 220},
-    {10, 222}, {10, 224}, {10, 226}, {10, 228}, {10, 230}, {10, 232},
-    {10, 234}, {10, 236}, {10, 238}, {10, 240}, {10, 242}, {10, 244},
-    {10, 246}, {10, 248}, {10, 250}, {10, 252}, {10, 254}, {10, 256},
-    {10, 258}, {10, 260}, {10, 262}, {10, 264}, {10, 266}, {10, 268},
-    {10, 270}, {10, 272}, {10, 274}, {10, 276}, {10, 278}, {10, 280},
-    {10, 282}, {10, 284}, {10, 286}, {10, 288}, {10, 290}, {10, 292},
-    {10, 294}, {10, 296}, {10, 298}, {10, 300}, {10, 302}, {10, 304},
-    {10, 306}, {10, 308}, {10, 310}, {10, 312}, {10, 314}, {10, 316},
-    {10, 318}, {10, 320}, {10, 322}, {10, 324}, {10, 326}, {10, 328},
-    {10, 330}, {10, 332}, {10, 334}, {10, 336}, {10, 338}, {10, 340},
-    {10, 342}, {10, 344}, {10, 346}, {10, 348}, {10, 350}, {10, 352},
-    {10, 354}, {10, 356}, {10, 358}, {10, 360}, {10, 362}, {10, 364},
-    {10, 366}, {10, 368}, {10, 370}, {10, 372}, {10, 374}, {10, 376},
-    {10, 378}, {10, 380}, {10, 382}, {10, 384}, {10, 386}, {10, 388},
-    {10, 390}, {10, 392}, {10, 394}, {10, 396}, {10, 398}, {10, 400},
-    {10, 402}, {10, 404}, {10, 406}, {10, 408}, {10, 410}, {10, 412},
-    {10, 414}, {10, 416}, {10, 418}, {10, 420}, {10, 422}, {10, 424},
-    {10, 426}, {10, 428}, {10, 430}, {10, 432}, {10, 434}, {10, 436},
-    {10, 438}, {10, 440}, {10, 442}, {10, 444}, {10, 446}, {10, 448},
-    {10, 450}, {10, 452}, {10, 454}, {10, 456}, {10, 458}, {10, 460},
-    {10, 462}, {10, 464}, {10, 466}, {10, 468}, {10, 470}, {10, 472},
-    {10, 474}, {10, 476}, {10, 478}, {10, 480}, {10, 482}, {10, 484},
-    {10, 486}, {10, 488}, {10, 490}, {10, 492}, {10, 494}, {10, 496},
-    {10, 498}, {10, 500}, {10, 502}, {10, 504}, {10, 506}, {10, 508},
-    {10, 510}, {10, 512}, {10, 514}, {10, 516}, {10, 518}, {10, 520},
-    {10, 522}, {10, 524}, {10, 526}, {10, 528}, {10, 530}, {10, 532},
-    {10, 534}, {10, 536}, {10, 538}, {10, 540}, {10, 542}, {10, 544},
-    {10, 546}, {10, 548}, {10, 550}, {10, 552}, {10, 554}, {10, 556},
-    {10, 558}, {10, 560}, {10, 562}, {10, 564}, {10, 566}, {10, 568},
-    {10, 570}, {10, 572}, {10, 574}, {10, 576}, {10, 578}, {10, 580},
-    {10, 582}, {10, 584}, {10, 586}, {10, 588}, {10, 590}, {10, 592},
-    {10, 594}, {10, 596}, {10, 598}, {10, 600}, {10, 602}, {10, 604},
-    {10, 606}, {10, 608}, {10, 610}, {10, 612}, {10, 614}, {10, 616},
-    {10, 618}, {10, 620}, {10, 622}, {10, 624}, {10, 626}, {10, 628},
-    {10, 630}, {10, 632}, {10, 634}, {10, 636}, {10, 638}, {10, 640},
-    {10, 642}, {10, 644}, {10, 646}, {10, 648}, {10, 650}, {10, 652},
-    {10, 654}, {10, 656}, {10, 658}, {10, 660}, {10, 662}, {10, 664},
-    {10, 666}, {10, 668}, {10, 670}, {10, 672}, {10, 674}, {10, 676},
-    {10, 678}, {10, 680}, {10, 682}, {10, 684}, {10, 686}, {10, 688},
-    {10, 690}, {10, 692}, {10, 694}, {10, 696}, {10, 698}, {10, 700},
-    {10, 702}, {10, 704}, {10, 706}, {10, 708}, {10, 710}, {10, 712},
-    {10, 714}, {10, 716}, {10, 718}, {10, 720}, {10, 722}, {10, 724},
-    {10, 726}, {10, 728}, {10, 730}, {10, 732}, {10, 734}, {10, 736},
-    {10, 738}, {10, 740}, {10, 742}, {10, 744}, {10, 746}, {10, 748},
-    {10, 750}, {10, 752}, {10, 754}, {10, 756}, {10, 758}, {10, 760},
-    {10, 762}, {10, 764}, {10, 766}, {10, 768}, {10, 770}, {10, 772},
-    {10, 774}, {10, 776}, {10, 778}, {10, 780}, {10, 782}, {10, 784},
-    {10, 786}, {10, 788}, {10, 790}, {10, 792}, {10, 794}, {10, 796},
-    {10, 798}, {10, 800}, {10, 802}, {10, 804}, {10, 806}, {10, 808},
-    {10, 810}, {10, 812}, {10, 814}, {10, 816}, {10, 818}, {10, 820},
-    {10, 822}, {10, 824}, {10, 826}, {10, 828}, {10, 830}, {10, 832},
-    {10, 834}, {10, 836}, {10, 838}, {10, 840}, {10, 842}, {10, 844},
-    {10, 846}, {10, 848}, {10, 850}, {10, 852}, {10, 854}, {10, 856},
-    {10, 858}, {10, 860}, {10, 862}, {10, 864}, {10, 866}, {10, 868},
-    {10, 870}, {10, 872}, {10, 874}, {10, 876}, {10, 878}, {10, 880},
-    {10, 882}, {10, 884}, {10, 886}, {10, 888}, {10, 890}, {10, 892},
-    {10, 894}, {10, 896}, {10, 898}, {10, 900}, {10, 902}, {10, 904},
-    {10, 906}, {10, 908}, {10, 910}, {10, 912}, {10, 914}, {10, 916},
-    {10, 918}, {10, 920}, {10, 922}, {10, 924}, {10, 926}, {10, 928},
-    {10, 930}, {10, 932}, {10, 934}, {10, 936}, {10, 938}, {10, 940},
-    {10, 942}, {10, 944}, {10, 946}, {10, 948}, {10, 950}, {10, 952},
-    {10, 954}, {10, 956}, {10, 958}, {10, 960}, {10, 962}, {10, 964},
-    {10, 966}, {10, 968}, {10, 970}, {10, 972}, {10, 974}, {10, 976},
-    {10, 978}, {10, 980}, {10, 982}, {10, 984}, {10, 986}, {10, 988},
-    {10, 990}, {10, 992}, {10, 994}, {10, 996}, {10, 998}, {10, 1000},
-    {10, 1002}, {10, 1004}, {10, 1006}, {10, 1008}, {10, 1010}, {10, 1012},
-    {10, 1014}, {10, 1016}, {10, 1018}, {10, 1020}, {10, 1022}, {10, 1024},
-    {10, 1026}, {10, 1028}, {10, 1030}, {10, 1032}, {10, 1034}, {10, 1036},
-    {10, 1038}, {10, 1040}, {10, 1042}, {10, 1044}, {10, 1046}, {10, 1048},
-    {10, 1050}, {10, 1052}, {10, 1054}, {10, 1056}, {10, 1058}, {10, 1060},
-    {10, 1062}, {10, 1064}, {10, 1066}, {10, 1068}, {10, 1070}, {10, 1072},
-    {10, 1074}, {10, 1076}, {10, 1078}, {10, 1080}, {10, 1082}, {10, 1084},
-    {10, 1086}, {10, 1088}, {10, 1090}, {10, 1092}, {10, 1094}, {10, 1096},
-    {10, 1098}, {10, 1100}, {10, 1102}, {10, 1104}, {10, 1106}, {10, 1108},
-    {10, 1110}, {10, 1112}, {10, 1114}, {10, 1116}, {10, 1118}, {10, 1120},
-    {10, 1122}, {10, 1124}, {10, 1126}, {10, 1128}, {10, 1130}, {10, 1132},
-    {10, 1134}, {10, 1136}, {10, 1138}, {10, 1140}, {10, 1142}, {10, 1144},
-    {10, 1146}, {10, 1148}, {10, 1150}, {10, 1152}, {10, 1154}, {10, 1156},
-    {10, 1158}, {10, 1160}, {10, 1162}, {10, 1164}, {10, 1166}, {10, 1168},
-    {10, 1170}, {10, 1172}, {10, 1174}, {10, 1176}, {10, 1178}, {10, 1180},
-    {10, 1182}, {10, 1184}, {10, 1186}, {10, 1188}, {10, 1190}, {10, 1192},
-    {10, 1194}, {10, 1196}, {10, 1198}, {10, 1200}, {10, 1202}, {10, 1204},
-    {10, 1206}, {10, 1208}, {10, 1210}, {10, 1212}, {10, 1214}, {10, 1216},
-    {10, 1218}, {10, 1220}, {10, 1222}, {10, 1224}, {10, 1226}, {10, 1228},
-    {10, 1230}, {10, 1232}, {10, 1234}, {10, 1236}, {10, 1238}, {10, 1240},
-    {10, 1242}, {10, 1244}, {10, 1246}, {10, 1248}, {10, 1250}, {10, 1252},
-    {10, 1254}, {10, 1256}, {10, 1258}, {10, 1260}, {10, 1262}, {10, 1264},
-    {10, 1266}, {10, 1268}, {10, 1270}, {10, 1272}, {10, 1274}, {10, 1276},
-    {10, 1278}, {10, 1280}, {10, 1282}, {10, 1284}, {10, 1286}, {10, 1288},
-    {10, 1290}, {10, 1292}, {10, 1294}, {10, 1296}, {10, 1298}, {10, 1300},
-    {10, 1302}, {10, 1304}, {10, 1306}, {10, 1308}, {10, 1310}, {10, 1312},
-    {10, 1314}, {10, 1316}, {10, 1318}, {10, 1320}, {10, 1322}, {10, 1324},
-    {10, 1326}, {10, 1328}, {10, 1330}, {10, 1332}, {10, 1334}, {10, 1336},
-    {10, 1338}, {10, 1340}, {10, 1342}, {10, 1344}, {10, 1346}, {10, 1348},
-    {10, 1350}, {10, 1352}, {10, 1354}, {10, 1356}, {10, 1358}, {10, 1360},
-    {10, 1362}, {10, 1364}, {10, 1366}, {10, 1368}, {10, 1370}, {10, 1372},
-    {10, 1374}, {10, 1376}, {10, 1378}, {10, 1380}, {10, 1382}, {10, 1384},
-    {10, 1386}, {10, 1388}, {10, 1390}, {10, 1392}, {10, 1394}, {10, 1396},
-    {10, 1398}, {10, 1400}, {10, 1402}, {10, 1404}, {10, 1406}, {10, 1408},
-    {10, 1410}, {10, 1412}, {10, 1414}, {10, 1416}, {10, 1418}, {10, 1420},
-    {10, 1422}, {10, 1424}, {10, 1426}, {10, 1428}, {10, 1430}, {10, 1432},
-    {10, 1434}, {10, 1436}, {10, 1438}, {10, 1440}, {10, 1442}, {10, 1444},
-    {10, 1446}, {10, 1448}, {10, 1450}, {10, 1452}, {10, 1454}, {10, 1456},
-    {10, 1458}, {10, 1460}, {10, 1462}, {10, 1464}, {10, 1466}, {10, 1468},
-    {10, 1470}, {10, 1472}, {10, 1474}, {10, 1476}, {10, 1478}, {10, 1480},
-    {10, 1482}, {10, 1484}, {10, 1486}, {10, 1488}, {10, 1490}, {10, 1492},
-    {10, 1494}, {10, 1496}, {10, 1498}, {10, 1500}, {10, 1502}, {10, 1504},
-    {10, 1506}, {10, 1508}, {10, 1510}, {10, 1512}, {10, 1514}, {10, 1516},
-    {10, 1518}, {10, 1520}, {10, 1522}, {10, 1524}, {10, 1526}, {10, 1528},
-    {10, 1530}, {10, 1532}, {10, 1534}, {10, 1536}, {10, 1538}, {10, 1540},
-    {10, 1542}, {10, 1544}, {10, 1546}, {10, 1548}, {10, 1550}, {10, 1552},
-    {10, 1554}, {10, 1556}, {10, 1558}, {10, 1560}, {10, 1562}, {10, 1564},
-    {10, 1566}, {10, 1568}, {10, 1570}, {10, 1572}, {10, 1574}, {10, 1576},
-    {10, 1578}, {10, 1580}, {10, 1582}, {10, 1584}, {10, 1586}, {10, 1588},
-    {10, 1590}, {10, 1592}, {10, 1594}, {10, 1596}, {10, 1598}, {10, 1600},
-    {10, 1602}, {10, 1604}, {10, 1606}, {10, 1608}, {10, 1610}, {10, 1612},
-    {10, 1614}, {10, 1616}, {10, 1618}, {10, 1620}, {10, 1622}, {10, 1624},
-    {10, 1626}, {10, 1628}, {10, 1630}, {10, 1632}, {10, 1634}, {10, 1636},
-    {10, 1638}, {10, 1640}, {10, 1642}, {10, 1644}, {10, 1646}, {10, 1648},
-    {10, 1650}, {10, 1652}, {10, 1654}, {10, 1656}, {10, 1658}, {10, 1660},
-    {10, 1662}, {10, 1664}, {10, 1666}, {10, 1668}, {10, 1670}, {10, 1672},
-    {10, 1674}, {10, 1676}, {10, 1678}, {10, 1680}, {10, 1682}, {10, 1684},
-    {10, 1686}, {10, 1688}, {10, 1690}, {10, 1692}, {10, 1694}, {10, 1696},
-    {10, 1698}, {10, 1700}, {10, 1702}, {10, 1704}, {10, 1706}, {10, 1708},
-    {10, 1710}, {10, 1712}, {10, 1714}, {10, 1716}, {10, 1718}, {10, 1720},
-    {10, 1722}, {10, 1724}, {10, 1726}, {10, 1728}, {10, 1730}, {10, 1732},
-    {10, 1734}, {10, 1736}, {10, 1738}, {10, 1740}, {10, 1742}, {10, 1744},
-    {10, 1746}, {10, 1748}, {10, 1750}, {10, 1752}, {10, 1754}, {10, 1756},
-    {10, 1758}, {10, 1760}, {10, 1762}, {10, 1764}, {10, 1766}, {10, 1768},
-    {10, 1770}, {10, 1772}, {10, 1774}, {10, 1776}, {10, 1778}, {10, 1780},
-    {10, 1782}, {10, 1784}, {10, 1786}, {10, 1788}, {10, 1790}, {10, 1792},
-    {10, 1794}, {10, 1796}, {10, 1798}, {10, 1800}, {10, 1802}, {10, 1804},
-    {10, 1806}, {10, 1808}, {10, 1810}, {10, 1812}, {10, 1814}, {10, 1816},
-    {10, 1818}, {10, 1820}, {10, 1822}, {10, 1824}, {10, 1826}, {10, 1828},
-    {10, 1830}, {10, 1832}, {10, 1834}, {10, 1836}, {10, 1838}, {10, 1840},
-    {10, 1842}, {10, 1844}, {10, 1846}, {10, 1848}, {10, 1850}, {10, 1852},
-    {10, 1854}, {10, 1856}, {10, 1858}, {10, 1860}, {10, 1862}, {10, 1864},
-    {10, 1866}, {10, 1868}, {10, 1870}, {10, 1872}, {10, 1874}, {10, 1876},
-    {10, 1878}, {10, 1880}, {10, 1882}, {10, 1884}, {10, 1886}, {10, 1888},
-    {10, 1890}, {10, 1892}, {10, 1894}, {10, 1896}, {10, 1898}, {10, 1900},
-    {10, 1902}, {10, 1904}, {10, 1906}, {10, 1908}, {10, 1910}, {10, 1912},
-    {10, 1914}, {10, 1916}, {10, 1918}, {10, 1920}, {10, 1922}, {10, 1924},
-    {10, 1926}, {10, 1928}, {10, 1930}, {10, 1932}, {10, 1934}, {10, 1936},
-    {10, 1938}, {10, 1940}, {10, 1942}, {10, 1944}, {10, 1946}, {10, 1948},
-    {10, 1950}, {10, 1952}, {10, 1954}, {10, 1956}, {10, 1958}, {10, 1960},
-    {10, 1962}, {10, 1964}, {10, 1966}, {10, 1968}, {10, 1970}, {10, 1972},
-    {10, 1974}, {10, 1976}, {10, 1978}, {10, 1980}, {10, 1982}, {10, 1984},
-    {10, 1986}, {10, 1988}, {10, 1990}, {10, 1992}, {10, 1994}, {10, 1996},
-    {10, 1998}, {10, 2000}, {10, 2002}, {10, 2004}, {10, 2006}, {10, 2008},
-    {10, 2010}, {10, 2012}, {10, 2014}, {10, 2016}, {10, 2018}, {10, 2020},
-    {10, 2022}, {10, 2024}, {10, 2026}, {10, 2028}, {10, 2030}, {10, 2032},
-    {10, 2034}, {10, 2036}, {10, 2038}, {10, 2040}, {10, 2042}, {10, 2044},
-    {10, 2046}, {10, 2048}, {10, 2050}, {10, 2052}, {10, 2054}, {10, 2056},
-    {10, 2058}, {10, 2060}, {10, 2062}, {10, 2064}, {10, 2066}, {10, 2068},
-    {10, 2070}, {10, 2072}, {10, 2074}, {10, 2076}, {10, 2078}, {10, 2080},
-    {10, 2082}, {10, 2084}, {10, 2086}, {10, 2088}, {10, 2090}, {10, 2092},
-    {10, 2094}, {10, 2096}, {10, 2098}, {10, 2100}, {10, 2102}, {10, 2104},
-    {10, 2106}, {10, 2108}, {10, 2110}, {10, 2112}, {10, 2114}, {10, 2116},
-    {10, 2118}, {10, 2120}, {10, 2122}, {10, 2124}, {10, 2126}, {10, 2128},
-    {10, 2130}, {10, 2132}, {10, 2134}, {10, 2136}, {10, 2138}, {10, 2140},
-    {10, 2142}, {10, 2144}, {10, 2146}, {10, 2148}, {10, 2150}, {10, 2152},
-    {10, 2154}, {10, 2156}, {10, 2158}, {10, 2160}, {10, 2162}, {10, 2164},
-    {10, 2166}, {10, 2168}, {10, 2170}, {10, 2172}, {10, 2174}, {10, 2176},
-    {10, 2178}, {10, 2180}, {10, 2182}, {10, 2184}, {10, 2186}, {10, 2188},
-    {10, 2190}, {10, 2192}, {10, 2194}, {10, 2196}, {10, 2198}, {10, 2200},
-    {10, 2202}, {10, 2204}, {10, 2206}, {10, 2208}, {10, 2210}, {10, 2212},
-    {10, 2214}, {10, 2216}, {10, 2218}, {10, 2220}, {10, 2222}, {10, 2224},
-    {10, 2226}, {10, 2228}, {10, 2230}, {10, 2232}, {10, 2234}, {10, 2236},
-    {10, 2238}, {10, 2240}, {10, 2242}, {10, 2244}, {10, 2246}, {10, 2248},
-    {10, 2250}, {10, 2252}, {10, 2254}, {10, 2256}, {10, 2258}, {10, 2260},
-    {10, 2262}, {10, 2264}, {10, 2266}, {10, 2268}, {10, 2270}, {10, 2272},
-    {10, 2274}, {10, 2276}, {10, 2278}, {10, 2280}, {10, 2282}, {10, 2284},
-    {10, 2286}, {10, 2288}, {10, 2290}, {10, 2292}, {10, 2294}, {10, 2296},
-    {10, 2298}, {10, 2300}, {10, 2302}, {10, 2304}, {10, 2306}, {10, 2308},
-    {10, 2310}, {10, 2312}, {10, 2314}, {10, 2316}, {10, 2318}, {10, 2320},
-    {10, 2322}, {10, 2324}, {10, 2326}, {10, 2328}, {10, 2330}, {10, 2332},
-    {10, 2334}, {10, 2336}, {10, 2338}, {10, 2340}, {10, 2342}, {10, 2344},
-    {10, 2346}, {10, 2348}, {10, 2350}, {10, 2352}, {10, 2354}, {10, 2356},
-    {10, 2358}, {10, 2360}, {10, 2362}, {10, 2364}, {10, 2366}, {10, 2368},
-    {10, 2370}, {10, 2372}, {10, 2374}, {10, 2376}, {10, 2378}, {10, 2380},
-    {10, 2382}, {10, 2384}, {10, 2386}, {10, 2388}, {10, 2390}, {10, 2392},
-    {10, 2394}, {10, 2396}, {10, 2398}, {10, 2400}, {10, 2402}, {10, 2404},
-    {10, 2406}, {10, 2408}, {10, 2410}, {10, 2412}, {10, 2414}, {10, 2416},
-    {10, 2418}, {10, 2420}, {10, 2422}, {10, 2424}, {10, 2426}, {10, 2428},
-    {10, 2430}, {10, 2432}, {10, 2434}, {10, 2436}, {10, 2438}, {10, 2440},
-    {10, 2442}, {10, 2444}, {10, 2446}, {10, 2448}, {10, 2450}, {10, 2452},
-    {10, 2454}, {10, 2456}, {10, 2458}, {10, 2460}, {10, 2462}, {10, 2464},
-    {10, 2466}, {10, 2468}, {10, 2470}, {10, 2472}, {10, 2474}, {10, 2476},
-    {10, 2478}, {10, 2480}, {10, 2482}, {10, 2484}, {10, 2486}, {10, 2488},
-    {10, 2490}, {10, 2492}, {10, 2494}, {10, 2496}, {10, 2498}, {10, 2500},
-    {10, 2502}, {10, 2504}, {10, 2506}, {10, 2508}, {10, 2510}, {10, 2512},
-    {10, 2514}, {10, 2516}, {10, 2518}, {10, 2520}, {10, 2522}, {10, 2524},
-    {10, 2526}, {10, 2528}, {10, 2530}, {10, 2532}, {10, 2534}, {10, 2536},
-    {10, 2538}, {10, 2540}, {10, 2542}, {10, 2544}, {10, 2546}, {10, 2548},
-    {10, 2550}, {10, 2552}, {10, 2554}, {10, 2556}, {10, 2558}, {10, 2560},
-    {10, 2562}, {10, 2564}, {10, 2566}, {10, 2568}, {10, 2570}, {10, 2572},
-    {10, 2574}, {10, 2576}, {10, 2578}, {10, 2580}, {10, 2582}, {10, 2584},
-    {10, 2586}, {10, 2588}, {10, 2590}, {10, 2592}, {10, 2594}, {10, 2596},
-    {10, 2598}, {10, 2600}, {10, 2602}, {10, 2604}, {10, 2606}, {10, 2608},
-    {10, 2610}, {10, 2612}, {10, 2614}, {10, 2616}, {10, 2618}, {10, 2620},
-    {10, 2622}, {10, 2624}, {10, 2626}, {10, 2628}, {10, 2630}, {10, 2632},
-    {10, 2634}, {10, 2636}, {10, 2638}, {10, 2640}, {10, 2642}, {10, 2644},
-    {10, 2646}, {10, 2648}, {10, 2650}, {10, 2652}, {10, 2654}, {10, 2656},
-    {10, 2658}, {10, 2660}, {10, 2662}, {10, 2664}, {10, 2666}, {10, 2668},
-    {10, 2670}, {10, 2672}, {10, 2674}, {10, 2676}, {10, 2678}, {10, 2680},
-    {10, 2682}, {10, 2684}, {10, 2686}, {10, 2688}, {10, 2690}, {10, 2692},
-    {10, 2694}, {10, 2696}, {10, 2698}, {10, 2700}, {10, 2702}, {10, 2704},
-    {10, 2706}, {10, 2708}, {10, 2710}, {10, 2712}, {10, 2714}, {10, 2716},
-    {10, 2718}, {10, 2720}, {10, 2722}, {10, 2724}, {10, 2726}, {10, 2728},
-    {10, 2730}, {10, 2732}, {10, 2734}, {10, 2736}, {10, 2738}, {10, 2740},
-    {10, 2742}, {10, 2744}, {10, 2746}, {10, 2748}, {10, 2750}, {10, 2752},
-    {10, 2754}, {10, 2756}, {10, 2758}, {10, 2760}, {10, 2762}, {10, 2764},
-    {10, 2766}, {10, 2768}, {10, 2770}, {10, 2772}, {10, 2774}, {10, 2776},
-    {10, 2778}, {10, 2780}, {10, 2782}, {10, 2784}, {10, 2786}, {10, 2788},
-    {10, 2790}, {10, 2792}, {10, 2794}, {10, 2796}, {10, 2798}, {10, 2800},
-    {10, 2802}, {10, 2804}, {10, 2806}, {10, 2808}, {10, 2810}, {10, 2812},
-    {10, 2814}, {10, 2816}, {10, 2818}, {10, 2820}, {10, 2822}, {10, 2824},
-    {10, 2826}, {10, 2828}, {10, 2830}, {10, 2832}, {10, 2834}, {10, 2836},
-    {10, 2838}, {10, 2840}, {10, 2842}, {10, 2844}, {10, 2846}, {10, 2848},
-    {10, 2850}, {10, 2852}, {10, 2854}, {10, 2856}, {10, 2858}, {10, 2860},
-    {10, 2862}, {10, 2864}, {10, 2866}, {10, 2868}, {10, 2870}, {10, 2872},
-    {10, 2874}, {10, 2876}, {10, 2878}, {10, 2880}, {10, 2882}, {10, 2884},
-    {10, 2886}, {10, 2888}, {10, 2890}, {10, 2892}, {10, 2894}, {10, 2896},
-    {10, 2898}, {10, 2900}, {10, 2902}, {10, 2904}, {10, 2906}, {10, 2908},
-    {10, 2910}, {10, 2912}, {10, 2914}, {10, 2916}, {10, 2918}, {10, 2920},
-    {10, 2922}, {10, 2924}, {10, 2926}, {10, 2928}, {10, 2930}, {10, 2932},
-    {10, 2934}, {10, 2936}, {10, 2938}, {10, 2940}, {10, 2942}, {10, 2944},
-    {10, 2946}, {10, 2948}, {10, 2950}, {10, 2952}, {10, 2954}, {10, 2956},
-    {10, 2958}, {10, 2960}, {10, 2962}, {10, 2964}, {10, 2966}, {10, 2968},
-    {10, 2970}, {10, 2972}, {10, 2974}, {10, 2976}, {10, 2978}, {10, 2980},
-    {10, 2982}, {10, 2984}, {10, 2986}, {10, 2988}, {10, 2990}, {10, 2992},
-    {10, 2994}, {10, 2996}, {10, 2998}, {10, 3000}, {10, 3002}, {10, 3004},
-    {10, 3006}, {10, 3008}, {10, 3010}, {10, 3012}, {10, 3014}, {10, 3016},
-    {10, 3018}, {10, 3020}, {10, 3022}, {10, 3024}, {10, 3026}, {10, 3028},
-    {10, 3030}, {10, 3032}, {10, 3034}, {10, 3036}, {10, 3038}, {10, 3040},
-    {10, 3042}, {10, 3044}, {10, 3046}, {10, 3048}, {10, 3050}, {10, 3052},
-    {10, 3054}, {10, 3056}, {10, 3058}, {10, 3060}, {10, 3062}, {10, 3064},
-    {10, 3066}, {10, 3068}, {10, 3070}, {10, 3072}, {10, 3074}, {10, 3076},
-    {10, 3078}, {10, 3080}, {10, 3082}, {10, 3084}, {10, 3086}, {10, 3088},
-    {10, 3090}, {10, 3092}, {10, 3094}, {10, 3096}, {10, 3098}, {10, 3100},
-    {10, 3102}, {10, 3104}, {10, 3106}, {10, 3108}, {10, 3110}, {10, 3112},
-    {10, 3114}, {10, 3116}, {10, 3118}, {10, 3120}, {10, 3122}, {10, 3124},
-    {10, 3126}, {10, 3128}, {10, 3130}, {10, 3132}, {10, 3134}, {10, 3136},
-    {10, 3138}, {10, 3140}, {10, 3142}, {10, 3144}, {10, 3146}, {10, 3148},
-    {10, 3150}, {10, 3152}, {10, 3154}, {10, 3156}, {10, 3158}, {10, 3160},
-    {10, 3162}, {10, 3164}, {10, 3166}, {10, 3168}, {10, 3170}, {10, 3172},
-    {10, 3174}, {10, 3176}, {10, 3178}, {10, 3180}, {10, 3182}, {10, 3184},
-    {10, 3186}, {10, 3188}, {10, 3190}, {10, 3192}, {10, 3194}, {10, 3196},
-    {10, 3198}, {10, 3200}, {10, 3202}, {10, 3204}, {10, 3206}, {10, 3208},
-    {10, 3210}, {10, 3212}, {10, 3214}, {10, 3216}, {10, 3218}, {10, 3220},
-    {10, 3222}, {10, 3224}, {10, 3226}, {10, 3228}, {10, 3230}, {10, 3232},
-    {10, 3234}, {10, 3236}, {10, 3238}, {10, 3240}, {10, 3242}, {10, 3244},
-    {10, 3246}, {10, 3248}, {10, 3250}, {10, 3252}, {10, 3254}, {10, 3256},
-    {10, 3258}, {10, 3260}, {10, 3262}, {10, 3264}, {10, 3266}, {10, 3268},
-    {10, 3270}, {10, 3272}, {10, 3274}, {10, 3276}, {10, 3278}, {10, 3280},
-    {10, 3282}, {10, 3284}, {10, 3286}, {10, 3288}, {10, 3290}, {10, 3292},
-    {10, 3294}, {10, 3296}, {10, 3298}, {10, 3300}, {10, 3302}, {10, 3304},
-    {10, 3306}, {10, 3308}, {10, 3310}, {10, 3312}, {10, 3314}, {10, 3316},
-    {10, 3318}, {10, 3320}, {10, 3322}, {10, 3324}, {10, 3326}, {10, 3328},
-    {10, 3330}, {10, 3332}, {10, 3334}, {10, 3336}, {10, 3338}, {10, 3340},
-    {10, 3342}, {10, 3344}, {10, 3346}, {10, 3348}, {10, 3350}, {10, 3352},
-    {10, 3354}, {10, 3356}, {10, 3358}, {10, 3360}, {10, 3362}, {10, 3364},
-    {10, 3366}, {10, 3368}, {10, 3370}, {10, 3372}, {10, 3374}, {10, 3376},
-    {10, 3378}, {10, 3380}, {10, 3382}, {10, 3384}, {10, 3386}, {10, 3388},
-    {10, 3390}, {10, 3392}, {10, 3394}, {10, 3396}, {10, 3398}, {10, 3400},
-    {10, 3402}, {10, 3404}, {10, 3406}, {10, 3408}, {10, 3410}, {10, 3412},
-    {10, 3414}, {10, 3416}, {10, 3418}, {10, 3420}, {10, 3422}, {10, 3424},
-    {10, 3426}, {10, 3428}, {10, 3430}, {10, 3432}, {10, 3434}, {10, 3436},
-    {10, 3438}, {10, 3440}, {10, 3442}, {10, 3444}, {10, 3446}, {10, 3448},
-    {10, 3450}, {10, 3452}, {10, 3454}, {10, 3456}, {10, 3458}, {10, 3460},
-    {10, 3462}, {10, 3464}, {10, 3466}, {10, 3468}, {10, 3470}, {10, 3472},
-    {10, 3474}, {10, 3476}, {10, 3478}, {10, 3480}, {10, 3482}, {10, 3484},
-    {10, 3486}, {10, 3488}, {10, 3490}, {10, 3492}, {10, 3494}, {10, 3496},
-    {10, 3498}, {10, 3500}, {10, 3502}, {10, 3504}, {10, 3506}, {10, 3508},
-    {10, 3510}, {10, 3512}, {10, 3514}, {10, 3516}, {10, 3518}, {10, 3520},
-    {10, 3522}, {10, 3524}, {10, 3526}, {10, 3528}, {10, 3530}, {10, 3532},
-    {10, 3534}, {10, 3536}, {10, 3538}, {10, 3540}, {10, 3542}, {10, 3544},
-    {10, 3546}, {10, 3548}, {10, 3550}, {10, 3552}, {10, 3554}, {10, 3556},
-    {10, 3558}, {10, 3560}, {10, 3562}, {10, 3564}, {10, 3566}, {10, 3568},
-    {10, 3570}, {10, 3572}, {10, 3574}, {10, 3576}, {10, 3578}, {10, 3580},
-    {10, 3582}, {10, 3584}, {10, 3586}, {10, 3588}, {10, 3590}, {10, 3592},
-    {10, 3594}, {10, 3596}, {10, 3598}, {10, 3600}, {10, 3602}, {10, 3604},
-    {10, 3606}, {10, 3608}, {10, 3610}, {10, 3612}, {10, 3614}, {10, 3616},
-    {10, 3618}, {10, 3620}, {10, 3622}, {10, 3624}, {10, 3626}, {10, 3628},
-    {10, 3630}, {10, 3632}, {10, 3634}, {10, 3636}, {10, 3638}, {10, 3640},
-    {10, 3642}, {10, 3644}, {10, 3646}, {10, 3648}, {10, 3650}, {10, 3652},
-    {10, 3654}, {10, 3656}, {10, 3658}, {10, 3660}, {10, 3662}, {10, 3664},
-    {10, 3666}, {10, 3668}, {10, 3670}, {10, 3672}, {10, 3674}, {10, 3676},
-    {10, 3678}, {10, 3680}, {10, 3682}, {10, 3684}, {10, 3686}, {10, 3688},
-    {10, 3690}, {10, 3692}, {10, 3694}, {10, 3696}, {10, 3698}, {10, 3700},
-    {10, 3702}, {10, 3704}, {10, 3706}, {10, 3708}, {10, 3710}, {10, 3712},
-    {10, 3714}, {10, 3716}, {10, 3718}, {10, 3720}, {10, 3722}, {10, 3724},
-    {10, 3726}, {10, 3728}, {10, 3730}, {10, 3732}, {10, 3734}, {10, 3736},
-    {10, 3738}, {10, 3740}, {10, 3742}, {10, 3744}, {10, 3746}, {10, 3748},
-    {10, 3750}, {10, 3752}, {10, 3754}, {10, 3756}, {10, 3758}, {10, 3760},
-    {10, 3762}, {10, 3764}, {10, 3766}, {10, 3768}, {10, 3770}, {10, 3772},
-    {10, 3774}, {10, 3776}, {10, 3778}, {10, 3780}, {10, 3782}, {10, 3784},
-    {10, 3786}, {10, 3788}, {10, 3790}, {10, 3792}, {10, 3794}, {10, 3796},
-    {10, 3798}, {10, 3800}, {10, 3802}, {10, 3804}, {10, 3806}, {10, 3808},
-    {10, 3810}, {10, 3812}, {10, 3814}, {10, 3816}, {10, 3818}, {10, 3820},
-    {10, 3822}, {10, 3824}, {10, 3826}, {10, 3828}, {10, 3830}, {10, 3832},
-    {10, 3834}, {10, 3836}, {10, 3838}, {10, 3840}, {10, 3842}, {10, 3844},
-    {10, 3846}, {10, 3848}, {10, 3850}, {10, 3852}, {10, 3854}, {10, 3856},
-    {10, 3858}, {10, 3860}, {10, 3862}, {10, 3864}, {10, 3866}, {10, 3868},
-    {10, 3870}, {10, 3872}, {10, 3874}, {10, 3876}, {10, 3878}, {10, 3880},
-    {10, 3882}, {10, 3884}, {10, 3886}, {10, 3888}, {10, 3890}, {10, 3892},
-    {10, 3894}, {10, 3896}, {10, 3898}, {10, 3900}, {10, 3902}, {10, 3904},
-    {10, 3906}, {10, 3908}, {10, 3910}, {10, 3912}, {10, 3914}, {10, 3916},
-    {10, 3918}, {10, 3920}, {10, 3922}, {10, 3924}, {10, 3926}, {10, 3928},
-    {10, 3930}, {10, 3932}, {10, 3934}, {10, 3936}, {10, 3938}, {10, 3940},
-    {10, 3942}, {10, 3944}, {10, 3946}, {10, 3948}, {10, 3950}, {10, 3952},
-    {10, 3954}, {10, 3956}, {10, 3958}, {10, 3960}
-};
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP8_ENCODER_DCT_VALUE_TOKENS_H_
diff --git a/vp8/encoder/defaultcoefcounts.h b/vp8/encoder/defaultcoefcounts.h
deleted file mode 100644 (file)
index 1e8e804..0000000
+++ /dev/null
@@ -1,236 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#ifndef VP8_ENCODER_DEFAULTCOEFCOUNTS_H_
-#define VP8_ENCODER_DEFAULTCOEFCOUNTS_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* Generated file, included by entropy.c */
-
-static const unsigned int default_coef_counts[BLOCK_TYPES]
-                                             [COEF_BANDS]
-                                             [PREV_COEF_CONTEXTS]
-                                             [MAX_ENTROPY_TOKENS] =
-{
-
-    {
-        /* Block Type ( 0 ) */
-        {
-            /* Coeff Band ( 0 ) */
-            {   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,},
-            {   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,},
-            {   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,},
-        },
-        {
-            /* Coeff Band ( 1 ) */
-            {30190, 26544, 225,  24,   4,   0,   0,   0,   0,   0,   0, 4171593,},
-            {26846, 25157, 1241, 130,  26,   6,   1,   0,   0,   0,   0, 149987,},
-            {10484, 9538, 1006, 160,  36,  18,   0,   0,   0,   0,   0, 15104,},
-        },
-        {
-            /* Coeff Band ( 2 ) */
-            {25842, 40456, 1126,  83,  11,   2,   0,   0,   0,   0,   0,   0,},
-            {9338, 8010, 512,  73,   7,   3,   2,   0,   0,   0,   0, 43294,},
-            {1047, 751, 149,  31,  13,   6,   1,   0,   0,   0,   0, 879,},
-        },
-        {
-            /* Coeff Band ( 3 ) */
-            {26136, 9826, 252,  13,   0,   0,   0,   0,   0,   0,   0,   0,},
-            {8134, 5574, 191,  14,   2,   0,   0,   0,   0,   0,   0, 35302,},
-            { 605, 677, 116,   9,   1,   0,   0,   0,   0,   0,   0, 611,},
-        },
-        {
-            /* Coeff Band ( 4 ) */
-            {10263, 15463, 283,  17,   0,   0,   0,   0,   0,   0,   0,   0,},
-            {2773, 2191, 128,   9,   2,   2,   0,   0,   0,   0,   0, 10073,},
-            { 134, 125,  32,   4,   0,   2,   0,   0,   0,   0,   0,  50,},
-        },
-        {
-            /* Coeff Band ( 5 ) */
-            {10483, 2663,  23,   1,   0,   0,   0,   0,   0,   0,   0,   0,},
-            {2137, 1251,  27,   1,   1,   0,   0,   0,   0,   0,   0, 14362,},
-            { 116, 156,  14,   2,   1,   0,   0,   0,   0,   0,   0, 190,},
-        },
-        {
-            /* Coeff Band ( 6 ) */
-            {40977, 27614, 412,  28,   0,   0,   0,   0,   0,   0,   0,   0,},
-            {6113, 5213, 261,  22,   3,   0,   0,   0,   0,   0,   0, 26164,},
-            { 382, 312,  50,  14,   2,   0,   0,   0,   0,   0,   0, 345,},
-        },
-        {
-            /* Coeff Band ( 7 ) */
-            {   0,  26,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,},
-            {   0,  13,   0,   0,   0,   0,   0,   0,   0,   0,   0, 319,},
-            {   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   8,},
-        },
-    },
-    {
-        /* Block Type ( 1 ) */
-        {
-            /* Coeff Band ( 0 ) */
-            {3268, 19382, 1043, 250,  93,  82,  49,  26,  17,   8,  25, 82289,},
-            {8758, 32110, 5436, 1832, 827, 668, 420, 153,  24,   0,   3, 52914,},
-            {9337, 23725, 8487, 3954, 2107, 1836, 1069, 399,  59,   0,   0, 18620,},
-        },
-        {
-            /* Coeff Band ( 1 ) */
-            {12419, 8420, 452,  62,   9,   1,   0,   0,   0,   0,   0,   0,},
-            {11715, 8705, 693,  92,  15,   7,   2,   0,   0,   0,   0, 53988,},
-            {7603, 8585, 2306, 778, 270, 145,  39,   5,   0,   0,   0, 9136,},
-        },
-        {
-            /* Coeff Band ( 2 ) */
-            {15938, 14335, 1207, 184,  55,  13,   4,   1,   0,   0,   0,   0,},
-            {7415, 6829, 1138, 244,  71,  26,   7,   0,   0,   0,   0, 9980,},
-            {1580, 1824, 655, 241,  89,  46,  10,   2,   0,   0,   0, 429,},
-        },
-        {
-            /* Coeff Band ( 3 ) */
-            {19453, 5260, 201,  19,   0,   0,   0,   0,   0,   0,   0,   0,},
-            {9173, 3758, 213,  22,   1,   1,   0,   0,   0,   0,   0, 9820,},
-            {1689, 1277, 276,  51,  17,   4,   0,   0,   0,   0,   0, 679,},
-        },
-        {
-            /* Coeff Band ( 4 ) */
-            {12076, 10667, 620,  85,  19,   9,   5,   0,   0,   0,   0,   0,},
-            {4665, 3625, 423,  55,  19,   9,   0,   0,   0,   0,   0, 5127,},
-            { 415, 440, 143,  34,  20,   7,   2,   0,   0,   0,   0, 101,},
-        },
-        {
-            /* Coeff Band ( 5 ) */
-            {12183, 4846, 115,  11,   1,   0,   0,   0,   0,   0,   0,   0,},
-            {4226, 3149, 177,  21,   2,   0,   0,   0,   0,   0,   0, 7157,},
-            { 375, 621, 189,  51,  11,   4,   1,   0,   0,   0,   0, 198,},
-        },
-        {
-            /* Coeff Band ( 6 ) */
-            {61658, 37743, 1203,  94,  10,   3,   0,   0,   0,   0,   0,   0,},
-            {15514, 11563, 903, 111,  14,   5,   0,   0,   0,   0,   0, 25195,},
-            { 929, 1077, 291,  78,  14,   7,   1,   0,   0,   0,   0, 507,},
-        },
-        {
-            /* Coeff Band ( 7 ) */
-            {   0, 990,  15,   3,   0,   0,   0,   0,   0,   0,   0,   0,},
-            {   0, 412,  13,   0,   0,   0,   0,   0,   0,   0,   0, 1641,},
-            {   0,  18,   7,   1,   0,   0,   0,   0,   0,   0,   0,  30,},
-        },
-    },
-    {
-        /* Block Type ( 2 ) */
-        {
-            /* Coeff Band ( 0 ) */
-            { 953, 24519, 628, 120,  28,  12,   4,   0,   0,   0,   0, 2248798,},
-            {1525, 25654, 2647, 617, 239, 143,  42,   5,   0,   0,   0, 66837,},
-            {1180, 11011, 3001, 1237, 532, 448, 239,  54,   5,   0,   0, 7122,},
-        },
-        {
-            /* Coeff Band ( 1 ) */
-            {1356, 2220,  67,  10,   4,   1,   0,   0,   0,   0,   0,   0,},
-            {1450, 2544, 102,  18,   4,   3,   0,   0,   0,   0,   0, 57063,},
-            {1182, 2110, 470, 130,  41,  21,   0,   0,   0,   0,   0, 6047,},
-        },
-        {
-            /* Coeff Band ( 2 ) */
-            { 370, 3378, 200,  30,   5,   4,   1,   0,   0,   0,   0,   0,},
-            { 293, 1006, 131,  29,  11,   0,   0,   0,   0,   0,   0, 5404,},
-            { 114, 387,  98,  23,   4,   8,   1,   0,   0,   0,   0, 236,},
-        },
-        {
-            /* Coeff Band ( 3 ) */
-            { 579, 194,   4,   0,   0,   0,   0,   0,   0,   0,   0,   0,},
-            { 395, 213,   5,   1,   0,   0,   0,   0,   0,   0,   0, 4157,},
-            { 119, 122,   4,   0,   0,   0,   0,   0,   0,   0,   0, 300,},
-        },
-        {
-            /* Coeff Band ( 4 ) */
-            {  38, 557,  19,   0,   0,   0,   0,   0,   0,   0,   0,   0,},
-            {  21, 114,  12,   1,   0,   0,   0,   0,   0,   0,   0, 427,},
-            {   0,   5,   0,   0,   0,   0,   0,   0,   0,   0,   0,   7,},
-        },
-        {
-            /* Coeff Band ( 5 ) */
-            {  52,   7,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,},
-            {  18,   6,   0,   0,   0,   0,   0,   0,   0,   0,   0, 652,},
-            {   1,   1,   0,   0,   0,   0,   0,   0,   0,   0,   0,  30,},
-        },
-        {
-            /* Coeff Band ( 6 ) */
-            { 640, 569,  10,   0,   0,   0,   0,   0,   0,   0,   0,   0,},
-            {  25,  77,   2,   0,   0,   0,   0,   0,   0,   0,   0, 517,},
-            {   4,   7,   0,   0,   0,   0,   0,   0,   0,   0,   0,   3,},
-        },
-        {
-            /* Coeff Band ( 7 ) */
-            {   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,},
-            {   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,},
-            {   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,},
-        },
-    },
-    {
-        /* Block Type ( 3 ) */
-        {
-            /* Coeff Band ( 0 ) */
-            {2506, 20161, 2707, 767, 261, 178, 107,  30,  14,   3,   0, 100694,},
-            {8806, 36478, 8817, 3268, 1280, 850, 401, 114,  42,   0,   0, 58572,},
-            {11003, 27214, 11798, 5716, 2482, 2072, 1048, 175,  32,   0,   0, 19284,},
-        },
-        {
-            /* Coeff Band ( 1 ) */
-            {9738, 11313, 959, 205,  70,  18,  11,   1,   0,   0,   0,   0,},
-            {12628, 15085, 1507, 273,  52,  19,   9,   0,   0,   0,   0, 54280,},
-            {10701, 15846, 5561, 1926, 813, 570, 249,  36,   0,   0,   0, 6460,},
-        },
-        {
-            /* Coeff Band ( 2 ) */
-            {6781, 22539, 2784, 634, 182, 123,  20,   4,   0,   0,   0,   0,},
-            {6263, 11544, 2649, 790, 259, 168,  27,   5,   0,   0,   0, 20539,},
-            {3109, 4075, 2031, 896, 457, 386, 158,  29,   0,   0,   0, 1138,},
-        },
-        {
-            /* Coeff Band ( 3 ) */
-            {11515, 4079, 465,  73,   5,  14,   2,   0,   0,   0,   0,   0,},
-            {9361, 5834, 650,  96,  24,   8,   4,   0,   0,   0,   0, 22181,},
-            {4343, 3974, 1360, 415, 132,  96,  14,   1,   0,   0,   0, 1267,},
-        },
-        {
-            /* Coeff Band ( 4 ) */
-            {4787, 9297, 823, 168,  44,  12,   4,   0,   0,   0,   0,   0,},
-            {3619, 4472, 719, 198,  60,  31,   3,   0,   0,   0,   0, 8401,},
-            {1157, 1175, 483, 182,  88,  31,   8,   0,   0,   0,   0, 268,},
-        },
-        {
-            /* Coeff Band ( 5 ) */
-            {8299, 1226,  32,   5,   1,   0,   0,   0,   0,   0,   0,   0,},
-            {3502, 1568,  57,   4,   1,   1,   0,   0,   0,   0,   0, 9811,},
-            {1055, 1070, 166,  29,   6,   1,   0,   0,   0,   0,   0, 527,},
-        },
-        {
-            /* Coeff Band ( 6 ) */
-            {27414, 27927, 1989, 347,  69,  26,   0,   0,   0,   0,   0,   0,},
-            {5876, 10074, 1574, 341,  91,  24,   4,   0,   0,   0,   0, 21954,},
-            {1571, 2171, 778, 324, 124,  65,  16,   0,   0,   0,   0, 979,},
-        },
-        {
-            /* Coeff Band ( 7 ) */
-            {   0,  29,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,},
-            {   0,  23,   0,   0,   0,   0,   0,   0,   0,   0,   0, 459,},
-            {   0,   1,   0,   0,   0,   0,   0,   0,   0,   0,   0,  13,},
-        },
-    },
-};
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP8_ENCODER_DEFAULTCOEFCOUNTS_H_
diff --git a/vp8/encoder/denoising.c b/vp8/encoder/denoising.c
deleted file mode 100644 (file)
index 26ce120..0000000
+++ /dev/null
@@ -1,761 +0,0 @@
-/*
- *  Copyright (c) 2012 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.
- */
-
-#include <limits.h>
-
-#include "denoising.h"
-
-#include "vp8/common/reconinter.h"
-#include "vpx/vpx_integer.h"
-#include "vpx_mem/vpx_mem.h"
-#include "vp8_rtcd.h"
-
-static const unsigned int NOISE_MOTION_THRESHOLD = 25 * 25;
-/* SSE_DIFF_THRESHOLD is selected as ~95% confidence assuming
- * var(noise) ~= 100.
- */
-static const unsigned int SSE_DIFF_THRESHOLD = 16 * 16 * 20;
-static const unsigned int SSE_THRESHOLD = 16 * 16 * 40;
-static const unsigned int SSE_THRESHOLD_HIGH = 16 * 16 * 80;
-
-/*
- * The filter function was modified to reduce the computational complexity.
- * Step 1:
- * Instead of applying tap coefficients for each pixel, we calculated the
- * pixel adjustments vs. pixel diff value ahead of time.
- *     adjustment = filtered_value - current_raw
- *                = (filter_coefficient * diff + 128) >> 8
- * where
- *     filter_coefficient = (255 << 8) / (256 + ((absdiff * 330) >> 3));
- *     filter_coefficient += filter_coefficient /
- *                           (3 + motion_magnitude_adjustment);
- *     filter_coefficient is clamped to 0 ~ 255.
- *
- * Step 2:
- * The adjustment vs. diff curve becomes flat very quick when diff increases.
- * This allowed us to use only several levels to approximate the curve without
- * changing the filtering algorithm too much.
- * The adjustments were further corrected by checking the motion magnitude.
- * The levels used are:
- * diff       adjustment w/o motion correction   adjustment w/ motion correction
- * [-255, -16]           -6                                   -7
- * [-15, -8]             -4                                   -5
- * [-7, -4]              -3                                   -4
- * [-3, 3]               diff                                 diff
- * [4, 7]                 3                                    4
- * [8, 15]                4                                    5
- * [16, 255]              6                                    7
- */
-
-int vp8_denoiser_filter_c(unsigned char *mc_running_avg_y, int mc_avg_y_stride,
-                          unsigned char *running_avg_y, int avg_y_stride,
-                          unsigned char *sig, int sig_stride,
-                          unsigned int motion_magnitude,
-                          int increase_denoising)
-{
-    unsigned char *running_avg_y_start = running_avg_y;
-    unsigned char *sig_start = sig;
-    int sum_diff_thresh;
-    int r, c;
-    int sum_diff = 0;
-    int adj_val[3] = {3, 4, 6};
-    int shift_inc1 = 0;
-    int shift_inc2 = 1;
-    int col_sum[16] = {0, 0, 0, 0,
-                       0, 0, 0, 0,
-                       0, 0, 0, 0,
-                       0, 0, 0, 0};
-    /* If motion_magnitude is small, making the denoiser more aggressive by
-     * increasing the adjustment for each level. Add another increment for
-     * blocks that are labeled for increase denoising. */
-    if (motion_magnitude <= MOTION_MAGNITUDE_THRESHOLD)
-    {
-      if (increase_denoising) {
-        shift_inc1 = 1;
-        shift_inc2 = 2;
-      }
-      adj_val[0] += shift_inc2;
-      adj_val[1] += shift_inc2;
-      adj_val[2] += shift_inc2;
-    }
-
-    for (r = 0; r < 16; ++r)
-    {
-        for (c = 0; c < 16; ++c)
-        {
-            int diff = 0;
-            int adjustment = 0;
-            int absdiff = 0;
-
-            diff = mc_running_avg_y[c] - sig[c];
-            absdiff = abs(diff);
-
-            // When |diff| <= |3 + shift_inc1|, use pixel value from
-            // last denoised raw.
-            if (absdiff <= 3 + shift_inc1)
-            {
-                running_avg_y[c] = mc_running_avg_y[c];
-                col_sum[c] += diff;
-            }
-            else
-            {
-                if (absdiff >= 4 + shift_inc1 && absdiff <= 7)
-                    adjustment = adj_val[0];
-                else if (absdiff >= 8 && absdiff <= 15)
-                    adjustment = adj_val[1];
-                else
-                    adjustment = adj_val[2];
-
-                if (diff > 0)
-                {
-                    if ((sig[c] + adjustment) > 255)
-                        running_avg_y[c] = 255;
-                    else
-                        running_avg_y[c] = sig[c] + adjustment;
-
-                    col_sum[c] += adjustment;
-                }
-                else
-                {
-                    if ((sig[c] - adjustment) < 0)
-                        running_avg_y[c] = 0;
-                    else
-                        running_avg_y[c] = sig[c] - adjustment;
-
-                    col_sum[c] -= adjustment;
-                }
-            }
-        }
-
-        /* Update pointers for next iteration. */
-        sig += sig_stride;
-        mc_running_avg_y += mc_avg_y_stride;
-        running_avg_y += avg_y_stride;
-    }
-
-    for (c = 0; c < 16; ++c) {
-      // Below we clip the value in the same way which SSE code use.
-      // When adopting aggressive denoiser, the adj_val for each pixel
-      // could be at most 8 (this is current max adjustment of the map).
-      // In SSE code, we calculate the sum of adj_val for
-      // the columns, so the sum could be upto 128(16 rows). However,
-      // the range of the value is -128 ~ 127 in SSE code, that's why
-      // we do this change in C code.
-      // We don't do this for UV denoiser, since there are only 8 rows,
-      // and max adjustments <= 8, so the sum of the columns will not
-      // exceed 64.
-      if (col_sum[c] >= 128) {
-        col_sum[c] = 127;
-      }
-      sum_diff += col_sum[c];
-    }
-
-    sum_diff_thresh= SUM_DIFF_THRESHOLD;
-    if (increase_denoising) sum_diff_thresh = SUM_DIFF_THRESHOLD_HIGH;
-    if (abs(sum_diff) > sum_diff_thresh) {
-      // Before returning to copy the block (i.e., apply no denoising), check
-      // if we can still apply some (weaker) temporal filtering to this block,
-      // that would otherwise not be denoised at all. Simplest is to apply
-      // an additional adjustment to running_avg_y to bring it closer to sig.
-      // The adjustment is capped by a maximum delta, and chosen such that
-      // in most cases the resulting sum_diff will be within the
-      // accceptable range given by sum_diff_thresh.
-
-      // The delta is set by the excess of absolute pixel diff over threshold.
-      int delta = ((abs(sum_diff) - sum_diff_thresh) >> 8) + 1;
-      // Only apply the adjustment for max delta up to 3.
-      if (delta < 4) {
-        sig -= sig_stride * 16;
-        mc_running_avg_y -= mc_avg_y_stride * 16;
-        running_avg_y -= avg_y_stride * 16;
-        for (r = 0; r < 16; ++r) {
-          for (c = 0; c < 16; ++c) {
-            int diff = mc_running_avg_y[c] - sig[c];
-            int adjustment = abs(diff);
-            if (adjustment > delta)
-              adjustment = delta;
-            if (diff > 0) {
-              // Bring denoised signal down.
-              if (running_avg_y[c] - adjustment < 0)
-                running_avg_y[c] = 0;
-              else
-                running_avg_y[c] = running_avg_y[c] - adjustment;
-              col_sum[c] -= adjustment;
-            } else if (diff < 0) {
-              // Bring denoised signal up.
-              if (running_avg_y[c] + adjustment > 255)
-                running_avg_y[c] = 255;
-              else
-                running_avg_y[c] = running_avg_y[c] + adjustment;
-              col_sum[c] += adjustment;
-            }
-          }
-          // TODO(marpan): Check here if abs(sum_diff) has gone below the
-          // threshold sum_diff_thresh, and if so, we can exit the row loop.
-          sig += sig_stride;
-          mc_running_avg_y += mc_avg_y_stride;
-          running_avg_y += avg_y_stride;
-        }
-
-        sum_diff = 0;
-        for (c = 0; c < 16; ++c) {
-          if (col_sum[c] >= 128) {
-            col_sum[c] = 127;
-          }
-          sum_diff += col_sum[c];
-        }
-
-        if (abs(sum_diff) > sum_diff_thresh)
-          return COPY_BLOCK;
-      } else {
-        return COPY_BLOCK;
-      }
-    }
-
-    vp8_copy_mem16x16(running_avg_y_start, avg_y_stride, sig_start, sig_stride);
-    return FILTER_BLOCK;
-}
-
-int vp8_denoiser_filter_uv_c(unsigned char *mc_running_avg_uv,
-                             int mc_avg_uv_stride,
-                             unsigned char *running_avg_uv,
-                             int avg_uv_stride,
-                             unsigned char *sig,
-                             int sig_stride,
-                             unsigned int motion_magnitude,
-                             int increase_denoising) {
-    unsigned char *running_avg_uv_start = running_avg_uv;
-    unsigned char *sig_start = sig;
-    int sum_diff_thresh;
-    int r, c;
-    int sum_diff = 0;
-    int sum_block = 0;
-    int adj_val[3] = {3, 4, 6};
-    int shift_inc1 = 0;
-    int shift_inc2 = 1;
-    /* If motion_magnitude is small, making the denoiser more aggressive by
-     * increasing the adjustment for each level. Add another increment for
-     * blocks that are labeled for increase denoising. */
-    if (motion_magnitude <= MOTION_MAGNITUDE_THRESHOLD_UV) {
-      if (increase_denoising) {
-        shift_inc1 = 1;
-        shift_inc2 = 2;
-      }
-      adj_val[0] += shift_inc2;
-      adj_val[1] += shift_inc2;
-      adj_val[2] += shift_inc2;
-    }
-
-    // Avoid denoising color signal if its close to average level.
-    for (r = 0; r < 8; ++r) {
-      for (c = 0; c < 8; ++c) {
-        sum_block += sig[c];
-      }
-      sig += sig_stride;
-    }
-    if (abs(sum_block - (128 * 8 * 8)) < SUM_DIFF_FROM_AVG_THRESH_UV) {
-      return COPY_BLOCK;
-    }
-
-    sig -= sig_stride * 8;
-    for (r = 0; r < 8; ++r) {
-      for (c = 0; c < 8; ++c) {
-        int diff = 0;
-        int adjustment = 0;
-        int absdiff = 0;
-
-        diff = mc_running_avg_uv[c] - sig[c];
-        absdiff = abs(diff);
-
-        // When |diff| <= |3 + shift_inc1|, use pixel value from
-        // last denoised raw.
-        if (absdiff <= 3 + shift_inc1) {
-          running_avg_uv[c] = mc_running_avg_uv[c];
-          sum_diff += diff;
-        } else {
-          if (absdiff >= 4 && absdiff <= 7)
-            adjustment = adj_val[0];
-          else if (absdiff >= 8 && absdiff <= 15)
-            adjustment = adj_val[1];
-          else
-            adjustment = adj_val[2];
-          if (diff > 0) {
-            if ((sig[c] + adjustment) > 255)
-              running_avg_uv[c] = 255;
-            else
-              running_avg_uv[c] = sig[c] + adjustment;
-            sum_diff += adjustment;
-          } else {
-            if ((sig[c] - adjustment) < 0)
-              running_avg_uv[c] = 0;
-            else
-              running_avg_uv[c] = sig[c] - adjustment;
-            sum_diff -= adjustment;
-          }
-        }
-      }
-      /* Update pointers for next iteration. */
-      sig += sig_stride;
-      mc_running_avg_uv += mc_avg_uv_stride;
-      running_avg_uv += avg_uv_stride;
-    }
-
-    sum_diff_thresh= SUM_DIFF_THRESHOLD_UV;
-    if (increase_denoising) sum_diff_thresh = SUM_DIFF_THRESHOLD_HIGH_UV;
-    if (abs(sum_diff) > sum_diff_thresh) {
-      // Before returning to copy the block (i.e., apply no denoising), check
-      // if we can still apply some (weaker) temporal filtering to this block,
-      // that would otherwise not be denoised at all. Simplest is to apply
-      // an additional adjustment to running_avg_y to bring it closer to sig.
-      // The adjustment is capped by a maximum delta, and chosen such that
-      // in most cases the resulting sum_diff will be within the
-      // accceptable range given by sum_diff_thresh.
-
-      // The delta is set by the excess of absolute pixel diff over threshold.
-      int delta = ((abs(sum_diff) - sum_diff_thresh) >> 8) + 1;
-      // Only apply the adjustment for max delta up to 3.
-      if (delta < 4) {
-        sig -= sig_stride * 8;
-        mc_running_avg_uv -= mc_avg_uv_stride * 8;
-        running_avg_uv -= avg_uv_stride * 8;
-        for (r = 0; r < 8; ++r) {
-          for (c = 0; c < 8; ++c) {
-            int diff = mc_running_avg_uv[c] - sig[c];
-            int adjustment = abs(diff);
-            if (adjustment > delta)
-              adjustment = delta;
-            if (diff > 0) {
-              // Bring denoised signal down.
-              if (running_avg_uv[c] - adjustment < 0)
-                running_avg_uv[c] = 0;
-              else
-                running_avg_uv[c] = running_avg_uv[c] - adjustment;
-              sum_diff -= adjustment;
-            } else if (diff < 0) {
-              // Bring denoised signal up.
-              if (running_avg_uv[c] + adjustment > 255)
-                running_avg_uv[c] = 255;
-              else
-                running_avg_uv[c] = running_avg_uv[c] + adjustment;
-              sum_diff += adjustment;
-            }
-          }
-          // TODO(marpan): Check here if abs(sum_diff) has gone below the
-          // threshold sum_diff_thresh, and if so, we can exit the row loop.
-          sig += sig_stride;
-          mc_running_avg_uv += mc_avg_uv_stride;
-          running_avg_uv += avg_uv_stride;
-        }
-        if (abs(sum_diff) > sum_diff_thresh)
-          return COPY_BLOCK;
-      } else {
-        return COPY_BLOCK;
-      }
-    }
-
-    vp8_copy_mem8x8(running_avg_uv_start, avg_uv_stride, sig_start,
-                    sig_stride);
-    return FILTER_BLOCK;
-}
-
-void vp8_denoiser_set_parameters(VP8_DENOISER *denoiser, int mode) {
-  assert(mode > 0);  // Denoiser is allocated only if mode > 0.
-  if (mode == 1) {
-    denoiser->denoiser_mode = kDenoiserOnYOnly;
-  } else if (mode == 2) {
-    denoiser->denoiser_mode = kDenoiserOnYUV;
-  } else if (mode == 3) {
-    denoiser->denoiser_mode = kDenoiserOnYUVAggressive;
-  } else {
-    denoiser->denoiser_mode = kDenoiserOnYUV;
-  }
-  if (denoiser->denoiser_mode != kDenoiserOnYUVAggressive) {
-    denoiser->denoise_pars.scale_sse_thresh = 1;
-    denoiser->denoise_pars.scale_motion_thresh = 8;
-    denoiser->denoise_pars.scale_increase_filter = 0;
-    denoiser->denoise_pars.denoise_mv_bias = 95;
-    denoiser->denoise_pars.pickmode_mv_bias = 100;
-    denoiser->denoise_pars.qp_thresh = 0;
-    denoiser->denoise_pars.consec_zerolast = UINT_MAX;
-    denoiser->denoise_pars.spatial_blur = 0;
-  } else {
-    denoiser->denoise_pars.scale_sse_thresh = 2;
-    denoiser->denoise_pars.scale_motion_thresh = 16;
-    denoiser->denoise_pars.scale_increase_filter = 1;
-    denoiser->denoise_pars.denoise_mv_bias = 60;
-    denoiser->denoise_pars.pickmode_mv_bias = 75;
-    denoiser->denoise_pars.qp_thresh = 80;
-    denoiser->denoise_pars.consec_zerolast = 15;
-    denoiser->denoise_pars.spatial_blur = 0;
-  }
-}
-
-int vp8_denoiser_allocate(VP8_DENOISER *denoiser, int width, int height,
-                          int num_mb_rows, int num_mb_cols, int mode)
-{
-    int i;
-    assert(denoiser);
-    denoiser->num_mb_cols = num_mb_cols;
-
-    for (i = 0; i < MAX_REF_FRAMES; i++)
-    {
-        denoiser->yv12_running_avg[i].flags = 0;
-
-        if (vp8_yv12_alloc_frame_buffer(&(denoiser->yv12_running_avg[i]), width,
-                                        height, VP8BORDERINPIXELS)
-            < 0)
-        {
-            vp8_denoiser_free(denoiser);
-            return 1;
-        }
-        memset(denoiser->yv12_running_avg[i].buffer_alloc, 0,
-               denoiser->yv12_running_avg[i].frame_size);
-
-    }
-    denoiser->yv12_mc_running_avg.flags = 0;
-
-    if (vp8_yv12_alloc_frame_buffer(&(denoiser->yv12_mc_running_avg), width,
-                                   height, VP8BORDERINPIXELS) < 0)
-    {
-        vp8_denoiser_free(denoiser);
-        return 1;
-    }
-
-    memset(denoiser->yv12_mc_running_avg.buffer_alloc, 0,
-           denoiser->yv12_mc_running_avg.frame_size);
-
-    if (vp8_yv12_alloc_frame_buffer(&denoiser->yv12_last_source, width,
-                                    height, VP8BORDERINPIXELS) < 0) {
-      vp8_denoiser_free(denoiser);
-      return 1;
-    }
-    memset(denoiser->yv12_last_source.buffer_alloc, 0,
-           denoiser->yv12_last_source.frame_size);
-
-    denoiser->denoise_state = vpx_calloc((num_mb_rows * num_mb_cols), 1);
-    if (!denoiser->denoise_state)
-    {
-        vp8_denoiser_free(denoiser);
-        return 1;
-    }
-    memset(denoiser->denoise_state, 0, (num_mb_rows * num_mb_cols));
-    vp8_denoiser_set_parameters(denoiser, mode);
-    denoiser->nmse_source_diff = 0;
-    denoiser->nmse_source_diff_count = 0;
-    denoiser->qp_avg = 0;
-    // QP threshold below which we can go up to aggressive mode.
-    denoiser->qp_threshold_up = 80;
-    // QP threshold above which we can go back down to normal mode.
-    // For now keep this second threshold high, so not used currently.
-    denoiser->qp_threshold_down = 128;
-    // Bitrate thresholds and noise metric (nmse) thresholds for switching to
-    // aggressive mode.
-    // TODO(marpan): Adjust thresholds, including effect on resolution.
-    denoiser->bitrate_threshold = 400000;  // (bits/sec).
-    denoiser->threshold_aggressive_mode = 80;
-    if (width * height > 1280 * 720) {
-      denoiser->bitrate_threshold = 3000000;
-      denoiser->threshold_aggressive_mode = 200;
-    } else if (width * height > 960 * 540) {
-      denoiser->bitrate_threshold = 1200000;
-      denoiser->threshold_aggressive_mode = 120;
-    } else if (width * height > 640 * 480) {
-      denoiser->bitrate_threshold = 600000;
-      denoiser->threshold_aggressive_mode = 100;
-    }
-    return 0;
-}
-
-
-void vp8_denoiser_free(VP8_DENOISER *denoiser)
-{
-    int i;
-    assert(denoiser);
-
-    for (i = 0; i < MAX_REF_FRAMES ; i++)
-    {
-        vp8_yv12_de_alloc_frame_buffer(&denoiser->yv12_running_avg[i]);
-    }
-    vp8_yv12_de_alloc_frame_buffer(&denoiser->yv12_mc_running_avg);
-    vp8_yv12_de_alloc_frame_buffer(&denoiser->yv12_last_source);
-    vpx_free(denoiser->denoise_state);
-}
-
-void vp8_denoiser_denoise_mb(VP8_DENOISER *denoiser,
-                             MACROBLOCK *x,
-                             unsigned int best_sse,
-                             unsigned int zero_mv_sse,
-                             int recon_yoffset,
-                             int recon_uvoffset,
-                             loop_filter_info_n *lfi_n,
-                             int mb_row,
-                             int mb_col,
-                             int block_index,
-                             int consec_zero_last)
-
-{
-    int mv_row;
-    int mv_col;
-    unsigned int motion_threshold;
-    unsigned int motion_magnitude2;
-    unsigned int sse_thresh;
-    int sse_diff_thresh = 0;
-    // Spatial loop filter: only applied selectively based on
-    // temporal filter state of block relative to top/left neighbors.
-    int apply_spatial_loop_filter = 1;
-    MV_REFERENCE_FRAME frame = x->best_reference_frame;
-    MV_REFERENCE_FRAME zero_frame = x->best_zeromv_reference_frame;
-
-    enum vp8_denoiser_decision decision = FILTER_BLOCK;
-    enum vp8_denoiser_decision decision_u = COPY_BLOCK;
-    enum vp8_denoiser_decision decision_v = COPY_BLOCK;
-
-    if (zero_frame)
-    {
-        YV12_BUFFER_CONFIG *src = &denoiser->yv12_running_avg[frame];
-        YV12_BUFFER_CONFIG *dst = &denoiser->yv12_mc_running_avg;
-        YV12_BUFFER_CONFIG saved_pre,saved_dst;
-        MB_MODE_INFO saved_mbmi;
-        MACROBLOCKD *filter_xd = &x->e_mbd;
-        MB_MODE_INFO *mbmi = &filter_xd->mode_info_context->mbmi;
-        int sse_diff = 0;
-        // Bias on zero motion vector sse.
-        const int zero_bias = denoiser->denoise_pars.denoise_mv_bias;
-        zero_mv_sse = (unsigned int)((int64_t)zero_mv_sse * zero_bias / 100);
-        sse_diff = (int)zero_mv_sse - (int)best_sse;
-
-        saved_mbmi = *mbmi;
-
-        /* Use the best MV for the compensation. */
-        mbmi->ref_frame = x->best_reference_frame;
-        mbmi->mode = x->best_sse_inter_mode;
-        mbmi->mv = x->best_sse_mv;
-        mbmi->need_to_clamp_mvs = x->need_to_clamp_best_mvs;
-        mv_col = x->best_sse_mv.as_mv.col;
-        mv_row = x->best_sse_mv.as_mv.row;
-        // Bias to zero_mv if small amount of motion.
-        // Note sse_diff_thresh is intialized to zero, so this ensures
-        // we will always choose zero_mv for denoising if
-        // zero_mv_see <= best_sse (i.e., sse_diff <= 0).
-        if ((unsigned int)(mv_row * mv_row + mv_col * mv_col)
-            <= NOISE_MOTION_THRESHOLD)
-            sse_diff_thresh = (int)SSE_DIFF_THRESHOLD;
-
-        if (frame == INTRA_FRAME ||
-            sse_diff <= sse_diff_thresh)
-        {
-            /*
-             * Handle intra blocks as referring to last frame with zero motion
-             * and let the absolute pixel difference affect the filter factor.
-             * Also consider small amount of motion as being random walk due
-             * to noise, if it doesn't mean that we get a much bigger error.
-             * Note that any changes to the mode info only affects the
-             * denoising.
-             */
-            x->denoise_zeromv = 1;
-            mbmi->ref_frame =
-                    x->best_zeromv_reference_frame;
-
-            src = &denoiser->yv12_running_avg[zero_frame];
-
-            mbmi->mode = ZEROMV;
-            mbmi->mv.as_int = 0;
-            x->best_sse_inter_mode = ZEROMV;
-            x->best_sse_mv.as_int = 0;
-            best_sse = zero_mv_sse;
-        }
-
-        mv_row = x->best_sse_mv.as_mv.row;
-        mv_col = x->best_sse_mv.as_mv.col;
-        motion_magnitude2 = mv_row * mv_row + mv_col * mv_col;
-        motion_threshold = denoiser->denoise_pars.scale_motion_thresh *
-            NOISE_MOTION_THRESHOLD;
-
-        if (motion_magnitude2 <
-          denoiser->denoise_pars.scale_increase_filter * NOISE_MOTION_THRESHOLD)
-          x->increase_denoising = 1;
-
-        sse_thresh = denoiser->denoise_pars.scale_sse_thresh * SSE_THRESHOLD;
-        if (x->increase_denoising)
-          sse_thresh =
-              denoiser->denoise_pars.scale_sse_thresh * SSE_THRESHOLD_HIGH;
-
-        if (best_sse > sse_thresh || motion_magnitude2 > motion_threshold)
-          decision = COPY_BLOCK;
-
-        // If block is considered skin, don't denoise if the block
-        // (1) is selected as non-zero motion for current frame, or
-        // (2) has not been selected as ZERO_LAST mode at least x past frames
-        // in a row.
-        // TODO(marpan): Parameter "x" should be varied with framerate.
-        // In particualar, should be reduced for layers (base layer/LAST).
-        if (x->is_skin && (consec_zero_last < 2 || motion_magnitude2 > 0))
-          decision = COPY_BLOCK;
-
-        if (decision == FILTER_BLOCK) {
-          saved_pre = filter_xd->pre;
-          saved_dst = filter_xd->dst;
-
-          /* Compensate the running average. */
-          filter_xd->pre.y_buffer = src->y_buffer + recon_yoffset;
-          filter_xd->pre.u_buffer = src->u_buffer + recon_uvoffset;
-          filter_xd->pre.v_buffer = src->v_buffer + recon_uvoffset;
-          /* Write the compensated running average to the destination buffer. */
-          filter_xd->dst.y_buffer = dst->y_buffer + recon_yoffset;
-          filter_xd->dst.u_buffer = dst->u_buffer + recon_uvoffset;
-          filter_xd->dst.v_buffer = dst->v_buffer + recon_uvoffset;
-
-          if (!x->skip)
-          {
-              vp8_build_inter_predictors_mb(filter_xd);
-          }
-          else
-          {
-              vp8_build_inter16x16_predictors_mb(filter_xd,
-                                                 filter_xd->dst.y_buffer,
-                                                 filter_xd->dst.u_buffer,
-                                                 filter_xd->dst.v_buffer,
-                                                 filter_xd->dst.y_stride,
-                                                 filter_xd->dst.uv_stride);
-          }
-          filter_xd->pre = saved_pre;
-          filter_xd->dst = saved_dst;
-          *mbmi = saved_mbmi;
-        }
-    } else {
-      // zero_frame should always be 1 for real-time mode, as the
-      // ZEROMV mode is always checked, so we should never go into this branch.
-      // If case ZEROMV is not checked, then we will force no denoise (COPY).
-      decision = COPY_BLOCK;
-    }
-
-    if (decision == FILTER_BLOCK)
-    {
-        unsigned char *mc_running_avg_y =
-            denoiser->yv12_mc_running_avg.y_buffer + recon_yoffset;
-        int mc_avg_y_stride = denoiser->yv12_mc_running_avg.y_stride;
-        unsigned char *running_avg_y =
-            denoiser->yv12_running_avg[INTRA_FRAME].y_buffer + recon_yoffset;
-        int avg_y_stride = denoiser->yv12_running_avg[INTRA_FRAME].y_stride;
-
-        /* Filter. */
-        decision = vp8_denoiser_filter(mc_running_avg_y, mc_avg_y_stride,
-                                       running_avg_y, avg_y_stride,
-                                       x->thismb, 16, motion_magnitude2,
-                                       x->increase_denoising);
-        denoiser->denoise_state[block_index] = motion_magnitude2 > 0 ?
-            kFilterNonZeroMV : kFilterZeroMV;
-        // Only denoise UV for zero motion, and if y channel was denoised.
-        if (denoiser->denoiser_mode != kDenoiserOnYOnly &&
-            motion_magnitude2 == 0 &&
-            decision == FILTER_BLOCK) {
-          unsigned char *mc_running_avg_u =
-              denoiser->yv12_mc_running_avg.u_buffer + recon_uvoffset;
-          unsigned char *running_avg_u =
-              denoiser->yv12_running_avg[INTRA_FRAME].u_buffer + recon_uvoffset;
-          unsigned char *mc_running_avg_v =
-              denoiser->yv12_mc_running_avg.v_buffer + recon_uvoffset;
-          unsigned char *running_avg_v =
-              denoiser->yv12_running_avg[INTRA_FRAME].v_buffer + recon_uvoffset;
-          int mc_avg_uv_stride = denoiser->yv12_mc_running_avg.uv_stride;
-          int avg_uv_stride = denoiser->yv12_running_avg[INTRA_FRAME].uv_stride;
-          int signal_stride = x->block[16].src_stride;
-          decision_u =
-              vp8_denoiser_filter_uv(mc_running_avg_u, mc_avg_uv_stride,
-                                      running_avg_u, avg_uv_stride,
-                                      x->block[16].src + *x->block[16].base_src,
-                                      signal_stride, motion_magnitude2, 0);
-          decision_v =
-              vp8_denoiser_filter_uv(mc_running_avg_v, mc_avg_uv_stride,
-                                      running_avg_v, avg_uv_stride,
-                                      x->block[20].src + *x->block[20].base_src,
-                                      signal_stride, motion_magnitude2, 0);
-        }
-    }
-    if (decision == COPY_BLOCK)
-    {
-        /* No filtering of this block; it differs too much from the predictor,
-         * or the motion vector magnitude is considered too big.
-         */
-        x->denoise_zeromv = 0;
-        vp8_copy_mem16x16(
-                x->thismb, 16,
-                denoiser->yv12_running_avg[INTRA_FRAME].y_buffer + recon_yoffset,
-                denoiser->yv12_running_avg[INTRA_FRAME].y_stride);
-        denoiser->denoise_state[block_index] = kNoFilter;
-    }
-    if (denoiser->denoiser_mode != kDenoiserOnYOnly) {
-      if (decision_u == COPY_BLOCK) {
-        vp8_copy_mem8x8(
-            x->block[16].src + *x->block[16].base_src, x->block[16].src_stride,
-            denoiser->yv12_running_avg[INTRA_FRAME].u_buffer + recon_uvoffset,
-            denoiser->yv12_running_avg[INTRA_FRAME].uv_stride);
-      }
-      if (decision_v == COPY_BLOCK) {
-        vp8_copy_mem8x8(
-            x->block[20].src + *x->block[20].base_src, x->block[16].src_stride,
-            denoiser->yv12_running_avg[INTRA_FRAME].v_buffer + recon_uvoffset,
-            denoiser->yv12_running_avg[INTRA_FRAME].uv_stride);
-      }
-    }
-    // Option to selectively deblock the denoised signal, for y channel only.
-    if (apply_spatial_loop_filter) {
-      loop_filter_info lfi;
-      int apply_filter_col = 0;
-      int apply_filter_row = 0;
-      int apply_filter = 0;
-      int y_stride = denoiser->yv12_running_avg[INTRA_FRAME].y_stride;
-      int uv_stride =denoiser->yv12_running_avg[INTRA_FRAME].uv_stride;
-
-      // Fix filter level to some nominal value for now.
-      int filter_level = 48;
-
-      int hev_index = lfi_n->hev_thr_lut[INTER_FRAME][filter_level];
-      lfi.mblim = lfi_n->mblim[filter_level];
-      lfi.blim = lfi_n->blim[filter_level];
-      lfi.lim = lfi_n->lim[filter_level];
-      lfi.hev_thr = lfi_n->hev_thr[hev_index];
-
-      // Apply filter if there is a difference in the denoiser filter state
-      // between the current and left/top block, or if non-zero motion vector
-      // is used for the motion-compensated filtering.
-      if (mb_col > 0) {
-        apply_filter_col = !((denoiser->denoise_state[block_index] ==
-            denoiser->denoise_state[block_index - 1]) &&
-            denoiser->denoise_state[block_index] != kFilterNonZeroMV);
-        if (apply_filter_col) {
-          // Filter left vertical edge.
-          apply_filter = 1;
-          vp8_loop_filter_mbv(
-              denoiser->yv12_running_avg[INTRA_FRAME].y_buffer + recon_yoffset,
-              NULL, NULL, y_stride, uv_stride, &lfi);
-        }
-      }
-      if (mb_row > 0) {
-        apply_filter_row = !((denoiser->denoise_state[block_index] ==
-            denoiser->denoise_state[block_index - denoiser->num_mb_cols]) &&
-            denoiser->denoise_state[block_index] != kFilterNonZeroMV);
-        if (apply_filter_row) {
-          // Filter top horizontal edge.
-          apply_filter = 1;
-          vp8_loop_filter_mbh(
-              denoiser->yv12_running_avg[INTRA_FRAME].y_buffer + recon_yoffset,
-              NULL, NULL, y_stride, uv_stride, &lfi);
-        }
-      }
-      if (apply_filter) {
-        // Update the signal block |x|. Pixel changes are only to top and/or
-        // left boundary pixels: can we avoid full block copy here.
-        vp8_copy_mem16x16(
-            denoiser->yv12_running_avg[INTRA_FRAME].y_buffer + recon_yoffset,
-            y_stride, x->thismb, 16);
-      }
-    }
-}
diff --git a/vp8/encoder/denoising.h b/vp8/encoder/denoising.h
deleted file mode 100644 (file)
index 8c126c1..0000000
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- *  Copyright (c) 2012 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.
- */
-
-#ifndef VP8_ENCODER_DENOISING_H_
-#define VP8_ENCODER_DENOISING_H_
-
-#include "block.h"
-#include "vp8/common/loopfilter.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define SUM_DIFF_THRESHOLD 512
-#define SUM_DIFF_THRESHOLD_HIGH 600
-#define MOTION_MAGNITUDE_THRESHOLD (8*3)
-
-#define SUM_DIFF_THRESHOLD_UV (96)   // (8 * 8 * 1.5)
-#define SUM_DIFF_THRESHOLD_HIGH_UV (8 * 8 * 2)
-#define SUM_DIFF_FROM_AVG_THRESH_UV (8 * 8 * 8)
-#define MOTION_MAGNITUDE_THRESHOLD_UV (8*3)
-
-#define MAX_GF_ARF_DENOISE_RANGE (8)
-
-enum vp8_denoiser_decision
-{
-  COPY_BLOCK,
-  FILTER_BLOCK
-};
-
-enum vp8_denoiser_filter_state {
-  kNoFilter,
-  kFilterZeroMV,
-  kFilterNonZeroMV
-};
-
-enum vp8_denoiser_mode {
-  kDenoiserOff,
-  kDenoiserOnYOnly,
-  kDenoiserOnYUV,
-  kDenoiserOnYUVAggressive,
-  kDenoiserOnAdaptive
-};
-
-typedef struct {
-  // Scale factor on sse threshold above which no denoising is done.
-  unsigned int scale_sse_thresh;
-  // Scale factor on motion magnitude threshold above which no
-  // denoising is done.
-  unsigned int scale_motion_thresh;
-  // Scale factor on motion magnitude below which we increase the strength of
-  // the temporal filter (in function vp8_denoiser_filter).
-  unsigned int scale_increase_filter;
-  // Scale factor to bias to ZEROMV for denoising.
-  unsigned int denoise_mv_bias;
-  // Scale factor to bias to ZEROMV for coding mode selection.
-  unsigned int pickmode_mv_bias;
-  // Quantizer threshold below which we use the segmentation map to switch off
-  // loop filter for blocks that have been coded as ZEROMV-LAST a certain number
-  // (consec_zerolast) of consecutive frames. Note that the delta-QP is set to
-  // 0 when segmentation map is used for shutting off loop filter.
-  unsigned int qp_thresh;
-  // Threshold for number of consecutive frames for blocks coded as ZEROMV-LAST.
-  unsigned int consec_zerolast;
-  // Threshold for amount of spatial blur on Y channel. 0 means no spatial blur.
-  unsigned int spatial_blur;
-} denoise_params;
-
-typedef struct vp8_denoiser
-{
-    YV12_BUFFER_CONFIG yv12_running_avg[MAX_REF_FRAMES];
-    YV12_BUFFER_CONFIG yv12_mc_running_avg;
-    // TODO(marpan): Should remove yv12_last_source and use vp8_lookahead_peak.
-    YV12_BUFFER_CONFIG yv12_last_source;
-    unsigned char* denoise_state;
-    int num_mb_cols;
-    int denoiser_mode;
-    int threshold_aggressive_mode;
-    int nmse_source_diff;
-    int nmse_source_diff_count;
-    int qp_avg;
-    int qp_threshold_up;
-    int qp_threshold_down;
-    int bitrate_threshold;
-    denoise_params denoise_pars;
-} VP8_DENOISER;
-
-int vp8_denoiser_allocate(VP8_DENOISER *denoiser, int width, int height,
-                          int num_mb_rows, int num_mb_cols, int mode);
-
-void vp8_denoiser_free(VP8_DENOISER *denoiser);
-
-void vp8_denoiser_set_parameters(VP8_DENOISER *denoiser, int mode);
-
-void vp8_denoiser_denoise_mb(VP8_DENOISER *denoiser,
-                             MACROBLOCK *x,
-                             unsigned int best_sse,
-                             unsigned int zero_mv_sse,
-                             int recon_yoffset,
-                             int recon_uvoffset,
-                             loop_filter_info_n *lfi_n,
-                             int mb_row,
-                             int mb_col,
-                             int block_index,
-                             int consec_zero_last);
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP8_ENCODER_DENOISING_H_
diff --git a/vp8/encoder/encodeframe.c b/vp8/encoder/encodeframe.c
deleted file mode 100644 (file)
index 9b05cd1..0000000
+++ /dev/null
@@ -1,1424 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#include "vpx_config.h"
-#include "vp8_rtcd.h"
-#include "./vpx_dsp_rtcd.h"
-#include "encodemb.h"
-#include "encodemv.h"
-#include "vp8/common/common.h"
-#include "onyx_int.h"
-#include "vp8/common/extend.h"
-#include "vp8/common/entropymode.h"
-#include "vp8/common/quant_common.h"
-#include "segmentation.h"
-#include "vp8/common/setupintrarecon.h"
-#include "encodeintra.h"
-#include "vp8/common/reconinter.h"
-#include "rdopt.h"
-#include "pickinter.h"
-#include "vp8/common/findnearmv.h"
-#include <stdio.h>
-#include <limits.h>
-#include "vp8/common/invtrans.h"
-#include "vpx_ports/vpx_timer.h"
-#if CONFIG_REALTIME_ONLY & CONFIG_ONTHEFLY_BITPACKING
-#include "bitstream.h"
-#endif
-#include "encodeframe.h"
-
-extern void vp8_stuff_mb(VP8_COMP *cpi, MACROBLOCK *x, TOKENEXTRA **t) ;
-extern void vp8_calc_ref_frame_costs(int *ref_frame_cost,
-                                     int prob_intra,
-                                     int prob_last,
-                                     int prob_garf
-                                    );
-extern void vp8_convert_rfct_to_prob(VP8_COMP *const cpi);
-extern void vp8cx_initialize_me_consts(VP8_COMP *cpi, int QIndex);
-extern void vp8_auto_select_speed(VP8_COMP *cpi);
-extern void vp8cx_init_mbrthread_data(VP8_COMP *cpi,
-                                      MACROBLOCK *x,
-                                      MB_ROW_COMP *mbr_ei,
-                                      int count);
-static void adjust_act_zbin( VP8_COMP *cpi, MACROBLOCK *x );
-
-#ifdef MODE_STATS
-unsigned int inter_y_modes[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
-unsigned int inter_uv_modes[4] = {0, 0, 0, 0};
-unsigned int inter_b_modes[15]  = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
-unsigned int y_modes[5]   = {0, 0, 0, 0, 0};
-unsigned int uv_modes[4]  = {0, 0, 0, 0};
-unsigned int b_modes[14]  = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
-#endif
-
-
-/* activity_avg must be positive, or flat regions could get a zero weight
- *  (infinite lambda), which confounds analysis.
- * This also avoids the need for divide by zero checks in
- *  vp8_activity_masking().
- */
-#define VP8_ACTIVITY_AVG_MIN (64)
-
-/* This is used as a reference when computing the source variance for the
- *  purposes of activity masking.
- * Eventually this should be replaced by custom no-reference routines,
- *  which will be faster.
- */
-static const unsigned char VP8_VAR_OFFS[16]=
-{
-    128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128
-};
-
-
-/* Original activity measure from Tim T's code. */
-static unsigned int tt_activity_measure( VP8_COMP *cpi, MACROBLOCK *x )
-{
-    unsigned int act;
-    unsigned int sse;
-    (void)cpi;
-    /* TODO: This could also be done over smaller areas (8x8), but that would
-     *  require extensive changes elsewhere, as lambda is assumed to be fixed
-     *  over an entire MB in most of the code.
-     * Another option is to compute four 8x8 variances, and pick a single
-     *  lambda using a non-linear combination (e.g., the smallest, or second
-     *  smallest, etc.).
-     */
-    act =  vpx_variance16x16(x->src.y_buffer,
-                    x->src.y_stride, VP8_VAR_OFFS, 0, &sse);
-    act = act<<4;
-
-    /* If the region is flat, lower the activity some more. */
-    if (act < 8<<12)
-        act = act < 5<<12 ? act : 5<<12;
-
-    return act;
-}
-
-/* Stub for alternative experimental activity measures. */
-static unsigned int alt_activity_measure( VP8_COMP *cpi,
-                                          MACROBLOCK *x, int use_dc_pred )
-{
-    return vp8_encode_intra(cpi,x, use_dc_pred);
-}
-
-
-/* Measure the activity of the current macroblock
- * What we measure here is TBD so abstracted to this function
- */
-#define ALT_ACT_MEASURE 1
-static unsigned int mb_activity_measure( VP8_COMP *cpi, MACROBLOCK *x,
-                                  int mb_row, int mb_col)
-{
-    unsigned int mb_activity;
-
-    if  ( ALT_ACT_MEASURE )
-    {
-        int use_dc_pred = (mb_col || mb_row) && (!mb_col || !mb_row);
-
-        /* Or use and alternative. */
-        mb_activity = alt_activity_measure( cpi, x, use_dc_pred );
-    }
-    else
-    {
-        /* Original activity measure from Tim T's code. */
-        mb_activity = tt_activity_measure( cpi, x );
-    }
-
-    if ( mb_activity < VP8_ACTIVITY_AVG_MIN )
-        mb_activity = VP8_ACTIVITY_AVG_MIN;
-
-    return mb_activity;
-}
-
-/* Calculate an "average" mb activity value for the frame */
-#define ACT_MEDIAN 0
-static void calc_av_activity( VP8_COMP *cpi, int64_t activity_sum )
-{
-#if ACT_MEDIAN
-    /* Find median: Simple n^2 algorithm for experimentation */
-    {
-        unsigned int median;
-        unsigned int i,j;
-        unsigned int * sortlist;
-        unsigned int tmp;
-
-        /* Create a list to sort to */
-        CHECK_MEM_ERROR(sortlist,
-                        vpx_calloc(sizeof(unsigned int),
-                        cpi->common.MBs));
-
-        /* Copy map to sort list */
-        memcpy( sortlist, cpi->mb_activity_map,
-                sizeof(unsigned int) * cpi->common.MBs );
-
-
-        /* Ripple each value down to its correct position */
-        for ( i = 1; i < cpi->common.MBs; i ++ )
-        {
-            for ( j = i; j > 0; j -- )
-            {
-                if ( sortlist[j] < sortlist[j-1] )
-                {
-                    /* Swap values */
-                    tmp = sortlist[j-1];
-                    sortlist[j-1] = sortlist[j];
-                    sortlist[j] = tmp;
-                }
-                else
-                    break;
-            }
-        }
-
-        /* Even number MBs so estimate median as mean of two either side. */
-        median = ( 1 + sortlist[cpi->common.MBs >> 1] +
-                   sortlist[(cpi->common.MBs >> 1) + 1] ) >> 1;
-
-        cpi->activity_avg = median;
-
-        vpx_free(sortlist);
-    }
-#else
-    /* Simple mean for now */
-    cpi->activity_avg = (unsigned int)(activity_sum/cpi->common.MBs);
-#endif
-
-    if (cpi->activity_avg < VP8_ACTIVITY_AVG_MIN)
-        cpi->activity_avg = VP8_ACTIVITY_AVG_MIN;
-
-    /* Experimental code: return fixed value normalized for several clips */
-    if  ( ALT_ACT_MEASURE )
-        cpi->activity_avg = 100000;
-}
-
-#define USE_ACT_INDEX   0
-#define OUTPUT_NORM_ACT_STATS   0
-
-#if USE_ACT_INDEX
-/* Calculate and activity index for each mb */
-static void calc_activity_index( VP8_COMP *cpi, MACROBLOCK *x )
-{
-    VP8_COMMON *const cm = & cpi->common;
-    int mb_row, mb_col;
-
-    int64_t act;
-    int64_t a;
-    int64_t b;
-
-#if OUTPUT_NORM_ACT_STATS
-    FILE *f = fopen("norm_act.stt", "a");
-    fprintf(f, "\n%12d\n", cpi->activity_avg );
-#endif
-
-    /* Reset pointers to start of activity map */
-    x->mb_activity_ptr = cpi->mb_activity_map;
-
-    /* Calculate normalized mb activity number. */
-    for (mb_row = 0; mb_row < cm->mb_rows; mb_row++)
-    {
-        /* for each macroblock col in image */
-        for (mb_col = 0; mb_col < cm->mb_cols; mb_col++)
-        {
-            /* Read activity from the map */
-            act = *(x->mb_activity_ptr);
-
-            /* Calculate a normalized activity number */
-            a = act + 4*cpi->activity_avg;
-            b = 4*act + cpi->activity_avg;
-
-            if ( b >= a )
-                *(x->activity_ptr) = (int)((b + (a>>1))/a) - 1;
-            else
-                *(x->activity_ptr) = 1 - (int)((a + (b>>1))/b);
-
-#if OUTPUT_NORM_ACT_STATS
-            fprintf(f, " %6d", *(x->mb_activity_ptr));
-#endif
-            /* Increment activity map pointers */
-            x->mb_activity_ptr++;
-        }
-
-#if OUTPUT_NORM_ACT_STATS
-        fprintf(f, "\n");
-#endif
-
-    }
-
-#if OUTPUT_NORM_ACT_STATS
-    fclose(f);
-#endif
-
-}
-#endif
-
-/* Loop through all MBs. Note activity of each, average activity and
- * calculate a normalized activity for each
- */
-static void build_activity_map( VP8_COMP *cpi )
-{
-    MACROBLOCK *const x = & cpi->mb;
-    MACROBLOCKD *xd = &x->e_mbd;
-    VP8_COMMON *const cm = & cpi->common;
-
-#if ALT_ACT_MEASURE
-    YV12_BUFFER_CONFIG *new_yv12 = &cm->yv12_fb[cm->new_fb_idx];
-    int recon_yoffset;
-    int recon_y_stride = new_yv12->y_stride;
-#endif
-
-    int mb_row, mb_col;
-    unsigned int mb_activity;
-    int64_t activity_sum = 0;
-
-    /* for each macroblock row in image */
-    for (mb_row = 0; mb_row < cm->mb_rows; mb_row++)
-    {
-#if ALT_ACT_MEASURE
-        /* reset above block coeffs */
-        xd->up_available = (mb_row != 0);
-        recon_yoffset = (mb_row * recon_y_stride * 16);
-#endif
-        /* for each macroblock col in image */
-        for (mb_col = 0; mb_col < cm->mb_cols; mb_col++)
-        {
-#if ALT_ACT_MEASURE
-            xd->dst.y_buffer = new_yv12->y_buffer + recon_yoffset;
-            xd->left_available = (mb_col != 0);
-            recon_yoffset += 16;
-#endif
-            /* Copy current mb to a buffer */
-            vp8_copy_mem16x16(x->src.y_buffer, x->src.y_stride, x->thismb, 16);
-
-            /* measure activity */
-            mb_activity = mb_activity_measure( cpi, x, mb_row, mb_col );
-
-            /* Keep frame sum */
-            activity_sum += mb_activity;
-
-            /* Store MB level activity details. */
-            *x->mb_activity_ptr = mb_activity;
-
-            /* Increment activity map pointer */
-            x->mb_activity_ptr++;
-
-            /* adjust to the next column of source macroblocks */
-            x->src.y_buffer += 16;
-        }
-
-
-        /* adjust to the next row of mbs */
-        x->src.y_buffer += 16 * x->src.y_stride - 16 * cm->mb_cols;
-
-#if ALT_ACT_MEASURE
-        /* extend the recon for intra prediction */
-        vp8_extend_mb_row(new_yv12, xd->dst.y_buffer + 16,
-                          xd->dst.u_buffer + 8, xd->dst.v_buffer + 8);
-#endif
-
-    }
-
-    /* Calculate an "average" MB activity */
-    calc_av_activity(cpi, activity_sum);
-
-#if USE_ACT_INDEX
-    /* Calculate an activity index number of each mb */
-    calc_activity_index( cpi, x );
-#endif
-
-}
-
-/* Macroblock activity masking */
-void vp8_activity_masking(VP8_COMP *cpi, MACROBLOCK *x)
-{
-#if USE_ACT_INDEX
-    x->rdmult += *(x->mb_activity_ptr) * (x->rdmult >> 2);
-    x->errorperbit = x->rdmult * 100 /(110 * x->rddiv);
-    x->errorperbit += (x->errorperbit==0);
-#else
-    int64_t a;
-    int64_t b;
-    int64_t act = *(x->mb_activity_ptr);
-
-    /* Apply the masking to the RD multiplier. */
-    a = act + (2*cpi->activity_avg);
-    b = (2*act) + cpi->activity_avg;
-
-    x->rdmult = (unsigned int)(((int64_t)x->rdmult*b + (a>>1))/a);
-    x->errorperbit = x->rdmult * 100 /(110 * x->rddiv);
-    x->errorperbit += (x->errorperbit==0);
-#endif
-
-    /* Activity based Zbin adjustment */
-    adjust_act_zbin(cpi, x);
-}
-
-static
-void encode_mb_row(VP8_COMP *cpi,
-                   VP8_COMMON *cm,
-                   int mb_row,
-                   MACROBLOCK  *x,
-                   MACROBLOCKD *xd,
-                   TOKENEXTRA **tp,
-                   int *segment_counts,
-                   int *totalrate)
-{
-    int recon_yoffset, recon_uvoffset;
-    int mb_col;
-    int ref_fb_idx = cm->lst_fb_idx;
-    int dst_fb_idx = cm->new_fb_idx;
-    int recon_y_stride = cm->yv12_fb[ref_fb_idx].y_stride;
-    int recon_uv_stride = cm->yv12_fb[ref_fb_idx].uv_stride;
-    int map_index = (mb_row * cpi->common.mb_cols);
-
-#if (CONFIG_REALTIME_ONLY & CONFIG_ONTHEFLY_BITPACKING)
-    const int num_part = (1 << cm->multi_token_partition);
-    TOKENEXTRA * tp_start = cpi->tok;
-    vp8_writer *w;
-#endif
-
-#if CONFIG_MULTITHREAD
-    const int nsync = cpi->mt_sync_range;
-    const int rightmost_col = cm->mb_cols + nsync;
-    const int *last_row_current_mb_col;
-    int *current_mb_col = &cpi->mt_current_mb_col[mb_row];
-
-    if ((cpi->b_multi_threaded != 0) && (mb_row != 0))
-        last_row_current_mb_col = &cpi->mt_current_mb_col[mb_row - 1];
-    else
-        last_row_current_mb_col = &rightmost_col;
-#endif
-
-#if (CONFIG_REALTIME_ONLY & CONFIG_ONTHEFLY_BITPACKING)
-    if(num_part > 1)
-        w= &cpi->bc[1 + (mb_row % num_part)];
-    else
-        w = &cpi->bc[1];
-#endif
-
-    /* reset above block coeffs */
-    xd->above_context = cm->above_context;
-
-    xd->up_available = (mb_row != 0);
-    recon_yoffset = (mb_row * recon_y_stride * 16);
-    recon_uvoffset = (mb_row * recon_uv_stride * 8);
-
-    cpi->tplist[mb_row].start = *tp;
-    /* printf("Main mb_row = %d\n", mb_row); */
-
-    /* Distance of Mb to the top & bottom edges, specified in 1/8th pel
-     * units as they are always compared to values that are in 1/8th pel
-     */
-    xd->mb_to_top_edge = -((mb_row * 16) << 3);
-    xd->mb_to_bottom_edge = ((cm->mb_rows - 1 - mb_row) * 16) << 3;
-
-    /* Set up limit values for vertical motion vector components
-     * to prevent them extending beyond the UMV borders
-     */
-    x->mv_row_min = -((mb_row * 16) + (VP8BORDERINPIXELS - 16));
-    x->mv_row_max = ((cm->mb_rows - 1 - mb_row) * 16)
-                        + (VP8BORDERINPIXELS - 16);
-
-    /* Set the mb activity pointer to the start of the row. */
-    x->mb_activity_ptr = &cpi->mb_activity_map[map_index];
-
-    /* for each macroblock col in image */
-    for (mb_col = 0; mb_col < cm->mb_cols; mb_col++)
-    {
-
-#if  (CONFIG_REALTIME_ONLY & CONFIG_ONTHEFLY_BITPACKING)
-        *tp = cpi->tok;
-#endif
-        /* Distance of Mb to the left & right edges, specified in
-         * 1/8th pel units as they are always compared to values
-         * that are in 1/8th pel units
-         */
-        xd->mb_to_left_edge = -((mb_col * 16) << 3);
-        xd->mb_to_right_edge = ((cm->mb_cols - 1 - mb_col) * 16) << 3;
-
-        /* Set up limit values for horizontal motion vector components
-         * to prevent them extending beyond the UMV borders
-         */
-        x->mv_col_min = -((mb_col * 16) + (VP8BORDERINPIXELS - 16));
-        x->mv_col_max = ((cm->mb_cols - 1 - mb_col) * 16)
-                            + (VP8BORDERINPIXELS - 16);
-
-        xd->dst.y_buffer = cm->yv12_fb[dst_fb_idx].y_buffer + recon_yoffset;
-        xd->dst.u_buffer = cm->yv12_fb[dst_fb_idx].u_buffer + recon_uvoffset;
-        xd->dst.v_buffer = cm->yv12_fb[dst_fb_idx].v_buffer + recon_uvoffset;
-        xd->left_available = (mb_col != 0);
-
-        x->rddiv = cpi->RDDIV;
-        x->rdmult = cpi->RDMULT;
-
-        /* Copy current mb to a buffer */
-        vp8_copy_mem16x16(x->src.y_buffer, x->src.y_stride, x->thismb, 16);
-
-#if CONFIG_MULTITHREAD
-        if (cpi->b_multi_threaded != 0) {
-            if (((mb_col - 1) % nsync) == 0) {
-                pthread_mutex_t *mutex = &cpi->pmutex[mb_row];
-                protected_write(mutex, current_mb_col, mb_col - 1);
-            }
-
-            if (mb_row && !(mb_col & (nsync - 1))) {
-                pthread_mutex_t *mutex = &cpi->pmutex[mb_row-1];
-                sync_read(mutex, mb_col, last_row_current_mb_col, nsync);
-            }
-        }
-#endif
-
-        if(cpi->oxcf.tuning == VP8_TUNE_SSIM)
-            vp8_activity_masking(cpi, x);
-
-        /* Is segmentation enabled */
-        /* MB level adjustment to quantizer */
-        if (xd->segmentation_enabled)
-        {
-            /* Code to set segment id in xd->mbmi.segment_id for current MB
-             * (with range checking)
-             */
-            if (cpi->segmentation_map[map_index+mb_col] <= 3)
-                xd->mode_info_context->mbmi.segment_id = cpi->segmentation_map[map_index+mb_col];
-            else
-                xd->mode_info_context->mbmi.segment_id = 0;
-
-            vp8cx_mb_init_quantizer(cpi, x, 1);
-        }
-        else
-            /* Set to Segment 0 by default */
-            xd->mode_info_context->mbmi.segment_id = 0;
-
-        x->active_ptr = cpi->active_map + map_index + mb_col;
-
-        if (cm->frame_type == KEY_FRAME)
-        {
-            *totalrate += vp8cx_encode_intra_macroblock(cpi, x, tp);
-#ifdef MODE_STATS
-            y_modes[xd->mbmi.mode] ++;
-#endif
-        }
-        else
-        {
-            *totalrate += vp8cx_encode_inter_macroblock(cpi, x, tp, recon_yoffset, recon_uvoffset, mb_row, mb_col);
-
-#ifdef MODE_STATS
-            inter_y_modes[xd->mbmi.mode] ++;
-
-            if (xd->mbmi.mode == SPLITMV)
-            {
-                int b;
-
-                for (b = 0; b < xd->mbmi.partition_count; b++)
-                {
-                    inter_b_modes[x->partition->bmi[b].mode] ++;
-                }
-            }
-
-#endif
-
-            // Keep track of how many (consecutive) times a  block is coded
-            // as ZEROMV_LASTREF, for base layer frames.
-            // Reset to 0 if its coded as anything else.
-            if (cpi->current_layer == 0) {
-              if (xd->mode_info_context->mbmi.mode == ZEROMV &&
-                  xd->mode_info_context->mbmi.ref_frame == LAST_FRAME) {
-                // Increment, check for wrap-around.
-                if (cpi->consec_zero_last[map_index+mb_col] < 255)
-                  cpi->consec_zero_last[map_index+mb_col] += 1;
-                if (cpi->consec_zero_last_mvbias[map_index+mb_col] < 255)
-                  cpi->consec_zero_last_mvbias[map_index+mb_col] += 1;
-              } else {
-                cpi->consec_zero_last[map_index+mb_col] = 0;
-                cpi->consec_zero_last_mvbias[map_index+mb_col] = 0;
-              }
-              if (x->zero_last_dot_suppress)
-                cpi->consec_zero_last_mvbias[map_index+mb_col] = 0;
-            }
-
-            /* Special case code for cyclic refresh
-             * If cyclic update enabled then copy xd->mbmi.segment_id; (which
-             * may have been updated based on mode during
-             * vp8cx_encode_inter_macroblock()) back into the global
-             * segmentation map
-             */
-            if ((cpi->current_layer == 0) &&
-                (cpi->cyclic_refresh_mode_enabled &&
-                 xd->segmentation_enabled))
-            {
-                cpi->segmentation_map[map_index+mb_col] = xd->mode_info_context->mbmi.segment_id;
-
-                /* If the block has been refreshed mark it as clean (the
-                 * magnitude of the -ve influences how long it will be before
-                 * we consider another refresh):
-                 * Else if it was coded (last frame 0,0) and has not already
-                 * been refreshed then mark it as a candidate for cleanup
-                 * next time (marked 0) else mark it as dirty (1).
-                 */
-                if (xd->mode_info_context->mbmi.segment_id)
-                    cpi->cyclic_refresh_map[map_index+mb_col] = -1;
-                else if ((xd->mode_info_context->mbmi.mode == ZEROMV) && (xd->mode_info_context->mbmi.ref_frame == LAST_FRAME))
-                {
-                    if (cpi->cyclic_refresh_map[map_index+mb_col] == 1)
-                        cpi->cyclic_refresh_map[map_index+mb_col] = 0;
-                }
-                else
-                    cpi->cyclic_refresh_map[map_index+mb_col] = 1;
-
-            }
-        }
-
-        cpi->tplist[mb_row].stop = *tp;
-
-#if CONFIG_REALTIME_ONLY & CONFIG_ONTHEFLY_BITPACKING
-        /* pack tokens for this MB */
-        {
-            int tok_count = *tp - tp_start;
-            vp8_pack_tokens(w, tp_start, tok_count);
-        }
-#endif
-        /* Increment pointer into gf usage flags structure. */
-        x->gf_active_ptr++;
-
-        /* Increment the activity mask pointers. */
-        x->mb_activity_ptr++;
-
-        /* adjust to the next column of macroblocks */
-        x->src.y_buffer += 16;
-        x->src.u_buffer += 8;
-        x->src.v_buffer += 8;
-
-        recon_yoffset += 16;
-        recon_uvoffset += 8;
-
-        /* Keep track of segment usage */
-        segment_counts[xd->mode_info_context->mbmi.segment_id] ++;
-
-        /* skip to next mb */
-        xd->mode_info_context++;
-        x->partition_info++;
-        xd->above_context++;
-    }
-
-    /* extend the recon for intra prediction */
-    vp8_extend_mb_row( &cm->yv12_fb[dst_fb_idx],
-                        xd->dst.y_buffer + 16,
-                        xd->dst.u_buffer + 8,
-                        xd->dst.v_buffer + 8);
-
-#if CONFIG_MULTITHREAD
-    if (cpi->b_multi_threaded != 0)
-        protected_write(&cpi->pmutex[mb_row], current_mb_col, rightmost_col);
-#endif
-
-    /* this is to account for the border */
-    xd->mode_info_context++;
-    x->partition_info++;
-}
-
-static void init_encode_frame_mb_context(VP8_COMP *cpi)
-{
-    MACROBLOCK *const x = & cpi->mb;
-    VP8_COMMON *const cm = & cpi->common;
-    MACROBLOCKD *const xd = & x->e_mbd;
-
-    /* GF active flags data structure */
-    x->gf_active_ptr = (signed char *)cpi->gf_active_flags;
-
-    /* Activity map pointer */
-    x->mb_activity_ptr = cpi->mb_activity_map;
-
-    x->act_zbin_adj = 0;
-
-    x->partition_info = x->pi;
-
-    xd->mode_info_context = cm->mi;
-    xd->mode_info_stride = cm->mode_info_stride;
-
-    xd->frame_type = cm->frame_type;
-
-    /* reset intra mode contexts */
-    if (cm->frame_type == KEY_FRAME)
-        vp8_init_mbmode_probs(cm);
-
-    /* Copy data over into macro block data structures. */
-    x->src = * cpi->Source;
-    xd->pre = cm->yv12_fb[cm->lst_fb_idx];
-    xd->dst = cm->yv12_fb[cm->new_fb_idx];
-
-    /* set up frame for intra coded blocks */
-    vp8_setup_intra_recon(&cm->yv12_fb[cm->new_fb_idx]);
-
-    vp8_build_block_offsets(x);
-
-    xd->mode_info_context->mbmi.mode = DC_PRED;
-    xd->mode_info_context->mbmi.uv_mode = DC_PRED;
-
-    xd->left_context = &cm->left_context;
-
-    x->mvc = cm->fc.mvc;
-
-    memset(cm->above_context, 0, sizeof(ENTROPY_CONTEXT_PLANES) * cm->mb_cols);
-
-    /* Special case treatment when GF and ARF are not sensible options
-     * for reference
-     */
-    if (cpi->ref_frame_flags == VP8_LAST_FRAME)
-        vp8_calc_ref_frame_costs(x->ref_frame_cost,
-                                 cpi->prob_intra_coded,255,128);
-    else if ((cpi->oxcf.number_of_layers > 1) &&
-               (cpi->ref_frame_flags == VP8_GOLD_FRAME))
-        vp8_calc_ref_frame_costs(x->ref_frame_cost,
-                                 cpi->prob_intra_coded,1,255);
-    else if ((cpi->oxcf.number_of_layers > 1) &&
-                (cpi->ref_frame_flags == VP8_ALTR_FRAME))
-        vp8_calc_ref_frame_costs(x->ref_frame_cost,
-                                 cpi->prob_intra_coded,1,1);
-    else
-        vp8_calc_ref_frame_costs(x->ref_frame_cost,
-                                 cpi->prob_intra_coded,
-                                 cpi->prob_last_coded,
-                                 cpi->prob_gf_coded);
-
-    xd->fullpixel_mask = 0xffffffff;
-    if(cm->full_pixel)
-        xd->fullpixel_mask = 0xfffffff8;
-
-    vp8_zero(x->coef_counts);
-    vp8_zero(x->ymode_count);
-    vp8_zero(x->uv_mode_count)
-    x->prediction_error = 0;
-    x->intra_error = 0;
-    vp8_zero(x->count_mb_ref_frame_usage);
-}
-
-#if CONFIG_MULTITHREAD
-static void sum_coef_counts(MACROBLOCK *x, MACROBLOCK *x_thread)
-{
-    int i = 0;
-    do
-    {
-        int j = 0;
-        do
-        {
-            int k = 0;
-            do
-            {
-                /* at every context */
-
-                /* calc probs and branch cts for this frame only */
-                int t = 0;      /* token/prob index */
-
-                do
-                {
-                    x->coef_counts [i][j][k][t] +=
-                        x_thread->coef_counts [i][j][k][t];
-                }
-                while (++t < ENTROPY_NODES);
-            }
-            while (++k < PREV_COEF_CONTEXTS);
-        }
-        while (++j < COEF_BANDS);
-    }
-    while (++i < BLOCK_TYPES);
-}
-#endif  // CONFIG_MULTITHREAD
-
-void vp8_encode_frame(VP8_COMP *cpi)
-{
-    int mb_row;
-    MACROBLOCK *const x = & cpi->mb;
-    VP8_COMMON *const cm = & cpi->common;
-    MACROBLOCKD *const xd = & x->e_mbd;
-    TOKENEXTRA *tp = cpi->tok;
-    int segment_counts[MAX_MB_SEGMENTS];
-    int totalrate;
-#if CONFIG_REALTIME_ONLY & CONFIG_ONTHEFLY_BITPACKING
-    BOOL_CODER * bc = &cpi->bc[1]; /* bc[0] is for control partition */
-    const int num_part = (1 << cm->multi_token_partition);
-#endif
-
-    memset(segment_counts, 0, sizeof(segment_counts));
-    totalrate = 0;
-
-    if (cpi->compressor_speed == 2)
-    {
-        if (cpi->oxcf.cpu_used < 0)
-            cpi->Speed = -(cpi->oxcf.cpu_used);
-        else
-            vp8_auto_select_speed(cpi);
-    }
-
-    /* Functions setup for all frame types so we can use MC in AltRef */
-    if(!cm->use_bilinear_mc_filter)
-    {
-        xd->subpixel_predict        = vp8_sixtap_predict4x4;
-        xd->subpixel_predict8x4     = vp8_sixtap_predict8x4;
-        xd->subpixel_predict8x8     = vp8_sixtap_predict8x8;
-        xd->subpixel_predict16x16   = vp8_sixtap_predict16x16;
-    }
-    else
-    {
-        xd->subpixel_predict        = vp8_bilinear_predict4x4;
-        xd->subpixel_predict8x4     = vp8_bilinear_predict8x4;
-        xd->subpixel_predict8x8     = vp8_bilinear_predict8x8;
-        xd->subpixel_predict16x16   = vp8_bilinear_predict16x16;
-    }
-
-    cpi->mb.skip_true_count = 0;
-    cpi->tok_count = 0;
-
-#if 0
-    /* Experimental code */
-    cpi->frame_distortion = 0;
-    cpi->last_mb_distortion = 0;
-#endif
-
-    xd->mode_info_context = cm->mi;
-
-    vp8_zero(cpi->mb.MVcount);
-
-    vp8cx_frame_init_quantizer(cpi);
-
-    vp8_initialize_rd_consts(cpi, x,
-                             vp8_dc_quant(cm->base_qindex, cm->y1dc_delta_q));
-
-    vp8cx_initialize_me_consts(cpi, cm->base_qindex);
-
-    if(cpi->oxcf.tuning == VP8_TUNE_SSIM)
-    {
-        /* Initialize encode frame context. */
-        init_encode_frame_mb_context(cpi);
-
-        /* Build a frame level activity map */
-        build_activity_map(cpi);
-    }
-
-    /* re-init encode frame context. */
-    init_encode_frame_mb_context(cpi);
-
-#if CONFIG_REALTIME_ONLY & CONFIG_ONTHEFLY_BITPACKING
-    {
-        int i;
-        for(i = 0; i < num_part; i++)
-        {
-            vp8_start_encode(&bc[i], cpi->partition_d[i + 1],
-                    cpi->partition_d_end[i + 1]);
-            bc[i].error = &cm->error;
-        }
-    }
-
-#endif
-
-    {
-        struct vpx_usec_timer  emr_timer;
-        vpx_usec_timer_start(&emr_timer);
-
-#if CONFIG_MULTITHREAD
-        if (cpi->b_multi_threaded)
-        {
-            int i;
-
-            vp8cx_init_mbrthread_data(cpi, x, cpi->mb_row_ei,
-                                      cpi->encoding_thread_count);
-
-            for (i = 0; i < cm->mb_rows; i++)
-                cpi->mt_current_mb_col[i] = -1;
-
-            for (i = 0; i < cpi->encoding_thread_count; i++)
-            {
-                sem_post(&cpi->h_event_start_encoding[i]);
-            }
-
-            for (mb_row = 0; mb_row < cm->mb_rows; mb_row += (cpi->encoding_thread_count + 1))
-            {
-                vp8_zero(cm->left_context)
-
-#if CONFIG_REALTIME_ONLY & CONFIG_ONTHEFLY_BITPACKING
-                tp = cpi->tok;
-#else
-                tp = cpi->tok + mb_row * (cm->mb_cols * 16 * 24);
-#endif
-
-                encode_mb_row(cpi, cm, mb_row, x, xd, &tp, segment_counts, &totalrate);
-
-                /* adjust to the next row of mbs */
-                x->src.y_buffer += 16 * x->src.y_stride * (cpi->encoding_thread_count + 1) - 16 * cm->mb_cols;
-                x->src.u_buffer +=  8 * x->src.uv_stride * (cpi->encoding_thread_count + 1) - 8 * cm->mb_cols;
-                x->src.v_buffer +=  8 * x->src.uv_stride * (cpi->encoding_thread_count + 1) - 8 * cm->mb_cols;
-
-                xd->mode_info_context += xd->mode_info_stride * cpi->encoding_thread_count;
-                x->partition_info  += xd->mode_info_stride * cpi->encoding_thread_count;
-                x->gf_active_ptr   += cm->mb_cols * cpi->encoding_thread_count;
-
-                if(mb_row == cm->mb_rows - 1)
-                {
-                    sem_post(&cpi->h_event_end_encoding); /* signal frame encoding end */
-                }
-            }
-
-            sem_wait(&cpi->h_event_end_encoding); /* wait for other threads to finish */
-
-            for (mb_row = 0; mb_row < cm->mb_rows; mb_row ++)
-            {
-                cpi->tok_count += (unsigned int)
-                  (cpi->tplist[mb_row].stop - cpi->tplist[mb_row].start);
-            }
-
-            if (xd->segmentation_enabled)
-            {
-                int j;
-
-                if (xd->segmentation_enabled)
-                {
-                    for (i = 0; i < cpi->encoding_thread_count; i++)
-                    {
-                        for (j = 0; j < 4; j++)
-                            segment_counts[j] += cpi->mb_row_ei[i].segment_counts[j];
-                    }
-                }
-            }
-
-            for (i = 0; i < cpi->encoding_thread_count; i++)
-            {
-                int mode_count;
-                int c_idx;
-                totalrate += cpi->mb_row_ei[i].totalrate;
-
-                cpi->mb.skip_true_count += cpi->mb_row_ei[i].mb.skip_true_count;
-
-                for(mode_count = 0; mode_count < VP8_YMODES; mode_count++)
-                    cpi->mb.ymode_count[mode_count] +=
-                        cpi->mb_row_ei[i].mb.ymode_count[mode_count];
-
-                for(mode_count = 0; mode_count < VP8_UV_MODES; mode_count++)
-                    cpi->mb.uv_mode_count[mode_count] +=
-                        cpi->mb_row_ei[i].mb.uv_mode_count[mode_count];
-
-                for(c_idx = 0; c_idx < MVvals; c_idx++)
-                {
-                    cpi->mb.MVcount[0][c_idx] +=
-                        cpi->mb_row_ei[i].mb.MVcount[0][c_idx];
-                    cpi->mb.MVcount[1][c_idx] +=
-                        cpi->mb_row_ei[i].mb.MVcount[1][c_idx];
-                }
-
-                cpi->mb.prediction_error +=
-                    cpi->mb_row_ei[i].mb.prediction_error;
-                cpi->mb.intra_error += cpi->mb_row_ei[i].mb.intra_error;
-
-                for(c_idx = 0; c_idx < MAX_REF_FRAMES; c_idx++)
-                    cpi->mb.count_mb_ref_frame_usage[c_idx] +=
-                        cpi->mb_row_ei[i].mb.count_mb_ref_frame_usage[c_idx];
-
-                for(c_idx = 0; c_idx < MAX_ERROR_BINS; c_idx++)
-                    cpi->mb.error_bins[c_idx] +=
-                        cpi->mb_row_ei[i].mb.error_bins[c_idx];
-
-                /* add up counts for each thread */
-                sum_coef_counts(x, &cpi->mb_row_ei[i].mb);
-            }
-
-        }
-        else
-#endif  // CONFIG_MULTITHREAD
-        {
-
-            /* for each macroblock row in image */
-            for (mb_row = 0; mb_row < cm->mb_rows; mb_row++)
-            {
-                vp8_zero(cm->left_context)
-
-#if CONFIG_REALTIME_ONLY & CONFIG_ONTHEFLY_BITPACKING
-                tp = cpi->tok;
-#endif
-
-                encode_mb_row(cpi, cm, mb_row, x, xd, &tp, segment_counts, &totalrate);
-
-                /* adjust to the next row of mbs */
-                x->src.y_buffer += 16 * x->src.y_stride - 16 * cm->mb_cols;
-                x->src.u_buffer += 8 * x->src.uv_stride - 8 * cm->mb_cols;
-                x->src.v_buffer += 8 * x->src.uv_stride - 8 * cm->mb_cols;
-            }
-
-            cpi->tok_count = (unsigned int)(tp - cpi->tok);
-        }
-
-#if CONFIG_REALTIME_ONLY & CONFIG_ONTHEFLY_BITPACKING
-        {
-            int i;
-            for(i = 0; i < num_part; i++)
-            {
-                vp8_stop_encode(&bc[i]);
-                cpi->partition_sz[i+1] = bc[i].pos;
-            }
-        }
-#endif
-
-        vpx_usec_timer_mark(&emr_timer);
-        cpi->time_encode_mb_row += vpx_usec_timer_elapsed(&emr_timer);
-    }
-
-
-    // Work out the segment probabilities if segmentation is enabled
-    // and needs to be updated
-    if (xd->segmentation_enabled && xd->update_mb_segmentation_map)
-    {
-        int tot_count;
-        int i;
-
-        /* Set to defaults */
-        memset(xd->mb_segment_tree_probs, 255 , sizeof(xd->mb_segment_tree_probs));
-
-        tot_count = segment_counts[0] + segment_counts[1] + segment_counts[2] + segment_counts[3];
-
-        if (tot_count)
-        {
-            xd->mb_segment_tree_probs[0] = ((segment_counts[0] + segment_counts[1]) * 255) / tot_count;
-
-            tot_count = segment_counts[0] + segment_counts[1];
-
-            if (tot_count > 0)
-            {
-                xd->mb_segment_tree_probs[1] = (segment_counts[0] * 255) / tot_count;
-            }
-
-            tot_count = segment_counts[2] + segment_counts[3];
-
-            if (tot_count > 0)
-                xd->mb_segment_tree_probs[2] = (segment_counts[2] * 255) / tot_count;
-
-            /* Zero probabilities not allowed */
-            for (i = 0; i < MB_FEATURE_TREE_PROBS; i ++)
-            {
-                if (xd->mb_segment_tree_probs[i] == 0)
-                    xd->mb_segment_tree_probs[i] = 1;
-            }
-        }
-    }
-
-    /* projected_frame_size in units of BYTES */
-    cpi->projected_frame_size = totalrate >> 8;
-
-    /* Make a note of the percentage MBs coded Intra. */
-    if (cm->frame_type == KEY_FRAME)
-    {
-        cpi->this_frame_percent_intra = 100;
-    }
-    else
-    {
-        int tot_modes;
-
-        tot_modes = cpi->mb.count_mb_ref_frame_usage[INTRA_FRAME]
-                    + cpi->mb.count_mb_ref_frame_usage[LAST_FRAME]
-                    + cpi->mb.count_mb_ref_frame_usage[GOLDEN_FRAME]
-                    + cpi->mb.count_mb_ref_frame_usage[ALTREF_FRAME];
-
-        if (tot_modes)
-            cpi->this_frame_percent_intra =
-                cpi->mb.count_mb_ref_frame_usage[INTRA_FRAME] * 100 / tot_modes;
-
-    }
-
-#if ! CONFIG_REALTIME_ONLY
-    /* Adjust the projected reference frame usage probability numbers to
-     * reflect what we have just seen. This may be useful when we make
-     * multiple iterations of the recode loop rather than continuing to use
-     * values from the previous frame.
-     */
-    if ((cm->frame_type != KEY_FRAME) && ((cpi->oxcf.number_of_layers > 1) ||
-        (!cm->refresh_alt_ref_frame && !cm->refresh_golden_frame)))
-    {
-      vp8_convert_rfct_to_prob(cpi);
-    }
-#endif
-}
-void vp8_setup_block_ptrs(MACROBLOCK *x)
-{
-    int r, c;
-    int i;
-
-    for (r = 0; r < 4; r++)
-    {
-        for (c = 0; c < 4; c++)
-        {
-            x->block[r*4+c].src_diff = x->src_diff + r * 4 * 16 + c * 4;
-        }
-    }
-
-    for (r = 0; r < 2; r++)
-    {
-        for (c = 0; c < 2; c++)
-        {
-            x->block[16 + r*2+c].src_diff = x->src_diff + 256 + r * 4 * 8 + c * 4;
-        }
-    }
-
-
-    for (r = 0; r < 2; r++)
-    {
-        for (c = 0; c < 2; c++)
-        {
-            x->block[20 + r*2+c].src_diff = x->src_diff + 320 + r * 4 * 8 + c * 4;
-        }
-    }
-
-    x->block[24].src_diff = x->src_diff + 384;
-
-
-    for (i = 0; i < 25; i++)
-    {
-        x->block[i].coeff = x->coeff + i * 16;
-    }
-}
-
-void vp8_build_block_offsets(MACROBLOCK *x)
-{
-    int block = 0;
-    int br, bc;
-
-    vp8_build_block_doffsets(&x->e_mbd);
-
-    /* y blocks */
-    x->thismb_ptr = &x->thismb[0];
-    for (br = 0; br < 4; br++)
-    {
-        for (bc = 0; bc < 4; bc++)
-        {
-            BLOCK *this_block = &x->block[block];
-            this_block->base_src = &x->thismb_ptr;
-            this_block->src_stride = 16;
-            this_block->src = 4 * br * 16 + 4 * bc;
-            ++block;
-        }
-    }
-
-    /* u blocks */
-    for (br = 0; br < 2; br++)
-    {
-        for (bc = 0; bc < 2; bc++)
-        {
-            BLOCK *this_block = &x->block[block];
-            this_block->base_src = &x->src.u_buffer;
-            this_block->src_stride = x->src.uv_stride;
-            this_block->src = 4 * br * this_block->src_stride + 4 * bc;
-            ++block;
-        }
-    }
-
-    /* v blocks */
-    for (br = 0; br < 2; br++)
-    {
-        for (bc = 0; bc < 2; bc++)
-        {
-            BLOCK *this_block = &x->block[block];
-            this_block->base_src = &x->src.v_buffer;
-            this_block->src_stride = x->src.uv_stride;
-            this_block->src = 4 * br * this_block->src_stride + 4 * bc;
-            ++block;
-        }
-    }
-}
-
-static void sum_intra_stats(VP8_COMP *cpi, MACROBLOCK *x)
-{
-    const MACROBLOCKD *xd = & x->e_mbd;
-    const MB_PREDICTION_MODE m = xd->mode_info_context->mbmi.mode;
-    const MB_PREDICTION_MODE uvm = xd->mode_info_context->mbmi.uv_mode;
-
-#ifdef MODE_STATS
-    const int is_key = cpi->common.frame_type == KEY_FRAME;
-
-    ++ (is_key ? uv_modes : inter_uv_modes)[uvm];
-
-    if (m == B_PRED)
-    {
-        unsigned int *const bct = is_key ? b_modes : inter_b_modes;
-
-        int b = 0;
-
-        do
-        {
-            ++ bct[xd->block[b].bmi.mode];
-        }
-        while (++b < 16);
-    }
-
-#else
-    (void)cpi;
-#endif
-
-    ++x->ymode_count[m];
-    ++x->uv_mode_count[uvm];
-
-}
-
-/* Experimental stub function to create a per MB zbin adjustment based on
- * some previously calculated measure of MB activity.
- */
-static void adjust_act_zbin( VP8_COMP *cpi, MACROBLOCK *x )
-{
-#if USE_ACT_INDEX
-    x->act_zbin_adj = *(x->mb_activity_ptr);
-#else
-    int64_t a;
-    int64_t b;
-    int64_t act = *(x->mb_activity_ptr);
-
-    /* Apply the masking to the RD multiplier. */
-    a = act + 4*cpi->activity_avg;
-    b = 4*act + cpi->activity_avg;
-
-    if ( act > cpi->activity_avg )
-        x->act_zbin_adj = (int)(((int64_t)b + (a>>1))/a) - 1;
-    else
-        x->act_zbin_adj = 1 - (int)(((int64_t)a + (b>>1))/b);
-#endif
-}
-
-int vp8cx_encode_intra_macroblock(VP8_COMP *cpi, MACROBLOCK *x,
-                                  TOKENEXTRA **t)
-{
-    MACROBLOCKD *xd = &x->e_mbd;
-    int rate;
-
-    if (cpi->sf.RD && cpi->compressor_speed != 2)
-        vp8_rd_pick_intra_mode(x, &rate);
-    else
-        vp8_pick_intra_mode(x, &rate);
-
-    if(cpi->oxcf.tuning == VP8_TUNE_SSIM)
-    {
-        adjust_act_zbin( cpi, x );
-        vp8_update_zbin_extra(cpi, x);
-    }
-
-    if (x->e_mbd.mode_info_context->mbmi.mode == B_PRED)
-        vp8_encode_intra4x4mby(x);
-    else
-        vp8_encode_intra16x16mby(x);
-
-    vp8_encode_intra16x16mbuv(x);
-
-    sum_intra_stats(cpi, x);
-
-    vp8_tokenize_mb(cpi, x, t);
-
-    if (xd->mode_info_context->mbmi.mode != B_PRED)
-        vp8_inverse_transform_mby(xd);
-
-    vp8_dequant_idct_add_uv_block
-                    (xd->qcoeff+16*16, xd->dequant_uv,
-                     xd->dst.u_buffer, xd->dst.v_buffer,
-                     xd->dst.uv_stride, xd->eobs+16);
-    return rate;
-}
-#ifdef SPEEDSTATS
-extern int cnt_pm;
-#endif
-
-extern void vp8_fix_contexts(MACROBLOCKD *x);
-
-int vp8cx_encode_inter_macroblock
-(
-    VP8_COMP *cpi, MACROBLOCK *x, TOKENEXTRA **t,
-    int recon_yoffset, int recon_uvoffset,
-    int mb_row, int mb_col
-)
-{
-    MACROBLOCKD *const xd = &x->e_mbd;
-    int intra_error = 0;
-    int rate;
-    int distortion;
-
-    x->skip = 0;
-
-    if (xd->segmentation_enabled)
-        x->encode_breakout = cpi->segment_encode_breakout[xd->mode_info_context->mbmi.segment_id];
-    else
-        x->encode_breakout = cpi->oxcf.encode_breakout;
-
-#if CONFIG_TEMPORAL_DENOISING
-    /* Reset the best sse mode/mv for each macroblock. */
-    x->best_reference_frame = INTRA_FRAME;
-    x->best_zeromv_reference_frame = INTRA_FRAME;
-    x->best_sse_inter_mode = 0;
-    x->best_sse_mv.as_int = 0;
-    x->need_to_clamp_best_mvs = 0;
-#endif
-
-    if (cpi->sf.RD)
-    {
-        int zbin_mode_boost_enabled = x->zbin_mode_boost_enabled;
-
-        /* Are we using the fast quantizer for the mode selection? */
-        if(cpi->sf.use_fastquant_for_pick)
-        {
-            x->quantize_b      = vp8_fast_quantize_b;
-
-            /* the fast quantizer does not use zbin_extra, so
-             * do not recalculate */
-            x->zbin_mode_boost_enabled = 0;
-        }
-        vp8_rd_pick_inter_mode(cpi, x, recon_yoffset, recon_uvoffset, &rate,
-                               &distortion, &intra_error, mb_row, mb_col);
-
-        /* switch back to the regular quantizer for the encode */
-        if (cpi->sf.improved_quant)
-        {
-            x->quantize_b      = vp8_regular_quantize_b;
-        }
-
-        /* restore cpi->zbin_mode_boost_enabled */
-        x->zbin_mode_boost_enabled = zbin_mode_boost_enabled;
-
-    }
-    else
-    {
-        vp8_pick_inter_mode(cpi, x, recon_yoffset, recon_uvoffset, &rate,
-                            &distortion, &intra_error, mb_row, mb_col);
-    }
-
-    x->prediction_error += distortion;
-    x->intra_error += intra_error;
-
-    if(cpi->oxcf.tuning == VP8_TUNE_SSIM)
-    {
-        /* Adjust the zbin based on this MB rate. */
-        adjust_act_zbin( cpi, x );
-    }
-
-#if 0
-    /* Experimental RD code */
-    cpi->frame_distortion += distortion;
-    cpi->last_mb_distortion = distortion;
-#endif
-
-    /* MB level adjutment to quantizer setup */
-    if (xd->segmentation_enabled)
-    {
-        /* If cyclic update enabled */
-        if (cpi->current_layer == 0 && cpi->cyclic_refresh_mode_enabled)
-        {
-            /* Clear segment_id back to 0 if not coded (last frame 0,0) */
-            if ((xd->mode_info_context->mbmi.segment_id == 1) &&
-                ((xd->mode_info_context->mbmi.ref_frame != LAST_FRAME) || (xd->mode_info_context->mbmi.mode != ZEROMV)))
-            {
-                xd->mode_info_context->mbmi.segment_id = 0;
-
-                /* segment_id changed, so update */
-                vp8cx_mb_init_quantizer(cpi, x, 1);
-            }
-        }
-    }
-
-    {
-        /* Experimental code.
-         * Special case for gf and arf zeromv modes, for 1 temporal layer.
-         * Increase zbin size to supress noise.
-         */
-        x->zbin_mode_boost = 0;
-        if (x->zbin_mode_boost_enabled)
-        {
-            if ( xd->mode_info_context->mbmi.ref_frame != INTRA_FRAME )
-            {
-                if (xd->mode_info_context->mbmi.mode == ZEROMV)
-                {
-                    if (xd->mode_info_context->mbmi.ref_frame != LAST_FRAME &&
-                        cpi->oxcf.number_of_layers == 1)
-                        x->zbin_mode_boost = GF_ZEROMV_ZBIN_BOOST;
-                    else
-                        x->zbin_mode_boost = LF_ZEROMV_ZBIN_BOOST;
-                }
-                else if (xd->mode_info_context->mbmi.mode == SPLITMV)
-                    x->zbin_mode_boost = 0;
-                else
-                    x->zbin_mode_boost = MV_ZBIN_BOOST;
-            }
-        }
-
-        /* The fast quantizer doesn't use zbin_extra, only do so with
-         * the regular quantizer. */
-        if (cpi->sf.improved_quant)
-            vp8_update_zbin_extra(cpi, x);
-    }
-
-    x->count_mb_ref_frame_usage[xd->mode_info_context->mbmi.ref_frame] ++;
-
-    if (xd->mode_info_context->mbmi.ref_frame == INTRA_FRAME)
-    {
-        vp8_encode_intra16x16mbuv(x);
-
-        if (xd->mode_info_context->mbmi.mode == B_PRED)
-        {
-            vp8_encode_intra4x4mby(x);
-        }
-        else
-        {
-            vp8_encode_intra16x16mby(x);
-        }
-
-        sum_intra_stats(cpi, x);
-    }
-    else
-    {
-        int ref_fb_idx;
-
-        if (xd->mode_info_context->mbmi.ref_frame == LAST_FRAME)
-            ref_fb_idx = cpi->common.lst_fb_idx;
-        else if (xd->mode_info_context->mbmi.ref_frame == GOLDEN_FRAME)
-            ref_fb_idx = cpi->common.gld_fb_idx;
-        else
-            ref_fb_idx = cpi->common.alt_fb_idx;
-
-        xd->pre.y_buffer = cpi->common.yv12_fb[ref_fb_idx].y_buffer + recon_yoffset;
-        xd->pre.u_buffer = cpi->common.yv12_fb[ref_fb_idx].u_buffer + recon_uvoffset;
-        xd->pre.v_buffer = cpi->common.yv12_fb[ref_fb_idx].v_buffer + recon_uvoffset;
-
-        if (!x->skip)
-        {
-            vp8_encode_inter16x16(x);
-        }
-        else
-            vp8_build_inter16x16_predictors_mb(xd, xd->dst.y_buffer,
-                                           xd->dst.u_buffer, xd->dst.v_buffer,
-                                           xd->dst.y_stride, xd->dst.uv_stride);
-
-    }
-
-    if (!x->skip)
-    {
-        vp8_tokenize_mb(cpi, x, t);
-
-        if (xd->mode_info_context->mbmi.mode != B_PRED)
-            vp8_inverse_transform_mby(xd);
-
-        vp8_dequant_idct_add_uv_block
-                        (xd->qcoeff+16*16, xd->dequant_uv,
-                         xd->dst.u_buffer, xd->dst.v_buffer,
-                         xd->dst.uv_stride, xd->eobs+16);
-    }
-    else
-    {
-        /* always set mb_skip_coeff as it is needed by the loopfilter */
-        xd->mode_info_context->mbmi.mb_skip_coeff = 1;
-
-        if (cpi->common.mb_no_coeff_skip)
-        {
-            x->skip_true_count ++;
-            vp8_fix_contexts(xd);
-        }
-        else
-        {
-            vp8_stuff_mb(cpi, x, t);
-        }
-    }
-
-    return rate;
-}
diff --git a/vp8/encoder/encodeframe.h b/vp8/encoder/encodeframe.h
deleted file mode 100644 (file)
index e185c10..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- *  Copyright (c) 2012 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.
- */
-#ifndef VP8_ENCODER_ENCODEFRAME_H_
-#define VP8_ENCODER_ENCODEFRAME_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-extern void vp8_activity_masking(VP8_COMP *cpi, MACROBLOCK *x);
-
-extern void vp8_build_block_offsets(MACROBLOCK *x);
-
-extern void vp8_setup_block_ptrs(MACROBLOCK *x);
-
-extern void vp8_encode_frame(VP8_COMP *cpi);
-
-extern int vp8cx_encode_inter_macroblock(VP8_COMP *cpi, MACROBLOCK *x,
-        TOKENEXTRA **t,
-        int recon_yoffset, int recon_uvoffset,
-        int mb_row, int mb_col);
-
-extern int vp8cx_encode_intra_macroblock(VP8_COMP *cpi, MACROBLOCK *x,
-        TOKENEXTRA **t);
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP8_ENCODER_ENCODEFRAME_H_
diff --git a/vp8/encoder/encodeintra.c b/vp8/encoder/encodeintra.c
deleted file mode 100644 (file)
index 44be959..0000000
+++ /dev/null
@@ -1,140 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#include "vpx_config.h"
-#include "vp8_rtcd.h"
-#include "./vpx_dsp_rtcd.h"
-#include "vp8/encoder/quantize.h"
-#include "vp8/common/reconintra.h"
-#include "vp8/common/reconintra4x4.h"
-#include "encodemb.h"
-#include "vp8/common/invtrans.h"
-#include "encodeintra.h"
-
-
-int vp8_encode_intra(VP8_COMP *cpi, MACROBLOCK *x, int use_dc_pred)
-{
-
-    int i;
-    int intra_pred_var = 0;
-    (void) cpi;
-
-    if (use_dc_pred)
-    {
-        x->e_mbd.mode_info_context->mbmi.mode = DC_PRED;
-        x->e_mbd.mode_info_context->mbmi.uv_mode = DC_PRED;
-        x->e_mbd.mode_info_context->mbmi.ref_frame = INTRA_FRAME;
-
-        vp8_encode_intra16x16mby(x);
-
-        vp8_inverse_transform_mby(&x->e_mbd);
-    }
-    else
-    {
-        for (i = 0; i < 16; i++)
-        {
-            x->e_mbd.block[i].bmi.as_mode = B_DC_PRED;
-            vp8_encode_intra4x4block(x, i);
-        }
-    }
-
-    intra_pred_var = vpx_get_mb_ss(x->src_diff);
-
-    return intra_pred_var;
-}
-
-void vp8_encode_intra4x4block(MACROBLOCK *x, int ib)
-{
-    BLOCKD *b = &x->e_mbd.block[ib];
-    BLOCK *be = &x->block[ib];
-    int dst_stride = x->e_mbd.dst.y_stride;
-    unsigned char *dst = x->e_mbd.dst.y_buffer + b->offset;
-    unsigned char *Above = dst - dst_stride;
-    unsigned char *yleft = dst - 1;
-    unsigned char top_left = Above[-1];
-
-    vp8_intra4x4_predict(Above, yleft, dst_stride, b->bmi.as_mode,
-                         b->predictor, 16, top_left);
-
-    vp8_subtract_b(be, b, 16);
-
-    x->short_fdct4x4(be->src_diff, be->coeff, 32);
-
-    x->quantize_b(be, b);
-
-    if (*b->eob > 1)
-    {
-      vp8_short_idct4x4llm(b->dqcoeff, b->predictor, 16, dst, dst_stride);
-    }
-    else
-    {
-      vp8_dc_only_idct_add(b->dqcoeff[0], b->predictor, 16, dst, dst_stride);
-    }
-}
-
-void vp8_encode_intra4x4mby(MACROBLOCK *mb)
-{
-    int i;
-
-    MACROBLOCKD *xd = &mb->e_mbd;
-    intra_prediction_down_copy(xd, xd->dst.y_buffer - xd->dst.y_stride + 16);
-
-    for (i = 0; i < 16; i++)
-        vp8_encode_intra4x4block(mb, i);
-    return;
-}
-
-void vp8_encode_intra16x16mby(MACROBLOCK *x)
-{
-    BLOCK *b = &x->block[0];
-    MACROBLOCKD *xd = &x->e_mbd;
-
-    vp8_build_intra_predictors_mby_s(xd,
-                                         xd->dst.y_buffer - xd->dst.y_stride,
-                                         xd->dst.y_buffer - 1,
-                                         xd->dst.y_stride,
-                                         xd->dst.y_buffer,
-                                         xd->dst.y_stride);
-
-    vp8_subtract_mby(x->src_diff, *(b->base_src),
-        b->src_stride, xd->dst.y_buffer, xd->dst.y_stride);
-
-    vp8_transform_intra_mby(x);
-
-    vp8_quantize_mby(x);
-
-    if (x->optimize)
-        vp8_optimize_mby(x);
-}
-
-void vp8_encode_intra16x16mbuv(MACROBLOCK *x)
-{
-    MACROBLOCKD *xd = &x->e_mbd;
-
-    vp8_build_intra_predictors_mbuv_s(xd, xd->dst.u_buffer - xd->dst.uv_stride,
-                                      xd->dst.v_buffer - xd->dst.uv_stride,
-                                      xd->dst.u_buffer - 1,
-                                      xd->dst.v_buffer - 1,
-                                      xd->dst.uv_stride,
-                                      xd->dst.u_buffer, xd->dst.v_buffer,
-                                      xd->dst.uv_stride);
-
-    vp8_subtract_mbuv(x->src_diff, x->src.u_buffer,
-        x->src.v_buffer, x->src.uv_stride, xd->dst.u_buffer,
-        xd->dst.v_buffer, xd->dst.uv_stride);
-
-    vp8_transform_mbuv(x);
-
-    vp8_quantize_mbuv(x);
-
-    if (x->optimize)
-        vp8_optimize_mbuv(x);
-}
diff --git a/vp8/encoder/encodeintra.h b/vp8/encoder/encodeintra.h
deleted file mode 100644 (file)
index a8d0284..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#ifndef VP8_ENCODER_ENCODEINTRA_H_
-#define VP8_ENCODER_ENCODEINTRA_H_
-#include "onyx_int.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-int vp8_encode_intra(VP8_COMP *cpi, MACROBLOCK *x, int use_dc_pred);
-void vp8_encode_intra16x16mby(MACROBLOCK *x);
-void vp8_encode_intra16x16mbuv(MACROBLOCK *x);
-void vp8_encode_intra4x4mby(MACROBLOCK *mb);
-void vp8_encode_intra4x4block(MACROBLOCK *x, int ib);
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP8_ENCODER_ENCODEINTRA_H_
diff --git a/vp8/encoder/encodemb.c b/vp8/encoder/encodemb.c
deleted file mode 100644 (file)
index 932a157..0000000
+++ /dev/null
@@ -1,593 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#include "./vpx_dsp_rtcd.h"
-
-#include "vpx_config.h"
-#include "vp8_rtcd.h"
-#include "encodemb.h"
-#include "vp8/common/reconinter.h"
-#include "vp8/encoder/quantize.h"
-#include "tokenize.h"
-#include "vp8/common/invtrans.h"
-#include "vpx_mem/vpx_mem.h"
-#include "rdopt.h"
-
-void vp8_subtract_b(BLOCK *be, BLOCKD *bd, int pitch) {
-  unsigned char *src_ptr = (*(be->base_src) + be->src);
-  short *diff_ptr = be->src_diff;
-  unsigned char *pred_ptr = bd->predictor;
-  int src_stride = be->src_stride;
-
-  vpx_subtract_block(4, 4, diff_ptr, pitch, src_ptr, src_stride,
-                     pred_ptr, pitch);
-}
-
-void vp8_subtract_mbuv(short *diff, unsigned char *usrc, unsigned char *vsrc,
-                         int src_stride, unsigned char *upred,
-                         unsigned char *vpred, int pred_stride) {
-  short *udiff = diff + 256;
-  short *vdiff = diff + 320;
-
-  vpx_subtract_block(8, 8, udiff, 8, usrc, src_stride, upred, pred_stride);
-  vpx_subtract_block(8, 8, vdiff, 8, vsrc, src_stride, vpred, pred_stride);
-}
-
-void vp8_subtract_mby(short *diff, unsigned char *src, int src_stride,
-                      unsigned char *pred, int pred_stride) {
-  vpx_subtract_block(16, 16, diff, 16, src, src_stride, pred, pred_stride);
-}
-
-static void vp8_subtract_mb(MACROBLOCK *x)
-{
-    BLOCK *b = &x->block[0];
-
-    vp8_subtract_mby(x->src_diff, *(b->base_src),
-        b->src_stride, x->e_mbd.dst.y_buffer, x->e_mbd.dst.y_stride);
-    vp8_subtract_mbuv(x->src_diff, x->src.u_buffer,
-        x->src.v_buffer, x->src.uv_stride, x->e_mbd.dst.u_buffer,
-        x->e_mbd.dst.v_buffer, x->e_mbd.dst.uv_stride);
-}
-
-static void build_dcblock(MACROBLOCK *x)
-{
-    short *src_diff_ptr = &x->src_diff[384];
-    int i;
-
-    for (i = 0; i < 16; i++)
-    {
-        src_diff_ptr[i] = x->coeff[i * 16];
-    }
-}
-
-void vp8_transform_mbuv(MACROBLOCK *x)
-{
-    int i;
-
-    for (i = 16; i < 24; i += 2)
-    {
-        x->short_fdct8x4(&x->block[i].src_diff[0],
-            &x->block[i].coeff[0], 16);
-    }
-}
-
-
-void vp8_transform_intra_mby(MACROBLOCK *x)
-{
-    int i;
-
-    for (i = 0; i < 16; i += 2)
-    {
-        x->short_fdct8x4(&x->block[i].src_diff[0],
-            &x->block[i].coeff[0], 32);
-    }
-
-    /* build dc block from 16 y dc values */
-    build_dcblock(x);
-
-    /* do 2nd order transform on the dc block */
-    x->short_walsh4x4(&x->block[24].src_diff[0],
-        &x->block[24].coeff[0], 8);
-
-}
-
-
-static void transform_mb(MACROBLOCK *x)
-{
-    int i;
-
-    for (i = 0; i < 16; i += 2)
-    {
-        x->short_fdct8x4(&x->block[i].src_diff[0],
-            &x->block[i].coeff[0], 32);
-    }
-
-    /* build dc block from 16 y dc values */
-    if (x->e_mbd.mode_info_context->mbmi.mode != SPLITMV)
-        build_dcblock(x);
-
-    for (i = 16; i < 24; i += 2)
-    {
-        x->short_fdct8x4(&x->block[i].src_diff[0],
-            &x->block[i].coeff[0], 16);
-    }
-
-    /* do 2nd order transform on the dc block */
-    if (x->e_mbd.mode_info_context->mbmi.mode != SPLITMV)
-        x->short_walsh4x4(&x->block[24].src_diff[0],
-        &x->block[24].coeff[0], 8);
-
-}
-
-
-static void transform_mby(MACROBLOCK *x)
-{
-    int i;
-
-    for (i = 0; i < 16; i += 2)
-    {
-        x->short_fdct8x4(&x->block[i].src_diff[0],
-            &x->block[i].coeff[0], 32);
-    }
-
-    /* build dc block from 16 y dc values */
-    if (x->e_mbd.mode_info_context->mbmi.mode != SPLITMV)
-    {
-        build_dcblock(x);
-        x->short_walsh4x4(&x->block[24].src_diff[0],
-            &x->block[24].coeff[0], 8);
-    }
-}
-
-
-
-#define RDTRUNC(RM,DM,R,D) ( (128+(R)*(RM)) & 0xFF )
-
-typedef struct vp8_token_state vp8_token_state;
-
-struct vp8_token_state{
-  int           rate;
-  int           error;
-  signed char   next;
-  signed char   token;
-  short         qc;
-};
-
-/* TODO: experiments to find optimal multiple numbers */
-#define Y1_RD_MULT 4
-#define UV_RD_MULT 2
-#define Y2_RD_MULT 16
-
-static const int plane_rd_mult[4]=
-{
-    Y1_RD_MULT,
-    Y2_RD_MULT,
-    UV_RD_MULT,
-    Y1_RD_MULT
-};
-
-static void optimize_b(MACROBLOCK *mb, int ib, int type,
-                       ENTROPY_CONTEXT *a, ENTROPY_CONTEXT *l)
-{
-    BLOCK *b;
-    BLOCKD *d;
-    vp8_token_state tokens[17][2];
-    unsigned best_mask[2];
-    const short *dequant_ptr;
-    const short *coeff_ptr;
-    short *qcoeff_ptr;
-    short *dqcoeff_ptr;
-    int eob;
-    int i0;
-    int rc;
-    int x;
-    int sz = 0;
-    int next;
-    int rdmult;
-    int rddiv;
-    int final_eob;
-    int rd_cost0;
-    int rd_cost1;
-    int rate0;
-    int rate1;
-    int error0;
-    int error1;
-    int t0;
-    int t1;
-    int best;
-    int band;
-    int pt;
-    int i;
-    int err_mult = plane_rd_mult[type];
-
-    b = &mb->block[ib];
-    d = &mb->e_mbd.block[ib];
-
-    dequant_ptr = d->dequant;
-    coeff_ptr = b->coeff;
-    qcoeff_ptr = d->qcoeff;
-    dqcoeff_ptr = d->dqcoeff;
-    i0 = !type;
-    eob = *d->eob;
-
-    /* Now set up a Viterbi trellis to evaluate alternative roundings. */
-    rdmult = mb->rdmult * err_mult;
-    if(mb->e_mbd.mode_info_context->mbmi.ref_frame==INTRA_FRAME)
-        rdmult = (rdmult * 9)>>4;
-
-    rddiv = mb->rddiv;
-    best_mask[0] = best_mask[1] = 0;
-    /* Initialize the sentinel node of the trellis. */
-    tokens[eob][0].rate = 0;
-    tokens[eob][0].error = 0;
-    tokens[eob][0].next = 16;
-    tokens[eob][0].token = DCT_EOB_TOKEN;
-    tokens[eob][0].qc = 0;
-    *(tokens[eob] + 1) = *(tokens[eob] + 0);
-    next = eob;
-    for (i = eob; i-- > i0;)
-    {
-        int base_bits;
-        int d2;
-        int dx;
-
-        rc = vp8_default_zig_zag1d[i];
-        x = qcoeff_ptr[rc];
-        /* Only add a trellis state for non-zero coefficients. */
-        if (x)
-        {
-            int shortcut=0;
-            error0 = tokens[next][0].error;
-            error1 = tokens[next][1].error;
-            /* Evaluate the first possibility for this state. */
-            rate0 = tokens[next][0].rate;
-            rate1 = tokens[next][1].rate;
-            t0 = (vp8_dct_value_tokens_ptr + x)->Token;
-            /* Consider both possible successor states. */
-            if (next < 16)
-            {
-                band = vp8_coef_bands[i + 1];
-                pt = vp8_prev_token_class[t0];
-                rate0 +=
-                    mb->token_costs[type][band][pt][tokens[next][0].token];
-                rate1 +=
-                    mb->token_costs[type][band][pt][tokens[next][1].token];
-            }
-            rd_cost0 = RDCOST(rdmult, rddiv, rate0, error0);
-            rd_cost1 = RDCOST(rdmult, rddiv, rate1, error1);
-            if (rd_cost0 == rd_cost1)
-            {
-                rd_cost0 = RDTRUNC(rdmult, rddiv, rate0, error0);
-                rd_cost1 = RDTRUNC(rdmult, rddiv, rate1, error1);
-            }
-            /* And pick the best. */
-            best = rd_cost1 < rd_cost0;
-            base_bits = *(vp8_dct_value_cost_ptr + x);
-            dx = dqcoeff_ptr[rc] - coeff_ptr[rc];
-            d2 = dx*dx;
-            tokens[i][0].rate = base_bits + (best ? rate1 : rate0);
-            tokens[i][0].error = d2 + (best ? error1 : error0);
-            tokens[i][0].next = next;
-            tokens[i][0].token = t0;
-            tokens[i][0].qc = x;
-            best_mask[0] |= best << i;
-            /* Evaluate the second possibility for this state. */
-            rate0 = tokens[next][0].rate;
-            rate1 = tokens[next][1].rate;
-
-            if((abs(x)*dequant_ptr[rc]>abs(coeff_ptr[rc])) &&
-               (abs(x)*dequant_ptr[rc]<abs(coeff_ptr[rc])+dequant_ptr[rc]))
-                shortcut = 1;
-            else
-                shortcut = 0;
-
-            if(shortcut)
-            {
-                sz = -(x < 0);
-                x -= 2*sz + 1;
-            }
-
-            /* Consider both possible successor states. */
-            if (!x)
-            {
-                /* If we reduced this coefficient to zero, check to see if
-                 *  we need to move the EOB back here.
-                 */
-                t0 = tokens[next][0].token == DCT_EOB_TOKEN ?
-                    DCT_EOB_TOKEN : ZERO_TOKEN;
-                t1 = tokens[next][1].token == DCT_EOB_TOKEN ?
-                    DCT_EOB_TOKEN : ZERO_TOKEN;
-            }
-            else
-            {
-                t0=t1 = (vp8_dct_value_tokens_ptr + x)->Token;
-            }
-            if (next < 16)
-            {
-                band = vp8_coef_bands[i + 1];
-                if(t0!=DCT_EOB_TOKEN)
-                {
-                    pt = vp8_prev_token_class[t0];
-                    rate0 += mb->token_costs[type][band][pt][
-                        tokens[next][0].token];
-                }
-                if(t1!=DCT_EOB_TOKEN)
-                {
-                    pt = vp8_prev_token_class[t1];
-                    rate1 += mb->token_costs[type][band][pt][
-                        tokens[next][1].token];
-                }
-            }
-
-            rd_cost0 = RDCOST(rdmult, rddiv, rate0, error0);
-            rd_cost1 = RDCOST(rdmult, rddiv, rate1, error1);
-            if (rd_cost0 == rd_cost1)
-            {
-                rd_cost0 = RDTRUNC(rdmult, rddiv, rate0, error0);
-                rd_cost1 = RDTRUNC(rdmult, rddiv, rate1, error1);
-            }
-            /* And pick the best. */
-            best = rd_cost1 < rd_cost0;
-            base_bits = *(vp8_dct_value_cost_ptr + x);
-
-            if(shortcut)
-            {
-                dx -= (dequant_ptr[rc] + sz) ^ sz;
-                d2 = dx*dx;
-            }
-            tokens[i][1].rate = base_bits + (best ? rate1 : rate0);
-            tokens[i][1].error = d2 + (best ? error1 : error0);
-            tokens[i][1].next = next;
-            tokens[i][1].token =best?t1:t0;
-            tokens[i][1].qc = x;
-            best_mask[1] |= best << i;
-            /* Finally, make this the new head of the trellis. */
-            next = i;
-        }
-        /* There's no choice to make for a zero coefficient, so we don't
-         *  add a new trellis node, but we do need to update the costs.
-         */
-        else
-        {
-            band = vp8_coef_bands[i + 1];
-            t0 = tokens[next][0].token;
-            t1 = tokens[next][1].token;
-            /* Update the cost of each path if we're past the EOB token. */
-            if (t0 != DCT_EOB_TOKEN)
-            {
-                tokens[next][0].rate += mb->token_costs[type][band][0][t0];
-                tokens[next][0].token = ZERO_TOKEN;
-            }
-            if (t1 != DCT_EOB_TOKEN)
-            {
-                tokens[next][1].rate += mb->token_costs[type][band][0][t1];
-                tokens[next][1].token = ZERO_TOKEN;
-            }
-            /* Don't update next, because we didn't add a new node. */
-        }
-    }
-
-    /* Now pick the best path through the whole trellis. */
-    band = vp8_coef_bands[i + 1];
-    VP8_COMBINEENTROPYCONTEXTS(pt, *a, *l);
-    rate0 = tokens[next][0].rate;
-    rate1 = tokens[next][1].rate;
-    error0 = tokens[next][0].error;
-    error1 = tokens[next][1].error;
-    t0 = tokens[next][0].token;
-    t1 = tokens[next][1].token;
-    rate0 += mb->token_costs[type][band][pt][t0];
-    rate1 += mb->token_costs[type][band][pt][t1];
-    rd_cost0 = RDCOST(rdmult, rddiv, rate0, error0);
-    rd_cost1 = RDCOST(rdmult, rddiv, rate1, error1);
-    if (rd_cost0 == rd_cost1)
-    {
-        rd_cost0 = RDTRUNC(rdmult, rddiv, rate0, error0);
-        rd_cost1 = RDTRUNC(rdmult, rddiv, rate1, error1);
-    }
-    best = rd_cost1 < rd_cost0;
-    final_eob = i0 - 1;
-    for (i = next; i < eob; i = next)
-    {
-        x = tokens[i][best].qc;
-        if (x)
-            final_eob = i;
-        rc = vp8_default_zig_zag1d[i];
-        qcoeff_ptr[rc] = x;
-        dqcoeff_ptr[rc] = x * dequant_ptr[rc];
-        next = tokens[i][best].next;
-        best = (best_mask[best] >> i) & 1;
-    }
-    final_eob++;
-
-    *a = *l = (final_eob != !type);
-    *d->eob = (char)final_eob;
-}
-static void check_reset_2nd_coeffs(MACROBLOCKD *x, int type,
-                                   ENTROPY_CONTEXT *a, ENTROPY_CONTEXT *l)
-{
-    int sum=0;
-    int i;
-    BLOCKD *bd = &x->block[24];
-
-    if(bd->dequant[0]>=35 && bd->dequant[1]>=35)
-        return;
-
-    for(i=0;i<(*bd->eob);i++)
-    {
-        int coef = bd->dqcoeff[vp8_default_zig_zag1d[i]];
-        sum+= (coef>=0)?coef:-coef;
-        if(sum>=35)
-            return;
-    }
-    /**************************************************************************
-    our inverse hadamard transform effectively is weighted sum of all 16 inputs
-    with weight either 1 or -1. It has a last stage scaling of (sum+3)>>3. And
-    dc only idct is (dc+4)>>3. So if all the sums are between -35 and 29, the
-    output after inverse wht and idct will be all zero. A sum of absolute value
-    smaller than 35 guarantees all 16 different (+1/-1) weighted sums in wht
-    fall between -35 and +35.
-    **************************************************************************/
-    if(sum < 35)
-    {
-        for(i=0;i<(*bd->eob);i++)
-        {
-            int rc = vp8_default_zig_zag1d[i];
-            bd->qcoeff[rc]=0;
-            bd->dqcoeff[rc]=0;
-        }
-        *bd->eob = 0;
-        *a = *l = (*bd->eob != !type);
-    }
-}
-
-static void optimize_mb(MACROBLOCK *x)
-{
-    int b;
-    int type;
-    int has_2nd_order;
-
-    ENTROPY_CONTEXT_PLANES t_above, t_left;
-    ENTROPY_CONTEXT *ta;
-    ENTROPY_CONTEXT *tl;
-
-    memcpy(&t_above, x->e_mbd.above_context, sizeof(ENTROPY_CONTEXT_PLANES));
-    memcpy(&t_left, x->e_mbd.left_context, sizeof(ENTROPY_CONTEXT_PLANES));
-
-    ta = (ENTROPY_CONTEXT *)&t_above;
-    tl = (ENTROPY_CONTEXT *)&t_left;
-
-    has_2nd_order = (x->e_mbd.mode_info_context->mbmi.mode != B_PRED
-        && x->e_mbd.mode_info_context->mbmi.mode != SPLITMV);
-    type = has_2nd_order ? PLANE_TYPE_Y_NO_DC : PLANE_TYPE_Y_WITH_DC;
-
-    for (b = 0; b < 16; b++)
-    {
-        optimize_b(x, b, type,
-            ta + vp8_block2above[b], tl + vp8_block2left[b]);
-    }
-
-    for (b = 16; b < 24; b++)
-    {
-        optimize_b(x, b, PLANE_TYPE_UV,
-            ta + vp8_block2above[b], tl + vp8_block2left[b]);
-    }
-
-    if (has_2nd_order)
-    {
-        b=24;
-        optimize_b(x, b, PLANE_TYPE_Y2,
-            ta + vp8_block2above[b], tl + vp8_block2left[b]);
-        check_reset_2nd_coeffs(&x->e_mbd, PLANE_TYPE_Y2,
-            ta + vp8_block2above[b], tl + vp8_block2left[b]);
-    }
-}
-
-
-void vp8_optimize_mby(MACROBLOCK *x)
-{
-    int b;
-    int type;
-    int has_2nd_order;
-
-    ENTROPY_CONTEXT_PLANES t_above, t_left;
-    ENTROPY_CONTEXT *ta;
-    ENTROPY_CONTEXT *tl;
-
-    if (!x->e_mbd.above_context)
-        return;
-
-    if (!x->e_mbd.left_context)
-        return;
-
-    memcpy(&t_above, x->e_mbd.above_context, sizeof(ENTROPY_CONTEXT_PLANES));
-    memcpy(&t_left, x->e_mbd.left_context, sizeof(ENTROPY_CONTEXT_PLANES));
-
-    ta = (ENTROPY_CONTEXT *)&t_above;
-    tl = (ENTROPY_CONTEXT *)&t_left;
-
-    has_2nd_order = (x->e_mbd.mode_info_context->mbmi.mode != B_PRED
-        && x->e_mbd.mode_info_context->mbmi.mode != SPLITMV);
-    type = has_2nd_order ? PLANE_TYPE_Y_NO_DC : PLANE_TYPE_Y_WITH_DC;
-
-    for (b = 0; b < 16; b++)
-    {
-        optimize_b(x, b, type,
-            ta + vp8_block2above[b], tl + vp8_block2left[b]);
-    }
-
-
-    if (has_2nd_order)
-    {
-        b=24;
-        optimize_b(x, b, PLANE_TYPE_Y2,
-            ta + vp8_block2above[b], tl + vp8_block2left[b]);
-        check_reset_2nd_coeffs(&x->e_mbd, PLANE_TYPE_Y2,
-            ta + vp8_block2above[b], tl + vp8_block2left[b]);
-    }
-}
-
-void vp8_optimize_mbuv(MACROBLOCK *x)
-{
-    int b;
-    ENTROPY_CONTEXT_PLANES t_above, t_left;
-    ENTROPY_CONTEXT *ta;
-    ENTROPY_CONTEXT *tl;
-
-    if (!x->e_mbd.above_context)
-        return;
-
-    if (!x->e_mbd.left_context)
-        return;
-
-    memcpy(&t_above, x->e_mbd.above_context, sizeof(ENTROPY_CONTEXT_PLANES));
-    memcpy(&t_left, x->e_mbd.left_context, sizeof(ENTROPY_CONTEXT_PLANES));
-
-    ta = (ENTROPY_CONTEXT *)&t_above;
-    tl = (ENTROPY_CONTEXT *)&t_left;
-
-    for (b = 16; b < 24; b++)
-    {
-        optimize_b(x, b, PLANE_TYPE_UV,
-            ta + vp8_block2above[b], tl + vp8_block2left[b]);
-    }
-}
-
-void vp8_encode_inter16x16(MACROBLOCK *x)
-{
-    vp8_build_inter_predictors_mb(&x->e_mbd);
-
-    vp8_subtract_mb(x);
-
-    transform_mb(x);
-
-    vp8_quantize_mb(x);
-
-    if (x->optimize)
-        optimize_mb(x);
-}
-
-/* this funciton is used by first pass only */
-void vp8_encode_inter16x16y(MACROBLOCK *x)
-{
-    BLOCK *b = &x->block[0];
-
-    vp8_build_inter16x16_predictors_mby(&x->e_mbd, x->e_mbd.dst.y_buffer,
-                                        x->e_mbd.dst.y_stride);
-
-    vp8_subtract_mby(x->src_diff, *(b->base_src),
-        b->src_stride, x->e_mbd.dst.y_buffer, x->e_mbd.dst.y_stride);
-
-    transform_mby(x);
-
-    vp8_quantize_mby(x);
-
-    vp8_inverse_transform_mby(&x->e_mbd);
-}
diff --git a/vp8/encoder/encodemb.h b/vp8/encoder/encodemb.h
deleted file mode 100644 (file)
index 10b3d86..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#ifndef VP8_ENCODER_ENCODEMB_H_
-#define VP8_ENCODER_ENCODEMB_H_
-
-#include "onyx_int.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-void vp8_encode_inter16x16(MACROBLOCK *x);
-
-void vp8_subtract_b(BLOCK *be, BLOCKD *bd, int pitch);
-void vp8_subtract_mbuv(short *diff, unsigned char *usrc, unsigned char *vsrc,
-                       int src_stride, unsigned char *upred,
-                       unsigned char *vpred, int pred_stride);
-void vp8_subtract_mby(short *diff, unsigned char *src, int src_stride,
-                      unsigned char *pred, int pred_stride);
-
-void vp8_build_dcblock(MACROBLOCK *b);
-void vp8_transform_mb(MACROBLOCK *mb);
-void vp8_transform_mbuv(MACROBLOCK *x);
-void vp8_transform_intra_mby(MACROBLOCK *x);
-
-void vp8_optimize_mby(MACROBLOCK *x);
-void vp8_optimize_mbuv(MACROBLOCK *x);
-void vp8_encode_inter16x16y(MACROBLOCK *x);
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP8_ENCODER_ENCODEMB_H_
diff --git a/vp8/encoder/encodemv.c b/vp8/encoder/encodemv.c
deleted file mode 100644 (file)
index 2a74ff4..0000000
+++ /dev/null
@@ -1,380 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#include "vp8/common/common.h"
-#include "encodemv.h"
-#include "vp8/common/entropymode.h"
-#include "vp8/common/systemdependent.h"
-
-#include <math.h>
-
-#ifdef VP8_ENTROPY_STATS
-extern unsigned int active_section;
-#endif
-
-static void encode_mvcomponent(
-    vp8_writer *const w,
-    const int v,
-    const struct mv_context *mvc
-)
-{
-    const vp8_prob *p = mvc->prob;
-    const int x = v < 0 ? -v : v;
-
-    if (x < mvnum_short)     /* Small */
-    {
-        vp8_write(w, 0, p [mvpis_short]);
-        vp8_treed_write(w, vp8_small_mvtree, p + MVPshort, x, 3);
-
-        if (!x)
-            return;         /* no sign bit */
-    }
-    else                    /* Large */
-    {
-        int i = 0;
-
-        vp8_write(w, 1, p [mvpis_short]);
-
-        do
-            vp8_write(w, (x >> i) & 1, p [MVPbits + i]);
-
-        while (++i < 3);
-
-        i = mvlong_width - 1;  /* Skip bit 3, which is sometimes implicit */
-
-        do
-            vp8_write(w, (x >> i) & 1, p [MVPbits + i]);
-
-        while (--i > 3);
-
-        if (x & 0xFFF0)
-            vp8_write(w, (x >> 3) & 1, p [MVPbits + 3]);
-    }
-
-    vp8_write(w, v < 0, p [MVPsign]);
-}
-#if 0
-static int max_mv_r = 0;
-static int max_mv_c = 0;
-#endif
-void vp8_encode_motion_vector(vp8_writer *w, const MV *mv, const MV_CONTEXT *mvc)
-{
-
-#if 0
-    {
-        if (abs(mv->row >> 1) > max_mv_r)
-        {
-            FILE *f = fopen("maxmv.stt", "a");
-            max_mv_r = abs(mv->row >> 1);
-            fprintf(f, "New Mv Row Max %6d\n", (mv->row >> 1));
-
-            if ((abs(mv->row) / 2) != max_mv_r)
-                fprintf(f, "MV Row conversion error %6d\n", abs(mv->row) / 2);
-
-            fclose(f);
-        }
-
-        if (abs(mv->col >> 1) > max_mv_c)
-        {
-            FILE *f = fopen("maxmv.stt", "a");
-            fprintf(f, "New Mv Col Max %6d\n", (mv->col >> 1));
-            max_mv_c = abs(mv->col >> 1);
-            fclose(f);
-        }
-    }
-#endif
-
-    encode_mvcomponent(w, mv->row >> 1, &mvc[0]);
-    encode_mvcomponent(w, mv->col >> 1, &mvc[1]);
-}
-
-
-static unsigned int cost_mvcomponent(const int v, const struct mv_context *mvc)
-{
-    const vp8_prob *p = mvc->prob;
-    const int x = v;
-    unsigned int cost;
-
-    if (x < mvnum_short)
-    {
-        cost = vp8_cost_zero(p [mvpis_short])
-               + vp8_treed_cost(vp8_small_mvtree, p + MVPshort, x, 3);
-
-        if (!x)
-            return cost;
-    }
-    else
-    {
-        int i = 0;
-        cost = vp8_cost_one(p [mvpis_short]);
-
-        do
-            cost += vp8_cost_bit(p [MVPbits + i], (x >> i) & 1);
-
-        while (++i < 3);
-
-        i = mvlong_width - 1;  /* Skip bit 3, which is sometimes implicit */
-
-        do
-            cost += vp8_cost_bit(p [MVPbits + i], (x >> i) & 1);
-
-        while (--i > 3);
-
-        if (x & 0xFFF0)
-            cost += vp8_cost_bit(p [MVPbits + 3], (x >> 3) & 1);
-    }
-
-    return cost;   /* + vp8_cost_bit( p [MVPsign], v < 0); */
-}
-
-void vp8_build_component_cost_table(int *mvcost[2], const MV_CONTEXT *mvc, int mvc_flag[2])
-{
-    int i = 1;
-    unsigned int cost0 = 0;
-    unsigned int cost1 = 0;
-
-    vp8_clear_system_state();
-
-    i = 1;
-
-    if (mvc_flag[0])
-    {
-        mvcost [0] [0] = cost_mvcomponent(0, &mvc[0]);
-
-        do
-        {
-            cost0 = cost_mvcomponent(i, &mvc[0]);
-
-            mvcost [0] [i] = cost0 + vp8_cost_zero(mvc[0].prob[MVPsign]);
-            mvcost [0] [-i] = cost0 + vp8_cost_one(mvc[0].prob[MVPsign]);
-        }
-        while (++i <= mv_max);
-    }
-
-    i = 1;
-
-    if (mvc_flag[1])
-    {
-        mvcost [1] [0] = cost_mvcomponent(0, &mvc[1]);
-
-        do
-        {
-            cost1 = cost_mvcomponent(i, &mvc[1]);
-
-            mvcost [1] [i] = cost1 + vp8_cost_zero(mvc[1].prob[MVPsign]);
-            mvcost [1] [-i] = cost1 + vp8_cost_one(mvc[1].prob[MVPsign]);
-        }
-        while (++i <= mv_max);
-    }
-}
-
-
-/* Motion vector probability table update depends on benefit.
- * Small correction allows for the fact that an update to an MV probability
- * may have benefit in subsequent frames as well as the current one.
- */
-#define MV_PROB_UPDATE_CORRECTION   -1
-
-
-static void calc_prob(vp8_prob *p, const unsigned int ct[2])
-{
-    const unsigned int tot = ct[0] + ct[1];
-
-    if (tot)
-    {
-        const vp8_prob x = ((ct[0] * 255) / tot) & -2;
-        *p = x ? x : 1;
-    }
-}
-
-static void update(
-    vp8_writer *const w,
-    const unsigned int ct[2],
-    vp8_prob *const cur_p,
-    const vp8_prob new_p,
-    const vp8_prob update_p,
-    int *updated
-)
-{
-    const int cur_b = vp8_cost_branch(ct, *cur_p);
-    const int new_b = vp8_cost_branch(ct, new_p);
-    const int cost = 7 + MV_PROB_UPDATE_CORRECTION + ((vp8_cost_one(update_p) - vp8_cost_zero(update_p) + 128) >> 8);
-
-    if (cur_b - new_b > cost)
-    {
-        *cur_p = new_p;
-        vp8_write(w, 1, update_p);
-        vp8_write_literal(w, new_p >> 1, 7);
-        *updated = 1;
-
-    }
-    else
-        vp8_write(w, 0, update_p);
-}
-
-static void write_component_probs(
-    vp8_writer *const w,
-    struct mv_context *cur_mvc,
-    const struct mv_context *default_mvc_,
-    const struct mv_context *update_mvc,
-    const unsigned int events [MVvals],
-    unsigned int rc,
-    int *updated
-)
-{
-    vp8_prob *Pcur = cur_mvc->prob;
-    const vp8_prob *default_mvc = default_mvc_->prob;
-    const vp8_prob *Pupdate = update_mvc->prob;
-    unsigned int is_short_ct[2], sign_ct[2];
-
-    unsigned int bit_ct [mvlong_width] [2];
-
-    unsigned int short_ct  [mvnum_short];
-    unsigned int short_bct [mvnum_short-1] [2];
-
-    vp8_prob Pnew [MVPcount];
-
-    (void) rc;
-    vp8_copy_array(Pnew, default_mvc, MVPcount);
-
-    vp8_zero(is_short_ct)
-    vp8_zero(sign_ct)
-    vp8_zero(bit_ct)
-    vp8_zero(short_ct)
-    vp8_zero(short_bct)
-
-
-    /* j=0 */
-    {
-        const int c = events [mv_max];
-
-        is_short_ct [0] += c;     /* Short vector */
-        short_ct [0] += c;       /* Magnitude distribution */
-    }
-
-    /* j: 1 ~ mv_max (1023) */
-    {
-        int j = 1;
-
-        do
-        {
-            const int c1 = events [mv_max + j];  /* positive */
-            const int c2 = events [mv_max - j];  /* negative */
-            const int c  = c1 + c2;
-            int a = j;
-
-            sign_ct [0] += c1;
-            sign_ct [1] += c2;
-
-            if (a < mvnum_short)
-            {
-                is_short_ct [0] += c;     /* Short vector */
-                short_ct [a] += c;       /* Magnitude distribution */
-            }
-            else
-            {
-                int k = mvlong_width - 1;
-                is_short_ct [1] += c;     /* Long vector */
-
-                /*  bit 3 not always encoded. */
-                do
-                    bit_ct [k] [(a >> k) & 1] += c;
-
-                while (--k >= 0);
-            }
-        }
-        while (++j <= mv_max);
-    }
-
-    calc_prob(Pnew + mvpis_short, is_short_ct);
-
-    calc_prob(Pnew + MVPsign, sign_ct);
-
-    {
-        vp8_prob p [mvnum_short - 1];    /* actually only need branch ct */
-        int j = 0;
-
-        vp8_tree_probs_from_distribution(
-            8, vp8_small_mvencodings, vp8_small_mvtree,
-            p, short_bct, short_ct,
-            256, 1
-        );
-
-        do
-            calc_prob(Pnew + MVPshort + j, short_bct[j]);
-
-        while (++j < mvnum_short - 1);
-    }
-
-    {
-        int j = 0;
-
-        do
-            calc_prob(Pnew + MVPbits + j, bit_ct[j]);
-
-        while (++j < mvlong_width);
-    }
-
-    update(w, is_short_ct, Pcur + mvpis_short, Pnew[mvpis_short], *Pupdate++, updated);
-
-    update(w, sign_ct, Pcur + MVPsign, Pnew[MVPsign], *Pupdate++, updated);
-
-    {
-        const vp8_prob *const new_p = Pnew + MVPshort;
-        vp8_prob *const cur_p = Pcur + MVPshort;
-
-        int j = 0;
-
-        do
-
-            update(w, short_bct[j], cur_p + j, new_p[j], *Pupdate++, updated);
-
-        while (++j < mvnum_short - 1);
-    }
-
-    {
-        const vp8_prob *const new_p = Pnew + MVPbits;
-        vp8_prob *const cur_p = Pcur + MVPbits;
-
-        int j = 0;
-
-        do
-
-            update(w, bit_ct[j], cur_p + j, new_p[j], *Pupdate++, updated);
-
-        while (++j < mvlong_width);
-    }
-}
-
-void vp8_write_mvprobs(VP8_COMP *cpi)
-{
-    vp8_writer *const w  = cpi->bc;
-    MV_CONTEXT *mvc = cpi->common.fc.mvc;
-    int flags[2] = {0, 0};
-#ifdef VP8_ENTROPY_STATS
-    active_section = 4;
-#endif
-    write_component_probs(
-        w, &mvc[0], &vp8_default_mv_context[0], &vp8_mv_update_probs[0],
-        cpi->mb.MVcount[0], 0, &flags[0]
-    );
-    write_component_probs(
-        w, &mvc[1], &vp8_default_mv_context[1], &vp8_mv_update_probs[1],
-        cpi->mb.MVcount[1], 1, &flags[1]
-    );
-
-    if (flags[0] || flags[1])
-        vp8_build_component_cost_table(cpi->mb.mvcost, (const MV_CONTEXT *) cpi->common.fc.mvc, flags);
-
-#ifdef VP8_ENTROPY_STATS
-    active_section = 5;
-#endif
-}
diff --git a/vp8/encoder/encodemv.h b/vp8/encoder/encodemv.h
deleted file mode 100644 (file)
index 722162b..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#ifndef VP8_ENCODER_ENCODEMV_H_
-#define VP8_ENCODER_ENCODEMV_H_
-
-#include "onyx_int.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-void vp8_write_mvprobs(VP8_COMP *);
-void vp8_encode_motion_vector(vp8_writer *, const MV *, const MV_CONTEXT *);
-void vp8_build_component_cost_table(int *mvcost[2], const MV_CONTEXT *mvc, int mvc_flag[2]);
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP8_ENCODER_ENCODEMV_H_
diff --git a/vp8/encoder/ethreading.c b/vp8/encoder/ethreading.c
deleted file mode 100644 (file)
index 2a0c298..0000000
+++ /dev/null
@@ -1,679 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#include "onyx_int.h"
-#include "vp8/common/threading.h"
-#include "vp8/common/common.h"
-#include "vp8/common/extend.h"
-#include "bitstream.h"
-#include "encodeframe.h"
-
-#if CONFIG_MULTITHREAD
-
-extern void vp8cx_mb_init_quantizer(VP8_COMP *cpi, MACROBLOCK *x, int ok_to_skip);
-
-static THREAD_FUNCTION thread_loopfilter(void *p_data)
-{
-    VP8_COMP *cpi = (VP8_COMP *)(((LPFTHREAD_DATA *)p_data)->ptr1);
-    VP8_COMMON *cm = &cpi->common;
-
-    while (1)
-    {
-        if (protected_read(&cpi->mt_mutex, &cpi->b_multi_threaded) == 0)
-            break;
-
-        if (sem_wait(&cpi->h_event_start_lpf) == 0)
-        {
-            /* we're shutting down */
-            if (protected_read(&cpi->mt_mutex, &cpi->b_multi_threaded) == 0)
-                break;
-
-            vp8_loopfilter_frame(cpi, cm);
-
-            sem_post(&cpi->h_event_end_lpf);
-        }
-    }
-
-    return 0;
-}
-
-static
-THREAD_FUNCTION thread_encoding_proc(void *p_data)
-{
-    int ithread = ((ENCODETHREAD_DATA *)p_data)->ithread;
-    VP8_COMP *cpi = (VP8_COMP *)(((ENCODETHREAD_DATA *)p_data)->ptr1);
-    MB_ROW_COMP *mbri = (MB_ROW_COMP *)(((ENCODETHREAD_DATA *)p_data)->ptr2);
-    ENTROPY_CONTEXT_PLANES mb_row_left_context;
-
-    while (1)
-    {
-        if (protected_read(&cpi->mt_mutex, &cpi->b_multi_threaded) == 0)
-            break;
-
-        if (sem_wait(&cpi->h_event_start_encoding[ithread]) == 0)
-        {
-            const int nsync = cpi->mt_sync_range;
-            VP8_COMMON *cm = &cpi->common;
-            int mb_row;
-            MACROBLOCK *x = &mbri->mb;
-            MACROBLOCKD *xd = &x->e_mbd;
-            TOKENEXTRA *tp ;
-#if CONFIG_REALTIME_ONLY & CONFIG_ONTHEFLY_BITPACKING
-            TOKENEXTRA *tp_start = cpi->tok + (1 + ithread) * (16 * 24);
-            const int num_part = (1 << cm->multi_token_partition);
-#endif
-
-            int *segment_counts = mbri->segment_counts;
-            int *totalrate = &mbri->totalrate;
-
-            /* we're shutting down */
-            if (protected_read(&cpi->mt_mutex, &cpi->b_multi_threaded) == 0)
-                break;
-
-            xd->mode_info_context = cm->mi + cm->mode_info_stride *
-                (ithread + 1);
-            xd->mode_info_stride = cm->mode_info_stride;
-
-            for (mb_row = ithread + 1; mb_row < cm->mb_rows; mb_row += (cpi->encoding_thread_count + 1))
-            {
-
-                int recon_yoffset, recon_uvoffset;
-                int mb_col;
-                int ref_fb_idx = cm->lst_fb_idx;
-                int dst_fb_idx = cm->new_fb_idx;
-                int recon_y_stride = cm->yv12_fb[ref_fb_idx].y_stride;
-                int recon_uv_stride = cm->yv12_fb[ref_fb_idx].uv_stride;
-                int map_index = (mb_row * cm->mb_cols);
-                const int *last_row_current_mb_col;
-                int *current_mb_col = &cpi->mt_current_mb_col[mb_row];
-
-#if  (CONFIG_REALTIME_ONLY & CONFIG_ONTHEFLY_BITPACKING)
-                vp8_writer *w = &cpi->bc[1 + (mb_row % num_part)];
-#else
-                tp = cpi->tok + (mb_row * (cm->mb_cols * 16 * 24));
-                cpi->tplist[mb_row].start = tp;
-#endif
-
-                last_row_current_mb_col = &cpi->mt_current_mb_col[mb_row - 1];
-
-                /* reset above block coeffs */
-                xd->above_context = cm->above_context;
-                xd->left_context = &mb_row_left_context;
-
-                vp8_zero(mb_row_left_context);
-
-                xd->up_available = (mb_row != 0);
-                recon_yoffset = (mb_row * recon_y_stride * 16);
-                recon_uvoffset = (mb_row * recon_uv_stride * 8);
-
-                /* Set the mb activity pointer to the start of the row. */
-                x->mb_activity_ptr = &cpi->mb_activity_map[map_index];
-
-                /* for each macroblock col in image */
-                for (mb_col = 0; mb_col < cm->mb_cols; mb_col++)
-                {
-                    if (((mb_col - 1) % nsync) == 0) {
-                        pthread_mutex_t *mutex = &cpi->pmutex[mb_row];
-                        protected_write(mutex, current_mb_col, mb_col - 1);
-                    }
-
-                    if (mb_row && !(mb_col & (nsync - 1))) {
-                      pthread_mutex_t *mutex = &cpi->pmutex[mb_row-1];
-                      sync_read(mutex, mb_col, last_row_current_mb_col, nsync);
-                    }
-
-#if CONFIG_REALTIME_ONLY & CONFIG_ONTHEFLY_BITPACKING
-                    tp = tp_start;
-#endif
-
-                    /* Distance of Mb to the various image edges.
-                     * These specified to 8th pel as they are always compared
-                     * to values that are in 1/8th pel units
-                     */
-                    xd->mb_to_left_edge = -((mb_col * 16) << 3);
-                    xd->mb_to_right_edge = ((cm->mb_cols - 1 - mb_col) * 16) << 3;
-                    xd->mb_to_top_edge = -((mb_row * 16) << 3);
-                    xd->mb_to_bottom_edge = ((cm->mb_rows - 1 - mb_row) * 16) << 3;
-
-                    /* Set up limit values for motion vectors used to prevent
-                     * them extending outside the UMV borders
-                     */
-                    x->mv_col_min = -((mb_col * 16) + (VP8BORDERINPIXELS - 16));
-                    x->mv_col_max = ((cm->mb_cols - 1 - mb_col) * 16) + (VP8BORDERINPIXELS - 16);
-                    x->mv_row_min = -((mb_row * 16) + (VP8BORDERINPIXELS - 16));
-                    x->mv_row_max = ((cm->mb_rows - 1 - mb_row) * 16) + (VP8BORDERINPIXELS - 16);
-
-                    xd->dst.y_buffer = cm->yv12_fb[dst_fb_idx].y_buffer + recon_yoffset;
-                    xd->dst.u_buffer = cm->yv12_fb[dst_fb_idx].u_buffer + recon_uvoffset;
-                    xd->dst.v_buffer = cm->yv12_fb[dst_fb_idx].v_buffer + recon_uvoffset;
-                    xd->left_available = (mb_col != 0);
-
-                    x->rddiv = cpi->RDDIV;
-                    x->rdmult = cpi->RDMULT;
-
-                    /* Copy current mb to a buffer */
-                    vp8_copy_mem16x16(x->src.y_buffer, x->src.y_stride, x->thismb, 16);
-
-                    if (cpi->oxcf.tuning == VP8_TUNE_SSIM)
-                        vp8_activity_masking(cpi, x);
-
-                    /* Is segmentation enabled */
-                    /* MB level adjustment to quantizer */
-                    if (xd->segmentation_enabled)
-                    {
-                        /* Code to set segment id in xd->mbmi.segment_id for
-                         * current MB (with range checking)
-                         */
-                        if (cpi->segmentation_map[map_index + mb_col] <= 3)
-                            xd->mode_info_context->mbmi.segment_id = cpi->segmentation_map[map_index + mb_col];
-                        else
-                            xd->mode_info_context->mbmi.segment_id = 0;
-
-                        vp8cx_mb_init_quantizer(cpi, x, 1);
-                    }
-                    else
-                        /* Set to Segment 0 by default */
-                        xd->mode_info_context->mbmi.segment_id = 0;
-
-                    x->active_ptr = cpi->active_map + map_index + mb_col;
-
-                    if (cm->frame_type == KEY_FRAME)
-                    {
-                        *totalrate += vp8cx_encode_intra_macroblock(cpi, x, &tp);
-#ifdef MODE_STATS
-                        y_modes[xd->mbmi.mode] ++;
-#endif
-                    }
-                    else
-                    {
-                        *totalrate += vp8cx_encode_inter_macroblock(cpi, x, &tp, recon_yoffset, recon_uvoffset, mb_row, mb_col);
-
-#ifdef MODE_STATS
-                        inter_y_modes[xd->mbmi.mode] ++;
-
-                        if (xd->mbmi.mode == SPLITMV)
-                        {
-                            int b;
-
-                            for (b = 0; b < xd->mbmi.partition_count; b++)
-                            {
-                                inter_b_modes[x->partition->bmi[b].mode] ++;
-                            }
-                        }
-
-#endif
-                        // Keep track of how many (consecutive) times a  block
-                        // is coded as ZEROMV_LASTREF, for base layer frames.
-                        // Reset to 0 if its coded as anything else.
-                        if (cpi->current_layer == 0) {
-                          if (xd->mode_info_context->mbmi.mode == ZEROMV &&
-                              xd->mode_info_context->mbmi.ref_frame ==
-                                  LAST_FRAME) {
-                            // Increment, check for wrap-around.
-                            if (cpi->consec_zero_last[map_index+mb_col] < 255)
-                              cpi->consec_zero_last[map_index+mb_col] += 1;
-                            if (cpi->consec_zero_last_mvbias[map_index+mb_col] < 255)
-                              cpi->consec_zero_last_mvbias[map_index+mb_col] += 1;
-                          } else {
-                            cpi->consec_zero_last[map_index+mb_col] = 0;
-                            cpi->consec_zero_last_mvbias[map_index+mb_col] = 0;
-                          }
-                          if (x->zero_last_dot_suppress)
-                            cpi->consec_zero_last_mvbias[map_index+mb_col] = 0;
-                        }
-
-                        /* Special case code for cyclic refresh
-                         * If cyclic update enabled then copy
-                         * xd->mbmi.segment_id; (which may have been updated
-                         * based on mode during
-                         * vp8cx_encode_inter_macroblock()) back into the
-                         * global segmentation map
-                         */
-                        if ((cpi->current_layer == 0) &&
-                            (cpi->cyclic_refresh_mode_enabled &&
-                             xd->segmentation_enabled))
-                        {
-                            const MB_MODE_INFO * mbmi = &xd->mode_info_context->mbmi;
-                            cpi->segmentation_map[map_index + mb_col] = mbmi->segment_id;
-
-                            /* If the block has been refreshed mark it as clean
-                             * (the magnitude of the -ve influences how long it
-                             * will be before we consider another refresh):
-                             * Else if it was coded (last frame 0,0) and has
-                             * not already been refreshed then mark it as a
-                             * candidate for cleanup next time (marked 0) else
-                             * mark it as dirty (1).
-                             */
-                            if (mbmi->segment_id)
-                                cpi->cyclic_refresh_map[map_index + mb_col] = -1;
-                            else if ((mbmi->mode == ZEROMV) && (mbmi->ref_frame == LAST_FRAME))
-                            {
-                                if (cpi->cyclic_refresh_map[map_index + mb_col] == 1)
-                                    cpi->cyclic_refresh_map[map_index + mb_col] = 0;
-                            }
-                            else
-                                cpi->cyclic_refresh_map[map_index + mb_col] = 1;
-
-                        }
-                    }
-
-#if CONFIG_REALTIME_ONLY & CONFIG_ONTHEFLY_BITPACKING
-                    /* pack tokens for this MB */
-                    {
-                        int tok_count = tp - tp_start;
-                        vp8_pack_tokens(w, tp_start, tok_count);
-                    }
-#else
-                    cpi->tplist[mb_row].stop = tp;
-#endif
-                    /* Increment pointer into gf usage flags structure. */
-                    x->gf_active_ptr++;
-
-                    /* Increment the activity mask pointers. */
-                    x->mb_activity_ptr++;
-
-                    /* adjust to the next column of macroblocks */
-                    x->src.y_buffer += 16;
-                    x->src.u_buffer += 8;
-                    x->src.v_buffer += 8;
-
-                    recon_yoffset += 16;
-                    recon_uvoffset += 8;
-
-                    /* Keep track of segment usage */
-                    segment_counts[xd->mode_info_context->mbmi.segment_id]++;
-
-                    /* skip to next mb */
-                    xd->mode_info_context++;
-                    x->partition_info++;
-                    xd->above_context++;
-                }
-
-                vp8_extend_mb_row( &cm->yv12_fb[dst_fb_idx],
-                                    xd->dst.y_buffer + 16,
-                                    xd->dst.u_buffer + 8,
-                                    xd->dst.v_buffer + 8);
-
-                protected_write(&cpi->pmutex[mb_row], current_mb_col,
-                                mb_col + nsync);
-
-                /* this is to account for the border */
-                xd->mode_info_context++;
-                x->partition_info++;
-
-                x->src.y_buffer += 16 * x->src.y_stride * (cpi->encoding_thread_count + 1) - 16 * cm->mb_cols;
-                x->src.u_buffer += 8 * x->src.uv_stride * (cpi->encoding_thread_count + 1) - 8 * cm->mb_cols;
-                x->src.v_buffer += 8 * x->src.uv_stride * (cpi->encoding_thread_count + 1) - 8 * cm->mb_cols;
-
-                xd->mode_info_context += xd->mode_info_stride * cpi->encoding_thread_count;
-                x->partition_info += xd->mode_info_stride * cpi->encoding_thread_count;
-                x->gf_active_ptr   += cm->mb_cols * cpi->encoding_thread_count;
-
-                if (mb_row == cm->mb_rows - 1)
-                {
-                    sem_post(&cpi->h_event_end_encoding); /* signal frame encoding end */
-                }
-            }
-        }
-    }
-
-    /* printf("exit thread %d\n", ithread); */
-    return 0;
-}
-
-static void setup_mbby_copy(MACROBLOCK *mbdst, MACROBLOCK *mbsrc)
-{
-
-    MACROBLOCK *x = mbsrc;
-    MACROBLOCK *z = mbdst;
-    int i;
-
-    z->ss               = x->ss;
-    z->ss_count          = x->ss_count;
-    z->searches_per_step  = x->searches_per_step;
-    z->errorperbit      = x->errorperbit;
-
-    z->sadperbit16      = x->sadperbit16;
-    z->sadperbit4       = x->sadperbit4;
-
-    /*
-    z->mv_col_min    = x->mv_col_min;
-    z->mv_col_max    = x->mv_col_max;
-    z->mv_row_min    = x->mv_row_min;
-    z->mv_row_max    = x->mv_row_max;
-    */
-
-    z->short_fdct4x4     = x->short_fdct4x4;
-    z->short_fdct8x4     = x->short_fdct8x4;
-    z->short_walsh4x4    = x->short_walsh4x4;
-    z->quantize_b        = x->quantize_b;
-    z->optimize          = x->optimize;
-
-    /*
-    z->mvc              = x->mvc;
-    z->src.y_buffer      = x->src.y_buffer;
-    z->src.u_buffer      = x->src.u_buffer;
-    z->src.v_buffer      = x->src.v_buffer;
-    */
-
-    z->mvcost[0] =  x->mvcost[0];
-    z->mvcost[1] =  x->mvcost[1];
-    z->mvsadcost[0] =  x->mvsadcost[0];
-    z->mvsadcost[1] =  x->mvsadcost[1];
-
-    z->token_costs = x->token_costs;
-    z->inter_bmode_costs = x->inter_bmode_costs;
-    z->mbmode_cost = x->mbmode_cost;
-    z->intra_uv_mode_cost = x->intra_uv_mode_cost;
-    z->bmode_costs = x->bmode_costs;
-
-    for (i = 0; i < 25; i++)
-    {
-        z->block[i].quant           = x->block[i].quant;
-        z->block[i].quant_fast      = x->block[i].quant_fast;
-        z->block[i].quant_shift     = x->block[i].quant_shift;
-        z->block[i].zbin            = x->block[i].zbin;
-        z->block[i].zrun_zbin_boost = x->block[i].zrun_zbin_boost;
-        z->block[i].round           = x->block[i].round;
-        z->block[i].src_stride      = x->block[i].src_stride;
-    }
-
-    z->q_index           = x->q_index;
-    z->act_zbin_adj      = x->act_zbin_adj;
-    z->last_act_zbin_adj = x->last_act_zbin_adj;
-
-    {
-        MACROBLOCKD *xd = &x->e_mbd;
-        MACROBLOCKD *zd = &z->e_mbd;
-
-        /*
-        zd->mode_info_context = xd->mode_info_context;
-        zd->mode_info        = xd->mode_info;
-
-        zd->mode_info_stride  = xd->mode_info_stride;
-        zd->frame_type       = xd->frame_type;
-        zd->up_available     = xd->up_available   ;
-        zd->left_available   = xd->left_available;
-        zd->left_context     = xd->left_context;
-        zd->last_frame_dc     = xd->last_frame_dc;
-        zd->last_frame_dccons = xd->last_frame_dccons;
-        zd->gold_frame_dc     = xd->gold_frame_dc;
-        zd->gold_frame_dccons = xd->gold_frame_dccons;
-        zd->mb_to_left_edge    = xd->mb_to_left_edge;
-        zd->mb_to_right_edge   = xd->mb_to_right_edge;
-        zd->mb_to_top_edge     = xd->mb_to_top_edge   ;
-        zd->mb_to_bottom_edge  = xd->mb_to_bottom_edge;
-        zd->gf_active_ptr     = xd->gf_active_ptr;
-        zd->frames_since_golden       = xd->frames_since_golden;
-        zd->frames_till_alt_ref_frame   = xd->frames_till_alt_ref_frame;
-        */
-        zd->subpixel_predict         = xd->subpixel_predict;
-        zd->subpixel_predict8x4      = xd->subpixel_predict8x4;
-        zd->subpixel_predict8x8      = xd->subpixel_predict8x8;
-        zd->subpixel_predict16x16    = xd->subpixel_predict16x16;
-        zd->segmentation_enabled     = xd->segmentation_enabled;
-        zd->mb_segement_abs_delta      = xd->mb_segement_abs_delta;
-        memcpy(zd->segment_feature_data, xd->segment_feature_data,
-               sizeof(xd->segment_feature_data));
-
-        memcpy(zd->dequant_y1_dc, xd->dequant_y1_dc, sizeof(xd->dequant_y1_dc));
-        memcpy(zd->dequant_y1, xd->dequant_y1, sizeof(xd->dequant_y1));
-        memcpy(zd->dequant_y2, xd->dequant_y2, sizeof(xd->dequant_y2));
-        memcpy(zd->dequant_uv, xd->dequant_uv, sizeof(xd->dequant_uv));
-
-#if 1
-        /*TODO:  Remove dequant from BLOCKD.  This is a temporary solution until
-         * the quantizer code uses a passed in pointer to the dequant constants.
-         * This will also require modifications to the x86 and neon assembly.
-         * */
-        for (i = 0; i < 16; i++)
-            zd->block[i].dequant = zd->dequant_y1;
-        for (i = 16; i < 24; i++)
-            zd->block[i].dequant = zd->dequant_uv;
-        zd->block[24].dequant = zd->dequant_y2;
-#endif
-
-
-        memcpy(z->rd_threshes, x->rd_threshes, sizeof(x->rd_threshes));
-        memcpy(z->rd_thresh_mult, x->rd_thresh_mult, sizeof(x->rd_thresh_mult));
-
-        z->zbin_over_quant = x->zbin_over_quant;
-        z->zbin_mode_boost_enabled = x->zbin_mode_boost_enabled;
-        z->zbin_mode_boost = x->zbin_mode_boost;
-
-        memset(z->error_bins, 0, sizeof(z->error_bins));
-    }
-}
-
-void vp8cx_init_mbrthread_data(VP8_COMP *cpi,
-                               MACROBLOCK *x,
-                               MB_ROW_COMP *mbr_ei,
-                               int count
-                              )
-{
-
-    VP8_COMMON *const cm = & cpi->common;
-    MACROBLOCKD *const xd = & x->e_mbd;
-    int i;
-
-    for (i = 0; i < count; i++)
-    {
-        MACROBLOCK *mb = & mbr_ei[i].mb;
-        MACROBLOCKD *mbd = &mb->e_mbd;
-
-        mbd->subpixel_predict        = xd->subpixel_predict;
-        mbd->subpixel_predict8x4     = xd->subpixel_predict8x4;
-        mbd->subpixel_predict8x8     = xd->subpixel_predict8x8;
-        mbd->subpixel_predict16x16   = xd->subpixel_predict16x16;
-        mb->gf_active_ptr            = x->gf_active_ptr;
-
-        memset(mbr_ei[i].segment_counts, 0, sizeof(mbr_ei[i].segment_counts));
-        mbr_ei[i].totalrate = 0;
-
-        mb->partition_info = x->pi + x->e_mbd.mode_info_stride * (i + 1);
-
-        mbd->frame_type = cm->frame_type;
-
-        mb->src = * cpi->Source;
-        mbd->pre = cm->yv12_fb[cm->lst_fb_idx];
-        mbd->dst = cm->yv12_fb[cm->new_fb_idx];
-
-        mb->src.y_buffer += 16 * x->src.y_stride * (i + 1);
-        mb->src.u_buffer +=  8 * x->src.uv_stride * (i + 1);
-        mb->src.v_buffer +=  8 * x->src.uv_stride * (i + 1);
-
-        vp8_build_block_offsets(mb);
-
-        mbd->left_context = &cm->left_context;
-        mb->mvc = cm->fc.mvc;
-
-        setup_mbby_copy(&mbr_ei[i].mb, x);
-
-        mbd->fullpixel_mask = 0xffffffff;
-        if(cm->full_pixel)
-            mbd->fullpixel_mask = 0xfffffff8;
-
-        vp8_zero(mb->coef_counts);
-        vp8_zero(x->ymode_count);
-        mb->skip_true_count = 0;
-        vp8_zero(mb->MVcount);
-        mb->prediction_error = 0;
-        mb->intra_error = 0;
-        vp8_zero(mb->count_mb_ref_frame_usage);
-        mb->mbs_tested_so_far = 0;
-        mb->mbs_zero_last_dot_suppress = 0;
-    }
-}
-
-int vp8cx_create_encoder_threads(VP8_COMP *cpi)
-{
-    const VP8_COMMON * cm = &cpi->common;
-
-    cpi->b_multi_threaded = 0;
-    cpi->encoding_thread_count = 0;
-
-    pthread_mutex_init(&cpi->mt_mutex, NULL);
-
-    if (cm->processor_core_count > 1 && cpi->oxcf.multi_threaded > 1)
-    {
-        int ithread;
-        int th_count = cpi->oxcf.multi_threaded - 1;
-        int rc = 0;
-
-        /* don't allocate more threads than cores available */
-        if (cpi->oxcf.multi_threaded > cm->processor_core_count)
-            th_count = cm->processor_core_count - 1;
-
-        /* we have th_count + 1 (main) threads processing one row each */
-        /* no point to have more threads than the sync range allows */
-        if(th_count > ((cm->mb_cols / cpi->mt_sync_range) - 1))
-        {
-            th_count = (cm->mb_cols / cpi->mt_sync_range) - 1;
-        }
-
-        if(th_count == 0)
-            return 0;
-
-        CHECK_MEM_ERROR(cpi->h_encoding_thread,
-                        vpx_malloc(sizeof(pthread_t) * th_count));
-        CHECK_MEM_ERROR(cpi->h_event_start_encoding,
-                        vpx_malloc(sizeof(sem_t) * th_count));
-        CHECK_MEM_ERROR(cpi->mb_row_ei,
-                        vpx_memalign(32, sizeof(MB_ROW_COMP) * th_count));
-        memset(cpi->mb_row_ei, 0, sizeof(MB_ROW_COMP) * th_count);
-        CHECK_MEM_ERROR(cpi->en_thread_data,
-                        vpx_malloc(sizeof(ENCODETHREAD_DATA) * th_count));
-
-        sem_init(&cpi->h_event_end_encoding, 0, 0);
-
-        cpi->b_multi_threaded = 1;
-        cpi->encoding_thread_count = th_count;
-
-        /*
-        printf("[VP8:] multi_threaded encoding is enabled with %d threads\n\n",
-               (cpi->encoding_thread_count +1));
-        */
-
-        for (ithread = 0; ithread < th_count; ithread++)
-        {
-            ENCODETHREAD_DATA *ethd = &cpi->en_thread_data[ithread];
-
-            /* Setup block ptrs and offsets */
-            vp8_setup_block_ptrs(&cpi->mb_row_ei[ithread].mb);
-            vp8_setup_block_dptrs(&cpi->mb_row_ei[ithread].mb.e_mbd);
-
-            sem_init(&cpi->h_event_start_encoding[ithread], 0, 0);
-
-            ethd->ithread = ithread;
-            ethd->ptr1 = (void *)cpi;
-            ethd->ptr2 = (void *)&cpi->mb_row_ei[ithread];
-
-            rc = pthread_create(&cpi->h_encoding_thread[ithread], 0,
-                                thread_encoding_proc, ethd);
-            if(rc)
-                break;
-        }
-
-        if(rc)
-        {
-            /* shutdown other threads */
-            protected_write(&cpi->mt_mutex, &cpi->b_multi_threaded, 0);
-            for(--ithread; ithread >= 0; ithread--)
-            {
-                pthread_join(cpi->h_encoding_thread[ithread], 0);
-                sem_destroy(&cpi->h_event_start_encoding[ithread]);
-            }
-            sem_destroy(&cpi->h_event_end_encoding);
-
-            /* free thread related resources */
-            vpx_free(cpi->h_event_start_encoding);
-            vpx_free(cpi->h_encoding_thread);
-            vpx_free(cpi->mb_row_ei);
-            vpx_free(cpi->en_thread_data);
-
-            pthread_mutex_destroy(&cpi->mt_mutex);
-
-            return -1;
-        }
-
-
-        {
-            LPFTHREAD_DATA * lpfthd = &cpi->lpf_thread_data;
-
-            sem_init(&cpi->h_event_start_lpf, 0, 0);
-            sem_init(&cpi->h_event_end_lpf, 0, 0);
-
-            lpfthd->ptr1 = (void *)cpi;
-            rc = pthread_create(&cpi->h_filter_thread, 0, thread_loopfilter,
-                                lpfthd);
-
-            if(rc)
-            {
-                /* shutdown other threads */
-                protected_write(&cpi->mt_mutex, &cpi->b_multi_threaded, 0);
-                for(--ithread; ithread >= 0; ithread--)
-                {
-                    sem_post(&cpi->h_event_start_encoding[ithread]);
-                    pthread_join(cpi->h_encoding_thread[ithread], 0);
-                    sem_destroy(&cpi->h_event_start_encoding[ithread]);
-                }
-                sem_destroy(&cpi->h_event_end_encoding);
-                sem_destroy(&cpi->h_event_end_lpf);
-                sem_destroy(&cpi->h_event_start_lpf);
-
-                /* free thread related resources */
-                vpx_free(cpi->h_event_start_encoding);
-                vpx_free(cpi->h_encoding_thread);
-                vpx_free(cpi->mb_row_ei);
-                vpx_free(cpi->en_thread_data);
-
-                pthread_mutex_destroy(&cpi->mt_mutex);
-
-                return -2;
-            }
-        }
-    }
-    return 0;
-}
-
-void vp8cx_remove_encoder_threads(VP8_COMP *cpi)
-{
-    if (protected_read(&cpi->mt_mutex, &cpi->b_multi_threaded))
-    {
-        /* shutdown other threads */
-        protected_write(&cpi->mt_mutex, &cpi->b_multi_threaded, 0);
-        {
-            int i;
-
-            for (i = 0; i < cpi->encoding_thread_count; i++)
-            {
-                sem_post(&cpi->h_event_start_encoding[i]);
-                pthread_join(cpi->h_encoding_thread[i], 0);
-
-                sem_destroy(&cpi->h_event_start_encoding[i]);
-            }
-
-            sem_post(&cpi->h_event_start_lpf);
-            pthread_join(cpi->h_filter_thread, 0);
-        }
-
-        sem_destroy(&cpi->h_event_end_encoding);
-        sem_destroy(&cpi->h_event_end_lpf);
-        sem_destroy(&cpi->h_event_start_lpf);
-
-        /* free thread related resources */
-        vpx_free(cpi->h_event_start_encoding);
-        vpx_free(cpi->h_encoding_thread);
-        vpx_free(cpi->mb_row_ei);
-        vpx_free(cpi->en_thread_data);
-    }
-    pthread_mutex_destroy(&cpi->mt_mutex);
-}
-#endif
diff --git a/vp8/encoder/firstpass.c b/vp8/encoder/firstpass.c
deleted file mode 100644 (file)
index c526a3e..0000000
+++ /dev/null
@@ -1,3372 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#include <math.h>
-#include <limits.h>
-#include <stdio.h>
-
-#include "./vpx_dsp_rtcd.h"
-#include "./vpx_scale_rtcd.h"
-#include "block.h"
-#include "onyx_int.h"
-#include "vpx_dsp/variance.h"
-#include "encodeintra.h"
-#include "vp8/common/common.h"
-#include "vp8/common/setupintrarecon.h"
-#include "vp8/common/systemdependent.h"
-#include "mcomp.h"
-#include "firstpass.h"
-#include "vpx_scale/vpx_scale.h"
-#include "encodemb.h"
-#include "vp8/common/extend.h"
-#include "vpx_mem/vpx_mem.h"
-#include "vp8/common/swapyv12buffer.h"
-#include "rdopt.h"
-#include "vp8/common/quant_common.h"
-#include "encodemv.h"
-#include "encodeframe.h"
-
-/* #define OUTPUT_FPF 1 */
-
-extern void vp8cx_frame_init_quantizer(VP8_COMP *cpi);
-
-#define GFQ_ADJUSTMENT vp8_gf_boost_qadjustment[Q]
-extern int vp8_kf_boost_qadjustment[QINDEX_RANGE];
-
-extern const int vp8_gf_boost_qadjustment[QINDEX_RANGE];
-
-#define IIFACTOR   1.5
-#define IIKFACTOR1 1.40
-#define IIKFACTOR2 1.5
-#define RMAX       14.0
-#define GF_RMAX    48.0
-
-#define KF_MB_INTRA_MIN 300
-#define GF_MB_INTRA_MIN 200
-
-#define DOUBLE_DIVIDE_CHECK(X) ((X)<0?(X)-.000001:(X)+.000001)
-
-#define POW1 (double)cpi->oxcf.two_pass_vbrbias/100.0
-#define POW2 (double)cpi->oxcf.two_pass_vbrbias/100.0
-
-#define NEW_BOOST 1
-
-static int vscale_lookup[7] = {0, 1, 1, 2, 2, 3, 3};
-static int hscale_lookup[7] = {0, 0, 1, 1, 2, 2, 3};
-
-
-static const int cq_level[QINDEX_RANGE] =
-{
-    0,0,1,1,2,3,3,4,4,5,6,6,7,8,8,9,
-    9,10,11,11,12,13,13,14,15,15,16,17,17,18,19,20,
-    20,21,22,22,23,24,24,25,26,27,27,28,29,30,30,31,
-    32,33,33,34,35,36,36,37,38,39,39,40,41,42,42,43,
-    44,45,46,46,47,48,49,50,50,51,52,53,54,55,55,56,
-    57,58,59,60,60,61,62,63,64,65,66,67,67,68,69,70,
-    71,72,73,74,75,75,76,77,78,79,80,81,82,83,84,85,
-    86,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100
-};
-
-static void find_next_key_frame(VP8_COMP *cpi, FIRSTPASS_STATS *this_frame);
-
-/* Resets the first pass file to the given position using a relative seek
- * from the current position
- */
-static void reset_fpf_position(VP8_COMP *cpi, FIRSTPASS_STATS *Position)
-{
-    cpi->twopass.stats_in = Position;
-}
-
-static int lookup_next_frame_stats(VP8_COMP *cpi, FIRSTPASS_STATS *next_frame)
-{
-    if (cpi->twopass.stats_in >= cpi->twopass.stats_in_end)
-        return EOF;
-
-    *next_frame = *cpi->twopass.stats_in;
-    return 1;
-}
-
-/* Read frame stats at an offset from the current position */
-static int read_frame_stats( VP8_COMP *cpi,
-                             FIRSTPASS_STATS *frame_stats,
-                             int offset )
-{
-    FIRSTPASS_STATS * fps_ptr = cpi->twopass.stats_in;
-
-    /* Check legality of offset */
-    if ( offset >= 0 )
-    {
-        if ( &fps_ptr[offset] >= cpi->twopass.stats_in_end )
-             return EOF;
-    }
-    else if ( offset < 0 )
-    {
-        if ( &fps_ptr[offset] < cpi->twopass.stats_in_start )
-             return EOF;
-    }
-
-    *frame_stats = fps_ptr[offset];
-    return 1;
-}
-
-static int input_stats(VP8_COMP *cpi, FIRSTPASS_STATS *fps)
-{
-    if (cpi->twopass.stats_in >= cpi->twopass.stats_in_end)
-        return EOF;
-
-    *fps = *cpi->twopass.stats_in;
-    cpi->twopass.stats_in =
-         (void*)((char *)cpi->twopass.stats_in + sizeof(FIRSTPASS_STATS));
-    return 1;
-}
-
-static void output_stats(const VP8_COMP            *cpi,
-                         struct vpx_codec_pkt_list *pktlist,
-                         FIRSTPASS_STATS            *stats)
-{
-    struct vpx_codec_cx_pkt pkt;
-    (void)cpi;
-    pkt.kind = VPX_CODEC_STATS_PKT;
-    pkt.data.twopass_stats.buf = stats;
-    pkt.data.twopass_stats.sz = sizeof(FIRSTPASS_STATS);
-    vpx_codec_pkt_list_add(pktlist, &pkt);
-
-/* TEMP debug code */
-#if OUTPUT_FPF
-
-    {
-        FILE *fpfile;
-        fpfile = fopen("firstpass.stt", "a");
-
-        fprintf(fpfile, "%12.0f %12.0f %12.0f %12.4f %12.4f %12.4f %12.4f"
-                " %12.4f %12.4f %12.4f %12.4f %12.4f %12.4f %12.4f %12.4f"
-                " %12.0f %12.0f %12.4f\n",
-                stats->frame,
-                stats->intra_error,
-                stats->coded_error,
-                stats->ssim_weighted_pred_err,
-                stats->pcnt_inter,
-                stats->pcnt_motion,
-                stats->pcnt_second_ref,
-                stats->pcnt_neutral,
-                stats->MVr,
-                stats->mvr_abs,
-                stats->MVc,
-                stats->mvc_abs,
-                stats->MVrv,
-                stats->MVcv,
-                stats->mv_in_out_count,
-                stats->new_mv_count,
-                stats->count,
-                stats->duration);
-        fclose(fpfile);
-    }
-#endif
-}
-
-static void zero_stats(FIRSTPASS_STATS *section)
-{
-    section->frame      = 0.0;
-    section->intra_error = 0.0;
-    section->coded_error = 0.0;
-    section->ssim_weighted_pred_err = 0.0;
-    section->pcnt_inter  = 0.0;
-    section->pcnt_motion  = 0.0;
-    section->pcnt_second_ref = 0.0;
-    section->pcnt_neutral = 0.0;
-    section->MVr        = 0.0;
-    section->mvr_abs     = 0.0;
-    section->MVc        = 0.0;
-    section->mvc_abs     = 0.0;
-    section->MVrv       = 0.0;
-    section->MVcv       = 0.0;
-    section->mv_in_out_count  = 0.0;
-    section->new_mv_count = 0.0;
-    section->count      = 0.0;
-    section->duration   = 1.0;
-}
-
-static void accumulate_stats(FIRSTPASS_STATS *section, FIRSTPASS_STATS *frame)
-{
-    section->frame += frame->frame;
-    section->intra_error += frame->intra_error;
-    section->coded_error += frame->coded_error;
-    section->ssim_weighted_pred_err += frame->ssim_weighted_pred_err;
-    section->pcnt_inter  += frame->pcnt_inter;
-    section->pcnt_motion += frame->pcnt_motion;
-    section->pcnt_second_ref += frame->pcnt_second_ref;
-    section->pcnt_neutral += frame->pcnt_neutral;
-    section->MVr        += frame->MVr;
-    section->mvr_abs     += frame->mvr_abs;
-    section->MVc        += frame->MVc;
-    section->mvc_abs     += frame->mvc_abs;
-    section->MVrv       += frame->MVrv;
-    section->MVcv       += frame->MVcv;
-    section->mv_in_out_count  += frame->mv_in_out_count;
-    section->new_mv_count += frame->new_mv_count;
-    section->count      += frame->count;
-    section->duration   += frame->duration;
-}
-
-static void subtract_stats(FIRSTPASS_STATS *section, FIRSTPASS_STATS *frame)
-{
-    section->frame -= frame->frame;
-    section->intra_error -= frame->intra_error;
-    section->coded_error -= frame->coded_error;
-    section->ssim_weighted_pred_err -= frame->ssim_weighted_pred_err;
-    section->pcnt_inter  -= frame->pcnt_inter;
-    section->pcnt_motion -= frame->pcnt_motion;
-    section->pcnt_second_ref -= frame->pcnt_second_ref;
-    section->pcnt_neutral -= frame->pcnt_neutral;
-    section->MVr        -= frame->MVr;
-    section->mvr_abs     -= frame->mvr_abs;
-    section->MVc        -= frame->MVc;
-    section->mvc_abs     -= frame->mvc_abs;
-    section->MVrv       -= frame->MVrv;
-    section->MVcv       -= frame->MVcv;
-    section->mv_in_out_count  -= frame->mv_in_out_count;
-    section->new_mv_count -= frame->new_mv_count;
-    section->count      -= frame->count;
-    section->duration   -= frame->duration;
-}
-
-static void avg_stats(FIRSTPASS_STATS *section)
-{
-    if (section->count < 1.0)
-        return;
-
-    section->intra_error /= section->count;
-    section->coded_error /= section->count;
-    section->ssim_weighted_pred_err /= section->count;
-    section->pcnt_inter  /= section->count;
-    section->pcnt_second_ref /= section->count;
-    section->pcnt_neutral /= section->count;
-    section->pcnt_motion /= section->count;
-    section->MVr        /= section->count;
-    section->mvr_abs     /= section->count;
-    section->MVc        /= section->count;
-    section->mvc_abs     /= section->count;
-    section->MVrv       /= section->count;
-    section->MVcv       /= section->count;
-    section->mv_in_out_count   /= section->count;
-    section->duration   /= section->count;
-}
-
-/* Calculate a modified Error used in distributing bits between easier
- * and harder frames
- */
-static double calculate_modified_err(VP8_COMP *cpi, FIRSTPASS_STATS *this_frame)
-{
-    double av_err = ( cpi->twopass.total_stats.ssim_weighted_pred_err /
-                      cpi->twopass.total_stats.count );
-    double this_err = this_frame->ssim_weighted_pred_err;
-    double modified_err;
-
-    if (this_err > av_err)
-        modified_err = av_err * pow((this_err / DOUBLE_DIVIDE_CHECK(av_err)), POW1);
-    else
-        modified_err = av_err * pow((this_err / DOUBLE_DIVIDE_CHECK(av_err)), POW2);
-
-    return modified_err;
-}
-
-static const double weight_table[256] = {
-0.020000, 0.020000, 0.020000, 0.020000, 0.020000, 0.020000, 0.020000, 0.020000,
-0.020000, 0.020000, 0.020000, 0.020000, 0.020000, 0.020000, 0.020000, 0.020000,
-0.020000, 0.020000, 0.020000, 0.020000, 0.020000, 0.020000, 0.020000, 0.020000,
-0.020000, 0.020000, 0.020000, 0.020000, 0.020000, 0.020000, 0.020000, 0.020000,
-0.020000, 0.031250, 0.062500, 0.093750, 0.125000, 0.156250, 0.187500, 0.218750,
-0.250000, 0.281250, 0.312500, 0.343750, 0.375000, 0.406250, 0.437500, 0.468750,
-0.500000, 0.531250, 0.562500, 0.593750, 0.625000, 0.656250, 0.687500, 0.718750,
-0.750000, 0.781250, 0.812500, 0.843750, 0.875000, 0.906250, 0.937500, 0.968750,
-1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000,
-1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000,
-1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000,
-1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000,
-1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000,
-1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000,
-1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000,
-1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000,
-1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000,
-1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000,
-1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000,
-1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000,
-1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000,
-1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000,
-1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000,
-1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000,
-1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000,
-1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000,
-1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000,
-1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000,
-1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000,
-1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000,
-1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000,
-1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000
-};
-
-static double simple_weight(YV12_BUFFER_CONFIG *source)
-{
-    int i, j;
-
-    unsigned char *src = source->y_buffer;
-    double sum_weights = 0.0;
-
-    /* Loop throught the Y plane raw examining levels and creating a weight
-     * for the image
-     */
-    i = source->y_height;
-    do
-    {
-        j = source->y_width;
-        do
-        {
-            sum_weights += weight_table[ *src];
-            src++;
-        }while(--j);
-        src -= source->y_width;
-        src += source->y_stride;
-    }while(--i);
-
-    sum_weights /= (source->y_height * source->y_width);
-
-    return sum_weights;
-}
-
-
-/* This function returns the current per frame maximum bitrate target */
-static int frame_max_bits(VP8_COMP *cpi)
-{
-    /* Max allocation for a single frame based on the max section guidelines
-     * passed in and how many bits are left
-     */
-    int max_bits;
-
-    /* For CBR we need to also consider buffer fullness.
-     * If we are running below the optimal level then we need to gradually
-     * tighten up on max_bits.
-     */
-    if (cpi->oxcf.end_usage == USAGE_STREAM_FROM_SERVER)
-    {
-        double buffer_fullness_ratio = (double)cpi->buffer_level / DOUBLE_DIVIDE_CHECK((double)cpi->oxcf.optimal_buffer_level);
-
-        /* For CBR base this on the target average bits per frame plus the
-         * maximum sedction rate passed in by the user
-         */
-        max_bits = (int)(cpi->av_per_frame_bandwidth * ((double)cpi->oxcf.two_pass_vbrmax_section / 100.0));
-
-        /* If our buffer is below the optimum level */
-        if (buffer_fullness_ratio < 1.0)
-        {
-            /* The lower of max_bits / 4 or cpi->av_per_frame_bandwidth / 4. */
-            int min_max_bits = ((cpi->av_per_frame_bandwidth >> 2) < (max_bits >> 2)) ? cpi->av_per_frame_bandwidth >> 2 : max_bits >> 2;
-
-            max_bits = (int)(max_bits * buffer_fullness_ratio);
-
-            /* Lowest value we will set ... which should allow the buffer to
-             * refill.
-             */
-            if (max_bits < min_max_bits)
-                max_bits = min_max_bits;
-        }
-    }
-    /* VBR */
-    else
-    {
-        /* For VBR base this on the bits and frames left plus the
-         * two_pass_vbrmax_section rate passed in by the user
-         */
-        max_bits = (int)(((double)cpi->twopass.bits_left / (cpi->twopass.total_stats.count - (double)cpi->common.current_video_frame)) * ((double)cpi->oxcf.two_pass_vbrmax_section / 100.0));
-    }
-
-    /* Trap case where we are out of bits */
-    if (max_bits < 0)
-        max_bits = 0;
-
-    return max_bits;
-}
-
-void vp8_init_first_pass(VP8_COMP *cpi)
-{
-    zero_stats(&cpi->twopass.total_stats);
-}
-
-void vp8_end_first_pass(VP8_COMP *cpi)
-{
-    output_stats(cpi, cpi->output_pkt_list, &cpi->twopass.total_stats);
-}
-
-static void zz_motion_search( VP8_COMP *cpi, MACROBLOCK * x,
-                              YV12_BUFFER_CONFIG * raw_buffer,
-                              int * raw_motion_err,
-                              YV12_BUFFER_CONFIG * recon_buffer,
-                              int * best_motion_err, int recon_yoffset)
-{
-    MACROBLOCKD * const xd = & x->e_mbd;
-    BLOCK *b = &x->block[0];
-    BLOCKD *d = &x->e_mbd.block[0];
-
-    unsigned char *src_ptr = (*(b->base_src) + b->src);
-    int src_stride = b->src_stride;
-    unsigned char *raw_ptr;
-    int raw_stride = raw_buffer->y_stride;
-    unsigned char *ref_ptr;
-    int ref_stride = x->e_mbd.pre.y_stride;
-    (void)cpi;
-
-    /* Set up pointers for this macro block raw buffer */
-    raw_ptr = (unsigned char *)(raw_buffer->y_buffer + recon_yoffset
-                                + d->offset);
-    vpx_mse16x16(src_ptr, src_stride, raw_ptr, raw_stride,
-                 (unsigned int *)(raw_motion_err));
-
-    /* Set up pointers for this macro block recon buffer */
-    xd->pre.y_buffer = recon_buffer->y_buffer + recon_yoffset;
-    ref_ptr = (unsigned char *)(xd->pre.y_buffer + d->offset );
-    vpx_mse16x16(src_ptr, src_stride, ref_ptr, ref_stride,
-                 (unsigned int *)(best_motion_err));
-}
-
-static void first_pass_motion_search(VP8_COMP *cpi, MACROBLOCK *x,
-                                     int_mv *ref_mv, MV *best_mv,
-                                     YV12_BUFFER_CONFIG *recon_buffer,
-                                     int *best_motion_err, int recon_yoffset )
-{
-    MACROBLOCKD *const xd = & x->e_mbd;
-    BLOCK *b = &x->block[0];
-    BLOCKD *d = &x->e_mbd.block[0];
-    int num00;
-
-    int_mv tmp_mv;
-    int_mv ref_mv_full;
-
-    int tmp_err;
-    int step_param = 3; /* Dont search over full range for first pass */
-    int further_steps = (MAX_MVSEARCH_STEPS - 1) - step_param;
-    int n;
-    vp8_variance_fn_ptr_t v_fn_ptr = cpi->fn_ptr[BLOCK_16X16];
-    int new_mv_mode_penalty = 256;
-
-    /* override the default variance function to use MSE */
-    v_fn_ptr.vf    = vpx_mse16x16;
-
-    /* Set up pointers for this macro block recon buffer */
-    xd->pre.y_buffer = recon_buffer->y_buffer + recon_yoffset;
-
-    /* Initial step/diamond search centred on best mv */
-    tmp_mv.as_int = 0;
-    ref_mv_full.as_mv.col = ref_mv->as_mv.col>>3;
-    ref_mv_full.as_mv.row = ref_mv->as_mv.row>>3;
-    tmp_err = cpi->diamond_search_sad(x, b, d, &ref_mv_full, &tmp_mv, step_param,
-                                      x->sadperbit16, &num00, &v_fn_ptr,
-                                      x->mvcost, ref_mv);
-    if ( tmp_err < INT_MAX-new_mv_mode_penalty )
-        tmp_err += new_mv_mode_penalty;
-
-    if (tmp_err < *best_motion_err)
-    {
-        *best_motion_err = tmp_err;
-        best_mv->row = tmp_mv.as_mv.row;
-        best_mv->col = tmp_mv.as_mv.col;
-    }
-
-    /* Further step/diamond searches as necessary */
-    n = num00;
-    num00 = 0;
-
-    while (n < further_steps)
-    {
-        n++;
-
-        if (num00)
-            num00--;
-        else
-        {
-            tmp_err = cpi->diamond_search_sad(x, b, d, &ref_mv_full, &tmp_mv,
-                                              step_param + n, x->sadperbit16,
-                                              &num00, &v_fn_ptr, x->mvcost,
-                                              ref_mv);
-            if ( tmp_err < INT_MAX-new_mv_mode_penalty )
-                tmp_err += new_mv_mode_penalty;
-
-            if (tmp_err < *best_motion_err)
-            {
-                *best_motion_err = tmp_err;
-                best_mv->row = tmp_mv.as_mv.row;
-                best_mv->col = tmp_mv.as_mv.col;
-            }
-        }
-    }
-}
-
-void vp8_first_pass(VP8_COMP *cpi)
-{
-    int mb_row, mb_col;
-    MACROBLOCK *const x = & cpi->mb;
-    VP8_COMMON *const cm = & cpi->common;
-    MACROBLOCKD *const xd = & x->e_mbd;
-
-    int recon_yoffset, recon_uvoffset;
-    YV12_BUFFER_CONFIG *lst_yv12 = &cm->yv12_fb[cm->lst_fb_idx];
-    YV12_BUFFER_CONFIG *new_yv12 = &cm->yv12_fb[cm->new_fb_idx];
-    YV12_BUFFER_CONFIG *gld_yv12 = &cm->yv12_fb[cm->gld_fb_idx];
-    int recon_y_stride = lst_yv12->y_stride;
-    int recon_uv_stride = lst_yv12->uv_stride;
-    int64_t intra_error = 0;
-    int64_t coded_error = 0;
-
-    int sum_mvr = 0, sum_mvc = 0;
-    int sum_mvr_abs = 0, sum_mvc_abs = 0;
-    int sum_mvrs = 0, sum_mvcs = 0;
-    int mvcount = 0;
-    int intercount = 0;
-    int second_ref_count = 0;
-    int intrapenalty = 256;
-    int neutral_count = 0;
-    int new_mv_count = 0;
-    int sum_in_vectors = 0;
-    uint32_t lastmv_as_int = 0;
-
-    int_mv zero_ref_mv;
-
-    zero_ref_mv.as_int = 0;
-
-    vp8_clear_system_state();
-
-    x->src = * cpi->Source;
-    xd->pre = *lst_yv12;
-    xd->dst = *new_yv12;
-
-    x->partition_info = x->pi;
-
-    xd->mode_info_context = cm->mi;
-
-    if(!cm->use_bilinear_mc_filter)
-    {
-         xd->subpixel_predict        = vp8_sixtap_predict4x4;
-         xd->subpixel_predict8x4     = vp8_sixtap_predict8x4;
-         xd->subpixel_predict8x8     = vp8_sixtap_predict8x8;
-         xd->subpixel_predict16x16   = vp8_sixtap_predict16x16;
-     }
-     else
-     {
-         xd->subpixel_predict        = vp8_bilinear_predict4x4;
-         xd->subpixel_predict8x4     = vp8_bilinear_predict8x4;
-         xd->subpixel_predict8x8     = vp8_bilinear_predict8x8;
-         xd->subpixel_predict16x16   = vp8_bilinear_predict16x16;
-     }
-
-    vp8_build_block_offsets(x);
-
-    /* set up frame new frame for intra coded blocks */
-    vp8_setup_intra_recon(new_yv12);
-    vp8cx_frame_init_quantizer(cpi);
-
-    /* Initialise the MV cost table to the defaults */
-    {
-        int flag[2] = {1, 1};
-        vp8_initialize_rd_consts(cpi, x, vp8_dc_quant(cm->base_qindex, cm->y1dc_delta_q));
-        memcpy(cm->fc.mvc, vp8_default_mv_context, sizeof(vp8_default_mv_context));
-        vp8_build_component_cost_table(cpi->mb.mvcost, (const MV_CONTEXT *) cm->fc.mvc, flag);
-    }
-
-    /* for each macroblock row in image */
-    for (mb_row = 0; mb_row < cm->mb_rows; mb_row++)
-    {
-        int_mv best_ref_mv;
-
-        best_ref_mv.as_int = 0;
-
-        /* reset above block coeffs */
-        xd->up_available = (mb_row != 0);
-        recon_yoffset = (mb_row * recon_y_stride * 16);
-        recon_uvoffset = (mb_row * recon_uv_stride * 8);
-
-        /* Set up limit values for motion vectors to prevent them extending
-         * outside the UMV borders
-         */
-        x->mv_row_min = -((mb_row * 16) + (VP8BORDERINPIXELS - 16));
-        x->mv_row_max = ((cm->mb_rows - 1 - mb_row) * 16) + (VP8BORDERINPIXELS - 16);
-
-
-        /* for each macroblock col in image */
-        for (mb_col = 0; mb_col < cm->mb_cols; mb_col++)
-        {
-            int this_error;
-            int gf_motion_error = INT_MAX;
-            int use_dc_pred = (mb_col || mb_row) && (!mb_col || !mb_row);
-
-            xd->dst.y_buffer = new_yv12->y_buffer + recon_yoffset;
-            xd->dst.u_buffer = new_yv12->u_buffer + recon_uvoffset;
-            xd->dst.v_buffer = new_yv12->v_buffer + recon_uvoffset;
-            xd->left_available = (mb_col != 0);
-
-            /* Copy current mb to a buffer */
-            vp8_copy_mem16x16(x->src.y_buffer, x->src.y_stride, x->thismb, 16);
-
-            /* do intra 16x16 prediction */
-            this_error = vp8_encode_intra(cpi, x, use_dc_pred);
-
-            /* "intrapenalty" below deals with situations where the intra
-             * and inter error scores are very low (eg a plain black frame)
-             * We do not have special cases in first pass for 0,0 and
-             * nearest etc so all inter modes carry an overhead cost
-             * estimate fot the mv. When the error score is very low this
-             * causes us to pick all or lots of INTRA modes and throw lots
-             * of key frames. This penalty adds a cost matching that of a
-             * 0,0 mv to the intra case.
-             */
-            this_error += intrapenalty;
-
-            /* Cumulative intra error total */
-            intra_error += (int64_t)this_error;
-
-            /* Set up limit values for motion vectors to prevent them
-             * extending outside the UMV borders
-             */
-            x->mv_col_min = -((mb_col * 16) + (VP8BORDERINPIXELS - 16));
-            x->mv_col_max = ((cm->mb_cols - 1 - mb_col) * 16) + (VP8BORDERINPIXELS - 16);
-
-            /* Other than for the first frame do a motion search */
-            if (cm->current_video_frame > 0)
-            {
-                BLOCKD *d = &x->e_mbd.block[0];
-                MV tmp_mv = {0, 0};
-                int tmp_err;
-                int motion_error = INT_MAX;
-                int raw_motion_error = INT_MAX;
-
-                /* Simple 0,0 motion with no mv overhead */
-                zz_motion_search( cpi, x, cpi->last_frame_unscaled_source,
-                                  &raw_motion_error, lst_yv12, &motion_error,
-                                  recon_yoffset );
-                d->bmi.mv.as_mv.row = 0;
-                d->bmi.mv.as_mv.col = 0;
-
-                if (raw_motion_error < cpi->oxcf.encode_breakout)
-                    goto skip_motion_search;
-
-                /* Test last reference frame using the previous best mv as the
-                 * starting point (best reference) for the search
-                 */
-                first_pass_motion_search(cpi, x, &best_ref_mv,
-                                        &d->bmi.mv.as_mv, lst_yv12,
-                                        &motion_error, recon_yoffset);
-
-                /* If the current best reference mv is not centred on 0,0
-                 * then do a 0,0 based search as well
-                 */
-                if (best_ref_mv.as_int)
-                {
-                   tmp_err = INT_MAX;
-                   first_pass_motion_search(cpi, x, &zero_ref_mv, &tmp_mv,
-                                     lst_yv12, &tmp_err, recon_yoffset);
-
-                   if ( tmp_err < motion_error )
-                   {
-                        motion_error = tmp_err;
-                        d->bmi.mv.as_mv.row = tmp_mv.row;
-                        d->bmi.mv.as_mv.col = tmp_mv.col;
-                   }
-                }
-
-                /* Experimental search in a second reference frame ((0,0)
-                 * based only)
-                 */
-                if (cm->current_video_frame > 1)
-                {
-                    first_pass_motion_search(cpi, x, &zero_ref_mv, &tmp_mv, gld_yv12, &gf_motion_error, recon_yoffset);
-
-                    if ((gf_motion_error < motion_error) && (gf_motion_error < this_error))
-                    {
-                        second_ref_count++;
-                    }
-
-                    /* Reset to last frame as reference buffer */
-                    xd->pre.y_buffer = lst_yv12->y_buffer + recon_yoffset;
-                    xd->pre.u_buffer = lst_yv12->u_buffer + recon_uvoffset;
-                    xd->pre.v_buffer = lst_yv12->v_buffer + recon_uvoffset;
-                }
-
-skip_motion_search:
-                /* Intra assumed best */
-                best_ref_mv.as_int = 0;
-
-                if (motion_error <= this_error)
-                {
-                    /* Keep a count of cases where the inter and intra were
-                     * very close and very low. This helps with scene cut
-                     * detection for example in cropped clips with black bars
-                     * at the sides or top and bottom.
-                     */
-                    if( (((this_error-intrapenalty) * 9) <=
-                         (motion_error*10)) &&
-                        (this_error < (2*intrapenalty)) )
-                    {
-                        neutral_count++;
-                    }
-
-                    d->bmi.mv.as_mv.row *= 8;
-                    d->bmi.mv.as_mv.col *= 8;
-                    this_error = motion_error;
-                    vp8_set_mbmode_and_mvs(x, NEWMV, &d->bmi.mv);
-                    vp8_encode_inter16x16y(x);
-                    sum_mvr += d->bmi.mv.as_mv.row;
-                    sum_mvr_abs += abs(d->bmi.mv.as_mv.row);
-                    sum_mvc += d->bmi.mv.as_mv.col;
-                    sum_mvc_abs += abs(d->bmi.mv.as_mv.col);
-                    sum_mvrs += d->bmi.mv.as_mv.row * d->bmi.mv.as_mv.row;
-                    sum_mvcs += d->bmi.mv.as_mv.col * d->bmi.mv.as_mv.col;
-                    intercount++;
-
-                    best_ref_mv.as_int = d->bmi.mv.as_int;
-
-                    /* Was the vector non-zero */
-                    if (d->bmi.mv.as_int)
-                    {
-                        mvcount++;
-
-                        /* Was it different from the last non zero vector */
-                        if ( d->bmi.mv.as_int != lastmv_as_int )
-                            new_mv_count++;
-                        lastmv_as_int = d->bmi.mv.as_int;
-
-                        /* Does the Row vector point inwards or outwards */
-                        if (mb_row < cm->mb_rows / 2)
-                        {
-                            if (d->bmi.mv.as_mv.row > 0)
-                                sum_in_vectors--;
-                            else if (d->bmi.mv.as_mv.row < 0)
-                                sum_in_vectors++;
-                        }
-                        else if (mb_row > cm->mb_rows / 2)
-                        {
-                            if (d->bmi.mv.as_mv.row > 0)
-                                sum_in_vectors++;
-                            else if (d->bmi.mv.as_mv.row < 0)
-                                sum_in_vectors--;
-                        }
-
-                        /* Does the Row vector point inwards or outwards */
-                        if (mb_col < cm->mb_cols / 2)
-                        {
-                            if (d->bmi.mv.as_mv.col > 0)
-                                sum_in_vectors--;
-                            else if (d->bmi.mv.as_mv.col < 0)
-                                sum_in_vectors++;
-                        }
-                        else if (mb_col > cm->mb_cols / 2)
-                        {
-                            if (d->bmi.mv.as_mv.col > 0)
-                                sum_in_vectors++;
-                            else if (d->bmi.mv.as_mv.col < 0)
-                                sum_in_vectors--;
-                        }
-                    }
-                }
-            }
-
-            coded_error += (int64_t)this_error;
-
-            /* adjust to the next column of macroblocks */
-            x->src.y_buffer += 16;
-            x->src.u_buffer += 8;
-            x->src.v_buffer += 8;
-
-            recon_yoffset += 16;
-            recon_uvoffset += 8;
-        }
-
-        /* adjust to the next row of mbs */
-        x->src.y_buffer += 16 * x->src.y_stride - 16 * cm->mb_cols;
-        x->src.u_buffer += 8 * x->src.uv_stride - 8 * cm->mb_cols;
-        x->src.v_buffer += 8 * x->src.uv_stride - 8 * cm->mb_cols;
-
-        /* extend the recon for intra prediction */
-        vp8_extend_mb_row(new_yv12, xd->dst.y_buffer + 16, xd->dst.u_buffer + 8, xd->dst.v_buffer + 8);
-        vp8_clear_system_state();
-    }
-
-    vp8_clear_system_state();
-    {
-        double weight = 0.0;
-
-        FIRSTPASS_STATS fps;
-
-        fps.frame      = cm->current_video_frame ;
-        fps.intra_error = (double)(intra_error >> 8);
-        fps.coded_error = (double)(coded_error >> 8);
-        weight = simple_weight(cpi->Source);
-
-
-        if (weight < 0.1)
-            weight = 0.1;
-
-        fps.ssim_weighted_pred_err = fps.coded_error * weight;
-
-        fps.pcnt_inter  = 0.0;
-        fps.pcnt_motion = 0.0;
-        fps.MVr        = 0.0;
-        fps.mvr_abs     = 0.0;
-        fps.MVc        = 0.0;
-        fps.mvc_abs     = 0.0;
-        fps.MVrv       = 0.0;
-        fps.MVcv       = 0.0;
-        fps.mv_in_out_count  = 0.0;
-        fps.new_mv_count = 0.0;
-        fps.count      = 1.0;
-
-        fps.pcnt_inter   = 1.0 * (double)intercount / cm->MBs;
-        fps.pcnt_second_ref = 1.0 * (double)second_ref_count / cm->MBs;
-        fps.pcnt_neutral = 1.0 * (double)neutral_count / cm->MBs;
-
-        if (mvcount > 0)
-        {
-            fps.MVr = (double)sum_mvr / (double)mvcount;
-            fps.mvr_abs = (double)sum_mvr_abs / (double)mvcount;
-            fps.MVc = (double)sum_mvc / (double)mvcount;
-            fps.mvc_abs = (double)sum_mvc_abs / (double)mvcount;
-            fps.MVrv = ((double)sum_mvrs - (fps.MVr * fps.MVr / (double)mvcount)) / (double)mvcount;
-            fps.MVcv = ((double)sum_mvcs - (fps.MVc * fps.MVc / (double)mvcount)) / (double)mvcount;
-            fps.mv_in_out_count = (double)sum_in_vectors / (double)(mvcount * 2);
-            fps.new_mv_count = new_mv_count;
-
-            fps.pcnt_motion = 1.0 * (double)mvcount / cpi->common.MBs;
-        }
-
-        /* TODO:  handle the case when duration is set to 0, or something less
-         * than the full time between subsequent cpi->source_time_stamps
-         */
-        fps.duration = (double)(cpi->source->ts_end
-                       - cpi->source->ts_start);
-
-        /* don't want to do output stats with a stack variable! */
-        memcpy(&cpi->twopass.this_frame_stats,
-               &fps,
-               sizeof(FIRSTPASS_STATS));
-        output_stats(cpi, cpi->output_pkt_list, &cpi->twopass.this_frame_stats);
-        accumulate_stats(&cpi->twopass.total_stats, &fps);
-    }
-
-    /* Copy the previous Last Frame into the GF buffer if specific
-     * conditions for doing so are met
-     */
-    if ((cm->current_video_frame > 0) &&
-        (cpi->twopass.this_frame_stats.pcnt_inter > 0.20) &&
-        ((cpi->twopass.this_frame_stats.intra_error /
-          DOUBLE_DIVIDE_CHECK(cpi->twopass.this_frame_stats.coded_error)) >
-         2.0))
-    {
-        vp8_yv12_copy_frame(lst_yv12, gld_yv12);
-    }
-
-    /* swap frame pointers so last frame refers to the frame we just
-     * compressed
-     */
-    vp8_swap_yv12_buffer(lst_yv12, new_yv12);
-    vp8_yv12_extend_frame_borders(lst_yv12);
-
-    /* Special case for the first frame. Copy into the GF buffer as a
-     * second reference.
-     */
-    if (cm->current_video_frame == 0)
-    {
-        vp8_yv12_copy_frame(lst_yv12, gld_yv12);
-    }
-
-
-    /* use this to see what the first pass reconstruction looks like */
-    if (0)
-    {
-        char filename[512];
-        FILE *recon_file;
-        sprintf(filename, "enc%04d.yuv", (int) cm->current_video_frame);
-
-        if (cm->current_video_frame == 0)
-            recon_file = fopen(filename, "wb");
-        else
-            recon_file = fopen(filename, "ab");
-
-        (void) fwrite(lst_yv12->buffer_alloc, lst_yv12->frame_size, 1,
-                      recon_file);
-        fclose(recon_file);
-    }
-
-    cm->current_video_frame++;
-
-}
-extern const int vp8_bits_per_mb[2][QINDEX_RANGE];
-
-/* Estimate a cost per mb attributable to overheads such as the coding of
- * modes and motion vectors.
- * Currently simplistic in its assumptions for testing.
- */
-
-static double bitcost( double prob )
-{
-  if (prob > 0.000122)
-    return -log(prob) / log(2.0);
-  else
-    return 13.0;
-}
-static int64_t estimate_modemvcost(VP8_COMP *cpi,
-                                     FIRSTPASS_STATS * fpstats)
-{
-    int mv_cost;
-    int64_t mode_cost;
-
-    double av_pct_inter = fpstats->pcnt_inter / fpstats->count;
-    double av_pct_motion = fpstats->pcnt_motion / fpstats->count;
-    double av_intra = (1.0 - av_pct_inter);
-
-    double zz_cost;
-    double motion_cost;
-    double intra_cost;
-
-    zz_cost = bitcost(av_pct_inter - av_pct_motion);
-    motion_cost = bitcost(av_pct_motion);
-    intra_cost = bitcost(av_intra);
-
-    /* Estimate of extra bits per mv overhead for mbs
-     * << 9 is the normalization to the (bits * 512) used in vp8_bits_per_mb
-     */
-    mv_cost = ((int)(fpstats->new_mv_count / fpstats->count) * 8) << 9;
-
-    /* Crude estimate of overhead cost from modes
-     * << 9 is the normalization to (bits * 512) used in vp8_bits_per_mb
-     */
-    mode_cost = (int64_t)((((av_pct_inter - av_pct_motion) * zz_cost) +
-                             (av_pct_motion * motion_cost) +
-                             (av_intra * intra_cost)) * cpi->common.MBs) * 512;
-
-    return mv_cost + mode_cost;
-}
-
-static double calc_correction_factor( double err_per_mb,
-                                      double err_devisor,
-                                      double pt_low,
-                                      double pt_high,
-                                      int Q )
-{
-    double power_term;
-    double error_term = err_per_mb / err_devisor;
-    double correction_factor;
-
-    /* Adjustment based on Q to power term. */
-    power_term = pt_low + (Q * 0.01);
-    power_term = (power_term > pt_high) ? pt_high : power_term;
-
-    /* Adjustments to error term */
-    /* TBD */
-
-    /* Calculate correction factor */
-    correction_factor = pow(error_term, power_term);
-
-    /* Clip range */
-    correction_factor =
-        (correction_factor < 0.05)
-            ? 0.05 : (correction_factor > 5.0) ? 5.0 : correction_factor;
-
-    return correction_factor;
-}
-
-static int estimate_max_q(VP8_COMP *cpi,
-                          FIRSTPASS_STATS * fpstats,
-                          int section_target_bandwitdh,
-                          int overhead_bits )
-{
-    int Q;
-    int num_mbs = cpi->common.MBs;
-    int target_norm_bits_per_mb;
-
-    double section_err = (fpstats->coded_error / fpstats->count);
-    double err_per_mb = section_err / num_mbs;
-    double err_correction_factor;
-    double speed_correction = 1.0;
-    int overhead_bits_per_mb;
-
-    if (section_target_bandwitdh <= 0)
-        return cpi->twopass.maxq_max_limit;       /* Highest value allowed */
-
-    target_norm_bits_per_mb =
-        (section_target_bandwitdh < (1 << 20))
-            ? (512 * section_target_bandwitdh) / num_mbs
-            : 512 * (section_target_bandwitdh / num_mbs);
-
-    /* Calculate a corrective factor based on a rolling ratio of bits spent
-     * vs target bits
-     */
-    if ((cpi->rolling_target_bits > 0) &&
-        (cpi->active_worst_quality < cpi->worst_quality))
-    {
-        double rolling_ratio;
-
-        rolling_ratio = (double)cpi->rolling_actual_bits /
-                        (double)cpi->rolling_target_bits;
-
-        if (rolling_ratio < 0.95)
-            cpi->twopass.est_max_qcorrection_factor -= 0.005;
-        else if (rolling_ratio > 1.05)
-            cpi->twopass.est_max_qcorrection_factor += 0.005;
-
-        cpi->twopass.est_max_qcorrection_factor =
-            (cpi->twopass.est_max_qcorrection_factor < 0.1)
-                ? 0.1
-                : (cpi->twopass.est_max_qcorrection_factor > 10.0)
-                    ? 10.0 : cpi->twopass.est_max_qcorrection_factor;
-    }
-
-    /* Corrections for higher compression speed settings
-     * (reduced compression expected)
-     */
-    if ((cpi->compressor_speed == 3) || (cpi->compressor_speed == 1))
-    {
-        if (cpi->oxcf.cpu_used <= 5)
-            speed_correction = 1.04 + (cpi->oxcf.cpu_used * 0.04);
-        else
-            speed_correction = 1.25;
-    }
-
-    /* Estimate of overhead bits per mb */
-    /* Correction to overhead bits for min allowed Q. */
-    overhead_bits_per_mb = overhead_bits / num_mbs;
-    overhead_bits_per_mb = (int)(overhead_bits_per_mb *
-                            pow( 0.98, (double)cpi->twopass.maxq_min_limit ));
-
-    /* Try and pick a max Q that will be high enough to encode the
-     * content at the given rate.
-     */
-    for (Q = cpi->twopass.maxq_min_limit; Q < cpi->twopass.maxq_max_limit; Q++)
-    {
-        int bits_per_mb_at_this_q;
-
-        /* Error per MB based correction factor */
-        err_correction_factor =
-            calc_correction_factor(err_per_mb, 150.0, 0.40, 0.90, Q);
-
-        bits_per_mb_at_this_q =
-            vp8_bits_per_mb[INTER_FRAME][Q] + overhead_bits_per_mb;
-
-        bits_per_mb_at_this_q = (int)(.5 + err_correction_factor
-            * speed_correction * cpi->twopass.est_max_qcorrection_factor
-            * cpi->twopass.section_max_qfactor
-            * (double)bits_per_mb_at_this_q);
-
-        /* Mode and motion overhead */
-        /* As Q rises in real encode loop rd code will force overhead down
-         * We make a crude adjustment for this here as *.98 per Q step.
-         */
-        overhead_bits_per_mb = (int)((double)overhead_bits_per_mb * 0.98);
-
-        if (bits_per_mb_at_this_q <= target_norm_bits_per_mb)
-            break;
-    }
-
-    /* Restriction on active max q for constrained quality mode. */
-    if ( (cpi->oxcf.end_usage == USAGE_CONSTRAINED_QUALITY) &&
-         (Q < cpi->cq_target_quality) )
-    {
-        Q = cpi->cq_target_quality;
-    }
-
-    /* Adjust maxq_min_limit and maxq_max_limit limits based on
-     * average q observed in clip for non kf/gf.arf frames
-     * Give average a chance to settle though.
-     */
-    if ( (cpi->ni_frames >
-                  ((int)cpi->twopass.total_stats.count >> 8)) &&
-         (cpi->ni_frames > 150) )
-    {
-        cpi->twopass.maxq_max_limit = ((cpi->ni_av_qi + 32) < cpi->worst_quality)
-                                  ? (cpi->ni_av_qi + 32) : cpi->worst_quality;
-        cpi->twopass.maxq_min_limit = ((cpi->ni_av_qi - 32) > cpi->best_quality)
-                                  ? (cpi->ni_av_qi - 32) : cpi->best_quality;
-    }
-
-    return Q;
-}
-
-/* For cq mode estimate a cq level that matches the observed
- * complexity and data rate.
- */
-static int estimate_cq( VP8_COMP *cpi,
-                        FIRSTPASS_STATS * fpstats,
-                        int section_target_bandwitdh,
-                        int overhead_bits )
-{
-    int Q;
-    int num_mbs = cpi->common.MBs;
-    int target_norm_bits_per_mb;
-
-    double section_err = (fpstats->coded_error / fpstats->count);
-    double err_per_mb = section_err / num_mbs;
-    double err_correction_factor;
-    double speed_correction = 1.0;
-    double clip_iiratio;
-    double clip_iifactor;
-    int overhead_bits_per_mb;
-
-    if (0)
-    {
-        FILE *f = fopen("epmp.stt", "a");
-        fprintf(f, "%10.2f\n", err_per_mb );
-        fclose(f);
-    }
-
-    target_norm_bits_per_mb = (section_target_bandwitdh < (1 << 20))
-                              ? (512 * section_target_bandwitdh) / num_mbs
-                              : 512 * (section_target_bandwitdh / num_mbs);
-
-    /* Estimate of overhead bits per mb */
-    overhead_bits_per_mb = overhead_bits / num_mbs;
-
-    /* Corrections for higher compression speed settings
-     * (reduced compression expected)
-     */
-    if ((cpi->compressor_speed == 3) || (cpi->compressor_speed == 1))
-    {
-        if (cpi->oxcf.cpu_used <= 5)
-            speed_correction = 1.04 + (cpi->oxcf.cpu_used * 0.04);
-        else
-            speed_correction = 1.25;
-    }
-
-    /* II ratio correction factor for clip as a whole */
-    clip_iiratio = cpi->twopass.total_stats.intra_error /
-                   DOUBLE_DIVIDE_CHECK(cpi->twopass.total_stats.coded_error);
-    clip_iifactor = 1.0 - ((clip_iiratio - 10.0) * 0.025);
-    if (clip_iifactor < 0.80)
-        clip_iifactor = 0.80;
-
-    /* Try and pick a Q that can encode the content at the given rate. */
-    for (Q = 0; Q < MAXQ; Q++)
-    {
-        int bits_per_mb_at_this_q;
-
-        /* Error per MB based correction factor */
-        err_correction_factor =
-            calc_correction_factor(err_per_mb, 100.0, 0.40, 0.90, Q);
-
-        bits_per_mb_at_this_q =
-            vp8_bits_per_mb[INTER_FRAME][Q] + overhead_bits_per_mb;
-
-        bits_per_mb_at_this_q =
-            (int)( .5 + err_correction_factor *
-                        speed_correction *
-                        clip_iifactor *
-                        (double)bits_per_mb_at_this_q);
-
-        /* Mode and motion overhead */
-        /* As Q rises in real encode loop rd code will force overhead down
-         * We make a crude adjustment for this here as *.98 per Q step.
-         */
-        overhead_bits_per_mb = (int)((double)overhead_bits_per_mb * 0.98);
-
-        if (bits_per_mb_at_this_q <= target_norm_bits_per_mb)
-            break;
-    }
-
-    /* Clip value to range "best allowed to (worst allowed - 1)" */
-    Q = cq_level[Q];
-    if ( Q >= cpi->worst_quality )
-        Q = cpi->worst_quality - 1;
-    if ( Q < cpi->best_quality )
-        Q = cpi->best_quality;
-
-    return Q;
-}
-
-static int estimate_q(VP8_COMP *cpi, double section_err, int section_target_bandwitdh)
-{
-    int Q;
-    int num_mbs = cpi->common.MBs;
-    int target_norm_bits_per_mb;
-
-    double err_per_mb = section_err / num_mbs;
-    double err_correction_factor;
-    double speed_correction = 1.0;
-
-    target_norm_bits_per_mb = (section_target_bandwitdh < (1 << 20)) ? (512 * section_target_bandwitdh) / num_mbs : 512 * (section_target_bandwitdh / num_mbs);
-
-    /* Corrections for higher compression speed settings
-     * (reduced compression expected)
-     */
-    if ((cpi->compressor_speed == 3) || (cpi->compressor_speed == 1))
-    {
-        if (cpi->oxcf.cpu_used <= 5)
-            speed_correction = 1.04 + (cpi->oxcf.cpu_used * 0.04);
-        else
-            speed_correction = 1.25;
-    }
-
-    /* Try and pick a Q that can encode the content at the given rate. */
-    for (Q = 0; Q < MAXQ; Q++)
-    {
-        int bits_per_mb_at_this_q;
-
-        /* Error per MB based correction factor */
-        err_correction_factor =
-            calc_correction_factor(err_per_mb, 150.0, 0.40, 0.90, Q);
-
-        bits_per_mb_at_this_q =
-            (int)( .5 + ( err_correction_factor *
-                          speed_correction *
-                          cpi->twopass.est_max_qcorrection_factor *
-                          (double)vp8_bits_per_mb[INTER_FRAME][Q] / 1.0 ) );
-
-        if (bits_per_mb_at_this_q <= target_norm_bits_per_mb)
-            break;
-    }
-
-    return Q;
-}
-
-/* Estimate a worst case Q for a KF group */
-static int estimate_kf_group_q(VP8_COMP *cpi, double section_err, int section_target_bandwitdh, double group_iiratio)
-{
-    int Q;
-    int num_mbs = cpi->common.MBs;
-    int target_norm_bits_per_mb = (512 * section_target_bandwitdh) / num_mbs;
-    int bits_per_mb_at_this_q;
-
-    double err_per_mb = section_err / num_mbs;
-    double err_correction_factor;
-    double speed_correction = 1.0;
-    double current_spend_ratio = 1.0;
-
-    double pow_highq = (POW1 < 0.6) ? POW1 + 0.3 : 0.90;
-    double pow_lowq = (POW1 < 0.7) ? POW1 + 0.1 : 0.80;
-
-    double iiratio_correction_factor = 1.0;
-
-    double combined_correction_factor;
-
-    /* Trap special case where the target is <= 0 */
-    if (target_norm_bits_per_mb <= 0)
-        return MAXQ * 2;
-
-    /* Calculate a corrective factor based on a rolling ratio of bits spent
-     *  vs target bits
-     * This is clamped to the range 0.1 to 10.0
-     */
-    if (cpi->long_rolling_target_bits <= 0)
-        current_spend_ratio = 10.0;
-    else
-    {
-        current_spend_ratio = (double)cpi->long_rolling_actual_bits / (double)cpi->long_rolling_target_bits;
-        current_spend_ratio = (current_spend_ratio > 10.0) ? 10.0 : (current_spend_ratio < 0.1) ? 0.1 : current_spend_ratio;
-    }
-
-    /* Calculate a correction factor based on the quality of prediction in
-     * the sequence as indicated by intra_inter error score ratio (IIRatio)
-     * The idea here is to favour subsampling in the hardest sections vs
-     * the easyest.
-     */
-    iiratio_correction_factor = 1.0 - ((group_iiratio - 6.0) * 0.1);
-
-    if (iiratio_correction_factor < 0.5)
-        iiratio_correction_factor = 0.5;
-
-    /* Corrections for higher compression speed settings
-     * (reduced compression expected)
-     */
-    if ((cpi->compressor_speed == 3) || (cpi->compressor_speed == 1))
-    {
-        if (cpi->oxcf.cpu_used <= 5)
-            speed_correction = 1.04 + (cpi->oxcf.cpu_used * 0.04);
-        else
-            speed_correction = 1.25;
-    }
-
-    /* Combine the various factors calculated above */
-    combined_correction_factor = speed_correction * iiratio_correction_factor * current_spend_ratio;
-
-    /* Try and pick a Q that should be high enough to encode the content at
-     * the given rate.
-     */
-    for (Q = 0; Q < MAXQ; Q++)
-    {
-        /* Error per MB based correction factor */
-        err_correction_factor =
-            calc_correction_factor(err_per_mb, 150.0, pow_lowq, pow_highq, Q);
-
-        bits_per_mb_at_this_q =
-            (int)(.5 + ( err_correction_factor *
-                         combined_correction_factor *
-                         (double)vp8_bits_per_mb[INTER_FRAME][Q]) );
-
-        if (bits_per_mb_at_this_q <= target_norm_bits_per_mb)
-            break;
-    }
-
-    /* If we could not hit the target even at Max Q then estimate what Q
-     * would have been required
-     */
-    while ((bits_per_mb_at_this_q > target_norm_bits_per_mb)  && (Q < (MAXQ * 2)))
-    {
-
-        bits_per_mb_at_this_q = (int)(0.96 * bits_per_mb_at_this_q);
-        Q++;
-    }
-
-    if (0)
-    {
-        FILE *f = fopen("estkf_q.stt", "a");
-        fprintf(f, "%8d %8d %8d %8.2f %8.3f %8.2f %8.3f %8.3f %8.3f %8d\n", cpi->common.current_video_frame, bits_per_mb_at_this_q,
-                target_norm_bits_per_mb, err_per_mb, err_correction_factor,
-                current_spend_ratio, group_iiratio, iiratio_correction_factor,
-                (double)cpi->buffer_level / (double)cpi->oxcf.optimal_buffer_level, Q);
-        fclose(f);
-    }
-
-    return Q;
-}
-
-void vp8_init_second_pass(VP8_COMP *cpi)
-{
-    FIRSTPASS_STATS this_frame;
-    FIRSTPASS_STATS *start_pos;
-
-    double two_pass_min_rate = (double)(cpi->oxcf.target_bandwidth * cpi->oxcf.two_pass_vbrmin_section / 100);
-
-    zero_stats(&cpi->twopass.total_stats);
-    zero_stats(&cpi->twopass.total_left_stats);
-
-    if (!cpi->twopass.stats_in_end)
-        return;
-
-    cpi->twopass.total_stats = *cpi->twopass.stats_in_end;
-    cpi->twopass.total_left_stats = cpi->twopass.total_stats;
-
-    /* each frame can have a different duration, as the frame rate in the
-     * source isn't guaranteed to be constant.   The frame rate prior to
-     * the first frame encoded in the second pass is a guess.  However the
-     * sum duration is not. Its calculated based on the actual durations of
-     * all frames from the first pass.
-     */
-    vp8_new_framerate(cpi, 10000000.0 * cpi->twopass.total_stats.count / cpi->twopass.total_stats.duration);
-
-    cpi->output_framerate = cpi->framerate;
-    cpi->twopass.bits_left = (int64_t)(cpi->twopass.total_stats.duration * cpi->oxcf.target_bandwidth / 10000000.0) ;
-    cpi->twopass.bits_left -= (int64_t)(cpi->twopass.total_stats.duration * two_pass_min_rate / 10000000.0);
-
-    /* Calculate a minimum intra value to be used in determining the IIratio
-     * scores used in the second pass. We have this minimum to make sure
-     * that clips that are static but "low complexity" in the intra domain
-     * are still boosted appropriately for KF/GF/ARF
-     */
-    cpi->twopass.kf_intra_err_min = KF_MB_INTRA_MIN * cpi->common.MBs;
-    cpi->twopass.gf_intra_err_min = GF_MB_INTRA_MIN * cpi->common.MBs;
-
-    /* Scan the first pass file and calculate an average Intra / Inter error
-     * score ratio for the sequence
-     */
-    {
-        double sum_iiratio = 0.0;
-        double IIRatio;
-
-        start_pos = cpi->twopass.stats_in; /* Note starting "file" position */
-
-        while (input_stats(cpi, &this_frame) != EOF)
-        {
-            IIRatio = this_frame.intra_error / DOUBLE_DIVIDE_CHECK(this_frame.coded_error);
-            IIRatio = (IIRatio < 1.0) ? 1.0 : (IIRatio > 20.0) ? 20.0 : IIRatio;
-            sum_iiratio += IIRatio;
-        }
-
-        cpi->twopass.avg_iiratio = sum_iiratio / DOUBLE_DIVIDE_CHECK((double)cpi->twopass.total_stats.count);
-
-        /* Reset file position */
-        reset_fpf_position(cpi, start_pos);
-    }
-
-    /* Scan the first pass file and calculate a modified total error based
-     * upon the bias/power function used to allocate bits
-     */
-    {
-        start_pos = cpi->twopass.stats_in;  /* Note starting "file" position */
-
-        cpi->twopass.modified_error_total = 0.0;
-        cpi->twopass.modified_error_used = 0.0;
-
-        while (input_stats(cpi, &this_frame) != EOF)
-        {
-            cpi->twopass.modified_error_total += calculate_modified_err(cpi, &this_frame);
-        }
-        cpi->twopass.modified_error_left = cpi->twopass.modified_error_total;
-
-        reset_fpf_position(cpi, start_pos);  /* Reset file position */
-
-    }
-}
-
-void vp8_end_second_pass(VP8_COMP *cpi)
-{
-  (void)cpi;
-}
-
-/* This function gives and estimate of how badly we believe the prediction
- * quality is decaying from frame to frame.
- */
-static double get_prediction_decay_rate(VP8_COMP *cpi, FIRSTPASS_STATS *next_frame)
-{
-    double prediction_decay_rate;
-    double motion_decay;
-    double motion_pct = next_frame->pcnt_motion;
-    (void)cpi;
-
-    /* Initial basis is the % mbs inter coded */
-    prediction_decay_rate = next_frame->pcnt_inter;
-
-    /* High % motion -> somewhat higher decay rate */
-    motion_decay = (1.0 - (motion_pct / 20.0));
-    if (motion_decay < prediction_decay_rate)
-        prediction_decay_rate = motion_decay;
-
-    /* Adjustment to decay rate based on speed of motion */
-    {
-        double this_mv_rabs;
-        double this_mv_cabs;
-        double distance_factor;
-
-        this_mv_rabs = fabs(next_frame->mvr_abs * motion_pct);
-        this_mv_cabs = fabs(next_frame->mvc_abs * motion_pct);
-
-        distance_factor = sqrt((this_mv_rabs * this_mv_rabs) +
-                               (this_mv_cabs * this_mv_cabs)) / 250.0;
-        distance_factor = ((distance_factor > 1.0)
-                                ? 0.0 : (1.0 - distance_factor));
-        if (distance_factor < prediction_decay_rate)
-            prediction_decay_rate = distance_factor;
-    }
-
-    return prediction_decay_rate;
-}
-
-/* Function to test for a condition where a complex transition is followed
- * by a static section. For example in slide shows where there is a fade
- * between slides. This is to help with more optimal kf and gf positioning.
- */
-static int detect_transition_to_still(
-    VP8_COMP *cpi,
-    int frame_interval,
-    int still_interval,
-    double loop_decay_rate,
-    double decay_accumulator )
-{
-    int trans_to_still = 0;
-
-    /* Break clause to detect very still sections after motion
-     * For example a static image after a fade or other transition
-     * instead of a clean scene cut.
-     */
-    if ( (frame_interval > MIN_GF_INTERVAL) &&
-         (loop_decay_rate >= 0.999) &&
-         (decay_accumulator < 0.9) )
-    {
-        int j;
-        FIRSTPASS_STATS * position = cpi->twopass.stats_in;
-        FIRSTPASS_STATS tmp_next_frame;
-        double decay_rate;
-
-        /* Look ahead a few frames to see if static condition persists... */
-        for ( j = 0; j < still_interval; j++ )
-        {
-            if (EOF == input_stats(cpi, &tmp_next_frame))
-                break;
-
-            decay_rate = get_prediction_decay_rate(cpi, &tmp_next_frame);
-            if ( decay_rate < 0.999 )
-                break;
-        }
-        /* Reset file position */
-        reset_fpf_position(cpi, position);
-
-        /* Only if it does do we signal a transition to still */
-        if ( j == still_interval )
-            trans_to_still = 1;
-    }
-
-    return trans_to_still;
-}
-
-/* This function detects a flash through the high relative pcnt_second_ref
- * score in the frame following a flash frame. The offset passed in should
- * reflect this
- */
-static int detect_flash( VP8_COMP *cpi, int offset )
-{
-    FIRSTPASS_STATS next_frame;
-
-    int flash_detected = 0;
-
-    /* Read the frame data. */
-    /* The return is 0 (no flash detected) if not a valid frame */
-    if ( read_frame_stats(cpi, &next_frame, offset) != EOF )
-    {
-        /* What we are looking for here is a situation where there is a
-         * brief break in prediction (such as a flash) but subsequent frames
-         * are reasonably well predicted by an earlier (pre flash) frame.
-         * The recovery after a flash is indicated by a high pcnt_second_ref
-         * comapred to pcnt_inter.
-         */
-        if ( (next_frame.pcnt_second_ref > next_frame.pcnt_inter) &&
-             (next_frame.pcnt_second_ref >= 0.5 ) )
-        {
-            flash_detected = 1;
-
-            /*if (1)
-            {
-                FILE *f = fopen("flash.stt", "a");
-                fprintf(f, "%8.0f %6.2f %6.2f\n",
-                    next_frame.frame,
-                    next_frame.pcnt_inter,
-                    next_frame.pcnt_second_ref);
-                fclose(f);
-            }*/
-        }
-    }
-
-    return flash_detected;
-}
-
-/* Update the motion related elements to the GF arf boost calculation */
-static void accumulate_frame_motion_stats(
-    VP8_COMP *cpi,
-    FIRSTPASS_STATS * this_frame,
-    double * this_frame_mv_in_out,
-    double * mv_in_out_accumulator,
-    double * abs_mv_in_out_accumulator,
-    double * mv_ratio_accumulator )
-{
-    double this_frame_mvr_ratio;
-    double this_frame_mvc_ratio;
-    double motion_pct;
-    (void)cpi;
-
-    /* Accumulate motion stats. */
-    motion_pct = this_frame->pcnt_motion;
-
-    /* Accumulate Motion In/Out of frame stats */
-    *this_frame_mv_in_out = this_frame->mv_in_out_count * motion_pct;
-    *mv_in_out_accumulator += this_frame->mv_in_out_count * motion_pct;
-    *abs_mv_in_out_accumulator +=
-        fabs(this_frame->mv_in_out_count * motion_pct);
-
-    /* Accumulate a measure of how uniform (or conversely how random)
-     * the motion field is. (A ratio of absmv / mv)
-     */
-    if (motion_pct > 0.05)
-    {
-        this_frame_mvr_ratio = fabs(this_frame->mvr_abs) /
-                               DOUBLE_DIVIDE_CHECK(fabs(this_frame->MVr));
-
-        this_frame_mvc_ratio = fabs(this_frame->mvc_abs) /
-                               DOUBLE_DIVIDE_CHECK(fabs(this_frame->MVc));
-
-         *mv_ratio_accumulator +=
-            (this_frame_mvr_ratio < this_frame->mvr_abs)
-                ? (this_frame_mvr_ratio * motion_pct)
-                : this_frame->mvr_abs * motion_pct;
-
-        *mv_ratio_accumulator +=
-            (this_frame_mvc_ratio < this_frame->mvc_abs)
-                ? (this_frame_mvc_ratio * motion_pct)
-                : this_frame->mvc_abs * motion_pct;
-
-    }
-}
-
-/* Calculate a baseline boost number for the current frame. */
-static double calc_frame_boost(
-    VP8_COMP *cpi,
-    FIRSTPASS_STATS * this_frame,
-    double this_frame_mv_in_out )
-{
-    double frame_boost;
-
-    /* Underlying boost factor is based on inter intra error ratio */
-    if (this_frame->intra_error > cpi->twopass.gf_intra_err_min)
-        frame_boost = (IIFACTOR * this_frame->intra_error /
-                      DOUBLE_DIVIDE_CHECK(this_frame->coded_error));
-    else
-        frame_boost = (IIFACTOR * cpi->twopass.gf_intra_err_min /
-                      DOUBLE_DIVIDE_CHECK(this_frame->coded_error));
-
-    /* Increase boost for frames where new data coming into frame
-     * (eg zoom out). Slightly reduce boost if there is a net balance
-     * of motion out of the frame (zoom in).
-     * The range for this_frame_mv_in_out is -1.0 to +1.0
-     */
-    if (this_frame_mv_in_out > 0.0)
-        frame_boost += frame_boost * (this_frame_mv_in_out * 2.0);
-    /* In extreme case boost is halved */
-    else
-        frame_boost += frame_boost * (this_frame_mv_in_out / 2.0);
-
-    /* Clip to maximum */
-    if (frame_boost > GF_RMAX)
-        frame_boost = GF_RMAX;
-
-    return frame_boost;
-}
-
-#if NEW_BOOST
-static int calc_arf_boost(
-    VP8_COMP *cpi,
-    int offset,
-    int f_frames,
-    int b_frames,
-    int *f_boost,
-    int *b_boost )
-{
-    FIRSTPASS_STATS this_frame;
-
-    int i;
-    double boost_score = 0.0;
-    double mv_ratio_accumulator = 0.0;
-    double decay_accumulator = 1.0;
-    double this_frame_mv_in_out = 0.0;
-    double mv_in_out_accumulator = 0.0;
-    double abs_mv_in_out_accumulator = 0.0;
-    double r;
-    int flash_detected = 0;
-
-    /* Search forward from the proposed arf/next gf position */
-    for ( i = 0; i < f_frames; i++ )
-    {
-        if ( read_frame_stats(cpi, &this_frame, (i+offset)) == EOF )
-            break;
-
-        /* Update the motion related elements to the boost calculation */
-        accumulate_frame_motion_stats( cpi, &this_frame,
-            &this_frame_mv_in_out, &mv_in_out_accumulator,
-            &abs_mv_in_out_accumulator, &mv_ratio_accumulator );
-
-        /* Calculate the baseline boost number for this frame */
-        r = calc_frame_boost( cpi, &this_frame, this_frame_mv_in_out );
-
-        /* We want to discount the the flash frame itself and the recovery
-         * frame that follows as both will have poor scores.
-         */
-        flash_detected = detect_flash(cpi, (i+offset)) ||
-                         detect_flash(cpi, (i+offset+1));
-
-        /* Cumulative effect of prediction quality decay */
-        if ( !flash_detected )
-        {
-            decay_accumulator =
-                decay_accumulator *
-                get_prediction_decay_rate(cpi, &this_frame);
-            decay_accumulator =
-                decay_accumulator < 0.1 ? 0.1 : decay_accumulator;
-        }
-        boost_score += (decay_accumulator * r);
-
-        /* Break out conditions. */
-        if  ( (!flash_detected) &&
-              ((mv_ratio_accumulator > 100.0) ||
-               (abs_mv_in_out_accumulator > 3.0) ||
-               (mv_in_out_accumulator < -2.0) ) )
-        {
-            break;
-        }
-    }
-
-    *f_boost = (int)(boost_score * 100.0) >> 4;
-
-    /* Reset for backward looking loop */
-    boost_score = 0.0;
-    mv_ratio_accumulator = 0.0;
-    decay_accumulator = 1.0;
-    this_frame_mv_in_out = 0.0;
-    mv_in_out_accumulator = 0.0;
-    abs_mv_in_out_accumulator = 0.0;
-
-    /* Search forward from the proposed arf/next gf position */
-    for ( i = -1; i >= -b_frames; i-- )
-    {
-        if ( read_frame_stats(cpi, &this_frame, (i+offset)) == EOF )
-            break;
-
-        /* Update the motion related elements to the boost calculation */
-        accumulate_frame_motion_stats( cpi, &this_frame,
-            &this_frame_mv_in_out, &mv_in_out_accumulator,
-            &abs_mv_in_out_accumulator, &mv_ratio_accumulator );
-
-        /* Calculate the baseline boost number for this frame */
-        r = calc_frame_boost( cpi, &this_frame, this_frame_mv_in_out );
-
-        /* We want to discount the the flash frame itself and the recovery
-         * frame that follows as both will have poor scores.
-         */
-        flash_detected = detect_flash(cpi, (i+offset)) ||
-                         detect_flash(cpi, (i+offset+1));
-
-        /* Cumulative effect of prediction quality decay */
-        if ( !flash_detected )
-        {
-            decay_accumulator =
-                decay_accumulator *
-                get_prediction_decay_rate(cpi, &this_frame);
-            decay_accumulator =
-                decay_accumulator < 0.1 ? 0.1 : decay_accumulator;
-        }
-
-        boost_score += (decay_accumulator * r);
-
-        /* Break out conditions. */
-        if  ( (!flash_detected) &&
-              ((mv_ratio_accumulator > 100.0) ||
-               (abs_mv_in_out_accumulator > 3.0) ||
-               (mv_in_out_accumulator < -2.0) ) )
-        {
-            break;
-        }
-    }
-    *b_boost = (int)(boost_score * 100.0) >> 4;
-
-    return (*f_boost + *b_boost);
-}
-#endif
-
-/* Analyse and define a gf/arf group . */
-static void define_gf_group(VP8_COMP *cpi, FIRSTPASS_STATS *this_frame)
-{
-    FIRSTPASS_STATS next_frame;
-    FIRSTPASS_STATS *start_pos;
-    int i;
-    double r;
-    double boost_score = 0.0;
-    double old_boost_score = 0.0;
-    double gf_group_err = 0.0;
-    double gf_first_frame_err = 0.0;
-    double mod_frame_err = 0.0;
-
-    double mv_ratio_accumulator = 0.0;
-    double decay_accumulator = 1.0;
-
-    double loop_decay_rate = 1.00;          /* Starting decay rate */
-
-    double this_frame_mv_in_out = 0.0;
-    double mv_in_out_accumulator = 0.0;
-    double abs_mv_in_out_accumulator = 0.0;
-    double mod_err_per_mb_accumulator = 0.0;
-
-    int max_bits = frame_max_bits(cpi);     /* Max for a single frame */
-
-    unsigned int allow_alt_ref =
-                    cpi->oxcf.play_alternate && cpi->oxcf.lag_in_frames;
-
-    int alt_boost = 0;
-    int f_boost = 0;
-    int b_boost = 0;
-    int flash_detected;
-
-    cpi->twopass.gf_group_bits = 0;
-    cpi->twopass.gf_decay_rate = 0;
-
-    vp8_clear_system_state();
-
-    start_pos = cpi->twopass.stats_in;
-
-    memset(&next_frame, 0, sizeof(next_frame)); /* assure clean */
-
-    /* Load stats for the current frame. */
-    mod_frame_err = calculate_modified_err(cpi, this_frame);
-
-    /* Note the error of the frame at the start of the group (this will be
-     * the GF frame error if we code a normal gf
-     */
-    gf_first_frame_err = mod_frame_err;
-
-    /* Special treatment if the current frame is a key frame (which is also
-     * a gf). If it is then its error score (and hence bit allocation) need
-     * to be subtracted out from the calculation for the GF group
-     */
-    if (cpi->common.frame_type == KEY_FRAME)
-        gf_group_err -= gf_first_frame_err;
-
-    /* Scan forward to try and work out how many frames the next gf group
-     * should contain and what level of boost is appropriate for the GF
-     * or ARF that will be coded with the group
-     */
-    i = 0;
-
-    while (((i < cpi->twopass.static_scene_max_gf_interval) ||
-            ((cpi->twopass.frames_to_key - i) < MIN_GF_INTERVAL)) &&
-           (i < cpi->twopass.frames_to_key))
-    {
-        i++;
-
-        /* Accumulate error score of frames in this gf group */
-        mod_frame_err = calculate_modified_err(cpi, this_frame);
-
-        gf_group_err += mod_frame_err;
-
-        mod_err_per_mb_accumulator +=
-            mod_frame_err / DOUBLE_DIVIDE_CHECK((double)cpi->common.MBs);
-
-        if (EOF == input_stats(cpi, &next_frame))
-            break;
-
-        /* Test for the case where there is a brief flash but the prediction
-         * quality back to an earlier frame is then restored.
-         */
-        flash_detected = detect_flash(cpi, 0);
-
-        /* Update the motion related elements to the boost calculation */
-        accumulate_frame_motion_stats( cpi, &next_frame,
-            &this_frame_mv_in_out, &mv_in_out_accumulator,
-            &abs_mv_in_out_accumulator, &mv_ratio_accumulator );
-
-        /* Calculate a baseline boost number for this frame */
-        r = calc_frame_boost( cpi, &next_frame, this_frame_mv_in_out );
-
-        /* Cumulative effect of prediction quality decay */
-        if ( !flash_detected )
-        {
-            loop_decay_rate = get_prediction_decay_rate(cpi, &next_frame);
-            decay_accumulator = decay_accumulator * loop_decay_rate;
-            decay_accumulator =
-                decay_accumulator < 0.1 ? 0.1 : decay_accumulator;
-        }
-        boost_score += (decay_accumulator * r);
-
-        /* Break clause to detect very still sections after motion
-         * For example a staic image after a fade or other transition.
-         */
-        if ( detect_transition_to_still( cpi, i, 5,
-                                         loop_decay_rate,
-                                         decay_accumulator ) )
-        {
-            allow_alt_ref = 0;
-            boost_score = old_boost_score;
-            break;
-        }
-
-        /* Break out conditions. */
-        if  (
-            /* Break at cpi->max_gf_interval unless almost totally static */
-            (i >= cpi->max_gf_interval && (decay_accumulator < 0.995)) ||
-            (
-                /* Dont break out with a very short interval */
-                (i > MIN_GF_INTERVAL) &&
-                /* Dont break out very close to a key frame */
-                ((cpi->twopass.frames_to_key - i) >= MIN_GF_INTERVAL) &&
-                ((boost_score > 20.0) || (next_frame.pcnt_inter < 0.75)) &&
-                (!flash_detected) &&
-                ((mv_ratio_accumulator > 100.0) ||
-                 (abs_mv_in_out_accumulator > 3.0) ||
-                 (mv_in_out_accumulator < -2.0) ||
-                 ((boost_score - old_boost_score) < 2.0))
-            ) )
-        {
-            boost_score = old_boost_score;
-            break;
-        }
-
-        memcpy(this_frame, &next_frame, sizeof(*this_frame));
-
-        old_boost_score = boost_score;
-    }
-
-    cpi->twopass.gf_decay_rate =
-        (i > 0) ? (int)(100.0 * (1.0 - decay_accumulator)) / i : 0;
-
-    /* When using CBR apply additional buffer related upper limits */
-    if (cpi->oxcf.end_usage == USAGE_STREAM_FROM_SERVER)
-    {
-        double max_boost;
-
-        /* For cbr apply buffer related limits */
-        if (cpi->drop_frames_allowed)
-        {
-            int64_t df_buffer_level = cpi->oxcf.drop_frames_water_mark *
-                                  (cpi->oxcf.optimal_buffer_level / 100);
-
-            if (cpi->buffer_level > df_buffer_level)
-                max_boost = ((double)((cpi->buffer_level - df_buffer_level) * 2 / 3) * 16.0) / DOUBLE_DIVIDE_CHECK((double)cpi->av_per_frame_bandwidth);
-            else
-                max_boost = 0.0;
-        }
-        else if (cpi->buffer_level > 0)
-        {
-            max_boost = ((double)(cpi->buffer_level * 2 / 3) * 16.0) / DOUBLE_DIVIDE_CHECK((double)cpi->av_per_frame_bandwidth);
-        }
-        else
-        {
-            max_boost = 0.0;
-        }
-
-        if (boost_score > max_boost)
-            boost_score = max_boost;
-    }
-
-    /* Dont allow conventional gf too near the next kf */
-    if ((cpi->twopass.frames_to_key - i) < MIN_GF_INTERVAL)
-    {
-        while (i < cpi->twopass.frames_to_key)
-        {
-            i++;
-
-            if (EOF == input_stats(cpi, this_frame))
-                break;
-
-            if (i < cpi->twopass.frames_to_key)
-            {
-                mod_frame_err = calculate_modified_err(cpi, this_frame);
-                gf_group_err += mod_frame_err;
-            }
-        }
-    }
-
-    cpi->gfu_boost = (int)(boost_score * 100.0) >> 4;
-
-#if NEW_BOOST
-    /* Alterrnative boost calculation for alt ref */
-    alt_boost = calc_arf_boost( cpi, 0, (i-1), (i-1), &f_boost, &b_boost );
-#endif
-
-    /* Should we use the alternate refernce frame */
-    if (allow_alt_ref &&
-        (i >= MIN_GF_INTERVAL) &&
-        /* dont use ARF very near next kf */
-        (i <= (cpi->twopass.frames_to_key - MIN_GF_INTERVAL)) &&
-#if NEW_BOOST
-        ((next_frame.pcnt_inter > 0.75) ||
-         (next_frame.pcnt_second_ref > 0.5)) &&
-        ((mv_in_out_accumulator / (double)i > -0.2) ||
-         (mv_in_out_accumulator > -2.0)) &&
-        (b_boost > 100) &&
-        (f_boost > 100) )
-#else
-        (next_frame.pcnt_inter > 0.75) &&
-        ((mv_in_out_accumulator / (double)i > -0.2) ||
-         (mv_in_out_accumulator > -2.0)) &&
-        (cpi->gfu_boost > 100) &&
-        (cpi->twopass.gf_decay_rate <=
-            (ARF_DECAY_THRESH + (cpi->gfu_boost / 200))) )
-#endif
-    {
-        int Boost;
-        int allocation_chunks;
-        int Q = (cpi->oxcf.fixed_q < 0)
-                ? cpi->last_q[INTER_FRAME] : cpi->oxcf.fixed_q;
-        int tmp_q;
-        int arf_frame_bits = 0;
-        int group_bits;
-
-#if NEW_BOOST
-        cpi->gfu_boost = alt_boost;
-#endif
-
-        /* Estimate the bits to be allocated to the group as a whole */
-        if ((cpi->twopass.kf_group_bits > 0) &&
-            (cpi->twopass.kf_group_error_left > 0))
-        {
-            group_bits = (int)((double)cpi->twopass.kf_group_bits *
-                (gf_group_err / (double)cpi->twopass.kf_group_error_left));
-        }
-        else
-            group_bits = 0;
-
-        /* Boost for arf frame */
-#if NEW_BOOST
-        Boost = (alt_boost * GFQ_ADJUSTMENT) / 100;
-#else
-        Boost = (cpi->gfu_boost * 3 * GFQ_ADJUSTMENT) / (2 * 100);
-#endif
-        Boost += (i * 50);
-
-        /* Set max and minimum boost and hence minimum allocation */
-        if (Boost > ((cpi->baseline_gf_interval + 1) * 200))
-            Boost = ((cpi->baseline_gf_interval + 1) * 200);
-        else if (Boost < 125)
-            Boost = 125;
-
-        allocation_chunks = (i * 100) + Boost;
-
-        /* Normalize Altboost and allocations chunck down to prevent overflow */
-        while (Boost > 1000)
-        {
-            Boost /= 2;
-            allocation_chunks /= 2;
-        }
-
-        /* Calculate the number of bits to be spent on the arf based on the
-         * boost number
-         */
-        arf_frame_bits = (int)((double)Boost * (group_bits /
-                               (double)allocation_chunks));
-
-        /* Estimate if there are enough bits available to make worthwhile use
-         * of an arf.
-         */
-        tmp_q = estimate_q(cpi, mod_frame_err, (int)arf_frame_bits);
-
-        /* Only use an arf if it is likely we will be able to code
-         * it at a lower Q than the surrounding frames.
-         */
-        if (tmp_q < cpi->worst_quality)
-        {
-            int half_gf_int;
-            int frames_after_arf;
-            int frames_bwd = cpi->oxcf.arnr_max_frames - 1;
-            int frames_fwd = cpi->oxcf.arnr_max_frames - 1;
-
-            cpi->source_alt_ref_pending = 1;
-
-            /*
-             * For alt ref frames the error score for the end frame of the
-             * group (the alt ref frame) should not contribute to the group
-             * total and hence the number of bit allocated to the group.
-             * Rather it forms part of the next group (it is the GF at the
-             * start of the next group)
-             * gf_group_err -= mod_frame_err;
-             *
-             * For alt ref frames alt ref frame is technically part of the
-             * GF frame for the next group but we always base the error
-             * calculation and bit allocation on the current group of frames.
-             *
-             * Set the interval till the next gf or arf.
-             * For ARFs this is the number of frames to be coded before the
-             * future frame that is coded as an ARF.
-             * The future frame itself is part of the next group
-             */
-            cpi->baseline_gf_interval = i;
-
-            /*
-             * Define the arnr filter width for this group of frames:
-             * We only filter frames that lie within a distance of half
-             * the GF interval from the ARF frame. We also have to trap
-             * cases where the filter extends beyond the end of clip.
-             * Note: this_frame->frame has been updated in the loop
-             * so it now points at the ARF frame.
-             */
-            half_gf_int = cpi->baseline_gf_interval >> 1;
-            frames_after_arf = (int)(cpi->twopass.total_stats.count -
-                               this_frame->frame - 1);
-
-            switch (cpi->oxcf.arnr_type)
-            {
-            case 1: /* Backward filter */
-                frames_fwd = 0;
-                if (frames_bwd > half_gf_int)
-                    frames_bwd = half_gf_int;
-                break;
-
-            case 2: /* Forward filter */
-                if (frames_fwd > half_gf_int)
-                    frames_fwd = half_gf_int;
-                if (frames_fwd > frames_after_arf)
-                    frames_fwd = frames_after_arf;
-                frames_bwd = 0;
-                break;
-
-            case 3: /* Centered filter */
-            default:
-                frames_fwd >>= 1;
-                if (frames_fwd > frames_after_arf)
-                    frames_fwd = frames_after_arf;
-                if (frames_fwd > half_gf_int)
-                    frames_fwd = half_gf_int;
-
-                frames_bwd = frames_fwd;
-
-                /* For even length filter there is one more frame backward
-                 * than forward: e.g. len=6 ==> bbbAff, len=7 ==> bbbAfff.
-                 */
-                if (frames_bwd < half_gf_int)
-                    frames_bwd += (cpi->oxcf.arnr_max_frames+1) & 0x1;
-                break;
-            }
-
-            cpi->active_arnr_frames = frames_bwd + 1 + frames_fwd;
-        }
-        else
-        {
-            cpi->source_alt_ref_pending = 0;
-            cpi->baseline_gf_interval = i;
-        }
-    }
-    else
-    {
-        cpi->source_alt_ref_pending = 0;
-        cpi->baseline_gf_interval = i;
-    }
-
-    /*
-     * Now decide how many bits should be allocated to the GF group as  a
-     * proportion of those remaining in the kf group.
-     * The final key frame group in the clip is treated as a special case
-     * where cpi->twopass.kf_group_bits is tied to cpi->twopass.bits_left.
-     * This is also important for short clips where there may only be one
-     * key frame.
-     */
-    if (cpi->twopass.frames_to_key >= (int)(cpi->twopass.total_stats.count -
-                                            cpi->common.current_video_frame))
-    {
-        cpi->twopass.kf_group_bits =
-            (cpi->twopass.bits_left > 0) ? cpi->twopass.bits_left : 0;
-    }
-
-    /* Calculate the bits to be allocated to the group as a whole */
-    if ((cpi->twopass.kf_group_bits > 0) &&
-        (cpi->twopass.kf_group_error_left > 0))
-    {
-        cpi->twopass.gf_group_bits =
-            (int64_t)(cpi->twopass.kf_group_bits *
-                      (gf_group_err / cpi->twopass.kf_group_error_left));
-    }
-    else
-        cpi->twopass.gf_group_bits = 0;
-
-    cpi->twopass.gf_group_bits =
-        (cpi->twopass.gf_group_bits < 0)
-            ? 0
-            : (cpi->twopass.gf_group_bits > cpi->twopass.kf_group_bits)
-                ? cpi->twopass.kf_group_bits : cpi->twopass.gf_group_bits;
-
-    /* Clip cpi->twopass.gf_group_bits based on user supplied data rate
-     * variability limit (cpi->oxcf.two_pass_vbrmax_section)
-     */
-    if (cpi->twopass.gf_group_bits >
-        (int64_t)max_bits * cpi->baseline_gf_interval)
-        cpi->twopass.gf_group_bits =
-            (int64_t)max_bits * cpi->baseline_gf_interval;
-
-    /* Reset the file position */
-    reset_fpf_position(cpi, start_pos);
-
-    /* Update the record of error used so far (only done once per gf group) */
-    cpi->twopass.modified_error_used += gf_group_err;
-
-    /* Assign  bits to the arf or gf. */
-    for (i = 0; i <= (cpi->source_alt_ref_pending && cpi->common.frame_type != KEY_FRAME); i++) {
-        int Boost;
-        int allocation_chunks;
-        int Q = (cpi->oxcf.fixed_q < 0) ? cpi->last_q[INTER_FRAME] : cpi->oxcf.fixed_q;
-        int gf_bits;
-
-        /* For ARF frames */
-        if (cpi->source_alt_ref_pending && i == 0)
-        {
-#if NEW_BOOST
-            Boost = (alt_boost * GFQ_ADJUSTMENT) / 100;
-#else
-            Boost = (cpi->gfu_boost * 3 * GFQ_ADJUSTMENT) / (2 * 100);
-#endif
-            Boost += (cpi->baseline_gf_interval * 50);
-
-            /* Set max and minimum boost and hence minimum allocation */
-            if (Boost > ((cpi->baseline_gf_interval + 1) * 200))
-                Boost = ((cpi->baseline_gf_interval + 1) * 200);
-            else if (Boost < 125)
-                Boost = 125;
-
-            allocation_chunks =
-                ((cpi->baseline_gf_interval + 1) * 100) + Boost;
-        }
-        /* Else for standard golden frames */
-        else
-        {
-            /* boost based on inter / intra ratio of subsequent frames */
-            Boost = (cpi->gfu_boost * GFQ_ADJUSTMENT) / 100;
-
-            /* Set max and minimum boost and hence minimum allocation */
-            if (Boost > (cpi->baseline_gf_interval * 150))
-                Boost = (cpi->baseline_gf_interval * 150);
-            else if (Boost < 125)
-                Boost = 125;
-
-            allocation_chunks =
-                (cpi->baseline_gf_interval * 100) + (Boost - 100);
-        }
-
-        /* Normalize Altboost and allocations chunck down to prevent overflow */
-        while (Boost > 1000)
-        {
-            Boost /= 2;
-            allocation_chunks /= 2;
-        }
-
-        /* Calculate the number of bits to be spent on the gf or arf based on
-         * the boost number
-         */
-        gf_bits = (int)((double)Boost *
-                        (cpi->twopass.gf_group_bits /
-                         (double)allocation_chunks));
-
-        /* If the frame that is to be boosted is simpler than the average for
-         * the gf/arf group then use an alternative calculation
-         * based on the error score of the frame itself
-         */
-        if (mod_frame_err < gf_group_err / (double)cpi->baseline_gf_interval)
-        {
-            double  alt_gf_grp_bits;
-            int     alt_gf_bits;
-
-            alt_gf_grp_bits =
-                (double)cpi->twopass.kf_group_bits  *
-                (mod_frame_err * (double)cpi->baseline_gf_interval) /
-                DOUBLE_DIVIDE_CHECK((double)cpi->twopass.kf_group_error_left);
-
-            alt_gf_bits = (int)((double)Boost * (alt_gf_grp_bits /
-                                                 (double)allocation_chunks));
-
-            if (gf_bits > alt_gf_bits)
-            {
-                gf_bits = alt_gf_bits;
-            }
-        }
-        /* Else if it is harder than other frames in the group make sure it at
-         * least receives an allocation in keeping with its relative error
-         * score, otherwise it may be worse off than an "un-boosted" frame
-         */
-        else
-        {
-            int alt_gf_bits =
-                (int)((double)cpi->twopass.kf_group_bits *
-                      mod_frame_err /
-                      DOUBLE_DIVIDE_CHECK((double)cpi->twopass.kf_group_error_left));
-
-            if (alt_gf_bits > gf_bits)
-            {
-                gf_bits = alt_gf_bits;
-            }
-        }
-
-        /* Apply an additional limit for CBR */
-        if (cpi->oxcf.end_usage == USAGE_STREAM_FROM_SERVER)
-        {
-            if (cpi->twopass.gf_bits > (int)(cpi->buffer_level >> 1))
-                cpi->twopass.gf_bits = (int)(cpi->buffer_level >> 1);
-        }
-
-        /* Dont allow a negative value for gf_bits */
-        if (gf_bits < 0)
-            gf_bits = 0;
-
-        /* Add in minimum for a frame */
-        gf_bits += cpi->min_frame_bandwidth;
-
-        if (i == 0)
-        {
-            cpi->twopass.gf_bits = gf_bits;
-        }
-        if (i == 1 || (!cpi->source_alt_ref_pending && (cpi->common.frame_type != KEY_FRAME)))
-        {
-            /* Per frame bit target for this frame */
-            cpi->per_frame_bandwidth = gf_bits;
-        }
-    }
-
-    {
-        /* Adjust KF group bits and error remainin */
-        cpi->twopass.kf_group_error_left -= (int64_t)gf_group_err;
-        cpi->twopass.kf_group_bits -= cpi->twopass.gf_group_bits;
-
-        if (cpi->twopass.kf_group_bits < 0)
-            cpi->twopass.kf_group_bits = 0;
-
-        /* Note the error score left in the remaining frames of the group.
-         * For normal GFs we want to remove the error score for the first
-         * frame of the group (except in Key frame case where this has
-         * already happened)
-         */
-        if (!cpi->source_alt_ref_pending && cpi->common.frame_type != KEY_FRAME)
-            cpi->twopass.gf_group_error_left = (int)(gf_group_err -
-                                                     gf_first_frame_err);
-        else
-            cpi->twopass.gf_group_error_left = (int) gf_group_err;
-
-        cpi->twopass.gf_group_bits -= cpi->twopass.gf_bits - cpi->min_frame_bandwidth;
-
-        if (cpi->twopass.gf_group_bits < 0)
-            cpi->twopass.gf_group_bits = 0;
-
-        /* This condition could fail if there are two kfs very close together
-         * despite (MIN_GF_INTERVAL) and would cause a devide by 0 in the
-         * calculation of cpi->twopass.alt_extra_bits.
-         */
-        if ( cpi->baseline_gf_interval >= 3 )
-        {
-#if NEW_BOOST
-            int boost = (cpi->source_alt_ref_pending)
-                        ? b_boost : cpi->gfu_boost;
-#else
-            int boost = cpi->gfu_boost;
-#endif
-            if ( boost >= 150 )
-            {
-                int pct_extra;
-
-                pct_extra = (boost - 100) / 50;
-                pct_extra = (pct_extra > 20) ? 20 : pct_extra;
-
-                cpi->twopass.alt_extra_bits =
-                    (int)(cpi->twopass.gf_group_bits * pct_extra) / 100;
-                cpi->twopass.gf_group_bits -= cpi->twopass.alt_extra_bits;
-                cpi->twopass.alt_extra_bits /=
-                    ((cpi->baseline_gf_interval-1)>>1);
-            }
-            else
-                cpi->twopass.alt_extra_bits = 0;
-        }
-        else
-            cpi->twopass.alt_extra_bits = 0;
-    }
-
-    /* Adjustments based on a measure of complexity of the section */
-    if (cpi->common.frame_type != KEY_FRAME)
-    {
-        FIRSTPASS_STATS sectionstats;
-        double Ratio;
-
-        zero_stats(&sectionstats);
-        reset_fpf_position(cpi, start_pos);
-
-        for (i = 0 ; i < cpi->baseline_gf_interval ; i++)
-        {
-            input_stats(cpi, &next_frame);
-            accumulate_stats(&sectionstats, &next_frame);
-        }
-
-        avg_stats(&sectionstats);
-
-        cpi->twopass.section_intra_rating = (unsigned int)
-            (sectionstats.intra_error /
-            DOUBLE_DIVIDE_CHECK(sectionstats.coded_error));
-
-        Ratio = sectionstats.intra_error / DOUBLE_DIVIDE_CHECK(sectionstats.coded_error);
-        cpi->twopass.section_max_qfactor = 1.0 - ((Ratio - 10.0) * 0.025);
-
-        if (cpi->twopass.section_max_qfactor < 0.80)
-            cpi->twopass.section_max_qfactor = 0.80;
-
-        reset_fpf_position(cpi, start_pos);
-    }
-}
-
-/* Allocate bits to a normal frame that is neither a gf an arf or a key frame. */
-static void assign_std_frame_bits(VP8_COMP *cpi, FIRSTPASS_STATS *this_frame)
-{
-    int    target_frame_size;
-
-    double modified_err;
-    double err_fraction;
-
-    int max_bits = frame_max_bits(cpi);  /* Max for a single frame */
-
-    /* Calculate modified prediction error used in bit allocation */
-    modified_err = calculate_modified_err(cpi, this_frame);
-
-    /* What portion of the remaining GF group error is used by this frame */
-    if (cpi->twopass.gf_group_error_left > 0)
-        err_fraction = modified_err / cpi->twopass.gf_group_error_left;
-    else
-        err_fraction = 0.0;
-
-    /* How many of those bits available for allocation should we give it? */
-    target_frame_size = (int)((double)cpi->twopass.gf_group_bits * err_fraction);
-
-    /* Clip to target size to 0 - max_bits (or cpi->twopass.gf_group_bits)
-     * at the top end.
-     */
-    if (target_frame_size < 0)
-        target_frame_size = 0;
-    else
-    {
-        if (target_frame_size > max_bits)
-            target_frame_size = max_bits;
-
-        if (target_frame_size > cpi->twopass.gf_group_bits)
-            target_frame_size = (int)cpi->twopass.gf_group_bits;
-    }
-
-    /* Adjust error and bits remaining */
-    cpi->twopass.gf_group_error_left -= (int)modified_err;
-    cpi->twopass.gf_group_bits -= target_frame_size;
-
-    if (cpi->twopass.gf_group_bits < 0)
-        cpi->twopass.gf_group_bits = 0;
-
-    /* Add in the minimum number of bits that is set aside for every frame. */
-    target_frame_size += cpi->min_frame_bandwidth;
-
-    /* Every other frame gets a few extra bits */
-    if ( (cpi->frames_since_golden & 0x01) &&
-         (cpi->frames_till_gf_update_due > 0) )
-    {
-        target_frame_size += cpi->twopass.alt_extra_bits;
-    }
-
-    /* Per frame bit target for this frame */
-    cpi->per_frame_bandwidth = target_frame_size;
-}
-
-void vp8_second_pass(VP8_COMP *cpi)
-{
-    int tmp_q;
-    int frames_left = (int)(cpi->twopass.total_stats.count - cpi->common.current_video_frame);
-
-    FIRSTPASS_STATS this_frame;
-    FIRSTPASS_STATS this_frame_copy;
-
-    double this_frame_intra_error;
-    double this_frame_coded_error;
-
-    int overhead_bits;
-
-    vp8_zero(this_frame);
-
-    if (!cpi->twopass.stats_in)
-    {
-        return ;
-    }
-
-    vp8_clear_system_state();
-
-    if (EOF == input_stats(cpi, &this_frame))
-        return;
-
-    this_frame_intra_error = this_frame.intra_error;
-    this_frame_coded_error = this_frame.coded_error;
-
-    /* keyframe and section processing ! */
-    if (cpi->twopass.frames_to_key == 0)
-    {
-        /* Define next KF group and assign bits to it */
-        memcpy(&this_frame_copy, &this_frame, sizeof(this_frame));
-        find_next_key_frame(cpi, &this_frame_copy);
-
-        /* Special case: Error error_resilient_mode mode does not make much
-         * sense for two pass but with its current meaning this code is
-         * designed to stop outlandish behaviour if someone does set it when
-         * using two pass. It effectively disables GF groups. This is
-         * temporary code until we decide what should really happen in this
-         * case.
-         */
-        if (cpi->oxcf.error_resilient_mode)
-        {
-            cpi->twopass.gf_group_bits = cpi->twopass.kf_group_bits;
-            cpi->twopass.gf_group_error_left =
-                                  (int)cpi->twopass.kf_group_error_left;
-            cpi->baseline_gf_interval = cpi->twopass.frames_to_key;
-            cpi->frames_till_gf_update_due = cpi->baseline_gf_interval;
-            cpi->source_alt_ref_pending = 0;
-        }
-
-    }
-
-    /* Is this a GF / ARF (Note that a KF is always also a GF) */
-    if (cpi->frames_till_gf_update_due == 0)
-    {
-        /* Define next gf group and assign bits to it */
-        memcpy(&this_frame_copy, &this_frame, sizeof(this_frame));
-        define_gf_group(cpi, &this_frame_copy);
-
-        /* If we are going to code an altref frame at the end of the group
-         * and the current frame is not a key frame.... If the previous
-         * group used an arf this frame has already benefited from that arf
-         * boost and it should not be given extra bits If the previous
-         * group was NOT coded using arf we may want to apply some boost to
-         * this GF as well
-         */
-        if (cpi->source_alt_ref_pending && (cpi->common.frame_type != KEY_FRAME))
-        {
-            /* Assign a standard frames worth of bits from those allocated
-             * to the GF group
-             */
-            int bak = cpi->per_frame_bandwidth;
-            memcpy(&this_frame_copy, &this_frame, sizeof(this_frame));
-            assign_std_frame_bits(cpi, &this_frame_copy);
-            cpi->per_frame_bandwidth = bak;
-        }
-    }
-
-    /* Otherwise this is an ordinary frame */
-    else
-    {
-        /* Special case: Error error_resilient_mode mode does not make much
-         * sense for two pass but with its current meaning but this code is
-         * designed to stop outlandish behaviour if someone does set it
-         * when using two pass. It effectively disables GF groups. This is
-         * temporary code till we decide what should really happen in this
-         * case.
-         */
-        if (cpi->oxcf.error_resilient_mode)
-        {
-            cpi->frames_till_gf_update_due = cpi->twopass.frames_to_key;
-
-            if (cpi->common.frame_type != KEY_FRAME)
-            {
-                /* Assign bits from those allocated to the GF group */
-                memcpy(&this_frame_copy, &this_frame, sizeof(this_frame));
-                assign_std_frame_bits(cpi, &this_frame_copy);
-            }
-        }
-        else
-        {
-            /* Assign bits from those allocated to the GF group */
-            memcpy(&this_frame_copy, &this_frame, sizeof(this_frame));
-            assign_std_frame_bits(cpi, &this_frame_copy);
-        }
-    }
-
-    /* Keep a globally available copy of this and the next frame's iiratio. */
-    cpi->twopass.this_iiratio = (unsigned int)(this_frame_intra_error /
-                        DOUBLE_DIVIDE_CHECK(this_frame_coded_error));
-    {
-        FIRSTPASS_STATS next_frame;
-        if ( lookup_next_frame_stats(cpi, &next_frame) != EOF )
-        {
-            cpi->twopass.next_iiratio = (unsigned int)(next_frame.intra_error /
-                                DOUBLE_DIVIDE_CHECK(next_frame.coded_error));
-        }
-    }
-
-    /* Set nominal per second bandwidth for this frame */
-    cpi->target_bandwidth = (int)
-    (cpi->per_frame_bandwidth * cpi->output_framerate);
-    if (cpi->target_bandwidth < 0)
-        cpi->target_bandwidth = 0;
-
-
-    /* Account for mv, mode and other overheads. */
-    overhead_bits = (int)estimate_modemvcost(
-                        cpi, &cpi->twopass.total_left_stats );
-
-    /* Special case code for first frame. */
-    if (cpi->common.current_video_frame == 0)
-    {
-        cpi->twopass.est_max_qcorrection_factor = 1.0;
-
-        /* Set a cq_level in constrained quality mode. */
-        if ( cpi->oxcf.end_usage == USAGE_CONSTRAINED_QUALITY )
-        {
-            int est_cq;
-
-            est_cq =
-                estimate_cq( cpi,
-                             &cpi->twopass.total_left_stats,
-                             (int)(cpi->twopass.bits_left / frames_left),
-                             overhead_bits );
-
-            cpi->cq_target_quality = cpi->oxcf.cq_level;
-            if ( est_cq > cpi->cq_target_quality )
-                cpi->cq_target_quality = est_cq;
-        }
-
-        /* guess at maxq needed in 2nd pass */
-        cpi->twopass.maxq_max_limit = cpi->worst_quality;
-        cpi->twopass.maxq_min_limit = cpi->best_quality;
-
-        tmp_q = estimate_max_q(
-                    cpi,
-                    &cpi->twopass.total_left_stats,
-                    (int)(cpi->twopass.bits_left / frames_left),
-                    overhead_bits );
-
-        /* Limit the maxq value returned subsequently.
-         * This increases the risk of overspend or underspend if the initial
-         * estimate for the clip is bad, but helps prevent excessive
-         * variation in Q, especially near the end of a clip
-         * where for example a small overspend may cause Q to crash
-         */
-        cpi->twopass.maxq_max_limit = ((tmp_q + 32) < cpi->worst_quality)
-                                  ? (tmp_q + 32) : cpi->worst_quality;
-        cpi->twopass.maxq_min_limit = ((tmp_q - 32) > cpi->best_quality)
-                                  ? (tmp_q - 32) : cpi->best_quality;
-
-        cpi->active_worst_quality         = tmp_q;
-        cpi->ni_av_qi                     = tmp_q;
-    }
-
-    /* The last few frames of a clip almost always have to few or too many
-     * bits and for the sake of over exact rate control we dont want to make
-     * radical adjustments to the allowed quantizer range just to use up a
-     * few surplus bits or get beneath the target rate.
-     */
-    else if ( (cpi->common.current_video_frame <
-                 (((unsigned int)cpi->twopass.total_stats.count * 255)>>8)) &&
-              ((cpi->common.current_video_frame + cpi->baseline_gf_interval) <
-                 (unsigned int)cpi->twopass.total_stats.count) )
-    {
-        if (frames_left < 1)
-            frames_left = 1;
-
-        tmp_q = estimate_max_q(
-                    cpi,
-                    &cpi->twopass.total_left_stats,
-                    (int)(cpi->twopass.bits_left / frames_left),
-                    overhead_bits );
-
-        /* Move active_worst_quality but in a damped way */
-        if (tmp_q > cpi->active_worst_quality)
-            cpi->active_worst_quality ++;
-        else if (tmp_q < cpi->active_worst_quality)
-            cpi->active_worst_quality --;
-
-        cpi->active_worst_quality =
-            ((cpi->active_worst_quality * 3) + tmp_q + 2) / 4;
-    }
-
-    cpi->twopass.frames_to_key --;
-
-    /* Update the total stats remaining sturcture */
-    subtract_stats(&cpi->twopass.total_left_stats, &this_frame );
-}
-
-
-static int test_candidate_kf(VP8_COMP *cpi,  FIRSTPASS_STATS *last_frame, FIRSTPASS_STATS *this_frame, FIRSTPASS_STATS *next_frame)
-{
-    int is_viable_kf = 0;
-
-    /* Does the frame satisfy the primary criteria of a key frame
-     *      If so, then examine how well it predicts subsequent frames
-     */
-    if ((this_frame->pcnt_second_ref < 0.10) &&
-        (next_frame->pcnt_second_ref < 0.10) &&
-        ((this_frame->pcnt_inter < 0.05) ||
-         (
-             ((this_frame->pcnt_inter - this_frame->pcnt_neutral) < .25) &&
-             ((this_frame->intra_error / DOUBLE_DIVIDE_CHECK(this_frame->coded_error)) < 2.5) &&
-             ((fabs(last_frame->coded_error - this_frame->coded_error) / DOUBLE_DIVIDE_CHECK(this_frame->coded_error) > .40) ||
-              (fabs(last_frame->intra_error - this_frame->intra_error) / DOUBLE_DIVIDE_CHECK(this_frame->intra_error) > .40) ||
-              ((next_frame->intra_error / DOUBLE_DIVIDE_CHECK(next_frame->coded_error)) > 3.5)
-             )
-         )
-        )
-       )
-    {
-        int i;
-        FIRSTPASS_STATS *start_pos;
-
-        FIRSTPASS_STATS local_next_frame;
-
-        double boost_score = 0.0;
-        double old_boost_score = 0.0;
-        double decay_accumulator = 1.0;
-        double next_iiratio;
-
-        memcpy(&local_next_frame, next_frame, sizeof(*next_frame));
-
-        /* Note the starting file position so we can reset to it */
-        start_pos = cpi->twopass.stats_in;
-
-        /* Examine how well the key frame predicts subsequent frames */
-        for (i = 0 ; i < 16; i++)
-        {
-            next_iiratio = (IIKFACTOR1 * local_next_frame.intra_error / DOUBLE_DIVIDE_CHECK(local_next_frame.coded_error)) ;
-
-            if (next_iiratio > RMAX)
-                next_iiratio = RMAX;
-
-            /* Cumulative effect of decay in prediction quality */
-            if (local_next_frame.pcnt_inter > 0.85)
-                decay_accumulator = decay_accumulator * local_next_frame.pcnt_inter;
-            else
-                decay_accumulator = decay_accumulator * ((0.85 + local_next_frame.pcnt_inter) / 2.0);
-
-            /* Keep a running total */
-            boost_score += (decay_accumulator * next_iiratio);
-
-            /* Test various breakout clauses */
-            if ((local_next_frame.pcnt_inter < 0.05) ||
-                (next_iiratio < 1.5) ||
-                (((local_next_frame.pcnt_inter -
-                   local_next_frame.pcnt_neutral) < 0.20) &&
-                 (next_iiratio < 3.0)) ||
-                ((boost_score - old_boost_score) < 0.5) ||
-                (local_next_frame.intra_error < 200)
-               )
-            {
-                break;
-            }
-
-            old_boost_score = boost_score;
-
-            /* Get the next frame details */
-            if (EOF == input_stats(cpi, &local_next_frame))
-                break;
-        }
-
-        /* If there is tolerable prediction for at least the next 3 frames
-         * then break out else discard this pottential key frame and move on
-         */
-        if (boost_score > 5.0 && (i > 3))
-            is_viable_kf = 1;
-        else
-        {
-            /* Reset the file position */
-            reset_fpf_position(cpi, start_pos);
-
-            is_viable_kf = 0;
-        }
-    }
-
-    return is_viable_kf;
-}
-static void find_next_key_frame(VP8_COMP *cpi, FIRSTPASS_STATS *this_frame)
-{
-    int i,j;
-    FIRSTPASS_STATS last_frame;
-    FIRSTPASS_STATS first_frame;
-    FIRSTPASS_STATS next_frame;
-    FIRSTPASS_STATS *start_position;
-
-    double decay_accumulator = 1.0;
-    double boost_score = 0;
-    double old_boost_score = 0.0;
-    double loop_decay_rate;
-
-    double kf_mod_err = 0.0;
-    double kf_group_err = 0.0;
-    double kf_group_intra_err = 0.0;
-    double kf_group_coded_err = 0.0;
-    double recent_loop_decay[8] = {1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0};
-
-    memset(&next_frame, 0, sizeof(next_frame));
-
-    vp8_clear_system_state();
-    start_position = cpi->twopass.stats_in;
-
-    cpi->common.frame_type = KEY_FRAME;
-
-    /* is this a forced key frame by interval */
-    cpi->this_key_frame_forced = cpi->next_key_frame_forced;
-
-    /* Clear the alt ref active flag as this can never be active on a key
-     * frame
-     */
-    cpi->source_alt_ref_active = 0;
-
-    /* Kf is always a gf so clear frames till next gf counter */
-    cpi->frames_till_gf_update_due = 0;
-
-    cpi->twopass.frames_to_key = 1;
-
-    /* Take a copy of the initial frame details */
-    memcpy(&first_frame, this_frame, sizeof(*this_frame));
-
-    cpi->twopass.kf_group_bits = 0;
-    cpi->twopass.kf_group_error_left = 0;
-
-    kf_mod_err = calculate_modified_err(cpi, this_frame);
-
-    /* find the next keyframe */
-    i = 0;
-    while (cpi->twopass.stats_in < cpi->twopass.stats_in_end)
-    {
-        /* Accumulate kf group error */
-        kf_group_err += calculate_modified_err(cpi, this_frame);
-
-        /* These figures keep intra and coded error counts for all frames
-         * including key frames in the group. The effect of the key frame
-         * itself can be subtracted out using the first_frame data
-         * collected above
-         */
-        kf_group_intra_err += this_frame->intra_error;
-        kf_group_coded_err += this_frame->coded_error;
-
-        /* Load the next frame's stats. */
-        memcpy(&last_frame, this_frame, sizeof(*this_frame));
-        input_stats(cpi, this_frame);
-
-        /* Provided that we are not at the end of the file... */
-        if (cpi->oxcf.auto_key
-            && lookup_next_frame_stats(cpi, &next_frame) != EOF)
-        {
-            /* Normal scene cut check */
-            if ( ( i >= MIN_GF_INTERVAL ) &&
-                 test_candidate_kf(cpi, &last_frame, this_frame, &next_frame) )
-            {
-                break;
-            }
-
-            /* How fast is prediction quality decaying */
-            loop_decay_rate = get_prediction_decay_rate(cpi, &next_frame);
-
-            /* We want to know something about the recent past... rather than
-             * as used elsewhere where we are concened with decay in prediction
-             * quality since the last GF or KF.
-             */
-            recent_loop_decay[i%8] = loop_decay_rate;
-            decay_accumulator = 1.0;
-            for (j = 0; j < 8; j++)
-            {
-                decay_accumulator = decay_accumulator * recent_loop_decay[j];
-            }
-
-            /* Special check for transition or high motion followed by a
-             * static scene.
-             */
-            if ( detect_transition_to_still( cpi, i,
-                                             ((int)(cpi->key_frame_frequency) -
-                                              (int)i),
-                                             loop_decay_rate,
-                                             decay_accumulator ) )
-            {
-                break;
-            }
-
-
-            /* Step on to the next frame */
-            cpi->twopass.frames_to_key ++;
-
-            /* If we don't have a real key frame within the next two
-             * forcekeyframeevery intervals then break out of the loop.
-             */
-            if (cpi->twopass.frames_to_key >= 2 *(int)cpi->key_frame_frequency)
-                break;
-        } else
-            cpi->twopass.frames_to_key ++;
-
-        i++;
-    }
-
-    /* If there is a max kf interval set by the user we must obey it.
-     * We already breakout of the loop above at 2x max.
-     * This code centers the extra kf if the actual natural
-     * interval is between 1x and 2x
-     */
-    if (cpi->oxcf.auto_key
-        && cpi->twopass.frames_to_key > (int)cpi->key_frame_frequency )
-    {
-        FIRSTPASS_STATS *current_pos = cpi->twopass.stats_in;
-        FIRSTPASS_STATS tmp_frame;
-
-        cpi->twopass.frames_to_key /= 2;
-
-        /* Copy first frame details */
-        memcpy(&tmp_frame, &first_frame, sizeof(first_frame));
-
-        /* Reset to the start of the group */
-        reset_fpf_position(cpi, start_position);
-
-        kf_group_err = 0;
-        kf_group_intra_err = 0;
-        kf_group_coded_err = 0;
-
-        /* Rescan to get the correct error data for the forced kf group */
-        for( i = 0; i < cpi->twopass.frames_to_key; i++ )
-        {
-            /* Accumulate kf group errors */
-            kf_group_err += calculate_modified_err(cpi, &tmp_frame);
-            kf_group_intra_err += tmp_frame.intra_error;
-            kf_group_coded_err += tmp_frame.coded_error;
-
-            /* Load a the next frame's stats */
-            input_stats(cpi, &tmp_frame);
-        }
-
-        /* Reset to the start of the group */
-        reset_fpf_position(cpi, current_pos);
-
-        cpi->next_key_frame_forced = 1;
-    }
-    else
-        cpi->next_key_frame_forced = 0;
-
-    /* Special case for the last frame of the file */
-    if (cpi->twopass.stats_in >= cpi->twopass.stats_in_end)
-    {
-        /* Accumulate kf group error */
-        kf_group_err += calculate_modified_err(cpi, this_frame);
-
-        /* These figures keep intra and coded error counts for all frames
-         * including key frames in the group. The effect of the key frame
-         * itself can be subtracted out using the first_frame data
-         * collected above
-         */
-        kf_group_intra_err += this_frame->intra_error;
-        kf_group_coded_err += this_frame->coded_error;
-    }
-
-    /* Calculate the number of bits that should be assigned to the kf group. */
-    if ((cpi->twopass.bits_left > 0) && (cpi->twopass.modified_error_left > 0.0))
-    {
-        /* Max for a single normal frame (not key frame) */
-        int max_bits = frame_max_bits(cpi);
-
-        /* Maximum bits for the kf group */
-        int64_t max_grp_bits;
-
-        /* Default allocation based on bits left and relative
-         * complexity of the section
-         */
-        cpi->twopass.kf_group_bits = (int64_t)( cpi->twopass.bits_left *
-                                          ( kf_group_err /
-                                            cpi->twopass.modified_error_left ));
-
-        /* Clip based on maximum per frame rate defined by the user. */
-        max_grp_bits = (int64_t)max_bits * (int64_t)cpi->twopass.frames_to_key;
-        if (cpi->twopass.kf_group_bits > max_grp_bits)
-            cpi->twopass.kf_group_bits = max_grp_bits;
-
-        /* Additional special case for CBR if buffer is getting full. */
-        if (cpi->oxcf.end_usage == USAGE_STREAM_FROM_SERVER)
-        {
-            int64_t opt_buffer_lvl = cpi->oxcf.optimal_buffer_level;
-            int64_t buffer_lvl = cpi->buffer_level;
-
-            /* If the buffer is near or above the optimal and this kf group is
-             * not being allocated much then increase the allocation a bit.
-             */
-            if (buffer_lvl >= opt_buffer_lvl)
-            {
-                int64_t high_water_mark = (opt_buffer_lvl +
-                                       cpi->oxcf.maximum_buffer_size) >> 1;
-
-                int64_t av_group_bits;
-
-                /* Av bits per frame * number of frames */
-                av_group_bits = (int64_t)cpi->av_per_frame_bandwidth *
-                                (int64_t)cpi->twopass.frames_to_key;
-
-                /* We are at or above the maximum. */
-                if (cpi->buffer_level >= high_water_mark)
-                {
-                    int64_t min_group_bits;
-
-                    min_group_bits = av_group_bits +
-                                     (int64_t)(buffer_lvl -
-                                                 high_water_mark);
-
-                    if (cpi->twopass.kf_group_bits < min_group_bits)
-                        cpi->twopass.kf_group_bits = min_group_bits;
-                }
-                /* We are above optimal but below the maximum */
-                else if (cpi->twopass.kf_group_bits < av_group_bits)
-                {
-                    int64_t bits_below_av = av_group_bits -
-                                              cpi->twopass.kf_group_bits;
-
-                    cpi->twopass.kf_group_bits +=
-                       (int64_t)((double)bits_below_av *
-                                   (double)(buffer_lvl - opt_buffer_lvl) /
-                                   (double)(high_water_mark - opt_buffer_lvl));
-                }
-            }
-        }
-    }
-    else
-        cpi->twopass.kf_group_bits = 0;
-
-    /* Reset the first pass file position */
-    reset_fpf_position(cpi, start_position);
-
-    /* determine how big to make this keyframe based on how well the
-     * subsequent frames use inter blocks
-     */
-    decay_accumulator = 1.0;
-    boost_score = 0.0;
-
-    for (i = 0 ; i < cpi->twopass.frames_to_key ; i++)
-    {
-        double r;
-
-        if (EOF == input_stats(cpi, &next_frame))
-            break;
-
-        if (next_frame.intra_error > cpi->twopass.kf_intra_err_min)
-            r = (IIKFACTOR2 * next_frame.intra_error /
-                     DOUBLE_DIVIDE_CHECK(next_frame.coded_error));
-        else
-            r = (IIKFACTOR2 * cpi->twopass.kf_intra_err_min /
-                     DOUBLE_DIVIDE_CHECK(next_frame.coded_error));
-
-        if (r > RMAX)
-            r = RMAX;
-
-        /* How fast is prediction quality decaying */
-        loop_decay_rate = get_prediction_decay_rate(cpi, &next_frame);
-
-        decay_accumulator = decay_accumulator * loop_decay_rate;
-        decay_accumulator = decay_accumulator < 0.1 ? 0.1 : decay_accumulator;
-
-        boost_score += (decay_accumulator * r);
-
-        if ((i > MIN_GF_INTERVAL) &&
-            ((boost_score - old_boost_score) < 1.0))
-        {
-            break;
-        }
-
-        old_boost_score = boost_score;
-    }
-
-    if (1)
-    {
-        FIRSTPASS_STATS sectionstats;
-        double Ratio;
-
-        zero_stats(&sectionstats);
-        reset_fpf_position(cpi, start_position);
-
-        for (i = 0 ; i < cpi->twopass.frames_to_key ; i++)
-        {
-            input_stats(cpi, &next_frame);
-            accumulate_stats(&sectionstats, &next_frame);
-        }
-
-        avg_stats(&sectionstats);
-
-        cpi->twopass.section_intra_rating = (unsigned int)
-            (sectionstats.intra_error
-            / DOUBLE_DIVIDE_CHECK(sectionstats.coded_error));
-
-        Ratio = sectionstats.intra_error / DOUBLE_DIVIDE_CHECK(sectionstats.coded_error);
-        cpi->twopass.section_max_qfactor = 1.0 - ((Ratio - 10.0) * 0.025);
-
-        if (cpi->twopass.section_max_qfactor < 0.80)
-            cpi->twopass.section_max_qfactor = 0.80;
-    }
-
-    /* When using CBR apply additional buffer fullness related upper limits */
-    if (cpi->oxcf.end_usage == USAGE_STREAM_FROM_SERVER)
-    {
-        double max_boost;
-
-        if (cpi->drop_frames_allowed)
-        {
-            int df_buffer_level = (int)(cpi->oxcf.drop_frames_water_mark
-                                  * (cpi->oxcf.optimal_buffer_level / 100));
-
-            if (cpi->buffer_level > df_buffer_level)
-                max_boost = ((double)((cpi->buffer_level - df_buffer_level) * 2 / 3) * 16.0) / DOUBLE_DIVIDE_CHECK((double)cpi->av_per_frame_bandwidth);
-            else
-                max_boost = 0.0;
-        }
-        else if (cpi->buffer_level > 0)
-        {
-            max_boost = ((double)(cpi->buffer_level * 2 / 3) * 16.0) / DOUBLE_DIVIDE_CHECK((double)cpi->av_per_frame_bandwidth);
-        }
-        else
-        {
-            max_boost = 0.0;
-        }
-
-        if (boost_score > max_boost)
-            boost_score = max_boost;
-    }
-
-    /* Reset the first pass file position */
-    reset_fpf_position(cpi, start_position);
-
-    /* Work out how many bits to allocate for the key frame itself */
-    if (1)
-    {
-        int kf_boost = (int)boost_score;
-        int allocation_chunks;
-        int Counter = cpi->twopass.frames_to_key;
-        int alt_kf_bits;
-        YV12_BUFFER_CONFIG *lst_yv12 = &cpi->common.yv12_fb[cpi->common.lst_fb_idx];
-        /* Min boost based on kf interval */
-#if 0
-
-        while ((kf_boost < 48) && (Counter > 0))
-        {
-            Counter -= 2;
-            kf_boost ++;
-        }
-
-#endif
-
-        if (kf_boost < 48)
-        {
-            kf_boost += ((Counter + 1) >> 1);
-
-            if (kf_boost > 48) kf_boost = 48;
-        }
-
-        /* bigger frame sizes need larger kf boosts, smaller frames smaller
-         * boosts...
-         */
-        if ((lst_yv12->y_width * lst_yv12->y_height) > (320 * 240))
-            kf_boost += 2 * (lst_yv12->y_width * lst_yv12->y_height) / (320 * 240);
-        else if ((lst_yv12->y_width * lst_yv12->y_height) < (320 * 240))
-            kf_boost -= 4 * (320 * 240) / (lst_yv12->y_width * lst_yv12->y_height);
-
-        /* Min KF boost */
-        kf_boost = (int)((double)kf_boost * 100.0) >> 4; /* Scale 16 to 100 */
-        if (kf_boost < 250)
-            kf_boost = 250;
-
-        /*
-         * We do three calculations for kf size.
-         * The first is based on the error score for the whole kf group.
-         * The second (optionaly) on the key frames own error if this is
-         * smaller than the average for the group.
-         * The final one insures that the frame receives at least the
-         * allocation it would have received based on its own error score vs
-         * the error score remaining
-         * Special case if the sequence appears almost totaly static
-         * as measured by the decay accumulator. In this case we want to
-         * spend almost all of the bits on the key frame.
-         * cpi->twopass.frames_to_key-1 because key frame itself is taken
-         * care of by kf_boost.
-         */
-        if ( decay_accumulator >= 0.99 )
-        {
-            allocation_chunks =
-                ((cpi->twopass.frames_to_key - 1) * 10) + kf_boost;
-        }
-        else
-        {
-            allocation_chunks =
-                ((cpi->twopass.frames_to_key - 1) * 100) + kf_boost;
-        }
-
-        /* Normalize Altboost and allocations chunck down to prevent overflow */
-        while (kf_boost > 1000)
-        {
-            kf_boost /= 2;
-            allocation_chunks /= 2;
-        }
-
-        cpi->twopass.kf_group_bits = (cpi->twopass.kf_group_bits < 0) ? 0 : cpi->twopass.kf_group_bits;
-
-        /* Calculate the number of bits to be spent on the key frame */
-        cpi->twopass.kf_bits  = (int)((double)kf_boost * ((double)cpi->twopass.kf_group_bits / (double)allocation_chunks));
-
-        /* Apply an additional limit for CBR */
-        if (cpi->oxcf.end_usage == USAGE_STREAM_FROM_SERVER)
-        {
-            if (cpi->twopass.kf_bits > (int)((3 * cpi->buffer_level) >> 2))
-                cpi->twopass.kf_bits = (int)((3 * cpi->buffer_level) >> 2);
-        }
-
-        /* If the key frame is actually easier than the average for the
-         * kf group (which does sometimes happen... eg a blank intro frame)
-         * Then use an alternate calculation based on the kf error score
-         * which should give a smaller key frame.
-         */
-        if (kf_mod_err < kf_group_err / cpi->twopass.frames_to_key)
-        {
-            double  alt_kf_grp_bits =
-                        ((double)cpi->twopass.bits_left *
-                         (kf_mod_err * (double)cpi->twopass.frames_to_key) /
-                         DOUBLE_DIVIDE_CHECK(cpi->twopass.modified_error_left));
-
-            alt_kf_bits = (int)((double)kf_boost *
-                                (alt_kf_grp_bits / (double)allocation_chunks));
-
-            if (cpi->twopass.kf_bits > alt_kf_bits)
-            {
-                cpi->twopass.kf_bits = alt_kf_bits;
-            }
-        }
-        /* Else if it is much harder than other frames in the group make sure
-         * it at least receives an allocation in keeping with its relative
-         * error score
-         */
-        else
-        {
-            alt_kf_bits =
-                (int)((double)cpi->twopass.bits_left *
-                      (kf_mod_err /
-                       DOUBLE_DIVIDE_CHECK(cpi->twopass.modified_error_left)));
-
-            if (alt_kf_bits > cpi->twopass.kf_bits)
-            {
-                cpi->twopass.kf_bits = alt_kf_bits;
-            }
-        }
-
-        cpi->twopass.kf_group_bits -= cpi->twopass.kf_bits;
-        /* Add in the minimum frame allowance */
-        cpi->twopass.kf_bits += cpi->min_frame_bandwidth;
-
-        /* Peer frame bit target for this frame */
-        cpi->per_frame_bandwidth = cpi->twopass.kf_bits;
-
-        /* Convert to a per second bitrate */
-        cpi->target_bandwidth = (int)(cpi->twopass.kf_bits *
-                                      cpi->output_framerate);
-    }
-
-    /* Note the total error score of the kf group minus the key frame itself */
-    cpi->twopass.kf_group_error_left = (int)(kf_group_err - kf_mod_err);
-
-    /* Adjust the count of total modified error left. The count of bits left
-     * is adjusted elsewhere based on real coded frame sizes
-     */
-    cpi->twopass.modified_error_left -= kf_group_err;
-
-    if (cpi->oxcf.allow_spatial_resampling)
-    {
-        int resample_trigger = 0;
-        int last_kf_resampled = 0;
-        int kf_q;
-        int scale_val = 0;
-        int hr, hs, vr, vs;
-        int new_width = cpi->oxcf.Width;
-        int new_height = cpi->oxcf.Height;
-
-        int projected_buffer_level;
-        int tmp_q;
-
-        double projected_bits_perframe;
-        double group_iiratio = (kf_group_intra_err - first_frame.intra_error) / (kf_group_coded_err - first_frame.coded_error);
-        double err_per_frame = kf_group_err / cpi->twopass.frames_to_key;
-        double bits_per_frame;
-        double av_bits_per_frame;
-        double effective_size_ratio;
-
-        if ((cpi->common.Width != cpi->oxcf.Width) || (cpi->common.Height != cpi->oxcf.Height))
-            last_kf_resampled = 1;
-
-        /* Set back to unscaled by defaults */
-        cpi->common.horiz_scale = NORMAL;
-        cpi->common.vert_scale = NORMAL;
-
-        /* Calculate Average bits per frame. */
-        av_bits_per_frame = cpi->oxcf.target_bandwidth / DOUBLE_DIVIDE_CHECK((double)cpi->framerate);
-
-        /* CBR... Use the clip average as the target for deciding resample */
-        if (cpi->oxcf.end_usage == USAGE_STREAM_FROM_SERVER)
-        {
-            bits_per_frame = av_bits_per_frame;
-        }
-
-        /* In VBR we want to avoid downsampling in easy section unless we
-         * are under extreme pressure So use the larger of target bitrate
-         * for this section or average bitrate for sequence
-         */
-        else
-        {
-            /* This accounts for how hard the section is... */
-            bits_per_frame = (double)
-                (cpi->twopass.kf_group_bits / cpi->twopass.frames_to_key);
-
-            /* Dont turn to resampling in easy sections just because they
-             * have been assigned a small number of bits
-             */
-            if (bits_per_frame < av_bits_per_frame)
-                bits_per_frame = av_bits_per_frame;
-        }
-
-        /* bits_per_frame should comply with our minimum */
-        if (bits_per_frame < (cpi->oxcf.target_bandwidth * cpi->oxcf.two_pass_vbrmin_section / 100))
-            bits_per_frame = (cpi->oxcf.target_bandwidth * cpi->oxcf.two_pass_vbrmin_section / 100);
-
-        /* Work out if spatial resampling is necessary */
-        kf_q = estimate_kf_group_q(cpi, err_per_frame,
-                                  (int)bits_per_frame, group_iiratio);
-
-        /* If we project a required Q higher than the maximum allowed Q then
-         * make a guess at the actual size of frames in this section
-         */
-        projected_bits_perframe = bits_per_frame;
-        tmp_q = kf_q;
-
-        while (tmp_q > cpi->worst_quality)
-        {
-            projected_bits_perframe *= 1.04;
-            tmp_q--;
-        }
-
-        /* Guess at buffer level at the end of the section */
-        projected_buffer_level = (int)
-                    (cpi->buffer_level - (int)
-                    ((projected_bits_perframe - av_bits_per_frame) *
-                    cpi->twopass.frames_to_key));
-
-        if (0)
-        {
-            FILE *f = fopen("Subsamle.stt", "a");
-            fprintf(f, " %8d %8d %8d %8d %12.0f %8d %8d %8d\n",  cpi->common.current_video_frame, kf_q, cpi->common.horiz_scale, cpi->common.vert_scale,  kf_group_err / cpi->twopass.frames_to_key, (int)(cpi->twopass.kf_group_bits / cpi->twopass.frames_to_key), new_height, new_width);
-            fclose(f);
-        }
-
-        /* The trigger for spatial resampling depends on the various
-         * parameters such as whether we are streaming (CBR) or VBR.
-         */
-        if (cpi->oxcf.end_usage == USAGE_STREAM_FROM_SERVER)
-        {
-            /* Trigger resample if we are projected to fall below down
-             * sample level or resampled last time and are projected to
-             * remain below the up sample level
-             */
-            if ((projected_buffer_level < (cpi->oxcf.resample_down_water_mark * cpi->oxcf.optimal_buffer_level / 100)) ||
-                (last_kf_resampled && (projected_buffer_level < (cpi->oxcf.resample_up_water_mark * cpi->oxcf.optimal_buffer_level / 100))))
-                resample_trigger = 1;
-            else
-                resample_trigger = 0;
-        }
-        else
-        {
-            int64_t clip_bits = (int64_t)(cpi->twopass.total_stats.count * cpi->oxcf.target_bandwidth / DOUBLE_DIVIDE_CHECK((double)cpi->framerate));
-            int64_t over_spend = cpi->oxcf.starting_buffer_level - cpi->buffer_level;
-
-            /* If triggered last time the threshold for triggering again is
-             * reduced:
-             *
-             * Projected Q higher than allowed and Overspend > 5% of total
-             * bits
-             */
-            if ((last_kf_resampled && (kf_q > cpi->worst_quality)) ||
-                ((kf_q > cpi->worst_quality) &&
-                 (over_spend > clip_bits / 20)))
-                resample_trigger = 1;
-            else
-                resample_trigger = 0;
-
-        }
-
-        if (resample_trigger)
-        {
-            while ((kf_q >= cpi->worst_quality) && (scale_val < 6))
-            {
-                scale_val ++;
-
-                cpi->common.vert_scale   = vscale_lookup[scale_val];
-                cpi->common.horiz_scale  = hscale_lookup[scale_val];
-
-                Scale2Ratio(cpi->common.horiz_scale, &hr, &hs);
-                Scale2Ratio(cpi->common.vert_scale, &vr, &vs);
-
-                new_width = ((hs - 1) + (cpi->oxcf.Width * hr)) / hs;
-                new_height = ((vs - 1) + (cpi->oxcf.Height * vr)) / vs;
-
-                /* Reducing the area to 1/4 does not reduce the complexity
-                 * (err_per_frame) to 1/4... effective_sizeratio attempts
-                 * to provide a crude correction for this
-                 */
-                effective_size_ratio = (double)(new_width * new_height) / (double)(cpi->oxcf.Width * cpi->oxcf.Height);
-                effective_size_ratio = (1.0 + (3.0 * effective_size_ratio)) / 4.0;
-
-                /* Now try again and see what Q we get with the smaller
-                 * image size
-                 */
-                kf_q = estimate_kf_group_q(cpi,
-                                          err_per_frame * effective_size_ratio,
-                                          (int)bits_per_frame, group_iiratio);
-
-                if (0)
-                {
-                    FILE *f = fopen("Subsamle.stt", "a");
-                    fprintf(f, "******** %8d %8d %8d %12.0f %8d %8d %8d\n",  kf_q, cpi->common.horiz_scale, cpi->common.vert_scale,  kf_group_err / cpi->twopass.frames_to_key, (int)(cpi->twopass.kf_group_bits / cpi->twopass.frames_to_key), new_height, new_width);
-                    fclose(f);
-                }
-            }
-        }
-
-        if ((cpi->common.Width != new_width) || (cpi->common.Height != new_height))
-        {
-            cpi->common.Width = new_width;
-            cpi->common.Height = new_height;
-            vp8_alloc_compressor_data(cpi);
-        }
-    }
-}
diff --git a/vp8/encoder/firstpass.h b/vp8/encoder/firstpass.h
deleted file mode 100644 (file)
index c409ebc..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#ifndef VP8_ENCODER_FIRSTPASS_H_
-#define VP8_ENCODER_FIRSTPASS_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-extern void vp8_init_first_pass(VP8_COMP *cpi);
-extern void vp8_first_pass(VP8_COMP *cpi);
-extern void vp8_end_first_pass(VP8_COMP *cpi);
-
-extern void vp8_init_second_pass(VP8_COMP *cpi);
-extern void vp8_second_pass(VP8_COMP *cpi);
-extern void vp8_end_second_pass(VP8_COMP *cpi);
-
-extern size_t vp8_firstpass_stats_sz(unsigned int mb_count);
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP8_ENCODER_FIRSTPASS_H_
diff --git a/vp8/encoder/lookahead.c b/vp8/encoder/lookahead.c
deleted file mode 100644 (file)
index 6623385..0000000
+++ /dev/null
@@ -1,231 +0,0 @@
-/*
- *  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.
- */
-#include <assert.h>
-#include <stdlib.h>
-#include "vpx_config.h"
-#include "lookahead.h"
-#include "vp8/common/extend.h"
-
-#define MAX_LAG_BUFFERS (CONFIG_REALTIME_ONLY? 1 : 25)
-
-struct lookahead_ctx
-{
-    unsigned int max_sz;         /* Absolute size of the queue */
-    unsigned int sz;             /* Number of buffers currently in the queue */
-    unsigned int read_idx;       /* Read index */
-    unsigned int write_idx;      /* Write index */
-    struct lookahead_entry *buf; /* Buffer list */
-};
-
-
-/* Return the buffer at the given absolute index and increment the index */
-static struct lookahead_entry *
-pop(struct lookahead_ctx *ctx,
-    unsigned int         *idx)
-{
-    unsigned int            index = *idx;
-    struct lookahead_entry *buf = ctx->buf + index;
-
-    assert(index < ctx->max_sz);
-    if(++index >= ctx->max_sz)
-        index -= ctx->max_sz;
-    *idx = index;
-    return buf;
-}
-
-
-void
-vp8_lookahead_destroy(struct lookahead_ctx *ctx)
-{
-    if(ctx)
-    {
-        if(ctx->buf)
-        {
-            unsigned int i;
-
-            for(i = 0; i < ctx->max_sz; i++)
-                vp8_yv12_de_alloc_frame_buffer(&ctx->buf[i].img);
-            free(ctx->buf);
-        }
-        free(ctx);
-    }
-}
-
-
-struct lookahead_ctx*
-vp8_lookahead_init(unsigned int width,
-                   unsigned int height,
-                   unsigned int depth)
-{
-    struct lookahead_ctx *ctx = NULL;
-    unsigned int i;
-
-    /* Clamp the lookahead queue depth */
-    if(depth < 1)
-        depth = 1;
-    else if(depth > MAX_LAG_BUFFERS)
-        depth = MAX_LAG_BUFFERS;
-
-    /* Keep last frame in lookahead buffer by increasing depth by 1.*/
-    depth += 1;
-
-    /* Align the buffer dimensions */
-    width = (width + 15) & ~15;
-    height = (height + 15) & ~15;
-
-    /* Allocate the lookahead structures */
-    ctx = calloc(1, sizeof(*ctx));
-    if(ctx)
-    {
-        ctx->max_sz = depth;
-        ctx->buf = calloc(depth, sizeof(*ctx->buf));
-        if(!ctx->buf)
-            goto bail;
-        for(i=0; i<depth; i++)
-            if (vp8_yv12_alloc_frame_buffer(&ctx->buf[i].img,
-                                            width, height, VP8BORDERINPIXELS))
-                goto bail;
-    }
-    return ctx;
-bail:
-    vp8_lookahead_destroy(ctx);
-    return NULL;
-}
-
-
-int
-vp8_lookahead_push(struct lookahead_ctx *ctx,
-                   YV12_BUFFER_CONFIG   *src,
-                   int64_t               ts_start,
-                   int64_t               ts_end,
-                   unsigned int          flags,
-                   unsigned char        *active_map)
-{
-    struct lookahead_entry* buf;
-    int row, col, active_end;
-    int mb_rows = (src->y_height + 15) >> 4;
-    int mb_cols = (src->y_width + 15) >> 4;
-
-    if(ctx->sz + 2 > ctx->max_sz)
-        return 1;
-    ctx->sz++;
-    buf = pop(ctx, &ctx->write_idx);
-
-    /* Only do this partial copy if the following conditions are all met:
-     * 1. Lookahead queue has has size of 1.
-     * 2. Active map is provided.
-     * 3. This is not a key frame, golden nor altref frame.
-     */
-    if (ctx->max_sz == 1 && active_map && !flags)
-    {
-        for (row = 0; row < mb_rows; ++row)
-        {
-            col = 0;
-
-            while (1)
-            {
-                /* Find the first active macroblock in this row. */
-                for (; col < mb_cols; ++col)
-                {
-                    if (active_map[col])
-                        break;
-                }
-
-                /* No more active macroblock in this row. */
-                if (col == mb_cols)
-                    break;
-
-                /* Find the end of active region in this row. */
-                active_end = col;
-
-                for (; active_end < mb_cols; ++active_end)
-                {
-                    if (!active_map[active_end])
-                        break;
-                }
-
-                /* Only copy this active region. */
-                vp8_copy_and_extend_frame_with_rect(src, &buf->img,
-                                                    row << 4,
-                                                    col << 4, 16,
-                                                    (active_end - col) << 4);
-
-                /* Start again from the end of this active region. */
-                col = active_end;
-            }
-
-            active_map += mb_cols;
-        }
-    }
-    else
-    {
-        vp8_copy_and_extend_frame(src, &buf->img);
-    }
-    buf->ts_start = ts_start;
-    buf->ts_end = ts_end;
-    buf->flags = flags;
-    return 0;
-}
-
-
-struct lookahead_entry*
-vp8_lookahead_pop(struct lookahead_ctx *ctx,
-                  int                   drain)
-{
-    struct lookahead_entry* buf = NULL;
-
-    assert(ctx != NULL);
-    if(ctx->sz && (drain || ctx->sz == ctx->max_sz - 1))
-    {
-        buf = pop(ctx, &ctx->read_idx);
-        ctx->sz--;
-    }
-    return buf;
-}
-
-
-struct lookahead_entry*
-vp8_lookahead_peek(struct lookahead_ctx *ctx,
-                   unsigned int          index,
-                   int                   direction)
-{
-    struct lookahead_entry* buf = NULL;
-
-    if (direction == PEEK_FORWARD)
-    {
-        assert(index < ctx->max_sz - 1);
-        if(index < ctx->sz)
-        {
-            index += ctx->read_idx;
-            if(index >= ctx->max_sz)
-                index -= ctx->max_sz;
-            buf = ctx->buf + index;
-        }
-    }
-    else if (direction == PEEK_BACKWARD)
-    {
-        assert(index == 1);
-
-        if(ctx->read_idx == 0)
-            index = ctx->max_sz - 1;
-        else
-            index = ctx->read_idx - index;
-        buf = ctx->buf + index;
-    }
-
-    return buf;
-}
-
-
-unsigned int
-vp8_lookahead_depth(struct lookahead_ctx *ctx)
-{
-    return ctx->sz;
-}
diff --git a/vp8/encoder/lookahead.h b/vp8/encoder/lookahead.h
deleted file mode 100644 (file)
index cad68e6..0000000
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- *  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.
- */
-#ifndef VP8_ENCODER_LOOKAHEAD_H_
-#define VP8_ENCODER_LOOKAHEAD_H_
-#include "vpx_scale/yv12config.h"
-#include "vpx/vpx_integer.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-struct lookahead_entry
-{
-    YV12_BUFFER_CONFIG  img;
-    int64_t             ts_start;
-    int64_t             ts_end;
-    unsigned int        flags;
-};
-
-
-struct lookahead_ctx;
-
-/**\brief Initializes the lookahead stage
- *
- * The lookahead stage is a queue of frame buffers on which some analysis
- * may be done when buffers are enqueued.
- *
- *
- */
-struct lookahead_ctx* vp8_lookahead_init(unsigned int width,
-                                         unsigned int height,
-                                         unsigned int depth
-                                         );
-
-
-/**\brief Destroys the lookahead stage
- *
- */
-void vp8_lookahead_destroy(struct lookahead_ctx *ctx);
-
-
-/**\brief Enqueue a source buffer
- *
- * This function will copy the source image into a new framebuffer with
- * the expected stride/border.
- *
- * If active_map is non-NULL and there is only one frame in the queue, then copy
- * only active macroblocks.
- *
- * \param[in] ctx         Pointer to the lookahead context
- * \param[in] src         Pointer to the image to enqueue
- * \param[in] ts_start    Timestamp for the start of this frame
- * \param[in] ts_end      Timestamp for the end of this frame
- * \param[in] flags       Flags set on this frame
- * \param[in] active_map  Map that specifies which macroblock is active
- */
-int
-vp8_lookahead_push(struct lookahead_ctx *ctx,
-                   YV12_BUFFER_CONFIG   *src,
-                   int64_t               ts_start,
-                   int64_t               ts_end,
-                   unsigned int          flags,
-                   unsigned char        *active_map);
-
-
-/**\brief Get the next source buffer to encode
- *
- *
- * \param[in] ctx       Pointer to the lookahead context
- * \param[in] drain     Flag indicating the buffer should be drained
- *                      (return a buffer regardless of the current queue depth)
- *
- * \retval NULL, if drain set and queue is empty
- * \retval NULL, if drain not set and queue not of the configured depth
- *
- */
-struct lookahead_entry*
-vp8_lookahead_pop(struct lookahead_ctx *ctx,
-                  int                   drain);
-
-
-#define PEEK_FORWARD   1
-#define PEEK_BACKWARD -1
-/**\brief Get a future source buffer to encode
- *
- * \param[in] ctx       Pointer to the lookahead context
- * \param[in] index     Index of the frame to be returned, 0 == next frame
- *
- * \retval NULL, if no buffer exists at the specified index
- *
- */
-struct lookahead_entry*
-vp8_lookahead_peek(struct lookahead_ctx *ctx,
-                   unsigned int          index,
-                   int                   direction);
-
-
-/**\brief Get the number of frames currently in the lookahead queue
- *
- * \param[in] ctx       Pointer to the lookahead context
- */
-unsigned int
-vp8_lookahead_depth(struct lookahead_ctx *ctx);
-
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP8_ENCODER_LOOKAHEAD_H_
diff --git a/vp8/encoder/mcomp.c b/vp8/encoder/mcomp.c
deleted file mode 100644 (file)
index e20c1ea..0000000
+++ /dev/null
@@ -1,2032 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#include "./vp8_rtcd.h"
-#include "./vpx_dsp_rtcd.h"
-#include "onyx_int.h"
-#include "mcomp.h"
-#include "vpx_mem/vpx_mem.h"
-#include "vpx_config.h"
-#include <stdio.h>
-#include <limits.h>
-#include <math.h>
-#include "vp8/common/findnearmv.h"
-#include "vp8/common/common.h"
-#include "vpx_dsp/vpx_dsp_common.h"
-
-#ifdef VP8_ENTROPY_STATS
-static int mv_ref_ct [31] [4] [2];
-static int mv_mode_cts [4] [2];
-#endif
-
-int vp8_mv_bit_cost(int_mv *mv, int_mv *ref, int *mvcost[2], int Weight)
-{
-    /* MV costing is based on the distribution of vectors in the previous
-     * frame and as such will tend to over state the cost of vectors. In
-     * addition coding a new vector can have a knock on effect on the cost
-     * of subsequent vectors and the quality of prediction from NEAR and
-     * NEAREST for subsequent blocks. The "Weight" parameter allows, to a
-     * limited extent, for some account to be taken of these factors.
-     */
-    return ((mvcost[0][(mv->as_mv.row - ref->as_mv.row) >> 1] + mvcost[1][(mv->as_mv.col - ref->as_mv.col) >> 1]) * Weight) >> 7;
-}
-
-static int mv_err_cost(int_mv *mv, int_mv *ref, int *mvcost[2], int error_per_bit)
-{
-    /* Ignore mv costing if mvcost is NULL */
-    if (mvcost)
-        return ((mvcost[0][(mv->as_mv.row - ref->as_mv.row) >> 1] +
-                 mvcost[1][(mv->as_mv.col - ref->as_mv.col) >> 1])
-                 * error_per_bit + 128) >> 8;
-    return 0;
-}
-
-static int mvsad_err_cost(int_mv *mv, int_mv *ref, int *mvsadcost[2], int error_per_bit)
-{
-    /* Calculate sad error cost on full pixel basis. */
-    /* Ignore mv costing if mvsadcost is NULL */
-    if (mvsadcost)
-        return ((mvsadcost[0][(mv->as_mv.row - ref->as_mv.row)] +
-                 mvsadcost[1][(mv->as_mv.col - ref->as_mv.col)])
-                * error_per_bit + 128) >> 8;
-    return 0;
-}
-
-void vp8_init_dsmotion_compensation(MACROBLOCK *x, int stride)
-{
-    int Len;
-    int search_site_count = 0;
-
-
-    /* Generate offsets for 4 search sites per step. */
-    Len = MAX_FIRST_STEP;
-    x->ss[search_site_count].mv.col = 0;
-    x->ss[search_site_count].mv.row = 0;
-    x->ss[search_site_count].offset = 0;
-    search_site_count++;
-
-    while (Len > 0)
-    {
-
-        /* Compute offsets for search sites. */
-        x->ss[search_site_count].mv.col = 0;
-        x->ss[search_site_count].mv.row = -Len;
-        x->ss[search_site_count].offset = -Len * stride;
-        search_site_count++;
-
-        /* Compute offsets for search sites. */
-        x->ss[search_site_count].mv.col = 0;
-        x->ss[search_site_count].mv.row = Len;
-        x->ss[search_site_count].offset = Len * stride;
-        search_site_count++;
-
-        /* Compute offsets for search sites. */
-        x->ss[search_site_count].mv.col = -Len;
-        x->ss[search_site_count].mv.row = 0;
-        x->ss[search_site_count].offset = -Len;
-        search_site_count++;
-
-        /* Compute offsets for search sites. */
-        x->ss[search_site_count].mv.col = Len;
-        x->ss[search_site_count].mv.row = 0;
-        x->ss[search_site_count].offset = Len;
-        search_site_count++;
-
-        /* Contract. */
-        Len /= 2;
-    }
-
-    x->ss_count = search_site_count;
-    x->searches_per_step = 4;
-}
-
-void vp8_init3smotion_compensation(MACROBLOCK *x, int stride)
-{
-    int Len;
-    int search_site_count = 0;
-
-    /* Generate offsets for 8 search sites per step. */
-    Len = MAX_FIRST_STEP;
-    x->ss[search_site_count].mv.col = 0;
-    x->ss[search_site_count].mv.row = 0;
-    x->ss[search_site_count].offset = 0;
-    search_site_count++;
-
-    while (Len > 0)
-    {
-
-        /* Compute offsets for search sites. */
-        x->ss[search_site_count].mv.col = 0;
-        x->ss[search_site_count].mv.row = -Len;
-        x->ss[search_site_count].offset = -Len * stride;
-        search_site_count++;
-
-        /* Compute offsets for search sites. */
-        x->ss[search_site_count].mv.col = 0;
-        x->ss[search_site_count].mv.row = Len;
-        x->ss[search_site_count].offset = Len * stride;
-        search_site_count++;
-
-        /* Compute offsets for search sites. */
-        x->ss[search_site_count].mv.col = -Len;
-        x->ss[search_site_count].mv.row = 0;
-        x->ss[search_site_count].offset = -Len;
-        search_site_count++;
-
-        /* Compute offsets for search sites. */
-        x->ss[search_site_count].mv.col = Len;
-        x->ss[search_site_count].mv.row = 0;
-        x->ss[search_site_count].offset = Len;
-        search_site_count++;
-
-        /* Compute offsets for search sites. */
-        x->ss[search_site_count].mv.col = -Len;
-        x->ss[search_site_count].mv.row = -Len;
-        x->ss[search_site_count].offset = -Len * stride - Len;
-        search_site_count++;
-
-        /* Compute offsets for search sites. */
-        x->ss[search_site_count].mv.col = Len;
-        x->ss[search_site_count].mv.row = -Len;
-        x->ss[search_site_count].offset = -Len * stride + Len;
-        search_site_count++;
-
-        /* Compute offsets for search sites. */
-        x->ss[search_site_count].mv.col = -Len;
-        x->ss[search_site_count].mv.row = Len;
-        x->ss[search_site_count].offset = Len * stride - Len;
-        search_site_count++;
-
-        /* Compute offsets for search sites. */
-        x->ss[search_site_count].mv.col = Len;
-        x->ss[search_site_count].mv.row = Len;
-        x->ss[search_site_count].offset = Len * stride + Len;
-        search_site_count++;
-
-
-        /* Contract. */
-        Len /= 2;
-    }
-
-    x->ss_count = search_site_count;
-    x->searches_per_step = 8;
-}
-
-/*
- * To avoid the penalty for crossing cache-line read, preload the reference
- * area in a small buffer, which is aligned to make sure there won't be crossing
- * cache-line read while reading from this buffer. This reduced the cpu
- * cycles spent on reading ref data in sub-pixel filter functions.
- * TODO: Currently, since sub-pixel search range here is -3 ~ 3, copy 22 rows x
- * 32 cols area that is enough for 16x16 macroblock. Later, for SPLITMV, we
- * could reduce the area.
- */
-
-/* estimated cost of a motion vector (r,c) */
-#define MVC(r,c) (mvcost ? ((mvcost[0][(r)-rr] + mvcost[1][(c) - rc]) * error_per_bit + 128 )>>8 : 0)
-/* pointer to predictor base of a motionvector */
-#define PRE(r,c) (y + (((r)>>2) * y_stride + ((c)>>2) -(offset)))
-/* convert motion vector component to offset for svf calc */
-#define SP(x) (((x)&3)<<1)
-/* returns subpixel variance error function. */
-#define DIST(r,c) vfp->svf( PRE(r,c), y_stride, SP(c),SP(r), z,b->src_stride,&sse)
-#define IFMVCV(r,c,s,e) if ( c >= minc && c <= maxc && r >= minr && r <= maxr) s else e;
-/* 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;)
-
-int vp8_find_best_sub_pixel_step_iteratively(MACROBLOCK *x, BLOCK *b, BLOCKD *d,
-                                             int_mv *bestmv, int_mv *ref_mv,
-                                             int error_per_bit,
-                                             const vp8_variance_fn_ptr_t *vfp,
-                                             int *mvcost[2], int *distortion,
-                                             unsigned int *sse1)
-{
-    unsigned char *z = (*(b->base_src) + b->src);
-
-    int rr = ref_mv->as_mv.row >> 1, rc = ref_mv->as_mv.col >> 1;
-    int br = bestmv->as_mv.row * 4, bc = bestmv->as_mv.col * 4;
-    int tr = br, tc = bc;
-    unsigned int besterr;
-    unsigned int left, right, up, down, diag;
-    unsigned int sse;
-    unsigned int whichdir;
-    unsigned int halfiters = 4;
-    unsigned int quarteriters = 4;
-    int thismse;
-
-    int minc = VPXMAX(x->mv_col_min * 4,
-                      (ref_mv->as_mv.col >> 1) - ((1 << mvlong_width) - 1));
-    int maxc = VPXMIN(x->mv_col_max * 4,
-                      (ref_mv->as_mv.col >> 1) + ((1 << mvlong_width) - 1));
-    int minr = VPXMAX(x->mv_row_min * 4,
-                      (ref_mv->as_mv.row >> 1) - ((1 << mvlong_width) - 1));
-    int maxr = VPXMIN(x->mv_row_max * 4,
-                      (ref_mv->as_mv.row >> 1) + ((1 << mvlong_width) - 1));
-
-    int y_stride;
-    int offset;
-    int pre_stride = x->e_mbd.pre.y_stride;
-    unsigned char *base_pre = x->e_mbd.pre.y_buffer;
-
-
-#if ARCH_X86 || ARCH_X86_64
-    MACROBLOCKD *xd = &x->e_mbd;
-    unsigned char *y_0 = base_pre + d->offset + (bestmv->as_mv.row) * pre_stride + bestmv->as_mv.col;
-    unsigned char *y;
-    int buf_r1, buf_r2, buf_c1;
-
-    /* Clamping to avoid out-of-range data access */
-    buf_r1 = ((bestmv->as_mv.row - 3) < x->mv_row_min)?(bestmv->as_mv.row - x->mv_row_min):3;
-    buf_r2 = ((bestmv->as_mv.row + 3) > x->mv_row_max)?(x->mv_row_max - bestmv->as_mv.row):3;
-    buf_c1 = ((bestmv->as_mv.col - 3) < x->mv_col_min)?(bestmv->as_mv.col - x->mv_col_min):3;
-    y_stride = 32;
-
-    /* Copy to intermediate buffer before searching. */
-    vfp->copymem(y_0 - buf_c1 - pre_stride*buf_r1, pre_stride, xd->y_buf, y_stride, 16+buf_r1+buf_r2);
-    y = xd->y_buf + y_stride*buf_r1 +buf_c1;
-#else
-    unsigned char *y = base_pre + d->offset + (bestmv->as_mv.row) * pre_stride + bestmv->as_mv.col;
-    y_stride = pre_stride;
-#endif
-
-    offset = (bestmv->as_mv.row) * y_stride + bestmv->as_mv.col;
-
-    /* central mv */
-    bestmv->as_mv.row *= 8;
-    bestmv->as_mv.col *= 8;
-
-    /* calculate central point error */
-    besterr = vfp->vf(y, y_stride, z, b->src_stride, sse1);
-    *distortion = besterr;
-    besterr += mv_err_cost(bestmv, ref_mv, mvcost, error_per_bit);
-
-    /* TODO: Each subsequent iteration checks at least one point in common
-     * with the last iteration could be 2 ( if diag selected)
-     */
-    while (--halfiters)
-    {
-        /* 1/2 pel */
-        CHECK_BETTER(left, tr, tc - 2);
-        CHECK_BETTER(right, tr, tc + 2);
-        CHECK_BETTER(up, tr - 2, tc);
-        CHECK_BETTER(down, tr + 2, tc);
-
-        whichdir = (left < right ? 0 : 1) + (up < down ? 0 : 2);
-
-        switch (whichdir)
-        {
-        case 0:
-            CHECK_BETTER(diag, tr - 2, tc - 2);
-            break;
-        case 1:
-            CHECK_BETTER(diag, tr - 2, tc + 2);
-            break;
-        case 2:
-            CHECK_BETTER(diag, tr + 2, tc - 2);
-            break;
-        case 3:
-            CHECK_BETTER(diag, tr + 2, tc + 2);
-            break;
-        }
-
-        /* no reason to check the same one again. */
-        if (tr == br && tc == bc)
-            break;
-
-        tr = br;
-        tc = bc;
-    }
-
-    /* TODO: Each subsequent iteration checks at least one point in common
-     * with the last iteration could be 2 ( if diag selected)
-     */
-
-    /* 1/4 pel */
-    while (--quarteriters)
-    {
-        CHECK_BETTER(left, tr, tc - 1);
-        CHECK_BETTER(right, tr, tc + 1);
-        CHECK_BETTER(up, tr - 1, tc);
-        CHECK_BETTER(down, tr + 1, tc);
-
-        whichdir = (left < right ? 0 : 1) + (up < down ? 0 : 2);
-
-        switch (whichdir)
-        {
-        case 0:
-            CHECK_BETTER(diag, tr - 1, tc - 1);
-            break;
-        case 1:
-            CHECK_BETTER(diag, tr - 1, tc + 1);
-            break;
-        case 2:
-            CHECK_BETTER(diag, tr + 1, tc - 1);
-            break;
-        case 3:
-            CHECK_BETTER(diag, tr + 1, tc + 1);
-            break;
-        }
-
-        /* no reason to check the same one again. */
-        if (tr == br && tc == bc)
-            break;
-
-        tr = br;
-        tc = bc;
-    }
-
-    bestmv->as_mv.row = br * 2;
-    bestmv->as_mv.col = bc * 2;
-
-    if ((abs(bestmv->as_mv.col - ref_mv->as_mv.col) > (MAX_FULL_PEL_VAL<<3)) ||
-        (abs(bestmv->as_mv.row - ref_mv->as_mv.row) > (MAX_FULL_PEL_VAL<<3)))
-        return INT_MAX;
-
-    return besterr;
-}
-#undef MVC
-#undef PRE
-#undef SP
-#undef DIST
-#undef IFMVCV
-#undef ERR
-#undef CHECK_BETTER
-
-int vp8_find_best_sub_pixel_step(MACROBLOCK *x, BLOCK *b, BLOCKD *d,
-                                 int_mv *bestmv, int_mv *ref_mv,
-                                 int error_per_bit,
-                                 const vp8_variance_fn_ptr_t *vfp,
-                                 int *mvcost[2], int *distortion,
-                                 unsigned int *sse1)
-{
-    int bestmse = INT_MAX;
-    int_mv startmv;
-    int_mv this_mv;
-    unsigned char *z = (*(b->base_src) + b->src);
-    int left, right, up, down, diag;
-    unsigned int sse;
-    int whichdir ;
-    int thismse;
-    int y_stride;
-    int pre_stride = x->e_mbd.pre.y_stride;
-    unsigned char *base_pre = x->e_mbd.pre.y_buffer;
-
-#if ARCH_X86 || ARCH_X86_64
-    MACROBLOCKD *xd = &x->e_mbd;
-    unsigned char *y_0 = base_pre + d->offset + (bestmv->as_mv.row) * pre_stride + bestmv->as_mv.col;
-    unsigned char *y;
-
-    y_stride = 32;
-    /* Copy 18 rows x 32 cols area to intermediate buffer before searching. */
-     vfp->copymem(y_0 - 1 - pre_stride, pre_stride, xd->y_buf, y_stride, 18);
-     y = xd->y_buf + y_stride + 1;
-#else
-     unsigned char *y = base_pre + d->offset + (bestmv->as_mv.row) * pre_stride + bestmv->as_mv.col;
-     y_stride = pre_stride;
-#endif
-
-    /* central mv */
-    bestmv->as_mv.row *= 8;
-    bestmv->as_mv.col *= 8;
-    startmv = *bestmv;
-
-    /* calculate central point error */
-    bestmse = vfp->vf(y, y_stride, z, b->src_stride, sse1);
-    *distortion = bestmse;
-    bestmse += mv_err_cost(bestmv, ref_mv, mvcost, error_per_bit);
-
-    /* go left then right and check error */
-    this_mv.as_mv.row = startmv.as_mv.row;
-    this_mv.as_mv.col = ((startmv.as_mv.col - 8) | 4);
-    thismse = vfp->svf_halfpix_h(y - 1, y_stride, z, b->src_stride, &sse);
-    left = thismse + mv_err_cost(&this_mv, ref_mv, mvcost, error_per_bit);
-
-    if (left < bestmse)
-    {
-        *bestmv = this_mv;
-        bestmse = left;
-        *distortion = thismse;
-        *sse1 = sse;
-    }
-
-    this_mv.as_mv.col += 8;
-    thismse = vfp->svf_halfpix_h(y, y_stride, z, b->src_stride, &sse);
-    right = thismse + mv_err_cost(&this_mv, ref_mv, mvcost, error_per_bit);
-
-    if (right < bestmse)
-    {
-        *bestmv = this_mv;
-        bestmse = right;
-        *distortion = thismse;
-        *sse1 = sse;
-    }
-
-    /* go up then down and check error */
-    this_mv.as_mv.col = startmv.as_mv.col;
-    this_mv.as_mv.row = ((startmv.as_mv.row - 8) | 4);
-    thismse =  vfp->svf_halfpix_v(y - y_stride, y_stride, z, b->src_stride, &sse);
-    up = thismse + mv_err_cost(&this_mv, ref_mv, mvcost, error_per_bit);
-
-    if (up < bestmse)
-    {
-        *bestmv = this_mv;
-        bestmse = up;
-        *distortion = thismse;
-        *sse1 = sse;
-    }
-
-    this_mv.as_mv.row += 8;
-    thismse = vfp->svf_halfpix_v(y, y_stride, z, b->src_stride, &sse);
-    down = thismse + mv_err_cost(&this_mv, ref_mv, mvcost, error_per_bit);
-
-    if (down < bestmse)
-    {
-        *bestmv = this_mv;
-        bestmse = down;
-        *distortion = thismse;
-        *sse1 = sse;
-    }
-
-
-    /* now check 1 more diagonal */
-    whichdir = (left < right ? 0 : 1) + (up < down ? 0 : 2);
-    this_mv = startmv;
-
-    switch (whichdir)
-    {
-    case 0:
-        this_mv.as_mv.col = (this_mv.as_mv.col - 8) | 4;
-        this_mv.as_mv.row = (this_mv.as_mv.row - 8) | 4;
-        thismse = vfp->svf_halfpix_hv(y - 1 - y_stride, y_stride, z, b->src_stride, &sse);
-        break;
-    case 1:
-        this_mv.as_mv.col += 4;
-        this_mv.as_mv.row = (this_mv.as_mv.row - 8) | 4;
-        thismse = vfp->svf_halfpix_hv(y - y_stride, y_stride, z, b->src_stride, &sse);
-        break;
-    case 2:
-        this_mv.as_mv.col = (this_mv.as_mv.col - 8) | 4;
-        this_mv.as_mv.row += 4;
-        thismse = vfp->svf_halfpix_hv(y - 1, y_stride, z, b->src_stride, &sse);
-        break;
-    case 3:
-    default:
-        this_mv.as_mv.col += 4;
-        this_mv.as_mv.row += 4;
-        thismse = vfp->svf_halfpix_hv(y, y_stride, z, b->src_stride, &sse);
-        break;
-    }
-
-    diag = thismse + mv_err_cost(&this_mv, ref_mv, mvcost, error_per_bit);
-
-    if (diag < bestmse)
-    {
-        *bestmv = this_mv;
-        bestmse = diag;
-        *distortion = thismse;
-        *sse1 = sse;
-    }
-
-
-    /* time to check quarter pels. */
-    if (bestmv->as_mv.row < startmv.as_mv.row)
-        y -= y_stride;
-
-    if (bestmv->as_mv.col < startmv.as_mv.col)
-        y--;
-
-    startmv = *bestmv;
-
-
-
-    /* go left then right and check error */
-    this_mv.as_mv.row = startmv.as_mv.row;
-
-    if (startmv.as_mv.col & 7)
-    {
-        this_mv.as_mv.col = startmv.as_mv.col - 2;
-        thismse = vfp->svf(y, y_stride, this_mv.as_mv.col & 7, this_mv.as_mv.row & 7, z, b->src_stride, &sse);
-    }
-    else
-    {
-        this_mv.as_mv.col = (startmv.as_mv.col - 8) | 6;
-        thismse = vfp->svf(y - 1, y_stride, 6, this_mv.as_mv.row & 7, z, b->src_stride, &sse);
-    }
-
-    left = thismse + mv_err_cost(&this_mv, ref_mv, mvcost, error_per_bit);
-
-    if (left < bestmse)
-    {
-        *bestmv = this_mv;
-        bestmse = left;
-        *distortion = thismse;
-        *sse1 = sse;
-    }
-
-    this_mv.as_mv.col += 4;
-    thismse = vfp->svf(y, y_stride, this_mv.as_mv.col & 7, this_mv.as_mv.row & 7, z, b->src_stride, &sse);
-    right = thismse + mv_err_cost(&this_mv, ref_mv, mvcost, error_per_bit);
-
-    if (right < bestmse)
-    {
-        *bestmv = this_mv;
-        bestmse = right;
-        *distortion = thismse;
-        *sse1 = sse;
-    }
-
-    /* go up then down and check error */
-    this_mv.as_mv.col = startmv.as_mv.col;
-
-    if (startmv.as_mv.row & 7)
-    {
-        this_mv.as_mv.row = startmv.as_mv.row - 2;
-        thismse = vfp->svf(y, y_stride, this_mv.as_mv.col & 7, this_mv.as_mv.row & 7, z, b->src_stride, &sse);
-    }
-    else
-    {
-        this_mv.as_mv.row = (startmv.as_mv.row - 8) | 6;
-        thismse = vfp->svf(y - y_stride, y_stride, this_mv.as_mv.col & 7, 6, z, b->src_stride, &sse);
-    }
-
-    up = thismse + mv_err_cost(&this_mv, ref_mv, mvcost, error_per_bit);
-
-    if (up < bestmse)
-    {
-        *bestmv = this_mv;
-        bestmse = up;
-        *distortion = thismse;
-        *sse1 = sse;
-    }
-
-    this_mv.as_mv.row += 4;
-    thismse = vfp->svf(y, y_stride, this_mv.as_mv.col & 7, this_mv.as_mv.row & 7, z, b->src_stride, &sse);
-    down = thismse + mv_err_cost(&this_mv, ref_mv, mvcost, error_per_bit);
-
-    if (down < bestmse)
-    {
-        *bestmv = this_mv;
-        bestmse = down;
-        *distortion = thismse;
-        *sse1 = sse;
-    }
-
-
-    /* now check 1 more diagonal */
-    whichdir = (left < right ? 0 : 1) + (up < down ? 0 : 2);
-
-    this_mv = startmv;
-
-    switch (whichdir)
-    {
-    case 0:
-
-        if (startmv.as_mv.row & 7)
-        {
-            this_mv.as_mv.row -= 2;
-
-            if (startmv.as_mv.col & 7)
-            {
-                this_mv.as_mv.col -= 2;
-                thismse = vfp->svf(y, y_stride, this_mv.as_mv.col & 7, this_mv.as_mv.row & 7, z, b->src_stride, &sse);
-            }
-            else
-            {
-                this_mv.as_mv.col = (startmv.as_mv.col - 8) | 6;
-                thismse = vfp->svf(y - 1, y_stride, 6, this_mv.as_mv.row & 7, z, b->src_stride, &sse);;
-            }
-        }
-        else
-        {
-            this_mv.as_mv.row = (startmv.as_mv.row - 8) | 6;
-
-            if (startmv.as_mv.col & 7)
-            {
-                this_mv.as_mv.col -= 2;
-                thismse = vfp->svf(y - y_stride, y_stride, this_mv.as_mv.col & 7, 6, z, b->src_stride, &sse);
-            }
-            else
-            {
-                this_mv.as_mv.col = (startmv.as_mv.col - 8) | 6;
-                thismse = vfp->svf(y - y_stride - 1, y_stride, 6, 6, z, b->src_stride, &sse);
-            }
-        }
-
-        break;
-    case 1:
-        this_mv.as_mv.col += 2;
-
-        if (startmv.as_mv.row & 7)
-        {
-            this_mv.as_mv.row -= 2;
-            thismse = vfp->svf(y, y_stride, this_mv.as_mv.col & 7, this_mv.as_mv.row & 7, z, b->src_stride, &sse);
-        }
-        else
-        {
-            this_mv.as_mv.row = (startmv.as_mv.row - 8) | 6;
-            thismse = vfp->svf(y - y_stride, y_stride, this_mv.as_mv.col & 7, 6, z, b->src_stride, &sse);
-        }
-
-        break;
-    case 2:
-        this_mv.as_mv.row += 2;
-
-        if (startmv.as_mv.col & 7)
-        {
-            this_mv.as_mv.col -= 2;
-            thismse = vfp->svf(y, y_stride, this_mv.as_mv.col & 7, this_mv.as_mv.row & 7, z, b->src_stride, &sse);
-        }
-        else
-        {
-            this_mv.as_mv.col = (startmv.as_mv.col - 8) | 6;
-            thismse = vfp->svf(y - 1, y_stride, 6, this_mv.as_mv.row & 7, z, b->src_stride, &sse);
-        }
-
-        break;
-    case 3:
-        this_mv.as_mv.col += 2;
-        this_mv.as_mv.row += 2;
-        thismse = vfp->svf(y, y_stride,  this_mv.as_mv.col & 7, this_mv.as_mv.row & 7, z, b->src_stride, &sse);
-        break;
-    }
-
-    diag = thismse + mv_err_cost(&this_mv, ref_mv, mvcost, error_per_bit);
-
-    if (diag < bestmse)
-    {
-        *bestmv = this_mv;
-        bestmse = diag;
-        *distortion = thismse;
-        *sse1 = sse;
-    }
-
-    return bestmse;
-}
-
-int vp8_find_best_half_pixel_step(MACROBLOCK *x, BLOCK *b, BLOCKD *d,
-                                  int_mv *bestmv, int_mv *ref_mv,
-                                  int error_per_bit,
-                                  const vp8_variance_fn_ptr_t *vfp,
-                                  int *mvcost[2], int *distortion,
-                                  unsigned int *sse1)
-{
-    int bestmse = INT_MAX;
-    int_mv startmv;
-    int_mv this_mv;
-    unsigned char *z = (*(b->base_src) + b->src);
-    int left, right, up, down, diag;
-    unsigned int sse;
-    int whichdir ;
-    int thismse;
-    int y_stride;
-    int pre_stride = x->e_mbd.pre.y_stride;
-    unsigned char *base_pre = x->e_mbd.pre.y_buffer;
-
-#if ARCH_X86 || ARCH_X86_64
-    MACROBLOCKD *xd = &x->e_mbd;
-    unsigned char *y_0 = base_pre + d->offset + (bestmv->as_mv.row) * pre_stride + bestmv->as_mv.col;
-    unsigned char *y;
-
-    y_stride = 32;
-    /* Copy 18 rows x 32 cols area to intermediate buffer before searching. */
-    vfp->copymem(y_0 - 1 - pre_stride, pre_stride, xd->y_buf, y_stride, 18);
-    y = xd->y_buf + y_stride + 1;
-#else
-    unsigned char *y = base_pre + d->offset + (bestmv->as_mv.row) * pre_stride + bestmv->as_mv.col;
-    y_stride = pre_stride;
-#endif
-
-    /* central mv */
-    bestmv->as_mv.row *= 8;
-    bestmv->as_mv.col *= 8;
-    startmv = *bestmv;
-
-    /* calculate central point error */
-    bestmse = vfp->vf(y, y_stride, z, b->src_stride, sse1);
-    *distortion = bestmse;
-    bestmse += mv_err_cost(bestmv, ref_mv, mvcost, error_per_bit);
-
-    /* go left then right and check error */
-    this_mv.as_mv.row = startmv.as_mv.row;
-    this_mv.as_mv.col = ((startmv.as_mv.col - 8) | 4);
-    thismse = vfp->svf_halfpix_h(y - 1, y_stride, z, b->src_stride, &sse);
-    left = thismse + mv_err_cost(&this_mv, ref_mv, mvcost, error_per_bit);
-
-    if (left < bestmse)
-    {
-        *bestmv = this_mv;
-        bestmse = left;
-        *distortion = thismse;
-        *sse1 = sse;
-    }
-
-    this_mv.as_mv.col += 8;
-    thismse = vfp->svf_halfpix_h(y, y_stride, z, b->src_stride, &sse);
-    right = thismse + mv_err_cost(&this_mv, ref_mv, mvcost, error_per_bit);
-
-    if (right < bestmse)
-    {
-        *bestmv = this_mv;
-        bestmse = right;
-        *distortion = thismse;
-        *sse1 = sse;
-    }
-
-    /* go up then down and check error */
-    this_mv.as_mv.col = startmv.as_mv.col;
-    this_mv.as_mv.row = ((startmv.as_mv.row - 8) | 4);
-    thismse = vfp->svf_halfpix_v(y - y_stride, y_stride, z, b->src_stride, &sse);
-    up = thismse + mv_err_cost(&this_mv, ref_mv, mvcost, error_per_bit);
-
-    if (up < bestmse)
-    {
-        *bestmv = this_mv;
-        bestmse = up;
-        *distortion = thismse;
-        *sse1 = sse;
-    }
-
-    this_mv.as_mv.row += 8;
-    thismse = vfp->svf_halfpix_v(y, y_stride, z, b->src_stride, &sse);
-    down = thismse + mv_err_cost(&this_mv, ref_mv, mvcost, error_per_bit);
-
-    if (down < bestmse)
-    {
-        *bestmv = this_mv;
-        bestmse = down;
-        *distortion = thismse;
-        *sse1 = sse;
-    }
-
-    /* now check 1 more diagonal - */
-    whichdir = (left < right ? 0 : 1) + (up < down ? 0 : 2);
-    this_mv = startmv;
-
-    switch (whichdir)
-    {
-    case 0:
-        this_mv.as_mv.col = (this_mv.as_mv.col - 8) | 4;
-        this_mv.as_mv.row = (this_mv.as_mv.row - 8) | 4;
-        thismse = vfp->svf_halfpix_hv(y - 1 - y_stride, y_stride, z, b->src_stride, &sse);
-        break;
-    case 1:
-        this_mv.as_mv.col += 4;
-        this_mv.as_mv.row = (this_mv.as_mv.row - 8) | 4;
-        thismse = vfp->svf_halfpix_hv(y - y_stride, y_stride, z, b->src_stride, &sse);
-        break;
-    case 2:
-        this_mv.as_mv.col = (this_mv.as_mv.col - 8) | 4;
-        this_mv.as_mv.row += 4;
-        thismse = vfp->svf_halfpix_hv(y - 1, y_stride, z, b->src_stride, &sse);
-        break;
-    case 3:
-    default:
-        this_mv.as_mv.col += 4;
-        this_mv.as_mv.row += 4;
-        thismse = vfp->svf_halfpix_hv(y, y_stride, z, b->src_stride, &sse);
-        break;
-    }
-
-    diag = thismse + mv_err_cost(&this_mv, ref_mv, mvcost, error_per_bit);
-
-    if (diag < bestmse)
-    {
-        *bestmv = this_mv;
-        bestmse = diag;
-        *distortion = thismse;
-        *sse1 = sse;
-    }
-
-    return bestmse;
-}
-
-#define CHECK_BOUNDS(range) \
-{\
-    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);\
-}
-
-#define CHECK_POINT \
-{\
-    if (this_mv.as_mv.col < x->mv_col_min) continue;\
-    if (this_mv.as_mv.col > x->mv_col_max) continue;\
-    if (this_mv.as_mv.row < x->mv_row_min) continue;\
-    if (this_mv.as_mv.row > x->mv_row_max) continue;\
-}
-
-#define CHECK_BETTER \
-{\
-    if (thissad < bestsad)\
-    {\
-        thissad += mvsad_err_cost(&this_mv, &fcenter_mv, mvsadcost, sad_per_bit);\
-        if (thissad < bestsad)\
-        {\
-            bestsad = thissad;\
-            best_site = i;\
-        }\
-    }\
-}
-
-static const MV next_chkpts[6][3] =
-{
-    {{ -2, 0}, { -1, -2}, {1, -2}},
-    {{ -1, -2}, {1, -2}, {2, 0}},
-    {{1, -2}, {2, 0}, {1, 2}},
-    {{2, 0}, {1, 2}, { -1, 2}},
-    {{1, 2}, { -1, 2}, { -2, 0}},
-    {{ -1, 2}, { -2, 0}, { -1, -2}}
-};
-
-int vp8_hex_search
-(
-    MACROBLOCK *x,
-    BLOCK *b,
-    BLOCKD *d,
-    int_mv *ref_mv,
-    int_mv *best_mv,
-    int search_param,
-    int sad_per_bit,
-    const vp8_variance_fn_ptr_t *vfp,
-    int *mvsadcost[2],
-    int *mvcost[2],
-    int_mv *center_mv
-)
-{
-    MV hex[6] = { { -1, -2}, {1, -2}, {2, 0}, {1, 2}, { -1, 2}, { -2, 0} } ;
-    MV neighbors[4] = {{0, -1}, { -1, 0}, {1, 0}, {0, 1}} ;
-    int i, j;
-
-    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;
-
-    int in_what_stride = pre_stride;
-    int br, bc;
-    int_mv this_mv;
-    unsigned int bestsad;
-    unsigned int thissad;
-    unsigned char *base_offset;
-    unsigned char *this_offset;
-    int k = -1;
-    int all_in;
-    int best_site = -1;
-    int hex_range = 127;
-    int dia_range = 8;
-
-    int_mv fcenter_mv;
-    fcenter_mv.as_mv.row = center_mv->as_mv.row >> 3;
-    fcenter_mv.as_mv.col = center_mv->as_mv.col >> 3;
-
-    (void)mvcost;
-
-    /* adjust ref_mv to make sure it is within MV range */
-    vp8_clamp_mv(ref_mv, x->mv_col_min, x->mv_col_max, x->mv_row_min, x->mv_row_max);
-    br = ref_mv->as_mv.row;
-    bc = ref_mv->as_mv.col;
-
-    /* Work out the start point for the search */
-    base_offset = (unsigned char *)(base_pre + d->offset);
-    this_offset = base_offset + (br * (pre_stride)) + bc;
-    this_mv.as_mv.row = br;
-    this_mv.as_mv.col = bc;
-    bestsad = vfp->sdf(what, what_stride, this_offset, in_what_stride)
-            + mvsad_err_cost(&this_mv, &fcenter_mv, mvsadcost, sad_per_bit);
-
-#if CONFIG_MULTI_RES_ENCODING
-    /* Lower search range based on prediction info */
-    if (search_param >= 6) goto cal_neighbors;
-    else if (search_param >= 5) hex_range = 4;
-    else if (search_param >= 4) hex_range = 6;
-    else if (search_param >= 3) hex_range = 15;
-    else if (search_param >= 2) hex_range = 31;
-    else if (search_param >= 1) hex_range = 63;
-
-    dia_range = 8;
-#else
-    (void)search_param;
-#endif
-
-    /* hex search */
-    CHECK_BOUNDS(2)
-
-    if(all_in)
-    {
-        for (i = 0; i < 6; i++)
-        {
-            this_mv.as_mv.row = br + hex[i].row;
-            this_mv.as_mv.col = bc + hex[i].col;
-            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
-        }
-    }else
-    {
-        for (i = 0; i < 6; i++)
-        {
-            this_mv.as_mv.row = br + hex[i].row;
-            this_mv.as_mv.col = bc + hex[i].col;
-            CHECK_POINT
-            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
-        }
-    }
-
-    if (best_site == -1)
-        goto cal_neighbors;
-    else
-    {
-        br += hex[best_site].row;
-        bc += hex[best_site].col;
-        k = best_site;
-    }
-
-    for (j = 1; j < hex_range; j++)
-    {
-        best_site = -1;
-        CHECK_BOUNDS(2)
-
-        if(all_in)
-        {
-            for (i = 0; i < 3; i++)
-            {
-                this_mv.as_mv.row = br + next_chkpts[k][i].row;
-                this_mv.as_mv.col = bc + next_chkpts[k][i].col;
-                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
-            }
-        }else
-        {
-            for (i = 0; i < 3; i++)
-            {
-                this_mv.as_mv.row = br + next_chkpts[k][i].row;
-                this_mv.as_mv.col = bc + next_chkpts[k][i].col;
-                CHECK_POINT
-                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
-            }
-        }
-
-        if (best_site == -1)
-            break;
-        else
-        {
-            br += next_chkpts[k][best_site].row;
-            bc += next_chkpts[k][best_site].col;
-            k += 5 + best_site;
-            if (k >= 12) k -= 12;
-            else if (k >= 6) k -= 6;
-        }
-    }
-
-    /* check 4 1-away neighbors */
-cal_neighbors:
-    for (j = 0; j < dia_range; j++)
-    {
-        best_site = -1;
-        CHECK_BOUNDS(1)
-
-        if(all_in)
-        {
-            for (i = 0; i < 4; i++)
-            {
-                this_mv.as_mv.row = br + neighbors[i].row;
-                this_mv.as_mv.col = bc + neighbors[i].col;
-                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
-            }
-        }else
-        {
-            for (i = 0; i < 4; i++)
-            {
-                this_mv.as_mv.row = br + neighbors[i].row;
-                this_mv.as_mv.col = bc + neighbors[i].col;
-                CHECK_POINT
-                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
-            }
-        }
-
-        if (best_site == -1)
-            break;
-        else
-        {
-            br += neighbors[best_site].row;
-            bc += neighbors[best_site].col;
-        }
-    }
-
-    best_mv->as_mv.row = br;
-    best_mv->as_mv.col = bc;
-
-    return bestsad;
-}
-#undef CHECK_BOUNDS
-#undef CHECK_POINT
-#undef CHECK_BETTER
-
-int vp8_diamond_search_sad_c
-(
-    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,
-    int *mvcost[2],
-    int_mv *center_mv
-)
-{
-    int i, j, step;
-
-    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;
-    unsigned char *best_address;
-
-    int tot_steps;
-    int_mv this_mv;
-
-    unsigned int bestsad;
-    unsigned int thissad;
-    int best_site = 0;
-    int last_site = 0;
-
-    int ref_row;
-    int ref_col;
-    int this_row_offset;
-    int this_col_offset;
-    search_site *ss;
-
-    unsigned char *check_here;
-
-    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;
-
-    vp8_clamp_mv(ref_mv, x->mv_col_min, x->mv_col_max, x->mv_row_min, x->mv_row_max);
-    ref_row = ref_mv->as_mv.row;
-    ref_col = ref_mv->as_mv.col;
-    *num00 = 0;
-    best_mv->as_mv.row = ref_row;
-    best_mv->as_mv.col = ref_col;
-
-    /* Work out the start point for the search */
-    in_what = (unsigned char *)(base_pre + d->offset + (ref_row * pre_stride) + ref_col);
-    best_address = in_what;
-
-    /* Check the starting position */
-    bestsad = fn_ptr->sdf(what, what_stride, in_what, in_what_stride)
-            + mvsad_err_cost(best_mv, &fcenter_mv, mvsadcost, sad_per_bit);
-
-    /* search_param determines the length of the initial step and hence
-     * the number of iterations 0 = initial step (MAX_FIRST_STEP) pel :
-     * 1 = (MAX_FIRST_STEP/2) pel, 2 = (MAX_FIRST_STEP/4) pel... etc.
-     */
-    ss = &x->ss[search_param * x->searches_per_step];
-    tot_steps = (x->ss_count / x->searches_per_step) - search_param;
-
-    i = 1;
-
-    for (step = 0; step < tot_steps ; step++)
-    {
-        for (j = 0 ; j < x->searches_per_step ; j++)
-        {
-            /* Trap illegal vectors */
-            this_row_offset = best_mv->as_mv.row + ss[i].mv.row;
-            this_col_offset = best_mv->as_mv.col + ss[i].mv.col;
-
-            if ((this_col_offset > x->mv_col_min) && (this_col_offset < x->mv_col_max) &&
-            (this_row_offset > x->mv_row_min) && (this_row_offset < x->mv_row_max))
-
-            {
-                check_here = ss[i].offset + best_address;
-                thissad = fn_ptr->sdf(what, what_stride, check_here, in_what_stride);
-
-                if (thissad < bestsad)
-                {
-                    this_mv.as_mv.row = this_row_offset;
-                    this_mv.as_mv.col = this_col_offset;
-                    thissad += mvsad_err_cost(&this_mv, &fcenter_mv,
-                                              mvsadcost, sad_per_bit);
-
-                    if (thissad < bestsad)
-                    {
-                        bestsad = thissad;
-                        best_site = i;
-                    }
-                }
-            }
-
-            i++;
-        }
-
-        if (best_site != last_site)
-        {
-            best_mv->as_mv.row += ss[best_site].mv.row;
-            best_mv->as_mv.col += ss[best_site].mv.col;
-            best_address += ss[best_site].offset;
-            last_site = best_site;
-        }
-        else if (best_address == in_what)
-            (*num00)++;
-    }
-
-    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, best_address, in_what_stride, &thissad)
-           + mv_err_cost(&this_mv, center_mv, mvcost, x->errorperbit);
-}
-
-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,
-    int *mvcost[2],
-    int_mv *center_mv
-)
-{
-    int i, j, step;
-
-    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;
-    unsigned char *best_address;
-
-    int tot_steps;
-    int_mv this_mv;
-
-    unsigned int bestsad;
-    unsigned int thissad;
-    int best_site = 0;
-    int last_site = 0;
-
-    int ref_row;
-    int ref_col;
-    int this_row_offset;
-    int this_col_offset;
-    search_site *ss;
-
-    unsigned char *check_here;
-
-    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;
-
-    vp8_clamp_mv(ref_mv, x->mv_col_min, x->mv_col_max, x->mv_row_min, x->mv_row_max);
-    ref_row = ref_mv->as_mv.row;
-    ref_col = ref_mv->as_mv.col;
-    *num00 = 0;
-    best_mv->as_mv.row = ref_row;
-    best_mv->as_mv.col = ref_col;
-
-    /* Work out the start point for the search */
-    in_what = (unsigned char *)(base_pre + d->offset + (ref_row * pre_stride) + ref_col);
-    best_address = in_what;
-
-    /* Check the starting position */
-    bestsad = fn_ptr->sdf(what, what_stride, in_what, in_what_stride)
-            + mvsad_err_cost(best_mv, &fcenter_mv, mvsadcost, sad_per_bit);
-
-    /* search_param determines the length of the initial step and hence the
-     * number of iterations 0 = initial step (MAX_FIRST_STEP) pel : 1 =
-     * (MAX_FIRST_STEP/2) pel, 2 = (MAX_FIRST_STEP/4) pel... etc.
-     */
-    ss = &x->ss[search_param * x->searches_per_step];
-    tot_steps = (x->ss_count / x->searches_per_step) - search_param;
-
-    i = 1;
-
-    for (step = 0; step < tot_steps ; step++)
-    {
-        int all_in = 1, t;
-
-        /* To know if all neighbor points are within the bounds, 4 bounds
-         * checking are enough instead of checking 4 bounds for each
-         * points.
-         */
-        all_in &= ((best_mv->as_mv.row + ss[i].mv.row)> x->mv_row_min);
-        all_in &= ((best_mv->as_mv.row + ss[i+1].mv.row) < x->mv_row_max);
-        all_in &= ((best_mv->as_mv.col + ss[i+2].mv.col) > x->mv_col_min);
-        all_in &= ((best_mv->as_mv.col + ss[i+3].mv.col) < x->mv_col_max);
-
-        if (all_in)
-        {
-            unsigned int sad_array[4];
-
-            for (j = 0 ; j < x->searches_per_step ; j += 4)
-            {
-                const unsigned char *block_offset[4];
-
-                for (t = 0; t < 4; t++)
-                    block_offset[t] = ss[i+t].offset + best_address;
-
-                fn_ptr->sdx4df(what, what_stride, block_offset, in_what_stride, sad_array);
-
-                for (t = 0; t < 4; t++, i++)
-                {
-                    if (sad_array[t] < bestsad)
-                    {
-                        this_mv.as_mv.row = best_mv->as_mv.row + ss[i].mv.row;
-                        this_mv.as_mv.col = best_mv->as_mv.col + ss[i].mv.col;
-                        sad_array[t] += mvsad_err_cost(&this_mv, &fcenter_mv,
-                                                       mvsadcost, sad_per_bit);
-
-                        if (sad_array[t] < bestsad)
-                        {
-                            bestsad = sad_array[t];
-                            best_site = i;
-                        }
-                    }
-                }
-            }
-        }
-        else
-        {
-            for (j = 0 ; j < x->searches_per_step ; j++)
-            {
-                /* Trap illegal vectors */
-                this_row_offset = best_mv->as_mv.row + ss[i].mv.row;
-                this_col_offset = best_mv->as_mv.col + ss[i].mv.col;
-
-                if ((this_col_offset > x->mv_col_min) && (this_col_offset < x->mv_col_max) &&
-                (this_row_offset > x->mv_row_min) && (this_row_offset < x->mv_row_max))
-                {
-                    check_here = ss[i].offset + best_address;
-                    thissad = fn_ptr->sdf(what, what_stride, check_here, in_what_stride);
-
-                    if (thissad < bestsad)
-                    {
-                        this_mv.as_mv.row = this_row_offset;
-                        this_mv.as_mv.col = this_col_offset;
-                        thissad += mvsad_err_cost(&this_mv, &fcenter_mv,
-                                                  mvsadcost, sad_per_bit);
-
-                        if (thissad < bestsad)
-                        {
-                            bestsad = thissad;
-                            best_site = i;
-                        }
-                    }
-                }
-                i++;
-            }
-        }
-
-        if (best_site != last_site)
-        {
-            best_mv->as_mv.row += ss[best_site].mv.row;
-            best_mv->as_mv.col += ss[best_site].mv.col;
-            best_address += ss[best_site].offset;
-            last_site = best_site;
-        }
-        else if (best_address == in_what)
-            (*num00)++;
-    }
-
-    this_mv.as_mv.row = best_mv->as_mv.row * 8;
-    this_mv.as_mv.col = best_mv->as_mv.col * 8;
-
-    return fn_ptr->vf(what, what_stride, best_address, in_what_stride, &thissad)
-           + mv_err_cost(&this_mv, center_mv, mvcost, x->errorperbit);
-}
-
-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);
-}
-
-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)
-{
-    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;
-
-    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);
-}
-
-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;
-
-    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 + 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)
-        {
-            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 * 8;
-    this_mv.as_mv.col = best_mv->as_mv.col * 8;
-
-    return fn_ptr->vf(what, what_stride, bestaddress, in_what_stride, &thissad)
-           + mv_err_cost(&this_mv, center_mv, mvcost, x->errorperbit);
-}
-
-int vp8_refining_search_sad_c(MACROBLOCK *x, BLOCK *b, BLOCKD *d, int_mv *ref_mv,
-                            int error_per_bit, int search_range,
-                            vp8_variance_fn_ptr_t *fn_ptr, int *mvcost[2],
-                            int_mv *center_mv)
-{
-    MV neighbors[4] = {{-1, 0}, {0, -1}, {0, 1}, {1, 0}};
-    int i, j;
-    short this_row_offset, this_col_offset;
-
-    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;
-    int in_what_stride = pre_stride;
-    unsigned char *what = (*(b->base_src) + b->src);
-    unsigned char *best_address = (unsigned char *)(base_pre + d->offset +
-        (ref_mv->as_mv.row * pre_stride) + ref_mv->as_mv.col);
-    unsigned char *check_here;
-    int_mv this_mv;
-    unsigned int bestsad;
-    unsigned int thissad;
-
-    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;
-
-    bestsad = fn_ptr->sdf(what, what_stride, best_address, in_what_stride)
-            + mvsad_err_cost(ref_mv, &fcenter_mv, mvsadcost, error_per_bit);
-
-    for (i=0; i<search_range; i++)
-    {
-        int best_site = -1;
-
-        for (j = 0 ; j < 4 ; j++)
-        {
-            this_row_offset = ref_mv->as_mv.row + neighbors[j].row;
-            this_col_offset = ref_mv->as_mv.col + neighbors[j].col;
-
-            if ((this_col_offset > x->mv_col_min) && (this_col_offset < x->mv_col_max) &&
-            (this_row_offset > x->mv_row_min) && (this_row_offset < x->mv_row_max))
-            {
-                check_here = (neighbors[j].row)*in_what_stride + neighbors[j].col + best_address;
-                thissad = fn_ptr->sdf(what, what_stride, check_here , in_what_stride);
-
-                if (thissad < bestsad)
-                {
-                    this_mv.as_mv.row = this_row_offset;
-                    this_mv.as_mv.col = this_col_offset;
-                    thissad += mvsad_err_cost(&this_mv, &fcenter_mv, mvsadcost, error_per_bit);
-
-                    if (thissad < bestsad)
-                    {
-                        bestsad = thissad;
-                        best_site = j;
-                    }
-                }
-            }
-        }
-
-        if (best_site == -1)
-            break;
-        else
-        {
-            ref_mv->as_mv.row += neighbors[best_site].row;
-            ref_mv->as_mv.col += neighbors[best_site].col;
-            best_address += (neighbors[best_site].row)*in_what_stride + neighbors[best_site].col;
-        }
-    }
-
-    this_mv.as_mv.row = ref_mv->as_mv.row << 3;
-    this_mv.as_mv.col = ref_mv->as_mv.col << 3;
-
-    return fn_ptr->vf(what, what_stride, best_address, in_what_stride, &thissad)
-           + mv_err_cost(&this_mv, center_mv, mvcost, x->errorperbit);
-}
-
-int vp8_refining_search_sadx4(MACROBLOCK *x, BLOCK *b, BLOCKD *d,
-                              int_mv *ref_mv, int error_per_bit,
-                              int search_range, vp8_variance_fn_ptr_t *fn_ptr,
-                              int *mvcost[2], int_mv *center_mv)
-{
-    MV neighbors[4] = {{-1, 0}, {0, -1}, {0, 1}, {1, 0}};
-    int i, j;
-    short this_row_offset, this_col_offset;
-
-    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;
-    int in_what_stride = pre_stride;
-    unsigned char *what = (*(b->base_src) + b->src);
-    unsigned char *best_address = (unsigned char *)(base_pre + d->offset +
-        (ref_mv->as_mv.row * pre_stride) + ref_mv->as_mv.col);
-    unsigned char *check_here;
-    int_mv this_mv;
-    unsigned int bestsad;
-    unsigned int thissad;
-
-    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;
-
-    bestsad = fn_ptr->sdf(what, what_stride, best_address, in_what_stride)
-            + mvsad_err_cost(ref_mv, &fcenter_mv, mvsadcost, error_per_bit);
-
-    for (i=0; i<search_range; i++)
-    {
-        int best_site = -1;
-        int all_in = 1;
-
-        all_in &= ((ref_mv->as_mv.row - 1) > x->mv_row_min);
-        all_in &= ((ref_mv->as_mv.row + 1) < x->mv_row_max);
-        all_in &= ((ref_mv->as_mv.col - 1) > x->mv_col_min);
-        all_in &= ((ref_mv->as_mv.col + 1) < x->mv_col_max);
-
-        if(all_in)
-        {
-            unsigned int sad_array[4];
-            const unsigned char *block_offset[4];
-            block_offset[0] = best_address - in_what_stride;
-            block_offset[1] = best_address - 1;
-            block_offset[2] = best_address + 1;
-            block_offset[3] = best_address + in_what_stride;
-
-            fn_ptr->sdx4df(what, what_stride, block_offset, in_what_stride, sad_array);
-
-            for (j = 0; j < 4; j++)
-            {
-                if (sad_array[j] < bestsad)
-                {
-                    this_mv.as_mv.row = ref_mv->as_mv.row + neighbors[j].row;
-                    this_mv.as_mv.col = ref_mv->as_mv.col + neighbors[j].col;
-                    sad_array[j] += mvsad_err_cost(&this_mv, &fcenter_mv, mvsadcost, error_per_bit);
-
-                    if (sad_array[j] < bestsad)
-                    {
-                        bestsad = sad_array[j];
-                        best_site = j;
-                    }
-                }
-            }
-        }
-        else
-        {
-            for (j = 0 ; j < 4 ; j++)
-            {
-                this_row_offset = ref_mv->as_mv.row + neighbors[j].row;
-                this_col_offset = ref_mv->as_mv.col + neighbors[j].col;
-
-                if ((this_col_offset > x->mv_col_min) && (this_col_offset < x->mv_col_max) &&
-                (this_row_offset > x->mv_row_min) && (this_row_offset < x->mv_row_max))
-                {
-                    check_here = (neighbors[j].row)*in_what_stride + neighbors[j].col + best_address;
-                    thissad = fn_ptr->sdf(what, what_stride, check_here , in_what_stride);
-
-                    if (thissad < bestsad)
-                    {
-                        this_mv.as_mv.row = this_row_offset;
-                        this_mv.as_mv.col = this_col_offset;
-                        thissad += mvsad_err_cost(&this_mv, &fcenter_mv, mvsadcost, error_per_bit);
-
-                        if (thissad < bestsad)
-                        {
-                            bestsad = thissad;
-                            best_site = j;
-                        }
-                    }
-                }
-            }
-        }
-
-        if (best_site == -1)
-            break;
-        else
-        {
-            ref_mv->as_mv.row += neighbors[best_site].row;
-            ref_mv->as_mv.col += neighbors[best_site].col;
-            best_address += (neighbors[best_site].row)*in_what_stride + neighbors[best_site].col;
-        }
-    }
-
-    this_mv.as_mv.row = ref_mv->as_mv.row * 8;
-    this_mv.as_mv.col = ref_mv->as_mv.col * 8;
-
-    return fn_ptr->vf(what, what_stride, best_address, in_what_stride, &thissad)
-           + mv_err_cost(&this_mv, center_mv, mvcost, x->errorperbit);
-}
-
-#ifdef VP8_ENTROPY_STATS
-void print_mode_context(void)
-{
-    FILE *f = fopen("modecont.c", "w");
-    int i, j;
-
-    fprintf(f, "#include \"entropy.h\"\n");
-    fprintf(f, "const int vp8_mode_contexts[6][4] =\n");
-    fprintf(f, "{\n");
-
-    for (j = 0; j < 6; j++)
-    {
-        fprintf(f, "  { /* %d */\n", j);
-        fprintf(f, "    ");
-
-        for (i = 0; i < 4; i++)
-        {
-            int overal_prob;
-            int this_prob;
-            int count;
-
-            /* Overall probs */
-            count = mv_mode_cts[i][0] + mv_mode_cts[i][1];
-
-            if (count)
-                overal_prob = 256 * mv_mode_cts[i][0] / count;
-            else
-                overal_prob = 128;
-
-            if (overal_prob == 0)
-                overal_prob = 1;
-
-            /* context probs */
-            count = mv_ref_ct[j][i][0] + mv_ref_ct[j][i][1];
-
-            if (count)
-                this_prob = 256 * mv_ref_ct[j][i][0] / count;
-            else
-                this_prob = 128;
-
-            if (this_prob == 0)
-                this_prob = 1;
-
-            fprintf(f, "%5d, ", this_prob);
-        }
-
-        fprintf(f, "  },\n");
-    }
-
-    fprintf(f, "};\n");
-    fclose(f);
-}
-
-/* MV ref count VP8_ENTROPY_STATS stats code */
-#ifdef VP8_ENTROPY_STATS
-void init_mv_ref_counts()
-{
-    memset(mv_ref_ct, 0, sizeof(mv_ref_ct));
-    memset(mv_mode_cts, 0, sizeof(mv_mode_cts));
-}
-
-void accum_mv_refs(MB_PREDICTION_MODE m, const int ct[4])
-{
-    if (m == ZEROMV)
-    {
-        ++mv_ref_ct [ct[0]] [0] [0];
-        ++mv_mode_cts[0][0];
-    }
-    else
-    {
-        ++mv_ref_ct [ct[0]] [0] [1];
-        ++mv_mode_cts[0][1];
-
-        if (m == NEARESTMV)
-        {
-            ++mv_ref_ct [ct[1]] [1] [0];
-            ++mv_mode_cts[1][0];
-        }
-        else
-        {
-            ++mv_ref_ct [ct[1]] [1] [1];
-            ++mv_mode_cts[1][1];
-
-            if (m == NEARMV)
-            {
-                ++mv_ref_ct [ct[2]] [2] [0];
-                ++mv_mode_cts[2][0];
-            }
-            else
-            {
-                ++mv_ref_ct [ct[2]] [2] [1];
-                ++mv_mode_cts[2][1];
-
-                if (m == NEWMV)
-                {
-                    ++mv_ref_ct [ct[3]] [3] [0];
-                    ++mv_mode_cts[3][0];
-                }
-                else
-                {
-                    ++mv_ref_ct [ct[3]] [3] [1];
-                    ++mv_mode_cts[3][1];
-                }
-            }
-        }
-    }
-}
-
-#endif/* END MV ref count VP8_ENTROPY_STATS stats code */
-
-#endif
diff --git a/vp8/encoder/mcomp.h b/vp8/encoder/mcomp.h
deleted file mode 100644 (file)
index 1694af8..0000000
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#ifndef VP8_ENCODER_MCOMP_H_
-#define VP8_ENCODER_MCOMP_H_
-
-#include "block.h"
-#include "vpx_dsp/variance.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#ifdef VP8_ENTROPY_STATS
-extern void init_mv_ref_counts();
-extern void accum_mv_refs(MB_PREDICTION_MODE, const int near_mv_ref_cts[4]);
-#endif
-
-
-/* The maximum number of steps in a step search given the largest allowed
- * initial step
- */
-#define MAX_MVSEARCH_STEPS 8
-
-/* Max full pel mv specified in 1 pel units */
-#define MAX_FULL_PEL_VAL ((1 << (MAX_MVSEARCH_STEPS)) - 1)
-
-/* Maximum size of the first step in full pel units */
-#define MAX_FIRST_STEP (1 << (MAX_MVSEARCH_STEPS-1))
-
-extern void print_mode_context(void);
-extern int vp8_mv_bit_cost(int_mv *mv, int_mv *ref, int *mvcost[2], int Weight);
-extern void vp8_init_dsmotion_compensation(MACROBLOCK *x, int stride);
-extern void vp8_init3smotion_compensation(MACROBLOCK *x,  int stride);
-
-
-extern int vp8_hex_search
-(
-    MACROBLOCK *x,
-    BLOCK *b,
-    BLOCKD *d,
-    int_mv *ref_mv,
-    int_mv *best_mv,
-    int search_param,
-    int error_per_bit,
-    const vp8_variance_fn_ptr_t *vf,
-    int *mvsadcost[2],
-    int *mvcost[2],
-    int_mv *center_mv
-);
-
-typedef int (fractional_mv_step_fp)
-    (MACROBLOCK *x, BLOCK *b, BLOCKD *d, int_mv *bestmv, int_mv *ref_mv,
-     int error_per_bit, const vp8_variance_fn_ptr_t *vfp, int *mvcost[2],
-     int *distortion, unsigned int *sse);
-
-extern fractional_mv_step_fp vp8_find_best_sub_pixel_step_iteratively;
-extern fractional_mv_step_fp vp8_find_best_sub_pixel_step;
-extern fractional_mv_step_fp vp8_find_best_half_pixel_step;
-extern fractional_mv_step_fp vp8_skip_fractional_mv_step;
-
-typedef int (*vp8_full_search_fn_t)
-    (
-     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
-    );
-
-typedef int (*vp8_refining_search_fn_t)
-    (
-     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
-    );
-
-typedef int (*vp8_diamond_search_fn_t)
-    (
-     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,
-     int *mvcost[2],
-     int_mv *center_mv
-    );
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP8_ENCODER_MCOMP_H_
diff --git a/vp8/encoder/mips/msa/dct_msa.c b/vp8/encoder/mips/msa/dct_msa.c
deleted file mode 100644 (file)
index be61ffa..0000000
+++ /dev/null
@@ -1,199 +0,0 @@
-/*
- *  Copyright (c) 2015 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.
- */
-
-#include "./vp8_rtcd.h"
-#include "vp8/common/mips/msa/vp8_macros_msa.h"
-
-#define TRANSPOSE4x4_H(in0, in1, in2, in3, out0, out1, out2, out3)  \
-{                                                                   \
-    v8i16 s0_m, s1_m, tp0_m, tp1_m, tp2_m, tp3_m;                   \
-                                                                    \
-    ILVR_H2_SH(in2, in0, in3, in1, s0_m, s1_m);                     \
-    ILVRL_H2_SH(s1_m, s0_m, tp0_m, tp1_m);                          \
-    ILVL_H2_SH(in2, in0, in3, in1, s0_m, s1_m);                     \
-    ILVRL_H2_SH(s1_m, s0_m, tp2_m, tp3_m);                          \
-    PCKEV_D2_SH(tp2_m, tp0_m, tp3_m, tp1_m, out0, out2);            \
-    PCKOD_D2_SH(tp2_m, tp0_m, tp3_m, tp1_m, out1, out3);            \
-}
-
-#define SET_DOTP_VALUES(coeff, val0, val1, val2, const1, const2)    \
-{                                                                   \
-    v8i16 tmp0_m;                                                   \
-                                                                    \
-    SPLATI_H3_SH(coeff, val0, val1, val2, tmp0_m, const1, const2);  \
-    ILVEV_H2_SH(tmp0_m, const1, const2, tmp0_m, const1, const2);    \
-}
-
-#define RET_1_IF_NZERO_H(in0)       \
-({                                  \
-    v8i16 tmp0_m;                   \
-    v8i16 one_m = __msa_ldi_h(1);   \
-                                    \
-    tmp0_m = __msa_ceqi_h(in0, 0);  \
-    tmp0_m = tmp0_m ^ 255;          \
-    tmp0_m = one_m & tmp0_m;        \
-                                    \
-    tmp0_m;                         \
-})
-
-#define RET_1_IF_NZERO_W(in0)       \
-({                                  \
-    v4i32 tmp0_m;                   \
-    v4i32 one_m = __msa_ldi_w(1);   \
-                                    \
-    tmp0_m = __msa_ceqi_w(in0, 0);  \
-    tmp0_m = tmp0_m ^ 255;          \
-    tmp0_m = one_m & tmp0_m;        \
-                                    \
-    tmp0_m;                         \
-})
-
-#define RET_1_IF_NEG_W(in0)           \
-({                                    \
-    v4i32 tmp0_m;                     \
-                                      \
-    v4i32 one_m = __msa_ldi_w(1);     \
-    tmp0_m = __msa_clti_s_w(in0, 0);  \
-    tmp0_m = one_m & tmp0_m;          \
-                                      \
-    tmp0_m;                           \
-})
-
-void vp8_short_fdct4x4_msa(int16_t *input, int16_t *output, int32_t pitch)
-{
-    v8i16 in0, in1, in2, in3;
-    v8i16 temp0, temp1;
-    v8i16 const0, const1;
-    v8i16 coeff = { 2217, 5352, -5352, 14500, 7500, 12000, 25000, 26000 };
-    v4i32 out0, out1, out2, out3;
-    v8i16 zero = { 0 };
-
-    LD_SH4(input, pitch / 2, in0, in1, in2, in3);
-    TRANSPOSE4x4_SH_SH(in0, in1, in2, in3, in0, in1, in2, in3);
-
-    BUTTERFLY_4(in0, in1, in2, in3, temp0, temp1, in1, in3);
-    SLLI_4V(temp0, temp1, in1, in3, 3);
-    in0 = temp0 + temp1;
-    in2 = temp0 - temp1;
-    SET_DOTP_VALUES(coeff, 0, 1, 2, const0, const1);
-    temp0 = __msa_ilvr_h(in3, in1);
-    in1 = __msa_splati_h(coeff, 3);
-    out0 = (v4i32)__msa_ilvev_h(zero, in1);
-    coeff = __msa_ilvl_h(zero, coeff);
-    out1 = __msa_splati_w((v4i32)coeff, 0);
-    DPADD_SH2_SW(temp0, temp0, const0, const1, out0, out1);
-    out0 >>= 12;
-    out1 >>= 12;
-    PCKEV_H2_SH(out0, out0, out1, out1, in1, in3);
-    TRANSPOSE4x4_SH_SH(in0, in1, in2, in3, in0, in1, in2, in3);
-
-    BUTTERFLY_4(in0, in1, in2, in3, temp0, temp1, in1, in3);
-    in0 = temp0 + temp1 + 7;
-    in2 = temp0 - temp1 + 7;
-    in0 >>= 4;
-    in2 >>= 4;
-    ILVR_H2_SW(zero, in0, zero, in2, out0, out2);
-    temp1 = RET_1_IF_NZERO_H(in3);
-    ILVR_H2_SH(zero, temp1, in3, in1, temp1, temp0);
-    SPLATI_W2_SW(coeff, 2, out3, out1);
-    out3 += out1;
-    out1 = __msa_splati_w((v4i32)coeff, 1);
-    DPADD_SH2_SW(temp0, temp0, const0, const1, out1, out3);
-    out1 >>= 16;
-    out3 >>= 16;
-    out1 += (v4i32)temp1;
-    PCKEV_H2_SH(out1, out0, out3, out2, in0, in2);
-    ST_SH2(in0, in2, output, 8);
-}
-
-void vp8_short_fdct8x4_msa(int16_t *input, int16_t *output, int32_t pitch)
-{
-    v8i16 in0, in1, in2, in3;
-    v8i16 temp0, temp1, tmp0, tmp1;
-    v8i16 const0, const1, const2;
-    v8i16 coeff = { 2217, 5352, -5352, 14500, 7500, 12000, 25000, 26000 };
-    v8i16 zero = { 0 };
-    v4i32 vec0_w, vec1_w, vec2_w, vec3_w;
-
-    LD_SH4(input, pitch / 2, in0, in1, in2, in3);
-    TRANSPOSE4x4_H(in0, in1, in2, in3, in0, in1, in2, in3);
-
-    BUTTERFLY_4(in0, in1, in2, in3, temp0, temp1, in1, in3);
-    SLLI_4V(temp0, temp1, in1, in3, 3);
-    in0 = temp0 + temp1;
-    in2 = temp0 - temp1;
-    SET_DOTP_VALUES(coeff, 0, 1, 2, const1, const2);
-    temp0 = __msa_splati_h(coeff, 3);
-    vec1_w = (v4i32)__msa_ilvev_h(zero, temp0);
-    coeff = __msa_ilvl_h(zero, coeff);
-    vec3_w = __msa_splati_w((v4i32)coeff, 0);
-    ILVRL_H2_SH(in3, in1, tmp1, tmp0);
-    vec0_w = vec1_w;
-    vec2_w = vec3_w;
-    DPADD_SH4_SW(tmp1, tmp0, tmp1, tmp0, const1, const1, const2, const2,
-                 vec0_w, vec1_w, vec2_w, vec3_w);
-    SRA_4V(vec1_w, vec0_w, vec3_w, vec2_w, 12);
-    PCKEV_H2_SH(vec1_w, vec0_w, vec3_w, vec2_w, in1, in3);
-    TRANSPOSE4x4_H(in0, in1, in2, in3, in0, in1, in2, in3);
-
-    BUTTERFLY_4(in0, in1, in2, in3, temp0, temp1, in1, in3);
-    in0 = temp0 + temp1 + 7;
-    in2 = temp0 - temp1 + 7;
-    in0 >>= 4;
-    in2 >>= 4;
-    SPLATI_W2_SW(coeff, 2, vec3_w, vec1_w);
-    vec3_w += vec1_w;
-    vec1_w = __msa_splati_w((v4i32)coeff, 1);
-    const0 = RET_1_IF_NZERO_H(in3);
-    ILVRL_H2_SH(in3, in1, tmp1, tmp0);
-    vec0_w = vec1_w;
-    vec2_w = vec3_w;
-    DPADD_SH4_SW(tmp1, tmp0, tmp1, tmp0, const1, const1, const2, const2,
-                 vec0_w, vec1_w, vec2_w, vec3_w);
-    SRA_4V(vec1_w, vec0_w, vec3_w, vec2_w, 16);
-    PCKEV_H2_SH(vec1_w, vec0_w, vec3_w, vec2_w, in1, in3);
-    in1 += const0;
-    PCKEV_D2_SH(in1, in0, in3, in2, temp0, temp1);
-    ST_SH2(temp0, temp1, output, 8);
-
-    PCKOD_D2_SH(in1, in0, in3, in2, in0, in2);
-    ST_SH2(in0, in2, output + 16, 8);
-}
-
-void vp8_short_walsh4x4_msa(int16_t *input, int16_t *output, int32_t pitch)
-{
-    v8i16 in0_h, in1_h, in2_h, in3_h;
-    v4i32 in0_w, in1_w, in2_w, in3_w, temp0, temp1, temp2, temp3;
-
-    LD_SH4(input, pitch / 2, in0_h, in1_h, in2_h, in3_h);
-    TRANSPOSE4x4_SH_SH(in0_h, in1_h, in2_h, in3_h, in0_h, in1_h, in2_h, in3_h);
-
-    UNPCK_R_SH_SW(in0_h, in0_w);
-    UNPCK_R_SH_SW(in1_h, in1_w);
-    UNPCK_R_SH_SW(in2_h, in2_w);
-    UNPCK_R_SH_SW(in3_h, in3_w);
-    BUTTERFLY_4(in0_w, in1_w, in3_w, in2_w, temp0, temp3, temp2, temp1);
-    SLLI_4V(temp0, temp1, temp2, temp3, 2);
-    BUTTERFLY_4(temp0, temp1, temp2, temp3, in0_w, in1_w, in2_w, in3_w);
-    temp0 = RET_1_IF_NZERO_W(temp0);
-    in0_w += temp0;
-    TRANSPOSE4x4_SW_SW(in0_w, in1_w, in2_w, in3_w, in0_w, in1_w, in2_w, in3_w);
-
-    BUTTERFLY_4(in0_w, in1_w, in3_w, in2_w, temp0, temp3, temp2, temp1);
-    BUTTERFLY_4(temp0, temp1, temp2, temp3, in0_w, in1_w, in2_w, in3_w);
-    in0_w += RET_1_IF_NEG_W(in0_w);
-    in1_w += RET_1_IF_NEG_W(in1_w);
-    in2_w += RET_1_IF_NEG_W(in2_w);
-    in3_w += RET_1_IF_NEG_W(in3_w);
-    ADD4(in0_w, 3, in1_w, 3, in2_w, 3, in3_w, 3, in0_w, in1_w, in2_w, in3_w);
-    SRA_4V(in0_w, in1_w, in2_w, in3_w, 3);
-    PCKEV_H2_SH(in1_w, in0_w, in3_w, in2_w, in0_h, in1_h);
-    ST_SH2(in0_h, in1_h, output, 8);
-}
diff --git a/vp8/encoder/mips/msa/denoising_msa.c b/vp8/encoder/mips/msa/denoising_msa.c
deleted file mode 100644 (file)
index 66965c6..0000000
+++ /dev/null
@@ -1,624 +0,0 @@
-/*
- *  Copyright (c) 2015 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.
- */
-
-#include <stdlib.h>
-#include "./vp8_rtcd.h"
-#include "vp8/common/mips/msa/vp8_macros_msa.h"
-#include "vp8/encoder/denoising.h"
-
-int32_t vp8_denoiser_filter_msa(uint8_t *mc_running_avg_y_ptr,
-                                int32_t mc_avg_y_stride,
-                                uint8_t *running_avg_y_ptr,
-                                int32_t avg_y_stride,
-                                uint8_t *sig_ptr, int32_t sig_stride,
-                                uint32_t motion_magnitude,
-                                int32_t increase_denoising)
-{
-    uint8_t *running_avg_y_start = running_avg_y_ptr;
-    uint8_t *sig_start = sig_ptr;
-    int32_t cnt = 0;
-    int32_t sum_diff = 0;
-    int32_t shift_inc1 = 3;
-    int32_t delta = 0;
-    int32_t sum_diff_thresh;
-    v16u8 src0, src1, src2, src3, src4, src5, src6, src7;
-    v16u8 src8, src9, src10, src11, src12, src13, src14, src15;
-    v16u8 mc_running_avg_y0, running_avg_y, sig0;
-    v16u8 mc_running_avg_y1, running_avg_y1, sig1;
-    v16u8 coeff0, coeff1;
-    v8i16 diff0, diff1, abs_diff0, abs_diff1, abs_diff_neg0, abs_diff_neg1;
-    v8i16 adjust0, adjust1, adjust2, adjust3;
-    v8i16 shift_inc1_vec = { 0 };
-    v8i16 col_sum0 = { 0 };
-    v8i16 col_sum1 = { 0 };
-    v8i16 col_sum2 = { 0 };
-    v8i16 col_sum3 = { 0 };
-    v8i16 temp0_h, temp1_h, temp2_h, temp3_h, cmp, delta_vec;
-    v4i32 temp0_w;
-    v2i64 temp0_d, temp1_d;
-    v8i16 zero = { 0 };
-    v8i16 one = __msa_ldi_h(1);
-    v8i16 four = __msa_ldi_h(4);
-    v8i16 val_127 = __msa_ldi_h(127);
-    v8i16 adj_val = { 6, 4, 3, 0, -6, -4, -3, 0 };
-
-    if (motion_magnitude <= MOTION_MAGNITUDE_THRESHOLD)
-    {
-        adj_val = __msa_add_a_h(adj_val, one);
-        if (increase_denoising)
-        {
-            adj_val = __msa_add_a_h(adj_val, one);
-            shift_inc1 = 4;
-        }
-
-        temp0_h = zero - adj_val;
-        adj_val = (v8i16)__msa_ilvev_d((v2i64)temp0_h, (v2i64)adj_val);
-    }
-
-    adj_val = __msa_insert_h(adj_val, 3, cnt);
-    adj_val = __msa_insert_h(adj_val, 7, cnt);
-    shift_inc1_vec = __msa_fill_h(shift_inc1);
-
-    for (cnt = 8; cnt--;)
-    {
-        v8i16 mask0 = { 0 };
-        v8i16 mask1 = { 0 };
-
-        mc_running_avg_y0 = LD_UB(mc_running_avg_y_ptr);
-        sig0 = LD_UB(sig_ptr);
-        sig_ptr += sig_stride;
-        mc_running_avg_y_ptr += mc_avg_y_stride;
-
-        mc_running_avg_y1 = LD_UB(mc_running_avg_y_ptr);
-        sig1 = LD_UB(sig_ptr);
-
-        ILVRL_B2_UB(mc_running_avg_y0, sig0, coeff0, coeff1);
-        HSUB_UB2_SH(coeff0, coeff1, diff0, diff1);
-        abs_diff0 = __msa_add_a_h(diff0, zero);
-        abs_diff1 = __msa_add_a_h(diff1, zero);
-        cmp = __msa_clei_s_h(abs_diff0, 15);
-        cmp = cmp & one;
-        mask0 += cmp;
-        cmp = __msa_clei_s_h(abs_diff0, 7);
-        cmp = cmp & one;
-        mask0 += cmp;
-        cmp = abs_diff0 < shift_inc1_vec;
-        cmp = cmp & one;
-        mask0 += cmp;
-        cmp = __msa_clei_s_h(abs_diff1, 15);
-        cmp = cmp & one;
-        mask1 += cmp;
-        cmp = __msa_clei_s_h(abs_diff1, 7);
-        cmp = cmp & one;
-        mask1 += cmp;
-        cmp = abs_diff1 < shift_inc1_vec;
-        cmp = cmp & one;
-        mask1 += cmp;
-        temp0_h = __msa_clei_s_h(diff0, 0);
-        temp0_h = temp0_h & four;
-        mask0 += temp0_h;
-        temp1_h = __msa_clei_s_h(diff1, 0);
-        temp1_h = temp1_h & four;
-        mask1 += temp1_h;
-        VSHF_H2_SH(adj_val, adj_val, adj_val, adj_val, mask0, mask1, adjust0,
-                   adjust1);
-        temp2_h = __msa_ceqi_h(adjust0, 0);
-        temp3_h = __msa_ceqi_h(adjust1, 0);
-        adjust0 = (v8i16)__msa_bmnz_v((v16u8)adjust0, (v16u8)diff0,
-                                     (v16u8)temp2_h);
-        adjust1 = (v8i16)__msa_bmnz_v((v16u8)adjust1, (v16u8)diff1,
-                                     (v16u8)temp3_h);
-        ADD2(col_sum0, adjust0, col_sum1, adjust1, col_sum0, col_sum1);
-        UNPCK_UB_SH(sig0, temp0_h, temp1_h);
-        ADD2(temp0_h, adjust0, temp1_h, adjust1, temp0_h, temp1_h);
-        MAXI_SH2_SH(temp0_h, temp1_h, 0);
-        SAT_UH2_SH(temp0_h, temp1_h, 7);
-        temp2_h = (v8i16)__msa_pckev_b((v16i8)temp3_h, (v16i8)temp2_h);
-        running_avg_y = (v16u8)__msa_pckev_b((v16i8)temp1_h, (v16i8)temp0_h);
-        running_avg_y = __msa_bmnz_v(running_avg_y, mc_running_avg_y0,
-                                     (v16u8)temp2_h);
-        ST_UB(running_avg_y, running_avg_y_ptr);
-        running_avg_y_ptr += avg_y_stride;
-
-        mask0 = zero;
-        mask1 = zero;
-        ILVRL_B2_UB(mc_running_avg_y1, sig1, coeff0, coeff1);
-        HSUB_UB2_SH(coeff0, coeff1, diff0, diff1);
-        abs_diff0 = __msa_add_a_h(diff0, zero);
-        abs_diff1 = __msa_add_a_h(diff1, zero);
-        cmp = __msa_clei_s_h(abs_diff0, 15);
-        cmp = cmp & one;
-        mask0 += cmp;
-        cmp = __msa_clei_s_h(abs_diff0, 7);
-        cmp = cmp & one;
-        mask0 += cmp;
-        cmp = abs_diff0 < shift_inc1_vec;
-        cmp = cmp & one;
-        mask0 += cmp;
-        cmp = __msa_clei_s_h(abs_diff1, 15);
-        cmp = cmp & one;
-        mask1 += cmp;
-        cmp = __msa_clei_s_h(abs_diff1, 7);
-        cmp = cmp & one;
-        mask1 += cmp;
-        cmp = abs_diff1 < shift_inc1_vec;
-        cmp = cmp & one;
-        mask1 += cmp;
-        temp0_h = __msa_clei_s_h(diff0, 0);
-        temp0_h = temp0_h & four;
-        mask0 += temp0_h;
-        temp1_h = __msa_clei_s_h(diff1, 0);
-        temp1_h = temp1_h & four;
-        mask1 += temp1_h;
-        VSHF_H2_SH(adj_val, adj_val, adj_val, adj_val, mask0, mask1, adjust0,
-                   adjust1);
-        temp2_h = __msa_ceqi_h(adjust0, 0);
-        temp3_h = __msa_ceqi_h(adjust1, 0);
-        adjust0 = (v8i16)__msa_bmnz_v((v16u8)adjust0, (v16u8)diff0,
-                                      (v16u8)temp2_h);
-        adjust1 = (v8i16)__msa_bmnz_v((v16u8)adjust1, (v16u8)diff1,
-                                      (v16u8)temp3_h);
-        ADD2(col_sum0, adjust0, col_sum1, adjust1, col_sum0, col_sum1);
-        UNPCK_UB_SH(sig1, temp0_h, temp1_h);
-        ADD2(temp0_h, adjust0, temp1_h, adjust1, temp0_h, temp1_h);
-        MAXI_SH2_SH(temp0_h, temp1_h, 0);
-        SAT_UH2_SH(temp0_h, temp1_h, 7);
-        temp2_h = (v8i16)__msa_pckev_b((v16i8)temp3_h, (v16i8)temp2_h);
-        running_avg_y = (v16u8)__msa_pckev_b((v16i8)temp1_h, (v16i8)temp0_h);
-        running_avg_y = __msa_bmnz_v(running_avg_y, mc_running_avg_y1,
-                                     (v16u8)temp2_h);
-        ST_UB(running_avg_y, running_avg_y_ptr);
-        sig_ptr += sig_stride;
-        mc_running_avg_y_ptr += mc_avg_y_stride;
-        running_avg_y_ptr += avg_y_stride;
-    }
-
-    col_sum0 = __msa_min_s_h(col_sum0, val_127);
-    col_sum1 = __msa_min_s_h(col_sum1, val_127);
-    temp0_h = col_sum0 + col_sum1;
-    temp0_w = __msa_hadd_s_w(temp0_h, temp0_h);
-    temp0_d = __msa_hadd_s_d(temp0_w, temp0_w);
-    temp1_d = __msa_splati_d(temp0_d, 1);
-    temp0_d += temp1_d;
-    sum_diff = __msa_copy_s_w((v4i32)temp0_d, 0);
-    sig_ptr -= sig_stride * 16;
-    mc_running_avg_y_ptr -= mc_avg_y_stride * 16;
-    running_avg_y_ptr -= avg_y_stride * 16;
-
-    if (increase_denoising)
-    {
-        sum_diff_thresh = SUM_DIFF_THRESHOLD_HIGH;
-    }
-
-    if (abs(sum_diff) > sum_diff_thresh)
-    {
-        delta = ((abs(sum_diff) - sum_diff_thresh) >> 8) + 1;
-        delta_vec = __msa_fill_h(delta);
-        if (delta < 4)
-        {
-            for (cnt = 8; cnt--;)
-            {
-                running_avg_y = LD_UB(running_avg_y_ptr);
-                mc_running_avg_y0 = LD_UB(mc_running_avg_y_ptr);
-                sig0 = LD_UB(sig_ptr);
-                sig_ptr += sig_stride;
-                mc_running_avg_y_ptr += mc_avg_y_stride;
-                running_avg_y_ptr += avg_y_stride;
-                mc_running_avg_y1 = LD_UB(mc_running_avg_y_ptr);
-                sig1 = LD_UB(sig_ptr);
-                running_avg_y1 = LD_UB(running_avg_y_ptr);
-                ILVRL_B2_UB(mc_running_avg_y0, sig0, coeff0, coeff1);
-                HSUB_UB2_SH(coeff0, coeff1, diff0, diff1);
-                abs_diff0 = __msa_add_a_h(diff0, zero);
-                abs_diff1 = __msa_add_a_h(diff1, zero);
-                temp0_h = abs_diff0 < delta_vec;
-                temp1_h = abs_diff1 < delta_vec;
-                abs_diff0 = (v8i16)__msa_bmz_v((v16u8)abs_diff0,
-                                               (v16u8)delta_vec,
-                                               (v16u8)temp0_h);
-                abs_diff1 = (v8i16)__msa_bmz_v((v16u8)abs_diff1,
-                                               (v16u8)delta_vec,
-                                               (v16u8)temp1_h);
-                SUB2(zero, abs_diff0, zero, abs_diff1, abs_diff_neg0,
-                     abs_diff_neg1);
-                abs_diff_neg0 = zero - abs_diff0;
-                abs_diff_neg1 = zero - abs_diff1;
-                temp0_h = __msa_clei_s_h(diff0, 0);
-                temp1_h = __msa_clei_s_h(diff1, 0);
-                adjust0 = (v8i16)__msa_bmnz_v((v16u8)abs_diff0,
-                                              (v16u8)abs_diff_neg0,
-                                              (v16u8)temp0_h);
-                adjust1 = (v8i16)__msa_bmnz_v((v16u8)abs_diff1,
-                                              (v16u8)abs_diff_neg1,
-                                              (v16u8)temp1_h);
-                ILVRL_B2_SH(zero, running_avg_y, temp2_h, temp3_h);
-                ADD2(temp2_h, adjust0, temp3_h, adjust1, adjust2, adjust3);
-                MAXI_SH2_SH(adjust2, adjust3, 0);
-                SAT_UH2_SH(adjust2, adjust3, 7);
-                temp0_h = __msa_ceqi_h(diff0, 0);
-                temp1_h = __msa_ceqi_h(diff1, 0);
-                adjust2 = (v8i16)__msa_bmz_v((v16u8)adjust2, (v16u8)temp2_h,
-                                             (v16u8)temp0_h);
-                adjust3 = (v8i16)__msa_bmz_v((v16u8)adjust3, (v16u8)temp3_h,
-                                             (v16u8)temp1_h);
-                adjust0 = (v8i16)__msa_bmnz_v((v16u8)adjust0, (v16u8)zero,
-                                              (v16u8)temp0_h);
-                adjust1 = (v8i16)__msa_bmnz_v((v16u8)adjust1, (v16u8)zero,
-                                              (v16u8)temp1_h);
-                ADD2(col_sum2, adjust0, col_sum3, adjust1, col_sum2, col_sum3);
-                running_avg_y = (v16u8)__msa_pckev_b((v16i8)adjust3,
-                                                     (v16i8)adjust2);
-                ST_UB(running_avg_y, running_avg_y_ptr - avg_y_stride);
-                ILVRL_B2_UB(mc_running_avg_y1, sig1, coeff0, coeff1);
-                HSUB_UB2_SH(coeff0, coeff1, diff0, diff1);
-                abs_diff0 = __msa_add_a_h(diff0, zero);
-                abs_diff1 = __msa_add_a_h(diff1, zero);
-                temp0_h = abs_diff0 < delta_vec;
-                temp1_h = abs_diff1 < delta_vec;
-                abs_diff0 = (v8i16)__msa_bmz_v((v16u8)abs_diff0,
-                                               (v16u8)delta_vec,
-                                               (v16u8)temp0_h);
-                abs_diff1 = (v8i16)__msa_bmz_v((v16u8)abs_diff1,
-                                               (v16u8)delta_vec,
-                                               (v16u8)temp1_h);
-                SUB2(zero, abs_diff0, zero, abs_diff1, abs_diff_neg0,
-                     abs_diff_neg1);
-                temp0_h = __msa_clei_s_h(diff0, 0);
-                temp1_h = __msa_clei_s_h(diff1, 0);
-                adjust0 = (v8i16)__msa_bmnz_v((v16u8)abs_diff0,
-                                              (v16u8)abs_diff_neg0,
-                                              (v16u8)temp0_h);
-                adjust1 = (v8i16)__msa_bmnz_v((v16u8)abs_diff1,
-                                              (v16u8)abs_diff_neg1,
-                                              (v16u8)temp1_h);
-                ILVRL_H2_SH(zero, running_avg_y1, temp2_h, temp3_h);
-                ADD2(temp2_h, adjust0, temp3_h, adjust1, adjust2, adjust3);
-                MAXI_SH2_SH(adjust2, adjust3, 0);
-                SAT_UH2_SH(adjust2, adjust3, 7);
-                temp0_h = __msa_ceqi_h(diff0, 0);
-                temp1_h = __msa_ceqi_h(diff1, 0);
-                adjust2 = (v8i16)__msa_bmz_v((v16u8)adjust2, (v16u8)temp2_h,
-                                             (v16u8)temp0_h);
-                adjust3 = (v8i16)__msa_bmz_v((v16u8)adjust3, (v16u8)temp3_h,
-                                             (v16u8)temp1_h);
-                adjust0 = (v8i16)__msa_bmz_v((v16u8)adjust0, (v16u8)zero,
-                                             (v16u8)temp0_h);
-                adjust1 = (v8i16)__msa_bmz_v((v16u8)adjust1, (v16u8)zero,
-                                             (v16u8)temp1_h);
-                ADD2(col_sum2, adjust0, col_sum3, adjust1, col_sum2, col_sum3);
-                running_avg_y = (v16u8)__msa_pckev_b((v16i8)adjust3,
-                                                     (v16i8)adjust2);
-                ST_UB(running_avg_y, running_avg_y_ptr);
-                running_avg_y_ptr += avg_y_stride;
-            }
-
-            col_sum2 = __msa_min_s_h(col_sum2, val_127);
-            col_sum3 = __msa_min_s_h(col_sum3, val_127);
-            temp0_h = col_sum2 + col_sum3;
-            temp0_w = __msa_hadd_s_w(temp0_h, temp0_h);
-            temp0_d = __msa_hadd_s_d(temp0_w, temp0_w);
-            temp1_d = __msa_splati_d(temp0_d, 1);
-            temp0_d += (v2i64)temp1_d;
-            sum_diff = __msa_copy_s_w((v4i32)temp0_d, 0);
-            if (abs(sum_diff) > SUM_DIFF_THRESHOLD)
-            {
-                return COPY_BLOCK;
-            }
-        }
-        else
-        {
-            return COPY_BLOCK;
-        }
-    }
-
-    LD_UB8(sig_start, sig_stride, src0, src1, src2, src3, src4, src5, src6,
-           src7);
-    sig_start += (8 * sig_stride);
-    LD_UB8(sig_start, sig_stride, src8, src9, src10, src11, src12, src13,
-           src14, src15);
-
-    ST_UB8(src0, src1, src2, src3, src4, src5, src6, src7, running_avg_y_start,
-           avg_y_stride);
-    running_avg_y_start += (8 * avg_y_stride);
-    ST_UB8(src8, src9, src10, src11, src12, src13, src14, src15,
-           running_avg_y_start, avg_y_stride);
-
-    return FILTER_BLOCK;
-}
-
-int32_t vp8_denoiser_filter_uv_msa(uint8_t *mc_running_avg_y_ptr,
-                                   int32_t mc_avg_y_stride,
-                                   uint8_t *running_avg_y_ptr,
-                                   int32_t avg_y_stride,
-                                   uint8_t *sig_ptr,
-                                   int32_t sig_stride,
-                                   uint32_t motion_magnitude,
-                                   int32_t increase_denoising)
-{
-    uint8_t *running_avg_y_start = running_avg_y_ptr;
-    uint8_t *sig_start = sig_ptr;
-    int32_t cnt = 0;
-    int32_t sum_diff = 0;
-    int32_t shift_inc1 = 3;
-    int32_t delta = 0;
-    int32_t sum_block = 0;
-    int32_t sum_diff_thresh;
-    int64_t dst0, dst1, src0, src1, src2, src3;
-    v16u8 mc_running_avg_y0, running_avg_y, sig0;
-    v16u8 mc_running_avg_y1, running_avg_y1, sig1;
-    v16u8 sig2, sig3, sig4, sig5, sig6, sig7;
-    v16u8 coeff0;
-    v8i16 diff0, abs_diff0, abs_diff_neg0;
-    v8i16 adjust0, adjust2;
-    v8i16 shift_inc1_vec = { 0 };
-    v8i16 col_sum0 = { 0 };
-    v8i16 temp0_h, temp2_h, cmp, delta_vec;
-    v4i32 temp0_w;
-    v2i64 temp0_d, temp1_d;
-    v16i8 zero = { 0 };
-    v8i16 one = __msa_ldi_h(1);
-    v8i16 four = __msa_ldi_h(4);
-    v8i16 adj_val = { 6, 4, 3, 0, -6, -4, -3, 0 };
-
-
-    sig0 = LD_UB(sig_ptr);
-    sig_ptr += sig_stride;
-    temp0_h = (v8i16)__msa_ilvr_b(zero, (v16i8)sig0);
-    sig1 = LD_UB(sig_ptr);
-    sig_ptr += sig_stride;
-    temp0_h += (v8i16)__msa_ilvr_b(zero, (v16i8)sig1);
-    sig2 = LD_UB(sig_ptr);
-    sig_ptr += sig_stride;
-    temp0_h += (v8i16)__msa_ilvr_b(zero, (v16i8)sig2);
-    sig3 = LD_UB(sig_ptr);
-    sig_ptr += sig_stride;
-    temp0_h += (v8i16)__msa_ilvr_b(zero, (v16i8)sig3);
-    sig4 = LD_UB(sig_ptr);
-    sig_ptr += sig_stride;
-    temp0_h += (v8i16)__msa_ilvr_b(zero, (v16i8)sig4);
-    sig5 = LD_UB(sig_ptr);
-    sig_ptr += sig_stride;
-    temp0_h += (v8i16)__msa_ilvr_b(zero, (v16i8)sig5);
-    sig6 = LD_UB(sig_ptr);
-    sig_ptr += sig_stride;
-    temp0_h += (v8i16)__msa_ilvr_b(zero, (v16i8)sig6);
-    sig7 = LD_UB(sig_ptr);
-    sig_ptr += sig_stride;
-    temp0_h += (v8i16)__msa_ilvr_b(zero, (v16i8)sig7);
-    temp0_w = __msa_hadd_s_w(temp0_h, temp0_h);
-    temp0_d = __msa_hadd_s_d(temp0_w, temp0_w);
-    temp1_d = __msa_splati_d(temp0_d, 1);
-    temp0_d += temp1_d;
-    sum_block = __msa_copy_s_w((v4i32)temp0_d, 0);
-    sig_ptr -= sig_stride * 8;
-
-    if (abs(sum_block - (128 * 8 * 8)) < SUM_DIFF_FROM_AVG_THRESH_UV)
-    {
-        return COPY_BLOCK;
-    }
-
-    if (motion_magnitude <= MOTION_MAGNITUDE_THRESHOLD)
-    {
-        adj_val = __msa_add_a_h(adj_val, one);
-
-        if (increase_denoising)
-        {
-            adj_val = __msa_add_a_h(adj_val, one);
-            shift_inc1 = 4;
-        }
-
-        temp0_h = (v8i16)zero - adj_val;
-        adj_val = (v8i16)__msa_ilvev_d((v2i64)temp0_h, (v2i64)adj_val);
-    }
-
-    adj_val = __msa_insert_h(adj_val, 3, cnt);
-    adj_val = __msa_insert_h(adj_val, 7, cnt);
-    shift_inc1_vec = __msa_fill_h(shift_inc1);
-    for (cnt = 4; cnt--;)
-    {
-        v8i16 mask0 = { 0 };
-        mc_running_avg_y0 = LD_UB(mc_running_avg_y_ptr);
-        sig0 = LD_UB(sig_ptr);
-        sig_ptr += sig_stride;
-        mc_running_avg_y_ptr += mc_avg_y_stride;
-        mc_running_avg_y1 = LD_UB(mc_running_avg_y_ptr);
-        sig1 = LD_UB(sig_ptr);
-        coeff0 = (v16u8)__msa_ilvr_b((v16i8)mc_running_avg_y0, (v16i8)sig0);
-        diff0 = __msa_hsub_u_h(coeff0, coeff0);
-        abs_diff0 = __msa_add_a_h(diff0, (v8i16)zero);
-        cmp = __msa_clei_s_h(abs_diff0, 15);
-        cmp = cmp & one;
-        mask0 += cmp;
-        cmp = __msa_clei_s_h(abs_diff0, 7);
-        cmp = cmp & one;
-        mask0 += cmp;
-        cmp = abs_diff0 < shift_inc1_vec;
-        cmp = cmp & one;
-        mask0 += cmp;
-        temp0_h = __msa_clei_s_h(diff0, 0);
-        temp0_h = temp0_h & four;
-        mask0 += temp0_h;
-        adjust0 = __msa_vshf_h(mask0, adj_val, adj_val);
-        temp2_h = __msa_ceqi_h(adjust0, 0);
-        adjust0 = (v8i16)__msa_bmnz_v((v16u8)adjust0, (v16u8)diff0,
-                                      (v16u8)temp2_h);
-        col_sum0 += adjust0;
-        temp0_h = (v8i16)__msa_ilvr_b(zero, (v16i8)sig0);
-        temp0_h += adjust0;
-        temp0_h = __msa_maxi_s_h(temp0_h, 0);
-        temp0_h = (v8i16)__msa_sat_u_h((v8u16)temp0_h, 7);
-        temp2_h = (v8i16)__msa_pckev_b((v16i8)temp2_h, (v16i8)temp2_h);
-        running_avg_y = (v16u8)__msa_pckev_b((v16i8)temp0_h, (v16i8)temp0_h);
-        running_avg_y = __msa_bmnz_v(running_avg_y, mc_running_avg_y0,
-                                     (v16u8)temp2_h);
-        dst0 = __msa_copy_s_d((v2i64)running_avg_y,  0);
-        SD(dst0, running_avg_y_ptr);
-        running_avg_y_ptr += avg_y_stride;
-
-        mask0 = __msa_ldi_h(0);
-        coeff0 = (v16u8)__msa_ilvr_b((v16i8)mc_running_avg_y1, (v16i8)sig1);
-        diff0 = __msa_hsub_u_h(coeff0, coeff0);
-        abs_diff0 = __msa_add_a_h(diff0, (v8i16)zero);
-        cmp = __msa_clei_s_h(abs_diff0, 15);
-        cmp = cmp & one;
-        mask0 += cmp;
-        cmp = __msa_clei_s_h(abs_diff0, 7);
-        cmp = cmp & one;
-        mask0 += cmp;
-        cmp = abs_diff0 < shift_inc1_vec;
-        cmp = cmp & one;
-        mask0 += cmp;
-        temp0_h = __msa_clei_s_h(diff0, 0);
-        temp0_h = temp0_h & four;
-        mask0 += temp0_h;
-        adjust0 = __msa_vshf_h(mask0, adj_val, adj_val);
-        temp2_h = __msa_ceqi_h(adjust0, 0);
-        adjust0 = (v8i16)__msa_bmnz_v((v16u8)adjust0, (v16u8)diff0,
-                                      (v16u8)temp2_h);
-        col_sum0 += adjust0;
-        temp0_h = (v8i16)__msa_ilvr_b(zero, (v16i8)sig1);
-        temp0_h += adjust0;
-        temp0_h = __msa_maxi_s_h(temp0_h, 0);
-        temp0_h = (v8i16)__msa_sat_u_h((v8u16)temp0_h, 7);
-
-        temp2_h = (v8i16)__msa_pckev_b((v16i8)temp2_h, (v16i8)temp2_h);
-        running_avg_y = (v16u8)__msa_pckev_b((v16i8)temp0_h, (v16i8)temp0_h);
-        running_avg_y = __msa_bmnz_v(running_avg_y, mc_running_avg_y1,
-                                     (v16u8)temp2_h);
-        dst1 = __msa_copy_s_d((v2i64)running_avg_y, 0);
-        SD(dst1, running_avg_y_ptr);
-
-        sig_ptr += sig_stride;
-        mc_running_avg_y_ptr += mc_avg_y_stride;
-        running_avg_y_ptr += avg_y_stride;
-    }
-
-    temp0_h = col_sum0;
-    temp0_w = __msa_hadd_s_w(temp0_h, temp0_h);
-    temp0_d = __msa_hadd_s_d(temp0_w, temp0_w);
-    temp1_d = __msa_splati_d(temp0_d, 1);
-    temp0_d += temp1_d;
-    sum_diff = __msa_copy_s_w((v4i32)temp0_d, 0);
-    sig_ptr -= sig_stride * 8;
-    mc_running_avg_y_ptr -= mc_avg_y_stride * 8;
-    running_avg_y_ptr -= avg_y_stride * 8;
-    sum_diff_thresh = SUM_DIFF_THRESHOLD_UV;
-
-    if (increase_denoising)
-    {
-        sum_diff_thresh = SUM_DIFF_THRESHOLD_HIGH_UV;
-    }
-
-    if (abs(sum_diff) > sum_diff_thresh)
-    {
-        delta = ((abs(sum_diff) - sum_diff_thresh) >> 8) + 1;
-        delta_vec = __msa_fill_h(delta);
-        if (delta < 4)
-        {
-            for (cnt = 4; cnt--;)
-            {
-                running_avg_y = LD_UB(running_avg_y_ptr);
-                mc_running_avg_y0 = LD_UB(mc_running_avg_y_ptr);
-                sig0 = LD_UB(sig_ptr);
-                /* Update pointers for next iteration. */
-                sig_ptr += sig_stride;
-                mc_running_avg_y_ptr += mc_avg_y_stride;
-                running_avg_y_ptr += avg_y_stride;
-
-                mc_running_avg_y1 = LD_UB(mc_running_avg_y_ptr);
-                sig1 = LD_UB(sig_ptr);
-                running_avg_y1 = LD_UB(running_avg_y_ptr);
-
-                coeff0 = (v16u8)__msa_ilvr_b((v16i8)mc_running_avg_y0,
-                                             (v16i8)sig0);
-                diff0 = __msa_hsub_u_h(coeff0, coeff0);
-                abs_diff0 = __msa_add_a_h(diff0, (v8i16)zero);
-                temp0_h = delta_vec < abs_diff0;
-                abs_diff0 = (v8i16)__msa_bmnz_v((v16u8)abs_diff0,
-                                                (v16u8)delta_vec,
-                                                (v16u8)temp0_h);
-                abs_diff_neg0 = (v8i16)zero - abs_diff0;
-                temp0_h = __msa_clei_s_h(diff0, 0);
-                adjust0 = (v8i16)__msa_bmz_v((v16u8)abs_diff0,
-                                             (v16u8)abs_diff_neg0,
-                                             (v16u8)temp0_h);
-                temp2_h = (v8i16)__msa_ilvr_b(zero, (v16i8)running_avg_y);
-                adjust2 = temp2_h + adjust0;
-                adjust2 = __msa_maxi_s_h(adjust2, 0);
-                adjust2 = (v8i16)__msa_sat_u_h((v8u16)adjust2, 7);
-                temp0_h = __msa_ceqi_h(diff0, 0);
-                adjust2 = (v8i16)__msa_bmnz_v((v16u8)adjust2, (v16u8)temp2_h,
-                                              (v16u8)temp0_h);
-                adjust0 = (v8i16)__msa_bmnz_v((v16u8)adjust0, (v16u8)zero,
-                                              (v16u8)temp0_h);
-                col_sum0 += adjust0;
-                running_avg_y = (v16u8)__msa_pckev_b((v16i8)adjust2,
-                                                     (v16i8)adjust2);
-                dst0 = __msa_copy_s_d((v2i64)running_avg_y, 0);
-                SD(dst0, running_avg_y_ptr - avg_y_stride);
-
-                coeff0 = (v16u8)__msa_ilvr_b((v16i8)mc_running_avg_y1,
-                                             (v16i8)sig1);
-                diff0 = __msa_hsub_u_h(coeff0, coeff0);
-                abs_diff0 = __msa_add_a_h(diff0, (v8i16)zero);
-                temp0_h = delta_vec < abs_diff0;
-                abs_diff0 = (v8i16)__msa_bmnz_v((v16u8)abs_diff0,
-                                                (v16u8)delta_vec,
-                                                (v16u8)temp0_h);
-                abs_diff_neg0 = (v8i16)zero - abs_diff0;
-                temp0_h = __msa_clei_s_h(diff0, 0);
-                adjust0 = (v8i16)__msa_bmz_v((v16u8)abs_diff0,
-                                             (v16u8)abs_diff_neg0,
-                                             (v16u8)temp0_h);
-                temp2_h = (v8i16)__msa_ilvr_b(zero, (v16i8)running_avg_y1);
-                adjust2 = temp2_h + adjust0;
-                adjust2 = __msa_maxi_s_h(adjust2, 0);
-                adjust2 = (v8i16)__msa_sat_u_h((v8u16)adjust2, 7);
-                temp0_h = __msa_ceqi_h(diff0, 0);
-                adjust2 = (v8i16)__msa_bmnz_v((v16u8)adjust2, (v16u8)temp2_h,
-                                              (v16u8)temp0_h);
-                adjust0 = (v8i16)__msa_bmnz_v((v16u8)adjust0, (v16u8)zero,
-                                              (v16u8)temp0_h);
-                col_sum0 += adjust0;
-                running_avg_y = (v16u8)__msa_pckev_b((v16i8)adjust2,
-                                                     (v16i8)adjust2);
-                dst1 = __msa_copy_s_d((v2i64)running_avg_y, 0);
-                SD(dst1, running_avg_y_ptr);
-                running_avg_y_ptr += avg_y_stride;
-            }
-
-            temp0_h = col_sum0;
-            temp0_w = __msa_hadd_s_w(temp0_h, temp0_h);
-            temp0_d = __msa_hadd_s_d(temp0_w, temp0_w);
-            temp1_d = __msa_splati_d(temp0_d, 1);
-            temp0_d += temp1_d;
-            sum_diff = __msa_copy_s_w((v4i32)temp0_d, 0);
-
-            if (abs(sum_diff) > sum_diff_thresh)
-            {
-                return COPY_BLOCK;
-            }
-        }
-        else
-        {
-            return COPY_BLOCK;
-        }
-    }
-
-    LD4(sig_start, sig_stride, src0, src1, src2, src3);
-    sig_start += (4 * sig_stride);
-    SD4(src0, src1, src2, src3, running_avg_y_start, avg_y_stride);
-    running_avg_y_start += (4 * avg_y_stride);
-
-    LD4(sig_start, sig_stride, src0, src1, src2, src3);
-    SD4(src0, src1, src2, src3, running_avg_y_start, avg_y_stride);
-
-    return FILTER_BLOCK;
-}
diff --git a/vp8/encoder/mips/msa/encodeopt_msa.c b/vp8/encoder/mips/msa/encodeopt_msa.c
deleted file mode 100644 (file)
index ea794a8..0000000
+++ /dev/null
@@ -1,174 +0,0 @@
-/*
- *  Copyright (c) 2015 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.
- */
-
-#include "./vp8_rtcd.h"
-#include "vp8/common/mips/msa/vp8_macros_msa.h"
-#include "vp8/encoder/block.h"
-
-int32_t vp8_block_error_msa(int16_t *coeff_ptr, int16_t *dq_coeff_ptr)
-{
-    int32_t err = 0;
-    uint32_t loop_cnt;
-    v8i16 coeff, dq_coeff, coeff0, coeff1;
-    v4i32 diff0, diff1;
-    v2i64 err0 = { 0 };
-    v2i64 err1 = { 0 };
-
-    for (loop_cnt = 2; loop_cnt--;)
-    {
-        coeff = LD_SH(coeff_ptr);
-        dq_coeff = LD_SH(dq_coeff_ptr);
-        ILVRL_H2_SH(coeff, dq_coeff, coeff0, coeff1);
-        HSUB_UH2_SW(coeff0, coeff1, diff0, diff1);
-        DPADD_SD2_SD(diff0, diff1, err0, err1);
-        coeff_ptr += 8;
-        dq_coeff_ptr += 8;
-    }
-
-    err0 += __msa_splati_d(err0, 1);
-    err1 += __msa_splati_d(err1, 1);
-    err = __msa_copy_s_d(err0, 0);
-    err += __msa_copy_s_d(err1, 0);
-
-    return err;
-}
-
-int32_t vp8_mbblock_error_msa(MACROBLOCK *mb, int32_t dc)
-{
-    BLOCK *be;
-    BLOCKD *bd;
-    int16_t *coeff_ptr, *dq_coeff_ptr;
-    int32_t err = 0;
-    uint32_t loop_cnt;
-    v8i16 coeff, coeff0, coeff1, coeff2, coeff3, coeff4;
-    v8i16 dq_coeff, dq_coeff2, dq_coeff3, dq_coeff4;
-    v4i32 diff0, diff1;
-    v2i64 err0, err1;
-    v16u8 zero  = { 0 };
-    v16u8 mask0 = (v16u8)__msa_ldi_b(255);
-
-    if (1 == dc)
-    {
-        mask0 = (v16u8)__msa_insve_w((v4i32)mask0, 0, (v4i32)zero);
-    }
-
-    for (loop_cnt = 0; loop_cnt < 8; loop_cnt++)
-    {
-        be = &mb->block[2 * loop_cnt];
-        bd = &mb->e_mbd.block[2 * loop_cnt];
-        coeff_ptr = be->coeff;
-        dq_coeff_ptr = bd->dqcoeff;
-        coeff = LD_SH(coeff_ptr);
-        dq_coeff = LD_SH(dq_coeff_ptr);
-        coeff_ptr += 8;
-        dq_coeff_ptr += 8;
-        coeff2 = LD_SH(coeff_ptr);
-        dq_coeff2 = LD_SH(dq_coeff_ptr);
-        be = &mb->block[2 * loop_cnt + 1];
-        bd = &mb->e_mbd.block[2 * loop_cnt + 1];
-        coeff_ptr = be->coeff;
-        dq_coeff_ptr = bd->dqcoeff;
-        coeff3 = LD_SH(coeff_ptr);
-        dq_coeff3 = LD_SH(dq_coeff_ptr);
-        coeff_ptr += 8;
-        dq_coeff_ptr += 8;
-        coeff4 = LD_SH(coeff_ptr);
-        dq_coeff4 = LD_SH(dq_coeff_ptr);
-        ILVRL_H2_SH(coeff, dq_coeff, coeff0, coeff1);
-        HSUB_UH2_SW(coeff0, coeff1, diff0, diff1);
-        diff0 = (v4i32)__msa_bmnz_v(zero, (v16u8)diff0, mask0);
-        DOTP_SW2_SD(diff0, diff1, diff0, diff1, err0, err1);
-        ILVRL_H2_SH(coeff2, dq_coeff2, coeff0, coeff1);
-        HSUB_UH2_SW(coeff0, coeff1, diff0, diff1);
-        DPADD_SD2_SD(diff0, diff1, err0, err1);
-        err0 += __msa_splati_d(err0, 1);
-        err1 += __msa_splati_d(err1, 1);
-        err += __msa_copy_s_d(err0, 0);
-        err += __msa_copy_s_d(err1, 0);
-
-        ILVRL_H2_SH(coeff3, dq_coeff3, coeff0, coeff1);
-        HSUB_UH2_SW(coeff0, coeff1, diff0, diff1);
-        diff0 = (v4i32)__msa_bmnz_v(zero, (v16u8)diff0, mask0);
-        DOTP_SW2_SD(diff0, diff1, diff0, diff1, err0, err1);
-        ILVRL_H2_SH(coeff4, dq_coeff4, coeff0, coeff1);
-        HSUB_UH2_SW(coeff0, coeff1, diff0, diff1);
-        DPADD_SD2_SD(diff0, diff1, err0, err1);
-        err0 += __msa_splati_d(err0, 1);
-        err1 += __msa_splati_d(err1, 1);
-        err += __msa_copy_s_d(err0, 0);
-        err += __msa_copy_s_d(err1, 0);
-    }
-
-    return err;
-}
-
-int32_t vp8_mbuverror_msa(MACROBLOCK *mb)
-{
-    BLOCK *be;
-    BLOCKD *bd;
-    int16_t *coeff_ptr, *dq_coeff_ptr;
-    int32_t err = 0;
-    uint32_t loop_cnt;
-    v8i16 coeff, coeff0, coeff1, coeff2, coeff3, coeff4;
-    v8i16 dq_coeff, dq_coeff2, dq_coeff3, dq_coeff4;
-    v4i32 diff0, diff1;
-    v2i64 err0, err1, err_dup0, err_dup1;
-
-    for (loop_cnt = 16; loop_cnt < 24; loop_cnt += 2)
-    {
-        be = &mb->block[loop_cnt];
-        bd = &mb->e_mbd.block[loop_cnt];
-        coeff_ptr = be->coeff;
-        dq_coeff_ptr = bd->dqcoeff;
-        coeff = LD_SH(coeff_ptr);
-        dq_coeff = LD_SH(dq_coeff_ptr);
-        coeff_ptr += 8;
-        dq_coeff_ptr += 8;
-        coeff2 = LD_SH(coeff_ptr);
-        dq_coeff2 = LD_SH(dq_coeff_ptr);
-        be = &mb->block[loop_cnt + 1];
-        bd = &mb->e_mbd.block[loop_cnt + 1];
-        coeff_ptr = be->coeff;
-        dq_coeff_ptr = bd->dqcoeff;
-        coeff3 = LD_SH(coeff_ptr);
-        dq_coeff3 = LD_SH(dq_coeff_ptr);
-        coeff_ptr += 8;
-        dq_coeff_ptr += 8;
-        coeff4 = LD_SH(coeff_ptr);
-        dq_coeff4 = LD_SH(dq_coeff_ptr);
-
-        ILVRL_H2_SH(coeff, dq_coeff, coeff0, coeff1);
-        HSUB_UH2_SW(coeff0, coeff1, diff0, diff1);
-        DOTP_SW2_SD(diff0, diff1, diff0, diff1, err0, err1);
-
-        ILVRL_H2_SH(coeff2, dq_coeff2, coeff0, coeff1);
-        HSUB_UH2_SW(coeff0, coeff1, diff0, diff1);
-        DPADD_SD2_SD(diff0, diff1, err0, err1);
-        err_dup0 = __msa_splati_d(err0, 1);
-        err_dup1 = __msa_splati_d(err1, 1);
-        ADD2(err0, err_dup0, err1, err_dup1, err0, err1);
-        err += __msa_copy_s_d(err0, 0);
-        err += __msa_copy_s_d(err1, 0);
-
-        ILVRL_H2_SH(coeff3, dq_coeff3, coeff0, coeff1);
-        HSUB_UH2_SW(coeff0, coeff1, diff0, diff1);
-        DOTP_SW2_SD(diff0, diff1, diff0, diff1, err0, err1);
-        ILVRL_H2_SH(coeff4, dq_coeff4, coeff0, coeff1);
-        HSUB_UH2_SW(coeff0, coeff1, diff0, diff1);
-        DPADD_SD2_SD(diff0, diff1, err0, err1);
-        err_dup0 = __msa_splati_d(err0, 1);
-        err_dup1 = __msa_splati_d(err1, 1);
-        ADD2(err0, err_dup0, err1, err_dup1, err0, err1);
-        err += __msa_copy_s_d(err0, 0);
-        err += __msa_copy_s_d(err1, 0);
-    }
-
-    return err;
-}
diff --git a/vp8/encoder/mips/msa/quantize_msa.c b/vp8/encoder/mips/msa/quantize_msa.c
deleted file mode 100644 (file)
index 0f97646..0000000
+++ /dev/null
@@ -1,246 +0,0 @@
-/*
- *  Copyright (c) 2015 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.
- */
-
-#include "./vp8_rtcd.h"
-#include "vp8/common/mips/msa/vp8_macros_msa.h"
-#include "vp8/encoder/block.h"
-
-static int8_t fast_quantize_b_msa(int16_t *coeff_ptr, int16_t *zbin,
-                                  int16_t *round, int16_t *quant,
-                                  int16_t *de_quant, int16_t *q_coeff,
-                                  int16_t *dq_coeff)
-{
-    int32_t cnt, eob;
-    v16i8 inv_zig_zag = { 0, 1, 5, 6, 2, 4, 7, 12,
-                          3, 8, 11, 13, 9, 10, 14, 15 };
-    v8i16 round0, round1;
-    v8i16 sign_z0, sign_z1;
-    v8i16 q_coeff0, q_coeff1;
-    v8i16 x0, x1, de_quant0, de_quant1;
-    v8i16 coeff0, coeff1, z0, z1;
-    v8i16 quant0, quant1, quant2, quant3;
-    v8i16 zero = { 0 };
-    v8i16 inv_zig_zag0, inv_zig_zag1;
-    v8i16 zigzag_mask0 = { 0, 1, 4, 8, 5, 2, 3, 6 };
-    v8i16 zigzag_mask1 = { 9, 12, 13, 10, 7, 11, 14, 15 };
-    v8i16 temp0_h, temp1_h, temp2_h, temp3_h;
-    v4i32 temp0_w, temp1_w, temp2_w, temp3_w;
-
-    ILVRL_B2_SH(zero, inv_zig_zag, inv_zig_zag0, inv_zig_zag1);
-    eob = -1;
-    LD_SH2(coeff_ptr, 8, coeff0, coeff1);
-    VSHF_H2_SH(coeff0, coeff1, coeff0, coeff1, zigzag_mask0, zigzag_mask1,
-               z0, z1);
-    LD_SH2(round, 8, coeff0, coeff1);
-    VSHF_H2_SH(coeff0, coeff1, coeff0, coeff1, zigzag_mask0, zigzag_mask1,
-               round0, round1);
-    LD_SH2(quant, 8, coeff0, coeff1);
-    VSHF_H2_SH(coeff0, coeff1, coeff0, coeff1, zigzag_mask0, zigzag_mask1,
-               quant0, quant2);
-    sign_z0 = z0 >> 15;
-    sign_z1 = z1 >> 15;
-    x0 = __msa_add_a_h(z0, zero);
-    x1 = __msa_add_a_h(z1, zero);
-    ILVL_H2_SH(quant0, quant0, quant2, quant2, quant1, quant3);
-    ILVR_H2_SH(quant0, quant0, quant2, quant2, quant0, quant2);
-    ILVL_H2_SH(round0, x0, round1, x1, temp1_h, temp3_h);
-    ILVR_H2_SH(round0, x0, round1, x1, temp0_h, temp2_h);
-    DOTP_SH4_SW(temp0_h, temp1_h, temp2_h, temp3_h, quant0, quant1, quant2,
-                quant3, temp0_w, temp1_w, temp2_w, temp3_w);
-    SRA_4V(temp0_w, temp1_w, temp2_w, temp3_w, 16);
-    PCKEV_H2_SH(temp1_w, temp0_w, temp3_w, temp2_w, x0, x1);
-    x0 = x0 ^ sign_z0;
-    x1 = x1 ^ sign_z1;
-    SUB2(x0, sign_z0, x1, sign_z1, x0, x1);
-    VSHF_H2_SH(x0, x1, x0, x1, inv_zig_zag0, inv_zig_zag1, q_coeff0, q_coeff1);
-    ST_SH2(q_coeff0, q_coeff1, q_coeff, 8);
-    LD_SH2(de_quant, 8, de_quant0, de_quant1);
-    q_coeff0 *= de_quant0;
-    q_coeff1 *= de_quant1;
-    ST_SH2(q_coeff0, q_coeff1, dq_coeff, 8);
-
-    for (cnt = 0; cnt < 16; ++cnt)
-    {
-        if ((cnt <= 7) && (x1[7 - cnt] != 0))
-        {
-            eob = (15 - cnt);
-            break;
-        }
-
-        if ((cnt > 7) && (x0[7 - (cnt - 8)] != 0))
-        {
-            eob = (7 - (cnt - 8));
-            break;
-        }
-    }
-
-    return (int8_t)(eob + 1);
-}
-
-static int8_t exact_regular_quantize_b_msa(int16_t *zbin_boost,
-                                           int16_t *coeff_ptr,
-                                           int16_t *zbin,
-                                           int16_t *round,
-                                           int16_t *quant,
-                                           int16_t *quant_shift,
-                                           int16_t *de_quant,
-                                           int16_t zbin_oq_in,
-                                           int16_t *q_coeff,
-                                           int16_t *dq_coeff)
-{
-    int32_t cnt, eob;
-    int16_t *boost_temp = zbin_boost;
-    v16i8 inv_zig_zag = { 0, 1, 5, 6, 2, 4, 7, 12,
-                          3, 8, 11, 13, 9, 10, 14, 15 };
-    v8i16 round0, round1;
-    v8i16 sign_z0, sign_z1;
-    v8i16 q_coeff0, q_coeff1;
-    v8i16 z_bin0, z_bin1, zbin_o_q;
-    v8i16 x0, x1, sign_x0, sign_x1, de_quant0, de_quant1;
-    v8i16 coeff0, coeff1, z0, z1;
-    v8i16 quant0, quant1, quant2, quant3;
-    v8i16 zero = { 0 };
-    v8i16 inv_zig_zag0, inv_zig_zag1;
-    v8i16 zigzag_mask0 = { 0, 1, 4, 8, 5, 2, 3, 6 };
-    v8i16 zigzag_mask1 = { 9, 12, 13, 10, 7, 11, 14, 15 };
-    v8i16 temp0_h, temp1_h, temp2_h, temp3_h;
-    v4i32 temp0_w, temp1_w, temp2_w, temp3_w;
-
-    ILVRL_B2_SH(zero, inv_zig_zag, inv_zig_zag0, inv_zig_zag1);
-    zbin_o_q = __msa_fill_h(zbin_oq_in);
-    eob = -1;
-    LD_SH2(coeff_ptr, 8, coeff0, coeff1);
-    VSHF_H2_SH(coeff0, coeff1, coeff0, coeff1, zigzag_mask0, zigzag_mask1,
-               z0, z1);
-    LD_SH2(round, 8, coeff0, coeff1);
-    VSHF_H2_SH(coeff0, coeff1, coeff0, coeff1, zigzag_mask0, zigzag_mask1,
-               round0, round1);
-    LD_SH2(quant, 8, coeff0, coeff1);
-    VSHF_H2_SH(coeff0, coeff1, coeff0, coeff1, zigzag_mask0, zigzag_mask1,
-               quant0, quant2);
-    LD_SH2(zbin, 8, coeff0, coeff1);
-    VSHF_H2_SH(coeff0, coeff1, coeff0, coeff1, zigzag_mask0, zigzag_mask1,
-               z_bin0, z_bin1);
-    sign_z0 = z0 >> 15;
-    sign_z1 = z1 >> 15;
-    x0 = __msa_add_a_h(z0, zero);
-    x1 = __msa_add_a_h(z1, zero);
-    SUB2(x0, z_bin0, x1, z_bin1, z_bin0, z_bin1);
-    SUB2(z_bin0, zbin_o_q, z_bin1, zbin_o_q, z_bin0, z_bin1);
-    ILVL_H2_SH(quant0, quant0, quant2, quant2, quant1, quant3);
-    ILVR_H2_SH(quant0, quant0, quant2, quant2, quant0, quant2);
-    ILVL_H2_SH(round0, x0, round1, x1, temp1_h, temp3_h);
-    ILVR_H2_SH(round0, x0, round1, x1, temp0_h, temp2_h);
-    DOTP_SH4_SW(temp0_h, temp1_h, temp2_h, temp3_h, quant0, quant1, quant2,
-                quant3, temp0_w, temp1_w, temp2_w, temp3_w);
-    SRA_4V(temp0_w, temp1_w, temp2_w, temp3_w, 16);
-    PCKEV_H2_SH(temp1_w, temp0_w, temp3_w, temp2_w, temp0_h, temp2_h);
-    LD_SH2(quant_shift, 8, coeff0, coeff1);
-    VSHF_H2_SH(coeff0, coeff1, coeff0, coeff1, zigzag_mask0, zigzag_mask1,
-               quant0, quant2);
-    ILVL_H2_SH(quant0, quant0, quant2, quant2, quant1, quant3);
-    ILVR_H2_SH(quant0, quant0, quant2, quant2, quant0, quant2);
-    ADD2(x0, round0, x1, round1, x0, x1);
-    ILVL_H2_SH(temp0_h, x0, temp2_h, x1, temp1_h, temp3_h);
-    ILVR_H2_SH(temp0_h, x0, temp2_h, x1, temp0_h, temp2_h);
-    DOTP_SH4_SW(temp0_h, temp1_h, temp2_h, temp3_h, quant0, quant1, quant2,
-                quant3, temp0_w, temp1_w, temp2_w, temp3_w);
-    SRA_4V(temp0_w, temp1_w, temp2_w, temp3_w, 16);
-    PCKEV_H2_SH(temp1_w, temp0_w, temp3_w, temp2_w, x0, x1);
-    sign_x0 = x0 ^ sign_z0;
-    sign_x1 = x1 ^ sign_z1;
-    SUB2(sign_x0, sign_z0, sign_x1, sign_z1, sign_x0, sign_x1);
-    for (cnt = 0; cnt < 16; ++cnt)
-    {
-        if (cnt <= 7)
-        {
-            if (boost_temp[0] <= z_bin0[cnt])
-            {
-                if (x0[cnt])
-                {
-                    eob = cnt;
-                    boost_temp = zbin_boost;
-                }
-                else
-                {
-                    boost_temp++;
-                }
-            }
-            else
-            {
-                sign_x0[cnt] = 0;
-                boost_temp++;
-            }
-        }
-        else
-        {
-            if (boost_temp[0] <= z_bin1[cnt - 8])
-            {
-                if (x1[cnt - 8])
-                {
-                    eob = cnt;
-                    boost_temp = zbin_boost;
-                }
-                else
-                {
-                    boost_temp++;
-                }
-            }
-            else
-            {
-                sign_x1[cnt - 8] = 0;
-                boost_temp++;
-            }
-        }
-    }
-
-    VSHF_H2_SH(sign_x0, sign_x1, sign_x0, sign_x1, inv_zig_zag0, inv_zig_zag1,
-               q_coeff0, q_coeff1);
-    ST_SH2(q_coeff0, q_coeff1, q_coeff, 8);
-    LD_SH2(de_quant, 8, de_quant0, de_quant1);
-    MUL2(de_quant0, q_coeff0, de_quant1, q_coeff1, de_quant0, de_quant1);
-    ST_SH2(de_quant0, de_quant1, dq_coeff, 8);
-
-    return (int8_t)(eob + 1);
-}
-
-void vp8_fast_quantize_b_msa(BLOCK *b, BLOCKD *d)
-{
-    int16_t *coeff_ptr = b->coeff;
-    int16_t *zbin_ptr = b->zbin;
-    int16_t *round_ptr = b->round;
-    int16_t *quant_ptr = b->quant_fast;
-    int16_t *qcoeff_ptr = d->qcoeff;
-    int16_t *dqcoeff_ptr = d->dqcoeff;
-    int16_t *dequant_ptr = d->dequant;
-
-    *d->eob = fast_quantize_b_msa(coeff_ptr, zbin_ptr, round_ptr, quant_ptr,
-                                  dequant_ptr, qcoeff_ptr, dqcoeff_ptr);
-}
-
-void vp8_regular_quantize_b_msa(BLOCK *b, BLOCKD *d)
-{
-    int16_t *zbin_boost_ptr = b->zrun_zbin_boost;
-    int16_t *coeff_ptr = b->coeff;
-    int16_t *zbin_ptr = b->zbin;
-    int16_t *round_ptr = b->round;
-    int16_t *quant_ptr = b->quant;
-    int16_t *quant_shift_ptr = b->quant_shift;
-    int16_t *qcoeff_ptr = d->qcoeff;
-    int16_t *dqcoeff_ptr = d->dqcoeff;
-    int16_t *dequant_ptr = d->dequant;
-    int16_t zbin_oq_value = b->zbin_extra;
-
-    *d->eob = exact_regular_quantize_b_msa(zbin_boost_ptr, coeff_ptr,
-                                           zbin_ptr, round_ptr,
-                                           quant_ptr, quant_shift_ptr,
-                                           dequant_ptr, zbin_oq_value,
-                                           qcoeff_ptr, dqcoeff_ptr);
-}
diff --git a/vp8/encoder/mips/msa/temporal_filter_msa.c b/vp8/encoder/mips/msa/temporal_filter_msa.c
deleted file mode 100644 (file)
index 5cca5e0..0000000
+++ /dev/null
@@ -1,303 +0,0 @@
-/*
- *  Copyright (c) 2015 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.
- */
-
-#include "./vp8_rtcd.h"
-#include "vp8/common/mips/msa/vp8_macros_msa.h"
-
-static void temporal_filter_apply_16size_msa(uint8_t *frame1_ptr,
-                                             uint32_t stride,
-                                             uint8_t *frame2_ptr,
-                                             int32_t strength_in,
-                                             int32_t filter_wt_in,
-                                             uint32_t *acc, uint16_t *cnt)
-{
-    uint32_t row;
-    v16i8 frame1_0_b, frame1_1_b, frame2_0_b, frame2_1_b;
-    v16u8 frame_l, frame_h;
-    v16i8 zero = { 0 };
-    v8i16 frame2_0_h, frame2_1_h, mod0_h, mod1_h;
-    v8i16 diff0, diff1, cnt0, cnt1;
-    v4i32 const3, const16, filter_wt, strength;
-    v4i32 mod0_w, mod1_w, mod2_w, mod3_w;
-    v4i32 diff0_r, diff0_l, diff1_r, diff1_l;
-    v4i32 frame2_0, frame2_1, frame2_2, frame2_3;
-    v4i32 acc0, acc1, acc2, acc3;
-
-    filter_wt = __msa_fill_w(filter_wt_in);
-    strength = __msa_fill_w(strength_in);
-    const3 = __msa_ldi_w(3);
-    const16 = __msa_ldi_w(16);
-
-    for (row = 8; row--;)
-    {
-        frame1_0_b = LD_SB(frame1_ptr);
-        frame2_0_b = LD_SB(frame2_ptr);
-        frame1_ptr += stride;
-        frame2_ptr += 16;
-        frame1_1_b = LD_SB(frame1_ptr);
-        frame2_1_b = LD_SB(frame2_ptr);
-        LD_SW2(acc, 4, acc0, acc1);
-        LD_SW2(acc + 8, 4, acc2, acc3);
-        LD_SH2(cnt, 8, cnt0, cnt1);
-        ILVRL_B2_UB(frame1_0_b, frame2_0_b, frame_l, frame_h);
-        HSUB_UB2_SH(frame_l, frame_h, diff0, diff1);
-        UNPCK_SH_SW(diff0, diff0_r, diff0_l);
-        UNPCK_SH_SW(diff1, diff1_r, diff1_l);
-        MUL4(diff0_r, diff0_r, diff0_l, diff0_l, diff1_r, diff1_r, diff1_l,
-             diff1_l, mod0_w, mod1_w, mod2_w, mod3_w);
-        MUL4(mod0_w, const3, mod1_w, const3, mod2_w, const3, mod3_w, const3,
-             mod0_w, mod1_w, mod2_w, mod3_w);
-        SRAR_W4_SW(mod0_w, mod1_w, mod2_w, mod3_w, strength);
-        diff0_r = (mod0_w < const16);
-        diff0_l = (mod1_w < const16);
-        diff1_r = (mod2_w < const16);
-        diff1_l = (mod3_w < const16);
-        SUB4(const16, mod0_w, const16, mod1_w, const16, mod2_w, const16, mod3_w,
-             mod0_w, mod1_w, mod2_w, mod3_w);
-        mod0_w = diff0_r & mod0_w;
-        mod1_w = diff0_l & mod1_w;
-        mod2_w = diff1_r & mod2_w;
-        mod3_w = diff1_l & mod3_w;
-        MUL4(mod0_w, filter_wt, mod1_w, filter_wt, mod2_w, filter_wt, mod3_w,
-             filter_wt, mod0_w, mod1_w, mod2_w, mod3_w);
-        PCKEV_H2_SH(mod1_w, mod0_w, mod3_w, mod2_w, mod0_h, mod1_h)
-        ADD2(mod0_h, cnt0, mod1_h, cnt1, mod0_h, mod1_h);
-        ST_SH2(mod0_h, mod1_h, cnt, 8);
-        cnt += 16;
-        ILVRL_B2_SH(zero, frame2_0_b, frame2_0_h, frame2_1_h);
-        UNPCK_SH_SW(frame2_0_h, frame2_0, frame2_1);
-        UNPCK_SH_SW(frame2_1_h, frame2_2, frame2_3);
-        MUL4(mod0_w, frame2_0, mod1_w, frame2_1, mod2_w, frame2_2, mod3_w,
-             frame2_3, mod0_w, mod1_w, mod2_w, mod3_w);
-        ADD4(mod0_w, acc0, mod1_w, acc1, mod2_w, acc2, mod3_w, acc3,
-             mod0_w, mod1_w, mod2_w, mod3_w);
-        ST_SW2(mod0_w, mod1_w, acc, 4);
-        ST_SW2(mod2_w, mod3_w, acc + 8, 4);
-        acc += 16;
-        LD_SW2(acc, 4, acc0, acc1);
-        LD_SW2(acc + 8, 4, acc2, acc3);
-        LD_SH2(cnt, 8, cnt0, cnt1);
-        ILVRL_B2_UB(frame1_1_b, frame2_1_b, frame_l, frame_h);
-        HSUB_UB2_SH(frame_l, frame_h, diff0, diff1);
-        UNPCK_SH_SW(diff0, diff0_r, diff0_l);
-        UNPCK_SH_SW(diff1, diff1_r, diff1_l);
-        MUL4(diff0_r, diff0_r, diff0_l, diff0_l, diff1_r, diff1_r, diff1_l,
-             diff1_l, mod0_w, mod1_w, mod2_w, mod3_w);
-        MUL4(mod0_w, const3, mod1_w, const3, mod2_w, const3, mod3_w, const3,
-             mod0_w, mod1_w, mod2_w, mod3_w);
-        SRAR_W4_SW(mod0_w, mod1_w, mod2_w, mod3_w, strength);
-        diff0_r = (mod0_w < const16);
-        diff0_l = (mod1_w < const16);
-        diff1_r = (mod2_w < const16);
-        diff1_l = (mod3_w < const16);
-        SUB4(const16, mod0_w, const16, mod1_w, const16, mod2_w, const16, mod3_w,
-             mod0_w, mod1_w, mod2_w, mod3_w);
-        mod0_w = diff0_r & mod0_w;
-        mod1_w = diff0_l & mod1_w;
-        mod2_w = diff1_r & mod2_w;
-        mod3_w = diff1_l & mod3_w;
-        MUL4(mod0_w, filter_wt, mod1_w, filter_wt, mod2_w, filter_wt, mod3_w,
-             filter_wt, mod0_w, mod1_w, mod2_w, mod3_w);
-        PCKEV_H2_SH(mod1_w, mod0_w, mod3_w, mod2_w, mod0_h, mod1_h);
-        ADD2(mod0_h, cnt0, mod1_h, cnt1, mod0_h, mod1_h);
-        ST_SH2(mod0_h, mod1_h, cnt, 8);
-        cnt += 16;
-
-        UNPCK_UB_SH(frame2_1_b, frame2_0_h, frame2_1_h);
-        UNPCK_SH_SW(frame2_0_h, frame2_0, frame2_1);
-        UNPCK_SH_SW(frame2_1_h, frame2_2, frame2_3);
-        MUL4(mod0_w, frame2_0, mod1_w, frame2_1, mod2_w, frame2_2, mod3_w,
-             frame2_3, mod0_w, mod1_w, mod2_w, mod3_w);
-        ADD4(mod0_w, acc0, mod1_w, acc1, mod2_w, acc2, mod3_w, acc3,
-             mod0_w, mod1_w, mod2_w, mod3_w);
-        ST_SW2(mod0_w, mod1_w, acc, 4);
-        ST_SW2(mod2_w, mod3_w, acc + 8, 4);
-        acc += 16;
-        frame1_ptr += stride;
-        frame2_ptr += 16;
-    }
-}
-
-static void temporal_filter_apply_8size_msa(uint8_t *frame1_ptr,
-                                            uint32_t stride,
-                                            uint8_t *frame2_ptr,
-                                            int32_t strength_in,
-                                            int32_t filter_wt_in,
-                                            uint32_t *acc, uint16_t *cnt)
-{
-    uint32_t row;
-    uint64_t f0, f1, f2, f3, f4, f5, f6, f7;
-    v16i8 frame1 = { 0 };
-    v16i8 frame2 = { 0 };
-    v16i8 frame3 = { 0 };
-    v16i8 frame4 = { 0 };
-    v16u8 frame_l, frame_h;
-    v8i16 frame2_0_h, frame2_1_h, mod0_h, mod1_h;
-    v8i16 diff0, diff1, cnt0, cnt1;
-    v4i32 const3, const16;
-    v4i32 filter_wt, strength;
-    v4i32 mod0_w, mod1_w, mod2_w, mod3_w;
-    v4i32 diff0_r, diff0_l, diff1_r, diff1_l;
-    v4i32 frame2_0, frame2_1, frame2_2, frame2_3;
-    v4i32 acc0, acc1, acc2, acc3;
-
-    filter_wt = __msa_fill_w(filter_wt_in);
-    strength = __msa_fill_w(strength_in);
-    const3 = __msa_ldi_w(3);
-    const16 = __msa_ldi_w(16);
-
-    for (row = 2; row--;)
-    {
-        LD2(frame1_ptr, stride, f0, f1);
-        frame1_ptr += (2 * stride);
-        LD2(frame2_ptr, 8, f2, f3);
-        frame2_ptr += 16;
-        LD2(frame1_ptr, stride, f4, f5);
-        frame1_ptr += (2 * stride);
-        LD2(frame2_ptr, 8, f6, f7);
-        frame2_ptr += 16;
-
-        LD_SW2(acc, 4, acc0, acc1);
-        LD_SW2(acc + 8, 4, acc2, acc3);
-        LD_SH2(cnt, 8, cnt0, cnt1);
-        INSERT_D2_SB(f0, f1, frame1);
-        INSERT_D2_SB(f2, f3, frame2);
-        INSERT_D2_SB(f4, f5, frame3);
-        INSERT_D2_SB(f6, f7, frame4);
-        ILVRL_B2_UB(frame1, frame2, frame_l, frame_h);
-        HSUB_UB2_SH(frame_l, frame_h, diff0, diff1);
-        UNPCK_SH_SW(diff0, diff0_r, diff0_l);
-        UNPCK_SH_SW(diff1, diff1_r, diff1_l);
-        MUL4(diff0_r, diff0_r, diff0_l, diff0_l, diff1_r, diff1_r, diff1_l,
-             diff1_l, mod0_w, mod1_w, mod2_w, mod3_w);
-        MUL4(mod0_w, const3, mod1_w, const3, mod2_w, const3, mod3_w, const3,
-             mod0_w, mod1_w, mod2_w, mod3_w);
-        SRAR_W4_SW(mod0_w, mod1_w, mod2_w, mod3_w, strength);
-        diff0_r = (mod0_w < const16);
-        diff0_l = (mod1_w < const16);
-        diff1_r = (mod2_w < const16);
-        diff1_l = (mod3_w < const16);
-        SUB4(const16, mod0_w, const16, mod1_w, const16, mod2_w, const16, mod3_w,
-             mod0_w, mod1_w, mod2_w, mod3_w);
-        mod0_w = diff0_r & mod0_w;
-        mod1_w = diff0_l & mod1_w;
-        mod2_w = diff1_r & mod2_w;
-        mod3_w = diff1_l & mod3_w;
-        MUL4(mod0_w, filter_wt, mod1_w, filter_wt, mod2_w, filter_wt, mod3_w,
-             filter_wt, mod0_w, mod1_w, mod2_w, mod3_w);
-        PCKEV_H2_SH(mod1_w, mod0_w, mod3_w, mod2_w, mod0_h, mod1_h);
-        ADD2(mod0_h, cnt0, mod1_h, cnt1, mod0_h, mod1_h);
-        ST_SH2(mod0_h, mod1_h, cnt, 8);
-        cnt += 16;
-
-        UNPCK_UB_SH(frame2, frame2_0_h, frame2_1_h);
-        UNPCK_SH_SW(frame2_0_h, frame2_0, frame2_1);
-        UNPCK_SH_SW(frame2_1_h, frame2_2, frame2_3);
-        MUL4(mod0_w, frame2_0, mod1_w, frame2_1, mod2_w, frame2_2, mod3_w,
-             frame2_3, mod0_w, mod1_w, mod2_w, mod3_w);
-        ADD4(mod0_w, acc0, mod1_w, acc1, mod2_w, acc2, mod3_w, acc3,
-             mod0_w, mod1_w, mod2_w, mod3_w);
-        ST_SW2(mod0_w, mod1_w, acc, 4);
-        ST_SW2(mod2_w, mod3_w, acc + 8, 4);
-        acc += 16;
-
-        LD_SW2(acc, 4, acc0, acc1);
-        LD_SW2(acc + 8, 4, acc2, acc3);
-        LD_SH2(cnt, 8, cnt0, cnt1);
-        ILVRL_B2_UB(frame3, frame4, frame_l, frame_h);
-        HSUB_UB2_SH(frame_l, frame_h, diff0, diff1);
-        UNPCK_SH_SW(diff0, diff0_r, diff0_l);
-        UNPCK_SH_SW(diff1, diff1_r, diff1_l);
-        MUL4(diff0_r, diff0_r, diff0_l, diff0_l, diff1_r, diff1_r, diff1_l,
-             diff1_l, mod0_w, mod1_w, mod2_w, mod3_w);
-        MUL4(mod0_w, const3, mod1_w, const3, mod2_w, const3, mod3_w, const3,
-             mod0_w, mod1_w, mod2_w, mod3_w);
-        SRAR_W4_SW(mod0_w, mod1_w, mod2_w, mod3_w, strength);
-        diff0_r = (mod0_w < const16);
-        diff0_l = (mod1_w < const16);
-        diff1_r = (mod2_w < const16);
-        diff1_l = (mod3_w < const16);
-        SUB4(const16, mod0_w, const16, mod1_w, const16, mod2_w, const16, mod3_w,
-             mod0_w, mod1_w, mod2_w, mod3_w);
-        mod0_w = diff0_r & mod0_w;
-        mod1_w = diff0_l & mod1_w;
-        mod2_w = diff1_r & mod2_w;
-        mod3_w = diff1_l & mod3_w;
-        MUL4(mod0_w, filter_wt, mod1_w, filter_wt, mod2_w, filter_wt, mod3_w,
-             filter_wt, mod0_w, mod1_w, mod2_w, mod3_w);
-        PCKEV_H2_SH(mod1_w, mod0_w, mod3_w, mod2_w, mod0_h, mod1_h);
-        ADD2(mod0_h, cnt0, mod1_h, cnt1, mod0_h, mod1_h);
-        ST_SH2(mod0_h, mod1_h, cnt, 8);
-        cnt += 16;
-
-        UNPCK_UB_SH(frame4, frame2_0_h, frame2_1_h);
-        UNPCK_SH_SW(frame2_0_h, frame2_0, frame2_1);
-        UNPCK_SH_SW(frame2_1_h, frame2_2, frame2_3);
-        MUL4(mod0_w, frame2_0, mod1_w, frame2_1, mod2_w, frame2_2, mod3_w,
-             frame2_3, mod0_w, mod1_w, mod2_w, mod3_w);
-        ADD4(mod0_w, acc0, mod1_w, acc1, mod2_w, acc2, mod3_w, acc3,
-             mod0_w, mod1_w, mod2_w, mod3_w);
-        ST_SW2(mod0_w, mod1_w, acc, 4);
-        ST_SW2(mod2_w, mod3_w, acc + 8, 4);
-        acc += 16;
-    }
-}
-
-void vp8_temporal_filter_apply_msa(uint8_t *frame1, uint32_t stride,
-                                   uint8_t *frame2, uint32_t block_size,
-                                   int32_t strength,  int32_t filter_weight,
-                                   uint32_t *accumulator, uint16_t *count)
-{
-    if (8 == block_size)
-    {
-        temporal_filter_apply_8size_msa(frame1, stride, frame2, strength,
-                                        filter_weight, accumulator, count);
-    }
-    else if (16 == block_size)
-    {
-        temporal_filter_apply_16size_msa(frame1, stride, frame2, strength,
-                                         filter_weight, accumulator, count);
-    }
-    else
-    {
-        uint32_t i, j, k;
-        int32_t modifier;
-        int32_t byte = 0;
-        const int32_t rounding = strength > 0 ? 1 << (strength - 1) : 0;
-
-        for (i = 0, k = 0; i < block_size; ++i)
-        {
-            for (j = 0; j < block_size; ++j, ++k)
-            {
-                int src_byte = frame1[byte];
-                int pixel_value = *frame2++;
-
-                modifier = src_byte - pixel_value;
-                modifier *= modifier;
-                modifier *= 3;
-                modifier += rounding;
-                modifier >>= strength;
-
-                if (modifier > 16)
-                    modifier = 16;
-
-                modifier = 16 - modifier;
-                modifier *= filter_weight;
-
-                count[k] += modifier;
-                accumulator[k] += modifier * pixel_value;
-
-                byte++;
-            }
-
-            byte += stride - block_size;
-        }
-    }
-}
diff --git a/vp8/encoder/modecosts.c b/vp8/encoder/modecosts.c
deleted file mode 100644 (file)
index ad0e930..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#include "vp8/common/blockd.h"
-#include "modecosts.h"
-#include "onyx_int.h"
-#include "treewriter.h"
-#include "vp8/common/entropymode.h"
-
-
-void vp8_init_mode_costs(VP8_COMP *c)
-{
-    VP8_COMMON *x = &c->common;
-    struct rd_costs_struct *rd_costs = &c->rd_costs;
-
-    {
-        const vp8_tree_p T = vp8_bmode_tree;
-
-        int i = 0;
-
-        do
-        {
-            int j = 0;
-
-            do
-            {
-                vp8_cost_tokens(rd_costs->bmode_costs[i][j],
-                                vp8_kf_bmode_prob[i][j], T);
-            }
-            while (++j < VP8_BINTRAMODES);
-        }
-        while (++i < VP8_BINTRAMODES);
-
-        vp8_cost_tokens(rd_costs->inter_bmode_costs, x->fc.bmode_prob, T);
-    }
-    vp8_cost_tokens(rd_costs->inter_bmode_costs, x->fc.sub_mv_ref_prob,
-                    vp8_sub_mv_ref_tree);
-
-    vp8_cost_tokens(rd_costs->mbmode_cost[1], x->fc.ymode_prob, vp8_ymode_tree);
-    vp8_cost_tokens(rd_costs->mbmode_cost[0], vp8_kf_ymode_prob,
-                    vp8_kf_ymode_tree);
-
-    vp8_cost_tokens(rd_costs->intra_uv_mode_cost[1], x->fc.uv_mode_prob,
-                    vp8_uv_mode_tree);
-    vp8_cost_tokens(rd_costs->intra_uv_mode_cost[0], vp8_kf_uv_mode_prob,
-                    vp8_uv_mode_tree);
-}
diff --git a/vp8/encoder/modecosts.h b/vp8/encoder/modecosts.h
deleted file mode 100644 (file)
index 9871bff..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#ifndef VP8_ENCODER_MODECOSTS_H_
-#define VP8_ENCODER_MODECOSTS_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-struct VP8_COMP;
-
-void vp8_init_mode_costs(struct VP8_COMP *x);
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP8_ENCODER_MODECOSTS_H_
diff --git a/vp8/encoder/mr_dissim.c b/vp8/encoder/mr_dissim.c
deleted file mode 100644 (file)
index 886cba2..0000000
+++ /dev/null
@@ -1,240 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#include <limits.h>
-#include "vpx_config.h"
-#include "onyx_int.h"
-#include "mr_dissim.h"
-#include "vpx_dsp/vpx_dsp_common.h"
-#include "vpx_mem/vpx_mem.h"
-#include "rdopt.h"
-#include "vp8/common/common.h"
-
-void vp8_cal_low_res_mb_cols(VP8_COMP *cpi)
-{
-    int low_res_w;
-
-    /* Support arbitrary down-sampling factor */
-    unsigned int iw = cpi->oxcf.Width*cpi->oxcf.mr_down_sampling_factor.den
-                      + cpi->oxcf.mr_down_sampling_factor.num - 1;
-
-    low_res_w = iw/cpi->oxcf.mr_down_sampling_factor.num;
-    cpi->mr_low_res_mb_cols = ((low_res_w + 15) >> 4);
-}
-
-#define GET_MV(x)    \
-if(x->mbmi.ref_frame !=INTRA_FRAME)   \
-{   \
-    mvx[cnt] = x->mbmi.mv.as_mv.row;  \
-    mvy[cnt] = x->mbmi.mv.as_mv.col;  \
-    cnt++;    \
-}
-
-#define GET_MV_SIGN(x)    \
-if(x->mbmi.ref_frame !=INTRA_FRAME)   \
-{   \
-    mvx[cnt] = x->mbmi.mv.as_mv.row;  \
-    mvy[cnt] = x->mbmi.mv.as_mv.col;  \
-    if (cm->ref_frame_sign_bias[x->mbmi.ref_frame]  \
-        != cm->ref_frame_sign_bias[tmp->mbmi.ref_frame])  \
-    {  \
-        mvx[cnt] *= -1;   \
-        mvy[cnt] *= -1;   \
-    }  \
-    cnt++;  \
-}
-
-void vp8_cal_dissimilarity(VP8_COMP *cpi)
-{
-    VP8_COMMON *cm = &cpi->common;
-    int i;
-
-    /* Note: The first row & first column in mip are outside the frame, which
-     * were initialized to all 0.(ref_frame, mode, mv...)
-     * Their ref_frame = 0 means they won't be counted in the following
-     * calculation.
-     */
-    if (cpi->oxcf.mr_total_resolutions >1
-        && cpi->oxcf.mr_encoder_id < (cpi->oxcf.mr_total_resolutions - 1))
-    {
-        /* Store info for show/no-show frames for supporting alt_ref.
-         * If parent frame is alt_ref, child has one too.
-         */
-        LOWER_RES_FRAME_INFO* store_info
-                      = (LOWER_RES_FRAME_INFO*)cpi->oxcf.mr_low_res_mode_info;
-
-        store_info->frame_type = cm->frame_type;
-
-        if(cm->frame_type != KEY_FRAME)
-        {
-            store_info->is_frame_dropped = 0;
-            for (i = 1; i < MAX_REF_FRAMES; i++)
-                store_info->low_res_ref_frames[i] = cpi->current_ref_frames[i];
-        }
-
-        if(cm->frame_type != KEY_FRAME)
-        {
-            int mb_row;
-            int mb_col;
-            /* Point to beginning of allocated MODE_INFO arrays. */
-            MODE_INFO *tmp = cm->mip + cm->mode_info_stride;
-            LOWER_RES_MB_INFO* store_mode_info = store_info->mb_info;
-
-            for (mb_row = 0; mb_row < cm->mb_rows; mb_row ++)
-            {
-                tmp++;
-                for (mb_col = 0; mb_col < cm->mb_cols; mb_col ++)
-                {
-                    int dissim = INT_MAX;
-
-                    if(tmp->mbmi.ref_frame !=INTRA_FRAME)
-                    {
-                        int              mvx[8];
-                        int              mvy[8];
-                        int              mmvx;
-                        int              mmvy;
-                        int              cnt=0;
-                        const MODE_INFO *here = tmp;
-                        const MODE_INFO *above = here - cm->mode_info_stride;
-                        const MODE_INFO *left = here - 1;
-                        const MODE_INFO *aboveleft = above - 1;
-                        const MODE_INFO *aboveright = NULL;
-                        const MODE_INFO *right = NULL;
-                        const MODE_INFO *belowleft = NULL;
-                        const MODE_INFO *below = NULL;
-                        const MODE_INFO *belowright = NULL;
-
-                        /* If alternate reference frame is used, we have to
-                         * check sign of MV. */
-                        if(cpi->oxcf.play_alternate)
-                        {
-                            /* Gather mv of neighboring MBs */
-                            GET_MV_SIGN(above)
-                            GET_MV_SIGN(left)
-                            GET_MV_SIGN(aboveleft)
-
-                            if(mb_col < (cm->mb_cols-1))
-                            {
-                                right = here + 1;
-                                aboveright = above + 1;
-                                GET_MV_SIGN(right)
-                                GET_MV_SIGN(aboveright)
-                            }
-
-                            if(mb_row < (cm->mb_rows-1))
-                            {
-                                below = here + cm->mode_info_stride;
-                                belowleft = below - 1;
-                                GET_MV_SIGN(below)
-                                GET_MV_SIGN(belowleft)
-                            }
-
-                            if(mb_col < (cm->mb_cols-1)
-                                && mb_row < (cm->mb_rows-1))
-                            {
-                                belowright = below + 1;
-                                GET_MV_SIGN(belowright)
-                            }
-                        }else
-                        {
-                            /* No alt_ref and gather mv of neighboring MBs */
-                            GET_MV(above)
-                            GET_MV(left)
-                            GET_MV(aboveleft)
-
-                            if(mb_col < (cm->mb_cols-1))
-                            {
-                                right = here + 1;
-                                aboveright = above + 1;
-                                GET_MV(right)
-                                GET_MV(aboveright)
-                            }
-
-                            if(mb_row < (cm->mb_rows-1))
-                            {
-                                below = here + cm->mode_info_stride;
-                                belowleft = below - 1;
-                                GET_MV(below)
-                                GET_MV(belowleft)
-                            }
-
-                            if(mb_col < (cm->mb_cols-1)
-                                && mb_row < (cm->mb_rows-1))
-                            {
-                                belowright = below + 1;
-                                GET_MV(belowright)
-                            }
-                        }
-
-                        if (cnt > 0)
-                        {
-                            int max_mvx = mvx[0];
-                            int min_mvx = mvx[0];
-                            int max_mvy = mvy[0];
-                            int min_mvy = mvy[0];
-                            int i;
-
-                            if (cnt > 1)
-                            {
-                                for (i=1; i< cnt; i++)
-                                {
-                                    if (mvx[i] > max_mvx) max_mvx = mvx[i];
-                                    else if (mvx[i] < min_mvx) min_mvx = mvx[i];
-                                    if (mvy[i] > max_mvy) max_mvy = mvy[i];
-                                    else if (mvy[i] < min_mvy) min_mvy = mvy[i];
-                                }
-                            }
-
-                            mmvx = VPXMAX(
-                                abs(min_mvx - here->mbmi.mv.as_mv.row),
-                                abs(max_mvx - here->mbmi.mv.as_mv.row));
-                            mmvy = VPXMAX(
-                                abs(min_mvy - here->mbmi.mv.as_mv.col),
-                                abs(max_mvy - here->mbmi.mv.as_mv.col));
-                            dissim = VPXMAX(mmvx, mmvy);
-                        }
-                    }
-
-                    /* Store mode info for next resolution encoding */
-                    store_mode_info->mode = tmp->mbmi.mode;
-                    store_mode_info->ref_frame = tmp->mbmi.ref_frame;
-                    store_mode_info->mv.as_int = tmp->mbmi.mv.as_int;
-                    store_mode_info->dissim = dissim;
-                    tmp++;
-                    store_mode_info++;
-                }
-            }
-        }
-    }
-}
-
-/* This function is called only when this frame is dropped at current
-   resolution level. */
-void vp8_store_drop_frame_info(VP8_COMP *cpi)
-{
-    /* If the frame is dropped in lower-resolution encoding, this information
-       is passed to higher resolution level so that the encoder knows there
-       is no mode & motion info available.
-     */
-    if (cpi->oxcf.mr_total_resolutions >1
-        && cpi->oxcf.mr_encoder_id < (cpi->oxcf.mr_total_resolutions - 1))
-    {
-        /* Store info for show/no-show frames for supporting alt_ref.
-         * If parent frame is alt_ref, child has one too.
-         */
-        LOWER_RES_FRAME_INFO* store_info
-                      = (LOWER_RES_FRAME_INFO*)cpi->oxcf.mr_low_res_mode_info;
-
-        /* Set frame_type to be INTER_FRAME since we won't drop key frame. */
-        store_info->frame_type = INTER_FRAME;
-        store_info->is_frame_dropped = 1;
-    }
-}
diff --git a/vp8/encoder/mr_dissim.h b/vp8/encoder/mr_dissim.h
deleted file mode 100644 (file)
index 5a59ce6..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#ifndef VP8_ENCODER_MR_DISSIM_H_
-#define VP8_ENCODER_MR_DISSIM_H_
-#include "vpx_config.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-extern void vp8_cal_low_res_mb_cols(VP8_COMP *cpi);
-extern void vp8_cal_dissimilarity(VP8_COMP *cpi);
-extern void vp8_store_drop_frame_info(VP8_COMP *cpi);
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP8_ENCODER_MR_DISSIM_H_
diff --git a/vp8/encoder/onyx_if.c b/vp8/encoder/onyx_if.c
deleted file mode 100644 (file)
index 8511af2..0000000
+++ /dev/null
@@ -1,5900 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#include "vpx_config.h"
-#include "./vpx_scale_rtcd.h"
-#include "./vpx_dsp_rtcd.h"
-#include "./vp8_rtcd.h"
-#include "vp8/common/onyxc_int.h"
-#include "vp8/common/blockd.h"
-#include "onyx_int.h"
-#include "vp8/common/systemdependent.h"
-#include "vp8/encoder/quantize.h"
-#include "vp8/common/alloccommon.h"
-#include "mcomp.h"
-#include "firstpass.h"
-#include "vpx_dsp/psnr.h"
-#include "vpx_scale/vpx_scale.h"
-#include "vp8/common/extend.h"
-#include "ratectrl.h"
-#include "vp8/common/quant_common.h"
-#include "segmentation.h"
-#if CONFIG_POSTPROC
-#include "vp8/common/postproc.h"
-#endif
-#include "vpx_mem/vpx_mem.h"
-#include "vp8/common/reconintra.h"
-#include "vp8/common/swapyv12buffer.h"
-#include "vp8/common/threading.h"
-#include "vpx_ports/vpx_timer.h"
-#if ARCH_ARM
-#include "vpx_ports/arm.h"
-#endif
-#if CONFIG_MULTI_RES_ENCODING
-#include "mr_dissim.h"
-#endif
-#include "encodeframe.h"
-
-#include <math.h>
-#include <stdio.h>
-#include <limits.h>
-
-#if CONFIG_REALTIME_ONLY & CONFIG_ONTHEFLY_BITPACKING
-extern int vp8_update_coef_context(VP8_COMP *cpi);
-extern void vp8_update_coef_probs(VP8_COMP *cpi);
-#endif
-
-extern void vp8cx_pick_filter_level_fast(YV12_BUFFER_CONFIG *sd, VP8_COMP *cpi);
-extern void vp8cx_set_alt_lf_level(VP8_COMP *cpi, int filt_val);
-extern void vp8cx_pick_filter_level(YV12_BUFFER_CONFIG *sd, VP8_COMP *cpi);
-
-extern void vp8_deblock_frame(YV12_BUFFER_CONFIG *source, YV12_BUFFER_CONFIG *post, int filt_lvl, int low_var_thresh, int flag);
-extern void print_parms(VP8_CONFIG *ocf, char *filenam);
-extern unsigned int vp8_get_processor_freq();
-extern void print_tree_update_probs();
-extern int vp8cx_create_encoder_threads(VP8_COMP *cpi);
-extern void vp8cx_remove_encoder_threads(VP8_COMP *cpi);
-
-int vp8_estimate_entropy_savings(VP8_COMP *cpi);
-
-int vp8_calc_ss_err(YV12_BUFFER_CONFIG *source, YV12_BUFFER_CONFIG *dest);
-
-extern void vp8_temporal_filter_prepare_c(VP8_COMP *cpi, int distance);
-
-static void set_default_lf_deltas(VP8_COMP *cpi);
-
-extern const int vp8_gf_interval_table[101];
-
-#if CONFIG_INTERNAL_STATS
-#include "math.h"
-#include "vpx_dsp/ssim.h"
-#endif
-
-
-#ifdef OUTPUT_YUV_SRC
-FILE *yuv_file;
-#endif
-#ifdef OUTPUT_YUV_DENOISED
-FILE *yuv_denoised_file;
-#endif
-
-#if 0
-FILE *framepsnr;
-FILE *kf_list;
-FILE *keyfile;
-#endif
-
-#if 0
-extern int skip_true_count;
-extern int skip_false_count;
-#endif
-
-
-#ifdef VP8_ENTROPY_STATS
-extern int intra_mode_stats[10][10][10];
-#endif
-
-#ifdef SPEEDSTATS
-unsigned int frames_at_speed[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
-unsigned int tot_pm = 0;
-unsigned int cnt_pm = 0;
-unsigned int tot_ef = 0;
-unsigned int cnt_ef = 0;
-#endif
-
-#ifdef MODE_STATS
-extern unsigned __int64 Sectionbits[50];
-extern int y_modes[5]  ;
-extern int uv_modes[4] ;
-extern int b_modes[10]  ;
-
-extern int inter_y_modes[10] ;
-extern int inter_uv_modes[4] ;
-extern unsigned int inter_b_modes[15];
-#endif
-
-extern const int vp8_bits_per_mb[2][QINDEX_RANGE];
-
-extern const int qrounding_factors[129];
-extern const int qzbin_factors[129];
-extern void vp8cx_init_quantizer(VP8_COMP *cpi);
-extern const int vp8cx_base_skip_false_prob[128];
-
-/* Tables relating active max Q to active min Q */
-static const unsigned char kf_low_motion_minq[QINDEX_RANGE] =
-{
-    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
-    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
-    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
-    0,0,0,0,1,1,1,1,1,1,1,1,2,2,2,2,
-    3,3,3,3,3,3,4,4,4,5,5,5,5,5,6,6,
-    6,6,7,7,8,8,8,8,9,9,10,10,10,10,11,11,
-    11,11,12,12,13,13,13,13,14,14,15,15,15,15,16,16,
-    16,16,17,17,18,18,18,18,19,20,20,21,21,22,23,23
-};
-static const unsigned char kf_high_motion_minq[QINDEX_RANGE] =
-{
-    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
-    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
-    1,1,1,1,1,1,1,1,2,2,2,2,3,3,3,3,
-    3,3,3,3,4,4,4,4,5,5,5,5,5,5,6,6,
-    6,6,7,7,8,8,8,8,9,9,10,10,10,10,11,11,
-    11,11,12,12,13,13,13,13,14,14,15,15,15,15,16,16,
-    16,16,17,17,18,18,18,18,19,19,20,20,20,20,21,21,
-    21,21,22,22,23,23,24,25,25,26,26,27,28,28,29,30
-};
-static const unsigned char gf_low_motion_minq[QINDEX_RANGE] =
-{
-    0,0,0,0,1,1,1,1,1,1,1,1,2,2,2,2,
-    3,3,3,3,4,4,4,4,5,5,5,5,6,6,6,6,
-    7,7,7,7,8,8,8,8,9,9,9,9,10,10,10,10,
-    11,11,12,12,13,13,14,14,15,15,16,16,17,17,18,18,
-    19,19,20,20,21,21,22,22,23,23,24,24,25,25,26,26,
-    27,27,28,28,29,29,30,30,31,31,32,32,33,33,34,34,
-    35,35,36,36,37,37,38,38,39,39,40,40,41,41,42,42,
-    43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58
-};
-static const unsigned char gf_mid_motion_minq[QINDEX_RANGE] =
-{
-    0,0,0,0,1,1,1,1,1,1,2,2,3,3,3,4,
-    4,4,5,5,5,6,6,6,7,7,7,8,8,8,9,9,
-    9,10,10,10,10,11,11,11,12,12,12,12,13,13,13,14,
-    14,14,15,15,16,16,17,17,18,18,19,19,20,20,21,21,
-    22,22,23,23,24,24,25,25,26,26,27,27,28,28,29,29,
-    30,30,31,31,32,32,33,33,34,34,35,35,36,36,37,37,
-    38,39,39,40,40,41,41,42,42,43,43,44,45,46,47,48,
-    49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64
-};
-static const unsigned char gf_high_motion_minq[QINDEX_RANGE] =
-{
-    0,0,0,0,1,1,1,1,1,2,2,2,3,3,3,4,
-    4,4,5,5,5,6,6,6,7,7,7,8,8,8,9,9,
-    9,10,10,10,11,11,12,12,13,13,14,14,15,15,16,16,
-    17,17,18,18,19,19,20,20,21,21,22,22,23,23,24,24,
-    25,25,26,26,27,27,28,28,29,29,30,30,31,31,32,32,
-    33,33,34,34,35,35,36,36,37,37,38,38,39,39,40,40,
-    41,41,42,42,43,44,45,46,47,48,49,50,51,52,53,54,
-    55,56,57,58,59,60,62,64,66,68,70,72,74,76,78,80
-};
-static const unsigned char inter_minq[QINDEX_RANGE] =
-{
-    0,0,1,1,2,3,3,4,4,5,6,6,7,8,8,9,
-    9,10,11,11,12,13,13,14,15,15,16,17,17,18,19,20,
-    20,21,22,22,23,24,24,25,26,27,27,28,29,30,30,31,
-    32,33,33,34,35,36,36,37,38,39,39,40,41,42,42,43,
-    44,45,46,46,47,48,49,50,50,51,52,53,54,55,55,56,
-    57,58,59,60,60,61,62,63,64,65,66,67,67,68,69,70,
-    71,72,73,74,75,75,76,77,78,79,80,81,82,83,84,85,
-    86,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100
-};
-
-#ifdef PACKET_TESTING
-extern FILE *vpxlogc;
-#endif
-
-static void save_layer_context(VP8_COMP *cpi)
-{
-    LAYER_CONTEXT *lc = &cpi->layer_context[cpi->current_layer];
-
-    /* Save layer dependent coding state */
-    lc->target_bandwidth                 = cpi->target_bandwidth;
-    lc->starting_buffer_level            = cpi->oxcf.starting_buffer_level;
-    lc->optimal_buffer_level             = cpi->oxcf.optimal_buffer_level;
-    lc->maximum_buffer_size              = cpi->oxcf.maximum_buffer_size;
-    lc->starting_buffer_level_in_ms      = cpi->oxcf.starting_buffer_level_in_ms;
-    lc->optimal_buffer_level_in_ms       = cpi->oxcf.optimal_buffer_level_in_ms;
-    lc->maximum_buffer_size_in_ms        = cpi->oxcf.maximum_buffer_size_in_ms;
-    lc->buffer_level                     = cpi->buffer_level;
-    lc->bits_off_target                  = cpi->bits_off_target;
-    lc->total_actual_bits                = cpi->total_actual_bits;
-    lc->worst_quality                    = cpi->worst_quality;
-    lc->active_worst_quality             = cpi->active_worst_quality;
-    lc->best_quality                     = cpi->best_quality;
-    lc->active_best_quality              = cpi->active_best_quality;
-    lc->ni_av_qi                         = cpi->ni_av_qi;
-    lc->ni_tot_qi                        = cpi->ni_tot_qi;
-    lc->ni_frames                        = cpi->ni_frames;
-    lc->avg_frame_qindex                 = cpi->avg_frame_qindex;
-    lc->rate_correction_factor           = cpi->rate_correction_factor;
-    lc->key_frame_rate_correction_factor = cpi->key_frame_rate_correction_factor;
-    lc->gf_rate_correction_factor        = cpi->gf_rate_correction_factor;
-    lc->zbin_over_quant                  = cpi->mb.zbin_over_quant;
-    lc->inter_frame_target               = cpi->inter_frame_target;
-    lc->total_byte_count                 = cpi->total_byte_count;
-    lc->filter_level                     = cpi->common.filter_level;
-
-    lc->last_frame_percent_intra         = cpi->last_frame_percent_intra;
-
-    memcpy (lc->count_mb_ref_frame_usage,
-            cpi->mb.count_mb_ref_frame_usage,
-            sizeof(cpi->mb.count_mb_ref_frame_usage));
-}
-
-static void restore_layer_context(VP8_COMP *cpi, const int layer)
-{
-    LAYER_CONTEXT *lc = &cpi->layer_context[layer];
-
-    /* Restore layer dependent coding state */
-    cpi->current_layer                    = layer;
-    cpi->target_bandwidth                 = lc->target_bandwidth;
-    cpi->oxcf.target_bandwidth            = lc->target_bandwidth;
-    cpi->oxcf.starting_buffer_level       = lc->starting_buffer_level;
-    cpi->oxcf.optimal_buffer_level        = lc->optimal_buffer_level;
-    cpi->oxcf.maximum_buffer_size         = lc->maximum_buffer_size;
-    cpi->oxcf.starting_buffer_level_in_ms = lc->starting_buffer_level_in_ms;
-    cpi->oxcf.optimal_buffer_level_in_ms  = lc->optimal_buffer_level_in_ms;
-    cpi->oxcf.maximum_buffer_size_in_ms   = lc->maximum_buffer_size_in_ms;
-    cpi->buffer_level                     = lc->buffer_level;
-    cpi->bits_off_target                  = lc->bits_off_target;
-    cpi->total_actual_bits                = lc->total_actual_bits;
-    cpi->active_worst_quality             = lc->active_worst_quality;
-    cpi->active_best_quality              = lc->active_best_quality;
-    cpi->ni_av_qi                         = lc->ni_av_qi;
-    cpi->ni_tot_qi                        = lc->ni_tot_qi;
-    cpi->ni_frames                        = lc->ni_frames;
-    cpi->avg_frame_qindex                 = lc->avg_frame_qindex;
-    cpi->rate_correction_factor           = lc->rate_correction_factor;
-    cpi->key_frame_rate_correction_factor = lc->key_frame_rate_correction_factor;
-    cpi->gf_rate_correction_factor        = lc->gf_rate_correction_factor;
-    cpi->mb.zbin_over_quant                  = lc->zbin_over_quant;
-    cpi->inter_frame_target               = lc->inter_frame_target;
-    cpi->total_byte_count                 = lc->total_byte_count;
-    cpi->common.filter_level              = lc->filter_level;
-
-    cpi->last_frame_percent_intra         = lc->last_frame_percent_intra;
-
-    memcpy (cpi->mb.count_mb_ref_frame_usage,
-            lc->count_mb_ref_frame_usage,
-            sizeof(cpi->mb.count_mb_ref_frame_usage));
-}
-
-static int rescale(int val, int num, int denom)
-{
-    int64_t llnum = num;
-    int64_t llden = denom;
-    int64_t llval = val;
-
-    return (int)(llval * llnum / llden);
-}
-
-static void init_temporal_layer_context(VP8_COMP *cpi,
-                                        VP8_CONFIG *oxcf,
-                                        const int layer,
-                                        double prev_layer_framerate)
-{
-    LAYER_CONTEXT *lc = &cpi->layer_context[layer];
-
-    lc->framerate = cpi->output_framerate / cpi->oxcf.rate_decimator[layer];
-    lc->target_bandwidth = cpi->oxcf.target_bitrate[layer] * 1000;
-
-    lc->starting_buffer_level_in_ms = oxcf->starting_buffer_level;
-    lc->optimal_buffer_level_in_ms  = oxcf->optimal_buffer_level;
-    lc->maximum_buffer_size_in_ms   = oxcf->maximum_buffer_size;
-
-    lc->starting_buffer_level =
-        rescale((int)(oxcf->starting_buffer_level),
-                lc->target_bandwidth, 1000);
-
-    if (oxcf->optimal_buffer_level == 0)
-      lc->optimal_buffer_level = lc->target_bandwidth / 8;
-    else
-      lc->optimal_buffer_level =
-          rescale((int)(oxcf->optimal_buffer_level),
-                  lc->target_bandwidth, 1000);
-
-    if (oxcf->maximum_buffer_size == 0)
-      lc->maximum_buffer_size = lc->target_bandwidth / 8;
-    else
-      lc->maximum_buffer_size =
-          rescale((int)(oxcf->maximum_buffer_size),
-                  lc->target_bandwidth, 1000);
-
-    /* Work out the average size of a frame within this layer */
-    if (layer > 0)
-      lc->avg_frame_size_for_layer =
-          (int)((cpi->oxcf.target_bitrate[layer] -
-                cpi->oxcf.target_bitrate[layer-1]) * 1000 /
-                (lc->framerate - prev_layer_framerate));
-
-     lc->active_worst_quality         = cpi->oxcf.worst_allowed_q;
-     lc->active_best_quality          = cpi->oxcf.best_allowed_q;
-     lc->avg_frame_qindex             = cpi->oxcf.worst_allowed_q;
-
-     lc->buffer_level                 = lc->starting_buffer_level;
-     lc->bits_off_target              = lc->starting_buffer_level;
-
-     lc->total_actual_bits                 = 0;
-     lc->ni_av_qi                          = 0;
-     lc->ni_tot_qi                         = 0;
-     lc->ni_frames                         = 0;
-     lc->rate_correction_factor            = 1.0;
-     lc->key_frame_rate_correction_factor  = 1.0;
-     lc->gf_rate_correction_factor         = 1.0;
-     lc->inter_frame_target                = 0;
-}
-
-// Upon a run-time change in temporal layers, reset the layer context parameters
-// for any "new" layers. For "existing" layers, let them inherit the parameters
-// from the previous layer state (at the same layer #). In future we may want
-// to better map the previous layer state(s) to the "new" ones.
-static void reset_temporal_layer_change(VP8_COMP *cpi,
-                                        VP8_CONFIG *oxcf,
-                                        const int prev_num_layers)
-{
-    int i;
-    double prev_layer_framerate = 0;
-    const int curr_num_layers = cpi->oxcf.number_of_layers;
-    // If the previous state was 1 layer, get current layer context from cpi.
-    // We need this to set the layer context for the new layers below.
-    if (prev_num_layers == 1)
-    {
-        cpi->current_layer = 0;
-        save_layer_context(cpi);
-    }
-    for (i = 0; i < curr_num_layers; i++)
-    {
-        LAYER_CONTEXT *lc = &cpi->layer_context[i];
-        if (i >= prev_num_layers)
-        {
-           init_temporal_layer_context(cpi, oxcf, i, prev_layer_framerate);
-        }
-        // The initial buffer levels are set based on their starting levels.
-        // We could set the buffer levels based on the previous state (normalized
-        // properly by the layer bandwidths) but we would need to keep track of
-        // the previous set of layer bandwidths (i.e., target_bitrate[i])
-        // before the layer change. For now, reset to the starting levels.
-        lc->buffer_level = cpi->oxcf.starting_buffer_level_in_ms *
-                           cpi->oxcf.target_bitrate[i];
-        lc->bits_off_target = lc->buffer_level;
-        // TDOD(marpan): Should we set the rate_correction_factor and
-        // active_worst/best_quality to values derived from the previous layer
-        // state (to smooth-out quality dips/rate fluctuation at transition)?
-
-        // We need to treat the 1 layer case separately: oxcf.target_bitrate[i]
-        // is not set for 1 layer, and the restore_layer_context/save_context()
-        // are not called in the encoding loop, so we need to call it here to
-        // pass the layer context state to |cpi|.
-        if (curr_num_layers == 1)
-        {
-            lc->target_bandwidth = cpi->oxcf.target_bandwidth;
-            lc->buffer_level = cpi->oxcf.starting_buffer_level_in_ms *
-                               lc->target_bandwidth  / 1000;
-            lc->bits_off_target = lc->buffer_level;
-            restore_layer_context(cpi, 0);
-        }
-        prev_layer_framerate = cpi->output_framerate /
-                               cpi->oxcf.rate_decimator[i];
-    }
-}
-
-static void setup_features(VP8_COMP *cpi)
-{
-    // If segmentation enabled set the update flags
-    if ( cpi->mb.e_mbd.segmentation_enabled )
-    {
-        cpi->mb.e_mbd.update_mb_segmentation_map = 1;
-        cpi->mb.e_mbd.update_mb_segmentation_data = 1;
-    }
-    else
-    {
-        cpi->mb.e_mbd.update_mb_segmentation_map = 0;
-        cpi->mb.e_mbd.update_mb_segmentation_data = 0;
-    }
-
-    cpi->mb.e_mbd.mode_ref_lf_delta_enabled = 0;
-    cpi->mb.e_mbd.mode_ref_lf_delta_update = 0;
-    memset(cpi->mb.e_mbd.ref_lf_deltas, 0, sizeof(cpi->mb.e_mbd.ref_lf_deltas));
-    memset(cpi->mb.e_mbd.mode_lf_deltas, 0, sizeof(cpi->mb.e_mbd.mode_lf_deltas));
-    memset(cpi->mb.e_mbd.last_ref_lf_deltas, 0, sizeof(cpi->mb.e_mbd.ref_lf_deltas));
-    memset(cpi->mb.e_mbd.last_mode_lf_deltas, 0, sizeof(cpi->mb.e_mbd.mode_lf_deltas));
-
-    set_default_lf_deltas(cpi);
-
-}
-
-
-static void dealloc_raw_frame_buffers(VP8_COMP *cpi);
-
-void vp8_initialize_enc(void)
-{
-    static volatile int init_done = 0;
-
-    if (!init_done) {
-        vpx_dsp_rtcd();
-        vp8_init_intra_predictors();
-        init_done = 1;
-    }
-}
-
-static void dealloc_compressor_data(VP8_COMP *cpi)
-{
-    vpx_free(cpi->tplist);
-    cpi->tplist = NULL;
-
-    /* Delete last frame MV storage buffers */
-    vpx_free(cpi->lfmv);
-    cpi->lfmv = 0;
-
-    vpx_free(cpi->lf_ref_frame_sign_bias);
-    cpi->lf_ref_frame_sign_bias = 0;
-
-    vpx_free(cpi->lf_ref_frame);
-    cpi->lf_ref_frame = 0;
-
-    /* Delete sementation map */
-    vpx_free(cpi->segmentation_map);
-    cpi->segmentation_map = 0;
-
-    vpx_free(cpi->active_map);
-    cpi->active_map = 0;
-
-    vp8_de_alloc_frame_buffers(&cpi->common);
-
-    vp8_yv12_de_alloc_frame_buffer(&cpi->pick_lf_lvl_frame);
-    vp8_yv12_de_alloc_frame_buffer(&cpi->scaled_source);
-    dealloc_raw_frame_buffers(cpi);
-
-    vpx_free(cpi->tok);
-    cpi->tok = 0;
-
-    /* Structure used to monitor GF usage */
-    vpx_free(cpi->gf_active_flags);
-    cpi->gf_active_flags = 0;
-
-    /* Activity mask based per mb zbin adjustments */
-    vpx_free(cpi->mb_activity_map);
-    cpi->mb_activity_map = 0;
-
-    vpx_free(cpi->mb.pip);
-    cpi->mb.pip = 0;
-
-#if CONFIG_MULTITHREAD
-    /* De-allocate mutex */
-    if (cpi->pmutex != NULL) {
-        VP8_COMMON *const pc = &cpi->common;
-        int i;
-
-        for (i = 0; i < pc->mb_rows; i++) {
-            pthread_mutex_destroy(&cpi->pmutex[i]);
-        }
-        vpx_free(cpi->pmutex);
-        cpi->pmutex = NULL;
-    }
-
-    vpx_free(cpi->mt_current_mb_col);
-    cpi->mt_current_mb_col = NULL;
-#endif
-}
-
-static void enable_segmentation(VP8_COMP *cpi)
-{
-    /* Set the appropriate feature bit */
-    cpi->mb.e_mbd.segmentation_enabled = 1;
-    cpi->mb.e_mbd.update_mb_segmentation_map = 1;
-    cpi->mb.e_mbd.update_mb_segmentation_data = 1;
-}
-static void disable_segmentation(VP8_COMP *cpi)
-{
-    /* Clear the appropriate feature bit */
-    cpi->mb.e_mbd.segmentation_enabled = 0;
-}
-
-/* Valid values for a segment are 0 to 3
- * Segmentation map is arrange as [Rows][Columns]
- */
-static void set_segmentation_map(VP8_COMP *cpi, unsigned char *segmentation_map)
-{
-    /* Copy in the new segmentation map */
-    memcpy(cpi->segmentation_map, segmentation_map, (cpi->common.mb_rows * cpi->common.mb_cols));
-
-    /* Signal that the map should be updated. */
-    cpi->mb.e_mbd.update_mb_segmentation_map = 1;
-    cpi->mb.e_mbd.update_mb_segmentation_data = 1;
-}
-
-/* The values given for each segment can be either deltas (from the default
- * value chosen for the frame) or absolute values.
- *
- * Valid range for abs values is:
- *    (0-127 for MB_LVL_ALT_Q), (0-63 for SEGMENT_ALT_LF)
- * Valid range for delta values are:
- *    (+/-127 for MB_LVL_ALT_Q), (+/-63 for SEGMENT_ALT_LF)
- *
- * abs_delta = SEGMENT_DELTADATA (deltas)
- * abs_delta = SEGMENT_ABSDATA (use the absolute values given).
- *
- */
-static void set_segment_data(VP8_COMP *cpi, signed char *feature_data, unsigned char abs_delta)
-{
-    cpi->mb.e_mbd.mb_segement_abs_delta = abs_delta;
-    memcpy(cpi->segment_feature_data, feature_data, sizeof(cpi->segment_feature_data));
-}
-
-
-/* A simple function to cyclically refresh the background at a lower Q */
-static void cyclic_background_refresh(VP8_COMP *cpi, int Q, int lf_adjustment)
-{
-    unsigned char *seg_map = cpi->segmentation_map;
-    signed char feature_data[MB_LVL_MAX][MAX_MB_SEGMENTS];
-    int i;
-    int block_count = cpi->cyclic_refresh_mode_max_mbs_perframe;
-    int mbs_in_frame = cpi->common.mb_rows * cpi->common.mb_cols;
-
-    cpi->cyclic_refresh_q = Q / 2;
-
-    if (cpi->oxcf.screen_content_mode) {
-      // Modify quality ramp-up based on Q. Above some Q level, increase the
-      // number of blocks to be refreshed, and reduce it below the thredhold.
-      // Turn-off under certain conditions (i.e., away from key frame, and if
-      // we are at good quality (low Q) and most of the blocks were skipped-encoded
-      // in previous frame.
-      int qp_thresh = (cpi->oxcf.screen_content_mode == 2) ? 80 : 100;
-      if (Q >= qp_thresh) {
-        cpi->cyclic_refresh_mode_max_mbs_perframe =
-            (cpi->common.mb_rows * cpi->common.mb_cols) / 10;
-      } else if (cpi->frames_since_key > 250 &&
-                 Q < 20 &&
-                 cpi->mb.skip_true_count > (int)(0.95 * mbs_in_frame)) {
-        cpi->cyclic_refresh_mode_max_mbs_perframe = 0;
-      } else {
-        cpi->cyclic_refresh_mode_max_mbs_perframe =
-            (cpi->common.mb_rows * cpi->common.mb_cols) / 20;
-      }
-      block_count = cpi->cyclic_refresh_mode_max_mbs_perframe;
-    }
-
-    // Set every macroblock to be eligible for update.
-    // For key frame this will reset seg map to 0.
-    memset(cpi->segmentation_map, 0, mbs_in_frame);
-
-    if (cpi->common.frame_type != KEY_FRAME && block_count > 0)
-    {
-        /* Cycle through the macro_block rows */
-        /* MB loop to set local segmentation map */
-        i = cpi->cyclic_refresh_mode_index;
-        assert(i < mbs_in_frame);
-        do
-        {
-          /* If the MB is as a candidate for clean up then mark it for
-           * possible boost/refresh (segment 1) The segment id may get
-           * reset to 0 later if the MB gets coded anything other than
-           * last frame 0,0 as only (last frame 0,0) MBs are eligable for
-           * refresh : that is to say Mbs likely to be background blocks.
-           */
-          if (cpi->cyclic_refresh_map[i] == 0)
-          {
-              seg_map[i] = 1;
-              block_count --;
-          }
-          else if (cpi->cyclic_refresh_map[i] < 0)
-              cpi->cyclic_refresh_map[i]++;
-
-          i++;
-          if (i == mbs_in_frame)
-              i = 0;
-
-        }
-        while(block_count && i != cpi->cyclic_refresh_mode_index);
-
-        cpi->cyclic_refresh_mode_index = i;
-
-#if CONFIG_TEMPORAL_DENOISING
-        if (cpi->oxcf.noise_sensitivity > 0) {
-          if (cpi->denoiser.denoiser_mode == kDenoiserOnYUVAggressive &&
-              Q < (int)cpi->denoiser.denoise_pars.qp_thresh &&
-              (cpi->frames_since_key >
-               2 * cpi->denoiser.denoise_pars.consec_zerolast)) {
-            // Under aggressive denoising, use segmentation to turn off loop
-            // filter below some qp thresh. The filter is reduced for all
-            // blocks that have been encoded as ZEROMV LAST x frames in a row,
-            // where x is set by cpi->denoiser.denoise_pars.consec_zerolast.
-            // This is to avoid "dot" artifacts that can occur from repeated
-            // loop filtering on noisy input source.
-            cpi->cyclic_refresh_q = Q;
-            // lf_adjustment = -MAX_LOOP_FILTER;
-            lf_adjustment = -40;
-            for (i = 0; i < mbs_in_frame; ++i) {
-              seg_map[i] = (cpi->consec_zero_last[i] >
-                            cpi->denoiser.denoise_pars.consec_zerolast) ? 1 : 0;
-            }
-          }
-        }
-#endif
-    }
-
-    /* Activate segmentation. */
-    cpi->mb.e_mbd.update_mb_segmentation_map = 1;
-    cpi->mb.e_mbd.update_mb_segmentation_data = 1;
-    enable_segmentation(cpi);
-
-    /* Set up the quant segment data */
-    feature_data[MB_LVL_ALT_Q][0] = 0;
-    feature_data[MB_LVL_ALT_Q][1] = (cpi->cyclic_refresh_q - Q);
-    feature_data[MB_LVL_ALT_Q][2] = 0;
-    feature_data[MB_LVL_ALT_Q][3] = 0;
-
-    /* Set up the loop segment data */
-    feature_data[MB_LVL_ALT_LF][0] = 0;
-    feature_data[MB_LVL_ALT_LF][1] = lf_adjustment;
-    feature_data[MB_LVL_ALT_LF][2] = 0;
-    feature_data[MB_LVL_ALT_LF][3] = 0;
-
-    /* Initialise the feature data structure */
-    set_segment_data(cpi, &feature_data[0][0], SEGMENT_DELTADATA);
-
-}
-
-static void set_default_lf_deltas(VP8_COMP *cpi)
-{
-    cpi->mb.e_mbd.mode_ref_lf_delta_enabled = 1;
-    cpi->mb.e_mbd.mode_ref_lf_delta_update = 1;
-
-    memset(cpi->mb.e_mbd.ref_lf_deltas, 0, sizeof(cpi->mb.e_mbd.ref_lf_deltas));
-    memset(cpi->mb.e_mbd.mode_lf_deltas, 0, sizeof(cpi->mb.e_mbd.mode_lf_deltas));
-
-    /* Test of ref frame deltas */
-    cpi->mb.e_mbd.ref_lf_deltas[INTRA_FRAME] = 2;
-    cpi->mb.e_mbd.ref_lf_deltas[LAST_FRAME] = 0;
-    cpi->mb.e_mbd.ref_lf_deltas[GOLDEN_FRAME] = -2;
-    cpi->mb.e_mbd.ref_lf_deltas[ALTREF_FRAME] = -2;
-
-    cpi->mb.e_mbd.mode_lf_deltas[0] = 4;               /* BPRED */
-
-    if(cpi->oxcf.Mode == MODE_REALTIME)
-      cpi->mb.e_mbd.mode_lf_deltas[1] = -12;              /* Zero */
-    else
-      cpi->mb.e_mbd.mode_lf_deltas[1] = -2;              /* Zero */
-
-    cpi->mb.e_mbd.mode_lf_deltas[2] = 2;               /* New mv */
-    cpi->mb.e_mbd.mode_lf_deltas[3] = 4;               /* Split mv */
-}
-
-/* Convenience macros for mapping speed and mode into a continuous
- * range
- */
-#define GOOD(x) (x+1)
-#define RT(x) (x+7)
-
-static int speed_map(int speed, const int *map)
-{
-    int res;
-
-    do
-    {
-        res = *map++;
-    } while(speed >= *map++);
-    return res;
-}
-
-static const int thresh_mult_map_znn[] = {
-    /* map common to zero, nearest, and near */
-    0, GOOD(2), 1500, GOOD(3), 2000, RT(0), 1000, RT(2), 2000, INT_MAX
-};
-
-static const int thresh_mult_map_vhpred[] = {
-    1000, GOOD(2), 1500, GOOD(3), 2000, RT(0), 1000, RT(1), 2000,
-    RT(7), INT_MAX, INT_MAX
-};
-
-static const int thresh_mult_map_bpred[] = {
-    2000, GOOD(0), 2500, GOOD(2), 5000, GOOD(3), 7500, RT(0), 2500, RT(1), 5000,
-    RT(6), INT_MAX, INT_MAX
-};
-
-static const int thresh_mult_map_tm[] = {
-    1000, GOOD(2), 1500, GOOD(3), 2000, RT(0), 0, RT(1), 1000, RT(2), 2000,
-    RT(7), INT_MAX, INT_MAX
-};
-
-static const int thresh_mult_map_new1[] = {
-    1000, GOOD(2), 2000, RT(0), 2000, INT_MAX
-};
-
-static const int thresh_mult_map_new2[] = {
-    1000, GOOD(2), 2000, GOOD(3), 2500, GOOD(5), 4000, RT(0), 2000, RT(2), 2500,
-    RT(5), 4000, INT_MAX
-};
-
-static const int thresh_mult_map_split1[] = {
-    2500, GOOD(0), 1700, GOOD(2), 10000, GOOD(3), 25000, GOOD(4), INT_MAX,
-    RT(0), 5000, RT(1), 10000, RT(2), 25000, RT(3), INT_MAX, INT_MAX
-};
-
-static const int thresh_mult_map_split2[] = {
-    5000, GOOD(0), 4500, GOOD(2), 20000, GOOD(3), 50000, GOOD(4), INT_MAX,
-    RT(0), 10000, RT(1), 20000, RT(2), 50000, RT(3), INT_MAX, INT_MAX
-};
-
-static const int mode_check_freq_map_zn2[] = {
-    /* {zero,nearest}{2,3} */
-    0, RT(10), 1<<1, RT(11), 1<<2, RT(12), 1<<3, INT_MAX
-};
-
-static const int mode_check_freq_map_vhbpred[] = {
-    0, GOOD(5), 2, RT(0), 0, RT(3), 2, RT(5), 4, INT_MAX
-};
-
-static const int mode_check_freq_map_near2[] = {
-    0, GOOD(5), 2, RT(0), 0, RT(3), 2, RT(10), 1<<2, RT(11), 1<<3, RT(12), 1<<4,
-    INT_MAX
-};
-
-static const int mode_check_freq_map_new1[] = {
-    0, RT(10), 1<<1, RT(11), 1<<2, RT(12), 1<<3, INT_MAX
-};
-
-static const int mode_check_freq_map_new2[] = {
-    0, GOOD(5), 4, RT(0), 0, RT(3), 4, RT(10), 1<<3, RT(11), 1<<4, RT(12), 1<<5,
-    INT_MAX
-};
-
-static const int mode_check_freq_map_split1[] = {
-    0, GOOD(2), 2, GOOD(3), 7, RT(1), 2, RT(2), 7, INT_MAX
-};
-
-static const int mode_check_freq_map_split2[] = {
-    0, GOOD(1), 2, GOOD(2), 4, GOOD(3), 15, RT(1), 4, RT(2), 15, INT_MAX
-};
-
-void vp8_set_speed_features(VP8_COMP *cpi)
-{
-    SPEED_FEATURES *sf = &cpi->sf;
-    int Mode = cpi->compressor_speed;
-    int Speed = cpi->Speed;
-    int i;
-    VP8_COMMON *cm = &cpi->common;
-    int last_improved_quant = sf->improved_quant;
-    int ref_frames;
-
-    /* Initialise default mode frequency sampling variables */
-    for (i = 0; i < MAX_MODES; i ++)
-    {
-        cpi->mode_check_freq[i] = 0;
-    }
-
-    cpi->mb.mbs_tested_so_far = 0;
-    cpi->mb.mbs_zero_last_dot_suppress = 0;
-
-    /* best quality defaults */
-    sf->RD = 1;
-    sf->search_method = NSTEP;
-    sf->improved_quant = 1;
-    sf->improved_dct = 1;
-    sf->auto_filter = 1;
-    sf->recode_loop = 1;
-    sf->quarter_pixel_search = 1;
-    sf->half_pixel_search = 1;
-    sf->iterative_sub_pixel = 1;
-    sf->optimize_coefficients = 1;
-    sf->use_fastquant_for_pick = 0;
-    sf->no_skip_block4x4_search = 1;
-
-    sf->first_step = 0;
-    sf->max_step_search_steps = MAX_MVSEARCH_STEPS;
-    sf->improved_mv_pred = 1;
-
-    /* default thresholds to 0 */
-    for (i = 0; i < MAX_MODES; i++)
-        sf->thresh_mult[i] = 0;
-
-    /* Count enabled references */
-    ref_frames = 1;
-    if (cpi->ref_frame_flags & VP8_LAST_FRAME)
-        ref_frames++;
-    if (cpi->ref_frame_flags & VP8_GOLD_FRAME)
-        ref_frames++;
-    if (cpi->ref_frame_flags & VP8_ALTR_FRAME)
-        ref_frames++;
-
-    /* Convert speed to continuous range, with clamping */
-    if (Mode == 0)
-        Speed = 0;
-    else if (Mode == 2)
-        Speed = RT(Speed);
-    else
-    {
-        if (Speed > 5)
-            Speed = 5;
-        Speed = GOOD(Speed);
-    }
-
-    sf->thresh_mult[THR_ZERO1] =
-    sf->thresh_mult[THR_NEAREST1] =
-    sf->thresh_mult[THR_NEAR1] =
-    sf->thresh_mult[THR_DC] = 0; /* always */
-
-    sf->thresh_mult[THR_ZERO2] =
-    sf->thresh_mult[THR_ZERO3] =
-    sf->thresh_mult[THR_NEAREST2] =
-    sf->thresh_mult[THR_NEAREST3] =
-    sf->thresh_mult[THR_NEAR2]  =
-    sf->thresh_mult[THR_NEAR3]  = speed_map(Speed, thresh_mult_map_znn);
-
-    sf->thresh_mult[THR_V_PRED] =
-    sf->thresh_mult[THR_H_PRED] = speed_map(Speed, thresh_mult_map_vhpred);
-    sf->thresh_mult[THR_B_PRED] = speed_map(Speed, thresh_mult_map_bpred);
-    sf->thresh_mult[THR_TM]     = speed_map(Speed, thresh_mult_map_tm);
-    sf->thresh_mult[THR_NEW1]   = speed_map(Speed, thresh_mult_map_new1);
-    sf->thresh_mult[THR_NEW2]   =
-    sf->thresh_mult[THR_NEW3]   = speed_map(Speed, thresh_mult_map_new2);
-    sf->thresh_mult[THR_SPLIT1] = speed_map(Speed, thresh_mult_map_split1);
-    sf->thresh_mult[THR_SPLIT2] =
-    sf->thresh_mult[THR_SPLIT3] = speed_map(Speed, thresh_mult_map_split2);
-
-    // Special case for temporal layers.
-    // Reduce the thresholds for zero/nearest/near for GOLDEN, if GOLDEN is
-    // used as second reference. We don't modify thresholds for ALTREF case
-    // since ALTREF is usually used as long-term reference in temporal layers.
-    if ((cpi->Speed <= 6) &&
-        (cpi->oxcf.number_of_layers > 1) &&
-        (cpi->ref_frame_flags & VP8_LAST_FRAME) &&
-        (cpi->ref_frame_flags & VP8_GOLD_FRAME)) {
-      if (cpi->closest_reference_frame == GOLDEN_FRAME) {
-        sf->thresh_mult[THR_ZERO2] =  sf->thresh_mult[THR_ZERO2] >> 3;
-        sf->thresh_mult[THR_NEAREST2] = sf->thresh_mult[THR_NEAREST2] >> 3;
-        sf->thresh_mult[THR_NEAR2]  = sf->thresh_mult[THR_NEAR2] >> 3;
-      } else {
-        sf->thresh_mult[THR_ZERO2] =  sf->thresh_mult[THR_ZERO2] >> 1;
-        sf->thresh_mult[THR_NEAREST2] = sf->thresh_mult[THR_NEAREST2] >> 1;
-        sf->thresh_mult[THR_NEAR2]  = sf->thresh_mult[THR_NEAR2] >> 1;
-      }
-    }
-
-    cpi->mode_check_freq[THR_ZERO1] =
-    cpi->mode_check_freq[THR_NEAREST1] =
-    cpi->mode_check_freq[THR_NEAR1] =
-    cpi->mode_check_freq[THR_TM]     =
-    cpi->mode_check_freq[THR_DC] = 0; /* always */
-
-    cpi->mode_check_freq[THR_ZERO2] =
-    cpi->mode_check_freq[THR_ZERO3] =
-    cpi->mode_check_freq[THR_NEAREST2] =
-    cpi->mode_check_freq[THR_NEAREST3] = speed_map(Speed,
-                                                   mode_check_freq_map_zn2);
-
-    cpi->mode_check_freq[THR_NEAR2]  =
-    cpi->mode_check_freq[THR_NEAR3]  = speed_map(Speed,
-                                                 mode_check_freq_map_near2);
-
-    cpi->mode_check_freq[THR_V_PRED] =
-    cpi->mode_check_freq[THR_H_PRED] =
-    cpi->mode_check_freq[THR_B_PRED] = speed_map(Speed,
-                                                 mode_check_freq_map_vhbpred);
-    cpi->mode_check_freq[THR_NEW1]   = speed_map(Speed,
-                                                 mode_check_freq_map_new1);
-    cpi->mode_check_freq[THR_NEW2]   =
-    cpi->mode_check_freq[THR_NEW3]   = speed_map(Speed,
-                                                 mode_check_freq_map_new2);
-    cpi->mode_check_freq[THR_SPLIT1] = speed_map(Speed,
-                                                 mode_check_freq_map_split1);
-    cpi->mode_check_freq[THR_SPLIT2] =
-    cpi->mode_check_freq[THR_SPLIT3] = speed_map(Speed,
-                                                 mode_check_freq_map_split2);
-    Speed = cpi->Speed;
-    switch (Mode)
-    {
-#if !CONFIG_REALTIME_ONLY
-    case 0: /* best quality mode */
-        sf->first_step = 0;
-        sf->max_step_search_steps = MAX_MVSEARCH_STEPS;
-        break;
-    case 1:
-    case 3:
-        if (Speed > 0)
-        {
-            /* Disable coefficient optimization above speed 0 */
-            sf->optimize_coefficients = 0;
-            sf->use_fastquant_for_pick = 1;
-            sf->no_skip_block4x4_search = 0;
-
-            sf->first_step = 1;
-        }
-
-        if (Speed > 2)
-        {
-            sf->improved_quant = 0;
-            sf->improved_dct = 0;
-
-            /* Only do recode loop on key frames, golden frames and
-             * alt ref frames
-             */
-            sf->recode_loop = 2;
-
-        }
-
-        if (Speed > 3)
-        {
-            sf->auto_filter = 1;
-            sf->recode_loop = 0; /* recode loop off */
-            sf->RD = 0;         /* Turn rd off */
-
-        }
-
-        if (Speed > 4)
-        {
-            sf->auto_filter = 0;  /* Faster selection of loop filter */
-        }
-
-        break;
-#endif
-    case 2:
-        sf->optimize_coefficients = 0;
-        sf->recode_loop = 0;
-        sf->auto_filter = 1;
-        sf->iterative_sub_pixel = 1;
-        sf->search_method = NSTEP;
-
-        if (Speed > 0)
-        {
-            sf->improved_quant = 0;
-            sf->improved_dct = 0;
-
-            sf->use_fastquant_for_pick = 1;
-            sf->no_skip_block4x4_search = 0;
-            sf->first_step = 1;
-        }
-
-        if (Speed > 2)
-            sf->auto_filter = 0;  /* Faster selection of loop filter */
-
-        if (Speed > 3)
-        {
-            sf->RD = 0;
-            sf->auto_filter = 1;
-        }
-
-        if (Speed > 4)
-        {
-            sf->auto_filter = 0;  /* Faster selection of loop filter */
-            sf->search_method = HEX;
-            sf->iterative_sub_pixel = 0;
-        }
-
-        if (Speed > 6)
-        {
-            unsigned int sum = 0;
-            unsigned int total_mbs = cm->MBs;
-            int thresh;
-            unsigned int total_skip;
-
-            int min = 2000;
-
-            if (cpi->oxcf.encode_breakout > 2000)
-                min = cpi->oxcf.encode_breakout;
-
-            min >>= 7;
-
-            for (i = 0; i < min; i++)
-            {
-                sum += cpi->mb.error_bins[i];
-            }
-
-            total_skip = sum;
-            sum = 0;
-
-            /* i starts from 2 to make sure thresh started from 2048 */
-            for (; i < 1024; i++)
-            {
-                sum += cpi->mb.error_bins[i];
-
-                if (10 * sum >= (unsigned int)(cpi->Speed - 6)*(total_mbs - total_skip))
-                    break;
-            }
-
-            i--;
-            thresh = (i << 7);
-
-            if (thresh < 2000)
-                thresh = 2000;
-
-            if (ref_frames > 1)
-            {
-                sf->thresh_mult[THR_NEW1 ] = thresh;
-                sf->thresh_mult[THR_NEAREST1  ] = thresh >> 1;
-                sf->thresh_mult[THR_NEAR1     ] = thresh >> 1;
-            }
-
-            if (ref_frames > 2)
-            {
-                sf->thresh_mult[THR_NEW2] = thresh << 1;
-                sf->thresh_mult[THR_NEAREST2 ] = thresh;
-                sf->thresh_mult[THR_NEAR2    ] = thresh;
-            }
-
-            if (ref_frames > 3)
-            {
-                sf->thresh_mult[THR_NEW3] = thresh << 1;
-                sf->thresh_mult[THR_NEAREST3 ] = thresh;
-                sf->thresh_mult[THR_NEAR3    ] = thresh;
-            }
-
-            sf->improved_mv_pred = 0;
-        }
-
-        if (Speed > 8)
-            sf->quarter_pixel_search = 0;
-
-        if(cm->version == 0)
-        {
-            cm->filter_type = NORMAL_LOOPFILTER;
-
-            if (Speed >= 14)
-                cm->filter_type = SIMPLE_LOOPFILTER;
-        }
-        else
-        {
-            cm->filter_type = SIMPLE_LOOPFILTER;
-        }
-
-        /* This has a big hit on quality. Last resort */
-        if (Speed >= 15)
-            sf->half_pixel_search = 0;
-
-        memset(cpi->mb.error_bins, 0, sizeof(cpi->mb.error_bins));
-
-    }; /* switch */
-
-    /* Slow quant, dct and trellis not worthwhile for first pass
-     * so make sure they are always turned off.
-     */
-    if ( cpi->pass == 1 )
-    {
-        sf->improved_quant = 0;
-        sf->optimize_coefficients = 0;
-        sf->improved_dct = 0;
-    }
-
-    if (cpi->sf.search_method == NSTEP)
-    {
-        vp8_init3smotion_compensation(&cpi->mb, cm->yv12_fb[cm->lst_fb_idx].y_stride);
-    }
-    else if (cpi->sf.search_method == DIAMOND)
-    {
-        vp8_init_dsmotion_compensation(&cpi->mb, cm->yv12_fb[cm->lst_fb_idx].y_stride);
-    }
-
-    if (cpi->sf.improved_dct)
-    {
-        cpi->mb.short_fdct8x4 = vp8_short_fdct8x4;
-        cpi->mb.short_fdct4x4 = vp8_short_fdct4x4;
-    }
-    else
-    {
-        /* No fast FDCT defined for any platform at this time. */
-        cpi->mb.short_fdct8x4 = vp8_short_fdct8x4;
-        cpi->mb.short_fdct4x4 = vp8_short_fdct4x4;
-    }
-
-    cpi->mb.short_walsh4x4 = vp8_short_walsh4x4;
-
-    if (cpi->sf.improved_quant)
-    {
-        cpi->mb.quantize_b      = vp8_regular_quantize_b;
-    }
-    else
-    {
-        cpi->mb.quantize_b      = vp8_fast_quantize_b;
-    }
-    if (cpi->sf.improved_quant != last_improved_quant)
-        vp8cx_init_quantizer(cpi);
-
-    if (cpi->sf.iterative_sub_pixel == 1)
-    {
-        cpi->find_fractional_mv_step = vp8_find_best_sub_pixel_step_iteratively;
-    }
-    else if (cpi->sf.quarter_pixel_search)
-    {
-        cpi->find_fractional_mv_step = vp8_find_best_sub_pixel_step;
-    }
-    else if (cpi->sf.half_pixel_search)
-    {
-        cpi->find_fractional_mv_step = vp8_find_best_half_pixel_step;
-    }
-    else
-    {
-        cpi->find_fractional_mv_step = vp8_skip_fractional_mv_step;
-    }
-
-    if (cpi->sf.optimize_coefficients == 1 && cpi->pass!=1)
-        cpi->mb.optimize = 1;
-    else
-        cpi->mb.optimize = 0;
-
-    if (cpi->common.full_pixel)
-        cpi->find_fractional_mv_step = vp8_skip_fractional_mv_step;
-
-#ifdef SPEEDSTATS
-    frames_at_speed[cpi->Speed]++;
-#endif
-}
-#undef GOOD
-#undef RT
-
-static void alloc_raw_frame_buffers(VP8_COMP *cpi)
-{
-#if VP8_TEMPORAL_ALT_REF
-    int width = (cpi->oxcf.Width + 15) & ~15;
-    int height = (cpi->oxcf.Height + 15) & ~15;
-#endif
-
-    cpi->lookahead = vp8_lookahead_init(cpi->oxcf.Width, cpi->oxcf.Height,
-                                        cpi->oxcf.lag_in_frames);
-    if(!cpi->lookahead)
-        vpx_internal_error(&cpi->common.error, VPX_CODEC_MEM_ERROR,
-                           "Failed to allocate lag buffers");
-
-#if VP8_TEMPORAL_ALT_REF
-
-    if (vp8_yv12_alloc_frame_buffer(&cpi->alt_ref_buffer,
-                                    width, height, VP8BORDERINPIXELS))
-        vpx_internal_error(&cpi->common.error, VPX_CODEC_MEM_ERROR,
-                           "Failed to allocate altref buffer");
-
-#endif
-}
-
-
-static void dealloc_raw_frame_buffers(VP8_COMP *cpi)
-{
-#if VP8_TEMPORAL_ALT_REF
-    vp8_yv12_de_alloc_frame_buffer(&cpi->alt_ref_buffer);
-#endif
-    vp8_lookahead_destroy(cpi->lookahead);
-}
-
-
-static int vp8_alloc_partition_data(VP8_COMP *cpi)
-{
-        vpx_free(cpi->mb.pip);
-
-    cpi->mb.pip = vpx_calloc((cpi->common.mb_cols + 1) *
-                                (cpi->common.mb_rows + 1),
-                                sizeof(PARTITION_INFO));
-    if(!cpi->mb.pip)
-        return 1;
-
-    cpi->mb.pi = cpi->mb.pip + cpi->common.mode_info_stride + 1;
-
-    return 0;
-}
-
-void vp8_alloc_compressor_data(VP8_COMP *cpi)
-{
-    VP8_COMMON *cm = & cpi->common;
-
-    int width = cm->Width;
-    int height = cm->Height;
-#if CONFIG_MULTITHREAD
-    int prev_mb_rows = cm->mb_rows;
-#endif
-
-    if (vp8_alloc_frame_buffers(cm, width, height))
-        vpx_internal_error(&cpi->common.error, VPX_CODEC_MEM_ERROR,
-                           "Failed to allocate frame buffers");
-
-    if (vp8_alloc_partition_data(cpi))
-        vpx_internal_error(&cpi->common.error, VPX_CODEC_MEM_ERROR,
-                           "Failed to allocate partition data");
-
-
-    if ((width & 0xf) != 0)
-        width += 16 - (width & 0xf);
-
-    if ((height & 0xf) != 0)
-        height += 16 - (height & 0xf);
-
-
-    if (vp8_yv12_alloc_frame_buffer(&cpi->pick_lf_lvl_frame,
-                                    width, height, VP8BORDERINPIXELS))
-        vpx_internal_error(&cpi->common.error, VPX_CODEC_MEM_ERROR,
-                           "Failed to allocate last frame buffer");
-
-    if (vp8_yv12_alloc_frame_buffer(&cpi->scaled_source,
-                                    width, height, VP8BORDERINPIXELS))
-        vpx_internal_error(&cpi->common.error, VPX_CODEC_MEM_ERROR,
-                           "Failed to allocate scaled source buffer");
-
-    vpx_free(cpi->tok);
-
-    {
-#if CONFIG_REALTIME_ONLY & CONFIG_ONTHEFLY_BITPACKING
-        unsigned int tokens = 8 * 24 * 16; /* one MB for each thread */
-#else
-        unsigned int tokens = cm->mb_rows * cm->mb_cols * 24 * 16;
-#endif
-        CHECK_MEM_ERROR(cpi->tok, vpx_calloc(tokens, sizeof(*cpi->tok)));
-    }
-
-    /* Data used for real time vc mode to see if gf needs refreshing */
-    cpi->zeromv_count = 0;
-
-
-    /* Structures used to monitor GF usage */
-    vpx_free(cpi->gf_active_flags);
-    CHECK_MEM_ERROR(cpi->gf_active_flags,
-                    vpx_calloc(sizeof(*cpi->gf_active_flags),
-                    cm->mb_rows * cm->mb_cols));
-    cpi->gf_active_count = cm->mb_rows * cm->mb_cols;
-
-    vpx_free(cpi->mb_activity_map);
-    CHECK_MEM_ERROR(cpi->mb_activity_map,
-                    vpx_calloc(sizeof(*cpi->mb_activity_map),
-                    cm->mb_rows * cm->mb_cols));
-
-    /* allocate memory for storing last frame's MVs for MV prediction. */
-    vpx_free(cpi->lfmv);
-    CHECK_MEM_ERROR(cpi->lfmv, vpx_calloc((cm->mb_rows+2) * (cm->mb_cols+2),
-                    sizeof(*cpi->lfmv)));
-    vpx_free(cpi->lf_ref_frame_sign_bias);
-    CHECK_MEM_ERROR(cpi->lf_ref_frame_sign_bias,
-                    vpx_calloc((cm->mb_rows+2) * (cm->mb_cols+2),
-                    sizeof(*cpi->lf_ref_frame_sign_bias)));
-    vpx_free(cpi->lf_ref_frame);
-    CHECK_MEM_ERROR(cpi->lf_ref_frame,
-                    vpx_calloc((cm->mb_rows+2) * (cm->mb_cols+2),
-                    sizeof(*cpi->lf_ref_frame)));
-
-    /* Create the encoder segmentation map and set all entries to 0 */
-    vpx_free(cpi->segmentation_map);
-    CHECK_MEM_ERROR(cpi->segmentation_map,
-                    vpx_calloc(cm->mb_rows * cm->mb_cols,
-                    sizeof(*cpi->segmentation_map)));
-    cpi->cyclic_refresh_mode_index = 0;
-    vpx_free(cpi->active_map);
-    CHECK_MEM_ERROR(cpi->active_map,
-                    vpx_calloc(cm->mb_rows * cm->mb_cols,
-                    sizeof(*cpi->active_map)));
-    memset(cpi->active_map , 1, (cm->mb_rows * cm->mb_cols));
-
-#if CONFIG_MULTITHREAD
-    if (width < 640)
-        cpi->mt_sync_range = 1;
-    else if (width <= 1280)
-        cpi->mt_sync_range = 4;
-    else if (width <= 2560)
-        cpi->mt_sync_range = 8;
-    else
-        cpi->mt_sync_range = 16;
-
-    if (cpi->oxcf.multi_threaded > 1)
-    {
-        int i;
-
-        /* De-allocate and re-allocate mutex */
-        if (cpi->pmutex != NULL) {
-            for (i = 0; i < prev_mb_rows; i++) {
-                pthread_mutex_destroy(&cpi->pmutex[i]);
-            }
-            vpx_free(cpi->pmutex);
-            cpi->pmutex = NULL;
-        }
-
-        CHECK_MEM_ERROR(cpi->pmutex, vpx_malloc(sizeof(*cpi->pmutex) *
-                                                cm->mb_rows));
-        if (cpi->pmutex) {
-            for (i = 0; i < cm->mb_rows; i++) {
-                pthread_mutex_init(&cpi->pmutex[i], NULL);
-            }
-        }
-
-        vpx_free(cpi->mt_current_mb_col);
-        CHECK_MEM_ERROR(cpi->mt_current_mb_col,
-                    vpx_malloc(sizeof(*cpi->mt_current_mb_col) * cm->mb_rows));
-    }
-
-#endif
-
-    vpx_free(cpi->tplist);
-    CHECK_MEM_ERROR(cpi->tplist, vpx_malloc(sizeof(TOKENLIST) * cm->mb_rows));
-
-#if CONFIG_TEMPORAL_DENOISING
-    if (cpi->oxcf.noise_sensitivity > 0) {
-      vp8_denoiser_free(&cpi->denoiser);
-      if (vp8_denoiser_allocate(&cpi->denoiser, width, height,
-                                cm->mb_rows, cm->mb_cols,
-                                cpi->oxcf.noise_sensitivity))
-          vpx_internal_error(&cpi->common.error, VPX_CODEC_MEM_ERROR,
-                             "Failed to allocate denoiser");
-    }
-#endif
-}
-
-
-/* Quant MOD */
-static const int q_trans[] =
-{
-    0,   1,  2,  3,  4,  5,  7,  8,
-    9,  10, 12, 13, 15, 17, 18, 19,
-    20,  21, 23, 24, 25, 26, 27, 28,
-    29,  30, 31, 33, 35, 37, 39, 41,
-    43,  45, 47, 49, 51, 53, 55, 57,
-    59,  61, 64, 67, 70, 73, 76, 79,
-    82,  85, 88, 91, 94, 97, 100, 103,
-    106, 109, 112, 115, 118, 121, 124, 127,
-};
-
-int vp8_reverse_trans(int x)
-{
-    int i;
-
-    for (i = 0; i < 64; i++)
-        if (q_trans[i] >= x)
-            return i;
-
-    return 63;
-}
-void vp8_new_framerate(VP8_COMP *cpi, double framerate)
-{
-    if(framerate < .1)
-        framerate = 30;
-
-    cpi->framerate              = framerate;
-    cpi->output_framerate       = framerate;
-    cpi->per_frame_bandwidth    = (int)(cpi->oxcf.target_bandwidth /
-                                  cpi->output_framerate);
-    cpi->av_per_frame_bandwidth = cpi->per_frame_bandwidth;
-    cpi->min_frame_bandwidth    = (int)(cpi->av_per_frame_bandwidth *
-                                  cpi->oxcf.two_pass_vbrmin_section / 100);
-
-    /* Set Maximum gf/arf interval */
-    cpi->max_gf_interval = ((int)(cpi->output_framerate / 2.0) + 2);
-
-    if(cpi->max_gf_interval < 12)
-        cpi->max_gf_interval = 12;
-
-    /* Extended interval for genuinely static scenes */
-    cpi->twopass.static_scene_max_gf_interval = cpi->key_frame_frequency >> 1;
-
-     /* Special conditions when altr ref frame enabled in lagged compress mode */
-    if (cpi->oxcf.play_alternate && cpi->oxcf.lag_in_frames)
-    {
-        if (cpi->max_gf_interval > cpi->oxcf.lag_in_frames - 1)
-            cpi->max_gf_interval = cpi->oxcf.lag_in_frames - 1;
-
-        if (cpi->twopass.static_scene_max_gf_interval > cpi->oxcf.lag_in_frames - 1)
-            cpi->twopass.static_scene_max_gf_interval = cpi->oxcf.lag_in_frames - 1;
-    }
-
-    if ( cpi->max_gf_interval > cpi->twopass.static_scene_max_gf_interval )
-        cpi->max_gf_interval = cpi->twopass.static_scene_max_gf_interval;
-}
-
-
-static void init_config(VP8_COMP *cpi, VP8_CONFIG *oxcf)
-{
-    VP8_COMMON *cm = &cpi->common;
-
-    cpi->oxcf = *oxcf;
-
-    cpi->auto_gold = 1;
-    cpi->auto_adjust_gold_quantizer = 1;
-
-    cm->version = oxcf->Version;
-    vp8_setup_version(cm);
-
-    /* Frame rate is not available on the first frame, as it's derived from
-     * the observed timestamps. The actual value used here doesn't matter
-     * too much, as it will adapt quickly.
-     */
-    if (oxcf->timebase.num > 0) {
-      cpi->framerate = (double)(oxcf->timebase.den) /
-                       (double)(oxcf->timebase.num);
-    } else {
-      cpi->framerate = 30;
-    }
-
-    /* If the reciprocal of the timebase seems like a reasonable framerate,
-     * then use that as a guess, otherwise use 30.
-     */
-    if (cpi->framerate > 180)
-        cpi->framerate = 30;
-
-    cpi->ref_framerate = cpi->framerate;
-
-    cpi->ref_frame_flags = VP8_ALTR_FRAME | VP8_GOLD_FRAME | VP8_LAST_FRAME;
-
-    cm->refresh_golden_frame = 0;
-    cm->refresh_last_frame = 1;
-    cm->refresh_entropy_probs = 1;
-
-    /* change includes all joint functionality */
-    vp8_change_config(cpi, oxcf);
-
-    /* Initialize active best and worst q and average q values. */
-    cpi->active_worst_quality         = cpi->oxcf.worst_allowed_q;
-    cpi->active_best_quality          = cpi->oxcf.best_allowed_q;
-    cpi->avg_frame_qindex             = cpi->oxcf.worst_allowed_q;
-
-    /* Initialise the starting buffer levels */
-    cpi->buffer_level                 = cpi->oxcf.starting_buffer_level;
-    cpi->bits_off_target              = cpi->oxcf.starting_buffer_level;
-
-    cpi->rolling_target_bits          = cpi->av_per_frame_bandwidth;
-    cpi->rolling_actual_bits          = cpi->av_per_frame_bandwidth;
-    cpi->long_rolling_target_bits     = cpi->av_per_frame_bandwidth;
-    cpi->long_rolling_actual_bits     = cpi->av_per_frame_bandwidth;
-
-    cpi->total_actual_bits            = 0;
-    cpi->total_target_vs_actual       = 0;
-
-    /* Temporal scalabilty */
-    if (cpi->oxcf.number_of_layers > 1)
-    {
-        unsigned int i;
-        double prev_layer_framerate=0;
-
-        for (i=0; i<cpi->oxcf.number_of_layers; i++)
-        {
-            init_temporal_layer_context(cpi, oxcf, i, prev_layer_framerate);
-            prev_layer_framerate = cpi->output_framerate /
-                                   cpi->oxcf.rate_decimator[i];
-        }
-    }
-
-#if VP8_TEMPORAL_ALT_REF
-    {
-        int i;
-
-        cpi->fixed_divide[0] = 0;
-
-        for (i = 1; i < 512; i++)
-            cpi->fixed_divide[i] = 0x80000 / i;
-    }
-#endif
-}
-
-static void update_layer_contexts (VP8_COMP *cpi)
-{
-    VP8_CONFIG *oxcf = &cpi->oxcf;
-
-    /* Update snapshots of the layer contexts to reflect new parameters */
-    if (oxcf->number_of_layers > 1)
-    {
-        unsigned int i;
-        double prev_layer_framerate=0;
-
-        assert(oxcf->number_of_layers <= VPX_TS_MAX_LAYERS);
-        for (i = 0; i < oxcf->number_of_layers && i < VPX_TS_MAX_LAYERS; ++i)
-        {
-            LAYER_CONTEXT *lc = &cpi->layer_context[i];
-
-            lc->framerate =
-                cpi->ref_framerate / oxcf->rate_decimator[i];
-            lc->target_bandwidth = oxcf->target_bitrate[i] * 1000;
-
-            lc->starting_buffer_level = rescale(
-                          (int)oxcf->starting_buffer_level_in_ms,
-                          lc->target_bandwidth, 1000);
-
-            if (oxcf->optimal_buffer_level == 0)
-                lc->optimal_buffer_level = lc->target_bandwidth / 8;
-            else
-                lc->optimal_buffer_level = rescale(
-                          (int)oxcf->optimal_buffer_level_in_ms,
-                          lc->target_bandwidth, 1000);
-
-            if (oxcf->maximum_buffer_size == 0)
-                lc->maximum_buffer_size = lc->target_bandwidth / 8;
-            else
-                lc->maximum_buffer_size = rescale(
-                          (int)oxcf->maximum_buffer_size_in_ms,
-                          lc->target_bandwidth, 1000);
-
-            /* Work out the average size of a frame within this layer */
-            if (i > 0)
-                lc->avg_frame_size_for_layer =
-                   (int)((oxcf->target_bitrate[i] -
-                          oxcf->target_bitrate[i-1]) * 1000 /
-                          (lc->framerate - prev_layer_framerate));
-
-            prev_layer_framerate = lc->framerate;
-        }
-    }
-}
-
-void vp8_change_config(VP8_COMP *cpi, VP8_CONFIG *oxcf)
-{
-    VP8_COMMON *cm = &cpi->common;
-    int last_w, last_h;
-    unsigned int prev_number_of_layers;
-
-    if (!cpi)
-        return;
-
-    if (!oxcf)
-        return;
-
-    if (cm->version != oxcf->Version)
-    {
-        cm->version = oxcf->Version;
-        vp8_setup_version(cm);
-    }
-
-    last_w = cpi->oxcf.Width;
-    last_h = cpi->oxcf.Height;
-    prev_number_of_layers = cpi->oxcf.number_of_layers;
-
-    cpi->oxcf = *oxcf;
-
-    switch (cpi->oxcf.Mode)
-    {
-
-    case MODE_REALTIME:
-        cpi->pass = 0;
-        cpi->compressor_speed = 2;
-
-        if (cpi->oxcf.cpu_used < -16)
-        {
-            cpi->oxcf.cpu_used = -16;
-        }
-
-        if (cpi->oxcf.cpu_used > 16)
-            cpi->oxcf.cpu_used = 16;
-
-        break;
-
-    case MODE_GOODQUALITY:
-        cpi->pass = 0;
-        cpi->compressor_speed = 1;
-
-        if (cpi->oxcf.cpu_used < -5)
-        {
-            cpi->oxcf.cpu_used = -5;
-        }
-
-        if (cpi->oxcf.cpu_used > 5)
-            cpi->oxcf.cpu_used = 5;
-
-        break;
-
-    case MODE_BESTQUALITY:
-        cpi->pass = 0;
-        cpi->compressor_speed = 0;
-        break;
-
-    case MODE_FIRSTPASS:
-        cpi->pass = 1;
-        cpi->compressor_speed = 1;
-        break;
-    case MODE_SECONDPASS:
-        cpi->pass = 2;
-        cpi->compressor_speed = 1;
-
-        if (cpi->oxcf.cpu_used < -5)
-        {
-            cpi->oxcf.cpu_used = -5;
-        }
-
-        if (cpi->oxcf.cpu_used > 5)
-            cpi->oxcf.cpu_used = 5;
-
-        break;
-    case MODE_SECONDPASS_BEST:
-        cpi->pass = 2;
-        cpi->compressor_speed = 0;
-        break;
-    }
-
-    if (cpi->pass == 0)
-        cpi->auto_worst_q = 1;
-
-    cpi->oxcf.worst_allowed_q = q_trans[oxcf->worst_allowed_q];
-    cpi->oxcf.best_allowed_q = q_trans[oxcf->best_allowed_q];
-    cpi->oxcf.cq_level = q_trans[cpi->oxcf.cq_level];
-
-    if (oxcf->fixed_q >= 0)
-    {
-        if (oxcf->worst_allowed_q < 0)
-            cpi->oxcf.fixed_q = q_trans[0];
-        else
-            cpi->oxcf.fixed_q = q_trans[oxcf->worst_allowed_q];
-
-        if (oxcf->alt_q < 0)
-            cpi->oxcf.alt_q = q_trans[0];
-        else
-            cpi->oxcf.alt_q = q_trans[oxcf->alt_q];
-
-        if (oxcf->key_q < 0)
-            cpi->oxcf.key_q = q_trans[0];
-        else
-            cpi->oxcf.key_q = q_trans[oxcf->key_q];
-
-        if (oxcf->gold_q < 0)
-            cpi->oxcf.gold_q = q_trans[0];
-        else
-            cpi->oxcf.gold_q = q_trans[oxcf->gold_q];
-
-    }
-
-    cpi->baseline_gf_interval =
-        cpi->oxcf.alt_freq ? cpi->oxcf.alt_freq : DEFAULT_GF_INTERVAL;
-
-#if (CONFIG_REALTIME_ONLY & CONFIG_ONTHEFLY_BITPACKING)
-    cpi->oxcf.token_partitions = 3;
-#endif
-
-    if (cpi->oxcf.token_partitions >= 0 && cpi->oxcf.token_partitions <= 3)
-        cm->multi_token_partition =
-            (TOKEN_PARTITION) cpi->oxcf.token_partitions;
-
-    setup_features(cpi);
-
-    {
-        int i;
-
-        for (i = 0; i < MAX_MB_SEGMENTS; i++)
-            cpi->segment_encode_breakout[i] = cpi->oxcf.encode_breakout;
-    }
-
-    /* At the moment the first order values may not be > MAXQ */
-    if (cpi->oxcf.fixed_q > MAXQ)
-        cpi->oxcf.fixed_q = MAXQ;
-
-    /* local file playback mode == really big buffer */
-    if (cpi->oxcf.end_usage == USAGE_LOCAL_FILE_PLAYBACK)
-    {
-        cpi->oxcf.starting_buffer_level       = 60000;
-        cpi->oxcf.optimal_buffer_level        = 60000;
-        cpi->oxcf.maximum_buffer_size         = 240000;
-        cpi->oxcf.starting_buffer_level_in_ms = 60000;
-        cpi->oxcf.optimal_buffer_level_in_ms  = 60000;
-        cpi->oxcf.maximum_buffer_size_in_ms   = 240000;
-    }
-
-    /* Convert target bandwidth from Kbit/s to Bit/s */
-    cpi->oxcf.target_bandwidth       *= 1000;
-
-    cpi->oxcf.starting_buffer_level =
-        rescale((int)cpi->oxcf.starting_buffer_level,
-                cpi->oxcf.target_bandwidth, 1000);
-
-    /* Set or reset optimal and maximum buffer levels. */
-    if (cpi->oxcf.optimal_buffer_level == 0)
-        cpi->oxcf.optimal_buffer_level = cpi->oxcf.target_bandwidth / 8;
-    else
-        cpi->oxcf.optimal_buffer_level =
-            rescale((int)cpi->oxcf.optimal_buffer_level,
-                    cpi->oxcf.target_bandwidth, 1000);
-
-    if (cpi->oxcf.maximum_buffer_size == 0)
-        cpi->oxcf.maximum_buffer_size = cpi->oxcf.target_bandwidth / 8;
-    else
-        cpi->oxcf.maximum_buffer_size =
-            rescale((int)cpi->oxcf.maximum_buffer_size,
-                    cpi->oxcf.target_bandwidth, 1000);
-    // Under a configuration change, where maximum_buffer_size may change,
-    // keep buffer level clipped to the maximum allowed buffer size.
-    if (cpi->bits_off_target > cpi->oxcf.maximum_buffer_size) {
-      cpi->bits_off_target = cpi->oxcf.maximum_buffer_size;
-      cpi->buffer_level = cpi->bits_off_target;
-    }
-
-    /* Set up frame rate and related parameters rate control values. */
-    vp8_new_framerate(cpi, cpi->framerate);
-
-    /* Set absolute upper and lower quality limits */
-    cpi->worst_quality               = cpi->oxcf.worst_allowed_q;
-    cpi->best_quality                = cpi->oxcf.best_allowed_q;
-
-    /* active values should only be modified if out of new range */
-    if (cpi->active_worst_quality > cpi->oxcf.worst_allowed_q)
-    {
-      cpi->active_worst_quality = cpi->oxcf.worst_allowed_q;
-    }
-    /* less likely */
-    else if (cpi->active_worst_quality < cpi->oxcf.best_allowed_q)
-    {
-      cpi->active_worst_quality = cpi->oxcf.best_allowed_q;
-    }
-    if (cpi->active_best_quality < cpi->oxcf.best_allowed_q)
-    {
-      cpi->active_best_quality = cpi->oxcf.best_allowed_q;
-    }
-    /* less likely */
-    else if (cpi->active_best_quality > cpi->oxcf.worst_allowed_q)
-    {
-      cpi->active_best_quality = cpi->oxcf.worst_allowed_q;
-    }
-
-    cpi->buffered_mode = cpi->oxcf.optimal_buffer_level > 0;
-
-    cpi->cq_target_quality = cpi->oxcf.cq_level;
-
-    /* Only allow dropped frames in buffered mode */
-    cpi->drop_frames_allowed = cpi->oxcf.allow_df && cpi->buffered_mode;
-
-    cpi->target_bandwidth = cpi->oxcf.target_bandwidth;
-
-    // Check if the number of temporal layers has changed, and if so reset the
-    // pattern counter and set/initialize the temporal layer context for the
-    // new layer configuration.
-    if (cpi->oxcf.number_of_layers != prev_number_of_layers)
-    {
-        // If the number of temporal layers are changed we must start at the
-        // base of the pattern cycle, so set the layer id to 0 and reset
-        // the temporal pattern counter.
-        if (cpi->temporal_layer_id > 0) {
-          cpi->temporal_layer_id = 0;
-        }
-        cpi->temporal_pattern_counter = 0;
-        reset_temporal_layer_change(cpi, oxcf, prev_number_of_layers);
-    }
-
-    if (!cpi->initial_width)
-    {
-        cpi->initial_width = cpi->oxcf.Width;
-        cpi->initial_height = cpi->oxcf.Height;
-    }
-
-    cm->Width       = cpi->oxcf.Width;
-    cm->Height      = cpi->oxcf.Height;
-    assert(cm->Width <= cpi->initial_width);
-    assert(cm->Height <= cpi->initial_height);
-
-    /* TODO(jkoleszar): if an internal spatial resampling is active,
-     * and we downsize the input image, maybe we should clear the
-     * internal scale immediately rather than waiting for it to
-     * correct.
-     */
-
-    /* VP8 sharpness level mapping 0-7 (vs 0-10 in general VPx dialogs) */
-    if (cpi->oxcf.Sharpness > 7)
-        cpi->oxcf.Sharpness = 7;
-
-    cm->sharpness_level = cpi->oxcf.Sharpness;
-
-    if (cm->horiz_scale != NORMAL || cm->vert_scale != NORMAL)
-    {
-        int UNINITIALIZED_IS_SAFE(hr), UNINITIALIZED_IS_SAFE(hs);
-        int UNINITIALIZED_IS_SAFE(vr), UNINITIALIZED_IS_SAFE(vs);
-
-        Scale2Ratio(cm->horiz_scale, &hr, &hs);
-        Scale2Ratio(cm->vert_scale, &vr, &vs);
-
-        /* always go to the next whole number */
-        cm->Width = (hs - 1 + cpi->oxcf.Width * hr) / hs;
-        cm->Height = (vs - 1 + cpi->oxcf.Height * vr) / vs;
-    }
-
-    if (last_w != cpi->oxcf.Width || last_h != cpi->oxcf.Height)
-        cpi->force_next_frame_intra = 1;
-
-    if (((cm->Width + 15) & ~15) != cm->yv12_fb[cm->lst_fb_idx].y_width ||
-        ((cm->Height + 15) & ~15) != cm->yv12_fb[cm->lst_fb_idx].y_height ||
-        cm->yv12_fb[cm->lst_fb_idx].y_width == 0)
-    {
-        dealloc_raw_frame_buffers(cpi);
-        alloc_raw_frame_buffers(cpi);
-        vp8_alloc_compressor_data(cpi);
-    }
-
-    if (cpi->oxcf.fixed_q >= 0)
-    {
-        cpi->last_q[0] = cpi->oxcf.fixed_q;
-        cpi->last_q[1] = cpi->oxcf.fixed_q;
-    }
-
-    cpi->Speed = cpi->oxcf.cpu_used;
-
-    /* force to allowlag to 0 if lag_in_frames is 0; */
-    if (cpi->oxcf.lag_in_frames == 0)
-    {
-        cpi->oxcf.allow_lag = 0;
-    }
-    /* Limit on lag buffers as these are not currently dynamically allocated */
-    else if (cpi->oxcf.lag_in_frames > MAX_LAG_BUFFERS)
-        cpi->oxcf.lag_in_frames = MAX_LAG_BUFFERS;
-
-    /* YX Temp */
-    cpi->alt_ref_source = NULL;
-    cpi->is_src_frame_alt_ref = 0;
-
-#if CONFIG_TEMPORAL_DENOISING
-    if (cpi->oxcf.noise_sensitivity)
-    {
-      if (!cpi->denoiser.yv12_mc_running_avg.buffer_alloc)
-      {
-        int width = (cpi->oxcf.Width + 15) & ~15;
-        int height = (cpi->oxcf.Height + 15) & ~15;
-        if (vp8_denoiser_allocate(&cpi->denoiser, width, height,
-                                  cm->mb_rows, cm->mb_cols,
-                                  cpi->oxcf.noise_sensitivity))
-            vpx_internal_error(&cpi->common.error, VPX_CODEC_MEM_ERROR,
-                               "Failed to allocate denoiser");
-      }
-    }
-#endif
-
-#if 0
-    /* Experimental RD Code */
-    cpi->frame_distortion = 0;
-    cpi->last_frame_distortion = 0;
-#endif
-
-}
-
-#ifndef M_LOG2_E
-#define M_LOG2_E 0.693147180559945309417
-#endif
-#define log2f(x) (log (x) / (float) M_LOG2_E)
-
-static void cal_mvsadcosts(int *mvsadcost[2])
-{
-    int i = 1;
-
-    mvsadcost [0] [0] = 300;
-    mvsadcost [1] [0] = 300;
-
-    do
-    {
-        double z = 256 * (2 * (log2f(8 * i) + .6));
-        mvsadcost [0][i] = (int) z;
-        mvsadcost [1][i] = (int) z;
-        mvsadcost [0][-i] = (int) z;
-        mvsadcost [1][-i] = (int) z;
-    }
-    while (++i <= mvfp_max);
-}
-
-struct VP8_COMP* vp8_create_compressor(VP8_CONFIG *oxcf)
-{
-    int i;
-
-    VP8_COMP *cpi;
-    VP8_COMMON *cm;
-
-    cpi = vpx_memalign(32, sizeof(VP8_COMP));
-    /* Check that the CPI instance is valid */
-    if (!cpi)
-        return 0;
-
-    cm = &cpi->common;
-
-    memset(cpi, 0, sizeof(VP8_COMP));
-
-    if (setjmp(cm->error.jmp))
-    {
-        cpi->common.error.setjmp = 0;
-        vp8_remove_compressor(&cpi);
-        return 0;
-    }
-
-    cpi->common.error.setjmp = 1;
-
-    CHECK_MEM_ERROR(cpi->mb.ss, vpx_calloc(sizeof(search_site), (MAX_MVSEARCH_STEPS * 8) + 1));
-
-    vp8_create_common(&cpi->common);
-
-    init_config(cpi, oxcf);
-
-    memcpy(cpi->base_skip_false_prob, vp8cx_base_skip_false_prob, sizeof(vp8cx_base_skip_false_prob));
-    cpi->common.current_video_frame   = 0;
-    cpi->temporal_pattern_counter     = 0;
-    cpi->temporal_layer_id            = -1;
-    cpi->kf_overspend_bits            = 0;
-    cpi->kf_bitrate_adjustment        = 0;
-    cpi->frames_till_gf_update_due      = 0;
-    cpi->gf_overspend_bits            = 0;
-    cpi->non_gf_bitrate_adjustment     = 0;
-    cpi->prob_last_coded              = 128;
-    cpi->prob_gf_coded                = 128;
-    cpi->prob_intra_coded             = 63;
-
-    /* Prime the recent reference frame usage counters.
-     * Hereafter they will be maintained as a sort of moving average
-     */
-    cpi->recent_ref_frame_usage[INTRA_FRAME]  = 1;
-    cpi->recent_ref_frame_usage[LAST_FRAME]   = 1;
-    cpi->recent_ref_frame_usage[GOLDEN_FRAME] = 1;
-    cpi->recent_ref_frame_usage[ALTREF_FRAME] = 1;
-
-    /* Set reference frame sign bias for ALTREF frame to 1 (for now) */
-    cpi->common.ref_frame_sign_bias[ALTREF_FRAME] = 1;
-
-    cpi->twopass.gf_decay_rate = 0;
-    cpi->baseline_gf_interval = DEFAULT_GF_INTERVAL;
-
-    cpi->gold_is_last = 0 ;
-    cpi->alt_is_last  = 0 ;
-    cpi->gold_is_alt  = 0 ;
-
-    cpi->active_map_enabled = 0;
-
-#if 0
-    /* Experimental code for lagged and one pass */
-    /* Initialise one_pass GF frames stats */
-    /* Update stats used for GF selection */
-    if (cpi->pass == 0)
-    {
-        cpi->one_pass_frame_index = 0;
-
-        for (i = 0; i < MAX_LAG_BUFFERS; i++)
-        {
-            cpi->one_pass_frame_stats[i].frames_so_far = 0;
-            cpi->one_pass_frame_stats[i].frame_intra_error = 0.0;
-            cpi->one_pass_frame_stats[i].frame_coded_error = 0.0;
-            cpi->one_pass_frame_stats[i].frame_pcnt_inter = 0.0;
-            cpi->one_pass_frame_stats[i].frame_pcnt_motion = 0.0;
-            cpi->one_pass_frame_stats[i].frame_mvr = 0.0;
-            cpi->one_pass_frame_stats[i].frame_mvr_abs = 0.0;
-            cpi->one_pass_frame_stats[i].frame_mvc = 0.0;
-            cpi->one_pass_frame_stats[i].frame_mvc_abs = 0.0;
-        }
-    }
-#endif
-
-    cpi->mse_source_denoised = 0;
-
-    /* Should we use the cyclic refresh method.
-     * Currently this is tied to error resilliant mode
-     */
-    cpi->cyclic_refresh_mode_enabled = cpi->oxcf.error_resilient_mode;
-    cpi->cyclic_refresh_mode_max_mbs_perframe = (cpi->common.mb_rows * cpi->common.mb_cols) / 7;
-    if (cpi->oxcf.number_of_layers == 1) {
-        cpi->cyclic_refresh_mode_max_mbs_perframe =
-            (cpi->common.mb_rows * cpi->common.mb_cols) / 20;
-    } else if (cpi->oxcf.number_of_layers == 2) {
-        cpi->cyclic_refresh_mode_max_mbs_perframe =
-            (cpi->common.mb_rows * cpi->common.mb_cols) / 10;
-    }
-    cpi->cyclic_refresh_mode_index = 0;
-    cpi->cyclic_refresh_q = 32;
-
-    if (cpi->cyclic_refresh_mode_enabled)
-    {
-        CHECK_MEM_ERROR(cpi->cyclic_refresh_map, vpx_calloc((cpi->common.mb_rows * cpi->common.mb_cols), 1));
-    }
-    else
-        cpi->cyclic_refresh_map = (signed char *) NULL;
-
-    CHECK_MEM_ERROR(cpi->consec_zero_last,
-                    vpx_calloc(cm->mb_rows * cm->mb_cols, 1));
-    CHECK_MEM_ERROR(cpi->consec_zero_last_mvbias,
-                    vpx_calloc((cpi->common.mb_rows * cpi->common.mb_cols), 1));
-
-#ifdef VP8_ENTROPY_STATS
-    init_context_counters();
-#endif
-
-    /*Initialize the feed-forward activity masking.*/
-    cpi->activity_avg = 90<<12;
-
-    /* Give a sensible default for the first frame. */
-    cpi->frames_since_key = 8;
-    cpi->key_frame_frequency = cpi->oxcf.key_freq;
-    cpi->this_key_frame_forced = 0;
-    cpi->next_key_frame_forced = 0;
-
-    cpi->source_alt_ref_pending = 0;
-    cpi->source_alt_ref_active = 0;
-    cpi->common.refresh_alt_ref_frame = 0;
-
-    cpi->force_maxqp = 0;
-
-    cpi->b_calculate_psnr = CONFIG_INTERNAL_STATS;
-#if CONFIG_INTERNAL_STATS
-    cpi->count = 0;
-    cpi->bytes = 0;
-
-    if (cpi->b_calculate_psnr)
-    {
-        cpi->total_sq_error = 0.0;
-        cpi->total_sq_error2 = 0.0;
-        cpi->total_y = 0.0;
-        cpi->total_u = 0.0;
-        cpi->total_v = 0.0;
-        cpi->total = 0.0;
-        cpi->totalp_y = 0.0;
-        cpi->totalp_u = 0.0;
-        cpi->totalp_v = 0.0;
-        cpi->totalp = 0.0;
-        cpi->tot_recode_hits = 0;
-        cpi->summed_quality = 0;
-        cpi->summed_weights = 0;
-    }
-
-#endif
-
-    cpi->first_time_stamp_ever = 0x7FFFFFFF;
-
-    cpi->frames_till_gf_update_due      = 0;
-    cpi->key_frame_count              = 1;
-
-    cpi->ni_av_qi                     = cpi->oxcf.worst_allowed_q;
-    cpi->ni_tot_qi                    = 0;
-    cpi->ni_frames                   = 0;
-    cpi->total_byte_count             = 0;
-
-    cpi->drop_frame                  = 0;
-
-    cpi->rate_correction_factor         = 1.0;
-    cpi->key_frame_rate_correction_factor = 1.0;
-    cpi->gf_rate_correction_factor  = 1.0;
-    cpi->twopass.est_max_qcorrection_factor  = 1.0;
-
-    for (i = 0; i < KEY_FRAME_CONTEXT; i++)
-    {
-        cpi->prior_key_frame_distance[i] = (int)cpi->output_framerate;
-    }
-
-#ifdef OUTPUT_YUV_SRC
-    yuv_file = fopen("bd.yuv", "ab");
-#endif
-#ifdef OUTPUT_YUV_DENOISED
-    yuv_denoised_file = fopen("denoised.yuv", "ab");
-#endif
-
-#if 0
-    framepsnr = fopen("framepsnr.stt", "a");
-    kf_list = fopen("kf_list.stt", "w");
-#endif
-
-    cpi->output_pkt_list = oxcf->output_pkt_list;
-
-#if !CONFIG_REALTIME_ONLY
-
-    if (cpi->pass == 1)
-    {
-        vp8_init_first_pass(cpi);
-    }
-    else if (cpi->pass == 2)
-    {
-        size_t packet_sz = sizeof(FIRSTPASS_STATS);
-        int packets = (int)(oxcf->two_pass_stats_in.sz / packet_sz);
-
-        cpi->twopass.stats_in_start = oxcf->two_pass_stats_in.buf;
-        cpi->twopass.stats_in = cpi->twopass.stats_in_start;
-        cpi->twopass.stats_in_end = (void*)((char *)cpi->twopass.stats_in
-                            + (packets - 1) * packet_sz);
-        vp8_init_second_pass(cpi);
-    }
-
-#endif
-
-    if (cpi->compressor_speed == 2)
-    {
-        cpi->avg_encode_time      = 0;
-        cpi->avg_pick_mode_time    = 0;
-    }
-
-    vp8_set_speed_features(cpi);
-
-    /* Set starting values of RD threshold multipliers (128 = *1) */
-    for (i = 0; i < MAX_MODES; i++)
-    {
-        cpi->mb.rd_thresh_mult[i] = 128;
-    }
-
-#ifdef VP8_ENTROPY_STATS
-    init_mv_ref_counts();
-#endif
-
-#if CONFIG_MULTITHREAD
-    if(vp8cx_create_encoder_threads(cpi))
-    {
-        vp8_remove_compressor(&cpi);
-        return 0;
-    }
-#endif
-
-    cpi->fn_ptr[BLOCK_16X16].sdf            = vpx_sad16x16;
-    cpi->fn_ptr[BLOCK_16X16].vf             = vpx_variance16x16;
-    cpi->fn_ptr[BLOCK_16X16].svf            = vpx_sub_pixel_variance16x16;
-    cpi->fn_ptr[BLOCK_16X16].svf_halfpix_h  = vpx_variance_halfpixvar16x16_h;
-    cpi->fn_ptr[BLOCK_16X16].svf_halfpix_v  = vpx_variance_halfpixvar16x16_v;
-    cpi->fn_ptr[BLOCK_16X16].svf_halfpix_hv = vpx_variance_halfpixvar16x16_hv;
-    cpi->fn_ptr[BLOCK_16X16].sdx3f          = vpx_sad16x16x3;
-    cpi->fn_ptr[BLOCK_16X16].sdx8f          = vpx_sad16x16x8;
-    cpi->fn_ptr[BLOCK_16X16].sdx4df         = vpx_sad16x16x4d;
-
-    cpi->fn_ptr[BLOCK_16X8].sdf            = vpx_sad16x8;
-    cpi->fn_ptr[BLOCK_16X8].vf             = vpx_variance16x8;
-    cpi->fn_ptr[BLOCK_16X8].svf            = vpx_sub_pixel_variance16x8;
-    cpi->fn_ptr[BLOCK_16X8].svf_halfpix_h  = NULL;
-    cpi->fn_ptr[BLOCK_16X8].svf_halfpix_v  = NULL;
-    cpi->fn_ptr[BLOCK_16X8].svf_halfpix_hv = NULL;
-    cpi->fn_ptr[BLOCK_16X8].sdx3f          = vpx_sad16x8x3;
-    cpi->fn_ptr[BLOCK_16X8].sdx8f          = vpx_sad16x8x8;
-    cpi->fn_ptr[BLOCK_16X8].sdx4df         = vpx_sad16x8x4d;
-
-    cpi->fn_ptr[BLOCK_8X16].sdf            = vpx_sad8x16;
-    cpi->fn_ptr[BLOCK_8X16].vf             = vpx_variance8x16;
-    cpi->fn_ptr[BLOCK_8X16].svf            = vpx_sub_pixel_variance8x16;
-    cpi->fn_ptr[BLOCK_8X16].svf_halfpix_h  = NULL;
-    cpi->fn_ptr[BLOCK_8X16].svf_halfpix_v  = NULL;
-    cpi->fn_ptr[BLOCK_8X16].svf_halfpix_hv = NULL;
-    cpi->fn_ptr[BLOCK_8X16].sdx3f          = vpx_sad8x16x3;
-    cpi->fn_ptr[BLOCK_8X16].sdx8f          = vpx_sad8x16x8;
-    cpi->fn_ptr[BLOCK_8X16].sdx4df         = vpx_sad8x16x4d;
-
-    cpi->fn_ptr[BLOCK_8X8].sdf            = vpx_sad8x8;
-    cpi->fn_ptr[BLOCK_8X8].vf             = vpx_variance8x8;
-    cpi->fn_ptr[BLOCK_8X8].svf            = vpx_sub_pixel_variance8x8;
-    cpi->fn_ptr[BLOCK_8X8].svf_halfpix_h  = NULL;
-    cpi->fn_ptr[BLOCK_8X8].svf_halfpix_v  = NULL;
-    cpi->fn_ptr[BLOCK_8X8].svf_halfpix_hv = NULL;
-    cpi->fn_ptr[BLOCK_8X8].sdx3f          = vpx_sad8x8x3;
-    cpi->fn_ptr[BLOCK_8X8].sdx8f          = vpx_sad8x8x8;
-    cpi->fn_ptr[BLOCK_8X8].sdx4df         = vpx_sad8x8x4d;
-
-    cpi->fn_ptr[BLOCK_4X4].sdf            = vpx_sad4x4;
-    cpi->fn_ptr[BLOCK_4X4].vf             = vpx_variance4x4;
-    cpi->fn_ptr[BLOCK_4X4].svf            = vpx_sub_pixel_variance4x4;
-    cpi->fn_ptr[BLOCK_4X4].svf_halfpix_h  = NULL;
-    cpi->fn_ptr[BLOCK_4X4].svf_halfpix_v  = NULL;
-    cpi->fn_ptr[BLOCK_4X4].svf_halfpix_hv = NULL;
-    cpi->fn_ptr[BLOCK_4X4].sdx3f          = vpx_sad4x4x3;
-    cpi->fn_ptr[BLOCK_4X4].sdx8f          = vpx_sad4x4x8;
-    cpi->fn_ptr[BLOCK_4X4].sdx4df         = vpx_sad4x4x4d;
-
-#if ARCH_X86 || ARCH_X86_64
-    cpi->fn_ptr[BLOCK_16X16].copymem      = vp8_copy32xn;
-    cpi->fn_ptr[BLOCK_16X8].copymem       = vp8_copy32xn;
-    cpi->fn_ptr[BLOCK_8X16].copymem       = vp8_copy32xn;
-    cpi->fn_ptr[BLOCK_8X8].copymem        = vp8_copy32xn;
-    cpi->fn_ptr[BLOCK_4X4].copymem        = vp8_copy32xn;
-#endif
-
-    cpi->full_search_sad = vp8_full_search_sad;
-    cpi->diamond_search_sad = vp8_diamond_search_sad;
-    cpi->refining_search_sad = vp8_refining_search_sad;
-
-    /* make sure frame 1 is okay */
-    cpi->mb.error_bins[0] = cpi->common.MBs;
-
-    /* vp8cx_init_quantizer() is first called here. Add check in
-     * vp8cx_frame_init_quantizer() so that vp8cx_init_quantizer is only
-     * called later when needed. This will avoid unnecessary calls of
-     * vp8cx_init_quantizer() for every frame.
-     */
-    vp8cx_init_quantizer(cpi);
-
-    vp8_loop_filter_init(cm);
-
-    cpi->common.error.setjmp = 0;
-
-#if CONFIG_MULTI_RES_ENCODING
-
-    /* Calculate # of MBs in a row in lower-resolution level image. */
-    if (cpi->oxcf.mr_encoder_id > 0)
-        vp8_cal_low_res_mb_cols(cpi);
-
-#endif
-
-    /* setup RD costs to MACROBLOCK struct */
-
-    cpi->mb.mvcost[0] = &cpi->rd_costs.mvcosts[0][mv_max+1];
-    cpi->mb.mvcost[1] = &cpi->rd_costs.mvcosts[1][mv_max+1];
-    cpi->mb.mvsadcost[0] = &cpi->rd_costs.mvsadcosts[0][mvfp_max+1];
-    cpi->mb.mvsadcost[1] = &cpi->rd_costs.mvsadcosts[1][mvfp_max+1];
-
-    cal_mvsadcosts(cpi->mb.mvsadcost);
-
-    cpi->mb.mbmode_cost = cpi->rd_costs.mbmode_cost;
-    cpi->mb.intra_uv_mode_cost = cpi->rd_costs.intra_uv_mode_cost;
-    cpi->mb.bmode_costs = cpi->rd_costs.bmode_costs;
-    cpi->mb.inter_bmode_costs = cpi->rd_costs.inter_bmode_costs;
-    cpi->mb.token_costs = cpi->rd_costs.token_costs;
-
-    /* setup block ptrs & offsets */
-    vp8_setup_block_ptrs(&cpi->mb);
-    vp8_setup_block_dptrs(&cpi->mb.e_mbd);
-
-    return  cpi;
-}
-
-
-void vp8_remove_compressor(VP8_COMP **ptr)
-{
-    VP8_COMP *cpi = *ptr;
-
-    if (!cpi)
-        return;
-
-    if (cpi && (cpi->common.current_video_frame > 0))
-    {
-#if !CONFIG_REALTIME_ONLY
-
-        if (cpi->pass == 2)
-        {
-            vp8_end_second_pass(cpi);
-        }
-
-#endif
-
-#ifdef VP8_ENTROPY_STATS
-        print_context_counters();
-        print_tree_update_probs();
-        print_mode_context();
-#endif
-
-#if CONFIG_INTERNAL_STATS
-
-        if (cpi->pass != 1)
-        {
-            FILE *f = fopen("opsnr.stt", "a");
-            double time_encoded = (cpi->last_end_time_stamp_seen
-                                   - cpi->first_time_stamp_ever) / 10000000.000;
-            double total_encode_time = (cpi->time_receive_data +
-                                            cpi->time_compress_data) / 1000.000;
-            double dr = (double)cpi->bytes * 8.0 / 1000.0 / time_encoded;
-            const double target_rate = (double)cpi->oxcf.target_bandwidth / 1000;
-            const double rate_err = ((100.0 * (dr - target_rate)) / target_rate);
-
-            if (cpi->b_calculate_psnr)
-            {
-                if (cpi->oxcf.number_of_layers > 1)
-                {
-                    int i;
-
-                    fprintf(f, "Layer\tBitrate\tAVGPsnr\tGLBPsnr\tAVPsnrP\t"
-                               "GLPsnrP\tVPXSSIM\t\n");
-                    for (i=0; i<(int)cpi->oxcf.number_of_layers; i++)
-                    {
-                        double dr = (double)cpi->bytes_in_layer[i] *
-                                              8.0 / 1000.0  / time_encoded;
-                        double samples = 3.0 / 2 * cpi->frames_in_layer[i] *
-                                         cpi->common.Width * cpi->common.Height;
-                        double total_psnr =
-                            vpx_sse_to_psnr(samples, 255.0,
-                                            cpi->total_error2[i]);
-                        double total_psnr2 =
-                            vpx_sse_to_psnr(samples, 255.0,
-                                            cpi->total_error2_p[i]);
-                        double total_ssim = 100 * pow(cpi->sum_ssim[i] /
-                                                      cpi->sum_weights[i], 8.0);
-
-                        fprintf(f, "%5d\t%7.3f\t%7.3f\t%7.3f\t%7.3f\t"
-                                   "%7.3f\t%7.3f\n",
-                                   i, dr,
-                                   cpi->sum_psnr[i] / cpi->frames_in_layer[i],
-                                   total_psnr,
-                                   cpi->sum_psnr_p[i] / cpi->frames_in_layer[i],
-                                   total_psnr2, total_ssim);
-                    }
-                }
-                else
-                {
-                    double samples = 3.0 / 2 * cpi->count *
-                                     cpi->common.Width * cpi->common.Height;
-                    double total_psnr = vpx_sse_to_psnr(samples, 255.0,
-                                                        cpi->total_sq_error);
-                    double total_psnr2 = vpx_sse_to_psnr(samples, 255.0,
-                                                         cpi->total_sq_error2);
-                    double total_ssim = 100 * pow(cpi->summed_quality /
-                                                      cpi->summed_weights, 8.0);
-
-                    fprintf(f, "Bitrate\tAVGPsnr\tGLBPsnr\tAVPsnrP\t"
-                               "GLPsnrP\tVPXSSIM\t  Time(us)  Rc-Err "
-                               "Abs Err\n");
-                    fprintf(f, "%7.3f\t%7.3f\t%7.3f\t%7.3f\t%7.3f\t"
-                               "%7.3f\t%8.0f %7.2f %7.2f\n",
-                               dr, cpi->total / cpi->count, total_psnr,
-                               cpi->totalp / cpi->count, total_psnr2,
-                               total_ssim, total_encode_time,
-                               rate_err, fabs(rate_err));
-                }
-            }
-            fclose(f);
-#if 0
-            f = fopen("qskip.stt", "a");
-            fprintf(f, "minq:%d -maxq:%d skiptrue:skipfalse = %d:%d\n", cpi->oxcf.best_allowed_q, cpi->oxcf.worst_allowed_q, skiptruecount, skipfalsecount);
-            fclose(f);
-#endif
-
-        }
-
-#endif
-
-
-#ifdef SPEEDSTATS
-
-        if (cpi->compressor_speed == 2)
-        {
-            int i;
-            FILE *f = fopen("cxspeed.stt", "a");
-            cnt_pm /= cpi->common.MBs;
-
-            for (i = 0; i < 16; i++)
-                fprintf(f, "%5d", frames_at_speed[i]);
-
-            fprintf(f, "\n");
-            fclose(f);
-        }
-
-#endif
-
-
-#ifdef MODE_STATS
-        {
-            extern int count_mb_seg[4];
-            FILE *f = fopen("modes.stt", "a");
-            double dr = (double)cpi->framerate * (double)bytes * (double)8 / (double)count / (double)1000 ;
-            fprintf(f, "intra_mode in Intra Frames:\n");
-            fprintf(f, "Y: %8d, %8d, %8d, %8d, %8d\n", y_modes[0], y_modes[1], y_modes[2], y_modes[3], y_modes[4]);
-            fprintf(f, "UV:%8d, %8d, %8d, %8d\n", uv_modes[0], uv_modes[1], uv_modes[2], uv_modes[3]);
-            fprintf(f, "B: ");
-            {
-                int i;
-
-                for (i = 0; i < 10; i++)
-                    fprintf(f, "%8d, ", b_modes[i]);
-
-                fprintf(f, "\n");
-
-            }
-
-            fprintf(f, "Modes in Inter Frames:\n");
-            fprintf(f, "Y: %8d, %8d, %8d, %8d, %8d, %8d, %8d, %8d, %8d, %8d\n",
-                    inter_y_modes[0], inter_y_modes[1], inter_y_modes[2], inter_y_modes[3], inter_y_modes[4],
-                    inter_y_modes[5], inter_y_modes[6], inter_y_modes[7], inter_y_modes[8], inter_y_modes[9]);
-            fprintf(f, "UV:%8d, %8d, %8d, %8d\n", inter_uv_modes[0], inter_uv_modes[1], inter_uv_modes[2], inter_uv_modes[3]);
-            fprintf(f, "B: ");
-            {
-                int i;
-
-                for (i = 0; i < 15; i++)
-                    fprintf(f, "%8d, ", inter_b_modes[i]);
-
-                fprintf(f, "\n");
-
-            }
-            fprintf(f, "P:%8d, %8d, %8d, %8d\n", count_mb_seg[0], count_mb_seg[1], count_mb_seg[2], count_mb_seg[3]);
-            fprintf(f, "PB:%8d, %8d, %8d, %8d\n", inter_b_modes[LEFT4X4], inter_b_modes[ABOVE4X4], inter_b_modes[ZERO4X4], inter_b_modes[NEW4X4]);
-
-
-
-            fclose(f);
-        }
-#endif
-
-#ifdef VP8_ENTROPY_STATS
-        {
-            int i, j, k;
-            FILE *fmode = fopen("modecontext.c", "w");
-
-            fprintf(fmode, "\n#include \"entropymode.h\"\n\n");
-            fprintf(fmode, "const unsigned int vp8_kf_default_bmode_counts ");
-            fprintf(fmode, "[VP8_BINTRAMODES] [VP8_BINTRAMODES] [VP8_BINTRAMODES] =\n{\n");
-
-            for (i = 0; i < 10; i++)
-            {
-
-                fprintf(fmode, "    { /* Above Mode :  %d */\n", i);
-
-                for (j = 0; j < 10; j++)
-                {
-
-                    fprintf(fmode, "        {");
-
-                    for (k = 0; k < 10; k++)
-                    {
-                        if (!intra_mode_stats[i][j][k])
-                            fprintf(fmode, " %5d, ", 1);
-                        else
-                            fprintf(fmode, " %5d, ", intra_mode_stats[i][j][k]);
-                    }
-
-                    fprintf(fmode, "}, /* left_mode %d */\n", j);
-
-                }
-
-                fprintf(fmode, "    },\n");
-
-            }
-
-            fprintf(fmode, "};\n");
-            fclose(fmode);
-        }
-#endif
-
-
-#if defined(SECTIONBITS_OUTPUT)
-
-        if (0)
-        {
-            int i;
-            FILE *f = fopen("tokenbits.stt", "a");
-
-            for (i = 0; i < 28; i++)
-                fprintf(f, "%8d", (int)(Sectionbits[i] / 256));
-
-            fprintf(f, "\n");
-            fclose(f);
-        }
-
-#endif
-
-#if 0
-        {
-            printf("\n_pick_loop_filter_level:%d\n", cpi->time_pick_lpf / 1000);
-            printf("\n_frames recive_data encod_mb_row compress_frame  Total\n");
-            printf("%6d %10ld %10ld %10ld %10ld\n", cpi->common.current_video_frame, cpi->time_receive_data / 1000, cpi->time_encode_mb_row / 1000, cpi->time_compress_data / 1000, (cpi->time_receive_data + cpi->time_compress_data) / 1000);
-        }
-#endif
-
-    }
-
-#if CONFIG_MULTITHREAD
-    vp8cx_remove_encoder_threads(cpi);
-#endif
-
-#if CONFIG_TEMPORAL_DENOISING
-    vp8_denoiser_free(&cpi->denoiser);
-#endif
-    dealloc_compressor_data(cpi);
-    vpx_free(cpi->mb.ss);
-    vpx_free(cpi->tok);
-    vpx_free(cpi->cyclic_refresh_map);
-    vpx_free(cpi->consec_zero_last);
-    vpx_free(cpi->consec_zero_last_mvbias);
-
-    vp8_remove_common(&cpi->common);
-    vpx_free(cpi);
-    *ptr = 0;
-
-#ifdef OUTPUT_YUV_SRC
-    fclose(yuv_file);
-#endif
-#ifdef OUTPUT_YUV_DENOISED
-    fclose(yuv_denoised_file);
-#endif
-
-#if 0
-
-    if (keyfile)
-        fclose(keyfile);
-
-    if (framepsnr)
-        fclose(framepsnr);
-
-    if (kf_list)
-        fclose(kf_list);
-
-#endif
-
-}
-
-
-static uint64_t calc_plane_error(unsigned char *orig, int orig_stride,
-                                 unsigned char *recon, int recon_stride,
-                                 unsigned int cols, unsigned int rows)
-{
-    unsigned int row, col;
-    uint64_t total_sse = 0;
-    int diff;
-
-    for (row = 0; row + 16 <= rows; row += 16)
-    {
-        for (col = 0; col + 16 <= cols; col += 16)
-        {
-            unsigned int sse;
-
-            vpx_mse16x16(orig + col, orig_stride,
-                                            recon + col, recon_stride,
-                                            &sse);
-            total_sse += sse;
-        }
-
-        /* Handle odd-sized width */
-        if (col < cols)
-        {
-            unsigned int   border_row, border_col;
-            unsigned char *border_orig = orig;
-            unsigned char *border_recon = recon;
-
-            for (border_row = 0; border_row < 16; border_row++)
-            {
-                for (border_col = col; border_col < cols; border_col++)
-                {
-                    diff = border_orig[border_col] - border_recon[border_col];
-                    total_sse += diff * diff;
-                }
-
-                border_orig += orig_stride;
-                border_recon += recon_stride;
-            }
-        }
-
-        orig += orig_stride * 16;
-        recon += recon_stride * 16;
-    }
-
-    /* Handle odd-sized height */
-    for (; row < rows; row++)
-    {
-        for (col = 0; col < cols; col++)
-        {
-            diff = orig[col] - recon[col];
-            total_sse += diff * diff;
-        }
-
-        orig += orig_stride;
-        recon += recon_stride;
-    }
-
-    vp8_clear_system_state();
-    return total_sse;
-}
-
-
-static void generate_psnr_packet(VP8_COMP *cpi)
-{
-    YV12_BUFFER_CONFIG      *orig = cpi->Source;
-    YV12_BUFFER_CONFIG      *recon = cpi->common.frame_to_show;
-    struct vpx_codec_cx_pkt  pkt;
-    uint64_t                 sse;
-    int                      i;
-    unsigned int             width = cpi->common.Width;
-    unsigned int             height = cpi->common.Height;
-
-    pkt.kind = VPX_CODEC_PSNR_PKT;
-    sse = calc_plane_error(orig->y_buffer, orig->y_stride,
-                           recon->y_buffer, recon->y_stride,
-                           width, height);
-    pkt.data.psnr.sse[0] = sse;
-    pkt.data.psnr.sse[1] = sse;
-    pkt.data.psnr.samples[0] = width * height;
-    pkt.data.psnr.samples[1] = width * height;
-
-    width = (width + 1) / 2;
-    height = (height + 1) / 2;
-
-    sse = calc_plane_error(orig->u_buffer, orig->uv_stride,
-                           recon->u_buffer, recon->uv_stride,
-                           width, height);
-    pkt.data.psnr.sse[0] += sse;
-    pkt.data.psnr.sse[2] = sse;
-    pkt.data.psnr.samples[0] += width * height;
-    pkt.data.psnr.samples[2] = width * height;
-
-    sse = calc_plane_error(orig->v_buffer, orig->uv_stride,
-                           recon->v_buffer, recon->uv_stride,
-                           width, height);
-    pkt.data.psnr.sse[0] += sse;
-    pkt.data.psnr.sse[3] = sse;
-    pkt.data.psnr.samples[0] += width * height;
-    pkt.data.psnr.samples[3] = width * height;
-
-    for (i = 0; i < 4; i++)
-        pkt.data.psnr.psnr[i] = vpx_sse_to_psnr(pkt.data.psnr.samples[i], 255.0,
-                                                (double)(pkt.data.psnr.sse[i]));
-
-    vpx_codec_pkt_list_add(cpi->output_pkt_list, &pkt);
-}
-
-
-int vp8_use_as_reference(VP8_COMP *cpi, int ref_frame_flags)
-{
-    if (ref_frame_flags > 7)
-        return -1 ;
-
-    cpi->ref_frame_flags = ref_frame_flags;
-    return 0;
-}
-int vp8_update_reference(VP8_COMP *cpi, int ref_frame_flags)
-{
-    if (ref_frame_flags > 7)
-        return -1 ;
-
-    cpi->common.refresh_golden_frame = 0;
-    cpi->common.refresh_alt_ref_frame = 0;
-    cpi->common.refresh_last_frame   = 0;
-
-    if (ref_frame_flags & VP8_LAST_FRAME)
-        cpi->common.refresh_last_frame = 1;
-
-    if (ref_frame_flags & VP8_GOLD_FRAME)
-        cpi->common.refresh_golden_frame = 1;
-
-    if (ref_frame_flags & VP8_ALTR_FRAME)
-        cpi->common.refresh_alt_ref_frame = 1;
-
-    return 0;
-}
-
-int vp8_get_reference(VP8_COMP *cpi, enum vpx_ref_frame_type ref_frame_flag, YV12_BUFFER_CONFIG *sd)
-{
-    VP8_COMMON *cm = &cpi->common;
-    int ref_fb_idx;
-
-    if (ref_frame_flag == VP8_LAST_FRAME)
-        ref_fb_idx = cm->lst_fb_idx;
-    else if (ref_frame_flag == VP8_GOLD_FRAME)
-        ref_fb_idx = cm->gld_fb_idx;
-    else if (ref_frame_flag == VP8_ALTR_FRAME)
-        ref_fb_idx = cm->alt_fb_idx;
-    else
-        return -1;
-
-    vp8_yv12_copy_frame(&cm->yv12_fb[ref_fb_idx], sd);
-
-    return 0;
-}
-int vp8_set_reference(VP8_COMP *cpi, enum vpx_ref_frame_type ref_frame_flag, YV12_BUFFER_CONFIG *sd)
-{
-    VP8_COMMON *cm = &cpi->common;
-
-    int ref_fb_idx;
-
-    if (ref_frame_flag == VP8_LAST_FRAME)
-        ref_fb_idx = cm->lst_fb_idx;
-    else if (ref_frame_flag == VP8_GOLD_FRAME)
-        ref_fb_idx = cm->gld_fb_idx;
-    else if (ref_frame_flag == VP8_ALTR_FRAME)
-        ref_fb_idx = cm->alt_fb_idx;
-    else
-        return -1;
-
-    vp8_yv12_copy_frame(sd, &cm->yv12_fb[ref_fb_idx]);
-
-    return 0;
-}
-int vp8_update_entropy(VP8_COMP *cpi, int update)
-{
-    VP8_COMMON *cm = &cpi->common;
-    cm->refresh_entropy_probs = update;
-
-    return 0;
-}
-
-
-#if defined(OUTPUT_YUV_SRC) || defined(OUTPUT_YUV_DENOISED)
-void vp8_write_yuv_frame(FILE *yuv_file, YV12_BUFFER_CONFIG *s)
-{
-    unsigned char *src = s->y_buffer;
-    int h = s->y_height;
-
-    do
-    {
-        fwrite(src, s->y_width, 1,  yuv_file);
-        src += s->y_stride;
-    }
-    while (--h);
-
-    src = s->u_buffer;
-    h = s->uv_height;
-
-    do
-    {
-        fwrite(src, s->uv_width, 1,  yuv_file);
-        src += s->uv_stride;
-    }
-    while (--h);
-
-    src = s->v_buffer;
-    h = s->uv_height;
-
-    do
-    {
-        fwrite(src, s->uv_width, 1, yuv_file);
-        src += s->uv_stride;
-    }
-    while (--h);
-}
-#endif
-
-static void scale_and_extend_source(YV12_BUFFER_CONFIG *sd, VP8_COMP *cpi)
-{
-    VP8_COMMON *cm = &cpi->common;
-
-    /* are we resizing the image */
-    if (cm->horiz_scale != 0 || cm->vert_scale != 0)
-    {
-#if CONFIG_SPATIAL_RESAMPLING
-        int UNINITIALIZED_IS_SAFE(hr), UNINITIALIZED_IS_SAFE(hs);
-        int UNINITIALIZED_IS_SAFE(vr), UNINITIALIZED_IS_SAFE(vs);
-        int tmp_height;
-
-        if (cm->vert_scale == 3)
-            tmp_height = 9;
-        else
-            tmp_height = 11;
-
-        Scale2Ratio(cm->horiz_scale, &hr, &hs);
-        Scale2Ratio(cm->vert_scale, &vr, &vs);
-
-        vpx_scale_frame(sd, &cpi->scaled_source, cm->temp_scale_frame.y_buffer,
-                        tmp_height, hs, hr, vs, vr, 0);
-
-        vp8_yv12_extend_frame_borders(&cpi->scaled_source);
-        cpi->Source = &cpi->scaled_source;
-#endif
-    }
-    else
-        cpi->Source = sd;
-}
-
-
-static int resize_key_frame(VP8_COMP *cpi)
-{
-#if CONFIG_SPATIAL_RESAMPLING
-    VP8_COMMON *cm = &cpi->common;
-
-    /* Do we need to apply resampling for one pass cbr.
-     * In one pass this is more limited than in two pass cbr.
-     * The test and any change is only made once per key frame sequence.
-     */
-    if (cpi->oxcf.allow_spatial_resampling && (cpi->oxcf.end_usage == USAGE_STREAM_FROM_SERVER))
-    {
-        int UNINITIALIZED_IS_SAFE(hr), UNINITIALIZED_IS_SAFE(hs);
-        int UNINITIALIZED_IS_SAFE(vr), UNINITIALIZED_IS_SAFE(vs);
-        int new_width, new_height;
-
-        /* If we are below the resample DOWN watermark then scale down a
-         * notch.
-         */
-        if (cpi->buffer_level < (cpi->oxcf.resample_down_water_mark * cpi->oxcf.optimal_buffer_level / 100))
-        {
-            cm->horiz_scale = (cm->horiz_scale < ONETWO) ? cm->horiz_scale + 1 : ONETWO;
-            cm->vert_scale = (cm->vert_scale < ONETWO) ? cm->vert_scale + 1 : ONETWO;
-        }
-        /* Should we now start scaling back up */
-        else if (cpi->buffer_level > (cpi->oxcf.resample_up_water_mark * cpi->oxcf.optimal_buffer_level / 100))
-        {
-            cm->horiz_scale = (cm->horiz_scale > NORMAL) ? cm->horiz_scale - 1 : NORMAL;
-            cm->vert_scale = (cm->vert_scale > NORMAL) ? cm->vert_scale - 1 : NORMAL;
-        }
-
-        /* Get the new height and width */
-        Scale2Ratio(cm->horiz_scale, &hr, &hs);
-        Scale2Ratio(cm->vert_scale, &vr, &vs);
-        new_width = ((hs - 1) + (cpi->oxcf.Width * hr)) / hs;
-        new_height = ((vs - 1) + (cpi->oxcf.Height * vr)) / vs;
-
-        /* If the image size has changed we need to reallocate the buffers
-         * and resample the source image
-         */
-        if ((cm->Width != new_width) || (cm->Height != new_height))
-        {
-            cm->Width = new_width;
-            cm->Height = new_height;
-            vp8_alloc_compressor_data(cpi);
-            scale_and_extend_source(cpi->un_scaled_source, cpi);
-            return 1;
-        }
-    }
-
-#endif
-    return 0;
-}
-
-
-static void update_alt_ref_frame_stats(VP8_COMP *cpi)
-{
-    VP8_COMMON *cm = &cpi->common;
-
-    /* Select an interval before next GF or altref */
-    if (!cpi->auto_gold)
-        cpi->frames_till_gf_update_due = DEFAULT_GF_INTERVAL;
-
-    if ((cpi->pass != 2) && cpi->frames_till_gf_update_due)
-    {
-        cpi->current_gf_interval = cpi->frames_till_gf_update_due;
-
-        /* Set the bits per frame that we should try and recover in
-         * subsequent inter frames to account for the extra GF spend...
-         * note that his does not apply for GF updates that occur
-         * coincident with a key frame as the extra cost of key frames is
-         * dealt with elsewhere.
-         */
-        cpi->gf_overspend_bits += cpi->projected_frame_size;
-        cpi->non_gf_bitrate_adjustment = cpi->gf_overspend_bits / cpi->frames_till_gf_update_due;
-    }
-
-    /* Update data structure that monitors level of reference to last GF */
-    memset(cpi->gf_active_flags, 1, (cm->mb_rows * cm->mb_cols));
-    cpi->gf_active_count = cm->mb_rows * cm->mb_cols;
-
-    /* this frame refreshes means next frames don't unless specified by user */
-    cpi->frames_since_golden = 0;
-
-    /* Clear the alternate reference update pending flag. */
-    cpi->source_alt_ref_pending = 0;
-
-    /* Set the alternate reference frame active flag */
-    cpi->source_alt_ref_active = 1;
-
-
-}
-static void update_golden_frame_stats(VP8_COMP *cpi)
-{
-    VP8_COMMON *cm = &cpi->common;
-
-    /* Update the Golden frame usage counts. */
-    if (cm->refresh_golden_frame)
-    {
-        /* Select an interval before next GF */
-        if (!cpi->auto_gold)
-            cpi->frames_till_gf_update_due = DEFAULT_GF_INTERVAL;
-
-        if ((cpi->pass != 2) && (cpi->frames_till_gf_update_due > 0))
-        {
-            cpi->current_gf_interval = cpi->frames_till_gf_update_due;
-
-            /* Set the bits per frame that we should try and recover in
-             * subsequent inter frames to account for the extra GF spend...
-             * note that his does not apply for GF updates that occur
-             * coincident with a key frame as the extra cost of key frames
-             * is dealt with elsewhere.
-             */
-            if ((cm->frame_type != KEY_FRAME) && !cpi->source_alt_ref_active)
-            {
-                /* Calcluate GF bits to be recovered
-                 * Projected size - av frame bits available for inter
-                 * frames for clip as a whole
-                 */
-                cpi->gf_overspend_bits += (cpi->projected_frame_size - cpi->inter_frame_target);
-            }
-
-            cpi->non_gf_bitrate_adjustment = cpi->gf_overspend_bits / cpi->frames_till_gf_update_due;
-
-        }
-
-        /* Update data structure that monitors level of reference to last GF */
-        memset(cpi->gf_active_flags, 1, (cm->mb_rows * cm->mb_cols));
-        cpi->gf_active_count = cm->mb_rows * cm->mb_cols;
-
-        /* this frame refreshes means next frames don't unless specified by
-         * user
-         */
-        cm->refresh_golden_frame = 0;
-        cpi->frames_since_golden = 0;
-
-        cpi->recent_ref_frame_usage[INTRA_FRAME] = 1;
-        cpi->recent_ref_frame_usage[LAST_FRAME] = 1;
-        cpi->recent_ref_frame_usage[GOLDEN_FRAME] = 1;
-        cpi->recent_ref_frame_usage[ALTREF_FRAME] = 1;
-
-        /* ******** Fixed Q test code only ************ */
-        /* If we are going to use the ALT reference for the next group of
-         * frames set a flag to say so.
-         */
-        if (cpi->oxcf.fixed_q >= 0 &&
-            cpi->oxcf.play_alternate && !cpi->common.refresh_alt_ref_frame)
-        {
-            cpi->source_alt_ref_pending = 1;
-            cpi->frames_till_gf_update_due = cpi->baseline_gf_interval;
-        }
-
-        if (!cpi->source_alt_ref_pending)
-            cpi->source_alt_ref_active = 0;
-
-        /* Decrement count down till next gf */
-        if (cpi->frames_till_gf_update_due > 0)
-            cpi->frames_till_gf_update_due--;
-
-    }
-    else if (!cpi->common.refresh_alt_ref_frame)
-    {
-        /* Decrement count down till next gf */
-        if (cpi->frames_till_gf_update_due > 0)
-            cpi->frames_till_gf_update_due--;
-
-        if (cpi->frames_till_alt_ref_frame)
-            cpi->frames_till_alt_ref_frame --;
-
-        cpi->frames_since_golden ++;
-
-        if (cpi->frames_since_golden > 1)
-        {
-            cpi->recent_ref_frame_usage[INTRA_FRAME] +=
-                cpi->mb.count_mb_ref_frame_usage[INTRA_FRAME];
-            cpi->recent_ref_frame_usage[LAST_FRAME] +=
-                cpi->mb.count_mb_ref_frame_usage[LAST_FRAME];
-            cpi->recent_ref_frame_usage[GOLDEN_FRAME] +=
-                cpi->mb.count_mb_ref_frame_usage[GOLDEN_FRAME];
-            cpi->recent_ref_frame_usage[ALTREF_FRAME] +=
-                cpi->mb.count_mb_ref_frame_usage[ALTREF_FRAME];
-        }
-    }
-}
-
-/* This function updates the reference frame probability estimates that
- * will be used during mode selection
- */
-static void update_rd_ref_frame_probs(VP8_COMP *cpi)
-{
-    VP8_COMMON *cm = &cpi->common;
-
-    const int *const rfct = cpi->mb.count_mb_ref_frame_usage;
-    const int rf_intra = rfct[INTRA_FRAME];
-    const int rf_inter = rfct[LAST_FRAME] + rfct[GOLDEN_FRAME] + rfct[ALTREF_FRAME];
-
-    if (cm->frame_type == KEY_FRAME)
-    {
-        cpi->prob_intra_coded = 255;
-        cpi->prob_last_coded  = 128;
-        cpi->prob_gf_coded  = 128;
-    }
-    else if (!(rf_intra + rf_inter))
-    {
-        cpi->prob_intra_coded = 63;
-        cpi->prob_last_coded  = 128;
-        cpi->prob_gf_coded    = 128;
-    }
-
-    /* update reference frame costs since we can do better than what we got
-     * last frame.
-     */
-    if (cpi->oxcf.number_of_layers == 1)
-    {
-        if (cpi->common.refresh_alt_ref_frame)
-        {
-            cpi->prob_intra_coded += 40;
-            if (cpi->prob_intra_coded > 255)
-                cpi->prob_intra_coded = 255;
-            cpi->prob_last_coded = 200;
-            cpi->prob_gf_coded = 1;
-        }
-        else if (cpi->frames_since_golden == 0)
-        {
-            cpi->prob_last_coded = 214;
-        }
-        else if (cpi->frames_since_golden == 1)
-        {
-            cpi->prob_last_coded = 192;
-            cpi->prob_gf_coded = 220;
-        }
-        else if (cpi->source_alt_ref_active)
-        {
-            cpi->prob_gf_coded -= 20;
-
-            if (cpi->prob_gf_coded < 10)
-                cpi->prob_gf_coded = 10;
-        }
-        if (!cpi->source_alt_ref_active)
-            cpi->prob_gf_coded = 255;
-    }
-}
-
-
-#if !CONFIG_REALTIME_ONLY
-/* 1 = key, 0 = inter */
-static int decide_key_frame(VP8_COMP *cpi)
-{
-    VP8_COMMON *cm = &cpi->common;
-
-    int code_key_frame = 0;
-
-    cpi->kf_boost = 0;
-
-    if (cpi->Speed > 11)
-        return 0;
-
-    /* Clear down mmx registers */
-    vp8_clear_system_state();
-
-    if ((cpi->compressor_speed == 2) && (cpi->Speed >= 5) && (cpi->sf.RD == 0))
-    {
-        double change = 1.0 * abs((int)(cpi->mb.intra_error -
-            cpi->last_intra_error)) / (1 + cpi->last_intra_error);
-        double change2 = 1.0 * abs((int)(cpi->mb.prediction_error -
-            cpi->last_prediction_error)) / (1 + cpi->last_prediction_error);
-        double minerror = cm->MBs * 256;
-
-        cpi->last_intra_error = cpi->mb.intra_error;
-        cpi->last_prediction_error = cpi->mb.prediction_error;
-
-        if (10 * cpi->mb.intra_error / (1 + cpi->mb.prediction_error) < 15
-            && cpi->mb.prediction_error > minerror
-            && (change > .25 || change2 > .25))
-        {
-            /*(change > 1.4 || change < .75)&& cpi->this_frame_percent_intra > cpi->last_frame_percent_intra + 3*/
-            return 1;
-        }
-
-        return 0;
-
-    }
-
-    /* If the following are true we might as well code a key frame */
-    if (((cpi->this_frame_percent_intra == 100) &&
-         (cpi->this_frame_percent_intra > (cpi->last_frame_percent_intra + 2))) ||
-        ((cpi->this_frame_percent_intra > 95) &&
-         (cpi->this_frame_percent_intra >= (cpi->last_frame_percent_intra + 5))))
-    {
-        code_key_frame = 1;
-    }
-    /* in addition if the following are true and this is not a golden frame
-     * then code a key frame Note that on golden frames there often seems
-     * to be a pop in intra useage anyway hence this restriction is
-     * designed to prevent spurious key frames. The Intra pop needs to be
-     * investigated.
-     */
-    else if (((cpi->this_frame_percent_intra > 60) &&
-              (cpi->this_frame_percent_intra > (cpi->last_frame_percent_intra * 2))) ||
-             ((cpi->this_frame_percent_intra > 75) &&
-              (cpi->this_frame_percent_intra > (cpi->last_frame_percent_intra * 3 / 2))) ||
-             ((cpi->this_frame_percent_intra > 90) &&
-              (cpi->this_frame_percent_intra > (cpi->last_frame_percent_intra + 10))))
-    {
-        if (!cm->refresh_golden_frame)
-            code_key_frame = 1;
-    }
-
-    return code_key_frame;
-
-}
-
-static void Pass1Encode(VP8_COMP *cpi, unsigned long *size, unsigned char *dest, unsigned int *frame_flags)
-{
-    (void) size;
-    (void) dest;
-    (void) frame_flags;
-    vp8_set_quantizer(cpi, 26);
-
-    vp8_first_pass(cpi);
-}
-#endif
-
-#if 0
-void write_cx_frame_to_file(YV12_BUFFER_CONFIG *frame, int this_frame)
-{
-
-    /* write the frame */
-    FILE *yframe;
-    int i;
-    char filename[255];
-
-    sprintf(filename, "cx\\y%04d.raw", this_frame);
-    yframe = fopen(filename, "wb");
-
-    for (i = 0; i < frame->y_height; i++)
-        fwrite(frame->y_buffer + i * frame->y_stride, frame->y_width, 1, yframe);
-
-    fclose(yframe);
-    sprintf(filename, "cx\\u%04d.raw", this_frame);
-    yframe = fopen(filename, "wb");
-
-    for (i = 0; i < frame->uv_height; i++)
-        fwrite(frame->u_buffer + i * frame->uv_stride, frame->uv_width, 1, yframe);
-
-    fclose(yframe);
-    sprintf(filename, "cx\\v%04d.raw", this_frame);
-    yframe = fopen(filename, "wb");
-
-    for (i = 0; i < frame->uv_height; i++)
-        fwrite(frame->v_buffer + i * frame->uv_stride, frame->uv_width, 1, yframe);
-
-    fclose(yframe);
-}
-#endif
-/* return of 0 means drop frame */
-
-#if !CONFIG_REALTIME_ONLY
-/* Function to test for conditions that indeicate we should loop
- * back and recode a frame.
- */
-static int recode_loop_test( VP8_COMP *cpi,
-                              int high_limit, int low_limit,
-                              int q, int maxq, int minq )
-{
-    int force_recode = 0;
-    VP8_COMMON *cm = &cpi->common;
-
-    /* Is frame recode allowed at all
-     * Yes if either recode mode 1 is selected or mode two is selcted
-     * and the frame is a key frame. golden frame or alt_ref_frame
-     */
-    if ( (cpi->sf.recode_loop == 1) ||
-         ( (cpi->sf.recode_loop == 2) &&
-           ( (cm->frame_type == KEY_FRAME) ||
-             cm->refresh_golden_frame ||
-             cm->refresh_alt_ref_frame ) ) )
-    {
-        /* General over and under shoot tests */
-        if ( ((cpi->projected_frame_size > high_limit) && (q < maxq)) ||
-             ((cpi->projected_frame_size < low_limit) && (q > minq)) )
-        {
-            force_recode = 1;
-        }
-        /* Special Constrained quality tests */
-        else if (cpi->oxcf.end_usage == USAGE_CONSTRAINED_QUALITY)
-        {
-            /* Undershoot and below auto cq level */
-            if ( (q > cpi->cq_target_quality) &&
-                 (cpi->projected_frame_size <
-                     ((cpi->this_frame_target * 7) >> 3)))
-            {
-                force_recode = 1;
-            }
-            /* Severe undershoot and between auto and user cq level */
-            else if ( (q > cpi->oxcf.cq_level) &&
-                      (cpi->projected_frame_size < cpi->min_frame_bandwidth) &&
-                      (cpi->active_best_quality > cpi->oxcf.cq_level))
-            {
-                force_recode = 1;
-                cpi->active_best_quality = cpi->oxcf.cq_level;
-            }
-        }
-    }
-
-    return force_recode;
-}
-#endif  // !CONFIG_REALTIME_ONLY
-
-static void update_reference_frames(VP8_COMP *cpi)
-{
-    VP8_COMMON *cm = &cpi->common;
-    YV12_BUFFER_CONFIG *yv12_fb = cm->yv12_fb;
-
-    /* At this point the new frame has been encoded.
-     * If any buffer copy / swapping is signaled it should be done here.
-     */
-
-    if (cm->frame_type == KEY_FRAME)
-    {
-        yv12_fb[cm->new_fb_idx].flags |= VP8_GOLD_FRAME | VP8_ALTR_FRAME ;
-
-        yv12_fb[cm->gld_fb_idx].flags &= ~VP8_GOLD_FRAME;
-        yv12_fb[cm->alt_fb_idx].flags &= ~VP8_ALTR_FRAME;
-
-        cm->alt_fb_idx = cm->gld_fb_idx = cm->new_fb_idx;
-
-        cpi->current_ref_frames[GOLDEN_FRAME] = cm->current_video_frame;
-        cpi->current_ref_frames[ALTREF_FRAME] = cm->current_video_frame;
-    }
-    else    /* For non key frames */
-    {
-        if (cm->refresh_alt_ref_frame)
-        {
-            assert(!cm->copy_buffer_to_arf);
-
-            cm->yv12_fb[cm->new_fb_idx].flags |= VP8_ALTR_FRAME;
-            cm->yv12_fb[cm->alt_fb_idx].flags &= ~VP8_ALTR_FRAME;
-            cm->alt_fb_idx = cm->new_fb_idx;
-
-            cpi->current_ref_frames[ALTREF_FRAME] = cm->current_video_frame;
-        }
-        else if (cm->copy_buffer_to_arf)
-        {
-            assert(!(cm->copy_buffer_to_arf & ~0x3));
-
-            if (cm->copy_buffer_to_arf == 1)
-            {
-                if(cm->alt_fb_idx != cm->lst_fb_idx)
-                {
-                    yv12_fb[cm->lst_fb_idx].flags |= VP8_ALTR_FRAME;
-                    yv12_fb[cm->alt_fb_idx].flags &= ~VP8_ALTR_FRAME;
-                    cm->alt_fb_idx = cm->lst_fb_idx;
-
-                    cpi->current_ref_frames[ALTREF_FRAME] =
-                        cpi->current_ref_frames[LAST_FRAME];
-                }
-            }
-            else /* if (cm->copy_buffer_to_arf == 2) */
-            {
-                if(cm->alt_fb_idx != cm->gld_fb_idx)
-                {
-                    yv12_fb[cm->gld_fb_idx].flags |= VP8_ALTR_FRAME;
-                    yv12_fb[cm->alt_fb_idx].flags &= ~VP8_ALTR_FRAME;
-                    cm->alt_fb_idx = cm->gld_fb_idx;
-
-                    cpi->current_ref_frames[ALTREF_FRAME] =
-                        cpi->current_ref_frames[GOLDEN_FRAME];
-                }
-            }
-        }
-
-        if (cm->refresh_golden_frame)
-        {
-            assert(!cm->copy_buffer_to_gf);
-
-            cm->yv12_fb[cm->new_fb_idx].flags |= VP8_GOLD_FRAME;
-            cm->yv12_fb[cm->gld_fb_idx].flags &= ~VP8_GOLD_FRAME;
-            cm->gld_fb_idx = cm->new_fb_idx;
-
-            cpi->current_ref_frames[GOLDEN_FRAME] = cm->current_video_frame;
-        }
-        else if (cm->copy_buffer_to_gf)
-        {
-            assert(!(cm->copy_buffer_to_arf & ~0x3));
-
-            if (cm->copy_buffer_to_gf == 1)
-            {
-                if(cm->gld_fb_idx != cm->lst_fb_idx)
-                {
-                    yv12_fb[cm->lst_fb_idx].flags |= VP8_GOLD_FRAME;
-                    yv12_fb[cm->gld_fb_idx].flags &= ~VP8_GOLD_FRAME;
-                    cm->gld_fb_idx = cm->lst_fb_idx;
-
-                    cpi->current_ref_frames[GOLDEN_FRAME] =
-                        cpi->current_ref_frames[LAST_FRAME];
-                }
-            }
-            else /* if (cm->copy_buffer_to_gf == 2) */
-            {
-                if(cm->alt_fb_idx != cm->gld_fb_idx)
-                {
-                    yv12_fb[cm->alt_fb_idx].flags |= VP8_GOLD_FRAME;
-                    yv12_fb[cm->gld_fb_idx].flags &= ~VP8_GOLD_FRAME;
-                    cm->gld_fb_idx = cm->alt_fb_idx;
-
-                    cpi->current_ref_frames[GOLDEN_FRAME] =
-                        cpi->current_ref_frames[ALTREF_FRAME];
-                }
-            }
-        }
-    }
-
-    if (cm->refresh_last_frame)
-    {
-        cm->yv12_fb[cm->new_fb_idx].flags |= VP8_LAST_FRAME;
-        cm->yv12_fb[cm->lst_fb_idx].flags &= ~VP8_LAST_FRAME;
-        cm->lst_fb_idx = cm->new_fb_idx;
-
-        cpi->current_ref_frames[LAST_FRAME] = cm->current_video_frame;
-    }
-
-#if CONFIG_TEMPORAL_DENOISING
-    if (cpi->oxcf.noise_sensitivity)
-    {
-        /* we shouldn't have to keep multiple copies as we know in advance which
-         * buffer we should start - for now to get something up and running
-         * I've chosen to copy the buffers
-         */
-        if (cm->frame_type == KEY_FRAME)
-        {
-            int i;
-            for (i = LAST_FRAME; i < MAX_REF_FRAMES; ++i)
-              vp8_yv12_copy_frame(cpi->Source,
-                                  &cpi->denoiser.yv12_running_avg[i]);
-        }
-        else /* For non key frames */
-        {
-            vp8_yv12_extend_frame_borders(
-                    &cpi->denoiser.yv12_running_avg[INTRA_FRAME]);
-
-            if (cm->refresh_alt_ref_frame || cm->copy_buffer_to_arf)
-            {
-                vp8_yv12_copy_frame(
-                        &cpi->denoiser.yv12_running_avg[INTRA_FRAME],
-                        &cpi->denoiser.yv12_running_avg[ALTREF_FRAME]);
-            }
-            if (cm->refresh_golden_frame || cm->copy_buffer_to_gf)
-            {
-                vp8_yv12_copy_frame(
-                        &cpi->denoiser.yv12_running_avg[INTRA_FRAME],
-                        &cpi->denoiser.yv12_running_avg[GOLDEN_FRAME]);
-            }
-            if(cm->refresh_last_frame)
-            {
-                vp8_yv12_copy_frame(
-                        &cpi->denoiser.yv12_running_avg[INTRA_FRAME],
-                        &cpi->denoiser.yv12_running_avg[LAST_FRAME]);
-            }
-        }
-        if (cpi->oxcf.noise_sensitivity == 4)
-          vp8_yv12_copy_frame(cpi->Source, &cpi->denoiser.yv12_last_source);
-
-    }
-#endif
-
-}
-
-static int measure_square_diff_partial(YV12_BUFFER_CONFIG *source,
-                                       YV12_BUFFER_CONFIG *dest,
-                                       VP8_COMP *cpi)
-    {
-        int i, j;
-        int Total = 0;
-        int num_blocks = 0;
-        int skip = 2;
-        int min_consec_zero_last = 10;
-        int tot_num_blocks = (source->y_height * source->y_width) >> 8;
-        unsigned char *src = source->y_buffer;
-        unsigned char *dst = dest->y_buffer;
-
-        /* Loop through the Y plane, every |skip| blocks along rows and colmumns,
-         * summing the square differences, and only for blocks that have been
-         * zero_last mode at least |x| frames in a row.
-         */
-        for (i = 0; i < source->y_height; i += 16 * skip)
-        {
-            int block_index_row = (i >> 4) * cpi->common.mb_cols;
-            for (j = 0; j < source->y_width; j += 16 * skip)
-            {
-                int index = block_index_row + (j >> 4);
-                if (cpi->consec_zero_last[index] >= min_consec_zero_last) {
-                  unsigned int sse;
-                  Total += vpx_mse16x16(src + j,
-                                        source->y_stride,
-                                        dst + j, dest->y_stride,
-                                        &sse);
-                  num_blocks++;
-                }
-            }
-            src += 16 * skip * source->y_stride;
-            dst += 16 * skip * dest->y_stride;
-        }
-        // Only return non-zero if we have at least ~1/16 samples for estimate.
-        if (num_blocks > (tot_num_blocks >> 4)) {
-        return (Total / num_blocks);
-        } else {
-          return 0;
-        }
-    }
-
-#if CONFIG_TEMPORAL_DENOISING
-static void process_denoiser_mode_change(VP8_COMP *cpi) {
-  const VP8_COMMON *const cm = &cpi->common;
-  int i, j;
-  int total = 0;
-  int num_blocks = 0;
-  // Number of blocks skipped along row/column in computing the
-  // nmse (normalized mean square error) of source.
-  int skip = 2;
-  // Only select blocks for computing nmse that have been encoded
-  // as ZERO LAST min_consec_zero_last frames in a row.
-  // Scale with number of temporal layers.
-  int min_consec_zero_last = 12 / cpi->oxcf.number_of_layers;
-  // Decision is tested for changing the denoising mode every
-  // num_mode_change times this function is called. Note that this
-  // function called every 8 frames, so (8 * num_mode_change) is number
-  // of frames where denoising mode change is tested for switch.
-  int num_mode_change = 20;
-  // Framerate factor, to compensate for larger mse at lower framerates.
-  // Use ref_framerate, which is full source framerate for temporal layers.
-  // TODO(marpan): Adjust this factor.
-  int fac_framerate = cpi->ref_framerate < 25.0f ? 80 : 100;
-  int tot_num_blocks = cm->mb_rows * cm->mb_cols;
-  int ystride = cpi->Source->y_stride;
-  unsigned char *src = cpi->Source->y_buffer;
-  unsigned char *dst = cpi->denoiser.yv12_last_source.y_buffer;
-  static const unsigned char const_source[16] = {
-      128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
-      128, 128, 128};
-  int bandwidth = (int)(cpi->target_bandwidth);
-  // For temporal layers, use full bandwidth (top layer).
-  if (cpi->oxcf.number_of_layers > 1) {
-    LAYER_CONTEXT *lc = &cpi->layer_context[cpi->oxcf.number_of_layers - 1];
-    bandwidth = (int)(lc->target_bandwidth);
-  }
-  // Loop through the Y plane, every skip blocks along rows and columns,
-  // summing the normalized mean square error, only for blocks that have
-  // been encoded as ZEROMV LAST at least min_consec_zero_last least frames in
-  // a row and have small sum difference between current and previous frame.
-  // Normalization here is by the contrast of the current frame block.
-  for (i = 0; i < cm->Height; i += 16 * skip) {
-    int block_index_row = (i >> 4) * cm->mb_cols;
-    for (j = 0; j < cm->Width; j += 16 * skip) {
-      int index = block_index_row + (j >> 4);
-      if (cpi->consec_zero_last[index] >= min_consec_zero_last) {
-        unsigned int sse;
-        const unsigned int var = vpx_variance16x16(src + j,
-                                                   ystride,
-                                                   dst + j,
-                                                   ystride,
-                                                   &sse);
-        // Only consider this block as valid for noise measurement
-        // if the sum_diff average of the current and previous frame
-        // is small (to avoid effects from lighting change).
-        if ((sse - var) < 128) {
-          unsigned int sse2;
-          const unsigned int act = vpx_variance16x16(src + j,
-                                                     ystride,
-                                                     const_source,
-                                                     0,
-                                                     &sse2);
-          if (act > 0)
-            total += sse / act;
-          num_blocks++;
-        }
-      }
-    }
-    src += 16 * skip * ystride;
-    dst += 16 * skip * ystride;
-  }
-  total = total * fac_framerate / 100;
-
-  // Only consider this frame as valid sample if we have computed nmse over
-  // at least ~1/16 blocks, and Total > 0 (Total == 0 can happen if the
-  // application inputs duplicate frames, or contrast is all zero).
-  if (total > 0 &&
-      (num_blocks > (tot_num_blocks >> 4))) {
-    // Update the recursive mean square source_diff.
-    total = (total << 8) / num_blocks;
-    if (cpi->denoiser.nmse_source_diff_count == 0) {
-      // First sample in new interval.
-      cpi->denoiser.nmse_source_diff = total;
-      cpi->denoiser.qp_avg = cm->base_qindex;
-    } else {
-      // For subsequent samples, use average with weight ~1/4 for new sample.
-      cpi->denoiser.nmse_source_diff = (int)((total +
-          3 * cpi->denoiser.nmse_source_diff) >> 2);
-      cpi->denoiser.qp_avg = (int)((cm->base_qindex +
-          3 * cpi->denoiser.qp_avg) >> 2);
-    }
-    cpi->denoiser.nmse_source_diff_count++;
-  }
-  // Check for changing the denoiser mode, when we have obtained #samples =
-  // num_mode_change. Condition the change also on the bitrate and QP.
-  if (cpi->denoiser.nmse_source_diff_count == num_mode_change) {
-    // Check for going up: from normal to aggressive mode.
-    if ((cpi->denoiser.denoiser_mode == kDenoiserOnYUV) &&
-        (cpi->denoiser.nmse_source_diff >
-        cpi->denoiser.threshold_aggressive_mode) &&
-        (cpi->denoiser.qp_avg < cpi->denoiser.qp_threshold_up &&
-         bandwidth > cpi->denoiser.bitrate_threshold)) {
-      vp8_denoiser_set_parameters(&cpi->denoiser, kDenoiserOnYUVAggressive);
-    } else {
-      // Check for going down: from aggressive to normal mode.
-      if (((cpi->denoiser.denoiser_mode == kDenoiserOnYUVAggressive) &&
-          (cpi->denoiser.nmse_source_diff <
-          cpi->denoiser.threshold_aggressive_mode)) ||
-          ((cpi->denoiser.denoiser_mode == kDenoiserOnYUVAggressive) &&
-          (cpi->denoiser.qp_avg > cpi->denoiser.qp_threshold_down ||
-           bandwidth < cpi->denoiser.bitrate_threshold))) {
-        vp8_denoiser_set_parameters(&cpi->denoiser, kDenoiserOnYUV);
-      }
-    }
-    // Reset metric and counter for next interval.
-    cpi->denoiser.nmse_source_diff = 0;
-    cpi->denoiser.qp_avg = 0;
-    cpi->denoiser.nmse_source_diff_count = 0;
-  }
-}
-#endif
-
-void vp8_loopfilter_frame(VP8_COMP *cpi, VP8_COMMON *cm)
-{
-    const FRAME_TYPE frame_type = cm->frame_type;
-
-    int update_any_ref_buffers = 1;
-    if (cpi->common.refresh_last_frame == 0 &&
-        cpi->common.refresh_golden_frame == 0 &&
-        cpi->common.refresh_alt_ref_frame == 0) {
-        update_any_ref_buffers = 0;
-    }
-
-    if (cm->no_lpf)
-    {
-        cm->filter_level = 0;
-    }
-    else
-    {
-        struct vpx_usec_timer timer;
-
-        vp8_clear_system_state();
-
-        vpx_usec_timer_start(&timer);
-        if (cpi->sf.auto_filter == 0) {
-#if CONFIG_TEMPORAL_DENOISING
-            if (cpi->oxcf.noise_sensitivity && cm->frame_type != KEY_FRAME) {
-                // Use the denoised buffer for selecting base loop filter level.
-                // Denoised signal for current frame is stored in INTRA_FRAME.
-                // No denoising on key frames.
-                vp8cx_pick_filter_level_fast(
-                    &cpi->denoiser.yv12_running_avg[INTRA_FRAME], cpi);
-            } else {
-                vp8cx_pick_filter_level_fast(cpi->Source, cpi);
-            }
-#else
-            vp8cx_pick_filter_level_fast(cpi->Source, cpi);
-#endif
-        } else {
-#if CONFIG_TEMPORAL_DENOISING
-            if (cpi->oxcf.noise_sensitivity && cm->frame_type != KEY_FRAME) {
-                // Use the denoised buffer for selecting base loop filter level.
-                // Denoised signal for current frame is stored in INTRA_FRAME.
-                // No denoising on key frames.
-                vp8cx_pick_filter_level(
-                    &cpi->denoiser.yv12_running_avg[INTRA_FRAME], cpi);
-            } else {
-                vp8cx_pick_filter_level(cpi->Source, cpi);
-            }
-#else
-            vp8cx_pick_filter_level(cpi->Source, cpi);
-#endif
-        }
-
-
-        if (cm->filter_level > 0)
-        {
-            vp8cx_set_alt_lf_level(cpi, cm->filter_level);
-        }
-
-        vpx_usec_timer_mark(&timer);
-        cpi->time_pick_lpf += vpx_usec_timer_elapsed(&timer);
-    }
-
-#if CONFIG_MULTITHREAD
-    if (cpi->b_multi_threaded)
-        sem_post(&cpi->h_event_end_lpf); /* signal that we have set filter_level */
-#endif
-
-    // No need to apply loop-filter if the encoded frame does not update
-    // any reference buffers.
-    if (cm->filter_level > 0 && update_any_ref_buffers)
-    {
-        vp8_loop_filter_frame(cm, &cpi->mb.e_mbd, frame_type);
-    }
-
-    vp8_yv12_extend_frame_borders(cm->frame_to_show);
-
-}
-
-static void encode_frame_to_data_rate
-(
-    VP8_COMP *cpi,
-    unsigned long *size,
-    unsigned char *dest,
-    unsigned char* dest_end,
-    unsigned int *frame_flags
-)
-{
-    int Q;
-    int frame_over_shoot_limit;
-    int frame_under_shoot_limit;
-
-    int Loop = 0;
-    int loop_count;
-
-    VP8_COMMON *cm = &cpi->common;
-    int active_worst_qchanged = 0;
-
-#if !CONFIG_REALTIME_ONLY
-    int q_low;
-    int q_high;
-    int zbin_oq_high;
-    int zbin_oq_low = 0;
-    int top_index;
-    int bottom_index;
-    int overshoot_seen = 0;
-    int undershoot_seen = 0;
-#endif
-
-    int drop_mark = (int)(cpi->oxcf.drop_frames_water_mark *
-                          cpi->oxcf.optimal_buffer_level / 100);
-    int drop_mark75 = drop_mark * 2 / 3;
-    int drop_mark50 = drop_mark / 4;
-    int drop_mark25 = drop_mark / 8;
-
-
-    /* Clear down mmx registers to allow floating point in what follows */
-    vp8_clear_system_state();
-
-    if(cpi->force_next_frame_intra)
-    {
-        cm->frame_type = KEY_FRAME;  /* delayed intra frame */
-        cpi->force_next_frame_intra = 0;
-    }
-
-    /* For an alt ref frame in 2 pass we skip the call to the second pass
-     * function that sets the target bandwidth
-     */
-#if !CONFIG_REALTIME_ONLY
-
-    if (cpi->pass == 2)
-    {
-        if (cpi->common.refresh_alt_ref_frame)
-        {
-            /* Per frame bit target for the alt ref frame */
-            cpi->per_frame_bandwidth = cpi->twopass.gf_bits;
-            /* per second target bitrate */
-            cpi->target_bandwidth = (int)(cpi->twopass.gf_bits *
-                                          cpi->output_framerate);
-        }
-    }
-    else
-#endif
-        cpi->per_frame_bandwidth  = (int)(cpi->target_bandwidth / cpi->output_framerate);
-
-    /* Default turn off buffer to buffer copying */
-    cm->copy_buffer_to_gf = 0;
-    cm->copy_buffer_to_arf = 0;
-
-    /* Clear zbin over-quant value and mode boost values. */
-    cpi->mb.zbin_over_quant = 0;
-    cpi->mb.zbin_mode_boost = 0;
-
-    /* Enable or disable mode based tweaking of the zbin
-     * For 2 Pass Only used where GF/ARF prediction quality
-     * is above a threshold
-     */
-    cpi->mb.zbin_mode_boost_enabled = 1;
-    if (cpi->pass == 2)
-    {
-        if ( cpi->gfu_boost <= 400 )
-        {
-            cpi->mb.zbin_mode_boost_enabled = 0;
-        }
-    }
-
-    /* Current default encoder behaviour for the altref sign bias */
-    if (cpi->source_alt_ref_active)
-        cpi->common.ref_frame_sign_bias[ALTREF_FRAME] = 1;
-    else
-        cpi->common.ref_frame_sign_bias[ALTREF_FRAME] = 0;
-
-    /* Check to see if a key frame is signaled
-     * For two pass with auto key frame enabled cm->frame_type may already
-     * be set, but not for one pass.
-     */
-    if ((cm->current_video_frame == 0) ||
-        (cm->frame_flags & FRAMEFLAGS_KEY) ||
-        (cpi->oxcf.auto_key && (cpi->frames_since_key % cpi->key_frame_frequency == 0)))
-    {
-        /* Key frame from VFW/auto-keyframe/first frame */
-        cm->frame_type = KEY_FRAME;
-#if CONFIG_TEMPORAL_DENOISING
-        if (cpi->oxcf.noise_sensitivity == 4) {
-          // For adaptive mode, reset denoiser to normal mode on key frame.
-          vp8_denoiser_set_parameters(&cpi->denoiser, kDenoiserOnYUV);
-        }
-#endif
-    }
-
-#if CONFIG_MULTI_RES_ENCODING
-    if (cpi->oxcf.mr_total_resolutions > 1) {
-      LOWER_RES_FRAME_INFO* low_res_frame_info
-         = (LOWER_RES_FRAME_INFO*)cpi->oxcf.mr_low_res_mode_info;
-
-      if (cpi->oxcf.mr_encoder_id) {
-
-        // TODO(marpan): This constraint shouldn't be needed, as we would like
-        // to allow for key frame setting (forced or periodic) defined per
-        // spatial layer. For now, keep this in.
-        cm->frame_type = low_res_frame_info->frame_type;
-
-        // Check if lower resolution is available for motion vector reuse.
-        if(cm->frame_type != KEY_FRAME)
-        {
-          cpi->mr_low_res_mv_avail = 1;
-          cpi->mr_low_res_mv_avail &= !(low_res_frame_info->is_frame_dropped);
-
-          if (cpi->ref_frame_flags & VP8_LAST_FRAME)
-              cpi->mr_low_res_mv_avail &= (cpi->current_ref_frames[LAST_FRAME]
-                       == low_res_frame_info->low_res_ref_frames[LAST_FRAME]);
-
-          if (cpi->ref_frame_flags & VP8_GOLD_FRAME)
-              cpi->mr_low_res_mv_avail &= (cpi->current_ref_frames[GOLDEN_FRAME]
-                       == low_res_frame_info->low_res_ref_frames[GOLDEN_FRAME]);
-
-          // Don't use altref to determine whether low res is available.
-          // TODO (marpan): Should we make this type of condition on a
-          // per-reference frame basis?
-          /*
-          if (cpi->ref_frame_flags & VP8_ALTR_FRAME)
-              cpi->mr_low_res_mv_avail &= (cpi->current_ref_frames[ALTREF_FRAME]
-                       == low_res_frame_info->low_res_ref_frames[ALTREF_FRAME]);
-          */
-        }
-      }
-
-      // On a key frame: For the lowest resolution, keep track of the key frame
-      // counter value. For the higher resolutions, reset the current video
-      // frame counter to that of the lowest resolution.
-      // This is done to the handle the case where we may stop/start encoding
-      // higher layer(s). The restart-encoding of higher layer is only signaled
-      // by a key frame for now.
-      // TODO (marpan): Add flag to indicate restart-encoding of higher layer.
-      if (cm->frame_type == KEY_FRAME) {
-        if (cpi->oxcf.mr_encoder_id) {
-          // If the initial starting value of the buffer level is zero (this can
-          // happen because we may have not started encoding this higher stream),
-          // then reset it to non-zero value based on |starting_buffer_level|.
-          if (cpi->common.current_video_frame == 0 && cpi->buffer_level == 0) {
-            unsigned int i;
-            cpi->bits_off_target = cpi->oxcf.starting_buffer_level;
-            cpi->buffer_level = cpi->oxcf.starting_buffer_level;
-            for (i = 0; i < cpi->oxcf.number_of_layers; i++) {
-              LAYER_CONTEXT *lc = &cpi->layer_context[i];
-              lc->bits_off_target = lc->starting_buffer_level;
-              lc->buffer_level = lc->starting_buffer_level;
-            }
-          }
-          cpi->common.current_video_frame =
-              low_res_frame_info->key_frame_counter_value;
-        } else {
-          low_res_frame_info->key_frame_counter_value =
-              cpi->common.current_video_frame;
-        }
-      }
-
-    }
-#endif
-
-    // Find the reference frame closest to the current frame.
-    cpi->closest_reference_frame = LAST_FRAME;
-    if(cm->frame_type != KEY_FRAME) {
-      int i;
-      MV_REFERENCE_FRAME closest_ref = INTRA_FRAME;
-      if (cpi->ref_frame_flags & VP8_LAST_FRAME) {
-        closest_ref = LAST_FRAME;
-      } else if (cpi->ref_frame_flags & VP8_GOLD_FRAME) {
-        closest_ref = GOLDEN_FRAME;
-      } else if (cpi->ref_frame_flags & VP8_ALTR_FRAME) {
-        closest_ref = ALTREF_FRAME;
-      }
-      for(i = 1; i <= 3; i++) {
-        vpx_ref_frame_type_t ref_frame_type = (vpx_ref_frame_type_t)
-            ((i == 3) ? 4 : i);
-        if (cpi->ref_frame_flags & ref_frame_type) {
-          if ((cm->current_video_frame - cpi->current_ref_frames[i]) <
-              (cm->current_video_frame - cpi->current_ref_frames[closest_ref])) {
-            closest_ref = i;
-          }
-        }
-      }
-      cpi->closest_reference_frame = closest_ref;
-    }
-
-    /* Set various flags etc to special state if it is a key frame */
-    if (cm->frame_type == KEY_FRAME)
-    {
-        int i;
-
-        // Set the loop filter deltas and segmentation map update
-        setup_features(cpi);
-
-        /* The alternate reference frame cannot be active for a key frame */
-        cpi->source_alt_ref_active = 0;
-
-        /* Reset the RD threshold multipliers to default of * 1 (128) */
-        for (i = 0; i < MAX_MODES; i++)
-        {
-            cpi->mb.rd_thresh_mult[i] = 128;
-        }
-
-        // Reset the zero_last counter to 0 on key frame.
-        memset(cpi->consec_zero_last, 0, cm->mb_rows * cm->mb_cols);
-        memset(cpi->consec_zero_last_mvbias, 0,
-               (cpi->common.mb_rows * cpi->common.mb_cols));
-    }
-
-#if 0
-    /* Experimental code for lagged compress and one pass
-     * Initialise one_pass GF frames stats
-     * Update stats used for GF selection
-     */
-    {
-        cpi->one_pass_frame_index = cm->current_video_frame % MAX_LAG_BUFFERS;
-
-        cpi->one_pass_frame_stats[cpi->one_pass_frame_index ].frames_so_far = 0;
-        cpi->one_pass_frame_stats[cpi->one_pass_frame_index ].frame_intra_error = 0.0;
-        cpi->one_pass_frame_stats[cpi->one_pass_frame_index ].frame_coded_error = 0.0;
-        cpi->one_pass_frame_stats[cpi->one_pass_frame_index ].frame_pcnt_inter = 0.0;
-        cpi->one_pass_frame_stats[cpi->one_pass_frame_index ].frame_pcnt_motion = 0.0;
-        cpi->one_pass_frame_stats[cpi->one_pass_frame_index ].frame_mvr = 0.0;
-        cpi->one_pass_frame_stats[cpi->one_pass_frame_index ].frame_mvr_abs = 0.0;
-        cpi->one_pass_frame_stats[cpi->one_pass_frame_index ].frame_mvc = 0.0;
-        cpi->one_pass_frame_stats[cpi->one_pass_frame_index ].frame_mvc_abs = 0.0;
-    }
-#endif
-
-    update_rd_ref_frame_probs(cpi);
-
-    if (cpi->drop_frames_allowed)
-    {
-        /* The reset to decimation 0 is only done here for one pass.
-         * Once it is set two pass leaves decimation on till the next kf.
-         */
-        if ((cpi->buffer_level > drop_mark) && (cpi->decimation_factor > 0))
-            cpi->decimation_factor --;
-
-        if (cpi->buffer_level > drop_mark75 && cpi->decimation_factor > 0)
-            cpi->decimation_factor = 1;
-
-        else if (cpi->buffer_level < drop_mark25 && (cpi->decimation_factor == 2 || cpi->decimation_factor == 3))
-        {
-            cpi->decimation_factor = 3;
-        }
-        else if (cpi->buffer_level < drop_mark50 && (cpi->decimation_factor == 1 || cpi->decimation_factor == 2))
-        {
-            cpi->decimation_factor = 2;
-        }
-        else if (cpi->buffer_level < drop_mark75 && (cpi->decimation_factor == 0 || cpi->decimation_factor == 1))
-        {
-            cpi->decimation_factor = 1;
-        }
-    }
-
-    /* The following decimates the frame rate according to a regular
-     * pattern (i.e. to 1/2 or 2/3 frame rate) This can be used to help
-     * prevent buffer under-run in CBR mode. Alternatively it might be
-     * desirable in some situations to drop frame rate but throw more bits
-     * at each frame.
-     *
-     * Note that dropping a key frame can be problematic if spatial
-     * resampling is also active
-     */
-    if (cpi->decimation_factor > 0)
-    {
-        switch (cpi->decimation_factor)
-        {
-        case 1:
-            cpi->per_frame_bandwidth  = cpi->per_frame_bandwidth * 3 / 2;
-            break;
-        case 2:
-            cpi->per_frame_bandwidth  = cpi->per_frame_bandwidth * 5 / 4;
-            break;
-        case 3:
-            cpi->per_frame_bandwidth  = cpi->per_frame_bandwidth * 5 / 4;
-            break;
-        }
-
-        /* Note that we should not throw out a key frame (especially when
-         * spatial resampling is enabled).
-         */
-        if (cm->frame_type == KEY_FRAME)
-        {
-            cpi->decimation_count = cpi->decimation_factor;
-        }
-        else if (cpi->decimation_count > 0)
-        {
-            cpi->decimation_count --;
-
-            cpi->bits_off_target += cpi->av_per_frame_bandwidth;
-            if (cpi->bits_off_target > cpi->oxcf.maximum_buffer_size)
-                cpi->bits_off_target = cpi->oxcf.maximum_buffer_size;
-
-#if CONFIG_MULTI_RES_ENCODING
-            vp8_store_drop_frame_info(cpi);
-#endif
-
-            cm->current_video_frame++;
-            cpi->frames_since_key++;
-            // We advance the temporal pattern for dropped frames.
-            cpi->temporal_pattern_counter++;
-
-#if CONFIG_INTERNAL_STATS
-            cpi->count ++;
-#endif
-
-            cpi->buffer_level = cpi->bits_off_target;
-
-            if (cpi->oxcf.number_of_layers > 1)
-            {
-                unsigned int i;
-
-                /* Propagate bits saved by dropping the frame to higher
-                 * layers
-                 */
-                for (i=cpi->current_layer+1; i<cpi->oxcf.number_of_layers; i++)
-                {
-                    LAYER_CONTEXT *lc = &cpi->layer_context[i];
-                    lc->bits_off_target += (int)(lc->target_bandwidth /
-                                                 lc->framerate);
-                    if (lc->bits_off_target > lc->maximum_buffer_size)
-                        lc->bits_off_target = lc->maximum_buffer_size;
-                    lc->buffer_level = lc->bits_off_target;
-                }
-            }
-
-            return;
-        }
-        else
-            cpi->decimation_count = cpi->decimation_factor;
-    }
-    else
-        cpi->decimation_count = 0;
-
-    /* Decide how big to make the frame */
-    if (!vp8_pick_frame_size(cpi))
-    {
-        /*TODO: 2 drop_frame and return code could be put together. */
-#if CONFIG_MULTI_RES_ENCODING
-        vp8_store_drop_frame_info(cpi);
-#endif
-        cm->current_video_frame++;
-        cpi->frames_since_key++;
-        // We advance the temporal pattern for dropped frames.
-        cpi->temporal_pattern_counter++;
-        return;
-    }
-
-    /* Reduce active_worst_allowed_q for CBR if our buffer is getting too full.
-     * This has a knock on effect on active best quality as well.
-     * For CBR if the buffer reaches its maximum level then we can no longer
-     * save up bits for later frames so we might as well use them up
-     * on the current frame.
-     */
-    if ((cpi->oxcf.end_usage == USAGE_STREAM_FROM_SERVER) &&
-        (cpi->buffer_level >= cpi->oxcf.optimal_buffer_level) && cpi->buffered_mode)
-    {
-        /* Max adjustment is 1/4 */
-        int Adjustment = cpi->active_worst_quality / 4;
-
-        if (Adjustment)
-        {
-            int buff_lvl_step;
-
-            if (cpi->buffer_level < cpi->oxcf.maximum_buffer_size)
-            {
-                buff_lvl_step = (int)
-                                ((cpi->oxcf.maximum_buffer_size -
-                                  cpi->oxcf.optimal_buffer_level) /
-                                  Adjustment);
-
-                if (buff_lvl_step)
-                    Adjustment = (int)
-                                 ((cpi->buffer_level -
-                                 cpi->oxcf.optimal_buffer_level) /
-                                 buff_lvl_step);
-                else
-                    Adjustment = 0;
-            }
-
-            cpi->active_worst_quality -= Adjustment;
-
-            if(cpi->active_worst_quality < cpi->active_best_quality)
-                cpi->active_worst_quality = cpi->active_best_quality;
-        }
-    }
-
-    /* Set an active best quality and if necessary active worst quality
-     * There is some odd behavior for one pass here that needs attention.
-     */
-    if ( (cpi->pass == 2) || (cpi->ni_frames > 150))
-    {
-        vp8_clear_system_state();
-
-        Q = cpi->active_worst_quality;
-
-        if ( cm->frame_type == KEY_FRAME )
-        {
-            if ( cpi->pass == 2 )
-            {
-                if (cpi->gfu_boost > 600)
-                   cpi->active_best_quality = kf_low_motion_minq[Q];
-                else
-                   cpi->active_best_quality = kf_high_motion_minq[Q];
-
-                /* Special case for key frames forced because we have reached
-                 * the maximum key frame interval. Here force the Q to a range
-                 * based on the ambient Q to reduce the risk of popping
-                 */
-                if ( cpi->this_key_frame_forced )
-                {
-                    if ( cpi->active_best_quality > cpi->avg_frame_qindex * 7/8)
-                        cpi->active_best_quality = cpi->avg_frame_qindex * 7/8;
-                    else if ( cpi->active_best_quality < cpi->avg_frame_qindex >> 2 )
-                        cpi->active_best_quality = cpi->avg_frame_qindex >> 2;
-                }
-            }
-            /* One pass more conservative */
-            else
-               cpi->active_best_quality = kf_high_motion_minq[Q];
-        }
-
-        else if (cpi->oxcf.number_of_layers==1 &&
-                (cm->refresh_golden_frame || cpi->common.refresh_alt_ref_frame))
-        {
-            /* Use the lower of cpi->active_worst_quality and recent
-             * average Q as basis for GF/ARF Q limit unless last frame was
-             * a key frame.
-             */
-            if ( (cpi->frames_since_key > 1) &&
-               (cpi->avg_frame_qindex < cpi->active_worst_quality) )
-            {
-                Q = cpi->avg_frame_qindex;
-            }
-
-            /* For constrained quality dont allow Q less than the cq level */
-            if ( (cpi->oxcf.end_usage == USAGE_CONSTRAINED_QUALITY) &&
-                 (Q < cpi->cq_target_quality) )
-            {
-                Q = cpi->cq_target_quality;
-            }
-
-            if ( cpi->pass == 2 )
-            {
-                if ( cpi->gfu_boost > 1000 )
-                    cpi->active_best_quality = gf_low_motion_minq[Q];
-                else if ( cpi->gfu_boost < 400 )
-                    cpi->active_best_quality = gf_high_motion_minq[Q];
-                else
-                    cpi->active_best_quality = gf_mid_motion_minq[Q];
-
-                /* Constrained quality use slightly lower active best. */
-                if ( cpi->oxcf.end_usage == USAGE_CONSTRAINED_QUALITY )
-                {
-                    cpi->active_best_quality =
-                        cpi->active_best_quality * 15/16;
-                }
-            }
-            /* One pass more conservative */
-            else
-                cpi->active_best_quality = gf_high_motion_minq[Q];
-        }
-        else
-        {
-            cpi->active_best_quality = inter_minq[Q];
-
-            /* For the constant/constrained quality mode we dont want
-             * q to fall below the cq level.
-             */
-            if ((cpi->oxcf.end_usage == USAGE_CONSTRAINED_QUALITY) &&
-                (cpi->active_best_quality < cpi->cq_target_quality) )
-            {
-                /* If we are strongly undershooting the target rate in the last
-                 * frames then use the user passed in cq value not the auto
-                 * cq value.
-                 */
-                if ( cpi->rolling_actual_bits < cpi->min_frame_bandwidth )
-                    cpi->active_best_quality = cpi->oxcf.cq_level;
-                else
-                    cpi->active_best_quality = cpi->cq_target_quality;
-            }
-        }
-
-        /* If CBR and the buffer is as full then it is reasonable to allow
-         * higher quality on the frames to prevent bits just going to waste.
-         */
-        if (cpi->oxcf.end_usage == USAGE_STREAM_FROM_SERVER)
-        {
-            /* Note that the use of >= here elliminates the risk of a devide
-             * by 0 error in the else if clause
-             */
-            if (cpi->buffer_level >= cpi->oxcf.maximum_buffer_size)
-                cpi->active_best_quality = cpi->best_quality;
-
-            else if (cpi->buffer_level > cpi->oxcf.optimal_buffer_level)
-            {
-                int Fraction = (int)
-                  (((cpi->buffer_level - cpi->oxcf.optimal_buffer_level) * 128)
-                  / (cpi->oxcf.maximum_buffer_size -
-                  cpi->oxcf.optimal_buffer_level));
-                int min_qadjustment = ((cpi->active_best_quality -
-                                        cpi->best_quality) * Fraction) / 128;
-
-                cpi->active_best_quality -= min_qadjustment;
-            }
-        }
-    }
-    /* Make sure constrained quality mode limits are adhered to for the first
-     * few frames of one pass encodes
-     */
-    else if (cpi->oxcf.end_usage == USAGE_CONSTRAINED_QUALITY)
-    {
-        if ( (cm->frame_type == KEY_FRAME) ||
-             cm->refresh_golden_frame || cpi->common.refresh_alt_ref_frame )
-        {
-             cpi->active_best_quality = cpi->best_quality;
-        }
-        else if (cpi->active_best_quality < cpi->cq_target_quality)
-        {
-            cpi->active_best_quality = cpi->cq_target_quality;
-        }
-    }
-
-    /* Clip the active best and worst quality values to limits */
-    if (cpi->active_worst_quality > cpi->worst_quality)
-        cpi->active_worst_quality = cpi->worst_quality;
-
-    if (cpi->active_best_quality < cpi->best_quality)
-        cpi->active_best_quality = cpi->best_quality;
-
-    if ( cpi->active_worst_quality < cpi->active_best_quality )
-        cpi->active_worst_quality = cpi->active_best_quality;
-
-    /* Determine initial Q to try */
-    Q = vp8_regulate_q(cpi, cpi->this_frame_target);
-
-#if !CONFIG_REALTIME_ONLY
-
-    /* Set highest allowed value for Zbin over quant */
-    if (cm->frame_type == KEY_FRAME)
-        zbin_oq_high = 0;
-    else if ((cpi->oxcf.number_of_layers == 1) && ((cm->refresh_alt_ref_frame ||
-              (cm->refresh_golden_frame && !cpi->source_alt_ref_active))))
-    {
-          zbin_oq_high = 16;
-    }
-    else
-        zbin_oq_high = ZBIN_OQ_MAX;
-#endif
-
-    /* Setup background Q adjustment for error resilient mode.
-     * For multi-layer encodes only enable this for the base layer.
-    */
-    if (cpi->cyclic_refresh_mode_enabled)
-    {
-      // Special case for screen_content_mode with golden frame updates.
-      int disable_cr_gf = (cpi->oxcf.screen_content_mode == 2 &&
-                           cm->refresh_golden_frame);
-      if (cpi->current_layer == 0 && cpi->force_maxqp == 0 && !disable_cr_gf)
-        cyclic_background_refresh(cpi, Q, 0);
-      else
-        disable_segmentation(cpi);
-    }
-
-    vp8_compute_frame_size_bounds(cpi, &frame_under_shoot_limit, &frame_over_shoot_limit);
-
-#if !CONFIG_REALTIME_ONLY
-    /* Limit Q range for the adaptive loop. */
-    bottom_index = cpi->active_best_quality;
-    top_index    = cpi->active_worst_quality;
-    q_low  = cpi->active_best_quality;
-    q_high = cpi->active_worst_quality;
-#endif
-
-    vp8_save_coding_context(cpi);
-
-    loop_count = 0;
-
-    scale_and_extend_source(cpi->un_scaled_source, cpi);
-
-#if CONFIG_TEMPORAL_DENOISING && CONFIG_POSTPROC
-    // Option to apply spatial blur under the aggressive or adaptive
-    // (temporal denoising) mode.
-    if (cpi->oxcf.noise_sensitivity >= 3) {
-      if (cpi->denoiser.denoise_pars.spatial_blur != 0) {
-        vp8_de_noise(cm, cpi->Source, cpi->Source,
-            cpi->denoiser.denoise_pars.spatial_blur, 1, 0, 0);
-      }
-    }
-#endif
-
-#if !(CONFIG_REALTIME_ONLY) && CONFIG_POSTPROC && !(CONFIG_TEMPORAL_DENOISING)
-
-    if (cpi->oxcf.noise_sensitivity > 0)
-    {
-        unsigned char *src;
-        int l = 0;
-
-        switch (cpi->oxcf.noise_sensitivity)
-        {
-        case 1:
-            l = 20;
-            break;
-        case 2:
-            l = 40;
-            break;
-        case 3:
-            l = 60;
-            break;
-        case 4:
-            l = 80;
-            break;
-        case 5:
-            l = 100;
-            break;
-        case 6:
-            l = 150;
-            break;
-        }
-
-
-        if (cm->frame_type == KEY_FRAME)
-        {
-            vp8_de_noise(cm, cpi->Source, cpi->Source, l , 1,  0, 1);
-        }
-        else
-        {
-            vp8_de_noise(cm, cpi->Source, cpi->Source, l , 1,  0, 1);
-
-            src = cpi->Source->y_buffer;
-
-            if (cpi->Source->y_stride < 0)
-            {
-                src += cpi->Source->y_stride * (cpi->Source->y_height - 1);
-            }
-        }
-    }
-
-#endif
-
-
-#ifdef OUTPUT_YUV_SRC
-    vp8_write_yuv_frame(yuv_file, cpi->Source);
-#endif
-
-    do
-    {
-        vp8_clear_system_state();
-
-        vp8_set_quantizer(cpi, Q);
-
-        /* setup skip prob for costing in mode/mv decision */
-        if (cpi->common.mb_no_coeff_skip)
-        {
-            cpi->prob_skip_false = cpi->base_skip_false_prob[Q];
-
-            if (cm->frame_type != KEY_FRAME)
-            {
-                if (cpi->common.refresh_alt_ref_frame)
-                {
-                    if (cpi->last_skip_false_probs[2] != 0)
-                        cpi->prob_skip_false = cpi->last_skip_false_probs[2];
-
-                    /*
-                                        if(cpi->last_skip_false_probs[2]!=0 && abs(Q- cpi->last_skip_probs_q[2])<=16 )
-                       cpi->prob_skip_false = cpi->last_skip_false_probs[2];
-                                        else if (cpi->last_skip_false_probs[2]!=0)
-                       cpi->prob_skip_false = (cpi->last_skip_false_probs[2]  + cpi->prob_skip_false ) / 2;
-                       */
-                }
-                else if (cpi->common.refresh_golden_frame)
-                {
-                    if (cpi->last_skip_false_probs[1] != 0)
-                        cpi->prob_skip_false = cpi->last_skip_false_probs[1];
-
-                    /*
-                                        if(cpi->last_skip_false_probs[1]!=0 && abs(Q- cpi->last_skip_probs_q[1])<=16 )
-                       cpi->prob_skip_false = cpi->last_skip_false_probs[1];
-                                        else if (cpi->last_skip_false_probs[1]!=0)
-                       cpi->prob_skip_false = (cpi->last_skip_false_probs[1]  + cpi->prob_skip_false ) / 2;
-                       */
-                }
-                else
-                {
-                    if (cpi->last_skip_false_probs[0] != 0)
-                        cpi->prob_skip_false = cpi->last_skip_false_probs[0];
-
-                    /*
-                    if(cpi->last_skip_false_probs[0]!=0 && abs(Q- cpi->last_skip_probs_q[0])<=16 )
-                        cpi->prob_skip_false = cpi->last_skip_false_probs[0];
-                    else if(cpi->last_skip_false_probs[0]!=0)
-                        cpi->prob_skip_false = (cpi->last_skip_false_probs[0]  + cpi->prob_skip_false ) / 2;
-                        */
-                }
-
-                /* as this is for cost estimate, let's make sure it does not
-                 * go extreme eitehr way
-                 */
-                if (cpi->prob_skip_false < 5)
-                    cpi->prob_skip_false = 5;
-
-                if (cpi->prob_skip_false > 250)
-                    cpi->prob_skip_false = 250;
-
-                if (cpi->oxcf.number_of_layers == 1 && cpi->is_src_frame_alt_ref)
-                    cpi->prob_skip_false = 1;
-            }
-
-#if 0
-
-            if (cpi->pass != 1)
-            {
-                FILE *f = fopen("skip.stt", "a");
-                fprintf(f, "%d, %d, %4d ", cpi->common.refresh_golden_frame, cpi->common.refresh_alt_ref_frame, cpi->prob_skip_false);
-                fclose(f);
-            }
-
-#endif
-
-        }
-
-        if (cm->frame_type == KEY_FRAME)
-        {
-            if(resize_key_frame(cpi))
-            {
-              /* If the frame size has changed, need to reset Q, quantizer,
-               * and background refresh.
-               */
-              Q = vp8_regulate_q(cpi, cpi->this_frame_target);
-              if (cpi->cyclic_refresh_mode_enabled)
-              {
-                if (cpi->current_layer==0)
-                  cyclic_background_refresh(cpi, Q, 0);
-                else
-                  disable_segmentation(cpi);
-              }
-              // Reset the zero_last counter to 0 on key frame.
-              memset(cpi->consec_zero_last, 0, cm->mb_rows * cm->mb_cols);
-              memset(cpi->consec_zero_last_mvbias, 0,
-                     (cpi->common.mb_rows * cpi->common.mb_cols));
-              vp8_set_quantizer(cpi, Q);
-            }
-
-            vp8_setup_key_frame(cpi);
-        }
-
-#if CONFIG_REALTIME_ONLY & CONFIG_ONTHEFLY_BITPACKING
-        {
-            if(cpi->oxcf.error_resilient_mode)
-                cm->refresh_entropy_probs = 0;
-
-            if (cpi->oxcf.error_resilient_mode & VPX_ERROR_RESILIENT_PARTITIONS)
-            {
-                if (cm->frame_type == KEY_FRAME)
-                    cm->refresh_entropy_probs = 1;
-            }
-
-            if (cm->refresh_entropy_probs == 0)
-            {
-                /* save a copy for later refresh */
-                memcpy(&cm->lfc, &cm->fc, sizeof(cm->fc));
-            }
-
-            vp8_update_coef_context(cpi);
-
-            vp8_update_coef_probs(cpi);
-
-            /* transform / motion compensation build reconstruction frame
-             * +pack coef partitions
-             */
-            vp8_encode_frame(cpi);
-
-            /* cpi->projected_frame_size is not needed for RT mode */
-        }
-#else
-        /* transform / motion compensation build reconstruction frame */
-        vp8_encode_frame(cpi);
-
-        if (cpi->oxcf.screen_content_mode == 2) {
-          if (vp8_drop_encodedframe_overshoot(cpi, Q))
-            return;
-        }
-
-        cpi->projected_frame_size -= vp8_estimate_entropy_savings(cpi);
-        cpi->projected_frame_size = (cpi->projected_frame_size > 0) ? cpi->projected_frame_size : 0;
-#endif
-        vp8_clear_system_state();
-
-        /* Test to see if the stats generated for this frame indicate that
-         * we should have coded a key frame (assuming that we didn't)!
-         */
-
-        if (cpi->pass != 2 && cpi->oxcf.auto_key && cm->frame_type != KEY_FRAME
-            && cpi->compressor_speed != 2)
-        {
-#if !CONFIG_REALTIME_ONLY
-            if (decide_key_frame(cpi))
-            {
-                /* Reset all our sizing numbers and recode */
-                cm->frame_type = KEY_FRAME;
-
-                vp8_pick_frame_size(cpi);
-
-                /* Clear the Alt reference frame active flag when we have
-                 * a key frame
-                 */
-                cpi->source_alt_ref_active = 0;
-
-                // Set the loop filter deltas and segmentation map update
-                setup_features(cpi);
-
-                vp8_restore_coding_context(cpi);
-
-                Q = vp8_regulate_q(cpi, cpi->this_frame_target);
-
-                vp8_compute_frame_size_bounds(cpi, &frame_under_shoot_limit, &frame_over_shoot_limit);
-
-                /* Limit Q range for the adaptive loop. */
-                bottom_index = cpi->active_best_quality;
-                top_index    = cpi->active_worst_quality;
-                q_low  = cpi->active_best_quality;
-                q_high = cpi->active_worst_quality;
-
-                loop_count++;
-                Loop = 1;
-
-                continue;
-            }
-#endif
-        }
-
-        vp8_clear_system_state();
-
-        if (frame_over_shoot_limit == 0)
-            frame_over_shoot_limit = 1;
-
-        /* Are we are overshooting and up against the limit of active max Q. */
-        if (((cpi->pass != 2) || (cpi->oxcf.end_usage == USAGE_STREAM_FROM_SERVER)) &&
-            (Q == cpi->active_worst_quality)                     &&
-            (cpi->active_worst_quality < cpi->worst_quality)      &&
-            (cpi->projected_frame_size > frame_over_shoot_limit))
-        {
-            int over_size_percent = ((cpi->projected_frame_size - frame_over_shoot_limit) * 100) / frame_over_shoot_limit;
-
-            /* If so is there any scope for relaxing it */
-            while ((cpi->active_worst_quality < cpi->worst_quality) && (over_size_percent > 0))
-            {
-                cpi->active_worst_quality++;
-                /* Assume 1 qstep = about 4% on frame size. */
-                over_size_percent = (int)(over_size_percent * 0.96);
-            }
-#if !CONFIG_REALTIME_ONLY
-            top_index = cpi->active_worst_quality;
-#endif  // !CONFIG_REALTIME_ONLY
-            /* If we have updated the active max Q do not call
-             * vp8_update_rate_correction_factors() this loop.
-             */
-            active_worst_qchanged = 1;
-        }
-        else
-            active_worst_qchanged = 0;
-
-#if !CONFIG_REALTIME_ONLY
-        /* Special case handling for forced key frames */
-        if ( (cm->frame_type == KEY_FRAME) && cpi->this_key_frame_forced )
-        {
-            int last_q = Q;
-            int kf_err = vp8_calc_ss_err(cpi->Source,
-                                         &cm->yv12_fb[cm->new_fb_idx]);
-
-            /* The key frame is not good enough */
-            if ( kf_err > ((cpi->ambient_err * 7) >> 3) )
-            {
-                /* Lower q_high */
-                q_high = (Q > q_low) ? (Q - 1) : q_low;
-
-                /* Adjust Q */
-                Q = (q_high + q_low) >> 1;
-            }
-            /* The key frame is much better than the previous frame */
-            else if ( kf_err < (cpi->ambient_err >> 1) )
-            {
-                /* Raise q_low */
-                q_low = (Q < q_high) ? (Q + 1) : q_high;
-
-                /* Adjust Q */
-                Q = (q_high + q_low + 1) >> 1;
-            }
-
-            /* Clamp Q to upper and lower limits: */
-            if (Q > q_high)
-                Q = q_high;
-            else if (Q < q_low)
-                Q = q_low;
-
-            Loop = Q != last_q;
-        }
-
-        /* Is the projected frame size out of range and are we allowed
-         * to attempt to recode.
-         */
-        else if ( recode_loop_test( cpi,
-                               frame_over_shoot_limit, frame_under_shoot_limit,
-                               Q, top_index, bottom_index ) )
-        {
-            int last_q = Q;
-            int Retries = 0;
-
-            /* Frame size out of permitted range. Update correction factor
-             * & compute new Q to try...
-             */
-
-            /* Frame is too large */
-            if (cpi->projected_frame_size > cpi->this_frame_target)
-            {
-                /* Raise Qlow as to at least the current value */
-                q_low = (Q < q_high) ? (Q + 1) : q_high;
-
-                /* If we are using over quant do the same for zbin_oq_low */
-                if (cpi->mb.zbin_over_quant > 0)
-                    zbin_oq_low = (cpi->mb.zbin_over_quant < zbin_oq_high) ?
-                        (cpi->mb.zbin_over_quant + 1) : zbin_oq_high;
-
-                if (undershoot_seen)
-                {
-                    /* Update rate_correction_factor unless
-                     * cpi->active_worst_quality has changed.
-                     */
-                    if (!active_worst_qchanged)
-                        vp8_update_rate_correction_factors(cpi, 1);
-
-                    Q = (q_high + q_low + 1) / 2;
-
-                    /* Adjust cpi->zbin_over_quant (only allowed when Q
-                     * is max)
-                     */
-                    if (Q < MAXQ)
-                        cpi->mb.zbin_over_quant = 0;
-                    else
-                    {
-                        zbin_oq_low = (cpi->mb.zbin_over_quant < zbin_oq_high) ?
-                            (cpi->mb.zbin_over_quant + 1) : zbin_oq_high;
-                        cpi->mb.zbin_over_quant =
-                            (zbin_oq_high + zbin_oq_low) / 2;
-                    }
-                }
-                else
-                {
-                    /* Update rate_correction_factor unless
-                     * cpi->active_worst_quality has changed.
-                     */
-                    if (!active_worst_qchanged)
-                        vp8_update_rate_correction_factors(cpi, 0);
-
-                    Q = vp8_regulate_q(cpi, cpi->this_frame_target);
-
-                    while (((Q < q_low) ||
-                        (cpi->mb.zbin_over_quant < zbin_oq_low)) &&
-                        (Retries < 10))
-                    {
-                        vp8_update_rate_correction_factors(cpi, 0);
-                        Q = vp8_regulate_q(cpi, cpi->this_frame_target);
-                        Retries ++;
-                    }
-                }
-
-                overshoot_seen = 1;
-            }
-            /* Frame is too small */
-            else
-            {
-                if (cpi->mb.zbin_over_quant == 0)
-                    /* Lower q_high if not using over quant */
-                    q_high = (Q > q_low) ? (Q - 1) : q_low;
-                else
-                    /* else lower zbin_oq_high */
-                    zbin_oq_high = (cpi->mb.zbin_over_quant > zbin_oq_low) ?
-                        (cpi->mb.zbin_over_quant - 1) : zbin_oq_low;
-
-                if (overshoot_seen)
-                {
-                    /* Update rate_correction_factor unless
-                     * cpi->active_worst_quality has changed.
-                     */
-                    if (!active_worst_qchanged)
-                        vp8_update_rate_correction_factors(cpi, 1);
-
-                    Q = (q_high + q_low) / 2;
-
-                    /* Adjust cpi->zbin_over_quant (only allowed when Q
-                     * is max)
-                     */
-                    if (Q < MAXQ)
-                        cpi->mb.zbin_over_quant = 0;
-                    else
-                        cpi->mb.zbin_over_quant =
-                            (zbin_oq_high + zbin_oq_low) / 2;
-                }
-                else
-                {
-                    /* Update rate_correction_factor unless
-                     * cpi->active_worst_quality has changed.
-                     */
-                    if (!active_worst_qchanged)
-                        vp8_update_rate_correction_factors(cpi, 0);
-
-                    Q = vp8_regulate_q(cpi, cpi->this_frame_target);
-
-                    /* Special case reset for qlow for constrained quality.
-                     * This should only trigger where there is very substantial
-                     * undershoot on a frame and the auto cq level is above
-                     * the user passsed in value.
-                     */
-                    if ( (cpi->oxcf.end_usage == USAGE_CONSTRAINED_QUALITY) &&
-                         (Q < q_low) )
-                    {
-                        q_low = Q;
-                    }
-
-                    while (((Q > q_high) ||
-                        (cpi->mb.zbin_over_quant > zbin_oq_high)) &&
-                        (Retries < 10))
-                    {
-                        vp8_update_rate_correction_factors(cpi, 0);
-                        Q = vp8_regulate_q(cpi, cpi->this_frame_target);
-                        Retries ++;
-                    }
-                }
-
-                undershoot_seen = 1;
-            }
-
-            /* Clamp Q to upper and lower limits: */
-            if (Q > q_high)
-                Q = q_high;
-            else if (Q < q_low)
-                Q = q_low;
-
-            /* Clamp cpi->zbin_over_quant */
-            cpi->mb.zbin_over_quant = (cpi->mb.zbin_over_quant < zbin_oq_low) ?
-                zbin_oq_low : (cpi->mb.zbin_over_quant > zbin_oq_high) ?
-                    zbin_oq_high : cpi->mb.zbin_over_quant;
-
-            Loop = Q != last_q;
-        }
-        else
-#endif
-            Loop = 0;
-
-        if (cpi->is_src_frame_alt_ref)
-            Loop = 0;
-
-        if (Loop == 1)
-        {
-            vp8_restore_coding_context(cpi);
-            loop_count++;
-#if CONFIG_INTERNAL_STATS
-            cpi->tot_recode_hits++;
-#endif
-        }
-    }
-    while (Loop == 1);
-
-#if 0
-    /* Experimental code for lagged and one pass
-     * Update stats used for one pass GF selection
-     */
-    {
-        cpi->one_pass_frame_stats[cpi->one_pass_frame_index].frame_coded_error = (double)cpi->prediction_error;
-        cpi->one_pass_frame_stats[cpi->one_pass_frame_index].frame_intra_error = (double)cpi->intra_error;
-        cpi->one_pass_frame_stats[cpi->one_pass_frame_index].frame_pcnt_inter = (double)(100 - cpi->this_frame_percent_intra) / 100.0;
-    }
-#endif
-
-    /* Special case code to reduce pulsing when key frames are forced at a
-     * fixed interval. Note the reconstruction error if it is the frame before
-     * the force key frame
-     */
-    if ( cpi->next_key_frame_forced && (cpi->twopass.frames_to_key == 0) )
-    {
-        cpi->ambient_err = vp8_calc_ss_err(cpi->Source,
-                                           &cm->yv12_fb[cm->new_fb_idx]);
-    }
-
-    /* This frame's MVs are saved and will be used in next frame's MV predictor.
-     * Last frame has one more line(add to bottom) and one more column(add to
-     * right) than cm->mip. The edge elements are initialized to 0.
-     */
-#if CONFIG_MULTI_RES_ENCODING
-    if(!cpi->oxcf.mr_encoder_id && cm->show_frame)
-#else
-    if(cm->show_frame)   /* do not save for altref frame */
-#endif
-    {
-        int mb_row;
-        int mb_col;
-        /* Point to beginning of allocated MODE_INFO arrays. */
-        MODE_INFO *tmp = cm->mip;
-
-        if(cm->frame_type != KEY_FRAME)
-        {
-            for (mb_row = 0; mb_row < cm->mb_rows+1; mb_row ++)
-            {
-                for (mb_col = 0; mb_col < cm->mb_cols+1; mb_col ++)
-                {
-                    if(tmp->mbmi.ref_frame != INTRA_FRAME)
-                        cpi->lfmv[mb_col + mb_row*(cm->mode_info_stride+1)].as_int = tmp->mbmi.mv.as_int;
-
-                    cpi->lf_ref_frame_sign_bias[mb_col + mb_row*(cm->mode_info_stride+1)] = cm->ref_frame_sign_bias[tmp->mbmi.ref_frame];
-                    cpi->lf_ref_frame[mb_col + mb_row*(cm->mode_info_stride+1)] = tmp->mbmi.ref_frame;
-                    tmp++;
-                }
-            }
-        }
-    }
-
-    /* Count last ref frame 0,0 usage on current encoded frame. */
-    {
-        int mb_row;
-        int mb_col;
-        /* Point to beginning of MODE_INFO arrays. */
-        MODE_INFO *tmp = cm->mi;
-
-        cpi->zeromv_count = 0;
-
-        if(cm->frame_type != KEY_FRAME)
-        {
-            for (mb_row = 0; mb_row < cm->mb_rows; mb_row ++)
-            {
-                for (mb_col = 0; mb_col < cm->mb_cols; mb_col ++)
-                {
-                    if (tmp->mbmi.mode == ZEROMV &&
-                       tmp->mbmi.ref_frame == LAST_FRAME)
-                        cpi->zeromv_count++;
-                    tmp++;
-                }
-                tmp++;
-            }
-        }
-    }
-
-#if CONFIG_MULTI_RES_ENCODING
-    vp8_cal_dissimilarity(cpi);
-#endif
-
-    /* Update the GF useage maps.
-     * This is done after completing the compression of a frame when all
-     * modes etc. are finalized but before loop filter
-     */
-    if (cpi->oxcf.number_of_layers == 1)
-        vp8_update_gf_useage_maps(cpi, cm, &cpi->mb);
-
-    if (cm->frame_type == KEY_FRAME)
-        cm->refresh_last_frame = 1;
-
-#if 0
-    {
-        FILE *f = fopen("gfactive.stt", "a");
-        fprintf(f, "%8d %8d %8d %8d %8d\n", cm->current_video_frame, (100 * cpi->gf_active_count) / (cpi->common.mb_rows * cpi->common.mb_cols), cpi->this_iiratio, cpi->next_iiratio, cm->refresh_golden_frame);
-        fclose(f);
-    }
-#endif
-
-    /* For inter frames the current default behavior is that when
-     * cm->refresh_golden_frame is set we copy the old GF over to the ARF buffer
-     * This is purely an encoder decision at present.
-     */
-    if (!cpi->oxcf.error_resilient_mode && cm->refresh_golden_frame)
-        cm->copy_buffer_to_arf  = 2;
-    else
-        cm->copy_buffer_to_arf  = 0;
-
-    cm->frame_to_show = &cm->yv12_fb[cm->new_fb_idx];
-
-#if CONFIG_TEMPORAL_DENOISING
-    // Get some measure of the amount of noise, by measuring the (partial) mse
-    // between source and denoised buffer, for y channel. Partial refers to
-    // computing the sse for a sub-sample of the frame (i.e., skip x blocks along row/column),
-    // and only for blocks in that set that are consecutive ZEROMV_LAST mode.
-    // Do this every ~8 frames, to further reduce complexity.
-    // TODO(marpan): Keep this for now for the case cpi->oxcf.noise_sensitivity < 4,
-    // should be removed in favor of the process_denoiser_mode_change() function below.
-    if (cpi->oxcf.noise_sensitivity > 0 &&
-       cpi->oxcf.noise_sensitivity < 4 &&
-       !cpi->oxcf.screen_content_mode &&
-       cpi->frames_since_key%8 == 0 &&
-       cm->frame_type != KEY_FRAME) {
-       cpi->mse_source_denoised = measure_square_diff_partial(
-           &cpi->denoiser.yv12_running_avg[INTRA_FRAME], cpi->Source, cpi);
-    }
-
-    // For the adaptive denoising mode (noise_sensitivity == 4), sample the mse
-    // of source diff (between current and previous frame), and determine if we
-    // should switch the denoiser mode. Sampling refers to computing the mse for
-    // a sub-sample of the frame (i.e., skip x blocks along row/column), and
-    // only for blocks in that set that have used ZEROMV LAST, along with some
-    // constraint on the sum diff between blocks. This process is called every
-    // ~8 frames, to further reduce complexity.
-    if (cpi->oxcf.noise_sensitivity == 4 &&
-        !cpi->oxcf.screen_content_mode &&
-        cpi->frames_since_key % 8 == 0 &&
-        cm->frame_type != KEY_FRAME) {
-      process_denoiser_mode_change(cpi);
-    }
-#endif
-
-#if CONFIG_MULTITHREAD
-    if (cpi->b_multi_threaded)
-    {
-        /* start loopfilter in separate thread */
-        sem_post(&cpi->h_event_start_lpf);
-    }
-    else
-#endif
-    {
-        vp8_loopfilter_frame(cpi, cm);
-    }
-
-    update_reference_frames(cpi);
-
-#ifdef OUTPUT_YUV_DENOISED
-    vp8_write_yuv_frame(yuv_denoised_file,
-                        &cpi->denoiser.yv12_running_avg[INTRA_FRAME]);
-#endif
-
-#if !(CONFIG_REALTIME_ONLY & CONFIG_ONTHEFLY_BITPACKING)
-    if (cpi->oxcf.error_resilient_mode)
-    {
-        cm->refresh_entropy_probs = 0;
-    }
-#endif
-
-#if CONFIG_MULTITHREAD
-    /* wait that filter_level is picked so that we can continue with stream packing */
-    if (cpi->b_multi_threaded)
-        sem_wait(&cpi->h_event_end_lpf);
-#endif
-
-    /* build the bitstream */
-    vp8_pack_bitstream(cpi, dest, dest_end, size);
-
-#if CONFIG_MULTITHREAD
-    /* wait for the lpf thread done */
-    if (cpi->b_multi_threaded)
-    {
-        sem_wait(&cpi->h_event_end_lpf);
-    }
-#endif
-
-    /* Move storing frame_type out of the above loop since it is also
-     * needed in motion search besides loopfilter */
-    cm->last_frame_type = cm->frame_type;
-
-    /* Update rate control heuristics */
-    cpi->total_byte_count += (*size);
-    cpi->projected_frame_size = (*size) << 3;
-
-    if (cpi->oxcf.number_of_layers > 1)
-    {
-        unsigned int i;
-        for (i=cpi->current_layer+1; i<cpi->oxcf.number_of_layers; i++)
-          cpi->layer_context[i].total_byte_count += (*size);
-    }
-
-    if (!active_worst_qchanged)
-        vp8_update_rate_correction_factors(cpi, 2);
-
-    cpi->last_q[cm->frame_type] = cm->base_qindex;
-
-    if (cm->frame_type == KEY_FRAME)
-    {
-        vp8_adjust_key_frame_context(cpi);
-    }
-
-    /* Keep a record of ambient average Q. */
-    if (cm->frame_type != KEY_FRAME)
-        cpi->avg_frame_qindex = (2 + 3 * cpi->avg_frame_qindex + cm->base_qindex) >> 2;
-
-    /* Keep a record from which we can calculate the average Q excluding
-     * GF updates and key frames
-     */
-    if ((cm->frame_type != KEY_FRAME) && ((cpi->oxcf.number_of_layers > 1) ||
-        (!cm->refresh_golden_frame && !cm->refresh_alt_ref_frame)))
-    {
-        cpi->ni_frames++;
-
-        /* Calculate the average Q for normal inter frames (not key or GFU
-         * frames).
-         */
-        if ( cpi->pass == 2 )
-        {
-            cpi->ni_tot_qi += Q;
-            cpi->ni_av_qi = (cpi->ni_tot_qi / cpi->ni_frames);
-        }
-        else
-        {
-            /* Damp value for first few frames */
-            if (cpi->ni_frames > 150 )
-            {
-                cpi->ni_tot_qi += Q;
-                cpi->ni_av_qi = (cpi->ni_tot_qi / cpi->ni_frames);
-            }
-            /* For one pass, early in the clip ... average the current frame Q
-             * value with the worstq entered by the user as a dampening measure
-             */
-            else
-            {
-                cpi->ni_tot_qi += Q;
-                cpi->ni_av_qi = ((cpi->ni_tot_qi / cpi->ni_frames) + cpi->worst_quality + 1) / 2;
-            }
-
-            /* If the average Q is higher than what was used in the last
-             * frame (after going through the recode loop to keep the frame
-             * size within range) then use the last frame value - 1. The -1
-             * is designed to stop Q and hence the data rate, from
-             * progressively falling away during difficult sections, but at
-             * the same time reduce the number of itterations around the
-             * recode loop.
-             */
-            if (Q > cpi->ni_av_qi)
-                cpi->ni_av_qi = Q - 1;
-        }
-    }
-
-    /* Update the buffer level variable. */
-    /* Non-viewable frames are a special case and are treated as pure overhead. */
-    if ( !cm->show_frame )
-        cpi->bits_off_target -= cpi->projected_frame_size;
-    else
-        cpi->bits_off_target += cpi->av_per_frame_bandwidth - cpi->projected_frame_size;
-
-    /* Clip the buffer level to the maximum specified buffer size */
-    if (cpi->bits_off_target > cpi->oxcf.maximum_buffer_size)
-        cpi->bits_off_target = cpi->oxcf.maximum_buffer_size;
-
-    // If the frame dropper is not enabled, don't let the buffer level go below
-    // some threshold, given here by -|maximum_buffer_size|. For now we only do
-    // this for screen content input.
-    if (cpi->drop_frames_allowed == 0 && cpi->oxcf.screen_content_mode &&
-        cpi->bits_off_target < -cpi->oxcf.maximum_buffer_size)
-        cpi->bits_off_target = -cpi->oxcf.maximum_buffer_size;
-
-    /* Rolling monitors of whether we are over or underspending used to
-     * help regulate min and Max Q in two pass.
-     */
-    cpi->rolling_target_bits = ((cpi->rolling_target_bits * 3) + cpi->this_frame_target + 2) / 4;
-    cpi->rolling_actual_bits = ((cpi->rolling_actual_bits * 3) + cpi->projected_frame_size + 2) / 4;
-    cpi->long_rolling_target_bits = ((cpi->long_rolling_target_bits * 31) + cpi->this_frame_target + 16) / 32;
-    cpi->long_rolling_actual_bits = ((cpi->long_rolling_actual_bits * 31) + cpi->projected_frame_size + 16) / 32;
-
-    /* Actual bits spent */
-    cpi->total_actual_bits += cpi->projected_frame_size;
-
-    /* Debug stats */
-    cpi->total_target_vs_actual += (cpi->this_frame_target - cpi->projected_frame_size);
-
-    cpi->buffer_level = cpi->bits_off_target;
-
-    /* Propagate values to higher temporal layers */
-    if (cpi->oxcf.number_of_layers > 1)
-    {
-        unsigned int i;
-
-        for (i=cpi->current_layer+1; i<cpi->oxcf.number_of_layers; i++)
-        {
-            LAYER_CONTEXT *lc = &cpi->layer_context[i];
-            int bits_off_for_this_layer =
-               (int)(lc->target_bandwidth / lc->framerate -
-                     cpi->projected_frame_size);
-
-            lc->bits_off_target += bits_off_for_this_layer;
-
-            /* Clip buffer level to maximum buffer size for the layer */
-            if (lc->bits_off_target > lc->maximum_buffer_size)
-                lc->bits_off_target = lc->maximum_buffer_size;
-
-            lc->total_actual_bits += cpi->projected_frame_size;
-            lc->total_target_vs_actual += bits_off_for_this_layer;
-            lc->buffer_level = lc->bits_off_target;
-        }
-    }
-
-    /* Update bits left to the kf and gf groups to account for overshoot
-     * or undershoot on these frames
-     */
-    if (cm->frame_type == KEY_FRAME)
-    {
-        cpi->twopass.kf_group_bits += cpi->this_frame_target - cpi->projected_frame_size;
-
-        if (cpi->twopass.kf_group_bits < 0)
-            cpi->twopass.kf_group_bits = 0 ;
-    }
-    else if (cm->refresh_golden_frame || cm->refresh_alt_ref_frame)
-    {
-        cpi->twopass.gf_group_bits += cpi->this_frame_target - cpi->projected_frame_size;
-
-        if (cpi->twopass.gf_group_bits < 0)
-            cpi->twopass.gf_group_bits = 0 ;
-    }
-
-    if (cm->frame_type != KEY_FRAME)
-    {
-        if (cpi->common.refresh_alt_ref_frame)
-        {
-            cpi->last_skip_false_probs[2] = cpi->prob_skip_false;
-            cpi->last_skip_probs_q[2] = cm->base_qindex;
-        }
-        else if (cpi->common.refresh_golden_frame)
-        {
-            cpi->last_skip_false_probs[1] = cpi->prob_skip_false;
-            cpi->last_skip_probs_q[1] = cm->base_qindex;
-        }
-        else
-        {
-            cpi->last_skip_false_probs[0] = cpi->prob_skip_false;
-            cpi->last_skip_probs_q[0] = cm->base_qindex;
-
-            /* update the baseline */
-            cpi->base_skip_false_prob[cm->base_qindex] = cpi->prob_skip_false;
-
-        }
-    }
-
-#if 0 && CONFIG_INTERNAL_STATS
-    {
-        FILE *f = fopen("tmp.stt", "a");
-
-        vp8_clear_system_state();
-
-        if (cpi->twopass.total_left_stats.coded_error != 0.0)
-            fprintf(f, "%10d %10d %10d %10d %10d %10"PRId64" %10"PRId64
-                       "%10"PRId64" %10d %6d %6d %6d %6d %5d %5d %5d %8d "
-                       "%8.2lf %"PRId64" %10.3lf %10"PRId64" %8d\n",
-                       cpi->common.current_video_frame, cpi->this_frame_target,
-                       cpi->projected_frame_size,
-                       (cpi->projected_frame_size - cpi->this_frame_target),
-                       cpi->total_target_vs_actual,
-                       cpi->buffer_level,
-                       (cpi->oxcf.starting_buffer_level-cpi->bits_off_target),
-                       cpi->total_actual_bits, cm->base_qindex,
-                       cpi->active_best_quality, cpi->active_worst_quality,
-                       cpi->ni_av_qi, cpi->cq_target_quality,
-                       cm->refresh_golden_frame, cm->refresh_alt_ref_frame,
-                       cm->frame_type, cpi->gfu_boost,
-                       cpi->twopass.est_max_qcorrection_factor,
-                       cpi->twopass.bits_left,
-                       cpi->twopass.total_left_stats.coded_error,
-                       (double)cpi->twopass.bits_left /
-                           cpi->twopass.total_left_stats.coded_error,
-                       cpi->tot_recode_hits);
-        else
-            fprintf(f, "%10d %10d %10d %10d %10d %10"PRId64" %10"PRId64
-                       "%10"PRId64" %10d %6d %6d %6d %6d %5d %5d %5d %8d "
-                       "%8.2lf %"PRId64" %10.3lf %8d\n",
-                       cpi->common.current_video_frame, cpi->this_frame_target,
-                       cpi->projected_frame_size,
-                       (cpi->projected_frame_size - cpi->this_frame_target),
-                       cpi->total_target_vs_actual,
-                       cpi->buffer_level,
-                       (cpi->oxcf.starting_buffer_level-cpi->bits_off_target),
-                       cpi->total_actual_bits, cm->base_qindex,
-                       cpi->active_best_quality, cpi->active_worst_quality,
-                       cpi->ni_av_qi, cpi->cq_target_quality,
-                       cm->refresh_golden_frame, cm->refresh_alt_ref_frame,
-                       cm->frame_type, cpi->gfu_boost,
-                       cpi->twopass.est_max_qcorrection_factor,
-                       cpi->twopass.bits_left,
-                       cpi->twopass.total_left_stats.coded_error,
-                       cpi->tot_recode_hits);
-
-        fclose(f);
-
-        {
-            FILE *fmodes = fopen("Modes.stt", "a");
-
-            fprintf(fmodes, "%6d:%1d:%1d:%1d ",
-                        cpi->common.current_video_frame,
-                        cm->frame_type, cm->refresh_golden_frame,
-                        cm->refresh_alt_ref_frame);
-
-            fprintf(fmodes, "\n");
-
-            fclose(fmodes);
-        }
-    }
-
-#endif
-
-    if (cm->refresh_golden_frame == 1)
-        cm->frame_flags = cm->frame_flags | FRAMEFLAGS_GOLDEN;
-    else
-        cm->frame_flags = cm->frame_flags&~FRAMEFLAGS_GOLDEN;
-
-    if (cm->refresh_alt_ref_frame == 1)
-        cm->frame_flags = cm->frame_flags | FRAMEFLAGS_ALTREF;
-    else
-        cm->frame_flags = cm->frame_flags&~FRAMEFLAGS_ALTREF;
-
-
-    if (cm->refresh_last_frame & cm->refresh_golden_frame)
-        /* both refreshed */
-        cpi->gold_is_last = 1;
-    else if (cm->refresh_last_frame ^ cm->refresh_golden_frame)
-        /* 1 refreshed but not the other */
-        cpi->gold_is_last = 0;
-
-    if (cm->refresh_last_frame & cm->refresh_alt_ref_frame)
-        /* both refreshed */
-        cpi->alt_is_last = 1;
-    else if (cm->refresh_last_frame ^ cm->refresh_alt_ref_frame)
-        /* 1 refreshed but not the other */
-        cpi->alt_is_last = 0;
-
-    if (cm->refresh_alt_ref_frame & cm->refresh_golden_frame)
-        /* both refreshed */
-        cpi->gold_is_alt = 1;
-    else if (cm->refresh_alt_ref_frame ^ cm->refresh_golden_frame)
-        /* 1 refreshed but not the other */
-        cpi->gold_is_alt = 0;
-
-    cpi->ref_frame_flags = VP8_ALTR_FRAME | VP8_GOLD_FRAME | VP8_LAST_FRAME;
-
-    if (cpi->gold_is_last)
-        cpi->ref_frame_flags &= ~VP8_GOLD_FRAME;
-
-    if (cpi->alt_is_last)
-        cpi->ref_frame_flags &= ~VP8_ALTR_FRAME;
-
-    if (cpi->gold_is_alt)
-        cpi->ref_frame_flags &= ~VP8_ALTR_FRAME;
-
-
-    if (!cpi->oxcf.error_resilient_mode)
-    {
-        if (cpi->oxcf.play_alternate && cm->refresh_alt_ref_frame && (cm->frame_type != KEY_FRAME))
-            /* Update the alternate reference frame stats as appropriate. */
-            update_alt_ref_frame_stats(cpi);
-        else
-            /* Update the Golden frame stats as appropriate. */
-            update_golden_frame_stats(cpi);
-    }
-
-    if (cm->frame_type == KEY_FRAME)
-    {
-        /* Tell the caller that the frame was coded as a key frame */
-        *frame_flags = cm->frame_flags | FRAMEFLAGS_KEY;
-
-        /* As this frame is a key frame  the next defaults to an inter frame. */
-        cm->frame_type = INTER_FRAME;
-
-        cpi->last_frame_percent_intra = 100;
-    }
-    else
-    {
-        *frame_flags = cm->frame_flags&~FRAMEFLAGS_KEY;
-
-        cpi->last_frame_percent_intra = cpi->this_frame_percent_intra;
-    }
-
-    /* Clear the one shot update flags for segmentation map and mode/ref
-     * loop filter deltas.
-     */
-    cpi->mb.e_mbd.update_mb_segmentation_map = 0;
-    cpi->mb.e_mbd.update_mb_segmentation_data = 0;
-    cpi->mb.e_mbd.mode_ref_lf_delta_update = 0;
-
-
-    /* Dont increment frame counters if this was an altref buffer update
-     * not a real frame
-     */
-    if (cm->show_frame)
-    {
-        cm->current_video_frame++;
-        cpi->frames_since_key++;
-        cpi->temporal_pattern_counter++;
-    }
-
-    /* reset to normal state now that we are done. */
-
-
-
-#if 0
-    {
-        char filename[512];
-        FILE *recon_file;
-        sprintf(filename, "enc%04d.yuv", (int) cm->current_video_frame);
-        recon_file = fopen(filename, "wb");
-        fwrite(cm->yv12_fb[cm->lst_fb_idx].buffer_alloc,
-               cm->yv12_fb[cm->lst_fb_idx].frame_size, 1, recon_file);
-        fclose(recon_file);
-    }
-#endif
-
-    /* DEBUG */
-    /* vp8_write_yuv_frame("encoder_recon.yuv", cm->frame_to_show); */
-
-
-}
-#if !CONFIG_REALTIME_ONLY
-static void Pass2Encode(VP8_COMP *cpi, unsigned long *size, unsigned char *dest, unsigned char * dest_end, unsigned int *frame_flags)
-{
-
-    if (!cpi->common.refresh_alt_ref_frame)
-        vp8_second_pass(cpi);
-
-    encode_frame_to_data_rate(cpi, size, dest, dest_end, frame_flags);
-    cpi->twopass.bits_left -= 8 * (int)(*size);
-
-    if (!cpi->common.refresh_alt_ref_frame)
-    {
-        double two_pass_min_rate = (double)(cpi->oxcf.target_bandwidth
-            *cpi->oxcf.two_pass_vbrmin_section / 100);
-        cpi->twopass.bits_left += (int64_t)(two_pass_min_rate / cpi->framerate);
-    }
-}
-#endif
-
-int vp8_receive_raw_frame(VP8_COMP *cpi, unsigned int frame_flags, YV12_BUFFER_CONFIG *sd, int64_t time_stamp, int64_t end_time)
-{
-    struct vpx_usec_timer  timer;
-    int                    res = 0;
-
-    vpx_usec_timer_start(&timer);
-
-    /* Reinit the lookahead buffer if the frame size changes */
-    if (sd->y_width != cpi->oxcf.Width || sd->y_height != cpi->oxcf.Height)
-    {
-        assert(cpi->oxcf.lag_in_frames < 2);
-        dealloc_raw_frame_buffers(cpi);
-        alloc_raw_frame_buffers(cpi);
-    }
-
-    if(vp8_lookahead_push(cpi->lookahead, sd, time_stamp, end_time,
-                          frame_flags, cpi->active_map_enabled ? cpi->active_map : NULL))
-        res = -1;
-    vpx_usec_timer_mark(&timer);
-    cpi->time_receive_data += vpx_usec_timer_elapsed(&timer);
-
-    return res;
-}
-
-
-static int frame_is_reference(const VP8_COMP *cpi)
-{
-    const VP8_COMMON *cm = &cpi->common;
-    const MACROBLOCKD *xd = &cpi->mb.e_mbd;
-
-    return cm->frame_type == KEY_FRAME || cm->refresh_last_frame
-           || cm->refresh_golden_frame || cm->refresh_alt_ref_frame
-           || cm->copy_buffer_to_gf || cm->copy_buffer_to_arf
-           || cm->refresh_entropy_probs
-           || xd->mode_ref_lf_delta_update
-           || xd->update_mb_segmentation_map || xd->update_mb_segmentation_data;
-}
-
-
-int vp8_get_compressed_data(VP8_COMP *cpi, unsigned int *frame_flags, unsigned long *size, unsigned char *dest, unsigned char *dest_end, int64_t *time_stamp, int64_t *time_end, int flush)
-{
-    VP8_COMMON *cm;
-    struct vpx_usec_timer  tsctimer;
-    struct vpx_usec_timer  ticktimer;
-    struct vpx_usec_timer  cmptimer;
-    YV12_BUFFER_CONFIG    *force_src_buffer = NULL;
-
-    if (!cpi)
-        return -1;
-
-    cm = &cpi->common;
-
-    if (setjmp(cpi->common.error.jmp))
-    {
-        cpi->common.error.setjmp = 0;
-        vp8_clear_system_state();
-        return VPX_CODEC_CORRUPT_FRAME;
-    }
-
-    cpi->common.error.setjmp = 1;
-
-    vpx_usec_timer_start(&cmptimer);
-
-    cpi->source = NULL;
-
-#if !CONFIG_REALTIME_ONLY
-    /* Should we code an alternate reference frame */
-    if (cpi->oxcf.error_resilient_mode == 0 &&
-        cpi->oxcf.play_alternate &&
-        cpi->source_alt_ref_pending)
-    {
-        if ((cpi->source = vp8_lookahead_peek(cpi->lookahead,
-                                              cpi->frames_till_gf_update_due,
-                                              PEEK_FORWARD)))
-        {
-            cpi->alt_ref_source = cpi->source;
-            if (cpi->oxcf.arnr_max_frames > 0)
-            {
-                vp8_temporal_filter_prepare_c(cpi,
-                                              cpi->frames_till_gf_update_due);
-                force_src_buffer = &cpi->alt_ref_buffer;
-            }
-            cpi->frames_till_alt_ref_frame = cpi->frames_till_gf_update_due;
-            cm->refresh_alt_ref_frame = 1;
-            cm->refresh_golden_frame = 0;
-            cm->refresh_last_frame = 0;
-            cm->show_frame = 0;
-            /* Clear Pending alt Ref flag. */
-            cpi->source_alt_ref_pending = 0;
-            cpi->is_src_frame_alt_ref = 0;
-        }
-    }
-#endif
-
-    if (!cpi->source)
-    {
-        /* Read last frame source if we are encoding first pass. */
-        if (cpi->pass == 1 && cm->current_video_frame > 0)
-        {
-            if((cpi->last_source = vp8_lookahead_peek(cpi->lookahead, 1,
-                                                      PEEK_BACKWARD)) == NULL)
-              return -1;
-        }
-
-
-        if ((cpi->source = vp8_lookahead_pop(cpi->lookahead, flush)))
-        {
-            cm->show_frame = 1;
-
-            cpi->is_src_frame_alt_ref = cpi->alt_ref_source
-                                        && (cpi->source == cpi->alt_ref_source);
-
-            if(cpi->is_src_frame_alt_ref)
-                cpi->alt_ref_source = NULL;
-        }
-    }
-
-    if (cpi->source)
-    {
-        cpi->Source = force_src_buffer ? force_src_buffer : &cpi->source->img;
-        cpi->un_scaled_source = cpi->Source;
-        *time_stamp = cpi->source->ts_start;
-        *time_end = cpi->source->ts_end;
-        *frame_flags = cpi->source->flags;
-
-        if (cpi->pass == 1 && cm->current_video_frame > 0)
-        {
-            cpi->last_frame_unscaled_source = &cpi->last_source->img;
-        }
-    }
-    else
-    {
-        *size = 0;
-#if !CONFIG_REALTIME_ONLY
-
-        if (flush && cpi->pass == 1 && !cpi->twopass.first_pass_done)
-        {
-            vp8_end_first_pass(cpi);    /* get last stats packet */
-            cpi->twopass.first_pass_done = 1;
-        }
-
-#endif
-
-        return -1;
-    }
-
-    if (cpi->source->ts_start < cpi->first_time_stamp_ever)
-    {
-        cpi->first_time_stamp_ever = cpi->source->ts_start;
-        cpi->last_end_time_stamp_seen = cpi->source->ts_start;
-    }
-
-    /* adjust frame rates based on timestamps given */
-    if (cm->show_frame)
-    {
-        int64_t this_duration;
-        int step = 0;
-
-        if (cpi->source->ts_start == cpi->first_time_stamp_ever)
-        {
-            this_duration = cpi->source->ts_end - cpi->source->ts_start;
-            step = 1;
-        }
-        else
-        {
-            int64_t last_duration;
-
-            this_duration = cpi->source->ts_end - cpi->last_end_time_stamp_seen;
-            last_duration = cpi->last_end_time_stamp_seen
-                            - cpi->last_time_stamp_seen;
-            /* do a step update if the duration changes by 10% */
-            if (last_duration)
-                step = (int)(((this_duration - last_duration) *
-                            10 / last_duration));
-        }
-
-        if (this_duration)
-        {
-            if (step)
-                cpi->ref_framerate = 10000000.0 / this_duration;
-            else
-            {
-                double avg_duration, interval;
-
-                /* Average this frame's rate into the last second's average
-                 * frame rate. If we haven't seen 1 second yet, then average
-                 * over the whole interval seen.
-                 */
-                interval = (double)(cpi->source->ts_end -
-                                    cpi->first_time_stamp_ever);
-                if(interval > 10000000.0)
-                    interval = 10000000;
-
-                avg_duration = 10000000.0 / cpi->ref_framerate;
-                avg_duration *= (interval - avg_duration + this_duration);
-                avg_duration /= interval;
-
-                cpi->ref_framerate = 10000000.0 / avg_duration;
-            }
-#if CONFIG_MULTI_RES_ENCODING
-            if (cpi->oxcf.mr_total_resolutions > 1) {
-              LOWER_RES_FRAME_INFO* low_res_frame_info = (LOWER_RES_FRAME_INFO*)
-                  cpi->oxcf.mr_low_res_mode_info;
-              // Frame rate should be the same for all spatial layers in
-              // multi-res-encoding (simulcast), so we constrain the frame for
-              // higher layers to be that of lowest resolution. This is needed
-              // as he application may decide to skip encoding a high layer and
-              // then start again, in which case a big jump in time-stamps will
-              // be received for that high layer, which will yield an incorrect
-              // frame rate (from time-stamp adjustment in above calculation).
-              if (cpi->oxcf.mr_encoder_id) {
-                 cpi->ref_framerate = low_res_frame_info->low_res_framerate;
-              }
-              else {
-                // Keep track of frame rate for lowest resolution.
-                low_res_frame_info->low_res_framerate = cpi->ref_framerate;
-              }
-            }
-#endif
-            if (cpi->oxcf.number_of_layers > 1)
-            {
-                unsigned int i;
-
-                /* Update frame rates for each layer */
-                assert(cpi->oxcf.number_of_layers <= VPX_TS_MAX_LAYERS);
-                for (i = 0; i < cpi->oxcf.number_of_layers &&
-                     i < VPX_TS_MAX_LAYERS; ++i)
-                {
-                    LAYER_CONTEXT *lc = &cpi->layer_context[i];
-                    lc->framerate = cpi->ref_framerate /
-                                    cpi->oxcf.rate_decimator[i];
-                }
-            }
-            else
-                vp8_new_framerate(cpi, cpi->ref_framerate);
-        }
-
-        cpi->last_time_stamp_seen = cpi->source->ts_start;
-        cpi->last_end_time_stamp_seen = cpi->source->ts_end;
-    }
-
-    if (cpi->oxcf.number_of_layers > 1)
-    {
-        int layer;
-
-        update_layer_contexts (cpi);
-
-        /* Restore layer specific context & set frame rate */
-        if (cpi->temporal_layer_id >= 0) {
-          layer = cpi->temporal_layer_id;
-        } else {
-          layer = cpi->oxcf.layer_id[
-                  cpi->temporal_pattern_counter % cpi->oxcf.periodicity];
-        }
-        restore_layer_context (cpi, layer);
-        vp8_new_framerate(cpi, cpi->layer_context[layer].framerate);
-    }
-
-    if (cpi->compressor_speed == 2)
-    {
-        vpx_usec_timer_start(&tsctimer);
-        vpx_usec_timer_start(&ticktimer);
-    }
-
-    cpi->lf_zeromv_pct = (cpi->zeromv_count * 100)/cm->MBs;
-
-#if CONFIG_REALTIME_ONLY & CONFIG_ONTHEFLY_BITPACKING
-    {
-        int i;
-        const int num_part = (1 << cm->multi_token_partition);
-        /* the available bytes in dest */
-        const unsigned long dest_size = dest_end - dest;
-        const int tok_part_buff_size = (dest_size * 9) / (10 * num_part);
-
-        unsigned char *dp = dest;
-
-        cpi->partition_d[0] = dp;
-        dp += dest_size/10;         /* reserve 1/10 for control partition */
-        cpi->partition_d_end[0] = dp;
-
-        for(i = 0; i < num_part; i++)
-        {
-            cpi->partition_d[i + 1] = dp;
-            dp += tok_part_buff_size;
-            cpi->partition_d_end[i + 1] = dp;
-        }
-    }
-#endif
-
-    /* start with a 0 size frame */
-    *size = 0;
-
-    /* Clear down mmx registers */
-    vp8_clear_system_state();
-
-    cm->frame_type = INTER_FRAME;
-    cm->frame_flags = *frame_flags;
-
-#if 0
-
-    if (cm->refresh_alt_ref_frame)
-    {
-        cm->refresh_golden_frame = 0;
-        cm->refresh_last_frame = 0;
-    }
-    else
-    {
-        cm->refresh_golden_frame = 0;
-        cm->refresh_last_frame = 1;
-    }
-
-#endif
-    /* find a free buffer for the new frame */
-    {
-        int i = 0;
-        for(; i < NUM_YV12_BUFFERS; i++)
-        {
-            if(!cm->yv12_fb[i].flags)
-            {
-                cm->new_fb_idx = i;
-                break;
-            }
-        }
-
-        assert(i < NUM_YV12_BUFFERS );
-    }
-#if !CONFIG_REALTIME_ONLY
-
-    if (cpi->pass == 1)
-    {
-        Pass1Encode(cpi, size, dest, frame_flags);
-    }
-    else if (cpi->pass == 2)
-    {
-        Pass2Encode(cpi, size, dest, dest_end, frame_flags);
-    }
-    else
-#endif
-        encode_frame_to_data_rate(cpi, size, dest, dest_end, frame_flags);
-
-    if (cpi->compressor_speed == 2)
-    {
-        unsigned int duration, duration2;
-        vpx_usec_timer_mark(&tsctimer);
-        vpx_usec_timer_mark(&ticktimer);
-
-        duration = (int)(vpx_usec_timer_elapsed(&ticktimer));
-        duration2 = (unsigned int)((double)duration / 2);
-
-        if (cm->frame_type != KEY_FRAME)
-        {
-            if (cpi->avg_encode_time == 0)
-                cpi->avg_encode_time = duration;
-            else
-                cpi->avg_encode_time = (7 * cpi->avg_encode_time + duration) >> 3;
-        }
-
-        if (duration2)
-        {
-            {
-
-                if (cpi->avg_pick_mode_time == 0)
-                    cpi->avg_pick_mode_time = duration2;
-                else
-                    cpi->avg_pick_mode_time = (7 * cpi->avg_pick_mode_time + duration2) >> 3;
-            }
-        }
-
-    }
-
-    if (cm->refresh_entropy_probs == 0)
-    {
-        memcpy(&cm->fc, &cm->lfc, sizeof(cm->fc));
-    }
-
-    /* Save the contexts separately for alt ref, gold and last. */
-    /* (TODO jbb -> Optimize this with pointers to avoid extra copies. ) */
-    if(cm->refresh_alt_ref_frame)
-        memcpy(&cpi->lfc_a, &cm->fc, sizeof(cm->fc));
-
-    if(cm->refresh_golden_frame)
-        memcpy(&cpi->lfc_g, &cm->fc, sizeof(cm->fc));
-
-    if(cm->refresh_last_frame)
-        memcpy(&cpi->lfc_n, &cm->fc, sizeof(cm->fc));
-
-    /* if its a dropped frame honor the requests on subsequent frames */
-    if (*size > 0)
-    {
-        cpi->droppable = !frame_is_reference(cpi);
-
-        /* return to normal state */
-        cm->refresh_entropy_probs = 1;
-        cm->refresh_alt_ref_frame = 0;
-        cm->refresh_golden_frame = 0;
-        cm->refresh_last_frame = 1;
-        cm->frame_type = INTER_FRAME;
-
-    }
-
-    /* Save layer specific state */
-    if (cpi->oxcf.number_of_layers > 1)
-        save_layer_context (cpi);
-
-    vpx_usec_timer_mark(&cmptimer);
-    cpi->time_compress_data += vpx_usec_timer_elapsed(&cmptimer);
-
-    if (cpi->b_calculate_psnr && cpi->pass != 1 && cm->show_frame)
-    {
-        generate_psnr_packet(cpi);
-    }
-
-#if CONFIG_INTERNAL_STATS
-
-    if (cpi->pass != 1)
-    {
-        cpi->bytes += *size;
-
-        if (cm->show_frame)
-        {
-            cpi->common.show_frame_mi = cpi->common.mi;
-            cpi->count ++;
-
-            if (cpi->b_calculate_psnr)
-            {
-                uint64_t ye,ue,ve;
-                double frame_psnr;
-                YV12_BUFFER_CONFIG      *orig = cpi->Source;
-                YV12_BUFFER_CONFIG      *recon = cpi->common.frame_to_show;
-                unsigned int y_width = cpi->common.Width;
-                unsigned int y_height = cpi->common.Height;
-                unsigned int uv_width = (y_width + 1) / 2;
-                unsigned int uv_height = (y_height + 1) / 2;
-                int y_samples = y_height * y_width;
-                int uv_samples = uv_height * uv_width;
-                int t_samples = y_samples + 2 * uv_samples;
-                double sq_error;
-
-                ye = calc_plane_error(orig->y_buffer, orig->y_stride,
-                  recon->y_buffer, recon->y_stride, y_width, y_height);
-
-                ue = calc_plane_error(orig->u_buffer, orig->uv_stride,
-                  recon->u_buffer, recon->uv_stride, uv_width, uv_height);
-
-                ve = calc_plane_error(orig->v_buffer, orig->uv_stride,
-                  recon->v_buffer, recon->uv_stride, uv_width, uv_height);
-
-                sq_error = (double)(ye + ue + ve);
-
-                frame_psnr = vpx_sse_to_psnr(t_samples, 255.0, sq_error);
-
-                cpi->total_y += vpx_sse_to_psnr(y_samples, 255.0, (double)ye);
-                cpi->total_u += vpx_sse_to_psnr(uv_samples, 255.0, (double)ue);
-                cpi->total_v += vpx_sse_to_psnr(uv_samples, 255.0, (double)ve);
-                cpi->total_sq_error += sq_error;
-                cpi->total  += frame_psnr;
-#if CONFIG_POSTPROC
-                {
-                    YV12_BUFFER_CONFIG      *pp = &cm->post_proc_buffer;
-                    double sq_error2;
-                    double frame_psnr2, frame_ssim2 = 0;
-                    double weight = 0;
-
-                    vp8_deblock(cm, cm->frame_to_show, &cm->post_proc_buffer, cm->filter_level * 10 / 6, 1, 0);
-                    vp8_clear_system_state();
-
-                    ye = calc_plane_error(orig->y_buffer, orig->y_stride,
-                      pp->y_buffer, pp->y_stride, y_width, y_height);
-
-                    ue = calc_plane_error(orig->u_buffer, orig->uv_stride,
-                      pp->u_buffer, pp->uv_stride, uv_width, uv_height);
-
-                    ve = calc_plane_error(orig->v_buffer, orig->uv_stride,
-                      pp->v_buffer, pp->uv_stride, uv_width, uv_height);
-
-                    sq_error2 = (double)(ye + ue + ve);
-
-                    frame_psnr2 = vpx_sse_to_psnr(t_samples, 255.0, sq_error2);
-
-                    cpi->totalp_y += vpx_sse_to_psnr(y_samples,
-                                                     255.0, (double)ye);
-                    cpi->totalp_u += vpx_sse_to_psnr(uv_samples,
-                                                     255.0, (double)ue);
-                    cpi->totalp_v += vpx_sse_to_psnr(uv_samples,
-                                                     255.0, (double)ve);
-                    cpi->total_sq_error2 += sq_error2;
-                    cpi->totalp  += frame_psnr2;
-
-                    frame_ssim2 = vpx_calc_ssim(cpi->Source,
-                      &cm->post_proc_buffer, &weight);
-
-                    cpi->summed_quality += frame_ssim2 * weight;
-                    cpi->summed_weights += weight;
-
-                    if (cpi->oxcf.number_of_layers > 1)
-                    {
-                         unsigned int i;
-
-                         for (i=cpi->current_layer;
-                                       i<cpi->oxcf.number_of_layers; i++)
-                         {
-                             cpi->frames_in_layer[i]++;
-
-                             cpi->bytes_in_layer[i] += *size;
-                             cpi->sum_psnr[i]       += frame_psnr;
-                             cpi->sum_psnr_p[i]     += frame_psnr2;
-                             cpi->total_error2[i]   += sq_error;
-                             cpi->total_error2_p[i] += sq_error2;
-                             cpi->sum_ssim[i]       += frame_ssim2 * weight;
-                             cpi->sum_weights[i]    += weight;
-                         }
-                    }
-                }
-#endif
-            }
-        }
-    }
-
-#if 0
-
-    if (cpi->common.frame_type != 0 && cpi->common.base_qindex == cpi->oxcf.worst_allowed_q)
-    {
-        skiptruecount += cpi->skip_true_count;
-        skipfalsecount += cpi->skip_false_count;
-    }
-
-#endif
-#if 0
-
-    if (cpi->pass != 1)
-    {
-        FILE *f = fopen("skip.stt", "a");
-        fprintf(f, "frame:%4d flags:%4x Q:%4d P:%4d Size:%5d\n", cpi->common.current_video_frame, *frame_flags, cpi->common.base_qindex, cpi->prob_skip_false, *size);
-
-        if (cpi->is_src_frame_alt_ref == 1)
-            fprintf(f, "skipcount: %4d framesize: %d\n", cpi->skip_true_count , *size);
-
-        fclose(f);
-    }
-
-#endif
-#endif
-
-    cpi->common.error.setjmp = 0;
-
-    return 0;
-}
-
-int vp8_get_preview_raw_frame(VP8_COMP *cpi, YV12_BUFFER_CONFIG *dest, vp8_ppflags_t *flags)
-{
-    if (cpi->common.refresh_alt_ref_frame)
-        return -1;
-    else
-    {
-        int ret;
-
-#if CONFIG_POSTPROC
-        cpi->common.show_frame_mi = cpi->common.mi;
-        ret = vp8_post_proc_frame(&cpi->common, dest, flags);
-#else
-        (void)flags;
-
-        if (cpi->common.frame_to_show)
-        {
-            *dest = *cpi->common.frame_to_show;
-            dest->y_width = cpi->common.Width;
-            dest->y_height = cpi->common.Height;
-            dest->uv_height = cpi->common.Height / 2;
-            ret = 0;
-        }
-        else
-        {
-            ret = -1;
-        }
-
-#endif
-        vp8_clear_system_state();
-        return ret;
-    }
-}
-
-int vp8_set_roimap(VP8_COMP *cpi, unsigned char *map, unsigned int rows, unsigned int cols, int delta_q[4], int delta_lf[4], unsigned int threshold[4])
-{
-    signed char feature_data[MB_LVL_MAX][MAX_MB_SEGMENTS];
-    int internal_delta_q[MAX_MB_SEGMENTS];
-    const int range = 63;
-    int i;
-
-    // This method is currently incompatible with the cyclic refresh method
-    if ( cpi->cyclic_refresh_mode_enabled )
-        return -1;
-
-    // Check number of rows and columns match
-    if (cpi->common.mb_rows != (int)rows || cpi->common.mb_cols != (int)cols)
-        return -1;
-
-    // Range check the delta Q values and convert the external Q range values
-    // to internal ones.
-    if ( (abs(delta_q[0]) > range) || (abs(delta_q[1]) > range) ||
-         (abs(delta_q[2]) > range) || (abs(delta_q[3]) > range) )
-        return -1;
-
-    // Range check the delta lf values
-    if ( (abs(delta_lf[0]) > range) || (abs(delta_lf[1]) > range) ||
-         (abs(delta_lf[2]) > range) || (abs(delta_lf[3]) > range) )
-        return -1;
-
-    if (!map)
-    {
-        disable_segmentation(cpi);
-        return 0;
-    }
-
-    // Translate the external delta q values to internal values.
-    for ( i = 0; i < MAX_MB_SEGMENTS; i++ )
-        internal_delta_q[i] =
-            ( delta_q[i] >= 0 ) ? q_trans[delta_q[i]] : -q_trans[-delta_q[i]];
-
-    /* Set the segmentation Map */
-    set_segmentation_map(cpi, map);
-
-    /* Activate segmentation. */
-    enable_segmentation(cpi);
-
-    /* Set up the quant segment data */
-    feature_data[MB_LVL_ALT_Q][0] = internal_delta_q[0];
-    feature_data[MB_LVL_ALT_Q][1] = internal_delta_q[1];
-    feature_data[MB_LVL_ALT_Q][2] = internal_delta_q[2];
-    feature_data[MB_LVL_ALT_Q][3] = internal_delta_q[3];
-
-    /* Set up the loop segment data s */
-    feature_data[MB_LVL_ALT_LF][0] = delta_lf[0];
-    feature_data[MB_LVL_ALT_LF][1] = delta_lf[1];
-    feature_data[MB_LVL_ALT_LF][2] = delta_lf[2];
-    feature_data[MB_LVL_ALT_LF][3] = delta_lf[3];
-
-    cpi->segment_encode_breakout[0] = threshold[0];
-    cpi->segment_encode_breakout[1] = threshold[1];
-    cpi->segment_encode_breakout[2] = threshold[2];
-    cpi->segment_encode_breakout[3] = threshold[3];
-
-    /* Initialise the feature data structure */
-    set_segment_data(cpi, &feature_data[0][0], SEGMENT_DELTADATA);
-
-    return 0;
-}
-
-int vp8_set_active_map(VP8_COMP *cpi, unsigned char *map, unsigned int rows, unsigned int cols)
-{
-    if ((int)rows == cpi->common.mb_rows && (int)cols == cpi->common.mb_cols)
-    {
-        if (map)
-        {
-            memcpy(cpi->active_map, map, rows * cols);
-            cpi->active_map_enabled = 1;
-        }
-        else
-            cpi->active_map_enabled = 0;
-
-        return 0;
-    }
-    else
-    {
-        return -1 ;
-    }
-}
-
-int vp8_set_internal_size(VP8_COMP *cpi, VPX_SCALING horiz_mode, VPX_SCALING vert_mode)
-{
-    if (horiz_mode <= ONETWO)
-        cpi->common.horiz_scale = horiz_mode;
-    else
-        return -1;
-
-    if (vert_mode <= ONETWO)
-        cpi->common.vert_scale  = vert_mode;
-    else
-        return -1;
-
-    return 0;
-}
-
-
-
-int vp8_calc_ss_err(YV12_BUFFER_CONFIG *source, YV12_BUFFER_CONFIG *dest)
-{
-    int i, j;
-    int Total = 0;
-
-    unsigned char *src = source->y_buffer;
-    unsigned char *dst = dest->y_buffer;
-
-    /* Loop through the Y plane raw and reconstruction data summing
-     * (square differences)
-     */
-    for (i = 0; i < source->y_height; i += 16)
-    {
-        for (j = 0; j < source->y_width; j += 16)
-        {
-            unsigned int sse;
-            Total += vpx_mse16x16(src + j, source->y_stride,
-                                  dst + j, dest->y_stride, &sse);
-        }
-
-        src += 16 * source->y_stride;
-        dst += 16 * dest->y_stride;
-    }
-
-    return Total;
-}
-
-
-int vp8_get_quantizer(VP8_COMP *cpi)
-{
-    return cpi->common.base_qindex;
-}
diff --git a/vp8/encoder/onyx_int.h b/vp8/encoder/onyx_int.h
deleted file mode 100644 (file)
index 716f878..0000000
+++ /dev/null
@@ -1,742 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#ifndef VP8_ENCODER_ONYX_INT_H_
-#define VP8_ENCODER_ONYX_INT_H_
-
-#include <stdio.h>
-#include "vpx_config.h"
-#include "vp8/common/onyx.h"
-#include "treewriter.h"
-#include "tokenize.h"
-#include "vp8/common/onyxc_int.h"
-#include "vpx_dsp/variance.h"
-#include "encodemb.h"
-#include "vp8/encoder/quantize.h"
-#include "vp8/common/entropy.h"
-#include "vp8/common/threading.h"
-#include "vpx_ports/mem.h"
-#include "vpx/internal/vpx_codec_internal.h"
-#include "vpx/vp8.h"
-#include "mcomp.h"
-#include "vp8/common/findnearmv.h"
-#include "lookahead.h"
-#if CONFIG_TEMPORAL_DENOISING
-#include "vp8/encoder/denoising.h"
-#endif
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define MIN_GF_INTERVAL             4
-#define DEFAULT_GF_INTERVAL         7
-
-#define KEY_FRAME_CONTEXT 5
-
-#define MAX_LAG_BUFFERS (CONFIG_REALTIME_ONLY? 1 : 25)
-
-#define AF_THRESH   25
-#define AF_THRESH2  100
-#define ARF_DECAY_THRESH 12
-
-
-#define MIN_THRESHMULT  32
-#define MAX_THRESHMULT  512
-
-#define GF_ZEROMV_ZBIN_BOOST 12
-#define LF_ZEROMV_ZBIN_BOOST 6
-#define MV_ZBIN_BOOST        4
-#define ZBIN_OQ_MAX 192
-
-#if !(CONFIG_REALTIME_ONLY)
-#define VP8_TEMPORAL_ALT_REF 1
-#endif
-
-typedef struct
-{
-    int kf_indicated;
-    unsigned int frames_since_key;
-    unsigned int frames_since_golden;
-    int filter_level;
-    int frames_till_gf_update_due;
-    int recent_ref_frame_usage[MAX_REF_FRAMES];
-
-    MV_CONTEXT mvc[2];
-    int mvcosts[2][MVvals+1];
-
-#ifdef MODE_STATS
-    int y_modes[5];
-    int uv_modes[4];
-    int b_modes[10];
-    int inter_y_modes[10];
-    int inter_uv_modes[4];
-    int inter_b_modes[10];
-#endif
-
-    vp8_prob ymode_prob[4], uv_mode_prob[3];   /* interframe intra mode probs */
-    vp8_prob kf_ymode_prob[4], kf_uv_mode_prob[3];   /* keyframe "" */
-
-    int ymode_count[5], uv_mode_count[4];  /* intra MB type cts this frame */
-
-    int count_mb_ref_frame_usage[MAX_REF_FRAMES];
-
-    int this_frame_percent_intra;
-    int last_frame_percent_intra;
-
-
-} CODING_CONTEXT;
-
-typedef struct
-{
-    double frame;
-    double intra_error;
-    double coded_error;
-    double ssim_weighted_pred_err;
-    double pcnt_inter;
-    double pcnt_motion;
-    double pcnt_second_ref;
-    double pcnt_neutral;
-    double MVr;
-    double mvr_abs;
-    double MVc;
-    double mvc_abs;
-    double MVrv;
-    double MVcv;
-    double mv_in_out_count;
-    double new_mv_count;
-    double duration;
-    double count;
-}
-FIRSTPASS_STATS;
-
-typedef struct
-{
-    int frames_so_far;
-    double frame_intra_error;
-    double frame_coded_error;
-    double frame_pcnt_inter;
-    double frame_pcnt_motion;
-    double frame_mvr;
-    double frame_mvr_abs;
-    double frame_mvc;
-    double frame_mvc_abs;
-
-} ONEPASS_FRAMESTATS;
-
-
-typedef enum
-{
-    THR_ZERO1          = 0,
-    THR_DC             = 1,
-
-    THR_NEAREST1       = 2,
-    THR_NEAR1          = 3,
-
-    THR_ZERO2          = 4,
-    THR_NEAREST2       = 5,
-
-    THR_ZERO3          = 6,
-    THR_NEAREST3       = 7,
-
-    THR_NEAR2          = 8,
-    THR_NEAR3          = 9,
-
-    THR_V_PRED         = 10,
-    THR_H_PRED         = 11,
-    THR_TM             = 12,
-
-    THR_NEW1           = 13,
-    THR_NEW2           = 14,
-    THR_NEW3           = 15,
-
-    THR_SPLIT1         = 16,
-    THR_SPLIT2         = 17,
-    THR_SPLIT3         = 18,
-
-    THR_B_PRED         = 19
-}
-THR_MODES;
-
-typedef enum
-{
-    DIAMOND = 0,
-    NSTEP = 1,
-    HEX = 2
-} SEARCH_METHODS;
-
-typedef struct
-{
-    int RD;
-    SEARCH_METHODS search_method;
-    int improved_quant;
-    int improved_dct;
-    int auto_filter;
-    int recode_loop;
-    int iterative_sub_pixel;
-    int half_pixel_search;
-    int quarter_pixel_search;
-    int thresh_mult[MAX_MODES];
-    int max_step_search_steps;
-    int first_step;
-    int optimize_coefficients;
-
-    int use_fastquant_for_pick;
-    int no_skip_block4x4_search;
-    int improved_mv_pred;
-
-} SPEED_FEATURES;
-
-typedef struct
-{
-    MACROBLOCK  mb;
-    int segment_counts[MAX_MB_SEGMENTS];
-    int totalrate;
-} MB_ROW_COMP;
-
-typedef struct
-{
-    TOKENEXTRA *start;
-    TOKENEXTRA *stop;
-} TOKENLIST;
-
-typedef struct
-{
-    int ithread;
-    void *ptr1;
-    void *ptr2;
-} ENCODETHREAD_DATA;
-typedef struct
-{
-    int ithread;
-    void *ptr1;
-} LPFTHREAD_DATA;
-
-enum
-{
-    BLOCK_16X8,
-    BLOCK_8X16,
-    BLOCK_8X8,
-    BLOCK_4X4,
-    BLOCK_16X16,
-    BLOCK_MAX_SEGMENTS
-};
-
-typedef struct
-{
-    /* Layer configuration */
-    double framerate;
-    int target_bandwidth;
-
-    /* Layer specific coding parameters */
-    int64_t starting_buffer_level;
-    int64_t optimal_buffer_level;
-    int64_t maximum_buffer_size;
-    int64_t starting_buffer_level_in_ms;
-    int64_t optimal_buffer_level_in_ms;
-    int64_t maximum_buffer_size_in_ms;
-
-    int avg_frame_size_for_layer;
-
-    int64_t buffer_level;
-    int64_t bits_off_target;
-
-    int64_t total_actual_bits;
-    int total_target_vs_actual;
-
-    int worst_quality;
-    int active_worst_quality;
-    int best_quality;
-    int active_best_quality;
-
-    int ni_av_qi;
-    int ni_tot_qi;
-    int ni_frames;
-    int avg_frame_qindex;
-
-    double rate_correction_factor;
-    double key_frame_rate_correction_factor;
-    double gf_rate_correction_factor;
-
-    int zbin_over_quant;
-
-    int inter_frame_target;
-    int64_t total_byte_count;
-
-    int filter_level;
-
-    int last_frame_percent_intra;
-
-    int count_mb_ref_frame_usage[MAX_REF_FRAMES];
-
-} LAYER_CONTEXT;
-
-typedef struct VP8_COMP
-{
-
-    DECLARE_ALIGNED(16, short, Y1quant[QINDEX_RANGE][16]);
-    DECLARE_ALIGNED(16, short, Y1quant_shift[QINDEX_RANGE][16]);
-    DECLARE_ALIGNED(16, short, Y1zbin[QINDEX_RANGE][16]);
-    DECLARE_ALIGNED(16, short, Y1round[QINDEX_RANGE][16]);
-
-    DECLARE_ALIGNED(16, short, Y2quant[QINDEX_RANGE][16]);
-    DECLARE_ALIGNED(16, short, Y2quant_shift[QINDEX_RANGE][16]);
-    DECLARE_ALIGNED(16, short, Y2zbin[QINDEX_RANGE][16]);
-    DECLARE_ALIGNED(16, short, Y2round[QINDEX_RANGE][16]);
-
-    DECLARE_ALIGNED(16, short, UVquant[QINDEX_RANGE][16]);
-    DECLARE_ALIGNED(16, short, UVquant_shift[QINDEX_RANGE][16]);
-    DECLARE_ALIGNED(16, short, UVzbin[QINDEX_RANGE][16]);
-    DECLARE_ALIGNED(16, short, UVround[QINDEX_RANGE][16]);
-
-    DECLARE_ALIGNED(16, short, zrun_zbin_boost_y1[QINDEX_RANGE][16]);
-    DECLARE_ALIGNED(16, short, zrun_zbin_boost_y2[QINDEX_RANGE][16]);
-    DECLARE_ALIGNED(16, short, zrun_zbin_boost_uv[QINDEX_RANGE][16]);
-    DECLARE_ALIGNED(16, short, Y1quant_fast[QINDEX_RANGE][16]);
-    DECLARE_ALIGNED(16, short, Y2quant_fast[QINDEX_RANGE][16]);
-    DECLARE_ALIGNED(16, short, UVquant_fast[QINDEX_RANGE][16]);
-
-
-    MACROBLOCK mb;
-    VP8_COMMON common;
-    vp8_writer bc[9]; /* one boolcoder for each partition */
-
-    VP8_CONFIG oxcf;
-
-    struct lookahead_ctx    *lookahead;
-    struct lookahead_entry  *source;
-    struct lookahead_entry  *alt_ref_source;
-    struct lookahead_entry  *last_source;
-
-    YV12_BUFFER_CONFIG *Source;
-    YV12_BUFFER_CONFIG *un_scaled_source;
-    YV12_BUFFER_CONFIG scaled_source;
-    YV12_BUFFER_CONFIG *last_frame_unscaled_source;
-
-    unsigned int frames_till_alt_ref_frame;
-    /* frame in src_buffers has been identified to be encoded as an alt ref */
-    int source_alt_ref_pending;
-    /* an alt ref frame has been encoded and is usable */
-    int source_alt_ref_active;
-    /* source of frame to encode is an exact copy of an alt ref frame */
-    int is_src_frame_alt_ref;
-
-    /* golden frame same as last frame ( short circuit gold searches) */
-    int gold_is_last;
-    /* Alt reference frame same as last ( short circuit altref search) */
-    int alt_is_last;
-    /* don't do both alt and gold search ( just do gold). */
-    int gold_is_alt;
-
-    YV12_BUFFER_CONFIG pick_lf_lvl_frame;
-
-    TOKENEXTRA *tok;
-    unsigned int tok_count;
-
-
-    unsigned int frames_since_key;
-    unsigned int key_frame_frequency;
-    unsigned int this_key_frame_forced;
-    unsigned int next_key_frame_forced;
-
-    /* Ambient reconstruction err target for force key frames */
-    int ambient_err;
-
-    unsigned int mode_check_freq[MAX_MODES];
-
-    int rd_baseline_thresh[MAX_MODES];
-
-    int RDMULT;
-    int RDDIV ;
-
-    CODING_CONTEXT coding_context;
-
-    /* Rate targetting variables */
-    int64_t last_prediction_error;
-    int64_t last_intra_error;
-
-    int this_frame_target;
-    int projected_frame_size;
-    int last_q[2];                   /* Separate values for Intra/Inter */
-
-    double rate_correction_factor;
-    double key_frame_rate_correction_factor;
-    double gf_rate_correction_factor;
-
-    int frames_since_golden;
-    /* Count down till next GF */
-    int frames_till_gf_update_due;
-
-    /* GF interval chosen when we coded the last GF */
-    int current_gf_interval;
-
-    /* Total bits overspent becasue of GF boost (cumulative) */
-    int gf_overspend_bits;
-
-    /* Used in the few frames following a GF to recover the extra bits
-     * spent in that GF
-     */
-    int non_gf_bitrate_adjustment;
-
-    /* Extra bits spent on key frames that need to be recovered */
-    int kf_overspend_bits;
-
-    /* Current number of bit s to try and recover on each inter frame. */
-    int kf_bitrate_adjustment;
-    int max_gf_interval;
-    int baseline_gf_interval;
-    int active_arnr_frames;
-
-    int64_t key_frame_count;
-    int prior_key_frame_distance[KEY_FRAME_CONTEXT];
-    /* Current section per frame bandwidth target */
-    int per_frame_bandwidth;
-    /* Average frame size target for clip */
-    int av_per_frame_bandwidth;
-    /* Minimum allocation that should be used for any frame */
-    int min_frame_bandwidth;
-    int inter_frame_target;
-    double output_framerate;
-    int64_t last_time_stamp_seen;
-    int64_t last_end_time_stamp_seen;
-    int64_t first_time_stamp_ever;
-
-    int ni_av_qi;
-    int ni_tot_qi;
-    int ni_frames;
-    int avg_frame_qindex;
-
-    int64_t total_byte_count;
-
-    int buffered_mode;
-
-    double framerate;
-    double ref_framerate;
-    int64_t buffer_level;
-    int64_t bits_off_target;
-
-    int rolling_target_bits;
-    int rolling_actual_bits;
-
-    int long_rolling_target_bits;
-    int long_rolling_actual_bits;
-
-    int64_t total_actual_bits;
-    int total_target_vs_actual; /* debug stats */
-
-    int worst_quality;
-    int active_worst_quality;
-    int best_quality;
-    int active_best_quality;
-
-    int cq_target_quality;
-
-    int drop_frames_allowed; /* Are we permitted to drop frames? */
-    int drop_frame;          /* Drop this frame? */
-
-    vp8_prob frame_coef_probs [BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [ENTROPY_NODES];
-    char update_probs [BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [ENTROPY_NODES];
-
-    unsigned int frame_branch_ct [BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [ENTROPY_NODES][2];
-
-    int gfu_boost;
-    int kf_boost;
-    int last_boost;
-
-    int target_bandwidth;
-    struct vpx_codec_pkt_list  *output_pkt_list;
-
-#if 0
-    /* Experimental code for lagged and one pass */
-    ONEPASS_FRAMESTATS one_pass_frame_stats[MAX_LAG_BUFFERS];
-    int one_pass_frame_index;
-#endif
-
-    int decimation_factor;
-    int decimation_count;
-
-    /* for real time encoding */
-    int avg_encode_time;     /* microsecond */
-    int avg_pick_mode_time;  /* microsecond */
-    int Speed;
-    int compressor_speed;
-
-    int auto_gold;
-    int auto_adjust_gold_quantizer;
-    int auto_worst_q;
-    int cpu_used;
-    int pass;
-
-
-    int prob_intra_coded;
-    int prob_last_coded;
-    int prob_gf_coded;
-    int prob_skip_false;
-    int last_skip_false_probs[3];
-    int last_skip_probs_q[3];
-    int recent_ref_frame_usage[MAX_REF_FRAMES];
-
-    int this_frame_percent_intra;
-    int last_frame_percent_intra;
-
-    int ref_frame_flags;
-
-    SPEED_FEATURES sf;
-
-    /* Count ZEROMV on all reference frames. */
-    int zeromv_count;
-    int lf_zeromv_pct;
-
-    unsigned char *segmentation_map;
-    signed char segment_feature_data[MB_LVL_MAX][MAX_MB_SEGMENTS];
-    int  segment_encode_breakout[MAX_MB_SEGMENTS];
-
-    unsigned char *active_map;
-    unsigned int active_map_enabled;
-
-    /* Video conferencing cyclic refresh mode flags. This is a mode
-     * designed to clean up the background over time in live encoding
-     * scenarious. It uses segmentation.
-     */
-    int cyclic_refresh_mode_enabled;
-    int cyclic_refresh_mode_max_mbs_perframe;
-    int cyclic_refresh_mode_index;
-    int cyclic_refresh_q;
-    signed char *cyclic_refresh_map;
-    // Count on how many (consecutive) times a macroblock uses ZER0MV_LAST.
-    unsigned char *consec_zero_last;
-    // Counter that is reset when a block is checked for a mode-bias against
-    // ZEROMV_LASTREF.
-    unsigned char *consec_zero_last_mvbias;
-
-    // Frame counter for the temporal pattern. Counter is rest when the temporal
-    // layers are changed dynamically (run-time change).
-    unsigned int temporal_pattern_counter;
-    // Temporal layer id.
-    int temporal_layer_id;
-
-    // Measure of average squared difference between source and denoised signal.
-    int mse_source_denoised;
-
-    int force_maxqp;
-
-#if CONFIG_MULTITHREAD
-    /* multithread data */
-    pthread_mutex_t *pmutex;
-    pthread_mutex_t mt_mutex;           /* mutex for b_multi_threaded */
-    int * mt_current_mb_col;
-    int mt_sync_range;
-    int b_multi_threaded;
-    int encoding_thread_count;
-
-    pthread_t *h_encoding_thread;
-    pthread_t h_filter_thread;
-
-    MB_ROW_COMP *mb_row_ei;
-    ENCODETHREAD_DATA *en_thread_data;
-    LPFTHREAD_DATA lpf_thread_data;
-
-    /* events */
-    sem_t *h_event_start_encoding;
-    sem_t h_event_end_encoding;
-    sem_t h_event_start_lpf;
-    sem_t h_event_end_lpf;
-#endif
-
-    TOKENLIST *tplist;
-    unsigned int partition_sz[MAX_PARTITIONS];
-    unsigned char *partition_d[MAX_PARTITIONS];
-    unsigned char *partition_d_end[MAX_PARTITIONS];
-
-
-    fractional_mv_step_fp *find_fractional_mv_step;
-    vp8_full_search_fn_t full_search_sad;
-    vp8_refining_search_fn_t refining_search_sad;
-    vp8_diamond_search_fn_t diamond_search_sad;
-    vp8_variance_fn_ptr_t fn_ptr[BLOCK_MAX_SEGMENTS];
-    uint64_t time_receive_data;
-    uint64_t time_compress_data;
-    uint64_t time_pick_lpf;
-    uint64_t time_encode_mb_row;
-
-    int base_skip_false_prob[128];
-
-    FRAME_CONTEXT lfc_n; /* last frame entropy */
-    FRAME_CONTEXT lfc_a; /* last alt ref entropy */
-    FRAME_CONTEXT lfc_g; /* last gold ref entropy */
-
-
-    struct twopass_rc
-    {
-        unsigned int section_intra_rating;
-        double section_max_qfactor;
-        unsigned int next_iiratio;
-        unsigned int this_iiratio;
-        FIRSTPASS_STATS total_stats;
-        FIRSTPASS_STATS this_frame_stats;
-        FIRSTPASS_STATS *stats_in, *stats_in_end, *stats_in_start;
-        FIRSTPASS_STATS total_left_stats;
-        int first_pass_done;
-        int64_t bits_left;
-        int64_t clip_bits_total;
-        double avg_iiratio;
-        double modified_error_total;
-        double modified_error_used;
-        double modified_error_left;
-        double kf_intra_err_min;
-        double gf_intra_err_min;
-        int frames_to_key;
-        int maxq_max_limit;
-        int maxq_min_limit;
-        int gf_decay_rate;
-        int static_scene_max_gf_interval;
-        int kf_bits;
-        /* Remaining error from uncoded frames in a gf group. */
-        int gf_group_error_left;
-        /* Projected total bits available for a key frame group of frames */
-        int64_t kf_group_bits;
-        /* Error score of frames still to be coded in kf group */
-        int64_t kf_group_error_left;
-        /* Projected Bits available for a group including 1 GF or ARF */
-        int64_t gf_group_bits;
-        /* Bits for the golden frame or ARF */
-        int gf_bits;
-        int alt_extra_bits;
-        double est_max_qcorrection_factor;
-    } twopass;
-
-#if VP8_TEMPORAL_ALT_REF
-    YV12_BUFFER_CONFIG alt_ref_buffer;
-    YV12_BUFFER_CONFIG *frames[MAX_LAG_BUFFERS];
-    int fixed_divide[512];
-#endif
-
-#if CONFIG_INTERNAL_STATS
-    int    count;
-    double total_y;
-    double total_u;
-    double total_v;
-    double total ;
-    double total_sq_error;
-    double totalp_y;
-    double totalp_u;
-    double totalp_v;
-    double totalp;
-    double total_sq_error2;
-    int    bytes;
-    double summed_quality;
-    double summed_weights;
-    unsigned int tot_recode_hits;
-
-#endif
-    int b_calculate_psnr;
-
-    /* Per MB activity measurement */
-    unsigned int activity_avg;
-    unsigned int * mb_activity_map;
-
-    /* Record of which MBs still refer to last golden frame either
-     * directly or through 0,0
-     */
-    unsigned char *gf_active_flags;
-    int gf_active_count;
-
-    int output_partition;
-
-    /* Store last frame's MV info for next frame MV prediction */
-    int_mv *lfmv;
-    int *lf_ref_frame_sign_bias;
-    int *lf_ref_frame;
-
-    /* force next frame to intra when kf_auto says so */
-    int force_next_frame_intra;
-
-    int droppable;
-
-    int initial_width;
-    int initial_height;
-
-#if CONFIG_TEMPORAL_DENOISING
-    VP8_DENOISER denoiser;
-#endif
-
-    /* Coding layer state variables */
-    unsigned int current_layer;
-    LAYER_CONTEXT layer_context[VPX_TS_MAX_LAYERS];
-
-    int64_t frames_in_layer[VPX_TS_MAX_LAYERS];
-    int64_t bytes_in_layer[VPX_TS_MAX_LAYERS];
-    double sum_psnr[VPX_TS_MAX_LAYERS];
-    double sum_psnr_p[VPX_TS_MAX_LAYERS];
-    double total_error2[VPX_TS_MAX_LAYERS];
-    double total_error2_p[VPX_TS_MAX_LAYERS];
-    double sum_ssim[VPX_TS_MAX_LAYERS];
-    double sum_weights[VPX_TS_MAX_LAYERS];
-
-#if CONFIG_MULTI_RES_ENCODING
-    /* Number of MBs per row at lower-resolution level */
-    int    mr_low_res_mb_cols;
-    /* Indicate if lower-res mv info is available */
-    unsigned char  mr_low_res_mv_avail;
-#endif
-    /* The frame number of each reference frames */
-    unsigned int current_ref_frames[MAX_REF_FRAMES];
-    // Closest reference frame to current frame.
-    MV_REFERENCE_FRAME closest_reference_frame;
-
-    struct rd_costs_struct
-    {
-        int mvcosts[2][MVvals+1];
-        int mvsadcosts[2][MVfpvals+1];
-        int mbmode_cost[2][MB_MODE_COUNT];
-        int intra_uv_mode_cost[2][MB_MODE_COUNT];
-        int bmode_costs[10][10][10];
-        int inter_bmode_costs[B_MODE_COUNT];
-        int token_costs[BLOCK_TYPES][COEF_BANDS]
-        [PREV_COEF_CONTEXTS][MAX_ENTROPY_TOKENS];
-    } rd_costs;
-} VP8_COMP;
-
-void vp8_initialize_enc(void);
-
-void vp8_alloc_compressor_data(VP8_COMP *cpi);
-int vp8_reverse_trans(int x);
-void vp8_new_framerate(VP8_COMP *cpi, double framerate);
-void vp8_loopfilter_frame(VP8_COMP *cpi, VP8_COMMON *cm);
-
-void vp8_pack_bitstream(VP8_COMP *cpi, unsigned char *dest,
-                        unsigned char *dest_end, unsigned long *size);
-
-void vp8_tokenize_mb(VP8_COMP *, MACROBLOCK *, TOKENEXTRA **);
-
-void vp8_set_speed_features(VP8_COMP *cpi);
-
-#if CONFIG_DEBUG
-#define CHECK_MEM_ERROR(lval,expr) do {\
-        lval = (expr); \
-        if(!lval) \
-            vpx_internal_error(&cpi->common.error, VPX_CODEC_MEM_ERROR,\
-                               "Failed to allocate "#lval" at %s:%d", \
-                               __FILE__,__LINE__);\
-    } while(0)
-#else
-#define CHECK_MEM_ERROR(lval,expr) do {\
-        lval = (expr); \
-        if(!lval) \
-            vpx_internal_error(&cpi->common.error, VPX_CODEC_MEM_ERROR,\
-                               "Failed to allocate "#lval);\
-    } while(0)
-#endif
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP8_ENCODER_ONYX_INT_H_
diff --git a/vp8/encoder/pickinter.c b/vp8/encoder/pickinter.c
deleted file mode 100644 (file)
index 24b332d..0000000
+++ /dev/null
@@ -1,1607 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#include <limits.h>
-#include "vpx_config.h"
-#include "./vpx_dsp_rtcd.h"
-#include "onyx_int.h"
-#include "modecosts.h"
-#include "encodeintra.h"
-#include "vp8/common/common.h"
-#include "vp8/common/entropymode.h"
-#include "pickinter.h"
-#include "vp8/common/findnearmv.h"
-#include "encodemb.h"
-#include "vp8/common/reconinter.h"
-#include "vp8/common/reconintra.h"
-#include "vp8/common/reconintra4x4.h"
-#include "vpx_dsp/variance.h"
-#include "mcomp.h"
-#include "rdopt.h"
-#include "vpx_dsp/vpx_dsp_common.h"
-#include "vpx_mem/vpx_mem.h"
-#if CONFIG_TEMPORAL_DENOISING
-#include "denoising.h"
-#endif
-
-#ifdef SPEEDSTATS
-extern unsigned int cnt_pm;
-#endif
-
-#define MODEL_MODE 1
-
-extern const int vp8_ref_frame_order[MAX_MODES];
-extern const MB_PREDICTION_MODE vp8_mode_order[MAX_MODES];
-
-// Fixed point implementation of a skin color classifier. Skin color
-// is model by a Gaussian distribution in the CbCr color space.
-// See ../../test/skin_color_detector_test.cc where the reference
-// skin color classifier is defined.
-
-// Fixed-point skin color model parameters.
-static const int skin_mean[5][2] =
-    {{7463, 9614}, {6400, 10240}, {7040, 10240}, {8320, 9280}, {6800, 9614}};
-static const int skin_inv_cov[4] = {4107, 1663, 1663, 2157};  // q16
-static const int skin_threshold[6] = {1570636, 1400000, 800000, 800000, 800000,
-    800000};  // q18
-
-// Evaluates the Mahalanobis distance measure for the input CbCr values.
-static int evaluate_skin_color_difference(int cb, int cr, int idx) {
-  const int cb_q6 = cb << 6;
-  const int cr_q6 = cr << 6;
-  const int cb_diff_q12 =
-      (cb_q6 - skin_mean[idx][0]) * (cb_q6 - skin_mean[idx][0]);
-  const int cbcr_diff_q12 =
-      (cb_q6 - skin_mean[idx][0]) * (cr_q6 - skin_mean[idx][1]);
-  const int cr_diff_q12 =
-      (cr_q6 - skin_mean[idx][1]) * (cr_q6 - skin_mean[idx][1]);
-  const int cb_diff_q2 = (cb_diff_q12 + (1 << 9)) >> 10;
-  const int cbcr_diff_q2 = (cbcr_diff_q12 + (1 << 9)) >> 10;
-  const int cr_diff_q2 = (cr_diff_q12 + (1 << 9)) >> 10;
-  const int skin_diff = skin_inv_cov[0] * cb_diff_q2 +
-      skin_inv_cov[1] * cbcr_diff_q2 +
-      skin_inv_cov[2] * cbcr_diff_q2 +
-      skin_inv_cov[3] * cr_diff_q2;
-  return skin_diff;
-}
-
-// Checks if the input yCbCr values corresponds to skin color.
-static int is_skin_color(int y, int cb, int cr, int consec_zeromv)
-{
-  if (y < 40 || y > 220)
-  {
-    return 0;
-  }
-  else
-  {
-    if (MODEL_MODE == 0)
-    {
-      return (evaluate_skin_color_difference(cb, cr, 0) < skin_threshold[0]);
-    }
-    else
-    {
-      int i = 0;
-      // No skin if block has been zero motion for long consecutive time.
-      if (consec_zeromv > 60)
-        return 0;
-      // Exit on grey.
-       if (cb == 128 && cr == 128)
-         return 0;
-       // Exit on very strong cb.
-       if (cb > 150 && cr < 110)
-         return 0;
-       for (; i < 5; i++) {
-         int skin_color_diff = evaluate_skin_color_difference(cb, cr, i);
-         if (skin_color_diff < skin_threshold[i + 1]) {
-            if (y < 60 && skin_color_diff > 3 * (skin_threshold[i + 1] >> 2))
-              return 0;
-            else if (consec_zeromv > 25 &&
-                     skin_color_diff > (skin_threshold[i + 1] >> 1))
-              return 0;
-            else
-             return 1;
-         }
-         // Exit if difference is much large than the threshold.
-         if (skin_color_diff > (skin_threshold[i + 1] << 3)) {
-           return 0;
-         }
-       }
-      return 0;
-    }
-  }
-}
-
-static int macroblock_corner_grad(unsigned char* signal, int stride,
-                                  int offsetx, int offsety, int sgnx, int sgny)
-{
-  int y1 = signal[offsetx * stride + offsety];
-  int y2 = signal[offsetx * stride + offsety + sgny];
-  int y3 = signal[(offsetx + sgnx) * stride + offsety];
-  int y4 = signal[(offsetx + sgnx) * stride + offsety + sgny];
-  return VPXMAX(VPXMAX(abs(y1 - y2), abs(y1 - y3)), abs(y1 - y4));
-}
-
-static int check_dot_artifact_candidate(VP8_COMP *cpi,
-                                        MACROBLOCK *x,
-                                        unsigned char *target_last,
-                                        int stride,
-                                        unsigned char* last_ref,
-                                        int mb_row,
-                                        int mb_col,
-                                        int channel)
-{
-  int threshold1 = 6;
-  int threshold2 = 3;
-  unsigned int max_num = (cpi->common.MBs) / 10;
-  int grad_last = 0;
-  int grad_source = 0;
-  int index = mb_row * cpi->common.mb_cols + mb_col;
-  // Threshold for #consecutive (base layer) frames using zero_last mode.
-  int num_frames = 30;
-  int shift = 15;
-  if (channel > 0) {
-    shift = 7;
-  }
-  if (cpi->oxcf.number_of_layers > 1)
-  {
-    num_frames = 20;
-  }
-  x->zero_last_dot_suppress = 0;
-  // Blocks on base layer frames that have been using ZEROMV_LAST repeatedly
-  // (i.e, at least |x| consecutive frames are candidates for increasing the
-  // rd adjustment for zero_last mode.
-  // Only allow this for at most |max_num| blocks per frame.
-  // Don't allow this for screen content input.
-  if (cpi->current_layer == 0 &&
-      cpi->consec_zero_last_mvbias[index] > num_frames &&
-      x->mbs_zero_last_dot_suppress < max_num &&
-      !cpi->oxcf.screen_content_mode)
-  {
-    // If this block is checked here, label it so we don't check it again until
-    // ~|x| framaes later.
-    x->zero_last_dot_suppress = 1;
-    // Dot artifact is noticeable as strong gradient at corners of macroblock,
-    // for flat areas. As a simple detector for now, we look for a high
-    // corner gradient on last ref, and a smaller gradient on source.
-    // Check 4 corners, return if any satisfy condition.
-    // Top-left:
-    grad_last = macroblock_corner_grad(last_ref, stride, 0, 0, 1, 1);
-    grad_source = macroblock_corner_grad(target_last, stride, 0, 0, 1, 1);
-    if (grad_last >= threshold1 && grad_source <= threshold2)
-    {
-       x->mbs_zero_last_dot_suppress++;
-       return 1;
-    }
-    // Top-right:
-    grad_last = macroblock_corner_grad(last_ref, stride, 0, shift, 1, -1);
-    grad_source = macroblock_corner_grad(target_last, stride, 0, shift, 1, -1);
-    if (grad_last >= threshold1 && grad_source <= threshold2)
-    {
-      x->mbs_zero_last_dot_suppress++;
-      return 1;
-    }
-    // Bottom-left:
-    grad_last = macroblock_corner_grad(last_ref, stride, shift, 0, -1, 1);
-    grad_source = macroblock_corner_grad(target_last, stride, shift, 0, -1, 1);
-    if (grad_last >= threshold1 && grad_source <= threshold2)
-    {
-      x->mbs_zero_last_dot_suppress++;
-      return 1;
-    }
-    // Bottom-right:
-    grad_last = macroblock_corner_grad(last_ref, stride, shift, shift, -1, -1);
-    grad_source = macroblock_corner_grad(target_last, stride, shift, shift, -1, -1);
-    if (grad_last >= threshold1 && grad_source <= threshold2)
-    {
-      x->mbs_zero_last_dot_suppress++;
-      return 1;
-    }
-    return 0;
-  }
-  return 0;
-}
-
-int vp8_skip_fractional_mv_step(MACROBLOCK *mb, BLOCK *b, BLOCKD *d,
-                                int_mv *bestmv, int_mv *ref_mv,
-                                int error_per_bit,
-                                const vp8_variance_fn_ptr_t *vfp,
-                                int *mvcost[2], int *distortion,
-                                unsigned int *sse)
-{
-    (void) b;
-    (void) d;
-    (void) ref_mv;
-    (void) error_per_bit;
-    (void) vfp;
-    (void) mb;
-    (void) mvcost;
-    (void) distortion;
-    (void) sse;
-    bestmv->as_mv.row <<= 3;
-    bestmv->as_mv.col <<= 3;
-    return 0;
-}
-
-
-int vp8_get_inter_mbpred_error(MACROBLOCK *mb,
-                                  const vp8_variance_fn_ptr_t *vfp,
-                                  unsigned int *sse,
-                                  int_mv this_mv)
-{
-
-    BLOCK *b = &mb->block[0];
-    BLOCKD *d = &mb->e_mbd.block[0];
-    unsigned char *what = (*(b->base_src) + b->src);
-    int what_stride = b->src_stride;
-    int pre_stride = mb->e_mbd.pre.y_stride;
-    unsigned char *in_what = mb->e_mbd.pre.y_buffer + d->offset ;
-    int in_what_stride = pre_stride;
-    int xoffset = this_mv.as_mv.col & 7;
-    int yoffset = this_mv.as_mv.row & 7;
-
-    in_what += (this_mv.as_mv.row >> 3) * pre_stride + (this_mv.as_mv.col >> 3);
-
-    if (xoffset | yoffset)
-    {
-        return vfp->svf(in_what, in_what_stride, xoffset, yoffset, what, what_stride, sse);
-    }
-    else
-    {
-        return vfp->vf(what, what_stride, in_what, in_what_stride, sse);
-    }
-
-}
-
-static int get_prediction_error(BLOCK *be, BLOCKD *b)
-{
-    unsigned char *sptr;
-    unsigned char *dptr;
-    sptr = (*(be->base_src) + be->src);
-    dptr = b->predictor;
-
-    return vpx_get4x4sse_cs(sptr, be->src_stride, dptr, 16);
-
-}
-
-static int pick_intra4x4block(
-    MACROBLOCK *x,
-    int ib,
-    B_PREDICTION_MODE *best_mode,
-    const int *mode_costs,
-
-    int *bestrate,
-    int *bestdistortion)
-{
-
-    BLOCKD *b = &x->e_mbd.block[ib];
-    BLOCK *be = &x->block[ib];
-    int dst_stride = x->e_mbd.dst.y_stride;
-    unsigned char *dst = x->e_mbd.dst.y_buffer + b->offset;
-    B_PREDICTION_MODE mode;
-    int best_rd = INT_MAX;
-    int rate;
-    int distortion;
-
-    unsigned char *Above = dst - dst_stride;
-    unsigned char *yleft = dst - 1;
-    unsigned char top_left = Above[-1];
-
-    for (mode = B_DC_PRED; mode <= B_HE_PRED; mode++)
-    {
-        int this_rd;
-
-        rate = mode_costs[mode];
-
-        vp8_intra4x4_predict(Above, yleft, dst_stride, mode,
-                             b->predictor, 16, top_left);
-        distortion = get_prediction_error(be, b);
-        this_rd = RDCOST(x->rdmult, x->rddiv, rate, distortion);
-
-        if (this_rd < best_rd)
-        {
-            *bestrate = rate;
-            *bestdistortion = distortion;
-            best_rd = this_rd;
-            *best_mode = mode;
-        }
-    }
-
-    b->bmi.as_mode = *best_mode;
-    vp8_encode_intra4x4block(x, ib);
-    return best_rd;
-}
-
-
-static int pick_intra4x4mby_modes
-(
-    MACROBLOCK *mb,
-    int *Rate,
-    int *best_dist
-)
-{
-    MACROBLOCKD *const xd = &mb->e_mbd;
-    int i;
-    int cost = mb->mbmode_cost [xd->frame_type] [B_PRED];
-    int error;
-    int distortion = 0;
-    const int *bmode_costs;
-
-    intra_prediction_down_copy(xd, xd->dst.y_buffer - xd->dst.y_stride + 16);
-
-    bmode_costs = mb->inter_bmode_costs;
-
-    for (i = 0; i < 16; i++)
-    {
-        MODE_INFO *const mic = xd->mode_info_context;
-        const int mis = xd->mode_info_stride;
-
-        B_PREDICTION_MODE UNINITIALIZED_IS_SAFE(best_mode);
-        int UNINITIALIZED_IS_SAFE(r), UNINITIALIZED_IS_SAFE(d);
-
-        if (mb->e_mbd.frame_type == KEY_FRAME)
-        {
-            const B_PREDICTION_MODE A = above_block_mode(mic, i, mis);
-            const B_PREDICTION_MODE L = left_block_mode(mic, i);
-
-            bmode_costs  = mb->bmode_costs[A][L];
-        }
-
-
-        pick_intra4x4block(mb, i, &best_mode, bmode_costs, &r, &d);
-
-        cost += r;
-        distortion += d;
-        mic->bmi[i].as_mode = best_mode;
-
-        /* Break out case where we have already exceeded best so far value
-         * that was passed in
-         */
-        if (distortion > *best_dist)
-            break;
-    }
-
-    *Rate = cost;
-
-    if (i == 16)
-    {
-        *best_dist = distortion;
-        error = RDCOST(mb->rdmult, mb->rddiv, cost, distortion);
-    }
-    else
-    {
-        *best_dist = INT_MAX;
-        error = INT_MAX;
-    }
-
-    return error;
-}
-
-static void pick_intra_mbuv_mode(MACROBLOCK *mb)
-{
-
-    MACROBLOCKD *x = &mb->e_mbd;
-    unsigned char *uabove_row = x->dst.u_buffer - x->dst.uv_stride;
-    unsigned char *vabove_row = x->dst.v_buffer - x->dst.uv_stride;
-    unsigned char *usrc_ptr = (mb->block[16].src + *mb->block[16].base_src);
-    unsigned char *vsrc_ptr = (mb->block[20].src + *mb->block[20].base_src);
-    int uvsrc_stride = mb->block[16].src_stride;
-    unsigned char uleft_col[8];
-    unsigned char vleft_col[8];
-    unsigned char utop_left = uabove_row[-1];
-    unsigned char vtop_left = vabove_row[-1];
-    int i, j;
-    int expected_udc;
-    int expected_vdc;
-    int shift;
-    int Uaverage = 0;
-    int Vaverage = 0;
-    int diff;
-    int pred_error[4] = {0, 0, 0, 0}, best_error = INT_MAX;
-    MB_PREDICTION_MODE UNINITIALIZED_IS_SAFE(best_mode);
-
-
-    for (i = 0; i < 8; i++)
-    {
-        uleft_col[i] = x->dst.u_buffer [i* x->dst.uv_stride -1];
-        vleft_col[i] = x->dst.v_buffer [i* x->dst.uv_stride -1];
-    }
-
-    if (!x->up_available && !x->left_available)
-    {
-        expected_udc = 128;
-        expected_vdc = 128;
-    }
-    else
-    {
-        shift = 2;
-
-        if (x->up_available)
-        {
-
-            for (i = 0; i < 8; i++)
-            {
-                Uaverage += uabove_row[i];
-                Vaverage += vabove_row[i];
-            }
-
-            shift ++;
-
-        }
-
-        if (x->left_available)
-        {
-            for (i = 0; i < 8; i++)
-            {
-                Uaverage += uleft_col[i];
-                Vaverage += vleft_col[i];
-            }
-
-            shift ++;
-
-        }
-
-        expected_udc = (Uaverage + (1 << (shift - 1))) >> shift;
-        expected_vdc = (Vaverage + (1 << (shift - 1))) >> shift;
-    }
-
-
-    for (i = 0; i < 8; i++)
-    {
-        for (j = 0; j < 8; j++)
-        {
-
-            int predu = uleft_col[i] + uabove_row[j] - utop_left;
-            int predv = vleft_col[i] + vabove_row[j] - vtop_left;
-            int u_p, v_p;
-
-            u_p = usrc_ptr[j];
-            v_p = vsrc_ptr[j];
-
-            if (predu < 0)
-                predu = 0;
-
-            if (predu > 255)
-                predu = 255;
-
-            if (predv < 0)
-                predv = 0;
-
-            if (predv > 255)
-                predv = 255;
-
-
-            diff = u_p - expected_udc;
-            pred_error[DC_PRED] += diff * diff;
-            diff = v_p - expected_vdc;
-            pred_error[DC_PRED] += diff * diff;
-
-
-            diff = u_p - uabove_row[j];
-            pred_error[V_PRED] += diff * diff;
-            diff = v_p - vabove_row[j];
-            pred_error[V_PRED] += diff * diff;
-
-
-            diff = u_p - uleft_col[i];
-            pred_error[H_PRED] += diff * diff;
-            diff = v_p - vleft_col[i];
-            pred_error[H_PRED] += diff * diff;
-
-
-            diff = u_p - predu;
-            pred_error[TM_PRED] += diff * diff;
-            diff = v_p - predv;
-            pred_error[TM_PRED] += diff * diff;
-
-
-        }
-
-        usrc_ptr += uvsrc_stride;
-        vsrc_ptr += uvsrc_stride;
-
-        if (i == 3)
-        {
-            usrc_ptr = (mb->block[18].src + *mb->block[18].base_src);
-            vsrc_ptr = (mb->block[22].src + *mb->block[22].base_src);
-        }
-
-
-
-    }
-
-
-    for (i = DC_PRED; i <= TM_PRED; i++)
-    {
-        if (best_error > pred_error[i])
-        {
-            best_error = pred_error[i];
-            best_mode = (MB_PREDICTION_MODE)i;
-        }
-    }
-
-
-    mb->e_mbd.mode_info_context->mbmi.uv_mode = best_mode;
-
-}
-
-static void update_mvcount(MACROBLOCK *x, int_mv *best_ref_mv)
-{
-    MACROBLOCKD *xd = &x->e_mbd;
-    /* Split MV modes currently not supported when RD is nopt enabled,
-     * therefore, only need to modify MVcount in NEWMV mode. */
-    if (xd->mode_info_context->mbmi.mode == NEWMV)
-    {
-        x->MVcount[0][mv_max+((xd->mode_info_context->mbmi.mv.as_mv.row -
-                                      best_ref_mv->as_mv.row) >> 1)]++;
-        x->MVcount[1][mv_max+((xd->mode_info_context->mbmi.mv.as_mv.col -
-                                      best_ref_mv->as_mv.col) >> 1)]++;
-    }
-}
-
-
-#if CONFIG_MULTI_RES_ENCODING
-static
-void get_lower_res_motion_info(VP8_COMP *cpi, MACROBLOCKD *xd, int *dissim,
-                               int *parent_ref_frame,
-                               MB_PREDICTION_MODE *parent_mode,
-                               int_mv *parent_ref_mv, int mb_row, int mb_col)
-{
-    LOWER_RES_MB_INFO* store_mode_info
-                          = ((LOWER_RES_FRAME_INFO*)cpi->oxcf.mr_low_res_mode_info)->mb_info;
-    unsigned int parent_mb_index;
-
-    /* Consider different down_sampling_factor.  */
-    {
-        /* TODO: Removed the loop that supports special down_sampling_factor
-         * such as 2, 4, 8. Will revisit it if needed.
-         * Should also try using a look-up table to see if it helps
-         * performance. */
-        int parent_mb_row, parent_mb_col;
-
-        parent_mb_row = mb_row*cpi->oxcf.mr_down_sampling_factor.den
-                    /cpi->oxcf.mr_down_sampling_factor.num;
-        parent_mb_col = mb_col*cpi->oxcf.mr_down_sampling_factor.den
-                    /cpi->oxcf.mr_down_sampling_factor.num;
-        parent_mb_index = parent_mb_row*cpi->mr_low_res_mb_cols + parent_mb_col;
-    }
-
-    /* Read lower-resolution mode & motion result from memory.*/
-    *parent_ref_frame = store_mode_info[parent_mb_index].ref_frame;
-    *parent_mode =  store_mode_info[parent_mb_index].mode;
-    *dissim = store_mode_info[parent_mb_index].dissim;
-
-    /* For highest-resolution encoder, adjust dissim value. Lower its quality
-     * for good performance. */
-    if (cpi->oxcf.mr_encoder_id == (cpi->oxcf.mr_total_resolutions - 1))
-        *dissim>>=1;
-
-    if(*parent_ref_frame != INTRA_FRAME)
-    {
-        /* Consider different down_sampling_factor.
-         * The result can be rounded to be more precise, but it takes more time.
-         */
-        (*parent_ref_mv).as_mv.row = store_mode_info[parent_mb_index].mv.as_mv.row
-                                  *cpi->oxcf.mr_down_sampling_factor.num
-                                  /cpi->oxcf.mr_down_sampling_factor.den;
-        (*parent_ref_mv).as_mv.col = store_mode_info[parent_mb_index].mv.as_mv.col
-                                  *cpi->oxcf.mr_down_sampling_factor.num
-                                  /cpi->oxcf.mr_down_sampling_factor.den;
-
-        vp8_clamp_mv2(parent_ref_mv, xd);
-    }
-}
-#endif
-
-static void check_for_encode_breakout(unsigned int sse, MACROBLOCK* x)
-{
-    MACROBLOCKD *xd = &x->e_mbd;
-
-    unsigned int threshold = (xd->block[0].dequant[1]
-        * xd->block[0].dequant[1] >>4);
-
-    if(threshold < x->encode_breakout)
-        threshold = x->encode_breakout;
-
-    if (sse < threshold )
-    {
-        /* Check u and v to make sure skip is ok */
-        unsigned int sse2 = 0;
-
-        sse2 = VP8_UVSSE(x);
-
-        if (sse2 * 2 < x->encode_breakout)
-            x->skip = 1;
-        else
-            x->skip = 0;
-    }
-}
-
-static int evaluate_inter_mode(unsigned int* sse, int rate2, int* distortion2,
-                               VP8_COMP *cpi, MACROBLOCK *x, int rd_adj)
-{
-    MB_PREDICTION_MODE this_mode = x->e_mbd.mode_info_context->mbmi.mode;
-    int_mv mv = x->e_mbd.mode_info_context->mbmi.mv;
-    int this_rd;
-    int denoise_aggressive = 0;
-    /* Exit early and don't compute the distortion if this macroblock
-     * is marked inactive. */
-    if (cpi->active_map_enabled && x->active_ptr[0] == 0)
-    {
-        *sse = 0;
-        *distortion2 = 0;
-        x->skip = 1;
-        return INT_MAX;
-    }
-
-    if((this_mode != NEWMV) ||
-        !(cpi->sf.half_pixel_search) || cpi->common.full_pixel==1)
-        *distortion2 = vp8_get_inter_mbpred_error(x,
-                                              &cpi->fn_ptr[BLOCK_16X16],
-                                              sse, mv);
-
-    this_rd = RDCOST(x->rdmult, x->rddiv, rate2, *distortion2);
-
-#if CONFIG_TEMPORAL_DENOISING
-    if (cpi->oxcf.noise_sensitivity > 0) {
-      denoise_aggressive =
-        (cpi->denoiser.denoiser_mode == kDenoiserOnYUVAggressive) ? 1 : 0;
-    }
-#endif
-
-    // Adjust rd for ZEROMV and LAST, if LAST is the closest reference frame.
-    // TODO: We should also add condition on distance of closest to current.
-    if(!cpi->oxcf.screen_content_mode &&
-       this_mode == ZEROMV &&
-       x->e_mbd.mode_info_context->mbmi.ref_frame == LAST_FRAME &&
-       (denoise_aggressive || (cpi->closest_reference_frame == LAST_FRAME)))
-    {
-        // No adjustment if block is considered to be skin area.
-        if(x->is_skin)
-            rd_adj = 100;
-
-        this_rd = ((int64_t)this_rd) * rd_adj / 100;
-    }
-
-    check_for_encode_breakout(*sse, x);
-    return this_rd;
-}
-
-static void calculate_zeromv_rd_adjustment(VP8_COMP *cpi, MACROBLOCK *x,
-                                    int *rd_adjustment)
-{
-    MODE_INFO *mic = x->e_mbd.mode_info_context;
-    int_mv mv_l, mv_a, mv_al;
-    int local_motion_check = 0;
-
-    if (cpi->lf_zeromv_pct > 40)
-    {
-        /* left mb */
-        mic -= 1;
-        mv_l = mic->mbmi.mv;
-
-        if (mic->mbmi.ref_frame != INTRA_FRAME)
-            if( abs(mv_l.as_mv.row) < 8 && abs(mv_l.as_mv.col) < 8)
-                local_motion_check++;
-
-        /* above-left mb */
-        mic -= x->e_mbd.mode_info_stride;
-        mv_al = mic->mbmi.mv;
-
-        if (mic->mbmi.ref_frame != INTRA_FRAME)
-            if( abs(mv_al.as_mv.row) < 8 && abs(mv_al.as_mv.col) < 8)
-                local_motion_check++;
-
-        /* above mb */
-        mic += 1;
-        mv_a = mic->mbmi.mv;
-
-        if (mic->mbmi.ref_frame != INTRA_FRAME)
-            if( abs(mv_a.as_mv.row) < 8 && abs(mv_a.as_mv.col) < 8)
-                local_motion_check++;
-
-        if (((!x->e_mbd.mb_to_top_edge || !x->e_mbd.mb_to_left_edge)
-            && local_motion_check >0) ||  local_motion_check >2 )
-            *rd_adjustment = 80;
-        else if (local_motion_check > 0)
-            *rd_adjustment = 90;
-    }
-}
-
-void vp8_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset,
-                         int recon_uvoffset, int *returnrate,
-                         int *returndistortion, int *returnintra, int mb_row,
-                         int mb_col)
-{
-    BLOCK *b = &x->block[0];
-    BLOCKD *d = &x->e_mbd.block[0];
-    MACROBLOCKD *xd = &x->e_mbd;
-    MB_MODE_INFO best_mbmode;
-
-    int_mv best_ref_mv_sb[2];
-    int_mv mode_mv_sb[2][MB_MODE_COUNT];
-    int_mv best_ref_mv;
-    int_mv *mode_mv;
-    MB_PREDICTION_MODE this_mode;
-    int num00;
-    int mdcounts[4];
-    int best_rd = INT_MAX;
-    int rd_adjustment = 100;
-    int best_intra_rd = INT_MAX;
-    int mode_index;
-    int rate;
-    int rate2;
-    int distortion2;
-    int bestsme = INT_MAX;
-    int best_mode_index = 0;
-    unsigned int sse = UINT_MAX, best_rd_sse = UINT_MAX;
-#if CONFIG_TEMPORAL_DENOISING
-    unsigned int zero_mv_sse = UINT_MAX, best_sse = UINT_MAX;
-#endif
-
-    int sf_improved_mv_pred = cpi->sf.improved_mv_pred;
-
-#if CONFIG_MULTI_RES_ENCODING
-    int dissim = INT_MAX;
-    int parent_ref_frame = 0;
-    int_mv parent_ref_mv;
-    MB_PREDICTION_MODE parent_mode = 0;
-    int parent_ref_valid = 0;
-#endif
-
-    int_mv mvp;
-
-    int near_sadidx[8] = {0, 1, 2, 3, 4, 5, 6, 7};
-    int saddone=0;
-    /* search range got from mv_pred(). It uses step_param levels. (0-7) */
-    int sr=0;
-
-    unsigned char *plane[4][3];
-    int ref_frame_map[4];
-    int sign_bias = 0;
-    int dot_artifact_candidate = 0;
-    get_predictor_pointers(cpi, plane, recon_yoffset, recon_uvoffset);
-
-    // If the current frame is using LAST as a reference, check for
-    // biasing the mode selection for dot artifacts.
-    if (cpi->ref_frame_flags & VP8_LAST_FRAME) {
-      unsigned char* target_y = x->src.y_buffer;
-      unsigned char* target_u = x->block[16].src + *x->block[16].base_src;
-      unsigned char* target_v = x->block[20].src + *x->block[20].base_src;
-      int stride = x->src.y_stride;
-      int stride_uv = x->block[16].src_stride;
-#if CONFIG_TEMPORAL_DENOISING
-      if (cpi->oxcf.noise_sensitivity) {
-        const int uv_denoise = (cpi->oxcf.noise_sensitivity >= 2) ? 1 : 0;
-        target_y =
-            cpi->denoiser.yv12_running_avg[LAST_FRAME].y_buffer + recon_yoffset;
-        stride = cpi->denoiser.yv12_running_avg[LAST_FRAME].y_stride;
-        if (uv_denoise) {
-          target_u =
-              cpi->denoiser.yv12_running_avg[LAST_FRAME].u_buffer +
-                  recon_uvoffset;
-          target_v =
-              cpi->denoiser.yv12_running_avg[LAST_FRAME].v_buffer +
-                  recon_uvoffset;
-          stride_uv = cpi->denoiser.yv12_running_avg[LAST_FRAME].uv_stride;
-        }
-      }
-#endif
-      dot_artifact_candidate =
-          check_dot_artifact_candidate(cpi, x, target_y, stride,
-              plane[LAST_FRAME][0], mb_row, mb_col, 0);
-      // If not found in Y channel, check UV channel.
-      if (!dot_artifact_candidate) {
-        dot_artifact_candidate =
-            check_dot_artifact_candidate(cpi, x, target_u, stride_uv,
-                plane[LAST_FRAME][1], mb_row, mb_col, 1);
-        if (!dot_artifact_candidate) {
-          dot_artifact_candidate =
-              check_dot_artifact_candidate(cpi, x, target_v, stride_uv,
-                  plane[LAST_FRAME][2], mb_row, mb_col, 2);
-        }
-      }
-    }
-
-#if CONFIG_MULTI_RES_ENCODING
-    // |parent_ref_valid| will be set here if potentially we can do mv resue for
-    // this higher resol (|cpi->oxcf.mr_encoder_id| > 0) frame.
-    // |parent_ref_valid| may be reset depending on |parent_ref_frame| for
-    // the current macroblock below.
-    parent_ref_valid = cpi->oxcf.mr_encoder_id && cpi->mr_low_res_mv_avail;
-    if (parent_ref_valid)
-    {
-        int parent_ref_flag;
-
-        get_lower_res_motion_info(cpi, xd, &dissim, &parent_ref_frame,
-                                  &parent_mode, &parent_ref_mv, mb_row, mb_col);
-
-        /* TODO(jkoleszar): The references available (ref_frame_flags) to the
-         * lower res encoder should match those available to this encoder, but
-         * there seems to be a situation where this mismatch can happen in the
-         * case of frame dropping and temporal layers. For example,
-         * GOLD being disallowed in ref_frame_flags, but being returned as
-         * parent_ref_frame.
-         *
-         * In this event, take the conservative approach of disabling the
-         * lower res info for this MB.
-         */
-
-        parent_ref_flag = 0;
-        // Note availability for mv reuse is only based on last and golden.
-        if (parent_ref_frame == LAST_FRAME)
-            parent_ref_flag = (cpi->ref_frame_flags & VP8_LAST_FRAME);
-        else if (parent_ref_frame == GOLDEN_FRAME)
-            parent_ref_flag = (cpi->ref_frame_flags & VP8_GOLD_FRAME);
-
-        //assert(!parent_ref_frame || parent_ref_flag);
-
-        // If |parent_ref_frame| did not match either last or golden then
-        // shut off mv reuse.
-        if (parent_ref_frame && !parent_ref_flag)
-            parent_ref_valid = 0;
-
-        // Don't do mv reuse since we want to allow for another mode besides
-        // ZEROMV_LAST to remove dot artifact.
-        if (dot_artifact_candidate)
-          parent_ref_valid = 0;
-    }
-#endif
-
-    // Check if current macroblock is in skin area.
-    {
-    const int y = (x->src.y_buffer[7 * x->src.y_stride + 7] +
-        x->src.y_buffer[7 * x->src.y_stride + 8] +
-        x->src.y_buffer[8 * x->src.y_stride + 7] +
-        x->src.y_buffer[8 * x->src.y_stride + 8]) >> 2;
-    const int cb = (x->src.u_buffer[3 * x->src.uv_stride + 3] +
-        x->src.u_buffer[3 * x->src.uv_stride + 4] +
-        x->src.u_buffer[4 * x->src.uv_stride + 3] +
-        x->src.u_buffer[4 * x->src.uv_stride + 4]) >> 2;
-    const int cr = (x->src.v_buffer[3 * x->src.uv_stride + 3] +
-        x->src.v_buffer[3 * x->src.uv_stride + 4] +
-        x->src.v_buffer[4 * x->src.uv_stride + 3] +
-        x->src.v_buffer[4 * x->src.uv_stride + 4]) >> 2;
-    x->is_skin = 0;
-    if (!cpi->oxcf.screen_content_mode) {
-      int block_index = mb_row * cpi->common.mb_cols + mb_col;
-      x->is_skin = is_skin_color(y, cb, cr, cpi->consec_zero_last[block_index]);
-    }
-    }
-#if CONFIG_TEMPORAL_DENOISING
-    if (cpi->oxcf.noise_sensitivity) {
-      // Under aggressive denoising mode, should we use skin map to reduce denoiser
-      // and ZEROMV bias? Will need to revisit the accuracy of this detection for
-      // very noisy input. For now keep this as is (i.e., don't turn it off).
-      // if (cpi->denoiser.denoiser_mode == kDenoiserOnYUVAggressive)
-      //   x->is_skin = 0;
-    }
-#endif
-
-    mode_mv = mode_mv_sb[sign_bias];
-    best_ref_mv.as_int = 0;
-    memset(mode_mv_sb, 0, sizeof(mode_mv_sb));
-    memset(&best_mbmode, 0, sizeof(best_mbmode));
-
-    /* Setup search priorities */
-#if CONFIG_MULTI_RES_ENCODING
-    if (parent_ref_valid && parent_ref_frame && dissim < 8)
-    {
-        ref_frame_map[0] = -1;
-        ref_frame_map[1] = parent_ref_frame;
-        ref_frame_map[2] = -1;
-        ref_frame_map[3] = -1;
-    } else
-#endif
-    get_reference_search_order(cpi, ref_frame_map);
-
-    /* Check to see if there is at least 1 valid reference frame that we need
-     * to calculate near_mvs.
-     */
-    if (ref_frame_map[1] > 0)
-    {
-        sign_bias = vp8_find_near_mvs_bias(&x->e_mbd,
-                                           x->e_mbd.mode_info_context,
-                                           mode_mv_sb,
-                                           best_ref_mv_sb,
-                                           mdcounts,
-                                           ref_frame_map[1],
-                                           cpi->common.ref_frame_sign_bias);
-
-        mode_mv = mode_mv_sb[sign_bias];
-        best_ref_mv.as_int = best_ref_mv_sb[sign_bias].as_int;
-    }
-
-    /* Count of the number of MBs tested so far this frame */
-    x->mbs_tested_so_far++;
-
-    *returnintra = INT_MAX;
-    x->skip = 0;
-
-    x->e_mbd.mode_info_context->mbmi.ref_frame = INTRA_FRAME;
-
-    /* If the frame has big static background and current MB is in low
-    *  motion area, its mode decision is biased to ZEROMV mode.
-    *  No adjustment if cpu_used is <= -12 (i.e., cpi->Speed >= 12).
-    *  At such speed settings, ZEROMV is already heavily favored.
-    */
-    if (cpi->Speed < 12) {
-      calculate_zeromv_rd_adjustment(cpi, x, &rd_adjustment);
-    }
-
-#if CONFIG_TEMPORAL_DENOISING
-    if (cpi->oxcf.noise_sensitivity) {
-      rd_adjustment = (int)(rd_adjustment *
-          cpi->denoiser.denoise_pars.pickmode_mv_bias / 100);
-    }
-#endif
-
-    if (dot_artifact_candidate)
-    {
-        // Bias against ZEROMV_LAST mode.
-        rd_adjustment = 150;
-    }
-
-
-    /* if we encode a new mv this is important
-     * find the best new motion vector
-     */
-    for (mode_index = 0; mode_index < MAX_MODES; mode_index++)
-    {
-        int frame_cost;
-        int this_rd = INT_MAX;
-        int this_ref_frame = ref_frame_map[vp8_ref_frame_order[mode_index]];
-
-        if (best_rd <= x->rd_threshes[mode_index])
-            continue;
-
-        if (this_ref_frame < 0)
-            continue;
-
-        x->e_mbd.mode_info_context->mbmi.ref_frame = this_ref_frame;
-
-        /* everything but intra */
-        if (x->e_mbd.mode_info_context->mbmi.ref_frame)
-        {
-            x->e_mbd.pre.y_buffer = plane[this_ref_frame][0];
-            x->e_mbd.pre.u_buffer = plane[this_ref_frame][1];
-            x->e_mbd.pre.v_buffer = plane[this_ref_frame][2];
-
-            if (sign_bias != cpi->common.ref_frame_sign_bias[this_ref_frame])
-            {
-                sign_bias = cpi->common.ref_frame_sign_bias[this_ref_frame];
-                mode_mv = mode_mv_sb[sign_bias];
-                best_ref_mv.as_int = best_ref_mv_sb[sign_bias].as_int;
-            }
-
-#if CONFIG_MULTI_RES_ENCODING
-            if (parent_ref_valid)
-            {
-                if (vp8_mode_order[mode_index] == NEARESTMV &&
-                    mode_mv[NEARESTMV].as_int ==0)
-                    continue;
-                if (vp8_mode_order[mode_index] == NEARMV &&
-                    mode_mv[NEARMV].as_int ==0)
-                    continue;
-
-                if (vp8_mode_order[mode_index] == NEWMV && parent_mode == ZEROMV
-                    && best_ref_mv.as_int==0)
-                    continue;
-                else if(vp8_mode_order[mode_index] == NEWMV && dissim==0
-                    && best_ref_mv.as_int==parent_ref_mv.as_int)
-                    continue;
-            }
-#endif
-        }
-
-        /* Check to see if the testing frequency for this mode is at its max
-         * If so then prevent it from being tested and increase the threshold
-         * for its testing */
-        if (x->mode_test_hit_counts[mode_index] &&
-                                         (cpi->mode_check_freq[mode_index] > 1))
-        {
-            if (x->mbs_tested_so_far <= (cpi->mode_check_freq[mode_index] *
-                                         x->mode_test_hit_counts[mode_index]))
-            {
-                /* Increase the threshold for coding this mode to make it less
-                 * likely to be chosen */
-                x->rd_thresh_mult[mode_index] += 4;
-
-                if (x->rd_thresh_mult[mode_index] > MAX_THRESHMULT)
-                    x->rd_thresh_mult[mode_index] = MAX_THRESHMULT;
-
-                x->rd_threshes[mode_index] =
-                                 (cpi->rd_baseline_thresh[mode_index] >> 7) *
-                                 x->rd_thresh_mult[mode_index];
-                continue;
-            }
-        }
-
-        /* We have now reached the point where we are going to test the current
-         * mode so increment the counter for the number of times it has been
-         * tested */
-        x->mode_test_hit_counts[mode_index] ++;
-
-        rate2 = 0;
-        distortion2 = 0;
-
-        this_mode = vp8_mode_order[mode_index];
-
-        x->e_mbd.mode_info_context->mbmi.mode = this_mode;
-        x->e_mbd.mode_info_context->mbmi.uv_mode = DC_PRED;
-
-        /* Work out the cost assosciated with selecting the reference frame */
-        frame_cost =
-            x->ref_frame_cost[x->e_mbd.mode_info_context->mbmi.ref_frame];
-        rate2 += frame_cost;
-
-        /* Only consider ZEROMV/ALTREF_FRAME for alt ref frame,
-         * unless ARNR filtering is enabled in which case we want
-         * an unfiltered alternative */
-        if (cpi->is_src_frame_alt_ref && (cpi->oxcf.arnr_max_frames == 0))
-        {
-            if (this_mode != ZEROMV ||
-                x->e_mbd.mode_info_context->mbmi.ref_frame != ALTREF_FRAME)
-                continue;
-        }
-
-        switch (this_mode)
-        {
-        case B_PRED:
-            /* Pass best so far to pick_intra4x4mby_modes to use as breakout */
-            distortion2 = best_rd_sse;
-            pick_intra4x4mby_modes(x, &rate, &distortion2);
-
-            if (distortion2 == INT_MAX)
-            {
-                this_rd = INT_MAX;
-            }
-            else
-            {
-                rate2 += rate;
-                distortion2 = vpx_variance16x16(
-                                    *(b->base_src), b->src_stride,
-                                    x->e_mbd.predictor, 16, &sse);
-                this_rd = RDCOST(x->rdmult, x->rddiv, rate2, distortion2);
-
-                if (this_rd < best_intra_rd)
-                {
-                    best_intra_rd = this_rd;
-                    *returnintra = distortion2;
-                }
-            }
-
-            break;
-
-        case SPLITMV:
-
-            /* Split MV modes currently not supported when RD is not enabled. */
-            break;
-
-        case DC_PRED:
-        case V_PRED:
-        case H_PRED:
-        case TM_PRED:
-            vp8_build_intra_predictors_mby_s(xd,
-                                             xd->dst.y_buffer - xd->dst.y_stride,
-                                             xd->dst.y_buffer - 1,
-                                             xd->dst.y_stride,
-                                             xd->predictor,
-                                             16);
-            distortion2 = vpx_variance16x16
-                                          (*(b->base_src), b->src_stride,
-                                          x->e_mbd.predictor, 16, &sse);
-            rate2 += x->mbmode_cost[x->e_mbd.frame_type][x->e_mbd.mode_info_context->mbmi.mode];
-            this_rd = RDCOST(x->rdmult, x->rddiv, rate2, distortion2);
-
-            if (this_rd < best_intra_rd)
-            {
-                best_intra_rd = this_rd;
-                *returnintra = distortion2;
-            }
-            break;
-
-        case NEWMV:
-        {
-            int thissme;
-            int step_param;
-            int further_steps;
-            int n = 0;
-            int sadpb = x->sadperbit16;
-            int_mv mvp_full;
-
-            int col_min = ((best_ref_mv.as_mv.col+7)>>3) - MAX_FULL_PEL_VAL;
-            int row_min = ((best_ref_mv.as_mv.row+7)>>3) - MAX_FULL_PEL_VAL;
-            int col_max = (best_ref_mv.as_mv.col>>3)
-                         + MAX_FULL_PEL_VAL;
-            int row_max = (best_ref_mv.as_mv.row>>3)
-                         + MAX_FULL_PEL_VAL;
-
-            int tmp_col_min = x->mv_col_min;
-            int tmp_col_max = x->mv_col_max;
-            int tmp_row_min = x->mv_row_min;
-            int tmp_row_max = x->mv_row_max;
-
-            int speed_adjust = (cpi->Speed > 5) ? ((cpi->Speed >= 8)? 3 : 2) : 1;
-
-            /* Further step/diamond searches as necessary */
-            step_param = cpi->sf.first_step + speed_adjust;
-
-#if CONFIG_MULTI_RES_ENCODING
-            /* If lower-res frame is not available for mv reuse (because of
-               frame dropping or different temporal layer pattern), then higher
-               resol encoder does motion search without any previous knowledge.
-               Also, since last frame motion info is not stored, then we can not
-               use improved_mv_pred. */
-            if (cpi->oxcf.mr_encoder_id)
-                sf_improved_mv_pred = 0;
-
-            // Only use parent MV as predictor if this candidate reference frame
-            // (|this_ref_frame|) is equal to |parent_ref_frame|.
-            if (parent_ref_valid && (parent_ref_frame == this_ref_frame))
-            {
-                /* Use parent MV as predictor. Adjust search range
-                 * accordingly.
-                 */
-                mvp.as_int = parent_ref_mv.as_int;
-                mvp_full.as_mv.col = parent_ref_mv.as_mv.col>>3;
-                mvp_full.as_mv.row = parent_ref_mv.as_mv.row>>3;
-
-                if(dissim <=32) step_param += 3;
-                else if(dissim <=128) step_param += 2;
-                else step_param += 1;
-            }else
-#endif
-            {
-                if(sf_improved_mv_pred)
-                {
-                    if(!saddone)
-                    {
-                        vp8_cal_sad(cpi,xd,x, recon_yoffset ,&near_sadidx[0] );
-                        saddone = 1;
-                    }
-
-                    vp8_mv_pred(cpi, &x->e_mbd, x->e_mbd.mode_info_context,
-                                &mvp,x->e_mbd.mode_info_context->mbmi.ref_frame,
-                                cpi->common.ref_frame_sign_bias, &sr,
-                                &near_sadidx[0]);
-
-                    sr += speed_adjust;
-                    /* adjust search range according to sr from mv prediction */
-                    if(sr > step_param)
-                        step_param = sr;
-
-                    mvp_full.as_mv.col = mvp.as_mv.col>>3;
-                    mvp_full.as_mv.row = mvp.as_mv.row>>3;
-                }else
-                {
-                    mvp.as_int = best_ref_mv.as_int;
-                    mvp_full.as_mv.col = best_ref_mv.as_mv.col>>3;
-                    mvp_full.as_mv.row = best_ref_mv.as_mv.row>>3;
-                }
-            }
-
-#if CONFIG_MULTI_RES_ENCODING
-            if (parent_ref_valid && (parent_ref_frame == this_ref_frame) &&
-                dissim <= 2 &&
-                VPXMAX(abs(best_ref_mv.as_mv.row - parent_ref_mv.as_mv.row),
-                       abs(best_ref_mv.as_mv.col - parent_ref_mv.as_mv.col)) <=
-                    4)
-            {
-                d->bmi.mv.as_int = mvp_full.as_int;
-                mode_mv[NEWMV].as_int = mvp_full.as_int;
-
-                cpi->find_fractional_mv_step(x, b, d, &d->bmi.mv, &best_ref_mv,
-                                             x->errorperbit,
-                                             &cpi->fn_ptr[BLOCK_16X16],
-                                             cpi->mb.mvcost,
-                                             &distortion2,&sse);
-            }else
-#endif
-            {
-                /* Get intersection of UMV window and valid MV window to
-                 * reduce # of checks in diamond search. */
-                if (x->mv_col_min < col_min )
-                    x->mv_col_min = col_min;
-                if (x->mv_col_max > col_max )
-                    x->mv_col_max = col_max;
-                if (x->mv_row_min < row_min )
-                    x->mv_row_min = row_min;
-                if (x->mv_row_max > row_max )
-                    x->mv_row_max = row_max;
-
-                further_steps = (cpi->Speed >= 8)?
-                           0: (cpi->sf.max_step_search_steps - 1 - step_param);
-
-                if (cpi->sf.search_method == HEX)
-                {
-#if CONFIG_MULTI_RES_ENCODING
-                /* TODO: In higher-res pick_inter_mode, step_param is used to
-                 * modify hex search range. Here, set step_param to 0 not to
-                 * change the behavior in lowest-resolution encoder.
-                 * Will improve it later.
-                 */
-                /* Set step_param to 0 to ensure large-range motion search
-                 * when mv reuse if not valid (i.e. |parent_ref_valid| = 0),
-                 * or if this candidate reference frame (|this_ref_frame|) is
-                 * not equal to |parent_ref_frame|.
-                 */
-                if (!parent_ref_valid || (parent_ref_frame != this_ref_frame))
-                    step_param = 0;
-#endif
-                    bestsme = vp8_hex_search(x, b, d, &mvp_full, &d->bmi.mv,
-                                          step_param, sadpb,
-                                          &cpi->fn_ptr[BLOCK_16X16],
-                                          x->mvsadcost, x->mvcost, &best_ref_mv);
-                    mode_mv[NEWMV].as_int = d->bmi.mv.as_int;
-                }
-                else
-                {
-                    bestsme = cpi->diamond_search_sad(x, b, d, &mvp_full,
-                                          &d->bmi.mv, step_param, sadpb, &num00,
-                                          &cpi->fn_ptr[BLOCK_16X16],
-                                          x->mvcost, &best_ref_mv);
-                    mode_mv[NEWMV].as_int = d->bmi.mv.as_int;
-
-                    /* Further step/diamond searches as necessary */
-                    n = num00;
-                    num00 = 0;
-
-                    while (n < further_steps)
-                    {
-                        n++;
-
-                        if (num00)
-                            num00--;
-                        else
-                        {
-                            thissme =
-                            cpi->diamond_search_sad(x, b, d, &mvp_full,
-                                                    &d->bmi.mv,
-                                                    step_param + n,
-                                                    sadpb, &num00,
-                                                    &cpi->fn_ptr[BLOCK_16X16],
-                                                    x->mvcost, &best_ref_mv);
-                            if (thissme < bestsme)
-                            {
-                                bestsme = thissme;
-                                mode_mv[NEWMV].as_int = d->bmi.mv.as_int;
-                            }
-                            else
-                            {
-                                d->bmi.mv.as_int = mode_mv[NEWMV].as_int;
-                            }
-                        }
-                    }
-                }
-
-                x->mv_col_min = tmp_col_min;
-                x->mv_col_max = tmp_col_max;
-                x->mv_row_min = tmp_row_min;
-                x->mv_row_max = tmp_row_max;
-
-                if (bestsme < INT_MAX)
-                    cpi->find_fractional_mv_step(x, b, d, &d->bmi.mv,
-                                             &best_ref_mv, x->errorperbit,
-                                             &cpi->fn_ptr[BLOCK_16X16],
-                                             cpi->mb.mvcost,
-                                             &distortion2,&sse);
-            }
-
-            mode_mv[NEWMV].as_int = d->bmi.mv.as_int;
-            // The clamp below is not necessary from the perspective
-            // of VP8 bitstream, but is added to improve ChromeCast
-            // mirroring's robustness. Please do not remove.
-            vp8_clamp_mv2(&mode_mv[this_mode], xd);
-            /* mv cost; */
-            rate2 += vp8_mv_bit_cost(&mode_mv[NEWMV], &best_ref_mv,
-                                     cpi->mb.mvcost, 128);
-        }
-
-        case NEARESTMV:
-        case NEARMV:
-            if (mode_mv[this_mode].as_int == 0)
-                continue;
-
-        case ZEROMV:
-
-            /* Trap vectors that reach beyond the UMV borders
-             * Note that ALL New MV, Nearest MV Near MV and Zero MV code drops
-             * through to this point because of the lack of break statements
-             * in the previous two cases.
-             */
-            if (((mode_mv[this_mode].as_mv.row >> 3) < x->mv_row_min) ||
-                ((mode_mv[this_mode].as_mv.row >> 3) > x->mv_row_max) ||
-                ((mode_mv[this_mode].as_mv.col >> 3) < x->mv_col_min) ||
-                ((mode_mv[this_mode].as_mv.col >> 3) > x->mv_col_max))
-                continue;
-
-            rate2 += vp8_cost_mv_ref(this_mode, mdcounts);
-            x->e_mbd.mode_info_context->mbmi.mv.as_int =
-                                                    mode_mv[this_mode].as_int;
-            this_rd = evaluate_inter_mode(&sse, rate2, &distortion2, cpi, x,
-                                          rd_adjustment);
-
-            break;
-        default:
-            break;
-        }
-
-#if CONFIG_TEMPORAL_DENOISING
-        if (cpi->oxcf.noise_sensitivity)
-        {
-            /* Store for later use by denoiser. */
-            // Dont' denoise with GOLDEN OR ALTREF is they are old reference
-            // frames (greater than MAX_GF_ARF_DENOISE_RANGE frames in past).
-            int skip_old_reference = ((this_ref_frame != LAST_FRAME) &&
-                (cpi->common.current_video_frame -
-                 cpi->current_ref_frames[this_ref_frame] >
-                 MAX_GF_ARF_DENOISE_RANGE)) ? 1 : 0;
-            if (this_mode == ZEROMV && sse < zero_mv_sse &&
-                !skip_old_reference)
-            {
-                zero_mv_sse = sse;
-                x->best_zeromv_reference_frame =
-                        x->e_mbd.mode_info_context->mbmi.ref_frame;
-            }
-
-            // Store the best NEWMV in x for later use in the denoiser.
-            if (x->e_mbd.mode_info_context->mbmi.mode == NEWMV &&
-                sse < best_sse && !skip_old_reference)
-            {
-                best_sse = sse;
-                x->best_sse_inter_mode = NEWMV;
-                x->best_sse_mv = x->e_mbd.mode_info_context->mbmi.mv;
-                x->need_to_clamp_best_mvs =
-                    x->e_mbd.mode_info_context->mbmi.need_to_clamp_mvs;
-                x->best_reference_frame =
-                    x->e_mbd.mode_info_context->mbmi.ref_frame;
-            }
-        }
-#endif
-
-        if (this_rd < best_rd || x->skip)
-        {
-            /* Note index of best mode */
-            best_mode_index = mode_index;
-
-            *returnrate = rate2;
-            *returndistortion = distortion2;
-            best_rd_sse = sse;
-            best_rd = this_rd;
-            memcpy(&best_mbmode, &x->e_mbd.mode_info_context->mbmi,
-                   sizeof(MB_MODE_INFO));
-
-            /* Testing this mode gave rise to an improvement in best error
-             * score. Lower threshold a bit for next time
-             */
-            x->rd_thresh_mult[mode_index] =
-                     (x->rd_thresh_mult[mode_index] >= (MIN_THRESHMULT + 2)) ?
-                     x->rd_thresh_mult[mode_index] - 2 : MIN_THRESHMULT;
-            x->rd_threshes[mode_index] =
-                                   (cpi->rd_baseline_thresh[mode_index] >> 7) *
-                                   x->rd_thresh_mult[mode_index];
-        }
-
-        /* If the mode did not help improve the best error case then raise the
-         * threshold for testing that mode next time around.
-         */
-        else
-        {
-            x->rd_thresh_mult[mode_index] += 4;
-
-            if (x->rd_thresh_mult[mode_index] > MAX_THRESHMULT)
-                x->rd_thresh_mult[mode_index] = MAX_THRESHMULT;
-
-            x->rd_threshes[mode_index] =
-                         (cpi->rd_baseline_thresh[mode_index] >> 7) *
-                         x->rd_thresh_mult[mode_index];
-        }
-
-        if (x->skip)
-            break;
-    }
-
-    /* Reduce the activation RD thresholds for the best choice mode */
-    if ((cpi->rd_baseline_thresh[best_mode_index] > 0) && (cpi->rd_baseline_thresh[best_mode_index] < (INT_MAX >> 2)))
-    {
-        int best_adjustment = (x->rd_thresh_mult[best_mode_index] >> 3);
-
-        x->rd_thresh_mult[best_mode_index] =
-                        (x->rd_thresh_mult[best_mode_index]
-                        >= (MIN_THRESHMULT + best_adjustment)) ?
-                        x->rd_thresh_mult[best_mode_index] - best_adjustment :
-                        MIN_THRESHMULT;
-        x->rd_threshes[best_mode_index] =
-                        (cpi->rd_baseline_thresh[best_mode_index] >> 7) *
-                        x->rd_thresh_mult[best_mode_index];
-    }
-
-
-    {
-        int this_rdbin = (*returndistortion >> 7);
-
-        if (this_rdbin >= 1024)
-        {
-            this_rdbin = 1023;
-        }
-
-        x->error_bins[this_rdbin] ++;
-    }
-
-#if CONFIG_TEMPORAL_DENOISING
-    if (cpi->oxcf.noise_sensitivity)
-    {
-        int block_index = mb_row * cpi->common.mb_cols + mb_col;
-        int reevaluate = 0;
-        int is_noisy = 0;
-        if (x->best_sse_inter_mode == DC_PRED)
-        {
-            /* No best MV found. */
-            x->best_sse_inter_mode = best_mbmode.mode;
-            x->best_sse_mv = best_mbmode.mv;
-            x->need_to_clamp_best_mvs = best_mbmode.need_to_clamp_mvs;
-            x->best_reference_frame = best_mbmode.ref_frame;
-            best_sse = best_rd_sse;
-        }
-        // For non-skin blocks that have selected ZEROMV for this current frame,
-        // and have been selecting ZEROMV_LAST (on the base layer frame) at
-        // least |x~20| consecutive past frames in a row, label the block for
-        // possible increase in denoising strength. We also condition this
-        // labeling on there being significant denoising in the scene
-        if  (cpi->oxcf.noise_sensitivity == 4) {
-          if (cpi->denoiser.nmse_source_diff >
-              70 * cpi->denoiser.threshold_aggressive_mode / 100)
-            is_noisy = 1;
-        } else {
-          if (cpi->mse_source_denoised > 1000)
-            is_noisy = 1;
-        }
-        x->increase_denoising = 0;
-        if (!x->is_skin &&
-            x->best_sse_inter_mode == ZEROMV &&
-            (x->best_reference_frame == LAST_FRAME ||
-            x->best_reference_frame == cpi->closest_reference_frame) &&
-            cpi->consec_zero_last[block_index] >= 20 &&
-            is_noisy) {
-            x->increase_denoising = 1;
-        }
-        x->denoise_zeromv = 0;
-        vp8_denoiser_denoise_mb(&cpi->denoiser, x, best_sse, zero_mv_sse,
-                                recon_yoffset, recon_uvoffset,
-                                &cpi->common.lf_info, mb_row, mb_col,
-                                block_index,
-                                cpi->consec_zero_last_mvbias[block_index]);
-
-        // Reevaluate ZEROMV after denoising: for large noise content
-        // (i.e., cpi->mse_source_denoised is above threshold), do this for all
-        // blocks that did not pick ZEROMV as best mode but are using ZEROMV
-        // for denoising. Otherwise, always re-evaluate for blocks that picked
-        // INTRA mode as best mode.
-        // Avoid blocks that have been biased against ZERO_LAST
-        // (i.e., dot artifact candidate blocks).
-        reevaluate = (best_mbmode.ref_frame == INTRA_FRAME) ||
-                     (best_mbmode.mode != ZEROMV &&
-                      x->denoise_zeromv &&
-                      cpi->mse_source_denoised > 2000);
-        if (!dot_artifact_candidate &&
-            reevaluate &&
-            x->best_zeromv_reference_frame != INTRA_FRAME)
-        {
-            int this_rd = 0;
-            int this_ref_frame = x->best_zeromv_reference_frame;
-            rd_adjustment = 100;
-            rate2 = x->ref_frame_cost[this_ref_frame] +
-                    vp8_cost_mv_ref(ZEROMV, mdcounts);
-            distortion2 = 0;
-
-            /* set up the proper prediction buffers for the frame */
-            x->e_mbd.mode_info_context->mbmi.ref_frame = this_ref_frame;
-            x->e_mbd.pre.y_buffer = plane[this_ref_frame][0];
-            x->e_mbd.pre.u_buffer = plane[this_ref_frame][1];
-            x->e_mbd.pre.v_buffer = plane[this_ref_frame][2];
-
-            x->e_mbd.mode_info_context->mbmi.mode = ZEROMV;
-            x->e_mbd.mode_info_context->mbmi.uv_mode = DC_PRED;
-            x->e_mbd.mode_info_context->mbmi.mv.as_int = 0;
-            this_rd = evaluate_inter_mode(&sse, rate2, &distortion2, cpi, x,
-                                          rd_adjustment);
-
-            if (this_rd < best_rd)
-            {
-                memcpy(&best_mbmode, &x->e_mbd.mode_info_context->mbmi,
-                       sizeof(MB_MODE_INFO));
-            }
-        }
-
-    }
-#endif
-
-    if (cpi->is_src_frame_alt_ref &&
-        (best_mbmode.mode != ZEROMV || best_mbmode.ref_frame != ALTREF_FRAME))
-    {
-        x->e_mbd.mode_info_context->mbmi.mode = ZEROMV;
-        x->e_mbd.mode_info_context->mbmi.ref_frame = ALTREF_FRAME;
-        x->e_mbd.mode_info_context->mbmi.mv.as_int = 0;
-        x->e_mbd.mode_info_context->mbmi.uv_mode = DC_PRED;
-        x->e_mbd.mode_info_context->mbmi.mb_skip_coeff =
-                                        (cpi->common.mb_no_coeff_skip);
-        x->e_mbd.mode_info_context->mbmi.partitioning = 0;
-
-        return;
-    }
-
-    /* set to the best mb mode, this copy can be skip if x->skip since it
-     * already has the right content */
-    if (!x->skip)
-        memcpy(&x->e_mbd.mode_info_context->mbmi, &best_mbmode,
-               sizeof(MB_MODE_INFO));
-
-    if (best_mbmode.mode <= B_PRED)
-    {
-        /* set mode_info_context->mbmi.uv_mode */
-        pick_intra_mbuv_mode(x);
-    }
-
-    if (sign_bias
-      != cpi->common.ref_frame_sign_bias[xd->mode_info_context->mbmi.ref_frame])
-        best_ref_mv.as_int = best_ref_mv_sb[!sign_bias].as_int;
-
-    update_mvcount(x, &best_ref_mv);
-}
-
-void vp8_pick_intra_mode(MACROBLOCK *x, int *rate_)
-{
-    int error4x4, error16x16 = INT_MAX;
-    int rate, best_rate = 0, distortion, best_sse;
-    MB_PREDICTION_MODE mode, best_mode = DC_PRED;
-    int this_rd;
-    unsigned int sse;
-    BLOCK *b = &x->block[0];
-    MACROBLOCKD *xd = &x->e_mbd;
-
-    xd->mode_info_context->mbmi.ref_frame = INTRA_FRAME;
-
-    pick_intra_mbuv_mode(x);
-
-    for (mode = DC_PRED; mode <= TM_PRED; mode ++)
-    {
-        xd->mode_info_context->mbmi.mode = mode;
-        vp8_build_intra_predictors_mby_s(xd,
-                                         xd->dst.y_buffer - xd->dst.y_stride,
-                                         xd->dst.y_buffer - 1,
-                                         xd->dst.y_stride,
-                                         xd->predictor,
-                                         16);
-        distortion = vpx_variance16x16
-            (*(b->base_src), b->src_stride, xd->predictor, 16, &sse);
-        rate = x->mbmode_cost[xd->frame_type][mode];
-        this_rd = RDCOST(x->rdmult, x->rddiv, rate, distortion);
-
-        if (error16x16 > this_rd)
-        {
-            error16x16 = this_rd;
-            best_mode = mode;
-            best_sse = sse;
-            best_rate = rate;
-        }
-    }
-    xd->mode_info_context->mbmi.mode = best_mode;
-
-    error4x4 = pick_intra4x4mby_modes(x, &rate,
-                                      &best_sse);
-    if (error4x4 < error16x16)
-    {
-        xd->mode_info_context->mbmi.mode = B_PRED;
-        best_rate = rate;
-    }
-
-    *rate_ = best_rate;
-}
diff --git a/vp8/encoder/pickinter.h b/vp8/encoder/pickinter.h
deleted file mode 100644 (file)
index cf3b1f8..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#ifndef VP8_ENCODER_PICKINTER_H_
-#define VP8_ENCODER_PICKINTER_H_
-#include "vpx_config.h"
-#include "vp8/common/onyxc_int.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-extern void vp8_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset,
-                                int recon_uvoffset, int *returnrate,
-                                int *returndistortion, int *returnintra,
-                                int mb_row, int mb_col);
-extern void vp8_pick_intra_mode(MACROBLOCK *x, int *rate);
-
-extern int vp8_get_inter_mbpred_error(MACROBLOCK *mb,
-                                      const vp8_variance_fn_ptr_t *vfp,
-                                      unsigned int *sse,
-                                      int_mv this_mv);
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP8_ENCODER_PICKINTER_H_
diff --git a/vp8/encoder/picklpf.c b/vp8/encoder/picklpf.c
deleted file mode 100644 (file)
index debd304..0000000
+++ /dev/null
@@ -1,407 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#include "./vpx_dsp_rtcd.h"
-#include "./vpx_scale_rtcd.h"
-#include "vp8/common/onyxc_int.h"
-#include "onyx_int.h"
-#include "vp8/encoder/quantize.h"
-#include "vpx_mem/vpx_mem.h"
-#include "vpx_scale/vpx_scale.h"
-#include "vp8/common/alloccommon.h"
-#include "vp8/common/loopfilter.h"
-#if ARCH_ARM
-#include "vpx_ports/arm.h"
-#endif
-
-extern int vp8_calc_ss_err(YV12_BUFFER_CONFIG *source, YV12_BUFFER_CONFIG *dest);
-
-static void yv12_copy_partial_frame(YV12_BUFFER_CONFIG *src_ybc,
-                                    YV12_BUFFER_CONFIG *dst_ybc)
-{
-    unsigned char *src_y, *dst_y;
-    int yheight;
-    int ystride;
-    int yoffset;
-    int linestocopy;
-
-    yheight  = src_ybc->y_height;
-    ystride  = src_ybc->y_stride;
-
-    /* number of MB rows to use in partial filtering */
-    linestocopy = (yheight >> 4) / PARTIAL_FRAME_FRACTION;
-    linestocopy = linestocopy ? linestocopy << 4 : 16;     /* 16 lines per MB */
-
-    /* Copy extra 4 so that full filter context is available if filtering done
-     * on the copied partial frame and not original. Partial filter does mb
-     * filtering for top row also, which can modify3 pixels above.
-     */
-    linestocopy += 4;
-    /* partial image starts at ~middle of frame (macroblock border)*/
-    yoffset  = ystride * (((yheight >> 5) * 16) - 4);
-    src_y = src_ybc->y_buffer + yoffset;
-    dst_y = dst_ybc->y_buffer + yoffset;
-
-    memcpy(dst_y, src_y, ystride * linestocopy);
-}
-
-static int calc_partial_ssl_err(YV12_BUFFER_CONFIG *source,
-                                YV12_BUFFER_CONFIG *dest)
-{
-    int i, j;
-    int Total = 0;
-    int srcoffset, dstoffset;
-    unsigned char *src = source->y_buffer;
-    unsigned char *dst = dest->y_buffer;
-
-    int linestocopy;
-
-    /* number of MB rows to use in partial filtering */
-    linestocopy = (source->y_height >> 4) / PARTIAL_FRAME_FRACTION;
-    linestocopy = linestocopy ? linestocopy << 4 : 16;     /* 16 lines per MB */
-
-
-    /* partial image starts at ~middle of frame (macroblock border)*/
-    srcoffset = source->y_stride * ((dest->y_height >> 5) * 16);
-    dstoffset = dest->y_stride   * ((dest->y_height >> 5) * 16);
-
-    src += srcoffset;
-    dst += dstoffset;
-
-    /* Loop through the Y plane raw and reconstruction data summing
-     * (square differences)
-     */
-    for (i = 0; i < linestocopy; i += 16)
-    {
-        for (j = 0; j < source->y_width; j += 16)
-        {
-            unsigned int sse;
-            Total += vpx_mse16x16(src + j, source->y_stride,
-                                                     dst + j, dest->y_stride,
-                                                     &sse);
-        }
-
-        src += 16 * source->y_stride;
-        dst += 16 * dest->y_stride;
-    }
-
-    return Total;
-}
-
-/* Enforce a minimum filter level based upon baseline Q */
-static int get_min_filter_level(VP8_COMP *cpi, int base_qindex)
-{
-    int min_filter_level;
-
-    if (cpi->source_alt_ref_active && cpi->common.refresh_golden_frame &&
-        !cpi->common.refresh_alt_ref_frame)
-        min_filter_level = 0;
-    else
-    {
-        if (base_qindex <= 6)
-            min_filter_level = 0;
-        else if (base_qindex <= 16)
-            min_filter_level = 1;
-        else
-            min_filter_level = (base_qindex / 8);
-    }
-
-    return min_filter_level;
-}
-
-/* Enforce a maximum filter level based upon baseline Q */
-static int get_max_filter_level(VP8_COMP *cpi, int base_qindex)
-{
-    /* PGW August 2006: Highest filter values almost always a bad idea */
-
-    /* jbb chg: 20100118 - not so any more with this overquant stuff allow
-     * high values with lots of intra coming in.
-     */
-    int max_filter_level = MAX_LOOP_FILTER;
-    (void)base_qindex;
-
-    if (cpi->twopass.section_intra_rating > 8)
-        max_filter_level = MAX_LOOP_FILTER * 3 / 4;
-
-    return max_filter_level;
-}
-
-void vp8cx_pick_filter_level_fast(YV12_BUFFER_CONFIG *sd, VP8_COMP *cpi)
-{
-    VP8_COMMON *cm = &cpi->common;
-
-    int best_err = 0;
-    int filt_err = 0;
-    int min_filter_level = get_min_filter_level(cpi, cm->base_qindex);
-    int max_filter_level = get_max_filter_level(cpi, cm->base_qindex);
-    int filt_val;
-    int best_filt_val;
-    YV12_BUFFER_CONFIG * saved_frame = cm->frame_to_show;
-
-    /* Replace unfiltered frame buffer with a new one */
-    cm->frame_to_show = &cpi->pick_lf_lvl_frame;
-
-    if (cm->frame_type == KEY_FRAME)
-        cm->sharpness_level = 0;
-    else
-        cm->sharpness_level = cpi->oxcf.Sharpness;
-
-    if (cm->sharpness_level != cm->last_sharpness_level)
-    {
-        vp8_loop_filter_update_sharpness(&cm->lf_info, cm->sharpness_level);
-        cm->last_sharpness_level = cm->sharpness_level;
-    }
-
-    /* Start the search at the previous frame filter level unless it is
-     * now out of range.
-     */
-    if (cm->filter_level < min_filter_level)
-        cm->filter_level = min_filter_level;
-    else if (cm->filter_level > max_filter_level)
-        cm->filter_level = max_filter_level;
-
-    filt_val = cm->filter_level;
-    best_filt_val = filt_val;
-
-    /* Get the err using the previous frame's filter value. */
-
-    /* Copy the unfiltered / processed recon buffer to the new buffer */
-    yv12_copy_partial_frame(saved_frame, cm->frame_to_show);
-    vp8_loop_filter_partial_frame(cm, &cpi->mb.e_mbd, filt_val);
-
-    best_err = calc_partial_ssl_err(sd, cm->frame_to_show);
-
-    filt_val -= 1 + (filt_val > 10);
-
-    /* Search lower filter levels */
-    while (filt_val >= min_filter_level)
-    {
-        /* Apply the loop filter */
-        yv12_copy_partial_frame(saved_frame, cm->frame_to_show);
-        vp8_loop_filter_partial_frame(cm, &cpi->mb.e_mbd, filt_val);
-
-        /* Get the err for filtered frame */
-        filt_err = calc_partial_ssl_err(sd, cm->frame_to_show);
-
-        /* Update the best case record or exit loop. */
-        if (filt_err < best_err)
-        {
-            best_err = filt_err;
-            best_filt_val = filt_val;
-        }
-        else
-            break;
-
-        /* Adjust filter level */
-        filt_val -= 1 + (filt_val > 10);
-    }
-
-    /* Search up (note that we have already done filt_val = cm->filter_level) */
-    filt_val = cm->filter_level + 1 + (filt_val > 10);
-
-    if (best_filt_val == cm->filter_level)
-    {
-        /* Resist raising filter level for very small gains */
-        best_err -= (best_err >> 10);
-
-        while (filt_val < max_filter_level)
-        {
-            /* Apply the loop filter */
-            yv12_copy_partial_frame(saved_frame, cm->frame_to_show);
-
-            vp8_loop_filter_partial_frame(cm, &cpi->mb.e_mbd, filt_val);
-
-            /* Get the err for filtered frame */
-            filt_err = calc_partial_ssl_err(sd, cm->frame_to_show);
-
-            /* Update the best case record or exit loop. */
-            if (filt_err < best_err)
-            {
-                /* Do not raise filter level if improvement is < 1 part
-                 * in 4096
-                 */
-                best_err = filt_err - (filt_err >> 10);
-
-                best_filt_val = filt_val;
-            }
-            else
-                break;
-
-            /* Adjust filter level */
-            filt_val += 1 + (filt_val > 10);
-        }
-    }
-
-    cm->filter_level = best_filt_val;
-
-    if (cm->filter_level < min_filter_level)
-        cm->filter_level = min_filter_level;
-
-    if (cm->filter_level > max_filter_level)
-        cm->filter_level = max_filter_level;
-
-    /* restore unfiltered frame pointer */
-    cm->frame_to_show = saved_frame;
-}
-
-/* Stub function for now Alt LF not used */
-void vp8cx_set_alt_lf_level(VP8_COMP *cpi, int filt_val)
-{
-    MACROBLOCKD *mbd = &cpi->mb.e_mbd;
-    (void) filt_val;
-
-    mbd->segment_feature_data[MB_LVL_ALT_LF][0] = cpi->segment_feature_data[MB_LVL_ALT_LF][0];
-    mbd->segment_feature_data[MB_LVL_ALT_LF][1] = cpi->segment_feature_data[MB_LVL_ALT_LF][1];
-    mbd->segment_feature_data[MB_LVL_ALT_LF][2] = cpi->segment_feature_data[MB_LVL_ALT_LF][2];
-    mbd->segment_feature_data[MB_LVL_ALT_LF][3] = cpi->segment_feature_data[MB_LVL_ALT_LF][3];
-}
-
-void vp8cx_pick_filter_level(YV12_BUFFER_CONFIG *sd, VP8_COMP *cpi)
-{
-    VP8_COMMON *cm = &cpi->common;
-
-    int best_err = 0;
-    int filt_err = 0;
-    int min_filter_level = get_min_filter_level(cpi, cm->base_qindex);
-    int max_filter_level = get_max_filter_level(cpi, cm->base_qindex);
-
-    int filter_step;
-    int filt_high = 0;
-    int filt_mid;
-    int filt_low = 0;
-    int filt_best;
-    int filt_direction = 0;
-
-    /* Bias against raising loop filter and in favor of lowering it */
-    int Bias = 0;
-
-    int ss_err[MAX_LOOP_FILTER + 1];
-
-    YV12_BUFFER_CONFIG * saved_frame = cm->frame_to_show;
-
-    memset(ss_err, 0, sizeof(ss_err));
-
-    /* Replace unfiltered frame buffer with a new one */
-    cm->frame_to_show = &cpi->pick_lf_lvl_frame;
-
-    if (cm->frame_type == KEY_FRAME)
-        cm->sharpness_level = 0;
-    else
-        cm->sharpness_level = cpi->oxcf.Sharpness;
-
-    /* Start the search at the previous frame filter level unless it is
-     * now out of range.
-     */
-    filt_mid = cm->filter_level;
-
-    if (filt_mid < min_filter_level)
-        filt_mid = min_filter_level;
-    else if (filt_mid > max_filter_level)
-        filt_mid = max_filter_level;
-
-    /* Define the initial step size */
-    filter_step = (filt_mid < 16) ? 4 : filt_mid / 4;
-
-    /* Get baseline error score */
-
-    /* Copy the unfiltered / processed recon buffer to the new buffer */
-    vpx_yv12_copy_y(saved_frame, cm->frame_to_show);
-
-    vp8cx_set_alt_lf_level(cpi, filt_mid);
-    vp8_loop_filter_frame_yonly(cm, &cpi->mb.e_mbd, filt_mid);
-
-    best_err = vp8_calc_ss_err(sd, cm->frame_to_show);
-
-    ss_err[filt_mid] = best_err;
-
-    filt_best = filt_mid;
-
-    while (filter_step > 0)
-    {
-        Bias = (best_err >> (15 - (filt_mid / 8))) * filter_step;
-
-        if (cpi->twopass.section_intra_rating < 20)
-            Bias = Bias * cpi->twopass.section_intra_rating / 20;
-
-        filt_high = ((filt_mid + filter_step) > max_filter_level) ? max_filter_level : (filt_mid + filter_step);
-        filt_low = ((filt_mid - filter_step) < min_filter_level) ? min_filter_level : (filt_mid - filter_step);
-
-        if ((filt_direction <= 0) && (filt_low != filt_mid))
-        {
-            if(ss_err[filt_low] == 0)
-            {
-                /* Get Low filter error score */
-                vpx_yv12_copy_y(saved_frame, cm->frame_to_show);
-                vp8cx_set_alt_lf_level(cpi, filt_low);
-                vp8_loop_filter_frame_yonly(cm, &cpi->mb.e_mbd, filt_low);
-
-                filt_err = vp8_calc_ss_err(sd, cm->frame_to_show);
-                ss_err[filt_low] = filt_err;
-            }
-            else
-                filt_err = ss_err[filt_low];
-
-            /* If value is close to the best so far then bias towards a
-             * lower loop filter value.
-             */
-            if ((filt_err - Bias) < best_err)
-            {
-                /* Was it actually better than the previous best? */
-                if (filt_err < best_err)
-                    best_err = filt_err;
-
-                filt_best = filt_low;
-            }
-        }
-
-        /* Now look at filt_high */
-        if ((filt_direction >= 0) && (filt_high != filt_mid))
-        {
-            if(ss_err[filt_high] == 0)
-            {
-                vpx_yv12_copy_y(saved_frame, cm->frame_to_show);
-                vp8cx_set_alt_lf_level(cpi, filt_high);
-                vp8_loop_filter_frame_yonly(cm, &cpi->mb.e_mbd, filt_high);
-
-                filt_err = vp8_calc_ss_err(sd, cm->frame_to_show);
-                ss_err[filt_high] = filt_err;
-            }
-            else
-                filt_err = ss_err[filt_high];
-
-            /* Was it better than the previous best? */
-            if (filt_err < (best_err - Bias))
-            {
-                best_err = filt_err;
-                filt_best = filt_high;
-            }
-        }
-
-        /* Half the step distance if the best filter value was the same
-         * as last time
-         */
-        if (filt_best == filt_mid)
-        {
-            filter_step = filter_step / 2;
-            filt_direction = 0;
-        }
-        else
-        {
-            filt_direction = (filt_best < filt_mid) ? -1 : 1;
-            filt_mid = filt_best;
-        }
-    }
-
-    cm->filter_level = filt_best;
-
-    /* restore unfiltered frame pointer */
-    cm->frame_to_show = saved_frame;
-}
diff --git a/vp8/encoder/quantize.h b/vp8/encoder/quantize.h
deleted file mode 100644 (file)
index 7d36c2b..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#ifndef VP8_ENCODER_QUANTIZE_H_
-#define VP8_ENCODER_QUANTIZE_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-struct VP8_COMP;
-struct macroblock;
-extern void vp8_quantize_mb(struct macroblock *x);
-extern void vp8_quantize_mby(struct macroblock *x);
-extern void vp8_quantize_mbuv(struct macroblock *x);
-extern void vp8_set_quantizer(struct VP8_COMP *cpi, int Q);
-extern void vp8cx_frame_init_quantizer(struct VP8_COMP *cpi);
-extern void vp8_update_zbin_extra(struct VP8_COMP *cpi, struct macroblock *x);
-extern void vp8cx_mb_init_quantizer(struct VP8_COMP *cpi, struct macroblock *x, int ok_to_skip);
-extern void vp8cx_init_quantizer(struct VP8_COMP *cpi);
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP8_ENCODER_QUANTIZE_H_
diff --git a/vp8/encoder/ratectrl.c b/vp8/encoder/ratectrl.c
deleted file mode 100644 (file)
index 7da3d71..0000000
+++ /dev/null
@@ -1,1638 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <limits.h>
-#include <assert.h>
-
-#include "math.h"
-#include "vp8/common/common.h"
-#include "ratectrl.h"
-#include "vp8/common/entropymode.h"
-#include "vpx_mem/vpx_mem.h"
-#include "vp8/common/systemdependent.h"
-#include "encodemv.h"
-#include "vpx_dsp/vpx_dsp_common.h"
-
-
-#define MIN_BPB_FACTOR          0.01
-#define MAX_BPB_FACTOR          50
-
-extern const MB_PREDICTION_MODE vp8_mode_order[MAX_MODES];
-
-
-
-#ifdef MODE_STATS
-extern int y_modes[5];
-extern int uv_modes[4];
-extern int b_modes[10];
-
-extern int inter_y_modes[10];
-extern int inter_uv_modes[4];
-extern int inter_b_modes[10];
-#endif
-
-/* Bits Per MB at different Q (Multiplied by 512) */
-#define BPER_MB_NORMBITS    9
-
-/* Work in progress recalibration of baseline rate tables based on
- * the assumption that bits per mb is inversely proportional to the
- * quantizer value.
- */
-const int vp8_bits_per_mb[2][QINDEX_RANGE] =
-{
-    /* Intra case 450000/Qintra */
-    {
-        1125000,900000, 750000, 642857, 562500, 500000, 450000, 450000,
-        409090, 375000, 346153, 321428, 300000, 281250, 264705, 264705,
-        250000, 236842, 225000, 225000, 214285, 214285, 204545, 204545,
-        195652, 195652, 187500, 180000, 180000, 173076, 166666, 160714,
-        155172, 150000, 145161, 140625, 136363, 132352, 128571, 125000,
-        121621, 121621, 118421, 115384, 112500, 109756, 107142, 104651,
-        102272, 100000, 97826,  97826,  95744,  93750,  91836,  90000,
-        88235,  86538,  84905,  83333,  81818,  80357,  78947,  77586,
-        76271,  75000,  73770,  72580,  71428,  70312,  69230,  68181,
-        67164,  66176,  65217,  64285,  63380,  62500,  61643,  60810,
-        60000,  59210,  59210,  58441,  57692,  56962,  56250,  55555,
-        54878,  54216,  53571,  52941,  52325,  51724,  51136,  50561,
-        49450,  48387,  47368,  46875,  45918,  45000,  44554,  44117,
-        43269,  42452,  41666,  40909,  40178,  39473,  38793,  38135,
-        36885,  36290,  35714,  35156,  34615,  34090,  33582,  33088,
-        32608,  32142,  31468,  31034,  30405,  29801,  29220,  28662,
-    },
-    /* Inter case 285000/Qinter */
-    {
-        712500, 570000, 475000, 407142, 356250, 316666, 285000, 259090,
-        237500, 219230, 203571, 190000, 178125, 167647, 158333, 150000,
-        142500, 135714, 129545, 123913, 118750, 114000, 109615, 105555,
-        101785, 98275,  95000,  91935,  89062,  86363,  83823,  81428,
-        79166,  77027,  75000,  73076,  71250,  69512,  67857,  66279,
-        64772,  63333,  61956,  60638,  59375,  58163,  57000,  55882,
-        54807,  53773,  52777,  51818,  50892,  50000,  49137,  47500,
-        45967,  44531,  43181,  41911,  40714,  39583,  38513,  37500,
-        36538,  35625,  34756,  33928,  33139,  32386,  31666,  30978,
-        30319,  29687,  29081,  28500,  27941,  27403,  26886,  26388,
-        25909,  25446,  25000,  24568,  23949,  23360,  22800,  22265,
-        21755,  21268,  20802,  20357,  19930,  19520,  19127,  18750,
-        18387,  18037,  17701,  17378,  17065,  16764,  16473,  16101,
-        15745,  15405,  15079,  14766,  14467,  14179,  13902,  13636,
-        13380,  13133,  12895,  12666,  12445,  12179,  11924,  11632,
-        11445,  11220,  11003,  10795,  10594,  10401,  10215,  10035,
-    }
-};
-
-static const int kf_boost_qadjustment[QINDEX_RANGE] =
-{
-    128, 129, 130, 131, 132, 133, 134, 135,
-    136, 137, 138, 139, 140, 141, 142, 143,
-    144, 145, 146, 147, 148, 149, 150, 151,
-    152, 153, 154, 155, 156, 157, 158, 159,
-    160, 161, 162, 163, 164, 165, 166, 167,
-    168, 169, 170, 171, 172, 173, 174, 175,
-    176, 177, 178, 179, 180, 181, 182, 183,
-    184, 185, 186, 187, 188, 189, 190, 191,
-    192, 193, 194, 195, 196, 197, 198, 199,
-    200, 200, 201, 201, 202, 203, 203, 203,
-    204, 204, 205, 205, 206, 206, 207, 207,
-    208, 208, 209, 209, 210, 210, 211, 211,
-    212, 212, 213, 213, 214, 214, 215, 215,
-    216, 216, 217, 217, 218, 218, 219, 219,
-    220, 220, 220, 220, 220, 220, 220, 220,
-    220, 220, 220, 220, 220, 220, 220, 220,
-};
-
-/* #define GFQ_ADJUSTMENT (Q+100) */
-#define GFQ_ADJUSTMENT vp8_gf_boost_qadjustment[Q]
-const int vp8_gf_boost_qadjustment[QINDEX_RANGE] =
-{
-    80, 82, 84, 86, 88, 90, 92, 94,
-    96, 97, 98, 99, 100, 101, 102, 103,
-    104, 105, 106, 107, 108, 109, 110, 111,
-    112, 113, 114, 115, 116, 117, 118, 119,
-    120, 121, 122, 123, 124, 125, 126, 127,
-    128, 129, 130, 131, 132, 133, 134, 135,
-    136, 137, 138, 139, 140, 141, 142, 143,
-    144, 145, 146, 147, 148, 149, 150, 151,
-    152, 153, 154, 155, 156, 157, 158, 159,
-    160, 161, 162, 163, 164, 165, 166, 167,
-    168, 169, 170, 171, 172, 173, 174, 175,
-    176, 177, 178, 179, 180, 181, 182, 183,
-    184, 184, 185, 185, 186, 186, 187, 187,
-    188, 188, 189, 189, 190, 190, 191, 191,
-    192, 192, 193, 193, 194, 194, 194, 194,
-    195, 195, 196, 196, 197, 197, 198, 198
-};
-
-/*
-const int vp8_gf_boost_qadjustment[QINDEX_RANGE] =
-{
-    100,101,102,103,104,105,105,106,
-    106,107,107,108,109,109,110,111,
-    112,113,114,115,116,117,118,119,
-    120,121,122,123,124,125,126,127,
-    128,129,130,131,132,133,134,135,
-    136,137,138,139,140,141,142,143,
-    144,145,146,147,148,149,150,151,
-    152,153,154,155,156,157,158,159,
-    160,161,162,163,164,165,166,167,
-    168,169,170,170,171,171,172,172,
-    173,173,173,174,174,174,175,175,
-    175,176,176,176,177,177,177,177,
-    178,178,179,179,180,180,181,181,
-    182,182,183,183,184,184,185,185,
-    186,186,187,187,188,188,189,189,
-    190,190,191,191,192,192,193,193,
-};
-*/
-
-static const int kf_gf_boost_qlimits[QINDEX_RANGE] =
-{
-    150, 155, 160, 165, 170, 175, 180, 185,
-    190, 195, 200, 205, 210, 215, 220, 225,
-    230, 235, 240, 245, 250, 255, 260, 265,
-    270, 275, 280, 285, 290, 295, 300, 305,
-    310, 320, 330, 340, 350, 360, 370, 380,
-    390, 400, 410, 420, 430, 440, 450, 460,
-    470, 480, 490, 500, 510, 520, 530, 540,
-    550, 560, 570, 580, 590, 600, 600, 600,
-    600, 600, 600, 600, 600, 600, 600, 600,
-    600, 600, 600, 600, 600, 600, 600, 600,
-    600, 600, 600, 600, 600, 600, 600, 600,
-    600, 600, 600, 600, 600, 600, 600, 600,
-    600, 600, 600, 600, 600, 600, 600, 600,
-    600, 600, 600, 600, 600, 600, 600, 600,
-    600, 600, 600, 600, 600, 600, 600, 600,
-    600, 600, 600, 600, 600, 600, 600, 600,
-};
-
-static const int gf_adjust_table[101] =
-{
-    100,
-    115, 130, 145, 160, 175, 190, 200, 210, 220, 230,
-    240, 260, 270, 280, 290, 300, 310, 320, 330, 340,
-    350, 360, 370, 380, 390, 400, 400, 400, 400, 400,
-    400, 400, 400, 400, 400, 400, 400, 400, 400, 400,
-    400, 400, 400, 400, 400, 400, 400, 400, 400, 400,
-    400, 400, 400, 400, 400, 400, 400, 400, 400, 400,
-    400, 400, 400, 400, 400, 400, 400, 400, 400, 400,
-    400, 400, 400, 400, 400, 400, 400, 400, 400, 400,
-    400, 400, 400, 400, 400, 400, 400, 400, 400, 400,
-    400, 400, 400, 400, 400, 400, 400, 400, 400, 400,
-};
-
-static const int gf_intra_usage_adjustment[20] =
-{
-    125, 120, 115, 110, 105, 100,  95,  85,  80,  75,
-    70,  65,  60,  55,  50,  50,  50,  50,  50,  50,
-};
-
-static const int gf_interval_table[101] =
-{
-    7,
-    7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
-    7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
-    7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
-    8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
-    8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
-    9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
-    9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
-    10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
-    10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
-    11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
-};
-
-static const unsigned int prior_key_frame_weight[KEY_FRAME_CONTEXT] = { 1, 2, 3, 4, 5 };
-
-
-void vp8_save_coding_context(VP8_COMP *cpi)
-{
-    CODING_CONTEXT *const cc = & cpi->coding_context;
-
-    /* Stores a snapshot of key state variables which can subsequently be
-     * restored with a call to vp8_restore_coding_context. These functions are
-     * intended for use in a re-code loop in vp8_compress_frame where the
-     * quantizer value is adjusted between loop iterations.
-     */
-
-    cc->frames_since_key          = cpi->frames_since_key;
-    cc->filter_level             = cpi->common.filter_level;
-    cc->frames_till_gf_update_due   = cpi->frames_till_gf_update_due;
-    cc->frames_since_golden       = cpi->frames_since_golden;
-
-    vp8_copy(cc->mvc,      cpi->common.fc.mvc);
-    vp8_copy(cc->mvcosts,  cpi->rd_costs.mvcosts);
-
-    vp8_copy(cc->ymode_prob,   cpi->common.fc.ymode_prob);
-    vp8_copy(cc->uv_mode_prob,  cpi->common.fc.uv_mode_prob);
-
-    vp8_copy(cc->ymode_count, cpi->mb.ymode_count);
-    vp8_copy(cc->uv_mode_count, cpi->mb.uv_mode_count);
-
-
-    /* Stats */
-#ifdef MODE_STATS
-    vp8_copy(cc->y_modes,       y_modes);
-    vp8_copy(cc->uv_modes,      uv_modes);
-    vp8_copy(cc->b_modes,       b_modes);
-    vp8_copy(cc->inter_y_modes,  inter_y_modes);
-    vp8_copy(cc->inter_uv_modes, inter_uv_modes);
-    vp8_copy(cc->inter_b_modes,  inter_b_modes);
-#endif
-
-    cc->this_frame_percent_intra = cpi->this_frame_percent_intra;
-}
-
-
-void vp8_restore_coding_context(VP8_COMP *cpi)
-{
-    CODING_CONTEXT *const cc = & cpi->coding_context;
-
-    /* Restore key state variables to the snapshot state stored in the
-     * previous call to vp8_save_coding_context.
-     */
-
-    cpi->frames_since_key         =   cc->frames_since_key;
-    cpi->common.filter_level     =   cc->filter_level;
-    cpi->frames_till_gf_update_due  =   cc->frames_till_gf_update_due;
-    cpi->frames_since_golden       =   cc->frames_since_golden;
-
-    vp8_copy(cpi->common.fc.mvc, cc->mvc);
-
-    vp8_copy(cpi->rd_costs.mvcosts, cc->mvcosts);
-
-    vp8_copy(cpi->common.fc.ymode_prob,   cc->ymode_prob);
-    vp8_copy(cpi->common.fc.uv_mode_prob,  cc->uv_mode_prob);
-
-    vp8_copy(cpi->mb.ymode_count, cc->ymode_count);
-    vp8_copy(cpi->mb.uv_mode_count, cc->uv_mode_count);
-
-    /* Stats */
-#ifdef MODE_STATS
-    vp8_copy(y_modes, cc->y_modes);
-    vp8_copy(uv_modes, cc->uv_modes);
-    vp8_copy(b_modes, cc->b_modes);
-    vp8_copy(inter_y_modes, cc->inter_y_modes);
-    vp8_copy(inter_uv_modes, cc->inter_uv_modes);
-    vp8_copy(inter_b_modes, cc->inter_b_modes);
-#endif
-
-
-    cpi->this_frame_percent_intra = cc->this_frame_percent_intra;
-}
-
-
-void vp8_setup_key_frame(VP8_COMP *cpi)
-{
-    /* Setup for Key frame: */
-
-    vp8_default_coef_probs(& cpi->common);
-
-    memcpy(cpi->common.fc.mvc, vp8_default_mv_context, sizeof(vp8_default_mv_context));
-    {
-        int flag[2] = {1, 1};
-        vp8_build_component_cost_table(cpi->mb.mvcost, (const MV_CONTEXT *) cpi->common.fc.mvc, flag);
-    }
-
-    /* Make sure we initialize separate contexts for altref,gold, and normal.
-     * TODO shouldn't need 3 different copies of structure to do this!
-     */
-    memcpy(&cpi->lfc_a, &cpi->common.fc, sizeof(cpi->common.fc));
-    memcpy(&cpi->lfc_g, &cpi->common.fc, sizeof(cpi->common.fc));
-    memcpy(&cpi->lfc_n, &cpi->common.fc, sizeof(cpi->common.fc));
-
-    cpi->common.filter_level = cpi->common.base_qindex * 3 / 8 ;
-
-    /* Provisional interval before next GF */
-    if (cpi->auto_gold)
-        cpi->frames_till_gf_update_due = cpi->baseline_gf_interval;
-    else
-        cpi->frames_till_gf_update_due = DEFAULT_GF_INTERVAL;
-
-    cpi->common.refresh_golden_frame = 1;
-    cpi->common.refresh_alt_ref_frame = 1;
-}
-
-
-static int estimate_bits_at_q(int frame_kind, int Q, int MBs,
-                              double correction_factor)
-{
-    int Bpm = (int)(.5 + correction_factor * vp8_bits_per_mb[frame_kind][Q]);
-
-    /* Attempt to retain reasonable accuracy without overflow. The cutoff is
-     * chosen such that the maximum product of Bpm and MBs fits 31 bits. The
-     * largest Bpm takes 20 bits.
-     */
-    if (MBs > (1 << 11))
-        return (Bpm >> BPER_MB_NORMBITS) * MBs;
-    else
-        return (Bpm * MBs) >> BPER_MB_NORMBITS;
-}
-
-
-static void calc_iframe_target_size(VP8_COMP *cpi)
-{
-    /* boost defaults to half second */
-    int kf_boost;
-    uint64_t target;
-
-    /* Clear down mmx registers to allow floating point in what follows */
-    vp8_clear_system_state();
-
-    if (cpi->oxcf.fixed_q >= 0)
-    {
-        int Q = cpi->oxcf.key_q;
-
-        target = estimate_bits_at_q(INTRA_FRAME, Q, cpi->common.MBs,
-                                    cpi->key_frame_rate_correction_factor);
-    }
-    else if (cpi->pass == 2)
-    {
-        /* New Two pass RC */
-        target = cpi->per_frame_bandwidth;
-    }
-    /* First Frame is a special case */
-    else if (cpi->common.current_video_frame == 0)
-    {
-        /* 1 Pass there is no information on which to base size so use
-         * bandwidth per second * fraction of the initial buffer
-         * level
-         */
-        target = cpi->oxcf.starting_buffer_level / 2;
-
-        if(target > cpi->oxcf.target_bandwidth * 3 / 2)
-            target = cpi->oxcf.target_bandwidth * 3 / 2;
-    }
-    else
-    {
-        /* if this keyframe was forced, use a more recent Q estimate */
-        int Q = (cpi->common.frame_flags & FRAMEFLAGS_KEY)
-                ? cpi->avg_frame_qindex : cpi->ni_av_qi;
-
-        int initial_boost = 32; /* |3.0 * per_frame_bandwidth| */
-        /* Boost depends somewhat on frame rate: only used for 1 layer case. */
-        if (cpi->oxcf.number_of_layers == 1) {
-          kf_boost = VPXMAX(initial_boost,
-                            (int)(2 * cpi->output_framerate - 16));
-        }
-        else {
-          /* Initial factor: set target size to: |3.0 * per_frame_bandwidth|. */
-          kf_boost = initial_boost;
-        }
-
-        /* adjustment up based on q: this factor ranges from ~1.2 to 2.2. */
-        kf_boost = kf_boost * kf_boost_qadjustment[Q] / 100;
-
-        /* frame separation adjustment ( down) */
-        if (cpi->frames_since_key  < cpi->output_framerate / 2)
-            kf_boost = (int)(kf_boost
-                       * cpi->frames_since_key / (cpi->output_framerate / 2));
-
-        /* Minimal target size is |2* per_frame_bandwidth|. */
-        if (kf_boost < 16)
-            kf_boost = 16;
-
-        target = ((16 + kf_boost) * cpi->per_frame_bandwidth) >> 4;
-    }
-
-
-    if (cpi->oxcf.rc_max_intra_bitrate_pct)
-    {
-        unsigned int max_rate = cpi->per_frame_bandwidth
-                                * cpi->oxcf.rc_max_intra_bitrate_pct / 100;
-
-        if (target > max_rate)
-            target = max_rate;
-    }
-
-    cpi->this_frame_target = (int)target;
-
-    /* TODO: if we separate rate targeting from Q targetting, move this.
-     * Reset the active worst quality to the baseline value for key frames.
-     */
-    if (cpi->pass != 2)
-        cpi->active_worst_quality = cpi->worst_quality;
-
-#if 0
-    {
-        FILE *f;
-
-        f = fopen("kf_boost.stt", "a");
-        fprintf(f, " %8u %10d %10d %10d\n",
-                cpi->common.current_video_frame,  cpi->gfu_boost, cpi->baseline_gf_interval, cpi->source_alt_ref_pending);
-
-        fclose(f);
-    }
-#endif
-}
-
-
-/* Do the best we can to define the parameters for the next GF based on what
- * information we have available.
- */
-static void calc_gf_params(VP8_COMP *cpi)
-{
-    int Q = (cpi->oxcf.fixed_q < 0) ? cpi->last_q[INTER_FRAME] : cpi->oxcf.fixed_q;
-    int Boost = 0;
-
-    int gf_frame_useage = 0;      /* Golden frame useage since last GF */
-    int tot_mbs = cpi->recent_ref_frame_usage[INTRA_FRAME]  +
-                  cpi->recent_ref_frame_usage[LAST_FRAME]   +
-                  cpi->recent_ref_frame_usage[GOLDEN_FRAME] +
-                  cpi->recent_ref_frame_usage[ALTREF_FRAME];
-
-    int pct_gf_active = (100 * cpi->gf_active_count) / (cpi->common.mb_rows * cpi->common.mb_cols);
-
-    if (tot_mbs)
-        gf_frame_useage = (cpi->recent_ref_frame_usage[GOLDEN_FRAME] + cpi->recent_ref_frame_usage[ALTREF_FRAME]) * 100 / tot_mbs;
-
-    if (pct_gf_active > gf_frame_useage)
-        gf_frame_useage = pct_gf_active;
-
-    /* Not two pass */
-    if (cpi->pass != 2)
-    {
-        /* Single Pass lagged mode: TBD */
-        if (0)
-        {
-        }
-
-        /* Single Pass compression: Has to use current and historical data */
-        else
-        {
-#if 0
-            /* Experimental code */
-            int index = cpi->one_pass_frame_index;
-            int frames_to_scan = (cpi->max_gf_interval <= MAX_LAG_BUFFERS) ? cpi->max_gf_interval : MAX_LAG_BUFFERS;
-
-            /* ************** Experimental code - incomplete */
-            /*
-            double decay_val = 1.0;
-            double IIAccumulator = 0.0;
-            double last_iiaccumulator = 0.0;
-            double IIRatio;
-
-            cpi->one_pass_frame_index = cpi->common.current_video_frame%MAX_LAG_BUFFERS;
-
-            for ( i = 0; i < (frames_to_scan - 1); i++ )
-            {
-                if ( index < 0 )
-                    index = MAX_LAG_BUFFERS;
-                index --;
-
-                if ( cpi->one_pass_frame_stats[index].frame_coded_error > 0.0 )
-                {
-                    IIRatio = cpi->one_pass_frame_stats[index].frame_intra_error / cpi->one_pass_frame_stats[index].frame_coded_error;
-
-                    if ( IIRatio > 30.0 )
-                        IIRatio = 30.0;
-                }
-                else
-                    IIRatio = 30.0;
-
-                IIAccumulator += IIRatio * decay_val;
-
-                decay_val = decay_val * cpi->one_pass_frame_stats[index].frame_pcnt_inter;
-
-                if (    (i > MIN_GF_INTERVAL) &&
-                        ((IIAccumulator - last_iiaccumulator) < 2.0) )
-                {
-                    break;
-                }
-                last_iiaccumulator = IIAccumulator;
-            }
-
-            Boost = IIAccumulator*100.0/16.0;
-            cpi->baseline_gf_interval = i;
-
-            */
-#else
-
-            /*************************************************************/
-            /* OLD code */
-
-            /* Adjust boost based upon ambient Q */
-            Boost = GFQ_ADJUSTMENT;
-
-            /* Adjust based upon most recently measure intra useage */
-            Boost = Boost * gf_intra_usage_adjustment[(cpi->this_frame_percent_intra < 15) ? cpi->this_frame_percent_intra : 14] / 100;
-
-            /* Adjust gf boost based upon GF usage since last GF */
-            Boost = Boost * gf_adjust_table[gf_frame_useage] / 100;
-#endif
-        }
-
-        /* golden frame boost without recode loop often goes awry.  be
-         * safe by keeping numbers down.
-         */
-        if (!cpi->sf.recode_loop)
-        {
-            if (cpi->compressor_speed == 2)
-                Boost = Boost / 2;
-        }
-
-        /* Apply an upper limit based on Q for 1 pass encodes */
-        if (Boost > kf_gf_boost_qlimits[Q] && (cpi->pass == 0))
-            Boost = kf_gf_boost_qlimits[Q];
-
-        /* Apply lower limits to boost. */
-        else if (Boost < 110)
-            Boost = 110;
-
-        /* Note the boost used */
-        cpi->last_boost = Boost;
-
-    }
-
-    /* Estimate next interval
-     * This is updated once the real frame size/boost is known.
-     */
-    if (cpi->oxcf.fixed_q == -1)
-    {
-        if (cpi->pass == 2)         /* 2 Pass */
-        {
-            cpi->frames_till_gf_update_due = cpi->baseline_gf_interval;
-        }
-        else                            /* 1 Pass */
-        {
-            cpi->frames_till_gf_update_due = cpi->baseline_gf_interval;
-
-            if (cpi->last_boost > 750)
-                cpi->frames_till_gf_update_due++;
-
-            if (cpi->last_boost > 1000)
-                cpi->frames_till_gf_update_due++;
-
-            if (cpi->last_boost > 1250)
-                cpi->frames_till_gf_update_due++;
-
-            if (cpi->last_boost >= 1500)
-                cpi->frames_till_gf_update_due ++;
-
-            if (gf_interval_table[gf_frame_useage] > cpi->frames_till_gf_update_due)
-                cpi->frames_till_gf_update_due = gf_interval_table[gf_frame_useage];
-
-            if (cpi->frames_till_gf_update_due > cpi->max_gf_interval)
-                cpi->frames_till_gf_update_due = cpi->max_gf_interval;
-        }
-    }
-    else
-        cpi->frames_till_gf_update_due = cpi->baseline_gf_interval;
-
-    /* ARF on or off */
-    if (cpi->pass != 2)
-    {
-        /* For now Alt ref is not allowed except in 2 pass modes. */
-        cpi->source_alt_ref_pending = 0;
-
-        /*if ( cpi->oxcf.fixed_q == -1)
-        {
-            if ( cpi->oxcf.play_alternate && (cpi->last_boost > (100 + (AF_THRESH*cpi->frames_till_gf_update_due)) ) )
-                cpi->source_alt_ref_pending = 1;
-            else
-                cpi->source_alt_ref_pending = 0;
-        }*/
-    }
-}
-
-
-static void calc_pframe_target_size(VP8_COMP *cpi)
-{
-    int min_frame_target;
-    int old_per_frame_bandwidth = cpi->per_frame_bandwidth;
-
-    if ( cpi->current_layer > 0)
-        cpi->per_frame_bandwidth =
-            cpi->layer_context[cpi->current_layer].avg_frame_size_for_layer;
-
-    min_frame_target = 0;
-
-    if (cpi->pass == 2)
-    {
-        min_frame_target = cpi->min_frame_bandwidth;
-
-        if (min_frame_target < (cpi->av_per_frame_bandwidth >> 5))
-            min_frame_target = cpi->av_per_frame_bandwidth >> 5;
-    }
-    else if (min_frame_target < cpi->per_frame_bandwidth / 4)
-        min_frame_target = cpi->per_frame_bandwidth / 4;
-
-
-    /* Special alt reference frame case */
-    if((cpi->common.refresh_alt_ref_frame) && (cpi->oxcf.number_of_layers == 1))
-    {
-        if (cpi->pass == 2)
-        {
-            /* Per frame bit target for the alt ref frame */
-            cpi->per_frame_bandwidth = cpi->twopass.gf_bits;
-            cpi->this_frame_target = cpi->per_frame_bandwidth;
-        }
-
-        /* One Pass ??? TBD */
-    }
-
-    /* Normal frames (gf,and inter) */
-    else
-    {
-        /* 2 pass */
-        if (cpi->pass == 2)
-        {
-            cpi->this_frame_target = cpi->per_frame_bandwidth;
-        }
-        /* 1 pass */
-        else
-        {
-            int Adjustment;
-            /* Make rate adjustment to recover bits spent in key frame
-             * Test to see if the key frame inter data rate correction
-             * should still be in force
-             */
-            if (cpi->kf_overspend_bits > 0)
-            {
-                Adjustment = (cpi->kf_bitrate_adjustment <= cpi->kf_overspend_bits) ? cpi->kf_bitrate_adjustment : cpi->kf_overspend_bits;
-
-                if (Adjustment > (cpi->per_frame_bandwidth - min_frame_target))
-                    Adjustment = (cpi->per_frame_bandwidth - min_frame_target);
-
-                cpi->kf_overspend_bits -= Adjustment;
-
-                /* Calculate an inter frame bandwidth target for the next
-                 * few frames designed to recover any extra bits spent on
-                 * the key frame.
-                 */
-                cpi->this_frame_target = cpi->per_frame_bandwidth - Adjustment;
-
-                if (cpi->this_frame_target < min_frame_target)
-                    cpi->this_frame_target = min_frame_target;
-            }
-            else
-                cpi->this_frame_target = cpi->per_frame_bandwidth;
-
-            /* If appropriate make an adjustment to recover bits spent on a
-             * recent GF
-             */
-            if ((cpi->gf_overspend_bits > 0) && (cpi->this_frame_target > min_frame_target))
-            {
-                Adjustment = (cpi->non_gf_bitrate_adjustment <= cpi->gf_overspend_bits) ? cpi->non_gf_bitrate_adjustment : cpi->gf_overspend_bits;
-
-                if (Adjustment > (cpi->this_frame_target - min_frame_target))
-                    Adjustment = (cpi->this_frame_target - min_frame_target);
-
-                cpi->gf_overspend_bits -= Adjustment;
-                cpi->this_frame_target -= Adjustment;
-            }
-
-            /* Apply small + and - boosts for non gf frames */
-            if ((cpi->last_boost > 150) && (cpi->frames_till_gf_update_due > 0) &&
-                (cpi->current_gf_interval >= (MIN_GF_INTERVAL << 1)))
-            {
-                /* % Adjustment limited to the range 1% to 10% */
-                Adjustment = (cpi->last_boost - 100) >> 5;
-
-                if (Adjustment < 1)
-                    Adjustment = 1;
-                else if (Adjustment > 10)
-                    Adjustment = 10;
-
-                /* Convert to bits */
-                Adjustment = (cpi->this_frame_target * Adjustment) / 100;
-
-                if (Adjustment > (cpi->this_frame_target - min_frame_target))
-                    Adjustment = (cpi->this_frame_target - min_frame_target);
-
-                if (cpi->frames_since_golden == (cpi->current_gf_interval >> 1))
-                {
-                    Adjustment = (cpi->current_gf_interval - 1) * Adjustment;
-                    // Limit adjustment to 10% of current target.
-                    if (Adjustment > (10 * cpi->this_frame_target) / 100)
-                        Adjustment = (10 * cpi->this_frame_target) / 100;
-                    cpi->this_frame_target += Adjustment;
-                }
-                else
-                    cpi->this_frame_target -= Adjustment;
-            }
-        }
-    }
-
-    /* Sanity check that the total sum of adjustments is not above the
-     * maximum allowed That is that having allowed for KF and GF penalties
-     * we have not pushed the current interframe target to low. If the
-     * adjustment we apply here is not capable of recovering all the extra
-     * bits we have spent in the KF or GF then the remainder will have to
-     * be recovered over a longer time span via other buffer / rate control
-     * mechanisms.
-     */
-    if (cpi->this_frame_target < min_frame_target)
-        cpi->this_frame_target = min_frame_target;
-
-    if (!cpi->common.refresh_alt_ref_frame)
-        /* Note the baseline target data rate for this inter frame. */
-        cpi->inter_frame_target = cpi->this_frame_target;
-
-    /* One Pass specific code */
-    if (cpi->pass == 0)
-    {
-        /* Adapt target frame size with respect to any buffering constraints: */
-        if (cpi->buffered_mode)
-        {
-            int one_percent_bits = (int)
-                (1 + cpi->oxcf.optimal_buffer_level / 100);
-
-            if ((cpi->buffer_level < cpi->oxcf.optimal_buffer_level) ||
-                (cpi->bits_off_target < cpi->oxcf.optimal_buffer_level))
-            {
-                int percent_low = 0;
-
-                /* Decide whether or not we need to adjust the frame data
-                 * rate target.
-                 *
-                 * If we are are below the optimal buffer fullness level
-                 * and adherence to buffering constraints is important to
-                 * the end usage then adjust the per frame target.
-                 */
-                if ((cpi->oxcf.end_usage == USAGE_STREAM_FROM_SERVER) &&
-                    (cpi->buffer_level < cpi->oxcf.optimal_buffer_level))
-                {
-                    percent_low = (int)
-                        ((cpi->oxcf.optimal_buffer_level - cpi->buffer_level) /
-                        one_percent_bits);
-                }
-                /* Are we overshooting the long term clip data rate... */
-                else if (cpi->bits_off_target < 0)
-                {
-                    /* Adjust per frame data target downwards to compensate. */
-                    percent_low = (int)(100 * -cpi->bits_off_target /
-                                       (cpi->total_byte_count * 8));
-                }
-
-                if (percent_low > cpi->oxcf.under_shoot_pct)
-                    percent_low = cpi->oxcf.under_shoot_pct;
-                else if (percent_low < 0)
-                    percent_low = 0;
-
-                /* lower the target bandwidth for this frame. */
-                cpi->this_frame_target -=
-                        (cpi->this_frame_target * percent_low) / 200;
-
-                /* Are we using allowing control of active_worst_allowed_q
-                 * according to buffer level.
-                 */
-                if (cpi->auto_worst_q && cpi->ni_frames > 150)
-                {
-                    int64_t critical_buffer_level;
-
-                    /* For streaming applications the most important factor is
-                     * cpi->buffer_level as this takes into account the
-                     * specified short term buffering constraints. However,
-                     * hitting the long term clip data rate target is also
-                     * important.
-                     */
-                    if (cpi->oxcf.end_usage == USAGE_STREAM_FROM_SERVER)
-                    {
-                        /* Take the smaller of cpi->buffer_level and
-                         * cpi->bits_off_target
-                         */
-                        critical_buffer_level =
-                            (cpi->buffer_level < cpi->bits_off_target)
-                            ? cpi->buffer_level : cpi->bits_off_target;
-                    }
-                    /* For local file playback short term buffering constraints
-                     * are less of an issue
-                     */
-                    else
-                    {
-                        /* Consider only how we are doing for the clip as a
-                         * whole
-                         */
-                        critical_buffer_level = cpi->bits_off_target;
-                    }
-
-                    /* Set the active worst quality based upon the selected
-                     * buffer fullness number.
-                     */
-                    if (critical_buffer_level < cpi->oxcf.optimal_buffer_level)
-                    {
-                        if ( critical_buffer_level >
-                             (cpi->oxcf.optimal_buffer_level >> 2) )
-                        {
-                            int64_t qadjustment_range =
-                                      cpi->worst_quality - cpi->ni_av_qi;
-                            int64_t above_base =
-                                      (critical_buffer_level -
-                                       (cpi->oxcf.optimal_buffer_level >> 2));
-
-                            /* Step active worst quality down from
-                             * cpi->ni_av_qi when (critical_buffer_level ==
-                             * cpi->optimal_buffer_level) to
-                             * cpi->worst_quality when
-                             * (critical_buffer_level ==
-                             *     cpi->optimal_buffer_level >> 2)
-                             */
-                            cpi->active_worst_quality =
-                                cpi->worst_quality -
-                                (int)((qadjustment_range * above_base) /
-                                 (cpi->oxcf.optimal_buffer_level*3>>2));
-                        }
-                        else
-                        {
-                            cpi->active_worst_quality = cpi->worst_quality;
-                        }
-                    }
-                    else
-                    {
-                        cpi->active_worst_quality = cpi->ni_av_qi;
-                    }
-                }
-                else
-                {
-                    cpi->active_worst_quality = cpi->worst_quality;
-                }
-            }
-            else
-            {
-                int percent_high = 0;
-
-                if ((cpi->oxcf.end_usage == USAGE_STREAM_FROM_SERVER)
-                     && (cpi->buffer_level > cpi->oxcf.optimal_buffer_level))
-                {
-                    percent_high = (int)((cpi->buffer_level
-                                    - cpi->oxcf.optimal_buffer_level)
-                                   / one_percent_bits);
-                }
-                else if (cpi->bits_off_target > cpi->oxcf.optimal_buffer_level)
-                {
-                    percent_high = (int)((100 * cpi->bits_off_target)
-                                         / (cpi->total_byte_count * 8));
-                }
-
-                if (percent_high > cpi->oxcf.over_shoot_pct)
-                    percent_high = cpi->oxcf.over_shoot_pct;
-                else if (percent_high < 0)
-                    percent_high = 0;
-
-                cpi->this_frame_target += (cpi->this_frame_target *
-                                          percent_high) / 200;
-
-                /* Are we allowing control of active_worst_allowed_q according
-                 * to buffer level.
-                 */
-                if (cpi->auto_worst_q && cpi->ni_frames > 150)
-                {
-                    /* When using the relaxed buffer model stick to the
-                     * user specified value
-                     */
-                    cpi->active_worst_quality = cpi->ni_av_qi;
-                }
-                else
-                {
-                    cpi->active_worst_quality = cpi->worst_quality;
-                }
-            }
-
-            /* Set active_best_quality to prevent quality rising too high */
-            cpi->active_best_quality = cpi->best_quality;
-
-            /* Worst quality obviously must not be better than best quality */
-            if (cpi->active_worst_quality <= cpi->active_best_quality)
-                cpi->active_worst_quality = cpi->active_best_quality + 1;
-
-            if(cpi->active_worst_quality > 127)
-                cpi->active_worst_quality = 127;
-        }
-        /* Unbuffered mode (eg. video conferencing) */
-        else
-        {
-            /* Set the active worst quality */
-            cpi->active_worst_quality = cpi->worst_quality;
-        }
-
-        /* Special trap for constrained quality mode
-         * "active_worst_quality" may never drop below cq level
-         * for any frame type.
-         */
-        if ( cpi->oxcf.end_usage == USAGE_CONSTRAINED_QUALITY &&
-             cpi->active_worst_quality < cpi->cq_target_quality)
-        {
-            cpi->active_worst_quality = cpi->cq_target_quality;
-        }
-    }
-
-    /* Test to see if we have to drop a frame
-     * The auto-drop frame code is only used in buffered mode.
-     * In unbufferd mode (eg vide conferencing) the descision to
-     * code or drop a frame is made outside the codec in response to real
-     * world comms or buffer considerations.
-     */
-    if (cpi->drop_frames_allowed &&
-        (cpi->oxcf.end_usage == USAGE_STREAM_FROM_SERVER) &&
-        ((cpi->common.frame_type != KEY_FRAME)))
-    {
-        /* Check for a buffer underun-crisis in which case we have to drop
-         * a frame
-         */
-        if ((cpi->buffer_level < 0))
-        {
-#if 0
-            FILE *f = fopen("dec.stt", "a");
-            fprintf(f, "%10d %10d %10d %10d ***** BUFFER EMPTY\n",
-                    (int) cpi->common.current_video_frame,
-                    cpi->decimation_factor, cpi->common.horiz_scale,
-                    (cpi->buffer_level * 100) / cpi->oxcf.optimal_buffer_level);
-            fclose(f);
-#endif
-            cpi->drop_frame = 1;
-
-            /* Update the buffer level variable. */
-            cpi->bits_off_target += cpi->av_per_frame_bandwidth;
-            if (cpi->bits_off_target > cpi->oxcf.maximum_buffer_size)
-              cpi->bits_off_target = (int)cpi->oxcf.maximum_buffer_size;
-            cpi->buffer_level = cpi->bits_off_target;
-
-            if (cpi->oxcf.number_of_layers > 1) {
-              unsigned int i;
-
-              // Propagate bits saved by dropping the frame to higher layers.
-              for (i = cpi->current_layer + 1; i < cpi->oxcf.number_of_layers;
-                  i++) {
-                LAYER_CONTEXT *lc = &cpi->layer_context[i];
-                lc->bits_off_target += (int)(lc->target_bandwidth /
-                                             lc->framerate);
-                if (lc->bits_off_target > lc->maximum_buffer_size)
-                  lc->bits_off_target = lc->maximum_buffer_size;
-                lc->buffer_level = lc->bits_off_target;
-              }
-            }
-        }
-    }
-
-    /* Adjust target frame size for Golden Frames: */
-    if (cpi->oxcf.error_resilient_mode == 0 &&
-        (cpi->frames_till_gf_update_due == 0) && !cpi->drop_frame)
-    {
-        int Q = (cpi->oxcf.fixed_q < 0) ? cpi->last_q[INTER_FRAME] : cpi->oxcf.fixed_q;
-
-        int gf_frame_useage = 0;      /* Golden frame useage since last GF */
-        int tot_mbs = cpi->recent_ref_frame_usage[INTRA_FRAME]  +
-                      cpi->recent_ref_frame_usage[LAST_FRAME]   +
-                      cpi->recent_ref_frame_usage[GOLDEN_FRAME] +
-                      cpi->recent_ref_frame_usage[ALTREF_FRAME];
-
-        int pct_gf_active = (100 * cpi->gf_active_count) / (cpi->common.mb_rows * cpi->common.mb_cols);
-
-        if (tot_mbs)
-            gf_frame_useage = (cpi->recent_ref_frame_usage[GOLDEN_FRAME] + cpi->recent_ref_frame_usage[ALTREF_FRAME]) * 100 / tot_mbs;
-
-        if (pct_gf_active > gf_frame_useage)
-            gf_frame_useage = pct_gf_active;
-
-        /* Is a fixed manual GF frequency being used */
-        if (cpi->auto_gold)
-        {
-            /* For one pass throw a GF if recent frame intra useage is
-             * low or the GF useage is high
-             */
-            if ((cpi->pass == 0) && (cpi->this_frame_percent_intra < 15 || gf_frame_useage >= 5))
-                cpi->common.refresh_golden_frame = 1;
-
-            /* Two pass GF descision */
-            else if (cpi->pass == 2)
-                cpi->common.refresh_golden_frame = 1;
-        }
-
-#if 0
-
-        /* Debug stats */
-        if (0)
-        {
-            FILE *f;
-
-            f = fopen("gf_useaget.stt", "a");
-            fprintf(f, " %8ld %10ld %10ld %10ld %10ld\n",
-                    cpi->common.current_video_frame,  cpi->gfu_boost, GFQ_ADJUSTMENT, cpi->gfu_boost, gf_frame_useage);
-            fclose(f);
-        }
-
-#endif
-
-        if (cpi->common.refresh_golden_frame == 1)
-        {
-#if 0
-
-            if (0)
-            {
-                FILE *f;
-
-                f = fopen("GFexit.stt", "a");
-                fprintf(f, "%8ld GF coded\n", cpi->common.current_video_frame);
-                fclose(f);
-            }
-
-#endif
-
-            if (cpi->auto_adjust_gold_quantizer)
-            {
-                calc_gf_params(cpi);
-            }
-
-            /* If we are using alternate ref instead of gf then do not apply the
-             * boost It will instead be applied to the altref update Jims
-             * modified boost
-             */
-            if (!cpi->source_alt_ref_active)
-            {
-                if (cpi->oxcf.fixed_q < 0)
-                {
-                    if (cpi->pass == 2)
-                    {
-                        /* The spend on the GF is defined in the two pass
-                         * code for two pass encodes
-                         */
-                        cpi->this_frame_target = cpi->per_frame_bandwidth;
-                    }
-                    else
-                    {
-                        int Boost = cpi->last_boost;
-                        int frames_in_section = cpi->frames_till_gf_update_due + 1;
-                        int allocation_chunks = (frames_in_section * 100) + (Boost - 100);
-                        int bits_in_section = cpi->inter_frame_target * frames_in_section;
-
-                        /* Normalize Altboost and allocations chunck down to
-                         * prevent overflow
-                         */
-                        while (Boost > 1000)
-                        {
-                            Boost /= 2;
-                            allocation_chunks /= 2;
-                        }
-
-                        /* Avoid loss of precision but avoid overflow */
-                        if ((bits_in_section >> 7) > allocation_chunks)
-                            cpi->this_frame_target = Boost * (bits_in_section / allocation_chunks);
-                        else
-                            cpi->this_frame_target = (Boost * bits_in_section) / allocation_chunks;
-                    }
-                }
-                else
-                    cpi->this_frame_target =
-                        (estimate_bits_at_q(1, Q, cpi->common.MBs, 1.0)
-                         * cpi->last_boost) / 100;
-
-            }
-            /* If there is an active ARF at this location use the minimum
-             * bits on this frame even if it is a contructed arf.
-             * The active maximum quantizer insures that an appropriate
-             * number of bits will be spent if needed for contstructed ARFs.
-             */
-            else
-            {
-                cpi->this_frame_target = 0;
-            }
-
-            cpi->current_gf_interval = cpi->frames_till_gf_update_due;
-
-        }
-    }
-
-    cpi->per_frame_bandwidth = old_per_frame_bandwidth;
-}
-
-
-void vp8_update_rate_correction_factors(VP8_COMP *cpi, int damp_var)
-{
-    int    Q = cpi->common.base_qindex;
-    int    correction_factor = 100;
-    double rate_correction_factor;
-    double adjustment_limit;
-
-    int    projected_size_based_on_q = 0;
-
-    /* Clear down mmx registers to allow floating point in what follows */
-    vp8_clear_system_state();
-
-    if (cpi->common.frame_type == KEY_FRAME)
-    {
-        rate_correction_factor = cpi->key_frame_rate_correction_factor;
-    }
-    else
-    {
-        if (cpi->oxcf.number_of_layers == 1 &&
-           (cpi->common.refresh_alt_ref_frame ||
-            cpi->common.refresh_golden_frame))
-            rate_correction_factor = cpi->gf_rate_correction_factor;
-        else
-            rate_correction_factor = cpi->rate_correction_factor;
-    }
-
-    /* Work out how big we would have expected the frame to be at this Q
-     * given the current correction factor. Stay in double to avoid int
-     * overflow when values are large
-     */
-    projected_size_based_on_q = (int)(((.5 + rate_correction_factor * vp8_bits_per_mb[cpi->common.frame_type][Q]) * cpi->common.MBs) / (1 << BPER_MB_NORMBITS));
-
-    /* Make some allowance for cpi->zbin_over_quant */
-    if (cpi->mb.zbin_over_quant > 0)
-    {
-        int Z = cpi->mb.zbin_over_quant;
-        double Factor = 0.99;
-        double factor_adjustment = 0.01 / 256.0;
-
-        while (Z > 0)
-        {
-            Z --;
-            projected_size_based_on_q =
-                (int)(Factor * projected_size_based_on_q);
-            Factor += factor_adjustment;
-
-            if (Factor  >= 0.999)
-                Factor = 0.999;
-        }
-    }
-
-    /* Work out a size correction factor. */
-    if (projected_size_based_on_q > 0)
-        correction_factor = (100 * cpi->projected_frame_size) / projected_size_based_on_q;
-
-    /* More heavily damped adjustment used if we have been oscillating
-     * either side of target
-     */
-    switch (damp_var)
-    {
-    case 0:
-        adjustment_limit = 0.75;
-        break;
-    case 1:
-        adjustment_limit = 0.375;
-        break;
-    case 2:
-    default:
-        adjustment_limit = 0.25;
-        break;
-    }
-
-    if (correction_factor > 102)
-    {
-        /* We are not already at the worst allowable quality */
-        correction_factor = (int)(100.5 + ((correction_factor - 100) * adjustment_limit));
-        rate_correction_factor = ((rate_correction_factor * correction_factor) / 100);
-
-        /* Keep rate_correction_factor within limits */
-        if (rate_correction_factor > MAX_BPB_FACTOR)
-            rate_correction_factor = MAX_BPB_FACTOR;
-    }
-    else if (correction_factor < 99)
-    {
-        /* We are not already at the best allowable quality */
-        correction_factor = (int)(100.5 - ((100 - correction_factor) * adjustment_limit));
-        rate_correction_factor = ((rate_correction_factor * correction_factor) / 100);
-
-        /* Keep rate_correction_factor within limits */
-        if (rate_correction_factor < MIN_BPB_FACTOR)
-            rate_correction_factor = MIN_BPB_FACTOR;
-    }
-
-    if (cpi->common.frame_type == KEY_FRAME)
-        cpi->key_frame_rate_correction_factor = rate_correction_factor;
-    else
-    {
-        if (cpi->oxcf.number_of_layers == 1 &&
-           (cpi->common.refresh_alt_ref_frame ||
-            cpi->common.refresh_golden_frame))
-            cpi->gf_rate_correction_factor = rate_correction_factor;
-        else
-            cpi->rate_correction_factor = rate_correction_factor;
-    }
-}
-
-
-int vp8_regulate_q(VP8_COMP *cpi, int target_bits_per_frame)
-{
-    int Q = cpi->active_worst_quality;
-
-    if (cpi->force_maxqp == 1) {
-      cpi->active_worst_quality = cpi->worst_quality;
-      return cpi->worst_quality;
-    }
-
-    /* Reset Zbin OQ value */
-    cpi->mb.zbin_over_quant = 0;
-
-    if (cpi->oxcf.fixed_q >= 0)
-    {
-        Q = cpi->oxcf.fixed_q;
-
-        if (cpi->common.frame_type == KEY_FRAME)
-        {
-            Q = cpi->oxcf.key_q;
-        }
-        else if (cpi->oxcf.number_of_layers == 1 &&
-            cpi->common.refresh_alt_ref_frame)
-        {
-            Q = cpi->oxcf.alt_q;
-        }
-        else if (cpi->oxcf.number_of_layers == 1  &&
-            cpi->common.refresh_golden_frame)
-        {
-            Q = cpi->oxcf.gold_q;
-        }
-    }
-    else
-    {
-        int i;
-        int last_error = INT_MAX;
-        int target_bits_per_mb;
-        int bits_per_mb_at_this_q;
-        double correction_factor;
-
-        /* Select the appropriate correction factor based upon type of frame. */
-        if (cpi->common.frame_type == KEY_FRAME)
-            correction_factor = cpi->key_frame_rate_correction_factor;
-        else
-        {
-            if (cpi->oxcf.number_of_layers == 1 &&
-               (cpi->common.refresh_alt_ref_frame ||
-                cpi->common.refresh_golden_frame))
-                correction_factor = cpi->gf_rate_correction_factor;
-            else
-                correction_factor = cpi->rate_correction_factor;
-        }
-
-        /* Calculate required scaling factor based on target frame size and
-         * size of frame produced using previous Q
-         */
-        if (target_bits_per_frame >= (INT_MAX >> BPER_MB_NORMBITS))
-            /* Case where we would overflow int */
-            target_bits_per_mb = (target_bits_per_frame / cpi->common.MBs) << BPER_MB_NORMBITS;
-        else
-            target_bits_per_mb = (target_bits_per_frame << BPER_MB_NORMBITS) / cpi->common.MBs;
-
-        i = cpi->active_best_quality;
-
-        do
-        {
-            bits_per_mb_at_this_q = (int)(.5 + correction_factor * vp8_bits_per_mb[cpi->common.frame_type][i]);
-
-            if (bits_per_mb_at_this_q <= target_bits_per_mb)
-            {
-                if ((target_bits_per_mb - bits_per_mb_at_this_q) <= last_error)
-                    Q = i;
-                else
-                    Q = i - 1;
-
-                break;
-            }
-            else
-                last_error = bits_per_mb_at_this_q - target_bits_per_mb;
-        }
-        while (++i <= cpi->active_worst_quality);
-
-
-        /* If we are at MAXQ then enable Q over-run which seeks to claw
-         * back additional bits through things like the RD multiplier
-         * and zero bin size.
-         */
-        if (Q >= MAXQ)
-        {
-            int zbin_oqmax;
-
-            double Factor = 0.99;
-            double factor_adjustment = 0.01 / 256.0;
-
-            if (cpi->common.frame_type == KEY_FRAME)
-                zbin_oqmax = 0;
-            else if (cpi->oxcf.number_of_layers == 1 &&
-                (cpi->common.refresh_alt_ref_frame ||
-                (cpi->common.refresh_golden_frame &&
-                 !cpi->source_alt_ref_active)))
-                zbin_oqmax = 16;
-            else
-                zbin_oqmax = ZBIN_OQ_MAX;
-
-            /*{
-                double Factor = (double)target_bits_per_mb/(double)bits_per_mb_at_this_q;
-                double Oq;
-
-                Factor = Factor/1.2683;
-
-                Oq = pow( Factor, (1.0/-0.165) );
-
-                if ( Oq > zbin_oqmax )
-                    Oq = zbin_oqmax;
-
-                cpi->zbin_over_quant = (int)Oq;
-            }*/
-
-            /* Each incrment in the zbin is assumed to have a fixed effect
-             * on bitrate. This is not of course true. The effect will be
-             * highly clip dependent and may well have sudden steps. The
-             * idea here is to acheive higher effective quantizers than the
-             * normal maximum by expanding the zero bin and hence
-             * decreasing the number of low magnitude non zero coefficients.
-             */
-            while (cpi->mb.zbin_over_quant < zbin_oqmax)
-            {
-                cpi->mb.zbin_over_quant ++;
-
-                if (cpi->mb.zbin_over_quant > zbin_oqmax)
-                    cpi->mb.zbin_over_quant = zbin_oqmax;
-
-                /* Adjust bits_per_mb_at_this_q estimate */
-                bits_per_mb_at_this_q = (int)(Factor * bits_per_mb_at_this_q);
-                Factor += factor_adjustment;
-
-                if (Factor  >= 0.999)
-                    Factor = 0.999;
-
-                /* Break out if we get down to the target rate */
-                if (bits_per_mb_at_this_q <= target_bits_per_mb)
-                    break;
-            }
-
-        }
-    }
-
-    return Q;
-}
-
-
-static int estimate_keyframe_frequency(VP8_COMP *cpi)
-{
-    int i;
-
-    /* Average key frame frequency */
-    int av_key_frame_frequency = 0;
-
-    /* First key frame at start of sequence is a special case. We have no
-     * frequency data.
-     */
-    if (cpi->key_frame_count == 1)
-    {
-        /* Assume a default of 1 kf every 2 seconds, or the max kf interval,
-         * whichever is smaller.
-         */
-        int key_freq = cpi->oxcf.key_freq>0 ? cpi->oxcf.key_freq : 1;
-        av_key_frame_frequency = 1 + (int)cpi->output_framerate * 2;
-
-        if (cpi->oxcf.auto_key && av_key_frame_frequency > key_freq)
-            av_key_frame_frequency = key_freq;
-
-        cpi->prior_key_frame_distance[KEY_FRAME_CONTEXT - 1]
-            = av_key_frame_frequency;
-    }
-    else
-    {
-        unsigned int total_weight = 0;
-        int last_kf_interval =
-                (cpi->frames_since_key > 0) ? cpi->frames_since_key : 1;
-
-        /* reset keyframe context and calculate weighted average of last
-         * KEY_FRAME_CONTEXT keyframes
-         */
-        for (i = 0; i < KEY_FRAME_CONTEXT; i++)
-        {
-            if (i < KEY_FRAME_CONTEXT - 1)
-                cpi->prior_key_frame_distance[i]
-                    = cpi->prior_key_frame_distance[i+1];
-            else
-                cpi->prior_key_frame_distance[i] = last_kf_interval;
-
-            av_key_frame_frequency += prior_key_frame_weight[i]
-                                      * cpi->prior_key_frame_distance[i];
-            total_weight += prior_key_frame_weight[i];
-        }
-
-        av_key_frame_frequency  /= total_weight;
-
-    }
-    // TODO (marpan): Given the checks above, |av_key_frame_frequency|
-    // should always be above 0. But for now we keep the sanity check in.
-    if (av_key_frame_frequency == 0)
-        av_key_frame_frequency = 1;
-    return av_key_frame_frequency;
-}
-
-
-void vp8_adjust_key_frame_context(VP8_COMP *cpi)
-{
-    /* Clear down mmx registers to allow floating point in what follows */
-    vp8_clear_system_state();
-
-    /* Do we have any key frame overspend to recover? */
-    /* Two-pass overspend handled elsewhere. */
-    if ((cpi->pass != 2)
-         && (cpi->projected_frame_size > cpi->per_frame_bandwidth))
-    {
-        int overspend;
-
-        /* Update the count of key frame overspend to be recovered in
-         * subsequent frames. A portion of the KF overspend is treated as gf
-         * overspend (and hence recovered more quickly) as the kf is also a
-         * gf. Otherwise the few frames following each kf tend to get more
-         * bits allocated than those following other gfs.
-         */
-        overspend = (cpi->projected_frame_size - cpi->per_frame_bandwidth);
-
-        if (cpi->oxcf.number_of_layers > 1)
-            cpi->kf_overspend_bits += overspend;
-        else
-        {
-            cpi->kf_overspend_bits += overspend * 7 / 8;
-            cpi->gf_overspend_bits += overspend * 1 / 8;
-        }
-
-        /* Work out how much to try and recover per frame. */
-        cpi->kf_bitrate_adjustment = cpi->kf_overspend_bits
-                                     / estimate_keyframe_frequency(cpi);
-    }
-
-    cpi->frames_since_key = 0;
-    cpi->key_frame_count++;
-}
-
-
-void vp8_compute_frame_size_bounds(VP8_COMP *cpi, int *frame_under_shoot_limit, int *frame_over_shoot_limit)
-{
-    /* Set-up bounds on acceptable frame size: */
-    if (cpi->oxcf.fixed_q >= 0)
-    {
-        /* Fixed Q scenario: frame size never outranges target
-         * (there is no target!)
-         */
-        *frame_under_shoot_limit = 0;
-        *frame_over_shoot_limit  = INT_MAX;
-    }
-    else
-    {
-        if (cpi->common.frame_type == KEY_FRAME)
-        {
-            *frame_over_shoot_limit  = cpi->this_frame_target * 9 / 8;
-            *frame_under_shoot_limit = cpi->this_frame_target * 7 / 8;
-        }
-        else
-        {
-            if (cpi->oxcf.number_of_layers > 1 ||
-                cpi->common.refresh_alt_ref_frame ||
-                cpi->common.refresh_golden_frame)
-            {
-                *frame_over_shoot_limit  = cpi->this_frame_target * 9 / 8;
-                *frame_under_shoot_limit = cpi->this_frame_target * 7 / 8;
-            }
-            else
-            {
-                /* For CBR take buffer fullness into account */
-                if (cpi->oxcf.end_usage == USAGE_STREAM_FROM_SERVER)
-                {
-                    if (cpi->buffer_level >= ((cpi->oxcf.optimal_buffer_level + cpi->oxcf.maximum_buffer_size) >> 1))
-                    {
-                        /* Buffer is too full so relax overshoot and tighten
-                         * undershoot
-                         */
-                        *frame_over_shoot_limit  = cpi->this_frame_target * 12 / 8;
-                        *frame_under_shoot_limit = cpi->this_frame_target * 6 / 8;
-                    }
-                    else if (cpi->buffer_level <= (cpi->oxcf.optimal_buffer_level >> 1))
-                    {
-                        /* Buffer is too low so relax undershoot and tighten
-                         * overshoot
-                         */
-                        *frame_over_shoot_limit  = cpi->this_frame_target * 10 / 8;
-                        *frame_under_shoot_limit = cpi->this_frame_target * 4 / 8;
-                    }
-                    else
-                    {
-                        *frame_over_shoot_limit  = cpi->this_frame_target * 11 / 8;
-                        *frame_under_shoot_limit = cpi->this_frame_target * 5 / 8;
-                    }
-                }
-                /* VBR and CQ mode */
-                /* Note that tighter restrictions here can help quality
-                 * but hurt encode speed
-                 */
-                else
-                {
-                    /* Stron overshoot limit for constrained quality */
-                    if (cpi->oxcf.end_usage == USAGE_CONSTRAINED_QUALITY)
-                    {
-                        *frame_over_shoot_limit  = cpi->this_frame_target * 11 / 8;
-                        *frame_under_shoot_limit = cpi->this_frame_target * 2 / 8;
-                    }
-                    else
-                    {
-                        *frame_over_shoot_limit  = cpi->this_frame_target * 11 / 8;
-                        *frame_under_shoot_limit = cpi->this_frame_target * 5 / 8;
-                    }
-                }
-            }
-        }
-
-        /* For very small rate targets where the fractional adjustment
-         * (eg * 7/8) may be tiny make sure there is at least a minimum
-         * range.
-         */
-        *frame_over_shoot_limit += 200;
-        *frame_under_shoot_limit -= 200;
-        if ( *frame_under_shoot_limit < 0 )
-            *frame_under_shoot_limit = 0;
-
-    }
-}
-
-
-/* return of 0 means drop frame */
-int vp8_pick_frame_size(VP8_COMP *cpi)
-{
-    VP8_COMMON *cm = &cpi->common;
-
-    if (cm->frame_type == KEY_FRAME)
-        calc_iframe_target_size(cpi);
-    else
-    {
-        calc_pframe_target_size(cpi);
-
-        /* Check if we're dropping the frame: */
-        if (cpi->drop_frame)
-        {
-            cpi->drop_frame = 0;
-            return 0;
-        }
-    }
-    return 1;
-}
-// If this just encoded frame (mcomp/transform/quant, but before loopfilter and
-// pack_bitstream) has large overshoot, and was not being encoded close to the
-// max QP, then drop this frame and force next frame to be encoded at max QP.
-// Condition this on 1 pass CBR with screen content mode and frame dropper off.
-// TODO(marpan): Should do this exit condition during the encode_frame
-// (i.e., halfway during the encoding of the frame) to save cycles.
-int vp8_drop_encodedframe_overshoot(VP8_COMP *cpi, int Q) {
-  if (cpi->pass == 0 &&
-      cpi->oxcf.end_usage == USAGE_STREAM_FROM_SERVER &&
-      cpi->drop_frames_allowed == 0 &&
-      cpi->common.frame_type != KEY_FRAME) {
-    // Note: the "projected_frame_size" from encode_frame() only gives estimate
-    // of mode/motion vector rate (in non-rd mode): so below we only require
-    // that projected_frame_size is somewhat greater than per-frame-bandwidth,
-    // but add additional condition with high threshold on prediction residual.
-
-    // QP threshold: only allow dropping if we are not close to qp_max.
-    int thresh_qp = 3 * cpi->worst_quality >> 2;
-    // Rate threshold, in bytes.
-    int thresh_rate = 2 * (cpi->av_per_frame_bandwidth >> 3);
-    // Threshold for the average (over all macroblocks) of the pixel-sum
-    // residual error over 16x16 block. Should add QP dependence on threshold?
-    int thresh_pred_err_mb = (256 << 4);
-    int pred_err_mb = (int)(cpi->mb.prediction_error / cpi->common.MBs);
-    if (Q < thresh_qp &&
-        cpi->projected_frame_size > thresh_rate &&
-        pred_err_mb > thresh_pred_err_mb) {
-      double new_correction_factor = cpi->rate_correction_factor;
-      const int target_size = cpi->av_per_frame_bandwidth;
-      int target_bits_per_mb;
-      // Drop this frame: advance frame counters, and set force_maxqp flag.
-      cpi->common.current_video_frame++;
-      cpi->frames_since_key++;
-      // Flag to indicate we will force next frame to be encoded at max QP.
-      cpi->force_maxqp = 1;
-      // Reset the buffer levels.
-      cpi->buffer_level = cpi->oxcf.optimal_buffer_level;
-      cpi->bits_off_target = cpi->oxcf.optimal_buffer_level;
-      // Compute a new rate correction factor, corresponding to the current
-      // target frame size and max_QP, and adjust the rate correction factor
-      // upwards, if needed.
-      // This is to prevent a bad state where the re-encoded frame at max_QP
-      // undershoots significantly, and then we end up dropping every other
-      // frame because the QP/rate_correction_factor may have been too low
-      // before the drop and then takes too long to come up.
-      if (target_size >= (INT_MAX >> BPER_MB_NORMBITS))
-        target_bits_per_mb =
-            (target_size / cpi->common.MBs) << BPER_MB_NORMBITS;
-      else
-        target_bits_per_mb =
-            (target_size << BPER_MB_NORMBITS) / cpi->common.MBs;
-      // Rate correction factor based on target_size_per_mb and max_QP.
-      new_correction_factor = (double)target_bits_per_mb /
-          (double)vp8_bits_per_mb[INTER_FRAME][cpi->worst_quality];
-      if (new_correction_factor > cpi->rate_correction_factor)
-        cpi->rate_correction_factor =
-            VPXMIN(2.0 * cpi->rate_correction_factor, new_correction_factor);
-      if (cpi->rate_correction_factor > MAX_BPB_FACTOR)
-        cpi->rate_correction_factor = MAX_BPB_FACTOR;
-      return 1;
-    } else {
-      cpi->force_maxqp = 0;
-      return 0;
-    }
-    cpi->force_maxqp = 0;
-    return 0;
-  }
-  cpi->force_maxqp = 0;
-  return 0;
-}
diff --git a/vp8/encoder/ratectrl.h b/vp8/encoder/ratectrl.h
deleted file mode 100644 (file)
index 703de9f..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#ifndef VP8_ENCODER_RATECTRL_H_
-#define VP8_ENCODER_RATECTRL_H_
-
-#include "onyx_int.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-extern void vp8_save_coding_context(VP8_COMP *cpi);
-extern void vp8_restore_coding_context(VP8_COMP *cpi);
-
-extern void vp8_setup_key_frame(VP8_COMP *cpi);
-extern void vp8_update_rate_correction_factors(VP8_COMP *cpi, int damp_var);
-extern int vp8_regulate_q(VP8_COMP *cpi, int target_bits_per_frame);
-extern void vp8_adjust_key_frame_context(VP8_COMP *cpi);
-extern void vp8_compute_frame_size_bounds(VP8_COMP *cpi, int *frame_under_shoot_limit, int *frame_over_shoot_limit);
-
-/* return of 0 means drop frame */
-extern int vp8_pick_frame_size(VP8_COMP *cpi);
-
-extern int vp8_drop_encodedframe_overshoot(VP8_COMP *cpi, int Q);
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP8_ENCODER_RATECTRL_H_
diff --git a/vp8/encoder/rdopt.c b/vp8/encoder/rdopt.c
deleted file mode 100644 (file)
index 6507ae9..0000000
+++ /dev/null
@@ -1,2646 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#include <stdio.h>
-#include <math.h>
-#include <limits.h>
-#include <assert.h>
-#include "vpx_config.h"
-#include "vp8_rtcd.h"
-#include "./vpx_dsp_rtcd.h"
-#include "tokenize.h"
-#include "treewriter.h"
-#include "onyx_int.h"
-#include "modecosts.h"
-#include "encodeintra.h"
-#include "pickinter.h"
-#include "vp8/common/entropymode.h"
-#include "vp8/common/reconinter.h"
-#include "vp8/common/reconintra.h"
-#include "vp8/common/reconintra4x4.h"
-#include "vp8/common/findnearmv.h"
-#include "vp8/common/quant_common.h"
-#include "encodemb.h"
-#include "vp8/encoder/quantize.h"
-#include "vpx_dsp/variance.h"
-#include "mcomp.h"
-#include "rdopt.h"
-#include "vpx_mem/vpx_mem.h"
-#include "vp8/common/systemdependent.h"
-#if CONFIG_TEMPORAL_DENOISING
-#include "denoising.h"
-#endif
-extern void vp8_update_zbin_extra(VP8_COMP *cpi, MACROBLOCK *x);
-
-#define MAXF(a,b)            (((a) > (b)) ? (a) : (b))
-
-typedef struct rate_distortion_struct
-{
-    int rate2;
-    int rate_y;
-    int rate_uv;
-    int distortion2;
-    int distortion_uv;
-} RATE_DISTORTION;
-
-typedef struct best_mode_struct
-{
-  int yrd;
-  int rd;
-  int intra_rd;
-  MB_MODE_INFO mbmode;
-  union b_mode_info bmodes[16];
-  PARTITION_INFO partition;
-} BEST_MODE;
-
-static const int auto_speed_thresh[17] =
-{
-    1000,
-    200,
-    150,
-    130,
-    150,
-    125,
-    120,
-    115,
-    115,
-    115,
-    115,
-    115,
-    115,
-    115,
-    115,
-    115,
-    105
-};
-
-const MB_PREDICTION_MODE vp8_mode_order[MAX_MODES] =
-{
-    ZEROMV,
-    DC_PRED,
-
-    NEARESTMV,
-    NEARMV,
-
-    ZEROMV,
-    NEARESTMV,
-
-    ZEROMV,
-    NEARESTMV,
-
-    NEARMV,
-    NEARMV,
-
-    V_PRED,
-    H_PRED,
-    TM_PRED,
-
-    NEWMV,
-    NEWMV,
-    NEWMV,
-
-    SPLITMV,
-    SPLITMV,
-    SPLITMV,
-
-    B_PRED,
-};
-
-/* This table determines the search order in reference frame priority order,
- * which may not necessarily match INTRA,LAST,GOLDEN,ARF
- */
-const int vp8_ref_frame_order[MAX_MODES] =
-{
-    1,
-    0,
-
-    1,
-    1,
-
-    2,
-    2,
-
-    3,
-    3,
-
-    2,
-    3,
-
-    0,
-    0,
-    0,
-
-    1,
-    2,
-    3,
-
-    1,
-    2,
-    3,
-
-    0,
-};
-
-static void fill_token_costs(
-    int c[BLOCK_TYPES][COEF_BANDS][PREV_COEF_CONTEXTS][MAX_ENTROPY_TOKENS],
-    const vp8_prob p[BLOCK_TYPES][COEF_BANDS][PREV_COEF_CONTEXTS][ENTROPY_NODES]
-)
-{
-    int i, j, k;
-
-
-    for (i = 0; i < BLOCK_TYPES; i++)
-        for (j = 0; j < COEF_BANDS; j++)
-            for (k = 0; k < PREV_COEF_CONTEXTS; k++)
-
-                /* check for pt=0 and band > 1 if block type 0
-                 * and 0 if blocktype 1
-                 */
-                if (k == 0 && j > (i == 0))
-                    vp8_cost_tokens2(c[i][j][k], p [i][j][k], vp8_coef_tree, 2);
-                else
-                    vp8_cost_tokens(c[i][j][k], p [i][j][k], vp8_coef_tree);
-}
-
-static const int rd_iifactor[32] =
-{
-    4, 4, 3, 2, 1, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0
-};
-
-/* values are now correlated to quantizer */
-static const int sad_per_bit16lut[QINDEX_RANGE] =
-{
-    2,  2,  2,  2,  2,  2,  2,  2,
-    2,  2,  2,  2,  2,  2,  2,  2,
-    3,  3,  3,  3,  3,  3,  3,  3,
-    3,  3,  3,  3,  3,  3,  4,  4,
-    4,  4,  4,  4,  4,  4,  4,  4,
-    4,  4,  5,  5,  5,  5,  5,  5,
-    5,  5,  5,  5,  5,  5,  6,  6,
-    6,  6,  6,  6,  6,  6,  6,  6,
-    6,  6,  7,  7,  7,  7,  7,  7,
-    7,  7,  7,  7,  7,  7,  8,  8,
-    8,  8,  8,  8,  8,  8,  8,  8,
-    8,  8,  9,  9,  9,  9,  9,  9,
-    9,  9,  9,  9,  9,  9,  10, 10,
-    10, 10, 10, 10, 10, 10, 11, 11,
-    11, 11, 11, 11, 12, 12, 12, 12,
-    12, 12, 13, 13, 13, 13, 14, 14
-};
-static const int sad_per_bit4lut[QINDEX_RANGE] =
-{
-    2,  2,  2,  2,  2,  2,  3,  3,
-    3,  3,  3,  3,  3,  3,  3,  3,
-    3,  3,  3,  3,  4,  4,  4,  4,
-    4,  4,  4,  4,  4,  4,  5,  5,
-    5,  5,  5,  5,  6,  6,  6,  6,
-    6,  6,  6,  6,  6,  6,  6,  6,
-    7,  7,  7,  7,  7,  7,  7,  7,
-    7,  7,  7,  7,  7,  8,  8,  8,
-    8,  8,  9,  9,  9,  9,  9,  9,
-    10, 10, 10, 10, 10, 10, 10, 10,
-    11, 11, 11, 11, 11, 11, 11, 11,
-    12, 12, 12, 12, 12, 12, 12, 12,
-    13, 13, 13, 13, 13, 13, 13, 14,
-    14, 14, 14, 14, 15, 15, 15, 15,
-    16, 16, 16, 16, 17, 17, 17, 18,
-    18, 18, 19, 19, 19, 20, 20, 20,
-};
-
-void vp8cx_initialize_me_consts(VP8_COMP *cpi, int QIndex)
-{
-    cpi->mb.sadperbit16 =  sad_per_bit16lut[QIndex];
-    cpi->mb.sadperbit4  =  sad_per_bit4lut[QIndex];
-}
-
-void vp8_initialize_rd_consts(VP8_COMP *cpi, MACROBLOCK *x, int Qvalue)
-{
-    int q;
-    int i;
-    double capped_q = (Qvalue < 160) ? (double)Qvalue : 160.0;
-    double rdconst = 2.80;
-
-    vp8_clear_system_state();
-
-    /* Further tests required to see if optimum is different
-     * for key frames, golden frames and arf frames.
-     */
-    cpi->RDMULT = (int)(rdconst * (capped_q * capped_q));
-
-    /* Extend rate multiplier along side quantizer zbin increases */
-    if (cpi->mb.zbin_over_quant  > 0)
-    {
-        double oq_factor;
-        double modq;
-
-        /* Experimental code using the same basic equation as used for Q above
-         * The units of cpi->mb.zbin_over_quant are 1/128 of Q bin size
-         */
-        oq_factor = 1.0 + ((double)0.0015625 * cpi->mb.zbin_over_quant);
-        modq = (int)((double)capped_q * oq_factor);
-        cpi->RDMULT = (int)(rdconst * (modq * modq));
-    }
-
-    if (cpi->pass == 2 && (cpi->common.frame_type != KEY_FRAME))
-    {
-        if (cpi->twopass.next_iiratio > 31)
-            cpi->RDMULT += (cpi->RDMULT * rd_iifactor[31]) >> 4;
-        else
-            cpi->RDMULT +=
-                (cpi->RDMULT * rd_iifactor[cpi->twopass.next_iiratio]) >> 4;
-    }
-
-    cpi->mb.errorperbit = (cpi->RDMULT / 110);
-    cpi->mb.errorperbit += (cpi->mb.errorperbit==0);
-
-    vp8_set_speed_features(cpi);
-
-    for (i = 0; i < MAX_MODES; i++)
-    {
-        x->mode_test_hit_counts[i] = 0;
-    }
-
-    q = (int)pow(Qvalue, 1.25);
-
-    if (q < 8)
-        q = 8;
-
-    if (cpi->RDMULT > 1000)
-    {
-        cpi->RDDIV = 1;
-        cpi->RDMULT /= 100;
-
-        for (i = 0; i < MAX_MODES; i++)
-        {
-            if (cpi->sf.thresh_mult[i] < INT_MAX)
-            {
-                x->rd_threshes[i] = cpi->sf.thresh_mult[i] * q / 100;
-            }
-            else
-            {
-                x->rd_threshes[i] = INT_MAX;
-            }
-
-            cpi->rd_baseline_thresh[i] = x->rd_threshes[i];
-        }
-    }
-    else
-    {
-        cpi->RDDIV = 100;
-
-        for (i = 0; i < MAX_MODES; i++)
-        {
-            if (cpi->sf.thresh_mult[i] < (INT_MAX / q))
-            {
-                x->rd_threshes[i] = cpi->sf.thresh_mult[i] * q;
-            }
-            else
-            {
-                x->rd_threshes[i] = INT_MAX;
-            }
-
-            cpi->rd_baseline_thresh[i] = x->rd_threshes[i];
-        }
-    }
-
-    {
-      /* build token cost array for the type of frame we have now */
-      FRAME_CONTEXT *l = &cpi->lfc_n;
-
-      if(cpi->common.refresh_alt_ref_frame)
-          l = &cpi->lfc_a;
-      else if(cpi->common.refresh_golden_frame)
-          l = &cpi->lfc_g;
-
-      fill_token_costs(
-          cpi->mb.token_costs,
-          (const vp8_prob( *)[8][3][11]) l->coef_probs
-      );
-      /*
-      fill_token_costs(
-          cpi->mb.token_costs,
-          (const vp8_prob( *)[8][3][11]) cpi->common.fc.coef_probs);
-      */
-
-
-      /* TODO make these mode costs depend on last,alt or gold too.  (jbb) */
-      vp8_init_mode_costs(cpi);
-    }
-
-}
-
-void vp8_auto_select_speed(VP8_COMP *cpi)
-{
-    int milliseconds_for_compress = (int)(1000000 / cpi->framerate);
-
-    milliseconds_for_compress = milliseconds_for_compress * (16 - cpi->oxcf.cpu_used) / 16;
-
-#if 0
-
-    if (0)
-    {
-        FILE *f;
-
-        f = fopen("speed.stt", "a");
-        fprintf(f, " %8ld %10ld %10ld %10ld\n",
-                cpi->common.current_video_frame, cpi->Speed, milliseconds_for_compress, cpi->avg_pick_mode_time);
-        fclose(f);
-    }
-
-#endif
-
-    if (cpi->avg_pick_mode_time < milliseconds_for_compress && (cpi->avg_encode_time - cpi->avg_pick_mode_time) < milliseconds_for_compress)
-    {
-        if (cpi->avg_pick_mode_time == 0)
-        {
-            cpi->Speed = 4;
-        }
-        else
-        {
-            if (milliseconds_for_compress * 100 < cpi->avg_encode_time * 95)
-            {
-                cpi->Speed          += 2;
-                cpi->avg_pick_mode_time = 0;
-                cpi->avg_encode_time = 0;
-
-                if (cpi->Speed > 16)
-                {
-                    cpi->Speed = 16;
-                }
-            }
-
-            if (milliseconds_for_compress * 100 > cpi->avg_encode_time * auto_speed_thresh[cpi->Speed])
-            {
-                cpi->Speed          -= 1;
-                cpi->avg_pick_mode_time = 0;
-                cpi->avg_encode_time = 0;
-
-                /* In real-time mode, cpi->speed is in [4, 16]. */
-                if (cpi->Speed < 4)
-                {
-                    cpi->Speed = 4;
-                }
-            }
-        }
-    }
-    else
-    {
-        cpi->Speed += 4;
-
-        if (cpi->Speed > 16)
-            cpi->Speed = 16;
-
-
-        cpi->avg_pick_mode_time = 0;
-        cpi->avg_encode_time = 0;
-    }
-}
-
-int vp8_block_error_c(short *coeff, short *dqcoeff)
-{
-    int i;
-    int error = 0;
-
-    for (i = 0; i < 16; i++)
-    {
-        int this_diff = coeff[i] - dqcoeff[i];
-        error += this_diff * this_diff;
-    }
-
-    return error;
-}
-
-int vp8_mbblock_error_c(MACROBLOCK *mb, int dc)
-{
-    BLOCK  *be;
-    BLOCKD *bd;
-    int i, j;
-    int berror, error = 0;
-
-    for (i = 0; i < 16; i++)
-    {
-        be = &mb->block[i];
-        bd = &mb->e_mbd.block[i];
-
-        berror = 0;
-
-        for (j = dc; j < 16; j++)
-        {
-            int this_diff = be->coeff[j] - bd->dqcoeff[j];
-            berror += this_diff * this_diff;
-        }
-
-        error += berror;
-    }
-
-    return error;
-}
-
-int vp8_mbuverror_c(MACROBLOCK *mb)
-{
-
-    BLOCK  *be;
-    BLOCKD *bd;
-
-
-    int i;
-    int error = 0;
-
-    for (i = 16; i < 24; i++)
-    {
-        be = &mb->block[i];
-        bd = &mb->e_mbd.block[i];
-
-        error += vp8_block_error_c(be->coeff, bd->dqcoeff);
-    }
-
-    return error;
-}
-
-int VP8_UVSSE(MACROBLOCK *x)
-{
-    unsigned char *uptr, *vptr;
-    unsigned char *upred_ptr = (*(x->block[16].base_src) + x->block[16].src);
-    unsigned char *vpred_ptr = (*(x->block[20].base_src) + x->block[20].src);
-    int uv_stride = x->block[16].src_stride;
-
-    unsigned int sse1 = 0;
-    unsigned int sse2 = 0;
-    int mv_row = x->e_mbd.mode_info_context->mbmi.mv.as_mv.row;
-    int mv_col = x->e_mbd.mode_info_context->mbmi.mv.as_mv.col;
-    int offset;
-    int pre_stride = x->e_mbd.pre.uv_stride;
-
-    if (mv_row < 0)
-        mv_row -= 1;
-    else
-        mv_row += 1;
-
-    if (mv_col < 0)
-        mv_col -= 1;
-    else
-        mv_col += 1;
-
-    mv_row /= 2;
-    mv_col /= 2;
-
-    offset = (mv_row >> 3) * pre_stride + (mv_col >> 3);
-    uptr = x->e_mbd.pre.u_buffer + offset;
-    vptr = x->e_mbd.pre.v_buffer + offset;
-
-    if ((mv_row | mv_col) & 7)
-    {
-        vpx_sub_pixel_variance8x8(uptr, pre_stride,
-            mv_col & 7, mv_row & 7, upred_ptr, uv_stride, &sse2);
-        vpx_sub_pixel_variance8x8(vptr, pre_stride,
-            mv_col & 7, mv_row & 7, vpred_ptr, uv_stride, &sse1);
-        sse2 += sse1;
-    }
-    else
-    {
-        vpx_variance8x8(uptr, pre_stride,
-            upred_ptr, uv_stride, &sse2);
-        vpx_variance8x8(vptr, pre_stride,
-            vpred_ptr, uv_stride, &sse1);
-        sse2 += sse1;
-    }
-    return sse2;
-
-}
-
-static int cost_coeffs(MACROBLOCK *mb, BLOCKD *b, int type, ENTROPY_CONTEXT *a, ENTROPY_CONTEXT *l)
-{
-    int c = !type;              /* start at coef 0, unless Y with Y2 */
-    int eob = (int)(*b->eob);
-    int pt ;    /* surrounding block/prev coef predictor */
-    int cost = 0;
-    short *qcoeff_ptr = b->qcoeff;
-
-    VP8_COMBINEENTROPYCONTEXTS(pt, *a, *l);
-
-    assert(eob <= 16);
-    for (; c < eob; c++)
-    {
-        const int v = qcoeff_ptr[vp8_default_zig_zag1d[c]];
-        const int t = vp8_dct_value_tokens_ptr[v].Token;
-        cost += mb->token_costs [type] [vp8_coef_bands[c]] [pt] [t];
-        cost += vp8_dct_value_cost_ptr[v];
-        pt = vp8_prev_token_class[t];
-    }
-
-    if (c < 16)
-        cost += mb->token_costs [type] [vp8_coef_bands[c]] [pt] [DCT_EOB_TOKEN];
-
-    pt = (c != !type); /* is eob first coefficient; */
-    *a = *l = pt;
-
-    return cost;
-}
-
-static int vp8_rdcost_mby(MACROBLOCK *mb)
-{
-    int cost = 0;
-    int b;
-    MACROBLOCKD *x = &mb->e_mbd;
-    ENTROPY_CONTEXT_PLANES t_above, t_left;
-    ENTROPY_CONTEXT *ta;
-    ENTROPY_CONTEXT *tl;
-
-    memcpy(&t_above, mb->e_mbd.above_context, sizeof(ENTROPY_CONTEXT_PLANES));
-    memcpy(&t_left, mb->e_mbd.left_context, sizeof(ENTROPY_CONTEXT_PLANES));
-
-    ta = (ENTROPY_CONTEXT *)&t_above;
-    tl = (ENTROPY_CONTEXT *)&t_left;
-
-    for (b = 0; b < 16; b++)
-        cost += cost_coeffs(mb, x->block + b, PLANE_TYPE_Y_NO_DC,
-                    ta + vp8_block2above[b], tl + vp8_block2left[b]);
-
-    cost += cost_coeffs(mb, x->block + 24, PLANE_TYPE_Y2,
-                ta + vp8_block2above[24], tl + vp8_block2left[24]);
-
-    return cost;
-}
-
-static void macro_block_yrd( MACROBLOCK *mb,
-                             int *Rate,
-                             int *Distortion)
-{
-    int b;
-    MACROBLOCKD *const x = &mb->e_mbd;
-    BLOCK   *const mb_y2 = mb->block + 24;
-    BLOCKD *const x_y2  = x->block + 24;
-    short *Y2DCPtr = mb_y2->src_diff;
-    BLOCK *beptr;
-    int d;
-
-    vp8_subtract_mby( mb->src_diff, *(mb->block[0].base_src),
-        mb->block[0].src_stride,  mb->e_mbd.predictor, 16);
-
-    /* Fdct and building the 2nd order block */
-    for (beptr = mb->block; beptr < mb->block + 16; beptr += 2)
-    {
-        mb->short_fdct8x4(beptr->src_diff, beptr->coeff, 32);
-        *Y2DCPtr++ = beptr->coeff[0];
-        *Y2DCPtr++ = beptr->coeff[16];
-    }
-
-    /* 2nd order fdct */
-    mb->short_walsh4x4(mb_y2->src_diff, mb_y2->coeff, 8);
-
-    /* Quantization */
-    for (b = 0; b < 16; b++)
-    {
-        mb->quantize_b(&mb->block[b], &mb->e_mbd.block[b]);
-    }
-
-    /* DC predication and Quantization of 2nd Order block */
-    mb->quantize_b(mb_y2, x_y2);
-
-    /* Distortion */
-    d = vp8_mbblock_error(mb, 1) << 2;
-    d += vp8_block_error(mb_y2->coeff, x_y2->dqcoeff);
-
-    *Distortion = (d >> 4);
-
-    /* rate */
-    *Rate = vp8_rdcost_mby(mb);
-}
-
-static void copy_predictor(unsigned char *dst, const unsigned char *predictor)
-{
-    const unsigned int *p = (const unsigned int *)predictor;
-    unsigned int *d = (unsigned int *)dst;
-    d[0] = p[0];
-    d[4] = p[4];
-    d[8] = p[8];
-    d[12] = p[12];
-}
-static int rd_pick_intra4x4block(
-    MACROBLOCK *x,
-    BLOCK *be,
-    BLOCKD *b,
-    B_PREDICTION_MODE *best_mode,
-    const int *bmode_costs,
-    ENTROPY_CONTEXT *a,
-    ENTROPY_CONTEXT *l,
-
-    int *bestrate,
-    int *bestratey,
-    int *bestdistortion)
-{
-    B_PREDICTION_MODE mode;
-    int best_rd = INT_MAX;
-    int rate = 0;
-    int distortion;
-
-    ENTROPY_CONTEXT ta = *a, tempa = *a;
-    ENTROPY_CONTEXT tl = *l, templ = *l;
-    /*
-     * The predictor buffer is a 2d buffer with a stride of 16.  Create
-     * a temp buffer that meets the stride requirements, but we are only
-     * interested in the left 4x4 block
-     * */
-    DECLARE_ALIGNED(16, unsigned char,  best_predictor[16*4]);
-    DECLARE_ALIGNED(16, short, best_dqcoeff[16]);
-    int dst_stride = x->e_mbd.dst.y_stride;
-    unsigned char *dst = x->e_mbd.dst.y_buffer + b->offset;
-
-    unsigned char *Above = dst - dst_stride;
-    unsigned char *yleft = dst - 1;
-    unsigned char top_left = Above[-1];
-
-    for (mode = B_DC_PRED; mode <= B_HU_PRED; mode++)
-    {
-        int this_rd;
-        int ratey;
-
-        rate = bmode_costs[mode];
-
-        vp8_intra4x4_predict(Above, yleft, dst_stride, mode,
-                             b->predictor, 16, top_left);
-        vp8_subtract_b(be, b, 16);
-        x->short_fdct4x4(be->src_diff, be->coeff, 32);
-        x->quantize_b(be, b);
-
-        tempa = ta;
-        templ = tl;
-
-        ratey = cost_coeffs(x, b, PLANE_TYPE_Y_WITH_DC, &tempa, &templ);
-        rate += ratey;
-        distortion = vp8_block_error(be->coeff, b->dqcoeff) >> 2;
-
-        this_rd = RDCOST(x->rdmult, x->rddiv, rate, distortion);
-
-        if (this_rd < best_rd)
-        {
-            *bestrate = rate;
-            *bestratey = ratey;
-            *bestdistortion = distortion;
-            best_rd = this_rd;
-            *best_mode = mode;
-            *a = tempa;
-            *l = templ;
-            copy_predictor(best_predictor, b->predictor);
-            memcpy(best_dqcoeff, b->dqcoeff, 32);
-        }
-    }
-    b->bmi.as_mode = *best_mode;
-
-    vp8_short_idct4x4llm(best_dqcoeff, best_predictor, 16, dst, dst_stride);
-
-    return best_rd;
-}
-
-static int rd_pick_intra4x4mby_modes(MACROBLOCK *mb, int *Rate,
-                                     int *rate_y, int *Distortion, int best_rd)
-{
-    MACROBLOCKD *const xd = &mb->e_mbd;
-    int i;
-    int cost = mb->mbmode_cost [xd->frame_type] [B_PRED];
-    int distortion = 0;
-    int tot_rate_y = 0;
-    int64_t total_rd = 0;
-    ENTROPY_CONTEXT_PLANES t_above, t_left;
-    ENTROPY_CONTEXT *ta;
-    ENTROPY_CONTEXT *tl;
-    const int *bmode_costs;
-
-    memcpy(&t_above, mb->e_mbd.above_context, sizeof(ENTROPY_CONTEXT_PLANES));
-    memcpy(&t_left, mb->e_mbd.left_context, sizeof(ENTROPY_CONTEXT_PLANES));
-
-    ta = (ENTROPY_CONTEXT *)&t_above;
-    tl = (ENTROPY_CONTEXT *)&t_left;
-
-    intra_prediction_down_copy(xd, xd->dst.y_buffer - xd->dst.y_stride + 16);
-
-    bmode_costs = mb->inter_bmode_costs;
-
-    for (i = 0; i < 16; i++)
-    {
-        MODE_INFO *const mic = xd->mode_info_context;
-        const int mis = xd->mode_info_stride;
-        B_PREDICTION_MODE UNINITIALIZED_IS_SAFE(best_mode);
-        int UNINITIALIZED_IS_SAFE(r), UNINITIALIZED_IS_SAFE(ry), UNINITIALIZED_IS_SAFE(d);
-
-        if (mb->e_mbd.frame_type == KEY_FRAME)
-        {
-            const B_PREDICTION_MODE A = above_block_mode(mic, i, mis);
-            const B_PREDICTION_MODE L = left_block_mode(mic, i);
-
-            bmode_costs  = mb->bmode_costs[A][L];
-        }
-
-        total_rd += rd_pick_intra4x4block(
-            mb, mb->block + i, xd->block + i, &best_mode, bmode_costs,
-            ta + vp8_block2above[i],
-            tl + vp8_block2left[i], &r, &ry, &d);
-
-        cost += r;
-        distortion += d;
-        tot_rate_y += ry;
-
-        mic->bmi[i].as_mode = best_mode;
-
-        if(total_rd >= (int64_t)best_rd)
-            break;
-    }
-
-    if(total_rd >= (int64_t)best_rd)
-        return INT_MAX;
-
-    *Rate = cost;
-    *rate_y = tot_rate_y;
-    *Distortion = distortion;
-
-    return RDCOST(mb->rdmult, mb->rddiv, cost, distortion);
-}
-
-
-static int rd_pick_intra16x16mby_mode(MACROBLOCK *x,
-                                      int *Rate,
-                                      int *rate_y,
-                                      int *Distortion)
-{
-    MB_PREDICTION_MODE mode;
-    MB_PREDICTION_MODE UNINITIALIZED_IS_SAFE(mode_selected);
-    int rate, ratey;
-    int distortion;
-    int best_rd = INT_MAX;
-    int this_rd;
-    MACROBLOCKD *xd = &x->e_mbd;
-
-    /* Y Search for 16x16 intra prediction mode */
-    for (mode = DC_PRED; mode <= TM_PRED; mode++)
-    {
-        xd->mode_info_context->mbmi.mode = mode;
-
-        vp8_build_intra_predictors_mby_s(xd,
-                                         xd->dst.y_buffer - xd->dst.y_stride,
-                                         xd->dst.y_buffer - 1,
-                                         xd->dst.y_stride,
-                                         xd->predictor,
-                                         16);
-
-        macro_block_yrd(x, &ratey, &distortion);
-        rate = ratey + x->mbmode_cost[xd->frame_type]
-                                     [xd->mode_info_context->mbmi.mode];
-
-        this_rd = RDCOST(x->rdmult, x->rddiv, rate, distortion);
-
-        if (this_rd < best_rd)
-        {
-            mode_selected = mode;
-            best_rd = this_rd;
-            *Rate = rate;
-            *rate_y = ratey;
-            *Distortion = distortion;
-        }
-    }
-
-    xd->mode_info_context->mbmi.mode = mode_selected;
-    return best_rd;
-}
-
-static int rd_cost_mbuv(MACROBLOCK *mb)
-{
-    int b;
-    int cost = 0;
-    MACROBLOCKD *x = &mb->e_mbd;
-    ENTROPY_CONTEXT_PLANES t_above, t_left;
-    ENTROPY_CONTEXT *ta;
-    ENTROPY_CONTEXT *tl;
-
-    memcpy(&t_above, mb->e_mbd.above_context, sizeof(ENTROPY_CONTEXT_PLANES));
-    memcpy(&t_left, mb->e_mbd.left_context, sizeof(ENTROPY_CONTEXT_PLANES));
-
-    ta = (ENTROPY_CONTEXT *)&t_above;
-    tl = (ENTROPY_CONTEXT *)&t_left;
-
-    for (b = 16; b < 24; b++)
-        cost += cost_coeffs(mb, x->block + b, PLANE_TYPE_UV,
-                    ta + vp8_block2above[b], tl + vp8_block2left[b]);
-
-    return cost;
-}
-
-
-static int rd_inter16x16_uv(VP8_COMP *cpi, MACROBLOCK *x, int *rate,
-                            int *distortion, int fullpixel)
-{
-    (void)cpi;
-    (void)fullpixel;
-
-    vp8_build_inter16x16_predictors_mbuv(&x->e_mbd);
-    vp8_subtract_mbuv(x->src_diff,
-        x->src.u_buffer, x->src.v_buffer, x->src.uv_stride,
-        &x->e_mbd.predictor[256], &x->e_mbd.predictor[320], 8);
-
-    vp8_transform_mbuv(x);
-    vp8_quantize_mbuv(x);
-
-    *rate       = rd_cost_mbuv(x);
-    *distortion = vp8_mbuverror(x) / 4;
-
-    return RDCOST(x->rdmult, x->rddiv, *rate, *distortion);
-}
-
-static int rd_inter4x4_uv(VP8_COMP *cpi, MACROBLOCK *x, int *rate,
-                          int *distortion, int fullpixel)
-{
-    (void)cpi;
-    (void)fullpixel;
-
-    vp8_build_inter4x4_predictors_mbuv(&x->e_mbd);
-    vp8_subtract_mbuv(x->src_diff,
-        x->src.u_buffer, x->src.v_buffer, x->src.uv_stride,
-        &x->e_mbd.predictor[256], &x->e_mbd.predictor[320], 8);
-
-    vp8_transform_mbuv(x);
-    vp8_quantize_mbuv(x);
-
-    *rate       = rd_cost_mbuv(x);
-    *distortion = vp8_mbuverror(x) / 4;
-
-    return RDCOST(x->rdmult, x->rddiv, *rate, *distortion);
-}
-
-static void rd_pick_intra_mbuv_mode(MACROBLOCK *x, int *rate,
-                                    int *rate_tokenonly, int *distortion)
-{
-    MB_PREDICTION_MODE mode;
-    MB_PREDICTION_MODE UNINITIALIZED_IS_SAFE(mode_selected);
-    int best_rd = INT_MAX;
-    int UNINITIALIZED_IS_SAFE(d), UNINITIALIZED_IS_SAFE(r);
-    int rate_to;
-    MACROBLOCKD *xd = &x->e_mbd;
-
-    for (mode = DC_PRED; mode <= TM_PRED; mode++)
-    {
-        int this_rate;
-        int this_distortion;
-        int this_rd;
-
-        xd->mode_info_context->mbmi.uv_mode = mode;
-
-        vp8_build_intra_predictors_mbuv_s(xd,
-                                          xd->dst.u_buffer - xd->dst.uv_stride,
-                                          xd->dst.v_buffer - xd->dst.uv_stride,
-                                          xd->dst.u_buffer - 1,
-                                          xd->dst.v_buffer - 1,
-                                          xd->dst.uv_stride,
-                                          &xd->predictor[256], &xd->predictor[320],
-                                          8);
-
-
-        vp8_subtract_mbuv(x->src_diff,
-                      x->src.u_buffer, x->src.v_buffer, x->src.uv_stride,
-                      &xd->predictor[256], &xd->predictor[320], 8);
-        vp8_transform_mbuv(x);
-        vp8_quantize_mbuv(x);
-
-        rate_to = rd_cost_mbuv(x);
-        this_rate = rate_to + x->intra_uv_mode_cost[xd->frame_type][xd->mode_info_context->mbmi.uv_mode];
-
-        this_distortion = vp8_mbuverror(x) / 4;
-
-        this_rd = RDCOST(x->rdmult, x->rddiv, this_rate, this_distortion);
-
-        if (this_rd < best_rd)
-        {
-            best_rd = this_rd;
-            d = this_distortion;
-            r = this_rate;
-            *rate_tokenonly = rate_to;
-            mode_selected = mode;
-        }
-    }
-
-    *rate = r;
-    *distortion = d;
-
-    xd->mode_info_context->mbmi.uv_mode = mode_selected;
-}
-
-int vp8_cost_mv_ref(MB_PREDICTION_MODE m, const int near_mv_ref_ct[4])
-{
-    vp8_prob p [VP8_MVREFS-1];
-    assert(NEARESTMV <= m  &&  m <= SPLITMV);
-    vp8_mv_ref_probs(p, near_mv_ref_ct);
-    return vp8_cost_token(vp8_mv_ref_tree, p,
-                          vp8_mv_ref_encoding_array + (m - NEARESTMV));
-}
-
-void vp8_set_mbmode_and_mvs(MACROBLOCK *x, MB_PREDICTION_MODE mb, int_mv *mv)
-{
-    x->e_mbd.mode_info_context->mbmi.mode = mb;
-    x->e_mbd.mode_info_context->mbmi.mv.as_int = mv->as_int;
-}
-
-static int labels2mode(
-    MACROBLOCK *x,
-    int const *labelings, int which_label,
-    B_PREDICTION_MODE this_mode,
-    int_mv *this_mv, int_mv *best_ref_mv,
-    int *mvcost[2]
-)
-{
-    MACROBLOCKD *const xd = & x->e_mbd;
-    MODE_INFO *const mic = xd->mode_info_context;
-    const int mis = xd->mode_info_stride;
-
-    int cost = 0;
-    int thismvcost = 0;
-
-    /* We have to be careful retrieving previously-encoded motion vectors.
-       Ones from this macroblock have to be pulled from the BLOCKD array
-       as they have not yet made it to the bmi array in our MB_MODE_INFO. */
-
-    int i = 0;
-
-    do
-    {
-        BLOCKD *const d = xd->block + i;
-        const int row = i >> 2,  col = i & 3;
-
-        B_PREDICTION_MODE m;
-
-        if (labelings[i] != which_label)
-            continue;
-
-        if (col  &&  labelings[i] == labelings[i-1])
-            m = LEFT4X4;
-        else if (row  &&  labelings[i] == labelings[i-4])
-            m = ABOVE4X4;
-        else
-        {
-            /* the only time we should do costing for new motion vector
-             * or mode is when we are on a new label  (jbb May 08, 2007)
-             */
-            switch (m = this_mode)
-            {
-            case NEW4X4 :
-                thismvcost  = vp8_mv_bit_cost(this_mv, best_ref_mv, mvcost, 102);
-                break;
-            case LEFT4X4:
-                this_mv->as_int = col ? d[-1].bmi.mv.as_int : left_block_mv(mic, i);
-                break;
-            case ABOVE4X4:
-                this_mv->as_int = row ? d[-4].bmi.mv.as_int : above_block_mv(mic, i, mis);
-                break;
-            case ZERO4X4:
-                this_mv->as_int = 0;
-                break;
-            default:
-                break;
-            }
-
-            if (m == ABOVE4X4)  /* replace above with left if same */
-            {
-                int_mv left_mv;
-
-                left_mv.as_int = col ? d[-1].bmi.mv.as_int :
-                                        left_block_mv(mic, i);
-
-                if (left_mv.as_int == this_mv->as_int)
-                    m = LEFT4X4;
-            }
-
-            cost = x->inter_bmode_costs[ m];
-        }
-
-        d->bmi.mv.as_int = this_mv->as_int;
-
-        x->partition_info->bmi[i].mode = m;
-        x->partition_info->bmi[i].mv.as_int = this_mv->as_int;
-
-    }
-    while (++i < 16);
-
-    cost += thismvcost ;
-    return cost;
-}
-
-static int rdcost_mbsegment_y(MACROBLOCK *mb, const int *labels,
-                              int which_label, ENTROPY_CONTEXT *ta,
-                              ENTROPY_CONTEXT *tl)
-{
-    int cost = 0;
-    int b;
-    MACROBLOCKD *x = &mb->e_mbd;
-
-    for (b = 0; b < 16; b++)
-        if (labels[ b] == which_label)
-            cost += cost_coeffs(mb, x->block + b, PLANE_TYPE_Y_WITH_DC,
-                                ta + vp8_block2above[b],
-                                tl + vp8_block2left[b]);
-
-    return cost;
-
-}
-static unsigned int vp8_encode_inter_mb_segment(MACROBLOCK *x, int const *labels, int which_label)
-{
-    int i;
-    unsigned int distortion = 0;
-    int pre_stride = x->e_mbd.pre.y_stride;
-    unsigned char *base_pre = x->e_mbd.pre.y_buffer;
-
-
-    for (i = 0; i < 16; i++)
-    {
-        if (labels[i] == which_label)
-        {
-            BLOCKD *bd = &x->e_mbd.block[i];
-            BLOCK *be = &x->block[i];
-
-            vp8_build_inter_predictors_b(bd, 16, base_pre, pre_stride, x->e_mbd.subpixel_predict);
-            vp8_subtract_b(be, bd, 16);
-            x->short_fdct4x4(be->src_diff, be->coeff, 32);
-            x->quantize_b(be, bd);
-
-            distortion += vp8_block_error(be->coeff, bd->dqcoeff);
-        }
-    }
-
-    return distortion;
-}
-
-
-static const unsigned int segmentation_to_sseshift[4] = {3, 3, 2, 0};
-
-
-typedef struct
-{
-  int_mv *ref_mv;
-  int_mv mvp;
-
-  int segment_rd;
-  int segment_num;
-  int r;
-  int d;
-  int segment_yrate;
-  B_PREDICTION_MODE modes[16];
-  int_mv mvs[16];
-  unsigned char eobs[16];
-
-  int mvthresh;
-  int *mdcounts;
-
-  int_mv sv_mvp[4]; /* save 4 mvp from 8x8 */
-  int sv_istep[2];  /* save 2 initial step_param for 16x8/8x16 */
-
-} BEST_SEG_INFO;
-
-
-static void rd_check_segment(VP8_COMP *cpi, MACROBLOCK *x,
-                             BEST_SEG_INFO *bsi, unsigned int segmentation)
-{
-    int i;
-    int const *labels;
-    int br = 0;
-    int bd = 0;
-    B_PREDICTION_MODE this_mode;
-
-
-    int label_count;
-    int this_segment_rd = 0;
-    int label_mv_thresh;
-    int rate = 0;
-    int sbr = 0;
-    int sbd = 0;
-    int segmentyrate = 0;
-
-    vp8_variance_fn_ptr_t *v_fn_ptr;
-
-    ENTROPY_CONTEXT_PLANES t_above, t_left;
-    ENTROPY_CONTEXT *ta;
-    ENTROPY_CONTEXT *tl;
-    ENTROPY_CONTEXT_PLANES t_above_b, t_left_b;
-    ENTROPY_CONTEXT *ta_b;
-    ENTROPY_CONTEXT *tl_b;
-
-    memcpy(&t_above, x->e_mbd.above_context, sizeof(ENTROPY_CONTEXT_PLANES));
-    memcpy(&t_left, x->e_mbd.left_context, sizeof(ENTROPY_CONTEXT_PLANES));
-
-    ta = (ENTROPY_CONTEXT *)&t_above;
-    tl = (ENTROPY_CONTEXT *)&t_left;
-    ta_b = (ENTROPY_CONTEXT *)&t_above_b;
-    tl_b = (ENTROPY_CONTEXT *)&t_left_b;
-
-    br = 0;
-    bd = 0;
-
-    v_fn_ptr = &cpi->fn_ptr[segmentation];
-    labels = vp8_mbsplits[segmentation];
-    label_count = vp8_mbsplit_count[segmentation];
-
-    /* 64 makes this threshold really big effectively making it so that we
-     * very rarely check mvs on segments.   setting this to 1 would make mv
-     * thresh roughly equal to what it is for macroblocks
-     */
-    label_mv_thresh = 1 * bsi->mvthresh / label_count ;
-
-    /* Segmentation method overheads */
-    rate = vp8_cost_token(vp8_mbsplit_tree, vp8_mbsplit_probs, vp8_mbsplit_encodings + segmentation);
-    rate += vp8_cost_mv_ref(SPLITMV, bsi->mdcounts);
-    this_segment_rd += RDCOST(x->rdmult, x->rddiv, rate, 0);
-    br += rate;
-
-    for (i = 0; i < label_count; i++)
-    {
-        int_mv mode_mv[B_MODE_COUNT];
-        int best_label_rd = INT_MAX;
-        B_PREDICTION_MODE mode_selected = ZERO4X4;
-        int bestlabelyrate = 0;
-
-        /* search for the best motion vector on this segment */
-        for (this_mode = LEFT4X4; this_mode <= NEW4X4 ; this_mode ++)
-        {
-            int this_rd;
-            int distortion;
-            int labelyrate;
-            ENTROPY_CONTEXT_PLANES t_above_s, t_left_s;
-            ENTROPY_CONTEXT *ta_s;
-            ENTROPY_CONTEXT *tl_s;
-
-            memcpy(&t_above_s, &t_above, sizeof(ENTROPY_CONTEXT_PLANES));
-            memcpy(&t_left_s, &t_left, sizeof(ENTROPY_CONTEXT_PLANES));
-
-            ta_s = (ENTROPY_CONTEXT *)&t_above_s;
-            tl_s = (ENTROPY_CONTEXT *)&t_left_s;
-
-            if (this_mode == NEW4X4)
-            {
-                int sseshift;
-                int num00;
-                int step_param = 0;
-                int further_steps;
-                int n;
-                int thissme;
-                int bestsme = INT_MAX;
-                int_mv  temp_mv;
-                BLOCK *c;
-                BLOCKD *e;
-
-                /* Is the best so far sufficiently good that we cant justify
-                 * doing a new motion search.
-                 */
-                if (best_label_rd < label_mv_thresh)
-                    break;
-
-                if(cpi->compressor_speed)
-                {
-                    if (segmentation == BLOCK_8X16 || segmentation == BLOCK_16X8)
-                    {
-                        bsi->mvp.as_int = bsi->sv_mvp[i].as_int;
-                        if (i==1 && segmentation == BLOCK_16X8)
-                          bsi->mvp.as_int = bsi->sv_mvp[2].as_int;
-
-                        step_param = bsi->sv_istep[i];
-                    }
-
-                    /* use previous block's result as next block's MV
-                     * predictor.
-                     */
-                    if (segmentation == BLOCK_4X4 && i>0)
-                    {
-                        bsi->mvp.as_int = x->e_mbd.block[i-1].bmi.mv.as_int;
-                        if (i==4 || i==8 || i==12)
-                            bsi->mvp.as_int = x->e_mbd.block[i-4].bmi.mv.as_int;
-                        step_param = 2;
-                    }
-                }
-
-                further_steps = (MAX_MVSEARCH_STEPS - 1) - step_param;
-
-                {
-                    int sadpb = x->sadperbit4;
-                    int_mv mvp_full;
-
-                    mvp_full.as_mv.row = bsi->mvp.as_mv.row >>3;
-                    mvp_full.as_mv.col = bsi->mvp.as_mv.col >>3;
-
-                    /* find first label */
-                    n = vp8_mbsplit_offset[segmentation][i];
-
-                    c = &x->block[n];
-                    e = &x->e_mbd.block[n];
-
-                    {
-                        bestsme = cpi->diamond_search_sad(x, c, e, &mvp_full,
-                                                &mode_mv[NEW4X4], step_param,
-                                                sadpb, &num00, v_fn_ptr,
-                                                x->mvcost, bsi->ref_mv);
-
-                        n = num00;
-                        num00 = 0;
-
-                        while (n < further_steps)
-                        {
-                            n++;
-
-                            if (num00)
-                                num00--;
-                            else
-                            {
-                                thissme = cpi->diamond_search_sad(x, c, e,
-                                                    &mvp_full, &temp_mv,
-                                                    step_param + n, sadpb,
-                                                    &num00, v_fn_ptr,
-                                                    x->mvcost, bsi->ref_mv);
-
-                                if (thissme < bestsme)
-                                {
-                                    bestsme = thissme;
-                                    mode_mv[NEW4X4].as_int = temp_mv.as_int;
-                                }
-                            }
-                        }
-                    }
-
-                    sseshift = segmentation_to_sseshift[segmentation];
-
-                    /* Should we do a full search (best quality only) */
-                    if ((cpi->compressor_speed == 0) && (bestsme >> sseshift) > 4000)
-                    {
-                        /* Check if mvp_full is within the range. */
-                        vp8_clamp_mv(&mvp_full, x->mv_col_min, x->mv_col_max, x->mv_row_min, x->mv_row_max);
-
-                        thissme = cpi->full_search_sad(x, c, e, &mvp_full,
-                                                       sadpb, 16, v_fn_ptr,
-                                                       x->mvcost, bsi->ref_mv);
-
-                        if (thissme < bestsme)
-                        {
-                            bestsme = thissme;
-                            mode_mv[NEW4X4].as_int = e->bmi.mv.as_int;
-                        }
-                        else
-                        {
-                            /* The full search result is actually worse so
-                             * re-instate the previous best vector
-                             */
-                            e->bmi.mv.as_int = mode_mv[NEW4X4].as_int;
-                        }
-                    }
-                }
-
-                if (bestsme < INT_MAX)
-                {
-                    int disto;
-                    unsigned int sse;
-                    cpi->find_fractional_mv_step(x, c, e, &mode_mv[NEW4X4],
-                        bsi->ref_mv, x->errorperbit, v_fn_ptr, x->mvcost,
-                        &disto, &sse);
-                }
-            } /* NEW4X4 */
-
-            rate = labels2mode(x, labels, i, this_mode, &mode_mv[this_mode],
-                               bsi->ref_mv, x->mvcost);
-
-            /* Trap vectors that reach beyond the UMV borders */
-            if (((mode_mv[this_mode].as_mv.row >> 3) < x->mv_row_min) || ((mode_mv[this_mode].as_mv.row >> 3) > x->mv_row_max) ||
-                ((mode_mv[this_mode].as_mv.col >> 3) < x->mv_col_min) || ((mode_mv[this_mode].as_mv.col >> 3) > x->mv_col_max))
-            {
-                continue;
-            }
-
-            distortion = vp8_encode_inter_mb_segment(x, labels, i) / 4;
-
-            labelyrate = rdcost_mbsegment_y(x, labels, i, ta_s, tl_s);
-            rate += labelyrate;
-
-            this_rd = RDCOST(x->rdmult, x->rddiv, rate, distortion);
-
-            if (this_rd < best_label_rd)
-            {
-                sbr = rate;
-                sbd = distortion;
-                bestlabelyrate = labelyrate;
-                mode_selected = this_mode;
-                best_label_rd = this_rd;
-
-                memcpy(ta_b, ta_s, sizeof(ENTROPY_CONTEXT_PLANES));
-                memcpy(tl_b, tl_s, sizeof(ENTROPY_CONTEXT_PLANES));
-
-            }
-        } /*for each 4x4 mode*/
-
-        memcpy(ta, ta_b, sizeof(ENTROPY_CONTEXT_PLANES));
-        memcpy(tl, tl_b, sizeof(ENTROPY_CONTEXT_PLANES));
-
-        labels2mode(x, labels, i, mode_selected, &mode_mv[mode_selected],
-                    bsi->ref_mv, x->mvcost);
-
-        br += sbr;
-        bd += sbd;
-        segmentyrate += bestlabelyrate;
-        this_segment_rd += best_label_rd;
-
-        if (this_segment_rd >= bsi->segment_rd)
-            break;
-
-    } /* for each label */
-
-    if (this_segment_rd < bsi->segment_rd)
-    {
-        bsi->r = br;
-        bsi->d = bd;
-        bsi->segment_yrate = segmentyrate;
-        bsi->segment_rd = this_segment_rd;
-        bsi->segment_num = segmentation;
-
-        /* store everything needed to come back to this!! */
-        for (i = 0; i < 16; i++)
-        {
-            bsi->mvs[i].as_mv = x->partition_info->bmi[i].mv.as_mv;
-            bsi->modes[i] = x->partition_info->bmi[i].mode;
-            bsi->eobs[i] = x->e_mbd.eobs[i];
-        }
-    }
-}
-
-static
-void vp8_cal_step_param(int sr, int *sp)
-{
-    int step = 0;
-
-    if (sr > MAX_FIRST_STEP) sr = MAX_FIRST_STEP;
-    else if (sr < 1) sr = 1;
-
-    while (sr>>=1)
-        step++;
-
-    *sp = MAX_MVSEARCH_STEPS - 1 - step;
-}
-
-static int vp8_rd_pick_best_mbsegmentation(VP8_COMP *cpi, MACROBLOCK *x,
-                                           int_mv *best_ref_mv, int best_rd,
-                                           int *mdcounts, int *returntotrate,
-                                           int *returnyrate, int *returndistortion,
-                                           int mvthresh)
-{
-    int i;
-    BEST_SEG_INFO bsi;
-
-    memset(&bsi, 0, sizeof(bsi));
-
-    bsi.segment_rd = best_rd;
-    bsi.ref_mv = best_ref_mv;
-    bsi.mvp.as_int = best_ref_mv->as_int;
-    bsi.mvthresh = mvthresh;
-    bsi.mdcounts = mdcounts;
-
-    for(i = 0; i < 16; i++)
-    {
-        bsi.modes[i] = ZERO4X4;
-    }
-
-    if(cpi->compressor_speed == 0)
-    {
-        /* for now, we will keep the original segmentation order
-           when in best quality mode */
-        rd_check_segment(cpi, x, &bsi, BLOCK_16X8);
-        rd_check_segment(cpi, x, &bsi, BLOCK_8X16);
-        rd_check_segment(cpi, x, &bsi, BLOCK_8X8);
-        rd_check_segment(cpi, x, &bsi, BLOCK_4X4);
-    }
-    else
-    {
-        int sr;
-
-        rd_check_segment(cpi, x, &bsi, BLOCK_8X8);
-
-        if (bsi.segment_rd < best_rd)
-        {
-            int col_min = ((best_ref_mv->as_mv.col+7)>>3) - MAX_FULL_PEL_VAL;
-            int row_min = ((best_ref_mv->as_mv.row+7)>>3) - MAX_FULL_PEL_VAL;
-            int col_max = (best_ref_mv->as_mv.col>>3) + MAX_FULL_PEL_VAL;
-            int row_max = (best_ref_mv->as_mv.row>>3) + MAX_FULL_PEL_VAL;
-
-            int tmp_col_min = x->mv_col_min;
-            int tmp_col_max = x->mv_col_max;
-            int tmp_row_min = x->mv_row_min;
-            int tmp_row_max = x->mv_row_max;
-
-            /* Get intersection of UMV window and valid MV window to reduce # of checks in diamond search. */
-            if (x->mv_col_min < col_min )
-                x->mv_col_min = col_min;
-            if (x->mv_col_max > col_max )
-                x->mv_col_max = col_max;
-            if (x->mv_row_min < row_min )
-                x->mv_row_min = row_min;
-            if (x->mv_row_max > row_max )
-                x->mv_row_max = row_max;
-
-            /* Get 8x8 result */
-            bsi.sv_mvp[0].as_int = bsi.mvs[0].as_int;
-            bsi.sv_mvp[1].as_int = bsi.mvs[2].as_int;
-            bsi.sv_mvp[2].as_int = bsi.mvs[8].as_int;
-            bsi.sv_mvp[3].as_int = bsi.mvs[10].as_int;
-
-            /* Use 8x8 result as 16x8/8x16's predictor MV. Adjust search range according to the closeness of 2 MV. */
-            /* block 8X16 */
-            {
-                sr = MAXF((abs(bsi.sv_mvp[0].as_mv.row - bsi.sv_mvp[2].as_mv.row))>>3, (abs(bsi.sv_mvp[0].as_mv.col - bsi.sv_mvp[2].as_mv.col))>>3);
-                vp8_cal_step_param(sr, &bsi.sv_istep[0]);
-
-                sr = MAXF((abs(bsi.sv_mvp[1].as_mv.row - bsi.sv_mvp[3].as_mv.row))>>3, (abs(bsi.sv_mvp[1].as_mv.col - bsi.sv_mvp[3].as_mv.col))>>3);
-                vp8_cal_step_param(sr, &bsi.sv_istep[1]);
-
-                rd_check_segment(cpi, x, &bsi, BLOCK_8X16);
-            }
-
-            /* block 16X8 */
-            {
-                sr = MAXF((abs(bsi.sv_mvp[0].as_mv.row - bsi.sv_mvp[1].as_mv.row))>>3, (abs(bsi.sv_mvp[0].as_mv.col - bsi.sv_mvp[1].as_mv.col))>>3);
-                vp8_cal_step_param(sr, &bsi.sv_istep[0]);
-
-                sr = MAXF((abs(bsi.sv_mvp[2].as_mv.row - bsi.sv_mvp[3].as_mv.row))>>3, (abs(bsi.sv_mvp[2].as_mv.col - bsi.sv_mvp[3].as_mv.col))>>3);
-                vp8_cal_step_param(sr, &bsi.sv_istep[1]);
-
-                rd_check_segment(cpi, x, &bsi, BLOCK_16X8);
-            }
-
-            /* If 8x8 is better than 16x8/8x16, then do 4x4 search */
-            /* Not skip 4x4 if speed=0 (good quality) */
-            if (cpi->sf.no_skip_block4x4_search || bsi.segment_num == BLOCK_8X8)  /* || (sv_segment_rd8x8-bsi.segment_rd) < sv_segment_rd8x8>>5) */
-            {
-                bsi.mvp.as_int = bsi.sv_mvp[0].as_int;
-                rd_check_segment(cpi, x, &bsi, BLOCK_4X4);
-            }
-
-            /* restore UMV window */
-            x->mv_col_min = tmp_col_min;
-            x->mv_col_max = tmp_col_max;
-            x->mv_row_min = tmp_row_min;
-            x->mv_row_max = tmp_row_max;
-        }
-    }
-
-    /* set it to the best */
-    for (i = 0; i < 16; i++)
-    {
-        BLOCKD *bd = &x->e_mbd.block[i];
-
-        bd->bmi.mv.as_int = bsi.mvs[i].as_int;
-        *bd->eob = bsi.eobs[i];
-    }
-
-    *returntotrate = bsi.r;
-    *returndistortion = bsi.d;
-    *returnyrate = bsi.segment_yrate;
-
-    /* save partitions */
-    x->e_mbd.mode_info_context->mbmi.partitioning = bsi.segment_num;
-    x->partition_info->count = vp8_mbsplit_count[bsi.segment_num];
-
-    for (i = 0; i < x->partition_info->count; i++)
-    {
-        int j;
-
-        j = vp8_mbsplit_offset[bsi.segment_num][i];
-
-        x->partition_info->bmi[i].mode = bsi.modes[j];
-        x->partition_info->bmi[i].mv.as_mv = bsi.mvs[j].as_mv;
-    }
-    /*
-     * used to set x->e_mbd.mode_info_context->mbmi.mv.as_int
-     */
-    x->partition_info->bmi[15].mv.as_int = bsi.mvs[15].as_int;
-
-    return bsi.segment_rd;
-}
-
-/* The improved MV prediction */
-void vp8_mv_pred
-(
-    VP8_COMP *cpi,
-    MACROBLOCKD *xd,
-    const MODE_INFO *here,
-    int_mv *mvp,
-    int refframe,
-    int *ref_frame_sign_bias,
-    int *sr,
-    int near_sadidx[]
-)
-{
-    const MODE_INFO *above = here - xd->mode_info_stride;
-    const MODE_INFO *left = here - 1;
-    const MODE_INFO *aboveleft = above - 1;
-    int_mv           near_mvs[8];
-    int              near_ref[8];
-    int_mv           mv;
-    int              vcnt=0;
-    int              find=0;
-    int              mb_offset;
-
-    int              mvx[8];
-    int              mvy[8];
-    int              i;
-
-    mv.as_int = 0;
-
-    if(here->mbmi.ref_frame != INTRA_FRAME)
-    {
-        near_mvs[0].as_int = near_mvs[1].as_int = near_mvs[2].as_int = near_mvs[3].as_int = near_mvs[4].as_int = near_mvs[5].as_int = near_mvs[6].as_int = near_mvs[7].as_int = 0;
-        near_ref[0] = near_ref[1] = near_ref[2] = near_ref[3] = near_ref[4] = near_ref[5] = near_ref[6] = near_ref[7] = 0;
-
-        /* read in 3 nearby block's MVs from current frame as prediction
-         * candidates.
-         */
-        if (above->mbmi.ref_frame != INTRA_FRAME)
-        {
-            near_mvs[vcnt].as_int = above->mbmi.mv.as_int;
-            mv_bias(ref_frame_sign_bias[above->mbmi.ref_frame], refframe, &near_mvs[vcnt], ref_frame_sign_bias);
-            near_ref[vcnt] =  above->mbmi.ref_frame;
-        }
-        vcnt++;
-        if (left->mbmi.ref_frame != INTRA_FRAME)
-        {
-            near_mvs[vcnt].as_int = left->mbmi.mv.as_int;
-            mv_bias(ref_frame_sign_bias[left->mbmi.ref_frame], refframe, &near_mvs[vcnt], ref_frame_sign_bias);
-            near_ref[vcnt] =  left->mbmi.ref_frame;
-        }
-        vcnt++;
-        if (aboveleft->mbmi.ref_frame != INTRA_FRAME)
-        {
-            near_mvs[vcnt].as_int = aboveleft->mbmi.mv.as_int;
-            mv_bias(ref_frame_sign_bias[aboveleft->mbmi.ref_frame], refframe, &near_mvs[vcnt], ref_frame_sign_bias);
-            near_ref[vcnt] =  aboveleft->mbmi.ref_frame;
-        }
-        vcnt++;
-
-        /* read in 5 nearby block's MVs from last frame. */
-        if(cpi->common.last_frame_type != KEY_FRAME)
-        {
-            mb_offset = (-xd->mb_to_top_edge/128 + 1) * (xd->mode_info_stride +1) + (-xd->mb_to_left_edge/128 +1) ;
-
-            /* current in last frame */
-            if (cpi->lf_ref_frame[mb_offset] != INTRA_FRAME)
-            {
-                near_mvs[vcnt].as_int = cpi->lfmv[mb_offset].as_int;
-                mv_bias(cpi->lf_ref_frame_sign_bias[mb_offset], refframe, &near_mvs[vcnt], ref_frame_sign_bias);
-                near_ref[vcnt] =  cpi->lf_ref_frame[mb_offset];
-            }
-            vcnt++;
-
-            /* above in last frame */
-            if (cpi->lf_ref_frame[mb_offset - xd->mode_info_stride-1] != INTRA_FRAME)
-            {
-                near_mvs[vcnt].as_int = cpi->lfmv[mb_offset - xd->mode_info_stride-1].as_int;
-                mv_bias(cpi->lf_ref_frame_sign_bias[mb_offset - xd->mode_info_stride-1], refframe, &near_mvs[vcnt], ref_frame_sign_bias);
-                near_ref[vcnt] =  cpi->lf_ref_frame[mb_offset - xd->mode_info_stride-1];
-            }
-            vcnt++;
-
-            /* left in last frame */
-            if (cpi->lf_ref_frame[mb_offset-1] != INTRA_FRAME)
-            {
-                near_mvs[vcnt].as_int = cpi->lfmv[mb_offset -1].as_int;
-                mv_bias(cpi->lf_ref_frame_sign_bias[mb_offset -1], refframe, &near_mvs[vcnt], ref_frame_sign_bias);
-                near_ref[vcnt] =  cpi->lf_ref_frame[mb_offset - 1];
-            }
-            vcnt++;
-
-            /* right in last frame */
-            if (cpi->lf_ref_frame[mb_offset +1] != INTRA_FRAME)
-            {
-                near_mvs[vcnt].as_int = cpi->lfmv[mb_offset +1].as_int;
-                mv_bias(cpi->lf_ref_frame_sign_bias[mb_offset +1], refframe, &near_mvs[vcnt], ref_frame_sign_bias);
-                near_ref[vcnt] =  cpi->lf_ref_frame[mb_offset +1];
-            }
-            vcnt++;
-
-            /* below in last frame */
-            if (cpi->lf_ref_frame[mb_offset + xd->mode_info_stride +1] != INTRA_FRAME)
-            {
-                near_mvs[vcnt].as_int = cpi->lfmv[mb_offset + xd->mode_info_stride +1].as_int;
-                mv_bias(cpi->lf_ref_frame_sign_bias[mb_offset + xd->mode_info_stride +1], refframe, &near_mvs[vcnt], ref_frame_sign_bias);
-                near_ref[vcnt] =  cpi->lf_ref_frame[mb_offset + xd->mode_info_stride +1];
-            }
-            vcnt++;
-        }
-
-        for(i=0; i< vcnt; i++)
-        {
-            if(near_ref[near_sadidx[i]] != INTRA_FRAME)
-            {
-                if(here->mbmi.ref_frame == near_ref[near_sadidx[i]])
-                {
-                    mv.as_int = near_mvs[near_sadidx[i]].as_int;
-                    find = 1;
-                    if (i < 3)
-                        *sr = 3;
-                    else
-                        *sr = 2;
-                    break;
-                }
-            }
-        }
-
-        if(!find)
-        {
-            for(i=0; i<vcnt; i++)
-            {
-                mvx[i] = near_mvs[i].as_mv.row;
-                mvy[i] = near_mvs[i].as_mv.col;
-            }
-
-            insertsortmv(mvx, vcnt);
-            insertsortmv(mvy, vcnt);
-            mv.as_mv.row = mvx[vcnt/2];
-            mv.as_mv.col = mvy[vcnt/2];
-
-            /* sr is set to 0 to allow calling function to decide the search
-             * range.
-             */
-            *sr = 0;
-        }
-    }
-
-    /* Set up return values */
-    mvp->as_int = mv.as_int;
-    vp8_clamp_mv2(mvp, xd);
-}
-
-void vp8_cal_sad(VP8_COMP *cpi, MACROBLOCKD *xd, MACROBLOCK *x, int recon_yoffset, int near_sadidx[])
-{
-    /* near_sad indexes:
-     *   0-cf above, 1-cf left, 2-cf aboveleft,
-     *   3-lf current, 4-lf above, 5-lf left, 6-lf right, 7-lf below
-     */
-    int near_sad[8] = {0};
-    BLOCK *b = &x->block[0];
-    unsigned char *src_y_ptr = *(b->base_src);
-
-    /* calculate sad for current frame 3 nearby MBs. */
-    if( xd->mb_to_top_edge==0 && xd->mb_to_left_edge ==0)
-    {
-        near_sad[0] = near_sad[1] = near_sad[2] = INT_MAX;
-    }else if(xd->mb_to_top_edge==0)
-    {   /* only has left MB for sad calculation. */
-        near_sad[0] = near_sad[2] = INT_MAX;
-        near_sad[1] = cpi->fn_ptr[BLOCK_16X16].sdf(src_y_ptr, b->src_stride, xd->dst.y_buffer - 16,xd->dst.y_stride);
-    }else if(xd->mb_to_left_edge ==0)
-    {   /* only has left MB for sad calculation. */
-        near_sad[1] = near_sad[2] = INT_MAX;
-        near_sad[0] = cpi->fn_ptr[BLOCK_16X16].sdf(src_y_ptr, b->src_stride, xd->dst.y_buffer - xd->dst.y_stride *16,xd->dst.y_stride);
-    }else
-    {
-        near_sad[0] = cpi->fn_ptr[BLOCK_16X16].sdf(src_y_ptr, b->src_stride, xd->dst.y_buffer - xd->dst.y_stride *16,xd->dst.y_stride);
-        near_sad[1] = cpi->fn_ptr[BLOCK_16X16].sdf(src_y_ptr, b->src_stride, xd->dst.y_buffer - 16,xd->dst.y_stride);
-        near_sad[2] = cpi->fn_ptr[BLOCK_16X16].sdf(src_y_ptr, b->src_stride, xd->dst.y_buffer - xd->dst.y_stride *16 -16,xd->dst.y_stride);
-    }
-
-    if(cpi->common.last_frame_type != KEY_FRAME)
-    {
-        /* calculate sad for last frame 5 nearby MBs. */
-        unsigned char *pre_y_buffer = cpi->common.yv12_fb[cpi->common.lst_fb_idx].y_buffer + recon_yoffset;
-        int pre_y_stride = cpi->common.yv12_fb[cpi->common.lst_fb_idx].y_stride;
-
-        if(xd->mb_to_top_edge==0) near_sad[4] = INT_MAX;
-        if(xd->mb_to_left_edge ==0) near_sad[5] = INT_MAX;
-        if(xd->mb_to_right_edge ==0) near_sad[6] = INT_MAX;
-        if(xd->mb_to_bottom_edge==0) near_sad[7] = INT_MAX;
-
-        if(near_sad[4] != INT_MAX)
-            near_sad[4] = cpi->fn_ptr[BLOCK_16X16].sdf(src_y_ptr, b->src_stride, pre_y_buffer - pre_y_stride *16, pre_y_stride);
-        if(near_sad[5] != INT_MAX)
-            near_sad[5] = cpi->fn_ptr[BLOCK_16X16].sdf(src_y_ptr, b->src_stride, pre_y_buffer - 16, pre_y_stride);
-        near_sad[3] = cpi->fn_ptr[BLOCK_16X16].sdf(src_y_ptr, b->src_stride, pre_y_buffer, pre_y_stride);
-        if(near_sad[6] != INT_MAX)
-            near_sad[6] = cpi->fn_ptr[BLOCK_16X16].sdf(src_y_ptr, b->src_stride, pre_y_buffer + 16, pre_y_stride);
-        if(near_sad[7] != INT_MAX)
-            near_sad[7] = cpi->fn_ptr[BLOCK_16X16].sdf(src_y_ptr, b->src_stride, pre_y_buffer + pre_y_stride *16, pre_y_stride);
-    }
-
-    if(cpi->common.last_frame_type != KEY_FRAME)
-    {
-        insertsortsad(near_sad, near_sadidx, 8);
-    }else
-    {
-        insertsortsad(near_sad, near_sadidx, 3);
-    }
-}
-
-static void rd_update_mvcount(MACROBLOCK *x, int_mv *best_ref_mv)
-{
-    if (x->e_mbd.mode_info_context->mbmi.mode == SPLITMV)
-    {
-        int i;
-
-        for (i = 0; i < x->partition_info->count; i++)
-        {
-            if (x->partition_info->bmi[i].mode == NEW4X4)
-            {
-                x->MVcount[0][mv_max+((x->partition_info->bmi[i].mv.as_mv.row
-                                          - best_ref_mv->as_mv.row) >> 1)]++;
-                x->MVcount[1][mv_max+((x->partition_info->bmi[i].mv.as_mv.col
-                                          - best_ref_mv->as_mv.col) >> 1)]++;
-            }
-        }
-    }
-    else if (x->e_mbd.mode_info_context->mbmi.mode == NEWMV)
-    {
-        x->MVcount[0][mv_max+((x->e_mbd.mode_info_context->mbmi.mv.as_mv.row
-                                          - best_ref_mv->as_mv.row) >> 1)]++;
-        x->MVcount[1][mv_max+((x->e_mbd.mode_info_context->mbmi.mv.as_mv.col
-                                          - best_ref_mv->as_mv.col) >> 1)]++;
-    }
-}
-
-static int evaluate_inter_mode_rd(int mdcounts[4],
-                                  RATE_DISTORTION* rd,
-                                  int* disable_skip,
-                                  VP8_COMP *cpi, MACROBLOCK *x)
-{
-    MB_PREDICTION_MODE this_mode = x->e_mbd.mode_info_context->mbmi.mode;
-    BLOCK *b = &x->block[0];
-    MACROBLOCKD *xd = &x->e_mbd;
-    int distortion;
-    vp8_build_inter16x16_predictors_mby(&x->e_mbd, x->e_mbd.predictor, 16);
-
-    if (cpi->active_map_enabled && x->active_ptr[0] == 0) {
-        x->skip = 1;
-    }
-    else if (x->encode_breakout)
-    {
-        unsigned int sse;
-        unsigned int var;
-        unsigned int threshold = (xd->block[0].dequant[1]
-                    * xd->block[0].dequant[1] >>4);
-
-        if(threshold < x->encode_breakout)
-            threshold = x->encode_breakout;
-
-        var = vpx_variance16x16
-                (*(b->base_src), b->src_stride,
-                x->e_mbd.predictor, 16, &sse);
-
-        if (sse < threshold)
-        {
-             unsigned int q2dc = xd->block[24].dequant[0];
-            /* If theres is no codeable 2nd order dc
-               or a very small uniform pixel change change */
-            if ((sse - var < q2dc * q2dc >>4) ||
-                (sse /2 > var && sse-var < 64))
-            {
-                /* Check u and v to make sure skip is ok */
-                unsigned int sse2 = VP8_UVSSE(x);
-                if (sse2 * 2 < threshold)
-                {
-                    x->skip = 1;
-                    rd->distortion2 = sse + sse2;
-                    rd->rate2 = 500;
-
-                    /* for best_yrd calculation */
-                    rd->rate_uv = 0;
-                    rd->distortion_uv = sse2;
-
-                    *disable_skip = 1;
-                    return RDCOST(x->rdmult, x->rddiv, rd->rate2,
-                                  rd->distortion2);
-                }
-            }
-        }
-    }
-
-
-    /* Add in the Mv/mode cost */
-    rd->rate2 += vp8_cost_mv_ref(this_mode, mdcounts);
-
-    /* Y cost and distortion */
-    macro_block_yrd(x, &rd->rate_y, &distortion);
-    rd->rate2 += rd->rate_y;
-    rd->distortion2 += distortion;
-
-    /* UV cost and distortion */
-    rd_inter16x16_uv(cpi, x, &rd->rate_uv, &rd->distortion_uv,
-                     cpi->common.full_pixel);
-    rd->rate2 += rd->rate_uv;
-    rd->distortion2 += rd->distortion_uv;
-    return INT_MAX;
-}
-
-static int calculate_final_rd_costs(int this_rd,
-                                    RATE_DISTORTION* rd,
-                                    int* other_cost,
-                                    int disable_skip,
-                                    int uv_intra_tteob,
-                                    int intra_rd_penalty,
-                                    VP8_COMP *cpi, MACROBLOCK *x)
-{
-    MB_PREDICTION_MODE this_mode = x->e_mbd.mode_info_context->mbmi.mode;
-
-    /* Where skip is allowable add in the default per mb cost for the no
-     * skip case. where we then decide to skip we have to delete this and
-     * replace it with the cost of signalling a skip
-     */
-    if (cpi->common.mb_no_coeff_skip)
-    {
-        *other_cost += vp8_cost_bit(cpi->prob_skip_false, 0);
-        rd->rate2 += *other_cost;
-    }
-
-    /* Estimate the reference frame signaling cost and add it
-     * to the rolling cost variable.
-     */
-    rd->rate2 +=
-        x->ref_frame_cost[x->e_mbd.mode_info_context->mbmi.ref_frame];
-
-    if (!disable_skip)
-    {
-        /* Test for the condition where skip block will be activated
-         * because there are no non zero coefficients and make any
-         * necessary adjustment for rate
-         */
-        if (cpi->common.mb_no_coeff_skip)
-        {
-            int i;
-            int tteob;
-            int has_y2_block = (this_mode!=SPLITMV && this_mode!=B_PRED);
-
-            tteob = 0;
-            if(has_y2_block)
-                tteob += x->e_mbd.eobs[24];
-
-            for (i = 0; i < 16; i++)
-                tteob += (x->e_mbd.eobs[i] > has_y2_block);
-
-            if (x->e_mbd.mode_info_context->mbmi.ref_frame)
-            {
-                for (i = 16; i < 24; i++)
-                    tteob += x->e_mbd.eobs[i];
-            }
-            else
-                tteob += uv_intra_tteob;
-
-            if (tteob == 0)
-            {
-                rd->rate2 -= (rd->rate_y + rd->rate_uv);
-                /* for best_yrd calculation */
-                rd->rate_uv = 0;
-
-                /* Back out no skip flag costing and add in skip flag costing */
-                if (cpi->prob_skip_false)
-                {
-                    int prob_skip_cost;
-
-                    prob_skip_cost = vp8_cost_bit(cpi->prob_skip_false, 1);
-                    prob_skip_cost -=
-                        (int)vp8_cost_bit(cpi->prob_skip_false, 0);
-                    rd->rate2 += prob_skip_cost;
-                    *other_cost += prob_skip_cost;
-                }
-            }
-        }
-        /* Calculate the final RD estimate for this mode */
-        this_rd = RDCOST(x->rdmult, x->rddiv, rd->rate2, rd->distortion2);
-        if (this_rd < INT_MAX && x->e_mbd.mode_info_context->mbmi.ref_frame
-                                 == INTRA_FRAME)
-            this_rd += intra_rd_penalty;
-    }
-    return this_rd;
-}
-
-static void update_best_mode(BEST_MODE* best_mode, int this_rd,
-                             RATE_DISTORTION* rd, int other_cost, MACROBLOCK *x)
-{
-    MB_PREDICTION_MODE this_mode = x->e_mbd.mode_info_context->mbmi.mode;
-
-    other_cost +=
-    x->ref_frame_cost[x->e_mbd.mode_info_context->mbmi.ref_frame];
-
-    /* Calculate the final y RD estimate for this mode */
-    best_mode->yrd = RDCOST(x->rdmult, x->rddiv, (rd->rate2-rd->rate_uv-other_cost),
-                      (rd->distortion2-rd->distortion_uv));
-
-    best_mode->rd = this_rd;
-    memcpy(&best_mode->mbmode, &x->e_mbd.mode_info_context->mbmi, sizeof(MB_MODE_INFO));
-    memcpy(&best_mode->partition, x->partition_info, sizeof(PARTITION_INFO));
-
-    if ((this_mode == B_PRED) || (this_mode == SPLITMV))
-    {
-        int i;
-        for (i = 0; i < 16; i++)
-        {
-            best_mode->bmodes[i] = x->e_mbd.block[i].bmi;
-        }
-    }
-}
-
-void vp8_rd_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset,
-                            int recon_uvoffset, int *returnrate,
-                            int *returndistortion, int *returnintra,
-                            int mb_row, int mb_col)
-{
-    BLOCK *b = &x->block[0];
-    BLOCKD *d = &x->e_mbd.block[0];
-    MACROBLOCKD *xd = &x->e_mbd;
-    int_mv best_ref_mv_sb[2];
-    int_mv mode_mv_sb[2][MB_MODE_COUNT];
-    int_mv best_ref_mv;
-    int_mv *mode_mv;
-    MB_PREDICTION_MODE this_mode;
-    int num00;
-    int best_mode_index = 0;
-    BEST_MODE best_mode;
-
-    int i;
-    int mode_index;
-    int mdcounts[4];
-    int rate;
-    RATE_DISTORTION rd;
-    int uv_intra_rate, uv_intra_distortion, uv_intra_rate_tokenonly;
-    int uv_intra_tteob = 0;
-    int uv_intra_done = 0;
-
-    MB_PREDICTION_MODE uv_intra_mode = 0;
-    int_mv mvp;
-    int near_sadidx[8] = {0, 1, 2, 3, 4, 5, 6, 7};
-    int saddone=0;
-    /* search range got from mv_pred(). It uses step_param levels. (0-7) */
-    int sr=0;
-
-    unsigned char *plane[4][3];
-    int ref_frame_map[4];
-    int sign_bias = 0;
-
-    int intra_rd_penalty =  10* vp8_dc_quant(cpi->common.base_qindex,
-                                             cpi->common.y1dc_delta_q);
-
-#if CONFIG_TEMPORAL_DENOISING
-    unsigned int zero_mv_sse = UINT_MAX, best_sse = UINT_MAX,
-            best_rd_sse = UINT_MAX;
-#endif
-
-    mode_mv = mode_mv_sb[sign_bias];
-    best_ref_mv.as_int = 0;
-    best_mode.rd = INT_MAX;
-    best_mode.yrd = INT_MAX;
-    best_mode.intra_rd = INT_MAX;
-    memset(mode_mv_sb, 0, sizeof(mode_mv_sb));
-    memset(&best_mode.mbmode, 0, sizeof(best_mode.mbmode));
-    memset(&best_mode.bmodes, 0, sizeof(best_mode.bmodes));
-
-    /* Setup search priorities */
-    get_reference_search_order(cpi, ref_frame_map);
-
-    /* Check to see if there is at least 1 valid reference frame that we need
-     * to calculate near_mvs.
-     */
-    if (ref_frame_map[1] > 0)
-    {
-        sign_bias = vp8_find_near_mvs_bias(&x->e_mbd,
-                                           x->e_mbd.mode_info_context,
-                                           mode_mv_sb,
-                                           best_ref_mv_sb,
-                                           mdcounts,
-                                           ref_frame_map[1],
-                                           cpi->common.ref_frame_sign_bias);
-
-        mode_mv = mode_mv_sb[sign_bias];
-        best_ref_mv.as_int = best_ref_mv_sb[sign_bias].as_int;
-    }
-
-    get_predictor_pointers(cpi, plane, recon_yoffset, recon_uvoffset);
-
-    *returnintra = INT_MAX;
-    /* Count of the number of MBs tested so far this frame */
-    x->mbs_tested_so_far++;
-
-    x->skip = 0;
-
-    for (mode_index = 0; mode_index < MAX_MODES; mode_index++)
-    {
-        int this_rd = INT_MAX;
-        int disable_skip = 0;
-        int other_cost = 0;
-        int this_ref_frame = ref_frame_map[vp8_ref_frame_order[mode_index]];
-
-        /* Test best rd so far against threshold for trying this mode. */
-        if (best_mode.rd <= x->rd_threshes[mode_index])
-            continue;
-
-        if (this_ref_frame < 0)
-            continue;
-
-        /* These variables hold are rolling total cost and distortion for
-         * this mode
-         */
-        rd.rate2 = 0;
-        rd.distortion2 = 0;
-
-        this_mode = vp8_mode_order[mode_index];
-
-        x->e_mbd.mode_info_context->mbmi.mode = this_mode;
-        x->e_mbd.mode_info_context->mbmi.ref_frame = this_ref_frame;
-
-        /* Only consider ZEROMV/ALTREF_FRAME for alt ref frame,
-         * unless ARNR filtering is enabled in which case we want
-         * an unfiltered alternative
-         */
-        if (cpi->is_src_frame_alt_ref && (cpi->oxcf.arnr_max_frames == 0))
-        {
-            if (this_mode != ZEROMV || x->e_mbd.mode_info_context->mbmi.ref_frame != ALTREF_FRAME)
-                continue;
-        }
-
-        /* everything but intra */
-        if (x->e_mbd.mode_info_context->mbmi.ref_frame)
-        {
-            x->e_mbd.pre.y_buffer = plane[this_ref_frame][0];
-            x->e_mbd.pre.u_buffer = plane[this_ref_frame][1];
-            x->e_mbd.pre.v_buffer = plane[this_ref_frame][2];
-
-            if (sign_bias != cpi->common.ref_frame_sign_bias[this_ref_frame])
-            {
-                sign_bias = cpi->common.ref_frame_sign_bias[this_ref_frame];
-                mode_mv = mode_mv_sb[sign_bias];
-                best_ref_mv.as_int = best_ref_mv_sb[sign_bias].as_int;
-            }
-        }
-
-        /* Check to see if the testing frequency for this mode is at its
-         * max If so then prevent it from being tested and increase the
-         * threshold for its testing
-         */
-        if (x->mode_test_hit_counts[mode_index] && (cpi->mode_check_freq[mode_index] > 1))
-        {
-            if (x->mbs_tested_so_far  <= cpi->mode_check_freq[mode_index] * x->mode_test_hit_counts[mode_index])
-            {
-                /* Increase the threshold for coding this mode to make it
-                 * less likely to be chosen
-                 */
-                x->rd_thresh_mult[mode_index] += 4;
-
-                if (x->rd_thresh_mult[mode_index] > MAX_THRESHMULT)
-                    x->rd_thresh_mult[mode_index] = MAX_THRESHMULT;
-
-                x->rd_threshes[mode_index] =
-                    (cpi->rd_baseline_thresh[mode_index] >> 7) *
-                    x->rd_thresh_mult[mode_index];
-
-                continue;
-            }
-        }
-
-        /* We have now reached the point where we are going to test the
-         * current mode so increment the counter for the number of times
-         * it has been tested
-         */
-        x->mode_test_hit_counts[mode_index] ++;
-
-        /* Experimental code. Special case for gf and arf zeromv modes.
-         * Increase zbin size to supress noise
-         */
-        if (x->zbin_mode_boost_enabled)
-        {
-            if ( this_ref_frame == INTRA_FRAME )
-                x->zbin_mode_boost = 0;
-            else
-            {
-                if (vp8_mode_order[mode_index] == ZEROMV)
-                {
-                    if (this_ref_frame != LAST_FRAME)
-                        x->zbin_mode_boost = GF_ZEROMV_ZBIN_BOOST;
-                    else
-                        x->zbin_mode_boost = LF_ZEROMV_ZBIN_BOOST;
-                }
-                else if (vp8_mode_order[mode_index] == SPLITMV)
-                    x->zbin_mode_boost = 0;
-                else
-                    x->zbin_mode_boost = MV_ZBIN_BOOST;
-            }
-
-            vp8_update_zbin_extra(cpi, x);
-        }
-
-        if(!uv_intra_done && this_ref_frame == INTRA_FRAME)
-        {
-            rd_pick_intra_mbuv_mode(x, &uv_intra_rate,
-                                    &uv_intra_rate_tokenonly,
-                                    &uv_intra_distortion);
-            uv_intra_mode = x->e_mbd.mode_info_context->mbmi.uv_mode;
-
-            /*
-             * Total of the eobs is used later to further adjust rate2. Since uv
-             * block's intra eobs will be overwritten when we check inter modes,
-             * we need to save uv_intra_tteob here.
-             */
-            for (i = 16; i < 24; i++)
-                uv_intra_tteob += x->e_mbd.eobs[i];
-
-            uv_intra_done = 1;
-        }
-
-        switch (this_mode)
-        {
-        case B_PRED:
-        {
-            int tmp_rd;
-
-            /* Note the rate value returned here includes the cost of
-             * coding the BPRED mode: x->mbmode_cost[x->e_mbd.frame_type][BPRED]
-             */
-            int distortion;
-            tmp_rd = rd_pick_intra4x4mby_modes(x, &rate, &rd.rate_y, &distortion, best_mode.yrd);
-            rd.rate2 += rate;
-            rd.distortion2 += distortion;
-
-            if(tmp_rd < best_mode.yrd)
-            {
-                rd.rate2 += uv_intra_rate;
-                rd.rate_uv = uv_intra_rate_tokenonly;
-                rd.distortion2 += uv_intra_distortion;
-                rd.distortion_uv = uv_intra_distortion;
-            }
-            else
-            {
-                this_rd = INT_MAX;
-                disable_skip = 1;
-            }
-        }
-        break;
-
-        case SPLITMV:
-        {
-            int tmp_rd;
-            int this_rd_thresh;
-            int distortion;
-
-            this_rd_thresh = (vp8_ref_frame_order[mode_index] == 1) ?
-                x->rd_threshes[THR_NEW1] : x->rd_threshes[THR_NEW3];
-            this_rd_thresh = (vp8_ref_frame_order[mode_index] == 2) ?
-                x->rd_threshes[THR_NEW2] : this_rd_thresh;
-
-            tmp_rd = vp8_rd_pick_best_mbsegmentation(cpi, x, &best_ref_mv,
-                                                     best_mode.yrd, mdcounts,
-                                                     &rate, &rd.rate_y, &distortion, this_rd_thresh) ;
-
-            rd.rate2 += rate;
-            rd.distortion2 += distortion;
-
-            /* If even the 'Y' rd value of split is higher than best so far
-             * then dont bother looking at UV
-             */
-            if (tmp_rd < best_mode.yrd)
-            {
-                /* Now work out UV cost and add it in */
-                rd_inter4x4_uv(cpi, x, &rd.rate_uv, &rd.distortion_uv, cpi->common.full_pixel);
-                rd.rate2 += rd.rate_uv;
-                rd.distortion2 += rd.distortion_uv;
-            }
-            else
-            {
-                this_rd = INT_MAX;
-                disable_skip = 1;
-            }
-        }
-        break;
-        case DC_PRED:
-        case V_PRED:
-        case H_PRED:
-        case TM_PRED:
-        {
-            int distortion;
-            x->e_mbd.mode_info_context->mbmi.ref_frame = INTRA_FRAME;
-
-            vp8_build_intra_predictors_mby_s(xd,
-                                             xd->dst.y_buffer - xd->dst.y_stride,
-                                             xd->dst.y_buffer - 1,
-                                             xd->dst.y_stride,
-                                             xd->predictor,
-                                             16);
-            macro_block_yrd(x, &rd.rate_y, &distortion) ;
-            rd.rate2 += rd.rate_y;
-            rd.distortion2 += distortion;
-            rd.rate2 += x->mbmode_cost[x->e_mbd.frame_type][x->e_mbd.mode_info_context->mbmi.mode];
-            rd.rate2 += uv_intra_rate;
-            rd.rate_uv = uv_intra_rate_tokenonly;
-            rd.distortion2 += uv_intra_distortion;
-            rd.distortion_uv = uv_intra_distortion;
-        }
-        break;
-
-        case NEWMV:
-        {
-            int thissme;
-            int bestsme = INT_MAX;
-            int step_param = cpi->sf.first_step;
-            int further_steps;
-            int n;
-            int do_refine=1;   /* If last step (1-away) of n-step search doesn't pick the center point as the best match,
-                                  we will do a final 1-away diamond refining search  */
-
-            int sadpb = x->sadperbit16;
-            int_mv mvp_full;
-
-            int col_min = ((best_ref_mv.as_mv.col+7)>>3) - MAX_FULL_PEL_VAL;
-            int row_min = ((best_ref_mv.as_mv.row+7)>>3) - MAX_FULL_PEL_VAL;
-            int col_max = (best_ref_mv.as_mv.col>>3) + MAX_FULL_PEL_VAL;
-            int row_max = (best_ref_mv.as_mv.row>>3) + MAX_FULL_PEL_VAL;
-
-            int tmp_col_min = x->mv_col_min;
-            int tmp_col_max = x->mv_col_max;
-            int tmp_row_min = x->mv_row_min;
-            int tmp_row_max = x->mv_row_max;
-
-            if(!saddone)
-            {
-                vp8_cal_sad(cpi,xd,x, recon_yoffset ,&near_sadidx[0] );
-                saddone = 1;
-            }
-
-            vp8_mv_pred(cpi, &x->e_mbd, x->e_mbd.mode_info_context, &mvp,
-                        x->e_mbd.mode_info_context->mbmi.ref_frame, cpi->common.ref_frame_sign_bias, &sr, &near_sadidx[0]);
-
-            mvp_full.as_mv.col = mvp.as_mv.col>>3;
-            mvp_full.as_mv.row = mvp.as_mv.row>>3;
-
-            /* Get intersection of UMV window and valid MV window to
-             * reduce # of checks in diamond search.
-             */
-            if (x->mv_col_min < col_min )
-                x->mv_col_min = col_min;
-            if (x->mv_col_max > col_max )
-                x->mv_col_max = col_max;
-            if (x->mv_row_min < row_min )
-                x->mv_row_min = row_min;
-            if (x->mv_row_max > row_max )
-                x->mv_row_max = row_max;
-
-            /* adjust search range according to sr from mv prediction */
-            if(sr > step_param)
-                step_param = sr;
-
-            /* Initial step/diamond search */
-            {
-                bestsme = cpi->diamond_search_sad(x, b, d, &mvp_full, &d->bmi.mv,
-                                        step_param, sadpb, &num00,
-                                        &cpi->fn_ptr[BLOCK_16X16],
-                                        x->mvcost, &best_ref_mv);
-                mode_mv[NEWMV].as_int = d->bmi.mv.as_int;
-
-                /* Further step/diamond searches as necessary */
-                further_steps = (cpi->sf.max_step_search_steps - 1) - step_param;
-
-                n = num00;
-                num00 = 0;
-
-                /* If there won't be more n-step search, check to see if refining search is needed. */
-                if (n > further_steps)
-                    do_refine = 0;
-
-                while (n < further_steps)
-                {
-                    n++;
-
-                    if (num00)
-                        num00--;
-                    else
-                    {
-                        thissme = cpi->diamond_search_sad(x, b, d, &mvp_full,
-                                    &d->bmi.mv, step_param + n, sadpb, &num00,
-                                    &cpi->fn_ptr[BLOCK_16X16], x->mvcost,
-                                    &best_ref_mv);
-
-                        /* check to see if refining search is needed. */
-                        if (num00 > (further_steps-n))
-                            do_refine = 0;
-
-                        if (thissme < bestsme)
-                        {
-                            bestsme = thissme;
-                            mode_mv[NEWMV].as_int = d->bmi.mv.as_int;
-                        }
-                        else
-                        {
-                            d->bmi.mv.as_int = mode_mv[NEWMV].as_int;
-                        }
-                    }
-                }
-            }
-
-            /* final 1-away diamond refining search */
-            if (do_refine == 1)
-            {
-                int search_range;
-
-                search_range = 8;
-
-                thissme = cpi->refining_search_sad(x, b, d, &d->bmi.mv, sadpb,
-                                       search_range, &cpi->fn_ptr[BLOCK_16X16],
-                                       x->mvcost, &best_ref_mv);
-
-                if (thissme < bestsme)
-                {
-                    bestsme = thissme;
-                    mode_mv[NEWMV].as_int = d->bmi.mv.as_int;
-                }
-                else
-                {
-                    d->bmi.mv.as_int = mode_mv[NEWMV].as_int;
-                }
-            }
-
-            x->mv_col_min = tmp_col_min;
-            x->mv_col_max = tmp_col_max;
-            x->mv_row_min = tmp_row_min;
-            x->mv_row_max = tmp_row_max;
-
-            if (bestsme < INT_MAX)
-            {
-                int dis; /* TODO: use dis in distortion calculation later. */
-                unsigned int sse;
-                cpi->find_fractional_mv_step(x, b, d, &d->bmi.mv, &best_ref_mv,
-                                             x->errorperbit,
-                                             &cpi->fn_ptr[BLOCK_16X16],
-                                             x->mvcost, &dis, &sse);
-            }
-
-            mode_mv[NEWMV].as_int = d->bmi.mv.as_int;
-
-            /* Add the new motion vector cost to our rolling cost variable */
-            rd.rate2 += vp8_mv_bit_cost(&mode_mv[NEWMV], &best_ref_mv, x->mvcost, 96);
-        }
-
-        case NEARESTMV:
-        case NEARMV:
-            /* Clip "next_nearest" so that it does not extend to far out
-             * of image
-             */
-            vp8_clamp_mv2(&mode_mv[this_mode], xd);
-
-            /* Do not bother proceeding if the vector (from newmv, nearest
-             * or near) is 0,0 as this should then be coded using the zeromv
-             * mode.
-             */
-            if (((this_mode == NEARMV) || (this_mode == NEARESTMV)) && (mode_mv[this_mode].as_int == 0))
-                continue;
-
-        case ZEROMV:
-
-            /* Trap vectors that reach beyond the UMV borders
-             * Note that ALL New MV, Nearest MV Near MV and Zero MV code
-             * drops through to this point because of the lack of break
-             * statements in the previous two cases.
-             */
-            if (((mode_mv[this_mode].as_mv.row >> 3) < x->mv_row_min) || ((mode_mv[this_mode].as_mv.row >> 3) > x->mv_row_max) ||
-                ((mode_mv[this_mode].as_mv.col >> 3) < x->mv_col_min) || ((mode_mv[this_mode].as_mv.col >> 3) > x->mv_col_max))
-                continue;
-
-            vp8_set_mbmode_and_mvs(x, this_mode, &mode_mv[this_mode]);
-            this_rd = evaluate_inter_mode_rd(mdcounts, &rd,
-                                             &disable_skip, cpi, x);
-            break;
-
-        default:
-            break;
-        }
-
-        this_rd = calculate_final_rd_costs(this_rd, &rd, &other_cost,
-                                           disable_skip, uv_intra_tteob,
-                                           intra_rd_penalty, cpi, x);
-
-        /* Keep record of best intra distortion */
-        if ((x->e_mbd.mode_info_context->mbmi.ref_frame == INTRA_FRAME) &&
-            (this_rd < best_mode.intra_rd) )
-        {
-          best_mode.intra_rd = this_rd;
-            *returnintra = rd.distortion2 ;
-        }
-#if CONFIG_TEMPORAL_DENOISING
-        if (cpi->oxcf.noise_sensitivity)
-        {
-            unsigned int sse;
-            vp8_get_inter_mbpred_error(x,&cpi->fn_ptr[BLOCK_16X16],&sse,
-                                   mode_mv[this_mode]);
-
-            if (sse < best_rd_sse)
-                best_rd_sse = sse;
-
-            /* Store for later use by denoiser. */
-            if (this_mode == ZEROMV && sse < zero_mv_sse )
-            {
-                zero_mv_sse = sse;
-                x->best_zeromv_reference_frame =
-                        x->e_mbd.mode_info_context->mbmi.ref_frame;
-            }
-
-            /* Store the best NEWMV in x for later use in the denoiser. */
-            if (x->e_mbd.mode_info_context->mbmi.mode == NEWMV &&
-                    sse < best_sse)
-            {
-                best_sse = sse;
-                vp8_get_inter_mbpred_error(x,&cpi->fn_ptr[BLOCK_16X16],&best_sse,
-                                       mode_mv[this_mode]);
-                x->best_sse_inter_mode = NEWMV;
-                x->best_sse_mv = x->e_mbd.mode_info_context->mbmi.mv;
-                x->need_to_clamp_best_mvs =
-                    x->e_mbd.mode_info_context->mbmi.need_to_clamp_mvs;
-                x->best_reference_frame =
-                    x->e_mbd.mode_info_context->mbmi.ref_frame;
-            }
-        }
-#endif
-
-        /* Did this mode help.. i.i is it the new best mode */
-        if (this_rd < best_mode.rd || x->skip)
-        {
-            /* Note index of best mode so far */
-            best_mode_index = mode_index;
-            *returnrate = rd.rate2;
-            *returndistortion = rd.distortion2;
-            if (this_mode <= B_PRED)
-            {
-                x->e_mbd.mode_info_context->mbmi.uv_mode = uv_intra_mode;
-                /* required for left and above block mv */
-                x->e_mbd.mode_info_context->mbmi.mv.as_int = 0;
-            }
-            update_best_mode(&best_mode, this_rd, &rd, other_cost, x);
-
-
-            /* Testing this mode gave rise to an improvement in best error
-             * score. Lower threshold a bit for next time
-             */
-            x->rd_thresh_mult[mode_index] =
-                (x->rd_thresh_mult[mode_index] >= (MIN_THRESHMULT + 2)) ?
-                    x->rd_thresh_mult[mode_index] - 2 : MIN_THRESHMULT;
-        }
-
-        /* If the mode did not help improve the best error case then raise
-         * the threshold for testing that mode next time around.
-         */
-        else
-        {
-            x->rd_thresh_mult[mode_index] += 4;
-
-            if (x->rd_thresh_mult[mode_index] > MAX_THRESHMULT)
-                x->rd_thresh_mult[mode_index] = MAX_THRESHMULT;
-        }
-        x->rd_threshes[mode_index] =
-            (cpi->rd_baseline_thresh[mode_index] >> 7) *
-                x->rd_thresh_mult[mode_index];
-
-        if (x->skip)
-            break;
-
-    }
-
-    /* Reduce the activation RD thresholds for the best choice mode */
-    if ((cpi->rd_baseline_thresh[best_mode_index] > 0) && (cpi->rd_baseline_thresh[best_mode_index] < (INT_MAX >> 2)))
-    {
-        int best_adjustment = (x->rd_thresh_mult[best_mode_index] >> 2);
-
-        x->rd_thresh_mult[best_mode_index] =
-            (x->rd_thresh_mult[best_mode_index] >=
-                (MIN_THRESHMULT + best_adjustment)) ?
-                    x->rd_thresh_mult[best_mode_index] - best_adjustment :
-                    MIN_THRESHMULT;
-        x->rd_threshes[best_mode_index] =
-            (cpi->rd_baseline_thresh[best_mode_index] >> 7) *
-                x->rd_thresh_mult[best_mode_index];
-    }
-
-#if CONFIG_TEMPORAL_DENOISING
-    if (cpi->oxcf.noise_sensitivity)
-    {
-        int block_index = mb_row * cpi->common.mb_cols + mb_col;
-        if (x->best_sse_inter_mode == DC_PRED)
-        {
-            /* No best MV found. */
-            x->best_sse_inter_mode = best_mode.mbmode.mode;
-            x->best_sse_mv = best_mode.mbmode.mv;
-            x->need_to_clamp_best_mvs = best_mode.mbmode.need_to_clamp_mvs;
-            x->best_reference_frame = best_mode.mbmode.ref_frame;
-            best_sse = best_rd_sse;
-        }
-        vp8_denoiser_denoise_mb(&cpi->denoiser, x, best_sse, zero_mv_sse,
-                                recon_yoffset, recon_uvoffset,
-                                &cpi->common.lf_info, mb_row, mb_col,
-                                block_index, 0);
-
-        /* Reevaluate ZEROMV after denoising. */
-        if (best_mode.mbmode.ref_frame == INTRA_FRAME &&
-            x->best_zeromv_reference_frame != INTRA_FRAME)
-        {
-            int this_rd = INT_MAX;
-            int disable_skip = 0;
-            int other_cost = 0;
-            int this_ref_frame = x->best_zeromv_reference_frame;
-            rd.rate2 = x->ref_frame_cost[this_ref_frame] +
-                    vp8_cost_mv_ref(ZEROMV, mdcounts);
-            rd.distortion2 = 0;
-
-            /* set up the proper prediction buffers for the frame */
-            x->e_mbd.mode_info_context->mbmi.ref_frame = this_ref_frame;
-            x->e_mbd.pre.y_buffer = plane[this_ref_frame][0];
-            x->e_mbd.pre.u_buffer = plane[this_ref_frame][1];
-            x->e_mbd.pre.v_buffer = plane[this_ref_frame][2];
-
-            x->e_mbd.mode_info_context->mbmi.mode = ZEROMV;
-            x->e_mbd.mode_info_context->mbmi.uv_mode = DC_PRED;
-            x->e_mbd.mode_info_context->mbmi.mv.as_int = 0;
-
-            this_rd = evaluate_inter_mode_rd(mdcounts, &rd, &disable_skip, cpi, x);
-            this_rd = calculate_final_rd_costs(this_rd, &rd, &other_cost,
-                                               disable_skip, uv_intra_tteob,
-                                               intra_rd_penalty, cpi, x);
-            if (this_rd < best_mode.rd || x->skip)
-            {
-                *returnrate = rd.rate2;
-                *returndistortion = rd.distortion2;
-                update_best_mode(&best_mode, this_rd, &rd, other_cost, x);
-            }
-        }
-
-    }
-#endif
-
-    if (cpi->is_src_frame_alt_ref &&
-        (best_mode.mbmode.mode != ZEROMV || best_mode.mbmode.ref_frame != ALTREF_FRAME))
-    {
-        x->e_mbd.mode_info_context->mbmi.mode = ZEROMV;
-        x->e_mbd.mode_info_context->mbmi.ref_frame = ALTREF_FRAME;
-        x->e_mbd.mode_info_context->mbmi.mv.as_int = 0;
-        x->e_mbd.mode_info_context->mbmi.uv_mode = DC_PRED;
-        x->e_mbd.mode_info_context->mbmi.mb_skip_coeff =
-                                        (cpi->common.mb_no_coeff_skip);
-        x->e_mbd.mode_info_context->mbmi.partitioning = 0;
-        return;
-    }
-
-
-    /* macroblock modes */
-    memcpy(&x->e_mbd.mode_info_context->mbmi, &best_mode.mbmode, sizeof(MB_MODE_INFO));
-
-    if (best_mode.mbmode.mode == B_PRED)
-    {
-        for (i = 0; i < 16; i++)
-            xd->mode_info_context->bmi[i].as_mode = best_mode.bmodes[i].as_mode;
-    }
-
-    if (best_mode.mbmode.mode == SPLITMV)
-    {
-        for (i = 0; i < 16; i++)
-            xd->mode_info_context->bmi[i].mv.as_int = best_mode.bmodes[i].mv.as_int;
-
-        memcpy(x->partition_info, &best_mode.partition, sizeof(PARTITION_INFO));
-
-        x->e_mbd.mode_info_context->mbmi.mv.as_int =
-                                      x->partition_info->bmi[15].mv.as_int;
-    }
-
-    if (sign_bias
-        != cpi->common.ref_frame_sign_bias[xd->mode_info_context->mbmi.ref_frame])
-        best_ref_mv.as_int = best_ref_mv_sb[!sign_bias].as_int;
-
-    rd_update_mvcount(x, &best_ref_mv);
-}
-
-void vp8_rd_pick_intra_mode(MACROBLOCK *x, int *rate_)
-{
-    int error4x4, error16x16;
-    int rate4x4, rate16x16 = 0, rateuv;
-    int dist4x4, dist16x16, distuv;
-    int rate;
-    int rate4x4_tokenonly = 0;
-    int rate16x16_tokenonly = 0;
-    int rateuv_tokenonly = 0;
-
-    x->e_mbd.mode_info_context->mbmi.ref_frame = INTRA_FRAME;
-
-    rd_pick_intra_mbuv_mode(x, &rateuv, &rateuv_tokenonly, &distuv);
-    rate = rateuv;
-
-    error16x16 = rd_pick_intra16x16mby_mode(x, &rate16x16, &rate16x16_tokenonly,
-                                            &dist16x16);
-
-    error4x4 = rd_pick_intra4x4mby_modes(x, &rate4x4, &rate4x4_tokenonly,
-                                         &dist4x4, error16x16);
-
-    if (error4x4 < error16x16)
-    {
-        x->e_mbd.mode_info_context->mbmi.mode = B_PRED;
-        rate += rate4x4;
-    }
-    else
-    {
-        rate += rate16x16;
-    }
-
-    *rate_ = rate;
-}
diff --git a/vp8/encoder/rdopt.h b/vp8/encoder/rdopt.h
deleted file mode 100644 (file)
index 1cb1a07..0000000
+++ /dev/null
@@ -1,149 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#ifndef VP8_ENCODER_RDOPT_H_
-#define VP8_ENCODER_RDOPT_H_
-
-#include "./vpx_config.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define RDCOST(RM,DM,R,D) ( ((128+(R)*(RM)) >> 8) + (DM)*(D) )
-
-static INLINE void insertsortmv(int arr[], int len)
-{
-    int i, j, k;
-
-    for ( i = 1 ; i <= len-1 ; i++ )
-    {
-        for ( j = 0 ; j < i ; j++ )
-        {
-            if ( arr[j] > arr[i] )
-            {
-                int temp;
-
-                temp = arr[i];
-
-                for ( k = i; k >j; k--)
-                    arr[k] = arr[k - 1] ;
-
-                arr[j] = temp ;
-            }
-        }
-    }
-}
-
-static INLINE void insertsortsad(int arr[],int idx[], int len)
-{
-    int i, j, k;
-
-    for ( i = 1 ; i <= len-1 ; i++ )
-    {
-        for ( j = 0 ; j < i ; j++ )
-        {
-            if ( arr[j] > arr[i] )
-            {
-                int temp, tempi;
-
-                temp = arr[i];
-                tempi = idx[i];
-
-                for ( k = i; k >j; k--)
-                {
-                    arr[k] = arr[k - 1] ;
-                    idx[k] = idx[k - 1];
-                }
-
-                arr[j] = temp ;
-                idx[j] = tempi;
-            }
-        }
-    }
-}
-
-extern void vp8_initialize_rd_consts(VP8_COMP *cpi, MACROBLOCK *x, int Qvalue);
-extern void vp8_rd_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x,
-                                   int recon_yoffset, int recon_uvoffset,
-                                   int *returnrate, int *returndistortion,
-                                   int *returnintra, int mb_row, int mb_col);
-extern void vp8_rd_pick_intra_mode(MACROBLOCK *x, int *rate);
-
-
-static INLINE void get_plane_pointers(const YV12_BUFFER_CONFIG *fb,
-                                      unsigned char *plane[3],
-                                      unsigned int recon_yoffset,
-                                      unsigned int recon_uvoffset)
-{
-    plane[0] = fb->y_buffer + recon_yoffset;
-    plane[1] = fb->u_buffer + recon_uvoffset;
-    plane[2] = fb->v_buffer + recon_uvoffset;
-}
-
-
-static INLINE void get_predictor_pointers(const VP8_COMP *cpi,
-                                          unsigned char *plane[4][3],
-                                          unsigned int recon_yoffset,
-                                          unsigned int recon_uvoffset)
-{
-    if (cpi->ref_frame_flags & VP8_LAST_FRAME)
-        get_plane_pointers(&cpi->common.yv12_fb[cpi->common.lst_fb_idx],
-                           plane[LAST_FRAME], recon_yoffset, recon_uvoffset);
-
-    if (cpi->ref_frame_flags & VP8_GOLD_FRAME)
-        get_plane_pointers(&cpi->common.yv12_fb[cpi->common.gld_fb_idx],
-                           plane[GOLDEN_FRAME], recon_yoffset, recon_uvoffset);
-
-    if (cpi->ref_frame_flags & VP8_ALTR_FRAME)
-        get_plane_pointers(&cpi->common.yv12_fb[cpi->common.alt_fb_idx],
-                           plane[ALTREF_FRAME], recon_yoffset, recon_uvoffset);
-}
-
-
-static INLINE void get_reference_search_order(const VP8_COMP *cpi,
-                                              int ref_frame_map[4])
-{
-    int i=0;
-
-    ref_frame_map[i++] = INTRA_FRAME;
-    if (cpi->ref_frame_flags & VP8_LAST_FRAME)
-        ref_frame_map[i++] = LAST_FRAME;
-    if (cpi->ref_frame_flags & VP8_GOLD_FRAME)
-        ref_frame_map[i++] = GOLDEN_FRAME;
-    if (cpi->ref_frame_flags & VP8_ALTR_FRAME)
-        ref_frame_map[i++] = ALTREF_FRAME;
-    for(; i<4; i++)
-        ref_frame_map[i] = -1;
-}
-
-
-extern void vp8_mv_pred
-(
-    VP8_COMP *cpi,
-    MACROBLOCKD *xd,
-    const MODE_INFO *here,
-    int_mv *mvp,
-    int refframe,
-    int *ref_frame_sign_bias,
-    int *sr,
-    int near_sadidx[]
-);
-void vp8_cal_sad(VP8_COMP *cpi, MACROBLOCKD *xd, MACROBLOCK *x, int recon_yoffset, int near_sadidx[]);
-int VP8_UVSSE(MACROBLOCK *x);
-int vp8_cost_mv_ref(MB_PREDICTION_MODE m, const int near_mv_ref_ct[4]);
-void vp8_set_mbmode_and_mvs(MACROBLOCK *x, MB_PREDICTION_MODE mb, int_mv *mv);
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP8_ENCODER_RDOPT_H_
diff --git a/vp8/encoder/segmentation.c b/vp8/encoder/segmentation.c
deleted file mode 100644 (file)
index fdd22fc..0000000
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#include "segmentation.h"
-#include "vpx_mem/vpx_mem.h"
-
-void vp8_update_gf_useage_maps(VP8_COMP *cpi, VP8_COMMON *cm, MACROBLOCK *x)
-{
-    int mb_row, mb_col;
-
-    MODE_INFO *this_mb_mode_info = cm->mi;
-
-    x->gf_active_ptr = (signed char *)cpi->gf_active_flags;
-
-    if ((cm->frame_type == KEY_FRAME) || (cm->refresh_golden_frame))
-    {
-        /* Reset Gf useage monitors */
-        memset(cpi->gf_active_flags, 1, (cm->mb_rows * cm->mb_cols));
-        cpi->gf_active_count = cm->mb_rows * cm->mb_cols;
-    }
-    else
-    {
-        /* for each macroblock row in image */
-        for (mb_row = 0; mb_row < cm->mb_rows; mb_row++)
-        {
-            /* for each macroblock col in image */
-            for (mb_col = 0; mb_col < cm->mb_cols; mb_col++)
-            {
-
-                /* If using golden then set GF active flag if not already set.
-                 * If using last frame 0,0 mode then leave flag as it is
-                 * else if using non 0,0 motion or intra modes then clear
-                 * flag if it is currently set
-                 */
-                if ((this_mb_mode_info->mbmi.ref_frame == GOLDEN_FRAME) || (this_mb_mode_info->mbmi.ref_frame == ALTREF_FRAME))
-                {
-                    if (*(x->gf_active_ptr) == 0)
-                    {
-                        *(x->gf_active_ptr) = 1;
-                        cpi->gf_active_count ++;
-                    }
-                }
-                else if ((this_mb_mode_info->mbmi.mode != ZEROMV) && *(x->gf_active_ptr))
-                {
-                    *(x->gf_active_ptr) = 0;
-                    cpi->gf_active_count--;
-                }
-
-                x->gf_active_ptr++;          /* Step onto next entry */
-                this_mb_mode_info++;         /* skip to next mb */
-
-            }
-
-            /* this is to account for the border */
-            this_mb_mode_info++;
-        }
-    }
-}
diff --git a/vp8/encoder/segmentation.h b/vp8/encoder/segmentation.h
deleted file mode 100644 (file)
index 6b55005..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#ifndef VP8_ENCODER_SEGMENTATION_H_
-#define VP8_ENCODER_SEGMENTATION_H_
-
-#include "string.h"
-#include "vp8/common/blockd.h"
-#include "onyx_int.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-extern void vp8_update_gf_useage_maps(VP8_COMP *cpi, VP8_COMMON *cm, MACROBLOCK *x);
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP8_ENCODER_SEGMENTATION_H_
diff --git a/vp8/encoder/temporal_filter.c b/vp8/encoder/temporal_filter.c
deleted file mode 100644 (file)
index 85d26c2..0000000
+++ /dev/null
@@ -1,521 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#include "vp8/common/onyxc_int.h"
-#include "onyx_int.h"
-#include "vp8/common/systemdependent.h"
-#include "vp8/encoder/quantize.h"
-#include "vp8/common/alloccommon.h"
-#include "mcomp.h"
-#include "firstpass.h"
-#include "vpx_scale/vpx_scale.h"
-#include "vp8/common/extend.h"
-#include "ratectrl.h"
-#include "vp8/common/quant_common.h"
-#include "segmentation.h"
-#include "vpx_mem/vpx_mem.h"
-#include "vp8/common/swapyv12buffer.h"
-#include "vp8/common/threading.h"
-#include "vpx_ports/vpx_timer.h"
-
-#include <math.h>
-#include <limits.h>
-
-#define ALT_REF_MC_ENABLED 1    /* dis/enable MC in AltRef filtering */
-#define ALT_REF_SUBPEL_ENABLED 1 /* dis/enable subpel in MC AltRef filtering */
-
-#if VP8_TEMPORAL_ALT_REF
-
-static void vp8_temporal_filter_predictors_mb_c
-(
-    MACROBLOCKD *x,
-    unsigned char *y_mb_ptr,
-    unsigned char *u_mb_ptr,
-    unsigned char *v_mb_ptr,
-    int stride,
-    int mv_row,
-    int mv_col,
-    unsigned char *pred
-)
-{
-    int offset;
-    unsigned char *yptr, *uptr, *vptr;
-
-    /* Y */
-    yptr = y_mb_ptr + (mv_row >> 3) * stride + (mv_col >> 3);
-
-    if ((mv_row | mv_col) & 7)
-    {
-        x->subpixel_predict16x16(yptr, stride,
-                                    mv_col & 7, mv_row & 7, &pred[0], 16);
-    }
-    else
-    {
-        vp8_copy_mem16x16(yptr, stride, &pred[0], 16);
-    }
-
-    /* U & V */
-    mv_row >>= 1;
-    mv_col >>= 1;
-    stride = (stride + 1) >> 1;
-    offset = (mv_row >> 3) * stride + (mv_col >> 3);
-    uptr = u_mb_ptr + offset;
-    vptr = v_mb_ptr + offset;
-
-    if ((mv_row | mv_col) & 7)
-    {
-        x->subpixel_predict8x8(uptr, stride,
-                            mv_col & 7, mv_row & 7, &pred[256], 8);
-        x->subpixel_predict8x8(vptr, stride,
-                            mv_col & 7, mv_row & 7, &pred[320], 8);
-    }
-    else
-    {
-        vp8_copy_mem8x8(uptr, stride, &pred[256], 8);
-        vp8_copy_mem8x8(vptr, stride, &pred[320], 8);
-    }
-}
-void vp8_temporal_filter_apply_c
-(
-    unsigned char *frame1,
-    unsigned int stride,
-    unsigned char *frame2,
-    unsigned int block_size,
-    int strength,
-    int filter_weight,
-    unsigned int *accumulator,
-    unsigned short *count
-)
-{
-    unsigned int i, j, k;
-    int modifier;
-    int byte = 0;
-    const int rounding = strength > 0 ? 1 << (strength - 1) : 0;
-
-    for (i = 0,k = 0; i < block_size; i++)
-    {
-        for (j = 0; j < block_size; j++, k++)
-        {
-
-            int src_byte = frame1[byte];
-            int pixel_value = *frame2++;
-
-            modifier   = src_byte - pixel_value;
-            /* This is an integer approximation of:
-             * float coeff = (3.0 * modifer * modifier) / pow(2, strength);
-             * modifier =  (int)roundf(coeff > 16 ? 0 : 16-coeff);
-             */
-            modifier  *= modifier;
-            modifier  *= 3;
-            modifier  += rounding;
-            modifier >>= strength;
-
-            if (modifier > 16)
-                modifier = 16;
-
-            modifier = 16 - modifier;
-            modifier *= filter_weight;
-
-            count[k] += modifier;
-            accumulator[k] += modifier * pixel_value;
-
-            byte++;
-        }
-
-        byte += stride - block_size;
-    }
-}
-
-#if ALT_REF_MC_ENABLED
-
-static int vp8_temporal_filter_find_matching_mb_c
-(
-    VP8_COMP *cpi,
-    YV12_BUFFER_CONFIG *arf_frame,
-    YV12_BUFFER_CONFIG *frame_ptr,
-    int mb_offset,
-    int error_thresh
-)
-{
-    MACROBLOCK *x = &cpi->mb;
-    int step_param;
-    int sadpb = x->sadperbit16;
-    int bestsme = INT_MAX;
-
-    BLOCK *b = &x->block[0];
-    BLOCKD *d = &x->e_mbd.block[0];
-    int_mv best_ref_mv1;
-    int_mv best_ref_mv1_full; /* full-pixel value of best_ref_mv1 */
-
-    /* Save input state */
-    unsigned char **base_src = b->base_src;
-    int src = b->src;
-    int src_stride = b->src_stride;
-    unsigned char *base_pre = x->e_mbd.pre.y_buffer;
-    int pre = d->offset;
-    int pre_stride = x->e_mbd.pre.y_stride;
-
-    (void)error_thresh;
-
-    best_ref_mv1.as_int = 0;
-    best_ref_mv1_full.as_mv.col = best_ref_mv1.as_mv.col >>3;
-    best_ref_mv1_full.as_mv.row = best_ref_mv1.as_mv.row >>3;
-
-    /* Setup frame pointers */
-    b->base_src = &arf_frame->y_buffer;
-    b->src_stride = arf_frame->y_stride;
-    b->src = mb_offset;
-
-    x->e_mbd.pre.y_buffer = frame_ptr->y_buffer;
-    x->e_mbd.pre.y_stride = frame_ptr->y_stride;
-    d->offset = mb_offset;
-
-    /* Further step/diamond searches as necessary */
-    if (cpi->Speed < 8)
-    {
-        step_param = cpi->sf.first_step + (cpi->Speed > 5);
-    }
-    else
-    {
-        step_param = cpi->sf.first_step + 2;
-    }
-
-    /* TODO Check that the 16x16 vf & sdf are selected here */
-    /* Ignore mv costing by sending NULL cost arrays */
-    bestsme = vp8_hex_search(x, b, d, &best_ref_mv1_full, &d->bmi.mv,
-                             step_param, sadpb,
-                             &cpi->fn_ptr[BLOCK_16X16],
-                             NULL, NULL, &best_ref_mv1);
-
-#if ALT_REF_SUBPEL_ENABLED
-    /* Try sub-pixel MC? */
-    {
-        int distortion;
-        unsigned int sse;
-        /* Ignore mv costing by sending NULL cost array */
-        bestsme = cpi->find_fractional_mv_step(x, b, d,
-                                               &d->bmi.mv,
-                                               &best_ref_mv1,
-                                               x->errorperbit,
-                                               &cpi->fn_ptr[BLOCK_16X16],
-                                               NULL, &distortion, &sse);
-    }
-#endif
-
-    /* Save input state */
-    b->base_src = base_src;
-    b->src = src;
-    b->src_stride = src_stride;
-    x->e_mbd.pre.y_buffer = base_pre;
-    d->offset = pre;
-    x->e_mbd.pre.y_stride = pre_stride;
-
-    return bestsme;
-}
-#endif
-
-static void vp8_temporal_filter_iterate_c
-(
-    VP8_COMP *cpi,
-    int frame_count,
-    int alt_ref_index,
-    int strength
-)
-{
-    int byte;
-    int frame;
-    int mb_col, mb_row;
-    unsigned int filter_weight;
-    int mb_cols = cpi->common.mb_cols;
-    int mb_rows = cpi->common.mb_rows;
-    int mb_y_offset = 0;
-    int mb_uv_offset = 0;
-    DECLARE_ALIGNED(16, unsigned int, accumulator[16*16 + 8*8 + 8*8]);
-    DECLARE_ALIGNED(16, unsigned short, count[16*16 + 8*8 + 8*8]);
-    MACROBLOCKD *mbd = &cpi->mb.e_mbd;
-    YV12_BUFFER_CONFIG *f = cpi->frames[alt_ref_index];
-    unsigned char *dst1, *dst2;
-    DECLARE_ALIGNED(16, unsigned char,  predictor[16*16 + 8*8 + 8*8]);
-
-    /* Save input state */
-    unsigned char *y_buffer = mbd->pre.y_buffer;
-    unsigned char *u_buffer = mbd->pre.u_buffer;
-    unsigned char *v_buffer = mbd->pre.v_buffer;
-
-    for (mb_row = 0; mb_row < mb_rows; mb_row++)
-    {
-#if ALT_REF_MC_ENABLED
-        /* Source frames are extended to 16 pixels.  This is different than
-         *  L/A/G reference frames that have a border of 32 (VP8BORDERINPIXELS)
-         * A 6 tap filter is used for motion search.  This requires 2 pixels
-         *  before and 3 pixels after.  So the largest Y mv on a border would
-         *  then be 16 - 3.  The UV blocks are half the size of the Y and
-         *  therefore only extended by 8.  The largest mv that a UV block
-         *  can support is 8 - 3.  A UV mv is half of a Y mv.
-         *  (16 - 3) >> 1 == 6 which is greater than 8 - 3.
-         * To keep the mv in play for both Y and UV planes the max that it
-         *  can be on a border is therefore 16 - 5.
-         */
-        cpi->mb.mv_row_min = -((mb_row * 16) + (16 - 5));
-        cpi->mb.mv_row_max = ((cpi->common.mb_rows - 1 - mb_row) * 16)
-                                + (16 - 5);
-#endif
-
-        for (mb_col = 0; mb_col < mb_cols; mb_col++)
-        {
-            int i, j, k;
-            int stride;
-
-            memset(accumulator, 0, 384*sizeof(unsigned int));
-            memset(count, 0, 384*sizeof(unsigned short));
-
-#if ALT_REF_MC_ENABLED
-            cpi->mb.mv_col_min = -((mb_col * 16) + (16 - 5));
-            cpi->mb.mv_col_max = ((cpi->common.mb_cols - 1 - mb_col) * 16)
-                                    + (16 - 5);
-#endif
-
-            for (frame = 0; frame < frame_count; frame++)
-            {
-                if (cpi->frames[frame] == NULL)
-                    continue;
-
-                mbd->block[0].bmi.mv.as_mv.row = 0;
-                mbd->block[0].bmi.mv.as_mv.col = 0;
-
-                if (frame == alt_ref_index)
-                {
-                    filter_weight = 2;
-                }
-                else
-                {
-                    int err = 0;
-#if ALT_REF_MC_ENABLED
-#define THRESH_LOW   10000
-#define THRESH_HIGH  20000
-                    /* Find best match in this frame by MC */
-                    err = vp8_temporal_filter_find_matching_mb_c
-                              (cpi,
-                               cpi->frames[alt_ref_index],
-                               cpi->frames[frame],
-                               mb_y_offset,
-                               THRESH_LOW);
-#endif
-                    /* Assign higher weight to matching MB if it's error
-                     * score is lower. If not applying MC default behavior
-                     * is to weight all MBs equal.
-                     */
-                    filter_weight = err<THRESH_LOW
-                                       ? 2 : err<THRESH_HIGH ? 1 : 0;
-                }
-
-                if (filter_weight != 0)
-                {
-                    /* Construct the predictors */
-                    vp8_temporal_filter_predictors_mb_c
-                        (mbd,
-                         cpi->frames[frame]->y_buffer + mb_y_offset,
-                         cpi->frames[frame]->u_buffer + mb_uv_offset,
-                         cpi->frames[frame]->v_buffer + mb_uv_offset,
-                         cpi->frames[frame]->y_stride,
-                         mbd->block[0].bmi.mv.as_mv.row,
-                         mbd->block[0].bmi.mv.as_mv.col,
-                         predictor);
-
-                    /* Apply the filter (YUV) */
-                    vp8_temporal_filter_apply
-                        (f->y_buffer + mb_y_offset,
-                         f->y_stride,
-                         predictor,
-                         16,
-                         strength,
-                         filter_weight,
-                         accumulator,
-                         count);
-
-                    vp8_temporal_filter_apply
-                        (f->u_buffer + mb_uv_offset,
-                         f->uv_stride,
-                         predictor + 256,
-                         8,
-                         strength,
-                         filter_weight,
-                         accumulator + 256,
-                         count + 256);
-
-                    vp8_temporal_filter_apply
-                        (f->v_buffer + mb_uv_offset,
-                         f->uv_stride,
-                         predictor + 320,
-                         8,
-                         strength,
-                         filter_weight,
-                         accumulator + 320,
-                         count + 320);
-                }
-            }
-
-            /* Normalize filter output to produce AltRef frame */
-            dst1 = cpi->alt_ref_buffer.y_buffer;
-            stride = cpi->alt_ref_buffer.y_stride;
-            byte = mb_y_offset;
-            for (i = 0,k = 0; i < 16; i++)
-            {
-                for (j = 0; j < 16; j++, k++)
-                {
-                    unsigned int pval = accumulator[k] + (count[k] >> 1);
-                    pval *= cpi->fixed_divide[count[k]];
-                    pval >>= 19;
-
-                    dst1[byte] = (unsigned char)pval;
-
-                    /* move to next pixel */
-                    byte++;
-                }
-
-                byte += stride - 16;
-            }
-
-            dst1 = cpi->alt_ref_buffer.u_buffer;
-            dst2 = cpi->alt_ref_buffer.v_buffer;
-            stride = cpi->alt_ref_buffer.uv_stride;
-            byte = mb_uv_offset;
-            for (i = 0,k = 256; i < 8; i++)
-            {
-                for (j = 0; j < 8; j++, k++)
-                {
-                    int m=k+64;
-
-                    /* U */
-                    unsigned int pval = accumulator[k] + (count[k] >> 1);
-                    pval *= cpi->fixed_divide[count[k]];
-                    pval >>= 19;
-                    dst1[byte] = (unsigned char)pval;
-
-                    /* V */
-                    pval = accumulator[m] + (count[m] >> 1);
-                    pval *= cpi->fixed_divide[count[m]];
-                    pval >>= 19;
-                    dst2[byte] = (unsigned char)pval;
-
-                    /* move to next pixel */
-                    byte++;
-                }
-
-                byte += stride - 8;
-            }
-
-            mb_y_offset += 16;
-            mb_uv_offset += 8;
-        }
-
-        mb_y_offset += 16*(f->y_stride-mb_cols);
-        mb_uv_offset += 8*(f->uv_stride-mb_cols);
-    }
-
-    /* Restore input state */
-    mbd->pre.y_buffer = y_buffer;
-    mbd->pre.u_buffer = u_buffer;
-    mbd->pre.v_buffer = v_buffer;
-}
-
-void vp8_temporal_filter_prepare_c
-(
-    VP8_COMP *cpi,
-    int distance
-)
-{
-    int frame = 0;
-
-    int num_frames_backward = 0;
-    int num_frames_forward = 0;
-    int frames_to_blur_backward = 0;
-    int frames_to_blur_forward = 0;
-    int frames_to_blur = 0;
-    int start_frame = 0;
-
-    int strength = cpi->oxcf.arnr_strength;
-
-    int blur_type = cpi->oxcf.arnr_type;
-
-    int max_frames = cpi->active_arnr_frames;
-
-    num_frames_backward = distance;
-    num_frames_forward = vp8_lookahead_depth(cpi->lookahead)
-                         - (num_frames_backward + 1);
-
-    switch (blur_type)
-    {
-    case 1:
-        /* Backward Blur */
-
-        frames_to_blur_backward = num_frames_backward;
-
-        if (frames_to_blur_backward >= max_frames)
-            frames_to_blur_backward = max_frames - 1;
-
-        frames_to_blur = frames_to_blur_backward + 1;
-        break;
-
-    case 2:
-        /* Forward Blur */
-
-        frames_to_blur_forward = num_frames_forward;
-
-        if (frames_to_blur_forward >= max_frames)
-            frames_to_blur_forward = max_frames - 1;
-
-        frames_to_blur = frames_to_blur_forward + 1;
-        break;
-
-    case 3:
-    default:
-        /* Center Blur */
-        frames_to_blur_forward = num_frames_forward;
-        frames_to_blur_backward = num_frames_backward;
-
-        if (frames_to_blur_forward > frames_to_blur_backward)
-            frames_to_blur_forward = frames_to_blur_backward;
-
-        if (frames_to_blur_backward > frames_to_blur_forward)
-            frames_to_blur_backward = frames_to_blur_forward;
-
-        /* When max_frames is even we have 1 more frame backward than forward */
-        if (frames_to_blur_forward > (max_frames - 1) / 2)
-            frames_to_blur_forward = ((max_frames - 1) / 2);
-
-        if (frames_to_blur_backward > (max_frames / 2))
-            frames_to_blur_backward = (max_frames / 2);
-
-        frames_to_blur = frames_to_blur_backward + frames_to_blur_forward + 1;
-        break;
-    }
-
-    start_frame = distance + frames_to_blur_forward;
-
-    /* Setup frame pointers, NULL indicates frame not included in filter */
-    memset(cpi->frames, 0, max_frames*sizeof(YV12_BUFFER_CONFIG *));
-    for (frame = 0; frame < frames_to_blur; frame++)
-    {
-        int which_buffer =  start_frame - frame;
-        struct lookahead_entry* buf = vp8_lookahead_peek(cpi->lookahead,
-                                                         which_buffer,
-                                                         PEEK_FORWARD);
-        cpi->frames[frames_to_blur-1-frame] = &buf->img;
-    }
-
-    vp8_temporal_filter_iterate_c (
-        cpi,
-        frames_to_blur,
-        frames_to_blur_backward,
-        strength );
-}
-#endif
diff --git a/vp8/encoder/tokenize.c b/vp8/encoder/tokenize.c
deleted file mode 100644 (file)
index afd46fb..0000000
+++ /dev/null
@@ -1,608 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#include <math.h>
-#include <stdio.h>
-#include <string.h>
-#include <assert.h>
-#include "onyx_int.h"
-#include "tokenize.h"
-#include "vpx_mem/vpx_mem.h"
-
-/* Global event counters used for accumulating statistics across several
-   compressions, then generating context.c = initial stats. */
-
-#ifdef VP8_ENTROPY_STATS
-_int64 context_counters[BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [MAX_ENTROPY_TOKENS];
-#endif
-void vp8_stuff_mb(VP8_COMP *cpi, MACROBLOCK *x, TOKENEXTRA **t) ;
-void vp8_fix_contexts(MACROBLOCKD *x);
-
-#include "dct_value_tokens.h"
-#include "dct_value_cost.h"
-
-const TOKENVALUE *const vp8_dct_value_tokens_ptr = dct_value_tokens +
-        DCT_MAX_VALUE;
-const short *const vp8_dct_value_cost_ptr = dct_value_cost + DCT_MAX_VALUE;
-
-#if 0
-int skip_true_count = 0;
-int skip_false_count = 0;
-#endif
-
-/* function used to generate dct_value_tokens and dct_value_cost tables */
-/*
-static void fill_value_tokens()
-{
-
-    TOKENVALUE *t = dct_value_tokens + DCT_MAX_VALUE;
-    const vp8_extra_bit_struct *e = vp8_extra_bits;
-
-    int i = -DCT_MAX_VALUE;
-    int sign = 1;
-
-    do
-    {
-        if (!i)
-            sign = 0;
-
-        {
-            const int a = sign ? -i : i;
-            int eb = sign;
-
-            if (a > 4)
-            {
-                int j = 4;
-
-                while (++j < 11  &&  e[j].base_val <= a) {}
-
-                t[i].Token = --j;
-                eb |= (a - e[j].base_val) << 1;
-            }
-            else
-                t[i].Token = a;
-
-            t[i].Extra = eb;
-        }
-
-        // initialize the cost for extra bits for all possible coefficient value.
-        {
-            int cost = 0;
-            const vp8_extra_bit_struct *p = vp8_extra_bits + t[i].Token;
-
-            if (p->base_val)
-            {
-                const int extra = t[i].Extra;
-                const int Length = p->Len;
-
-                if (Length)
-                    cost += vp8_treed_cost(p->tree, p->prob, extra >> 1, Length);
-
-                cost += vp8_cost_bit(vp8_prob_half, extra & 1); // sign
-                dct_value_cost[i + DCT_MAX_VALUE] = cost;
-            }
-
-        }
-
-    }
-    while (++i < DCT_MAX_VALUE);
-
-    vp8_dct_value_tokens_ptr = dct_value_tokens + DCT_MAX_VALUE;
-    vp8_dct_value_cost_ptr   = dct_value_cost + DCT_MAX_VALUE;
-}
-*/
-
-static void tokenize2nd_order_b
-(
-    MACROBLOCK *x,
-    TOKENEXTRA **tp,
-    VP8_COMP *cpi
-)
-{
-    MACROBLOCKD *xd = &x->e_mbd;
-    int pt;             /* near block/prev token context index */
-    int c;              /* start at DC */
-    TOKENEXTRA *t = *tp;/* store tokens starting here */
-    const BLOCKD *b;
-    const short *qcoeff_ptr;
-    ENTROPY_CONTEXT * a;
-    ENTROPY_CONTEXT * l;
-    int band, rc, v, token;
-    int eob;
-
-    b = xd->block + 24;
-    qcoeff_ptr = b->qcoeff;
-    a = (ENTROPY_CONTEXT *)xd->above_context + 8;
-    l = (ENTROPY_CONTEXT *)xd->left_context + 8;
-    eob = xd->eobs[24];
-    VP8_COMBINEENTROPYCONTEXTS(pt, *a, *l);
-
-    if(!eob)
-    {
-        /* c = band for this case */
-        t->Token = DCT_EOB_TOKEN;
-        t->context_tree = cpi->common.fc.coef_probs [1] [0] [pt];
-        t->skip_eob_node = 0;
-
-        ++x->coef_counts       [1] [0] [pt] [DCT_EOB_TOKEN];
-        t++;
-        *tp = t;
-        *a = *l = 0;
-        return;
-    }
-
-    v = qcoeff_ptr[0];
-    t->Extra = vp8_dct_value_tokens_ptr[v].Extra;
-    token    = vp8_dct_value_tokens_ptr[v].Token;
-    t->Token = token;
-
-    t->context_tree = cpi->common.fc.coef_probs [1] [0] [pt];
-    t->skip_eob_node = 0;
-    ++x->coef_counts       [1] [0] [pt] [token];
-    pt = vp8_prev_token_class[token];
-    t++;
-    c = 1;
-
-    for (; c < eob; c++)
-    {
-        rc = vp8_default_zig_zag1d[c];
-        band = vp8_coef_bands[c];
-        v = qcoeff_ptr[rc];
-
-        t->Extra = vp8_dct_value_tokens_ptr[v].Extra;
-        token    = vp8_dct_value_tokens_ptr[v].Token;
-
-        t->Token = token;
-        t->context_tree = cpi->common.fc.coef_probs [1] [band] [pt];
-
-        t->skip_eob_node = ((pt == 0));
-
-        ++x->coef_counts       [1] [band] [pt] [token];
-
-        pt = vp8_prev_token_class[token];
-        t++;
-    }
-    if (c < 16)
-    {
-        band = vp8_coef_bands[c];
-        t->Token = DCT_EOB_TOKEN;
-        t->context_tree = cpi->common.fc.coef_probs [1] [band] [pt];
-
-        t->skip_eob_node = 0;
-
-        ++x->coef_counts       [1] [band] [pt] [DCT_EOB_TOKEN];
-
-        t++;
-    }
-
-    *tp = t;
-    *a = *l = 1;
-
-}
-
-static void tokenize1st_order_b
-(
-    MACROBLOCK *x,
-    TOKENEXTRA **tp,
-    int type,           /* which plane: 0=Y no DC, 1=Y2, 2=UV, 3=Y with DC */
-    VP8_COMP *cpi
-)
-{
-    MACROBLOCKD *xd = &x->e_mbd;
-    unsigned int block;
-    const BLOCKD *b;
-    int pt;             /* near block/prev token context index */
-    int c;
-    int token;
-    TOKENEXTRA *t = *tp;/* store tokens starting here */
-    const short *qcoeff_ptr;
-    ENTROPY_CONTEXT * a;
-    ENTROPY_CONTEXT * l;
-    int band, rc, v;
-    int tmp1, tmp2;
-
-    b = xd->block;
-    /* Luma */
-    for (block = 0; block < 16; block++, b++)
-    {
-        const int eob = *b->eob;
-        tmp1 = vp8_block2above[block];
-        tmp2 = vp8_block2left[block];
-        qcoeff_ptr = b->qcoeff;
-        a = (ENTROPY_CONTEXT *)xd->above_context + tmp1;
-        l = (ENTROPY_CONTEXT *)xd->left_context + tmp2;
-
-        VP8_COMBINEENTROPYCONTEXTS(pt, *a, *l);
-
-        c = type ? 0 : 1;
-
-        if(c >= eob)
-        {
-            /* c = band for this case */
-            t->Token = DCT_EOB_TOKEN;
-            t->context_tree = cpi->common.fc.coef_probs [type] [c] [pt];
-            t->skip_eob_node = 0;
-
-            ++x->coef_counts       [type] [c] [pt] [DCT_EOB_TOKEN];
-            t++;
-            *tp = t;
-            *a = *l = 0;
-            continue;
-        }
-
-        v = qcoeff_ptr[c];
-
-        t->Extra = vp8_dct_value_tokens_ptr[v].Extra;
-        token    = vp8_dct_value_tokens_ptr[v].Token;
-        t->Token = token;
-
-        t->context_tree = cpi->common.fc.coef_probs [type] [c] [pt];
-        t->skip_eob_node = 0;
-        ++x->coef_counts       [type] [c] [pt] [token];
-        pt = vp8_prev_token_class[token];
-        t++;
-        c++;
-
-        assert(eob <= 16);
-        for (; c < eob; c++)
-        {
-            rc = vp8_default_zig_zag1d[c];
-            band = vp8_coef_bands[c];
-            v = qcoeff_ptr[rc];
-
-            t->Extra = vp8_dct_value_tokens_ptr[v].Extra;
-            token    = vp8_dct_value_tokens_ptr[v].Token;
-
-            t->Token = token;
-            t->context_tree = cpi->common.fc.coef_probs [type] [band] [pt];
-
-            t->skip_eob_node = (pt == 0);
-            ++x->coef_counts       [type] [band] [pt] [token];
-
-            pt = vp8_prev_token_class[token];
-            t++;
-        }
-        if (c < 16)
-        {
-            band = vp8_coef_bands[c];
-            t->Token = DCT_EOB_TOKEN;
-            t->context_tree = cpi->common.fc.coef_probs [type] [band] [pt];
-
-            t->skip_eob_node = 0;
-            ++x->coef_counts       [type] [band] [pt] [DCT_EOB_TOKEN];
-
-            t++;
-        }
-        *tp = t;
-        *a = *l = 1;
-    }
-
-    /* Chroma */
-    for (block = 16; block < 24; block++, b++)
-    {
-        const int eob = *b->eob;
-        tmp1 = vp8_block2above[block];
-        tmp2 = vp8_block2left[block];
-        qcoeff_ptr = b->qcoeff;
-        a = (ENTROPY_CONTEXT *)xd->above_context + tmp1;
-        l = (ENTROPY_CONTEXT *)xd->left_context + tmp2;
-
-        VP8_COMBINEENTROPYCONTEXTS(pt, *a, *l);
-
-        if(!eob)
-        {
-            /* c = band for this case */
-            t->Token = DCT_EOB_TOKEN;
-            t->context_tree = cpi->common.fc.coef_probs [2] [0] [pt];
-            t->skip_eob_node = 0;
-
-            ++x->coef_counts       [2] [0] [pt] [DCT_EOB_TOKEN];
-            t++;
-            *tp = t;
-            *a = *l = 0;
-            continue;
-        }
-
-        v = qcoeff_ptr[0];
-
-        t->Extra = vp8_dct_value_tokens_ptr[v].Extra;
-        token    = vp8_dct_value_tokens_ptr[v].Token;
-        t->Token = token;
-
-        t->context_tree = cpi->common.fc.coef_probs [2] [0] [pt];
-        t->skip_eob_node = 0;
-        ++x->coef_counts       [2] [0] [pt] [token];
-        pt = vp8_prev_token_class[token];
-        t++;
-        c = 1;
-
-        assert(eob <= 16);
-        for (; c < eob; c++)
-        {
-            rc = vp8_default_zig_zag1d[c];
-            band = vp8_coef_bands[c];
-            v = qcoeff_ptr[rc];
-
-            t->Extra = vp8_dct_value_tokens_ptr[v].Extra;
-            token    = vp8_dct_value_tokens_ptr[v].Token;
-
-            t->Token = token;
-            t->context_tree = cpi->common.fc.coef_probs [2] [band] [pt];
-
-            t->skip_eob_node = (pt == 0);
-
-            ++x->coef_counts       [2] [band] [pt] [token];
-
-            pt = vp8_prev_token_class[token];
-            t++;
-        }
-        if (c < 16)
-        {
-            band = vp8_coef_bands[c];
-            t->Token = DCT_EOB_TOKEN;
-            t->context_tree = cpi->common.fc.coef_probs [2] [band] [pt];
-
-            t->skip_eob_node = 0;
-
-            ++x->coef_counts       [2] [band] [pt] [DCT_EOB_TOKEN];
-
-            t++;
-        }
-        *tp = t;
-        *a = *l = 1;
-    }
-}
-
-
-static int mb_is_skippable(MACROBLOCKD *x, int has_y2_block)
-{
-    int skip = 1;
-    int i = 0;
-
-    if (has_y2_block)
-    {
-        for (i = 0; i < 16; i++)
-            skip &= (x->eobs[i] < 2);
-    }
-
-    for (; i < 24 + has_y2_block; i++)
-        skip &= (!x->eobs[i]);
-
-    return skip;
-}
-
-
-void vp8_tokenize_mb(VP8_COMP *cpi, MACROBLOCK *x, TOKENEXTRA **t)
-{
-    MACROBLOCKD *xd = &x->e_mbd;
-    int plane_type;
-    int has_y2_block;
-
-    has_y2_block = (xd->mode_info_context->mbmi.mode != B_PRED
-                    && xd->mode_info_context->mbmi.mode != SPLITMV);
-
-    xd->mode_info_context->mbmi.mb_skip_coeff =
-        mb_is_skippable(xd, has_y2_block);
-    if (xd->mode_info_context->mbmi.mb_skip_coeff)
-    {
-        if (!cpi->common.mb_no_coeff_skip)
-        {
-            vp8_stuff_mb(cpi, x, t);
-        }
-        else
-        {
-            vp8_fix_contexts(xd);
-            x->skip_true_count++;
-        }
-
-        return;
-    }
-
-    plane_type = 3;
-    if(has_y2_block)
-    {
-        tokenize2nd_order_b(x, t, cpi);
-        plane_type = 0;
-    }
-
-    tokenize1st_order_b(x, t, plane_type, cpi);
-}
-
-
-#ifdef VP8_ENTROPY_STATS
-
-void init_context_counters(void)
-{
-    memset(context_counters, 0, sizeof(context_counters));
-}
-
-void print_context_counters()
-{
-
-    int type, band, pt, t;
-
-    FILE *const f = fopen("context.c", "w");
-
-    fprintf(f, "#include \"entropy.h\"\n");
-
-    fprintf(f, "\n/* *** GENERATED FILE: DO NOT EDIT *** */\n\n");
-
-    fprintf(f, "int Contexts[BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [MAX_ENTROPY_TOKENS];\n\n");
-
-    fprintf(f, "const int default_contexts[BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [MAX_ENTROPY_TOKENS] = {");
-
-# define Comma( X) (X? ",":"")
-
-    type = 0;
-
-    do
-    {
-        fprintf(f, "%s\n  { /* block Type %d */", Comma(type), type);
-
-        band = 0;
-
-        do
-        {
-            fprintf(f, "%s\n    { /* Coeff Band %d */", Comma(band), band);
-
-            pt = 0;
-
-            do
-            {
-                fprintf(f, "%s\n      {", Comma(pt));
-
-                t = 0;
-
-                do
-                {
-                    const _int64 x = context_counters [type] [band] [pt] [t];
-                    const int y = (int) x;
-
-                    assert(x == (_int64) y);  /* no overflow handling yet */
-                    fprintf(f, "%s %d", Comma(t), y);
-
-                }
-                while (++t < MAX_ENTROPY_TOKENS);
-
-                fprintf(f, "}");
-            }
-            while (++pt < PREV_COEF_CONTEXTS);
-
-            fprintf(f, "\n    }");
-
-        }
-        while (++band < COEF_BANDS);
-
-        fprintf(f, "\n  }");
-    }
-    while (++type < BLOCK_TYPES);
-
-    fprintf(f, "\n};\n");
-    fclose(f);
-}
-#endif
-
-
-static void stuff2nd_order_b
-(
-    TOKENEXTRA **tp,
-    ENTROPY_CONTEXT *a,
-    ENTROPY_CONTEXT *l,
-    VP8_COMP *cpi,
-    MACROBLOCK *x
-)
-{
-    int pt; /* near block/prev token context index */
-    TOKENEXTRA *t = *tp;        /* store tokens starting here */
-    VP8_COMBINEENTROPYCONTEXTS(pt, *a, *l);
-
-    t->Token = DCT_EOB_TOKEN;
-    t->context_tree = cpi->common.fc.coef_probs [1] [0] [pt];
-    t->skip_eob_node = 0;
-    ++x->coef_counts       [1] [0] [pt] [DCT_EOB_TOKEN];
-    ++t;
-
-    *tp = t;
-    pt = 0;
-    *a = *l = pt;
-}
-
-static void stuff1st_order_b
-(
-    TOKENEXTRA **tp,
-    ENTROPY_CONTEXT *a,
-    ENTROPY_CONTEXT *l,
-    int type,
-    VP8_COMP *cpi,
-    MACROBLOCK *x
-)
-{
-    int pt; /* near block/prev token context index */
-    int band;
-    TOKENEXTRA *t = *tp;        /* store tokens starting here */
-    VP8_COMBINEENTROPYCONTEXTS(pt, *a, *l);
-    band = type ? 0 : 1;
-    t->Token = DCT_EOB_TOKEN;
-    t->context_tree = cpi->common.fc.coef_probs [type] [band] [pt];
-    t->skip_eob_node = 0;
-    ++x->coef_counts       [type] [band] [pt] [DCT_EOB_TOKEN];
-    ++t;
-    *tp = t;
-    pt = 0; /* 0 <-> all coeff data is zero */
-    *a = *l = pt;
-}
-
-static
-void stuff1st_order_buv
-(
-    TOKENEXTRA **tp,
-    ENTROPY_CONTEXT *a,
-    ENTROPY_CONTEXT *l,
-    VP8_COMP *cpi,
-    MACROBLOCK *x
-)
-{
-    int pt; /* near block/prev token context index */
-    TOKENEXTRA *t = *tp;        /* store tokens starting here */
-    VP8_COMBINEENTROPYCONTEXTS(pt, *a, *l);
-
-    t->Token = DCT_EOB_TOKEN;
-    t->context_tree = cpi->common.fc.coef_probs [2] [0] [pt];
-    t->skip_eob_node = 0;
-    ++x->coef_counts[2] [0] [pt] [DCT_EOB_TOKEN];
-    ++t;
-    *tp = t;
-    pt = 0; /* 0 <-> all coeff data is zero */
-    *a = *l = pt;
-}
-
-void vp8_stuff_mb(VP8_COMP *cpi, MACROBLOCK *x, TOKENEXTRA **t)
-{
-    MACROBLOCKD *xd = &x->e_mbd;
-    ENTROPY_CONTEXT * A = (ENTROPY_CONTEXT *)xd->above_context;
-    ENTROPY_CONTEXT * L = (ENTROPY_CONTEXT *)xd->left_context;
-    int plane_type;
-    int b;
-    plane_type = 3;
-    if((xd->mode_info_context->mbmi.mode != B_PRED
-                        && xd->mode_info_context->mbmi.mode != SPLITMV))
-    {
-        stuff2nd_order_b(t,
-                     A + vp8_block2above[24], L + vp8_block2left[24], cpi, x);
-        plane_type = 0;
-    }
-
-    for (b = 0; b < 16; b++)
-        stuff1st_order_b(t,
-                         A + vp8_block2above[b],
-                         L + vp8_block2left[b], plane_type, cpi, x);
-
-    for (b = 16; b < 24; b++)
-        stuff1st_order_buv(t,
-                           A + vp8_block2above[b],
-                           L + vp8_block2left[b], cpi, x);
-
-}
-void vp8_fix_contexts(MACROBLOCKD *x)
-{
-    /* Clear entropy contexts for Y2 blocks */
-    if (x->mode_info_context->mbmi.mode != B_PRED && x->mode_info_context->mbmi.mode != SPLITMV)
-    {
-        memset(x->above_context, 0, sizeof(ENTROPY_CONTEXT_PLANES));
-        memset(x->left_context, 0, sizeof(ENTROPY_CONTEXT_PLANES));
-    }
-    else
-    {
-        memset(x->above_context, 0, sizeof(ENTROPY_CONTEXT_PLANES)-1);
-        memset(x->left_context, 0, sizeof(ENTROPY_CONTEXT_PLANES)-1);
-    }
-
-}
diff --git a/vp8/encoder/tokenize.h b/vp8/encoder/tokenize.h
deleted file mode 100644 (file)
index b73a9ee..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#ifndef VP8_ENCODER_TOKENIZE_H_
-#define VP8_ENCODER_TOKENIZE_H_
-
-#include "vp8/common/entropy.h"
-#include "block.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-void vp8_tokenize_initialize();
-
-typedef struct
-{
-    short Token;
-    short Extra;
-} TOKENVALUE;
-
-typedef struct
-{
-    const vp8_prob *context_tree;
-    short           Extra;
-    unsigned char   Token;
-    unsigned char   skip_eob_node;
-} TOKENEXTRA;
-
-int rd_cost_mby(MACROBLOCKD *);
-
-#ifdef VP8_ENTROPY_STATS
-void init_context_counters();
-void print_context_counters();
-
-extern _int64 context_counters[BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [MAX_ENTROPY_TOKENS];
-#endif
-
-extern const short *const vp8_dct_value_cost_ptr;
-/* TODO: The Token field should be broken out into a separate char array to
- *  improve cache locality, since it's needed for costing when the rest of the
- *  fields are not.
- */
-extern const TOKENVALUE *const vp8_dct_value_tokens_ptr;
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP8_ENCODER_TOKENIZE_H_
diff --git a/vp8/encoder/treewriter.c b/vp8/encoder/treewriter.c
deleted file mode 100644 (file)
index ef25f67..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#include "treewriter.h"
-
-static void cost(
-    int *const C,
-    vp8_tree T,
-    const vp8_prob *const P,
-    int i,
-    int c
-)
-{
-    const vp8_prob p = P [i>>1];
-
-    do
-    {
-        const vp8_tree_index j = T[i];
-        const int d = c + vp8_cost_bit(p, i & 1);
-
-        if (j <= 0)
-            C[-j] = d;
-        else
-            cost(C, T, P, j, d);
-    }
-    while (++i & 1);
-}
-void vp8_cost_tokens(int *c, const vp8_prob *p, vp8_tree t)
-{
-    cost(c, t, p, 0, 0);
-}
-void vp8_cost_tokens2(int *c, const vp8_prob *p, vp8_tree t,int start)
-{
-    cost(c, t, p, start, 0);
-}
diff --git a/vp8/encoder/treewriter.h b/vp8/encoder/treewriter.h
deleted file mode 100644 (file)
index 2debf92..0000000
+++ /dev/null
@@ -1,135 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#ifndef VP8_ENCODER_TREEWRITER_H_
-#define VP8_ENCODER_TREEWRITER_H_
-
-/* Trees map alphabets into huffman-like codes suitable for an arithmetic
-   bit coder.  Timothy S Murphy  11 October 2004 */
-
-#include "./vpx_config.h"
-#include "vp8/common/treecoder.h"
-
-#include "boolhuff.h"       /* for now */
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef BOOL_CODER vp8_writer;
-
-#define vp8_write vp8_encode_bool
-#define vp8_write_literal vp8_encode_value
-#define vp8_write_bit( W, V) vp8_write( W, V, vp8_prob_half)
-
-#define vp8bc_write vp8bc_write_bool
-#define vp8bc_write_literal vp8bc_write_bits
-#define vp8bc_write_bit( W, V) vp8bc_write_bits( W, V, 1)
-
-
-/* Approximate length of an encoded bool in 256ths of a bit at given prob */
-
-#define vp8_cost_zero( x) ( vp8_prob_cost[x])
-#define vp8_cost_one( x)  vp8_cost_zero( vp8_complement(x))
-
-#define vp8_cost_bit( x, b) vp8_cost_zero( (b)?  vp8_complement(x) : (x) )
-
-/* VP8BC version is scaled by 2^20 rather than 2^8; see bool_coder.h */
-
-
-/* Both of these return bits, not scaled bits. */
-
-static INLINE unsigned int vp8_cost_branch(const unsigned int ct[2], vp8_prob p)
-{
-    /* Imitate existing calculation */
-
-    return ((ct[0] * vp8_cost_zero(p))
-            + (ct[1] * vp8_cost_one(p))) >> 8;
-}
-
-/* Small functions to write explicit values and tokens, as well as
-   estimate their lengths. */
-
-static void vp8_treed_write
-(
-    vp8_writer *const w,
-    vp8_tree t,
-    const vp8_prob *const p,
-    int v,
-    int n               /* number of bits in v, assumed nonzero */
-)
-{
-    vp8_tree_index i = 0;
-
-    do
-    {
-        const int b = (v >> --n) & 1;
-        vp8_write(w, b, p[i>>1]);
-        i = t[i+b];
-    }
-    while (n);
-}
-static INLINE void vp8_write_token
-(
-    vp8_writer *const w,
-    vp8_tree t,
-    const vp8_prob *const p,
-    vp8_token *const x
-)
-{
-    vp8_treed_write(w, t, p, x->value, x->Len);
-}
-
-static int vp8_treed_cost(
-    vp8_tree t,
-    const vp8_prob *const p,
-    int v,
-    int n               /* number of bits in v, assumed nonzero */
-)
-{
-    int c = 0;
-    vp8_tree_index i = 0;
-
-    do
-    {
-        const int b = (v >> --n) & 1;
-        c += vp8_cost_bit(p[i>>1], b);
-        i = t[i+b];
-    }
-    while (n);
-
-    return c;
-}
-static INLINE int vp8_cost_token
-(
-    vp8_tree t,
-    const vp8_prob *const p,
-    vp8_token *const x
-)
-{
-    return vp8_treed_cost(t, p, x->value, x->Len);
-}
-
-/* Fill array of costs for all possible token values. */
-
-void vp8_cost_tokens(
-    int *Costs, const vp8_prob *, vp8_tree
-);
-
-void vp8_cost_tokens2(
-    int *Costs, const vp8_prob *, vp8_tree, int
-);
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP8_ENCODER_TREEWRITER_H_
diff --git a/vp8/encoder/vp8_quantize.c b/vp8/encoder/vp8_quantize.c
deleted file mode 100644 (file)
index 0d101ba..0000000
+++ /dev/null
@@ -1,583 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#include <math.h>
-#include "vpx_mem/vpx_mem.h"
-
-#include "onyx_int.h"
-#include "vp8/encoder/quantize.h"
-#include "vp8/common/quant_common.h"
-
-void vp8_fast_quantize_b_c(BLOCK *b, BLOCKD *d)
-{
-    int i, rc, eob;
-    int x, y, z, sz;
-    short *coeff_ptr   = b->coeff;
-    short *round_ptr   = b->round;
-    short *quant_ptr   = b->quant_fast;
-    short *qcoeff_ptr  = d->qcoeff;
-    short *dqcoeff_ptr = d->dqcoeff;
-    short *dequant_ptr = d->dequant;
-
-    eob = -1;
-    for (i = 0; i < 16; i++)
-    {
-        rc   = vp8_default_zig_zag1d[i];
-        z    = coeff_ptr[rc];
-
-        sz = (z >> 31);                              /* sign of z */
-        x  = (z ^ sz) - sz;                          /* x = abs(z) */
-
-        y  = ((x + round_ptr[rc]) * quant_ptr[rc]) >> 16; /* quantize (x) */
-        x  = (y ^ sz) - sz;                          /* get the sign back */
-        qcoeff_ptr[rc] = x;                          /* write to destination */
-        dqcoeff_ptr[rc] = x * dequant_ptr[rc];       /* dequantized value */
-
-        if (y)
-        {
-            eob = i;                                 /* last nonzero coeffs */
-        }
-    }
-    *d->eob = (char)(eob + 1);
-}
-
-void vp8_regular_quantize_b_c(BLOCK *b, BLOCKD *d)
-{
-    int i, rc, eob;
-    int zbin;
-    int x, y, z, sz;
-    short *zbin_boost_ptr  = b->zrun_zbin_boost;
-    short *coeff_ptr       = b->coeff;
-    short *zbin_ptr        = b->zbin;
-    short *round_ptr       = b->round;
-    short *quant_ptr       = b->quant;
-    short *quant_shift_ptr = b->quant_shift;
-    short *qcoeff_ptr      = d->qcoeff;
-    short *dqcoeff_ptr     = d->dqcoeff;
-    short *dequant_ptr     = d->dequant;
-    short zbin_oq_value    = b->zbin_extra;
-
-    memset(qcoeff_ptr, 0, 32);
-    memset(dqcoeff_ptr, 0, 32);
-
-    eob = -1;
-
-    for (i = 0; i < 16; i++)
-    {
-        rc   = vp8_default_zig_zag1d[i];
-        z    = coeff_ptr[rc];
-
-        zbin = zbin_ptr[rc] + *zbin_boost_ptr + zbin_oq_value;
-
-        zbin_boost_ptr ++;
-        sz = (z >> 31);                              /* sign of z */
-        x  = (z ^ sz) - sz;                          /* x = abs(z) */
-
-        if (x >= zbin)
-        {
-            x += round_ptr[rc];
-            y  = ((((x * quant_ptr[rc]) >> 16) + x)
-                 * quant_shift_ptr[rc]) >> 16;       /* quantize (x) */
-            x  = (y ^ sz) - sz;                      /* get the sign back */
-            qcoeff_ptr[rc]  = x;                     /* write to destination */
-            dqcoeff_ptr[rc] = x * dequant_ptr[rc];   /* dequantized value */
-
-            if (y)
-            {
-                eob = i;                             /* last nonzero coeffs */
-                zbin_boost_ptr = b->zrun_zbin_boost; /* reset zero runlength */
-            }
-        }
-    }
-
-    *d->eob = (char)(eob + 1);
-}
-
-void vp8_quantize_mby(MACROBLOCK *x)
-{
-    int i;
-    int has_2nd_order = (x->e_mbd.mode_info_context->mbmi.mode != B_PRED
-        && x->e_mbd.mode_info_context->mbmi.mode != SPLITMV);
-
-    for (i = 0; i < 16; i++)
-        x->quantize_b(&x->block[i], &x->e_mbd.block[i]);
-
-    if(has_2nd_order)
-        x->quantize_b(&x->block[24], &x->e_mbd.block[24]);
-}
-
-void vp8_quantize_mb(MACROBLOCK *x)
-{
-    int i;
-    int has_2nd_order=(x->e_mbd.mode_info_context->mbmi.mode != B_PRED
-        && x->e_mbd.mode_info_context->mbmi.mode != SPLITMV);
-
-    for (i = 0; i < 24+has_2nd_order; i++)
-        x->quantize_b(&x->block[i], &x->e_mbd.block[i]);
-}
-
-
-void vp8_quantize_mbuv(MACROBLOCK *x)
-{
-    int i;
-
-    for (i = 16; i < 24; i++)
-        x->quantize_b(&x->block[i], &x->e_mbd.block[i]);
-}
-
-static const int qrounding_factors[129] =
-{
-    48, 48, 48, 48, 48, 48, 48, 48,
-    48, 48, 48, 48, 48, 48, 48, 48,
-    48, 48, 48, 48, 48, 48, 48, 48,
-    48, 48, 48, 48, 48, 48, 48, 48,
-    48, 48, 48, 48, 48, 48, 48, 48,
-    48, 48, 48, 48, 48, 48, 48, 48,
-    48, 48, 48, 48, 48, 48, 48, 48,
-    48, 48, 48, 48, 48, 48, 48, 48,
-    48, 48, 48, 48, 48, 48, 48, 48,
-    48, 48, 48, 48, 48, 48, 48, 48,
-    48, 48, 48, 48, 48, 48, 48, 48,
-    48, 48, 48, 48, 48, 48, 48, 48,
-    48, 48, 48, 48, 48, 48, 48, 48,
-    48, 48, 48, 48, 48, 48, 48, 48,
-    48, 48, 48, 48, 48, 48, 48, 48,
-    48, 48, 48, 48, 48, 48, 48, 48,
-    48
-};
-
-
-static const int qzbin_factors[129] =
-{
-    84, 84, 84, 84, 84, 84, 84, 84,
-    84, 84, 84, 84, 84, 84, 84, 84,
-    84, 84, 84, 84, 84, 84, 84, 84,
-    84, 84, 84, 84, 84, 84, 84, 84,
-    84, 84, 84, 84, 84, 84, 84, 84,
-    84, 84, 84, 84, 84, 84, 84, 84,
-    80, 80, 80, 80, 80, 80, 80, 80,
-    80, 80, 80, 80, 80, 80, 80, 80,
-    80, 80, 80, 80, 80, 80, 80, 80,
-    80, 80, 80, 80, 80, 80, 80, 80,
-    80, 80, 80, 80, 80, 80, 80, 80,
-    80, 80, 80, 80, 80, 80, 80, 80,
-    80, 80, 80, 80, 80, 80, 80, 80,
-    80, 80, 80, 80, 80, 80, 80, 80,
-    80, 80, 80, 80, 80, 80, 80, 80,
-    80, 80, 80, 80, 80, 80, 80, 80,
-    80
-};
-
-
-static const int qrounding_factors_y2[129] =
-{
-    48, 48, 48, 48, 48, 48, 48, 48,
-    48, 48, 48, 48, 48, 48, 48, 48,
-    48, 48, 48, 48, 48, 48, 48, 48,
-    48, 48, 48, 48, 48, 48, 48, 48,
-    48, 48, 48, 48, 48, 48, 48, 48,
-    48, 48, 48, 48, 48, 48, 48, 48,
-    48, 48, 48, 48, 48, 48, 48, 48,
-    48, 48, 48, 48, 48, 48, 48, 48,
-    48, 48, 48, 48, 48, 48, 48, 48,
-    48, 48, 48, 48, 48, 48, 48, 48,
-    48, 48, 48, 48, 48, 48, 48, 48,
-    48, 48, 48, 48, 48, 48, 48, 48,
-    48, 48, 48, 48, 48, 48, 48, 48,
-    48, 48, 48, 48, 48, 48, 48, 48,
-    48, 48, 48, 48, 48, 48, 48, 48,
-    48, 48, 48, 48, 48, 48, 48, 48,
-    48
-};
-
-
-static const int qzbin_factors_y2[129] =
-{
-    84, 84, 84, 84, 84, 84, 84, 84,
-    84, 84, 84, 84, 84, 84, 84, 84,
-    84, 84, 84, 84, 84, 84, 84, 84,
-    84, 84, 84, 84, 84, 84, 84, 84,
-    84, 84, 84, 84, 84, 84, 84, 84,
-    84, 84, 84, 84, 84, 84, 84, 84,
-    80, 80, 80, 80, 80, 80, 80, 80,
-    80, 80, 80, 80, 80, 80, 80, 80,
-    80, 80, 80, 80, 80, 80, 80, 80,
-    80, 80, 80, 80, 80, 80, 80, 80,
-    80, 80, 80, 80, 80, 80, 80, 80,
-    80, 80, 80, 80, 80, 80, 80, 80,
-    80, 80, 80, 80, 80, 80, 80, 80,
-    80, 80, 80, 80, 80, 80, 80, 80,
-    80, 80, 80, 80, 80, 80, 80, 80,
-    80, 80, 80, 80, 80, 80, 80, 80,
-    80
-};
-
-
-static void invert_quant(int improved_quant, short *quant,
-                         short *shift, short d)
-{
-    if(improved_quant)
-    {
-        unsigned t;
-        int l, m;
-        t = d;
-        for(l = 0; t > 1; l++)
-            t>>=1;
-        m = 1 + (1<<(16+l))/d;
-        *quant = (short)(m - (1<<16));
-        *shift = l;
-        /* use multiplication and constant shift by 16 */
-        *shift = 1 << (16 - *shift);
-    }
-    else
-    {
-        *quant = (1 << 16) / d;
-        *shift = 0;
-        /* use multiplication and constant shift by 16 */
-        *shift = 1 << (16 - *shift);
-    }
-}
-
-
-void vp8cx_init_quantizer(VP8_COMP *cpi)
-{
-    int i;
-    int quant_val;
-    int Q;
-
-    int zbin_boost[16] = {0, 0, 8, 10, 12, 14, 16, 20, 24, 28, 32, 36, 40, 44,
-                          44, 44};
-
-    for (Q = 0; Q < QINDEX_RANGE; Q++)
-    {
-        /* dc values */
-        quant_val = vp8_dc_quant(Q, cpi->common.y1dc_delta_q);
-        cpi->Y1quant_fast[Q][0] = (1 << 16) / quant_val;
-        invert_quant(cpi->sf.improved_quant, cpi->Y1quant[Q] + 0,
-                     cpi->Y1quant_shift[Q] + 0, quant_val);
-        cpi->Y1zbin[Q][0] = ((qzbin_factors[Q] * quant_val) + 64) >> 7;
-        cpi->Y1round[Q][0] = (qrounding_factors[Q] * quant_val) >> 7;
-        cpi->common.Y1dequant[Q][0] = quant_val;
-        cpi->zrun_zbin_boost_y1[Q][0] = (quant_val * zbin_boost[0]) >> 7;
-
-        quant_val = vp8_dc2quant(Q, cpi->common.y2dc_delta_q);
-        cpi->Y2quant_fast[Q][0] = (1 << 16) / quant_val;
-        invert_quant(cpi->sf.improved_quant, cpi->Y2quant[Q] + 0,
-                     cpi->Y2quant_shift[Q] + 0, quant_val);
-        cpi->Y2zbin[Q][0] = ((qzbin_factors_y2[Q] * quant_val) + 64) >> 7;
-        cpi->Y2round[Q][0] = (qrounding_factors_y2[Q] * quant_val) >> 7;
-        cpi->common.Y2dequant[Q][0] = quant_val;
-        cpi->zrun_zbin_boost_y2[Q][0] = (quant_val * zbin_boost[0]) >> 7;
-
-        quant_val = vp8_dc_uv_quant(Q, cpi->common.uvdc_delta_q);
-        cpi->UVquant_fast[Q][0] = (1 << 16) / quant_val;
-        invert_quant(cpi->sf.improved_quant, cpi->UVquant[Q] + 0,
-                     cpi->UVquant_shift[Q] + 0, quant_val);
-        cpi->UVzbin[Q][0] = ((qzbin_factors[Q] * quant_val) + 64) >> 7;;
-        cpi->UVround[Q][0] = (qrounding_factors[Q] * quant_val) >> 7;
-        cpi->common.UVdequant[Q][0] = quant_val;
-        cpi->zrun_zbin_boost_uv[Q][0] = (quant_val * zbin_boost[0]) >> 7;
-
-        /* all the ac values = ; */
-        quant_val = vp8_ac_yquant(Q);
-        cpi->Y1quant_fast[Q][1] = (1 << 16) / quant_val;
-        invert_quant(cpi->sf.improved_quant, cpi->Y1quant[Q] + 1,
-                     cpi->Y1quant_shift[Q] + 1, quant_val);
-        cpi->Y1zbin[Q][1] = ((qzbin_factors[Q] * quant_val) + 64) >> 7;
-        cpi->Y1round[Q][1] = (qrounding_factors[Q] * quant_val) >> 7;
-        cpi->common.Y1dequant[Q][1] = quant_val;
-        cpi->zrun_zbin_boost_y1[Q][1] = (quant_val * zbin_boost[1]) >> 7;
-
-        quant_val = vp8_ac2quant(Q, cpi->common.y2ac_delta_q);
-        cpi->Y2quant_fast[Q][1] = (1 << 16) / quant_val;
-        invert_quant(cpi->sf.improved_quant, cpi->Y2quant[Q] + 1,
-                     cpi->Y2quant_shift[Q] + 1, quant_val);
-        cpi->Y2zbin[Q][1] = ((qzbin_factors_y2[Q] * quant_val) + 64) >> 7;
-        cpi->Y2round[Q][1] = (qrounding_factors_y2[Q] * quant_val) >> 7;
-        cpi->common.Y2dequant[Q][1] = quant_val;
-        cpi->zrun_zbin_boost_y2[Q][1] = (quant_val * zbin_boost[1]) >> 7;
-
-        quant_val = vp8_ac_uv_quant(Q, cpi->common.uvac_delta_q);
-        cpi->UVquant_fast[Q][1] = (1 << 16) / quant_val;
-        invert_quant(cpi->sf.improved_quant, cpi->UVquant[Q] + 1,
-                     cpi->UVquant_shift[Q] + 1, quant_val);
-        cpi->UVzbin[Q][1] = ((qzbin_factors[Q] * quant_val) + 64) >> 7;
-        cpi->UVround[Q][1] = (qrounding_factors[Q] * quant_val) >> 7;
-        cpi->common.UVdequant[Q][1] = quant_val;
-        cpi->zrun_zbin_boost_uv[Q][1] = (quant_val * zbin_boost[1]) >> 7;
-
-        for (i = 2; i < 16; i++)
-        {
-            cpi->Y1quant_fast[Q][i] = cpi->Y1quant_fast[Q][1];
-            cpi->Y1quant[Q][i] = cpi->Y1quant[Q][1];
-            cpi->Y1quant_shift[Q][i] = cpi->Y1quant_shift[Q][1];
-            cpi->Y1zbin[Q][i] = cpi->Y1zbin[Q][1];
-            cpi->Y1round[Q][i] = cpi->Y1round[Q][1];
-            cpi->zrun_zbin_boost_y1[Q][i] = (cpi->common.Y1dequant[Q][1] *
-                                             zbin_boost[i]) >> 7;
-
-            cpi->Y2quant_fast[Q][i] = cpi->Y2quant_fast[Q][1];
-            cpi->Y2quant[Q][i] = cpi->Y2quant[Q][1];
-            cpi->Y2quant_shift[Q][i] = cpi->Y2quant_shift[Q][1];
-            cpi->Y2zbin[Q][i] = cpi->Y2zbin[Q][1];
-            cpi->Y2round[Q][i] = cpi->Y2round[Q][1];
-            cpi->zrun_zbin_boost_y2[Q][i] = (cpi->common.Y2dequant[Q][1] *
-                                             zbin_boost[i]) >> 7;
-
-            cpi->UVquant_fast[Q][i] = cpi->UVquant_fast[Q][1];
-            cpi->UVquant[Q][i] = cpi->UVquant[Q][1];
-            cpi->UVquant_shift[Q][i] = cpi->UVquant_shift[Q][1];
-            cpi->UVzbin[Q][i] = cpi->UVzbin[Q][1];
-            cpi->UVround[Q][i] = cpi->UVround[Q][1];
-            cpi->zrun_zbin_boost_uv[Q][i] = (cpi->common.UVdequant[Q][1] *
-                                             zbin_boost[i]) >> 7;
-        }
-    }
-}
-
-#define ZBIN_EXTRA_Y \
-    (( cpi->common.Y1dequant[QIndex][1] *  \
-    ( x->zbin_over_quant +  \
-      x->zbin_mode_boost +  \
-      x->act_zbin_adj ) ) >> 7)
-
-#define ZBIN_EXTRA_UV \
-    (( cpi->common.UVdequant[QIndex][1] *  \
-    ( x->zbin_over_quant +  \
-      x->zbin_mode_boost +  \
-      x->act_zbin_adj ) ) >> 7)
-
-#define ZBIN_EXTRA_Y2 \
-    (( cpi->common.Y2dequant[QIndex][1] *  \
-    ( (x->zbin_over_quant / 2) +  \
-       x->zbin_mode_boost +  \
-       x->act_zbin_adj ) ) >> 7)
-
-void vp8cx_mb_init_quantizer(VP8_COMP *cpi, MACROBLOCK *x, int ok_to_skip)
-{
-    int i;
-    int QIndex;
-    MACROBLOCKD *xd = &x->e_mbd;
-    int zbin_extra;
-
-    /* Select the baseline MB Q index. */
-    if (xd->segmentation_enabled)
-    {
-        /* Abs Value */
-        if (xd->mb_segement_abs_delta == SEGMENT_ABSDATA)
-            QIndex = xd->segment_feature_data[MB_LVL_ALT_Q][xd->mode_info_context->mbmi.segment_id];
-        /* Delta Value */
-        else
-        {
-            QIndex = cpi->common.base_qindex + xd->segment_feature_data[MB_LVL_ALT_Q][xd->mode_info_context->mbmi.segment_id];
-            /* Clamp to valid range */
-            QIndex = (QIndex >= 0) ? ((QIndex <= MAXQ) ? QIndex : MAXQ) : 0;
-        }
-    }
-    else
-        QIndex = cpi->common.base_qindex;
-
-    /* This initialization should be called at least once. Use ok_to_skip to
-     * decide if it is ok to skip.
-     * Before encoding a frame, this function is always called with ok_to_skip
-     * =0, which means no skiping of calculations. The "last" values are
-     * initialized at that time.
-     */
-    if (!ok_to_skip || QIndex != x->q_index)
-    {
-
-        xd->dequant_y1_dc[0] = 1;
-        xd->dequant_y1[0] = cpi->common.Y1dequant[QIndex][0];
-        xd->dequant_y2[0] = cpi->common.Y2dequant[QIndex][0];
-        xd->dequant_uv[0] = cpi->common.UVdequant[QIndex][0];
-
-        for (i = 1; i < 16; i++)
-        {
-            xd->dequant_y1_dc[i] =
-            xd->dequant_y1[i] = cpi->common.Y1dequant[QIndex][1];
-            xd->dequant_y2[i] = cpi->common.Y2dequant[QIndex][1];
-            xd->dequant_uv[i] = cpi->common.UVdequant[QIndex][1];
-        }
-#if 1
-        /*TODO:  Remove dequant from BLOCKD.  This is a temporary solution until
-         * the quantizer code uses a passed in pointer to the dequant constants.
-         * This will also require modifications to the x86 and neon assembly.
-         * */
-        for (i = 0; i < 16; i++)
-            x->e_mbd.block[i].dequant = xd->dequant_y1;
-        for (i = 16; i < 24; i++)
-            x->e_mbd.block[i].dequant = xd->dequant_uv;
-        x->e_mbd.block[24].dequant = xd->dequant_y2;
-#endif
-
-        /* Y */
-        zbin_extra = ZBIN_EXTRA_Y;
-
-        for (i = 0; i < 16; i++)
-        {
-            x->block[i].quant = cpi->Y1quant[QIndex];
-            x->block[i].quant_fast = cpi->Y1quant_fast[QIndex];
-            x->block[i].quant_shift = cpi->Y1quant_shift[QIndex];
-            x->block[i].zbin = cpi->Y1zbin[QIndex];
-            x->block[i].round = cpi->Y1round[QIndex];
-            x->block[i].zrun_zbin_boost = cpi->zrun_zbin_boost_y1[QIndex];
-            x->block[i].zbin_extra = (short)zbin_extra;
-        }
-
-        /* UV */
-        zbin_extra = ZBIN_EXTRA_UV;
-
-        for (i = 16; i < 24; i++)
-        {
-            x->block[i].quant = cpi->UVquant[QIndex];
-            x->block[i].quant_fast = cpi->UVquant_fast[QIndex];
-            x->block[i].quant_shift = cpi->UVquant_shift[QIndex];
-            x->block[i].zbin = cpi->UVzbin[QIndex];
-            x->block[i].round = cpi->UVround[QIndex];
-            x->block[i].zrun_zbin_boost = cpi->zrun_zbin_boost_uv[QIndex];
-            x->block[i].zbin_extra = (short)zbin_extra;
-        }
-
-        /* Y2 */
-        zbin_extra = ZBIN_EXTRA_Y2;
-
-        x->block[24].quant_fast = cpi->Y2quant_fast[QIndex];
-        x->block[24].quant = cpi->Y2quant[QIndex];
-        x->block[24].quant_shift = cpi->Y2quant_shift[QIndex];
-        x->block[24].zbin = cpi->Y2zbin[QIndex];
-        x->block[24].round = cpi->Y2round[QIndex];
-        x->block[24].zrun_zbin_boost = cpi->zrun_zbin_boost_y2[QIndex];
-        x->block[24].zbin_extra = (short)zbin_extra;
-
-        /* save this macroblock QIndex for vp8_update_zbin_extra() */
-        x->q_index = QIndex;
-
-        x->last_zbin_over_quant = x->zbin_over_quant;
-        x->last_zbin_mode_boost = x->zbin_mode_boost;
-        x->last_act_zbin_adj = x->act_zbin_adj;
-
-
-
-    }
-    else if(x->last_zbin_over_quant != x->zbin_over_quant
-            || x->last_zbin_mode_boost != x->zbin_mode_boost
-            || x->last_act_zbin_adj != x->act_zbin_adj)
-    {
-        /* Y */
-        zbin_extra = ZBIN_EXTRA_Y;
-
-        for (i = 0; i < 16; i++)
-            x->block[i].zbin_extra = (short)zbin_extra;
-
-        /* UV */
-        zbin_extra = ZBIN_EXTRA_UV;
-
-        for (i = 16; i < 24; i++)
-            x->block[i].zbin_extra = (short)zbin_extra;
-
-        /* Y2 */
-        zbin_extra = ZBIN_EXTRA_Y2;
-        x->block[24].zbin_extra = (short)zbin_extra;
-
-        x->last_zbin_over_quant = x->zbin_over_quant;
-        x->last_zbin_mode_boost = x->zbin_mode_boost;
-        x->last_act_zbin_adj = x->act_zbin_adj;
-    }
-}
-
-void vp8_update_zbin_extra(VP8_COMP *cpi, MACROBLOCK *x)
-{
-    int i;
-    int QIndex = x->q_index;
-    int zbin_extra;
-
-    /* Y */
-    zbin_extra = ZBIN_EXTRA_Y;
-
-    for (i = 0; i < 16; i++)
-        x->block[i].zbin_extra = (short)zbin_extra;
-
-    /* UV */
-    zbin_extra = ZBIN_EXTRA_UV;
-
-    for (i = 16; i < 24; i++)
-        x->block[i].zbin_extra = (short)zbin_extra;
-
-    /* Y2 */
-    zbin_extra = ZBIN_EXTRA_Y2;
-    x->block[24].zbin_extra = (short)zbin_extra;
-}
-#undef ZBIN_EXTRA_Y
-#undef ZBIN_EXTRA_UV
-#undef ZBIN_EXTRA_Y2
-
-void vp8cx_frame_init_quantizer(VP8_COMP *cpi)
-{
-    /* Clear Zbin mode boost for default case */
-    cpi->mb.zbin_mode_boost = 0;
-
-    /* MB level quantizer setup */
-    vp8cx_mb_init_quantizer(cpi, &cpi->mb, 0);
-}
-
-
-void vp8_set_quantizer(struct VP8_COMP *cpi, int Q)
-{
-    VP8_COMMON *cm = &cpi->common;
-    MACROBLOCKD *mbd = &cpi->mb.e_mbd;
-    int update = 0;
-    int new_delta_q;
-    int new_uv_delta_q;
-    cm->base_qindex = Q;
-
-    /* if any of the delta_q values are changing update flag has to be set */
-    /* currently only y2dc_delta_q may change */
-
-    cm->y1dc_delta_q = 0;
-    cm->y2ac_delta_q = 0;
-
-    if (Q < 4)
-    {
-        new_delta_q = 4-Q;
-    }
-    else
-        new_delta_q = 0;
-
-    update |= cm->y2dc_delta_q != new_delta_q;
-    cm->y2dc_delta_q = new_delta_q;
-
-    new_uv_delta_q = 0;
-    // For screen content, lower the q value for UV channel. For now, select
-    // conservative delta; same delta for dc and ac, and decrease it with lower
-    // Q, and set to 0 below some threshold. May want to condition this in
-    // future on the variance/energy in UV channel.
-    if (cpi->oxcf.screen_content_mode && Q > 40) {
-      new_uv_delta_q = -(int)(0.15 * Q);
-      // Check range: magnitude of delta is 4 bits.
-      if (new_uv_delta_q < -15) {
-        new_uv_delta_q = -15;
-      }
-    }
-    update |= cm->uvdc_delta_q != new_uv_delta_q;
-    cm->uvdc_delta_q = new_uv_delta_q;
-    cm->uvac_delta_q = new_uv_delta_q;
-
-    /* Set Segment specific quatizers */
-    mbd->segment_feature_data[MB_LVL_ALT_Q][0] = cpi->segment_feature_data[MB_LVL_ALT_Q][0];
-    mbd->segment_feature_data[MB_LVL_ALT_Q][1] = cpi->segment_feature_data[MB_LVL_ALT_Q][1];
-    mbd->segment_feature_data[MB_LVL_ALT_Q][2] = cpi->segment_feature_data[MB_LVL_ALT_Q][2];
-    mbd->segment_feature_data[MB_LVL_ALT_Q][3] = cpi->segment_feature_data[MB_LVL_ALT_Q][3];
-
-    /* quantizer has to be reinitialized for any delta_q changes */
-    if(update)
-        vp8cx_init_quantizer(cpi);
-
-}
diff --git a/vp8/encoder/x86/dct_mmx.asm b/vp8/encoder/x86/dct_mmx.asm
deleted file mode 100644 (file)
index 6f188cb..0000000
+++ /dev/null
@@ -1,241 +0,0 @@
-;
-;  Copyright (c) 2010 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.
-;
-
-
-%include "vpx_ports/x86_abi_support.asm"
-
-;void vp8_short_fdct4x4_mmx(short *input, short *output, int pitch)
-global sym(vp8_short_fdct4x4_mmx) PRIVATE
-sym(vp8_short_fdct4x4_mmx):
-    push        rbp
-    mov         rbp,        rsp
-    SHADOW_ARGS_TO_STACK 3
-    GET_GOT     rbx
-    push        rsi
-    push        rdi
-    ; end prolog
-
-        mov         rsi,        arg(0)      ; input
-        mov         rdi,        arg(1)      ; output
-
-        movsxd      rax,        dword ptr arg(2) ;pitch
-
-        lea         rcx,        [rsi + rax*2]
-        ; read the input data
-        movq        mm0,        [rsi]
-        movq        mm1,        [rsi + rax]
-
-        movq        mm2,        [rcx]
-        movq        mm4,        [rcx + rax]
-
-        ; transpose for the first stage
-        movq        mm3,        mm0         ; 00 01 02 03
-        movq        mm5,        mm2         ; 20 21 22 23
-
-        punpcklwd   mm0,        mm1         ; 00 10 01 11
-        punpckhwd   mm3,        mm1         ; 02 12 03 13
-
-        punpcklwd   mm2,        mm4         ; 20 30 21 31
-        punpckhwd   mm5,        mm4         ; 22 32 23 33
-
-        movq        mm1,        mm0         ; 00 10 01 11
-        punpckldq   mm0,        mm2         ; 00 10 20 30
-
-        punpckhdq   mm1,        mm2         ; 01 11 21 31
-
-        movq        mm2,        mm3         ; 02 12 03 13
-        punpckldq   mm2,        mm5         ; 02 12 22 32
-
-        punpckhdq   mm3,        mm5         ; 03 13 23 33
-
-        ; mm0 0
-        ; mm1 1
-        ; mm2 2
-        ; mm3 3
-
-        ; first stage
-        movq        mm5,        mm0
-        movq        mm4,        mm1
-
-        paddw       mm0,        mm3         ; a1 = 0 + 3
-        paddw       mm1,        mm2         ; b1 = 1 + 2
-
-        psubw       mm4,        mm2         ; c1 = 1 - 2
-        psubw       mm5,        mm3         ; d1 = 0 - 3
-
-        psllw       mm5,        3
-        psllw       mm4,        3
-
-        psllw       mm0,        3
-        psllw       mm1,        3
-
-        ; output 0 and 2
-        movq        mm2,        mm0         ; a1
-
-        paddw       mm0,        mm1         ; op[0] = a1 + b1
-        psubw       mm2,        mm1         ; op[2] = a1 - b1
-
-        ; output 1 and 3
-        ; interleave c1, d1
-        movq        mm1,        mm5         ; d1
-        punpcklwd   mm1,        mm4         ; c1 d1
-        punpckhwd   mm5,        mm4         ; c1 d1
-
-        movq        mm3,        mm1
-        movq        mm4,        mm5
-
-        pmaddwd     mm1,        MMWORD PTR[GLOBAL (_5352_2217)]    ; c1*2217 + d1*5352
-        pmaddwd     mm4,        MMWORD PTR[GLOBAL (_5352_2217)]    ; c1*2217 + d1*5352
-
-        pmaddwd     mm3,        MMWORD PTR[GLOBAL(_2217_neg5352)]  ; d1*2217 - c1*5352
-        pmaddwd     mm5,        MMWORD PTR[GLOBAL(_2217_neg5352)]  ; d1*2217 - c1*5352
-
-        paddd       mm1,        MMWORD PTR[GLOBAL(_14500)]
-        paddd       mm4,        MMWORD PTR[GLOBAL(_14500)]
-        paddd       mm3,        MMWORD PTR[GLOBAL(_7500)]
-        paddd       mm5,        MMWORD PTR[GLOBAL(_7500)]
-
-        psrad       mm1,        12          ; (c1 * 2217 + d1 * 5352 +  14500)>>12
-        psrad       mm4,        12          ; (c1 * 2217 + d1 * 5352 +  14500)>>12
-        psrad       mm3,        12          ; (d1 * 2217 - c1 * 5352 +   7500)>>12
-        psrad       mm5,        12          ; (d1 * 2217 - c1 * 5352 +   7500)>>12
-
-        packssdw    mm1,        mm4         ; op[1]
-        packssdw    mm3,        mm5         ; op[3]
-
-        ; done with vertical
-        ; transpose for the second stage
-        movq        mm4,        mm0         ; 00 10 20 30
-        movq        mm5,        mm2         ; 02 12 22 32
-
-        punpcklwd   mm0,        mm1         ; 00 01 10 11
-        punpckhwd   mm4,        mm1         ; 20 21 30 31
-
-        punpcklwd   mm2,        mm3         ; 02 03 12 13
-        punpckhwd   mm5,        mm3         ; 22 23 32 33
-
-        movq        mm1,        mm0         ; 00 01 10 11
-        punpckldq   mm0,        mm2         ; 00 01 02 03
-
-        punpckhdq   mm1,        mm2         ; 01 22 12 13
-
-        movq        mm2,        mm4         ; 20 31 30 31
-        punpckldq   mm2,        mm5         ; 20 21 22 23
-
-        punpckhdq   mm4,        mm5         ; 30 31 32 33
-
-        ; mm0 0
-        ; mm1 1
-        ; mm2 2
-        ; mm3 4
-
-        movq        mm5,        mm0
-        movq        mm3,        mm1
-
-        paddw       mm0,        mm4         ; a1 = 0 + 3
-        paddw       mm1,        mm2         ; b1 = 1 + 2
-
-        psubw       mm3,        mm2         ; c1 = 1 - 2
-        psubw       mm5,        mm4         ; d1 = 0 - 3
-
-        pxor        mm6,        mm6         ; zero out for compare
-
-        pcmpeqw     mm6,        mm5         ; d1 != 0
-
-        pandn       mm6,        MMWORD PTR[GLOBAL(_cmp_mask)]   ; clear upper,
-                                                                ; and keep bit 0 of lower
-
-        ; output 0 and 2
-        movq        mm2,        mm0         ; a1
-
-        paddw       mm0,        mm1         ; a1 + b1
-        psubw       mm2,        mm1         ; a1 - b1
-
-        paddw       mm0,        MMWORD PTR[GLOBAL(_7w)]
-        paddw       mm2,        MMWORD PTR[GLOBAL(_7w)]
-
-        psraw       mm0,        4           ; op[0] = (a1 + b1 + 7)>>4
-        psraw       mm2,        4           ; op[8] = (a1 - b1 + 7)>>4
-
-        movq        MMWORD PTR[rdi + 0 ],  mm0
-        movq        MMWORD PTR[rdi + 16],  mm2
-
-        ; output 1 and 3
-        ; interleave c1, d1
-        movq        mm1,        mm5         ; d1
-        punpcklwd   mm1,        mm3         ; c1 d1
-        punpckhwd   mm5,        mm3         ; c1 d1
-
-        movq        mm3,        mm1
-        movq        mm4,        mm5
-
-        pmaddwd     mm1,        MMWORD PTR[GLOBAL (_5352_2217)]    ; c1*2217 + d1*5352
-        pmaddwd     mm4,        MMWORD PTR[GLOBAL (_5352_2217)]    ; c1*2217 + d1*5352
-
-        pmaddwd     mm3,        MMWORD PTR[GLOBAL(_2217_neg5352)]  ; d1*2217 - c1*5352
-        pmaddwd     mm5,        MMWORD PTR[GLOBAL(_2217_neg5352)]  ; d1*2217 - c1*5352
-
-        paddd       mm1,        MMWORD PTR[GLOBAL(_12000)]
-        paddd       mm4,        MMWORD PTR[GLOBAL(_12000)]
-        paddd       mm3,        MMWORD PTR[GLOBAL(_51000)]
-        paddd       mm5,        MMWORD PTR[GLOBAL(_51000)]
-
-        psrad       mm1,        16          ; (c1 * 2217 + d1 * 5352 +  14500)>>16
-        psrad       mm4,        16          ; (c1 * 2217 + d1 * 5352 +  14500)>>16
-        psrad       mm3,        16          ; (d1 * 2217 - c1 * 5352 +   7500)>>16
-        psrad       mm5,        16          ; (d1 * 2217 - c1 * 5352 +   7500)>>16
-
-        packssdw    mm1,        mm4         ; op[4]
-        packssdw    mm3,        mm5         ; op[12]
-
-        paddw       mm1,        mm6         ; op[4] += (d1!=0)
-
-        movq        MMWORD PTR[rdi + 8 ],  mm1
-        movq        MMWORD PTR[rdi + 24],  mm3
-
-     ; begin epilog
-    pop         rdi
-    pop         rsi
-    RESTORE_GOT
-    UNSHADOW_ARGS
-    pop         rbp
-    ret
-
-SECTION_RODATA
-align 8
-_5352_2217:
-    dw 5352
-    dw 2217
-    dw 5352
-    dw 2217
-align 8
-_2217_neg5352:
-    dw 2217
-    dw -5352
-    dw 2217
-    dw -5352
-align 8
-_cmp_mask:
-    times 4 dw 1
-align 8
-_7w:
-    times 4 dw 7
-align 8
-_14500:
-    times 2 dd 14500
-align 8
-_7500:
-    times 2 dd 7500
-align 8
-_12000:
-    times 2 dd 12000
-align 8
-_51000:
-    times 2 dd 51000
diff --git a/vp8/encoder/x86/dct_sse2.asm b/vp8/encoder/x86/dct_sse2.asm
deleted file mode 100644 (file)
index d06bca5..0000000
+++ /dev/null
@@ -1,432 +0,0 @@
-;
-;  Copyright (c) 2010 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.
-;
-
-
-%include "vpx_ports/x86_abi_support.asm"
-
-%macro STACK_FRAME_CREATE 0
-%if ABI_IS_32BIT
-  %define       input       rsi
-  %define       output      rdi
-  %define       pitch       rax
-    push        rbp
-    mov         rbp, rsp
-    GET_GOT     rbx
-    push        rsi
-    push        rdi
-    ; end prolog
-
-    mov         rsi, arg(0)
-    mov         rdi, arg(1)
-
-    movsxd      rax, dword ptr arg(2)
-    lea         rcx, [rsi + rax*2]
-%else
-  %if LIBVPX_YASM_WIN64
-    %define     input       rcx
-    %define     output      rdx
-    %define     pitch       r8
-    SAVE_XMM 7, u
-  %else
-    %define     input       rdi
-    %define     output      rsi
-    %define     pitch       rdx
-  %endif
-%endif
-%endmacro
-
-%macro STACK_FRAME_DESTROY 0
-  %define     input
-  %define     output
-  %define     pitch
-
-%if ABI_IS_32BIT
-    pop         rdi
-    pop         rsi
-    RESTORE_GOT
-    pop         rbp
-%else
-  %if LIBVPX_YASM_WIN64
-    RESTORE_XMM
-  %endif
-%endif
-    ret
-%endmacro
-
-;void vp8_short_fdct4x4_sse2(short *input, short *output, int pitch)
-global sym(vp8_short_fdct4x4_sse2) PRIVATE
-sym(vp8_short_fdct4x4_sse2):
-
-    STACK_FRAME_CREATE
-
-    movq        xmm0, MMWORD PTR[input        ] ;03 02 01 00
-    movq        xmm2, MMWORD PTR[input+  pitch] ;13 12 11 10
-    lea         input,          [input+2*pitch]
-    movq        xmm1, MMWORD PTR[input        ] ;23 22 21 20
-    movq        xmm3, MMWORD PTR[input+  pitch] ;33 32 31 30
-
-    punpcklqdq  xmm0, xmm2                      ;13 12 11 10 03 02 01 00
-    punpcklqdq  xmm1, xmm3                      ;33 32 31 30 23 22 21 20
-
-    movdqa      xmm2, xmm0
-    punpckldq   xmm0, xmm1                      ;23 22 03 02 21 20 01 00
-    punpckhdq   xmm2, xmm1                      ;33 32 13 12 31 30 11 10
-    movdqa      xmm1, xmm0
-    punpckldq   xmm0, xmm2                      ;31 21 30 20 11 10 01 00
-    pshufhw     xmm1, xmm1, 0b1h                ;22 23 02 03 xx xx xx xx
-    pshufhw     xmm2, xmm2, 0b1h                ;32 33 12 13 xx xx xx xx
-
-    punpckhdq   xmm1, xmm2                      ;32 33 22 23 12 13 02 03
-    movdqa      xmm3, xmm0
-    paddw       xmm0, xmm1                      ;b1 a1 b1 a1 b1 a1 b1 a1
-    psubw       xmm3, xmm1                      ;c1 d1 c1 d1 c1 d1 c1 d1
-    psllw       xmm0, 3                         ;b1 <<= 3 a1 <<= 3
-    psllw       xmm3, 3                         ;c1 <<= 3 d1 <<= 3
-
-    movdqa      xmm1, xmm0
-    pmaddwd     xmm0, XMMWORD PTR[GLOBAL(_mult_add)]    ;a1 + b1
-    pmaddwd     xmm1, XMMWORD PTR[GLOBAL(_mult_sub)]    ;a1 - b1
-    movdqa      xmm4, xmm3
-    pmaddwd     xmm3, XMMWORD PTR[GLOBAL(_5352_2217)]   ;c1*2217 + d1*5352
-    pmaddwd     xmm4, XMMWORD PTR[GLOBAL(_2217_neg5352)];d1*2217 - c1*5352
-
-    paddd       xmm3, XMMWORD PTR[GLOBAL(_14500)]
-    paddd       xmm4, XMMWORD PTR[GLOBAL(_7500)]
-    psrad       xmm3, 12            ;(c1 * 2217 + d1 * 5352 +  14500)>>12
-    psrad       xmm4, 12            ;(d1 * 2217 - c1 * 5352 +   7500)>>12
-
-    packssdw    xmm0, xmm1                      ;op[2] op[0]
-    packssdw    xmm3, xmm4                      ;op[3] op[1]
-    ; 23 22 21 20 03 02 01 00
-    ;
-    ; 33 32 31 30 13 12 11 10
-    ;
-    movdqa      xmm2, xmm0
-    punpcklqdq  xmm0, xmm3                      ;13 12 11 10 03 02 01 00
-    punpckhqdq  xmm2, xmm3                      ;23 22 21 20 33 32 31 30
-
-    movdqa      xmm3, xmm0
-    punpcklwd   xmm0, xmm2                      ;32 30 22 20 12 10 02 00
-    punpckhwd   xmm3, xmm2                      ;33 31 23 21 13 11 03 01
-    movdqa      xmm2, xmm0
-    punpcklwd   xmm0, xmm3                      ;13 12 11 10 03 02 01 00
-    punpckhwd   xmm2, xmm3                      ;33 32 31 30 23 22 21 20
-
-    movdqa      xmm5, XMMWORD PTR[GLOBAL(_7)]
-    pshufd      xmm2, xmm2, 04eh
-    movdqa      xmm3, xmm0
-    paddw       xmm0, xmm2                      ;b1 b1 b1 b1 a1 a1 a1 a1
-    psubw       xmm3, xmm2                      ;c1 c1 c1 c1 d1 d1 d1 d1
-
-    pshufd      xmm0, xmm0, 0d8h                ;b1 b1 a1 a1 b1 b1 a1 a1
-    movdqa      xmm2, xmm3                      ;save d1 for compare
-    pshufd      xmm3, xmm3, 0d8h                ;c1 c1 d1 d1 c1 c1 d1 d1
-    pshuflw     xmm0, xmm0, 0d8h                ;b1 b1 a1 a1 b1 a1 b1 a1
-    pshuflw     xmm3, xmm3, 0d8h                ;c1 c1 d1 d1 c1 d1 c1 d1
-    pshufhw     xmm0, xmm0, 0d8h                ;b1 a1 b1 a1 b1 a1 b1 a1
-    pshufhw     xmm3, xmm3, 0d8h                ;c1 d1 c1 d1 c1 d1 c1 d1
-    movdqa      xmm1, xmm0
-    pmaddwd     xmm0, XMMWORD PTR[GLOBAL(_mult_add)] ;a1 + b1
-    pmaddwd     xmm1, XMMWORD PTR[GLOBAL(_mult_sub)] ;a1 - b1
-
-    pxor        xmm4, xmm4                      ;zero out for compare
-    paddd       xmm0, xmm5
-    paddd       xmm1, xmm5
-    pcmpeqw     xmm2, xmm4
-    psrad       xmm0, 4                         ;(a1 + b1 + 7)>>4
-    psrad       xmm1, 4                         ;(a1 - b1 + 7)>>4
-    pandn       xmm2, XMMWORD PTR[GLOBAL(_cmp_mask)] ;clear upper,
-                                                     ;and keep bit 0 of lower
-
-    movdqa      xmm4, xmm3
-    pmaddwd     xmm3, XMMWORD PTR[GLOBAL(_5352_2217)]    ;c1*2217 + d1*5352
-    pmaddwd     xmm4, XMMWORD PTR[GLOBAL(_2217_neg5352)] ;d1*2217 - c1*5352
-    paddd       xmm3, XMMWORD PTR[GLOBAL(_12000)]
-    paddd       xmm4, XMMWORD PTR[GLOBAL(_51000)]
-    packssdw    xmm0, xmm1                      ;op[8] op[0]
-    psrad       xmm3, 16                ;(c1 * 2217 + d1 * 5352 +  12000)>>16
-    psrad       xmm4, 16                ;(d1 * 2217 - c1 * 5352 +  51000)>>16
-
-    packssdw    xmm3, xmm4                      ;op[12] op[4]
-    movdqa      xmm1, xmm0
-    paddw       xmm3, xmm2                      ;op[4] += (d1!=0)
-    punpcklqdq  xmm0, xmm3                      ;op[4] op[0]
-    punpckhqdq  xmm1, xmm3                      ;op[12] op[8]
-
-    movdqa      XMMWORD PTR[output +  0], xmm0
-    movdqa      XMMWORD PTR[output + 16], xmm1
-
-    STACK_FRAME_DESTROY
-
-;void vp8_short_fdct8x4_sse2(short *input, short *output, int pitch)
-global sym(vp8_short_fdct8x4_sse2) PRIVATE
-sym(vp8_short_fdct8x4_sse2):
-
-    STACK_FRAME_CREATE
-
-        ; read the input data
-        movdqa      xmm0,       [input        ]
-        movdqa      xmm2,       [input+  pitch]
-        lea         input,      [input+2*pitch]
-        movdqa      xmm4,       [input        ]
-        movdqa      xmm3,       [input+  pitch]
-
-        ; transpose for the first stage
-        movdqa      xmm1,       xmm0        ; 00 01 02 03 04 05 06 07
-        movdqa      xmm5,       xmm4        ; 20 21 22 23 24 25 26 27
-
-        punpcklwd   xmm0,       xmm2        ; 00 10 01 11 02 12 03 13
-        punpckhwd   xmm1,       xmm2        ; 04 14 05 15 06 16 07 17
-
-        punpcklwd   xmm4,       xmm3        ; 20 30 21 31 22 32 23 33
-        punpckhwd   xmm5,       xmm3        ; 24 34 25 35 26 36 27 37
-
-        movdqa      xmm2,       xmm0        ; 00 10 01 11 02 12 03 13
-        punpckldq   xmm0,       xmm4        ; 00 10 20 30 01 11 21 31
-
-        punpckhdq   xmm2,       xmm4        ; 02 12 22 32 03 13 23 33
-
-        movdqa      xmm4,       xmm1        ; 04 14 05 15 06 16 07 17
-        punpckldq   xmm4,       xmm5        ; 04 14 24 34 05 15 25 35
-
-        punpckhdq   xmm1,       xmm5        ; 06 16 26 36 07 17 27 37
-        movdqa      xmm3,       xmm2        ; 02 12 22 32 03 13 23 33
-
-        punpckhqdq  xmm3,       xmm1        ; 03 13 23 33 07 17 27 37
-        punpcklqdq  xmm2,       xmm1        ; 02 12 22 32 06 16 26 36
-
-        movdqa      xmm1,       xmm0        ; 00 10 20 30 01 11 21 31
-        punpcklqdq  xmm0,       xmm4        ; 00 10 20 30 04 14 24 34
-
-        punpckhqdq  xmm1,       xmm4        ; 01 11 21 32 05 15 25 35
-
-        ; xmm0 0
-        ; xmm1 1
-        ; xmm2 2
-        ; xmm3 3
-
-        ; first stage
-        movdqa      xmm5,       xmm0
-        movdqa      xmm4,       xmm1
-
-        paddw       xmm0,       xmm3        ; a1 = 0 + 3
-        paddw       xmm1,       xmm2        ; b1 = 1 + 2
-
-        psubw       xmm4,       xmm2        ; c1 = 1 - 2
-        psubw       xmm5,       xmm3        ; d1 = 0 - 3
-
-        psllw       xmm5,        3
-        psllw       xmm4,        3
-
-        psllw       xmm0,        3
-        psllw       xmm1,        3
-
-        ; output 0 and 2
-        movdqa      xmm2,       xmm0        ; a1
-
-        paddw       xmm0,       xmm1        ; op[0] = a1 + b1
-        psubw       xmm2,       xmm1        ; op[2] = a1 - b1
-
-        ; output 1 and 3
-        ; interleave c1, d1
-        movdqa      xmm1,       xmm5        ; d1
-        punpcklwd   xmm1,       xmm4        ; c1 d1
-        punpckhwd   xmm5,       xmm4        ; c1 d1
-
-        movdqa      xmm3,       xmm1
-        movdqa      xmm4,       xmm5
-
-        pmaddwd     xmm1,       XMMWORD PTR[GLOBAL (_5352_2217)]    ; c1*2217 + d1*5352
-        pmaddwd     xmm4,       XMMWORD PTR[GLOBAL (_5352_2217)]    ; c1*2217 + d1*5352
-
-        pmaddwd     xmm3,       XMMWORD PTR[GLOBAL(_2217_neg5352)]  ; d1*2217 - c1*5352
-        pmaddwd     xmm5,       XMMWORD PTR[GLOBAL(_2217_neg5352)]  ; d1*2217 - c1*5352
-
-        paddd       xmm1,       XMMWORD PTR[GLOBAL(_14500)]
-        paddd       xmm4,       XMMWORD PTR[GLOBAL(_14500)]
-        paddd       xmm3,       XMMWORD PTR[GLOBAL(_7500)]
-        paddd       xmm5,       XMMWORD PTR[GLOBAL(_7500)]
-
-        psrad       xmm1,       12          ; (c1 * 2217 + d1 * 5352 +  14500)>>12
-        psrad       xmm4,       12          ; (c1 * 2217 + d1 * 5352 +  14500)>>12
-        psrad       xmm3,       12          ; (d1 * 2217 - c1 * 5352 +   7500)>>12
-        psrad       xmm5,       12          ; (d1 * 2217 - c1 * 5352 +   7500)>>12
-
-        packssdw    xmm1,       xmm4        ; op[1]
-        packssdw    xmm3,       xmm5        ; op[3]
-
-        ; done with vertical
-        ; transpose for the second stage
-        movdqa      xmm4,       xmm0         ; 00 10 20 30 04 14 24 34
-        movdqa      xmm5,       xmm2         ; 02 12 22 32 06 16 26 36
-
-        punpcklwd   xmm0,       xmm1         ; 00 01 10 11 20 21 30 31
-        punpckhwd   xmm4,       xmm1         ; 04 05 14 15 24 25 34 35
-
-        punpcklwd   xmm2,       xmm3         ; 02 03 12 13 22 23 32 33
-        punpckhwd   xmm5,       xmm3         ; 06 07 16 17 26 27 36 37
-
-        movdqa      xmm1,       xmm0         ; 00 01 10 11 20 21 30 31
-        punpckldq   xmm0,       xmm2         ; 00 01 02 03 10 11 12 13
-
-        punpckhdq   xmm1,       xmm2         ; 20 21 22 23 30 31 32 33
-
-        movdqa      xmm2,       xmm4         ; 04 05 14 15 24 25 34 35
-        punpckldq   xmm2,       xmm5         ; 04 05 06 07 14 15 16 17
-
-        punpckhdq   xmm4,       xmm5         ; 24 25 26 27 34 35 36 37
-        movdqa      xmm3,       xmm1         ; 20 21 22 23 30 31 32 33
-
-        punpckhqdq  xmm3,       xmm4         ; 30 31 32 33 34 35 36 37
-        punpcklqdq  xmm1,       xmm4         ; 20 21 22 23 24 25 26 27
-
-        movdqa      xmm4,       xmm0         ; 00 01 02 03 10 11 12 13
-        punpcklqdq  xmm0,       xmm2         ; 00 01 02 03 04 05 06 07
-
-        punpckhqdq  xmm4,       xmm2         ; 10 11 12 13 14 15 16 17
-
-        ; xmm0 0
-        ; xmm1 4
-        ; xmm2 1
-        ; xmm3 3
-
-        movdqa      xmm5,       xmm0
-        movdqa      xmm2,       xmm1
-
-        paddw       xmm0,       xmm3        ; a1 = 0 + 3
-        paddw       xmm1,       xmm4        ; b1 = 1 + 2
-
-        psubw       xmm4,       xmm2        ; c1 = 1 - 2
-        psubw       xmm5,       xmm3        ; d1 = 0 - 3
-
-        pxor        xmm6,       xmm6        ; zero out for compare
-
-        pcmpeqw     xmm6,       xmm5        ; d1 != 0
-
-        pandn       xmm6,       XMMWORD PTR[GLOBAL(_cmp_mask8x4)]   ; clear upper,
-                                                                    ; and keep bit 0 of lower
-
-        ; output 0 and 2
-        movdqa      xmm2,       xmm0        ; a1
-
-        paddw       xmm0,       xmm1        ; a1 + b1
-        psubw       xmm2,       xmm1        ; a1 - b1
-
-        paddw       xmm0,       XMMWORD PTR[GLOBAL(_7w)]
-        paddw       xmm2,       XMMWORD PTR[GLOBAL(_7w)]
-
-        psraw       xmm0,       4           ; op[0] = (a1 + b1 + 7)>>4
-        psraw       xmm2,       4           ; op[8] = (a1 - b1 + 7)>>4
-
-        ; output 1 and 3
-        ; interleave c1, d1
-        movdqa      xmm1,       xmm5        ; d1
-        punpcklwd   xmm1,       xmm4        ; c1 d1
-        punpckhwd   xmm5,       xmm4        ; c1 d1
-
-        movdqa      xmm3,       xmm1
-        movdqa      xmm4,       xmm5
-
-        pmaddwd     xmm1,       XMMWORD PTR[GLOBAL (_5352_2217)]    ; c1*2217 + d1*5352
-        pmaddwd     xmm4,       XMMWORD PTR[GLOBAL (_5352_2217)]    ; c1*2217 + d1*5352
-
-        pmaddwd     xmm3,       XMMWORD PTR[GLOBAL(_2217_neg5352)]  ; d1*2217 - c1*5352
-        pmaddwd     xmm5,       XMMWORD PTR[GLOBAL(_2217_neg5352)]  ; d1*2217 - c1*5352
-
-        paddd       xmm1,       XMMWORD PTR[GLOBAL(_12000)]
-        paddd       xmm4,       XMMWORD PTR[GLOBAL(_12000)]
-        paddd       xmm3,       XMMWORD PTR[GLOBAL(_51000)]
-        paddd       xmm5,       XMMWORD PTR[GLOBAL(_51000)]
-
-        psrad       xmm1,       16          ; (c1 * 2217 + d1 * 5352 +  14500)>>16
-        psrad       xmm4,       16          ; (c1 * 2217 + d1 * 5352 +  14500)>>16
-        psrad       xmm3,       16          ; (d1 * 2217 - c1 * 5352 +   7500)>>16
-        psrad       xmm5,       16          ; (d1 * 2217 - c1 * 5352 +   7500)>>16
-
-        packssdw    xmm1,       xmm4        ; op[4]
-        packssdw    xmm3,       xmm5        ; op[12]
-
-        paddw       xmm1,       xmm6        ; op[4] += (d1!=0)
-
-        movdqa      xmm4,       xmm0
-        movdqa      xmm5,       xmm2
-
-        punpcklqdq  xmm0,       xmm1
-        punpckhqdq  xmm4,       xmm1
-
-        punpcklqdq  xmm2,       xmm3
-        punpckhqdq  xmm5,       xmm3
-
-        movdqa      XMMWORD PTR[output + 0 ],  xmm0
-        movdqa      XMMWORD PTR[output + 16],  xmm2
-        movdqa      XMMWORD PTR[output + 32],  xmm4
-        movdqa      XMMWORD PTR[output + 48],  xmm5
-
-    STACK_FRAME_DESTROY
-
-SECTION_RODATA
-align 16
-_5352_2217:
-    dw 5352
-    dw 2217
-    dw 5352
-    dw 2217
-    dw 5352
-    dw 2217
-    dw 5352
-    dw 2217
-align 16
-_2217_neg5352:
-    dw 2217
-    dw -5352
-    dw 2217
-    dw -5352
-    dw 2217
-    dw -5352
-    dw 2217
-    dw -5352
-align 16
-_mult_add:
-    times 8 dw 1
-align 16
-_cmp_mask:
-    times 4 dw 1
-    times 4 dw 0
-align 16
-_cmp_mask8x4:
-    times 8 dw 1
-align 16
-_mult_sub:
-    dw 1
-    dw -1
-    dw 1
-    dw -1
-    dw 1
-    dw -1
-    dw 1
-    dw -1
-align 16
-_7:
-    times 4 dd 7
-align 16
-_7w:
-    times 8 dw 7
-align 16
-_14500:
-    times 4 dd 14500
-align 16
-_7500:
-    times 4 dd 7500
-align 16
-_12000:
-    times 4 dd 12000
-align 16
-_51000:
-    times 4 dd 51000
diff --git a/vp8/encoder/x86/denoising_sse2.c b/vp8/encoder/x86/denoising_sse2.c
deleted file mode 100644 (file)
index 101d646..0000000
+++ /dev/null
@@ -1,379 +0,0 @@
-/*
- *  Copyright (c) 2012 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.
- */
-
-#include "vp8/encoder/denoising.h"
-#include "vp8/common/reconinter.h"
-#include "vpx/vpx_integer.h"
-#include "vpx_mem/vpx_mem.h"
-#include "vp8_rtcd.h"
-
-#include <emmintrin.h>
-#include "vpx_ports/emmintrin_compat.h"
-
-/* Compute the sum of all pixel differences of this MB. */
-static INLINE unsigned int abs_sum_diff_16x1(__m128i acc_diff) {
-  const __m128i k_1 = _mm_set1_epi16(1);
-  const __m128i acc_diff_lo = _mm_srai_epi16(
-      _mm_unpacklo_epi8(acc_diff, acc_diff), 8);
-  const __m128i acc_diff_hi = _mm_srai_epi16(
-      _mm_unpackhi_epi8(acc_diff, acc_diff), 8);
-  const __m128i acc_diff_16 = _mm_add_epi16(acc_diff_lo, acc_diff_hi);
-  const __m128i hg_fe_dc_ba = _mm_madd_epi16(acc_diff_16, k_1);
-  const __m128i hgfe_dcba = _mm_add_epi32(hg_fe_dc_ba,
-                                          _mm_srli_si128(hg_fe_dc_ba, 8));
-  const __m128i hgfedcba = _mm_add_epi32(hgfe_dcba,
-                                         _mm_srli_si128(hgfe_dcba, 4));
-  unsigned int sum_diff = abs(_mm_cvtsi128_si32(hgfedcba));
-
-  return sum_diff;
-}
-
-int vp8_denoiser_filter_sse2(unsigned char *mc_running_avg_y,
-                             int mc_avg_y_stride,
-                             unsigned char *running_avg_y, int avg_y_stride,
-                             unsigned char *sig, int sig_stride,
-                             unsigned int motion_magnitude,
-                             int increase_denoising)
-{
-    unsigned char *running_avg_y_start = running_avg_y;
-    unsigned char *sig_start = sig;
-    unsigned int sum_diff_thresh;
-    int r;
-    int shift_inc  = (increase_denoising &&
-        motion_magnitude <= MOTION_MAGNITUDE_THRESHOLD) ? 1 : 0;
-    __m128i acc_diff = _mm_setzero_si128();
-    const __m128i k_0 = _mm_setzero_si128();
-    const __m128i k_4 = _mm_set1_epi8(4 + shift_inc);
-    const __m128i k_8 = _mm_set1_epi8(8);
-    const __m128i k_16 = _mm_set1_epi8(16);
-    /* Modify each level's adjustment according to motion_magnitude. */
-    const __m128i l3 = _mm_set1_epi8(
-                       (motion_magnitude <= MOTION_MAGNITUDE_THRESHOLD) ?
-                        7 + shift_inc : 6);
-    /* Difference between level 3 and level 2 is 2. */
-    const __m128i l32 = _mm_set1_epi8(2);
-    /* Difference between level 2 and level 1 is 1. */
-    const __m128i l21 = _mm_set1_epi8(1);
-
-    for (r = 0; r < 16; ++r)
-    {
-        /* Calculate differences */
-        const __m128i v_sig = _mm_loadu_si128((__m128i *)(&sig[0]));
-        const __m128i v_mc_running_avg_y = _mm_loadu_si128(
-                                           (__m128i *)(&mc_running_avg_y[0]));
-        __m128i v_running_avg_y;
-        const __m128i pdiff = _mm_subs_epu8(v_mc_running_avg_y, v_sig);
-        const __m128i ndiff = _mm_subs_epu8(v_sig, v_mc_running_avg_y);
-        /* Obtain the sign. FF if diff is negative. */
-        const __m128i diff_sign = _mm_cmpeq_epi8(pdiff, k_0);
-        /* Clamp absolute difference to 16 to be used to get mask. Doing this
-         * allows us to use _mm_cmpgt_epi8, which operates on signed byte. */
-        const __m128i clamped_absdiff = _mm_min_epu8(
-                                        _mm_or_si128(pdiff, ndiff), k_16);
-        /* Get masks for l2 l1 and l0 adjustments */
-        const __m128i mask2 = _mm_cmpgt_epi8(k_16, clamped_absdiff);
-        const __m128i mask1 = _mm_cmpgt_epi8(k_8, clamped_absdiff);
-        const __m128i mask0 = _mm_cmpgt_epi8(k_4, clamped_absdiff);
-        /* Get adjustments for l2, l1, and l0 */
-        __m128i adj2 = _mm_and_si128(mask2, l32);
-        const __m128i adj1 = _mm_and_si128(mask1, l21);
-        const __m128i adj0 = _mm_and_si128(mask0, clamped_absdiff);
-        __m128i adj,  padj, nadj;
-
-        /* Combine the adjustments and get absolute adjustments. */
-        adj2 = _mm_add_epi8(adj2, adj1);
-        adj = _mm_sub_epi8(l3, adj2);
-        adj = _mm_andnot_si128(mask0, adj);
-        adj = _mm_or_si128(adj, adj0);
-
-        /* Restore the sign and get positive and negative adjustments. */
-        padj = _mm_andnot_si128(diff_sign, adj);
-        nadj = _mm_and_si128(diff_sign, adj);
-
-        /* Calculate filtered value. */
-        v_running_avg_y = _mm_adds_epu8(v_sig, padj);
-        v_running_avg_y = _mm_subs_epu8(v_running_avg_y, nadj);
-        _mm_storeu_si128((__m128i *)running_avg_y, v_running_avg_y);
-
-        /* Adjustments <=7, and each element in acc_diff can fit in signed
-         * char.
-         */
-        acc_diff = _mm_adds_epi8(acc_diff, padj);
-        acc_diff = _mm_subs_epi8(acc_diff, nadj);
-
-        /* Update pointers for next iteration. */
-        sig += sig_stride;
-        mc_running_avg_y += mc_avg_y_stride;
-        running_avg_y += avg_y_stride;
-    }
-
-    {
-        /* Compute the sum of all pixel differences of this MB. */
-        unsigned int abs_sum_diff = abs_sum_diff_16x1(acc_diff);
-        sum_diff_thresh = SUM_DIFF_THRESHOLD;
-        if (increase_denoising) sum_diff_thresh = SUM_DIFF_THRESHOLD_HIGH;
-        if (abs_sum_diff > sum_diff_thresh) {
-          // Before returning to copy the block (i.e., apply no denoising),
-          // check if we can still apply some (weaker) temporal filtering to
-          // this block, that would otherwise not be denoised at all. Simplest
-          // is to apply an additional adjustment to running_avg_y to bring it
-          // closer to sig. The adjustment is capped by a maximum delta, and
-          // chosen such that in most cases the resulting sum_diff will be
-          // within the acceptable range given by sum_diff_thresh.
-
-          // The delta is set by the excess of absolute pixel diff over the
-          // threshold.
-          int delta = ((abs_sum_diff - sum_diff_thresh) >> 8) + 1;
-          // Only apply the adjustment for max delta up to 3.
-          if (delta < 4) {
-            const __m128i k_delta = _mm_set1_epi8(delta);
-            sig -= sig_stride * 16;
-            mc_running_avg_y -= mc_avg_y_stride * 16;
-            running_avg_y -= avg_y_stride * 16;
-            for (r = 0; r < 16; ++r) {
-              __m128i v_running_avg_y =
-                  _mm_loadu_si128((__m128i *)(&running_avg_y[0]));
-              // Calculate differences.
-              const __m128i v_sig = _mm_loadu_si128((__m128i *)(&sig[0]));
-              const __m128i v_mc_running_avg_y =
-                  _mm_loadu_si128((__m128i *)(&mc_running_avg_y[0]));
-              const __m128i pdiff = _mm_subs_epu8(v_mc_running_avg_y, v_sig);
-              const __m128i ndiff = _mm_subs_epu8(v_sig, v_mc_running_avg_y);
-              // Obtain the sign. FF if diff is negative.
-              const __m128i diff_sign = _mm_cmpeq_epi8(pdiff, k_0);
-              // Clamp absolute difference to delta to get the adjustment.
-              const __m128i adj =
-                  _mm_min_epu8(_mm_or_si128(pdiff, ndiff), k_delta);
-              // Restore the sign and get positive and negative adjustments.
-              __m128i padj, nadj;
-              padj = _mm_andnot_si128(diff_sign, adj);
-              nadj = _mm_and_si128(diff_sign, adj);
-              // Calculate filtered value.
-              v_running_avg_y = _mm_subs_epu8(v_running_avg_y, padj);
-              v_running_avg_y = _mm_adds_epu8(v_running_avg_y, nadj);
-             _mm_storeu_si128((__m128i *)running_avg_y, v_running_avg_y);
-
-             // Accumulate the adjustments.
-             acc_diff = _mm_subs_epi8(acc_diff, padj);
-             acc_diff = _mm_adds_epi8(acc_diff, nadj);
-
-             // Update pointers for next iteration.
-             sig += sig_stride;
-             mc_running_avg_y += mc_avg_y_stride;
-             running_avg_y += avg_y_stride;
-            }
-            abs_sum_diff = abs_sum_diff_16x1(acc_diff);
-            if (abs_sum_diff > sum_diff_thresh) {
-              return COPY_BLOCK;
-            }
-          } else {
-            return COPY_BLOCK;
-          }
-        }
-    }
-
-    vp8_copy_mem16x16(running_avg_y_start, avg_y_stride, sig_start, sig_stride);
-    return FILTER_BLOCK;
-}
-
-int vp8_denoiser_filter_uv_sse2(unsigned char *mc_running_avg,
-                             int mc_avg_stride,
-                             unsigned char *running_avg, int avg_stride,
-                             unsigned char *sig, int sig_stride,
-                             unsigned int motion_magnitude,
-                             int increase_denoising) {
-    unsigned char *running_avg_start = running_avg;
-    unsigned char *sig_start = sig;
-    unsigned int sum_diff_thresh;
-    int r;
-    int shift_inc  = (increase_denoising &&
-        motion_magnitude <= MOTION_MAGNITUDE_THRESHOLD_UV) ? 1 : 0;
-    __m128i acc_diff = _mm_setzero_si128();
-    const __m128i k_0 = _mm_setzero_si128();
-    const __m128i k_4 = _mm_set1_epi8(4 + shift_inc);
-    const __m128i k_8 = _mm_set1_epi8(8);
-    const __m128i k_16 = _mm_set1_epi8(16);
-    /* Modify each level's adjustment according to motion_magnitude. */
-    const __m128i l3 = _mm_set1_epi8(
-                       (motion_magnitude <= MOTION_MAGNITUDE_THRESHOLD_UV) ?
-                        7 + shift_inc : 6);
-    /* Difference between level 3 and level 2 is 2. */
-    const __m128i l32 = _mm_set1_epi8(2);
-    /* Difference between level 2 and level 1 is 1. */
-    const __m128i l21 = _mm_set1_epi8(1);
-
-    {
-      const __m128i k_1 = _mm_set1_epi16(1);
-      __m128i vec_sum_block = _mm_setzero_si128();
-
-      // Avoid denoising color signal if its close to average level.
-      for (r = 0; r < 8; ++r) {
-        const __m128i v_sig = _mm_loadl_epi64((__m128i *)(&sig[0]));
-        const __m128i v_sig_unpack = _mm_unpacklo_epi8(v_sig, k_0);
-        vec_sum_block = _mm_add_epi16(vec_sum_block, v_sig_unpack);
-        sig += sig_stride;
-      }
-      sig -= sig_stride * 8;
-      {
-        const __m128i hg_fe_dc_ba = _mm_madd_epi16(vec_sum_block, k_1);
-        const __m128i hgfe_dcba = _mm_add_epi32(hg_fe_dc_ba,
-                                                _mm_srli_si128(hg_fe_dc_ba, 8));
-        const __m128i hgfedcba = _mm_add_epi32(hgfe_dcba,
-                                               _mm_srli_si128(hgfe_dcba, 4));
-        const int sum_block = _mm_cvtsi128_si32(hgfedcba);
-        if (abs(sum_block - (128 * 8 * 8)) < SUM_DIFF_FROM_AVG_THRESH_UV) {
-          return COPY_BLOCK;
-        }
-      }
-    }
-
-    for (r = 0; r < 4; ++r) {
-        /* Calculate differences */
-        const __m128i v_sig_low = _mm_castpd_si128(
-            _mm_load_sd((double *)(&sig[0])));
-        const __m128i v_sig = _mm_castpd_si128(
-            _mm_loadh_pd(_mm_castsi128_pd(v_sig_low),
-                         (double *)(&sig[sig_stride])));
-        const __m128i v_mc_running_avg_low = _mm_castpd_si128(
-            _mm_load_sd((double *)(&mc_running_avg[0])));
-        const __m128i v_mc_running_avg = _mm_castpd_si128(
-            _mm_loadh_pd(_mm_castsi128_pd(v_mc_running_avg_low),
-                         (double *)(&mc_running_avg[mc_avg_stride])));
-        const __m128i pdiff = _mm_subs_epu8(v_mc_running_avg, v_sig);
-        const __m128i ndiff = _mm_subs_epu8(v_sig, v_mc_running_avg);
-        /* Obtain the sign. FF if diff is negative. */
-        const __m128i diff_sign = _mm_cmpeq_epi8(pdiff, k_0);
-        /* Clamp absolute difference to 16 to be used to get mask. Doing this
-         * allows us to use _mm_cmpgt_epi8, which operates on signed byte. */
-        const __m128i clamped_absdiff = _mm_min_epu8(
-                                        _mm_or_si128(pdiff, ndiff), k_16);
-        /* Get masks for l2 l1 and l0 adjustments */
-        const __m128i mask2 = _mm_cmpgt_epi8(k_16, clamped_absdiff);
-        const __m128i mask1 = _mm_cmpgt_epi8(k_8, clamped_absdiff);
-        const __m128i mask0 = _mm_cmpgt_epi8(k_4, clamped_absdiff);
-        /* Get adjustments for l2, l1, and l0 */
-        __m128i adj2 = _mm_and_si128(mask2, l32);
-        const __m128i adj1 = _mm_and_si128(mask1, l21);
-        const __m128i adj0 = _mm_and_si128(mask0, clamped_absdiff);
-        __m128i adj,  padj, nadj;
-        __m128i v_running_avg;
-
-        /* Combine the adjustments and get absolute adjustments. */
-        adj2 = _mm_add_epi8(adj2, adj1);
-        adj = _mm_sub_epi8(l3, adj2);
-        adj = _mm_andnot_si128(mask0, adj);
-        adj = _mm_or_si128(adj, adj0);
-
-        /* Restore the sign and get positive and negative adjustments. */
-        padj = _mm_andnot_si128(diff_sign, adj);
-        nadj = _mm_and_si128(diff_sign, adj);
-
-        /* Calculate filtered value. */
-        v_running_avg = _mm_adds_epu8(v_sig, padj);
-        v_running_avg = _mm_subs_epu8(v_running_avg, nadj);
-
-        _mm_storel_pd((double *)&running_avg[0],
-                      _mm_castsi128_pd(v_running_avg));
-        _mm_storeh_pd((double *)&running_avg[avg_stride],
-                      _mm_castsi128_pd(v_running_avg));
-
-        /* Adjustments <=7, and each element in acc_diff can fit in signed
-         * char.
-         */
-        acc_diff = _mm_adds_epi8(acc_diff, padj);
-        acc_diff = _mm_subs_epi8(acc_diff, nadj);
-
-        /* Update pointers for next iteration. */
-        sig += sig_stride * 2;
-        mc_running_avg += mc_avg_stride * 2;
-        running_avg += avg_stride * 2;
-    }
-
-    {
-        unsigned int abs_sum_diff = abs_sum_diff_16x1(acc_diff);
-        sum_diff_thresh = SUM_DIFF_THRESHOLD_UV;
-        if (increase_denoising) sum_diff_thresh = SUM_DIFF_THRESHOLD_HIGH_UV;
-        if (abs_sum_diff > sum_diff_thresh) {
-          // Before returning to copy the block (i.e., apply no denoising),
-          // check if we can still apply some (weaker) temporal filtering to
-          // this block, that would otherwise not be denoised at all. Simplest
-          // is to apply an additional adjustment to running_avg_y to bring it
-          // closer to sig. The adjustment is capped by a maximum delta, and
-          // chosen such that in most cases the resulting sum_diff will be
-          // within the acceptable range given by sum_diff_thresh.
-
-          // The delta is set by the excess of absolute pixel diff over the
-          // threshold.
-          int delta = ((abs_sum_diff - sum_diff_thresh) >> 8) + 1;
-          // Only apply the adjustment for max delta up to 3.
-          if (delta < 4) {
-            const __m128i k_delta = _mm_set1_epi8(delta);
-            sig -= sig_stride * 8;
-            mc_running_avg -= mc_avg_stride * 8;
-            running_avg -= avg_stride * 8;
-            for (r = 0; r < 4; ++r) {
-              // Calculate differences.
-              const __m128i v_sig_low = _mm_castpd_si128(
-                  _mm_load_sd((double *)(&sig[0])));
-              const __m128i v_sig = _mm_castpd_si128(
-                  _mm_loadh_pd(_mm_castsi128_pd(v_sig_low),
-                               (double *)(&sig[sig_stride])));
-              const __m128i v_mc_running_avg_low = _mm_castpd_si128(
-                  _mm_load_sd((double *)(&mc_running_avg[0])));
-              const __m128i v_mc_running_avg = _mm_castpd_si128(
-                  _mm_loadh_pd(_mm_castsi128_pd(v_mc_running_avg_low),
-                               (double *)(&mc_running_avg[mc_avg_stride])));
-              const __m128i pdiff = _mm_subs_epu8(v_mc_running_avg, v_sig);
-              const __m128i ndiff = _mm_subs_epu8(v_sig, v_mc_running_avg);
-              // Obtain the sign. FF if diff is negative.
-              const __m128i diff_sign = _mm_cmpeq_epi8(pdiff, k_0);
-              // Clamp absolute difference to delta to get the adjustment.
-              const __m128i adj =
-                  _mm_min_epu8(_mm_or_si128(pdiff, ndiff), k_delta);
-              // Restore the sign and get positive and negative adjustments.
-              __m128i padj, nadj;
-              const __m128i v_running_avg_low = _mm_castpd_si128(
-                  _mm_load_sd((double *)(&running_avg[0])));
-              __m128i v_running_avg = _mm_castpd_si128(
-                  _mm_loadh_pd(_mm_castsi128_pd(v_running_avg_low),
-                               (double *)(&running_avg[avg_stride])));
-              padj = _mm_andnot_si128(diff_sign, adj);
-              nadj = _mm_and_si128(diff_sign, adj);
-              // Calculate filtered value.
-              v_running_avg = _mm_subs_epu8(v_running_avg, padj);
-              v_running_avg = _mm_adds_epu8(v_running_avg, nadj);
-
-              _mm_storel_pd((double *)&running_avg[0],
-                            _mm_castsi128_pd(v_running_avg));
-              _mm_storeh_pd((double *)&running_avg[avg_stride],
-                            _mm_castsi128_pd(v_running_avg));
-
-             // Accumulate the adjustments.
-             acc_diff = _mm_subs_epi8(acc_diff, padj);
-             acc_diff = _mm_adds_epi8(acc_diff, nadj);
-
-             // Update pointers for next iteration.
-             sig += sig_stride * 2;
-             mc_running_avg += mc_avg_stride * 2;
-             running_avg += avg_stride * 2;
-            }
-            abs_sum_diff = abs_sum_diff_16x1(acc_diff);
-            if (abs_sum_diff > sum_diff_thresh) {
-              return COPY_BLOCK;
-            }
-          } else {
-            return COPY_BLOCK;
-          }
-        }
-    }
-
-    vp8_copy_mem8x8(running_avg_start, avg_stride, sig_start, sig_stride);
-    return FILTER_BLOCK;
-}
diff --git a/vp8/encoder/x86/encodeopt.asm b/vp8/encoder/x86/encodeopt.asm
deleted file mode 100644 (file)
index fe26b18..0000000
+++ /dev/null
@@ -1,386 +0,0 @@
-;
-;  Copyright (c) 2010 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.
-;
-
-
-%include "vpx_ports/x86_abi_support.asm"
-
-;int vp8_block_error_xmm(short *coeff_ptr,  short *dcoef_ptr)
-global sym(vp8_block_error_xmm) PRIVATE
-sym(vp8_block_error_xmm):
-    push        rbp
-    mov         rbp, rsp
-    SHADOW_ARGS_TO_STACK 2
-    push rsi
-    push rdi
-    ; end prologue
-
-        mov         rsi,        arg(0) ;coeff_ptr
-        mov         rdi,        arg(1) ;dcoef_ptr
-
-        movdqa      xmm0,       [rsi]
-        movdqa      xmm1,       [rdi]
-
-        movdqa      xmm2,       [rsi+16]
-        movdqa      xmm3,       [rdi+16]
-
-        psubw       xmm0,       xmm1
-        psubw       xmm2,       xmm3
-
-        pmaddwd     xmm0,       xmm0
-        pmaddwd     xmm2,       xmm2
-
-        paddd       xmm0,       xmm2
-
-        pxor        xmm5,       xmm5
-        movdqa      xmm1,       xmm0
-
-        punpckldq   xmm0,       xmm5
-        punpckhdq   xmm1,       xmm5
-
-        paddd       xmm0,       xmm1
-        movdqa      xmm1,       xmm0
-
-        psrldq      xmm0,       8
-        paddd       xmm0,       xmm1
-
-        movq        rax,        xmm0
-
-    pop rdi
-    pop rsi
-    ; begin epilog
-    UNSHADOW_ARGS
-    pop         rbp
-    ret
-
-;int vp8_block_error_mmx(short *coeff_ptr,  short *dcoef_ptr)
-global sym(vp8_block_error_mmx) PRIVATE
-sym(vp8_block_error_mmx):
-    push        rbp
-    mov         rbp, rsp
-    SHADOW_ARGS_TO_STACK 2
-    push rsi
-    push rdi
-    ; end prolog
-
-
-        mov         rsi,        arg(0) ;coeff_ptr
-        pxor        mm7,        mm7
-
-        mov         rdi,        arg(1) ;dcoef_ptr
-        movq        mm3,        [rsi]
-
-        movq        mm4,        [rdi]
-        movq        mm5,        [rsi+8]
-
-        movq        mm6,        [rdi+8]
-        pxor        mm1,        mm1 ; from movd mm1, dc ; dc =0
-
-        movq        mm2,        mm7
-        psubw       mm5,        mm6
-
-        por         mm1,        mm2
-        pmaddwd     mm5,        mm5
-
-        pcmpeqw     mm1,        mm7
-        psubw       mm3,        mm4
-
-        pand        mm1,        mm3
-        pmaddwd     mm1,        mm1
-
-        paddd       mm1,        mm5
-        movq        mm3,        [rsi+16]
-
-        movq        mm4,        [rdi+16]
-        movq        mm5,        [rsi+24]
-
-        movq        mm6,        [rdi+24]
-        psubw       mm5,        mm6
-
-        pmaddwd     mm5,        mm5
-        psubw       mm3,        mm4
-
-        pmaddwd     mm3,        mm3
-        paddd       mm3,        mm5
-
-        paddd       mm1,        mm3
-        movq        mm0,        mm1
-
-        psrlq       mm1,        32
-        paddd       mm0,        mm1
-
-        movq        rax,        mm0
-
-    pop rdi
-    pop rsi
-    ; begin epilog
-    UNSHADOW_ARGS
-    pop         rbp
-    ret
-
-
-;int vp8_mbblock_error_mmx_impl(short *coeff_ptr, short *dcoef_ptr, int dc);
-global sym(vp8_mbblock_error_mmx_impl) PRIVATE
-sym(vp8_mbblock_error_mmx_impl):
-    push        rbp
-    mov         rbp, rsp
-    SHADOW_ARGS_TO_STACK 3
-    push rsi
-    push rdi
-    ; end prolog
-
-
-        mov         rsi,        arg(0) ;coeff_ptr
-        pxor        mm7,        mm7
-
-        mov         rdi,        arg(1) ;dcoef_ptr
-        pxor        mm2,        mm2
-
-        movd        mm1,        dword ptr arg(2) ;dc
-        por         mm1,        mm2
-
-        pcmpeqw     mm1,        mm7
-        mov         rcx,        16
-
-.mberror_loop_mmx:
-        movq        mm3,       [rsi]
-        movq        mm4,       [rdi]
-
-        movq        mm5,       [rsi+8]
-        movq        mm6,       [rdi+8]
-
-
-        psubw       mm5,        mm6
-        pmaddwd     mm5,        mm5
-
-        psubw       mm3,        mm4
-        pand        mm3,        mm1
-
-        pmaddwd     mm3,        mm3
-        paddd       mm2,        mm5
-
-        paddd       mm2,        mm3
-        movq        mm3,       [rsi+16]
-
-        movq        mm4,       [rdi+16]
-        movq        mm5,       [rsi+24]
-
-        movq        mm6,       [rdi+24]
-        psubw       mm5,        mm6
-
-        pmaddwd     mm5,        mm5
-        psubw       mm3,        mm4
-
-        pmaddwd     mm3,        mm3
-        paddd       mm2,        mm5
-
-        paddd       mm2,        mm3
-        add         rsi,        32
-
-        add         rdi,        32
-        sub         rcx,        1
-
-        jnz         .mberror_loop_mmx
-
-        movq        mm0,        mm2
-        psrlq       mm2,        32
-
-        paddd       mm0,        mm2
-        movq        rax,        mm0
-
-    pop rdi
-    pop rsi
-    ; begin epilog
-    UNSHADOW_ARGS
-    pop         rbp
-    ret
-
-
-;int vp8_mbblock_error_xmm_impl(short *coeff_ptr, short *dcoef_ptr, int dc);
-global sym(vp8_mbblock_error_xmm_impl) PRIVATE
-sym(vp8_mbblock_error_xmm_impl):
-    push        rbp
-    mov         rbp, rsp
-    SHADOW_ARGS_TO_STACK 3
-    SAVE_XMM 6
-    push rsi
-    push rdi
-    ; end prolog
-
-
-        mov         rsi,        arg(0) ;coeff_ptr
-        pxor        xmm6,       xmm6
-
-        mov         rdi,        arg(1) ;dcoef_ptr
-        pxor        xmm4,       xmm4
-
-        movd        xmm5,       dword ptr arg(2) ;dc
-        por         xmm5,       xmm4
-
-        pcmpeqw     xmm5,       xmm6
-        mov         rcx,        16
-
-.mberror_loop:
-        movdqa      xmm0,       [rsi]
-        movdqa      xmm1,       [rdi]
-
-        movdqa      xmm2,       [rsi+16]
-        movdqa      xmm3,       [rdi+16]
-
-
-        psubw       xmm2,       xmm3
-        pmaddwd     xmm2,       xmm2
-
-        psubw       xmm0,       xmm1
-        pand        xmm0,       xmm5
-
-        pmaddwd     xmm0,       xmm0
-        add         rsi,        32
-
-        add         rdi,        32
-
-        sub         rcx,        1
-        paddd       xmm4,       xmm2
-
-        paddd       xmm4,       xmm0
-        jnz         .mberror_loop
-
-        movdqa      xmm0,       xmm4
-        punpckldq   xmm0,       xmm6
-
-        punpckhdq   xmm4,       xmm6
-        paddd       xmm0,       xmm4
-
-        movdqa      xmm1,       xmm0
-        psrldq      xmm0,       8
-
-        paddd       xmm0,       xmm1
-        movq        rax,        xmm0
-
-    pop rdi
-    pop rsi
-    ; begin epilog
-    RESTORE_XMM
-    UNSHADOW_ARGS
-    pop         rbp
-    ret
-
-
-;int vp8_mbuverror_mmx_impl(short *s_ptr, short *d_ptr);
-global sym(vp8_mbuverror_mmx_impl) PRIVATE
-sym(vp8_mbuverror_mmx_impl):
-    push        rbp
-    mov         rbp, rsp
-    SHADOW_ARGS_TO_STACK 2
-    push rsi
-    push rdi
-    ; end prolog
-
-
-        mov             rsi,        arg(0) ;s_ptr
-        mov             rdi,        arg(1) ;d_ptr
-
-        mov             rcx,        16
-        pxor            mm7,        mm7
-
-.mbuverror_loop_mmx:
-
-        movq            mm1,        [rsi]
-        movq            mm2,        [rdi]
-
-        psubw           mm1,        mm2
-        pmaddwd         mm1,        mm1
-
-
-        movq            mm3,        [rsi+8]
-        movq            mm4,        [rdi+8]
-
-        psubw           mm3,        mm4
-        pmaddwd         mm3,        mm3
-
-
-        paddd           mm7,        mm1
-        paddd           mm7,        mm3
-
-
-        add             rsi,        16
-        add             rdi,        16
-
-        dec             rcx
-        jnz             .mbuverror_loop_mmx
-
-        movq            mm0,        mm7
-        psrlq           mm7,        32
-
-        paddd           mm0,        mm7
-        movq            rax,        mm0
-
-    pop rdi
-    pop rsi
-    ; begin epilog
-    UNSHADOW_ARGS
-    pop         rbp
-    ret
-
-
-;int vp8_mbuverror_xmm_impl(short *s_ptr, short *d_ptr);
-global sym(vp8_mbuverror_xmm_impl) PRIVATE
-sym(vp8_mbuverror_xmm_impl):
-    push        rbp
-    mov         rbp, rsp
-    SHADOW_ARGS_TO_STACK 2
-    push rsi
-    push rdi
-    ; end prolog
-
-
-        mov             rsi,        arg(0) ;s_ptr
-        mov             rdi,        arg(1) ;d_ptr
-
-        mov             rcx,        16
-        pxor            xmm3,       xmm3
-
-.mbuverror_loop:
-
-        movdqa          xmm1,       [rsi]
-        movdqa          xmm2,       [rdi]
-
-        psubw           xmm1,       xmm2
-        pmaddwd         xmm1,       xmm1
-
-        paddd           xmm3,       xmm1
-
-        add             rsi,        16
-        add             rdi,        16
-
-        dec             rcx
-        jnz             .mbuverror_loop
-
-        pxor        xmm0,           xmm0
-        movdqa      xmm1,           xmm3
-
-        movdqa      xmm2,           xmm1
-        punpckldq   xmm1,           xmm0
-
-        punpckhdq   xmm2,           xmm0
-        paddd       xmm1,           xmm2
-
-        movdqa      xmm2,           xmm1
-
-        psrldq      xmm1,           8
-        paddd       xmm1,           xmm2
-
-        movq            rax,            xmm1
-
-    pop rdi
-    pop rsi
-    ; begin epilog
-    UNSHADOW_ARGS
-    pop         rbp
-    ret
diff --git a/vp8/encoder/x86/fwalsh_sse2.asm b/vp8/encoder/x86/fwalsh_sse2.asm
deleted file mode 100644 (file)
index f498927..0000000
+++ /dev/null
@@ -1,164 +0,0 @@
-;
-;  Copyright (c) 2010 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.
-;
-
-
-%include "vpx_ports/x86_abi_support.asm"
-
-;void vp8_short_walsh4x4_sse2(short *input, short *output, int pitch)
-global sym(vp8_short_walsh4x4_sse2) PRIVATE
-sym(vp8_short_walsh4x4_sse2):
-    push        rbp
-    mov         rbp, rsp
-    SHADOW_ARGS_TO_STACK 3
-    SAVE_XMM 7
-    GET_GOT     rbx
-    push        rsi
-    push        rdi
-    ; end prolog
-
-    mov     rsi, arg(0)           ; input
-    mov     rdi, arg(1)           ; output
-    movsxd  rdx, dword ptr arg(2) ; pitch
-
-    ; first for loop
-    movq    xmm0, MMWORD PTR [rsi]           ; load input
-    movq    xmm1, MMWORD PTR [rsi + rdx]
-    lea     rsi,  [rsi + rdx*2]
-    movq    xmm2, MMWORD PTR [rsi]
-    movq    xmm3, MMWORD PTR [rsi + rdx]
-
-    punpcklwd xmm0,  xmm1
-    punpcklwd xmm2,  xmm3
-
-    movdqa    xmm1, xmm0
-    punpckldq xmm0, xmm2           ; ip[1] ip[0]
-    punpckhdq xmm1, xmm2           ; ip[3] ip[2]
-
-    movdqa    xmm2, xmm0
-    paddw     xmm0, xmm1
-    psubw     xmm2, xmm1
-
-    psllw     xmm0, 2              ; d1  a1
-    psllw     xmm2, 2              ; c1  b1
-
-    movdqa    xmm1, xmm0
-    punpcklqdq xmm0, xmm2          ; b1  a1
-    punpckhqdq xmm1, xmm2          ; c1  d1
-
-    pxor      xmm6, xmm6
-    movq      xmm6, xmm0
-    pxor      xmm7, xmm7
-    pcmpeqw   xmm7, xmm6
-    paddw     xmm7, [GLOBAL(c1)]
-
-    movdqa    xmm2, xmm0
-    paddw     xmm0, xmm1           ; b1+c1  a1+d1
-    psubw     xmm2, xmm1           ; b1-c1  a1-d1
-    paddw     xmm0, xmm7           ; b1+c1  a1+d1+(a1!=0)
-
-    ; second for loop
-    ; input: 13  9  5  1 12  8  4  0 (xmm0)
-    ;        14 10  6  2 15 11  7  3 (xmm2)
-    ; after shuffle:
-    ;        13  5  9  1 12  4  8  0 (xmm0)
-    ;        14  6 10  2 15  7 11  3 (xmm1)
-    pshuflw   xmm3, xmm0, 0xd8
-    pshufhw   xmm0, xmm3, 0xd8
-    pshuflw   xmm3, xmm2, 0xd8
-    pshufhw   xmm1, xmm3, 0xd8
-
-    movdqa    xmm2, xmm0
-    pmaddwd   xmm0, [GLOBAL(c1)]    ; d11 a11 d10 a10
-    pmaddwd   xmm2, [GLOBAL(cn1)]   ; c11 b11 c10 b10
-    movdqa    xmm3, xmm1
-    pmaddwd   xmm1, [GLOBAL(c1)]    ; d12 a12 d13 a13
-    pmaddwd   xmm3, [GLOBAL(cn1)]   ; c12 b12 c13 b13
-
-    pshufd    xmm4, xmm0, 0xd8      ; d11 d10 a11 a10
-    pshufd    xmm5, xmm2, 0xd8      ; c11 c10 b11 b10
-    pshufd    xmm6, xmm1, 0x72      ; d13 d12 a13 a12
-    pshufd    xmm7, xmm3, 0x72      ; c13 c12 b13 b12
-
-    movdqa    xmm0, xmm4
-    punpcklqdq xmm0, xmm5           ; b11 b10 a11 a10
-    punpckhqdq xmm4, xmm5           ; c11 c10 d11 d10
-    movdqa    xmm1, xmm6
-    punpcklqdq xmm1, xmm7           ; b13 b12 a13 a12
-    punpckhqdq xmm6, xmm7           ; c13 c12 d13 d12
-
-    movdqa    xmm2, xmm0
-    paddd     xmm0, xmm4            ; b21 b20 a21 a20
-    psubd     xmm2, xmm4            ; c21 c20 d21 d20
-    movdqa    xmm3, xmm1
-    paddd     xmm1, xmm6            ; b23 b22 a23 a22
-    psubd     xmm3, xmm6            ; c23 c22 d23 d22
-
-    pxor      xmm4, xmm4
-    movdqa    xmm5, xmm4
-    pcmpgtd   xmm4, xmm0
-    pcmpgtd   xmm5, xmm2
-    pand      xmm4, [GLOBAL(cd1)]
-    pand      xmm5, [GLOBAL(cd1)]
-
-    pxor      xmm6, xmm6
-    movdqa    xmm7, xmm6
-    pcmpgtd   xmm6, xmm1
-    pcmpgtd   xmm7, xmm3
-    pand      xmm6, [GLOBAL(cd1)]
-    pand      xmm7, [GLOBAL(cd1)]
-
-    paddd     xmm0, xmm4
-    paddd     xmm2, xmm5
-    paddd     xmm0, [GLOBAL(cd3)]
-    paddd     xmm2, [GLOBAL(cd3)]
-    paddd     xmm1, xmm6
-    paddd     xmm3, xmm7
-    paddd     xmm1, [GLOBAL(cd3)]
-    paddd     xmm3, [GLOBAL(cd3)]
-
-    psrad     xmm0, 3
-    psrad     xmm1, 3
-    psrad     xmm2, 3
-    psrad     xmm3, 3
-    movdqa    xmm4, xmm0
-    punpcklqdq xmm0, xmm1           ; a23 a22 a21 a20
-    punpckhqdq xmm4, xmm1           ; b23 b22 b21 b20
-    movdqa    xmm5, xmm2
-    punpckhqdq xmm2, xmm3           ; c23 c22 c21 c20
-    punpcklqdq xmm5, xmm3           ; d23 d22 d21 d20
-
-    packssdw  xmm0, xmm4            ; b23 b22 b21 b20 a23 a22 a21 a20
-    packssdw  xmm2, xmm5            ; d23 d22 d21 d20 c23 c22 c21 c20
-
-    movdqa  XMMWORD PTR [rdi], xmm0
-    movdqa  XMMWORD PTR [rdi + 16], xmm2
-
-    ; begin epilog
-    pop rdi
-    pop rsi
-    RESTORE_GOT
-    RESTORE_XMM
-    UNSHADOW_ARGS
-    pop         rbp
-    ret
-
-SECTION_RODATA
-align 16
-c1:
-    dw 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001
-align 16
-cn1:
-    dw 0x0001, 0xffff, 0x0001, 0xffff, 0x0001, 0xffff, 0x0001, 0xffff
-align 16
-cd1:
-    dd 0x00000001, 0x00000001, 0x00000001, 0x00000001
-align 16
-cd3:
-    dd 0x00000003, 0x00000003, 0x00000003, 0x00000003
diff --git a/vp8/encoder/x86/quantize_mmx.asm b/vp8/encoder/x86/quantize_mmx.asm
deleted file mode 100644 (file)
index 2864ce1..0000000
+++ /dev/null
@@ -1,286 +0,0 @@
-;
-;  Copyright (c) 2010 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.
-;
-
-
-%include "vpx_ports/x86_abi_support.asm"
-
-;int vp8_fast_quantize_b_impl_mmx(short *coeff_ptr, short *zbin_ptr,
-;                           short *qcoeff_ptr,short *dequant_ptr,
-;                           short *scan_mask, short *round_ptr,
-;                           short *quant_ptr, short *dqcoeff_ptr);
-global sym(vp8_fast_quantize_b_impl_mmx) PRIVATE
-sym(vp8_fast_quantize_b_impl_mmx):
-    push        rbp
-    mov         rbp, rsp
-    SHADOW_ARGS_TO_STACK 8
-    push rsi
-    push rdi
-    ; end prolog
-
-
-        mov             rsi,        arg(0) ;coeff_ptr
-        movq            mm0,        [rsi]
-
-        mov             rax,        arg(1) ;zbin_ptr
-        movq            mm1,        [rax]
-
-        movq            mm3,        mm0
-        psraw           mm0,        15
-
-        pxor            mm3,        mm0
-        psubw           mm3,        mm0         ; abs
-
-        movq            mm2,        mm3
-        pcmpgtw         mm1,        mm2
-
-        pandn           mm1,        mm2
-        movq            mm3,        mm1
-
-        mov             rdx,        arg(6) ;quant_ptr
-        movq            mm1,        [rdx]
-
-        mov             rcx,        arg(5) ;round_ptr
-        movq            mm2,        [rcx]
-
-        paddw           mm3,        mm2
-        pmulhuw         mm3,        mm1
-
-        pxor            mm3,        mm0
-        psubw           mm3,        mm0     ;gain the sign back
-
-        mov             rdi,        arg(2) ;qcoeff_ptr
-        movq            mm0,        mm3
-
-        movq            [rdi],      mm3
-
-        mov             rax,        arg(3) ;dequant_ptr
-        movq            mm2,        [rax]
-
-        pmullw          mm3,        mm2
-        mov             rax,        arg(7) ;dqcoeff_ptr
-
-        movq            [rax],      mm3
-
-        ; next 8
-        movq            mm4,        [rsi+8]
-
-        mov             rax,        arg(1) ;zbin_ptr
-        movq            mm5,        [rax+8]
-
-        movq            mm7,        mm4
-        psraw           mm4,        15
-
-        pxor            mm7,        mm4
-        psubw           mm7,        mm4         ; abs
-
-        movq            mm6,        mm7
-        pcmpgtw         mm5,        mm6
-
-        pandn           mm5,        mm6
-        movq            mm7,        mm5
-
-        movq            mm5,        [rdx+8]
-        movq            mm6,        [rcx+8]
-
-        paddw           mm7,        mm6
-        pmulhuw         mm7,        mm5
-
-        pxor            mm7,        mm4
-        psubw           mm7,        mm4;gain the sign back
-
-        mov             rdi,        arg(2) ;qcoeff_ptr
-
-        movq            mm1,        mm7
-        movq            [rdi+8],    mm7
-
-        mov             rax,        arg(3) ;dequant_ptr
-        movq            mm6,        [rax+8]
-
-        pmullw          mm7,        mm6
-        mov             rax,        arg(7) ;dqcoeff_ptr
-
-        movq            [rax+8],    mm7
-
-
-                ; next 8
-        movq            mm4,        [rsi+16]
-
-        mov             rax,        arg(1) ;zbin_ptr
-        movq            mm5,        [rax+16]
-
-        movq            mm7,        mm4
-        psraw           mm4,        15
-
-        pxor            mm7,        mm4
-        psubw           mm7,        mm4         ; abs
-
-        movq            mm6,        mm7
-        pcmpgtw         mm5,        mm6
-
-        pandn           mm5,        mm6
-        movq            mm7,        mm5
-
-        movq            mm5,        [rdx+16]
-        movq            mm6,        [rcx+16]
-
-        paddw           mm7,        mm6
-        pmulhuw         mm7,        mm5
-
-        pxor            mm7,        mm4
-        psubw           mm7,        mm4;gain the sign back
-
-        mov             rdi,        arg(2) ;qcoeff_ptr
-
-        movq            mm1,        mm7
-        movq            [rdi+16],   mm7
-
-        mov             rax,        arg(3) ;dequant_ptr
-        movq            mm6,        [rax+16]
-
-        pmullw          mm7,        mm6
-        mov             rax,        arg(7) ;dqcoeff_ptr
-
-        movq            [rax+16],   mm7
-
-
-                ; next 8
-        movq            mm4,        [rsi+24]
-
-        mov             rax,        arg(1) ;zbin_ptr
-        movq            mm5,        [rax+24]
-
-        movq            mm7,        mm4
-        psraw           mm4,        15
-
-        pxor            mm7,        mm4
-        psubw           mm7,        mm4         ; abs
-
-        movq            mm6,        mm7
-        pcmpgtw         mm5,        mm6
-
-        pandn           mm5,        mm6
-        movq            mm7,        mm5
-
-        movq            mm5,        [rdx+24]
-        movq            mm6,        [rcx+24]
-
-        paddw           mm7,        mm6
-        pmulhuw         mm7,        mm5
-
-        pxor            mm7,        mm4
-        psubw           mm7,        mm4;gain the sign back
-
-        mov             rdi,        arg(2) ;qcoeff_ptr
-
-        movq            mm1,        mm7
-        movq            [rdi+24],   mm7
-
-        mov             rax,        arg(3) ;dequant_ptr
-        movq            mm6,        [rax+24]
-
-        pmullw          mm7,        mm6
-        mov             rax,        arg(7) ;dqcoeff_ptr
-
-        movq            [rax+24],   mm7
-
-
-
-        mov             rdi,        arg(4) ;scan_mask
-        mov             rsi,        arg(2) ;qcoeff_ptr
-
-        pxor            mm5,        mm5
-        pxor            mm7,        mm7
-
-        movq            mm0,        [rsi]
-        movq            mm1,        [rsi+8]
-
-        movq            mm2,        [rdi]
-        movq            mm3,        [rdi+8];
-
-        pcmpeqw         mm0,        mm7
-        pcmpeqw         mm1,        mm7
-
-        pcmpeqw         mm6,        mm6
-        pxor            mm0,        mm6
-
-        pxor            mm1,        mm6
-        psrlw           mm0,        15
-
-        psrlw           mm1,        15
-        pmaddwd         mm0,        mm2
-
-        pmaddwd         mm1,        mm3
-        movq            mm5,        mm0
-
-        paddd           mm5,        mm1
-
-        movq            mm0,        [rsi+16]
-        movq            mm1,        [rsi+24]
-
-        movq            mm2,        [rdi+16]
-        movq            mm3,        [rdi+24];
-
-        pcmpeqw         mm0,        mm7
-        pcmpeqw         mm1,        mm7
-
-        pcmpeqw         mm6,        mm6
-        pxor            mm0,        mm6
-
-        pxor            mm1,        mm6
-        psrlw           mm0,        15
-
-        psrlw           mm1,        15
-        pmaddwd         mm0,        mm2
-
-        pmaddwd         mm1,        mm3
-        paddd           mm5,        mm0
-
-        paddd           mm5,        mm1
-        movq            mm0,        mm5
-
-        psrlq           mm5,        32
-        paddd           mm0,        mm5
-
-        ; eob adjustment begins here
-        movq            rcx,        mm0
-        and             rcx,        0xffff
-
-        xor             rdx,        rdx
-        sub             rdx,        rcx ; rdx=-rcx
-
-        bsr             rax,        rcx
-        inc             rax
-
-        sar             rdx,        31
-        and             rax,        rdx
-        ; Substitute the sse assembly for the old mmx mixed assembly/C. The
-        ; following is kept as reference
-        ;    movq            rcx,        mm0
-        ;    bsr             rax,        rcx
-        ;
-        ;    mov             eob,        rax
-        ;    mov             eee,        rcx
-        ;
-        ;if(eee==0)
-        ;{
-        ;    eob=-1;
-        ;}
-        ;else if(eee<0)
-        ;{
-        ;    eob=15;
-        ;}
-        ;d->eob = eob+1;
-
-    ; begin epilog
-    pop rdi
-    pop rsi
-    UNSHADOW_ARGS
-    pop         rbp
-    ret
diff --git a/vp8/encoder/x86/quantize_sse4.c b/vp8/encoder/x86/quantize_sse4.c
deleted file mode 100644 (file)
index 601dd23..0000000
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- *  Copyright (c) 2012 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.
- */
-
-
-#include <smmintrin.h> /* SSE4.1 */
-
-#include "./vp8_rtcd.h"
-#include "vp8/encoder/block.h"
-#include "vp8/common/entropy.h" /* vp8_default_inv_zig_zag */
-
-#define SELECT_EOB(i, z, x, y, q) \
-    do { \
-        short boost = *zbin_boost_ptr; \
-        short x_z = _mm_extract_epi16(x, z); \
-        short y_z = _mm_extract_epi16(y, z); \
-        int cmp = (x_z < boost) | (y_z == 0); \
-        zbin_boost_ptr++; \
-        if (cmp) \
-            break; \
-        q = _mm_insert_epi16(q, y_z, z); \
-        eob = i; \
-        zbin_boost_ptr = b->zrun_zbin_boost; \
-    } while (0)
-
-void vp8_regular_quantize_b_sse4_1(BLOCK *b, BLOCKD *d) {
-    char eob = 0;
-    short *zbin_boost_ptr  = b->zrun_zbin_boost;
-
-    __m128i sz0, x0, sz1, x1, y0, y1, x_minus_zbin0, x_minus_zbin1,
-            dqcoeff0, dqcoeff1;
-    __m128i quant_shift0 = _mm_load_si128((__m128i *)(b->quant_shift));
-    __m128i quant_shift1 = _mm_load_si128((__m128i *)(b->quant_shift + 8));
-    __m128i z0 = _mm_load_si128((__m128i *)(b->coeff));
-    __m128i z1 = _mm_load_si128((__m128i *)(b->coeff+8));
-    __m128i zbin_extra = _mm_cvtsi32_si128(b->zbin_extra);
-    __m128i zbin0 = _mm_load_si128((__m128i *)(b->zbin));
-    __m128i zbin1 = _mm_load_si128((__m128i *)(b->zbin + 8));
-    __m128i round0 = _mm_load_si128((__m128i *)(b->round));
-    __m128i round1 = _mm_load_si128((__m128i *)(b->round + 8));
-    __m128i quant0 = _mm_load_si128((__m128i *)(b->quant));
-    __m128i quant1 = _mm_load_si128((__m128i *)(b->quant + 8));
-    __m128i dequant0 = _mm_load_si128((__m128i *)(d->dequant));
-    __m128i dequant1 = _mm_load_si128((__m128i *)(d->dequant + 8));
-    __m128i qcoeff0 = _mm_setzero_si128();
-    __m128i qcoeff1 = _mm_setzero_si128();
-
-    /* Duplicate to all lanes. */
-    zbin_extra = _mm_shufflelo_epi16(zbin_extra, 0);
-    zbin_extra = _mm_unpacklo_epi16(zbin_extra, zbin_extra);
-
-    /* Sign of z: z >> 15 */
-    sz0 = _mm_srai_epi16(z0, 15);
-    sz1 = _mm_srai_epi16(z1, 15);
-
-    /* x = abs(z): (z ^ sz) - sz */
-    x0 = _mm_xor_si128(z0, sz0);
-    x1 = _mm_xor_si128(z1, sz1);
-    x0 = _mm_sub_epi16(x0, sz0);
-    x1 = _mm_sub_epi16(x1, sz1);
-
-    /* zbin[] + zbin_extra */
-    zbin0 = _mm_add_epi16(zbin0, zbin_extra);
-    zbin1 = _mm_add_epi16(zbin1, zbin_extra);
-
-    /* In C x is compared to zbin where zbin = zbin[] + boost + extra. Rebalance
-     * the equation because boost is the only value which can change:
-     * x - (zbin[] + extra) >= boost */
-    x_minus_zbin0 = _mm_sub_epi16(x0, zbin0);
-    x_minus_zbin1 = _mm_sub_epi16(x1, zbin1);
-
-    /* All the remaining calculations are valid whether they are done now with
-     * simd or later inside the loop one at a time. */
-    x0 = _mm_add_epi16(x0, round0);
-    x1 = _mm_add_epi16(x1, round1);
-
-    y0 = _mm_mulhi_epi16(x0, quant0);
-    y1 = _mm_mulhi_epi16(x1, quant1);
-
-    y0 = _mm_add_epi16(y0, x0);
-    y1 = _mm_add_epi16(y1, x1);
-
-    /* Instead of shifting each value independently we convert the scaling
-     * factor with 1 << (16 - shift) so we can use multiply/return high half. */
-    y0 = _mm_mulhi_epi16(y0, quant_shift0);
-    y1 = _mm_mulhi_epi16(y1, quant_shift1);
-
-    /* Return the sign: (y ^ sz) - sz */
-    y0 = _mm_xor_si128(y0, sz0);
-    y1 = _mm_xor_si128(y1, sz1);
-    y0 = _mm_sub_epi16(y0, sz0);
-    y1 = _mm_sub_epi16(y1, sz1);
-
-    /* The loop gets unrolled anyway. Avoid the vp8_default_zig_zag1d lookup. */
-    SELECT_EOB(1, 0, x_minus_zbin0, y0, qcoeff0);
-    SELECT_EOB(2, 1, x_minus_zbin0, y0, qcoeff0);
-    SELECT_EOB(3, 4, x_minus_zbin0, y0, qcoeff0);
-    SELECT_EOB(4, 0, x_minus_zbin1, y1, qcoeff1);
-    SELECT_EOB(5, 5, x_minus_zbin0, y0, qcoeff0);
-    SELECT_EOB(6, 2, x_minus_zbin0, y0, qcoeff0);
-    SELECT_EOB(7, 3, x_minus_zbin0, y0, qcoeff0);
-    SELECT_EOB(8, 6, x_minus_zbin0, y0, qcoeff0);
-    SELECT_EOB(9, 1, x_minus_zbin1, y1, qcoeff1);
-    SELECT_EOB(10, 4, x_minus_zbin1, y1, qcoeff1);
-    SELECT_EOB(11, 5, x_minus_zbin1, y1, qcoeff1);
-    SELECT_EOB(12, 2, x_minus_zbin1, y1, qcoeff1);
-    SELECT_EOB(13, 7, x_minus_zbin0, y0, qcoeff0);
-    SELECT_EOB(14, 3, x_minus_zbin1, y1, qcoeff1);
-    SELECT_EOB(15, 6, x_minus_zbin1, y1, qcoeff1);
-    SELECT_EOB(16, 7, x_minus_zbin1, y1, qcoeff1);
-
-    _mm_store_si128((__m128i *)(d->qcoeff), qcoeff0);
-    _mm_store_si128((__m128i *)(d->qcoeff + 8), qcoeff1);
-
-    dqcoeff0 = _mm_mullo_epi16(qcoeff0, dequant0);
-    dqcoeff1 = _mm_mullo_epi16(qcoeff1, dequant1);
-
-    _mm_store_si128((__m128i *)(d->dqcoeff), dqcoeff0);
-    _mm_store_si128((__m128i *)(d->dqcoeff + 8), dqcoeff1);
-
-    *d->eob = eob;
-}
diff --git a/vp8/encoder/x86/quantize_ssse3.c b/vp8/encoder/x86/quantize_ssse3.c
deleted file mode 100644 (file)
index 14282db..0000000
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- *  Copyright (c) 2012 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.
- */
-
-#include <tmmintrin.h> /* SSSE3 */
-
-#include "vp8/encoder/block.h"
-
-/* bitscan reverse (bsr) */
-#if defined(_MSC_VER)
-#include <intrin.h>
-#pragma intrinsic(_BitScanReverse)
-static int bsr(int mask) {
-  unsigned long eob;
-  _BitScanReverse(&eob, mask);
-  eob++;
-  if (mask == 0)
-    eob = 0;
-  return eob;
-}
-#else
-static int bsr(int mask) {
-  int eob;
-#if defined(__GNUC__) && __GNUC__
-  __asm__ __volatile__("bsr %1, %0" : "=r" (eob) : "r" (mask) : "flags");
-#elif defined(__SUNPRO_C) || defined(__SUNPRO_CC)
-  asm volatile("bsr %1, %0" : "=r" (eob) : "r" (mask) : "flags");
-#endif
-  eob++;
-  if (mask == 0)
-    eob = 0;
-  return eob;
-}
-#endif
-
-void vp8_fast_quantize_b_ssse3(BLOCK *b, BLOCKD *d) {
-  int eob, mask;
-
-  __m128i z0 = _mm_load_si128((__m128i *)(b->coeff));
-  __m128i z1 = _mm_load_si128((__m128i *)(b->coeff + 8));
-  __m128i round0 = _mm_load_si128((__m128i *)(b->round));
-  __m128i round1 = _mm_load_si128((__m128i *)(b->round + 8));
-  __m128i quant_fast0 = _mm_load_si128((__m128i *)(b->quant_fast));
-  __m128i quant_fast1 = _mm_load_si128((__m128i *)(b->quant_fast + 8));
-  __m128i dequant0 = _mm_load_si128((__m128i *)(d->dequant));
-  __m128i dequant1 = _mm_load_si128((__m128i *)(d->dequant + 8));
-
-  __m128i sz0, sz1, x, x0, x1, y0, y1, zeros, abs0, abs1;
-
-  DECLARE_ALIGNED(16, const uint8_t, pshufb_zig_zag_mask[16]) =
-    { 0, 1, 4, 8, 5, 2, 3, 6, 9, 12, 13, 10, 7, 11, 14, 15 };
-  __m128i zig_zag = _mm_load_si128((const __m128i *)pshufb_zig_zag_mask);
-
-  /* sign of z: z >> 15 */
-  sz0 = _mm_srai_epi16(z0, 15);
-  sz1 = _mm_srai_epi16(z1, 15);
-
-  /* x = abs(z) */
-  x0 = _mm_abs_epi16(z0);
-  x1 = _mm_abs_epi16(z1);
-
-  /* x += round */
-  x0 = _mm_add_epi16(x0, round0);
-  x1 = _mm_add_epi16(x1, round1);
-
-  /* y = (x * quant) >> 16 */
-  y0 = _mm_mulhi_epi16(x0, quant_fast0);
-  y1 = _mm_mulhi_epi16(x1, quant_fast1);
-
-  /* ASM saves Y for EOB */
-  /* I think we can ignore that because adding the sign doesn't change anything
-   * and multiplying 0 by dequant is OK as well */
-  abs0 = y0;
-  abs1 = y1;
-
-  /* Restore the sign bit. */
-  y0 = _mm_xor_si128(y0, sz0);
-  y1 = _mm_xor_si128(y1, sz1);
-  x0 = _mm_sub_epi16(y0, sz0);
-  x1 = _mm_sub_epi16(y1, sz1);
-
-  /* qcoeff = x */
-  _mm_store_si128((__m128i *)(d->qcoeff), x0);
-  _mm_store_si128((__m128i *)(d->qcoeff + 8), x1);
-
-  /* x * dequant */
-  x0 = _mm_mullo_epi16(x0, dequant0);
-  x1 = _mm_mullo_epi16(x1, dequant1);
-
-  /* dqcoeff = x * dequant */
-  _mm_store_si128((__m128i *)(d->dqcoeff), x0);
-  _mm_store_si128((__m128i *)(d->dqcoeff + 8), x1);
-
-  zeros = _mm_setzero_si128();
-
-  x0 = _mm_cmpgt_epi16(abs0, zeros);
-  x1 = _mm_cmpgt_epi16(abs1, zeros);
-
-  x = _mm_packs_epi16(x0, x1);
-
-  x = _mm_shuffle_epi8(x, zig_zag);
-
-  mask = _mm_movemask_epi8(x);
-
-  eob = bsr(mask);
-
-  *d->eob = 0xFF & eob;
-}
diff --git a/vp8/encoder/x86/temporal_filter_apply_sse2.asm b/vp8/encoder/x86/temporal_filter_apply_sse2.asm
deleted file mode 100644 (file)
index bd92b39..0000000
+++ /dev/null
@@ -1,207 +0,0 @@
-;
-;  Copyright (c) 2010 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.
-;
-
-
-%include "vpx_ports/x86_abi_support.asm"
-
-; void vp8_temporal_filter_apply_sse2 | arg
-;  (unsigned char  *frame1,           |  0
-;   unsigned int    stride,           |  1
-;   unsigned char  *frame2,           |  2
-;   unsigned int    block_size,       |  3
-;   int             strength,         |  4
-;   int             filter_weight,    |  5
-;   unsigned int   *accumulator,      |  6
-;   unsigned short *count)            |  7
-global sym(vp8_temporal_filter_apply_sse2) PRIVATE
-sym(vp8_temporal_filter_apply_sse2):
-
-    push        rbp
-    mov         rbp, rsp
-    SHADOW_ARGS_TO_STACK 8
-    SAVE_XMM 7
-    GET_GOT     rbx
-    push        rsi
-    push        rdi
-    ALIGN_STACK 16, rax
-    %define block_size    0
-    %define strength      16
-    %define filter_weight 32
-    %define rounding_bit  48
-    %define rbp_backup    64
-    %define stack_size    80
-    sub         rsp,           stack_size
-    mov         [rsp + rbp_backup], rbp
-    ; end prolog
-
-        mov         rdx,            arg(3)
-        mov         [rsp + block_size], rdx
-        movd        xmm6,            arg(4)
-        movdqa      [rsp + strength], xmm6 ; where strength is used, all 16 bytes are read
-
-        ; calculate the rounding bit outside the loop
-        ; 0x8000 >> (16 - strength)
-        mov         rdx,            16
-        sub         rdx,            arg(4) ; 16 - strength
-        movq        xmm4,           rdx    ; can't use rdx w/ shift
-        movdqa      xmm5,           [GLOBAL(_const_top_bit)]
-        psrlw       xmm5,           xmm4
-        movdqa      [rsp + rounding_bit], xmm5
-
-        mov         rsi,            arg(0) ; src/frame1
-        mov         rdx,            arg(2) ; predictor frame
-        mov         rdi,            arg(6) ; accumulator
-        mov         rax,            arg(7) ; count
-
-        ; dup the filter weight and store for later
-        movd        xmm0,           arg(5) ; filter_weight
-        pshuflw     xmm0,           xmm0, 0
-        punpcklwd   xmm0,           xmm0
-        movdqa      [rsp + filter_weight], xmm0
-
-        mov         rbp,            arg(1) ; stride
-        pxor        xmm7,           xmm7   ; zero for extraction
-
-        lea         rcx,            [rdx + 16*16*1]
-        cmp         dword ptr [rsp + block_size], 8
-        jne         .temporal_filter_apply_load_16
-        lea         rcx,            [rdx + 8*8*1]
-
-.temporal_filter_apply_load_8:
-        movq        xmm0,           [rsi]  ; first row
-        lea         rsi,            [rsi + rbp] ; += stride
-        punpcklbw   xmm0,           xmm7   ; src[ 0- 7]
-        movq        xmm1,           [rsi]  ; second row
-        lea         rsi,            [rsi + rbp] ; += stride
-        punpcklbw   xmm1,           xmm7   ; src[ 8-15]
-        jmp         .temporal_filter_apply_load_finished
-
-.temporal_filter_apply_load_16:
-        movdqa      xmm0,           [rsi]  ; src (frame1)
-        lea         rsi,            [rsi + rbp] ; += stride
-        movdqa      xmm1,           xmm0
-        punpcklbw   xmm0,           xmm7   ; src[ 0- 7]
-        punpckhbw   xmm1,           xmm7   ; src[ 8-15]
-
-.temporal_filter_apply_load_finished:
-        movdqa      xmm2,           [rdx]  ; predictor (frame2)
-        movdqa      xmm3,           xmm2
-        punpcklbw   xmm2,           xmm7   ; pred[ 0- 7]
-        punpckhbw   xmm3,           xmm7   ; pred[ 8-15]
-
-        ; modifier = src_byte - pixel_value
-        psubw       xmm0,           xmm2   ; src - pred[ 0- 7]
-        psubw       xmm1,           xmm3   ; src - pred[ 8-15]
-
-        ; modifier *= modifier
-        pmullw      xmm0,           xmm0   ; modifer[ 0- 7]^2
-        pmullw      xmm1,           xmm1   ; modifer[ 8-15]^2
-
-        ; modifier *= 3
-        pmullw      xmm0,           [GLOBAL(_const_3w)]
-        pmullw      xmm1,           [GLOBAL(_const_3w)]
-
-        ; modifer += 0x8000 >> (16 - strength)
-        paddw       xmm0,           [rsp + rounding_bit]
-        paddw       xmm1,           [rsp + rounding_bit]
-
-        ; modifier >>= strength
-        psrlw       xmm0,           [rsp + strength]
-        psrlw       xmm1,           [rsp + strength]
-
-        ; modifier = 16 - modifier
-        ; saturation takes care of modifier > 16
-        movdqa      xmm3,           [GLOBAL(_const_16w)]
-        movdqa      xmm2,           [GLOBAL(_const_16w)]
-        psubusw     xmm3,           xmm1
-        psubusw     xmm2,           xmm0
-
-        ; modifier *= filter_weight
-        pmullw      xmm2,           [rsp + filter_weight]
-        pmullw      xmm3,           [rsp + filter_weight]
-
-        ; count
-        movdqa      xmm4,           [rax]
-        movdqa      xmm5,           [rax+16]
-        ; += modifier
-        paddw       xmm4,           xmm2
-        paddw       xmm5,           xmm3
-        ; write back
-        movdqa      [rax],          xmm4
-        movdqa      [rax+16],       xmm5
-        lea         rax,            [rax + 16*2] ; count += 16*(sizeof(short))
-
-        ; load and extract the predictor up to shorts
-        pxor        xmm7,           xmm7
-        movdqa      xmm0,           [rdx]
-        lea         rdx,            [rdx + 16*1] ; pred += 16*(sizeof(char))
-        movdqa      xmm1,           xmm0
-        punpcklbw   xmm0,           xmm7   ; pred[ 0- 7]
-        punpckhbw   xmm1,           xmm7   ; pred[ 8-15]
-
-        ; modifier *= pixel_value
-        pmullw      xmm0,           xmm2
-        pmullw      xmm1,           xmm3
-
-        ; expand to double words
-        movdqa      xmm2,           xmm0
-        punpcklwd   xmm0,           xmm7   ; [ 0- 3]
-        punpckhwd   xmm2,           xmm7   ; [ 4- 7]
-        movdqa      xmm3,           xmm1
-        punpcklwd   xmm1,           xmm7   ; [ 8-11]
-        punpckhwd   xmm3,           xmm7   ; [12-15]
-
-        ; accumulator
-        movdqa      xmm4,           [rdi]
-        movdqa      xmm5,           [rdi+16]
-        movdqa      xmm6,           [rdi+32]
-        movdqa      xmm7,           [rdi+48]
-        ; += modifier
-        paddd       xmm4,           xmm0
-        paddd       xmm5,           xmm2
-        paddd       xmm6,           xmm1
-        paddd       xmm7,           xmm3
-        ; write back
-        movdqa      [rdi],          xmm4
-        movdqa      [rdi+16],       xmm5
-        movdqa      [rdi+32],       xmm6
-        movdqa      [rdi+48],       xmm7
-        lea         rdi,            [rdi + 16*4] ; accumulator += 16*(sizeof(int))
-
-        cmp         rdx,            rcx
-        je          .temporal_filter_apply_epilog
-        pxor        xmm7,           xmm7   ; zero for extraction
-        cmp         dword ptr [rsp + block_size], 16
-        je          .temporal_filter_apply_load_16
-        jmp         .temporal_filter_apply_load_8
-
-.temporal_filter_apply_epilog:
-    ; begin epilog
-    mov         rbp,            [rsp + rbp_backup]
-    add         rsp,            stack_size
-    pop         rsp
-    pop         rdi
-    pop         rsi
-    RESTORE_GOT
-    RESTORE_XMM
-    UNSHADOW_ARGS
-    pop         rbp
-    ret
-
-SECTION_RODATA
-align 16
-_const_3w:
-    times 8 dw 3
-align 16
-_const_top_bit:
-    times 8 dw 1<<15
-align 16
-_const_16w
-    times 8 dw 16
diff --git a/vp8/encoder/x86/vp8_enc_stubs_mmx.c b/vp8/encoder/x86/vp8_enc_stubs_mmx.c
deleted file mode 100644 (file)
index 7bf5155..0000000
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#include "vpx_config.h"
-#include "vp8_rtcd.h"
-#include "vpx_ports/x86.h"
-#include "vp8/encoder/block.h"
-
-void vp8_short_fdct4x4_mmx(short *input, short *output, int pitch);
-void vp8_short_fdct8x4_mmx(short *input, short *output, int pitch)
-{
-    vp8_short_fdct4x4_mmx(input,   output,    pitch);
-    vp8_short_fdct4x4_mmx(input + 4, output + 16, pitch);
-}
-
-int vp8_fast_quantize_b_impl_mmx(short *coeff_ptr, short *zbin_ptr,
-                                 short *qcoeff_ptr, short *dequant_ptr,
-                                 const short *scan_mask, short *round_ptr,
-                                 short *quant_ptr, short *dqcoeff_ptr);
-void vp8_fast_quantize_b_mmx(BLOCK *b, BLOCKD *d)
-{
-    const short *scan_mask   = vp8_default_zig_zag_mask;
-    short *coeff_ptr   = b->coeff;
-    short *zbin_ptr    = b->zbin;
-    short *round_ptr   = b->round;
-    short *quant_ptr   = b->quant_fast;
-    short *qcoeff_ptr  = d->qcoeff;
-    short *dqcoeff_ptr = d->dqcoeff;
-    short *dequant_ptr = d->dequant;
-
-    *d->eob = (char)vp8_fast_quantize_b_impl_mmx(
-                                                 coeff_ptr,
-                                                 zbin_ptr,
-                                                 qcoeff_ptr,
-                                                 dequant_ptr,
-                                                 scan_mask,
-
-                                                 round_ptr,
-                                                 quant_ptr,
-                                                 dqcoeff_ptr
-                                                 );
-}
-
-int vp8_mbblock_error_mmx_impl(short *coeff_ptr, short *dcoef_ptr, int dc);
-int vp8_mbblock_error_mmx(MACROBLOCK *mb, int dc)
-{
-    short *coeff_ptr =  mb->block[0].coeff;
-    short *dcoef_ptr =  mb->e_mbd.block[0].dqcoeff;
-    return vp8_mbblock_error_mmx_impl(coeff_ptr, dcoef_ptr, dc);
-}
-
-int vp8_mbuverror_mmx_impl(short *s_ptr, short *d_ptr);
-int vp8_mbuverror_mmx(MACROBLOCK *mb)
-{
-    short *s_ptr = &mb->coeff[256];
-    short *d_ptr = &mb->e_mbd.dqcoeff[256];
-    return vp8_mbuverror_mmx_impl(s_ptr, d_ptr);
-}
-
diff --git a/vp8/encoder/x86/vp8_enc_stubs_sse2.c b/vp8/encoder/x86/vp8_enc_stubs_sse2.c
deleted file mode 100644 (file)
index be9aaf3..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- *  Copyright (c) 2012 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.
- */
-
-
-#include "vpx_config.h"
-#include "vp8_rtcd.h"
-#include "vpx_ports/x86.h"
-#include "vp8/encoder/block.h"
-
-int vp8_mbblock_error_xmm_impl(short *coeff_ptr, short *dcoef_ptr, int dc);
-int vp8_mbblock_error_xmm(MACROBLOCK *mb, int dc)
-{
-    short *coeff_ptr =  mb->block[0].coeff;
-    short *dcoef_ptr =  mb->e_mbd.block[0].dqcoeff;
-    return vp8_mbblock_error_xmm_impl(coeff_ptr, dcoef_ptr, dc);
-}
-
-int vp8_mbuverror_xmm_impl(short *s_ptr, short *d_ptr);
-int vp8_mbuverror_xmm(MACROBLOCK *mb)
-{
-    short *s_ptr = &mb->coeff[256];
-    short *d_ptr = &mb->e_mbd.dqcoeff[256];
-    return vp8_mbuverror_xmm_impl(s_ptr, d_ptr);
-}
-
diff --git a/vp8/encoder/x86/vp8_quantize_sse2.c b/vp8/encoder/x86/vp8_quantize_sse2.c
deleted file mode 100644 (file)
index b4e92e0..0000000
+++ /dev/null
@@ -1,228 +0,0 @@
-/*
- *  Copyright (c) 2012 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.
- */
-
-
-#include "vpx_config.h"
-#include "vp8_rtcd.h"
-#include "vpx_ports/x86.h"
-#include "vpx_mem/vpx_mem.h"
-#include "vp8/encoder/block.h"
-#include "vp8/common/entropy.h" /* vp8_default_inv_zig_zag */
-
-#include <mmintrin.h> /* MMX */
-#include <xmmintrin.h> /* SSE */
-#include <emmintrin.h> /* SSE2 */
-
-#define SELECT_EOB(i, z) \
-    do { \
-        short boost = *zbin_boost_ptr; \
-        int cmp = (x[z] < boost) | (y[z] == 0); \
-        zbin_boost_ptr++; \
-        if (cmp) \
-            break; \
-        qcoeff_ptr[z] = y[z]; \
-        eob = i; \
-        zbin_boost_ptr = b->zrun_zbin_boost; \
-    } while (0)
-
-void vp8_regular_quantize_b_sse2(BLOCK *b, BLOCKD *d)
-{
-    char eob = 0;
-    short *zbin_boost_ptr;
-    short *qcoeff_ptr      = d->qcoeff;
-    DECLARE_ALIGNED(16, short, x[16]);
-    DECLARE_ALIGNED(16, short, y[16]);
-
-    __m128i sz0, x0, sz1, x1, y0, y1, x_minus_zbin0, x_minus_zbin1;
-    __m128i quant_shift0 = _mm_load_si128((__m128i *)(b->quant_shift));
-    __m128i quant_shift1 = _mm_load_si128((__m128i *)(b->quant_shift + 8));
-    __m128i z0 = _mm_load_si128((__m128i *)(b->coeff));
-    __m128i z1 = _mm_load_si128((__m128i *)(b->coeff+8));
-    __m128i zbin_extra = _mm_cvtsi32_si128(b->zbin_extra);
-    __m128i zbin0 = _mm_load_si128((__m128i *)(b->zbin));
-    __m128i zbin1 = _mm_load_si128((__m128i *)(b->zbin + 8));
-    __m128i round0 = _mm_load_si128((__m128i *)(b->round));
-    __m128i round1 = _mm_load_si128((__m128i *)(b->round + 8));
-    __m128i quant0 = _mm_load_si128((__m128i *)(b->quant));
-    __m128i quant1 = _mm_load_si128((__m128i *)(b->quant + 8));
-    __m128i dequant0 = _mm_load_si128((__m128i *)(d->dequant));
-    __m128i dequant1 = _mm_load_si128((__m128i *)(d->dequant + 8));
-
-    memset(qcoeff_ptr, 0, 32);
-
-    /* Duplicate to all lanes. */
-    zbin_extra = _mm_shufflelo_epi16(zbin_extra, 0);
-    zbin_extra = _mm_unpacklo_epi16(zbin_extra, zbin_extra);
-
-    /* Sign of z: z >> 15 */
-    sz0 = _mm_srai_epi16(z0, 15);
-    sz1 = _mm_srai_epi16(z1, 15);
-
-    /* x = abs(z): (z ^ sz) - sz */
-    x0 = _mm_xor_si128(z0, sz0);
-    x1 = _mm_xor_si128(z1, sz1);
-    x0 = _mm_sub_epi16(x0, sz0);
-    x1 = _mm_sub_epi16(x1, sz1);
-
-    /* zbin[] + zbin_extra */
-    zbin0 = _mm_add_epi16(zbin0, zbin_extra);
-    zbin1 = _mm_add_epi16(zbin1, zbin_extra);
-
-    /* In C x is compared to zbin where zbin = zbin[] + boost + extra. Rebalance
-     * the equation because boost is the only value which can change:
-     * x - (zbin[] + extra) >= boost */
-    x_minus_zbin0 = _mm_sub_epi16(x0, zbin0);
-    x_minus_zbin1 = _mm_sub_epi16(x1, zbin1);
-
-    _mm_store_si128((__m128i *)(x), x_minus_zbin0);
-    _mm_store_si128((__m128i *)(x + 8), x_minus_zbin1);
-
-    /* All the remaining calculations are valid whether they are done now with
-     * simd or later inside the loop one at a time. */
-    x0 = _mm_add_epi16(x0, round0);
-    x1 = _mm_add_epi16(x1, round1);
-
-    y0 = _mm_mulhi_epi16(x0, quant0);
-    y1 = _mm_mulhi_epi16(x1, quant1);
-
-    y0 = _mm_add_epi16(y0, x0);
-    y1 = _mm_add_epi16(y1, x1);
-
-    /* Instead of shifting each value independently we convert the scaling
-     * factor with 1 << (16 - shift) so we can use multiply/return high half. */
-    y0 = _mm_mulhi_epi16(y0, quant_shift0);
-    y1 = _mm_mulhi_epi16(y1, quant_shift1);
-
-    /* Return the sign: (y ^ sz) - sz */
-    y0 = _mm_xor_si128(y0, sz0);
-    y1 = _mm_xor_si128(y1, sz1);
-    y0 = _mm_sub_epi16(y0, sz0);
-    y1 = _mm_sub_epi16(y1, sz1);
-
-    _mm_store_si128((__m128i *)(y), y0);
-    _mm_store_si128((__m128i *)(y + 8), y1);
-
-    zbin_boost_ptr = b->zrun_zbin_boost;
-
-    /* The loop gets unrolled anyway. Avoid the vp8_default_zig_zag1d lookup. */
-    SELECT_EOB(1, 0);
-    SELECT_EOB(2, 1);
-    SELECT_EOB(3, 4);
-    SELECT_EOB(4, 8);
-    SELECT_EOB(5, 5);
-    SELECT_EOB(6, 2);
-    SELECT_EOB(7, 3);
-    SELECT_EOB(8, 6);
-    SELECT_EOB(9, 9);
-    SELECT_EOB(10, 12);
-    SELECT_EOB(11, 13);
-    SELECT_EOB(12, 10);
-    SELECT_EOB(13, 7);
-    SELECT_EOB(14, 11);
-    SELECT_EOB(15, 14);
-    SELECT_EOB(16, 15);
-
-    y0 = _mm_load_si128((__m128i *)(d->qcoeff));
-    y1 = _mm_load_si128((__m128i *)(d->qcoeff + 8));
-
-    /* dqcoeff = qcoeff * dequant */
-    y0 = _mm_mullo_epi16(y0, dequant0);
-    y1 = _mm_mullo_epi16(y1, dequant1);
-
-    _mm_store_si128((__m128i *)(d->dqcoeff), y0);
-    _mm_store_si128((__m128i *)(d->dqcoeff + 8), y1);
-
-    *d->eob = eob;
-}
-
-void vp8_fast_quantize_b_sse2(BLOCK *b, BLOCKD *d)
-{
-  __m128i z0 = _mm_load_si128((__m128i *)(b->coeff));
-  __m128i z1 = _mm_load_si128((__m128i *)(b->coeff + 8));
-  __m128i round0 = _mm_load_si128((__m128i *)(b->round));
-  __m128i round1 = _mm_load_si128((__m128i *)(b->round + 8));
-  __m128i quant_fast0 = _mm_load_si128((__m128i *)(b->quant_fast));
-  __m128i quant_fast1 = _mm_load_si128((__m128i *)(b->quant_fast + 8));
-  __m128i dequant0 = _mm_load_si128((__m128i *)(d->dequant));
-  __m128i dequant1 = _mm_load_si128((__m128i *)(d->dequant + 8));
-  __m128i inv_zig_zag0 = _mm_load_si128((const __m128i *)(vp8_default_inv_zig_zag));
-  __m128i inv_zig_zag1 = _mm_load_si128((const __m128i *)(vp8_default_inv_zig_zag + 8));
-
-  __m128i sz0, sz1, x0, x1, y0, y1, xdq0, xdq1, zeros, ones;
-
-  /* sign of z: z >> 15 */
-  sz0 = _mm_srai_epi16(z0, 15);
-  sz1 = _mm_srai_epi16(z1, 15);
-
-  /* x = abs(z): (z ^ sz) - sz */
-  x0 = _mm_xor_si128(z0, sz0);
-  x1 = _mm_xor_si128(z1, sz1);
-  x0 = _mm_sub_epi16(x0, sz0);
-  x1 = _mm_sub_epi16(x1, sz1);
-
-  /* x += round */
-  x0 = _mm_add_epi16(x0, round0);
-  x1 = _mm_add_epi16(x1, round1);
-
-  /* y = (x * quant) >> 16 */
-  y0 = _mm_mulhi_epi16(x0, quant_fast0);
-  y1 = _mm_mulhi_epi16(x1, quant_fast1);
-
-  /* x = abs(y) = (y ^ sz) - sz */
-  y0 = _mm_xor_si128(y0, sz0);
-  y1 = _mm_xor_si128(y1, sz1);
-  x0 = _mm_sub_epi16(y0, sz0);
-  x1 = _mm_sub_epi16(y1, sz1);
-
-  /* qcoeff = x */
-  _mm_store_si128((__m128i *)(d->qcoeff), x0);
-  _mm_store_si128((__m128i *)(d->qcoeff + 8), x1);
-
-  /* x * dequant */
-  xdq0 = _mm_mullo_epi16(x0, dequant0);
-  xdq1 = _mm_mullo_epi16(x1, dequant1);
-
-  /* dqcoeff = x * dequant */
-  _mm_store_si128((__m128i *)(d->dqcoeff), xdq0);
-  _mm_store_si128((__m128i *)(d->dqcoeff + 8), xdq1);
-
-  /* build a mask for the zig zag */
-  zeros = _mm_setzero_si128();
-
-  x0 = _mm_cmpeq_epi16(x0, zeros);
-  x1 = _mm_cmpeq_epi16(x1, zeros);
-
-  ones = _mm_cmpeq_epi16(zeros, zeros);
-
-  x0 = _mm_xor_si128(x0, ones);
-  x1 = _mm_xor_si128(x1, ones);
-
-  x0 = _mm_and_si128(x0, inv_zig_zag0);
-  x1 = _mm_and_si128(x1, inv_zig_zag1);
-
-  x0 = _mm_max_epi16(x0, x1);
-
-  /* now down to 8 */
-  x1 = _mm_shuffle_epi32(x0, 0xE); // 0b00001110
-
-  x0 = _mm_max_epi16(x0, x1);
-
-  /* only 4 left */
-  x1 = _mm_shufflelo_epi16(x0, 0xE); // 0b00001110
-
-  x0 = _mm_max_epi16(x0, x1);
-
-  /* okay, just 2! */
-  x1 = _mm_shufflelo_epi16(x0, 0x1); // 0b00000001
-
-  x0 = _mm_max_epi16(x0, x1);
-
-  *d->eob = 0xFF & _mm_cvtsi128_si32(x0);
-}
diff --git a/vp8/exports_dec b/vp8/exports_dec
deleted file mode 100644 (file)
index 100ac5c..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-data vpx_codec_vp8_dx_algo
-text vpx_codec_vp8_dx
diff --git a/vp8/exports_enc b/vp8/exports_enc
deleted file mode 100644 (file)
index 29ff35e..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-data vpx_codec_vp8_cx_algo
-text vpx_codec_vp8_cx
diff --git a/vp8/vp8_common.mk b/vp8/vp8_common.mk
deleted file mode 100644 (file)
index ec39d2e..0000000
+++ /dev/null
@@ -1,166 +0,0 @@
-##
-##  Copyright (c) 2010 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.
-##
-
-VP8_COMMON_SRCS-yes += vp8_common.mk
-VP8_COMMON_SRCS-yes += common/ppflags.h
-VP8_COMMON_SRCS-yes += common/onyx.h
-VP8_COMMON_SRCS-yes += common/onyxd.h
-VP8_COMMON_SRCS-yes += common/alloccommon.c
-VP8_COMMON_SRCS-yes += common/blockd.c
-VP8_COMMON_SRCS-yes += common/coefupdateprobs.h
-VP8_COMMON_SRCS-yes += common/copy_c.c
-VP8_COMMON_SRCS-yes += common/debugmodes.c
-VP8_COMMON_SRCS-yes += common/default_coef_probs.h
-VP8_COMMON_SRCS-yes += common/dequantize.c
-VP8_COMMON_SRCS-yes += common/entropy.c
-VP8_COMMON_SRCS-yes += common/entropymode.c
-VP8_COMMON_SRCS-yes += common/entropymv.c
-VP8_COMMON_SRCS-yes += common/extend.c
-VP8_COMMON_SRCS-yes += common/filter.c
-VP8_COMMON_SRCS-yes += common/filter.h
-VP8_COMMON_SRCS-yes += common/findnearmv.c
-VP8_COMMON_SRCS-yes += common/generic/systemdependent.c
-VP8_COMMON_SRCS-yes += common/idct_blk.c
-VP8_COMMON_SRCS-yes += common/idctllm.c
-VP8_COMMON_SRCS-yes += common/alloccommon.h
-VP8_COMMON_SRCS-yes += common/blockd.h
-VP8_COMMON_SRCS-yes += common/common.h
-VP8_COMMON_SRCS-yes += common/entropy.h
-VP8_COMMON_SRCS-yes += common/entropymode.h
-VP8_COMMON_SRCS-yes += common/entropymv.h
-VP8_COMMON_SRCS-yes += common/extend.h
-VP8_COMMON_SRCS-yes += common/findnearmv.h
-VP8_COMMON_SRCS-yes += common/header.h
-VP8_COMMON_SRCS-yes += common/invtrans.h
-VP8_COMMON_SRCS-yes += common/loopfilter.h
-VP8_COMMON_SRCS-yes += common/modecont.h
-VP8_COMMON_SRCS-yes += common/mv.h
-VP8_COMMON_SRCS-yes += common/onyxc_int.h
-VP8_COMMON_SRCS-yes += common/quant_common.h
-VP8_COMMON_SRCS-yes += common/reconinter.h
-VP8_COMMON_SRCS-yes += common/reconintra.h
-VP8_COMMON_SRCS-yes += common/reconintra4x4.h
-VP8_COMMON_SRCS-yes += common/rtcd.c
-VP8_COMMON_SRCS-yes += common/rtcd_defs.pl
-VP8_COMMON_SRCS-yes += common/setupintrarecon.h
-VP8_COMMON_SRCS-yes += common/swapyv12buffer.h
-VP8_COMMON_SRCS-yes += common/systemdependent.h
-VP8_COMMON_SRCS-yes += common/threading.h
-VP8_COMMON_SRCS-yes += common/treecoder.h
-VP8_COMMON_SRCS-yes += common/vp8_loopfilter.c
-VP8_COMMON_SRCS-yes += common/loopfilter_filters.c
-VP8_COMMON_SRCS-yes += common/mbpitch.c
-VP8_COMMON_SRCS-yes += common/modecont.c
-VP8_COMMON_SRCS-yes += common/quant_common.c
-VP8_COMMON_SRCS-yes += common/reconinter.c
-VP8_COMMON_SRCS-yes += common/reconintra.c
-VP8_COMMON_SRCS-yes += common/reconintra4x4.c
-VP8_COMMON_SRCS-yes += common/setupintrarecon.c
-VP8_COMMON_SRCS-yes += common/swapyv12buffer.c
-VP8_COMMON_SRCS-yes += common/vp8_entropymodedata.h
-
-
-
-VP8_COMMON_SRCS-$(CONFIG_POSTPROC_VISUALIZER) += common/textblit.c
-VP8_COMMON_SRCS-yes += common/treecoder.c
-
-VP8_COMMON_SRCS-$(ARCH_X86)$(ARCH_X86_64) += common/x86/filter_x86.c
-VP8_COMMON_SRCS-$(ARCH_X86)$(ARCH_X86_64) += common/x86/filter_x86.h
-VP8_COMMON_SRCS-$(ARCH_X86)$(ARCH_X86_64) += common/x86/vp8_asm_stubs.c
-VP8_COMMON_SRCS-$(ARCH_X86)$(ARCH_X86_64) += common/x86/loopfilter_x86.c
-VP8_COMMON_SRCS-$(CONFIG_POSTPROC) += common/mfqe.c
-VP8_COMMON_SRCS-$(CONFIG_POSTPROC) += common/postproc.h
-VP8_COMMON_SRCS-$(CONFIG_POSTPROC) += common/postproc.c
-VP8_COMMON_SRCS-$(HAVE_MMX) += common/x86/dequantize_mmx.asm
-VP8_COMMON_SRCS-$(HAVE_MMX) += common/x86/idct_blk_mmx.c
-VP8_COMMON_SRCS-$(HAVE_MMX) += common/x86/idctllm_mmx.asm
-VP8_COMMON_SRCS-$(HAVE_MMX) += common/x86/iwalsh_mmx.asm
-VP8_COMMON_SRCS-$(HAVE_MMX) += common/x86/vp8_loopfilter_mmx.asm
-VP8_COMMON_SRCS-$(HAVE_MMX) += common/x86/recon_mmx.asm
-VP8_COMMON_SRCS-$(HAVE_MMX) += common/x86/subpixel_mmx.asm
-VP8_COMMON_SRCS-$(HAVE_SSE2) += common/x86/copy_sse2.asm
-VP8_COMMON_SRCS-$(HAVE_SSE2) += common/x86/idct_blk_sse2.c
-VP8_COMMON_SRCS-$(HAVE_SSE2) += common/x86/idctllm_sse2.asm
-VP8_COMMON_SRCS-$(HAVE_SSE2) += common/x86/recon_sse2.asm
-VP8_COMMON_SRCS-$(HAVE_SSE2) += common/x86/subpixel_sse2.asm
-VP8_COMMON_SRCS-$(HAVE_SSE2) += common/x86/loopfilter_sse2.asm
-VP8_COMMON_SRCS-$(HAVE_SSE2) += common/x86/iwalsh_sse2.asm
-VP8_COMMON_SRCS-$(HAVE_SSE3) += common/x86/copy_sse3.asm
-VP8_COMMON_SRCS-$(HAVE_SSSE3) += common/x86/subpixel_ssse3.asm
-
-ifeq ($(CONFIG_POSTPROC),yes)
-VP8_COMMON_SRCS-$(HAVE_SSE2) += common/x86/mfqe_sse2.asm
-endif
-
-ifeq ($(ARCH_X86_64),yes)
-VP8_COMMON_SRCS-$(HAVE_SSE2) += common/x86/loopfilter_block_sse2_x86_64.asm
-endif
-
-# common (c)
-VP8_COMMON_SRCS-$(HAVE_DSPR2)  += common/mips/dspr2/idctllm_dspr2.c
-VP8_COMMON_SRCS-$(HAVE_DSPR2)  += common/mips/dspr2/filter_dspr2.c
-VP8_COMMON_SRCS-$(HAVE_DSPR2)  += common/mips/dspr2/vp8_loopfilter_filters_dspr2.c
-VP8_COMMON_SRCS-$(HAVE_DSPR2)  += common/mips/dspr2/reconinter_dspr2.c
-VP8_COMMON_SRCS-$(HAVE_DSPR2)  += common/mips/dspr2/idct_blk_dspr2.c
-VP8_COMMON_SRCS-$(HAVE_DSPR2)  += common/mips/dspr2/dequantize_dspr2.c
-
-# common (c)
-VP8_COMMON_SRCS-$(HAVE_MSA) += common/mips/msa/bilinear_filter_msa.c
-VP8_COMMON_SRCS-$(HAVE_MSA) += common/mips/msa/copymem_msa.c
-VP8_COMMON_SRCS-$(HAVE_MSA) += common/mips/msa/idct_msa.c
-VP8_COMMON_SRCS-$(HAVE_MSA) += common/mips/msa/loopfilter_filters_msa.c
-VP8_COMMON_SRCS-$(HAVE_MSA) += common/mips/msa/sixtap_filter_msa.c
-VP8_COMMON_SRCS-$(HAVE_MSA) += common/mips/msa/vp8_macros_msa.h
-
-ifeq ($(CONFIG_POSTPROC),yes)
-VP8_COMMON_SRCS-$(HAVE_MSA) += common/mips/msa/mfqe_msa.c
-endif
-
-# common (c)
-VP8_COMMON_SRCS-$(ARCH_ARM)  += common/arm/filter_arm.c
-VP8_COMMON_SRCS-$(ARCH_ARM)  += common/arm/loopfilter_arm.c
-VP8_COMMON_SRCS-$(ARCH_ARM)  += common/arm/dequantize_arm.c
-
-# common (media)
-VP8_COMMON_SRCS-$(HAVE_MEDIA)  += common/arm/bilinearfilter_arm.c
-VP8_COMMON_SRCS-$(HAVE_MEDIA)  += common/arm/bilinearfilter_arm.h
-VP8_COMMON_SRCS-$(HAVE_MEDIA)  += common/arm/armv6/bilinearfilter_v6$(ASM)
-VP8_COMMON_SRCS-$(HAVE_MEDIA)  += common/arm/armv6/copymem8x4_v6$(ASM)
-VP8_COMMON_SRCS-$(HAVE_MEDIA)  += common/arm/armv6/copymem8x8_v6$(ASM)
-VP8_COMMON_SRCS-$(HAVE_MEDIA)  += common/arm/armv6/copymem16x16_v6$(ASM)
-VP8_COMMON_SRCS-$(HAVE_MEDIA)  += common/arm/armv6/dc_only_idct_add_v6$(ASM)
-VP8_COMMON_SRCS-$(HAVE_MEDIA)  += common/arm/armv6/iwalsh_v6$(ASM)
-VP8_COMMON_SRCS-$(HAVE_MEDIA)  += common/arm/armv6/filter_v6$(ASM)
-VP8_COMMON_SRCS-$(HAVE_MEDIA)  += common/arm/armv6/idct_v6$(ASM)
-VP8_COMMON_SRCS-$(HAVE_MEDIA)  += common/arm/armv6/loopfilter_v6$(ASM)
-VP8_COMMON_SRCS-$(HAVE_MEDIA)  += common/arm/armv6/simpleloopfilter_v6$(ASM)
-VP8_COMMON_SRCS-$(HAVE_MEDIA)  += common/arm/armv6/sixtappredict8x4_v6$(ASM)
-VP8_COMMON_SRCS-$(HAVE_MEDIA)  += common/arm/armv6/dequant_idct_v6$(ASM)
-VP8_COMMON_SRCS-$(HAVE_MEDIA)  += common/arm/armv6/dequantize_v6$(ASM)
-VP8_COMMON_SRCS-$(HAVE_MEDIA)  += common/arm/armv6/idct_blk_v6.c
-
-# common (neon intrinsics)
-VP8_COMMON_SRCS-$(HAVE_NEON)  += common/arm/neon/bilinearpredict_neon.c
-VP8_COMMON_SRCS-$(HAVE_NEON)  += common/arm/neon/copymem_neon.c
-VP8_COMMON_SRCS-$(HAVE_NEON)  += common/arm/neon/dc_only_idct_add_neon.c
-VP8_COMMON_SRCS-$(HAVE_NEON)  += common/arm/neon/dequant_idct_neon.c
-VP8_COMMON_SRCS-$(HAVE_NEON)  += common/arm/neon/dequantizeb_neon.c
-VP8_COMMON_SRCS-$(HAVE_NEON)  += common/arm/neon/idct_blk_neon.c
-VP8_COMMON_SRCS-$(HAVE_NEON)  += common/arm/neon/idct_dequant_0_2x_neon.c
-VP8_COMMON_SRCS-$(HAVE_NEON)  += common/arm/neon/idct_dequant_full_2x_neon.c
-VP8_COMMON_SRCS-$(HAVE_NEON)  += common/arm/neon/iwalsh_neon.c
-VP8_COMMON_SRCS-$(HAVE_NEON)  += common/arm/neon/vp8_loopfilter_neon.c
-VP8_COMMON_SRCS-$(HAVE_NEON)  += common/arm/neon/loopfiltersimplehorizontaledge_neon.c
-VP8_COMMON_SRCS-$(HAVE_NEON)  += common/arm/neon/loopfiltersimpleverticaledge_neon.c
-VP8_COMMON_SRCS-$(HAVE_NEON)  += common/arm/neon/mbloopfilter_neon.c
-VP8_COMMON_SRCS-$(HAVE_NEON)  += common/arm/neon/shortidct4x4llm_neon.c
-VP8_COMMON_SRCS-$(HAVE_NEON)  += common/arm/neon/sixtappredict_neon.c
-
-$(eval $(call rtcd_h_template,vp8_rtcd,vp8/common/rtcd_defs.pl))
diff --git a/vp8/vp8_cx_iface.c b/vp8/vp8_cx_iface.c
deleted file mode 100644 (file)
index b19ab7a..0000000
+++ /dev/null
@@ -1,1377 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#include "./vpx_config.h"
-#include "./vp8_rtcd.h"
-#include "./vpx_dsp_rtcd.h"
-#include "./vpx_scale_rtcd.h"
-#include "vpx/vpx_codec.h"
-#include "vpx/internal/vpx_codec_internal.h"
-#include "vpx_version.h"
-#include "vpx_mem/vpx_mem.h"
-#include "vpx_ports/vpx_once.h"
-#include "vp8/encoder/onyx_int.h"
-#include "vpx/vp8cx.h"
-#include "vp8/encoder/firstpass.h"
-#include "vp8/common/onyx.h"
-#include "vp8/common/common.h"
-#include <stdlib.h>
-#include <string.h>
-
-struct vp8_extracfg
-{
-    struct vpx_codec_pkt_list *pkt_list;
-    int                         cpu_used;                    /** available cpu percentage in 1/16*/
-    unsigned int                enable_auto_alt_ref;           /** if encoder decides to uses alternate reference frame */
-    unsigned int                noise_sensitivity;
-    unsigned int                Sharpness;
-    unsigned int                static_thresh;
-    unsigned int                token_partitions;
-    unsigned int                arnr_max_frames;    /* alt_ref Noise Reduction Max Frame Count */
-    unsigned int                arnr_strength;    /* alt_ref Noise Reduction Strength */
-    unsigned int                arnr_type;        /* alt_ref filter type */
-    vp8e_tuning                 tuning;
-    unsigned int                cq_level;         /* constrained quality level */
-    unsigned int                rc_max_intra_bitrate_pct;
-    unsigned int                screen_content_mode;
-
-};
-
-static struct vp8_extracfg default_extracfg = {
-  NULL,
-#if !(CONFIG_REALTIME_ONLY)
-  0,                          /* cpu_used      */
-#else
-  4,                          /* cpu_used      */
-#endif
-  0,                          /* enable_auto_alt_ref */
-  0,                          /* noise_sensitivity */
-  0,                          /* Sharpness */
-  0,                          /* static_thresh */
-#if (CONFIG_REALTIME_ONLY & CONFIG_ONTHEFLY_BITPACKING)
-  VP8_EIGHT_TOKENPARTITION,
-#else
-  VP8_ONE_TOKENPARTITION,     /* token_partitions */
-#endif
-  0,                          /* arnr_max_frames */
-  3,                          /* arnr_strength */
-  3,                          /* arnr_type*/
-  0,                          /* tuning*/
-  10,                         /* cq_level */
-  0,                          /* rc_max_intra_bitrate_pct */
-  0,                          /* screen_content_mode */
-};
-
-struct vpx_codec_alg_priv
-{
-    vpx_codec_priv_t        base;
-    vpx_codec_enc_cfg_t     cfg;
-    struct vp8_extracfg     vp8_cfg;
-    VP8_CONFIG              oxcf;
-    struct VP8_COMP        *cpi;
-    unsigned char          *cx_data;
-    unsigned int            cx_data_sz;
-    vpx_image_t             preview_img;
-    unsigned int            next_frame_flag;
-    vp8_postproc_cfg_t      preview_ppcfg;
-    /* pkt_list size depends on the maximum number of lagged frames allowed. */
-    vpx_codec_pkt_list_decl(64) pkt_list;
-    unsigned int                fixed_kf_cntr;
-    vpx_enc_frame_flags_t   control_frame_flags;
-};
-
-
-static vpx_codec_err_t
-update_error_state(vpx_codec_alg_priv_t                 *ctx,
-                   const struct vpx_internal_error_info *error)
-{
-    vpx_codec_err_t res;
-
-    if ((res = error->error_code))
-        ctx->base.err_detail = error->has_detail
-                               ? error->detail
-                               : NULL;
-
-    return res;
-}
-
-
-#undef ERROR
-#define ERROR(str) do {\
-        ctx->base.err_detail = str;\
-        return VPX_CODEC_INVALID_PARAM;\
-    } while(0)
-
-#define RANGE_CHECK(p,memb,lo,hi) do {\
-        if(!(((p)->memb == lo || (p)->memb > (lo)) && (p)->memb <= hi)) \
-            ERROR(#memb " out of range ["#lo".."#hi"]");\
-    } while(0)
-
-#define RANGE_CHECK_HI(p,memb,hi) do {\
-        if(!((p)->memb <= (hi))) \
-            ERROR(#memb " out of range [.."#hi"]");\
-    } while(0)
-
-#define RANGE_CHECK_LO(p,memb,lo) do {\
-        if(!((p)->memb >= (lo))) \
-            ERROR(#memb " out of range ["#lo"..]");\
-    } while(0)
-
-#define RANGE_CHECK_BOOL(p,memb) do {\
-        if(!!((p)->memb) != (p)->memb) ERROR(#memb " expected boolean");\
-    } while(0)
-
-static vpx_codec_err_t validate_config(vpx_codec_alg_priv_t      *ctx,
-                                       const vpx_codec_enc_cfg_t *cfg,
-                                       const struct vp8_extracfg *vp8_cfg,
-                                       int                        finalize)
-{
-    RANGE_CHECK(cfg, g_w,                   1, 16383); /* 14 bits available */
-    RANGE_CHECK(cfg, g_h,                   1, 16383); /* 14 bits available */
-    RANGE_CHECK(cfg, g_timebase.den,        1, 1000000000);
-    RANGE_CHECK(cfg, g_timebase.num,        1, 1000000000);
-    RANGE_CHECK_HI(cfg, g_profile,          3);
-    RANGE_CHECK_HI(cfg, rc_max_quantizer,   63);
-    RANGE_CHECK_HI(cfg, rc_min_quantizer,   cfg->rc_max_quantizer);
-    RANGE_CHECK_HI(cfg, g_threads,          64);
-#if CONFIG_REALTIME_ONLY
-    RANGE_CHECK_HI(cfg, g_lag_in_frames,    0);
-#elif CONFIG_MULTI_RES_ENCODING
-    if (ctx->base.enc.total_encoders > 1)
-        RANGE_CHECK_HI(cfg, g_lag_in_frames,    0);
-#else
-    RANGE_CHECK_HI(cfg, g_lag_in_frames,    25);
-#endif
-    RANGE_CHECK(cfg, rc_end_usage,          VPX_VBR, VPX_Q);
-    RANGE_CHECK_HI(cfg, rc_undershoot_pct,  1000);
-    RANGE_CHECK_HI(cfg, rc_overshoot_pct,   1000);
-    RANGE_CHECK_HI(cfg, rc_2pass_vbr_bias_pct, 100);
-    RANGE_CHECK(cfg, kf_mode,               VPX_KF_DISABLED, VPX_KF_AUTO);
-
-/* TODO: add spatial re-sampling support and frame dropping in
- * multi-res-encoder.*/
-#if CONFIG_MULTI_RES_ENCODING
-    if (ctx->base.enc.total_encoders > 1)
-        RANGE_CHECK_HI(cfg, rc_resize_allowed,     0);
-#else
-    RANGE_CHECK_BOOL(cfg, rc_resize_allowed);
-#endif
-    RANGE_CHECK_HI(cfg, rc_dropframe_thresh,   100);
-    RANGE_CHECK_HI(cfg, rc_resize_up_thresh,   100);
-    RANGE_CHECK_HI(cfg, rc_resize_down_thresh, 100);
-
-#if CONFIG_REALTIME_ONLY
-    RANGE_CHECK(cfg,        g_pass,         VPX_RC_ONE_PASS, VPX_RC_ONE_PASS);
-#elif CONFIG_MULTI_RES_ENCODING
-    if (ctx->base.enc.total_encoders > 1)
-        RANGE_CHECK(cfg,    g_pass,         VPX_RC_ONE_PASS, VPX_RC_ONE_PASS);
-#else
-    RANGE_CHECK(cfg,        g_pass,         VPX_RC_ONE_PASS, VPX_RC_LAST_PASS);
-#endif
-
-    /* VP8 does not support a lower bound on the keyframe interval in
-     * automatic keyframe placement mode.
-     */
-    if (cfg->kf_mode != VPX_KF_DISABLED && cfg->kf_min_dist != cfg->kf_max_dist
-        && cfg->kf_min_dist > 0)
-        ERROR("kf_min_dist not supported in auto mode, use 0 "
-              "or kf_max_dist instead.");
-
-    RANGE_CHECK_BOOL(vp8_cfg,               enable_auto_alt_ref);
-    RANGE_CHECK(vp8_cfg, cpu_used,           -16, 16);
-
-#if CONFIG_REALTIME_ONLY && !CONFIG_TEMPORAL_DENOISING
-    RANGE_CHECK(vp8_cfg, noise_sensitivity,  0, 0);
-#else
-    RANGE_CHECK_HI(vp8_cfg, noise_sensitivity,  6);
-#endif
-
-    RANGE_CHECK(vp8_cfg, token_partitions,   VP8_ONE_TOKENPARTITION,
-                VP8_EIGHT_TOKENPARTITION);
-    RANGE_CHECK_HI(vp8_cfg, Sharpness,       7);
-    RANGE_CHECK(vp8_cfg, arnr_max_frames, 0, 15);
-    RANGE_CHECK_HI(vp8_cfg, arnr_strength,   6);
-    RANGE_CHECK(vp8_cfg, arnr_type,       1, 3);
-    RANGE_CHECK(vp8_cfg, cq_level, 0, 63);
-    RANGE_CHECK_HI(vp8_cfg, screen_content_mode, 2);
-    if (finalize && (cfg->rc_end_usage == VPX_CQ || cfg->rc_end_usage == VPX_Q))
-        RANGE_CHECK(vp8_cfg, cq_level,
-                    cfg->rc_min_quantizer, cfg->rc_max_quantizer);
-
-#if !(CONFIG_REALTIME_ONLY)
-    if (cfg->g_pass == VPX_RC_LAST_PASS)
-    {
-        size_t           packet_sz = sizeof(FIRSTPASS_STATS);
-        int              n_packets = (int)(cfg->rc_twopass_stats_in.sz /
-                                          packet_sz);
-        FIRSTPASS_STATS *stats;
-
-        if (!cfg->rc_twopass_stats_in.buf)
-            ERROR("rc_twopass_stats_in.buf not set.");
-
-        if (cfg->rc_twopass_stats_in.sz % packet_sz)
-            ERROR("rc_twopass_stats_in.sz indicates truncated packet.");
-
-        if (cfg->rc_twopass_stats_in.sz < 2 * packet_sz)
-            ERROR("rc_twopass_stats_in requires at least two packets.");
-
-        stats = (void*)((char *)cfg->rc_twopass_stats_in.buf
-                + (n_packets - 1) * packet_sz);
-
-        if ((int)(stats->count + 0.5) != n_packets - 1)
-            ERROR("rc_twopass_stats_in missing EOS stats packet");
-    }
-#endif
-
-    RANGE_CHECK(cfg, ts_number_layers, 1, 5);
-
-    if (cfg->ts_number_layers > 1)
-    {
-        unsigned int i;
-        RANGE_CHECK_HI(cfg, ts_periodicity, 16);
-
-        for (i=1; i<cfg->ts_number_layers; i++)
-            if (cfg->ts_target_bitrate[i] <= cfg->ts_target_bitrate[i-1] &&
-                cfg->rc_target_bitrate > 0)
-                ERROR("ts_target_bitrate entries are not strictly increasing");
-
-        RANGE_CHECK(cfg, ts_rate_decimator[cfg->ts_number_layers-1], 1, 1);
-        for (i=cfg->ts_number_layers-2; i>0; i--)
-            if (cfg->ts_rate_decimator[i-1] != 2*cfg->ts_rate_decimator[i])
-                ERROR("ts_rate_decimator factors are not powers of 2");
-
-        RANGE_CHECK_HI(cfg, ts_layer_id[i], cfg->ts_number_layers-1);
-    }
-
-#if (CONFIG_REALTIME_ONLY & CONFIG_ONTHEFLY_BITPACKING)
-    if(cfg->g_threads > (1 << vp8_cfg->token_partitions))
-        ERROR("g_threads cannot be bigger than number of token partitions");
-#endif
-
-    return VPX_CODEC_OK;
-}
-
-
-static vpx_codec_err_t validate_img(vpx_codec_alg_priv_t *ctx,
-                                    const vpx_image_t    *img)
-{
-    switch (img->fmt)
-    {
-    case VPX_IMG_FMT_YV12:
-    case VPX_IMG_FMT_I420:
-    case VPX_IMG_FMT_VPXI420:
-    case VPX_IMG_FMT_VPXYV12:
-        break;
-    default:
-        ERROR("Invalid image format. Only YV12 and I420 images are supported");
-    }
-
-    if ((img->d_w != ctx->cfg.g_w) || (img->d_h != ctx->cfg.g_h))
-        ERROR("Image size must match encoder init configuration size");
-
-    return VPX_CODEC_OK;
-}
-
-
-static vpx_codec_err_t set_vp8e_config(VP8_CONFIG *oxcf,
-                                       vpx_codec_enc_cfg_t cfg,
-                                       struct vp8_extracfg vp8_cfg,
-                                       vpx_codec_priv_enc_mr_cfg_t *mr_cfg)
-{
-    oxcf->multi_threaded         = cfg.g_threads;
-    oxcf->Version               = cfg.g_profile;
-
-    oxcf->Width                 = cfg.g_w;
-    oxcf->Height                = cfg.g_h;
-    oxcf->timebase              = cfg.g_timebase;
-
-    oxcf->error_resilient_mode = cfg.g_error_resilient;
-
-    switch (cfg.g_pass)
-    {
-    case VPX_RC_ONE_PASS:
-        oxcf->Mode = MODE_BESTQUALITY;
-        break;
-    case VPX_RC_FIRST_PASS:
-        oxcf->Mode = MODE_FIRSTPASS;
-        break;
-    case VPX_RC_LAST_PASS:
-        oxcf->Mode = MODE_SECONDPASS_BEST;
-        break;
-    }
-
-    if (cfg.g_pass == VPX_RC_FIRST_PASS || cfg.g_pass == VPX_RC_ONE_PASS)
-    {
-        oxcf->allow_lag     = 0;
-        oxcf->lag_in_frames = 0;
-    }
-    else
-    {
-        oxcf->allow_lag     = (cfg.g_lag_in_frames) > 0;
-        oxcf->lag_in_frames = cfg.g_lag_in_frames;
-    }
-
-    oxcf->allow_df               = (cfg.rc_dropframe_thresh > 0);
-    oxcf->drop_frames_water_mark   = cfg.rc_dropframe_thresh;
-
-    oxcf->allow_spatial_resampling = cfg.rc_resize_allowed;
-    oxcf->resample_up_water_mark   = cfg.rc_resize_up_thresh;
-    oxcf->resample_down_water_mark = cfg.rc_resize_down_thresh;
-
-    if (cfg.rc_end_usage == VPX_VBR) {
-      oxcf->end_usage = USAGE_LOCAL_FILE_PLAYBACK;
-    } else if (cfg.rc_end_usage == VPX_CBR) {
-      oxcf->end_usage = USAGE_STREAM_FROM_SERVER;
-    } else if (cfg.rc_end_usage == VPX_CQ) {
-      oxcf->end_usage = USAGE_CONSTRAINED_QUALITY;
-    } else if (cfg.rc_end_usage == VPX_Q) {
-      oxcf->end_usage = USAGE_CONSTANT_QUALITY;
-    }
-
-    oxcf->target_bandwidth         = cfg.rc_target_bitrate;
-    oxcf->rc_max_intra_bitrate_pct = vp8_cfg.rc_max_intra_bitrate_pct;
-
-    oxcf->best_allowed_q           = cfg.rc_min_quantizer;
-    oxcf->worst_allowed_q          = cfg.rc_max_quantizer;
-    oxcf->cq_level                 = vp8_cfg.cq_level;
-    oxcf->fixed_q = -1;
-
-    oxcf->under_shoot_pct          = cfg.rc_undershoot_pct;
-    oxcf->over_shoot_pct           = cfg.rc_overshoot_pct;
-
-    oxcf->maximum_buffer_size_in_ms   = cfg.rc_buf_sz;
-    oxcf->starting_buffer_level_in_ms = cfg.rc_buf_initial_sz;
-    oxcf->optimal_buffer_level_in_ms  = cfg.rc_buf_optimal_sz;
-
-    oxcf->maximum_buffer_size      = cfg.rc_buf_sz;
-    oxcf->starting_buffer_level    = cfg.rc_buf_initial_sz;
-    oxcf->optimal_buffer_level     = cfg.rc_buf_optimal_sz;
-
-    oxcf->two_pass_vbrbias         = cfg.rc_2pass_vbr_bias_pct;
-    oxcf->two_pass_vbrmin_section  = cfg.rc_2pass_vbr_minsection_pct;
-    oxcf->two_pass_vbrmax_section  = cfg.rc_2pass_vbr_maxsection_pct;
-
-    oxcf->auto_key                 = cfg.kf_mode == VPX_KF_AUTO
-                                       && cfg.kf_min_dist != cfg.kf_max_dist;
-    oxcf->key_freq                 = cfg.kf_max_dist;
-
-    oxcf->number_of_layers         = cfg.ts_number_layers;
-    oxcf->periodicity              = cfg.ts_periodicity;
-
-    if (oxcf->number_of_layers > 1)
-    {
-        memcpy (oxcf->target_bitrate, cfg.ts_target_bitrate,
-                sizeof(cfg.ts_target_bitrate));
-        memcpy (oxcf->rate_decimator, cfg.ts_rate_decimator,
-                sizeof(cfg.ts_rate_decimator));
-        memcpy (oxcf->layer_id, cfg.ts_layer_id, sizeof(cfg.ts_layer_id));
-    }
-
-#if CONFIG_MULTI_RES_ENCODING
-    /* When mr_cfg is NULL, oxcf->mr_total_resolutions and oxcf->mr_encoder_id
-     * are both memset to 0, which ensures the correct logic under this
-     * situation.
-     */
-    if(mr_cfg)
-    {
-        oxcf->mr_total_resolutions        = mr_cfg->mr_total_resolutions;
-        oxcf->mr_encoder_id               = mr_cfg->mr_encoder_id;
-        oxcf->mr_down_sampling_factor.num = mr_cfg->mr_down_sampling_factor.num;
-        oxcf->mr_down_sampling_factor.den = mr_cfg->mr_down_sampling_factor.den;
-        oxcf->mr_low_res_mode_info        = mr_cfg->mr_low_res_mode_info;
-    }
-#else
-    (void)mr_cfg;
-#endif
-
-    oxcf->cpu_used               = vp8_cfg.cpu_used;
-    oxcf->encode_breakout        = vp8_cfg.static_thresh;
-    oxcf->play_alternate         = vp8_cfg.enable_auto_alt_ref;
-    oxcf->noise_sensitivity      = vp8_cfg.noise_sensitivity;
-    oxcf->Sharpness              = vp8_cfg.Sharpness;
-    oxcf->token_partitions       = vp8_cfg.token_partitions;
-
-    oxcf->two_pass_stats_in      = cfg.rc_twopass_stats_in;
-    oxcf->output_pkt_list        = vp8_cfg.pkt_list;
-
-    oxcf->arnr_max_frames        = vp8_cfg.arnr_max_frames;
-    oxcf->arnr_strength          = vp8_cfg.arnr_strength;
-    oxcf->arnr_type              = vp8_cfg.arnr_type;
-
-    oxcf->tuning                 = vp8_cfg.tuning;
-
-    oxcf->screen_content_mode    = vp8_cfg.screen_content_mode;
-
-    /*
-        printf("Current VP8 Settings: \n");
-        printf("target_bandwidth: %d\n", oxcf->target_bandwidth);
-        printf("noise_sensitivity: %d\n", oxcf->noise_sensitivity);
-        printf("Sharpness: %d\n",    oxcf->Sharpness);
-        printf("cpu_used: %d\n",  oxcf->cpu_used);
-        printf("Mode: %d\n",     oxcf->Mode);
-        printf("auto_key: %d\n",  oxcf->auto_key);
-        printf("key_freq: %d\n", oxcf->key_freq);
-        printf("end_usage: %d\n", oxcf->end_usage);
-        printf("under_shoot_pct: %d\n", oxcf->under_shoot_pct);
-        printf("over_shoot_pct: %d\n", oxcf->over_shoot_pct);
-        printf("starting_buffer_level: %d\n", oxcf->starting_buffer_level);
-        printf("optimal_buffer_level: %d\n",  oxcf->optimal_buffer_level);
-        printf("maximum_buffer_size: %d\n", oxcf->maximum_buffer_size);
-        printf("fixed_q: %d\n",  oxcf->fixed_q);
-        printf("worst_allowed_q: %d\n", oxcf->worst_allowed_q);
-        printf("best_allowed_q: %d\n", oxcf->best_allowed_q);
-        printf("allow_spatial_resampling: %d\n",  oxcf->allow_spatial_resampling);
-        printf("resample_down_water_mark: %d\n", oxcf->resample_down_water_mark);
-        printf("resample_up_water_mark: %d\n", oxcf->resample_up_water_mark);
-        printf("allow_df: %d\n", oxcf->allow_df);
-        printf("drop_frames_water_mark: %d\n", oxcf->drop_frames_water_mark);
-        printf("two_pass_vbrbias: %d\n",  oxcf->two_pass_vbrbias);
-        printf("two_pass_vbrmin_section: %d\n", oxcf->two_pass_vbrmin_section);
-        printf("two_pass_vbrmax_section: %d\n", oxcf->two_pass_vbrmax_section);
-        printf("allow_lag: %d\n", oxcf->allow_lag);
-        printf("lag_in_frames: %d\n", oxcf->lag_in_frames);
-        printf("play_alternate: %d\n", oxcf->play_alternate);
-        printf("Version: %d\n", oxcf->Version);
-        printf("multi_threaded: %d\n",   oxcf->multi_threaded);
-        printf("encode_breakout: %d\n", oxcf->encode_breakout);
-    */
-    return VPX_CODEC_OK;
-}
-
-static vpx_codec_err_t vp8e_set_config(vpx_codec_alg_priv_t       *ctx,
-                                       const vpx_codec_enc_cfg_t  *cfg)
-{
-    vpx_codec_err_t res;
-
-    if (cfg->g_w != ctx->cfg.g_w || cfg->g_h != ctx->cfg.g_h)
-    {
-        if (cfg->g_lag_in_frames > 1 || cfg->g_pass != VPX_RC_ONE_PASS)
-            ERROR("Cannot change width or height after initialization");
-        if ((ctx->cpi->initial_width && (int)cfg->g_w > ctx->cpi->initial_width) ||
-            (ctx->cpi->initial_height && (int)cfg->g_h > ctx->cpi->initial_height))
-            ERROR("Cannot increase width or height larger than their initial values");
-    }
-
-    /* Prevent increasing lag_in_frames. This check is stricter than it needs
-     * to be -- the limit is not increasing past the first lag_in_frames
-     * value, but we don't track the initial config, only the last successful
-     * config.
-     */
-    if ((cfg->g_lag_in_frames > ctx->cfg.g_lag_in_frames))
-        ERROR("Cannot increase lag_in_frames");
-
-    res = validate_config(ctx, cfg, &ctx->vp8_cfg, 0);
-
-    if (!res)
-    {
-        ctx->cfg = *cfg;
-        set_vp8e_config(&ctx->oxcf, ctx->cfg, ctx->vp8_cfg, NULL);
-        vp8_change_config(ctx->cpi, &ctx->oxcf);
-    }
-
-    return res;
-}
-
-static vpx_codec_err_t get_quantizer(vpx_codec_alg_priv_t *ctx, va_list args)
-{
-  int *const arg = va_arg(args, int *);
-  if (arg == NULL)
-    return VPX_CODEC_INVALID_PARAM;
-  *arg = vp8_get_quantizer(ctx->cpi);
-  return VPX_CODEC_OK;
-}
-
-static vpx_codec_err_t get_quantizer64(vpx_codec_alg_priv_t *ctx, va_list args)
-{
-  int *const arg = va_arg(args, int *);
-  if (arg == NULL)
-    return VPX_CODEC_INVALID_PARAM;
-  *arg = vp8_reverse_trans(vp8_get_quantizer(ctx->cpi));
-  return VPX_CODEC_OK;
-}
-
-static vpx_codec_err_t update_extracfg(vpx_codec_alg_priv_t *ctx,
-                                       const struct vp8_extracfg *extra_cfg)
-{
-  const vpx_codec_err_t res = validate_config(ctx, &ctx->cfg, extra_cfg, 0);
-  if (res == VPX_CODEC_OK) {
-    ctx->vp8_cfg = *extra_cfg;
-    set_vp8e_config(&ctx->oxcf, ctx->cfg, ctx->vp8_cfg, NULL);
-    vp8_change_config(ctx->cpi, &ctx->oxcf);
-  }
-  return res;
-}
-
-static vpx_codec_err_t set_cpu_used(vpx_codec_alg_priv_t *ctx, va_list args)
-{
-  struct vp8_extracfg extra_cfg = ctx->vp8_cfg;
-  extra_cfg.cpu_used = CAST(VP8E_SET_CPUUSED, args);
-  return update_extracfg(ctx, &extra_cfg);
-}
-
-static vpx_codec_err_t set_enable_auto_alt_ref(vpx_codec_alg_priv_t *ctx,
-                                               va_list args)
-{
-  struct vp8_extracfg extra_cfg = ctx->vp8_cfg;
-  extra_cfg.enable_auto_alt_ref = CAST(VP8E_SET_ENABLEAUTOALTREF, args);
-  return update_extracfg(ctx, &extra_cfg);
-}
-
-static vpx_codec_err_t set_noise_sensitivity(vpx_codec_alg_priv_t *ctx,
-                                             va_list args)
-{
-  struct vp8_extracfg extra_cfg = ctx->vp8_cfg;
-  extra_cfg.noise_sensitivity = CAST(VP8E_SET_NOISE_SENSITIVITY, args);
-  return update_extracfg(ctx, &extra_cfg);
-}
-
-static vpx_codec_err_t set_sharpness(vpx_codec_alg_priv_t *ctx, va_list args)
-{
-  struct vp8_extracfg extra_cfg = ctx->vp8_cfg;
-  extra_cfg.Sharpness = CAST(VP8E_SET_SHARPNESS, args);
-  return update_extracfg(ctx, &extra_cfg);
-}
-
-static vpx_codec_err_t set_static_thresh(vpx_codec_alg_priv_t *ctx,
-                                         va_list args)
-{
-  struct vp8_extracfg extra_cfg = ctx->vp8_cfg;
-  extra_cfg.static_thresh = CAST(VP8E_SET_STATIC_THRESHOLD, args);
-  return update_extracfg(ctx, &extra_cfg);
-}
-
-static vpx_codec_err_t set_token_partitions(vpx_codec_alg_priv_t *ctx,
-                                            va_list args)
-{
-  struct vp8_extracfg extra_cfg = ctx->vp8_cfg;
-  extra_cfg.token_partitions = CAST(VP8E_SET_TOKEN_PARTITIONS, args);
-  return update_extracfg(ctx, &extra_cfg);
-}
-
-static vpx_codec_err_t set_arnr_max_frames(vpx_codec_alg_priv_t *ctx,
-                                           va_list args)
-{
-  struct vp8_extracfg extra_cfg = ctx->vp8_cfg;
-  extra_cfg.arnr_max_frames = CAST(VP8E_SET_ARNR_MAXFRAMES, args);
-  return update_extracfg(ctx, &extra_cfg);
-}
-
-static vpx_codec_err_t set_arnr_strength(vpx_codec_alg_priv_t *ctx,
-                                         va_list args)
-{
-  struct vp8_extracfg extra_cfg = ctx->vp8_cfg;
-  extra_cfg.arnr_strength = CAST(VP8E_SET_ARNR_STRENGTH, args);
-  return update_extracfg(ctx, &extra_cfg);
-}
-
-static vpx_codec_err_t set_arnr_type(vpx_codec_alg_priv_t *ctx, va_list args)
-{
-  struct vp8_extracfg extra_cfg = ctx->vp8_cfg;
-  extra_cfg.arnr_type = CAST(VP8E_SET_ARNR_TYPE, args);
-  return update_extracfg(ctx, &extra_cfg);
-}
-
-static vpx_codec_err_t set_tuning(vpx_codec_alg_priv_t *ctx, va_list args)
-{
-  struct vp8_extracfg extra_cfg = ctx->vp8_cfg;
-  extra_cfg.tuning = CAST(VP8E_SET_TUNING, args);
-  return update_extracfg(ctx, &extra_cfg);
-}
-
-static vpx_codec_err_t set_cq_level(vpx_codec_alg_priv_t *ctx, va_list args)
-{
-  struct vp8_extracfg extra_cfg = ctx->vp8_cfg;
-  extra_cfg.cq_level = CAST(VP8E_SET_CQ_LEVEL, args);
-  return update_extracfg(ctx, &extra_cfg);
-}
-
-static vpx_codec_err_t set_rc_max_intra_bitrate_pct(vpx_codec_alg_priv_t *ctx,
-                                                    va_list args)
-{
-  struct vp8_extracfg extra_cfg = ctx->vp8_cfg;
-  extra_cfg.rc_max_intra_bitrate_pct =
-      CAST(VP8E_SET_MAX_INTRA_BITRATE_PCT, args);
-  return update_extracfg(ctx, &extra_cfg);
-}
-
-static vpx_codec_err_t set_screen_content_mode(vpx_codec_alg_priv_t *ctx,
-                                               va_list args)
-{
-  struct vp8_extracfg extra_cfg = ctx->vp8_cfg;
-  extra_cfg.screen_content_mode =
-      CAST(VP8E_SET_SCREEN_CONTENT_MODE, args);
-  return update_extracfg(ctx, &extra_cfg);
-}
-
-static vpx_codec_err_t vp8e_mr_alloc_mem(const vpx_codec_enc_cfg_t *cfg,
-                                        void **mem_loc)
-{
-    vpx_codec_err_t res = 0;
-
-#if CONFIG_MULTI_RES_ENCODING
-    LOWER_RES_FRAME_INFO *shared_mem_loc;
-    int mb_rows = ((cfg->g_w + 15) >>4);
-    int mb_cols = ((cfg->g_h + 15) >>4);
-
-    shared_mem_loc = calloc(1, sizeof(LOWER_RES_FRAME_INFO));
-    if(!shared_mem_loc)
-    {
-        res = VPX_CODEC_MEM_ERROR;
-    }
-
-    shared_mem_loc->mb_info = calloc(mb_rows*mb_cols, sizeof(LOWER_RES_MB_INFO));
-    if(!(shared_mem_loc->mb_info))
-    {
-        res = VPX_CODEC_MEM_ERROR;
-    }
-    else
-    {
-        *mem_loc = (void *)shared_mem_loc;
-        res = VPX_CODEC_OK;
-    }
-#else
-    (void)cfg;
-    (void)mem_loc;
-#endif
-    return res;
-}
-
-static vpx_codec_err_t vp8e_init(vpx_codec_ctx_t *ctx,
-                                 vpx_codec_priv_enc_mr_cfg_t *mr_cfg)
-{
-    vpx_codec_err_t        res = VPX_CODEC_OK;
-
-
-    vp8_rtcd();
-    vpx_dsp_rtcd();
-    vpx_scale_rtcd();
-
-    if (!ctx->priv)
-    {
-        struct vpx_codec_alg_priv *priv =
-            (struct vpx_codec_alg_priv *)vpx_calloc(1, sizeof(*priv));
-
-        if (!priv)
-        {
-            return VPX_CODEC_MEM_ERROR;
-        }
-
-        ctx->priv = (vpx_codec_priv_t *)priv;
-        ctx->priv->init_flags = ctx->init_flags;
-
-        if (ctx->config.enc)
-        {
-            /* Update the reference to the config structure to an
-             * internal copy.
-             */
-            priv->cfg = *ctx->config.enc;
-            ctx->config.enc = &priv->cfg;
-        }
-
-        priv->vp8_cfg = default_extracfg;
-        priv->vp8_cfg.pkt_list = &priv->pkt_list.head;
-
-        priv->cx_data_sz = priv->cfg.g_w * priv->cfg.g_h * 3 / 2 * 2;
-
-        if (priv->cx_data_sz < 32768) priv->cx_data_sz = 32768;
-
-        priv->cx_data = malloc(priv->cx_data_sz);
-
-        if (!priv->cx_data)
-        {
-            return VPX_CODEC_MEM_ERROR;
-        }
-
-        if(mr_cfg)
-            ctx->priv->enc.total_encoders   = mr_cfg->mr_total_resolutions;
-        else
-            ctx->priv->enc.total_encoders   = 1;
-
-        once(vp8_initialize_enc);
-
-        res = validate_config(priv, &priv->cfg, &priv->vp8_cfg, 0);
-
-        if (!res)
-        {
-            set_vp8e_config(&priv->oxcf, priv->cfg, priv->vp8_cfg, mr_cfg);
-            priv->cpi = vp8_create_compressor(&priv->oxcf);
-            if (!priv->cpi)
-                res = VPX_CODEC_MEM_ERROR;
-        }
-    }
-
-    return res;
-}
-
-static vpx_codec_err_t vp8e_destroy(vpx_codec_alg_priv_t *ctx)
-{
-#if CONFIG_MULTI_RES_ENCODING
-    /* Free multi-encoder shared memory */
-    if (ctx->oxcf.mr_total_resolutions > 0 && (ctx->oxcf.mr_encoder_id == ctx->oxcf.mr_total_resolutions-1))
-    {
-        LOWER_RES_FRAME_INFO *shared_mem_loc = (LOWER_RES_FRAME_INFO *)ctx->oxcf.mr_low_res_mode_info;
-        free(shared_mem_loc->mb_info);
-        free(ctx->oxcf.mr_low_res_mode_info);
-    }
-#endif
-
-    free(ctx->cx_data);
-    vp8_remove_compressor(&ctx->cpi);
-    vpx_free(ctx);
-    return VPX_CODEC_OK;
-}
-
-static vpx_codec_err_t image2yuvconfig(const vpx_image_t   *img,
-                                       YV12_BUFFER_CONFIG  *yv12)
-{
-    const int y_w = img->d_w;
-    const int y_h = img->d_h;
-    const int uv_w = (img->d_w + 1) / 2;
-    const int uv_h = (img->d_h + 1) / 2;
-    vpx_codec_err_t        res = VPX_CODEC_OK;
-    yv12->y_buffer = img->planes[VPX_PLANE_Y];
-    yv12->u_buffer = img->planes[VPX_PLANE_U];
-    yv12->v_buffer = img->planes[VPX_PLANE_V];
-
-    yv12->y_crop_width  = y_w;
-    yv12->y_crop_height = y_h;
-    yv12->y_width  = y_w;
-    yv12->y_height = y_h;
-    yv12->uv_crop_width = uv_w;
-    yv12->uv_crop_height = uv_h;
-    yv12->uv_width = uv_w;
-    yv12->uv_height = uv_h;
-
-    yv12->y_stride = img->stride[VPX_PLANE_Y];
-    yv12->uv_stride = img->stride[VPX_PLANE_U];
-
-    yv12->border  = (img->stride[VPX_PLANE_Y] - img->w) / 2;
-    return res;
-}
-
-static void pick_quickcompress_mode(vpx_codec_alg_priv_t  *ctx,
-                                    unsigned long          duration,
-                                    unsigned long          deadline)
-{
-    int new_qc;
-
-#if !(CONFIG_REALTIME_ONLY)
-    /* Use best quality mode if no deadline is given. */
-    new_qc = MODE_BESTQUALITY;
-
-    if (deadline)
-    {
-        uint64_t     duration_us;
-
-        /* Convert duration parameter from stream timebase to microseconds */
-        duration_us = (uint64_t)duration * 1000000
-                      * (uint64_t)ctx->cfg.g_timebase.num
-                      / (uint64_t)ctx->cfg.g_timebase.den;
-
-        /* If the deadline is more that the duration this frame is to be shown,
-         * use good quality mode. Otherwise use realtime mode.
-         */
-        new_qc = (deadline > duration_us) ? MODE_GOODQUALITY : MODE_REALTIME;
-    }
-
-#else
-    new_qc = MODE_REALTIME;
-#endif
-
-    if (deadline == VPX_DL_REALTIME)
-        new_qc = MODE_REALTIME;
-    else if (ctx->cfg.g_pass == VPX_RC_FIRST_PASS)
-        new_qc = MODE_FIRSTPASS;
-    else if (ctx->cfg.g_pass == VPX_RC_LAST_PASS)
-        new_qc = (new_qc == MODE_BESTQUALITY)
-                 ? MODE_SECONDPASS_BEST
-                 : MODE_SECONDPASS;
-
-    if (ctx->oxcf.Mode != new_qc)
-    {
-        ctx->oxcf.Mode = new_qc;
-        vp8_change_config(ctx->cpi, &ctx->oxcf);
-    }
-}
-
-static vpx_codec_err_t set_reference_and_update(vpx_codec_alg_priv_t *ctx,
-                                                int flags)
-{
-
-    /* Handle Flags */
-    if (((flags & VP8_EFLAG_NO_UPD_GF) && (flags & VP8_EFLAG_FORCE_GF))
-        || ((flags & VP8_EFLAG_NO_UPD_ARF) && (flags & VP8_EFLAG_FORCE_ARF)))
-    {
-        ctx->base.err_detail = "Conflicting flags.";
-        return VPX_CODEC_INVALID_PARAM;
-    }
-
-    if (flags & (VP8_EFLAG_NO_REF_LAST | VP8_EFLAG_NO_REF_GF
-                 | VP8_EFLAG_NO_REF_ARF))
-    {
-        int ref = 7;
-
-        if (flags & VP8_EFLAG_NO_REF_LAST)
-            ref ^= VP8_LAST_FRAME;
-
-        if (flags & VP8_EFLAG_NO_REF_GF)
-            ref ^= VP8_GOLD_FRAME;
-
-        if (flags & VP8_EFLAG_NO_REF_ARF)
-            ref ^= VP8_ALTR_FRAME;
-
-        vp8_use_as_reference(ctx->cpi, ref);
-    }
-
-    if (flags & (VP8_EFLAG_NO_UPD_LAST | VP8_EFLAG_NO_UPD_GF
-                 | VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_FORCE_GF
-                 | VP8_EFLAG_FORCE_ARF))
-    {
-        int upd = 7;
-
-        if (flags & VP8_EFLAG_NO_UPD_LAST)
-            upd ^= VP8_LAST_FRAME;
-
-        if (flags & VP8_EFLAG_NO_UPD_GF)
-            upd ^= VP8_GOLD_FRAME;
-
-        if (flags & VP8_EFLAG_NO_UPD_ARF)
-            upd ^= VP8_ALTR_FRAME;
-
-        vp8_update_reference(ctx->cpi, upd);
-    }
-
-    if (flags & VP8_EFLAG_NO_UPD_ENTROPY)
-    {
-        vp8_update_entropy(ctx->cpi, 0);
-    }
-
-    return VPX_CODEC_OK;
-}
-
-static vpx_codec_err_t vp8e_encode(vpx_codec_alg_priv_t  *ctx,
-                                   const vpx_image_t     *img,
-                                   vpx_codec_pts_t        pts,
-                                   unsigned long          duration,
-                                   vpx_enc_frame_flags_t  flags,
-                                   unsigned long          deadline)
-{
-    vpx_codec_err_t res = VPX_CODEC_OK;
-
-    if (!ctx->cfg.rc_target_bitrate)
-        return res;
-
-    if (img)
-        res = validate_img(ctx, img);
-
-    if (!res)
-        res = validate_config(ctx, &ctx->cfg, &ctx->vp8_cfg, 1);
-
-    pick_quickcompress_mode(ctx, duration, deadline);
-    vpx_codec_pkt_list_init(&ctx->pkt_list);
-
-    // If no flags are set in the encode call, then use the frame flags as
-    // defined via the control function: vp8e_set_frame_flags.
-    if (!flags) {
-        flags = ctx->control_frame_flags;
-    }
-    ctx->control_frame_flags = 0;
-
-    if (!res)
-        res = set_reference_and_update(ctx, flags);
-
-    /* Handle fixed keyframe intervals */
-    if (ctx->cfg.kf_mode == VPX_KF_AUTO
-        && ctx->cfg.kf_min_dist == ctx->cfg.kf_max_dist)
-    {
-        if (++ctx->fixed_kf_cntr > ctx->cfg.kf_min_dist)
-        {
-            flags |= VPX_EFLAG_FORCE_KF;
-            ctx->fixed_kf_cntr = 1;
-        }
-    }
-
-    /* Initialize the encoder instance on the first frame*/
-    if (!res && ctx->cpi)
-    {
-        unsigned int lib_flags;
-        YV12_BUFFER_CONFIG sd;
-        int64_t dst_time_stamp, dst_end_time_stamp;
-        unsigned long size, cx_data_sz;
-        unsigned char *cx_data;
-        unsigned char *cx_data_end;
-        int comp_data_state = 0;
-
-        /* Set up internal flags */
-        if (ctx->base.init_flags & VPX_CODEC_USE_PSNR)
-            ((VP8_COMP *)ctx->cpi)->b_calculate_psnr = 1;
-
-        if (ctx->base.init_flags & VPX_CODEC_USE_OUTPUT_PARTITION)
-            ((VP8_COMP *)ctx->cpi)->output_partition = 1;
-
-        /* Convert API flags to internal codec lib flags */
-        lib_flags = (flags & VPX_EFLAG_FORCE_KF) ? FRAMEFLAGS_KEY : 0;
-
-        /* vp8 use 10,000,000 ticks/second as time stamp */
-        dst_time_stamp    = pts * 10000000 * ctx->cfg.g_timebase.num / ctx->cfg.g_timebase.den;
-        dst_end_time_stamp = (pts + duration) * 10000000 * ctx->cfg.g_timebase.num / ctx->cfg.g_timebase.den;
-
-        if (img != NULL)
-        {
-            res = image2yuvconfig(img, &sd);
-
-            if (vp8_receive_raw_frame(ctx->cpi, ctx->next_frame_flag | lib_flags,
-                                      &sd, dst_time_stamp, dst_end_time_stamp))
-            {
-                VP8_COMP *cpi = (VP8_COMP *)ctx->cpi;
-                res = update_error_state(ctx, &cpi->common.error);
-            }
-
-            /* reset for next frame */
-            ctx->next_frame_flag = 0;
-        }
-
-        cx_data = ctx->cx_data;
-        cx_data_sz = ctx->cx_data_sz;
-        cx_data_end = ctx->cx_data + cx_data_sz;
-        lib_flags = 0;
-
-        while (cx_data_sz >= ctx->cx_data_sz / 2)
-        {
-            comp_data_state = vp8_get_compressed_data(ctx->cpi,
-                                                  &lib_flags,
-                                                  &size,
-                                                  cx_data,
-                                                  cx_data_end,
-                                                  &dst_time_stamp,
-                                                  &dst_end_time_stamp,
-                                                  !img);
-
-            if(comp_data_state == VPX_CODEC_CORRUPT_FRAME)
-                return VPX_CODEC_CORRUPT_FRAME;
-            else if(comp_data_state == -1)
-                break;
-
-            if (size)
-            {
-                vpx_codec_pts_t    round, delta;
-                vpx_codec_cx_pkt_t pkt;
-                VP8_COMP *cpi = (VP8_COMP *)ctx->cpi;
-
-                /* Add the frame packet to the list of returned packets. */
-                round = (vpx_codec_pts_t)10000000
-                        * ctx->cfg.g_timebase.num / 2 - 1;
-                delta = (dst_end_time_stamp - dst_time_stamp);
-                pkt.kind = VPX_CODEC_CX_FRAME_PKT;
-                pkt.data.frame.pts =
-                    (dst_time_stamp * ctx->cfg.g_timebase.den + round)
-                    / ctx->cfg.g_timebase.num / 10000000;
-                pkt.data.frame.duration = (unsigned long)
-                    ((delta * ctx->cfg.g_timebase.den + round)
-                    / ctx->cfg.g_timebase.num / 10000000);
-                pkt.data.frame.flags = lib_flags << 16;
-
-                if (lib_flags & FRAMEFLAGS_KEY)
-                    pkt.data.frame.flags |= VPX_FRAME_IS_KEY;
-
-                if (!cpi->common.show_frame)
-                {
-                    pkt.data.frame.flags |= VPX_FRAME_IS_INVISIBLE;
-
-                    /* This timestamp should be as close as possible to the
-                     * prior PTS so that if a decoder uses pts to schedule when
-                     * to do this, we start right after last frame was decoded.
-                     * Invisible frames have no duration.
-                     */
-                    pkt.data.frame.pts = ((cpi->last_time_stamp_seen
-                        * ctx->cfg.g_timebase.den + round)
-                        / ctx->cfg.g_timebase.num / 10000000) + 1;
-                    pkt.data.frame.duration = 0;
-                }
-
-                if (cpi->droppable)
-                    pkt.data.frame.flags |= VPX_FRAME_IS_DROPPABLE;
-
-                if (cpi->output_partition)
-                {
-                    int i;
-                    const int num_partitions =
-                            (1 << cpi->common.multi_token_partition) + 1;
-
-                    pkt.data.frame.flags |= VPX_FRAME_IS_FRAGMENT;
-
-                    for (i = 0; i < num_partitions; ++i)
-                    {
-#if CONFIG_REALTIME_ONLY & CONFIG_ONTHEFLY_BITPACKING
-                        pkt.data.frame.buf = cpi->partition_d[i];
-#else
-                        pkt.data.frame.buf = cx_data;
-                        cx_data += cpi->partition_sz[i];
-                        cx_data_sz -= cpi->partition_sz[i];
-#endif
-                        pkt.data.frame.sz = cpi->partition_sz[i];
-                        pkt.data.frame.partition_id = i;
-                        /* don't set the fragment bit for the last partition */
-                        if (i == (num_partitions - 1))
-                            pkt.data.frame.flags &= ~VPX_FRAME_IS_FRAGMENT;
-                        vpx_codec_pkt_list_add(&ctx->pkt_list.head, &pkt);
-                    }
-#if CONFIG_REALTIME_ONLY & CONFIG_ONTHEFLY_BITPACKING
-                    /* In lagged mode the encoder can buffer multiple frames.
-                     * We don't want this in partitioned output because
-                     * partitions are spread all over the output buffer.
-                     * So, force an exit!
-                     */
-                    cx_data_sz -= ctx->cx_data_sz / 2;
-#endif
-                }
-                else
-                {
-                    pkt.data.frame.buf = cx_data;
-                    pkt.data.frame.sz  = size;
-                    pkt.data.frame.partition_id = -1;
-                    vpx_codec_pkt_list_add(&ctx->pkt_list.head, &pkt);
-                    cx_data += size;
-                    cx_data_sz -= size;
-                }
-            }
-        }
-    }
-
-    return res;
-}
-
-
-static const vpx_codec_cx_pkt_t *vp8e_get_cxdata(vpx_codec_alg_priv_t  *ctx,
-        vpx_codec_iter_t      *iter)
-{
-    return vpx_codec_pkt_list_get(&ctx->pkt_list.head, iter);
-}
-
-static vpx_codec_err_t vp8e_set_reference(vpx_codec_alg_priv_t *ctx,
-                                          va_list args)
-{
-    vpx_ref_frame_t *data = va_arg(args, vpx_ref_frame_t *);
-
-    if (data)
-    {
-        vpx_ref_frame_t *frame = (vpx_ref_frame_t *)data;
-        YV12_BUFFER_CONFIG sd;
-
-        image2yuvconfig(&frame->img, &sd);
-        vp8_set_reference(ctx->cpi, frame->frame_type, &sd);
-        return VPX_CODEC_OK;
-    }
-    else
-        return VPX_CODEC_INVALID_PARAM;
-
-}
-
-static vpx_codec_err_t vp8e_get_reference(vpx_codec_alg_priv_t *ctx,
-                                          va_list args)
-{
-
-    vpx_ref_frame_t *data = va_arg(args, vpx_ref_frame_t *);
-
-    if (data)
-    {
-        vpx_ref_frame_t *frame = (vpx_ref_frame_t *)data;
-        YV12_BUFFER_CONFIG sd;
-
-        image2yuvconfig(&frame->img, &sd);
-        vp8_get_reference(ctx->cpi, frame->frame_type, &sd);
-        return VPX_CODEC_OK;
-    }
-    else
-        return VPX_CODEC_INVALID_PARAM;
-}
-
-static vpx_codec_err_t vp8e_set_previewpp(vpx_codec_alg_priv_t *ctx,
-                                          va_list args)
-{
-#if CONFIG_POSTPROC
-    vp8_postproc_cfg_t *data = va_arg(args, vp8_postproc_cfg_t *);
-
-    if (data)
-    {
-        ctx->preview_ppcfg = *((vp8_postproc_cfg_t *)data);
-        return VPX_CODEC_OK;
-    }
-    else
-        return VPX_CODEC_INVALID_PARAM;
-#else
-    (void)ctx;
-    (void)args;
-    return VPX_CODEC_INCAPABLE;
-#endif
-}
-
-
-static vpx_image_t *vp8e_get_preview(vpx_codec_alg_priv_t *ctx)
-{
-
-    YV12_BUFFER_CONFIG sd;
-    vp8_ppflags_t flags;
-    vp8_zero(flags);
-
-    if (ctx->preview_ppcfg.post_proc_flag)
-    {
-        flags.post_proc_flag        = ctx->preview_ppcfg.post_proc_flag;
-        flags.deblocking_level      = ctx->preview_ppcfg.deblocking_level;
-        flags.noise_level           = ctx->preview_ppcfg.noise_level;
-    }
-
-    if (0 == vp8_get_preview_raw_frame(ctx->cpi, &sd, &flags))
-    {
-
-        /*
-        vpx_img_wrap(&ctx->preview_img, VPX_IMG_FMT_YV12,
-            sd.y_width + 2*VP8BORDERINPIXELS,
-            sd.y_height + 2*VP8BORDERINPIXELS,
-            1,
-            sd.buffer_alloc);
-        vpx_img_set_rect(&ctx->preview_img,
-            VP8BORDERINPIXELS, VP8BORDERINPIXELS,
-            sd.y_width, sd.y_height);
-            */
-
-        ctx->preview_img.bps = 12;
-        ctx->preview_img.planes[VPX_PLANE_Y] = sd.y_buffer;
-        ctx->preview_img.planes[VPX_PLANE_U] = sd.u_buffer;
-        ctx->preview_img.planes[VPX_PLANE_V] = sd.v_buffer;
-
-        ctx->preview_img.fmt = VPX_IMG_FMT_I420;
-        ctx->preview_img.x_chroma_shift = 1;
-        ctx->preview_img.y_chroma_shift = 1;
-
-        ctx->preview_img.d_w = sd.y_width;
-        ctx->preview_img.d_h = sd.y_height;
-        ctx->preview_img.stride[VPX_PLANE_Y] = sd.y_stride;
-        ctx->preview_img.stride[VPX_PLANE_U] = sd.uv_stride;
-        ctx->preview_img.stride[VPX_PLANE_V] = sd.uv_stride;
-        ctx->preview_img.w   = sd.y_width;
-        ctx->preview_img.h   = sd.y_height;
-
-        return &ctx->preview_img;
-    }
-    else
-        return NULL;
-}
-
-static vpx_codec_err_t vp8e_set_frame_flags(vpx_codec_alg_priv_t *ctx,
-                                            va_list args)
-{
-    int frame_flags = va_arg(args, int);
-    ctx->control_frame_flags = frame_flags;
-    return set_reference_and_update(ctx, frame_flags);
-}
-
-static vpx_codec_err_t vp8e_set_temporal_layer_id(vpx_codec_alg_priv_t *ctx,
-                                                  va_list args)
-{
-    int layer_id = va_arg(args, int);
-    if (layer_id < 0 || layer_id >= (int)ctx->cfg.ts_number_layers) {
-      return VPX_CODEC_INVALID_PARAM;
-    }
-    ctx->cpi->temporal_layer_id = layer_id;
-    return VPX_CODEC_OK;
-}
-
-static vpx_codec_err_t vp8e_set_roi_map(vpx_codec_alg_priv_t *ctx,
-                                        va_list args)
-{
-    vpx_roi_map_t *data = va_arg(args, vpx_roi_map_t *);
-
-    if (data)
-    {
-        vpx_roi_map_t *roi = (vpx_roi_map_t *)data;
-
-        if (!vp8_set_roimap(ctx->cpi, roi->roi_map, roi->rows, roi->cols, roi->delta_q, roi->delta_lf, roi->static_threshold))
-            return VPX_CODEC_OK;
-        else
-            return VPX_CODEC_INVALID_PARAM;
-    }
-    else
-        return VPX_CODEC_INVALID_PARAM;
-}
-
-
-static vpx_codec_err_t vp8e_set_activemap(vpx_codec_alg_priv_t *ctx,
-                                          va_list args)
-{
-    vpx_active_map_t *data = va_arg(args, vpx_active_map_t *);
-
-    if (data)
-    {
-
-        vpx_active_map_t *map = (vpx_active_map_t *)data;
-
-        if (!vp8_set_active_map(ctx->cpi, map->active_map, map->rows, map->cols))
-            return VPX_CODEC_OK;
-        else
-            return VPX_CODEC_INVALID_PARAM;
-    }
-    else
-        return VPX_CODEC_INVALID_PARAM;
-}
-
-static vpx_codec_err_t vp8e_set_scalemode(vpx_codec_alg_priv_t *ctx,
-                                          va_list args)
-{
-
-    vpx_scaling_mode_t *data =  va_arg(args, vpx_scaling_mode_t *);
-
-    if (data)
-    {
-        int res;
-        vpx_scaling_mode_t scalemode = *(vpx_scaling_mode_t *)data ;
-        res = vp8_set_internal_size(ctx->cpi,
-                                    (VPX_SCALING)scalemode.h_scaling_mode,
-                                    (VPX_SCALING)scalemode.v_scaling_mode);
-
-        if (!res)
-        {
-            /*force next frame a key frame to effect scaling mode */
-            ctx->next_frame_flag |= FRAMEFLAGS_KEY;
-            return VPX_CODEC_OK;
-        }
-        else
-            return VPX_CODEC_INVALID_PARAM;
-    }
-    else
-        return VPX_CODEC_INVALID_PARAM;
-}
-
-
-static vpx_codec_ctrl_fn_map_t vp8e_ctf_maps[] =
-{
-    {VP8_SET_REFERENCE,                 vp8e_set_reference},
-    {VP8_COPY_REFERENCE,                vp8e_get_reference},
-    {VP8_SET_POSTPROC,                  vp8e_set_previewpp},
-    {VP8E_SET_FRAME_FLAGS,              vp8e_set_frame_flags},
-    {VP8E_SET_TEMPORAL_LAYER_ID,        vp8e_set_temporal_layer_id},
-    {VP8E_SET_ROI_MAP,                  vp8e_set_roi_map},
-    {VP8E_SET_ACTIVEMAP,                vp8e_set_activemap},
-    {VP8E_SET_SCALEMODE,                vp8e_set_scalemode},
-    {VP8E_SET_CPUUSED,                  set_cpu_used},
-    {VP8E_SET_NOISE_SENSITIVITY,        set_noise_sensitivity},
-    {VP8E_SET_ENABLEAUTOALTREF,         set_enable_auto_alt_ref},
-    {VP8E_SET_SHARPNESS,                set_sharpness},
-    {VP8E_SET_STATIC_THRESHOLD,         set_static_thresh},
-    {VP8E_SET_TOKEN_PARTITIONS,         set_token_partitions},
-    {VP8E_GET_LAST_QUANTIZER,           get_quantizer},
-    {VP8E_GET_LAST_QUANTIZER_64,        get_quantizer64},
-    {VP8E_SET_ARNR_MAXFRAMES,           set_arnr_max_frames},
-    {VP8E_SET_ARNR_STRENGTH ,           set_arnr_strength},
-    {VP8E_SET_ARNR_TYPE     ,           set_arnr_type},
-    {VP8E_SET_TUNING,                   set_tuning},
-    {VP8E_SET_CQ_LEVEL,                 set_cq_level},
-    {VP8E_SET_MAX_INTRA_BITRATE_PCT,    set_rc_max_intra_bitrate_pct},
-    {VP8E_SET_SCREEN_CONTENT_MODE,      set_screen_content_mode},
-    { -1, NULL},
-};
-
-static vpx_codec_enc_cfg_map_t vp8e_usage_cfg_map[] =
-{
-    {
-    0,
-    {
-        0,                  /* g_usage */
-        0,                  /* g_threads */
-        0,                  /* g_profile */
-
-        320,                /* g_width */
-        240,                /* g_height */
-        VPX_BITS_8,         /* g_bit_depth */
-        8,                  /* g_input_bit_depth */
-
-        {1, 30},            /* g_timebase */
-
-        0,                  /* g_error_resilient */
-
-        VPX_RC_ONE_PASS,    /* g_pass */
-
-        0,                  /* g_lag_in_frames */
-
-        0,                  /* rc_dropframe_thresh */
-        0,                  /* rc_resize_allowed */
-        1,                  /* rc_scaled_width */
-        1,                  /* rc_scaled_height */
-        60,                 /* rc_resize_down_thresold */
-        30,                 /* rc_resize_up_thresold */
-
-        VPX_VBR,            /* rc_end_usage */
-        {NULL, 0},          /* rc_twopass_stats_in */
-        {NULL, 0},          /* rc_firstpass_mb_stats_in */
-        256,                /* rc_target_bandwidth */
-        4,                  /* rc_min_quantizer */
-        63,                 /* rc_max_quantizer */
-        100,                /* rc_undershoot_pct */
-        100,                /* rc_overshoot_pct */
-
-        6000,               /* rc_max_buffer_size */
-        4000,               /* rc_buffer_initial_size; */
-        5000,               /* rc_buffer_optimal_size; */
-
-        50,                 /* rc_two_pass_vbrbias  */
-        0,                  /* rc_two_pass_vbrmin_section */
-        400,                /* rc_two_pass_vbrmax_section */
-
-        /* keyframing settings (kf) */
-        VPX_KF_AUTO,        /* g_kfmode*/
-        0,                  /* kf_min_dist */
-        128,                /* kf_max_dist */
-
-        VPX_SS_DEFAULT_LAYERS, /* ss_number_layers */
-        {0},
-        {0},                /* ss_target_bitrate */
-        1,                  /* ts_number_layers */
-        {0},                /* ts_target_bitrate */
-        {0},                /* ts_rate_decimator */
-        0,                  /* ts_periodicity */
-        {0},                /* ts_layer_id */
-        {0},                /* layer_target_bitrate */
-        0                   /* temporal_layering_mode */
-    }},
-};
-
-
-#ifndef VERSION_STRING
-#define VERSION_STRING
-#endif
-CODEC_INTERFACE(vpx_codec_vp8_cx) =
-{
-    "WebM Project VP8 Encoder" VERSION_STRING,
-    VPX_CODEC_INTERNAL_ABI_VERSION,
-    VPX_CODEC_CAP_ENCODER | VPX_CODEC_CAP_PSNR |
-    VPX_CODEC_CAP_OUTPUT_PARTITION,
-    /* vpx_codec_caps_t          caps; */
-    vp8e_init,          /* vpx_codec_init_fn_t       init; */
-    vp8e_destroy,       /* vpx_codec_destroy_fn_t    destroy; */
-    vp8e_ctf_maps,      /* vpx_codec_ctrl_fn_map_t  *ctrl_maps; */
-    {
-        NULL,    /* vpx_codec_peek_si_fn_t    peek_si; */
-        NULL,    /* vpx_codec_get_si_fn_t     get_si; */
-        NULL,    /* vpx_codec_decode_fn_t     decode; */
-        NULL,    /* vpx_codec_frame_get_fn_t  frame_get; */
-        NULL,    /* vpx_codec_set_fb_fn_t     set_fb_fn; */
-    },
-    {
-        1,                  /* 1 cfg map */
-        vp8e_usage_cfg_map, /* vpx_codec_enc_cfg_map_t    cfg_maps; */
-        vp8e_encode,        /* vpx_codec_encode_fn_t      encode; */
-        vp8e_get_cxdata,    /* vpx_codec_get_cx_data_fn_t   get_cx_data; */
-        vp8e_set_config,
-        NULL,
-        vp8e_get_preview,
-        vp8e_mr_alloc_mem,
-    } /* encoder functions */
-};
diff --git a/vp8/vp8_dx_iface.c b/vp8/vp8_dx_iface.c
deleted file mode 100644 (file)
index fc9288d..0000000
+++ /dev/null
@@ -1,828 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#include <assert.h>
-#include <stdlib.h>
-#include <string.h>
-#include "./vp8_rtcd.h"
-#include "./vpx_dsp_rtcd.h"
-#include "./vpx_scale_rtcd.h"
-#include "vpx/vpx_decoder.h"
-#include "vpx/vp8dx.h"
-#include "vpx/internal/vpx_codec_internal.h"
-#include "vpx_version.h"
-#include "common/alloccommon.h"
-#include "common/common.h"
-#include "common/onyxd.h"
-#include "decoder/onyxd_int.h"
-#include "vpx_dsp/vpx_dsp_common.h"
-#include "vpx_mem/vpx_mem.h"
-#if CONFIG_ERROR_CONCEALMENT
-#include "decoder/error_concealment.h"
-#endif
-#include "decoder/decoderthreading.h"
-
-#define VP8_CAP_POSTPROC (CONFIG_POSTPROC ? VPX_CODEC_CAP_POSTPROC : 0)
-#define VP8_CAP_ERROR_CONCEALMENT (CONFIG_ERROR_CONCEALMENT ? \
-                                    VPX_CODEC_CAP_ERROR_CONCEALMENT : 0)
-
-typedef vpx_codec_stream_info_t  vp8_stream_info_t;
-
-/* Structures for handling memory allocations */
-typedef enum
-{
-    VP8_SEG_ALG_PRIV     = 256,
-    VP8_SEG_MAX
-} mem_seg_id_t;
-#define NELEMENTS(x) ((int)(sizeof(x)/sizeof(x[0])))
-
-struct vpx_codec_alg_priv
-{
-    vpx_codec_priv_t        base;
-    vpx_codec_dec_cfg_t     cfg;
-    vp8_stream_info_t       si;
-    int                     decoder_init;
-    int                     postproc_cfg_set;
-    vp8_postproc_cfg_t      postproc_cfg;
-#if CONFIG_POSTPROC_VISUALIZER
-    unsigned int            dbg_postproc_flag;
-    int                     dbg_color_ref_frame_flag;
-    int                     dbg_color_mb_modes_flag;
-    int                     dbg_color_b_modes_flag;
-    int                     dbg_display_mv_flag;
-#endif
-    vpx_decrypt_cb          decrypt_cb;
-    void                    *decrypt_state;
-    vpx_image_t             img;
-    int                     img_setup;
-    struct frame_buffers    yv12_frame_buffers;
-    void                    *user_priv;
-    FRAGMENT_DATA           fragments;
-};
-
-static int vp8_init_ctx(vpx_codec_ctx_t *ctx)
-{
-    vpx_codec_alg_priv_t *priv =
-        (vpx_codec_alg_priv_t *)vpx_calloc(1, sizeof(*priv));
-    if (!priv) return 1;
-
-    ctx->priv = (vpx_codec_priv_t *)priv;
-    ctx->priv->init_flags = ctx->init_flags;
-
-    priv->si.sz = sizeof(priv->si);
-    priv->decrypt_cb = NULL;
-    priv->decrypt_state = NULL;
-
-    if (ctx->config.dec)
-    {
-        /* Update the reference to the config structure to an internal copy. */
-        priv->cfg = *ctx->config.dec;
-        ctx->config.dec = &priv->cfg;
-    }
-
-    return 0;
-}
-
-static vpx_codec_err_t vp8_init(vpx_codec_ctx_t *ctx,
-                                vpx_codec_priv_enc_mr_cfg_t *data)
-{
-    vpx_codec_err_t res = VPX_CODEC_OK;
-    vpx_codec_alg_priv_t *priv = NULL;
-    (void) data;
-
-    vp8_rtcd();
-    vpx_dsp_rtcd();
-    vpx_scale_rtcd();
-
-    /* This function only allocates space for the vpx_codec_alg_priv_t
-     * structure. More memory may be required at the time the stream
-     * information becomes known.
-     */
-    if (!ctx->priv) {
-      if (vp8_init_ctx(ctx)) return VPX_CODEC_MEM_ERROR;
-      priv = (vpx_codec_alg_priv_t *)ctx->priv;
-
-      /* initialize number of fragments to zero */
-      priv->fragments.count = 0;
-      /* is input fragments enabled? */
-      priv->fragments.enabled =
-          (priv->base.init_flags & VPX_CODEC_USE_INPUT_FRAGMENTS);
-
-      /*post processing level initialized to do nothing */
-    } else {
-      priv = (vpx_codec_alg_priv_t *)ctx->priv;
-    }
-
-    priv->yv12_frame_buffers.use_frame_threads =
-        (ctx->priv->init_flags & VPX_CODEC_USE_FRAME_THREADING);
-
-    /* for now, disable frame threading */
-    priv->yv12_frame_buffers.use_frame_threads = 0;
-
-    if (priv->yv12_frame_buffers.use_frame_threads &&
-        ((ctx->priv->init_flags & VPX_CODEC_USE_ERROR_CONCEALMENT) ||
-         (ctx->priv->init_flags & VPX_CODEC_USE_INPUT_FRAGMENTS))) {
-      /* row-based threading, error concealment, and input fragments will
-       * not be supported when using frame-based threading */
-      res = VPX_CODEC_INVALID_PARAM;
-    }
-
-    return res;
-}
-
-static vpx_codec_err_t vp8_destroy(vpx_codec_alg_priv_t *ctx)
-{
-    vp8_remove_decoder_instances(&ctx->yv12_frame_buffers);
-
-    vpx_free(ctx);
-
-    return VPX_CODEC_OK;
-}
-
-static vpx_codec_err_t vp8_peek_si_internal(const uint8_t *data,
-                                            unsigned int data_sz,
-                                            vpx_codec_stream_info_t *si,
-                                            vpx_decrypt_cb decrypt_cb,
-                                            void *decrypt_state)
-{
-    vpx_codec_err_t res = VPX_CODEC_OK;
-
-    assert(data != NULL);
-
-    if(data + data_sz <= data)
-    {
-        res = VPX_CODEC_INVALID_PARAM;
-    }
-    else
-    {
-        /* Parse uncompresssed part of key frame header.
-         * 3 bytes:- including version, frame type and an offset
-         * 3 bytes:- sync code (0x9d, 0x01, 0x2a)
-         * 4 bytes:- including image width and height in the lowest 14 bits
-         *           of each 2-byte value.
-         */
-        uint8_t clear_buffer[10];
-        const uint8_t *clear = data;
-        if (decrypt_cb)
-        {
-            int n = VPXMIN(sizeof(clear_buffer), data_sz);
-            decrypt_cb(decrypt_state, data, clear_buffer, n);
-            clear = clear_buffer;
-        }
-        si->is_kf = 0;
-
-        if (data_sz >= 10 && !(clear[0] & 0x01))  /* I-Frame */
-        {
-            si->is_kf = 1;
-
-            /* vet via sync code */
-            if (clear[3] != 0x9d || clear[4] != 0x01 || clear[5] != 0x2a)
-                return VPX_CODEC_UNSUP_BITSTREAM;
-
-            si->w = (clear[6] | (clear[7] << 8)) & 0x3fff;
-            si->h = (clear[8] | (clear[9] << 8)) & 0x3fff;
-
-            /*printf("w=%d, h=%d\n", si->w, si->h);*/
-            if (!(si->h | si->w))
-                res = VPX_CODEC_UNSUP_BITSTREAM;
-        }
-        else
-        {
-            res = VPX_CODEC_UNSUP_BITSTREAM;
-        }
-    }
-
-    return res;
-}
-
-static vpx_codec_err_t vp8_peek_si(const uint8_t *data,
-                                   unsigned int data_sz,
-                                   vpx_codec_stream_info_t *si) {
-    return vp8_peek_si_internal(data, data_sz, si, NULL, NULL);
-}
-
-static vpx_codec_err_t vp8_get_si(vpx_codec_alg_priv_t    *ctx,
-                                  vpx_codec_stream_info_t *si)
-{
-
-    unsigned int sz;
-
-    if (si->sz >= sizeof(vp8_stream_info_t))
-        sz = sizeof(vp8_stream_info_t);
-    else
-        sz = sizeof(vpx_codec_stream_info_t);
-
-    memcpy(si, &ctx->si, sz);
-    si->sz = sz;
-
-    return VPX_CODEC_OK;
-}
-
-
-static vpx_codec_err_t
-update_error_state(vpx_codec_alg_priv_t                 *ctx,
-                   const struct vpx_internal_error_info *error)
-{
-    vpx_codec_err_t res;
-
-    if ((res = error->error_code))
-        ctx->base.err_detail = error->has_detail
-                               ? error->detail
-                               : NULL;
-
-    return res;
-}
-
-static void yuvconfig2image(vpx_image_t               *img,
-                            const YV12_BUFFER_CONFIG  *yv12,
-                            void                      *user_priv)
-{
-    /** vpx_img_wrap() doesn't allow specifying independent strides for
-      * the Y, U, and V planes, nor other alignment adjustments that
-      * might be representable by a YV12_BUFFER_CONFIG, so we just
-      * initialize all the fields.*/
-    img->fmt = VPX_IMG_FMT_I420;
-    img->w = yv12->y_stride;
-    img->h = (yv12->y_height + 2 * VP8BORDERINPIXELS + 15) & ~15;
-    img->d_w = img->r_w = yv12->y_width;
-    img->d_h = img->r_h = yv12->y_height;
-    img->x_chroma_shift = 1;
-    img->y_chroma_shift = 1;
-    img->planes[VPX_PLANE_Y] = yv12->y_buffer;
-    img->planes[VPX_PLANE_U] = yv12->u_buffer;
-    img->planes[VPX_PLANE_V] = yv12->v_buffer;
-    img->planes[VPX_PLANE_ALPHA] = NULL;
-    img->stride[VPX_PLANE_Y] = yv12->y_stride;
-    img->stride[VPX_PLANE_U] = yv12->uv_stride;
-    img->stride[VPX_PLANE_V] = yv12->uv_stride;
-    img->stride[VPX_PLANE_ALPHA] = yv12->y_stride;
-    img->bit_depth = 8;
-    img->bps = 12;
-    img->user_priv = user_priv;
-    img->img_data = yv12->buffer_alloc;
-    img->img_data_owner = 0;
-    img->self_allocd = 0;
-}
-
-static int
-update_fragments(vpx_codec_alg_priv_t  *ctx,
-                 const uint8_t         *data,
-                 unsigned int           data_sz,
-                 vpx_codec_err_t       *res)
-{
-    *res = VPX_CODEC_OK;
-
-    if (ctx->fragments.count == 0)
-    {
-        /* New frame, reset fragment pointers and sizes */
-        memset((void*)ctx->fragments.ptrs, 0, sizeof(ctx->fragments.ptrs));
-        memset(ctx->fragments.sizes, 0, sizeof(ctx->fragments.sizes));
-    }
-    if (ctx->fragments.enabled && !(data == NULL && data_sz == 0))
-    {
-        /* Store a pointer to this fragment and return. We haven't
-         * received the complete frame yet, so we will wait with decoding.
-         */
-        ctx->fragments.ptrs[ctx->fragments.count] = data;
-        ctx->fragments.sizes[ctx->fragments.count] = data_sz;
-        ctx->fragments.count++;
-        if (ctx->fragments.count > (1 << EIGHT_PARTITION) + 1)
-        {
-            ctx->fragments.count = 0;
-            *res = VPX_CODEC_INVALID_PARAM;
-            return -1;
-        }
-        return 0;
-    }
-
-    if (!ctx->fragments.enabled && (data == NULL && data_sz == 0))
-    {
-        return 0;
-    }
-
-    if (!ctx->fragments.enabled)
-    {
-        ctx->fragments.ptrs[0] = data;
-        ctx->fragments.sizes[0] = data_sz;
-        ctx->fragments.count = 1;
-    }
-
-    return 1;
-}
-
-static vpx_codec_err_t vp8_decode(vpx_codec_alg_priv_t  *ctx,
-                                  const uint8_t         *data,
-                                  unsigned int            data_sz,
-                                  void                    *user_priv,
-                                  long                    deadline)
-{
-    vpx_codec_err_t res = VPX_CODEC_OK;
-    unsigned int resolution_change = 0;
-    unsigned int w, h;
-
-    if (!ctx->fragments.enabled && (data == NULL && data_sz == 0))
-    {
-        return 0;
-    }
-
-    /* Update the input fragment data */
-    if(update_fragments(ctx, data, data_sz, &res) <= 0)
-        return res;
-
-    /* Determine the stream parameters. Note that we rely on peek_si to
-     * validate that we have a buffer that does not wrap around the top
-     * of the heap.
-     */
-    w = ctx->si.w;
-    h = ctx->si.h;
-
-    res = vp8_peek_si_internal(ctx->fragments.ptrs[0], ctx->fragments.sizes[0],
-                               &ctx->si, ctx->decrypt_cb, ctx->decrypt_state);
-
-    if((res == VPX_CODEC_UNSUP_BITSTREAM) && !ctx->si.is_kf)
-    {
-        /* the peek function returns an error for non keyframes, however for
-         * this case, it is not an error */
-        res = VPX_CODEC_OK;
-    }
-
-    if(!ctx->decoder_init && !ctx->si.is_kf)
-        res = VPX_CODEC_UNSUP_BITSTREAM;
-
-    if ((ctx->si.h != h) || (ctx->si.w != w))
-        resolution_change = 1;
-
-    /* Initialize the decoder instance on the first frame*/
-    if (!res && !ctx->decoder_init)
-    {
-      VP8D_CONFIG oxcf;
-
-      oxcf.Width = ctx->si.w;
-      oxcf.Height = ctx->si.h;
-      oxcf.Version = 9;
-      oxcf.postprocess = 0;
-      oxcf.max_threads = ctx->cfg.threads;
-      oxcf.error_concealment =
-          (ctx->base.init_flags & VPX_CODEC_USE_ERROR_CONCEALMENT);
-
-      /* If postprocessing was enabled by the application and a
-       * configuration has not been provided, default it.
-       */
-       if (!ctx->postproc_cfg_set
-           && (ctx->base.init_flags & VPX_CODEC_USE_POSTPROC)) {
-         ctx->postproc_cfg.post_proc_flag =
-             VP8_DEBLOCK | VP8_DEMACROBLOCK | VP8_MFQE;
-         ctx->postproc_cfg.deblocking_level = 4;
-         ctx->postproc_cfg.noise_level = 0;
-       }
-
-       res = vp8_create_decoder_instances(&ctx->yv12_frame_buffers, &oxcf);
-       ctx->decoder_init = 1;
-    }
-
-    /* Set these even if already initialized.  The caller may have changed the
-     * decrypt config between frames.
-     */
-    if (ctx->decoder_init) {
-      ctx->yv12_frame_buffers.pbi[0]->decrypt_cb = ctx->decrypt_cb;
-      ctx->yv12_frame_buffers.pbi[0]->decrypt_state = ctx->decrypt_state;
-    }
-
-    if (!res)
-    {
-        VP8D_COMP *pbi = ctx->yv12_frame_buffers.pbi[0];
-        if (resolution_change)
-        {
-            VP8_COMMON *const pc = & pbi->common;
-            MACROBLOCKD *const xd  = & pbi->mb;
-#if CONFIG_MULTITHREAD
-            int i;
-#endif
-            pc->Width = ctx->si.w;
-            pc->Height = ctx->si.h;
-            {
-                int prev_mb_rows = pc->mb_rows;
-
-                if (setjmp(pbi->common.error.jmp))
-                {
-                    pbi->common.error.setjmp = 0;
-                    vp8_clear_system_state();
-                    /* same return value as used in vp8dx_receive_compressed_data */
-                    return -1;
-                }
-
-                pbi->common.error.setjmp = 1;
-
-                if (pc->Width <= 0)
-                {
-                    pc->Width = w;
-                    vpx_internal_error(&pc->error, VPX_CODEC_CORRUPT_FRAME,
-                                       "Invalid frame width");
-                }
-
-                if (pc->Height <= 0)
-                {
-                    pc->Height = h;
-                    vpx_internal_error(&pc->error, VPX_CODEC_CORRUPT_FRAME,
-                                       "Invalid frame height");
-                }
-
-                if (vp8_alloc_frame_buffers(pc, pc->Width, pc->Height))
-                    vpx_internal_error(&pc->error, VPX_CODEC_MEM_ERROR,
-                                       "Failed to allocate frame buffers");
-
-                xd->pre = pc->yv12_fb[pc->lst_fb_idx];
-                xd->dst = pc->yv12_fb[pc->new_fb_idx];
-
-#if CONFIG_MULTITHREAD
-                for (i = 0; i < pbi->allocated_decoding_thread_count; i++)
-                {
-                    pbi->mb_row_di[i].mbd.dst = pc->yv12_fb[pc->new_fb_idx];
-                    vp8_build_block_doffsets(&pbi->mb_row_di[i].mbd);
-                }
-#endif
-                vp8_build_block_doffsets(&pbi->mb);
-
-                /* allocate memory for last frame MODE_INFO array */
-#if CONFIG_ERROR_CONCEALMENT
-
-                if (pbi->ec_enabled)
-                {
-                    /* old prev_mip was released by vp8_de_alloc_frame_buffers()
-                     * called in vp8_alloc_frame_buffers() */
-                    pc->prev_mip = vpx_calloc(
-                                       (pc->mb_cols + 1) * (pc->mb_rows + 1),
-                                       sizeof(MODE_INFO));
-
-                    if (!pc->prev_mip)
-                    {
-                        vp8_de_alloc_frame_buffers(pc);
-                        vpx_internal_error(&pc->error, VPX_CODEC_MEM_ERROR,
-                                           "Failed to allocate"
-                                           "last frame MODE_INFO array");
-                    }
-
-                    pc->prev_mi = pc->prev_mip + pc->mode_info_stride + 1;
-
-                    if (vp8_alloc_overlap_lists(pbi))
-                        vpx_internal_error(&pc->error, VPX_CODEC_MEM_ERROR,
-                                           "Failed to allocate overlap lists "
-                                           "for error concealment");
-                }
-
-#endif
-
-#if CONFIG_MULTITHREAD
-                if (pbi->b_multithreaded_rd)
-                    vp8mt_alloc_temp_buffers(pbi, pc->Width, prev_mb_rows);
-#else
-                (void)prev_mb_rows;
-#endif
-            }
-
-            pbi->common.error.setjmp = 0;
-
-            /* required to get past the first get_free_fb() call */
-            pbi->common.fb_idx_ref_cnt[0] = 0;
-        }
-
-        /* update the pbi fragment data */
-        pbi->fragments = ctx->fragments;
-
-        ctx->user_priv = user_priv;
-        if (vp8dx_receive_compressed_data(pbi, data_sz, data, deadline))
-        {
-            res = update_error_state(ctx, &pbi->common.error);
-        }
-
-        /* get ready for the next series of fragments */
-        ctx->fragments.count = 0;
-    }
-
-    return res;
-}
-
-static vpx_image_t *vp8_get_frame(vpx_codec_alg_priv_t  *ctx,
-                                  vpx_codec_iter_t      *iter)
-{
-    vpx_image_t *img = NULL;
-
-    /* iter acts as a flip flop, so an image is only returned on the first
-     * call to get_frame.
-     */
-    if (!(*iter) && ctx->yv12_frame_buffers.pbi[0])
-    {
-        YV12_BUFFER_CONFIG sd;
-        int64_t time_stamp = 0, time_end_stamp = 0;
-        vp8_ppflags_t flags;
-        vp8_zero(flags);
-
-        if (ctx->base.init_flags & VPX_CODEC_USE_POSTPROC)
-        {
-            flags.post_proc_flag= ctx->postproc_cfg.post_proc_flag
-#if CONFIG_POSTPROC_VISUALIZER
-
-                                | ((ctx->dbg_color_ref_frame_flag != 0) ? VP8D_DEBUG_CLR_FRM_REF_BLKS : 0)
-                                | ((ctx->dbg_color_mb_modes_flag != 0) ? VP8D_DEBUG_CLR_BLK_MODES : 0)
-                                | ((ctx->dbg_color_b_modes_flag != 0) ? VP8D_DEBUG_CLR_BLK_MODES : 0)
-                                | ((ctx->dbg_display_mv_flag != 0) ? VP8D_DEBUG_DRAW_MV : 0)
-#endif
-                                ;
-            flags.deblocking_level      = ctx->postproc_cfg.deblocking_level;
-            flags.noise_level           = ctx->postproc_cfg.noise_level;
-#if CONFIG_POSTPROC_VISUALIZER
-            flags.display_ref_frame_flag= ctx->dbg_color_ref_frame_flag;
-            flags.display_mb_modes_flag = ctx->dbg_color_mb_modes_flag;
-            flags.display_b_modes_flag  = ctx->dbg_color_b_modes_flag;
-            flags.display_mv_flag       = ctx->dbg_display_mv_flag;
-#endif
-        }
-
-        if (0 == vp8dx_get_raw_frame(ctx->yv12_frame_buffers.pbi[0], &sd,
-                                     &time_stamp, &time_end_stamp, &flags))
-        {
-            yuvconfig2image(&ctx->img, &sd, ctx->user_priv);
-
-            img = &ctx->img;
-            *iter = img;
-        }
-    }
-
-    return img;
-}
-
-static vpx_codec_err_t image2yuvconfig(const vpx_image_t   *img,
-                                       YV12_BUFFER_CONFIG  *yv12)
-{
-    const int y_w = img->d_w;
-    const int y_h = img->d_h;
-    const int uv_w = (img->d_w + 1) / 2;
-    const int uv_h = (img->d_h + 1) / 2;
-    vpx_codec_err_t        res = VPX_CODEC_OK;
-    yv12->y_buffer = img->planes[VPX_PLANE_Y];
-    yv12->u_buffer = img->planes[VPX_PLANE_U];
-    yv12->v_buffer = img->planes[VPX_PLANE_V];
-
-    yv12->y_crop_width  = y_w;
-    yv12->y_crop_height = y_h;
-    yv12->y_width  = y_w;
-    yv12->y_height = y_h;
-    yv12->uv_crop_width = uv_w;
-    yv12->uv_crop_height = uv_h;
-    yv12->uv_width = uv_w;
-    yv12->uv_height = uv_h;
-
-    yv12->y_stride = img->stride[VPX_PLANE_Y];
-    yv12->uv_stride = img->stride[VPX_PLANE_U];
-
-    yv12->border  = (img->stride[VPX_PLANE_Y] - img->d_w) / 2;
-    return res;
-}
-
-
-static vpx_codec_err_t vp8_set_reference(vpx_codec_alg_priv_t *ctx,
-                                         va_list args)
-{
-
-    vpx_ref_frame_t *data = va_arg(args, vpx_ref_frame_t *);
-
-    if (data && !ctx->yv12_frame_buffers.use_frame_threads)
-    {
-        vpx_ref_frame_t *frame = (vpx_ref_frame_t *)data;
-        YV12_BUFFER_CONFIG sd;
-
-        image2yuvconfig(&frame->img, &sd);
-
-        return vp8dx_set_reference(ctx->yv12_frame_buffers.pbi[0],
-                                   frame->frame_type, &sd);
-    }
-    else
-        return VPX_CODEC_INVALID_PARAM;
-
-}
-
-static vpx_codec_err_t vp8_get_reference(vpx_codec_alg_priv_t *ctx,
-                                         va_list args)
-{
-
-    vpx_ref_frame_t *data = va_arg(args, vpx_ref_frame_t *);
-
-    if (data && !ctx->yv12_frame_buffers.use_frame_threads)
-    {
-        vpx_ref_frame_t *frame = (vpx_ref_frame_t *)data;
-        YV12_BUFFER_CONFIG sd;
-
-        image2yuvconfig(&frame->img, &sd);
-
-        return vp8dx_get_reference(ctx->yv12_frame_buffers.pbi[0],
-                                   frame->frame_type, &sd);
-    }
-    else
-        return VPX_CODEC_INVALID_PARAM;
-
-}
-
-static vpx_codec_err_t vp8_set_postproc(vpx_codec_alg_priv_t *ctx,
-                                        va_list args)
-{
-#if CONFIG_POSTPROC
-    vp8_postproc_cfg_t *data = va_arg(args, vp8_postproc_cfg_t *);
-
-    if (data)
-    {
-        ctx->postproc_cfg_set = 1;
-        ctx->postproc_cfg = *((vp8_postproc_cfg_t *)data);
-        return VPX_CODEC_OK;
-    }
-    else
-        return VPX_CODEC_INVALID_PARAM;
-
-#else
-    (void)ctx;
-    (void)args;
-    return VPX_CODEC_INCAPABLE;
-#endif
-}
-
-
-static vpx_codec_err_t vp8_set_dbg_color_ref_frame(vpx_codec_alg_priv_t *ctx,
-                                                   va_list args) {
-#if CONFIG_POSTPROC_VISUALIZER && CONFIG_POSTPROC
-  ctx->dbg_color_ref_frame_flag = va_arg(args, int);
-  return VPX_CODEC_OK;
-#else
-  (void)ctx;
-  (void)args;
-  return VPX_CODEC_INCAPABLE;
-#endif
-}
-
-static vpx_codec_err_t vp8_set_dbg_color_mb_modes(vpx_codec_alg_priv_t *ctx,
-                                                  va_list args) {
-#if CONFIG_POSTPROC_VISUALIZER && CONFIG_POSTPROC
-  ctx->dbg_color_mb_modes_flag = va_arg(args, int);
-  return VPX_CODEC_OK;
-#else
-  (void)ctx;
-  (void)args;
-  return VPX_CODEC_INCAPABLE;
-#endif
-}
-
-static vpx_codec_err_t vp8_set_dbg_color_b_modes(vpx_codec_alg_priv_t *ctx,
-                                                 va_list args) {
-#if CONFIG_POSTPROC_VISUALIZER && CONFIG_POSTPROC
-  ctx->dbg_color_b_modes_flag = va_arg(args, int);
-  return VPX_CODEC_OK;
-#else
-  (void)ctx;
-  (void)args;
-  return VPX_CODEC_INCAPABLE;
-#endif
-}
-
-static vpx_codec_err_t vp8_set_dbg_display_mv(vpx_codec_alg_priv_t *ctx,
-                                              va_list args) {
-#if CONFIG_POSTPROC_VISUALIZER && CONFIG_POSTPROC
-  ctx->dbg_display_mv_flag = va_arg(args, int);
-  return VPX_CODEC_OK;
-#else
-  (void)ctx;
-  (void)args;
-  return VPX_CODEC_INCAPABLE;
-#endif
-}
-
-static vpx_codec_err_t vp8_get_last_ref_updates(vpx_codec_alg_priv_t *ctx,
-                                                va_list args)
-{
-    int *update_info = va_arg(args, int *);
-
-    if (update_info && !ctx->yv12_frame_buffers.use_frame_threads)
-    {
-        VP8D_COMP *pbi = (VP8D_COMP *)ctx->yv12_frame_buffers.pbi[0];
-
-        *update_info = pbi->common.refresh_alt_ref_frame * (int) VP8_ALTR_FRAME
-            + pbi->common.refresh_golden_frame * (int) VP8_GOLD_FRAME
-            + pbi->common.refresh_last_frame * (int) VP8_LAST_FRAME;
-
-        return VPX_CODEC_OK;
-    }
-    else
-        return VPX_CODEC_INVALID_PARAM;
-}
-
-extern int vp8dx_references_buffer( VP8_COMMON *oci, int ref_frame );
-static vpx_codec_err_t vp8_get_last_ref_frame(vpx_codec_alg_priv_t *ctx,
-                                              va_list args)
-{
-    int *ref_info = va_arg(args, int *);
-
-    if (ref_info && !ctx->yv12_frame_buffers.use_frame_threads)
-    {
-        VP8D_COMP *pbi = (VP8D_COMP *)ctx->yv12_frame_buffers.pbi[0];
-        VP8_COMMON *oci = &pbi->common;
-        *ref_info =
-            (vp8dx_references_buffer( oci, ALTREF_FRAME )?VP8_ALTR_FRAME:0) |
-            (vp8dx_references_buffer( oci, GOLDEN_FRAME )?VP8_GOLD_FRAME:0) |
-            (vp8dx_references_buffer( oci, LAST_FRAME )?VP8_LAST_FRAME:0);
-
-        return VPX_CODEC_OK;
-    }
-    else
-        return VPX_CODEC_INVALID_PARAM;
-}
-
-static vpx_codec_err_t vp8_get_frame_corrupted(vpx_codec_alg_priv_t *ctx,
-                                               va_list args)
-{
-
-    int *corrupted = va_arg(args, int *);
-    VP8D_COMP *pbi = (VP8D_COMP *)ctx->yv12_frame_buffers.pbi[0];
-
-    if (corrupted && pbi)
-    {
-        const YV12_BUFFER_CONFIG *const frame = pbi->common.frame_to_show;
-        if (frame == NULL) return VPX_CODEC_ERROR;
-        *corrupted = frame->corrupted;
-        return VPX_CODEC_OK;
-    }
-    else
-        return VPX_CODEC_INVALID_PARAM;
-
-}
-
-static vpx_codec_err_t vp8_set_decryptor(vpx_codec_alg_priv_t *ctx,
-                                         va_list args)
-{
-    vpx_decrypt_init *init = va_arg(args, vpx_decrypt_init *);
-
-    if (init)
-    {
-        ctx->decrypt_cb = init->decrypt_cb;
-        ctx->decrypt_state = init->decrypt_state;
-    }
-    else
-    {
-        ctx->decrypt_cb = NULL;
-        ctx->decrypt_state = NULL;
-    }
-    return VPX_CODEC_OK;
-}
-
-vpx_codec_ctrl_fn_map_t vp8_ctf_maps[] =
-{
-    {VP8_SET_REFERENCE,             vp8_set_reference},
-    {VP8_COPY_REFERENCE,            vp8_get_reference},
-    {VP8_SET_POSTPROC,              vp8_set_postproc},
-    {VP8_SET_DBG_COLOR_REF_FRAME,   vp8_set_dbg_color_ref_frame},
-    {VP8_SET_DBG_COLOR_MB_MODES,    vp8_set_dbg_color_mb_modes},
-    {VP8_SET_DBG_COLOR_B_MODES,     vp8_set_dbg_color_b_modes},
-    {VP8_SET_DBG_DISPLAY_MV,        vp8_set_dbg_display_mv},
-    {VP8D_GET_LAST_REF_UPDATES,     vp8_get_last_ref_updates},
-    {VP8D_GET_FRAME_CORRUPTED,      vp8_get_frame_corrupted},
-    {VP8D_GET_LAST_REF_USED,        vp8_get_last_ref_frame},
-    {VPXD_SET_DECRYPTOR,            vp8_set_decryptor},
-    { -1, NULL},
-};
-
-
-#ifndef VERSION_STRING
-#define VERSION_STRING
-#endif
-CODEC_INTERFACE(vpx_codec_vp8_dx) =
-{
-    "WebM Project VP8 Decoder" VERSION_STRING,
-    VPX_CODEC_INTERNAL_ABI_VERSION,
-    VPX_CODEC_CAP_DECODER | VP8_CAP_POSTPROC | VP8_CAP_ERROR_CONCEALMENT |
-    VPX_CODEC_CAP_INPUT_FRAGMENTS,
-    /* vpx_codec_caps_t          caps; */
-    vp8_init,         /* vpx_codec_init_fn_t       init; */
-    vp8_destroy,      /* vpx_codec_destroy_fn_t    destroy; */
-    vp8_ctf_maps,     /* vpx_codec_ctrl_fn_map_t  *ctrl_maps; */
-    {
-        vp8_peek_si,      /* vpx_codec_peek_si_fn_t    peek_si; */
-        vp8_get_si,       /* vpx_codec_get_si_fn_t     get_si; */
-        vp8_decode,       /* vpx_codec_decode_fn_t     decode; */
-        vp8_get_frame,    /* vpx_codec_frame_get_fn_t  frame_get; */
-        NULL,
-    },
-    { /* encoder functions */
-        0,
-        NULL,  /* vpx_codec_enc_cfg_map_t */
-        NULL,  /* vpx_codec_encode_fn_t */
-        NULL,  /* vpx_codec_get_cx_data_fn_t */
-        NULL,  /* vpx_codec_enc_config_set_fn_t */
-        NULL,  /* vpx_codec_get_global_headers_fn_t */
-        NULL,  /* vpx_codec_get_preview_frame_fn_t */
-        NULL   /* vpx_codec_enc_mr_get_mem_loc_fn_t */
-    }
-};
diff --git a/vp8/vp8cx.mk b/vp8/vp8cx.mk
deleted file mode 100644 (file)
index 857a631..0000000
+++ /dev/null
@@ -1,117 +0,0 @@
-##
-##  Copyright (c) 2010 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.
-##
-
-
-VP8_CX_EXPORTS += exports_enc
-
-VP8_CX_SRCS-yes += $(VP8_COMMON_SRCS-yes)
-VP8_CX_SRCS-no  += $(VP8_COMMON_SRCS-no)
-VP8_CX_SRCS_REMOVE-yes += $(VP8_COMMON_SRCS_REMOVE-yes)
-VP8_CX_SRCS_REMOVE-no  += $(VP8_COMMON_SRCS_REMOVE-no)
-
-ifeq ($(ARCH_ARM),yes)
-  include $(SRC_PATH_BARE)/$(VP8_PREFIX)vp8cx_arm.mk
-endif
-
-VP8_CX_SRCS-yes += vp8cx.mk
-
-VP8_CX_SRCS-yes += vp8_cx_iface.c
-
-VP8_CX_SRCS-yes += encoder/defaultcoefcounts.h
-VP8_CX_SRCS-yes += encoder/bitstream.c
-VP8_CX_SRCS-yes += encoder/boolhuff.c
-VP8_CX_SRCS-yes += encoder/dct.c
-VP8_CX_SRCS-yes += encoder/encodeframe.c
-VP8_CX_SRCS-yes += encoder/encodeframe.h
-VP8_CX_SRCS-yes += encoder/encodeintra.c
-VP8_CX_SRCS-yes += encoder/encodemb.c
-VP8_CX_SRCS-yes += encoder/encodemv.c
-VP8_CX_SRCS-$(CONFIG_MULTITHREAD) += encoder/ethreading.c
-VP8_CX_SRCS-yes += encoder/firstpass.c
-VP8_CX_SRCS-yes += encoder/block.h
-VP8_CX_SRCS-yes += encoder/boolhuff.h
-VP8_CX_SRCS-yes += encoder/bitstream.h
-VP8_CX_SRCS-$(CONFIG_TEMPORAL_DENOISING) += encoder/denoising.h
-VP8_CX_SRCS-$(CONFIG_TEMPORAL_DENOISING) += encoder/denoising.c
-VP8_CX_SRCS-yes += encoder/encodeintra.h
-VP8_CX_SRCS-yes += encoder/encodemb.h
-VP8_CX_SRCS-yes += encoder/encodemv.h
-VP8_CX_SRCS-yes += encoder/firstpass.h
-VP8_CX_SRCS-yes += encoder/lookahead.c
-VP8_CX_SRCS-yes += encoder/lookahead.h
-VP8_CX_SRCS-yes += encoder/mcomp.h
-VP8_CX_SRCS-yes += encoder/modecosts.h
-VP8_CX_SRCS-yes += encoder/onyx_int.h
-VP8_CX_SRCS-yes += encoder/pickinter.h
-VP8_CX_SRCS-yes += encoder/quantize.h
-VP8_CX_SRCS-yes += encoder/ratectrl.h
-VP8_CX_SRCS-yes += encoder/rdopt.h
-VP8_CX_SRCS-yes += encoder/tokenize.h
-VP8_CX_SRCS-yes += encoder/treewriter.h
-VP8_CX_SRCS-yes += encoder/mcomp.c
-VP8_CX_SRCS-yes += encoder/modecosts.c
-VP8_CX_SRCS-yes += encoder/onyx_if.c
-VP8_CX_SRCS-yes += encoder/pickinter.c
-VP8_CX_SRCS-yes += encoder/picklpf.c
-VP8_CX_SRCS-yes += encoder/vp8_quantize.c
-VP8_CX_SRCS-yes += encoder/ratectrl.c
-VP8_CX_SRCS-yes += encoder/rdopt.c
-VP8_CX_SRCS-yes += encoder/segmentation.c
-VP8_CX_SRCS-yes += encoder/segmentation.h
-VP8_CX_SRCS-yes += encoder/tokenize.c
-VP8_CX_SRCS-yes += encoder/dct_value_cost.h
-VP8_CX_SRCS-yes += encoder/dct_value_tokens.h
-VP8_CX_SRCS-yes += encoder/treewriter.c
-VP8_CX_SRCS-$(CONFIG_INTERNAL_STATS) += common/postproc.h
-VP8_CX_SRCS-$(CONFIG_INTERNAL_STATS) += common/postproc.c
-VP8_CX_SRCS-yes += encoder/temporal_filter.c
-VP8_CX_SRCS-$(CONFIG_MULTI_RES_ENCODING) += encoder/mr_dissim.c
-VP8_CX_SRCS-$(CONFIG_MULTI_RES_ENCODING) += encoder/mr_dissim.h
-
-ifeq ($(CONFIG_REALTIME_ONLY),yes)
-VP8_CX_SRCS_REMOVE-yes += encoder/firstpass.c
-VP8_CX_SRCS_REMOVE-yes += encoder/temporal_filter.c
-endif
-
-VP8_CX_SRCS-$(HAVE_MMX) += encoder/x86/dct_mmx.asm
-VP8_CX_SRCS-$(HAVE_MMX) += encoder/x86/vp8_enc_stubs_mmx.c
-VP8_CX_SRCS-$(HAVE_SSE2) += encoder/x86/dct_sse2.asm
-VP8_CX_SRCS-$(HAVE_SSE2) += encoder/x86/fwalsh_sse2.asm
-VP8_CX_SRCS-$(HAVE_SSE2) += encoder/x86/vp8_quantize_sse2.c
-VP8_CX_SRCS-$(HAVE_SSSE3) += encoder/x86/quantize_ssse3.c
-VP8_CX_SRCS-$(HAVE_SSE4_1) += encoder/x86/quantize_sse4.c
-
-ifeq ($(CONFIG_TEMPORAL_DENOISING),yes)
-VP8_CX_SRCS-$(HAVE_SSE2) += encoder/x86/denoising_sse2.c
-endif
-
-VP8_CX_SRCS-$(HAVE_SSE2) += encoder/x86/temporal_filter_apply_sse2.asm
-VP8_CX_SRCS-$(HAVE_SSE2) += encoder/x86/vp8_enc_stubs_sse2.c
-VP8_CX_SRCS-$(ARCH_X86)$(ARCH_X86_64) += encoder/x86/quantize_mmx.asm
-VP8_CX_SRCS-$(ARCH_X86)$(ARCH_X86_64) += encoder/x86/encodeopt.asm
-
-ifeq ($(CONFIG_REALTIME_ONLY),yes)
-VP8_CX_SRCS_REMOVE-$(HAVE_SSE2) += encoder/x86/temporal_filter_apply_sse2.asm
-endif
-
-VP8_CX_SRCS-$(HAVE_MSA) += encoder/mips/msa/dct_msa.c
-VP8_CX_SRCS-$(HAVE_MSA) += encoder/mips/msa/encodeopt_msa.c
-VP8_CX_SRCS-$(HAVE_MSA) += encoder/mips/msa/quantize_msa.c
-VP8_CX_SRCS-$(HAVE_MSA) += encoder/mips/msa/temporal_filter_msa.c
-
-ifeq ($(CONFIG_TEMPORAL_DENOISING),yes)
-VP8_CX_SRCS-$(HAVE_MSA) += encoder/mips/msa/denoising_msa.c
-endif
-
-ifeq ($(CONFIG_REALTIME_ONLY),yes)
-VP8_CX_SRCS_REMOVE-$(HAVE_MSA) += encoder/mips/msa/temporal_filter_msa.c
-endif
-
-VP8_CX_SRCS-yes := $(filter-out $(VP8_CX_SRCS_REMOVE-yes),$(VP8_CX_SRCS-yes))
diff --git a/vp8/vp8cx_arm.mk b/vp8/vp8cx_arm.mk
deleted file mode 100644 (file)
index 838b53d..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-##
-##  Copyright (c) 2010 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.
-##
-
-
-VP8_CX_SRCS-$(ARCH_ARM)  += vp8cx_arm.mk
-
-#File list for arm
-# encoder
-VP8_CX_SRCS-$(ARCH_ARM)  += encoder/arm/dct_arm.c
-
-#File list for media
-# encoder
-VP8_CX_SRCS-$(HAVE_MEDIA)  += encoder/arm/armv6/vp8_short_fdct4x4_armv6$(ASM)
-VP8_CX_SRCS-$(HAVE_MEDIA)  += encoder/arm/armv6/walsh_v6$(ASM)
-
-#File list for neon
-# encoder
-VP8_CX_SRCS-$(HAVE_NEON)  += encoder/arm/neon/denoising_neon.c
-VP8_CX_SRCS-$(HAVE_NEON)  += encoder/arm/neon/fastquantizeb_neon.c
-VP8_CX_SRCS-$(HAVE_NEON)  += encoder/arm/neon/shortfdct_neon.c
-VP8_CX_SRCS-$(HAVE_NEON)  += encoder/arm/neon/vp8_shortwalsh4x4_neon.c
diff --git a/vp8/vp8dx.mk b/vp8/vp8dx.mk
deleted file mode 100644 (file)
index 892ed70..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-##
-##  Copyright (c) 2010 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.
-##
-
-
-VP8_DX_EXPORTS += exports_dec
-
-VP8_DX_SRCS-yes += $(VP8_COMMON_SRCS-yes)
-VP8_DX_SRCS-no  += $(VP8_COMMON_SRCS-no)
-VP8_DX_SRCS_REMOVE-yes += $(VP8_COMMON_SRCS_REMOVE-yes)
-VP8_DX_SRCS_REMOVE-no  += $(VP8_COMMON_SRCS_REMOVE-no)
-
-VP8_DX_SRCS-yes += vp8dx.mk
-
-VP8_DX_SRCS-yes += vp8_dx_iface.c
-
-VP8_DX_SRCS-yes += decoder/dboolhuff.c
-VP8_DX_SRCS-yes += decoder/decodemv.c
-VP8_DX_SRCS-yes += decoder/decodeframe.c
-VP8_DX_SRCS-yes += decoder/detokenize.c
-VP8_DX_SRCS-$(CONFIG_ERROR_CONCEALMENT) += decoder/ec_types.h
-VP8_DX_SRCS-$(CONFIG_ERROR_CONCEALMENT) += decoder/error_concealment.h
-VP8_DX_SRCS-$(CONFIG_ERROR_CONCEALMENT) += decoder/error_concealment.c
-VP8_DX_SRCS-yes += decoder/dboolhuff.h
-VP8_DX_SRCS-yes += decoder/decodemv.h
-VP8_DX_SRCS-yes += decoder/decoderthreading.h
-VP8_DX_SRCS-yes += decoder/detokenize.h
-VP8_DX_SRCS-yes += decoder/onyxd_int.h
-VP8_DX_SRCS-yes += decoder/treereader.h
-VP8_DX_SRCS-yes += decoder/onyxd_if.c
-VP8_DX_SRCS-$(CONFIG_MULTITHREAD) += decoder/threading.c
-
-VP8_DX_SRCS-yes := $(filter-out $(VP8_DX_SRCS_REMOVE-yes),$(VP8_DX_SRCS-yes))
diff --git a/vp9/common/arm/neon/vp9_iht4x4_add_neon.c b/vp9/common/arm/neon/vp9_iht4x4_add_neon.c
deleted file mode 100644 (file)
index 1761fad..0000000
+++ /dev/null
@@ -1,248 +0,0 @@
-/*
- *  Copyright (c) 2014 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.
- */
-
-#include <arm_neon.h>
-#include <assert.h>
-
-#include "./vp9_rtcd.h"
-#include "./vpx_config.h"
-#include "vp9/common/vp9_common.h"
-
-static int16_t sinpi_1_9 = 0x14a3;
-static int16_t sinpi_2_9 = 0x26c9;
-static int16_t sinpi_3_9 = 0x3441;
-static int16_t sinpi_4_9 = 0x3b6c;
-static int16_t cospi_8_64 = 0x3b21;
-static int16_t cospi_16_64 = 0x2d41;
-static int16_t cospi_24_64 = 0x187e;
-
-static INLINE void TRANSPOSE4X4(
-        int16x8_t *q8s16,
-        int16x8_t *q9s16) {
-    int32x4_t q8s32, q9s32;
-    int16x4x2_t d0x2s16, d1x2s16;
-    int32x4x2_t q0x2s32;
-
-    d0x2s16 = vtrn_s16(vget_low_s16(*q8s16), vget_high_s16(*q8s16));
-    d1x2s16 = vtrn_s16(vget_low_s16(*q9s16), vget_high_s16(*q9s16));
-
-    q8s32 = vreinterpretq_s32_s16(vcombine_s16(d0x2s16.val[0], d0x2s16.val[1]));
-    q9s32 = vreinterpretq_s32_s16(vcombine_s16(d1x2s16.val[0], d1x2s16.val[1]));
-    q0x2s32 = vtrnq_s32(q8s32, q9s32);
-
-    *q8s16 = vreinterpretq_s16_s32(q0x2s32.val[0]);
-    *q9s16 = vreinterpretq_s16_s32(q0x2s32.val[1]);
-    return;
-}
-
-static INLINE void GENERATE_COSINE_CONSTANTS(
-        int16x4_t *d0s16,
-        int16x4_t *d1s16,
-        int16x4_t *d2s16) {
-    *d0s16 = vdup_n_s16(cospi_8_64);
-    *d1s16 = vdup_n_s16(cospi_16_64);
-    *d2s16 = vdup_n_s16(cospi_24_64);
-    return;
-}
-
-static INLINE void GENERATE_SINE_CONSTANTS(
-        int16x4_t *d3s16,
-        int16x4_t *d4s16,
-        int16x4_t *d5s16,
-        int16x8_t *q3s16) {
-    *d3s16 = vdup_n_s16(sinpi_1_9);
-    *d4s16 = vdup_n_s16(sinpi_2_9);
-    *q3s16 = vdupq_n_s16(sinpi_3_9);
-    *d5s16 = vdup_n_s16(sinpi_4_9);
-    return;
-}
-
-static INLINE void IDCT4x4_1D(
-        int16x4_t *d0s16,
-        int16x4_t *d1s16,
-        int16x4_t *d2s16,
-        int16x8_t *q8s16,
-        int16x8_t *q9s16) {
-    int16x4_t d16s16, d17s16, d18s16, d19s16, d23s16, d24s16;
-    int16x4_t d26s16, d27s16, d28s16, d29s16;
-    int32x4_t q10s32, q13s32, q14s32, q15s32;
-    int16x8_t q13s16, q14s16;
-
-    d16s16 = vget_low_s16(*q8s16);
-    d17s16 = vget_high_s16(*q8s16);
-    d18s16 = vget_low_s16(*q9s16);
-    d19s16 = vget_high_s16(*q9s16);
-
-    d23s16 = vadd_s16(d16s16, d18s16);
-    d24s16 = vsub_s16(d16s16, d18s16);
-
-    q15s32 = vmull_s16(d17s16, *d2s16);
-    q10s32 = vmull_s16(d17s16, *d0s16);
-    q13s32 = vmull_s16(d23s16, *d1s16);
-    q14s32 = vmull_s16(d24s16, *d1s16);
-    q15s32 = vmlsl_s16(q15s32, d19s16, *d0s16);
-    q10s32 = vmlal_s16(q10s32, d19s16, *d2s16);
-
-    d26s16 = vqrshrn_n_s32(q13s32, 14);
-    d27s16 = vqrshrn_n_s32(q14s32, 14);
-    d29s16 = vqrshrn_n_s32(q15s32, 14);
-    d28s16 = vqrshrn_n_s32(q10s32, 14);
-
-    q13s16 = vcombine_s16(d26s16, d27s16);
-    q14s16 = vcombine_s16(d28s16, d29s16);
-    *q8s16 = vaddq_s16(q13s16, q14s16);
-    *q9s16 = vsubq_s16(q13s16, q14s16);
-    *q9s16 = vcombine_s16(vget_high_s16(*q9s16),
-                          vget_low_s16(*q9s16));  // vswp
-    return;
-}
-
-static INLINE void IADST4x4_1D(
-        int16x4_t *d3s16,
-        int16x4_t *d4s16,
-        int16x4_t *d5s16,
-        int16x8_t *q3s16,
-        int16x8_t *q8s16,
-        int16x8_t *q9s16) {
-    int16x4_t d6s16, d16s16, d17s16, d18s16, d19s16;
-    int32x4_t q8s32, q9s32, q10s32, q11s32, q12s32, q13s32, q14s32, q15s32;
-
-    d6s16 = vget_low_s16(*q3s16);
-
-    d16s16 = vget_low_s16(*q8s16);
-    d17s16 = vget_high_s16(*q8s16);
-    d18s16 = vget_low_s16(*q9s16);
-    d19s16 = vget_high_s16(*q9s16);
-
-    q10s32 = vmull_s16(*d3s16, d16s16);
-    q11s32 = vmull_s16(*d4s16, d16s16);
-    q12s32 = vmull_s16(d6s16, d17s16);
-    q13s32 = vmull_s16(*d5s16, d18s16);
-    q14s32 = vmull_s16(*d3s16, d18s16);
-    q15s32 = vmovl_s16(d16s16);
-    q15s32 = vaddw_s16(q15s32, d19s16);
-    q8s32  = vmull_s16(*d4s16, d19s16);
-    q15s32 = vsubw_s16(q15s32, d18s16);
-    q9s32  = vmull_s16(*d5s16, d19s16);
-
-    q10s32 = vaddq_s32(q10s32, q13s32);
-    q10s32 = vaddq_s32(q10s32, q8s32);
-    q11s32 = vsubq_s32(q11s32, q14s32);
-    q8s32  = vdupq_n_s32(sinpi_3_9);
-    q11s32 = vsubq_s32(q11s32, q9s32);
-    q15s32 = vmulq_s32(q15s32, q8s32);
-
-    q13s32 = vaddq_s32(q10s32, q12s32);
-    q10s32 = vaddq_s32(q10s32, q11s32);
-    q14s32 = vaddq_s32(q11s32, q12s32);
-    q10s32 = vsubq_s32(q10s32, q12s32);
-
-    d16s16 = vqrshrn_n_s32(q13s32, 14);
-    d17s16 = vqrshrn_n_s32(q14s32, 14);
-    d18s16 = vqrshrn_n_s32(q15s32, 14);
-    d19s16 = vqrshrn_n_s32(q10s32, 14);
-
-    *q8s16 = vcombine_s16(d16s16, d17s16);
-    *q9s16 = vcombine_s16(d18s16, d19s16);
-    return;
-}
-
-void vp9_iht4x4_16_add_neon(const tran_low_t *input, uint8_t *dest,
-                            int dest_stride, int tx_type) {
-    uint8x8_t d26u8, d27u8;
-    int16x4_t d0s16, d1s16, d2s16, d3s16, d4s16, d5s16;
-    uint32x2_t d26u32, d27u32;
-    int16x8_t q3s16, q8s16, q9s16;
-    uint16x8_t q8u16, q9u16;
-
-    d26u32 = d27u32 = vdup_n_u32(0);
-
-    q8s16 = vld1q_s16(input);
-    q9s16 = vld1q_s16(input + 8);
-
-    TRANSPOSE4X4(&q8s16, &q9s16);
-
-    switch (tx_type) {
-      case 0:  // idct_idct is not supported. Fall back to C
-        vp9_iht4x4_16_add_c(input, dest, dest_stride, tx_type);
-        return;
-        break;
-      case 1:  // iadst_idct
-        // generate constants
-        GENERATE_COSINE_CONSTANTS(&d0s16, &d1s16, &d2s16);
-        GENERATE_SINE_CONSTANTS(&d3s16, &d4s16, &d5s16, &q3s16);
-
-        // first transform rows
-        IDCT4x4_1D(&d0s16, &d1s16, &d2s16, &q8s16, &q9s16);
-
-        // transpose the matrix
-        TRANSPOSE4X4(&q8s16, &q9s16);
-
-        // then transform columns
-        IADST4x4_1D(&d3s16, &d4s16, &d5s16, &q3s16, &q8s16, &q9s16);
-        break;
-      case 2:  // idct_iadst
-        // generate constantsyy
-        GENERATE_COSINE_CONSTANTS(&d0s16, &d1s16, &d2s16);
-        GENERATE_SINE_CONSTANTS(&d3s16, &d4s16, &d5s16, &q3s16);
-
-        // first transform rows
-        IADST4x4_1D(&d3s16, &d4s16, &d5s16, &q3s16, &q8s16, &q9s16);
-
-        // transpose the matrix
-        TRANSPOSE4X4(&q8s16, &q9s16);
-
-        // then transform columns
-        IDCT4x4_1D(&d0s16, &d1s16, &d2s16, &q8s16, &q9s16);
-        break;
-      case 3:  // iadst_iadst
-        // generate constants
-        GENERATE_SINE_CONSTANTS(&d3s16, &d4s16, &d5s16, &q3s16);
-
-        // first transform rows
-        IADST4x4_1D(&d3s16, &d4s16, &d5s16, &q3s16, &q8s16, &q9s16);
-
-        // transpose the matrix
-        TRANSPOSE4X4(&q8s16, &q9s16);
-
-        // then transform columns
-        IADST4x4_1D(&d3s16, &d4s16, &d5s16, &q3s16, &q8s16, &q9s16);
-        break;
-      default:  // iadst_idct
-        assert(0);
-        break;
-    }
-
-    q8s16 = vrshrq_n_s16(q8s16, 4);
-    q9s16 = vrshrq_n_s16(q9s16, 4);
-
-    d26u32 = vld1_lane_u32((const uint32_t *)dest, d26u32, 0);
-    dest += dest_stride;
-    d26u32 = vld1_lane_u32((const uint32_t *)dest, d26u32, 1);
-    dest += dest_stride;
-    d27u32 = vld1_lane_u32((const uint32_t *)dest, d27u32, 0);
-    dest += dest_stride;
-    d27u32 = vld1_lane_u32((const uint32_t *)dest, d27u32, 1);
-
-    q8u16 = vaddw_u8(vreinterpretq_u16_s16(q8s16), vreinterpret_u8_u32(d26u32));
-    q9u16 = vaddw_u8(vreinterpretq_u16_s16(q9s16), vreinterpret_u8_u32(d27u32));
-
-    d26u8 = vqmovun_s16(vreinterpretq_s16_u16(q8u16));
-    d27u8 = vqmovun_s16(vreinterpretq_s16_u16(q9u16));
-
-    vst1_lane_u32((uint32_t *)dest, vreinterpret_u32_u8(d27u8), 1);
-    dest -= dest_stride;
-    vst1_lane_u32((uint32_t *)dest, vreinterpret_u32_u8(d27u8), 0);
-    dest -= dest_stride;
-    vst1_lane_u32((uint32_t *)dest, vreinterpret_u32_u8(d26u8), 1);
-    dest -= dest_stride;
-    vst1_lane_u32((uint32_t *)dest, vreinterpret_u32_u8(d26u8), 0);
-    return;
-}
diff --git a/vp9/common/arm/neon/vp9_iht8x8_add_neon.c b/vp9/common/arm/neon/vp9_iht8x8_add_neon.c
deleted file mode 100644 (file)
index 04b342c..0000000
+++ /dev/null
@@ -1,624 +0,0 @@
-/*
- *  Copyright (c) 2014 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.
- */
-
-#include <arm_neon.h>
-#include <assert.h>
-
-#include "./vp9_rtcd.h"
-#include "./vpx_config.h"
-#include "vp9/common/vp9_common.h"
-
-static int16_t cospi_2_64 = 16305;
-static int16_t cospi_4_64 = 16069;
-static int16_t cospi_6_64 = 15679;
-static int16_t cospi_8_64 = 15137;
-static int16_t cospi_10_64 = 14449;
-static int16_t cospi_12_64 = 13623;
-static int16_t cospi_14_64 = 12665;
-static int16_t cospi_16_64 = 11585;
-static int16_t cospi_18_64 = 10394;
-static int16_t cospi_20_64 = 9102;
-static int16_t cospi_22_64 = 7723;
-static int16_t cospi_24_64 = 6270;
-static int16_t cospi_26_64 = 4756;
-static int16_t cospi_28_64 = 3196;
-static int16_t cospi_30_64 = 1606;
-
-static INLINE void TRANSPOSE8X8(
-        int16x8_t *q8s16,
-        int16x8_t *q9s16,
-        int16x8_t *q10s16,
-        int16x8_t *q11s16,
-        int16x8_t *q12s16,
-        int16x8_t *q13s16,
-        int16x8_t *q14s16,
-        int16x8_t *q15s16) {
-    int16x4_t d16s16, d17s16, d18s16, d19s16, d20s16, d21s16, d22s16, d23s16;
-    int16x4_t d24s16, d25s16, d26s16, d27s16, d28s16, d29s16, d30s16, d31s16;
-    int32x4x2_t q0x2s32, q1x2s32, q2x2s32, q3x2s32;
-    int16x8x2_t q0x2s16, q1x2s16, q2x2s16, q3x2s16;
-
-    d16s16 = vget_low_s16(*q8s16);
-    d17s16 = vget_high_s16(*q8s16);
-    d18s16 = vget_low_s16(*q9s16);
-    d19s16 = vget_high_s16(*q9s16);
-    d20s16 = vget_low_s16(*q10s16);
-    d21s16 = vget_high_s16(*q10s16);
-    d22s16 = vget_low_s16(*q11s16);
-    d23s16 = vget_high_s16(*q11s16);
-    d24s16 = vget_low_s16(*q12s16);
-    d25s16 = vget_high_s16(*q12s16);
-    d26s16 = vget_low_s16(*q13s16);
-    d27s16 = vget_high_s16(*q13s16);
-    d28s16 = vget_low_s16(*q14s16);
-    d29s16 = vget_high_s16(*q14s16);
-    d30s16 = vget_low_s16(*q15s16);
-    d31s16 = vget_high_s16(*q15s16);
-
-    *q8s16  = vcombine_s16(d16s16, d24s16);  // vswp d17, d24
-    *q9s16  = vcombine_s16(d18s16, d26s16);  // vswp d19, d26
-    *q10s16 = vcombine_s16(d20s16, d28s16);  // vswp d21, d28
-    *q11s16 = vcombine_s16(d22s16, d30s16);  // vswp d23, d30
-    *q12s16 = vcombine_s16(d17s16, d25s16);
-    *q13s16 = vcombine_s16(d19s16, d27s16);
-    *q14s16 = vcombine_s16(d21s16, d29s16);
-    *q15s16 = vcombine_s16(d23s16, d31s16);
-
-    q0x2s32 = vtrnq_s32(vreinterpretq_s32_s16(*q8s16),
-                        vreinterpretq_s32_s16(*q10s16));
-    q1x2s32 = vtrnq_s32(vreinterpretq_s32_s16(*q9s16),
-                        vreinterpretq_s32_s16(*q11s16));
-    q2x2s32 = vtrnq_s32(vreinterpretq_s32_s16(*q12s16),
-                        vreinterpretq_s32_s16(*q14s16));
-    q3x2s32 = vtrnq_s32(vreinterpretq_s32_s16(*q13s16),
-                        vreinterpretq_s32_s16(*q15s16));
-
-    q0x2s16 = vtrnq_s16(vreinterpretq_s16_s32(q0x2s32.val[0]),   // q8
-                        vreinterpretq_s16_s32(q1x2s32.val[0]));  // q9
-    q1x2s16 = vtrnq_s16(vreinterpretq_s16_s32(q0x2s32.val[1]),   // q10
-                        vreinterpretq_s16_s32(q1x2s32.val[1]));  // q11
-    q2x2s16 = vtrnq_s16(vreinterpretq_s16_s32(q2x2s32.val[0]),   // q12
-                        vreinterpretq_s16_s32(q3x2s32.val[0]));  // q13
-    q3x2s16 = vtrnq_s16(vreinterpretq_s16_s32(q2x2s32.val[1]),   // q14
-                        vreinterpretq_s16_s32(q3x2s32.val[1]));  // q15
-
-    *q8s16  = q0x2s16.val[0];
-    *q9s16  = q0x2s16.val[1];
-    *q10s16 = q1x2s16.val[0];
-    *q11s16 = q1x2s16.val[1];
-    *q12s16 = q2x2s16.val[0];
-    *q13s16 = q2x2s16.val[1];
-    *q14s16 = q3x2s16.val[0];
-    *q15s16 = q3x2s16.val[1];
-    return;
-}
-
-static INLINE void IDCT8x8_1D(
-        int16x8_t *q8s16,
-        int16x8_t *q9s16,
-        int16x8_t *q10s16,
-        int16x8_t *q11s16,
-        int16x8_t *q12s16,
-        int16x8_t *q13s16,
-        int16x8_t *q14s16,
-        int16x8_t *q15s16) {
-    int16x4_t d0s16, d1s16, d2s16, d3s16;
-    int16x4_t d8s16, d9s16, d10s16, d11s16, d12s16, d13s16, d14s16, d15s16;
-    int16x4_t d16s16, d17s16, d18s16, d19s16, d20s16, d21s16, d22s16, d23s16;
-    int16x4_t d24s16, d25s16, d26s16, d27s16, d28s16, d29s16, d30s16, d31s16;
-    int16x8_t q0s16, q1s16, q2s16, q3s16, q4s16, q5s16, q6s16, q7s16;
-    int32x4_t q2s32, q3s32, q5s32, q6s32, q8s32, q9s32;
-    int32x4_t q10s32, q11s32, q12s32, q13s32, q15s32;
-
-    d0s16 = vdup_n_s16(cospi_28_64);
-    d1s16 = vdup_n_s16(cospi_4_64);
-    d2s16 = vdup_n_s16(cospi_12_64);
-    d3s16 = vdup_n_s16(cospi_20_64);
-
-    d16s16 = vget_low_s16(*q8s16);
-    d17s16 = vget_high_s16(*q8s16);
-    d18s16 = vget_low_s16(*q9s16);
-    d19s16 = vget_high_s16(*q9s16);
-    d20s16 = vget_low_s16(*q10s16);
-    d21s16 = vget_high_s16(*q10s16);
-    d22s16 = vget_low_s16(*q11s16);
-    d23s16 = vget_high_s16(*q11s16);
-    d24s16 = vget_low_s16(*q12s16);
-    d25s16 = vget_high_s16(*q12s16);
-    d26s16 = vget_low_s16(*q13s16);
-    d27s16 = vget_high_s16(*q13s16);
-    d28s16 = vget_low_s16(*q14s16);
-    d29s16 = vget_high_s16(*q14s16);
-    d30s16 = vget_low_s16(*q15s16);
-    d31s16 = vget_high_s16(*q15s16);
-
-    q2s32 = vmull_s16(d18s16, d0s16);
-    q3s32 = vmull_s16(d19s16, d0s16);
-    q5s32 = vmull_s16(d26s16, d2s16);
-    q6s32 = vmull_s16(d27s16, d2s16);
-
-    q2s32 = vmlsl_s16(q2s32, d30s16, d1s16);
-    q3s32 = vmlsl_s16(q3s32, d31s16, d1s16);
-    q5s32 = vmlsl_s16(q5s32, d22s16, d3s16);
-    q6s32 = vmlsl_s16(q6s32, d23s16, d3s16);
-
-    d8s16  = vqrshrn_n_s32(q2s32, 14);
-    d9s16  = vqrshrn_n_s32(q3s32, 14);
-    d10s16 = vqrshrn_n_s32(q5s32, 14);
-    d11s16 = vqrshrn_n_s32(q6s32, 14);
-    q4s16 = vcombine_s16(d8s16, d9s16);
-    q5s16 = vcombine_s16(d10s16, d11s16);
-
-    q2s32 = vmull_s16(d18s16, d1s16);
-    q3s32 = vmull_s16(d19s16, d1s16);
-    q9s32 = vmull_s16(d26s16, d3s16);
-    q13s32 = vmull_s16(d27s16, d3s16);
-
-    q2s32 = vmlal_s16(q2s32, d30s16, d0s16);
-    q3s32 = vmlal_s16(q3s32, d31s16, d0s16);
-    q9s32 = vmlal_s16(q9s32, d22s16, d2s16);
-    q13s32 = vmlal_s16(q13s32, d23s16, d2s16);
-
-    d14s16 = vqrshrn_n_s32(q2s32, 14);
-    d15s16 = vqrshrn_n_s32(q3s32, 14);
-    d12s16 = vqrshrn_n_s32(q9s32, 14);
-    d13s16 = vqrshrn_n_s32(q13s32, 14);
-    q6s16 = vcombine_s16(d12s16, d13s16);
-    q7s16 = vcombine_s16(d14s16, d15s16);
-
-    d0s16 = vdup_n_s16(cospi_16_64);
-
-    q2s32 = vmull_s16(d16s16, d0s16);
-    q3s32 = vmull_s16(d17s16, d0s16);
-    q13s32 = vmull_s16(d16s16, d0s16);
-    q15s32 = vmull_s16(d17s16, d0s16);
-
-    q2s32 = vmlal_s16(q2s32, d24s16, d0s16);
-    q3s32 = vmlal_s16(q3s32, d25s16, d0s16);
-    q13s32 = vmlsl_s16(q13s32, d24s16, d0s16);
-    q15s32 = vmlsl_s16(q15s32, d25s16, d0s16);
-
-    d0s16 = vdup_n_s16(cospi_24_64);
-    d1s16 = vdup_n_s16(cospi_8_64);
-
-    d18s16 = vqrshrn_n_s32(q2s32, 14);
-    d19s16 = vqrshrn_n_s32(q3s32, 14);
-    d22s16 = vqrshrn_n_s32(q13s32, 14);
-    d23s16 = vqrshrn_n_s32(q15s32, 14);
-    *q9s16  = vcombine_s16(d18s16, d19s16);
-    *q11s16 = vcombine_s16(d22s16, d23s16);
-
-    q2s32 = vmull_s16(d20s16, d0s16);
-    q3s32 = vmull_s16(d21s16, d0s16);
-    q8s32 = vmull_s16(d20s16, d1s16);
-    q12s32 = vmull_s16(d21s16, d1s16);
-
-    q2s32 = vmlsl_s16(q2s32, d28s16, d1s16);
-    q3s32 = vmlsl_s16(q3s32, d29s16, d1s16);
-    q8s32 = vmlal_s16(q8s32, d28s16, d0s16);
-    q12s32 = vmlal_s16(q12s32, d29s16, d0s16);
-
-    d26s16 = vqrshrn_n_s32(q2s32, 14);
-    d27s16 = vqrshrn_n_s32(q3s32, 14);
-    d30s16 = vqrshrn_n_s32(q8s32, 14);
-    d31s16 = vqrshrn_n_s32(q12s32, 14);
-    *q13s16 = vcombine_s16(d26s16, d27s16);
-    *q15s16 = vcombine_s16(d30s16, d31s16);
-
-    q0s16 = vaddq_s16(*q9s16, *q15s16);
-    q1s16 = vaddq_s16(*q11s16, *q13s16);
-    q2s16 = vsubq_s16(*q11s16, *q13s16);
-    q3s16 = vsubq_s16(*q9s16, *q15s16);
-
-    *q13s16 = vsubq_s16(q4s16, q5s16);
-    q4s16   = vaddq_s16(q4s16, q5s16);
-    *q14s16 = vsubq_s16(q7s16, q6s16);
-    q7s16   = vaddq_s16(q7s16, q6s16);
-    d26s16 = vget_low_s16(*q13s16);
-    d27s16 = vget_high_s16(*q13s16);
-    d28s16 = vget_low_s16(*q14s16);
-    d29s16 = vget_high_s16(*q14s16);
-
-    d16s16 = vdup_n_s16(cospi_16_64);
-
-    q9s32  = vmull_s16(d28s16, d16s16);
-    q10s32 = vmull_s16(d29s16, d16s16);
-    q11s32 = vmull_s16(d28s16, d16s16);
-    q12s32 = vmull_s16(d29s16, d16s16);
-
-    q9s32  = vmlsl_s16(q9s32,  d26s16, d16s16);
-    q10s32 = vmlsl_s16(q10s32, d27s16, d16s16);
-    q11s32 = vmlal_s16(q11s32, d26s16, d16s16);
-    q12s32 = vmlal_s16(q12s32, d27s16, d16s16);
-
-    d10s16 = vqrshrn_n_s32(q9s32, 14);
-    d11s16 = vqrshrn_n_s32(q10s32, 14);
-    d12s16 = vqrshrn_n_s32(q11s32, 14);
-    d13s16 = vqrshrn_n_s32(q12s32, 14);
-    q5s16 = vcombine_s16(d10s16, d11s16);
-    q6s16 = vcombine_s16(d12s16, d13s16);
-
-    *q8s16  = vaddq_s16(q0s16, q7s16);
-    *q9s16  = vaddq_s16(q1s16, q6s16);
-    *q10s16 = vaddq_s16(q2s16, q5s16);
-    *q11s16 = vaddq_s16(q3s16, q4s16);
-    *q12s16 = vsubq_s16(q3s16, q4s16);
-    *q13s16 = vsubq_s16(q2s16, q5s16);
-    *q14s16 = vsubq_s16(q1s16, q6s16);
-    *q15s16 = vsubq_s16(q0s16, q7s16);
-    return;
-}
-
-static INLINE void IADST8X8_1D(
-        int16x8_t *q8s16,
-        int16x8_t *q9s16,
-        int16x8_t *q10s16,
-        int16x8_t *q11s16,
-        int16x8_t *q12s16,
-        int16x8_t *q13s16,
-        int16x8_t *q14s16,
-        int16x8_t *q15s16) {
-    int16x4_t d0s16, d1s16, d2s16, d3s16, d4s16, d5s16, d6s16, d7s16;
-    int16x4_t d8s16, d9s16, d10s16, d11s16, d12s16, d13s16, d14s16, d15s16;
-    int16x4_t d16s16, d17s16, d18s16, d19s16, d20s16, d21s16, d22s16, d23s16;
-    int16x4_t d24s16, d25s16, d26s16, d27s16, d28s16, d29s16, d30s16, d31s16;
-    int16x8_t q2s16, q4s16, q5s16, q6s16;
-    int32x4_t q0s32, q1s32, q2s32, q3s32, q4s32, q5s32, q6s32, q7s32, q8s32;
-    int32x4_t q9s32, q10s32, q11s32, q12s32, q13s32, q14s32, q15s32;
-
-    d16s16 = vget_low_s16(*q8s16);
-    d17s16 = vget_high_s16(*q8s16);
-    d18s16 = vget_low_s16(*q9s16);
-    d19s16 = vget_high_s16(*q9s16);
-    d20s16 = vget_low_s16(*q10s16);
-    d21s16 = vget_high_s16(*q10s16);
-    d22s16 = vget_low_s16(*q11s16);
-    d23s16 = vget_high_s16(*q11s16);
-    d24s16 = vget_low_s16(*q12s16);
-    d25s16 = vget_high_s16(*q12s16);
-    d26s16 = vget_low_s16(*q13s16);
-    d27s16 = vget_high_s16(*q13s16);
-    d28s16 = vget_low_s16(*q14s16);
-    d29s16 = vget_high_s16(*q14s16);
-    d30s16 = vget_low_s16(*q15s16);
-    d31s16 = vget_high_s16(*q15s16);
-
-    d14s16 = vdup_n_s16(cospi_2_64);
-    d15s16 = vdup_n_s16(cospi_30_64);
-
-    q1s32 = vmull_s16(d30s16, d14s16);
-    q2s32 = vmull_s16(d31s16, d14s16);
-    q3s32 = vmull_s16(d30s16, d15s16);
-    q4s32 = vmull_s16(d31s16, d15s16);
-
-    d30s16 = vdup_n_s16(cospi_18_64);
-    d31s16 = vdup_n_s16(cospi_14_64);
-
-    q1s32 = vmlal_s16(q1s32, d16s16, d15s16);
-    q2s32 = vmlal_s16(q2s32, d17s16, d15s16);
-    q3s32 = vmlsl_s16(q3s32, d16s16, d14s16);
-    q4s32 = vmlsl_s16(q4s32, d17s16, d14s16);
-
-    q5s32 = vmull_s16(d22s16, d30s16);
-    q6s32 = vmull_s16(d23s16, d30s16);
-    q7s32 = vmull_s16(d22s16, d31s16);
-    q8s32 = vmull_s16(d23s16, d31s16);
-
-    q5s32 = vmlal_s16(q5s32, d24s16, d31s16);
-    q6s32 = vmlal_s16(q6s32, d25s16, d31s16);
-    q7s32 = vmlsl_s16(q7s32, d24s16, d30s16);
-    q8s32 = vmlsl_s16(q8s32, d25s16, d30s16);
-
-    q11s32 = vaddq_s32(q1s32, q5s32);
-    q12s32 = vaddq_s32(q2s32, q6s32);
-    q1s32 = vsubq_s32(q1s32, q5s32);
-    q2s32 = vsubq_s32(q2s32, q6s32);
-
-    d22s16 = vqrshrn_n_s32(q11s32, 14);
-    d23s16 = vqrshrn_n_s32(q12s32, 14);
-    *q11s16 = vcombine_s16(d22s16, d23s16);
-
-    q12s32 = vaddq_s32(q3s32, q7s32);
-    q15s32 = vaddq_s32(q4s32, q8s32);
-    q3s32 = vsubq_s32(q3s32, q7s32);
-    q4s32 = vsubq_s32(q4s32, q8s32);
-
-    d2s16  = vqrshrn_n_s32(q1s32, 14);
-    d3s16  = vqrshrn_n_s32(q2s32, 14);
-    d24s16 = vqrshrn_n_s32(q12s32, 14);
-    d25s16 = vqrshrn_n_s32(q15s32, 14);
-    d6s16  = vqrshrn_n_s32(q3s32, 14);
-    d7s16  = vqrshrn_n_s32(q4s32, 14);
-    *q12s16 = vcombine_s16(d24s16, d25s16);
-
-    d0s16 = vdup_n_s16(cospi_10_64);
-    d1s16 = vdup_n_s16(cospi_22_64);
-    q4s32 = vmull_s16(d26s16, d0s16);
-    q5s32 = vmull_s16(d27s16, d0s16);
-    q2s32 = vmull_s16(d26s16, d1s16);
-    q6s32 = vmull_s16(d27s16, d1s16);
-
-    d30s16 = vdup_n_s16(cospi_26_64);
-    d31s16 = vdup_n_s16(cospi_6_64);
-
-    q4s32 = vmlal_s16(q4s32, d20s16, d1s16);
-    q5s32 = vmlal_s16(q5s32, d21s16, d1s16);
-    q2s32 = vmlsl_s16(q2s32, d20s16, d0s16);
-    q6s32 = vmlsl_s16(q6s32, d21s16, d0s16);
-
-    q0s32 = vmull_s16(d18s16, d30s16);
-    q13s32 = vmull_s16(d19s16, d30s16);
-
-    q0s32 = vmlal_s16(q0s32, d28s16, d31s16);
-    q13s32 = vmlal_s16(q13s32, d29s16, d31s16);
-
-    q10s32 = vmull_s16(d18s16, d31s16);
-    q9s32 = vmull_s16(d19s16, d31s16);
-
-    q10s32 = vmlsl_s16(q10s32, d28s16, d30s16);
-    q9s32 = vmlsl_s16(q9s32, d29s16, d30s16);
-
-    q14s32 = vaddq_s32(q2s32, q10s32);
-    q15s32 = vaddq_s32(q6s32, q9s32);
-    q2s32 = vsubq_s32(q2s32, q10s32);
-    q6s32 = vsubq_s32(q6s32, q9s32);
-
-    d28s16 = vqrshrn_n_s32(q14s32, 14);
-    d29s16 = vqrshrn_n_s32(q15s32, 14);
-    d4s16 = vqrshrn_n_s32(q2s32, 14);
-    d5s16 = vqrshrn_n_s32(q6s32, 14);
-    *q14s16 = vcombine_s16(d28s16, d29s16);
-
-    q9s32 = vaddq_s32(q4s32, q0s32);
-    q10s32 = vaddq_s32(q5s32, q13s32);
-    q4s32 = vsubq_s32(q4s32, q0s32);
-    q5s32 = vsubq_s32(q5s32, q13s32);
-
-    d30s16 = vdup_n_s16(cospi_8_64);
-    d31s16 = vdup_n_s16(cospi_24_64);
-
-    d18s16 = vqrshrn_n_s32(q9s32, 14);
-    d19s16 = vqrshrn_n_s32(q10s32, 14);
-    d8s16 = vqrshrn_n_s32(q4s32, 14);
-    d9s16 = vqrshrn_n_s32(q5s32, 14);
-    *q9s16 = vcombine_s16(d18s16, d19s16);
-
-    q5s32 = vmull_s16(d2s16, d30s16);
-    q6s32 = vmull_s16(d3s16, d30s16);
-    q7s32 = vmull_s16(d2s16, d31s16);
-    q0s32 = vmull_s16(d3s16, d31s16);
-
-    q5s32 = vmlal_s16(q5s32, d6s16, d31s16);
-    q6s32 = vmlal_s16(q6s32, d7s16, d31s16);
-    q7s32 = vmlsl_s16(q7s32, d6s16, d30s16);
-    q0s32 = vmlsl_s16(q0s32, d7s16, d30s16);
-
-    q1s32 = vmull_s16(d4s16, d30s16);
-    q3s32 = vmull_s16(d5s16, d30s16);
-    q10s32 = vmull_s16(d4s16, d31s16);
-    q2s32 = vmull_s16(d5s16, d31s16);
-
-    q1s32 = vmlsl_s16(q1s32, d8s16, d31s16);
-    q3s32 = vmlsl_s16(q3s32, d9s16, d31s16);
-    q10s32 = vmlal_s16(q10s32, d8s16, d30s16);
-    q2s32 = vmlal_s16(q2s32, d9s16, d30s16);
-
-    *q8s16 = vaddq_s16(*q11s16, *q9s16);
-    *q11s16 = vsubq_s16(*q11s16, *q9s16);
-    q4s16 = vaddq_s16(*q12s16, *q14s16);
-    *q12s16 = vsubq_s16(*q12s16, *q14s16);
-
-    q14s32 = vaddq_s32(q5s32, q1s32);
-    q15s32 = vaddq_s32(q6s32, q3s32);
-    q5s32 = vsubq_s32(q5s32, q1s32);
-    q6s32 = vsubq_s32(q6s32, q3s32);
-
-    d18s16 = vqrshrn_n_s32(q14s32, 14);
-    d19s16 = vqrshrn_n_s32(q15s32, 14);
-    d10s16 = vqrshrn_n_s32(q5s32, 14);
-    d11s16 = vqrshrn_n_s32(q6s32, 14);
-    *q9s16 = vcombine_s16(d18s16, d19s16);
-
-    q1s32 = vaddq_s32(q7s32, q10s32);
-    q3s32 = vaddq_s32(q0s32, q2s32);
-    q7s32 = vsubq_s32(q7s32, q10s32);
-    q0s32 = vsubq_s32(q0s32, q2s32);
-
-    d28s16 = vqrshrn_n_s32(q1s32, 14);
-    d29s16 = vqrshrn_n_s32(q3s32, 14);
-    d14s16 = vqrshrn_n_s32(q7s32, 14);
-    d15s16 = vqrshrn_n_s32(q0s32, 14);
-    *q14s16 = vcombine_s16(d28s16, d29s16);
-
-    d30s16 = vdup_n_s16(cospi_16_64);
-
-    d22s16 = vget_low_s16(*q11s16);
-    d23s16 = vget_high_s16(*q11s16);
-    q2s32 = vmull_s16(d22s16, d30s16);
-    q3s32 = vmull_s16(d23s16, d30s16);
-    q13s32 = vmull_s16(d22s16, d30s16);
-    q1s32 = vmull_s16(d23s16, d30s16);
-
-    d24s16 = vget_low_s16(*q12s16);
-    d25s16 = vget_high_s16(*q12s16);
-    q2s32 = vmlal_s16(q2s32, d24s16, d30s16);
-    q3s32 = vmlal_s16(q3s32, d25s16, d30s16);
-    q13s32 = vmlsl_s16(q13s32, d24s16, d30s16);
-    q1s32 = vmlsl_s16(q1s32, d25s16, d30s16);
-
-    d4s16 = vqrshrn_n_s32(q2s32, 14);
-    d5s16 = vqrshrn_n_s32(q3s32, 14);
-    d24s16 = vqrshrn_n_s32(q13s32, 14);
-    d25s16 = vqrshrn_n_s32(q1s32, 14);
-    q2s16 = vcombine_s16(d4s16, d5s16);
-    *q12s16 = vcombine_s16(d24s16, d25s16);
-
-    q13s32 = vmull_s16(d10s16, d30s16);
-    q1s32 = vmull_s16(d11s16, d30s16);
-    q11s32 = vmull_s16(d10s16, d30s16);
-    q0s32 = vmull_s16(d11s16, d30s16);
-
-    q13s32 = vmlal_s16(q13s32, d14s16, d30s16);
-    q1s32 = vmlal_s16(q1s32, d15s16, d30s16);
-    q11s32 = vmlsl_s16(q11s32, d14s16, d30s16);
-    q0s32 = vmlsl_s16(q0s32, d15s16, d30s16);
-
-    d20s16 = vqrshrn_n_s32(q13s32, 14);
-    d21s16 = vqrshrn_n_s32(q1s32, 14);
-    d12s16 = vqrshrn_n_s32(q11s32, 14);
-    d13s16 = vqrshrn_n_s32(q0s32, 14);
-    *q10s16 = vcombine_s16(d20s16, d21s16);
-    q6s16 = vcombine_s16(d12s16, d13s16);
-
-    q5s16 = vdupq_n_s16(0);
-
-    *q9s16  = vsubq_s16(q5s16, *q9s16);
-    *q11s16 = vsubq_s16(q5s16, q2s16);
-    *q13s16 = vsubq_s16(q5s16, q6s16);
-    *q15s16 = vsubq_s16(q5s16, q4s16);
-    return;
-}
-
-void vp9_iht8x8_64_add_neon(const tran_low_t *input, uint8_t *dest,
-                            int dest_stride, int tx_type) {
-    int i;
-    uint8_t *d1, *d2;
-    uint8x8_t d0u8, d1u8, d2u8, d3u8;
-    uint64x1_t d0u64, d1u64, d2u64, d3u64;
-    int16x8_t q8s16, q9s16, q10s16, q11s16, q12s16, q13s16, q14s16, q15s16;
-    uint16x8_t q8u16, q9u16, q10u16, q11u16;
-
-    q8s16  = vld1q_s16(input);
-    q9s16  = vld1q_s16(input + 8);
-    q10s16 = vld1q_s16(input + 8 * 2);
-    q11s16 = vld1q_s16(input + 8 * 3);
-    q12s16 = vld1q_s16(input + 8 * 4);
-    q13s16 = vld1q_s16(input + 8 * 5);
-    q14s16 = vld1q_s16(input + 8 * 6);
-    q15s16 = vld1q_s16(input + 8 * 7);
-
-    TRANSPOSE8X8(&q8s16, &q9s16, &q10s16, &q11s16,
-                 &q12s16, &q13s16, &q14s16, &q15s16);
-
-    switch (tx_type) {
-      case 0:  // idct_idct is not supported. Fall back to C
-        vp9_iht8x8_64_add_c(input, dest, dest_stride, tx_type);
-        return;
-        break;
-      case 1:  // iadst_idct
-        // generate IDCT constants
-        // GENERATE_IDCT_CONSTANTS
-
-        // first transform rows
-        IDCT8x8_1D(&q8s16, &q9s16, &q10s16, &q11s16,
-                   &q12s16, &q13s16, &q14s16, &q15s16);
-
-        // transpose the matrix
-        TRANSPOSE8X8(&q8s16, &q9s16, &q10s16, &q11s16,
-                     &q12s16, &q13s16, &q14s16, &q15s16);
-
-        // generate IADST constants
-        // GENERATE_IADST_CONSTANTS
-
-        // then transform columns
-        IADST8X8_1D(&q8s16, &q9s16, &q10s16, &q11s16,
-                    &q12s16, &q13s16, &q14s16, &q15s16);
-        break;
-      case 2:  // idct_iadst
-        // generate IADST constants
-        // GENERATE_IADST_CONSTANTS
-
-        // first transform rows
-        IADST8X8_1D(&q8s16, &q9s16, &q10s16, &q11s16,
-                    &q12s16, &q13s16, &q14s16, &q15s16);
-
-        // transpose the matrix
-        TRANSPOSE8X8(&q8s16, &q9s16, &q10s16, &q11s16,
-                     &q12s16, &q13s16, &q14s16, &q15s16);
-
-        // generate IDCT constants
-        // GENERATE_IDCT_CONSTANTS
-
-        // then transform columns
-        IDCT8x8_1D(&q8s16, &q9s16, &q10s16, &q11s16,
-                   &q12s16, &q13s16, &q14s16, &q15s16);
-        break;
-      case 3:  // iadst_iadst
-        // generate IADST constants
-        // GENERATE_IADST_CONSTANTS
-
-        // first transform rows
-        IADST8X8_1D(&q8s16, &q9s16, &q10s16, &q11s16,
-                    &q12s16, &q13s16, &q14s16, &q15s16);
-
-        // transpose the matrix
-        TRANSPOSE8X8(&q8s16, &q9s16, &q10s16, &q11s16,
-                     &q12s16, &q13s16, &q14s16, &q15s16);
-
-        // then transform columns
-        IADST8X8_1D(&q8s16, &q9s16, &q10s16, &q11s16,
-                    &q12s16, &q13s16, &q14s16, &q15s16);
-        break;
-      default:  // iadst_idct
-        assert(0);
-        break;
-    }
-
-    q8s16 = vrshrq_n_s16(q8s16, 5);
-    q9s16 = vrshrq_n_s16(q9s16, 5);
-    q10s16 = vrshrq_n_s16(q10s16, 5);
-    q11s16 = vrshrq_n_s16(q11s16, 5);
-    q12s16 = vrshrq_n_s16(q12s16, 5);
-    q13s16 = vrshrq_n_s16(q13s16, 5);
-    q14s16 = vrshrq_n_s16(q14s16, 5);
-    q15s16 = vrshrq_n_s16(q15s16, 5);
-
-    for (d1 = d2 = dest, i = 0; i < 2; i++) {
-        if (i != 0) {
-            q8s16 = q12s16;
-            q9s16 = q13s16;
-            q10s16 = q14s16;
-            q11s16 = q15s16;
-        }
-
-        d0u64 = vld1_u64((uint64_t *)d1);
-        d1 += dest_stride;
-        d1u64 = vld1_u64((uint64_t *)d1);
-        d1 += dest_stride;
-        d2u64 = vld1_u64((uint64_t *)d1);
-        d1 += dest_stride;
-        d3u64 = vld1_u64((uint64_t *)d1);
-        d1 += dest_stride;
-
-        q8u16  = vaddw_u8(vreinterpretq_u16_s16(q8s16),
-                          vreinterpret_u8_u64(d0u64));
-        q9u16  = vaddw_u8(vreinterpretq_u16_s16(q9s16),
-                          vreinterpret_u8_u64(d1u64));
-        q10u16 = vaddw_u8(vreinterpretq_u16_s16(q10s16),
-                          vreinterpret_u8_u64(d2u64));
-        q11u16 = vaddw_u8(vreinterpretq_u16_s16(q11s16),
-                          vreinterpret_u8_u64(d3u64));
-
-        d0u8 = vqmovun_s16(vreinterpretq_s16_u16(q8u16));
-        d1u8 = vqmovun_s16(vreinterpretq_s16_u16(q9u16));
-        d2u8 = vqmovun_s16(vreinterpretq_s16_u16(q10u16));
-        d3u8 = vqmovun_s16(vreinterpretq_s16_u16(q11u16));
-
-        vst1_u64((uint64_t *)d2, vreinterpret_u64_u8(d0u8));
-        d2 += dest_stride;
-        vst1_u64((uint64_t *)d2, vreinterpret_u64_u8(d1u8));
-        d2 += dest_stride;
-        vst1_u64((uint64_t *)d2, vreinterpret_u64_u8(d2u8));
-        d2 += dest_stride;
-        vst1_u64((uint64_t *)d2, vreinterpret_u64_u8(d3u8));
-        d2 += dest_stride;
-    }
-    return;
-}
diff --git a/vp9/common/mips/dspr2/vp9_itrans16_dspr2.c b/vp9/common/mips/dspr2/vp9_itrans16_dspr2.c
deleted file mode 100644 (file)
index 6ca83a0..0000000
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- *  Copyright (c) 2013 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.
- */
-
-#include <assert.h>
-#include <stdio.h>
-
-#include "./vpx_config.h"
-#include "./vp9_rtcd.h"
-#include "vp9/common/vp9_common.h"
-#include "vp9/common/vp9_blockd.h"
-#include "vp9/common/vp9_idct.h"
-#include "vpx_dsp/mips/inv_txfm_dspr2.h"
-#include "vpx_dsp/txfm_common.h"
-#include "vpx_ports/mem.h"
-
-#if HAVE_DSPR2
-void vp9_iht16x16_256_add_dspr2(const int16_t *input, uint8_t *dest,
-                                int pitch, int tx_type) {
-  int i, j;
-  DECLARE_ALIGNED(32, int16_t,  out[16 * 16]);
-  int16_t *outptr = out;
-  int16_t temp_out[16];
-  uint32_t pos = 45;
-
-  /* bit positon for extract from acc */
-  __asm__ __volatile__ (
-    "wrdsp    %[pos],    1    \n\t"
-    :
-    : [pos] "r" (pos)
-  );
-
-  switch (tx_type) {
-    case DCT_DCT:     // DCT in both horizontal and vertical
-      idct16_rows_dspr2(input, outptr, 16);
-      idct16_cols_add_blk_dspr2(out, dest, pitch);
-      break;
-    case ADST_DCT:    // ADST in vertical, DCT in horizontal
-      idct16_rows_dspr2(input, outptr, 16);
-
-      outptr = out;
-
-      for (i = 0; i < 16; ++i) {
-        iadst16_dspr2(outptr, temp_out);
-
-        for (j = 0; j < 16; ++j)
-          dest[j * pitch + i] =
-                    clip_pixel(ROUND_POWER_OF_TWO(temp_out[j], 6)
-                                      + dest[j * pitch + i]);
-        outptr += 16;
-      }
-      break;
-    case DCT_ADST:    // DCT in vertical, ADST in horizontal
-    {
-      int16_t temp_in[16 * 16];
-
-      for (i = 0; i < 16; ++i) {
-        /* prefetch row */
-        prefetch_load((const uint8_t *)(input + 16));
-
-        iadst16_dspr2(input, outptr);
-        input += 16;
-        outptr += 16;
-      }
-
-      for (i = 0; i < 16; ++i)
-        for (j = 0; j < 16; ++j)
-            temp_in[j * 16 + i] = out[i * 16 + j];
-
-      idct16_cols_add_blk_dspr2(temp_in, dest, pitch);
-    }
-    break;
-    case ADST_ADST:   // ADST in both directions
-    {
-      int16_t temp_in[16];
-
-      for (i = 0; i < 16; ++i) {
-        /* prefetch row */
-        prefetch_load((const uint8_t *)(input + 16));
-
-        iadst16_dspr2(input, outptr);
-        input += 16;
-        outptr += 16;
-      }
-
-      for (i = 0; i < 16; ++i) {
-        for (j = 0; j < 16; ++j)
-          temp_in[j] = out[j * 16 + i];
-        iadst16_dspr2(temp_in, temp_out);
-        for (j = 0; j < 16; ++j)
-          dest[j * pitch + i] =
-                    clip_pixel(ROUND_POWER_OF_TWO(temp_out[j], 6)
-                                      + dest[j * pitch + i]);
-      }
-    }
-    break;
-    default:
-      printf("vp9_short_iht16x16_add_dspr2 : Invalid tx_type\n");
-      break;
-  }
-}
-#endif  // #if HAVE_DSPR2
diff --git a/vp9/common/mips/dspr2/vp9_itrans4_dspr2.c b/vp9/common/mips/dspr2/vp9_itrans4_dspr2.c
deleted file mode 100644 (file)
index c10979b..0000000
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- *  Copyright (c) 2013 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.
- */
-
-#include <assert.h>
-#include <stdio.h>
-
-#include "./vpx_config.h"
-#include "./vp9_rtcd.h"
-#include "vp9/common/vp9_common.h"
-#include "vp9/common/vp9_blockd.h"
-#include "vp9/common/vp9_idct.h"
-#include "vpx_dsp/mips/inv_txfm_dspr2.h"
-#include "vpx_dsp/txfm_common.h"
-#include "vpx_ports/mem.h"
-
-#if HAVE_DSPR2
-void vp9_iht4x4_16_add_dspr2(const int16_t *input, uint8_t *dest,
-                             int dest_stride, int tx_type) {
-  int i, j;
-  DECLARE_ALIGNED(32, int16_t, out[4 * 4]);
-  int16_t *outptr = out;
-  int16_t temp_in[4 * 4], temp_out[4];
-  uint32_t pos = 45;
-
-  /* bit positon for extract from acc */
-  __asm__ __volatile__ (
-    "wrdsp      %[pos],     1           \n\t"
-    :
-    : [pos] "r" (pos)
-  );
-
-  switch (tx_type) {
-    case DCT_DCT:   // DCT in both horizontal and vertical
-      vpx_idct4_rows_dspr2(input, outptr);
-      vpx_idct4_columns_add_blk_dspr2(&out[0], dest, dest_stride);
-      break;
-    case ADST_DCT:  // ADST in vertical, DCT in horizontal
-      vpx_idct4_rows_dspr2(input, outptr);
-
-      outptr = out;
-
-      for (i = 0; i < 4; ++i) {
-        iadst4_dspr2(outptr, temp_out);
-
-        for (j = 0; j < 4; ++j)
-          dest[j * dest_stride + i] =
-                    clip_pixel(ROUND_POWER_OF_TWO(temp_out[j], 4)
-                                      + dest[j * dest_stride + i]);
-
-        outptr += 4;
-      }
-      break;
-    case DCT_ADST:  // DCT in vertical, ADST in horizontal
-      for (i = 0; i < 4; ++i) {
-        iadst4_dspr2(input, outptr);
-        input  += 4;
-        outptr += 4;
-      }
-
-      for (i = 0; i < 4; ++i) {
-        for (j = 0; j < 4; ++j) {
-          temp_in[i * 4 + j] = out[j * 4 + i];
-        }
-      }
-      vpx_idct4_columns_add_blk_dspr2(&temp_in[0], dest, dest_stride);
-      break;
-    case ADST_ADST:  // ADST in both directions
-      for (i = 0; i < 4; ++i) {
-        iadst4_dspr2(input, outptr);
-        input  += 4;
-        outptr += 4;
-      }
-
-      for (i = 0; i < 4; ++i) {
-        for (j = 0; j < 4; ++j)
-          temp_in[j] = out[j * 4 + i];
-        iadst4_dspr2(temp_in, temp_out);
-
-        for (j = 0; j < 4; ++j)
-          dest[j * dest_stride + i] =
-                  clip_pixel(ROUND_POWER_OF_TWO(temp_out[j], 4)
-                                      + dest[j * dest_stride + i]);
-      }
-      break;
-    default:
-      printf("vp9_short_iht4x4_add_dspr2 : Invalid tx_type\n");
-      break;
-  }
-}
-#endif  // #if HAVE_DSPR2
diff --git a/vp9/common/mips/dspr2/vp9_itrans8_dspr2.c b/vp9/common/mips/dspr2/vp9_itrans8_dspr2.c
deleted file mode 100644 (file)
index 37f3ca9..0000000
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- *  Copyright (c) 2013 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.
- */
-
-#include <assert.h>
-#include <stdio.h>
-
-#include "./vpx_config.h"
-#include "./vp9_rtcd.h"
-#include "vp9/common/vp9_common.h"
-#include "vp9/common/vp9_blockd.h"
-#include "vpx_dsp/mips/inv_txfm_dspr2.h"
-#include "vpx_dsp/txfm_common.h"
-#include "vpx_ports/mem.h"
-
-#if HAVE_DSPR2
-void vp9_iht8x8_64_add_dspr2(const int16_t *input, uint8_t *dest,
-                             int dest_stride, int tx_type) {
-  int i, j;
-  DECLARE_ALIGNED(32, int16_t, out[8 * 8]);
-  int16_t *outptr = out;
-  int16_t temp_in[8 * 8], temp_out[8];
-  uint32_t pos = 45;
-
-  /* bit positon for extract from acc */
-  __asm__ __volatile__ (
-    "wrdsp    %[pos],    1    \n\t"
-    :
-    : [pos] "r" (pos)
-  );
-
-  switch (tx_type) {
-    case DCT_DCT:     // DCT in both horizontal and vertical
-      idct8_rows_dspr2(input, outptr, 8);
-      idct8_columns_add_blk_dspr2(&out[0], dest, dest_stride);
-      break;
-    case ADST_DCT:    // ADST in vertical, DCT in horizontal
-      idct8_rows_dspr2(input, outptr, 8);
-
-      for (i = 0; i < 8; ++i) {
-        iadst8_dspr2(&out[i * 8], temp_out);
-
-        for (j = 0; j < 8; ++j)
-          dest[j * dest_stride + i] =
-                    clip_pixel(ROUND_POWER_OF_TWO(temp_out[j], 5)
-                                      + dest[j * dest_stride + i]);
-      }
-      break;
-    case DCT_ADST:    // DCT in vertical, ADST in horizontal
-      for (i = 0; i < 8; ++i) {
-        iadst8_dspr2(input, outptr);
-        input += 8;
-        outptr += 8;
-      }
-
-      for (i = 0; i < 8; ++i) {
-        for (j = 0; j < 8; ++j) {
-          temp_in[i * 8 + j] = out[j * 8 + i];
-        }
-      }
-      idct8_columns_add_blk_dspr2(&temp_in[0], dest, dest_stride);
-      break;
-    case ADST_ADST:   // ADST in both directions
-      for (i = 0; i < 8; ++i) {
-        iadst8_dspr2(input, outptr);
-        input += 8;
-        outptr += 8;
-      }
-
-      for (i = 0; i < 8; ++i) {
-        for (j = 0; j < 8; ++j)
-          temp_in[j] = out[j * 8 + i];
-
-        iadst8_dspr2(temp_in, temp_out);
-
-        for (j = 0; j < 8; ++j)
-          dest[j * dest_stride + i] =
-                clip_pixel(ROUND_POWER_OF_TWO(temp_out[j], 5)
-                                      + dest[j * dest_stride + i]);
-      }
-      break;
-    default:
-      printf("vp9_short_iht8x8_add_dspr2 : Invalid tx_type\n");
-      break;
-  }
-}
-#endif  // #if HAVE_DSPR2
diff --git a/vp9/common/mips/msa/vp9_idct16x16_msa.c b/vp9/common/mips/msa/vp9_idct16x16_msa.c
deleted file mode 100644 (file)
index 5adf0aa..0000000
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- *  Copyright (c) 2015 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.
- */
-
-#include <assert.h>
-
-#include "vp9/common/vp9_enums.h"
-#include "vpx_dsp/mips/inv_txfm_msa.h"
-
-void vp9_iht16x16_256_add_msa(const int16_t *input, uint8_t *dst,
-                              int32_t dst_stride, int32_t tx_type) {
-  int32_t i;
-  DECLARE_ALIGNED(32, int16_t, out[16 * 16]);
-  int16_t *out_ptr = &out[0];
-
-  switch (tx_type) {
-    case DCT_DCT:
-      /* transform rows */
-      for (i = 0; i < 2; ++i) {
-        /* process 16 * 8 block */
-        vpx_idct16_1d_rows_msa((input + (i << 7)), (out_ptr + (i << 7)));
-      }
-
-      /* transform columns */
-      for (i = 0; i < 2; ++i) {
-        /* process 8 * 16 block */
-        vpx_idct16_1d_columns_addblk_msa((out_ptr + (i << 3)), (dst + (i << 3)),
-                                         dst_stride);
-      }
-      break;
-    case ADST_DCT:
-      /* transform rows */
-      for (i = 0; i < 2; ++i) {
-        /* process 16 * 8 block */
-        vpx_idct16_1d_rows_msa((input + (i << 7)), (out_ptr + (i << 7)));
-      }
-
-      /* transform columns */
-      for (i = 0; i < 2; ++i) {
-        vpx_iadst16_1d_columns_addblk_msa((out_ptr + (i << 3)),
-                                          (dst + (i << 3)), dst_stride);
-      }
-      break;
-    case DCT_ADST:
-      /* transform rows */
-      for (i = 0; i < 2; ++i) {
-        /* process 16 * 8 block */
-        vpx_iadst16_1d_rows_msa((input + (i << 7)), (out_ptr + (i << 7)));
-      }
-
-      /* transform columns */
-      for (i = 0; i < 2; ++i) {
-        /* process 8 * 16 block */
-        vpx_idct16_1d_columns_addblk_msa((out_ptr + (i << 3)), (dst + (i << 3)),
-                                         dst_stride);
-      }
-      break;
-    case ADST_ADST:
-      /* transform rows */
-      for (i = 0; i < 2; ++i) {
-        /* process 16 * 8 block */
-        vpx_iadst16_1d_rows_msa((input + (i << 7)), (out_ptr + (i << 7)));
-      }
-
-      /* transform columns */
-      for (i = 0; i < 2; ++i) {
-        vpx_iadst16_1d_columns_addblk_msa((out_ptr + (i << 3)),
-                                          (dst + (i << 3)), dst_stride);
-      }
-      break;
-    default:
-      assert(0);
-      break;
-  }
-}
diff --git a/vp9/common/mips/msa/vp9_idct4x4_msa.c b/vp9/common/mips/msa/vp9_idct4x4_msa.c
deleted file mode 100644 (file)
index 75977b1..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- *  Copyright (c) 2015 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.
- */
-
-#include <assert.h>
-
-#include "vp9/common/vp9_enums.h"
-#include "vpx_dsp/mips/inv_txfm_msa.h"
-
-void vp9_iht4x4_16_add_msa(const int16_t *input, uint8_t *dst,
-                           int32_t dst_stride, int32_t tx_type) {
-  v8i16 in0, in1, in2, in3;
-
-  /* load vector elements of 4x4 block */
-  LD4x4_SH(input, in0, in1, in2, in3);
-  TRANSPOSE4x4_SH_SH(in0, in1, in2, in3, in0, in1, in2, in3);
-
-  switch (tx_type) {
-    case DCT_DCT:
-      /* DCT in horizontal */
-      VP9_IDCT4x4(in0, in1, in2, in3, in0, in1, in2, in3);
-      /* DCT in vertical */
-      TRANSPOSE4x4_SH_SH(in0, in1, in2, in3, in0, in1, in2, in3);
-      VP9_IDCT4x4(in0, in1, in2, in3, in0, in1, in2, in3);
-      break;
-    case ADST_DCT:
-      /* DCT in horizontal */
-      VP9_IDCT4x4(in0, in1, in2, in3, in0, in1, in2, in3);
-      /* ADST in vertical */
-      TRANSPOSE4x4_SH_SH(in0, in1, in2, in3, in0, in1, in2, in3);
-      VP9_IADST4x4(in0, in1, in2, in3, in0, in1, in2, in3);
-      break;
-    case DCT_ADST:
-      /* ADST in horizontal */
-      VP9_IADST4x4(in0, in1, in2, in3, in0, in1, in2, in3);
-      /* DCT in vertical */
-      TRANSPOSE4x4_SH_SH(in0, in1, in2, in3, in0, in1, in2, in3);
-      VP9_IDCT4x4(in0, in1, in2, in3, in0, in1, in2, in3);
-      break;
-    case ADST_ADST:
-      /* ADST in horizontal */
-      VP9_IADST4x4(in0, in1, in2, in3, in0, in1, in2, in3);
-      /* ADST in vertical */
-      TRANSPOSE4x4_SH_SH(in0, in1, in2, in3, in0, in1, in2, in3);
-      VP9_IADST4x4(in0, in1, in2, in3, in0, in1, in2, in3);
-      break;
-    default:
-      assert(0);
-      break;
-  }
-
-  /* final rounding (add 2^3, divide by 2^4) and shift */
-  SRARI_H4_SH(in0, in1, in2, in3, 4);
-  /* add block and store 4x4 */
-  ADDBLK_ST4x4_UB(in0, in1, in2, in3, dst, dst_stride);
-}
diff --git a/vp9/common/mips/msa/vp9_idct8x8_msa.c b/vp9/common/mips/msa/vp9_idct8x8_msa.c
deleted file mode 100644 (file)
index 65d2993..0000000
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- *  Copyright (c) 2015 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.
- */
-
-#include <assert.h>
-
-#include "vp9/common/vp9_enums.h"
-#include "vpx_dsp/mips/inv_txfm_msa.h"
-
-void vp9_iht8x8_64_add_msa(const int16_t *input, uint8_t *dst,
-                           int32_t dst_stride, int32_t tx_type) {
-  v8i16 in0, in1, in2, in3, in4, in5, in6, in7;
-
-  /* load vector elements of 8x8 block */
-  LD_SH8(input, 8, in0, in1, in2, in3, in4, in5, in6, in7);
-
-  TRANSPOSE8x8_SH_SH(in0, in1, in2, in3, in4, in5, in6, in7,
-                     in0, in1, in2, in3, in4, in5, in6, in7);
-
-  switch (tx_type) {
-    case DCT_DCT:
-      /* DCT in horizontal */
-      VP9_IDCT8x8_1D(in0, in1, in2, in3, in4, in5, in6, in7,
-                     in0, in1, in2, in3, in4, in5, in6, in7);
-      /* DCT in vertical */
-      TRANSPOSE8x8_SH_SH(in0, in1, in2, in3, in4, in5, in6, in7,
-                         in0, in1, in2, in3, in4, in5, in6, in7);
-      VP9_IDCT8x8_1D(in0, in1, in2, in3, in4, in5, in6, in7,
-                     in0, in1, in2, in3, in4, in5, in6, in7);
-      break;
-    case ADST_DCT:
-      /* DCT in horizontal */
-      VP9_IDCT8x8_1D(in0, in1, in2, in3, in4, in5, in6, in7,
-                     in0, in1, in2, in3, in4, in5, in6, in7);
-      /* ADST in vertical */
-      TRANSPOSE8x8_SH_SH(in0, in1, in2, in3, in4, in5, in6, in7,
-                         in0, in1, in2, in3, in4, in5, in6, in7);
-      VP9_ADST8(in0, in1, in2, in3, in4, in5, in6, in7,
-                in0, in1, in2, in3, in4, in5, in6, in7);
-      break;
-    case DCT_ADST:
-      /* ADST in horizontal */
-      VP9_ADST8(in0, in1, in2, in3, in4, in5, in6, in7,
-                in0, in1, in2, in3, in4, in5, in6, in7);
-      /* DCT in vertical */
-      TRANSPOSE8x8_SH_SH(in0, in1, in2, in3, in4, in5, in6, in7,
-                         in0, in1, in2, in3, in4, in5, in6, in7);
-      VP9_IDCT8x8_1D(in0, in1, in2, in3, in4, in5, in6, in7,
-                     in0, in1, in2, in3, in4, in5, in6, in7);
-      break;
-    case ADST_ADST:
-      /* ADST in horizontal */
-      VP9_ADST8(in0, in1, in2, in3, in4, in5, in6, in7,
-                in0, in1, in2, in3, in4, in5, in6, in7);
-      /* ADST in vertical */
-      TRANSPOSE8x8_SH_SH(in0, in1, in2, in3, in4, in5, in6, in7,
-                         in0, in1, in2, in3, in4, in5, in6, in7);
-      VP9_ADST8(in0, in1, in2, in3, in4, in5, in6, in7,
-                in0, in1, in2, in3, in4, in5, in6, in7);
-      break;
-    default:
-      assert(0);
-      break;
-  }
-
-  /* final rounding (add 2^4, divide by 2^5) and shift */
-  SRARI_H4_SH(in0, in1, in2, in3, 5);
-  SRARI_H4_SH(in4, in5, in6, in7, 5);
-
-  /* add block and store 8x8 */
-  VP9_ADDBLK_ST8x4_UB(dst, dst_stride, in0, in1, in2, in3);
-  dst += (4 * dst_stride);
-  VP9_ADDBLK_ST8x4_UB(dst, dst_stride, in4, in5, in6, in7);
-}
diff --git a/vp9/common/mips/msa/vp9_mfqe_msa.c b/vp9/common/mips/msa/vp9_mfqe_msa.c
deleted file mode 100644 (file)
index 7257cd6..0000000
+++ /dev/null
@@ -1,137 +0,0 @@
-/*
- *  Copyright (c) 2015 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.
- */
-
-#include "./vp9_rtcd.h"
-#include "vp9/common/vp9_onyxc_int.h"
-#include "vpx_dsp/mips/macros_msa.h"
-
-static void filter_by_weight8x8_msa(const uint8_t *src_ptr, int32_t src_stride,
-                                    uint8_t *dst_ptr, int32_t dst_stride,
-                                    int32_t src_weight) {
-  int32_t dst_weight = (1 << MFQE_PRECISION) - src_weight;
-  int32_t row;
-  uint64_t src0_d, src1_d, dst0_d, dst1_d;
-  v16i8 src0 = { 0 };
-  v16i8 src1 = { 0 };
-  v16i8 dst0 = { 0 };
-  v16i8 dst1 = { 0 };
-  v8i16 src_wt, dst_wt, res_h_r, res_h_l, src_r, src_l, dst_r, dst_l;
-
-  src_wt = __msa_fill_h(src_weight);
-  dst_wt = __msa_fill_h(dst_weight);
-
-  for (row = 2; row--;) {
-    LD2(src_ptr, src_stride, src0_d, src1_d);
-    src_ptr += (2 * src_stride);
-    LD2(dst_ptr, dst_stride, dst0_d, dst1_d);
-    INSERT_D2_SB(src0_d, src1_d, src0);
-    INSERT_D2_SB(dst0_d, dst1_d, dst0);
-
-    LD2(src_ptr, src_stride, src0_d, src1_d);
-    src_ptr += (2 * src_stride);
-    LD2((dst_ptr + 2 * dst_stride), dst_stride, dst0_d, dst1_d);
-    INSERT_D2_SB(src0_d, src1_d, src1);
-    INSERT_D2_SB(dst0_d, dst1_d, dst1);
-
-    UNPCK_UB_SH(src0, src_r, src_l);
-    UNPCK_UB_SH(dst0, dst_r, dst_l);
-    res_h_r = (src_r * src_wt);
-    res_h_r += (dst_r * dst_wt);
-    res_h_l = (src_l * src_wt);
-    res_h_l += (dst_l * dst_wt);
-    SRARI_H2_SH(res_h_r, res_h_l, MFQE_PRECISION);
-    dst0 = (v16i8)__msa_pckev_b((v16i8)res_h_l, (v16i8)res_h_r);
-    ST8x2_UB(dst0, dst_ptr, dst_stride);
-    dst_ptr += (2 * dst_stride);
-
-    UNPCK_UB_SH(src1, src_r, src_l);
-    UNPCK_UB_SH(dst1, dst_r, dst_l);
-    res_h_r = (src_r * src_wt);
-    res_h_r += (dst_r * dst_wt);
-    res_h_l = (src_l * src_wt);
-    res_h_l += (dst_l * dst_wt);
-    SRARI_H2_SH(res_h_r, res_h_l, MFQE_PRECISION);
-    dst1 = (v16i8)__msa_pckev_b((v16i8)res_h_l, (v16i8)res_h_r);
-    ST8x2_UB(dst1, dst_ptr, dst_stride);
-    dst_ptr += (2 * dst_stride);
-  }
-}
-
-static void filter_by_weight16x16_msa(const uint8_t *src_ptr,
-                                      int32_t src_stride,
-                                      uint8_t *dst_ptr,
-                                      int32_t dst_stride,
-                                      int32_t src_weight) {
-  int32_t dst_weight = (1 << MFQE_PRECISION) - src_weight;
-  int32_t row;
-  v16i8 src0, src1, src2, src3, dst0, dst1, dst2, dst3;
-  v8i16 src_wt, dst_wt, res_h_r, res_h_l, src_r, src_l, dst_r, dst_l;
-
-  src_wt = __msa_fill_h(src_weight);
-  dst_wt = __msa_fill_h(dst_weight);
-
-  for (row = 4; row--;) {
-    LD_SB4(src_ptr, src_stride, src0, src1, src2, src3);
-    src_ptr += (4 * src_stride);
-    LD_SB4(dst_ptr, dst_stride, dst0, dst1, dst2, dst3);
-
-    UNPCK_UB_SH(src0, src_r, src_l);
-    UNPCK_UB_SH(dst0, dst_r, dst_l);
-    res_h_r = (src_r * src_wt);
-    res_h_r += (dst_r * dst_wt);
-    res_h_l = (src_l * src_wt);
-    res_h_l += (dst_l * dst_wt);
-    SRARI_H2_SH(res_h_r, res_h_l, MFQE_PRECISION);
-    PCKEV_ST_SB(res_h_r, res_h_l, dst_ptr);
-    dst_ptr += dst_stride;
-
-    UNPCK_UB_SH(src1, src_r, src_l);
-    UNPCK_UB_SH(dst1, dst_r, dst_l);
-    res_h_r = (src_r * src_wt);
-    res_h_r += (dst_r * dst_wt);
-    res_h_l = (src_l * src_wt);
-    res_h_l += (dst_l * dst_wt);
-    SRARI_H2_SH(res_h_r, res_h_l, MFQE_PRECISION);
-    PCKEV_ST_SB(res_h_r, res_h_l, dst_ptr);
-    dst_ptr += dst_stride;
-
-    UNPCK_UB_SH(src2, src_r, src_l);
-    UNPCK_UB_SH(dst2, dst_r, dst_l);
-    res_h_r = (src_r * src_wt);
-    res_h_r += (dst_r * dst_wt);
-    res_h_l = (src_l * src_wt);
-    res_h_l += (dst_l * dst_wt);
-    SRARI_H2_SH(res_h_r, res_h_l, MFQE_PRECISION);
-    PCKEV_ST_SB(res_h_r, res_h_l, dst_ptr);
-    dst_ptr += dst_stride;
-
-    UNPCK_UB_SH(src3, src_r, src_l);
-    UNPCK_UB_SH(dst3, dst_r, dst_l);
-    res_h_r = (src_r * src_wt);
-    res_h_r += (dst_r * dst_wt);
-    res_h_l = (src_l * src_wt);
-    res_h_l += (dst_l * dst_wt);
-    SRARI_H2_SH(res_h_r, res_h_l, MFQE_PRECISION);
-    PCKEV_ST_SB(res_h_r, res_h_l, dst_ptr);
-    dst_ptr += dst_stride;
-  }
-}
-
-void vp9_filter_by_weight8x8_msa(const uint8_t *src, int src_stride,
-                                 uint8_t *dst, int dst_stride,
-                                 int src_weight) {
-  filter_by_weight8x8_msa(src, src_stride, dst, dst_stride, src_weight);
-}
-
-void vp9_filter_by_weight16x16_msa(const uint8_t *src, int src_stride,
-                                   uint8_t *dst, int dst_stride,
-                                   int src_weight) {
-  filter_by_weight16x16_msa(src, src_stride, dst, dst_stride, src_weight);
-}
diff --git a/vp9/common/vp9_alloccommon.c b/vp9/common/vp9_alloccommon.c
deleted file mode 100644 (file)
index b4b120b..0000000
+++ /dev/null
@@ -1,203 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#include "./vpx_config.h"
-#include "vpx_mem/vpx_mem.h"
-
-#include "vp9/common/vp9_alloccommon.h"
-#include "vp9/common/vp9_blockd.h"
-#include "vp9/common/vp9_entropymode.h"
-#include "vp9/common/vp9_entropymv.h"
-#include "vp9/common/vp9_onyxc_int.h"
-
-// TODO(hkuang): Don't need to lock the whole pool after implementing atomic
-// frame reference count.
-void lock_buffer_pool(BufferPool *const pool) {
-#if CONFIG_MULTITHREAD
-  pthread_mutex_lock(&pool->pool_mutex);
-#else
-  (void)pool;
-#endif
-}
-
-void unlock_buffer_pool(BufferPool *const pool) {
-#if CONFIG_MULTITHREAD
-  pthread_mutex_unlock(&pool->pool_mutex);
-#else
-  (void)pool;
-#endif
-}
-
-void vp9_set_mb_mi(VP9_COMMON *cm, int width, int height) {
-  const int aligned_width = ALIGN_POWER_OF_TWO(width, MI_SIZE_LOG2);
-  const int aligned_height = ALIGN_POWER_OF_TWO(height, MI_SIZE_LOG2);
-
-  cm->mi_cols = aligned_width >> MI_SIZE_LOG2;
-  cm->mi_rows = aligned_height >> MI_SIZE_LOG2;
-  cm->mi_stride = calc_mi_size(cm->mi_cols);
-
-  cm->mb_cols = (cm->mi_cols + 1) >> 1;
-  cm->mb_rows = (cm->mi_rows + 1) >> 1;
-  cm->MBs = cm->mb_rows * cm->mb_cols;
-}
-
-static int alloc_seg_map(VP9_COMMON *cm, int seg_map_size) {
-  int i;
-
-  for (i = 0; i < NUM_PING_PONG_BUFFERS; ++i) {
-    cm->seg_map_array[i] = (uint8_t *)vpx_calloc(seg_map_size, 1);
-    if (cm->seg_map_array[i] == NULL)
-      return 1;
-  }
-  cm->seg_map_alloc_size = seg_map_size;
-
-  // Init the index.
-  cm->seg_map_idx = 0;
-  cm->prev_seg_map_idx = 1;
-
-  cm->current_frame_seg_map = cm->seg_map_array[cm->seg_map_idx];
-  if (!cm->frame_parallel_decode)
-    cm->last_frame_seg_map = cm->seg_map_array[cm->prev_seg_map_idx];
-
-  return 0;
-}
-
-static void free_seg_map(VP9_COMMON *cm) {
-  int i;
-
-  for (i = 0; i < NUM_PING_PONG_BUFFERS; ++i) {
-    vpx_free(cm->seg_map_array[i]);
-    cm->seg_map_array[i] = NULL;
-  }
-
-  cm->current_frame_seg_map = NULL;
-
-  if (!cm->frame_parallel_decode) {
-    cm->last_frame_seg_map = NULL;
-  }
-}
-
-void vp9_free_ref_frame_buffers(BufferPool *pool) {
-  int i;
-
-  for (i = 0; i < FRAME_BUFFERS; ++i) {
-    if (pool->frame_bufs[i].ref_count > 0 &&
-        pool->frame_bufs[i].raw_frame_buffer.data != NULL) {
-      pool->release_fb_cb(pool->cb_priv, &pool->frame_bufs[i].raw_frame_buffer);
-      pool->frame_bufs[i].ref_count = 0;
-    }
-    vpx_free(pool->frame_bufs[i].mvs);
-    pool->frame_bufs[i].mvs = NULL;
-    vpx_free_frame_buffer(&pool->frame_bufs[i].buf);
-  }
-}
-
-void vp9_free_postproc_buffers(VP9_COMMON *cm) {
-#if CONFIG_VP9_POSTPROC
-  vpx_free_frame_buffer(&cm->post_proc_buffer);
-  vpx_free_frame_buffer(&cm->post_proc_buffer_int);
-  vpx_free(cm->postproc_state.limits);
-  cm->postproc_state.limits = 0;
-#else
-  (void)cm;
-#endif
-}
-
-void vp9_free_context_buffers(VP9_COMMON *cm) {
-  cm->free_mi(cm);
-  free_seg_map(cm);
-  vpx_free(cm->above_context);
-  cm->above_context = NULL;
-  vpx_free(cm->above_seg_context);
-  cm->above_seg_context = NULL;
-  vpx_free(cm->lf.lfm);
-  cm->lf.lfm = NULL;
-}
-
-
-int vp9_alloc_loop_filter(VP9_COMMON *cm) {
-  vpx_free(cm->lf.lfm);
-  // Each lfm holds bit masks for all the 8x8 blocks in a 64x64 region.  The
-  // stride and rows are rounded up / truncated to a multiple of 8.
-  cm->lf.lfm_stride = (cm->mi_cols + (MI_BLOCK_SIZE - 1)) >> 3;
-  cm->lf.lfm = (LOOP_FILTER_MASK *)vpx_calloc(
-      ((cm->mi_rows + (MI_BLOCK_SIZE - 1)) >> 3) * cm->lf.lfm_stride,
-      sizeof(*cm->lf.lfm));
-  if (!cm->lf.lfm)
-    return 1;
-  return 0;
-}
-
-int vp9_alloc_context_buffers(VP9_COMMON *cm, int width, int height) {
-  int new_mi_size;
-
-  vp9_set_mb_mi(cm, width, height);
-  new_mi_size = cm->mi_stride * calc_mi_size(cm->mi_rows);
-  if (cm->mi_alloc_size < new_mi_size) {
-    cm->free_mi(cm);
-    if (cm->alloc_mi(cm, new_mi_size))
-      goto fail;
-  }
-
-  if (cm->seg_map_alloc_size < cm->mi_rows * cm->mi_cols) {
-    // Create the segmentation map structure and set to 0.
-    free_seg_map(cm);
-    if (alloc_seg_map(cm, cm->mi_rows * cm->mi_cols))
-      goto fail;
-  }
-
-  if (cm->above_context_alloc_cols < cm->mi_cols) {
-    vpx_free(cm->above_context);
-    cm->above_context = (ENTROPY_CONTEXT *)vpx_calloc(
-        2 * mi_cols_aligned_to_sb(cm->mi_cols) * MAX_MB_PLANE,
-        sizeof(*cm->above_context));
-    if (!cm->above_context) goto fail;
-
-    vpx_free(cm->above_seg_context);
-    cm->above_seg_context = (PARTITION_CONTEXT *)vpx_calloc(
-        mi_cols_aligned_to_sb(cm->mi_cols), sizeof(*cm->above_seg_context));
-    if (!cm->above_seg_context) goto fail;
-    cm->above_context_alloc_cols = cm->mi_cols;
-  }
-
-  if (vp9_alloc_loop_filter(cm))
-    goto fail;
-
-  return 0;
-
- fail:
-  vp9_free_context_buffers(cm);
-  return 1;
-}
-
-void vp9_remove_common(VP9_COMMON *cm) {
-  vp9_free_context_buffers(cm);
-
-  vpx_free(cm->fc);
-  cm->fc = NULL;
-  vpx_free(cm->frame_contexts);
-  cm->frame_contexts = NULL;
-}
-
-void vp9_init_context_buffers(VP9_COMMON *cm) {
-  cm->setup_mi(cm);
-  if (cm->last_frame_seg_map && !cm->frame_parallel_decode)
-    memset(cm->last_frame_seg_map, 0, cm->mi_rows * cm->mi_cols);
-}
-
-void vp9_swap_current_and_last_seg_map(VP9_COMMON *cm) {
-  // Swap indices.
-  const int tmp = cm->seg_map_idx;
-  cm->seg_map_idx = cm->prev_seg_map_idx;
-  cm->prev_seg_map_idx = tmp;
-
-  cm->current_frame_seg_map = cm->seg_map_array[cm->seg_map_idx];
-  cm->last_frame_seg_map = cm->seg_map_array[cm->prev_seg_map_idx];
-}
diff --git a/vp9/common/vp9_alloccommon.h b/vp9/common/vp9_alloccommon.h
deleted file mode 100644 (file)
index e53955b..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#ifndef VP9_COMMON_VP9_ALLOCCOMMON_H_
-#define VP9_COMMON_VP9_ALLOCCOMMON_H_
-
-#define INVALID_IDX -1  // Invalid buffer index.
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-struct VP9Common;
-struct BufferPool;
-
-void vp9_remove_common(struct VP9Common *cm);
-
-int vp9_alloc_loop_filter(struct VP9Common *cm);
-int vp9_alloc_context_buffers(struct VP9Common *cm, int width, int height);
-void vp9_init_context_buffers(struct VP9Common *cm);
-void vp9_free_context_buffers(struct VP9Common *cm);
-
-void vp9_free_ref_frame_buffers(struct BufferPool *pool);
-void vp9_free_postproc_buffers(struct VP9Common *cm);
-
-int vp9_alloc_state_buffers(struct VP9Common *cm, int width, int height);
-void vp9_free_state_buffers(struct VP9Common *cm);
-
-void vp9_set_mb_mi(struct VP9Common *cm, int width, int height);
-
-void vp9_swap_current_and_last_seg_map(struct VP9Common *cm);
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP9_COMMON_VP9_ALLOCCOMMON_H_
diff --git a/vp9/common/vp9_blockd.c b/vp9/common/vp9_blockd.c
deleted file mode 100644 (file)
index 7bab27d..0000000
+++ /dev/null
@@ -1,135 +0,0 @@
-/*
- *  Copyright (c) 2014 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.
- */
-
-#include "vp9/common/vp9_blockd.h"
-
-PREDICTION_MODE vp9_left_block_mode(const MODE_INFO *cur_mi,
-                                    const MODE_INFO *left_mi, int b) {
-  if (b == 0 || b == 2) {
-    if (!left_mi || is_inter_block(left_mi))
-      return DC_PRED;
-
-    return get_y_mode(left_mi, b + 1);
-  } else {
-    assert(b == 1 || b == 3);
-    return cur_mi->bmi[b - 1].as_mode;
-  }
-}
-
-PREDICTION_MODE vp9_above_block_mode(const MODE_INFO *cur_mi,
-                                     const MODE_INFO *above_mi, int b) {
-  if (b == 0 || b == 1) {
-    if (!above_mi || is_inter_block(above_mi))
-      return DC_PRED;
-
-    return get_y_mode(above_mi, b + 2);
-  } else {
-    assert(b == 2 || b == 3);
-    return cur_mi->bmi[b - 2].as_mode;
-  }
-}
-
-void vp9_foreach_transformed_block_in_plane(
-    const MACROBLOCKD *const xd, BLOCK_SIZE bsize, int plane,
-    foreach_transformed_block_visitor visit, void *arg) {
-  const struct macroblockd_plane *const pd = &xd->plane[plane];
-  const MODE_INFO* mi = xd->mi[0];
-  // block and transform sizes, in number of 4x4 blocks log 2 ("*_b")
-  // 4x4=0, 8x8=2, 16x16=4, 32x32=6, 64x64=8
-  // transform size varies per plane, look it up in a common way.
-  const TX_SIZE tx_size = plane ? get_uv_tx_size(mi, pd)
-                                : mi->tx_size;
-  const BLOCK_SIZE plane_bsize = get_plane_block_size(bsize, pd);
-  const int num_4x4_w = num_4x4_blocks_wide_lookup[plane_bsize];
-  const int num_4x4_h = num_4x4_blocks_high_lookup[plane_bsize];
-  const int step = 1 << (tx_size << 1);
-  int i = 0, r, c;
-
-  // If mb_to_right_edge is < 0 we are in a situation in which
-  // the current block size extends into the UMV and we won't
-  // visit the sub blocks that are wholly within the UMV.
-  const int max_blocks_wide = num_4x4_w + (xd->mb_to_right_edge >= 0 ? 0 :
-      xd->mb_to_right_edge >> (5 + pd->subsampling_x));
-  const int max_blocks_high = num_4x4_h + (xd->mb_to_bottom_edge >= 0 ? 0 :
-      xd->mb_to_bottom_edge >> (5 + pd->subsampling_y));
-  const int extra_step = ((num_4x4_w - max_blocks_wide) >> tx_size) * step;
-
-  // Keep track of the row and column of the blocks we use so that we know
-  // if we are in the unrestricted motion border.
-  for (r = 0; r < max_blocks_high; r += (1 << tx_size)) {
-    // Skip visiting the sub blocks that are wholly within the UMV.
-    for (c = 0; c < max_blocks_wide; c += (1 << tx_size)) {
-      visit(plane, i, plane_bsize, tx_size, arg);
-      i += step;
-    }
-    i += extra_step;
-  }
-}
-
-void vp9_foreach_transformed_block(const MACROBLOCKD* const xd,
-                                   BLOCK_SIZE bsize,
-                                   foreach_transformed_block_visitor visit,
-                                   void *arg) {
-  int plane;
-
-  for (plane = 0; plane < MAX_MB_PLANE; ++plane)
-    vp9_foreach_transformed_block_in_plane(xd, bsize, plane, visit, arg);
-}
-
-void vp9_set_contexts(const MACROBLOCKD *xd, struct macroblockd_plane *pd,
-                      BLOCK_SIZE plane_bsize, TX_SIZE tx_size, int has_eob,
-                      int aoff, int loff) {
-  ENTROPY_CONTEXT *const a = pd->above_context + aoff;
-  ENTROPY_CONTEXT *const l = pd->left_context + loff;
-  const int tx_size_in_blocks = 1 << tx_size;
-
-  // above
-  if (has_eob && xd->mb_to_right_edge < 0) {
-    int i;
-    const int blocks_wide = num_4x4_blocks_wide_lookup[plane_bsize] +
-                            (xd->mb_to_right_edge >> (5 + pd->subsampling_x));
-    int above_contexts = tx_size_in_blocks;
-    if (above_contexts + aoff > blocks_wide)
-      above_contexts = blocks_wide - aoff;
-
-    for (i = 0; i < above_contexts; ++i)
-      a[i] = has_eob;
-    for (i = above_contexts; i < tx_size_in_blocks; ++i)
-      a[i] = 0;
-  } else {
-    memset(a, has_eob, sizeof(ENTROPY_CONTEXT) * tx_size_in_blocks);
-  }
-
-  // left
-  if (has_eob && xd->mb_to_bottom_edge < 0) {
-    int i;
-    const int blocks_high = num_4x4_blocks_high_lookup[plane_bsize] +
-                            (xd->mb_to_bottom_edge >> (5 + pd->subsampling_y));
-    int left_contexts = tx_size_in_blocks;
-    if (left_contexts + loff > blocks_high)
-      left_contexts = blocks_high - loff;
-
-    for (i = 0; i < left_contexts; ++i)
-      l[i] = has_eob;
-    for (i = left_contexts; i < tx_size_in_blocks; ++i)
-      l[i] = 0;
-  } else {
-    memset(l, has_eob, sizeof(ENTROPY_CONTEXT) * tx_size_in_blocks);
-  }
-}
-
-void vp9_setup_block_planes(MACROBLOCKD *xd, int ss_x, int ss_y) {
-  int i;
-
-  for (i = 0; i < MAX_MB_PLANE; i++) {
-    xd->plane[i].subsampling_x = i ? ss_x : 0;
-    xd->plane[i].subsampling_y = i ? ss_y : 0;
-  }
-}
diff --git a/vp9/common/vp9_blockd.h b/vp9/common/vp9_blockd.h
deleted file mode 100644 (file)
index 3d26fb2..0000000
+++ /dev/null
@@ -1,305 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#ifndef VP9_COMMON_VP9_BLOCKD_H_
-#define VP9_COMMON_VP9_BLOCKD_H_
-
-#include "./vpx_config.h"
-
-#include "vpx_dsp/vpx_dsp_common.h"
-#include "vpx_ports/mem.h"
-#include "vpx_scale/yv12config.h"
-
-#include "vp9/common/vp9_common_data.h"
-#include "vp9/common/vp9_entropy.h"
-#include "vp9/common/vp9_entropymode.h"
-#include "vp9/common/vp9_mv.h"
-#include "vp9/common/vp9_scale.h"
-#include "vp9/common/vp9_seg_common.h"
-#include "vp9/common/vp9_tile_common.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define MAX_MB_PLANE 3
-
-typedef enum {
-  KEY_FRAME = 0,
-  INTER_FRAME = 1,
-  FRAME_TYPES,
-} FRAME_TYPE;
-
-static INLINE int is_inter_mode(PREDICTION_MODE mode) {
-  return mode >= NEARESTMV && mode <= NEWMV;
-}
-
-/* For keyframes, intra block modes are predicted by the (already decoded)
-   modes for the Y blocks to the left and above us; for interframes, there
-   is a single probability table. */
-
-typedef struct {
-  PREDICTION_MODE as_mode;
-  int_mv as_mv[2];  // first, second inter predictor motion vectors
-} b_mode_info;
-
-// Note that the rate-distortion optimization loop, bit-stream writer, and
-// decoder implementation modules critically rely on the defined entry values
-// specified herein. They should be refactored concurrently.
-
-#define NONE           -1
-#define INTRA_FRAME     0
-#define LAST_FRAME      1
-#define GOLDEN_FRAME    2
-#define ALTREF_FRAME    3
-#define MAX_REF_FRAMES  4
-typedef int8_t MV_REFERENCE_FRAME;
-
-// This structure now relates to 8x8 block regions.
-typedef struct MODE_INFO {
-  // Common for both INTER and INTRA blocks
-  BLOCK_SIZE sb_type;
-  PREDICTION_MODE mode;
-  TX_SIZE tx_size;
-  int8_t skip;
-  int8_t segment_id;
-  int8_t seg_id_predicted;  // valid only when temporal_update is enabled
-
-  // Only for INTRA blocks
-  PREDICTION_MODE uv_mode;
-
-  // Only for INTER blocks
-  INTERP_FILTER interp_filter;
-  MV_REFERENCE_FRAME ref_frame[2];
-
-  // TODO(slavarnway): Delete and use bmi[3].as_mv[] instead.
-  int_mv mv[2];
-
-  b_mode_info bmi[4];
-} MODE_INFO;
-
-static INLINE PREDICTION_MODE get_y_mode(const MODE_INFO *mi, int block) {
-  return mi->sb_type < BLOCK_8X8 ? mi->bmi[block].as_mode
-                                 : mi->mode;
-}
-
-static INLINE int is_inter_block(const MODE_INFO *mi) {
-  return mi->ref_frame[0] > INTRA_FRAME;
-}
-
-static INLINE int has_second_ref(const MODE_INFO *mi) {
-  return mi->ref_frame[1] > INTRA_FRAME;
-}
-
-PREDICTION_MODE vp9_left_block_mode(const MODE_INFO *cur_mi,
-                                    const MODE_INFO *left_mi, int b);
-
-PREDICTION_MODE vp9_above_block_mode(const MODE_INFO *cur_mi,
-                                     const MODE_INFO *above_mi, int b);
-
-enum mv_precision {
-  MV_PRECISION_Q3,
-  MV_PRECISION_Q4
-};
-
-struct buf_2d {
-  uint8_t *buf;
-  int stride;
-};
-
-struct macroblockd_plane {
-  tran_low_t *dqcoeff;
-  int subsampling_x;
-  int subsampling_y;
-  struct buf_2d dst;
-  struct buf_2d pre[2];
-  ENTROPY_CONTEXT *above_context;
-  ENTROPY_CONTEXT *left_context;
-  int16_t seg_dequant[MAX_SEGMENTS][2];
-
-  // number of 4x4s in current block
-  uint16_t n4_w, n4_h;
-  // log2 of n4_w, n4_h
-  uint8_t n4_wl, n4_hl;
-
-  // encoder
-  const int16_t *dequant;
-};
-
-#define BLOCK_OFFSET(x, i) ((x) + (i) * 16)
-
-typedef struct RefBuffer {
-  // TODO(dkovalev): idx is not really required and should be removed, now it
-  // is used in vp9_onyxd_if.c
-  int idx;
-  YV12_BUFFER_CONFIG *buf;
-  struct scale_factors sf;
-} RefBuffer;
-
-typedef struct macroblockd {
-  struct macroblockd_plane plane[MAX_MB_PLANE];
-  uint8_t bmode_blocks_wl;
-  uint8_t bmode_blocks_hl;
-
-  FRAME_COUNTS *counts;
-  TileInfo tile;
-
-  int mi_stride;
-
-  MODE_INFO **mi;
-  MODE_INFO *left_mi;
-  MODE_INFO *above_mi;
-
-  unsigned int max_blocks_wide;
-  unsigned int max_blocks_high;
-
-  const vpx_prob (*partition_probs)[PARTITION_TYPES - 1];
-
-  /* Distance of MB away from frame edges */
-  int mb_to_left_edge;
-  int mb_to_right_edge;
-  int mb_to_top_edge;
-  int mb_to_bottom_edge;
-
-  FRAME_CONTEXT *fc;
-
-  /* pointers to reference frames */
-  RefBuffer *block_refs[2];
-
-  /* pointer to current frame */
-  const YV12_BUFFER_CONFIG *cur_buf;
-
-  ENTROPY_CONTEXT *above_context[MAX_MB_PLANE];
-  ENTROPY_CONTEXT left_context[MAX_MB_PLANE][16];
-
-  PARTITION_CONTEXT *above_seg_context;
-  PARTITION_CONTEXT left_seg_context[8];
-
-#if CONFIG_VP9_HIGHBITDEPTH
-  /* Bit depth: 8, 10, 12 */
-  int bd;
-#endif
-
-  int lossless;
-  int corrupted;
-
-  struct vpx_internal_error_info *error_info;
-} MACROBLOCKD;
-
-static INLINE PLANE_TYPE get_plane_type(int plane) {
-  return (PLANE_TYPE)(plane > 0);
-}
-
-static INLINE BLOCK_SIZE get_subsize(BLOCK_SIZE bsize,
-                                     PARTITION_TYPE partition) {
-  return subsize_lookup[partition][bsize];
-}
-
-extern const TX_TYPE intra_mode_to_tx_type_lookup[INTRA_MODES];
-
-static INLINE TX_TYPE get_tx_type(PLANE_TYPE plane_type,
-                                  const MACROBLOCKD *xd) {
-  const MODE_INFO *const mi = xd->mi[0];
-
-  if (plane_type != PLANE_TYPE_Y || xd->lossless || is_inter_block(mi))
-    return DCT_DCT;
-
-  return intra_mode_to_tx_type_lookup[mi->mode];
-}
-
-static INLINE TX_TYPE get_tx_type_4x4(PLANE_TYPE plane_type,
-                                      const MACROBLOCKD *xd, int ib) {
-  const MODE_INFO *const mi = xd->mi[0];
-
-  if (plane_type != PLANE_TYPE_Y || xd->lossless || is_inter_block(mi))
-    return DCT_DCT;
-
-  return intra_mode_to_tx_type_lookup[get_y_mode(mi, ib)];
-}
-
-void vp9_setup_block_planes(MACROBLOCKD *xd, int ss_x, int ss_y);
-
-static INLINE TX_SIZE get_uv_tx_size_impl(TX_SIZE y_tx_size, BLOCK_SIZE bsize,
-                                          int xss, int yss) {
-  if (bsize < BLOCK_8X8) {
-    return TX_4X4;
-  } else {
-    const BLOCK_SIZE plane_bsize = ss_size_lookup[bsize][xss][yss];
-    return VPXMIN(y_tx_size, max_txsize_lookup[plane_bsize]);
-  }
-}
-
-static INLINE TX_SIZE get_uv_tx_size(const MODE_INFO *mi,
-                                     const struct macroblockd_plane *pd) {
-  return get_uv_tx_size_impl(mi->tx_size, mi->sb_type, pd->subsampling_x,
-                             pd->subsampling_y);
-}
-
-static INLINE BLOCK_SIZE get_plane_block_size(BLOCK_SIZE bsize,
-    const struct macroblockd_plane *pd) {
-  return ss_size_lookup[bsize][pd->subsampling_x][pd->subsampling_y];
-}
-
-static INLINE void reset_skip_context(MACROBLOCKD *xd, BLOCK_SIZE bsize) {
-  int i;
-  for (i = 0; i < MAX_MB_PLANE; i++) {
-    struct macroblockd_plane *const pd = &xd->plane[i];
-    const BLOCK_SIZE plane_bsize = get_plane_block_size(bsize, pd);
-    memset(pd->above_context, 0,
-           sizeof(ENTROPY_CONTEXT) * num_4x4_blocks_wide_lookup[plane_bsize]);
-    memset(pd->left_context, 0,
-           sizeof(ENTROPY_CONTEXT) * num_4x4_blocks_high_lookup[plane_bsize]);
-  }
-}
-
-static INLINE const vpx_prob *get_y_mode_probs(const MODE_INFO *mi,
-                                               const MODE_INFO *above_mi,
-                                               const MODE_INFO *left_mi,
-                                               int block) {
-  const PREDICTION_MODE above = vp9_above_block_mode(mi, above_mi, block);
-  const PREDICTION_MODE left = vp9_left_block_mode(mi, left_mi, block);
-  return vp9_kf_y_mode_prob[above][left];
-}
-
-typedef void (*foreach_transformed_block_visitor)(int plane, int block,
-                                                  BLOCK_SIZE plane_bsize,
-                                                  TX_SIZE tx_size,
-                                                  void *arg);
-
-void vp9_foreach_transformed_block_in_plane(
-    const MACROBLOCKD *const xd, BLOCK_SIZE bsize, int plane,
-    foreach_transformed_block_visitor visit, void *arg);
-
-
-void vp9_foreach_transformed_block(
-    const MACROBLOCKD* const xd, BLOCK_SIZE bsize,
-    foreach_transformed_block_visitor visit, void *arg);
-
-static INLINE void txfrm_block_to_raster_xy(BLOCK_SIZE plane_bsize,
-                                            TX_SIZE tx_size, int block,
-                                            int *x, int *y) {
-  const int bwl = b_width_log2_lookup[plane_bsize];
-  const int tx_cols_log2 = bwl - tx_size;
-  const int tx_cols = 1 << tx_cols_log2;
-  const int raster_mb = block >> (tx_size << 1);
-  *x = (raster_mb & (tx_cols - 1)) << tx_size;
-  *y = (raster_mb >> tx_cols_log2) << tx_size;
-}
-
-void vp9_set_contexts(const MACROBLOCKD *xd, struct macroblockd_plane *pd,
-                      BLOCK_SIZE plane_bsize, TX_SIZE tx_size, int has_eob,
-                      int aoff, int loff);
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP9_COMMON_VP9_BLOCKD_H_
diff --git a/vp9/common/vp9_common.h b/vp9/common/vp9_common.h
deleted file mode 100644 (file)
index 38815ac..0000000
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#ifndef VP9_COMMON_VP9_COMMON_H_
-#define VP9_COMMON_VP9_COMMON_H_
-
-/* Interface header for common constant data structures and lookup tables */
-
-#include <assert.h>
-
-#include "./vpx_config.h"
-#include "vpx_dsp/vpx_dsp_common.h"
-#include "vpx_mem/vpx_mem.h"
-#include "vpx/vpx_integer.h"
-#include "vpx_ports/bitops.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-// Only need this for fixed-size arrays, for structs just assign.
-#define vp9_copy(dest, src) {            \
-    assert(sizeof(dest) == sizeof(src)); \
-    memcpy(dest, src, sizeof(src));  \
-  }
-
-// Use this for variably-sized arrays.
-#define vp9_copy_array(dest, src, n) {       \
-    assert(sizeof(*(dest)) == sizeof(*(src)));   \
-    memcpy(dest, src, n * sizeof(*(src))); \
-  }
-
-#define vp9_zero(dest) memset(&(dest), 0, sizeof(dest))
-#define vp9_zero_array(dest, n) memset(dest, 0, n * sizeof(*(dest)))
-
-static INLINE int get_unsigned_bits(unsigned int num_values) {
-  return num_values > 0 ? get_msb(num_values) + 1 : 0;
-}
-
-#if CONFIG_DEBUG
-#define CHECK_MEM_ERROR(cm, lval, expr) do { \
-  lval = (expr); \
-  if (!lval) \
-    vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, \
-                       "Failed to allocate "#lval" at %s:%d", \
-                       __FILE__, __LINE__); \
-  } while (0)
-#else
-#define CHECK_MEM_ERROR(cm, lval, expr) do { \
-  lval = (expr); \
-  if (!lval) \
-    vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, \
-                       "Failed to allocate "#lval); \
-  } while (0)
-#endif
-
-#define VP9_SYNC_CODE_0 0x49
-#define VP9_SYNC_CODE_1 0x83
-#define VP9_SYNC_CODE_2 0x42
-
-#define VP9_FRAME_MARKER 0x2
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP9_COMMON_VP9_COMMON_H_
diff --git a/vp9/common/vp9_common_data.c b/vp9/common/vp9_common_data.c
deleted file mode 100644 (file)
index 3409d04..0000000
+++ /dev/null
@@ -1,176 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#include "vp9/common/vp9_common_data.h"
-#include "vpx_dsp/vpx_dsp_common.h"
-
-// Log 2 conversion lookup tables for block width and height
-const uint8_t b_width_log2_lookup[BLOCK_SIZES] =
-  {0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4};
-const uint8_t b_height_log2_lookup[BLOCK_SIZES] =
-  {0, 1, 0, 1, 2, 1, 2, 3, 2, 3, 4, 3, 4};
-const uint8_t num_4x4_blocks_wide_lookup[BLOCK_SIZES] =
-  {1, 1, 2, 2, 2, 4, 4, 4, 8, 8, 8, 16, 16};
-const uint8_t num_4x4_blocks_high_lookup[BLOCK_SIZES] =
-  {1, 2, 1, 2, 4, 2, 4, 8, 4, 8, 16, 8, 16};
-// Log 2 conversion lookup tables for modeinfo width and height
-const uint8_t mi_width_log2_lookup[BLOCK_SIZES] =
-  {0, 0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3};
-const uint8_t num_8x8_blocks_wide_lookup[BLOCK_SIZES] =
-  {1, 1, 1, 1, 1, 2, 2, 2, 4, 4, 4, 8, 8};
-const uint8_t num_8x8_blocks_high_lookup[BLOCK_SIZES] =
-  {1, 1, 1, 1, 2, 1, 2, 4, 2, 4, 8, 4, 8};
-
-// VPXMIN(3, VPXMIN(b_width_log2(bsize), b_height_log2(bsize)))
-const uint8_t size_group_lookup[BLOCK_SIZES] =
-  {0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 3};
-
-const uint8_t num_pels_log2_lookup[BLOCK_SIZES] =
-  {4, 5, 5, 6, 7, 7, 8, 9, 9, 10, 11, 11, 12};
-
-const PARTITION_TYPE partition_lookup[][BLOCK_SIZES] = {
-  {  // 4X4
-    // 4X4, 4X8,8X4,8X8,8X16,16X8,16X16,16X32,32X16,32X32,32X64,64X32,64X64
-    PARTITION_NONE, PARTITION_INVALID, PARTITION_INVALID,
-    PARTITION_INVALID, PARTITION_INVALID, PARTITION_INVALID,
-    PARTITION_INVALID, PARTITION_INVALID, PARTITION_INVALID,
-    PARTITION_INVALID, PARTITION_INVALID, PARTITION_INVALID,
-    PARTITION_INVALID
-  }, {  // 8X8
-    // 4X4, 4X8,8X4,8X8,8X16,16X8,16X16,16X32,32X16,32X32,32X64,64X32,64X64
-    PARTITION_SPLIT, PARTITION_VERT, PARTITION_HORZ, PARTITION_NONE,
-    PARTITION_INVALID, PARTITION_INVALID, PARTITION_INVALID,
-    PARTITION_INVALID, PARTITION_INVALID, PARTITION_INVALID,
-    PARTITION_INVALID, PARTITION_INVALID, PARTITION_INVALID
-  }, {  // 16X16
-    // 4X4, 4X8,8X4,8X8,8X16,16X8,16X16,16X32,32X16,32X32,32X64,64X32,64X64
-    PARTITION_SPLIT, PARTITION_SPLIT, PARTITION_SPLIT, PARTITION_SPLIT,
-    PARTITION_VERT, PARTITION_HORZ, PARTITION_NONE, PARTITION_INVALID,
-    PARTITION_INVALID, PARTITION_INVALID, PARTITION_INVALID,
-    PARTITION_INVALID, PARTITION_INVALID
-  }, {  // 32X32
-    // 4X4, 4X8,8X4,8X8,8X16,16X8,16X16,16X32,32X16,32X32,32X64,64X32,64X64
-    PARTITION_SPLIT, PARTITION_SPLIT, PARTITION_SPLIT, PARTITION_SPLIT,
-    PARTITION_SPLIT, PARTITION_SPLIT, PARTITION_SPLIT, PARTITION_VERT,
-    PARTITION_HORZ, PARTITION_NONE, PARTITION_INVALID,
-    PARTITION_INVALID, PARTITION_INVALID
-  }, {  // 64X64
-    // 4X4, 4X8,8X4,8X8,8X16,16X8,16X16,16X32,32X16,32X32,32X64,64X32,64X64
-    PARTITION_SPLIT, PARTITION_SPLIT, PARTITION_SPLIT, PARTITION_SPLIT,
-    PARTITION_SPLIT, PARTITION_SPLIT, PARTITION_SPLIT, PARTITION_SPLIT,
-    PARTITION_SPLIT, PARTITION_SPLIT, PARTITION_VERT, PARTITION_HORZ,
-    PARTITION_NONE
-  }
-};
-
-const BLOCK_SIZE subsize_lookup[PARTITION_TYPES][BLOCK_SIZES] = {
-  {     // PARTITION_NONE
-    BLOCK_4X4,   BLOCK_4X8,   BLOCK_8X4,
-    BLOCK_8X8,   BLOCK_8X16,  BLOCK_16X8,
-    BLOCK_16X16, BLOCK_16X32, BLOCK_32X16,
-    BLOCK_32X32, BLOCK_32X64, BLOCK_64X32,
-    BLOCK_64X64,
-  }, {  // PARTITION_HORZ
-    BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID,
-    BLOCK_8X4,     BLOCK_INVALID, BLOCK_INVALID,
-    BLOCK_16X8,    BLOCK_INVALID, BLOCK_INVALID,
-    BLOCK_32X16,   BLOCK_INVALID, BLOCK_INVALID,
-    BLOCK_64X32,
-  }, {  // PARTITION_VERT
-    BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID,
-    BLOCK_4X8,     BLOCK_INVALID, BLOCK_INVALID,
-    BLOCK_8X16,    BLOCK_INVALID, BLOCK_INVALID,
-    BLOCK_16X32,   BLOCK_INVALID, BLOCK_INVALID,
-    BLOCK_32X64,
-  }, {  // PARTITION_SPLIT
-    BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID,
-    BLOCK_4X4,     BLOCK_INVALID, BLOCK_INVALID,
-    BLOCK_8X8,     BLOCK_INVALID, BLOCK_INVALID,
-    BLOCK_16X16,   BLOCK_INVALID, BLOCK_INVALID,
-    BLOCK_32X32,
-  }
-};
-
-const TX_SIZE max_txsize_lookup[BLOCK_SIZES] = {
-  TX_4X4,   TX_4X4,   TX_4X4,
-  TX_8X8,   TX_8X8,   TX_8X8,
-  TX_16X16, TX_16X16, TX_16X16,
-  TX_32X32, TX_32X32, TX_32X32, TX_32X32
-};
-
-const BLOCK_SIZE txsize_to_bsize[TX_SIZES] = {
-    BLOCK_4X4,  // TX_4X4
-    BLOCK_8X8,  // TX_8X8
-    BLOCK_16X16,  // TX_16X16
-    BLOCK_32X32,  // TX_32X32
-};
-
-const TX_SIZE tx_mode_to_biggest_tx_size[TX_MODES] = {
-  TX_4X4,  // ONLY_4X4
-  TX_8X8,  // ALLOW_8X8
-  TX_16X16,  // ALLOW_16X16
-  TX_32X32,  // ALLOW_32X32
-  TX_32X32,  // TX_MODE_SELECT
-};
-
-const BLOCK_SIZE ss_size_lookup[BLOCK_SIZES][2][2] = {
-//  ss_x == 0    ss_x == 0        ss_x == 1      ss_x == 1
-//  ss_y == 0    ss_y == 1        ss_y == 0      ss_y == 1
-  {{BLOCK_4X4,   BLOCK_INVALID}, {BLOCK_INVALID, BLOCK_INVALID}},
-  {{BLOCK_4X8,   BLOCK_4X4},     {BLOCK_INVALID, BLOCK_INVALID}},
-  {{BLOCK_8X4,   BLOCK_INVALID}, {BLOCK_4X4,     BLOCK_INVALID}},
-  {{BLOCK_8X8,   BLOCK_8X4},     {BLOCK_4X8,     BLOCK_4X4}},
-  {{BLOCK_8X16,  BLOCK_8X8},     {BLOCK_INVALID, BLOCK_4X8}},
-  {{BLOCK_16X8,  BLOCK_INVALID}, {BLOCK_8X8,     BLOCK_8X4}},
-  {{BLOCK_16X16, BLOCK_16X8},    {BLOCK_8X16,    BLOCK_8X8}},
-  {{BLOCK_16X32, BLOCK_16X16},   {BLOCK_INVALID, BLOCK_8X16}},
-  {{BLOCK_32X16, BLOCK_INVALID}, {BLOCK_16X16,   BLOCK_16X8}},
-  {{BLOCK_32X32, BLOCK_32X16},   {BLOCK_16X32,   BLOCK_16X16}},
-  {{BLOCK_32X64, BLOCK_32X32},   {BLOCK_INVALID, BLOCK_16X32}},
-  {{BLOCK_64X32, BLOCK_INVALID}, {BLOCK_32X32,   BLOCK_32X16}},
-  {{BLOCK_64X64, BLOCK_64X32},   {BLOCK_32X64,   BLOCK_32X32}},
-};
-
-// Generates 4 bit field in which each bit set to 1 represents
-// a blocksize partition  1111 means we split 64x64, 32x32, 16x16
-// and 8x8.  1000 means we just split the 64x64 to 32x32
-const struct {
-  PARTITION_CONTEXT above;
-  PARTITION_CONTEXT left;
-} partition_context_lookup[BLOCK_SIZES]= {
-  {15, 15},  // 4X4   - {0b1111, 0b1111}
-  {15, 14},  // 4X8   - {0b1111, 0b1110}
-  {14, 15},  // 8X4   - {0b1110, 0b1111}
-  {14, 14},  // 8X8   - {0b1110, 0b1110}
-  {14, 12},  // 8X16  - {0b1110, 0b1100}
-  {12, 14},  // 16X8  - {0b1100, 0b1110}
-  {12, 12},  // 16X16 - {0b1100, 0b1100}
-  {12, 8 },  // 16X32 - {0b1100, 0b1000}
-  {8,  12},  // 32X16 - {0b1000, 0b1100}
-  {8,  8 },  // 32X32 - {0b1000, 0b1000}
-  {8,  0 },  // 32X64 - {0b1000, 0b0000}
-  {0,  8 },  // 64X32 - {0b0000, 0b1000}
-  {0,  0 },  // 64X64 - {0b0000, 0b0000}
-};
-
-#if CONFIG_BETTER_HW_COMPATIBILITY && CONFIG_VP9_HIGHBITDEPTH
-const uint8_t need_top_left[INTRA_MODES] = {
-    0,  // DC_PRED
-    0,  // V_PRED
-    0,  // H_PRED
-    0,  // D45_PRED
-    1,  // D135_PRED
-    1,  // D117_PRED
-    1,  // D153_PRED
-    0,  // D207_PRED
-    0,  // D63_PRED
-    1,  // TM_PRED
-};
-#endif  // CONFIG_BETTER_HW_COMPATIBILITY && CONFIG_VP9_HIGHBITDEPTH
diff --git a/vp9/common/vp9_common_data.h b/vp9/common/vp9_common_data.h
deleted file mode 100644 (file)
index 0ae24da..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#ifndef VP9_COMMON_VP9_COMMON_DATA_H_
-#define VP9_COMMON_VP9_COMMON_DATA_H_
-
-#include "vp9/common/vp9_enums.h"
-#include "vpx/vpx_integer.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-extern const uint8_t b_width_log2_lookup[BLOCK_SIZES];
-extern const uint8_t b_height_log2_lookup[BLOCK_SIZES];
-extern const uint8_t mi_width_log2_lookup[BLOCK_SIZES];
-extern const uint8_t num_8x8_blocks_wide_lookup[BLOCK_SIZES];
-extern const uint8_t num_8x8_blocks_high_lookup[BLOCK_SIZES];
-extern const uint8_t num_4x4_blocks_high_lookup[BLOCK_SIZES];
-extern const uint8_t num_4x4_blocks_wide_lookup[BLOCK_SIZES];
-extern const uint8_t size_group_lookup[BLOCK_SIZES];
-extern const uint8_t num_pels_log2_lookup[BLOCK_SIZES];
-extern const PARTITION_TYPE partition_lookup[][BLOCK_SIZES];
-extern const BLOCK_SIZE subsize_lookup[PARTITION_TYPES][BLOCK_SIZES];
-extern const TX_SIZE max_txsize_lookup[BLOCK_SIZES];
-extern const BLOCK_SIZE txsize_to_bsize[TX_SIZES];
-extern const TX_SIZE tx_mode_to_biggest_tx_size[TX_MODES];
-extern const BLOCK_SIZE ss_size_lookup[BLOCK_SIZES][2][2];
-#if CONFIG_BETTER_HW_COMPATIBILITY && CONFIG_VP9_HIGHBITDEPTH
-extern const uint8_t need_top_left[INTRA_MODES];
-#endif  // CONFIG_BETTER_HW_COMPATIBILITY && CONFIG_VP9_HIGHBITDEPTH
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP9_COMMON_VP9_COMMON_DATA_H_
diff --git a/vp9/common/vp9_debugmodes.c b/vp9/common/vp9_debugmodes.c
deleted file mode 100644 (file)
index d9c1fd9..0000000
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#include <stdio.h>
-
-#include "vp9/common/vp9_blockd.h"
-#include "vp9/common/vp9_onyxc_int.h"
-
-static void log_frame_info(VP9_COMMON *cm, const char *str, FILE *f) {
-  fprintf(f, "%s", str);
-  fprintf(f, "(Frame %d, Show:%d, Q:%d): \n", cm->current_video_frame,
-          cm->show_frame, cm->base_qindex);
-}
-/* This function dereferences a pointer to the mbmi structure
- * and uses the passed in member offset to print out the value of an integer
- * for each mbmi member value in the mi structure.
- */
-static void print_mi_data(VP9_COMMON *cm, FILE *file, const char *descriptor,
-                          size_t member_offset) {
-  int mi_row, mi_col;
-  MODE_INFO **mi = cm->mi_grid_visible;
-  int rows = cm->mi_rows;
-  int cols = cm->mi_cols;
-  char prefix = descriptor[0];
-
-  log_frame_info(cm, descriptor, file);
-  for (mi_row = 0; mi_row < rows; mi_row++) {
-    fprintf(file, "%c ", prefix);
-    for (mi_col = 0; mi_col < cols; mi_col++) {
-      fprintf(file, "%2d ",
-              *((int*) ((char *) (mi[0]) +
-                                  member_offset)));
-      mi++;
-    }
-    fprintf(file, "\n");
-    mi += 8;
-  }
-  fprintf(file, "\n");
-}
-
-void vp9_print_modes_and_motion_vectors(VP9_COMMON *cm, const char *file) {
-  int mi_row;
-  int mi_col;
-  FILE *mvs = fopen(file, "a");
-  MODE_INFO **mi = cm->mi_grid_visible;
-  int rows = cm->mi_rows;
-  int cols = cm->mi_cols;
-
-  print_mi_data(cm, mvs, "Partitions:", offsetof(MODE_INFO, sb_type));
-  print_mi_data(cm, mvs, "Modes:", offsetof(MODE_INFO, mode));
-  print_mi_data(cm, mvs, "Ref frame:", offsetof(MODE_INFO, ref_frame[0]));
-  print_mi_data(cm, mvs, "Transform:", offsetof(MODE_INFO, tx_size));
-  print_mi_data(cm, mvs, "UV Modes:", offsetof(MODE_INFO, uv_mode));
-
-  // output skip infomation.
-  log_frame_info(cm, "Skips:", mvs);
-  for (mi_row = 0; mi_row < rows; mi_row++) {
-    fprintf(mvs, "S ");
-    for (mi_col = 0; mi_col < cols; mi_col++) {
-      fprintf(mvs, "%2d ", mi[0]->skip);
-      mi++;
-    }
-    fprintf(mvs, "\n");
-    mi += 8;
-  }
-  fprintf(mvs, "\n");
-
-  // output motion vectors.
-  log_frame_info(cm, "Vectors ", mvs);
-  mi = cm->mi_grid_visible;
-  for (mi_row = 0; mi_row < rows; mi_row++) {
-    fprintf(mvs, "V ");
-    for (mi_col = 0; mi_col < cols; mi_col++) {
-      fprintf(mvs, "%4d:%4d ", mi[0]->mv[0].as_mv.row,
-                               mi[0]->mv[0].as_mv.col);
-      mi++;
-    }
-    fprintf(mvs, "\n");
-    mi += 8;
-  }
-  fprintf(mvs, "\n");
-
-  fclose(mvs);
-}
diff --git a/vp9/common/vp9_entropy.c b/vp9/common/vp9_entropy.c
deleted file mode 100644 (file)
index 7b490af..0000000
+++ /dev/null
@@ -1,802 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#include "vp9/common/vp9_entropy.h"
-#include "vp9/common/vp9_blockd.h"
-#include "vp9/common/vp9_onyxc_int.h"
-#include "vp9/common/vp9_entropymode.h"
-#include "vpx_mem/vpx_mem.h"
-#include "vpx/vpx_integer.h"
-
-// Unconstrained Node Tree
-const vpx_tree_index vp9_coef_con_tree[TREE_SIZE(ENTROPY_TOKENS)] = {
-  2, 6,                                // 0 = LOW_VAL
-  -TWO_TOKEN, 4,                       // 1 = TWO
-  -THREE_TOKEN, -FOUR_TOKEN,           // 2 = THREE
-  8, 10,                               // 3 = HIGH_LOW
-  -CATEGORY1_TOKEN, -CATEGORY2_TOKEN,  // 4 = CAT_ONE
-  12, 14,                              // 5 = CAT_THREEFOUR
-  -CATEGORY3_TOKEN, -CATEGORY4_TOKEN,  // 6 = CAT_THREE
-  -CATEGORY5_TOKEN, -CATEGORY6_TOKEN   // 7 = CAT_FIVE
-};
-
-const vpx_prob vp9_cat1_prob[] = { 159 };
-const vpx_prob vp9_cat2_prob[] = { 165, 145 };
-const vpx_prob vp9_cat3_prob[] = { 173, 148, 140 };
-const vpx_prob vp9_cat4_prob[] = { 176, 155, 140, 135 };
-const vpx_prob vp9_cat5_prob[] = { 180, 157, 141, 134, 130 };
-const vpx_prob vp9_cat6_prob[] = {
-    254, 254, 254, 252, 249, 243, 230, 196, 177, 153, 140, 133, 130, 129
-};
-#if CONFIG_VP9_HIGHBITDEPTH
-const vpx_prob vp9_cat6_prob_high12[] = {
-    255, 255, 255, 255, 254, 254, 254, 252, 249,
-    243, 230, 196, 177, 153, 140, 133, 130, 129
-};
-#endif
-
-const uint8_t vp9_coefband_trans_8x8plus[1024] = {
-  0, 1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4,
-  4, 4, 4, 4, 4, 5,
-  // beyond MAXBAND_INDEX+1 all values are filled as 5
-                    5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
-  5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
-  5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
-  5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
-  5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
-  5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
-  5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
-  5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
-  5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
-  5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
-  5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
-  5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
-  5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
-  5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
-  5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
-  5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
-  5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
-  5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
-  5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
-  5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
-  5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
-  5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
-  5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
-  5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
-  5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
-  5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
-  5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
-  5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
-  5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
-  5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
-  5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
-  5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
-  5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
-  5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
-  5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
-  5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
-  5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
-  5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
-  5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
-  5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
-  5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
-  5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
-  5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
-  5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
-  5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
-  5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
-  5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
-  5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
-  5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
-  5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
-  5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
-  5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
-  5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
-  5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
-  5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
-  5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
-  5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
-  5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
-  5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
-  5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
-  5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
-  5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
-  5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
-};
-
-const uint8_t vp9_coefband_trans_4x4[16] = {
-  0, 1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5,
-};
-
-const uint8_t vp9_pt_energy_class[ENTROPY_TOKENS] = {
-  0, 1, 2, 3, 3, 4, 4, 5, 5, 5, 5, 5
-};
-
-// Model obtained from a 2-sided zero-centerd distribuition derived
-// from a Pareto distribution. The cdf of the distribution is:
-// cdf(x) = 0.5 + 0.5 * sgn(x) * [1 - {alpha/(alpha + |x|)} ^ beta]
-//
-// For a given beta and a given probablity of the 1-node, the alpha
-// is first solved, and then the {alpha, beta} pair is used to generate
-// the probabilities for the rest of the nodes.
-
-// beta = 8
-
-// Every odd line in this table can be generated from the even lines
-// by averaging :
-// vp9_pareto8_full[l][node] = (vp9_pareto8_full[l-1][node] +
-//                              vp9_pareto8_full[l+1][node] ) >> 1;
-const vpx_prob vp9_pareto8_full[COEFF_PROB_MODELS][MODEL_NODES] = {
-  {  3,  86, 128,   6,  86,  23,  88,  29},
-  {  6,  86, 128,  11,  87,  42,  91,  52},
-  {  9,  86, 129,  17,  88,  61,  94,  76},
-  { 12,  86, 129,  22,  88,  77,  97,  93},
-  { 15,  87, 129,  28,  89,  93, 100, 110},
-  { 17,  87, 129,  33,  90, 105, 103, 123},
-  { 20,  88, 130,  38,  91, 118, 106, 136},
-  { 23,  88, 130,  43,  91, 128, 108, 146},
-  { 26,  89, 131,  48,  92, 139, 111, 156},
-  { 28,  89, 131,  53,  93, 147, 114, 163},
-  { 31,  90, 131,  58,  94, 156, 117, 171},
-  { 34,  90, 131,  62,  94, 163, 119, 177},
-  { 37,  90, 132,  66,  95, 171, 122, 184},
-  { 39,  90, 132,  70,  96, 177, 124, 189},
-  { 42,  91, 132,  75,  97, 183, 127, 194},
-  { 44,  91, 132,  79,  97, 188, 129, 198},
-  { 47,  92, 133,  83,  98, 193, 132, 202},
-  { 49,  92, 133,  86,  99, 197, 134, 205},
-  { 52,  93, 133,  90, 100, 201, 137, 208},
-  { 54,  93, 133,  94, 100, 204, 139, 211},
-  { 57,  94, 134,  98, 101, 208, 142, 214},
-  { 59,  94, 134, 101, 102, 211, 144, 216},
-  { 62,  94, 135, 105, 103, 214, 146, 218},
-  { 64,  94, 135, 108, 103, 216, 148, 220},
-  { 66,  95, 135, 111, 104, 219, 151, 222},
-  { 68,  95, 135, 114, 105, 221, 153, 223},
-  { 71,  96, 136, 117, 106, 224, 155, 225},
-  { 73,  96, 136, 120, 106, 225, 157, 226},
-  { 76,  97, 136, 123, 107, 227, 159, 228},
-  { 78,  97, 136, 126, 108, 229, 160, 229},
-  { 80,  98, 137, 129, 109, 231, 162, 231},
-  { 82,  98, 137, 131, 109, 232, 164, 232},
-  { 84,  98, 138, 134, 110, 234, 166, 233},
-  { 86,  98, 138, 137, 111, 235, 168, 234},
-  { 89,  99, 138, 140, 112, 236, 170, 235},
-  { 91,  99, 138, 142, 112, 237, 171, 235},
-  { 93, 100, 139, 145, 113, 238, 173, 236},
-  { 95, 100, 139, 147, 114, 239, 174, 237},
-  { 97, 101, 140, 149, 115, 240, 176, 238},
-  { 99, 101, 140, 151, 115, 241, 177, 238},
-  {101, 102, 140, 154, 116, 242, 179, 239},
-  {103, 102, 140, 156, 117, 242, 180, 239},
-  {105, 103, 141, 158, 118, 243, 182, 240},
-  {107, 103, 141, 160, 118, 243, 183, 240},
-  {109, 104, 141, 162, 119, 244, 185, 241},
-  {111, 104, 141, 164, 119, 244, 186, 241},
-  {113, 104, 142, 166, 120, 245, 187, 242},
-  {114, 104, 142, 168, 121, 245, 188, 242},
-  {116, 105, 143, 170, 122, 246, 190, 243},
-  {118, 105, 143, 171, 122, 246, 191, 243},
-  {120, 106, 143, 173, 123, 247, 192, 244},
-  {121, 106, 143, 175, 124, 247, 193, 244},
-  {123, 107, 144, 177, 125, 248, 195, 244},
-  {125, 107, 144, 178, 125, 248, 196, 244},
-  {127, 108, 145, 180, 126, 249, 197, 245},
-  {128, 108, 145, 181, 127, 249, 198, 245},
-  {130, 109, 145, 183, 128, 249, 199, 245},
-  {132, 109, 145, 184, 128, 249, 200, 245},
-  {134, 110, 146, 186, 129, 250, 201, 246},
-  {135, 110, 146, 187, 130, 250, 202, 246},
-  {137, 111, 147, 189, 131, 251, 203, 246},
-  {138, 111, 147, 190, 131, 251, 204, 246},
-  {140, 112, 147, 192, 132, 251, 205, 247},
-  {141, 112, 147, 193, 132, 251, 206, 247},
-  {143, 113, 148, 194, 133, 251, 207, 247},
-  {144, 113, 148, 195, 134, 251, 207, 247},
-  {146, 114, 149, 197, 135, 252, 208, 248},
-  {147, 114, 149, 198, 135, 252, 209, 248},
-  {149, 115, 149, 199, 136, 252, 210, 248},
-  {150, 115, 149, 200, 137, 252, 210, 248},
-  {152, 115, 150, 201, 138, 252, 211, 248},
-  {153, 115, 150, 202, 138, 252, 212, 248},
-  {155, 116, 151, 204, 139, 253, 213, 249},
-  {156, 116, 151, 205, 139, 253, 213, 249},
-  {158, 117, 151, 206, 140, 253, 214, 249},
-  {159, 117, 151, 207, 141, 253, 215, 249},
-  {161, 118, 152, 208, 142, 253, 216, 249},
-  {162, 118, 152, 209, 142, 253, 216, 249},
-  {163, 119, 153, 210, 143, 253, 217, 249},
-  {164, 119, 153, 211, 143, 253, 217, 249},
-  {166, 120, 153, 212, 144, 254, 218, 250},
-  {167, 120, 153, 212, 145, 254, 219, 250},
-  {168, 121, 154, 213, 146, 254, 220, 250},
-  {169, 121, 154, 214, 146, 254, 220, 250},
-  {171, 122, 155, 215, 147, 254, 221, 250},
-  {172, 122, 155, 216, 147, 254, 221, 250},
-  {173, 123, 155, 217, 148, 254, 222, 250},
-  {174, 123, 155, 217, 149, 254, 222, 250},
-  {176, 124, 156, 218, 150, 254, 223, 250},
-  {177, 124, 156, 219, 150, 254, 223, 250},
-  {178, 125, 157, 220, 151, 254, 224, 251},
-  {179, 125, 157, 220, 151, 254, 224, 251},
-  {180, 126, 157, 221, 152, 254, 225, 251},
-  {181, 126, 157, 221, 152, 254, 225, 251},
-  {183, 127, 158, 222, 153, 254, 226, 251},
-  {184, 127, 158, 223, 154, 254, 226, 251},
-  {185, 128, 159, 224, 155, 255, 227, 251},
-  {186, 128, 159, 224, 155, 255, 227, 251},
-  {187, 129, 160, 225, 156, 255, 228, 251},
-  {188, 130, 160, 225, 156, 255, 228, 251},
-  {189, 131, 160, 226, 157, 255, 228, 251},
-  {190, 131, 160, 226, 158, 255, 228, 251},
-  {191, 132, 161, 227, 159, 255, 229, 251},
-  {192, 132, 161, 227, 159, 255, 229, 251},
-  {193, 133, 162, 228, 160, 255, 230, 252},
-  {194, 133, 162, 229, 160, 255, 230, 252},
-  {195, 134, 163, 230, 161, 255, 231, 252},
-  {196, 134, 163, 230, 161, 255, 231, 252},
-  {197, 135, 163, 231, 162, 255, 231, 252},
-  {198, 135, 163, 231, 162, 255, 231, 252},
-  {199, 136, 164, 232, 163, 255, 232, 252},
-  {200, 136, 164, 232, 164, 255, 232, 252},
-  {201, 137, 165, 233, 165, 255, 233, 252},
-  {201, 137, 165, 233, 165, 255, 233, 252},
-  {202, 138, 166, 233, 166, 255, 233, 252},
-  {203, 138, 166, 233, 166, 255, 233, 252},
-  {204, 139, 166, 234, 167, 255, 234, 252},
-  {205, 139, 166, 234, 167, 255, 234, 252},
-  {206, 140, 167, 235, 168, 255, 235, 252},
-  {206, 140, 167, 235, 168, 255, 235, 252},
-  {207, 141, 168, 236, 169, 255, 235, 252},
-  {208, 141, 168, 236, 170, 255, 235, 252},
-  {209, 142, 169, 237, 171, 255, 236, 252},
-  {209, 143, 169, 237, 171, 255, 236, 252},
-  {210, 144, 169, 237, 172, 255, 236, 252},
-  {211, 144, 169, 237, 172, 255, 236, 252},
-  {212, 145, 170, 238, 173, 255, 237, 252},
-  {213, 145, 170, 238, 173, 255, 237, 252},
-  {214, 146, 171, 239, 174, 255, 237, 253},
-  {214, 146, 171, 239, 174, 255, 237, 253},
-  {215, 147, 172, 240, 175, 255, 238, 253},
-  {215, 147, 172, 240, 175, 255, 238, 253},
-  {216, 148, 173, 240, 176, 255, 238, 253},
-  {217, 148, 173, 240, 176, 255, 238, 253},
-  {218, 149, 173, 241, 177, 255, 239, 253},
-  {218, 149, 173, 241, 178, 255, 239, 253},
-  {219, 150, 174, 241, 179, 255, 239, 253},
-  {219, 151, 174, 241, 179, 255, 239, 253},
-  {220, 152, 175, 242, 180, 255, 240, 253},
-  {221, 152, 175, 242, 180, 255, 240, 253},
-  {222, 153, 176, 242, 181, 255, 240, 253},
-  {222, 153, 176, 242, 181, 255, 240, 253},
-  {223, 154, 177, 243, 182, 255, 240, 253},
-  {223, 154, 177, 243, 182, 255, 240, 253},
-  {224, 155, 178, 244, 183, 255, 241, 253},
-  {224, 155, 178, 244, 183, 255, 241, 253},
-  {225, 156, 178, 244, 184, 255, 241, 253},
-  {225, 157, 178, 244, 184, 255, 241, 253},
-  {226, 158, 179, 244, 185, 255, 242, 253},
-  {227, 158, 179, 244, 185, 255, 242, 253},
-  {228, 159, 180, 245, 186, 255, 242, 253},
-  {228, 159, 180, 245, 186, 255, 242, 253},
-  {229, 160, 181, 245, 187, 255, 242, 253},
-  {229, 160, 181, 245, 187, 255, 242, 253},
-  {230, 161, 182, 246, 188, 255, 243, 253},
-  {230, 162, 182, 246, 188, 255, 243, 253},
-  {231, 163, 183, 246, 189, 255, 243, 253},
-  {231, 163, 183, 246, 189, 255, 243, 253},
-  {232, 164, 184, 247, 190, 255, 243, 253},
-  {232, 164, 184, 247, 190, 255, 243, 253},
-  {233, 165, 185, 247, 191, 255, 244, 253},
-  {233, 165, 185, 247, 191, 255, 244, 253},
-  {234, 166, 185, 247, 192, 255, 244, 253},
-  {234, 167, 185, 247, 192, 255, 244, 253},
-  {235, 168, 186, 248, 193, 255, 244, 253},
-  {235, 168, 186, 248, 193, 255, 244, 253},
-  {236, 169, 187, 248, 194, 255, 244, 253},
-  {236, 169, 187, 248, 194, 255, 244, 253},
-  {236, 170, 188, 248, 195, 255, 245, 253},
-  {236, 170, 188, 248, 195, 255, 245, 253},
-  {237, 171, 189, 249, 196, 255, 245, 254},
-  {237, 172, 189, 249, 196, 255, 245, 254},
-  {238, 173, 190, 249, 197, 255, 245, 254},
-  {238, 173, 190, 249, 197, 255, 245, 254},
-  {239, 174, 191, 249, 198, 255, 245, 254},
-  {239, 174, 191, 249, 198, 255, 245, 254},
-  {240, 175, 192, 249, 199, 255, 246, 254},
-  {240, 176, 192, 249, 199, 255, 246, 254},
-  {240, 177, 193, 250, 200, 255, 246, 254},
-  {240, 177, 193, 250, 200, 255, 246, 254},
-  {241, 178, 194, 250, 201, 255, 246, 254},
-  {241, 178, 194, 250, 201, 255, 246, 254},
-  {242, 179, 195, 250, 202, 255, 246, 254},
-  {242, 180, 195, 250, 202, 255, 246, 254},
-  {242, 181, 196, 250, 203, 255, 247, 254},
-  {242, 181, 196, 250, 203, 255, 247, 254},
-  {243, 182, 197, 251, 204, 255, 247, 254},
-  {243, 183, 197, 251, 204, 255, 247, 254},
-  {244, 184, 198, 251, 205, 255, 247, 254},
-  {244, 184, 198, 251, 205, 255, 247, 254},
-  {244, 185, 199, 251, 206, 255, 247, 254},
-  {244, 185, 199, 251, 206, 255, 247, 254},
-  {245, 186, 200, 251, 207, 255, 247, 254},
-  {245, 187, 200, 251, 207, 255, 247, 254},
-  {246, 188, 201, 252, 207, 255, 248, 254},
-  {246, 188, 201, 252, 207, 255, 248, 254},
-  {246, 189, 202, 252, 208, 255, 248, 254},
-  {246, 190, 202, 252, 208, 255, 248, 254},
-  {247, 191, 203, 252, 209, 255, 248, 254},
-  {247, 191, 203, 252, 209, 255, 248, 254},
-  {247, 192, 204, 252, 210, 255, 248, 254},
-  {247, 193, 204, 252, 210, 255, 248, 254},
-  {248, 194, 205, 252, 211, 255, 248, 254},
-  {248, 194, 205, 252, 211, 255, 248, 254},
-  {248, 195, 206, 252, 212, 255, 249, 254},
-  {248, 196, 206, 252, 212, 255, 249, 254},
-  {249, 197, 207, 253, 213, 255, 249, 254},
-  {249, 197, 207, 253, 213, 255, 249, 254},
-  {249, 198, 208, 253, 214, 255, 249, 254},
-  {249, 199, 209, 253, 214, 255, 249, 254},
-  {250, 200, 210, 253, 215, 255, 249, 254},
-  {250, 200, 210, 253, 215, 255, 249, 254},
-  {250, 201, 211, 253, 215, 255, 249, 254},
-  {250, 202, 211, 253, 215, 255, 249, 254},
-  {250, 203, 212, 253, 216, 255, 249, 254},
-  {250, 203, 212, 253, 216, 255, 249, 254},
-  {251, 204, 213, 253, 217, 255, 250, 254},
-  {251, 205, 213, 253, 217, 255, 250, 254},
-  {251, 206, 214, 254, 218, 255, 250, 254},
-  {251, 206, 215, 254, 218, 255, 250, 254},
-  {252, 207, 216, 254, 219, 255, 250, 254},
-  {252, 208, 216, 254, 219, 255, 250, 254},
-  {252, 209, 217, 254, 220, 255, 250, 254},
-  {252, 210, 217, 254, 220, 255, 250, 254},
-  {252, 211, 218, 254, 221, 255, 250, 254},
-  {252, 212, 218, 254, 221, 255, 250, 254},
-  {253, 213, 219, 254, 222, 255, 250, 254},
-  {253, 213, 220, 254, 222, 255, 250, 254},
-  {253, 214, 221, 254, 223, 255, 250, 254},
-  {253, 215, 221, 254, 223, 255, 250, 254},
-  {253, 216, 222, 254, 224, 255, 251, 254},
-  {253, 217, 223, 254, 224, 255, 251, 254},
-  {253, 218, 224, 254, 225, 255, 251, 254},
-  {253, 219, 224, 254, 225, 255, 251, 254},
-  {254, 220, 225, 254, 225, 255, 251, 254},
-  {254, 221, 226, 254, 225, 255, 251, 254},
-  {254, 222, 227, 255, 226, 255, 251, 254},
-  {254, 223, 227, 255, 226, 255, 251, 254},
-  {254, 224, 228, 255, 227, 255, 251, 254},
-  {254, 225, 229, 255, 227, 255, 251, 254},
-  {254, 226, 230, 255, 228, 255, 251, 254},
-  {254, 227, 230, 255, 229, 255, 251, 254},
-  {255, 228, 231, 255, 230, 255, 251, 254},
-  {255, 229, 232, 255, 230, 255, 251, 254},
-  {255, 230, 233, 255, 231, 255, 252, 254},
-  {255, 231, 234, 255, 231, 255, 252, 254},
-  {255, 232, 235, 255, 232, 255, 252, 254},
-  {255, 233, 236, 255, 232, 255, 252, 254},
-  {255, 235, 237, 255, 233, 255, 252, 254},
-  {255, 236, 238, 255, 234, 255, 252, 254},
-  {255, 238, 240, 255, 235, 255, 252, 255},
-  {255, 239, 241, 255, 235, 255, 252, 254},
-  {255, 241, 243, 255, 236, 255, 252, 254},
-  {255, 243, 245, 255, 237, 255, 252, 254},
-  {255, 246, 247, 255, 239, 255, 253, 255},
-};
-
-static const vp9_coeff_probs_model default_coef_probs_4x4[PLANE_TYPES] = {
-  {  // Y plane
-    {  // Intra
-      {  // Band 0
-        { 195,  29, 183 }, {  84,  49, 136 }, {   8,  42,  71 }
-      }, {  // Band 1
-        {  31, 107, 169 }, {  35,  99, 159 }, {  17,  82, 140 },
-        {   8,  66, 114 }, {   2,  44,  76 }, {   1,  19,  32 }
-      }, {  // Band 2
-        {  40, 132, 201 }, {  29, 114, 187 }, {  13,  91, 157 },
-        {   7,  75, 127 }, {   3,  58,  95 }, {   1,  28,  47 }
-      }, {  // Band 3
-        {  69, 142, 221 }, {  42, 122, 201 }, {  15,  91, 159 },
-        {   6,  67, 121 }, {   1,  42,  77 }, {   1,  17,  31 }
-      }, {  // Band 4
-        { 102, 148, 228 }, {  67, 117, 204 }, {  17,  82, 154 },
-        {   6,  59, 114 }, {   2,  39,  75 }, {   1,  15,  29 }
-      }, {  // Band 5
-        { 156,  57, 233 }, { 119,  57, 212 }, {  58,  48, 163 },
-        {  29,  40, 124 }, {  12,  30,  81 }, {   3,  12,  31 }
-      }
-    }, {  // Inter
-      {  // Band 0
-        { 191, 107, 226 }, { 124, 117, 204 }, {  25,  99, 155 }
-      }, {  // Band 1
-        {  29, 148, 210 }, {  37, 126, 194 }, {   8,  93, 157 },
-        {   2,  68, 118 }, {   1,  39,  69 }, {   1,  17,  33 }
-      }, {  // Band 2
-        {  41, 151, 213 }, {  27, 123, 193 }, {   3,  82, 144 },
-        {   1,  58, 105 }, {   1,  32,  60 }, {   1,  13,  26 }
-      }, {  // Band 3
-        {  59, 159, 220 }, {  23, 126, 198 }, {   4,  88, 151 },
-        {   1,  66, 114 }, {   1,  38,  71 }, {   1,  18,  34 }
-      }, {  // Band 4
-        { 114, 136, 232 }, {  51, 114, 207 }, {  11,  83, 155 },
-        {   3,  56, 105 }, {   1,  33,  65 }, {   1,  17,  34 }
-      }, {  // Band 5
-        { 149,  65, 234 }, { 121,  57, 215 }, {  61,  49, 166 },
-        {  28,  36, 114 }, {  12,  25,  76 }, {   3,  16,  42 }
-      }
-    }
-  }, {  // UV plane
-    {  // Intra
-      {  // Band 0
-        { 214,  49, 220 }, { 132,  63, 188 }, {  42,  65, 137 }
-      }, {  // Band 1
-        {  85, 137, 221 }, { 104, 131, 216 }, {  49, 111, 192 },
-        {  21,  87, 155 }, {   2,  49,  87 }, {   1,  16,  28 }
-      }, {  // Band 2
-        {  89, 163, 230 }, {  90, 137, 220 }, {  29, 100, 183 },
-        {  10,  70, 135 }, {   2,  42,  81 }, {   1,  17,  33 }
-      }, {  // Band 3
-        { 108, 167, 237 }, {  55, 133, 222 }, {  15,  97, 179 },
-        {   4,  72, 135 }, {   1,  45,  85 }, {   1,  19,  38 }
-      }, {  // Band 4
-        { 124, 146, 240 }, {  66, 124, 224 }, {  17,  88, 175 },
-        {   4,  58, 122 }, {   1,  36,  75 }, {   1,  18,  37 }
-      }, {  //  Band 5
-        { 141,  79, 241 }, { 126,  70, 227 }, {  66,  58, 182 },
-        {  30,  44, 136 }, {  12,  34,  96 }, {   2,  20,  47 }
-      }
-    }, {  // Inter
-      {  // Band 0
-        { 229,  99, 249 }, { 143, 111, 235 }, {  46, 109, 192 }
-      }, {  // Band 1
-        {  82, 158, 236 }, {  94, 146, 224 }, {  25, 117, 191 },
-        {   9,  87, 149 }, {   3,  56,  99 }, {   1,  33,  57 }
-      }, {  // Band 2
-        {  83, 167, 237 }, {  68, 145, 222 }, {  10, 103, 177 },
-        {   2,  72, 131 }, {   1,  41,  79 }, {   1,  20,  39 }
-      }, {  // Band 3
-        {  99, 167, 239 }, {  47, 141, 224 }, {  10, 104, 178 },
-        {   2,  73, 133 }, {   1,  44,  85 }, {   1,  22,  47 }
-      }, {  // Band 4
-        { 127, 145, 243 }, {  71, 129, 228 }, {  17,  93, 177 },
-        {   3,  61, 124 }, {   1,  41,  84 }, {   1,  21,  52 }
-      }, {  // Band 5
-        { 157,  78, 244 }, { 140,  72, 231 }, {  69,  58, 184 },
-        {  31,  44, 137 }, {  14,  38, 105 }, {   8,  23,  61 }
-      }
-    }
-  }
-};
-
-static const vp9_coeff_probs_model default_coef_probs_8x8[PLANE_TYPES] = {
-  {  // Y plane
-    {  // Intra
-      {  // Band 0
-        { 125,  34, 187 }, {  52,  41, 133 }, {   6,  31,  56 }
-      }, {  // Band 1
-        {  37, 109, 153 }, {  51, 102, 147 }, {  23,  87, 128 },
-        {   8,  67, 101 }, {   1,  41,  63 }, {   1,  19,  29 }
-      }, {  // Band 2
-        {  31, 154, 185 }, {  17, 127, 175 }, {   6,  96, 145 },
-        {   2,  73, 114 }, {   1,  51,  82 }, {   1,  28,  45 }
-      }, {  // Band 3
-        {  23, 163, 200 }, {  10, 131, 185 }, {   2,  93, 148 },
-        {   1,  67, 111 }, {   1,  41,  69 }, {   1,  14,  24 }
-      }, {  // Band 4
-        {  29, 176, 217 }, {  12, 145, 201 }, {   3, 101, 156 },
-        {   1,  69, 111 }, {   1,  39,  63 }, {   1,  14,  23 }
-      }, {  // Band 5
-        {  57, 192, 233 }, {  25, 154, 215 }, {   6, 109, 167 },
-        {   3,  78, 118 }, {   1,  48,  69 }, {   1,  21,  29 }
-      }
-    }, {  // Inter
-      {  // Band 0
-        { 202, 105, 245 }, { 108, 106, 216 }, {  18,  90, 144 }
-      }, {  // Band 1
-        {  33, 172, 219 }, {  64, 149, 206 }, {  14, 117, 177 },
-        {   5,  90, 141 }, {   2,  61,  95 }, {   1,  37,  57 }
-      }, {  // Band 2
-        {  33, 179, 220 }, {  11, 140, 198 }, {   1,  89, 148 },
-        {   1,  60, 104 }, {   1,  33,  57 }, {   1,  12,  21 }
-      }, {  // Band 3
-        {  30, 181, 221 }, {   8, 141, 198 }, {   1,  87, 145 },
-        {   1,  58, 100 }, {   1,  31,  55 }, {   1,  12,  20 }
-      }, {  // Band 4
-        {  32, 186, 224 }, {   7, 142, 198 }, {   1,  86, 143 },
-        {   1,  58, 100 }, {   1,  31,  55 }, {   1,  12,  22 }
-      }, {  // Band 5
-        {  57, 192, 227 }, {  20, 143, 204 }, {   3,  96, 154 },
-        {   1,  68, 112 }, {   1,  42,  69 }, {   1,  19,  32 }
-      }
-    }
-  }, {  // UV plane
-    {  // Intra
-      {  // Band 0
-        { 212,  35, 215 }, { 113,  47, 169 }, {  29,  48, 105 }
-      }, {  // Band 1
-        {  74, 129, 203 }, { 106, 120, 203 }, {  49, 107, 178 },
-        {  19,  84, 144 }, {   4,  50,  84 }, {   1,  15,  25 }
-      }, {  // Band 2
-        {  71, 172, 217 }, {  44, 141, 209 }, {  15, 102, 173 },
-        {   6,  76, 133 }, {   2,  51,  89 }, {   1,  24,  42 }
-      }, {  // Band 3
-        {  64, 185, 231 }, {  31, 148, 216 }, {   8, 103, 175 },
-        {   3,  74, 131 }, {   1,  46,  81 }, {   1,  18,  30 }
-      }, {  // Band 4
-        {  65, 196, 235 }, {  25, 157, 221 }, {   5, 105, 174 },
-        {   1,  67, 120 }, {   1,  38,  69 }, {   1,  15,  30 }
-      }, {  // Band 5
-        {  65, 204, 238 }, {  30, 156, 224 }, {   7, 107, 177 },
-        {   2,  70, 124 }, {   1,  42,  73 }, {   1,  18,  34 }
-      }
-    }, {  // Inter
-      {  // Band 0
-        { 225,  86, 251 }, { 144, 104, 235 }, {  42,  99, 181 }
-      }, {  // Band 1
-        {  85, 175, 239 }, { 112, 165, 229 }, {  29, 136, 200 },
-        {  12, 103, 162 }, {   6,  77, 123 }, {   2,  53,  84 }
-      }, {  // Band 2
-        {  75, 183, 239 }, {  30, 155, 221 }, {   3, 106, 171 },
-        {   1,  74, 128 }, {   1,  44,  76 }, {   1,  17,  28 }
-      }, {  // Band 3
-        {  73, 185, 240 }, {  27, 159, 222 }, {   2, 107, 172 },
-        {   1,  75, 127 }, {   1,  42,  73 }, {   1,  17,  29 }
-      }, {  // Band 4
-        {  62, 190, 238 }, {  21, 159, 222 }, {   2, 107, 172 },
-        {   1,  72, 122 }, {   1,  40,  71 }, {   1,  18,  32 }
-      }, {  // Band 5
-        {  61, 199, 240 }, {  27, 161, 226 }, {   4, 113, 180 },
-        {   1,  76, 129 }, {   1,  46,  80 }, {   1,  23,  41 }
-      }
-    }
-  }
-};
-
-static const vp9_coeff_probs_model default_coef_probs_16x16[PLANE_TYPES] = {
-  {  // Y plane
-    {  // Intra
-      {  // Band 0
-        {   7,  27, 153 }, {   5,  30,  95 }, {   1,  16,  30 }
-      }, {  // Band 1
-        {  50,  75, 127 }, {  57,  75, 124 }, {  27,  67, 108 },
-        {  10,  54,  86 }, {   1,  33,  52 }, {   1,  12,  18 }
-      }, {  // Band 2
-        {  43, 125, 151 }, {  26, 108, 148 }, {   7,  83, 122 },
-        {   2,  59,  89 }, {   1,  38,  60 }, {   1,  17,  27 }
-      }, {  // Band 3
-        {  23, 144, 163 }, {  13, 112, 154 }, {   2,  75, 117 },
-        {   1,  50,  81 }, {   1,  31,  51 }, {   1,  14,  23 }
-      }, {  // Band 4
-        {  18, 162, 185 }, {   6, 123, 171 }, {   1,  78, 125 },
-        {   1,  51,  86 }, {   1,  31,  54 }, {   1,  14,  23 }
-      }, {  // Band 5
-        {  15, 199, 227 }, {   3, 150, 204 }, {   1,  91, 146 },
-        {   1,  55,  95 }, {   1,  30,  53 }, {   1,  11,  20 }
-      }
-    }, {  // Inter
-      {  // Band 0
-        {  19,  55, 240 }, {  19,  59, 196 }, {   3,  52, 105 }
-      }, {  // Band 1
-        {  41, 166, 207 }, { 104, 153, 199 }, {  31, 123, 181 },
-        {  14, 101, 152 }, {   5,  72, 106 }, {   1,  36,  52 }
-      }, {  // Band 2
-        {  35, 176, 211 }, {  12, 131, 190 }, {   2,  88, 144 },
-        {   1,  60, 101 }, {   1,  36,  60 }, {   1,  16,  28 }
-      }, {  // Band 3
-        {  28, 183, 213 }, {   8, 134, 191 }, {   1,  86, 142 },
-        {   1,  56,  96 }, {   1,  30,  53 }, {   1,  12,  20 }
-      }, {  // Band 4
-        {  20, 190, 215 }, {   4, 135, 192 }, {   1,  84, 139 },
-        {   1,  53,  91 }, {   1,  28,  49 }, {   1,  11,  20 }
-      }, {  // Band 5
-        {  13, 196, 216 }, {   2, 137, 192 }, {   1,  86, 143 },
-        {   1,  57,  99 }, {   1,  32,  56 }, {   1,  13,  24 }
-      }
-    }
-  }, {  // UV plane
-    {  // Intra
-      {  // Band 0
-        { 211,  29, 217 }, {  96,  47, 156 }, {  22,  43,  87 }
-      }, {  // Band 1
-        {  78, 120, 193 }, { 111, 116, 186 }, {  46, 102, 164 },
-        {  15,  80, 128 }, {   2,  49,  76 }, {   1,  18,  28 }
-      }, {  // Band 2
-        {  71, 161, 203 }, {  42, 132, 192 }, {  10,  98, 150 },
-        {   3,  69, 109 }, {   1,  44,  70 }, {   1,  18,  29 }
-      }, {  // Band 3
-        {  57, 186, 211 }, {  30, 140, 196 }, {   4,  93, 146 },
-        {   1,  62, 102 }, {   1,  38,  65 }, {   1,  16,  27 }
-      }, {  // Band 4
-        {  47, 199, 217 }, {  14, 145, 196 }, {   1,  88, 142 },
-        {   1,  57,  98 }, {   1,  36,  62 }, {   1,  15,  26 }
-      }, {  // Band 5
-        {  26, 219, 229 }, {   5, 155, 207 }, {   1,  94, 151 },
-        {   1,  60, 104 }, {   1,  36,  62 }, {   1,  16,  28 }
-      }
-    }, {  // Inter
-      {  // Band 0
-        { 233,  29, 248 }, { 146,  47, 220 }, {  43,  52, 140 }
-      }, {  // Band 1
-        { 100, 163, 232 }, { 179, 161, 222 }, {  63, 142, 204 },
-        {  37, 113, 174 }, {  26,  89, 137 }, {  18,  68,  97 }
-      }, {  // Band 2
-        {  85, 181, 230 }, {  32, 146, 209 }, {   7, 100, 164 },
-        {   3,  71, 121 }, {   1,  45,  77 }, {   1,  18,  30 }
-      }, {  // Band 3
-        {  65, 187, 230 }, {  20, 148, 207 }, {   2,  97, 159 },
-        {   1,  68, 116 }, {   1,  40,  70 }, {   1,  14,  29 }
-      }, {  // Band 4
-        {  40, 194, 227 }, {   8, 147, 204 }, {   1,  94, 155 },
-        {   1,  65, 112 }, {   1,  39,  66 }, {   1,  14,  26 }
-      }, {  // Band 5
-        {  16, 208, 228 }, {   3, 151, 207 }, {   1,  98, 160 },
-        {   1,  67, 117 }, {   1,  41,  74 }, {   1,  17,  31 }
-      }
-    }
-  }
-};
-
-static const vp9_coeff_probs_model default_coef_probs_32x32[PLANE_TYPES] = {
-  {  // Y plane
-    {  // Intra
-      {  // Band 0
-        {  17,  38, 140 }, {   7,  34,  80 }, {   1,  17,  29 }
-      }, {  // Band 1
-        {  37,  75, 128 }, {  41,  76, 128 }, {  26,  66, 116 },
-        {  12,  52,  94 }, {   2,  32,  55 }, {   1,  10,  16 }
-      }, {  // Band 2
-        {  50, 127, 154 }, {  37, 109, 152 }, {  16,  82, 121 },
-        {   5,  59,  85 }, {   1,  35,  54 }, {   1,  13,  20 }
-      }, {  // Band 3
-        {  40, 142, 167 }, {  17, 110, 157 }, {   2,  71, 112 },
-        {   1,  44,  72 }, {   1,  27,  45 }, {   1,  11,  17 }
-      }, {  // Band 4
-        {  30, 175, 188 }, {   9, 124, 169 }, {   1,  74, 116 },
-        {   1,  48,  78 }, {   1,  30,  49 }, {   1,  11,  18 }
-      }, {  // Band 5
-        {  10, 222, 223 }, {   2, 150, 194 }, {   1,  83, 128 },
-        {   1,  48,  79 }, {   1,  27,  45 }, {   1,  11,  17 }
-      }
-    }, {  // Inter
-      {  // Band 0
-        {  36,  41, 235 }, {  29,  36, 193 }, {  10,  27, 111 }
-      }, {  // Band 1
-        {  85, 165, 222 }, { 177, 162, 215 }, { 110, 135, 195 },
-        {  57, 113, 168 }, {  23,  83, 120 }, {  10,  49,  61 }
-      }, {  // Band 2
-        {  85, 190, 223 }, {  36, 139, 200 }, {   5,  90, 146 },
-        {   1,  60, 103 }, {   1,  38,  65 }, {   1,  18,  30 }
-      }, {  // Band 3
-        {  72, 202, 223 }, {  23, 141, 199 }, {   2,  86, 140 },
-        {   1,  56,  97 }, {   1,  36,  61 }, {   1,  16,  27 }
-      }, {  // Band 4
-        {  55, 218, 225 }, {  13, 145, 200 }, {   1,  86, 141 },
-        {   1,  57,  99 }, {   1,  35,  61 }, {   1,  13,  22 }
-      }, {  // Band 5
-        {  15, 235, 212 }, {   1, 132, 184 }, {   1,  84, 139 },
-        {   1,  57,  97 }, {   1,  34,  56 }, {   1,  14,  23 }
-      }
-    }
-  }, {  // UV plane
-    {  // Intra
-      {  // Band 0
-        { 181,  21, 201 }, {  61,  37, 123 }, {  10,  38,  71 }
-      }, {  // Band 1
-        {  47, 106, 172 }, {  95, 104, 173 }, {  42,  93, 159 },
-        {  18,  77, 131 }, {   4,  50,  81 }, {   1,  17,  23 }
-      }, {  // Band 2
-        {  62, 147, 199 }, {  44, 130, 189 }, {  28, 102, 154 },
-        {  18,  75, 115 }, {   2,  44,  65 }, {   1,  12,  19 }
-      }, {  // Band 3
-        {  55, 153, 210 }, {  24, 130, 194 }, {   3,  93, 146 },
-        {   1,  61,  97 }, {   1,  31,  50 }, {   1,  10,  16 }
-      }, {  // Band 4
-        {  49, 186, 223 }, {  17, 148, 204 }, {   1,  96, 142 },
-        {   1,  53,  83 }, {   1,  26,  44 }, {   1,  11,  17 }
-      }, {  // Band 5
-        {  13, 217, 212 }, {   2, 136, 180 }, {   1,  78, 124 },
-        {   1,  50,  83 }, {   1,  29,  49 }, {   1,  14,  23 }
-      }
-    }, {  // Inter
-      {  // Band 0
-        { 197,  13, 247 }, {  82,  17, 222 }, {  25,  17, 162 }
-      }, {  // Band 1
-        { 126, 186, 247 }, { 234, 191, 243 }, { 176, 177, 234 },
-        { 104, 158, 220 }, {  66, 128, 186 }, {  55,  90, 137 }
-      }, {  // Band 2
-        { 111, 197, 242 }, {  46, 158, 219 }, {   9, 104, 171 },
-        {   2,  65, 125 }, {   1,  44,  80 }, {   1,  17,  91 }
-      }, {  // Band 3
-        { 104, 208, 245 }, {  39, 168, 224 }, {   3, 109, 162 },
-        {   1,  79, 124 }, {   1,  50, 102 }, {   1,  43, 102 }
-      }, {  // Band 4
-        {  84, 220, 246 }, {  31, 177, 231 }, {   2, 115, 180 },
-        {   1,  79, 134 }, {   1,  55,  77 }, {   1,  60,  79 }
-      }, {  // Band 5
-        {  43, 243, 240 }, {   8, 180, 217 }, {   1, 115, 166 },
-        {   1,  84, 121 }, {   1,  51,  67 }, {   1,  16,   6 }
-      }
-    }
-  }
-};
-
-static void extend_to_full_distribution(vpx_prob *probs, vpx_prob p) {
-  assert(p != 0);
-  memcpy(probs, vp9_pareto8_full[p - 1], MODEL_NODES * sizeof(vpx_prob));
-}
-
-void vp9_model_to_full_probs(const vpx_prob *model, vpx_prob *full) {
-  if (full != model)
-    memcpy(full, model, sizeof(vpx_prob) * UNCONSTRAINED_NODES);
-  extend_to_full_distribution(&full[UNCONSTRAINED_NODES], model[PIVOT_NODE]);
-}
-
-void vp9_default_coef_probs(VP9_COMMON *cm) {
-  vp9_copy(cm->fc->coef_probs[TX_4X4], default_coef_probs_4x4);
-  vp9_copy(cm->fc->coef_probs[TX_8X8], default_coef_probs_8x8);
-  vp9_copy(cm->fc->coef_probs[TX_16X16], default_coef_probs_16x16);
-  vp9_copy(cm->fc->coef_probs[TX_32X32], default_coef_probs_32x32);
-}
-
-#define COEF_COUNT_SAT 24
-#define COEF_MAX_UPDATE_FACTOR 112
-#define COEF_COUNT_SAT_KEY 24
-#define COEF_MAX_UPDATE_FACTOR_KEY 112
-#define COEF_COUNT_SAT_AFTER_KEY 24
-#define COEF_MAX_UPDATE_FACTOR_AFTER_KEY 128
-
-static void adapt_coef_probs(VP9_COMMON *cm, TX_SIZE tx_size,
-                             unsigned int count_sat,
-                             unsigned int update_factor) {
-  const FRAME_CONTEXT *pre_fc = &cm->frame_contexts[cm->frame_context_idx];
-  vp9_coeff_probs_model *const probs = cm->fc->coef_probs[tx_size];
-  const vp9_coeff_probs_model *const pre_probs = pre_fc->coef_probs[tx_size];
-  vp9_coeff_count_model *counts = cm->counts.coef[tx_size];
-  unsigned int (*eob_counts)[REF_TYPES][COEF_BANDS][COEFF_CONTEXTS] =
-      cm->counts.eob_branch[tx_size];
-  int i, j, k, l, m;
-
-  for (i = 0; i < PLANE_TYPES; ++i)
-    for (j = 0; j < REF_TYPES; ++j)
-      for (k = 0; k < COEF_BANDS; ++k)
-        for (l = 0; l < BAND_COEFF_CONTEXTS(k); ++l) {
-          const int n0 = counts[i][j][k][l][ZERO_TOKEN];
-          const int n1 = counts[i][j][k][l][ONE_TOKEN];
-          const int n2 = counts[i][j][k][l][TWO_TOKEN];
-          const int neob = counts[i][j][k][l][EOB_MODEL_TOKEN];
-          const unsigned int branch_ct[UNCONSTRAINED_NODES][2] = {
-            { neob, eob_counts[i][j][k][l] - neob },
-            { n0, n1 + n2 },
-            { n1, n2 }
-          };
-          for (m = 0; m < UNCONSTRAINED_NODES; ++m)
-            probs[i][j][k][l][m] = merge_probs(pre_probs[i][j][k][l][m],
-                                               branch_ct[m],
-                                               count_sat, update_factor);
-        }
-}
-
-void vp9_adapt_coef_probs(VP9_COMMON *cm) {
-  TX_SIZE t;
-  unsigned int count_sat, update_factor;
-
-  if (frame_is_intra_only(cm)) {
-    update_factor = COEF_MAX_UPDATE_FACTOR_KEY;
-    count_sat = COEF_COUNT_SAT_KEY;
-  } else if (cm->last_frame_type == KEY_FRAME) {
-    update_factor = COEF_MAX_UPDATE_FACTOR_AFTER_KEY;  /* adapt quickly */
-    count_sat = COEF_COUNT_SAT_AFTER_KEY;
-  } else {
-    update_factor = COEF_MAX_UPDATE_FACTOR;
-    count_sat = COEF_COUNT_SAT;
-  }
-  for (t = TX_4X4; t <= TX_32X32; t++)
-    adapt_coef_probs(cm, t, count_sat, update_factor);
-}
diff --git a/vp9/common/vp9_entropy.h b/vp9/common/vp9_entropy.h
deleted file mode 100644 (file)
index 63b3bff..0000000
+++ /dev/null
@@ -1,200 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#ifndef VP9_COMMON_VP9_ENTROPY_H_
-#define VP9_COMMON_VP9_ENTROPY_H_
-
-#include "vpx/vpx_integer.h"
-#include "vpx_dsp/prob.h"
-
-#include "vp9/common/vp9_common.h"
-#include "vp9/common/vp9_enums.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define DIFF_UPDATE_PROB 252
-
-// Coefficient token alphabet
-#define ZERO_TOKEN      0   // 0     Extra Bits 0+0
-#define ONE_TOKEN       1   // 1     Extra Bits 0+1
-#define TWO_TOKEN       2   // 2     Extra Bits 0+1
-#define THREE_TOKEN     3   // 3     Extra Bits 0+1
-#define FOUR_TOKEN      4   // 4     Extra Bits 0+1
-#define CATEGORY1_TOKEN 5   // 5-6   Extra Bits 1+1
-#define CATEGORY2_TOKEN 6   // 7-10  Extra Bits 2+1
-#define CATEGORY3_TOKEN 7   // 11-18 Extra Bits 3+1
-#define CATEGORY4_TOKEN 8   // 19-34 Extra Bits 4+1
-#define CATEGORY5_TOKEN 9   // 35-66 Extra Bits 5+1
-#define CATEGORY6_TOKEN 10  // 67+   Extra Bits 14+1
-#define EOB_TOKEN       11  // EOB   Extra Bits 0+0
-
-#define ENTROPY_TOKENS 12
-
-#define ENTROPY_NODES 11
-
-DECLARE_ALIGNED(16, extern const uint8_t, vp9_pt_energy_class[ENTROPY_TOKENS]);
-
-#define CAT1_MIN_VAL    5
-#define CAT2_MIN_VAL    7
-#define CAT3_MIN_VAL   11
-#define CAT4_MIN_VAL   19
-#define CAT5_MIN_VAL   35
-#define CAT6_MIN_VAL   67
-
-// Extra bit probabilities.
-DECLARE_ALIGNED(16, extern const uint8_t, vp9_cat1_prob[1]);
-DECLARE_ALIGNED(16, extern const uint8_t, vp9_cat2_prob[2]);
-DECLARE_ALIGNED(16, extern const uint8_t, vp9_cat3_prob[3]);
-DECLARE_ALIGNED(16, extern const uint8_t, vp9_cat4_prob[4]);
-DECLARE_ALIGNED(16, extern const uint8_t, vp9_cat5_prob[5]);
-DECLARE_ALIGNED(16, extern const uint8_t, vp9_cat6_prob[14]);
-
-#if CONFIG_VP9_HIGHBITDEPTH
-DECLARE_ALIGNED(16, extern const uint8_t, vp9_cat1_prob_high10[1]);
-DECLARE_ALIGNED(16, extern const uint8_t, vp9_cat2_prob_high10[2]);
-DECLARE_ALIGNED(16, extern const uint8_t, vp9_cat3_prob_high10[3]);
-DECLARE_ALIGNED(16, extern const uint8_t, vp9_cat4_prob_high10[4]);
-DECLARE_ALIGNED(16, extern const uint8_t, vp9_cat5_prob_high10[5]);
-DECLARE_ALIGNED(16, extern const uint8_t, vp9_cat6_prob_high10[16]);
-DECLARE_ALIGNED(16, extern const uint8_t, vp9_cat1_prob_high12[1]);
-DECLARE_ALIGNED(16, extern const uint8_t, vp9_cat2_prob_high12[2]);
-DECLARE_ALIGNED(16, extern const uint8_t, vp9_cat3_prob_high12[3]);
-DECLARE_ALIGNED(16, extern const uint8_t, vp9_cat4_prob_high12[4]);
-DECLARE_ALIGNED(16, extern const uint8_t, vp9_cat5_prob_high12[5]);
-DECLARE_ALIGNED(16, extern const uint8_t, vp9_cat6_prob_high12[18]);
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-
-#define EOB_MODEL_TOKEN 3
-
-#define DCT_MAX_VALUE           16384
-#if CONFIG_VP9_HIGHBITDEPTH
-#define DCT_MAX_VALUE_HIGH10    65536
-#define DCT_MAX_VALUE_HIGH12   262144
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-
-/* Coefficients are predicted via a 3-dimensional probability table. */
-
-#define REF_TYPES 2  // intra=0, inter=1
-
-/* Middle dimension reflects the coefficient position within the transform. */
-#define COEF_BANDS 6
-
-/* Inside dimension is measure of nearby complexity, that reflects the energy
-   of nearby coefficients are nonzero.  For the first coefficient (DC, unless
-   block type is 0), we look at the (already encoded) blocks above and to the
-   left of the current block.  The context index is then the number (0,1,or 2)
-   of these blocks having nonzero coefficients.
-   After decoding a coefficient, the measure is determined by the size of the
-   most recently decoded coefficient.
-   Note that the intuitive meaning of this measure changes as coefficients
-   are decoded, e.g., prior to the first token, a zero means that my neighbors
-   are empty while, after the first token, because of the use of end-of-block,
-   a zero means we just decoded a zero and hence guarantees that a non-zero
-   coefficient will appear later in this block.  However, this shift
-   in meaning is perfectly OK because our context depends also on the
-   coefficient band (and since zigzag positions 0, 1, and 2 are in
-   distinct bands). */
-
-#define COEFF_CONTEXTS 6
-#define BAND_COEFF_CONTEXTS(band) ((band) == 0 ? 3 : COEFF_CONTEXTS)
-
-// #define ENTROPY_STATS
-
-typedef unsigned int vp9_coeff_count[REF_TYPES][COEF_BANDS][COEFF_CONTEXTS]
-                                    [ENTROPY_TOKENS];
-typedef unsigned int vp9_coeff_stats[REF_TYPES][COEF_BANDS][COEFF_CONTEXTS]
-                                    [ENTROPY_NODES][2];
-
-#define SUBEXP_PARAM                4   /* Subexponential code parameter */
-#define MODULUS_PARAM               13  /* Modulus parameter */
-
-struct VP9Common;
-void vp9_default_coef_probs(struct VP9Common *cm);
-void vp9_adapt_coef_probs(struct VP9Common *cm);
-
-// This is the index in the scan order beyond which all coefficients for
-// 8x8 transform and above are in the top band.
-// This macro is currently unused but may be used by certain implementations
-#define MAXBAND_INDEX 21
-
-DECLARE_ALIGNED(16, extern const uint8_t, vp9_coefband_trans_8x8plus[1024]);
-DECLARE_ALIGNED(16, extern const uint8_t, vp9_coefband_trans_4x4[16]);
-
-static INLINE const uint8_t *get_band_translate(TX_SIZE tx_size) {
-  return tx_size == TX_4X4 ? vp9_coefband_trans_4x4
-                           : vp9_coefband_trans_8x8plus;
-}
-
-// 128 lists of probabilities are stored for the following ONE node probs:
-// 1, 3, 5, 7, ..., 253, 255
-// In between probabilities are interpolated linearly
-
-#define COEFF_PROB_MODELS 255
-
-#define UNCONSTRAINED_NODES         3
-
-#define PIVOT_NODE                  2   // which node is pivot
-
-#define MODEL_NODES (ENTROPY_NODES - UNCONSTRAINED_NODES)
-extern const vpx_tree_index vp9_coef_con_tree[TREE_SIZE(ENTROPY_TOKENS)];
-extern const vpx_prob vp9_pareto8_full[COEFF_PROB_MODELS][MODEL_NODES];
-
-typedef vpx_prob vp9_coeff_probs_model[REF_TYPES][COEF_BANDS]
-                                      [COEFF_CONTEXTS][UNCONSTRAINED_NODES];
-
-typedef unsigned int vp9_coeff_count_model[REF_TYPES][COEF_BANDS]
-                                          [COEFF_CONTEXTS]
-                                          [UNCONSTRAINED_NODES + 1];
-
-void vp9_model_to_full_probs(const vpx_prob *model, vpx_prob *full);
-
-typedef char ENTROPY_CONTEXT;
-
-static INLINE int combine_entropy_contexts(ENTROPY_CONTEXT a,
-                                           ENTROPY_CONTEXT b) {
-  return (a != 0) + (b != 0);
-}
-
-static INLINE int get_entropy_context(TX_SIZE tx_size, const ENTROPY_CONTEXT *a,
-                                      const ENTROPY_CONTEXT *l) {
-  ENTROPY_CONTEXT above_ec = 0, left_ec = 0;
-
-  switch (tx_size) {
-    case TX_4X4:
-      above_ec = a[0] != 0;
-      left_ec = l[0] != 0;
-      break;
-    case TX_8X8:
-      above_ec = !!*(const uint16_t *)a;
-      left_ec  = !!*(const uint16_t *)l;
-      break;
-    case TX_16X16:
-      above_ec = !!*(const uint32_t *)a;
-      left_ec  = !!*(const uint32_t *)l;
-      break;
-    case TX_32X32:
-      above_ec = !!*(const uint64_t *)a;
-      left_ec  = !!*(const uint64_t *)l;
-      break;
-    default:
-      assert(0 && "Invalid transform size.");
-      break;
-  }
-
-  return combine_entropy_contexts(above_ec, left_ec);
-}
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP9_COMMON_VP9_ENTROPY_H_
diff --git a/vp9/common/vp9_entropymode.c b/vp9/common/vp9_entropymode.c
deleted file mode 100644 (file)
index 670348b..0000000
+++ /dev/null
@@ -1,469 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#include "vpx_mem/vpx_mem.h"
-
-#include "vp9/common/vp9_onyxc_int.h"
-#include "vp9/common/vp9_seg_common.h"
-
-const vpx_prob vp9_kf_y_mode_prob[INTRA_MODES][INTRA_MODES][INTRA_MODES - 1] = {
-  {  // above = dc
-    { 137,  30,  42, 148, 151, 207,  70,  52,  91 },  // left = dc
-    {  92,  45, 102, 136, 116, 180,  74,  90, 100 },  // left = v
-    {  73,  32,  19, 187, 222, 215,  46,  34, 100 },  // left = h
-    {  91,  30,  32, 116, 121, 186,  93,  86,  94 },  // left = d45
-    {  72,  35,  36, 149,  68, 206,  68,  63, 105 },  // left = d135
-    {  73,  31,  28, 138,  57, 124,  55, 122, 151 },  // left = d117
-    {  67,  23,  21, 140, 126, 197,  40,  37, 171 },  // left = d153
-    {  86,  27,  28, 128, 154, 212,  45,  43,  53 },  // left = d207
-    {  74,  32,  27, 107,  86, 160,  63, 134, 102 },  // left = d63
-    {  59,  67,  44, 140, 161, 202,  78,  67, 119 }   // left = tm
-  }, {  // above = v
-    {  63,  36, 126, 146, 123, 158,  60,  90,  96 },  // left = dc
-    {  43,  46, 168, 134, 107, 128,  69, 142,  92 },  // left = v
-    {  44,  29,  68, 159, 201, 177,  50,  57,  77 },  // left = h
-    {  58,  38,  76, 114,  97, 172,  78, 133,  92 },  // left = d45
-    {  46,  41,  76, 140,  63, 184,  69, 112,  57 },  // left = d135
-    {  38,  32,  85, 140,  46, 112,  54, 151, 133 },  // left = d117
-    {  39,  27,  61, 131, 110, 175,  44,  75, 136 },  // left = d153
-    {  52,  30,  74, 113, 130, 175,  51,  64,  58 },  // left = d207
-    {  47,  35,  80, 100,  74, 143,  64, 163,  74 },  // left = d63
-    {  36,  61, 116, 114, 128, 162,  80, 125,  82 }   // left = tm
-  }, {  // above = h
-    {  82,  26,  26, 171, 208, 204,  44,  32, 105 },  // left = dc
-    {  55,  44,  68, 166, 179, 192,  57,  57, 108 },  // left = v
-    {  42,  26,  11, 199, 241, 228,  23,  15,  85 },  // left = h
-    {  68,  42,  19, 131, 160, 199,  55,  52,  83 },  // left = d45
-    {  58,  50,  25, 139, 115, 232,  39,  52, 118 },  // left = d135
-    {  50,  35,  33, 153, 104, 162,  64,  59, 131 },  // left = d117
-    {  44,  24,  16, 150, 177, 202,  33,  19, 156 },  // left = d153
-    {  55,  27,  12, 153, 203, 218,  26,  27,  49 },  // left = d207
-    {  53,  49,  21, 110, 116, 168,  59,  80,  76 },  // left = d63
-    {  38,  72,  19, 168, 203, 212,  50,  50, 107 }   // left = tm
-  }, {  // above = d45
-    { 103,  26,  36, 129, 132, 201,  83,  80,  93 },  // left = dc
-    {  59,  38,  83, 112, 103, 162,  98, 136,  90 },  // left = v
-    {  62,  30,  23, 158, 200, 207,  59,  57,  50 },  // left = h
-    {  67,  30,  29,  84,  86, 191, 102,  91,  59 },  // left = d45
-    {  60,  32,  33, 112,  71, 220,  64,  89, 104 },  // left = d135
-    {  53,  26,  34, 130,  56, 149,  84, 120, 103 },  // left = d117
-    {  53,  21,  23, 133, 109, 210,  56,  77, 172 },  // left = d153
-    {  77,  19,  29, 112, 142, 228,  55,  66,  36 },  // left = d207
-    {  61,  29,  29,  93,  97, 165,  83, 175, 162 },  // left = d63
-    {  47,  47,  43, 114, 137, 181, 100,  99,  95 }   // left = tm
-  }, {  // above = d135
-    {  69,  23,  29, 128,  83, 199,  46,  44, 101 },  // left = dc
-    {  53,  40,  55, 139,  69, 183,  61,  80, 110 },  // left = v
-    {  40,  29,  19, 161, 180, 207,  43,  24,  91 },  // left = h
-    {  60,  34,  19, 105,  61, 198,  53,  64,  89 },  // left = d45
-    {  52,  31,  22, 158,  40, 209,  58,  62,  89 },  // left = d135
-    {  44,  31,  29, 147,  46, 158,  56, 102, 198 },  // left = d117
-    {  35,  19,  12, 135,  87, 209,  41,  45, 167 },  // left = d153
-    {  55,  25,  21, 118,  95, 215,  38,  39,  66 },  // left = d207
-    {  51,  38,  25, 113,  58, 164,  70,  93,  97 },  // left = d63
-    {  47,  54,  34, 146, 108, 203,  72, 103, 151 }   // left = tm
-  }, {  // above = d117
-    {  64,  19,  37, 156,  66, 138,  49,  95, 133 },  // left = dc
-    {  46,  27,  80, 150,  55, 124,  55, 121, 135 },  // left = v
-    {  36,  23,  27, 165, 149, 166,  54,  64, 118 },  // left = h
-    {  53,  21,  36, 131,  63, 163,  60, 109,  81 },  // left = d45
-    {  40,  26,  35, 154,  40, 185,  51,  97, 123 },  // left = d135
-    {  35,  19,  34, 179,  19,  97,  48, 129, 124 },  // left = d117
-    {  36,  20,  26, 136,  62, 164,  33,  77, 154 },  // left = d153
-    {  45,  18,  32, 130,  90, 157,  40,  79,  91 },  // left = d207
-    {  45,  26,  28, 129,  45, 129,  49, 147, 123 },  // left = d63
-    {  38,  44,  51, 136,  74, 162,  57,  97, 121 }   // left = tm
-  }, {  // above = d153
-    {  75,  17,  22, 136, 138, 185,  32,  34, 166 },  // left = dc
-    {  56,  39,  58, 133, 117, 173,  48,  53, 187 },  // left = v
-    {  35,  21,  12, 161, 212, 207,  20,  23, 145 },  // left = h
-    {  56,  29,  19, 117, 109, 181,  55,  68, 112 },  // left = d45
-    {  47,  29,  17, 153,  64, 220,  59,  51, 114 },  // left = d135
-    {  46,  16,  24, 136,  76, 147,  41,  64, 172 },  // left = d117
-    {  34,  17,  11, 108, 152, 187,  13,  15, 209 },  // left = d153
-    {  51,  24,  14, 115, 133, 209,  32,  26, 104 },  // left = d207
-    {  55,  30,  18, 122,  79, 179,  44,  88, 116 },  // left = d63
-    {  37,  49,  25, 129, 168, 164,  41,  54, 148 }   // left = tm
-  }, {  // above = d207
-    {  82,  22,  32, 127, 143, 213,  39,  41,  70 },  // left = dc
-    {  62,  44,  61, 123, 105, 189,  48,  57,  64 },  // left = v
-    {  47,  25,  17, 175, 222, 220,  24,  30,  86 },  // left = h
-    {  68,  36,  17, 106, 102, 206,  59,  74,  74 },  // left = d45
-    {  57,  39,  23, 151,  68, 216,  55,  63,  58 },  // left = d135
-    {  49,  30,  35, 141,  70, 168,  82,  40, 115 },  // left = d117
-    {  51,  25,  15, 136, 129, 202,  38,  35, 139 },  // left = d153
-    {  68,  26,  16, 111, 141, 215,  29,  28,  28 },  // left = d207
-    {  59,  39,  19, 114,  75, 180,  77, 104,  42 },  // left = d63
-    {  40,  61,  26, 126, 152, 206,  61,  59,  93 }   // left = tm
-  }, {  // above = d63
-    {  78,  23,  39, 111, 117, 170,  74, 124,  94 },  // left = dc
-    {  48,  34,  86, 101,  92, 146,  78, 179, 134 },  // left = v
-    {  47,  22,  24, 138, 187, 178,  68,  69,  59 },  // left = h
-    {  56,  25,  33, 105, 112, 187,  95, 177, 129 },  // left = d45
-    {  48,  31,  27, 114,  63, 183,  82, 116,  56 },  // left = d135
-    {  43,  28,  37, 121,  63, 123,  61, 192, 169 },  // left = d117
-    {  42,  17,  24, 109,  97, 177,  56,  76, 122 },  // left = d153
-    {  58,  18,  28, 105, 139, 182,  70,  92,  63 },  // left = d207
-    {  46,  23,  32,  74,  86, 150,  67, 183,  88 },  // left = d63
-    {  36,  38,  48,  92, 122, 165,  88, 137,  91 }   // left = tm
-  }, {  // above = tm
-    {  65,  70,  60, 155, 159, 199,  61,  60,  81 },  // left = dc
-    {  44,  78, 115, 132, 119, 173,  71, 112,  93 },  // left = v
-    {  39,  38,  21, 184, 227, 206,  42,  32,  64 },  // left = h
-    {  58,  47,  36, 124, 137, 193,  80,  82,  78 },  // left = d45
-    {  49,  50,  35, 144,  95, 205,  63,  78,  59 },  // left = d135
-    {  41,  53,  52, 148,  71, 142,  65, 128,  51 },  // left = d117
-    {  40,  36,  28, 143, 143, 202,  40,  55, 137 },  // left = d153
-    {  52,  34,  29, 129, 183, 227,  42,  35,  43 },  // left = d207
-    {  42,  44,  44, 104, 105, 164,  64, 130,  80 },  // left = d63
-    {  43,  81,  53, 140, 169, 204,  68,  84,  72 }   // left = tm
-  }
-};
-
-const vpx_prob vp9_kf_uv_mode_prob[INTRA_MODES][INTRA_MODES - 1] = {
-  { 144,  11,  54, 157, 195, 130,  46,  58, 108 },  // y = dc
-  { 118,  15, 123, 148, 131, 101,  44,  93, 131 },  // y = v
-  { 113,  12,  23, 188, 226, 142,  26,  32, 125 },  // y = h
-  { 120,  11,  50, 123, 163, 135,  64,  77, 103 },  // y = d45
-  { 113,   9,  36, 155, 111, 157,  32,  44, 161 },  // y = d135
-  { 116,   9,  55, 176,  76,  96,  37,  61, 149 },  // y = d117
-  { 115,   9,  28, 141, 161, 167,  21,  25, 193 },  // y = d153
-  { 120,  12,  32, 145, 195, 142,  32,  38,  86 },  // y = d207
-  { 116,  12,  64, 120, 140, 125,  49, 115, 121 },  // y = d63
-  { 102,  19,  66, 162, 182, 122,  35,  59, 128 }   // y = tm
-};
-
-static const vpx_prob default_if_y_probs[BLOCK_SIZE_GROUPS][INTRA_MODES - 1] = {
-  {  65,  32,  18, 144, 162, 194,  41,  51,  98 },  // block_size < 8x8
-  { 132,  68,  18, 165, 217, 196,  45,  40,  78 },  // block_size < 16x16
-  { 173,  80,  19, 176, 240, 193,  64,  35,  46 },  // block_size < 32x32
-  { 221, 135,  38, 194, 248, 121,  96,  85,  29 }   // block_size >= 32x32
-};
-
-static const vpx_prob default_if_uv_probs[INTRA_MODES][INTRA_MODES - 1] = {
-  { 120,   7,  76, 176, 208, 126,  28,  54, 103 },  // y = dc
-  {  48,  12, 154, 155, 139,  90,  34, 117, 119 },  // y = v
-  {  67,   6,  25, 204, 243, 158,  13,  21,  96 },  // y = h
-  {  97,   5,  44, 131, 176, 139,  48,  68,  97 },  // y = d45
-  {  83,   5,  42, 156, 111, 152,  26,  49, 152 },  // y = d135
-  {  80,   5,  58, 178,  74,  83,  33,  62, 145 },  // y = d117
-  {  86,   5,  32, 154, 192, 168,  14,  22, 163 },  // y = d153
-  {  85,   5,  32, 156, 216, 148,  19,  29,  73 },  // y = d207
-  {  77,   7,  64, 116, 132, 122,  37, 126, 120 },  // y = d63
-  { 101,  21, 107, 181, 192, 103,  19,  67, 125 }   // y = tm
-};
-
-const vpx_prob vp9_kf_partition_probs[PARTITION_CONTEXTS]
-                                     [PARTITION_TYPES - 1] = {
-  // 8x8 -> 4x4
-  { 158,  97,  94 },  // a/l both not split
-  {  93,  24,  99 },  // a split, l not split
-  {  85, 119,  44 },  // l split, a not split
-  {  62,  59,  67 },  // a/l both split
-  // 16x16 -> 8x8
-  { 149,  53,  53 },  // a/l both not split
-  {  94,  20,  48 },  // a split, l not split
-  {  83,  53,  24 },  // l split, a not split
-  {  52,  18,  18 },  // a/l both split
-  // 32x32 -> 16x16
-  { 150,  40,  39 },  // a/l both not split
-  {  78,  12,  26 },  // a split, l not split
-  {  67,  33,  11 },  // l split, a not split
-  {  24,   7,   5 },  // a/l both split
-  // 64x64 -> 32x32
-  { 174,  35,  49 },  // a/l both not split
-  {  68,  11,  27 },  // a split, l not split
-  {  57,  15,   9 },  // l split, a not split
-  {  12,   3,   3 },  // a/l both split
-};
-
-static const vpx_prob default_partition_probs[PARTITION_CONTEXTS]
-                                             [PARTITION_TYPES - 1] = {
-  // 8x8 -> 4x4
-  { 199, 122, 141 },  // a/l both not split
-  { 147,  63, 159 },  // a split, l not split
-  { 148, 133, 118 },  // l split, a not split
-  { 121, 104, 114 },  // a/l both split
-  // 16x16 -> 8x8
-  { 174,  73,  87 },  // a/l both not split
-  {  92,  41,  83 },  // a split, l not split
-  {  82,  99,  50 },  // l split, a not split
-  {  53,  39,  39 },  // a/l both split
-  // 32x32 -> 16x16
-  { 177,  58,  59 },  // a/l both not split
-  {  68,  26,  63 },  // a split, l not split
-  {  52,  79,  25 },  // l split, a not split
-  {  17,  14,  12 },  // a/l both split
-  // 64x64 -> 32x32
-  { 222,  34,  30 },  // a/l both not split
-  {  72,  16,  44 },  // a split, l not split
-  {  58,  32,  12 },  // l split, a not split
-  {  10,   7,   6 },  // a/l both split
-};
-
-static const vpx_prob default_inter_mode_probs[INTER_MODE_CONTEXTS]
-                                              [INTER_MODES - 1] = {
-  {2,       173,   34},  // 0 = both zero mv
-  {7,       145,   85},  // 1 = one zero mv + one a predicted mv
-  {7,       166,   63},  // 2 = two predicted mvs
-  {7,       94,    66},  // 3 = one predicted/zero and one new mv
-  {8,       64,    46},  // 4 = two new mvs
-  {17,      81,    31},  // 5 = one intra neighbour + x
-  {25,      29,    30},  // 6 = two intra neighbours
-};
-
-/* Array indices are identical to previously-existing INTRAMODECONTEXTNODES. */
-const vpx_tree_index vp9_intra_mode_tree[TREE_SIZE(INTRA_MODES)] = {
-  -DC_PRED, 2,                      /* 0 = DC_NODE */
-  -TM_PRED, 4,                      /* 1 = TM_NODE */
-  -V_PRED, 6,                       /* 2 = V_NODE */
-  8, 12,                            /* 3 = COM_NODE */
-  -H_PRED, 10,                      /* 4 = H_NODE */
-  -D135_PRED, -D117_PRED,           /* 5 = D135_NODE */
-  -D45_PRED, 14,                    /* 6 = D45_NODE */
-  -D63_PRED, 16,                    /* 7 = D63_NODE */
-  -D153_PRED, -D207_PRED             /* 8 = D153_NODE */
-};
-
-const vpx_tree_index vp9_inter_mode_tree[TREE_SIZE(INTER_MODES)] = {
-  -INTER_OFFSET(ZEROMV), 2,
-  -INTER_OFFSET(NEARESTMV), 4,
-  -INTER_OFFSET(NEARMV), -INTER_OFFSET(NEWMV)
-};
-
-const vpx_tree_index vp9_partition_tree[TREE_SIZE(PARTITION_TYPES)] = {
-  -PARTITION_NONE, 2,
-  -PARTITION_HORZ, 4,
-  -PARTITION_VERT, -PARTITION_SPLIT
-};
-
-static const vpx_prob default_intra_inter_p[INTRA_INTER_CONTEXTS] = {
-  9, 102, 187, 225
-};
-
-static const vpx_prob default_comp_inter_p[COMP_INTER_CONTEXTS] = {
-  239, 183, 119,  96,  41
-};
-
-static const vpx_prob default_comp_ref_p[REF_CONTEXTS] = {
-  50, 126, 123, 221, 226
-};
-
-static const vpx_prob default_single_ref_p[REF_CONTEXTS][2] = {
-  {  33,  16 },
-  {  77,  74 },
-  { 142, 142 },
-  { 172, 170 },
-  { 238, 247 }
-};
-
-static const struct tx_probs default_tx_probs = {
-  { { 3, 136, 37 },
-    { 5, 52,  13 } },
-
-  { { 20, 152 },
-    { 15, 101 } },
-
-  { { 100 },
-    { 66  } }
-};
-
-void tx_counts_to_branch_counts_32x32(const unsigned int *tx_count_32x32p,
-                                      unsigned int (*ct_32x32p)[2]) {
-  ct_32x32p[0][0] = tx_count_32x32p[TX_4X4];
-  ct_32x32p[0][1] = tx_count_32x32p[TX_8X8] +
-                    tx_count_32x32p[TX_16X16] +
-                    tx_count_32x32p[TX_32X32];
-  ct_32x32p[1][0] = tx_count_32x32p[TX_8X8];
-  ct_32x32p[1][1] = tx_count_32x32p[TX_16X16] +
-                    tx_count_32x32p[TX_32X32];
-  ct_32x32p[2][0] = tx_count_32x32p[TX_16X16];
-  ct_32x32p[2][1] = tx_count_32x32p[TX_32X32];
-}
-
-void tx_counts_to_branch_counts_16x16(const unsigned int *tx_count_16x16p,
-                                      unsigned int (*ct_16x16p)[2]) {
-  ct_16x16p[0][0] = tx_count_16x16p[TX_4X4];
-  ct_16x16p[0][1] = tx_count_16x16p[TX_8X8] + tx_count_16x16p[TX_16X16];
-  ct_16x16p[1][0] = tx_count_16x16p[TX_8X8];
-  ct_16x16p[1][1] = tx_count_16x16p[TX_16X16];
-}
-
-void tx_counts_to_branch_counts_8x8(const unsigned int *tx_count_8x8p,
-                                    unsigned int (*ct_8x8p)[2]) {
-  ct_8x8p[0][0] = tx_count_8x8p[TX_4X4];
-  ct_8x8p[0][1] = tx_count_8x8p[TX_8X8];
-}
-
-static const vpx_prob default_skip_probs[SKIP_CONTEXTS] = {
-  192, 128, 64
-};
-
-static const vpx_prob default_switchable_interp_prob[SWITCHABLE_FILTER_CONTEXTS]
-                                                    [SWITCHABLE_FILTERS - 1] = {
-  { 235, 162, },
-  { 36, 255, },
-  { 34, 3, },
-  { 149, 144, },
-};
-
-static void init_mode_probs(FRAME_CONTEXT *fc) {
-  vp9_copy(fc->uv_mode_prob, default_if_uv_probs);
-  vp9_copy(fc->y_mode_prob, default_if_y_probs);
-  vp9_copy(fc->switchable_interp_prob, default_switchable_interp_prob);
-  vp9_copy(fc->partition_prob, default_partition_probs);
-  vp9_copy(fc->intra_inter_prob, default_intra_inter_p);
-  vp9_copy(fc->comp_inter_prob, default_comp_inter_p);
-  vp9_copy(fc->comp_ref_prob, default_comp_ref_p);
-  vp9_copy(fc->single_ref_prob, default_single_ref_p);
-  fc->tx_probs = default_tx_probs;
-  vp9_copy(fc->skip_probs, default_skip_probs);
-  vp9_copy(fc->inter_mode_probs, default_inter_mode_probs);
-}
-
-const vpx_tree_index vp9_switchable_interp_tree
-                         [TREE_SIZE(SWITCHABLE_FILTERS)] = {
-  -EIGHTTAP, 2,
-  -EIGHTTAP_SMOOTH, -EIGHTTAP_SHARP
-};
-
-void vp9_adapt_mode_probs(VP9_COMMON *cm) {
-  int i, j;
-  FRAME_CONTEXT *fc = cm->fc;
-  const FRAME_CONTEXT *pre_fc = &cm->frame_contexts[cm->frame_context_idx];
-  const FRAME_COUNTS *counts = &cm->counts;
-
-  for (i = 0; i < INTRA_INTER_CONTEXTS; i++)
-    fc->intra_inter_prob[i] = mode_mv_merge_probs(pre_fc->intra_inter_prob[i],
-                                                  counts->intra_inter[i]);
-  for (i = 0; i < COMP_INTER_CONTEXTS; i++)
-    fc->comp_inter_prob[i] = mode_mv_merge_probs(pre_fc->comp_inter_prob[i],
-                                                 counts->comp_inter[i]);
-  for (i = 0; i < REF_CONTEXTS; i++)
-    fc->comp_ref_prob[i] = mode_mv_merge_probs(pre_fc->comp_ref_prob[i],
-                                               counts->comp_ref[i]);
-  for (i = 0; i < REF_CONTEXTS; i++)
-    for (j = 0; j < 2; j++)
-      fc->single_ref_prob[i][j] = mode_mv_merge_probs(
-          pre_fc->single_ref_prob[i][j], counts->single_ref[i][j]);
-
-  for (i = 0; i < INTER_MODE_CONTEXTS; i++)
-    vpx_tree_merge_probs(vp9_inter_mode_tree, pre_fc->inter_mode_probs[i],
-                counts->inter_mode[i], fc->inter_mode_probs[i]);
-
-  for (i = 0; i < BLOCK_SIZE_GROUPS; i++)
-    vpx_tree_merge_probs(vp9_intra_mode_tree, pre_fc->y_mode_prob[i],
-                counts->y_mode[i], fc->y_mode_prob[i]);
-
-  for (i = 0; i < INTRA_MODES; ++i)
-    vpx_tree_merge_probs(vp9_intra_mode_tree, pre_fc->uv_mode_prob[i],
-                         counts->uv_mode[i], fc->uv_mode_prob[i]);
-
-  for (i = 0; i < PARTITION_CONTEXTS; i++)
-    vpx_tree_merge_probs(vp9_partition_tree, pre_fc->partition_prob[i],
-                         counts->partition[i], fc->partition_prob[i]);
-
-  if (cm->interp_filter == SWITCHABLE) {
-    for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++)
-      vpx_tree_merge_probs(vp9_switchable_interp_tree,
-                           pre_fc->switchable_interp_prob[i],
-                           counts->switchable_interp[i],
-                           fc->switchable_interp_prob[i]);
-  }
-
-  if (cm->tx_mode == TX_MODE_SELECT) {
-    int j;
-    unsigned int branch_ct_8x8p[TX_SIZES - 3][2];
-    unsigned int branch_ct_16x16p[TX_SIZES - 2][2];
-    unsigned int branch_ct_32x32p[TX_SIZES - 1][2];
-
-    for (i = 0; i < TX_SIZE_CONTEXTS; ++i) {
-      tx_counts_to_branch_counts_8x8(counts->tx.p8x8[i], branch_ct_8x8p);
-      for (j = 0; j < TX_SIZES - 3; ++j)
-        fc->tx_probs.p8x8[i][j] = mode_mv_merge_probs(
-            pre_fc->tx_probs.p8x8[i][j], branch_ct_8x8p[j]);
-
-      tx_counts_to_branch_counts_16x16(counts->tx.p16x16[i], branch_ct_16x16p);
-      for (j = 0; j < TX_SIZES - 2; ++j)
-        fc->tx_probs.p16x16[i][j] = mode_mv_merge_probs(
-            pre_fc->tx_probs.p16x16[i][j], branch_ct_16x16p[j]);
-
-      tx_counts_to_branch_counts_32x32(counts->tx.p32x32[i], branch_ct_32x32p);
-      for (j = 0; j < TX_SIZES - 1; ++j)
-        fc->tx_probs.p32x32[i][j] = mode_mv_merge_probs(
-            pre_fc->tx_probs.p32x32[i][j], branch_ct_32x32p[j]);
-    }
-  }
-
-  for (i = 0; i < SKIP_CONTEXTS; ++i)
-    fc->skip_probs[i] = mode_mv_merge_probs(
-        pre_fc->skip_probs[i], counts->skip[i]);
-}
-
-static void set_default_lf_deltas(struct loopfilter *lf) {
-  lf->mode_ref_delta_enabled = 1;
-  lf->mode_ref_delta_update = 1;
-
-  lf->ref_deltas[INTRA_FRAME] = 1;
-  lf->ref_deltas[LAST_FRAME] = 0;
-  lf->ref_deltas[GOLDEN_FRAME] = -1;
-  lf->ref_deltas[ALTREF_FRAME] = -1;
-
-  lf->mode_deltas[0] = 0;
-  lf->mode_deltas[1] = 0;
-}
-
-void vp9_setup_past_independence(VP9_COMMON *cm) {
-  // Reset the segment feature data to the default stats:
-  // Features disabled, 0, with delta coding (Default state).
-  struct loopfilter *const lf = &cm->lf;
-
-  int i;
-  vp9_clearall_segfeatures(&cm->seg);
-  cm->seg.abs_delta = SEGMENT_DELTADATA;
-
-  if (cm->last_frame_seg_map && !cm->frame_parallel_decode)
-    memset(cm->last_frame_seg_map, 0, (cm->mi_rows * cm->mi_cols));
-
-  if (cm->current_frame_seg_map)
-    memset(cm->current_frame_seg_map, 0, (cm->mi_rows * cm->mi_cols));
-
-  // Reset the mode ref deltas for loop filter
-  vp9_zero(lf->last_ref_deltas);
-  vp9_zero(lf->last_mode_deltas);
-  set_default_lf_deltas(lf);
-
-  // To force update of the sharpness
-  lf->last_sharpness_level = -1;
-
-  vp9_default_coef_probs(cm);
-  init_mode_probs(cm->fc);
-  vp9_init_mv_probs(cm);
-  cm->fc->initialized = 1;
-
-  if (cm->frame_type == KEY_FRAME ||
-      cm->error_resilient_mode || cm->reset_frame_context == 3) {
-    // Reset all frame contexts.
-    for (i = 0; i < FRAME_CONTEXTS; ++i)
-      cm->frame_contexts[i] = *cm->fc;
-  } else if (cm->reset_frame_context == 2) {
-    // Reset only the frame context specified in the frame header.
-    cm->frame_contexts[cm->frame_context_idx] = *cm->fc;
-  }
-
-  // prev_mip will only be allocated in encoder.
-  if (frame_is_intra_only(cm) && cm->prev_mip && !cm->frame_parallel_decode)
-    memset(cm->prev_mip, 0,
-           cm->mi_stride * (cm->mi_rows + 1) * sizeof(*cm->prev_mip));
-
-  vp9_zero(cm->ref_frame_sign_bias);
-
-  cm->frame_context_idx = 0;
-}
diff --git a/vp9/common/vp9_entropymode.h b/vp9/common/vp9_entropymode.h
deleted file mode 100644 (file)
index 0285be1..0000000
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#ifndef VP9_COMMON_VP9_ENTROPYMODE_H_
-#define VP9_COMMON_VP9_ENTROPYMODE_H_
-
-#include "vp9/common/vp9_entropy.h"
-#include "vp9/common/vp9_entropymv.h"
-#include "vp9/common/vp9_filter.h"
-#include "vpx_dsp/vpx_filter.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define BLOCK_SIZE_GROUPS 4
-
-#define TX_SIZE_CONTEXTS 2
-
-#define INTER_OFFSET(mode) ((mode) - NEARESTMV)
-
-struct VP9Common;
-
-struct tx_probs {
-  vpx_prob p32x32[TX_SIZE_CONTEXTS][TX_SIZES - 1];
-  vpx_prob p16x16[TX_SIZE_CONTEXTS][TX_SIZES - 2];
-  vpx_prob p8x8[TX_SIZE_CONTEXTS][TX_SIZES - 3];
-};
-
-struct tx_counts {
-  unsigned int p32x32[TX_SIZE_CONTEXTS][TX_SIZES];
-  unsigned int p16x16[TX_SIZE_CONTEXTS][TX_SIZES - 1];
-  unsigned int p8x8[TX_SIZE_CONTEXTS][TX_SIZES - 2];
-  unsigned int tx_totals[TX_SIZES];
-};
-
-typedef struct frame_contexts {
-  vpx_prob y_mode_prob[BLOCK_SIZE_GROUPS][INTRA_MODES - 1];
-  vpx_prob uv_mode_prob[INTRA_MODES][INTRA_MODES - 1];
-  vpx_prob partition_prob[PARTITION_CONTEXTS][PARTITION_TYPES - 1];
-  vp9_coeff_probs_model coef_probs[TX_SIZES][PLANE_TYPES];
-  vpx_prob switchable_interp_prob[SWITCHABLE_FILTER_CONTEXTS]
-                                 [SWITCHABLE_FILTERS - 1];
-  vpx_prob inter_mode_probs[INTER_MODE_CONTEXTS][INTER_MODES - 1];
-  vpx_prob intra_inter_prob[INTRA_INTER_CONTEXTS];
-  vpx_prob comp_inter_prob[COMP_INTER_CONTEXTS];
-  vpx_prob single_ref_prob[REF_CONTEXTS][2];
-  vpx_prob comp_ref_prob[REF_CONTEXTS];
-  struct tx_probs tx_probs;
-  vpx_prob skip_probs[SKIP_CONTEXTS];
-  nmv_context nmvc;
-  int initialized;
-} FRAME_CONTEXT;
-
-typedef struct FRAME_COUNTS {
-  unsigned int y_mode[BLOCK_SIZE_GROUPS][INTRA_MODES];
-  unsigned int uv_mode[INTRA_MODES][INTRA_MODES];
-  unsigned int partition[PARTITION_CONTEXTS][PARTITION_TYPES];
-  vp9_coeff_count_model coef[TX_SIZES][PLANE_TYPES];
-  unsigned int eob_branch[TX_SIZES][PLANE_TYPES][REF_TYPES]
-                         [COEF_BANDS][COEFF_CONTEXTS];
-  unsigned int switchable_interp[SWITCHABLE_FILTER_CONTEXTS]
-                                [SWITCHABLE_FILTERS];
-  unsigned int inter_mode[INTER_MODE_CONTEXTS][INTER_MODES];
-  unsigned int intra_inter[INTRA_INTER_CONTEXTS][2];
-  unsigned int comp_inter[COMP_INTER_CONTEXTS][2];
-  unsigned int single_ref[REF_CONTEXTS][2][2];
-  unsigned int comp_ref[REF_CONTEXTS][2];
-  struct tx_counts tx;
-  unsigned int skip[SKIP_CONTEXTS][2];
-  nmv_context_counts mv;
-} FRAME_COUNTS;
-
-extern const vpx_prob vp9_kf_uv_mode_prob[INTRA_MODES][INTRA_MODES - 1];
-extern const vpx_prob vp9_kf_y_mode_prob[INTRA_MODES][INTRA_MODES]
-                                        [INTRA_MODES - 1];
-extern const vpx_prob vp9_kf_partition_probs[PARTITION_CONTEXTS]
-                                            [PARTITION_TYPES - 1];
-extern const vpx_tree_index vp9_intra_mode_tree[TREE_SIZE(INTRA_MODES)];
-extern const vpx_tree_index vp9_inter_mode_tree[TREE_SIZE(INTER_MODES)];
-extern const vpx_tree_index vp9_partition_tree[TREE_SIZE(PARTITION_TYPES)];
-extern const vpx_tree_index vp9_switchable_interp_tree
-                                [TREE_SIZE(SWITCHABLE_FILTERS)];
-
-void vp9_setup_past_independence(struct VP9Common *cm);
-
-void vp9_adapt_mode_probs(struct VP9Common *cm);
-
-void tx_counts_to_branch_counts_32x32(const unsigned int *tx_count_32x32p,
-                                      unsigned int (*ct_32x32p)[2]);
-void tx_counts_to_branch_counts_16x16(const unsigned int *tx_count_16x16p,
-                                      unsigned int (*ct_16x16p)[2]);
-void tx_counts_to_branch_counts_8x8(const unsigned int *tx_count_8x8p,
-                                    unsigned int (*ct_8x8p)[2]);
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP9_COMMON_VP9_ENTROPYMODE_H_
diff --git a/vp9/common/vp9_entropymv.c b/vp9/common/vp9_entropymv.c
deleted file mode 100644 (file)
index 566ae91..0000000
+++ /dev/null
@@ -1,210 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#include "vp9/common/vp9_onyxc_int.h"
-#include "vp9/common/vp9_entropymv.h"
-
-const vpx_tree_index vp9_mv_joint_tree[TREE_SIZE(MV_JOINTS)] = {
-  -MV_JOINT_ZERO, 2,
-  -MV_JOINT_HNZVZ, 4,
-  -MV_JOINT_HZVNZ, -MV_JOINT_HNZVNZ
-};
-
-const vpx_tree_index vp9_mv_class_tree[TREE_SIZE(MV_CLASSES)] = {
-  -MV_CLASS_0, 2,
-  -MV_CLASS_1, 4,
-  6, 8,
-  -MV_CLASS_2, -MV_CLASS_3,
-  10, 12,
-  -MV_CLASS_4, -MV_CLASS_5,
-  -MV_CLASS_6, 14,
-  16, 18,
-  -MV_CLASS_7, -MV_CLASS_8,
-  -MV_CLASS_9, -MV_CLASS_10,
-};
-
-const vpx_tree_index vp9_mv_class0_tree[TREE_SIZE(CLASS0_SIZE)] = {
-  -0, -1,
-};
-
-const vpx_tree_index vp9_mv_fp_tree[TREE_SIZE(MV_FP_SIZE)] = {
-  -0, 2,
-  -1, 4,
-  -2, -3
-};
-
-static const nmv_context default_nmv_context = {
-  {32, 64, 96},
-  {
-    { // Vertical component
-      128,                                                  // sign
-      {224, 144, 192, 168, 192, 176, 192, 198, 198, 245},   // class
-      {216},                                                // class0
-      {136, 140, 148, 160, 176, 192, 224, 234, 234, 240},   // bits
-      {{128, 128, 64}, {96, 112, 64}},                      // class0_fp
-      {64, 96, 64},                                         // fp
-      160,                                                  // class0_hp bit
-      128,                                                  // hp
-    },
-    { // Horizontal component
-      128,                                                  // sign
-      {216, 128, 176, 160, 176, 176, 192, 198, 198, 208},   // class
-      {208},                                                // class0
-      {136, 140, 148, 160, 176, 192, 224, 234, 234, 240},   // bits
-      {{128, 128, 64}, {96, 112, 64}},                      // class0_fp
-      {64, 96, 64},                                         // fp
-      160,                                                  // class0_hp bit
-      128,                                                  // hp
-    }
-  },
-};
-
-static const uint8_t log_in_base_2[] = {
-  0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4,
-  4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
-  5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6,
-  6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
-  6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
-  6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
-  7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
-  7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
-  7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
-  7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
-  7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8,
-  8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
-  8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
-  8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
-  8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
-  8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
-  8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
-  8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
-  8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
-  8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
-  8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
-  8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
-  9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
-  9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
-  9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
-  9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
-  9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
-  9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
-  9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
-  9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
-  9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
-  9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
-  9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
-  9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
-  9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
-  9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
-  9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
-  9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
-  9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
-  9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
-  9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
-  9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
-  9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10
-};
-
-static INLINE int mv_class_base(MV_CLASS_TYPE c) {
-  return c ? CLASS0_SIZE << (c + 2) : 0;
-}
-
-MV_CLASS_TYPE vp9_get_mv_class(int z, int *offset) {
-  const MV_CLASS_TYPE c = (z >= CLASS0_SIZE * 4096) ?
-      MV_CLASS_10 : (MV_CLASS_TYPE)log_in_base_2[z >> 3];
-  if (offset)
-    *offset = z - mv_class_base(c);
-  return c;
-}
-
-static void inc_mv_component(int v, nmv_component_counts *comp_counts,
-                             int incr, int usehp) {
-  int s, z, c, o, d, e, f;
-  assert(v != 0);            /* should not be zero */
-  s = v < 0;
-  comp_counts->sign[s] += incr;
-  z = (s ? -v : v) - 1;       /* magnitude - 1 */
-
-  c = vp9_get_mv_class(z, &o);
-  comp_counts->classes[c] += incr;
-
-  d = (o >> 3);               /* int mv data */
-  f = (o >> 1) & 3;           /* fractional pel mv data */
-  e = (o & 1);                /* high precision mv data */
-
-  if (c == MV_CLASS_0) {
-    comp_counts->class0[d] += incr;
-    comp_counts->class0_fp[d][f] += incr;
-    comp_counts->class0_hp[e] += usehp * incr;
-  } else {
-    int i;
-    int b = c + CLASS0_BITS - 1;  // number of bits
-    for (i = 0; i < b; ++i)
-      comp_counts->bits[i][((d >> i) & 1)] += incr;
-    comp_counts->fp[f] += incr;
-    comp_counts->hp[e] += usehp * incr;
-  }
-}
-
-void vp9_inc_mv(const MV *mv, nmv_context_counts *counts) {
-  if (counts != NULL) {
-    const MV_JOINT_TYPE j = vp9_get_mv_joint(mv);
-    ++counts->joints[j];
-
-    if (mv_joint_vertical(j)) {
-      inc_mv_component(mv->row, &counts->comps[0], 1, 1);
-    }
-
-    if (mv_joint_horizontal(j)) {
-      inc_mv_component(mv->col, &counts->comps[1], 1, 1);
-    }
-  }
-}
-
-void vp9_adapt_mv_probs(VP9_COMMON *cm, int allow_hp) {
-  int i, j;
-
-  nmv_context *fc = &cm->fc->nmvc;
-  const nmv_context *pre_fc = &cm->frame_contexts[cm->frame_context_idx].nmvc;
-  const nmv_context_counts *counts = &cm->counts.mv;
-
-  vpx_tree_merge_probs(vp9_mv_joint_tree, pre_fc->joints, counts->joints,
-                       fc->joints);
-
-  for (i = 0; i < 2; ++i) {
-    nmv_component *comp = &fc->comps[i];
-    const nmv_component *pre_comp = &pre_fc->comps[i];
-    const nmv_component_counts *c = &counts->comps[i];
-
-    comp->sign = mode_mv_merge_probs(pre_comp->sign, c->sign);
-    vpx_tree_merge_probs(vp9_mv_class_tree, pre_comp->classes, c->classes,
-                         comp->classes);
-    vpx_tree_merge_probs(vp9_mv_class0_tree, pre_comp->class0, c->class0,
-                         comp->class0);
-
-    for (j = 0; j < MV_OFFSET_BITS; ++j)
-      comp->bits[j] = mode_mv_merge_probs(pre_comp->bits[j], c->bits[j]);
-
-    for (j = 0; j < CLASS0_SIZE; ++j)
-      vpx_tree_merge_probs(vp9_mv_fp_tree, pre_comp->class0_fp[j],
-                           c->class0_fp[j], comp->class0_fp[j]);
-
-    vpx_tree_merge_probs(vp9_mv_fp_tree, pre_comp->fp, c->fp, comp->fp);
-
-    if (allow_hp) {
-      comp->class0_hp = mode_mv_merge_probs(pre_comp->class0_hp, c->class0_hp);
-      comp->hp = mode_mv_merge_probs(pre_comp->hp, c->hp);
-    }
-  }
-}
-
-void vp9_init_mv_probs(VP9_COMMON *cm) {
-  cm->fc->nmvc = default_nmv_context;
-}
diff --git a/vp9/common/vp9_entropymv.h b/vp9/common/vp9_entropymv.h
deleted file mode 100644 (file)
index 2f05ad4..0000000
+++ /dev/null
@@ -1,140 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#ifndef VP9_COMMON_VP9_ENTROPYMV_H_
-#define VP9_COMMON_VP9_ENTROPYMV_H_
-
-#include "./vpx_config.h"
-
-#include "vpx_dsp/prob.h"
-
-#include "vp9/common/vp9_mv.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-struct VP9Common;
-
-void vp9_init_mv_probs(struct VP9Common *cm);
-
-void vp9_adapt_mv_probs(struct VP9Common *cm, int usehp);
-
-// Integer pel reference mv threshold for use of high-precision 1/8 mv
-#define COMPANDED_MVREF_THRESH 8
-
-static INLINE int use_mv_hp(const MV *ref) {
-  return (abs(ref->row) >> 3) < COMPANDED_MVREF_THRESH &&
-         (abs(ref->col) >> 3) < COMPANDED_MVREF_THRESH;
-}
-
-#define MV_UPDATE_PROB 252
-
-/* Symbols for coding which components are zero jointly */
-#define MV_JOINTS     4
-typedef enum {
-  MV_JOINT_ZERO = 0,             /* Zero vector */
-  MV_JOINT_HNZVZ = 1,            /* Vert zero, hor nonzero */
-  MV_JOINT_HZVNZ = 2,            /* Hor zero, vert nonzero */
-  MV_JOINT_HNZVNZ = 3,           /* Both components nonzero */
-} MV_JOINT_TYPE;
-
-static INLINE int mv_joint_vertical(MV_JOINT_TYPE type) {
-  return type == MV_JOINT_HZVNZ || type == MV_JOINT_HNZVNZ;
-}
-
-static INLINE int mv_joint_horizontal(MV_JOINT_TYPE type) {
-  return type == MV_JOINT_HNZVZ || type == MV_JOINT_HNZVNZ;
-}
-
-/* Symbols for coding magnitude class of nonzero components */
-#define MV_CLASSES     11
-typedef enum {
-  MV_CLASS_0 = 0,      /* (0, 2]     integer pel */
-  MV_CLASS_1 = 1,      /* (2, 4]     integer pel */
-  MV_CLASS_2 = 2,      /* (4, 8]     integer pel */
-  MV_CLASS_3 = 3,      /* (8, 16]    integer pel */
-  MV_CLASS_4 = 4,      /* (16, 32]   integer pel */
-  MV_CLASS_5 = 5,      /* (32, 64]   integer pel */
-  MV_CLASS_6 = 6,      /* (64, 128]  integer pel */
-  MV_CLASS_7 = 7,      /* (128, 256] integer pel */
-  MV_CLASS_8 = 8,      /* (256, 512] integer pel */
-  MV_CLASS_9 = 9,      /* (512, 1024] integer pel */
-  MV_CLASS_10 = 10,    /* (1024,2048] integer pel */
-} MV_CLASS_TYPE;
-
-#define CLASS0_BITS    1  /* bits at integer precision for class 0 */
-#define CLASS0_SIZE    (1 << CLASS0_BITS)
-#define MV_OFFSET_BITS (MV_CLASSES + CLASS0_BITS - 2)
-#define MV_FP_SIZE 4
-
-#define MV_MAX_BITS    (MV_CLASSES + CLASS0_BITS + 2)
-#define MV_MAX         ((1 << MV_MAX_BITS) - 1)
-#define MV_VALS        ((MV_MAX << 1) + 1)
-
-#define MV_IN_USE_BITS 14
-#define MV_UPP   ((1 << MV_IN_USE_BITS) - 1)
-#define MV_LOW   (-(1 << MV_IN_USE_BITS))
-
-extern const vpx_tree_index vp9_mv_joint_tree[];
-extern const vpx_tree_index vp9_mv_class_tree[];
-extern const vpx_tree_index vp9_mv_class0_tree[];
-extern const vpx_tree_index vp9_mv_fp_tree[];
-
-typedef struct {
-  vpx_prob sign;
-  vpx_prob classes[MV_CLASSES - 1];
-  vpx_prob class0[CLASS0_SIZE - 1];
-  vpx_prob bits[MV_OFFSET_BITS];
-  vpx_prob class0_fp[CLASS0_SIZE][MV_FP_SIZE - 1];
-  vpx_prob fp[MV_FP_SIZE - 1];
-  vpx_prob class0_hp;
-  vpx_prob hp;
-} nmv_component;
-
-typedef struct {
-  vpx_prob joints[MV_JOINTS - 1];
-  nmv_component comps[2];
-} nmv_context;
-
-static INLINE MV_JOINT_TYPE vp9_get_mv_joint(const MV *mv) {
-  if (mv->row == 0) {
-    return mv->col == 0 ? MV_JOINT_ZERO : MV_JOINT_HNZVZ;
-  } else {
-    return mv->col == 0 ? MV_JOINT_HZVNZ : MV_JOINT_HNZVNZ;
-  }
-}
-
-MV_CLASS_TYPE vp9_get_mv_class(int z, int *offset);
-
-typedef struct {
-  unsigned int sign[2];
-  unsigned int classes[MV_CLASSES];
-  unsigned int class0[CLASS0_SIZE];
-  unsigned int bits[MV_OFFSET_BITS][2];
-  unsigned int class0_fp[CLASS0_SIZE][MV_FP_SIZE];
-  unsigned int fp[MV_FP_SIZE];
-  unsigned int class0_hp[2];
-  unsigned int hp[2];
-} nmv_component_counts;
-
-typedef struct {
-  unsigned int joints[MV_JOINTS];
-  nmv_component_counts comps[2];
-} nmv_context_counts;
-
-void vp9_inc_mv(const MV *mv, nmv_context_counts *mvctx);
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP9_COMMON_VP9_ENTROPYMV_H_
diff --git a/vp9/common/vp9_enums.h b/vp9/common/vp9_enums.h
deleted file mode 100644 (file)
index d089f23..0000000
+++ /dev/null
@@ -1,147 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#ifndef VP9_COMMON_VP9_ENUMS_H_
-#define VP9_COMMON_VP9_ENUMS_H_
-
-#include "./vpx_config.h"
-#include "vpx/vpx_integer.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define MI_SIZE_LOG2 3
-#define MI_BLOCK_SIZE_LOG2 (6 - MI_SIZE_LOG2)  // 64 = 2^6
-
-#define MI_SIZE (1 << MI_SIZE_LOG2)  // pixels per mi-unit
-#define MI_BLOCK_SIZE (1 << MI_BLOCK_SIZE_LOG2)  // mi-units per max block
-
-#define MI_MASK (MI_BLOCK_SIZE - 1)
-
-// Bitstream profiles indicated by 2-3 bits in the uncompressed header.
-// 00: Profile 0.  8-bit 4:2:0 only.
-// 10: Profile 1.  8-bit 4:4:4, 4:2:2, and 4:4:0.
-// 01: Profile 2.  10-bit and 12-bit color only, with 4:2:0 sampling.
-// 110: Profile 3. 10-bit and 12-bit color only, with 4:2:2/4:4:4/4:4:0
-//                 sampling.
-// 111: Undefined profile.
-typedef enum BITSTREAM_PROFILE {
-  PROFILE_0,
-  PROFILE_1,
-  PROFILE_2,
-  PROFILE_3,
-  MAX_PROFILES
-} BITSTREAM_PROFILE;
-
-#define BLOCK_4X4     0
-#define BLOCK_4X8     1
-#define BLOCK_8X4     2
-#define BLOCK_8X8     3
-#define BLOCK_8X16    4
-#define BLOCK_16X8    5
-#define BLOCK_16X16   6
-#define BLOCK_16X32   7
-#define BLOCK_32X16   8
-#define BLOCK_32X32   9
-#define BLOCK_32X64  10
-#define BLOCK_64X32  11
-#define BLOCK_64X64  12
-#define BLOCK_SIZES  13
-#define BLOCK_INVALID BLOCK_SIZES
-typedef uint8_t BLOCK_SIZE;
-
-typedef enum PARTITION_TYPE {
-  PARTITION_NONE,
-  PARTITION_HORZ,
-  PARTITION_VERT,
-  PARTITION_SPLIT,
-  PARTITION_TYPES,
-  PARTITION_INVALID = PARTITION_TYPES
-} PARTITION_TYPE;
-
-typedef char PARTITION_CONTEXT;
-#define PARTITION_PLOFFSET   4  // number of probability models per block size
-#define PARTITION_CONTEXTS (4 * PARTITION_PLOFFSET)
-
-// block transform size
-typedef uint8_t TX_SIZE;
-#define TX_4X4   ((TX_SIZE)0)   // 4x4 transform
-#define TX_8X8   ((TX_SIZE)1)   // 8x8 transform
-#define TX_16X16 ((TX_SIZE)2)   // 16x16 transform
-#define TX_32X32 ((TX_SIZE)3)   // 32x32 transform
-#define TX_SIZES ((TX_SIZE)4)
-
-// frame transform mode
-typedef enum {
-  ONLY_4X4            = 0,        // only 4x4 transform used
-  ALLOW_8X8           = 1,        // allow block transform size up to 8x8
-  ALLOW_16X16         = 2,        // allow block transform size up to 16x16
-  ALLOW_32X32         = 3,        // allow block transform size up to 32x32
-  TX_MODE_SELECT      = 4,        // transform specified for each block
-  TX_MODES            = 5,
-} TX_MODE;
-
-typedef enum {
-  DCT_DCT   = 0,                      // DCT  in both horizontal and vertical
-  ADST_DCT  = 1,                      // ADST in vertical, DCT in horizontal
-  DCT_ADST  = 2,                      // DCT  in vertical, ADST in horizontal
-  ADST_ADST = 3,                      // ADST in both directions
-  TX_TYPES = 4
-} TX_TYPE;
-
-typedef enum {
-  VP9_LAST_FLAG = 1 << 0,
-  VP9_GOLD_FLAG = 1 << 1,
-  VP9_ALT_FLAG = 1 << 2,
-} VP9_REFFRAME;
-
-typedef enum {
-  PLANE_TYPE_Y  = 0,
-  PLANE_TYPE_UV = 1,
-  PLANE_TYPES
-} PLANE_TYPE;
-
-#define DC_PRED    0       // Average of above and left pixels
-#define V_PRED     1       // Vertical
-#define H_PRED     2       // Horizontal
-#define D45_PRED   3       // Directional 45  deg = round(arctan(1/1) * 180/pi)
-#define D135_PRED  4       // Directional 135 deg = 180 - 45
-#define D117_PRED  5       // Directional 117 deg = 180 - 63
-#define D153_PRED  6       // Directional 153 deg = 180 - 27
-#define D207_PRED  7       // Directional 207 deg = 180 + 27
-#define D63_PRED   8       // Directional 63  deg = round(arctan(2/1) * 180/pi)
-#define TM_PRED    9       // True-motion
-#define NEARESTMV 10
-#define NEARMV    11
-#define ZEROMV    12
-#define NEWMV     13
-#define MB_MODE_COUNT 14
-typedef uint8_t PREDICTION_MODE;
-
-#define INTRA_MODES (TM_PRED + 1)
-
-#define INTER_MODES (1 + NEWMV - NEARESTMV)
-
-#define SKIP_CONTEXTS 3
-#define INTER_MODE_CONTEXTS 7
-
-/* Segment Feature Masks */
-#define MAX_MV_REF_CANDIDATES 2
-
-#define INTRA_INTER_CONTEXTS 4
-#define COMP_INTER_CONTEXTS 5
-#define REF_CONTEXTS 5
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP9_COMMON_VP9_ENUMS_H_
diff --git a/vp9/common/vp9_filter.c b/vp9/common/vp9_filter.c
deleted file mode 100644 (file)
index 4b2198f..0000000
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#include <assert.h>
-
-#include "vp9/common/vp9_filter.h"
-
-DECLARE_ALIGNED(256, static const InterpKernel,
-                bilinear_filters[SUBPEL_SHIFTS]) = {
-  { 0, 0, 0, 128,   0, 0, 0, 0 },
-  { 0, 0, 0, 120,   8, 0, 0, 0 },
-  { 0, 0, 0, 112,  16, 0, 0, 0 },
-  { 0, 0, 0, 104,  24, 0, 0, 0 },
-  { 0, 0, 0,  96,  32, 0, 0, 0 },
-  { 0, 0, 0,  88,  40, 0, 0, 0 },
-  { 0, 0, 0,  80,  48, 0, 0, 0 },
-  { 0, 0, 0,  72,  56, 0, 0, 0 },
-  { 0, 0, 0,  64,  64, 0, 0, 0 },
-  { 0, 0, 0,  56,  72, 0, 0, 0 },
-  { 0, 0, 0,  48,  80, 0, 0, 0 },
-  { 0, 0, 0,  40,  88, 0, 0, 0 },
-  { 0, 0, 0,  32,  96, 0, 0, 0 },
-  { 0, 0, 0,  24, 104, 0, 0, 0 },
-  { 0, 0, 0,  16, 112, 0, 0, 0 },
-  { 0, 0, 0,   8, 120, 0, 0, 0 }
-};
-
-// Lagrangian interpolation filter
-DECLARE_ALIGNED(256, static const InterpKernel,
-                sub_pel_filters_8[SUBPEL_SHIFTS]) = {
-  { 0,   0,   0, 128,   0,   0,   0,  0},
-  { 0,   1,  -5, 126,   8,  -3,   1,  0},
-  { -1,   3, -10, 122,  18,  -6,   2,  0},
-  { -1,   4, -13, 118,  27,  -9,   3, -1},
-  { -1,   4, -16, 112,  37, -11,   4, -1},
-  { -1,   5, -18, 105,  48, -14,   4, -1},
-  { -1,   5, -19,  97,  58, -16,   5, -1},
-  { -1,   6, -19,  88,  68, -18,   5, -1},
-  { -1,   6, -19,  78,  78, -19,   6, -1},
-  { -1,   5, -18,  68,  88, -19,   6, -1},
-  { -1,   5, -16,  58,  97, -19,   5, -1},
-  { -1,   4, -14,  48, 105, -18,   5, -1},
-  { -1,   4, -11,  37, 112, -16,   4, -1},
-  { -1,   3,  -9,  27, 118, -13,   4, -1},
-  { 0,   2,  -6,  18, 122, -10,   3, -1},
-  { 0,   1,  -3,   8, 126,  -5,   1,  0}
-};
-
-// DCT based filter
-DECLARE_ALIGNED(256, static const InterpKernel,
-                sub_pel_filters_8s[SUBPEL_SHIFTS]) = {
-  {0,   0,   0, 128,   0,   0,   0, 0},
-  {-1,   3,  -7, 127,   8,  -3,   1, 0},
-  {-2,   5, -13, 125,  17,  -6,   3, -1},
-  {-3,   7, -17, 121,  27, -10,   5, -2},
-  {-4,   9, -20, 115,  37, -13,   6, -2},
-  {-4,  10, -23, 108,  48, -16,   8, -3},
-  {-4,  10, -24, 100,  59, -19,   9, -3},
-  {-4,  11, -24,  90,  70, -21,  10, -4},
-  {-4,  11, -23,  80,  80, -23,  11, -4},
-  {-4,  10, -21,  70,  90, -24,  11, -4},
-  {-3,   9, -19,  59, 100, -24,  10, -4},
-  {-3,   8, -16,  48, 108, -23,  10, -4},
-  {-2,   6, -13,  37, 115, -20,   9, -4},
-  {-2,   5, -10,  27, 121, -17,   7, -3},
-  {-1,   3,  -6,  17, 125, -13,   5, -2},
-  {0,   1,  -3,   8, 127,  -7,   3, -1}
-};
-
-// freqmultiplier = 0.5
-DECLARE_ALIGNED(256, static const InterpKernel,
-                sub_pel_filters_8lp[SUBPEL_SHIFTS]) = {
-  { 0,  0,  0, 128,  0,  0,  0,  0},
-  {-3, -1, 32,  64, 38,  1, -3,  0},
-  {-2, -2, 29,  63, 41,  2, -3,  0},
-  {-2, -2, 26,  63, 43,  4, -4,  0},
-  {-2, -3, 24,  62, 46,  5, -4,  0},
-  {-2, -3, 21,  60, 49,  7, -4,  0},
-  {-1, -4, 18,  59, 51,  9, -4,  0},
-  {-1, -4, 16,  57, 53, 12, -4, -1},
-  {-1, -4, 14,  55, 55, 14, -4, -1},
-  {-1, -4, 12,  53, 57, 16, -4, -1},
-  { 0, -4,  9,  51, 59, 18, -4, -1},
-  { 0, -4,  7,  49, 60, 21, -3, -2},
-  { 0, -4,  5,  46, 62, 24, -3, -2},
-  { 0, -4,  4,  43, 63, 26, -2, -2},
-  { 0, -3,  2,  41, 63, 29, -2, -2},
-  { 0, -3,  1,  38, 64, 32, -1, -3}
-};
-
-
-const InterpKernel *vp9_filter_kernels[4] = {
-  sub_pel_filters_8,
-  sub_pel_filters_8lp,
-  sub_pel_filters_8s,
-  bilinear_filters
-};
diff --git a/vp9/common/vp9_filter.h b/vp9/common/vp9_filter.h
deleted file mode 100644 (file)
index efa24bc..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- *  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.
- */
-
-#ifndef VP9_COMMON_VP9_FILTER_H_
-#define VP9_COMMON_VP9_FILTER_H_
-
-#include "./vpx_config.h"
-#include "vpx/vpx_integer.h"
-#include "vpx_dsp/vpx_filter.h"
-#include "vpx_ports/mem.h"
-
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define EIGHTTAP            0
-#define EIGHTTAP_SMOOTH     1
-#define EIGHTTAP_SHARP      2
-#define SWITCHABLE_FILTERS  3 /* Number of switchable filters */
-#define BILINEAR            3
-// The codec can operate in four possible inter prediction filter mode:
-// 8-tap, 8-tap-smooth, 8-tap-sharp, and switching between the three.
-#define SWITCHABLE_FILTER_CONTEXTS (SWITCHABLE_FILTERS + 1)
-#define SWITCHABLE 4 /* should be the last one */
-
-typedef uint8_t INTERP_FILTER;
-
-extern const InterpKernel *vp9_filter_kernels[4];
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP9_COMMON_VP9_FILTER_H_
diff --git a/vp9/common/vp9_frame_buffers.c b/vp9/common/vp9_frame_buffers.c
deleted file mode 100644 (file)
index 0f41d66..0000000
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- *  Copyright (c) 2014 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.
- */
-
-#include <assert.h>
-
-#include "vp9/common/vp9_frame_buffers.h"
-#include "vpx_mem/vpx_mem.h"
-
-int vp9_alloc_internal_frame_buffers(InternalFrameBufferList *list) {
-  assert(list != NULL);
-  vp9_free_internal_frame_buffers(list);
-
-  list->num_internal_frame_buffers =
-      VP9_MAXIMUM_REF_BUFFERS + VPX_MAXIMUM_WORK_BUFFERS;
-  list->int_fb =
-      (InternalFrameBuffer *)vpx_calloc(list->num_internal_frame_buffers,
-                                        sizeof(*list->int_fb));
-  return (list->int_fb == NULL);
-}
-
-void vp9_free_internal_frame_buffers(InternalFrameBufferList *list) {
-  int i;
-
-  assert(list != NULL);
-
-  for (i = 0; i < list->num_internal_frame_buffers; ++i) {
-    vpx_free(list->int_fb[i].data);
-    list->int_fb[i].data = NULL;
-  }
-  vpx_free(list->int_fb);
-  list->int_fb = NULL;
-}
-
-int vp9_get_frame_buffer(void *cb_priv, size_t min_size,
-                         vpx_codec_frame_buffer_t *fb) {
-  int i;
-  InternalFrameBufferList *const int_fb_list =
-      (InternalFrameBufferList *)cb_priv;
-  if (int_fb_list == NULL)
-    return -1;
-
-  // Find a free frame buffer.
-  for (i = 0; i < int_fb_list->num_internal_frame_buffers; ++i) {
-    if (!int_fb_list->int_fb[i].in_use)
-      break;
-  }
-
-  if (i == int_fb_list->num_internal_frame_buffers)
-    return -1;
-
-  if (int_fb_list->int_fb[i].size < min_size) {
-    int_fb_list->int_fb[i].data =
-        (uint8_t *)vpx_realloc(int_fb_list->int_fb[i].data, min_size);
-    if (!int_fb_list->int_fb[i].data)
-      return -1;
-
-    // This memset is needed for fixing valgrind error from C loop filter
-    // due to access uninitialized memory in frame border. It could be
-    // removed if border is totally removed.
-    memset(int_fb_list->int_fb[i].data, 0, min_size);
-    int_fb_list->int_fb[i].size = min_size;
-  }
-
-  fb->data = int_fb_list->int_fb[i].data;
-  fb->size = int_fb_list->int_fb[i].size;
-  int_fb_list->int_fb[i].in_use = 1;
-
-  // Set the frame buffer's private data to point at the internal frame buffer.
-  fb->priv = &int_fb_list->int_fb[i];
-  return 0;
-}
-
-int vp9_release_frame_buffer(void *cb_priv, vpx_codec_frame_buffer_t *fb) {
-  InternalFrameBuffer *const int_fb = (InternalFrameBuffer *)fb->priv;
-  (void)cb_priv;
-  if (int_fb)
-    int_fb->in_use = 0;
-  return 0;
-}
diff --git a/vp9/common/vp9_frame_buffers.h b/vp9/common/vp9_frame_buffers.h
deleted file mode 100644 (file)
index e2cfe61..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- *  Copyright (c) 2014 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.
- */
-
-#ifndef VP9_COMMON_VP9_FRAME_BUFFERS_H_
-#define VP9_COMMON_VP9_FRAME_BUFFERS_H_
-
-#include "vpx/vpx_frame_buffer.h"
-#include "vpx/vpx_integer.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef struct InternalFrameBuffer {
-  uint8_t *data;
-  size_t size;
-  int in_use;
-} InternalFrameBuffer;
-
-typedef struct InternalFrameBufferList {
-  int num_internal_frame_buffers;
-  InternalFrameBuffer *int_fb;
-} InternalFrameBufferList;
-
-// Initializes |list|. Returns 0 on success.
-int vp9_alloc_internal_frame_buffers(InternalFrameBufferList *list);
-
-// Free any data allocated to the frame buffers.
-void vp9_free_internal_frame_buffers(InternalFrameBufferList *list);
-
-// Callback used by libvpx to request an external frame buffer. |cb_priv|
-// Callback private data, which points to an InternalFrameBufferList.
-// |min_size| is the minimum size in bytes needed to decode the next frame.
-// |fb| pointer to the frame buffer.
-int vp9_get_frame_buffer(void *cb_priv, size_t min_size,
-                         vpx_codec_frame_buffer_t *fb);
-
-// Callback used by libvpx when there are no references to the frame buffer.
-// |cb_priv| is not used. |fb| pointer to the frame buffer.
-int vp9_release_frame_buffer(void *cb_priv, vpx_codec_frame_buffer_t *fb);
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP9_COMMON_VP9_FRAME_BUFFERS_H_
diff --git a/vp9/common/vp9_idct.c b/vp9/common/vp9_idct.c
deleted file mode 100644 (file)
index 1b42014..0000000
+++ /dev/null
@@ -1,405 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#include <math.h>
-
-#include "./vp9_rtcd.h"
-#include "./vpx_dsp_rtcd.h"
-#include "vp9/common/vp9_blockd.h"
-#include "vp9/common/vp9_idct.h"
-#include "vpx_dsp/inv_txfm.h"
-#include "vpx_ports/mem.h"
-
-void vp9_iht4x4_16_add_c(const tran_low_t *input, uint8_t *dest, int stride,
-                         int tx_type) {
-  const transform_2d IHT_4[] = {
-    { idct4_c, idct4_c  },  // DCT_DCT  = 0
-    { iadst4_c, idct4_c  },   // ADST_DCT = 1
-    { idct4_c, iadst4_c },    // DCT_ADST = 2
-    { iadst4_c, iadst4_c }      // ADST_ADST = 3
-  };
-
-  int i, j;
-  tran_low_t out[4 * 4];
-  tran_low_t *outptr = out;
-  tran_low_t temp_in[4], temp_out[4];
-
-  // inverse transform row vectors
-  for (i = 0; i < 4; ++i) {
-    IHT_4[tx_type].rows(input, outptr);
-    input  += 4;
-    outptr += 4;
-  }
-
-  // inverse transform column vectors
-  for (i = 0; i < 4; ++i) {
-    for (j = 0; j < 4; ++j)
-      temp_in[j] = out[j * 4 + i];
-    IHT_4[tx_type].cols(temp_in, temp_out);
-    for (j = 0; j < 4; ++j) {
-      dest[j * stride + i] = clip_pixel_add(dest[j * stride + i],
-                                            ROUND_POWER_OF_TWO(temp_out[j], 4));
-    }
-  }
-}
-
-static const transform_2d IHT_8[] = {
-  { idct8_c,  idct8_c  },  // DCT_DCT  = 0
-  { iadst8_c, idct8_c  },  // ADST_DCT = 1
-  { idct8_c,  iadst8_c },  // DCT_ADST = 2
-  { iadst8_c, iadst8_c }   // ADST_ADST = 3
-};
-
-void vp9_iht8x8_64_add_c(const tran_low_t *input, uint8_t *dest, int stride,
-                         int tx_type) {
-  int i, j;
-  tran_low_t out[8 * 8];
-  tran_low_t *outptr = out;
-  tran_low_t temp_in[8], temp_out[8];
-  const transform_2d ht = IHT_8[tx_type];
-
-  // inverse transform row vectors
-  for (i = 0; i < 8; ++i) {
-    ht.rows(input, outptr);
-    input += 8;
-    outptr += 8;
-  }
-
-  // inverse transform column vectors
-  for (i = 0; i < 8; ++i) {
-    for (j = 0; j < 8; ++j)
-      temp_in[j] = out[j * 8 + i];
-    ht.cols(temp_in, temp_out);
-    for (j = 0; j < 8; ++j) {
-      dest[j * stride + i] = clip_pixel_add(dest[j * stride + i],
-                                            ROUND_POWER_OF_TWO(temp_out[j], 5));
-    }
-  }
-}
-
-static const transform_2d IHT_16[] = {
-  { idct16_c,  idct16_c  },  // DCT_DCT  = 0
-  { iadst16_c, idct16_c  },  // ADST_DCT = 1
-  { idct16_c,  iadst16_c },  // DCT_ADST = 2
-  { iadst16_c, iadst16_c }   // ADST_ADST = 3
-};
-
-void vp9_iht16x16_256_add_c(const tran_low_t *input, uint8_t *dest, int stride,
-                            int tx_type) {
-  int i, j;
-  tran_low_t out[16 * 16];
-  tran_low_t *outptr = out;
-  tran_low_t temp_in[16], temp_out[16];
-  const transform_2d ht = IHT_16[tx_type];
-
-  // Rows
-  for (i = 0; i < 16; ++i) {
-    ht.rows(input, outptr);
-    input += 16;
-    outptr += 16;
-  }
-
-  // Columns
-  for (i = 0; i < 16; ++i) {
-    for (j = 0; j < 16; ++j)
-      temp_in[j] = out[j * 16 + i];
-    ht.cols(temp_in, temp_out);
-    for (j = 0; j < 16; ++j) {
-      dest[j * stride + i] = clip_pixel_add(dest[j * stride + i],
-                                            ROUND_POWER_OF_TWO(temp_out[j], 6));
-    }
-  }
-}
-
-// idct
-void vp9_idct4x4_add(const tran_low_t *input, uint8_t *dest, int stride,
-                     int eob) {
-  if (eob > 1)
-    vpx_idct4x4_16_add(input, dest, stride);
-  else
-    vpx_idct4x4_1_add(input, dest, stride);
-}
-
-
-void vp9_iwht4x4_add(const tran_low_t *input, uint8_t *dest, int stride,
-                     int eob) {
-  if (eob > 1)
-    vpx_iwht4x4_16_add(input, dest, stride);
-  else
-    vpx_iwht4x4_1_add(input, dest, stride);
-}
-
-void vp9_idct8x8_add(const tran_low_t *input, uint8_t *dest, int stride,
-                     int eob) {
-  // If dc is 1, then input[0] is the reconstructed value, do not need
-  // dequantization. Also, when dc is 1, dc is counted in eobs, namely eobs >=1.
-
-  // The calculation can be simplified if there are not many non-zero dct
-  // coefficients. Use eobs to decide what to do.
-  // TODO(yunqingwang): "eobs = 1" case is also handled in vp9_short_idct8x8_c.
-  // Combine that with code here.
-  if (eob == 1)
-    // DC only DCT coefficient
-    vpx_idct8x8_1_add(input, dest, stride);
-  else if (eob <= 12)
-    vpx_idct8x8_12_add(input, dest, stride);
-  else
-    vpx_idct8x8_64_add(input, dest, stride);
-}
-
-void vp9_idct16x16_add(const tran_low_t *input, uint8_t *dest, int stride,
-                       int eob) {
-  /* The calculation can be simplified if there are not many non-zero dct
-   * coefficients. Use eobs to separate different cases. */
-  if (eob == 1)
-    /* DC only DCT coefficient. */
-    vpx_idct16x16_1_add(input, dest, stride);
-  else if (eob <= 10)
-    vpx_idct16x16_10_add(input, dest, stride);
-  else
-    vpx_idct16x16_256_add(input, dest, stride);
-}
-
-void vp9_idct32x32_add(const tran_low_t *input, uint8_t *dest, int stride,
-                       int eob) {
-  if (eob == 1)
-    vpx_idct32x32_1_add(input, dest, stride);
-  else if (eob <= 34)
-    // non-zero coeff only in upper-left 8x8
-    vpx_idct32x32_34_add(input, dest, stride);
-  else if (eob <= 135)
-    // non-zero coeff only in upper-left 16x16
-    vpx_idct32x32_135_add(input, dest, stride);
-  else
-    vpx_idct32x32_1024_add(input, dest, stride);
-}
-
-// iht
-void vp9_iht4x4_add(TX_TYPE tx_type, const tran_low_t *input, uint8_t *dest,
-                    int stride, int eob) {
-  if (tx_type == DCT_DCT)
-    vp9_idct4x4_add(input, dest, stride, eob);
-  else
-    vp9_iht4x4_16_add(input, dest, stride, tx_type);
-}
-
-void vp9_iht8x8_add(TX_TYPE tx_type, const tran_low_t *input, uint8_t *dest,
-                    int stride, int eob) {
-  if (tx_type == DCT_DCT) {
-    vp9_idct8x8_add(input, dest, stride, eob);
-  } else {
-    vp9_iht8x8_64_add(input, dest, stride, tx_type);
-  }
-}
-
-void vp9_iht16x16_add(TX_TYPE tx_type, const tran_low_t *input, uint8_t *dest,
-                      int stride, int eob) {
-  if (tx_type == DCT_DCT) {
-    vp9_idct16x16_add(input, dest, stride, eob);
-  } else {
-    vp9_iht16x16_256_add(input, dest, stride, tx_type);
-  }
-}
-
-#if CONFIG_VP9_HIGHBITDEPTH
-void vp9_highbd_iht4x4_16_add_c(const tran_low_t *input, uint8_t *dest8,
-                                int stride, int tx_type, int bd) {
-  const highbd_transform_2d IHT_4[] = {
-    { vpx_highbd_idct4_c, vpx_highbd_idct4_c  },    // DCT_DCT  = 0
-    { vpx_highbd_iadst4_c, vpx_highbd_idct4_c },    // ADST_DCT = 1
-    { vpx_highbd_idct4_c, vpx_highbd_iadst4_c },    // DCT_ADST = 2
-    { vpx_highbd_iadst4_c, vpx_highbd_iadst4_c }    // ADST_ADST = 3
-  };
-  uint16_t *dest = CONVERT_TO_SHORTPTR(dest8);
-
-  int i, j;
-  tran_low_t out[4 * 4];
-  tran_low_t *outptr = out;
-  tran_low_t temp_in[4], temp_out[4];
-
-  // Inverse transform row vectors.
-  for (i = 0; i < 4; ++i) {
-    IHT_4[tx_type].rows(input, outptr, bd);
-    input  += 4;
-    outptr += 4;
-  }
-
-  // Inverse transform column vectors.
-  for (i = 0; i < 4; ++i) {
-    for (j = 0; j < 4; ++j)
-      temp_in[j] = out[j * 4 + i];
-    IHT_4[tx_type].cols(temp_in, temp_out, bd);
-    for (j = 0; j < 4; ++j) {
-      dest[j * stride + i] = highbd_clip_pixel_add(
-          dest[j * stride + i], ROUND_POWER_OF_TWO(temp_out[j], 4), bd);
-    }
-  }
-}
-
-static const highbd_transform_2d HIGH_IHT_8[] = {
-  { vpx_highbd_idct8_c,  vpx_highbd_idct8_c  },  // DCT_DCT  = 0
-  { vpx_highbd_iadst8_c, vpx_highbd_idct8_c  },  // ADST_DCT = 1
-  { vpx_highbd_idct8_c,  vpx_highbd_iadst8_c },  // DCT_ADST = 2
-  { vpx_highbd_iadst8_c, vpx_highbd_iadst8_c }   // ADST_ADST = 3
-};
-
-void vp9_highbd_iht8x8_64_add_c(const tran_low_t *input, uint8_t *dest8,
-                                int stride, int tx_type, int bd) {
-  int i, j;
-  tran_low_t out[8 * 8];
-  tran_low_t *outptr = out;
-  tran_low_t temp_in[8], temp_out[8];
-  const highbd_transform_2d ht = HIGH_IHT_8[tx_type];
-  uint16_t *dest = CONVERT_TO_SHORTPTR(dest8);
-
-  // Inverse transform row vectors.
-  for (i = 0; i < 8; ++i) {
-    ht.rows(input, outptr, bd);
-    input += 8;
-    outptr += 8;
-  }
-
-  // Inverse transform column vectors.
-  for (i = 0; i < 8; ++i) {
-    for (j = 0; j < 8; ++j)
-      temp_in[j] = out[j * 8 + i];
-    ht.cols(temp_in, temp_out, bd);
-    for (j = 0; j < 8; ++j) {
-      dest[j * stride + i] = highbd_clip_pixel_add(
-          dest[j * stride + i], ROUND_POWER_OF_TWO(temp_out[j], 5), bd);
-    }
-  }
-}
-
-static const highbd_transform_2d HIGH_IHT_16[] = {
-  { vpx_highbd_idct16_c,  vpx_highbd_idct16_c  },  // DCT_DCT  = 0
-  { vpx_highbd_iadst16_c, vpx_highbd_idct16_c  },  // ADST_DCT = 1
-  { vpx_highbd_idct16_c,  vpx_highbd_iadst16_c },  // DCT_ADST = 2
-  { vpx_highbd_iadst16_c, vpx_highbd_iadst16_c }   // ADST_ADST = 3
-};
-
-void vp9_highbd_iht16x16_256_add_c(const tran_low_t *input, uint8_t *dest8,
-                                   int stride, int tx_type, int bd) {
-  int i, j;
-  tran_low_t out[16 * 16];
-  tran_low_t *outptr = out;
-  tran_low_t temp_in[16], temp_out[16];
-  const highbd_transform_2d ht = HIGH_IHT_16[tx_type];
-  uint16_t *dest = CONVERT_TO_SHORTPTR(dest8);
-
-  // Rows
-  for (i = 0; i < 16; ++i) {
-    ht.rows(input, outptr, bd);
-    input += 16;
-    outptr += 16;
-  }
-
-  // Columns
-  for (i = 0; i < 16; ++i) {
-    for (j = 0; j < 16; ++j)
-      temp_in[j] = out[j * 16 + i];
-    ht.cols(temp_in, temp_out, bd);
-    for (j = 0; j < 16; ++j) {
-      dest[j * stride + i] = highbd_clip_pixel_add(
-          dest[j * stride + i], ROUND_POWER_OF_TWO(temp_out[j], 6), bd);
-    }
-  }
-}
-
-// idct
-void vp9_highbd_idct4x4_add(const tran_low_t *input, uint8_t *dest, int stride,
-                            int eob, int bd) {
-  if (eob > 1)
-    vpx_highbd_idct4x4_16_add(input, dest, stride, bd);
-  else
-    vpx_highbd_idct4x4_1_add(input, dest, stride, bd);
-}
-
-
-void vp9_highbd_iwht4x4_add(const tran_low_t *input, uint8_t *dest, int stride,
-                            int eob, int bd) {
-  if (eob > 1)
-    vpx_highbd_iwht4x4_16_add(input, dest, stride, bd);
-  else
-    vpx_highbd_iwht4x4_1_add(input, dest, stride, bd);
-}
-
-void vp9_highbd_idct8x8_add(const tran_low_t *input, uint8_t *dest, int stride,
-                            int eob, int bd) {
-  // If dc is 1, then input[0] is the reconstructed value, do not need
-  // dequantization. Also, when dc is 1, dc is counted in eobs, namely eobs >=1.
-
-  // The calculation can be simplified if there are not many non-zero dct
-  // coefficients. Use eobs to decide what to do.
-  // TODO(yunqingwang): "eobs = 1" case is also handled in vp9_short_idct8x8_c.
-  // Combine that with code here.
-  // DC only DCT coefficient
-  if (eob == 1) {
-    vpx_highbd_idct8x8_1_add(input, dest, stride, bd);
-  } else if (eob <= 10) {
-    vpx_highbd_idct8x8_10_add(input, dest, stride, bd);
-  } else {
-    vpx_highbd_idct8x8_64_add(input, dest, stride, bd);
-  }
-}
-
-void vp9_highbd_idct16x16_add(const tran_low_t *input, uint8_t *dest,
-                              int stride, int eob, int bd) {
-  // The calculation can be simplified if there are not many non-zero dct
-  // coefficients. Use eobs to separate different cases.
-  // DC only DCT coefficient.
-  if (eob == 1) {
-    vpx_highbd_idct16x16_1_add(input, dest, stride, bd);
-  } else if (eob <= 10) {
-    vpx_highbd_idct16x16_10_add(input, dest, stride, bd);
-  } else {
-    vpx_highbd_idct16x16_256_add(input, dest, stride, bd);
-  }
-}
-
-void vp9_highbd_idct32x32_add(const tran_low_t *input, uint8_t *dest,
-                              int stride, int eob, int bd) {
-  // Non-zero coeff only in upper-left 8x8
-  if (eob == 1) {
-    vpx_highbd_idct32x32_1_add(input, dest, stride, bd);
-  } else if (eob <= 34) {
-    vpx_highbd_idct32x32_34_add(input, dest, stride, bd);
-  } else {
-    vpx_highbd_idct32x32_1024_add(input, dest, stride, bd);
-  }
-}
-
-// iht
-void vp9_highbd_iht4x4_add(TX_TYPE tx_type, const tran_low_t *input,
-                           uint8_t *dest, int stride, int eob, int bd) {
-  if (tx_type == DCT_DCT)
-    vp9_highbd_idct4x4_add(input, dest, stride, eob, bd);
-  else
-    vp9_highbd_iht4x4_16_add(input, dest, stride, tx_type, bd);
-}
-
-void vp9_highbd_iht8x8_add(TX_TYPE tx_type, const tran_low_t *input,
-                           uint8_t *dest, int stride, int eob, int bd) {
-  if (tx_type == DCT_DCT) {
-    vp9_highbd_idct8x8_add(input, dest, stride, eob, bd);
-  } else {
-    vp9_highbd_iht8x8_64_add(input, dest, stride, tx_type, bd);
-  }
-}
-
-void vp9_highbd_iht16x16_add(TX_TYPE tx_type, const tran_low_t *input,
-                           uint8_t *dest, int stride, int eob, int bd) {
-  if (tx_type == DCT_DCT) {
-    vp9_highbd_idct16x16_add(input, dest, stride, eob, bd);
-  } else {
-    vp9_highbd_iht16x16_256_add(input, dest, stride, tx_type, bd);
-  }
-}
-#endif  // CONFIG_VP9_HIGHBITDEPTH
diff --git a/vp9/common/vp9_idct.h b/vp9/common/vp9_idct.h
deleted file mode 100644 (file)
index b5a3fbf..0000000
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#ifndef VP9_COMMON_VP9_IDCT_H_
-#define VP9_COMMON_VP9_IDCT_H_
-
-#include <assert.h>
-
-#include "./vpx_config.h"
-#include "vp9/common/vp9_common.h"
-#include "vp9/common/vp9_enums.h"
-#include "vpx_dsp/inv_txfm.h"
-#include "vpx_dsp/txfm_common.h"
-#include "vpx_ports/mem.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef void (*transform_1d)(const tran_low_t*, tran_low_t*);
-
-typedef struct {
-  transform_1d cols, rows;  // vertical and horizontal
-} transform_2d;
-
-#if CONFIG_VP9_HIGHBITDEPTH
-typedef void (*highbd_transform_1d)(const tran_low_t*, tran_low_t*, int bd);
-
-typedef struct {
-  highbd_transform_1d cols, rows;  // vertical and horizontal
-} highbd_transform_2d;
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-
-void vp9_iwht4x4_add(const tran_low_t *input, uint8_t *dest, int stride,
-                     int eob);
-void vp9_idct4x4_add(const tran_low_t *input, uint8_t *dest, int stride,
-                     int eob);
-void vp9_idct8x8_add(const tran_low_t *input, uint8_t *dest, int stride,
-                     int eob);
-void vp9_idct16x16_add(const tran_low_t *input, uint8_t *dest, int stride,
-                       int eob);
-void vp9_idct32x32_add(const tran_low_t *input, uint8_t *dest, int stride,
-                       int eob);
-
-void vp9_iht4x4_add(TX_TYPE tx_type, const tran_low_t *input, uint8_t *dest,
-                    int stride, int eob);
-void vp9_iht8x8_add(TX_TYPE tx_type, const tran_low_t *input, uint8_t *dest,
-                    int stride, int eob);
-void vp9_iht16x16_add(TX_TYPE tx_type, const tran_low_t *input, uint8_t *dest,
-                      int stride, int eob);
-
-#if CONFIG_VP9_HIGHBITDEPTH
-void vp9_highbd_iwht4x4_add(const tran_low_t *input, uint8_t *dest, int stride,
-                            int eob, int bd);
-void vp9_highbd_idct4x4_add(const tran_low_t *input, uint8_t *dest, int stride,
-                            int eob, int bd);
-void vp9_highbd_idct8x8_add(const tran_low_t *input, uint8_t *dest, int stride,
-                            int eob, int bd);
-void vp9_highbd_idct16x16_add(const tran_low_t *input, uint8_t *dest,
-                              int stride, int eob, int bd);
-void vp9_highbd_idct32x32_add(const tran_low_t *input, uint8_t *dest,
-                              int stride, int eob, int bd);
-void vp9_highbd_iht4x4_add(TX_TYPE tx_type, const tran_low_t *input,
-                           uint8_t *dest, int stride, int eob, int bd);
-void vp9_highbd_iht8x8_add(TX_TYPE tx_type, const tran_low_t *input,
-                           uint8_t *dest, int stride, int eob, int bd);
-void vp9_highbd_iht16x16_add(TX_TYPE tx_type, const tran_low_t *input,
-                             uint8_t *dest, int stride, int eob, int bd);
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP9_COMMON_VP9_IDCT_H_
diff --git a/vp9/common/vp9_loopfilter.c b/vp9/common/vp9_loopfilter.c
deleted file mode 100644 (file)
index 183dec4..0000000
+++ /dev/null
@@ -1,1697 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#include "./vpx_config.h"
-#include "./vpx_dsp_rtcd.h"
-#include "vp9/common/vp9_loopfilter.h"
-#include "vp9/common/vp9_onyxc_int.h"
-#include "vp9/common/vp9_reconinter.h"
-#include "vpx_dsp/vpx_dsp_common.h"
-#include "vpx_mem/vpx_mem.h"
-#include "vpx_ports/mem.h"
-
-#include "vp9/common/vp9_seg_common.h"
-
-// 64 bit masks for left transform size. Each 1 represents a position where
-// we should apply a loop filter across the left border of an 8x8 block
-// boundary.
-//
-// In the case of TX_16X16->  ( in low order byte first we end up with
-// a mask that looks like this
-//
-//    10101010
-//    10101010
-//    10101010
-//    10101010
-//    10101010
-//    10101010
-//    10101010
-//    10101010
-//
-// A loopfilter should be applied to every other 8x8 horizontally.
-static const uint64_t left_64x64_txform_mask[TX_SIZES]= {
-  0xffffffffffffffffULL,  // TX_4X4
-  0xffffffffffffffffULL,  // TX_8x8
-  0x5555555555555555ULL,  // TX_16x16
-  0x1111111111111111ULL,  // TX_32x32
-};
-
-// 64 bit masks for above transform size. Each 1 represents a position where
-// we should apply a loop filter across the top border of an 8x8 block
-// boundary.
-//
-// In the case of TX_32x32 ->  ( in low order byte first we end up with
-// a mask that looks like this
-//
-//    11111111
-//    00000000
-//    00000000
-//    00000000
-//    11111111
-//    00000000
-//    00000000
-//    00000000
-//
-// A loopfilter should be applied to every other 4 the row vertically.
-static const uint64_t above_64x64_txform_mask[TX_SIZES]= {
-  0xffffffffffffffffULL,  // TX_4X4
-  0xffffffffffffffffULL,  // TX_8x8
-  0x00ff00ff00ff00ffULL,  // TX_16x16
-  0x000000ff000000ffULL,  // TX_32x32
-};
-
-// 64 bit masks for prediction sizes (left). Each 1 represents a position
-// where left border of an 8x8 block. These are aligned to the right most
-// appropriate bit, and then shifted into place.
-//
-// In the case of TX_16x32 ->  ( low order byte first ) we end up with
-// a mask that looks like this :
-//
-//  10000000
-//  10000000
-//  10000000
-//  10000000
-//  00000000
-//  00000000
-//  00000000
-//  00000000
-static const uint64_t left_prediction_mask[BLOCK_SIZES] = {
-  0x0000000000000001ULL,  // BLOCK_4X4,
-  0x0000000000000001ULL,  // BLOCK_4X8,
-  0x0000000000000001ULL,  // BLOCK_8X4,
-  0x0000000000000001ULL,  // BLOCK_8X8,
-  0x0000000000000101ULL,  // BLOCK_8X16,
-  0x0000000000000001ULL,  // BLOCK_16X8,
-  0x0000000000000101ULL,  // BLOCK_16X16,
-  0x0000000001010101ULL,  // BLOCK_16X32,
-  0x0000000000000101ULL,  // BLOCK_32X16,
-  0x0000000001010101ULL,  // BLOCK_32X32,
-  0x0101010101010101ULL,  // BLOCK_32X64,
-  0x0000000001010101ULL,  // BLOCK_64X32,
-  0x0101010101010101ULL,  // BLOCK_64X64
-};
-
-// 64 bit mask to shift and set for each prediction size.
-static const uint64_t above_prediction_mask[BLOCK_SIZES] = {
-  0x0000000000000001ULL,  // BLOCK_4X4
-  0x0000000000000001ULL,  // BLOCK_4X8
-  0x0000000000000001ULL,  // BLOCK_8X4
-  0x0000000000000001ULL,  // BLOCK_8X8
-  0x0000000000000001ULL,  // BLOCK_8X16,
-  0x0000000000000003ULL,  // BLOCK_16X8
-  0x0000000000000003ULL,  // BLOCK_16X16
-  0x0000000000000003ULL,  // BLOCK_16X32,
-  0x000000000000000fULL,  // BLOCK_32X16,
-  0x000000000000000fULL,  // BLOCK_32X32,
-  0x000000000000000fULL,  // BLOCK_32X64,
-  0x00000000000000ffULL,  // BLOCK_64X32,
-  0x00000000000000ffULL,  // BLOCK_64X64
-};
-// 64 bit mask to shift and set for each prediction size. A bit is set for
-// each 8x8 block that would be in the left most block of the given block
-// size in the 64x64 block.
-static const uint64_t size_mask[BLOCK_SIZES] = {
-  0x0000000000000001ULL,  // BLOCK_4X4
-  0x0000000000000001ULL,  // BLOCK_4X8
-  0x0000000000000001ULL,  // BLOCK_8X4
-  0x0000000000000001ULL,  // BLOCK_8X8
-  0x0000000000000101ULL,  // BLOCK_8X16,
-  0x0000000000000003ULL,  // BLOCK_16X8
-  0x0000000000000303ULL,  // BLOCK_16X16
-  0x0000000003030303ULL,  // BLOCK_16X32,
-  0x0000000000000f0fULL,  // BLOCK_32X16,
-  0x000000000f0f0f0fULL,  // BLOCK_32X32,
-  0x0f0f0f0f0f0f0f0fULL,  // BLOCK_32X64,
-  0x00000000ffffffffULL,  // BLOCK_64X32,
-  0xffffffffffffffffULL,  // BLOCK_64X64
-};
-
-// These are used for masking the left and above borders.
-static const uint64_t left_border =  0x1111111111111111ULL;
-static const uint64_t above_border = 0x000000ff000000ffULL;
-
-// 16 bit masks for uv transform sizes.
-static const uint16_t left_64x64_txform_mask_uv[TX_SIZES]= {
-  0xffff,  // TX_4X4
-  0xffff,  // TX_8x8
-  0x5555,  // TX_16x16
-  0x1111,  // TX_32x32
-};
-
-static const uint16_t above_64x64_txform_mask_uv[TX_SIZES]= {
-  0xffff,  // TX_4X4
-  0xffff,  // TX_8x8
-  0x0f0f,  // TX_16x16
-  0x000f,  // TX_32x32
-};
-
-// 16 bit left mask to shift and set for each uv prediction size.
-static const uint16_t left_prediction_mask_uv[BLOCK_SIZES] = {
-  0x0001,  // BLOCK_4X4,
-  0x0001,  // BLOCK_4X8,
-  0x0001,  // BLOCK_8X4,
-  0x0001,  // BLOCK_8X8,
-  0x0001,  // BLOCK_8X16,
-  0x0001,  // BLOCK_16X8,
-  0x0001,  // BLOCK_16X16,
-  0x0011,  // BLOCK_16X32,
-  0x0001,  // BLOCK_32X16,
-  0x0011,  // BLOCK_32X32,
-  0x1111,  // BLOCK_32X64
-  0x0011,  // BLOCK_64X32,
-  0x1111,  // BLOCK_64X64
-};
-// 16 bit above mask to shift and set for uv each prediction size.
-static const uint16_t above_prediction_mask_uv[BLOCK_SIZES] = {
-  0x0001,  // BLOCK_4X4
-  0x0001,  // BLOCK_4X8
-  0x0001,  // BLOCK_8X4
-  0x0001,  // BLOCK_8X8
-  0x0001,  // BLOCK_8X16,
-  0x0001,  // BLOCK_16X8
-  0x0001,  // BLOCK_16X16
-  0x0001,  // BLOCK_16X32,
-  0x0003,  // BLOCK_32X16,
-  0x0003,  // BLOCK_32X32,
-  0x0003,  // BLOCK_32X64,
-  0x000f,  // BLOCK_64X32,
-  0x000f,  // BLOCK_64X64
-};
-
-// 64 bit mask to shift and set for each uv prediction size
-static const uint16_t size_mask_uv[BLOCK_SIZES] = {
-  0x0001,  // BLOCK_4X4
-  0x0001,  // BLOCK_4X8
-  0x0001,  // BLOCK_8X4
-  0x0001,  // BLOCK_8X8
-  0x0001,  // BLOCK_8X16,
-  0x0001,  // BLOCK_16X8
-  0x0001,  // BLOCK_16X16
-  0x0011,  // BLOCK_16X32,
-  0x0003,  // BLOCK_32X16,
-  0x0033,  // BLOCK_32X32,
-  0x3333,  // BLOCK_32X64,
-  0x00ff,  // BLOCK_64X32,
-  0xffff,  // BLOCK_64X64
-};
-static const uint16_t left_border_uv =  0x1111;
-static const uint16_t above_border_uv = 0x000f;
-
-static const int mode_lf_lut[MB_MODE_COUNT] = {
-  0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  // INTRA_MODES
-  1, 1, 0, 1                     // INTER_MODES (ZEROMV == 0)
-};
-
-static void update_sharpness(loop_filter_info_n *lfi, int sharpness_lvl) {
-  int lvl;
-
-  // For each possible value for the loop filter fill out limits
-  for (lvl = 0; lvl <= MAX_LOOP_FILTER; lvl++) {
-    // Set loop filter parameters that control sharpness.
-    int block_inside_limit = lvl >> ((sharpness_lvl > 0) + (sharpness_lvl > 4));
-
-    if (sharpness_lvl > 0) {
-      if (block_inside_limit > (9 - sharpness_lvl))
-        block_inside_limit = (9 - sharpness_lvl);
-    }
-
-    if (block_inside_limit < 1)
-      block_inside_limit = 1;
-
-    memset(lfi->lfthr[lvl].lim, block_inside_limit, SIMD_WIDTH);
-    memset(lfi->lfthr[lvl].mblim, (2 * (lvl + 2) + block_inside_limit),
-           SIMD_WIDTH);
-  }
-}
-
-static uint8_t get_filter_level(const loop_filter_info_n *lfi_n,
-                                const MODE_INFO *mi) {
-  return lfi_n->lvl[mi->segment_id][mi->ref_frame[0]]
-                   [mode_lf_lut[mi->mode]];
-}
-
-void vp9_loop_filter_init(VP9_COMMON *cm) {
-  loop_filter_info_n *lfi = &cm->lf_info;
-  struct loopfilter *lf = &cm->lf;
-  int lvl;
-
-  // init limits for given sharpness
-  update_sharpness(lfi, lf->sharpness_level);
-  lf->last_sharpness_level = lf->sharpness_level;
-
-  // init hev threshold const vectors
-  for (lvl = 0; lvl <= MAX_LOOP_FILTER; lvl++)
-    memset(lfi->lfthr[lvl].hev_thr, (lvl >> 4), SIMD_WIDTH);
-}
-
-void vp9_loop_filter_frame_init(VP9_COMMON *cm, int default_filt_lvl) {
-  int seg_id;
-  // n_shift is the multiplier for lf_deltas
-  // the multiplier is 1 for when filter_lvl is between 0 and 31;
-  // 2 when filter_lvl is between 32 and 63
-  const int scale = 1 << (default_filt_lvl >> 5);
-  loop_filter_info_n *const lfi = &cm->lf_info;
-  struct loopfilter *const lf = &cm->lf;
-  const struct segmentation *const seg = &cm->seg;
-
-  // update limits if sharpness has changed
-  if (lf->last_sharpness_level != lf->sharpness_level) {
-    update_sharpness(lfi, lf->sharpness_level);
-    lf->last_sharpness_level = lf->sharpness_level;
-  }
-
-  for (seg_id = 0; seg_id < MAX_SEGMENTS; seg_id++) {
-    int lvl_seg = default_filt_lvl;
-    if (segfeature_active(seg, seg_id, SEG_LVL_ALT_LF)) {
-      const int data = get_segdata(seg, seg_id, SEG_LVL_ALT_LF);
-      lvl_seg = clamp(seg->abs_delta == SEGMENT_ABSDATA ?
-                      data : default_filt_lvl + data,
-                      0, MAX_LOOP_FILTER);
-    }
-
-    if (!lf->mode_ref_delta_enabled) {
-      // we could get rid of this if we assume that deltas are set to
-      // zero when not in use; encoder always uses deltas
-      memset(lfi->lvl[seg_id], lvl_seg, sizeof(lfi->lvl[seg_id]));
-    } else {
-      int ref, mode;
-      const int intra_lvl = lvl_seg + lf->ref_deltas[INTRA_FRAME] * scale;
-      lfi->lvl[seg_id][INTRA_FRAME][0] = clamp(intra_lvl, 0, MAX_LOOP_FILTER);
-
-      for (ref = LAST_FRAME; ref < MAX_REF_FRAMES; ++ref) {
-        for (mode = 0; mode < MAX_MODE_LF_DELTAS; ++mode) {
-          const int inter_lvl = lvl_seg + lf->ref_deltas[ref] * scale
-                                        + lf->mode_deltas[mode] * scale;
-          lfi->lvl[seg_id][ref][mode] = clamp(inter_lvl, 0, MAX_LOOP_FILTER);
-        }
-      }
-    }
-  }
-}
-
-static void filter_selectively_vert_row2(int subsampling_factor,
-                                         uint8_t *s, int pitch,
-                                         unsigned int mask_16x16,
-                                         unsigned int mask_8x8,
-                                         unsigned int mask_4x4,
-                                         unsigned int mask_4x4_int,
-                                         const loop_filter_thresh *lfthr,
-                                         const uint8_t *lfl) {
-  const int dual_mask_cutoff = subsampling_factor ? 0xff : 0xffff;
-  const int lfl_forward = subsampling_factor ? 4 : 8;
-  const unsigned int dual_one = 1 | (1 << lfl_forward);
-  unsigned int mask;
-  uint8_t *ss[2];
-  ss[0] = s;
-
-  for (mask =
-           (mask_16x16 | mask_8x8 | mask_4x4 | mask_4x4_int) & dual_mask_cutoff;
-       mask; mask = (mask & ~dual_one) >> 1) {
-    if (mask & dual_one) {
-      const loop_filter_thresh *lfis[2];
-      lfis[0] = lfthr + *lfl;
-      lfis[1] = lfthr + *(lfl + lfl_forward);
-      ss[1] = ss[0] + 8 * pitch;
-
-      if (mask_16x16 & dual_one) {
-        if ((mask_16x16 & dual_one) == dual_one) {
-          vpx_lpf_vertical_16_dual(ss[0], pitch, lfis[0]->mblim, lfis[0]->lim,
-                                   lfis[0]->hev_thr);
-        } else {
-          const loop_filter_thresh *lfi = lfis[!(mask_16x16 & 1)];
-          vpx_lpf_vertical_16(ss[!(mask_16x16 & 1)], pitch, lfi->mblim,
-                              lfi->lim, lfi->hev_thr);
-        }
-      }
-
-      if (mask_8x8 & dual_one) {
-        if ((mask_8x8 & dual_one) == dual_one) {
-          vpx_lpf_vertical_8_dual(ss[0], pitch, lfis[0]->mblim, lfis[0]->lim,
-                                  lfis[0]->hev_thr, lfis[1]->mblim,
-                                  lfis[1]->lim, lfis[1]->hev_thr);
-        } else {
-          const loop_filter_thresh *lfi = lfis[!(mask_8x8 & 1)];
-          vpx_lpf_vertical_8(ss[!(mask_8x8 & 1)], pitch, lfi->mblim, lfi->lim,
-                             lfi->hev_thr);
-        }
-      }
-
-      if (mask_4x4 & dual_one) {
-        if ((mask_4x4 & dual_one) == dual_one) {
-          vpx_lpf_vertical_4_dual(ss[0], pitch, lfis[0]->mblim, lfis[0]->lim,
-                                  lfis[0]->hev_thr, lfis[1]->mblim,
-                                  lfis[1]->lim, lfis[1]->hev_thr);
-        } else {
-          const loop_filter_thresh *lfi = lfis[!(mask_4x4 & 1)];
-          vpx_lpf_vertical_4(ss[!(mask_4x4 & 1)], pitch, lfi->mblim, lfi->lim,
-                             lfi->hev_thr);
-        }
-      }
-
-      if (mask_4x4_int & dual_one) {
-        if ((mask_4x4_int & dual_one) == dual_one) {
-          vpx_lpf_vertical_4_dual(ss[0] + 4, pitch, lfis[0]->mblim,
-                                  lfis[0]->lim, lfis[0]->hev_thr,
-                                  lfis[1]->mblim, lfis[1]->lim,
-                                  lfis[1]->hev_thr);
-        } else {
-          const loop_filter_thresh *lfi = lfis[!(mask_4x4_int & 1)];
-          vpx_lpf_vertical_4(ss[!(mask_4x4_int & 1)] + 4, pitch, lfi->mblim,
-                             lfi->lim, lfi->hev_thr);
-        }
-      }
-    }
-
-    ss[0] += 8;
-    lfl += 1;
-    mask_16x16 >>= 1;
-    mask_8x8 >>= 1;
-    mask_4x4 >>= 1;
-    mask_4x4_int >>= 1;
-  }
-}
-
-#if CONFIG_VP9_HIGHBITDEPTH
-static void highbd_filter_selectively_vert_row2(int subsampling_factor,
-                                                uint16_t *s, int pitch,
-                                                unsigned int mask_16x16,
-                                                unsigned int mask_8x8,
-                                                unsigned int mask_4x4,
-                                                unsigned int mask_4x4_int,
-                                                const loop_filter_thresh *lfthr,
-                                                const uint8_t *lfl, int bd) {
-  const int dual_mask_cutoff = subsampling_factor ? 0xff : 0xffff;
-  const int lfl_forward = subsampling_factor ? 4 : 8;
-  const unsigned int dual_one = 1 | (1 << lfl_forward);
-  unsigned int mask;
-  uint16_t *ss[2];
-  ss[0] = s;
-
-  for (mask =
-           (mask_16x16 | mask_8x8 | mask_4x4 | mask_4x4_int) & dual_mask_cutoff;
-       mask; mask = (mask & ~dual_one) >> 1) {
-    if (mask & dual_one) {
-      const loop_filter_thresh *lfis[2];
-      lfis[0] = lfthr + *lfl;
-      lfis[1] = lfthr + *(lfl + lfl_forward);
-      ss[1] = ss[0] + 8 * pitch;
-
-      if (mask_16x16 & dual_one) {
-        if ((mask_16x16 & dual_one) == dual_one) {
-          vpx_highbd_lpf_vertical_16_dual(ss[0], pitch, lfis[0]->mblim,
-                                          lfis[0]->lim, lfis[0]->hev_thr, bd);
-        } else {
-          const loop_filter_thresh *lfi = lfis[!(mask_16x16 & 1)];
-          vpx_highbd_lpf_vertical_16(ss[!(mask_16x16 & 1)], pitch, lfi->mblim,
-                                     lfi->lim, lfi->hev_thr, bd);
-        }
-      }
-
-      if (mask_8x8 & dual_one) {
-        if ((mask_8x8 & dual_one) == dual_one) {
-          vpx_highbd_lpf_vertical_8_dual(ss[0], pitch, lfis[0]->mblim,
-                                         lfis[0]->lim, lfis[0]->hev_thr,
-                                         lfis[1]->mblim, lfis[1]->lim,
-                                         lfis[1]->hev_thr, bd);
-        } else {
-          const loop_filter_thresh *lfi = lfis[!(mask_8x8 & 1)];
-          vpx_highbd_lpf_vertical_8(ss[!(mask_8x8 & 1)], pitch, lfi->mblim,
-                                    lfi->lim, lfi->hev_thr, bd);
-        }
-      }
-
-      if (mask_4x4 & dual_one) {
-        if ((mask_4x4 & dual_one) == dual_one) {
-          vpx_highbd_lpf_vertical_4_dual(ss[0], pitch, lfis[0]->mblim,
-                                         lfis[0]->lim, lfis[0]->hev_thr,
-                                         lfis[1]->mblim, lfis[1]->lim,
-                                         lfis[1]->hev_thr, bd);
-        } else {
-          const loop_filter_thresh *lfi = lfis[!(mask_4x4 & 1)];
-          vpx_highbd_lpf_vertical_4(ss[!(mask_4x4 & 1)], pitch, lfi->mblim,
-                                    lfi->lim, lfi->hev_thr, bd);
-        }
-      }
-
-      if (mask_4x4_int & dual_one) {
-        if ((mask_4x4_int & dual_one) == dual_one) {
-          vpx_highbd_lpf_vertical_4_dual(ss[0] + 4, pitch, lfis[0]->mblim,
-                                         lfis[0]->lim, lfis[0]->hev_thr,
-                                         lfis[1]->mblim, lfis[1]->lim,
-                                         lfis[1]->hev_thr, bd);
-        } else {
-          const loop_filter_thresh *lfi = lfis[!(mask_4x4_int & 1)];
-          vpx_highbd_lpf_vertical_4(ss[!(mask_4x4_int & 1)] + 4, pitch,
-                                    lfi->mblim, lfi->lim, lfi->hev_thr, bd);
-        }
-      }
-    }
-
-    ss[0] += 8;
-    lfl += 1;
-    mask_16x16 >>= 1;
-    mask_8x8 >>= 1;
-    mask_4x4 >>= 1;
-    mask_4x4_int >>= 1;
-  }
-}
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-
-static void filter_selectively_horiz(uint8_t *s, int pitch,
-                                     unsigned int mask_16x16,
-                                     unsigned int mask_8x8,
-                                     unsigned int mask_4x4,
-                                     unsigned int mask_4x4_int,
-                                     const loop_filter_thresh *lfthr,
-                                     const uint8_t *lfl) {
-  unsigned int mask;
-  int count;
-
-  for (mask = mask_16x16 | mask_8x8 | mask_4x4 | mask_4x4_int;
-       mask; mask >>= count) {
-    count = 1;
-    if (mask & 1) {
-      const loop_filter_thresh *lfi = lfthr + *lfl;
-
-      if (mask_16x16 & 1) {
-        if ((mask_16x16 & 3) == 3) {
-          vpx_lpf_horizontal_edge_16(s, pitch, lfi->mblim, lfi->lim,
-                                     lfi->hev_thr);
-          count = 2;
-        } else {
-          vpx_lpf_horizontal_edge_8(s, pitch, lfi->mblim, lfi->lim,
-                                    lfi->hev_thr);
-        }
-      } else if (mask_8x8 & 1) {
-        if ((mask_8x8 & 3) == 3) {
-          // Next block's thresholds.
-          const loop_filter_thresh *lfin = lfthr + *(lfl + 1);
-
-          vpx_lpf_horizontal_8_dual(s, pitch, lfi->mblim, lfi->lim,
-                                    lfi->hev_thr, lfin->mblim, lfin->lim,
-                                    lfin->hev_thr);
-
-          if ((mask_4x4_int & 3) == 3) {
-            vpx_lpf_horizontal_4_dual(s + 4 * pitch, pitch, lfi->mblim,
-                                      lfi->lim, lfi->hev_thr, lfin->mblim,
-                                      lfin->lim, lfin->hev_thr);
-          } else {
-            if (mask_4x4_int & 1)
-              vpx_lpf_horizontal_4(s + 4 * pitch, pitch, lfi->mblim, lfi->lim,
-                                   lfi->hev_thr);
-            else if (mask_4x4_int & 2)
-              vpx_lpf_horizontal_4(s + 8 + 4 * pitch, pitch, lfin->mblim,
-                                   lfin->lim, lfin->hev_thr);
-          }
-          count = 2;
-        } else {
-          vpx_lpf_horizontal_8(s, pitch, lfi->mblim, lfi->lim, lfi->hev_thr);
-
-          if (mask_4x4_int & 1)
-            vpx_lpf_horizontal_4(s + 4 * pitch, pitch, lfi->mblim, lfi->lim,
-                                 lfi->hev_thr);
-        }
-      } else if (mask_4x4 & 1) {
-        if ((mask_4x4 & 3) == 3) {
-          // Next block's thresholds.
-          const loop_filter_thresh *lfin = lfthr + *(lfl + 1);
-
-          vpx_lpf_horizontal_4_dual(s, pitch, lfi->mblim, lfi->lim,
-                                    lfi->hev_thr, lfin->mblim, lfin->lim,
-                                    lfin->hev_thr);
-          if ((mask_4x4_int & 3) == 3) {
-            vpx_lpf_horizontal_4_dual(s + 4 * pitch, pitch, lfi->mblim,
-                                      lfi->lim, lfi->hev_thr, lfin->mblim,
-                                      lfin->lim, lfin->hev_thr);
-          } else {
-            if (mask_4x4_int & 1)
-              vpx_lpf_horizontal_4(s + 4 * pitch, pitch, lfi->mblim, lfi->lim,
-                                   lfi->hev_thr);
-            else if (mask_4x4_int & 2)
-              vpx_lpf_horizontal_4(s + 8 + 4 * pitch, pitch, lfin->mblim,
-                                   lfin->lim, lfin->hev_thr);
-          }
-          count = 2;
-        } else {
-          vpx_lpf_horizontal_4(s, pitch, lfi->mblim, lfi->lim, lfi->hev_thr);
-
-          if (mask_4x4_int & 1)
-            vpx_lpf_horizontal_4(s + 4 * pitch, pitch, lfi->mblim, lfi->lim,
-                                 lfi->hev_thr);
-        }
-      } else {
-        vpx_lpf_horizontal_4(s + 4 * pitch, pitch, lfi->mblim, lfi->lim,
-                             lfi->hev_thr);
-      }
-    }
-    s += 8 * count;
-    lfl += count;
-    mask_16x16 >>= count;
-    mask_8x8 >>= count;
-    mask_4x4 >>= count;
-    mask_4x4_int >>= count;
-  }
-}
-
-#if CONFIG_VP9_HIGHBITDEPTH
-static void highbd_filter_selectively_horiz(uint16_t *s, int pitch,
-                                            unsigned int mask_16x16,
-                                            unsigned int mask_8x8,
-                                            unsigned int mask_4x4,
-                                            unsigned int mask_4x4_int,
-                                            const loop_filter_thresh *lfthr,
-                                            const uint8_t *lfl, int bd) {
-  unsigned int mask;
-  int count;
-
-  for (mask = mask_16x16 | mask_8x8 | mask_4x4 | mask_4x4_int;
-       mask; mask >>= count) {
-    count = 1;
-    if (mask & 1) {
-      const loop_filter_thresh *lfi = lfthr + *lfl;
-
-      if (mask_16x16 & 1) {
-        if ((mask_16x16 & 3) == 3) {
-          vpx_highbd_lpf_horizontal_edge_16(s, pitch, lfi->mblim, lfi->lim,
-                                            lfi->hev_thr, bd);
-          count = 2;
-        } else {
-          vpx_highbd_lpf_horizontal_edge_8(s, pitch, lfi->mblim, lfi->lim,
-                                           lfi->hev_thr, bd);
-        }
-      } else if (mask_8x8 & 1) {
-        if ((mask_8x8 & 3) == 3) {
-          // Next block's thresholds.
-          const loop_filter_thresh *lfin = lfthr + *(lfl + 1);
-
-          vpx_highbd_lpf_horizontal_8_dual(s, pitch, lfi->mblim, lfi->lim,
-                                           lfi->hev_thr, lfin->mblim, lfin->lim,
-                                           lfin->hev_thr, bd);
-
-          if ((mask_4x4_int & 3) == 3) {
-            vpx_highbd_lpf_horizontal_4_dual(s + 4 * pitch, pitch, lfi->mblim,
-                                             lfi->lim, lfi->hev_thr,
-                                             lfin->mblim, lfin->lim,
-                                             lfin->hev_thr, bd);
-          } else {
-            if (mask_4x4_int & 1) {
-              vpx_highbd_lpf_horizontal_4(s + 4 * pitch, pitch, lfi->mblim,
-                                          lfi->lim, lfi->hev_thr, bd);
-            } else if (mask_4x4_int & 2) {
-              vpx_highbd_lpf_horizontal_4(s + 8 + 4 * pitch, pitch, lfin->mblim,
-                                          lfin->lim, lfin->hev_thr, bd);
-            }
-          }
-          count = 2;
-        } else {
-          vpx_highbd_lpf_horizontal_8(s, pitch, lfi->mblim, lfi->lim,
-                                      lfi->hev_thr, bd);
-
-          if (mask_4x4_int & 1) {
-            vpx_highbd_lpf_horizontal_4(s + 4 * pitch, pitch, lfi->mblim,
-                                        lfi->lim, lfi->hev_thr, bd);
-          }
-        }
-      } else if (mask_4x4 & 1) {
-        if ((mask_4x4 & 3) == 3) {
-          // Next block's thresholds.
-          const loop_filter_thresh *lfin = lfthr + *(lfl + 1);
-
-          vpx_highbd_lpf_horizontal_4_dual(s, pitch, lfi->mblim, lfi->lim,
-                                           lfi->hev_thr, lfin->mblim, lfin->lim,
-                                           lfin->hev_thr, bd);
-          if ((mask_4x4_int & 3) == 3) {
-            vpx_highbd_lpf_horizontal_4_dual(s + 4 * pitch, pitch, lfi->mblim,
-                                             lfi->lim, lfi->hev_thr,
-                                             lfin->mblim, lfin->lim,
-                                             lfin->hev_thr, bd);
-          } else {
-            if (mask_4x4_int & 1) {
-              vpx_highbd_lpf_horizontal_4(s + 4 * pitch, pitch, lfi->mblim,
-                                          lfi->lim, lfi->hev_thr, bd);
-            } else if (mask_4x4_int & 2) {
-              vpx_highbd_lpf_horizontal_4(s + 8 + 4 * pitch, pitch, lfin->mblim,
-                                          lfin->lim, lfin->hev_thr, bd);
-            }
-          }
-          count = 2;
-        } else {
-          vpx_highbd_lpf_horizontal_4(s, pitch, lfi->mblim, lfi->lim,
-                                      lfi->hev_thr, bd);
-
-          if (mask_4x4_int & 1) {
-            vpx_highbd_lpf_horizontal_4(s + 4 * pitch, pitch, lfi->mblim,
-                                        lfi->lim, lfi->hev_thr, bd);
-          }
-        }
-      } else {
-        vpx_highbd_lpf_horizontal_4(s + 4 * pitch, pitch, lfi->mblim, lfi->lim,
-                                    lfi->hev_thr, bd);
-      }
-    }
-    s += 8 * count;
-    lfl += count;
-    mask_16x16 >>= count;
-    mask_8x8 >>= count;
-    mask_4x4 >>= count;
-    mask_4x4_int >>= count;
-  }
-}
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-
-// This function ors into the current lfm structure, where to do loop
-// filters for the specific mi we are looking at. It uses information
-// including the block_size_type (32x16, 32x32, etc.), the transform size,
-// whether there were any coefficients encoded, and the loop filter strength
-// block we are currently looking at. Shift is used to position the
-// 1's we produce.
-static void build_masks(const loop_filter_info_n *const lfi_n,
-                        const MODE_INFO *mi, const int shift_y,
-                        const int shift_uv,
-                        LOOP_FILTER_MASK *lfm) {
-  const BLOCK_SIZE block_size = mi->sb_type;
-  const TX_SIZE tx_size_y = mi->tx_size;
-  const TX_SIZE tx_size_uv = get_uv_tx_size_impl(tx_size_y, block_size, 1, 1);
-  const int filter_level = get_filter_level(lfi_n, mi);
-  uint64_t *const left_y = &lfm->left_y[tx_size_y];
-  uint64_t *const above_y = &lfm->above_y[tx_size_y];
-  uint64_t *const int_4x4_y = &lfm->int_4x4_y;
-  uint16_t *const left_uv = &lfm->left_uv[tx_size_uv];
-  uint16_t *const above_uv = &lfm->above_uv[tx_size_uv];
-  uint16_t *const int_4x4_uv = &lfm->int_4x4_uv;
-  int i;
-
-  // If filter level is 0 we don't loop filter.
-  if (!filter_level) {
-    return;
-  } else {
-    const int w = num_8x8_blocks_wide_lookup[block_size];
-    const int h = num_8x8_blocks_high_lookup[block_size];
-    int index = shift_y;
-    for (i = 0; i < h; i++) {
-      memset(&lfm->lfl_y[index], filter_level, w);
-      index += 8;
-    }
-  }
-
-  // These set 1 in the current block size for the block size edges.
-  // For instance if the block size is 32x16, we'll set:
-  //    above =   1111
-  //              0000
-  //    and
-  //    left  =   1000
-  //          =   1000
-  // NOTE : In this example the low bit is left most ( 1000 ) is stored as
-  //        1,  not 8...
-  //
-  // U and V set things on a 16 bit scale.
-  //
-  *above_y |= above_prediction_mask[block_size] << shift_y;
-  *above_uv |= above_prediction_mask_uv[block_size] << shift_uv;
-  *left_y |= left_prediction_mask[block_size] << shift_y;
-  *left_uv |= left_prediction_mask_uv[block_size] << shift_uv;
-
-  // If the block has no coefficients and is not intra we skip applying
-  // the loop filter on block edges.
-  if (mi->skip && is_inter_block(mi))
-    return;
-
-  // Here we are adding a mask for the transform size. The transform
-  // size mask is set to be correct for a 64x64 prediction block size. We
-  // mask to match the size of the block we are working on and then shift it
-  // into place..
-  *above_y |= (size_mask[block_size] &
-               above_64x64_txform_mask[tx_size_y]) << shift_y;
-  *above_uv |= (size_mask_uv[block_size] &
-                above_64x64_txform_mask_uv[tx_size_uv]) << shift_uv;
-
-  *left_y |= (size_mask[block_size] &
-              left_64x64_txform_mask[tx_size_y]) << shift_y;
-  *left_uv |= (size_mask_uv[block_size] &
-               left_64x64_txform_mask_uv[tx_size_uv]) << shift_uv;
-
-  // Here we are trying to determine what to do with the internal 4x4 block
-  // boundaries.  These differ from the 4x4 boundaries on the outside edge of
-  // an 8x8 in that the internal ones can be skipped and don't depend on
-  // the prediction block size.
-  if (tx_size_y == TX_4X4)
-    *int_4x4_y |= size_mask[block_size] << shift_y;
-
-  if (tx_size_uv == TX_4X4)
-    *int_4x4_uv |= (size_mask_uv[block_size] & 0xffff) << shift_uv;
-}
-
-// This function does the same thing as the one above with the exception that
-// it only affects the y masks. It exists because for blocks < 16x16 in size,
-// we only update u and v masks on the first block.
-static void build_y_mask(const loop_filter_info_n *const lfi_n,
-                         const MODE_INFO *mi, const int shift_y,
-                         LOOP_FILTER_MASK *lfm) {
-  const BLOCK_SIZE block_size = mi->sb_type;
-  const TX_SIZE tx_size_y = mi->tx_size;
-  const int filter_level = get_filter_level(lfi_n, mi);
-  uint64_t *const left_y = &lfm->left_y[tx_size_y];
-  uint64_t *const above_y = &lfm->above_y[tx_size_y];
-  uint64_t *const int_4x4_y = &lfm->int_4x4_y;
-  int i;
-
-  if (!filter_level) {
-    return;
-  } else {
-    const int w = num_8x8_blocks_wide_lookup[block_size];
-    const int h = num_8x8_blocks_high_lookup[block_size];
-    int index = shift_y;
-    for (i = 0; i < h; i++) {
-      memset(&lfm->lfl_y[index], filter_level, w);
-      index += 8;
-    }
-  }
-
-  *above_y |= above_prediction_mask[block_size] << shift_y;
-  *left_y |= left_prediction_mask[block_size] << shift_y;
-
-  if (mi->skip && is_inter_block(mi))
-    return;
-
-  *above_y |= (size_mask[block_size] &
-               above_64x64_txform_mask[tx_size_y]) << shift_y;
-
-  *left_y |= (size_mask[block_size] &
-              left_64x64_txform_mask[tx_size_y]) << shift_y;
-
-  if (tx_size_y == TX_4X4)
-    *int_4x4_y |= size_mask[block_size] << shift_y;
-}
-
-void vp9_adjust_mask(VP9_COMMON *const cm, const int mi_row,
-                     const int mi_col, LOOP_FILTER_MASK *lfm) {
-  int i;
-
-  // The largest loopfilter we have is 16x16 so we use the 16x16 mask
-  // for 32x32 transforms also.
-  lfm->left_y[TX_16X16] |= lfm->left_y[TX_32X32];
-  lfm->above_y[TX_16X16] |= lfm->above_y[TX_32X32];
-  lfm->left_uv[TX_16X16] |= lfm->left_uv[TX_32X32];
-  lfm->above_uv[TX_16X16] |= lfm->above_uv[TX_32X32];
-
-  // We do at least 8 tap filter on every 32x32 even if the transform size
-  // is 4x4. So if the 4x4 is set on a border pixel add it to the 8x8 and
-  // remove it from the 4x4.
-  lfm->left_y[TX_8X8] |= lfm->left_y[TX_4X4] & left_border;
-  lfm->left_y[TX_4X4] &= ~left_border;
-  lfm->above_y[TX_8X8] |= lfm->above_y[TX_4X4] & above_border;
-  lfm->above_y[TX_4X4] &= ~above_border;
-  lfm->left_uv[TX_8X8] |= lfm->left_uv[TX_4X4] & left_border_uv;
-  lfm->left_uv[TX_4X4] &= ~left_border_uv;
-  lfm->above_uv[TX_8X8] |= lfm->above_uv[TX_4X4] & above_border_uv;
-  lfm->above_uv[TX_4X4] &= ~above_border_uv;
-
-  // We do some special edge handling.
-  if (mi_row + MI_BLOCK_SIZE > cm->mi_rows) {
-    const uint64_t rows = cm->mi_rows - mi_row;
-
-    // Each pixel inside the border gets a 1,
-    const uint64_t mask_y = (((uint64_t) 1 << (rows << 3)) - 1);
-    const uint16_t mask_uv = (((uint16_t) 1 << (((rows + 1) >> 1) << 2)) - 1);
-
-    // Remove values completely outside our border.
-    for (i = 0; i < TX_32X32; i++) {
-      lfm->left_y[i] &= mask_y;
-      lfm->above_y[i] &= mask_y;
-      lfm->left_uv[i] &= mask_uv;
-      lfm->above_uv[i] &= mask_uv;
-    }
-    lfm->int_4x4_y &= mask_y;
-    lfm->int_4x4_uv &= mask_uv;
-
-    // We don't apply a wide loop filter on the last uv block row. If set
-    // apply the shorter one instead.
-    if (rows == 1) {
-      lfm->above_uv[TX_8X8] |= lfm->above_uv[TX_16X16];
-      lfm->above_uv[TX_16X16] = 0;
-    }
-    if (rows == 5) {
-      lfm->above_uv[TX_8X8] |= lfm->above_uv[TX_16X16] & 0xff00;
-      lfm->above_uv[TX_16X16] &= ~(lfm->above_uv[TX_16X16] & 0xff00);
-    }
-  }
-
-  if (mi_col + MI_BLOCK_SIZE > cm->mi_cols) {
-    const uint64_t columns = cm->mi_cols - mi_col;
-
-    // Each pixel inside the border gets a 1, the multiply copies the border
-    // to where we need it.
-    const uint64_t mask_y  = (((1 << columns) - 1)) * 0x0101010101010101ULL;
-    const uint16_t mask_uv = ((1 << ((columns + 1) >> 1)) - 1) * 0x1111;
-
-    // Internal edges are not applied on the last column of the image so
-    // we mask 1 more for the internal edges
-    const uint16_t mask_uv_int = ((1 << (columns >> 1)) - 1) * 0x1111;
-
-    // Remove the bits outside the image edge.
-    for (i = 0; i < TX_32X32; i++) {
-      lfm->left_y[i] &= mask_y;
-      lfm->above_y[i] &= mask_y;
-      lfm->left_uv[i] &= mask_uv;
-      lfm->above_uv[i] &= mask_uv;
-    }
-    lfm->int_4x4_y &= mask_y;
-    lfm->int_4x4_uv &= mask_uv_int;
-
-    // We don't apply a wide loop filter on the last uv column. If set
-    // apply the shorter one instead.
-    if (columns == 1) {
-      lfm->left_uv[TX_8X8] |= lfm->left_uv[TX_16X16];
-      lfm->left_uv[TX_16X16] = 0;
-    }
-    if (columns == 5) {
-      lfm->left_uv[TX_8X8] |= (lfm->left_uv[TX_16X16] & 0xcccc);
-      lfm->left_uv[TX_16X16] &= ~(lfm->left_uv[TX_16X16] & 0xcccc);
-    }
-  }
-  // We don't apply a loop filter on the first column in the image, mask that
-  // out.
-  if (mi_col == 0) {
-    for (i = 0; i < TX_32X32; i++) {
-      lfm->left_y[i] &= 0xfefefefefefefefeULL;
-      lfm->left_uv[i] &= 0xeeee;
-    }
-  }
-
-  // Assert if we try to apply 2 different loop filters at the same position.
-  assert(!(lfm->left_y[TX_16X16] & lfm->left_y[TX_8X8]));
-  assert(!(lfm->left_y[TX_16X16] & lfm->left_y[TX_4X4]));
-  assert(!(lfm->left_y[TX_8X8] & lfm->left_y[TX_4X4]));
-  assert(!(lfm->int_4x4_y & lfm->left_y[TX_16X16]));
-  assert(!(lfm->left_uv[TX_16X16]&lfm->left_uv[TX_8X8]));
-  assert(!(lfm->left_uv[TX_16X16] & lfm->left_uv[TX_4X4]));
-  assert(!(lfm->left_uv[TX_8X8] & lfm->left_uv[TX_4X4]));
-  assert(!(lfm->int_4x4_uv & lfm->left_uv[TX_16X16]));
-  assert(!(lfm->above_y[TX_16X16] & lfm->above_y[TX_8X8]));
-  assert(!(lfm->above_y[TX_16X16] & lfm->above_y[TX_4X4]));
-  assert(!(lfm->above_y[TX_8X8] & lfm->above_y[TX_4X4]));
-  assert(!(lfm->int_4x4_y & lfm->above_y[TX_16X16]));
-  assert(!(lfm->above_uv[TX_16X16] & lfm->above_uv[TX_8X8]));
-  assert(!(lfm->above_uv[TX_16X16] & lfm->above_uv[TX_4X4]));
-  assert(!(lfm->above_uv[TX_8X8] & lfm->above_uv[TX_4X4]));
-  assert(!(lfm->int_4x4_uv & lfm->above_uv[TX_16X16]));
-}
-
-// This function sets up the bit masks for the entire 64x64 region represented
-// by mi_row, mi_col.
-void vp9_setup_mask(VP9_COMMON *const cm, const int mi_row, const int mi_col,
-                    MODE_INFO **mi, const int mode_info_stride,
-                    LOOP_FILTER_MASK *lfm) {
-  int idx_32, idx_16, idx_8;
-  const loop_filter_info_n *const lfi_n = &cm->lf_info;
-  MODE_INFO **mip = mi;
-  MODE_INFO **mip2 = mi;
-
-  // These are offsets to the next mi in the 64x64 block. It is what gets
-  // added to the mi ptr as we go through each loop. It helps us to avoid
-  // setting up special row and column counters for each index. The last step
-  // brings us out back to the starting position.
-  const int offset_32[] = {4, (mode_info_stride << 2) - 4, 4,
-                           -(mode_info_stride << 2) - 4};
-  const int offset_16[] = {2, (mode_info_stride << 1) - 2, 2,
-                           -(mode_info_stride << 1) - 2};
-  const int offset[] = {1, mode_info_stride - 1, 1, -mode_info_stride - 1};
-
-  // Following variables represent shifts to position the current block
-  // mask over the appropriate block. A shift of 36 to the left will move
-  // the bits for the final 32 by 32 block in the 64x64 up 4 rows and left
-  // 4 rows to the appropriate spot.
-  const int shift_32_y[] = {0, 4, 32, 36};
-  const int shift_16_y[] = {0, 2, 16, 18};
-  const int shift_8_y[] = {0, 1, 8, 9};
-  const int shift_32_uv[] = {0, 2, 8, 10};
-  const int shift_16_uv[] = {0, 1, 4, 5};
-  const int max_rows = (mi_row + MI_BLOCK_SIZE > cm->mi_rows ?
-                        cm->mi_rows - mi_row : MI_BLOCK_SIZE);
-  const int max_cols = (mi_col + MI_BLOCK_SIZE > cm->mi_cols ?
-                        cm->mi_cols - mi_col : MI_BLOCK_SIZE);
-
-  vp9_zero(*lfm);
-  assert(mip[0] != NULL);
-
-  switch (mip[0]->sb_type) {
-    case BLOCK_64X64:
-      build_masks(lfi_n, mip[0] , 0, 0, lfm);
-      break;
-    case BLOCK_64X32:
-      build_masks(lfi_n, mip[0], 0, 0, lfm);
-      mip2 = mip + mode_info_stride * 4;
-      if (4 >= max_rows)
-        break;
-      build_masks(lfi_n, mip2[0], 32, 8, lfm);
-      break;
-    case BLOCK_32X64:
-      build_masks(lfi_n, mip[0], 0, 0, lfm);
-      mip2 = mip + 4;
-      if (4 >= max_cols)
-        break;
-      build_masks(lfi_n, mip2[0], 4, 2, lfm);
-      break;
-    default:
-      for (idx_32 = 0; idx_32 < 4; mip += offset_32[idx_32], ++idx_32) {
-        const int shift_y = shift_32_y[idx_32];
-        const int shift_uv = shift_32_uv[idx_32];
-        const int mi_32_col_offset = ((idx_32 & 1) << 2);
-        const int mi_32_row_offset = ((idx_32 >> 1) << 2);
-        if (mi_32_col_offset >= max_cols || mi_32_row_offset >= max_rows)
-          continue;
-        switch (mip[0]->sb_type) {
-          case BLOCK_32X32:
-            build_masks(lfi_n, mip[0], shift_y, shift_uv, lfm);
-            break;
-          case BLOCK_32X16:
-            build_masks(lfi_n, mip[0], shift_y, shift_uv, lfm);
-            if (mi_32_row_offset + 2 >= max_rows)
-              continue;
-            mip2 = mip + mode_info_stride * 2;
-            build_masks(lfi_n, mip2[0], shift_y + 16, shift_uv + 4, lfm);
-            break;
-          case BLOCK_16X32:
-            build_masks(lfi_n, mip[0], shift_y, shift_uv, lfm);
-            if (mi_32_col_offset + 2 >= max_cols)
-              continue;
-            mip2 = mip + 2;
-            build_masks(lfi_n, mip2[0], shift_y + 2, shift_uv + 1, lfm);
-            break;
-          default:
-            for (idx_16 = 0; idx_16 < 4; mip += offset_16[idx_16], ++idx_16) {
-              const int shift_y = shift_32_y[idx_32] + shift_16_y[idx_16];
-              const int shift_uv = shift_32_uv[idx_32] + shift_16_uv[idx_16];
-              const int mi_16_col_offset = mi_32_col_offset +
-                  ((idx_16 & 1) << 1);
-              const int mi_16_row_offset = mi_32_row_offset +
-                  ((idx_16 >> 1) << 1);
-
-              if (mi_16_col_offset >= max_cols || mi_16_row_offset >= max_rows)
-                continue;
-
-              switch (mip[0]->sb_type) {
-                case BLOCK_16X16:
-                  build_masks(lfi_n, mip[0], shift_y, shift_uv, lfm);
-                  break;
-                case BLOCK_16X8:
-                  build_masks(lfi_n, mip[0], shift_y, shift_uv, lfm);
-                  if (mi_16_row_offset + 1 >= max_rows)
-                    continue;
-                  mip2 = mip + mode_info_stride;
-                  build_y_mask(lfi_n, mip2[0], shift_y+8, lfm);
-                  break;
-                case BLOCK_8X16:
-                  build_masks(lfi_n, mip[0], shift_y, shift_uv, lfm);
-                  if (mi_16_col_offset +1 >= max_cols)
-                    continue;
-                  mip2 = mip + 1;
-                  build_y_mask(lfi_n, mip2[0], shift_y+1, lfm);
-                  break;
-                default: {
-                  const int shift_y = shift_32_y[idx_32] +
-                                      shift_16_y[idx_16] +
-                                      shift_8_y[0];
-                  build_masks(lfi_n, mip[0], shift_y, shift_uv, lfm);
-                  mip += offset[0];
-                  for (idx_8 = 1; idx_8 < 4; mip += offset[idx_8], ++idx_8) {
-                    const int shift_y = shift_32_y[idx_32] +
-                                        shift_16_y[idx_16] +
-                                        shift_8_y[idx_8];
-                    const int mi_8_col_offset = mi_16_col_offset +
-                        ((idx_8 & 1));
-                    const int mi_8_row_offset = mi_16_row_offset +
-                        ((idx_8 >> 1));
-
-                    if (mi_8_col_offset >= max_cols ||
-                        mi_8_row_offset >= max_rows)
-                      continue;
-                    build_y_mask(lfi_n, mip[0], shift_y, lfm);
-                  }
-                  break;
-                }
-              }
-            }
-            break;
-        }
-      }
-      break;
-  }
-}
-
-static void filter_selectively_vert(uint8_t *s, int pitch,
-                                    unsigned int mask_16x16,
-                                    unsigned int mask_8x8,
-                                    unsigned int mask_4x4,
-                                    unsigned int mask_4x4_int,
-                                    const loop_filter_thresh *lfthr,
-                                    const uint8_t *lfl) {
-  unsigned int mask;
-
-  for (mask = mask_16x16 | mask_8x8 | mask_4x4 | mask_4x4_int;
-       mask; mask >>= 1) {
-    const loop_filter_thresh *lfi = lfthr + *lfl;
-
-    if (mask & 1) {
-      if (mask_16x16 & 1) {
-        vpx_lpf_vertical_16(s, pitch, lfi->mblim, lfi->lim, lfi->hev_thr);
-      } else if (mask_8x8 & 1) {
-        vpx_lpf_vertical_8(s, pitch, lfi->mblim, lfi->lim, lfi->hev_thr);
-      } else if (mask_4x4 & 1) {
-        vpx_lpf_vertical_4(s, pitch, lfi->mblim, lfi->lim, lfi->hev_thr);
-      }
-    }
-    if (mask_4x4_int & 1)
-      vpx_lpf_vertical_4(s + 4, pitch, lfi->mblim, lfi->lim, lfi->hev_thr);
-    s += 8;
-    lfl += 1;
-    mask_16x16 >>= 1;
-    mask_8x8 >>= 1;
-    mask_4x4 >>= 1;
-    mask_4x4_int >>= 1;
-  }
-}
-
-#if CONFIG_VP9_HIGHBITDEPTH
-static void highbd_filter_selectively_vert(uint16_t *s, int pitch,
-                                           unsigned int mask_16x16,
-                                           unsigned int mask_8x8,
-                                           unsigned int mask_4x4,
-                                           unsigned int mask_4x4_int,
-                                           const loop_filter_thresh *lfthr,
-                                           const uint8_t *lfl, int bd) {
-  unsigned int mask;
-
-  for (mask = mask_16x16 | mask_8x8 | mask_4x4 | mask_4x4_int;
-       mask; mask >>= 1) {
-    const loop_filter_thresh *lfi = lfthr + *lfl;
-
-    if (mask & 1) {
-      if (mask_16x16 & 1) {
-        vpx_highbd_lpf_vertical_16(s, pitch, lfi->mblim, lfi->lim,
-                                   lfi->hev_thr, bd);
-      } else if (mask_8x8 & 1) {
-        vpx_highbd_lpf_vertical_8(s, pitch, lfi->mblim, lfi->lim,
-                                  lfi->hev_thr, bd);
-      } else if (mask_4x4 & 1) {
-        vpx_highbd_lpf_vertical_4(s, pitch, lfi->mblim, lfi->lim,
-                                  lfi->hev_thr, bd);
-      }
-    }
-    if (mask_4x4_int & 1)
-      vpx_highbd_lpf_vertical_4(s + 4, pitch, lfi->mblim, lfi->lim,
-                                lfi->hev_thr, bd);
-    s += 8;
-    lfl += 1;
-    mask_16x16 >>= 1;
-    mask_8x8 >>= 1;
-    mask_4x4 >>= 1;
-    mask_4x4_int >>= 1;
-  }
-}
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-
-void vp9_filter_block_plane_non420(VP9_COMMON *cm,
-                                   struct macroblockd_plane *plane,
-                                   MODE_INFO **mi_8x8,
-                                   int mi_row, int mi_col) {
-  const int ss_x = plane->subsampling_x;
-  const int ss_y = plane->subsampling_y;
-  const int row_step = 1 << ss_y;
-  const int col_step = 1 << ss_x;
-  const int row_step_stride = cm->mi_stride * row_step;
-  struct buf_2d *const dst = &plane->dst;
-  uint8_t* const dst0 = dst->buf;
-  unsigned int mask_16x16[MI_BLOCK_SIZE] = {0};
-  unsigned int mask_8x8[MI_BLOCK_SIZE] = {0};
-  unsigned int mask_4x4[MI_BLOCK_SIZE] = {0};
-  unsigned int mask_4x4_int[MI_BLOCK_SIZE] = {0};
-  uint8_t lfl[MI_BLOCK_SIZE * MI_BLOCK_SIZE];
-  int r, c;
-
-  for (r = 0; r < MI_BLOCK_SIZE && mi_row + r < cm->mi_rows; r += row_step) {
-    unsigned int mask_16x16_c = 0;
-    unsigned int mask_8x8_c = 0;
-    unsigned int mask_4x4_c = 0;
-    unsigned int border_mask;
-
-    // Determine the vertical edges that need filtering
-    for (c = 0; c < MI_BLOCK_SIZE && mi_col + c < cm->mi_cols; c += col_step) {
-      const MODE_INFO *mi = mi_8x8[c];
-      const BLOCK_SIZE sb_type = mi[0].sb_type;
-      const int skip_this = mi[0].skip && is_inter_block(mi);
-      // left edge of current unit is block/partition edge -> no skip
-      const int block_edge_left = (num_4x4_blocks_wide_lookup[sb_type] > 1) ?
-          !(c & (num_8x8_blocks_wide_lookup[sb_type] - 1)) : 1;
-      const int skip_this_c = skip_this && !block_edge_left;
-      // top edge of current unit is block/partition edge -> no skip
-      const int block_edge_above = (num_4x4_blocks_high_lookup[sb_type] > 1) ?
-          !(r & (num_8x8_blocks_high_lookup[sb_type] - 1)) : 1;
-      const int skip_this_r = skip_this && !block_edge_above;
-      const TX_SIZE tx_size = get_uv_tx_size(mi, plane);
-      const int skip_border_4x4_c = ss_x && mi_col + c == cm->mi_cols - 1;
-      const int skip_border_4x4_r = ss_y && mi_row + r == cm->mi_rows - 1;
-
-      // Filter level can vary per MI
-      if (!(lfl[(r << 3) + (c >> ss_x)] =
-            get_filter_level(&cm->lf_info, mi)))
-        continue;
-
-      // Build masks based on the transform size of each block
-      if (tx_size == TX_32X32) {
-        if (!skip_this_c && ((c >> ss_x) & 3) == 0) {
-          if (!skip_border_4x4_c)
-            mask_16x16_c |= 1 << (c >> ss_x);
-          else
-            mask_8x8_c |= 1 << (c >> ss_x);
-        }
-        if (!skip_this_r && ((r >> ss_y) & 3) == 0) {
-          if (!skip_border_4x4_r)
-            mask_16x16[r] |= 1 << (c >> ss_x);
-          else
-            mask_8x8[r] |= 1 << (c >> ss_x);
-        }
-      } else if (tx_size == TX_16X16) {
-        if (!skip_this_c && ((c >> ss_x) & 1) == 0) {
-          if (!skip_border_4x4_c)
-            mask_16x16_c |= 1 << (c >> ss_x);
-          else
-            mask_8x8_c |= 1 << (c >> ss_x);
-        }
-        if (!skip_this_r && ((r >> ss_y) & 1) == 0) {
-          if (!skip_border_4x4_r)
-            mask_16x16[r] |= 1 << (c >> ss_x);
-          else
-            mask_8x8[r] |= 1 << (c >> ss_x);
-        }
-      } else {
-        // force 8x8 filtering on 32x32 boundaries
-        if (!skip_this_c) {
-          if (tx_size == TX_8X8 || ((c >> ss_x) & 3) == 0)
-            mask_8x8_c |= 1 << (c >> ss_x);
-          else
-            mask_4x4_c |= 1 << (c >> ss_x);
-        }
-
-        if (!skip_this_r) {
-          if (tx_size == TX_8X8 || ((r >> ss_y) & 3) == 0)
-            mask_8x8[r] |= 1 << (c >> ss_x);
-          else
-            mask_4x4[r] |= 1 << (c >> ss_x);
-        }
-
-        if (!skip_this && tx_size < TX_8X8 && !skip_border_4x4_c)
-          mask_4x4_int[r] |= 1 << (c >> ss_x);
-      }
-    }
-
-    // Disable filtering on the leftmost column
-    border_mask = ~(mi_col == 0);
-#if CONFIG_VP9_HIGHBITDEPTH
-    if (cm->use_highbitdepth) {
-      highbd_filter_selectively_vert(CONVERT_TO_SHORTPTR(dst->buf),
-                                     dst->stride,
-                                     mask_16x16_c & border_mask,
-                                     mask_8x8_c & border_mask,
-                                     mask_4x4_c & border_mask,
-                                     mask_4x4_int[r],
-                                     cm->lf_info.lfthr, &lfl[r << 3],
-                                     (int)cm->bit_depth);
-    } else {
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-      filter_selectively_vert(dst->buf, dst->stride,
-                              mask_16x16_c & border_mask,
-                              mask_8x8_c & border_mask,
-                              mask_4x4_c & border_mask,
-                              mask_4x4_int[r],
-                              cm->lf_info.lfthr, &lfl[r << 3]);
-#if CONFIG_VP9_HIGHBITDEPTH
-    }
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-    dst->buf += 8 * dst->stride;
-    mi_8x8 += row_step_stride;
-  }
-
-  // Now do horizontal pass
-  dst->buf = dst0;
-  for (r = 0; r < MI_BLOCK_SIZE && mi_row + r < cm->mi_rows; r += row_step) {
-    const int skip_border_4x4_r = ss_y && mi_row + r == cm->mi_rows - 1;
-    const unsigned int mask_4x4_int_r = skip_border_4x4_r ? 0 : mask_4x4_int[r];
-
-    unsigned int mask_16x16_r;
-    unsigned int mask_8x8_r;
-    unsigned int mask_4x4_r;
-
-    if (mi_row + r == 0) {
-      mask_16x16_r = 0;
-      mask_8x8_r = 0;
-      mask_4x4_r = 0;
-    } else {
-      mask_16x16_r = mask_16x16[r];
-      mask_8x8_r = mask_8x8[r];
-      mask_4x4_r = mask_4x4[r];
-    }
-#if CONFIG_VP9_HIGHBITDEPTH
-    if (cm->use_highbitdepth) {
-      highbd_filter_selectively_horiz(CONVERT_TO_SHORTPTR(dst->buf),
-                                      dst->stride,
-                                      mask_16x16_r,
-                                      mask_8x8_r,
-                                      mask_4x4_r,
-                                      mask_4x4_int_r,
-                                      cm->lf_info.lfthr, &lfl[r << 3],
-                                      (int)cm->bit_depth);
-    } else {
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-      filter_selectively_horiz(dst->buf, dst->stride,
-                               mask_16x16_r,
-                               mask_8x8_r,
-                               mask_4x4_r,
-                               mask_4x4_int_r,
-                               cm->lf_info.lfthr, &lfl[r << 3]);
-#if CONFIG_VP9_HIGHBITDEPTH
-    }
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-    dst->buf += 8 * dst->stride;
-  }
-}
-
-void vp9_filter_block_plane_ss00(VP9_COMMON *const cm,
-                                 struct macroblockd_plane *const plane,
-                                 int mi_row,
-                                 LOOP_FILTER_MASK *lfm) {
-  struct buf_2d *const dst = &plane->dst;
-  uint8_t *const dst0 = dst->buf;
-  int r;
-  uint64_t mask_16x16 = lfm->left_y[TX_16X16];
-  uint64_t mask_8x8 = lfm->left_y[TX_8X8];
-  uint64_t mask_4x4 = lfm->left_y[TX_4X4];
-  uint64_t mask_4x4_int = lfm->int_4x4_y;
-
-  assert(plane->subsampling_x == 0 && plane->subsampling_y == 0);
-
-  // Vertical pass: do 2 rows at one time
-  for (r = 0; r < MI_BLOCK_SIZE && mi_row + r < cm->mi_rows; r += 2) {
-    // Disable filtering on the leftmost column.
-#if CONFIG_VP9_HIGHBITDEPTH
-    if (cm->use_highbitdepth) {
-      highbd_filter_selectively_vert_row2(plane->subsampling_x,
-                                          CONVERT_TO_SHORTPTR(dst->buf),
-                                          dst->stride,
-                                          (unsigned int)mask_16x16,
-                                          (unsigned int)mask_8x8,
-                                          (unsigned int)mask_4x4,
-                                          (unsigned int)mask_4x4_int,
-                                          cm->lf_info.lfthr,
-                                          &lfm->lfl_y[r << 3],
-                                          (int)cm->bit_depth);
-    } else {
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-      filter_selectively_vert_row2(plane->subsampling_x, dst->buf, dst->stride,
-                                   (unsigned int)mask_16x16,
-                                   (unsigned int)mask_8x8,
-                                   (unsigned int)mask_4x4,
-                                   (unsigned int)mask_4x4_int,
-                                   cm->lf_info.lfthr, &lfm->lfl_y[r << 3]);
-#if CONFIG_VP9_HIGHBITDEPTH
-    }
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-    dst->buf += 16 * dst->stride;
-    mask_16x16 >>= 16;
-    mask_8x8 >>= 16;
-    mask_4x4 >>= 16;
-    mask_4x4_int >>= 16;
-  }
-
-  // Horizontal pass
-  dst->buf = dst0;
-  mask_16x16 = lfm->above_y[TX_16X16];
-  mask_8x8 = lfm->above_y[TX_8X8];
-  mask_4x4 = lfm->above_y[TX_4X4];
-  mask_4x4_int = lfm->int_4x4_y;
-
-  for (r = 0; r < MI_BLOCK_SIZE && mi_row + r < cm->mi_rows; r++) {
-    unsigned int mask_16x16_r;
-    unsigned int mask_8x8_r;
-    unsigned int mask_4x4_r;
-
-    if (mi_row + r == 0) {
-      mask_16x16_r = 0;
-      mask_8x8_r = 0;
-      mask_4x4_r = 0;
-    } else {
-      mask_16x16_r = mask_16x16 & 0xff;
-      mask_8x8_r = mask_8x8 & 0xff;
-      mask_4x4_r = mask_4x4 & 0xff;
-    }
-
-#if CONFIG_VP9_HIGHBITDEPTH
-    if (cm->use_highbitdepth) {
-      highbd_filter_selectively_horiz(CONVERT_TO_SHORTPTR(dst->buf),
-                                      dst->stride, mask_16x16_r, mask_8x8_r,
-                                      mask_4x4_r, mask_4x4_int & 0xff,
-                                      cm->lf_info.lfthr, &lfm->lfl_y[r << 3],
-                                      (int)cm->bit_depth);
-    } else {
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-      filter_selectively_horiz(dst->buf, dst->stride, mask_16x16_r, mask_8x8_r,
-                               mask_4x4_r, mask_4x4_int & 0xff,
-                               cm->lf_info.lfthr, &lfm->lfl_y[r << 3]);
-#if CONFIG_VP9_HIGHBITDEPTH
-    }
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-
-    dst->buf += 8 * dst->stride;
-    mask_16x16 >>= 8;
-    mask_8x8 >>= 8;
-    mask_4x4 >>= 8;
-    mask_4x4_int >>= 8;
-  }
-}
-
-void vp9_filter_block_plane_ss11(VP9_COMMON *const cm,
-                                 struct macroblockd_plane *const plane,
-                                 int mi_row,
-                                 LOOP_FILTER_MASK *lfm) {
-  struct buf_2d *const dst = &plane->dst;
-  uint8_t *const dst0 = dst->buf;
-  int r, c;
-  uint8_t lfl_uv[16];
-
-  uint16_t mask_16x16 = lfm->left_uv[TX_16X16];
-  uint16_t mask_8x8 = lfm->left_uv[TX_8X8];
-  uint16_t mask_4x4 = lfm->left_uv[TX_4X4];
-  uint16_t mask_4x4_int = lfm->int_4x4_uv;
-
-  assert(plane->subsampling_x == 1 && plane->subsampling_y == 1);
-
-  // Vertical pass: do 2 rows at one time
-  for (r = 0; r < MI_BLOCK_SIZE && mi_row + r < cm->mi_rows; r += 4) {
-    for (c = 0; c < (MI_BLOCK_SIZE >> 1); c++) {
-      lfl_uv[(r << 1) + c] = lfm->lfl_y[(r << 3) + (c << 1)];
-      lfl_uv[((r + 2) << 1) + c] = lfm->lfl_y[((r + 2) << 3) + (c << 1)];
-    }
-
-    // Disable filtering on the leftmost column.
-#if CONFIG_VP9_HIGHBITDEPTH
-    if (cm->use_highbitdepth) {
-      highbd_filter_selectively_vert_row2(plane->subsampling_x,
-                                          CONVERT_TO_SHORTPTR(dst->buf),
-                                          dst->stride,
-                                          (unsigned int)mask_16x16,
-                                          (unsigned int)mask_8x8,
-                                          (unsigned int)mask_4x4,
-                                          (unsigned int)mask_4x4_int,
-                                          cm->lf_info.lfthr, &lfl_uv[r << 1],
-                                          (int)cm->bit_depth);
-    } else {
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-      filter_selectively_vert_row2(plane->subsampling_x, dst->buf, dst->stride,
-                                   (unsigned int)mask_16x16,
-                                   (unsigned int)mask_8x8,
-                                   (unsigned int)mask_4x4,
-                                   (unsigned int)mask_4x4_int,
-                                   cm->lf_info.lfthr, &lfl_uv[r << 1]);
-#if CONFIG_VP9_HIGHBITDEPTH
-    }
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-
-    dst->buf += 16 * dst->stride;
-    mask_16x16 >>= 8;
-    mask_8x8 >>= 8;
-    mask_4x4 >>= 8;
-    mask_4x4_int >>= 8;
-  }
-
-  // Horizontal pass
-  dst->buf = dst0;
-  mask_16x16 = lfm->above_uv[TX_16X16];
-  mask_8x8 = lfm->above_uv[TX_8X8];
-  mask_4x4 = lfm->above_uv[TX_4X4];
-  mask_4x4_int = lfm->int_4x4_uv;
-
-  for (r = 0; r < MI_BLOCK_SIZE && mi_row + r < cm->mi_rows; r += 2) {
-    const int skip_border_4x4_r = mi_row + r == cm->mi_rows - 1;
-    const unsigned int mask_4x4_int_r =
-        skip_border_4x4_r ? 0 : (mask_4x4_int & 0xf);
-    unsigned int mask_16x16_r;
-    unsigned int mask_8x8_r;
-    unsigned int mask_4x4_r;
-
-    if (mi_row + r == 0) {
-      mask_16x16_r = 0;
-      mask_8x8_r = 0;
-      mask_4x4_r = 0;
-    } else {
-      mask_16x16_r = mask_16x16 & 0xf;
-      mask_8x8_r = mask_8x8 & 0xf;
-      mask_4x4_r = mask_4x4 & 0xf;
-    }
-
-#if CONFIG_VP9_HIGHBITDEPTH
-    if (cm->use_highbitdepth) {
-      highbd_filter_selectively_horiz(CONVERT_TO_SHORTPTR(dst->buf),
-                                      dst->stride, mask_16x16_r, mask_8x8_r,
-                                      mask_4x4_r, mask_4x4_int_r,
-                                      cm->lf_info.lfthr, &lfl_uv[r << 1],
-                                      (int)cm->bit_depth);
-    } else {
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-      filter_selectively_horiz(dst->buf, dst->stride, mask_16x16_r, mask_8x8_r,
-                               mask_4x4_r, mask_4x4_int_r, cm->lf_info.lfthr,
-                               &lfl_uv[r << 1]);
-#if CONFIG_VP9_HIGHBITDEPTH
-    }
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-
-    dst->buf += 8 * dst->stride;
-    mask_16x16 >>= 4;
-    mask_8x8 >>= 4;
-    mask_4x4 >>= 4;
-    mask_4x4_int >>= 4;
-  }
-}
-
-static void loop_filter_rows(YV12_BUFFER_CONFIG *frame_buffer, VP9_COMMON *cm,
-                             struct macroblockd_plane planes[MAX_MB_PLANE],
-                             int start, int stop, int y_only) {
-  const int num_planes = y_only ? 1 : MAX_MB_PLANE;
-  enum lf_path path;
-  int mi_row, mi_col;
-
-  if (y_only)
-    path = LF_PATH_444;
-  else if (planes[1].subsampling_y == 1 && planes[1].subsampling_x == 1)
-    path = LF_PATH_420;
-  else if (planes[1].subsampling_y == 0 && planes[1].subsampling_x == 0)
-    path = LF_PATH_444;
-  else
-    path = LF_PATH_SLOW;
-
-  for (mi_row = start; mi_row < stop; mi_row += MI_BLOCK_SIZE) {
-    MODE_INFO **mi = cm->mi_grid_visible + mi_row * cm->mi_stride;
-    LOOP_FILTER_MASK *lfm = get_lfm(&cm->lf, mi_row, 0);
-
-    for (mi_col = 0; mi_col < cm->mi_cols; mi_col += MI_BLOCK_SIZE, ++lfm) {
-      int plane;
-
-      vp9_setup_dst_planes(planes, frame_buffer, mi_row, mi_col);
-
-      // TODO(jimbankoski): For 444 only need to do y mask.
-      vp9_adjust_mask(cm, mi_row, mi_col, lfm);
-
-      vp9_filter_block_plane_ss00(cm, &planes[0], mi_row, lfm);
-      for (plane = 1; plane < num_planes; ++plane) {
-        switch (path) {
-          case LF_PATH_420:
-            vp9_filter_block_plane_ss11(cm, &planes[plane], mi_row, lfm);
-            break;
-          case LF_PATH_444:
-            vp9_filter_block_plane_ss00(cm, &planes[plane], mi_row, lfm);
-            break;
-          case LF_PATH_SLOW:
-            vp9_filter_block_plane_non420(cm, &planes[plane], mi + mi_col,
-                                          mi_row, mi_col);
-            break;
-        }
-      }
-    }
-  }
-}
-
-void vp9_loop_filter_frame(YV12_BUFFER_CONFIG *frame,
-                           VP9_COMMON *cm, MACROBLOCKD *xd,
-                           int frame_filter_level,
-                           int y_only, int partial_frame) {
-  int start_mi_row, end_mi_row, mi_rows_to_filter;
-  if (!frame_filter_level) return;
-  start_mi_row = 0;
-  mi_rows_to_filter = cm->mi_rows;
-  if (partial_frame && cm->mi_rows > 8) {
-    start_mi_row = cm->mi_rows >> 1;
-    start_mi_row &= 0xfffffff8;
-    mi_rows_to_filter = VPXMAX(cm->mi_rows / 8, 8);
-  }
-  end_mi_row = start_mi_row + mi_rows_to_filter;
-  loop_filter_rows(frame, cm, xd->plane, start_mi_row, end_mi_row, y_only);
-}
-
-// Used by the encoder to build the loopfilter masks.
-// TODO(slavarnway): Do the encoder the same way the decoder does it and
-//                   build the masks in line as part of the encode process.
-void vp9_build_mask_frame(VP9_COMMON *cm, int frame_filter_level,
-                          int partial_frame) {
-  int start_mi_row, end_mi_row, mi_rows_to_filter;
-  int mi_col, mi_row;
-  if (!frame_filter_level) return;
-  start_mi_row = 0;
-  mi_rows_to_filter = cm->mi_rows;
-  if (partial_frame && cm->mi_rows > 8) {
-    start_mi_row = cm->mi_rows >> 1;
-    start_mi_row &= 0xfffffff8;
-    mi_rows_to_filter = VPXMAX(cm->mi_rows / 8, 8);
-  }
-  end_mi_row = start_mi_row + mi_rows_to_filter;
-
-  vp9_loop_filter_frame_init(cm, frame_filter_level);
-
-  for (mi_row = start_mi_row; mi_row < end_mi_row; mi_row += MI_BLOCK_SIZE) {
-    MODE_INFO **mi = cm->mi_grid_visible + mi_row * cm->mi_stride;
-    for (mi_col = 0; mi_col < cm->mi_cols; mi_col += MI_BLOCK_SIZE) {
-      // vp9_setup_mask() zeros lfm
-      vp9_setup_mask(cm, mi_row, mi_col, mi + mi_col, cm->mi_stride,
-                     get_lfm(&cm->lf, mi_row, mi_col));
-    }
-  }
-}
-
-// 8x8 blocks in a superblock.  A "1" represents the first block in a 16x16
-// or greater area.
-static const uint8_t first_block_in_16x16[8][8] = {
-  {1, 0, 1, 0, 1, 0, 1, 0},
-  {0, 0, 0, 0, 0, 0, 0, 0},
-  {1, 0, 1, 0, 1, 0, 1, 0},
-  {0, 0, 0, 0, 0, 0, 0, 0},
-  {1, 0, 1, 0, 1, 0, 1, 0},
-  {0, 0, 0, 0, 0, 0, 0, 0},
-  {1, 0, 1, 0, 1, 0, 1, 0},
-  {0, 0, 0, 0, 0, 0, 0, 0}
-};
-
-// This function sets up the bit masks for a block represented
-// by mi_row, mi_col in a 64x64 region.
-// TODO(SJL): This function only works for yv12.
-void vp9_build_mask(VP9_COMMON *cm, const MODE_INFO *mi, int mi_row,
-                    int mi_col, int bw, int bh) {
-  const BLOCK_SIZE block_size = mi->sb_type;
-  const TX_SIZE tx_size_y = mi->tx_size;
-  const loop_filter_info_n *const lfi_n = &cm->lf_info;
-  const int filter_level = get_filter_level(lfi_n, mi);
-  const TX_SIZE tx_size_uv = get_uv_tx_size_impl(tx_size_y, block_size, 1, 1);
-  LOOP_FILTER_MASK *const lfm = get_lfm(&cm->lf, mi_row, mi_col);
-  uint64_t *const left_y = &lfm->left_y[tx_size_y];
-  uint64_t *const above_y = &lfm->above_y[tx_size_y];
-  uint64_t *const int_4x4_y = &lfm->int_4x4_y;
-  uint16_t *const left_uv = &lfm->left_uv[tx_size_uv];
-  uint16_t *const above_uv = &lfm->above_uv[tx_size_uv];
-  uint16_t *const int_4x4_uv = &lfm->int_4x4_uv;
-  const int row_in_sb = (mi_row & 7);
-  const int col_in_sb = (mi_col & 7);
-  const int shift_y = col_in_sb + (row_in_sb << 3);
-  const int shift_uv = (col_in_sb >> 1) + ((row_in_sb >> 1) << 2);
-  const int build_uv = first_block_in_16x16[row_in_sb][col_in_sb];
-
-  if (!filter_level) {
-    return;
-  } else {
-    int index = shift_y;
-    int i;
-    for (i = 0; i < bh; i++) {
-      memset(&lfm->lfl_y[index], filter_level, bw);
-      index += 8;
-    }
-  }
-
-  // These set 1 in the current block size for the block size edges.
-  // For instance if the block size is 32x16, we'll set:
-  //    above =   1111
-  //              0000
-  //    and
-  //    left  =   1000
-  //          =   1000
-  // NOTE : In this example the low bit is left most ( 1000 ) is stored as
-  //        1,  not 8...
-  //
-  // U and V set things on a 16 bit scale.
-  //
-  *above_y |= above_prediction_mask[block_size] << shift_y;
-  *left_y |= left_prediction_mask[block_size] << shift_y;
-
-  if (build_uv) {
-    *above_uv |= above_prediction_mask_uv[block_size] << shift_uv;
-    *left_uv |= left_prediction_mask_uv[block_size] << shift_uv;
-  }
-
-  // If the block has no coefficients and is not intra we skip applying
-  // the loop filter on block edges.
-  if (mi->skip && is_inter_block(mi))
-    return;
-
-  // Add a mask for the transform size. The transform size mask is set to
-  // be correct for a 64x64 prediction block size. Mask to match the size of
-  // the block we are working on and then shift it into place.
-  *above_y |= (size_mask[block_size] &
-               above_64x64_txform_mask[tx_size_y]) << shift_y;
-  *left_y |= (size_mask[block_size] &
-              left_64x64_txform_mask[tx_size_y]) << shift_y;
-
-  if (build_uv) {
-    *above_uv |= (size_mask_uv[block_size] &
-                  above_64x64_txform_mask_uv[tx_size_uv]) << shift_uv;
-
-    *left_uv |= (size_mask_uv[block_size] &
-                 left_64x64_txform_mask_uv[tx_size_uv]) << shift_uv;
-  }
-
-  // Try to determine what to do with the internal 4x4 block boundaries.  These
-  // differ from the 4x4 boundaries on the outside edge of an 8x8 in that the
-  // internal ones can be skipped and don't depend on the prediction block size.
-  if (tx_size_y == TX_4X4)
-    *int_4x4_y |= size_mask[block_size] << shift_y;
-
-  if (build_uv && tx_size_uv == TX_4X4)
-    *int_4x4_uv |= (size_mask_uv[block_size] & 0xffff) << shift_uv;
-}
-
-void vp9_loop_filter_data_reset(
-    LFWorkerData *lf_data, YV12_BUFFER_CONFIG *frame_buffer,
-    struct VP9Common *cm, const struct macroblockd_plane planes[MAX_MB_PLANE]) {
-  lf_data->frame_buffer = frame_buffer;
-  lf_data->cm = cm;
-  lf_data->start = 0;
-  lf_data->stop = 0;
-  lf_data->y_only = 0;
-  memcpy(lf_data->planes, planes, sizeof(lf_data->planes));
-}
-
-void vp9_reset_lfm(VP9_COMMON *const cm) {
-  if (cm->lf.filter_level) {
-    memset(cm->lf.lfm, 0,
-           ((cm->mi_rows + (MI_BLOCK_SIZE - 1)) >> 3) * cm->lf.lfm_stride *
-            sizeof(*cm->lf.lfm));
-  }
-}
-
-int vp9_loop_filter_worker(LFWorkerData *const lf_data, void *unused) {
-  (void)unused;
-  loop_filter_rows(lf_data->frame_buffer, lf_data->cm, lf_data->planes,
-                   lf_data->start, lf_data->stop, lf_data->y_only);
-  return 1;
-}
diff --git a/vp9/common/vp9_loopfilter.h b/vp9/common/vp9_loopfilter.h
deleted file mode 100644 (file)
index fca8830..0000000
+++ /dev/null
@@ -1,166 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#ifndef VP9_COMMON_VP9_LOOPFILTER_H_
-#define VP9_COMMON_VP9_LOOPFILTER_H_
-
-#include "vpx_ports/mem.h"
-#include "./vpx_config.h"
-
-#include "vp9/common/vp9_blockd.h"
-#include "vp9/common/vp9_seg_common.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define MAX_LOOP_FILTER 63
-#define MAX_SHARPNESS 7
-
-#define SIMD_WIDTH 16
-
-#define MAX_REF_LF_DELTAS       4
-#define MAX_MODE_LF_DELTAS      2
-
-enum lf_path {
-  LF_PATH_420,
-  LF_PATH_444,
-  LF_PATH_SLOW,
-};
-
-// Need to align this structure so when it is declared and
-// passed it can be loaded into vector registers.
-typedef struct {
-  DECLARE_ALIGNED(SIMD_WIDTH, uint8_t, mblim[SIMD_WIDTH]);
-  DECLARE_ALIGNED(SIMD_WIDTH, uint8_t, lim[SIMD_WIDTH]);
-  DECLARE_ALIGNED(SIMD_WIDTH, uint8_t, hev_thr[SIMD_WIDTH]);
-} loop_filter_thresh;
-
-typedef struct {
-  loop_filter_thresh lfthr[MAX_LOOP_FILTER + 1];
-  uint8_t lvl[MAX_SEGMENTS][MAX_REF_FRAMES][MAX_MODE_LF_DELTAS];
-} loop_filter_info_n;
-
-// This structure holds bit masks for all 8x8 blocks in a 64x64 region.
-// Each 1 bit represents a position in which we want to apply the loop filter.
-// Left_ entries refer to whether we apply a filter on the border to the
-// left of the block.   Above_ entries refer to whether or not to apply a
-// filter on the above border.   Int_ entries refer to whether or not to
-// apply borders on the 4x4 edges within the 8x8 block that each bit
-// represents.
-// Since each transform is accompanied by a potentially different type of
-// loop filter there is a different entry in the array for each transform size.
-typedef struct {
-  uint64_t left_y[TX_SIZES];
-  uint64_t above_y[TX_SIZES];
-  uint64_t int_4x4_y;
-  uint16_t left_uv[TX_SIZES];
-  uint16_t above_uv[TX_SIZES];
-  uint16_t int_4x4_uv;
-  uint8_t lfl_y[64];
-} LOOP_FILTER_MASK;
-
-struct loopfilter {
-  int filter_level;
-  int last_filt_level;
-
-  int sharpness_level;
-  int last_sharpness_level;
-
-  uint8_t mode_ref_delta_enabled;
-  uint8_t mode_ref_delta_update;
-
-  // 0 = Intra, Last, GF, ARF
-  signed char ref_deltas[MAX_REF_LF_DELTAS];
-  signed char last_ref_deltas[MAX_REF_LF_DELTAS];
-
-  // 0 = ZERO_MV, MV
-  signed char mode_deltas[MAX_MODE_LF_DELTAS];
-  signed char last_mode_deltas[MAX_MODE_LF_DELTAS];
-
-  LOOP_FILTER_MASK *lfm;
-  int lfm_stride;
-};
-
-/* assorted loopfilter functions which get used elsewhere */
-struct VP9Common;
-struct macroblockd;
-struct VP9LfSyncData;
-
-// This function sets up the bit masks for the entire 64x64 region represented
-// by mi_row, mi_col.
-void vp9_setup_mask(struct VP9Common *const cm,
-                    const int mi_row, const int mi_col,
-                    MODE_INFO **mi_8x8, const int mode_info_stride,
-                    LOOP_FILTER_MASK *lfm);
-
-void vp9_filter_block_plane_ss00(struct VP9Common *const cm,
-                                 struct macroblockd_plane *const plane,
-                                 int mi_row,
-                                 LOOP_FILTER_MASK *lfm);
-
-void vp9_filter_block_plane_ss11(struct VP9Common *const cm,
-                                 struct macroblockd_plane *const plane,
-                                 int mi_row,
-                                 LOOP_FILTER_MASK *lfm);
-
-void vp9_filter_block_plane_non420(struct VP9Common *cm,
-                                   struct macroblockd_plane *plane,
-                                   MODE_INFO **mi_8x8,
-                                   int mi_row, int mi_col);
-
-void vp9_loop_filter_init(struct VP9Common *cm);
-
-// Update the loop filter for the current frame.
-// This should be called before vp9_loop_filter_frame(), vp9_build_mask_frame()
-// calls this function directly.
-void vp9_loop_filter_frame_init(struct VP9Common *cm, int default_filt_lvl);
-
-void vp9_loop_filter_frame(YV12_BUFFER_CONFIG *frame,
-                           struct VP9Common *cm,
-                           struct macroblockd *mbd,
-                           int filter_level,
-                           int y_only, int partial_frame);
-
-// Get the superblock lfm for a given mi_row, mi_col.
-static INLINE LOOP_FILTER_MASK *get_lfm(const struct loopfilter *lf,
-                                        const int mi_row, const int mi_col) {
-  return &lf->lfm[(mi_col >> 3) + ((mi_row >> 3) * lf->lfm_stride)];
-}
-
-void vp9_build_mask(struct VP9Common *cm, const MODE_INFO *mi, int mi_row,
-                    int mi_col, int bw, int bh);
-void vp9_adjust_mask(struct VP9Common *const cm, const int mi_row,
-                     const int mi_col, LOOP_FILTER_MASK *lfm);
-void vp9_build_mask_frame(struct VP9Common *cm, int frame_filter_level,
-                          int partial_frame);
-void vp9_reset_lfm(struct VP9Common *const cm);
-
-typedef struct LoopFilterWorkerData {
-  YV12_BUFFER_CONFIG *frame_buffer;
-  struct VP9Common *cm;
-  struct macroblockd_plane planes[MAX_MB_PLANE];
-
-  int start;
-  int stop;
-  int y_only;
-} LFWorkerData;
-
-void vp9_loop_filter_data_reset(
-    LFWorkerData *lf_data, YV12_BUFFER_CONFIG *frame_buffer,
-    struct VP9Common *cm, const struct macroblockd_plane planes[MAX_MB_PLANE]);
-
-// Operates on the rows described by 'lf_data'.
-int vp9_loop_filter_worker(LFWorkerData *const lf_data, void *unused);
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP9_COMMON_VP9_LOOPFILTER_H_
diff --git a/vp9/common/vp9_mfqe.c b/vp9/common/vp9_mfqe.c
deleted file mode 100644 (file)
index f526466..0000000
+++ /dev/null
@@ -1,394 +0,0 @@
-/*
- *  Copyright (c) 2014 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.
- */
-
-#include "./vpx_config.h"
-#include "./vp9_rtcd.h"
-#include "./vpx_dsp_rtcd.h"
-#include "./vpx_scale_rtcd.h"
-
-#include "vp9/common/vp9_onyxc_int.h"
-#include "vp9/common/vp9_postproc.h"
-
-// TODO(jackychen): Replace this function with SSE2 code. There is
-// one SSE2 implementation in vp8, so will consider how to share it
-// between vp8 and vp9.
-static void filter_by_weight(const uint8_t *src, int src_stride,
-                             uint8_t *dst, int dst_stride,
-                             int block_size, int src_weight) {
-  const int dst_weight = (1 << MFQE_PRECISION) - src_weight;
-  const int rounding_bit = 1 << (MFQE_PRECISION - 1);
-  int r, c;
-
-  for (r = 0; r < block_size; r++) {
-    for (c = 0; c < block_size; c++) {
-      dst[c] = (src[c] * src_weight + dst[c] * dst_weight + rounding_bit)
-               >> MFQE_PRECISION;
-    }
-    src += src_stride;
-    dst += dst_stride;
-  }
-}
-
-void vp9_filter_by_weight8x8_c(const uint8_t *src, int src_stride,
-                               uint8_t *dst, int dst_stride, int src_weight) {
-  filter_by_weight(src, src_stride, dst, dst_stride, 8, src_weight);
-}
-
-void vp9_filter_by_weight16x16_c(const uint8_t *src, int src_stride,
-                                 uint8_t *dst, int dst_stride,
-                                 int src_weight) {
-  filter_by_weight(src, src_stride, dst, dst_stride, 16, src_weight);
-}
-
-static void filter_by_weight32x32(const uint8_t *src, int src_stride,
-                                  uint8_t *dst, int dst_stride, int weight) {
-  vp9_filter_by_weight16x16(src, src_stride, dst, dst_stride, weight);
-  vp9_filter_by_weight16x16(src + 16, src_stride, dst + 16, dst_stride,
-                            weight);
-  vp9_filter_by_weight16x16(src + src_stride * 16, src_stride,
-                            dst + dst_stride * 16, dst_stride, weight);
-  vp9_filter_by_weight16x16(src + src_stride * 16 + 16, src_stride,
-                            dst + dst_stride * 16 + 16, dst_stride, weight);
-}
-
-static void filter_by_weight64x64(const uint8_t *src, int src_stride,
-                                  uint8_t *dst, int dst_stride, int weight) {
-  filter_by_weight32x32(src, src_stride, dst, dst_stride, weight);
-  filter_by_weight32x32(src + 32, src_stride, dst + 32,
-                        dst_stride, weight);
-  filter_by_weight32x32(src + src_stride * 32, src_stride,
-                        dst + dst_stride * 32, dst_stride, weight);
-  filter_by_weight32x32(src + src_stride * 32 + 32, src_stride,
-                        dst + dst_stride * 32 + 32, dst_stride, weight);
-}
-
-static void apply_ifactor(const uint8_t *y, int y_stride, uint8_t *yd,
-                          int yd_stride, const uint8_t *u, const uint8_t *v,
-                          int uv_stride, uint8_t *ud, uint8_t *vd,
-                          int uvd_stride, BLOCK_SIZE block_size,
-                          int weight) {
-  if (block_size == BLOCK_16X16) {
-    vp9_filter_by_weight16x16(y, y_stride, yd, yd_stride, weight);
-    vp9_filter_by_weight8x8(u, uv_stride, ud, uvd_stride, weight);
-    vp9_filter_by_weight8x8(v, uv_stride, vd, uvd_stride, weight);
-  } else if (block_size == BLOCK_32X32) {
-    filter_by_weight32x32(y, y_stride, yd, yd_stride, weight);
-    vp9_filter_by_weight16x16(u, uv_stride, ud, uvd_stride, weight);
-    vp9_filter_by_weight16x16(v, uv_stride, vd, uvd_stride, weight);
-  } else if (block_size == BLOCK_64X64) {
-    filter_by_weight64x64(y, y_stride, yd, yd_stride, weight);
-    filter_by_weight32x32(u, uv_stride, ud, uvd_stride, weight);
-    filter_by_weight32x32(v, uv_stride, vd, uvd_stride, weight);
-  }
-}
-
-// TODO(jackychen): Determine whether replace it with assembly code.
-static void copy_mem8x8(const uint8_t *src, int src_stride,
-                        uint8_t *dst, int dst_stride) {
-  int r;
-  for (r = 0; r < 8; r++) {
-    memcpy(dst, src, 8);
-    src += src_stride;
-    dst += dst_stride;
-  }
-}
-
-static void copy_mem16x16(const uint8_t *src, int src_stride,
-                          uint8_t *dst, int dst_stride) {
-  int r;
-  for (r = 0; r < 16; r++) {
-    memcpy(dst, src, 16);
-    src += src_stride;
-    dst += dst_stride;
-  }
-}
-
-static void copy_mem32x32(const uint8_t *src, int src_stride,
-                          uint8_t *dst, int dst_stride) {
-  copy_mem16x16(src, src_stride, dst, dst_stride);
-  copy_mem16x16(src + 16, src_stride, dst + 16, dst_stride);
-  copy_mem16x16(src + src_stride * 16, src_stride,
-                dst + dst_stride * 16, dst_stride);
-  copy_mem16x16(src + src_stride * 16 + 16, src_stride,
-                dst + dst_stride * 16 + 16, dst_stride);
-}
-
-static void copy_mem64x64(const uint8_t *src, int src_stride,
-                          uint8_t *dst, int dst_stride) {
-  copy_mem32x32(src, src_stride, dst, dst_stride);
-  copy_mem32x32(src + 32, src_stride, dst + 32, dst_stride);
-  copy_mem32x32(src + src_stride * 32, src_stride,
-                dst + src_stride * 32, dst_stride);
-  copy_mem32x32(src + src_stride * 32 + 32, src_stride,
-                dst + src_stride * 32 + 32, dst_stride);
-}
-
-static void copy_block(const uint8_t *y, const uint8_t *u, const uint8_t *v,
-                       int y_stride, int uv_stride, uint8_t *yd, uint8_t *ud,
-                       uint8_t *vd, int yd_stride, int uvd_stride,
-                       BLOCK_SIZE bs) {
-  if (bs == BLOCK_16X16) {
-    copy_mem16x16(y, y_stride, yd, yd_stride);
-    copy_mem8x8(u, uv_stride, ud, uvd_stride);
-    copy_mem8x8(v, uv_stride, vd, uvd_stride);
-  } else if (bs == BLOCK_32X32) {
-    copy_mem32x32(y, y_stride, yd, yd_stride);
-    copy_mem16x16(u, uv_stride, ud, uvd_stride);
-    copy_mem16x16(v, uv_stride, vd, uvd_stride);
-  } else {
-    copy_mem64x64(y, y_stride, yd, yd_stride);
-    copy_mem32x32(u, uv_stride, ud, uvd_stride);
-    copy_mem32x32(v, uv_stride, vd, uvd_stride);
-  }
-}
-
-static void get_thr(BLOCK_SIZE bs, int qdiff, int *sad_thr, int *vdiff_thr) {
-  const int adj = qdiff >> MFQE_PRECISION;
-  if (bs == BLOCK_16X16) {
-    *sad_thr = 7 + adj;
-  } else if (bs == BLOCK_32X32) {
-    *sad_thr = 6 + adj;
-  } else {  // BLOCK_64X64
-    *sad_thr = 5 + adj;
-  }
-  *vdiff_thr = 125 + qdiff;
-}
-
-static void mfqe_block(BLOCK_SIZE bs, const uint8_t *y, const uint8_t *u,
-                       const uint8_t *v, int y_stride, int uv_stride,
-                       uint8_t *yd, uint8_t *ud, uint8_t *vd, int yd_stride,
-                       int uvd_stride, int qdiff) {
-  int sad, sad_thr, vdiff, vdiff_thr;
-  uint32_t sse;
-
-  get_thr(bs, qdiff, &sad_thr, &vdiff_thr);
-
-  if (bs == BLOCK_16X16) {
-    vdiff = (vpx_variance16x16(y, y_stride, yd, yd_stride, &sse) + 128) >> 8;
-    sad = (vpx_sad16x16(y, y_stride, yd, yd_stride) + 128) >> 8;
-  } else if (bs == BLOCK_32X32) {
-    vdiff = (vpx_variance32x32(y, y_stride, yd, yd_stride, &sse) + 512) >> 10;
-    sad = (vpx_sad32x32(y, y_stride, yd, yd_stride) + 512) >> 10;
-  } else /* if (bs == BLOCK_64X64) */ {
-    vdiff = (vpx_variance64x64(y, y_stride, yd, yd_stride, &sse) + 2048) >> 12;
-    sad = (vpx_sad64x64(y, y_stride, yd, yd_stride) + 2048) >> 12;
-  }
-
-  // vdiff > sad * 3 means vdiff should not be too small, otherwise,
-  // it might be a lighting change in smooth area. When there is a
-  // lighting change in smooth area, it is dangerous to do MFQE.
-  if (sad > 1 && vdiff > sad * 3) {
-    const int weight = 1 << MFQE_PRECISION;
-    int ifactor = weight * sad * vdiff / (sad_thr * vdiff_thr);
-    // When ifactor equals weight, no MFQE is done.
-    if (ifactor > weight) {
-      ifactor = weight;
-    }
-    apply_ifactor(y, y_stride, yd, yd_stride, u, v, uv_stride, ud, vd,
-                  uvd_stride, bs, ifactor);
-  } else {
-    // Copy the block from current frame (i.e., no mfqe is done).
-    copy_block(y, u, v, y_stride, uv_stride, yd, ud, vd,
-               yd_stride, uvd_stride, bs);
-  }
-}
-
-static int mfqe_decision(MODE_INFO *mi, BLOCK_SIZE cur_bs) {
-  // Check the motion in current block(for inter frame),
-  // or check the motion in the correlated block in last frame (for keyframe).
-  const int mv_len_square = mi->mv[0].as_mv.row *
-                            mi->mv[0].as_mv.row +
-                            mi->mv[0].as_mv.col *
-                            mi->mv[0].as_mv.col;
-  const int mv_threshold = 100;
-  return mi->mode >= NEARESTMV &&  // Not an intra block
-         cur_bs >= BLOCK_16X16 &&
-         mv_len_square <= mv_threshold;
-}
-
-// Process each partiton in a super block, recursively.
-static void mfqe_partition(VP9_COMMON *cm, MODE_INFO *mi, BLOCK_SIZE bs,
-                           const uint8_t *y, const uint8_t *u,
-                           const uint8_t *v, int y_stride, int uv_stride,
-                           uint8_t *yd, uint8_t *ud, uint8_t *vd,
-                           int yd_stride, int uvd_stride) {
-  int mi_offset, y_offset, uv_offset;
-  const BLOCK_SIZE cur_bs = mi->sb_type;
-  const int qdiff = cm->base_qindex - cm->postproc_state.last_base_qindex;
-  const int bsl = b_width_log2_lookup[bs];
-  PARTITION_TYPE partition = partition_lookup[bsl][cur_bs];
-  const BLOCK_SIZE subsize = get_subsize(bs, partition);
-
-  if (cur_bs < BLOCK_8X8) {
-    // If there are blocks smaller than 8x8, it must be on the boundary.
-    return;
-  }
-  // No MFQE on blocks smaller than 16x16
-  if (bs == BLOCK_16X16) {
-    partition = PARTITION_NONE;
-  }
-  if (bs == BLOCK_64X64) {
-    mi_offset = 4;
-    y_offset = 32;
-    uv_offset = 16;
-  } else {
-    mi_offset = 2;
-    y_offset = 16;
-    uv_offset = 8;
-  }
-  switch (partition) {
-    BLOCK_SIZE mfqe_bs, bs_tmp;
-    case PARTITION_HORZ:
-      if (bs == BLOCK_64X64) {
-        mfqe_bs = BLOCK_64X32;
-        bs_tmp = BLOCK_32X32;
-      } else {
-        mfqe_bs = BLOCK_32X16;
-        bs_tmp = BLOCK_16X16;
-      }
-      if (mfqe_decision(mi, mfqe_bs)) {
-        // Do mfqe on the first square partition.
-        mfqe_block(bs_tmp, y, u, v, y_stride, uv_stride,
-                   yd, ud, vd, yd_stride, uvd_stride, qdiff);
-        // Do mfqe on the second square partition.
-        mfqe_block(bs_tmp, y + y_offset, u + uv_offset, v + uv_offset,
-                   y_stride, uv_stride, yd + y_offset, ud + uv_offset,
-                   vd + uv_offset, yd_stride, uvd_stride, qdiff);
-      }
-      if (mfqe_decision(mi + mi_offset * cm->mi_stride, mfqe_bs)) {
-        // Do mfqe on the first square partition.
-        mfqe_block(bs_tmp, y + y_offset * y_stride, u + uv_offset * uv_stride,
-                   v + uv_offset * uv_stride, y_stride, uv_stride,
-                   yd + y_offset * yd_stride, ud + uv_offset * uvd_stride,
-                   vd + uv_offset * uvd_stride, yd_stride, uvd_stride, qdiff);
-        // Do mfqe on the second square partition.
-        mfqe_block(bs_tmp, y + y_offset * y_stride + y_offset,
-                   u + uv_offset * uv_stride + uv_offset,
-                   v + uv_offset * uv_stride + uv_offset, y_stride,
-                   uv_stride, yd + y_offset * yd_stride + y_offset,
-                   ud + uv_offset * uvd_stride + uv_offset,
-                   vd + uv_offset * uvd_stride + uv_offset,
-                   yd_stride, uvd_stride, qdiff);
-      }
-      break;
-    case PARTITION_VERT:
-      if (bs == BLOCK_64X64) {
-        mfqe_bs = BLOCK_32X64;
-        bs_tmp = BLOCK_32X32;
-      } else {
-        mfqe_bs = BLOCK_16X32;
-        bs_tmp = BLOCK_16X16;
-      }
-      if (mfqe_decision(mi, mfqe_bs)) {
-        // Do mfqe on the first square partition.
-        mfqe_block(bs_tmp, y, u, v, y_stride, uv_stride,
-                   yd, ud, vd, yd_stride, uvd_stride, qdiff);
-        // Do mfqe on the second square partition.
-        mfqe_block(bs_tmp, y + y_offset * y_stride, u + uv_offset * uv_stride,
-                   v + uv_offset * uv_stride, y_stride, uv_stride,
-                   yd + y_offset * yd_stride, ud + uv_offset * uvd_stride,
-                   vd + uv_offset * uvd_stride, yd_stride, uvd_stride, qdiff);
-      }
-      if (mfqe_decision(mi + mi_offset, mfqe_bs)) {
-        // Do mfqe on the first square partition.
-        mfqe_block(bs_tmp, y + y_offset, u + uv_offset, v + uv_offset,
-                   y_stride, uv_stride, yd + y_offset, ud + uv_offset,
-                   vd + uv_offset, yd_stride, uvd_stride, qdiff);
-        // Do mfqe on the second square partition.
-        mfqe_block(bs_tmp, y + y_offset * y_stride + y_offset,
-                   u + uv_offset * uv_stride + uv_offset,
-                   v + uv_offset * uv_stride + uv_offset, y_stride,
-                   uv_stride, yd + y_offset * yd_stride + y_offset,
-                   ud + uv_offset * uvd_stride + uv_offset,
-                   vd + uv_offset * uvd_stride + uv_offset,
-                   yd_stride, uvd_stride, qdiff);
-      }
-      break;
-    case PARTITION_NONE:
-      if (mfqe_decision(mi, cur_bs)) {
-        // Do mfqe on this partition.
-        mfqe_block(cur_bs, y, u, v, y_stride, uv_stride,
-                   yd, ud, vd, yd_stride, uvd_stride, qdiff);
-      } else {
-        // Copy the block from current frame(i.e., no mfqe is done).
-        copy_block(y, u, v, y_stride, uv_stride, yd, ud, vd,
-                   yd_stride, uvd_stride, bs);
-      }
-      break;
-    case PARTITION_SPLIT:
-      // Recursion on four square partitions, e.g. if bs is 64X64,
-      // then look into four 32X32 blocks in it.
-      mfqe_partition(cm, mi, subsize, y, u, v, y_stride, uv_stride, yd, ud, vd,
-                     yd_stride, uvd_stride);
-      mfqe_partition(cm, mi + mi_offset, subsize, y + y_offset, u + uv_offset,
-                     v + uv_offset, y_stride, uv_stride, yd + y_offset,
-                     ud + uv_offset, vd + uv_offset, yd_stride, uvd_stride);
-      mfqe_partition(cm, mi + mi_offset * cm->mi_stride, subsize,
-                     y + y_offset * y_stride, u + uv_offset * uv_stride,
-                     v + uv_offset * uv_stride, y_stride, uv_stride,
-                     yd + y_offset * yd_stride, ud + uv_offset * uvd_stride,
-                     vd + uv_offset * uvd_stride, yd_stride, uvd_stride);
-      mfqe_partition(cm, mi + mi_offset * cm->mi_stride + mi_offset,
-                     subsize, y + y_offset * y_stride + y_offset,
-                     u + uv_offset * uv_stride + uv_offset,
-                     v + uv_offset * uv_stride + uv_offset, y_stride,
-                     uv_stride, yd + y_offset * yd_stride + y_offset,
-                     ud + uv_offset * uvd_stride + uv_offset,
-                     vd + uv_offset * uvd_stride + uv_offset,
-                     yd_stride, uvd_stride);
-      break;
-    default:
-      assert(0);
-  }
-}
-
-void vp9_mfqe(VP9_COMMON *cm) {
-  int mi_row, mi_col;
-  // Current decoded frame.
-  const YV12_BUFFER_CONFIG *show = cm->frame_to_show;
-  // Last decoded frame and will store the MFQE result.
-  YV12_BUFFER_CONFIG *dest = &cm->post_proc_buffer;
-  // Loop through each super block.
-  for (mi_row = 0; mi_row < cm->mi_rows; mi_row += MI_BLOCK_SIZE) {
-    for (mi_col = 0; mi_col < cm->mi_cols; mi_col += MI_BLOCK_SIZE) {
-      MODE_INFO *mi;
-      MODE_INFO *mi_local = cm->mi + (mi_row * cm->mi_stride + mi_col);
-      // Motion Info in last frame.
-      MODE_INFO *mi_prev = cm->postproc_state.prev_mi +
-                           (mi_row * cm->mi_stride + mi_col);
-      const uint32_t y_stride = show->y_stride;
-      const uint32_t uv_stride = show->uv_stride;
-      const uint32_t yd_stride = dest->y_stride;
-      const uint32_t uvd_stride = dest->uv_stride;
-      const uint32_t row_offset_y = mi_row << 3;
-      const uint32_t row_offset_uv = mi_row << 2;
-      const uint32_t col_offset_y = mi_col << 3;
-      const uint32_t col_offset_uv = mi_col << 2;
-      const uint8_t *y = show->y_buffer + row_offset_y * y_stride +
-                         col_offset_y;
-      const uint8_t *u = show->u_buffer + row_offset_uv * uv_stride +
-                         col_offset_uv;
-      const uint8_t *v = show->v_buffer + row_offset_uv * uv_stride +
-                         col_offset_uv;
-      uint8_t *yd = dest->y_buffer + row_offset_y * yd_stride + col_offset_y;
-      uint8_t *ud = dest->u_buffer + row_offset_uv * uvd_stride +
-                    col_offset_uv;
-      uint8_t *vd = dest->v_buffer + row_offset_uv * uvd_stride +
-                    col_offset_uv;
-      if (frame_is_intra_only(cm)) {
-        mi = mi_prev;
-      } else {
-        mi = mi_local;
-      }
-      mfqe_partition(cm, mi, BLOCK_64X64, y, u, v, y_stride, uv_stride, yd, ud,
-                     vd, yd_stride, uvd_stride);
-    }
-  }
-}
diff --git a/vp9/common/vp9_mfqe.h b/vp9/common/vp9_mfqe.h
deleted file mode 100644 (file)
index dfff8c2..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- *  Copyright (c) 2014 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.
- */
-
-#ifndef VP9_COMMON_VP9_MFQE_H_
-#define VP9_COMMON_VP9_MFQE_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-// Multiframe Quality Enhancement.
-// The aim for MFQE is to replace pixel blocks in the current frame with
-// the correlated pixel blocks (with higher quality) in the last frame.
-// The replacement can only be taken in stationary blocks by checking
-// the motion of the blocks and other conditions such as the SAD of
-// the current block and correlated block, the variance of the block
-// difference, etc.
-void vp9_mfqe(struct VP9Common *cm);
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP9_COMMON_VP9_MFQE_H_
diff --git a/vp9/common/vp9_mv.h b/vp9/common/vp9_mv.h
deleted file mode 100644 (file)
index 5d89da8..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#ifndef VP9_COMMON_VP9_MV_H_
-#define VP9_COMMON_VP9_MV_H_
-
-#include "vpx/vpx_integer.h"
-
-#include "vp9/common/vp9_common.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef struct mv {
-  int16_t row;
-  int16_t col;
-} MV;
-
-typedef union int_mv {
-  uint32_t as_int;
-  MV as_mv;
-} int_mv; /* facilitates faster equality tests and copies */
-
-typedef struct mv32 {
-  int32_t row;
-  int32_t col;
-} MV32;
-
-static INLINE int is_zero_mv(const MV *mv) {
-  return *((const uint32_t *)mv) == 0;
-}
-
-static INLINE int is_equal_mv(const MV *a, const MV *b) {
-  return  *((const uint32_t *)a) == *((const uint32_t *)b);
-}
-
-static INLINE void clamp_mv(MV *mv, int min_col, int max_col,
-                            int min_row, int max_row) {
-  mv->col = clamp(mv->col, min_col, max_col);
-  mv->row = clamp(mv->row, min_row, max_row);
-}
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP9_COMMON_VP9_MV_H_
diff --git a/vp9/common/vp9_mvref_common.c b/vp9/common/vp9_mvref_common.c
deleted file mode 100644 (file)
index 0eb01a5..0000000
+++ /dev/null
@@ -1,201 +0,0 @@
-
-/*
- *  Copyright (c) 2012 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.
- */
-
-#include "vp9/common/vp9_mvref_common.h"
-
-// This function searches the neighborhood of a given MB/SB
-// to try and find candidate reference vectors.
-static void find_mv_refs_idx(const VP9_COMMON *cm, const MACROBLOCKD *xd,
-                             MODE_INFO *mi, MV_REFERENCE_FRAME ref_frame,
-                             int_mv *mv_ref_list,
-                             int block, int mi_row, int mi_col,
-                             uint8_t *mode_context) {
-  const int *ref_sign_bias = cm->ref_frame_sign_bias;
-  int i, refmv_count = 0;
-  const POSITION *const mv_ref_search = mv_ref_blocks[mi->sb_type];
-  int different_ref_found = 0;
-  int context_counter = 0;
-  const MV_REF *const prev_frame_mvs = cm->use_prev_frame_mvs ?
-      cm->prev_frame->mvs + mi_row * cm->mi_cols + mi_col : NULL;
-  const TileInfo *const tile = &xd->tile;
-
-  // Blank the reference vector list
-  memset(mv_ref_list, 0, sizeof(*mv_ref_list) * MAX_MV_REF_CANDIDATES);
-
-  // The nearest 2 blocks are treated differently
-  // if the size < 8x8 we get the mv from the bmi substructure,
-  // and we also need to keep a mode count.
-  for (i = 0; i < 2; ++i) {
-    const POSITION *const mv_ref = &mv_ref_search[i];
-    if (is_inside(tile, mi_col, mi_row, cm->mi_rows, mv_ref)) {
-      const MODE_INFO *const candidate_mi = xd->mi[mv_ref->col + mv_ref->row *
-                                                   xd->mi_stride];
-      // Keep counts for entropy encoding.
-      context_counter += mode_2_counter[candidate_mi->mode];
-      different_ref_found = 1;
-
-      if (candidate_mi->ref_frame[0] == ref_frame)
-        ADD_MV_REF_LIST(get_sub_block_mv(candidate_mi, 0, mv_ref->col, block),
-                        refmv_count, mv_ref_list, Done);
-      else if (candidate_mi->ref_frame[1] == ref_frame)
-        ADD_MV_REF_LIST(get_sub_block_mv(candidate_mi, 1, mv_ref->col, block),
-                        refmv_count, mv_ref_list, Done);
-    }
-  }
-
-  // Check the rest of the neighbors in much the same way
-  // as before except we don't need to keep track of sub blocks or
-  // mode counts.
-  for (; i < MVREF_NEIGHBOURS; ++i) {
-    const POSITION *const mv_ref = &mv_ref_search[i];
-    if (is_inside(tile, mi_col, mi_row, cm->mi_rows, mv_ref)) {
-      const MODE_INFO *const candidate_mi =
-          xd->mi[mv_ref->col + mv_ref->row * xd->mi_stride];
-      different_ref_found = 1;
-
-      if (candidate_mi->ref_frame[0] == ref_frame)
-        ADD_MV_REF_LIST(candidate_mi->mv[0], refmv_count, mv_ref_list, Done);
-      else if (candidate_mi->ref_frame[1] == ref_frame)
-        ADD_MV_REF_LIST(candidate_mi->mv[1], refmv_count, mv_ref_list, Done);
-    }
-  }
-
-  // Check the last frame's mode and mv info.
-  if (cm->use_prev_frame_mvs) {
-    if (prev_frame_mvs->ref_frame[0] == ref_frame) {
-      ADD_MV_REF_LIST(prev_frame_mvs->mv[0], refmv_count, mv_ref_list, Done);
-    } else if (prev_frame_mvs->ref_frame[1] == ref_frame) {
-      ADD_MV_REF_LIST(prev_frame_mvs->mv[1], refmv_count, mv_ref_list, Done);
-    }
-  }
-
-  // Since we couldn't find 2 mvs from the same reference frame
-  // go back through the neighbors and find motion vectors from
-  // different reference frames.
-  if (different_ref_found) {
-    for (i = 0; i < MVREF_NEIGHBOURS; ++i) {
-      const POSITION *mv_ref = &mv_ref_search[i];
-      if (is_inside(tile, mi_col, mi_row, cm->mi_rows, mv_ref)) {
-        const MODE_INFO *const candidate_mi =
-            xd->mi[mv_ref->col + mv_ref->row * xd->mi_stride];
-
-        // If the candidate is INTRA we don't want to consider its mv.
-        IF_DIFF_REF_FRAME_ADD_MV(candidate_mi, ref_frame, ref_sign_bias,
-                                 refmv_count, mv_ref_list, Done);
-      }
-    }
-  }
-
-  // Since we still don't have a candidate we'll try the last frame.
-  if (cm->use_prev_frame_mvs) {
-    if (prev_frame_mvs->ref_frame[0] != ref_frame &&
-        prev_frame_mvs->ref_frame[0] > INTRA_FRAME) {
-      int_mv mv = prev_frame_mvs->mv[0];
-      if (ref_sign_bias[prev_frame_mvs->ref_frame[0]] !=
-          ref_sign_bias[ref_frame]) {
-        mv.as_mv.row *= -1;
-        mv.as_mv.col *= -1;
-      }
-      ADD_MV_REF_LIST(mv, refmv_count, mv_ref_list, Done);
-    }
-
-    if (prev_frame_mvs->ref_frame[1] > INTRA_FRAME &&
-        prev_frame_mvs->ref_frame[1] != ref_frame &&
-        prev_frame_mvs->mv[1].as_int != prev_frame_mvs->mv[0].as_int) {
-      int_mv mv = prev_frame_mvs->mv[1];
-      if (ref_sign_bias[prev_frame_mvs->ref_frame[1]] !=
-          ref_sign_bias[ref_frame]) {
-        mv.as_mv.row *= -1;
-        mv.as_mv.col *= -1;
-      }
-      ADD_MV_REF_LIST(mv, refmv_count, mv_ref_list, Done);
-    }
-  }
-
- Done:
-
-  mode_context[ref_frame] = counter_to_context[context_counter];
-
-  // Clamp vectors
-  for (i = 0; i < MAX_MV_REF_CANDIDATES; ++i)
-    clamp_mv_ref(&mv_ref_list[i].as_mv, xd);
-}
-
-void vp9_find_mv_refs(const VP9_COMMON *cm, const MACROBLOCKD *xd,
-                      MODE_INFO *mi, MV_REFERENCE_FRAME ref_frame,
-                      int_mv *mv_ref_list,
-                      int mi_row, int mi_col,
-                      uint8_t *mode_context) {
-  find_mv_refs_idx(cm, xd, mi, ref_frame, mv_ref_list, -1,
-                   mi_row, mi_col, mode_context);
-}
-
-void vp9_find_best_ref_mvs(MACROBLOCKD *xd, int allow_hp,
-                           int_mv *mvlist, int_mv *nearest_mv,
-                           int_mv *near_mv) {
-  int i;
-  // Make sure all the candidates are properly clamped etc
-  for (i = 0; i < MAX_MV_REF_CANDIDATES; ++i) {
-    lower_mv_precision(&mvlist[i].as_mv, allow_hp);
-    clamp_mv2(&mvlist[i].as_mv, xd);
-  }
-  *nearest_mv = mvlist[0];
-  *near_mv = mvlist[1];
-}
-
-void vp9_append_sub8x8_mvs_for_idx(VP9_COMMON *cm, MACROBLOCKD *xd,
-                                   int block, int ref, int mi_row, int mi_col,
-                                   int_mv *nearest_mv, int_mv *near_mv,
-                                   uint8_t *mode_context) {
-  int_mv mv_list[MAX_MV_REF_CANDIDATES];
-  MODE_INFO *const mi = xd->mi[0];
-  b_mode_info *bmi = mi->bmi;
-  int n;
-
-  assert(MAX_MV_REF_CANDIDATES == 2);
-
-  find_mv_refs_idx(cm, xd, mi, mi->ref_frame[ref], mv_list, block,
-                   mi_row, mi_col, mode_context);
-
-  near_mv->as_int = 0;
-  switch (block) {
-    case 0:
-      nearest_mv->as_int = mv_list[0].as_int;
-      near_mv->as_int = mv_list[1].as_int;
-      break;
-    case 1:
-    case 2:
-      nearest_mv->as_int = bmi[0].as_mv[ref].as_int;
-      for (n = 0; n < MAX_MV_REF_CANDIDATES; ++n)
-        if (nearest_mv->as_int != mv_list[n].as_int) {
-          near_mv->as_int = mv_list[n].as_int;
-          break;
-        }
-      break;
-    case 3: {
-      int_mv candidates[2 + MAX_MV_REF_CANDIDATES];
-      candidates[0] = bmi[1].as_mv[ref];
-      candidates[1] = bmi[0].as_mv[ref];
-      candidates[2] = mv_list[0];
-      candidates[3] = mv_list[1];
-
-      nearest_mv->as_int = bmi[2].as_mv[ref].as_int;
-      for (n = 0; n < 2 + MAX_MV_REF_CANDIDATES; ++n)
-        if (nearest_mv->as_int != candidates[n].as_int) {
-          near_mv->as_int = candidates[n].as_int;
-          break;
-        }
-      break;
-    }
-    default:
-      assert(0 && "Invalid block index.");
-  }
-}
diff --git a/vp9/common/vp9_mvref_common.h b/vp9/common/vp9_mvref_common.h
deleted file mode 100644 (file)
index 4380843..0000000
+++ /dev/null
@@ -1,241 +0,0 @@
-/*
- *  Copyright (c) 2012 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.
- */
-#ifndef VP9_COMMON_VP9_MVREF_COMMON_H_
-#define VP9_COMMON_VP9_MVREF_COMMON_H_
-
-#include "vp9/common/vp9_onyxc_int.h"
-#include "vp9/common/vp9_blockd.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define LEFT_TOP_MARGIN ((VP9_ENC_BORDER_IN_PIXELS - VP9_INTERP_EXTEND) << 3)
-#define RIGHT_BOTTOM_MARGIN ((VP9_ENC_BORDER_IN_PIXELS -\
-                                VP9_INTERP_EXTEND) << 3)
-
-#define MVREF_NEIGHBOURS 8
-
-typedef struct position {
-  int row;
-  int col;
-} POSITION;
-
-typedef enum {
-  BOTH_ZERO = 0,
-  ZERO_PLUS_PREDICTED = 1,
-  BOTH_PREDICTED = 2,
-  NEW_PLUS_NON_INTRA = 3,
-  BOTH_NEW = 4,
-  INTRA_PLUS_NON_INTRA = 5,
-  BOTH_INTRA = 6,
-  INVALID_CASE = 9
-} motion_vector_context;
-
-// This is used to figure out a context for the ref blocks. The code flattens
-// an array that would have 3 possible counts (0, 1 & 2) for 3 choices by
-// adding 9 for each intra block, 3 for each zero mv and 1 for each new
-// motion vector. This single number is then converted into a context
-// with a single lookup ( counter_to_context ).
-static const int mode_2_counter[MB_MODE_COUNT] = {
-  9,  // DC_PRED
-  9,  // V_PRED
-  9,  // H_PRED
-  9,  // D45_PRED
-  9,  // D135_PRED
-  9,  // D117_PRED
-  9,  // D153_PRED
-  9,  // D207_PRED
-  9,  // D63_PRED
-  9,  // TM_PRED
-  0,  // NEARESTMV
-  0,  // NEARMV
-  3,  // ZEROMV
-  1,  // NEWMV
-};
-
-// There are 3^3 different combinations of 3 counts that can be either 0,1 or
-// 2. However the actual count can never be greater than 2 so the highest
-// counter we need is 18. 9 is an invalid counter that's never used.
-static const int counter_to_context[19] = {
-  BOTH_PREDICTED,  // 0
-  NEW_PLUS_NON_INTRA,  // 1
-  BOTH_NEW,  // 2
-  ZERO_PLUS_PREDICTED,  // 3
-  NEW_PLUS_NON_INTRA,  // 4
-  INVALID_CASE,  // 5
-  BOTH_ZERO,  // 6
-  INVALID_CASE,  // 7
-  INVALID_CASE,  // 8
-  INTRA_PLUS_NON_INTRA,  // 9
-  INTRA_PLUS_NON_INTRA,  // 10
-  INVALID_CASE,  // 11
-  INTRA_PLUS_NON_INTRA,  // 12
-  INVALID_CASE,  // 13
-  INVALID_CASE,  // 14
-  INVALID_CASE,  // 15
-  INVALID_CASE,  // 16
-  INVALID_CASE,  // 17
-  BOTH_INTRA  // 18
-};
-
-static const POSITION mv_ref_blocks[BLOCK_SIZES][MVREF_NEIGHBOURS] = {
-  // 4X4
-  {{-1, 0}, {0, -1}, {-1, -1}, {-2, 0}, {0, -2}, {-2, -1}, {-1, -2}, {-2, -2}},
-  // 4X8
-  {{-1, 0}, {0, -1}, {-1, -1}, {-2, 0}, {0, -2}, {-2, -1}, {-1, -2}, {-2, -2}},
-  // 8X4
-  {{-1, 0}, {0, -1}, {-1, -1}, {-2, 0}, {0, -2}, {-2, -1}, {-1, -2}, {-2, -2}},
-  // 8X8
-  {{-1, 0}, {0, -1}, {-1, -1}, {-2, 0}, {0, -2}, {-2, -1}, {-1, -2}, {-2, -2}},
-  // 8X16
-  {{0, -1}, {-1, 0}, {1, -1}, {-1, -1}, {0, -2}, {-2, 0}, {-2, -1}, {-1, -2}},
-  // 16X8
-  {{-1, 0}, {0, -1}, {-1, 1}, {-1, -1}, {-2, 0}, {0, -2}, {-1, -2}, {-2, -1}},
-  // 16X16
-  {{-1, 0}, {0, -1}, {-1, 1}, {1, -1}, {-1, -1}, {-3, 0}, {0, -3}, {-3, -3}},
-  // 16X32
-  {{0, -1}, {-1, 0}, {2, -1}, {-1, -1}, {-1, 1}, {0, -3}, {-3, 0}, {-3, -3}},
-  // 32X16
-  {{-1, 0}, {0, -1}, {-1, 2}, {-1, -1}, {1, -1}, {-3, 0}, {0, -3}, {-3, -3}},
-  // 32X32
-  {{-1, 1}, {1, -1}, {-1, 2}, {2, -1}, {-1, -1}, {-3, 0}, {0, -3}, {-3, -3}},
-  // 32X64
-  {{0, -1}, {-1, 0}, {4, -1}, {-1, 2}, {-1, -1}, {0, -3}, {-3, 0}, {2, -1}},
-  // 64X32
-  {{-1, 0}, {0, -1}, {-1, 4}, {2, -1}, {-1, -1}, {-3, 0}, {0, -3}, {-1, 2}},
-  // 64X64
-  {{-1, 3}, {3, -1}, {-1, 4}, {4, -1}, {-1, -1}, {-1, 0}, {0, -1}, {-1, 6}}
-};
-
-static const int idx_n_column_to_subblock[4][2] = {
-  {1, 2},
-  {1, 3},
-  {3, 2},
-  {3, 3}
-};
-
-// clamp_mv_ref
-#define MV_BORDER (16 << 3)  // Allow 16 pels in 1/8th pel units
-
-static INLINE void clamp_mv_ref(MV *mv, const MACROBLOCKD *xd) {
-  clamp_mv(mv, xd->mb_to_left_edge - MV_BORDER,
-               xd->mb_to_right_edge + MV_BORDER,
-               xd->mb_to_top_edge - MV_BORDER,
-               xd->mb_to_bottom_edge + MV_BORDER);
-}
-
-// This function returns either the appropriate sub block or block's mv
-// on whether the block_size < 8x8 and we have check_sub_blocks set.
-static INLINE int_mv get_sub_block_mv(const MODE_INFO *candidate, int which_mv,
-                                      int search_col, int block_idx) {
-  return block_idx >= 0 && candidate->sb_type < BLOCK_8X8
-          ? candidate->bmi[idx_n_column_to_subblock[block_idx][search_col == 0]]
-              .as_mv[which_mv]
-          : candidate->mv[which_mv];
-}
-
-
-// Performs mv sign inversion if indicated by the reference frame combination.
-static INLINE int_mv scale_mv(const MODE_INFO *mi, int ref,
-                              const MV_REFERENCE_FRAME this_ref_frame,
-                              const int *ref_sign_bias) {
-  int_mv mv = mi->mv[ref];
-  if (ref_sign_bias[mi->ref_frame[ref]] != ref_sign_bias[this_ref_frame]) {
-    mv.as_mv.row *= -1;
-    mv.as_mv.col *= -1;
-  }
-  return mv;
-}
-
-// This macro is used to add a motion vector mv_ref list if it isn't
-// already in the list.  If it's the second motion vector it will also
-// skip all additional processing and jump to Done!
-#define ADD_MV_REF_LIST(mv, refmv_count, mv_ref_list, Done) \
-  do { \
-    if (refmv_count) { \
-      if ((mv).as_int != (mv_ref_list)[0].as_int) { \
-        (mv_ref_list)[(refmv_count)] = (mv); \
-        goto Done; \
-      } \
-    } else { \
-      (mv_ref_list)[(refmv_count)++] = (mv); \
-    } \
-  } while (0)
-
-// If either reference frame is different, not INTRA, and they
-// are different from each other scale and add the mv to our list.
-#define IF_DIFF_REF_FRAME_ADD_MV(mbmi, ref_frame, ref_sign_bias, refmv_count, \
-                                 mv_ref_list, Done) \
-  do { \
-    if (is_inter_block(mbmi)) { \
-      if ((mbmi)->ref_frame[0] != ref_frame) \
-        ADD_MV_REF_LIST(scale_mv((mbmi), 0, ref_frame, ref_sign_bias), \
-                        refmv_count, mv_ref_list, Done); \
-      if (has_second_ref(mbmi) && \
-          (mbmi)->ref_frame[1] != ref_frame && \
-          (mbmi)->mv[1].as_int != (mbmi)->mv[0].as_int) \
-        ADD_MV_REF_LIST(scale_mv((mbmi), 1, ref_frame, ref_sign_bias), \
-                        refmv_count, mv_ref_list, Done); \
-    } \
-  } while (0)
-
-
-// Checks that the given mi_row, mi_col and search point
-// are inside the borders of the tile.
-static INLINE int is_inside(const TileInfo *const tile,
-                            int mi_col, int mi_row, int mi_rows,
-                            const POSITION *mi_pos) {
-  return !(mi_row + mi_pos->row < 0 ||
-           mi_col + mi_pos->col < tile->mi_col_start ||
-           mi_row + mi_pos->row >= mi_rows ||
-           mi_col + mi_pos->col >= tile->mi_col_end);
-}
-
-// TODO(jingning): this mv clamping function should be block size dependent.
-static INLINE void clamp_mv2(MV *mv, const MACROBLOCKD *xd) {
-  clamp_mv(mv, xd->mb_to_left_edge - LEFT_TOP_MARGIN,
-               xd->mb_to_right_edge + RIGHT_BOTTOM_MARGIN,
-               xd->mb_to_top_edge - LEFT_TOP_MARGIN,
-               xd->mb_to_bottom_edge + RIGHT_BOTTOM_MARGIN);
-}
-
-static INLINE void lower_mv_precision(MV *mv, int allow_hp) {
-  const int use_hp = allow_hp && use_mv_hp(mv);
-  if (!use_hp) {
-    if (mv->row & 1)
-      mv->row += (mv->row > 0 ? -1 : 1);
-    if (mv->col & 1)
-      mv->col += (mv->col > 0 ? -1 : 1);
-  }
-}
-
-typedef void (*find_mv_refs_sync)(void *const data, int mi_row);
-void vp9_find_mv_refs(const VP9_COMMON *cm, const MACROBLOCKD *xd,
-                      MODE_INFO *mi, MV_REFERENCE_FRAME ref_frame,
-                      int_mv *mv_ref_list, int mi_row, int mi_col,
-                      uint8_t *mode_context);
-
-// check a list of motion vectors by sad score using a number rows of pixels
-// above and a number cols of pixels in the left to select the one with best
-// score to use as ref motion vector
-void vp9_find_best_ref_mvs(MACROBLOCKD *xd, int allow_hp,
-                           int_mv *mvlist, int_mv *nearest_mv, int_mv *near_mv);
-
-void vp9_append_sub8x8_mvs_for_idx(VP9_COMMON *cm, MACROBLOCKD *xd,
-                                   int block, int ref, int mi_row, int mi_col,
-                                   int_mv *nearest_mv, int_mv *near_mv,
-                                   uint8_t *mode_context);
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP9_COMMON_VP9_MVREF_COMMON_H_
diff --git a/vp9/common/vp9_onyxc_int.h b/vp9/common/vp9_onyxc_int.h
deleted file mode 100644 (file)
index 3fd935e..0000000
+++ /dev/null
@@ -1,446 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#ifndef VP9_COMMON_VP9_ONYXC_INT_H_
-#define VP9_COMMON_VP9_ONYXC_INT_H_
-
-#include "./vpx_config.h"
-#include "vpx/internal/vpx_codec_internal.h"
-#include "vpx_util/vpx_thread.h"
-#include "./vp9_rtcd.h"
-#include "vp9/common/vp9_alloccommon.h"
-#include "vp9/common/vp9_loopfilter.h"
-#include "vp9/common/vp9_entropymv.h"
-#include "vp9/common/vp9_entropy.h"
-#include "vp9/common/vp9_entropymode.h"
-#include "vp9/common/vp9_frame_buffers.h"
-#include "vp9/common/vp9_quant_common.h"
-#include "vp9/common/vp9_tile_common.h"
-
-#if CONFIG_VP9_POSTPROC
-#include "vp9/common/vp9_postproc.h"
-#endif
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define REFS_PER_FRAME 3
-
-#define REF_FRAMES_LOG2 3
-#define REF_FRAMES (1 << REF_FRAMES_LOG2)
-
-// 4 scratch frames for the new frames to support a maximum of 4 cores decoding
-// in parallel, 3 for scaled references on the encoder.
-// TODO(hkuang): Add ondemand frame buffers instead of hardcoding the number
-// of framebuffers.
-// TODO(jkoleszar): These 3 extra references could probably come from the
-// normal reference pool.
-#define FRAME_BUFFERS (REF_FRAMES + 7)
-
-#define FRAME_CONTEXTS_LOG2 2
-#define FRAME_CONTEXTS (1 << FRAME_CONTEXTS_LOG2)
-
-#define NUM_PING_PONG_BUFFERS 2
-
-extern const struct {
-  PARTITION_CONTEXT above;
-  PARTITION_CONTEXT left;
-} partition_context_lookup[BLOCK_SIZES];
-
-
-typedef enum {
-  SINGLE_REFERENCE      = 0,
-  COMPOUND_REFERENCE    = 1,
-  REFERENCE_MODE_SELECT = 2,
-  REFERENCE_MODES       = 3,
-} REFERENCE_MODE;
-
-typedef struct {
-  int_mv mv[2];
-  MV_REFERENCE_FRAME ref_frame[2];
-} MV_REF;
-
-typedef struct {
-  int ref_count;
-  MV_REF *mvs;
-  int mi_rows;
-  int mi_cols;
-  vpx_codec_frame_buffer_t raw_frame_buffer;
-  YV12_BUFFER_CONFIG buf;
-
-  // The Following variables will only be used in frame parallel decode.
-
-  // frame_worker_owner indicates which FrameWorker owns this buffer. NULL means
-  // that no FrameWorker owns, or is decoding, this buffer.
-  VPxWorker *frame_worker_owner;
-
-  // row and col indicate which position frame has been decoded to in real
-  // pixel unit. They are reset to -1 when decoding begins and set to INT_MAX
-  // when the frame is fully decoded.
-  int row;
-  int col;
-} RefCntBuffer;
-
-typedef struct BufferPool {
-  // Protect BufferPool from being accessed by several FrameWorkers at
-  // the same time during frame parallel decode.
-  // TODO(hkuang): Try to use atomic variable instead of locking the whole pool.
-#if CONFIG_MULTITHREAD
-  pthread_mutex_t pool_mutex;
-#endif
-
-  // Private data associated with the frame buffer callbacks.
-  void *cb_priv;
-
-  vpx_get_frame_buffer_cb_fn_t get_fb_cb;
-  vpx_release_frame_buffer_cb_fn_t release_fb_cb;
-
-  RefCntBuffer frame_bufs[FRAME_BUFFERS];
-
-  // Frame buffers allocated internally by the codec.
-  InternalFrameBufferList int_frame_buffers;
-} BufferPool;
-
-typedef struct VP9Common {
-  struct vpx_internal_error_info  error;
-  vpx_color_space_t color_space;
-  vpx_color_range_t color_range;
-  int width;
-  int height;
-  int render_width;
-  int render_height;
-  int last_width;
-  int last_height;
-
-  // TODO(jkoleszar): this implies chroma ss right now, but could vary per
-  // plane. Revisit as part of the future change to YV12_BUFFER_CONFIG to
-  // support additional planes.
-  int subsampling_x;
-  int subsampling_y;
-
-#if CONFIG_VP9_HIGHBITDEPTH
-  int use_highbitdepth;  // Marks if we need to use 16bit frame buffers.
-#endif
-
-  YV12_BUFFER_CONFIG *frame_to_show;
-  RefCntBuffer *prev_frame;
-
-  // TODO(hkuang): Combine this with cur_buf in macroblockd.
-  RefCntBuffer *cur_frame;
-
-  int ref_frame_map[REF_FRAMES]; /* maps fb_idx to reference slot */
-
-  // Prepare ref_frame_map for the next frame.
-  // Only used in frame parallel decode.
-  int next_ref_frame_map[REF_FRAMES];
-
-  // TODO(jkoleszar): could expand active_ref_idx to 4, with 0 as intra, and
-  // roll new_fb_idx into it.
-
-  // Each frame can reference REFS_PER_FRAME buffers
-  RefBuffer frame_refs[REFS_PER_FRAME];
-
-  int new_fb_idx;
-
-#if CONFIG_VP9_POSTPROC
-  YV12_BUFFER_CONFIG post_proc_buffer;
-  YV12_BUFFER_CONFIG post_proc_buffer_int;
-#endif
-
-  FRAME_TYPE last_frame_type;  /* last frame's frame type for motion search.*/
-  FRAME_TYPE frame_type;
-
-  int show_frame;
-  int last_show_frame;
-  int show_existing_frame;
-
-  // Flag signaling that the frame is encoded using only INTRA modes.
-  uint8_t intra_only;
-  uint8_t last_intra_only;
-
-  int allow_high_precision_mv;
-
-  // Flag signaling that the frame context should be reset to default values.
-  // 0 or 1 implies don't reset, 2 reset just the context specified in the
-  // frame header, 3 reset all contexts.
-  int reset_frame_context;
-
-  // MBs, mb_rows/cols is in 16-pixel units; mi_rows/cols is in
-  // MODE_INFO (8-pixel) units.
-  int MBs;
-  int mb_rows, mi_rows;
-  int mb_cols, mi_cols;
-  int mi_stride;
-
-  /* profile settings */
-  TX_MODE tx_mode;
-
-  int base_qindex;
-  int y_dc_delta_q;
-  int uv_dc_delta_q;
-  int uv_ac_delta_q;
-  int16_t y_dequant[MAX_SEGMENTS][2];
-  int16_t uv_dequant[MAX_SEGMENTS][2];
-
-  /* We allocate a MODE_INFO struct for each macroblock, together with
-     an extra row on top and column on the left to simplify prediction. */
-  int mi_alloc_size;
-  MODE_INFO *mip; /* Base of allocated array */
-  MODE_INFO *mi;  /* Corresponds to upper left visible macroblock */
-
-  // TODO(agrange): Move prev_mi into encoder structure.
-  // prev_mip and prev_mi will only be allocated in VP9 encoder.
-  MODE_INFO *prev_mip; /* MODE_INFO array 'mip' from last decoded frame */
-  MODE_INFO *prev_mi;  /* 'mi' from last frame (points into prev_mip) */
-
-  // Separate mi functions between encoder and decoder.
-  int (*alloc_mi)(struct VP9Common *cm, int mi_size);
-  void (*free_mi)(struct VP9Common *cm);
-  void (*setup_mi)(struct VP9Common *cm);
-
-  // Grid of pointers to 8x8 MODE_INFO structs.  Any 8x8 not in the visible
-  // area will be NULL.
-  MODE_INFO **mi_grid_base;
-  MODE_INFO **mi_grid_visible;
-  MODE_INFO **prev_mi_grid_base;
-  MODE_INFO **prev_mi_grid_visible;
-
-  // Whether to use previous frame's motion vectors for prediction.
-  int use_prev_frame_mvs;
-
-  // Persistent mb segment id map used in prediction.
-  int seg_map_idx;
-  int prev_seg_map_idx;
-
-  uint8_t *seg_map_array[NUM_PING_PONG_BUFFERS];
-  uint8_t *last_frame_seg_map;
-  uint8_t *current_frame_seg_map;
-  int seg_map_alloc_size;
-
-  INTERP_FILTER interp_filter;
-
-  loop_filter_info_n lf_info;
-
-  int refresh_frame_context;    /* Two state 0 = NO, 1 = YES */
-
-  int ref_frame_sign_bias[MAX_REF_FRAMES];    /* Two state 0, 1 */
-
-  struct loopfilter lf;
-  struct segmentation seg;
-
-  // TODO(hkuang): Remove this as it is the same as frame_parallel_decode
-  // in pbi.
-  int frame_parallel_decode;  // frame-based threading.
-
-  // Context probabilities for reference frame prediction
-  MV_REFERENCE_FRAME comp_fixed_ref;
-  MV_REFERENCE_FRAME comp_var_ref[2];
-  REFERENCE_MODE reference_mode;
-
-  FRAME_CONTEXT *fc;  /* this frame entropy */
-  FRAME_CONTEXT *frame_contexts;   // FRAME_CONTEXTS
-  unsigned int  frame_context_idx; /* Context to use/update */
-  FRAME_COUNTS counts;
-
-  unsigned int current_video_frame;
-  BITSTREAM_PROFILE profile;
-
-  // VPX_BITS_8 in profile 0 or 1, VPX_BITS_10 or VPX_BITS_12 in profile 2 or 3.
-  vpx_bit_depth_t bit_depth;
-  vpx_bit_depth_t dequant_bit_depth;  // bit_depth of current dequantizer
-
-#if CONFIG_VP9_POSTPROC
-  struct postproc_state  postproc_state;
-#endif
-
-  int error_resilient_mode;
-  int frame_parallel_decoding_mode;
-
-  int log2_tile_cols, log2_tile_rows;
-  int byte_alignment;
-  int skip_loop_filter;
-
-  // Private data associated with the frame buffer callbacks.
-  void *cb_priv;
-  vpx_get_frame_buffer_cb_fn_t get_fb_cb;
-  vpx_release_frame_buffer_cb_fn_t release_fb_cb;
-
-  // Handles memory for the codec.
-  InternalFrameBufferList int_frame_buffers;
-
-  // External BufferPool passed from outside.
-  BufferPool *buffer_pool;
-
-  PARTITION_CONTEXT *above_seg_context;
-  ENTROPY_CONTEXT *above_context;
-  int above_context_alloc_cols;
-} VP9_COMMON;
-
-// TODO(hkuang): Don't need to lock the whole pool after implementing atomic
-// frame reference count.
-void lock_buffer_pool(BufferPool *const pool);
-void unlock_buffer_pool(BufferPool *const pool);
-
-static INLINE YV12_BUFFER_CONFIG *get_ref_frame(VP9_COMMON *cm, int index) {
-  if (index < 0 || index >= REF_FRAMES)
-    return NULL;
-  if (cm->ref_frame_map[index] < 0)
-    return NULL;
-  assert(cm->ref_frame_map[index] < FRAME_BUFFERS);
-  return &cm->buffer_pool->frame_bufs[cm->ref_frame_map[index]].buf;
-}
-
-static INLINE YV12_BUFFER_CONFIG *get_frame_new_buffer(VP9_COMMON *cm) {
-  return &cm->buffer_pool->frame_bufs[cm->new_fb_idx].buf;
-}
-
-static INLINE int get_free_fb(VP9_COMMON *cm) {
-  RefCntBuffer *const frame_bufs = cm->buffer_pool->frame_bufs;
-  int i;
-
-  lock_buffer_pool(cm->buffer_pool);
-  for (i = 0; i < FRAME_BUFFERS; ++i)
-    if (frame_bufs[i].ref_count == 0)
-      break;
-
-  if (i != FRAME_BUFFERS) {
-    frame_bufs[i].ref_count = 1;
-  } else {
-    // Reset i to be INVALID_IDX to indicate no free buffer found.
-    i = INVALID_IDX;
-  }
-
-  unlock_buffer_pool(cm->buffer_pool);
-  return i;
-}
-
-static INLINE void ref_cnt_fb(RefCntBuffer *bufs, int *idx, int new_idx) {
-  const int ref_index = *idx;
-
-  if (ref_index >= 0 && bufs[ref_index].ref_count > 0)
-    bufs[ref_index].ref_count--;
-
-  *idx = new_idx;
-
-  bufs[new_idx].ref_count++;
-}
-
-static INLINE int mi_cols_aligned_to_sb(int n_mis) {
-  return ALIGN_POWER_OF_TWO(n_mis, MI_BLOCK_SIZE_LOG2);
-}
-
-static INLINE int frame_is_intra_only(const VP9_COMMON *const cm) {
-  return cm->frame_type == KEY_FRAME || cm->intra_only;
-}
-
-static INLINE void set_partition_probs(const VP9_COMMON *const cm,
-                                       MACROBLOCKD *const xd) {
-  xd->partition_probs =
-      frame_is_intra_only(cm) ?
-          &vp9_kf_partition_probs[0] :
-          (const vpx_prob (*)[PARTITION_TYPES - 1])cm->fc->partition_prob;
-}
-
-static INLINE void vp9_init_macroblockd(VP9_COMMON *cm, MACROBLOCKD *xd,
-                                        tran_low_t *dqcoeff) {
-  int i;
-
-  for (i = 0; i < MAX_MB_PLANE; ++i) {
-    xd->plane[i].dqcoeff = dqcoeff;
-    xd->above_context[i] = cm->above_context +
-        i * sizeof(*cm->above_context) * 2 * mi_cols_aligned_to_sb(cm->mi_cols);
-
-    if (get_plane_type(i) == PLANE_TYPE_Y) {
-      memcpy(xd->plane[i].seg_dequant, cm->y_dequant, sizeof(cm->y_dequant));
-    } else {
-      memcpy(xd->plane[i].seg_dequant, cm->uv_dequant, sizeof(cm->uv_dequant));
-    }
-    xd->fc = cm->fc;
-  }
-
-  xd->above_seg_context = cm->above_seg_context;
-  xd->mi_stride = cm->mi_stride;
-  xd->error_info = &cm->error;
-
-  set_partition_probs(cm, xd);
-}
-
-static INLINE const vpx_prob* get_partition_probs(const MACROBLOCKD *xd,
-                                                  int ctx) {
-  return xd->partition_probs[ctx];
-}
-
-static INLINE void set_skip_context(MACROBLOCKD *xd, int mi_row, int mi_col) {
-  const int above_idx = mi_col * 2;
-  const int left_idx = (mi_row * 2) & 15;
-  int i;
-  for (i = 0; i < MAX_MB_PLANE; ++i) {
-    struct macroblockd_plane *const pd = &xd->plane[i];
-    pd->above_context = &xd->above_context[i][above_idx >> pd->subsampling_x];
-    pd->left_context = &xd->left_context[i][left_idx >> pd->subsampling_y];
-  }
-}
-
-static INLINE int calc_mi_size(int len) {
-  // len is in mi units.
-  return len + MI_BLOCK_SIZE;
-}
-
-static INLINE void set_mi_row_col(MACROBLOCKD *xd, const TileInfo *const tile,
-                                  int mi_row, int bh,
-                                  int mi_col, int bw,
-                                  int mi_rows, int mi_cols) {
-  xd->mb_to_top_edge    = -((mi_row * MI_SIZE) * 8);
-  xd->mb_to_bottom_edge = ((mi_rows - bh - mi_row) * MI_SIZE) * 8;
-  xd->mb_to_left_edge   = -((mi_col * MI_SIZE) * 8);
-  xd->mb_to_right_edge  = ((mi_cols - bw - mi_col) * MI_SIZE) * 8;
-
-  // Are edges available for intra prediction?
-  xd->above_mi = (mi_row != 0) ? xd->mi[-xd->mi_stride] : NULL;
-  xd->left_mi  = (mi_col > tile->mi_col_start) ? xd->mi[-1] : NULL;
-}
-
-static INLINE void update_partition_context(MACROBLOCKD *xd,
-                                            int mi_row, int mi_col,
-                                            BLOCK_SIZE subsize,
-                                            BLOCK_SIZE bsize) {
-  PARTITION_CONTEXT *const above_ctx = xd->above_seg_context + mi_col;
-  PARTITION_CONTEXT *const left_ctx = xd->left_seg_context + (mi_row & MI_MASK);
-
-  // num_4x4_blocks_wide_lookup[bsize] / 2
-  const int bs = num_8x8_blocks_wide_lookup[bsize];
-
-  // update the partition context at the end notes. set partition bits
-  // of block sizes larger than the current one to be one, and partition
-  // bits of smaller block sizes to be zero.
-  memset(above_ctx, partition_context_lookup[subsize].above, bs);
-  memset(left_ctx, partition_context_lookup[subsize].left, bs);
-}
-
-static INLINE int partition_plane_context(const MACROBLOCKD *xd,
-                                          int mi_row, int mi_col,
-                                          BLOCK_SIZE bsize) {
-  const PARTITION_CONTEXT *above_ctx = xd->above_seg_context + mi_col;
-  const PARTITION_CONTEXT *left_ctx = xd->left_seg_context + (mi_row & MI_MASK);
-  const int bsl = mi_width_log2_lookup[bsize];
-  int above = (*above_ctx >> bsl) & 1 , left = (*left_ctx >> bsl) & 1;
-
-  assert(b_width_log2_lookup[bsize] == b_height_log2_lookup[bsize]);
-  assert(bsl >= 0);
-
-  return (left * 2 + above) + bsl * PARTITION_PLOFFSET;
-}
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP9_COMMON_VP9_ONYXC_INT_H_
diff --git a/vp9/common/vp9_postproc.c b/vp9/common/vp9_postproc.c
deleted file mode 100644 (file)
index 4651f67..0000000
+++ /dev/null
@@ -1,450 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#include <math.h>
-#include <stdlib.h>
-#include <stdio.h>
-
-#include "./vpx_dsp_rtcd.h"
-#include "./vpx_config.h"
-#include "./vpx_scale_rtcd.h"
-#include "./vp9_rtcd.h"
-
-#include "vpx_dsp/vpx_dsp_common.h"
-#include "vpx_dsp/postproc.h"
-#include "vpx_ports/mem.h"
-#include "vpx_ports/system_state.h"
-#include "vpx_scale/vpx_scale.h"
-#include "vpx_scale/yv12config.h"
-
-#include "vp9/common/vp9_onyxc_int.h"
-#include "vp9/common/vp9_postproc.h"
-#include "vp9/common/vp9_textblit.h"
-
-#if CONFIG_VP9_POSTPROC
-static const int16_t kernel5[] = {
-  1, 1, 4, 1, 1
-};
-
-static const uint8_t q_diff_thresh = 20;
-static const uint8_t last_q_thresh = 170;
-extern const int16_t vpx_rv[];
-
-#if CONFIG_VP9_HIGHBITDEPTH
-void vp9_highbd_post_proc_down_and_across_c(const uint16_t *src_ptr,
-                                            uint16_t *dst_ptr,
-                                            int src_pixels_per_line,
-                                            int dst_pixels_per_line,
-                                            int rows,
-                                            int cols,
-                                            int flimit) {
-  uint16_t const *p_src;
-  uint16_t *p_dst;
-  int row, col, i, v, kernel;
-  int pitch = src_pixels_per_line;
-  uint16_t d[8];
-
-  for (row = 0; row < rows; row++) {
-    // post_proc_down for one row.
-    p_src = src_ptr;
-    p_dst = dst_ptr;
-
-    for (col = 0; col < cols; col++) {
-      kernel = 4;
-      v = p_src[col];
-
-      for (i = -2; i <= 2; i++) {
-        if (abs(v - p_src[col + i * pitch]) > flimit)
-          goto down_skip_convolve;
-
-        kernel += kernel5[2 + i] * p_src[col + i * pitch];
-      }
-
-      v = (kernel >> 3);
-
-    down_skip_convolve:
-      p_dst[col] = v;
-    }
-
-    /* now post_proc_across */
-    p_src = dst_ptr;
-    p_dst = dst_ptr;
-
-    for (i = 0; i < 8; i++)
-      d[i] = p_src[i];
-
-    for (col = 0; col < cols; col++) {
-      kernel = 4;
-      v = p_src[col];
-
-      d[col & 7] = v;
-
-      for (i = -2; i <= 2; i++) {
-        if (abs(v - p_src[col + i]) > flimit)
-          goto across_skip_convolve;
-
-        kernel += kernel5[2 + i] * p_src[col + i];
-      }
-
-      d[col & 7] = (kernel >> 3);
-
-    across_skip_convolve:
-      if (col >= 2)
-        p_dst[col - 2] = d[(col - 2) & 7];
-    }
-
-    /* handle the last two pixels */
-    p_dst[col - 2] = d[(col - 2) & 7];
-    p_dst[col - 1] = d[(col - 1) & 7];
-
-
-    /* next row */
-    src_ptr += pitch;
-    dst_ptr += dst_pixels_per_line;
-  }
-}
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-
-static int q2mbl(int x) {
-  if (x < 20) x = 20;
-
-  x = 50 + (x - 50) * 10 / 8;
-  return x * x / 3;
-}
-
-#if CONFIG_VP9_HIGHBITDEPTH
-void vp9_highbd_mbpost_proc_across_ip_c(uint16_t *src, int pitch,
-                                        int rows, int cols, int flimit) {
-  int r, c, i;
-
-  uint16_t *s = src;
-  uint16_t d[16];
-
-
-  for (r = 0; r < rows; r++) {
-    int sumsq = 0;
-    int sum   = 0;
-
-    for (i = -8; i <= 6; i++) {
-      sumsq += s[i] * s[i];
-      sum   += s[i];
-      d[i + 8] = 0;
-    }
-
-    for (c = 0; c < cols + 8; c++) {
-      int x = s[c + 7] - s[c - 8];
-      int y = s[c + 7] + s[c - 8];
-
-      sum  += x;
-      sumsq += x * y;
-
-      d[c & 15] = s[c];
-
-      if (sumsq * 15 - sum * sum < flimit) {
-        d[c & 15] = (8 + sum + s[c]) >> 4;
-      }
-
-      s[c - 8] = d[(c - 8) & 15];
-    }
-
-    s += pitch;
-  }
-}
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-
-
-#if CONFIG_VP9_HIGHBITDEPTH
-void vp9_highbd_mbpost_proc_down_c(uint16_t *dst, int pitch,
-                                   int rows, int cols, int flimit) {
-  int r, c, i;
-  const int16_t *rv3 = &vpx_rv[63 & rand()];  // NOLINT
-
-  for (c = 0; c < cols; c++) {
-    uint16_t *s = &dst[c];
-    int sumsq = 0;
-    int sum = 0;
-    uint16_t d[16];
-    const int16_t *rv2 = rv3 + ((c * 17) & 127);
-
-    for (i = -8; i <= 6; i++) {
-      sumsq += s[i * pitch] * s[i * pitch];
-      sum += s[i * pitch];
-    }
-
-    for (r = 0; r < rows + 8; r++) {
-      sumsq += s[7 * pitch] * s[ 7 * pitch] - s[-8 * pitch] * s[-8 * pitch];
-      sum += s[7 * pitch] - s[-8 * pitch];
-      d[r & 15] = s[0];
-
-      if (sumsq * 15 - sum * sum < flimit) {
-        d[r & 15] = (rv2[r & 127] + sum + s[0]) >> 4;
-      }
-
-      s[-8 * pitch] = d[(r - 8) & 15];
-      s += pitch;
-    }
-  }
-}
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-
-static void deblock_and_de_macro_block(YV12_BUFFER_CONFIG   *source,
-                                       YV12_BUFFER_CONFIG   *post,
-                                       int                   q,
-                                       int                   low_var_thresh,
-                                       int                   flag,
-                                       uint8_t              *limits) {
-  (void) low_var_thresh;
-  (void) flag;
-#if CONFIG_VP9_HIGHBITDEPTH
-  if (source->flags & YV12_FLAG_HIGHBITDEPTH) {
-    double level = 6.0e-05 * q * q * q - .0067 * q * q + .306 * q + .0065;
-    int ppl = (int)(level + .5);
-    vp9_highbd_post_proc_down_and_across(CONVERT_TO_SHORTPTR(source->y_buffer),
-                                         CONVERT_TO_SHORTPTR(post->y_buffer),
-                                         source->y_stride, post->y_stride,
-                                         source->y_height, source->y_width,
-                                         ppl);
-
-    vp9_highbd_mbpost_proc_across_ip(CONVERT_TO_SHORTPTR(post->y_buffer),
-                                     post->y_stride, post->y_height,
-                                     post->y_width, q2mbl(q));
-
-    vp9_highbd_mbpost_proc_down(CONVERT_TO_SHORTPTR(post->y_buffer),
-                                post->y_stride, post->y_height,
-                                post->y_width, q2mbl(q));
-
-    vp9_highbd_post_proc_down_and_across(CONVERT_TO_SHORTPTR(source->u_buffer),
-                                         CONVERT_TO_SHORTPTR(post->u_buffer),
-                                         source->uv_stride, post->uv_stride,
-                                         source->uv_height, source->uv_width,
-                                         ppl);
-    vp9_highbd_post_proc_down_and_across(CONVERT_TO_SHORTPTR(source->v_buffer),
-                                         CONVERT_TO_SHORTPTR(post->v_buffer),
-                                         source->uv_stride, post->uv_stride,
-                                         source->uv_height, source->uv_width,
-                                         ppl);
-  } else {
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-    vp9_deblock(source, post, q, limits);
-    vpx_mbpost_proc_across_ip(post->y_buffer, post->y_stride, post->y_height,
-                              post->y_width, q2mbl(q));
-    vpx_mbpost_proc_down(post->y_buffer, post->y_stride, post->y_height,
-                         post->y_width, q2mbl(q));
-#if CONFIG_VP9_HIGHBITDEPTH
-  }
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-}
-
-void vp9_deblock(const YV12_BUFFER_CONFIG *src, YV12_BUFFER_CONFIG *dst,
-                 int q, uint8_t *limits) {
-  const int ppl = (int)(6.0e-05 * q * q * q - 0.0067 * q * q + 0.306 * q
-                        + 0.0065 + 0.5);
-#if CONFIG_VP9_HIGHBITDEPTH
-  if (src->flags & YV12_FLAG_HIGHBITDEPTH) {
-    int i;
-    const uint8_t * const srcs[3] =
-        {src->y_buffer, src->u_buffer, src->v_buffer};
-    const int src_strides[3] = {src->y_stride, src->uv_stride, src->uv_stride};
-    const int src_widths[3] = {src->y_width, src->uv_width, src->uv_width};
-    const int src_heights[3] = {src->y_height, src->uv_height, src->uv_height};
-
-    uint8_t * const dsts[3] = {dst->y_buffer, dst->u_buffer, dst->v_buffer};
-    const int dst_strides[3] = {dst->y_stride, dst->uv_stride, dst->uv_stride};
-    for (i = 0; i < MAX_MB_PLANE; ++i) {
-      vp9_highbd_post_proc_down_and_across(CONVERT_TO_SHORTPTR(srcs[i]),
-                                           CONVERT_TO_SHORTPTR(dsts[i]),
-                                           src_strides[i], dst_strides[i],
-                                           src_heights[i], src_widths[i], ppl);
-    }
-  } else {
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-    int mbr;
-    const int mb_rows = src->y_height / 16;
-    const int mb_cols = src->y_width / 16;
-
-    memset(limits, (unsigned char) ppl, 16 * mb_cols);
-
-    for (mbr = 0; mbr < mb_rows; mbr++) {
-      vpx_post_proc_down_and_across_mb_row(
-          src->y_buffer + 16 * mbr * src->y_stride,
-          dst->y_buffer + 16 * mbr * dst->y_stride, src->y_stride,
-          dst->y_stride, src->y_width, limits, 16);
-      vpx_post_proc_down_and_across_mb_row(
-          src->u_buffer + 8 * mbr * src->uv_stride,
-          dst->u_buffer + 8 * mbr * dst->uv_stride, src->uv_stride,
-          dst->uv_stride, src->uv_width, limits, 8);
-      vpx_post_proc_down_and_across_mb_row(
-          src->v_buffer + 8 * mbr * src->uv_stride,
-          dst->v_buffer + 8 * mbr * dst->uv_stride, src->uv_stride,
-          dst->uv_stride, src->uv_width, limits, 8);
-    }
-#if CONFIG_VP9_HIGHBITDEPTH
-  }
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-}
-
-void vp9_denoise(const YV12_BUFFER_CONFIG *src, YV12_BUFFER_CONFIG *dst,
-                 int q, uint8_t *limits) {
-  vp9_deblock(src, dst, q, limits);
-}
-
-static void swap_mi_and_prev_mi(VP9_COMMON *cm) {
-  // Current mip will be the prev_mip for the next frame.
-  MODE_INFO *temp = cm->postproc_state.prev_mip;
-  cm->postproc_state.prev_mip = cm->mip;
-  cm->mip = temp;
-
-  // Update the upper left visible macroblock ptrs.
-  cm->mi = cm->mip + cm->mi_stride + 1;
-  cm->postproc_state.prev_mi = cm->postproc_state.prev_mip + cm->mi_stride + 1;
-}
-
-int vp9_post_proc_frame(struct VP9Common *cm,
-                        YV12_BUFFER_CONFIG *dest, vp9_ppflags_t *ppflags) {
-  const int q = VPXMIN(105, cm->lf.filter_level * 2);
-  const int flags = ppflags->post_proc_flag;
-  YV12_BUFFER_CONFIG *const ppbuf = &cm->post_proc_buffer;
-  struct postproc_state *const ppstate = &cm->postproc_state;
-
-  if (!cm->frame_to_show)
-    return -1;
-
-  if (!flags) {
-    *dest = *cm->frame_to_show;
-    return 0;
-  }
-
-  vpx_clear_system_state();
-
-  // Alloc memory for prev_mip in the first frame.
-  if (cm->current_video_frame == 1) {
-    cm->postproc_state.last_base_qindex = cm->base_qindex;
-    cm->postproc_state.last_frame_valid = 1;
-    ppstate->prev_mip = vpx_calloc(cm->mi_alloc_size, sizeof(*cm->mip));
-    if (!ppstate->prev_mip) {
-      return 1;
-    }
-    ppstate->prev_mi = ppstate->prev_mip + cm->mi_stride + 1;
-    memset(ppstate->prev_mip, 0,
-           cm->mi_stride * (cm->mi_rows + 1) * sizeof(*cm->mip));
-  }
-
-  // Allocate post_proc_buffer_int if needed.
-  if ((flags & VP9D_MFQE) && !cm->post_proc_buffer_int.buffer_alloc) {
-    if ((flags & VP9D_DEMACROBLOCK) || (flags & VP9D_DEBLOCK)) {
-      const int width = ALIGN_POWER_OF_TWO(cm->width, 4);
-      const int height = ALIGN_POWER_OF_TWO(cm->height, 4);
-
-      if (vpx_alloc_frame_buffer(&cm->post_proc_buffer_int, width, height,
-                                 cm->subsampling_x, cm->subsampling_y,
-#if CONFIG_VP9_HIGHBITDEPTH
-                                 cm->use_highbitdepth,
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-                                 VP9_ENC_BORDER_IN_PIXELS,
-                                 cm->byte_alignment) < 0) {
-        vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR,
-                           "Failed to allocate MFQE framebuffer");
-      }
-
-      // Ensure that postproc is set to all 0s so that post proc
-      // doesn't pull random data in from edge.
-      memset(cm->post_proc_buffer_int.buffer_alloc, 128,
-             cm->post_proc_buffer.frame_size);
-    }
-  }
-
-  if (vpx_realloc_frame_buffer(&cm->post_proc_buffer, cm->width, cm->height,
-                               cm->subsampling_x, cm->subsampling_y,
-#if CONFIG_VP9_HIGHBITDEPTH
-                               cm->use_highbitdepth,
-#endif
-                               VP9_DEC_BORDER_IN_PIXELS, cm->byte_alignment,
-                               NULL, NULL, NULL) < 0)
-    vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR,
-                       "Failed to allocate post-processing buffer");
-
-  if (flags & (VP9D_DEMACROBLOCK | VP9D_DEBLOCK)) {
-    if (!cm->postproc_state.limits) {
-      cm->postproc_state.limits = vpx_calloc(
-          cm->width, sizeof(*cm->postproc_state.limits));
-    }
-  }
-
-
-  if ((flags & VP9D_MFQE) && cm->current_video_frame >= 2 &&
-      cm->postproc_state.last_frame_valid && cm->bit_depth == 8 &&
-      cm->postproc_state.last_base_qindex <= last_q_thresh &&
-      cm->base_qindex - cm->postproc_state.last_base_qindex >= q_diff_thresh) {
-    vp9_mfqe(cm);
-    // TODO(jackychen): Consider whether enable deblocking by default
-    // if mfqe is enabled. Need to take both the quality and the speed
-    // into consideration.
-    if ((flags & VP9D_DEMACROBLOCK) || (flags & VP9D_DEBLOCK)) {
-      vp8_yv12_copy_frame(ppbuf, &cm->post_proc_buffer_int);
-    }
-    if ((flags & VP9D_DEMACROBLOCK) && cm->post_proc_buffer_int.buffer_alloc) {
-      deblock_and_de_macro_block(&cm->post_proc_buffer_int, ppbuf,
-                                 q + (ppflags->deblocking_level - 5) * 10,
-                                 1, 0, cm->postproc_state.limits);
-    } else if (flags & VP9D_DEBLOCK) {
-      vp9_deblock(&cm->post_proc_buffer_int, ppbuf, q,
-                  cm->postproc_state.limits);
-    } else {
-      vp8_yv12_copy_frame(&cm->post_proc_buffer_int, ppbuf);
-    }
-  } else if (flags & VP9D_DEMACROBLOCK) {
-    deblock_and_de_macro_block(cm->frame_to_show, ppbuf,
-                               q + (ppflags->deblocking_level - 5) * 10, 1, 0,
-                               cm->postproc_state.limits);
-  } else if (flags & VP9D_DEBLOCK) {
-    vp9_deblock(cm->frame_to_show, ppbuf, q, cm->postproc_state.limits);
-  } else {
-    vp8_yv12_copy_frame(cm->frame_to_show, ppbuf);
-  }
-
-  cm->postproc_state.last_base_qindex = cm->base_qindex;
-  cm->postproc_state.last_frame_valid = 1;
-
-  if (flags & VP9D_ADDNOISE) {
-    const int noise_level = ppflags->noise_level;
-    if (ppstate->last_q != q ||
-        ppstate->last_noise != noise_level) {
-      double sigma;
-      int clamp, i;
-      vpx_clear_system_state();
-      sigma = noise_level + .5 + .6 * q / 63.0;
-      clamp = vpx_setup_noise(sigma, sizeof(ppstate->noise),
-                              ppstate->noise);
-
-      for (i = 0; i < 16; i++) {
-        ppstate->blackclamp[i] = clamp;
-        ppstate->whiteclamp[i] = clamp;
-        ppstate->bothclamp[i] = 2 * clamp;
-      }
-      ppstate->last_q = q;
-      ppstate->last_noise = noise_level;
-    }
-    vpx_plane_add_noise(ppbuf->y_buffer, ppstate->noise, ppstate->blackclamp,
-                        ppstate->whiteclamp, ppstate->bothclamp,
-                        ppbuf->y_width, ppbuf->y_height, ppbuf->y_stride);
-  }
-
-  *dest = *ppbuf;
-
-  /* handle problem with extending borders */
-  dest->y_width = cm->width;
-  dest->y_height = cm->height;
-  dest->uv_width = dest->y_width >> cm->subsampling_x;
-  dest->uv_height = dest->y_height >> cm->subsampling_y;
-
-  swap_mi_and_prev_mi(cm);
-  return 0;
-}
-#endif  // CONFIG_VP9_POSTPROC
diff --git a/vp9/common/vp9_postproc.h b/vp9/common/vp9_postproc.h
deleted file mode 100644 (file)
index 60e6f52..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#ifndef VP9_COMMON_VP9_POSTPROC_H_
-#define VP9_COMMON_VP9_POSTPROC_H_
-
-#include "vpx_ports/mem.h"
-#include "vpx_scale/yv12config.h"
-#include "vp9/common/vp9_blockd.h"
-#include "vp9/common/vp9_mfqe.h"
-#include "vp9/common/vp9_ppflags.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-struct postproc_state {
-  int last_q;
-  int last_noise;
-  char noise[3072];
-  int last_base_qindex;
-  int last_frame_valid;
-  MODE_INFO *prev_mip;
-  MODE_INFO *prev_mi;
-  DECLARE_ALIGNED(16, char, blackclamp[16]);
-  DECLARE_ALIGNED(16, char, whiteclamp[16]);
-  DECLARE_ALIGNED(16, char, bothclamp[16]);
-  uint8_t *limits;
-};
-
-struct VP9Common;
-
-#define MFQE_PRECISION 4
-
-int vp9_post_proc_frame(struct VP9Common *cm,
-                        YV12_BUFFER_CONFIG *dest, vp9_ppflags_t *flags);
-
-void vp9_denoise(const YV12_BUFFER_CONFIG *src, YV12_BUFFER_CONFIG *dst, int q,
-                 uint8_t *limits);
-
-void vp9_deblock(const YV12_BUFFER_CONFIG *src, YV12_BUFFER_CONFIG *dst, int q,
-                 uint8_t *limits);
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP9_COMMON_VP9_POSTPROC_H_
diff --git a/vp9/common/vp9_ppflags.h b/vp9/common/vp9_ppflags.h
deleted file mode 100644 (file)
index 12b989f..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#ifndef VP9_COMMON_VP9_PPFLAGS_H_
-#define VP9_COMMON_VP9_PPFLAGS_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-enum {
-  VP9D_NOFILTERING            = 0,
-  VP9D_DEBLOCK                = 1 << 0,
-  VP9D_DEMACROBLOCK           = 1 << 1,
-  VP9D_ADDNOISE               = 1 << 2,
-  VP9D_DEBUG_TXT_FRAME_INFO   = 1 << 3,
-  VP9D_DEBUG_TXT_MBLK_MODES   = 1 << 4,
-  VP9D_DEBUG_TXT_DC_DIFF      = 1 << 5,
-  VP9D_DEBUG_TXT_RATE_INFO    = 1 << 6,
-  VP9D_DEBUG_DRAW_MV          = 1 << 7,
-  VP9D_DEBUG_CLR_BLK_MODES    = 1 << 8,
-  VP9D_DEBUG_CLR_FRM_REF_BLKS = 1 << 9,
-  VP9D_MFQE                   = 1 << 10
-};
-
-typedef struct {
-  int post_proc_flag;
-  int deblocking_level;
-  int noise_level;
-} vp9_ppflags_t;
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP9_COMMON_VP9_PPFLAGS_H_
diff --git a/vp9/common/vp9_pred_common.c b/vp9/common/vp9_pred_common.c
deleted file mode 100644 (file)
index 8f90e70..0000000
+++ /dev/null
@@ -1,314 +0,0 @@
-
-/*
- *  Copyright (c) 2012 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.
- */
-
-#include "vp9/common/vp9_common.h"
-#include "vp9/common/vp9_pred_common.h"
-#include "vp9/common/vp9_seg_common.h"
-
-// Returns a context number for the given MB prediction signal
-int vp9_get_pred_context_switchable_interp(const MACROBLOCKD *xd) {
-  // Note:
-  // The mode info data structure has a one element border above and to the
-  // left of the entries corresponding to real macroblocks.
-  // The prediction flags in these dummy entries are initialized to 0.
-  const MODE_INFO *const left_mi = xd->left_mi;
-  const int left_type = left_mi && is_inter_block(left_mi) ?
-                            left_mi->interp_filter : SWITCHABLE_FILTERS;
-  const MODE_INFO *const above_mi = xd->above_mi;
-  const int above_type = above_mi && is_inter_block(above_mi) ?
-                             above_mi->interp_filter : SWITCHABLE_FILTERS;
-
-  if (left_type == above_type)
-    return left_type;
-  else if (left_type == SWITCHABLE_FILTERS)
-    return above_type;
-  else if (above_type == SWITCHABLE_FILTERS)
-    return left_type;
-  else
-    return SWITCHABLE_FILTERS;
-}
-
-int vp9_get_reference_mode_context(const VP9_COMMON *cm,
-                                   const MACROBLOCKD *xd) {
-  int ctx;
-  const MODE_INFO *const above_mi = xd->above_mi;
-  const MODE_INFO *const left_mi = xd->left_mi;
-  const int has_above = !!above_mi;
-  const int has_left = !!left_mi;
-  // Note:
-  // The mode info data structure has a one element border above and to the
-  // left of the entries corresponding to real macroblocks.
-  // The prediction flags in these dummy entries are initialized to 0.
-  if (has_above && has_left) {  // both edges available
-    if (!has_second_ref(above_mi) && !has_second_ref(left_mi))
-      // neither edge uses comp pred (0/1)
-      ctx = (above_mi->ref_frame[0] == cm->comp_fixed_ref) ^
-            (left_mi->ref_frame[0] == cm->comp_fixed_ref);
-    else if (!has_second_ref(above_mi))
-      // one of two edges uses comp pred (2/3)
-      ctx = 2 + (above_mi->ref_frame[0] == cm->comp_fixed_ref ||
-                 !is_inter_block(above_mi));
-    else if (!has_second_ref(left_mi))
-      // one of two edges uses comp pred (2/3)
-      ctx = 2 + (left_mi->ref_frame[0] == cm->comp_fixed_ref ||
-                 !is_inter_block(left_mi));
-    else  // both edges use comp pred (4)
-      ctx = 4;
-  } else if (has_above || has_left) {  // one edge available
-    const MODE_INFO *edge_mi = has_above ? above_mi : left_mi;
-
-    if (!has_second_ref(edge_mi))
-      // edge does not use comp pred (0/1)
-      ctx = edge_mi->ref_frame[0] == cm->comp_fixed_ref;
-    else
-      // edge uses comp pred (3)
-      ctx = 3;
-  } else {  // no edges available (1)
-    ctx = 1;
-  }
-  assert(ctx >= 0 && ctx < COMP_INTER_CONTEXTS);
-  return ctx;
-}
-
-// Returns a context number for the given MB prediction signal
-int vp9_get_pred_context_comp_ref_p(const VP9_COMMON *cm,
-                                    const MACROBLOCKD *xd) {
-  int pred_context;
-  const MODE_INFO *const above_mi = xd->above_mi;
-  const MODE_INFO *const left_mi = xd->left_mi;
-  const int above_in_image = !!above_mi;
-  const int left_in_image = !!left_mi;
-
-  // Note:
-  // The mode info data structure has a one element border above and to the
-  // left of the entries corresponding to real macroblocks.
-  // The prediction flags in these dummy entries are initialized to 0.
-  const int fix_ref_idx = cm->ref_frame_sign_bias[cm->comp_fixed_ref];
-  const int var_ref_idx = !fix_ref_idx;
-
-  if (above_in_image && left_in_image) {  // both edges available
-    const int above_intra = !is_inter_block(above_mi);
-    const int left_intra = !is_inter_block(left_mi);
-
-    if (above_intra && left_intra) {  // intra/intra (2)
-      pred_context = 2;
-    } else if (above_intra || left_intra) {  // intra/inter
-      const MODE_INFO *edge_mi = above_intra ? left_mi : above_mi;
-
-      if (!has_second_ref(edge_mi))  // single pred (1/3)
-        pred_context = 1 + 2 * (edge_mi->ref_frame[0] != cm->comp_var_ref[1]);
-      else  // comp pred (1/3)
-        pred_context = 1 + 2 * (edge_mi->ref_frame[var_ref_idx]
-                                    != cm->comp_var_ref[1]);
-    } else {  // inter/inter
-      const int l_sg = !has_second_ref(left_mi);
-      const int a_sg = !has_second_ref(above_mi);
-      const MV_REFERENCE_FRAME vrfa = a_sg ? above_mi->ref_frame[0]
-                                           : above_mi->ref_frame[var_ref_idx];
-      const MV_REFERENCE_FRAME vrfl = l_sg ? left_mi->ref_frame[0]
-                                           : left_mi->ref_frame[var_ref_idx];
-
-      if (vrfa == vrfl && cm->comp_var_ref[1] == vrfa) {
-        pred_context = 0;
-      } else if (l_sg && a_sg) {  // single/single
-        if ((vrfa == cm->comp_fixed_ref && vrfl == cm->comp_var_ref[0]) ||
-            (vrfl == cm->comp_fixed_ref && vrfa == cm->comp_var_ref[0]))
-          pred_context = 4;
-        else if (vrfa == vrfl)
-          pred_context = 3;
-        else
-          pred_context = 1;
-      } else if (l_sg || a_sg) {  // single/comp
-        const MV_REFERENCE_FRAME vrfc = l_sg ? vrfa : vrfl;
-        const MV_REFERENCE_FRAME rfs = a_sg ? vrfa : vrfl;
-        if (vrfc == cm->comp_var_ref[1] && rfs != cm->comp_var_ref[1])
-          pred_context = 1;
-        else if (rfs == cm->comp_var_ref[1] && vrfc != cm->comp_var_ref[1])
-          pred_context = 2;
-        else
-          pred_context = 4;
-      } else if (vrfa == vrfl) {  // comp/comp
-        pred_context = 4;
-      } else {
-        pred_context = 2;
-      }
-    }
-  } else if (above_in_image || left_in_image) {  // one edge available
-    const MODE_INFO *edge_mi = above_in_image ? above_mi : left_mi;
-
-    if (!is_inter_block(edge_mi)) {
-      pred_context = 2;
-    } else {
-      if (has_second_ref(edge_mi))
-        pred_context = 4 * (edge_mi->ref_frame[var_ref_idx]
-                              != cm->comp_var_ref[1]);
-      else
-        pred_context = 3 * (edge_mi->ref_frame[0] != cm->comp_var_ref[1]);
-    }
-  } else {  // no edges available (2)
-    pred_context = 2;
-  }
-  assert(pred_context >= 0 && pred_context < REF_CONTEXTS);
-
-  return pred_context;
-}
-
-int vp9_get_pred_context_single_ref_p1(const MACROBLOCKD *xd) {
-  int pred_context;
-  const MODE_INFO *const above_mi = xd->above_mi;
-  const MODE_INFO *const left_mi = xd->left_mi;
-  const int has_above = !!above_mi;
-  const int has_left = !!left_mi;
-  // Note:
-  // The mode info data structure has a one element border above and to the
-  // left of the entries corresponding to real macroblocks.
-  // The prediction flags in these dummy entries are initialized to 0.
-  if (has_above && has_left) {  // both edges available
-    const int above_intra = !is_inter_block(above_mi);
-    const int left_intra = !is_inter_block(left_mi);
-
-    if (above_intra && left_intra) {  // intra/intra
-      pred_context = 2;
-    } else if (above_intra || left_intra) {  // intra/inter or inter/intra
-      const MODE_INFO *edge_mi = above_intra ? left_mi : above_mi;
-      if (!has_second_ref(edge_mi))
-        pred_context = 4 * (edge_mi->ref_frame[0] == LAST_FRAME);
-      else
-        pred_context = 1 + (edge_mi->ref_frame[0] == LAST_FRAME ||
-                            edge_mi->ref_frame[1] == LAST_FRAME);
-    } else {  // inter/inter
-      const int above_has_second = has_second_ref(above_mi);
-      const int left_has_second = has_second_ref(left_mi);
-      const MV_REFERENCE_FRAME above0 = above_mi->ref_frame[0];
-      const MV_REFERENCE_FRAME above1 = above_mi->ref_frame[1];
-      const MV_REFERENCE_FRAME left0 = left_mi->ref_frame[0];
-      const MV_REFERENCE_FRAME left1 = left_mi->ref_frame[1];
-
-      if (above_has_second && left_has_second) {
-        pred_context = 1 + (above0 == LAST_FRAME || above1 == LAST_FRAME ||
-                            left0 == LAST_FRAME || left1 == LAST_FRAME);
-      } else if (above_has_second || left_has_second) {
-        const MV_REFERENCE_FRAME rfs = !above_has_second ? above0 : left0;
-        const MV_REFERENCE_FRAME crf1 = above_has_second ? above0 : left0;
-        const MV_REFERENCE_FRAME crf2 = above_has_second ? above1 : left1;
-
-        if (rfs == LAST_FRAME)
-          pred_context = 3 + (crf1 == LAST_FRAME || crf2 == LAST_FRAME);
-        else
-          pred_context = (crf1 == LAST_FRAME || crf2 == LAST_FRAME);
-      } else {
-        pred_context = 2 * (above0 == LAST_FRAME) + 2 * (left0 == LAST_FRAME);
-      }
-    }
-  } else if (has_above || has_left) {  // one edge available
-    const MODE_INFO *edge_mi = has_above ? above_mi : left_mi;
-    if (!is_inter_block(edge_mi)) {  // intra
-      pred_context = 2;
-    } else {  // inter
-      if (!has_second_ref(edge_mi))
-        pred_context = 4 * (edge_mi->ref_frame[0] == LAST_FRAME);
-      else
-        pred_context = 1 + (edge_mi->ref_frame[0] == LAST_FRAME ||
-                            edge_mi->ref_frame[1] == LAST_FRAME);
-    }
-  } else {  // no edges available
-    pred_context = 2;
-  }
-
-  assert(pred_context >= 0 && pred_context < REF_CONTEXTS);
-  return pred_context;
-}
-
-int vp9_get_pred_context_single_ref_p2(const MACROBLOCKD *xd) {
-  int pred_context;
-  const MODE_INFO *const above_mi = xd->above_mi;
-  const MODE_INFO *const left_mi = xd->left_mi;
-  const int has_above = !!above_mi;
-  const int has_left = !!left_mi;
-
-  // Note:
-  // The mode info data structure has a one element border above and to the
-  // left of the entries corresponding to real macroblocks.
-  // The prediction flags in these dummy entries are initialized to 0.
-  if (has_above && has_left) {  // both edges available
-    const int above_intra = !is_inter_block(above_mi);
-    const int left_intra = !is_inter_block(left_mi);
-
-    if (above_intra && left_intra) {  // intra/intra
-      pred_context = 2;
-    } else if (above_intra || left_intra) {  // intra/inter or inter/intra
-      const MODE_INFO *edge_mi = above_intra ? left_mi : above_mi;
-      if (!has_second_ref(edge_mi)) {
-        if (edge_mi->ref_frame[0] == LAST_FRAME)
-          pred_context = 3;
-        else
-          pred_context = 4 * (edge_mi->ref_frame[0] == GOLDEN_FRAME);
-      } else {
-        pred_context = 1 + 2 * (edge_mi->ref_frame[0] == GOLDEN_FRAME ||
-                                edge_mi->ref_frame[1] == GOLDEN_FRAME);
-      }
-    } else {  // inter/inter
-      const int above_has_second = has_second_ref(above_mi);
-      const int left_has_second = has_second_ref(left_mi);
-      const MV_REFERENCE_FRAME above0 = above_mi->ref_frame[0];
-      const MV_REFERENCE_FRAME above1 = above_mi->ref_frame[1];
-      const MV_REFERENCE_FRAME left0 = left_mi->ref_frame[0];
-      const MV_REFERENCE_FRAME left1 = left_mi->ref_frame[1];
-
-      if (above_has_second && left_has_second) {
-        if (above0 == left0 && above1 == left1)
-          pred_context = 3 * (above0 == GOLDEN_FRAME ||
-                              above1 == GOLDEN_FRAME ||
-                              left0 == GOLDEN_FRAME ||
-                              left1 == GOLDEN_FRAME);
-        else
-          pred_context = 2;
-      } else if (above_has_second || left_has_second) {
-        const MV_REFERENCE_FRAME rfs = !above_has_second ? above0 : left0;
-        const MV_REFERENCE_FRAME crf1 = above_has_second ? above0 : left0;
-        const MV_REFERENCE_FRAME crf2 = above_has_second ? above1 : left1;
-
-        if (rfs == GOLDEN_FRAME)
-          pred_context = 3 + (crf1 == GOLDEN_FRAME || crf2 == GOLDEN_FRAME);
-        else if (rfs == ALTREF_FRAME)
-          pred_context = crf1 == GOLDEN_FRAME || crf2 == GOLDEN_FRAME;
-        else
-          pred_context = 1 + 2 * (crf1 == GOLDEN_FRAME || crf2 == GOLDEN_FRAME);
-      } else {
-        if (above0 == LAST_FRAME && left0 == LAST_FRAME) {
-          pred_context = 3;
-        } else if (above0 == LAST_FRAME || left0 == LAST_FRAME) {
-          const MV_REFERENCE_FRAME edge0 = (above0 == LAST_FRAME) ? left0
-                                                                  : above0;
-          pred_context = 4 * (edge0 == GOLDEN_FRAME);
-        } else {
-          pred_context = 2 * (above0 == GOLDEN_FRAME) +
-                             2 * (left0 == GOLDEN_FRAME);
-        }
-      }
-    }
-  } else if (has_above || has_left) {  // one edge available
-    const MODE_INFO *edge_mi = has_above ? above_mi : left_mi;
-
-    if (!is_inter_block(edge_mi) ||
-        (edge_mi->ref_frame[0] == LAST_FRAME && !has_second_ref(edge_mi)))
-      pred_context = 2;
-    else if (!has_second_ref(edge_mi))
-      pred_context = 4 * (edge_mi->ref_frame[0] == GOLDEN_FRAME);
-    else
-      pred_context = 3 * (edge_mi->ref_frame[0] == GOLDEN_FRAME ||
-                          edge_mi->ref_frame[1] == GOLDEN_FRAME);
-  } else {  // no edges available (2)
-    pred_context = 2;
-  }
-  assert(pred_context >= 0 && pred_context < REF_CONTEXTS);
-  return pred_context;
-}
diff --git a/vp9/common/vp9_pred_common.h b/vp9/common/vp9_pred_common.h
deleted file mode 100644 (file)
index f3c676e..0000000
+++ /dev/null
@@ -1,192 +0,0 @@
-/*
- *  Copyright (c) 2012 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.
- */
-
-#ifndef VP9_COMMON_VP9_PRED_COMMON_H_
-#define VP9_COMMON_VP9_PRED_COMMON_H_
-
-#include "vp9/common/vp9_blockd.h"
-#include "vp9/common/vp9_onyxc_int.h"
-#include "vpx_dsp/vpx_dsp_common.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-static INLINE int get_segment_id(const VP9_COMMON *cm,
-                                 const uint8_t *segment_ids,
-                                 BLOCK_SIZE bsize, int mi_row, int mi_col) {
-  const int mi_offset = mi_row * cm->mi_cols + mi_col;
-  const int bw = num_8x8_blocks_wide_lookup[bsize];
-  const int bh = num_8x8_blocks_high_lookup[bsize];
-  const int xmis = VPXMIN(cm->mi_cols - mi_col, bw);
-  const int ymis = VPXMIN(cm->mi_rows - mi_row, bh);
-  int x, y, segment_id = MAX_SEGMENTS;
-
-  for (y = 0; y < ymis; ++y)
-    for (x = 0; x < xmis; ++x)
-      segment_id =
-          VPXMIN(segment_id, segment_ids[mi_offset + y * cm->mi_cols + x]);
-
-  assert(segment_id >= 0 && segment_id < MAX_SEGMENTS);
-  return segment_id;
-}
-
-static INLINE int vp9_get_pred_context_seg_id(const MACROBLOCKD *xd) {
-  const MODE_INFO *const above_mi = xd->above_mi;
-  const MODE_INFO *const left_mi = xd->left_mi;
-  const int above_sip = (above_mi != NULL) ?
-                        above_mi->seg_id_predicted : 0;
-  const int left_sip = (left_mi != NULL) ? left_mi->seg_id_predicted : 0;
-
-  return above_sip + left_sip;
-}
-
-static INLINE vpx_prob vp9_get_pred_prob_seg_id(const struct segmentation *seg,
-                                                const MACROBLOCKD *xd) {
-  return seg->pred_probs[vp9_get_pred_context_seg_id(xd)];
-}
-
-static INLINE int vp9_get_skip_context(const MACROBLOCKD *xd) {
-  const MODE_INFO *const above_mi = xd->above_mi;
-  const MODE_INFO *const left_mi = xd->left_mi;
-  const int above_skip = (above_mi != NULL) ? above_mi->skip : 0;
-  const int left_skip = (left_mi != NULL) ? left_mi->skip : 0;
-  return above_skip + left_skip;
-}
-
-static INLINE vpx_prob vp9_get_skip_prob(const VP9_COMMON *cm,
-                                         const MACROBLOCKD *xd) {
-  return cm->fc->skip_probs[vp9_get_skip_context(xd)];
-}
-
-int vp9_get_pred_context_switchable_interp(const MACROBLOCKD *xd);
-
-// The mode info data structure has a one element border above and to the
-// left of the entries corresponding to real macroblocks.
-// The prediction flags in these dummy entries are initialized to 0.
-// 0 - inter/inter, inter/--, --/inter, --/--
-// 1 - intra/inter, inter/intra
-// 2 - intra/--, --/intra
-// 3 - intra/intra
-static INLINE int get_intra_inter_context(const MACROBLOCKD *xd) {
-  const MODE_INFO *const above_mi = xd->above_mi;
-  const MODE_INFO *const left_mi = xd->left_mi;
-  const int has_above = !!above_mi;
-  const int has_left = !!left_mi;
-
-  if (has_above && has_left) {  // both edges available
-    const int above_intra = !is_inter_block(above_mi);
-    const int left_intra = !is_inter_block(left_mi);
-    return left_intra && above_intra ? 3 : left_intra || above_intra;
-  } else if (has_above || has_left) {  // one edge available
-    return 2 * !is_inter_block(has_above ? above_mi : left_mi);
-  }
-  return 0;
-}
-
-static INLINE vpx_prob vp9_get_intra_inter_prob(const VP9_COMMON *cm,
-                                                const MACROBLOCKD *xd) {
-  return cm->fc->intra_inter_prob[get_intra_inter_context(xd)];
-}
-
-int vp9_get_reference_mode_context(const VP9_COMMON *cm, const MACROBLOCKD *xd);
-
-static INLINE vpx_prob vp9_get_reference_mode_prob(const VP9_COMMON *cm,
-                                                   const MACROBLOCKD *xd) {
-  return cm->fc->comp_inter_prob[vp9_get_reference_mode_context(cm, xd)];
-}
-
-int vp9_get_pred_context_comp_ref_p(const VP9_COMMON *cm,
-                                    const MACROBLOCKD *xd);
-
-static INLINE vpx_prob vp9_get_pred_prob_comp_ref_p(const VP9_COMMON *cm,
-                                                    const MACROBLOCKD *xd) {
-  const int pred_context = vp9_get_pred_context_comp_ref_p(cm, xd);
-  return cm->fc->comp_ref_prob[pred_context];
-}
-
-int vp9_get_pred_context_single_ref_p1(const MACROBLOCKD *xd);
-
-static INLINE vpx_prob vp9_get_pred_prob_single_ref_p1(const VP9_COMMON *cm,
-                                                       const MACROBLOCKD *xd) {
-  return cm->fc->single_ref_prob[vp9_get_pred_context_single_ref_p1(xd)][0];
-}
-
-int vp9_get_pred_context_single_ref_p2(const MACROBLOCKD *xd);
-
-static INLINE vpx_prob vp9_get_pred_prob_single_ref_p2(const VP9_COMMON *cm,
-                                                       const MACROBLOCKD *xd) {
-  return cm->fc->single_ref_prob[vp9_get_pred_context_single_ref_p2(xd)][1];
-}
-
-// Returns a context number for the given MB prediction signal
-// The mode info data structure has a one element border above and to the
-// left of the entries corresponding to real blocks.
-// The prediction flags in these dummy entries are initialized to 0.
-static INLINE int get_tx_size_context(const MACROBLOCKD *xd) {
-  const int max_tx_size = max_txsize_lookup[xd->mi[0]->sb_type];
-  const MODE_INFO *const above_mi = xd->above_mi;
-  const MODE_INFO *const left_mi = xd->left_mi;
-  const int has_above = !!above_mi;
-  const int has_left = !!left_mi;
-  int above_ctx = (has_above && !above_mi->skip) ? (int)above_mi->tx_size
-                                                 : max_tx_size;
-  int left_ctx = (has_left && !left_mi->skip) ? (int)left_mi->tx_size
-                                              : max_tx_size;
-  if (!has_left)
-    left_ctx = above_ctx;
-
-  if (!has_above)
-    above_ctx = left_ctx;
-
-  return (above_ctx + left_ctx) > max_tx_size;
-}
-
-static INLINE const vpx_prob *get_tx_probs(TX_SIZE max_tx_size, int ctx,
-                                           const struct tx_probs *tx_probs) {
-  switch (max_tx_size) {
-    case TX_8X8:
-      return tx_probs->p8x8[ctx];
-    case TX_16X16:
-      return tx_probs->p16x16[ctx];
-    case TX_32X32:
-      return tx_probs->p32x32[ctx];
-    default:
-      assert(0 && "Invalid max_tx_size.");
-      return NULL;
-  }
-}
-
-static INLINE const vpx_prob *get_tx_probs2(TX_SIZE max_tx_size,
-                                            const MACROBLOCKD *xd,
-                                            const struct tx_probs *tx_probs) {
-  return get_tx_probs(max_tx_size, get_tx_size_context(xd), tx_probs);
-}
-
-static INLINE unsigned int *get_tx_counts(TX_SIZE max_tx_size, int ctx,
-                                          struct tx_counts *tx_counts) {
-  switch (max_tx_size) {
-    case TX_8X8:
-      return tx_counts->p8x8[ctx];
-    case TX_16X16:
-      return tx_counts->p16x16[ctx];
-    case TX_32X32:
-      return tx_counts->p32x32[ctx];
-    default:
-      assert(0 && "Invalid max_tx_size.");
-      return NULL;
-  }
-}
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP9_COMMON_VP9_PRED_COMMON_H_
diff --git a/vp9/common/vp9_quant_common.c b/vp9/common/vp9_quant_common.c
deleted file mode 100644 (file)
index d83f3c1..0000000
+++ /dev/null
@@ -1,278 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#include "vp9/common/vp9_common.h"
-#include "vp9/common/vp9_quant_common.h"
-#include "vp9/common/vp9_seg_common.h"
-
-static const int16_t dc_qlookup[QINDEX_RANGE] = {
-  4,       8,    8,    9,   10,   11,   12,   12,
-  13,     14,   15,   16,   17,   18,   19,   19,
-  20,     21,   22,   23,   24,   25,   26,   26,
-  27,     28,   29,   30,   31,   32,   32,   33,
-  34,     35,   36,   37,   38,   38,   39,   40,
-  41,     42,   43,   43,   44,   45,   46,   47,
-  48,     48,   49,   50,   51,   52,   53,   53,
-  54,     55,   56,   57,   57,   58,   59,   60,
-  61,     62,   62,   63,   64,   65,   66,   66,
-  67,     68,   69,   70,   70,   71,   72,   73,
-  74,     74,   75,   76,   77,   78,   78,   79,
-  80,     81,   81,   82,   83,   84,   85,   85,
-  87,     88,   90,   92,   93,   95,   96,   98,
-  99,    101,  102,  104,  105,  107,  108,  110,
-  111,   113,  114,  116,  117,  118,  120,  121,
-  123,   125,  127,  129,  131,  134,  136,  138,
-  140,   142,  144,  146,  148,  150,  152,  154,
-  156,   158,  161,  164,  166,  169,  172,  174,
-  177,   180,  182,  185,  187,  190,  192,  195,
-  199,   202,  205,  208,  211,  214,  217,  220,
-  223,   226,  230,  233,  237,  240,  243,  247,
-  250,   253,  257,  261,  265,  269,  272,  276,
-  280,   284,  288,  292,  296,  300,  304,  309,
-  313,   317,  322,  326,  330,  335,  340,  344,
-  349,   354,  359,  364,  369,  374,  379,  384,
-  389,   395,  400,  406,  411,  417,  423,  429,
-  435,   441,  447,  454,  461,  467,  475,  482,
-  489,   497,  505,  513,  522,  530,  539,  549,
-  559,   569,  579,  590,  602,  614,  626,  640,
-  654,   668,  684,  700,  717,  736,  755,  775,
-  796,   819,  843,  869,  896,  925,  955,  988,
-  1022, 1058, 1098, 1139, 1184, 1232, 1282, 1336,
-};
-
-#if CONFIG_VP9_HIGHBITDEPTH
-static const int16_t dc_qlookup_10[QINDEX_RANGE] = {
-  4,     9,    10,    13,    15,    17,    20,    22,
-  25,    28,    31,    34,    37,    40,    43,    47,
-  50,    53,    57,    60,    64,    68,    71,    75,
-  78,    82,    86,    90,    93,    97,   101,   105,
-  109,   113,   116,   120,   124,   128,   132,   136,
-  140,   143,   147,   151,   155,   159,   163,   166,
-  170,   174,   178,   182,   185,   189,   193,   197,
-  200,   204,   208,   212,   215,   219,   223,   226,
-  230,   233,   237,   241,   244,   248,   251,   255,
-  259,   262,   266,   269,   273,   276,   280,   283,
-  287,   290,   293,   297,   300,   304,   307,   310,
-  314,   317,   321,   324,   327,   331,   334,   337,
-  343,   350,   356,   362,   369,   375,   381,   387,
-  394,   400,   406,   412,   418,   424,   430,   436,
-  442,   448,   454,   460,   466,   472,   478,   484,
-  490,   499,   507,   516,   525,   533,   542,   550,
-  559,   567,   576,   584,   592,   601,   609,   617,
-  625,   634,   644,   655,   666,   676,   687,   698,
-  708,   718,   729,   739,   749,   759,   770,   782,
-  795,   807,   819,   831,   844,   856,   868,   880,
-  891,   906,   920,   933,   947,   961,   975,   988,
-  1001,  1015,  1030,  1045,  1061,  1076,  1090,  1105,
-  1120,  1137,  1153,  1170,  1186,  1202,  1218,  1236,
-  1253,  1271,  1288,  1306,  1323,  1342,  1361,  1379,
-  1398,  1416,  1436,  1456,  1476,  1496,  1516,  1537,
-  1559,  1580,  1601,  1624,  1647,  1670,  1692,  1717,
-  1741,  1766,  1791,  1817,  1844,  1871,  1900,  1929,
-  1958,  1990,  2021,  2054,  2088,  2123,  2159,  2197,
-  2236,  2276,  2319,  2363,  2410,  2458,  2508,  2561,
-  2616,  2675,  2737,  2802,  2871,  2944,  3020,  3102,
-  3188,  3280,  3375,  3478,  3586,  3702,  3823,  3953,
-  4089,  4236,  4394,  4559,  4737,  4929,  5130,  5347,
-};
-
-static const int16_t dc_qlookup_12[QINDEX_RANGE] = {
-  4,    12,    18,    25,    33,    41,    50,    60,
-  70,    80,    91,   103,   115,   127,   140,   153,
-  166,   180,   194,   208,   222,   237,   251,   266,
-  281,   296,   312,   327,   343,   358,   374,   390,
-  405,   421,   437,   453,   469,   484,   500,   516,
-  532,   548,   564,   580,   596,   611,   627,   643,
-  659,   674,   690,   706,   721,   737,   752,   768,
-  783,   798,   814,   829,   844,   859,   874,   889,
-  904,   919,   934,   949,   964,   978,   993,  1008,
-  1022,  1037,  1051,  1065,  1080,  1094,  1108,  1122,
-  1136,  1151,  1165,  1179,  1192,  1206,  1220,  1234,
-  1248,  1261,  1275,  1288,  1302,  1315,  1329,  1342,
-  1368,  1393,  1419,  1444,  1469,  1494,  1519,  1544,
-  1569,  1594,  1618,  1643,  1668,  1692,  1717,  1741,
-  1765,  1789,  1814,  1838,  1862,  1885,  1909,  1933,
-  1957,  1992,  2027,  2061,  2096,  2130,  2165,  2199,
-  2233,  2267,  2300,  2334,  2367,  2400,  2434,  2467,
-  2499,  2532,  2575,  2618,  2661,  2704,  2746,  2788,
-  2830,  2872,  2913,  2954,  2995,  3036,  3076,  3127,
-  3177,  3226,  3275,  3324,  3373,  3421,  3469,  3517,
-  3565,  3621,  3677,  3733,  3788,  3843,  3897,  3951,
-  4005,  4058,  4119,  4181,  4241,  4301,  4361,  4420,
-  4479,  4546,  4612,  4677,  4742,  4807,  4871,  4942,
-  5013,  5083,  5153,  5222,  5291,  5367,  5442,  5517,
-  5591,  5665,  5745,  5825,  5905,  5984,  6063,  6149,
-  6234,  6319,  6404,  6495,  6587,  6678,  6769,  6867,
-  6966,  7064,  7163,  7269,  7376,  7483,  7599,  7715,
-  7832,  7958,  8085,  8214,  8352,  8492,  8635,  8788,
-  8945,  9104,  9275,  9450,  9639,  9832, 10031, 10245,
-  10465, 10702, 10946, 11210, 11482, 11776, 12081, 12409,
-  12750, 13118, 13501, 13913, 14343, 14807, 15290, 15812,
-  16356, 16943, 17575, 18237, 18949, 19718, 20521, 21387,
-};
-#endif
-
-static const int16_t ac_qlookup[QINDEX_RANGE] = {
-  4,       8,    9,   10,   11,   12,   13,   14,
-  15,     16,   17,   18,   19,   20,   21,   22,
-  23,     24,   25,   26,   27,   28,   29,   30,
-  31,     32,   33,   34,   35,   36,   37,   38,
-  39,     40,   41,   42,   43,   44,   45,   46,
-  47,     48,   49,   50,   51,   52,   53,   54,
-  55,     56,   57,   58,   59,   60,   61,   62,
-  63,     64,   65,   66,   67,   68,   69,   70,
-  71,     72,   73,   74,   75,   76,   77,   78,
-  79,     80,   81,   82,   83,   84,   85,   86,
-  87,     88,   89,   90,   91,   92,   93,   94,
-  95,     96,   97,   98,   99,  100,  101,  102,
-  104,   106,  108,  110,  112,  114,  116,  118,
-  120,   122,  124,  126,  128,  130,  132,  134,
-  136,   138,  140,  142,  144,  146,  148,  150,
-  152,   155,  158,  161,  164,  167,  170,  173,
-  176,   179,  182,  185,  188,  191,  194,  197,
-  200,   203,  207,  211,  215,  219,  223,  227,
-  231,   235,  239,  243,  247,  251,  255,  260,
-  265,   270,  275,  280,  285,  290,  295,  300,
-  305,   311,  317,  323,  329,  335,  341,  347,
-  353,   359,  366,  373,  380,  387,  394,  401,
-  408,   416,  424,  432,  440,  448,  456,  465,
-  474,   483,  492,  501,  510,  520,  530,  540,
-  550,   560,  571,  582,  593,  604,  615,  627,
-  639,   651,  663,  676,  689,  702,  715,  729,
-  743,   757,  771,  786,  801,  816,  832,  848,
-  864,   881,  898,  915,  933,  951,  969,  988,
-  1007, 1026, 1046, 1066, 1087, 1108, 1129, 1151,
-  1173, 1196, 1219, 1243, 1267, 1292, 1317, 1343,
-  1369, 1396, 1423, 1451, 1479, 1508, 1537, 1567,
-  1597, 1628, 1660, 1692, 1725, 1759, 1793, 1828,
-};
-
-#if CONFIG_VP9_HIGHBITDEPTH
-static const int16_t ac_qlookup_10[QINDEX_RANGE] = {
-  4,     9,    11,    13,    16,    18,    21,    24,
-  27,    30,    33,    37,    40,    44,    48,    51,
-  55,    59,    63,    67,    71,    75,    79,    83,
-  88,    92,    96,   100,   105,   109,   114,   118,
-  122,   127,   131,   136,   140,   145,   149,   154,
-  158,   163,   168,   172,   177,   181,   186,   190,
-  195,   199,   204,   208,   213,   217,   222,   226,
-  231,   235,   240,   244,   249,   253,   258,   262,
-  267,   271,   275,   280,   284,   289,   293,   297,
-  302,   306,   311,   315,   319,   324,   328,   332,
-  337,   341,   345,   349,   354,   358,   362,   367,
-  371,   375,   379,   384,   388,   392,   396,   401,
-  409,   417,   425,   433,   441,   449,   458,   466,
-  474,   482,   490,   498,   506,   514,   523,   531,
-  539,   547,   555,   563,   571,   579,   588,   596,
-  604,   616,   628,   640,   652,   664,   676,   688,
-  700,   713,   725,   737,   749,   761,   773,   785,
-  797,   809,   825,   841,   857,   873,   889,   905,
-  922,   938,   954,   970,   986,  1002,  1018,  1038,
-  1058,  1078,  1098,  1118,  1138,  1158,  1178,  1198,
-  1218,  1242,  1266,  1290,  1314,  1338,  1362,  1386,
-  1411,  1435,  1463,  1491,  1519,  1547,  1575,  1603,
-  1631,  1663,  1695,  1727,  1759,  1791,  1823,  1859,
-  1895,  1931,  1967,  2003,  2039,  2079,  2119,  2159,
-  2199,  2239,  2283,  2327,  2371,  2415,  2459,  2507,
-  2555,  2603,  2651,  2703,  2755,  2807,  2859,  2915,
-  2971,  3027,  3083,  3143,  3203,  3263,  3327,  3391,
-  3455,  3523,  3591,  3659,  3731,  3803,  3876,  3952,
-  4028,  4104,  4184,  4264,  4348,  4432,  4516,  4604,
-  4692,  4784,  4876,  4972,  5068,  5168,  5268,  5372,
-  5476,  5584,  5692,  5804,  5916,  6032,  6148,  6268,
-  6388,  6512,  6640,  6768,  6900,  7036,  7172,  7312,
-};
-
-static const int16_t ac_qlookup_12[QINDEX_RANGE] = {
-  4,    13,    19,    27,    35,    44,    54,    64,
-  75,    87,    99,   112,   126,   139,   154,   168,
-  183,   199,   214,   230,   247,   263,   280,   297,
-  314,   331,   349,   366,   384,   402,   420,   438,
-  456,   475,   493,   511,   530,   548,   567,   586,
-  604,   623,   642,   660,   679,   698,   716,   735,
-  753,   772,   791,   809,   828,   846,   865,   884,
-  902,   920,   939,   957,   976,   994,  1012,  1030,
-  1049,  1067,  1085,  1103,  1121,  1139,  1157,  1175,
-  1193,  1211,  1229,  1246,  1264,  1282,  1299,  1317,
-  1335,  1352,  1370,  1387,  1405,  1422,  1440,  1457,
-  1474,  1491,  1509,  1526,  1543,  1560,  1577,  1595,
-  1627,  1660,  1693,  1725,  1758,  1791,  1824,  1856,
-  1889,  1922,  1954,  1987,  2020,  2052,  2085,  2118,
-  2150,  2183,  2216,  2248,  2281,  2313,  2346,  2378,
-  2411,  2459,  2508,  2556,  2605,  2653,  2701,  2750,
-  2798,  2847,  2895,  2943,  2992,  3040,  3088,  3137,
-  3185,  3234,  3298,  3362,  3426,  3491,  3555,  3619,
-  3684,  3748,  3812,  3876,  3941,  4005,  4069,  4149,
-  4230,  4310,  4390,  4470,  4550,  4631,  4711,  4791,
-  4871,  4967,  5064,  5160,  5256,  5352,  5448,  5544,
-  5641,  5737,  5849,  5961,  6073,  6185,  6297,  6410,
-  6522,  6650,  6778,  6906,  7034,  7162,  7290,  7435,
-  7579,  7723,  7867,  8011,  8155,  8315,  8475,  8635,
-  8795,  8956,  9132,  9308,  9484,  9660,  9836, 10028,
-  10220, 10412, 10604, 10812, 11020, 11228, 11437, 11661,
-  11885, 12109, 12333, 12573, 12813, 13053, 13309, 13565,
-  13821, 14093, 14365, 14637, 14925, 15213, 15502, 15806,
-  16110, 16414, 16734, 17054, 17390, 17726, 18062, 18414,
-  18766, 19134, 19502, 19886, 20270, 20670, 21070, 21486,
-  21902, 22334, 22766, 23214, 23662, 24126, 24590, 25070,
-  25551, 26047, 26559, 27071, 27599, 28143, 28687, 29247,
-};
-#endif
-
-int16_t vp9_dc_quant(int qindex, int delta, vpx_bit_depth_t bit_depth) {
-#if CONFIG_VP9_HIGHBITDEPTH
-  switch (bit_depth) {
-    case VPX_BITS_8:
-      return dc_qlookup[clamp(qindex + delta, 0, MAXQ)];
-    case VPX_BITS_10:
-      return dc_qlookup_10[clamp(qindex + delta, 0, MAXQ)];
-    case VPX_BITS_12:
-      return dc_qlookup_12[clamp(qindex + delta, 0, MAXQ)];
-    default:
-      assert(0 && "bit_depth should be VPX_BITS_8, VPX_BITS_10 or VPX_BITS_12");
-      return -1;
-  }
-#else
-  (void) bit_depth;
-  return dc_qlookup[clamp(qindex + delta, 0, MAXQ)];
-#endif
-}
-
-int16_t vp9_ac_quant(int qindex, int delta, vpx_bit_depth_t bit_depth) {
-#if CONFIG_VP9_HIGHBITDEPTH
-  switch (bit_depth) {
-    case VPX_BITS_8:
-      return ac_qlookup[clamp(qindex + delta, 0, MAXQ)];
-    case VPX_BITS_10:
-      return ac_qlookup_10[clamp(qindex + delta, 0, MAXQ)];
-    case VPX_BITS_12:
-      return ac_qlookup_12[clamp(qindex + delta, 0, MAXQ)];
-    default:
-      assert(0 && "bit_depth should be VPX_BITS_8, VPX_BITS_10 or VPX_BITS_12");
-      return -1;
-  }
-#else
-  (void) bit_depth;
-  return ac_qlookup[clamp(qindex + delta, 0, MAXQ)];
-#endif
-}
-
-int vp9_get_qindex(const struct segmentation *seg, int segment_id,
-                   int base_qindex) {
-  if (segfeature_active(seg, segment_id, SEG_LVL_ALT_Q)) {
-    const int data = get_segdata(seg, segment_id, SEG_LVL_ALT_Q);
-    const int seg_qindex = seg->abs_delta == SEGMENT_ABSDATA ?
-        data : base_qindex + data;
-    return clamp(seg_qindex, 0, MAXQ);
-  } else {
-    return base_qindex;
-  }
-}
-
diff --git a/vp9/common/vp9_quant_common.h b/vp9/common/vp9_quant_common.h
deleted file mode 100644 (file)
index 4bae4a8..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#ifndef VP9_COMMON_VP9_QUANT_COMMON_H_
-#define VP9_COMMON_VP9_QUANT_COMMON_H_
-
-#include "vpx/vpx_codec.h"
-#include "vp9/common/vp9_seg_common.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define MINQ 0
-#define MAXQ 255
-#define QINDEX_RANGE (MAXQ - MINQ + 1)
-#define QINDEX_BITS 8
-
-int16_t vp9_dc_quant(int qindex, int delta, vpx_bit_depth_t bit_depth);
-int16_t vp9_ac_quant(int qindex, int delta, vpx_bit_depth_t bit_depth);
-
-int vp9_get_qindex(const struct segmentation *seg, int segment_id,
-                   int base_qindex);
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP9_COMMON_VP9_QUANT_COMMON_H_
diff --git a/vp9/common/vp9_reconinter.c b/vp9/common/vp9_reconinter.c
deleted file mode 100644 (file)
index 84718e9..0000000
+++ /dev/null
@@ -1,309 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#include <assert.h>
-
-#include "./vpx_scale_rtcd.h"
-#include "./vpx_config.h"
-
-#include "vpx/vpx_integer.h"
-
-#include "vp9/common/vp9_blockd.h"
-#include "vp9/common/vp9_reconinter.h"
-#include "vp9/common/vp9_reconintra.h"
-
-#if CONFIG_VP9_HIGHBITDEPTH
-void vp9_highbd_build_inter_predictor(const uint8_t *src, int src_stride,
-                                      uint8_t *dst, int dst_stride,
-                                      const MV *src_mv,
-                                      const struct scale_factors *sf,
-                                      int w, int h, int ref,
-                                      const InterpKernel *kernel,
-                                      enum mv_precision precision,
-                                      int x, int y, int bd) {
-  const int is_q4 = precision == MV_PRECISION_Q4;
-  const MV mv_q4 = { is_q4 ? src_mv->row : src_mv->row * 2,
-                     is_q4 ? src_mv->col : src_mv->col * 2 };
-  MV32 mv = vp9_scale_mv(&mv_q4, x, y, sf);
-  const int subpel_x = mv.col & SUBPEL_MASK;
-  const int subpel_y = mv.row & SUBPEL_MASK;
-
-  src += (mv.row >> SUBPEL_BITS) * src_stride + (mv.col >> SUBPEL_BITS);
-
-  highbd_inter_predictor(src, src_stride, dst, dst_stride, subpel_x, subpel_y,
-                         sf, w, h, ref, kernel, sf->x_step_q4, sf->y_step_q4,
-                         bd);
-}
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-
-void vp9_build_inter_predictor(const uint8_t *src, int src_stride,
-                               uint8_t *dst, int dst_stride,
-                               const MV *src_mv,
-                               const struct scale_factors *sf,
-                               int w, int h, int ref,
-                               const InterpKernel *kernel,
-                               enum mv_precision precision,
-                               int x, int y) {
-  const int is_q4 = precision == MV_PRECISION_Q4;
-  const MV mv_q4 = { is_q4 ? src_mv->row : src_mv->row * 2,
-                     is_q4 ? src_mv->col : src_mv->col * 2 };
-  MV32 mv = vp9_scale_mv(&mv_q4, x, y, sf);
-  const int subpel_x = mv.col & SUBPEL_MASK;
-  const int subpel_y = mv.row & SUBPEL_MASK;
-
-  src += (mv.row >> SUBPEL_BITS) * src_stride + (mv.col >> SUBPEL_BITS);
-
-  inter_predictor(src, src_stride, dst, dst_stride, subpel_x, subpel_y,
-                  sf, w, h, ref, kernel, sf->x_step_q4, sf->y_step_q4);
-}
-
-static INLINE int round_mv_comp_q4(int value) {
-  return (value < 0 ? value - 2 : value + 2) / 4;
-}
-
-static MV mi_mv_pred_q4(const MODE_INFO *mi, int idx) {
-  MV res = { round_mv_comp_q4(mi->bmi[0].as_mv[idx].as_mv.row +
-                              mi->bmi[1].as_mv[idx].as_mv.row +
-                              mi->bmi[2].as_mv[idx].as_mv.row +
-                              mi->bmi[3].as_mv[idx].as_mv.row),
-             round_mv_comp_q4(mi->bmi[0].as_mv[idx].as_mv.col +
-                              mi->bmi[1].as_mv[idx].as_mv.col +
-                              mi->bmi[2].as_mv[idx].as_mv.col +
-                              mi->bmi[3].as_mv[idx].as_mv.col) };
-  return res;
-}
-
-static INLINE int round_mv_comp_q2(int value) {
-  return (value < 0 ? value - 1 : value + 1) / 2;
-}
-
-static MV mi_mv_pred_q2(const MODE_INFO *mi, int idx, int block0, int block1) {
-  MV res = { round_mv_comp_q2(mi->bmi[block0].as_mv[idx].as_mv.row +
-                              mi->bmi[block1].as_mv[idx].as_mv.row),
-             round_mv_comp_q2(mi->bmi[block0].as_mv[idx].as_mv.col +
-                              mi->bmi[block1].as_mv[idx].as_mv.col) };
-  return res;
-}
-
-// TODO(jkoleszar): yet another mv clamping function :-(
-MV clamp_mv_to_umv_border_sb(const MACROBLOCKD *xd, const MV *src_mv,
-                             int bw, int bh, int ss_x, int ss_y) {
-  // If the MV points so far into the UMV border that no visible pixels
-  // are used for reconstruction, the subpel part of the MV can be
-  // discarded and the MV limited to 16 pixels with equivalent results.
-  const int spel_left = (VP9_INTERP_EXTEND + bw) << SUBPEL_BITS;
-  const int spel_right = spel_left - SUBPEL_SHIFTS;
-  const int spel_top = (VP9_INTERP_EXTEND + bh) << SUBPEL_BITS;
-  const int spel_bottom = spel_top - SUBPEL_SHIFTS;
-  MV clamped_mv = {
-    src_mv->row * (1 << (1 - ss_y)),
-    src_mv->col * (1 << (1 - ss_x))
-  };
-  assert(ss_x <= 1);
-  assert(ss_y <= 1);
-
-  clamp_mv(&clamped_mv,
-           xd->mb_to_left_edge * (1 << (1 - ss_x)) - spel_left,
-           xd->mb_to_right_edge * (1 << (1 - ss_x)) + spel_right,
-           xd->mb_to_top_edge * (1 << (1 - ss_y)) - spel_top,
-           xd->mb_to_bottom_edge * (1 << (1 - ss_y)) + spel_bottom);
-
-  return clamped_mv;
-}
-
-MV average_split_mvs(const struct macroblockd_plane *pd,
-                     const MODE_INFO *mi, int ref, int block) {
-  const int ss_idx = ((pd->subsampling_x > 0) << 1) | (pd->subsampling_y > 0);
-  MV res = {0, 0};
-  switch (ss_idx) {
-    case 0:
-      res = mi->bmi[block].as_mv[ref].as_mv;
-      break;
-    case 1:
-      res = mi_mv_pred_q2(mi, ref, block, block + 2);
-      break;
-    case 2:
-      res = mi_mv_pred_q2(mi, ref, block, block + 1);
-      break;
-    case 3:
-      res = mi_mv_pred_q4(mi, ref);
-      break;
-    default:
-      assert(ss_idx <= 3 && ss_idx >= 0);
-  }
-  return res;
-}
-
-static void build_inter_predictors(MACROBLOCKD *xd, int plane, int block,
-                                   int bw, int bh,
-                                   int x, int y, int w, int h,
-                                   int mi_x, int mi_y) {
-  struct macroblockd_plane *const pd = &xd->plane[plane];
-  const MODE_INFO *mi = xd->mi[0];
-  const int is_compound = has_second_ref(mi);
-  const InterpKernel *kernel = vp9_filter_kernels[mi->interp_filter];
-  int ref;
-
-  for (ref = 0; ref < 1 + is_compound; ++ref) {
-    const struct scale_factors *const sf = &xd->block_refs[ref]->sf;
-    struct buf_2d *const pre_buf = &pd->pre[ref];
-    struct buf_2d *const dst_buf = &pd->dst;
-    uint8_t *const dst = dst_buf->buf + dst_buf->stride * y + x;
-    const MV mv = mi->sb_type < BLOCK_8X8
-               ? average_split_mvs(pd, mi, ref, block)
-               : mi->mv[ref].as_mv;
-
-    // TODO(jkoleszar): This clamping is done in the incorrect place for the
-    // scaling case. It needs to be done on the scaled MV, not the pre-scaling
-    // MV. Note however that it performs the subsampling aware scaling so
-    // that the result is always q4.
-    // mv_precision precision is MV_PRECISION_Q4.
-    const MV mv_q4 = clamp_mv_to_umv_border_sb(xd, &mv, bw, bh,
-                                               pd->subsampling_x,
-                                               pd->subsampling_y);
-
-    uint8_t *pre;
-    MV32 scaled_mv;
-    int xs, ys, subpel_x, subpel_y;
-    const int is_scaled = vp9_is_scaled(sf);
-
-    if (is_scaled) {
-      // Co-ordinate of containing block to pixel precision.
-      const int x_start = (-xd->mb_to_left_edge >> (3 + pd->subsampling_x));
-      const int y_start = (-xd->mb_to_top_edge >> (3 + pd->subsampling_y));
-#if CONFIG_BETTER_HW_COMPATIBILITY
-      assert(xd->mi[0]->sb_type != BLOCK_4X8 &&
-             xd->mi[0]->sb_type != BLOCK_8X4);
-      assert(mv_q4.row == mv.row * (1 << (1 - pd->subsampling_y)) &&
-             mv_q4.col == mv.col * (1 << (1 - pd->subsampling_x)));
-#endif
-      if (plane == 0)
-        pre_buf->buf = xd->block_refs[ref]->buf->y_buffer;
-      else if (plane == 1)
-        pre_buf->buf = xd->block_refs[ref]->buf->u_buffer;
-      else
-        pre_buf->buf = xd->block_refs[ref]->buf->v_buffer;
-
-      pre_buf->buf += scaled_buffer_offset(x_start + x, y_start + y,
-                                           pre_buf->stride, sf);
-      pre = pre_buf->buf;
-      scaled_mv = vp9_scale_mv(&mv_q4, mi_x + x, mi_y + y, sf);
-      xs = sf->x_step_q4;
-      ys = sf->y_step_q4;
-    } else {
-      pre = pre_buf->buf + (y * pre_buf->stride + x);
-      scaled_mv.row = mv_q4.row;
-      scaled_mv.col = mv_q4.col;
-      xs = ys = 16;
-    }
-    subpel_x = scaled_mv.col & SUBPEL_MASK;
-    subpel_y = scaled_mv.row & SUBPEL_MASK;
-    pre += (scaled_mv.row >> SUBPEL_BITS) * pre_buf->stride
-           + (scaled_mv.col >> SUBPEL_BITS);
-
-#if CONFIG_VP9_HIGHBITDEPTH
-    if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
-      highbd_inter_predictor(pre, pre_buf->stride, dst, dst_buf->stride,
-                             subpel_x, subpel_y, sf, w, h, ref, kernel, xs, ys,
-                             xd->bd);
-    } else {
-      inter_predictor(pre, pre_buf->stride, dst, dst_buf->stride,
-                      subpel_x, subpel_y, sf, w, h, ref, kernel, xs, ys);
-    }
-#else
-    inter_predictor(pre, pre_buf->stride, dst, dst_buf->stride,
-                    subpel_x, subpel_y, sf, w, h, ref, kernel, xs, ys);
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-  }
-}
-
-static void build_inter_predictors_for_planes(MACROBLOCKD *xd, BLOCK_SIZE bsize,
-                                              int mi_row, int mi_col,
-                                              int plane_from, int plane_to) {
-  int plane;
-  const int mi_x = mi_col * MI_SIZE;
-  const int mi_y = mi_row * MI_SIZE;
-  for (plane = plane_from; plane <= plane_to; ++plane) {
-    const BLOCK_SIZE plane_bsize = get_plane_block_size(bsize,
-                                                        &xd->plane[plane]);
-    const int num_4x4_w = num_4x4_blocks_wide_lookup[plane_bsize];
-    const int num_4x4_h = num_4x4_blocks_high_lookup[plane_bsize];
-    const int bw = 4 * num_4x4_w;
-    const int bh = 4 * num_4x4_h;
-
-    if (xd->mi[0]->sb_type < BLOCK_8X8) {
-      int i = 0, x, y;
-      assert(bsize == BLOCK_8X8);
-      for (y = 0; y < num_4x4_h; ++y)
-        for (x = 0; x < num_4x4_w; ++x)
-           build_inter_predictors(xd, plane, i++, bw, bh,
-                                  4 * x, 4 * y, 4, 4, mi_x, mi_y);
-    } else {
-      build_inter_predictors(xd, plane, 0, bw, bh,
-                             0, 0, bw, bh, mi_x, mi_y);
-    }
-  }
-}
-
-void vp9_build_inter_predictors_sby(MACROBLOCKD *xd, int mi_row, int mi_col,
-                                    BLOCK_SIZE bsize) {
-  build_inter_predictors_for_planes(xd, bsize, mi_row, mi_col, 0, 0);
-}
-
-void vp9_build_inter_predictors_sbp(MACROBLOCKD *xd, int mi_row, int mi_col,
-                                    BLOCK_SIZE bsize, int plane) {
-  build_inter_predictors_for_planes(xd, bsize, mi_row, mi_col, plane, plane);
-}
-
-void vp9_build_inter_predictors_sbuv(MACROBLOCKD *xd, int mi_row, int mi_col,
-                                     BLOCK_SIZE bsize) {
-  build_inter_predictors_for_planes(xd, bsize, mi_row, mi_col, 1,
-                                    MAX_MB_PLANE - 1);
-}
-
-void vp9_build_inter_predictors_sb(MACROBLOCKD *xd, int mi_row, int mi_col,
-                                   BLOCK_SIZE bsize) {
-  build_inter_predictors_for_planes(xd, bsize, mi_row, mi_col, 0,
-                                    MAX_MB_PLANE - 1);
-}
-
-void vp9_setup_dst_planes(struct macroblockd_plane planes[MAX_MB_PLANE],
-                          const YV12_BUFFER_CONFIG *src,
-                          int mi_row, int mi_col) {
-  uint8_t *const buffers[MAX_MB_PLANE] = { src->y_buffer, src->u_buffer,
-      src->v_buffer};
-  const int strides[MAX_MB_PLANE] = { src->y_stride, src->uv_stride,
-      src->uv_stride};
-  int i;
-
-  for (i = 0; i < MAX_MB_PLANE; ++i) {
-    struct macroblockd_plane *const pd = &planes[i];
-    setup_pred_plane(&pd->dst, buffers[i], strides[i], mi_row, mi_col, NULL,
-                     pd->subsampling_x, pd->subsampling_y);
-  }
-}
-
-void vp9_setup_pre_planes(MACROBLOCKD *xd, int idx,
-                          const YV12_BUFFER_CONFIG *src,
-                          int mi_row, int mi_col,
-                          const struct scale_factors *sf) {
-  if (src != NULL) {
-    int i;
-    uint8_t *const buffers[MAX_MB_PLANE] = { src->y_buffer, src->u_buffer,
-        src->v_buffer};
-    const int strides[MAX_MB_PLANE] = { src->y_stride, src->uv_stride,
-        src->uv_stride};
-    for (i = 0; i < MAX_MB_PLANE; ++i) {
-      struct macroblockd_plane *const pd = &xd->plane[i];
-      setup_pred_plane(&pd->pre[idx], buffers[i], strides[i], mi_row, mi_col,
-                       sf, pd->subsampling_x, pd->subsampling_y);
-    }
-  }
-}
diff --git a/vp9/common/vp9_reconinter.h b/vp9/common/vp9_reconinter.h
deleted file mode 100644 (file)
index 07745e3..0000000
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#ifndef VP9_COMMON_VP9_RECONINTER_H_
-#define VP9_COMMON_VP9_RECONINTER_H_
-
-#include "vp9/common/vp9_filter.h"
-#include "vp9/common/vp9_onyxc_int.h"
-#include "vpx/vpx_integer.h"
-#include "vpx_dsp/vpx_filter.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-static INLINE void inter_predictor(const uint8_t *src, int src_stride,
-                                   uint8_t *dst, int dst_stride,
-                                   const int subpel_x,
-                                   const int subpel_y,
-                                   const struct scale_factors *sf,
-                                   int w, int h, int ref,
-                                   const InterpKernel *kernel,
-                                   int xs, int ys) {
-  sf->predict[subpel_x != 0][subpel_y != 0][ref](
-      src, src_stride, dst, dst_stride,
-      kernel[subpel_x], xs, kernel[subpel_y], ys, w, h);
-}
-
-#if CONFIG_VP9_HIGHBITDEPTH
-static INLINE void highbd_inter_predictor(const uint8_t *src, int src_stride,
-                                          uint8_t *dst, int dst_stride,
-                                          const int subpel_x,
-                                          const int subpel_y,
-                                          const struct scale_factors *sf,
-                                          int w, int h, int ref,
-                                          const InterpKernel *kernel,
-                                          int xs, int ys, int bd) {
-  sf->highbd_predict[subpel_x != 0][subpel_y != 0][ref](
-      src, src_stride, dst, dst_stride,
-      kernel[subpel_x], xs, kernel[subpel_y], ys, w, h, bd);
-}
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-
-MV average_split_mvs(const struct macroblockd_plane *pd, const MODE_INFO *mi,
-                     int ref, int block);
-
-MV clamp_mv_to_umv_border_sb(const MACROBLOCKD *xd, const MV *src_mv,
-                             int bw, int bh, int ss_x, int ss_y);
-
-void vp9_build_inter_predictors_sby(MACROBLOCKD *xd, int mi_row, int mi_col,
-                                    BLOCK_SIZE bsize);
-
-void vp9_build_inter_predictors_sbp(MACROBLOCKD *xd, int mi_row, int mi_col,
-                                    BLOCK_SIZE bsize, int plane);
-
-void vp9_build_inter_predictors_sbuv(MACROBLOCKD *xd, int mi_row, int mi_col,
-                                     BLOCK_SIZE bsize);
-
-void vp9_build_inter_predictors_sb(MACROBLOCKD *xd, int mi_row, int mi_col,
-                                   BLOCK_SIZE bsize);
-
-void vp9_build_inter_predictor(const uint8_t *src, int src_stride,
-                               uint8_t *dst, int dst_stride,
-                               const MV *mv_q3,
-                               const struct scale_factors *sf,
-                               int w, int h, int do_avg,
-                               const InterpKernel *kernel,
-                               enum mv_precision precision,
-                               int x, int y);
-
-#if CONFIG_VP9_HIGHBITDEPTH
-void vp9_highbd_build_inter_predictor(const uint8_t *src, int src_stride,
-                                      uint8_t *dst, int dst_stride,
-                                      const MV *mv_q3,
-                                      const struct scale_factors *sf,
-                                      int w, int h, int do_avg,
-                                      const InterpKernel *kernel,
-                                      enum mv_precision precision,
-                                      int x, int y, int bd);
-#endif
-
-static INLINE int scaled_buffer_offset(int x_offset, int y_offset, int stride,
-                                       const struct scale_factors *sf) {
-  const int x = sf ? sf->scale_value_x(x_offset, sf) : x_offset;
-  const int y = sf ? sf->scale_value_y(y_offset, sf) : y_offset;
-  return y * stride + x;
-}
-
-static INLINE void setup_pred_plane(struct buf_2d *dst,
-                                    uint8_t *src, int stride,
-                                    int mi_row, int mi_col,
-                                    const struct scale_factors *scale,
-                                    int subsampling_x, int subsampling_y) {
-  const int x = (MI_SIZE * mi_col) >> subsampling_x;
-  const int y = (MI_SIZE * mi_row) >> subsampling_y;
-  dst->buf = src + scaled_buffer_offset(x, y, stride, scale);
-  dst->stride = stride;
-}
-
-void vp9_setup_dst_planes(struct macroblockd_plane planes[MAX_MB_PLANE],
-                          const YV12_BUFFER_CONFIG *src,
-                          int mi_row, int mi_col);
-
-void vp9_setup_pre_planes(MACROBLOCKD *xd, int idx,
-                          const YV12_BUFFER_CONFIG *src, int mi_row, int mi_col,
-                          const struct scale_factors *sf);
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP9_COMMON_VP9_RECONINTER_H_
diff --git a/vp9/common/vp9_reconintra.c b/vp9/common/vp9_reconintra.c
deleted file mode 100644 (file)
index 4457858..0000000
+++ /dev/null
@@ -1,445 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#include "./vpx_config.h"
-#include "./vpx_dsp_rtcd.h"
-
-#if CONFIG_VP9_HIGHBITDEPTH
-#include "vpx_dsp/vpx_dsp_common.h"
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-#include "vpx_mem/vpx_mem.h"
-#include "vpx_ports/mem.h"
-#include "vpx_ports/vpx_once.h"
-
-#include "vp9/common/vp9_reconintra.h"
-#include "vp9/common/vp9_onyxc_int.h"
-
-const TX_TYPE intra_mode_to_tx_type_lookup[INTRA_MODES] = {
-  DCT_DCT,    // DC
-  ADST_DCT,   // V
-  DCT_ADST,   // H
-  DCT_DCT,    // D45
-  ADST_ADST,  // D135
-  ADST_DCT,   // D117
-  DCT_ADST,   // D153
-  DCT_ADST,   // D207
-  ADST_DCT,   // D63
-  ADST_ADST,  // TM
-};
-
-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
-};
-
-typedef void (*intra_pred_fn)(uint8_t *dst, ptrdiff_t stride,
-                              const uint8_t *above, const uint8_t *left);
-
-static intra_pred_fn pred[INTRA_MODES][TX_SIZES];
-static intra_pred_fn dc_pred[2][2][TX_SIZES];
-
-#if CONFIG_VP9_HIGHBITDEPTH
-typedef void (*intra_high_pred_fn)(uint16_t *dst, ptrdiff_t stride,
-                                   const uint16_t *above, const uint16_t *left,
-                                   int bd);
-static intra_high_pred_fn pred_high[INTRA_MODES][4];
-static intra_high_pred_fn dc_pred_high[2][2][4];
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-
-static void vp9_init_intra_predictors_internal(void) {
-#define INIT_ALL_SIZES(p, type) \
-  p[TX_4X4] = vpx_##type##_predictor_4x4; \
-  p[TX_8X8] = vpx_##type##_predictor_8x8; \
-  p[TX_16X16] = vpx_##type##_predictor_16x16; \
-  p[TX_32X32] = vpx_##type##_predictor_32x32
-
-  INIT_ALL_SIZES(pred[V_PRED], v);
-  INIT_ALL_SIZES(pred[H_PRED], h);
-  INIT_ALL_SIZES(pred[D207_PRED], d207);
-  INIT_ALL_SIZES(pred[D45_PRED], d45);
-  INIT_ALL_SIZES(pred[D63_PRED], d63);
-  INIT_ALL_SIZES(pred[D117_PRED], d117);
-  INIT_ALL_SIZES(pred[D135_PRED], d135);
-  INIT_ALL_SIZES(pred[D153_PRED], d153);
-  INIT_ALL_SIZES(pred[TM_PRED], tm);
-
-  INIT_ALL_SIZES(dc_pred[0][0], dc_128);
-  INIT_ALL_SIZES(dc_pred[0][1], dc_top);
-  INIT_ALL_SIZES(dc_pred[1][0], dc_left);
-  INIT_ALL_SIZES(dc_pred[1][1], dc);
-
-#if CONFIG_VP9_HIGHBITDEPTH
-  INIT_ALL_SIZES(pred_high[V_PRED], highbd_v);
-  INIT_ALL_SIZES(pred_high[H_PRED], highbd_h);
-  INIT_ALL_SIZES(pred_high[D207_PRED], highbd_d207);
-  INIT_ALL_SIZES(pred_high[D45_PRED], highbd_d45);
-  INIT_ALL_SIZES(pred_high[D63_PRED], highbd_d63);
-  INIT_ALL_SIZES(pred_high[D117_PRED], highbd_d117);
-  INIT_ALL_SIZES(pred_high[D135_PRED], highbd_d135);
-  INIT_ALL_SIZES(pred_high[D153_PRED], highbd_d153);
-  INIT_ALL_SIZES(pred_high[TM_PRED], highbd_tm);
-
-  INIT_ALL_SIZES(dc_pred_high[0][0], highbd_dc_128);
-  INIT_ALL_SIZES(dc_pred_high[0][1], highbd_dc_top);
-  INIT_ALL_SIZES(dc_pred_high[1][0], highbd_dc_left);
-  INIT_ALL_SIZES(dc_pred_high[1][1], highbd_dc);
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-
-#undef intra_pred_allsizes
-}
-
-#if CONFIG_VP9_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,
-                                        int up_available,
-                                        int left_available,
-                                        int right_available,
-                                        int x, int y,
-                                        int plane, int bd) {
-  int i;
-  uint16_t *dst = CONVERT_TO_SHORTPTR(dst8);
-  uint16_t *ref = CONVERT_TO_SHORTPTR(ref8);
-  DECLARE_ALIGNED(16, uint16_t, left_col[32]);
-  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;
-  int frame_width, frame_height;
-  int x0, y0;
-  const struct macroblockd_plane *const pd = &xd->plane[plane];
-  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
-  // For 10 bit and 12 bit, 127 and 129 are replaced by base -1 and base + 1.
-
-  // 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 {
-      vpx_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]));
-          vpx_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 {
-      vpx_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]));
-            vpx_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]));
-            vpx_memset16(above_row + r, above_row[r - 1],
-                         x0 + 2 * bs - frame_width);
-          } else {
-            memcpy(above_row, above_ref, bs * sizeof(above_row[0]));
-            vpx_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]));
-          vpx_memset16(above_row + r, above_row[r - 1],
-                       x0 + 2 * bs - frame_width);
-        }
-        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
-            vpx_memset16(above_row + bs, above_row[bs - 1], bs);
-          above_row[-1] = left_available ? above_ref[-1] : (base + 1);
-        }
-      }
-    } else {
-      vpx_memset16(above_row, base - 1, bs * 2);
-      above_row[-1] = base - 1;
-    }
-  }
-
-  // predict
-  if (mode == DC_PRED) {
-    dc_pred_high[left_available][up_available][tx_size](dst, dst_stride,
-                                                        const_above_row,
-                                                        left_col, xd->bd);
-  } else {
-    pred_high[mode][tx_size](dst, dst_stride, const_above_row, left_col,
-                             xd->bd);
-  }
-}
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-
-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,
-                                   int up_available, int left_available,
-                                   int right_available, int x, int y,
-                                   int plane) {
-  int i;
-  DECLARE_ALIGNED(16, uint8_t, left_col[32]);
-  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;
-  int frame_width, frame_height;
-  int x0, y0;
-  const struct macroblockd_plane *const pd = &xd->plane[plane];
-
-  // 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
-  // ..
-
-  // 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 (extend_modes[mode] & 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 {
-      memset(left_col, 129, bs);
-    }
-  }
-
-  // NEED_ABOVE
-  if (extend_modes[mode] & NEED_ABOVE) {
-    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;
-    }
-  }
-
-  // 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;
-    }
-  }
-
-  // predict
-  if (mode == DC_PRED) {
-    dc_pred[left_available][up_available][tx_size](dst, dst_stride,
-                                                   const_above_row, left_col);
-  } else {
-    pred[mode][tx_size](dst, dst_stride, const_above_row, left_col);
-  }
-}
-
-void vp9_predict_intra_block(const MACROBLOCKD *xd, int bwl_in,
-                             TX_SIZE tx_size, PREDICTION_MODE mode,
-                             const uint8_t *ref, int ref_stride,
-                             uint8_t *dst, int dst_stride,
-                             int aoff, int loff, int plane) {
-  const int bw = (1 << bwl_in);
-  const int txw = (1 << tx_size);
-  const int have_top = loff || (xd->above_mi != NULL);
-  const int have_left = aoff || (xd->left_mi != NULL);
-  const int have_right = (aoff + txw) < bw;
-  const int x = aoff * 4;
-  const int y = loff * 4;
-
-#if CONFIG_VP9_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);
-}
-
-void vp9_init_intra_predictors(void) {
-  once(vp9_init_intra_predictors_internal);
-}
diff --git a/vp9/common/vp9_reconintra.h b/vp9/common/vp9_reconintra.h
deleted file mode 100644 (file)
index de45380..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#ifndef VP9_COMMON_VP9_RECONINTRA_H_
-#define VP9_COMMON_VP9_RECONINTRA_H_
-
-#include "vpx/vpx_integer.h"
-#include "vp9/common/vp9_blockd.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-void vp9_init_intra_predictors(void);
-
-void vp9_predict_intra_block(const MACROBLOCKD *xd, int bwl_in,
-                             TX_SIZE tx_size, PREDICTION_MODE mode,
-                             const uint8_t *ref, int ref_stride,
-                             uint8_t *dst, int dst_stride,
-                             int aoff, int loff, int plane);
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP9_COMMON_VP9_RECONINTRA_H_
diff --git a/vp9/common/vp9_rtcd.c b/vp9/common/vp9_rtcd.c
deleted file mode 100644 (file)
index 2dfa09f..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-/*
- *  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.
- */
-#include "./vpx_config.h"
-#define RTCD_C
-#include "./vp9_rtcd.h"
-#include "vpx_ports/vpx_once.h"
-
-void vp9_rtcd() {
-    // TODO(JBB): Remove this once, by insuring that both the encoder and
-    // decoder setup functions are protected by once();
-    once(setup_rtcd_internal);
-}
diff --git a/vp9/common/vp9_rtcd_defs.pl b/vp9/common/vp9_rtcd_defs.pl
deleted file mode 100644 (file)
index f315a3b..0000000
+++ /dev/null
@@ -1,282 +0,0 @@
-sub vp9_common_forward_decls() {
-print <<EOF
-/*
- * VP9
- */
-
-#include "vpx/vpx_integer.h"
-#include "vp9/common/vp9_common.h"
-#include "vp9/common/vp9_enums.h"
-
-struct macroblockd;
-
-/* Encoder forward decls */
-struct macroblock;
-struct vp9_variance_vtable;
-struct search_site_config;
-struct mv;
-union int_mv;
-struct yv12_buffer_config;
-EOF
-}
-forward_decls qw/vp9_common_forward_decls/;
-
-# functions that are 64 bit only.
-$mmx_x86_64 = $sse2_x86_64 = $ssse3_x86_64 = $avx_x86_64 = $avx2_x86_64 = '';
-if ($opts{arch} eq "x86_64") {
-  $mmx_x86_64 = 'mmx';
-  $sse2_x86_64 = 'sse2';
-  $ssse3_x86_64 = 'ssse3';
-  $avx_x86_64 = 'avx';
-  $avx2_x86_64 = 'avx2';
-}
-
-#
-# post proc
-#
-if (vpx_config("CONFIG_VP9_POSTPROC") eq "yes") {
-add_proto qw/void vp9_filter_by_weight16x16/, "const uint8_t *src, int src_stride, uint8_t *dst, int dst_stride, int src_weight";
-specialize qw/vp9_filter_by_weight16x16 sse2 msa/;
-
-add_proto qw/void vp9_filter_by_weight8x8/, "const uint8_t *src, int src_stride, uint8_t *dst, int dst_stride, int src_weight";
-specialize qw/vp9_filter_by_weight8x8 sse2 msa/;
-}
-
-#
-# dct
-#
-if (vpx_config("CONFIG_VP9_HIGHBITDEPTH") eq "yes") {
-  # Force C versions if CONFIG_EMULATE_HARDWARE is 1
-  if (vpx_config("CONFIG_EMULATE_HARDWARE") eq "yes") {
-    add_proto qw/void vp9_iht4x4_16_add/, "const tran_low_t *input, uint8_t *dest, int dest_stride, int tx_type";
-    specialize qw/vp9_iht4x4_16_add/;
-
-    add_proto qw/void vp9_iht8x8_64_add/, "const tran_low_t *input, uint8_t *dest, int dest_stride, int tx_type";
-    specialize qw/vp9_iht8x8_64_add/;
-
-    add_proto qw/void vp9_iht16x16_256_add/, "const tran_low_t *input, uint8_t *output, int pitch, int tx_type";
-    specialize qw/vp9_iht16x16_256_add/;
-  } else {
-    add_proto qw/void vp9_iht4x4_16_add/, "const tran_low_t *input, uint8_t *dest, int dest_stride, int tx_type";
-    specialize qw/vp9_iht4x4_16_add sse2/;
-
-    add_proto qw/void vp9_iht8x8_64_add/, "const tran_low_t *input, uint8_t *dest, int dest_stride, int tx_type";
-    specialize qw/vp9_iht8x8_64_add sse2/;
-
-    add_proto qw/void vp9_iht16x16_256_add/, "const tran_low_t *input, uint8_t *output, int pitch, int tx_type";
-    specialize qw/vp9_iht16x16_256_add sse2/;
-  }
-} else {
-  # Force C versions if CONFIG_EMULATE_HARDWARE is 1
-  if (vpx_config("CONFIG_EMULATE_HARDWARE") eq "yes") {
-    add_proto qw/void vp9_iht4x4_16_add/, "const tran_low_t *input, uint8_t *dest, int dest_stride, int tx_type";
-    specialize qw/vp9_iht4x4_16_add/;
-
-    add_proto qw/void vp9_iht8x8_64_add/, "const tran_low_t *input, uint8_t *dest, int dest_stride, int tx_type";
-    specialize qw/vp9_iht8x8_64_add/;
-
-    add_proto qw/void vp9_iht16x16_256_add/, "const tran_low_t *input, uint8_t *output, int pitch, int tx_type";
-    specialize qw/vp9_iht16x16_256_add/;
-  } else {
-    add_proto qw/void vp9_iht4x4_16_add/, "const tran_low_t *input, uint8_t *dest, int dest_stride, int tx_type";
-    specialize qw/vp9_iht4x4_16_add sse2 neon dspr2 msa/;
-
-    add_proto qw/void vp9_iht8x8_64_add/, "const tran_low_t *input, uint8_t *dest, int dest_stride, int tx_type";
-    specialize qw/vp9_iht8x8_64_add sse2 neon dspr2 msa/;
-
-    add_proto qw/void vp9_iht16x16_256_add/, "const tran_low_t *input, uint8_t *output, int pitch, int tx_type";
-    specialize qw/vp9_iht16x16_256_add sse2 dspr2 msa/;
-  }
-}
-
-# High bitdepth functions
-if (vpx_config("CONFIG_VP9_HIGHBITDEPTH") eq "yes") {
-  #
-  # Sub Pixel Filters
-  #
-  add_proto qw/void vp9_highbd_convolve_copy/, "const uint8_t *src, ptrdiff_t src_stride, uint8_t *dst, ptrdiff_t dst_stride, const int16_t *filter_x, int x_step_q4, const int16_t *filter_y, int y_step_q4, int w, int h, int bps";
-  specialize qw/vp9_highbd_convolve_copy/;
-
-  add_proto qw/void vp9_highbd_convolve_avg/, "const uint8_t *src, ptrdiff_t src_stride, uint8_t *dst, ptrdiff_t dst_stride, const int16_t *filter_x, int x_step_q4, const int16_t *filter_y, int y_step_q4, int w, int h, int bps";
-  specialize qw/vp9_highbd_convolve_avg/;
-
-  add_proto qw/void vp9_highbd_convolve8/, "const uint8_t *src, ptrdiff_t src_stride, uint8_t *dst, ptrdiff_t dst_stride, const int16_t *filter_x, int x_step_q4, const int16_t *filter_y, int y_step_q4, int w, int h, int bps";
-  specialize qw/vp9_highbd_convolve8/, "$sse2_x86_64";
-
-  add_proto qw/void vp9_highbd_convolve8_horiz/, "const uint8_t *src, ptrdiff_t src_stride, uint8_t *dst, ptrdiff_t dst_stride, const int16_t *filter_x, int x_step_q4, const int16_t *filter_y, int y_step_q4, int w, int h, int bps";
-  specialize qw/vp9_highbd_convolve8_horiz/, "$sse2_x86_64";
-
-  add_proto qw/void vp9_highbd_convolve8_vert/, "const uint8_t *src, ptrdiff_t src_stride, uint8_t *dst, ptrdiff_t dst_stride, const int16_t *filter_x, int x_step_q4, const int16_t *filter_y, int y_step_q4, int w, int h, int bps";
-  specialize qw/vp9_highbd_convolve8_vert/, "$sse2_x86_64";
-
-  add_proto qw/void vp9_highbd_convolve8_avg/, "const uint8_t *src, ptrdiff_t src_stride, uint8_t *dst, ptrdiff_t dst_stride, const int16_t *filter_x, int x_step_q4, const int16_t *filter_y, int y_step_q4, int w, int h, int bps";
-  specialize qw/vp9_highbd_convolve8_avg/, "$sse2_x86_64";
-
-  add_proto qw/void vp9_highbd_convolve8_avg_horiz/, "const uint8_t *src, ptrdiff_t src_stride, uint8_t *dst, ptrdiff_t dst_stride, const int16_t *filter_x, int x_step_q4, const int16_t *filter_y, int y_step_q4, int w, int h, int bps";
-  specialize qw/vp9_highbd_convolve8_avg_horiz/, "$sse2_x86_64";
-
-  add_proto qw/void vp9_highbd_convolve8_avg_vert/, "const uint8_t *src, ptrdiff_t src_stride, uint8_t *dst, ptrdiff_t dst_stride, const int16_t *filter_x, int x_step_q4, const int16_t *filter_y, int y_step_q4, int w, int h, int bps";
-  specialize qw/vp9_highbd_convolve8_avg_vert/, "$sse2_x86_64";
-
-  #
-  # post proc
-  #
-  if (vpx_config("CONFIG_VP9_POSTPROC") eq "yes") {
-    add_proto qw/void vp9_highbd_mbpost_proc_down/, "uint16_t *dst, int pitch, int rows, int cols, int flimit";
-    specialize qw/vp9_highbd_mbpost_proc_down/;
-
-    add_proto qw/void vp9_highbd_mbpost_proc_across_ip/, "uint16_t *src, int pitch, int rows, int cols, int flimit";
-    specialize qw/vp9_highbd_mbpost_proc_across_ip/;
-
-    add_proto qw/void vp9_highbd_post_proc_down_and_across/, "const uint16_t *src_ptr, uint16_t *dst_ptr, int src_pixels_per_line, int dst_pixels_per_line, int rows, int cols, int flimit";
-    specialize qw/vp9_highbd_post_proc_down_and_across/;
-  }
-
-  #
-  # dct
-  #
-  # Note as optimized versions of these functions are added we need to add a check to ensure
-  # that when CONFIG_EMULATE_HARDWARE is on, it defaults to the C versions only.
-  add_proto qw/void vp9_highbd_iht4x4_16_add/, "const tran_low_t *input, uint8_t *dest, int dest_stride, int tx_type, int bd";
-  specialize qw/vp9_highbd_iht4x4_16_add/;
-
-  add_proto qw/void vp9_highbd_iht8x8_64_add/, "const tran_low_t *input, uint8_t *dest, int dest_stride, int tx_type, int bd";
-  specialize qw/vp9_highbd_iht8x8_64_add/;
-
-  add_proto qw/void vp9_highbd_iht16x16_256_add/, "const tran_low_t *input, uint8_t *output, int pitch, int tx_type, int bd";
-  specialize qw/vp9_highbd_iht16x16_256_add/;
-}
-
-#
-# Encoder functions below this point.
-#
-if (vpx_config("CONFIG_VP9_ENCODER") eq "yes") {
-
-# ENCODEMB INVOKE
-
-#
-# Denoiser
-#
-if (vpx_config("CONFIG_VP9_TEMPORAL_DENOISING") eq "yes") {
-  add_proto qw/int vp9_denoiser_filter/, "const uint8_t *sig, int sig_stride, const uint8_t *mc_avg, int mc_avg_stride, uint8_t *avg, int avg_stride, int increase_denoising, BLOCK_SIZE bs, int motion_magnitude";
-  specialize qw/vp9_denoiser_filter sse2/;
-}
-
-if (vpx_config("CONFIG_VP9_HIGHBITDEPTH") eq "yes") {
-  add_proto qw/int64_t vp9_block_error/, "const tran_low_t *coeff, const tran_low_t *dqcoeff, intptr_t block_size, int64_t *ssz";
-  specialize qw/vp9_block_error/;
-
-  add_proto qw/int64_t vp9_highbd_block_error/, "const tran_low_t *coeff, const tran_low_t *dqcoeff, intptr_t block_size, int64_t *ssz, int bd";
-  specialize qw/vp9_highbd_block_error sse2/;
-
-  add_proto qw/int64_t vp9_highbd_block_error_8bit/, "const tran_low_t *coeff, const tran_low_t *dqcoeff, intptr_t block_size, int64_t *ssz";
-  specialize qw/vp9_highbd_block_error_8bit sse2 avx/;
-
-  add_proto qw/void vp9_quantize_fp/, "const tran_low_t *coeff_ptr, intptr_t n_coeffs, int skip_block, const int16_t *zbin_ptr, const int16_t *round_ptr, const int16_t *quant_ptr, const int16_t *quant_shift_ptr, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const int16_t *scan, const int16_t *iscan";
-  specialize qw/vp9_quantize_fp/;
-
-  add_proto qw/void vp9_quantize_fp_32x32/, "const tran_low_t *coeff_ptr, intptr_t n_coeffs, int skip_block, const int16_t *zbin_ptr, const int16_t *round_ptr, const int16_t *quant_ptr, const int16_t *quant_shift_ptr, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const int16_t *scan, const int16_t *iscan";
-  specialize qw/vp9_quantize_fp_32x32/;
-
-  add_proto qw/void vp9_fdct8x8_quant/, "const int16_t *input, int stride, tran_low_t *coeff_ptr, intptr_t n_coeffs, int skip_block, const int16_t *zbin_ptr, const int16_t *round_ptr, const int16_t *quant_ptr, const int16_t *quant_shift_ptr, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const int16_t *scan, const int16_t *iscan";
-  specialize qw/vp9_fdct8x8_quant/;
-} else {
-  add_proto qw/int64_t vp9_block_error/, "const tran_low_t *coeff, const tran_low_t *dqcoeff, intptr_t block_size, int64_t *ssz";
-  specialize qw/vp9_block_error avx2 msa sse2/;
-
-  add_proto qw/int64_t vp9_block_error_fp/, "const int16_t *coeff, const int16_t *dqcoeff, int block_size";
-  specialize qw/vp9_block_error_fp neon sse2/;
-
-  add_proto qw/void vp9_quantize_fp/, "const tran_low_t *coeff_ptr, intptr_t n_coeffs, int skip_block, const int16_t *zbin_ptr, const int16_t *round_ptr, const int16_t *quant_ptr, const int16_t *quant_shift_ptr, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const int16_t *scan, const int16_t *iscan";
-  specialize qw/vp9_quantize_fp neon sse2/, "$ssse3_x86_64";
-
-  add_proto qw/void vp9_quantize_fp_32x32/, "const tran_low_t *coeff_ptr, intptr_t n_coeffs, int skip_block, const int16_t *zbin_ptr, const int16_t *round_ptr, const int16_t *quant_ptr, const int16_t *quant_shift_ptr, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const int16_t *scan, const int16_t *iscan";
-  specialize qw/vp9_quantize_fp_32x32/, "$ssse3_x86_64";
-
-  add_proto qw/void vp9_fdct8x8_quant/, "const int16_t *input, int stride, tran_low_t *coeff_ptr, intptr_t n_coeffs, int skip_block, const int16_t *zbin_ptr, const int16_t *round_ptr, const int16_t *quant_ptr, const int16_t *quant_shift_ptr, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const int16_t *scan, const int16_t *iscan";
-  specialize qw/vp9_fdct8x8_quant sse2 ssse3 neon/;
-}
-
-# fdct functions
-
-if (vpx_config("CONFIG_VP9_HIGHBITDEPTH") eq "yes") {
-  add_proto qw/void vp9_fht4x4/, "const int16_t *input, tran_low_t *output, int stride, int tx_type";
-  specialize qw/vp9_fht4x4 sse2/;
-
-  add_proto qw/void vp9_fht8x8/, "const int16_t *input, tran_low_t *output, int stride, int tx_type";
-  specialize qw/vp9_fht8x8 sse2/;
-
-  add_proto qw/void vp9_fht16x16/, "const int16_t *input, tran_low_t *output, int stride, int tx_type";
-  specialize qw/vp9_fht16x16 sse2/;
-
-  add_proto qw/void vp9_fwht4x4/, "const int16_t *input, tran_low_t *output, int stride";
-  specialize qw/vp9_fwht4x4 sse2/;
-} else {
-  add_proto qw/void vp9_fht4x4/, "const int16_t *input, tran_low_t *output, int stride, int tx_type";
-  specialize qw/vp9_fht4x4 sse2 msa/;
-
-  add_proto qw/void vp9_fht8x8/, "const int16_t *input, tran_low_t *output, int stride, int tx_type";
-  specialize qw/vp9_fht8x8 sse2 msa/;
-
-  add_proto qw/void vp9_fht16x16/, "const int16_t *input, tran_low_t *output, int stride, int tx_type";
-  specialize qw/vp9_fht16x16 sse2 msa/;
-
-  add_proto qw/void vp9_fwht4x4/, "const int16_t *input, tran_low_t *output, int stride";
-  specialize qw/vp9_fwht4x4 msa sse2/;
-}
-
-#
-# Motion search
-#
-add_proto qw/int vp9_full_search_sad/, "const struct macroblock *x, const struct mv *ref_mv, int sad_per_bit, int distance, const struct vp9_variance_vtable *fn_ptr, const struct mv *center_mv, struct mv *best_mv";
-specialize qw/vp9_full_search_sad sse3 sse4_1/;
-$vp9_full_search_sad_sse3=vp9_full_search_sadx3;
-$vp9_full_search_sad_sse4_1=vp9_full_search_sadx8;
-
-add_proto qw/int vp9_diamond_search_sad/, "const struct macroblock *x, const struct search_site_config *cfg,  struct mv *ref_mv, struct mv *best_mv, int search_param, int sad_per_bit, int *num00, const struct vp9_variance_vtable *fn_ptr, const struct mv *center_mv";
-specialize qw/vp9_diamond_search_sad avx/;
-
-add_proto qw/void vp9_temporal_filter_apply/, "uint8_t *frame1, unsigned int stride, uint8_t *frame2, unsigned int block_width, unsigned int block_height, int strength, int filter_weight, unsigned int *accumulator, uint16_t *count";
-specialize qw/vp9_temporal_filter_apply sse2 msa/;
-
-if (vpx_config("CONFIG_VP9_HIGHBITDEPTH") eq "yes") {
-
-  # ENCODEMB INVOKE
-
-  add_proto qw/void vp9_highbd_quantize_fp/, "const tran_low_t *coeff_ptr, intptr_t n_coeffs, int skip_block, const int16_t *zbin_ptr, const int16_t *round_ptr, const int16_t *quant_ptr, const int16_t *quant_shift_ptr, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const int16_t *scan, const int16_t *iscan";
-  specialize qw/vp9_highbd_quantize_fp/;
-
-  add_proto qw/void vp9_highbd_quantize_fp_32x32/, "const tran_low_t *coeff_ptr, intptr_t n_coeffs, int skip_block, const int16_t *zbin_ptr, const int16_t *round_ptr, const int16_t *quant_ptr, const int16_t *quant_shift_ptr, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const int16_t *scan, const int16_t *iscan";
-  specialize qw/vp9_highbd_quantize_fp_32x32/;
-
-  # fdct functions
-  add_proto qw/void vp9_highbd_fht4x4/, "const int16_t *input, tran_low_t *output, int stride, int tx_type";
-  specialize qw/vp9_highbd_fht4x4/;
-
-  add_proto qw/void vp9_highbd_fht8x8/, "const int16_t *input, tran_low_t *output, int stride, int tx_type";
-  specialize qw/vp9_highbd_fht8x8/;
-
-  add_proto qw/void vp9_highbd_fht16x16/, "const int16_t *input, tran_low_t *output, int stride, int tx_type";
-  specialize qw/vp9_highbd_fht16x16/;
-
-  add_proto qw/void vp9_highbd_fwht4x4/, "const int16_t *input, tran_low_t *output, int stride";
-  specialize qw/vp9_highbd_fwht4x4/;
-
-  add_proto qw/void vp9_highbd_temporal_filter_apply/, "uint8_t *frame1, unsigned int stride, uint8_t *frame2, unsigned int block_width, unsigned int block_height, int strength, int filter_weight, unsigned int *accumulator, uint16_t *count";
-  specialize qw/vp9_highbd_temporal_filter_apply/;
-
-}
-# End vp9_high encoder functions
-
-#
-# frame based scale
-#
-if (vpx_config("CONFIG_VP9_HIGHBITDEPTH") eq "yes") {
-} else {
-  add_proto qw/void vp9_scale_and_extend_frame/, "const struct yv12_buffer_config *src, struct yv12_buffer_config *dst";
-  specialize qw/vp9_scale_and_extend_frame ssse3/;
-}
-
-}
-# end encoder functions
-1;
diff --git a/vp9/common/vp9_scale.c b/vp9/common/vp9_scale.c
deleted file mode 100644 (file)
index b763b92..0000000
+++ /dev/null
@@ -1,175 +0,0 @@
-/*
- *  Copyright (c) 2013 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.
- */
-
-#include "./vpx_dsp_rtcd.h"
-#include "vp9/common/vp9_filter.h"
-#include "vp9/common/vp9_scale.h"
-#include "vpx_dsp/vpx_filter.h"
-
-static INLINE int scaled_x(int val, const struct scale_factors *sf) {
-  return (int)((int64_t)val * sf->x_scale_fp >> REF_SCALE_SHIFT);
-}
-
-static INLINE int scaled_y(int val, const struct scale_factors *sf) {
-  return (int)((int64_t)val * sf->y_scale_fp >> REF_SCALE_SHIFT);
-}
-
-static int unscaled_value(int val, const struct scale_factors *sf) {
-  (void) sf;
-  return val;
-}
-
-static int get_fixed_point_scale_factor(int other_size, int this_size) {
-  // Calculate scaling factor once for each reference frame
-  // and use fixed point scaling factors in decoding and encoding routines.
-  // Hardware implementations can calculate scale factor in device driver
-  // and use multiplication and shifting on hardware instead of division.
-  return (other_size << REF_SCALE_SHIFT) / this_size;
-}
-
-MV32 vp9_scale_mv(const MV *mv, int x, int y, const struct scale_factors *sf) {
-  const int x_off_q4 = scaled_x(x << SUBPEL_BITS, sf) & SUBPEL_MASK;
-  const int y_off_q4 = scaled_y(y << SUBPEL_BITS, sf) & SUBPEL_MASK;
-  const MV32 res = {
-    scaled_y(mv->row, sf) + y_off_q4,
-    scaled_x(mv->col, sf) + x_off_q4
-  };
-  return res;
-}
-
-#if CONFIG_VP9_HIGHBITDEPTH
-void vp9_setup_scale_factors_for_frame(struct scale_factors *sf,
-                                       int other_w, int other_h,
-                                       int this_w, int this_h,
-                                       int use_highbd) {
-#else
-void vp9_setup_scale_factors_for_frame(struct scale_factors *sf,
-                                       int other_w, int other_h,
-                                       int this_w, int this_h) {
-#endif
-  if (!valid_ref_frame_size(other_w, other_h, this_w, this_h)) {
-    sf->x_scale_fp = REF_INVALID_SCALE;
-    sf->y_scale_fp = REF_INVALID_SCALE;
-    return;
-  }
-
-  sf->x_scale_fp = get_fixed_point_scale_factor(other_w, this_w);
-  sf->y_scale_fp = get_fixed_point_scale_factor(other_h, this_h);
-  sf->x_step_q4 = scaled_x(16, sf);
-  sf->y_step_q4 = scaled_y(16, sf);
-
-  if (vp9_is_scaled(sf)) {
-    sf->scale_value_x = scaled_x;
-    sf->scale_value_y = scaled_y;
-  } else {
-    sf->scale_value_x = unscaled_value;
-    sf->scale_value_y = unscaled_value;
-  }
-
-  // TODO(agrange): Investigate the best choice of functions to use here
-  // for EIGHTTAP_SMOOTH. Since it is not interpolating, need to choose what
-  // to do at full-pel offsets. The current selection, where the filter is
-  // applied in one direction only, and not at all for 0,0, seems to give the
-  // best quality, but it may be worth trying an additional mode that does
-  // do the filtering on full-pel.
-
-  if (sf->x_step_q4 == 16) {
-    if (sf->y_step_q4 == 16) {
-      // No scaling in either direction.
-      sf->predict[0][0][0] = vpx_convolve_copy;
-      sf->predict[0][0][1] = vpx_convolve_avg;
-      sf->predict[0][1][0] = vpx_convolve8_vert;
-      sf->predict[0][1][1] = vpx_convolve8_avg_vert;
-      sf->predict[1][0][0] = vpx_convolve8_horiz;
-      sf->predict[1][0][1] = vpx_convolve8_avg_horiz;
-    } else {
-      // No scaling in x direction. Must always scale in the y direction.
-      sf->predict[0][0][0] = vpx_scaled_vert;
-      sf->predict[0][0][1] = vpx_scaled_avg_vert;
-      sf->predict[0][1][0] = vpx_scaled_vert;
-      sf->predict[0][1][1] = vpx_scaled_avg_vert;
-      sf->predict[1][0][0] = vpx_scaled_2d;
-      sf->predict[1][0][1] = vpx_scaled_avg_2d;
-    }
-  } else {
-    if (sf->y_step_q4 == 16) {
-      // No scaling in the y direction. Must always scale in the x direction.
-      sf->predict[0][0][0] = vpx_scaled_horiz;
-      sf->predict[0][0][1] = vpx_scaled_avg_horiz;
-      sf->predict[0][1][0] = vpx_scaled_2d;
-      sf->predict[0][1][1] = vpx_scaled_avg_2d;
-      sf->predict[1][0][0] = vpx_scaled_horiz;
-      sf->predict[1][0][1] = vpx_scaled_avg_horiz;
-    } else {
-      // Must always scale in both directions.
-      sf->predict[0][0][0] = vpx_scaled_2d;
-      sf->predict[0][0][1] = vpx_scaled_avg_2d;
-      sf->predict[0][1][0] = vpx_scaled_2d;
-      sf->predict[0][1][1] = vpx_scaled_avg_2d;
-      sf->predict[1][0][0] = vpx_scaled_2d;
-      sf->predict[1][0][1] = vpx_scaled_avg_2d;
-    }
-  }
-
-  // 2D subpel motion always gets filtered in both directions
-
-  if ((sf->x_step_q4 != 16) || (sf->y_step_q4 != 16)) {
-    sf->predict[1][1][0] = vpx_scaled_2d;
-    sf->predict[1][1][1] = vpx_scaled_avg_2d;
-  } else {
-    sf->predict[1][1][0] = vpx_convolve8;
-    sf->predict[1][1][1] = vpx_convolve8_avg;
-  }
-
-#if CONFIG_VP9_HIGHBITDEPTH
-  if (use_highbd) {
-    if (sf->x_step_q4 == 16) {
-      if (sf->y_step_q4 == 16) {
-        // No scaling in either direction.
-        sf->highbd_predict[0][0][0] = vpx_highbd_convolve_copy;
-        sf->highbd_predict[0][0][1] = vpx_highbd_convolve_avg;
-        sf->highbd_predict[0][1][0] = vpx_highbd_convolve8_vert;
-        sf->highbd_predict[0][1][1] = vpx_highbd_convolve8_avg_vert;
-        sf->highbd_predict[1][0][0] = vpx_highbd_convolve8_horiz;
-        sf->highbd_predict[1][0][1] = vpx_highbd_convolve8_avg_horiz;
-      } else {
-        // No scaling in x direction. Must always scale in the y direction.
-        sf->highbd_predict[0][0][0] = vpx_highbd_convolve8_vert;
-        sf->highbd_predict[0][0][1] = vpx_highbd_convolve8_avg_vert;
-        sf->highbd_predict[0][1][0] = vpx_highbd_convolve8_vert;
-        sf->highbd_predict[0][1][1] = vpx_highbd_convolve8_avg_vert;
-        sf->highbd_predict[1][0][0] = vpx_highbd_convolve8;
-        sf->highbd_predict[1][0][1] = vpx_highbd_convolve8_avg;
-      }
-    } else {
-      if (sf->y_step_q4 == 16) {
-        // No scaling in the y direction. Must always scale in the x direction.
-        sf->highbd_predict[0][0][0] = vpx_highbd_convolve8_horiz;
-        sf->highbd_predict[0][0][1] = vpx_highbd_convolve8_avg_horiz;
-        sf->highbd_predict[0][1][0] = vpx_highbd_convolve8;
-        sf->highbd_predict[0][1][1] = vpx_highbd_convolve8_avg;
-        sf->highbd_predict[1][0][0] = vpx_highbd_convolve8_horiz;
-        sf->highbd_predict[1][0][1] = vpx_highbd_convolve8_avg_horiz;
-      } else {
-        // Must always scale in both directions.
-        sf->highbd_predict[0][0][0] = vpx_highbd_convolve8;
-        sf->highbd_predict[0][0][1] = vpx_highbd_convolve8_avg;
-        sf->highbd_predict[0][1][0] = vpx_highbd_convolve8;
-        sf->highbd_predict[0][1][1] = vpx_highbd_convolve8_avg;
-        sf->highbd_predict[1][0][0] = vpx_highbd_convolve8;
-        sf->highbd_predict[1][0][1] = vpx_highbd_convolve8_avg;
-      }
-    }
-    // 2D subpel motion always gets filtered in both directions.
-    sf->highbd_predict[1][1][0] = vpx_highbd_convolve8;
-    sf->highbd_predict[1][1][1] = vpx_highbd_convolve8_avg;
-  }
-#endif
-}
diff --git a/vp9/common/vp9_scale.h b/vp9/common/vp9_scale.h
deleted file mode 100644 (file)
index 5e91041..0000000
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- *  Copyright (c) 2013 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.
- */
-
-#ifndef VP9_COMMON_VP9_SCALE_H_
-#define VP9_COMMON_VP9_SCALE_H_
-
-#include "vp9/common/vp9_mv.h"
-#include "vpx_dsp/vpx_convolve.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define REF_SCALE_SHIFT 14
-#define REF_NO_SCALE (1 << REF_SCALE_SHIFT)
-#define REF_INVALID_SCALE -1
-
-struct scale_factors {
-  int x_scale_fp;   // horizontal fixed point scale factor
-  int y_scale_fp;   // vertical fixed point scale factor
-  int x_step_q4;
-  int y_step_q4;
-
-  int (*scale_value_x)(int val, const struct scale_factors *sf);
-  int (*scale_value_y)(int val, const struct scale_factors *sf);
-
-  convolve_fn_t predict[2][2][2];  // horiz, vert, avg
-#if CONFIG_VP9_HIGHBITDEPTH
-  highbd_convolve_fn_t highbd_predict[2][2][2];  // horiz, vert, avg
-#endif
-};
-
-MV32 vp9_scale_mv(const MV *mv, int x, int y, const struct scale_factors *sf);
-
-#if CONFIG_VP9_HIGHBITDEPTH
-void vp9_setup_scale_factors_for_frame(struct scale_factors *sf,
-                                       int other_w, int other_h,
-                                       int this_w, int this_h,
-                                       int use_high);
-#else
-void vp9_setup_scale_factors_for_frame(struct scale_factors *sf,
-                                       int other_w, int other_h,
-                                       int this_w, int this_h);
-#endif
-
-static INLINE int vp9_is_valid_scale(const struct scale_factors *sf) {
-  return sf->x_scale_fp != REF_INVALID_SCALE &&
-         sf->y_scale_fp != REF_INVALID_SCALE;
-}
-
-static INLINE int vp9_is_scaled(const struct scale_factors *sf) {
-  return vp9_is_valid_scale(sf) &&
-         (sf->x_scale_fp != REF_NO_SCALE || sf->y_scale_fp != REF_NO_SCALE);
-}
-
-static INLINE int valid_ref_frame_size(int ref_width, int ref_height,
-                                      int this_width, int this_height) {
-  return 2 * this_width >= ref_width &&
-         2 * this_height >= ref_height &&
-         this_width <= 16 * ref_width &&
-         this_height <= 16 * ref_height;
-}
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP9_COMMON_VP9_SCALE_H_
diff --git a/vp9/common/vp9_scan.c b/vp9/common/vp9_scan.c
deleted file mode 100644 (file)
index 8b8b09f..0000000
+++ /dev/null
@@ -1,725 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#include <assert.h>
-
-#include "vp9/common/vp9_scan.h"
-
-DECLARE_ALIGNED(16, static const int16_t, default_scan_4x4[16]) = {
-  0,  4,  1,  5,
-  8,  2, 12,  9,
-  3,  6, 13, 10,
-  7, 14, 11, 15,
-};
-
-DECLARE_ALIGNED(16, static const int16_t, col_scan_4x4[16]) = {
-  0,  4,  8,  1,
-  12,  5,  9,  2,
-  13,  6, 10,  3,
-  7, 14, 11, 15,
-};
-
-DECLARE_ALIGNED(16, static const int16_t, row_scan_4x4[16]) = {
-  0,  1,  4,  2,
-  5,  3,  6,  8,
-  9,  7, 12, 10,
-  13, 11, 14, 15,
-};
-
-DECLARE_ALIGNED(16, static const int16_t, default_scan_8x8[64]) = {
-  0,  8,  1, 16,  9,  2, 17, 24,
-  10,  3, 18, 25, 32, 11,  4, 26,
-  33, 19, 40, 12, 34, 27,  5, 41,
-  20, 48, 13, 35, 42, 28, 21,  6,
-  49, 56, 36, 43, 29,  7, 14, 50,
-  57, 44, 22, 37, 15, 51, 58, 30,
-  45, 23, 52, 59, 38, 31, 60, 53,
-  46, 39, 61, 54, 47, 62, 55, 63,
-};
-
-DECLARE_ALIGNED(16, static const int16_t, col_scan_8x8[64]) = {
-  0,  8, 16,  1, 24,  9, 32, 17,
-  2, 40, 25, 10, 33, 18, 48,  3,
-  26, 41, 11, 56, 19, 34,  4, 49,
-  27, 42, 12, 35, 20, 57, 50, 28,
-  5, 43, 13, 36, 58, 51, 21, 44,
-  6, 29, 59, 37, 14, 52, 22,  7,
-  45, 60, 30, 15, 38, 53, 23, 46,
-  31, 61, 39, 54, 47, 62, 55, 63,
-};
-
-DECLARE_ALIGNED(16, static const int16_t, row_scan_8x8[64]) = {
-  0,  1,  2,  8,  9,  3, 16, 10,
-  4, 17, 11, 24,  5, 18, 25, 12,
-  19, 26, 32,  6, 13, 20, 33, 27,
-  7, 34, 40, 21, 28, 41, 14, 35,
-  48, 42, 29, 36, 49, 22, 43, 15,
-  56, 37, 50, 44, 30, 57, 23, 51,
-  58, 45, 38, 52, 31, 59, 53, 46,
-  60, 39, 61, 47, 54, 55, 62, 63,
-};
-
-DECLARE_ALIGNED(16, static const int16_t, default_scan_16x16[256]) = {
-  0, 16, 1, 32, 17, 2, 48, 33, 18, 3, 64, 34, 49, 19, 65, 80,
-  50, 4, 35, 66, 20, 81, 96, 51, 5, 36, 82, 97, 67, 112, 21, 52,
-  98, 37, 83, 113, 6, 68, 128, 53, 22, 99, 114, 84, 7, 129, 38, 69,
-  100, 115, 144, 130, 85, 54, 23, 8, 145, 39, 70, 116, 101, 131, 160, 146,
-  55, 86, 24, 71, 132, 117, 161, 40, 9, 102, 147, 176, 162, 87, 56, 25,
-  133, 118, 177, 148, 72, 103, 41, 163, 10, 192, 178, 88, 57, 134, 149, 119,
-  26, 164, 73, 104, 193, 42, 179, 208, 11, 135, 89, 165, 120, 150, 58, 194,
-  180, 27, 74, 209, 105, 151, 136, 43, 90, 224, 166, 195, 181, 121, 210, 59,
-  12, 152, 106, 167, 196, 75, 137, 225, 211, 240, 182, 122, 91, 28, 197, 13,
-  226, 168, 183, 153, 44, 212, 138, 107, 241, 60, 29, 123, 198, 184, 227, 169,
-  242, 76, 213, 154, 45, 92, 14, 199, 139, 61, 228, 214, 170, 185, 243, 108,
-  77, 155, 30, 15, 200, 229, 124, 215, 244, 93, 46, 186, 171, 201, 109, 140,
-  230, 62, 216, 245, 31, 125, 78, 156, 231, 47, 187, 202, 217, 94, 246, 141,
-  63, 232, 172, 110, 247, 157, 79, 218, 203, 126, 233, 188, 248, 95, 173, 142,
-  219, 111, 249, 234, 158, 127, 189, 204, 250, 235, 143, 174, 220, 205, 159,
-  251,
-  190, 221, 175, 236, 237, 191, 206, 252, 222, 253, 207, 238, 223, 254, 239,
-  255,
-};
-
-DECLARE_ALIGNED(16, static const int16_t, col_scan_16x16[256]) = {
-  0, 16, 32, 48, 1, 64, 17, 80, 33, 96, 49, 2, 65, 112, 18, 81,
-  34, 128, 50, 97, 3, 66, 144, 19, 113, 35, 82, 160, 98, 51, 129, 4,
-  67, 176, 20, 114, 145, 83, 36, 99, 130, 52, 192, 5, 161, 68, 115, 21,
-  146, 84, 208, 177, 37, 131, 100, 53, 162, 224, 69, 6, 116, 193, 147, 85,
-  22, 240, 132, 38, 178, 101, 163, 54, 209, 117, 70, 7, 148, 194, 86, 179,
-  225, 23, 133, 39, 164, 8, 102, 210, 241, 55, 195, 118, 149, 71, 180, 24,
-  87, 226, 134, 165, 211, 40, 103, 56, 72, 150, 196, 242, 119, 9, 181, 227,
-  88, 166, 25, 135, 41, 104, 212, 57, 151, 197, 120, 73, 243, 182, 136, 167,
-  213, 89, 10, 228, 105, 152, 198, 26, 42, 121, 183, 244, 168, 58, 137, 229,
-  74, 214, 90, 153, 199, 184, 11, 106, 245, 27, 122, 230, 169, 43, 215, 59,
-  200, 138, 185, 246, 75, 12, 91, 154, 216, 231, 107, 28, 44, 201, 123, 170,
-  60, 247, 232, 76, 139, 13, 92, 217, 186, 248, 155, 108, 29, 124, 45, 202,
-  233, 171, 61, 14, 77, 140, 15, 249, 93, 30, 187, 156, 218, 46, 109, 125,
-  62, 172, 78, 203, 31, 141, 234, 94, 47, 188, 63, 157, 110, 250, 219, 79,
-  126, 204, 173, 142, 95, 189, 111, 235, 158, 220, 251, 127, 174, 143, 205,
-  236,
-  159, 190, 221, 252, 175, 206, 237, 191, 253, 222, 238, 207, 254, 223, 239,
-  255,
-};
-
-DECLARE_ALIGNED(16, static const int16_t, row_scan_16x16[256]) = {
-  0, 1, 2, 16, 3, 17, 4, 18, 32, 5, 33, 19, 6, 34, 48, 20,
-  49, 7, 35, 21, 50, 64, 8, 36, 65, 22, 51, 37, 80, 9, 66, 52,
-  23, 38, 81, 67, 10, 53, 24, 82, 68, 96, 39, 11, 54, 83, 97, 69,
-  25, 98, 84, 40, 112, 55, 12, 70, 99, 113, 85, 26, 41, 56, 114, 100,
-  13, 71, 128, 86, 27, 115, 101, 129, 42, 57, 72, 116, 14, 87, 130, 102,
-  144, 73, 131, 117, 28, 58, 15, 88, 43, 145, 103, 132, 146, 118, 74, 160,
-  89, 133, 104, 29, 59, 147, 119, 44, 161, 148, 90, 105, 134, 162, 120, 176,
-  75, 135, 149, 30, 60, 163, 177, 45, 121, 91, 106, 164, 178, 150, 192, 136,
-  165, 179, 31, 151, 193, 76, 122, 61, 137, 194, 107, 152, 180, 208, 46, 166,
-  167, 195, 92, 181, 138, 209, 123, 153, 224, 196, 77, 168, 210, 182, 240, 108,
-  197, 62, 154, 225, 183, 169, 211, 47, 139, 93, 184, 226, 212, 241, 198, 170,
-  124, 155, 199, 78, 213, 185, 109, 227, 200, 63, 228, 242, 140, 214, 171, 186,
-  156, 229, 243, 125, 94, 201, 244, 215, 216, 230, 141, 187, 202, 79, 172, 110,
-  157, 245, 217, 231, 95, 246, 232, 126, 203, 247, 233, 173, 218, 142, 111,
-  158,
-  188, 248, 127, 234, 219, 249, 189, 204, 143, 174, 159, 250, 235, 205, 220,
-  175,
-  190, 251, 221, 191, 206, 236, 207, 237, 252, 222, 253, 223, 238, 239, 254,
-  255,
-};
-
-DECLARE_ALIGNED(16, static const int16_t, default_scan_32x32[1024]) = {
-  0, 32, 1, 64, 33, 2, 96, 65, 34, 128, 3, 97, 66, 160,
-  129, 35, 98, 4, 67, 130, 161, 192, 36, 99, 224, 5, 162, 193,
-  68, 131, 37, 100,
-  225, 194, 256, 163, 69, 132, 6, 226, 257, 288, 195, 101, 164, 38,
-  258, 7, 227, 289, 133, 320, 70, 196, 165, 290, 259, 228, 39, 321,
-  102, 352, 8, 197,
-  71, 134, 322, 291, 260, 353, 384, 229, 166, 103, 40, 354, 323, 292,
-  135, 385, 198, 261, 72, 9, 416, 167, 386, 355, 230, 324, 104, 293,
-  41, 417, 199, 136,
-  262, 387, 448, 325, 356, 10, 73, 418, 231, 168, 449, 294, 388, 105,
-  419, 263, 42, 200, 357, 450, 137, 480, 74, 326, 232, 11, 389, 169,
-  295, 420, 106, 451,
-  481, 358, 264, 327, 201, 43, 138, 512, 482, 390, 296, 233, 170, 421,
-  75, 452, 359, 12, 513, 265, 483, 328, 107, 202, 514, 544, 422, 391,
-  453, 139, 44, 234,
-  484, 297, 360, 171, 76, 515, 545, 266, 329, 454, 13, 423, 203, 108,
-  546, 485, 576, 298, 235, 140, 361, 330, 172, 547, 45, 455, 267, 577,
-  486, 77, 204, 362,
-  608, 14, 299, 578, 109, 236, 487, 609, 331, 141, 579, 46, 15, 173,
-  610, 363, 78, 205, 16, 110, 237, 611, 142, 47, 174, 79, 206, 17,
-  111, 238, 48, 143,
-  80, 175, 112, 207, 49, 18, 239, 81, 113, 19, 50, 82, 114, 51,
-  83, 115, 640, 516, 392, 268, 144, 20, 672, 641, 548, 517, 424,
-  393, 300, 269, 176, 145,
-  52, 21, 704, 673, 642, 580, 549, 518, 456, 425, 394, 332, 301,
-  270, 208, 177, 146, 84, 53, 22, 736, 705, 674, 643, 612, 581,
-  550, 519, 488, 457, 426, 395,
-  364, 333, 302, 271, 240, 209, 178, 147, 116, 85, 54, 23, 737,
-  706, 675, 613, 582, 551, 489, 458, 427, 365, 334, 303, 241,
-  210, 179, 117, 86, 55, 738, 707,
-  614, 583, 490, 459, 366, 335, 242, 211, 118, 87, 739, 615, 491,
-  367, 243, 119, 768, 644, 520, 396, 272, 148, 24, 800, 769, 676,
-  645, 552, 521, 428, 397, 304,
-  273, 180, 149, 56, 25, 832, 801, 770, 708, 677, 646, 584, 553,
-  522, 460, 429, 398, 336, 305, 274, 212, 181, 150, 88, 57, 26,
-  864, 833, 802, 771, 740, 709,
-  678, 647, 616, 585, 554, 523, 492, 461, 430, 399, 368, 337, 306,
-  275, 244, 213, 182, 151, 120, 89, 58, 27, 865, 834, 803, 741,
-  710, 679, 617, 586, 555, 493,
-  462, 431, 369, 338, 307, 245, 214, 183, 121, 90, 59, 866, 835,
-  742, 711, 618, 587, 494, 463, 370, 339, 246, 215, 122, 91, 867,
-  743, 619, 495, 371, 247, 123,
-  896, 772, 648, 524, 400, 276, 152, 28, 928, 897, 804, 773, 680,
-  649, 556, 525, 432, 401, 308, 277, 184, 153, 60, 29, 960, 929,
-  898, 836, 805, 774, 712, 681,
-  650, 588, 557, 526, 464, 433, 402, 340, 309, 278, 216, 185, 154,
-  92, 61, 30, 992, 961, 930, 899, 868, 837, 806, 775, 744, 713, 682,
-  651, 620, 589, 558, 527,
-  496, 465, 434, 403, 372, 341, 310, 279, 248, 217, 186, 155, 124,
-  93, 62, 31, 993, 962, 931, 869, 838, 807, 745, 714, 683, 621, 590,
-  559, 497, 466, 435, 373,
-  342, 311, 249, 218, 187, 125, 94, 63, 994, 963, 870, 839, 746, 715,
-  622, 591, 498, 467, 374, 343, 250, 219, 126, 95, 995, 871, 747, 623,
-  499, 375, 251, 127,
-  900, 776, 652, 528, 404, 280, 156, 932, 901, 808, 777, 684, 653, 560,
-  529, 436, 405, 312, 281, 188, 157, 964, 933, 902, 840, 809, 778, 716,
-  685, 654, 592, 561,
-  530, 468, 437, 406, 344, 313, 282, 220, 189, 158, 996, 965, 934, 903,
-  872, 841, 810, 779, 748, 717, 686, 655, 624, 593, 562, 531, 500, 469,
-  438, 407, 376, 345,
-  314, 283, 252, 221, 190, 159, 997, 966, 935, 873, 842, 811, 749, 718,
-  687, 625, 594, 563, 501, 470, 439, 377, 346, 315, 253, 222, 191, 998,
-  967, 874, 843, 750,
-  719, 626, 595, 502, 471, 378, 347, 254, 223, 999, 875, 751, 627, 503,
-  379, 255, 904, 780, 656, 532, 408, 284, 936, 905, 812, 781, 688, 657,
-  564, 533, 440, 409,
-  316, 285, 968, 937, 906, 844, 813, 782, 720, 689, 658, 596, 565, 534,
-  472, 441, 410, 348, 317, 286, 1000, 969, 938, 907, 876, 845, 814, 783,
-  752, 721, 690, 659,
-  628, 597, 566, 535, 504, 473, 442, 411, 380, 349, 318, 287, 1001, 970,
-  939, 877, 846, 815, 753, 722, 691, 629, 598, 567, 505, 474, 443, 381,
-  350, 319, 1002, 971,
-  878, 847, 754, 723, 630, 599, 506, 475, 382, 351, 1003, 879, 755, 631,
-  507, 383, 908, 784, 660, 536, 412, 940, 909, 816, 785, 692, 661, 568,
-  537, 444, 413, 972,
-  941, 910, 848, 817, 786, 724, 693, 662, 600, 569, 538, 476, 445, 414,
-  1004, 973, 942, 911, 880, 849, 818, 787, 756, 725, 694, 663, 632, 601,
-  570, 539, 508, 477,
-  446, 415, 1005, 974, 943, 881, 850, 819, 757, 726, 695, 633, 602, 571,
-  509, 478, 447, 1006, 975, 882, 851, 758, 727, 634, 603, 510, 479,
-  1007, 883, 759, 635, 511,
-  912, 788, 664, 540, 944, 913, 820, 789, 696, 665, 572, 541, 976, 945,
-  914, 852, 821, 790, 728, 697, 666, 604, 573, 542, 1008, 977, 946, 915,
-  884, 853, 822, 791,
-  760, 729, 698, 667, 636, 605, 574, 543, 1009, 978, 947, 885, 854, 823,
-  761, 730, 699, 637, 606, 575, 1010, 979, 886, 855, 762, 731, 638, 607,
-  1011, 887, 763, 639,
-  916, 792, 668, 948, 917, 824, 793, 700, 669, 980, 949, 918, 856, 825,
-  794, 732, 701, 670, 1012, 981, 950, 919, 888, 857, 826, 795, 764, 733,
-  702, 671, 1013, 982,
-  951, 889, 858, 827, 765, 734, 703, 1014, 983, 890, 859, 766, 735, 1015,
-  891, 767, 920, 796, 952, 921, 828, 797, 984, 953, 922, 860, 829, 798,
-  1016, 985, 954, 923,
-  892, 861, 830, 799, 1017, 986, 955, 893, 862, 831, 1018, 987, 894, 863,
-  1019, 895, 924, 956, 925, 988, 957, 926, 1020, 989, 958, 927, 1021,
-  990, 959, 1022, 991, 1023,
-};
-
-// Neighborhood 2-tuples for various scans and blocksizes,
-// in {top, left} order for each position in corresponding scan order.
-DECLARE_ALIGNED(16, static const int16_t,
-                default_scan_4x4_neighbors[17 * MAX_NEIGHBORS]) = {
-  0, 0, 0, 0, 0, 0, 1, 4, 4, 4, 1, 1, 8, 8, 5, 8, 2, 2, 2, 5, 9, 12, 6, 9,
-  3, 6, 10, 13, 7, 10, 11, 14, 0, 0,
-};
-
-DECLARE_ALIGNED(16, static const int16_t,
-                col_scan_4x4_neighbors[17 * MAX_NEIGHBORS]) = {
-  0, 0, 0, 0, 4, 4, 0, 0, 8, 8, 1, 1, 5, 5, 1, 1, 9, 9, 2, 2, 6, 6, 2, 2, 3,
-  3, 10, 10, 7, 7, 11, 11, 0, 0,
-};
-
-DECLARE_ALIGNED(16, static const int16_t,
-                row_scan_4x4_neighbors[17 * MAX_NEIGHBORS]) = {
-  0, 0, 0, 0, 0, 0, 1, 1, 4, 4, 2, 2, 5, 5, 4, 4, 8, 8, 6, 6, 8, 8, 9, 9, 12,
-  12, 10, 10, 13, 13, 14, 14, 0, 0,
-};
-
-DECLARE_ALIGNED(16, static const int16_t,
-                col_scan_8x8_neighbors[65 * MAX_NEIGHBORS]) = {
-  0, 0, 0, 0, 8, 8, 0, 0, 16, 16, 1, 1, 24, 24, 9, 9, 1, 1, 32, 32, 17, 17, 2,
-  2, 25, 25, 10, 10, 40, 40, 2, 2, 18, 18, 33, 33, 3, 3, 48, 48, 11, 11, 26,
-  26, 3, 3, 41, 41, 19, 19, 34, 34, 4, 4, 27, 27, 12, 12, 49, 49, 42, 42, 20,
-  20, 4, 4, 35, 35, 5, 5, 28, 28, 50, 50, 43, 43, 13, 13, 36, 36, 5, 5, 21, 21,
-  51, 51, 29, 29, 6, 6, 44, 44, 14, 14, 6, 6, 37, 37, 52, 52, 22, 22, 7, 7, 30,
-  30, 45, 45, 15, 15, 38, 38, 23, 23, 53, 53, 31, 31, 46, 46, 39, 39, 54, 54,
-  47, 47, 55, 55, 0, 0,
-};
-
-DECLARE_ALIGNED(16, static const int16_t,
-                row_scan_8x8_neighbors[65 * MAX_NEIGHBORS]) = {
-  0, 0, 0, 0, 1, 1, 0, 0, 8, 8, 2, 2, 8, 8, 9, 9, 3, 3, 16, 16, 10, 10, 16, 16,
-  4, 4, 17, 17, 24, 24, 11, 11, 18, 18, 25, 25, 24, 24, 5, 5, 12, 12, 19, 19,
-  32, 32, 26, 26, 6, 6, 33, 33, 32, 32, 20, 20, 27, 27, 40, 40, 13, 13, 34, 34,
-  40, 40, 41, 41, 28, 28, 35, 35, 48, 48, 21, 21, 42, 42, 14, 14, 48, 48, 36,
-  36, 49, 49, 43, 43, 29, 29, 56, 56, 22, 22, 50, 50, 57, 57, 44, 44, 37, 37,
-  51, 51, 30, 30, 58, 58, 52, 52, 45, 45, 59, 59, 38, 38, 60, 60, 46, 46, 53,
-  53, 54, 54, 61, 61, 62, 62, 0, 0,
-};
-
-DECLARE_ALIGNED(16, static const int16_t,
-                default_scan_8x8_neighbors[65 * MAX_NEIGHBORS]) = {
-  0, 0, 0, 0, 0, 0, 8, 8, 1, 8, 1, 1, 9, 16, 16, 16, 2, 9, 2, 2, 10, 17, 17,
-  24, 24, 24, 3, 10, 3, 3, 18, 25, 25, 32, 11, 18, 32, 32, 4, 11, 26, 33, 19,
-  26, 4, 4, 33, 40, 12, 19, 40, 40, 5, 12, 27, 34, 34, 41, 20, 27, 13, 20, 5,
-  5, 41, 48, 48, 48, 28, 35, 35, 42, 21, 28, 6, 6, 6, 13, 42, 49, 49, 56, 36,
-  43, 14, 21, 29, 36, 7, 14, 43, 50, 50, 57, 22, 29, 37, 44, 15, 22, 44, 51,
-  51, 58, 30, 37, 23, 30, 52, 59, 45, 52, 38, 45, 31, 38, 53, 60, 46, 53, 39,
-  46, 54, 61, 47, 54, 55, 62, 0, 0,
-};
-
-DECLARE_ALIGNED(16, static const int16_t,
-                col_scan_16x16_neighbors[257 * MAX_NEIGHBORS]) = {
-  0, 0, 0, 0, 16, 16, 32, 32, 0, 0, 48, 48, 1, 1, 64, 64,
-  17, 17, 80, 80, 33, 33, 1, 1, 49, 49, 96, 96, 2, 2, 65, 65,
-  18, 18, 112, 112, 34, 34, 81, 81, 2, 2, 50, 50, 128, 128, 3, 3,
-  97, 97, 19, 19, 66, 66, 144, 144, 82, 82, 35, 35, 113, 113, 3, 3,
-  51, 51, 160, 160, 4, 4, 98, 98, 129, 129, 67, 67, 20, 20, 83, 83,
-  114, 114, 36, 36, 176, 176, 4, 4, 145, 145, 52, 52, 99, 99, 5, 5,
-  130, 130, 68, 68, 192, 192, 161, 161, 21, 21, 115, 115, 84, 84, 37, 37,
-  146, 146, 208, 208, 53, 53, 5, 5, 100, 100, 177, 177, 131, 131, 69, 69,
-  6, 6, 224, 224, 116, 116, 22, 22, 162, 162, 85, 85, 147, 147, 38, 38,
-  193, 193, 101, 101, 54, 54, 6, 6, 132, 132, 178, 178, 70, 70, 163, 163,
-  209, 209, 7, 7, 117, 117, 23, 23, 148, 148, 7, 7, 86, 86, 194, 194,
-  225, 225, 39, 39, 179, 179, 102, 102, 133, 133, 55, 55, 164, 164, 8, 8,
-  71, 71, 210, 210, 118, 118, 149, 149, 195, 195, 24, 24, 87, 87, 40, 40,
-  56, 56, 134, 134, 180, 180, 226, 226, 103, 103, 8, 8, 165, 165, 211, 211,
-  72, 72, 150, 150, 9, 9, 119, 119, 25, 25, 88, 88, 196, 196, 41, 41,
-  135, 135, 181, 181, 104, 104, 57, 57, 227, 227, 166, 166, 120, 120, 151, 151,
-  197, 197, 73, 73, 9, 9, 212, 212, 89, 89, 136, 136, 182, 182, 10, 10,
-  26, 26, 105, 105, 167, 167, 228, 228, 152, 152, 42, 42, 121, 121, 213, 213,
-  58, 58, 198, 198, 74, 74, 137, 137, 183, 183, 168, 168, 10, 10, 90, 90,
-  229, 229, 11, 11, 106, 106, 214, 214, 153, 153, 27, 27, 199, 199, 43, 43,
-  184, 184, 122, 122, 169, 169, 230, 230, 59, 59, 11, 11, 75, 75, 138, 138,
-  200, 200, 215, 215, 91, 91, 12, 12, 28, 28, 185, 185, 107, 107, 154, 154,
-  44, 44, 231, 231, 216, 216, 60, 60, 123, 123, 12, 12, 76, 76, 201, 201,
-  170, 170, 232, 232, 139, 139, 92, 92, 13, 13, 108, 108, 29, 29, 186, 186,
-  217, 217, 155, 155, 45, 45, 13, 13, 61, 61, 124, 124, 14, 14, 233, 233,
-  77, 77, 14, 14, 171, 171, 140, 140, 202, 202, 30, 30, 93, 93, 109, 109,
-  46, 46, 156, 156, 62, 62, 187, 187, 15, 15, 125, 125, 218, 218, 78, 78,
-  31, 31, 172, 172, 47, 47, 141, 141, 94, 94, 234, 234, 203, 203, 63, 63,
-  110, 110, 188, 188, 157, 157, 126, 126, 79, 79, 173, 173, 95, 95, 219, 219,
-  142, 142, 204, 204, 235, 235, 111, 111, 158, 158, 127, 127, 189, 189, 220,
-  220, 143, 143, 174, 174, 205, 205, 236, 236, 159, 159, 190, 190, 221, 221,
-  175, 175, 237, 237, 206, 206, 222, 222, 191, 191, 238, 238, 207, 207, 223,
-  223, 239, 239, 0, 0,
-};
-
-DECLARE_ALIGNED(16, static const int16_t,
-                row_scan_16x16_neighbors[257 * MAX_NEIGHBORS]) = {
-  0, 0, 0, 0, 1, 1, 0, 0, 2, 2, 16, 16, 3, 3, 17, 17,
-  16, 16, 4, 4, 32, 32, 18, 18, 5, 5, 33, 33, 32, 32, 19, 19,
-  48, 48, 6, 6, 34, 34, 20, 20, 49, 49, 48, 48, 7, 7, 35, 35,
-  64, 64, 21, 21, 50, 50, 36, 36, 64, 64, 8, 8, 65, 65, 51, 51,
-  22, 22, 37, 37, 80, 80, 66, 66, 9, 9, 52, 52, 23, 23, 81, 81,
-  67, 67, 80, 80, 38, 38, 10, 10, 53, 53, 82, 82, 96, 96, 68, 68,
-  24, 24, 97, 97, 83, 83, 39, 39, 96, 96, 54, 54, 11, 11, 69, 69,
-  98, 98, 112, 112, 84, 84, 25, 25, 40, 40, 55, 55, 113, 113, 99, 99,
-  12, 12, 70, 70, 112, 112, 85, 85, 26, 26, 114, 114, 100, 100, 128, 128,
-  41, 41, 56, 56, 71, 71, 115, 115, 13, 13, 86, 86, 129, 129, 101, 101,
-  128, 128, 72, 72, 130, 130, 116, 116, 27, 27, 57, 57, 14, 14, 87, 87,
-  42, 42, 144, 144, 102, 102, 131, 131, 145, 145, 117, 117, 73, 73, 144, 144,
-  88, 88, 132, 132, 103, 103, 28, 28, 58, 58, 146, 146, 118, 118, 43, 43,
-  160, 160, 147, 147, 89, 89, 104, 104, 133, 133, 161, 161, 119, 119, 160, 160,
-  74, 74, 134, 134, 148, 148, 29, 29, 59, 59, 162, 162, 176, 176, 44, 44,
-  120, 120, 90, 90, 105, 105, 163, 163, 177, 177, 149, 149, 176, 176, 135, 135,
-  164, 164, 178, 178, 30, 30, 150, 150, 192, 192, 75, 75, 121, 121, 60, 60,
-  136, 136, 193, 193, 106, 106, 151, 151, 179, 179, 192, 192, 45, 45, 165, 165,
-  166, 166, 194, 194, 91, 91, 180, 180, 137, 137, 208, 208, 122, 122, 152, 152,
-  208, 208, 195, 195, 76, 76, 167, 167, 209, 209, 181, 181, 224, 224, 107, 107,
-  196, 196, 61, 61, 153, 153, 224, 224, 182, 182, 168, 168, 210, 210, 46, 46,
-  138, 138, 92, 92, 183, 183, 225, 225, 211, 211, 240, 240, 197, 197, 169, 169,
-  123, 123, 154, 154, 198, 198, 77, 77, 212, 212, 184, 184, 108, 108, 226, 226,
-  199, 199, 62, 62, 227, 227, 241, 241, 139, 139, 213, 213, 170, 170, 185, 185,
-  155, 155, 228, 228, 242, 242, 124, 124, 93, 93, 200, 200, 243, 243, 214, 214,
-  215, 215, 229, 229, 140, 140, 186, 186, 201, 201, 78, 78, 171, 171, 109, 109,
-  156, 156, 244, 244, 216, 216, 230, 230, 94, 94, 245, 245, 231, 231, 125, 125,
-  202, 202, 246, 246, 232, 232, 172, 172, 217, 217, 141, 141, 110, 110, 157,
-  157, 187, 187, 247, 247, 126, 126, 233, 233, 218, 218, 248, 248, 188, 188,
-  203, 203, 142, 142, 173, 173, 158, 158, 249, 249, 234, 234, 204, 204, 219,
-  219, 174, 174, 189, 189, 250, 250, 220, 220, 190, 190, 205, 205, 235, 235,
-  206, 206, 236, 236, 251, 251, 221, 221, 252, 252, 222, 222, 237, 237, 238,
-  238, 253, 253, 254, 254, 0, 0,
-};
-
-DECLARE_ALIGNED(16, static const int16_t,
-                default_scan_16x16_neighbors[257 * MAX_NEIGHBORS]) = {
-  0, 0, 0, 0, 0, 0, 16, 16, 1, 16, 1, 1, 32, 32, 17, 32,
-  2, 17, 2, 2, 48, 48, 18, 33, 33, 48, 3, 18, 49, 64, 64, 64,
-  34, 49, 3, 3, 19, 34, 50, 65, 4, 19, 65, 80, 80, 80, 35, 50,
-  4, 4, 20, 35, 66, 81, 81, 96, 51, 66, 96, 96, 5, 20, 36, 51,
-  82, 97, 21, 36, 67, 82, 97, 112, 5, 5, 52, 67, 112, 112, 37, 52,
-  6, 21, 83, 98, 98, 113, 68, 83, 6, 6, 113, 128, 22, 37, 53, 68,
-  84, 99, 99, 114, 128, 128, 114, 129, 69, 84, 38, 53, 7, 22, 7, 7,
-  129, 144, 23, 38, 54, 69, 100, 115, 85, 100, 115, 130, 144, 144, 130, 145,
-  39, 54, 70, 85, 8, 23, 55, 70, 116, 131, 101, 116, 145, 160, 24, 39,
-  8, 8, 86, 101, 131, 146, 160, 160, 146, 161, 71, 86, 40, 55, 9, 24,
-  117, 132, 102, 117, 161, 176, 132, 147, 56, 71, 87, 102, 25, 40, 147, 162,
-  9, 9, 176, 176, 162, 177, 72, 87, 41, 56, 118, 133, 133, 148, 103, 118,
-  10, 25, 148, 163, 57, 72, 88, 103, 177, 192, 26, 41, 163, 178, 192, 192,
-  10, 10, 119, 134, 73, 88, 149, 164, 104, 119, 134, 149, 42, 57, 178, 193,
-  164, 179, 11, 26, 58, 73, 193, 208, 89, 104, 135, 150, 120, 135, 27, 42,
-  74, 89, 208, 208, 150, 165, 179, 194, 165, 180, 105, 120, 194, 209, 43, 58,
-  11, 11, 136, 151, 90, 105, 151, 166, 180, 195, 59, 74, 121, 136, 209, 224,
-  195, 210, 224, 224, 166, 181, 106, 121, 75, 90, 12, 27, 181, 196, 12, 12,
-  210, 225, 152, 167, 167, 182, 137, 152, 28, 43, 196, 211, 122, 137, 91, 106,
-  225, 240, 44, 59, 13, 28, 107, 122, 182, 197, 168, 183, 211, 226, 153, 168,
-  226, 241, 60, 75, 197, 212, 138, 153, 29, 44, 76, 91, 13, 13, 183, 198,
-  123, 138, 45, 60, 212, 227, 198, 213, 154, 169, 169, 184, 227, 242, 92, 107,
-  61, 76, 139, 154, 14, 29, 14, 14, 184, 199, 213, 228, 108, 123, 199, 214,
-  228, 243, 77, 92, 30, 45, 170, 185, 155, 170, 185, 200, 93, 108, 124, 139,
-  214, 229, 46, 61, 200, 215, 229, 244, 15, 30, 109, 124, 62, 77, 140, 155,
-  215, 230, 31, 46, 171, 186, 186, 201, 201, 216, 78, 93, 230, 245, 125, 140,
-  47, 62, 216, 231, 156, 171, 94, 109, 231, 246, 141, 156, 63, 78, 202, 217,
-  187, 202, 110, 125, 217, 232, 172, 187, 232, 247, 79, 94, 157, 172, 126, 141,
-  203, 218, 95, 110, 233, 248, 218, 233, 142, 157, 111, 126, 173, 188, 188, 203,
-  234, 249, 219, 234, 127, 142, 158, 173, 204, 219, 189, 204, 143, 158, 235,
-  250, 174, 189, 205, 220, 159, 174, 220, 235, 221, 236, 175, 190, 190, 205,
-  236, 251, 206, 221, 237, 252, 191, 206, 222, 237, 207, 222, 238, 253, 223,
-  238, 239, 254, 0, 0,
-};
-
-DECLARE_ALIGNED(16, static const int16_t,
-                default_scan_32x32_neighbors[1025 * MAX_NEIGHBORS]) = {
-  0, 0, 0, 0, 0, 0, 32, 32, 1, 32, 1, 1, 64, 64, 33, 64,
-  2, 33, 96, 96, 2, 2, 65, 96, 34, 65, 128, 128, 97, 128, 3, 34,
-  66, 97, 3, 3, 35, 66, 98, 129, 129, 160, 160, 160, 4, 35, 67, 98,
-  192, 192, 4, 4, 130, 161, 161, 192, 36, 67, 99, 130, 5, 36, 68, 99,
-  193, 224, 162, 193, 224, 224, 131, 162, 37, 68, 100, 131, 5, 5, 194, 225,
-  225, 256, 256, 256, 163, 194, 69, 100, 132, 163, 6, 37, 226, 257, 6, 6,
-  195, 226, 257, 288, 101, 132, 288, 288, 38, 69, 164, 195, 133, 164, 258, 289,
-  227, 258, 196, 227, 7, 38, 289, 320, 70, 101, 320, 320, 7, 7, 165, 196,
-  39, 70, 102, 133, 290, 321, 259, 290, 228, 259, 321, 352, 352, 352, 197, 228,
-  134, 165, 71, 102, 8, 39, 322, 353, 291, 322, 260, 291, 103, 134, 353, 384,
-  166, 197, 229, 260, 40, 71, 8, 8, 384, 384, 135, 166, 354, 385, 323, 354,
-  198, 229, 292, 323, 72, 103, 261, 292, 9, 40, 385, 416, 167, 198, 104, 135,
-  230, 261, 355, 386, 416, 416, 293, 324, 324, 355, 9, 9, 41, 72, 386, 417,
-  199, 230, 136, 167, 417, 448, 262, 293, 356, 387, 73, 104, 387, 418, 231, 262,
-  10, 41, 168, 199, 325, 356, 418, 449, 105, 136, 448, 448, 42, 73, 294, 325,
-  200, 231, 10, 10, 357, 388, 137, 168, 263, 294, 388, 419, 74, 105, 419, 450,
-  449, 480, 326, 357, 232, 263, 295, 326, 169, 200, 11, 42, 106, 137, 480, 480,
-  450, 481, 358, 389, 264, 295, 201, 232, 138, 169, 389, 420, 43, 74, 420, 451,
-  327, 358, 11, 11, 481, 512, 233, 264, 451, 482, 296, 327, 75, 106, 170, 201,
-  482, 513, 512, 512, 390, 421, 359, 390, 421, 452, 107, 138, 12, 43, 202, 233,
-  452, 483, 265, 296, 328, 359, 139, 170, 44, 75, 483, 514, 513, 544, 234, 265,
-  297, 328, 422, 453, 12, 12, 391, 422, 171, 202, 76, 107, 514, 545, 453, 484,
-  544, 544, 266, 297, 203, 234, 108, 139, 329, 360, 298, 329, 140, 171, 515,
-  546, 13, 44, 423, 454, 235, 266, 545, 576, 454, 485, 45, 76, 172, 203, 330,
-  361, 576, 576, 13, 13, 267, 298, 546, 577, 77, 108, 204, 235, 455, 486, 577,
-  608, 299, 330, 109, 140, 547, 578, 14, 45, 14, 14, 141, 172, 578, 609, 331,
-  362, 46, 77, 173, 204, 15, 15, 78, 109, 205, 236, 579, 610, 110, 141, 15, 46,
-  142, 173, 47, 78, 174, 205, 16, 16, 79, 110, 206, 237, 16, 47, 111, 142,
-  48, 79, 143, 174, 80, 111, 175, 206, 17, 48, 17, 17, 207, 238, 49, 80,
-  81, 112, 18, 18, 18, 49, 50, 81, 82, 113, 19, 50, 51, 82, 83, 114, 608, 608,
-  484, 515, 360, 391, 236, 267, 112, 143, 19, 19, 640, 640, 609, 640, 516, 547,
-  485, 516, 392, 423, 361, 392, 268, 299, 237, 268, 144, 175, 113, 144, 20, 51,
-  20, 20, 672, 672, 641, 672, 610, 641, 548, 579, 517, 548, 486, 517, 424, 455,
-  393, 424, 362, 393, 300, 331, 269, 300, 238, 269, 176, 207, 145, 176, 114,
-  145, 52, 83, 21, 52, 21, 21, 704, 704, 673, 704, 642, 673, 611, 642, 580,
-  611, 549, 580, 518, 549, 487, 518, 456, 487, 425, 456, 394, 425, 363, 394,
-  332, 363, 301, 332, 270, 301, 239, 270, 208, 239, 177, 208, 146, 177, 115,
-  146, 84, 115, 53, 84, 22, 53, 22, 22, 705, 736, 674, 705, 643, 674, 581, 612,
-  550, 581, 519, 550, 457, 488, 426, 457, 395, 426, 333, 364, 302, 333, 271,
-  302, 209, 240, 178, 209, 147, 178, 85, 116, 54, 85, 23, 54, 706, 737, 675,
-  706, 582, 613, 551, 582, 458, 489, 427, 458, 334, 365, 303, 334, 210, 241,
-  179, 210, 86, 117, 55, 86, 707, 738, 583, 614, 459, 490, 335, 366, 211, 242,
-  87, 118, 736, 736, 612, 643, 488, 519, 364, 395, 240, 271, 116, 147, 23, 23,
-  768, 768, 737, 768, 644, 675, 613, 644, 520, 551, 489, 520, 396, 427, 365,
-  396, 272, 303, 241, 272, 148, 179, 117, 148, 24, 55, 24, 24, 800, 800, 769,
-  800, 738, 769, 676, 707, 645, 676, 614, 645, 552, 583, 521, 552, 490, 521,
-  428, 459, 397, 428, 366, 397, 304, 335, 273, 304, 242, 273, 180, 211, 149,
-  180, 118, 149, 56, 87, 25, 56, 25, 25, 832, 832, 801, 832, 770, 801, 739,
-  770, 708, 739, 677, 708, 646, 677, 615, 646, 584, 615, 553, 584, 522, 553,
-  491, 522, 460, 491, 429, 460, 398, 429, 367, 398, 336, 367, 305, 336, 274,
-  305, 243, 274, 212, 243, 181, 212, 150, 181, 119, 150, 88, 119, 57, 88, 26,
-  57, 26, 26, 833, 864, 802, 833, 771, 802, 709, 740, 678, 709, 647, 678, 585,
-  616, 554, 585, 523, 554, 461, 492, 430, 461, 399, 430, 337, 368, 306, 337,
-  275, 306, 213, 244, 182, 213, 151, 182, 89, 120, 58, 89, 27, 58, 834, 865,
-  803, 834, 710, 741, 679, 710, 586, 617, 555, 586, 462, 493, 431, 462, 338,
-  369, 307, 338, 214, 245, 183, 214, 90, 121, 59, 90, 835, 866, 711, 742, 587,
-  618, 463, 494, 339, 370, 215, 246, 91, 122, 864, 864, 740, 771, 616, 647,
-  492, 523, 368, 399, 244, 275, 120, 151, 27, 27, 896, 896, 865, 896, 772, 803,
-  741, 772, 648, 679, 617, 648, 524, 555, 493, 524, 400, 431, 369, 400, 276,
-  307, 245, 276, 152, 183, 121, 152, 28, 59, 28, 28, 928, 928, 897, 928, 866,
-  897, 804, 835, 773, 804, 742, 773, 680, 711, 649, 680, 618, 649, 556, 587,
-  525, 556, 494, 525, 432, 463, 401, 432, 370, 401, 308, 339, 277, 308, 246,
-  277, 184, 215, 153, 184, 122, 153, 60, 91, 29, 60, 29, 29, 960, 960, 929,
-  960, 898, 929, 867, 898, 836, 867, 805, 836, 774, 805, 743, 774, 712, 743,
-  681, 712, 650, 681, 619, 650, 588, 619, 557, 588, 526, 557, 495, 526, 464,
-  495, 433, 464, 402, 433, 371, 402, 340, 371, 309, 340, 278, 309, 247, 278,
-  216, 247, 185, 216, 154, 185, 123, 154, 92, 123, 61, 92, 30, 61, 30, 30,
-  961, 992, 930, 961, 899, 930, 837, 868, 806, 837, 775, 806, 713, 744, 682,
-  713, 651, 682, 589, 620, 558, 589, 527, 558, 465, 496, 434, 465, 403, 434,
-  341, 372, 310, 341, 279, 310, 217, 248, 186, 217, 155, 186, 93, 124, 62, 93,
-  31, 62, 962, 993, 931, 962, 838, 869, 807, 838, 714, 745, 683, 714, 590, 621,
-  559, 590, 466, 497, 435, 466, 342, 373, 311, 342, 218, 249, 187, 218, 94,
-  125, 63, 94, 963, 994, 839, 870, 715, 746, 591, 622, 467, 498, 343, 374, 219,
-  250, 95, 126, 868, 899, 744, 775, 620, 651, 496, 527, 372, 403, 248, 279,
-  124, 155, 900, 931, 869, 900, 776, 807, 745, 776, 652, 683, 621, 652, 528,
-  559, 497, 528, 404, 435, 373, 404, 280, 311, 249, 280, 156, 187, 125, 156,
-  932, 963, 901, 932, 870, 901, 808, 839, 777, 808, 746, 777, 684, 715, 653,
-  684, 622, 653, 560, 591, 529, 560, 498, 529, 436, 467, 405, 436, 374, 405,
-  312, 343, 281, 312, 250, 281, 188, 219, 157, 188, 126, 157, 964, 995, 933,
-  964, 902, 933, 871, 902, 840, 871, 809, 840, 778, 809, 747, 778, 716, 747,
-  685, 716, 654, 685, 623, 654, 592, 623, 561, 592, 530, 561, 499, 530, 468,
-  499, 437, 468, 406, 437, 375, 406, 344, 375, 313, 344, 282, 313, 251, 282,
-  220, 251, 189, 220, 158, 189, 127, 158, 965, 996, 934, 965, 903, 934, 841,
-  872, 810, 841, 779, 810, 717, 748, 686, 717, 655, 686, 593, 624, 562, 593,
-  531, 562, 469, 500, 438, 469, 407, 438, 345, 376, 314, 345, 283, 314, 221,
-  252, 190, 221, 159, 190, 966, 997, 935, 966, 842, 873, 811, 842, 718, 749,
-  687, 718, 594, 625, 563, 594, 470, 501, 439, 470, 346, 377, 315, 346, 222,
-  253, 191, 222, 967, 998, 843, 874, 719, 750, 595, 626, 471, 502, 347, 378,
-  223, 254, 872, 903, 748, 779, 624, 655, 500, 531, 376, 407, 252, 283, 904,
-  935, 873, 904, 780, 811, 749, 780, 656, 687, 625, 656, 532, 563, 501, 532,
-  408, 439, 377, 408, 284, 315, 253, 284, 936, 967, 905, 936, 874, 905, 812,
-  843, 781, 812, 750, 781, 688, 719, 657, 688, 626, 657, 564, 595, 533, 564,
-  502, 533, 440, 471, 409, 440, 378, 409, 316, 347, 285, 316, 254, 285, 968,
-  999, 937, 968, 906, 937, 875, 906, 844, 875, 813, 844, 782, 813, 751, 782,
-  720, 751, 689, 720, 658, 689, 627, 658, 596, 627, 565, 596, 534, 565, 503,
-  534, 472, 503, 441, 472, 410, 441, 379, 410, 348, 379, 317, 348, 286, 317,
-  255, 286, 969, 1000, 938, 969, 907, 938, 845, 876, 814, 845, 783, 814, 721,
-  752, 690, 721, 659, 690, 597, 628, 566, 597, 535, 566, 473, 504, 442, 473,
-  411, 442, 349, 380, 318, 349, 287, 318, 970, 1001, 939, 970, 846, 877, 815,
-  846, 722, 753, 691, 722, 598, 629, 567, 598, 474, 505, 443, 474, 350, 381,
-  319, 350, 971, 1002, 847, 878, 723, 754, 599, 630, 475, 506, 351, 382, 876,
-  907, 752, 783, 628, 659, 504, 535, 380, 411, 908, 939, 877, 908, 784, 815,
-  753, 784, 660, 691, 629, 660, 536, 567, 505, 536, 412, 443, 381, 412, 940,
-  971, 909, 940, 878, 909, 816, 847, 785, 816, 754, 785, 692, 723, 661, 692,
-  630, 661, 568, 599, 537, 568, 506, 537, 444, 475, 413, 444, 382, 413, 972,
-  1003, 941, 972, 910, 941, 879, 910, 848, 879, 817, 848, 786, 817, 755, 786,
-  724, 755, 693, 724, 662, 693, 631, 662, 600, 631, 569, 600, 538, 569, 507,
-  538, 476, 507, 445, 476, 414, 445, 383, 414, 973, 1004, 942, 973, 911, 942,
-  849, 880, 818, 849, 787, 818, 725, 756, 694, 725, 663, 694, 601, 632, 570,
-  601, 539, 570, 477, 508, 446, 477, 415, 446, 974, 1005, 943, 974, 850, 881,
-  819, 850, 726, 757, 695, 726, 602, 633, 571, 602, 478, 509, 447, 478, 975,
-  1006, 851, 882, 727, 758, 603, 634, 479, 510, 880, 911, 756, 787, 632, 663,
-  508, 539, 912, 943, 881, 912, 788, 819, 757, 788, 664, 695, 633, 664, 540,
-  571, 509, 540, 944, 975, 913, 944, 882, 913, 820, 851, 789, 820, 758, 789,
-  696, 727, 665, 696, 634, 665, 572, 603, 541, 572, 510, 541, 976, 1007, 945,
-  976, 914, 945, 883, 914, 852, 883, 821, 852, 790, 821, 759, 790, 728, 759,
-  697, 728, 666, 697, 635, 666, 604, 635, 573, 604, 542, 573, 511, 542, 977,
-  1008, 946, 977, 915, 946, 853, 884, 822, 853, 791, 822, 729, 760, 698, 729,
-  667, 698, 605, 636, 574, 605, 543, 574, 978, 1009, 947, 978, 854, 885, 823,
-  854, 730, 761, 699, 730, 606, 637, 575, 606, 979, 1010, 855, 886, 731, 762,
-  607, 638, 884, 915, 760, 791, 636, 667, 916, 947, 885, 916, 792, 823, 761,
-  792, 668, 699, 637, 668, 948, 979, 917, 948, 886, 917, 824, 855, 793, 824,
-  762, 793, 700, 731, 669, 700, 638, 669, 980, 1011, 949, 980, 918, 949, 887,
-  918, 856, 887, 825, 856, 794, 825, 763, 794, 732, 763, 701, 732, 670, 701,
-  639, 670, 981, 1012, 950, 981, 919, 950, 857, 888, 826, 857, 795, 826, 733,
-  764, 702, 733, 671, 702, 982, 1013, 951, 982, 858, 889, 827, 858, 734, 765,
-  703, 734, 983, 1014, 859, 890, 735, 766, 888, 919, 764, 795, 920, 951, 889,
-  920, 796, 827, 765, 796, 952, 983, 921, 952, 890, 921, 828, 859, 797, 828,
-  766, 797, 984, 1015, 953, 984, 922, 953, 891, 922, 860, 891, 829, 860, 798,
-  829, 767, 798, 985, 1016, 954, 985, 923, 954, 861, 892, 830, 861, 799, 830,
-  986, 1017, 955, 986, 862, 893, 831, 862, 987, 1018, 863, 894, 892, 923, 924,
-  955, 893, 924, 956, 987, 925, 956, 894, 925, 988, 1019, 957, 988, 926, 957,
-  895, 926, 989, 1020, 958, 989, 927, 958, 990, 1021, 959, 990, 991, 1022, 0, 0,
-};
-
-DECLARE_ALIGNED(16, static const int16_t, vp9_default_iscan_4x4[16]) = {
-  0, 2, 5, 8, 1, 3, 9, 12, 4, 7, 11, 14, 6, 10, 13, 15,
-};
-
-DECLARE_ALIGNED(16, static const int16_t, vp9_col_iscan_4x4[16]) = {
-  0, 3, 7, 11, 1, 5, 9, 12, 2, 6, 10, 14, 4, 8, 13, 15,
-};
-
-DECLARE_ALIGNED(16, static const int16_t, vp9_row_iscan_4x4[16]) = {
-  0, 1, 3, 5, 2, 4, 6, 9, 7, 8, 11, 13, 10, 12, 14, 15,
-};
-
-DECLARE_ALIGNED(16, static const int16_t, vp9_col_iscan_8x8[64]) = {
-  0, 3, 8, 15, 22, 32, 40, 47, 1, 5, 11, 18, 26, 34, 44, 51,
-  2, 7, 13, 20, 28, 38, 46, 54, 4, 10, 16, 24, 31, 41, 50, 56,
-  6, 12, 21, 27, 35, 43, 52, 58, 9, 17, 25, 33, 39, 48, 55, 60,
-  14, 23, 30, 37, 45, 53, 59, 62, 19, 29, 36, 42, 49, 57, 61, 63,
-};
-
-DECLARE_ALIGNED(16, static const int16_t, vp9_row_iscan_8x8[64]) = {
-  0, 1, 2, 5, 8, 12, 19, 24, 3, 4, 7, 10, 15, 20, 30, 39,
-  6, 9, 13, 16, 21, 27, 37, 46, 11, 14, 17, 23, 28, 34, 44, 52,
-  18, 22, 25, 31, 35, 41, 50, 57, 26, 29, 33, 38, 43, 49, 55, 59,
-  32, 36, 42, 47, 51, 54, 60, 61, 40, 45, 48, 53, 56, 58, 62, 63,
-};
-
-DECLARE_ALIGNED(16, static const int16_t, vp9_default_iscan_8x8[64]) = {
-  0, 2, 5, 9, 14, 22, 31, 37, 1, 4, 8, 13, 19, 26, 38, 44,
-  3, 6, 10, 17, 24, 30, 42, 49, 7, 11, 15, 21, 29, 36, 47, 53,
-  12, 16, 20, 27, 34, 43, 52, 57, 18, 23, 28, 35, 41, 48, 56, 60,
-  25, 32, 39, 45, 50, 55, 59, 62, 33, 40, 46, 51, 54, 58, 61, 63,
-};
-
-DECLARE_ALIGNED(16, static const int16_t, vp9_col_iscan_16x16[256]) = {
-  0, 4, 11, 20, 31, 43, 59, 75, 85, 109, 130, 150, 165, 181, 195, 198,
-  1, 6, 14, 23, 34, 47, 64, 81, 95, 114, 135, 153, 171, 188, 201, 212,
-  2, 8, 16, 25, 38, 52, 67, 83, 101, 116, 136, 157, 172, 190, 205, 216,
-  3, 10, 18, 29, 41, 55, 71, 89, 103, 119, 141, 159, 176, 194, 208, 218,
-  5, 12, 21, 32, 45, 58, 74, 93, 104, 123, 144, 164, 179, 196, 210, 223,
-  7, 15, 26, 37, 49, 63, 78, 96, 112, 129, 146, 166, 182, 200, 215, 228,
-  9, 19, 28, 39, 54, 69, 86, 102, 117, 132, 151, 170, 187, 206, 220, 230,
-  13, 24, 35, 46, 60, 73, 91, 108, 122, 137, 154, 174, 189, 207, 224, 235,
-  17, 30, 40, 53, 66, 82, 98, 115, 126, 142, 161, 180, 197, 213, 227, 237,
-  22, 36, 48, 62, 76, 92, 105, 120, 133, 147, 167, 186, 203, 219, 232, 240,
-  27, 44, 56, 70, 84, 99, 113, 127, 140, 156, 175, 193, 209, 226, 236, 244,
-  33, 51, 68, 79, 94, 110, 125, 138, 149, 162, 184, 202, 217, 229, 241, 247,
-  42, 61, 77, 90, 106, 121, 134, 148, 160, 173, 191, 211, 225, 238, 245, 251,
-  50, 72, 87, 100, 118, 128, 145, 158, 168, 183, 204, 222, 233, 242, 249, 253,
-  57, 80, 97, 111, 131, 143, 155, 169, 178, 192, 214, 231, 239, 246, 250, 254,
-  65, 88, 107, 124, 139, 152, 163, 177, 185, 199, 221, 234, 243, 248, 252, 255,
-};
-
-DECLARE_ALIGNED(16, static const int16_t, vp9_row_iscan_16x16[256]) = {
-  0, 1, 2, 4, 6, 9, 12, 17, 22, 29, 36, 43, 54, 64, 76, 86,
-  3, 5, 7, 11, 15, 19, 25, 32, 38, 48, 59, 68, 84, 99, 115, 130,
-  8, 10, 13, 18, 23, 27, 33, 42, 51, 60, 72, 88, 103, 119, 142, 167,
-  14, 16, 20, 26, 31, 37, 44, 53, 61, 73, 85, 100, 116, 135, 161, 185,
-  21, 24, 30, 35, 40, 47, 55, 65, 74, 81, 94, 112, 133, 154, 179, 205,
-  28, 34, 39, 45, 50, 58, 67, 77, 87, 96, 106, 121, 146, 169, 196, 212,
-  41, 46, 49, 56, 63, 70, 79, 90, 98, 107, 122, 138, 159, 182, 207, 222,
-  52, 57, 62, 69, 75, 83, 93, 102, 110, 120, 134, 150, 176, 195, 215, 226,
-  66, 71, 78, 82, 91, 97, 108, 113, 127, 136, 148, 168, 188, 202, 221, 232,
-  80, 89, 92, 101, 105, 114, 125, 131, 139, 151, 162, 177, 192, 208, 223, 234,
-  95, 104, 109, 117, 123, 128, 143, 144, 155, 165, 175, 190, 206, 219, 233, 239,
-  111, 118, 124, 129, 140, 147, 157, 164, 170, 181, 191, 203, 224, 230, 240,
-  243, 126, 132, 137, 145, 153, 160, 174, 178, 184, 197, 204, 216, 231, 237,
-  244, 246, 141, 149, 156, 166, 172, 180, 189, 199, 200, 210, 220, 228, 238,
-  242, 249, 251, 152, 163, 171, 183, 186, 193, 201, 211, 214, 218, 227, 236,
-  245, 247, 252, 253, 158, 173, 187, 194, 198, 209, 213, 217, 225, 229, 235,
-  241, 248, 250, 254, 255,
-};
-
-DECLARE_ALIGNED(16, static const int16_t, vp9_default_iscan_16x16[256]) = {
-  0, 2, 5, 9, 17, 24, 36, 44, 55, 72, 88, 104, 128, 143, 166, 179,
-  1, 4, 8, 13, 20, 30, 40, 54, 66, 79, 96, 113, 141, 154, 178, 196,
-  3, 7, 11, 18, 25, 33, 46, 57, 71, 86, 101, 119, 148, 164, 186, 201,
-  6, 12, 16, 23, 31, 39, 53, 64, 78, 92, 110, 127, 153, 169, 193, 208,
-  10, 14, 19, 28, 37, 47, 58, 67, 84, 98, 114, 133, 161, 176, 198, 214,
-  15, 21, 26, 34, 43, 52, 65, 77, 91, 106, 120, 140, 165, 185, 205, 221,
-  22, 27, 32, 41, 48, 60, 73, 85, 99, 116, 130, 151, 175, 190, 211, 225,
-  29, 35, 42, 49, 59, 69, 81, 95, 108, 125, 139, 155, 182, 197, 217, 229,
-  38, 45, 51, 61, 68, 80, 93, 105, 118, 134, 150, 168, 191, 207, 223, 234,
-  50, 56, 63, 74, 83, 94, 109, 117, 129, 147, 163, 177, 199, 213, 228, 238,
-  62, 70, 76, 87, 97, 107, 122, 131, 145, 159, 172, 188, 210, 222, 235, 242,
-  75, 82, 90, 102, 112, 124, 138, 146, 157, 173, 187, 202, 219, 230, 240, 245,
-  89, 100, 111, 123, 132, 142, 156, 167, 180, 189, 203, 216, 231, 237, 246, 250,
-  103, 115, 126, 136, 149, 162, 171, 183, 194, 204, 215, 224, 236, 241, 248,
-  252, 121, 135, 144, 158, 170, 181, 192, 200, 209, 218, 227, 233, 243, 244,
-  251, 254, 137, 152, 160, 174, 184, 195, 206, 212, 220, 226, 232, 239, 247,
-  249, 253, 255,
-};
-
-DECLARE_ALIGNED(16, static const int16_t, vp9_default_iscan_32x32[1024]) = {
-  0, 2, 5, 10, 17, 25, 38, 47, 62, 83, 101, 121, 145, 170, 193, 204,
-  210, 219, 229, 233, 245, 257, 275, 299, 342, 356, 377, 405, 455, 471, 495,
-  527, 1, 4, 8, 15, 22, 30, 45, 58, 74, 92, 112, 133, 158, 184, 203, 215, 222,
-  228, 234, 237, 256, 274, 298, 317, 355, 376, 404, 426, 470, 494, 526, 551,
-  3, 7, 12, 18, 28, 36, 52, 64, 82, 102, 118, 142, 164, 189, 208, 217, 224,
-  231, 235, 238, 273, 297, 316, 329, 375, 403, 425, 440, 493, 525, 550, 567,
-  6, 11, 16, 23, 31, 43, 60, 73, 90, 109, 126, 150, 173, 196, 211, 220, 226,
-  232, 236, 239, 296, 315, 328, 335, 402, 424, 439, 447, 524, 549, 566, 575,
-  9, 14, 19, 29, 37, 50, 65, 78, 95, 116, 134, 157, 179, 201, 214, 223, 244,
-  255, 272, 295, 341, 354, 374, 401, 454, 469, 492, 523, 582, 596, 617, 645,
-  13, 20, 26, 35, 44, 54, 72, 85, 105, 123, 140, 163, 182, 205, 216, 225,
-  254, 271, 294, 314, 353, 373, 400, 423, 468, 491, 522, 548, 595, 616, 644,
-  666, 21, 27, 33, 42, 53, 63, 80, 94, 113, 132, 151, 172, 190, 209, 218, 227,
-  270, 293, 313, 327, 372, 399, 422, 438, 490, 521, 547, 565, 615, 643, 665,
-  680, 24, 32, 39, 48, 57, 71, 88, 104, 120, 139, 159, 178, 197, 212, 221, 230,
-  292, 312, 326, 334, 398, 421, 437, 446, 520, 546, 564, 574, 642, 664, 679,
-  687, 34, 40, 46, 56, 68, 81, 96, 111, 130, 147, 167, 186, 243, 253, 269, 291,
-  340, 352, 371, 397, 453, 467, 489, 519, 581, 594, 614, 641, 693, 705, 723,
-  747, 41, 49, 55, 67, 77, 91, 107, 124, 138, 161, 177, 194, 252, 268, 290,
-  311, 351, 370, 396, 420, 466, 488, 518, 545, 593, 613, 640, 663, 704, 722,
-  746, 765, 51, 59, 66, 76, 89, 99, 119, 131, 149, 168, 181, 200, 267, 289,
-  310, 325, 369, 395, 419, 436, 487, 517, 544, 563, 612, 639, 662, 678, 721,
-  745, 764, 777, 61, 69, 75, 87, 100, 114, 129, 144, 162, 180, 191, 207, 288,
-  309, 324, 333, 394, 418, 435, 445, 516, 543, 562, 573, 638, 661, 677, 686,
-  744, 763, 776, 783, 70, 79, 86, 97, 108, 122, 137, 155, 242, 251, 266, 287,
-  339, 350, 368, 393, 452, 465, 486, 515, 580, 592, 611, 637, 692, 703, 720,
-  743, 788, 798, 813, 833, 84, 93, 103, 110, 125, 141, 154, 171, 250, 265, 286,
-  308, 349, 367, 392, 417, 464, 485, 514, 542, 591, 610, 636, 660, 702, 719,
-  742, 762, 797, 812, 832, 848, 98, 106, 115, 127, 143, 156, 169, 185, 264,
-  285, 307, 323, 366, 391, 416, 434, 484, 513, 541, 561, 609, 635, 659, 676,
-  718, 741, 761, 775, 811, 831, 847, 858, 117, 128, 136, 148, 160, 175, 188,
-  198, 284, 306, 322, 332, 390, 415, 433, 444, 512, 540, 560, 572, 634, 658,
-  675, 685, 740, 760, 774, 782, 830, 846, 857, 863, 135, 146, 152, 165, 241,
-  249, 263, 283, 338, 348, 365, 389, 451, 463, 483, 511, 579, 590, 608, 633,
-  691, 701, 717, 739, 787, 796, 810, 829, 867, 875, 887, 903, 153, 166, 174,
-  183, 248, 262, 282, 305, 347, 364, 388, 414, 462, 482, 510, 539, 589, 607,
-  632, 657, 700, 716, 738, 759, 795, 809, 828, 845, 874, 886, 902, 915, 176,
-  187, 195, 202, 261, 281, 304, 321, 363, 387, 413, 432, 481, 509, 538, 559,
-  606, 631, 656, 674, 715, 737, 758, 773, 808, 827, 844, 856, 885, 901, 914,
-  923, 192, 199, 206, 213, 280, 303, 320, 331, 386, 412, 431, 443, 508, 537,
-  558, 571, 630, 655, 673, 684, 736, 757, 772, 781, 826, 843, 855, 862, 900,
-  913, 922, 927, 240, 247, 260, 279, 337, 346, 362, 385, 450, 461, 480, 507,
-  578, 588, 605, 629, 690, 699, 714, 735, 786, 794, 807, 825, 866, 873, 884,
-  899, 930, 936, 945, 957, 246, 259, 278, 302, 345, 361, 384, 411, 460, 479,
-  506, 536, 587, 604, 628, 654, 698, 713, 734, 756, 793, 806, 824, 842, 872,
-  883, 898, 912, 935, 944, 956, 966, 258, 277, 301, 319, 360, 383, 410, 430,
-  478, 505, 535, 557, 603, 627, 653, 672, 712, 733, 755, 771, 805, 823, 841,
-  854, 882, 897, 911, 921, 943, 955, 965, 972, 276, 300, 318, 330, 382, 409,
-  429, 442, 504, 534, 556, 570, 626, 652, 671, 683, 732, 754, 770, 780, 822,
-  840, 853, 861, 896, 910, 920, 926, 954, 964, 971, 975, 336, 344, 359, 381,
-  449, 459, 477, 503, 577, 586, 602, 625, 689, 697, 711, 731, 785, 792, 804,
-  821, 865, 871, 881, 895, 929, 934, 942, 953, 977, 981, 987, 995, 343, 358,
-  380, 408, 458, 476, 502, 533, 585, 601, 624, 651, 696, 710, 730, 753, 791,
-  803, 820, 839, 870, 880, 894, 909, 933, 941, 952, 963, 980, 986, 994, 1001,
-  357, 379, 407, 428, 475, 501, 532, 555, 600, 623, 650, 670, 709, 729, 752,
-  769, 802, 819, 838, 852, 879, 893, 908, 919, 940, 951, 962, 970, 985, 993,
-  1000, 1005, 378, 406, 427, 441, 500, 531, 554, 569, 622, 649, 669, 682, 728,
-  751, 768, 779, 818, 837, 851, 860, 892, 907, 918, 925, 950, 961, 969, 974,
-  992, 999, 1004, 1007, 448, 457, 474, 499, 576, 584, 599, 621, 688, 695, 708,
-  727, 784, 790, 801, 817, 864, 869, 878, 891, 928, 932, 939, 949, 976, 979,
-  984, 991, 1008, 1010, 1013, 1017, 456, 473, 498, 530, 583, 598, 620, 648,
-  694, 707, 726, 750, 789, 800, 816, 836, 868, 877, 890, 906, 931, 938, 948,
-  960, 978, 983, 990, 998, 1009, 1012, 1016, 1020, 472, 497, 529, 553, 597,
-  619, 647, 668, 706, 725, 749, 767, 799, 815, 835, 850, 876, 889, 905, 917,
-  937, 947, 959, 968, 982, 989, 997, 1003, 1011, 1015, 1019, 1022, 496, 528,
-  552, 568, 618, 646, 667, 681, 724, 748, 766, 778, 814, 834, 849, 859, 888,
-  904, 916, 924, 946, 958, 967, 973, 988, 996, 1002, 1006, 1014, 1018, 1021,
-  1023,
-};
-
-const scan_order vp9_default_scan_orders[TX_SIZES] = {
-  {default_scan_4x4,   vp9_default_iscan_4x4,   default_scan_4x4_neighbors},
-  {default_scan_8x8,   vp9_default_iscan_8x8,   default_scan_8x8_neighbors},
-  {default_scan_16x16, vp9_default_iscan_16x16, default_scan_16x16_neighbors},
-  {default_scan_32x32, vp9_default_iscan_32x32, default_scan_32x32_neighbors},
-};
-
-const scan_order vp9_scan_orders[TX_SIZES][TX_TYPES] = {
-  {  // TX_4X4
-    {default_scan_4x4, vp9_default_iscan_4x4, default_scan_4x4_neighbors},
-    {row_scan_4x4,     vp9_row_iscan_4x4,     row_scan_4x4_neighbors},
-    {col_scan_4x4,     vp9_col_iscan_4x4,     col_scan_4x4_neighbors},
-    {default_scan_4x4, vp9_default_iscan_4x4, default_scan_4x4_neighbors}
-  }, {  // TX_8X8
-    {default_scan_8x8, vp9_default_iscan_8x8, default_scan_8x8_neighbors},
-    {row_scan_8x8,     vp9_row_iscan_8x8,     row_scan_8x8_neighbors},
-    {col_scan_8x8,     vp9_col_iscan_8x8,     col_scan_8x8_neighbors},
-    {default_scan_8x8, vp9_default_iscan_8x8, default_scan_8x8_neighbors}
-  }, {  // TX_16X16
-    {default_scan_16x16, vp9_default_iscan_16x16, default_scan_16x16_neighbors},
-    {row_scan_16x16,     vp9_row_iscan_16x16,     row_scan_16x16_neighbors},
-    {col_scan_16x16,     vp9_col_iscan_16x16,     col_scan_16x16_neighbors},
-    {default_scan_16x16, vp9_default_iscan_16x16, default_scan_16x16_neighbors}
-  }, {  // TX_32X32
-    {default_scan_32x32, vp9_default_iscan_32x32, default_scan_32x32_neighbors},
-    {default_scan_32x32, vp9_default_iscan_32x32, default_scan_32x32_neighbors},
-    {default_scan_32x32, vp9_default_iscan_32x32, default_scan_32x32_neighbors},
-    {default_scan_32x32, vp9_default_iscan_32x32, default_scan_32x32_neighbors},
-  }
-};
diff --git a/vp9/common/vp9_scan.h b/vp9/common/vp9_scan.h
deleted file mode 100644 (file)
index 4c1ee81..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- *  Copyright (c) 2013 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.
- */
-
-#ifndef VP9_COMMON_VP9_SCAN_H_
-#define VP9_COMMON_VP9_SCAN_H_
-
-#include "vpx/vpx_integer.h"
-#include "vpx_ports/mem.h"
-
-#include "vp9/common/vp9_enums.h"
-#include "vp9/common/vp9_blockd.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define MAX_NEIGHBORS 2
-
-typedef struct {
-  const int16_t *scan;
-  const int16_t *iscan;
-  const int16_t *neighbors;
-} scan_order;
-
-extern const scan_order vp9_default_scan_orders[TX_SIZES];
-extern const scan_order vp9_scan_orders[TX_SIZES][TX_TYPES];
-
-static INLINE int get_coef_context(const int16_t *neighbors,
-                                   const uint8_t *token_cache, int c) {
-  return (1 + token_cache[neighbors[MAX_NEIGHBORS * c + 0]] +
-          token_cache[neighbors[MAX_NEIGHBORS * c + 1]]) >> 1;
-}
-
-static INLINE const scan_order *get_scan(const MACROBLOCKD *xd, TX_SIZE tx_size,
-                                         PLANE_TYPE type, int block_idx) {
-  const MODE_INFO *const mi = xd->mi[0];
-
-  if (is_inter_block(mi) || type != PLANE_TYPE_Y || xd->lossless) {
-    return &vp9_default_scan_orders[tx_size];
-  } else {
-    const PREDICTION_MODE mode = get_y_mode(mi, block_idx);
-    return &vp9_scan_orders[tx_size][intra_mode_to_tx_type_lookup[mode]];
-  }
-}
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP9_COMMON_VP9_SCAN_H_
diff --git a/vp9/common/vp9_seg_common.c b/vp9/common/vp9_seg_common.c
deleted file mode 100644 (file)
index 7af6162..0000000
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#include <assert.h>
-
-#include "vp9/common/vp9_blockd.h"
-#include "vp9/common/vp9_loopfilter.h"
-#include "vp9/common/vp9_seg_common.h"
-#include "vp9/common/vp9_quant_common.h"
-
-static const int seg_feature_data_signed[SEG_LVL_MAX] = { 1, 1, 0, 0 };
-
-static const int seg_feature_data_max[SEG_LVL_MAX] = {
-  MAXQ, MAX_LOOP_FILTER, 3, 0 };
-
-// These functions provide access to new segment level features.
-// Eventually these function may be "optimized out" but for the moment,
-// the coding mechanism is still subject to change so these provide a
-// convenient single point of change.
-
-void vp9_clearall_segfeatures(struct segmentation *seg) {
-  vp9_zero(seg->feature_data);
-  vp9_zero(seg->feature_mask);
-  seg->aq_av_offset = 0;
-}
-
-void vp9_enable_segfeature(struct segmentation *seg, int segment_id,
-                           SEG_LVL_FEATURES feature_id) {
-  seg->feature_mask[segment_id] |= 1 << feature_id;
-}
-
-int vp9_seg_feature_data_max(SEG_LVL_FEATURES feature_id) {
-  return seg_feature_data_max[feature_id];
-}
-
-int vp9_is_segfeature_signed(SEG_LVL_FEATURES feature_id) {
-  return seg_feature_data_signed[feature_id];
-}
-
-void vp9_set_segdata(struct segmentation *seg, int segment_id,
-                     SEG_LVL_FEATURES feature_id, int seg_data) {
-  assert(seg_data <= seg_feature_data_max[feature_id]);
-  if (seg_data < 0) {
-    assert(seg_feature_data_signed[feature_id]);
-    assert(-seg_data <= seg_feature_data_max[feature_id]);
-  }
-
-  seg->feature_data[segment_id][feature_id] = seg_data;
-}
-
-const vpx_tree_index vp9_segment_tree[TREE_SIZE(MAX_SEGMENTS)] = {
-  2,  4,  6,  8, 10, 12,
-  0, -1, -2, -3, -4, -5, -6, -7
-};
-
-
-// TBD? Functions to read and write segment data with range / validity checking
diff --git a/vp9/common/vp9_seg_common.h b/vp9/common/vp9_seg_common.h
deleted file mode 100644 (file)
index 7ea7c3d..0000000
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- *  Copyright (c) 2012 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.
- */
-
-#ifndef VP9_COMMON_VP9_SEG_COMMON_H_
-#define VP9_COMMON_VP9_SEG_COMMON_H_
-
-#include "vpx_dsp/prob.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define SEGMENT_DELTADATA   0
-#define SEGMENT_ABSDATA     1
-
-#define MAX_SEGMENTS     8
-#define SEG_TREE_PROBS   (MAX_SEGMENTS-1)
-
-#define PREDICTION_PROBS 3
-
-// Segment level features.
-typedef enum {
-  SEG_LVL_ALT_Q = 0,               // Use alternate Quantizer ....
-  SEG_LVL_ALT_LF = 1,              // Use alternate loop filter value...
-  SEG_LVL_REF_FRAME = 2,           // Optional Segment reference frame
-  SEG_LVL_SKIP = 3,                // Optional Segment (0,0) + skip mode
-  SEG_LVL_MAX = 4                  // Number of features supported
-} SEG_LVL_FEATURES;
-
-
-struct segmentation {
-  uint8_t enabled;
-  uint8_t update_map;
-  uint8_t update_data;
-  uint8_t abs_delta;
-  uint8_t temporal_update;
-
-  vpx_prob tree_probs[SEG_TREE_PROBS];
-  vpx_prob pred_probs[PREDICTION_PROBS];
-
-  int16_t feature_data[MAX_SEGMENTS][SEG_LVL_MAX];
-  unsigned int feature_mask[MAX_SEGMENTS];
-  int aq_av_offset;
-};
-
-static INLINE int segfeature_active(const struct segmentation *seg,
-                                    int segment_id,
-                                    SEG_LVL_FEATURES feature_id) {
-  return seg->enabled &&
-         (seg->feature_mask[segment_id] & (1 << feature_id));
-}
-
-void vp9_clearall_segfeatures(struct segmentation *seg);
-
-void vp9_enable_segfeature(struct segmentation *seg,
-                           int segment_id,
-                           SEG_LVL_FEATURES feature_id);
-
-int vp9_seg_feature_data_max(SEG_LVL_FEATURES feature_id);
-
-int vp9_is_segfeature_signed(SEG_LVL_FEATURES feature_id);
-
-void vp9_set_segdata(struct segmentation *seg,
-                     int segment_id,
-                     SEG_LVL_FEATURES feature_id,
-                     int seg_data);
-
-static INLINE int get_segdata(const struct segmentation *seg, int segment_id,
-                              SEG_LVL_FEATURES feature_id) {
-  return seg->feature_data[segment_id][feature_id];
-}
-
-extern const vpx_tree_index vp9_segment_tree[TREE_SIZE(MAX_SEGMENTS)];
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP9_COMMON_VP9_SEG_COMMON_H_
-
diff --git a/vp9/common/vp9_textblit.c b/vp9/common/vp9_textblit.c
deleted file mode 100644 (file)
index 60e95e0..0000000
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#include <stdlib.h>
-
-#include "vp9/common/vp9_textblit.h"
-
-static const int font[] = {
-  0x0, 0x5C00, 0x8020, 0xAFABEA, 0xD7EC0, 0x1111111, 0x1855740, 0x18000,
-  0x45C0, 0x74400, 0x51140, 0x23880, 0xC4000, 0x21080, 0x80000, 0x111110,
-  0xE9D72E, 0x87E40, 0x12AD732, 0xAAD62A, 0x4F94C4, 0x4D6B7, 0x456AA,
-  0x3E8423, 0xAAD6AA, 0xAAD6A2, 0x2800, 0x2A00, 0x8A880, 0x52940, 0x22A20,
-  0x15422, 0x6AD62E, 0x1E4A53E, 0xAAD6BF, 0x8C62E, 0xE8C63F, 0x118D6BF,
-  0x1094BF, 0xCAC62E, 0x1F2109F, 0x118FE31, 0xF8C628, 0x8A89F, 0x108421F,
-  0x1F1105F, 0x1F4105F, 0xE8C62E, 0x2294BF, 0x164C62E, 0x12694BF, 0x8AD6A2,
-  0x10FC21, 0x1F8421F, 0x744107, 0xF8220F, 0x1151151, 0x117041, 0x119D731,
-  0x47E0, 0x1041041, 0xFC400, 0x10440, 0x1084210, 0x820
-};
-
-static void plot(int x, int y, unsigned char *image, int pitch) {
-  image[x + y * pitch] ^= 255;
-}
-
-void vp9_blit_text(const char *msg, unsigned char *address, const int pitch) {
-  int letter_bitmap;
-  unsigned char *output_pos = address;
-  int colpos = 0;
-
-  while (msg[colpos] != 0) {
-    char letter = msg[colpos];
-    int fontcol, fontrow;
-
-    if (letter <= 'Z' && letter >= ' ')
-      letter_bitmap = font[letter - ' '];
-    else if (letter <= 'z' && letter >= 'a')
-      letter_bitmap = font[letter - 'a' + 'A' - ' '];
-    else
-      letter_bitmap = font[0];
-
-    for (fontcol = 6; fontcol >= 0; fontcol--)
-      for (fontrow = 0; fontrow < 5; fontrow++)
-        output_pos[fontrow * pitch + fontcol] =
-          ((letter_bitmap >> (fontcol * 5)) & (1 << fontrow) ? 255 : 0);
-
-    output_pos += 7;
-    colpos++;
-  }
-}
-
-
-
-/* Bresenham line algorithm */
-void vp9_blit_line(int x0, int x1, int y0, int y1, unsigned char *image,
-                   int pitch) {
-  int steep = abs(y1 - y0) > abs(x1 - x0);
-  int deltax, deltay;
-  int error, ystep, y, x;
-
-  if (steep) {
-    int t;
-    t = x0;
-    x0 = y0;
-    y0 = t;
-
-    t = x1;
-    x1 = y1;
-    y1 = t;
-  }
-
-  if (x0 > x1) {
-    int t;
-    t = x0;
-    x0 = x1;
-    x1 = t;
-
-    t = y0;
-    y0 = y1;
-    y1 = t;
-  }
-
-  deltax = x1 - x0;
-  deltay = abs(y1 - y0);
-  error  = deltax / 2;
-
-  y = y0;
-
-  if (y0 < y1)
-    ystep = 1;
-  else
-    ystep = -1;
-
-  if (steep) {
-    for (x = x0; x <= x1; x++) {
-      plot(y, x, image, pitch);
-
-      error = error - deltay;
-      if (error < 0) {
-        y = y + ystep;
-        error = error + deltax;
-      }
-    }
-  } else {
-    for (x = x0; x <= x1; x++) {
-      plot(x, y, image, pitch);
-
-      error = error - deltay;
-      if (error < 0) {
-        y = y + ystep;
-        error = error + deltax;
-      }
-    }
-  }
-}
diff --git a/vp9/common/vp9_textblit.h b/vp9/common/vp9_textblit.h
deleted file mode 100644 (file)
index 158ec1b..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#ifndef VP9_COMMON_VP9_TEXTBLIT_H_
-#define VP9_COMMON_VP9_TEXTBLIT_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-void vp9_blit_text(const char *msg, unsigned char *address, int pitch);
-
-void vp9_blit_line(int x0, int x1, int y0, int y1, unsigned char *image,
-                   int pitch);
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP9_COMMON_VP9_TEXTBLIT_H_
diff --git a/vp9/common/vp9_thread_common.c b/vp9/common/vp9_thread_common.c
deleted file mode 100644 (file)
index 033326d..0000000
+++ /dev/null
@@ -1,435 +0,0 @@
-/*
- *  Copyright (c) 2014 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.
- */
-
-#include "./vpx_config.h"
-#include "vpx_dsp/vpx_dsp_common.h"
-#include "vpx_mem/vpx_mem.h"
-#include "vp9/common/vp9_entropymode.h"
-#include "vp9/common/vp9_thread_common.h"
-#include "vp9/common/vp9_reconinter.h"
-#include "vp9/common/vp9_loopfilter.h"
-
-#if CONFIG_MULTITHREAD
-static INLINE void mutex_lock(pthread_mutex_t *const mutex) {
-  const int kMaxTryLocks = 4000;
-  int locked = 0;
-  int i;
-
-  for (i = 0; i < kMaxTryLocks; ++i) {
-    if (!pthread_mutex_trylock(mutex)) {
-      locked = 1;
-      break;
-    }
-  }
-
-  if (!locked)
-    pthread_mutex_lock(mutex);
-}
-#endif  // CONFIG_MULTITHREAD
-
-static INLINE void sync_read(VP9LfSync *const lf_sync, int r, int c) {
-#if CONFIG_MULTITHREAD
-  const int nsync = lf_sync->sync_range;
-
-  if (r && !(c & (nsync - 1))) {
-    pthread_mutex_t *const mutex = &lf_sync->mutex_[r - 1];
-    mutex_lock(mutex);
-
-    while (c > lf_sync->cur_sb_col[r - 1] - nsync) {
-      pthread_cond_wait(&lf_sync->cond_[r - 1], mutex);
-    }
-    pthread_mutex_unlock(mutex);
-  }
-#else
-  (void)lf_sync;
-  (void)r;
-  (void)c;
-#endif  // CONFIG_MULTITHREAD
-}
-
-static INLINE void sync_write(VP9LfSync *const lf_sync, int r, int c,
-                              const int sb_cols) {
-#if CONFIG_MULTITHREAD
-  const int nsync = lf_sync->sync_range;
-  int cur;
-  // Only signal when there are enough filtered SB for next row to run.
-  int sig = 1;
-
-  if (c < sb_cols - 1) {
-    cur = c;
-    if (c % nsync)
-      sig = 0;
-  } else {
-    cur = sb_cols + nsync;
-  }
-
-  if (sig) {
-    mutex_lock(&lf_sync->mutex_[r]);
-
-    lf_sync->cur_sb_col[r] = cur;
-
-    pthread_cond_signal(&lf_sync->cond_[r]);
-    pthread_mutex_unlock(&lf_sync->mutex_[r]);
-  }
-#else
-  (void)lf_sync;
-  (void)r;
-  (void)c;
-  (void)sb_cols;
-#endif  // CONFIG_MULTITHREAD
-}
-
-// Implement row loopfiltering for each thread.
-static INLINE
-void thread_loop_filter_rows(const YV12_BUFFER_CONFIG *const frame_buffer,
-                             VP9_COMMON *const cm,
-                             struct macroblockd_plane planes[MAX_MB_PLANE],
-                             int start, int stop, int y_only,
-                             VP9LfSync *const lf_sync) {
-  const int num_planes = y_only ? 1 : MAX_MB_PLANE;
-  const int sb_cols = mi_cols_aligned_to_sb(cm->mi_cols) >> MI_BLOCK_SIZE_LOG2;
-  int mi_row, mi_col;
-  enum lf_path path;
-  if (y_only)
-    path = LF_PATH_444;
-  else if (planes[1].subsampling_y == 1 && planes[1].subsampling_x == 1)
-    path = LF_PATH_420;
-  else if (planes[1].subsampling_y == 0 && planes[1].subsampling_x == 0)
-    path = LF_PATH_444;
-  else
-    path = LF_PATH_SLOW;
-
-  for (mi_row = start; mi_row < stop;
-       mi_row += lf_sync->num_workers * MI_BLOCK_SIZE) {
-    MODE_INFO **const mi = cm->mi_grid_visible + mi_row * cm->mi_stride;
-    LOOP_FILTER_MASK *lfm = get_lfm(&cm->lf, mi_row, 0);
-
-    for (mi_col = 0; mi_col < cm->mi_cols; mi_col += MI_BLOCK_SIZE, ++lfm) {
-      const int r = mi_row >> MI_BLOCK_SIZE_LOG2;
-      const int c = mi_col >> MI_BLOCK_SIZE_LOG2;
-      int plane;
-
-      sync_read(lf_sync, r, c);
-
-      vp9_setup_dst_planes(planes, frame_buffer, mi_row, mi_col);
-
-      vp9_adjust_mask(cm, mi_row, mi_col, lfm);
-
-      vp9_filter_block_plane_ss00(cm, &planes[0], mi_row, lfm);
-      for (plane = 1; plane < num_planes; ++plane) {
-        switch (path) {
-          case LF_PATH_420:
-            vp9_filter_block_plane_ss11(cm, &planes[plane], mi_row, lfm);
-            break;
-          case LF_PATH_444:
-            vp9_filter_block_plane_ss00(cm, &planes[plane], mi_row, lfm);
-            break;
-          case LF_PATH_SLOW:
-            vp9_filter_block_plane_non420(cm, &planes[plane], mi + mi_col,
-                                          mi_row, mi_col);
-            break;
-        }
-      }
-
-      sync_write(lf_sync, r, c, sb_cols);
-    }
-  }
-}
-
-// Row-based multi-threaded loopfilter hook
-static int loop_filter_row_worker(VP9LfSync *const lf_sync,
-                                  LFWorkerData *const lf_data) {
-  thread_loop_filter_rows(lf_data->frame_buffer, lf_data->cm, lf_data->planes,
-                          lf_data->start, lf_data->stop, lf_data->y_only,
-                          lf_sync);
-  return 1;
-}
-
-static void loop_filter_rows_mt(YV12_BUFFER_CONFIG *frame,
-                                VP9_COMMON *cm,
-                                struct macroblockd_plane planes[MAX_MB_PLANE],
-                                int start, int stop, int y_only,
-                                VPxWorker *workers, int nworkers,
-                                VP9LfSync *lf_sync) {
-  const VPxWorkerInterface *const winterface = vpx_get_worker_interface();
-  // Number of superblock rows and cols
-  const int sb_rows = mi_cols_aligned_to_sb(cm->mi_rows) >> MI_BLOCK_SIZE_LOG2;
-  // Decoder may allocate more threads than number of tiles based on user's
-  // input.
-  const int tile_cols = 1 << cm->log2_tile_cols;
-  const int num_workers = VPXMIN(nworkers, tile_cols);
-  int i;
-
-  if (!lf_sync->sync_range || sb_rows != lf_sync->rows ||
-      num_workers > lf_sync->num_workers) {
-    vp9_loop_filter_dealloc(lf_sync);
-    vp9_loop_filter_alloc(lf_sync, cm, sb_rows, cm->width, num_workers);
-  }
-
-  // Initialize cur_sb_col to -1 for all SB rows.
-  memset(lf_sync->cur_sb_col, -1, sizeof(*lf_sync->cur_sb_col) * sb_rows);
-
-  // Set up loopfilter thread data.
-  // The decoder is capping num_workers because it has been observed that using
-  // more threads on the loopfilter than there are cores will hurt performance
-  // on Android. This is because the system will only schedule the tile decode
-  // workers on cores equal to the number of tile columns. Then if the decoder
-  // tries to use more threads for the loopfilter, it will hurt performance
-  // because of contention. If the multithreading code changes in the future
-  // then the number of workers used by the loopfilter should be revisited.
-  for (i = 0; i < num_workers; ++i) {
-    VPxWorker *const worker = &workers[i];
-    LFWorkerData *const lf_data = &lf_sync->lfdata[i];
-
-    worker->hook = (VPxWorkerHook)loop_filter_row_worker;
-    worker->data1 = lf_sync;
-    worker->data2 = lf_data;
-
-    // Loopfilter data
-    vp9_loop_filter_data_reset(lf_data, frame, cm, planes);
-    lf_data->start = start + i * MI_BLOCK_SIZE;
-    lf_data->stop = stop;
-    lf_data->y_only = y_only;
-
-    // Start loopfiltering
-    if (i == num_workers - 1) {
-      winterface->execute(worker);
-    } else {
-      winterface->launch(worker);
-    }
-  }
-
-  // Wait till all rows are finished
-  for (i = 0; i < num_workers; ++i) {
-    winterface->sync(&workers[i]);
-  }
-}
-
-void vp9_loop_filter_frame_mt(YV12_BUFFER_CONFIG *frame,
-                              VP9_COMMON *cm,
-                              struct macroblockd_plane planes[MAX_MB_PLANE],
-                              int frame_filter_level,
-                              int y_only, int partial_frame,
-                              VPxWorker *workers, int num_workers,
-                              VP9LfSync *lf_sync) {
-  int start_mi_row, end_mi_row, mi_rows_to_filter;
-
-  if (!frame_filter_level) return;
-
-  start_mi_row = 0;
-  mi_rows_to_filter = cm->mi_rows;
-  if (partial_frame && cm->mi_rows > 8) {
-    start_mi_row = cm->mi_rows >> 1;
-    start_mi_row &= 0xfffffff8;
-    mi_rows_to_filter = VPXMAX(cm->mi_rows / 8, 8);
-  }
-  end_mi_row = start_mi_row + mi_rows_to_filter;
-  vp9_loop_filter_frame_init(cm, frame_filter_level);
-
-  loop_filter_rows_mt(frame, cm, planes, start_mi_row, end_mi_row,
-                      y_only, workers, num_workers, lf_sync);
-}
-
-// Set up nsync by width.
-static INLINE int get_sync_range(int width) {
-  // nsync numbers are picked by testing. For example, for 4k
-  // video, using 4 gives best performance.
-  if (width < 640)
-    return 1;
-  else if (width <= 1280)
-    return 2;
-  else if (width <= 4096)
-    return 4;
-  else
-    return 8;
-}
-
-// Allocate memory for lf row synchronization
-void vp9_loop_filter_alloc(VP9LfSync *lf_sync, VP9_COMMON *cm, int rows,
-                           int width, int num_workers) {
-  lf_sync->rows = rows;
-#if CONFIG_MULTITHREAD
-  {
-    int i;
-
-    CHECK_MEM_ERROR(cm, lf_sync->mutex_,
-                    vpx_malloc(sizeof(*lf_sync->mutex_) * rows));
-    if (lf_sync->mutex_) {
-      for (i = 0; i < rows; ++i) {
-        pthread_mutex_init(&lf_sync->mutex_[i], NULL);
-      }
-    }
-
-    CHECK_MEM_ERROR(cm, lf_sync->cond_,
-                    vpx_malloc(sizeof(*lf_sync->cond_) * rows));
-    if (lf_sync->cond_) {
-      for (i = 0; i < rows; ++i) {
-        pthread_cond_init(&lf_sync->cond_[i], NULL);
-      }
-    }
-  }
-#endif  // CONFIG_MULTITHREAD
-
-  CHECK_MEM_ERROR(cm, lf_sync->lfdata,
-                  vpx_malloc(num_workers * sizeof(*lf_sync->lfdata)));
-  lf_sync->num_workers = num_workers;
-
-  CHECK_MEM_ERROR(cm, lf_sync->cur_sb_col,
-                  vpx_malloc(sizeof(*lf_sync->cur_sb_col) * rows));
-
-  // Set up nsync.
-  lf_sync->sync_range = get_sync_range(width);
-}
-
-// Deallocate lf synchronization related mutex and data
-void vp9_loop_filter_dealloc(VP9LfSync *lf_sync) {
-  if (lf_sync != NULL) {
-#if CONFIG_MULTITHREAD
-    int i;
-
-    if (lf_sync->mutex_ != NULL) {
-      for (i = 0; i < lf_sync->rows; ++i) {
-        pthread_mutex_destroy(&lf_sync->mutex_[i]);
-      }
-      vpx_free(lf_sync->mutex_);
-    }
-    if (lf_sync->cond_ != NULL) {
-      for (i = 0; i < lf_sync->rows; ++i) {
-        pthread_cond_destroy(&lf_sync->cond_[i]);
-      }
-      vpx_free(lf_sync->cond_);
-    }
-#endif  // CONFIG_MULTITHREAD
-    vpx_free(lf_sync->lfdata);
-    vpx_free(lf_sync->cur_sb_col);
-    // clear the structure as the source of this call may be a resize in which
-    // case this call will be followed by an _alloc() which may fail.
-    vp9_zero(*lf_sync);
-  }
-}
-
-// Accumulate frame counts.
-void vp9_accumulate_frame_counts(FRAME_COUNTS *accum,
-                                 const FRAME_COUNTS *counts, int is_dec) {
-  int i, j, k, l, m;
-
-  for (i = 0; i < BLOCK_SIZE_GROUPS; i++)
-    for (j = 0; j < INTRA_MODES; j++)
-      accum->y_mode[i][j] += counts->y_mode[i][j];
-
-  for (i = 0; i < INTRA_MODES; i++)
-    for (j = 0; j < INTRA_MODES; j++)
-      accum->uv_mode[i][j] += counts->uv_mode[i][j];
-
-  for (i = 0; i < PARTITION_CONTEXTS; i++)
-    for (j = 0; j < PARTITION_TYPES; j++)
-      accum->partition[i][j] += counts->partition[i][j];
-
-  if (is_dec) {
-    int n;
-    for (i = 0; i < TX_SIZES; i++)
-      for (j = 0; j < PLANE_TYPES; j++)
-        for (k = 0; k < REF_TYPES; k++)
-          for (l = 0; l < COEF_BANDS; l++)
-            for (m = 0; m < COEFF_CONTEXTS; m++) {
-              accum->eob_branch[i][j][k][l][m] +=
-                  counts->eob_branch[i][j][k][l][m];
-              for (n = 0; n < UNCONSTRAINED_NODES + 1; n++)
-                accum->coef[i][j][k][l][m][n] +=
-                    counts->coef[i][j][k][l][m][n];
-            }
-  } else {
-    for (i = 0; i < TX_SIZES; i++)
-      for (j = 0; j < PLANE_TYPES; j++)
-        for (k = 0; k < REF_TYPES; k++)
-          for (l = 0; l < COEF_BANDS; l++)
-            for (m = 0; m < COEFF_CONTEXTS; m++)
-              accum->eob_branch[i][j][k][l][m] +=
-                  counts->eob_branch[i][j][k][l][m];
-                // In the encoder, coef is only updated at frame
-                // level, so not need to accumulate it here.
-                // for (n = 0; n < UNCONSTRAINED_NODES + 1; n++)
-                //   accum->coef[i][j][k][l][m][n] +=
-                //       counts->coef[i][j][k][l][m][n];
-  }
-
-  for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++)
-    for (j = 0; j < SWITCHABLE_FILTERS; j++)
-      accum->switchable_interp[i][j] += counts->switchable_interp[i][j];
-
-  for (i = 0; i < INTER_MODE_CONTEXTS; i++)
-    for (j = 0; j < INTER_MODES; j++)
-      accum->inter_mode[i][j] += counts->inter_mode[i][j];
-
-  for (i = 0; i < INTRA_INTER_CONTEXTS; i++)
-    for (j = 0; j < 2; j++)
-      accum->intra_inter[i][j] += counts->intra_inter[i][j];
-
-  for (i = 0; i < COMP_INTER_CONTEXTS; i++)
-    for (j = 0; j < 2; j++)
-      accum->comp_inter[i][j] += counts->comp_inter[i][j];
-
-  for (i = 0; i < REF_CONTEXTS; i++)
-    for (j = 0; j < 2; j++)
-      for (k = 0; k < 2; k++)
-        accum->single_ref[i][j][k] += counts->single_ref[i][j][k];
-
-  for (i = 0; i < REF_CONTEXTS; i++)
-    for (j = 0; j < 2; j++)
-        accum->comp_ref[i][j] += counts->comp_ref[i][j];
-
-  for (i = 0; i < TX_SIZE_CONTEXTS; i++) {
-    for (j = 0; j < TX_SIZES; j++)
-      accum->tx.p32x32[i][j] += counts->tx.p32x32[i][j];
-
-    for (j = 0; j < TX_SIZES - 1; j++)
-      accum->tx.p16x16[i][j] += counts->tx.p16x16[i][j];
-
-    for (j = 0; j < TX_SIZES - 2; j++)
-      accum->tx.p8x8[i][j] += counts->tx.p8x8[i][j];
-  }
-
-  for (i = 0; i < TX_SIZES; i++)
-    accum->tx.tx_totals[i] += counts->tx.tx_totals[i];
-
-  for (i = 0; i < SKIP_CONTEXTS; i++)
-    for (j = 0; j < 2; j++)
-      accum->skip[i][j] += counts->skip[i][j];
-
-  for (i = 0; i < MV_JOINTS; i++)
-    accum->mv.joints[i] += counts->mv.joints[i];
-
-  for (k = 0; k < 2; k++) {
-    nmv_component_counts *const comps = &accum->mv.comps[k];
-    const nmv_component_counts *const comps_t = &counts->mv.comps[k];
-
-    for (i = 0; i < 2; i++) {
-      comps->sign[i] += comps_t->sign[i];
-      comps->class0_hp[i] += comps_t->class0_hp[i];
-      comps->hp[i] += comps_t->hp[i];
-    }
-
-    for (i = 0; i < MV_CLASSES; i++)
-      comps->classes[i] += comps_t->classes[i];
-
-    for (i = 0; i < CLASS0_SIZE; i++) {
-      comps->class0[i] += comps_t->class0[i];
-      for (j = 0; j < MV_FP_SIZE; j++)
-        comps->class0_fp[i][j] += comps_t->class0_fp[i][j];
-    }
-
-    for (i = 0; i < MV_OFFSET_BITS; i++)
-      for (j = 0; j < 2; j++)
-        comps->bits[i][j] += comps_t->bits[i][j];
-
-    for (i = 0; i < MV_FP_SIZE; i++)
-      comps->fp[i] += comps_t->fp[i];
-  }
-}
diff --git a/vp9/common/vp9_thread_common.h b/vp9/common/vp9_thread_common.h
deleted file mode 100644 (file)
index b3b60c2..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- *  Copyright (c) 2014 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.
- */
-
-#ifndef VP9_COMMON_VP9_THREAD_COMMON_H_
-#define VP9_COMMON_VP9_THREAD_COMMON_H_
-#include "./vpx_config.h"
-#include "vp9/common/vp9_loopfilter.h"
-#include "vpx_util/vpx_thread.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-struct VP9Common;
-struct FRAME_COUNTS;
-
-// Loopfilter row synchronization
-typedef struct VP9LfSyncData {
-#if CONFIG_MULTITHREAD
-  pthread_mutex_t *mutex_;
-  pthread_cond_t *cond_;
-#endif
-  // Allocate memory to store the loop-filtered superblock index in each row.
-  int *cur_sb_col;
-  // The optimal sync_range for different resolution and platform should be
-  // determined by testing. Currently, it is chosen to be a power-of-2 number.
-  int sync_range;
-  int rows;
-
-  // Row-based parallel loopfilter data
-  LFWorkerData *lfdata;
-  int num_workers;
-} VP9LfSync;
-
-// Allocate memory for loopfilter row synchronization.
-void vp9_loop_filter_alloc(VP9LfSync *lf_sync, struct VP9Common *cm, int rows,
-                           int width, int num_workers);
-
-// Deallocate loopfilter synchronization related mutex and data.
-void vp9_loop_filter_dealloc(VP9LfSync *lf_sync);
-
-// Multi-threaded loopfilter that uses the tile threads.
-void vp9_loop_filter_frame_mt(YV12_BUFFER_CONFIG *frame,
-                              struct VP9Common *cm,
-                              struct macroblockd_plane planes[MAX_MB_PLANE],
-                              int frame_filter_level,
-                              int y_only, int partial_frame,
-                              VPxWorker *workers, int num_workers,
-                              VP9LfSync *lf_sync);
-
-void vp9_accumulate_frame_counts(struct FRAME_COUNTS *accum,
-                                 const struct FRAME_COUNTS *counts, int is_dec);
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP9_COMMON_VP9_THREAD_COMMON_H_
diff --git a/vp9/common/vp9_tile_common.c b/vp9/common/vp9_tile_common.c
deleted file mode 100644 (file)
index 9fcb97c..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#include "vp9/common/vp9_tile_common.h"
-#include "vp9/common/vp9_onyxc_int.h"
-#include "vpx_dsp/vpx_dsp_common.h"
-
-#define MIN_TILE_WIDTH_B64 4
-#define MAX_TILE_WIDTH_B64 64
-
-static int get_tile_offset(int idx, int mis, int log2) {
-  const int sb_cols = mi_cols_aligned_to_sb(mis) >> MI_BLOCK_SIZE_LOG2;
-  const int offset = ((idx * sb_cols) >> log2) << MI_BLOCK_SIZE_LOG2;
-  return VPXMIN(offset, mis);
-}
-
-void vp9_tile_set_row(TileInfo *tile, const VP9_COMMON *cm, int row) {
-  tile->mi_row_start = get_tile_offset(row, cm->mi_rows, cm->log2_tile_rows);
-  tile->mi_row_end = get_tile_offset(row + 1, cm->mi_rows, cm->log2_tile_rows);
-}
-
-void vp9_tile_set_col(TileInfo *tile, const VP9_COMMON *cm, int col) {
-  tile->mi_col_start = get_tile_offset(col, cm->mi_cols, cm->log2_tile_cols);
-  tile->mi_col_end = get_tile_offset(col + 1, cm->mi_cols, cm->log2_tile_cols);
-}
-
-void vp9_tile_init(TileInfo *tile, const VP9_COMMON *cm, int row, int col) {
-  vp9_tile_set_row(tile, cm, row);
-  vp9_tile_set_col(tile, cm, col);
-}
-
-static int get_min_log2_tile_cols(const int sb64_cols) {
-  int min_log2 = 0;
-  while ((MAX_TILE_WIDTH_B64 << min_log2) < sb64_cols)
-    ++min_log2;
-  return min_log2;
-}
-
-static int get_max_log2_tile_cols(const int sb64_cols) {
-  int max_log2 = 1;
-  while ((sb64_cols >> max_log2) >= MIN_TILE_WIDTH_B64)
-    ++max_log2;
-  return max_log2 - 1;
-}
-
-void vp9_get_tile_n_bits(int mi_cols,
-                         int *min_log2_tile_cols, int *max_log2_tile_cols) {
-  const int sb64_cols = mi_cols_aligned_to_sb(mi_cols) >> MI_BLOCK_SIZE_LOG2;
-  *min_log2_tile_cols = get_min_log2_tile_cols(sb64_cols);
-  *max_log2_tile_cols = get_max_log2_tile_cols(sb64_cols);
-  assert(*min_log2_tile_cols <= *max_log2_tile_cols);
-}
diff --git a/vp9/common/vp9_tile_common.h b/vp9/common/vp9_tile_common.h
deleted file mode 100644 (file)
index ae58805..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#ifndef VP9_COMMON_VP9_TILE_COMMON_H_
-#define VP9_COMMON_VP9_TILE_COMMON_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-struct VP9Common;
-
-typedef struct TileInfo {
-  int mi_row_start, mi_row_end;
-  int mi_col_start, mi_col_end;
-} TileInfo;
-
-// initializes 'tile->mi_(row|col)_(start|end)' for (row, col) based on
-// 'cm->log2_tile_(rows|cols)' & 'cm->mi_(rows|cols)'
-void vp9_tile_init(TileInfo *tile, const struct VP9Common *cm,
-                   int row, int col);
-
-void vp9_tile_set_row(TileInfo *tile, const struct VP9Common *cm, int row);
-void vp9_tile_set_col(TileInfo *tile, const struct VP9Common *cm, int col);
-
-void vp9_get_tile_n_bits(int mi_cols,
-                         int *min_log2_tile_cols, int *max_log2_tile_cols);
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP9_COMMON_VP9_TILE_COMMON_H_
diff --git a/vp9/common/x86/vp9_idct_intrin_sse2.c b/vp9/common/x86/vp9_idct_intrin_sse2.c
deleted file mode 100644 (file)
index 1c77b57..0000000
+++ /dev/null
@@ -1,181 +0,0 @@
-/*
- *  Copyright (c) 2012 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.
- */
-
-#include "./vp9_rtcd.h"
-#include "vpx_dsp/x86/inv_txfm_sse2.h"
-#include "vpx_dsp/x86/txfm_common_sse2.h"
-#include "vpx_ports/mem.h"
-
-void vp9_iht4x4_16_add_sse2(const tran_low_t *input, uint8_t *dest, int stride,
-                            int tx_type) {
-  __m128i in[2];
-  const __m128i zero = _mm_setzero_si128();
-  const __m128i eight = _mm_set1_epi16(8);
-
-  in[0] = load_input_data(input);
-  in[1] = load_input_data(input + 8);
-
-  switch (tx_type) {
-    case 0:  // DCT_DCT
-      idct4_sse2(in);
-      idct4_sse2(in);
-      break;
-    case 1:  // ADST_DCT
-      idct4_sse2(in);
-      iadst4_sse2(in);
-      break;
-    case 2:  // DCT_ADST
-      iadst4_sse2(in);
-      idct4_sse2(in);
-      break;
-    case 3:  // ADST_ADST
-      iadst4_sse2(in);
-      iadst4_sse2(in);
-      break;
-    default:
-      assert(0);
-      break;
-  }
-
-  // Final round and shift
-  in[0] = _mm_add_epi16(in[0], eight);
-  in[1] = _mm_add_epi16(in[1], eight);
-
-  in[0] = _mm_srai_epi16(in[0], 4);
-  in[1] = _mm_srai_epi16(in[1], 4);
-
-  // Reconstruction and Store
-  {
-    __m128i d0 = _mm_cvtsi32_si128(*(const int *)(dest));
-    __m128i d2 = _mm_cvtsi32_si128(*(const int *)(dest + stride * 2));
-    d0 = _mm_unpacklo_epi32(d0,
-                            _mm_cvtsi32_si128(*(const int *)(dest + stride)));
-    d2 = _mm_unpacklo_epi32(
-        d2, _mm_cvtsi32_si128(*(const int *)(dest + stride * 3)));
-    d0 = _mm_unpacklo_epi8(d0, zero);
-    d2 = _mm_unpacklo_epi8(d2, zero);
-    d0 = _mm_add_epi16(d0, in[0]);
-    d2 = _mm_add_epi16(d2, in[1]);
-    d0 = _mm_packus_epi16(d0, d2);
-    // store result[0]
-    *(int *)dest = _mm_cvtsi128_si32(d0);
-    // store result[1]
-    d0 = _mm_srli_si128(d0, 4);
-    *(int *)(dest + stride) = _mm_cvtsi128_si32(d0);
-    // store result[2]
-    d0 = _mm_srli_si128(d0, 4);
-    *(int *)(dest + stride * 2) = _mm_cvtsi128_si32(d0);
-    // store result[3]
-    d0 = _mm_srli_si128(d0, 4);
-    *(int *)(dest + stride * 3) = _mm_cvtsi128_si32(d0);
-  }
-}
-
-void vp9_iht8x8_64_add_sse2(const tran_low_t *input, uint8_t *dest, int stride,
-                            int tx_type) {
-  __m128i in[8];
-  const __m128i zero = _mm_setzero_si128();
-  const __m128i final_rounding = _mm_set1_epi16(1 << 4);
-
-  // load input data
-  in[0] = load_input_data(input);
-  in[1] = load_input_data(input + 8 * 1);
-  in[2] = load_input_data(input + 8 * 2);
-  in[3] = load_input_data(input + 8 * 3);
-  in[4] = load_input_data(input + 8 * 4);
-  in[5] = load_input_data(input + 8 * 5);
-  in[6] = load_input_data(input + 8 * 6);
-  in[7] = load_input_data(input + 8 * 7);
-
-  switch (tx_type) {
-    case 0:  // DCT_DCT
-      idct8_sse2(in);
-      idct8_sse2(in);
-      break;
-    case 1:  // ADST_DCT
-      idct8_sse2(in);
-      iadst8_sse2(in);
-      break;
-    case 2:  // DCT_ADST
-      iadst8_sse2(in);
-      idct8_sse2(in);
-      break;
-    case 3:  // ADST_ADST
-      iadst8_sse2(in);
-      iadst8_sse2(in);
-      break;
-    default:
-      assert(0);
-      break;
-  }
-
-  // Final rounding and shift
-  in[0] = _mm_adds_epi16(in[0], final_rounding);
-  in[1] = _mm_adds_epi16(in[1], final_rounding);
-  in[2] = _mm_adds_epi16(in[2], final_rounding);
-  in[3] = _mm_adds_epi16(in[3], final_rounding);
-  in[4] = _mm_adds_epi16(in[4], final_rounding);
-  in[5] = _mm_adds_epi16(in[5], final_rounding);
-  in[6] = _mm_adds_epi16(in[6], final_rounding);
-  in[7] = _mm_adds_epi16(in[7], final_rounding);
-
-  in[0] = _mm_srai_epi16(in[0], 5);
-  in[1] = _mm_srai_epi16(in[1], 5);
-  in[2] = _mm_srai_epi16(in[2], 5);
-  in[3] = _mm_srai_epi16(in[3], 5);
-  in[4] = _mm_srai_epi16(in[4], 5);
-  in[5] = _mm_srai_epi16(in[5], 5);
-  in[6] = _mm_srai_epi16(in[6], 5);
-  in[7] = _mm_srai_epi16(in[7], 5);
-
-  RECON_AND_STORE(dest + 0 * stride, in[0]);
-  RECON_AND_STORE(dest + 1 * stride, in[1]);
-  RECON_AND_STORE(dest + 2 * stride, in[2]);
-  RECON_AND_STORE(dest + 3 * stride, in[3]);
-  RECON_AND_STORE(dest + 4 * stride, in[4]);
-  RECON_AND_STORE(dest + 5 * stride, in[5]);
-  RECON_AND_STORE(dest + 6 * stride, in[6]);
-  RECON_AND_STORE(dest + 7 * stride, in[7]);
-}
-
-void vp9_iht16x16_256_add_sse2(const tran_low_t *input, uint8_t *dest,
-                               int stride, int tx_type) {
-  __m128i in0[16], in1[16];
-
-  load_buffer_8x16(input, in0);
-  input += 8;
-  load_buffer_8x16(input, in1);
-
-  switch (tx_type) {
-    case 0:  // DCT_DCT
-      idct16_sse2(in0, in1);
-      idct16_sse2(in0, in1);
-      break;
-    case 1:  // ADST_DCT
-      idct16_sse2(in0, in1);
-      iadst16_sse2(in0, in1);
-      break;
-    case 2:  // DCT_ADST
-      iadst16_sse2(in0, in1);
-      idct16_sse2(in0, in1);
-      break;
-    case 3:  // ADST_ADST
-      iadst16_sse2(in0, in1);
-      iadst16_sse2(in0, in1);
-      break;
-    default:
-      assert(0);
-      break;
-  }
-
-  write_buffer_8x16(dest, in0, stride);
-  dest += 8;
-  write_buffer_8x16(dest, in1, stride);
-}
diff --git a/vp9/common/x86/vp9_mfqe_sse2.asm b/vp9/common/x86/vp9_mfqe_sse2.asm
deleted file mode 100644 (file)
index 3085204..0000000
+++ /dev/null
@@ -1,287 +0,0 @@
-;
-;  Copyright (c) 2015 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.
-;
-
-;  This file is a duplicate of mfqe_sse2.asm in VP8.
-;  TODO(jackychen): Find a way to fix the duplicate.
-%include "vpx_ports/x86_abi_support.asm"
-
-;void vp9_filter_by_weight16x16_sse2
-;(
-;    unsigned char *src,
-;    int            src_stride,
-;    unsigned char *dst,
-;    int            dst_stride,
-;    int            src_weight
-;)
-global sym(vp9_filter_by_weight16x16_sse2) PRIVATE
-sym(vp9_filter_by_weight16x16_sse2):
-    push        rbp
-    mov         rbp, rsp
-    SHADOW_ARGS_TO_STACK 5
-    SAVE_XMM 6
-    GET_GOT     rbx
-    push        rsi
-    push        rdi
-    ; end prolog
-
-    movd        xmm0, arg(4)                ; src_weight
-    pshuflw     xmm0, xmm0, 0x0             ; replicate to all low words
-    punpcklqdq  xmm0, xmm0                  ; replicate to all hi words
-
-    movdqa      xmm1, [GLOBAL(tMFQE)]
-    psubw       xmm1, xmm0                  ; dst_weight
-
-    mov         rax, arg(0)                 ; src
-    mov         rsi, arg(1)                 ; src_stride
-    mov         rdx, arg(2)                 ; dst
-    mov         rdi, arg(3)                 ; dst_stride
-
-    mov         rcx, 16                     ; loop count
-    pxor        xmm6, xmm6
-
-.combine:
-    movdqa      xmm2, [rax]
-    movdqa      xmm4, [rdx]
-    add         rax, rsi
-
-    ; src * src_weight
-    movdqa      xmm3, xmm2
-    punpcklbw   xmm2, xmm6
-    punpckhbw   xmm3, xmm6
-    pmullw      xmm2, xmm0
-    pmullw      xmm3, xmm0
-
-    ; dst * dst_weight
-    movdqa      xmm5, xmm4
-    punpcklbw   xmm4, xmm6
-    punpckhbw   xmm5, xmm6
-    pmullw      xmm4, xmm1
-    pmullw      xmm5, xmm1
-
-    ; sum, round and shift
-    paddw       xmm2, xmm4
-    paddw       xmm3, xmm5
-    paddw       xmm2, [GLOBAL(tMFQE_round)]
-    paddw       xmm3, [GLOBAL(tMFQE_round)]
-    psrlw       xmm2, 4
-    psrlw       xmm3, 4
-
-    packuswb    xmm2, xmm3
-    movdqa      [rdx], xmm2
-    add         rdx, rdi
-
-    dec         rcx
-    jnz         .combine
-
-    ; begin epilog
-    pop         rdi
-    pop         rsi
-    RESTORE_GOT
-    RESTORE_XMM
-    UNSHADOW_ARGS
-    pop         rbp
-
-    ret
-
-;void vp9_filter_by_weight8x8_sse2
-;(
-;    unsigned char *src,
-;    int            src_stride,
-;    unsigned char *dst,
-;    int            dst_stride,
-;    int            src_weight
-;)
-global sym(vp9_filter_by_weight8x8_sse2) PRIVATE
-sym(vp9_filter_by_weight8x8_sse2):
-    push        rbp
-    mov         rbp, rsp
-    SHADOW_ARGS_TO_STACK 5
-    GET_GOT     rbx
-    push        rsi
-    push        rdi
-    ; end prolog
-
-    movd        xmm0, arg(4)                ; src_weight
-    pshuflw     xmm0, xmm0, 0x0             ; replicate to all low words
-    punpcklqdq  xmm0, xmm0                  ; replicate to all hi words
-
-    movdqa      xmm1, [GLOBAL(tMFQE)]
-    psubw       xmm1, xmm0                  ; dst_weight
-
-    mov         rax, arg(0)                 ; src
-    mov         rsi, arg(1)                 ; src_stride
-    mov         rdx, arg(2)                 ; dst
-    mov         rdi, arg(3)                 ; dst_stride
-
-    mov         rcx, 8                      ; loop count
-    pxor        xmm4, xmm4
-
-.combine:
-    movq        xmm2, [rax]
-    movq        xmm3, [rdx]
-    add         rax, rsi
-
-    ; src * src_weight
-    punpcklbw   xmm2, xmm4
-    pmullw      xmm2, xmm0
-
-    ; dst * dst_weight
-    punpcklbw   xmm3, xmm4
-    pmullw      xmm3, xmm1
-
-    ; sum, round and shift
-    paddw       xmm2, xmm3
-    paddw       xmm2, [GLOBAL(tMFQE_round)]
-    psrlw       xmm2, 4
-
-    packuswb    xmm2, xmm4
-    movq        [rdx], xmm2
-    add         rdx, rdi
-
-    dec         rcx
-    jnz         .combine
-
-    ; begin epilog
-    pop         rdi
-    pop         rsi
-    RESTORE_GOT
-    UNSHADOW_ARGS
-    pop         rbp
-
-    ret
-
-;void vp9_variance_and_sad_16x16_sse2 | arg
-;(
-;    unsigned char *src1,          0
-;    int            stride1,       1
-;    unsigned char *src2,          2
-;    int            stride2,       3
-;    unsigned int  *variance,      4
-;    unsigned int  *sad,           5
-;)
-global sym(vp9_variance_and_sad_16x16_sse2) PRIVATE
-sym(vp9_variance_and_sad_16x16_sse2):
-    push        rbp
-    mov         rbp, rsp
-    SHADOW_ARGS_TO_STACK 6
-    GET_GOT     rbx
-    push        rsi
-    push        rdi
-    ; end prolog
-
-    mov         rax,        arg(0)          ; src1
-    mov         rcx,        arg(1)          ; stride1
-    mov         rdx,        arg(2)          ; src2
-    mov         rdi,        arg(3)          ; stride2
-
-    mov         rsi,        16              ; block height
-
-    ; Prep accumulator registers
-    pxor        xmm3, xmm3                  ; SAD
-    pxor        xmm4, xmm4                  ; sum of src2
-    pxor        xmm5, xmm5                  ; sum of src2^2
-
-    ; Because we're working with the actual output frames
-    ; we can't depend on any kind of data alignment.
-.accumulate:
-    movdqa      xmm0, [rax]                 ; src1
-    movdqa      xmm1, [rdx]                 ; src2
-    add         rax, rcx                    ; src1 + stride1
-    add         rdx, rdi                    ; src2 + stride2
-
-    ; SAD(src1, src2)
-    psadbw      xmm0, xmm1
-    paddusw     xmm3, xmm0
-
-    ; SUM(src2)
-    pxor        xmm2, xmm2
-    psadbw      xmm2, xmm1                  ; sum src2 by misusing SAD against 0
-    paddusw     xmm4, xmm2
-
-    ; pmaddubsw would be ideal if it took two unsigned values. instead,
-    ; it expects a signed and an unsigned value. so instead we zero extend
-    ; and operate on words.
-    pxor        xmm2, xmm2
-    movdqa      xmm0, xmm1
-    punpcklbw   xmm0, xmm2
-    punpckhbw   xmm1, xmm2
-    pmaddwd     xmm0, xmm0
-    pmaddwd     xmm1, xmm1
-    paddd       xmm5, xmm0
-    paddd       xmm5, xmm1
-
-    sub         rsi,        1
-    jnz         .accumulate
-
-    ; phaddd only operates on adjacent double words.
-    ; Finalize SAD and store
-    movdqa      xmm0, xmm3
-    psrldq      xmm0, 8
-    paddusw     xmm0, xmm3
-    paddd       xmm0, [GLOBAL(t128)]
-    psrld       xmm0, 8
-
-    mov         rax,  arg(5)
-    movd        [rax], xmm0
-
-    ; Accumulate sum of src2
-    movdqa      xmm0, xmm4
-    psrldq      xmm0, 8
-    paddusw     xmm0, xmm4
-    ; Square src2. Ignore high value
-    pmuludq     xmm0, xmm0
-    psrld       xmm0, 8
-
-    ; phaddw could be used to sum adjacent values but we want
-    ; all the values summed. promote to doubles, accumulate,
-    ; shift and sum
-    pxor        xmm2, xmm2
-    movdqa      xmm1, xmm5
-    punpckldq   xmm1, xmm2
-    punpckhdq   xmm5, xmm2
-    paddd       xmm1, xmm5
-    movdqa      xmm2, xmm1
-    psrldq      xmm1, 8
-    paddd       xmm1, xmm2
-
-    psubd       xmm1, xmm0
-
-    ; (variance + 128) >> 8
-    paddd       xmm1, [GLOBAL(t128)]
-    psrld       xmm1, 8
-    mov         rax,  arg(4)
-
-    movd        [rax], xmm1
-
-
-    ; begin epilog
-    pop         rdi
-    pop         rsi
-    RESTORE_GOT
-    UNSHADOW_ARGS
-    pop         rbp
-    ret
-
-SECTION_RODATA
-align 16
-t128:
-%ifndef __NASM_VER__
-    ddq 128
-%elif CONFIG_BIG_ENDIAN
-    dq  0, 128
-%else
-    dq  128, 0
-%endif
-align 16
-tMFQE: ; 1 << MFQE_PRECISION
-    times 8 dw 0x10
-align 16
-tMFQE_round: ; 1 << (MFQE_PRECISION - 1)
-    times 8 dw 0x08
diff --git a/vp9/decoder/vp9_decodeframe.c b/vp9/decoder/vp9_decodeframe.c
deleted file mode 100644 (file)
index d639129..0000000
+++ /dev/null
@@ -1,2271 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#include <assert.h>
-#include <stdlib.h>  // qsort()
-
-#include "./vp9_rtcd.h"
-#include "./vpx_dsp_rtcd.h"
-#include "./vpx_scale_rtcd.h"
-
-#include "vpx_dsp/bitreader_buffer.h"
-#include "vpx_dsp/bitreader.h"
-#include "vpx_dsp/vpx_dsp_common.h"
-#include "vpx_mem/vpx_mem.h"
-#include "vpx_ports/mem.h"
-#include "vpx_ports/mem_ops.h"
-#include "vpx_scale/vpx_scale.h"
-#include "vpx_util/vpx_thread.h"
-
-#include "vp9/common/vp9_alloccommon.h"
-#include "vp9/common/vp9_common.h"
-#include "vp9/common/vp9_entropy.h"
-#include "vp9/common/vp9_entropymode.h"
-#include "vp9/common/vp9_idct.h"
-#include "vp9/common/vp9_thread_common.h"
-#include "vp9/common/vp9_pred_common.h"
-#include "vp9/common/vp9_quant_common.h"
-#include "vp9/common/vp9_reconintra.h"
-#include "vp9/common/vp9_reconinter.h"
-#include "vp9/common/vp9_seg_common.h"
-#include "vp9/common/vp9_tile_common.h"
-
-#include "vp9/decoder/vp9_decodeframe.h"
-#include "vp9/decoder/vp9_detokenize.h"
-#include "vp9/decoder/vp9_decodemv.h"
-#include "vp9/decoder/vp9_decoder.h"
-#include "vp9/decoder/vp9_dsubexp.h"
-
-#define MAX_VP9_HEADER_SIZE 80
-
-static int is_compound_reference_allowed(const VP9_COMMON *cm) {
-  int i;
-  for (i = 1; i < REFS_PER_FRAME; ++i)
-    if (cm->ref_frame_sign_bias[i + 1] != cm->ref_frame_sign_bias[1])
-      return 1;
-
-  return 0;
-}
-
-static void setup_compound_reference_mode(VP9_COMMON *cm) {
-  if (cm->ref_frame_sign_bias[LAST_FRAME] ==
-          cm->ref_frame_sign_bias[GOLDEN_FRAME]) {
-    cm->comp_fixed_ref = ALTREF_FRAME;
-    cm->comp_var_ref[0] = LAST_FRAME;
-    cm->comp_var_ref[1] = GOLDEN_FRAME;
-  } else if (cm->ref_frame_sign_bias[LAST_FRAME] ==
-                 cm->ref_frame_sign_bias[ALTREF_FRAME]) {
-    cm->comp_fixed_ref = GOLDEN_FRAME;
-    cm->comp_var_ref[0] = LAST_FRAME;
-    cm->comp_var_ref[1] = ALTREF_FRAME;
-  } else {
-    cm->comp_fixed_ref = LAST_FRAME;
-    cm->comp_var_ref[0] = GOLDEN_FRAME;
-    cm->comp_var_ref[1] = ALTREF_FRAME;
-  }
-}
-
-static int read_is_valid(const uint8_t *start, size_t len, const uint8_t *end) {
-  return len != 0 && len <= (size_t)(end - start);
-}
-
-static int decode_unsigned_max(struct vpx_read_bit_buffer *rb, int max) {
-  const int data = vpx_rb_read_literal(rb, get_unsigned_bits(max));
-  return data > max ? max : data;
-}
-
-static TX_MODE read_tx_mode(vpx_reader *r) {
-  TX_MODE tx_mode = vpx_read_literal(r, 2);
-  if (tx_mode == ALLOW_32X32)
-    tx_mode += vpx_read_bit(r);
-  return tx_mode;
-}
-
-static void read_tx_mode_probs(struct tx_probs *tx_probs, vpx_reader *r) {
-  int i, j;
-
-  for (i = 0; i < TX_SIZE_CONTEXTS; ++i)
-    for (j = 0; j < TX_SIZES - 3; ++j)
-      vp9_diff_update_prob(r, &tx_probs->p8x8[i][j]);
-
-  for (i = 0; i < TX_SIZE_CONTEXTS; ++i)
-    for (j = 0; j < TX_SIZES - 2; ++j)
-      vp9_diff_update_prob(r, &tx_probs->p16x16[i][j]);
-
-  for (i = 0; i < TX_SIZE_CONTEXTS; ++i)
-    for (j = 0; j < TX_SIZES - 1; ++j)
-      vp9_diff_update_prob(r, &tx_probs->p32x32[i][j]);
-}
-
-static void read_switchable_interp_probs(FRAME_CONTEXT *fc, vpx_reader *r) {
-  int i, j;
-  for (j = 0; j < SWITCHABLE_FILTER_CONTEXTS; ++j)
-    for (i = 0; i < SWITCHABLE_FILTERS - 1; ++i)
-      vp9_diff_update_prob(r, &fc->switchable_interp_prob[j][i]);
-}
-
-static void read_inter_mode_probs(FRAME_CONTEXT *fc, vpx_reader *r) {
-  int i, j;
-  for (i = 0; i < INTER_MODE_CONTEXTS; ++i)
-    for (j = 0; j < INTER_MODES - 1; ++j)
-      vp9_diff_update_prob(r, &fc->inter_mode_probs[i][j]);
-}
-
-static REFERENCE_MODE read_frame_reference_mode(const VP9_COMMON *cm,
-                                                vpx_reader *r) {
-  if (is_compound_reference_allowed(cm)) {
-    return vpx_read_bit(r) ? (vpx_read_bit(r) ? REFERENCE_MODE_SELECT
-                                              : COMPOUND_REFERENCE)
-                           : SINGLE_REFERENCE;
-  } else {
-    return SINGLE_REFERENCE;
-  }
-}
-
-static void read_frame_reference_mode_probs(VP9_COMMON *cm, vpx_reader *r) {
-  FRAME_CONTEXT *const fc = cm->fc;
-  int i;
-
-  if (cm->reference_mode == REFERENCE_MODE_SELECT)
-    for (i = 0; i < COMP_INTER_CONTEXTS; ++i)
-      vp9_diff_update_prob(r, &fc->comp_inter_prob[i]);
-
-  if (cm->reference_mode != COMPOUND_REFERENCE)
-    for (i = 0; i < REF_CONTEXTS; ++i) {
-      vp9_diff_update_prob(r, &fc->single_ref_prob[i][0]);
-      vp9_diff_update_prob(r, &fc->single_ref_prob[i][1]);
-    }
-
-  if (cm->reference_mode != SINGLE_REFERENCE)
-    for (i = 0; i < REF_CONTEXTS; ++i)
-      vp9_diff_update_prob(r, &fc->comp_ref_prob[i]);
-}
-
-static void update_mv_probs(vpx_prob *p, int n, vpx_reader *r) {
-  int i;
-  for (i = 0; i < n; ++i)
-    if (vpx_read(r, MV_UPDATE_PROB))
-      p[i] = (vpx_read_literal(r, 7) << 1) | 1;
-}
-
-static void read_mv_probs(nmv_context *ctx, int allow_hp, vpx_reader *r) {
-  int i, j;
-
-  update_mv_probs(ctx->joints, MV_JOINTS - 1, r);
-
-  for (i = 0; i < 2; ++i) {
-    nmv_component *const comp_ctx = &ctx->comps[i];
-    update_mv_probs(&comp_ctx->sign, 1, r);
-    update_mv_probs(comp_ctx->classes, MV_CLASSES - 1, r);
-    update_mv_probs(comp_ctx->class0, CLASS0_SIZE - 1, r);
-    update_mv_probs(comp_ctx->bits, MV_OFFSET_BITS, r);
-  }
-
-  for (i = 0; i < 2; ++i) {
-    nmv_component *const comp_ctx = &ctx->comps[i];
-    for (j = 0; j < CLASS0_SIZE; ++j)
-      update_mv_probs(comp_ctx->class0_fp[j], MV_FP_SIZE - 1, r);
-    update_mv_probs(comp_ctx->fp, 3, r);
-  }
-
-  if (allow_hp) {
-    for (i = 0; i < 2; ++i) {
-      nmv_component *const comp_ctx = &ctx->comps[i];
-      update_mv_probs(&comp_ctx->class0_hp, 1, r);
-      update_mv_probs(&comp_ctx->hp, 1, r);
-    }
-  }
-}
-
-static void inverse_transform_block_inter(MACROBLOCKD* xd, int plane,
-                                          const TX_SIZE tx_size,
-                                          uint8_t *dst, int stride,
-                                          int eob) {
-  struct macroblockd_plane *const pd = &xd->plane[plane];
-  tran_low_t *const dqcoeff = pd->dqcoeff;
-  assert(eob > 0);
-#if CONFIG_VP9_HIGHBITDEPTH
-  if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
-    if (xd->lossless) {
-      vp9_highbd_iwht4x4_add(dqcoeff, dst, stride, eob, xd->bd);
-    } else {
-      switch (tx_size) {
-        case TX_4X4:
-          vp9_highbd_idct4x4_add(dqcoeff, dst, stride, eob, xd->bd);
-          break;
-        case TX_8X8:
-          vp9_highbd_idct8x8_add(dqcoeff, dst, stride, eob, xd->bd);
-          break;
-        case TX_16X16:
-          vp9_highbd_idct16x16_add(dqcoeff, dst, stride, eob, xd->bd);
-          break;
-        case TX_32X32:
-          vp9_highbd_idct32x32_add(dqcoeff, dst, stride, eob, xd->bd);
-          break;
-        default:
-          assert(0 && "Invalid transform size");
-      }
-    }
-  } else {
-    if (xd->lossless) {
-      vp9_iwht4x4_add(dqcoeff, dst, stride, eob);
-    } else {
-      switch (tx_size) {
-        case TX_4X4:
-          vp9_idct4x4_add(dqcoeff, dst, stride, eob);
-          break;
-        case TX_8X8:
-          vp9_idct8x8_add(dqcoeff, dst, stride, eob);
-          break;
-        case TX_16X16:
-          vp9_idct16x16_add(dqcoeff, dst, stride, eob);
-          break;
-        case TX_32X32:
-          vp9_idct32x32_add(dqcoeff, dst, stride, eob);
-          break;
-        default:
-          assert(0 && "Invalid transform size");
-          return;
-      }
-    }
-  }
-#else
-  if (xd->lossless) {
-    vp9_iwht4x4_add(dqcoeff, dst, stride, eob);
-  } else {
-    switch (tx_size) {
-      case TX_4X4:
-        vp9_idct4x4_add(dqcoeff, dst, stride, eob);
-        break;
-      case TX_8X8:
-        vp9_idct8x8_add(dqcoeff, dst, stride, eob);
-        break;
-      case TX_16X16:
-        vp9_idct16x16_add(dqcoeff, dst, stride, eob);
-        break;
-      case TX_32X32:
-        vp9_idct32x32_add(dqcoeff, dst, stride, eob);
-        break;
-      default:
-        assert(0 && "Invalid transform size");
-        return;
-    }
-  }
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-
-  if (eob == 1) {
-    dqcoeff[0] = 0;
-  } else {
-    if (tx_size <= TX_16X16 && eob <= 10)
-      memset(dqcoeff, 0, 4 * (4 << tx_size) * sizeof(dqcoeff[0]));
-    else if (tx_size == TX_32X32 && eob <= 34)
-      memset(dqcoeff, 0, 256 * sizeof(dqcoeff[0]));
-    else
-      memset(dqcoeff, 0, (16 << (tx_size << 1)) * sizeof(dqcoeff[0]));
-  }
-}
-
-static void inverse_transform_block_intra(MACROBLOCKD* xd, int plane,
-                                          const TX_TYPE tx_type,
-                                          const TX_SIZE tx_size,
-                                          uint8_t *dst, int stride,
-                                          int eob) {
-  struct macroblockd_plane *const pd = &xd->plane[plane];
-  tran_low_t *const dqcoeff = pd->dqcoeff;
-  assert(eob > 0);
-#if CONFIG_VP9_HIGHBITDEPTH
-  if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
-    if (xd->lossless) {
-      vp9_highbd_iwht4x4_add(dqcoeff, dst, stride, eob, xd->bd);
-    } else {
-      switch (tx_size) {
-        case TX_4X4:
-          vp9_highbd_iht4x4_add(tx_type, dqcoeff, dst, stride, eob, xd->bd);
-          break;
-        case TX_8X8:
-          vp9_highbd_iht8x8_add(tx_type, dqcoeff, dst, stride, eob, xd->bd);
-          break;
-        case TX_16X16:
-          vp9_highbd_iht16x16_add(tx_type, dqcoeff, dst, stride, eob, xd->bd);
-          break;
-        case TX_32X32:
-          vp9_highbd_idct32x32_add(dqcoeff, dst, stride, eob, xd->bd);
-          break;
-        default:
-          assert(0 && "Invalid transform size");
-      }
-    }
-  } else {
-    if (xd->lossless) {
-      vp9_iwht4x4_add(dqcoeff, dst, stride, eob);
-    } else {
-      switch (tx_size) {
-        case TX_4X4:
-          vp9_iht4x4_add(tx_type, dqcoeff, dst, stride, eob);
-          break;
-        case TX_8X8:
-          vp9_iht8x8_add(tx_type, dqcoeff, dst, stride, eob);
-          break;
-        case TX_16X16:
-          vp9_iht16x16_add(tx_type, dqcoeff, dst, stride, eob);
-          break;
-        case TX_32X32:
-          vp9_idct32x32_add(dqcoeff, dst, stride, eob);
-          break;
-        default:
-          assert(0 && "Invalid transform size");
-          return;
-      }
-    }
-  }
-#else
-  if (xd->lossless) {
-    vp9_iwht4x4_add(dqcoeff, dst, stride, eob);
-  } else {
-    switch (tx_size) {
-      case TX_4X4:
-        vp9_iht4x4_add(tx_type, dqcoeff, dst, stride, eob);
-        break;
-      case TX_8X8:
-        vp9_iht8x8_add(tx_type, dqcoeff, dst, stride, eob);
-        break;
-      case TX_16X16:
-        vp9_iht16x16_add(tx_type, dqcoeff, dst, stride, eob);
-        break;
-      case TX_32X32:
-        vp9_idct32x32_add(dqcoeff, dst, stride, eob);
-        break;
-      default:
-        assert(0 && "Invalid transform size");
-        return;
-    }
-  }
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-
-  if (eob == 1) {
-    dqcoeff[0] = 0;
-  } else {
-    if (tx_type == DCT_DCT && tx_size <= TX_16X16 && eob <= 10)
-      memset(dqcoeff, 0, 4 * (4 << tx_size) * sizeof(dqcoeff[0]));
-    else if (tx_size == TX_32X32 && eob <= 34)
-      memset(dqcoeff, 0, 256 * sizeof(dqcoeff[0]));
-    else
-      memset(dqcoeff, 0, (16 << (tx_size << 1)) * sizeof(dqcoeff[0]));
-  }
-}
-
-static void predict_and_reconstruct_intra_block(MACROBLOCKD *const xd,
-                                                vpx_reader *r,
-                                                MODE_INFO *const mi,
-                                                int plane,
-                                                int row, int col,
-                                                TX_SIZE tx_size) {
-  struct macroblockd_plane *const pd = &xd->plane[plane];
-  PREDICTION_MODE mode = (plane == 0) ? mi->mode : mi->uv_mode;
-  uint8_t *dst;
-  dst = &pd->dst.buf[4 * row * pd->dst.stride + 4 * col];
-
-  if (mi->sb_type < BLOCK_8X8)
-    if (plane == 0)
-      mode = xd->mi[0]->bmi[(row << 1) + col].as_mode;
-
-  vp9_predict_intra_block(xd, pd->n4_wl, tx_size, mode,
-                          dst, pd->dst.stride, dst, pd->dst.stride,
-                          col, row, plane);
-
-  if (!mi->skip) {
-    const TX_TYPE tx_type = (plane || xd->lossless) ?
-        DCT_DCT : intra_mode_to_tx_type_lookup[mode];
-    const scan_order *sc = (plane || xd->lossless) ?
-        &vp9_default_scan_orders[tx_size] : &vp9_scan_orders[tx_size][tx_type];
-    const int eob = vp9_decode_block_tokens(xd, plane, sc, col, row, tx_size,
-                                            r, mi->segment_id);
-    if (eob > 0) {
-      inverse_transform_block_intra(xd, plane, tx_type, tx_size,
-                                    dst, pd->dst.stride, eob);
-    }
-  }
-}
-
-static int reconstruct_inter_block(MACROBLOCKD *const xd, vpx_reader *r,
-                                   MODE_INFO *const mi, int plane,
-                                   int row, int col, TX_SIZE tx_size) {
-  struct macroblockd_plane *const pd = &xd->plane[plane];
-  const scan_order *sc = &vp9_default_scan_orders[tx_size];
-  const int eob = vp9_decode_block_tokens(xd, plane, sc, col, row, tx_size, r,
-                                          mi->segment_id);
-
-  if (eob > 0) {
-    inverse_transform_block_inter(
-        xd, plane, tx_size, &pd->dst.buf[4 * row * pd->dst.stride + 4 * col],
-        pd->dst.stride, eob);
-  }
-  return eob;
-}
-
-static void build_mc_border(const uint8_t *src, int src_stride,
-                            uint8_t *dst, int dst_stride,
-                            int x, int y, int b_w, int b_h, int w, int h) {
-  // Get a pointer to the start of the real data for this row.
-  const uint8_t *ref_row = src - x - y * src_stride;
-
-  if (y >= h)
-    ref_row += (h - 1) * src_stride;
-  else if (y > 0)
-    ref_row += y * src_stride;
-
-  do {
-    int right = 0, copy;
-    int left = x < 0 ? -x : 0;
-
-    if (left > b_w)
-      left = b_w;
-
-    if (x + b_w > w)
-      right = x + b_w - w;
-
-    if (right > b_w)
-      right = b_w;
-
-    copy = b_w - left - right;
-
-    if (left)
-      memset(dst, ref_row[0], left);
-
-    if (copy)
-      memcpy(dst + left, ref_row + x + left, copy);
-
-    if (right)
-      memset(dst + left + copy, ref_row[w - 1], right);
-
-    dst += dst_stride;
-    ++y;
-
-    if (y > 0 && y < h)
-      ref_row += src_stride;
-  } while (--b_h);
-}
-
-#if CONFIG_VP9_HIGHBITDEPTH
-static void high_build_mc_border(const uint8_t *src8, int src_stride,
-                                 uint16_t *dst, int dst_stride,
-                                 int x, int y, int b_w, int b_h,
-                                 int w, int h) {
-  // Get a pointer to the start of the real data for this row.
-  const uint16_t *src = CONVERT_TO_SHORTPTR(src8);
-  const uint16_t *ref_row = src - x - y * src_stride;
-
-  if (y >= h)
-    ref_row += (h - 1) * src_stride;
-  else if (y > 0)
-    ref_row += y * src_stride;
-
-  do {
-    int right = 0, copy;
-    int left = x < 0 ? -x : 0;
-
-    if (left > b_w)
-      left = b_w;
-
-    if (x + b_w > w)
-      right = x + b_w - w;
-
-    if (right > b_w)
-      right = b_w;
-
-    copy = b_w - left - right;
-
-    if (left)
-      vpx_memset16(dst, ref_row[0], left);
-
-    if (copy)
-      memcpy(dst + left, ref_row + x + left, copy * sizeof(uint16_t));
-
-    if (right)
-      vpx_memset16(dst + left + copy, ref_row[w - 1], right);
-
-    dst += dst_stride;
-    ++y;
-
-    if (y > 0 && y < h)
-      ref_row += src_stride;
-  } while (--b_h);
-}
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-
-#if CONFIG_VP9_HIGHBITDEPTH
-static void extend_and_predict(const uint8_t *buf_ptr1, int pre_buf_stride,
-                               int x0, int y0, int b_w, int b_h,
-                               int frame_width, int frame_height,
-                               int border_offset,
-                               uint8_t *const dst, int dst_buf_stride,
-                               int subpel_x, int subpel_y,
-                               const InterpKernel *kernel,
-                               const struct scale_factors *sf,
-                               MACROBLOCKD *xd,
-                               int w, int h, int ref, int xs, int ys) {
-  DECLARE_ALIGNED(16, uint16_t, mc_buf_high[80 * 2 * 80 * 2]);
-  const uint8_t *buf_ptr;
-
-  if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
-    high_build_mc_border(buf_ptr1, pre_buf_stride, mc_buf_high, b_w,
-                         x0, y0, b_w, b_h, frame_width, frame_height);
-    buf_ptr = CONVERT_TO_BYTEPTR(mc_buf_high) + border_offset;
-  } else {
-    build_mc_border(buf_ptr1, pre_buf_stride, (uint8_t *)mc_buf_high, b_w,
-                    x0, y0, b_w, b_h, frame_width, frame_height);
-    buf_ptr = ((uint8_t *)mc_buf_high) + border_offset;
-  }
-
-  if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
-    highbd_inter_predictor(buf_ptr, b_w, dst, dst_buf_stride, subpel_x,
-                           subpel_y, sf, w, h, ref, kernel, xs, ys, xd->bd);
-  } else {
-    inter_predictor(buf_ptr, b_w, dst, dst_buf_stride, subpel_x,
-                    subpel_y, sf, w, h, ref, kernel, xs, ys);
-  }
-}
-#else
-static void extend_and_predict(const uint8_t *buf_ptr1, int pre_buf_stride,
-                               int x0, int y0, int b_w, int b_h,
-                               int frame_width, int frame_height,
-                               int border_offset,
-                               uint8_t *const dst, int dst_buf_stride,
-                               int subpel_x, int subpel_y,
-                               const InterpKernel *kernel,
-                               const struct scale_factors *sf,
-                               int w, int h, int ref, int xs, int ys) {
-  DECLARE_ALIGNED(16, uint8_t, mc_buf[80 * 2 * 80 * 2]);
-  const uint8_t *buf_ptr;
-
-  build_mc_border(buf_ptr1, pre_buf_stride, mc_buf, b_w,
-                  x0, y0, b_w, b_h, frame_width, frame_height);
-  buf_ptr = mc_buf + border_offset;
-
-  inter_predictor(buf_ptr, b_w, dst, dst_buf_stride, subpel_x,
-                  subpel_y, sf, w, h, ref, kernel, xs, ys);
-}
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-
-static void dec_build_inter_predictors(VPxWorker *const worker, MACROBLOCKD *xd,
-                                       int plane, int bw, int bh, int x,
-                                       int y, int w, int h, int mi_x, int mi_y,
-                                       const InterpKernel *kernel,
-                                       const struct scale_factors *sf,
-                                       struct buf_2d *pre_buf,
-                                       struct buf_2d *dst_buf, const MV* mv,
-                                       RefCntBuffer *ref_frame_buf,
-                                       int is_scaled, int ref) {
-  struct macroblockd_plane *const pd = &xd->plane[plane];
-  uint8_t *const dst = dst_buf->buf + dst_buf->stride * y + x;
-  MV32 scaled_mv;
-  int xs, ys, x0, y0, x0_16, y0_16, frame_width, frame_height,
-      buf_stride, subpel_x, subpel_y;
-  uint8_t *ref_frame, *buf_ptr;
-
-  // Get reference frame pointer, width and height.
-  if (plane == 0) {
-    frame_width = ref_frame_buf->buf.y_crop_width;
-    frame_height = ref_frame_buf->buf.y_crop_height;
-    ref_frame = ref_frame_buf->buf.y_buffer;
-  } else {
-    frame_width = ref_frame_buf->buf.uv_crop_width;
-    frame_height = ref_frame_buf->buf.uv_crop_height;
-    ref_frame = plane == 1 ? ref_frame_buf->buf.u_buffer
-                         : ref_frame_buf->buf.v_buffer;
-  }
-
-  if (is_scaled) {
-    const MV mv_q4 = clamp_mv_to_umv_border_sb(xd, mv, bw, bh,
-                                               pd->subsampling_x,
-                                               pd->subsampling_y);
-    // Co-ordinate of containing block to pixel precision.
-    int x_start = (-xd->mb_to_left_edge >> (3 + pd->subsampling_x));
-    int y_start = (-xd->mb_to_top_edge >> (3 + pd->subsampling_y));
-#if CONFIG_BETTER_HW_COMPATIBILITY
-    assert(xd->mi[0]->sb_type != BLOCK_4X8 &&
-           xd->mi[0]->sb_type != BLOCK_8X4);
-    assert(mv_q4.row == mv->row * (1 << (1 - pd->subsampling_y)) &&
-           mv_q4.col == mv->col * (1 << (1 - pd->subsampling_x)));
-#endif
-    // Co-ordinate of the block to 1/16th pixel precision.
-    x0_16 = (x_start + x) << SUBPEL_BITS;
-    y0_16 = (y_start + y) << SUBPEL_BITS;
-
-    // Co-ordinate of current block in reference frame
-    // to 1/16th pixel precision.
-    x0_16 = sf->scale_value_x(x0_16, sf);
-    y0_16 = sf->scale_value_y(y0_16, sf);
-
-    // Map the top left corner of the block into the reference frame.
-    x0 = sf->scale_value_x(x_start + x, sf);
-    y0 = sf->scale_value_y(y_start + y, sf);
-
-    // Scale the MV and incorporate the sub-pixel offset of the block
-    // in the reference frame.
-    scaled_mv = vp9_scale_mv(&mv_q4, mi_x + x, mi_y + y, sf);
-    xs = sf->x_step_q4;
-    ys = sf->y_step_q4;
-  } else {
-    // Co-ordinate of containing block to pixel precision.
-    x0 = (-xd->mb_to_left_edge >> (3 + pd->subsampling_x)) + x;
-    y0 = (-xd->mb_to_top_edge >> (3 + pd->subsampling_y)) + y;
-
-    // Co-ordinate of the block to 1/16th pixel precision.
-    x0_16 = x0 << SUBPEL_BITS;
-    y0_16 = y0 << SUBPEL_BITS;
-
-    scaled_mv.row = mv->row * (1 << (1 - pd->subsampling_y));
-    scaled_mv.col = mv->col * (1 << (1 - pd->subsampling_x));
-    xs = ys = 16;
-  }
-  subpel_x = scaled_mv.col & SUBPEL_MASK;
-  subpel_y = scaled_mv.row & SUBPEL_MASK;
-
-  // Calculate the top left corner of the best matching block in the
-  // reference frame.
-  x0 += scaled_mv.col >> SUBPEL_BITS;
-  y0 += scaled_mv.row >> SUBPEL_BITS;
-  x0_16 += scaled_mv.col;
-  y0_16 += scaled_mv.row;
-
-  // Get reference block pointer.
-  buf_ptr = ref_frame + y0 * pre_buf->stride + x0;
-  buf_stride = pre_buf->stride;
-
-  // Do border extension if there is motion or the
-  // width/height is not a multiple of 8 pixels.
-  if (is_scaled || scaled_mv.col || scaled_mv.row ||
-      (frame_width & 0x7) || (frame_height & 0x7)) {
-    int y1 = ((y0_16 + (h - 1) * ys) >> SUBPEL_BITS) + 1;
-
-    // Get reference block bottom right horizontal coordinate.
-    int x1 = ((x0_16 + (w - 1) * xs) >> SUBPEL_BITS) + 1;
-    int x_pad = 0, y_pad = 0;
-
-    if (subpel_x || (sf->x_step_q4 != SUBPEL_SHIFTS)) {
-      x0 -= VP9_INTERP_EXTEND - 1;
-      x1 += VP9_INTERP_EXTEND;
-      x_pad = 1;
-    }
-
-    if (subpel_y || (sf->y_step_q4 != SUBPEL_SHIFTS)) {
-      y0 -= VP9_INTERP_EXTEND - 1;
-      y1 += VP9_INTERP_EXTEND;
-      y_pad = 1;
-    }
-
-    // Wait until reference block is ready. Pad 7 more pixels as last 7
-    // pixels of each superblock row can be changed by next superblock row.
-    if (worker != NULL)
-      vp9_frameworker_wait(worker, ref_frame_buf,
-                           VPXMAX(0, (y1 + 7)) << (plane == 0 ? 0 : 1));
-
-    // Skip border extension if block is inside the frame.
-    if (x0 < 0 || x0 > frame_width - 1 || x1 < 0 || x1 > frame_width - 1 ||
-        y0 < 0 || y0 > frame_height - 1 || y1 < 0 || y1 > frame_height - 1) {
-      // Extend the border.
-      const uint8_t *const buf_ptr1 = ref_frame + y0 * buf_stride + x0;
-      const int b_w = x1 - x0 + 1;
-      const int b_h = y1 - y0 + 1;
-      const int border_offset = y_pad * 3 * b_w + x_pad * 3;
-
-      extend_and_predict(buf_ptr1, buf_stride, x0, y0, b_w, b_h,
-                         frame_width, frame_height, border_offset,
-                         dst, dst_buf->stride,
-                         subpel_x, subpel_y,
-                         kernel, sf,
-#if CONFIG_VP9_HIGHBITDEPTH
-                         xd,
-#endif
-                         w, h, ref, xs, ys);
-      return;
-    }
-  } else {
-    // Wait until reference block is ready. Pad 7 more pixels as last 7
-    // pixels of each superblock row can be changed by next superblock row.
-    if (worker != NULL) {
-      const int y1 = (y0_16 + (h - 1) * ys) >> SUBPEL_BITS;
-      vp9_frameworker_wait(worker, ref_frame_buf,
-                           VPXMAX(0, (y1 + 7)) << (plane == 0 ? 0 : 1));
-    }
-  }
-#if CONFIG_VP9_HIGHBITDEPTH
-  if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
-    highbd_inter_predictor(buf_ptr, buf_stride, dst, dst_buf->stride, subpel_x,
-                           subpel_y, sf, w, h, ref, kernel, xs, ys, xd->bd);
-  } else {
-    inter_predictor(buf_ptr, buf_stride, dst, dst_buf->stride, subpel_x,
-                    subpel_y, sf, w, h, ref, kernel, xs, ys);
-  }
-#else
-  inter_predictor(buf_ptr, buf_stride, dst, dst_buf->stride, subpel_x,
-                  subpel_y, sf, w, h, ref, kernel, xs, ys);
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-}
-
-static void dec_build_inter_predictors_sb(VP9Decoder *const pbi,
-                                          MACROBLOCKD *xd,
-                                          int mi_row, int mi_col) {
-  int plane;
-  const int mi_x = mi_col * MI_SIZE;
-  const int mi_y = mi_row * MI_SIZE;
-  const MODE_INFO *mi = xd->mi[0];
-  const InterpKernel *kernel = vp9_filter_kernels[mi->interp_filter];
-  const BLOCK_SIZE sb_type = mi->sb_type;
-  const int is_compound = has_second_ref(mi);
-  int ref;
-  int is_scaled;
-  VPxWorker *const fwo = pbi->frame_parallel_decode ?
-      pbi->frame_worker_owner : NULL;
-
-  for (ref = 0; ref < 1 + is_compound; ++ref) {
-    const MV_REFERENCE_FRAME frame = mi->ref_frame[ref];
-    RefBuffer *ref_buf = &pbi->common.frame_refs[frame - LAST_FRAME];
-    const struct scale_factors *const sf = &ref_buf->sf;
-    const int idx = ref_buf->idx;
-    BufferPool *const pool = pbi->common.buffer_pool;
-    RefCntBuffer *const ref_frame_buf = &pool->frame_bufs[idx];
-
-    if (!vp9_is_valid_scale(sf))
-      vpx_internal_error(xd->error_info, VPX_CODEC_UNSUP_BITSTREAM,
-                         "Reference frame has invalid dimensions");
-
-    is_scaled = vp9_is_scaled(sf);
-    vp9_setup_pre_planes(xd, ref, ref_buf->buf, mi_row, mi_col,
-                         is_scaled ? sf : NULL);
-    xd->block_refs[ref] = ref_buf;
-
-    if (sb_type < BLOCK_8X8) {
-      for (plane = 0; plane < MAX_MB_PLANE; ++plane) {
-        struct macroblockd_plane *const pd = &xd->plane[plane];
-        struct buf_2d *const dst_buf = &pd->dst;
-        const int num_4x4_w = pd->n4_w;
-        const int num_4x4_h = pd->n4_h;
-        const int n4w_x4 = 4 * num_4x4_w;
-        const int n4h_x4 = 4 * num_4x4_h;
-        struct buf_2d *const pre_buf = &pd->pre[ref];
-        int i = 0, x, y;
-        for (y = 0; y < num_4x4_h; ++y) {
-          for (x = 0; x < num_4x4_w; ++x) {
-            const MV mv = average_split_mvs(pd, mi, ref, i++);
-            dec_build_inter_predictors(fwo, xd, plane, n4w_x4, n4h_x4,
-                                       4 * x, 4 * y, 4, 4, mi_x, mi_y, kernel,
-                                       sf, pre_buf, dst_buf, &mv,
-                                       ref_frame_buf, is_scaled, ref);
-          }
-        }
-      }
-    } else {
-      const MV mv = mi->mv[ref].as_mv;
-      for (plane = 0; plane < MAX_MB_PLANE; ++plane) {
-        struct macroblockd_plane *const pd = &xd->plane[plane];
-        struct buf_2d *const dst_buf = &pd->dst;
-        const int num_4x4_w = pd->n4_w;
-        const int num_4x4_h = pd->n4_h;
-        const int n4w_x4 = 4 * num_4x4_w;
-        const int n4h_x4 = 4 * num_4x4_h;
-        struct buf_2d *const pre_buf = &pd->pre[ref];
-        dec_build_inter_predictors(fwo, xd, plane, n4w_x4, n4h_x4,
-                                   0, 0, n4w_x4, n4h_x4, mi_x, mi_y, kernel,
-                                   sf, pre_buf, dst_buf, &mv,
-                                   ref_frame_buf, is_scaled, ref);
-      }
-    }
-  }
-}
-
-static INLINE TX_SIZE dec_get_uv_tx_size(const MODE_INFO *mi,
-                                         int n4_wl, int n4_hl) {
-  // get minimum log2 num4x4s dimension
-  const int x = VPXMIN(n4_wl, n4_hl);
-  return VPXMIN(mi->tx_size,  x);
-}
-
-static INLINE void dec_reset_skip_context(MACROBLOCKD *xd) {
-  int i;
-  for (i = 0; i < MAX_MB_PLANE; i++) {
-    struct macroblockd_plane *const pd = &xd->plane[i];
-    memset(pd->above_context, 0, sizeof(ENTROPY_CONTEXT) * pd->n4_w);
-    memset(pd->left_context, 0, sizeof(ENTROPY_CONTEXT) * pd->n4_h);
-  }
-}
-
-static void set_plane_n4(MACROBLOCKD *const xd, int bw, int bh, int bwl,
-                         int bhl) {
-  int i;
-  for (i = 0; i < MAX_MB_PLANE; i++) {
-    xd->plane[i].n4_w = (bw << 1) >> xd->plane[i].subsampling_x;
-    xd->plane[i].n4_h = (bh << 1) >> xd->plane[i].subsampling_y;
-    xd->plane[i].n4_wl = bwl - xd->plane[i].subsampling_x;
-    xd->plane[i].n4_hl = bhl - xd->plane[i].subsampling_y;
-  }
-}
-
-static MODE_INFO *set_offsets(VP9_COMMON *const cm, MACROBLOCKD *const xd,
-                              BLOCK_SIZE bsize, int mi_row, int mi_col,
-                              int bw, int bh, int x_mis, int y_mis,
-                              int bwl, int bhl) {
-  const int offset = mi_row * cm->mi_stride + mi_col;
-  int x, y;
-  const TileInfo *const tile = &xd->tile;
-
-  xd->mi = cm->mi_grid_visible + offset;
-  xd->mi[0] = &cm->mi[offset];
-  // TODO(slavarnway): Generate sb_type based on bwl and bhl, instead of
-  // passing bsize from decode_partition().
-  xd->mi[0]->sb_type = bsize;
-  for (y = 0; y < y_mis; ++y)
-    for (x = !y; x < x_mis; ++x) {
-      xd->mi[y * cm->mi_stride + x] = xd->mi[0];
-    }
-
-  set_plane_n4(xd, bw, bh, bwl, bhl);
-
-  set_skip_context(xd, mi_row, mi_col);
-
-  // Distance of Mb to the various image edges. These are specified to 8th pel
-  // as they are always compared to values that are in 1/8th pel units
-  set_mi_row_col(xd, tile, mi_row, bh, mi_col, bw, cm->mi_rows, cm->mi_cols);
-
-  vp9_setup_dst_planes(xd->plane, get_frame_new_buffer(cm), mi_row, mi_col);
-  return xd->mi[0];
-}
-
-static void decode_block(VP9Decoder *const pbi, MACROBLOCKD *const xd,
-                         int mi_row, int mi_col,
-                         vpx_reader *r, BLOCK_SIZE bsize,
-                         int bwl, int bhl) {
-  VP9_COMMON *const cm = &pbi->common;
-  const int less8x8 = bsize < BLOCK_8X8;
-  const int bw = 1 << (bwl - 1);
-  const int bh = 1 << (bhl - 1);
-  const int x_mis = VPXMIN(bw, cm->mi_cols - mi_col);
-  const int y_mis = VPXMIN(bh, cm->mi_rows - mi_row);
-
-  MODE_INFO *mi = set_offsets(cm, xd, bsize, mi_row, mi_col,
-                              bw, bh, x_mis, y_mis, bwl, bhl);
-
-  if (bsize >= BLOCK_8X8 && (cm->subsampling_x || cm->subsampling_y)) {
-    const BLOCK_SIZE uv_subsize =
-        ss_size_lookup[bsize][cm->subsampling_x][cm->subsampling_y];
-    if (uv_subsize == BLOCK_INVALID)
-      vpx_internal_error(xd->error_info,
-                         VPX_CODEC_CORRUPT_FRAME, "Invalid block size.");
-  }
-
-  vp9_read_mode_info(pbi, xd, mi_row, mi_col, r, x_mis, y_mis);
-
-  if (mi->skip) {
-    dec_reset_skip_context(xd);
-  }
-
-  if (!is_inter_block(mi)) {
-    int plane;
-    for (plane = 0; plane < MAX_MB_PLANE; ++plane) {
-      const struct macroblockd_plane *const pd = &xd->plane[plane];
-      const TX_SIZE tx_size =
-          plane ? dec_get_uv_tx_size(mi, pd->n4_wl, pd->n4_hl)
-                  : mi->tx_size;
-      const int num_4x4_w = pd->n4_w;
-      const int num_4x4_h = pd->n4_h;
-      const int step = (1 << tx_size);
-      int row, col;
-      const int max_blocks_wide = num_4x4_w + (xd->mb_to_right_edge >= 0 ?
-          0 : xd->mb_to_right_edge >> (5 + pd->subsampling_x));
-      const int max_blocks_high = num_4x4_h + (xd->mb_to_bottom_edge >= 0 ?
-          0 : xd->mb_to_bottom_edge >> (5 + pd->subsampling_y));
-
-      xd->max_blocks_wide = xd->mb_to_right_edge >= 0 ? 0 : max_blocks_wide;
-      xd->max_blocks_high = xd->mb_to_bottom_edge >= 0 ? 0 : max_blocks_high;
-
-      for (row = 0; row < max_blocks_high; row += step)
-        for (col = 0; col < max_blocks_wide; col += step)
-          predict_and_reconstruct_intra_block(xd, r, mi, plane,
-                                              row, col, tx_size);
-    }
-  } else {
-    // Prediction
-    dec_build_inter_predictors_sb(pbi, xd, mi_row, mi_col);
-
-    // Reconstruction
-    if (!mi->skip) {
-      int eobtotal = 0;
-      int plane;
-
-      for (plane = 0; plane < MAX_MB_PLANE; ++plane) {
-        const struct macroblockd_plane *const pd = &xd->plane[plane];
-        const TX_SIZE tx_size =
-            plane ? dec_get_uv_tx_size(mi, pd->n4_wl, pd->n4_hl)
-                    : mi->tx_size;
-        const int num_4x4_w = pd->n4_w;
-        const int num_4x4_h = pd->n4_h;
-        const int step = (1 << tx_size);
-        int row, col;
-        const int max_blocks_wide = num_4x4_w + (xd->mb_to_right_edge >= 0 ?
-            0 : xd->mb_to_right_edge >> (5 + pd->subsampling_x));
-        const int max_blocks_high = num_4x4_h + (xd->mb_to_bottom_edge >= 0 ?
-            0 : xd->mb_to_bottom_edge >> (5 + pd->subsampling_y));
-
-        xd->max_blocks_wide = xd->mb_to_right_edge >= 0 ? 0 : max_blocks_wide;
-        xd->max_blocks_high = xd->mb_to_bottom_edge >= 0 ? 0 : max_blocks_high;
-
-        for (row = 0; row < max_blocks_high; row += step)
-          for (col = 0; col < max_blocks_wide; col += step)
-            eobtotal += reconstruct_inter_block(xd, r, mi, plane, row, col,
-                                                tx_size);
-      }
-
-      if (!less8x8 && eobtotal == 0)
-        mi->skip = 1;  // skip loopfilter
-    }
-  }
-
-  xd->corrupted |= vpx_reader_has_error(r);
-
-  if (cm->lf.filter_level) {
-    vp9_build_mask(cm, mi, mi_row, mi_col, bw, bh);
-  }
-}
-
-static INLINE int dec_partition_plane_context(const MACROBLOCKD *xd,
-                                              int mi_row, int mi_col,
-                                              int bsl) {
-  const PARTITION_CONTEXT *above_ctx = xd->above_seg_context + mi_col;
-  const PARTITION_CONTEXT *left_ctx = xd->left_seg_context + (mi_row & MI_MASK);
-  int above = (*above_ctx >> bsl) & 1 , left = (*left_ctx >> bsl) & 1;
-
-//  assert(bsl >= 0);
-
-  return (left * 2 + above) + bsl * PARTITION_PLOFFSET;
-}
-
-static INLINE void dec_update_partition_context(MACROBLOCKD *xd,
-                                                int mi_row, int mi_col,
-                                                BLOCK_SIZE subsize,
-                                                int bw) {
-  PARTITION_CONTEXT *const above_ctx = xd->above_seg_context + mi_col;
-  PARTITION_CONTEXT *const left_ctx = xd->left_seg_context + (mi_row & MI_MASK);
-
-  // update the partition context at the end notes. set partition bits
-  // of block sizes larger than the current one to be one, and partition
-  // bits of smaller block sizes to be zero.
-  memset(above_ctx, partition_context_lookup[subsize].above, bw);
-  memset(left_ctx, partition_context_lookup[subsize].left, bw);
-}
-
-static PARTITION_TYPE read_partition(MACROBLOCKD *xd, int mi_row, int mi_col,
-                                     vpx_reader *r,
-                                     int has_rows, int has_cols, int bsl) {
-  const int ctx = dec_partition_plane_context(xd, mi_row, mi_col, bsl);
-  const vpx_prob *const probs = get_partition_probs(xd, ctx);
-  FRAME_COUNTS *counts = xd->counts;
-  PARTITION_TYPE p;
-
-  if (has_rows && has_cols)
-    p = (PARTITION_TYPE)vpx_read_tree(r, vp9_partition_tree, probs);
-  else if (!has_rows && has_cols)
-    p = vpx_read(r, probs[1]) ? PARTITION_SPLIT : PARTITION_HORZ;
-  else if (has_rows && !has_cols)
-    p = vpx_read(r, probs[2]) ? PARTITION_SPLIT : PARTITION_VERT;
-  else
-    p = PARTITION_SPLIT;
-
-  if (counts)
-    ++counts->partition[ctx][p];
-
-  return p;
-}
-
-// TODO(slavarnway): eliminate bsize and subsize in future commits
-static void decode_partition(VP9Decoder *const pbi, MACROBLOCKD *const xd,
-                             int mi_row, int mi_col,
-                             vpx_reader* r, BLOCK_SIZE bsize, int n4x4_l2) {
-  VP9_COMMON *const cm = &pbi->common;
-  const int n8x8_l2 = n4x4_l2 - 1;
-  const int num_8x8_wh = 1 << n8x8_l2;
-  const int hbs = num_8x8_wh >> 1;
-  PARTITION_TYPE partition;
-  BLOCK_SIZE subsize;
-  const int has_rows = (mi_row + hbs) < cm->mi_rows;
-  const int has_cols = (mi_col + hbs) < cm->mi_cols;
-
-  if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols)
-    return;
-
-  partition = read_partition(xd, mi_row, mi_col, r, has_rows, has_cols,
-                             n8x8_l2);
-  subsize = subsize_lookup[partition][bsize];  // get_subsize(bsize, partition);
-  if (!hbs) {
-    // calculate bmode block dimensions (log 2)
-    xd->bmode_blocks_wl = 1 >> !!(partition & PARTITION_VERT);
-    xd->bmode_blocks_hl = 1 >> !!(partition & PARTITION_HORZ);
-    decode_block(pbi, xd, mi_row, mi_col, r, subsize, 1, 1);
-  } else {
-    switch (partition) {
-      case PARTITION_NONE:
-        decode_block(pbi, xd, mi_row, mi_col, r, subsize, n4x4_l2, n4x4_l2);
-        break;
-      case PARTITION_HORZ:
-        decode_block(pbi, xd, mi_row, mi_col, r, subsize, n4x4_l2, n8x8_l2);
-        if (has_rows)
-          decode_block(pbi, xd, mi_row + hbs, mi_col, r, subsize, n4x4_l2,
-                       n8x8_l2);
-        break;
-      case PARTITION_VERT:
-        decode_block(pbi, xd, mi_row, mi_col, r, subsize, n8x8_l2, n4x4_l2);
-        if (has_cols)
-          decode_block(pbi, xd, mi_row, mi_col + hbs, r, subsize, n8x8_l2,
-                       n4x4_l2);
-        break;
-      case PARTITION_SPLIT:
-        decode_partition(pbi, xd, mi_row, mi_col, r, subsize, n8x8_l2);
-        decode_partition(pbi, xd, mi_row, mi_col + hbs, r, subsize, n8x8_l2);
-        decode_partition(pbi, xd, mi_row + hbs, mi_col, r, subsize, n8x8_l2);
-        decode_partition(pbi, xd, mi_row + hbs, mi_col + hbs, r, subsize,
-                         n8x8_l2);
-        break;
-      default:
-        assert(0 && "Invalid partition type");
-    }
-  }
-
-  // update partition context
-  if (bsize >= BLOCK_8X8 &&
-      (bsize == BLOCK_8X8 || partition != PARTITION_SPLIT))
-    dec_update_partition_context(xd, mi_row, mi_col, subsize, num_8x8_wh);
-}
-
-static void setup_token_decoder(const uint8_t *data,
-                                const uint8_t *data_end,
-                                size_t read_size,
-                                struct vpx_internal_error_info *error_info,
-                                vpx_reader *r,
-                                vpx_decrypt_cb decrypt_cb,
-                                void *decrypt_state) {
-  // Validate the calculated partition length. If the buffer
-  // described by the partition can't be fully read, then restrict
-  // it to the portion that can be (for EC mode) or throw an error.
-  if (!read_is_valid(data, read_size, data_end))
-    vpx_internal_error(error_info, VPX_CODEC_CORRUPT_FRAME,
-                       "Truncated packet or corrupt tile length");
-
-  if (vpx_reader_init(r, data, read_size, decrypt_cb, decrypt_state))
-    vpx_internal_error(error_info, VPX_CODEC_MEM_ERROR,
-                       "Failed to allocate bool decoder %d", 1);
-}
-
-static void read_coef_probs_common(vp9_coeff_probs_model *coef_probs,
-                                   vpx_reader *r) {
-  int i, j, k, l, m;
-
-  if (vpx_read_bit(r))
-    for (i = 0; i < PLANE_TYPES; ++i)
-      for (j = 0; j < REF_TYPES; ++j)
-        for (k = 0; k < COEF_BANDS; ++k)
-          for (l = 0; l < BAND_COEFF_CONTEXTS(k); ++l)
-            for (m = 0; m < UNCONSTRAINED_NODES; ++m)
-              vp9_diff_update_prob(r, &coef_probs[i][j][k][l][m]);
-}
-
-static void read_coef_probs(FRAME_CONTEXT *fc, TX_MODE tx_mode,
-                            vpx_reader *r) {
-    const TX_SIZE max_tx_size = tx_mode_to_biggest_tx_size[tx_mode];
-    TX_SIZE tx_size;
-    for (tx_size = TX_4X4; tx_size <= max_tx_size; ++tx_size)
-      read_coef_probs_common(fc->coef_probs[tx_size], r);
-}
-
-static void setup_segmentation(struct segmentation *seg,
-                               struct vpx_read_bit_buffer *rb) {
-  int i, j;
-
-  seg->update_map = 0;
-  seg->update_data = 0;
-
-  seg->enabled = vpx_rb_read_bit(rb);
-  if (!seg->enabled)
-    return;
-
-  // Segmentation map update
-  seg->update_map = vpx_rb_read_bit(rb);
-  if (seg->update_map) {
-    for (i = 0; i < SEG_TREE_PROBS; i++)
-      seg->tree_probs[i] = vpx_rb_read_bit(rb) ? vpx_rb_read_literal(rb, 8)
-                                               : MAX_PROB;
-
-    seg->temporal_update = vpx_rb_read_bit(rb);
-    if (seg->temporal_update) {
-      for (i = 0; i < PREDICTION_PROBS; i++)
-        seg->pred_probs[i] = vpx_rb_read_bit(rb) ? vpx_rb_read_literal(rb, 8)
-                                                 : MAX_PROB;
-    } else {
-      for (i = 0; i < PREDICTION_PROBS; i++)
-        seg->pred_probs[i] = MAX_PROB;
-    }
-  }
-
-  // Segmentation data update
-  seg->update_data = vpx_rb_read_bit(rb);
-  if (seg->update_data) {
-    seg->abs_delta = vpx_rb_read_bit(rb);
-
-    vp9_clearall_segfeatures(seg);
-
-    for (i = 0; i < MAX_SEGMENTS; i++) {
-      for (j = 0; j < SEG_LVL_MAX; j++) {
-        int data = 0;
-        const int feature_enabled = vpx_rb_read_bit(rb);
-        if (feature_enabled) {
-          vp9_enable_segfeature(seg, i, j);
-          data = decode_unsigned_max(rb, vp9_seg_feature_data_max(j));
-          if (vp9_is_segfeature_signed(j))
-            data = vpx_rb_read_bit(rb) ? -data : data;
-        }
-        vp9_set_segdata(seg, i, j, data);
-      }
-    }
-  }
-}
-
-static void setup_loopfilter(struct loopfilter *lf,
-                             struct vpx_read_bit_buffer *rb) {
-  lf->filter_level = vpx_rb_read_literal(rb, 6);
-  lf->sharpness_level = vpx_rb_read_literal(rb, 3);
-
-  // Read in loop filter deltas applied at the MB level based on mode or ref
-  // frame.
-  lf->mode_ref_delta_update = 0;
-
-  lf->mode_ref_delta_enabled = vpx_rb_read_bit(rb);
-  if (lf->mode_ref_delta_enabled) {
-    lf->mode_ref_delta_update = vpx_rb_read_bit(rb);
-    if (lf->mode_ref_delta_update) {
-      int i;
-
-      for (i = 0; i < MAX_REF_LF_DELTAS; i++)
-        if (vpx_rb_read_bit(rb))
-          lf->ref_deltas[i] = vpx_rb_read_signed_literal(rb, 6);
-
-      for (i = 0; i < MAX_MODE_LF_DELTAS; i++)
-        if (vpx_rb_read_bit(rb))
-          lf->mode_deltas[i] = vpx_rb_read_signed_literal(rb, 6);
-    }
-  }
-}
-
-static INLINE int read_delta_q(struct vpx_read_bit_buffer *rb) {
-  return vpx_rb_read_bit(rb) ? vpx_rb_read_signed_literal(rb, 4) : 0;
-}
-
-static void setup_quantization(VP9_COMMON *const cm, MACROBLOCKD *const xd,
-                               struct vpx_read_bit_buffer *rb) {
-  cm->base_qindex = vpx_rb_read_literal(rb, QINDEX_BITS);
-  cm->y_dc_delta_q = read_delta_q(rb);
-  cm->uv_dc_delta_q = read_delta_q(rb);
-  cm->uv_ac_delta_q = read_delta_q(rb);
-  cm->dequant_bit_depth = cm->bit_depth;
-  xd->lossless = cm->base_qindex == 0 &&
-                 cm->y_dc_delta_q == 0 &&
-                 cm->uv_dc_delta_q == 0 &&
-                 cm->uv_ac_delta_q == 0;
-
-#if CONFIG_VP9_HIGHBITDEPTH
-  xd->bd = (int)cm->bit_depth;
-#endif
-}
-
-static void setup_segmentation_dequant(VP9_COMMON *const cm) {
-  // Build y/uv dequant values based on segmentation.
-  if (cm->seg.enabled) {
-    int i;
-    for (i = 0; i < MAX_SEGMENTS; ++i) {
-      const int qindex = vp9_get_qindex(&cm->seg, i, cm->base_qindex);
-      cm->y_dequant[i][0] = vp9_dc_quant(qindex, cm->y_dc_delta_q,
-                                         cm->bit_depth);
-      cm->y_dequant[i][1] = vp9_ac_quant(qindex, 0, cm->bit_depth);
-      cm->uv_dequant[i][0] = vp9_dc_quant(qindex, cm->uv_dc_delta_q,
-                                          cm->bit_depth);
-      cm->uv_dequant[i][1] = vp9_ac_quant(qindex, cm->uv_ac_delta_q,
-                                          cm->bit_depth);
-    }
-  } else {
-    const int qindex = cm->base_qindex;
-    // When segmentation is disabled, only the first value is used.  The
-    // remaining are don't cares.
-    cm->y_dequant[0][0] = vp9_dc_quant(qindex, cm->y_dc_delta_q, cm->bit_depth);
-    cm->y_dequant[0][1] = vp9_ac_quant(qindex, 0, cm->bit_depth);
-    cm->uv_dequant[0][0] = vp9_dc_quant(qindex, cm->uv_dc_delta_q,
-                                        cm->bit_depth);
-    cm->uv_dequant[0][1] = vp9_ac_quant(qindex, cm->uv_ac_delta_q,
-                                        cm->bit_depth);
-  }
-}
-
-static INTERP_FILTER read_interp_filter(struct vpx_read_bit_buffer *rb) {
-  const INTERP_FILTER literal_to_filter[] = { EIGHTTAP_SMOOTH,
-                                              EIGHTTAP,
-                                              EIGHTTAP_SHARP,
-                                              BILINEAR };
-  return vpx_rb_read_bit(rb) ? SWITCHABLE
-                             : literal_to_filter[vpx_rb_read_literal(rb, 2)];
-}
-
-static void setup_render_size(VP9_COMMON *cm, struct vpx_read_bit_buffer *rb) {
-  cm->render_width = cm->width;
-  cm->render_height = cm->height;
-  if (vpx_rb_read_bit(rb))
-    vp9_read_frame_size(rb, &cm->render_width, &cm->render_height);
-}
-
-static void resize_mv_buffer(VP9_COMMON *cm) {
-  vpx_free(cm->cur_frame->mvs);
-  cm->cur_frame->mi_rows = cm->mi_rows;
-  cm->cur_frame->mi_cols = cm->mi_cols;
-  CHECK_MEM_ERROR(cm, cm->cur_frame->mvs,
-                  (MV_REF *)vpx_calloc(cm->mi_rows * cm->mi_cols,
-                                       sizeof(*cm->cur_frame->mvs)));
-}
-
-static void resize_context_buffers(VP9_COMMON *cm, int width, int height) {
-#if CONFIG_SIZE_LIMIT
-  if (width > DECODE_WIDTH_LIMIT || height > DECODE_HEIGHT_LIMIT)
-    vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME,
-                       "Dimensions of %dx%d beyond allowed size of %dx%d.",
-                       width, height, DECODE_WIDTH_LIMIT, DECODE_HEIGHT_LIMIT);
-#endif
-  if (cm->width != width || cm->height != height) {
-    const int new_mi_rows =
-        ALIGN_POWER_OF_TWO(height, MI_SIZE_LOG2) >> MI_SIZE_LOG2;
-    const int new_mi_cols =
-        ALIGN_POWER_OF_TWO(width,  MI_SIZE_LOG2) >> MI_SIZE_LOG2;
-
-    // Allocations in vp9_alloc_context_buffers() depend on individual
-    // dimensions as well as the overall size.
-    if (new_mi_cols > cm->mi_cols || new_mi_rows > cm->mi_rows) {
-      if (vp9_alloc_context_buffers(cm, width, height))
-        vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR,
-                           "Failed to allocate context buffers");
-    } else {
-      vp9_set_mb_mi(cm, width, height);
-    }
-    vp9_init_context_buffers(cm);
-    cm->width = width;
-    cm->height = height;
-  }
-  if (cm->cur_frame->mvs == NULL || cm->mi_rows > cm->cur_frame->mi_rows ||
-      cm->mi_cols > cm->cur_frame->mi_cols) {
-    resize_mv_buffer(cm);
-  }
-}
-
-static void setup_frame_size(VP9_COMMON *cm, struct vpx_read_bit_buffer *rb) {
-  int width, height;
-  BufferPool *const pool = cm->buffer_pool;
-  vp9_read_frame_size(rb, &width, &height);
-  resize_context_buffers(cm, width, height);
-  setup_render_size(cm, rb);
-
-  lock_buffer_pool(pool);
-  if (vpx_realloc_frame_buffer(
-          get_frame_new_buffer(cm), cm->width, cm->height,
-          cm->subsampling_x, cm->subsampling_y,
-#if CONFIG_VP9_HIGHBITDEPTH
-          cm->use_highbitdepth,
-#endif
-          VP9_DEC_BORDER_IN_PIXELS,
-          cm->byte_alignment,
-          &pool->frame_bufs[cm->new_fb_idx].raw_frame_buffer, pool->get_fb_cb,
-          pool->cb_priv)) {
-    unlock_buffer_pool(pool);
-    vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR,
-                       "Failed to allocate frame buffer");
-  }
-  unlock_buffer_pool(pool);
-
-  pool->frame_bufs[cm->new_fb_idx].buf.subsampling_x = cm->subsampling_x;
-  pool->frame_bufs[cm->new_fb_idx].buf.subsampling_y = cm->subsampling_y;
-  pool->frame_bufs[cm->new_fb_idx].buf.bit_depth = (unsigned int)cm->bit_depth;
-  pool->frame_bufs[cm->new_fb_idx].buf.color_space = cm->color_space;
-  pool->frame_bufs[cm->new_fb_idx].buf.color_range = cm->color_range;
-  pool->frame_bufs[cm->new_fb_idx].buf.render_width  = cm->render_width;
-  pool->frame_bufs[cm->new_fb_idx].buf.render_height = cm->render_height;
-}
-
-static INLINE int valid_ref_frame_img_fmt(vpx_bit_depth_t ref_bit_depth,
-                                          int ref_xss, int ref_yss,
-                                          vpx_bit_depth_t this_bit_depth,
-                                          int this_xss, int this_yss) {
-  return ref_bit_depth == this_bit_depth && ref_xss == this_xss &&
-         ref_yss == this_yss;
-}
-
-static void setup_frame_size_with_refs(VP9_COMMON *cm,
-                                       struct vpx_read_bit_buffer *rb) {
-  int width, height;
-  int found = 0, i;
-  int has_valid_ref_frame = 0;
-  BufferPool *const pool = cm->buffer_pool;
-  for (i = 0; i < REFS_PER_FRAME; ++i) {
-    if (vpx_rb_read_bit(rb)) {
-      if (cm->frame_refs[i].idx != INVALID_IDX) {
-        YV12_BUFFER_CONFIG *const buf = cm->frame_refs[i].buf;
-        width = buf->y_crop_width;
-        height = buf->y_crop_height;
-        found = 1;
-        break;
-      } else {
-        vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME,
-                           "Failed to decode frame size");
-      }
-    }
-  }
-
-  if (!found)
-    vp9_read_frame_size(rb, &width, &height);
-
-  if (width <= 0 || height <= 0)
-    vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME,
-                       "Invalid frame size");
-
-  // Check to make sure at least one of frames that this frame references
-  // has valid dimensions.
-  for (i = 0; i < REFS_PER_FRAME; ++i) {
-    RefBuffer *const ref_frame = &cm->frame_refs[i];
-    has_valid_ref_frame |= (ref_frame->idx != INVALID_IDX &&
-                            valid_ref_frame_size(ref_frame->buf->y_crop_width,
-                                                 ref_frame->buf->y_crop_height,
-                                                 width, height));
-  }
-  if (!has_valid_ref_frame)
-    vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME,
-                       "Referenced frame has invalid size");
-  for (i = 0; i < REFS_PER_FRAME; ++i) {
-    RefBuffer *const ref_frame = &cm->frame_refs[i];
-    if (ref_frame->idx == INVALID_IDX ||
-        !valid_ref_frame_img_fmt(ref_frame->buf->bit_depth,
-                                 ref_frame->buf->subsampling_x,
-                                 ref_frame->buf->subsampling_y,
-                                 cm->bit_depth,
-                                 cm->subsampling_x,
-                                 cm->subsampling_y))
-      vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME,
-                         "Referenced frame has incompatible color format");
-  }
-
-  resize_context_buffers(cm, width, height);
-  setup_render_size(cm, rb);
-
-  lock_buffer_pool(pool);
-  if (vpx_realloc_frame_buffer(
-          get_frame_new_buffer(cm), cm->width, cm->height,
-          cm->subsampling_x, cm->subsampling_y,
-#if CONFIG_VP9_HIGHBITDEPTH
-          cm->use_highbitdepth,
-#endif
-          VP9_DEC_BORDER_IN_PIXELS,
-          cm->byte_alignment,
-          &pool->frame_bufs[cm->new_fb_idx].raw_frame_buffer, pool->get_fb_cb,
-          pool->cb_priv)) {
-    unlock_buffer_pool(pool);
-    vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR,
-                       "Failed to allocate frame buffer");
-  }
-  unlock_buffer_pool(pool);
-
-  pool->frame_bufs[cm->new_fb_idx].buf.subsampling_x = cm->subsampling_x;
-  pool->frame_bufs[cm->new_fb_idx].buf.subsampling_y = cm->subsampling_y;
-  pool->frame_bufs[cm->new_fb_idx].buf.bit_depth = (unsigned int)cm->bit_depth;
-  pool->frame_bufs[cm->new_fb_idx].buf.color_space = cm->color_space;
-  pool->frame_bufs[cm->new_fb_idx].buf.color_range = cm->color_range;
-  pool->frame_bufs[cm->new_fb_idx].buf.render_width  = cm->render_width;
-  pool->frame_bufs[cm->new_fb_idx].buf.render_height = cm->render_height;
-}
-
-static void setup_tile_info(VP9_COMMON *cm, struct vpx_read_bit_buffer *rb) {
-  int min_log2_tile_cols, max_log2_tile_cols, max_ones;
-  vp9_get_tile_n_bits(cm->mi_cols, &min_log2_tile_cols, &max_log2_tile_cols);
-
-  // columns
-  max_ones = max_log2_tile_cols - min_log2_tile_cols;
-  cm->log2_tile_cols = min_log2_tile_cols;
-  while (max_ones-- && vpx_rb_read_bit(rb))
-    cm->log2_tile_cols++;
-
-  if (cm->log2_tile_cols > 6)
-    vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME,
-                       "Invalid number of tile columns");
-
-  // rows
-  cm->log2_tile_rows = vpx_rb_read_bit(rb);
-  if (cm->log2_tile_rows)
-    cm->log2_tile_rows += vpx_rb_read_bit(rb);
-}
-
-// Reads the next tile returning its size and adjusting '*data' accordingly
-// based on 'is_last'.
-static void get_tile_buffer(const uint8_t *const data_end,
-                            int is_last,
-                            struct vpx_internal_error_info *error_info,
-                            const uint8_t **data,
-                            vpx_decrypt_cb decrypt_cb, void *decrypt_state,
-                            TileBuffer *buf) {
-  size_t size;
-
-  if (!is_last) {
-    if (!read_is_valid(*data, 4, data_end))
-      vpx_internal_error(error_info, VPX_CODEC_CORRUPT_FRAME,
-                         "Truncated packet or corrupt tile length");
-
-    if (decrypt_cb) {
-      uint8_t be_data[4];
-      decrypt_cb(decrypt_state, *data, be_data, 4);
-      size = mem_get_be32(be_data);
-    } else {
-      size = mem_get_be32(*data);
-    }
-    *data += 4;
-
-    if (size > (size_t)(data_end - *data))
-      vpx_internal_error(error_info, VPX_CODEC_CORRUPT_FRAME,
-                         "Truncated packet or corrupt tile size");
-  } else {
-    size = data_end - *data;
-  }
-
-  buf->data = *data;
-  buf->size = size;
-
-  *data += size;
-}
-
-static void get_tile_buffers(VP9Decoder *pbi,
-                             const uint8_t *data, const uint8_t *data_end,
-                             int tile_cols, int tile_rows,
-                             TileBuffer (*tile_buffers)[1 << 6]) {
-  int r, c;
-
-  for (r = 0; r < tile_rows; ++r) {
-    for (c = 0; c < tile_cols; ++c) {
-      const int is_last = (r == tile_rows - 1) && (c == tile_cols - 1);
-      TileBuffer *const buf = &tile_buffers[r][c];
-      buf->col = c;
-      get_tile_buffer(data_end, is_last, &pbi->common.error, &data,
-                      pbi->decrypt_cb, pbi->decrypt_state, buf);
-    }
-  }
-}
-
-static const uint8_t *decode_tiles(VP9Decoder *pbi,
-                                   const uint8_t *data,
-                                   const uint8_t *data_end) {
-  VP9_COMMON *const cm = &pbi->common;
-  const VPxWorkerInterface *const winterface = vpx_get_worker_interface();
-  const int aligned_cols = mi_cols_aligned_to_sb(cm->mi_cols);
-  const int tile_cols = 1 << cm->log2_tile_cols;
-  const int tile_rows = 1 << cm->log2_tile_rows;
-  TileBuffer tile_buffers[4][1 << 6];
-  int tile_row, tile_col;
-  int mi_row, mi_col;
-  TileWorkerData *tile_data = NULL;
-
-  if (cm->lf.filter_level && !cm->skip_loop_filter &&
-      pbi->lf_worker.data1 == NULL) {
-    CHECK_MEM_ERROR(cm, pbi->lf_worker.data1,
-                    vpx_memalign(32, sizeof(LFWorkerData)));
-    pbi->lf_worker.hook = (VPxWorkerHook)vp9_loop_filter_worker;
-    if (pbi->max_threads > 1 && !winterface->reset(&pbi->lf_worker)) {
-      vpx_internal_error(&cm->error, VPX_CODEC_ERROR,
-                         "Loop filter thread creation failed");
-    }
-  }
-
-  if (cm->lf.filter_level && !cm->skip_loop_filter) {
-    LFWorkerData *const lf_data = (LFWorkerData*)pbi->lf_worker.data1;
-    // Be sure to sync as we might be resuming after a failed frame decode.
-    winterface->sync(&pbi->lf_worker);
-    vp9_loop_filter_data_reset(lf_data, get_frame_new_buffer(cm), cm,
-                               pbi->mb.plane);
-  }
-
-  assert(tile_rows <= 4);
-  assert(tile_cols <= (1 << 6));
-
-  // Note: this memset assumes above_context[0], [1] and [2]
-  // are allocated as part of the same buffer.
-  memset(cm->above_context, 0,
-         sizeof(*cm->above_context) * MAX_MB_PLANE * 2 * aligned_cols);
-
-  memset(cm->above_seg_context, 0,
-         sizeof(*cm->above_seg_context) * aligned_cols);
-
-  vp9_reset_lfm(cm);
-
-  get_tile_buffers(pbi, data, data_end, tile_cols, tile_rows, tile_buffers);
-
-  // Load all tile information into tile_data.
-  for (tile_row = 0; tile_row < tile_rows; ++tile_row) {
-    for (tile_col = 0; tile_col < tile_cols; ++tile_col) {
-      const TileBuffer *const buf = &tile_buffers[tile_row][tile_col];
-      tile_data = pbi->tile_worker_data + tile_cols * tile_row + tile_col;
-      tile_data->xd = pbi->mb;
-      tile_data->xd.corrupted = 0;
-      tile_data->xd.counts =
-          cm->frame_parallel_decoding_mode ? NULL : &cm->counts;
-      vp9_zero(tile_data->dqcoeff);
-      vp9_tile_init(&tile_data->xd.tile, cm, tile_row, tile_col);
-      setup_token_decoder(buf->data, data_end, buf->size, &cm->error,
-                          &tile_data->bit_reader, pbi->decrypt_cb,
-                          pbi->decrypt_state);
-      vp9_init_macroblockd(cm, &tile_data->xd, tile_data->dqcoeff);
-    }
-  }
-
-  for (tile_row = 0; tile_row < tile_rows; ++tile_row) {
-    TileInfo tile;
-    vp9_tile_set_row(&tile, cm, tile_row);
-    for (mi_row = tile.mi_row_start; mi_row < tile.mi_row_end;
-         mi_row += MI_BLOCK_SIZE) {
-      for (tile_col = 0; tile_col < tile_cols; ++tile_col) {
-        const int col = pbi->inv_tile_order ?
-                        tile_cols - tile_col - 1 : tile_col;
-        tile_data = pbi->tile_worker_data + tile_cols * tile_row + col;
-        vp9_tile_set_col(&tile, cm, col);
-        vp9_zero(tile_data->xd.left_context);
-        vp9_zero(tile_data->xd.left_seg_context);
-        for (mi_col = tile.mi_col_start; mi_col < tile.mi_col_end;
-             mi_col += MI_BLOCK_SIZE) {
-          decode_partition(pbi, &tile_data->xd, mi_row,
-                           mi_col, &tile_data->bit_reader, BLOCK_64X64, 4);
-        }
-        pbi->mb.corrupted |= tile_data->xd.corrupted;
-        if (pbi->mb.corrupted)
-            vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME,
-                               "Failed to decode tile data");
-      }
-      // Loopfilter one row.
-      if (cm->lf.filter_level && !cm->skip_loop_filter) {
-        const int lf_start = mi_row - MI_BLOCK_SIZE;
-        LFWorkerData *const lf_data = (LFWorkerData*)pbi->lf_worker.data1;
-
-        // delay the loopfilter by 1 macroblock row.
-        if (lf_start < 0) continue;
-
-        // decoding has completed: finish up the loop filter in this thread.
-        if (mi_row + MI_BLOCK_SIZE >= cm->mi_rows) continue;
-
-        winterface->sync(&pbi->lf_worker);
-        lf_data->start = lf_start;
-        lf_data->stop = mi_row;
-        if (pbi->max_threads > 1) {
-          winterface->launch(&pbi->lf_worker);
-        } else {
-          winterface->execute(&pbi->lf_worker);
-        }
-      }
-      // After loopfiltering, the last 7 row pixels in each superblock row may
-      // still be changed by the longest loopfilter of the next superblock
-      // row.
-      if (pbi->frame_parallel_decode)
-        vp9_frameworker_broadcast(pbi->cur_buf,
-                                  mi_row << MI_BLOCK_SIZE_LOG2);
-    }
-  }
-
-  // Loopfilter remaining rows in the frame.
-  if (cm->lf.filter_level && !cm->skip_loop_filter) {
-    LFWorkerData *const lf_data = (LFWorkerData*)pbi->lf_worker.data1;
-    winterface->sync(&pbi->lf_worker);
-    lf_data->start = lf_data->stop;
-    lf_data->stop = cm->mi_rows;
-    winterface->execute(&pbi->lf_worker);
-  }
-
-  // Get last tile data.
-  tile_data = pbi->tile_worker_data + tile_cols * tile_rows - 1;
-
-  if (pbi->frame_parallel_decode)
-    vp9_frameworker_broadcast(pbi->cur_buf, INT_MAX);
-  return vpx_reader_find_end(&tile_data->bit_reader);
-}
-
-// On entry 'tile_data->data_end' points to the end of the input frame, on exit
-// it is updated to reflect the bitreader position of the final tile column if
-// present in the tile buffer group or NULL otherwise.
-static int tile_worker_hook(TileWorkerData *const tile_data,
-                            VP9Decoder *const pbi) {
-  TileInfo *volatile tile = &tile_data->xd.tile;
-  const int final_col = (1 << pbi->common.log2_tile_cols) - 1;
-  const uint8_t *volatile bit_reader_end = NULL;
-  volatile int n = tile_data->buf_start;
-  tile_data->error_info.setjmp = 1;
-
-  if (setjmp(tile_data->error_info.jmp)) {
-    tile_data->error_info.setjmp = 0;
-    tile_data->xd.corrupted = 1;
-    tile_data->data_end = NULL;
-    return 0;
-  }
-
-  tile_data->xd.error_info = &tile_data->error_info;
-  tile_data->xd.corrupted = 0;
-
-  do {
-    int mi_row, mi_col;
-    const TileBuffer *const buf = pbi->tile_buffers + n;
-    vp9_zero(tile_data->dqcoeff);
-    vp9_tile_init(tile, &pbi->common, 0, buf->col);
-    setup_token_decoder(buf->data, tile_data->data_end, buf->size,
-                        &tile_data->error_info, &tile_data->bit_reader,
-                        pbi->decrypt_cb, pbi->decrypt_state);
-    vp9_init_macroblockd(&pbi->common, &tile_data->xd, tile_data->dqcoeff);
-
-    for (mi_row = tile->mi_row_start; mi_row < tile->mi_row_end;
-         mi_row += MI_BLOCK_SIZE) {
-      vp9_zero(tile_data->xd.left_context);
-      vp9_zero(tile_data->xd.left_seg_context);
-      for (mi_col = tile->mi_col_start; mi_col < tile->mi_col_end;
-           mi_col += MI_BLOCK_SIZE) {
-        decode_partition(pbi, &tile_data->xd, mi_row, mi_col,
-                         &tile_data->bit_reader, BLOCK_64X64, 4);
-      }
-    }
-
-    if (buf->col == final_col) {
-      bit_reader_end = vpx_reader_find_end(&tile_data->bit_reader);
-    }
-  } while (!tile_data->xd.corrupted && ++n <= tile_data->buf_end);
-
-  tile_data->data_end = bit_reader_end;
-  return !tile_data->xd.corrupted;
-}
-
-// sorts in descending order
-static int compare_tile_buffers(const void *a, const void *b) {
-  const TileBuffer *const buf1 = (const TileBuffer*)a;
-  const TileBuffer *const buf2 = (const TileBuffer*)b;
-  return (int)(buf2->size - buf1->size);
-}
-
-static const uint8_t *decode_tiles_mt(VP9Decoder *pbi,
-                                      const uint8_t *data,
-                                      const uint8_t *data_end) {
-  VP9_COMMON *const cm = &pbi->common;
-  const VPxWorkerInterface *const winterface = vpx_get_worker_interface();
-  const uint8_t *bit_reader_end = NULL;
-  const int aligned_mi_cols = mi_cols_aligned_to_sb(cm->mi_cols);
-  const int tile_cols = 1 << cm->log2_tile_cols;
-  const int tile_rows = 1 << cm->log2_tile_rows;
-  const int num_workers = VPXMIN(pbi->max_threads, tile_cols);
-  int n;
-
-  assert(tile_cols <= (1 << 6));
-  assert(tile_rows == 1);
-  (void)tile_rows;
-
-  if (pbi->num_tile_workers == 0) {
-    const int num_threads = pbi->max_threads;
-    CHECK_MEM_ERROR(cm, pbi->tile_workers,
-                    vpx_malloc(num_threads * sizeof(*pbi->tile_workers)));
-    for (n = 0; n < num_threads; ++n) {
-      VPxWorker *const worker = &pbi->tile_workers[n];
-      ++pbi->num_tile_workers;
-
-      winterface->init(worker);
-      if (n < num_threads - 1 && !winterface->reset(worker)) {
-        vpx_internal_error(&cm->error, VPX_CODEC_ERROR,
-                           "Tile decoder thread creation failed");
-      }
-    }
-  }
-
-  // Reset tile decoding hook
-  for (n = 0; n < num_workers; ++n) {
-    VPxWorker *const worker = &pbi->tile_workers[n];
-    TileWorkerData *const tile_data =
-        &pbi->tile_worker_data[n + pbi->total_tiles];
-    winterface->sync(worker);
-    tile_data->xd = pbi->mb;
-    tile_data->xd.counts =
-        cm->frame_parallel_decoding_mode ? NULL : &tile_data->counts;
-    worker->hook = (VPxWorkerHook)tile_worker_hook;
-    worker->data1 = tile_data;
-    worker->data2 = pbi;
-  }
-
-  // Note: this memset assumes above_context[0], [1] and [2]
-  // are allocated as part of the same buffer.
-  memset(cm->above_context, 0,
-         sizeof(*cm->above_context) * MAX_MB_PLANE * 2 * aligned_mi_cols);
-  memset(cm->above_seg_context, 0,
-         sizeof(*cm->above_seg_context) * aligned_mi_cols);
-
-  vp9_reset_lfm(cm);
-
-  // Load tile data into tile_buffers
-  get_tile_buffers(pbi, data, data_end, tile_cols, tile_rows,
-                   &pbi->tile_buffers);
-
-  // Sort the buffers based on size in descending order.
-  qsort(pbi->tile_buffers, tile_cols, sizeof(pbi->tile_buffers[0]),
-        compare_tile_buffers);
-
-  if (num_workers == tile_cols) {
-    // Rearrange the tile buffers such that the largest, and
-    // presumably the most difficult, tile will be decoded in the main thread.
-    // This should help minimize the number of instances where the main thread
-    // is waiting for a worker to complete.
-    const TileBuffer largest = pbi->tile_buffers[0];
-    memmove(pbi->tile_buffers, pbi->tile_buffers + 1,
-            (tile_cols - 1) * sizeof(pbi->tile_buffers[0]));
-    pbi->tile_buffers[tile_cols - 1] = largest;
-  } else {
-    int start = 0, end = tile_cols - 2;
-    TileBuffer tmp;
-
-    // Interleave the tiles to distribute the load between threads, assuming a
-    // larger tile implies it is more difficult to decode.
-    while (start < end) {
-      tmp = pbi->tile_buffers[start];
-      pbi->tile_buffers[start] = pbi->tile_buffers[end];
-      pbi->tile_buffers[end] = tmp;
-      start += 2;
-      end -= 2;
-    }
-  }
-
-  // Initialize thread frame counts.
-  if (!cm->frame_parallel_decoding_mode) {
-    for (n = 0; n < num_workers; ++n) {
-      TileWorkerData *const tile_data =
-          (TileWorkerData*)pbi->tile_workers[n].data1;
-      vp9_zero(tile_data->counts);
-    }
-  }
-
-  {
-    const int base = tile_cols / num_workers;
-    const int remain = tile_cols % num_workers;
-    int buf_start = 0;
-
-    for (n = 0; n < num_workers; ++n) {
-      const int count = base + (remain + n) / num_workers;
-      VPxWorker *const worker = &pbi->tile_workers[n];
-      TileWorkerData *const tile_data = (TileWorkerData*)worker->data1;
-
-      tile_data->buf_start = buf_start;
-      tile_data->buf_end = buf_start + count - 1;
-      tile_data->data_end = data_end;
-      buf_start += count;
-
-      worker->had_error = 0;
-      if (n == num_workers - 1) {
-        assert(tile_data->buf_end == tile_cols - 1);
-        winterface->execute(worker);
-      } else {
-        winterface->launch(worker);
-      }
-    }
-
-    for (; n > 0; --n) {
-      VPxWorker *const worker = &pbi->tile_workers[n - 1];
-      TileWorkerData *const tile_data = (TileWorkerData*)worker->data1;
-      // TODO(jzern): The tile may have specific error data associated with
-      // its vpx_internal_error_info which could be propagated to the main info
-      // in cm. Additionally once the threads have been synced and an error is
-      // detected, there's no point in continuing to decode tiles.
-      pbi->mb.corrupted |= !winterface->sync(worker);
-      if (!bit_reader_end) bit_reader_end = tile_data->data_end;
-    }
-  }
-
-  // Accumulate thread frame counts.
-  if (!cm->frame_parallel_decoding_mode) {
-    for (n = 0; n < num_workers; ++n) {
-      TileWorkerData *const tile_data =
-          (TileWorkerData*)pbi->tile_workers[n].data1;
-      vp9_accumulate_frame_counts(&cm->counts, &tile_data->counts, 1);
-    }
-  }
-
-  assert(bit_reader_end || pbi->mb.corrupted);
-  return bit_reader_end;
-}
-
-static void error_handler(void *data) {
-  VP9_COMMON *const cm = (VP9_COMMON *)data;
-  vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME, "Truncated packet");
-}
-
-static void read_bitdepth_colorspace_sampling(
-    VP9_COMMON *cm, struct vpx_read_bit_buffer *rb) {
-  if (cm->profile >= PROFILE_2) {
-    cm->bit_depth = vpx_rb_read_bit(rb) ? VPX_BITS_12 : VPX_BITS_10;
-#if CONFIG_VP9_HIGHBITDEPTH
-    cm->use_highbitdepth = 1;
-#endif
-  } else {
-    cm->bit_depth = VPX_BITS_8;
-#if CONFIG_VP9_HIGHBITDEPTH
-    cm->use_highbitdepth = 0;
-#endif
-  }
-  cm->color_space = vpx_rb_read_literal(rb, 3);
-  if (cm->color_space != VPX_CS_SRGB) {
-    cm->color_range = (vpx_color_range_t)vpx_rb_read_bit(rb);
-    if (cm->profile == PROFILE_1 || cm->profile == PROFILE_3) {
-      cm->subsampling_x = vpx_rb_read_bit(rb);
-      cm->subsampling_y = vpx_rb_read_bit(rb);
-      if (cm->subsampling_x == 1 && cm->subsampling_y == 1)
-        vpx_internal_error(&cm->error, VPX_CODEC_UNSUP_BITSTREAM,
-                           "4:2:0 color not supported in profile 1 or 3");
-      if (vpx_rb_read_bit(rb))
-        vpx_internal_error(&cm->error, VPX_CODEC_UNSUP_BITSTREAM,
-                           "Reserved bit set");
-    } else {
-      cm->subsampling_y = cm->subsampling_x = 1;
-    }
-  } else {
-    cm->color_range = VPX_CR_FULL_RANGE;
-    if (cm->profile == PROFILE_1 || cm->profile == PROFILE_3) {
-      // Note if colorspace is SRGB then 4:4:4 chroma sampling is assumed.
-      // 4:2:2 or 4:4:0 chroma sampling is not allowed.
-      cm->subsampling_y = cm->subsampling_x = 0;
-      if (vpx_rb_read_bit(rb))
-        vpx_internal_error(&cm->error, VPX_CODEC_UNSUP_BITSTREAM,
-                           "Reserved bit set");
-    } else {
-      vpx_internal_error(&cm->error, VPX_CODEC_UNSUP_BITSTREAM,
-                         "4:4:4 color not supported in profile 0 or 2");
-    }
-  }
-}
-
-static size_t read_uncompressed_header(VP9Decoder *pbi,
-                                       struct vpx_read_bit_buffer *rb) {
-  VP9_COMMON *const cm = &pbi->common;
-  BufferPool *const pool = cm->buffer_pool;
-  RefCntBuffer *const frame_bufs = pool->frame_bufs;
-  int i, mask, ref_index = 0;
-  size_t sz;
-
-  cm->last_frame_type = cm->frame_type;
-  cm->last_intra_only = cm->intra_only;
-
-  if (vpx_rb_read_literal(rb, 2) != VP9_FRAME_MARKER)
-      vpx_internal_error(&cm->error, VPX_CODEC_UNSUP_BITSTREAM,
-                         "Invalid frame marker");
-
-  cm->profile = vp9_read_profile(rb);
-#if CONFIG_VP9_HIGHBITDEPTH
-  if (cm->profile >= MAX_PROFILES)
-    vpx_internal_error(&cm->error, VPX_CODEC_UNSUP_BITSTREAM,
-                       "Unsupported bitstream profile");
-#else
-  if (cm->profile >= PROFILE_2)
-    vpx_internal_error(&cm->error, VPX_CODEC_UNSUP_BITSTREAM,
-                       "Unsupported bitstream profile");
-#endif
-
-  cm->show_existing_frame = vpx_rb_read_bit(rb);
-  if (cm->show_existing_frame) {
-    // Show an existing frame directly.
-    const int frame_to_show = cm->ref_frame_map[vpx_rb_read_literal(rb, 3)];
-    lock_buffer_pool(pool);
-    if (frame_to_show < 0 || frame_bufs[frame_to_show].ref_count < 1) {
-      unlock_buffer_pool(pool);
-      vpx_internal_error(&cm->error, VPX_CODEC_UNSUP_BITSTREAM,
-                         "Buffer %d does not contain a decoded frame",
-                         frame_to_show);
-    }
-
-    ref_cnt_fb(frame_bufs, &cm->new_fb_idx, frame_to_show);
-    unlock_buffer_pool(pool);
-    pbi->refresh_frame_flags = 0;
-    cm->lf.filter_level = 0;
-    cm->show_frame = 1;
-
-    if (pbi->frame_parallel_decode) {
-      for (i = 0; i < REF_FRAMES; ++i)
-        cm->next_ref_frame_map[i] = cm->ref_frame_map[i];
-    }
-    return 0;
-  }
-
-  cm->frame_type = (FRAME_TYPE) vpx_rb_read_bit(rb);
-  cm->show_frame = vpx_rb_read_bit(rb);
-  cm->error_resilient_mode = vpx_rb_read_bit(rb);
-
-  if (cm->frame_type == KEY_FRAME) {
-    if (!vp9_read_sync_code(rb))
-      vpx_internal_error(&cm->error, VPX_CODEC_UNSUP_BITSTREAM,
-                         "Invalid frame sync code");
-
-    read_bitdepth_colorspace_sampling(cm, rb);
-    pbi->refresh_frame_flags = (1 << REF_FRAMES) - 1;
-
-    for (i = 0; i < REFS_PER_FRAME; ++i) {
-      cm->frame_refs[i].idx = INVALID_IDX;
-      cm->frame_refs[i].buf = NULL;
-    }
-
-    setup_frame_size(cm, rb);
-    if (pbi->need_resync) {
-      memset(&cm->ref_frame_map, -1, sizeof(cm->ref_frame_map));
-      pbi->need_resync = 0;
-    }
-  } else {
-    cm->intra_only = cm->show_frame ? 0 : vpx_rb_read_bit(rb);
-
-    cm->reset_frame_context = cm->error_resilient_mode ?
-        0 : vpx_rb_read_literal(rb, 2);
-
-    if (cm->intra_only) {
-      if (!vp9_read_sync_code(rb))
-        vpx_internal_error(&cm->error, VPX_CODEC_UNSUP_BITSTREAM,
-                           "Invalid frame sync code");
-      if (cm->profile > PROFILE_0) {
-        read_bitdepth_colorspace_sampling(cm, rb);
-      } else {
-        // NOTE: The intra-only frame header does not include the specification
-        // of either the color format or color sub-sampling in profile 0. VP9
-        // specifies that the default color format should be YUV 4:2:0 in this
-        // case (normative).
-        cm->color_space = VPX_CS_BT_601;
-        cm->color_range = VPX_CR_STUDIO_RANGE;
-        cm->subsampling_y = cm->subsampling_x = 1;
-        cm->bit_depth = VPX_BITS_8;
-#if CONFIG_VP9_HIGHBITDEPTH
-        cm->use_highbitdepth = 0;
-#endif
-      }
-
-      pbi->refresh_frame_flags = vpx_rb_read_literal(rb, REF_FRAMES);
-      setup_frame_size(cm, rb);
-      if (pbi->need_resync) {
-        memset(&cm->ref_frame_map, -1, sizeof(cm->ref_frame_map));
-        pbi->need_resync = 0;
-      }
-    } else if (pbi->need_resync != 1) {  /* Skip if need resync */
-      pbi->refresh_frame_flags = vpx_rb_read_literal(rb, REF_FRAMES);
-      for (i = 0; i < REFS_PER_FRAME; ++i) {
-        const int ref = vpx_rb_read_literal(rb, REF_FRAMES_LOG2);
-        const int idx = cm->ref_frame_map[ref];
-        RefBuffer *const ref_frame = &cm->frame_refs[i];
-        ref_frame->idx = idx;
-        ref_frame->buf = &frame_bufs[idx].buf;
-        cm->ref_frame_sign_bias[LAST_FRAME + i] = vpx_rb_read_bit(rb);
-      }
-
-      setup_frame_size_with_refs(cm, rb);
-
-      cm->allow_high_precision_mv = vpx_rb_read_bit(rb);
-      cm->interp_filter = read_interp_filter(rb);
-
-      for (i = 0; i < REFS_PER_FRAME; ++i) {
-        RefBuffer *const ref_buf = &cm->frame_refs[i];
-#if CONFIG_VP9_HIGHBITDEPTH
-        vp9_setup_scale_factors_for_frame(&ref_buf->sf,
-                                          ref_buf->buf->y_crop_width,
-                                          ref_buf->buf->y_crop_height,
-                                          cm->width, cm->height,
-                                          cm->use_highbitdepth);
-#else
-        vp9_setup_scale_factors_for_frame(&ref_buf->sf,
-                                          ref_buf->buf->y_crop_width,
-                                          ref_buf->buf->y_crop_height,
-                                          cm->width, cm->height);
-#endif
-      }
-    }
-  }
-#if CONFIG_VP9_HIGHBITDEPTH
-  get_frame_new_buffer(cm)->bit_depth = cm->bit_depth;
-#endif
-  get_frame_new_buffer(cm)->color_space = cm->color_space;
-  get_frame_new_buffer(cm)->color_range = cm->color_range;
-  get_frame_new_buffer(cm)->render_width  = cm->render_width;
-  get_frame_new_buffer(cm)->render_height = cm->render_height;
-
-  if (pbi->need_resync) {
-    vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME,
-                       "Keyframe / intra-only frame required to reset decoder"
-                       " state");
-  }
-
-  if (!cm->error_resilient_mode) {
-    cm->refresh_frame_context = vpx_rb_read_bit(rb);
-    cm->frame_parallel_decoding_mode = vpx_rb_read_bit(rb);
-    if (!cm->frame_parallel_decoding_mode)
-      vp9_zero(cm->counts);
-  } else {
-    cm->refresh_frame_context = 0;
-    cm->frame_parallel_decoding_mode = 1;
-  }
-
-  // This flag will be overridden by the call to vp9_setup_past_independence
-  // below, forcing the use of context 0 for those frame types.
-  cm->frame_context_idx = vpx_rb_read_literal(rb, FRAME_CONTEXTS_LOG2);
-
-  // Generate next_ref_frame_map.
-  lock_buffer_pool(pool);
-  for (mask = pbi->refresh_frame_flags; mask; mask >>= 1) {
-    if (mask & 1) {
-      cm->next_ref_frame_map[ref_index] = cm->new_fb_idx;
-      ++frame_bufs[cm->new_fb_idx].ref_count;
-    } else {
-      cm->next_ref_frame_map[ref_index] = cm->ref_frame_map[ref_index];
-    }
-    // Current thread holds the reference frame.
-    if (cm->ref_frame_map[ref_index] >= 0)
-      ++frame_bufs[cm->ref_frame_map[ref_index]].ref_count;
-    ++ref_index;
-  }
-
-  for (; ref_index < REF_FRAMES; ++ref_index) {
-    cm->next_ref_frame_map[ref_index] = cm->ref_frame_map[ref_index];
-    // Current thread holds the reference frame.
-    if (cm->ref_frame_map[ref_index] >= 0)
-      ++frame_bufs[cm->ref_frame_map[ref_index]].ref_count;
-  }
-  unlock_buffer_pool(pool);
-  pbi->hold_ref_buf = 1;
-
-  if (frame_is_intra_only(cm) || cm->error_resilient_mode)
-    vp9_setup_past_independence(cm);
-
-  setup_loopfilter(&cm->lf, rb);
-  setup_quantization(cm, &pbi->mb, rb);
-  setup_segmentation(&cm->seg, rb);
-  setup_segmentation_dequant(cm);
-
-  setup_tile_info(cm, rb);
-  sz = vpx_rb_read_literal(rb, 16);
-
-  if (sz == 0)
-    vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME,
-                       "Invalid header size");
-
-  return sz;
-}
-
-static int read_compressed_header(VP9Decoder *pbi, const uint8_t *data,
-                                  size_t partition_size) {
-  VP9_COMMON *const cm = &pbi->common;
-  MACROBLOCKD *const xd = &pbi->mb;
-  FRAME_CONTEXT *const fc = cm->fc;
-  vpx_reader r;
-  int k;
-
-  if (vpx_reader_init(&r, data, partition_size, pbi->decrypt_cb,
-                      pbi->decrypt_state))
-    vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR,
-                       "Failed to allocate bool decoder 0");
-
-  cm->tx_mode = xd->lossless ? ONLY_4X4 : read_tx_mode(&r);
-  if (cm->tx_mode == TX_MODE_SELECT)
-    read_tx_mode_probs(&fc->tx_probs, &r);
-  read_coef_probs(fc, cm->tx_mode, &r);
-
-  for (k = 0; k < SKIP_CONTEXTS; ++k)
-    vp9_diff_update_prob(&r, &fc->skip_probs[k]);
-
-  if (!frame_is_intra_only(cm)) {
-    nmv_context *const nmvc = &fc->nmvc;
-    int i, j;
-
-    read_inter_mode_probs(fc, &r);
-
-    if (cm->interp_filter == SWITCHABLE)
-      read_switchable_interp_probs(fc, &r);
-
-    for (i = 0; i < INTRA_INTER_CONTEXTS; i++)
-      vp9_diff_update_prob(&r, &fc->intra_inter_prob[i]);
-
-    cm->reference_mode = read_frame_reference_mode(cm, &r);
-    if (cm->reference_mode != SINGLE_REFERENCE)
-      setup_compound_reference_mode(cm);
-    read_frame_reference_mode_probs(cm, &r);
-
-    for (j = 0; j < BLOCK_SIZE_GROUPS; j++)
-      for (i = 0; i < INTRA_MODES - 1; ++i)
-        vp9_diff_update_prob(&r, &fc->y_mode_prob[j][i]);
-
-    for (j = 0; j < PARTITION_CONTEXTS; ++j)
-      for (i = 0; i < PARTITION_TYPES - 1; ++i)
-        vp9_diff_update_prob(&r, &fc->partition_prob[j][i]);
-
-    read_mv_probs(nmvc, cm->allow_high_precision_mv, &r);
-  }
-
-  return vpx_reader_has_error(&r);
-}
-
-static struct vpx_read_bit_buffer *init_read_bit_buffer(
-    VP9Decoder *pbi,
-    struct vpx_read_bit_buffer *rb,
-    const uint8_t *data,
-    const uint8_t *data_end,
-    uint8_t clear_data[MAX_VP9_HEADER_SIZE]) {
-  rb->bit_offset = 0;
-  rb->error_handler = error_handler;
-  rb->error_handler_data = &pbi->common;
-  if (pbi->decrypt_cb) {
-    const int n = (int)VPXMIN(MAX_VP9_HEADER_SIZE, data_end - data);
-    pbi->decrypt_cb(pbi->decrypt_state, data, clear_data, n);
-    rb->bit_buffer = clear_data;
-    rb->bit_buffer_end = clear_data + n;
-  } else {
-    rb->bit_buffer = data;
-    rb->bit_buffer_end = data_end;
-  }
-  return rb;
-}
-
-//------------------------------------------------------------------------------
-
-int vp9_read_sync_code(struct vpx_read_bit_buffer *const rb) {
-  return vpx_rb_read_literal(rb, 8) == VP9_SYNC_CODE_0 &&
-         vpx_rb_read_literal(rb, 8) == VP9_SYNC_CODE_1 &&
-         vpx_rb_read_literal(rb, 8) == VP9_SYNC_CODE_2;
-}
-
-void vp9_read_frame_size(struct vpx_read_bit_buffer *rb,
-                         int *width, int *height) {
-  *width = vpx_rb_read_literal(rb, 16) + 1;
-  *height = vpx_rb_read_literal(rb, 16) + 1;
-}
-
-BITSTREAM_PROFILE vp9_read_profile(struct vpx_read_bit_buffer *rb) {
-  int profile = vpx_rb_read_bit(rb);
-  profile |= vpx_rb_read_bit(rb) << 1;
-  if (profile > 2)
-    profile += vpx_rb_read_bit(rb);
-  return (BITSTREAM_PROFILE) profile;
-}
-
-void vp9_decode_frame(VP9Decoder *pbi,
-                      const uint8_t *data, const uint8_t *data_end,
-                      const uint8_t **p_data_end) {
-  VP9_COMMON *const cm = &pbi->common;
-  MACROBLOCKD *const xd = &pbi->mb;
-  struct vpx_read_bit_buffer rb;
-  int context_updated = 0;
-  uint8_t clear_data[MAX_VP9_HEADER_SIZE];
-  const size_t first_partition_size = read_uncompressed_header(pbi,
-      init_read_bit_buffer(pbi, &rb, data, data_end, clear_data));
-  const int tile_rows = 1 << cm->log2_tile_rows;
-  const int tile_cols = 1 << cm->log2_tile_cols;
-  YV12_BUFFER_CONFIG *const new_fb = get_frame_new_buffer(cm);
-  xd->cur_buf = new_fb;
-
-  if (!first_partition_size) {
-    // showing a frame directly
-    *p_data_end = data + (cm->profile <= PROFILE_2 ? 1 : 2);
-    return;
-  }
-
-  data += vpx_rb_bytes_read(&rb);
-  if (!read_is_valid(data, first_partition_size, data_end))
-    vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME,
-                       "Truncated packet or corrupt header length");
-
-  cm->use_prev_frame_mvs = !cm->error_resilient_mode &&
-                           cm->width == cm->last_width &&
-                           cm->height == cm->last_height &&
-                           !cm->last_intra_only &&
-                           cm->last_show_frame &&
-                           (cm->last_frame_type != KEY_FRAME);
-
-  vp9_setup_block_planes(xd, cm->subsampling_x, cm->subsampling_y);
-
-  *cm->fc = cm->frame_contexts[cm->frame_context_idx];
-  if (!cm->fc->initialized)
-    vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME,
-                       "Uninitialized entropy context.");
-
-  xd->corrupted = 0;
-  new_fb->corrupted = read_compressed_header(pbi, data, first_partition_size);
-  if (new_fb->corrupted)
-    vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME,
-                       "Decode failed. Frame data header is corrupted.");
-
-  if (cm->lf.filter_level && !cm->skip_loop_filter) {
-    vp9_loop_filter_frame_init(cm, cm->lf.filter_level);
-  }
-
-  // If encoded in frame parallel mode, frame context is ready after decoding
-  // the frame header.
-  if (pbi->frame_parallel_decode && cm->frame_parallel_decoding_mode) {
-    VPxWorker *const worker = pbi->frame_worker_owner;
-    FrameWorkerData *const frame_worker_data = worker->data1;
-    if (cm->refresh_frame_context) {
-      context_updated = 1;
-      cm->frame_contexts[cm->frame_context_idx] = *cm->fc;
-    }
-    vp9_frameworker_lock_stats(worker);
-    pbi->cur_buf->row = -1;
-    pbi->cur_buf->col = -1;
-    frame_worker_data->frame_context_ready = 1;
-    // Signal the main thread that context is ready.
-    vp9_frameworker_signal_stats(worker);
-    vp9_frameworker_unlock_stats(worker);
-  }
-
-  if (pbi->tile_worker_data == NULL ||
-      (tile_cols * tile_rows) != pbi->total_tiles) {
-    const int num_tile_workers = tile_cols * tile_rows +
-        ((pbi->max_threads > 1) ? pbi->max_threads : 0);
-    const size_t twd_size = num_tile_workers * sizeof(*pbi->tile_worker_data);
-    // Ensure tile data offsets will be properly aligned. This may fail on
-    // platforms without DECLARE_ALIGNED().
-    assert((sizeof(*pbi->tile_worker_data) % 16) == 0);
-    vpx_free(pbi->tile_worker_data);
-    CHECK_MEM_ERROR(cm, pbi->tile_worker_data, vpx_memalign(32, twd_size));
-    pbi->total_tiles = tile_rows * tile_cols;
-  }
-
-  if (pbi->max_threads > 1 && tile_rows == 1 && tile_cols > 1) {
-    // Multi-threaded tile decoder
-    *p_data_end = decode_tiles_mt(pbi, data + first_partition_size, data_end);
-    if (!xd->corrupted) {
-      if (!cm->skip_loop_filter) {
-        // If multiple threads are used to decode tiles, then we use those
-        // threads to do parallel loopfiltering.
-        vp9_loop_filter_frame_mt(new_fb, cm, pbi->mb.plane,
-                                 cm->lf.filter_level, 0, 0, pbi->tile_workers,
-                                 pbi->num_tile_workers, &pbi->lf_row_sync);
-      }
-    } else {
-      vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME,
-                         "Decode failed. Frame data is corrupted.");
-    }
-  } else {
-    *p_data_end = decode_tiles(pbi, data + first_partition_size, data_end);
-  }
-
-  if (!xd->corrupted) {
-    if (!cm->error_resilient_mode && !cm->frame_parallel_decoding_mode) {
-      vp9_adapt_coef_probs(cm);
-
-      if (!frame_is_intra_only(cm)) {
-        vp9_adapt_mode_probs(cm);
-        vp9_adapt_mv_probs(cm, cm->allow_high_precision_mv);
-      }
-    }
-  } else {
-    vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME,
-                       "Decode failed. Frame data is corrupted.");
-  }
-
-  // Non frame parallel update frame context here.
-  if (cm->refresh_frame_context && !context_updated)
-    cm->frame_contexts[cm->frame_context_idx] = *cm->fc;
-}
diff --git a/vp9/decoder/vp9_decodeframe.h b/vp9/decoder/vp9_decodeframe.h
deleted file mode 100644 (file)
index ce33cbd..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#ifndef VP9_DECODER_VP9_DECODEFRAME_H_
-#define VP9_DECODER_VP9_DECODEFRAME_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include "vp9/common/vp9_enums.h"
-
-struct VP9Decoder;
-struct vpx_read_bit_buffer;
-
-int vp9_read_sync_code(struct vpx_read_bit_buffer *const rb);
-void vp9_read_frame_size(struct vpx_read_bit_buffer *rb,
-                         int *width, int *height);
-BITSTREAM_PROFILE vp9_read_profile(struct vpx_read_bit_buffer *rb);
-
-void vp9_decode_frame(struct VP9Decoder *pbi,
-                      const uint8_t *data, const uint8_t *data_end,
-                      const uint8_t **p_data_end);
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP9_DECODER_VP9_DECODEFRAME_H_
diff --git a/vp9/decoder/vp9_decodemv.c b/vp9/decoder/vp9_decodemv.c
deleted file mode 100644 (file)
index ffc6839..0000000
+++ /dev/null
@@ -1,911 +0,0 @@
-/*
-  Copyright (c) 2010 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.
- */
-
-#include <assert.h>
-
-#include "vp9/common/vp9_common.h"
-#include "vp9/common/vp9_entropy.h"
-#include "vp9/common/vp9_entropymode.h"
-#include "vp9/common/vp9_entropymv.h"
-#include "vp9/common/vp9_mvref_common.h"
-#include "vp9/common/vp9_pred_common.h"
-#include "vp9/common/vp9_reconinter.h"
-#include "vp9/common/vp9_seg_common.h"
-
-#include "vp9/decoder/vp9_decodemv.h"
-#include "vp9/decoder/vp9_decodeframe.h"
-
-#include "vpx_dsp/vpx_dsp_common.h"
-
-static PREDICTION_MODE read_intra_mode(vpx_reader *r, const vpx_prob *p) {
-  return (PREDICTION_MODE)vpx_read_tree(r, vp9_intra_mode_tree, p);
-}
-
-static PREDICTION_MODE read_intra_mode_y(VP9_COMMON *cm, MACROBLOCKD *xd,
-                                         vpx_reader *r, int size_group) {
-  const PREDICTION_MODE y_mode =
-      read_intra_mode(r, cm->fc->y_mode_prob[size_group]);
-  FRAME_COUNTS *counts = xd->counts;
-  if (counts)
-    ++counts->y_mode[size_group][y_mode];
-  return y_mode;
-}
-
-static PREDICTION_MODE read_intra_mode_uv(VP9_COMMON *cm, MACROBLOCKD *xd,
-                                          vpx_reader *r,
-                                          PREDICTION_MODE y_mode) {
-  const PREDICTION_MODE uv_mode = read_intra_mode(r,
-                                         cm->fc->uv_mode_prob[y_mode]);
-  FRAME_COUNTS *counts = xd->counts;
-  if (counts)
-    ++counts->uv_mode[y_mode][uv_mode];
-  return uv_mode;
-}
-
-static PREDICTION_MODE read_inter_mode(VP9_COMMON *cm, MACROBLOCKD *xd,
-                                       vpx_reader *r, int ctx) {
-  const int mode = vpx_read_tree(r, vp9_inter_mode_tree,
-                                 cm->fc->inter_mode_probs[ctx]);
-  FRAME_COUNTS *counts = xd->counts;
-  if (counts)
-    ++counts->inter_mode[ctx][mode];
-
-  return NEARESTMV + mode;
-}
-
-static int read_segment_id(vpx_reader *r, const struct segmentation *seg) {
-  return vpx_read_tree(r, vp9_segment_tree, seg->tree_probs);
-}
-
-static TX_SIZE read_selected_tx_size(VP9_COMMON *cm, MACROBLOCKD *xd,
-                                     TX_SIZE max_tx_size, vpx_reader *r) {
-  FRAME_COUNTS *counts = xd->counts;
-  const int ctx = get_tx_size_context(xd);
-  const vpx_prob *tx_probs = get_tx_probs(max_tx_size, ctx, &cm->fc->tx_probs);
-  int tx_size = vpx_read(r, tx_probs[0]);
-  if (tx_size != TX_4X4 && max_tx_size >= TX_16X16) {
-    tx_size += vpx_read(r, tx_probs[1]);
-    if (tx_size != TX_8X8 && max_tx_size >= TX_32X32)
-      tx_size += vpx_read(r, tx_probs[2]);
-  }
-
-  if (counts)
-    ++get_tx_counts(max_tx_size, ctx, &counts->tx)[tx_size];
-  return (TX_SIZE)tx_size;
-}
-
-static INLINE TX_SIZE read_tx_size(VP9_COMMON *cm, MACROBLOCKD *xd,
-                                   int allow_select, vpx_reader *r) {
-  TX_MODE tx_mode = cm->tx_mode;
-  BLOCK_SIZE bsize = xd->mi[0]->sb_type;
-  const TX_SIZE max_tx_size = max_txsize_lookup[bsize];
-  if (allow_select && tx_mode == TX_MODE_SELECT && bsize >= BLOCK_8X8)
-    return read_selected_tx_size(cm, xd, max_tx_size, r);
-  else
-    return VPXMIN(max_tx_size, tx_mode_to_biggest_tx_size[tx_mode]);
-}
-
-static int dec_get_segment_id(const VP9_COMMON *cm, const uint8_t *segment_ids,
-                              int mi_offset, int x_mis, int y_mis) {
-  int x, y, segment_id = INT_MAX;
-
-  for (y = 0; y < y_mis; y++)
-    for (x = 0; x < x_mis; x++)
-      segment_id =
-          VPXMIN(segment_id, segment_ids[mi_offset + y * cm->mi_cols + x]);
-
-  assert(segment_id >= 0 && segment_id < MAX_SEGMENTS);
-  return segment_id;
-}
-
-static void set_segment_id(VP9_COMMON *cm, int mi_offset,
-                           int x_mis, int y_mis, int segment_id) {
-  int x, y;
-
-  assert(segment_id >= 0 && segment_id < MAX_SEGMENTS);
-
-  for (y = 0; y < y_mis; y++)
-    for (x = 0; x < x_mis; x++)
-      cm->current_frame_seg_map[mi_offset + y * cm->mi_cols + x] = segment_id;
-}
-
-static void copy_segment_id(const VP9_COMMON *cm,
-                           const uint8_t *last_segment_ids,
-                           uint8_t *current_segment_ids,
-                           int mi_offset, int x_mis, int y_mis) {
-  int x, y;
-
-  for (y = 0; y < y_mis; y++)
-    for (x = 0; x < x_mis; x++)
-      current_segment_ids[mi_offset + y * cm->mi_cols + x] =  last_segment_ids ?
-          last_segment_ids[mi_offset + y * cm->mi_cols + x] : 0;
-}
-
-static int read_intra_segment_id(VP9_COMMON *const cm, int mi_offset,
-                                 int x_mis, int y_mis,
-                                 vpx_reader *r) {
-  struct segmentation *const seg = &cm->seg;
-  int segment_id;
-
-  if (!seg->enabled)
-    return 0;  // Default for disabled segmentation
-
-  if (!seg->update_map) {
-    copy_segment_id(cm, cm->last_frame_seg_map, cm->current_frame_seg_map,
-                    mi_offset, x_mis, y_mis);
-    return 0;
-  }
-
-  segment_id = read_segment_id(r, seg);
-  set_segment_id(cm, mi_offset, x_mis, y_mis, segment_id);
-  return segment_id;
-}
-
-static int read_inter_segment_id(VP9_COMMON *const cm, MACROBLOCKD *const xd,
-                                 int mi_row, int mi_col, vpx_reader *r,
-                                 int x_mis, int y_mis) {
-  struct segmentation *const seg = &cm->seg;
-  MODE_INFO *const mi = xd->mi[0];
-  int predicted_segment_id, segment_id;
-  const int mi_offset = mi_row * cm->mi_cols + mi_col;
-
-  if (!seg->enabled)
-    return 0;  // Default for disabled segmentation
-
-  predicted_segment_id = cm->last_frame_seg_map ?
-      dec_get_segment_id(cm, cm->last_frame_seg_map, mi_offset, x_mis, y_mis) :
-      0;
-
-  if (!seg->update_map) {
-    copy_segment_id(cm, cm->last_frame_seg_map, cm->current_frame_seg_map,
-                    mi_offset, x_mis, y_mis);
-    return predicted_segment_id;
-  }
-
-  if (seg->temporal_update) {
-    const vpx_prob pred_prob = vp9_get_pred_prob_seg_id(seg, xd);
-    mi->seg_id_predicted = vpx_read(r, pred_prob);
-    segment_id = mi->seg_id_predicted ? predicted_segment_id
-                                      : read_segment_id(r, seg);
-  } else {
-    segment_id = read_segment_id(r, seg);
-  }
-  set_segment_id(cm, mi_offset, x_mis, y_mis, segment_id);
-  return segment_id;
-}
-
-static int read_skip(VP9_COMMON *cm, const MACROBLOCKD *xd,
-                     int segment_id, vpx_reader *r) {
-  if (segfeature_active(&cm->seg, segment_id, SEG_LVL_SKIP)) {
-    return 1;
-  } else {
-    const int ctx = vp9_get_skip_context(xd);
-    const int skip = vpx_read(r, cm->fc->skip_probs[ctx]);
-    FRAME_COUNTS *counts = xd->counts;
-    if (counts)
-      ++counts->skip[ctx][skip];
-    return skip;
-  }
-}
-
-static void read_intra_frame_mode_info(VP9_COMMON *const cm,
-                                       MACROBLOCKD *const xd,
-                                       int mi_row, int mi_col, vpx_reader *r,
-                                       int x_mis, int y_mis) {
-  MODE_INFO *const mi = xd->mi[0];
-  const MODE_INFO *above_mi = xd->above_mi;
-  const MODE_INFO *left_mi  = xd->left_mi;
-  const BLOCK_SIZE bsize = mi->sb_type;
-  int i;
-  const int mi_offset = mi_row * cm->mi_cols + mi_col;
-
-  mi->segment_id = read_intra_segment_id(cm, mi_offset, x_mis, y_mis, r);
-  mi->skip = read_skip(cm, xd, mi->segment_id, r);
-  mi->tx_size = read_tx_size(cm, xd, 1, r);
-  mi->ref_frame[0] = INTRA_FRAME;
-  mi->ref_frame[1] = NONE;
-
-  switch (bsize) {
-    case BLOCK_4X4:
-      for (i = 0; i < 4; ++i)
-        mi->bmi[i].as_mode =
-            read_intra_mode(r, get_y_mode_probs(mi, above_mi, left_mi, i));
-      mi->mode = mi->bmi[3].as_mode;
-      break;
-    case BLOCK_4X8:
-      mi->bmi[0].as_mode = mi->bmi[2].as_mode =
-          read_intra_mode(r, get_y_mode_probs(mi, above_mi, left_mi, 0));
-      mi->bmi[1].as_mode = mi->bmi[3].as_mode = mi->mode =
-          read_intra_mode(r, get_y_mode_probs(mi, above_mi, left_mi, 1));
-      break;
-    case BLOCK_8X4:
-      mi->bmi[0].as_mode = mi->bmi[1].as_mode =
-          read_intra_mode(r, get_y_mode_probs(mi, above_mi, left_mi, 0));
-      mi->bmi[2].as_mode = mi->bmi[3].as_mode = mi->mode =
-          read_intra_mode(r, get_y_mode_probs(mi, above_mi, left_mi, 2));
-      break;
-    default:
-      mi->mode = read_intra_mode(r,
-                                 get_y_mode_probs(mi, above_mi, left_mi, 0));
-  }
-
-  mi->uv_mode = read_intra_mode(r, vp9_kf_uv_mode_prob[mi->mode]);
-}
-
-static int read_mv_component(vpx_reader *r,
-                             const nmv_component *mvcomp, int usehp) {
-  int mag, d, fr, hp;
-  const int sign = vpx_read(r, mvcomp->sign);
-  const int mv_class = vpx_read_tree(r, vp9_mv_class_tree, mvcomp->classes);
-  const int class0 = mv_class == MV_CLASS_0;
-
-  // Integer part
-  if (class0) {
-    d = vpx_read_tree(r, vp9_mv_class0_tree, mvcomp->class0);
-    mag = 0;
-  } else {
-    int i;
-    const int n = mv_class + CLASS0_BITS - 1;  // number of bits
-
-    d = 0;
-    for (i = 0; i < n; ++i)
-      d |= vpx_read(r, mvcomp->bits[i]) << i;
-    mag = CLASS0_SIZE << (mv_class + 2);
-  }
-
-  // Fractional part
-  fr = vpx_read_tree(r, vp9_mv_fp_tree, class0 ? mvcomp->class0_fp[d]
-                                               : mvcomp->fp);
-
-  // High precision part (if hp is not used, the default value of the hp is 1)
-  hp = usehp ? vpx_read(r, class0 ? mvcomp->class0_hp : mvcomp->hp)
-             : 1;
-
-  // Result
-  mag += ((d << 3) | (fr << 1) | hp) + 1;
-  return sign ? -mag : mag;
-}
-
-static INLINE void read_mv(vpx_reader *r, MV *mv, const MV *ref,
-                           const nmv_context *ctx,
-                           nmv_context_counts *counts, int allow_hp) {
-  const MV_JOINT_TYPE joint_type =
-      (MV_JOINT_TYPE)vpx_read_tree(r, vp9_mv_joint_tree, ctx->joints);
-  const int use_hp = allow_hp && use_mv_hp(ref);
-  MV diff = {0, 0};
-
-  if (mv_joint_vertical(joint_type))
-    diff.row = read_mv_component(r, &ctx->comps[0], use_hp);
-
-  if (mv_joint_horizontal(joint_type))
-    diff.col = read_mv_component(r, &ctx->comps[1], use_hp);
-
-  vp9_inc_mv(&diff, counts);
-
-  mv->row = ref->row + diff.row;
-  mv->col = ref->col + diff.col;
-}
-
-static REFERENCE_MODE read_block_reference_mode(VP9_COMMON *cm,
-                                                const MACROBLOCKD *xd,
-                                                vpx_reader *r) {
-  if (cm->reference_mode == REFERENCE_MODE_SELECT) {
-    const int ctx = vp9_get_reference_mode_context(cm, xd);
-    const REFERENCE_MODE mode =
-        (REFERENCE_MODE)vpx_read(r, cm->fc->comp_inter_prob[ctx]);
-    FRAME_COUNTS *counts = xd->counts;
-    if (counts)
-      ++counts->comp_inter[ctx][mode];
-    return mode;  // SINGLE_REFERENCE or COMPOUND_REFERENCE
-  } else {
-    return cm->reference_mode;
-  }
-}
-
-// Read the referncence frame
-static void read_ref_frames(VP9_COMMON *const cm, MACROBLOCKD *const xd,
-                            vpx_reader *r,
-                            int segment_id, MV_REFERENCE_FRAME ref_frame[2]) {
-  FRAME_CONTEXT *const fc = cm->fc;
-  FRAME_COUNTS *counts = xd->counts;
-
-  if (segfeature_active(&cm->seg, segment_id, SEG_LVL_REF_FRAME)) {
-    ref_frame[0] = (MV_REFERENCE_FRAME)get_segdata(&cm->seg, segment_id,
-                                                   SEG_LVL_REF_FRAME);
-    ref_frame[1] = NONE;
-  } else {
-    const REFERENCE_MODE mode = read_block_reference_mode(cm, xd, r);
-    // FIXME(rbultje) I'm pretty sure this breaks segmentation ref frame coding
-    if (mode == COMPOUND_REFERENCE) {
-      const int idx = cm->ref_frame_sign_bias[cm->comp_fixed_ref];
-      const int ctx = vp9_get_pred_context_comp_ref_p(cm, xd);
-      const int bit = vpx_read(r, fc->comp_ref_prob[ctx]);
-      if (counts)
-        ++counts->comp_ref[ctx][bit];
-      ref_frame[idx] = cm->comp_fixed_ref;
-      ref_frame[!idx] = cm->comp_var_ref[bit];
-    } else if (mode == SINGLE_REFERENCE) {
-      const int ctx0 = vp9_get_pred_context_single_ref_p1(xd);
-      const int bit0 = vpx_read(r, fc->single_ref_prob[ctx0][0]);
-      if (counts)
-        ++counts->single_ref[ctx0][0][bit0];
-      if (bit0) {
-        const int ctx1 = vp9_get_pred_context_single_ref_p2(xd);
-        const int bit1 = vpx_read(r, fc->single_ref_prob[ctx1][1]);
-        if (counts)
-          ++counts->single_ref[ctx1][1][bit1];
-        ref_frame[0] = bit1 ? ALTREF_FRAME : GOLDEN_FRAME;
-      } else {
-        ref_frame[0] = LAST_FRAME;
-      }
-
-      ref_frame[1] = NONE;
-    } else {
-      assert(0 && "Invalid prediction mode.");
-    }
-  }
-}
-
-// TODO(slavarnway): Move this decoder version of
-// vp9_get_pred_context_switchable_interp() to vp9_pred_common.h and update the
-// encoder.
-//
-// Returns a context number for the given MB prediction signal
-static int dec_get_pred_context_switchable_interp(const MACROBLOCKD *xd) {
-  // Note:
-  // The mode info data structure has a one element border above and to the
-  // left of the entries corresponding to real macroblocks.
-  // The prediction flags in these dummy entries are initialized to 0.
-  const MODE_INFO *const left_mi = xd->left_mi;
-  const int left_type = left_mi ? left_mi->interp_filter : SWITCHABLE_FILTERS;
-  const MODE_INFO *const above_mi = xd->above_mi;
-  const int above_type = above_mi ? above_mi->interp_filter
-                             : SWITCHABLE_FILTERS;
-
-  if (left_type == above_type)
-    return left_type;
-  else if (left_type == SWITCHABLE_FILTERS)
-    return above_type;
-  else if (above_type == SWITCHABLE_FILTERS)
-    return left_type;
-  else
-    return SWITCHABLE_FILTERS;
-}
-
-static INLINE INTERP_FILTER read_switchable_interp_filter(
-    VP9_COMMON *const cm, MACROBLOCKD *const xd,
-    vpx_reader *r) {
-  const int ctx = dec_get_pred_context_switchable_interp(xd);
-  const INTERP_FILTER type =
-      (INTERP_FILTER)vpx_read_tree(r, vp9_switchable_interp_tree,
-                                   cm->fc->switchable_interp_prob[ctx]);
-  FRAME_COUNTS *counts = xd->counts;
-  if (counts)
-    ++counts->switchable_interp[ctx][type];
-  return type;
-}
-
-static void read_intra_block_mode_info(VP9_COMMON *const cm,
-                                       MACROBLOCKD *const xd, MODE_INFO *mi,
-                                       vpx_reader *r) {
-  const BLOCK_SIZE bsize = mi->sb_type;
-  int i;
-
-  switch (bsize) {
-    case BLOCK_4X4:
-      for (i = 0; i < 4; ++i)
-        mi->bmi[i].as_mode = read_intra_mode_y(cm, xd, r, 0);
-      mi->mode = mi->bmi[3].as_mode;
-      break;
-    case BLOCK_4X8:
-      mi->bmi[0].as_mode = mi->bmi[2].as_mode = read_intra_mode_y(cm, xd,
-                                                                  r, 0);
-      mi->bmi[1].as_mode = mi->bmi[3].as_mode = mi->mode =
-          read_intra_mode_y(cm, xd, r, 0);
-      break;
-    case BLOCK_8X4:
-      mi->bmi[0].as_mode = mi->bmi[1].as_mode = read_intra_mode_y(cm, xd,
-                                                                  r, 0);
-      mi->bmi[2].as_mode = mi->bmi[3].as_mode = mi->mode =
-          read_intra_mode_y(cm, xd, r, 0);
-      break;
-    default:
-      mi->mode = read_intra_mode_y(cm, xd, r, size_group_lookup[bsize]);
-  }
-
-  mi->uv_mode = read_intra_mode_uv(cm, xd, r, mi->mode);
-
-  // Initialize interp_filter here so we do not have to check for inter block
-  // modes in dec_get_pred_context_switchable_interp()
-  mi->interp_filter = SWITCHABLE_FILTERS;
-
-  mi->ref_frame[0] = INTRA_FRAME;
-  mi->ref_frame[1] = NONE;
-}
-
-static INLINE int is_mv_valid(const MV *mv) {
-  return mv->row > MV_LOW && mv->row < MV_UPP &&
-         mv->col > MV_LOW && mv->col < MV_UPP;
-}
-
-static INLINE void copy_mv_pair(int_mv *dst, const int_mv *src) {
-  memcpy(dst, src, sizeof(*dst) * 2);
-}
-
-static INLINE void zero_mv_pair(int_mv *dst) {
-  memset(dst, 0, sizeof(*dst) * 2);
-}
-
-static INLINE int assign_mv(VP9_COMMON *cm, MACROBLOCKD *xd,
-                            PREDICTION_MODE mode,
-                            int_mv mv[2], int_mv ref_mv[2],
-                            int_mv near_nearest_mv[2],
-                            int is_compound, int allow_hp, vpx_reader *r) {
-  int i;
-  int ret = 1;
-
-  switch (mode) {
-    case NEWMV: {
-      FRAME_COUNTS *counts = xd->counts;
-      nmv_context_counts *const mv_counts = counts ? &counts->mv : NULL;
-      for (i = 0; i < 1 + is_compound; ++i) {
-        read_mv(r, &mv[i].as_mv, &ref_mv[i].as_mv, &cm->fc->nmvc, mv_counts,
-                allow_hp);
-        ret = ret && is_mv_valid(&mv[i].as_mv);
-      }
-      break;
-    }
-    case NEARMV:
-    case NEARESTMV: {
-      copy_mv_pair(mv, near_nearest_mv);
-      break;
-    }
-    case ZEROMV: {
-      zero_mv_pair(mv);
-      break;
-    }
-    default: {
-      return 0;
-    }
-  }
-  return ret;
-}
-
-static int read_is_inter_block(VP9_COMMON *const cm, MACROBLOCKD *const xd,
-                               int segment_id, vpx_reader *r) {
-  if (segfeature_active(&cm->seg, segment_id, SEG_LVL_REF_FRAME)) {
-    return get_segdata(&cm->seg, segment_id, SEG_LVL_REF_FRAME) != INTRA_FRAME;
-  } else {
-    const int ctx = get_intra_inter_context(xd);
-    const int is_inter = vpx_read(r, cm->fc->intra_inter_prob[ctx]);
-    FRAME_COUNTS *counts = xd->counts;
-    if (counts)
-      ++counts->intra_inter[ctx][is_inter];
-    return is_inter;
-  }
-}
-
-static void dec_find_best_ref_mvs(int allow_hp, int_mv *mvlist, int_mv *best_mv,
-                                  int refmv_count) {
-  int i;
-
-  // Make sure all the candidates are properly clamped etc
-  for (i = 0; i < refmv_count; ++i) {
-    lower_mv_precision(&mvlist[i].as_mv, allow_hp);
-    *best_mv = mvlist[i];
-  }
-}
-
-static void fpm_sync(void *const data, int mi_row) {
-  VP9Decoder *const pbi = (VP9Decoder *)data;
-  vp9_frameworker_wait(pbi->frame_worker_owner, pbi->common.prev_frame,
-                       mi_row << MI_BLOCK_SIZE_LOG2);
-}
-
-// This macro is used to add a motion vector mv_ref list if it isn't
-// already in the list.  If it's the second motion vector or early_break
-// it will also skip all additional processing and jump to Done!
-#define ADD_MV_REF_LIST_EB(mv, refmv_count, mv_ref_list, Done) \
-  do { \
-    if (refmv_count) { \
-      if ((mv).as_int != (mv_ref_list)[0].as_int) { \
-        (mv_ref_list)[(refmv_count)] = (mv); \
-        refmv_count++; \
-        goto Done; \
-      } \
-    } else { \
-      (mv_ref_list)[(refmv_count)++] = (mv); \
-      if (early_break) \
-        goto Done; \
-    } \
-  } while (0)
-
-// If either reference frame is different, not INTRA, and they
-// are different from each other scale and add the mv to our list.
-#define IF_DIFF_REF_FRAME_ADD_MV_EB(mbmi, ref_frame, ref_sign_bias, \
-                                    refmv_count, mv_ref_list, Done) \
-  do { \
-    if (is_inter_block(mbmi)) { \
-      if ((mbmi)->ref_frame[0] != ref_frame) \
-        ADD_MV_REF_LIST_EB(scale_mv((mbmi), 0, ref_frame, ref_sign_bias), \
-                           refmv_count, mv_ref_list, Done); \
-      if (has_second_ref(mbmi) && \
-          (mbmi)->ref_frame[1] != ref_frame && \
-          (mbmi)->mv[1].as_int != (mbmi)->mv[0].as_int) \
-        ADD_MV_REF_LIST_EB(scale_mv((mbmi), 1, ref_frame, ref_sign_bias), \
-                           refmv_count, mv_ref_list, Done); \
-    } \
-  } while (0)
-
-// This function searches the neighborhood of a given MB/SB
-// to try and find candidate reference vectors.
-static int dec_find_mv_refs(const VP9_COMMON *cm, const MACROBLOCKD *xd,
-                            PREDICTION_MODE mode, MV_REFERENCE_FRAME ref_frame,
-                            const POSITION *const mv_ref_search,
-                            int_mv *mv_ref_list,
-                            int mi_row, int mi_col, int block, int is_sub8x8,
-                            find_mv_refs_sync sync, void *const data) {
-  const int *ref_sign_bias = cm->ref_frame_sign_bias;
-  int i, refmv_count = 0;
-  int different_ref_found = 0;
-  const MV_REF *const prev_frame_mvs = cm->use_prev_frame_mvs ?
-      cm->prev_frame->mvs + mi_row * cm->mi_cols + mi_col : NULL;
-  const TileInfo *const tile = &xd->tile;
-  // If mode is nearestmv or newmv (uses nearestmv as a reference) then stop
-  // searching after the first mv is found.
-  const int early_break = (mode != NEARMV);
-
-  // Blank the reference vector list
-  memset(mv_ref_list, 0, sizeof(*mv_ref_list) * MAX_MV_REF_CANDIDATES);
-
-  i = 0;
-  if (is_sub8x8) {
-    // If the size < 8x8 we get the mv from the bmi substructure for the
-    // nearest two blocks.
-    for (i = 0; i < 2; ++i) {
-      const POSITION *const mv_ref = &mv_ref_search[i];
-      if (is_inside(tile, mi_col, mi_row, cm->mi_rows, mv_ref)) {
-        const MODE_INFO *const candidate_mi =
-            xd->mi[mv_ref->col + mv_ref->row * xd->mi_stride];
-        different_ref_found = 1;
-
-        if (candidate_mi->ref_frame[0] == ref_frame)
-          ADD_MV_REF_LIST_EB(
-              get_sub_block_mv(candidate_mi, 0, mv_ref->col, block),
-                  refmv_count, mv_ref_list, Done);
-        else if (candidate_mi->ref_frame[1] == ref_frame)
-          ADD_MV_REF_LIST_EB(
-              get_sub_block_mv(candidate_mi, 1, mv_ref->col, block),
-                  refmv_count, mv_ref_list, Done);
-      }
-    }
-  }
-
-  // Check the rest of the neighbors in much the same way
-  // as before except we don't need to keep track of sub blocks or
-  // mode counts.
-  for (; i < MVREF_NEIGHBOURS; ++i) {
-    const POSITION *const mv_ref = &mv_ref_search[i];
-    if (is_inside(tile, mi_col, mi_row, cm->mi_rows, mv_ref)) {
-      const MODE_INFO *const candidate =
-          xd->mi[mv_ref->col + mv_ref->row * xd->mi_stride];
-      different_ref_found = 1;
-
-      if (candidate->ref_frame[0] == ref_frame)
-        ADD_MV_REF_LIST_EB(candidate->mv[0], refmv_count, mv_ref_list, Done);
-      else if (candidate->ref_frame[1] == ref_frame)
-        ADD_MV_REF_LIST_EB(candidate->mv[1], refmv_count, mv_ref_list, Done);
-    }
-  }
-
-  // TODO(hkuang): Remove this sync after fixing pthread_cond_broadcast
-  // on windows platform. The sync here is unnecessary if use_prev_frame_mvs
-  // is 0. But after removing it, there will be hang in the unit test on windows
-  // due to several threads waiting for a thread's signal.
-#if defined(_WIN32) && !HAVE_PTHREAD_H
-    if (cm->frame_parallel_decode && sync != NULL) {
-      sync(data, mi_row);
-    }
-#endif
-
-  // Check the last frame's mode and mv info.
-  if (prev_frame_mvs) {
-    // Synchronize here for frame parallel decode if sync function is provided.
-    if (cm->frame_parallel_decode && sync != NULL) {
-      sync(data, mi_row);
-    }
-
-    if (prev_frame_mvs->ref_frame[0] == ref_frame) {
-      ADD_MV_REF_LIST_EB(prev_frame_mvs->mv[0], refmv_count, mv_ref_list, Done);
-    } else if (prev_frame_mvs->ref_frame[1] == ref_frame) {
-      ADD_MV_REF_LIST_EB(prev_frame_mvs->mv[1], refmv_count, mv_ref_list, Done);
-    }
-  }
-
-  // Since we couldn't find 2 mvs from the same reference frame
-  // go back through the neighbors and find motion vectors from
-  // different reference frames.
-  if (different_ref_found) {
-    for (i = 0; i < MVREF_NEIGHBOURS; ++i) {
-      const POSITION *mv_ref = &mv_ref_search[i];
-      if (is_inside(tile, mi_col, mi_row, cm->mi_rows, mv_ref)) {
-        const MODE_INFO *const candidate =
-            xd->mi[mv_ref->col + mv_ref->row * xd->mi_stride];
-
-        // If the candidate is INTRA we don't want to consider its mv.
-        IF_DIFF_REF_FRAME_ADD_MV_EB(candidate, ref_frame, ref_sign_bias,
-                                    refmv_count, mv_ref_list, Done);
-      }
-    }
-  }
-
-  // Since we still don't have a candidate we'll try the last frame.
-  if (prev_frame_mvs) {
-    if (prev_frame_mvs->ref_frame[0] != ref_frame &&
-        prev_frame_mvs->ref_frame[0] > INTRA_FRAME) {
-      int_mv mv = prev_frame_mvs->mv[0];
-      if (ref_sign_bias[prev_frame_mvs->ref_frame[0]] !=
-          ref_sign_bias[ref_frame]) {
-        mv.as_mv.row *= -1;
-        mv.as_mv.col *= -1;
-      }
-      ADD_MV_REF_LIST_EB(mv, refmv_count, mv_ref_list, Done);
-    }
-
-    if (prev_frame_mvs->ref_frame[1] > INTRA_FRAME &&
-        prev_frame_mvs->ref_frame[1] != ref_frame &&
-        prev_frame_mvs->mv[1].as_int != prev_frame_mvs->mv[0].as_int) {
-      int_mv mv = prev_frame_mvs->mv[1];
-      if (ref_sign_bias[prev_frame_mvs->ref_frame[1]] !=
-          ref_sign_bias[ref_frame]) {
-        mv.as_mv.row *= -1;
-        mv.as_mv.col *= -1;
-      }
-      ADD_MV_REF_LIST_EB(mv, refmv_count, mv_ref_list, Done);
-    }
-  }
-
-  if (mode == NEARMV)
-    refmv_count = MAX_MV_REF_CANDIDATES;
-  else
-    // we only care about the nearestmv for the remaining modes
-    refmv_count = 1;
-
- Done:
-  // Clamp vectors
-  for (i = 0; i < refmv_count; ++i)
-    clamp_mv_ref(&mv_ref_list[i].as_mv, xd);
-
-  return refmv_count;
-}
-
-static void append_sub8x8_mvs_for_idx(VP9_COMMON *cm, MACROBLOCKD *xd,
-                                      const POSITION *const mv_ref_search,
-                                      PREDICTION_MODE b_mode, int block,
-                                      int ref, int mi_row, int mi_col,
-                                      int_mv *best_sub8x8) {
-  int_mv mv_list[MAX_MV_REF_CANDIDATES];
-  MODE_INFO *const mi = xd->mi[0];
-  b_mode_info *bmi = mi->bmi;
-  int n;
-  int refmv_count;
-
-  assert(MAX_MV_REF_CANDIDATES == 2);
-
-  refmv_count = dec_find_mv_refs(cm, xd, b_mode, mi->ref_frame[ref],
-                                 mv_ref_search, mv_list, mi_row, mi_col, block,
-                                 1, NULL, NULL);
-
-  switch (block) {
-    case 0:
-      best_sub8x8->as_int = mv_list[refmv_count - 1].as_int;
-      break;
-    case 1:
-    case 2:
-      if (b_mode == NEARESTMV) {
-        best_sub8x8->as_int = bmi[0].as_mv[ref].as_int;
-      } else {
-        best_sub8x8->as_int = 0;
-        for (n = 0; n < refmv_count; ++n)
-          if (bmi[0].as_mv[ref].as_int != mv_list[n].as_int) {
-            best_sub8x8->as_int = mv_list[n].as_int;
-            break;
-          }
-      }
-      break;
-    case 3:
-      if (b_mode == NEARESTMV) {
-        best_sub8x8->as_int = bmi[2].as_mv[ref].as_int;
-      } else {
-        int_mv candidates[2 + MAX_MV_REF_CANDIDATES];
-        candidates[0] = bmi[1].as_mv[ref];
-        candidates[1] = bmi[0].as_mv[ref];
-        candidates[2] = mv_list[0];
-        candidates[3] = mv_list[1];
-        best_sub8x8->as_int = 0;
-        for (n = 0; n < 2 + MAX_MV_REF_CANDIDATES; ++n)
-          if (bmi[2].as_mv[ref].as_int != candidates[n].as_int) {
-            best_sub8x8->as_int = candidates[n].as_int;
-            break;
-          }
-      }
-      break;
-    default:
-      assert(0 && "Invalid block index.");
-  }
-}
-
-static uint8_t get_mode_context(const VP9_COMMON *cm, const MACROBLOCKD *xd,
-                                const POSITION *const mv_ref_search,
-                                int mi_row, int mi_col) {
-  int i;
-  int context_counter = 0;
-  const TileInfo *const tile = &xd->tile;
-
-  // Get mode count from nearest 2 blocks
-  for (i = 0; i < 2; ++i) {
-    const POSITION *const mv_ref = &mv_ref_search[i];
-    if (is_inside(tile, mi_col, mi_row, cm->mi_rows, mv_ref)) {
-      const MODE_INFO *const candidate =
-          xd->mi[mv_ref->col + mv_ref->row * xd->mi_stride];
-      // Keep counts for entropy encoding.
-      context_counter += mode_2_counter[candidate->mode];
-    }
-  }
-
-  return counter_to_context[context_counter];
-}
-
-static void read_inter_block_mode_info(VP9Decoder *const pbi,
-                                       MACROBLOCKD *const xd,
-                                       MODE_INFO *const mi,
-                                       int mi_row, int mi_col, vpx_reader *r) {
-  VP9_COMMON *const cm = &pbi->common;
-  const BLOCK_SIZE bsize = mi->sb_type;
-  const int allow_hp = cm->allow_high_precision_mv;
-  int_mv best_ref_mvs[2];
-  int ref, is_compound;
-  uint8_t inter_mode_ctx;
-  const POSITION *const mv_ref_search = mv_ref_blocks[bsize];
-
-  read_ref_frames(cm, xd, r, mi->segment_id, mi->ref_frame);
-  is_compound = has_second_ref(mi);
-  inter_mode_ctx = get_mode_context(cm, xd, mv_ref_search, mi_row, mi_col);
-
-  if (segfeature_active(&cm->seg, mi->segment_id, SEG_LVL_SKIP)) {
-    mi->mode = ZEROMV;
-    if (bsize < BLOCK_8X8) {
-        vpx_internal_error(xd->error_info, VPX_CODEC_UNSUP_BITSTREAM,
-                           "Invalid usage of segement feature on small blocks");
-        return;
-    }
-  } else {
-    if (bsize >= BLOCK_8X8)
-      mi->mode = read_inter_mode(cm, xd, r, inter_mode_ctx);
-    else
-      // Sub 8x8 blocks use the nearestmv as a ref_mv if the b_mode is NEWMV.
-      // Setting mode to NEARESTMV forces the search to stop after the nearestmv
-      // has been found. After b_modes have been read, mode will be overwritten
-      // by the last b_mode.
-      mi->mode = NEARESTMV;
-
-    if (mi->mode != ZEROMV) {
-      for (ref = 0; ref < 1 + is_compound; ++ref) {
-        int_mv tmp_mvs[MAX_MV_REF_CANDIDATES];
-        const MV_REFERENCE_FRAME frame = mi->ref_frame[ref];
-        int refmv_count;
-
-        refmv_count = dec_find_mv_refs(cm, xd, mi->mode, frame, mv_ref_search,
-                                       tmp_mvs, mi_row, mi_col, -1, 0,
-                                       fpm_sync, (void *)pbi);
-
-        dec_find_best_ref_mvs(allow_hp, tmp_mvs, &best_ref_mvs[ref],
-                              refmv_count);
-      }
-    }
-  }
-
-  mi->interp_filter = (cm->interp_filter == SWITCHABLE)
-                      ? read_switchable_interp_filter(cm, xd, r)
-                      : cm->interp_filter;
-
-  if (bsize < BLOCK_8X8) {
-    const int num_4x4_w = 1 << xd->bmode_blocks_wl;
-    const int num_4x4_h = 1 << xd->bmode_blocks_hl;
-    int idx, idy;
-    PREDICTION_MODE b_mode;
-    int_mv best_sub8x8[2];
-    for (idy = 0; idy < 2; idy += num_4x4_h) {
-      for (idx = 0; idx < 2; idx += num_4x4_w) {
-        const int j = idy * 2 + idx;
-        b_mode = read_inter_mode(cm, xd, r, inter_mode_ctx);
-
-        if (b_mode == NEARESTMV || b_mode == NEARMV) {
-          for (ref = 0; ref < 1 + is_compound; ++ref)
-            append_sub8x8_mvs_for_idx(cm, xd, mv_ref_search, b_mode, j, ref,
-                                      mi_row, mi_col, &best_sub8x8[ref]);
-        }
-
-        if (!assign_mv(cm, xd, b_mode, mi->bmi[j].as_mv, best_ref_mvs,
-                       best_sub8x8, is_compound, allow_hp, r)) {
-          xd->corrupted |= 1;
-          break;
-        }
-
-        if (num_4x4_h == 2)
-          mi->bmi[j + 2] = mi->bmi[j];
-        if (num_4x4_w == 2)
-          mi->bmi[j + 1] = mi->bmi[j];
-      }
-    }
-
-    mi->mode = b_mode;
-
-    copy_mv_pair(mi->mv, mi->bmi[3].as_mv);
-  } else {
-    xd->corrupted |= !assign_mv(cm, xd, mi->mode, mi->mv, best_ref_mvs,
-                                best_ref_mvs, is_compound, allow_hp, r);
-  }
-}
-
-static void read_inter_frame_mode_info(VP9Decoder *const pbi,
-                                       MACROBLOCKD *const xd,
-                                       int mi_row, int mi_col, vpx_reader *r,
-                                       int x_mis, int y_mis) {
-  VP9_COMMON *const cm = &pbi->common;
-  MODE_INFO *const mi = xd->mi[0];
-  int inter_block;
-
-  mi->segment_id = read_inter_segment_id(cm, xd, mi_row, mi_col, r, x_mis,
-                                         y_mis);
-  mi->skip = read_skip(cm, xd, mi->segment_id, r);
-  inter_block = read_is_inter_block(cm, xd, mi->segment_id, r);
-  mi->tx_size = read_tx_size(cm, xd, !mi->skip || !inter_block, r);
-
-  if (inter_block)
-    read_inter_block_mode_info(pbi, xd, mi, mi_row, mi_col, r);
-  else
-    read_intra_block_mode_info(cm, xd, mi, r);
-}
-
-static INLINE void copy_ref_frame_pair(MV_REFERENCE_FRAME *dst,
-                                       const MV_REFERENCE_FRAME *src) {
-  memcpy(dst, src, sizeof(*dst) * 2);
-}
-
-void vp9_read_mode_info(VP9Decoder *const pbi, MACROBLOCKD *xd,
-                        int mi_row, int mi_col, vpx_reader *r,
-                        int x_mis, int y_mis) {
-  VP9_COMMON *const cm = &pbi->common;
-  MODE_INFO *const mi = xd->mi[0];
-  MV_REF* frame_mvs = cm->cur_frame->mvs + mi_row * cm->mi_cols + mi_col;
-  int w, h;
-
-  if (frame_is_intra_only(cm)) {
-    read_intra_frame_mode_info(cm, xd, mi_row, mi_col, r, x_mis, y_mis);
-  } else {
-    read_inter_frame_mode_info(pbi, xd, mi_row, mi_col, r, x_mis, y_mis);
-
-    for (h = 0; h < y_mis; ++h) {
-      for (w = 0; w < x_mis; ++w) {
-        MV_REF *const mv = frame_mvs + w;
-        copy_ref_frame_pair(mv->ref_frame, mi->ref_frame);
-        copy_mv_pair(mv->mv, mi->mv);
-      }
-      frame_mvs += cm->mi_cols;
-    }
-  }
-#if CONFIG_BETTER_HW_COMPATIBILITY && CONFIG_VP9_HIGHBITDEPTH
-    if ((xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) &&
-        (xd->above_mi == NULL || xd->left_mi == NULL) &&
-        !is_inter_block(mi) && need_top_left[mi->uv_mode])
-      assert(0);
-#endif  // CONFIG_BETTER_HW_COMPATIBILITY && CONFIG_VP9_HIGHBITDEPTH
-}
diff --git a/vp9/decoder/vp9_decodemv.h b/vp9/decoder/vp9_decodemv.h
deleted file mode 100644 (file)
index 45569ec..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#ifndef VP9_DECODER_VP9_DECODEMV_H_
-#define VP9_DECODER_VP9_DECODEMV_H_
-
-#include "vpx_dsp/bitreader.h"
-
-#include "vp9/decoder/vp9_decoder.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-void vp9_read_mode_info(VP9Decoder *const pbi, MACROBLOCKD *xd,
-                        int mi_row, int mi_col, vpx_reader *r,
-                        int x_mis, int y_mis);
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP9_DECODER_VP9_DECODEMV_H_
diff --git a/vp9/decoder/vp9_decoder.c b/vp9/decoder/vp9_decoder.c
deleted file mode 100644 (file)
index 891613f..0000000
+++ /dev/null
@@ -1,515 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#include <assert.h>
-#include <limits.h>
-#include <stdio.h>
-
-#include "./vp9_rtcd.h"
-#include "./vpx_dsp_rtcd.h"
-#include "./vpx_scale_rtcd.h"
-
-#include "vpx_mem/vpx_mem.h"
-#include "vpx_ports/system_state.h"
-#include "vpx_ports/vpx_once.h"
-#include "vpx_ports/vpx_timer.h"
-#include "vpx_scale/vpx_scale.h"
-#include "vpx_util/vpx_thread.h"
-
-#include "vp9/common/vp9_alloccommon.h"
-#include "vp9/common/vp9_loopfilter.h"
-#include "vp9/common/vp9_onyxc_int.h"
-#if CONFIG_VP9_POSTPROC
-#include "vp9/common/vp9_postproc.h"
-#endif
-#include "vp9/common/vp9_quant_common.h"
-#include "vp9/common/vp9_reconintra.h"
-
-#include "vp9/decoder/vp9_decodeframe.h"
-#include "vp9/decoder/vp9_decoder.h"
-#include "vp9/decoder/vp9_detokenize.h"
-
-static void initialize_dec(void) {
-  static volatile int init_done = 0;
-
-  if (!init_done) {
-    vp9_rtcd();
-    vpx_dsp_rtcd();
-    vpx_scale_rtcd();
-    vp9_init_intra_predictors();
-    init_done = 1;
-  }
-}
-
-static void vp9_dec_setup_mi(VP9_COMMON *cm) {
-  cm->mi = cm->mip + cm->mi_stride + 1;
-  cm->mi_grid_visible = cm->mi_grid_base + cm->mi_stride + 1;
-  memset(cm->mi_grid_base, 0,
-         cm->mi_stride * (cm->mi_rows + 1) * sizeof(*cm->mi_grid_base));
-}
-
-static int vp9_dec_alloc_mi(VP9_COMMON *cm, int mi_size) {
-  cm->mip = vpx_calloc(mi_size, sizeof(*cm->mip));
-  if (!cm->mip)
-    return 1;
-  cm->mi_alloc_size = mi_size;
-  cm->mi_grid_base = (MODE_INFO **)vpx_calloc(mi_size, sizeof(MODE_INFO*));
-  if (!cm->mi_grid_base)
-    return 1;
-  return 0;
-}
-
-static void vp9_dec_free_mi(VP9_COMMON *cm) {
-  vpx_free(cm->mip);
-  cm->mip = NULL;
-  vpx_free(cm->mi_grid_base);
-  cm->mi_grid_base = NULL;
-}
-
-VP9Decoder *vp9_decoder_create(BufferPool *const pool) {
-  VP9Decoder *volatile const pbi = vpx_memalign(32, sizeof(*pbi));
-  VP9_COMMON *volatile const cm = pbi ? &pbi->common : NULL;
-
-  if (!cm)
-    return NULL;
-
-  vp9_zero(*pbi);
-
-  if (setjmp(cm->error.jmp)) {
-    cm->error.setjmp = 0;
-    vp9_decoder_remove(pbi);
-    return NULL;
-  }
-
-  cm->error.setjmp = 1;
-
-  CHECK_MEM_ERROR(cm, cm->fc,
-                  (FRAME_CONTEXT *)vpx_calloc(1, sizeof(*cm->fc)));
-  CHECK_MEM_ERROR(cm, cm->frame_contexts,
-                  (FRAME_CONTEXT *)vpx_calloc(FRAME_CONTEXTS,
-                  sizeof(*cm->frame_contexts)));
-
-  pbi->need_resync = 1;
-  once(initialize_dec);
-
-  // Initialize the references to not point to any frame buffers.
-  memset(&cm->ref_frame_map, -1, sizeof(cm->ref_frame_map));
-  memset(&cm->next_ref_frame_map, -1, sizeof(cm->next_ref_frame_map));
-
-  cm->current_video_frame = 0;
-  pbi->ready_for_new_data = 1;
-  pbi->common.buffer_pool = pool;
-
-  cm->bit_depth = VPX_BITS_8;
-  cm->dequant_bit_depth = VPX_BITS_8;
-
-  cm->alloc_mi = vp9_dec_alloc_mi;
-  cm->free_mi = vp9_dec_free_mi;
-  cm->setup_mi = vp9_dec_setup_mi;
-
-  vp9_loop_filter_init(cm);
-
-  cm->error.setjmp = 0;
-
-  vpx_get_worker_interface()->init(&pbi->lf_worker);
-
-  return pbi;
-}
-
-void vp9_decoder_remove(VP9Decoder *pbi) {
-  int i;
-
-  if (!pbi)
-    return;
-
-  vpx_get_worker_interface()->end(&pbi->lf_worker);
-  vpx_free(pbi->lf_worker.data1);
-
-  for (i = 0; i < pbi->num_tile_workers; ++i) {
-    VPxWorker *const worker = &pbi->tile_workers[i];
-    vpx_get_worker_interface()->end(worker);
-  }
-
-  vpx_free(pbi->tile_worker_data);
-  vpx_free(pbi->tile_workers);
-
-  if (pbi->num_tile_workers > 0) {
-    vp9_loop_filter_dealloc(&pbi->lf_row_sync);
-  }
-
-  vpx_free(pbi);
-}
-
-static int equal_dimensions(const YV12_BUFFER_CONFIG *a,
-                            const YV12_BUFFER_CONFIG *b) {
-    return a->y_height == b->y_height && a->y_width == b->y_width &&
-           a->uv_height == b->uv_height && a->uv_width == b->uv_width;
-}
-
-vpx_codec_err_t vp9_copy_reference_dec(VP9Decoder *pbi,
-                                       VP9_REFFRAME ref_frame_flag,
-                                       YV12_BUFFER_CONFIG *sd) {
-  VP9_COMMON *cm = &pbi->common;
-
-  /* TODO(jkoleszar): The decoder doesn't have any real knowledge of what the
-   * encoder is using the frame buffers for. This is just a stub to keep the
-   * vpxenc --test-decode functionality working, and will be replaced in a
-   * later commit that adds VP9-specific controls for this functionality.
-   */
-  if (ref_frame_flag == VP9_LAST_FLAG) {
-    const YV12_BUFFER_CONFIG *const cfg = get_ref_frame(cm, 0);
-    if (cfg == NULL) {
-      vpx_internal_error(&cm->error, VPX_CODEC_ERROR,
-                         "No 'last' reference frame");
-      return VPX_CODEC_ERROR;
-    }
-    if (!equal_dimensions(cfg, sd))
-      vpx_internal_error(&cm->error, VPX_CODEC_ERROR,
-                         "Incorrect buffer dimensions");
-    else
-      vp8_yv12_copy_frame(cfg, sd);
-  } else {
-    vpx_internal_error(&cm->error, VPX_CODEC_ERROR,
-                       "Invalid reference frame");
-  }
-
-  return cm->error.error_code;
-}
-
-
-vpx_codec_err_t vp9_set_reference_dec(VP9_COMMON *cm,
-                                      VP9_REFFRAME ref_frame_flag,
-                                      YV12_BUFFER_CONFIG *sd) {
-  int idx;
-  YV12_BUFFER_CONFIG *ref_buf = NULL;
-
-  // TODO(jkoleszar): The decoder doesn't have any real knowledge of what the
-  // encoder is using the frame buffers for. This is just a stub to keep the
-  // vpxenc --test-decode functionality working, and will be replaced in a
-  // later commit that adds VP9-specific controls for this functionality.
-
-  // (Yunqing) The set_reference control depends on the following setting in
-  // encoder.
-  // cpi->lst_fb_idx = 0;
-  // cpi->gld_fb_idx = 1;
-  // cpi->alt_fb_idx = 2;
-  if (ref_frame_flag == VP9_LAST_FLAG) {
-    idx = cm->ref_frame_map[0];
-  } else if (ref_frame_flag == VP9_GOLD_FLAG) {
-    idx = cm->ref_frame_map[1];
-  } else if (ref_frame_flag == VP9_ALT_FLAG) {
-    idx = cm->ref_frame_map[2];
-  } else {
-    vpx_internal_error(&cm->error, VPX_CODEC_ERROR,
-                       "Invalid reference frame");
-    return cm->error.error_code;
-  }
-
-  if (idx < 0 || idx >= FRAME_BUFFERS) {
-    vpx_internal_error(&cm->error, VPX_CODEC_ERROR,
-                       "Invalid reference frame map");
-    return cm->error.error_code;
-  }
-
-  // Get the destination reference buffer.
-  ref_buf = &cm->buffer_pool->frame_bufs[idx].buf;
-
-  if (!equal_dimensions(ref_buf, sd)) {
-    vpx_internal_error(&cm->error, VPX_CODEC_ERROR,
-                       "Incorrect buffer dimensions");
-  } else {
-    // Overwrite the reference frame buffer.
-    vp8_yv12_copy_frame(sd, ref_buf);
-  }
-
-  return cm->error.error_code;
-}
-
-/* If any buffer updating is signaled it should be done here. */
-static void swap_frame_buffers(VP9Decoder *pbi) {
-  int ref_index = 0, mask;
-  VP9_COMMON *const cm = &pbi->common;
-  BufferPool *const pool = cm->buffer_pool;
-  RefCntBuffer *const frame_bufs = cm->buffer_pool->frame_bufs;
-
-  lock_buffer_pool(pool);
-  for (mask = pbi->refresh_frame_flags; mask; mask >>= 1) {
-    const int old_idx = cm->ref_frame_map[ref_index];
-    // Current thread releases the holding of reference frame.
-    decrease_ref_count(old_idx, frame_bufs, pool);
-
-    // Release the reference frame in reference map.
-    if (mask & 1)
-      decrease_ref_count(old_idx, frame_bufs, pool);
-
-    cm->ref_frame_map[ref_index] = cm->next_ref_frame_map[ref_index];
-    ++ref_index;
-  }
-
-  // Current thread releases the holding of reference frame.
-  for (; ref_index < REF_FRAMES && !cm->show_existing_frame; ++ref_index) {
-    const int old_idx = cm->ref_frame_map[ref_index];
-    decrease_ref_count(old_idx, frame_bufs, pool);
-    cm->ref_frame_map[ref_index] = cm->next_ref_frame_map[ref_index];
-  }
-  unlock_buffer_pool(pool);
-  pbi->hold_ref_buf = 0;
-  cm->frame_to_show = get_frame_new_buffer(cm);
-
-  if (!pbi->frame_parallel_decode || !cm->show_frame) {
-    lock_buffer_pool(pool);
-    --frame_bufs[cm->new_fb_idx].ref_count;
-    unlock_buffer_pool(pool);
-  }
-
-  // Invalidate these references until the next frame starts.
-  for (ref_index = 0; ref_index < REFS_PER_FRAME; ref_index++)
-    cm->frame_refs[ref_index].idx = -1;
-}
-
-int vp9_receive_compressed_data(VP9Decoder *pbi,
-                                size_t size, const uint8_t **psource) {
-  VP9_COMMON *volatile const cm = &pbi->common;
-  BufferPool *volatile const pool = cm->buffer_pool;
-  RefCntBuffer *volatile const frame_bufs = cm->buffer_pool->frame_bufs;
-  const uint8_t *source = *psource;
-  int retcode = 0;
-  cm->error.error_code = VPX_CODEC_OK;
-
-  if (size == 0) {
-    // This is used to signal that we are missing frames.
-    // We do not know if the missing frame(s) was supposed to update
-    // any of the reference buffers, but we act conservative and
-    // mark only the last buffer as corrupted.
-    //
-    // TODO(jkoleszar): Error concealment is undefined and non-normative
-    // at this point, but if it becomes so, [0] may not always be the correct
-    // thing to do here.
-    if (cm->frame_refs[0].idx > 0) {
-      assert(cm->frame_refs[0].buf != NULL);
-      cm->frame_refs[0].buf->corrupted = 1;
-    }
-  }
-
-  pbi->ready_for_new_data = 0;
-
-  // Check if the previous frame was a frame without any references to it.
-  // Release frame buffer if not decoding in frame parallel mode.
-  if (!pbi->frame_parallel_decode && cm->new_fb_idx >= 0
-      && frame_bufs[cm->new_fb_idx].ref_count == 0)
-    pool->release_fb_cb(pool->cb_priv,
-                        &frame_bufs[cm->new_fb_idx].raw_frame_buffer);
-  // Find a free frame buffer. Return error if can not find any.
-  cm->new_fb_idx = get_free_fb(cm);
-  if (cm->new_fb_idx == INVALID_IDX) {
-    vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR,
-                       "Unable to find free frame buffer");
-    return cm->error.error_code;
-  }
-
-  // Assign a MV array to the frame buffer.
-  cm->cur_frame = &pool->frame_bufs[cm->new_fb_idx];
-
-  pbi->hold_ref_buf = 0;
-  if (pbi->frame_parallel_decode) {
-    VPxWorker *const worker = pbi->frame_worker_owner;
-    vp9_frameworker_lock_stats(worker);
-    frame_bufs[cm->new_fb_idx].frame_worker_owner = worker;
-    // Reset decoding progress.
-    pbi->cur_buf = &frame_bufs[cm->new_fb_idx];
-    pbi->cur_buf->row = -1;
-    pbi->cur_buf->col = -1;
-    vp9_frameworker_unlock_stats(worker);
-  } else {
-    pbi->cur_buf = &frame_bufs[cm->new_fb_idx];
-  }
-
-  if (setjmp(cm->error.jmp)) {
-    const VPxWorkerInterface *const winterface = vpx_get_worker_interface();
-    int i;
-
-    cm->error.setjmp = 0;
-    pbi->ready_for_new_data = 1;
-
-    // Synchronize all threads immediately as a subsequent decode call may
-    // cause a resize invalidating some allocations.
-    winterface->sync(&pbi->lf_worker);
-    for (i = 0; i < pbi->num_tile_workers; ++i) {
-      winterface->sync(&pbi->tile_workers[i]);
-    }
-
-    lock_buffer_pool(pool);
-    // Release all the reference buffers if worker thread is holding them.
-    if (pbi->hold_ref_buf == 1) {
-      int ref_index = 0, mask;
-      for (mask = pbi->refresh_frame_flags; mask; mask >>= 1) {
-        const int old_idx = cm->ref_frame_map[ref_index];
-        // Current thread releases the holding of reference frame.
-        decrease_ref_count(old_idx, frame_bufs, pool);
-
-        // Release the reference frame in reference map.
-        if (mask & 1)
-          decrease_ref_count(old_idx, frame_bufs, pool);
-        ++ref_index;
-      }
-
-      // Current thread releases the holding of reference frame.
-      for (; ref_index < REF_FRAMES && !cm->show_existing_frame; ++ref_index) {
-        const int old_idx = cm->ref_frame_map[ref_index];
-        decrease_ref_count(old_idx, frame_bufs, pool);
-      }
-      pbi->hold_ref_buf = 0;
-    }
-    // Release current frame.
-    decrease_ref_count(cm->new_fb_idx, frame_bufs, pool);
-    unlock_buffer_pool(pool);
-
-    vpx_clear_system_state();
-    return -1;
-  }
-
-  cm->error.setjmp = 1;
-  vp9_decode_frame(pbi, source, source + size, psource);
-
-  swap_frame_buffers(pbi);
-
-  vpx_clear_system_state();
-
-  if (!cm->show_existing_frame) {
-    cm->last_show_frame = cm->show_frame;
-    cm->prev_frame = cm->cur_frame;
-    if (cm->seg.enabled && !pbi->frame_parallel_decode)
-      vp9_swap_current_and_last_seg_map(cm);
-  }
-
-  // Update progress in frame parallel decode.
-  if (pbi->frame_parallel_decode) {
-    // Need to lock the mutex here as another thread may
-    // be accessing this buffer.
-    VPxWorker *const worker = pbi->frame_worker_owner;
-    FrameWorkerData *const frame_worker_data = worker->data1;
-    vp9_frameworker_lock_stats(worker);
-
-    if (cm->show_frame) {
-      cm->current_video_frame++;
-    }
-    frame_worker_data->frame_decoded = 1;
-    frame_worker_data->frame_context_ready = 1;
-    vp9_frameworker_signal_stats(worker);
-    vp9_frameworker_unlock_stats(worker);
-  } else {
-    cm->last_width = cm->width;
-    cm->last_height = cm->height;
-    if (cm->show_frame) {
-      cm->current_video_frame++;
-    }
-  }
-
-  cm->error.setjmp = 0;
-  return retcode;
-}
-
-int vp9_get_raw_frame(VP9Decoder *pbi, YV12_BUFFER_CONFIG *sd,
-                      vp9_ppflags_t *flags) {
-  VP9_COMMON *const cm = &pbi->common;
-  int ret = -1;
-#if !CONFIG_VP9_POSTPROC
-  (void)*flags;
-#endif
-
-  if (pbi->ready_for_new_data == 1)
-    return ret;
-
-  pbi->ready_for_new_data = 1;
-
-  /* no raw frame to show!!! */
-  if (!cm->show_frame)
-    return ret;
-
-  pbi->ready_for_new_data = 1;
-
-#if CONFIG_VP9_POSTPROC
-  if (!cm->show_existing_frame) {
-    ret = vp9_post_proc_frame(cm, sd, flags);
-  } else {
-    *sd = *cm->frame_to_show;
-    ret = 0;
-  }
-#else
-  *sd = *cm->frame_to_show;
-  ret = 0;
-#endif /*!CONFIG_POSTPROC*/
-  vpx_clear_system_state();
-  return ret;
-}
-
-vpx_codec_err_t vp9_parse_superframe_index(const uint8_t *data,
-                                           size_t data_sz,
-                                           uint32_t sizes[8], int *count,
-                                           vpx_decrypt_cb decrypt_cb,
-                                           void *decrypt_state) {
-  // A chunk ending with a byte matching 0xc0 is an invalid chunk unless
-  // it is a super frame index. If the last byte of real video compression
-  // data is 0xc0 the encoder must add a 0 byte. If we have the marker but
-  // not the associated matching marker byte at the front of the index we have
-  // an invalid bitstream and need to return an error.
-
-  uint8_t marker;
-
-  assert(data_sz);
-  marker = read_marker(decrypt_cb, decrypt_state, data + data_sz - 1);
-  *count = 0;
-
-  if ((marker & 0xe0) == 0xc0) {
-    const uint32_t frames = (marker & 0x7) + 1;
-    const uint32_t mag = ((marker >> 3) & 0x3) + 1;
-    const size_t index_sz = 2 + mag * frames;
-
-    // This chunk is marked as having a superframe index but doesn't have
-    // enough data for it, thus it's an invalid superframe index.
-    if (data_sz < index_sz)
-      return VPX_CODEC_CORRUPT_FRAME;
-
-    {
-      const uint8_t marker2 = read_marker(decrypt_cb, decrypt_state,
-                                          data + data_sz - index_sz);
-
-      // This chunk is marked as having a superframe index but doesn't have
-      // the matching marker byte at the front of the index therefore it's an
-      // invalid chunk.
-      if (marker != marker2)
-        return VPX_CODEC_CORRUPT_FRAME;
-    }
-
-    {
-      // Found a valid superframe index.
-      uint32_t i, j;
-      const uint8_t *x = &data[data_sz - index_sz + 1];
-
-      // Frames has a maximum of 8 and mag has a maximum of 4.
-      uint8_t clear_buffer[32];
-      assert(sizeof(clear_buffer) >= frames * mag);
-      if (decrypt_cb) {
-        decrypt_cb(decrypt_state, x, clear_buffer, frames * mag);
-        x = clear_buffer;
-      }
-
-      for (i = 0; i < frames; ++i) {
-        uint32_t this_sz = 0;
-
-        for (j = 0; j < mag; ++j)
-          this_sz |= ((uint32_t)(*x++)) << (j * 8);
-        sizes[i] = this_sz;
-      }
-      *count = frames;
-    }
-  }
-  return VPX_CODEC_OK;
-}
diff --git a/vp9/decoder/vp9_decoder.h b/vp9/decoder/vp9_decoder.h
deleted file mode 100644 (file)
index 7111a36..0000000
+++ /dev/null
@@ -1,137 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#ifndef VP9_DECODER_VP9_DECODER_H_
-#define VP9_DECODER_VP9_DECODER_H_
-
-#include "./vpx_config.h"
-
-#include "vpx/vpx_codec.h"
-#include "vpx_dsp/bitreader.h"
-#include "vpx_scale/yv12config.h"
-#include "vpx_util/vpx_thread.h"
-
-#include "vp9/common/vp9_thread_common.h"
-#include "vp9/common/vp9_onyxc_int.h"
-#include "vp9/common/vp9_ppflags.h"
-#include "vp9/decoder/vp9_dthread.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef struct TileBuffer {
-  const uint8_t *data;
-  size_t size;
-  int col;  // only used with multi-threaded decoding
-} TileBuffer;
-
-typedef struct TileWorkerData {
-  const uint8_t *data_end;
-  int buf_start, buf_end;  // pbi->tile_buffers to decode, inclusive
-  vpx_reader bit_reader;
-  FRAME_COUNTS counts;
-  DECLARE_ALIGNED(16, MACROBLOCKD, xd);
-  /* dqcoeff are shared by all the planes. So planes must be decoded serially */
-  DECLARE_ALIGNED(16, tran_low_t, dqcoeff[32 * 32]);
-  struct vpx_internal_error_info error_info;
-} TileWorkerData;
-
-typedef struct VP9Decoder {
-  DECLARE_ALIGNED(16, MACROBLOCKD, mb);
-
-  DECLARE_ALIGNED(16, VP9_COMMON, common);
-
-  int ready_for_new_data;
-
-  int refresh_frame_flags;
-
-  int frame_parallel_decode;  // frame-based threading.
-
-  // TODO(hkuang): Combine this with cur_buf in macroblockd as they are
-  // the same.
-  RefCntBuffer *cur_buf;   //  Current decoding frame buffer.
-
-  VPxWorker *frame_worker_owner;   // frame_worker that owns this pbi.
-  VPxWorker lf_worker;
-  VPxWorker *tile_workers;
-  TileWorkerData *tile_worker_data;
-  TileBuffer tile_buffers[64];
-  int num_tile_workers;
-  int total_tiles;
-
-  VP9LfSync lf_row_sync;
-
-  vpx_decrypt_cb decrypt_cb;
-  void *decrypt_state;
-
-  int max_threads;
-  int inv_tile_order;
-  int need_resync;  // wait for key/intra-only frame.
-  int hold_ref_buf;  // hold the reference buffer.
-} VP9Decoder;
-
-int vp9_receive_compressed_data(struct VP9Decoder *pbi,
-                                size_t size, const uint8_t **dest);
-
-int vp9_get_raw_frame(struct VP9Decoder *pbi, YV12_BUFFER_CONFIG *sd,
-                      vp9_ppflags_t *flags);
-
-vpx_codec_err_t vp9_copy_reference_dec(struct VP9Decoder *pbi,
-                                       VP9_REFFRAME ref_frame_flag,
-                                       YV12_BUFFER_CONFIG *sd);
-
-vpx_codec_err_t vp9_set_reference_dec(VP9_COMMON *cm,
-                                      VP9_REFFRAME ref_frame_flag,
-                                      YV12_BUFFER_CONFIG *sd);
-
-static INLINE uint8_t read_marker(vpx_decrypt_cb decrypt_cb,
-                                  void *decrypt_state,
-                                  const uint8_t *data) {
-  if (decrypt_cb) {
-    uint8_t marker;
-    decrypt_cb(decrypt_state, data, &marker, 1);
-    return marker;
-  }
-  return *data;
-}
-
-// This function is exposed for use in tests, as well as the inlined function
-// "read_marker".
-vpx_codec_err_t vp9_parse_superframe_index(const uint8_t *data,
-                                           size_t data_sz,
-                                           uint32_t sizes[8], int *count,
-                                           vpx_decrypt_cb decrypt_cb,
-                                           void *decrypt_state);
-
-struct VP9Decoder *vp9_decoder_create(BufferPool *const pool);
-
-void vp9_decoder_remove(struct VP9Decoder *pbi);
-
-static INLINE void decrease_ref_count(int idx, RefCntBuffer *const frame_bufs,
-                                      BufferPool *const pool) {
-  if (idx >= 0 && frame_bufs[idx].ref_count > 0) {
-    --frame_bufs[idx].ref_count;
-    // A worker may only get a free framebuffer index when calling get_free_fb.
-    // But the private buffer is not set up until finish decoding header.
-    // So any error happens during decoding header, the frame_bufs will not
-    // have valid priv buffer.
-    if (frame_bufs[idx].ref_count == 0 &&
-        frame_bufs[idx].raw_frame_buffer.priv) {
-      pool->release_fb_cb(pool->cb_priv, &frame_bufs[idx].raw_frame_buffer);
-    }
-  }
-}
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP9_DECODER_VP9_DECODER_H_
diff --git a/vp9/decoder/vp9_detokenize.c b/vp9/decoder/vp9_detokenize.c
deleted file mode 100644 (file)
index 47dc107..0000000
+++ /dev/null
@@ -1,224 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#include "vpx_mem/vpx_mem.h"
-#include "vpx_ports/mem.h"
-
-#include "vp9/common/vp9_blockd.h"
-#include "vp9/common/vp9_common.h"
-#include "vp9/common/vp9_entropy.h"
-#if CONFIG_COEFFICIENT_RANGE_CHECKING
-#include "vp9/common/vp9_idct.h"
-#endif
-
-#include "vp9/decoder/vp9_detokenize.h"
-
-#define EOB_CONTEXT_NODE            0
-#define ZERO_CONTEXT_NODE           1
-#define ONE_CONTEXT_NODE            2
-
-#define INCREMENT_COUNT(token)                              \
-  do {                                                      \
-     if (counts)                                            \
-       ++coef_counts[band][ctx][token];                     \
-  } while (0)
-
-static INLINE int read_coeff(const vpx_prob *probs, int n, vpx_reader *r) {
-  int i, val = 0;
-  for (i = 0; i < n; ++i)
-    val = (val << 1) | vpx_read(r, probs[i]);
-  return val;
-}
-
-static int decode_coefs(const MACROBLOCKD *xd,
-                        PLANE_TYPE type,
-                        tran_low_t *dqcoeff, TX_SIZE tx_size, const int16_t *dq,
-                        int ctx, const int16_t *scan, const int16_t *nb,
-                        vpx_reader *r) {
-  FRAME_COUNTS *counts = xd->counts;
-  const int max_eob = 16 << (tx_size << 1);
-  const FRAME_CONTEXT *const fc = xd->fc;
-  const int ref = is_inter_block(xd->mi[0]);
-  int band, c = 0;
-  const vpx_prob (*coef_probs)[COEFF_CONTEXTS][UNCONSTRAINED_NODES] =
-      fc->coef_probs[tx_size][type][ref];
-  const vpx_prob *prob;
-  unsigned int (*coef_counts)[COEFF_CONTEXTS][UNCONSTRAINED_NODES + 1];
-  unsigned int (*eob_branch_count)[COEFF_CONTEXTS];
-  uint8_t token_cache[32 * 32];
-  const uint8_t *band_translate = get_band_translate(tx_size);
-  const int dq_shift = (tx_size == TX_32X32);
-  int v, token;
-  int16_t dqv = dq[0];
-  const uint8_t *const cat6_prob =
-#if CONFIG_VP9_HIGHBITDEPTH
-      (xd->bd == VPX_BITS_12) ? vp9_cat6_prob_high12 :
-      (xd->bd == VPX_BITS_10) ? vp9_cat6_prob_high12 + 2 :
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-      vp9_cat6_prob;
-  const int cat6_bits =
-#if CONFIG_VP9_HIGHBITDEPTH
-      (xd->bd == VPX_BITS_12) ? 18 :
-      (xd->bd == VPX_BITS_10) ? 16 :
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-      14;
-
-  if (counts) {
-    coef_counts = counts->coef[tx_size][type][ref];
-    eob_branch_count = counts->eob_branch[tx_size][type][ref];
-  }
-
-  while (c < max_eob) {
-    int val = -1;
-    band = *band_translate++;
-    prob = coef_probs[band][ctx];
-    if (counts)
-      ++eob_branch_count[band][ctx];
-    if (!vpx_read(r, prob[EOB_CONTEXT_NODE])) {
-      INCREMENT_COUNT(EOB_MODEL_TOKEN);
-      break;
-    }
-
-    while (!vpx_read(r, prob[ZERO_CONTEXT_NODE])) {
-      INCREMENT_COUNT(ZERO_TOKEN);
-      dqv = dq[1];
-      token_cache[scan[c]] = 0;
-      ++c;
-      if (c >= max_eob)
-        return c;  // zero tokens at the end (no eob token)
-      ctx = get_coef_context(nb, token_cache, c);
-      band = *band_translate++;
-      prob = coef_probs[band][ctx];
-    }
-
-    if (!vpx_read(r, prob[ONE_CONTEXT_NODE])) {
-      INCREMENT_COUNT(ONE_TOKEN);
-      token = ONE_TOKEN;
-      val = 1;
-    } else {
-      INCREMENT_COUNT(TWO_TOKEN);
-      token = vpx_read_tree(r, vp9_coef_con_tree,
-                            vp9_pareto8_full[prob[PIVOT_NODE] - 1]);
-      switch (token) {
-        case TWO_TOKEN:
-        case THREE_TOKEN:
-        case FOUR_TOKEN:
-          val = token;
-          break;
-        case CATEGORY1_TOKEN:
-          val = CAT1_MIN_VAL + read_coeff(vp9_cat1_prob, 1, r);
-          break;
-        case CATEGORY2_TOKEN:
-          val = CAT2_MIN_VAL + read_coeff(vp9_cat2_prob, 2, r);
-          break;
-        case CATEGORY3_TOKEN:
-          val = CAT3_MIN_VAL + read_coeff(vp9_cat3_prob, 3, r);
-          break;
-        case CATEGORY4_TOKEN:
-          val = CAT4_MIN_VAL + read_coeff(vp9_cat4_prob, 4, r);
-          break;
-        case CATEGORY5_TOKEN:
-          val = CAT5_MIN_VAL + read_coeff(vp9_cat5_prob, 5, r);
-          break;
-        case CATEGORY6_TOKEN:
-          val = CAT6_MIN_VAL + read_coeff(cat6_prob, cat6_bits, r);
-          break;
-      }
-    }
-    v = (val * dqv) >> dq_shift;
-#if CONFIG_COEFFICIENT_RANGE_CHECKING
-#if CONFIG_VP9_HIGHBITDEPTH
-    dqcoeff[scan[c]] = highbd_check_range((vpx_read_bit(r) ? -v : v),
-                                          xd->bd);
-#else
-    dqcoeff[scan[c]] = check_range(vpx_read_bit(r) ? -v : v);
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-#else
-    dqcoeff[scan[c]] = vpx_read_bit(r) ? -v : v;
-#endif  // CONFIG_COEFFICIENT_RANGE_CHECKING
-    token_cache[scan[c]] = vp9_pt_energy_class[token];
-    ++c;
-    ctx = get_coef_context(nb, token_cache, c);
-    dqv = dq[1];
-  }
-
-  return c;
-}
-
-static void get_ctx_shift(MACROBLOCKD *xd, int *ctx_shift_a, int *ctx_shift_l,
-                          int x, int y, unsigned int tx_size_in_blocks) {
-  if (xd->max_blocks_wide) {
-    if (tx_size_in_blocks + x > xd->max_blocks_wide)
-      *ctx_shift_a = (tx_size_in_blocks - (xd->max_blocks_wide - x)) * 8;
-  }
-  if (xd->max_blocks_high) {
-    if (tx_size_in_blocks + y > xd->max_blocks_high)
-      *ctx_shift_l = (tx_size_in_blocks - (xd->max_blocks_high - y)) * 8;
-  }
-}
-
-int vp9_decode_block_tokens(MACROBLOCKD *xd, int plane, const scan_order *sc,
-                            int x, int y, TX_SIZE tx_size, vpx_reader *r,
-                            int seg_id) {
-  struct macroblockd_plane *const pd = &xd->plane[plane];
-  const int16_t *const dequant = pd->seg_dequant[seg_id];
-  int eob;
-  ENTROPY_CONTEXT *a = pd->above_context + x;
-  ENTROPY_CONTEXT *l = pd->left_context + y;
-  int ctx;
-  int ctx_shift_a = 0;
-  int ctx_shift_l = 0;
-
-  switch (tx_size) {
-    case TX_4X4:
-      ctx  = a[0] != 0;
-      ctx += l[0] != 0;
-      eob = decode_coefs(xd, get_plane_type(plane), pd->dqcoeff, tx_size,
-                         dequant, ctx, sc->scan, sc->neighbors, r);
-      a[0] = l[0] = (eob > 0);
-      break;
-    case TX_8X8:
-      get_ctx_shift(xd, &ctx_shift_a, &ctx_shift_l, x, y, 1 << TX_8X8);
-      ctx  = !!*(const uint16_t *)a;
-      ctx += !!*(const uint16_t *)l;
-      eob = decode_coefs(xd, get_plane_type(plane), pd->dqcoeff, tx_size,
-                         dequant, ctx, sc->scan, sc->neighbors, r);
-      *(uint16_t *)a = ((eob > 0) * 0x0101) >> ctx_shift_a;
-      *(uint16_t *)l = ((eob > 0) * 0x0101) >> ctx_shift_l;
-      break;
-    case TX_16X16:
-      get_ctx_shift(xd, &ctx_shift_a, &ctx_shift_l, x, y, 1 << TX_16X16);
-      ctx  = !!*(const uint32_t *)a;
-      ctx += !!*(const uint32_t *)l;
-      eob = decode_coefs(xd, get_plane_type(plane), pd->dqcoeff, tx_size,
-                         dequant, ctx, sc->scan, sc->neighbors, r);
-      *(uint32_t *)a = ((eob > 0) * 0x01010101) >> ctx_shift_a;
-      *(uint32_t *)l = ((eob > 0) * 0x01010101) >> ctx_shift_l;
-      break;
-    case TX_32X32:
-      get_ctx_shift(xd, &ctx_shift_a, &ctx_shift_l, x, y, 1 << TX_32X32);
-      // NOTE: casting to uint64_t here is safe because the default memory
-      // alignment is at least 8 bytes and the TX_32X32 is aligned on 8 byte
-      // boundaries.
-      ctx  = !!*(const uint64_t *)a;
-      ctx += !!*(const uint64_t *)l;
-      eob = decode_coefs(xd, get_plane_type(plane), pd->dqcoeff, tx_size,
-                         dequant, ctx, sc->scan, sc->neighbors, r);
-      *(uint64_t *)a = ((eob > 0) * 0x0101010101010101ULL) >> ctx_shift_a;
-      *(uint64_t *)l = ((eob > 0) * 0x0101010101010101ULL) >> ctx_shift_l;
-      break;
-    default:
-      assert(0 && "Invalid transform size.");
-      eob = 0;
-      break;
-  }
-
-  return eob;
-}
diff --git a/vp9/decoder/vp9_detokenize.h b/vp9/decoder/vp9_detokenize.h
deleted file mode 100644 (file)
index d242d44..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#ifndef VP9_DECODER_VP9_DETOKENIZE_H_
-#define VP9_DECODER_VP9_DETOKENIZE_H_
-
-#include "vpx_dsp/bitreader.h"
-#include "vp9/decoder/vp9_decoder.h"
-#include "vp9/common/vp9_scan.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-int vp9_decode_block_tokens(MACROBLOCKD *xd,
-                            int plane, const scan_order *sc,
-                            int x, int y,
-                            TX_SIZE tx_size, vpx_reader *r,
-                            int seg_id);
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP9_DECODER_VP9_DETOKENIZE_H_
diff --git a/vp9/decoder/vp9_dsubexp.c b/vp9/decoder/vp9_dsubexp.c
deleted file mode 100644 (file)
index 05b3853..0000000
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
-  Copyright (c) 2010 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.
- */
-
-#include <assert.h>
-
-#include "vp9/common/vp9_entropy.h"
-
-#include "vp9/decoder/vp9_dsubexp.h"
-
-static int inv_recenter_nonneg(int v, int m) {
-  if (v > 2 * m)
-    return v;
-
-  return (v & 1) ? m - ((v + 1) >> 1) : m + (v >> 1);
-}
-
-static int decode_uniform(vpx_reader *r) {
-  const int l = 8;
-  const int m = (1 << l) - 191;
-  const int v = vpx_read_literal(r, l - 1);
-  return v < m ?  v : (v << 1) - m + vpx_read_bit(r);
-}
-
-static int inv_remap_prob(int v, int m) {
-  static uint8_t inv_map_table[MAX_PROB] = {
-      7,  20,  33,  46,  59,  72,  85,  98, 111, 124, 137, 150, 163, 176, 189,
-    202, 215, 228, 241, 254,   1,   2,   3,   4,   5,   6,   8,   9,  10,  11,
-     12,  13,  14,  15,  16,  17,  18,  19,  21,  22,  23,  24,  25,  26,  27,
-     28,  29,  30,  31,  32,  34,  35,  36,  37,  38,  39,  40,  41,  42,  43,
-     44,  45,  47,  48,  49,  50,  51,  52,  53,  54,  55,  56,  57,  58,  60,
-     61,  62,  63,  64,  65,  66,  67,  68,  69,  70,  71,  73,  74,  75,  76,
-     77,  78,  79,  80,  81,  82,  83,  84,  86,  87,  88,  89,  90,  91,  92,
-     93,  94,  95,  96,  97,  99, 100, 101, 102, 103, 104, 105, 106, 107, 108,
-    109, 110, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 125,
-    126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 138, 139, 140, 141,
-    142, 143, 144, 145, 146, 147, 148, 149, 151, 152, 153, 154, 155, 156, 157,
-    158, 159, 160, 161, 162, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173,
-    174, 175, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 190,
-    191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 203, 204, 205, 206,
-    207, 208, 209, 210, 211, 212, 213, 214, 216, 217, 218, 219, 220, 221, 222,
-    223, 224, 225, 226, 227, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238,
-    239, 240, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 253
-  };
-  assert(v < (int)(sizeof(inv_map_table) / sizeof(inv_map_table[0])));
-  v = inv_map_table[v];
-  m--;
-  if ((m << 1) <= MAX_PROB) {
-    return 1 + inv_recenter_nonneg(v, m);
-  } else {
-    return MAX_PROB - inv_recenter_nonneg(v, MAX_PROB - 1 - m);
-  }
-}
-
-static int decode_term_subexp(vpx_reader *r) {
-  if (!vpx_read_bit(r))
-    return vpx_read_literal(r, 4);
-  if (!vpx_read_bit(r))
-    return vpx_read_literal(r, 4) + 16;
-  if (!vpx_read_bit(r))
-    return vpx_read_literal(r, 5) + 32;
-  return decode_uniform(r) + 64;
-}
-
-void vp9_diff_update_prob(vpx_reader *r, vpx_prob* p) {
-  if (vpx_read(r, DIFF_UPDATE_PROB)) {
-    const int delp = decode_term_subexp(r);
-    *p = (vpx_prob)inv_remap_prob(delp, *p);
-  }
-}
diff --git a/vp9/decoder/vp9_dsubexp.h b/vp9/decoder/vp9_dsubexp.h
deleted file mode 100644 (file)
index a8bcc70..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- *  Copyright (c) 2013 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.
- */
-
-
-#ifndef VP9_DECODER_VP9_DSUBEXP_H_
-#define VP9_DECODER_VP9_DSUBEXP_H_
-
-#include "vpx_dsp/bitreader.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-void vp9_diff_update_prob(vpx_reader *r, vpx_prob* p);
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP9_DECODER_VP9_DSUBEXP_H_
diff --git a/vp9/decoder/vp9_dthread.c b/vp9/decoder/vp9_dthread.c
deleted file mode 100644 (file)
index 14a7144..0000000
+++ /dev/null
@@ -1,189 +0,0 @@
-/*
- *  Copyright (c) 2014 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.
- */
-
-#include "./vpx_config.h"
-#include "vpx_mem/vpx_mem.h"
-#include "vp9/common/vp9_reconinter.h"
-#include "vp9/decoder/vp9_dthread.h"
-#include "vp9/decoder/vp9_decoder.h"
-
-// #define DEBUG_THREAD
-
-// TODO(hkuang): Clean up all the #ifdef in this file.
-void vp9_frameworker_lock_stats(VPxWorker *const worker) {
-#if CONFIG_MULTITHREAD
-  FrameWorkerData *const worker_data = worker->data1;
-  pthread_mutex_lock(&worker_data->stats_mutex);
-#else
-  (void)worker;
-#endif
-}
-
-void vp9_frameworker_unlock_stats(VPxWorker *const worker) {
-#if CONFIG_MULTITHREAD
-  FrameWorkerData *const worker_data = worker->data1;
-  pthread_mutex_unlock(&worker_data->stats_mutex);
-#else
-  (void)worker;
-#endif
-}
-
-void vp9_frameworker_signal_stats(VPxWorker *const worker) {
-#if CONFIG_MULTITHREAD
-  FrameWorkerData *const worker_data = worker->data1;
-
-// TODO(hkuang): Fix the pthread_cond_broadcast in windows wrapper.
-#if defined(_WIN32) && !HAVE_PTHREAD_H
-  pthread_cond_signal(&worker_data->stats_cond);
-#else
-  pthread_cond_broadcast(&worker_data->stats_cond);
-#endif
-
-#else
-  (void)worker;
-#endif
-}
-
-// This macro prevents thread_sanitizer from reporting known concurrent writes.
-#if defined(__has_feature)
-#if __has_feature(thread_sanitizer)
-#define BUILDING_WITH_TSAN
-#endif
-#endif
-
-// TODO(hkuang): Remove worker parameter as it is only used in debug code.
-void vp9_frameworker_wait(VPxWorker *const worker, RefCntBuffer *const ref_buf,
-                          int row) {
-#if CONFIG_MULTITHREAD
-  if (!ref_buf)
-    return;
-
-#ifndef BUILDING_WITH_TSAN
-  // The following line of code will get harmless tsan error but it is the key
-  // to get best performance.
-  if (ref_buf->row >= row && ref_buf->buf.corrupted != 1) return;
-#endif
-
-  {
-    // Find the worker thread that owns the reference frame. If the reference
-    // frame has been fully decoded, it may not have owner.
-    VPxWorker *const ref_worker = ref_buf->frame_worker_owner;
-    FrameWorkerData *const ref_worker_data =
-        (FrameWorkerData *)ref_worker->data1;
-    const VP9Decoder *const pbi = ref_worker_data->pbi;
-
-#ifdef DEBUG_THREAD
-    {
-      FrameWorkerData *const worker_data = (FrameWorkerData *)worker->data1;
-      printf("%d %p worker is waiting for %d %p worker (%d)  ref %d \r\n",
-             worker_data->worker_id, worker, ref_worker_data->worker_id,
-             ref_buf->frame_worker_owner, row, ref_buf->row);
-    }
-#endif
-
-    vp9_frameworker_lock_stats(ref_worker);
-    while (ref_buf->row < row && pbi->cur_buf == ref_buf &&
-           ref_buf->buf.corrupted != 1) {
-      pthread_cond_wait(&ref_worker_data->stats_cond,
-                        &ref_worker_data->stats_mutex);
-    }
-
-    if (ref_buf->buf.corrupted == 1) {
-      FrameWorkerData *const worker_data = (FrameWorkerData *)worker->data1;
-      vp9_frameworker_unlock_stats(ref_worker);
-      vpx_internal_error(&worker_data->pbi->common.error,
-                         VPX_CODEC_CORRUPT_FRAME,
-                         "Worker %p failed to decode frame", worker);
-    }
-    vp9_frameworker_unlock_stats(ref_worker);
-  }
-#else
-  (void)worker;
-  (void)ref_buf;
-  (void)row;
-  (void)ref_buf;
-#endif  // CONFIG_MULTITHREAD
-}
-
-void vp9_frameworker_broadcast(RefCntBuffer *const buf, int row) {
-#if CONFIG_MULTITHREAD
-  VPxWorker *worker = buf->frame_worker_owner;
-
-#ifdef DEBUG_THREAD
-  {
-    FrameWorkerData *const worker_data = (FrameWorkerData *)worker->data1;
-    printf("%d %p worker decode to (%d) \r\n", worker_data->worker_id,
-           buf->frame_worker_owner, row);
-  }
-#endif
-
-  vp9_frameworker_lock_stats(worker);
-  buf->row = row;
-  vp9_frameworker_signal_stats(worker);
-  vp9_frameworker_unlock_stats(worker);
-#else
-  (void)buf;
-  (void)row;
-#endif  // CONFIG_MULTITHREAD
-}
-
-void vp9_frameworker_copy_context(VPxWorker *const dst_worker,
-                                  VPxWorker *const src_worker) {
-#if CONFIG_MULTITHREAD
-  FrameWorkerData *const src_worker_data = (FrameWorkerData *)src_worker->data1;
-  FrameWorkerData *const dst_worker_data = (FrameWorkerData *)dst_worker->data1;
-  VP9_COMMON *const src_cm = &src_worker_data->pbi->common;
-  VP9_COMMON *const dst_cm = &dst_worker_data->pbi->common;
-  int i;
-
-  // Wait until source frame's context is ready.
-  vp9_frameworker_lock_stats(src_worker);
-  while (!src_worker_data->frame_context_ready) {
-    pthread_cond_wait(&src_worker_data->stats_cond,
-        &src_worker_data->stats_mutex);
-  }
-
-  dst_cm->last_frame_seg_map = src_cm->seg.enabled ?
-      src_cm->current_frame_seg_map : src_cm->last_frame_seg_map;
-  dst_worker_data->pbi->need_resync = src_worker_data->pbi->need_resync;
-  vp9_frameworker_unlock_stats(src_worker);
-
-  dst_cm->bit_depth = src_cm->bit_depth;
-#if CONFIG_VP9_HIGHBITDEPTH
-  dst_cm->use_highbitdepth = src_cm->use_highbitdepth;
-#endif
-  dst_cm->prev_frame = src_cm->show_existing_frame ?
-                       src_cm->prev_frame : src_cm->cur_frame;
-  dst_cm->last_width = !src_cm->show_existing_frame ?
-                       src_cm->width : src_cm->last_width;
-  dst_cm->last_height = !src_cm->show_existing_frame ?
-                        src_cm->height : src_cm->last_height;
-  dst_cm->subsampling_x = src_cm->subsampling_x;
-  dst_cm->subsampling_y = src_cm->subsampling_y;
-  dst_cm->frame_type = src_cm->frame_type;
-  dst_cm->last_show_frame = !src_cm->show_existing_frame ?
-                            src_cm->show_frame : src_cm->last_show_frame;
-  for (i = 0; i < REF_FRAMES; ++i)
-    dst_cm->ref_frame_map[i] = src_cm->next_ref_frame_map[i];
-
-  memcpy(dst_cm->lf_info.lfthr, src_cm->lf_info.lfthr,
-         (MAX_LOOP_FILTER + 1) * sizeof(loop_filter_thresh));
-  dst_cm->lf.last_sharpness_level = src_cm->lf.sharpness_level;
-  dst_cm->lf.filter_level = src_cm->lf.filter_level;
-  memcpy(dst_cm->lf.ref_deltas, src_cm->lf.ref_deltas, MAX_REF_LF_DELTAS);
-  memcpy(dst_cm->lf.mode_deltas, src_cm->lf.mode_deltas, MAX_MODE_LF_DELTAS);
-  dst_cm->seg = src_cm->seg;
-  memcpy(dst_cm->frame_contexts, src_cm->frame_contexts,
-         FRAME_CONTEXTS * sizeof(dst_cm->frame_contexts[0]));
-#else
-  (void) dst_worker;
-  (void) src_worker;
-#endif  // CONFIG_MULTITHREAD
-}
diff --git a/vp9/decoder/vp9_dthread.h b/vp9/decoder/vp9_dthread.h
deleted file mode 100644 (file)
index ba7c38a..0000000
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- *  Copyright (c) 2014 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.
- */
-
-#ifndef VP9_DECODER_VP9_DTHREAD_H_
-#define VP9_DECODER_VP9_DTHREAD_H_
-
-#include "./vpx_config.h"
-#include "vpx_util/vpx_thread.h"
-#include "vpx/internal/vpx_codec_internal.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-struct VP9Common;
-struct VP9Decoder;
-
-// WorkerData for the FrameWorker thread. It contains all the information of
-// the worker and decode structures for decoding a frame.
-typedef struct FrameWorkerData {
-  struct VP9Decoder *pbi;
-  const uint8_t *data;
-  const uint8_t *data_end;
-  size_t data_size;
-  void *user_priv;
-  int result;
-  int worker_id;
-  int received_frame;
-
-  // scratch_buffer is used in frame parallel mode only.
-  // It is used to make a copy of the compressed data.
-  uint8_t *scratch_buffer;
-  size_t scratch_buffer_size;
-
-#if CONFIG_MULTITHREAD
-  pthread_mutex_t stats_mutex;
-  pthread_cond_t stats_cond;
-#endif
-
-  int frame_context_ready;  // Current frame's context is ready to read.
-  int frame_decoded;        // Finished decoding current frame.
-} FrameWorkerData;
-
-void vp9_frameworker_lock_stats(VPxWorker *const worker);
-void vp9_frameworker_unlock_stats(VPxWorker *const worker);
-void vp9_frameworker_signal_stats(VPxWorker *const worker);
-
-// Wait until ref_buf has been decoded to row in real pixel unit.
-// Note: worker may already finish decoding ref_buf and release it in order to
-// start decoding next frame. So need to check whether worker is still decoding
-// ref_buf.
-void vp9_frameworker_wait(VPxWorker *const worker, RefCntBuffer *const ref_buf,
-                          int row);
-
-// FrameWorker broadcasts its decoding progress so other workers that are
-// waiting on it can resume decoding.
-void vp9_frameworker_broadcast(RefCntBuffer *const buf, int row);
-
-// Copy necessary decoding context from src worker to dst worker.
-void vp9_frameworker_copy_context(VPxWorker *const dst_worker,
-                                  VPxWorker *const src_worker);
-
-#ifdef __cplusplus
-}    // extern "C"
-#endif
-
-#endif  // VP9_DECODER_VP9_DTHREAD_H_
diff --git a/vp9/encoder/arm/neon/vp9_dct_neon.c b/vp9/encoder/arm/neon/vp9_dct_neon.c
deleted file mode 100644 (file)
index 11e8773..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- *  Copyright (c) 2014 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.
- */
-
-#include <arm_neon.h>
-
-#include "./vp9_rtcd.h"
-#include "./vpx_config.h"
-#include "./vpx_dsp_rtcd.h"
-
-#include "vp9/common/vp9_blockd.h"
-#include "vpx_dsp/txfm_common.h"
-
-void vp9_fdct8x8_quant_neon(const int16_t *input, int stride,
-                            int16_t* coeff_ptr, intptr_t n_coeffs,
-                            int skip_block, const int16_t* zbin_ptr,
-                            const int16_t* round_ptr, const int16_t* quant_ptr,
-                            const int16_t* quant_shift_ptr,
-                            int16_t* qcoeff_ptr, int16_t* dqcoeff_ptr,
-                            const int16_t* dequant_ptr, uint16_t* eob_ptr,
-                            const int16_t* scan_ptr,
-                            const int16_t* iscan_ptr) {
-  int16_t temp_buffer[64];
-  (void)coeff_ptr;
-
-  vpx_fdct8x8_neon(input, temp_buffer, stride);
-  vp9_quantize_fp_neon(temp_buffer, n_coeffs, skip_block, zbin_ptr, round_ptr,
-                       quant_ptr, quant_shift_ptr, qcoeff_ptr, dqcoeff_ptr,
-                       dequant_ptr, eob_ptr, scan_ptr, iscan_ptr);
-}
diff --git a/vp9/encoder/arm/neon/vp9_error_neon.c b/vp9/encoder/arm/neon/vp9_error_neon.c
deleted file mode 100644 (file)
index 1c75031..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- *  Copyright (c) 2015 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.
- */
-
-#include <arm_neon.h>
-#include <assert.h>
-
-#include "./vp9_rtcd.h"
-
-int64_t vp9_block_error_fp_neon(const int16_t *coeff, const int16_t *dqcoeff,
-                                int block_size) {
-  int64x2_t error = vdupq_n_s64(0);
-
-  assert(block_size >= 8);
-  assert((block_size % 8) == 0);
-
-  do {
-    const int16x8_t c = vld1q_s16(coeff);
-    const int16x8_t d = vld1q_s16(dqcoeff);
-    const int16x8_t diff = vsubq_s16(c, d);
-    const int16x4_t diff_lo = vget_low_s16(diff);
-    const int16x4_t diff_hi = vget_high_s16(diff);
-    // diff is 15-bits, the squares 30, so we can store 2 in 31-bits before
-    // accumulating them in 64-bits.
-    const int32x4_t err0 = vmull_s16(diff_lo, diff_lo);
-    const int32x4_t err1 = vmlal_s16(err0, diff_hi, diff_hi);
-    const int64x2_t err2 = vaddl_s32(vget_low_s32(err1), vget_high_s32(err1));
-    error = vaddq_s64(error, err2);
-    coeff += 8;
-    dqcoeff += 8;
-    block_size -= 8;
-  } while (block_size != 0);
-
-  return vgetq_lane_s64(error, 0) + vgetq_lane_s64(error, 1);
-}
diff --git a/vp9/encoder/arm/neon/vp9_quantize_neon.c b/vp9/encoder/arm/neon/vp9_quantize_neon.c
deleted file mode 100644 (file)
index 47363c7..0000000
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- *  Copyright (c) 2014 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.
- */
-
-#include <arm_neon.h>
-
-#include <math.h>
-
-#include "vpx_mem/vpx_mem.h"
-
-#include "vp9/common/vp9_quant_common.h"
-#include "vp9/common/vp9_seg_common.h"
-
-#include "vp9/encoder/vp9_encoder.h"
-#include "vp9/encoder/vp9_quantize.h"
-#include "vp9/encoder/vp9_rd.h"
-
-void vp9_quantize_fp_neon(const int16_t *coeff_ptr, intptr_t count,
-                          int skip_block, const int16_t *zbin_ptr,
-                          const int16_t *round_ptr, const int16_t *quant_ptr,
-                          const int16_t *quant_shift_ptr, int16_t *qcoeff_ptr,
-                          int16_t *dqcoeff_ptr, const int16_t *dequant_ptr,
-                          uint16_t *eob_ptr,
-                          const int16_t *scan, const int16_t *iscan) {
-  // TODO(jingning) Decide the need of these arguments after the
-  // quantization process is completed.
-  (void)zbin_ptr;
-  (void)quant_shift_ptr;
-  (void)scan;
-
-  if (!skip_block) {
-    // Quantization pass: All coefficients with index >= zero_flag are
-    // skippable. Note: zero_flag can be zero.
-    int i;
-    const int16x8_t v_zero = vdupq_n_s16(0);
-    const int16x8_t v_one = vdupq_n_s16(1);
-    int16x8_t v_eobmax_76543210 = vdupq_n_s16(-1);
-    int16x8_t v_round = vmovq_n_s16(round_ptr[1]);
-    int16x8_t v_quant = vmovq_n_s16(quant_ptr[1]);
-    int16x8_t v_dequant = vmovq_n_s16(dequant_ptr[1]);
-    // adjust for dc
-    v_round = vsetq_lane_s16(round_ptr[0], v_round, 0);
-    v_quant = vsetq_lane_s16(quant_ptr[0], v_quant, 0);
-    v_dequant = vsetq_lane_s16(dequant_ptr[0], v_dequant, 0);
-    // process dc and the first seven ac coeffs
-    {
-      const int16x8_t v_iscan = vld1q_s16(&iscan[0]);
-      const int16x8_t v_coeff = vld1q_s16(&coeff_ptr[0]);
-      const int16x8_t v_coeff_sign = vshrq_n_s16(v_coeff, 15);
-      const int16x8_t v_tmp = vabaq_s16(v_round, v_coeff, v_zero);
-      const int32x4_t v_tmp_lo = vmull_s16(vget_low_s16(v_tmp),
-                                           vget_low_s16(v_quant));
-      const int32x4_t v_tmp_hi = vmull_s16(vget_high_s16(v_tmp),
-                                           vget_high_s16(v_quant));
-      const int16x8_t v_tmp2 = vcombine_s16(vshrn_n_s32(v_tmp_lo, 16),
-                                            vshrn_n_s32(v_tmp_hi, 16));
-      const uint16x8_t v_nz_mask = vceqq_s16(v_tmp2, v_zero);
-      const int16x8_t v_iscan_plus1 = vaddq_s16(v_iscan, v_one);
-      const int16x8_t v_nz_iscan = vbslq_s16(v_nz_mask, v_zero, v_iscan_plus1);
-      const int16x8_t v_qcoeff_a = veorq_s16(v_tmp2, v_coeff_sign);
-      const int16x8_t v_qcoeff = vsubq_s16(v_qcoeff_a, v_coeff_sign);
-      const int16x8_t v_dqcoeff = vmulq_s16(v_qcoeff, v_dequant);
-      v_eobmax_76543210 = vmaxq_s16(v_eobmax_76543210, v_nz_iscan);
-      vst1q_s16(&qcoeff_ptr[0], v_qcoeff);
-      vst1q_s16(&dqcoeff_ptr[0], v_dqcoeff);
-      v_round = vmovq_n_s16(round_ptr[1]);
-      v_quant = vmovq_n_s16(quant_ptr[1]);
-      v_dequant = vmovq_n_s16(dequant_ptr[1]);
-    }
-    // now process the rest of the ac coeffs
-    for (i = 8; i < count; i += 8) {
-      const int16x8_t v_iscan = vld1q_s16(&iscan[i]);
-      const int16x8_t v_coeff = vld1q_s16(&coeff_ptr[i]);
-      const int16x8_t v_coeff_sign = vshrq_n_s16(v_coeff, 15);
-      const int16x8_t v_tmp = vabaq_s16(v_round, v_coeff, v_zero);
-      const int32x4_t v_tmp_lo = vmull_s16(vget_low_s16(v_tmp),
-                                           vget_low_s16(v_quant));
-      const int32x4_t v_tmp_hi = vmull_s16(vget_high_s16(v_tmp),
-                                           vget_high_s16(v_quant));
-      const int16x8_t v_tmp2 = vcombine_s16(vshrn_n_s32(v_tmp_lo, 16),
-                                            vshrn_n_s32(v_tmp_hi, 16));
-      const uint16x8_t v_nz_mask = vceqq_s16(v_tmp2, v_zero);
-      const int16x8_t v_iscan_plus1 = vaddq_s16(v_iscan, v_one);
-      const int16x8_t v_nz_iscan = vbslq_s16(v_nz_mask, v_zero, v_iscan_plus1);
-      const int16x8_t v_qcoeff_a = veorq_s16(v_tmp2, v_coeff_sign);
-      const int16x8_t v_qcoeff = vsubq_s16(v_qcoeff_a, v_coeff_sign);
-      const int16x8_t v_dqcoeff = vmulq_s16(v_qcoeff, v_dequant);
-      v_eobmax_76543210 = vmaxq_s16(v_eobmax_76543210, v_nz_iscan);
-      vst1q_s16(&qcoeff_ptr[i], v_qcoeff);
-      vst1q_s16(&dqcoeff_ptr[i], v_dqcoeff);
-    }
-    {
-      const int16x4_t v_eobmax_3210 =
-          vmax_s16(vget_low_s16(v_eobmax_76543210),
-                   vget_high_s16(v_eobmax_76543210));
-      const int64x1_t v_eobmax_xx32 =
-          vshr_n_s64(vreinterpret_s64_s16(v_eobmax_3210), 32);
-      const int16x4_t v_eobmax_tmp =
-          vmax_s16(v_eobmax_3210, vreinterpret_s16_s64(v_eobmax_xx32));
-      const int64x1_t v_eobmax_xxx3 =
-          vshr_n_s64(vreinterpret_s64_s16(v_eobmax_tmp), 16);
-      const int16x4_t v_eobmax_final =
-          vmax_s16(v_eobmax_tmp, vreinterpret_s16_s64(v_eobmax_xxx3));
-
-      *eob_ptr = (uint16_t)vget_lane_s16(v_eobmax_final, 0);
-    }
-  } else {
-    memset(qcoeff_ptr, 0, count * sizeof(int16_t));
-    memset(dqcoeff_ptr, 0, count * sizeof(int16_t));
-    *eob_ptr = 0;
-  }
-}
diff --git a/vp9/encoder/mips/msa/vp9_error_msa.c b/vp9/encoder/mips/msa/vp9_error_msa.c
deleted file mode 100644 (file)
index 1dc70bd..0000000
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- *  Copyright (c) 2015 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.
- */
-
-#include "./vp9_rtcd.h"
-#include "vpx_dsp/mips/macros_msa.h"
-
-#define BLOCK_ERROR_BLOCKSIZE_MSA(BSize)                                   \
-static int64_t block_error_##BSize##size_msa(const int16_t *coeff_ptr,     \
-                                             const int16_t *dq_coeff_ptr,  \
-                                             int64_t *ssz) {               \
-  int64_t err = 0;                                                         \
-  uint32_t loop_cnt;                                                       \
-  v8i16 coeff, dq_coeff, coeff_r_h, coeff_l_h;                             \
-  v4i32 diff_r, diff_l, coeff_r_w, coeff_l_w;                              \
-  v2i64 sq_coeff_r, sq_coeff_l;                                            \
-  v2i64 err0, err_dup0, err1, err_dup1;                                    \
-                                                                           \
-  coeff = LD_SH(coeff_ptr);                                                \
-  dq_coeff = LD_SH(dq_coeff_ptr);                                          \
-  UNPCK_SH_SW(coeff, coeff_r_w, coeff_l_w);                                \
-  ILVRL_H2_SH(coeff, dq_coeff, coeff_r_h, coeff_l_h);                      \
-  HSUB_UH2_SW(coeff_r_h, coeff_l_h, diff_r, diff_l);                       \
-  DOTP_SW2_SD(coeff_r_w, coeff_l_w, coeff_r_w, coeff_l_w,                  \
-              sq_coeff_r, sq_coeff_l);                                     \
-  DOTP_SW2_SD(diff_r, diff_l, diff_r, diff_l, err0, err1);                 \
-                                                                           \
-  coeff = LD_SH(coeff_ptr + 8);                                            \
-  dq_coeff = LD_SH(dq_coeff_ptr + 8);                                      \
-  UNPCK_SH_SW(coeff, coeff_r_w, coeff_l_w);                                \
-  ILVRL_H2_SH(coeff, dq_coeff, coeff_r_h, coeff_l_h);                      \
-  HSUB_UH2_SW(coeff_r_h, coeff_l_h, diff_r, diff_l);                       \
-  DPADD_SD2_SD(coeff_r_w, coeff_l_w, sq_coeff_r, sq_coeff_l);              \
-  DPADD_SD2_SD(diff_r, diff_l, err0, err1);                                \
-                                                                           \
-  coeff_ptr += 16;                                                         \
-  dq_coeff_ptr += 16;                                                      \
-                                                                           \
-  for (loop_cnt = ((BSize >> 4) - 1); loop_cnt--;) {                       \
-    coeff = LD_SH(coeff_ptr);                                              \
-    dq_coeff = LD_SH(dq_coeff_ptr);                                        \
-    UNPCK_SH_SW(coeff, coeff_r_w, coeff_l_w);                              \
-    ILVRL_H2_SH(coeff, dq_coeff, coeff_r_h, coeff_l_h);                    \
-    HSUB_UH2_SW(coeff_r_h, coeff_l_h, diff_r, diff_l);                     \
-    DPADD_SD2_SD(coeff_r_w, coeff_l_w, sq_coeff_r, sq_coeff_l);            \
-    DPADD_SD2_SD(diff_r, diff_l, err0, err1);                              \
-                                                                           \
-    coeff = LD_SH(coeff_ptr + 8);                                          \
-    dq_coeff = LD_SH(dq_coeff_ptr + 8);                                    \
-    UNPCK_SH_SW(coeff, coeff_r_w, coeff_l_w);                              \
-    ILVRL_H2_SH(coeff, dq_coeff, coeff_r_h, coeff_l_h);                    \
-    HSUB_UH2_SW(coeff_r_h, coeff_l_h, diff_r, diff_l);                     \
-    DPADD_SD2_SD(coeff_r_w, coeff_l_w, sq_coeff_r, sq_coeff_l);            \
-    DPADD_SD2_SD(diff_r, diff_l, err0, err1);                              \
-                                                                           \
-    coeff_ptr += 16;                                                       \
-    dq_coeff_ptr += 16;                                                    \
-  }                                                                        \
-                                                                           \
-  err_dup0 = __msa_splati_d(sq_coeff_r, 1);                                \
-  err_dup1 = __msa_splati_d(sq_coeff_l, 1);                                \
-  sq_coeff_r += err_dup0;                                                  \
-  sq_coeff_l += err_dup1;                                                  \
-  *ssz = __msa_copy_s_d(sq_coeff_r, 0);                                    \
-  *ssz += __msa_copy_s_d(sq_coeff_l, 0);                                   \
-                                                                           \
-  err_dup0 = __msa_splati_d(err0, 1);                                      \
-  err_dup1 = __msa_splati_d(err1, 1);                                      \
-  err0 += err_dup0;                                                        \
-  err1 += err_dup1;                                                        \
-  err = __msa_copy_s_d(err0, 0);                                           \
-  err += __msa_copy_s_d(err1, 0);                                          \
-                                                                           \
-  return err;                                                              \
-}
-
-BLOCK_ERROR_BLOCKSIZE_MSA(16);
-BLOCK_ERROR_BLOCKSIZE_MSA(64);
-BLOCK_ERROR_BLOCKSIZE_MSA(256);
-BLOCK_ERROR_BLOCKSIZE_MSA(1024);
-
-int64_t vp9_block_error_msa(const tran_low_t *coeff_ptr,
-                            const tran_low_t *dq_coeff_ptr,
-                            intptr_t blk_size, int64_t *ssz) {
-  int64_t err;
-  const int16_t *coeff = (const int16_t *)coeff_ptr;
-  const int16_t *dq_coeff = (const int16_t *)dq_coeff_ptr;
-
-  switch (blk_size) {
-    case 16:
-      err = block_error_16size_msa(coeff, dq_coeff, ssz);
-      break;
-    case 64:
-      err = block_error_64size_msa(coeff, dq_coeff, ssz);
-      break;
-    case 256:
-      err = block_error_256size_msa(coeff, dq_coeff, ssz);
-      break;
-    case 1024:
-      err = block_error_1024size_msa(coeff, dq_coeff, ssz);
-      break;
-    default:
-      err = vp9_block_error_c(coeff_ptr, dq_coeff_ptr, blk_size, ssz);
-      break;
-  }
-
-  return err;
-}
diff --git a/vp9/encoder/mips/msa/vp9_fdct16x16_msa.c b/vp9/encoder/mips/msa/vp9_fdct16x16_msa.c
deleted file mode 100644 (file)
index 6dabb58..0000000
+++ /dev/null
@@ -1,507 +0,0 @@
-/*
- *  Copyright (c) 2015 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.
- */
-
-#include <assert.h>
-
-#include "vp9/common/vp9_enums.h"
-#include "vp9/encoder/mips/msa/vp9_fdct_msa.h"
-#include "vpx_dsp/mips/fwd_txfm_msa.h"
-
-static void fadst16_cols_step1_msa(const int16_t *input, int32_t stride,
-                                   const int32_t *const0, int16_t *int_buf) {
-  v8i16 r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r13, r14, r15;
-  v8i16 tp0, tp1, tp2, tp3, g0, g1, g2, g3, g8, g9, g10, g11, h0, h1, h2, h3;
-  v4i32 k0, k1, k2, k3;
-
-  /* load input data */
-  r0 = LD_SH(input);
-  r15 = LD_SH(input + 15 * stride);
-  r7 = LD_SH(input + 7 * stride);
-  r8 = LD_SH(input + 8 * stride);
-  SLLI_4V(r0, r15, r7, r8, 2);
-
-  /* stage 1 */
-  LD_SW2(const0, 4, k0, k1);
-  LD_SW2(const0 + 8, 4, k2, k3);
-  MADD_BF(r15, r0, r7, r8, k0, k1, k2, k3, g0, g1, g2, g3);
-
-  r3 = LD_SH(input + 3 * stride);
-  r4 = LD_SH(input + 4 * stride);
-  r11 = LD_SH(input + 11 * stride);
-  r12 = LD_SH(input + 12 * stride);
-  SLLI_4V(r3, r4, r11, r12, 2);
-
-  LD_SW2(const0 + 4 * 4, 4, k0, k1);
-  LD_SW2(const0 + 4 * 6, 4, k2, k3);
-  MADD_BF(r11, r4, r3, r12, k0, k1, k2, k3, g8, g9, g10, g11);
-
-  /* stage 2 */
-  BUTTERFLY_4(g0, g2, g10, g8, tp0, tp2, tp3, tp1);
-  ST_SH2(tp0, tp2, int_buf, 8);
-  ST_SH2(tp1, tp3, int_buf + 4 * 8, 8);
-
-  LD_SW2(const0 + 4 * 8, 4, k0, k1);
-  k2 = LD_SW(const0 + 4 * 10);
-  MADD_BF(g1, g3, g9, g11, k0, k1, k2, k0, h0, h1, h2, h3);
-
-  ST_SH2(h0, h1, int_buf + 8 * 8, 8);
-  ST_SH2(h3, h2, int_buf + 12 * 8, 8);
-
-  r9 = LD_SH(input + 9 * stride);
-  r6 = LD_SH(input + 6 * stride);
-  r1 = LD_SH(input + stride);
-  r14 = LD_SH(input + 14 * stride);
-  SLLI_4V(r9, r6, r1, r14, 2);
-
-  LD_SW2(const0 + 4 * 11, 4, k0, k1);
-  LD_SW2(const0 + 4 * 13, 4, k2, k3);
-  MADD_BF(r9, r6, r1, r14, k0, k1, k2, k3, g0, g1, g2, g3);
-
-  ST_SH2(g1, g3, int_buf + 3 * 8, 4 * 8);
-
-  r13 = LD_SH(input + 13 * stride);
-  r2 = LD_SH(input + 2 * stride);
-  r5 = LD_SH(input + 5 * stride);
-  r10 = LD_SH(input + 10 * stride);
-  SLLI_4V(r13, r2, r5, r10, 2);
-
-  LD_SW2(const0 + 4 * 15, 4, k0, k1);
-  LD_SW2(const0 + 4 * 17, 4, k2, k3);
-  MADD_BF(r13, r2, r5, r10, k0, k1, k2, k3, h0, h1, h2, h3);
-
-  ST_SH2(h1, h3, int_buf + 11 * 8, 4 * 8);
-
-  BUTTERFLY_4(h0, h2, g2, g0, tp0, tp1, tp2, tp3);
-  ST_SH4(tp0, tp1, tp2, tp3, int_buf + 2 * 8, 4 * 8);
-}
-
-static void fadst16_cols_step2_msa(int16_t *int_buf, const int32_t *const0,
-                                   int16_t *out) {
-  int16_t *out_ptr = out + 128;
-  v8i16 tp0, tp1, tp2, tp3, g5, g7, g13, g15;
-  v8i16 h0, h1, h2, h3, h4, h5, h6, h7, h10, h11;
-  v8i16 out0, out1, out2, out3, out4, out5, out6, out7;
-  v8i16 out8, out9, out10, out11, out12, out13, out14, out15;
-  v4i32 k0, k1, k2, k3;
-
-  LD_SH2(int_buf + 3 * 8, 4 * 8, g13, g15);
-  LD_SH2(int_buf + 11 * 8, 4 * 8, g5, g7);
-  LD_SW2(const0 + 4 * 19, 4, k0, k1);
-  k2 = LD_SW(const0 + 4 * 21);
-  MADD_BF(g7, g5, g15, g13, k0, k1, k2, k0, h4, h5, h6, h7);
-
-  tp0 = LD_SH(int_buf + 4 * 8);
-  tp1 = LD_SH(int_buf + 5 * 8);
-  tp3 = LD_SH(int_buf + 10 * 8);
-  tp2 = LD_SH(int_buf + 14 * 8);
-  LD_SW2(const0 + 4 * 22, 4, k0, k1);
-  k2 = LD_SW(const0 + 4 * 24);
-  MADD_BF(tp0, tp1, tp2, tp3, k0, k1, k2, k0, out4, out6, out5, out7);
-  out4 = -out4;
-  ST_SH(out4, (out + 3 * 16));
-  ST_SH(out5, (out_ptr + 4 * 16));
-
-  h1 = LD_SH(int_buf + 9 * 8);
-  h3 = LD_SH(int_buf + 12 * 8);
-  MADD_BF(h1, h3, h5, h7, k0, k1, k2, k0, out12, out14, out13, out15);
-  out13 = -out13;
-  ST_SH(out12, (out + 2 * 16));
-  ST_SH(out13, (out_ptr + 5 * 16));
-
-  tp0 = LD_SH(int_buf);
-  tp1 = LD_SH(int_buf + 8);
-  tp2 = LD_SH(int_buf + 2 * 8);
-  tp3 = LD_SH(int_buf + 6 * 8);
-
-  BUTTERFLY_4(tp0, tp1, tp3, tp2, out0, out1, h11, h10);
-  out1 = -out1;
-  ST_SH(out0, (out));
-  ST_SH(out1, (out_ptr + 7 * 16));
-
-  h0 = LD_SH(int_buf + 8 * 8);
-  h2 = LD_SH(int_buf + 13 * 8);
-
-  BUTTERFLY_4(h0, h2, h6, h4, out8, out9, out11, out10);
-  out8 = -out8;
-  ST_SH(out8, (out + 16));
-  ST_SH(out9, (out_ptr + 6 * 16));
-
-  /* stage 4 */
-  LD_SW2(const0 + 4 * 25, 4, k0, k1);
-  LD_SW2(const0 + 4 * 27, 4, k2, k3);
-  MADD_SHORT(h10, h11, k1, k2, out2, out3);
-  ST_SH(out2, (out + 7 * 16));
-  ST_SH(out3, (out_ptr));
-
-  MADD_SHORT(out6, out7, k0, k3, out6, out7);
-  ST_SH(out6, (out + 4 * 16));
-  ST_SH(out7, (out_ptr + 3 * 16));
-
-  MADD_SHORT(out10, out11, k0, k3, out10, out11);
-  ST_SH(out10, (out + 6 * 16));
-  ST_SH(out11, (out_ptr + 16));
-
-  MADD_SHORT(out14, out15, k1, k2, out14, out15);
-  ST_SH(out14, (out + 5 * 16));
-  ST_SH(out15, (out_ptr + 2 * 16));
-}
-
-static void fadst16_transpose_postproc_msa(int16_t *input, int16_t *out) {
-  v8i16 r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r13, r14, r15;
-  v8i16 l0, l1, l2, l3, l4, l5, l6, l7, l8, l9, l10, l11, l12, l13, l14, l15;
-
-  /* load input data */
-  LD_SH8(input, 16, l0, l1, l2, l3, l4, l5, l6, l7);
-  TRANSPOSE8x8_SH_SH(l0, l1, l2, l3, l4, l5, l6, l7,
-                     r0, r1, r2, r3, r4, r5, r6, r7);
-  FDCT_POSTPROC_2V_NEG_H(r0, r1);
-  FDCT_POSTPROC_2V_NEG_H(r2, r3);
-  FDCT_POSTPROC_2V_NEG_H(r4, r5);
-  FDCT_POSTPROC_2V_NEG_H(r6, r7);
-  ST_SH8(r0, r1, r2, r3, r4, r5, r6, r7, out, 8);
-  out += 64;
-
-  LD_SH8(input + 8, 16, l8, l9, l10, l11, l12, l13, l14, l15);
-  TRANSPOSE8x8_SH_SH(l8, l9, l10, l11, l12, l13, l14, l15,
-                     r8, r9, r10, r11, r12, r13, r14, r15);
-  FDCT_POSTPROC_2V_NEG_H(r8, r9);
-  FDCT_POSTPROC_2V_NEG_H(r10, r11);
-  FDCT_POSTPROC_2V_NEG_H(r12, r13);
-  FDCT_POSTPROC_2V_NEG_H(r14, r15);
-  ST_SH8(r8, r9, r10, r11, r12, r13, r14, r15, out, 8);
-  out += 64;
-
-  /* load input data */
-  input += 128;
-  LD_SH8(input, 16, l0, l1, l2, l3, l4, l5, l6, l7);
-  TRANSPOSE8x8_SH_SH(l0, l1, l2, l3, l4, l5, l6, l7,
-                     r0, r1, r2, r3, r4, r5, r6, r7);
-  FDCT_POSTPROC_2V_NEG_H(r0, r1);
-  FDCT_POSTPROC_2V_NEG_H(r2, r3);
-  FDCT_POSTPROC_2V_NEG_H(r4, r5);
-  FDCT_POSTPROC_2V_NEG_H(r6, r7);
-  ST_SH8(r0, r1, r2, r3, r4, r5, r6, r7, out, 8);
-  out += 64;
-
-  LD_SH8(input + 8, 16, l8, l9, l10, l11, l12, l13, l14, l15);
-  TRANSPOSE8x8_SH_SH(l8, l9, l10, l11, l12, l13, l14, l15,
-                     r8, r9, r10, r11, r12, r13, r14, r15);
-  FDCT_POSTPROC_2V_NEG_H(r8, r9);
-  FDCT_POSTPROC_2V_NEG_H(r10, r11);
-  FDCT_POSTPROC_2V_NEG_H(r12, r13);
-  FDCT_POSTPROC_2V_NEG_H(r14, r15);
-  ST_SH8(r8, r9, r10, r11, r12, r13, r14, r15, out, 8);
-}
-
-static void fadst16_rows_step1_msa(int16_t *input, const int32_t *const0,
-                                   int16_t *int_buf) {
-  v8i16 r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r13, r14, r15;
-  v8i16 tp0, tp1, tp2, tp3, g0, g1, g2, g3, g8, g9, g10, g11, h0, h1, h2, h3;
-  v4i32 k0, k1, k2, k3;
-
-  /* load input data */
-  r0 = LD_SH(input);
-  r7 = LD_SH(input + 7 * 8);
-  r8 = LD_SH(input + 8 * 8);
-  r15 = LD_SH(input + 15 * 8);
-
-  /* stage 1 */
-  LD_SW2(const0, 4, k0, k1);
-  LD_SW2(const0 + 4 * 2, 4, k2, k3);
-  MADD_BF(r15, r0, r7, r8, k0, k1, k2, k3, g0, g1, g2, g3);
-
-  r3 = LD_SH(input + 3 * 8);
-  r4 = LD_SH(input + 4 * 8);
-  r11 = LD_SH(input + 11 * 8);
-  r12 = LD_SH(input + 12 * 8);
-
-  LD_SW2(const0 + 4 * 4, 4, k0, k1);
-  LD_SW2(const0 + 4 * 6, 4, k2, k3);
-  MADD_BF(r11, r4, r3, r12, k0, k1, k2, k3, g8, g9, g10, g11);
-
-  /* stage 2 */
-  BUTTERFLY_4(g0, g2, g10, g8, tp0, tp2, tp3, tp1);
-  ST_SH2(tp0, tp1, int_buf, 4 * 8);
-  ST_SH2(tp2, tp3, int_buf + 8, 4 * 8);
-
-  LD_SW2(const0 + 4 * 8, 4, k0, k1);
-  k2 = LD_SW(const0 + 4 * 10);
-  MADD_BF(g1, g3, g9, g11, k0, k1, k2, k0, h0, h1, h2, h3);
-  ST_SH2(h0, h3, int_buf + 8 * 8, 4 * 8);
-  ST_SH2(h1, h2, int_buf + 9 * 8, 4 * 8);
-
-  r1 = LD_SH(input + 8);
-  r6 = LD_SH(input + 6 * 8);
-  r9 = LD_SH(input + 9 * 8);
-  r14 = LD_SH(input + 14 * 8);
-
-  LD_SW2(const0 + 4 * 11, 4, k0, k1);
-  LD_SW2(const0 + 4 * 13, 4, k2, k3);
-  MADD_BF(r9, r6, r1, r14, k0, k1, k2, k3, g0, g1, g2, g3);
-  ST_SH2(g1, g3, int_buf + 3 * 8, 4 * 8);
-
-  r2 = LD_SH(input + 2 * 8);
-  r5 = LD_SH(input + 5 * 8);
-  r10 = LD_SH(input + 10 * 8);
-  r13 = LD_SH(input + 13 * 8);
-
-  LD_SW2(const0 + 4 * 15, 4, k0, k1);
-  LD_SW2(const0 + 4 * 17, 4, k2, k3);
-  MADD_BF(r13, r2, r5, r10, k0, k1, k2, k3, h0, h1, h2, h3);
-  ST_SH2(h1, h3, int_buf + 11 * 8, 4 * 8);
-  BUTTERFLY_4(h0, h2, g2, g0, tp0, tp1, tp2, tp3);
-  ST_SH4(tp0, tp1, tp2, tp3, int_buf + 2 * 8, 4 * 8);
-}
-
-static void fadst16_rows_step2_msa(int16_t *int_buf, const int32_t *const0,
-                                   int16_t *out) {
-  int16_t *out_ptr = out + 8;
-  v8i16 tp0, tp1, tp2, tp3, g5, g7, g13, g15;
-  v8i16 h0, h1, h2, h3, h4, h5, h6, h7, h10, h11;
-  v8i16 out0, out1, out2, out3, out4, out5, out6, out7;
-  v8i16 out8, out9, out10, out11, out12, out13, out14, out15;
-  v4i32 k0, k1, k2, k3;
-
-  g13 = LD_SH(int_buf + 3 * 8);
-  g15 = LD_SH(int_buf + 7 * 8);
-  g5 = LD_SH(int_buf + 11 * 8);
-  g7 = LD_SH(int_buf + 15 * 8);
-
-  LD_SW2(const0 + 4 * 19, 4, k0, k1);
-  k2 = LD_SW(const0 + 4 * 21);
-  MADD_BF(g7, g5, g15, g13, k0, k1, k2, k0, h4, h5, h6, h7);
-
-  tp0 = LD_SH(int_buf + 4 * 8);
-  tp1 = LD_SH(int_buf + 5 * 8);
-  tp3 = LD_SH(int_buf + 10 * 8);
-  tp2 = LD_SH(int_buf + 14 * 8);
-
-  LD_SW2(const0 + 4 * 22, 4, k0, k1);
-  k2 = LD_SW(const0 + 4 * 24);
-  MADD_BF(tp0, tp1, tp2, tp3, k0, k1, k2, k0, out4, out6, out5, out7);
-  out4 = -out4;
-  ST_SH(out4, (out + 3 * 16));
-  ST_SH(out5, (out_ptr + 4 * 16));
-
-  h1 = LD_SH(int_buf + 9 * 8);
-  h3 = LD_SH(int_buf + 12 * 8);
-  MADD_BF(h1, h3, h5, h7, k0, k1, k2, k0, out12, out14, out13, out15);
-  out13 = -out13;
-  ST_SH(out12, (out + 2 * 16));
-  ST_SH(out13, (out_ptr + 5 * 16));
-
-  tp0 = LD_SH(int_buf);
-  tp1 = LD_SH(int_buf + 8);
-  tp2 = LD_SH(int_buf + 2 * 8);
-  tp3 = LD_SH(int_buf + 6 * 8);
-
-  BUTTERFLY_4(tp0, tp1, tp3, tp2, out0, out1, h11, h10);
-  out1 = -out1;
-  ST_SH(out0, (out));
-  ST_SH(out1, (out_ptr + 7 * 16));
-
-  h0 = LD_SH(int_buf + 8 * 8);
-  h2 = LD_SH(int_buf + 13 * 8);
-  BUTTERFLY_4(h0, h2, h6, h4, out8, out9, out11, out10);
-  out8 = -out8;
-  ST_SH(out8, (out + 16));
-  ST_SH(out9, (out_ptr + 6 * 16));
-
-  /* stage 4 */
-  LD_SW2(const0 + 4 * 25, 4, k0, k1);
-  LD_SW2(const0 + 4 * 27, 4, k2, k3);
-  MADD_SHORT(h10, h11, k1, k2, out2, out3);
-  ST_SH(out2, (out + 7 * 16));
-  ST_SH(out3, (out_ptr));
-
-  MADD_SHORT(out6, out7, k0, k3, out6, out7);
-  ST_SH(out6, (out + 4 * 16));
-  ST_SH(out7, (out_ptr + 3 * 16));
-
-  MADD_SHORT(out10, out11, k0, k3, out10, out11);
-  ST_SH(out10, (out + 6 * 16));
-  ST_SH(out11, (out_ptr + 16));
-
-  MADD_SHORT(out14, out15, k1, k2, out14, out15);
-  ST_SH(out14, (out + 5 * 16));
-  ST_SH(out15, (out_ptr + 2 * 16));
-}
-
-static void fadst16_transpose_msa(int16_t *input, int16_t *out) {
-  v8i16 r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r13, r14, r15;
-  v8i16 l0, l1, l2, l3, l4, l5, l6, l7, l8, l9, l10, l11, l12, l13, l14, l15;
-
-  /* load input data */
-  LD_SH16(input, 8, l0, l8, l1, l9, l2, l10, l3, l11,
-          l4, l12, l5, l13, l6, l14, l7, l15);
-  TRANSPOSE8x8_SH_SH(l0, l1, l2, l3, l4, l5, l6, l7,
-                     r0, r1, r2, r3, r4, r5, r6, r7);
-  TRANSPOSE8x8_SH_SH(l8, l9, l10, l11, l12, l13, l14, l15,
-                     r8, r9, r10, r11, r12, r13, r14, r15);
-  ST_SH8(r0, r8, r1, r9, r2, r10, r3, r11, out, 8);
-  ST_SH8(r4, r12, r5, r13, r6, r14, r7, r15, (out + 64), 8);
-  out += 16 * 8;
-
-  /* load input data */
-  input += 128;
-  LD_SH16(input, 8, l0, l8, l1, l9, l2, l10, l3, l11,
-          l4, l12, l5, l13, l6, l14, l7, l15);
-  TRANSPOSE8x8_SH_SH(l0, l1, l2, l3, l4, l5, l6, l7,
-                     r0, r1, r2, r3, r4, r5, r6, r7);
-  TRANSPOSE8x8_SH_SH(l8, l9, l10, l11, l12, l13, l14, l15,
-                     r8, r9, r10, r11, r12, r13, r14, r15);
-  ST_SH8(r0, r8, r1, r9, r2, r10, r3, r11, out, 8);
-  ST_SH8(r4, r12, r5, r13, r6, r14, r7, r15, (out + 64), 8);
-}
-
-static void postproc_fdct16x8_1d_row(int16_t *intermediate, int16_t *output) {
-  int16_t *temp = intermediate;
-  int16_t *out = output;
-  v8i16 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
-  v8i16 in0, in1, in2, in3, in4, in5, in6, in7, in8, in9, in10, in11;
-  v8i16 in12, in13, in14, in15;
-
-  LD_SH8(temp, 16, in0, in1, in2, in3, in4, in5, in6, in7);
-  temp = intermediate + 8;
-  LD_SH8(temp, 16, in8, in9, in10, in11, in12, in13, in14, in15);
-  TRANSPOSE8x8_SH_SH(in0, in1, in2, in3, in4, in5, in6, in7,
-                     in0, in1, in2, in3, in4, in5, in6, in7);
-  TRANSPOSE8x8_SH_SH(in8, in9, in10, in11, in12, in13, in14, in15,
-                     in8, in9, in10, in11, in12, in13, in14, in15);
-  FDCT_POSTPROC_2V_NEG_H(in0, in1);
-  FDCT_POSTPROC_2V_NEG_H(in2, in3);
-  FDCT_POSTPROC_2V_NEG_H(in4, in5);
-  FDCT_POSTPROC_2V_NEG_H(in6, in7);
-  FDCT_POSTPROC_2V_NEG_H(in8, in9);
-  FDCT_POSTPROC_2V_NEG_H(in10, in11);
-  FDCT_POSTPROC_2V_NEG_H(in12, in13);
-  FDCT_POSTPROC_2V_NEG_H(in14, in15);
-  BUTTERFLY_16(in0, in1, in2, in3, in4, in5, in6, in7,
-               in8, in9, in10, in11, in12, in13, in14, in15,
-               tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7,
-               in8, in9, in10, in11, in12, in13, in14, in15);
-  temp = intermediate;
-  ST_SH8(in8, in9, in10, in11, in12, in13, in14, in15, temp, 16);
-  FDCT8x16_EVEN(tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7,
-                tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7);
-  temp = intermediate;
-  LD_SH8(temp, 16, in8, in9, in10, in11, in12, in13, in14, in15);
-  FDCT8x16_ODD(in8, in9, in10, in11, in12, in13, in14, in15,
-               in0, in1, in2, in3, in4, in5, in6, in7);
-  TRANSPOSE8x8_SH_SH(tmp0, in0, tmp1, in1, tmp2, in2, tmp3, in3,
-                     tmp0, in0, tmp1, in1, tmp2, in2, tmp3, in3);
-  ST_SH8(tmp0, in0, tmp1, in1, tmp2, in2, tmp3, in3, out, 16);
-  TRANSPOSE8x8_SH_SH(tmp4, in4, tmp5, in5, tmp6, in6, tmp7, in7,
-                     tmp4, in4, tmp5, in5, tmp6, in6, tmp7, in7);
-  out = output + 8;
-  ST_SH8(tmp4, in4, tmp5, in5, tmp6, in6, tmp7, in7, out, 16);
-}
-
-void vp9_fht16x16_msa(const int16_t *input, int16_t *output,
-                      int32_t stride, int32_t tx_type) {
-  DECLARE_ALIGNED(32, int16_t, tmp[256]);
-  DECLARE_ALIGNED(32, int16_t, trans_buf[256]);
-  DECLARE_ALIGNED(32, int16_t, tmp_buf[128]);
-  int32_t i;
-  int16_t *ptmpbuf = &tmp_buf[0];
-  int16_t *trans = &trans_buf[0];
-  const int32_t const_arr[29 * 4] = {
-    52707308, 52707308, 52707308, 52707308,
-    -1072430300, -1072430300, -1072430300, -1072430300,
-    795618043, 795618043, 795618043, 795618043,
-    -721080468, -721080468, -721080468, -721080468,
-    459094491, 459094491, 459094491, 459094491,
-    -970646691, -970646691, -970646691, -970646691,
-    1010963856, 1010963856, 1010963856, 1010963856,
-    -361743294, -361743294, -361743294, -361743294,
-    209469125, 209469125, 209469125, 209469125,
-    -1053094788, -1053094788, -1053094788, -1053094788,
-    1053160324, 1053160324, 1053160324, 1053160324,
-    639644520, 639644520, 639644520, 639644520,
-    -862444000, -862444000, -862444000, -862444000,
-    1062144356, 1062144356, 1062144356, 1062144356,
-    -157532337, -157532337, -157532337, -157532337,
-    260914709, 260914709, 260914709, 260914709,
-    -1041559667, -1041559667, -1041559667, -1041559667,
-    920985831, 920985831, 920985831, 920985831,
-    -551995675, -551995675, -551995675, -551995675,
-    596522295, 596522295, 596522295, 596522295,
-    892853362, 892853362, 892853362, 892853362,
-    -892787826, -892787826, -892787826, -892787826,
-    410925857, 410925857, 410925857, 410925857,
-    -992012162, -992012162, -992012162, -992012162,
-    992077698, 992077698, 992077698, 992077698,
-    759246145, 759246145, 759246145, 759246145,
-    -759180609, -759180609, -759180609, -759180609,
-    -759222975, -759222975, -759222975, -759222975,
-    759288511, 759288511, 759288511, 759288511 };
-
-  switch (tx_type) {
-    case DCT_DCT:
-      /* column transform */
-      for (i = 0; i < 2; ++i) {
-        fdct8x16_1d_column(input + 8 * i, tmp + 8 * i, stride);
-      }
-
-      /* row transform */
-      for (i = 0; i < 2; ++i) {
-        fdct16x8_1d_row(tmp + (128 * i), output + (128 * i));
-      }
-      break;
-    case ADST_DCT:
-      /* column transform */
-      for (i = 0; i < 2; ++i) {
-        fadst16_cols_step1_msa(input + (i << 3), stride, const_arr, ptmpbuf);
-        fadst16_cols_step2_msa(ptmpbuf, const_arr, tmp + (i << 3));
-      }
-
-      /* row transform */
-      for (i = 0; i < 2; ++i) {
-        postproc_fdct16x8_1d_row(tmp + (128 * i), output + (128 * i));
-      }
-      break;
-    case DCT_ADST:
-      /* column transform */
-      for (i = 0; i < 2; ++i) {
-        fdct8x16_1d_column(input + 8 * i, tmp + 8 * i, stride);
-      }
-
-      fadst16_transpose_postproc_msa(tmp, trans);
-
-      /* row transform */
-      for (i = 0; i < 2; ++i) {
-        fadst16_rows_step1_msa(trans + (i << 7), const_arr, ptmpbuf);
-        fadst16_rows_step2_msa(ptmpbuf, const_arr, tmp + (i << 7));
-      }
-
-      fadst16_transpose_msa(tmp, output);
-      break;
-    case ADST_ADST:
-      /* column transform */
-      for (i = 0; i < 2; ++i) {
-        fadst16_cols_step1_msa(input + (i << 3), stride, const_arr, ptmpbuf);
-        fadst16_cols_step2_msa(ptmpbuf, const_arr, tmp + (i << 3));
-      }
-
-      fadst16_transpose_postproc_msa(tmp, trans);
-
-      /* row transform */
-      for (i = 0; i < 2; ++i) {
-        fadst16_rows_step1_msa(trans + (i << 7), const_arr, ptmpbuf);
-        fadst16_rows_step2_msa(ptmpbuf, const_arr, tmp + (i << 7));
-      }
-
-      fadst16_transpose_msa(tmp, output);
-      break;
-    default:
-      assert(0);
-      break;
-  }
-}
diff --git a/vp9/encoder/mips/msa/vp9_fdct4x4_msa.c b/vp9/encoder/mips/msa/vp9_fdct4x4_msa.c
deleted file mode 100644 (file)
index 574016f..0000000
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- *  Copyright (c) 2015 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.
- */
-
-#include <assert.h>
-
-#include "vp9/common/vp9_enums.h"
-#include "vp9/encoder/mips/msa/vp9_fdct_msa.h"
-
-void vp9_fwht4x4_msa(const int16_t *input, int16_t *output,
-                     int32_t src_stride) {
-  v8i16 in0, in1, in2, in3, in4;
-
-  LD_SH4(input, src_stride, in0, in1, in2, in3);
-
-  in0 += in1;
-  in3 -= in2;
-  in4 = (in0 - in3) >> 1;
-  SUB2(in4, in1, in4, in2, in1, in2);
-  in0 -= in2;
-  in3 += in1;
-
-  TRANSPOSE4x4_SH_SH(in0, in2, in3, in1, in0, in2, in3, in1);
-
-  in0 += in2;
-  in1 -= in3;
-  in4 = (in0 - in1) >> 1;
-  SUB2(in4, in2, in4, in3, in2, in3);
-  in0 -= in3;
-  in1 += in2;
-
-  SLLI_4V(in0, in1, in2, in3, 2);
-
-  TRANSPOSE4x4_SH_SH(in0, in3, in1, in2, in0, in3, in1, in2);
-
-  ST4x2_UB(in0, output, 4);
-  ST4x2_UB(in3, output + 4, 4);
-  ST4x2_UB(in1, output + 8, 4);
-  ST4x2_UB(in2, output + 12, 4);
-}
-
-void vp9_fht4x4_msa(const int16_t *input, int16_t *output, int32_t stride,
-                    int32_t tx_type) {
-  v8i16 in0, in1, in2, in3;
-
-  LD_SH4(input, stride, in0, in1, in2, in3);
-
-  /* fdct4 pre-process */
-  {
-    v8i16 temp, mask;
-    v16i8 zero = { 0 };
-    v16i8 one = __msa_ldi_b(1);
-
-    mask = (v8i16)__msa_sldi_b(zero, one, 15);
-    SLLI_4V(in0, in1, in2, in3, 4);
-    temp = __msa_ceqi_h(in0, 0);
-    temp = (v8i16)__msa_xori_b((v16u8)temp, 255);
-    temp = mask & temp;
-    in0 += temp;
-  }
-
-  switch (tx_type) {
-    case DCT_DCT:
-      VP9_FDCT4(in0, in1, in2, in3, in0, in1, in2, in3);
-      TRANSPOSE4x4_SH_SH(in0, in1, in2, in3, in0, in1, in2, in3);
-      VP9_FDCT4(in0, in1, in2, in3, in0, in1, in2, in3);
-      break;
-    case ADST_DCT:
-      VP9_FADST4(in0, in1, in2, in3, in0, in1, in2, in3);
-      TRANSPOSE4x4_SH_SH(in0, in1, in2, in3, in0, in1, in2, in3);
-      VP9_FDCT4(in0, in1, in2, in3, in0, in1, in2, in3);
-      break;
-    case DCT_ADST:
-      VP9_FDCT4(in0, in1, in2, in3, in0, in1, in2, in3);
-      TRANSPOSE4x4_SH_SH(in0, in1, in2, in3, in0, in1, in2, in3);
-      VP9_FADST4(in0, in1, in2, in3, in0, in1, in2, in3);
-      break;
-    case ADST_ADST:
-      VP9_FADST4(in0, in1, in2, in3, in0, in1, in2, in3);
-      TRANSPOSE4x4_SH_SH(in0, in1, in2, in3, in0, in1, in2, in3);
-      VP9_FADST4(in0, in1, in2, in3, in0, in1, in2, in3);
-      break;
-    default:
-      assert(0);
-      break;
-  }
-
-  TRANSPOSE4x4_SH_SH(in0, in1, in2, in3, in0, in1, in2, in3);
-  ADD4(in0, 1, in1, 1, in2, 1, in3, 1, in0, in1, in2, in3);
-  SRA_4V(in0, in1, in2, in3, 2);
-  PCKEV_D2_SH(in1, in0, in3, in2, in0, in2);
-  ST_SH2(in0, in2, output, 8);
-}
diff --git a/vp9/encoder/mips/msa/vp9_fdct8x8_msa.c b/vp9/encoder/mips/msa/vp9_fdct8x8_msa.c
deleted file mode 100644 (file)
index 7c3c635..0000000
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- *  Copyright (c) 2015 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.
- */
-
-#include <assert.h>
-
-#include "vp9/common/vp9_enums.h"
-#include "vp9/encoder/mips/msa/vp9_fdct_msa.h"
-
-void vp9_fht8x8_msa(const int16_t *input, int16_t *output, int32_t stride,
-                    int32_t tx_type) {
-  v8i16 in0, in1, in2, in3, in4, in5, in6, in7;
-
-  LD_SH8(input, stride, in0, in1, in2, in3, in4, in5, in6, in7);
-  SLLI_4V(in0, in1, in2, in3, 2);
-  SLLI_4V(in4, in5, in6, in7, 2);
-
-  switch (tx_type) {
-    case DCT_DCT:
-      VP9_FDCT8(in0, in1, in2, in3, in4, in5, in6, in7,
-                in0, in1, in2, in3, in4, in5, in6, in7);
-      TRANSPOSE8x8_SH_SH(in0, in1, in2, in3, in4, in5, in6, in7,
-                         in0, in1, in2, in3, in4, in5, in6, in7);
-      VP9_FDCT8(in0, in1, in2, in3, in4, in5, in6, in7,
-                in0, in1, in2, in3, in4, in5, in6, in7);
-      break;
-    case ADST_DCT:
-      VP9_ADST8(in0, in1, in2, in3, in4, in5, in6, in7,
-                in0, in1, in2, in3, in4, in5, in6, in7);
-      TRANSPOSE8x8_SH_SH(in0, in1, in2, in3, in4, in5, in6, in7,
-                         in0, in1, in2, in3, in4, in5, in6, in7);
-      VP9_FDCT8(in0, in1, in2, in3, in4, in5, in6, in7,
-                in0, in1, in2, in3, in4, in5, in6, in7);
-      break;
-    case DCT_ADST:
-      VP9_FDCT8(in0, in1, in2, in3, in4, in5, in6, in7,
-                in0, in1, in2, in3, in4, in5, in6, in7);
-      TRANSPOSE8x8_SH_SH(in0, in1, in2, in3, in4, in5, in6, in7,
-                         in0, in1, in2, in3, in4, in5, in6, in7);
-      VP9_ADST8(in0, in1, in2, in3, in4, in5, in6, in7,
-                in0, in1, in2, in3, in4, in5, in6, in7);
-      break;
-    case ADST_ADST:
-      VP9_ADST8(in0, in1, in2, in3, in4, in5, in6, in7,
-                in0, in1, in2, in3, in4, in5, in6, in7);
-      TRANSPOSE8x8_SH_SH(in0, in1, in2, in3, in4, in5, in6, in7,
-                         in0, in1, in2, in3, in4, in5, in6, in7);
-      VP9_ADST8(in0, in1, in2, in3, in4, in5, in6, in7,
-                in0, in1, in2, in3, in4, in5, in6, in7);
-      break;
-    default:
-      assert(0);
-      break;
-  }
-
-  TRANSPOSE8x8_SH_SH(in0, in1, in2, in3, in4, in5, in6, in7,
-                     in0, in1, in2, in3, in4, in5, in6, in7);
-  SRLI_AVE_S_4V_H(in0, in1, in2, in3, in4, in5, in6, in7);
-  ST_SH8(in0, in1, in2, in3, in4, in5, in6, in7, output, 8);
-}
diff --git a/vp9/encoder/mips/msa/vp9_fdct_msa.h b/vp9/encoder/mips/msa/vp9_fdct_msa.h
deleted file mode 100644 (file)
index d7d40cb..0000000
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- *  Copyright (c) 2015 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.
- */
-
-#ifndef VP9_ENCODER_MIPS_MSA_VP9_FDCT_MSA_H_
-#define VP9_ENCODER_MIPS_MSA_VP9_FDCT_MSA_H_
-
-#include "vpx_dsp/mips/fwd_txfm_msa.h"
-#include "vpx_dsp/mips/txfm_macros_msa.h"
-#include "vpx_ports/mem.h"
-
-#define VP9_ADST8(in0, in1, in2, in3, in4, in5, in6, in7,                   \
-                  out0, out1, out2, out3, out4, out5, out6, out7) {         \
-  v8i16 cnst0_m, cnst1_m, cnst2_m, cnst3_m, cnst4_m;                        \
-  v8i16 vec0_m, vec1_m, vec2_m, vec3_m, s0_m, s1_m;                         \
-  v8i16 coeff0_m = { cospi_2_64, cospi_6_64, cospi_10_64, cospi_14_64,      \
-                     cospi_18_64, cospi_22_64, cospi_26_64, cospi_30_64 };  \
-  v8i16 coeff1_m = { cospi_8_64, -cospi_8_64, cospi_16_64, -cospi_16_64,    \
-                     cospi_24_64, -cospi_24_64, 0, 0 };                     \
-                                                                            \
-  SPLATI_H2_SH(coeff0_m, 0, 7, cnst0_m, cnst1_m);                           \
-  cnst2_m = -cnst0_m;                                                       \
-  ILVEV_H2_SH(cnst0_m, cnst1_m, cnst1_m, cnst2_m, cnst0_m, cnst1_m);        \
-  SPLATI_H2_SH(coeff0_m, 4, 3, cnst2_m, cnst3_m);                           \
-  cnst4_m = -cnst2_m;                                                       \
-  ILVEV_H2_SH(cnst2_m, cnst3_m, cnst3_m, cnst4_m, cnst2_m, cnst3_m);        \
-                                                                            \
-  ILVRL_H2_SH(in0, in7, vec1_m, vec0_m);                                    \
-  ILVRL_H2_SH(in4, in3, vec3_m, vec2_m);                                    \
-  DOT_ADD_SUB_SRARI_PCK(vec0_m, vec1_m, vec2_m, vec3_m, cnst0_m,            \
-                        cnst1_m, cnst2_m, cnst3_m, in7, in0,                \
-                        in4, in3);                                          \
-                                                                            \
-  SPLATI_H2_SH(coeff0_m, 2, 5, cnst0_m, cnst1_m);                           \
-  cnst2_m = -cnst0_m;                                                       \
-  ILVEV_H2_SH(cnst0_m, cnst1_m, cnst1_m, cnst2_m, cnst0_m, cnst1_m);        \
-  SPLATI_H2_SH(coeff0_m, 6, 1, cnst2_m, cnst3_m);                           \
-  cnst4_m = -cnst2_m;                                                       \
-  ILVEV_H2_SH(cnst2_m, cnst3_m, cnst3_m, cnst4_m, cnst2_m, cnst3_m);        \
-                                                                            \
-  ILVRL_H2_SH(in2, in5, vec1_m, vec0_m);                                    \
-  ILVRL_H2_SH(in6, in1, vec3_m, vec2_m);                                    \
-                                                                            \
-  DOT_ADD_SUB_SRARI_PCK(vec0_m, vec1_m, vec2_m, vec3_m, cnst0_m,            \
-                        cnst1_m, cnst2_m, cnst3_m, in5, in2,                \
-                        in6, in1);                                          \
-  BUTTERFLY_4(in7, in0, in2, in5, s1_m, s0_m, in2, in5);                    \
-  out7 = -s0_m;                                                             \
-  out0 = s1_m;                                                              \
-                                                                            \
-  SPLATI_H4_SH(coeff1_m, 0, 4, 1, 5, cnst0_m, cnst1_m, cnst2_m, cnst3_m);   \
-                                                                            \
-  ILVEV_H2_SH(cnst3_m, cnst0_m, cnst1_m, cnst2_m, cnst3_m, cnst2_m);        \
-  cnst0_m = __msa_ilvev_h(cnst1_m, cnst0_m);                                \
-  cnst1_m = cnst0_m;                                                        \
-                                                                            \
-  ILVRL_H2_SH(in4, in3, vec1_m, vec0_m);                                    \
-  ILVRL_H2_SH(in6, in1, vec3_m, vec2_m);                                    \
-  DOT_ADD_SUB_SRARI_PCK(vec0_m, vec1_m, vec2_m, vec3_m, cnst0_m,            \
-                        cnst2_m, cnst3_m, cnst1_m, out1, out6,              \
-                        s0_m, s1_m);                                        \
-                                                                            \
-  SPLATI_H2_SH(coeff1_m, 2, 3, cnst0_m, cnst1_m);                           \
-  cnst1_m = __msa_ilvev_h(cnst1_m, cnst0_m);                                \
-                                                                            \
-  ILVRL_H2_SH(in2, in5, vec1_m, vec0_m);                                    \
-  ILVRL_H2_SH(s0_m, s1_m, vec3_m, vec2_m);                                  \
-  out3 = DOT_SHIFT_RIGHT_PCK_H(vec0_m, vec1_m, cnst0_m);                    \
-  out4 = DOT_SHIFT_RIGHT_PCK_H(vec0_m, vec1_m, cnst1_m);                    \
-  out2 = DOT_SHIFT_RIGHT_PCK_H(vec2_m, vec3_m, cnst0_m);                    \
-  out5 = DOT_SHIFT_RIGHT_PCK_H(vec2_m, vec3_m, cnst1_m);                    \
-                                                                            \
-  out1 = -out1;                                                             \
-  out3 = -out3;                                                             \
-  out5 = -out5;                                                             \
-}
-
-#define VP9_FADST4(in0, in1, in2, in3, out0, out1, out2, out3) {  \
-  v4i32 s0_m, s1_m, s2_m, s3_m, constant_m;                       \
-  v4i32 in0_r_m, in1_r_m, in2_r_m, in3_r_m;                       \
-                                                                  \
-  UNPCK_R_SH_SW(in0, in0_r_m);                                    \
-  UNPCK_R_SH_SW(in1, in1_r_m);                                    \
-  UNPCK_R_SH_SW(in2, in2_r_m);                                    \
-  UNPCK_R_SH_SW(in3, in3_r_m);                                    \
-                                                                  \
-  constant_m = __msa_fill_w(sinpi_4_9);                           \
-  MUL2(in0_r_m, constant_m, in3_r_m, constant_m, s1_m, s0_m);     \
-                                                                  \
-  constant_m = __msa_fill_w(sinpi_1_9);                           \
-  s0_m += in0_r_m * constant_m;                                   \
-  s1_m -= in1_r_m * constant_m;                                   \
-                                                                  \
-  constant_m = __msa_fill_w(sinpi_2_9);                           \
-  s0_m += in1_r_m * constant_m;                                   \
-  s1_m += in3_r_m * constant_m;                                   \
-                                                                  \
-  s2_m = in0_r_m + in1_r_m - in3_r_m;                             \
-                                                                  \
-  constant_m = __msa_fill_w(sinpi_3_9);                           \
-  MUL2(in2_r_m, constant_m, s2_m, constant_m, s3_m, in1_r_m);     \
-                                                                  \
-  in0_r_m = s0_m + s3_m;                                          \
-  s2_m = s1_m - s3_m;                                             \
-  s3_m = s1_m - s0_m + s3_m;                                      \
-                                                                  \
-  SRARI_W4_SW(in0_r_m, in1_r_m, s2_m, s3_m, DCT_CONST_BITS);      \
-  PCKEV_H4_SH(in0_r_m, in0_r_m, in1_r_m, in1_r_m, s2_m, s2_m,     \
-              s3_m, s3_m, out0, out1, out2, out3);                \
-}
-#endif  /* VP9_ENCODER_MIPS_MSA_VP9_FDCT_MSA_H_ */
diff --git a/vp9/encoder/mips/msa/vp9_temporal_filter_msa.c b/vp9/encoder/mips/msa/vp9_temporal_filter_msa.c
deleted file mode 100644 (file)
index 363aabb..0000000
+++ /dev/null
@@ -1,289 +0,0 @@
-/*
- *  Copyright (c) 2015 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.
- */
-
-#include "./vp9_rtcd.h"
-#include "vpx_dsp/mips/macros_msa.h"
-
-static void temporal_filter_apply_8size_msa(uint8_t *frm1_ptr,
-                                            uint32_t stride,
-                                            uint8_t *frm2_ptr,
-                                            int32_t filt_sth,
-                                            int32_t filt_wgt,
-                                            uint32_t *acc,
-                                            uint16_t *cnt) {
-  uint32_t row;
-  uint64_t f0, f1, f2, f3;
-  v16i8 frm2, frm1 = { 0 };
-  v16i8 frm4, frm3 = { 0 };
-  v16u8 frm_r, frm_l;
-  v8i16 frm2_r, frm2_l;
-  v8i16 diff0, diff1, mod0_h, mod1_h;
-  v4i32 cnst3, cnst16, filt_wt, strength;
-  v4i32 mod0_w, mod1_w, mod2_w, mod3_w;
-  v4i32 diff0_r, diff0_l, diff1_r, diff1_l;
-  v4i32 frm2_rr, frm2_rl, frm2_lr, frm2_ll;
-  v4i32 acc0, acc1, acc2, acc3;
-  v8i16 cnt0, cnt1;
-
-  filt_wt = __msa_fill_w(filt_wgt);
-  strength = __msa_fill_w(filt_sth);
-  cnst3 = __msa_ldi_w(3);
-  cnst16 = __msa_ldi_w(16);
-
-  for (row = 2; row--;) {
-    LD4(frm1_ptr, stride, f0, f1, f2, f3);
-    frm1_ptr += (4 * stride);
-
-    LD_SB2(frm2_ptr, 16, frm2, frm4);
-    frm2_ptr += 32;
-
-    LD_SW2(acc, 4, acc0, acc1);
-    LD_SW2(acc + 8, 4, acc2, acc3);
-    LD_SH2(cnt, 8, cnt0, cnt1);
-
-    INSERT_D2_SB(f0, f1, frm1);
-    INSERT_D2_SB(f2, f3, frm3);
-    ILVRL_B2_UB(frm1, frm2, frm_r, frm_l);
-    HSUB_UB2_SH(frm_r, frm_l, diff0, diff1);
-    UNPCK_SH_SW(diff0, diff0_r, diff0_l);
-    UNPCK_SH_SW(diff1, diff1_r, diff1_l);
-    MUL4(diff0_r, diff0_r, diff0_l, diff0_l, diff1_r, diff1_r, diff1_l,
-         diff1_l, mod0_w, mod1_w, mod2_w, mod3_w);
-    MUL4(mod0_w, cnst3, mod1_w, cnst3, mod2_w, cnst3, mod3_w, cnst3,
-         mod0_w, mod1_w, mod2_w, mod3_w);
-    SRAR_W4_SW(mod0_w, mod1_w, mod2_w, mod3_w, strength);
-
-    diff0_r = (mod0_w < cnst16);
-    diff0_l = (mod1_w < cnst16);
-    diff1_r = (mod2_w < cnst16);
-    diff1_l = (mod3_w < cnst16);
-
-    SUB4(cnst16, mod0_w, cnst16, mod1_w, cnst16, mod2_w, cnst16, mod3_w,
-         mod0_w, mod1_w, mod2_w, mod3_w);
-
-    mod0_w = diff0_r & mod0_w;
-    mod1_w = diff0_l & mod1_w;
-    mod2_w = diff1_r & mod2_w;
-    mod3_w = diff1_l & mod3_w;
-
-    MUL4(mod0_w, filt_wt, mod1_w, filt_wt, mod2_w, filt_wt, mod3_w, filt_wt,
-         mod0_w, mod1_w, mod2_w, mod3_w);
-    PCKEV_H2_SH(mod1_w, mod0_w, mod3_w, mod2_w, mod0_h, mod1_h);
-    ADD2(mod0_h, cnt0, mod1_h, cnt1, mod0_h, mod1_h);
-    ST_SH2(mod0_h, mod1_h, cnt, 8);
-    cnt += 16;
-
-    UNPCK_UB_SH(frm2, frm2_r, frm2_l);
-    UNPCK_SH_SW(frm2_r, frm2_rr, frm2_rl);
-    UNPCK_SH_SW(frm2_l, frm2_lr, frm2_ll);
-    MUL4(mod0_w, frm2_rr, mod1_w, frm2_rl, mod2_w, frm2_lr, mod3_w, frm2_ll,
-         mod0_w, mod1_w, mod2_w, mod3_w);
-    ADD4(mod0_w, acc0, mod1_w, acc1, mod2_w, acc2, mod3_w, acc3,
-         mod0_w, mod1_w, mod2_w, mod3_w);
-
-    ST_SW2(mod0_w, mod1_w, acc, 4);
-    acc += 8;
-    ST_SW2(mod2_w, mod3_w, acc, 4);
-    acc += 8;
-
-    LD_SW2(acc, 4, acc0, acc1);
-    LD_SW2(acc + 8, 4, acc2, acc3);
-    LD_SH2(cnt, 8, cnt0, cnt1);
-
-    ILVRL_B2_UB(frm3, frm4, frm_r, frm_l);
-    HSUB_UB2_SH(frm_r, frm_l, diff0, diff1);
-    UNPCK_SH_SW(diff0, diff0_r, diff0_l);
-    UNPCK_SH_SW(diff1, diff1_r, diff1_l);
-    MUL4(diff0_r, diff0_r, diff0_l, diff0_l, diff1_r, diff1_r, diff1_l,
-         diff1_l, mod0_w, mod1_w, mod2_w, mod3_w);
-    MUL4(mod0_w, cnst3, mod1_w, cnst3, mod2_w, cnst3, mod3_w, cnst3,
-         mod0_w, mod1_w, mod2_w, mod3_w);
-    SRAR_W4_SW(mod0_w, mod1_w, mod2_w, mod3_w, strength);
-
-    diff0_r = (mod0_w < cnst16);
-    diff0_l = (mod1_w < cnst16);
-    diff1_r = (mod2_w < cnst16);
-    diff1_l = (mod3_w < cnst16);
-
-    SUB4(cnst16, mod0_w, cnst16, mod1_w, cnst16, mod2_w, cnst16, mod3_w,
-         mod0_w, mod1_w, mod2_w, mod3_w);
-
-    mod0_w = diff0_r & mod0_w;
-    mod1_w = diff0_l & mod1_w;
-    mod2_w = diff1_r & mod2_w;
-    mod3_w = diff1_l & mod3_w;
-
-    MUL4(mod0_w, filt_wt, mod1_w, filt_wt, mod2_w, filt_wt, mod3_w, filt_wt,
-         mod0_w, mod1_w, mod2_w, mod3_w);
-    PCKEV_H2_SH(mod1_w, mod0_w, mod3_w, mod2_w, mod0_h, mod1_h);
-    ADD2(mod0_h, cnt0, mod1_h, cnt1, mod0_h, mod1_h);
-    ST_SH2(mod0_h, mod1_h, cnt, 8);
-    cnt += 16;
-    UNPCK_UB_SH(frm4, frm2_r, frm2_l);
-    UNPCK_SH_SW(frm2_r, frm2_rr, frm2_rl);
-    UNPCK_SH_SW(frm2_l, frm2_lr, frm2_ll);
-    MUL4(mod0_w, frm2_rr, mod1_w, frm2_rl, mod2_w, frm2_lr, mod3_w, frm2_ll,
-         mod0_w, mod1_w, mod2_w, mod3_w);
-    ADD4(mod0_w, acc0, mod1_w, acc1, mod2_w, acc2, mod3_w, acc3,
-         mod0_w, mod1_w, mod2_w, mod3_w);
-
-    ST_SW2(mod0_w, mod1_w, acc, 4);
-    acc += 8;
-    ST_SW2(mod2_w, mod3_w, acc, 4);
-    acc += 8;
-  }
-}
-
-static void temporal_filter_apply_16size_msa(uint8_t *frm1_ptr,
-                                             uint32_t stride,
-                                             uint8_t *frm2_ptr,
-                                             int32_t filt_sth,
-                                             int32_t filt_wgt,
-                                             uint32_t *acc,
-                                             uint16_t *cnt) {
-  uint32_t row;
-  v16i8 frm1, frm2, frm3, frm4;
-  v16u8 frm_r, frm_l;
-  v16i8 zero = { 0 };
-  v8u16 frm2_r, frm2_l;
-  v8i16 diff0, diff1, mod0_h, mod1_h;
-  v4i32 cnst3, cnst16, filt_wt, strength;
-  v4i32 mod0_w, mod1_w, mod2_w, mod3_w;
-  v4i32 diff0_r, diff0_l, diff1_r, diff1_l;
-  v4i32 frm2_rr, frm2_rl, frm2_lr, frm2_ll;
-  v4i32 acc0, acc1, acc2, acc3;
-  v8i16 cnt0, cnt1;
-
-  filt_wt = __msa_fill_w(filt_wgt);
-  strength = __msa_fill_w(filt_sth);
-  cnst3 = __msa_ldi_w(3);
-  cnst16 = __msa_ldi_w(16);
-
-  for (row = 8; row--;) {
-    LD_SB2(frm1_ptr, stride, frm1, frm3);
-    frm1_ptr += stride;
-
-    LD_SB2(frm2_ptr, 16, frm2, frm4);
-    frm2_ptr += 16;
-
-    LD_SW2(acc, 4, acc0, acc1);
-    LD_SW2(acc, 4, acc2, acc3);
-    LD_SH2(cnt, 8, cnt0, cnt1);
-
-    ILVRL_B2_UB(frm1, frm2, frm_r, frm_l);
-    HSUB_UB2_SH(frm_r, frm_l, diff0, diff1);
-    UNPCK_SH_SW(diff0, diff0_r, diff0_l);
-    UNPCK_SH_SW(diff1, diff1_r, diff1_l);
-    MUL4(diff0_r, diff0_r, diff0_l, diff0_l, diff1_r, diff1_r, diff1_l, diff1_l,
-         mod0_w, mod1_w, mod2_w, mod3_w);
-    MUL4(mod0_w, cnst3, mod1_w, cnst3, mod2_w, cnst3, mod3_w, cnst3,
-         mod0_w, mod1_w, mod2_w, mod3_w);
-    SRAR_W4_SW(mod0_w, mod1_w, mod2_w, mod3_w, strength);
-
-    diff0_r = (mod0_w < cnst16);
-    diff0_l = (mod1_w < cnst16);
-    diff1_r = (mod2_w < cnst16);
-    diff1_l = (mod3_w < cnst16);
-
-    SUB4(cnst16, mod0_w, cnst16, mod1_w, cnst16, mod2_w, cnst16, mod3_w,
-         mod0_w, mod1_w, mod2_w, mod3_w);
-
-    mod0_w = diff0_r & mod0_w;
-    mod1_w = diff0_l & mod1_w;
-    mod2_w = diff1_r & mod2_w;
-    mod3_w = diff1_l & mod3_w;
-
-    MUL4(mod0_w, filt_wt, mod1_w, filt_wt, mod2_w, filt_wt, mod3_w, filt_wt,
-         mod0_w, mod1_w, mod2_w, mod3_w);
-    PCKEV_H2_SH(mod1_w, mod0_w, mod3_w, mod2_w, mod0_h, mod1_h);
-    ADD2(mod0_h, cnt0, mod1_h, cnt1, mod0_h, mod1_h);
-    ST_SH2(mod0_h, mod1_h, cnt, 8);
-    cnt += 16;
-
-    ILVRL_B2_UH(zero, frm2, frm2_r, frm2_l);
-    UNPCK_SH_SW(frm2_r, frm2_rr, frm2_rl);
-    UNPCK_SH_SW(frm2_l, frm2_lr, frm2_ll);
-    MUL4(mod0_w, frm2_rr, mod1_w, frm2_rl, mod2_w, frm2_lr, mod3_w, frm2_ll,
-         mod0_w, mod1_w, mod2_w, mod3_w);
-    ADD4(mod0_w, acc0, mod1_w, acc1, mod2_w, acc2, mod3_w, acc3,
-         mod0_w, mod1_w, mod2_w, mod3_w);
-
-    ST_SW2(mod0_w, mod1_w, acc, 4);
-    acc += 8;
-    ST_SW2(mod2_w, mod3_w, acc, 4);
-    acc += 8;
-
-    LD_SW2(acc, 4, acc0, acc1);
-    LD_SW2(acc + 8, 4, acc2, acc3);
-    LD_SH2(cnt, 8, cnt0, cnt1);
-
-    ILVRL_B2_UB(frm3, frm4, frm_r, frm_l);
-    HSUB_UB2_SH(frm_r, frm_l, diff0, diff1);
-    UNPCK_SH_SW(diff0, diff0_r, diff0_l);
-    UNPCK_SH_SW(diff1, diff1_r, diff1_l);
-    MUL4(diff0_r, diff0_r, diff0_l, diff0_l, diff1_r, diff1_r, diff1_l, diff1_l,
-         mod0_w, mod1_w, mod2_w, mod3_w);
-    MUL4(mod0_w, cnst3, mod1_w, cnst3, mod2_w, cnst3, mod3_w, cnst3,
-         mod0_w, mod1_w, mod2_w, mod3_w);
-    SRAR_W4_SW(mod0_w, mod1_w, mod2_w, mod3_w, strength);
-
-    diff0_r = (mod0_w < cnst16);
-    diff0_l = (mod1_w < cnst16);
-    diff1_r = (mod2_w < cnst16);
-    diff1_l = (mod3_w < cnst16);
-
-    SUB4(cnst16, mod0_w, cnst16, mod1_w, cnst16, mod2_w, cnst16, mod3_w,
-         mod0_w, mod1_w, mod2_w, mod3_w);
-
-    mod0_w = diff0_r & mod0_w;
-    mod1_w = diff0_l & mod1_w;
-    mod2_w = diff1_r & mod2_w;
-    mod3_w = diff1_l & mod3_w;
-
-    MUL4(mod0_w, filt_wt, mod1_w, filt_wt, mod2_w, filt_wt, mod3_w, filt_wt,
-         mod0_w, mod1_w, mod2_w, mod3_w);
-    PCKEV_H2_SH(mod1_w, mod0_w, mod3_w, mod2_w, mod0_h, mod1_h);
-    ADD2(mod0_h, cnt0, mod1_h, cnt1, mod0_h, mod1_h);
-    ST_SH2(mod0_h, mod1_h, cnt, 8);
-    cnt += 16;
-
-    ILVRL_B2_UH(zero, frm4, frm2_r, frm2_l);
-    UNPCK_SH_SW(frm2_r, frm2_rr, frm2_rl);
-    UNPCK_SH_SW(frm2_l, frm2_lr, frm2_ll);
-    MUL4(mod0_w, frm2_rr, mod1_w, frm2_rl, mod2_w, frm2_lr, mod3_w, frm2_ll,
-         mod0_w, mod1_w, mod2_w, mod3_w);
-    ADD4(mod0_w, acc0, mod1_w, acc1, mod2_w, acc2, mod3_w, acc3,
-         mod0_w, mod1_w, mod2_w, mod3_w);
-    ST_SW2(mod0_w, mod1_w, acc, 4);
-    acc += 8;
-    ST_SW2(mod2_w, mod3_w, acc, 4);
-    acc += 8;
-
-    frm1_ptr += stride;
-    frm2_ptr += 16;
-  }
-}
-
-void vp9_temporal_filter_apply_msa(uint8_t *frame1_ptr, uint32_t stride,
-                                   uint8_t *frame2_ptr, uint32_t blk_w,
-                                   uint32_t blk_h, int32_t strength,
-                                   int32_t filt_wgt, uint32_t *accu,
-                                   uint16_t *cnt) {
-  if (8 == (blk_w * blk_h)) {
-    temporal_filter_apply_8size_msa(frame1_ptr, stride, frame2_ptr,
-                                    strength, filt_wgt, accu, cnt);
-  } else if (16 == (blk_w * blk_h)) {
-    temporal_filter_apply_16size_msa(frame1_ptr, stride, frame2_ptr,
-                                     strength, filt_wgt, accu, cnt);
-  } else {
-    vp9_temporal_filter_apply_c(frame1_ptr, stride, frame2_ptr, blk_w, blk_h,
-                                strength, filt_wgt, accu, cnt);
-  }
-}
diff --git a/vp9/encoder/vp9_aq_360.c b/vp9/encoder/vp9_aq_360.c
deleted file mode 100644 (file)
index 7d411f6..0000000
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- *  Copyright (c) 2013 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.
- */
-
-#include <math.h>
-
-#include "vpx_ports/mem.h"
-#include "vpx_ports/system_state.h"
-
-#include "vp9/encoder/vp9_aq_360.h"
-#include "vp9/encoder/vp9_aq_variance.h"
-
-#include "vp9/common/vp9_seg_common.h"
-
-#include "vp9/encoder/vp9_ratectrl.h"
-#include "vp9/encoder/vp9_rd.h"
-#include "vp9/encoder/vp9_segmentation.h"
-
-static const double rate_ratio[MAX_SEGMENTS] =
-  {1.0, 0.75, 0.6, 0.5, 0.4, 0.3, 0.25};
-
-// Sets segment id 0 for the equatorial region, 1 for temperate region
-// and 2 for the polar regions
-unsigned int vp9_360aq_segment_id(int mi_row, int mi_rows) {
-  if (mi_row < mi_rows / 8 || mi_row > mi_rows - mi_rows / 8)
-    return 2;
-  else if (mi_row < mi_rows / 4 || mi_row > mi_rows - mi_rows / 4)
-    return 1;
-  else
-    return 0;
-}
-
-void vp9_360aq_frame_setup(VP9_COMP *cpi) {
-  VP9_COMMON *cm = &cpi->common;
-  struct segmentation *seg = &cm->seg;
-  int i;
-
-  if (frame_is_intra_only(cm) || cm->error_resilient_mode) {
-    vp9_enable_segmentation(seg);
-    vp9_clearall_segfeatures(seg);
-
-    seg->abs_delta = SEGMENT_DELTADATA;
-
-    vpx_clear_system_state();
-
-    for (i = 0; i < MAX_SEGMENTS; ++i) {
-      int qindex_delta =
-          vp9_compute_qdelta_by_rate(&cpi->rc, cm->frame_type, cm->base_qindex,
-                                     rate_ratio[i], cm->bit_depth);
-
-      // We don't allow qindex 0 in a segment if the base value is not 0.
-      // Q index 0 (lossless) implies 4x4 encoding only and in AQ mode a segment
-      // Q delta is sometimes applied without going back around the rd loop.
-      // This could lead to an illegal combination of partition size and q.
-      if ((cm->base_qindex != 0) && ((cm->base_qindex + qindex_delta) == 0)) {
-        qindex_delta = -cm->base_qindex + 1;
-      }
-
-      // No need to enable SEG_LVL_ALT_Q for this segment.
-      if (rate_ratio[i] == 1.0) {
-        continue;
-      }
-
-      vp9_set_segdata(seg, i, SEG_LVL_ALT_Q, qindex_delta);
-      vp9_enable_segfeature(seg, i, SEG_LVL_ALT_Q);
-    }
-  }
-}
diff --git a/vp9/encoder/vp9_aq_360.h b/vp9/encoder/vp9_aq_360.h
deleted file mode 100644 (file)
index fb861cb..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- *  Copyright (c) 2013 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.
- */
-
-
-#ifndef VP9_ENCODER_VP9_AQ_360_H_
-#define VP9_ENCODER_VP9_AQ_360_H_
-
-#include "vp9/encoder/vp9_encoder.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-unsigned int vp9_360aq_segment_id(int mi_row, int mi_rows);
-void vp9_360aq_frame_setup(VP9_COMP *cpi);
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP9_ENCODER_VP9_AQ_VARIANCE_H_
diff --git a/vp9/encoder/vp9_aq_complexity.c b/vp9/encoder/vp9_aq_complexity.c
deleted file mode 100644 (file)
index 2d979ec..0000000
+++ /dev/null
@@ -1,161 +0,0 @@
-/*
- *  Copyright (c) 2014 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.
- */
-
-#include <limits.h>
-#include <math.h>
-#include "vpx_dsp/vpx_dsp_common.h"
-#include "vpx_ports/system_state.h"
-
-#include "vp9/encoder/vp9_aq_complexity.h"
-#include "vp9/encoder/vp9_aq_variance.h"
-#include "vp9/encoder/vp9_encodeframe.h"
-#include "vp9/common/vp9_seg_common.h"
-#include "vp9/encoder/vp9_segmentation.h"
-
-#define AQ_C_SEGMENTS  5
-#define DEFAULT_AQ2_SEG 3   // Neutral Q segment
-#define AQ_C_STRENGTHS 3
-static const double aq_c_q_adj_factor[AQ_C_STRENGTHS][AQ_C_SEGMENTS] =
-  { {1.75, 1.25, 1.05, 1.00, 0.90},
-    {2.00, 1.50, 1.15, 1.00, 0.85},
-    {2.50, 1.75, 1.25, 1.00, 0.80} };
-static const double aq_c_transitions[AQ_C_STRENGTHS][AQ_C_SEGMENTS] =
-  { {0.15, 0.30, 0.55, 2.00, 100.0},
-    {0.20, 0.40, 0.65, 2.00, 100.0},
-    {0.25, 0.50, 0.75, 2.00, 100.0} };
-static const double aq_c_var_thresholds[AQ_C_STRENGTHS][AQ_C_SEGMENTS] =
-  { {-4.0, -3.0, -2.0, 100.00, 100.0},
-    {-3.5, -2.5, -1.5, 100.00, 100.0},
-    {-3.0, -2.0, -1.0, 100.00, 100.0} };
-
-static int get_aq_c_strength(int q_index, vpx_bit_depth_t bit_depth) {
-  // Approximate base quatizer (truncated to int)
-  const int base_quant = vp9_ac_quant(q_index, 0, bit_depth) / 4;
-  return (base_quant > 10) + (base_quant > 25);
-}
-
-void vp9_setup_in_frame_q_adj(VP9_COMP *cpi) {
-  VP9_COMMON *const cm = &cpi->common;
-  struct segmentation *const seg = &cm->seg;
-
-  // Make SURE use of floating point in this function is safe.
-  vpx_clear_system_state();
-
-  if (frame_is_intra_only(cm) || cm->error_resilient_mode ||
-      cpi->refresh_alt_ref_frame ||
-      (cpi->refresh_golden_frame && !cpi->rc.is_src_frame_alt_ref)) {
-    int segment;
-    const int aq_strength = get_aq_c_strength(cm->base_qindex, cm->bit_depth);
-
-    // Clear down the segment map.
-    memset(cpi->segmentation_map, DEFAULT_AQ2_SEG, cm->mi_rows * cm->mi_cols);
-
-    vp9_clearall_segfeatures(seg);
-
-    // Segmentation only makes sense if the target bits per SB is above a
-    // threshold. Below this the overheads will usually outweigh any benefit.
-    if (cpi->rc.sb64_target_rate < 256) {
-      vp9_disable_segmentation(seg);
-      return;
-    }
-
-    vp9_enable_segmentation(seg);
-
-    // Select delta coding method.
-    seg->abs_delta = SEGMENT_DELTADATA;
-
-    // Default segment "Q" feature is disabled so it defaults to the baseline Q.
-    vp9_disable_segfeature(seg, DEFAULT_AQ2_SEG, SEG_LVL_ALT_Q);
-
-    // Use some of the segments for in frame Q adjustment.
-    for (segment = 0; segment < AQ_C_SEGMENTS; ++segment) {
-      int qindex_delta;
-
-      if (segment == DEFAULT_AQ2_SEG)
-        continue;
-
-      qindex_delta =
-        vp9_compute_qdelta_by_rate(&cpi->rc, cm->frame_type, cm->base_qindex,
-                                   aq_c_q_adj_factor[aq_strength][segment],
-                                   cm->bit_depth);
-
-
-      // For AQ complexity mode, we dont allow Q0 in a segment if the base
-      // Q is not 0. Q0 (lossless) implies 4x4 only and in AQ mode 2 a segment
-      // Q delta is sometimes applied without going back around the rd loop.
-      // This could lead to an illegal combination of partition size and q.
-      if ((cm->base_qindex != 0) && ((cm->base_qindex + qindex_delta) == 0)) {
-        qindex_delta = -cm->base_qindex + 1;
-      }
-      if ((cm->base_qindex + qindex_delta) > 0) {
-        vp9_enable_segfeature(seg, segment, SEG_LVL_ALT_Q);
-        vp9_set_segdata(seg, segment, SEG_LVL_ALT_Q, qindex_delta);
-      }
-    }
-  }
-}
-
-#define DEFAULT_LV_THRESH 10.0
-#define MIN_DEFAULT_LV_THRESH 8.0
-// Select a segment for the current block.
-// The choice of segment for a block depends on the ratio of the projected
-// bits for the block vs a target average and its spatial complexity.
-void vp9_caq_select_segment(VP9_COMP *cpi, MACROBLOCK *mb, BLOCK_SIZE bs,
-                            int mi_row, int mi_col, int projected_rate) {
-  VP9_COMMON *const cm = &cpi->common;
-
-  const int mi_offset = mi_row * cm->mi_cols + mi_col;
-  const int bw = num_8x8_blocks_wide_lookup[BLOCK_64X64];
-  const int bh = num_8x8_blocks_high_lookup[BLOCK_64X64];
-  const int xmis = VPXMIN(cm->mi_cols - mi_col, num_8x8_blocks_wide_lookup[bs]);
-  const int ymis = VPXMIN(cm->mi_rows - mi_row, num_8x8_blocks_high_lookup[bs]);
-  int x, y;
-  int i;
-  unsigned char segment;
-
-  if (0) {
-    segment = DEFAULT_AQ2_SEG;
-  } else {
-    // Rate depends on fraction of a SB64 in frame (xmis * ymis / bw * bh).
-    // It is converted to bits * 256 units.
-    const int target_rate = (cpi->rc.sb64_target_rate * xmis * ymis * 256) /
-                            (bw * bh);
-    double logvar;
-    double low_var_thresh;
-    const int aq_strength = get_aq_c_strength(cm->base_qindex, cm->bit_depth);
-
-    vpx_clear_system_state();
-    low_var_thresh = (cpi->oxcf.pass == 2)
-      ? VPXMAX(cpi->twopass.mb_av_energy, MIN_DEFAULT_LV_THRESH)
-      : DEFAULT_LV_THRESH;
-
-    vp9_setup_src_planes(mb, cpi->Source, mi_row, mi_col);
-    logvar = vp9_log_block_var(cpi, mb, bs);
-
-    segment = AQ_C_SEGMENTS - 1;    // Just in case no break out below.
-    for (i = 0; i < AQ_C_SEGMENTS; ++i) {
-      // Test rate against a threshold value and variance against a threshold.
-      // Increasing segment number (higher variance and complexity) = higher Q.
-      if ((projected_rate <
-           target_rate * aq_c_transitions[aq_strength][i]) &&
-          (logvar < (low_var_thresh + aq_c_var_thresholds[aq_strength][i]))) {
-        segment = i;
-        break;
-      }
-    }
-  }
-
-  // Fill in the entires in the segment map corresponding to this SB64.
-  for (y = 0; y < ymis; y++) {
-    for (x = 0; x < xmis; x++) {
-      cpi->segmentation_map[mi_offset + y * cm->mi_cols + x] = segment;
-    }
-  }
-}
diff --git a/vp9/encoder/vp9_aq_complexity.h b/vp9/encoder/vp9_aq_complexity.h
deleted file mode 100644 (file)
index e9acb1c..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- *  Copyright (c) 2014 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.
- */
-
-
-#ifndef VP9_ENCODER_VP9_AQ_COMPLEXITY_H_
-#define VP9_ENCODER_VP9_AQ_COMPLEXITY_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include "vp9/common/vp9_enums.h"
-
-struct VP9_COMP;
-struct macroblock;
-
-// Select a segment for the current Block.
-void vp9_caq_select_segment(struct VP9_COMP *cpi, struct macroblock *,
-                            BLOCK_SIZE bs,
-                            int mi_row, int mi_col, int projected_rate);
-
-// This function sets up a set of segments with delta Q values around
-// the baseline frame quantizer.
-void vp9_setup_in_frame_q_adj(struct VP9_COMP *cpi);
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP9_ENCODER_VP9_AQ_COMPLEXITY_H_
diff --git a/vp9/encoder/vp9_aq_cyclicrefresh.c b/vp9/encoder/vp9_aq_cyclicrefresh.c
deleted file mode 100644 (file)
index d8920fb..0000000
+++ /dev/null
@@ -1,612 +0,0 @@
-/*
- *  Copyright (c) 2014 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.
- */
-
-#include <limits.h>
-#include <math.h>
-
-#include "vpx_dsp/vpx_dsp_common.h"
-#include "vpx_ports/system_state.h"
-
-#include "vp9/encoder/vp9_aq_cyclicrefresh.h"
-
-#include "vp9/common/vp9_seg_common.h"
-
-#include "vp9/encoder/vp9_ratectrl.h"
-#include "vp9/encoder/vp9_segmentation.h"
-CYCLIC_REFRESH *vp9_cyclic_refresh_alloc(int mi_rows, int mi_cols) {
-  size_t last_coded_q_map_size;
-  CYCLIC_REFRESH *const cr = vpx_calloc(1, sizeof(*cr));
-  if (cr == NULL)
-    return NULL;
-
-  cr->map = vpx_calloc(mi_rows * mi_cols, sizeof(*cr->map));
-  if (cr->map == NULL) {
-    vp9_cyclic_refresh_free(cr);
-    return NULL;
-  }
-  last_coded_q_map_size = mi_rows * mi_cols * sizeof(*cr->last_coded_q_map);
-  cr->last_coded_q_map = vpx_malloc(last_coded_q_map_size);
-  if (cr->last_coded_q_map == NULL) {
-    vp9_cyclic_refresh_free(cr);
-    return NULL;
-  }
-  assert(MAXQ <= 255);
-  memset(cr->last_coded_q_map, MAXQ, last_coded_q_map_size);
-  return cr;
-}
-
-void vp9_cyclic_refresh_free(CYCLIC_REFRESH *cr) {
-  vpx_free(cr->map);
-  vpx_free(cr->last_coded_q_map);
-  vpx_free(cr);
-}
-
-// Check if this coding block, of size bsize, should be considered for refresh
-// (lower-qp coding). Decision can be based on various factors, such as
-// size of the coding block (i.e., below min_block size rejected), coding
-// mode, and rate/distortion.
-static int candidate_refresh_aq(const CYCLIC_REFRESH *cr,
-                                const MODE_INFO *mi,
-                                int64_t rate,
-                                int64_t dist,
-                                int bsize) {
-  MV mv = mi->mv[0].as_mv;
-  // Reject the block for lower-qp coding if projected distortion
-  // is above the threshold, and any of the following is true:
-  // 1) mode uses large mv
-  // 2) mode is an intra-mode
-  // Otherwise accept for refresh.
-  if (dist > cr->thresh_dist_sb &&
-      (mv.row > cr->motion_thresh || mv.row < -cr->motion_thresh ||
-       mv.col > cr->motion_thresh || mv.col < -cr->motion_thresh ||
-       !is_inter_block(mi)))
-    return CR_SEGMENT_ID_BASE;
-  else  if (bsize >= BLOCK_16X16 &&
-            rate < cr->thresh_rate_sb &&
-            is_inter_block(mi) &&
-            mi->mv[0].as_int == 0 &&
-            cr->rate_boost_fac > 10)
-    // More aggressive delta-q for bigger blocks with zero motion.
-    return CR_SEGMENT_ID_BOOST2;
-  else
-    return CR_SEGMENT_ID_BOOST1;
-}
-
-// Compute delta-q for the segment.
-static int compute_deltaq(const VP9_COMP *cpi, int q, double rate_factor) {
-  const CYCLIC_REFRESH *const cr = cpi->cyclic_refresh;
-  const RATE_CONTROL *const rc = &cpi->rc;
-  int deltaq = vp9_compute_qdelta_by_rate(rc, cpi->common.frame_type,
-                                          q, rate_factor,
-                                          cpi->common.bit_depth);
-  if ((-deltaq) > cr->max_qdelta_perc * q / 100) {
-    deltaq = -cr->max_qdelta_perc * q / 100;
-  }
-  return deltaq;
-}
-
-// For the just encoded frame, estimate the bits, incorporating the delta-q
-// from non-base segment. For now ignore effect of multiple segments
-// (with different delta-q). Note this function is called in the postencode
-// (called from rc_update_rate_correction_factors()).
-int vp9_cyclic_refresh_estimate_bits_at_q(const VP9_COMP *cpi,
-                                          double correction_factor) {
-  const VP9_COMMON *const cm = &cpi->common;
-  const CYCLIC_REFRESH *const cr = cpi->cyclic_refresh;
-  int estimated_bits;
-  int mbs = cm->MBs;
-  int num8x8bl = mbs << 2;
-  // Weight for non-base segments: use actual number of blocks refreshed in
-  // previous/just encoded frame. Note number of blocks here is in 8x8 units.
-  double weight_segment1 = (double)cr->actual_num_seg1_blocks / num8x8bl;
-  double weight_segment2 = (double)cr->actual_num_seg2_blocks / num8x8bl;
-  // Take segment weighted average for estimated bits.
-  estimated_bits = (int)((1.0 - weight_segment1 - weight_segment2) *
-      vp9_estimate_bits_at_q(cm->frame_type, cm->base_qindex, mbs,
-                             correction_factor, cm->bit_depth) +
-                             weight_segment1 *
-      vp9_estimate_bits_at_q(cm->frame_type,
-                             cm->base_qindex + cr->qindex_delta[1], mbs,
-                             correction_factor, cm->bit_depth) +
-                             weight_segment2 *
-      vp9_estimate_bits_at_q(cm->frame_type,
-                             cm->base_qindex + cr->qindex_delta[2], mbs,
-                             correction_factor, cm->bit_depth));
-  return estimated_bits;
-}
-
-// Prior to encoding the frame, estimate the bits per mb, for a given q = i and
-// a corresponding delta-q (for segment 1). This function is called in the
-// rc_regulate_q() to set the base qp index.
-// Note: the segment map is set to either 0/CR_SEGMENT_ID_BASE (no refresh) or
-// to 1/CR_SEGMENT_ID_BOOST1 (refresh) for each superblock, prior to encoding.
-int vp9_cyclic_refresh_rc_bits_per_mb(const VP9_COMP *cpi, int i,
-                                      double correction_factor) {
-  const VP9_COMMON *const cm = &cpi->common;
-  CYCLIC_REFRESH *const cr = cpi->cyclic_refresh;
-  int bits_per_mb;
-  int num8x8bl = cm->MBs << 2;
-  // Weight for segment prior to encoding: take the average of the target
-  // number for the frame to be encoded and the actual from the previous frame.
-  int target_refresh = cr->percent_refresh * cm->mi_rows * cm->mi_cols / 100;
-  double weight_segment = (double)((target_refresh +
-      cr->actual_num_seg1_blocks + cr->actual_num_seg2_blocks) >> 1) /
-      num8x8bl;
-  // Compute delta-q corresponding to qindex i.
-  int deltaq = compute_deltaq(cpi, i, cr->rate_ratio_qdelta);
-  // Take segment weighted average for bits per mb.
-  bits_per_mb = (int)((1.0 - weight_segment) *
-      vp9_rc_bits_per_mb(cm->frame_type, i, correction_factor, cm->bit_depth) +
-      weight_segment *
-      vp9_rc_bits_per_mb(cm->frame_type, i + deltaq, correction_factor,
-                         cm->bit_depth));
-  return bits_per_mb;
-}
-
-// Prior to coding a given prediction block, of size bsize at (mi_row, mi_col),
-// check if we should reset the segment_id, and update the cyclic_refresh map
-// and segmentation map.
-void vp9_cyclic_refresh_update_segment(VP9_COMP *const cpi,
-                                       MODE_INFO *const mi,
-                                       int mi_row, int mi_col,
-                                       BLOCK_SIZE bsize,
-                                       int64_t rate,
-                                       int64_t dist,
-                                       int skip,
-                                       struct macroblock_plane *const p) {
-  const VP9_COMMON *const cm = &cpi->common;
-  CYCLIC_REFRESH *const cr = cpi->cyclic_refresh;
-  const int bw = num_8x8_blocks_wide_lookup[bsize];
-  const int bh = num_8x8_blocks_high_lookup[bsize];
-  const int xmis = VPXMIN(cm->mi_cols - mi_col, bw);
-  const int ymis = VPXMIN(cm->mi_rows - mi_row, bh);
-  const int block_index = mi_row * cm->mi_cols + mi_col;
-  int refresh_this_block = candidate_refresh_aq(cr, mi, rate, dist, bsize);
-  // Default is to not update the refresh map.
-  int new_map_value = cr->map[block_index];
-  int x = 0; int y = 0;
-
-  int is_skin = 0;
-  if (refresh_this_block == 0 &&
-      bsize <= BLOCK_16X16 &&
-      cpi->use_skin_detection) {
-    is_skin = vp9_compute_skin_block(p[0].src.buf,
-                                     p[1].src.buf,
-                                     p[2].src.buf,
-                                     p[0].src.stride,
-                                     p[1].src.stride,
-                                     bsize,
-                                     0,
-                                     0);
-    if (is_skin)
-      refresh_this_block = 1;
-  }
-
-  if (cpi->oxcf.rc_mode == VPX_VBR && mi->ref_frame[0] == GOLDEN_FRAME)
-    refresh_this_block = 0;
-
-  // If this block is labeled for refresh, check if we should reset the
-  // segment_id.
-  if (cyclic_refresh_segment_id_boosted(mi->segment_id)) {
-    mi->segment_id = refresh_this_block;
-    // Reset segment_id if it will be skipped.
-    if (skip)
-      mi->segment_id = CR_SEGMENT_ID_BASE;
-  }
-
-  // Update the cyclic refresh map, to be used for setting segmentation map
-  // for the next frame. If the block  will be refreshed this frame, mark it
-  // as clean. The magnitude of the -ve influences how long before we consider
-  // it for refresh again.
-  if (cyclic_refresh_segment_id_boosted(mi->segment_id)) {
-    new_map_value = -cr->time_for_refresh;
-  } else if (refresh_this_block) {
-    // Else if it is accepted as candidate for refresh, and has not already
-    // been refreshed (marked as 1) then mark it as a candidate for cleanup
-    // for future time (marked as 0), otherwise don't update it.
-    if (cr->map[block_index] == 1)
-      new_map_value = 0;
-  } else {
-    // Leave it marked as block that is not candidate for refresh.
-    new_map_value = 1;
-  }
-
-  // Update entries in the cyclic refresh map with new_map_value, and
-  // copy mbmi->segment_id into global segmentation map.
-  for (y = 0; y < ymis; y++)
-    for (x = 0; x < xmis; x++) {
-      int map_offset = block_index + y * cm->mi_cols + x;
-      cr->map[map_offset] = new_map_value;
-      cpi->segmentation_map[map_offset] = mi->segment_id;
-    }
-}
-
-void vp9_cyclic_refresh_update_sb_postencode(VP9_COMP *const cpi,
-                                             const MODE_INFO *const mi,
-                                             int mi_row, int mi_col,
-                                             BLOCK_SIZE bsize) {
-  const VP9_COMMON *const cm = &cpi->common;
-  CYCLIC_REFRESH *const cr = cpi->cyclic_refresh;
-  const int bw = num_8x8_blocks_wide_lookup[bsize];
-  const int bh = num_8x8_blocks_high_lookup[bsize];
-  const int xmis = VPXMIN(cm->mi_cols - mi_col, bw);
-  const int ymis = VPXMIN(cm->mi_rows - mi_row, bh);
-  const int block_index = mi_row * cm->mi_cols + mi_col;
-  int x, y;
-  for (y = 0; y < ymis; y++)
-    for (x = 0; x < xmis; x++) {
-      int map_offset = block_index + y * cm->mi_cols + x;
-      // Inter skip blocks were clearly not coded at the current qindex, so
-      // don't update the map for them. For cases where motion is non-zero or
-      // the reference frame isn't the previous frame, the previous value in
-      // the map for this spatial location is not entirely correct.
-      if ((!is_inter_block(mi) || !mi->skip) &&
-          mi->segment_id <= CR_SEGMENT_ID_BOOST2) {
-        cr->last_coded_q_map[map_offset] = clamp(
-            cm->base_qindex + cr->qindex_delta[mi->segment_id], 0, MAXQ);
-      } else if (is_inter_block(mi) && mi->skip &&
-                 mi->segment_id <= CR_SEGMENT_ID_BOOST2) {
-        cr->last_coded_q_map[map_offset] = VPXMIN(
-            clamp(cm->base_qindex + cr->qindex_delta[mi->segment_id],
-                  0, MAXQ),
-            cr->last_coded_q_map[map_offset]);
-      }
-    }
-}
-
-// Update the actual number of blocks that were applied the segment delta q.
-void vp9_cyclic_refresh_postencode(VP9_COMP *const cpi) {
-  VP9_COMMON *const cm = &cpi->common;
-  CYCLIC_REFRESH *const cr = cpi->cyclic_refresh;
-  unsigned char *const seg_map = cpi->segmentation_map;
-  int mi_row, mi_col;
-  cr->actual_num_seg1_blocks = 0;
-  cr->actual_num_seg2_blocks = 0;
-  for (mi_row = 0; mi_row < cm->mi_rows; mi_row++)
-    for (mi_col = 0; mi_col < cm->mi_cols; mi_col++) {
-      if (cyclic_refresh_segment_id(
-          seg_map[mi_row * cm->mi_cols + mi_col]) == CR_SEGMENT_ID_BOOST1)
-        cr->actual_num_seg1_blocks++;
-      else if (cyclic_refresh_segment_id(
-          seg_map[mi_row * cm->mi_cols + mi_col]) == CR_SEGMENT_ID_BOOST2)
-        cr->actual_num_seg2_blocks++;
-    }
-}
-
-// Set golden frame update interval, for non-svc 1 pass CBR mode.
-void vp9_cyclic_refresh_set_golden_update(VP9_COMP *const cpi) {
-  RATE_CONTROL *const rc = &cpi->rc;
-  CYCLIC_REFRESH *const cr = cpi->cyclic_refresh;
-  // Set minimum gf_interval for GF update to a multiple of the refresh period,
-  // with some max limit. Depending on past encoding stats, GF flag may be
-  // reset and update may not occur until next baseline_gf_interval.
-  if (cr->percent_refresh > 0)
-    rc->baseline_gf_interval = VPXMIN(4 * (100 / cr->percent_refresh), 40);
-  else
-    rc->baseline_gf_interval = 40;
-  if (cpi->oxcf.rc_mode == VPX_VBR)
-    rc->baseline_gf_interval = 20;
-}
-
-// Update some encoding stats (from the just encoded frame). If this frame's
-// background has high motion, refresh the golden frame. Otherwise, if the
-// golden reference is to be updated check if we should NOT update the golden
-// ref.
-void vp9_cyclic_refresh_check_golden_update(VP9_COMP *const cpi) {
-  VP9_COMMON *const cm = &cpi->common;
-  CYCLIC_REFRESH *const cr = cpi->cyclic_refresh;
-  int mi_row, mi_col;
-  double fraction_low = 0.0;
-  int low_content_frame = 0;
-  MODE_INFO **mi = cm->mi_grid_visible;
-  RATE_CONTROL *const rc = &cpi->rc;
-  const int rows = cm->mi_rows, cols = cm->mi_cols;
-  int cnt1 = 0, cnt2 = 0;
-  int force_gf_refresh = 0;
-  int flag_force_gf_high_motion = 0;
-  for (mi_row = 0; mi_row < rows; mi_row++) {
-    for (mi_col = 0; mi_col < cols; mi_col++) {
-      if (flag_force_gf_high_motion == 1) {
-        int16_t abs_mvr = mi[0]->mv[0].as_mv.row >= 0 ?
-            mi[0]->mv[0].as_mv.row : -1 * mi[0]->mv[0].as_mv.row;
-        int16_t abs_mvc = mi[0]->mv[0].as_mv.col >= 0 ?
-            mi[0]->mv[0].as_mv.col : -1 * mi[0]->mv[0].as_mv.col;
-        // Calculate the motion of the background.
-        if (abs_mvr <= 16 && abs_mvc <= 16) {
-          cnt1++;
-          if (abs_mvr == 0 && abs_mvc == 0)
-            cnt2++;
-        }
-      }
-      mi++;
-      // Accumulate low_content_frame.
-      if (cr->map[mi_row * cols + mi_col] < 1)
-        low_content_frame++;
-    }
-    mi += 8;
-  }
-  // For video conference clips, if the background has high motion in current
-  // frame because of the camera movement, set this frame as the golden frame.
-  // Use 70% and 5% as the thresholds for golden frame refreshing.
-  // Also, force this frame as a golden update frame if this frame will change
-  // the resolution (resize_pending != 0).
-  if (cpi->resize_pending != 0 ||
-     (cnt1 * 100 > (70 * rows * cols) && cnt2 * 20 < cnt1)) {
-    vp9_cyclic_refresh_set_golden_update(cpi);
-    rc->frames_till_gf_update_due = rc->baseline_gf_interval;
-
-    if (rc->frames_till_gf_update_due > rc->frames_to_key)
-      rc->frames_till_gf_update_due = rc->frames_to_key;
-    cpi->refresh_golden_frame = 1;
-    force_gf_refresh = 1;
-  }
-  fraction_low =
-      (double)low_content_frame / (rows * cols);
-  // Update average.
-  cr->low_content_avg = (fraction_low + 3 * cr->low_content_avg) / 4;
-  if (!force_gf_refresh && cpi->refresh_golden_frame == 1) {
-    // Don't update golden reference if the amount of low_content for the
-    // current encoded frame is small, or if the recursive average of the
-    // low_content over the update interval window falls below threshold.
-    if (fraction_low < 0.8 || cr->low_content_avg < 0.7)
-      cpi->refresh_golden_frame = 0;
-    // Reset for next internal.
-    cr->low_content_avg = fraction_low;
-  }
-}
-
-// Update the segmentation map, and related quantities: cyclic refresh map,
-// refresh sb_index, and target number of blocks to be refreshed.
-// The map is set to either 0/CR_SEGMENT_ID_BASE (no refresh) or to
-// 1/CR_SEGMENT_ID_BOOST1 (refresh) for each superblock.
-// Blocks labeled as BOOST1 may later get set to BOOST2 (during the
-// encoding of the superblock).
-static void cyclic_refresh_update_map(VP9_COMP *const cpi) {
-  VP9_COMMON *const cm = &cpi->common;
-  CYCLIC_REFRESH *const cr = cpi->cyclic_refresh;
-  unsigned char *const seg_map = cpi->segmentation_map;
-  int i, block_count, bl_index, sb_rows, sb_cols, sbs_in_frame;
-  int xmis, ymis, x, y;
-  int consec_zero_mv_thresh = 0;
-  int qindex_thresh = 0;
-  int count_sel = 0;
-  int count_tot = 0;
-  memset(seg_map, CR_SEGMENT_ID_BASE, cm->mi_rows * cm->mi_cols);
-  sb_cols = (cm->mi_cols + MI_BLOCK_SIZE - 1) / MI_BLOCK_SIZE;
-  sb_rows = (cm->mi_rows + MI_BLOCK_SIZE - 1) / MI_BLOCK_SIZE;
-  sbs_in_frame = sb_cols * sb_rows;
-  // Number of target blocks to get the q delta (segment 1).
-  block_count = cr->percent_refresh * cm->mi_rows * cm->mi_cols / 100;
-  // Set the segmentation map: cycle through the superblocks, starting at
-  // cr->mb_index, and stopping when either block_count blocks have been found
-  // to be refreshed, or we have passed through whole frame.
-  assert(cr->sb_index < sbs_in_frame);
-  i = cr->sb_index;
-  cr->target_num_seg_blocks = 0;
-  if (cpi->oxcf.content != VP9E_CONTENT_SCREEN) {
-    consec_zero_mv_thresh = 100;
-  }
-  qindex_thresh =
-      cpi->oxcf.content == VP9E_CONTENT_SCREEN
-      ? vp9_get_qindex(&cm->seg, CR_SEGMENT_ID_BOOST2, cm->base_qindex)
-      : vp9_get_qindex(&cm->seg, CR_SEGMENT_ID_BOOST1, cm->base_qindex);
-  // More aggressive settings for noisy content.
-  if (cpi->noise_estimate.enabled && cpi->noise_estimate.level >= kMedium) {
-    consec_zero_mv_thresh = 80;
-    qindex_thresh =
-        VPXMAX(vp9_get_qindex(&cm->seg, CR_SEGMENT_ID_BOOST1, cm->base_qindex),
-                              7 * cm->base_qindex >> 3);
-  }
-  do {
-    int sum_map = 0;
-    // Get the mi_row/mi_col corresponding to superblock index i.
-    int sb_row_index = (i / sb_cols);
-    int sb_col_index = i - sb_row_index * sb_cols;
-    int mi_row = sb_row_index * MI_BLOCK_SIZE;
-    int mi_col = sb_col_index * MI_BLOCK_SIZE;
-    assert(mi_row >= 0 && mi_row < cm->mi_rows);
-    assert(mi_col >= 0 && mi_col < cm->mi_cols);
-    bl_index = mi_row * cm->mi_cols + mi_col;
-    // Loop through all 8x8 blocks in superblock and update map.
-    xmis =
-        VPXMIN(cm->mi_cols - mi_col, num_8x8_blocks_wide_lookup[BLOCK_64X64]);
-    ymis =
-        VPXMIN(cm->mi_rows - mi_row, num_8x8_blocks_high_lookup[BLOCK_64X64]);
-    for (y = 0; y < ymis; y++) {
-      for (x = 0; x < xmis; x++) {
-        const int bl_index2 = bl_index + y * cm->mi_cols + x;
-        // If the block is as a candidate for clean up then mark it
-        // for possible boost/refresh (segment 1). The segment id may get
-        // reset to 0 later if block gets coded anything other than ZEROMV.
-        if (cr->map[bl_index2] == 0) {
-          count_tot++;
-          if (cr->last_coded_q_map[bl_index2] > qindex_thresh ||
-              cpi->consec_zero_mv[bl_index2] < consec_zero_mv_thresh) {
-            sum_map++;
-            count_sel++;
-          }
-        } else if (cr->map[bl_index2] < 0) {
-          cr->map[bl_index2]++;
-        }
-      }
-    }
-    // Enforce constant segment over superblock.
-    // If segment is at least half of superblock, set to 1.
-    if (sum_map >= xmis * ymis / 2) {
-      for (y = 0; y < ymis; y++)
-        for (x = 0; x < xmis; x++) {
-          seg_map[bl_index + y * cm->mi_cols + x] = CR_SEGMENT_ID_BOOST1;
-        }
-      cr->target_num_seg_blocks += xmis * ymis;
-    }
-    i++;
-    if (i == sbs_in_frame) {
-      i = 0;
-    }
-  } while (cr->target_num_seg_blocks < block_count && i != cr->sb_index);
-  cr->sb_index = i;
-  cr->reduce_refresh = 0;
-  if (count_sel < (3 * count_tot) >> 2)
-    cr->reduce_refresh = 1;
-}
-
-// Set cyclic refresh parameters.
-void vp9_cyclic_refresh_update_parameters(VP9_COMP *const cpi) {
-  const RATE_CONTROL *const rc = &cpi->rc;
-  const VP9_COMMON *const cm = &cpi->common;
-  CYCLIC_REFRESH *const cr = cpi->cyclic_refresh;
-  cr->percent_refresh = 10;
-  if (cr->reduce_refresh)
-    cr->percent_refresh = 5;
-  cr->max_qdelta_perc = 50;
-  cr->time_for_refresh = 0;
-  cr->motion_thresh = 32;
-  cr->rate_boost_fac = 15;
-  // Use larger delta-qp (increase rate_ratio_qdelta) for first few (~4)
-  // periods of the refresh cycle, after a key frame.
-  // Account for larger interval on base layer for temporal layers.
-  if (cr->percent_refresh > 0 &&
-      rc->frames_since_key <  (4 * cpi->svc.number_temporal_layers) *
-      (100 / cr->percent_refresh)) {
-    cr->rate_ratio_qdelta = 3.0;
-  } else {
-    cr->rate_ratio_qdelta = 2.0;
-    if (cpi->noise_estimate.enabled && cpi->noise_estimate.level >= kMedium) {
-      // Reduce the delta-qp if the estimated source noise is above threshold.
-      cr->rate_ratio_qdelta = 1.7;
-      cr->rate_boost_fac = 13;
-    }
-  }
-  // Adjust some parameters for low resolutions at low bitrates.
-  if (cm->width <= 352 &&
-      cm->height <= 288 &&
-      rc->avg_frame_bandwidth < 3400) {
-    cr->motion_thresh = 4;
-    cr->rate_boost_fac = 10;
-  }
-  if (cpi->svc.spatial_layer_id > 0) {
-    cr->motion_thresh = 4;
-    cr->rate_boost_fac = 12;
-  }
-  if (cpi->oxcf.rc_mode == VPX_VBR) {
-    // To be adjusted for VBR mode, e.g., based on gf period and boost.
-    // For now use smaller qp-delta (than CBR), no second boosted seg, and
-    // turn-off (no refresh) on golden refresh (since it's already boosted).
-    cr->percent_refresh = 10;
-    cr->rate_ratio_qdelta = 1.5;
-    cr->rate_boost_fac = 10;
-    if (cpi->refresh_golden_frame == 1) {
-      cr->percent_refresh = 0;
-      cr->rate_ratio_qdelta = 1.0;
-    }
-  }
-}
-
-// Setup cyclic background refresh: set delta q and segmentation map.
-void vp9_cyclic_refresh_setup(VP9_COMP *const cpi) {
-  VP9_COMMON *const cm = &cpi->common;
-  const RATE_CONTROL *const rc = &cpi->rc;
-  CYCLIC_REFRESH *const cr = cpi->cyclic_refresh;
-  struct segmentation *const seg = &cm->seg;
-  // TODO(marpan): Look into whether we should reduce the amount/delta-qp
-  // instead of completely shutting off at low bitrates. For now keep it on.
-  // const int apply_cyclic_refresh = apply_cyclic_refresh_bitrate(cm, rc);
-  const int apply_cyclic_refresh = 1;
-  if (cm->current_video_frame == 0)
-    cr->low_content_avg = 0.0;
-  // Don't apply refresh on key frame or temporal enhancement layer frames.
-  if (!apply_cyclic_refresh ||
-      (cm->frame_type == KEY_FRAME) ||
-      (cpi->svc.temporal_layer_id > 0)) {
-    // Set segmentation map to 0 and disable.
-    unsigned char *const seg_map = cpi->segmentation_map;
-    memset(seg_map, 0, cm->mi_rows * cm->mi_cols);
-    vp9_disable_segmentation(&cm->seg);
-    if (cm->frame_type == KEY_FRAME) {
-      memset(cr->last_coded_q_map, MAXQ,
-             cm->mi_rows * cm->mi_cols * sizeof(*cr->last_coded_q_map));
-      cr->sb_index = 0;
-    }
-    return;
-  } else {
-    int qindex_delta = 0;
-    int qindex2;
-    const double q = vp9_convert_qindex_to_q(cm->base_qindex, cm->bit_depth);
-    vpx_clear_system_state();
-    // Set rate threshold to some multiple (set to 2 for now) of the target
-    // rate (target is given by sb64_target_rate and scaled by 256).
-    cr->thresh_rate_sb = ((int64_t)(rc->sb64_target_rate) << 8) << 2;
-    // Distortion threshold, quadratic in Q, scale factor to be adjusted.
-    // q will not exceed 457, so (q * q) is within 32bit; see:
-    // vp9_convert_qindex_to_q(), vp9_ac_quant(), ac_qlookup*[].
-    cr->thresh_dist_sb = ((int64_t)(q * q)) << 2;
-
-    // Set up segmentation.
-    // Clear down the segment map.
-    vp9_enable_segmentation(&cm->seg);
-    vp9_clearall_segfeatures(seg);
-    // Select delta coding method.
-    seg->abs_delta = SEGMENT_DELTADATA;
-
-    // Note: setting temporal_update has no effect, as the seg-map coding method
-    // (temporal or spatial) is determined in vp9_choose_segmap_coding_method(),
-    // based on the coding cost of each method. For error_resilient mode on the
-    // last_frame_seg_map is set to 0, so if temporal coding is used, it is
-    // relative to 0 previous map.
-    // seg->temporal_update = 0;
-
-    // Segment BASE "Q" feature is disabled so it defaults to the baseline Q.
-    vp9_disable_segfeature(seg, CR_SEGMENT_ID_BASE, SEG_LVL_ALT_Q);
-    // Use segment BOOST1 for in-frame Q adjustment.
-    vp9_enable_segfeature(seg, CR_SEGMENT_ID_BOOST1, SEG_LVL_ALT_Q);
-    // Use segment BOOST2 for more aggressive in-frame Q adjustment.
-    vp9_enable_segfeature(seg, CR_SEGMENT_ID_BOOST2, SEG_LVL_ALT_Q);
-
-    // Set the q delta for segment BOOST1.
-    qindex_delta = compute_deltaq(cpi, cm->base_qindex, cr->rate_ratio_qdelta);
-    cr->qindex_delta[1] = qindex_delta;
-
-    // Compute rd-mult for segment BOOST1.
-    qindex2 = clamp(cm->base_qindex + cm->y_dc_delta_q + qindex_delta, 0, MAXQ);
-
-    cr->rdmult = vp9_compute_rd_mult(cpi, qindex2);
-
-    vp9_set_segdata(seg, CR_SEGMENT_ID_BOOST1, SEG_LVL_ALT_Q, qindex_delta);
-
-    // Set a more aggressive (higher) q delta for segment BOOST2.
-    qindex_delta = compute_deltaq(
-        cpi, cm->base_qindex,
-        VPXMIN(CR_MAX_RATE_TARGET_RATIO,
-               0.1 * cr->rate_boost_fac * cr->rate_ratio_qdelta));
-    cr->qindex_delta[2] = qindex_delta;
-    vp9_set_segdata(seg, CR_SEGMENT_ID_BOOST2, SEG_LVL_ALT_Q, qindex_delta);
-
-    // Reset if resoluton change has occurred.
-    if (cpi->resize_pending != 0)
-      vp9_cyclic_refresh_reset_resize(cpi);
-
-    // Update the segmentation and refresh map.
-    cyclic_refresh_update_map(cpi);
-  }
-}
-
-int vp9_cyclic_refresh_get_rdmult(const CYCLIC_REFRESH *cr) {
-  return cr->rdmult;
-}
-
-void vp9_cyclic_refresh_reset_resize(VP9_COMP *const cpi) {
-  const VP9_COMMON *const cm = &cpi->common;
-  CYCLIC_REFRESH *const cr = cpi->cyclic_refresh;
-  memset(cr->map, 0, cm->mi_rows * cm->mi_cols);
-  memset(cr->last_coded_q_map, MAXQ, cm->mi_rows * cm->mi_cols);
-  cr->sb_index = 0;
-  cpi->refresh_golden_frame = 1;
-  cpi->refresh_alt_ref_frame = 1;
-}
diff --git a/vp9/encoder/vp9_aq_cyclicrefresh.h b/vp9/encoder/vp9_aq_cyclicrefresh.h
deleted file mode 100644 (file)
index 35eea18..0000000
+++ /dev/null
@@ -1,145 +0,0 @@
-/*
- *  Copyright (c) 2014 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.
- */
-
-
-#ifndef VP9_ENCODER_VP9_AQ_CYCLICREFRESH_H_
-#define VP9_ENCODER_VP9_AQ_CYCLICREFRESH_H_
-
-#include "vpx/vpx_integer.h"
-#include "vp9/common/vp9_blockd.h"
-#include "vp9/encoder/vp9_block.h"
-#include "vp9/encoder/vp9_skin_detection.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-// The segment ids used in cyclic refresh: from base (no boost) to increasing
-// boost (higher delta-qp).
-#define CR_SEGMENT_ID_BASE    0
-#define CR_SEGMENT_ID_BOOST1  1
-#define CR_SEGMENT_ID_BOOST2  2
-
-// Maximum rate target ratio for setting segment delta-qp.
-#define CR_MAX_RATE_TARGET_RATIO 4.0
-
-struct CYCLIC_REFRESH {
-  // Percentage of blocks per frame that are targeted as candidates
-  // for cyclic refresh.
-  int percent_refresh;
-  // Maximum q-delta as percentage of base q.
-  int max_qdelta_perc;
-  // Superblock starting index for cycling through the frame.
-  int sb_index;
-  // Controls how long block will need to wait to be refreshed again, in
-  // excess of the cycle time, i.e., in the case of all zero motion, block
-  // will be refreshed every (100/percent_refresh + time_for_refresh) frames.
-  int time_for_refresh;
-  // Target number of (8x8) blocks that are set for delta-q.
-  int target_num_seg_blocks;
-  // Actual number of (8x8) blocks that were applied delta-q.
-  int actual_num_seg1_blocks;
-  int actual_num_seg2_blocks;
-  // RD mult. parameters for segment 1.
-  int rdmult;
-  // Cyclic refresh map.
-  signed char *map;
-  // Map of the last q a block was coded at.
-  uint8_t *last_coded_q_map;
-  // Thresholds applied to the projected rate/distortion of the coding block,
-  // when deciding whether block should be refreshed.
-  int64_t thresh_rate_sb;
-  int64_t thresh_dist_sb;
-  // Threshold applied to the motion vector (in units of 1/8 pel) of the
-  // coding block, when deciding whether block should be refreshed.
-  int16_t motion_thresh;
-  // Rate target ratio to set q delta.
-  double rate_ratio_qdelta;
-  // Boost factor for rate target ratio, for segment CR_SEGMENT_ID_BOOST2.
-  int rate_boost_fac;
-  double low_content_avg;
-  int qindex_delta[3];
-  int reduce_refresh;
-};
-
-struct VP9_COMP;
-
-typedef struct CYCLIC_REFRESH CYCLIC_REFRESH;
-
-CYCLIC_REFRESH *vp9_cyclic_refresh_alloc(int mi_rows, int mi_cols);
-
-void vp9_cyclic_refresh_free(CYCLIC_REFRESH *cr);
-
-// Estimate the bits, incorporating the delta-q from segment 1, after encoding
-// the frame.
-int vp9_cyclic_refresh_estimate_bits_at_q(const struct VP9_COMP *cpi,
-                                          double correction_factor);
-
-// Estimate the bits per mb, for a given q = i and a corresponding delta-q
-// (for segment 1), prior to encoding the frame.
-int vp9_cyclic_refresh_rc_bits_per_mb(const struct VP9_COMP *cpi, int i,
-                                      double correction_factor);
-
-// Prior to coding a given prediction block, of size bsize at (mi_row, mi_col),
-// check if we should reset the segment_id, and update the cyclic_refresh map
-// and segmentation map.
-void vp9_cyclic_refresh_update_segment(struct VP9_COMP *const cpi,
-                                       MODE_INFO *const mi,
-                                       int mi_row, int mi_col, BLOCK_SIZE bsize,
-                                       int64_t rate, int64_t dist, int skip,
-                                       struct macroblock_plane *const p);
-
-void vp9_cyclic_refresh_update_sb_postencode(struct VP9_COMP *const cpi,
-                                             const MODE_INFO *const mi,
-                                             int mi_row, int mi_col,
-                                             BLOCK_SIZE bsize);
-
-// Update the segmentation map, and related quantities: cyclic refresh map,
-// refresh sb_index, and target number of blocks to be refreshed.
-void vp9_cyclic_refresh_update__map(struct VP9_COMP *const cpi);
-
-// Update the actual number of blocks that were applied the segment delta q.
-void vp9_cyclic_refresh_postencode(struct VP9_COMP *const cpi);
-
-// Set golden frame update interval, for non-svc 1 pass CBR mode.
-void vp9_cyclic_refresh_set_golden_update(struct VP9_COMP *const cpi);
-
-// Check if we should not update golden reference, based on past refresh stats.
-void vp9_cyclic_refresh_check_golden_update(struct VP9_COMP *const cpi);
-
-// Set/update global/frame level refresh parameters.
-void vp9_cyclic_refresh_update_parameters(struct VP9_COMP *const cpi);
-
-// Setup cyclic background refresh: set delta q and segmentation map.
-void vp9_cyclic_refresh_setup(struct VP9_COMP *const cpi);
-
-int vp9_cyclic_refresh_get_rdmult(const CYCLIC_REFRESH *cr);
-
-void vp9_cyclic_refresh_reset_resize(struct VP9_COMP *const cpi);
-
-static INLINE int cyclic_refresh_segment_id_boosted(int segment_id) {
-  return segment_id == CR_SEGMENT_ID_BOOST1 ||
-         segment_id == CR_SEGMENT_ID_BOOST2;
-}
-
-static INLINE int cyclic_refresh_segment_id(int segment_id) {
-  if (segment_id == CR_SEGMENT_ID_BOOST1)
-    return CR_SEGMENT_ID_BOOST1;
-  else if (segment_id == CR_SEGMENT_ID_BOOST2)
-    return CR_SEGMENT_ID_BOOST2;
-  else
-    return CR_SEGMENT_ID_BASE;
-}
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP9_ENCODER_VP9_AQ_CYCLICREFRESH_H_
diff --git a/vp9/encoder/vp9_aq_variance.c b/vp9/encoder/vp9_aq_variance.c
deleted file mode 100644 (file)
index 59ef5fa..0000000
+++ /dev/null
@@ -1,207 +0,0 @@
-/*
- *  Copyright (c) 2013 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.
- */
-
-#include <math.h>
-
-#include "vpx_ports/mem.h"
-#include "vpx_ports/system_state.h"
-
-#include "vp9/encoder/vp9_aq_variance.h"
-
-#include "vp9/common/vp9_seg_common.h"
-
-#include "vp9/encoder/vp9_ratectrl.h"
-#include "vp9/encoder/vp9_rd.h"
-#include "vp9/encoder/vp9_segmentation.h"
-
-#define ENERGY_MIN (-4)
-#define ENERGY_MAX (1)
-#define ENERGY_SPAN (ENERGY_MAX - ENERGY_MIN +  1)
-#define ENERGY_IN_BOUNDS(energy)\
-  assert((energy) >= ENERGY_MIN && (energy) <= ENERGY_MAX)
-
-static const double rate_ratio[MAX_SEGMENTS] =
-  {2.5, 2.0, 1.5, 1.0, 0.75, 1.0, 1.0, 1.0};
-static const int segment_id[ENERGY_SPAN] = {0, 1, 1, 2, 3, 4};
-
-#define SEGMENT_ID(i) segment_id[(i) - ENERGY_MIN]
-
-DECLARE_ALIGNED(16, static const uint8_t, vp9_64_zeros[64]) = {0};
-#if CONFIG_VP9_HIGHBITDEPTH
-DECLARE_ALIGNED(16, static const uint16_t, vp9_highbd_64_zeros[64]) = {0};
-#endif
-
-unsigned int vp9_vaq_segment_id(int energy) {
-  ENERGY_IN_BOUNDS(energy);
-  return SEGMENT_ID(energy);
-}
-
-void vp9_vaq_frame_setup(VP9_COMP *cpi) {
-  VP9_COMMON *cm = &cpi->common;
-  struct segmentation *seg = &cm->seg;
-  int i;
-
-  if (frame_is_intra_only(cm) || cm->error_resilient_mode ||
-      cpi->refresh_alt_ref_frame ||
-      (cpi->refresh_golden_frame && !cpi->rc.is_src_frame_alt_ref)) {
-    vp9_enable_segmentation(seg);
-    vp9_clearall_segfeatures(seg);
-
-    seg->abs_delta = SEGMENT_DELTADATA;
-
-    vpx_clear_system_state();
-
-    for (i = 0; i < MAX_SEGMENTS; ++i) {
-      int qindex_delta =
-          vp9_compute_qdelta_by_rate(&cpi->rc, cm->frame_type, cm->base_qindex,
-                                     rate_ratio[i], cm->bit_depth);
-
-      // We don't allow qindex 0 in a segment if the base value is not 0.
-      // Q index 0 (lossless) implies 4x4 encoding only and in AQ mode a segment
-      // Q delta is sometimes applied without going back around the rd loop.
-      // This could lead to an illegal combination of partition size and q.
-      if ((cm->base_qindex != 0) && ((cm->base_qindex + qindex_delta) == 0)) {
-        qindex_delta = -cm->base_qindex + 1;
-      }
-
-      // No need to enable SEG_LVL_ALT_Q for this segment.
-      if (rate_ratio[i] == 1.0) {
-        continue;
-      }
-
-      vp9_set_segdata(seg, i, SEG_LVL_ALT_Q, qindex_delta);
-      vp9_enable_segfeature(seg, i, SEG_LVL_ALT_Q);
-    }
-  }
-}
-
-/* TODO(agrange, paulwilkins): The block_variance calls the unoptimized versions
- * of variance() and highbd_8_variance(). It should not.
- */
-static void aq_variance(const uint8_t *a, int  a_stride,
-                        const uint8_t *b, int  b_stride,
-                        int  w, int  h, unsigned int *sse, int *sum) {
-  int i, j;
-
-  *sum = 0;
-  *sse = 0;
-
-  for (i = 0; i < h; i++) {
-    for (j = 0; j < w; j++) {
-      const int diff = a[j] - b[j];
-      *sum += diff;
-      *sse += diff * diff;
-    }
-
-    a += a_stride;
-    b += b_stride;
-  }
-}
-
-#if CONFIG_VP9_HIGHBITDEPTH
-static void aq_highbd_variance64(const uint8_t *a8, int  a_stride,
-                                 const uint8_t *b8, int  b_stride,
-                                 int w, int h, uint64_t *sse, uint64_t *sum) {
-  int i, j;
-
-  uint16_t *a = CONVERT_TO_SHORTPTR(a8);
-  uint16_t *b = CONVERT_TO_SHORTPTR(b8);
-  *sum = 0;
-  *sse = 0;
-
-  for (i = 0; i < h; i++) {
-    for (j = 0; j < w; j++) {
-      const int diff = a[j] - b[j];
-      *sum += diff;
-      *sse += diff * diff;
-    }
-    a += a_stride;
-    b += b_stride;
-  }
-}
-
-static void aq_highbd_8_variance(const uint8_t *a8, int  a_stride,
-                                 const uint8_t *b8, int  b_stride,
-                                 int w, int h, unsigned int *sse, int *sum) {
-  uint64_t sse_long = 0;
-  uint64_t sum_long = 0;
-  aq_highbd_variance64(a8, a_stride, b8, b_stride, w, h, &sse_long, &sum_long);
-  *sse = (unsigned int)sse_long;
-  *sum = (int)sum_long;
-}
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-
-static unsigned int block_variance(VP9_COMP *cpi, MACROBLOCK *x,
-                                   BLOCK_SIZE bs) {
-  MACROBLOCKD *xd = &x->e_mbd;
-  unsigned int var, sse;
-  int right_overflow = (xd->mb_to_right_edge < 0) ?
-      ((-xd->mb_to_right_edge) >> 3) : 0;
-  int bottom_overflow = (xd->mb_to_bottom_edge < 0) ?
-      ((-xd->mb_to_bottom_edge) >> 3) : 0;
-
-  if (right_overflow || bottom_overflow) {
-    const int bw = 8 * num_8x8_blocks_wide_lookup[bs] - right_overflow;
-    const int bh = 8 * num_8x8_blocks_high_lookup[bs] - bottom_overflow;
-    int avg;
-#if CONFIG_VP9_HIGHBITDEPTH
-    if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
-      aq_highbd_8_variance(x->plane[0].src.buf, x->plane[0].src.stride,
-                           CONVERT_TO_BYTEPTR(vp9_highbd_64_zeros), 0, bw, bh,
-                           &sse, &avg);
-      sse >>= 2 * (xd->bd - 8);
-      avg >>= (xd->bd - 8);
-    } else {
-      aq_variance(x->plane[0].src.buf, x->plane[0].src.stride,
-                  vp9_64_zeros, 0, bw, bh, &sse, &avg);
-    }
-#else
-    aq_variance(x->plane[0].src.buf, x->plane[0].src.stride,
-                vp9_64_zeros, 0, bw, bh, &sse, &avg);
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-    var = sse - (((int64_t)avg * avg) / (bw * bh));
-    return (unsigned int)(((uint64_t)256 * var) / (bw * bh));
-  } else {
-#if CONFIG_VP9_HIGHBITDEPTH
-    if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
-      var = cpi->fn_ptr[bs].vf(x->plane[0].src.buf,
-                               x->plane[0].src.stride,
-                               CONVERT_TO_BYTEPTR(vp9_highbd_64_zeros),
-                               0, &sse);
-    } else {
-      var = cpi->fn_ptr[bs].vf(x->plane[0].src.buf,
-                               x->plane[0].src.stride,
-                               vp9_64_zeros, 0, &sse);
-    }
-#else
-    var = cpi->fn_ptr[bs].vf(x->plane[0].src.buf,
-                             x->plane[0].src.stride,
-                             vp9_64_zeros, 0, &sse);
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-    return (unsigned int)(((uint64_t)256 * var) >> num_pels_log2_lookup[bs]);
-  }
-}
-
-double vp9_log_block_var(VP9_COMP *cpi, MACROBLOCK *x, BLOCK_SIZE bs) {
-  unsigned int var = block_variance(cpi, x, bs);
-  vpx_clear_system_state();
-  return log(var + 1.0);
-}
-
-#define DEFAULT_E_MIDPOINT 10.0
-int vp9_block_energy(VP9_COMP *cpi, MACROBLOCK *x, BLOCK_SIZE bs) {
-  double energy;
-  double energy_midpoint;
-  vpx_clear_system_state();
-  energy_midpoint =
-    (cpi->oxcf.pass == 2) ? cpi->twopass.mb_av_energy : DEFAULT_E_MIDPOINT;
-  energy = vp9_log_block_var(cpi, x, bs) - energy_midpoint;
-  return clamp((int)round(energy), ENERGY_MIN, ENERGY_MAX);
-}
diff --git a/vp9/encoder/vp9_aq_variance.h b/vp9/encoder/vp9_aq_variance.h
deleted file mode 100644 (file)
index a0effa3..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- *  Copyright (c) 2013 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.
- */
-
-
-#ifndef VP9_ENCODER_VP9_AQ_VARIANCE_H_
-#define VP9_ENCODER_VP9_AQ_VARIANCE_H_
-
-#include "vp9/encoder/vp9_encoder.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-unsigned int vp9_vaq_segment_id(int energy);
-void vp9_vaq_frame_setup(VP9_COMP *cpi);
-
-int vp9_block_energy(VP9_COMP *cpi, MACROBLOCK *x, BLOCK_SIZE bs);
-double vp9_log_block_var(VP9_COMP *cpi, MACROBLOCK *x, BLOCK_SIZE bs);
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP9_ENCODER_VP9_AQ_VARIANCE_H_
diff --git a/vp9/encoder/vp9_bitstream.c b/vp9/encoder/vp9_bitstream.c
deleted file mode 100644 (file)
index 73a2db0..0000000
+++ /dev/null
@@ -1,1245 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#include <assert.h>
-#include <stdio.h>
-#include <limits.h>
-
-#include "vpx/vpx_encoder.h"
-#include "vpx_dsp/bitwriter_buffer.h"
-#include "vpx_dsp/vpx_dsp_common.h"
-#include "vpx_mem/vpx_mem.h"
-#include "vpx_ports/mem_ops.h"
-#include "vpx_ports/system_state.h"
-
-#include "vp9/common/vp9_entropy.h"
-#include "vp9/common/vp9_entropymode.h"
-#include "vp9/common/vp9_entropymv.h"
-#include "vp9/common/vp9_mvref_common.h"
-#include "vp9/common/vp9_pred_common.h"
-#include "vp9/common/vp9_seg_common.h"
-#include "vp9/common/vp9_tile_common.h"
-
-#include "vp9/encoder/vp9_cost.h"
-#include "vp9/encoder/vp9_bitstream.h"
-#include "vp9/encoder/vp9_encodemv.h"
-#include "vp9/encoder/vp9_mcomp.h"
-#include "vp9/encoder/vp9_segmentation.h"
-#include "vp9/encoder/vp9_subexp.h"
-#include "vp9/encoder/vp9_tokenize.h"
-
-static const struct vp9_token intra_mode_encodings[INTRA_MODES] = {
-  {0, 1}, {6, 3}, {28, 5}, {30, 5}, {58, 6}, {59, 6}, {126, 7}, {127, 7},
-  {62, 6}, {2, 2}};
-static const struct vp9_token switchable_interp_encodings[SWITCHABLE_FILTERS] =
-  {{0, 1}, {2, 2}, {3, 2}};
-static const struct vp9_token partition_encodings[PARTITION_TYPES] =
-  {{0, 1}, {2, 2}, {6, 3}, {7, 3}};
-static const struct vp9_token inter_mode_encodings[INTER_MODES] =
-  {{2, 2}, {6, 3}, {0, 1}, {7, 3}};
-
-static void write_intra_mode(vpx_writer *w, PREDICTION_MODE mode,
-                             const vpx_prob *probs) {
-  vp9_write_token(w, vp9_intra_mode_tree, probs, &intra_mode_encodings[mode]);
-}
-
-static void write_inter_mode(vpx_writer *w, PREDICTION_MODE mode,
-                             const vpx_prob *probs) {
-  assert(is_inter_mode(mode));
-  vp9_write_token(w, vp9_inter_mode_tree, probs,
-                  &inter_mode_encodings[INTER_OFFSET(mode)]);
-}
-
-static void encode_unsigned_max(struct vpx_write_bit_buffer *wb,
-                                int data, int max) {
-  vpx_wb_write_literal(wb, data, get_unsigned_bits(max));
-}
-
-static void prob_diff_update(const vpx_tree_index *tree,
-                             vpx_prob probs[/*n - 1*/],
-                             const unsigned int counts[/*n - 1*/],
-                             int n, vpx_writer *w) {
-  int i;
-  unsigned int branch_ct[32][2];
-
-  // Assuming max number of probabilities <= 32
-  assert(n <= 32);
-
-  vp9_tree_probs_from_distribution(tree, branch_ct, counts);
-  for (i = 0; i < n - 1; ++i)
-    vp9_cond_prob_diff_update(w, &probs[i], branch_ct[i]);
-}
-
-static void write_selected_tx_size(const VP9_COMMON *cm,
-                                   const MACROBLOCKD *xd, vpx_writer *w) {
-  TX_SIZE tx_size = xd->mi[0]->tx_size;
-  BLOCK_SIZE bsize = xd->mi[0]->sb_type;
-  const TX_SIZE max_tx_size = max_txsize_lookup[bsize];
-  const vpx_prob *const tx_probs = get_tx_probs2(max_tx_size, xd,
-                                                 &cm->fc->tx_probs);
-  vpx_write(w, tx_size != TX_4X4, tx_probs[0]);
-  if (tx_size != TX_4X4 && max_tx_size >= TX_16X16) {
-    vpx_write(w, tx_size != TX_8X8, tx_probs[1]);
-    if (tx_size != TX_8X8 && max_tx_size >= TX_32X32)
-      vpx_write(w, tx_size != TX_16X16, tx_probs[2]);
-  }
-}
-
-static int write_skip(const VP9_COMMON *cm, const MACROBLOCKD *xd,
-                      int segment_id, const MODE_INFO *mi, vpx_writer *w) {
-  if (segfeature_active(&cm->seg, segment_id, SEG_LVL_SKIP)) {
-    return 1;
-  } else {
-    const int skip = mi->skip;
-    vpx_write(w, skip, vp9_get_skip_prob(cm, xd));
-    return skip;
-  }
-}
-
-static void update_skip_probs(VP9_COMMON *cm, vpx_writer *w,
-                              FRAME_COUNTS *counts) {
-  int k;
-
-  for (k = 0; k < SKIP_CONTEXTS; ++k)
-    vp9_cond_prob_diff_update(w, &cm->fc->skip_probs[k], counts->skip[k]);
-}
-
-static void update_switchable_interp_probs(VP9_COMMON *cm, vpx_writer *w,
-                                           FRAME_COUNTS *counts) {
-  int j;
-  for (j = 0; j < SWITCHABLE_FILTER_CONTEXTS; ++j)
-    prob_diff_update(vp9_switchable_interp_tree,
-                     cm->fc->switchable_interp_prob[j],
-                     counts->switchable_interp[j], SWITCHABLE_FILTERS, w);
-}
-
-static void pack_mb_tokens(vpx_writer *w,
-                           TOKENEXTRA **tp, const TOKENEXTRA *const stop,
-                           vpx_bit_depth_t bit_depth) {
-  const TOKENEXTRA *p;
-  const vp9_extra_bit *const extra_bits =
-#if CONFIG_VP9_HIGHBITDEPTH
-    (bit_depth == VPX_BITS_12) ? vp9_extra_bits_high12 :
-    (bit_depth == VPX_BITS_10) ? vp9_extra_bits_high10 :
-    vp9_extra_bits;
-#else
-    vp9_extra_bits;
-    (void) bit_depth;
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-
-  for (p = *tp; p < stop && p->token != EOSB_TOKEN; ++p) {
-    if (p->token == EOB_TOKEN) {
-      vpx_write(w, 0, p->context_tree[0]);
-      continue;
-    }
-    vpx_write(w, 1, p->context_tree[0]);
-    while (p->token == ZERO_TOKEN) {
-      vpx_write(w, 0, p->context_tree[1]);
-      ++p;
-      if (p == stop || p->token == EOSB_TOKEN) {
-        *tp = (TOKENEXTRA*)(uintptr_t)p + (p->token == EOSB_TOKEN);
-        return;
-      }
-    }
-
-    {
-      const int t = p->token;
-      const vpx_prob *const context_tree = p->context_tree;
-      assert(t != ZERO_TOKEN);
-      assert(t != EOB_TOKEN);
-      assert(t != EOSB_TOKEN);
-      vpx_write(w, 1, context_tree[1]);
-      if (t == ONE_TOKEN) {
-        vpx_write(w, 0, context_tree[2]);
-        vpx_write_bit(w, p->extra & 1);
-      } else {  // t >= TWO_TOKEN && t < EOB_TOKEN
-        const struct vp9_token *const a = &vp9_coef_encodings[t];
-        const int v = a->value;
-        const int n = a->len;
-        const int e = p->extra;
-        vpx_write(w, 1, context_tree[2]);
-        vp9_write_tree(w, vp9_coef_con_tree,
-                       vp9_pareto8_full[context_tree[PIVOT_NODE] - 1], v,
-                       n - UNCONSTRAINED_NODES, 0);
-        if (t >= CATEGORY1_TOKEN) {
-          const vp9_extra_bit *const b = &extra_bits[t];
-          const unsigned char *pb = b->prob;
-          int v = e >> 1;
-          int n = b->len;  // number of bits in v, assumed nonzero
-          do {
-            const int bb = (v >> --n) & 1;
-            vpx_write(w, bb, *pb++);
-          } while (n);
-        }
-        vpx_write_bit(w, e & 1);
-      }
-    }
-  }
-  *tp = (TOKENEXTRA*)(uintptr_t)p + (p->token == EOSB_TOKEN);
-}
-
-static void write_segment_id(vpx_writer *w, const struct segmentation *seg,
-                             int segment_id) {
-  if (seg->enabled && seg->update_map)
-    vp9_write_tree(w, vp9_segment_tree, seg->tree_probs, segment_id, 3, 0);
-}
-
-// This function encodes the reference frame
-static void write_ref_frames(const VP9_COMMON *cm, const MACROBLOCKD *xd,
-                             vpx_writer *w) {
-  const MODE_INFO *const mi = xd->mi[0];
-  const int is_compound = has_second_ref(mi);
-  const int segment_id = mi->segment_id;
-
-  // If segment level coding of this signal is disabled...
-  // or the segment allows multiple reference frame options
-  if (segfeature_active(&cm->seg, segment_id, SEG_LVL_REF_FRAME)) {
-    assert(!is_compound);
-    assert(mi->ref_frame[0] ==
-               get_segdata(&cm->seg, segment_id, SEG_LVL_REF_FRAME));
-  } else {
-    // does the feature use compound prediction or not
-    // (if not specified at the frame/segment level)
-    if (cm->reference_mode == REFERENCE_MODE_SELECT) {
-      vpx_write(w, is_compound, vp9_get_reference_mode_prob(cm, xd));
-    } else {
-      assert(!is_compound == (cm->reference_mode == SINGLE_REFERENCE));
-    }
-
-    if (is_compound) {
-      vpx_write(w, mi->ref_frame[0] == GOLDEN_FRAME,
-                vp9_get_pred_prob_comp_ref_p(cm, xd));
-    } else {
-      const int bit0 = mi->ref_frame[0] != LAST_FRAME;
-      vpx_write(w, bit0, vp9_get_pred_prob_single_ref_p1(cm, xd));
-      if (bit0) {
-        const int bit1 = mi->ref_frame[0] != GOLDEN_FRAME;
-        vpx_write(w, bit1, vp9_get_pred_prob_single_ref_p2(cm, xd));
-      }
-    }
-  }
-}
-
-static void pack_inter_mode_mvs(VP9_COMP *cpi, const MODE_INFO *mi,
-                                vpx_writer *w) {
-  VP9_COMMON *const cm = &cpi->common;
-  const nmv_context *nmvc = &cm->fc->nmvc;
-  const MACROBLOCK *const x = &cpi->td.mb;
-  const MACROBLOCKD *const xd = &x->e_mbd;
-  const struct segmentation *const seg = &cm->seg;
-  const MB_MODE_INFO_EXT *const mbmi_ext = x->mbmi_ext;
-  const PREDICTION_MODE mode = mi->mode;
-  const int segment_id = mi->segment_id;
-  const BLOCK_SIZE bsize = mi->sb_type;
-  const int allow_hp = cm->allow_high_precision_mv;
-  const int is_inter = is_inter_block(mi);
-  const int is_compound = has_second_ref(mi);
-  int skip, ref;
-
-  if (seg->update_map) {
-    if (seg->temporal_update) {
-      const int pred_flag = mi->seg_id_predicted;
-      vpx_prob pred_prob = vp9_get_pred_prob_seg_id(seg, xd);
-      vpx_write(w, pred_flag, pred_prob);
-      if (!pred_flag)
-        write_segment_id(w, seg, segment_id);
-    } else {
-      write_segment_id(w, seg, segment_id);
-    }
-  }
-
-  skip = write_skip(cm, xd, segment_id, mi, w);
-
-  if (!segfeature_active(seg, segment_id, SEG_LVL_REF_FRAME))
-    vpx_write(w, is_inter, vp9_get_intra_inter_prob(cm, xd));
-
-  if (bsize >= BLOCK_8X8 && cm->tx_mode == TX_MODE_SELECT &&
-      !(is_inter && skip)) {
-    write_selected_tx_size(cm, xd, w);
-  }
-
-  if (!is_inter) {
-    if (bsize >= BLOCK_8X8) {
-      write_intra_mode(w, mode, cm->fc->y_mode_prob[size_group_lookup[bsize]]);
-    } else {
-      int idx, idy;
-      const int num_4x4_w = num_4x4_blocks_wide_lookup[bsize];
-      const int num_4x4_h = num_4x4_blocks_high_lookup[bsize];
-      for (idy = 0; idy < 2; idy += num_4x4_h) {
-        for (idx = 0; idx < 2; idx += num_4x4_w) {
-          const PREDICTION_MODE b_mode = mi->bmi[idy * 2 + idx].as_mode;
-          write_intra_mode(w, b_mode, cm->fc->y_mode_prob[0]);
-        }
-      }
-    }
-    write_intra_mode(w, mi->uv_mode, cm->fc->uv_mode_prob[mode]);
-  } else {
-    const int mode_ctx = mbmi_ext->mode_context[mi->ref_frame[0]];
-    const vpx_prob *const inter_probs = cm->fc->inter_mode_probs[mode_ctx];
-    write_ref_frames(cm, xd, w);
-
-    // If segment skip is not enabled code the mode.
-    if (!segfeature_active(seg, segment_id, SEG_LVL_SKIP)) {
-      if (bsize >= BLOCK_8X8) {
-        write_inter_mode(w, mode, inter_probs);
-      }
-    }
-
-    if (cm->interp_filter == SWITCHABLE) {
-      const int ctx = vp9_get_pred_context_switchable_interp(xd);
-      vp9_write_token(w, vp9_switchable_interp_tree,
-                      cm->fc->switchable_interp_prob[ctx],
-                      &switchable_interp_encodings[mi->interp_filter]);
-      ++cpi->interp_filter_selected[0][mi->interp_filter];
-    } else {
-      assert(mi->interp_filter == cm->interp_filter);
-    }
-
-    if (bsize < BLOCK_8X8) {
-      const int num_4x4_w = num_4x4_blocks_wide_lookup[bsize];
-      const int num_4x4_h = num_4x4_blocks_high_lookup[bsize];
-      int idx, idy;
-      for (idy = 0; idy < 2; idy += num_4x4_h) {
-        for (idx = 0; idx < 2; idx += num_4x4_w) {
-          const int j = idy * 2 + idx;
-          const PREDICTION_MODE b_mode = mi->bmi[j].as_mode;
-          write_inter_mode(w, b_mode, inter_probs);
-          if (b_mode == NEWMV) {
-            for (ref = 0; ref < 1 + is_compound; ++ref)
-              vp9_encode_mv(cpi, w, &mi->bmi[j].as_mv[ref].as_mv,
-                            &mbmi_ext->ref_mvs[mi->ref_frame[ref]][0].as_mv,
-                            nmvc, allow_hp);
-          }
-        }
-      }
-    } else {
-      if (mode == NEWMV) {
-        for (ref = 0; ref < 1 + is_compound; ++ref)
-          vp9_encode_mv(cpi, w, &mi->mv[ref].as_mv,
-                        &mbmi_ext->ref_mvs[mi->ref_frame[ref]][0].as_mv, nmvc,
-                        allow_hp);
-      }
-    }
-  }
-}
-
-static void write_mb_modes_kf(const VP9_COMMON *cm, const MACROBLOCKD *xd,
-                              MODE_INFO **mi_8x8, vpx_writer *w) {
-  const struct segmentation *const seg = &cm->seg;
-  const MODE_INFO *const mi = mi_8x8[0];
-  const MODE_INFO *const above_mi = xd->above_mi;
-  const MODE_INFO *const left_mi = xd->left_mi;
-  const BLOCK_SIZE bsize = mi->sb_type;
-
-  if (seg->update_map)
-    write_segment_id(w, seg, mi->segment_id);
-
-  write_skip(cm, xd, mi->segment_id, mi, w);
-
-  if (bsize >= BLOCK_8X8 && cm->tx_mode == TX_MODE_SELECT)
-    write_selected_tx_size(cm, xd, w);
-
-  if (bsize >= BLOCK_8X8) {
-    write_intra_mode(w, mi->mode, get_y_mode_probs(mi, above_mi, left_mi, 0));
-  } else {
-    const int num_4x4_w = num_4x4_blocks_wide_lookup[bsize];
-    const int num_4x4_h = num_4x4_blocks_high_lookup[bsize];
-    int idx, idy;
-
-    for (idy = 0; idy < 2; idy += num_4x4_h) {
-      for (idx = 0; idx < 2; idx += num_4x4_w) {
-        const int block = idy * 2 + idx;
-        write_intra_mode(w, mi->bmi[block].as_mode,
-                         get_y_mode_probs(mi, above_mi, left_mi, block));
-      }
-    }
-  }
-
-  write_intra_mode(w, mi->uv_mode, vp9_kf_uv_mode_prob[mi->mode]);
-}
-
-static void write_modes_b(VP9_COMP *cpi, const TileInfo *const tile,
-                          vpx_writer *w, TOKENEXTRA **tok,
-                          const TOKENEXTRA *const tok_end,
-                          int mi_row, int mi_col) {
-  const VP9_COMMON *const cm = &cpi->common;
-  MACROBLOCKD *const xd = &cpi->td.mb.e_mbd;
-  MODE_INFO *m;
-
-  xd->mi = cm->mi_grid_visible + (mi_row * cm->mi_stride + mi_col);
-  m = xd->mi[0];
-
-  cpi->td.mb.mbmi_ext = cpi->td.mb.mbmi_ext_base +
-      (mi_row * cm->mi_cols + mi_col);
-
-  set_mi_row_col(xd, tile,
-                 mi_row, num_8x8_blocks_high_lookup[m->sb_type],
-                 mi_col, num_8x8_blocks_wide_lookup[m->sb_type],
-                 cm->mi_rows, cm->mi_cols);
-  if (frame_is_intra_only(cm)) {
-    write_mb_modes_kf(cm, xd, xd->mi, w);
-  } else {
-    pack_inter_mode_mvs(cpi, m, w);
-  }
-
-  assert(*tok < tok_end);
-  pack_mb_tokens(w, tok, tok_end, cm->bit_depth);
-}
-
-static void write_partition(const VP9_COMMON *const cm,
-                            const MACROBLOCKD *const xd,
-                            int hbs, int mi_row, int mi_col,
-                            PARTITION_TYPE p, BLOCK_SIZE bsize, vpx_writer *w) {
-  const int ctx = partition_plane_context(xd, mi_row, mi_col, bsize);
-  const vpx_prob *const probs = xd->partition_probs[ctx];
-  const int has_rows = (mi_row + hbs) < cm->mi_rows;
-  const int has_cols = (mi_col + hbs) < cm->mi_cols;
-
-  if (has_rows && has_cols) {
-    vp9_write_token(w, vp9_partition_tree, probs, &partition_encodings[p]);
-  } else if (!has_rows && has_cols) {
-    assert(p == PARTITION_SPLIT || p == PARTITION_HORZ);
-    vpx_write(w, p == PARTITION_SPLIT, probs[1]);
-  } else if (has_rows && !has_cols) {
-    assert(p == PARTITION_SPLIT || p == PARTITION_VERT);
-    vpx_write(w, p == PARTITION_SPLIT, probs[2]);
-  } else {
-    assert(p == PARTITION_SPLIT);
-  }
-}
-
-static void write_modes_sb(VP9_COMP *cpi,
-                           const TileInfo *const tile, vpx_writer *w,
-                           TOKENEXTRA **tok, const TOKENEXTRA *const tok_end,
-                           int mi_row, int mi_col, BLOCK_SIZE bsize) {
-  const VP9_COMMON *const cm = &cpi->common;
-  MACROBLOCKD *const xd = &cpi->td.mb.e_mbd;
-
-  const int bsl = b_width_log2_lookup[bsize];
-  const int bs = (1 << bsl) / 4;
-  PARTITION_TYPE partition;
-  BLOCK_SIZE subsize;
-  const MODE_INFO *m = NULL;
-
-  if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols)
-    return;
-
-  m = cm->mi_grid_visible[mi_row * cm->mi_stride + mi_col];
-
-  partition = partition_lookup[bsl][m->sb_type];
-  write_partition(cm, xd, bs, mi_row, mi_col, partition, bsize, w);
-  subsize = get_subsize(bsize, partition);
-  if (subsize < BLOCK_8X8) {
-    write_modes_b(cpi, tile, w, tok, tok_end, mi_row, mi_col);
-  } else {
-    switch (partition) {
-      case PARTITION_NONE:
-        write_modes_b(cpi, tile, w, tok, tok_end, mi_row, mi_col);
-        break;
-      case PARTITION_HORZ:
-        write_modes_b(cpi, tile, w, tok, tok_end, mi_row, mi_col);
-        if (mi_row + bs < cm->mi_rows)
-          write_modes_b(cpi, tile, w, tok, tok_end, mi_row + bs, mi_col);
-        break;
-      case PARTITION_VERT:
-        write_modes_b(cpi, tile, w, tok, tok_end, mi_row, mi_col);
-        if (mi_col + bs < cm->mi_cols)
-          write_modes_b(cpi, tile, w, tok, tok_end, mi_row, mi_col + bs);
-        break;
-      case PARTITION_SPLIT:
-        write_modes_sb(cpi, tile, w, tok, tok_end, mi_row, mi_col, subsize);
-        write_modes_sb(cpi, tile, w, tok, tok_end, mi_row, mi_col + bs,
-                       subsize);
-        write_modes_sb(cpi, tile, w, tok, tok_end, mi_row + bs, mi_col,
-                       subsize);
-        write_modes_sb(cpi, tile, w, tok, tok_end, mi_row + bs, mi_col + bs,
-                       subsize);
-        break;
-      default:
-        assert(0);
-    }
-  }
-
-  // update partition context
-  if (bsize >= BLOCK_8X8 &&
-      (bsize == BLOCK_8X8 || partition != PARTITION_SPLIT))
-    update_partition_context(xd, mi_row, mi_col, subsize, bsize);
-}
-
-static void write_modes(VP9_COMP *cpi,
-                        const TileInfo *const tile, vpx_writer *w,
-                        TOKENEXTRA **tok, const TOKENEXTRA *const tok_end) {
-  const VP9_COMMON *const cm = &cpi->common;
-  MACROBLOCKD *const xd = &cpi->td.mb.e_mbd;
-  int mi_row, mi_col;
-
-  set_partition_probs(cm, xd);
-
-  for (mi_row = tile->mi_row_start; mi_row < tile->mi_row_end;
-       mi_row += MI_BLOCK_SIZE) {
-    vp9_zero(xd->left_seg_context);
-    for (mi_col = tile->mi_col_start; mi_col < tile->mi_col_end;
-         mi_col += MI_BLOCK_SIZE)
-      write_modes_sb(cpi, tile, w, tok, tok_end, mi_row, mi_col,
-                     BLOCK_64X64);
-  }
-}
-
-static void build_tree_distribution(VP9_COMP *cpi, TX_SIZE tx_size,
-                                    vp9_coeff_stats *coef_branch_ct,
-                                    vp9_coeff_probs_model *coef_probs) {
-  vp9_coeff_count *coef_counts = cpi->td.rd_counts.coef_counts[tx_size];
-  unsigned int (*eob_branch_ct)[REF_TYPES][COEF_BANDS][COEFF_CONTEXTS] =
-      cpi->common.counts.eob_branch[tx_size];
-  int i, j, k, l, m;
-
-  for (i = 0; i < PLANE_TYPES; ++i) {
-    for (j = 0; j < REF_TYPES; ++j) {
-      for (k = 0; k < COEF_BANDS; ++k) {
-        for (l = 0; l < BAND_COEFF_CONTEXTS(k); ++l) {
-          vp9_tree_probs_from_distribution(vp9_coef_tree,
-                                           coef_branch_ct[i][j][k][l],
-                                           coef_counts[i][j][k][l]);
-          coef_branch_ct[i][j][k][l][0][1] = eob_branch_ct[i][j][k][l] -
-                                             coef_branch_ct[i][j][k][l][0][0];
-          for (m = 0; m < UNCONSTRAINED_NODES; ++m)
-            coef_probs[i][j][k][l][m] = get_binary_prob(
-                                            coef_branch_ct[i][j][k][l][m][0],
-                                            coef_branch_ct[i][j][k][l][m][1]);
-        }
-      }
-    }
-  }
-}
-
-static void update_coef_probs_common(vpx_writer* const bc, VP9_COMP *cpi,
-                                     TX_SIZE tx_size,
-                                     vp9_coeff_stats *frame_branch_ct,
-                                     vp9_coeff_probs_model *new_coef_probs) {
-  vp9_coeff_probs_model *old_coef_probs = cpi->common.fc->coef_probs[tx_size];
-  const vpx_prob upd = DIFF_UPDATE_PROB;
-  const int entropy_nodes_update = UNCONSTRAINED_NODES;
-  int i, j, k, l, t;
-  int stepsize = cpi->sf.coeff_prob_appx_step;
-
-  switch (cpi->sf.use_fast_coef_updates) {
-    case TWO_LOOP: {
-      /* dry run to see if there is any update at all needed */
-      int savings = 0;
-      int update[2] = {0, 0};
-      for (i = 0; i < PLANE_TYPES; ++i) {
-        for (j = 0; j < REF_TYPES; ++j) {
-          for (k = 0; k < COEF_BANDS; ++k) {
-            for (l = 0; l < BAND_COEFF_CONTEXTS(k); ++l) {
-              for (t = 0; t < entropy_nodes_update; ++t) {
-                vpx_prob newp = new_coef_probs[i][j][k][l][t];
-                const vpx_prob oldp = old_coef_probs[i][j][k][l][t];
-                int s;
-                int u = 0;
-                if (t == PIVOT_NODE)
-                  s = vp9_prob_diff_update_savings_search_model(
-                      frame_branch_ct[i][j][k][l][0], oldp, &newp, upd,
-                      stepsize);
-                else
-                  s = vp9_prob_diff_update_savings_search(
-                      frame_branch_ct[i][j][k][l][t], oldp, &newp, upd);
-                if (s > 0 && newp != oldp)
-                  u = 1;
-                if (u)
-                  savings += s - (int)(vp9_cost_zero(upd));
-                else
-                  savings -= (int)(vp9_cost_zero(upd));
-                update[u]++;
-              }
-            }
-          }
-        }
-      }
-
-      // printf("Update %d %d, savings %d\n", update[0], update[1], savings);
-      /* Is coef updated at all */
-      if (update[1] == 0 || savings < 0) {
-        vpx_write_bit(bc, 0);
-        return;
-      }
-      vpx_write_bit(bc, 1);
-      for (i = 0; i < PLANE_TYPES; ++i) {
-        for (j = 0; j < REF_TYPES; ++j) {
-          for (k = 0; k < COEF_BANDS; ++k) {
-            for (l = 0; l < BAND_COEFF_CONTEXTS(k); ++l) {
-              // calc probs and branch cts for this frame only
-              for (t = 0; t < entropy_nodes_update; ++t) {
-                vpx_prob newp = new_coef_probs[i][j][k][l][t];
-                vpx_prob *oldp = old_coef_probs[i][j][k][l] + t;
-                const vpx_prob upd = DIFF_UPDATE_PROB;
-                int s;
-                int u = 0;
-                if (t == PIVOT_NODE)
-                  s = vp9_prob_diff_update_savings_search_model(
-                      frame_branch_ct[i][j][k][l][0],
-                      *oldp, &newp, upd, stepsize);
-                else
-                  s = vp9_prob_diff_update_savings_search(
-                      frame_branch_ct[i][j][k][l][t],
-                      *oldp, &newp, upd);
-                if (s > 0 && newp != *oldp)
-                  u = 1;
-                vpx_write(bc, u, upd);
-                if (u) {
-                  /* send/use new probability */
-                  vp9_write_prob_diff_update(bc, newp, *oldp);
-                  *oldp = newp;
-                }
-              }
-            }
-          }
-        }
-      }
-      return;
-    }
-
-    case ONE_LOOP_REDUCED: {
-      int updates = 0;
-      int noupdates_before_first = 0;
-      for (i = 0; i < PLANE_TYPES; ++i) {
-        for (j = 0; j < REF_TYPES; ++j) {
-          for (k = 0; k < COEF_BANDS; ++k) {
-            for (l = 0; l < BAND_COEFF_CONTEXTS(k); ++l) {
-              // calc probs and branch cts for this frame only
-              for (t = 0; t < entropy_nodes_update; ++t) {
-                vpx_prob newp = new_coef_probs[i][j][k][l][t];
-                vpx_prob *oldp = old_coef_probs[i][j][k][l] + t;
-                int s;
-                int u = 0;
-
-                if (t == PIVOT_NODE) {
-                  s = vp9_prob_diff_update_savings_search_model(
-                      frame_branch_ct[i][j][k][l][0],
-                      *oldp, &newp, upd, stepsize);
-                } else {
-                  s = vp9_prob_diff_update_savings_search(
-                      frame_branch_ct[i][j][k][l][t],
-                      *oldp, &newp, upd);
-                }
-
-                if (s > 0 && newp != *oldp)
-                  u = 1;
-                updates += u;
-                if (u == 0 && updates == 0) {
-                  noupdates_before_first++;
-                  continue;
-                }
-                if (u == 1 && updates == 1) {
-                  int v;
-                  // first update
-                  vpx_write_bit(bc, 1);
-                  for (v = 0; v < noupdates_before_first; ++v)
-                    vpx_write(bc, 0, upd);
-                }
-                vpx_write(bc, u, upd);
-                if (u) {
-                  /* send/use new probability */
-                  vp9_write_prob_diff_update(bc, newp, *oldp);
-                  *oldp = newp;
-                }
-              }
-            }
-          }
-        }
-      }
-      if (updates == 0) {
-        vpx_write_bit(bc, 0);  // no updates
-      }
-      return;
-    }
-    default:
-      assert(0);
-  }
-}
-
-static void update_coef_probs(VP9_COMP *cpi, vpx_writer* w) {
-  const TX_MODE tx_mode = cpi->common.tx_mode;
-  const TX_SIZE max_tx_size = tx_mode_to_biggest_tx_size[tx_mode];
-  TX_SIZE tx_size;
-  for (tx_size = TX_4X4; tx_size <= max_tx_size; ++tx_size) {
-    vp9_coeff_stats frame_branch_ct[PLANE_TYPES];
-    vp9_coeff_probs_model frame_coef_probs[PLANE_TYPES];
-    if (cpi->td.counts->tx.tx_totals[tx_size] <= 20 ||
-        (tx_size >= TX_16X16 && cpi->sf.tx_size_search_method == USE_TX_8X8)) {
-      vpx_write_bit(w, 0);
-    } else {
-      build_tree_distribution(cpi, tx_size, frame_branch_ct,
-                              frame_coef_probs);
-      update_coef_probs_common(w, cpi, tx_size, frame_branch_ct,
-                               frame_coef_probs);
-    }
-  }
-}
-
-static void encode_loopfilter(struct loopfilter *lf,
-                              struct vpx_write_bit_buffer *wb) {
-  int i;
-
-  // Encode the loop filter level and type
-  vpx_wb_write_literal(wb, lf->filter_level, 6);
-  vpx_wb_write_literal(wb, lf->sharpness_level, 3);
-
-  // Write out loop filter deltas applied at the MB level based on mode or
-  // ref frame (if they are enabled).
-  vpx_wb_write_bit(wb, lf->mode_ref_delta_enabled);
-
-  if (lf->mode_ref_delta_enabled) {
-    vpx_wb_write_bit(wb, lf->mode_ref_delta_update);
-    if (lf->mode_ref_delta_update) {
-      for (i = 0; i < MAX_REF_LF_DELTAS; i++) {
-        const int delta = lf->ref_deltas[i];
-        const int changed = delta != lf->last_ref_deltas[i];
-        vpx_wb_write_bit(wb, changed);
-        if (changed) {
-          lf->last_ref_deltas[i] = delta;
-          vpx_wb_write_literal(wb, abs(delta) & 0x3F, 6);
-          vpx_wb_write_bit(wb, delta < 0);
-        }
-      }
-
-      for (i = 0; i < MAX_MODE_LF_DELTAS; i++) {
-        const int delta = lf->mode_deltas[i];
-        const int changed = delta != lf->last_mode_deltas[i];
-        vpx_wb_write_bit(wb, changed);
-        if (changed) {
-          lf->last_mode_deltas[i] = delta;
-          vpx_wb_write_literal(wb, abs(delta) & 0x3F, 6);
-          vpx_wb_write_bit(wb, delta < 0);
-        }
-      }
-    }
-  }
-}
-
-static void write_delta_q(struct vpx_write_bit_buffer *wb, int delta_q) {
-  if (delta_q != 0) {
-    vpx_wb_write_bit(wb, 1);
-    vpx_wb_write_literal(wb, abs(delta_q), 4);
-    vpx_wb_write_bit(wb, delta_q < 0);
-  } else {
-    vpx_wb_write_bit(wb, 0);
-  }
-}
-
-static void encode_quantization(const VP9_COMMON *const cm,
-                                struct vpx_write_bit_buffer *wb) {
-  vpx_wb_write_literal(wb, cm->base_qindex, QINDEX_BITS);
-  write_delta_q(wb, cm->y_dc_delta_q);
-  write_delta_q(wb, cm->uv_dc_delta_q);
-  write_delta_q(wb, cm->uv_ac_delta_q);
-}
-
-static void encode_segmentation(VP9_COMMON *cm, MACROBLOCKD *xd,
-                                struct vpx_write_bit_buffer *wb) {
-  int i, j;
-
-  const struct segmentation *seg = &cm->seg;
-
-  vpx_wb_write_bit(wb, seg->enabled);
-  if (!seg->enabled)
-    return;
-
-  // Segmentation map
-  vpx_wb_write_bit(wb, seg->update_map);
-  if (seg->update_map) {
-    // Select the coding strategy (temporal or spatial)
-    vp9_choose_segmap_coding_method(cm, xd);
-    // Write out probabilities used to decode unpredicted  macro-block segments
-    for (i = 0; i < SEG_TREE_PROBS; i++) {
-      const int prob = seg->tree_probs[i];
-      const int update = prob != MAX_PROB;
-      vpx_wb_write_bit(wb, update);
-      if (update)
-        vpx_wb_write_literal(wb, prob, 8);
-    }
-
-    // Write out the chosen coding method.
-    vpx_wb_write_bit(wb, seg->temporal_update);
-    if (seg->temporal_update) {
-      for (i = 0; i < PREDICTION_PROBS; i++) {
-        const int prob = seg->pred_probs[i];
-        const int update = prob != MAX_PROB;
-        vpx_wb_write_bit(wb, update);
-        if (update)
-          vpx_wb_write_literal(wb, prob, 8);
-      }
-    }
-  }
-
-  // Segmentation data
-  vpx_wb_write_bit(wb, seg->update_data);
-  if (seg->update_data) {
-    vpx_wb_write_bit(wb, seg->abs_delta);
-
-    for (i = 0; i < MAX_SEGMENTS; i++) {
-      for (j = 0; j < SEG_LVL_MAX; j++) {
-        const int active = segfeature_active(seg, i, j);
-        vpx_wb_write_bit(wb, active);
-        if (active) {
-          const int data = get_segdata(seg, i, j);
-          const int data_max = vp9_seg_feature_data_max(j);
-
-          if (vp9_is_segfeature_signed(j)) {
-            encode_unsigned_max(wb, abs(data), data_max);
-            vpx_wb_write_bit(wb, data < 0);
-          } else {
-            encode_unsigned_max(wb, data, data_max);
-          }
-        }
-      }
-    }
-  }
-}
-
-static void encode_txfm_probs(VP9_COMMON *cm, vpx_writer *w,
-                              FRAME_COUNTS *counts) {
-  // Mode
-  vpx_write_literal(w, VPXMIN(cm->tx_mode, ALLOW_32X32), 2);
-  if (cm->tx_mode >= ALLOW_32X32)
-    vpx_write_bit(w, cm->tx_mode == TX_MODE_SELECT);
-
-  // Probabilities
-  if (cm->tx_mode == TX_MODE_SELECT) {
-    int i, j;
-    unsigned int ct_8x8p[TX_SIZES - 3][2];
-    unsigned int ct_16x16p[TX_SIZES - 2][2];
-    unsigned int ct_32x32p[TX_SIZES - 1][2];
-
-
-    for (i = 0; i < TX_SIZE_CONTEXTS; i++) {
-      tx_counts_to_branch_counts_8x8(counts->tx.p8x8[i], ct_8x8p);
-      for (j = 0; j < TX_SIZES - 3; j++)
-        vp9_cond_prob_diff_update(w, &cm->fc->tx_probs.p8x8[i][j], ct_8x8p[j]);
-    }
-
-    for (i = 0; i < TX_SIZE_CONTEXTS; i++) {
-      tx_counts_to_branch_counts_16x16(counts->tx.p16x16[i], ct_16x16p);
-      for (j = 0; j < TX_SIZES - 2; j++)
-        vp9_cond_prob_diff_update(w, &cm->fc->tx_probs.p16x16[i][j],
-                                  ct_16x16p[j]);
-    }
-
-    for (i = 0; i < TX_SIZE_CONTEXTS; i++) {
-      tx_counts_to_branch_counts_32x32(counts->tx.p32x32[i], ct_32x32p);
-      for (j = 0; j < TX_SIZES - 1; j++)
-        vp9_cond_prob_diff_update(w, &cm->fc->tx_probs.p32x32[i][j],
-                                  ct_32x32p[j]);
-    }
-  }
-}
-
-static void write_interp_filter(INTERP_FILTER filter,
-                                struct vpx_write_bit_buffer *wb) {
-  const int filter_to_literal[] = { 1, 0, 2, 3 };
-
-  vpx_wb_write_bit(wb, filter == SWITCHABLE);
-  if (filter != SWITCHABLE)
-    vpx_wb_write_literal(wb, filter_to_literal[filter], 2);
-}
-
-static void fix_interp_filter(VP9_COMMON *cm, FRAME_COUNTS *counts) {
-  if (cm->interp_filter == SWITCHABLE) {
-    // Check to see if only one of the filters is actually used
-    int count[SWITCHABLE_FILTERS];
-    int i, j, c = 0;
-    for (i = 0; i < SWITCHABLE_FILTERS; ++i) {
-      count[i] = 0;
-      for (j = 0; j < SWITCHABLE_FILTER_CONTEXTS; ++j)
-        count[i] += counts->switchable_interp[j][i];
-      c += (count[i] > 0);
-    }
-    if (c == 1) {
-      // Only one filter is used. So set the filter at frame level
-      for (i = 0; i < SWITCHABLE_FILTERS; ++i) {
-        if (count[i]) {
-          cm->interp_filter = i;
-          break;
-        }
-      }
-    }
-  }
-}
-
-static void write_tile_info(const VP9_COMMON *const cm,
-                            struct vpx_write_bit_buffer *wb) {
-  int min_log2_tile_cols, max_log2_tile_cols, ones;
-  vp9_get_tile_n_bits(cm->mi_cols, &min_log2_tile_cols, &max_log2_tile_cols);
-
-  // columns
-  ones = cm->log2_tile_cols - min_log2_tile_cols;
-  while (ones--)
-    vpx_wb_write_bit(wb, 1);
-
-  if (cm->log2_tile_cols < max_log2_tile_cols)
-    vpx_wb_write_bit(wb, 0);
-
-  // rows
-  vpx_wb_write_bit(wb, cm->log2_tile_rows != 0);
-  if (cm->log2_tile_rows != 0)
-    vpx_wb_write_bit(wb, cm->log2_tile_rows != 1);
-}
-
-int vp9_get_refresh_mask(VP9_COMP *cpi) {
-  if (vp9_preserve_existing_gf(cpi)) {
-    // We have decided to preserve the previously existing golden frame as our
-    // new ARF frame. However, in the short term we leave it in the GF slot and,
-    // if we're updating the GF with the current decoded frame, we save it
-    // instead to the ARF slot.
-    // Later, in the function vp9_encoder.c:vp9_update_reference_frames() we
-    // will swap gld_fb_idx and alt_fb_idx to achieve our objective. We do it
-    // there so that it can be done outside of the recode loop.
-    // Note: This is highly specific to the use of ARF as a forward reference,
-    // and this needs to be generalized as other uses are implemented
-    // (like RTC/temporal scalability).
-    return (cpi->refresh_last_frame << cpi->lst_fb_idx) |
-           (cpi->refresh_golden_frame << cpi->alt_fb_idx);
-  } else {
-    int arf_idx = cpi->alt_fb_idx;
-    if ((cpi->oxcf.pass == 2) && cpi->multi_arf_allowed) {
-      const GF_GROUP *const gf_group = &cpi->twopass.gf_group;
-      arf_idx = gf_group->arf_update_idx[gf_group->index];
-    }
-    return (cpi->refresh_last_frame << cpi->lst_fb_idx) |
-           (cpi->refresh_golden_frame << cpi->gld_fb_idx) |
-           (cpi->refresh_alt_ref_frame << arf_idx);
-  }
-}
-
-static size_t encode_tiles(VP9_COMP *cpi, uint8_t *data_ptr) {
-  VP9_COMMON *const cm = &cpi->common;
-  vpx_writer residual_bc;
-  int tile_row, tile_col;
-  TOKENEXTRA *tok_end;
-  size_t total_size = 0;
-  const int tile_cols = 1 << cm->log2_tile_cols;
-  const int tile_rows = 1 << cm->log2_tile_rows;
-
-  memset(cm->above_seg_context, 0,
-         sizeof(*cm->above_seg_context) * mi_cols_aligned_to_sb(cm->mi_cols));
-
-  for (tile_row = 0; tile_row < tile_rows; tile_row++) {
-    for (tile_col = 0; tile_col < tile_cols; tile_col++) {
-      int tile_idx = tile_row * tile_cols + tile_col;
-      TOKENEXTRA *tok = cpi->tile_tok[tile_row][tile_col];
-
-      tok_end = cpi->tile_tok[tile_row][tile_col] +
-          cpi->tok_count[tile_row][tile_col];
-
-      if (tile_col < tile_cols - 1 || tile_row < tile_rows - 1)
-        vpx_start_encode(&residual_bc, data_ptr + total_size + 4);
-      else
-        vpx_start_encode(&residual_bc, data_ptr + total_size);
-
-      write_modes(cpi, &cpi->tile_data[tile_idx].tile_info,
-                  &residual_bc, &tok, tok_end);
-      assert(tok == tok_end);
-      vpx_stop_encode(&residual_bc);
-      if (tile_col < tile_cols - 1 || tile_row < tile_rows - 1) {
-        // size of this tile
-        mem_put_be32(data_ptr + total_size, residual_bc.pos);
-        total_size += 4;
-      }
-
-      total_size += residual_bc.pos;
-    }
-  }
-
-  return total_size;
-}
-
-static void write_render_size(const VP9_COMMON *cm,
-                              struct vpx_write_bit_buffer *wb) {
-  const int scaling_active = cm->width != cm->render_width ||
-                             cm->height != cm->render_height;
-  vpx_wb_write_bit(wb, scaling_active);
-  if (scaling_active) {
-    vpx_wb_write_literal(wb, cm->render_width - 1, 16);
-    vpx_wb_write_literal(wb, cm->render_height - 1, 16);
-  }
-}
-
-static void write_frame_size(const VP9_COMMON *cm,
-                             struct vpx_write_bit_buffer *wb) {
-  vpx_wb_write_literal(wb, cm->width - 1, 16);
-  vpx_wb_write_literal(wb, cm->height - 1, 16);
-
-  write_render_size(cm, wb);
-}
-
-static void write_frame_size_with_refs(VP9_COMP *cpi,
-                                       struct vpx_write_bit_buffer *wb) {
-  VP9_COMMON *const cm = &cpi->common;
-  int found = 0;
-
-  MV_REFERENCE_FRAME ref_frame;
-  for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) {
-    YV12_BUFFER_CONFIG *cfg = get_ref_frame_buffer(cpi, ref_frame);
-
-    // Set "found" to 0 for temporal svc and for spatial svc key frame
-    if (cpi->use_svc &&
-        ((cpi->svc.number_temporal_layers > 1 &&
-         cpi->oxcf.rc_mode == VPX_CBR) ||
-        (cpi->svc.number_spatial_layers > 1 &&
-         cpi->svc.layer_context[cpi->svc.spatial_layer_id].is_key_frame) ||
-        (is_two_pass_svc(cpi) &&
-         cpi->svc.encode_empty_frame_state == ENCODING &&
-         cpi->svc.layer_context[0].frames_from_key_frame <
-         cpi->svc.number_temporal_layers + 1))) {
-      found = 0;
-    } else if (cfg != NULL) {
-      found = cm->width == cfg->y_crop_width &&
-              cm->height == cfg->y_crop_height;
-    }
-    vpx_wb_write_bit(wb, found);
-    if (found) {
-      break;
-    }
-  }
-
-  if (!found) {
-    vpx_wb_write_literal(wb, cm->width - 1, 16);
-    vpx_wb_write_literal(wb, cm->height - 1, 16);
-  }
-
-  write_render_size(cm, wb);
-}
-
-static void write_sync_code(struct vpx_write_bit_buffer *wb) {
-  vpx_wb_write_literal(wb, VP9_SYNC_CODE_0, 8);
-  vpx_wb_write_literal(wb, VP9_SYNC_CODE_1, 8);
-  vpx_wb_write_literal(wb, VP9_SYNC_CODE_2, 8);
-}
-
-static void write_profile(BITSTREAM_PROFILE profile,
-                          struct vpx_write_bit_buffer *wb) {
-  switch (profile) {
-    case PROFILE_0:
-      vpx_wb_write_literal(wb, 0, 2);
-      break;
-    case PROFILE_1:
-      vpx_wb_write_literal(wb, 2, 2);
-      break;
-    case PROFILE_2:
-      vpx_wb_write_literal(wb, 1, 2);
-      break;
-    case PROFILE_3:
-      vpx_wb_write_literal(wb, 6, 3);
-      break;
-    default:
-      assert(0);
-  }
-}
-
-static void write_bitdepth_colorspace_sampling(
-    VP9_COMMON *const cm, struct vpx_write_bit_buffer *wb) {
-  if (cm->profile >= PROFILE_2) {
-    assert(cm->bit_depth > VPX_BITS_8);
-    vpx_wb_write_bit(wb, cm->bit_depth == VPX_BITS_10 ? 0 : 1);
-  }
-  vpx_wb_write_literal(wb, cm->color_space, 3);
-  if (cm->color_space != VPX_CS_SRGB) {
-    // 0: [16, 235] (i.e. xvYCC), 1: [0, 255]
-    vpx_wb_write_bit(wb, cm->color_range);
-    if (cm->profile == PROFILE_1 || cm->profile == PROFILE_3) {
-      assert(cm->subsampling_x != 1 || cm->subsampling_y != 1);
-      vpx_wb_write_bit(wb, cm->subsampling_x);
-      vpx_wb_write_bit(wb, cm->subsampling_y);
-      vpx_wb_write_bit(wb, 0);  // unused
-    } else {
-      assert(cm->subsampling_x == 1 && cm->subsampling_y == 1);
-    }
-  } else {
-    assert(cm->profile == PROFILE_1 || cm->profile == PROFILE_3);
-    vpx_wb_write_bit(wb, 0);  // unused
-  }
-}
-
-static void write_uncompressed_header(VP9_COMP *cpi,
-                                      struct vpx_write_bit_buffer *wb) {
-  VP9_COMMON *const cm = &cpi->common;
-  MACROBLOCKD *const xd = &cpi->td.mb.e_mbd;
-
-  vpx_wb_write_literal(wb, VP9_FRAME_MARKER, 2);
-
-  write_profile(cm->profile, wb);
-
-  vpx_wb_write_bit(wb, 0);  // show_existing_frame
-  vpx_wb_write_bit(wb, cm->frame_type);
-  vpx_wb_write_bit(wb, cm->show_frame);
-  vpx_wb_write_bit(wb, cm->error_resilient_mode);
-
-  if (cm->frame_type == KEY_FRAME) {
-    write_sync_code(wb);
-    write_bitdepth_colorspace_sampling(cm, wb);
-    write_frame_size(cm, wb);
-  } else {
-    // In spatial svc if it's not error_resilient_mode then we need to code all
-    // visible frames as invisible. But we need to keep the show_frame flag so
-    // that the publisher could know whether it is supposed to be visible.
-    // So we will code the show_frame flag as it is. Then code the intra_only
-    // bit here. This will make the bitstream incompatible. In the player we
-    // will change to show_frame flag to 0, then add an one byte frame with
-    // show_existing_frame flag which tells the decoder which frame we want to
-    // show.
-    if (!cm->show_frame)
-      vpx_wb_write_bit(wb, cm->intra_only);
-
-    if (!cm->error_resilient_mode)
-      vpx_wb_write_literal(wb, cm->reset_frame_context, 2);
-
-    if (cm->intra_only) {
-      write_sync_code(wb);
-
-      // Note for profile 0, 420 8bpp is assumed.
-      if (cm->profile > PROFILE_0) {
-        write_bitdepth_colorspace_sampling(cm, wb);
-      }
-
-      vpx_wb_write_literal(wb, vp9_get_refresh_mask(cpi), REF_FRAMES);
-      write_frame_size(cm, wb);
-    } else {
-      MV_REFERENCE_FRAME ref_frame;
-      vpx_wb_write_literal(wb, vp9_get_refresh_mask(cpi), REF_FRAMES);
-      for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) {
-        assert(get_ref_frame_map_idx(cpi, ref_frame) != INVALID_IDX);
-        vpx_wb_write_literal(wb, get_ref_frame_map_idx(cpi, ref_frame),
-                             REF_FRAMES_LOG2);
-        vpx_wb_write_bit(wb, cm->ref_frame_sign_bias[ref_frame]);
-      }
-
-      write_frame_size_with_refs(cpi, wb);
-
-      vpx_wb_write_bit(wb, cm->allow_high_precision_mv);
-
-      fix_interp_filter(cm, cpi->td.counts);
-      write_interp_filter(cm->interp_filter, wb);
-    }
-  }
-
-  if (!cm->error_resilient_mode) {
-    vpx_wb_write_bit(wb, cm->refresh_frame_context);
-    vpx_wb_write_bit(wb, cm->frame_parallel_decoding_mode);
-  }
-
-  vpx_wb_write_literal(wb, cm->frame_context_idx, FRAME_CONTEXTS_LOG2);
-
-  encode_loopfilter(&cm->lf, wb);
-  encode_quantization(cm, wb);
-  encode_segmentation(cm, xd, wb);
-
-  write_tile_info(cm, wb);
-}
-
-static size_t write_compressed_header(VP9_COMP *cpi, uint8_t *data) {
-  VP9_COMMON *const cm = &cpi->common;
-  MACROBLOCKD *const xd = &cpi->td.mb.e_mbd;
-  FRAME_CONTEXT *const fc = cm->fc;
-  FRAME_COUNTS *counts = cpi->td.counts;
-  vpx_writer header_bc;
-
-  vpx_start_encode(&header_bc, data);
-
-  if (xd->lossless)
-    cm->tx_mode = ONLY_4X4;
-  else
-    encode_txfm_probs(cm, &header_bc, counts);
-
-  update_coef_probs(cpi, &header_bc);
-  update_skip_probs(cm, &header_bc, counts);
-
-  if (!frame_is_intra_only(cm)) {
-    int i;
-
-    for (i = 0; i < INTER_MODE_CONTEXTS; ++i)
-      prob_diff_update(vp9_inter_mode_tree, cm->fc->inter_mode_probs[i],
-                       counts->inter_mode[i], INTER_MODES, &header_bc);
-
-    if (cm->interp_filter == SWITCHABLE)
-      update_switchable_interp_probs(cm, &header_bc, counts);
-
-    for (i = 0; i < INTRA_INTER_CONTEXTS; i++)
-      vp9_cond_prob_diff_update(&header_bc, &fc->intra_inter_prob[i],
-                                counts->intra_inter[i]);
-
-    if (cpi->allow_comp_inter_inter) {
-      const int use_compound_pred = cm->reference_mode != SINGLE_REFERENCE;
-      const int use_hybrid_pred = cm->reference_mode == REFERENCE_MODE_SELECT;
-
-      vpx_write_bit(&header_bc, use_compound_pred);
-      if (use_compound_pred) {
-        vpx_write_bit(&header_bc, use_hybrid_pred);
-        if (use_hybrid_pred)
-          for (i = 0; i < COMP_INTER_CONTEXTS; i++)
-            vp9_cond_prob_diff_update(&header_bc, &fc->comp_inter_prob[i],
-                                      counts->comp_inter[i]);
-      }
-    }
-
-    if (cm->reference_mode != COMPOUND_REFERENCE) {
-      for (i = 0; i < REF_CONTEXTS; i++) {
-        vp9_cond_prob_diff_update(&header_bc, &fc->single_ref_prob[i][0],
-                                  counts->single_ref[i][0]);
-        vp9_cond_prob_diff_update(&header_bc, &fc->single_ref_prob[i][1],
-                                  counts->single_ref[i][1]);
-      }
-    }
-
-    if (cm->reference_mode != SINGLE_REFERENCE)
-      for (i = 0; i < REF_CONTEXTS; i++)
-        vp9_cond_prob_diff_update(&header_bc, &fc->comp_ref_prob[i],
-                                  counts->comp_ref[i]);
-
-    for (i = 0; i < BLOCK_SIZE_GROUPS; ++i)
-      prob_diff_update(vp9_intra_mode_tree, cm->fc->y_mode_prob[i],
-                       counts->y_mode[i], INTRA_MODES, &header_bc);
-
-    for (i = 0; i < PARTITION_CONTEXTS; ++i)
-      prob_diff_update(vp9_partition_tree, fc->partition_prob[i],
-                       counts->partition[i], PARTITION_TYPES, &header_bc);
-
-    vp9_write_nmv_probs(cm, cm->allow_high_precision_mv, &header_bc,
-                        &counts->mv);
-  }
-
-  vpx_stop_encode(&header_bc);
-  assert(header_bc.pos <= 0xffff);
-
-  return header_bc.pos;
-}
-
-void vp9_pack_bitstream(VP9_COMP *cpi, uint8_t *dest, size_t *size) {
-  uint8_t *data = dest;
-  size_t first_part_size, uncompressed_hdr_size;
-  struct vpx_write_bit_buffer wb = {data, 0};
-  struct vpx_write_bit_buffer saved_wb;
-
-  write_uncompressed_header(cpi, &wb);
-  saved_wb = wb;
-  vpx_wb_write_literal(&wb, 0, 16);  // don't know in advance first part. size
-
-  uncompressed_hdr_size = vpx_wb_bytes_written(&wb);
-  data += uncompressed_hdr_size;
-
-  vpx_clear_system_state();
-
-  first_part_size = write_compressed_header(cpi, data);
-  data += first_part_size;
-  // TODO(jbb): Figure out what to do if first_part_size > 16 bits.
-  vpx_wb_write_literal(&saved_wb, (int)first_part_size, 16);
-
-  data += encode_tiles(cpi, data);
-
-  *size = data - dest;
-}
diff --git a/vp9/encoder/vp9_bitstream.h b/vp9/encoder/vp9_bitstream.h
deleted file mode 100644 (file)
index f24d20f..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#ifndef VP9_ENCODER_VP9_BITSTREAM_H_
-#define VP9_ENCODER_VP9_BITSTREAM_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include "vp9/encoder/vp9_encoder.h"
-
-int vp9_get_refresh_mask(VP9_COMP *cpi);
-
-void vp9_pack_bitstream(VP9_COMP *cpi, uint8_t *dest, size_t *size);
-
-static INLINE int vp9_preserve_existing_gf(VP9_COMP *cpi) {
-  return !cpi->multi_arf_allowed && cpi->refresh_golden_frame &&
-         cpi->rc.is_src_frame_alt_ref &&
-         (!cpi->use_svc ||      // Add spatial svc base layer case here
-          (is_two_pass_svc(cpi) &&
-           cpi->svc.spatial_layer_id == 0 &&
-           cpi->svc.layer_context[0].gold_ref_idx >=0 &&
-           cpi->oxcf.ss_enable_auto_arf[0]));
-}
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP9_ENCODER_VP9_BITSTREAM_H_
diff --git a/vp9/encoder/vp9_block.h b/vp9/encoder/vp9_block.h
deleted file mode 100644 (file)
index 069c335..0000000
+++ /dev/null
@@ -1,165 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#ifndef VP9_ENCODER_VP9_BLOCK_H_
-#define VP9_ENCODER_VP9_BLOCK_H_
-
-#include "vp9/common/vp9_entropymv.h"
-#include "vp9/common/vp9_entropy.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef struct {
-  unsigned int sse;
-  int sum;
-  unsigned int var;
-} diff;
-
-struct macroblock_plane {
-  DECLARE_ALIGNED(16, int16_t, src_diff[64 * 64]);
-  tran_low_t *qcoeff;
-  tran_low_t *coeff;
-  uint16_t *eobs;
-  struct buf_2d src;
-
-  // Quantizer setings
-  int16_t *quant_fp;
-  int16_t *round_fp;
-  int16_t *quant;
-  int16_t *quant_shift;
-  int16_t *zbin;
-  int16_t *round;
-
-  int64_t quant_thred[2];
-};
-
-/* The [2] dimension is for whether we skip the EOB node (i.e. if previous
- * coefficient in this block was zero) or not. */
-typedef unsigned int vp9_coeff_cost[PLANE_TYPES][REF_TYPES][COEF_BANDS][2]
-                                   [COEFF_CONTEXTS][ENTROPY_TOKENS];
-
-typedef struct {
-  int_mv ref_mvs[MAX_REF_FRAMES][MAX_MV_REF_CANDIDATES];
-  uint8_t mode_context[MAX_REF_FRAMES];
-} MB_MODE_INFO_EXT;
-
-typedef struct macroblock MACROBLOCK;
-struct macroblock {
-  struct macroblock_plane plane[MAX_MB_PLANE];
-
-  MACROBLOCKD e_mbd;
-  MB_MODE_INFO_EXT *mbmi_ext;
-  MB_MODE_INFO_EXT *mbmi_ext_base;
-  int skip_block;
-  int select_tx_size;
-  int skip_recode;
-  int skip_optimize;
-  int q_index;
-
-  // The equivalent error at the current rdmult of one whole bit (not one
-  // bitcost unit).
-  int errorperbit;
-  // The equivalend SAD error of one (whole) bit at the current quantizer
-  // for large blocks.
-  int sadperbit16;
-  // The equivalend SAD error of one (whole) bit at the current quantizer
-  // for sub-8x8 blocks.
-  int sadperbit4;
-  int rddiv;
-  int rdmult;
-  int mb_energy;
-  int * m_search_count_ptr;
-  int * ex_search_count_ptr;
-
-  // These are set to their default values at the beginning, and then adjusted
-  // further in the encoding process.
-  BLOCK_SIZE min_partition_size;
-  BLOCK_SIZE max_partition_size;
-
-  int mv_best_ref_index[MAX_REF_FRAMES];
-  unsigned int max_mv_context[MAX_REF_FRAMES];
-  unsigned int source_variance;
-  unsigned int pred_sse[MAX_REF_FRAMES];
-  int pred_mv_sad[MAX_REF_FRAMES];
-
-  int nmvjointcost[MV_JOINTS];
-  int *nmvcost[2];
-  int *nmvcost_hp[2];
-  int **mvcost;
-
-  int nmvjointsadcost[MV_JOINTS];
-  int *nmvsadcost[2];
-  int *nmvsadcost_hp[2];
-  int **mvsadcost;
-
-  // These define limits to motion vector components to prevent them
-  // from extending outside the UMV borders
-  int mv_col_min;
-  int mv_col_max;
-  int mv_row_min;
-  int mv_row_max;
-
-  // Notes transform blocks where no coefficents are coded.
-  // Set during mode selection. Read during block encoding.
-  uint8_t zcoeff_blk[TX_SIZES][256];
-
-  int skip;
-
-  int encode_breakout;
-
-  // note that token_costs is the cost when eob node is skipped
-  vp9_coeff_cost token_costs[TX_SIZES];
-
-  int optimize;
-
-  // indicate if it is in the rd search loop or encoding process
-  int use_lp32x32fdct;
-  int skip_encode;
-
-  // use fast quantization process
-  int quant_fp;
-
-  // skip forward transform and quantization
-  uint8_t skip_txfm[MAX_MB_PLANE << 2];
-  #define SKIP_TXFM_NONE 0
-  #define SKIP_TXFM_AC_DC 1
-  #define SKIP_TXFM_AC_ONLY 2
-
-  int64_t bsse[MAX_MB_PLANE << 2];
-
-  // Used to store sub partition's choices.
-  MV pred_mv[MAX_REF_FRAMES];
-
-  // Strong color activity detection. Used in RTC coding mode to enhance
-  // the visual quality at the boundary of moving color objects.
-  uint8_t color_sensitivity[2];
-
-  uint8_t sb_is_skin;
-
-  // Used to save the status of whether a block has a low variance in
-  // choose_partitioning. 0 for 64x64, 1~2 for 64x32, 3~4 for 32x64, 5~8 for
-  // 32x32, 9~24 for 16x16.
-  uint8_t variance_low[25];
-
-  void (*fwd_txm4x4)(const int16_t *input, tran_low_t *output, int stride);
-  void (*itxm_add)(const tran_low_t *input, uint8_t *dest, int stride, int eob);
-#if CONFIG_VP9_HIGHBITDEPTH
-  void (*highbd_itxm_add)(const tran_low_t *input, uint8_t *dest, int stride,
-                          int eob, int bd);
-#endif
-};
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP9_ENCODER_VP9_BLOCK_H_
diff --git a/vp9/encoder/vp9_blockiness.c b/vp9/encoder/vp9_blockiness.c
deleted file mode 100644 (file)
index 1a89ce4..0000000
+++ /dev/null
@@ -1,134 +0,0 @@
-/*
- *  Copyright (c) 2014 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.
- */
-#include <stdlib.h>
-
-#include "vpx/vpx_integer.h"
-#include "vpx_ports/system_state.h"
-
-static int horizontal_filter(const uint8_t *s) {
-  return (s[1] - s[-2]) * 2 + (s[-1] - s[0]) * 6;
-}
-
-static int vertical_filter(const uint8_t *s, int p) {
-  return (s[p] - s[-2 * p]) * 2 + (s[-p] - s[0]) * 6;
-}
-
-static int variance(int sum, int sum_squared, int size) {
-  return sum_squared / size - (sum / size) * (sum / size);
-}
-// Calculate a blockiness level for a vertical block edge.
-// This function returns a new blockiness metric that's defined as
-
-//              p0 p1 p2 p3
-//              q0 q1 q2 q3
-// block edge ->
-//              r0 r1 r2 r3
-//              s0 s1 s2 s3
-
-// blockiness =  p0*-2+q0*6+r0*-6+s0*2 +
-//               p1*-2+q1*6+r1*-6+s1*2 +
-//               p2*-2+q2*6+r2*-6+s2*2 +
-//               p3*-2+q3*6+r3*-6+s3*2 ;
-
-// reconstructed_blockiness = abs(blockiness from reconstructed buffer -
-//                                blockiness from source buffer,0)
-//
-// I make the assumption that flat blocks are much more visible than high
-// contrast blocks. As such, I scale the result of the blockiness calc
-// by dividing the blockiness by the variance of the pixels on either side
-// of the edge as follows:
-// var_0 = (q0^2+q1^2+q2^2+q3^2) - ((q0 + q1 + q2 + q3) / 4 )^2
-// var_1 = (r0^2+r1^2+r2^2+r3^2) - ((r0 + r1 + r2 + r3) / 4 )^2
-// The returned blockiness is the scaled value
-// Reconstructed blockiness / ( 1 + var_0 + var_1 ) ;
-static int blockiness_vertical(const uint8_t *s, int sp, const uint8_t *r,
-                               int rp, int size) {
-  int s_blockiness = 0;
-  int r_blockiness = 0;
-  int sum_0 = 0;
-  int sum_sq_0 = 0;
-  int sum_1 = 0;
-  int sum_sq_1 = 0;
-  int i;
-  int var_0;
-  int var_1;
-  for (i = 0; i < size; ++i, s += sp, r += rp) {
-    s_blockiness += horizontal_filter(s);
-    r_blockiness += horizontal_filter(r);
-    sum_0 += s[0];
-    sum_sq_0 += s[0]*s[0];
-    sum_1 += s[-1];
-    sum_sq_1 += s[-1]*s[-1];
-  }
-  var_0 = variance(sum_0, sum_sq_0, size);
-  var_1 = variance(sum_1, sum_sq_1, size);
-  r_blockiness = abs(r_blockiness);
-  s_blockiness = abs(s_blockiness);
-
-  if (r_blockiness > s_blockiness)
-    return (r_blockiness - s_blockiness) / (1 + var_0 + var_1);
-  else
-    return 0;
-}
-
-// Calculate a blockiness level for a horizontal block edge
-// same as above.
-static int blockiness_horizontal(const uint8_t *s, int sp, const uint8_t *r,
-                                 int rp, int size) {
-  int s_blockiness = 0;
-  int r_blockiness = 0;
-  int sum_0 = 0;
-  int sum_sq_0 = 0;
-  int sum_1 = 0;
-  int sum_sq_1 = 0;
-  int i;
-  int var_0;
-  int var_1;
-  for (i = 0; i < size; ++i, ++s, ++r) {
-    s_blockiness += vertical_filter(s, sp);
-    r_blockiness += vertical_filter(r, rp);
-    sum_0 += s[0];
-    sum_sq_0 += s[0] * s[0];
-    sum_1 += s[-sp];
-    sum_sq_1 += s[-sp] * s[-sp];
-  }
-  var_0 = variance(sum_0, sum_sq_0, size);
-  var_1 = variance(sum_1, sum_sq_1, size);
-  r_blockiness = abs(r_blockiness);
-  s_blockiness = abs(s_blockiness);
-
-  if (r_blockiness > s_blockiness)
-    return (r_blockiness - s_blockiness) / (1 + var_0 + var_1);
-  else
-    return 0;
-}
-
-// This function returns the blockiness for the entire frame currently by
-// looking at all borders in steps of 4.
-double vp9_get_blockiness(const uint8_t *img1, int img1_pitch,
-                          const uint8_t *img2, int img2_pitch,
-                          int width, int height) {
-  double blockiness = 0;
-  int i, j;
-  vpx_clear_system_state();
-  for (i = 0; i < height; i += 4, img1 += img1_pitch * 4,
-       img2 += img2_pitch * 4) {
-    for (j = 0; j < width; j += 4) {
-      if (i > 0 && i < height && j > 0 && j < width) {
-        blockiness += blockiness_vertical(img1 + j, img1_pitch,
-                                          img2 + j, img2_pitch, 4);
-        blockiness += blockiness_horizontal(img1 + j, img1_pitch,
-                                            img2 + j, img2_pitch, 4);
-      }
-    }
-  }
-  blockiness /= width * height / 16;
-  return blockiness;
-}
diff --git a/vp9/encoder/vp9_context_tree.c b/vp9/encoder/vp9_context_tree.c
deleted file mode 100644 (file)
index 396ed3f..0000000
+++ /dev/null
@@ -1,161 +0,0 @@
-/*
- *  Copyright (c) 2014 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.
- */
-
-#include "vp9/encoder/vp9_context_tree.h"
-#include "vp9/encoder/vp9_encoder.h"
-
-static const BLOCK_SIZE square[] = {
-  BLOCK_8X8,
-  BLOCK_16X16,
-  BLOCK_32X32,
-  BLOCK_64X64,
-};
-
-static void alloc_mode_context(VP9_COMMON *cm, int num_4x4_blk,
-                               PICK_MODE_CONTEXT *ctx) {
-  const int num_blk = (num_4x4_blk < 4 ? 4 : num_4x4_blk);
-  const int num_pix = num_blk << 4;
-  int i, k;
-  ctx->num_4x4_blk = num_blk;
-
-  CHECK_MEM_ERROR(cm, ctx->zcoeff_blk,
-                  vpx_calloc(num_blk, sizeof(uint8_t)));
-  for (i = 0; i < MAX_MB_PLANE; ++i) {
-    for (k = 0; k < 3; ++k) {
-      CHECK_MEM_ERROR(cm, ctx->coeff[i][k],
-                      vpx_memalign(32, num_pix * sizeof(*ctx->coeff[i][k])));
-      CHECK_MEM_ERROR(cm, ctx->qcoeff[i][k],
-                      vpx_memalign(32, num_pix * sizeof(*ctx->qcoeff[i][k])));
-      CHECK_MEM_ERROR(cm, ctx->dqcoeff[i][k],
-                      vpx_memalign(32, num_pix * sizeof(*ctx->dqcoeff[i][k])));
-      CHECK_MEM_ERROR(cm, ctx->eobs[i][k],
-                      vpx_memalign(32, num_blk * sizeof(*ctx->eobs[i][k])));
-      ctx->coeff_pbuf[i][k]   = ctx->coeff[i][k];
-      ctx->qcoeff_pbuf[i][k]  = ctx->qcoeff[i][k];
-      ctx->dqcoeff_pbuf[i][k] = ctx->dqcoeff[i][k];
-      ctx->eobs_pbuf[i][k]    = ctx->eobs[i][k];
-    }
-  }
-}
-
-static void free_mode_context(PICK_MODE_CONTEXT *ctx) {
-  int i, k;
-  vpx_free(ctx->zcoeff_blk);
-  ctx->zcoeff_blk = 0;
-  for (i = 0; i < MAX_MB_PLANE; ++i) {
-    for (k = 0; k < 3; ++k) {
-      vpx_free(ctx->coeff[i][k]);
-      ctx->coeff[i][k] = 0;
-      vpx_free(ctx->qcoeff[i][k]);
-      ctx->qcoeff[i][k] = 0;
-      vpx_free(ctx->dqcoeff[i][k]);
-      ctx->dqcoeff[i][k] = 0;
-      vpx_free(ctx->eobs[i][k]);
-      ctx->eobs[i][k] = 0;
-    }
-  }
-}
-
-static void alloc_tree_contexts(VP9_COMMON *cm, PC_TREE *tree,
-                                int num_4x4_blk) {
-  alloc_mode_context(cm, num_4x4_blk, &tree->none);
-  alloc_mode_context(cm, num_4x4_blk/2, &tree->horizontal[0]);
-  alloc_mode_context(cm, num_4x4_blk/2, &tree->vertical[0]);
-
-  if (num_4x4_blk > 4) {
-    alloc_mode_context(cm, num_4x4_blk/2, &tree->horizontal[1]);
-    alloc_mode_context(cm, num_4x4_blk/2, &tree->vertical[1]);
-  } else {
-    memset(&tree->horizontal[1], 0, sizeof(tree->horizontal[1]));
-    memset(&tree->vertical[1], 0, sizeof(tree->vertical[1]));
-  }
-}
-
-static void free_tree_contexts(PC_TREE *tree) {
-  free_mode_context(&tree->none);
-  free_mode_context(&tree->horizontal[0]);
-  free_mode_context(&tree->horizontal[1]);
-  free_mode_context(&tree->vertical[0]);
-  free_mode_context(&tree->vertical[1]);
-}
-
-// This function sets up a tree of contexts such that at each square
-// partition level. There are contexts for none, horizontal, vertical, and
-// split.  Along with a block_size value and a selected block_size which
-// represents the state of our search.
-void vp9_setup_pc_tree(VP9_COMMON *cm, ThreadData *td) {
-  int i, j;
-  const int leaf_nodes = 64;
-  const int tree_nodes = 64 + 16 + 4 + 1;
-  int pc_tree_index = 0;
-  PC_TREE *this_pc;
-  PICK_MODE_CONTEXT *this_leaf;
-  int square_index = 1;
-  int nodes;
-
-  vpx_free(td->leaf_tree);
-  CHECK_MEM_ERROR(cm, td->leaf_tree, vpx_calloc(leaf_nodes,
-                                                sizeof(*td->leaf_tree)));
-  vpx_free(td->pc_tree);
-  CHECK_MEM_ERROR(cm, td->pc_tree, vpx_calloc(tree_nodes,
-                                              sizeof(*td->pc_tree)));
-
-  this_pc = &td->pc_tree[0];
-  this_leaf = &td->leaf_tree[0];
-
-  // 4x4 blocks smaller than 8x8 but in the same 8x8 block share the same
-  // context so we only need to allocate 1 for each 8x8 block.
-  for (i = 0; i < leaf_nodes; ++i)
-    alloc_mode_context(cm, 1, &td->leaf_tree[i]);
-
-  // Sets up all the leaf nodes in the tree.
-  for (pc_tree_index = 0; pc_tree_index < leaf_nodes; ++pc_tree_index) {
-    PC_TREE *const tree = &td->pc_tree[pc_tree_index];
-    tree->block_size = square[0];
-    alloc_tree_contexts(cm, tree, 4);
-    tree->leaf_split[0] = this_leaf++;
-    for (j = 1; j < 4; j++)
-      tree->leaf_split[j] = tree->leaf_split[0];
-  }
-
-  // Each node has 4 leaf nodes, fill each block_size level of the tree
-  // from leafs to the root.
-  for (nodes = 16; nodes > 0; nodes >>= 2) {
-    for (i = 0; i < nodes; ++i) {
-      PC_TREE *const tree = &td->pc_tree[pc_tree_index];
-      alloc_tree_contexts(cm, tree, 4 << (2 * square_index));
-      tree->block_size = square[square_index];
-      for (j = 0; j < 4; j++)
-        tree->split[j] = this_pc++;
-      ++pc_tree_index;
-    }
-    ++square_index;
-  }
-  td->pc_root = &td->pc_tree[tree_nodes - 1];
-  td->pc_root[0].none.best_mode_index = 2;
-}
-
-void vp9_free_pc_tree(ThreadData *td) {
-  const int tree_nodes = 64 + 16 + 4 + 1;
-  int i;
-
-  // Set up all 4x4 mode contexts
-  for (i = 0; i < 64; ++i)
-    free_mode_context(&td->leaf_tree[i]);
-
-  // Sets up all the leaf nodes in the tree.
-  for (i = 0; i < tree_nodes; ++i)
-    free_tree_contexts(&td->pc_tree[i]);
-
-  vpx_free(td->pc_tree);
-  td->pc_tree = NULL;
-  vpx_free(td->leaf_tree);
-  td->leaf_tree = NULL;
-}
diff --git a/vp9/encoder/vp9_context_tree.h b/vp9/encoder/vp9_context_tree.h
deleted file mode 100644 (file)
index 86ba03d..0000000
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- *  Copyright (c) 2014 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.
- */
-
-#ifndef VP9_ENCODER_VP9_CONTEXT_TREE_H_
-#define VP9_ENCODER_VP9_CONTEXT_TREE_H_
-
-#include "vp9/common/vp9_blockd.h"
-#include "vp9/encoder/vp9_block.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-struct VP9_COMP;
-struct VP9Common;
-struct ThreadData;
-
-// Structure to hold snapshot of coding context during the mode picking process
-typedef struct {
-  MODE_INFO mic;
-  MB_MODE_INFO_EXT mbmi_ext;
-  uint8_t *zcoeff_blk;
-  tran_low_t *coeff[MAX_MB_PLANE][3];
-  tran_low_t *qcoeff[MAX_MB_PLANE][3];
-  tran_low_t *dqcoeff[MAX_MB_PLANE][3];
-  uint16_t *eobs[MAX_MB_PLANE][3];
-
-  // dual buffer pointers, 0: in use, 1: best in store
-  tran_low_t *coeff_pbuf[MAX_MB_PLANE][3];
-  tran_low_t *qcoeff_pbuf[MAX_MB_PLANE][3];
-  tran_low_t *dqcoeff_pbuf[MAX_MB_PLANE][3];
-  uint16_t *eobs_pbuf[MAX_MB_PLANE][3];
-
-  int is_coded;
-  int num_4x4_blk;
-  int skip;
-  int pred_pixel_ready;
-  // For current partition, only if all Y, U, and V transform blocks'
-  // coefficients are quantized to 0, skippable is set to 0.
-  int skippable;
-  uint8_t skip_txfm[MAX_MB_PLANE << 2];
-  int best_mode_index;
-  int hybrid_pred_diff;
-  int comp_pred_diff;
-  int single_pred_diff;
-  int64_t best_filter_diff[SWITCHABLE_FILTER_CONTEXTS];
-
-  // TODO(jingning) Use RD_COST struct here instead. This involves a boarder
-  // scope of refactoring.
-  int rate;
-  int64_t dist;
-
-#if CONFIG_VP9_TEMPORAL_DENOISING
-  unsigned int newmv_sse;
-  unsigned int zeromv_sse;
-  unsigned int zeromv_lastref_sse;
-  PREDICTION_MODE best_sse_inter_mode;
-  int_mv best_sse_mv;
-  MV_REFERENCE_FRAME best_reference_frame;
-  MV_REFERENCE_FRAME best_zeromv_reference_frame;
-#endif
-
-  // motion vector cache for adaptive motion search control in partition
-  // search loop
-  MV pred_mv[MAX_REF_FRAMES];
-  INTERP_FILTER pred_interp_filter;
-} PICK_MODE_CONTEXT;
-
-typedef struct PC_TREE {
-  int index;
-  PARTITION_TYPE partitioning;
-  BLOCK_SIZE block_size;
-  PICK_MODE_CONTEXT none;
-  PICK_MODE_CONTEXT horizontal[2];
-  PICK_MODE_CONTEXT vertical[2];
-  union {
-    struct PC_TREE *split[4];
-    PICK_MODE_CONTEXT *leaf_split[4];
-  };
-} PC_TREE;
-
-void vp9_setup_pc_tree(struct VP9Common *cm, struct ThreadData *td);
-void vp9_free_pc_tree(struct ThreadData *td);
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif /* VP9_ENCODER_VP9_CONTEXT_TREE_H_ */
diff --git a/vp9/encoder/vp9_cost.c b/vp9/encoder/vp9_cost.c
deleted file mode 100644 (file)
index 5d14742..0000000
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- *  Copyright (c) 2014 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.
- */
-#include <assert.h>
-
-#include "vp9/encoder/vp9_cost.h"
-
-/* round(-log2(i/256.) * (1 << VP9_PROB_COST_SHIFT))
-   Begins with a bogus entry for simpler addressing. */
-const uint16_t vp9_prob_cost[256] = {
-    4096, 4096, 3584, 3284, 3072, 2907, 2772, 2659, 2560, 2473, 2395, 2325,
-    2260, 2201, 2147, 2096, 2048, 2003, 1961, 1921, 1883, 1847, 1813, 1780,
-    1748, 1718, 1689, 1661, 1635, 1609, 1584, 1559, 1536, 1513, 1491, 1470,
-    1449, 1429, 1409, 1390, 1371, 1353, 1335, 1318, 1301, 1284, 1268, 1252,
-    1236, 1221, 1206, 1192, 1177, 1163, 1149, 1136, 1123, 1110, 1097, 1084,
-    1072, 1059, 1047, 1036, 1024, 1013, 1001, 990,  979,  968,  958,  947,
-    937,  927,  917,  907,  897,  887,  878,  868,  859,  850,  841,  832,
-    823,  814,  806,  797,  789,  780,  772,  764,  756,  748,  740,  732,
-    724,  717,  709,  702,  694,  687,  680,  673,  665,  658,  651,  644,
-    637,  631,  624,  617,  611,  604,  598,  591,  585,  578,  572,  566,
-    560,  554,  547,  541,  535,  530,  524,  518,  512,  506,  501,  495,
-    489,  484,  478,  473,  467,  462,  456,  451,  446,  441,  435,  430,
-    425,  420,  415,  410,  405,  400,  395,  390,  385,  380,  375,  371,
-    366,  361,  356,  352,  347,  343,  338,  333,  329,  324,  320,  316,
-    311,  307,  302,  298,  294,  289,  285,  281,  277,  273,  268,  264,
-    260,  256,  252,  248,  244,  240,  236,  232,  228,  224,  220,  216,
-    212,  209,  205,  201,  197,  194,  190,  186,  182,  179,  175,  171,
-    168,  164,  161,  157,  153,  150,  146,  143,  139,  136,  132,  129,
-    125,  122,  119,  115,  112,  109,  105,  102,  99,   95,   92,   89,
-    86,   82,   79,   76,   73,   70,   66,   63,   60,   57,   54,   51,
-    48,   45,   42,   38,   35,   32,   29,   26,   23,   20,   18,   15,
-    12,   9,    6,    3};
-
-static void cost(int *costs, vpx_tree tree, const vpx_prob *probs,
-                 int i, int c) {
-  const vpx_prob prob = probs[i / 2];
-  int b;
-
-  assert(prob != 0);
-  for (b = 0; b <= 1; ++b) {
-    const int cc = c + vp9_cost_bit(prob, b);
-    const vpx_tree_index ii = tree[i + b];
-
-    if (ii <= 0)
-      costs[-ii] = cc;
-    else
-      cost(costs, tree, probs, ii, cc);
-  }
-}
-
-void vp9_cost_tokens(int *costs, const vpx_prob *probs, vpx_tree tree) {
-  cost(costs, tree, probs, 0, 0);
-}
-
-void vp9_cost_tokens_skip(int *costs, const vpx_prob *probs, vpx_tree tree) {
-  assert(tree[0] <= 0 && tree[1] > 0);
-
-  costs[-tree[0]] = vp9_cost_bit(probs[0], 0);
-  cost(costs, tree, probs, 2, 0);
-}
diff --git a/vp9/encoder/vp9_cost.h b/vp9/encoder/vp9_cost.h
deleted file mode 100644 (file)
index 0c70b78..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- *  Copyright (c) 2014 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.
- */
-
-#ifndef VP9_ENCODER_VP9_COST_H_
-#define VP9_ENCODER_VP9_COST_H_
-
-#include "vpx_dsp/prob.h"
-#include "vpx/vpx_integer.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-extern const uint16_t vp9_prob_cost[256];
-
-// The factor to scale from cost in bits to cost in vp9_prob_cost units.
-#define VP9_PROB_COST_SHIFT 9
-
-#define vp9_cost_zero(prob) (vp9_prob_cost[prob])
-
-#define vp9_cost_one(prob) vp9_cost_zero(256 - (prob))
-
-#define vp9_cost_bit(prob, bit) vp9_cost_zero((bit) ? 256 - (prob) \
-                                                    : (prob))
-
-static INLINE unsigned int cost_branch256(const unsigned int ct[2],
-                                          vpx_prob p) {
-  return ct[0] * vp9_cost_zero(p) + ct[1] * vp9_cost_one(p);
-}
-
-static INLINE int treed_cost(vpx_tree tree, const vpx_prob *probs,
-                             int bits, int len) {
-  int cost = 0;
-  vpx_tree_index i = 0;
-
-  do {
-    const int bit = (bits >> --len) & 1;
-    cost += vp9_cost_bit(probs[i >> 1], bit);
-    i = tree[i + bit];
-  } while (len);
-
-  return cost;
-}
-
-void vp9_cost_tokens(int *costs, const vpx_prob *probs, vpx_tree tree);
-void vp9_cost_tokens_skip(int *costs, const vpx_prob *probs, vpx_tree tree);
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP9_ENCODER_VP9_COST_H_
diff --git a/vp9/encoder/vp9_dct.c b/vp9/encoder/vp9_dct.c
deleted file mode 100644 (file)
index f94540b..0000000
+++ /dev/null
@@ -1,810 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#include <assert.h>
-#include <math.h>
-
-#include "./vp9_rtcd.h"
-#include "./vpx_config.h"
-#include "./vpx_dsp_rtcd.h"
-
-#include "vp9/common/vp9_blockd.h"
-#include "vp9/common/vp9_idct.h"
-#include "vpx_dsp/fwd_txfm.h"
-#include "vpx_ports/mem.h"
-
-static void fdct4(const tran_low_t *input, tran_low_t *output) {
-  tran_high_t step[4];
-  tran_high_t temp1, temp2;
-
-  step[0] = input[0] + input[3];
-  step[1] = input[1] + input[2];
-  step[2] = input[1] - input[2];
-  step[3] = input[0] - input[3];
-
-  temp1 = (step[0] + step[1]) * cospi_16_64;
-  temp2 = (step[0] - step[1]) * cospi_16_64;
-  output[0] = (tran_low_t)fdct_round_shift(temp1);
-  output[2] = (tran_low_t)fdct_round_shift(temp2);
-  temp1 = step[2] * cospi_24_64 + step[3] * cospi_8_64;
-  temp2 = -step[2] * cospi_8_64 + step[3] * cospi_24_64;
-  output[1] = (tran_low_t)fdct_round_shift(temp1);
-  output[3] = (tran_low_t)fdct_round_shift(temp2);
-}
-
-static void fdct8(const tran_low_t *input, tran_low_t *output) {
-  tran_high_t s0, s1, s2, s3, s4, s5, s6, s7;  // canbe16
-  tran_high_t t0, t1, t2, t3;                  // needs32
-  tran_high_t x0, x1, x2, x3;                  // canbe16
-
-  // stage 1
-  s0 = input[0] + input[7];
-  s1 = input[1] + input[6];
-  s2 = input[2] + input[5];
-  s3 = input[3] + input[4];
-  s4 = input[3] - input[4];
-  s5 = input[2] - input[5];
-  s6 = input[1] - input[6];
-  s7 = input[0] - input[7];
-
-  // fdct4(step, step);
-  x0 = s0 + s3;
-  x1 = s1 + s2;
-  x2 = s1 - s2;
-  x3 = s0 - s3;
-  t0 = (x0 + x1) * cospi_16_64;
-  t1 = (x0 - x1) * cospi_16_64;
-  t2 =  x2 * cospi_24_64 + x3 *  cospi_8_64;
-  t3 = -x2 * cospi_8_64  + x3 * cospi_24_64;
-  output[0] = (tran_low_t)fdct_round_shift(t0);
-  output[2] = (tran_low_t)fdct_round_shift(t2);
-  output[4] = (tran_low_t)fdct_round_shift(t1);
-  output[6] = (tran_low_t)fdct_round_shift(t3);
-
-  // Stage 2
-  t0 = (s6 - s5) * cospi_16_64;
-  t1 = (s6 + s5) * cospi_16_64;
-  t2 = (tran_low_t)fdct_round_shift(t0);
-  t3 = (tran_low_t)fdct_round_shift(t1);
-
-  // Stage 3
-  x0 = s4 + t2;
-  x1 = s4 - t2;
-  x2 = s7 - t3;
-  x3 = s7 + t3;
-
-  // Stage 4
-  t0 = x0 * cospi_28_64 + x3 *   cospi_4_64;
-  t1 = x1 * cospi_12_64 + x2 *  cospi_20_64;
-  t2 = x2 * cospi_12_64 + x1 * -cospi_20_64;
-  t3 = x3 * cospi_28_64 + x0 *  -cospi_4_64;
-  output[1] = (tran_low_t)fdct_round_shift(t0);
-  output[3] = (tran_low_t)fdct_round_shift(t2);
-  output[5] = (tran_low_t)fdct_round_shift(t1);
-  output[7] = (tran_low_t)fdct_round_shift(t3);
-}
-
-static void fdct16(const tran_low_t in[16], tran_low_t out[16]) {
-  tran_high_t step1[8];      // canbe16
-  tran_high_t step2[8];      // canbe16
-  tran_high_t step3[8];      // canbe16
-  tran_high_t input[8];      // canbe16
-  tran_high_t temp1, temp2;  // needs32
-
-  // step 1
-  input[0] = in[0] + in[15];
-  input[1] = in[1] + in[14];
-  input[2] = in[2] + in[13];
-  input[3] = in[3] + in[12];
-  input[4] = in[4] + in[11];
-  input[5] = in[5] + in[10];
-  input[6] = in[6] + in[ 9];
-  input[7] = in[7] + in[ 8];
-
-  step1[0] = in[7] - in[ 8];
-  step1[1] = in[6] - in[ 9];
-  step1[2] = in[5] - in[10];
-  step1[3] = in[4] - in[11];
-  step1[4] = in[3] - in[12];
-  step1[5] = in[2] - in[13];
-  step1[6] = in[1] - in[14];
-  step1[7] = in[0] - in[15];
-
-  // fdct8(step, step);
-  {
-    tran_high_t s0, s1, s2, s3, s4, s5, s6, s7;  // canbe16
-    tran_high_t t0, t1, t2, t3;                  // needs32
-    tran_high_t x0, x1, x2, x3;                  // canbe16
-
-    // stage 1
-    s0 = input[0] + input[7];
-    s1 = input[1] + input[6];
-    s2 = input[2] + input[5];
-    s3 = input[3] + input[4];
-    s4 = input[3] - input[4];
-    s5 = input[2] - input[5];
-    s6 = input[1] - input[6];
-    s7 = input[0] - input[7];
-
-    // fdct4(step, step);
-    x0 = s0 + s3;
-    x1 = s1 + s2;
-    x2 = s1 - s2;
-    x3 = s0 - s3;
-    t0 = (x0 + x1) * cospi_16_64;
-    t1 = (x0 - x1) * cospi_16_64;
-    t2 = x3 * cospi_8_64  + x2 * cospi_24_64;
-    t3 = x3 * cospi_24_64 - x2 * cospi_8_64;
-    out[0] = (tran_low_t)fdct_round_shift(t0);
-    out[4] = (tran_low_t)fdct_round_shift(t2);
-    out[8] = (tran_low_t)fdct_round_shift(t1);
-    out[12] = (tran_low_t)fdct_round_shift(t3);
-
-    // Stage 2
-    t0 = (s6 - s5) * cospi_16_64;
-    t1 = (s6 + s5) * cospi_16_64;
-    t2 = fdct_round_shift(t0);
-    t3 = fdct_round_shift(t1);
-
-    // Stage 3
-    x0 = s4 + t2;
-    x1 = s4 - t2;
-    x2 = s7 - t3;
-    x3 = s7 + t3;
-
-    // Stage 4
-    t0 = x0 * cospi_28_64 + x3 *   cospi_4_64;
-    t1 = x1 * cospi_12_64 + x2 *  cospi_20_64;
-    t2 = x2 * cospi_12_64 + x1 * -cospi_20_64;
-    t3 = x3 * cospi_28_64 + x0 *  -cospi_4_64;
-    out[2] = (tran_low_t)fdct_round_shift(t0);
-    out[6] = (tran_low_t)fdct_round_shift(t2);
-    out[10] = (tran_low_t)fdct_round_shift(t1);
-    out[14] = (tran_low_t)fdct_round_shift(t3);
-  }
-
-  // step 2
-  temp1 = (step1[5] - step1[2]) * cospi_16_64;
-  temp2 = (step1[4] - step1[3]) * cospi_16_64;
-  step2[2] = fdct_round_shift(temp1);
-  step2[3] = fdct_round_shift(temp2);
-  temp1 = (step1[4] + step1[3]) * cospi_16_64;
-  temp2 = (step1[5] + step1[2]) * cospi_16_64;
-  step2[4] = fdct_round_shift(temp1);
-  step2[5] = fdct_round_shift(temp2);
-
-  // step 3
-  step3[0] = step1[0] + step2[3];
-  step3[1] = step1[1] + step2[2];
-  step3[2] = step1[1] - step2[2];
-  step3[3] = step1[0] - step2[3];
-  step3[4] = step1[7] - step2[4];
-  step3[5] = step1[6] - step2[5];
-  step3[6] = step1[6] + step2[5];
-  step3[7] = step1[7] + step2[4];
-
-  // step 4
-  temp1 = step3[1] *  -cospi_8_64 + step3[6] * cospi_24_64;
-  temp2 = step3[2] * cospi_24_64 + step3[5] *  cospi_8_64;
-  step2[1] = fdct_round_shift(temp1);
-  step2[2] = fdct_round_shift(temp2);
-  temp1 = step3[2] * cospi_8_64 - step3[5] * cospi_24_64;
-  temp2 = step3[1] * cospi_24_64 + step3[6] *  cospi_8_64;
-  step2[5] = fdct_round_shift(temp1);
-  step2[6] = fdct_round_shift(temp2);
-
-  // step 5
-  step1[0] = step3[0] + step2[1];
-  step1[1] = step3[0] - step2[1];
-  step1[2] = step3[3] + step2[2];
-  step1[3] = step3[3] - step2[2];
-  step1[4] = step3[4] - step2[5];
-  step1[5] = step3[4] + step2[5];
-  step1[6] = step3[7] - step2[6];
-  step1[7] = step3[7] + step2[6];
-
-  // step 6
-  temp1 = step1[0] * cospi_30_64 + step1[7] *  cospi_2_64;
-  temp2 = step1[1] * cospi_14_64 + step1[6] * cospi_18_64;
-  out[1] = (tran_low_t)fdct_round_shift(temp1);
-  out[9] = (tran_low_t)fdct_round_shift(temp2);
-
-  temp1 = step1[2] * cospi_22_64 + step1[5] * cospi_10_64;
-  temp2 = step1[3] *  cospi_6_64 + step1[4] * cospi_26_64;
-  out[5] = (tran_low_t)fdct_round_shift(temp1);
-  out[13] = (tran_low_t)fdct_round_shift(temp2);
-
-  temp1 = step1[3] * -cospi_26_64 + step1[4] *  cospi_6_64;
-  temp2 = step1[2] * -cospi_10_64 + step1[5] * cospi_22_64;
-  out[3] = (tran_low_t)fdct_round_shift(temp1);
-  out[11] = (tran_low_t)fdct_round_shift(temp2);
-
-  temp1 = step1[1] * -cospi_18_64 + step1[6] * cospi_14_64;
-  temp2 = step1[0] *  -cospi_2_64 + step1[7] * cospi_30_64;
-  out[7] = (tran_low_t)fdct_round_shift(temp1);
-  out[15] = (tran_low_t)fdct_round_shift(temp2);
-}
-
-static void fadst4(const tran_low_t *input, tran_low_t *output) {
-  tran_high_t x0, x1, x2, x3;
-  tran_high_t s0, s1, s2, s3, s4, s5, s6, s7;
-
-  x0 = input[0];
-  x1 = input[1];
-  x2 = input[2];
-  x3 = input[3];
-
-  if (!(x0 | x1 | x2 | x3)) {
-    output[0] = output[1] = output[2] = output[3] = 0;
-    return;
-  }
-
-  s0 = sinpi_1_9 * x0;
-  s1 = sinpi_4_9 * x0;
-  s2 = sinpi_2_9 * x1;
-  s3 = sinpi_1_9 * x1;
-  s4 = sinpi_3_9 * x2;
-  s5 = sinpi_4_9 * x3;
-  s6 = sinpi_2_9 * x3;
-  s7 = x0 + x1 - x3;
-
-  x0 = s0 + s2 + s5;
-  x1 = sinpi_3_9 * s7;
-  x2 = s1 - s3 + s6;
-  x3 = s4;
-
-  s0 = x0 + x3;
-  s1 = x1;
-  s2 = x2 - x3;
-  s3 = x2 - x0 + x3;
-
-  // 1-D transform scaling factor is sqrt(2).
-  output[0] = (tran_low_t)fdct_round_shift(s0);
-  output[1] = (tran_low_t)fdct_round_shift(s1);
-  output[2] = (tran_low_t)fdct_round_shift(s2);
-  output[3] = (tran_low_t)fdct_round_shift(s3);
-}
-
-static void fadst8(const tran_low_t *input, tran_low_t *output) {
-  tran_high_t s0, s1, s2, s3, s4, s5, s6, s7;
-
-  tran_high_t x0 = input[7];
-  tran_high_t x1 = input[0];
-  tran_high_t x2 = input[5];
-  tran_high_t x3 = input[2];
-  tran_high_t x4 = input[3];
-  tran_high_t x5 = input[4];
-  tran_high_t x6 = input[1];
-  tran_high_t x7 = input[6];
-
-  // stage 1
-  s0 = cospi_2_64  * x0 + cospi_30_64 * x1;
-  s1 = cospi_30_64 * x0 - cospi_2_64  * x1;
-  s2 = cospi_10_64 * x2 + cospi_22_64 * x3;
-  s3 = cospi_22_64 * x2 - cospi_10_64 * x3;
-  s4 = cospi_18_64 * x4 + cospi_14_64 * x5;
-  s5 = cospi_14_64 * x4 - cospi_18_64 * x5;
-  s6 = cospi_26_64 * x6 + cospi_6_64  * x7;
-  s7 = cospi_6_64  * x6 - cospi_26_64 * x7;
-
-  x0 = fdct_round_shift(s0 + s4);
-  x1 = fdct_round_shift(s1 + s5);
-  x2 = fdct_round_shift(s2 + s6);
-  x3 = fdct_round_shift(s3 + s7);
-  x4 = fdct_round_shift(s0 - s4);
-  x5 = fdct_round_shift(s1 - s5);
-  x6 = fdct_round_shift(s2 - s6);
-  x7 = fdct_round_shift(s3 - s7);
-
-  // stage 2
-  s0 = x0;
-  s1 = x1;
-  s2 = x2;
-  s3 = x3;
-  s4 = cospi_8_64  * x4 + cospi_24_64 * x5;
-  s5 = cospi_24_64 * x4 - cospi_8_64  * x5;
-  s6 = - cospi_24_64 * x6 + cospi_8_64  * x7;
-  s7 =   cospi_8_64  * x6 + cospi_24_64 * x7;
-
-  x0 = s0 + s2;
-  x1 = s1 + s3;
-  x2 = s0 - s2;
-  x3 = s1 - s3;
-  x4 = fdct_round_shift(s4 + s6);
-  x5 = fdct_round_shift(s5 + s7);
-  x6 = fdct_round_shift(s4 - s6);
-  x7 = fdct_round_shift(s5 - s7);
-
-  // stage 3
-  s2 = cospi_16_64 * (x2 + x3);
-  s3 = cospi_16_64 * (x2 - x3);
-  s6 = cospi_16_64 * (x6 + x7);
-  s7 = cospi_16_64 * (x6 - x7);
-
-  x2 = fdct_round_shift(s2);
-  x3 = fdct_round_shift(s3);
-  x6 = fdct_round_shift(s6);
-  x7 = fdct_round_shift(s7);
-
-  output[0] = (tran_low_t)x0;
-  output[1] = (tran_low_t)-x4;
-  output[2] = (tran_low_t)x6;
-  output[3] = (tran_low_t)-x2;
-  output[4] = (tran_low_t)x3;
-  output[5] = (tran_low_t)-x7;
-  output[6] = (tran_low_t)x5;
-  output[7] = (tran_low_t)-x1;
-}
-
-static void fadst16(const tran_low_t *input, tran_low_t *output) {
-  tran_high_t s0, s1, s2, s3, s4, s5, s6, s7, s8;
-  tran_high_t s9, s10, s11, s12, s13, s14, s15;
-
-  tran_high_t x0 = input[15];
-  tran_high_t x1 = input[0];
-  tran_high_t x2 = input[13];
-  tran_high_t x3 = input[2];
-  tran_high_t x4 = input[11];
-  tran_high_t x5 = input[4];
-  tran_high_t x6 = input[9];
-  tran_high_t x7 = input[6];
-  tran_high_t x8 = input[7];
-  tran_high_t x9 = input[8];
-  tran_high_t x10 = input[5];
-  tran_high_t x11 = input[10];
-  tran_high_t x12 = input[3];
-  tran_high_t x13 = input[12];
-  tran_high_t x14 = input[1];
-  tran_high_t x15 = input[14];
-
-  // stage 1
-  s0 = x0 * cospi_1_64  + x1 * cospi_31_64;
-  s1 = x0 * cospi_31_64 - x1 * cospi_1_64;
-  s2 = x2 * cospi_5_64  + x3 * cospi_27_64;
-  s3 = x2 * cospi_27_64 - x3 * cospi_5_64;
-  s4 = x4 * cospi_9_64  + x5 * cospi_23_64;
-  s5 = x4 * cospi_23_64 - x5 * cospi_9_64;
-  s6 = x6 * cospi_13_64 + x7 * cospi_19_64;
-  s7 = x6 * cospi_19_64 - x7 * cospi_13_64;
-  s8 = x8 * cospi_17_64 + x9 * cospi_15_64;
-  s9 = x8 * cospi_15_64 - x9 * cospi_17_64;
-  s10 = x10 * cospi_21_64 + x11 * cospi_11_64;
-  s11 = x10 * cospi_11_64 - x11 * cospi_21_64;
-  s12 = x12 * cospi_25_64 + x13 * cospi_7_64;
-  s13 = x12 * cospi_7_64  - x13 * cospi_25_64;
-  s14 = x14 * cospi_29_64 + x15 * cospi_3_64;
-  s15 = x14 * cospi_3_64  - x15 * cospi_29_64;
-
-  x0 = fdct_round_shift(s0 + s8);
-  x1 = fdct_round_shift(s1 + s9);
-  x2 = fdct_round_shift(s2 + s10);
-  x3 = fdct_round_shift(s3 + s11);
-  x4 = fdct_round_shift(s4 + s12);
-  x5 = fdct_round_shift(s5 + s13);
-  x6 = fdct_round_shift(s6 + s14);
-  x7 = fdct_round_shift(s7 + s15);
-  x8  = fdct_round_shift(s0 - s8);
-  x9  = fdct_round_shift(s1 - s9);
-  x10 = fdct_round_shift(s2 - s10);
-  x11 = fdct_round_shift(s3 - s11);
-  x12 = fdct_round_shift(s4 - s12);
-  x13 = fdct_round_shift(s5 - s13);
-  x14 = fdct_round_shift(s6 - s14);
-  x15 = fdct_round_shift(s7 - s15);
-
-  // stage 2
-  s0 = x0;
-  s1 = x1;
-  s2 = x2;
-  s3 = x3;
-  s4 = x4;
-  s5 = x5;
-  s6 = x6;
-  s7 = x7;
-  s8 =    x8 * cospi_4_64   + x9 * cospi_28_64;
-  s9 =    x8 * cospi_28_64  - x9 * cospi_4_64;
-  s10 =   x10 * cospi_20_64 + x11 * cospi_12_64;
-  s11 =   x10 * cospi_12_64 - x11 * cospi_20_64;
-  s12 = - x12 * cospi_28_64 + x13 * cospi_4_64;
-  s13 =   x12 * cospi_4_64  + x13 * cospi_28_64;
-  s14 = - x14 * cospi_12_64 + x15 * cospi_20_64;
-  s15 =   x14 * cospi_20_64 + x15 * cospi_12_64;
-
-  x0 = s0 + s4;
-  x1 = s1 + s5;
-  x2 = s2 + s6;
-  x3 = s3 + s7;
-  x4 = s0 - s4;
-  x5 = s1 - s5;
-  x6 = s2 - s6;
-  x7 = s3 - s7;
-  x8 = fdct_round_shift(s8 + s12);
-  x9 = fdct_round_shift(s9 + s13);
-  x10 = fdct_round_shift(s10 + s14);
-  x11 = fdct_round_shift(s11 + s15);
-  x12 = fdct_round_shift(s8 - s12);
-  x13 = fdct_round_shift(s9 - s13);
-  x14 = fdct_round_shift(s10 - s14);
-  x15 = fdct_round_shift(s11 - s15);
-
-  // stage 3
-  s0 = x0;
-  s1 = x1;
-  s2 = x2;
-  s3 = x3;
-  s4 = x4 * cospi_8_64  + x5 * cospi_24_64;
-  s5 = x4 * cospi_24_64 - x5 * cospi_8_64;
-  s6 = - x6 * cospi_24_64 + x7 * cospi_8_64;
-  s7 =   x6 * cospi_8_64  + x7 * cospi_24_64;
-  s8 = x8;
-  s9 = x9;
-  s10 = x10;
-  s11 = x11;
-  s12 = x12 * cospi_8_64  + x13 * cospi_24_64;
-  s13 = x12 * cospi_24_64 - x13 * cospi_8_64;
-  s14 = - x14 * cospi_24_64 + x15 * cospi_8_64;
-  s15 =   x14 * cospi_8_64  + x15 * cospi_24_64;
-
-  x0 = s0 + s2;
-  x1 = s1 + s3;
-  x2 = s0 - s2;
-  x3 = s1 - s3;
-  x4 = fdct_round_shift(s4 + s6);
-  x5 = fdct_round_shift(s5 + s7);
-  x6 = fdct_round_shift(s4 - s6);
-  x7 = fdct_round_shift(s5 - s7);
-  x8 = s8 + s10;
-  x9 = s9 + s11;
-  x10 = s8 - s10;
-  x11 = s9 - s11;
-  x12 = fdct_round_shift(s12 + s14);
-  x13 = fdct_round_shift(s13 + s15);
-  x14 = fdct_round_shift(s12 - s14);
-  x15 = fdct_round_shift(s13 - s15);
-
-  // stage 4
-  s2 = (- cospi_16_64) * (x2 + x3);
-  s3 = cospi_16_64 * (x2 - x3);
-  s6 = cospi_16_64 * (x6 + x7);
-  s7 = cospi_16_64 * (- x6 + x7);
-  s10 = cospi_16_64 * (x10 + x11);
-  s11 = cospi_16_64 * (- x10 + x11);
-  s14 = (- cospi_16_64) * (x14 + x15);
-  s15 = cospi_16_64 * (x14 - x15);
-
-  x2 = fdct_round_shift(s2);
-  x3 = fdct_round_shift(s3);
-  x6 = fdct_round_shift(s6);
-  x7 = fdct_round_shift(s7);
-  x10 = fdct_round_shift(s10);
-  x11 = fdct_round_shift(s11);
-  x14 = fdct_round_shift(s14);
-  x15 = fdct_round_shift(s15);
-
-  output[0] = (tran_low_t)x0;
-  output[1] = (tran_low_t)-x8;
-  output[2] = (tran_low_t)x12;
-  output[3] = (tran_low_t)-x4;
-  output[4] = (tran_low_t)x6;
-  output[5] = (tran_low_t)x14;
-  output[6] = (tran_low_t)x10;
-  output[7] = (tran_low_t)x2;
-  output[8] = (tran_low_t)x3;
-  output[9] = (tran_low_t)x11;
-  output[10] = (tran_low_t)x15;
-  output[11] = (tran_low_t)x7;
-  output[12] = (tran_low_t)x5;
-  output[13] = (tran_low_t)-x13;
-  output[14] = (tran_low_t)x9;
-  output[15] = (tran_low_t)-x1;
-}
-
-static const transform_2d FHT_4[] = {
-  { fdct4,  fdct4  },  // DCT_DCT  = 0
-  { fadst4, fdct4  },  // ADST_DCT = 1
-  { fdct4,  fadst4 },  // DCT_ADST = 2
-  { fadst4, fadst4 }   // ADST_ADST = 3
-};
-
-static const transform_2d FHT_8[] = {
-  { fdct8,  fdct8  },  // DCT_DCT  = 0
-  { fadst8, fdct8  },  // ADST_DCT = 1
-  { fdct8,  fadst8 },  // DCT_ADST = 2
-  { fadst8, fadst8 }   // ADST_ADST = 3
-};
-
-static const transform_2d FHT_16[] = {
-  { fdct16,  fdct16  },  // DCT_DCT  = 0
-  { fadst16, fdct16  },  // ADST_DCT = 1
-  { fdct16,  fadst16 },  // DCT_ADST = 2
-  { fadst16, fadst16 }   // ADST_ADST = 3
-};
-
-void vp9_fht4x4_c(const int16_t *input, tran_low_t *output,
-                  int stride, int tx_type) {
-  if (tx_type == DCT_DCT) {
-    vpx_fdct4x4_c(input, output, stride);
-  } else {
-    tran_low_t out[4 * 4];
-    int i, j;
-    tran_low_t temp_in[4], temp_out[4];
-    const transform_2d ht = FHT_4[tx_type];
-
-    // Columns
-    for (i = 0; i < 4; ++i) {
-      for (j = 0; j < 4; ++j)
-        temp_in[j] = input[j * stride + i] * 16;
-      if (i == 0 && temp_in[0])
-        temp_in[0] += 1;
-      ht.cols(temp_in, temp_out);
-      for (j = 0; j < 4; ++j)
-        out[j * 4 + i] = temp_out[j];
-    }
-
-    // Rows
-    for (i = 0; i < 4; ++i) {
-      for (j = 0; j < 4; ++j)
-        temp_in[j] = out[j + i * 4];
-      ht.rows(temp_in, temp_out);
-      for (j = 0; j < 4; ++j)
-        output[j + i * 4] = (temp_out[j] + 1) >> 2;
-    }
-  }
-}
-
-void vp9_fdct8x8_quant_c(const int16_t *input, int stride,
-                         tran_low_t *coeff_ptr, intptr_t n_coeffs,
-                         int skip_block,
-                         const int16_t *zbin_ptr, const int16_t *round_ptr,
-                         const int16_t *quant_ptr,
-                         const int16_t *quant_shift_ptr,
-                         tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr,
-                         const int16_t *dequant_ptr,
-                         uint16_t *eob_ptr,
-                         const int16_t *scan, const int16_t *iscan) {
-  int eob = -1;
-
-  int i, j;
-  tran_low_t intermediate[64];
-
-  // Transform columns
-  {
-    tran_low_t *output = intermediate;
-    tran_high_t s0, s1, s2, s3, s4, s5, s6, s7;  // canbe16
-    tran_high_t t0, t1, t2, t3;                  // needs32
-    tran_high_t x0, x1, x2, x3;                  // canbe16
-
-    int i;
-    for (i = 0; i < 8; i++) {
-      // stage 1
-      s0 = (input[0 * stride] + input[7 * stride]) * 4;
-      s1 = (input[1 * stride] + input[6 * stride]) * 4;
-      s2 = (input[2 * stride] + input[5 * stride]) * 4;
-      s3 = (input[3 * stride] + input[4 * stride]) * 4;
-      s4 = (input[3 * stride] - input[4 * stride]) * 4;
-      s5 = (input[2 * stride] - input[5 * stride]) * 4;
-      s6 = (input[1 * stride] - input[6 * stride]) * 4;
-      s7 = (input[0 * stride] - input[7 * stride]) * 4;
-
-      // fdct4(step, step);
-      x0 = s0 + s3;
-      x1 = s1 + s2;
-      x2 = s1 - s2;
-      x3 = s0 - s3;
-      t0 = (x0 + x1) * cospi_16_64;
-      t1 = (x0 - x1) * cospi_16_64;
-      t2 =  x2 * cospi_24_64 + x3 *  cospi_8_64;
-      t3 = -x2 * cospi_8_64  + x3 * cospi_24_64;
-      output[0 * 8] = (tran_low_t)fdct_round_shift(t0);
-      output[2 * 8] = (tran_low_t)fdct_round_shift(t2);
-      output[4 * 8] = (tran_low_t)fdct_round_shift(t1);
-      output[6 * 8] = (tran_low_t)fdct_round_shift(t3);
-
-      // Stage 2
-      t0 = (s6 - s5) * cospi_16_64;
-      t1 = (s6 + s5) * cospi_16_64;
-      t2 = fdct_round_shift(t0);
-      t3 = fdct_round_shift(t1);
-
-      // Stage 3
-      x0 = s4 + t2;
-      x1 = s4 - t2;
-      x2 = s7 - t3;
-      x3 = s7 + t3;
-
-      // Stage 4
-      t0 = x0 * cospi_28_64 + x3 *   cospi_4_64;
-      t1 = x1 * cospi_12_64 + x2 *  cospi_20_64;
-      t2 = x2 * cospi_12_64 + x1 * -cospi_20_64;
-      t3 = x3 * cospi_28_64 + x0 *  -cospi_4_64;
-      output[1 * 8] = (tran_low_t)fdct_round_shift(t0);
-      output[3 * 8] = (tran_low_t)fdct_round_shift(t2);
-      output[5 * 8] = (tran_low_t)fdct_round_shift(t1);
-      output[7 * 8] = (tran_low_t)fdct_round_shift(t3);
-      input++;
-      output++;
-    }
-  }
-
-  // Rows
-  for (i = 0; i < 8; ++i) {
-    fdct8(&intermediate[i * 8], &coeff_ptr[i * 8]);
-    for (j = 0; j < 8; ++j)
-      coeff_ptr[j + i * 8] /= 2;
-  }
-
-  // TODO(jingning) Decide the need of these arguments after the
-  // quantization process is completed.
-  (void)zbin_ptr;
-  (void)quant_shift_ptr;
-  (void)iscan;
-
-  memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr));
-  memset(dqcoeff_ptr, 0, n_coeffs * sizeof(*dqcoeff_ptr));
-
-  if (!skip_block) {
-    // Quantization pass: All coefficients with index >= zero_flag are
-    // skippable. Note: zero_flag can be zero.
-    for (i = 0; i < n_coeffs; i++) {
-      const int rc = scan[i];
-      const int coeff = coeff_ptr[rc];
-      const int coeff_sign = (coeff >> 31);
-      const int abs_coeff = (coeff ^ coeff_sign) - coeff_sign;
-
-      int tmp = clamp(abs_coeff + round_ptr[rc != 0], INT16_MIN, INT16_MAX);
-      tmp = (tmp * quant_ptr[rc != 0]) >> 16;
-
-      qcoeff_ptr[rc] = (tmp ^ coeff_sign) - coeff_sign;
-      dqcoeff_ptr[rc] = qcoeff_ptr[rc] * dequant_ptr[rc != 0];
-
-      if (tmp)
-        eob = i;
-    }
-  }
-  *eob_ptr = eob + 1;
-}
-
-void vp9_fht8x8_c(const int16_t *input, tran_low_t *output,
-                  int stride, int tx_type) {
-  if (tx_type == DCT_DCT) {
-    vpx_fdct8x8_c(input, output, stride);
-  } else {
-    tran_low_t out[64];
-    int i, j;
-    tran_low_t temp_in[8], temp_out[8];
-    const transform_2d ht = FHT_8[tx_type];
-
-    // Columns
-    for (i = 0; i < 8; ++i) {
-      for (j = 0; j < 8; ++j)
-        temp_in[j] = input[j * stride + i] * 4;
-      ht.cols(temp_in, temp_out);
-      for (j = 0; j < 8; ++j)
-        out[j * 8 + i] = temp_out[j];
-    }
-
-    // Rows
-    for (i = 0; i < 8; ++i) {
-      for (j = 0; j < 8; ++j)
-        temp_in[j] = out[j + i * 8];
-      ht.rows(temp_in, temp_out);
-      for (j = 0; j < 8; ++j)
-        output[j + i * 8] = (temp_out[j] + (temp_out[j] < 0)) >> 1;
-    }
-  }
-}
-
-/* 4-point reversible, orthonormal Walsh-Hadamard in 3.5 adds, 0.5 shifts per
-   pixel. */
-void vp9_fwht4x4_c(const int16_t *input, tran_low_t *output, int stride) {
-  int i;
-  tran_high_t a1, b1, c1, d1, e1;
-  const int16_t *ip_pass0 = input;
-  const tran_low_t *ip = NULL;
-  tran_low_t *op = output;
-
-  for (i = 0; i < 4; i++) {
-    a1 = ip_pass0[0 * stride];
-    b1 = ip_pass0[1 * stride];
-    c1 = ip_pass0[2 * stride];
-    d1 = ip_pass0[3 * stride];
-
-    a1 += b1;
-    d1 = d1 - c1;
-    e1 = (a1 - d1) >> 1;
-    b1 = e1 - b1;
-    c1 = e1 - c1;
-    a1 -= c1;
-    d1 += b1;
-    op[0] = (tran_low_t)a1;
-    op[4] = (tran_low_t)c1;
-    op[8] = (tran_low_t)d1;
-    op[12] = (tran_low_t)b1;
-
-    ip_pass0++;
-    op++;
-  }
-  ip = output;
-  op = output;
-
-  for (i = 0; i < 4; i++) {
-    a1 = ip[0];
-    b1 = ip[1];
-    c1 = ip[2];
-    d1 = ip[3];
-
-    a1 += b1;
-    d1 -= c1;
-    e1 = (a1 - d1) >> 1;
-    b1 = e1 - b1;
-    c1 = e1 - c1;
-    a1 -= c1;
-    d1 += b1;
-    op[0] = (tran_low_t)(a1 * UNIT_QUANT_FACTOR);
-    op[1] = (tran_low_t)(c1 * UNIT_QUANT_FACTOR);
-    op[2] = (tran_low_t)(d1 * UNIT_QUANT_FACTOR);
-    op[3] = (tran_low_t)(b1 * UNIT_QUANT_FACTOR);
-
-    ip += 4;
-    op += 4;
-  }
-}
-
-void vp9_fht16x16_c(const int16_t *input, tran_low_t *output,
-                    int stride, int tx_type) {
-  if (tx_type == DCT_DCT) {
-    vpx_fdct16x16_c(input, output, stride);
-  } else {
-    tran_low_t out[256];
-    int i, j;
-    tran_low_t temp_in[16], temp_out[16];
-    const transform_2d ht = FHT_16[tx_type];
-
-    // Columns
-    for (i = 0; i < 16; ++i) {
-      for (j = 0; j < 16; ++j)
-        temp_in[j] = input[j * stride + i] * 4;
-      ht.cols(temp_in, temp_out);
-      for (j = 0; j < 16; ++j)
-        out[j * 16 + i] = (temp_out[j] + 1 + (temp_out[j] < 0)) >> 2;
-    }
-
-    // Rows
-    for (i = 0; i < 16; ++i) {
-      for (j = 0; j < 16; ++j)
-        temp_in[j] = out[j + i * 16];
-      ht.rows(temp_in, temp_out);
-      for (j = 0; j < 16; ++j)
-        output[j + i * 16] = temp_out[j];
-    }
-  }
-}
-
-#if CONFIG_VP9_HIGHBITDEPTH
-void vp9_highbd_fht4x4_c(const int16_t *input, tran_low_t *output,
-                         int stride, int tx_type) {
-  vp9_fht4x4_c(input, output, stride, tx_type);
-}
-
-void vp9_highbd_fht8x8_c(const int16_t *input, tran_low_t *output,
-                         int stride, int tx_type) {
-  vp9_fht8x8_c(input, output, stride, tx_type);
-}
-
-void vp9_highbd_fwht4x4_c(const int16_t *input, tran_low_t *output,
-                          int stride) {
-  vp9_fwht4x4_c(input, output, stride);
-}
-
-void vp9_highbd_fht16x16_c(const int16_t *input, tran_low_t *output,
-                           int stride, int tx_type) {
-  vp9_fht16x16_c(input, output, stride, tx_type);
-}
-#endif  // CONFIG_VP9_HIGHBITDEPTH
diff --git a/vp9/encoder/vp9_denoiser.c b/vp9/encoder/vp9_denoiser.c
deleted file mode 100644 (file)
index 42d456e..0000000
+++ /dev/null
@@ -1,615 +0,0 @@
-/*
- *  Copyright (c) 2012 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.
- */
-
-#include <assert.h>
-#include <limits.h>
-#include <math.h>
-
-#include "./vpx_dsp_rtcd.h"
-#include "vpx_dsp/vpx_dsp_common.h"
-#include "vpx_scale/yv12config.h"
-#include "vpx/vpx_integer.h"
-#include "vp9/common/vp9_reconinter.h"
-#include "vp9/encoder/vp9_context_tree.h"
-#include "vp9/encoder/vp9_denoiser.h"
-#include "vp9/encoder/vp9_encoder.h"
-
-#ifdef OUTPUT_YUV_DENOISED
-static void make_grayscale(YV12_BUFFER_CONFIG *yuv);
-#endif
-
-static int absdiff_thresh(BLOCK_SIZE bs, int increase_denoising) {
-  (void)bs;
-  return 3 + (increase_denoising ? 1 : 0);
-}
-
-static int delta_thresh(BLOCK_SIZE bs, int increase_denoising) {
-  (void)bs;
-  (void)increase_denoising;
-  return 4;
-}
-
-static int noise_motion_thresh(BLOCK_SIZE bs, int increase_denoising) {
-  (void)bs;
-  (void)increase_denoising;
-  return 625;
-}
-
-static unsigned int sse_thresh(BLOCK_SIZE bs, int increase_denoising) {
-  return (1 << num_pels_log2_lookup[bs]) * (increase_denoising ? 80 : 40);
-}
-
-static int sse_diff_thresh(BLOCK_SIZE bs, int increase_denoising,
-                           int motion_magnitude) {
-  if (motion_magnitude >
-      noise_motion_thresh(bs, increase_denoising)) {
-    if (increase_denoising)
-      return (1 << num_pels_log2_lookup[bs]) << 2;
-    else
-      return 0;
-  } else {
-    return (1 << num_pels_log2_lookup[bs]) << 4;
-  }
-}
-
-static int total_adj_weak_thresh(BLOCK_SIZE bs, int increase_denoising) {
-  return (1 << num_pels_log2_lookup[bs]) * (increase_denoising ? 3 : 2);
-}
-
-// TODO(jackychen): If increase_denoising is enabled in the future,
-// we might need to update the code for calculating 'total_adj' in
-// case the C code is not bit-exact with corresponding sse2 code.
-int vp9_denoiser_filter_c(const uint8_t *sig, int sig_stride,
-                          const uint8_t *mc_avg,
-                          int mc_avg_stride,
-                          uint8_t *avg, int avg_stride,
-                          int increase_denoising,
-                          BLOCK_SIZE bs,
-                          int motion_magnitude) {
-  int r, c;
-  const uint8_t *sig_start = sig;
-  const uint8_t *mc_avg_start = mc_avg;
-  uint8_t *avg_start = avg;
-  int diff, adj, absdiff, delta;
-  int adj_val[] = {3, 4, 6};
-  int total_adj = 0;
-  int shift_inc = 1;
-
-  // If motion_magnitude is small, making the denoiser more aggressive by
-  // increasing the adjustment for each level. Add another increment for
-  // blocks that are labeled for increase denoising.
-  if (motion_magnitude <= MOTION_MAGNITUDE_THRESHOLD) {
-    if (increase_denoising) {
-      shift_inc = 2;
-    }
-    adj_val[0] += shift_inc;
-    adj_val[1] += shift_inc;
-    adj_val[2] += shift_inc;
-  }
-
-  // First attempt to apply a strong temporal denoising filter.
-  for (r = 0; r < (4 << b_height_log2_lookup[bs]); ++r) {
-    for (c = 0; c < (4 << b_width_log2_lookup[bs]); ++c) {
-      diff = mc_avg[c] - sig[c];
-      absdiff = abs(diff);
-
-      if (absdiff <= absdiff_thresh(bs, increase_denoising)) {
-        avg[c] = mc_avg[c];
-        total_adj += diff;
-      } else {
-        switch (absdiff) {
-          case 4: case 5: case 6: case 7:
-            adj = adj_val[0];
-            break;
-          case 8: case 9: case 10: case 11:
-          case 12: case 13: case 14: case 15:
-            adj = adj_val[1];
-            break;
-          default:
-            adj = adj_val[2];
-        }
-        if (diff > 0) {
-          avg[c] = VPXMIN(UINT8_MAX, sig[c] + adj);
-          total_adj += adj;
-        } else {
-          avg[c] = VPXMAX(0, sig[c] - adj);
-          total_adj -= adj;
-        }
-      }
-    }
-    sig += sig_stride;
-    avg += avg_stride;
-    mc_avg += mc_avg_stride;
-  }
-
-  // If the strong filter did not modify the signal too much, we're all set.
-  if (abs(total_adj) <= total_adj_strong_thresh(bs, increase_denoising)) {
-    return FILTER_BLOCK;
-  }
-
-  // Otherwise, we try to dampen the filter if the delta is not too high.
-  delta = ((abs(total_adj) - total_adj_strong_thresh(bs, increase_denoising))
-           >> num_pels_log2_lookup[bs]) + 1;
-
-  if (delta >= delta_thresh(bs, increase_denoising)) {
-    return COPY_BLOCK;
-  }
-
-  mc_avg =  mc_avg_start;
-  avg = avg_start;
-  sig = sig_start;
-  for (r = 0; r < (4 << b_height_log2_lookup[bs]); ++r) {
-    for (c = 0; c < (4 << b_width_log2_lookup[bs]); ++c) {
-      diff = mc_avg[c] - sig[c];
-      adj = abs(diff);
-      if (adj > delta) {
-        adj = delta;
-      }
-      if (diff > 0) {
-        // Diff positive means we made positive adjustment above
-        // (in first try/attempt), so now make negative adjustment to bring
-        // denoised signal down.
-        avg[c] = VPXMAX(0, avg[c] - adj);
-        total_adj -= adj;
-      } else {
-        // Diff negative means we made negative adjustment above
-        // (in first try/attempt), so now make positive adjustment to bring
-        // denoised signal up.
-        avg[c] = VPXMIN(UINT8_MAX, avg[c] + adj);
-        total_adj += adj;
-      }
-    }
-    sig += sig_stride;
-    avg += avg_stride;
-    mc_avg += mc_avg_stride;
-  }
-
-  // We can use the filter if it has been sufficiently dampened
-  if (abs(total_adj) <= total_adj_weak_thresh(bs, increase_denoising)) {
-    return FILTER_BLOCK;
-  }
-  return COPY_BLOCK;
-}
-
-static uint8_t *block_start(uint8_t *framebuf, int stride,
-                            int mi_row, int mi_col) {
-  return framebuf + (stride * mi_row  << 3) + (mi_col << 3);
-}
-
-static VP9_DENOISER_DECISION perform_motion_compensation(VP9_DENOISER *denoiser,
-                                                         MACROBLOCK *mb,
-                                                         BLOCK_SIZE bs,
-                                                         int increase_denoising,
-                                                         int mi_row,
-                                                         int mi_col,
-                                                         PICK_MODE_CONTEXT *ctx,
-                                                         int motion_magnitude,
-                                                         int is_skin,
-                                                         int *zeromv_filter,
-                                                         int consec_zeromv) {
-  int sse_diff = ctx->zeromv_sse - ctx->newmv_sse;
-  MV_REFERENCE_FRAME frame;
-  MACROBLOCKD *filter_mbd = &mb->e_mbd;
-  MODE_INFO *mi = filter_mbd->mi[0];
-  MODE_INFO saved_mi;
-  int i;
-  struct buf_2d saved_dst[MAX_MB_PLANE];
-  struct buf_2d saved_pre[MAX_MB_PLANE];
-
-  frame = ctx->best_reference_frame;
-  saved_mi = *mi;
-
-  if (is_skin && (motion_magnitude > 0 || consec_zeromv < 4))
-    return COPY_BLOCK;
-
-  // Avoid denoising for small block (unless motion is small).
-  // Small blocks are selected in variance partition (before encoding) and
-  // will typically lie on moving areas.
-  if (denoiser->denoising_level < kDenHigh &&
-      motion_magnitude > 16 && bs <= BLOCK_8X8)
-    return COPY_BLOCK;
-
-  // If the best reference frame uses inter-prediction and there is enough of a
-  // difference in sum-squared-error, use it.
-  if (frame != INTRA_FRAME &&
-      ctx->newmv_sse != UINT_MAX &&
-      sse_diff > sse_diff_thresh(bs, increase_denoising, motion_magnitude)) {
-    mi->ref_frame[0] = ctx->best_reference_frame;
-    mi->mode = ctx->best_sse_inter_mode;
-    mi->mv[0] = ctx->best_sse_mv;
-  } else {
-    // Otherwise, use the zero reference frame.
-    frame = ctx->best_zeromv_reference_frame;
-    ctx->newmv_sse = ctx->zeromv_sse;
-    // Bias to last reference.
-    if (frame != LAST_FRAME &&
-        ((ctx->zeromv_lastref_sse < (5 * ctx->zeromv_sse) >> 2) ||
-         denoiser->denoising_level >= kDenHigh)) {
-      frame = LAST_FRAME;
-      ctx->newmv_sse = ctx->zeromv_lastref_sse;
-    }
-    mi->ref_frame[0] = frame;
-    mi->mode = ZEROMV;
-    mi->mv[0].as_int = 0;
-    ctx->best_sse_inter_mode = ZEROMV;
-    ctx->best_sse_mv.as_int = 0;
-    *zeromv_filter = 1;
-    if (denoiser->denoising_level > kDenMedium) {
-      motion_magnitude = 0;
-    }
-  }
-
-  if (ctx->newmv_sse > sse_thresh(bs, increase_denoising)) {
-    // Restore everything to its original state
-    *mi = saved_mi;
-    return COPY_BLOCK;
-  }
-  if (motion_magnitude >
-     (noise_motion_thresh(bs, increase_denoising) << 3)) {
-    // Restore everything to its original state
-    *mi = saved_mi;
-    return COPY_BLOCK;
-  }
-
-  // We will restore these after motion compensation.
-  for (i = 0; i < MAX_MB_PLANE; ++i) {
-    saved_pre[i] = filter_mbd->plane[i].pre[0];
-    saved_dst[i] = filter_mbd->plane[i].dst;
-  }
-
-  // Set the pointers in the MACROBLOCKD to point to the buffers in the denoiser
-  // struct.
-  filter_mbd->plane[0].pre[0].buf =
-      block_start(denoiser->running_avg_y[frame].y_buffer,
-                  denoiser->running_avg_y[frame].y_stride,
-                  mi_row, mi_col);
-  filter_mbd->plane[0].pre[0].stride =
-      denoiser->running_avg_y[frame].y_stride;
-  filter_mbd->plane[1].pre[0].buf =
-       block_start(denoiser->running_avg_y[frame].u_buffer,
-                  denoiser->running_avg_y[frame].uv_stride,
-                  mi_row, mi_col);
-  filter_mbd->plane[1].pre[0].stride =
-      denoiser->running_avg_y[frame].uv_stride;
-  filter_mbd->plane[2].pre[0].buf =
-      block_start(denoiser->running_avg_y[frame].v_buffer,
-                  denoiser->running_avg_y[frame].uv_stride,
-                  mi_row, mi_col);
-  filter_mbd->plane[2].pre[0].stride =
-      denoiser->running_avg_y[frame].uv_stride;
-
-  filter_mbd->plane[0].dst.buf =
-      block_start(denoiser->mc_running_avg_y.y_buffer,
-                  denoiser->mc_running_avg_y.y_stride,
-                  mi_row, mi_col);
-  filter_mbd->plane[0].dst.stride = denoiser->mc_running_avg_y.y_stride;
-  filter_mbd->plane[1].dst.buf =
-      block_start(denoiser->mc_running_avg_y.u_buffer,
-                  denoiser->mc_running_avg_y.uv_stride,
-                  mi_row, mi_col);
-  filter_mbd->plane[1].dst.stride = denoiser->mc_running_avg_y.uv_stride;
-  filter_mbd->plane[2].dst.buf =
-      block_start(denoiser->mc_running_avg_y.v_buffer,
-                  denoiser->mc_running_avg_y.uv_stride,
-                  mi_row, mi_col);
-  filter_mbd->plane[2].dst.stride = denoiser->mc_running_avg_y.uv_stride;
-
-  vp9_build_inter_predictors_sby(filter_mbd, mi_row, mi_col, bs);
-
-  // Restore everything to its original state
-  *mi = saved_mi;
-  for (i = 0; i < MAX_MB_PLANE; ++i) {
-    filter_mbd->plane[i].pre[0] = saved_pre[i];
-    filter_mbd->plane[i].dst = saved_dst[i];
-  }
-
-  return FILTER_BLOCK;
-}
-
-void vp9_denoiser_denoise(VP9_COMP *cpi, MACROBLOCK *mb,
-                          int mi_row, int mi_col, BLOCK_SIZE bs,
-                          PICK_MODE_CONTEXT *ctx,
-                          VP9_DENOISER_DECISION *denoiser_decision) {
-  int mv_col, mv_row;
-  int motion_magnitude = 0;
-  int zeromv_filter = 0;
-  VP9_DENOISER *denoiser = &cpi->denoiser;
-  VP9_DENOISER_DECISION decision = COPY_BLOCK;
-  YV12_BUFFER_CONFIG avg = denoiser->running_avg_y[INTRA_FRAME];
-  YV12_BUFFER_CONFIG mc_avg = denoiser->mc_running_avg_y;
-  uint8_t *avg_start = block_start(avg.y_buffer, avg.y_stride, mi_row, mi_col);
-  uint8_t *mc_avg_start = block_start(mc_avg.y_buffer, mc_avg.y_stride,
-                                          mi_row, mi_col);
-  struct buf_2d src = mb->plane[0].src;
-  int is_skin = 0;
-  int consec_zeromv = 0;
-  mv_col = ctx->best_sse_mv.as_mv.col;
-  mv_row = ctx->best_sse_mv.as_mv.row;
-  motion_magnitude = mv_row * mv_row + mv_col * mv_col;
-
-  if (cpi->use_skin_detection &&
-      bs <= BLOCK_32X32 &&
-      denoiser->denoising_level < kDenHigh) {
-    int motion_level = (motion_magnitude < 16) ? 0 : 1;
-    // If motion for current block is small/zero, compute consec_zeromv for
-    // skin detection (early exit in skin detection is done for large
-    // consec_zeromv when current block has small/zero motion).
-    consec_zeromv = 0;
-    if (motion_level == 0) {
-      VP9_COMMON * const cm = &cpi->common;
-      int j, i;
-      // Loop through the 8x8 sub-blocks.
-      const int bw = num_8x8_blocks_wide_lookup[BLOCK_64X64];
-      const int bh = num_8x8_blocks_high_lookup[BLOCK_64X64];
-      const int xmis = VPXMIN(cm->mi_cols - mi_col, bw);
-      const int ymis = VPXMIN(cm->mi_rows - mi_row, bh);
-      const int block_index = mi_row * cm->mi_cols + mi_col;
-      consec_zeromv = 100;
-      for (i = 0; i < ymis; i++) {
-        for (j = 0; j < xmis; j++) {
-          int bl_index = block_index + i * cm->mi_cols + j;
-          consec_zeromv = VPXMIN(cpi->consec_zero_mv[bl_index], consec_zeromv);
-          // No need to keep checking 8x8 blocks if any of the sub-blocks
-          // has small consec_zeromv (since threshold for no_skin based on
-          // zero/small motion in skin detection is high, i.e, > 4).
-          if (consec_zeromv < 4) {
-            i = ymis;
-            j = xmis;
-          }
-        }
-      }
-    }
-    // TODO(marpan): Compute skin detection over sub-blocks.
-    is_skin = vp9_compute_skin_block(mb->plane[0].src.buf,
-                                     mb->plane[1].src.buf,
-                                     mb->plane[2].src.buf,
-                                     mb->plane[0].src.stride,
-                                     mb->plane[1].src.stride,
-                                     bs,
-                                     consec_zeromv,
-                                     motion_level);
-  }
-  if (!is_skin &&
-      denoiser->denoising_level == kDenHigh) {
-    denoiser->increase_denoising = 1;
-  } else {
-    denoiser->increase_denoising = 0;
-  }
-
-  if (denoiser->denoising_level >= kDenLow)
-    decision = perform_motion_compensation(denoiser, mb, bs,
-                                           denoiser->increase_denoising,
-                                           mi_row, mi_col, ctx,
-                                           motion_magnitude,
-                                           is_skin,
-                                           &zeromv_filter,
-                                           consec_zeromv);
-
-  if (decision == FILTER_BLOCK) {
-    decision = vp9_denoiser_filter(src.buf, src.stride,
-                                 mc_avg_start, mc_avg.y_stride,
-                                 avg_start, avg.y_stride,
-                                 denoiser->increase_denoising,
-                                 bs, motion_magnitude);
-  }
-
-  if (decision == FILTER_BLOCK) {
-    vpx_convolve_copy(avg_start, avg.y_stride, src.buf, src.stride,
-                      NULL, 0, NULL, 0,
-                      num_4x4_blocks_wide_lookup[bs] << 2,
-                      num_4x4_blocks_high_lookup[bs] << 2);
-  } else {  // COPY_BLOCK
-    vpx_convolve_copy(src.buf, src.stride, avg_start, avg.y_stride,
-                      NULL, 0, NULL, 0,
-                      num_4x4_blocks_wide_lookup[bs] << 2,
-                      num_4x4_blocks_high_lookup[bs] << 2);
-  }
-  *denoiser_decision = decision;
-  if (decision == FILTER_BLOCK && zeromv_filter == 1)
-    *denoiser_decision = FILTER_ZEROMV_BLOCK;
-}
-
-static void copy_frame(YV12_BUFFER_CONFIG * const dest,
-                       const YV12_BUFFER_CONFIG * const src) {
-  int r;
-  const uint8_t *srcbuf = src->y_buffer;
-  uint8_t *destbuf = dest->y_buffer;
-
-  assert(dest->y_width == src->y_width);
-  assert(dest->y_height == src->y_height);
-
-  for (r = 0; r < dest->y_height; ++r) {
-    memcpy(destbuf, srcbuf, dest->y_width);
-    destbuf += dest->y_stride;
-    srcbuf += src->y_stride;
-  }
-}
-
-static void swap_frame_buffer(YV12_BUFFER_CONFIG * const dest,
-                              YV12_BUFFER_CONFIG * const src) {
-  uint8_t *tmp_buf = dest->y_buffer;
-  assert(dest->y_width == src->y_width);
-  assert(dest->y_height == src->y_height);
-  dest->y_buffer = src->y_buffer;
-  src->y_buffer = tmp_buf;
-}
-
-void vp9_denoiser_update_frame_info(VP9_DENOISER *denoiser,
-                                    YV12_BUFFER_CONFIG src,
-                                    FRAME_TYPE frame_type,
-                                    int refresh_alt_ref_frame,
-                                    int refresh_golden_frame,
-                                    int refresh_last_frame,
-                                    int resized) {
-  // Copy source into denoised reference buffers on KEY_FRAME or
-  // if the just encoded frame was resized.
-  if (frame_type == KEY_FRAME || resized != 0 || denoiser->reset) {
-    int i;
-    // Start at 1 so as not to overwrite the INTRA_FRAME
-    for (i = 1; i < MAX_REF_FRAMES; ++i)
-      copy_frame(&denoiser->running_avg_y[i], &src);
-    denoiser->reset = 0;
-    return;
-  }
-
-  // If more than one refresh occurs, must copy frame buffer.
-  if ((refresh_alt_ref_frame + refresh_golden_frame + refresh_last_frame)
-      > 1) {
-    if (refresh_alt_ref_frame) {
-      copy_frame(&denoiser->running_avg_y[ALTREF_FRAME],
-                 &denoiser->running_avg_y[INTRA_FRAME]);
-    }
-    if (refresh_golden_frame) {
-      copy_frame(&denoiser->running_avg_y[GOLDEN_FRAME],
-                 &denoiser->running_avg_y[INTRA_FRAME]);
-    }
-    if (refresh_last_frame) {
-      copy_frame(&denoiser->running_avg_y[LAST_FRAME],
-                 &denoiser->running_avg_y[INTRA_FRAME]);
-    }
-  } else {
-    if (refresh_alt_ref_frame) {
-      swap_frame_buffer(&denoiser->running_avg_y[ALTREF_FRAME],
-                        &denoiser->running_avg_y[INTRA_FRAME]);
-    }
-    if (refresh_golden_frame) {
-      swap_frame_buffer(&denoiser->running_avg_y[GOLDEN_FRAME],
-                        &denoiser->running_avg_y[INTRA_FRAME]);
-    }
-    if (refresh_last_frame) {
-      swap_frame_buffer(&denoiser->running_avg_y[LAST_FRAME],
-                        &denoiser->running_avg_y[INTRA_FRAME]);
-    }
-  }
-}
-
-void vp9_denoiser_reset_frame_stats(PICK_MODE_CONTEXT *ctx) {
-  ctx->zeromv_sse = UINT_MAX;
-  ctx->newmv_sse = UINT_MAX;
-  ctx->zeromv_lastref_sse = UINT_MAX;
-  ctx->best_sse_mv.as_int = 0;
-}
-
-void vp9_denoiser_update_frame_stats(MODE_INFO *mi, unsigned int sse,
-                                     PREDICTION_MODE mode,
-                                     PICK_MODE_CONTEXT *ctx) {
-  if (mi->mv[0].as_int == 0 && sse < ctx->zeromv_sse) {
-    ctx->zeromv_sse = sse;
-    ctx->best_zeromv_reference_frame = mi->ref_frame[0];
-    if (mi->ref_frame[0] == LAST_FRAME)
-      ctx->zeromv_lastref_sse = sse;
-  }
-
-  if (mi->mv[0].as_int != 0 && sse < ctx->newmv_sse) {
-    ctx->newmv_sse = sse;
-    ctx->best_sse_inter_mode = mode;
-    ctx->best_sse_mv = mi->mv[0];
-    ctx->best_reference_frame = mi->ref_frame[0];
-  }
-}
-
-int vp9_denoiser_alloc(VP9_DENOISER *denoiser, int width, int height,
-                       int ssx, int ssy,
-#if CONFIG_VP9_HIGHBITDEPTH
-                       int use_highbitdepth,
-#endif
-                       int border) {
-  int i, fail;
-  const int legacy_byte_alignment = 0;
-  assert(denoiser != NULL);
-
-  for (i = 0; i < MAX_REF_FRAMES; ++i) {
-    fail = vpx_alloc_frame_buffer(&denoiser->running_avg_y[i], width, height,
-                                  ssx, ssy,
-#if CONFIG_VP9_HIGHBITDEPTH
-                                  use_highbitdepth,
-#endif
-                                  border, legacy_byte_alignment);
-    if (fail) {
-      vp9_denoiser_free(denoiser);
-      return 1;
-    }
-#ifdef OUTPUT_YUV_DENOISED
-    make_grayscale(&denoiser->running_avg_y[i]);
-#endif
-  }
-
-  fail = vpx_alloc_frame_buffer(&denoiser->mc_running_avg_y, width, height,
-                                ssx, ssy,
-#if CONFIG_VP9_HIGHBITDEPTH
-                                use_highbitdepth,
-#endif
-                                border, legacy_byte_alignment);
-  if (fail) {
-    vp9_denoiser_free(denoiser);
-    return 1;
-  }
-
-  fail = vpx_alloc_frame_buffer(&denoiser->last_source, width, height,
-                                ssx, ssy,
-#if CONFIG_VP9_HIGHBITDEPTH
-                                use_highbitdepth,
-#endif
-                                border, legacy_byte_alignment);
-  if (fail) {
-    vp9_denoiser_free(denoiser);
-    return 1;
-  }
-#ifdef OUTPUT_YUV_DENOISED
-  make_grayscale(&denoiser->running_avg_y[i]);
-#endif
-  denoiser->increase_denoising = 0;
-  denoiser->frame_buffer_initialized = 1;
-  denoiser->denoising_level = kDenLow;
-  denoiser->prev_denoising_level = kDenLow;
-  denoiser->reset = 0;
-  return 0;
-}
-
-void vp9_denoiser_free(VP9_DENOISER *denoiser) {
-  int i;
-  denoiser->frame_buffer_initialized = 0;
-  if (denoiser == NULL) {
-    return;
-  }
-  for (i = 0; i < MAX_REF_FRAMES; ++i) {
-    vpx_free_frame_buffer(&denoiser->running_avg_y[i]);
-  }
-  vpx_free_frame_buffer(&denoiser->mc_running_avg_y);
-  vpx_free_frame_buffer(&denoiser->last_source);
-}
-
-void vp9_denoiser_set_noise_level(VP9_DENOISER *denoiser,
-                                  int noise_level) {
-  denoiser->denoising_level = noise_level;
-  if (denoiser->denoising_level > kDenLowLow &&
-      denoiser->prev_denoising_level == kDenLowLow)
-    denoiser->reset = 1;
-  else
-    denoiser->reset = 0;
-  denoiser->prev_denoising_level = denoiser->denoising_level;
-}
-
-#ifdef OUTPUT_YUV_DENOISED
-static void make_grayscale(YV12_BUFFER_CONFIG *yuv) {
-  int r, c;
-  uint8_t *u = yuv->u_buffer;
-  uint8_t *v = yuv->v_buffer;
-
-  for (r = 0; r < yuv->uv_height; ++r) {
-    for (c = 0; c < yuv->uv_width; ++c) {
-      u[c] = UINT8_MAX / 2;
-      v[c] = UINT8_MAX / 2;
-    }
-    u += yuv->uv_stride;
-    v += yuv->uv_stride;
-  }
-}
-#endif
diff --git a/vp9/encoder/vp9_denoiser.h b/vp9/encoder/vp9_denoiser.h
deleted file mode 100644 (file)
index 9c86e5a..0000000
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- *  Copyright (c) 2012 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.
- */
-
-#ifndef VP9_ENCODER_DENOISER_H_
-#define VP9_ENCODER_DENOISER_H_
-
-#include "vp9/encoder/vp9_block.h"
-#include "vp9/encoder/vp9_skin_detection.h"
-#include "vpx_scale/yv12config.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define MOTION_MAGNITUDE_THRESHOLD (8 * 3)
-
-typedef enum vp9_denoiser_decision {
-  COPY_BLOCK,
-  FILTER_BLOCK,
-  FILTER_ZEROMV_BLOCK
-} VP9_DENOISER_DECISION;
-
-typedef enum vp9_denoiser_level {
-  kDenLowLow,
-  kDenLow,
-  kDenMedium,
-  kDenHigh
-} VP9_DENOISER_LEVEL;
-
-typedef struct vp9_denoiser {
-  YV12_BUFFER_CONFIG running_avg_y[MAX_REF_FRAMES];
-  YV12_BUFFER_CONFIG mc_running_avg_y;
-  YV12_BUFFER_CONFIG last_source;
-  int increase_denoising;
-  int frame_buffer_initialized;
-  int reset;
-  VP9_DENOISER_LEVEL denoising_level;
-  VP9_DENOISER_LEVEL prev_denoising_level;
-} VP9_DENOISER;
-
-typedef struct {
-  int64_t zero_last_cost_orig;
-  int *ref_frame_cost;
-  int_mv (*frame_mv)[MAX_REF_FRAMES];
-  int reuse_inter_pred;
-  TX_SIZE best_tx_size;
-  PREDICTION_MODE best_mode;
-  MV_REFERENCE_FRAME best_ref_frame;
-  INTERP_FILTER best_pred_filter;
-  uint8_t best_mode_skip_txfm;
-} VP9_PICKMODE_CTX_DEN;
-
-struct VP9_COMP;
-
-void vp9_denoiser_update_frame_info(VP9_DENOISER *denoiser,
-                                    YV12_BUFFER_CONFIG src,
-                                    FRAME_TYPE frame_type,
-                                    int refresh_alt_ref_frame,
-                                    int refresh_golden_frame,
-                                    int refresh_last_frame,
-                                    int resized);
-
-void vp9_denoiser_denoise(struct VP9_COMP *cpi, MACROBLOCK *mb,
-                          int mi_row, int mi_col, BLOCK_SIZE bs,
-                          PICK_MODE_CONTEXT *ctx ,
-                          VP9_DENOISER_DECISION *denoiser_decision);
-
-void vp9_denoiser_reset_frame_stats(PICK_MODE_CONTEXT *ctx);
-
-void vp9_denoiser_update_frame_stats(MODE_INFO *mi,
-                                     unsigned int sse, PREDICTION_MODE mode,
-                                     PICK_MODE_CONTEXT *ctx);
-
-int vp9_denoiser_alloc(VP9_DENOISER *denoiser, int width, int height,
-                       int ssx, int ssy,
-#if CONFIG_VP9_HIGHBITDEPTH
-                       int use_highbitdepth,
-#endif
-                       int border);
-
-#if CONFIG_VP9_TEMPORAL_DENOISING
-// This function is used by both c and sse2 denoiser implementations.
-// Define it as a static function within the scope where vp9_denoiser.h
-// is referenced.
-static INLINE int total_adj_strong_thresh(BLOCK_SIZE bs,
-                                          int increase_denoising) {
-  return (1 << num_pels_log2_lookup[bs]) * (increase_denoising ? 3 : 2);
-}
-#endif
-
-void vp9_denoiser_free(VP9_DENOISER *denoiser);
-
-void vp9_denoiser_set_noise_level(VP9_DENOISER *denoiser,
-                                  int noise_level);
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP9_ENCODER_DENOISER_H_
diff --git a/vp9/encoder/vp9_encodeframe.c b/vp9/encoder/vp9_encodeframe.c
deleted file mode 100644 (file)
index e6a75d9..0000000
+++ /dev/null
@@ -1,4505 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#include <limits.h>
-#include <math.h>
-#include <stdio.h>
-
-#include "./vp9_rtcd.h"
-#include "./vpx_dsp_rtcd.h"
-#include "./vpx_config.h"
-
-#include "vpx_dsp/vpx_dsp_common.h"
-#include "vpx_ports/mem.h"
-#include "vpx_ports/vpx_timer.h"
-#include "vpx_ports/system_state.h"
-
-#include "vp9/common/vp9_common.h"
-#include "vp9/common/vp9_entropy.h"
-#include "vp9/common/vp9_entropymode.h"
-#include "vp9/common/vp9_idct.h"
-#include "vp9/common/vp9_mvref_common.h"
-#include "vp9/common/vp9_pred_common.h"
-#include "vp9/common/vp9_quant_common.h"
-#include "vp9/common/vp9_reconintra.h"
-#include "vp9/common/vp9_reconinter.h"
-#include "vp9/common/vp9_seg_common.h"
-#include "vp9/common/vp9_tile_common.h"
-
-#include "vp9/encoder/vp9_aq_360.h"
-#include "vp9/encoder/vp9_aq_complexity.h"
-#include "vp9/encoder/vp9_aq_cyclicrefresh.h"
-#include "vp9/encoder/vp9_aq_variance.h"
-#include "vp9/encoder/vp9_encodeframe.h"
-#include "vp9/encoder/vp9_encodemb.h"
-#include "vp9/encoder/vp9_encodemv.h"
-#include "vp9/encoder/vp9_ethread.h"
-#include "vp9/encoder/vp9_extend.h"
-#include "vp9/encoder/vp9_pickmode.h"
-#include "vp9/encoder/vp9_rd.h"
-#include "vp9/encoder/vp9_rdopt.h"
-#include "vp9/encoder/vp9_segmentation.h"
-#include "vp9/encoder/vp9_tokenize.h"
-
-static void encode_superblock(VP9_COMP *cpi, ThreadData * td,
-                              TOKENEXTRA **t, int output_enabled,
-                              int mi_row, int mi_col, BLOCK_SIZE bsize,
-                              PICK_MODE_CONTEXT *ctx);
-
-// This is used as a reference when computing the source variance for the
-//  purposes of activity masking.
-// Eventually this should be replaced by custom no-reference routines,
-//  which will be faster.
-static const uint8_t VP9_VAR_OFFS[64] = {
-    128, 128, 128, 128, 128, 128, 128, 128,
-    128, 128, 128, 128, 128, 128, 128, 128,
-    128, 128, 128, 128, 128, 128, 128, 128,
-    128, 128, 128, 128, 128, 128, 128, 128,
-    128, 128, 128, 128, 128, 128, 128, 128,
-    128, 128, 128, 128, 128, 128, 128, 128,
-    128, 128, 128, 128, 128, 128, 128, 128,
-    128, 128, 128, 128, 128, 128, 128, 128
-};
-
-#if CONFIG_VP9_HIGHBITDEPTH
-static const uint16_t VP9_HIGH_VAR_OFFS_8[64] = {
-    128, 128, 128, 128, 128, 128, 128, 128,
-    128, 128, 128, 128, 128, 128, 128, 128,
-    128, 128, 128, 128, 128, 128, 128, 128,
-    128, 128, 128, 128, 128, 128, 128, 128,
-    128, 128, 128, 128, 128, 128, 128, 128,
-    128, 128, 128, 128, 128, 128, 128, 128,
-    128, 128, 128, 128, 128, 128, 128, 128,
-    128, 128, 128, 128, 128, 128, 128, 128
-};
-
-static const uint16_t VP9_HIGH_VAR_OFFS_10[64] = {
-    128*4, 128*4, 128*4, 128*4, 128*4, 128*4, 128*4, 128*4,
-    128*4, 128*4, 128*4, 128*4, 128*4, 128*4, 128*4, 128*4,
-    128*4, 128*4, 128*4, 128*4, 128*4, 128*4, 128*4, 128*4,
-    128*4, 128*4, 128*4, 128*4, 128*4, 128*4, 128*4, 128*4,
-    128*4, 128*4, 128*4, 128*4, 128*4, 128*4, 128*4, 128*4,
-    128*4, 128*4, 128*4, 128*4, 128*4, 128*4, 128*4, 128*4,
-    128*4, 128*4, 128*4, 128*4, 128*4, 128*4, 128*4, 128*4,
-    128*4, 128*4, 128*4, 128*4, 128*4, 128*4, 128*4, 128*4
-};
-
-static const uint16_t VP9_HIGH_VAR_OFFS_12[64] = {
-    128*16, 128*16, 128*16, 128*16, 128*16, 128*16, 128*16, 128*16,
-    128*16, 128*16, 128*16, 128*16, 128*16, 128*16, 128*16, 128*16,
-    128*16, 128*16, 128*16, 128*16, 128*16, 128*16, 128*16, 128*16,
-    128*16, 128*16, 128*16, 128*16, 128*16, 128*16, 128*16, 128*16,
-    128*16, 128*16, 128*16, 128*16, 128*16, 128*16, 128*16, 128*16,
-    128*16, 128*16, 128*16, 128*16, 128*16, 128*16, 128*16, 128*16,
-    128*16, 128*16, 128*16, 128*16, 128*16, 128*16, 128*16, 128*16,
-    128*16, 128*16, 128*16, 128*16, 128*16, 128*16, 128*16, 128*16
-};
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-
-unsigned int vp9_get_sby_perpixel_variance(VP9_COMP *cpi,
-                                           const struct buf_2d *ref,
-                                           BLOCK_SIZE bs) {
-  unsigned int sse;
-  const unsigned int var = cpi->fn_ptr[bs].vf(ref->buf, ref->stride,
-                                              VP9_VAR_OFFS, 0, &sse);
-  return ROUND_POWER_OF_TWO(var, num_pels_log2_lookup[bs]);
-}
-
-#if CONFIG_VP9_HIGHBITDEPTH
-unsigned int vp9_high_get_sby_perpixel_variance(
-    VP9_COMP *cpi, const struct buf_2d *ref, BLOCK_SIZE bs, int bd) {
-  unsigned int var, sse;
-  switch (bd) {
-    case 10:
-      var = cpi->fn_ptr[bs].vf(ref->buf, ref->stride,
-                               CONVERT_TO_BYTEPTR(VP9_HIGH_VAR_OFFS_10),
-                               0, &sse);
-      break;
-    case 12:
-      var = cpi->fn_ptr[bs].vf(ref->buf, ref->stride,
-                               CONVERT_TO_BYTEPTR(VP9_HIGH_VAR_OFFS_12),
-                               0, &sse);
-      break;
-    case 8:
-    default:
-      var = cpi->fn_ptr[bs].vf(ref->buf, ref->stride,
-                               CONVERT_TO_BYTEPTR(VP9_HIGH_VAR_OFFS_8),
-                               0, &sse);
-      break;
-  }
-  return ROUND_POWER_OF_TWO((int64_t)var, num_pels_log2_lookup[bs]);
-}
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-
-static unsigned int get_sby_perpixel_diff_variance(VP9_COMP *cpi,
-                                                   const struct buf_2d *ref,
-                                                   int mi_row, int mi_col,
-                                                   BLOCK_SIZE bs) {
-  unsigned int sse, var;
-  uint8_t *last_y;
-  const YV12_BUFFER_CONFIG *last = get_ref_frame_buffer(cpi, LAST_FRAME);
-
-  assert(last != NULL);
-  last_y =
-      &last->y_buffer[mi_row * MI_SIZE * last->y_stride + mi_col * MI_SIZE];
-  var = cpi->fn_ptr[bs].vf(ref->buf, ref->stride, last_y, last->y_stride, &sse);
-  return ROUND_POWER_OF_TWO(var, num_pels_log2_lookup[bs]);
-}
-
-static BLOCK_SIZE get_rd_var_based_fixed_partition(VP9_COMP *cpi, MACROBLOCK *x,
-                                                   int mi_row,
-                                                   int mi_col) {
-  unsigned int var = get_sby_perpixel_diff_variance(cpi, &x->plane[0].src,
-                                                    mi_row, mi_col,
-                                                    BLOCK_64X64);
-  if (var < 8)
-    return BLOCK_64X64;
-  else if (var < 128)
-    return BLOCK_32X32;
-  else if (var < 2048)
-    return BLOCK_16X16;
-  else
-    return BLOCK_8X8;
-}
-
-// Lighter version of set_offsets that only sets the mode info
-// pointers.
-static INLINE void set_mode_info_offsets(VP9_COMMON *const cm,
-                                         MACROBLOCK *const x,
-                                         MACROBLOCKD *const xd,
-                                         int mi_row,
-                                         int mi_col) {
-  const int idx_str = xd->mi_stride * mi_row + mi_col;
-  xd->mi = cm->mi_grid_visible + idx_str;
-  xd->mi[0] = cm->mi + idx_str;
-  x->mbmi_ext = x->mbmi_ext_base + (mi_row * cm->mi_cols + mi_col);
-}
-
-static void set_offsets(VP9_COMP *cpi, const TileInfo *const tile,
-                        MACROBLOCK *const x, int mi_row, int mi_col,
-                        BLOCK_SIZE bsize) {
-  VP9_COMMON *const cm = &cpi->common;
-  MACROBLOCKD *const xd = &x->e_mbd;
-  MODE_INFO *mi;
-  const int mi_width = num_8x8_blocks_wide_lookup[bsize];
-  const int mi_height = num_8x8_blocks_high_lookup[bsize];
-  const struct segmentation *const seg = &cm->seg;
-
-  set_skip_context(xd, mi_row, mi_col);
-
-  set_mode_info_offsets(cm, x, xd, mi_row, mi_col);
-
-  mi = xd->mi[0];
-
-  // Set up destination pointers.
-  vp9_setup_dst_planes(xd->plane, get_frame_new_buffer(cm), mi_row, mi_col);
-
-  // Set up limit values for MV components.
-  // Mv beyond the range do not produce new/different prediction block.
-  x->mv_row_min = -(((mi_row + mi_height) * MI_SIZE) + VP9_INTERP_EXTEND);
-  x->mv_col_min = -(((mi_col + mi_width) * MI_SIZE) + VP9_INTERP_EXTEND);
-  x->mv_row_max = (cm->mi_rows - mi_row) * MI_SIZE + VP9_INTERP_EXTEND;
-  x->mv_col_max = (cm->mi_cols - mi_col) * MI_SIZE + VP9_INTERP_EXTEND;
-
-  // Set up distance of MB to edge of frame in 1/8th pel units.
-  assert(!(mi_col & (mi_width - 1)) && !(mi_row & (mi_height - 1)));
-  set_mi_row_col(xd, tile, mi_row, mi_height, mi_col, mi_width,
-                 cm->mi_rows, cm->mi_cols);
-
-  // Set up source buffers.
-  vp9_setup_src_planes(x, cpi->Source, mi_row, mi_col);
-
-  // R/D setup.
-  x->rddiv = cpi->rd.RDDIV;
-  x->rdmult = cpi->rd.RDMULT;
-
-  // Setup segment ID.
-  if (seg->enabled) {
-    if (cpi->oxcf.aq_mode != VARIANCE_AQ &&
-        cpi->oxcf.aq_mode != EQUATOR360_AQ) {
-      const uint8_t *const map = seg->update_map ? cpi->segmentation_map
-                                                 : cm->last_frame_seg_map;
-      mi->segment_id = get_segment_id(cm, map, bsize, mi_row, mi_col);
-    }
-    vp9_init_plane_quantizers(cpi, x);
-
-    x->encode_breakout = cpi->segment_encode_breakout[mi->segment_id];
-  } else {
-    mi->segment_id = 0;
-    x->encode_breakout = cpi->encode_breakout;
-  }
-
-  // required by vp9_append_sub8x8_mvs_for_idx() and vp9_find_best_ref_mvs()
-  xd->tile = *tile;
-}
-
-static void duplicate_mode_info_in_sb(VP9_COMMON *cm, MACROBLOCKD *xd,
-                                      int mi_row, int mi_col,
-                                      BLOCK_SIZE bsize) {
-  const int block_width = VPXMIN(num_8x8_blocks_wide_lookup[bsize],
-                                 cm->mi_cols - mi_col);
-  const int block_height = VPXMIN(num_8x8_blocks_high_lookup[bsize],
-                                  cm->mi_rows - mi_row);
-  const int mi_stride = xd->mi_stride;
-  MODE_INFO *const src_mi = xd->mi[0];
-  int i, j;
-  for (j = 0; j < block_height; ++j)
-    for (i = 0; i < block_width; ++i)
-      xd->mi[j * mi_stride + i] = src_mi;
-}
-
-static void set_block_size(VP9_COMP * const cpi,
-                           MACROBLOCK *const x,
-                           MACROBLOCKD *const xd,
-                           int mi_row, int mi_col,
-                           BLOCK_SIZE bsize) {
-  if (cpi->common.mi_cols > mi_col && cpi->common.mi_rows > mi_row) {
-    set_mode_info_offsets(&cpi->common, x, xd, mi_row, mi_col);
-    xd->mi[0]->sb_type = bsize;
-  }
-}
-
-typedef struct {
-  int64_t sum_square_error;
-  int64_t sum_error;
-  int log2_count;
-  int variance;
-} var;
-
-typedef struct {
-  var none;
-  var horz[2];
-  var vert[2];
-} partition_variance;
-
-typedef struct {
-  partition_variance part_variances;
-  var split[4];
-} v4x4;
-
-typedef struct {
-  partition_variance part_variances;
-  v4x4 split[4];
-} v8x8;
-
-typedef struct {
-  partition_variance part_variances;
-  v8x8 split[4];
-} v16x16;
-
-typedef struct {
-  partition_variance part_variances;
-  v16x16 split[4];
-} v32x32;
-
-typedef struct {
-  partition_variance part_variances;
-  v32x32 split[4];
-} v64x64;
-
-typedef struct {
-  partition_variance *part_variances;
-  var *split[4];
-} variance_node;
-
-typedef enum {
-  V16X16,
-  V32X32,
-  V64X64,
-} TREE_LEVEL;
-
-static void tree_to_node(void *data, BLOCK_SIZE bsize, variance_node *node) {
-  int i;
-  node->part_variances = NULL;
-  switch (bsize) {
-    case BLOCK_64X64: {
-      v64x64 *vt = (v64x64 *) data;
-      node->part_variances = &vt->part_variances;
-      for (i = 0; i < 4; i++)
-        node->split[i] = &vt->split[i].part_variances.none;
-      break;
-    }
-    case BLOCK_32X32: {
-      v32x32 *vt = (v32x32 *) data;
-      node->part_variances = &vt->part_variances;
-      for (i = 0; i < 4; i++)
-        node->split[i] = &vt->split[i].part_variances.none;
-      break;
-    }
-    case BLOCK_16X16: {
-      v16x16 *vt = (v16x16 *) data;
-      node->part_variances = &vt->part_variances;
-      for (i = 0; i < 4; i++)
-        node->split[i] = &vt->split[i].part_variances.none;
-      break;
-    }
-    case BLOCK_8X8: {
-      v8x8 *vt = (v8x8 *) data;
-      node->part_variances = &vt->part_variances;
-      for (i = 0; i < 4; i++)
-        node->split[i] = &vt->split[i].part_variances.none;
-      break;
-    }
-    case BLOCK_4X4: {
-      v4x4 *vt = (v4x4 *) data;
-      node->part_variances = &vt->part_variances;
-      for (i = 0; i < 4; i++)
-        node->split[i] = &vt->split[i];
-      break;
-    }
-    default: {
-      assert(0);
-      break;
-    }
-  }
-}
-
-// Set variance values given sum square error, sum error, count.
-static void fill_variance(int64_t s2, int64_t s, int c, var *v) {
-  v->sum_square_error = s2;
-  v->sum_error = s;
-  v->log2_count = c;
-}
-
-static void get_variance(var *v) {
-  v->variance = (int)(256 * (v->sum_square_error -
-      ((v->sum_error * v->sum_error) >> v->log2_count)) >> v->log2_count);
-}
-
-static void sum_2_variances(const var *a, const var *b, var *r) {
-  assert(a->log2_count == b->log2_count);
-  fill_variance(a->sum_square_error + b->sum_square_error,
-                a->sum_error + b->sum_error, a->log2_count + 1, r);
-}
-
-static void fill_variance_tree(void *data, BLOCK_SIZE bsize) {
-  variance_node node;
-  memset(&node, 0, sizeof(node));
-  tree_to_node(data, bsize, &node);
-  sum_2_variances(node.split[0], node.split[1], &node.part_variances->horz[0]);
-  sum_2_variances(node.split[2], node.split[3], &node.part_variances->horz[1]);
-  sum_2_variances(node.split[0], node.split[2], &node.part_variances->vert[0]);
-  sum_2_variances(node.split[1], node.split[3], &node.part_variances->vert[1]);
-  sum_2_variances(&node.part_variances->vert[0], &node.part_variances->vert[1],
-                  &node.part_variances->none);
-}
-
-static int set_vt_partitioning(VP9_COMP *cpi,
-                               MACROBLOCK *const x,
-                               MACROBLOCKD *const xd,
-                               void *data,
-                               BLOCK_SIZE bsize,
-                               int mi_row,
-                               int mi_col,
-                               int64_t threshold,
-                               BLOCK_SIZE bsize_min,
-                               int force_split) {
-  VP9_COMMON * const cm = &cpi->common;
-  variance_node vt;
-  const int block_width = num_8x8_blocks_wide_lookup[bsize];
-  const int block_height = num_8x8_blocks_high_lookup[bsize];
-
-  assert(block_height == block_width);
-  tree_to_node(data, bsize, &vt);
-
-  if (force_split == 1)
-    return 0;
-
-  // For bsize=bsize_min (16x16/8x8 for 8x8/4x4 downsampling), select if
-  // variance is below threshold, otherwise split will be selected.
-  // No check for vert/horiz split as too few samples for variance.
-  if (bsize == bsize_min) {
-    // Variance already computed to set the force_split.
-    if (cm->frame_type == KEY_FRAME)
-      get_variance(&vt.part_variances->none);
-    if (mi_col + block_width / 2 < cm->mi_cols &&
-        mi_row + block_height / 2 < cm->mi_rows &&
-        vt.part_variances->none.variance < threshold) {
-      set_block_size(cpi, x, xd, mi_row, mi_col, bsize);
-      return 1;
-    }
-    return 0;
-  } else if (bsize > bsize_min) {
-    // Variance already computed to set the force_split.
-    if (cm->frame_type == KEY_FRAME)
-      get_variance(&vt.part_variances->none);
-    // For key frame: take split for bsize above 32X32 or very high variance.
-    if (cm->frame_type == KEY_FRAME &&
-        (bsize > BLOCK_32X32 ||
-        vt.part_variances->none.variance > (threshold << 4))) {
-      return 0;
-    }
-    // If variance is low, take the bsize (no split).
-    if (mi_col + block_width / 2 < cm->mi_cols &&
-        mi_row + block_height / 2 < cm->mi_rows &&
-        vt.part_variances->none.variance < threshold) {
-      set_block_size(cpi, x, xd, mi_row, mi_col, bsize);
-      return 1;
-    }
-
-    // Check vertical split.
-    if (mi_row + block_height / 2 < cm->mi_rows) {
-      BLOCK_SIZE subsize = get_subsize(bsize, PARTITION_VERT);
-      get_variance(&vt.part_variances->vert[0]);
-      get_variance(&vt.part_variances->vert[1]);
-      if (vt.part_variances->vert[0].variance < threshold &&
-          vt.part_variances->vert[1].variance < threshold &&
-          get_plane_block_size(subsize, &xd->plane[1]) < BLOCK_INVALID) {
-        set_block_size(cpi, x, xd, mi_row, mi_col, subsize);
-        set_block_size(cpi, x, xd, mi_row, mi_col + block_width / 2, subsize);
-        return 1;
-      }
-    }
-    // Check horizontal split.
-    if (mi_col + block_width / 2 < cm->mi_cols) {
-      BLOCK_SIZE subsize = get_subsize(bsize, PARTITION_HORZ);
-      get_variance(&vt.part_variances->horz[0]);
-      get_variance(&vt.part_variances->horz[1]);
-      if (vt.part_variances->horz[0].variance < threshold &&
-          vt.part_variances->horz[1].variance < threshold &&
-          get_plane_block_size(subsize, &xd->plane[1]) < BLOCK_INVALID) {
-        set_block_size(cpi, x, xd, mi_row, mi_col, subsize);
-        set_block_size(cpi, x, xd, mi_row + block_height / 2, mi_col, subsize);
-        return 1;
-      }
-    }
-
-    return 0;
-  }
-  return 0;
-}
-
-// Set the variance split thresholds for following the block sizes:
-// 0 - threshold_64x64, 1 - threshold_32x32, 2 - threshold_16x16,
-// 3 - vbp_threshold_8x8. vbp_threshold_8x8 (to split to 4x4 partition) is
-// currently only used on key frame.
-static void set_vbp_thresholds(VP9_COMP *cpi, int64_t thresholds[], int q) {
-  VP9_COMMON *const cm = &cpi->common;
-  const int is_key_frame = (cm->frame_type == KEY_FRAME);
-  const int threshold_multiplier = is_key_frame ? 20 : 1;
-  int64_t threshold_base = (int64_t)(threshold_multiplier *
-      cpi->y_dequant[q][1]);
-  if (is_key_frame) {
-    thresholds[0] = threshold_base;
-    thresholds[1] = threshold_base >> 2;
-    thresholds[2] = threshold_base >> 2;
-    thresholds[3] = threshold_base << 2;
-  } else {
-    // Increase base variance threshold based on  estimated noise level.
-    if (cpi->noise_estimate.enabled) {
-      NOISE_LEVEL noise_level = vp9_noise_estimate_extract_level(
-          &cpi->noise_estimate);
-      if (noise_level == kHigh)
-        threshold_base = 3 * threshold_base;
-      else if (noise_level == kMedium)
-        threshold_base = threshold_base << 1;
-      else if (noise_level < kLow)
-        threshold_base = (7 * threshold_base) >> 3;
-    }
-    if (cm->width <= 352 && cm->height <= 288) {
-      thresholds[0] = threshold_base >> 3;
-      thresholds[1] = threshold_base >> 1;
-      thresholds[2] = threshold_base << 3;
-    } else {
-      thresholds[0] = threshold_base;
-      thresholds[1] = (5 * threshold_base) >> 2;
-      if (cm->width >= 1920 && cm->height >= 1080)
-        thresholds[1] = (7 * threshold_base) >> 2;
-      thresholds[2] = threshold_base << cpi->oxcf.speed;
-    }
-  }
-}
-
-void vp9_set_variance_partition_thresholds(VP9_COMP *cpi, int q) {
-  VP9_COMMON *const cm = &cpi->common;
-  SPEED_FEATURES *const sf = &cpi->sf;
-  const int is_key_frame = (cm->frame_type == KEY_FRAME);
-  if (sf->partition_search_type != VAR_BASED_PARTITION &&
-      sf->partition_search_type != REFERENCE_PARTITION) {
-    return;
-  } else {
-    set_vbp_thresholds(cpi, cpi->vbp_thresholds, q);
-    // The thresholds below are not changed locally.
-    if (is_key_frame) {
-      cpi->vbp_threshold_sad = 0;
-      cpi->vbp_bsize_min = BLOCK_8X8;
-    } else {
-      if (cm->width <= 352 && cm->height <= 288)
-        cpi->vbp_threshold_sad = 10;
-      else
-        cpi->vbp_threshold_sad = (cpi->y_dequant[q][1] << 1) > 1000 ?
-            (cpi->y_dequant[q][1] << 1) : 1000;
-      cpi->vbp_bsize_min = BLOCK_16X16;
-    }
-    cpi->vbp_threshold_minmax = 15 + (q >> 3);
-  }
-}
-
-// Compute the minmax over the 8x8 subblocks.
-static int compute_minmax_8x8(const uint8_t *s, int sp, const uint8_t *d,
-                              int dp, int x16_idx, int y16_idx,
-#if CONFIG_VP9_HIGHBITDEPTH
-                              int highbd_flag,
-#endif
-                              int pixels_wide,
-                              int pixels_high) {
-  int k;
-  int minmax_max = 0;
-  int minmax_min = 255;
-  // Loop over the 4 8x8 subblocks.
-  for (k = 0; k < 4; k++) {
-    int x8_idx = x16_idx + ((k & 1) << 3);
-    int y8_idx = y16_idx + ((k >> 1) << 3);
-    int min = 0;
-    int max = 0;
-    if (x8_idx < pixels_wide && y8_idx < pixels_high) {
-#if CONFIG_VP9_HIGHBITDEPTH
-      if (highbd_flag & YV12_FLAG_HIGHBITDEPTH) {
-        vpx_highbd_minmax_8x8(s + y8_idx * sp + x8_idx, sp,
-                              d + y8_idx * dp + x8_idx, dp,
-                              &min, &max);
-      } else {
-        vpx_minmax_8x8(s + y8_idx * sp + x8_idx, sp,
-                       d + y8_idx * dp + x8_idx, dp,
-                       &min, &max);
-      }
-#else
-      vpx_minmax_8x8(s + y8_idx * sp + x8_idx, sp,
-                     d + y8_idx * dp + x8_idx, dp,
-                     &min, &max);
-#endif
-      if ((max - min) > minmax_max)
-        minmax_max = (max - min);
-      if ((max - min) < minmax_min)
-        minmax_min = (max - min);
-    }
-  }
-  return (minmax_max - minmax_min);
-}
-
-static void fill_variance_4x4avg(const uint8_t *s, int sp, const uint8_t *d,
-                                 int dp, int x8_idx, int y8_idx, v8x8 *vst,
-#if CONFIG_VP9_HIGHBITDEPTH
-                                 int highbd_flag,
-#endif
-                                 int pixels_wide,
-                                 int pixels_high,
-                                 int is_key_frame) {
-  int k;
-  for (k = 0; k < 4; k++) {
-    int x4_idx = x8_idx + ((k & 1) << 2);
-    int y4_idx = y8_idx + ((k >> 1) << 2);
-    unsigned int sse = 0;
-    int sum = 0;
-    if (x4_idx < pixels_wide && y4_idx < pixels_high) {
-      int s_avg;
-      int d_avg = 128;
-#if CONFIG_VP9_HIGHBITDEPTH
-      if (highbd_flag & YV12_FLAG_HIGHBITDEPTH) {
-        s_avg = vpx_highbd_avg_4x4(s + y4_idx * sp + x4_idx, sp);
-        if (!is_key_frame)
-          d_avg = vpx_highbd_avg_4x4(d + y4_idx * dp + x4_idx, dp);
-      } else {
-        s_avg = vpx_avg_4x4(s + y4_idx * sp + x4_idx, sp);
-        if (!is_key_frame)
-          d_avg = vpx_avg_4x4(d + y4_idx * dp + x4_idx, dp);
-      }
-#else
-      s_avg = vpx_avg_4x4(s + y4_idx * sp + x4_idx, sp);
-      if (!is_key_frame)
-        d_avg = vpx_avg_4x4(d + y4_idx * dp + x4_idx, dp);
-#endif
-      sum = s_avg - d_avg;
-      sse = sum * sum;
-    }
-    fill_variance(sse, sum, 0, &vst->split[k].part_variances.none);
-  }
-}
-
-static void fill_variance_8x8avg(const uint8_t *s, int sp, const uint8_t *d,
-                                 int dp, int x16_idx, int y16_idx, v16x16 *vst,
-#if CONFIG_VP9_HIGHBITDEPTH
-                                 int highbd_flag,
-#endif
-                                 int pixels_wide,
-                                 int pixels_high,
-                                 int is_key_frame) {
-  int k;
-  for (k = 0; k < 4; k++) {
-    int x8_idx = x16_idx + ((k & 1) << 3);
-    int y8_idx = y16_idx + ((k >> 1) << 3);
-    unsigned int sse = 0;
-    int sum = 0;
-    if (x8_idx < pixels_wide && y8_idx < pixels_high) {
-      int s_avg;
-      int d_avg = 128;
-#if CONFIG_VP9_HIGHBITDEPTH
-      if (highbd_flag & YV12_FLAG_HIGHBITDEPTH) {
-        s_avg = vpx_highbd_avg_8x8(s + y8_idx * sp + x8_idx, sp);
-        if (!is_key_frame)
-          d_avg = vpx_highbd_avg_8x8(d + y8_idx * dp + x8_idx, dp);
-      } else {
-        s_avg = vpx_avg_8x8(s + y8_idx * sp + x8_idx, sp);
-        if (!is_key_frame)
-          d_avg = vpx_avg_8x8(d + y8_idx * dp + x8_idx, dp);
-      }
-#else
-      s_avg = vpx_avg_8x8(s + y8_idx * sp + x8_idx, sp);
-      if (!is_key_frame)
-        d_avg = vpx_avg_8x8(d + y8_idx * dp + x8_idx, dp);
-#endif
-      sum = s_avg - d_avg;
-      sse = sum * sum;
-    }
-    fill_variance(sse, sum, 0, &vst->split[k].part_variances.none);
-  }
-}
-
-#if !CONFIG_VP9_HIGHBITDEPTH
-// Check if most of the superblock is skin content, and if so, force split to
-// 32x32, and set x->sb_is_skin for use in mode selection.
-static int skin_sb_split(VP9_COMP *cpi, MACROBLOCK *x, const int low_res,
-                         int mi_row, int mi_col, int *force_split) {
-  VP9_COMMON * const cm = &cpi->common;
-  // Avoid checking superblocks on/near boundary and avoid low resolutions.
-  // Note superblock may still pick 64X64 if y_sad is very small
-  // (i.e., y_sad < cpi->vbp_threshold_sad) below. For now leave this as is.
-  if (!low_res && (mi_col >= 8 && mi_col + 8 < cm->mi_cols && mi_row >= 8 &&
-      mi_row + 8 < cm->mi_rows)) {
-    int num_16x16_skin = 0;
-    int num_16x16_nonskin = 0;
-    uint8_t *ysignal = x->plane[0].src.buf;
-    uint8_t *usignal = x->plane[1].src.buf;
-    uint8_t *vsignal = x->plane[2].src.buf;
-    int sp = x->plane[0].src.stride;
-    int spuv = x->plane[1].src.stride;
-    const int block_index = mi_row * cm->mi_cols + mi_col;
-    const int bw = num_8x8_blocks_wide_lookup[BLOCK_64X64];
-    const int bh = num_8x8_blocks_high_lookup[BLOCK_64X64];
-    const int xmis = VPXMIN(cm->mi_cols - mi_col, bw);
-    const int ymis = VPXMIN(cm->mi_rows - mi_row, bh);
-    // Loop through the 16x16 sub-blocks.
-    int i, j;
-    for (i = 0; i < ymis; i+=2) {
-      for (j = 0; j < xmis; j+=2) {
-        int bl_index = block_index + i * cm->mi_cols + j;
-        int bl_index1 = bl_index + 1;
-        int bl_index2 = bl_index + cm->mi_cols;
-        int bl_index3 = bl_index2 + 1;
-        int consec_zeromv = VPXMIN(cpi->consec_zero_mv[bl_index],
-                                   VPXMIN(cpi->consec_zero_mv[bl_index1],
-                                   VPXMIN(cpi->consec_zero_mv[bl_index2],
-                                   cpi->consec_zero_mv[bl_index3])));
-        int is_skin = vp9_compute_skin_block(ysignal,
-                                             usignal,
-                                             vsignal,
-                                             sp,
-                                             spuv,
-                                             BLOCK_16X16,
-                                             consec_zeromv,
-                                             0);
-        num_16x16_skin += is_skin;
-        num_16x16_nonskin += (1 - is_skin);
-        if (num_16x16_nonskin > 3) {
-          // Exit loop if at least 4 of the 16x16 blocks are not skin.
-          i = ymis;
-          break;
-        }
-        ysignal += 16;
-        usignal += 8;
-        vsignal += 8;
-      }
-      ysignal += (sp << 4) - 64;
-      usignal += (spuv << 3) - 32;
-      vsignal += (spuv << 3) - 32;
-    }
-    if (num_16x16_skin > 12) {
-      *force_split = 1;
-      return 1;
-    }
-  }
-  return 0;
-}
-#endif
-
-// This function chooses partitioning based on the variance between source and
-// reconstructed last, where variance is computed for down-sampled inputs.
-static int choose_partitioning(VP9_COMP *cpi,
-                               const TileInfo *const tile,
-                               MACROBLOCK *x,
-                               int mi_row, int mi_col) {
-  VP9_COMMON * const cm = &cpi->common;
-  MACROBLOCKD *xd = &x->e_mbd;
-  int i, j, k, m;
-  v64x64 vt;
-  v16x16 vt2[16];
-  int force_split[21];
-  int avg_32x32;
-  int avg_16x16[4];
-  uint8_t *s;
-  const uint8_t *d;
-  int sp;
-  int dp;
-  // Ref frame used in partitioning.
-  MV_REFERENCE_FRAME ref_frame_partition = LAST_FRAME;
-  int pixels_wide = 64, pixels_high = 64;
-  int64_t thresholds[4] = {cpi->vbp_thresholds[0], cpi->vbp_thresholds[1],
-      cpi->vbp_thresholds[2], cpi->vbp_thresholds[3]};
-
-  // For the variance computation under SVC mode, we treat the frame as key if
-  // the reference (base layer frame) is key frame (i.e., is_key_frame == 1).
-  const int is_key_frame = (cm->frame_type == KEY_FRAME ||
-      (is_one_pass_cbr_svc(cpi) &&
-      cpi->svc.layer_context[cpi->svc.temporal_layer_id].is_key_frame));
-  // Always use 4x4 partition for key frame.
-  const int use_4x4_partition = cm->frame_type == KEY_FRAME;
-  const int low_res = (cm->width <= 352 && cm->height <= 288);
-  int variance4x4downsample[16];
-  int segment_id;
-
-  set_offsets(cpi, tile, x, mi_row, mi_col, BLOCK_64X64);
-  segment_id = xd->mi[0]->segment_id;
-  if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ && cm->seg.enabled) {
-    if (cyclic_refresh_segment_id_boosted(segment_id)) {
-      int q = vp9_get_qindex(&cm->seg, segment_id, cm->base_qindex);
-      set_vbp_thresholds(cpi, thresholds, q);
-    }
-  }
-
-  memset(x->variance_low, 0, sizeof(x->variance_low));
-
-  if (xd->mb_to_right_edge < 0)
-    pixels_wide += (xd->mb_to_right_edge >> 3);
-  if (xd->mb_to_bottom_edge < 0)
-    pixels_high += (xd->mb_to_bottom_edge >> 3);
-
-  s = x->plane[0].src.buf;
-  sp = x->plane[0].src.stride;
-
-  // Index for force_split: 0 for 64x64, 1-4 for 32x32 blocks,
-  // 5-20 for the 16x16 blocks.
-  force_split[0] = 0;
-
-  if (!is_key_frame) {
-    // In the case of spatial/temporal scalable coding, the assumption here is
-    // that the temporal reference frame will always be of type LAST_FRAME.
-    // TODO(marpan): If that assumption is broken, we need to revisit this code.
-    MODE_INFO *mi = xd->mi[0];
-    unsigned int uv_sad;
-    const YV12_BUFFER_CONFIG *yv12 = get_ref_frame_buffer(cpi, LAST_FRAME);
-
-    const YV12_BUFFER_CONFIG *yv12_g = NULL;
-    unsigned int y_sad, y_sad_g, y_sad_thr;
-    const BLOCK_SIZE bsize = BLOCK_32X32
-        + (mi_col + 4 < cm->mi_cols) * 2 + (mi_row + 4 < cm->mi_rows);
-
-    assert(yv12 != NULL);
-
-    if (!(is_one_pass_cbr_svc(cpi) && cpi->svc.spatial_layer_id)) {
-      // For now, GOLDEN will not be used for non-zero spatial layers, since
-      // it may not be a temporal reference.
-      yv12_g = get_ref_frame_buffer(cpi, GOLDEN_FRAME);
-    }
-
-    if (yv12_g && yv12_g != yv12 &&
-       (cpi->ref_frame_flags & VP9_GOLD_FLAG)) {
-      vp9_setup_pre_planes(xd, 0, yv12_g, mi_row, mi_col,
-                           &cm->frame_refs[GOLDEN_FRAME - 1].sf);
-      y_sad_g = cpi->fn_ptr[bsize].sdf(x->plane[0].src.buf,
-                                       x->plane[0].src.stride,
-                                       xd->plane[0].pre[0].buf,
-                                       xd->plane[0].pre[0].stride);
-    } else {
-      y_sad_g = UINT_MAX;
-    }
-
-    vp9_setup_pre_planes(xd, 0, yv12, mi_row, mi_col,
-                         &cm->frame_refs[LAST_FRAME - 1].sf);
-    mi->ref_frame[0] = LAST_FRAME;
-    mi->ref_frame[1] = NONE;
-    mi->sb_type = BLOCK_64X64;
-    mi->mv[0].as_int = 0;
-    mi->interp_filter = BILINEAR;
-
-    y_sad = vp9_int_pro_motion_estimation(cpi, x, bsize, mi_row, mi_col);
-    // Pick ref frame for partitioning, bias last frame when y_sad_g and y_sad
-    // are close if short_circuit_low_temp_var is on.
-    y_sad_thr = cpi->sf.short_circuit_low_temp_var ? (y_sad * 7) >> 3 : y_sad;
-    if (y_sad_g < y_sad_thr) {
-      vp9_setup_pre_planes(xd, 0, yv12_g, mi_row, mi_col,
-                           &cm->frame_refs[GOLDEN_FRAME - 1].sf);
-      mi->ref_frame[0] = GOLDEN_FRAME;
-      mi->mv[0].as_int = 0;
-      y_sad = y_sad_g;
-      ref_frame_partition = GOLDEN_FRAME;
-    } else {
-      x->pred_mv[LAST_FRAME] = mi->mv[0].as_mv;
-      ref_frame_partition = LAST_FRAME;
-    }
-
-    set_ref_ptrs(cm, xd, mi->ref_frame[0], mi->ref_frame[1]);
-    vp9_build_inter_predictors_sb(xd, mi_row, mi_col, BLOCK_64X64);
-
-    x->sb_is_skin = 0;
-#if !CONFIG_VP9_HIGHBITDEPTH
-    if (cpi->use_skin_detection)
-      x->sb_is_skin = skin_sb_split(cpi, x, low_res, mi_row, mi_col,
-                                    &force_split[0]);
-#endif
-
-    for (i = 1; i <= 2; ++i) {
-      struct macroblock_plane  *p = &x->plane[i];
-      struct macroblockd_plane *pd = &xd->plane[i];
-      const BLOCK_SIZE bs = get_plane_block_size(bsize, pd);
-
-      if (bs == BLOCK_INVALID)
-        uv_sad = UINT_MAX;
-      else
-        uv_sad = cpi->fn_ptr[bs].sdf(p->src.buf, p->src.stride,
-                                     pd->dst.buf, pd->dst.stride);
-
-        // TODO(marpan): Investigate if we should lower this threshold if
-        // superblock is detected as skin.
-        x->color_sensitivity[i - 1] = uv_sad > (y_sad >> 2);
-    }
-
-    d = xd->plane[0].dst.buf;
-    dp = xd->plane[0].dst.stride;
-
-    // If the y_sad is very small, take 64x64 as partition and exit.
-    // Don't check on boosted segment for now, as 64x64 is suppressed there.
-    if (segment_id == CR_SEGMENT_ID_BASE &&
-        y_sad < cpi->vbp_threshold_sad) {
-      const int block_width = num_8x8_blocks_wide_lookup[BLOCK_64X64];
-      const int block_height = num_8x8_blocks_high_lookup[BLOCK_64X64];
-      if (mi_col + block_width / 2 < cm->mi_cols &&
-          mi_row + block_height / 2 < cm->mi_rows) {
-        set_block_size(cpi, x, xd, mi_row, mi_col, BLOCK_64X64);
-        return 0;
-      }
-    }
-  } else {
-    d = VP9_VAR_OFFS;
-    dp = 0;
-#if CONFIG_VP9_HIGHBITDEPTH
-    if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
-      switch (xd->bd) {
-        case 10:
-          d = CONVERT_TO_BYTEPTR(VP9_HIGH_VAR_OFFS_10);
-          break;
-        case 12:
-          d = CONVERT_TO_BYTEPTR(VP9_HIGH_VAR_OFFS_12);
-          break;
-        case 8:
-        default:
-          d = CONVERT_TO_BYTEPTR(VP9_HIGH_VAR_OFFS_8);
-          break;
-      }
-    }
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-  }
-
-  // Fill in the entire tree of 8x8 (or 4x4 under some conditions) variances
-  // for splits.
-  for (i = 0; i < 4; i++) {
-    const int x32_idx = ((i & 1) << 5);
-    const int y32_idx = ((i >> 1) << 5);
-    const int i2 = i << 2;
-    force_split[i + 1] = 0;
-    avg_16x16[i] = 0;
-    for (j = 0; j < 4; j++) {
-      const int x16_idx = x32_idx + ((j & 1) << 4);
-      const int y16_idx = y32_idx + ((j >> 1) << 4);
-      const int split_index = 5 + i2 + j;
-      v16x16 *vst = &vt.split[i].split[j];
-      force_split[split_index] = 0;
-      variance4x4downsample[i2 + j] = 0;
-      if (!is_key_frame) {
-        fill_variance_8x8avg(s, sp, d, dp, x16_idx, y16_idx, vst,
-#if CONFIG_VP9_HIGHBITDEPTH
-                            xd->cur_buf->flags,
-#endif
-                            pixels_wide,
-                            pixels_high,
-                            is_key_frame);
-        fill_variance_tree(&vt.split[i].split[j], BLOCK_16X16);
-        get_variance(&vt.split[i].split[j].part_variances.none);
-        avg_16x16[i] += vt.split[i].split[j].part_variances.none.variance;
-        if (vt.split[i].split[j].part_variances.none.variance >
-            thresholds[2]) {
-          // 16X16 variance is above threshold for split, so force split to 8x8
-          // for this 16x16 block (this also forces splits for upper levels).
-          force_split[split_index] = 1;
-          force_split[i + 1] = 1;
-          force_split[0] = 1;
-        } else if (cpi->oxcf.speed < 8 &&
-                   vt.split[i].split[j].part_variances.none.variance >
-                   thresholds[1] &&
-                   !cyclic_refresh_segment_id_boosted(segment_id)) {
-          // We have some nominal amount of 16x16 variance (based on average),
-          // compute the minmax over the 8x8 sub-blocks, and if above threshold,
-          // force split to 8x8 block for this 16x16 block.
-          int minmax = compute_minmax_8x8(s, sp, d, dp, x16_idx, y16_idx,
-#if CONFIG_VP9_HIGHBITDEPTH
-                                          xd->cur_buf->flags,
-#endif
-                                          pixels_wide, pixels_high);
-          if (minmax > cpi->vbp_threshold_minmax) {
-            force_split[split_index] = 1;
-            force_split[i + 1] = 1;
-            force_split[0] = 1;
-          }
-        }
-      }
-      if (is_key_frame || (low_res &&
-          vt.split[i].split[j].part_variances.none.variance >
-          (thresholds[1] << 1))) {
-        force_split[split_index] = 0;
-        // Go down to 4x4 down-sampling for variance.
-        variance4x4downsample[i2 + j] = 1;
-        for (k = 0; k < 4; k++) {
-          int x8_idx = x16_idx + ((k & 1) << 3);
-          int y8_idx = y16_idx + ((k >> 1) << 3);
-          v8x8 *vst2 = is_key_frame ? &vst->split[k] :
-              &vt2[i2 + j].split[k];
-          fill_variance_4x4avg(s, sp, d, dp, x8_idx, y8_idx, vst2,
-#if CONFIG_VP9_HIGHBITDEPTH
-                               xd->cur_buf->flags,
-#endif
-                               pixels_wide,
-                               pixels_high,
-                               is_key_frame);
-        }
-      }
-    }
-  }
-  // Fill the rest of the variance tree by summing split partition values.
-  avg_32x32 = 0;
-  for (i = 0; i < 4; i++) {
-    const int i2 = i << 2;
-    for (j = 0; j < 4; j++) {
-      if (variance4x4downsample[i2 + j] == 1) {
-        v16x16 *vtemp = (!is_key_frame) ? &vt2[i2 + j] :
-            &vt.split[i].split[j];
-        for (m = 0; m < 4; m++)
-          fill_variance_tree(&vtemp->split[m], BLOCK_8X8);
-        fill_variance_tree(vtemp, BLOCK_16X16);
-        // If variance of this 16x16 block is above the threshold, force block
-        // to split. This also forces a split on the upper levels.
-        get_variance(&vtemp->part_variances.none);
-        if (vtemp->part_variances.none.variance > thresholds[2]) {
-          force_split[5 + i2 + j] = 1;
-          force_split[i + 1] = 1;
-          force_split[0] = 1;
-        }
-      }
-    }
-    fill_variance_tree(&vt.split[i], BLOCK_32X32);
-    // If variance of this 32x32 block is above the threshold, or if its above
-    // (some threshold of) the average variance over the sub-16x16 blocks, then
-    // force this block to split. This also forces a split on the upper
-    // (64x64) level.
-    if (!force_split[i + 1]) {
-      get_variance(&vt.split[i].part_variances.none);
-      if (vt.split[i].part_variances.none.variance > thresholds[1] ||
-          (!is_key_frame &&
-          vt.split[i].part_variances.none.variance > (thresholds[1] >> 1) &&
-          vt.split[i].part_variances.none.variance > (avg_16x16[i] >> 1))) {
-        force_split[i + 1] = 1;
-        force_split[0] = 1;
-      }
-      avg_32x32 += vt.split[i].part_variances.none.variance;
-    }
-  }
-  if (!force_split[0]) {
-    fill_variance_tree(&vt, BLOCK_64X64);
-    get_variance(&vt.part_variances.none);
-    // If variance of this 64x64 block is above (some threshold of) the average
-    // variance over the sub-32x32 blocks, then force this block to split.
-    if (!is_key_frame &&
-        vt.part_variances.none.variance > (5 * avg_32x32) >> 4)
-      force_split[0] = 1;
-  }
-
-  // Now go through the entire structure, splitting every block size until
-  // we get to one that's got a variance lower than our threshold.
-  if ( mi_col + 8 > cm->mi_cols || mi_row + 8 > cm->mi_rows ||
-      !set_vt_partitioning(cpi, x, xd, &vt, BLOCK_64X64, mi_row, mi_col,
-                           thresholds[0], BLOCK_16X16, force_split[0])) {
-    for (i = 0; i < 4; ++i) {
-      const int x32_idx = ((i & 1) << 2);
-      const int y32_idx = ((i >> 1) << 2);
-      const int i2 = i << 2;
-      if (!set_vt_partitioning(cpi, x, xd, &vt.split[i], BLOCK_32X32,
-                               (mi_row + y32_idx), (mi_col + x32_idx),
-                               thresholds[1], BLOCK_16X16,
-                               force_split[i + 1])) {
-        for (j = 0; j < 4; ++j) {
-          const int x16_idx = ((j & 1) << 1);
-          const int y16_idx = ((j >> 1) << 1);
-          // For inter frames: if variance4x4downsample[] == 1 for this 16x16
-          // block, then the variance is based on 4x4 down-sampling, so use vt2
-          // in set_vt_partioning(), otherwise use vt.
-          v16x16 *vtemp = (!is_key_frame &&
-                           variance4x4downsample[i2 + j] == 1) ?
-                           &vt2[i2 + j] : &vt.split[i].split[j];
-          if (!set_vt_partitioning(cpi, x, xd, vtemp, BLOCK_16X16,
-                                   mi_row + y32_idx + y16_idx,
-                                   mi_col + x32_idx + x16_idx,
-                                   thresholds[2],
-                                   cpi->vbp_bsize_min,
-                                   force_split[5 + i2  + j])) {
-            for (k = 0; k < 4; ++k) {
-              const int x8_idx = (k & 1);
-              const int y8_idx = (k >> 1);
-              if (use_4x4_partition) {
-                if (!set_vt_partitioning(cpi, x, xd, &vtemp->split[k],
-                                         BLOCK_8X8,
-                                         mi_row + y32_idx + y16_idx + y8_idx,
-                                         mi_col + x32_idx + x16_idx + x8_idx,
-                                         thresholds[3], BLOCK_8X8, 0)) {
-                  set_block_size(cpi, x, xd,
-                                 (mi_row + y32_idx + y16_idx + y8_idx),
-                                 (mi_col + x32_idx + x16_idx + x8_idx),
-                                 BLOCK_4X4);
-                }
-              } else {
-                set_block_size(cpi, x, xd,
-                               (mi_row + y32_idx + y16_idx + y8_idx),
-                               (mi_col + x32_idx + x16_idx + x8_idx),
-                               BLOCK_8X8);
-              }
-            }
-          }
-        }
-      }
-    }
-  }
-
-  if (cpi->sf.short_circuit_low_temp_var) {
-    const int mv_thr = cm->width > 640 ? 8 : 4;
-    // Check temporal variance for bsize >= 16x16, if LAST_FRAME was selected
-    // and int_pro mv is small. If the temporal variance is small set the
-    // variance_low flag for the block. The variance threshold can be adjusted,
-    // the higher the more aggressive.
-    if (ref_frame_partition == LAST_FRAME &&
-        (cpi->sf.short_circuit_low_temp_var == 1 ||
-         (xd->mi[0]->mv[0].as_mv.col < mv_thr &&
-          xd->mi[0]->mv[0].as_mv.col > -mv_thr &&
-          xd->mi[0]->mv[0].as_mv.row < mv_thr &&
-          xd->mi[0]->mv[0].as_mv.row > -mv_thr))) {
-      if (xd->mi[0]->sb_type == BLOCK_64X64 &&
-          vt.part_variances.none.variance < (thresholds[0] >> 1)) {
-        x->variance_low[0] = 1;
-      } else if (xd->mi[0]->sb_type == BLOCK_64X32) {
-        for (j = 0; j < 2; j++) {
-          if (vt.part_variances.horz[j].variance < (thresholds[0] >> 2))
-            x->variance_low[j + 1] = 1;
-        }
-      } else if (xd->mi[0]->sb_type == BLOCK_32X64) {
-        for (j = 0; j < 2; j++) {
-          if (vt.part_variances.vert[j].variance < (thresholds[0] >> 2))
-            x->variance_low[j + 3] = 1;
-        }
-      } else {
-        for (i = 0; i < 4; i++) {
-          if (!force_split[i + 1]) {
-            // 32x32
-            if (vt.split[i].part_variances.none.variance <
-                (thresholds[1] >> 1))
-              x->variance_low[i + 5] = 1;
-          } else if (cpi->sf.short_circuit_low_temp_var == 2) {
-            int idx[4] = {0, 4, xd->mi_stride << 2, (xd->mi_stride << 2) + 4};
-            const int idx_str = cm->mi_stride * mi_row + mi_col + idx[i];
-            MODE_INFO **this_mi = cm->mi_grid_visible + idx_str;
-            // For 32x16 and 16x32 blocks, the flag is set on each 16x16 block
-            // inside.
-            if ((*this_mi)->sb_type == BLOCK_16X16 ||
-                (*this_mi)->sb_type == BLOCK_32X16 ||
-                (*this_mi)->sb_type == BLOCK_16X32) {
-              for (j = 0; j < 4; j++) {
-                if (vt.split[i].split[j].part_variances.none.variance <
-                    (thresholds[2] >> 8))
-                  x->variance_low[(i << 2) + j + 9] = 1;
-              }
-            }
-          }
-        }
-      }
-    }
-  }
-  return 0;
-}
-
-static void update_state(VP9_COMP *cpi, ThreadData *td,
-                         PICK_MODE_CONTEXT *ctx,
-                         int mi_row, int mi_col, BLOCK_SIZE bsize,
-                         int output_enabled) {
-  int i, x_idx, y;
-  VP9_COMMON *const cm = &cpi->common;
-  RD_COUNTS *const rdc = &td->rd_counts;
-  MACROBLOCK *const x = &td->mb;
-  MACROBLOCKD *const xd = &x->e_mbd;
-  struct macroblock_plane *const p = x->plane;
-  struct macroblockd_plane *const pd = xd->plane;
-  MODE_INFO *mi = &ctx->mic;
-  MODE_INFO *const xdmi = xd->mi[0];
-  MODE_INFO *mi_addr = xd->mi[0];
-  const struct segmentation *const seg = &cm->seg;
-  const int bw = num_8x8_blocks_wide_lookup[mi->sb_type];
-  const int bh = num_8x8_blocks_high_lookup[mi->sb_type];
-  const int x_mis = VPXMIN(bw, cm->mi_cols - mi_col);
-  const int y_mis = VPXMIN(bh, cm->mi_rows - mi_row);
-  MV_REF *const frame_mvs =
-      cm->cur_frame->mvs + mi_row * cm->mi_cols + mi_col;
-  int w, h;
-
-  const int mis = cm->mi_stride;
-  const int mi_width = num_8x8_blocks_wide_lookup[bsize];
-  const int mi_height = num_8x8_blocks_high_lookup[bsize];
-  int max_plane;
-
-  assert(mi->sb_type == bsize);
-
-  *mi_addr = *mi;
-  *x->mbmi_ext = ctx->mbmi_ext;
-
-  // If segmentation in use
-  if (seg->enabled) {
-    // For in frame complexity AQ copy the segment id from the segment map.
-    if (cpi->oxcf.aq_mode == COMPLEXITY_AQ) {
-      const uint8_t *const map = seg->update_map ? cpi->segmentation_map
-                                                 : cm->last_frame_seg_map;
-      mi_addr->segment_id =
-        get_segment_id(cm, map, bsize, mi_row, mi_col);
-    }
-    // Else for cyclic refresh mode update the segment map, set the segment id
-    // and then update the quantizer.
-    if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ) {
-      vp9_cyclic_refresh_update_segment(cpi, xd->mi[0], mi_row,
-                                        mi_col, bsize, ctx->rate, ctx->dist,
-                                        x->skip, p);
-    }
-  }
-
-  max_plane = is_inter_block(xdmi) ? MAX_MB_PLANE : 1;
-  for (i = 0; i < max_plane; ++i) {
-    p[i].coeff = ctx->coeff_pbuf[i][1];
-    p[i].qcoeff = ctx->qcoeff_pbuf[i][1];
-    pd[i].dqcoeff = ctx->dqcoeff_pbuf[i][1];
-    p[i].eobs = ctx->eobs_pbuf[i][1];
-  }
-
-  for (i = max_plane; i < MAX_MB_PLANE; ++i) {
-    p[i].coeff = ctx->coeff_pbuf[i][2];
-    p[i].qcoeff = ctx->qcoeff_pbuf[i][2];
-    pd[i].dqcoeff = ctx->dqcoeff_pbuf[i][2];
-    p[i].eobs = ctx->eobs_pbuf[i][2];
-  }
-
-  // Restore the coding context of the MB to that that was in place
-  // when the mode was picked for it
-  for (y = 0; y < mi_height; y++)
-    for (x_idx = 0; x_idx < mi_width; x_idx++)
-      if ((xd->mb_to_right_edge >> (3 + MI_SIZE_LOG2)) + mi_width > x_idx
-        && (xd->mb_to_bottom_edge >> (3 + MI_SIZE_LOG2)) + mi_height > y) {
-        xd->mi[x_idx + y * mis] = mi_addr;
-      }
-
-  if (cpi->oxcf.aq_mode)
-    vp9_init_plane_quantizers(cpi, x);
-
-  if (is_inter_block(xdmi) && xdmi->sb_type < BLOCK_8X8) {
-    xdmi->mv[0].as_int = mi->bmi[3].as_mv[0].as_int;
-    xdmi->mv[1].as_int = mi->bmi[3].as_mv[1].as_int;
-  }
-
-  x->skip = ctx->skip;
-  memcpy(x->zcoeff_blk[xdmi->tx_size], ctx->zcoeff_blk,
-         sizeof(ctx->zcoeff_blk[0]) * ctx->num_4x4_blk);
-
-  if (!output_enabled)
-    return;
-
-#if CONFIG_INTERNAL_STATS
-  if (frame_is_intra_only(cm)) {
-    static const int kf_mode_index[] = {
-      THR_DC        /*DC_PRED*/,
-      THR_V_PRED    /*V_PRED*/,
-      THR_H_PRED    /*H_PRED*/,
-      THR_D45_PRED  /*D45_PRED*/,
-      THR_D135_PRED /*D135_PRED*/,
-      THR_D117_PRED /*D117_PRED*/,
-      THR_D153_PRED /*D153_PRED*/,
-      THR_D207_PRED /*D207_PRED*/,
-      THR_D63_PRED  /*D63_PRED*/,
-      THR_TM        /*TM_PRED*/,
-    };
-    ++cpi->mode_chosen_counts[kf_mode_index[xdmi->mode]];
-  } else {
-    // Note how often each mode chosen as best
-    ++cpi->mode_chosen_counts[ctx->best_mode_index];
-  }
-#endif
-  if (!frame_is_intra_only(cm)) {
-    if (is_inter_block(xdmi)) {
-      vp9_update_mv_count(td);
-
-      if (cm->interp_filter == SWITCHABLE) {
-        const int ctx = vp9_get_pred_context_switchable_interp(xd);
-        ++td->counts->switchable_interp[ctx][xdmi->interp_filter];
-      }
-    }
-
-    rdc->comp_pred_diff[SINGLE_REFERENCE] += ctx->single_pred_diff;
-    rdc->comp_pred_diff[COMPOUND_REFERENCE] += ctx->comp_pred_diff;
-    rdc->comp_pred_diff[REFERENCE_MODE_SELECT] += ctx->hybrid_pred_diff;
-
-    for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; ++i)
-      rdc->filter_diff[i] += ctx->best_filter_diff[i];
-  }
-
-  for (h = 0; h < y_mis; ++h) {
-    MV_REF *const frame_mv = frame_mvs + h * cm->mi_cols;
-    for (w = 0; w < x_mis; ++w) {
-      MV_REF *const mv = frame_mv + w;
-      mv->ref_frame[0] = mi->ref_frame[0];
-      mv->ref_frame[1] = mi->ref_frame[1];
-      mv->mv[0].as_int = mi->mv[0].as_int;
-      mv->mv[1].as_int = mi->mv[1].as_int;
-    }
-  }
-}
-
-void vp9_setup_src_planes(MACROBLOCK *x, const YV12_BUFFER_CONFIG *src,
-                          int mi_row, int mi_col) {
-  uint8_t *const buffers[3] = {src->y_buffer, src->u_buffer, src->v_buffer };
-  const int strides[3] = {src->y_stride, src->uv_stride, src->uv_stride };
-  int i;
-
-  // Set current frame pointer.
-  x->e_mbd.cur_buf = src;
-
-  for (i = 0; i < MAX_MB_PLANE; i++)
-    setup_pred_plane(&x->plane[i].src, buffers[i], strides[i], mi_row, mi_col,
-                     NULL, x->e_mbd.plane[i].subsampling_x,
-                     x->e_mbd.plane[i].subsampling_y);
-}
-
-static void set_mode_info_seg_skip(MACROBLOCK *x, TX_MODE tx_mode,
-                                   RD_COST *rd_cost, BLOCK_SIZE bsize) {
-  MACROBLOCKD *const xd = &x->e_mbd;
-  MODE_INFO *const mi = xd->mi[0];
-  INTERP_FILTER filter_ref;
-
-  if (xd->above_mi)
-    filter_ref = xd->above_mi->interp_filter;
-  else if (xd->left_mi)
-    filter_ref = xd->left_mi->interp_filter;
-  else
-    filter_ref = EIGHTTAP;
-
-  mi->sb_type = bsize;
-  mi->mode = ZEROMV;
-  mi->tx_size =
-      VPXMIN(max_txsize_lookup[bsize], tx_mode_to_biggest_tx_size[tx_mode]);
-  mi->skip = 1;
-  mi->uv_mode = DC_PRED;
-  mi->ref_frame[0] = LAST_FRAME;
-  mi->ref_frame[1] = NONE;
-  mi->mv[0].as_int = 0;
-  mi->interp_filter = filter_ref;
-
-  xd->mi[0]->bmi[0].as_mv[0].as_int = 0;
-  x->skip = 1;
-
-  vp9_rd_cost_init(rd_cost);
-}
-
-static int set_segment_rdmult(VP9_COMP *const cpi,
-                               MACROBLOCK *const x,
-                               int8_t segment_id) {
-  int segment_qindex;
-  VP9_COMMON *const cm = &cpi->common;
-  vp9_init_plane_quantizers(cpi, x);
-  vpx_clear_system_state();
-  segment_qindex = vp9_get_qindex(&cm->seg, segment_id,
-                                  cm->base_qindex);
-  return vp9_compute_rd_mult(cpi, segment_qindex + cm->y_dc_delta_q);
-}
-
-static void rd_pick_sb_modes(VP9_COMP *cpi,
-                             TileDataEnc *tile_data,
-                             MACROBLOCK *const x,
-                             int mi_row, int mi_col, RD_COST *rd_cost,
-                             BLOCK_SIZE bsize, PICK_MODE_CONTEXT *ctx,
-                             int64_t best_rd) {
-  VP9_COMMON *const cm = &cpi->common;
-  TileInfo *const tile_info = &tile_data->tile_info;
-  MACROBLOCKD *const xd = &x->e_mbd;
-  MODE_INFO *mi;
-  struct macroblock_plane *const p = x->plane;
-  struct macroblockd_plane *const pd = xd->plane;
-  const AQ_MODE aq_mode = cpi->oxcf.aq_mode;
-  int i, orig_rdmult;
-
-  vpx_clear_system_state();
-
-  // Use the lower precision, but faster, 32x32 fdct for mode selection.
-  x->use_lp32x32fdct = 1;
-
-  set_offsets(cpi, tile_info, x, mi_row, mi_col, bsize);
-  mi = xd->mi[0];
-  mi->sb_type = bsize;
-
-  for (i = 0; i < MAX_MB_PLANE; ++i) {
-    p[i].coeff = ctx->coeff_pbuf[i][0];
-    p[i].qcoeff = ctx->qcoeff_pbuf[i][0];
-    pd[i].dqcoeff = ctx->dqcoeff_pbuf[i][0];
-    p[i].eobs = ctx->eobs_pbuf[i][0];
-  }
-  ctx->is_coded = 0;
-  ctx->skippable = 0;
-  ctx->pred_pixel_ready = 0;
-  x->skip_recode = 0;
-
-  // Set to zero to make sure we do not use the previous encoded frame stats
-  mi->skip = 0;
-
-#if CONFIG_VP9_HIGHBITDEPTH
-  if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
-    x->source_variance =
-        vp9_high_get_sby_perpixel_variance(cpi, &x->plane[0].src,
-                                           bsize, xd->bd);
-  } else {
-    x->source_variance =
-      vp9_get_sby_perpixel_variance(cpi, &x->plane[0].src, bsize);
-  }
-#else
-  x->source_variance =
-    vp9_get_sby_perpixel_variance(cpi, &x->plane[0].src, bsize);
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-
-  // Save rdmult before it might be changed, so it can be restored later.
-  orig_rdmult = x->rdmult;
-
-  if (aq_mode == VARIANCE_AQ) {
-    const int energy = bsize <= BLOCK_16X16 ? x->mb_energy
-                                            : vp9_block_energy(cpi, x, bsize);
-    if (cm->frame_type == KEY_FRAME ||
-        cpi->refresh_alt_ref_frame ||
-        (cpi->refresh_golden_frame && !cpi->rc.is_src_frame_alt_ref)) {
-      mi->segment_id = vp9_vaq_segment_id(energy);
-    } else {
-      const uint8_t *const map = cm->seg.update_map ? cpi->segmentation_map
-                                                    : cm->last_frame_seg_map;
-      mi->segment_id = get_segment_id(cm, map, bsize, mi_row, mi_col);
-    }
-    x->rdmult = set_segment_rdmult(cpi, x, mi->segment_id);
-  } else if (aq_mode == EQUATOR360_AQ) {
-    if (cm->frame_type == KEY_FRAME) {
-      mi->segment_id = vp9_360aq_segment_id(mi_row, cm->mi_rows);
-    } else {
-      const uint8_t *const map = cm->seg.update_map ? cpi->segmentation_map
-                                                    : cm->last_frame_seg_map;
-      mi->segment_id = get_segment_id(cm, map, bsize, mi_row, mi_col);
-    }
-    x->rdmult = set_segment_rdmult(cpi, x, mi->segment_id);
-  } else if (aq_mode == COMPLEXITY_AQ) {
-    x->rdmult = set_segment_rdmult(cpi, x, mi->segment_id);
-  } else if (aq_mode == CYCLIC_REFRESH_AQ) {
-    const uint8_t *const map = cm->seg.update_map ? cpi->segmentation_map
-                                                  : cm->last_frame_seg_map;
-    // If segment is boosted, use rdmult for that segment.
-    if (cyclic_refresh_segment_id_boosted(
-            get_segment_id(cm, map, bsize, mi_row, mi_col)))
-      x->rdmult = vp9_cyclic_refresh_get_rdmult(cpi->cyclic_refresh);
-  }
-
-  // Find best coding mode & reconstruct the MB so it is available
-  // as a predictor for MBs that follow in the SB
-  if (frame_is_intra_only(cm)) {
-    vp9_rd_pick_intra_mode_sb(cpi, x, rd_cost, bsize, ctx, best_rd);
-  } else {
-    if (bsize >= BLOCK_8X8) {
-      if (segfeature_active(&cm->seg, mi->segment_id, SEG_LVL_SKIP))
-        vp9_rd_pick_inter_mode_sb_seg_skip(cpi, tile_data, x, rd_cost, bsize,
-                                           ctx, best_rd);
-      else
-        vp9_rd_pick_inter_mode_sb(cpi, tile_data, x, mi_row, mi_col,
-                                  rd_cost, bsize, ctx, best_rd);
-    } else {
-      vp9_rd_pick_inter_mode_sub8x8(cpi, tile_data, x, mi_row, mi_col,
-                                    rd_cost, bsize, ctx, best_rd);
-    }
-  }
-
-
-  // Examine the resulting rate and for AQ mode 2 make a segment choice.
-  if ((rd_cost->rate != INT_MAX) &&
-      (aq_mode == COMPLEXITY_AQ) && (bsize >= BLOCK_16X16) &&
-      (cm->frame_type == KEY_FRAME ||
-       cpi->refresh_alt_ref_frame ||
-       (cpi->refresh_golden_frame && !cpi->rc.is_src_frame_alt_ref))) {
-    vp9_caq_select_segment(cpi, x, bsize, mi_row, mi_col, rd_cost->rate);
-  }
-
-  x->rdmult = orig_rdmult;
-
-  // TODO(jingning) The rate-distortion optimization flow needs to be
-  // refactored to provide proper exit/return handle.
-  if (rd_cost->rate == INT_MAX)
-    rd_cost->rdcost = INT64_MAX;
-
-  ctx->rate = rd_cost->rate;
-  ctx->dist = rd_cost->dist;
-}
-
-static void update_stats(VP9_COMMON *cm, ThreadData *td) {
-  const MACROBLOCK *x = &td->mb;
-  const MACROBLOCKD *const xd = &x->e_mbd;
-  const MODE_INFO *const mi = xd->mi[0];
-  const MB_MODE_INFO_EXT *const mbmi_ext = x->mbmi_ext;
-  const BLOCK_SIZE bsize = mi->sb_type;
-
-  if (!frame_is_intra_only(cm)) {
-    FRAME_COUNTS *const counts = td->counts;
-    const int inter_block = is_inter_block(mi);
-    const int seg_ref_active = segfeature_active(&cm->seg, mi->segment_id,
-                                                 SEG_LVL_REF_FRAME);
-    if (!seg_ref_active) {
-      counts->intra_inter[get_intra_inter_context(xd)][inter_block]++;
-      // If the segment reference feature is enabled we have only a single
-      // reference frame allowed for the segment so exclude it from
-      // the reference frame counts used to work out probabilities.
-      if (inter_block) {
-        const MV_REFERENCE_FRAME ref0 = mi->ref_frame[0];
-        if (cm->reference_mode == REFERENCE_MODE_SELECT)
-          counts->comp_inter[vp9_get_reference_mode_context(cm, xd)]
-                            [has_second_ref(mi)]++;
-
-        if (has_second_ref(mi)) {
-          counts->comp_ref[vp9_get_pred_context_comp_ref_p(cm, xd)]
-                          [ref0 == GOLDEN_FRAME]++;
-        } else {
-          counts->single_ref[vp9_get_pred_context_single_ref_p1(xd)][0]
-                            [ref0 != LAST_FRAME]++;
-          if (ref0 != LAST_FRAME)
-            counts->single_ref[vp9_get_pred_context_single_ref_p2(xd)][1]
-                              [ref0 != GOLDEN_FRAME]++;
-        }
-      }
-    }
-    if (inter_block &&
-        !segfeature_active(&cm->seg, mi->segment_id, SEG_LVL_SKIP)) {
-      const int mode_ctx = mbmi_ext->mode_context[mi->ref_frame[0]];
-      if (bsize >= BLOCK_8X8) {
-        const PREDICTION_MODE mode = mi->mode;
-        ++counts->inter_mode[mode_ctx][INTER_OFFSET(mode)];
-      } else {
-        const int num_4x4_w = num_4x4_blocks_wide_lookup[bsize];
-        const int num_4x4_h = num_4x4_blocks_high_lookup[bsize];
-        int idx, idy;
-        for (idy = 0; idy < 2; idy += num_4x4_h) {
-          for (idx = 0; idx < 2; idx += num_4x4_w) {
-            const int j = idy * 2 + idx;
-            const PREDICTION_MODE b_mode = mi->bmi[j].as_mode;
-            ++counts->inter_mode[mode_ctx][INTER_OFFSET(b_mode)];
-          }
-        }
-      }
-    }
-  }
-}
-
-static void restore_context(MACROBLOCK *const x, int mi_row, int mi_col,
-                            ENTROPY_CONTEXT a[16 * MAX_MB_PLANE],
-                            ENTROPY_CONTEXT l[16 * MAX_MB_PLANE],
-                            PARTITION_CONTEXT sa[8], PARTITION_CONTEXT sl[8],
-                            BLOCK_SIZE bsize) {
-  MACROBLOCKD *const xd = &x->e_mbd;
-  int p;
-  const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[bsize];
-  const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[bsize];
-  int mi_width = num_8x8_blocks_wide_lookup[bsize];
-  int mi_height = num_8x8_blocks_high_lookup[bsize];
-  for (p = 0; p < MAX_MB_PLANE; p++) {
-    memcpy(
-        xd->above_context[p] + ((mi_col * 2) >> xd->plane[p].subsampling_x),
-        a + num_4x4_blocks_wide * p,
-        (sizeof(ENTROPY_CONTEXT) * num_4x4_blocks_wide) >>
-        xd->plane[p].subsampling_x);
-    memcpy(
-        xd->left_context[p]
-            + ((mi_row & MI_MASK) * 2 >> xd->plane[p].subsampling_y),
-        l + num_4x4_blocks_high * p,
-        (sizeof(ENTROPY_CONTEXT) * num_4x4_blocks_high) >>
-        xd->plane[p].subsampling_y);
-  }
-  memcpy(xd->above_seg_context + mi_col, sa,
-         sizeof(*xd->above_seg_context) * mi_width);
-  memcpy(xd->left_seg_context + (mi_row & MI_MASK), sl,
-         sizeof(xd->left_seg_context[0]) * mi_height);
-}
-
-static void save_context(MACROBLOCK *const x, int mi_row, int mi_col,
-                         ENTROPY_CONTEXT a[16 * MAX_MB_PLANE],
-                         ENTROPY_CONTEXT l[16 * MAX_MB_PLANE],
-                         PARTITION_CONTEXT sa[8], PARTITION_CONTEXT sl[8],
-                         BLOCK_SIZE bsize) {
-  const MACROBLOCKD *const xd = &x->e_mbd;
-  int p;
-  const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[bsize];
-  const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[bsize];
-  int mi_width = num_8x8_blocks_wide_lookup[bsize];
-  int mi_height = num_8x8_blocks_high_lookup[bsize];
-
-  // buffer the above/left context information of the block in search.
-  for (p = 0; p < MAX_MB_PLANE; ++p) {
-    memcpy(
-        a + num_4x4_blocks_wide * p,
-        xd->above_context[p] + (mi_col * 2 >> xd->plane[p].subsampling_x),
-        (sizeof(ENTROPY_CONTEXT) * num_4x4_blocks_wide) >>
-        xd->plane[p].subsampling_x);
-    memcpy(
-        l + num_4x4_blocks_high * p,
-        xd->left_context[p]
-            + ((mi_row & MI_MASK) * 2 >> xd->plane[p].subsampling_y),
-        (sizeof(ENTROPY_CONTEXT) * num_4x4_blocks_high) >>
-        xd->plane[p].subsampling_y);
-  }
-  memcpy(sa, xd->above_seg_context + mi_col,
-         sizeof(*xd->above_seg_context) * mi_width);
-  memcpy(sl, xd->left_seg_context + (mi_row & MI_MASK),
-         sizeof(xd->left_seg_context[0]) * mi_height);
-}
-
-static void encode_b(VP9_COMP *cpi, const TileInfo *const tile,
-                     ThreadData *td,
-                     TOKENEXTRA **tp, int mi_row, int mi_col,
-                     int output_enabled, BLOCK_SIZE bsize,
-                     PICK_MODE_CONTEXT *ctx) {
-  MACROBLOCK *const x = &td->mb;
-  set_offsets(cpi, tile, x, mi_row, mi_col, bsize);
-  update_state(cpi, td, ctx, mi_row, mi_col, bsize, output_enabled);
-  encode_superblock(cpi, td, tp, output_enabled, mi_row, mi_col, bsize, ctx);
-
-  if (output_enabled) {
-    update_stats(&cpi->common, td);
-
-    (*tp)->token = EOSB_TOKEN;
-    (*tp)++;
-  }
-}
-
-static void encode_sb(VP9_COMP *cpi, ThreadData *td,
-                      const TileInfo *const tile,
-                      TOKENEXTRA **tp, int mi_row, int mi_col,
-                      int output_enabled, BLOCK_SIZE bsize,
-                      PC_TREE *pc_tree) {
-  VP9_COMMON *const cm = &cpi->common;
-  MACROBLOCK *const x = &td->mb;
-  MACROBLOCKD *const xd = &x->e_mbd;
-
-  const int bsl = b_width_log2_lookup[bsize], hbs = (1 << bsl) / 4;
-  int ctx;
-  PARTITION_TYPE partition;
-  BLOCK_SIZE subsize = bsize;
-
-  if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols)
-    return;
-
-  if (bsize >= BLOCK_8X8) {
-    ctx = partition_plane_context(xd, mi_row, mi_col, bsize);
-    subsize = get_subsize(bsize, pc_tree->partitioning);
-  } else {
-    ctx = 0;
-    subsize = BLOCK_4X4;
-  }
-
-  partition = partition_lookup[bsl][subsize];
-  if (output_enabled && bsize != BLOCK_4X4)
-    td->counts->partition[ctx][partition]++;
-
-  switch (partition) {
-    case PARTITION_NONE:
-      encode_b(cpi, tile, td, tp, mi_row, mi_col, output_enabled, subsize,
-               &pc_tree->none);
-      break;
-    case PARTITION_VERT:
-      encode_b(cpi, tile, td, tp, mi_row, mi_col, output_enabled, subsize,
-               &pc_tree->vertical[0]);
-      if (mi_col + hbs < cm->mi_cols && bsize > BLOCK_8X8) {
-        encode_b(cpi, tile, td, tp, mi_row, mi_col + hbs, output_enabled,
-                 subsize, &pc_tree->vertical[1]);
-      }
-      break;
-    case PARTITION_HORZ:
-      encode_b(cpi, tile, td, tp, mi_row, mi_col, output_enabled, subsize,
-               &pc_tree->horizontal[0]);
-      if (mi_row + hbs < cm->mi_rows && bsize > BLOCK_8X8) {
-        encode_b(cpi, tile, td, tp, mi_row + hbs, mi_col, output_enabled,
-                 subsize, &pc_tree->horizontal[1]);
-      }
-      break;
-    case PARTITION_SPLIT:
-      if (bsize == BLOCK_8X8) {
-        encode_b(cpi, tile, td, tp, mi_row, mi_col, output_enabled, subsize,
-                 pc_tree->leaf_split[0]);
-      } else {
-        encode_sb(cpi, td, tile, tp, mi_row, mi_col, output_enabled, subsize,
-                  pc_tree->split[0]);
-        encode_sb(cpi, td, tile, tp, mi_row, mi_col + hbs, output_enabled,
-                  subsize, pc_tree->split[1]);
-        encode_sb(cpi, td, tile, tp, mi_row + hbs, mi_col, output_enabled,
-                  subsize, pc_tree->split[2]);
-        encode_sb(cpi, td, tile, tp, mi_row + hbs, mi_col + hbs, output_enabled,
-                  subsize, pc_tree->split[3]);
-      }
-      break;
-    default:
-      assert(0 && "Invalid partition type.");
-      break;
-  }
-
-  if (partition != PARTITION_SPLIT || bsize == BLOCK_8X8)
-    update_partition_context(xd, mi_row, mi_col, subsize, bsize);
-}
-
-// Check to see if the given partition size is allowed for a specified number
-// of 8x8 block rows and columns remaining in the image.
-// If not then return the largest allowed partition size
-static BLOCK_SIZE find_partition_size(BLOCK_SIZE bsize,
-                                      int rows_left, int cols_left,
-                                      int *bh, int *bw) {
-  if (rows_left <= 0 || cols_left <= 0) {
-    return VPXMIN(bsize, BLOCK_8X8);
-  } else {
-    for (; bsize > 0; bsize -= 3) {
-      *bh = num_8x8_blocks_high_lookup[bsize];
-      *bw = num_8x8_blocks_wide_lookup[bsize];
-      if ((*bh <= rows_left) && (*bw <= cols_left)) {
-        break;
-      }
-    }
-  }
-  return bsize;
-}
-
-static void set_partial_b64x64_partition(MODE_INFO *mi, int mis,
-    int bh_in, int bw_in, int row8x8_remaining, int col8x8_remaining,
-    BLOCK_SIZE bsize, MODE_INFO **mi_8x8) {
-  int bh = bh_in;
-  int r, c;
-  for (r = 0; r < MI_BLOCK_SIZE; r += bh) {
-    int bw = bw_in;
-    for (c = 0; c < MI_BLOCK_SIZE; c += bw) {
-      const int index = r * mis + c;
-      mi_8x8[index] = mi + index;
-      mi_8x8[index]->sb_type = find_partition_size(bsize,
-          row8x8_remaining - r, col8x8_remaining - c, &bh, &bw);
-    }
-  }
-}
-
-// This function attempts to set all mode info entries in a given SB64
-// to the same block partition size.
-// However, at the bottom and right borders of the image the requested size
-// may not be allowed in which case this code attempts to choose the largest
-// allowable partition.
-static void set_fixed_partitioning(VP9_COMP *cpi, const TileInfo *const tile,
-                                   MODE_INFO **mi_8x8, int mi_row, int mi_col,
-                                   BLOCK_SIZE bsize) {
-  VP9_COMMON *const cm = &cpi->common;
-  const int mis = cm->mi_stride;
-  const int row8x8_remaining = tile->mi_row_end - mi_row;
-  const int col8x8_remaining = tile->mi_col_end - mi_col;
-  int block_row, block_col;
-  MODE_INFO *mi_upper_left = cm->mi + mi_row * mis + mi_col;
-  int bh = num_8x8_blocks_high_lookup[bsize];
-  int bw = num_8x8_blocks_wide_lookup[bsize];
-
-  assert((row8x8_remaining > 0) && (col8x8_remaining > 0));
-
-  // Apply the requested partition size to the SB64 if it is all "in image"
-  if ((col8x8_remaining >= MI_BLOCK_SIZE) &&
-      (row8x8_remaining >= MI_BLOCK_SIZE)) {
-    for (block_row = 0; block_row < MI_BLOCK_SIZE; block_row += bh) {
-      for (block_col = 0; block_col < MI_BLOCK_SIZE; block_col += bw) {
-        int index = block_row * mis + block_col;
-        mi_8x8[index] = mi_upper_left + index;
-        mi_8x8[index]->sb_type = bsize;
-      }
-    }
-  } else {
-    // Else this is a partial SB64.
-    set_partial_b64x64_partition(mi_upper_left, mis, bh, bw, row8x8_remaining,
-        col8x8_remaining, bsize, mi_8x8);
-  }
-}
-
-static const struct {
-  int row;
-  int col;
-} coord_lookup[16] = {
-    // 32x32 index = 0
-    {0, 0}, {0, 2}, {2, 0}, {2, 2},
-    // 32x32 index = 1
-    {0, 4}, {0, 6}, {2, 4}, {2, 6},
-    // 32x32 index = 2
-    {4, 0}, {4, 2}, {6, 0}, {6, 2},
-    // 32x32 index = 3
-    {4, 4}, {4, 6}, {6, 4}, {6, 6},
-};
-
-static void set_source_var_based_partition(VP9_COMP *cpi,
-                                           const TileInfo *const tile,
-                                           MACROBLOCK *const x,
-                                           MODE_INFO **mi_8x8,
-                                           int mi_row, int mi_col) {
-  VP9_COMMON *const cm = &cpi->common;
-  const int mis = cm->mi_stride;
-  const int row8x8_remaining = tile->mi_row_end - mi_row;
-  const int col8x8_remaining = tile->mi_col_end - mi_col;
-  MODE_INFO *mi_upper_left = cm->mi + mi_row * mis + mi_col;
-
-  vp9_setup_src_planes(x, cpi->Source, mi_row, mi_col);
-
-  assert((row8x8_remaining > 0) && (col8x8_remaining > 0));
-
-  // In-image SB64
-  if ((col8x8_remaining >= MI_BLOCK_SIZE) &&
-      (row8x8_remaining >= MI_BLOCK_SIZE)) {
-    int i, j;
-    int index;
-    diff d32[4];
-    const int offset = (mi_row >> 1) * cm->mb_cols + (mi_col >> 1);
-    int is_larger_better = 0;
-    int use32x32 = 0;
-    unsigned int thr = cpi->source_var_thresh;
-
-    memset(d32, 0, 4 * sizeof(diff));
-
-    for (i = 0; i < 4; i++) {
-      diff *d16[4];
-
-      for (j = 0; j < 4; j++) {
-        int b_mi_row = coord_lookup[i * 4 + j].row;
-        int b_mi_col = coord_lookup[i * 4 + j].col;
-        int boffset = b_mi_row / 2 * cm->mb_cols +
-                      b_mi_col / 2;
-
-        d16[j] = cpi->source_diff_var + offset + boffset;
-
-        index = b_mi_row * mis + b_mi_col;
-        mi_8x8[index] = mi_upper_left + index;
-        mi_8x8[index]->sb_type = BLOCK_16X16;
-
-        // TODO(yunqingwang): If d16[j].var is very large, use 8x8 partition
-        // size to further improve quality.
-      }
-
-      is_larger_better = (d16[0]->var < thr) && (d16[1]->var < thr) &&
-          (d16[2]->var < thr) && (d16[3]->var < thr);
-
-      // Use 32x32 partition
-      if (is_larger_better) {
-        use32x32 += 1;
-
-        for (j = 0; j < 4; j++) {
-          d32[i].sse += d16[j]->sse;
-          d32[i].sum += d16[j]->sum;
-        }
-
-        d32[i].var = d32[i].sse - (((int64_t)d32[i].sum * d32[i].sum) >> 10);
-
-        index = coord_lookup[i*4].row * mis + coord_lookup[i*4].col;
-        mi_8x8[index] = mi_upper_left + index;
-        mi_8x8[index]->sb_type = BLOCK_32X32;
-      }
-    }
-
-    if (use32x32 == 4) {
-      thr <<= 1;
-      is_larger_better = (d32[0].var < thr) && (d32[1].var < thr) &&
-          (d32[2].var < thr) && (d32[3].var < thr);
-
-      // Use 64x64 partition
-      if (is_larger_better) {
-        mi_8x8[0] = mi_upper_left;
-        mi_8x8[0]->sb_type = BLOCK_64X64;
-      }
-    }
-  } else {   // partial in-image SB64
-    int bh = num_8x8_blocks_high_lookup[BLOCK_16X16];
-    int bw = num_8x8_blocks_wide_lookup[BLOCK_16X16];
-    set_partial_b64x64_partition(mi_upper_left, mis, bh, bw,
-        row8x8_remaining, col8x8_remaining, BLOCK_16X16, mi_8x8);
-  }
-}
-
-static void update_state_rt(VP9_COMP *cpi, ThreadData *td,
-                            PICK_MODE_CONTEXT *ctx,
-                            int mi_row, int mi_col, int bsize) {
-  VP9_COMMON *const cm = &cpi->common;
-  MACROBLOCK *const x = &td->mb;
-  MACROBLOCKD *const xd = &x->e_mbd;
-  MODE_INFO *const mi = xd->mi[0];
-  struct macroblock_plane *const p = x->plane;
-  const struct segmentation *const seg = &cm->seg;
-  const int bw = num_8x8_blocks_wide_lookup[mi->sb_type];
-  const int bh = num_8x8_blocks_high_lookup[mi->sb_type];
-  const int x_mis = VPXMIN(bw, cm->mi_cols - mi_col);
-  const int y_mis = VPXMIN(bh, cm->mi_rows - mi_row);
-
-  *(xd->mi[0]) = ctx->mic;
-  *(x->mbmi_ext) = ctx->mbmi_ext;
-
-  if (seg->enabled && cpi->oxcf.aq_mode) {
-    // For in frame complexity AQ or variance AQ, copy segment_id from
-    // segmentation_map.
-    if (cpi->oxcf.aq_mode == COMPLEXITY_AQ ||
-        cpi->oxcf.aq_mode == VARIANCE_AQ ||
-        cpi->oxcf.aq_mode == EQUATOR360_AQ) {
-      const uint8_t *const map = seg->update_map ? cpi->segmentation_map
-                                                 : cm->last_frame_seg_map;
-      mi->segment_id = get_segment_id(cm, map, bsize, mi_row, mi_col);
-    } else {
-    // Setting segmentation map for cyclic_refresh.
-      vp9_cyclic_refresh_update_segment(cpi, mi, mi_row, mi_col, bsize,
-                                        ctx->rate, ctx->dist, x->skip, p);
-    }
-    vp9_init_plane_quantizers(cpi, x);
-  }
-
-  if (is_inter_block(mi)) {
-    vp9_update_mv_count(td);
-    if (cm->interp_filter == SWITCHABLE) {
-      const int pred_ctx = vp9_get_pred_context_switchable_interp(xd);
-      ++td->counts->switchable_interp[pred_ctx][mi->interp_filter];
-    }
-
-    if (mi->sb_type < BLOCK_8X8) {
-      mi->mv[0].as_int = mi->bmi[3].as_mv[0].as_int;
-      mi->mv[1].as_int = mi->bmi[3].as_mv[1].as_int;
-    }
-  }
-
-  if (cm->use_prev_frame_mvs ||
-      (cpi->svc.use_base_mv && cpi->svc.number_spatial_layers > 1
-        && cpi->svc.spatial_layer_id != cpi->svc.number_spatial_layers - 1)) {
-    MV_REF *const frame_mvs =
-        cm->cur_frame->mvs + mi_row * cm->mi_cols + mi_col;
-    int w, h;
-
-    for (h = 0; h < y_mis; ++h) {
-      MV_REF *const frame_mv = frame_mvs + h * cm->mi_cols;
-      for (w = 0; w < x_mis; ++w) {
-        MV_REF *const mv = frame_mv + w;
-        mv->ref_frame[0] = mi->ref_frame[0];
-        mv->ref_frame[1] = mi->ref_frame[1];
-        mv->mv[0].as_int = mi->mv[0].as_int;
-        mv->mv[1].as_int = mi->mv[1].as_int;
-      }
-    }
-  }
-
-  x->skip = ctx->skip;
-  x->skip_txfm[0] = mi->segment_id ? 0 : ctx->skip_txfm[0];
-}
-
-static void encode_b_rt(VP9_COMP *cpi, ThreadData *td,
-                        const TileInfo *const tile,
-                        TOKENEXTRA **tp, int mi_row, int mi_col,
-                        int output_enabled, BLOCK_SIZE bsize,
-                        PICK_MODE_CONTEXT *ctx) {
-  MACROBLOCK *const x = &td->mb;
-  set_offsets(cpi, tile, x, mi_row, mi_col, bsize);
-  update_state_rt(cpi, td, ctx, mi_row, mi_col, bsize);
-
-  encode_superblock(cpi, td, tp, output_enabled, mi_row, mi_col, bsize, ctx);
-  update_stats(&cpi->common, td);
-
-  (*tp)->token = EOSB_TOKEN;
-  (*tp)++;
-}
-
-static void encode_sb_rt(VP9_COMP *cpi, ThreadData *td,
-                         const TileInfo *const tile,
-                         TOKENEXTRA **tp, int mi_row, int mi_col,
-                         int output_enabled, BLOCK_SIZE bsize,
-                         PC_TREE *pc_tree) {
-  VP9_COMMON *const cm = &cpi->common;
-  MACROBLOCK *const x = &td->mb;
-  MACROBLOCKD *const xd = &x->e_mbd;
-
-  const int bsl = b_width_log2_lookup[bsize], hbs = (1 << bsl) / 4;
-  int ctx;
-  PARTITION_TYPE partition;
-  BLOCK_SIZE subsize;
-
-  if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols)
-    return;
-
-  if (bsize >= BLOCK_8X8) {
-    const int idx_str = xd->mi_stride * mi_row + mi_col;
-    MODE_INFO ** mi_8x8 = cm->mi_grid_visible + idx_str;
-    ctx = partition_plane_context(xd, mi_row, mi_col, bsize);
-    subsize = mi_8x8[0]->sb_type;
-  } else {
-    ctx = 0;
-    subsize = BLOCK_4X4;
-  }
-
-  partition = partition_lookup[bsl][subsize];
-  if (output_enabled && bsize != BLOCK_4X4)
-    td->counts->partition[ctx][partition]++;
-
-  switch (partition) {
-    case PARTITION_NONE:
-      encode_b_rt(cpi, td, tile, tp, mi_row, mi_col, output_enabled, subsize,
-                  &pc_tree->none);
-      break;
-    case PARTITION_VERT:
-      encode_b_rt(cpi, td, tile, tp, mi_row, mi_col, output_enabled, subsize,
-                  &pc_tree->vertical[0]);
-      if (mi_col + hbs < cm->mi_cols && bsize > BLOCK_8X8) {
-        encode_b_rt(cpi, td, tile, tp, mi_row, mi_col + hbs, output_enabled,
-                    subsize, &pc_tree->vertical[1]);
-      }
-      break;
-    case PARTITION_HORZ:
-      encode_b_rt(cpi, td, tile, tp, mi_row, mi_col, output_enabled, subsize,
-                  &pc_tree->horizontal[0]);
-      if (mi_row + hbs < cm->mi_rows && bsize > BLOCK_8X8) {
-        encode_b_rt(cpi, td, tile, tp, mi_row + hbs, mi_col, output_enabled,
-                    subsize, &pc_tree->horizontal[1]);
-      }
-      break;
-    case PARTITION_SPLIT:
-      subsize = get_subsize(bsize, PARTITION_SPLIT);
-      encode_sb_rt(cpi, td, tile, tp, mi_row, mi_col, output_enabled, subsize,
-                   pc_tree->split[0]);
-      encode_sb_rt(cpi, td, tile, tp, mi_row, mi_col + hbs, output_enabled,
-                   subsize, pc_tree->split[1]);
-      encode_sb_rt(cpi, td, tile, tp, mi_row + hbs, mi_col, output_enabled,
-                   subsize, pc_tree->split[2]);
-      encode_sb_rt(cpi, td, tile, tp, mi_row + hbs, mi_col + hbs,
-                   output_enabled, subsize, pc_tree->split[3]);
-      break;
-    default:
-      assert(0 && "Invalid partition type.");
-      break;
-  }
-
-  if (partition != PARTITION_SPLIT || bsize == BLOCK_8X8)
-    update_partition_context(xd, mi_row, mi_col, subsize, bsize);
-}
-
-static void rd_use_partition(VP9_COMP *cpi,
-                             ThreadData *td,
-                             TileDataEnc *tile_data,
-                             MODE_INFO **mi_8x8, TOKENEXTRA **tp,
-                             int mi_row, int mi_col,
-                             BLOCK_SIZE bsize,
-                             int *rate, int64_t *dist,
-                             int do_recon, PC_TREE *pc_tree) {
-  VP9_COMMON *const cm = &cpi->common;
-  TileInfo *const tile_info = &tile_data->tile_info;
-  MACROBLOCK *const x = &td->mb;
-  MACROBLOCKD *const xd = &x->e_mbd;
-  const int mis = cm->mi_stride;
-  const int bsl = b_width_log2_lookup[bsize];
-  const int mi_step = num_4x4_blocks_wide_lookup[bsize] / 2;
-  const int bss = (1 << bsl) / 4;
-  int i, pl;
-  PARTITION_TYPE partition = PARTITION_NONE;
-  BLOCK_SIZE subsize;
-  ENTROPY_CONTEXT l[16 * MAX_MB_PLANE], a[16 * MAX_MB_PLANE];
-  PARTITION_CONTEXT sl[8], sa[8];
-  RD_COST last_part_rdc, none_rdc, chosen_rdc;
-  BLOCK_SIZE sub_subsize = BLOCK_4X4;
-  int splits_below = 0;
-  BLOCK_SIZE bs_type = mi_8x8[0]->sb_type;
-  int do_partition_search = 1;
-  PICK_MODE_CONTEXT *ctx = &pc_tree->none;
-
-  if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols)
-    return;
-
-  assert(num_4x4_blocks_wide_lookup[bsize] ==
-         num_4x4_blocks_high_lookup[bsize]);
-
-  vp9_rd_cost_reset(&last_part_rdc);
-  vp9_rd_cost_reset(&none_rdc);
-  vp9_rd_cost_reset(&chosen_rdc);
-
-  partition = partition_lookup[bsl][bs_type];
-  subsize = get_subsize(bsize, partition);
-
-  pc_tree->partitioning = partition;
-  save_context(x, mi_row, mi_col, a, l, sa, sl, bsize);
-
-  if (bsize == BLOCK_16X16 && cpi->oxcf.aq_mode) {
-    set_offsets(cpi, tile_info, x, mi_row, mi_col, bsize);
-    x->mb_energy = vp9_block_energy(cpi, x, bsize);
-  }
-
-  if (do_partition_search &&
-      cpi->sf.partition_search_type == SEARCH_PARTITION &&
-      cpi->sf.adjust_partitioning_from_last_frame) {
-    // Check if any of the sub blocks are further split.
-    if (partition == PARTITION_SPLIT && subsize > BLOCK_8X8) {
-      sub_subsize = get_subsize(subsize, PARTITION_SPLIT);
-      splits_below = 1;
-      for (i = 0; i < 4; i++) {
-        int jj = i >> 1, ii = i & 0x01;
-        MODE_INFO *this_mi = mi_8x8[jj * bss * mis + ii * bss];
-        if (this_mi && this_mi->sb_type >= sub_subsize) {
-          splits_below = 0;
-        }
-      }
-    }
-
-    // If partition is not none try none unless each of the 4 splits are split
-    // even further..
-    if (partition != PARTITION_NONE && !splits_below &&
-        mi_row + (mi_step >> 1) < cm->mi_rows &&
-        mi_col + (mi_step >> 1) < cm->mi_cols) {
-      pc_tree->partitioning = PARTITION_NONE;
-      rd_pick_sb_modes(cpi, tile_data, x, mi_row, mi_col, &none_rdc, bsize,
-                       ctx, INT64_MAX);
-
-      pl = partition_plane_context(xd, mi_row, mi_col, bsize);
-
-      if (none_rdc.rate < INT_MAX) {
-        none_rdc.rate += cpi->partition_cost[pl][PARTITION_NONE];
-        none_rdc.rdcost = RDCOST(x->rdmult, x->rddiv, none_rdc.rate,
-                                 none_rdc.dist);
-      }
-
-      restore_context(x, mi_row, mi_col, a, l, sa, sl, bsize);
-      mi_8x8[0]->sb_type = bs_type;
-      pc_tree->partitioning = partition;
-    }
-  }
-
-  switch (partition) {
-    case PARTITION_NONE:
-      rd_pick_sb_modes(cpi, tile_data, x, mi_row, mi_col, &last_part_rdc,
-                       bsize, ctx, INT64_MAX);
-      break;
-    case PARTITION_HORZ:
-      rd_pick_sb_modes(cpi, tile_data, x, mi_row, mi_col, &last_part_rdc,
-                       subsize, &pc_tree->horizontal[0],
-                       INT64_MAX);
-      if (last_part_rdc.rate != INT_MAX &&
-          bsize >= BLOCK_8X8 && mi_row + (mi_step >> 1) < cm->mi_rows) {
-        RD_COST tmp_rdc;
-        PICK_MODE_CONTEXT *ctx = &pc_tree->horizontal[0];
-        vp9_rd_cost_init(&tmp_rdc);
-        update_state(cpi, td, ctx, mi_row, mi_col, subsize, 0);
-        encode_superblock(cpi, td, tp, 0, mi_row, mi_col, subsize, ctx);
-        rd_pick_sb_modes(cpi, tile_data, x,
-                         mi_row + (mi_step >> 1), mi_col, &tmp_rdc,
-                         subsize, &pc_tree->horizontal[1], INT64_MAX);
-        if (tmp_rdc.rate == INT_MAX || tmp_rdc.dist == INT64_MAX) {
-          vp9_rd_cost_reset(&last_part_rdc);
-          break;
-        }
-        last_part_rdc.rate += tmp_rdc.rate;
-        last_part_rdc.dist += tmp_rdc.dist;
-        last_part_rdc.rdcost += tmp_rdc.rdcost;
-      }
-      break;
-    case PARTITION_VERT:
-      rd_pick_sb_modes(cpi, tile_data, x, mi_row, mi_col, &last_part_rdc,
-                       subsize, &pc_tree->vertical[0], INT64_MAX);
-      if (last_part_rdc.rate != INT_MAX &&
-          bsize >= BLOCK_8X8 && mi_col + (mi_step >> 1) < cm->mi_cols) {
-        RD_COST tmp_rdc;
-        PICK_MODE_CONTEXT *ctx = &pc_tree->vertical[0];
-        vp9_rd_cost_init(&tmp_rdc);
-        update_state(cpi, td, ctx, mi_row, mi_col, subsize, 0);
-        encode_superblock(cpi, td, tp, 0, mi_row, mi_col, subsize, ctx);
-        rd_pick_sb_modes(cpi, tile_data, x,
-                         mi_row, mi_col + (mi_step >> 1), &tmp_rdc,
-                         subsize, &pc_tree->vertical[bsize > BLOCK_8X8],
-                         INT64_MAX);
-        if (tmp_rdc.rate == INT_MAX || tmp_rdc.dist == INT64_MAX) {
-          vp9_rd_cost_reset(&last_part_rdc);
-          break;
-        }
-        last_part_rdc.rate += tmp_rdc.rate;
-        last_part_rdc.dist += tmp_rdc.dist;
-        last_part_rdc.rdcost += tmp_rdc.rdcost;
-      }
-      break;
-    case PARTITION_SPLIT:
-      if (bsize == BLOCK_8X8) {
-        rd_pick_sb_modes(cpi, tile_data, x, mi_row, mi_col, &last_part_rdc,
-                         subsize, pc_tree->leaf_split[0], INT64_MAX);
-        break;
-      }
-      last_part_rdc.rate = 0;
-      last_part_rdc.dist = 0;
-      last_part_rdc.rdcost = 0;
-      for (i = 0; i < 4; i++) {
-        int x_idx = (i & 1) * (mi_step >> 1);
-        int y_idx = (i >> 1) * (mi_step >> 1);
-        int jj = i >> 1, ii = i & 0x01;
-        RD_COST tmp_rdc;
-        if ((mi_row + y_idx >= cm->mi_rows) || (mi_col + x_idx >= cm->mi_cols))
-          continue;
-
-        vp9_rd_cost_init(&tmp_rdc);
-        rd_use_partition(cpi, td, tile_data,
-                         mi_8x8 + jj * bss * mis + ii * bss, tp,
-                         mi_row + y_idx, mi_col + x_idx, subsize,
-                         &tmp_rdc.rate, &tmp_rdc.dist,
-                         i != 3, pc_tree->split[i]);
-        if (tmp_rdc.rate == INT_MAX || tmp_rdc.dist == INT64_MAX) {
-          vp9_rd_cost_reset(&last_part_rdc);
-          break;
-        }
-        last_part_rdc.rate += tmp_rdc.rate;
-        last_part_rdc.dist += tmp_rdc.dist;
-      }
-      break;
-    default:
-      assert(0);
-      break;
-  }
-
-  pl = partition_plane_context(xd, mi_row, mi_col, bsize);
-  if (last_part_rdc.rate < INT_MAX) {
-    last_part_rdc.rate += cpi->partition_cost[pl][partition];
-    last_part_rdc.rdcost = RDCOST(x->rdmult, x->rddiv,
-                                  last_part_rdc.rate, last_part_rdc.dist);
-  }
-
-  if (do_partition_search
-      && cpi->sf.adjust_partitioning_from_last_frame
-      && cpi->sf.partition_search_type == SEARCH_PARTITION
-      && partition != PARTITION_SPLIT && bsize > BLOCK_8X8
-      && (mi_row + mi_step < cm->mi_rows ||
-          mi_row + (mi_step >> 1) == cm->mi_rows)
-      && (mi_col + mi_step < cm->mi_cols ||
-          mi_col + (mi_step >> 1) == cm->mi_cols)) {
-    BLOCK_SIZE split_subsize = get_subsize(bsize, PARTITION_SPLIT);
-    chosen_rdc.rate = 0;
-    chosen_rdc.dist = 0;
-    restore_context(x, mi_row, mi_col, a, l, sa, sl, bsize);
-    pc_tree->partitioning = PARTITION_SPLIT;
-
-    // Split partition.
-    for (i = 0; i < 4; i++) {
-      int x_idx = (i & 1) * (mi_step >> 1);
-      int y_idx = (i >> 1) * (mi_step >> 1);
-      RD_COST tmp_rdc;
-      ENTROPY_CONTEXT l[16 * MAX_MB_PLANE], a[16 * MAX_MB_PLANE];
-      PARTITION_CONTEXT sl[8], sa[8];
-
-      if ((mi_row + y_idx >= cm->mi_rows) || (mi_col + x_idx >= cm->mi_cols))
-        continue;
-
-      save_context(x, mi_row, mi_col, a, l, sa, sl, bsize);
-      pc_tree->split[i]->partitioning = PARTITION_NONE;
-      rd_pick_sb_modes(cpi, tile_data, x,
-                       mi_row + y_idx, mi_col + x_idx, &tmp_rdc,
-                       split_subsize, &pc_tree->split[i]->none, INT64_MAX);
-
-      restore_context(x, mi_row, mi_col, a, l, sa, sl, bsize);
-
-      if (tmp_rdc.rate == INT_MAX || tmp_rdc.dist == INT64_MAX) {
-        vp9_rd_cost_reset(&chosen_rdc);
-        break;
-      }
-
-      chosen_rdc.rate += tmp_rdc.rate;
-      chosen_rdc.dist += tmp_rdc.dist;
-
-      if (i != 3)
-        encode_sb(cpi, td, tile_info, tp,  mi_row + y_idx, mi_col + x_idx, 0,
-                  split_subsize, pc_tree->split[i]);
-
-      pl = partition_plane_context(xd, mi_row + y_idx, mi_col + x_idx,
-                                   split_subsize);
-      chosen_rdc.rate += cpi->partition_cost[pl][PARTITION_NONE];
-    }
-    pl = partition_plane_context(xd, mi_row, mi_col, bsize);
-    if (chosen_rdc.rate < INT_MAX) {
-      chosen_rdc.rate += cpi->partition_cost[pl][PARTITION_SPLIT];
-      chosen_rdc.rdcost = RDCOST(x->rdmult, x->rddiv,
-                                 chosen_rdc.rate, chosen_rdc.dist);
-    }
-  }
-
-  // If last_part is better set the partitioning to that.
-  if (last_part_rdc.rdcost < chosen_rdc.rdcost) {
-    mi_8x8[0]->sb_type = bsize;
-    if (bsize >= BLOCK_8X8)
-      pc_tree->partitioning = partition;
-    chosen_rdc = last_part_rdc;
-  }
-  // If none was better set the partitioning to that.
-  if (none_rdc.rdcost < chosen_rdc.rdcost) {
-    if (bsize >= BLOCK_8X8)
-      pc_tree->partitioning = PARTITION_NONE;
-    chosen_rdc = none_rdc;
-  }
-
-  restore_context(x, mi_row, mi_col, a, l, sa, sl, bsize);
-
-  // We must have chosen a partitioning and encoding or we'll fail later on.
-  // No other opportunities for success.
-  if (bsize == BLOCK_64X64)
-    assert(chosen_rdc.rate < INT_MAX && chosen_rdc.dist < INT64_MAX);
-
-  if (do_recon) {
-    int output_enabled = (bsize == BLOCK_64X64);
-    encode_sb(cpi, td, tile_info, tp, mi_row, mi_col, output_enabled, bsize,
-              pc_tree);
-  }
-
-  *rate = chosen_rdc.rate;
-  *dist = chosen_rdc.dist;
-}
-
-static const BLOCK_SIZE min_partition_size[BLOCK_SIZES] = {
-  BLOCK_4X4,   BLOCK_4X4,   BLOCK_4X4,
-  BLOCK_4X4,   BLOCK_4X4,   BLOCK_4X4,
-  BLOCK_8X8,   BLOCK_8X8,   BLOCK_8X8,
-  BLOCK_16X16, BLOCK_16X16, BLOCK_16X16,
-  BLOCK_16X16
-};
-
-static const BLOCK_SIZE max_partition_size[BLOCK_SIZES] = {
-  BLOCK_8X8,   BLOCK_16X16, BLOCK_16X16,
-  BLOCK_16X16, BLOCK_32X32, BLOCK_32X32,
-  BLOCK_32X32, BLOCK_64X64, BLOCK_64X64,
-  BLOCK_64X64, BLOCK_64X64, BLOCK_64X64,
-  BLOCK_64X64
-};
-
-
-// Look at all the mode_info entries for blocks that are part of this
-// partition and find the min and max values for sb_type.
-// At the moment this is designed to work on a 64x64 SB but could be
-// adjusted to use a size parameter.
-//
-// The min and max are assumed to have been initialized prior to calling this
-// function so repeat calls can accumulate a min and max of more than one sb64.
-static void get_sb_partition_size_range(MACROBLOCKD *xd, MODE_INFO **mi_8x8,
-                                        BLOCK_SIZE *min_block_size,
-                                        BLOCK_SIZE *max_block_size,
-                                        int bs_hist[BLOCK_SIZES]) {
-  int sb_width_in_blocks = MI_BLOCK_SIZE;
-  int sb_height_in_blocks  = MI_BLOCK_SIZE;
-  int i, j;
-  int index = 0;
-
-  // Check the sb_type for each block that belongs to this region.
-  for (i = 0; i < sb_height_in_blocks; ++i) {
-    for (j = 0; j < sb_width_in_blocks; ++j) {
-      MODE_INFO *mi = mi_8x8[index+j];
-      BLOCK_SIZE sb_type = mi ? mi->sb_type : 0;
-      bs_hist[sb_type]++;
-      *min_block_size = VPXMIN(*min_block_size, sb_type);
-      *max_block_size = VPXMAX(*max_block_size, sb_type);
-    }
-    index += xd->mi_stride;
-  }
-}
-
-// Next square block size less or equal than current block size.
-static const BLOCK_SIZE next_square_size[BLOCK_SIZES] = {
-  BLOCK_4X4, BLOCK_4X4, BLOCK_4X4,
-  BLOCK_8X8, BLOCK_8X8, BLOCK_8X8,
-  BLOCK_16X16, BLOCK_16X16, BLOCK_16X16,
-  BLOCK_32X32, BLOCK_32X32, BLOCK_32X32,
-  BLOCK_64X64
-};
-
-// Look at neighboring blocks and set a min and max partition size based on
-// what they chose.
-static void rd_auto_partition_range(VP9_COMP *cpi, const TileInfo *const tile,
-                                    MACROBLOCKD *const xd,
-                                    int mi_row, int mi_col,
-                                    BLOCK_SIZE *min_block_size,
-                                    BLOCK_SIZE *max_block_size) {
-  VP9_COMMON *const cm = &cpi->common;
-  MODE_INFO **mi = xd->mi;
-  const int left_in_image = !!xd->left_mi;
-  const int above_in_image = !!xd->above_mi;
-  const int row8x8_remaining = tile->mi_row_end - mi_row;
-  const int col8x8_remaining = tile->mi_col_end - mi_col;
-  int bh, bw;
-  BLOCK_SIZE min_size = BLOCK_4X4;
-  BLOCK_SIZE max_size = BLOCK_64X64;
-  int bs_hist[BLOCK_SIZES] = {0};
-
-  // Trap case where we do not have a prediction.
-  if (left_in_image || above_in_image || cm->frame_type != KEY_FRAME) {
-    // Default "min to max" and "max to min"
-    min_size = BLOCK_64X64;
-    max_size = BLOCK_4X4;
-
-    // NOTE: each call to get_sb_partition_size_range() uses the previous
-    // passed in values for min and max as a starting point.
-    // Find the min and max partition used in previous frame at this location
-    if (cm->frame_type != KEY_FRAME) {
-      MODE_INFO **prev_mi =
-          &cm->prev_mi_grid_visible[mi_row * xd->mi_stride + mi_col];
-      get_sb_partition_size_range(xd, prev_mi, &min_size, &max_size, bs_hist);
-    }
-    // Find the min and max partition sizes used in the left SB64
-    if (left_in_image) {
-      MODE_INFO **left_sb64_mi = &mi[-MI_BLOCK_SIZE];
-      get_sb_partition_size_range(xd, left_sb64_mi, &min_size, &max_size,
-                                  bs_hist);
-    }
-    // Find the min and max partition sizes used in the above SB64.
-    if (above_in_image) {
-      MODE_INFO **above_sb64_mi = &mi[-xd->mi_stride * MI_BLOCK_SIZE];
-      get_sb_partition_size_range(xd, above_sb64_mi, &min_size, &max_size,
-                                  bs_hist);
-    }
-
-    // Adjust observed min and max for "relaxed" auto partition case.
-    if (cpi->sf.auto_min_max_partition_size == RELAXED_NEIGHBORING_MIN_MAX) {
-      min_size = min_partition_size[min_size];
-      max_size = max_partition_size[max_size];
-    }
-  }
-
-  // Check border cases where max and min from neighbors may not be legal.
-  max_size = find_partition_size(max_size,
-                                 row8x8_remaining, col8x8_remaining,
-                                 &bh, &bw);
-  // Test for blocks at the edge of the active image.
-  // This may be the actual edge of the image or where there are formatting
-  // bars.
-  if (vp9_active_edge_sb(cpi, mi_row, mi_col)) {
-    min_size = BLOCK_4X4;
-  } else {
-    min_size =
-        VPXMIN(cpi->sf.rd_auto_partition_min_limit, VPXMIN(min_size, max_size));
-  }
-
-  // When use_square_partition_only is true, make sure at least one square
-  // partition is allowed by selecting the next smaller square size as
-  // *min_block_size.
-  if (cpi->sf.use_square_partition_only &&
-      next_square_size[max_size] < min_size) {
-     min_size = next_square_size[max_size];
-  }
-
-  *min_block_size = min_size;
-  *max_block_size = max_size;
-}
-
-// TODO(jingning) refactor functions setting partition search range
-static void set_partition_range(VP9_COMMON *cm, MACROBLOCKD *xd,
-                                int mi_row, int mi_col, BLOCK_SIZE bsize,
-                                BLOCK_SIZE *min_bs, BLOCK_SIZE *max_bs) {
-  int mi_width  = num_8x8_blocks_wide_lookup[bsize];
-  int mi_height = num_8x8_blocks_high_lookup[bsize];
-  int idx, idy;
-
-  MODE_INFO *mi;
-  const int idx_str = cm->mi_stride * mi_row + mi_col;
-  MODE_INFO **prev_mi = &cm->prev_mi_grid_visible[idx_str];
-  BLOCK_SIZE bs, min_size, max_size;
-
-  min_size = BLOCK_64X64;
-  max_size = BLOCK_4X4;
-
-  if (prev_mi) {
-    for (idy = 0; idy < mi_height; ++idy) {
-      for (idx = 0; idx < mi_width; ++idx) {
-        mi = prev_mi[idy * cm->mi_stride + idx];
-        bs = mi ? mi->sb_type : bsize;
-        min_size = VPXMIN(min_size, bs);
-        max_size = VPXMAX(max_size, bs);
-      }
-    }
-  }
-
-  if (xd->left_mi) {
-    for (idy = 0; idy < mi_height; ++idy) {
-      mi = xd->mi[idy * cm->mi_stride - 1];
-      bs = mi ? mi->sb_type : bsize;
-      min_size = VPXMIN(min_size, bs);
-      max_size = VPXMAX(max_size, bs);
-    }
-  }
-
-  if (xd->above_mi) {
-    for (idx = 0; idx < mi_width; ++idx) {
-      mi = xd->mi[idx - cm->mi_stride];
-      bs = mi ? mi->sb_type : bsize;
-      min_size = VPXMIN(min_size, bs);
-      max_size = VPXMAX(max_size, bs);
-    }
-  }
-
-  if (min_size == max_size) {
-    min_size = min_partition_size[min_size];
-    max_size = max_partition_size[max_size];
-  }
-
-  *min_bs = min_size;
-  *max_bs = max_size;
-}
-
-static INLINE void store_pred_mv(MACROBLOCK *x, PICK_MODE_CONTEXT *ctx) {
-  memcpy(ctx->pred_mv, x->pred_mv, sizeof(x->pred_mv));
-}
-
-static INLINE void load_pred_mv(MACROBLOCK *x, PICK_MODE_CONTEXT *ctx) {
-  memcpy(x->pred_mv, ctx->pred_mv, sizeof(x->pred_mv));
-}
-
-#if CONFIG_FP_MB_STATS
-const int num_16x16_blocks_wide_lookup[BLOCK_SIZES] =
-  {1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 4, 4};
-const int num_16x16_blocks_high_lookup[BLOCK_SIZES] =
-  {1, 1, 1, 1, 1, 1, 1, 2, 1, 2, 4, 2, 4};
-const int qindex_skip_threshold_lookup[BLOCK_SIZES] =
-  {0, 10, 10, 30, 40, 40, 60, 80, 80, 90, 100, 100, 120};
-const int qindex_split_threshold_lookup[BLOCK_SIZES] =
-  {0, 3, 3, 7, 15, 15, 30, 40, 40, 60, 80, 80, 120};
-const int complexity_16x16_blocks_threshold[BLOCK_SIZES] =
-  {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4, 4, 6};
-
-typedef enum {
-  MV_ZERO = 0,
-  MV_LEFT = 1,
-  MV_UP = 2,
-  MV_RIGHT = 3,
-  MV_DOWN = 4,
-  MV_INVALID
-} MOTION_DIRECTION;
-
-static INLINE MOTION_DIRECTION get_motion_direction_fp(uint8_t fp_byte) {
-  if (fp_byte & FPMB_MOTION_ZERO_MASK) {
-    return MV_ZERO;
-  } else if (fp_byte & FPMB_MOTION_LEFT_MASK) {
-    return MV_LEFT;
-  } else if (fp_byte & FPMB_MOTION_RIGHT_MASK) {
-    return MV_RIGHT;
-  } else if (fp_byte & FPMB_MOTION_UP_MASK) {
-    return MV_UP;
-  } else {
-    return MV_DOWN;
-  }
-}
-
-static INLINE int get_motion_inconsistency(MOTION_DIRECTION this_mv,
-                                           MOTION_DIRECTION that_mv) {
-  if (this_mv == that_mv) {
-    return 0;
-  } else {
-    return abs(this_mv - that_mv) == 2 ? 2 : 1;
-  }
-}
-#endif
-
-// TODO(jingning,jimbankoski,rbultje): properly skip partition types that are
-// unlikely to be selected depending on previous rate-distortion optimization
-// results, for encoding speed-up.
-static void rd_pick_partition(VP9_COMP *cpi, ThreadData *td,
-                              TileDataEnc *tile_data,
-                              TOKENEXTRA **tp, int mi_row, int mi_col,
-                              BLOCK_SIZE bsize, RD_COST *rd_cost,
-                              int64_t best_rd, PC_TREE *pc_tree) {
-  VP9_COMMON *const cm = &cpi->common;
-  TileInfo *const tile_info = &tile_data->tile_info;
-  MACROBLOCK *const x = &td->mb;
-  MACROBLOCKD *const xd = &x->e_mbd;
-  const int mi_step = num_8x8_blocks_wide_lookup[bsize] / 2;
-  ENTROPY_CONTEXT l[16 * MAX_MB_PLANE], a[16 * MAX_MB_PLANE];
-  PARTITION_CONTEXT sl[8], sa[8];
-  TOKENEXTRA *tp_orig = *tp;
-  PICK_MODE_CONTEXT *ctx = &pc_tree->none;
-  int i;
-  const int pl = partition_plane_context(xd, mi_row, mi_col, bsize);
-  BLOCK_SIZE subsize;
-  RD_COST this_rdc, sum_rdc, best_rdc;
-  int do_split = bsize >= BLOCK_8X8;
-  int do_rect = 1;
-
-  // Override skipping rectangular partition operations for edge blocks
-  const int force_horz_split = (mi_row + mi_step >= cm->mi_rows);
-  const int force_vert_split = (mi_col + mi_step >= cm->mi_cols);
-  const int xss = x->e_mbd.plane[1].subsampling_x;
-  const int yss = x->e_mbd.plane[1].subsampling_y;
-
-  BLOCK_SIZE min_size = x->min_partition_size;
-  BLOCK_SIZE max_size = x->max_partition_size;
-
-#if CONFIG_FP_MB_STATS
-  unsigned int src_diff_var = UINT_MAX;
-  int none_complexity = 0;
-#endif
-
-  int partition_none_allowed = !force_horz_split && !force_vert_split;
-  int partition_horz_allowed = !force_vert_split && yss <= xss &&
-                               bsize >= BLOCK_8X8;
-  int partition_vert_allowed = !force_horz_split && xss <= yss &&
-                               bsize >= BLOCK_8X8;
-
-  int64_t dist_breakout_thr = cpi->sf.partition_search_breakout_dist_thr;
-  int rate_breakout_thr = cpi->sf.partition_search_breakout_rate_thr;
-
-  (void)*tp_orig;
-
-  assert(num_8x8_blocks_wide_lookup[bsize] ==
-             num_8x8_blocks_high_lookup[bsize]);
-
-  // Adjust dist breakout threshold according to the partition size.
-  dist_breakout_thr >>= 8 - (b_width_log2_lookup[bsize] +
-      b_height_log2_lookup[bsize]);
-  rate_breakout_thr *= num_pels_log2_lookup[bsize];
-
-  vp9_rd_cost_init(&this_rdc);
-  vp9_rd_cost_init(&sum_rdc);
-  vp9_rd_cost_reset(&best_rdc);
-  best_rdc.rdcost = best_rd;
-
-  set_offsets(cpi, tile_info, x, mi_row, mi_col, bsize);
-
-  if (bsize == BLOCK_16X16 && cpi->oxcf.aq_mode)
-    x->mb_energy = vp9_block_energy(cpi, x, bsize);
-
-  if (cpi->sf.cb_partition_search && bsize == BLOCK_16X16) {
-    int cb_partition_search_ctrl = ((pc_tree->index == 0 || pc_tree->index == 3)
-        + get_chessboard_index(cm->current_video_frame)) & 0x1;
-
-    if (cb_partition_search_ctrl && bsize > min_size && bsize < max_size)
-      set_partition_range(cm, xd, mi_row, mi_col, bsize, &min_size, &max_size);
-  }
-
-  // Determine partition types in search according to the speed features.
-  // The threshold set here has to be of square block size.
-  if (cpi->sf.auto_min_max_partition_size) {
-    partition_none_allowed &= (bsize <= max_size && bsize >= min_size);
-    partition_horz_allowed &= ((bsize <= max_size && bsize > min_size) ||
-                                force_horz_split);
-    partition_vert_allowed &= ((bsize <= max_size && bsize > min_size) ||
-                                force_vert_split);
-    do_split &= bsize > min_size;
-  }
-
-  if (cpi->sf.use_square_partition_only &&
-      bsize > cpi->sf.use_square_only_threshold) {
-    if (cpi->use_svc) {
-      if (!vp9_active_h_edge(cpi, mi_row, mi_step) || x->e_mbd.lossless)
-        partition_horz_allowed &= force_horz_split;
-      if (!vp9_active_v_edge(cpi, mi_row, mi_step) || x->e_mbd.lossless)
-        partition_vert_allowed &= force_vert_split;
-    } else {
-      partition_horz_allowed &= force_horz_split;
-      partition_vert_allowed &= force_vert_split;
-    }
-  }
-
-  save_context(x, mi_row, mi_col, a, l, sa, sl, bsize);
-
-#if CONFIG_FP_MB_STATS
-  if (cpi->use_fp_mb_stats) {
-    set_offsets(cpi, tile_info, x, mi_row, mi_col, bsize);
-    src_diff_var = get_sby_perpixel_diff_variance(cpi, &x->plane[0].src,
-                                                  mi_row, mi_col, bsize);
-  }
-#endif
-
-#if CONFIG_FP_MB_STATS
-  // Decide whether we shall split directly and skip searching NONE by using
-  // the first pass block statistics
-  if (cpi->use_fp_mb_stats && bsize >= BLOCK_32X32 && do_split &&
-      partition_none_allowed && src_diff_var > 4 &&
-      cm->base_qindex < qindex_split_threshold_lookup[bsize]) {
-    int mb_row = mi_row >> 1;
-    int mb_col = mi_col >> 1;
-    int mb_row_end =
-        VPXMIN(mb_row + num_16x16_blocks_high_lookup[bsize], cm->mb_rows);
-    int mb_col_end =
-        VPXMIN(mb_col + num_16x16_blocks_wide_lookup[bsize], cm->mb_cols);
-    int r, c;
-
-    // compute a complexity measure, basically measure inconsistency of motion
-    // vectors obtained from the first pass in the current block
-    for (r = mb_row; r < mb_row_end ; r++) {
-      for (c = mb_col; c < mb_col_end; c++) {
-        const int mb_index = r * cm->mb_cols + c;
-
-        MOTION_DIRECTION this_mv;
-        MOTION_DIRECTION right_mv;
-        MOTION_DIRECTION bottom_mv;
-
-        this_mv =
-            get_motion_direction_fp(cpi->twopass.this_frame_mb_stats[mb_index]);
-
-        // to its right
-        if (c != mb_col_end - 1) {
-          right_mv = get_motion_direction_fp(
-              cpi->twopass.this_frame_mb_stats[mb_index + 1]);
-          none_complexity += get_motion_inconsistency(this_mv, right_mv);
-        }
-
-        // to its bottom
-        if (r != mb_row_end - 1) {
-          bottom_mv = get_motion_direction_fp(
-              cpi->twopass.this_frame_mb_stats[mb_index + cm->mb_cols]);
-          none_complexity += get_motion_inconsistency(this_mv, bottom_mv);
-        }
-
-        // do not count its left and top neighbors to avoid double counting
-      }
-    }
-
-    if (none_complexity > complexity_16x16_blocks_threshold[bsize]) {
-      partition_none_allowed = 0;
-    }
-  }
-#endif
-
-  // PARTITION_NONE
-  if (partition_none_allowed) {
-    rd_pick_sb_modes(cpi, tile_data, x, mi_row, mi_col,
-                     &this_rdc, bsize, ctx, best_rdc.rdcost);
-    if (this_rdc.rate != INT_MAX) {
-      if (bsize >= BLOCK_8X8) {
-        this_rdc.rate += cpi->partition_cost[pl][PARTITION_NONE];
-        this_rdc.rdcost = RDCOST(x->rdmult, x->rddiv,
-                                 this_rdc.rate, this_rdc.dist);
-      }
-
-      if (this_rdc.rdcost < best_rdc.rdcost) {
-        best_rdc = this_rdc;
-        if (bsize >= BLOCK_8X8)
-          pc_tree->partitioning = PARTITION_NONE;
-
-        // If all y, u, v transform blocks in this partition are skippable, and
-        // the dist & rate are within the thresholds, the partition search is
-        // terminated for current branch of the partition search tree.
-        if (!x->e_mbd.lossless && ctx->skippable  &&
-            ((best_rdc.dist < (dist_breakout_thr >> 2)) ||
-             (best_rdc.dist < dist_breakout_thr &&
-              best_rdc.rate < rate_breakout_thr))) {
-          do_split = 0;
-          do_rect = 0;
-        }
-
-#if CONFIG_FP_MB_STATS
-        // Check if every 16x16 first pass block statistics has zero
-        // motion and the corresponding first pass residue is small enough.
-        // If that is the case, check the difference variance between the
-        // current frame and the last frame. If the variance is small enough,
-        // stop further splitting in RD optimization
-        if (cpi->use_fp_mb_stats && do_split != 0 &&
-            cm->base_qindex > qindex_skip_threshold_lookup[bsize]) {
-          int mb_row = mi_row >> 1;
-          int mb_col = mi_col >> 1;
-          int mb_row_end =
-              VPXMIN(mb_row + num_16x16_blocks_high_lookup[bsize], cm->mb_rows);
-          int mb_col_end =
-              VPXMIN(mb_col + num_16x16_blocks_wide_lookup[bsize], cm->mb_cols);
-          int r, c;
-
-          int skip = 1;
-          for (r = mb_row; r < mb_row_end; r++) {
-            for (c = mb_col; c < mb_col_end; c++) {
-              const int mb_index = r * cm->mb_cols + c;
-              if (!(cpi->twopass.this_frame_mb_stats[mb_index] &
-                    FPMB_MOTION_ZERO_MASK) ||
-                  !(cpi->twopass.this_frame_mb_stats[mb_index] &
-                    FPMB_ERROR_SMALL_MASK)) {
-                skip = 0;
-                break;
-              }
-            }
-            if (skip == 0) {
-              break;
-            }
-          }
-          if (skip) {
-            if (src_diff_var == UINT_MAX) {
-              set_offsets(cpi, tile_info, x, mi_row, mi_col, bsize);
-              src_diff_var = get_sby_perpixel_diff_variance(
-                  cpi, &x->plane[0].src, mi_row, mi_col, bsize);
-            }
-            if (src_diff_var < 8) {
-              do_split = 0;
-              do_rect = 0;
-            }
-          }
-        }
-#endif
-      }
-    }
-    restore_context(x, mi_row, mi_col, a, l, sa, sl, bsize);
-  }
-
-  // store estimated motion vector
-  if (cpi->sf.adaptive_motion_search)
-    store_pred_mv(x, ctx);
-
-  // PARTITION_SPLIT
-  // TODO(jingning): use the motion vectors given by the above search as
-  // the starting point of motion search in the following partition type check.
-  if (do_split) {
-    subsize = get_subsize(bsize, PARTITION_SPLIT);
-    if (bsize == BLOCK_8X8) {
-      i = 4;
-      if (cpi->sf.adaptive_pred_interp_filter && partition_none_allowed)
-        pc_tree->leaf_split[0]->pred_interp_filter =
-            ctx->mic.interp_filter;
-      rd_pick_sb_modes(cpi, tile_data, x, mi_row, mi_col, &sum_rdc, subsize,
-                       pc_tree->leaf_split[0], best_rdc.rdcost);
-      if (sum_rdc.rate == INT_MAX)
-        sum_rdc.rdcost = INT64_MAX;
-    } else {
-      for (i = 0; i < 4 && sum_rdc.rdcost < best_rdc.rdcost; ++i) {
-      const int x_idx = (i & 1) * mi_step;
-      const int y_idx = (i >> 1) * mi_step;
-
-        if (mi_row + y_idx >= cm->mi_rows || mi_col + x_idx >= cm->mi_cols)
-          continue;
-
-        if (cpi->sf.adaptive_motion_search)
-          load_pred_mv(x, ctx);
-
-        pc_tree->split[i]->index = i;
-        rd_pick_partition(cpi, td, tile_data, tp,
-                          mi_row + y_idx, mi_col + x_idx,
-                          subsize, &this_rdc,
-                          best_rdc.rdcost - sum_rdc.rdcost, pc_tree->split[i]);
-
-        if (this_rdc.rate == INT_MAX) {
-          sum_rdc.rdcost = INT64_MAX;
-          break;
-        } else {
-          sum_rdc.rate += this_rdc.rate;
-          sum_rdc.dist += this_rdc.dist;
-          sum_rdc.rdcost += this_rdc.rdcost;
-        }
-      }
-    }
-
-    if (sum_rdc.rdcost < best_rdc.rdcost && i == 4) {
-      sum_rdc.rate += cpi->partition_cost[pl][PARTITION_SPLIT];
-      sum_rdc.rdcost = RDCOST(x->rdmult, x->rddiv,
-                              sum_rdc.rate, sum_rdc.dist);
-
-      if (sum_rdc.rdcost < best_rdc.rdcost) {
-        best_rdc = sum_rdc;
-        pc_tree->partitioning = PARTITION_SPLIT;
-
-        // Rate and distortion based partition search termination clause.
-        if (!x->e_mbd.lossless &&
-            ((best_rdc.dist < (dist_breakout_thr >> 2)) ||
-             (best_rdc.dist < dist_breakout_thr &&
-              best_rdc.rate < rate_breakout_thr))) {
-          do_rect = 0;
-        }
-      }
-    } else {
-      // skip rectangular partition test when larger block size
-      // gives better rd cost
-      if ((cpi->sf.less_rectangular_check) &&
-          ((bsize > cpi->sf.use_square_only_threshold) ||
-           (best_rdc.dist < dist_breakout_thr)))
-        do_rect &= !partition_none_allowed;
-    }
-    restore_context(x, mi_row, mi_col, a, l, sa, sl, bsize);
-  }
-
-  // PARTITION_HORZ
-  if (partition_horz_allowed &&
-      (do_rect || vp9_active_h_edge(cpi, mi_row, mi_step))) {
-    subsize = get_subsize(bsize, PARTITION_HORZ);
-    if (cpi->sf.adaptive_motion_search)
-      load_pred_mv(x, ctx);
-    if (cpi->sf.adaptive_pred_interp_filter && bsize == BLOCK_8X8 &&
-        partition_none_allowed)
-      pc_tree->horizontal[0].pred_interp_filter =
-          ctx->mic.interp_filter;
-    rd_pick_sb_modes(cpi, tile_data, x, mi_row, mi_col, &sum_rdc, subsize,
-                     &pc_tree->horizontal[0], best_rdc.rdcost);
-
-    if (sum_rdc.rdcost < best_rdc.rdcost && mi_row + mi_step < cm->mi_rows &&
-        bsize > BLOCK_8X8) {
-      PICK_MODE_CONTEXT *ctx = &pc_tree->horizontal[0];
-      update_state(cpi, td, ctx, mi_row, mi_col, subsize, 0);
-      encode_superblock(cpi, td, tp, 0, mi_row, mi_col, subsize, ctx);
-
-      if (cpi->sf.adaptive_motion_search)
-        load_pred_mv(x, ctx);
-      if (cpi->sf.adaptive_pred_interp_filter && bsize == BLOCK_8X8 &&
-          partition_none_allowed)
-        pc_tree->horizontal[1].pred_interp_filter =
-            ctx->mic.interp_filter;
-      rd_pick_sb_modes(cpi, tile_data, x, mi_row + mi_step, mi_col,
-                       &this_rdc, subsize, &pc_tree->horizontal[1],
-                       best_rdc.rdcost - sum_rdc.rdcost);
-      if (this_rdc.rate == INT_MAX) {
-        sum_rdc.rdcost = INT64_MAX;
-      } else {
-        sum_rdc.rate += this_rdc.rate;
-        sum_rdc.dist += this_rdc.dist;
-        sum_rdc.rdcost += this_rdc.rdcost;
-      }
-    }
-
-    if (sum_rdc.rdcost < best_rdc.rdcost) {
-      sum_rdc.rate += cpi->partition_cost[pl][PARTITION_HORZ];
-      sum_rdc.rdcost = RDCOST(x->rdmult, x->rddiv, sum_rdc.rate, sum_rdc.dist);
-      if (sum_rdc.rdcost < best_rdc.rdcost) {
-        best_rdc = sum_rdc;
-        pc_tree->partitioning = PARTITION_HORZ;
-
-        if ((cpi->sf.less_rectangular_check) &&
-            (bsize > cpi->sf.use_square_only_threshold))
-          do_rect = 0;
-      }
-    }
-    restore_context(x, mi_row, mi_col, a, l, sa, sl, bsize);
-  }
-  // PARTITION_VERT
-  if (partition_vert_allowed &&
-      (do_rect || vp9_active_v_edge(cpi, mi_col, mi_step))) {
-    subsize = get_subsize(bsize, PARTITION_VERT);
-
-    if (cpi->sf.adaptive_motion_search)
-      load_pred_mv(x, ctx);
-    if (cpi->sf.adaptive_pred_interp_filter && bsize == BLOCK_8X8 &&
-        partition_none_allowed)
-      pc_tree->vertical[0].pred_interp_filter =
-          ctx->mic.interp_filter;
-    rd_pick_sb_modes(cpi, tile_data, x, mi_row, mi_col, &sum_rdc, subsize,
-                     &pc_tree->vertical[0], best_rdc.rdcost);
-    if (sum_rdc.rdcost < best_rdc.rdcost && mi_col + mi_step < cm->mi_cols &&
-        bsize > BLOCK_8X8) {
-      update_state(cpi, td, &pc_tree->vertical[0], mi_row, mi_col, subsize, 0);
-      encode_superblock(cpi, td, tp, 0, mi_row, mi_col, subsize,
-                        &pc_tree->vertical[0]);
-
-      if (cpi->sf.adaptive_motion_search)
-        load_pred_mv(x, ctx);
-      if (cpi->sf.adaptive_pred_interp_filter && bsize == BLOCK_8X8 &&
-          partition_none_allowed)
-        pc_tree->vertical[1].pred_interp_filter =
-            ctx->mic.interp_filter;
-      rd_pick_sb_modes(cpi, tile_data, x, mi_row, mi_col + mi_step,
-                       &this_rdc, subsize,
-                       &pc_tree->vertical[1], best_rdc.rdcost - sum_rdc.rdcost);
-      if (this_rdc.rate == INT_MAX) {
-        sum_rdc.rdcost = INT64_MAX;
-      } else {
-        sum_rdc.rate += this_rdc.rate;
-        sum_rdc.dist += this_rdc.dist;
-        sum_rdc.rdcost += this_rdc.rdcost;
-      }
-    }
-
-    if (sum_rdc.rdcost < best_rdc.rdcost) {
-      sum_rdc.rate += cpi->partition_cost[pl][PARTITION_VERT];
-      sum_rdc.rdcost = RDCOST(x->rdmult, x->rddiv,
-                              sum_rdc.rate, sum_rdc.dist);
-      if (sum_rdc.rdcost < best_rdc.rdcost) {
-        best_rdc = sum_rdc;
-        pc_tree->partitioning = PARTITION_VERT;
-      }
-    }
-    restore_context(x, mi_row, mi_col, a, l, sa, sl, bsize);
-  }
-
-  // TODO(jbb): This code added so that we avoid static analysis
-  // warning related to the fact that best_rd isn't used after this
-  // point.  This code should be refactored so that the duplicate
-  // checks occur in some sub function and thus are used...
-  (void) best_rd;
-  *rd_cost = best_rdc;
-
-  if (best_rdc.rate < INT_MAX && best_rdc.dist < INT64_MAX &&
-      pc_tree->index != 3) {
-    int output_enabled = (bsize == BLOCK_64X64);
-    encode_sb(cpi, td, tile_info, tp, mi_row, mi_col, output_enabled,
-              bsize, pc_tree);
-  }
-
-  if (bsize == BLOCK_64X64) {
-    assert(tp_orig < *tp);
-    assert(best_rdc.rate < INT_MAX);
-    assert(best_rdc.dist < INT64_MAX);
-  } else {
-    assert(tp_orig == *tp);
-  }
-}
-
-static void encode_rd_sb_row(VP9_COMP *cpi,
-                             ThreadData *td,
-                             TileDataEnc *tile_data,
-                             int mi_row,
-                             TOKENEXTRA **tp) {
-  VP9_COMMON *const cm = &cpi->common;
-  TileInfo *const tile_info = &tile_data->tile_info;
-  MACROBLOCK *const x = &td->mb;
-  MACROBLOCKD *const xd = &x->e_mbd;
-  SPEED_FEATURES *const sf = &cpi->sf;
-  int mi_col;
-
-  // Initialize the left context for the new SB row
-  memset(&xd->left_context, 0, sizeof(xd->left_context));
-  memset(xd->left_seg_context, 0, sizeof(xd->left_seg_context));
-
-  // Code each SB in the row
-  for (mi_col = tile_info->mi_col_start; mi_col < tile_info->mi_col_end;
-       mi_col += MI_BLOCK_SIZE) {
-    const struct segmentation *const seg = &cm->seg;
-    int dummy_rate;
-    int64_t dummy_dist;
-    RD_COST dummy_rdc;
-    int i;
-    int seg_skip = 0;
-
-    const int idx_str = cm->mi_stride * mi_row + mi_col;
-    MODE_INFO **mi = cm->mi_grid_visible + idx_str;
-
-    if (sf->adaptive_pred_interp_filter) {
-      for (i = 0; i < 64; ++i)
-        td->leaf_tree[i].pred_interp_filter = SWITCHABLE;
-
-      for (i = 0; i < 64; ++i) {
-        td->pc_tree[i].vertical[0].pred_interp_filter = SWITCHABLE;
-        td->pc_tree[i].vertical[1].pred_interp_filter = SWITCHABLE;
-        td->pc_tree[i].horizontal[0].pred_interp_filter = SWITCHABLE;
-        td->pc_tree[i].horizontal[1].pred_interp_filter = SWITCHABLE;
-      }
-    }
-
-    vp9_zero(x->pred_mv);
-    td->pc_root->index = 0;
-
-    if (seg->enabled) {
-      const uint8_t *const map = seg->update_map ? cpi->segmentation_map
-                                                 : cm->last_frame_seg_map;
-      int segment_id = get_segment_id(cm, map, BLOCK_64X64, mi_row, mi_col);
-      seg_skip = segfeature_active(seg, segment_id, SEG_LVL_SKIP);
-    }
-
-    x->source_variance = UINT_MAX;
-    if (sf->partition_search_type == FIXED_PARTITION || seg_skip) {
-      const BLOCK_SIZE bsize =
-          seg_skip ? BLOCK_64X64 : sf->always_this_block_size;
-      set_offsets(cpi, tile_info, x, mi_row, mi_col, BLOCK_64X64);
-      set_fixed_partitioning(cpi, tile_info, mi, mi_row, mi_col, bsize);
-      rd_use_partition(cpi, td, tile_data, mi, tp, mi_row, mi_col,
-                       BLOCK_64X64, &dummy_rate, &dummy_dist, 1, td->pc_root);
-    } else if (cpi->partition_search_skippable_frame) {
-      BLOCK_SIZE bsize;
-      set_offsets(cpi, tile_info, x, mi_row, mi_col, BLOCK_64X64);
-      bsize = get_rd_var_based_fixed_partition(cpi, x, mi_row, mi_col);
-      set_fixed_partitioning(cpi, tile_info, mi, mi_row, mi_col, bsize);
-      rd_use_partition(cpi, td, tile_data, mi, tp, mi_row, mi_col,
-                       BLOCK_64X64, &dummy_rate, &dummy_dist, 1, td->pc_root);
-    } else if (sf->partition_search_type == VAR_BASED_PARTITION &&
-               cm->frame_type != KEY_FRAME) {
-      choose_partitioning(cpi, tile_info, x, mi_row, mi_col);
-      rd_use_partition(cpi, td, tile_data, mi, tp, mi_row, mi_col,
-                       BLOCK_64X64, &dummy_rate, &dummy_dist, 1, td->pc_root);
-    } else {
-      // If required set upper and lower partition size limits
-      if (sf->auto_min_max_partition_size) {
-        set_offsets(cpi, tile_info, x, mi_row, mi_col, BLOCK_64X64);
-        rd_auto_partition_range(cpi, tile_info, xd, mi_row, mi_col,
-                                &x->min_partition_size,
-                                &x->max_partition_size);
-      }
-      rd_pick_partition(cpi, td, tile_data, tp, mi_row, mi_col, BLOCK_64X64,
-                        &dummy_rdc, INT64_MAX, td->pc_root);
-    }
-  }
-}
-
-static void init_encode_frame_mb_context(VP9_COMP *cpi) {
-  MACROBLOCK *const x = &cpi->td.mb;
-  VP9_COMMON *const cm = &cpi->common;
-  MACROBLOCKD *const xd = &x->e_mbd;
-  const int aligned_mi_cols = mi_cols_aligned_to_sb(cm->mi_cols);
-
-  // Copy data over into macro block data structures.
-  vp9_setup_src_planes(x, cpi->Source, 0, 0);
-
-  vp9_setup_block_planes(&x->e_mbd, cm->subsampling_x, cm->subsampling_y);
-
-  // Note: this memset assumes above_context[0], [1] and [2]
-  // are allocated as part of the same buffer.
-  memset(xd->above_context[0], 0,
-         sizeof(*xd->above_context[0]) *
-         2 * aligned_mi_cols * MAX_MB_PLANE);
-  memset(xd->above_seg_context, 0,
-         sizeof(*xd->above_seg_context) * aligned_mi_cols);
-}
-
-static int check_dual_ref_flags(VP9_COMP *cpi) {
-  const int ref_flags = cpi->ref_frame_flags;
-
-  if (segfeature_active(&cpi->common.seg, 1, SEG_LVL_REF_FRAME)) {
-    return 0;
-  } else {
-    return (!!(ref_flags & VP9_GOLD_FLAG) + !!(ref_flags & VP9_LAST_FLAG)
-        + !!(ref_flags & VP9_ALT_FLAG)) >= 2;
-  }
-}
-
-static void reset_skip_tx_size(VP9_COMMON *cm, TX_SIZE max_tx_size) {
-  int mi_row, mi_col;
-  const int mis = cm->mi_stride;
-  MODE_INFO **mi_ptr = cm->mi_grid_visible;
-
-  for (mi_row = 0; mi_row < cm->mi_rows; ++mi_row, mi_ptr += mis) {
-    for (mi_col = 0; mi_col < cm->mi_cols; ++mi_col) {
-      if (mi_ptr[mi_col]->tx_size > max_tx_size)
-        mi_ptr[mi_col]->tx_size = max_tx_size;
-    }
-  }
-}
-
-static MV_REFERENCE_FRAME get_frame_type(const VP9_COMP *cpi) {
-  if (frame_is_intra_only(&cpi->common))
-    return INTRA_FRAME;
-  else if (cpi->rc.is_src_frame_alt_ref && cpi->refresh_golden_frame)
-    return ALTREF_FRAME;
-  else if (cpi->refresh_golden_frame || cpi->refresh_alt_ref_frame)
-    return GOLDEN_FRAME;
-  else
-    return LAST_FRAME;
-}
-
-static TX_MODE select_tx_mode(const VP9_COMP *cpi, MACROBLOCKD *const xd) {
-  if (xd->lossless)
-    return ONLY_4X4;
-  if (cpi->common.frame_type == KEY_FRAME &&
-      cpi->sf.use_nonrd_pick_mode)
-    return ALLOW_16X16;
-  if (cpi->sf.tx_size_search_method == USE_LARGESTALL)
-    return ALLOW_32X32;
-  else if (cpi->sf.tx_size_search_method == USE_FULL_RD||
-           cpi->sf.tx_size_search_method == USE_TX_8X8)
-    return TX_MODE_SELECT;
-  else
-    return cpi->common.tx_mode;
-}
-
-static void hybrid_intra_mode_search(VP9_COMP *cpi, MACROBLOCK *const x,
-                                     RD_COST *rd_cost, BLOCK_SIZE bsize,
-                                     PICK_MODE_CONTEXT *ctx) {
-  if (bsize < BLOCK_16X16)
-    vp9_rd_pick_intra_mode_sb(cpi, x, rd_cost, bsize, ctx, INT64_MAX);
-  else
-    vp9_pick_intra_mode(cpi, x, rd_cost, bsize, ctx);
-}
-
-static void nonrd_pick_sb_modes(VP9_COMP *cpi,
-                                TileDataEnc *tile_data, MACROBLOCK *const x,
-                                int mi_row, int mi_col, RD_COST *rd_cost,
-                                BLOCK_SIZE bsize, PICK_MODE_CONTEXT *ctx) {
-  VP9_COMMON *const cm = &cpi->common;
-  TileInfo *const tile_info = &tile_data->tile_info;
-  MACROBLOCKD *const xd = &x->e_mbd;
-  MODE_INFO *mi;
-  ENTROPY_CONTEXT l[16 * MAX_MB_PLANE], a[16 * MAX_MB_PLANE];
-  BLOCK_SIZE bs = VPXMAX(bsize, BLOCK_8X8);  // processing unit block size
-  const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[bs];
-  const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[bs];
-  int plane;
-
-  set_offsets(cpi, tile_info, x, mi_row, mi_col, bsize);
-  mi = xd->mi[0];
-  mi->sb_type = bsize;
-
-  for (plane = 0; plane < MAX_MB_PLANE; ++plane) {
-    struct macroblockd_plane *pd = &xd->plane[plane];
-    memcpy(a + num_4x4_blocks_wide * plane, pd->above_context,
-           (sizeof(a[0]) * num_4x4_blocks_wide) >> pd->subsampling_x);
-    memcpy(l + num_4x4_blocks_high * plane, pd->left_context,
-           (sizeof(l[0]) * num_4x4_blocks_high) >> pd->subsampling_y);
-  }
-
-  if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ && cm->seg.enabled)
-    if (cyclic_refresh_segment_id_boosted(mi->segment_id))
-      x->rdmult = vp9_cyclic_refresh_get_rdmult(cpi->cyclic_refresh);
-
-  if (cm->frame_type == KEY_FRAME)
-    hybrid_intra_mode_search(cpi, x, rd_cost, bsize, ctx);
-  else if (segfeature_active(&cm->seg, mi->segment_id, SEG_LVL_SKIP))
-    set_mode_info_seg_skip(x, cm->tx_mode, rd_cost, bsize);
-  else if (bsize >= BLOCK_8X8)
-    vp9_pick_inter_mode(cpi, x, tile_data, mi_row, mi_col,
-                        rd_cost, bsize, ctx);
-  else
-    vp9_pick_inter_mode_sub8x8(cpi, x, mi_row, mi_col,
-                               rd_cost, bsize, ctx);
-
-  duplicate_mode_info_in_sb(cm, xd, mi_row, mi_col, bsize);
-
-  for (plane = 0; plane < MAX_MB_PLANE; ++plane) {
-    struct macroblockd_plane *pd = &xd->plane[plane];
-    memcpy(pd->above_context, a + num_4x4_blocks_wide * plane,
-           (sizeof(a[0]) * num_4x4_blocks_wide) >> pd->subsampling_x);
-    memcpy(pd->left_context, l + num_4x4_blocks_high * plane,
-           (sizeof(l[0]) * num_4x4_blocks_high) >> pd->subsampling_y);
-  }
-
-  if (rd_cost->rate == INT_MAX)
-    vp9_rd_cost_reset(rd_cost);
-
-  ctx->rate = rd_cost->rate;
-  ctx->dist = rd_cost->dist;
-}
-
-static void fill_mode_info_sb(VP9_COMMON *cm, MACROBLOCK *x,
-                              int mi_row, int mi_col,
-                              BLOCK_SIZE bsize,
-                              PC_TREE *pc_tree) {
-  MACROBLOCKD *xd = &x->e_mbd;
-  int bsl = b_width_log2_lookup[bsize], hbs = (1 << bsl) / 4;
-  PARTITION_TYPE partition = pc_tree->partitioning;
-  BLOCK_SIZE subsize = get_subsize(bsize, partition);
-
-  assert(bsize >= BLOCK_8X8);
-
-  if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols)
-    return;
-
-  switch (partition) {
-    case PARTITION_NONE:
-      set_mode_info_offsets(cm, x, xd, mi_row, mi_col);
-      *(xd->mi[0]) = pc_tree->none.mic;
-      *(x->mbmi_ext) = pc_tree->none.mbmi_ext;
-      duplicate_mode_info_in_sb(cm, xd, mi_row, mi_col, bsize);
-      break;
-    case PARTITION_VERT:
-      set_mode_info_offsets(cm, x, xd, mi_row, mi_col);
-      *(xd->mi[0]) = pc_tree->vertical[0].mic;
-      *(x->mbmi_ext) = pc_tree->vertical[0].mbmi_ext;
-      duplicate_mode_info_in_sb(cm, xd, mi_row, mi_col, subsize);
-
-      if (mi_col + hbs < cm->mi_cols) {
-        set_mode_info_offsets(cm, x, xd, mi_row, mi_col + hbs);
-        *(xd->mi[0]) = pc_tree->vertical[1].mic;
-        *(x->mbmi_ext) = pc_tree->vertical[1].mbmi_ext;
-        duplicate_mode_info_in_sb(cm, xd, mi_row, mi_col + hbs, subsize);
-      }
-      break;
-    case PARTITION_HORZ:
-      set_mode_info_offsets(cm, x, xd, mi_row, mi_col);
-      *(xd->mi[0]) = pc_tree->horizontal[0].mic;
-      *(x->mbmi_ext) = pc_tree->horizontal[0].mbmi_ext;
-      duplicate_mode_info_in_sb(cm, xd, mi_row, mi_col, subsize);
-      if (mi_row + hbs < cm->mi_rows) {
-        set_mode_info_offsets(cm, x, xd, mi_row + hbs, mi_col);
-        *(xd->mi[0]) = pc_tree->horizontal[1].mic;
-        *(x->mbmi_ext) = pc_tree->horizontal[1].mbmi_ext;
-        duplicate_mode_info_in_sb(cm, xd, mi_row + hbs, mi_col, subsize);
-      }
-      break;
-    case PARTITION_SPLIT: {
-      fill_mode_info_sb(cm, x, mi_row, mi_col, subsize, pc_tree->split[0]);
-      fill_mode_info_sb(cm, x, mi_row, mi_col + hbs, subsize,
-                        pc_tree->split[1]);
-      fill_mode_info_sb(cm, x, mi_row + hbs, mi_col, subsize,
-                        pc_tree->split[2]);
-      fill_mode_info_sb(cm, x, mi_row + hbs, mi_col + hbs, subsize,
-                        pc_tree->split[3]);
-      break;
-    }
-    default:
-      break;
-  }
-}
-
-// Reset the prediction pixel ready flag recursively.
-static void pred_pixel_ready_reset(PC_TREE *pc_tree, BLOCK_SIZE bsize) {
-  pc_tree->none.pred_pixel_ready = 0;
-  pc_tree->horizontal[0].pred_pixel_ready = 0;
-  pc_tree->horizontal[1].pred_pixel_ready = 0;
-  pc_tree->vertical[0].pred_pixel_ready = 0;
-  pc_tree->vertical[1].pred_pixel_ready = 0;
-
-  if (bsize > BLOCK_8X8) {
-    BLOCK_SIZE subsize = get_subsize(bsize, PARTITION_SPLIT);
-    int i;
-    for (i = 0; i < 4; ++i)
-      pred_pixel_ready_reset(pc_tree->split[i], subsize);
-  }
-}
-
-static void nonrd_pick_partition(VP9_COMP *cpi, ThreadData *td,
-                                 TileDataEnc *tile_data,
-                                 TOKENEXTRA **tp, int mi_row,
-                                 int mi_col, BLOCK_SIZE bsize, RD_COST *rd_cost,
-                                 int do_recon, int64_t best_rd,
-                                 PC_TREE *pc_tree) {
-  const SPEED_FEATURES *const sf = &cpi->sf;
-  VP9_COMMON *const cm = &cpi->common;
-  TileInfo *const tile_info = &tile_data->tile_info;
-  MACROBLOCK *const x = &td->mb;
-  MACROBLOCKD *const xd = &x->e_mbd;
-  const int ms = num_8x8_blocks_wide_lookup[bsize] / 2;
-  TOKENEXTRA *tp_orig = *tp;
-  PICK_MODE_CONTEXT *ctx = &pc_tree->none;
-  int i;
-  BLOCK_SIZE subsize = bsize;
-  RD_COST this_rdc, sum_rdc, best_rdc;
-  int do_split = bsize >= BLOCK_8X8;
-  int do_rect = 1;
-  // Override skipping rectangular partition operations for edge blocks
-  const int force_horz_split = (mi_row + ms >= cm->mi_rows);
-  const int force_vert_split = (mi_col + ms >= cm->mi_cols);
-  const int xss = x->e_mbd.plane[1].subsampling_x;
-  const int yss = x->e_mbd.plane[1].subsampling_y;
-
-  int partition_none_allowed = !force_horz_split && !force_vert_split;
-  int partition_horz_allowed = !force_vert_split && yss <= xss &&
-                               bsize >= BLOCK_8X8;
-  int partition_vert_allowed = !force_horz_split && xss <= yss &&
-                               bsize >= BLOCK_8X8;
-  (void) *tp_orig;
-
-  assert(num_8x8_blocks_wide_lookup[bsize] ==
-             num_8x8_blocks_high_lookup[bsize]);
-
-  vp9_rd_cost_init(&sum_rdc);
-  vp9_rd_cost_reset(&best_rdc);
-  best_rdc.rdcost = best_rd;
-
-  // Determine partition types in search according to the speed features.
-  // The threshold set here has to be of square block size.
-  if (sf->auto_min_max_partition_size) {
-    partition_none_allowed &= (bsize <= x->max_partition_size &&
-                               bsize >= x->min_partition_size);
-    partition_horz_allowed &= ((bsize <= x->max_partition_size &&
-                                bsize > x->min_partition_size) ||
-                                force_horz_split);
-    partition_vert_allowed &= ((bsize <= x->max_partition_size &&
-                                bsize > x->min_partition_size) ||
-                                force_vert_split);
-    do_split &= bsize > x->min_partition_size;
-  }
-  if (sf->use_square_partition_only) {
-    partition_horz_allowed &= force_horz_split;
-    partition_vert_allowed &= force_vert_split;
-  }
-
-  ctx->pred_pixel_ready = !(partition_vert_allowed ||
-                            partition_horz_allowed ||
-                            do_split);
-
-  // PARTITION_NONE
-  if (partition_none_allowed) {
-    nonrd_pick_sb_modes(cpi, tile_data, x, mi_row, mi_col,
-                        &this_rdc, bsize, ctx);
-    ctx->mic = *xd->mi[0];
-    ctx->mbmi_ext = *x->mbmi_ext;
-    ctx->skip_txfm[0] = x->skip_txfm[0];
-    ctx->skip = x->skip;
-
-    if (this_rdc.rate != INT_MAX) {
-      int pl = partition_plane_context(xd, mi_row, mi_col, bsize);
-      this_rdc.rate += cpi->partition_cost[pl][PARTITION_NONE];
-      this_rdc.rdcost = RDCOST(x->rdmult, x->rddiv,
-                              this_rdc.rate, this_rdc.dist);
-      if (this_rdc.rdcost < best_rdc.rdcost) {
-        int64_t dist_breakout_thr = sf->partition_search_breakout_dist_thr;
-        int64_t rate_breakout_thr = sf->partition_search_breakout_rate_thr;
-
-        dist_breakout_thr >>= 8 - (b_width_log2_lookup[bsize] +
-            b_height_log2_lookup[bsize]);
-
-        rate_breakout_thr *= num_pels_log2_lookup[bsize];
-
-        best_rdc = this_rdc;
-        if (bsize >= BLOCK_8X8)
-          pc_tree->partitioning = PARTITION_NONE;
-
-        if (!x->e_mbd.lossless &&
-            this_rdc.rate < rate_breakout_thr &&
-            this_rdc.dist < dist_breakout_thr) {
-          do_split = 0;
-          do_rect = 0;
-        }
-      }
-    }
-  }
-
-  // store estimated motion vector
-  store_pred_mv(x, ctx);
-
-  // PARTITION_SPLIT
-  if (do_split) {
-    int pl = partition_plane_context(xd, mi_row, mi_col, bsize);
-    sum_rdc.rate += cpi->partition_cost[pl][PARTITION_SPLIT];
-    sum_rdc.rdcost = RDCOST(x->rdmult, x->rddiv, sum_rdc.rate, sum_rdc.dist);
-    subsize = get_subsize(bsize, PARTITION_SPLIT);
-    for (i = 0; i < 4 && sum_rdc.rdcost < best_rdc.rdcost; ++i) {
-      const int x_idx = (i & 1) * ms;
-      const int y_idx = (i >> 1) * ms;
-
-      if (mi_row + y_idx >= cm->mi_rows || mi_col + x_idx >= cm->mi_cols)
-        continue;
-      load_pred_mv(x, ctx);
-      nonrd_pick_partition(cpi, td, tile_data, tp,
-                           mi_row + y_idx, mi_col + x_idx,
-                           subsize, &this_rdc, 0,
-                           best_rdc.rdcost - sum_rdc.rdcost, pc_tree->split[i]);
-
-      if (this_rdc.rate == INT_MAX) {
-        vp9_rd_cost_reset(&sum_rdc);
-      } else {
-        sum_rdc.rate += this_rdc.rate;
-        sum_rdc.dist += this_rdc.dist;
-        sum_rdc.rdcost += this_rdc.rdcost;
-      }
-    }
-
-    if (sum_rdc.rdcost < best_rdc.rdcost) {
-      best_rdc = sum_rdc;
-      pc_tree->partitioning = PARTITION_SPLIT;
-    } else {
-      // skip rectangular partition test when larger block size
-      // gives better rd cost
-      if (sf->less_rectangular_check)
-        do_rect &= !partition_none_allowed;
-    }
-  }
-
-  // PARTITION_HORZ
-  if (partition_horz_allowed && do_rect) {
-    subsize = get_subsize(bsize, PARTITION_HORZ);
-    if (sf->adaptive_motion_search)
-      load_pred_mv(x, ctx);
-    pc_tree->horizontal[0].pred_pixel_ready = 1;
-    nonrd_pick_sb_modes(cpi, tile_data, x, mi_row, mi_col, &sum_rdc, subsize,
-                        &pc_tree->horizontal[0]);
-
-    pc_tree->horizontal[0].mic = *xd->mi[0];
-    pc_tree->horizontal[0].mbmi_ext = *x->mbmi_ext;
-    pc_tree->horizontal[0].skip_txfm[0] = x->skip_txfm[0];
-    pc_tree->horizontal[0].skip = x->skip;
-
-    if (sum_rdc.rdcost < best_rdc.rdcost && mi_row + ms < cm->mi_rows) {
-      load_pred_mv(x, ctx);
-      pc_tree->horizontal[1].pred_pixel_ready = 1;
-      nonrd_pick_sb_modes(cpi, tile_data, x, mi_row + ms, mi_col,
-                          &this_rdc, subsize,
-                          &pc_tree->horizontal[1]);
-
-      pc_tree->horizontal[1].mic = *xd->mi[0];
-      pc_tree->horizontal[1].mbmi_ext = *x->mbmi_ext;
-      pc_tree->horizontal[1].skip_txfm[0] = x->skip_txfm[0];
-      pc_tree->horizontal[1].skip = x->skip;
-
-      if (this_rdc.rate == INT_MAX) {
-        vp9_rd_cost_reset(&sum_rdc);
-      } else {
-        int pl = partition_plane_context(xd, mi_row, mi_col, bsize);
-        this_rdc.rate += cpi->partition_cost[pl][PARTITION_HORZ];
-        sum_rdc.rate += this_rdc.rate;
-        sum_rdc.dist += this_rdc.dist;
-        sum_rdc.rdcost = RDCOST(x->rdmult, x->rddiv,
-                                sum_rdc.rate, sum_rdc.dist);
-      }
-    }
-
-    if (sum_rdc.rdcost < best_rdc.rdcost) {
-      best_rdc = sum_rdc;
-      pc_tree->partitioning = PARTITION_HORZ;
-    } else {
-      pred_pixel_ready_reset(pc_tree, bsize);
-    }
-  }
-
-  // PARTITION_VERT
-  if (partition_vert_allowed && do_rect) {
-    subsize = get_subsize(bsize, PARTITION_VERT);
-    if (sf->adaptive_motion_search)
-      load_pred_mv(x, ctx);
-    pc_tree->vertical[0].pred_pixel_ready = 1;
-    nonrd_pick_sb_modes(cpi, tile_data, x, mi_row, mi_col, &sum_rdc, subsize,
-                        &pc_tree->vertical[0]);
-    pc_tree->vertical[0].mic = *xd->mi[0];
-    pc_tree->vertical[0].mbmi_ext = *x->mbmi_ext;
-    pc_tree->vertical[0].skip_txfm[0] = x->skip_txfm[0];
-    pc_tree->vertical[0].skip = x->skip;
-
-    if (sum_rdc.rdcost < best_rdc.rdcost && mi_col + ms < cm->mi_cols) {
-      load_pred_mv(x, ctx);
-      pc_tree->vertical[1].pred_pixel_ready = 1;
-      nonrd_pick_sb_modes(cpi, tile_data, x, mi_row, mi_col + ms,
-                          &this_rdc, subsize,
-                          &pc_tree->vertical[1]);
-      pc_tree->vertical[1].mic = *xd->mi[0];
-      pc_tree->vertical[1].mbmi_ext = *x->mbmi_ext;
-      pc_tree->vertical[1].skip_txfm[0] = x->skip_txfm[0];
-      pc_tree->vertical[1].skip = x->skip;
-
-      if (this_rdc.rate == INT_MAX) {
-        vp9_rd_cost_reset(&sum_rdc);
-      } else {
-        int pl = partition_plane_context(xd, mi_row, mi_col, bsize);
-        sum_rdc.rate += cpi->partition_cost[pl][PARTITION_VERT];
-        sum_rdc.rate += this_rdc.rate;
-        sum_rdc.dist += this_rdc.dist;
-        sum_rdc.rdcost = RDCOST(x->rdmult, x->rddiv,
-                                sum_rdc.rate, sum_rdc.dist);
-      }
-    }
-
-    if (sum_rdc.rdcost < best_rdc.rdcost) {
-      best_rdc = sum_rdc;
-      pc_tree->partitioning = PARTITION_VERT;
-    } else {
-      pred_pixel_ready_reset(pc_tree, bsize);
-    }
-  }
-
-  *rd_cost = best_rdc;
-
-  if (best_rdc.rate == INT_MAX) {
-    vp9_rd_cost_reset(rd_cost);
-    return;
-  }
-
-  // update mode info array
-  fill_mode_info_sb(cm, x, mi_row, mi_col, bsize, pc_tree);
-
-  if (best_rdc.rate < INT_MAX && best_rdc.dist < INT64_MAX && do_recon) {
-    int output_enabled = (bsize == BLOCK_64X64);
-    encode_sb_rt(cpi, td, tile_info, tp, mi_row, mi_col, output_enabled,
-                 bsize, pc_tree);
-  }
-
-  if (bsize == BLOCK_64X64 && do_recon) {
-    assert(tp_orig < *tp);
-    assert(best_rdc.rate < INT_MAX);
-    assert(best_rdc.dist < INT64_MAX);
-  } else {
-    assert(tp_orig == *tp);
-  }
-}
-
-static void nonrd_select_partition(VP9_COMP *cpi,
-                                   ThreadData *td,
-                                   TileDataEnc *tile_data,
-                                   MODE_INFO **mi,
-                                   TOKENEXTRA **tp,
-                                   int mi_row, int mi_col,
-                                   BLOCK_SIZE bsize, int output_enabled,
-                                   RD_COST *rd_cost, PC_TREE *pc_tree) {
-  VP9_COMMON *const cm = &cpi->common;
-  TileInfo *const tile_info = &tile_data->tile_info;
-  MACROBLOCK *const x = &td->mb;
-  MACROBLOCKD *const xd = &x->e_mbd;
-  const int bsl = b_width_log2_lookup[bsize], hbs = (1 << bsl) / 4;
-  const int mis = cm->mi_stride;
-  PARTITION_TYPE partition;
-  BLOCK_SIZE subsize;
-  RD_COST this_rdc;
-
-  vp9_rd_cost_reset(&this_rdc);
-  if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols)
-    return;
-
-  subsize = (bsize >= BLOCK_8X8) ? mi[0]->sb_type : BLOCK_4X4;
-  partition = partition_lookup[bsl][subsize];
-
-  if (bsize == BLOCK_32X32 && subsize == BLOCK_32X32) {
-    x->max_partition_size = BLOCK_32X32;
-    x->min_partition_size = BLOCK_16X16;
-    nonrd_pick_partition(cpi, td, tile_data, tp, mi_row, mi_col, bsize,
-                         rd_cost, 0, INT64_MAX, pc_tree);
-  } else if (bsize == BLOCK_32X32 && partition != PARTITION_NONE &&
-             subsize >= BLOCK_16X16) {
-    x->max_partition_size = BLOCK_32X32;
-    x->min_partition_size = BLOCK_8X8;
-    nonrd_pick_partition(cpi, td, tile_data, tp, mi_row, mi_col, bsize,
-                         rd_cost, 0, INT64_MAX, pc_tree);
-  } else if (bsize == BLOCK_16X16 && partition != PARTITION_NONE) {
-    x->max_partition_size = BLOCK_16X16;
-    x->min_partition_size = BLOCK_8X8;
-    nonrd_pick_partition(cpi, td, tile_data, tp, mi_row, mi_col, bsize,
-                         rd_cost, 0, INT64_MAX, pc_tree);
-  } else {
-    switch (partition) {
-      case PARTITION_NONE:
-        pc_tree->none.pred_pixel_ready = 1;
-        nonrd_pick_sb_modes(cpi, tile_data, x, mi_row, mi_col, rd_cost,
-                            subsize, &pc_tree->none);
-        pc_tree->none.mic = *xd->mi[0];
-        pc_tree->none.mbmi_ext = *x->mbmi_ext;
-        pc_tree->none.skip_txfm[0] = x->skip_txfm[0];
-        pc_tree->none.skip = x->skip;
-        break;
-      case PARTITION_VERT:
-        pc_tree->vertical[0].pred_pixel_ready = 1;
-        nonrd_pick_sb_modes(cpi, tile_data, x, mi_row, mi_col, rd_cost,
-                            subsize, &pc_tree->vertical[0]);
-        pc_tree->vertical[0].mic = *xd->mi[0];
-        pc_tree->vertical[0].mbmi_ext = *x->mbmi_ext;
-        pc_tree->vertical[0].skip_txfm[0] = x->skip_txfm[0];
-        pc_tree->vertical[0].skip = x->skip;
-        if (mi_col + hbs < cm->mi_cols) {
-          pc_tree->vertical[1].pred_pixel_ready = 1;
-          nonrd_pick_sb_modes(cpi, tile_data, x, mi_row, mi_col + hbs,
-                              &this_rdc, subsize, &pc_tree->vertical[1]);
-          pc_tree->vertical[1].mic = *xd->mi[0];
-          pc_tree->vertical[1].mbmi_ext = *x->mbmi_ext;
-          pc_tree->vertical[1].skip_txfm[0] = x->skip_txfm[0];
-          pc_tree->vertical[1].skip = x->skip;
-          if (this_rdc.rate != INT_MAX && this_rdc.dist != INT64_MAX &&
-              rd_cost->rate != INT_MAX && rd_cost->dist != INT64_MAX) {
-            rd_cost->rate += this_rdc.rate;
-            rd_cost->dist += this_rdc.dist;
-          }
-        }
-        break;
-      case PARTITION_HORZ:
-        pc_tree->horizontal[0].pred_pixel_ready = 1;
-        nonrd_pick_sb_modes(cpi, tile_data, x, mi_row, mi_col, rd_cost,
-                            subsize, &pc_tree->horizontal[0]);
-        pc_tree->horizontal[0].mic = *xd->mi[0];
-        pc_tree->horizontal[0].mbmi_ext = *x->mbmi_ext;
-        pc_tree->horizontal[0].skip_txfm[0] = x->skip_txfm[0];
-        pc_tree->horizontal[0].skip = x->skip;
-        if (mi_row + hbs < cm->mi_rows) {
-          pc_tree->horizontal[1].pred_pixel_ready = 1;
-          nonrd_pick_sb_modes(cpi, tile_data, x, mi_row + hbs, mi_col,
-                              &this_rdc, subsize, &pc_tree->horizontal[1]);
-          pc_tree->horizontal[1].mic = *xd->mi[0];
-          pc_tree->horizontal[1].mbmi_ext = *x->mbmi_ext;
-          pc_tree->horizontal[1].skip_txfm[0] = x->skip_txfm[0];
-          pc_tree->horizontal[1].skip = x->skip;
-          if (this_rdc.rate != INT_MAX && this_rdc.dist != INT64_MAX &&
-              rd_cost->rate != INT_MAX && rd_cost->dist != INT64_MAX) {
-            rd_cost->rate += this_rdc.rate;
-            rd_cost->dist += this_rdc.dist;
-          }
-        }
-        break;
-      case PARTITION_SPLIT:
-        subsize = get_subsize(bsize, PARTITION_SPLIT);
-        nonrd_select_partition(cpi, td, tile_data, mi, tp, mi_row, mi_col,
-                               subsize, output_enabled, rd_cost,
-                               pc_tree->split[0]);
-        nonrd_select_partition(cpi, td, tile_data, mi + hbs, tp,
-                               mi_row, mi_col + hbs, subsize, output_enabled,
-                               &this_rdc, pc_tree->split[1]);
-        if (this_rdc.rate != INT_MAX && this_rdc.dist != INT64_MAX &&
-            rd_cost->rate != INT_MAX && rd_cost->dist != INT64_MAX) {
-          rd_cost->rate += this_rdc.rate;
-          rd_cost->dist += this_rdc.dist;
-        }
-        nonrd_select_partition(cpi, td, tile_data, mi + hbs * mis, tp,
-                               mi_row + hbs, mi_col, subsize, output_enabled,
-                               &this_rdc, pc_tree->split[2]);
-        if (this_rdc.rate != INT_MAX && this_rdc.dist != INT64_MAX &&
-            rd_cost->rate != INT_MAX && rd_cost->dist != INT64_MAX) {
-          rd_cost->rate += this_rdc.rate;
-          rd_cost->dist += this_rdc.dist;
-        }
-        nonrd_select_partition(cpi, td, tile_data, mi + hbs * mis + hbs, tp,
-                               mi_row + hbs, mi_col + hbs, subsize,
-                               output_enabled, &this_rdc, pc_tree->split[3]);
-        if (this_rdc.rate != INT_MAX && this_rdc.dist != INT64_MAX &&
-            rd_cost->rate != INT_MAX && rd_cost->dist != INT64_MAX) {
-          rd_cost->rate += this_rdc.rate;
-          rd_cost->dist += this_rdc.dist;
-        }
-        break;
-      default:
-        assert(0 && "Invalid partition type.");
-        break;
-    }
-  }
-
-  if (bsize == BLOCK_64X64 && output_enabled)
-    encode_sb_rt(cpi, td, tile_info, tp, mi_row, mi_col, 1, bsize, pc_tree);
-}
-
-
-static void nonrd_use_partition(VP9_COMP *cpi,
-                                ThreadData *td,
-                                TileDataEnc *tile_data,
-                                MODE_INFO **mi,
-                                TOKENEXTRA **tp,
-                                int mi_row, int mi_col,
-                                BLOCK_SIZE bsize, int output_enabled,
-                                RD_COST *dummy_cost, PC_TREE *pc_tree) {
-  VP9_COMMON *const cm = &cpi->common;
-  TileInfo *tile_info = &tile_data->tile_info;
-  MACROBLOCK *const x = &td->mb;
-  MACROBLOCKD *const xd = &x->e_mbd;
-  const int bsl = b_width_log2_lookup[bsize], hbs = (1 << bsl) / 4;
-  const int mis = cm->mi_stride;
-  PARTITION_TYPE partition;
-  BLOCK_SIZE subsize;
-
-  if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols)
-    return;
-
-  subsize = (bsize >= BLOCK_8X8) ? mi[0]->sb_type : BLOCK_4X4;
-  partition = partition_lookup[bsl][subsize];
-
-  if (output_enabled && bsize != BLOCK_4X4) {
-    int ctx = partition_plane_context(xd, mi_row, mi_col, bsize);
-    td->counts->partition[ctx][partition]++;
-  }
-
-  switch (partition) {
-    case PARTITION_NONE:
-      pc_tree->none.pred_pixel_ready = 1;
-      nonrd_pick_sb_modes(cpi, tile_data, x, mi_row, mi_col, dummy_cost,
-                          subsize, &pc_tree->none);
-      pc_tree->none.mic = *xd->mi[0];
-      pc_tree->none.mbmi_ext = *x->mbmi_ext;
-      pc_tree->none.skip_txfm[0] = x->skip_txfm[0];
-      pc_tree->none.skip = x->skip;
-      encode_b_rt(cpi, td, tile_info, tp, mi_row, mi_col, output_enabled,
-                  subsize, &pc_tree->none);
-      break;
-    case PARTITION_VERT:
-      pc_tree->vertical[0].pred_pixel_ready = 1;
-      nonrd_pick_sb_modes(cpi, tile_data, x, mi_row, mi_col, dummy_cost,
-                          subsize, &pc_tree->vertical[0]);
-      pc_tree->vertical[0].mic = *xd->mi[0];
-      pc_tree->vertical[0].mbmi_ext = *x->mbmi_ext;
-      pc_tree->vertical[0].skip_txfm[0] = x->skip_txfm[0];
-      pc_tree->vertical[0].skip = x->skip;
-      encode_b_rt(cpi, td, tile_info, tp, mi_row, mi_col, output_enabled,
-                  subsize, &pc_tree->vertical[0]);
-      if (mi_col + hbs < cm->mi_cols && bsize > BLOCK_8X8) {
-        pc_tree->vertical[1].pred_pixel_ready = 1;
-        nonrd_pick_sb_modes(cpi, tile_data, x, mi_row, mi_col + hbs,
-                            dummy_cost, subsize, &pc_tree->vertical[1]);
-        pc_tree->vertical[1].mic = *xd->mi[0];
-        pc_tree->vertical[1].mbmi_ext = *x->mbmi_ext;
-        pc_tree->vertical[1].skip_txfm[0] = x->skip_txfm[0];
-        pc_tree->vertical[1].skip = x->skip;
-        encode_b_rt(cpi, td, tile_info, tp, mi_row, mi_col + hbs,
-                    output_enabled, subsize, &pc_tree->vertical[1]);
-      }
-      break;
-    case PARTITION_HORZ:
-      pc_tree->horizontal[0].pred_pixel_ready = 1;
-      nonrd_pick_sb_modes(cpi, tile_data, x, mi_row, mi_col, dummy_cost,
-                          subsize, &pc_tree->horizontal[0]);
-      pc_tree->horizontal[0].mic = *xd->mi[0];
-      pc_tree->horizontal[0].mbmi_ext = *x->mbmi_ext;
-      pc_tree->horizontal[0].skip_txfm[0] = x->skip_txfm[0];
-      pc_tree->horizontal[0].skip = x->skip;
-      encode_b_rt(cpi, td, tile_info, tp, mi_row, mi_col, output_enabled,
-                  subsize, &pc_tree->horizontal[0]);
-
-      if (mi_row + hbs < cm->mi_rows && bsize > BLOCK_8X8) {
-        pc_tree->horizontal[1].pred_pixel_ready = 1;
-        nonrd_pick_sb_modes(cpi, tile_data, x, mi_row + hbs, mi_col,
-                            dummy_cost, subsize, &pc_tree->horizontal[1]);
-        pc_tree->horizontal[1].mic = *xd->mi[0];
-        pc_tree->horizontal[1].mbmi_ext = *x->mbmi_ext;
-        pc_tree->horizontal[1].skip_txfm[0] = x->skip_txfm[0];
-        pc_tree->horizontal[1].skip = x->skip;
-        encode_b_rt(cpi, td, tile_info, tp, mi_row + hbs, mi_col,
-                    output_enabled, subsize, &pc_tree->horizontal[1]);
-      }
-      break;
-    case PARTITION_SPLIT:
-      subsize = get_subsize(bsize, PARTITION_SPLIT);
-      if (bsize == BLOCK_8X8) {
-        nonrd_pick_sb_modes(cpi, tile_data, x, mi_row, mi_col, dummy_cost,
-                            subsize, pc_tree->leaf_split[0]);
-        encode_b_rt(cpi, td, tile_info, tp, mi_row, mi_col,
-                    output_enabled, subsize, pc_tree->leaf_split[0]);
-      } else {
-        nonrd_use_partition(cpi, td, tile_data, mi, tp, mi_row, mi_col,
-                            subsize, output_enabled, dummy_cost,
-                            pc_tree->split[0]);
-        nonrd_use_partition(cpi, td, tile_data, mi + hbs, tp,
-                            mi_row, mi_col + hbs, subsize, output_enabled,
-                            dummy_cost, pc_tree->split[1]);
-        nonrd_use_partition(cpi, td, tile_data, mi + hbs * mis, tp,
-                            mi_row + hbs, mi_col, subsize, output_enabled,
-                            dummy_cost, pc_tree->split[2]);
-        nonrd_use_partition(cpi, td, tile_data, mi + hbs * mis + hbs, tp,
-                            mi_row + hbs, mi_col + hbs, subsize, output_enabled,
-                            dummy_cost, pc_tree->split[3]);
-      }
-      break;
-    default:
-      assert(0 && "Invalid partition type.");
-      break;
-  }
-
-  if (partition != PARTITION_SPLIT || bsize == BLOCK_8X8)
-    update_partition_context(xd, mi_row, mi_col, subsize, bsize);
-}
-
-static void encode_nonrd_sb_row(VP9_COMP *cpi,
-                                ThreadData *td,
-                                TileDataEnc *tile_data,
-                                int mi_row,
-                                TOKENEXTRA **tp) {
-  SPEED_FEATURES *const sf = &cpi->sf;
-  VP9_COMMON *const cm = &cpi->common;
-  TileInfo *const tile_info = &tile_data->tile_info;
-  MACROBLOCK *const x = &td->mb;
-  MACROBLOCKD *const xd = &x->e_mbd;
-  int mi_col;
-
-  // Initialize the left context for the new SB row
-  memset(&xd->left_context, 0, sizeof(xd->left_context));
-  memset(xd->left_seg_context, 0, sizeof(xd->left_seg_context));
-
-  // Code each SB in the row
-  for (mi_col = tile_info->mi_col_start; mi_col < tile_info->mi_col_end;
-       mi_col += MI_BLOCK_SIZE) {
-    const struct segmentation *const seg = &cm->seg;
-    RD_COST dummy_rdc;
-    const int idx_str = cm->mi_stride * mi_row + mi_col;
-    MODE_INFO **mi = cm->mi_grid_visible + idx_str;
-    PARTITION_SEARCH_TYPE partition_search_type = sf->partition_search_type;
-    BLOCK_SIZE bsize = BLOCK_64X64;
-    int seg_skip = 0;
-    x->source_variance = UINT_MAX;
-    vp9_zero(x->pred_mv);
-    vp9_rd_cost_init(&dummy_rdc);
-    x->color_sensitivity[0] = 0;
-    x->color_sensitivity[1] = 0;
-    x->sb_is_skin = 0;
-
-    if (seg->enabled) {
-      const uint8_t *const map = seg->update_map ? cpi->segmentation_map
-                                                 : cm->last_frame_seg_map;
-      int segment_id = get_segment_id(cm, map, BLOCK_64X64, mi_row, mi_col);
-      seg_skip = segfeature_active(seg, segment_id, SEG_LVL_SKIP);
-      if (seg_skip) {
-        partition_search_type = FIXED_PARTITION;
-      }
-    }
-
-    // Set the partition type of the 64X64 block
-    switch (partition_search_type) {
-      case VAR_BASED_PARTITION:
-        // TODO(jingning, marpan): The mode decision and encoding process
-        // support both intra and inter sub8x8 block coding for RTC mode.
-        // Tune the thresholds accordingly to use sub8x8 block coding for
-        // coding performance improvement.
-        choose_partitioning(cpi, tile_info, x, mi_row, mi_col);
-        nonrd_use_partition(cpi, td, tile_data, mi, tp, mi_row, mi_col,
-                            BLOCK_64X64, 1, &dummy_rdc, td->pc_root);
-        break;
-      case SOURCE_VAR_BASED_PARTITION:
-        set_source_var_based_partition(cpi, tile_info, x, mi, mi_row, mi_col);
-        nonrd_use_partition(cpi, td, tile_data, mi, tp, mi_row, mi_col,
-                            BLOCK_64X64, 1, &dummy_rdc, td->pc_root);
-        break;
-      case FIXED_PARTITION:
-        if (!seg_skip)
-          bsize = sf->always_this_block_size;
-        set_fixed_partitioning(cpi, tile_info, mi, mi_row, mi_col, bsize);
-        nonrd_use_partition(cpi, td, tile_data, mi, tp, mi_row, mi_col,
-                            BLOCK_64X64, 1, &dummy_rdc, td->pc_root);
-        break;
-      case REFERENCE_PARTITION:
-        set_offsets(cpi, tile_info, x, mi_row, mi_col, BLOCK_64X64);
-        // Use nonrd_pick_partition on scene-cut for VBR, or on qp-segment
-        // if cyclic_refresh is enabled.
-        // nonrd_pick_partition does not support 4x4 partition, so avoid it
-        // on key frame for now.
-        if ((cpi->oxcf.rc_mode == VPX_VBR && cpi->rc.high_source_sad &&
-            cm->frame_type != KEY_FRAME) ||
-            (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ && cm->seg.enabled &&
-            xd->mi[0]->segment_id)) {
-          // Use lower max_partition_size for low resoultions.
-          if (cm->width <= 352 && cm->height <= 288)
-            x->max_partition_size = BLOCK_32X32;
-          else
-            x->max_partition_size = BLOCK_64X64;
-          x->min_partition_size = BLOCK_8X8;
-          nonrd_pick_partition(cpi, td, tile_data, tp, mi_row, mi_col,
-                               BLOCK_64X64, &dummy_rdc, 1,
-                               INT64_MAX, td->pc_root);
-        } else {
-          choose_partitioning(cpi, tile_info, x, mi_row, mi_col);
-          // TODO(marpan): Seems like nonrd_select_partition does not support
-          // 4x4 partition. Since 4x4 is used on key frame, use this switch
-          // for now.
-          if (cm->frame_type == KEY_FRAME)
-            nonrd_use_partition(cpi, td, tile_data, mi, tp, mi_row, mi_col,
-                                BLOCK_64X64, 1, &dummy_rdc, td->pc_root);
-          else
-            nonrd_select_partition(cpi, td, tile_data, mi, tp, mi_row, mi_col,
-                                   BLOCK_64X64, 1, &dummy_rdc, td->pc_root);
-        }
-
-        break;
-      default:
-        assert(0);
-        break;
-    }
-  }
-}
-// end RTC play code
-
-static int set_var_thresh_from_histogram(VP9_COMP *cpi) {
-  const SPEED_FEATURES *const sf = &cpi->sf;
-  const VP9_COMMON *const cm = &cpi->common;
-
-  const uint8_t *src = cpi->Source->y_buffer;
-  const uint8_t *last_src = cpi->Last_Source->y_buffer;
-  const int src_stride = cpi->Source->y_stride;
-  const int last_stride = cpi->Last_Source->y_stride;
-
-  // Pick cutoff threshold
-  const int cutoff = (VPXMIN(cm->width, cm->height) >= 720) ?
-      (cm->MBs * VAR_HIST_LARGE_CUT_OFF / 100) :
-      (cm->MBs * VAR_HIST_SMALL_CUT_OFF / 100);
-  DECLARE_ALIGNED(16, int, hist[VAR_HIST_BINS]);
-  diff *var16 = cpi->source_diff_var;
-
-  int sum = 0;
-  int i, j;
-
-  memset(hist, 0, VAR_HIST_BINS * sizeof(hist[0]));
-
-  for (i = 0; i < cm->mb_rows; i++) {
-    for (j = 0; j < cm->mb_cols; j++) {
-#if CONFIG_VP9_HIGHBITDEPTH
-      if (cm->use_highbitdepth) {
-        switch (cm->bit_depth) {
-          case VPX_BITS_8:
-            vpx_highbd_8_get16x16var(src, src_stride, last_src, last_stride,
-                                   &var16->sse, &var16->sum);
-            break;
-          case VPX_BITS_10:
-            vpx_highbd_10_get16x16var(src, src_stride, last_src, last_stride,
-                                    &var16->sse, &var16->sum);
-            break;
-          case VPX_BITS_12:
-            vpx_highbd_12_get16x16var(src, src_stride, last_src, last_stride,
-                                      &var16->sse, &var16->sum);
-            break;
-          default:
-            assert(0 && "cm->bit_depth should be VPX_BITS_8, VPX_BITS_10"
-                   " or VPX_BITS_12");
-            return -1;
-        }
-      } else {
-        vpx_get16x16var(src, src_stride, last_src, last_stride,
-                        &var16->sse, &var16->sum);
-      }
-#else
-      vpx_get16x16var(src, src_stride, last_src, last_stride,
-                      &var16->sse, &var16->sum);
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-      var16->var = var16->sse -
-          (((uint32_t)var16->sum * var16->sum) >> 8);
-
-      if (var16->var >= VAR_HIST_MAX_BG_VAR)
-        hist[VAR_HIST_BINS - 1]++;
-      else
-        hist[var16->var / VAR_HIST_FACTOR]++;
-
-      src += 16;
-      last_src += 16;
-      var16++;
-    }
-
-    src = src - cm->mb_cols * 16 + 16 * src_stride;
-    last_src = last_src - cm->mb_cols * 16 + 16 * last_stride;
-  }
-
-  cpi->source_var_thresh = 0;
-
-  if (hist[VAR_HIST_BINS - 1] < cutoff) {
-    for (i = 0; i < VAR_HIST_BINS - 1; i++) {
-      sum += hist[i];
-
-      if (sum > cutoff) {
-        cpi->source_var_thresh = (i + 1) * VAR_HIST_FACTOR;
-        return 0;
-      }
-    }
-  }
-
-  return sf->search_type_check_frequency;
-}
-
-static void source_var_based_partition_search_method(VP9_COMP *cpi) {
-  VP9_COMMON *const cm = &cpi->common;
-  SPEED_FEATURES *const sf = &cpi->sf;
-
-  if (cm->frame_type == KEY_FRAME) {
-    // For key frame, use SEARCH_PARTITION.
-    sf->partition_search_type = SEARCH_PARTITION;
-  } else if (cm->intra_only) {
-    sf->partition_search_type = FIXED_PARTITION;
-  } else {
-    if (cm->last_width != cm->width || cm->last_height != cm->height) {
-      if (cpi->source_diff_var)
-        vpx_free(cpi->source_diff_var);
-
-      CHECK_MEM_ERROR(cm, cpi->source_diff_var,
-                      vpx_calloc(cm->MBs, sizeof(diff)));
-    }
-
-    if (!cpi->frames_till_next_var_check)
-      cpi->frames_till_next_var_check = set_var_thresh_from_histogram(cpi);
-
-    if (cpi->frames_till_next_var_check > 0) {
-      sf->partition_search_type = FIXED_PARTITION;
-      cpi->frames_till_next_var_check--;
-    }
-  }
-}
-
-static int get_skip_encode_frame(const VP9_COMMON *cm, ThreadData *const td) {
-  unsigned int intra_count = 0, inter_count = 0;
-  int j;
-
-  for (j = 0; j < INTRA_INTER_CONTEXTS; ++j) {
-    intra_count += td->counts->intra_inter[j][0];
-    inter_count += td->counts->intra_inter[j][1];
-  }
-
-  return (intra_count << 2) < inter_count &&
-         cm->frame_type != KEY_FRAME &&
-         cm->show_frame;
-}
-
-void vp9_init_tile_data(VP9_COMP *cpi) {
-  VP9_COMMON *const cm = &cpi->common;
-  const int tile_cols = 1 << cm->log2_tile_cols;
-  const int tile_rows = 1 << cm->log2_tile_rows;
-  int tile_col, tile_row;
-  TOKENEXTRA *pre_tok = cpi->tile_tok[0][0];
-  int tile_tok = 0;
-
-  if (cpi->tile_data == NULL || cpi->allocated_tiles < tile_cols * tile_rows) {
-    if (cpi->tile_data != NULL)
-      vpx_free(cpi->tile_data);
-    CHECK_MEM_ERROR(cm, cpi->tile_data,
-        vpx_malloc(tile_cols * tile_rows * sizeof(*cpi->tile_data)));
-    cpi->allocated_tiles = tile_cols * tile_rows;
-
-    for (tile_row = 0; tile_row < tile_rows; ++tile_row)
-      for (tile_col = 0; tile_col < tile_cols; ++tile_col) {
-        TileDataEnc *tile_data =
-            &cpi->tile_data[tile_row * tile_cols + tile_col];
-        int i, j;
-        for (i = 0; i < BLOCK_SIZES; ++i) {
-          for (j = 0; j < MAX_MODES; ++j) {
-            tile_data->thresh_freq_fact[i][j] = 32;
-            tile_data->mode_map[i][j] = j;
-          }
-        }
-      }
-  }
-
-  for (tile_row = 0; tile_row < tile_rows; ++tile_row) {
-    for (tile_col = 0; tile_col < tile_cols; ++tile_col) {
-      TileInfo *tile_info =
-          &cpi->tile_data[tile_row * tile_cols + tile_col].tile_info;
-      vp9_tile_init(tile_info, cm, tile_row, tile_col);
-
-      cpi->tile_tok[tile_row][tile_col] = pre_tok + tile_tok;
-      pre_tok = cpi->tile_tok[tile_row][tile_col];
-      tile_tok = allocated_tokens(*tile_info);
-    }
-  }
-}
-
-void vp9_encode_tile(VP9_COMP *cpi, ThreadData *td,
-                     int tile_row, int tile_col) {
-  VP9_COMMON *const cm = &cpi->common;
-  const int tile_cols = 1 << cm->log2_tile_cols;
-  TileDataEnc *this_tile =
-      &cpi->tile_data[tile_row * tile_cols + tile_col];
-  const TileInfo * const tile_info = &this_tile->tile_info;
-  TOKENEXTRA *tok = cpi->tile_tok[tile_row][tile_col];
-  int mi_row;
-
-  // Set up pointers to per thread motion search counters.
-  td->mb.m_search_count_ptr = &td->rd_counts.m_search_count;
-  td->mb.ex_search_count_ptr = &td->rd_counts.ex_search_count;
-
-  for (mi_row = tile_info->mi_row_start; mi_row < tile_info->mi_row_end;
-       mi_row += MI_BLOCK_SIZE) {
-    if (cpi->sf.use_nonrd_pick_mode)
-      encode_nonrd_sb_row(cpi, td, this_tile, mi_row, &tok);
-    else
-      encode_rd_sb_row(cpi, td, this_tile, mi_row, &tok);
-  }
-  cpi->tok_count[tile_row][tile_col] =
-      (unsigned int)(tok - cpi->tile_tok[tile_row][tile_col]);
-  assert(tok - cpi->tile_tok[tile_row][tile_col] <=
-      allocated_tokens(*tile_info));
-}
-
-static void encode_tiles(VP9_COMP *cpi) {
-  VP9_COMMON *const cm = &cpi->common;
-  const int tile_cols = 1 << cm->log2_tile_cols;
-  const int tile_rows = 1 << cm->log2_tile_rows;
-  int tile_col, tile_row;
-
-  vp9_init_tile_data(cpi);
-
-  for (tile_row = 0; tile_row < tile_rows; ++tile_row)
-    for (tile_col = 0; tile_col < tile_cols; ++tile_col)
-      vp9_encode_tile(cpi, &cpi->td, tile_row, tile_col);
-}
-
-#if CONFIG_FP_MB_STATS
-static int input_fpmb_stats(FIRSTPASS_MB_STATS *firstpass_mb_stats,
-                            VP9_COMMON *cm, uint8_t **this_frame_mb_stats) {
-  uint8_t *mb_stats_in = firstpass_mb_stats->mb_stats_start +
-      cm->current_video_frame * cm->MBs * sizeof(uint8_t);
-
-  if (mb_stats_in > firstpass_mb_stats->mb_stats_end)
-    return EOF;
-
-  *this_frame_mb_stats = mb_stats_in;
-
-  return 1;
-}
-#endif
-
-static void encode_frame_internal(VP9_COMP *cpi) {
-  SPEED_FEATURES *const sf = &cpi->sf;
-  ThreadData *const td = &cpi->td;
-  MACROBLOCK *const x = &td->mb;
-  VP9_COMMON *const cm = &cpi->common;
-  MACROBLOCKD *const xd = &x->e_mbd;
-  RD_COUNTS *const rdc = &cpi->td.rd_counts;
-
-  xd->mi = cm->mi_grid_visible;
-  xd->mi[0] = cm->mi;
-
-  vp9_zero(*td->counts);
-  vp9_zero(rdc->coef_counts);
-  vp9_zero(rdc->comp_pred_diff);
-  vp9_zero(rdc->filter_diff);
-  rdc->m_search_count = 0;   // Count of motion search hits.
-  rdc->ex_search_count = 0;  // Exhaustive mesh search hits.
-
-  xd->lossless = cm->base_qindex == 0 &&
-                 cm->y_dc_delta_q == 0 &&
-                 cm->uv_dc_delta_q == 0 &&
-                 cm->uv_ac_delta_q == 0;
-
-#if CONFIG_VP9_HIGHBITDEPTH
-  if (cm->use_highbitdepth)
-    x->fwd_txm4x4 = xd->lossless ? vp9_highbd_fwht4x4 : vpx_highbd_fdct4x4;
-  else
-    x->fwd_txm4x4 = xd->lossless ? vp9_fwht4x4 : vpx_fdct4x4;
-  x->highbd_itxm_add = xd->lossless ? vp9_highbd_iwht4x4_add :
-                                      vp9_highbd_idct4x4_add;
-#else
-  x->fwd_txm4x4 = xd->lossless ? vp9_fwht4x4 : vpx_fdct4x4;
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-  x->itxm_add = xd->lossless ? vp9_iwht4x4_add : vp9_idct4x4_add;
-
-  if (xd->lossless)
-    x->optimize = 0;
-
-  cm->tx_mode = select_tx_mode(cpi, xd);
-
-  vp9_frame_init_quantizer(cpi);
-
-  vp9_initialize_rd_consts(cpi);
-  vp9_initialize_me_consts(cpi, x, cm->base_qindex);
-  init_encode_frame_mb_context(cpi);
-  cm->use_prev_frame_mvs = !cm->error_resilient_mode &&
-                           cm->width == cm->last_width &&
-                           cm->height == cm->last_height &&
-                           !cm->intra_only &&
-                           cm->last_show_frame;
-  // Special case: set prev_mi to NULL when the previous mode info
-  // context cannot be used.
-  cm->prev_mi = cm->use_prev_frame_mvs ?
-                cm->prev_mip + cm->mi_stride + 1 : NULL;
-
-  x->quant_fp = cpi->sf.use_quant_fp;
-  vp9_zero(x->skip_txfm);
-  if (sf->use_nonrd_pick_mode) {
-    // Initialize internal buffer pointers for rtc coding, where non-RD
-    // mode decision is used and hence no buffer pointer swap needed.
-    int i;
-    struct macroblock_plane *const p = x->plane;
-    struct macroblockd_plane *const pd = xd->plane;
-    PICK_MODE_CONTEXT *ctx = &cpi->td.pc_root->none;
-
-    for (i = 0; i < MAX_MB_PLANE; ++i) {
-      p[i].coeff = ctx->coeff_pbuf[i][0];
-      p[i].qcoeff = ctx->qcoeff_pbuf[i][0];
-      pd[i].dqcoeff = ctx->dqcoeff_pbuf[i][0];
-      p[i].eobs = ctx->eobs_pbuf[i][0];
-    }
-    vp9_zero(x->zcoeff_blk);
-
-    if (cm->frame_type != KEY_FRAME &&
-        cpi->rc.frames_since_golden == 0 &&
-        !cpi->use_svc)
-      cpi->ref_frame_flags &= (~VP9_GOLD_FLAG);
-
-    if (sf->partition_search_type == SOURCE_VAR_BASED_PARTITION)
-      source_var_based_partition_search_method(cpi);
-  }
-
-  {
-    struct vpx_usec_timer emr_timer;
-    vpx_usec_timer_start(&emr_timer);
-
-#if CONFIG_FP_MB_STATS
-  if (cpi->use_fp_mb_stats) {
-    input_fpmb_stats(&cpi->twopass.firstpass_mb_stats, cm,
-                     &cpi->twopass.this_frame_mb_stats);
-  }
-#endif
-
-    // If allowed, encoding tiles in parallel with one thread handling one tile.
-    if (VPXMIN(cpi->oxcf.max_threads, 1 << cm->log2_tile_cols) > 1)
-      vp9_encode_tiles_mt(cpi);
-    else
-      encode_tiles(cpi);
-
-    vpx_usec_timer_mark(&emr_timer);
-    cpi->time_encode_sb_row += vpx_usec_timer_elapsed(&emr_timer);
-  }
-
-  sf->skip_encode_frame = sf->skip_encode_sb ?
-      get_skip_encode_frame(cm, td) : 0;
-
-#if 0
-  // Keep record of the total distortion this time around for future use
-  cpi->last_frame_distortion = cpi->frame_distortion;
-#endif
-}
-
-static INTERP_FILTER get_interp_filter(
-    const int64_t threshes[SWITCHABLE_FILTER_CONTEXTS], int is_alt_ref) {
-  if (!is_alt_ref &&
-      threshes[EIGHTTAP_SMOOTH] > threshes[EIGHTTAP] &&
-      threshes[EIGHTTAP_SMOOTH] > threshes[EIGHTTAP_SHARP] &&
-      threshes[EIGHTTAP_SMOOTH] > threshes[SWITCHABLE - 1]) {
-    return EIGHTTAP_SMOOTH;
-  } else if (threshes[EIGHTTAP_SHARP] > threshes[EIGHTTAP] &&
-             threshes[EIGHTTAP_SHARP] > threshes[SWITCHABLE - 1]) {
-    return EIGHTTAP_SHARP;
-  } else if (threshes[EIGHTTAP] > threshes[SWITCHABLE - 1]) {
-    return EIGHTTAP;
-  } else {
-    return SWITCHABLE;
-  }
-}
-
-static int compute_frame_aq_offset(struct VP9_COMP *cpi) {
-  VP9_COMMON *const cm = &cpi->common;
-  MODE_INFO **mi_8x8_ptr = cm->mi_grid_visible;
-  struct segmentation *const seg = &cm->seg;
-
-  int mi_row, mi_col;
-  int sum_delta = 0;
-  int map_index = 0;
-  int qdelta_index;
-  int segment_id;
-
-  for (mi_row = 0; mi_row < cm->mi_rows; mi_row++) {
-    MODE_INFO **mi_8x8 = mi_8x8_ptr;
-    for (mi_col = 0; mi_col < cm->mi_cols; mi_col++, mi_8x8++) {
-      segment_id = mi_8x8[0]->segment_id;
-      qdelta_index = get_segdata(seg, segment_id, SEG_LVL_ALT_Q);
-      sum_delta += qdelta_index;
-      map_index++;
-    }
-    mi_8x8_ptr += cm->mi_stride;
-  }
-
-  return sum_delta / (cm->mi_rows * cm->mi_cols);
-}
-
-void vp9_encode_frame(VP9_COMP *cpi) {
-  VP9_COMMON *const cm = &cpi->common;
-
-  // In the longer term the encoder should be generalized to match the
-  // decoder such that we allow compound where one of the 3 buffers has a
-  // different sign bias and that buffer is then the fixed ref. However, this
-  // requires further work in the rd loop. For now the only supported encoder
-  // side behavior is where the ALT ref buffer has opposite sign bias to
-  // the other two.
-  if (!frame_is_intra_only(cm)) {
-    if ((cm->ref_frame_sign_bias[ALTREF_FRAME] ==
-             cm->ref_frame_sign_bias[GOLDEN_FRAME]) ||
-        (cm->ref_frame_sign_bias[ALTREF_FRAME] ==
-             cm->ref_frame_sign_bias[LAST_FRAME])) {
-      cpi->allow_comp_inter_inter = 0;
-    } else {
-      cpi->allow_comp_inter_inter = 1;
-      cm->comp_fixed_ref = ALTREF_FRAME;
-      cm->comp_var_ref[0] = LAST_FRAME;
-      cm->comp_var_ref[1] = GOLDEN_FRAME;
-    }
-  }
-
-  if (cpi->sf.frame_parameter_update) {
-    int i;
-    RD_OPT *const rd_opt = &cpi->rd;
-    FRAME_COUNTS *counts = cpi->td.counts;
-    RD_COUNTS *const rdc = &cpi->td.rd_counts;
-
-    // This code does a single RD pass over the whole frame assuming
-    // either compound, single or hybrid prediction as per whatever has
-    // worked best for that type of frame in the past.
-    // It also predicts whether another coding mode would have worked
-    // better than this coding mode. If that is the case, it remembers
-    // that for subsequent frames.
-    // It does the same analysis for transform size selection also.
-    const MV_REFERENCE_FRAME frame_type = get_frame_type(cpi);
-    int64_t *const mode_thrs = rd_opt->prediction_type_threshes[frame_type];
-    int64_t *const filter_thrs = rd_opt->filter_threshes[frame_type];
-    const int is_alt_ref = frame_type == ALTREF_FRAME;
-
-    /* prediction (compound, single or hybrid) mode selection */
-    if (is_alt_ref || !cpi->allow_comp_inter_inter)
-      cm->reference_mode = SINGLE_REFERENCE;
-    else if (mode_thrs[COMPOUND_REFERENCE] > mode_thrs[SINGLE_REFERENCE] &&
-             mode_thrs[COMPOUND_REFERENCE] >
-                 mode_thrs[REFERENCE_MODE_SELECT] &&
-             check_dual_ref_flags(cpi) &&
-             cpi->static_mb_pct == 100)
-      cm->reference_mode = COMPOUND_REFERENCE;
-    else if (mode_thrs[SINGLE_REFERENCE] > mode_thrs[REFERENCE_MODE_SELECT])
-      cm->reference_mode = SINGLE_REFERENCE;
-    else
-      cm->reference_mode = REFERENCE_MODE_SELECT;
-
-    if (cm->interp_filter == SWITCHABLE)
-      cm->interp_filter = get_interp_filter(filter_thrs, is_alt_ref);
-
-    encode_frame_internal(cpi);
-
-    for (i = 0; i < REFERENCE_MODES; ++i)
-      mode_thrs[i] = (mode_thrs[i] + rdc->comp_pred_diff[i] / cm->MBs) / 2;
-
-    for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; ++i)
-      filter_thrs[i] = (filter_thrs[i] + rdc->filter_diff[i] / cm->MBs) / 2;
-
-    if (cm->reference_mode == REFERENCE_MODE_SELECT) {
-      int single_count_zero = 0;
-      int comp_count_zero = 0;
-
-      for (i = 0; i < COMP_INTER_CONTEXTS; i++) {
-        single_count_zero += counts->comp_inter[i][0];
-        comp_count_zero += counts->comp_inter[i][1];
-      }
-
-      if (comp_count_zero == 0) {
-        cm->reference_mode = SINGLE_REFERENCE;
-        vp9_zero(counts->comp_inter);
-      } else if (single_count_zero == 0) {
-        cm->reference_mode = COMPOUND_REFERENCE;
-        vp9_zero(counts->comp_inter);
-      }
-    }
-
-    if (cm->tx_mode == TX_MODE_SELECT) {
-      int count4x4 = 0;
-      int count8x8_lp = 0, count8x8_8x8p = 0;
-      int count16x16_16x16p = 0, count16x16_lp = 0;
-      int count32x32 = 0;
-
-      for (i = 0; i < TX_SIZE_CONTEXTS; ++i) {
-        count4x4 += counts->tx.p32x32[i][TX_4X4];
-        count4x4 += counts->tx.p16x16[i][TX_4X4];
-        count4x4 += counts->tx.p8x8[i][TX_4X4];
-
-        count8x8_lp += counts->tx.p32x32[i][TX_8X8];
-        count8x8_lp += counts->tx.p16x16[i][TX_8X8];
-        count8x8_8x8p += counts->tx.p8x8[i][TX_8X8];
-
-        count16x16_16x16p += counts->tx.p16x16[i][TX_16X16];
-        count16x16_lp += counts->tx.p32x32[i][TX_16X16];
-        count32x32 += counts->tx.p32x32[i][TX_32X32];
-      }
-      if (count4x4 == 0 && count16x16_lp == 0 && count16x16_16x16p == 0 &&
-          count32x32 == 0) {
-        cm->tx_mode = ALLOW_8X8;
-        reset_skip_tx_size(cm, TX_8X8);
-      } else if (count8x8_8x8p == 0 && count16x16_16x16p == 0 &&
-                 count8x8_lp == 0 && count16x16_lp == 0 && count32x32 == 0) {
-        cm->tx_mode = ONLY_4X4;
-        reset_skip_tx_size(cm, TX_4X4);
-      } else if (count8x8_lp == 0 && count16x16_lp == 0 && count4x4 == 0) {
-        cm->tx_mode = ALLOW_32X32;
-      } else if (count32x32 == 0 && count8x8_lp == 0 && count4x4 == 0) {
-        cm->tx_mode = ALLOW_16X16;
-        reset_skip_tx_size(cm, TX_16X16);
-      }
-    }
-  } else {
-    cm->reference_mode = SINGLE_REFERENCE;
-    encode_frame_internal(cpi);
-  }
-
-  // If segmentated AQ is enabled compute the average AQ weighting.
-  if (cm->seg.enabled && (cpi->oxcf.aq_mode != NO_AQ) &&
-      (cm->seg.update_map || cm->seg.update_data)) {
-    cm->seg.aq_av_offset = compute_frame_aq_offset(cpi);
-  }
-}
-static void sum_intra_stats(FRAME_COUNTS *counts, const MODE_INFO *mi) {
-  const PREDICTION_MODE y_mode = mi->mode;
-  const PREDICTION_MODE uv_mode = mi->uv_mode;
-  const BLOCK_SIZE bsize = mi->sb_type;
-
-  if (bsize < BLOCK_8X8) {
-    int idx, idy;
-    const int num_4x4_w = num_4x4_blocks_wide_lookup[bsize];
-    const int num_4x4_h = num_4x4_blocks_high_lookup[bsize];
-    for (idy = 0; idy < 2; idy += num_4x4_h)
-      for (idx = 0; idx < 2; idx += num_4x4_w)
-        ++counts->y_mode[0][mi->bmi[idy * 2 + idx].as_mode];
-  } else {
-    ++counts->y_mode[size_group_lookup[bsize]][y_mode];
-  }
-
-  ++counts->uv_mode[y_mode][uv_mode];
-}
-
-static void update_zeromv_cnt(VP9_COMP *const cpi,
-                              const MODE_INFO *const mi,
-                              int mi_row, int mi_col,
-                              BLOCK_SIZE bsize) {
-  const VP9_COMMON *const cm = &cpi->common;
-  MV mv = mi->mv[0].as_mv;
-  const int bw = num_8x8_blocks_wide_lookup[bsize];
-  const int bh = num_8x8_blocks_high_lookup[bsize];
-  const int xmis = VPXMIN(cm->mi_cols - mi_col, bw);
-  const int ymis = VPXMIN(cm->mi_rows - mi_row, bh);
-  const int block_index = mi_row * cm->mi_cols + mi_col;
-  int x, y;
-  for (y = 0; y < ymis; y++)
-    for (x = 0; x < xmis; x++) {
-      int map_offset = block_index + y * cm->mi_cols + x;
-      if (is_inter_block(mi) && mi->segment_id <= CR_SEGMENT_ID_BOOST2) {
-        if (abs(mv.row) < 8 && abs(mv.col) < 8) {
-          if (cpi->consec_zero_mv[map_offset] < 255)
-           cpi->consec_zero_mv[map_offset]++;
-        } else {
-          cpi->consec_zero_mv[map_offset] = 0;
-        }
-      }
-    }
-}
-
-static void encode_superblock(VP9_COMP *cpi, ThreadData *td,
-                              TOKENEXTRA **t, int output_enabled,
-                              int mi_row, int mi_col, BLOCK_SIZE bsize,
-                              PICK_MODE_CONTEXT *ctx) {
-  VP9_COMMON *const cm = &cpi->common;
-  MACROBLOCK *const x = &td->mb;
-  MACROBLOCKD *const xd = &x->e_mbd;
-  MODE_INFO *mi = xd->mi[0];
-  const int seg_skip = segfeature_active(&cm->seg, mi->segment_id,
-                                         SEG_LVL_SKIP);
-
-  x->skip_recode = !x->select_tx_size && mi->sb_type >= BLOCK_8X8 &&
-                   cpi->oxcf.aq_mode != COMPLEXITY_AQ &&
-                   cpi->oxcf.aq_mode != CYCLIC_REFRESH_AQ &&
-                   cpi->sf.allow_skip_recode;
-
-  if (!x->skip_recode && !cpi->sf.use_nonrd_pick_mode)
-    memset(x->skip_txfm, 0, sizeof(x->skip_txfm));
-
-  x->skip_optimize = ctx->is_coded;
-  ctx->is_coded = 1;
-  x->use_lp32x32fdct = cpi->sf.use_lp32x32fdct;
-  x->skip_encode = (!output_enabled && cpi->sf.skip_encode_frame &&
-                    x->q_index < QIDX_SKIP_THRESH);
-
-  if (x->skip_encode)
-    return;
-
-  if (!is_inter_block(mi)) {
-    int plane;
-#if CONFIG_BETTER_HW_COMPATIBILITY && CONFIG_VP9_HIGHBITDEPTH
-    if ((xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) &&
-        (xd->above_mi == NULL || xd->left_mi == NULL) &&
-        need_top_left[mi->uv_mode])
-      assert(0);
-#endif  // CONFIG_BETTER_HW_COMPATIBILITY && CONFIG_VP9_HIGHBITDEPTH
-    mi->skip = 1;
-    for (plane = 0; plane < MAX_MB_PLANE; ++plane)
-      vp9_encode_intra_block_plane(x, VPXMAX(bsize, BLOCK_8X8), plane, 1);
-    if (output_enabled)
-      sum_intra_stats(td->counts, mi);
-    vp9_tokenize_sb(cpi, td, t, !output_enabled, seg_skip,
-                    VPXMAX(bsize, BLOCK_8X8));
-  } else {
-    int ref;
-    const int is_compound = has_second_ref(mi);
-    set_ref_ptrs(cm, xd, mi->ref_frame[0], mi->ref_frame[1]);
-    for (ref = 0; ref < 1 + is_compound; ++ref) {
-      YV12_BUFFER_CONFIG *cfg = get_ref_frame_buffer(cpi,
-                                                     mi->ref_frame[ref]);
-      assert(cfg != NULL);
-      vp9_setup_pre_planes(xd, ref, cfg, mi_row, mi_col,
-                           &xd->block_refs[ref]->sf);
-    }
-    if (!(cpi->sf.reuse_inter_pred_sby && ctx->pred_pixel_ready) || seg_skip)
-      vp9_build_inter_predictors_sby(xd, mi_row, mi_col,
-                                     VPXMAX(bsize, BLOCK_8X8));
-
-    vp9_build_inter_predictors_sbuv(xd, mi_row, mi_col,
-                                    VPXMAX(bsize, BLOCK_8X8));
-
-    vp9_encode_sb(x, VPXMAX(bsize, BLOCK_8X8));
-    vp9_tokenize_sb(cpi, td, t, !output_enabled, seg_skip,
-                    VPXMAX(bsize, BLOCK_8X8));
-  }
-
-  if (output_enabled) {
-    if (cm->tx_mode == TX_MODE_SELECT &&
-        mi->sb_type >= BLOCK_8X8  &&
-        !(is_inter_block(mi) && (mi->skip || seg_skip))) {
-      ++get_tx_counts(max_txsize_lookup[bsize], get_tx_size_context(xd),
-                      &td->counts->tx)[mi->tx_size];
-    } else {
-      // The new intra coding scheme requires no change of transform size
-      if (is_inter_block(mi)) {
-        mi->tx_size = VPXMIN(tx_mode_to_biggest_tx_size[cm->tx_mode],
-                             max_txsize_lookup[bsize]);
-      } else {
-        mi->tx_size = (bsize >= BLOCK_8X8) ? mi->tx_size : TX_4X4;
-      }
-
-    }
-    ++td->counts->tx.tx_totals[mi->tx_size];
-    ++td->counts->tx.tx_totals[get_uv_tx_size(mi, &xd->plane[1])];
-    if (cm->seg.enabled && cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ)
-      vp9_cyclic_refresh_update_sb_postencode(cpi, mi, mi_row, mi_col, bsize);
-    if (cpi->oxcf.pass == 0 && cpi->svc.temporal_layer_id == 0)
-      update_zeromv_cnt(cpi, mi, mi_row, mi_col, bsize);
-  }
-}
diff --git a/vp9/encoder/vp9_encodeframe.h b/vp9/encoder/vp9_encodeframe.h
deleted file mode 100644 (file)
index 6aaa564..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#ifndef VP9_ENCODER_VP9_ENCODEFRAME_H_
-#define VP9_ENCODER_VP9_ENCODEFRAME_H_
-
-#include "vpx/vpx_integer.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-struct macroblock;
-struct yv12_buffer_config;
-struct VP9_COMP;
-struct ThreadData;
-
-// Constants used in SOURCE_VAR_BASED_PARTITION
-#define VAR_HIST_MAX_BG_VAR 1000
-#define VAR_HIST_FACTOR 10
-#define VAR_HIST_BINS (VAR_HIST_MAX_BG_VAR / VAR_HIST_FACTOR + 1)
-#define VAR_HIST_LARGE_CUT_OFF 75
-#define VAR_HIST_SMALL_CUT_OFF 45
-
-void vp9_setup_src_planes(struct macroblock *x,
-                          const struct yv12_buffer_config *src,
-                          int mi_row, int mi_col);
-
-void vp9_encode_frame(struct VP9_COMP *cpi);
-
-void vp9_init_tile_data(struct VP9_COMP *cpi);
-void vp9_encode_tile(struct VP9_COMP *cpi, struct ThreadData *td,
-                     int tile_row, int tile_col);
-
-void vp9_set_variance_partition_thresholds(struct VP9_COMP *cpi, int q);
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP9_ENCODER_VP9_ENCODEFRAME_H_
diff --git a/vp9/encoder/vp9_encodemb.c b/vp9/encoder/vp9_encodemb.c
deleted file mode 100644 (file)
index fdf403e..0000000
+++ /dev/null
@@ -1,1020 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#include "./vp9_rtcd.h"
-#include "./vpx_config.h"
-#include "./vpx_dsp_rtcd.h"
-
-#include "vpx_dsp/quantize.h"
-#include "vpx_mem/vpx_mem.h"
-#include "vpx_ports/mem.h"
-
-#include "vp9/common/vp9_idct.h"
-#include "vp9/common/vp9_reconinter.h"
-#include "vp9/common/vp9_reconintra.h"
-#include "vp9/common/vp9_scan.h"
-
-#include "vp9/encoder/vp9_encodemb.h"
-#include "vp9/encoder/vp9_rd.h"
-#include "vp9/encoder/vp9_tokenize.h"
-
-struct optimize_ctx {
-  ENTROPY_CONTEXT ta[MAX_MB_PLANE][16];
-  ENTROPY_CONTEXT tl[MAX_MB_PLANE][16];
-};
-
-void vp9_subtract_plane(MACROBLOCK *x, BLOCK_SIZE bsize, int plane) {
-  struct macroblock_plane *const p = &x->plane[plane];
-  const struct macroblockd_plane *const pd = &x->e_mbd.plane[plane];
-  const BLOCK_SIZE plane_bsize = get_plane_block_size(bsize, pd);
-  const int bw = 4 * num_4x4_blocks_wide_lookup[plane_bsize];
-  const int bh = 4 * num_4x4_blocks_high_lookup[plane_bsize];
-
-#if CONFIG_VP9_HIGHBITDEPTH
-  if (x->e_mbd.cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
-    vpx_highbd_subtract_block(bh, bw, p->src_diff, bw, p->src.buf,
-                              p->src.stride, pd->dst.buf, pd->dst.stride,
-                              x->e_mbd.bd);
-    return;
-  }
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-  vpx_subtract_block(bh, bw, p->src_diff, bw, p->src.buf, p->src.stride,
-                     pd->dst.buf, pd->dst.stride);
-}
-
-// TODO(aconverse): Re-pack this structure.
-typedef struct vp9_token_state {
-  int           rate;
-  int64_t       error;
-  int           next;
-  int16_t       token;
-  tran_low_t    qc;
-  tran_low_t    dqc;
-} vp9_token_state;
-
-static const int plane_rd_mult[REF_TYPES][PLANE_TYPES] ={ {10, 6}, {8, 7}, };
-
-#define UPDATE_RD_COST()\
-{\
-  rd_cost0 = RDCOST(rdmult, rddiv, rate0, error0);\
-  rd_cost1 = RDCOST(rdmult, rddiv, rate1, error1);\
-}
-
-// This function is a place holder for now but may ultimately need
-// to scan previous tokens to work out the correct context.
-static int trellis_get_coeff_context(const int16_t *scan,
-                                     const int16_t *nb,
-                                     int idx, int token,
-                                     uint8_t *token_cache) {
-  int bak = token_cache[scan[idx]], pt;
-  token_cache[scan[idx]] = vp9_pt_energy_class[token];
-  pt = get_coef_context(nb, token_cache, idx + 1);
-  token_cache[scan[idx]] = bak;
-  return pt;
-}
-
-static int optimize_b(MACROBLOCK *mb, int plane, int block,
-                      TX_SIZE tx_size, int ctx) {
-  MACROBLOCKD *const xd = &mb->e_mbd;
-  struct macroblock_plane *const p = &mb->plane[plane];
-  struct macroblockd_plane *const pd = &xd->plane[plane];
-  const int ref = is_inter_block(xd->mi[0]);
-  vp9_token_state tokens[1025][2];
-  unsigned best_index[1025][2];
-  uint8_t token_cache[1024];
-  const tran_low_t *const coeff = BLOCK_OFFSET(mb->plane[plane].coeff, block);
-  tran_low_t *const qcoeff = BLOCK_OFFSET(p->qcoeff, block);
-  tran_low_t *const dqcoeff = BLOCK_OFFSET(pd->dqcoeff, block);
-  const int eob = p->eobs[block];
-  const PLANE_TYPE type = get_plane_type(plane);
-  const int default_eob = 16 << (tx_size << 1);
-  const int shift = (tx_size == TX_32X32);
-  const int16_t* const dequant_ptr = pd->dequant;
-  const uint8_t* const band_translate = get_band_translate(tx_size);
-  const scan_order *const so = get_scan(xd, tx_size, type, block);
-  const int16_t *const scan = so->scan;
-  const int16_t *const nb = so->neighbors;
-  const int dq_step[2] = { dequant_ptr[0] >> shift, dequant_ptr[1] >> shift };
-  int next = eob, sz = 0;
-  const int64_t rdmult = (mb->rdmult * plane_rd_mult[ref][type]) >> 1;
-  const int64_t rddiv = mb->rddiv;
-  int64_t rd_cost0, rd_cost1;
-  int rate0, rate1;
-  int64_t error0, error1;
-  int16_t t0, t1;
-  EXTRABIT e0;
-  int best, band, pt, i, final_eob;
-#if CONFIG_VP9_HIGHBITDEPTH
-  const int *cat6_high_cost = vp9_get_high_cost_table(xd->bd);
-#else
-  const int *cat6_high_cost = vp9_get_high_cost_table(8);
-#endif
-
-  assert((!type && !plane) || (type && plane));
-  assert(eob <= default_eob);
-
-  /* Now set up a Viterbi trellis to evaluate alternative roundings. */
-  /* Initialize the sentinel node of the trellis. */
-  tokens[eob][0].rate = 0;
-  tokens[eob][0].error = 0;
-  tokens[eob][0].next = default_eob;
-  tokens[eob][0].token = EOB_TOKEN;
-  tokens[eob][0].qc = 0;
-  tokens[eob][1] = tokens[eob][0];
-
-  for (i = 0; i < eob; i++)
-    token_cache[scan[i]] =
-        vp9_pt_energy_class[vp9_get_token(qcoeff[scan[i]])];
-
-  for (i = eob; i-- > 0;) {
-    int base_bits, d2, dx;
-    const int rc = scan[i];
-    int x = qcoeff[rc];
-    /* Only add a trellis state for non-zero coefficients. */
-    if (x) {
-      int shortcut = 0;
-      error0 = tokens[next][0].error;
-      error1 = tokens[next][1].error;
-      /* Evaluate the first possibility for this state. */
-      rate0 = tokens[next][0].rate;
-      rate1 = tokens[next][1].rate;
-      vp9_get_token_extra(x, &t0, &e0);
-      /* Consider both possible successor states. */
-      if (next < default_eob) {
-        band = band_translate[i + 1];
-        pt = trellis_get_coeff_context(scan, nb, i, t0, token_cache);
-        rate0 += mb->token_costs[tx_size][type][ref][band][0][pt]
-                                [tokens[next][0].token];
-        rate1 += mb->token_costs[tx_size][type][ref][band][0][pt]
-                                [tokens[next][1].token];
-      }
-      UPDATE_RD_COST();
-      /* And pick the best. */
-      best = rd_cost1 < rd_cost0;
-      base_bits = vp9_get_cost(t0, e0, cat6_high_cost);
-      dx = (dqcoeff[rc] - coeff[rc]) * (1 << shift);
-#if CONFIG_VP9_HIGHBITDEPTH
-      if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
-        dx >>= xd->bd - 8;
-      }
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-      d2 = dx * dx;
-      tokens[i][0].rate = base_bits + (best ? rate1 : rate0);
-      tokens[i][0].error = d2 + (best ? error1 : error0);
-      tokens[i][0].next = next;
-      tokens[i][0].token = t0;
-      tokens[i][0].qc = x;
-      tokens[i][0].dqc = dqcoeff[rc];
-      best_index[i][0] = best;
-
-      /* Evaluate the second possibility for this state. */
-      rate0 = tokens[next][0].rate;
-      rate1 = tokens[next][1].rate;
-
-      if ((abs(x) * dequant_ptr[rc != 0] > (abs(coeff[rc]) << shift)) &&
-          (abs(x) * dequant_ptr[rc != 0] < (abs(coeff[rc]) << shift) +
-                                               dequant_ptr[rc != 0]))
-        shortcut = 1;
-      else
-        shortcut = 0;
-
-      if (shortcut) {
-        sz = -(x < 0);
-        x -= 2 * sz + 1;
-      } else {
-        tokens[i][1] = tokens[i][0];
-        best_index[i][1] = best_index[i][0];
-        next = i;
-        continue;
-      }
-
-      /* Consider both possible successor states. */
-      if (!x) {
-        /* If we reduced this coefficient to zero, check to see if
-         *  we need to move the EOB back here.
-         */
-        t0 = tokens[next][0].token == EOB_TOKEN ? EOB_TOKEN : ZERO_TOKEN;
-        t1 = tokens[next][1].token == EOB_TOKEN ? EOB_TOKEN : ZERO_TOKEN;
-        e0 = 0;
-      } else {
-        vp9_get_token_extra(x, &t0, &e0);
-        t1 = t0;
-      }
-      if (next < default_eob) {
-        band = band_translate[i + 1];
-        if (t0 != EOB_TOKEN) {
-          pt = trellis_get_coeff_context(scan, nb, i, t0, token_cache);
-          rate0 += mb->token_costs[tx_size][type][ref][band][!x][pt]
-                                  [tokens[next][0].token];
-        }
-        if (t1 != EOB_TOKEN) {
-          pt = trellis_get_coeff_context(scan, nb, i, t1, token_cache);
-          rate1 += mb->token_costs[tx_size][type][ref][band][!x][pt]
-                                  [tokens[next][1].token];
-        }
-      }
-
-      UPDATE_RD_COST();
-      /* And pick the best. */
-      best = rd_cost1 < rd_cost0;
-      base_bits = vp9_get_cost(t0, e0, cat6_high_cost);
-
-      if (shortcut) {
-#if CONFIG_VP9_HIGHBITDEPTH
-        if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
-          dx -= ((dequant_ptr[rc != 0] >> (xd->bd - 8)) + sz) ^ sz;
-        } else {
-          dx -= (dequant_ptr[rc != 0] + sz) ^ sz;
-        }
-#else
-        dx -= (dequant_ptr[rc != 0] + sz) ^ sz;
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-        d2 = dx * dx;
-      }
-      tokens[i][1].rate = base_bits + (best ? rate1 : rate0);
-      tokens[i][1].error = d2 + (best ? error1 : error0);
-      tokens[i][1].next = next;
-      tokens[i][1].token = best ? t1 : t0;
-      tokens[i][1].qc = x;
-
-      if (x) {
-        tran_low_t offset = dq_step[rc != 0];
-        // The 32x32 transform coefficient uses half quantization step size.
-        // Account for the rounding difference in the dequantized coefficeint
-        // value when the quantization index is dropped from an even number
-        // to an odd number.
-        if (shift & x)
-          offset += (dequant_ptr[rc != 0] & 0x01);
-
-        if (sz == 0)
-          tokens[i][1].dqc = dqcoeff[rc] - offset;
-        else
-          tokens[i][1].dqc = dqcoeff[rc] + offset;
-      } else {
-        tokens[i][1].dqc = 0;
-      }
-
-      best_index[i][1] = best;
-      /* Finally, make this the new head of the trellis. */
-      next = i;
-    } else {
-      /* There's no choice to make for a zero coefficient, so we don't
-       *  add a new trellis node, but we do need to update the costs.
-       */
-      band = band_translate[i + 1];
-      t0 = tokens[next][0].token;
-      t1 = tokens[next][1].token;
-      /* Update the cost of each path if we're past the EOB token. */
-      if (t0 != EOB_TOKEN) {
-        tokens[next][0].rate +=
-            mb->token_costs[tx_size][type][ref][band][1][0][t0];
-        tokens[next][0].token = ZERO_TOKEN;
-      }
-      if (t1 != EOB_TOKEN) {
-        tokens[next][1].rate +=
-            mb->token_costs[tx_size][type][ref][band][1][0][t1];
-        tokens[next][1].token = ZERO_TOKEN;
-      }
-      best_index[i][0] = best_index[i][1] = 0;
-      /* Don't update next, because we didn't add a new node. */
-    }
-  }
-
-  /* Now pick the best path through the whole trellis. */
-  band = band_translate[i + 1];
-  rate0 = tokens[next][0].rate;
-  rate1 = tokens[next][1].rate;
-  error0 = tokens[next][0].error;
-  error1 = tokens[next][1].error;
-  t0 = tokens[next][0].token;
-  t1 = tokens[next][1].token;
-  rate0 += mb->token_costs[tx_size][type][ref][band][0][ctx][t0];
-  rate1 += mb->token_costs[tx_size][type][ref][band][0][ctx][t1];
-  UPDATE_RD_COST();
-  best = rd_cost1 < rd_cost0;
-  final_eob = -1;
-
-  for (i = next; i < eob; i = next) {
-    const int x = tokens[i][best].qc;
-    const int rc = scan[i];
-    if (x) final_eob = i;
-    qcoeff[rc] = x;
-    dqcoeff[rc] = tokens[i][best].dqc;
-    next = tokens[i][best].next;
-    best = best_index[i][best];
-  }
-  final_eob++;
-
-  mb->plane[plane].eobs[block] = final_eob;
-  return final_eob;
-}
-
-static INLINE void fdct32x32(int rd_transform,
-                             const int16_t *src, tran_low_t *dst,
-                             int src_stride) {
-  if (rd_transform)
-    vpx_fdct32x32_rd(src, dst, src_stride);
-  else
-    vpx_fdct32x32(src, dst, src_stride);
-}
-
-#if CONFIG_VP9_HIGHBITDEPTH
-static INLINE void highbd_fdct32x32(int rd_transform, const int16_t *src,
-                                    tran_low_t *dst, int src_stride) {
-  if (rd_transform)
-    vpx_highbd_fdct32x32_rd(src, dst, src_stride);
-  else
-    vpx_highbd_fdct32x32(src, dst, src_stride);
-}
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-
-void vp9_xform_quant_fp(MACROBLOCK *x, int plane, int block,
-                        BLOCK_SIZE plane_bsize, TX_SIZE tx_size) {
-  MACROBLOCKD *const xd = &x->e_mbd;
-  const struct macroblock_plane *const p = &x->plane[plane];
-  const struct macroblockd_plane *const pd = &xd->plane[plane];
-  const scan_order *const scan_order = &vp9_default_scan_orders[tx_size];
-  tran_low_t *const coeff = BLOCK_OFFSET(p->coeff, block);
-  tran_low_t *const qcoeff = BLOCK_OFFSET(p->qcoeff, block);
-  tran_low_t *const dqcoeff = BLOCK_OFFSET(pd->dqcoeff, block);
-  uint16_t *const eob = &p->eobs[block];
-  const int diff_stride = 4 * num_4x4_blocks_wide_lookup[plane_bsize];
-  int i, j;
-  const int16_t *src_diff;
-  txfrm_block_to_raster_xy(plane_bsize, tx_size, block, &i, &j);
-  src_diff = &p->src_diff[4 * (j * diff_stride + i)];
-
-#if CONFIG_VP9_HIGHBITDEPTH
-  if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
-    switch (tx_size) {
-      case TX_32X32:
-        highbd_fdct32x32(x->use_lp32x32fdct, src_diff, coeff, diff_stride);
-        vp9_highbd_quantize_fp_32x32(coeff, 1024, x->skip_block, p->zbin,
-                                     p->round_fp, p->quant_fp, p->quant_shift,
-                                     qcoeff, dqcoeff, pd->dequant,
-                                     eob, scan_order->scan,
-                                     scan_order->iscan);
-        break;
-      case TX_16X16:
-        vpx_highbd_fdct16x16(src_diff, coeff, diff_stride);
-        vp9_highbd_quantize_fp(coeff, 256, x->skip_block, p->zbin, p->round_fp,
-                               p->quant_fp, p->quant_shift, qcoeff, dqcoeff,
-                               pd->dequant, eob,
-                               scan_order->scan, scan_order->iscan);
-        break;
-      case TX_8X8:
-        vpx_highbd_fdct8x8(src_diff, coeff, diff_stride);
-        vp9_highbd_quantize_fp(coeff, 64, x->skip_block, p->zbin, p->round_fp,
-                               p->quant_fp, p->quant_shift, qcoeff, dqcoeff,
-                               pd->dequant, eob,
-                               scan_order->scan, scan_order->iscan);
-        break;
-      case TX_4X4:
-        x->fwd_txm4x4(src_diff, coeff, diff_stride);
-        vp9_highbd_quantize_fp(coeff, 16, x->skip_block, p->zbin, p->round_fp,
-                               p->quant_fp, p->quant_shift, qcoeff, dqcoeff,
-                               pd->dequant, eob,
-                               scan_order->scan, scan_order->iscan);
-        break;
-      default:
-        assert(0);
-    }
-    return;
-  }
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-
-  switch (tx_size) {
-    case TX_32X32:
-      fdct32x32(x->use_lp32x32fdct, src_diff, coeff, diff_stride);
-      vp9_quantize_fp_32x32(coeff, 1024, x->skip_block, p->zbin, p->round_fp,
-                            p->quant_fp, p->quant_shift, qcoeff, dqcoeff,
-                            pd->dequant, eob, scan_order->scan,
-                            scan_order->iscan);
-      break;
-    case TX_16X16:
-      vpx_fdct16x16(src_diff, coeff, diff_stride);
-      vp9_quantize_fp(coeff, 256, x->skip_block, p->zbin, p->round_fp,
-                      p->quant_fp, p->quant_shift, qcoeff, dqcoeff,
-                      pd->dequant, eob,
-                      scan_order->scan, scan_order->iscan);
-      break;
-    case TX_8X8:
-      vp9_fdct8x8_quant(src_diff, diff_stride, coeff, 64,
-                        x->skip_block, p->zbin, p->round_fp,
-                        p->quant_fp, p->quant_shift, qcoeff, dqcoeff,
-                        pd->dequant, eob,
-                        scan_order->scan, scan_order->iscan);
-      break;
-    case TX_4X4:
-      x->fwd_txm4x4(src_diff, coeff, diff_stride);
-      vp9_quantize_fp(coeff, 16, x->skip_block, p->zbin, p->round_fp,
-                      p->quant_fp, p->quant_shift, qcoeff, dqcoeff,
-                      pd->dequant, eob,
-                      scan_order->scan, scan_order->iscan);
-      break;
-    default:
-      assert(0);
-      break;
-  }
-}
-
-void vp9_xform_quant_dc(MACROBLOCK *x, int plane, int block,
-                        BLOCK_SIZE plane_bsize, TX_SIZE tx_size) {
-  MACROBLOCKD *const xd = &x->e_mbd;
-  const struct macroblock_plane *const p = &x->plane[plane];
-  const struct macroblockd_plane *const pd = &xd->plane[plane];
-  tran_low_t *const coeff = BLOCK_OFFSET(p->coeff, block);
-  tran_low_t *const qcoeff = BLOCK_OFFSET(p->qcoeff, block);
-  tran_low_t *const dqcoeff = BLOCK_OFFSET(pd->dqcoeff, block);
-  uint16_t *const eob = &p->eobs[block];
-  const int diff_stride = 4 * num_4x4_blocks_wide_lookup[plane_bsize];
-  int i, j;
-  const int16_t *src_diff;
-
-  txfrm_block_to_raster_xy(plane_bsize, tx_size, block, &i, &j);
-  src_diff = &p->src_diff[4 * (j * diff_stride + i)];
-
-#if CONFIG_VP9_HIGHBITDEPTH
-  if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
-    switch (tx_size) {
-      case TX_32X32:
-        vpx_highbd_fdct32x32_1(src_diff, coeff, diff_stride);
-        vpx_highbd_quantize_dc_32x32(coeff, x->skip_block, p->round,
-                                     p->quant_fp[0], qcoeff, dqcoeff,
-                                     pd->dequant[0], eob);
-        break;
-      case TX_16X16:
-        vpx_highbd_fdct16x16_1(src_diff, coeff, diff_stride);
-        vpx_highbd_quantize_dc(coeff, 256, x->skip_block, p->round,
-                               p->quant_fp[0], qcoeff, dqcoeff,
-                               pd->dequant[0], eob);
-        break;
-      case TX_8X8:
-        vpx_highbd_fdct8x8_1(src_diff, coeff, diff_stride);
-        vpx_highbd_quantize_dc(coeff, 64, x->skip_block, p->round,
-                               p->quant_fp[0], qcoeff, dqcoeff,
-                               pd->dequant[0], eob);
-        break;
-      case TX_4X4:
-        x->fwd_txm4x4(src_diff, coeff, diff_stride);
-        vpx_highbd_quantize_dc(coeff, 16, x->skip_block, p->round,
-                               p->quant_fp[0], qcoeff, dqcoeff,
-                               pd->dequant[0], eob);
-        break;
-      default:
-        assert(0);
-    }
-    return;
-  }
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-
-  switch (tx_size) {
-    case TX_32X32:
-      vpx_fdct32x32_1(src_diff, coeff, diff_stride);
-      vpx_quantize_dc_32x32(coeff, x->skip_block, p->round,
-                            p->quant_fp[0], qcoeff, dqcoeff,
-                            pd->dequant[0], eob);
-      break;
-    case TX_16X16:
-      vpx_fdct16x16_1(src_diff, coeff, diff_stride);
-      vpx_quantize_dc(coeff, 256, x->skip_block, p->round,
-                     p->quant_fp[0], qcoeff, dqcoeff,
-                     pd->dequant[0], eob);
-      break;
-    case TX_8X8:
-      vpx_fdct8x8_1(src_diff, coeff, diff_stride);
-      vpx_quantize_dc(coeff, 64, x->skip_block, p->round,
-                      p->quant_fp[0], qcoeff, dqcoeff,
-                      pd->dequant[0], eob);
-      break;
-    case TX_4X4:
-      x->fwd_txm4x4(src_diff, coeff, diff_stride);
-      vpx_quantize_dc(coeff, 16, x->skip_block, p->round,
-                      p->quant_fp[0], qcoeff, dqcoeff,
-                      pd->dequant[0], eob);
-      break;
-    default:
-      assert(0);
-      break;
-  }
-}
-
-void vp9_xform_quant(MACROBLOCK *x, int plane, int block,
-                     BLOCK_SIZE plane_bsize, TX_SIZE tx_size) {
-  MACROBLOCKD *const xd = &x->e_mbd;
-  const struct macroblock_plane *const p = &x->plane[plane];
-  const struct macroblockd_plane *const pd = &xd->plane[plane];
-  const scan_order *const scan_order = &vp9_default_scan_orders[tx_size];
-  tran_low_t *const coeff = BLOCK_OFFSET(p->coeff, block);
-  tran_low_t *const qcoeff = BLOCK_OFFSET(p->qcoeff, block);
-  tran_low_t *const dqcoeff = BLOCK_OFFSET(pd->dqcoeff, block);
-  uint16_t *const eob = &p->eobs[block];
-  const int diff_stride = 4 * num_4x4_blocks_wide_lookup[plane_bsize];
-  int i, j;
-  const int16_t *src_diff;
-  txfrm_block_to_raster_xy(plane_bsize, tx_size, block, &i, &j);
-  src_diff = &p->src_diff[4 * (j * diff_stride + i)];
-
-#if CONFIG_VP9_HIGHBITDEPTH
-  if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
-     switch (tx_size) {
-      case TX_32X32:
-        highbd_fdct32x32(x->use_lp32x32fdct, src_diff, coeff, diff_stride);
-        vpx_highbd_quantize_b_32x32(coeff, 1024, x->skip_block, p->zbin,
-                                    p->round, p->quant, p->quant_shift, qcoeff,
-                                    dqcoeff, pd->dequant, eob,
-                                    scan_order->scan, scan_order->iscan);
-        break;
-      case TX_16X16:
-        vpx_highbd_fdct16x16(src_diff, coeff, diff_stride);
-        vpx_highbd_quantize_b(coeff, 256, x->skip_block, p->zbin, p->round,
-                              p->quant, p->quant_shift, qcoeff, dqcoeff,
-                              pd->dequant, eob,
-                              scan_order->scan, scan_order->iscan);
-        break;
-      case TX_8X8:
-        vpx_highbd_fdct8x8(src_diff, coeff, diff_stride);
-        vpx_highbd_quantize_b(coeff, 64, x->skip_block, p->zbin, p->round,
-                              p->quant, p->quant_shift, qcoeff, dqcoeff,
-                              pd->dequant, eob,
-                              scan_order->scan, scan_order->iscan);
-        break;
-      case TX_4X4:
-        x->fwd_txm4x4(src_diff, coeff, diff_stride);
-        vpx_highbd_quantize_b(coeff, 16, x->skip_block, p->zbin, p->round,
-                              p->quant, p->quant_shift, qcoeff, dqcoeff,
-                              pd->dequant, eob,
-                              scan_order->scan, scan_order->iscan);
-        break;
-      default:
-        assert(0);
-    }
-    return;
-  }
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-
-  switch (tx_size) {
-    case TX_32X32:
-      fdct32x32(x->use_lp32x32fdct, src_diff, coeff, diff_stride);
-      vpx_quantize_b_32x32(coeff, 1024, x->skip_block, p->zbin, p->round,
-                           p->quant, p->quant_shift, qcoeff, dqcoeff,
-                           pd->dequant, eob, scan_order->scan,
-                           scan_order->iscan);
-      break;
-    case TX_16X16:
-      vpx_fdct16x16(src_diff, coeff, diff_stride);
-      vpx_quantize_b(coeff, 256, x->skip_block, p->zbin, p->round,
-                     p->quant, p->quant_shift, qcoeff, dqcoeff,
-                     pd->dequant, eob,
-                     scan_order->scan, scan_order->iscan);
-      break;
-    case TX_8X8:
-      vpx_fdct8x8(src_diff, coeff, diff_stride);
-      vpx_quantize_b(coeff, 64, x->skip_block, p->zbin, p->round,
-                     p->quant, p->quant_shift, qcoeff, dqcoeff,
-                     pd->dequant, eob,
-                     scan_order->scan, scan_order->iscan);
-      break;
-    case TX_4X4:
-      x->fwd_txm4x4(src_diff, coeff, diff_stride);
-      vpx_quantize_b(coeff, 16, x->skip_block, p->zbin, p->round,
-                     p->quant, p->quant_shift, qcoeff, dqcoeff,
-                     pd->dequant, eob,
-                     scan_order->scan, scan_order->iscan);
-      break;
-    default:
-      assert(0);
-      break;
-  }
-}
-
-static void encode_block(int plane, int block, BLOCK_SIZE plane_bsize,
-                         TX_SIZE tx_size, void *arg) {
-  struct encode_b_args *const args = arg;
-  MACROBLOCK *const x = args->x;
-  MACROBLOCKD *const xd = &x->e_mbd;
-  struct optimize_ctx *const ctx = args->ctx;
-  struct macroblock_plane *const p = &x->plane[plane];
-  struct macroblockd_plane *const pd = &xd->plane[plane];
-  tran_low_t *const dqcoeff = BLOCK_OFFSET(pd->dqcoeff, block);
-  int i, j;
-  uint8_t *dst;
-  ENTROPY_CONTEXT *a, *l;
-  txfrm_block_to_raster_xy(plane_bsize, tx_size, block, &i, &j);
-  dst = &pd->dst.buf[4 * j * pd->dst.stride + 4 * i];
-  a = &ctx->ta[plane][i];
-  l = &ctx->tl[plane][j];
-
-  // TODO(jingning): per transformed block zero forcing only enabled for
-  // luma component. will integrate chroma components as well.
-  if (x->zcoeff_blk[tx_size][block] && plane == 0) {
-    p->eobs[block] = 0;
-    *a = *l = 0;
-    return;
-  }
-
-  if (!x->skip_recode) {
-    if (x->quant_fp) {
-      // Encoding process for rtc mode
-      if (x->skip_txfm[0] == SKIP_TXFM_AC_DC && plane == 0) {
-        // skip forward transform
-        p->eobs[block] = 0;
-        *a = *l = 0;
-        return;
-      } else {
-        vp9_xform_quant_fp(x, plane, block, plane_bsize, tx_size);
-      }
-    } else {
-      if (max_txsize_lookup[plane_bsize] == tx_size) {
-        int txfm_blk_index = (plane << 2) + (block >> (tx_size << 1));
-        if (x->skip_txfm[txfm_blk_index] == SKIP_TXFM_NONE) {
-          // full forward transform and quantization
-          vp9_xform_quant(x, plane, block, plane_bsize, tx_size);
-        } else if (x->skip_txfm[txfm_blk_index] == SKIP_TXFM_AC_ONLY) {
-          // fast path forward transform and quantization
-          vp9_xform_quant_dc(x, plane, block, plane_bsize, tx_size);
-        } else {
-          // skip forward transform
-          p->eobs[block] = 0;
-          *a = *l = 0;
-          return;
-        }
-      } else {
-        vp9_xform_quant(x, plane, block, plane_bsize, tx_size);
-      }
-    }
-  }
-
-  if (x->optimize && (!x->skip_recode || !x->skip_optimize)) {
-    const int ctx = combine_entropy_contexts(*a, *l);
-    *a = *l = optimize_b(x, plane, block, tx_size, ctx) > 0;
-  } else {
-    *a = *l = p->eobs[block] > 0;
-  }
-
-  if (p->eobs[block])
-    *(args->skip) = 0;
-
-  if (x->skip_encode || p->eobs[block] == 0)
-    return;
-#if CONFIG_VP9_HIGHBITDEPTH
-  if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
-    switch (tx_size) {
-      case TX_32X32:
-        vp9_highbd_idct32x32_add(dqcoeff, dst, pd->dst.stride,
-                                 p->eobs[block], xd->bd);
-        break;
-      case TX_16X16:
-        vp9_highbd_idct16x16_add(dqcoeff, dst, pd->dst.stride,
-                                 p->eobs[block], xd->bd);
-        break;
-      case TX_8X8:
-        vp9_highbd_idct8x8_add(dqcoeff, dst, pd->dst.stride,
-                               p->eobs[block], xd->bd);
-        break;
-      case TX_4X4:
-        // this is like vp9_short_idct4x4 but has a special case around eob<=1
-        // which is significant (not just an optimization) for the lossless
-        // case.
-        x->highbd_itxm_add(dqcoeff, dst, pd->dst.stride,
-                           p->eobs[block], xd->bd);
-        break;
-      default:
-        assert(0 && "Invalid transform size");
-    }
-    return;
-  }
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-
-  switch (tx_size) {
-    case TX_32X32:
-      vp9_idct32x32_add(dqcoeff, dst, pd->dst.stride, p->eobs[block]);
-      break;
-    case TX_16X16:
-      vp9_idct16x16_add(dqcoeff, dst, pd->dst.stride, p->eobs[block]);
-      break;
-    case TX_8X8:
-      vp9_idct8x8_add(dqcoeff, dst, pd->dst.stride, p->eobs[block]);
-      break;
-    case TX_4X4:
-      // this is like vp9_short_idct4x4 but has a special case around eob<=1
-      // which is significant (not just an optimization) for the lossless
-      // case.
-      x->itxm_add(dqcoeff, dst, pd->dst.stride, p->eobs[block]);
-      break;
-    default:
-      assert(0 && "Invalid transform size");
-      break;
-  }
-}
-
-static void encode_block_pass1(int plane, int block, BLOCK_SIZE plane_bsize,
-                               TX_SIZE tx_size, void *arg) {
-  MACROBLOCK *const x = (MACROBLOCK *)arg;
-  MACROBLOCKD *const xd = &x->e_mbd;
-  struct macroblock_plane *const p = &x->plane[plane];
-  struct macroblockd_plane *const pd = &xd->plane[plane];
-  tran_low_t *const dqcoeff = BLOCK_OFFSET(pd->dqcoeff, block);
-  int i, j;
-  uint8_t *dst;
-  txfrm_block_to_raster_xy(plane_bsize, tx_size, block, &i, &j);
-  dst = &pd->dst.buf[4 * j * pd->dst.stride + 4 * i];
-
-  vp9_xform_quant(x, plane, block, plane_bsize, tx_size);
-
-  if (p->eobs[block] > 0) {
-#if CONFIG_VP9_HIGHBITDEPTH
-    if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
-       x->highbd_itxm_add(dqcoeff, dst, pd->dst.stride, p->eobs[block], xd->bd);
-       return;
-    }
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-    x->itxm_add(dqcoeff, dst, pd->dst.stride, p->eobs[block]);
-  }
-}
-
-void vp9_encode_sby_pass1(MACROBLOCK *x, BLOCK_SIZE bsize) {
-  vp9_subtract_plane(x, bsize, 0);
-  vp9_foreach_transformed_block_in_plane(&x->e_mbd, bsize, 0,
-                                         encode_block_pass1, x);
-}
-
-void vp9_encode_sb(MACROBLOCK *x, BLOCK_SIZE bsize) {
-  MACROBLOCKD *const xd = &x->e_mbd;
-  struct optimize_ctx ctx;
-  MODE_INFO *mi = xd->mi[0];
-  struct encode_b_args arg = {x, &ctx, &mi->skip};
-  int plane;
-
-  mi->skip = 1;
-
-  if (x->skip)
-    return;
-
-  for (plane = 0; plane < MAX_MB_PLANE; ++plane) {
-    if (!x->skip_recode)
-      vp9_subtract_plane(x, bsize, plane);
-
-    if (x->optimize && (!x->skip_recode || !x->skip_optimize)) {
-      const struct macroblockd_plane* const pd = &xd->plane[plane];
-      const TX_SIZE tx_size = plane ? get_uv_tx_size(mi, pd) : mi->tx_size;
-      vp9_get_entropy_contexts(bsize, tx_size, pd,
-                               ctx.ta[plane], ctx.tl[plane]);
-    }
-
-    vp9_foreach_transformed_block_in_plane(xd, bsize, plane, encode_block,
-                                           &arg);
-  }
-}
-
-void vp9_encode_block_intra(int plane, int block, BLOCK_SIZE plane_bsize,
-                            TX_SIZE tx_size, void *arg) {
-  struct encode_b_args* const args = arg;
-  MACROBLOCK *const x = args->x;
-  MACROBLOCKD *const xd = &x->e_mbd;
-  MODE_INFO *mi = xd->mi[0];
-  struct macroblock_plane *const p = &x->plane[plane];
-  struct macroblockd_plane *const pd = &xd->plane[plane];
-  tran_low_t *coeff = BLOCK_OFFSET(p->coeff, block);
-  tran_low_t *qcoeff = BLOCK_OFFSET(p->qcoeff, block);
-  tran_low_t *dqcoeff = BLOCK_OFFSET(pd->dqcoeff, block);
-  const scan_order *scan_order;
-  TX_TYPE tx_type = DCT_DCT;
-  PREDICTION_MODE mode;
-  const int bwl = b_width_log2_lookup[plane_bsize];
-  const int diff_stride = 4 * (1 << bwl);
-  uint8_t *src, *dst;
-  int16_t *src_diff;
-  uint16_t *eob = &p->eobs[block];
-  const int src_stride = p->src.stride;
-  const int dst_stride = pd->dst.stride;
-  int i, j;
-  struct optimize_ctx *const ctx = args->ctx;
-  ENTROPY_CONTEXT *a = NULL;
-  ENTROPY_CONTEXT *l = NULL;
-  int entropy_ctx = 0;
-  txfrm_block_to_raster_xy(plane_bsize, tx_size, block, &i, &j);
-  dst = &pd->dst.buf[4 * (j * dst_stride + i)];
-  src = &p->src.buf[4 * (j * src_stride + i)];
-  src_diff = &p->src_diff[4 * (j * diff_stride + i)];
-  if (args->ctx != NULL) {
-    a = &ctx->ta[plane][i];
-    l = &ctx->tl[plane][j];
-    entropy_ctx = combine_entropy_contexts(*a, *l);
-  }
-
-  if (tx_size == TX_4X4) {
-    tx_type = get_tx_type_4x4(get_plane_type(plane), xd, block);
-    scan_order = &vp9_scan_orders[TX_4X4][tx_type];
-    mode = plane == 0 ? get_y_mode(xd->mi[0], block) : mi->uv_mode;
-  } else {
-    mode = plane == 0 ? mi->mode : mi->uv_mode;
-    if (tx_size == TX_32X32) {
-      scan_order = &vp9_default_scan_orders[TX_32X32];
-    } else {
-      tx_type = get_tx_type(get_plane_type(plane), xd);
-      scan_order = &vp9_scan_orders[tx_size][tx_type];
-    }
-  }
-
-  vp9_predict_intra_block(xd, bwl, tx_size, mode, x->skip_encode ? src : dst,
-                          x->skip_encode ? src_stride : dst_stride,
-                          dst, dst_stride, i, j, plane);
-
-#if CONFIG_VP9_HIGHBITDEPTH
-  if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
-    switch (tx_size) {
-      case TX_32X32:
-        if (!x->skip_recode) {
-          vpx_highbd_subtract_block(32, 32, src_diff, diff_stride,
-                                    src, src_stride, dst, dst_stride, xd->bd);
-          highbd_fdct32x32(x->use_lp32x32fdct, src_diff, coeff, diff_stride);
-          vpx_highbd_quantize_b_32x32(coeff, 1024, x->skip_block, p->zbin,
-                                      p->round, p->quant, p->quant_shift,
-                                      qcoeff, dqcoeff, pd->dequant, eob,
-                                      scan_order->scan, scan_order->iscan);
-        }
-        if (!x->skip_encode && *eob) {
-          vp9_highbd_idct32x32_add(dqcoeff, dst, dst_stride, *eob, xd->bd);
-        }
-        break;
-      case TX_16X16:
-        if (!x->skip_recode) {
-          vpx_highbd_subtract_block(16, 16, src_diff, diff_stride,
-                                    src, src_stride, dst, dst_stride, xd->bd);
-          if (tx_type == DCT_DCT)
-            vpx_highbd_fdct16x16(src_diff, coeff, diff_stride);
-          else
-            vp9_highbd_fht16x16(src_diff, coeff, diff_stride, tx_type);
-          vpx_highbd_quantize_b(coeff, 256, x->skip_block, p->zbin, p->round,
-                                p->quant, p->quant_shift, qcoeff, dqcoeff,
-                                pd->dequant, eob,
-                                scan_order->scan, scan_order->iscan);
-        }
-        if (!x->skip_encode && *eob) {
-          vp9_highbd_iht16x16_add(tx_type, dqcoeff, dst, dst_stride,
-                                  *eob, xd->bd);
-        }
-        break;
-      case TX_8X8:
-        if (!x->skip_recode) {
-          vpx_highbd_subtract_block(8, 8, src_diff, diff_stride,
-                                    src, src_stride, dst, dst_stride, xd->bd);
-          if (tx_type == DCT_DCT)
-            vpx_highbd_fdct8x8(src_diff, coeff, diff_stride);
-          else
-            vp9_highbd_fht8x8(src_diff, coeff, diff_stride, tx_type);
-          vpx_highbd_quantize_b(coeff, 64, x->skip_block, p->zbin, p->round,
-                                p->quant, p->quant_shift, qcoeff, dqcoeff,
-                                pd->dequant, eob,
-                                scan_order->scan, scan_order->iscan);
-        }
-        if (!x->skip_encode && *eob) {
-          vp9_highbd_iht8x8_add(tx_type, dqcoeff, dst, dst_stride, *eob,
-                                xd->bd);
-        }
-        break;
-      case TX_4X4:
-        if (!x->skip_recode) {
-          vpx_highbd_subtract_block(4, 4, src_diff, diff_stride,
-                                    src, src_stride, dst, dst_stride, xd->bd);
-          if (tx_type != DCT_DCT)
-            vp9_highbd_fht4x4(src_diff, coeff, diff_stride, tx_type);
-          else
-            x->fwd_txm4x4(src_diff, coeff, diff_stride);
-          vpx_highbd_quantize_b(coeff, 16, x->skip_block, p->zbin, p->round,
-                                p->quant, p->quant_shift, qcoeff, dqcoeff,
-                                pd->dequant, eob,
-                                scan_order->scan, scan_order->iscan);
-        }
-
-        if (!x->skip_encode && *eob) {
-          if (tx_type == DCT_DCT) {
-            // this is like vp9_short_idct4x4 but has a special case around
-            // eob<=1 which is significant (not just an optimization) for the
-            // lossless case.
-            x->highbd_itxm_add(dqcoeff, dst, dst_stride, *eob, xd->bd);
-          } else {
-            vp9_highbd_iht4x4_16_add(dqcoeff, dst, dst_stride, tx_type, xd->bd);
-          }
-        }
-        break;
-      default:
-        assert(0);
-        return;
-    }
-    if (*eob)
-      *(args->skip) = 0;
-    return;
-  }
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-
-  switch (tx_size) {
-    case TX_32X32:
-      if (!x->skip_recode) {
-        vpx_subtract_block(32, 32, src_diff, diff_stride,
-                           src, src_stride, dst, dst_stride);
-        fdct32x32(x->use_lp32x32fdct, src_diff, coeff, diff_stride);
-        vpx_quantize_b_32x32(coeff, 1024, x->skip_block, p->zbin, p->round,
-                             p->quant, p->quant_shift, qcoeff, dqcoeff,
-                             pd->dequant, eob, scan_order->scan,
-                             scan_order->iscan);
-      }
-      if (args->ctx != NULL && !x->skip_recode) {
-       *a = *l = optimize_b(x, plane, block, tx_size, entropy_ctx) > 0;
-      }
-      if (!x->skip_encode && *eob)
-        vp9_idct32x32_add(dqcoeff, dst, dst_stride, *eob);
-      break;
-    case TX_16X16:
-      if (!x->skip_recode) {
-        vpx_subtract_block(16, 16, src_diff, diff_stride,
-                           src, src_stride, dst, dst_stride);
-        vp9_fht16x16(src_diff, coeff, diff_stride, tx_type);
-        vpx_quantize_b(coeff, 256, x->skip_block, p->zbin, p->round,
-                       p->quant, p->quant_shift, qcoeff, dqcoeff,
-                       pd->dequant, eob, scan_order->scan,
-                       scan_order->iscan);
-      }
-      if (args->ctx != NULL && !x->skip_recode) {
-        *a = *l = optimize_b(x, plane, block, tx_size, entropy_ctx) > 0;
-      }
-      if (!x->skip_encode && *eob)
-        vp9_iht16x16_add(tx_type, dqcoeff, dst, dst_stride, *eob);
-      break;
-    case TX_8X8:
-      if (!x->skip_recode) {
-        vpx_subtract_block(8, 8, src_diff, diff_stride,
-                           src, src_stride, dst, dst_stride);
-        vp9_fht8x8(src_diff, coeff, diff_stride, tx_type);
-        vpx_quantize_b(coeff, 64, x->skip_block, p->zbin, p->round, p->quant,
-                       p->quant_shift, qcoeff, dqcoeff,
-                       pd->dequant, eob, scan_order->scan,
-                       scan_order->iscan);
-      }
-      if (args->ctx != NULL && !x->skip_recode) {
-        *a = *l = optimize_b(x, plane, block, tx_size, entropy_ctx) > 0;
-      }
-      if (!x->skip_encode && *eob)
-        vp9_iht8x8_add(tx_type, dqcoeff, dst, dst_stride, *eob);
-      break;
-    case TX_4X4:
-      if (!x->skip_recode) {
-        vpx_subtract_block(4, 4, src_diff, diff_stride,
-                           src, src_stride, dst, dst_stride);
-        if (tx_type != DCT_DCT)
-          vp9_fht4x4(src_diff, coeff, diff_stride, tx_type);
-        else
-          x->fwd_txm4x4(src_diff, coeff, diff_stride);
-        vpx_quantize_b(coeff, 16, x->skip_block, p->zbin, p->round, p->quant,
-                       p->quant_shift, qcoeff, dqcoeff,
-                       pd->dequant, eob, scan_order->scan,
-                       scan_order->iscan);
-      }
-      if (args->ctx != NULL && !x->skip_recode) {
-        *a = *l = optimize_b(x, plane, block, tx_size, entropy_ctx) > 0;
-      }
-      if (!x->skip_encode && *eob) {
-        if (tx_type == DCT_DCT)
-          // this is like vp9_short_idct4x4 but has a special case around eob<=1
-          // which is significant (not just an optimization) for the lossless
-          // case.
-          x->itxm_add(dqcoeff, dst, dst_stride, *eob);
-        else
-          vp9_iht4x4_16_add(dqcoeff, dst, dst_stride, tx_type);
-      }
-      break;
-    default:
-      assert(0);
-      break;
-  }
-  if (*eob)
-    *(args->skip) = 0;
-}
-
-void vp9_encode_intra_block_plane(MACROBLOCK *x, BLOCK_SIZE bsize, int plane,
-                                  int enable_optimize_b) {
-  const MACROBLOCKD *const xd = &x->e_mbd;
-  struct optimize_ctx ctx;
-  struct encode_b_args arg = {x, NULL, &xd->mi[0]->skip};
-
-  if (enable_optimize_b && x->optimize &&
-      (!x->skip_recode || !x->skip_optimize)) {
-    const struct macroblockd_plane* const pd = &xd->plane[plane];
-    const TX_SIZE tx_size = plane ? get_uv_tx_size(xd->mi[0], pd) :
-        xd->mi[0]->tx_size;
-    vp9_get_entropy_contexts(bsize, tx_size, pd, ctx.ta[plane], ctx.tl[plane]);
-    arg.ctx = &ctx;
-  }
-
-  vp9_foreach_transformed_block_in_plane(xd, bsize, plane,
-                                         vp9_encode_block_intra, &arg);
-}
diff --git a/vp9/encoder/vp9_encodemb.h b/vp9/encoder/vp9_encodemb.h
deleted file mode 100644 (file)
index 25b0b23..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#ifndef VP9_ENCODER_VP9_ENCODEMB_H_
-#define VP9_ENCODER_VP9_ENCODEMB_H_
-
-#include "./vpx_config.h"
-#include "vp9/encoder/vp9_block.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-struct encode_b_args {
-  MACROBLOCK *x;
-  struct optimize_ctx *ctx;
-  int8_t *skip;
-};
-void vp9_encode_sb(MACROBLOCK *x, BLOCK_SIZE bsize);
-void vp9_encode_sby_pass1(MACROBLOCK *x, BLOCK_SIZE bsize);
-void vp9_xform_quant_fp(MACROBLOCK *x, int plane, int block,
-                        BLOCK_SIZE plane_bsize, TX_SIZE tx_size);
-void vp9_xform_quant_dc(MACROBLOCK *x, int plane, int block,
-                        BLOCK_SIZE plane_bsize, TX_SIZE tx_size);
-void vp9_xform_quant(MACROBLOCK *x, int plane, int block,
-                     BLOCK_SIZE plane_bsize, TX_SIZE tx_size);
-
-void vp9_subtract_plane(MACROBLOCK *x, BLOCK_SIZE bsize, int plane);
-
-void vp9_encode_block_intra(int plane, int block, BLOCK_SIZE plane_bsize,
-                            TX_SIZE tx_size, void *arg);
-
-void vp9_encode_intra_block_plane(MACROBLOCK *x, BLOCK_SIZE bsize, int plane,
-                                  int enable_optimize_b);
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP9_ENCODER_VP9_ENCODEMB_H_
diff --git a/vp9/encoder/vp9_encodemv.c b/vp9/encoder/vp9_encodemv.c
deleted file mode 100644 (file)
index 71f27cc..0000000
+++ /dev/null
@@ -1,282 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#include <math.h>
-
-#include "vp9/common/vp9_common.h"
-#include "vp9/common/vp9_entropymode.h"
-
-#include "vp9/encoder/vp9_cost.h"
-#include "vp9/encoder/vp9_encodemv.h"
-
-#include "vpx_dsp/vpx_dsp_common.h"
-
-static struct vp9_token mv_joint_encodings[MV_JOINTS];
-static struct vp9_token mv_class_encodings[MV_CLASSES];
-static struct vp9_token mv_fp_encodings[MV_FP_SIZE];
-static struct vp9_token mv_class0_encodings[CLASS0_SIZE];
-
-void vp9_entropy_mv_init(void) {
-  vp9_tokens_from_tree(mv_joint_encodings, vp9_mv_joint_tree);
-  vp9_tokens_from_tree(mv_class_encodings, vp9_mv_class_tree);
-  vp9_tokens_from_tree(mv_class0_encodings, vp9_mv_class0_tree);
-  vp9_tokens_from_tree(mv_fp_encodings, vp9_mv_fp_tree);
-}
-
-static void encode_mv_component(vpx_writer* w, int comp,
-                                const nmv_component* mvcomp, int usehp) {
-  int offset;
-  const int sign = comp < 0;
-  const int mag = sign ? -comp : comp;
-  const int mv_class = vp9_get_mv_class(mag - 1, &offset);
-  const int d = offset >> 3;                // int mv data
-  const int fr = (offset >> 1) & 3;         // fractional mv data
-  const int hp = offset & 1;                // high precision mv data
-
-  assert(comp != 0);
-
-  // Sign
-  vpx_write(w, sign, mvcomp->sign);
-
-  // Class
-  vp9_write_token(w, vp9_mv_class_tree, mvcomp->classes,
-                  &mv_class_encodings[mv_class]);
-
-  // Integer bits
-  if (mv_class == MV_CLASS_0) {
-    vp9_write_token(w, vp9_mv_class0_tree, mvcomp->class0,
-                    &mv_class0_encodings[d]);
-  } else {
-    int i;
-    const int n = mv_class + CLASS0_BITS - 1;  // number of bits
-    for (i = 0; i < n; ++i)
-      vpx_write(w, (d >> i) & 1, mvcomp->bits[i]);
-  }
-
-  // Fractional bits
-  vp9_write_token(w, vp9_mv_fp_tree,
-                  mv_class == MV_CLASS_0 ?  mvcomp->class0_fp[d] : mvcomp->fp,
-                  &mv_fp_encodings[fr]);
-
-  // High precision bit
-  if (usehp)
-    vpx_write(w, hp,
-              mv_class == MV_CLASS_0 ? mvcomp->class0_hp : mvcomp->hp);
-}
-
-
-static void build_nmv_component_cost_table(int *mvcost,
-                                           const nmv_component* const mvcomp,
-                                           int usehp) {
-  int sign_cost[2], class_cost[MV_CLASSES], class0_cost[CLASS0_SIZE];
-  int bits_cost[MV_OFFSET_BITS][2];
-  int class0_fp_cost[CLASS0_SIZE][MV_FP_SIZE], fp_cost[MV_FP_SIZE];
-  int class0_hp_cost[2], hp_cost[2];
-  int i;
-  int c, o;
-
-  sign_cost[0] = vp9_cost_zero(mvcomp->sign);
-  sign_cost[1] = vp9_cost_one(mvcomp->sign);
-  vp9_cost_tokens(class_cost, mvcomp->classes, vp9_mv_class_tree);
-  vp9_cost_tokens(class0_cost, mvcomp->class0, vp9_mv_class0_tree);
-  for (i = 0; i < MV_OFFSET_BITS; ++i) {
-    bits_cost[i][0] = vp9_cost_zero(mvcomp->bits[i]);
-    bits_cost[i][1] = vp9_cost_one(mvcomp->bits[i]);
-  }
-
-  for (i = 0; i < CLASS0_SIZE; ++i)
-    vp9_cost_tokens(class0_fp_cost[i], mvcomp->class0_fp[i], vp9_mv_fp_tree);
-  vp9_cost_tokens(fp_cost, mvcomp->fp, vp9_mv_fp_tree);
-
-  // Always build the hp costs to avoid an uninitialized warning from gcc
-  class0_hp_cost[0] = vp9_cost_zero(mvcomp->class0_hp);
-  class0_hp_cost[1] = vp9_cost_one(mvcomp->class0_hp);
-  hp_cost[0] = vp9_cost_zero(mvcomp->hp);
-  hp_cost[1] = vp9_cost_one(mvcomp->hp);
-
-  mvcost[0] = 0;
-  // MV_CLASS_0
-  for (o = 0; o < (CLASS0_SIZE << 3); ++o) {
-    int d, e, f;
-    int cost = class_cost[MV_CLASS_0];
-    int v = o + 1;
-    d = (o >> 3);               /* int mv data */
-    f = (o >> 1) & 3;           /* fractional pel mv data */
-    cost += class0_cost[d];
-    cost += class0_fp_cost[d][f];
-    if (usehp) {
-      e = (o & 1);                /* high precision mv data */
-      cost += class0_hp_cost[e];
-    }
-    mvcost[v] = cost + sign_cost[0];
-    mvcost[-v] = cost + sign_cost[1];
-  }
-  for (c = MV_CLASS_1; c < MV_CLASSES; ++c) {
-    int d;
-    for (d = 0; d < (1 << c); ++d) {
-      int f;
-      int whole_cost = class_cost[c];
-      int b = c + CLASS0_BITS - 1;  /* number of bits */
-      for (i = 0; i < b; ++i)
-        whole_cost += bits_cost[i][((d >> i) & 1)];
-      for (f = 0; f < 4; ++f) {
-        int cost = whole_cost + fp_cost[f];
-        int v = (CLASS0_SIZE << (c + 2)) + d * 8 + f * 2 /* + e */ + 1;
-        if (usehp) {
-          mvcost[v] = cost + hp_cost[0] + sign_cost[0];
-          mvcost[-v] = cost + hp_cost[0] + sign_cost[1];
-          if (v + 1 > MV_MAX) break;
-          mvcost[v + 1] = cost + hp_cost[1] + sign_cost[0];
-          mvcost[-v - 1] = cost + hp_cost[1] + sign_cost[1];
-        } else {
-          mvcost[v] = cost + sign_cost[0];
-          mvcost[-v] = cost + sign_cost[1];
-          if (v + 1 > MV_MAX) break;
-          mvcost[v + 1] = cost + sign_cost[0];
-          mvcost[-v - 1] = cost + sign_cost[1];
-        }
-      }
-    }
-  }
-}
-
-static int update_mv(vpx_writer *w, const unsigned int ct[2], vpx_prob *cur_p,
-                     vpx_prob upd_p) {
-  const vpx_prob new_p = get_binary_prob(ct[0], ct[1]) | 1;
-  const int update = cost_branch256(ct, *cur_p) + vp9_cost_zero(upd_p) >
-                     cost_branch256(ct, new_p) + vp9_cost_one(upd_p) +
-                         (7 << VP9_PROB_COST_SHIFT);
-  vpx_write(w, update, upd_p);
-  if (update) {
-    *cur_p = new_p;
-    vpx_write_literal(w, new_p >> 1, 7);
-  }
-  return update;
-}
-
-static void write_mv_update(const vpx_tree_index *tree,
-                            vpx_prob probs[/*n - 1*/],
-                            const unsigned int counts[/*n - 1*/],
-                            int n, vpx_writer *w) {
-  int i;
-  unsigned int branch_ct[32][2];
-
-  // Assuming max number of probabilities <= 32
-  assert(n <= 32);
-
-  vp9_tree_probs_from_distribution(tree, branch_ct, counts);
-  for (i = 0; i < n - 1; ++i)
-    update_mv(w, branch_ct[i], &probs[i], MV_UPDATE_PROB);
-}
-
-void vp9_write_nmv_probs(VP9_COMMON *cm, int usehp, vpx_writer *w,
-                         nmv_context_counts *const counts) {
-  int i, j;
-  nmv_context *const mvc = &cm->fc->nmvc;
-
-  write_mv_update(vp9_mv_joint_tree, mvc->joints, counts->joints, MV_JOINTS, w);
-
-  for (i = 0; i < 2; ++i) {
-    nmv_component *comp = &mvc->comps[i];
-    nmv_component_counts *comp_counts = &counts->comps[i];
-
-    update_mv(w, comp_counts->sign, &comp->sign, MV_UPDATE_PROB);
-    write_mv_update(vp9_mv_class_tree, comp->classes, comp_counts->classes,
-                    MV_CLASSES, w);
-    write_mv_update(vp9_mv_class0_tree, comp->class0, comp_counts->class0,
-                    CLASS0_SIZE, w);
-    for (j = 0; j < MV_OFFSET_BITS; ++j)
-      update_mv(w, comp_counts->bits[j], &comp->bits[j], MV_UPDATE_PROB);
-  }
-
-  for (i = 0; i < 2; ++i) {
-    for (j = 0; j < CLASS0_SIZE; ++j)
-      write_mv_update(vp9_mv_fp_tree, mvc->comps[i].class0_fp[j],
-                      counts->comps[i].class0_fp[j], MV_FP_SIZE, w);
-
-    write_mv_update(vp9_mv_fp_tree, mvc->comps[i].fp, counts->comps[i].fp,
-                    MV_FP_SIZE, w);
-  }
-
-  if (usehp) {
-    for (i = 0; i < 2; ++i) {
-      update_mv(w, counts->comps[i].class0_hp, &mvc->comps[i].class0_hp,
-                MV_UPDATE_PROB);
-      update_mv(w, counts->comps[i].hp, &mvc->comps[i].hp, MV_UPDATE_PROB);
-    }
-  }
-}
-
-void vp9_encode_mv(VP9_COMP* cpi, vpx_writer* w,
-                   const MV* mv, const MV* ref,
-                   const nmv_context* mvctx, int usehp) {
-  const MV diff = {mv->row - ref->row,
-                   mv->col - ref->col};
-  const MV_JOINT_TYPE j = vp9_get_mv_joint(&diff);
-  usehp = usehp && use_mv_hp(ref);
-
-  vp9_write_token(w, vp9_mv_joint_tree, mvctx->joints, &mv_joint_encodings[j]);
-  if (mv_joint_vertical(j))
-    encode_mv_component(w, diff.row, &mvctx->comps[0], usehp);
-
-  if (mv_joint_horizontal(j))
-    encode_mv_component(w, diff.col, &mvctx->comps[1], usehp);
-
-  // If auto_mv_step_size is enabled then keep track of the largest
-  // motion vector component used.
-  if (cpi->sf.mv.auto_mv_step_size) {
-    unsigned int maxv = VPXMAX(abs(mv->row), abs(mv->col)) >> 3;
-    cpi->max_mv_magnitude = VPXMAX(maxv, cpi->max_mv_magnitude);
-  }
-}
-
-void vp9_build_nmv_cost_table(int *mvjoint, int *mvcost[2],
-                              const nmv_context* ctx, int usehp) {
-  vp9_cost_tokens(mvjoint, ctx->joints, vp9_mv_joint_tree);
-  build_nmv_component_cost_table(mvcost[0], &ctx->comps[0], usehp);
-  build_nmv_component_cost_table(mvcost[1], &ctx->comps[1], usehp);
-}
-
-static void inc_mvs(const MODE_INFO *mi, const MB_MODE_INFO_EXT *mbmi_ext,
-                    const int_mv mvs[2],
-                    nmv_context_counts *counts) {
-  int i;
-
-  for (i = 0; i < 1 + has_second_ref(mi); ++i) {
-    const MV *ref = &mbmi_ext->ref_mvs[mi->ref_frame[i]][0].as_mv;
-    const MV diff = {mvs[i].as_mv.row - ref->row,
-                     mvs[i].as_mv.col - ref->col};
-    vp9_inc_mv(&diff, counts);
-  }
-}
-
-void vp9_update_mv_count(ThreadData *td) {
-  const MACROBLOCKD *xd = &td->mb.e_mbd;
-  const MODE_INFO *mi = xd->mi[0];
-  const MB_MODE_INFO_EXT *mbmi_ext = td->mb.mbmi_ext;
-
-  if (mi->sb_type < BLOCK_8X8) {
-    const int num_4x4_w = num_4x4_blocks_wide_lookup[mi->sb_type];
-    const int num_4x4_h = num_4x4_blocks_high_lookup[mi->sb_type];
-    int idx, idy;
-
-    for (idy = 0; idy < 2; idy += num_4x4_h) {
-      for (idx = 0; idx < 2; idx += num_4x4_w) {
-        const int i = idy * 2 + idx;
-        if (mi->bmi[i].as_mode == NEWMV)
-          inc_mvs(mi, mbmi_ext, mi->bmi[i].as_mv, &td->counts->mv);
-      }
-    }
-  } else {
-    if (mi->mode == NEWMV)
-      inc_mvs(mi, mbmi_ext, mi->mv, &td->counts->mv);
-  }
-}
-
diff --git a/vp9/encoder/vp9_encodemv.h b/vp9/encoder/vp9_encodemv.h
deleted file mode 100644 (file)
index 5fb114c..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#ifndef VP9_ENCODER_VP9_ENCODEMV_H_
-#define VP9_ENCODER_VP9_ENCODEMV_H_
-
-#include "vp9/encoder/vp9_encoder.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-void vp9_entropy_mv_init(void);
-
-void vp9_write_nmv_probs(VP9_COMMON *cm, int usehp, vpx_writer *w,
-                         nmv_context_counts *const counts);
-
-void vp9_encode_mv(VP9_COMP *cpi, vpx_writer* w, const MV* mv, const MV* ref,
-                   const nmv_context* mvctx, int usehp);
-
-void vp9_build_nmv_cost_table(int *mvjoint, int *mvcost[2],
-                              const nmv_context* mvctx, int usehp);
-
-void vp9_update_mv_count(ThreadData *td);
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP9_ENCODER_VP9_ENCODEMV_H_
diff --git a/vp9/encoder/vp9_encoder.c b/vp9/encoder/vp9_encoder.c
deleted file mode 100644 (file)
index 0ce996a..0000000
+++ /dev/null
@@ -1,4925 +0,0 @@
-/*
- * Copyright (c) 2010 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.
- */
-
-#include <math.h>
-#include <stdio.h>
-#include <limits.h>
-
-#include "./vp9_rtcd.h"
-#include "./vpx_config.h"
-#include "./vpx_dsp_rtcd.h"
-#include "./vpx_scale_rtcd.h"
-#include "vpx_dsp/psnr.h"
-#include "vpx_dsp/vpx_dsp_common.h"
-#include "vpx_dsp/vpx_filter.h"
-#if CONFIG_INTERNAL_STATS
-#include "vpx_dsp/ssim.h"
-#endif
-#include "vpx_ports/mem.h"
-#include "vpx_ports/system_state.h"
-#include "vpx_ports/vpx_timer.h"
-
-#include "vp9/common/vp9_alloccommon.h"
-#include "vp9/common/vp9_filter.h"
-#include "vp9/common/vp9_idct.h"
-#if CONFIG_VP9_POSTPROC
-#include "vp9/common/vp9_postproc.h"
-#endif
-#include "vp9/common/vp9_reconinter.h"
-#include "vp9/common/vp9_reconintra.h"
-#include "vp9/common/vp9_tile_common.h"
-
-#include "vp9/encoder/vp9_aq_360.h"
-#include "vp9/encoder/vp9_aq_complexity.h"
-#include "vp9/encoder/vp9_aq_cyclicrefresh.h"
-#include "vp9/encoder/vp9_aq_variance.h"
-#include "vp9/encoder/vp9_bitstream.h"
-#include "vp9/encoder/vp9_context_tree.h"
-#include "vp9/encoder/vp9_encodeframe.h"
-#include "vp9/encoder/vp9_encodemv.h"
-#include "vp9/encoder/vp9_encoder.h"
-#include "vp9/encoder/vp9_ethread.h"
-#include "vp9/encoder/vp9_firstpass.h"
-#include "vp9/encoder/vp9_mbgraph.h"
-#include "vp9/encoder/vp9_noise_estimate.h"
-#include "vp9/encoder/vp9_picklpf.h"
-#include "vp9/encoder/vp9_ratectrl.h"
-#include "vp9/encoder/vp9_rd.h"
-#include "vp9/encoder/vp9_resize.h"
-#include "vp9/encoder/vp9_segmentation.h"
-#include "vp9/encoder/vp9_skin_detection.h"
-#include "vp9/encoder/vp9_speed_features.h"
-#include "vp9/encoder/vp9_svc_layercontext.h"
-#include "vp9/encoder/vp9_temporal_filter.h"
-
-#define AM_SEGMENT_ID_INACTIVE 7
-#define AM_SEGMENT_ID_ACTIVE 0
-
-#define ALTREF_HIGH_PRECISION_MV 1      // Whether to use high precision mv
-                                         //  for altref computation.
-#define HIGH_PRECISION_MV_QTHRESH 200   // Q threshold for high precision
-                                         // mv. Choose a very high value for
-                                         // now so that HIGH_PRECISION is always
-                                         // chosen.
-// #define OUTPUT_YUV_REC
-
-#ifdef OUTPUT_YUV_DENOISED
-FILE *yuv_denoised_file = NULL;
-#endif
-#ifdef OUTPUT_YUV_SKINMAP
-FILE *yuv_skinmap_file = NULL;
-#endif
-#ifdef OUTPUT_YUV_REC
-FILE *yuv_rec_file;
-#endif
-
-#if 0
-FILE *framepsnr;
-FILE *kf_list;
-FILE *keyfile;
-#endif
-
-static const Vp9LevelSpec vp9_level_defs[VP9_LEVELS] = {
-  {LEVEL_1,   829440,      36864,    200,    400,   2, 1,  4,  8},
-  {LEVEL_1_1, 2764800,     73728,    800,    1000,  2, 1,  4,  8},
-  {LEVEL_2,   4608000,     122880,   1800,   1500,  2, 1,  4,  8},
-  {LEVEL_2_1, 9216000,     245760,   3600,   2800,  2, 2,  4,  8},
-  {LEVEL_3,   20736000,    552960,   7200,   6000,  2, 4,  4,  8},
-  {LEVEL_3_1, 36864000,    983040,   12000,  10000, 2, 4,  4,  8},
-  {LEVEL_4,   83558400,    2228224,  18000,  16000, 4, 4,  4,  8},
-  {LEVEL_4_1, 160432128,   2228224,  30000,  18000, 4, 4,  5,  6},
-  {LEVEL_5,   311951360,   8912896,  60000,  36000, 6, 8,  6,  4},
-  {LEVEL_5_1, 588251136,   8912896,  120000, 46000, 8, 8,  10, 4},
-  // TODO(huisu): update max_cpb_size for level 5_2 ~ 6_2 when
-  // they are finalized (currently TBD).
-  {LEVEL_5_2, 1176502272,  8912896,  180000, 0,     8, 8,  10, 4},
-  {LEVEL_6,   1176502272,  35651584, 180000, 0,     8, 16, 10, 4},
-  {LEVEL_6_1, 2353004544u, 35651584, 240000, 0,     8, 16, 10, 4},
-  {LEVEL_6_2, 4706009088u, 35651584, 480000, 0,     8, 16, 10, 4},
-};
-
-static INLINE void Scale2Ratio(VPX_SCALING mode, int *hr, int *hs) {
-  switch (mode) {
-    case NORMAL:
-      *hr = 1;
-      *hs = 1;
-      break;
-    case FOURFIVE:
-      *hr = 4;
-      *hs = 5;
-      break;
-    case THREEFIVE:
-      *hr = 3;
-      *hs = 5;
-    break;
-    case ONETWO:
-      *hr = 1;
-      *hs = 2;
-    break;
-    default:
-      *hr = 1;
-      *hs = 1;
-       assert(0);
-      break;
-  }
-}
-
-// Mark all inactive blocks as active. Other segmentation features may be set
-// so memset cannot be used, instead only inactive blocks should be reset.
-static void suppress_active_map(VP9_COMP *cpi) {
-  unsigned char *const seg_map = cpi->segmentation_map;
-  int i;
-  if (cpi->active_map.enabled || cpi->active_map.update)
-    for (i = 0; i < cpi->common.mi_rows * cpi->common.mi_cols; ++i)
-      if (seg_map[i] == AM_SEGMENT_ID_INACTIVE)
-        seg_map[i] = AM_SEGMENT_ID_ACTIVE;
-}
-
-static void apply_active_map(VP9_COMP *cpi) {
-  struct segmentation *const seg = &cpi->common.seg;
-  unsigned char *const seg_map = cpi->segmentation_map;
-  const unsigned char *const active_map = cpi->active_map.map;
-  int i;
-
-  assert(AM_SEGMENT_ID_ACTIVE == CR_SEGMENT_ID_BASE);
-
-  if (frame_is_intra_only(&cpi->common)) {
-    cpi->active_map.enabled = 0;
-    cpi->active_map.update = 1;
-  }
-
-  if (cpi->active_map.update) {
-    if (cpi->active_map.enabled) {
-      for (i = 0; i < cpi->common.mi_rows * cpi->common.mi_cols; ++i)
-        if (seg_map[i] == AM_SEGMENT_ID_ACTIVE) seg_map[i] = active_map[i];
-      vp9_enable_segmentation(seg);
-      vp9_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_SKIP);
-      vp9_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF);
-      // Setting the data to -MAX_LOOP_FILTER will result in the computed loop
-      // filter level being zero regardless of the value of seg->abs_delta.
-      vp9_set_segdata(seg, AM_SEGMENT_ID_INACTIVE,
-                      SEG_LVL_ALT_LF, -MAX_LOOP_FILTER);
-    } else {
-      vp9_disable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_SKIP);
-      vp9_disable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF);
-      if (seg->enabled) {
-        seg->update_data = 1;
-        seg->update_map = 1;
-      }
-    }
-    cpi->active_map.update = 0;
-  }
-}
-
-static void init_level_info(Vp9LevelInfo *level_info) {
-  Vp9LevelStats *const level_stats = &level_info->level_stats;
-  Vp9LevelSpec *const level_spec = &level_info->level_spec;
-
-  memset(level_stats, 0, sizeof(*level_stats));
-  memset(level_spec, 0, sizeof(*level_spec));
-  level_spec->level = LEVEL_UNKNOWN;
-  level_spec->min_altref_distance = INT_MAX;
-}
-
-VP9_LEVEL vp9_get_level(const Vp9LevelSpec * const level_spec) {
-  int i;
-  const Vp9LevelSpec *this_level;
-
-  vpx_clear_system_state();
-
-  for (i = 0; i < VP9_LEVELS; ++i) {
-    this_level = &vp9_level_defs[i];
-    if ((double)level_spec->max_luma_sample_rate * (1 + SAMPLE_RATE_GRACE_P) >
-        (double)this_level->max_luma_sample_rate ||
-        level_spec->max_luma_picture_size > this_level->max_luma_picture_size ||
-        level_spec->average_bitrate > this_level->average_bitrate ||
-        level_spec->max_cpb_size > this_level->max_cpb_size ||
-        level_spec->compression_ratio < this_level->compression_ratio ||
-        level_spec->max_col_tiles > this_level->max_col_tiles ||
-        level_spec->min_altref_distance < this_level->min_altref_distance ||
-        level_spec->max_ref_frame_buffers > this_level->max_ref_frame_buffers)
-      continue;
-    break;
-  }
-  return (i == VP9_LEVELS) ? LEVEL_UNKNOWN : vp9_level_defs[i].level;
-}
-
-int vp9_set_active_map(VP9_COMP* cpi,
-                       unsigned char* new_map_16x16,
-                       int rows,
-                       int cols) {
-  if (rows == cpi->common.mb_rows && cols == cpi->common.mb_cols) {
-    unsigned char *const active_map_8x8 = cpi->active_map.map;
-    const int mi_rows = cpi->common.mi_rows;
-    const int mi_cols = cpi->common.mi_cols;
-    cpi->active_map.update = 1;
-    if (new_map_16x16) {
-      int r, c;
-      for (r = 0; r < mi_rows; ++r) {
-        for (c = 0; c < mi_cols; ++c) {
-          active_map_8x8[r * mi_cols + c] =
-              new_map_16x16[(r >> 1) * cols + (c >> 1)]
-                  ? AM_SEGMENT_ID_ACTIVE
-                  : AM_SEGMENT_ID_INACTIVE;
-        }
-      }
-      cpi->active_map.enabled = 1;
-    } else {
-      cpi->active_map.enabled = 0;
-    }
-    return 0;
-  } else {
-    return -1;
-  }
-}
-
-int vp9_get_active_map(VP9_COMP* cpi,
-                       unsigned char* new_map_16x16,
-                       int rows,
-                       int cols) {
-  if (rows == cpi->common.mb_rows && cols == cpi->common.mb_cols &&
-      new_map_16x16) {
-    unsigned char* const seg_map_8x8 = cpi->segmentation_map;
-    const int mi_rows = cpi->common.mi_rows;
-    const int mi_cols = cpi->common.mi_cols;
-    memset(new_map_16x16, !cpi->active_map.enabled, rows * cols);
-    if (cpi->active_map.enabled) {
-      int r, c;
-      for (r = 0; r < mi_rows; ++r) {
-        for (c = 0; c < mi_cols; ++c) {
-          // Cyclic refresh segments are considered active despite not having
-          // AM_SEGMENT_ID_ACTIVE
-          new_map_16x16[(r >> 1) * cols + (c >> 1)] |=
-              seg_map_8x8[r * mi_cols + c] != AM_SEGMENT_ID_INACTIVE;
-        }
-      }
-    }
-    return 0;
-  } else {
-    return -1;
-  }
-}
-
-void vp9_set_high_precision_mv(VP9_COMP *cpi, int allow_high_precision_mv) {
-  MACROBLOCK *const mb = &cpi->td.mb;
-  cpi->common.allow_high_precision_mv = allow_high_precision_mv;
-  if (cpi->common.allow_high_precision_mv) {
-    mb->mvcost = mb->nmvcost_hp;
-    mb->mvsadcost = mb->nmvsadcost_hp;
-  } else {
-    mb->mvcost = mb->nmvcost;
-    mb->mvsadcost = mb->nmvsadcost;
-  }
-}
-
-static void setup_frame(VP9_COMP *cpi) {
-  VP9_COMMON *const cm = &cpi->common;
-  // Set up entropy context depending on frame type. The decoder mandates
-  // the use of the default context, index 0, for keyframes and inter
-  // frames where the error_resilient_mode or intra_only flag is set. For
-  // other inter-frames the encoder currently uses only two contexts;
-  // context 1 for ALTREF frames and context 0 for the others.
-  if (frame_is_intra_only(cm) || cm->error_resilient_mode) {
-    vp9_setup_past_independence(cm);
-  } else {
-    if (!cpi->use_svc)
-      cm->frame_context_idx = cpi->refresh_alt_ref_frame;
-  }
-
-  if (cm->frame_type == KEY_FRAME) {
-    if (!is_two_pass_svc(cpi))
-      cpi->refresh_golden_frame = 1;
-    cpi->refresh_alt_ref_frame = 1;
-    vp9_zero(cpi->interp_filter_selected);
-  } else {
-    *cm->fc = cm->frame_contexts[cm->frame_context_idx];
-    vp9_zero(cpi->interp_filter_selected[0]);
-  }
-}
-
-static void vp9_enc_setup_mi(VP9_COMMON *cm) {
-  int i;
-  cm->mi = cm->mip + cm->mi_stride + 1;
-  memset(cm->mip, 0, cm->mi_stride * (cm->mi_rows + 1) * sizeof(*cm->mip));
-  cm->prev_mi = cm->prev_mip + cm->mi_stride + 1;
-  // Clear top border row
-  memset(cm->prev_mip, 0, sizeof(*cm->prev_mip) * cm->mi_stride);
-  // Clear left border column
-  for (i = 1; i < cm->mi_rows + 1; ++i)
-    memset(&cm->prev_mip[i * cm->mi_stride], 0, sizeof(*cm->prev_mip));
-
-  cm->mi_grid_visible = cm->mi_grid_base + cm->mi_stride + 1;
-  cm->prev_mi_grid_visible = cm->prev_mi_grid_base + cm->mi_stride + 1;
-
-  memset(cm->mi_grid_base, 0,
-         cm->mi_stride * (cm->mi_rows + 1) * sizeof(*cm->mi_grid_base));
-}
-
-static int vp9_enc_alloc_mi(VP9_COMMON *cm, int mi_size) {
-  cm->mip = vpx_calloc(mi_size, sizeof(*cm->mip));
-  if (!cm->mip)
-    return 1;
-  cm->prev_mip = vpx_calloc(mi_size, sizeof(*cm->prev_mip));
-  if (!cm->prev_mip)
-    return 1;
-  cm->mi_alloc_size = mi_size;
-
-  cm->mi_grid_base = (MODE_INFO **)vpx_calloc(mi_size, sizeof(MODE_INFO*));
-  if (!cm->mi_grid_base)
-    return 1;
-  cm->prev_mi_grid_base = (MODE_INFO **)vpx_calloc(mi_size, sizeof(MODE_INFO*));
-  if (!cm->prev_mi_grid_base)
-    return 1;
-
-  return 0;
-}
-
-static void vp9_enc_free_mi(VP9_COMMON *cm) {
-  vpx_free(cm->mip);
-  cm->mip = NULL;
-  vpx_free(cm->prev_mip);
-  cm->prev_mip = NULL;
-  vpx_free(cm->mi_grid_base);
-  cm->mi_grid_base = NULL;
-  vpx_free(cm->prev_mi_grid_base);
-  cm->prev_mi_grid_base = NULL;
-}
-
-static void vp9_swap_mi_and_prev_mi(VP9_COMMON *cm) {
-  // Current mip will be the prev_mip for the next frame.
-  MODE_INFO **temp_base = cm->prev_mi_grid_base;
-  MODE_INFO *temp = cm->prev_mip;
-  cm->prev_mip = cm->mip;
-  cm->mip = temp;
-
-  // Update the upper left visible macroblock ptrs.
-  cm->mi = cm->mip + cm->mi_stride + 1;
-  cm->prev_mi = cm->prev_mip + cm->mi_stride + 1;
-
-  cm->prev_mi_grid_base = cm->mi_grid_base;
-  cm->mi_grid_base = temp_base;
-  cm->mi_grid_visible = cm->mi_grid_base + cm->mi_stride + 1;
-  cm->prev_mi_grid_visible = cm->prev_mi_grid_base + cm->mi_stride + 1;
-}
-
-void vp9_initialize_enc(void) {
-  static volatile int init_done = 0;
-
-  if (!init_done) {
-    vp9_rtcd();
-    vpx_dsp_rtcd();
-    vpx_scale_rtcd();
-    vp9_init_intra_predictors();
-    vp9_init_me_luts();
-    vp9_rc_init_minq_luts();
-    vp9_entropy_mv_init();
-    vp9_temporal_filter_init();
-    init_done = 1;
-  }
-}
-
-static void dealloc_compressor_data(VP9_COMP *cpi) {
-  VP9_COMMON *const cm = &cpi->common;
-  int i;
-
-  vpx_free(cpi->mbmi_ext_base);
-  cpi->mbmi_ext_base = NULL;
-
-  vpx_free(cpi->tile_data);
-  cpi->tile_data = NULL;
-
-  // Delete sementation map
-  vpx_free(cpi->segmentation_map);
-  cpi->segmentation_map = NULL;
-  vpx_free(cpi->coding_context.last_frame_seg_map_copy);
-  cpi->coding_context.last_frame_seg_map_copy = NULL;
-
-  vpx_free(cpi->nmvcosts[0]);
-  vpx_free(cpi->nmvcosts[1]);
-  cpi->nmvcosts[0] = NULL;
-  cpi->nmvcosts[1] = NULL;
-
-  vpx_free(cpi->nmvcosts_hp[0]);
-  vpx_free(cpi->nmvcosts_hp[1]);
-  cpi->nmvcosts_hp[0] = NULL;
-  cpi->nmvcosts_hp[1] = NULL;
-
-  vpx_free(cpi->nmvsadcosts[0]);
-  vpx_free(cpi->nmvsadcosts[1]);
-  cpi->nmvsadcosts[0] = NULL;
-  cpi->nmvsadcosts[1] = NULL;
-
-  vpx_free(cpi->nmvsadcosts_hp[0]);
-  vpx_free(cpi->nmvsadcosts_hp[1]);
-  cpi->nmvsadcosts_hp[0] = NULL;
-  cpi->nmvsadcosts_hp[1] = NULL;
-
-  vp9_cyclic_refresh_free(cpi->cyclic_refresh);
-  cpi->cyclic_refresh = NULL;
-
-  vpx_free(cpi->active_map.map);
-  cpi->active_map.map = NULL;
-
-  vpx_free(cpi->consec_zero_mv);
-  cpi->consec_zero_mv = NULL;
-
-  vp9_free_ref_frame_buffers(cm->buffer_pool);
-#if CONFIG_VP9_POSTPROC
-  vp9_free_postproc_buffers(cm);
-#endif
-  vp9_free_context_buffers(cm);
-
-  vpx_free_frame_buffer(&cpi->last_frame_uf);
-  vpx_free_frame_buffer(&cpi->scaled_source);
-  vpx_free_frame_buffer(&cpi->scaled_last_source);
-  vpx_free_frame_buffer(&cpi->alt_ref_buffer);
-  vp9_lookahead_destroy(cpi->lookahead);
-
-  vpx_free(cpi->tile_tok[0][0]);
-  cpi->tile_tok[0][0] = 0;
-
-  vp9_free_pc_tree(&cpi->td);
-
-  for (i = 0; i < cpi->svc.number_spatial_layers; ++i) {
-    LAYER_CONTEXT *const lc = &cpi->svc.layer_context[i];
-    vpx_free(lc->rc_twopass_stats_in.buf);
-    lc->rc_twopass_stats_in.buf = NULL;
-    lc->rc_twopass_stats_in.sz = 0;
-  }
-
-  if (cpi->source_diff_var != NULL) {
-    vpx_free(cpi->source_diff_var);
-    cpi->source_diff_var = NULL;
-  }
-
-  for (i = 0; i < MAX_LAG_BUFFERS; ++i) {
-    vpx_free_frame_buffer(&cpi->svc.scaled_frames[i]);
-  }
-  memset(&cpi->svc.scaled_frames[0], 0,
-         MAX_LAG_BUFFERS * sizeof(cpi->svc.scaled_frames[0]));
-
-  vpx_free_frame_buffer(&cpi->svc.scaled_temp);
-  memset(&cpi->svc.scaled_temp, 0, sizeof(cpi->svc.scaled_temp));
-
-  vpx_free_frame_buffer(&cpi->svc.empty_frame.img);
-  memset(&cpi->svc.empty_frame, 0, sizeof(cpi->svc.empty_frame));
-
-  vp9_free_svc_cyclic_refresh(cpi);
-}
-
-static void save_coding_context(VP9_COMP *cpi) {
-  CODING_CONTEXT *const cc = &cpi->coding_context;
-  VP9_COMMON *cm = &cpi->common;
-
-  // Stores a snapshot of key state variables which can subsequently be
-  // restored with a call to vp9_restore_coding_context. These functions are
-  // intended for use in a re-code loop in vp9_compress_frame where the
-  // quantizer value is adjusted between loop iterations.
-  vp9_copy(cc->nmvjointcost,  cpi->td.mb.nmvjointcost);
-
-  memcpy(cc->nmvcosts[0], cpi->nmvcosts[0],
-         MV_VALS * sizeof(*cpi->nmvcosts[0]));
-  memcpy(cc->nmvcosts[1], cpi->nmvcosts[1],
-         MV_VALS * sizeof(*cpi->nmvcosts[1]));
-  memcpy(cc->nmvcosts_hp[0], cpi->nmvcosts_hp[0],
-         MV_VALS * sizeof(*cpi->nmvcosts_hp[0]));
-  memcpy(cc->nmvcosts_hp[1], cpi->nmvcosts_hp[1],
-         MV_VALS * sizeof(*cpi->nmvcosts_hp[1]));
-
-  vp9_copy(cc->segment_pred_probs, cm->seg.pred_probs);
-
-  memcpy(cpi->coding_context.last_frame_seg_map_copy,
-         cm->last_frame_seg_map, (cm->mi_rows * cm->mi_cols));
-
-  vp9_copy(cc->last_ref_lf_deltas, cm->lf.last_ref_deltas);
-  vp9_copy(cc->last_mode_lf_deltas, cm->lf.last_mode_deltas);
-
-  cc->fc = *cm->fc;
-}
-
-static void restore_coding_context(VP9_COMP *cpi) {
-  CODING_CONTEXT *const cc = &cpi->coding_context;
-  VP9_COMMON *cm = &cpi->common;
-
-  // Restore key state variables to the snapshot state stored in the
-  // previous call to vp9_save_coding_context.
-  vp9_copy(cpi->td.mb.nmvjointcost, cc->nmvjointcost);
-
-  memcpy(cpi->nmvcosts[0], cc->nmvcosts[0], MV_VALS * sizeof(*cc->nmvcosts[0]));
-  memcpy(cpi->nmvcosts[1], cc->nmvcosts[1], MV_VALS * sizeof(*cc->nmvcosts[1]));
-  memcpy(cpi->nmvcosts_hp[0], cc->nmvcosts_hp[0],
-         MV_VALS * sizeof(*cc->nmvcosts_hp[0]));
-  memcpy(cpi->nmvcosts_hp[1], cc->nmvcosts_hp[1],
-         MV_VALS * sizeof(*cc->nmvcosts_hp[1]));
-
-  vp9_copy(cm->seg.pred_probs, cc->segment_pred_probs);
-
-  memcpy(cm->last_frame_seg_map,
-         cpi->coding_context.last_frame_seg_map_copy,
-         (cm->mi_rows * cm->mi_cols));
-
-  vp9_copy(cm->lf.last_ref_deltas, cc->last_ref_lf_deltas);
-  vp9_copy(cm->lf.last_mode_deltas, cc->last_mode_lf_deltas);
-
-  *cm->fc = cc->fc;
-}
-
-static void configure_static_seg_features(VP9_COMP *cpi) {
-  VP9_COMMON *const cm = &cpi->common;
-  const RATE_CONTROL *const rc = &cpi->rc;
-  struct segmentation *const seg = &cm->seg;
-
-  int high_q = (int)(rc->avg_q > 48.0);
-  int qi_delta;
-
-  // Disable and clear down for KF
-  if (cm->frame_type == KEY_FRAME) {
-    // Clear down the global segmentation map
-    memset(cpi->segmentation_map, 0, cm->mi_rows * cm->mi_cols);
-    seg->update_map = 0;
-    seg->update_data = 0;
-    cpi->static_mb_pct = 0;
-
-    // Disable segmentation
-    vp9_disable_segmentation(seg);
-
-    // Clear down the segment features.
-    vp9_clearall_segfeatures(seg);
-  } else if (cpi->refresh_alt_ref_frame) {
-    // If this is an alt ref frame
-    // Clear down the global segmentation map
-    memset(cpi->segmentation_map, 0, cm->mi_rows * cm->mi_cols);
-    seg->update_map = 0;
-    seg->update_data = 0;
-    cpi->static_mb_pct = 0;
-
-    // Disable segmentation and individual segment features by default
-    vp9_disable_segmentation(seg);
-    vp9_clearall_segfeatures(seg);
-
-    // Scan frames from current to arf frame.
-    // This function re-enables segmentation if appropriate.
-    vp9_update_mbgraph_stats(cpi);
-
-    // If segmentation was enabled set those features needed for the
-    // arf itself.
-    if (seg->enabled) {
-      seg->update_map = 1;
-      seg->update_data = 1;
-
-      qi_delta = vp9_compute_qdelta(rc, rc->avg_q, rc->avg_q * 0.875,
-                                    cm->bit_depth);
-      vp9_set_segdata(seg, 1, SEG_LVL_ALT_Q, qi_delta - 2);
-      vp9_set_segdata(seg, 1, SEG_LVL_ALT_LF, -2);
-
-      vp9_enable_segfeature(seg, 1, SEG_LVL_ALT_Q);
-      vp9_enable_segfeature(seg, 1, SEG_LVL_ALT_LF);
-
-      // Where relevant assume segment data is delta data
-      seg->abs_delta = SEGMENT_DELTADATA;
-    }
-  } else if (seg->enabled) {
-    // All other frames if segmentation has been enabled
-
-    // First normal frame in a valid gf or alt ref group
-    if (rc->frames_since_golden == 0) {
-      // Set up segment features for normal frames in an arf group
-      if (rc->source_alt_ref_active) {
-        seg->update_map = 0;
-        seg->update_data = 1;
-        seg->abs_delta = SEGMENT_DELTADATA;
-
-        qi_delta = vp9_compute_qdelta(rc, rc->avg_q, rc->avg_q * 1.125,
-                                      cm->bit_depth);
-        vp9_set_segdata(seg, 1, SEG_LVL_ALT_Q, qi_delta + 2);
-        vp9_enable_segfeature(seg, 1, SEG_LVL_ALT_Q);
-
-        vp9_set_segdata(seg, 1, SEG_LVL_ALT_LF, -2);
-        vp9_enable_segfeature(seg, 1, SEG_LVL_ALT_LF);
-
-        // Segment coding disabled for compred testing
-        if (high_q || (cpi->static_mb_pct == 100)) {
-          vp9_set_segdata(seg, 1, SEG_LVL_REF_FRAME, ALTREF_FRAME);
-          vp9_enable_segfeature(seg, 1, SEG_LVL_REF_FRAME);
-          vp9_enable_segfeature(seg, 1, SEG_LVL_SKIP);
-        }
-      } else {
-        // Disable segmentation and clear down features if alt ref
-        // is not active for this group
-
-        vp9_disable_segmentation(seg);
-
-        memset(cpi->segmentation_map, 0, cm->mi_rows * cm->mi_cols);
-
-        seg->update_map = 0;
-        seg->update_data = 0;
-
-        vp9_clearall_segfeatures(seg);
-      }
-    } else if (rc->is_src_frame_alt_ref) {
-      // Special case where we are coding over the top of a previous
-      // alt ref frame.
-      // Segment coding disabled for compred testing
-
-      // Enable ref frame features for segment 0 as well
-      vp9_enable_segfeature(seg, 0, SEG_LVL_REF_FRAME);
-      vp9_enable_segfeature(seg, 1, SEG_LVL_REF_FRAME);
-
-      // All mbs should use ALTREF_FRAME
-      vp9_clear_segdata(seg, 0, SEG_LVL_REF_FRAME);
-      vp9_set_segdata(seg, 0, SEG_LVL_REF_FRAME, ALTREF_FRAME);
-      vp9_clear_segdata(seg, 1, SEG_LVL_REF_FRAME);
-      vp9_set_segdata(seg, 1, SEG_LVL_REF_FRAME, ALTREF_FRAME);
-
-      // Skip all MBs if high Q (0,0 mv and skip coeffs)
-      if (high_q) {
-        vp9_enable_segfeature(seg, 0, SEG_LVL_SKIP);
-        vp9_enable_segfeature(seg, 1, SEG_LVL_SKIP);
-      }
-      // Enable data update
-      seg->update_data = 1;
-    } else {
-      // All other frames.
-
-      // No updates.. leave things as they are.
-      seg->update_map = 0;
-      seg->update_data = 0;
-    }
-  }
-}
-
-static void update_reference_segmentation_map(VP9_COMP *cpi) {
-  VP9_COMMON *const cm = &cpi->common;
-  MODE_INFO **mi_8x8_ptr = cm->mi_grid_visible;
-  uint8_t *cache_ptr = cm->last_frame_seg_map;
-  int row, col;
-
-  for (row = 0; row < cm->mi_rows; row++) {
-    MODE_INFO **mi_8x8 = mi_8x8_ptr;
-    uint8_t *cache = cache_ptr;
-    for (col = 0; col < cm->mi_cols; col++, mi_8x8++, cache++)
-      cache[0] = mi_8x8[0]->segment_id;
-    mi_8x8_ptr += cm->mi_stride;
-    cache_ptr += cm->mi_cols;
-  }
-}
-
-static void alloc_raw_frame_buffers(VP9_COMP *cpi) {
-  VP9_COMMON *cm = &cpi->common;
-  const VP9EncoderConfig *oxcf = &cpi->oxcf;
-
-  if (!cpi->lookahead)
-    cpi->lookahead = vp9_lookahead_init(oxcf->width, oxcf->height,
-                                        cm->subsampling_x, cm->subsampling_y,
-#if CONFIG_VP9_HIGHBITDEPTH
-                                      cm->use_highbitdepth,
-#endif
-                                      oxcf->lag_in_frames);
-  if (!cpi->lookahead)
-    vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR,
-                       "Failed to allocate lag buffers");
-
-  // TODO(agrange) Check if ARF is enabled and skip allocation if not.
-  if (vpx_realloc_frame_buffer(&cpi->alt_ref_buffer,
-                               oxcf->width, oxcf->height,
-                               cm->subsampling_x, cm->subsampling_y,
-#if CONFIG_VP9_HIGHBITDEPTH
-                               cm->use_highbitdepth,
-#endif
-                               VP9_ENC_BORDER_IN_PIXELS, cm->byte_alignment,
-                               NULL, NULL, NULL))
-    vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR,
-                       "Failed to allocate altref buffer");
-}
-
-static void alloc_util_frame_buffers(VP9_COMP *cpi) {
-  VP9_COMMON *const cm = &cpi->common;
-  if (vpx_realloc_frame_buffer(&cpi->last_frame_uf,
-                               cm->width, cm->height,
-                               cm->subsampling_x, cm->subsampling_y,
-#if CONFIG_VP9_HIGHBITDEPTH
-                               cm->use_highbitdepth,
-#endif
-                               VP9_ENC_BORDER_IN_PIXELS, cm->byte_alignment,
-                               NULL, NULL, NULL))
-    vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR,
-                       "Failed to allocate last frame buffer");
-
-  if (vpx_realloc_frame_buffer(&cpi->scaled_source,
-                               cm->width, cm->height,
-                               cm->subsampling_x, cm->subsampling_y,
-#if CONFIG_VP9_HIGHBITDEPTH
-                               cm->use_highbitdepth,
-#endif
-                               VP9_ENC_BORDER_IN_PIXELS, cm->byte_alignment,
-                               NULL, NULL, NULL))
-    vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR,
-                       "Failed to allocate scaled source buffer");
-
-  if (vpx_realloc_frame_buffer(&cpi->scaled_last_source,
-                               cm->width, cm->height,
-                               cm->subsampling_x, cm->subsampling_y,
-#if CONFIG_VP9_HIGHBITDEPTH
-                               cm->use_highbitdepth,
-#endif
-                               VP9_ENC_BORDER_IN_PIXELS, cm->byte_alignment,
-                               NULL, NULL, NULL))
-    vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR,
-                       "Failed to allocate scaled last source buffer");
-}
-
-
-static int alloc_context_buffers_ext(VP9_COMP *cpi) {
-  VP9_COMMON *cm = &cpi->common;
-  int mi_size = cm->mi_cols * cm->mi_rows;
-
-  cpi->mbmi_ext_base = vpx_calloc(mi_size, sizeof(*cpi->mbmi_ext_base));
-  if (!cpi->mbmi_ext_base)
-    return 1;
-
-  return 0;
-}
-
-static void alloc_compressor_data(VP9_COMP *cpi) {
-  VP9_COMMON *cm = &cpi->common;
-
-  vp9_alloc_context_buffers(cm, cm->width, cm->height);
-
-  alloc_context_buffers_ext(cpi);
-
-  vpx_free(cpi->tile_tok[0][0]);
-
-  {
-    unsigned int tokens = get_token_alloc(cm->mb_rows, cm->mb_cols);
-    CHECK_MEM_ERROR(cm, cpi->tile_tok[0][0],
-        vpx_calloc(tokens, sizeof(*cpi->tile_tok[0][0])));
-  }
-
-  vp9_setup_pc_tree(&cpi->common, &cpi->td);
-}
-
-void vp9_new_framerate(VP9_COMP *cpi, double framerate) {
-  cpi->framerate = framerate < 0.1 ? 30 : framerate;
-  vp9_rc_update_framerate(cpi);
-}
-
-static void set_tile_limits(VP9_COMP *cpi) {
-  VP9_COMMON *const cm = &cpi->common;
-
-  int min_log2_tile_cols, max_log2_tile_cols;
-  vp9_get_tile_n_bits(cm->mi_cols, &min_log2_tile_cols, &max_log2_tile_cols);
-
-  if (is_two_pass_svc(cpi) &&
-      (cpi->svc.encode_empty_frame_state == ENCODING ||
-      cpi->svc.number_spatial_layers > 1)) {
-    cm->log2_tile_cols = 0;
-    cm->log2_tile_rows = 0;
-  } else {
-    cm->log2_tile_cols = clamp(cpi->oxcf.tile_columns,
-                               min_log2_tile_cols, max_log2_tile_cols);
-    cm->log2_tile_rows = cpi->oxcf.tile_rows;
-  }
-}
-
-static void update_frame_size(VP9_COMP *cpi) {
-  VP9_COMMON *const cm = &cpi->common;
-  MACROBLOCKD *const xd = &cpi->td.mb.e_mbd;
-
-  vp9_set_mb_mi(cm, cm->width, cm->height);
-  vp9_init_context_buffers(cm);
-  vp9_init_macroblockd(cm, xd, NULL);
-  cpi->td.mb.mbmi_ext_base = cpi->mbmi_ext_base;
-  memset(cpi->mbmi_ext_base, 0,
-         cm->mi_rows * cm->mi_cols * sizeof(*cpi->mbmi_ext_base));
-
-  set_tile_limits(cpi);
-
-  if (is_two_pass_svc(cpi)) {
-    if (vpx_realloc_frame_buffer(&cpi->alt_ref_buffer,
-                                 cm->width, cm->height,
-                                 cm->subsampling_x, cm->subsampling_y,
-#if CONFIG_VP9_HIGHBITDEPTH
-                                 cm->use_highbitdepth,
-#endif
-                                 VP9_ENC_BORDER_IN_PIXELS, cm->byte_alignment,
-                                 NULL, NULL, NULL))
-      vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR,
-                         "Failed to reallocate alt_ref_buffer");
-  }
-}
-
-static void init_buffer_indices(VP9_COMP *cpi) {
-  cpi->lst_fb_idx = 0;
-  cpi->gld_fb_idx = 1;
-  cpi->alt_fb_idx = 2;
-}
-
-static void init_config(struct VP9_COMP *cpi, VP9EncoderConfig *oxcf) {
-  VP9_COMMON *const cm = &cpi->common;
-
-  cpi->oxcf = *oxcf;
-  cpi->framerate = oxcf->init_framerate;
-  cm->profile = oxcf->profile;
-  cm->bit_depth = oxcf->bit_depth;
-#if CONFIG_VP9_HIGHBITDEPTH
-  cm->use_highbitdepth = oxcf->use_highbitdepth;
-#endif
-  cm->color_space = oxcf->color_space;
-  cm->color_range = oxcf->color_range;
-
-  cpi->target_level = oxcf->target_level;
-  cpi->keep_level_stats = oxcf->target_level != LEVEL_MAX;
-
-  cm->width = oxcf->width;
-  cm->height = oxcf->height;
-  alloc_compressor_data(cpi);
-
-  cpi->svc.temporal_layering_mode = oxcf->temporal_layering_mode;
-
-  // Single thread case: use counts in common.
-  cpi->td.counts = &cm->counts;
-
-  // Spatial scalability.
-  cpi->svc.number_spatial_layers = oxcf->ss_number_layers;
-  // Temporal scalability.
-  cpi->svc.number_temporal_layers = oxcf->ts_number_layers;
-
-  if ((cpi->svc.number_temporal_layers > 1 && cpi->oxcf.rc_mode == VPX_CBR) ||
-      ((cpi->svc.number_temporal_layers > 1 ||
-        cpi->svc.number_spatial_layers > 1) &&
-       cpi->oxcf.pass != 1)) {
-    vp9_init_layer_context(cpi);
-  }
-
-  // change includes all joint functionality
-  vp9_change_config(cpi, oxcf);
-
-  cpi->static_mb_pct = 0;
-  cpi->ref_frame_flags = 0;
-
-  init_buffer_indices(cpi);
-
-  vp9_noise_estimate_init(&cpi->noise_estimate, cm->width, cm->height);
-}
-
-static void set_rc_buffer_sizes(RATE_CONTROL *rc,
-                                const VP9EncoderConfig *oxcf) {
-  const int64_t bandwidth = oxcf->target_bandwidth;
-  const int64_t starting = oxcf->starting_buffer_level_ms;
-  const int64_t optimal = oxcf->optimal_buffer_level_ms;
-  const int64_t maximum = oxcf->maximum_buffer_size_ms;
-
-  rc->starting_buffer_level = starting * bandwidth / 1000;
-  rc->optimal_buffer_level = (optimal == 0) ? bandwidth / 8
-                                            : optimal * bandwidth / 1000;
-  rc->maximum_buffer_size = (maximum == 0) ? bandwidth / 8
-                                           : maximum * bandwidth / 1000;
-}
-
-#if CONFIG_VP9_HIGHBITDEPTH
-#define HIGHBD_BFP(BT, SDF, SDAF, VF, SVF, SVAF, SDX3F, SDX8F, SDX4DF) \
-    cpi->fn_ptr[BT].sdf = SDF; \
-    cpi->fn_ptr[BT].sdaf = SDAF; \
-    cpi->fn_ptr[BT].vf = VF; \
-    cpi->fn_ptr[BT].svf = SVF; \
-    cpi->fn_ptr[BT].svaf = SVAF; \
-    cpi->fn_ptr[BT].sdx3f = SDX3F; \
-    cpi->fn_ptr[BT].sdx8f = SDX8F; \
-    cpi->fn_ptr[BT].sdx4df = SDX4DF;
-
-#define MAKE_BFP_SAD_WRAPPER(fnname) \
-static unsigned int fnname##_bits8(const uint8_t *src_ptr, \
-                                   int source_stride, \
-                                   const uint8_t *ref_ptr, \
-                                   int ref_stride) {  \
-  return fnname(src_ptr, source_stride, ref_ptr, ref_stride); \
-} \
-static unsigned int fnname##_bits10(const uint8_t *src_ptr, \
-                                    int source_stride, \
-                                    const uint8_t *ref_ptr, \
-                                    int ref_stride) {  \
-  return fnname(src_ptr, source_stride, ref_ptr, ref_stride) >> 2; \
-} \
-static unsigned int fnname##_bits12(const uint8_t *src_ptr, \
-                                    int source_stride, \
-                                    const uint8_t *ref_ptr, \
-                                    int ref_stride) {  \
-  return fnname(src_ptr, source_stride, ref_ptr, ref_stride) >> 4; \
-}
-
-#define MAKE_BFP_SADAVG_WRAPPER(fnname) static unsigned int \
-fnname##_bits8(const uint8_t *src_ptr, \
-               int source_stride, \
-               const uint8_t *ref_ptr, \
-               int ref_stride, \
-               const uint8_t *second_pred) {  \
-  return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred); \
-} \
-static unsigned int fnname##_bits10(const uint8_t *src_ptr, \
-                                    int source_stride, \
-                                    const uint8_t *ref_ptr, \
-                                    int ref_stride, \
-                                    const uint8_t *second_pred) {  \
-  return fnname(src_ptr, source_stride, ref_ptr, ref_stride, \
-                second_pred) >> 2; \
-} \
-static unsigned int fnname##_bits12(const uint8_t *src_ptr, \
-                                    int source_stride, \
-                                    const uint8_t *ref_ptr, \
-                                    int ref_stride, \
-                                    const uint8_t *second_pred) {  \
-  return fnname(src_ptr, source_stride, ref_ptr, ref_stride, \
-                second_pred) >> 4; \
-}
-
-#define MAKE_BFP_SAD3_WRAPPER(fnname) \
-static void fnname##_bits8(const uint8_t *src_ptr, \
-                           int source_stride, \
-                           const uint8_t *ref_ptr, \
-                           int  ref_stride, \
-                           unsigned int *sad_array) {  \
-  fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \
-} \
-static void fnname##_bits10(const uint8_t *src_ptr, \
-                            int source_stride, \
-                            const uint8_t *ref_ptr, \
-                            int  ref_stride, \
-                            unsigned int *sad_array) {  \
-  int i; \
-  fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \
-  for (i = 0; i < 3; i++) \
-    sad_array[i] >>= 2; \
-} \
-static void fnname##_bits12(const uint8_t *src_ptr, \
-                            int source_stride, \
-                            const uint8_t *ref_ptr, \
-                            int  ref_stride, \
-                            unsigned int *sad_array) {  \
-  int i; \
-  fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \
-  for (i = 0; i < 3; i++) \
-    sad_array[i] >>= 4; \
-}
-
-#define MAKE_BFP_SAD8_WRAPPER(fnname) \
-static void fnname##_bits8(const uint8_t *src_ptr, \
-                           int source_stride, \
-                           const uint8_t *ref_ptr, \
-                           int  ref_stride, \
-                           unsigned int *sad_array) {  \
-  fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \
-} \
-static void fnname##_bits10(const uint8_t *src_ptr, \
-                            int source_stride, \
-                            const uint8_t *ref_ptr, \
-                            int  ref_stride, \
-                            unsigned int *sad_array) {  \
-  int i; \
-  fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \
-  for (i = 0; i < 8; i++) \
-    sad_array[i] >>= 2; \
-} \
-static void fnname##_bits12(const uint8_t *src_ptr, \
-                            int source_stride, \
-                            const uint8_t *ref_ptr, \
-                            int  ref_stride, \
-                            unsigned int *sad_array) {  \
-  int i; \
-  fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \
-  for (i = 0; i < 8; i++) \
-    sad_array[i] >>= 4; \
-}
-#define MAKE_BFP_SAD4D_WRAPPER(fnname) \
-static void fnname##_bits8(const uint8_t *src_ptr, \
-                           int source_stride, \
-                           const uint8_t* const ref_ptr[], \
-                           int  ref_stride, \
-                           unsigned int *sad_array) {  \
-  fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \
-} \
-static void fnname##_bits10(const uint8_t *src_ptr, \
-                            int source_stride, \
-                            const uint8_t* const ref_ptr[], \
-                            int  ref_stride, \
-                            unsigned int *sad_array) {  \
-  int i; \
-  fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \
-  for (i = 0; i < 4; i++) \
-  sad_array[i] >>= 2; \
-} \
-static void fnname##_bits12(const uint8_t *src_ptr, \
-                            int source_stride, \
-                            const uint8_t* const ref_ptr[], \
-                            int  ref_stride, \
-                            unsigned int *sad_array) {  \
-  int i; \
-  fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \
-  for (i = 0; i < 4; i++) \
-  sad_array[i] >>= 4; \
-}
-
-MAKE_BFP_SAD_WRAPPER(vpx_highbd_sad32x16)
-MAKE_BFP_SADAVG_WRAPPER(vpx_highbd_sad32x16_avg)
-MAKE_BFP_SAD4D_WRAPPER(vpx_highbd_sad32x16x4d)
-MAKE_BFP_SAD_WRAPPER(vpx_highbd_sad16x32)
-MAKE_BFP_SADAVG_WRAPPER(vpx_highbd_sad16x32_avg)
-MAKE_BFP_SAD4D_WRAPPER(vpx_highbd_sad16x32x4d)
-MAKE_BFP_SAD_WRAPPER(vpx_highbd_sad64x32)
-MAKE_BFP_SADAVG_WRAPPER(vpx_highbd_sad64x32_avg)
-MAKE_BFP_SAD4D_WRAPPER(vpx_highbd_sad64x32x4d)
-MAKE_BFP_SAD_WRAPPER(vpx_highbd_sad32x64)
-MAKE_BFP_SADAVG_WRAPPER(vpx_highbd_sad32x64_avg)
-MAKE_BFP_SAD4D_WRAPPER(vpx_highbd_sad32x64x4d)
-MAKE_BFP_SAD_WRAPPER(vpx_highbd_sad32x32)
-MAKE_BFP_SADAVG_WRAPPER(vpx_highbd_sad32x32_avg)
-MAKE_BFP_SAD3_WRAPPER(vpx_highbd_sad32x32x3)
-MAKE_BFP_SAD8_WRAPPER(vpx_highbd_sad32x32x8)
-MAKE_BFP_SAD4D_WRAPPER(vpx_highbd_sad32x32x4d)
-MAKE_BFP_SAD_WRAPPER(vpx_highbd_sad64x64)
-MAKE_BFP_SADAVG_WRAPPER(vpx_highbd_sad64x64_avg)
-MAKE_BFP_SAD3_WRAPPER(vpx_highbd_sad64x64x3)
-MAKE_BFP_SAD8_WRAPPER(vpx_highbd_sad64x64x8)
-MAKE_BFP_SAD4D_WRAPPER(vpx_highbd_sad64x64x4d)
-MAKE_BFP_SAD_WRAPPER(vpx_highbd_sad16x16)
-MAKE_BFP_SADAVG_WRAPPER(vpx_highbd_sad16x16_avg)
-MAKE_BFP_SAD3_WRAPPER(vpx_highbd_sad16x16x3)
-MAKE_BFP_SAD8_WRAPPER(vpx_highbd_sad16x16x8)
-MAKE_BFP_SAD4D_WRAPPER(vpx_highbd_sad16x16x4d)
-MAKE_BFP_SAD_WRAPPER(vpx_highbd_sad16x8)
-MAKE_BFP_SADAVG_WRAPPER(vpx_highbd_sad16x8_avg)
-MAKE_BFP_SAD3_WRAPPER(vpx_highbd_sad16x8x3)
-MAKE_BFP_SAD8_WRAPPER(vpx_highbd_sad16x8x8)
-MAKE_BFP_SAD4D_WRAPPER(vpx_highbd_sad16x8x4d)
-MAKE_BFP_SAD_WRAPPER(vpx_highbd_sad8x16)
-MAKE_BFP_SADAVG_WRAPPER(vpx_highbd_sad8x16_avg)
-MAKE_BFP_SAD3_WRAPPER(vpx_highbd_sad8x16x3)
-MAKE_BFP_SAD8_WRAPPER(vpx_highbd_sad8x16x8)
-MAKE_BFP_SAD4D_WRAPPER(vpx_highbd_sad8x16x4d)
-MAKE_BFP_SAD_WRAPPER(vpx_highbd_sad8x8)
-MAKE_BFP_SADAVG_WRAPPER(vpx_highbd_sad8x8_avg)
-MAKE_BFP_SAD3_WRAPPER(vpx_highbd_sad8x8x3)
-MAKE_BFP_SAD8_WRAPPER(vpx_highbd_sad8x8x8)
-MAKE_BFP_SAD4D_WRAPPER(vpx_highbd_sad8x8x4d)
-MAKE_BFP_SAD_WRAPPER(vpx_highbd_sad8x4)
-MAKE_BFP_SADAVG_WRAPPER(vpx_highbd_sad8x4_avg)
-MAKE_BFP_SAD8_WRAPPER(vpx_highbd_sad8x4x8)
-MAKE_BFP_SAD4D_WRAPPER(vpx_highbd_sad8x4x4d)
-MAKE_BFP_SAD_WRAPPER(vpx_highbd_sad4x8)
-MAKE_BFP_SADAVG_WRAPPER(vpx_highbd_sad4x8_avg)
-MAKE_BFP_SAD8_WRAPPER(vpx_highbd_sad4x8x8)
-MAKE_BFP_SAD4D_WRAPPER(vpx_highbd_sad4x8x4d)
-MAKE_BFP_SAD_WRAPPER(vpx_highbd_sad4x4)
-MAKE_BFP_SADAVG_WRAPPER(vpx_highbd_sad4x4_avg)
-MAKE_BFP_SAD3_WRAPPER(vpx_highbd_sad4x4x3)
-MAKE_BFP_SAD8_WRAPPER(vpx_highbd_sad4x4x8)
-MAKE_BFP_SAD4D_WRAPPER(vpx_highbd_sad4x4x4d)
-
-static void  highbd_set_var_fns(VP9_COMP *const cpi) {
-  VP9_COMMON *const cm = &cpi->common;
-  if (cm->use_highbitdepth) {
-    switch (cm->bit_depth) {
-      case VPX_BITS_8:
-        HIGHBD_BFP(BLOCK_32X16,
-                   vpx_highbd_sad32x16_bits8,
-                   vpx_highbd_sad32x16_avg_bits8,
-                   vpx_highbd_8_variance32x16,
-                   vpx_highbd_8_sub_pixel_variance32x16,
-                   vpx_highbd_8_sub_pixel_avg_variance32x16,
-                   NULL,
-                   NULL,
-                   vpx_highbd_sad32x16x4d_bits8)
-
-        HIGHBD_BFP(BLOCK_16X32,
-                   vpx_highbd_sad16x32_bits8,
-                   vpx_highbd_sad16x32_avg_bits8,
-                   vpx_highbd_8_variance16x32,
-                   vpx_highbd_8_sub_pixel_variance16x32,
-                   vpx_highbd_8_sub_pixel_avg_variance16x32,
-                   NULL,
-                   NULL,
-                   vpx_highbd_sad16x32x4d_bits8)
-
-        HIGHBD_BFP(BLOCK_64X32,
-                   vpx_highbd_sad64x32_bits8,
-                   vpx_highbd_sad64x32_avg_bits8,
-                   vpx_highbd_8_variance64x32,
-                   vpx_highbd_8_sub_pixel_variance64x32,
-                   vpx_highbd_8_sub_pixel_avg_variance64x32,
-                   NULL,
-                   NULL,
-                   vpx_highbd_sad64x32x4d_bits8)
-
-        HIGHBD_BFP(BLOCK_32X64,
-                   vpx_highbd_sad32x64_bits8,
-                   vpx_highbd_sad32x64_avg_bits8,
-                   vpx_highbd_8_variance32x64,
-                   vpx_highbd_8_sub_pixel_variance32x64,
-                   vpx_highbd_8_sub_pixel_avg_variance32x64,
-                   NULL,
-                   NULL,
-                   vpx_highbd_sad32x64x4d_bits8)
-
-        HIGHBD_BFP(BLOCK_32X32,
-                   vpx_highbd_sad32x32_bits8,
-                   vpx_highbd_sad32x32_avg_bits8,
-                   vpx_highbd_8_variance32x32,
-                   vpx_highbd_8_sub_pixel_variance32x32,
-                   vpx_highbd_8_sub_pixel_avg_variance32x32,
-                   vpx_highbd_sad32x32x3_bits8,
-                   vpx_highbd_sad32x32x8_bits8,
-                   vpx_highbd_sad32x32x4d_bits8)
-
-        HIGHBD_BFP(BLOCK_64X64,
-                   vpx_highbd_sad64x64_bits8,
-                   vpx_highbd_sad64x64_avg_bits8,
-                   vpx_highbd_8_variance64x64,
-                   vpx_highbd_8_sub_pixel_variance64x64,
-                   vpx_highbd_8_sub_pixel_avg_variance64x64,
-                   vpx_highbd_sad64x64x3_bits8,
-                   vpx_highbd_sad64x64x8_bits8,
-                   vpx_highbd_sad64x64x4d_bits8)
-
-        HIGHBD_BFP(BLOCK_16X16,
-                   vpx_highbd_sad16x16_bits8,
-                   vpx_highbd_sad16x16_avg_bits8,
-                   vpx_highbd_8_variance16x16,
-                   vpx_highbd_8_sub_pixel_variance16x16,
-                   vpx_highbd_8_sub_pixel_avg_variance16x16,
-                   vpx_highbd_sad16x16x3_bits8,
-                   vpx_highbd_sad16x16x8_bits8,
-                   vpx_highbd_sad16x16x4d_bits8)
-
-        HIGHBD_BFP(BLOCK_16X8,
-                   vpx_highbd_sad16x8_bits8,
-                   vpx_highbd_sad16x8_avg_bits8,
-                   vpx_highbd_8_variance16x8,
-                   vpx_highbd_8_sub_pixel_variance16x8,
-                   vpx_highbd_8_sub_pixel_avg_variance16x8,
-                   vpx_highbd_sad16x8x3_bits8,
-                   vpx_highbd_sad16x8x8_bits8,
-                   vpx_highbd_sad16x8x4d_bits8)
-
-        HIGHBD_BFP(BLOCK_8X16,
-                   vpx_highbd_sad8x16_bits8,
-                   vpx_highbd_sad8x16_avg_bits8,
-                   vpx_highbd_8_variance8x16,
-                   vpx_highbd_8_sub_pixel_variance8x16,
-                   vpx_highbd_8_sub_pixel_avg_variance8x16,
-                   vpx_highbd_sad8x16x3_bits8,
-                   vpx_highbd_sad8x16x8_bits8,
-                   vpx_highbd_sad8x16x4d_bits8)
-
-        HIGHBD_BFP(BLOCK_8X8,
-                   vpx_highbd_sad8x8_bits8,
-                   vpx_highbd_sad8x8_avg_bits8,
-                   vpx_highbd_8_variance8x8,
-                   vpx_highbd_8_sub_pixel_variance8x8,
-                   vpx_highbd_8_sub_pixel_avg_variance8x8,
-                   vpx_highbd_sad8x8x3_bits8,
-                   vpx_highbd_sad8x8x8_bits8,
-                   vpx_highbd_sad8x8x4d_bits8)
-
-        HIGHBD_BFP(BLOCK_8X4,
-                   vpx_highbd_sad8x4_bits8,
-                   vpx_highbd_sad8x4_avg_bits8,
-                   vpx_highbd_8_variance8x4,
-                   vpx_highbd_8_sub_pixel_variance8x4,
-                   vpx_highbd_8_sub_pixel_avg_variance8x4,
-                   NULL,
-                   vpx_highbd_sad8x4x8_bits8,
-                   vpx_highbd_sad8x4x4d_bits8)
-
-        HIGHBD_BFP(BLOCK_4X8,
-                   vpx_highbd_sad4x8_bits8,
-                   vpx_highbd_sad4x8_avg_bits8,
-                   vpx_highbd_8_variance4x8,
-                   vpx_highbd_8_sub_pixel_variance4x8,
-                   vpx_highbd_8_sub_pixel_avg_variance4x8,
-                   NULL,
-                   vpx_highbd_sad4x8x8_bits8,
-                   vpx_highbd_sad4x8x4d_bits8)
-
-        HIGHBD_BFP(BLOCK_4X4,
-                   vpx_highbd_sad4x4_bits8,
-                   vpx_highbd_sad4x4_avg_bits8,
-                   vpx_highbd_8_variance4x4,
-                   vpx_highbd_8_sub_pixel_variance4x4,
-                   vpx_highbd_8_sub_pixel_avg_variance4x4,
-                   vpx_highbd_sad4x4x3_bits8,
-                   vpx_highbd_sad4x4x8_bits8,
-                   vpx_highbd_sad4x4x4d_bits8)
-        break;
-
-      case VPX_BITS_10:
-        HIGHBD_BFP(BLOCK_32X16,
-                   vpx_highbd_sad32x16_bits10,
-                   vpx_highbd_sad32x16_avg_bits10,
-                   vpx_highbd_10_variance32x16,
-                   vpx_highbd_10_sub_pixel_variance32x16,
-                   vpx_highbd_10_sub_pixel_avg_variance32x16,
-                   NULL,
-                   NULL,
-                   vpx_highbd_sad32x16x4d_bits10)
-
-        HIGHBD_BFP(BLOCK_16X32,
-                   vpx_highbd_sad16x32_bits10,
-                   vpx_highbd_sad16x32_avg_bits10,
-                   vpx_highbd_10_variance16x32,
-                   vpx_highbd_10_sub_pixel_variance16x32,
-                   vpx_highbd_10_sub_pixel_avg_variance16x32,
-                   NULL,
-                   NULL,
-                   vpx_highbd_sad16x32x4d_bits10)
-
-        HIGHBD_BFP(BLOCK_64X32,
-                   vpx_highbd_sad64x32_bits10,
-                   vpx_highbd_sad64x32_avg_bits10,
-                   vpx_highbd_10_variance64x32,
-                   vpx_highbd_10_sub_pixel_variance64x32,
-                   vpx_highbd_10_sub_pixel_avg_variance64x32,
-                   NULL,
-                   NULL,
-                   vpx_highbd_sad64x32x4d_bits10)
-
-        HIGHBD_BFP(BLOCK_32X64,
-                   vpx_highbd_sad32x64_bits10,
-                   vpx_highbd_sad32x64_avg_bits10,
-                   vpx_highbd_10_variance32x64,
-                   vpx_highbd_10_sub_pixel_variance32x64,
-                   vpx_highbd_10_sub_pixel_avg_variance32x64,
-                   NULL,
-                   NULL,
-                   vpx_highbd_sad32x64x4d_bits10)
-
-        HIGHBD_BFP(BLOCK_32X32,
-                   vpx_highbd_sad32x32_bits10,
-                   vpx_highbd_sad32x32_avg_bits10,
-                   vpx_highbd_10_variance32x32,
-                   vpx_highbd_10_sub_pixel_variance32x32,
-                   vpx_highbd_10_sub_pixel_avg_variance32x32,
-                   vpx_highbd_sad32x32x3_bits10,
-                   vpx_highbd_sad32x32x8_bits10,
-                   vpx_highbd_sad32x32x4d_bits10)
-
-        HIGHBD_BFP(BLOCK_64X64,
-                   vpx_highbd_sad64x64_bits10,
-                   vpx_highbd_sad64x64_avg_bits10,
-                   vpx_highbd_10_variance64x64,
-                   vpx_highbd_10_sub_pixel_variance64x64,
-                   vpx_highbd_10_sub_pixel_avg_variance64x64,
-                   vpx_highbd_sad64x64x3_bits10,
-                   vpx_highbd_sad64x64x8_bits10,
-                   vpx_highbd_sad64x64x4d_bits10)
-
-        HIGHBD_BFP(BLOCK_16X16,
-                   vpx_highbd_sad16x16_bits10,
-                   vpx_highbd_sad16x16_avg_bits10,
-                   vpx_highbd_10_variance16x16,
-                   vpx_highbd_10_sub_pixel_variance16x16,
-                   vpx_highbd_10_sub_pixel_avg_variance16x16,
-                   vpx_highbd_sad16x16x3_bits10,
-                   vpx_highbd_sad16x16x8_bits10,
-                   vpx_highbd_sad16x16x4d_bits10)
-
-        HIGHBD_BFP(BLOCK_16X8,
-                   vpx_highbd_sad16x8_bits10,
-                   vpx_highbd_sad16x8_avg_bits10,
-                   vpx_highbd_10_variance16x8,
-                   vpx_highbd_10_sub_pixel_variance16x8,
-                   vpx_highbd_10_sub_pixel_avg_variance16x8,
-                   vpx_highbd_sad16x8x3_bits10,
-                   vpx_highbd_sad16x8x8_bits10,
-                   vpx_highbd_sad16x8x4d_bits10)
-
-        HIGHBD_BFP(BLOCK_8X16,
-                   vpx_highbd_sad8x16_bits10,
-                   vpx_highbd_sad8x16_avg_bits10,
-                   vpx_highbd_10_variance8x16,
-                   vpx_highbd_10_sub_pixel_variance8x16,
-                   vpx_highbd_10_sub_pixel_avg_variance8x16,
-                   vpx_highbd_sad8x16x3_bits10,
-                   vpx_highbd_sad8x16x8_bits10,
-                   vpx_highbd_sad8x16x4d_bits10)
-
-        HIGHBD_BFP(BLOCK_8X8,
-                   vpx_highbd_sad8x8_bits10,
-                   vpx_highbd_sad8x8_avg_bits10,
-                   vpx_highbd_10_variance8x8,
-                   vpx_highbd_10_sub_pixel_variance8x8,
-                   vpx_highbd_10_sub_pixel_avg_variance8x8,
-                   vpx_highbd_sad8x8x3_bits10,
-                   vpx_highbd_sad8x8x8_bits10,
-                   vpx_highbd_sad8x8x4d_bits10)
-
-        HIGHBD_BFP(BLOCK_8X4,
-                   vpx_highbd_sad8x4_bits10,
-                   vpx_highbd_sad8x4_avg_bits10,
-                   vpx_highbd_10_variance8x4,
-                   vpx_highbd_10_sub_pixel_variance8x4,
-                   vpx_highbd_10_sub_pixel_avg_variance8x4,
-                   NULL,
-                   vpx_highbd_sad8x4x8_bits10,
-                   vpx_highbd_sad8x4x4d_bits10)
-
-        HIGHBD_BFP(BLOCK_4X8,
-                   vpx_highbd_sad4x8_bits10,
-                   vpx_highbd_sad4x8_avg_bits10,
-                   vpx_highbd_10_variance4x8,
-                   vpx_highbd_10_sub_pixel_variance4x8,
-                   vpx_highbd_10_sub_pixel_avg_variance4x8,
-                   NULL,
-                   vpx_highbd_sad4x8x8_bits10,
-                   vpx_highbd_sad4x8x4d_bits10)
-
-        HIGHBD_BFP(BLOCK_4X4,
-                   vpx_highbd_sad4x4_bits10,
-                   vpx_highbd_sad4x4_avg_bits10,
-                   vpx_highbd_10_variance4x4,
-                   vpx_highbd_10_sub_pixel_variance4x4,
-                   vpx_highbd_10_sub_pixel_avg_variance4x4,
-                   vpx_highbd_sad4x4x3_bits10,
-                   vpx_highbd_sad4x4x8_bits10,
-                   vpx_highbd_sad4x4x4d_bits10)
-        break;
-
-      case VPX_BITS_12:
-        HIGHBD_BFP(BLOCK_32X16,
-                   vpx_highbd_sad32x16_bits12,
-                   vpx_highbd_sad32x16_avg_bits12,
-                   vpx_highbd_12_variance32x16,
-                   vpx_highbd_12_sub_pixel_variance32x16,
-                   vpx_highbd_12_sub_pixel_avg_variance32x16,
-                   NULL,
-                   NULL,
-                   vpx_highbd_sad32x16x4d_bits12)
-
-        HIGHBD_BFP(BLOCK_16X32,
-                   vpx_highbd_sad16x32_bits12,
-                   vpx_highbd_sad16x32_avg_bits12,
-                   vpx_highbd_12_variance16x32,
-                   vpx_highbd_12_sub_pixel_variance16x32,
-                   vpx_highbd_12_sub_pixel_avg_variance16x32,
-                   NULL,
-                   NULL,
-                   vpx_highbd_sad16x32x4d_bits12)
-
-        HIGHBD_BFP(BLOCK_64X32,
-                   vpx_highbd_sad64x32_bits12,
-                   vpx_highbd_sad64x32_avg_bits12,
-                   vpx_highbd_12_variance64x32,
-                   vpx_highbd_12_sub_pixel_variance64x32,
-                   vpx_highbd_12_sub_pixel_avg_variance64x32,
-                   NULL,
-                   NULL,
-                   vpx_highbd_sad64x32x4d_bits12)
-
-        HIGHBD_BFP(BLOCK_32X64,
-                   vpx_highbd_sad32x64_bits12,
-                   vpx_highbd_sad32x64_avg_bits12,
-                   vpx_highbd_12_variance32x64,
-                   vpx_highbd_12_sub_pixel_variance32x64,
-                   vpx_highbd_12_sub_pixel_avg_variance32x64,
-                   NULL,
-                   NULL,
-                   vpx_highbd_sad32x64x4d_bits12)
-
-        HIGHBD_BFP(BLOCK_32X32,
-                   vpx_highbd_sad32x32_bits12,
-                   vpx_highbd_sad32x32_avg_bits12,
-                   vpx_highbd_12_variance32x32,
-                   vpx_highbd_12_sub_pixel_variance32x32,
-                   vpx_highbd_12_sub_pixel_avg_variance32x32,
-                   vpx_highbd_sad32x32x3_bits12,
-                   vpx_highbd_sad32x32x8_bits12,
-                   vpx_highbd_sad32x32x4d_bits12)
-
-        HIGHBD_BFP(BLOCK_64X64,
-                   vpx_highbd_sad64x64_bits12,
-                   vpx_highbd_sad64x64_avg_bits12,
-                   vpx_highbd_12_variance64x64,
-                   vpx_highbd_12_sub_pixel_variance64x64,
-                   vpx_highbd_12_sub_pixel_avg_variance64x64,
-                   vpx_highbd_sad64x64x3_bits12,
-                   vpx_highbd_sad64x64x8_bits12,
-                   vpx_highbd_sad64x64x4d_bits12)
-
-        HIGHBD_BFP(BLOCK_16X16,
-                   vpx_highbd_sad16x16_bits12,
-                   vpx_highbd_sad16x16_avg_bits12,
-                   vpx_highbd_12_variance16x16,
-                   vpx_highbd_12_sub_pixel_variance16x16,
-                   vpx_highbd_12_sub_pixel_avg_variance16x16,
-                   vpx_highbd_sad16x16x3_bits12,
-                   vpx_highbd_sad16x16x8_bits12,
-                   vpx_highbd_sad16x16x4d_bits12)
-
-        HIGHBD_BFP(BLOCK_16X8,
-                   vpx_highbd_sad16x8_bits12,
-                   vpx_highbd_sad16x8_avg_bits12,
-                   vpx_highbd_12_variance16x8,
-                   vpx_highbd_12_sub_pixel_variance16x8,
-                   vpx_highbd_12_sub_pixel_avg_variance16x8,
-                   vpx_highbd_sad16x8x3_bits12,
-                   vpx_highbd_sad16x8x8_bits12,
-                   vpx_highbd_sad16x8x4d_bits12)
-
-        HIGHBD_BFP(BLOCK_8X16,
-                   vpx_highbd_sad8x16_bits12,
-                   vpx_highbd_sad8x16_avg_bits12,
-                   vpx_highbd_12_variance8x16,
-                   vpx_highbd_12_sub_pixel_variance8x16,
-                   vpx_highbd_12_sub_pixel_avg_variance8x16,
-                   vpx_highbd_sad8x16x3_bits12,
-                   vpx_highbd_sad8x16x8_bits12,
-                   vpx_highbd_sad8x16x4d_bits12)
-
-        HIGHBD_BFP(BLOCK_8X8,
-                   vpx_highbd_sad8x8_bits12,
-                   vpx_highbd_sad8x8_avg_bits12,
-                   vpx_highbd_12_variance8x8,
-                   vpx_highbd_12_sub_pixel_variance8x8,
-                   vpx_highbd_12_sub_pixel_avg_variance8x8,
-                   vpx_highbd_sad8x8x3_bits12,
-                   vpx_highbd_sad8x8x8_bits12,
-                   vpx_highbd_sad8x8x4d_bits12)
-
-        HIGHBD_BFP(BLOCK_8X4,
-                   vpx_highbd_sad8x4_bits12,
-                   vpx_highbd_sad8x4_avg_bits12,
-                   vpx_highbd_12_variance8x4,
-                   vpx_highbd_12_sub_pixel_variance8x4,
-                   vpx_highbd_12_sub_pixel_avg_variance8x4,
-                   NULL,
-                   vpx_highbd_sad8x4x8_bits12,
-                   vpx_highbd_sad8x4x4d_bits12)
-
-        HIGHBD_BFP(BLOCK_4X8,
-                   vpx_highbd_sad4x8_bits12,
-                   vpx_highbd_sad4x8_avg_bits12,
-                   vpx_highbd_12_variance4x8,
-                   vpx_highbd_12_sub_pixel_variance4x8,
-                   vpx_highbd_12_sub_pixel_avg_variance4x8,
-                   NULL,
-                   vpx_highbd_sad4x8x8_bits12,
-                   vpx_highbd_sad4x8x4d_bits12)
-
-        HIGHBD_BFP(BLOCK_4X4,
-                   vpx_highbd_sad4x4_bits12,
-                   vpx_highbd_sad4x4_avg_bits12,
-                   vpx_highbd_12_variance4x4,
-                   vpx_highbd_12_sub_pixel_variance4x4,
-                   vpx_highbd_12_sub_pixel_avg_variance4x4,
-                   vpx_highbd_sad4x4x3_bits12,
-                   vpx_highbd_sad4x4x8_bits12,
-                   vpx_highbd_sad4x4x4d_bits12)
-        break;
-
-      default:
-        assert(0 && "cm->bit_depth should be VPX_BITS_8, "
-                    "VPX_BITS_10 or VPX_BITS_12");
-    }
-  }
-}
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-
-static void realloc_segmentation_maps(VP9_COMP *cpi) {
-  VP9_COMMON *const cm = &cpi->common;
-
-  // Create the encoder segmentation map and set all entries to 0
-  vpx_free(cpi->segmentation_map);
-  CHECK_MEM_ERROR(cm, cpi->segmentation_map,
-                  vpx_calloc(cm->mi_rows * cm->mi_cols, 1));
-
-  // Create a map used for cyclic background refresh.
-  if (cpi->cyclic_refresh)
-    vp9_cyclic_refresh_free(cpi->cyclic_refresh);
-  CHECK_MEM_ERROR(cm, cpi->cyclic_refresh,
-                  vp9_cyclic_refresh_alloc(cm->mi_rows, cm->mi_cols));
-
-  // Create a map used to mark inactive areas.
-  vpx_free(cpi->active_map.map);
-  CHECK_MEM_ERROR(cm, cpi->active_map.map,
-                  vpx_calloc(cm->mi_rows * cm->mi_cols, 1));
-
-  // And a place holder structure is the coding context
-  // for use if we want to save and restore it
-  vpx_free(cpi->coding_context.last_frame_seg_map_copy);
-  CHECK_MEM_ERROR(cm, cpi->coding_context.last_frame_seg_map_copy,
-                  vpx_calloc(cm->mi_rows * cm->mi_cols, 1));
-}
-
-void vp9_change_config(struct VP9_COMP *cpi, const VP9EncoderConfig *oxcf) {
-  VP9_COMMON *const cm = &cpi->common;
-  RATE_CONTROL *const rc = &cpi->rc;
-  int last_w = cpi->oxcf.width;
-  int last_h = cpi->oxcf.height;
-
-  if (cm->profile != oxcf->profile)
-    cm->profile = oxcf->profile;
-  cm->bit_depth = oxcf->bit_depth;
-  cm->color_space = oxcf->color_space;
-  cm->color_range = oxcf->color_range;
-
-  cpi->target_level = oxcf->target_level;
-  cpi->keep_level_stats = oxcf->target_level != LEVEL_MAX;
-
-  if (cm->profile <= PROFILE_1)
-    assert(cm->bit_depth == VPX_BITS_8);
-  else
-    assert(cm->bit_depth > VPX_BITS_8);
-
-  cpi->oxcf = *oxcf;
-#if CONFIG_VP9_HIGHBITDEPTH
-  cpi->td.mb.e_mbd.bd = (int)cm->bit_depth;
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-
-  if ((oxcf->pass == 0) && (oxcf->rc_mode == VPX_Q)) {
-    rc->baseline_gf_interval = FIXED_GF_INTERVAL;
-  } else {
-    rc->baseline_gf_interval = (MIN_GF_INTERVAL + MAX_GF_INTERVAL) / 2;
-  }
-
-  cpi->refresh_golden_frame = 0;
-  cpi->refresh_last_frame = 1;
-  cm->refresh_frame_context = 1;
-  cm->reset_frame_context = 0;
-
-  vp9_reset_segment_features(&cm->seg);
-  vp9_set_high_precision_mv(cpi, 0);
-
-  {
-    int i;
-
-    for (i = 0; i < MAX_SEGMENTS; i++)
-      cpi->segment_encode_breakout[i] = cpi->oxcf.encode_breakout;
-  }
-  cpi->encode_breakout = cpi->oxcf.encode_breakout;
-
-  set_rc_buffer_sizes(rc, &cpi->oxcf);
-
-  // Under a configuration change, where maximum_buffer_size may change,
-  // keep buffer level clipped to the maximum allowed buffer size.
-  rc->bits_off_target = VPXMIN(rc->bits_off_target, rc->maximum_buffer_size);
-  rc->buffer_level = VPXMIN(rc->buffer_level, rc->maximum_buffer_size);
-
-  // Set up frame rate and related parameters rate control values.
-  vp9_new_framerate(cpi, cpi->framerate);
-
-  // Set absolute upper and lower quality limits
-  rc->worst_quality = cpi->oxcf.worst_allowed_q;
-  rc->best_quality = cpi->oxcf.best_allowed_q;
-
-  cm->interp_filter = cpi->sf.default_interp_filter;
-
-  if (cpi->oxcf.render_width > 0 && cpi->oxcf.render_height > 0) {
-    cm->render_width = cpi->oxcf.render_width;
-    cm->render_height = cpi->oxcf.render_height;
-  } else {
-    cm->render_width = cpi->oxcf.width;
-    cm->render_height = cpi->oxcf.height;
-  }
-  if (last_w != cpi->oxcf.width || last_h != cpi->oxcf.height) {
-    cm->width = cpi->oxcf.width;
-    cm->height = cpi->oxcf.height;
-    cpi->external_resize = 1;
-  }
-
-  if (cpi->initial_width) {
-    int new_mi_size = 0;
-    vp9_set_mb_mi(cm, cm->width, cm->height);
-    new_mi_size = cm->mi_stride * calc_mi_size(cm->mi_rows);
-    if (cm->mi_alloc_size < new_mi_size) {
-      vp9_free_context_buffers(cm);
-      alloc_compressor_data(cpi);
-      realloc_segmentation_maps(cpi);
-      cpi->initial_width = cpi->initial_height = 0;
-      cpi->external_resize = 0;
-    } else if (cm->mi_alloc_size == new_mi_size &&
-             (cpi->oxcf.width > last_w || cpi->oxcf.height > last_h)) {
-        vp9_alloc_loop_filter(cm);
-    }
-  }
-
-  update_frame_size(cpi);
-
-  if (last_w != cpi->oxcf.width || last_h != cpi->oxcf.height) {
-    memset(cpi->consec_zero_mv, 0,
-               cm->mi_rows * cm->mi_cols * sizeof(*cpi->consec_zero_mv));
-    if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ)
-      vp9_cyclic_refresh_reset_resize(cpi);
-  }
-
-  if ((cpi->svc.number_temporal_layers > 1 &&
-      cpi->oxcf.rc_mode == VPX_CBR) ||
-      ((cpi->svc.number_temporal_layers > 1 ||
-        cpi->svc.number_spatial_layers > 1) &&
-       cpi->oxcf.pass != 1)) {
-    vp9_update_layer_context_change_config(cpi,
-                                           (int)cpi->oxcf.target_bandwidth);
-  }
-
-  cpi->alt_ref_source = NULL;
-  rc->is_src_frame_alt_ref = 0;
-
-#if 0
-  // Experimental RD Code
-  cpi->frame_distortion = 0;
-  cpi->last_frame_distortion = 0;
-#endif
-
-  set_tile_limits(cpi);
-
-  cpi->ext_refresh_frame_flags_pending = 0;
-  cpi->ext_refresh_frame_context_pending = 0;
-
-#if CONFIG_VP9_HIGHBITDEPTH
-  highbd_set_var_fns(cpi);
-#endif
-}
-
-#ifndef M_LOG2_E
-#define M_LOG2_E 0.693147180559945309417
-#endif
-#define log2f(x) (log (x) / (float) M_LOG2_E)
-
-/***********************************************************************
- * Read before modifying 'cal_nmvjointsadcost' or 'cal_nmvsadcosts'    *
- ***********************************************************************
- * The following 2 functions ('cal_nmvjointsadcost' and                *
- * 'cal_nmvsadcosts') are used to calculate cost lookup tables         *
- * used by 'vp9_diamond_search_sad'. The C implementation of the       *
- * function is generic, but the AVX intrinsics optimised version       *
- * relies on the following properties of the computed tables:          *
- * For cal_nmvjointsadcost:                                            *
- *   - mvjointsadcost[1] == mvjointsadcost[2] == mvjointsadcost[3]     *
- * For cal_nmvsadcosts:                                                *
- *   - For all i: mvsadcost[0][i] == mvsadcost[1][i]                   *
- *         (Equal costs for both components)                           *
- *   - For all i: mvsadcost[0][i] == mvsadcost[0][-i]                  *
- *         (Cost function is even)                                     *
- * If these do not hold, then the AVX optimised version of the         *
- * 'vp9_diamond_search_sad' function cannot be used as it is, in which *
- * case you can revert to using the C function instead.                *
- ***********************************************************************/
-
-static void cal_nmvjointsadcost(int *mvjointsadcost) {
-  /*********************************************************************
-   * Warning: Read the comments above before modifying this function   *
-   *********************************************************************/
-  mvjointsadcost[0] = 600;
-  mvjointsadcost[1] = 300;
-  mvjointsadcost[2] = 300;
-  mvjointsadcost[3] = 300;
-}
-
-static void cal_nmvsadcosts(int *mvsadcost[2]) {
-  /*********************************************************************
-   * Warning: Read the comments above before modifying this function   *
-   *********************************************************************/
-  int i = 1;
-
-  mvsadcost[0][0] = 0;
-  mvsadcost[1][0] = 0;
-
-  do {
-    double z = 256 * (2 * (log2f(8 * i) + .6));
-    mvsadcost[0][i] = (int)z;
-    mvsadcost[1][i] = (int)z;
-    mvsadcost[0][-i] = (int)z;
-    mvsadcost[1][-i] = (int)z;
-  } while (++i <= MV_MAX);
-}
-
-static void cal_nmvsadcosts_hp(int *mvsadcost[2]) {
-  int i = 1;
-
-  mvsadcost[0][0] = 0;
-  mvsadcost[1][0] = 0;
-
-  do {
-    double z = 256 * (2 * (log2f(8 * i) + .6));
-    mvsadcost[0][i] = (int)z;
-    mvsadcost[1][i] = (int)z;
-    mvsadcost[0][-i] = (int)z;
-    mvsadcost[1][-i] = (int)z;
-  } while (++i <= MV_MAX);
-}
-
-VP9_COMP *vp9_create_compressor(VP9EncoderConfig *oxcf,
-                                BufferPool *const pool) {
-  unsigned int i;
-  VP9_COMP *volatile const cpi = vpx_memalign(32, sizeof(VP9_COMP));
-  VP9_COMMON *volatile const cm = cpi != NULL ? &cpi->common : NULL;
-
-  if (!cm)
-    return NULL;
-
-  vp9_zero(*cpi);
-
-  if (setjmp(cm->error.jmp)) {
-    cm->error.setjmp = 0;
-    vp9_remove_compressor(cpi);
-    return 0;
-  }
-
-  cm->error.setjmp = 1;
-  cm->alloc_mi = vp9_enc_alloc_mi;
-  cm->free_mi = vp9_enc_free_mi;
-  cm->setup_mi = vp9_enc_setup_mi;
-
-  CHECK_MEM_ERROR(cm, cm->fc,
-                  (FRAME_CONTEXT *)vpx_calloc(1, sizeof(*cm->fc)));
-  CHECK_MEM_ERROR(cm, cm->frame_contexts,
-                  (FRAME_CONTEXT *)vpx_calloc(FRAME_CONTEXTS,
-                  sizeof(*cm->frame_contexts)));
-
-  cpi->use_svc = 0;
-  cpi->resize_state = 0;
-  cpi->external_resize = 0;
-  cpi->resize_avg_qp = 0;
-  cpi->resize_buffer_underflow = 0;
-  cpi->use_skin_detection = 0;
-  cpi->common.buffer_pool = pool;
-
-  init_config(cpi, oxcf);
-  vp9_rc_init(&cpi->oxcf, oxcf->pass, &cpi->rc);
-
-  cm->current_video_frame = 0;
-  cpi->partition_search_skippable_frame = 0;
-  cpi->tile_data = NULL;
-
-  realloc_segmentation_maps(cpi);
-
-  CHECK_MEM_ERROR(cm, cpi->consec_zero_mv,
-                  vpx_calloc(cm->mi_rows * cm->mi_cols,
-                             sizeof(*cpi->consec_zero_mv)));
-
-  CHECK_MEM_ERROR(cm, cpi->nmvcosts[0],
-                  vpx_calloc(MV_VALS, sizeof(*cpi->nmvcosts[0])));
-  CHECK_MEM_ERROR(cm, cpi->nmvcosts[1],
-                  vpx_calloc(MV_VALS, sizeof(*cpi->nmvcosts[1])));
-  CHECK_MEM_ERROR(cm, cpi->nmvcosts_hp[0],
-                  vpx_calloc(MV_VALS, sizeof(*cpi->nmvcosts_hp[0])));
-  CHECK_MEM_ERROR(cm, cpi->nmvcosts_hp[1],
-                  vpx_calloc(MV_VALS, sizeof(*cpi->nmvcosts_hp[1])));
-  CHECK_MEM_ERROR(cm, cpi->nmvsadcosts[0],
-                  vpx_calloc(MV_VALS, sizeof(*cpi->nmvsadcosts[0])));
-  CHECK_MEM_ERROR(cm, cpi->nmvsadcosts[1],
-                  vpx_calloc(MV_VALS, sizeof(*cpi->nmvsadcosts[1])));
-  CHECK_MEM_ERROR(cm, cpi->nmvsadcosts_hp[0],
-                  vpx_calloc(MV_VALS, sizeof(*cpi->nmvsadcosts_hp[0])));
-  CHECK_MEM_ERROR(cm, cpi->nmvsadcosts_hp[1],
-                  vpx_calloc(MV_VALS, sizeof(*cpi->nmvsadcosts_hp[1])));
-
-  for (i = 0; i < (sizeof(cpi->mbgraph_stats) /
-                   sizeof(cpi->mbgraph_stats[0])); i++) {
-    CHECK_MEM_ERROR(cm, cpi->mbgraph_stats[i].mb_stats,
-                    vpx_calloc(cm->MBs *
-                               sizeof(*cpi->mbgraph_stats[i].mb_stats), 1));
-  }
-
-#if CONFIG_FP_MB_STATS
-  cpi->use_fp_mb_stats = 0;
-  if (cpi->use_fp_mb_stats) {
-    // a place holder used to store the first pass mb stats in the first pass
-    CHECK_MEM_ERROR(cm, cpi->twopass.frame_mb_stats_buf,
-                    vpx_calloc(cm->MBs * sizeof(uint8_t), 1));
-  } else {
-    cpi->twopass.frame_mb_stats_buf = NULL;
-  }
-#endif
-
-  cpi->refresh_alt_ref_frame = 0;
-  cpi->multi_arf_last_grp_enabled = 0;
-
-  cpi->b_calculate_psnr = CONFIG_INTERNAL_STATS;
-
-  init_level_info(&cpi->level_info);
-
-#if CONFIG_INTERNAL_STATS
-  cpi->b_calculate_blockiness = 1;
-  cpi->b_calculate_consistency = 1;
-  cpi->total_inconsistency = 0;
-  cpi->psnr.worst = 100.0;
-  cpi->worst_ssim = 100.0;
-
-  cpi->count = 0;
-  cpi->bytes = 0;
-
-  if (cpi->b_calculate_psnr) {
-    cpi->total_sq_error = 0;
-    cpi->total_samples = 0;
-
-    cpi->totalp_sq_error = 0;
-    cpi->totalp_samples = 0;
-
-    cpi->tot_recode_hits = 0;
-    cpi->summed_quality = 0;
-    cpi->summed_weights = 0;
-    cpi->summedp_quality = 0;
-    cpi->summedp_weights = 0;
-  }
-
-  cpi->fastssim.worst = 100.0;
-  cpi->psnrhvs.worst = 100.0;
-
-  if (cpi->b_calculate_blockiness) {
-    cpi->total_blockiness = 0;
-    cpi->worst_blockiness = 0.0;
-  }
-
-  if (cpi->b_calculate_consistency) {
-    CHECK_MEM_ERROR(cm, cpi->ssim_vars,
-                    vpx_malloc(sizeof(*cpi->ssim_vars) * 4 *
-                               cpi->common.mi_rows * cpi->common.mi_cols));
-    cpi->worst_consistency = 100.0;
-  }
-
-#endif
-
-  cpi->first_time_stamp_ever = INT64_MAX;
-
-  /*********************************************************************
-   * Warning: Read the comments around 'cal_nmvjointsadcost' and       *
-   * 'cal_nmvsadcosts' before modifying how these tables are computed. *
-   *********************************************************************/
-  cal_nmvjointsadcost(cpi->td.mb.nmvjointsadcost);
-  cpi->td.mb.nmvcost[0] = &cpi->nmvcosts[0][MV_MAX];
-  cpi->td.mb.nmvcost[1] = &cpi->nmvcosts[1][MV_MAX];
-  cpi->td.mb.nmvsadcost[0] = &cpi->nmvsadcosts[0][MV_MAX];
-  cpi->td.mb.nmvsadcost[1] = &cpi->nmvsadcosts[1][MV_MAX];
-  cal_nmvsadcosts(cpi->td.mb.nmvsadcost);
-
-  cpi->td.mb.nmvcost_hp[0] = &cpi->nmvcosts_hp[0][MV_MAX];
-  cpi->td.mb.nmvcost_hp[1] = &cpi->nmvcosts_hp[1][MV_MAX];
-  cpi->td.mb.nmvsadcost_hp[0] = &cpi->nmvsadcosts_hp[0][MV_MAX];
-  cpi->td.mb.nmvsadcost_hp[1] = &cpi->nmvsadcosts_hp[1][MV_MAX];
-  cal_nmvsadcosts_hp(cpi->td.mb.nmvsadcost_hp);
-
-#if CONFIG_VP9_TEMPORAL_DENOISING
-#ifdef OUTPUT_YUV_DENOISED
-  yuv_denoised_file = fopen("denoised.yuv", "ab");
-#endif
-#endif
-#ifdef OUTPUT_YUV_SKINMAP
-  yuv_skinmap_file = fopen("skinmap.yuv", "ab");
-#endif
-#ifdef OUTPUT_YUV_REC
-  yuv_rec_file = fopen("rec.yuv", "wb");
-#endif
-
-#if 0
-  framepsnr = fopen("framepsnr.stt", "a");
-  kf_list = fopen("kf_list.stt", "w");
-#endif
-
-  cpi->allow_encode_breakout = ENCODE_BREAKOUT_ENABLED;
-
-  if (oxcf->pass == 1) {
-    vp9_init_first_pass(cpi);
-  } else if (oxcf->pass == 2) {
-    const size_t packet_sz = sizeof(FIRSTPASS_STATS);
-    const int packets = (int)(oxcf->two_pass_stats_in.sz / packet_sz);
-
-    if (cpi->svc.number_spatial_layers > 1
-        || cpi->svc.number_temporal_layers > 1) {
-      FIRSTPASS_STATS *const stats = oxcf->two_pass_stats_in.buf;
-      FIRSTPASS_STATS *stats_copy[VPX_SS_MAX_LAYERS] = {0};
-      int i;
-
-      for (i = 0; i < oxcf->ss_number_layers; ++i) {
-        FIRSTPASS_STATS *const last_packet_for_layer =
-            &stats[packets - oxcf->ss_number_layers + i];
-        const int layer_id = (int)last_packet_for_layer->spatial_layer_id;
-        const int packets_in_layer = (int)last_packet_for_layer->count + 1;
-        if (layer_id >= 0 && layer_id < oxcf->ss_number_layers) {
-          LAYER_CONTEXT *const lc = &cpi->svc.layer_context[layer_id];
-
-          vpx_free(lc->rc_twopass_stats_in.buf);
-
-          lc->rc_twopass_stats_in.sz = packets_in_layer * packet_sz;
-          CHECK_MEM_ERROR(cm, lc->rc_twopass_stats_in.buf,
-                          vpx_malloc(lc->rc_twopass_stats_in.sz));
-          lc->twopass.stats_in_start = lc->rc_twopass_stats_in.buf;
-          lc->twopass.stats_in = lc->twopass.stats_in_start;
-          lc->twopass.stats_in_end = lc->twopass.stats_in_start
-                                     + packets_in_layer - 1;
-          stats_copy[layer_id] = lc->rc_twopass_stats_in.buf;
-        }
-      }
-
-      for (i = 0; i < packets; ++i) {
-        const int layer_id = (int)stats[i].spatial_layer_id;
-        if (layer_id >= 0 && layer_id < oxcf->ss_number_layers
-            && stats_copy[layer_id] != NULL) {
-          *stats_copy[layer_id] = stats[i];
-          ++stats_copy[layer_id];
-        }
-      }
-
-      vp9_init_second_pass_spatial_svc(cpi);
-    } else {
-#if CONFIG_FP_MB_STATS
-      if (cpi->use_fp_mb_stats) {
-        const size_t psz = cpi->common.MBs * sizeof(uint8_t);
-        const int ps = (int)(oxcf->firstpass_mb_stats_in.sz / psz);
-
-        cpi->twopass.firstpass_mb_stats.mb_stats_start =
-            oxcf->firstpass_mb_stats_in.buf;
-        cpi->twopass.firstpass_mb_stats.mb_stats_end =
-            cpi->twopass.firstpass_mb_stats.mb_stats_start +
-            (ps - 1) * cpi->common.MBs * sizeof(uint8_t);
-      }
-#endif
-
-      cpi->twopass.stats_in_start = oxcf->two_pass_stats_in.buf;
-      cpi->twopass.stats_in = cpi->twopass.stats_in_start;
-      cpi->twopass.stats_in_end = &cpi->twopass.stats_in[packets - 1];
-
-      vp9_init_second_pass(cpi);
-    }
-  }
-
-  vp9_set_speed_features_framesize_independent(cpi);
-  vp9_set_speed_features_framesize_dependent(cpi);
-
-  // Allocate memory to store variances for a frame.
-  CHECK_MEM_ERROR(cm, cpi->source_diff_var,
-                  vpx_calloc(cm->MBs, sizeof(diff)));
-  cpi->source_var_thresh = 0;
-  cpi->frames_till_next_var_check = 0;
-
-#define BFP(BT, SDF, SDAF, VF, SVF, SVAF, SDX3F, SDX8F, SDX4DF)\
-    cpi->fn_ptr[BT].sdf            = SDF; \
-    cpi->fn_ptr[BT].sdaf           = SDAF; \
-    cpi->fn_ptr[BT].vf             = VF; \
-    cpi->fn_ptr[BT].svf            = SVF; \
-    cpi->fn_ptr[BT].svaf           = SVAF; \
-    cpi->fn_ptr[BT].sdx3f          = SDX3F; \
-    cpi->fn_ptr[BT].sdx8f          = SDX8F; \
-    cpi->fn_ptr[BT].sdx4df         = SDX4DF;
-
-  BFP(BLOCK_32X16, vpx_sad32x16, vpx_sad32x16_avg,
-      vpx_variance32x16, vpx_sub_pixel_variance32x16,
-      vpx_sub_pixel_avg_variance32x16, NULL, NULL, vpx_sad32x16x4d)
-
-  BFP(BLOCK_16X32, vpx_sad16x32, vpx_sad16x32_avg,
-      vpx_variance16x32, vpx_sub_pixel_variance16x32,
-      vpx_sub_pixel_avg_variance16x32, NULL, NULL, vpx_sad16x32x4d)
-
-  BFP(BLOCK_64X32, vpx_sad64x32, vpx_sad64x32_avg,
-      vpx_variance64x32, vpx_sub_pixel_variance64x32,
-      vpx_sub_pixel_avg_variance64x32, NULL, NULL, vpx_sad64x32x4d)
-
-  BFP(BLOCK_32X64, vpx_sad32x64, vpx_sad32x64_avg,
-      vpx_variance32x64, vpx_sub_pixel_variance32x64,
-      vpx_sub_pixel_avg_variance32x64, NULL, NULL, vpx_sad32x64x4d)
-
-  BFP(BLOCK_32X32, vpx_sad32x32, vpx_sad32x32_avg,
-      vpx_variance32x32, vpx_sub_pixel_variance32x32,
-      vpx_sub_pixel_avg_variance32x32, vpx_sad32x32x3, vpx_sad32x32x8,
-      vpx_sad32x32x4d)
-
-  BFP(BLOCK_64X64, vpx_sad64x64, vpx_sad64x64_avg,
-      vpx_variance64x64, vpx_sub_pixel_variance64x64,
-      vpx_sub_pixel_avg_variance64x64, vpx_sad64x64x3, vpx_sad64x64x8,
-      vpx_sad64x64x4d)
-
-  BFP(BLOCK_16X16, vpx_sad16x16, vpx_sad16x16_avg,
-      vpx_variance16x16, vpx_sub_pixel_variance16x16,
-      vpx_sub_pixel_avg_variance16x16, vpx_sad16x16x3, vpx_sad16x16x8,
-      vpx_sad16x16x4d)
-
-  BFP(BLOCK_16X8, vpx_sad16x8, vpx_sad16x8_avg,
-      vpx_variance16x8, vpx_sub_pixel_variance16x8,
-      vpx_sub_pixel_avg_variance16x8,
-      vpx_sad16x8x3, vpx_sad16x8x8, vpx_sad16x8x4d)
-
-  BFP(BLOCK_8X16, vpx_sad8x16, vpx_sad8x16_avg,
-      vpx_variance8x16, vpx_sub_pixel_variance8x16,
-      vpx_sub_pixel_avg_variance8x16,
-      vpx_sad8x16x3, vpx_sad8x16x8, vpx_sad8x16x4d)
-
-  BFP(BLOCK_8X8, vpx_sad8x8, vpx_sad8x8_avg,
-      vpx_variance8x8, vpx_sub_pixel_variance8x8,
-      vpx_sub_pixel_avg_variance8x8,
-      vpx_sad8x8x3, vpx_sad8x8x8, vpx_sad8x8x4d)
-
-  BFP(BLOCK_8X4, vpx_sad8x4, vpx_sad8x4_avg,
-      vpx_variance8x4, vpx_sub_pixel_variance8x4,
-      vpx_sub_pixel_avg_variance8x4, NULL, vpx_sad8x4x8, vpx_sad8x4x4d)
-
-  BFP(BLOCK_4X8, vpx_sad4x8, vpx_sad4x8_avg,
-      vpx_variance4x8, vpx_sub_pixel_variance4x8,
-      vpx_sub_pixel_avg_variance4x8, NULL, vpx_sad4x8x8, vpx_sad4x8x4d)
-
-  BFP(BLOCK_4X4, vpx_sad4x4, vpx_sad4x4_avg,
-      vpx_variance4x4, vpx_sub_pixel_variance4x4,
-      vpx_sub_pixel_avg_variance4x4,
-      vpx_sad4x4x3, vpx_sad4x4x8, vpx_sad4x4x4d)
-
-#if CONFIG_VP9_HIGHBITDEPTH
-  highbd_set_var_fns(cpi);
-#endif
-
-  /* vp9_init_quantizer() is first called here. Add check in
-   * vp9_frame_init_quantizer() so that vp9_init_quantizer is only
-   * called later when needed. This will avoid unnecessary calls of
-   * vp9_init_quantizer() for every frame.
-   */
-  vp9_init_quantizer(cpi);
-
-  vp9_loop_filter_init(cm);
-
-  cm->error.setjmp = 0;
-
-  return cpi;
-}
-
-#if CONFIG_INTERNAL_STATS
-#define SNPRINT(H, T) \
-  snprintf((H) + strlen(H), sizeof(H) - strlen(H), (T))
-
-#define SNPRINT2(H, T, V) \
-  snprintf((H) + strlen(H), sizeof(H) - strlen(H), (T), (V))
-#endif  // CONFIG_INTERNAL_STATS
-
-void vp9_remove_compressor(VP9_COMP *cpi) {
-  VP9_COMMON *cm;
-  unsigned int i;
-  int t;
-
-  if (!cpi)
-    return;
-
-  cm = &cpi->common;
-  if (cm->current_video_frame > 0) {
-#if CONFIG_INTERNAL_STATS
-    vpx_clear_system_state();
-
-    if (cpi->oxcf.pass != 1) {
-      char headings[512] = {0};
-      char results[512] = {0};
-      FILE *f = fopen("opsnr.stt", "a");
-      double time_encoded = (cpi->last_end_time_stamp_seen
-                             - cpi->first_time_stamp_ever) / 10000000.000;
-      double total_encode_time = (cpi->time_receive_data +
-                                  cpi->time_compress_data)   / 1000.000;
-      const double dr =
-          (double)cpi->bytes * (double) 8 / (double)1000 / time_encoded;
-      const double peak = (double)((1 << cpi->oxcf.input_bit_depth) - 1);
-      const double target_rate = (double)cpi->oxcf.target_bandwidth / 1000;
-      const double rate_err = ((100.0 * (dr - target_rate)) / target_rate);
-
-      if (cpi->b_calculate_psnr) {
-        const double total_psnr =
-            vpx_sse_to_psnr((double)cpi->total_samples, peak,
-                            (double)cpi->total_sq_error);
-        const double totalp_psnr =
-            vpx_sse_to_psnr((double)cpi->totalp_samples, peak,
-                            (double)cpi->totalp_sq_error);
-        const double total_ssim = 100 * pow(cpi->summed_quality /
-                                            cpi->summed_weights, 8.0);
-        const double totalp_ssim = 100 * pow(cpi->summedp_quality /
-                                             cpi->summedp_weights, 8.0);
-
-        snprintf(headings, sizeof(headings),
-                 "Bitrate\tAVGPsnr\tGLBPsnr\tAVPsnrP\tGLPsnrP\t"
-                 "VPXSSIM\tVPSSIMP\tFASTSIM\tPSNRHVS\t"
-                 "WstPsnr\tWstSsim\tWstFast\tWstHVS");
-        snprintf(results, sizeof(results),
-                 "%7.2f\t%7.3f\t%7.3f\t%7.3f\t%7.3f\t"
-                 "%7.3f\t%7.3f\t%7.3f\t%7.3f\t"
-                 "%7.3f\t%7.3f\t%7.3f\t%7.3f",
-                 dr, cpi->psnr.stat[ALL] / cpi->count, total_psnr,
-                 cpi->psnrp.stat[ALL] / cpi->count, totalp_psnr,
-                 total_ssim, totalp_ssim,
-                 cpi->fastssim.stat[ALL] / cpi->count,
-                 cpi->psnrhvs.stat[ALL] / cpi->count,
-                 cpi->psnr.worst, cpi->worst_ssim, cpi->fastssim.worst,
-                 cpi->psnrhvs.worst);
-
-        if (cpi->b_calculate_blockiness) {
-          SNPRINT(headings, "\t  Block\tWstBlck");
-          SNPRINT2(results, "\t%7.3f", cpi->total_blockiness / cpi->count);
-          SNPRINT2(results, "\t%7.3f", cpi->worst_blockiness);
-        }
-
-        if (cpi->b_calculate_consistency) {
-          double consistency =
-              vpx_sse_to_psnr((double)cpi->totalp_samples, peak,
-                              (double)cpi->total_inconsistency);
-
-          SNPRINT(headings, "\tConsist\tWstCons");
-          SNPRINT2(results, "\t%7.3f", consistency);
-          SNPRINT2(results, "\t%7.3f", cpi->worst_consistency);
-        }
-        fprintf(f, "%s\t    Time  Rc-Err Abs Err\n", headings);
-        fprintf(f, "%s\t%8.0f %7.2f %7.2f\n", results,
-                total_encode_time, rate_err, fabs(rate_err));
-      }
-
-      fclose(f);
-    }
-
-#endif
-
-#if 0
-    {
-      printf("\n_pick_loop_filter_level:%d\n", cpi->time_pick_lpf / 1000);
-      printf("\n_frames recive_data encod_mb_row compress_frame  Total\n");
-      printf("%6d %10ld %10ld %10ld %10ld\n", cpi->common.current_video_frame,
-             cpi->time_receive_data / 1000, cpi->time_encode_sb_row / 1000,
-             cpi->time_compress_data / 1000,
-             (cpi->time_receive_data + cpi->time_compress_data) / 1000);
-    }
-#endif
-  }
-
-#if CONFIG_VP9_TEMPORAL_DENOISING
-  vp9_denoiser_free(&(cpi->denoiser));
-#endif
-
-  for (t = 0; t < cpi->num_workers; ++t) {
-    VPxWorker *const worker = &cpi->workers[t];
-    EncWorkerData *const thread_data = &cpi->tile_thr_data[t];
-
-    // Deallocate allocated threads.
-    vpx_get_worker_interface()->end(worker);
-
-    // Deallocate allocated thread data.
-    if (t < cpi->num_workers - 1) {
-      vpx_free(thread_data->td->counts);
-      vp9_free_pc_tree(thread_data->td);
-      vpx_free(thread_data->td);
-    }
-  }
-  vpx_free(cpi->tile_thr_data);
-  vpx_free(cpi->workers);
-
-  if (cpi->num_workers > 1)
-    vp9_loop_filter_dealloc(&cpi->lf_row_sync);
-
-  dealloc_compressor_data(cpi);
-
-  for (i = 0; i < sizeof(cpi->mbgraph_stats) /
-                  sizeof(cpi->mbgraph_stats[0]); ++i) {
-    vpx_free(cpi->mbgraph_stats[i].mb_stats);
-  }
-
-#if CONFIG_FP_MB_STATS
-  if (cpi->use_fp_mb_stats) {
-    vpx_free(cpi->twopass.frame_mb_stats_buf);
-    cpi->twopass.frame_mb_stats_buf = NULL;
-  }
-#endif
-
-  vp9_remove_common(cm);
-  vp9_free_ref_frame_buffers(cm->buffer_pool);
-#if CONFIG_VP9_POSTPROC
-  vp9_free_postproc_buffers(cm);
-#endif
-  vpx_free(cpi);
-
-#if CONFIG_VP9_TEMPORAL_DENOISING
-#ifdef OUTPUT_YUV_DENOISED
-  fclose(yuv_denoised_file);
-#endif
-#endif
-#ifdef OUTPUT_YUV_SKINMAP
-  fclose(yuv_skinmap_file);
-#endif
-#ifdef OUTPUT_YUV_REC
-  fclose(yuv_rec_file);
-#endif
-
-#if 0
-
-  if (keyfile)
-    fclose(keyfile);
-
-  if (framepsnr)
-    fclose(framepsnr);
-
-  if (kf_list)
-    fclose(kf_list);
-
-#endif
-}
-
-static void generate_psnr_packet(VP9_COMP *cpi) {
-  struct vpx_codec_cx_pkt pkt;
-  int i;
-  PSNR_STATS psnr;
-#if CONFIG_VP9_HIGHBITDEPTH
-  vpx_calc_highbd_psnr(cpi->Source, cpi->common.frame_to_show, &psnr,
-                       cpi->td.mb.e_mbd.bd, cpi->oxcf.input_bit_depth);
-#else
-  vpx_calc_psnr(cpi->Source, cpi->common.frame_to_show, &psnr);
-#endif
-
-  for (i = 0; i < 4; ++i) {
-    pkt.data.psnr.samples[i] = psnr.samples[i];
-    pkt.data.psnr.sse[i] = psnr.sse[i];
-    pkt.data.psnr.psnr[i] = psnr.psnr[i];
-  }
-  pkt.kind = VPX_CODEC_PSNR_PKT;
-  if (cpi->use_svc)
-    cpi->svc.layer_context[cpi->svc.spatial_layer_id *
-        cpi->svc.number_temporal_layers].psnr_pkt = pkt.data.psnr;
-  else
-    vpx_codec_pkt_list_add(cpi->output_pkt_list, &pkt);
-}
-
-int vp9_use_as_reference(VP9_COMP *cpi, int ref_frame_flags) {
-  if (ref_frame_flags > 7)
-    return -1;
-
-  cpi->ref_frame_flags = ref_frame_flags;
-  return 0;
-}
-
-void vp9_update_reference(VP9_COMP *cpi, int ref_frame_flags) {
-  cpi->ext_refresh_golden_frame = (ref_frame_flags & VP9_GOLD_FLAG) != 0;
-  cpi->ext_refresh_alt_ref_frame = (ref_frame_flags & VP9_ALT_FLAG) != 0;
-  cpi->ext_refresh_last_frame = (ref_frame_flags & VP9_LAST_FLAG) != 0;
-  cpi->ext_refresh_frame_flags_pending = 1;
-}
-
-static YV12_BUFFER_CONFIG *get_vp9_ref_frame_buffer(VP9_COMP *cpi,
-                                VP9_REFFRAME ref_frame_flag) {
-  MV_REFERENCE_FRAME ref_frame = NONE;
-  if (ref_frame_flag == VP9_LAST_FLAG)
-    ref_frame = LAST_FRAME;
-  else if (ref_frame_flag == VP9_GOLD_FLAG)
-    ref_frame = GOLDEN_FRAME;
-  else if (ref_frame_flag == VP9_ALT_FLAG)
-    ref_frame = ALTREF_FRAME;
-
-  return ref_frame == NONE ? NULL : get_ref_frame_buffer(cpi, ref_frame);
-}
-
-int vp9_copy_reference_enc(VP9_COMP *cpi, VP9_REFFRAME ref_frame_flag,
-                           YV12_BUFFER_CONFIG *sd) {
-  YV12_BUFFER_CONFIG *cfg = get_vp9_ref_frame_buffer(cpi, ref_frame_flag);
-  if (cfg) {
-    vp8_yv12_copy_frame(cfg, sd);
-    return 0;
-  } else {
-    return -1;
-  }
-}
-
-int vp9_set_reference_enc(VP9_COMP *cpi, VP9_REFFRAME ref_frame_flag,
-                          YV12_BUFFER_CONFIG *sd) {
-  YV12_BUFFER_CONFIG *cfg = get_vp9_ref_frame_buffer(cpi, ref_frame_flag);
-  if (cfg) {
-    vp8_yv12_copy_frame(sd, cfg);
-    return 0;
-  } else {
-    return -1;
-  }
-}
-
-int vp9_update_entropy(VP9_COMP * cpi, int update) {
-  cpi->ext_refresh_frame_context = update;
-  cpi->ext_refresh_frame_context_pending = 1;
-  return 0;
-}
-
-#if defined(OUTPUT_YUV_DENOISED) || defined(OUTPUT_YUV_SKINMAP)
-// The denoiser buffer is allocated as a YUV 440 buffer. This function writes it
-// as YUV 420. We simply use the top-left pixels of the UV buffers, since we do
-// not denoise the UV channels at this time. If ever we implement UV channel
-// denoising we will have to modify this.
-void vp9_write_yuv_frame_420(YV12_BUFFER_CONFIG *s, FILE *f) {
-  uint8_t *src = s->y_buffer;
-  int h = s->y_height;
-
-  do {
-    fwrite(src, s->y_width, 1, f);
-    src += s->y_stride;
-  } while (--h);
-
-  src = s->u_buffer;
-  h = s->uv_height;
-
-  do {
-    fwrite(src, s->uv_width, 1, f);
-    src += s->uv_stride;
-  } while (--h);
-
-  src = s->v_buffer;
-  h = s->uv_height;
-
-  do {
-    fwrite(src, s->uv_width, 1, f);
-    src += s->uv_stride;
-  } while (--h);
-}
-#endif
-
-#ifdef OUTPUT_YUV_REC
-void vp9_write_yuv_rec_frame(VP9_COMMON *cm) {
-  YV12_BUFFER_CONFIG *s = cm->frame_to_show;
-  uint8_t *src = s->y_buffer;
-  int h = cm->height;
-
-#if CONFIG_VP9_HIGHBITDEPTH
-  if (s->flags & YV12_FLAG_HIGHBITDEPTH) {
-    uint16_t *src16 = CONVERT_TO_SHORTPTR(s->y_buffer);
-
-    do {
-      fwrite(src16, s->y_width, 2,  yuv_rec_file);
-      src16 += s->y_stride;
-    } while (--h);
-
-    src16 = CONVERT_TO_SHORTPTR(s->u_buffer);
-    h = s->uv_height;
-
-    do {
-      fwrite(src16, s->uv_width, 2,  yuv_rec_file);
-      src16 += s->uv_stride;
-    } while (--h);
-
-    src16 = CONVERT_TO_SHORTPTR(s->v_buffer);
-    h = s->uv_height;
-
-    do {
-      fwrite(src16, s->uv_width, 2, yuv_rec_file);
-      src16 += s->uv_stride;
-    } while (--h);
-
-    fflush(yuv_rec_file);
-    return;
-  }
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-
-  do {
-    fwrite(src, s->y_width, 1,  yuv_rec_file);
-    src += s->y_stride;
-  } while (--h);
-
-  src = s->u_buffer;
-  h = s->uv_height;
-
-  do {
-    fwrite(src, s->uv_width, 1,  yuv_rec_file);
-    src += s->uv_stride;
-  } while (--h);
-
-  src = s->v_buffer;
-  h = s->uv_height;
-
-  do {
-    fwrite(src, s->uv_width, 1, yuv_rec_file);
-    src += s->uv_stride;
-  } while (--h);
-
-  fflush(yuv_rec_file);
-}
-#endif
-
-#if CONFIG_VP9_HIGHBITDEPTH
-static void scale_and_extend_frame_nonnormative(const YV12_BUFFER_CONFIG *src,
-                                                YV12_BUFFER_CONFIG *dst,
-                                                int bd) {
-#else
-static void scale_and_extend_frame_nonnormative(const YV12_BUFFER_CONFIG *src,
-                                                YV12_BUFFER_CONFIG *dst) {
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-  // TODO(dkovalev): replace YV12_BUFFER_CONFIG with vpx_image_t
-  int i;
-  const uint8_t *const srcs[3] = {src->y_buffer, src->u_buffer, src->v_buffer};
-  const int src_strides[3] = {src->y_stride, src->uv_stride, src->uv_stride};
-  const int src_widths[3] = {src->y_crop_width, src->uv_crop_width,
-                             src->uv_crop_width };
-  const int src_heights[3] = {src->y_crop_height, src->uv_crop_height,
-                              src->uv_crop_height};
-  uint8_t *const dsts[3] = {dst->y_buffer, dst->u_buffer, dst->v_buffer};
-  const int dst_strides[3] = {dst->y_stride, dst->uv_stride, dst->uv_stride};
-  const int dst_widths[3] = {dst->y_crop_width, dst->uv_crop_width,
-                             dst->uv_crop_width};
-  const int dst_heights[3] = {dst->y_crop_height, dst->uv_crop_height,
-                              dst->uv_crop_height};
-
-  for (i = 0; i < MAX_MB_PLANE; ++i) {
-#if CONFIG_VP9_HIGHBITDEPTH
-    if (src->flags & YV12_FLAG_HIGHBITDEPTH) {
-      vp9_highbd_resize_plane(srcs[i], src_heights[i], src_widths[i],
-                              src_strides[i], dsts[i], dst_heights[i],
-                              dst_widths[i], dst_strides[i], bd);
-    } else {
-      vp9_resize_plane(srcs[i], src_heights[i], src_widths[i], src_strides[i],
-                       dsts[i], dst_heights[i], dst_widths[i], dst_strides[i]);
-    }
-#else
-    vp9_resize_plane(srcs[i], src_heights[i], src_widths[i], src_strides[i],
-                     dsts[i], dst_heights[i], dst_widths[i], dst_strides[i]);
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-  }
-  vpx_extend_frame_borders(dst);
-}
-
-#if CONFIG_VP9_HIGHBITDEPTH
-static void scale_and_extend_frame(const YV12_BUFFER_CONFIG *src,
-                                   YV12_BUFFER_CONFIG *dst, int bd) {
-  const int src_w = src->y_crop_width;
-  const int src_h = src->y_crop_height;
-  const int dst_w = dst->y_crop_width;
-  const int dst_h = dst->y_crop_height;
-  const uint8_t *const srcs[3] = {src->y_buffer, src->u_buffer, src->v_buffer};
-  const int src_strides[3] = {src->y_stride, src->uv_stride, src->uv_stride};
-  uint8_t *const dsts[3] = {dst->y_buffer, dst->u_buffer, dst->v_buffer};
-  const int dst_strides[3] = {dst->y_stride, dst->uv_stride, dst->uv_stride};
-  const InterpKernel *const kernel = vp9_filter_kernels[EIGHTTAP];
-  int x, y, i;
-
-  for (i = 0; i < MAX_MB_PLANE; ++i) {
-    const int factor = (i == 0 || i == 3 ? 1 : 2);
-    const int src_stride = src_strides[i];
-    const int dst_stride = dst_strides[i];
-    for (y = 0; y < dst_h; y += 16) {
-      const int y_q4 = y * (16 / factor) * src_h / dst_h;
-      for (x = 0; x < dst_w; x += 16) {
-        const int x_q4 = x * (16 / factor) * src_w / dst_w;
-        const uint8_t *src_ptr = srcs[i] + (y / factor) * src_h / dst_h *
-                                   src_stride + (x / factor) * src_w / dst_w;
-        uint8_t *dst_ptr = dsts[i] + (y / factor) * dst_stride + (x / factor);
-
-        if (src->flags & YV12_FLAG_HIGHBITDEPTH) {
-          vpx_highbd_convolve8(src_ptr, src_stride, dst_ptr, dst_stride,
-                               kernel[x_q4 & 0xf], 16 * src_w / dst_w,
-                               kernel[y_q4 & 0xf], 16 * src_h / dst_h,
-                               16 / factor, 16 / factor, bd);
-        } else {
-          vpx_scaled_2d(src_ptr, src_stride, dst_ptr, dst_stride,
-                        kernel[x_q4 & 0xf], 16 * src_w / dst_w,
-                        kernel[y_q4 & 0xf], 16 * src_h / dst_h,
-                        16 / factor, 16 / factor);
-        }
-      }
-    }
-  }
-
-  vpx_extend_frame_borders(dst);
-}
-#else
-void vp9_scale_and_extend_frame_c(const YV12_BUFFER_CONFIG *src,
-                                  YV12_BUFFER_CONFIG *dst) {
-  const int src_w = src->y_crop_width;
-  const int src_h = src->y_crop_height;
-  const int dst_w = dst->y_crop_width;
-  const int dst_h = dst->y_crop_height;
-  const uint8_t *const srcs[3] = {src->y_buffer, src->u_buffer, src->v_buffer};
-  const int src_strides[3] = {src->y_stride, src->uv_stride, src->uv_stride};
-  uint8_t *const dsts[3] = {dst->y_buffer, dst->u_buffer, dst->v_buffer};
-  const int dst_strides[3] = {dst->y_stride, dst->uv_stride, dst->uv_stride};
-  const InterpKernel *const kernel = vp9_filter_kernels[EIGHTTAP];
-  int x, y, i;
-
-  for (i = 0; i < MAX_MB_PLANE; ++i) {
-    const int factor = (i == 0 || i == 3 ? 1 : 2);
-    const int src_stride = src_strides[i];
-    const int dst_stride = dst_strides[i];
-    for (y = 0; y < dst_h; y += 16) {
-      const int y_q4 = y * (16 / factor) * src_h / dst_h;
-      for (x = 0; x < dst_w; x += 16) {
-        const int x_q4 = x * (16 / factor) * src_w / dst_w;
-        const uint8_t *src_ptr = srcs[i] + (y / factor) * src_h / dst_h *
-                                   src_stride + (x / factor) * src_w / dst_w;
-        uint8_t *dst_ptr = dsts[i] + (y / factor) * dst_stride + (x / factor);
-
-        vpx_scaled_2d(src_ptr, src_stride, dst_ptr, dst_stride,
-                      kernel[x_q4 & 0xf], 16 * src_w / dst_w,
-                      kernel[y_q4 & 0xf], 16 * src_h / dst_h,
-                      16 / factor, 16 / factor);
-      }
-    }
-  }
-
-  vpx_extend_frame_borders(dst);
-}
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-
-static int scale_down(VP9_COMP *cpi, int q) {
-  RATE_CONTROL *const rc = &cpi->rc;
-  GF_GROUP *const gf_group = &cpi->twopass.gf_group;
-  int scale = 0;
-  assert(frame_is_kf_gf_arf(cpi));
-
-  if (rc->frame_size_selector == UNSCALED &&
-      q >= rc->rf_level_maxq[gf_group->rf_level[gf_group->index]]) {
-    const int max_size_thresh = (int)(rate_thresh_mult[SCALE_STEP1]
-        * VPXMAX(rc->this_frame_target, rc->avg_frame_bandwidth));
-    scale = rc->projected_frame_size > max_size_thresh ? 1 : 0;
-  }
-  return scale;
-}
-
-static int big_rate_miss(VP9_COMP *cpi, int high_limit, int low_limit) {
-  const RATE_CONTROL *const rc = &cpi->rc;
-
-  return (rc->projected_frame_size > ((high_limit * 3) / 2)) ||
-         (rc->projected_frame_size < (low_limit / 2));
-}
-
-// Function to test for conditions that indicate we should loop
-// back and recode a frame.
-static int recode_loop_test(VP9_COMP *cpi,
-                            int high_limit, int low_limit,
-                            int q, int maxq, int minq) {
-  const RATE_CONTROL *const rc = &cpi->rc;
-  const VP9EncoderConfig *const oxcf = &cpi->oxcf;
-  const int frame_is_kfgfarf = frame_is_kf_gf_arf(cpi);
-  int force_recode = 0;
-
-  if ((rc->projected_frame_size >= rc->max_frame_bandwidth) ||
-      big_rate_miss(cpi, high_limit, low_limit) ||
-      (cpi->sf.recode_loop == ALLOW_RECODE) ||
-      (frame_is_kfgfarf &&
-       (cpi->sf.recode_loop == ALLOW_RECODE_KFARFGF))) {
-    if (frame_is_kfgfarf &&
-        (oxcf->resize_mode == RESIZE_DYNAMIC) &&
-        scale_down(cpi, q)) {
-        // Code this group at a lower resolution.
-        cpi->resize_pending = 1;
-        return 1;
-    }
-
-    // TODO(agrange) high_limit could be greater than the scale-down threshold.
-    if ((rc->projected_frame_size > high_limit && q < maxq) ||
-        (rc->projected_frame_size < low_limit && q > minq)) {
-      force_recode = 1;
-    } else if (cpi->oxcf.rc_mode == VPX_CQ) {
-      // Deal with frame undershoot and whether or not we are
-      // below the automatically set cq level.
-      if (q > oxcf->cq_level &&
-          rc->projected_frame_size < ((rc->this_frame_target * 7) >> 3)) {
-        force_recode = 1;
-      }
-    }
-  }
-  return force_recode;
-}
-
-void vp9_update_reference_frames(VP9_COMP *cpi) {
-  VP9_COMMON * const cm = &cpi->common;
-  BufferPool *const pool = cm->buffer_pool;
-
-  // At this point the new frame has been encoded.
-  // If any buffer copy / swapping is signaled it should be done here.
-  if (cm->frame_type == KEY_FRAME) {
-    ref_cnt_fb(pool->frame_bufs,
-               &cm->ref_frame_map[cpi->gld_fb_idx], cm->new_fb_idx);
-    ref_cnt_fb(pool->frame_bufs,
-               &cm->ref_frame_map[cpi->alt_fb_idx], cm->new_fb_idx);
-  } else if (vp9_preserve_existing_gf(cpi)) {
-    // We have decided to preserve the previously existing golden frame as our
-    // new ARF frame. However, in the short term in function
-    // vp9_get_refresh_mask() we left it in the GF slot and, if
-    // we're updating the GF with the current decoded frame, we save it to the
-    // ARF slot instead.
-    // We now have to update the ARF with the current frame and swap gld_fb_idx
-    // and alt_fb_idx so that, overall, we've stored the old GF in the new ARF
-    // slot and, if we're updating the GF, the current frame becomes the new GF.
-    int tmp;
-
-    ref_cnt_fb(pool->frame_bufs,
-               &cm->ref_frame_map[cpi->alt_fb_idx], cm->new_fb_idx);
-
-    tmp = cpi->alt_fb_idx;
-    cpi->alt_fb_idx = cpi->gld_fb_idx;
-    cpi->gld_fb_idx = tmp;
-
-    if (is_two_pass_svc(cpi)) {
-      cpi->svc.layer_context[0].gold_ref_idx = cpi->gld_fb_idx;
-      cpi->svc.layer_context[0].alt_ref_idx = cpi->alt_fb_idx;
-    }
-  } else { /* For non key/golden frames */
-    if (cpi->refresh_alt_ref_frame) {
-      int arf_idx = cpi->alt_fb_idx;
-      if ((cpi->oxcf.pass == 2) && cpi->multi_arf_allowed) {
-        const GF_GROUP *const gf_group = &cpi->twopass.gf_group;
-        arf_idx = gf_group->arf_update_idx[gf_group->index];
-      }
-
-      ref_cnt_fb(pool->frame_bufs,
-                 &cm->ref_frame_map[arf_idx], cm->new_fb_idx);
-      memcpy(cpi->interp_filter_selected[ALTREF_FRAME],
-             cpi->interp_filter_selected[0],
-             sizeof(cpi->interp_filter_selected[0]));
-    }
-
-    if (cpi->refresh_golden_frame) {
-      ref_cnt_fb(pool->frame_bufs,
-                 &cm->ref_frame_map[cpi->gld_fb_idx], cm->new_fb_idx);
-      if (!cpi->rc.is_src_frame_alt_ref)
-        memcpy(cpi->interp_filter_selected[GOLDEN_FRAME],
-               cpi->interp_filter_selected[0],
-               sizeof(cpi->interp_filter_selected[0]));
-      else
-        memcpy(cpi->interp_filter_selected[GOLDEN_FRAME],
-               cpi->interp_filter_selected[ALTREF_FRAME],
-               sizeof(cpi->interp_filter_selected[ALTREF_FRAME]));
-    }
-  }
-
-  if (cpi->refresh_last_frame) {
-    ref_cnt_fb(pool->frame_bufs,
-               &cm->ref_frame_map[cpi->lst_fb_idx], cm->new_fb_idx);
-    if (!cpi->rc.is_src_frame_alt_ref)
-      memcpy(cpi->interp_filter_selected[LAST_FRAME],
-             cpi->interp_filter_selected[0],
-             sizeof(cpi->interp_filter_selected[0]));
-  }
-#if CONFIG_VP9_TEMPORAL_DENOISING
-  if (cpi->oxcf.noise_sensitivity > 0 &&
-      cpi->denoiser.denoising_level > kDenLowLow) {
-    vp9_denoiser_update_frame_info(&cpi->denoiser,
-                                   *cpi->Source,
-                                   cpi->common.frame_type,
-                                   cpi->refresh_alt_ref_frame,
-                                   cpi->refresh_golden_frame,
-                                   cpi->refresh_last_frame,
-                                   cpi->resize_pending);
-  }
-#endif
-  if (is_one_pass_cbr_svc(cpi)) {
-    // Keep track of frame index for each reference frame.
-    SVC *const svc = &cpi->svc;
-    if (cm->frame_type == KEY_FRAME) {
-      svc->ref_frame_index[cpi->lst_fb_idx] = svc->current_superframe;
-      svc->ref_frame_index[cpi->gld_fb_idx] = svc->current_superframe;
-      svc->ref_frame_index[cpi->alt_fb_idx] = svc->current_superframe;
-    } else {
-      if (cpi->refresh_last_frame)
-        svc->ref_frame_index[cpi->lst_fb_idx] = svc->current_superframe;
-      if (cpi->refresh_golden_frame)
-        svc->ref_frame_index[cpi->gld_fb_idx] = svc->current_superframe;
-      if (cpi->refresh_alt_ref_frame)
-        svc->ref_frame_index[cpi->alt_fb_idx] = svc->current_superframe;
-    }
-  }
-}
-
-static void loopfilter_frame(VP9_COMP *cpi, VP9_COMMON *cm) {
-  MACROBLOCKD *xd = &cpi->td.mb.e_mbd;
-  struct loopfilter *lf = &cm->lf;
-
-  if (xd->lossless) {
-      lf->filter_level = 0;
-      lf->last_filt_level = 0;
-  } else {
-    struct vpx_usec_timer timer;
-
-    vpx_clear_system_state();
-
-    vpx_usec_timer_start(&timer);
-
-    if (!cpi->rc.is_src_frame_alt_ref) {
-      if ((cpi->common.frame_type == KEY_FRAME) &&
-          (!cpi->rc.this_key_frame_forced)) {
-        lf->last_filt_level = 0;
-      }
-      vp9_pick_filter_level(cpi->Source, cpi, cpi->sf.lpf_pick);
-      lf->last_filt_level = lf->filter_level;
-    } else {
-      lf->filter_level = 0;
-    }
-
-    vpx_usec_timer_mark(&timer);
-    cpi->time_pick_lpf += vpx_usec_timer_elapsed(&timer);
-  }
-
-  if (lf->filter_level > 0) {
-    vp9_build_mask_frame(cm, lf->filter_level, 0);
-
-    if (cpi->num_workers > 1)
-      vp9_loop_filter_frame_mt(cm->frame_to_show, cm, xd->plane,
-                               lf->filter_level, 0, 0,
-                               cpi->workers, cpi->num_workers,
-                               &cpi->lf_row_sync);
-    else
-      vp9_loop_filter_frame(cm->frame_to_show, cm, xd, lf->filter_level, 0, 0);
-  }
-
-  vpx_extend_frame_inner_borders(cm->frame_to_show);
-}
-
-static INLINE void alloc_frame_mvs(VP9_COMMON *const cm,
-                                   int buffer_idx) {
-  RefCntBuffer *const new_fb_ptr = &cm->buffer_pool->frame_bufs[buffer_idx];
-  if (new_fb_ptr->mvs == NULL ||
-      new_fb_ptr->mi_rows < cm->mi_rows ||
-      new_fb_ptr->mi_cols < cm->mi_cols) {
-    vpx_free(new_fb_ptr->mvs);
-    CHECK_MEM_ERROR(cm, new_fb_ptr->mvs,
-                    (MV_REF *)vpx_calloc(cm->mi_rows * cm->mi_cols,
-                                         sizeof(*new_fb_ptr->mvs)));
-    new_fb_ptr->mi_rows = cm->mi_rows;
-    new_fb_ptr->mi_cols = cm->mi_cols;
-  }
-}
-
-void vp9_scale_references(VP9_COMP *cpi) {
-  VP9_COMMON *cm = &cpi->common;
-  MV_REFERENCE_FRAME ref_frame;
-  const VP9_REFFRAME ref_mask[3] = {VP9_LAST_FLAG, VP9_GOLD_FLAG, VP9_ALT_FLAG};
-
-  for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) {
-    // Need to convert from VP9_REFFRAME to index into ref_mask (subtract 1).
-    if (cpi->ref_frame_flags & ref_mask[ref_frame - 1]) {
-      BufferPool *const pool = cm->buffer_pool;
-      const YV12_BUFFER_CONFIG *const ref = get_ref_frame_buffer(cpi,
-                                                                 ref_frame);
-
-      if (ref == NULL) {
-        cpi->scaled_ref_idx[ref_frame - 1] = INVALID_IDX;
-        continue;
-      }
-
-#if CONFIG_VP9_HIGHBITDEPTH
-      if (ref->y_crop_width != cm->width || ref->y_crop_height != cm->height) {
-        RefCntBuffer *new_fb_ptr = NULL;
-        int force_scaling = 0;
-        int new_fb = cpi->scaled_ref_idx[ref_frame - 1];
-        if (new_fb == INVALID_IDX) {
-          new_fb = get_free_fb(cm);
-          force_scaling = 1;
-        }
-        if (new_fb == INVALID_IDX)
-          return;
-        new_fb_ptr = &pool->frame_bufs[new_fb];
-        if (force_scaling ||
-            new_fb_ptr->buf.y_crop_width != cm->width ||
-            new_fb_ptr->buf.y_crop_height != cm->height) {
-          if (vpx_realloc_frame_buffer(&new_fb_ptr->buf, cm->width, cm->height,
-                                       cm->subsampling_x, cm->subsampling_y,
-                                       cm->use_highbitdepth,
-                                       VP9_ENC_BORDER_IN_PIXELS,
-                                       cm->byte_alignment, NULL, NULL, NULL))
-            vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR,
-                               "Failed to allocate frame buffer");
-          scale_and_extend_frame(ref, &new_fb_ptr->buf, (int)cm->bit_depth);
-          cpi->scaled_ref_idx[ref_frame - 1] = new_fb;
-          alloc_frame_mvs(cm, new_fb);
-        }
-#else
-      if (ref->y_crop_width != cm->width || ref->y_crop_height != cm->height) {
-        RefCntBuffer *new_fb_ptr = NULL;
-        int force_scaling = 0;
-        int new_fb = cpi->scaled_ref_idx[ref_frame - 1];
-        if (new_fb == INVALID_IDX) {
-          new_fb = get_free_fb(cm);
-          force_scaling = 1;
-        }
-        if (new_fb == INVALID_IDX)
-          return;
-        new_fb_ptr = &pool->frame_bufs[new_fb];
-        if (force_scaling ||
-            new_fb_ptr->buf.y_crop_width != cm->width ||
-            new_fb_ptr->buf.y_crop_height != cm->height) {
-          if (vpx_realloc_frame_buffer(&new_fb_ptr->buf, cm->width, cm->height,
-                                       cm->subsampling_x, cm->subsampling_y,
-                                       VP9_ENC_BORDER_IN_PIXELS,
-                                       cm->byte_alignment, NULL, NULL, NULL))
-            vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR,
-                               "Failed to allocate frame buffer");
-          vp9_scale_and_extend_frame(ref, &new_fb_ptr->buf);
-          cpi->scaled_ref_idx[ref_frame - 1] = new_fb;
-          alloc_frame_mvs(cm, new_fb);
-        }
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-      } else {
-        int buf_idx;
-        RefCntBuffer *buf = NULL;
-        if (cpi->oxcf.pass == 0 && !cpi->use_svc) {
-          // Check for release of scaled reference.
-          buf_idx = cpi->scaled_ref_idx[ref_frame - 1];
-          buf = (buf_idx != INVALID_IDX) ? &pool->frame_bufs[buf_idx] : NULL;
-          if (buf != NULL) {
-            --buf->ref_count;
-            cpi->scaled_ref_idx[ref_frame - 1] = INVALID_IDX;
-          }
-        }
-        buf_idx = get_ref_frame_buf_idx(cpi, ref_frame);
-        buf = &pool->frame_bufs[buf_idx];
-        buf->buf.y_crop_width = ref->y_crop_width;
-        buf->buf.y_crop_height = ref->y_crop_height;
-        cpi->scaled_ref_idx[ref_frame - 1] = buf_idx;
-        ++buf->ref_count;
-      }
-    } else {
-      if (cpi->oxcf.pass != 0 || cpi->use_svc)
-        cpi->scaled_ref_idx[ref_frame - 1] = INVALID_IDX;
-    }
-  }
-}
-
-static void release_scaled_references(VP9_COMP *cpi) {
-  VP9_COMMON *cm = &cpi->common;
-  int i;
-  if (cpi->oxcf.pass == 0 && !cpi->use_svc) {
-    // Only release scaled references under certain conditions:
-    // if reference will be updated, or if scaled reference has same resolution.
-    int refresh[3];
-    refresh[0] = (cpi->refresh_last_frame) ? 1 : 0;
-    refresh[1] = (cpi->refresh_golden_frame) ? 1 : 0;
-    refresh[2] = (cpi->refresh_alt_ref_frame) ? 1 : 0;
-    for (i = LAST_FRAME; i <= ALTREF_FRAME; ++i) {
-      const int idx = cpi->scaled_ref_idx[i - 1];
-      RefCntBuffer *const buf = idx != INVALID_IDX ?
-          &cm->buffer_pool->frame_bufs[idx] : NULL;
-      const YV12_BUFFER_CONFIG *const ref = get_ref_frame_buffer(cpi, i);
-      if (buf != NULL &&
-          (refresh[i - 1] ||
-          (buf->buf.y_crop_width == ref->y_crop_width &&
-           buf->buf.y_crop_height == ref->y_crop_height))) {
-        --buf->ref_count;
-        cpi->scaled_ref_idx[i -1] = INVALID_IDX;
-      }
-    }
-  } else {
-    for (i = 0; i < MAX_REF_FRAMES; ++i) {
-      const int idx = cpi->scaled_ref_idx[i];
-      RefCntBuffer *const buf = idx != INVALID_IDX ?
-          &cm->buffer_pool->frame_bufs[idx] : NULL;
-      if (buf != NULL) {
-        --buf->ref_count;
-        cpi->scaled_ref_idx[i] = INVALID_IDX;
-      }
-    }
-  }
-}
-
-static void full_to_model_count(unsigned int *model_count,
-                                unsigned int *full_count) {
-  int n;
-  model_count[ZERO_TOKEN] = full_count[ZERO_TOKEN];
-  model_count[ONE_TOKEN] = full_count[ONE_TOKEN];
-  model_count[TWO_TOKEN] = full_count[TWO_TOKEN];
-  for (n = THREE_TOKEN; n < EOB_TOKEN; ++n)
-    model_count[TWO_TOKEN] += full_count[n];
-  model_count[EOB_MODEL_TOKEN] = full_count[EOB_TOKEN];
-}
-
-static void full_to_model_counts(vp9_coeff_count_model *model_count,
-                                 vp9_coeff_count *full_count) {
-  int i, j, k, l;
-
-  for (i = 0; i < PLANE_TYPES; ++i)
-    for (j = 0; j < REF_TYPES; ++j)
-      for (k = 0; k < COEF_BANDS; ++k)
-        for (l = 0; l < BAND_COEFF_CONTEXTS(k); ++l)
-          full_to_model_count(model_count[i][j][k][l], full_count[i][j][k][l]);
-}
-
-#if 0 && CONFIG_INTERNAL_STATS
-static void output_frame_level_debug_stats(VP9_COMP *cpi) {
-  VP9_COMMON *const cm = &cpi->common;
-  FILE *const f = fopen("tmp.stt", cm->current_video_frame ? "a" : "w");
-  int64_t recon_err;
-
-  vpx_clear_system_state();
-
-#if CONFIG_VP9_HIGHBITDEPTH
-  if (cm->use_highbitdepth) {
-    recon_err = vpx_highbd_get_y_sse(cpi->Source, get_frame_new_buffer(cm));
-  } else {
-    recon_err = vpx_get_y_sse(cpi->Source, get_frame_new_buffer(cm));
-  }
-#else
-  recon_err = vpx_get_y_sse(cpi->Source, get_frame_new_buffer(cm));
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-
-
-  if (cpi->twopass.total_left_stats.coded_error != 0.0) {
-    double dc_quant_devisor;
-#if CONFIG_VP9_HIGHBITDEPTH
-    switch (cm->bit_depth) {
-      case VPX_BITS_8:
-        dc_quant_devisor = 4.0;
-        break;
-      case VPX_BITS_10:
-        dc_quant_devisor = 16.0;
-        break;
-      case VPX_BITS_12:
-        dc_quant_devisor = 64.0;
-        break;
-      default:
-        assert(0 && "bit_depth must be VPX_BITS_8, VPX_BITS_10 or VPX_BITS_12");
-        break;
-    }
-#else
-    dc_quant_devisor = 4.0;
-#endif
-
-    fprintf(f, "%10u %dx%d %10d %10d %d %d %10d %10d %10d %10d"
-       "%10"PRId64" %10"PRId64" %5d %5d %10"PRId64" "
-       "%10"PRId64" %10"PRId64" %10d "
-       "%7.2lf %7.2lf %7.2lf %7.2lf %7.2lf"
-        "%6d %6d %5d %5d %5d "
-        "%10"PRId64" %10.3lf"
-        "%10lf %8u %10"PRId64" %10d %10d %10d %10d %10d\n",
-        cpi->common.current_video_frame,
-        cm->width, cm->height,
-        cpi->td.rd_counts.m_search_count,
-        cpi->td.rd_counts.ex_search_count,
-        cpi->rc.source_alt_ref_pending,
-        cpi->rc.source_alt_ref_active,
-        cpi->rc.this_frame_target,
-        cpi->rc.projected_frame_size,
-        cpi->rc.projected_frame_size / cpi->common.MBs,
-        (cpi->rc.projected_frame_size - cpi->rc.this_frame_target),
-        cpi->rc.vbr_bits_off_target,
-        cpi->rc.vbr_bits_off_target_fast,
-        cpi->twopass.extend_minq,
-        cpi->twopass.extend_minq_fast,
-        cpi->rc.total_target_vs_actual,
-        (cpi->rc.starting_buffer_level - cpi->rc.bits_off_target),
-        cpi->rc.total_actual_bits, cm->base_qindex,
-        vp9_convert_qindex_to_q(cm->base_qindex, cm->bit_depth),
-        (double)vp9_dc_quant(cm->base_qindex, 0, cm->bit_depth) /
-            dc_quant_devisor,
-        vp9_convert_qindex_to_q(cpi->twopass.active_worst_quality,
-                                cm->bit_depth),
-        cpi->rc.avg_q,
-        vp9_convert_qindex_to_q(cpi->oxcf.cq_level, cm->bit_depth),
-        cpi->refresh_last_frame, cpi->refresh_golden_frame,
-        cpi->refresh_alt_ref_frame, cm->frame_type, cpi->rc.gfu_boost,
-        cpi->twopass.bits_left,
-        cpi->twopass.total_left_stats.coded_error,
-        cpi->twopass.bits_left /
-            (1 + cpi->twopass.total_left_stats.coded_error),
-        cpi->tot_recode_hits, recon_err, cpi->rc.kf_boost,
-        cpi->twopass.kf_zeromotion_pct,
-        cpi->twopass.fr_content_type,
-        cm->lf.filter_level,
-        cm->seg.aq_av_offset);
-  }
-  fclose(f);
-
-  if (0) {
-    FILE *const fmodes = fopen("Modes.stt", "a");
-    int i;
-
-    fprintf(fmodes, "%6d:%1d:%1d:%1d ", cpi->common.current_video_frame,
-            cm->frame_type, cpi->refresh_golden_frame,
-            cpi->refresh_alt_ref_frame);
-
-    for (i = 0; i < MAX_MODES; ++i)
-      fprintf(fmodes, "%5d ", cpi->mode_chosen_counts[i]);
-
-    fprintf(fmodes, "\n");
-
-    fclose(fmodes);
-  }
-}
-#endif
-
-static void set_mv_search_params(VP9_COMP *cpi) {
-  const VP9_COMMON *const cm = &cpi->common;
-  const unsigned int max_mv_def = VPXMIN(cm->width, cm->height);
-
-  // Default based on max resolution.
-  cpi->mv_step_param = vp9_init_search_range(max_mv_def);
-
-  if (cpi->sf.mv.auto_mv_step_size) {
-    if (frame_is_intra_only(cm)) {
-      // Initialize max_mv_magnitude for use in the first INTER frame
-      // after a key/intra-only frame.
-      cpi->max_mv_magnitude = max_mv_def;
-    } else {
-      if (cm->show_frame) {
-        // Allow mv_steps to correspond to twice the max mv magnitude found
-        // in the previous frame, capped by the default max_mv_magnitude based
-        // on resolution.
-        cpi->mv_step_param = vp9_init_search_range(
-            VPXMIN(max_mv_def, 2 * cpi->max_mv_magnitude));
-      }
-      cpi->max_mv_magnitude = 0;
-    }
-  }
-}
-
-static void set_size_independent_vars(VP9_COMP *cpi) {
-  vp9_set_speed_features_framesize_independent(cpi);
-  vp9_set_rd_speed_thresholds(cpi);
-  vp9_set_rd_speed_thresholds_sub8x8(cpi);
-  cpi->common.interp_filter = cpi->sf.default_interp_filter;
-}
-
-static void set_size_dependent_vars(VP9_COMP *cpi, int *q,
-                                    int *bottom_index, int *top_index) {
-  VP9_COMMON *const cm = &cpi->common;
-  const VP9EncoderConfig *const oxcf = &cpi->oxcf;
-
-  // Setup variables that depend on the dimensions of the frame.
-  vp9_set_speed_features_framesize_dependent(cpi);
-
-  // Decide q and q bounds.
-  *q = vp9_rc_pick_q_and_bounds(cpi, bottom_index, top_index);
-
-  if (!frame_is_intra_only(cm)) {
-    vp9_set_high_precision_mv(cpi, (*q) < HIGH_PRECISION_MV_QTHRESH);
-  }
-
-  // Configure experimental use of segmentation for enhanced coding of
-  // static regions if indicated.
-  // Only allowed in the second pass of a two pass encode, as it requires
-  // lagged coding, and if the relevant speed feature flag is set.
-  if (oxcf->pass == 2 && cpi->sf.static_segmentation)
-    configure_static_seg_features(cpi);
-
-#if CONFIG_VP9_POSTPROC && !(CONFIG_VP9_TEMPORAL_DENOISING)
-  if (oxcf->noise_sensitivity > 0) {
-    int l = 0;
-    switch (oxcf->noise_sensitivity) {
-      case 1:
-        l = 20;
-        break;
-      case 2:
-        l = 40;
-        break;
-      case 3:
-        l = 60;
-        break;
-      case 4:
-      case 5:
-        l = 100;
-        break;
-      case 6:
-        l = 150;
-        break;
-    }
-    if (!cpi->common.postproc_state.limits) {
-      cpi->common.postproc_state.limits = vpx_calloc(
-          cpi->common.width, sizeof(*cpi->common.postproc_state.limits));
-    }
-    vp9_denoise(cpi->Source, cpi->Source, l, cpi->common.postproc_state.limits);
-  }
-#endif  // CONFIG_VP9_POSTPROC
-}
-
-#if CONFIG_VP9_TEMPORAL_DENOISING
-static void setup_denoiser_buffer(VP9_COMP *cpi) {
-  VP9_COMMON *const cm = &cpi->common;
-  if (cpi->oxcf.noise_sensitivity > 0 &&
-      !cpi->denoiser.frame_buffer_initialized) {
-    if (vp9_denoiser_alloc(&cpi->denoiser, cm->width, cm->height,
-                           cm->subsampling_x, cm->subsampling_y,
-#if CONFIG_VP9_HIGHBITDEPTH
-                           cm->use_highbitdepth,
-#endif
-                           VP9_ENC_BORDER_IN_PIXELS))
-      vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR,
-                         "Failed to allocate denoiser");
-  }
-}
-#endif
-
-static void init_motion_estimation(VP9_COMP *cpi) {
-  int y_stride = cpi->scaled_source.y_stride;
-
-  if (cpi->sf.mv.search_method == NSTEP) {
-    vp9_init3smotion_compensation(&cpi->ss_cfg, y_stride);
-  } else if (cpi->sf.mv.search_method == DIAMOND) {
-    vp9_init_dsmotion_compensation(&cpi->ss_cfg, y_stride);
-  }
-}
-
-static void set_frame_size(VP9_COMP *cpi) {
-  int ref_frame;
-  VP9_COMMON *const cm = &cpi->common;
-  VP9EncoderConfig *const oxcf = &cpi->oxcf;
-  MACROBLOCKD *const xd = &cpi->td.mb.e_mbd;
-
-  if (oxcf->pass == 2 &&
-      oxcf->rc_mode == VPX_VBR &&
-      ((oxcf->resize_mode == RESIZE_FIXED && cm->current_video_frame == 0) ||
-        (oxcf->resize_mode == RESIZE_DYNAMIC && cpi->resize_pending))) {
-    calculate_coded_size(
-        cpi, &oxcf->scaled_frame_width, &oxcf->scaled_frame_height);
-
-    // There has been a change in frame size.
-    vp9_set_size_literal(cpi, oxcf->scaled_frame_width,
-                         oxcf->scaled_frame_height);
-  }
-
-  if (oxcf->pass == 0 &&
-      oxcf->rc_mode == VPX_CBR &&
-      !cpi->use_svc &&
-      oxcf->resize_mode == RESIZE_DYNAMIC &&
-      cpi->resize_pending != 0) {
-    oxcf->scaled_frame_width =
-        (oxcf->width * cpi->resize_scale_num) / cpi->resize_scale_den;
-    oxcf->scaled_frame_height =
-        (oxcf->height * cpi->resize_scale_num) /cpi->resize_scale_den;
-    // There has been a change in frame size.
-    vp9_set_size_literal(cpi,
-                         oxcf->scaled_frame_width,
-                         oxcf->scaled_frame_height);
-
-    // TODO(agrange) Scale cpi->max_mv_magnitude if frame-size has changed.
-    set_mv_search_params(cpi);
-
-    vp9_noise_estimate_init(&cpi->noise_estimate, cm->width, cm->height);
-#if CONFIG_VP9_TEMPORAL_DENOISING
-    // Reset the denoiser on the resized frame.
-    if (cpi->oxcf.noise_sensitivity > 0) {
-      vp9_denoiser_free(&(cpi->denoiser));
-      setup_denoiser_buffer(cpi);
-      // Dynamic resize is only triggered for non-SVC, so we can force
-      // golden frame update here as temporary fix to denoiser.
-      cpi->refresh_golden_frame = 1;
-    }
-#endif
-  }
-
-  if ((oxcf->pass == 2) &&
-      (!cpi->use_svc ||
-          (is_two_pass_svc(cpi) &&
-              cpi->svc.encode_empty_frame_state != ENCODING))) {
-    vp9_set_target_rate(cpi);
-  }
-
-  alloc_frame_mvs(cm, cm->new_fb_idx);
-
-  // Reset the frame pointers to the current frame size.
-  if (vpx_realloc_frame_buffer(get_frame_new_buffer(cm), cm->width, cm->height,
-                               cm->subsampling_x, cm->subsampling_y,
-#if CONFIG_VP9_HIGHBITDEPTH
-                               cm->use_highbitdepth,
-#endif
-                               VP9_ENC_BORDER_IN_PIXELS, cm->byte_alignment,
-                               NULL, NULL, NULL))
-    vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR,
-                       "Failed to allocate frame buffer");
-
-  alloc_util_frame_buffers(cpi);
-  init_motion_estimation(cpi);
-
-  for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) {
-    RefBuffer *const ref_buf = &cm->frame_refs[ref_frame - 1];
-    const int buf_idx = get_ref_frame_buf_idx(cpi, ref_frame);
-
-    ref_buf->idx = buf_idx;
-
-    if (buf_idx != INVALID_IDX) {
-      YV12_BUFFER_CONFIG *const buf = &cm->buffer_pool->frame_bufs[buf_idx].buf;
-      ref_buf->buf = buf;
-#if CONFIG_VP9_HIGHBITDEPTH
-      vp9_setup_scale_factors_for_frame(&ref_buf->sf,
-                                        buf->y_crop_width, buf->y_crop_height,
-                                        cm->width, cm->height,
-                                        (buf->flags & YV12_FLAG_HIGHBITDEPTH) ?
-                                            1 : 0);
-#else
-      vp9_setup_scale_factors_for_frame(&ref_buf->sf,
-                                        buf->y_crop_width, buf->y_crop_height,
-                                        cm->width, cm->height);
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-      if (vp9_is_scaled(&ref_buf->sf))
-        vpx_extend_frame_borders(buf);
-    } else {
-      ref_buf->buf = NULL;
-    }
-  }
-
-  set_ref_ptrs(cm, xd, LAST_FRAME, LAST_FRAME);
-}
-
-static void encode_without_recode_loop(VP9_COMP *cpi,
-                                       size_t *size,
-                                       uint8_t *dest) {
-  VP9_COMMON *const cm = &cpi->common;
-  int q = 0, bottom_index = 0, top_index = 0;  // Dummy variables.
-
-  vpx_clear_system_state();
-
-  set_frame_size(cpi);
-
-  if (is_one_pass_cbr_svc(cpi) &&
-      cpi->un_scaled_source->y_width == cm->width << 2 &&
-      cpi->un_scaled_source->y_height == cm->height << 2 &&
-      cpi->svc.scaled_temp.y_width == cm->width << 1 &&
-      cpi->svc.scaled_temp.y_height == cm->height << 1) {
-    cpi->Source = vp9_svc_twostage_scale(cm,
-                                         cpi->un_scaled_source,
-                                         &cpi->scaled_source,
-                                         &cpi->svc.scaled_temp);
-  } else {
-    cpi->Source = vp9_scale_if_required(cm,
-                                        cpi->un_scaled_source,
-                                        &cpi->scaled_source,
-                                        (cpi->oxcf.pass == 0));
-  }
-  // Avoid scaling last_source unless its needed.
-  // Last source is needed if vp9_avg_source_sad() is used, or if
-  // partition_search_type == SOURCE_VAR_BASED_PARTITION, or if noise
-  // estimation is enabled.
-  if (cpi->unscaled_last_source != NULL &&
-      (cpi->oxcf.content == VP9E_CONTENT_SCREEN ||
-      (cpi->oxcf.pass == 0 && cpi->oxcf.rc_mode == VPX_VBR &&
-      cpi->oxcf.mode == REALTIME && cpi->oxcf.speed >= 5) ||
-      cpi->sf.partition_search_type == SOURCE_VAR_BASED_PARTITION ||
-      cpi->noise_estimate.enabled))
-    cpi->Last_Source = vp9_scale_if_required(cm,
-                                             cpi->unscaled_last_source,
-                                             &cpi->scaled_last_source,
-                                             (cpi->oxcf.pass == 0));
-
-  if (cm->frame_type == KEY_FRAME || cpi->resize_pending != 0) {
-    memset(cpi->consec_zero_mv, 0,
-           cm->mi_rows * cm->mi_cols * sizeof(*cpi->consec_zero_mv));
-  }
-
-  vp9_update_noise_estimate(cpi);
-
-  if (cpi->oxcf.pass == 0 &&
-      cpi->oxcf.mode == REALTIME &&
-      cpi->oxcf.speed >= 5 &&
-      cpi->resize_state == 0 &&
-      cm->frame_type != KEY_FRAME &&
-      (cpi->oxcf.content == VP9E_CONTENT_SCREEN ||
-       cpi->oxcf.rc_mode == VPX_VBR))
-    vp9_avg_source_sad(cpi);
-
-  // For 1 pass SVC, since only ZEROMV is allowed for upsampled reference
-  // frame (i.e, svc->force_zero_mode_spatial_ref = 0), we can avoid this
-  // frame-level upsampling.
-  if (frame_is_intra_only(cm) == 0 && !is_one_pass_cbr_svc(cpi)) {
-    vp9_scale_references(cpi);
-  }
-
-  set_size_independent_vars(cpi);
-  set_size_dependent_vars(cpi, &q, &bottom_index, &top_index);
-
-  if (cpi->oxcf.speed >= 5 &&
-      cpi->oxcf.pass == 0 &&
-      cpi->oxcf.rc_mode == VPX_CBR &&
-      cpi->oxcf.content != VP9E_CONTENT_SCREEN &&
-      cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ) {
-    cpi->use_skin_detection = 1;
-  }
-
-  vp9_set_quantizer(cm, q);
-  vp9_set_variance_partition_thresholds(cpi, q);
-
-  setup_frame(cpi);
-
-  suppress_active_map(cpi);
-  // Variance adaptive and in frame q adjustment experiments are mutually
-  // exclusive.
-  if (cpi->oxcf.aq_mode == VARIANCE_AQ) {
-    vp9_vaq_frame_setup(cpi);
-  } else if (cpi->oxcf.aq_mode == EQUATOR360_AQ) {
-    vp9_360aq_frame_setup(cpi);
-  } else if (cpi->oxcf.aq_mode == COMPLEXITY_AQ) {
-    vp9_setup_in_frame_q_adj(cpi);
-  } else if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ) {
-    vp9_cyclic_refresh_setup(cpi);
-  }
-  apply_active_map(cpi);
-
-  // transform / motion compensation build reconstruction frame
-  vp9_encode_frame(cpi);
-
-  // Check if we should drop this frame because of high overshoot.
-  // Only for frames where high temporal-source sad is detected.
-  if (cpi->oxcf.pass == 0 &&
-      cpi->oxcf.rc_mode == VPX_CBR &&
-      cpi->resize_state == 0 &&
-      cm->frame_type != KEY_FRAME &&
-      cpi->oxcf.content == VP9E_CONTENT_SCREEN &&
-      cpi->rc.high_source_sad == 1) {
-    int frame_size = 0;
-    // Get an estimate of the encoded frame size.
-    save_coding_context(cpi);
-    vp9_pack_bitstream(cpi, dest, size);
-    restore_coding_context(cpi);
-    frame_size = (int)(*size) << 3;
-    // Check if encoded frame will overshoot too much, and if so, set the q and
-    // adjust some rate control parameters, and return to re-encode the frame.
-    if (vp9_encodedframe_overshoot(cpi, frame_size, &q)) {
-      vpx_clear_system_state();
-      vp9_set_quantizer(cm, q);
-      vp9_set_variance_partition_thresholds(cpi, q);
-      suppress_active_map(cpi);
-      // Turn-off cyclic refresh for re-encoded frame.
-      if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ) {
-        unsigned char *const seg_map = cpi->segmentation_map;
-        memset(seg_map, 0, cm->mi_rows * cm->mi_cols);
-        vp9_disable_segmentation(&cm->seg);
-      }
-      apply_active_map(cpi);
-      vp9_encode_frame(cpi);
-    }
-  }
-
-  // Update some stats from cyclic refresh, and check if we should not update
-  // golden reference, for non-SVC 1 pass CBR.
-  if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ &&
-      cm->frame_type != KEY_FRAME &&
-      !cpi->use_svc &&
-      cpi->ext_refresh_frame_flags_pending == 0 &&
-      (cpi->oxcf.pass == 0 && cpi->oxcf.rc_mode == VPX_CBR))
-    vp9_cyclic_refresh_check_golden_update(cpi);
-
-  // Update the skip mb flag probabilities based on the distribution
-  // seen in the last encoder iteration.
-  // update_base_skip_probs(cpi);
-  vpx_clear_system_state();
-}
-
-static void encode_with_recode_loop(VP9_COMP *cpi,
-                                    size_t *size,
-                                    uint8_t *dest) {
-  VP9_COMMON *const cm = &cpi->common;
-  RATE_CONTROL *const rc = &cpi->rc;
-  int bottom_index, top_index;
-  int loop_count = 0;
-  int loop_at_this_size = 0;
-  int loop = 0;
-  int overshoot_seen = 0;
-  int undershoot_seen = 0;
-  int frame_over_shoot_limit;
-  int frame_under_shoot_limit;
-  int q = 0, q_low = 0, q_high = 0;
-
-  set_size_independent_vars(cpi);
-
-  do {
-    vpx_clear_system_state();
-
-    set_frame_size(cpi);
-
-    if (loop_count == 0 || cpi->resize_pending != 0) {
-      set_size_dependent_vars(cpi, &q, &bottom_index, &top_index);
-
-      // TODO(agrange) Scale cpi->max_mv_magnitude if frame-size has changed.
-      set_mv_search_params(cpi);
-
-      // Reset the loop state for new frame size.
-      overshoot_seen = 0;
-      undershoot_seen = 0;
-
-      // Reconfiguration for change in frame size has concluded.
-      cpi->resize_pending = 0;
-
-      q_low = bottom_index;
-      q_high = top_index;
-
-      loop_at_this_size = 0;
-    }
-
-    // Decide frame size bounds first time through.
-    if (loop_count == 0) {
-      vp9_rc_compute_frame_size_bounds(cpi, rc->this_frame_target,
-                                       &frame_under_shoot_limit,
-                                       &frame_over_shoot_limit);
-    }
-
-    cpi->Source = vp9_scale_if_required(cm, cpi->un_scaled_source,
-                                      &cpi->scaled_source,
-                                      (cpi->oxcf.pass == 0));
-
-    if (cpi->unscaled_last_source != NULL)
-      cpi->Last_Source = vp9_scale_if_required(cm, cpi->unscaled_last_source,
-                                               &cpi->scaled_last_source,
-                                               (cpi->oxcf.pass == 0));
-
-    if (frame_is_intra_only(cm) == 0) {
-      if (loop_count > 0) {
-        release_scaled_references(cpi);
-      }
-      vp9_scale_references(cpi);
-    }
-
-    vp9_set_quantizer(cm, q);
-
-    if (loop_count == 0)
-      setup_frame(cpi);
-
-    // Variance adaptive and in frame q adjustment experiments are mutually
-    // exclusive.
-    if (cpi->oxcf.aq_mode == VARIANCE_AQ) {
-      vp9_vaq_frame_setup(cpi);
-    } else if (cpi->oxcf.aq_mode == EQUATOR360_AQ) {
-      vp9_360aq_frame_setup(cpi);
-    } else if (cpi->oxcf.aq_mode == COMPLEXITY_AQ) {
-      vp9_setup_in_frame_q_adj(cpi);
-    }
-
-    // transform / motion compensation build reconstruction frame
-    vp9_encode_frame(cpi);
-
-    // Update the skip mb flag probabilities based on the distribution
-    // seen in the last encoder iteration.
-    // update_base_skip_probs(cpi);
-
-    vpx_clear_system_state();
-
-    // Dummy pack of the bitstream using up to date stats to get an
-    // accurate estimate of output frame size to determine if we need
-    // to recode.
-    if (cpi->sf.recode_loop >= ALLOW_RECODE_KFARFGF) {
-      save_coding_context(cpi);
-      if (!cpi->sf.use_nonrd_pick_mode)
-        vp9_pack_bitstream(cpi, dest, size);
-
-      rc->projected_frame_size = (int)(*size) << 3;
-      restore_coding_context(cpi);
-
-      if (frame_over_shoot_limit == 0)
-        frame_over_shoot_limit = 1;
-    }
-
-    if (cpi->oxcf.rc_mode == VPX_Q) {
-      loop = 0;
-    } else {
-      if ((cm->frame_type == KEY_FRAME) &&
-           rc->this_key_frame_forced &&
-           (rc->projected_frame_size < rc->max_frame_bandwidth)) {
-        int last_q = q;
-        int64_t kf_err;
-
-        int64_t high_err_target = cpi->ambient_err;
-        int64_t low_err_target = cpi->ambient_err >> 1;
-
-#if CONFIG_VP9_HIGHBITDEPTH
-        if (cm->use_highbitdepth) {
-          kf_err = vpx_highbd_get_y_sse(cpi->Source, get_frame_new_buffer(cm));
-        } else {
-          kf_err = vpx_get_y_sse(cpi->Source, get_frame_new_buffer(cm));
-        }
-#else
-        kf_err = vpx_get_y_sse(cpi->Source, get_frame_new_buffer(cm));
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-
-        // Prevent possible divide by zero error below for perfect KF
-        kf_err += !kf_err;
-
-        // The key frame is not good enough or we can afford
-        // to make it better without undue risk of popping.
-        if ((kf_err > high_err_target &&
-             rc->projected_frame_size <= frame_over_shoot_limit) ||
-            (kf_err > low_err_target &&
-             rc->projected_frame_size <= frame_under_shoot_limit)) {
-          // Lower q_high
-          q_high = q > q_low ? q - 1 : q_low;
-
-          // Adjust Q
-          q = (int)((q * high_err_target) / kf_err);
-          q = VPXMIN(q, (q_high + q_low) >> 1);
-        } else if (kf_err < low_err_target &&
-                   rc->projected_frame_size >= frame_under_shoot_limit) {
-          // The key frame is much better than the previous frame
-          // Raise q_low
-          q_low = q < q_high ? q + 1 : q_high;
-
-          // Adjust Q
-          q = (int)((q * low_err_target) / kf_err);
-          q = VPXMIN(q, (q_high + q_low + 1) >> 1);
-        }
-
-        // Clamp Q to upper and lower limits:
-        q = clamp(q, q_low, q_high);
-
-        loop = q != last_q;
-      } else if (recode_loop_test(
-          cpi, frame_over_shoot_limit, frame_under_shoot_limit,
-          q, VPXMAX(q_high, top_index), bottom_index)) {
-        // Is the projected frame size out of range and are we allowed
-        // to attempt to recode.
-        int last_q = q;
-        int retries = 0;
-
-        if (cpi->resize_pending == 1) {
-          // Change in frame size so go back around the recode loop.
-          cpi->rc.frame_size_selector =
-              SCALE_STEP1 - cpi->rc.frame_size_selector;
-          cpi->rc.next_frame_size_selector = cpi->rc.frame_size_selector;
-
-#if CONFIG_INTERNAL_STATS
-          ++cpi->tot_recode_hits;
-#endif
-          ++loop_count;
-          loop = 1;
-          continue;
-        }
-
-        // Frame size out of permitted range:
-        // Update correction factor & compute new Q to try...
-
-        // Frame is too large
-        if (rc->projected_frame_size > rc->this_frame_target) {
-          // Special case if the projected size is > the max allowed.
-          if (rc->projected_frame_size >= rc->max_frame_bandwidth)
-            q_high = rc->worst_quality;
-
-          // Raise Qlow as to at least the current value
-          q_low = q < q_high ? q + 1 : q_high;
-
-          if (undershoot_seen || loop_at_this_size > 1) {
-            // Update rate_correction_factor unless
-            vp9_rc_update_rate_correction_factors(cpi);
-
-            q = (q_high + q_low + 1) / 2;
-          } else {
-            // Update rate_correction_factor unless
-            vp9_rc_update_rate_correction_factors(cpi);
-
-            q = vp9_rc_regulate_q(cpi, rc->this_frame_target,
-                                  bottom_index, VPXMAX(q_high, top_index));
-
-            while (q < q_low && retries < 10) {
-              vp9_rc_update_rate_correction_factors(cpi);
-              q = vp9_rc_regulate_q(cpi, rc->this_frame_target,
-                                    bottom_index, VPXMAX(q_high, top_index));
-              retries++;
-            }
-          }
-
-          overshoot_seen = 1;
-        } else {
-          // Frame is too small
-          q_high = q > q_low ? q - 1 : q_low;
-
-          if (overshoot_seen || loop_at_this_size > 1) {
-            vp9_rc_update_rate_correction_factors(cpi);
-            q = (q_high + q_low) / 2;
-          } else {
-            vp9_rc_update_rate_correction_factors(cpi);
-            q = vp9_rc_regulate_q(cpi, rc->this_frame_target,
-                                   bottom_index, top_index);
-            // Special case reset for qlow for constrained quality.
-            // This should only trigger where there is very substantial
-            // undershoot on a frame and the auto cq level is above
-            // the user passsed in value.
-            if (cpi->oxcf.rc_mode == VPX_CQ &&
-                q < q_low) {
-              q_low = q;
-            }
-
-            while (q > q_high && retries < 10) {
-              vp9_rc_update_rate_correction_factors(cpi);
-              q = vp9_rc_regulate_q(cpi, rc->this_frame_target,
-                                     bottom_index, top_index);
-              retries++;
-            }
-          }
-
-          undershoot_seen = 1;
-        }
-
-        // Clamp Q to upper and lower limits:
-        q = clamp(q, q_low, q_high);
-
-        loop = (q != last_q);
-      } else {
-        loop = 0;
-      }
-    }
-
-    // Special case for overlay frame.
-    if (rc->is_src_frame_alt_ref &&
-        rc->projected_frame_size < rc->max_frame_bandwidth)
-      loop = 0;
-
-    if (loop) {
-      ++loop_count;
-      ++loop_at_this_size;
-
-#if CONFIG_INTERNAL_STATS
-      ++cpi->tot_recode_hits;
-#endif
-    }
-  } while (loop);
-}
-
-static int get_ref_frame_flags(const VP9_COMP *cpi) {
-  const int *const map = cpi->common.ref_frame_map;
-  const int gold_is_last = map[cpi->gld_fb_idx] == map[cpi->lst_fb_idx];
-  const int alt_is_last = map[cpi->alt_fb_idx] == map[cpi->lst_fb_idx];
-  const int gold_is_alt = map[cpi->gld_fb_idx] == map[cpi->alt_fb_idx];
-  int flags = VP9_ALT_FLAG | VP9_GOLD_FLAG | VP9_LAST_FLAG;
-
-  if (gold_is_last)
-    flags &= ~VP9_GOLD_FLAG;
-
-  if (cpi->rc.frames_till_gf_update_due == INT_MAX &&
-      (cpi->svc.number_temporal_layers == 1 &&
-       cpi->svc.number_spatial_layers == 1))
-    flags &= ~VP9_GOLD_FLAG;
-
-  if (alt_is_last)
-    flags &= ~VP9_ALT_FLAG;
-
-  if (gold_is_alt)
-    flags &= ~VP9_ALT_FLAG;
-
-  return flags;
-}
-
-static void set_ext_overrides(VP9_COMP *cpi) {
-  // Overrides the defaults with the externally supplied values with
-  // vp9_update_reference() and vp9_update_entropy() calls
-  // Note: The overrides are valid only for the next frame passed
-  // to encode_frame_to_data_rate() function
-  if (cpi->ext_refresh_frame_context_pending) {
-    cpi->common.refresh_frame_context = cpi->ext_refresh_frame_context;
-    cpi->ext_refresh_frame_context_pending = 0;
-  }
-  if (cpi->ext_refresh_frame_flags_pending) {
-    cpi->refresh_last_frame = cpi->ext_refresh_last_frame;
-    cpi->refresh_golden_frame = cpi->ext_refresh_golden_frame;
-    cpi->refresh_alt_ref_frame = cpi->ext_refresh_alt_ref_frame;
-  }
-}
-
-YV12_BUFFER_CONFIG *vp9_svc_twostage_scale(VP9_COMMON *cm,
-                                           YV12_BUFFER_CONFIG *unscaled,
-                                           YV12_BUFFER_CONFIG *scaled,
-                                           YV12_BUFFER_CONFIG *scaled_temp) {
-  if (cm->mi_cols * MI_SIZE != unscaled->y_width ||
-      cm->mi_rows * MI_SIZE != unscaled->y_height) {
-#if CONFIG_VP9_HIGHBITDEPTH
-    scale_and_extend_frame(unscaled, scaled_temp, (int)cm->bit_depth);
-    scale_and_extend_frame(scaled_temp, scaled, (int)cm->bit_depth);
-#else
-    vp9_scale_and_extend_frame(unscaled, scaled_temp);
-    vp9_scale_and_extend_frame(scaled_temp, scaled);
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-    return scaled;
-  } else {
-    return unscaled;
-  }
-}
-
-YV12_BUFFER_CONFIG *vp9_scale_if_required(VP9_COMMON *cm,
-                                          YV12_BUFFER_CONFIG *unscaled,
-                                          YV12_BUFFER_CONFIG *scaled,
-                                          int use_normative_scaler) {
-  if (cm->mi_cols * MI_SIZE != unscaled->y_width ||
-      cm->mi_rows * MI_SIZE != unscaled->y_height) {
-#if CONFIG_VP9_HIGHBITDEPTH
-    if (use_normative_scaler &&
-        unscaled->y_width <= (scaled->y_width << 1) &&
-        unscaled->y_height <= (scaled->y_height << 1))
-      scale_and_extend_frame(unscaled, scaled, (int)cm->bit_depth);
-    else
-      scale_and_extend_frame_nonnormative(unscaled, scaled, (int)cm->bit_depth);
-#else
-    if (use_normative_scaler &&
-        unscaled->y_width <= (scaled->y_width << 1) &&
-        unscaled->y_height <= (scaled->y_height << 1))
-      vp9_scale_and_extend_frame(unscaled, scaled);
-    else
-      scale_and_extend_frame_nonnormative(unscaled, scaled);
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-    return scaled;
-  } else {
-    return unscaled;
-  }
-}
-
-static void set_arf_sign_bias(VP9_COMP *cpi) {
-  VP9_COMMON *const cm = &cpi->common;
-  int arf_sign_bias;
-
-  if ((cpi->oxcf.pass == 2) && cpi->multi_arf_allowed) {
-    const GF_GROUP *const gf_group = &cpi->twopass.gf_group;
-    arf_sign_bias = cpi->rc.source_alt_ref_active &&
-                    (!cpi->refresh_alt_ref_frame ||
-                     (gf_group->rf_level[gf_group->index] == GF_ARF_LOW));
-  } else {
-    arf_sign_bias =
-      (cpi->rc.source_alt_ref_active && !cpi->refresh_alt_ref_frame);
-  }
-  cm->ref_frame_sign_bias[ALTREF_FRAME] = arf_sign_bias;
-}
-
-static int setup_interp_filter_search_mask(VP9_COMP *cpi) {
-  INTERP_FILTER ifilter;
-  int ref_total[MAX_REF_FRAMES] = {0};
-  MV_REFERENCE_FRAME ref;
-  int mask = 0;
-  if (cpi->common.last_frame_type == KEY_FRAME ||
-      cpi->refresh_alt_ref_frame)
-    return mask;
-  for (ref = LAST_FRAME; ref <= ALTREF_FRAME; ++ref)
-    for (ifilter = EIGHTTAP; ifilter <= EIGHTTAP_SHARP; ++ifilter)
-      ref_total[ref] += cpi->interp_filter_selected[ref][ifilter];
-
-  for (ifilter = EIGHTTAP; ifilter <= EIGHTTAP_SHARP; ++ifilter) {
-    if ((ref_total[LAST_FRAME] &&
-        cpi->interp_filter_selected[LAST_FRAME][ifilter] == 0) &&
-        (ref_total[GOLDEN_FRAME] == 0 ||
-         cpi->interp_filter_selected[GOLDEN_FRAME][ifilter] * 50
-           < ref_total[GOLDEN_FRAME]) &&
-        (ref_total[ALTREF_FRAME] == 0 ||
-         cpi->interp_filter_selected[ALTREF_FRAME][ifilter] * 50
-           < ref_total[ALTREF_FRAME]))
-      mask |= 1 << ifilter;
-  }
-  return mask;
-}
-
-static void encode_frame_to_data_rate(VP9_COMP *cpi,
-                                      size_t *size,
-                                      uint8_t *dest,
-                                      unsigned int *frame_flags) {
-  VP9_COMMON *const cm = &cpi->common;
-  const VP9EncoderConfig *const oxcf = &cpi->oxcf;
-  struct segmentation *const seg = &cm->seg;
-  TX_SIZE t;
-
-  set_ext_overrides(cpi);
-  vpx_clear_system_state();
-
-  // Set the arf sign bias for this frame.
-  set_arf_sign_bias(cpi);
-
-  // Set default state for segment based loop filter update flags.
-  cm->lf.mode_ref_delta_update = 0;
-
-  if (cpi->oxcf.pass == 2 &&
-      cpi->sf.adaptive_interp_filter_search)
-    cpi->sf.interp_filter_search_mask =
-        setup_interp_filter_search_mask(cpi);
-
-  // Set various flags etc to special state if it is a key frame.
-  if (frame_is_intra_only(cm)) {
-    // Reset the loop filter deltas and segmentation map.
-    vp9_reset_segment_features(&cm->seg);
-
-    // If segmentation is enabled force a map update for key frames.
-    if (seg->enabled) {
-      seg->update_map = 1;
-      seg->update_data = 1;
-    }
-
-    // The alternate reference frame cannot be active for a key frame.
-    cpi->rc.source_alt_ref_active = 0;
-
-    cm->error_resilient_mode = oxcf->error_resilient_mode;
-    cm->frame_parallel_decoding_mode = oxcf->frame_parallel_decoding_mode;
-
-    // By default, encoder assumes decoder can use prev_mi.
-    if (cm->error_resilient_mode) {
-      cm->frame_parallel_decoding_mode = 1;
-      cm->reset_frame_context = 0;
-      cm->refresh_frame_context = 0;
-    } else if (cm->intra_only) {
-      // Only reset the current context.
-      cm->reset_frame_context = 2;
-    }
-  }
-  if (is_two_pass_svc(cpi) && cm->error_resilient_mode == 0) {
-    // Use context 0 for intra only empty frame, but the last frame context
-    // for other empty frames.
-    if (cpi->svc.encode_empty_frame_state == ENCODING) {
-      if (cpi->svc.encode_intra_empty_frame != 0)
-        cm->frame_context_idx = 0;
-      else
-        cm->frame_context_idx = FRAME_CONTEXTS - 1;
-    } else {
-    cm->frame_context_idx =
-        cpi->svc.spatial_layer_id * cpi->svc.number_temporal_layers +
-        cpi->svc.temporal_layer_id;
-    }
-
-    cm->frame_parallel_decoding_mode = oxcf->frame_parallel_decoding_mode;
-
-    // The probs will be updated based on the frame type of its previous
-    // frame if frame_parallel_decoding_mode is 0. The type may vary for
-    // the frame after a key frame in base layer since we may drop enhancement
-    // layers. So set frame_parallel_decoding_mode to 1 in this case.
-    if (cm->frame_parallel_decoding_mode == 0) {
-      if (cpi->svc.number_temporal_layers == 1) {
-        if (cpi->svc.spatial_layer_id == 0 &&
-            cpi->svc.layer_context[0].last_frame_type == KEY_FRAME)
-          cm->frame_parallel_decoding_mode = 1;
-      } else if (cpi->svc.spatial_layer_id == 0) {
-        // Find the 2nd frame in temporal base layer and 1st frame in temporal
-        // enhancement layers from the key frame.
-        int i;
-        for (i = 0; i < cpi->svc.number_temporal_layers; ++i) {
-          if (cpi->svc.layer_context[0].frames_from_key_frame == 1 << i) {
-            cm->frame_parallel_decoding_mode = 1;
-            break;
-          }
-        }
-      }
-    }
-  }
-
-  // For 1 pass CBR, check if we are dropping this frame.
-  // For spatial layers, for now only check for frame-dropping on first spatial
-  // layer, and if decision is to drop, we drop whole super-frame.
-  if (oxcf->pass == 0 &&
-      oxcf->rc_mode == VPX_CBR &&
-      cm->frame_type != KEY_FRAME) {
-    if (vp9_rc_drop_frame(cpi) ||
-        (is_one_pass_cbr_svc(cpi) && cpi->svc.rc_drop_superframe == 1)) {
-      vp9_rc_postencode_update_drop_frame(cpi);
-      ++cm->current_video_frame;
-      cpi->ext_refresh_frame_flags_pending = 0;
-      cpi->svc.rc_drop_superframe = 1;
-      // TODO(marpan): Advancing the svc counters on dropped frames can break
-      // the referencing scheme for the fixed svc patterns defined in
-      // vp9_one_pass_cbr_svc_start_layer(). Look into fixing this issue, but
-      // for now, don't advance the svc frame counters on dropped frame.
-      // if (cpi->use_svc)
-      //   vp9_inc_frame_in_layer(cpi);
-      return;
-    }
-  }
-
-  vpx_clear_system_state();
-
-#if CONFIG_INTERNAL_STATS
-  memset(cpi->mode_chosen_counts, 0,
-         MAX_MODES * sizeof(*cpi->mode_chosen_counts));
-#endif
-
-  if (cpi->sf.recode_loop == DISALLOW_RECODE) {
-    encode_without_recode_loop(cpi, size, dest);
-  } else {
-    encode_with_recode_loop(cpi, size, dest);
-  }
-
-#if CONFIG_VP9_TEMPORAL_DENOISING
-#ifdef OUTPUT_YUV_DENOISED
-  if (oxcf->noise_sensitivity > 0) {
-    vp9_write_yuv_frame_420(&cpi->denoiser.running_avg_y[INTRA_FRAME],
-                            yuv_denoised_file);
-  }
-#endif
-#endif
-#ifdef OUTPUT_YUV_SKINMAP
-  if (cpi->common.current_video_frame > 1) {
-    vp9_compute_skin_map(cpi, yuv_skinmap_file);
-  }
-#endif
-
-  // Special case code to reduce pulsing when key frames are forced at a
-  // fixed interval. Note the reconstruction error if it is the frame before
-  // the force key frame
-  if (cpi->rc.next_key_frame_forced && cpi->rc.frames_to_key == 1) {
-#if CONFIG_VP9_HIGHBITDEPTH
-    if (cm->use_highbitdepth) {
-      cpi->ambient_err = vpx_highbd_get_y_sse(cpi->Source,
-                                              get_frame_new_buffer(cm));
-    } else {
-      cpi->ambient_err = vpx_get_y_sse(cpi->Source, get_frame_new_buffer(cm));
-    }
-#else
-    cpi->ambient_err = vpx_get_y_sse(cpi->Source, get_frame_new_buffer(cm));
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-  }
-
-  // If the encoder forced a KEY_FRAME decision
-  if (cm->frame_type == KEY_FRAME)
-    cpi->refresh_last_frame = 1;
-
-  cm->frame_to_show = get_frame_new_buffer(cm);
-  cm->frame_to_show->color_space = cm->color_space;
-  cm->frame_to_show->color_range = cm->color_range;
-  cm->frame_to_show->render_width  = cm->render_width;
-  cm->frame_to_show->render_height = cm->render_height;
-
-  // Pick the loop filter level for the frame.
-  loopfilter_frame(cpi, cm);
-
-  // build the bitstream
-  vp9_pack_bitstream(cpi, dest, size);
-
-  if (cm->seg.update_map)
-    update_reference_segmentation_map(cpi);
-
-  if (frame_is_intra_only(cm) == 0) {
-    release_scaled_references(cpi);
-  }
-  vp9_update_reference_frames(cpi);
-
-  for (t = TX_4X4; t <= TX_32X32; t++)
-    full_to_model_counts(cpi->td.counts->coef[t],
-                         cpi->td.rd_counts.coef_counts[t]);
-
-  if (!cm->error_resilient_mode && !cm->frame_parallel_decoding_mode)
-    vp9_adapt_coef_probs(cm);
-
-  if (!frame_is_intra_only(cm)) {
-    if (!cm->error_resilient_mode && !cm->frame_parallel_decoding_mode) {
-      vp9_adapt_mode_probs(cm);
-      vp9_adapt_mv_probs(cm, cm->allow_high_precision_mv);
-    }
-  }
-
-  cpi->ext_refresh_frame_flags_pending = 0;
-
-  if (cpi->refresh_golden_frame == 1)
-    cpi->frame_flags |= FRAMEFLAGS_GOLDEN;
-  else
-    cpi->frame_flags &= ~FRAMEFLAGS_GOLDEN;
-
-  if (cpi->refresh_alt_ref_frame == 1)
-    cpi->frame_flags |= FRAMEFLAGS_ALTREF;
-  else
-    cpi->frame_flags &= ~FRAMEFLAGS_ALTREF;
-
-  cpi->ref_frame_flags = get_ref_frame_flags(cpi);
-
-  cm->last_frame_type = cm->frame_type;
-
-  if (!(is_two_pass_svc(cpi) && cpi->svc.encode_empty_frame_state == ENCODING))
-    vp9_rc_postencode_update(cpi, *size);
-
-#if 0
-  output_frame_level_debug_stats(cpi);
-#endif
-
-  if (cm->frame_type == KEY_FRAME) {
-    // Tell the caller that the frame was coded as a key frame
-    *frame_flags = cpi->frame_flags | FRAMEFLAGS_KEY;
-  } else {
-    *frame_flags = cpi->frame_flags & ~FRAMEFLAGS_KEY;
-  }
-
-  // Clear the one shot update flags for segmentation map and mode/ref loop
-  // filter deltas.
-  cm->seg.update_map = 0;
-  cm->seg.update_data = 0;
-  cm->lf.mode_ref_delta_update = 0;
-
-  // keep track of the last coded dimensions
-  cm->last_width = cm->width;
-  cm->last_height = cm->height;
-
-  // reset to normal state now that we are done.
-  if (!cm->show_existing_frame)
-    cm->last_show_frame = cm->show_frame;
-
-  if (cm->show_frame) {
-    vp9_swap_mi_and_prev_mi(cm);
-    // Don't increment frame counters if this was an altref buffer
-    // update not a real frame
-    ++cm->current_video_frame;
-    if (cpi->use_svc)
-      vp9_inc_frame_in_layer(cpi);
-  }
-  cm->prev_frame = cm->cur_frame;
-
-  if (cpi->use_svc)
-    cpi->svc.layer_context[cpi->svc.spatial_layer_id *
-                           cpi->svc.number_temporal_layers +
-                           cpi->svc.temporal_layer_id].last_frame_type =
-                               cm->frame_type;
-}
-
-static void SvcEncode(VP9_COMP *cpi, size_t *size, uint8_t *dest,
-                      unsigned int *frame_flags) {
-  vp9_rc_get_svc_params(cpi);
-  encode_frame_to_data_rate(cpi, size, dest, frame_flags);
-}
-
-static void Pass0Encode(VP9_COMP *cpi, size_t *size, uint8_t *dest,
-                        unsigned int *frame_flags) {
-  if (cpi->oxcf.rc_mode == VPX_CBR) {
-    vp9_rc_get_one_pass_cbr_params(cpi);
-  } else {
-    vp9_rc_get_one_pass_vbr_params(cpi);
-  }
-  encode_frame_to_data_rate(cpi, size, dest, frame_flags);
-}
-
-static void Pass2Encode(VP9_COMP *cpi, size_t *size,
-                        uint8_t *dest, unsigned int *frame_flags) {
-  cpi->allow_encode_breakout = ENCODE_BREAKOUT_ENABLED;
-  encode_frame_to_data_rate(cpi, size, dest, frame_flags);
-
-  if (!(is_two_pass_svc(cpi) && cpi->svc.encode_empty_frame_state == ENCODING))
-    vp9_twopass_postencode_update(cpi);
-}
-
-static void init_ref_frame_bufs(VP9_COMMON *cm) {
-  int i;
-  BufferPool *const pool = cm->buffer_pool;
-  cm->new_fb_idx = INVALID_IDX;
-  for (i = 0; i < REF_FRAMES; ++i) {
-    cm->ref_frame_map[i] = INVALID_IDX;
-    pool->frame_bufs[i].ref_count = 0;
-  }
-}
-
-static void check_initial_width(VP9_COMP *cpi,
-#if CONFIG_VP9_HIGHBITDEPTH
-                                int use_highbitdepth,
-#endif
-                                int subsampling_x, int subsampling_y) {
-  VP9_COMMON *const cm = &cpi->common;
-
-  if (!cpi->initial_width ||
-#if CONFIG_VP9_HIGHBITDEPTH
-      cm->use_highbitdepth != use_highbitdepth ||
-#endif
-      cm->subsampling_x != subsampling_x ||
-      cm->subsampling_y != subsampling_y) {
-    cm->subsampling_x = subsampling_x;
-    cm->subsampling_y = subsampling_y;
-#if CONFIG_VP9_HIGHBITDEPTH
-    cm->use_highbitdepth = use_highbitdepth;
-#endif
-
-    alloc_raw_frame_buffers(cpi);
-    init_ref_frame_bufs(cm);
-    alloc_util_frame_buffers(cpi);
-
-    init_motion_estimation(cpi);  // TODO(agrange) This can be removed.
-
-    cpi->initial_width = cm->width;
-    cpi->initial_height = cm->height;
-    cpi->initial_mbs = cm->MBs;
-  }
-}
-
-int vp9_receive_raw_frame(VP9_COMP *cpi, unsigned int frame_flags,
-                          YV12_BUFFER_CONFIG *sd, int64_t time_stamp,
-                          int64_t end_time) {
-  VP9_COMMON *const cm = &cpi->common;
-  struct vpx_usec_timer timer;
-  int res = 0;
-  const int subsampling_x = sd->subsampling_x;
-  const int subsampling_y = sd->subsampling_y;
-#if CONFIG_VP9_HIGHBITDEPTH
-  const int use_highbitdepth = (sd->flags & YV12_FLAG_HIGHBITDEPTH) != 0;
-#endif
-
-#if CONFIG_VP9_HIGHBITDEPTH
-  check_initial_width(cpi, use_highbitdepth, subsampling_x, subsampling_y);
-#else
-  check_initial_width(cpi, subsampling_x, subsampling_y);
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-
-#if CONFIG_VP9_TEMPORAL_DENOISING
-  setup_denoiser_buffer(cpi);
-#endif
-  vpx_usec_timer_start(&timer);
-
-  if (vp9_lookahead_push(cpi->lookahead, sd, time_stamp, end_time,
-#if CONFIG_VP9_HIGHBITDEPTH
-                         use_highbitdepth,
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-                         frame_flags))
-    res = -1;
-  vpx_usec_timer_mark(&timer);
-  cpi->time_receive_data += vpx_usec_timer_elapsed(&timer);
-
-  if ((cm->profile == PROFILE_0 || cm->profile == PROFILE_2) &&
-      (subsampling_x != 1 || subsampling_y != 1)) {
-    vpx_internal_error(&cm->error, VPX_CODEC_INVALID_PARAM,
-                       "Non-4:2:0 color format requires profile 1 or 3");
-    res = -1;
-  }
-  if ((cm->profile == PROFILE_1 || cm->profile == PROFILE_3) &&
-      (subsampling_x == 1 && subsampling_y == 1)) {
-    vpx_internal_error(&cm->error, VPX_CODEC_INVALID_PARAM,
-                       "4:2:0 color format requires profile 0 or 2");
-    res = -1;
-  }
-
-  return res;
-}
-
-
-static int frame_is_reference(const VP9_COMP *cpi) {
-  const VP9_COMMON *cm = &cpi->common;
-
-  return cm->frame_type == KEY_FRAME ||
-         cpi->refresh_last_frame ||
-         cpi->refresh_golden_frame ||
-         cpi->refresh_alt_ref_frame ||
-         cm->refresh_frame_context ||
-         cm->lf.mode_ref_delta_update ||
-         cm->seg.update_map ||
-         cm->seg.update_data;
-}
-
-static void adjust_frame_rate(VP9_COMP *cpi,
-                              const struct lookahead_entry *source) {
-  int64_t this_duration;
-  int step = 0;
-
-  if (source->ts_start == cpi->first_time_stamp_ever) {
-    this_duration = source->ts_end - source->ts_start;
-    step = 1;
-  } else {
-    int64_t last_duration = cpi->last_end_time_stamp_seen
-        - cpi->last_time_stamp_seen;
-
-    this_duration = source->ts_end - cpi->last_end_time_stamp_seen;
-
-    // do a step update if the duration changes by 10%
-    if (last_duration)
-      step = (int)((this_duration - last_duration) * 10 / last_duration);
-  }
-
-  if (this_duration) {
-    if (step) {
-      vp9_new_framerate(cpi, 10000000.0 / this_duration);
-    } else {
-      // Average this frame's rate into the last second's average
-      // frame rate. If we haven't seen 1 second yet, then average
-      // over the whole interval seen.
-      const double interval = VPXMIN(
-          (double)(source->ts_end - cpi->first_time_stamp_ever), 10000000.0);
-      double avg_duration = 10000000.0 / cpi->framerate;
-      avg_duration *= (interval - avg_duration + this_duration);
-      avg_duration /= interval;
-
-      vp9_new_framerate(cpi, 10000000.0 / avg_duration);
-    }
-  }
-  cpi->last_time_stamp_seen = source->ts_start;
-  cpi->last_end_time_stamp_seen = source->ts_end;
-}
-
-// Returns 0 if this is not an alt ref else the offset of the source frame
-// used as the arf midpoint.
-static int get_arf_src_index(VP9_COMP *cpi) {
-  RATE_CONTROL *const rc = &cpi->rc;
-  int arf_src_index = 0;
-  if (is_altref_enabled(cpi)) {
-    if (cpi->oxcf.pass == 2) {
-      const GF_GROUP *const gf_group = &cpi->twopass.gf_group;
-      if (gf_group->update_type[gf_group->index] == ARF_UPDATE) {
-        arf_src_index = gf_group->arf_src_offset[gf_group->index];
-      }
-    } else if (rc->source_alt_ref_pending) {
-      arf_src_index = rc->frames_till_gf_update_due;
-    }
-  }
-  return arf_src_index;
-}
-
-static void check_src_altref(VP9_COMP *cpi,
-                             const struct lookahead_entry *source) {
-  RATE_CONTROL *const rc = &cpi->rc;
-
-  if (cpi->oxcf.pass == 2) {
-    const GF_GROUP *const gf_group = &cpi->twopass.gf_group;
-    rc->is_src_frame_alt_ref =
-      (gf_group->update_type[gf_group->index] == OVERLAY_UPDATE);
-  } else {
-    rc->is_src_frame_alt_ref = cpi->alt_ref_source &&
-                               (source == cpi->alt_ref_source);
-  }
-
-  if (rc->is_src_frame_alt_ref) {
-    // Current frame is an ARF overlay frame.
-    cpi->alt_ref_source = NULL;
-
-    // Don't refresh the last buffer for an ARF overlay frame. It will
-    // become the GF so preserve last as an alternative prediction option.
-    cpi->refresh_last_frame = 0;
-  }
-}
-
-#if CONFIG_INTERNAL_STATS
-extern double vp9_get_blockiness(const uint8_t *img1, int img1_pitch,
-                                 const uint8_t *img2, int img2_pitch,
-                                 int width, int height);
-
-static void adjust_image_stat(double y, double u, double v, double all,
-                              ImageStat *s) {
-  s->stat[Y] += y;
-  s->stat[U] += u;
-  s->stat[V] += v;
-  s->stat[ALL] += all;
-  s->worst = VPXMIN(s->worst, all);
-}
-#endif  // CONFIG_INTERNAL_STATS
-
-static void update_level_info(VP9_COMP *cpi, size_t *size, int arf_src_index) {
-  VP9_COMMON *const cm = &cpi->common;
-  Vp9LevelInfo *const level_info = &cpi->level_info;
-  Vp9LevelSpec *const level_spec = &level_info->level_spec;
-  Vp9LevelStats *const level_stats = &level_info->level_stats;
-  int i, idx;
-  uint64_t luma_samples, dur_end;
-  const uint32_t luma_pic_size = cm->width * cm->height;
-  double cpb_data_size;
-
-  vpx_clear_system_state();
-
-  // update level_stats
-  level_stats->total_compressed_size += *size;
-  if (cm->show_frame) {
-    level_stats->total_uncompressed_size +=
-        luma_pic_size +
-        2 * (luma_pic_size >> (cm->subsampling_x + cm->subsampling_y));
-    level_stats->time_encoded =
-        (cpi->last_end_time_stamp_seen - cpi->first_time_stamp_ever) /
-        (double)TICKS_PER_SEC;
-  }
-
-  if (arf_src_index > 0) {
-    if (!level_stats->seen_first_altref) {
-      level_stats->seen_first_altref = 1;
-    } else if (level_stats->frames_since_last_altref <
-             level_spec->min_altref_distance) {
-      level_spec->min_altref_distance = level_stats->frames_since_last_altref;
-    }
-    level_stats->frames_since_last_altref = 0;
-  } else {
-    ++level_stats->frames_since_last_altref;
-  }
-
-  if (level_stats->frame_window_buffer.len < FRAME_WINDOW_SIZE - 1) {
-    idx = (level_stats->frame_window_buffer.start +
-           level_stats->frame_window_buffer.len++) % FRAME_WINDOW_SIZE;
-  } else {
-    idx = level_stats->frame_window_buffer.start;
-    level_stats->frame_window_buffer.start = (idx + 1) % FRAME_WINDOW_SIZE;
-  }
-  level_stats->frame_window_buffer.buf[idx].ts = cpi->last_time_stamp_seen;
-  level_stats->frame_window_buffer.buf[idx].size = (uint32_t)(*size);
-  level_stats->frame_window_buffer.buf[idx].luma_samples = luma_pic_size;
-
-  if (cm->frame_type == KEY_FRAME) {
-    level_stats->ref_refresh_map = 0;
-  } else {
-    int count = 0;
-    level_stats->ref_refresh_map |= vp9_get_refresh_mask(cpi);
-    // Also need to consider the case where the encoder refers to a buffer
-    // that has been implicitly refreshed after encoding a keyframe.
-    if (!cm->intra_only) {
-      level_stats->ref_refresh_map |= (1 << cpi->lst_fb_idx);
-      level_stats->ref_refresh_map |= (1 << cpi->gld_fb_idx);
-      level_stats->ref_refresh_map |= (1 << cpi->alt_fb_idx);
-    }
-    for (i = 0; i < REF_FRAMES; ++i) {
-      count += (level_stats->ref_refresh_map >> i) & 1;
-    }
-    if (count > level_spec->max_ref_frame_buffers) {
-      level_spec->max_ref_frame_buffers = count;
-    }
-  }
-
-  // update average_bitrate
-  level_spec->average_bitrate =
-      (double)level_stats->total_compressed_size / 125.0 /
-      level_stats->time_encoded;
-
-  // update max_luma_sample_rate
-  luma_samples = 0;
-  for (i = 0; i < level_stats->frame_window_buffer.len; ++i) {
-    idx = (level_stats->frame_window_buffer.start +
-           level_stats->frame_window_buffer.len - 1 - i) % FRAME_WINDOW_SIZE;
-    if (i == 0) {
-      dur_end = level_stats->frame_window_buffer.buf[idx].ts;
-    }
-    if (dur_end - level_stats->frame_window_buffer.buf[idx].ts >=
-        TICKS_PER_SEC) {
-      break;
-    }
-    luma_samples += level_stats->frame_window_buffer.buf[idx].luma_samples;
-  }
-  if (luma_samples > level_spec->max_luma_sample_rate) {
-    level_spec->max_luma_sample_rate = luma_samples;
-  }
-
-  // update max_cpb_size
-  cpb_data_size = 0;
-  for (i = 0; i < CPB_WINDOW_SIZE; ++i) {
-    if (i >= level_stats->frame_window_buffer.len) break;
-    idx = (level_stats->frame_window_buffer.start +
-           level_stats->frame_window_buffer.len - 1 - i) % FRAME_WINDOW_SIZE;
-    cpb_data_size += level_stats->frame_window_buffer.buf[idx].size;
-  }
-  cpb_data_size = cpb_data_size / 125.0;
-  if (cpb_data_size > level_spec->max_cpb_size) {
-    level_spec->max_cpb_size = cpb_data_size;
-  }
-
-  // update max_luma_picture_size
-  if (luma_pic_size > level_spec->max_luma_picture_size) {
-    level_spec->max_luma_picture_size = luma_pic_size;
-  }
-
-  // update compression_ratio
-  level_spec->compression_ratio =
-      (double)level_stats->total_uncompressed_size * cm->bit_depth /
-      level_stats->total_compressed_size / 8.0;
-
-  // update max_col_tiles
-  if (level_spec->max_col_tiles < (1 << cm->log2_tile_cols)) {
-    level_spec->max_col_tiles = (1 << cm->log2_tile_cols);
-  }
-}
-
-int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags,
-                            size_t *size, uint8_t *dest,
-                            int64_t *time_stamp, int64_t *time_end, int flush) {
-  const VP9EncoderConfig *const oxcf = &cpi->oxcf;
-  VP9_COMMON *const cm = &cpi->common;
-  BufferPool *const pool = cm->buffer_pool;
-  RATE_CONTROL *const rc = &cpi->rc;
-  struct vpx_usec_timer  cmptimer;
-  YV12_BUFFER_CONFIG *force_src_buffer = NULL;
-  struct lookahead_entry *last_source = NULL;
-  struct lookahead_entry *source = NULL;
-  int arf_src_index;
-  int i;
-
-  if (is_two_pass_svc(cpi)) {
-#if CONFIG_SPATIAL_SVC
-    vp9_svc_start_frame(cpi);
-    // Use a small empty frame instead of a real frame
-    if (cpi->svc.encode_empty_frame_state == ENCODING)
-      source = &cpi->svc.empty_frame;
-#endif
-    if (oxcf->pass == 2)
-      vp9_restore_layer_context(cpi);
-  } else if (is_one_pass_cbr_svc(cpi)) {
-    vp9_one_pass_cbr_svc_start_layer(cpi);
-  }
-
-  vpx_usec_timer_start(&cmptimer);
-
-  vp9_set_high_precision_mv(cpi, ALTREF_HIGH_PRECISION_MV);
-
-  // Is multi-arf enabled.
-  // Note that at the moment multi_arf is only configured for 2 pass VBR and
-  // will not work properly with svc.
-  if ((oxcf->pass == 2) && !cpi->use_svc &&
-      (cpi->oxcf.enable_auto_arf > 1))
-    cpi->multi_arf_allowed = 1;
-  else
-    cpi->multi_arf_allowed = 0;
-
-  // Normal defaults
-  cm->reset_frame_context = 0;
-  cm->refresh_frame_context = 1;
-  if (!is_one_pass_cbr_svc(cpi)) {
-    cpi->refresh_last_frame = 1;
-    cpi->refresh_golden_frame = 0;
-    cpi->refresh_alt_ref_frame = 0;
-  }
-
-  // Should we encode an arf frame.
-  arf_src_index = get_arf_src_index(cpi);
-
-  // Skip alt frame if we encode the empty frame
-  if (is_two_pass_svc(cpi) && source != NULL)
-    arf_src_index = 0;
-
-  if (arf_src_index) {
-    for (i = 0; i <= arf_src_index; ++i) {
-      struct lookahead_entry *e = vp9_lookahead_peek(cpi->lookahead, i);
-      // Avoid creating an alt-ref if there's a forced keyframe pending.
-      if (e == NULL) {
-        break;
-      } else if (e->flags == VPX_EFLAG_FORCE_KF) {
-        arf_src_index = 0;
-        flush = 1;
-        break;
-      }
-    }
-  }
-
-  if (arf_src_index) {
-    assert(arf_src_index <= rc->frames_to_key);
-
-    if ((source = vp9_lookahead_peek(cpi->lookahead, arf_src_index)) != NULL) {
-      cpi->alt_ref_source = source;
-
-#if CONFIG_SPATIAL_SVC
-      if (is_two_pass_svc(cpi) && cpi->svc.spatial_layer_id > 0) {
-        int i;
-        // Reference a hidden frame from a lower layer
-        for (i = cpi->svc.spatial_layer_id - 1; i >= 0; --i) {
-          if (oxcf->ss_enable_auto_arf[i]) {
-            cpi->gld_fb_idx = cpi->svc.layer_context[i].alt_ref_idx;
-            break;
-          }
-        }
-      }
-      cpi->svc.layer_context[cpi->svc.spatial_layer_id].has_alt_frame = 1;
-#endif
-
-      if ((oxcf->arnr_max_frames > 0) && (oxcf->arnr_strength > 0)) {
-        // Produce the filtered ARF frame.
-        vp9_temporal_filter(cpi, arf_src_index);
-        vpx_extend_frame_borders(&cpi->alt_ref_buffer);
-        force_src_buffer = &cpi->alt_ref_buffer;
-      }
-
-      cm->show_frame = 0;
-      cm->intra_only = 0;
-      cpi->refresh_alt_ref_frame = 1;
-      cpi->refresh_golden_frame = 0;
-      cpi->refresh_last_frame = 0;
-      rc->is_src_frame_alt_ref = 0;
-      rc->source_alt_ref_pending = 0;
-    } else {
-      rc->source_alt_ref_pending = 0;
-    }
-  }
-
-  if (!source) {
-    // Get last frame source.
-    if (cm->current_video_frame > 0) {
-      if ((last_source = vp9_lookahead_peek(cpi->lookahead, -1)) == NULL)
-        return -1;
-    }
-
-    // Read in the source frame.
-    if (cpi->use_svc)
-      source = vp9_svc_lookahead_pop(cpi, cpi->lookahead, flush);
-    else
-      source = vp9_lookahead_pop(cpi->lookahead, flush);
-
-    if (source != NULL) {
-      cm->show_frame = 1;
-      cm->intra_only = 0;
-      // if the flags indicate intra frame, but if the current picture is for
-      // non-zero spatial layer, it should not be an intra picture.
-      // TODO(Won Kap): this needs to change if per-layer intra frame is
-      // allowed.
-      if ((source->flags & VPX_EFLAG_FORCE_KF) &&
-          cpi->svc.spatial_layer_id > cpi->svc.first_spatial_layer_to_encode) {
-        source->flags &= ~(unsigned int)(VPX_EFLAG_FORCE_KF);
-      }
-
-      // Check to see if the frame should be encoded as an arf overlay.
-      check_src_altref(cpi, source);
-    }
-  }
-
-  if (source) {
-    cpi->un_scaled_source = cpi->Source = force_src_buffer ? force_src_buffer
-                                                           : &source->img;
-
-    cpi->unscaled_last_source = last_source != NULL ? &last_source->img : NULL;
-
-    *time_stamp = source->ts_start;
-    *time_end = source->ts_end;
-    *frame_flags = (source->flags & VPX_EFLAG_FORCE_KF) ? FRAMEFLAGS_KEY : 0;
-
-  } else {
-    *size = 0;
-    if (flush && oxcf->pass == 1 && !cpi->twopass.first_pass_done) {
-      vp9_end_first_pass(cpi);    /* get last stats packet */
-      cpi->twopass.first_pass_done = 1;
-    }
-    return -1;
-  }
-
-  if (source->ts_start < cpi->first_time_stamp_ever) {
-    cpi->first_time_stamp_ever = source->ts_start;
-    cpi->last_end_time_stamp_seen = source->ts_start;
-  }
-
-  // Clear down mmx registers
-  vpx_clear_system_state();
-
-  // adjust frame rates based on timestamps given
-  if (cm->show_frame) {
-    adjust_frame_rate(cpi, source);
-  }
-
-  if (is_one_pass_cbr_svc(cpi)) {
-    vp9_update_temporal_layer_framerate(cpi);
-    vp9_restore_layer_context(cpi);
-  }
-
-  // Find a free buffer for the new frame, releasing the reference previously
-  // held.
-  if (cm->new_fb_idx != INVALID_IDX) {
-    --pool->frame_bufs[cm->new_fb_idx].ref_count;
-  }
-  cm->new_fb_idx = get_free_fb(cm);
-
-  if (cm->new_fb_idx == INVALID_IDX)
-    return -1;
-
-  cm->cur_frame = &pool->frame_bufs[cm->new_fb_idx];
-
-  if (!cpi->use_svc && cpi->multi_arf_allowed) {
-    if (cm->frame_type == KEY_FRAME) {
-      init_buffer_indices(cpi);
-    } else if (oxcf->pass == 2) {
-      const GF_GROUP *const gf_group = &cpi->twopass.gf_group;
-      cpi->alt_fb_idx = gf_group->arf_ref_idx[gf_group->index];
-    }
-  }
-
-  // Start with a 0 size frame.
-  *size = 0;
-
-  cpi->frame_flags = *frame_flags;
-
-  if ((oxcf->pass == 2) &&
-      (!cpi->use_svc ||
-          (is_two_pass_svc(cpi) &&
-              cpi->svc.encode_empty_frame_state != ENCODING))) {
-    vp9_rc_get_second_pass_params(cpi);
-  } else if (oxcf->pass == 1) {
-    set_frame_size(cpi);
-  }
-
-  if (cpi->oxcf.pass != 0 ||
-      cpi->use_svc ||
-      frame_is_intra_only(cm) == 1) {
-    for (i = 0; i < MAX_REF_FRAMES; ++i)
-      cpi->scaled_ref_idx[i] = INVALID_IDX;
-  }
-
-  if (oxcf->pass == 1 &&
-      (!cpi->use_svc || is_two_pass_svc(cpi))) {
-    const int lossless = is_lossless_requested(oxcf);
-#if CONFIG_VP9_HIGHBITDEPTH
-    if (cpi->oxcf.use_highbitdepth)
-      cpi->td.mb.fwd_txm4x4 = lossless ?
-          vp9_highbd_fwht4x4 : vpx_highbd_fdct4x4;
-    else
-      cpi->td.mb.fwd_txm4x4 = lossless ? vp9_fwht4x4 : vpx_fdct4x4;
-    cpi->td.mb.highbd_itxm_add = lossless ? vp9_highbd_iwht4x4_add :
-                                         vp9_highbd_idct4x4_add;
-#else
-    cpi->td.mb.fwd_txm4x4 = lossless ? vp9_fwht4x4 : vpx_fdct4x4;
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-    cpi->td.mb.itxm_add = lossless ? vp9_iwht4x4_add : vp9_idct4x4_add;
-    vp9_first_pass(cpi, source);
-  } else if (oxcf->pass == 2 &&
-      (!cpi->use_svc || is_two_pass_svc(cpi))) {
-    Pass2Encode(cpi, size, dest, frame_flags);
-  } else if (cpi->use_svc) {
-    SvcEncode(cpi, size, dest, frame_flags);
-  } else {
-    // One pass encode
-    Pass0Encode(cpi, size, dest, frame_flags);
-  }
-
-  if (cm->refresh_frame_context)
-    cm->frame_contexts[cm->frame_context_idx] = *cm->fc;
-
-  // No frame encoded, or frame was dropped, release scaled references.
-  if ((*size == 0) && (frame_is_intra_only(cm) == 0)) {
-    release_scaled_references(cpi);
-  }
-
-  if (*size > 0) {
-    cpi->droppable = !frame_is_reference(cpi);
-  }
-
-  // Save layer specific state.
-  if (is_one_pass_cbr_svc(cpi) ||
-        ((cpi->svc.number_temporal_layers > 1 ||
-          cpi->svc.number_spatial_layers > 1) &&
-         oxcf->pass == 2)) {
-    vp9_save_layer_context(cpi);
-  }
-
-  vpx_usec_timer_mark(&cmptimer);
-  cpi->time_compress_data += vpx_usec_timer_elapsed(&cmptimer);
-
-  if (cpi->b_calculate_psnr && oxcf->pass != 1 && cm->show_frame)
-    generate_psnr_packet(cpi);
-
-  if (cpi->keep_level_stats && oxcf->pass != 1)
-    update_level_info(cpi, size, arf_src_index);
-
-#if CONFIG_INTERNAL_STATS
-
-  if (oxcf->pass != 1) {
-    double samples = 0.0;
-    cpi->bytes += (int)(*size);
-
-    if (cm->show_frame) {
-      uint32_t bit_depth = 8;
-      uint32_t in_bit_depth = 8;
-      cpi->count++;
-#if CONFIG_VP9_HIGHBITDEPTH
-    if (cm->use_highbitdepth) {
-      in_bit_depth = cpi->oxcf.input_bit_depth;
-      bit_depth = cm->bit_depth;
-    }
-#endif
-
-      if (cpi->b_calculate_psnr) {
-        YV12_BUFFER_CONFIG *orig = cpi->Source;
-        YV12_BUFFER_CONFIG *recon = cpi->common.frame_to_show;
-        YV12_BUFFER_CONFIG *pp = &cm->post_proc_buffer;
-        PSNR_STATS psnr;
-#if CONFIG_VP9_HIGHBITDEPTH
-        vpx_calc_highbd_psnr(orig, recon, &psnr, cpi->td.mb.e_mbd.bd,
-                             in_bit_depth);
-#else
-        vpx_calc_psnr(orig, recon, &psnr);
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-
-        adjust_image_stat(psnr.psnr[1], psnr.psnr[2], psnr.psnr[3],
-                          psnr.psnr[0], &cpi->psnr);
-        cpi->total_sq_error += psnr.sse[0];
-        cpi->total_samples += psnr.samples[0];
-        samples = psnr.samples[0];
-
-        {
-          PSNR_STATS psnr2;
-          double frame_ssim2 = 0, weight = 0;
-#if CONFIG_VP9_POSTPROC
-          if (vpx_alloc_frame_buffer(pp,
-                                     recon->y_crop_width, recon->y_crop_height,
-                                     cm->subsampling_x, cm->subsampling_y,
-#if CONFIG_VP9_HIGHBITDEPTH
-                                     cm->use_highbitdepth,
-#endif
-                                     VP9_ENC_BORDER_IN_PIXELS,
-                                     cm->byte_alignment) < 0) {
-            vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR,
-                               "Failed to allocate post processing buffer");
-          }
-
-          vp9_deblock(cm->frame_to_show, pp,
-                      cm->lf.filter_level * 10 / 6, cm->postproc_state.limits);
-#endif
-          vpx_clear_system_state();
-
-#if CONFIG_VP9_HIGHBITDEPTH
-          vpx_calc_highbd_psnr(orig, pp, &psnr2, cpi->td.mb.e_mbd.bd,
-                           cpi->oxcf.input_bit_depth);
-#else
-          vpx_calc_psnr(orig, pp, &psnr2);
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-
-          cpi->totalp_sq_error += psnr2.sse[0];
-          cpi->totalp_samples += psnr2.samples[0];
-          adjust_image_stat(psnr2.psnr[1], psnr2.psnr[2], psnr2.psnr[3],
-                            psnr2.psnr[0], &cpi->psnrp);
-
-#if CONFIG_VP9_HIGHBITDEPTH
-          if (cm->use_highbitdepth) {
-            frame_ssim2 = vpx_highbd_calc_ssim(orig, recon, &weight,
-                                               bit_depth, in_bit_depth);
-          } else {
-            frame_ssim2 = vpx_calc_ssim(orig, recon, &weight);
-          }
-#else
-          frame_ssim2 = vpx_calc_ssim(orig, recon, &weight);
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-
-          cpi->worst_ssim = VPXMIN(cpi->worst_ssim, frame_ssim2);
-          cpi->summed_quality += frame_ssim2 * weight;
-          cpi->summed_weights += weight;
-
-#if CONFIG_VP9_HIGHBITDEPTH
-          if (cm->use_highbitdepth) {
-            frame_ssim2 = vpx_highbd_calc_ssim(
-                orig, pp, &weight, bit_depth, in_bit_depth);
-          } else {
-            frame_ssim2 = vpx_calc_ssim(orig, pp, &weight);
-          }
-#else
-          frame_ssim2 = vpx_calc_ssim(orig, pp, &weight);
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-
-          cpi->summedp_quality += frame_ssim2 * weight;
-          cpi->summedp_weights += weight;
-#if 0
-          {
-            FILE *f = fopen("q_used.stt", "a");
-            fprintf(f, "%5d : Y%f7.3:U%f7.3:V%f7.3:F%f7.3:S%7.3f\n",
-                    cpi->common.current_video_frame, y2, u2, v2,
-                    frame_psnr2, frame_ssim2);
-            fclose(f);
-          }
-#endif
-        }
-      }
-      if (cpi->b_calculate_blockiness) {
-#if CONFIG_VP9_HIGHBITDEPTH
-        if (!cm->use_highbitdepth)
-#endif
-        {
-          double frame_blockiness = vp9_get_blockiness(
-              cpi->Source->y_buffer, cpi->Source->y_stride,
-              cm->frame_to_show->y_buffer, cm->frame_to_show->y_stride,
-              cpi->Source->y_width, cpi->Source->y_height);
-          cpi->worst_blockiness =
-              VPXMAX(cpi->worst_blockiness, frame_blockiness);
-          cpi->total_blockiness += frame_blockiness;
-        }
-      }
-
-      if (cpi->b_calculate_consistency) {
-#if CONFIG_VP9_HIGHBITDEPTH
-        if (!cm->use_highbitdepth)
-#endif
-        {
-          double this_inconsistency = vpx_get_ssim_metrics(
-              cpi->Source->y_buffer, cpi->Source->y_stride,
-              cm->frame_to_show->y_buffer, cm->frame_to_show->y_stride,
-              cpi->Source->y_width, cpi->Source->y_height, cpi->ssim_vars,
-              &cpi->metrics, 1);
-
-          const double peak = (double)((1 << cpi->oxcf.input_bit_depth) - 1);
-          double consistency = vpx_sse_to_psnr(samples, peak,
-                                             (double)cpi->total_inconsistency);
-          if (consistency > 0.0)
-            cpi->worst_consistency =
-                VPXMIN(cpi->worst_consistency, consistency);
-          cpi->total_inconsistency += this_inconsistency;
-        }
-      }
-
-      {
-        double y, u, v, frame_all;
-        frame_all = vpx_calc_fastssim(cpi->Source, cm->frame_to_show, &y, &u,
-                                      &v, bit_depth, in_bit_depth);
-        adjust_image_stat(y, u, v, frame_all, &cpi->fastssim);
-      }
-      {
-        double y, u, v, frame_all;
-        frame_all = vpx_psnrhvs(cpi->Source, cm->frame_to_show, &y, &u, &v,
-                                bit_depth, in_bit_depth);
-        adjust_image_stat(y, u, v, frame_all, &cpi->psnrhvs);
-      }
-    }
-  }
-
-#endif
-
-  if (is_two_pass_svc(cpi)) {
-    if (cpi->svc.encode_empty_frame_state == ENCODING) {
-      cpi->svc.encode_empty_frame_state = ENCODED;
-      cpi->svc.encode_intra_empty_frame = 0;
-    }
-
-    if (cm->show_frame) {
-      ++cpi->svc.spatial_layer_to_encode;
-      if (cpi->svc.spatial_layer_to_encode >= cpi->svc.number_spatial_layers)
-        cpi->svc.spatial_layer_to_encode = 0;
-
-      // May need the empty frame after an visible frame.
-      cpi->svc.encode_empty_frame_state = NEED_TO_ENCODE;
-    }
-  } else if (is_one_pass_cbr_svc(cpi)) {
-    if (cm->show_frame) {
-      ++cpi->svc.spatial_layer_to_encode;
-      if (cpi->svc.spatial_layer_to_encode >= cpi->svc.number_spatial_layers)
-        cpi->svc.spatial_layer_to_encode = 0;
-    }
-  }
-  vpx_clear_system_state();
-  return 0;
-}
-
-int vp9_get_preview_raw_frame(VP9_COMP *cpi, YV12_BUFFER_CONFIG *dest,
-                              vp9_ppflags_t *flags) {
-  VP9_COMMON *cm = &cpi->common;
-#if !CONFIG_VP9_POSTPROC
-  (void)flags;
-#endif
-
-  if (!cm->show_frame) {
-    return -1;
-  } else {
-    int ret;
-#if CONFIG_VP9_POSTPROC
-    ret = vp9_post_proc_frame(cm, dest, flags);
-#else
-    if (cm->frame_to_show) {
-      *dest = *cm->frame_to_show;
-      dest->y_width = cm->width;
-      dest->y_height = cm->height;
-      dest->uv_width = cm->width >> cm->subsampling_x;
-      dest->uv_height = cm->height >> cm->subsampling_y;
-      ret = 0;
-    } else {
-      ret = -1;
-    }
-#endif  // !CONFIG_VP9_POSTPROC
-    vpx_clear_system_state();
-    return ret;
-  }
-}
-
-int vp9_set_internal_size(VP9_COMP *cpi,
-                          VPX_SCALING horiz_mode, VPX_SCALING vert_mode) {
-  VP9_COMMON *cm = &cpi->common;
-  int hr = 0, hs = 0, vr = 0, vs = 0;
-
-  if (horiz_mode > ONETWO || vert_mode > ONETWO)
-    return -1;
-
-  Scale2Ratio(horiz_mode, &hr, &hs);
-  Scale2Ratio(vert_mode, &vr, &vs);
-
-  // always go to the next whole number
-  cm->width = (hs - 1 + cpi->oxcf.width * hr) / hs;
-  cm->height = (vs - 1 + cpi->oxcf.height * vr) / vs;
-  if (cm->current_video_frame) {
-    assert(cm->width <= cpi->initial_width);
-    assert(cm->height <= cpi->initial_height);
-  }
-
-  update_frame_size(cpi);
-
-  return 0;
-}
-
-int vp9_set_size_literal(VP9_COMP *cpi, unsigned int width,
-                         unsigned int height) {
-  VP9_COMMON *cm = &cpi->common;
-#if CONFIG_VP9_HIGHBITDEPTH
-  check_initial_width(cpi, cm->use_highbitdepth, 1, 1);
-#else
-  check_initial_width(cpi, 1, 1);
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-
-#if CONFIG_VP9_TEMPORAL_DENOISING
-  setup_denoiser_buffer(cpi);
-#endif
-
-  if (width) {
-    cm->width = width;
-    if (cm->width > cpi->initial_width) {
-      cm->width = cpi->initial_width;
-      printf("Warning: Desired width too large, changed to %d\n", cm->width);
-    }
-  }
-
-  if (height) {
-    cm->height = height;
-    if (cm->height > cpi->initial_height) {
-      cm->height = cpi->initial_height;
-      printf("Warning: Desired height too large, changed to %d\n", cm->height);
-    }
-  }
-  assert(cm->width <= cpi->initial_width);
-  assert(cm->height <= cpi->initial_height);
-
-  update_frame_size(cpi);
-
-  return 0;
-}
-
-void vp9_set_svc(VP9_COMP *cpi, int use_svc) {
-  cpi->use_svc = use_svc;
-  return;
-}
-
-int vp9_get_quantizer(VP9_COMP *cpi) {
-  return cpi->common.base_qindex;
-}
-
-void vp9_apply_encoding_flags(VP9_COMP *cpi, vpx_enc_frame_flags_t flags) {
-  if (flags & (VP8_EFLAG_NO_REF_LAST | VP8_EFLAG_NO_REF_GF |
-               VP8_EFLAG_NO_REF_ARF)) {
-    int ref = 7;
-
-    if (flags & VP8_EFLAG_NO_REF_LAST)
-      ref ^= VP9_LAST_FLAG;
-
-    if (flags & VP8_EFLAG_NO_REF_GF)
-      ref ^= VP9_GOLD_FLAG;
-
-    if (flags & VP8_EFLAG_NO_REF_ARF)
-      ref ^= VP9_ALT_FLAG;
-
-    vp9_use_as_reference(cpi, ref);
-  }
-
-  if (flags & (VP8_EFLAG_NO_UPD_LAST | VP8_EFLAG_NO_UPD_GF |
-               VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_FORCE_GF |
-               VP8_EFLAG_FORCE_ARF)) {
-    int upd = 7;
-
-    if (flags & VP8_EFLAG_NO_UPD_LAST)
-      upd ^= VP9_LAST_FLAG;
-
-    if (flags & VP8_EFLAG_NO_UPD_GF)
-      upd ^= VP9_GOLD_FLAG;
-
-    if (flags & VP8_EFLAG_NO_UPD_ARF)
-      upd ^= VP9_ALT_FLAG;
-
-    vp9_update_reference(cpi, upd);
-  }
-
-  if (flags & VP8_EFLAG_NO_UPD_ENTROPY) {
-    vp9_update_entropy(cpi, 0);
-  }
-}
diff --git a/vp9/encoder/vp9_encoder.h b/vp9/encoder/vp9_encoder.h
deleted file mode 100644 (file)
index 9a8b15a..0000000
+++ /dev/null
@@ -1,748 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#ifndef VP9_ENCODER_VP9_ENCODER_H_
-#define VP9_ENCODER_VP9_ENCODER_H_
-
-#include <stdio.h>
-
-#include "./vpx_config.h"
-#include "vpx/internal/vpx_codec_internal.h"
-#include "vpx/vp8cx.h"
-#if CONFIG_INTERNAL_STATS
-#include "vpx_dsp/ssim.h"
-#endif
-#include "vpx_dsp/variance.h"
-#include "vpx_ports/system_state.h"
-#include "vpx_util/vpx_thread.h"
-
-#include "vp9/common/vp9_alloccommon.h"
-#include "vp9/common/vp9_ppflags.h"
-#include "vp9/common/vp9_entropymode.h"
-#include "vp9/common/vp9_thread_common.h"
-#include "vp9/common/vp9_onyxc_int.h"
-
-#include "vp9/encoder/vp9_aq_cyclicrefresh.h"
-#include "vp9/encoder/vp9_context_tree.h"
-#include "vp9/encoder/vp9_encodemb.h"
-#include "vp9/encoder/vp9_firstpass.h"
-#include "vp9/encoder/vp9_lookahead.h"
-#include "vp9/encoder/vp9_mbgraph.h"
-#include "vp9/encoder/vp9_mcomp.h"
-#include "vp9/encoder/vp9_noise_estimate.h"
-#include "vp9/encoder/vp9_quantize.h"
-#include "vp9/encoder/vp9_ratectrl.h"
-#include "vp9/encoder/vp9_rd.h"
-#include "vp9/encoder/vp9_speed_features.h"
-#include "vp9/encoder/vp9_svc_layercontext.h"
-#include "vp9/encoder/vp9_tokenize.h"
-
-#if CONFIG_VP9_TEMPORAL_DENOISING
-#include "vp9/encoder/vp9_denoiser.h"
-#endif
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-// vp9 uses 10,000,000 ticks/second as time stamp
-#define TICKS_PER_SEC 10000000
-
-typedef struct {
-  int nmvjointcost[MV_JOINTS];
-  int nmvcosts[2][MV_VALS];
-  int nmvcosts_hp[2][MV_VALS];
-
-  vpx_prob segment_pred_probs[PREDICTION_PROBS];
-
-  unsigned char *last_frame_seg_map_copy;
-
-  // 0 = Intra, Last, GF, ARF
-  signed char last_ref_lf_deltas[MAX_REF_LF_DELTAS];
-  // 0 = ZERO_MV, MV
-  signed char last_mode_lf_deltas[MAX_MODE_LF_DELTAS];
-
-  FRAME_CONTEXT fc;
-} CODING_CONTEXT;
-
-
-typedef enum {
-  // encode_breakout is disabled.
-  ENCODE_BREAKOUT_DISABLED = 0,
-  // encode_breakout is enabled.
-  ENCODE_BREAKOUT_ENABLED = 1,
-  // encode_breakout is enabled with small max_thresh limit.
-  ENCODE_BREAKOUT_LIMITED = 2
-} ENCODE_BREAKOUT_TYPE;
-
-typedef enum {
-  NORMAL      = 0,
-  FOURFIVE    = 1,
-  THREEFIVE   = 2,
-  ONETWO      = 3
-} VPX_SCALING;
-
-typedef enum {
-  // Good Quality Fast Encoding. The encoder balances quality with the amount of
-  // time it takes to encode the output. Speed setting controls how fast.
-  GOOD,
-
-  // The encoder places priority on the quality of the output over encoding
-  // speed. The output is compressed at the highest possible quality. This
-  // option takes the longest amount of time to encode. Speed setting ignored.
-  BEST,
-
-  // Realtime/Live Encoding. This mode is optimized for realtime encoding (for
-  // example, capturing a television signal or feed from a live camera). Speed
-  // setting controls how fast.
-  REALTIME
-} MODE;
-
-typedef enum {
-  FRAMEFLAGS_KEY    = 1 << 0,
-  FRAMEFLAGS_GOLDEN = 1 << 1,
-  FRAMEFLAGS_ALTREF = 1 << 2,
-} FRAMETYPE_FLAGS;
-
-typedef enum {
-  NO_AQ = 0,
-  VARIANCE_AQ = 1,
-  COMPLEXITY_AQ = 2,
-  CYCLIC_REFRESH_AQ = 3,
-  EQUATOR360_AQ = 4,
-  AQ_MODE_COUNT  // This should always be the last member of the enum
-} AQ_MODE;
-
-typedef enum {
-  RESIZE_NONE = 0,    // No frame resizing allowed (except for SVC).
-  RESIZE_FIXED = 1,   // All frames are coded at the specified dimension.
-  RESIZE_DYNAMIC = 2  // Coded size of each frame is determined by the codec.
-} RESIZE_TYPE;
-
-typedef struct VP9EncoderConfig {
-  BITSTREAM_PROFILE profile;
-  vpx_bit_depth_t bit_depth;     // Codec bit-depth.
-  int width;  // width of data passed to the compressor
-  int height;  // height of data passed to the compressor
-  unsigned int input_bit_depth;  // Input bit depth.
-  double init_framerate;  // set to passed in framerate
-  int64_t target_bandwidth;  // bandwidth to be used in bits per second
-
-  int noise_sensitivity;  // pre processing blur: recommendation 0
-  int sharpness;  // sharpening output: recommendation 0:
-  int speed;
-  // maximum allowed bitrate for any intra frame in % of bitrate target.
-  unsigned int rc_max_intra_bitrate_pct;
-  // maximum allowed bitrate for any inter frame in % of bitrate target.
-  unsigned int rc_max_inter_bitrate_pct;
-  // percent of rate boost for golden frame in CBR mode.
-  unsigned int gf_cbr_boost_pct;
-
-  MODE mode;
-  int pass;
-
-  // Key Framing Operations
-  int auto_key;  // autodetect cut scenes and set the keyframes
-  int key_freq;  // maximum distance to key frame.
-
-  int lag_in_frames;  // how many frames lag before we start encoding
-
-  // ----------------------------------------------------------------
-  // DATARATE CONTROL OPTIONS
-
-  // vbr, cbr, constrained quality or constant quality
-  enum vpx_rc_mode rc_mode;
-
-  // buffer targeting aggressiveness
-  int under_shoot_pct;
-  int over_shoot_pct;
-
-  // buffering parameters
-  int64_t starting_buffer_level_ms;
-  int64_t optimal_buffer_level_ms;
-  int64_t maximum_buffer_size_ms;
-
-  // Frame drop threshold.
-  int drop_frames_water_mark;
-
-  // controlling quality
-  int fixed_q;
-  int worst_allowed_q;
-  int best_allowed_q;
-  int cq_level;
-  AQ_MODE aq_mode;  // Adaptive Quantization mode
-
-  // Internal frame size scaling.
-  RESIZE_TYPE resize_mode;
-  int scaled_frame_width;
-  int scaled_frame_height;
-
-  // Enable feature to reduce the frame quantization every x frames.
-  int frame_periodic_boost;
-
-  // two pass datarate control
-  int two_pass_vbrbias;        // two pass datarate control tweaks
-  int two_pass_vbrmin_section;
-  int two_pass_vbrmax_section;
-  // END DATARATE CONTROL OPTIONS
-  // ----------------------------------------------------------------
-
-  // Spatial and temporal scalability.
-  int ss_number_layers;  // Number of spatial layers.
-  int ts_number_layers;  // Number of temporal layers.
-  // Bitrate allocation for spatial layers.
-  int layer_target_bitrate[VPX_MAX_LAYERS];
-  int ss_target_bitrate[VPX_SS_MAX_LAYERS];
-  int ss_enable_auto_arf[VPX_SS_MAX_LAYERS];
-  // Bitrate allocation (CBR mode) and framerate factor, for temporal layers.
-  int ts_rate_decimator[VPX_TS_MAX_LAYERS];
-
-  int enable_auto_arf;
-
-  int encode_breakout;  // early breakout : for video conf recommend 800
-
-  /* Bitfield defining the error resiliency features to enable.
-   * Can provide decodable frames after losses in previous
-   * frames and decodable partitions after losses in the same frame.
-   */
-  unsigned int error_resilient_mode;
-
-  /* Bitfield defining the parallel decoding mode where the
-   * decoding in successive frames may be conducted in parallel
-   * just by decoding the frame headers.
-   */
-  unsigned int frame_parallel_decoding_mode;
-
-  int arnr_max_frames;
-  int arnr_strength;
-
-  int min_gf_interval;
-  int max_gf_interval;
-
-  int tile_columns;
-  int tile_rows;
-
-  int max_threads;
-
-  int target_level;
-
-  vpx_fixed_buf_t two_pass_stats_in;
-  struct vpx_codec_pkt_list *output_pkt_list;
-
-#if CONFIG_FP_MB_STATS
-  vpx_fixed_buf_t firstpass_mb_stats_in;
-#endif
-
-  vp8e_tuning tuning;
-  vp9e_tune_content content;
-#if CONFIG_VP9_HIGHBITDEPTH
-  int use_highbitdepth;
-#endif
-  vpx_color_space_t color_space;
-  vpx_color_range_t color_range;
-  int render_width;
-  int render_height;
-  VP9E_TEMPORAL_LAYERING_MODE temporal_layering_mode;
-} VP9EncoderConfig;
-
-static INLINE int is_lossless_requested(const VP9EncoderConfig *cfg) {
-  return cfg->best_allowed_q == 0 && cfg->worst_allowed_q == 0;
-}
-
-// TODO(jingning) All spatially adaptive variables should go to TileDataEnc.
-typedef struct TileDataEnc {
-  TileInfo tile_info;
-  int thresh_freq_fact[BLOCK_SIZES][MAX_MODES];
-  int mode_map[BLOCK_SIZES][MAX_MODES];
-} TileDataEnc;
-
-typedef struct RD_COUNTS {
-  vp9_coeff_count coef_counts[TX_SIZES][PLANE_TYPES];
-  int64_t comp_pred_diff[REFERENCE_MODES];
-  int64_t filter_diff[SWITCHABLE_FILTER_CONTEXTS];
-  int m_search_count;
-  int ex_search_count;
-} RD_COUNTS;
-
-typedef struct ThreadData {
-  MACROBLOCK mb;
-  RD_COUNTS rd_counts;
-  FRAME_COUNTS *counts;
-
-  PICK_MODE_CONTEXT *leaf_tree;
-  PC_TREE *pc_tree;
-  PC_TREE *pc_root;
-} ThreadData;
-
-struct EncWorkerData;
-
-typedef struct ActiveMap {
-  int enabled;
-  int update;
-  unsigned char *map;
-} ActiveMap;
-
-typedef enum {
-  Y,
-  U,
-  V,
-  ALL
-} STAT_TYPE;
-
-typedef struct IMAGE_STAT {
-  double stat[ALL+1];
-  double worst;
-} ImageStat;
-
-#define CPB_WINDOW_SIZE 4
-#define FRAME_WINDOW_SIZE 128
-#define SAMPLE_RATE_GRACE_P 0.015
-#define VP9_LEVELS 14
-
-typedef enum {
-  LEVEL_UNKNOWN = 0,
-  LEVEL_1 = 10,
-  LEVEL_1_1 = 11,
-  LEVEL_2 = 20,
-  LEVEL_2_1 = 21,
-  LEVEL_3 = 30,
-  LEVEL_3_1 = 31,
-  LEVEL_4 = 40,
-  LEVEL_4_1 = 41,
-  LEVEL_5 = 50,
-  LEVEL_5_1 = 51,
-  LEVEL_5_2 = 52,
-  LEVEL_6 = 60,
-  LEVEL_6_1 = 61,
-  LEVEL_6_2 = 62,
-  LEVEL_MAX = 255
-} VP9_LEVEL;
-
-typedef struct {
-  VP9_LEVEL level;
-  uint64_t max_luma_sample_rate;
-  uint32_t max_luma_picture_size;
-  double average_bitrate;  // in kilobits per second
-  double max_cpb_size;  // in kilobits
-  double compression_ratio;
-  uint8_t max_col_tiles;
-  uint32_t min_altref_distance;
-  uint8_t max_ref_frame_buffers;
-} Vp9LevelSpec;
-
-typedef struct {
-  int64_t ts;  // timestamp
-  uint32_t luma_samples;
-  uint32_t size;  // in bytes
-} FrameRecord;
-
-typedef struct {
-  FrameRecord buf[FRAME_WINDOW_SIZE];
-  uint8_t start;
-  uint8_t len;
-} FrameWindowBuffer;
-
-typedef struct {
-  uint8_t seen_first_altref;
-  uint32_t frames_since_last_altref;
-  uint64_t total_compressed_size;
-  uint64_t total_uncompressed_size;
-  double time_encoded;  // in seconds
-  FrameWindowBuffer frame_window_buffer;
-  int ref_refresh_map;
-} Vp9LevelStats;
-
-typedef struct {
-  Vp9LevelStats level_stats;
-  Vp9LevelSpec level_spec;
-} Vp9LevelInfo;
-
-typedef struct VP9_COMP {
-  QUANTS quants;
-  ThreadData td;
-  MB_MODE_INFO_EXT *mbmi_ext_base;
-  DECLARE_ALIGNED(16, int16_t, y_dequant[QINDEX_RANGE][8]);
-  DECLARE_ALIGNED(16, int16_t, uv_dequant[QINDEX_RANGE][8]);
-  VP9_COMMON common;
-  VP9EncoderConfig oxcf;
-  struct lookahead_ctx    *lookahead;
-  struct lookahead_entry  *alt_ref_source;
-
-  YV12_BUFFER_CONFIG *Source;
-  YV12_BUFFER_CONFIG *Last_Source;  // NULL for first frame and alt_ref frames
-  YV12_BUFFER_CONFIG *un_scaled_source;
-  YV12_BUFFER_CONFIG scaled_source;
-  YV12_BUFFER_CONFIG *unscaled_last_source;
-  YV12_BUFFER_CONFIG scaled_last_source;
-
-  TileDataEnc *tile_data;
-  int allocated_tiles;  // Keep track of memory allocated for tiles.
-
-  // For a still frame, this flag is set to 1 to skip partition search.
-  int partition_search_skippable_frame;
-
-  int scaled_ref_idx[MAX_REF_FRAMES];
-  int lst_fb_idx;
-  int gld_fb_idx;
-  int alt_fb_idx;
-
-  int refresh_last_frame;
-  int refresh_golden_frame;
-  int refresh_alt_ref_frame;
-
-  int ext_refresh_frame_flags_pending;
-  int ext_refresh_last_frame;
-  int ext_refresh_golden_frame;
-  int ext_refresh_alt_ref_frame;
-
-  int ext_refresh_frame_context_pending;
-  int ext_refresh_frame_context;
-
-  YV12_BUFFER_CONFIG last_frame_uf;
-
-  TOKENEXTRA *tile_tok[4][1 << 6];
-  unsigned int tok_count[4][1 << 6];
-
-  // Ambient reconstruction err target for force key frames
-  int64_t ambient_err;
-
-  RD_OPT rd;
-
-  CODING_CONTEXT coding_context;
-
-  int *nmvcosts[2];
-  int *nmvcosts_hp[2];
-  int *nmvsadcosts[2];
-  int *nmvsadcosts_hp[2];
-
-  int64_t last_time_stamp_seen;
-  int64_t last_end_time_stamp_seen;
-  int64_t first_time_stamp_ever;
-
-  RATE_CONTROL rc;
-  double framerate;
-
-  int interp_filter_selected[MAX_REF_FRAMES][SWITCHABLE];
-
-  struct vpx_codec_pkt_list  *output_pkt_list;
-
-  MBGRAPH_FRAME_STATS mbgraph_stats[MAX_LAG_BUFFERS];
-  int mbgraph_n_frames;             // number of frames filled in the above
-  int static_mb_pct;                // % forced skip mbs by segmentation
-  int ref_frame_flags;
-
-  SPEED_FEATURES sf;
-
-  unsigned int max_mv_magnitude;
-  int mv_step_param;
-
-  int allow_comp_inter_inter;
-
-  // Default value is 1. From first pass stats, encode_breakout may be disabled.
-  ENCODE_BREAKOUT_TYPE allow_encode_breakout;
-
-  // Get threshold from external input. A suggested threshold is 800 for HD
-  // clips, and 300 for < HD clips.
-  int encode_breakout;
-
-  unsigned char *segmentation_map;
-
-  // segment threashold for encode breakout
-  int  segment_encode_breakout[MAX_SEGMENTS];
-
-  CYCLIC_REFRESH *cyclic_refresh;
-  ActiveMap active_map;
-
-  fractional_mv_step_fp *find_fractional_mv_step;
-  vp9_full_search_fn_t full_search_sad;
-  vp9_diamond_search_fn_t diamond_search_sad;
-  vp9_variance_fn_ptr_t fn_ptr[BLOCK_SIZES];
-  uint64_t time_receive_data;
-  uint64_t time_compress_data;
-  uint64_t time_pick_lpf;
-  uint64_t time_encode_sb_row;
-
-#if CONFIG_FP_MB_STATS
-  int use_fp_mb_stats;
-#endif
-
-  TWO_PASS twopass;
-
-  YV12_BUFFER_CONFIG alt_ref_buffer;
-
-
-#if CONFIG_INTERNAL_STATS
-  unsigned int mode_chosen_counts[MAX_MODES];
-
-  int    count;
-  uint64_t total_sq_error;
-  uint64_t total_samples;
-  ImageStat psnr;
-
-  uint64_t totalp_sq_error;
-  uint64_t totalp_samples;
-  ImageStat psnrp;
-
-  double total_blockiness;
-  double worst_blockiness;
-
-  int    bytes;
-  double summed_quality;
-  double summed_weights;
-  double summedp_quality;
-  double summedp_weights;
-  unsigned int tot_recode_hits;
-  double worst_ssim;
-
-  ImageStat fastssim;
-  ImageStat psnrhvs;
-
-  int b_calculate_blockiness;
-  int b_calculate_consistency;
-
-  double total_inconsistency;
-  double worst_consistency;
-  Ssimv *ssim_vars;
-  Metrics metrics;
-#endif
-  int b_calculate_psnr;
-
-  int droppable;
-
-  int initial_width;
-  int initial_height;
-  int initial_mbs;  // Number of MBs in the full-size frame; to be used to
-                    // normalize the firstpass stats. This will differ from the
-                    // number of MBs in the current frame when the frame is
-                    // scaled.
-
-  int use_svc;
-
-  SVC svc;
-
-  // Store frame variance info in SOURCE_VAR_BASED_PARTITION search type.
-  diff *source_diff_var;
-  // The threshold used in SOURCE_VAR_BASED_PARTITION search type.
-  unsigned int source_var_thresh;
-  int frames_till_next_var_check;
-
-  int frame_flags;
-
-  search_site_config ss_cfg;
-
-  int mbmode_cost[INTRA_MODES];
-  unsigned int inter_mode_cost[INTER_MODE_CONTEXTS][INTER_MODES];
-  int intra_uv_mode_cost[FRAME_TYPES][INTRA_MODES][INTRA_MODES];
-  int y_mode_costs[INTRA_MODES][INTRA_MODES][INTRA_MODES];
-  int switchable_interp_costs[SWITCHABLE_FILTER_CONTEXTS][SWITCHABLE_FILTERS];
-  int partition_cost[PARTITION_CONTEXTS][PARTITION_TYPES];
-
-  int multi_arf_allowed;
-  int multi_arf_enabled;
-  int multi_arf_last_grp_enabled;
-
-#if CONFIG_VP9_TEMPORAL_DENOISING
-  VP9_DENOISER denoiser;
-#endif
-
-  int resize_pending;
-  int resize_state;
-  int external_resize;
-  int resize_scale_num;
-  int resize_scale_den;
-  int resize_avg_qp;
-  int resize_buffer_underflow;
-  int resize_count;
-
-  int use_skin_detection;
-
-  int target_level;
-
-  NOISE_ESTIMATE noise_estimate;
-
-  // Count on how many consecutive times a block uses small/zeromv for encoding.
-  uint8_t *consec_zero_mv;
-
-  // VAR_BASED_PARTITION thresholds
-  // 0 - threshold_64x64; 1 - threshold_32x32;
-  // 2 - threshold_16x16; 3 - vbp_threshold_8x8;
-  int64_t vbp_thresholds[4];
-  int64_t vbp_threshold_minmax;
-  int64_t vbp_threshold_sad;
-  BLOCK_SIZE vbp_bsize_min;
-
-  // Multi-threading
-  int num_workers;
-  VPxWorker *workers;
-  struct EncWorkerData *tile_thr_data;
-  VP9LfSync lf_row_sync;
-
-  int keep_level_stats;
-  Vp9LevelInfo level_info;
-} VP9_COMP;
-
-void vp9_initialize_enc(void);
-
-struct VP9_COMP *vp9_create_compressor(VP9EncoderConfig *oxcf,
-                                       BufferPool *const pool);
-void vp9_remove_compressor(VP9_COMP *cpi);
-
-void vp9_change_config(VP9_COMP *cpi, const VP9EncoderConfig *oxcf);
-
-  // receive a frames worth of data. caller can assume that a copy of this
-  // frame is made and not just a copy of the pointer..
-int vp9_receive_raw_frame(VP9_COMP *cpi, unsigned int frame_flags,
-                          YV12_BUFFER_CONFIG *sd, int64_t time_stamp,
-                          int64_t end_time_stamp);
-
-int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags,
-                            size_t *size, uint8_t *dest,
-                            int64_t *time_stamp, int64_t *time_end, int flush);
-
-int vp9_get_preview_raw_frame(VP9_COMP *cpi, YV12_BUFFER_CONFIG *dest,
-                              vp9_ppflags_t *flags);
-
-int vp9_use_as_reference(VP9_COMP *cpi, int ref_frame_flags);
-
-void vp9_update_reference(VP9_COMP *cpi, int ref_frame_flags);
-
-int vp9_copy_reference_enc(VP9_COMP *cpi, VP9_REFFRAME ref_frame_flag,
-                           YV12_BUFFER_CONFIG *sd);
-
-int vp9_set_reference_enc(VP9_COMP *cpi, VP9_REFFRAME ref_frame_flag,
-                          YV12_BUFFER_CONFIG *sd);
-
-int vp9_update_entropy(VP9_COMP *cpi, int update);
-
-int vp9_set_active_map(VP9_COMP *cpi, unsigned char *map, int rows, int cols);
-
-int vp9_get_active_map(VP9_COMP *cpi, unsigned char *map, int rows, int cols);
-
-int vp9_set_internal_size(VP9_COMP *cpi,
-                          VPX_SCALING horiz_mode, VPX_SCALING vert_mode);
-
-int vp9_set_size_literal(VP9_COMP *cpi, unsigned int width,
-                         unsigned int height);
-
-void vp9_set_svc(VP9_COMP *cpi, int use_svc);
-
-int vp9_get_quantizer(struct VP9_COMP *cpi);
-
-static INLINE int frame_is_kf_gf_arf(const VP9_COMP *cpi) {
-  return frame_is_intra_only(&cpi->common) ||
-         cpi->refresh_alt_ref_frame ||
-         (cpi->refresh_golden_frame && !cpi->rc.is_src_frame_alt_ref);
-}
-
-static INLINE int get_ref_frame_map_idx(const VP9_COMP *cpi,
-                                        MV_REFERENCE_FRAME ref_frame) {
-  if (ref_frame == LAST_FRAME) {
-    return cpi->lst_fb_idx;
-  } else if (ref_frame == GOLDEN_FRAME) {
-    return cpi->gld_fb_idx;
-  } else {
-    return cpi->alt_fb_idx;
-  }
-}
-
-static INLINE int get_ref_frame_buf_idx(const VP9_COMP *const cpi,
-                                        int ref_frame) {
-  const VP9_COMMON *const cm = &cpi->common;
-  const int map_idx = get_ref_frame_map_idx(cpi, ref_frame);
-  return (map_idx != INVALID_IDX) ? cm->ref_frame_map[map_idx] : INVALID_IDX;
-}
-
-static INLINE YV12_BUFFER_CONFIG *get_ref_frame_buffer(
-    VP9_COMP *cpi, MV_REFERENCE_FRAME ref_frame) {
-  VP9_COMMON *const cm = &cpi->common;
-  const int buf_idx = get_ref_frame_buf_idx(cpi, ref_frame);
-  return
-      buf_idx != INVALID_IDX ? &cm->buffer_pool->frame_bufs[buf_idx].buf : NULL;
-}
-
-static INLINE int get_token_alloc(int mb_rows, int mb_cols) {
-  // TODO(JBB): double check we can't exceed this token count if we have a
-  // 32x32 transform crossing a boundary at a multiple of 16.
-  // mb_rows, cols are in units of 16 pixels. We assume 3 planes all at full
-  // resolution. We assume up to 1 token per pixel, and then allow
-  // a head room of 4.
-  return mb_rows * mb_cols * (16 * 16 * 3 + 4);
-}
-
-// Get the allocated token size for a tile. It does the same calculation as in
-// the frame token allocation.
-static INLINE int allocated_tokens(TileInfo tile) {
-  int tile_mb_rows = (tile.mi_row_end - tile.mi_row_start + 1) >> 1;
-  int tile_mb_cols = (tile.mi_col_end - tile.mi_col_start + 1) >> 1;
-
-  return get_token_alloc(tile_mb_rows, tile_mb_cols);
-}
-
-void vp9_scale_references(VP9_COMP *cpi);
-
-void vp9_update_reference_frames(VP9_COMP *cpi);
-
-void vp9_set_high_precision_mv(VP9_COMP *cpi, int allow_high_precision_mv);
-
-YV12_BUFFER_CONFIG *vp9_svc_twostage_scale(VP9_COMMON *cm,
-                                           YV12_BUFFER_CONFIG *unscaled,
-                                           YV12_BUFFER_CONFIG *scaled,
-                                           YV12_BUFFER_CONFIG *scaled_temp);
-
-YV12_BUFFER_CONFIG *vp9_scale_if_required(VP9_COMMON *cm,
-                                          YV12_BUFFER_CONFIG *unscaled,
-                                          YV12_BUFFER_CONFIG *scaled,
-                                          int use_normative_scaler);
-
-void vp9_apply_encoding_flags(VP9_COMP *cpi, vpx_enc_frame_flags_t flags);
-
-static INLINE int is_two_pass_svc(const struct VP9_COMP *const cpi) {
-  return cpi->use_svc && cpi->oxcf.pass != 0;
-}
-
-static INLINE int is_one_pass_cbr_svc(const struct VP9_COMP *const cpi) {
-  return (cpi->use_svc && cpi->oxcf.pass == 0);
-}
-
-static INLINE int is_altref_enabled(const VP9_COMP *const cpi) {
-  return cpi->oxcf.mode != REALTIME && cpi->oxcf.lag_in_frames > 0 &&
-         (cpi->oxcf.enable_auto_arf &&
-          (!is_two_pass_svc(cpi) ||
-           cpi->oxcf.ss_enable_auto_arf[cpi->svc.spatial_layer_id]));
-}
-
-static INLINE void set_ref_ptrs(VP9_COMMON *cm, MACROBLOCKD *xd,
-                                MV_REFERENCE_FRAME ref0,
-                                MV_REFERENCE_FRAME ref1) {
-  xd->block_refs[0] = &cm->frame_refs[ref0 >= LAST_FRAME ? ref0 - LAST_FRAME
-                                                         : 0];
-  xd->block_refs[1] = &cm->frame_refs[ref1 >= LAST_FRAME ? ref1 - LAST_FRAME
-                                                         : 0];
-}
-
-static INLINE int get_chessboard_index(const int frame_index) {
-  return frame_index & 0x1;
-}
-
-static INLINE int *cond_cost_list(const struct VP9_COMP *cpi, int *cost_list) {
-  return cpi->sf.mv.subpel_search_method != SUBPEL_TREE ? cost_list : NULL;
-}
-
-VP9_LEVEL vp9_get_level(const Vp9LevelSpec *const level_spec);
-
-void vp9_new_framerate(VP9_COMP *cpi, double framerate);
-
-#define LAYER_IDS_TO_IDX(sl, tl, num_tl) ((sl) * (num_tl) + (tl))
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP9_ENCODER_VP9_ENCODER_H_
diff --git a/vp9/encoder/vp9_ethread.c b/vp9/encoder/vp9_ethread.c
deleted file mode 100644 (file)
index 1d1926c..0000000
+++ /dev/null
@@ -1,203 +0,0 @@
-/*
- *  Copyright (c) 2014 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.
- */
-
-#include "vp9/encoder/vp9_encodeframe.h"
-#include "vp9/encoder/vp9_encoder.h"
-#include "vp9/encoder/vp9_ethread.h"
-#include "vpx_dsp/vpx_dsp_common.h"
-
-static void accumulate_rd_opt(ThreadData *td, ThreadData *td_t) {
-  int i, j, k, l, m, n;
-
-  for (i = 0; i < REFERENCE_MODES; i++)
-    td->rd_counts.comp_pred_diff[i] += td_t->rd_counts.comp_pred_diff[i];
-
-  for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++)
-    td->rd_counts.filter_diff[i] += td_t->rd_counts.filter_diff[i];
-
-  for (i = 0; i < TX_SIZES; i++)
-    for (j = 0; j < PLANE_TYPES; j++)
-      for (k = 0; k < REF_TYPES; k++)
-        for (l = 0; l < COEF_BANDS; l++)
-          for (m = 0; m < COEFF_CONTEXTS; m++)
-            for (n = 0; n < ENTROPY_TOKENS; n++)
-              td->rd_counts.coef_counts[i][j][k][l][m][n] +=
-                  td_t->rd_counts.coef_counts[i][j][k][l][m][n];
-
-  // Counts of all motion searches and exhuastive mesh searches.
-  td->rd_counts.m_search_count += td_t->rd_counts.m_search_count;
-  td->rd_counts.ex_search_count += td_t->rd_counts.ex_search_count;
-}
-
-static int enc_worker_hook(EncWorkerData *const thread_data, void *unused) {
-  VP9_COMP *const cpi = thread_data->cpi;
-  const VP9_COMMON *const cm = &cpi->common;
-  const int tile_cols = 1 << cm->log2_tile_cols;
-  const int tile_rows = 1 << cm->log2_tile_rows;
-  int t;
-
-  (void) unused;
-
-  for (t = thread_data->start; t < tile_rows * tile_cols;
-      t += cpi->num_workers) {
-    int tile_row = t / tile_cols;
-    int tile_col = t % tile_cols;
-
-    vp9_encode_tile(cpi, thread_data->td, tile_row, tile_col);
-  }
-
-  return 0;
-}
-
-static int get_max_tile_cols(VP9_COMP *cpi) {
-  const int aligned_width = ALIGN_POWER_OF_TWO(cpi->oxcf.width, MI_SIZE_LOG2);
-  int mi_cols = aligned_width >> MI_SIZE_LOG2;
-  int min_log2_tile_cols, max_log2_tile_cols;
-  int log2_tile_cols;
-
-  vp9_get_tile_n_bits(mi_cols, &min_log2_tile_cols, &max_log2_tile_cols);
-  log2_tile_cols = clamp(cpi->oxcf.tile_columns,
-                   min_log2_tile_cols, max_log2_tile_cols);
-  return (1 << log2_tile_cols);
-}
-
-void vp9_encode_tiles_mt(VP9_COMP *cpi) {
-  VP9_COMMON *const cm = &cpi->common;
-  const int tile_cols = 1 << cm->log2_tile_cols;
-  const VPxWorkerInterface *const winterface = vpx_get_worker_interface();
-  const int num_workers = VPXMIN(cpi->oxcf.max_threads, tile_cols);
-  int i;
-
-  vp9_init_tile_data(cpi);
-
-  // Only run once to create threads and allocate thread data.
-  if (cpi->num_workers == 0) {
-    int allocated_workers = num_workers;
-
-    // While using SVC, we need to allocate threads according to the highest
-    // resolution.
-    if (cpi->use_svc) {
-      int max_tile_cols = get_max_tile_cols(cpi);
-      allocated_workers = VPXMIN(cpi->oxcf.max_threads, max_tile_cols);
-    }
-
-    CHECK_MEM_ERROR(cm, cpi->workers,
-                    vpx_malloc(allocated_workers * sizeof(*cpi->workers)));
-
-    CHECK_MEM_ERROR(cm, cpi->tile_thr_data,
-                    vpx_calloc(allocated_workers,
-                    sizeof(*cpi->tile_thr_data)));
-
-    for (i = 0; i < allocated_workers; i++) {
-      VPxWorker *const worker = &cpi->workers[i];
-      EncWorkerData *thread_data = &cpi->tile_thr_data[i];
-
-      ++cpi->num_workers;
-      winterface->init(worker);
-
-      if (i < allocated_workers - 1) {
-        thread_data->cpi = cpi;
-
-        // Allocate thread data.
-        CHECK_MEM_ERROR(cm, thread_data->td,
-                        vpx_memalign(32, sizeof(*thread_data->td)));
-        vp9_zero(*thread_data->td);
-
-        // Set up pc_tree.
-        thread_data->td->leaf_tree = NULL;
-        thread_data->td->pc_tree = NULL;
-        vp9_setup_pc_tree(cm, thread_data->td);
-
-        // Allocate frame counters in thread data.
-        CHECK_MEM_ERROR(cm, thread_data->td->counts,
-                        vpx_calloc(1, sizeof(*thread_data->td->counts)));
-
-        // Create threads
-        if (!winterface->reset(worker))
-          vpx_internal_error(&cm->error, VPX_CODEC_ERROR,
-                             "Tile encoder thread creation failed");
-      } else {
-        // Main thread acts as a worker and uses the thread data in cpi.
-        thread_data->cpi = cpi;
-        thread_data->td = &cpi->td;
-      }
-
-      winterface->sync(worker);
-    }
-  }
-
-  for (i = 0; i < num_workers; i++) {
-    VPxWorker *const worker = &cpi->workers[i];
-    EncWorkerData *thread_data;
-
-    worker->hook = (VPxWorkerHook)enc_worker_hook;
-    worker->data1 = &cpi->tile_thr_data[i];
-    worker->data2 = NULL;
-    thread_data = (EncWorkerData*)worker->data1;
-
-    // Before encoding a frame, copy the thread data from cpi.
-    if (thread_data->td != &cpi->td) {
-      thread_data->td->mb = cpi->td.mb;
-      thread_data->td->rd_counts = cpi->td.rd_counts;
-    }
-    if (thread_data->td->counts != &cpi->common.counts) {
-      memcpy(thread_data->td->counts, &cpi->common.counts,
-             sizeof(cpi->common.counts));
-    }
-
-    // Handle use_nonrd_pick_mode case.
-    if (cpi->sf.use_nonrd_pick_mode) {
-      MACROBLOCK *const x = &thread_data->td->mb;
-      MACROBLOCKD *const xd = &x->e_mbd;
-      struct macroblock_plane *const p = x->plane;
-      struct macroblockd_plane *const pd = xd->plane;
-      PICK_MODE_CONTEXT *ctx = &thread_data->td->pc_root->none;
-      int j;
-
-      for (j = 0; j < MAX_MB_PLANE; ++j) {
-        p[j].coeff = ctx->coeff_pbuf[j][0];
-        p[j].qcoeff = ctx->qcoeff_pbuf[j][0];
-        pd[j].dqcoeff = ctx->dqcoeff_pbuf[j][0];
-        p[j].eobs = ctx->eobs_pbuf[j][0];
-      }
-    }
-  }
-
-  // Encode a frame
-  for (i = 0; i < num_workers; i++) {
-    VPxWorker *const worker = &cpi->workers[i];
-    EncWorkerData *const thread_data = (EncWorkerData*)worker->data1;
-
-    // Set the starting tile for each thread.
-    thread_data->start = i;
-
-    if (i == cpi->num_workers - 1)
-      winterface->execute(worker);
-    else
-      winterface->launch(worker);
-  }
-
-  // Encoding ends.
-  for (i = 0; i < num_workers; i++) {
-    VPxWorker *const worker = &cpi->workers[i];
-    winterface->sync(worker);
-  }
-
-  for (i = 0; i < num_workers; i++) {
-    VPxWorker *const worker = &cpi->workers[i];
-    EncWorkerData *const thread_data = (EncWorkerData*)worker->data1;
-
-    // Accumulate counters.
-    if (i < cpi->num_workers - 1) {
-      vp9_accumulate_frame_counts(&cm->counts, thread_data->td->counts, 0);
-      accumulate_rd_opt(&cpi->td, thread_data->td);
-    }
-  }
-}
diff --git a/vp9/encoder/vp9_ethread.h b/vp9/encoder/vp9_ethread.h
deleted file mode 100644 (file)
index 1efa4dc..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- *  Copyright (c) 2014 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.
- */
-
-#ifndef VP9_ENCODER_VP9_ETHREAD_H_
-#define VP9_ENCODER_VP9_ETHREAD_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-struct VP9_COMP;
-struct ThreadData;
-
-typedef struct EncWorkerData {
-  struct VP9_COMP *cpi;
-  struct ThreadData *td;
-  int start;
-} EncWorkerData;
-
-void vp9_encode_tiles_mt(struct VP9_COMP *cpi);
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP9_ENCODER_VP9_ETHREAD_H_
diff --git a/vp9/encoder/vp9_extend.c b/vp9/encoder/vp9_extend.c
deleted file mode 100644 (file)
index 92585b8..0000000
+++ /dev/null
@@ -1,201 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#include "vpx_dsp/vpx_dsp_common.h"
-#include "vpx_mem/vpx_mem.h"
-#include "vpx_ports/mem.h"
-
-#include "vp9/common/vp9_common.h"
-#include "vp9/encoder/vp9_extend.h"
-
-static void copy_and_extend_plane(const uint8_t *src, int src_pitch,
-                                  uint8_t *dst, int dst_pitch,
-                                  int w, int h,
-                                  int extend_top, int extend_left,
-                                  int extend_bottom, int extend_right) {
-  int i, linesize;
-
-  // copy the left and right most columns out
-  const uint8_t *src_ptr1 = src;
-  const uint8_t *src_ptr2 = src + w - 1;
-  uint8_t *dst_ptr1 = dst - extend_left;
-  uint8_t *dst_ptr2 = dst + w;
-
-  for (i = 0; i < h; i++) {
-    memset(dst_ptr1, src_ptr1[0], extend_left);
-    memcpy(dst_ptr1 + extend_left, src_ptr1, w);
-    memset(dst_ptr2, src_ptr2[0], extend_right);
-    src_ptr1 += src_pitch;
-    src_ptr2 += src_pitch;
-    dst_ptr1 += dst_pitch;
-    dst_ptr2 += dst_pitch;
-  }
-
-  // Now copy the top and bottom lines into each line of the respective
-  // borders
-  src_ptr1 = dst - extend_left;
-  src_ptr2 = dst + dst_pitch * (h - 1) - extend_left;
-  dst_ptr1 = dst + dst_pitch * (-extend_top) - extend_left;
-  dst_ptr2 = dst + dst_pitch * (h) - extend_left;
-  linesize = extend_left + extend_right + w;
-
-  for (i = 0; i < extend_top; i++) {
-    memcpy(dst_ptr1, src_ptr1, linesize);
-    dst_ptr1 += dst_pitch;
-  }
-
-  for (i = 0; i < extend_bottom; i++) {
-    memcpy(dst_ptr2, src_ptr2, linesize);
-    dst_ptr2 += dst_pitch;
-  }
-}
-
-#if CONFIG_VP9_HIGHBITDEPTH
-static void highbd_copy_and_extend_plane(const uint8_t *src8, int src_pitch,
-                                         uint8_t *dst8, int dst_pitch,
-                                         int w, int h,
-                                         int extend_top, int extend_left,
-                                         int extend_bottom, int extend_right) {
-  int i, linesize;
-  uint16_t *src = CONVERT_TO_SHORTPTR(src8);
-  uint16_t *dst = CONVERT_TO_SHORTPTR(dst8);
-
-  // copy the left and right most columns out
-  const uint16_t *src_ptr1 = src;
-  const uint16_t *src_ptr2 = src + w - 1;
-  uint16_t *dst_ptr1 = dst - extend_left;
-  uint16_t *dst_ptr2 = dst + w;
-
-  for (i = 0; i < h; i++) {
-    vpx_memset16(dst_ptr1, src_ptr1[0], extend_left);
-    memcpy(dst_ptr1 + extend_left, src_ptr1, w * sizeof(src_ptr1[0]));
-    vpx_memset16(dst_ptr2, src_ptr2[0], extend_right);
-    src_ptr1 += src_pitch;
-    src_ptr2 += src_pitch;
-    dst_ptr1 += dst_pitch;
-    dst_ptr2 += dst_pitch;
-  }
-
-  // Now copy the top and bottom lines into each line of the respective
-  // borders
-  src_ptr1 = dst - extend_left;
-  src_ptr2 = dst + dst_pitch * (h - 1) - extend_left;
-  dst_ptr1 = dst + dst_pitch * (-extend_top) - extend_left;
-  dst_ptr2 = dst + dst_pitch * (h) - extend_left;
-  linesize = extend_left + extend_right + w;
-
-  for (i = 0; i < extend_top; i++) {
-    memcpy(dst_ptr1, src_ptr1, linesize * sizeof(src_ptr1[0]));
-    dst_ptr1 += dst_pitch;
-  }
-
-  for (i = 0; i < extend_bottom; i++) {
-    memcpy(dst_ptr2, src_ptr2, linesize * sizeof(src_ptr2[0]));
-    dst_ptr2 += dst_pitch;
-  }
-}
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-
-void vp9_copy_and_extend_frame(const YV12_BUFFER_CONFIG *src,
-                               YV12_BUFFER_CONFIG *dst) {
-  // Extend src frame in buffer
-  // Altref filtering assumes 16 pixel extension
-  const int et_y = 16;
-  const int el_y = 16;
-  // Motion estimation may use src block variance with the block size up
-  // to 64x64, so the right and bottom need to be extended to 64 multiple
-  // or up to 16, whichever is greater.
-  const int er_y =
-      VPXMAX(src->y_width + 16, ALIGN_POWER_OF_TWO(src->y_width, 6)) -
-      src->y_crop_width;
-  const int eb_y =
-      VPXMAX(src->y_height + 16, ALIGN_POWER_OF_TWO(src->y_height, 6)) -
-      src->y_crop_height;
-  const int uv_width_subsampling = (src->uv_width != src->y_width);
-  const int uv_height_subsampling = (src->uv_height != src->y_height);
-  const int et_uv = et_y >> uv_height_subsampling;
-  const int el_uv = el_y >> uv_width_subsampling;
-  const int eb_uv = eb_y >> uv_height_subsampling;
-  const int er_uv = er_y >> uv_width_subsampling;
-
-#if CONFIG_VP9_HIGHBITDEPTH
-  if (src->flags & YV12_FLAG_HIGHBITDEPTH) {
-    highbd_copy_and_extend_plane(src->y_buffer, src->y_stride,
-                                 dst->y_buffer, dst->y_stride,
-                                 src->y_crop_width, src->y_crop_height,
-                                 et_y, el_y, eb_y, er_y);
-
-    highbd_copy_and_extend_plane(src->u_buffer, src->uv_stride,
-                                 dst->u_buffer, dst->uv_stride,
-                                 src->uv_crop_width, src->uv_crop_height,
-                                 et_uv, el_uv, eb_uv, er_uv);
-
-    highbd_copy_and_extend_plane(src->v_buffer, src->uv_stride,
-                                 dst->v_buffer, dst->uv_stride,
-                                 src->uv_crop_width, src->uv_crop_height,
-                                 et_uv, el_uv, eb_uv, er_uv);
-    return;
-  }
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-
-  copy_and_extend_plane(src->y_buffer, src->y_stride,
-                        dst->y_buffer, dst->y_stride,
-                        src->y_crop_width, src->y_crop_height,
-                        et_y, el_y, eb_y, er_y);
-
-  copy_and_extend_plane(src->u_buffer, src->uv_stride,
-                        dst->u_buffer, dst->uv_stride,
-                        src->uv_crop_width, src->uv_crop_height,
-                        et_uv, el_uv, eb_uv, er_uv);
-
-  copy_and_extend_plane(src->v_buffer, src->uv_stride,
-                        dst->v_buffer, dst->uv_stride,
-                        src->uv_crop_width, src->uv_crop_height,
-                        et_uv, el_uv, eb_uv, er_uv);
-}
-
-void vp9_copy_and_extend_frame_with_rect(const YV12_BUFFER_CONFIG *src,
-                                         YV12_BUFFER_CONFIG *dst,
-                                         int srcy, int srcx,
-                                         int srch, int srcw) {
-  // If the side is not touching the bounder then don't extend.
-  const int et_y = srcy ? 0 : dst->border;
-  const int el_y = srcx ? 0 : dst->border;
-  const int eb_y = srcy + srch != src->y_height ? 0 :
-                      dst->border + dst->y_height - src->y_height;
-  const int er_y = srcx + srcw != src->y_width ? 0 :
-                      dst->border + dst->y_width - src->y_width;
-  const int src_y_offset = srcy * src->y_stride + srcx;
-  const int dst_y_offset = srcy * dst->y_stride + srcx;
-
-  const int et_uv = ROUND_POWER_OF_TWO(et_y, 1);
-  const int el_uv = ROUND_POWER_OF_TWO(el_y, 1);
-  const int eb_uv = ROUND_POWER_OF_TWO(eb_y, 1);
-  const int er_uv = ROUND_POWER_OF_TWO(er_y, 1);
-  const int src_uv_offset = ((srcy * src->uv_stride) >> 1) + (srcx >> 1);
-  const int dst_uv_offset = ((srcy * dst->uv_stride) >> 1) + (srcx >> 1);
-  const int srch_uv = ROUND_POWER_OF_TWO(srch, 1);
-  const int srcw_uv = ROUND_POWER_OF_TWO(srcw, 1);
-
-  copy_and_extend_plane(src->y_buffer + src_y_offset, src->y_stride,
-                        dst->y_buffer + dst_y_offset, dst->y_stride,
-                        srcw, srch,
-                        et_y, el_y, eb_y, er_y);
-
-  copy_and_extend_plane(src->u_buffer + src_uv_offset, src->uv_stride,
-                        dst->u_buffer + dst_uv_offset, dst->uv_stride,
-                        srcw_uv, srch_uv,
-                        et_uv, el_uv, eb_uv, er_uv);
-
-  copy_and_extend_plane(src->v_buffer + src_uv_offset, src->uv_stride,
-                        dst->v_buffer + dst_uv_offset, dst->uv_stride,
-                        srcw_uv, srch_uv,
-                        et_uv, el_uv, eb_uv, er_uv);
-}
diff --git a/vp9/encoder/vp9_extend.h b/vp9/encoder/vp9_extend.h
deleted file mode 100644 (file)
index 058fe09..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#ifndef VP9_ENCODER_VP9_EXTEND_H_
-#define VP9_ENCODER_VP9_EXTEND_H_
-
-#include "vpx_scale/yv12config.h"
-#include "vpx/vpx_integer.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-void vp9_copy_and_extend_frame(const YV12_BUFFER_CONFIG *src,
-                               YV12_BUFFER_CONFIG *dst);
-
-void vp9_copy_and_extend_frame_with_rect(const YV12_BUFFER_CONFIG *src,
-                                         YV12_BUFFER_CONFIG *dst,
-                                         int srcy, int srcx,
-                                         int srch, int srcw);
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP9_ENCODER_VP9_EXTEND_H_
diff --git a/vp9/encoder/vp9_firstpass.c b/vp9/encoder/vp9_firstpass.c
deleted file mode 100644 (file)
index f6e61b6..0000000
+++ /dev/null
@@ -1,2937 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#include <limits.h>
-#include <math.h>
-#include <stdio.h>
-
-#include "./vpx_dsp_rtcd.h"
-#include "./vpx_scale_rtcd.h"
-
-#include "vpx_dsp/vpx_dsp_common.h"
-#include "vpx_mem/vpx_mem.h"
-#include "vpx_ports/mem.h"
-#include "vpx_ports/system_state.h"
-#include "vpx_scale/vpx_scale.h"
-#include "vpx_scale/yv12config.h"
-
-#include "vp9/common/vp9_entropymv.h"
-#include "vp9/common/vp9_quant_common.h"
-#include "vp9/common/vp9_reconinter.h"  // vp9_setup_dst_planes()
-#include "vp9/encoder/vp9_aq_variance.h"
-#include "vp9/encoder/vp9_block.h"
-#include "vp9/encoder/vp9_encodeframe.h"
-#include "vp9/encoder/vp9_encodemb.h"
-#include "vp9/encoder/vp9_encodemv.h"
-#include "vp9/encoder/vp9_encoder.h"
-#include "vp9/encoder/vp9_extend.h"
-#include "vp9/encoder/vp9_firstpass.h"
-#include "vp9/encoder/vp9_mcomp.h"
-#include "vp9/encoder/vp9_quantize.h"
-#include "vp9/encoder/vp9_rd.h"
-#include "vpx_dsp/variance.h"
-
-#define OUTPUT_FPF          0
-#define ARF_STATS_OUTPUT    0
-
-#define BOOST_BREAKOUT      12.5
-#define BOOST_FACTOR        12.5
-#define FACTOR_PT_LOW       0.70
-#define FACTOR_PT_HIGH      0.90
-#define FIRST_PASS_Q        10.0
-#define GF_MAX_BOOST        96.0
-#define INTRA_MODE_PENALTY  1024
-#define KF_MAX_BOOST        128.0
-#define MIN_ARF_GF_BOOST    240
-#define MIN_DECAY_FACTOR    0.01
-#define MIN_KF_BOOST        300
-#define NEW_MV_MODE_PENALTY 32
-#define SVC_FACTOR_PT_LOW   0.45
-#define DARK_THRESH         64
-#define DEFAULT_GRP_WEIGHT  1.0
-#define RC_FACTOR_MIN       0.75
-#define RC_FACTOR_MAX       1.75
-
-
-#define NCOUNT_INTRA_THRESH 8192
-#define NCOUNT_INTRA_FACTOR 3
-
-
-#define DOUBLE_DIVIDE_CHECK(x) ((x) < 0 ? (x) - 0.000001 : (x) + 0.000001)
-
-#if ARF_STATS_OUTPUT
-unsigned int arf_count = 0;
-#endif
-
-// Resets the first pass file to the given position using a relative seek from
-// the current position.
-static void reset_fpf_position(TWO_PASS *p,
-                               const FIRSTPASS_STATS *position) {
-  p->stats_in = position;
-}
-
-// Read frame stats at an offset from the current position.
-static const FIRSTPASS_STATS *read_frame_stats(const TWO_PASS *p, int offset) {
-  if ((offset >= 0 && p->stats_in + offset >= p->stats_in_end) ||
-      (offset < 0 && p->stats_in + offset < p->stats_in_start)) {
-    return NULL;
-  }
-
-  return &p->stats_in[offset];
-}
-
-static int input_stats(TWO_PASS *p, FIRSTPASS_STATS *fps) {
-  if (p->stats_in >= p->stats_in_end)
-    return EOF;
-
-  *fps = *p->stats_in;
-  ++p->stats_in;
-  return 1;
-}
-
-static void output_stats(FIRSTPASS_STATS *stats,
-                         struct vpx_codec_pkt_list *pktlist) {
-  struct vpx_codec_cx_pkt pkt;
-  pkt.kind = VPX_CODEC_STATS_PKT;
-  pkt.data.twopass_stats.buf = stats;
-  pkt.data.twopass_stats.sz = sizeof(FIRSTPASS_STATS);
-  vpx_codec_pkt_list_add(pktlist, &pkt);
-
-// TEMP debug code
-#if OUTPUT_FPF
-  {
-    FILE *fpfile;
-    fpfile = fopen("firstpass.stt", "a");
-
-    fprintf(fpfile, "%12.0lf %12.4lf %12.0lf %12.0lf %12.0lf %12.4lf %12.4lf"
-            "%12.4lf %12.4lf %12.4lf %12.4lf %12.4lf %12.4lf %12.4lf %12.4lf"
-            "%12.4lf %12.4lf %12.4lf %12.0lf %12.0lf %12.0lf %12.4lf\n",
-            stats->frame,
-            stats->weight,
-            stats->intra_error,
-            stats->coded_error,
-            stats->sr_coded_error,
-            stats->pcnt_inter,
-            stats->pcnt_motion,
-            stats->pcnt_second_ref,
-            stats->pcnt_neutral,
-            stats->intra_skip_pct,
-            stats->intra_smooth_pct,
-            stats->inactive_zone_rows,
-            stats->inactive_zone_cols,
-            stats->MVr,
-            stats->mvr_abs,
-            stats->MVc,
-            stats->mvc_abs,
-            stats->MVrv,
-            stats->MVcv,
-            stats->mv_in_out_count,
-            stats->new_mv_count,
-            stats->count,
-            stats->duration);
-    fclose(fpfile);
-  }
-#endif
-}
-
-#if CONFIG_FP_MB_STATS
-static void output_fpmb_stats(uint8_t *this_frame_mb_stats, VP9_COMMON *cm,
-                         struct vpx_codec_pkt_list *pktlist) {
-  struct vpx_codec_cx_pkt pkt;
-  pkt.kind = VPX_CODEC_FPMB_STATS_PKT;
-  pkt.data.firstpass_mb_stats.buf = this_frame_mb_stats;
-  pkt.data.firstpass_mb_stats.sz = cm->initial_mbs * sizeof(uint8_t);
-  vpx_codec_pkt_list_add(pktlist, &pkt);
-}
-#endif
-
-static void zero_stats(FIRSTPASS_STATS *section) {
-  section->frame = 0.0;
-  section->weight = 0.0;
-  section->intra_error = 0.0;
-  section->coded_error = 0.0;
-  section->sr_coded_error = 0.0;
-  section->pcnt_inter  = 0.0;
-  section->pcnt_motion  = 0.0;
-  section->pcnt_second_ref = 0.0;
-  section->pcnt_neutral = 0.0;
-  section->intra_skip_pct = 0.0;
-  section->intra_smooth_pct = 0.0;
-  section->inactive_zone_rows = 0.0;
-  section->inactive_zone_cols = 0.0;
-  section->MVr = 0.0;
-  section->mvr_abs     = 0.0;
-  section->MVc        = 0.0;
-  section->mvc_abs     = 0.0;
-  section->MVrv       = 0.0;
-  section->MVcv       = 0.0;
-  section->mv_in_out_count  = 0.0;
-  section->new_mv_count = 0.0;
-  section->count      = 0.0;
-  section->duration   = 1.0;
-  section->spatial_layer_id = 0;
-}
-
-static void accumulate_stats(FIRSTPASS_STATS *section,
-                             const FIRSTPASS_STATS *frame) {
-  section->frame += frame->frame;
-  section->weight += frame->weight;
-  section->spatial_layer_id = frame->spatial_layer_id;
-  section->intra_error += frame->intra_error;
-  section->coded_error += frame->coded_error;
-  section->sr_coded_error += frame->sr_coded_error;
-  section->pcnt_inter  += frame->pcnt_inter;
-  section->pcnt_motion += frame->pcnt_motion;
-  section->pcnt_second_ref += frame->pcnt_second_ref;
-  section->pcnt_neutral += frame->pcnt_neutral;
-  section->intra_skip_pct += frame->intra_skip_pct;
-  section->intra_smooth_pct += frame->intra_smooth_pct;
-  section->inactive_zone_rows += frame->inactive_zone_rows;
-  section->inactive_zone_cols += frame->inactive_zone_cols;
-  section->MVr += frame->MVr;
-  section->mvr_abs     += frame->mvr_abs;
-  section->MVc        += frame->MVc;
-  section->mvc_abs     += frame->mvc_abs;
-  section->MVrv       += frame->MVrv;
-  section->MVcv       += frame->MVcv;
-  section->mv_in_out_count  += frame->mv_in_out_count;
-  section->new_mv_count += frame->new_mv_count;
-  section->count      += frame->count;
-  section->duration   += frame->duration;
-}
-
-static void subtract_stats(FIRSTPASS_STATS *section,
-                           const FIRSTPASS_STATS *frame) {
-  section->frame -= frame->frame;
-  section->weight -= frame->weight;
-  section->intra_error -= frame->intra_error;
-  section->coded_error -= frame->coded_error;
-  section->sr_coded_error -= frame->sr_coded_error;
-  section->pcnt_inter  -= frame->pcnt_inter;
-  section->pcnt_motion -= frame->pcnt_motion;
-  section->pcnt_second_ref -= frame->pcnt_second_ref;
-  section->pcnt_neutral -= frame->pcnt_neutral;
-  section->intra_skip_pct -= frame->intra_skip_pct;
-  section->intra_smooth_pct -= frame->intra_smooth_pct;
-  section->inactive_zone_rows -= frame->inactive_zone_rows;
-  section->inactive_zone_cols -= frame->inactive_zone_cols;
-  section->MVr -= frame->MVr;
-  section->mvr_abs     -= frame->mvr_abs;
-  section->MVc        -= frame->MVc;
-  section->mvc_abs     -= frame->mvc_abs;
-  section->MVrv       -= frame->MVrv;
-  section->MVcv       -= frame->MVcv;
-  section->mv_in_out_count  -= frame->mv_in_out_count;
-  section->new_mv_count -= frame->new_mv_count;
-  section->count      -= frame->count;
-  section->duration   -= frame->duration;
-}
-
-// Calculate an active area of the image that discounts formatting
-// bars and partially discounts other 0 energy areas.
-#define MIN_ACTIVE_AREA 0.5
-#define MAX_ACTIVE_AREA 1.0
-static double calculate_active_area(const VP9_COMP *cpi,
-                                    const FIRSTPASS_STATS *this_frame) {
-  double active_pct;
-
-  active_pct = 1.0 -
-    ((this_frame->intra_skip_pct / 2) +
-     ((this_frame->inactive_zone_rows * 2) / (double)cpi->common.mb_rows));
-  return fclamp(active_pct, MIN_ACTIVE_AREA, MAX_ACTIVE_AREA);
-}
-
-// Calculate a modified Error used in distributing bits between easier and
-// harder frames.
-#define ACT_AREA_CORRECTION 0.5
-static double calculate_modified_err(const VP9_COMP *cpi,
-                                     const TWO_PASS *twopass,
-                                     const VP9EncoderConfig *oxcf,
-                                     const FIRSTPASS_STATS *this_frame) {
-  const FIRSTPASS_STATS *const stats = &twopass->total_stats;
-  const double av_weight = stats->weight / stats->count;
-  const double av_err = (stats->coded_error * av_weight) / stats->count;
-  double modified_error =
-    av_err * pow(this_frame->coded_error * this_frame->weight /
-                 DOUBLE_DIVIDE_CHECK(av_err), oxcf->two_pass_vbrbias / 100.0);
-
-  // Correction for active area. Frames with a reduced active area
-  // (eg due to formatting bars) have a higher error per mb for the
-  // remaining active MBs. The correction here assumes that coding
-  // 0.5N blocks of complexity 2X is a little easier than coding N
-  // blocks of complexity X.
-  modified_error *=
-    pow(calculate_active_area(cpi, this_frame), ACT_AREA_CORRECTION);
-
-  return fclamp(modified_error,
-                twopass->modified_error_min, twopass->modified_error_max);
-}
-
-// This function returns the maximum target rate per frame.
-static int frame_max_bits(const RATE_CONTROL *rc,
-                          const VP9EncoderConfig *oxcf) {
-  int64_t max_bits = ((int64_t)rc->avg_frame_bandwidth *
-                          (int64_t)oxcf->two_pass_vbrmax_section) / 100;
-  if (max_bits < 0)
-    max_bits = 0;
-  else if (max_bits > rc->max_frame_bandwidth)
-    max_bits = rc->max_frame_bandwidth;
-
-  return (int)max_bits;
-}
-
-void vp9_init_first_pass(VP9_COMP *cpi) {
-  zero_stats(&cpi->twopass.total_stats);
-}
-
-void vp9_end_first_pass(VP9_COMP *cpi) {
-  if (is_two_pass_svc(cpi)) {
-    int i;
-    for (i = 0; i < cpi->svc.number_spatial_layers; ++i) {
-      output_stats(&cpi->svc.layer_context[i].twopass.total_stats,
-                   cpi->output_pkt_list);
-    }
-  } else {
-    output_stats(&cpi->twopass.total_stats, cpi->output_pkt_list);
-  }
-}
-
-static vpx_variance_fn_t get_block_variance_fn(BLOCK_SIZE bsize) {
-  switch (bsize) {
-    case BLOCK_8X8:
-      return vpx_mse8x8;
-    case BLOCK_16X8:
-      return vpx_mse16x8;
-    case BLOCK_8X16:
-      return vpx_mse8x16;
-    default:
-      return vpx_mse16x16;
-  }
-}
-
-static unsigned int get_prediction_error(BLOCK_SIZE bsize,
-                                         const struct buf_2d *src,
-                                         const struct buf_2d *ref) {
-  unsigned int sse;
-  const vpx_variance_fn_t fn = get_block_variance_fn(bsize);
-  fn(src->buf, src->stride, ref->buf, ref->stride, &sse);
-  return sse;
-}
-
-#if CONFIG_VP9_HIGHBITDEPTH
-static vpx_variance_fn_t highbd_get_block_variance_fn(BLOCK_SIZE bsize,
-                                                      int bd) {
-  switch (bd) {
-    default:
-      switch (bsize) {
-        case BLOCK_8X8:
-          return vpx_highbd_8_mse8x8;
-        case BLOCK_16X8:
-          return vpx_highbd_8_mse16x8;
-        case BLOCK_8X16:
-          return vpx_highbd_8_mse8x16;
-        default:
-          return vpx_highbd_8_mse16x16;
-      }
-      break;
-    case 10:
-      switch (bsize) {
-        case BLOCK_8X8:
-          return vpx_highbd_10_mse8x8;
-        case BLOCK_16X8:
-          return vpx_highbd_10_mse16x8;
-        case BLOCK_8X16:
-          return vpx_highbd_10_mse8x16;
-        default:
-          return vpx_highbd_10_mse16x16;
-      }
-      break;
-    case 12:
-      switch (bsize) {
-        case BLOCK_8X8:
-          return vpx_highbd_12_mse8x8;
-        case BLOCK_16X8:
-          return vpx_highbd_12_mse16x8;
-        case BLOCK_8X16:
-          return vpx_highbd_12_mse8x16;
-        default:
-          return vpx_highbd_12_mse16x16;
-      }
-      break;
-  }
-}
-
-static unsigned int highbd_get_prediction_error(BLOCK_SIZE bsize,
-                                                const struct buf_2d *src,
-                                                const struct buf_2d *ref,
-                                                int bd) {
-  unsigned int sse;
-  const vpx_variance_fn_t fn = highbd_get_block_variance_fn(bsize, bd);
-  fn(src->buf, src->stride, ref->buf, ref->stride, &sse);
-  return sse;
-}
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-
-// Refine the motion search range according to the frame dimension
-// for first pass test.
-static int get_search_range(const VP9_COMP *cpi) {
-  int sr = 0;
-  const int dim = VPXMIN(cpi->initial_width, cpi->initial_height);
-
-  while ((dim << sr) < MAX_FULL_PEL_VAL)
-    ++sr;
-  return sr;
-}
-
-static void first_pass_motion_search(VP9_COMP *cpi, MACROBLOCK *x,
-                                     const MV *ref_mv, MV *best_mv,
-                                     int *best_motion_err) {
-  MACROBLOCKD *const xd = &x->e_mbd;
-  MV tmp_mv = {0, 0};
-  MV ref_mv_full = {ref_mv->row >> 3, ref_mv->col >> 3};
-  int num00, tmp_err, n;
-  const BLOCK_SIZE bsize = xd->mi[0]->sb_type;
-  vp9_variance_fn_ptr_t v_fn_ptr = cpi->fn_ptr[bsize];
-  const int new_mv_mode_penalty = NEW_MV_MODE_PENALTY;
-
-  int step_param = 3;
-  int further_steps = (MAX_MVSEARCH_STEPS - 1) - step_param;
-  const int sr = get_search_range(cpi);
-  step_param += sr;
-  further_steps -= sr;
-
-  // Override the default variance function to use MSE.
-  v_fn_ptr.vf = get_block_variance_fn(bsize);
-#if CONFIG_VP9_HIGHBITDEPTH
-  if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
-    v_fn_ptr.vf = highbd_get_block_variance_fn(bsize, xd->bd);
-  }
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-
-  // Center the initial step/diamond search on best mv.
-  tmp_err = cpi->diamond_search_sad(x, &cpi->ss_cfg, &ref_mv_full, &tmp_mv,
-                                    step_param,
-                                    x->sadperbit16, &num00, &v_fn_ptr, ref_mv);
-  if (tmp_err < INT_MAX)
-    tmp_err = vp9_get_mvpred_var(x, &tmp_mv, ref_mv, &v_fn_ptr, 1);
-  if (tmp_err < INT_MAX - new_mv_mode_penalty)
-    tmp_err += new_mv_mode_penalty;
-
-  if (tmp_err < *best_motion_err) {
-    *best_motion_err = tmp_err;
-    *best_mv = tmp_mv;
-  }
-
-  // Carry out further step/diamond searches as necessary.
-  n = num00;
-  num00 = 0;
-
-  while (n < further_steps) {
-    ++n;
-
-    if (num00) {
-      --num00;
-    } else {
-      tmp_err = cpi->diamond_search_sad(x, &cpi->ss_cfg, &ref_mv_full, &tmp_mv,
-                                        step_param + n, x->sadperbit16,
-                                        &num00, &v_fn_ptr, ref_mv);
-      if (tmp_err < INT_MAX)
-        tmp_err = vp9_get_mvpred_var(x, &tmp_mv, ref_mv, &v_fn_ptr, 1);
-      if (tmp_err < INT_MAX - new_mv_mode_penalty)
-        tmp_err += new_mv_mode_penalty;
-
-      if (tmp_err < *best_motion_err) {
-        *best_motion_err = tmp_err;
-        *best_mv = tmp_mv;
-      }
-    }
-  }
-}
-
-static BLOCK_SIZE get_bsize(const VP9_COMMON *cm, int mb_row, int mb_col) {
-  if (2 * mb_col + 1 < cm->mi_cols) {
-    return 2 * mb_row + 1 < cm->mi_rows ? BLOCK_16X16
-                                        : BLOCK_16X8;
-  } else {
-    return 2 * mb_row + 1 < cm->mi_rows ? BLOCK_8X16
-                                        : BLOCK_8X8;
-  }
-}
-
-static int find_fp_qindex(vpx_bit_depth_t bit_depth) {
-  int i;
-
-  for (i = 0; i < QINDEX_RANGE; ++i)
-    if (vp9_convert_qindex_to_q(i, bit_depth) >= FIRST_PASS_Q)
-      break;
-
-  if (i == QINDEX_RANGE)
-    i--;
-
-  return i;
-}
-
-static void set_first_pass_params(VP9_COMP *cpi) {
-  VP9_COMMON *const cm = &cpi->common;
-  if (!cpi->refresh_alt_ref_frame &&
-      (cm->current_video_frame == 0 ||
-       (cpi->frame_flags & FRAMEFLAGS_KEY))) {
-    cm->frame_type = KEY_FRAME;
-  } else {
-    cm->frame_type = INTER_FRAME;
-  }
-  // Do not use periodic key frames.
-  cpi->rc.frames_to_key = INT_MAX;
-}
-
-// This threshold is used to track blocks where to all intents and purposes
-// the intra prediction error 0. Though the metric we test against
-// is technically a sse we are mainly interested in blocks where all the pixels
-// in the 8 bit domain have an error of <= 1 (where error = sse) so a
-// linear scaling for 10 and 12 bit gives similar results.
-#define UL_INTRA_THRESH 50
-static int get_ul_intra_threshold(VP9_COMMON *cm) {
-  int ret_val = UL_INTRA_THRESH;
-#if CONFIG_VP9_HIGHBITDEPTH
-  if (cm->use_highbitdepth) {
-    switch (cm->bit_depth) {
-      case VPX_BITS_8:
-        ret_val = UL_INTRA_THRESH;
-        break;
-      case VPX_BITS_10:
-        ret_val = UL_INTRA_THRESH >> 2;
-        break;
-      case VPX_BITS_12:
-        ret_val = UL_INTRA_THRESH >> 4;
-        break;
-      default:
-        assert(0 && "cm->bit_depth should be VPX_BITS_8, "
-                    "VPX_BITS_10 or VPX_BITS_12");
-    }
-  }
-#else
-  (void) cm;
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-  return ret_val;
-}
-
-#define SMOOTH_INTRA_THRESH 4000
-static int get_smooth_intra_threshold(VP9_COMMON *cm) {
-  int ret_val = SMOOTH_INTRA_THRESH;
-#if CONFIG_VP9_HIGHBITDEPTH
-  if (cm->use_highbitdepth) {
-    switch (cm->bit_depth) {
-      case VPX_BITS_8:
-        ret_val = SMOOTH_INTRA_THRESH;
-        break;
-      case VPX_BITS_10:
-        ret_val = SMOOTH_INTRA_THRESH >> 2;
-        break;
-      case VPX_BITS_12:
-        ret_val = SMOOTH_INTRA_THRESH >> 4;
-        break;
-      default:
-        assert(0 && "cm->bit_depth should be VPX_BITS_8, "
-                    "VPX_BITS_10 or VPX_BITS_12");
-    }
-  }
-#else
-  (void) cm;
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-  return ret_val;
-}
-
-#define INVALID_ROW -1
-void vp9_first_pass(VP9_COMP *cpi, const struct lookahead_entry *source) {
-  int mb_row, mb_col;
-  MACROBLOCK *const x = &cpi->td.mb;
-  VP9_COMMON *const cm = &cpi->common;
-  MACROBLOCKD *const xd = &x->e_mbd;
-  TileInfo tile;
-  struct macroblock_plane *const p = x->plane;
-  struct macroblockd_plane *const pd = xd->plane;
-  const PICK_MODE_CONTEXT *ctx = &cpi->td.pc_root->none;
-  int i;
-
-  int recon_yoffset, recon_uvoffset;
-  int64_t intra_error = 0;
-  int64_t coded_error = 0;
-  int64_t sr_coded_error = 0;
-
-  int sum_mvr = 0, sum_mvc = 0;
-  int sum_mvr_abs = 0, sum_mvc_abs = 0;
-  int64_t sum_mvrs = 0, sum_mvcs = 0;
-  int mvcount = 0;
-  int intercount = 0;
-  int second_ref_count = 0;
-  const int intrapenalty = INTRA_MODE_PENALTY;
-  double neutral_count;
-  int intra_skip_count = 0;
-  int intra_smooth_count = 0;
-  int image_data_start_row = INVALID_ROW;
-  int new_mv_count = 0;
-  int sum_in_vectors = 0;
-  MV lastmv = {0, 0};
-  TWO_PASS *twopass = &cpi->twopass;
-  const MV zero_mv = {0, 0};
-  int recon_y_stride, recon_uv_stride, uv_mb_height;
-
-  YV12_BUFFER_CONFIG *const lst_yv12 = get_ref_frame_buffer(cpi, LAST_FRAME);
-  YV12_BUFFER_CONFIG *gld_yv12 = get_ref_frame_buffer(cpi, GOLDEN_FRAME);
-  YV12_BUFFER_CONFIG *const new_yv12 = get_frame_new_buffer(cm);
-  const YV12_BUFFER_CONFIG *first_ref_buf = lst_yv12;
-
-  LAYER_CONTEXT *const lc = is_two_pass_svc(cpi) ?
-        &cpi->svc.layer_context[cpi->svc.spatial_layer_id] : NULL;
-  double intra_factor;
-  double brightness_factor;
-  BufferPool *const pool = cm->buffer_pool;
-  MODE_INFO mi_above, mi_left;
-
-  // First pass code requires valid last and new frame buffers.
-  assert(new_yv12 != NULL);
-  assert((lc != NULL) || frame_is_intra_only(cm) || (lst_yv12 != NULL));
-
-#if CONFIG_FP_MB_STATS
-  if (cpi->use_fp_mb_stats) {
-    vp9_zero_array(cpi->twopass.frame_mb_stats_buf, cm->initial_mbs);
-  }
-#endif
-
-  vpx_clear_system_state();
-
-  intra_factor = 0.0;
-  brightness_factor = 0.0;
-  neutral_count = 0.0;
-
-  set_first_pass_params(cpi);
-  vp9_set_quantizer(cm, find_fp_qindex(cm->bit_depth));
-
-  if (lc != NULL) {
-    twopass = &lc->twopass;
-
-    cpi->lst_fb_idx = cpi->svc.spatial_layer_id;
-    cpi->ref_frame_flags = VP9_LAST_FLAG;
-
-    if (cpi->svc.number_spatial_layers + cpi->svc.spatial_layer_id <
-        REF_FRAMES) {
-      cpi->gld_fb_idx =
-          cpi->svc.number_spatial_layers + cpi->svc.spatial_layer_id;
-      cpi->ref_frame_flags |= VP9_GOLD_FLAG;
-      cpi->refresh_golden_frame = (lc->current_video_frame_in_layer == 0);
-    } else {
-      cpi->refresh_golden_frame = 0;
-    }
-
-    if (lc->current_video_frame_in_layer == 0)
-      cpi->ref_frame_flags = 0;
-
-    vp9_scale_references(cpi);
-
-    // Use either last frame or alt frame for motion search.
-    if (cpi->ref_frame_flags & VP9_LAST_FLAG) {
-      first_ref_buf = vp9_get_scaled_ref_frame(cpi, LAST_FRAME);
-      if (first_ref_buf == NULL)
-        first_ref_buf = get_ref_frame_buffer(cpi, LAST_FRAME);
-    }
-
-    if (cpi->ref_frame_flags & VP9_GOLD_FLAG) {
-      gld_yv12 = vp9_get_scaled_ref_frame(cpi, GOLDEN_FRAME);
-      if (gld_yv12 == NULL) {
-        gld_yv12 = get_ref_frame_buffer(cpi, GOLDEN_FRAME);
-      }
-    } else {
-      gld_yv12 = NULL;
-    }
-
-    set_ref_ptrs(cm, xd,
-                 (cpi->ref_frame_flags & VP9_LAST_FLAG) ? LAST_FRAME: NONE,
-                 (cpi->ref_frame_flags & VP9_GOLD_FLAG) ? GOLDEN_FRAME : NONE);
-
-    cpi->Source = vp9_scale_if_required(cm, cpi->un_scaled_source,
-                                        &cpi->scaled_source, 0);
-  }
-
-  vp9_setup_block_planes(&x->e_mbd, cm->subsampling_x, cm->subsampling_y);
-
-  vp9_setup_src_planes(x, cpi->Source, 0, 0);
-  vp9_setup_dst_planes(xd->plane, new_yv12, 0, 0);
-
-  if (!frame_is_intra_only(cm)) {
-    vp9_setup_pre_planes(xd, 0, first_ref_buf, 0, 0, NULL);
-  }
-
-  xd->mi = cm->mi_grid_visible;
-  xd->mi[0] = cm->mi;
-
-  vp9_frame_init_quantizer(cpi);
-
-  for (i = 0; i < MAX_MB_PLANE; ++i) {
-    p[i].coeff = ctx->coeff_pbuf[i][1];
-    p[i].qcoeff = ctx->qcoeff_pbuf[i][1];
-    pd[i].dqcoeff = ctx->dqcoeff_pbuf[i][1];
-    p[i].eobs = ctx->eobs_pbuf[i][1];
-  }
-  x->skip_recode = 0;
-
-  vp9_init_mv_probs(cm);
-  vp9_initialize_rd_consts(cpi);
-
-  // Tiling is ignored in the first pass.
-  vp9_tile_init(&tile, cm, 0, 0);
-
-  recon_y_stride = new_yv12->y_stride;
-  recon_uv_stride = new_yv12->uv_stride;
-  uv_mb_height = 16 >> (new_yv12->y_height > new_yv12->uv_height);
-
-  for (mb_row = 0; mb_row < cm->mb_rows; ++mb_row) {
-    MV best_ref_mv = {0, 0};
-
-    // Reset above block coeffs.
-    recon_yoffset = (mb_row * recon_y_stride * 16);
-    recon_uvoffset = (mb_row * recon_uv_stride * uv_mb_height);
-
-    // Set up limit values for motion vectors to prevent them extending
-    // outside the UMV borders.
-    x->mv_row_min = -((mb_row * 16) + BORDER_MV_PIXELS_B16);
-    x->mv_row_max = ((cm->mb_rows - 1 - mb_row) * 16)
-                    + BORDER_MV_PIXELS_B16;
-
-    for (mb_col = 0; mb_col < cm->mb_cols; ++mb_col) {
-      int this_error;
-      const int use_dc_pred = (mb_col || mb_row) && (!mb_col || !mb_row);
-      const BLOCK_SIZE bsize = get_bsize(cm, mb_row, mb_col);
-      double log_intra;
-      int level_sample;
-
-#if CONFIG_FP_MB_STATS
-      const int mb_index = mb_row * cm->mb_cols + mb_col;
-#endif
-
-      vpx_clear_system_state();
-
-      xd->plane[0].dst.buf = new_yv12->y_buffer + recon_yoffset;
-      xd->plane[1].dst.buf = new_yv12->u_buffer + recon_uvoffset;
-      xd->plane[2].dst.buf = new_yv12->v_buffer + recon_uvoffset;
-      xd->mi[0]->sb_type = bsize;
-      xd->mi[0]->ref_frame[0] = INTRA_FRAME;
-      set_mi_row_col(xd, &tile,
-                     mb_row << 1, num_8x8_blocks_high_lookup[bsize],
-                     mb_col << 1, num_8x8_blocks_wide_lookup[bsize],
-                     cm->mi_rows, cm->mi_cols);
-      // Are edges available for intra prediction?
-      // Since the firstpass does not populate the mi_grid_visible,
-      // above_mi/left_mi must be overwritten with a nonzero value when edges
-      // are available.  Required by vp9_predict_intra_block().
-      xd->above_mi = (mb_row != 0) ? &mi_above : NULL;
-      xd->left_mi  = (mb_col > tile.mi_col_start) ? &mi_left : NULL;
-
-      // Do intra 16x16 prediction.
-      x->skip_encode = 0;
-      xd->mi[0]->mode = DC_PRED;
-      xd->mi[0]->tx_size = use_dc_pred ?
-         (bsize >= BLOCK_16X16 ? TX_16X16 : TX_8X8) : TX_4X4;
-      vp9_encode_intra_block_plane(x, bsize, 0, 0);
-      this_error = vpx_get_mb_ss(x->plane[0].src_diff);
-
-      // Keep a record of blocks that have almost no intra error residual
-      // (i.e. are in effect completely flat and untextured in the intra
-      // domain). In natural videos this is uncommon, but it is much more
-      // common in animations, graphics and screen content, so may be used
-      // as a signal to detect these types of content.
-      if (this_error < get_ul_intra_threshold(cm)) {
-        ++intra_skip_count;
-      } else if ((mb_col > 0) && (image_data_start_row == INVALID_ROW)) {
-        image_data_start_row = mb_row;
-      }
-      if (this_error < get_smooth_intra_threshold(cm)) {
-        ++intra_smooth_count;
-      }
-
-#if CONFIG_VP9_HIGHBITDEPTH
-      if (cm->use_highbitdepth) {
-        switch (cm->bit_depth) {
-          case VPX_BITS_8:
-            break;
-          case VPX_BITS_10:
-            this_error >>= 4;
-            break;
-          case VPX_BITS_12:
-            this_error >>= 8;
-            break;
-          default:
-            assert(0 && "cm->bit_depth should be VPX_BITS_8, "
-                        "VPX_BITS_10 or VPX_BITS_12");
-            return;
-        }
-      }
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-
-      vpx_clear_system_state();
-      log_intra = log(this_error + 1.0);
-      if (log_intra < 10.0)
-        intra_factor += 1.0 + ((10.0 - log_intra) * 0.05);
-      else
-        intra_factor += 1.0;
-
-#if CONFIG_VP9_HIGHBITDEPTH
-      if (cm->use_highbitdepth)
-        level_sample = CONVERT_TO_SHORTPTR(x->plane[0].src.buf)[0];
-      else
-        level_sample = x->plane[0].src.buf[0];
-#else
-      level_sample = x->plane[0].src.buf[0];
-#endif
-      if ((level_sample < DARK_THRESH) && (log_intra < 9.0))
-        brightness_factor += 1.0 + (0.01 * (DARK_THRESH - level_sample));
-      else
-        brightness_factor += 1.0;
-
-      // Intrapenalty below deals with situations where the intra and inter
-      // error scores are very low (e.g. a plain black frame).
-      // We do not have special cases in first pass for 0,0 and nearest etc so
-      // all inter modes carry an overhead cost estimate for the mv.
-      // When the error score is very low this causes us to pick all or lots of
-      // INTRA modes and throw lots of key frames.
-      // This penalty adds a cost matching that of a 0,0 mv to the intra case.
-      this_error += intrapenalty;
-
-      // Accumulate the intra error.
-      intra_error += (int64_t)this_error;
-
-#if CONFIG_FP_MB_STATS
-      if (cpi->use_fp_mb_stats) {
-        // initialization
-        cpi->twopass.frame_mb_stats_buf[mb_index] = 0;
-      }
-#endif
-
-      // Set up limit values for motion vectors to prevent them extending
-      // outside the UMV borders.
-      x->mv_col_min = -((mb_col * 16) + BORDER_MV_PIXELS_B16);
-      x->mv_col_max = ((cm->mb_cols - 1 - mb_col) * 16) + BORDER_MV_PIXELS_B16;
-
-      // Other than for the first frame do a motion search.
-      if ((lc == NULL && cm->current_video_frame > 0) ||
-          (lc != NULL && lc->current_video_frame_in_layer > 0)) {
-        int tmp_err, motion_error, raw_motion_error;
-        // Assume 0,0 motion with no mv overhead.
-        MV mv = {0, 0} , tmp_mv = {0, 0};
-        struct buf_2d unscaled_last_source_buf_2d;
-
-        xd->plane[0].pre[0].buf = first_ref_buf->y_buffer + recon_yoffset;
-#if CONFIG_VP9_HIGHBITDEPTH
-        if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
-          motion_error = highbd_get_prediction_error(
-              bsize, &x->plane[0].src, &xd->plane[0].pre[0], xd->bd);
-        } else {
-          motion_error = get_prediction_error(
-              bsize, &x->plane[0].src, &xd->plane[0].pre[0]);
-        }
-#else
-        motion_error = get_prediction_error(
-            bsize, &x->plane[0].src, &xd->plane[0].pre[0]);
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-
-        // Compute the motion error of the 0,0 motion using the last source
-        // frame as the reference. Skip the further motion search on
-        // reconstructed frame if this error is small.
-        unscaled_last_source_buf_2d.buf =
-            cpi->unscaled_last_source->y_buffer + recon_yoffset;
-        unscaled_last_source_buf_2d.stride =
-            cpi->unscaled_last_source->y_stride;
-#if CONFIG_VP9_HIGHBITDEPTH
-        if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
-          raw_motion_error = highbd_get_prediction_error(
-              bsize, &x->plane[0].src, &unscaled_last_source_buf_2d, xd->bd);
-        } else {
-          raw_motion_error = get_prediction_error(
-              bsize, &x->plane[0].src, &unscaled_last_source_buf_2d);
-        }
-#else
-        raw_motion_error = get_prediction_error(
-            bsize, &x->plane[0].src, &unscaled_last_source_buf_2d);
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-
-        // TODO(pengchong): Replace the hard-coded threshold
-        if (raw_motion_error > 25 || lc != NULL) {
-          // Test last reference frame using the previous best mv as the
-          // starting point (best reference) for the search.
-          first_pass_motion_search(cpi, x, &best_ref_mv, &mv, &motion_error);
-
-          // If the current best reference mv is not centered on 0,0 then do a
-          // 0,0 based search as well.
-          if (!is_zero_mv(&best_ref_mv)) {
-            tmp_err = INT_MAX;
-            first_pass_motion_search(cpi, x, &zero_mv, &tmp_mv, &tmp_err);
-
-            if (tmp_err < motion_error) {
-              motion_error = tmp_err;
-              mv = tmp_mv;
-            }
-          }
-
-          // Search in an older reference frame.
-          if (((lc == NULL && cm->current_video_frame > 1) ||
-               (lc != NULL && lc->current_video_frame_in_layer > 1))
-              && gld_yv12 != NULL) {
-            // Assume 0,0 motion with no mv overhead.
-            int gf_motion_error;
-
-            xd->plane[0].pre[0].buf = gld_yv12->y_buffer + recon_yoffset;
-#if CONFIG_VP9_HIGHBITDEPTH
-            if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
-              gf_motion_error = highbd_get_prediction_error(
-                  bsize, &x->plane[0].src, &xd->plane[0].pre[0], xd->bd);
-            } else {
-              gf_motion_error = get_prediction_error(
-                  bsize, &x->plane[0].src, &xd->plane[0].pre[0]);
-            }
-#else
-            gf_motion_error = get_prediction_error(
-                bsize, &x->plane[0].src, &xd->plane[0].pre[0]);
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-
-            first_pass_motion_search(cpi, x, &zero_mv, &tmp_mv,
-                                     &gf_motion_error);
-
-            if (gf_motion_error < motion_error && gf_motion_error < this_error)
-              ++second_ref_count;
-
-            // Reset to last frame as reference buffer.
-            xd->plane[0].pre[0].buf = first_ref_buf->y_buffer + recon_yoffset;
-            xd->plane[1].pre[0].buf = first_ref_buf->u_buffer + recon_uvoffset;
-            xd->plane[2].pre[0].buf = first_ref_buf->v_buffer + recon_uvoffset;
-
-            // In accumulating a score for the older reference frame take the
-            // best of the motion predicted score and the intra coded error
-            // (just as will be done for) accumulation of "coded_error" for
-            // the last frame.
-            if (gf_motion_error < this_error)
-              sr_coded_error += gf_motion_error;
-            else
-              sr_coded_error += this_error;
-          } else {
-            sr_coded_error += motion_error;
-          }
-        } else {
-          sr_coded_error += motion_error;
-        }
-
-        // Start by assuming that intra mode is best.
-        best_ref_mv.row = 0;
-        best_ref_mv.col = 0;
-
-#if CONFIG_FP_MB_STATS
-        if (cpi->use_fp_mb_stats) {
-          // intra predication statistics
-          cpi->twopass.frame_mb_stats_buf[mb_index] = 0;
-          cpi->twopass.frame_mb_stats_buf[mb_index] |= FPMB_DCINTRA_MASK;
-          cpi->twopass.frame_mb_stats_buf[mb_index] |= FPMB_MOTION_ZERO_MASK;
-          if (this_error > FPMB_ERROR_LARGE_TH) {
-            cpi->twopass.frame_mb_stats_buf[mb_index] |= FPMB_ERROR_LARGE_MASK;
-          } else if (this_error < FPMB_ERROR_SMALL_TH) {
-            cpi->twopass.frame_mb_stats_buf[mb_index] |= FPMB_ERROR_SMALL_MASK;
-          }
-        }
-#endif
-
-        if (motion_error <= this_error) {
-          vpx_clear_system_state();
-
-          // Keep a count of cases where the inter and intra were very close
-          // and very low. This helps with scene cut detection for example in
-          // cropped clips with black bars at the sides or top and bottom.
-          if (((this_error - intrapenalty) * 9 <= motion_error * 10) &&
-              (this_error < (2 * intrapenalty))) {
-            neutral_count += 1.0;
-          // Also track cases where the intra is not much worse than the inter
-          // and use this in limiting the GF/arf group length.
-          } else if ((this_error > NCOUNT_INTRA_THRESH) &&
-                     (this_error < (NCOUNT_INTRA_FACTOR * motion_error))) {
-            neutral_count += (double)motion_error /
-                             DOUBLE_DIVIDE_CHECK((double)this_error);
-          }
-
-          mv.row *= 8;
-          mv.col *= 8;
-          this_error = motion_error;
-          xd->mi[0]->mode = NEWMV;
-          xd->mi[0]->mv[0].as_mv = mv;
-          xd->mi[0]->tx_size = TX_4X4;
-          xd->mi[0]->ref_frame[0] = LAST_FRAME;
-          xd->mi[0]->ref_frame[1] = NONE;
-          vp9_build_inter_predictors_sby(xd, mb_row << 1, mb_col << 1, bsize);
-          vp9_encode_sby_pass1(x, bsize);
-          sum_mvr += mv.row;
-          sum_mvr_abs += abs(mv.row);
-          sum_mvc += mv.col;
-          sum_mvc_abs += abs(mv.col);
-          sum_mvrs += mv.row * mv.row;
-          sum_mvcs += mv.col * mv.col;
-          ++intercount;
-
-          best_ref_mv = mv;
-
-#if CONFIG_FP_MB_STATS
-          if (cpi->use_fp_mb_stats) {
-            // inter predication statistics
-            cpi->twopass.frame_mb_stats_buf[mb_index] = 0;
-            cpi->twopass.frame_mb_stats_buf[mb_index] &= ~FPMB_DCINTRA_MASK;
-            cpi->twopass.frame_mb_stats_buf[mb_index] |= FPMB_MOTION_ZERO_MASK;
-            if (this_error > FPMB_ERROR_LARGE_TH) {
-              cpi->twopass.frame_mb_stats_buf[mb_index] |=
-                  FPMB_ERROR_LARGE_MASK;
-            } else if (this_error < FPMB_ERROR_SMALL_TH) {
-              cpi->twopass.frame_mb_stats_buf[mb_index] |=
-                  FPMB_ERROR_SMALL_MASK;
-            }
-          }
-#endif
-
-          if (!is_zero_mv(&mv)) {
-            ++mvcount;
-
-#if CONFIG_FP_MB_STATS
-            if (cpi->use_fp_mb_stats) {
-              cpi->twopass.frame_mb_stats_buf[mb_index] &=
-                  ~FPMB_MOTION_ZERO_MASK;
-              // check estimated motion direction
-              if (mv.as_mv.col > 0 && mv.as_mv.col >= abs(mv.as_mv.row)) {
-                // right direction
-                cpi->twopass.frame_mb_stats_buf[mb_index] |=
-                    FPMB_MOTION_RIGHT_MASK;
-              } else if (mv.as_mv.row < 0 &&
-                         abs(mv.as_mv.row) >= abs(mv.as_mv.col)) {
-                // up direction
-                cpi->twopass.frame_mb_stats_buf[mb_index] |=
-                    FPMB_MOTION_UP_MASK;
-              } else if (mv.as_mv.col < 0 &&
-                         abs(mv.as_mv.col) >= abs(mv.as_mv.row)) {
-                // left direction
-                cpi->twopass.frame_mb_stats_buf[mb_index] |=
-                    FPMB_MOTION_LEFT_MASK;
-              } else {
-                // down direction
-                cpi->twopass.frame_mb_stats_buf[mb_index] |=
-                    FPMB_MOTION_DOWN_MASK;
-              }
-            }
-#endif
-
-            // Non-zero vector, was it different from the last non zero vector?
-            if (!is_equal_mv(&mv, &lastmv))
-              ++new_mv_count;
-            lastmv = mv;
-
-            // Does the row vector point inwards or outwards?
-            if (mb_row < cm->mb_rows / 2) {
-              if (mv.row > 0)
-                --sum_in_vectors;
-              else if (mv.row < 0)
-                ++sum_in_vectors;
-            } else if (mb_row > cm->mb_rows / 2) {
-              if (mv.row > 0)
-                ++sum_in_vectors;
-              else if (mv.row < 0)
-                --sum_in_vectors;
-            }
-
-            // Does the col vector point inwards or outwards?
-            if (mb_col < cm->mb_cols / 2) {
-              if (mv.col > 0)
-                --sum_in_vectors;
-              else if (mv.col < 0)
-                ++sum_in_vectors;
-            } else if (mb_col > cm->mb_cols / 2) {
-              if (mv.col > 0)
-                ++sum_in_vectors;
-              else if (mv.col < 0)
-                --sum_in_vectors;
-            }
-          }
-        }
-      } else {
-        sr_coded_error += (int64_t)this_error;
-      }
-      coded_error += (int64_t)this_error;
-
-      // Adjust to the next column of MBs.
-      x->plane[0].src.buf += 16;
-      x->plane[1].src.buf += uv_mb_height;
-      x->plane[2].src.buf += uv_mb_height;
-
-      recon_yoffset += 16;
-      recon_uvoffset += uv_mb_height;
-    }
-
-    // Adjust to the next row of MBs.
-    x->plane[0].src.buf += 16 * x->plane[0].src.stride - 16 * cm->mb_cols;
-    x->plane[1].src.buf += uv_mb_height * x->plane[1].src.stride -
-                           uv_mb_height * cm->mb_cols;
-    x->plane[2].src.buf += uv_mb_height * x->plane[1].src.stride -
-                           uv_mb_height * cm->mb_cols;
-
-    vpx_clear_system_state();
-  }
-
-  // Clamp the image start to rows/2. This number of rows is discarded top
-  // and bottom as dead data so rows / 2 means the frame is blank.
-  if ((image_data_start_row > cm->mb_rows / 2) ||
-      (image_data_start_row == INVALID_ROW)) {
-    image_data_start_row = cm->mb_rows / 2;
-  }
-  // Exclude any image dead zone
-  if (image_data_start_row > 0) {
-    intra_skip_count =
-        VPXMAX(0, intra_skip_count - (image_data_start_row * cm->mb_cols * 2));
-  }
-
-  {
-    FIRSTPASS_STATS fps;
-    // The minimum error here insures some bit allocation to frames even
-    // in static regions. The allocation per MB declines for larger formats
-    // where the typical "real" energy per MB also falls.
-    // Initial estimate here uses sqrt(mbs) to define the min_err, where the
-    // number of mbs is proportional to the image area.
-    const int num_mbs = (cpi->oxcf.resize_mode != RESIZE_NONE)
-                        ? cpi->initial_mbs : cpi->common.MBs;
-    const double min_err = 200 * sqrt(num_mbs);
-
-    intra_factor = intra_factor / (double)num_mbs;
-    brightness_factor = brightness_factor / (double)num_mbs;
-    fps.weight = intra_factor * brightness_factor;
-
-    fps.frame = cm->current_video_frame;
-    fps.spatial_layer_id = cpi->svc.spatial_layer_id;
-    fps.coded_error = (double)(coded_error >> 8) + min_err;
-    fps.sr_coded_error = (double)(sr_coded_error >> 8) + min_err;
-    fps.intra_error = (double)(intra_error >> 8) + min_err;
-    fps.count = 1.0;
-    fps.pcnt_inter = (double)intercount / num_mbs;
-    fps.pcnt_second_ref = (double)second_ref_count / num_mbs;
-    fps.pcnt_neutral = (double)neutral_count / num_mbs;
-    fps.intra_skip_pct = (double)intra_skip_count / num_mbs;
-    fps.intra_smooth_pct = (double)intra_smooth_count / num_mbs;
-    fps.inactive_zone_rows = (double)image_data_start_row;
-    // Currently set to 0 as most issues relate to letter boxing.
-    fps.inactive_zone_cols = (double)0;
-
-    if (mvcount > 0) {
-      fps.MVr = (double)sum_mvr / mvcount;
-      fps.mvr_abs = (double)sum_mvr_abs / mvcount;
-      fps.MVc = (double)sum_mvc / mvcount;
-      fps.mvc_abs = (double)sum_mvc_abs / mvcount;
-      fps.MVrv = ((double)sum_mvrs -
-                  ((double)sum_mvr * sum_mvr / mvcount)) / mvcount;
-      fps.MVcv = ((double)sum_mvcs -
-                  ((double)sum_mvc * sum_mvc / mvcount)) / mvcount;
-      fps.mv_in_out_count = (double)sum_in_vectors / (mvcount * 2);
-      fps.new_mv_count = new_mv_count;
-      fps.pcnt_motion = (double)mvcount / num_mbs;
-    } else {
-      fps.MVr = 0.0;
-      fps.mvr_abs = 0.0;
-      fps.MVc = 0.0;
-      fps.mvc_abs = 0.0;
-      fps.MVrv = 0.0;
-      fps.MVcv = 0.0;
-      fps.mv_in_out_count = 0.0;
-      fps.new_mv_count = 0.0;
-      fps.pcnt_motion = 0.0;
-    }
-
-    // Dont allow a value of 0 for duration.
-    // (Section duration is also defaulted to minimum of 1.0).
-    fps.duration = VPXMAX(1.0, (double)(source->ts_end - source->ts_start));
-
-    // Don't want to do output stats with a stack variable!
-    twopass->this_frame_stats = fps;
-    output_stats(&twopass->this_frame_stats, cpi->output_pkt_list);
-    accumulate_stats(&twopass->total_stats, &fps);
-
-#if CONFIG_FP_MB_STATS
-    if (cpi->use_fp_mb_stats) {
-      output_fpmb_stats(twopass->frame_mb_stats_buf, cm, cpi->output_pkt_list);
-    }
-#endif
-  }
-
-  // Copy the previous Last Frame back into gf and and arf buffers if
-  // the prediction is good enough... but also don't allow it to lag too far.
-  if ((twopass->sr_update_lag > 3) ||
-      ((cm->current_video_frame > 0) &&
-       (twopass->this_frame_stats.pcnt_inter > 0.20) &&
-       ((twopass->this_frame_stats.intra_error /
-         DOUBLE_DIVIDE_CHECK(twopass->this_frame_stats.coded_error)) > 2.0))) {
-    if (gld_yv12 != NULL) {
-      ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->gld_fb_idx],
-                 cm->ref_frame_map[cpi->lst_fb_idx]);
-    }
-    twopass->sr_update_lag = 1;
-  } else {
-    ++twopass->sr_update_lag;
-  }
-
-  vpx_extend_frame_borders(new_yv12);
-
-  if (lc != NULL) {
-    vp9_update_reference_frames(cpi);
-  } else {
-    // The frame we just compressed now becomes the last frame.
-    ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->lst_fb_idx],
-               cm->new_fb_idx);
-  }
-
-  // Special case for the first frame. Copy into the GF buffer as a second
-  // reference.
-  if (cm->current_video_frame == 0 && cpi->gld_fb_idx != INVALID_IDX &&
-      lc == NULL) {
-    ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->gld_fb_idx],
-               cm->ref_frame_map[cpi->lst_fb_idx]);
-  }
-
-  // Use this to see what the first pass reconstruction looks like.
-  if (0) {
-    char filename[512];
-    FILE *recon_file;
-    snprintf(filename, sizeof(filename), "enc%04d.yuv",
-             (int)cm->current_video_frame);
-
-    if (cm->current_video_frame == 0)
-      recon_file = fopen(filename, "wb");
-    else
-      recon_file = fopen(filename, "ab");
-
-    (void)fwrite(lst_yv12->buffer_alloc, lst_yv12->frame_size, 1, recon_file);
-    fclose(recon_file);
-  }
-
-  ++cm->current_video_frame;
-  if (cpi->use_svc)
-    vp9_inc_frame_in_layer(cpi);
-}
-
-static double calc_correction_factor(double err_per_mb,
-                                     double err_divisor,
-                                     double pt_low,
-                                     double pt_high,
-                                     int q,
-                                     vpx_bit_depth_t bit_depth) {
-  const double error_term = err_per_mb / err_divisor;
-
-  // Adjustment based on actual quantizer to power term.
-  const double power_term =
-      VPXMIN(vp9_convert_qindex_to_q(q, bit_depth) * 0.01 + pt_low, pt_high);
-
-  // Calculate correction factor.
-  if (power_term < 1.0)
-    assert(error_term >= 0.0);
-
-  return fclamp(pow(error_term, power_term), 0.05, 5.0);
-}
-
-#define ERR_DIVISOR         115.0
-static int get_twopass_worst_quality(VP9_COMP *cpi,
-                                     const double section_err,
-                                     double inactive_zone,
-                                     int section_target_bandwidth) {
-  const RATE_CONTROL *const rc = &cpi->rc;
-  const VP9EncoderConfig *const oxcf = &cpi->oxcf;
-  TWO_PASS *const twopass = &cpi->twopass;
-
-  // Clamp the target rate to VBR min / max limts.
-  const int target_rate =
-      vp9_rc_clamp_pframe_target_size(cpi, section_target_bandwidth);
-
-  inactive_zone = fclamp(inactive_zone, 0.0, 1.0);
-
-  if (target_rate <= 0) {
-    return rc->worst_quality;  // Highest value allowed
-  } else {
-    const int num_mbs = (cpi->oxcf.resize_mode != RESIZE_NONE)
-                        ? cpi->initial_mbs : cpi->common.MBs;
-    const int active_mbs = VPXMAX(1, num_mbs - (int)(num_mbs * inactive_zone));
-    const double av_err_per_mb = section_err / active_mbs;
-    const double speed_term = 1.0 + 0.04 * oxcf->speed;
-    double last_group_rate_err;
-    const int target_norm_bits_per_mb = ((uint64_t)target_rate <<
-                                         BPER_MB_NORMBITS) / active_mbs;
-    int q;
-    int is_svc_upper_layer = 0;
-
-    if (is_two_pass_svc(cpi) && cpi->svc.spatial_layer_id > 0)
-      is_svc_upper_layer = 1;
-
-    // based on recent history adjust expectations of bits per macroblock.
-    last_group_rate_err = (double)twopass->rolling_arf_group_actual_bits /
-        DOUBLE_DIVIDE_CHECK((double)twopass->rolling_arf_group_target_bits);
-    last_group_rate_err =
-        VPXMAX(0.25, VPXMIN(4.0, last_group_rate_err));
-    twopass->bpm_factor *= (3.0 + last_group_rate_err) / 4.0;
-    twopass->bpm_factor =
-        VPXMAX(0.25, VPXMIN(4.0, twopass->bpm_factor));
-
-    // Try and pick a max Q that will be high enough to encode the
-    // content at the given rate.
-    for (q = rc->best_quality; q < rc->worst_quality; ++q) {
-      const double factor =
-          calc_correction_factor(av_err_per_mb,
-                                 ERR_DIVISOR,
-                                 is_svc_upper_layer ? SVC_FACTOR_PT_LOW :
-                                 FACTOR_PT_LOW, FACTOR_PT_HIGH, q,
-                                 cpi->common.bit_depth);
-      const int bits_per_mb =
-        vp9_rc_bits_per_mb(INTER_FRAME, q,
-                           factor * speed_term * cpi->twopass.bpm_factor,
-                           cpi->common.bit_depth);
-      if (bits_per_mb <= target_norm_bits_per_mb)
-        break;
-    }
-
-    // Restriction on active max q for constrained quality mode.
-    if (cpi->oxcf.rc_mode == VPX_CQ)
-      q = VPXMAX(q, oxcf->cq_level);
-    return q;
-  }
-}
-
-static void setup_rf_level_maxq(VP9_COMP *cpi) {
-  int i;
-  RATE_CONTROL *const rc = &cpi->rc;
-  for (i = INTER_NORMAL; i < RATE_FACTOR_LEVELS; ++i) {
-    int qdelta = vp9_frame_type_qdelta(cpi, i, rc->worst_quality);
-    rc->rf_level_maxq[i] = VPXMAX(rc->worst_quality + qdelta, rc->best_quality);
-  }
-}
-
-static void init_subsampling(VP9_COMP *cpi) {
-  const VP9_COMMON *const cm = &cpi->common;
-  RATE_CONTROL *const rc = &cpi->rc;
-  const int w = cm->width;
-  const int h = cm->height;
-  int i;
-
-  for (i = 0; i < FRAME_SCALE_STEPS; ++i) {
-    // Note: Frames with odd-sized dimensions may result from this scaling.
-    rc->frame_width[i] = (w * 16) / frame_scale_factor[i];
-    rc->frame_height[i] = (h * 16) / frame_scale_factor[i];
-  }
-
-  setup_rf_level_maxq(cpi);
-}
-
-void calculate_coded_size(VP9_COMP *cpi,
-                          int *scaled_frame_width,
-                          int *scaled_frame_height) {
-  RATE_CONTROL *const rc = &cpi->rc;
-  *scaled_frame_width = rc->frame_width[rc->frame_size_selector];
-  *scaled_frame_height = rc->frame_height[rc->frame_size_selector];
-}
-
-void vp9_init_second_pass(VP9_COMP *cpi) {
-  SVC *const svc = &cpi->svc;
-  const VP9EncoderConfig *const oxcf = &cpi->oxcf;
-  const int is_two_pass_svc = (svc->number_spatial_layers > 1) ||
-                              (svc->number_temporal_layers > 1);
-  RATE_CONTROL *const rc = &cpi->rc;
-  TWO_PASS *const twopass = is_two_pass_svc ?
-      &svc->layer_context[svc->spatial_layer_id].twopass : &cpi->twopass;
-  double frame_rate;
-  FIRSTPASS_STATS *stats;
-
-  zero_stats(&twopass->total_stats);
-  zero_stats(&twopass->total_left_stats);
-
-  if (!twopass->stats_in_end)
-    return;
-
-  stats = &twopass->total_stats;
-
-  *stats = *twopass->stats_in_end;
-  twopass->total_left_stats = *stats;
-
-  frame_rate = 10000000.0 * stats->count / stats->duration;
-  // Each frame can have a different duration, as the frame rate in the source
-  // isn't guaranteed to be constant. The frame rate prior to the first frame
-  // encoded in the second pass is a guess. However, the sum duration is not.
-  // It is calculated based on the actual durations of all frames from the
-  // first pass.
-
-  if (is_two_pass_svc) {
-    vp9_update_spatial_layer_framerate(cpi, frame_rate);
-    twopass->bits_left = (int64_t)(stats->duration *
-        svc->layer_context[svc->spatial_layer_id].target_bandwidth /
-        10000000.0);
-  } else {
-    vp9_new_framerate(cpi, frame_rate);
-    twopass->bits_left = (int64_t)(stats->duration * oxcf->target_bandwidth /
-                             10000000.0);
-  }
-
-  // This variable monitors how far behind the second ref update is lagging.
-  twopass->sr_update_lag = 1;
-
-  // Scan the first pass file and calculate a modified total error based upon
-  // the bias/power function used to allocate bits.
-  {
-    const double avg_error = stats->coded_error /
-                             DOUBLE_DIVIDE_CHECK(stats->count);
-    const FIRSTPASS_STATS *s = twopass->stats_in;
-    double modified_error_total = 0.0;
-    twopass->modified_error_min = (avg_error *
-                                      oxcf->two_pass_vbrmin_section) / 100;
-    twopass->modified_error_max = (avg_error *
-                                      oxcf->two_pass_vbrmax_section) / 100;
-    while (s < twopass->stats_in_end) {
-      modified_error_total += calculate_modified_err(cpi, twopass, oxcf, s);
-      ++s;
-    }
-    twopass->modified_error_left = modified_error_total;
-  }
-
-  // Reset the vbr bits off target counters
-  rc->vbr_bits_off_target = 0;
-  rc->vbr_bits_off_target_fast = 0;
-  rc->rate_error_estimate = 0;
-
-  // Static sequence monitor variables.
-  twopass->kf_zeromotion_pct = 100;
-  twopass->last_kfgroup_zeromotion_pct = 100;
-
-  // Initialize bits per macro_block estimate correction factor.
-  twopass->bpm_factor = 1.0;
-  // Initiallize actual and target bits counters for ARF groups so that
-  // at the start we have a neutral bpm adjustment.
-  twopass->rolling_arf_group_target_bits = 1;
-  twopass->rolling_arf_group_actual_bits = 1;
-
-  if (oxcf->resize_mode != RESIZE_NONE) {
-    init_subsampling(cpi);
-  }
-}
-
-#define SR_DIFF_PART 0.0015
-#define INTRA_PART 0.005
-#define DEFAULT_DECAY_LIMIT 0.75
-#define LOW_SR_DIFF_TRHESH 0.1
-#define SR_DIFF_MAX 128.0
-#define LOW_CODED_ERR_PER_MB 10.0
-#define NCOUNT_FRAME_II_THRESH 6.0
-
-static double get_sr_decay_rate(const VP9_COMP *cpi,
-                                const FIRSTPASS_STATS *frame) {
-  const int num_mbs = (cpi->oxcf.resize_mode != RESIZE_NONE)
-                      ? cpi->initial_mbs : cpi->common.MBs;
-  double sr_diff =
-      (frame->sr_coded_error - frame->coded_error) / num_mbs;
-  double sr_decay = 1.0;
-  double modified_pct_inter;
-  double modified_pcnt_intra;
-  const double motion_amplitude_part =
-      frame->pcnt_motion *
-      ((frame->mvc_abs + frame->mvr_abs) /
-       (cpi->initial_height + cpi->initial_width));
-
-  modified_pct_inter = frame->pcnt_inter;
-  if (((frame->coded_error / num_mbs) > LOW_CODED_ERR_PER_MB) &&
-      ((frame->intra_error / DOUBLE_DIVIDE_CHECK(frame->coded_error)) <
-       (double)NCOUNT_FRAME_II_THRESH)) {
-    modified_pct_inter = frame->pcnt_inter - frame->pcnt_neutral;
-  }
-  modified_pcnt_intra = 100 * (1.0 - modified_pct_inter);
-
-
-  if ((sr_diff > LOW_SR_DIFF_TRHESH)) {
-    sr_diff = VPXMIN(sr_diff, SR_DIFF_MAX);
-    sr_decay = 1.0 - (SR_DIFF_PART * sr_diff) -
-               motion_amplitude_part -
-               (INTRA_PART * modified_pcnt_intra);
-  }
-  return VPXMAX(sr_decay, VPXMIN(DEFAULT_DECAY_LIMIT, modified_pct_inter));
-}
-
-// This function gives an estimate of how badly we believe the prediction
-// quality is decaying from frame to frame.
-static double get_zero_motion_factor(const VP9_COMP *cpi,
-                                     const FIRSTPASS_STATS *frame) {
-  const double zero_motion_pct = frame->pcnt_inter -
-                                 frame->pcnt_motion;
-  double sr_decay = get_sr_decay_rate(cpi, frame);
-  return VPXMIN(sr_decay, zero_motion_pct);
-}
-
-#define ZM_POWER_FACTOR 0.75
-
-static double get_prediction_decay_rate(const VP9_COMP *cpi,
-                                        const FIRSTPASS_STATS *next_frame) {
-  const double sr_decay_rate = get_sr_decay_rate(cpi, next_frame);
-  const double zero_motion_factor =
-    (0.95 * pow((next_frame->pcnt_inter - next_frame->pcnt_motion),
-                ZM_POWER_FACTOR));
-
-  return VPXMAX(zero_motion_factor,
-                (sr_decay_rate + ((1.0 - sr_decay_rate) * zero_motion_factor)));
-}
-
-// Function to test for a condition where a complex transition is followed
-// by a static section. For example in slide shows where there is a fade
-// between slides. This is to help with more optimal kf and gf positioning.
-static int detect_transition_to_still(VP9_COMP *cpi,
-                                      int frame_interval, int still_interval,
-                                      double loop_decay_rate,
-                                      double last_decay_rate) {
-  TWO_PASS *const twopass = &cpi->twopass;
-  RATE_CONTROL *const rc = &cpi->rc;
-
-  // Break clause to detect very still sections after motion
-  // For example a static image after a fade or other transition
-  // instead of a clean scene cut.
-  if (frame_interval > rc->min_gf_interval &&
-      loop_decay_rate >= 0.999 &&
-      last_decay_rate < 0.9) {
-    int j;
-
-    // Look ahead a few frames to see if static condition persists...
-    for (j = 0; j < still_interval; ++j) {
-      const FIRSTPASS_STATS *stats = &twopass->stats_in[j];
-      if (stats >= twopass->stats_in_end)
-        break;
-
-      if (stats->pcnt_inter - stats->pcnt_motion < 0.999)
-        break;
-    }
-
-    // Only if it does do we signal a transition to still.
-    return j == still_interval;
-  }
-
-  return 0;
-}
-
-// This function detects a flash through the high relative pcnt_second_ref
-// score in the frame following a flash frame. The offset passed in should
-// reflect this.
-static int detect_flash(const TWO_PASS *twopass, int offset) {
-  const FIRSTPASS_STATS *const next_frame = read_frame_stats(twopass, offset);
-
-  // What we are looking for here is a situation where there is a
-  // brief break in prediction (such as a flash) but subsequent frames
-  // are reasonably well predicted by an earlier (pre flash) frame.
-  // The recovery after a flash is indicated by a high pcnt_second_ref
-  // compared to pcnt_inter.
-  return next_frame != NULL &&
-         next_frame->pcnt_second_ref > next_frame->pcnt_inter &&
-         next_frame->pcnt_second_ref >= 0.5;
-}
-
-// Update the motion related elements to the GF arf boost calculation.
-static void accumulate_frame_motion_stats(const FIRSTPASS_STATS *stats,
-                                          double *mv_in_out,
-                                          double *mv_in_out_accumulator,
-                                          double *abs_mv_in_out_accumulator,
-                                          double *mv_ratio_accumulator) {
-  const double pct = stats->pcnt_motion;
-
-  // Accumulate Motion In/Out of frame stats.
-  *mv_in_out = stats->mv_in_out_count * pct;
-  *mv_in_out_accumulator += *mv_in_out;
-  *abs_mv_in_out_accumulator += fabs(*mv_in_out);
-
-  // Accumulate a measure of how uniform (or conversely how random) the motion
-  // field is (a ratio of abs(mv) / mv).
-  if (pct > 0.05) {
-    const double mvr_ratio = fabs(stats->mvr_abs) /
-                                 DOUBLE_DIVIDE_CHECK(fabs(stats->MVr));
-    const double mvc_ratio = fabs(stats->mvc_abs) /
-                                 DOUBLE_DIVIDE_CHECK(fabs(stats->MVc));
-
-    *mv_ratio_accumulator += pct * (mvr_ratio < stats->mvr_abs ?
-                                       mvr_ratio : stats->mvr_abs);
-    *mv_ratio_accumulator += pct * (mvc_ratio < stats->mvc_abs ?
-                                       mvc_ratio : stats->mvc_abs);
-  }
-}
-
-#define BASELINE_ERR_PER_MB 1000.0
-static double calc_frame_boost(VP9_COMP *cpi,
-                               const FIRSTPASS_STATS *this_frame,
-                               double this_frame_mv_in_out,
-                               double max_boost) {
-  double frame_boost;
-  const double lq =
-    vp9_convert_qindex_to_q(cpi->rc.avg_frame_qindex[INTER_FRAME],
-                            cpi->common.bit_depth);
-  const double boost_q_correction = VPXMIN((0.5 + (lq * 0.015)), 1.5);
-  int num_mbs = (cpi->oxcf.resize_mode != RESIZE_NONE)
-                ? cpi->initial_mbs : cpi->common.MBs;
-
-  // Correct for any inactive region in the image
-  num_mbs = (int)VPXMAX(1, num_mbs * calculate_active_area(cpi, this_frame));
-
-  // Underlying boost factor is based on inter error ratio.
-  frame_boost = (BASELINE_ERR_PER_MB * num_mbs) /
-                DOUBLE_DIVIDE_CHECK(this_frame->coded_error);
-  frame_boost = frame_boost * BOOST_FACTOR * boost_q_correction;
-
-  // Increase boost for frames where new data coming into frame (e.g. zoom out).
-  // Slightly reduce boost if there is a net balance of motion out of the frame
-  // (zoom in). The range for this_frame_mv_in_out is -1.0 to +1.0.
-  if (this_frame_mv_in_out > 0.0)
-    frame_boost += frame_boost * (this_frame_mv_in_out * 2.0);
-  // In the extreme case the boost is halved.
-  else
-    frame_boost += frame_boost * (this_frame_mv_in_out / 2.0);
-
-  return VPXMIN(frame_boost, max_boost * boost_q_correction);
-}
-
-static int calc_arf_boost(VP9_COMP *cpi, int offset,
-                          int f_frames, int b_frames,
-                          int *f_boost, int *b_boost) {
-  TWO_PASS *const twopass = &cpi->twopass;
-  int i;
-  double boost_score = 0.0;
-  double mv_ratio_accumulator = 0.0;
-  double decay_accumulator = 1.0;
-  double this_frame_mv_in_out = 0.0;
-  double mv_in_out_accumulator = 0.0;
-  double abs_mv_in_out_accumulator = 0.0;
-  int arf_boost;
-  int flash_detected = 0;
-
-  // Search forward from the proposed arf/next gf position.
-  for (i = 0; i < f_frames; ++i) {
-    const FIRSTPASS_STATS *this_frame = read_frame_stats(twopass, i + offset);
-    if (this_frame == NULL)
-      break;
-
-    // Update the motion related elements to the boost calculation.
-    accumulate_frame_motion_stats(this_frame,
-                                  &this_frame_mv_in_out, &mv_in_out_accumulator,
-                                  &abs_mv_in_out_accumulator,
-                                  &mv_ratio_accumulator);
-
-    // We want to discount the flash frame itself and the recovery
-    // frame that follows as both will have poor scores.
-    flash_detected = detect_flash(twopass, i + offset) ||
-                     detect_flash(twopass, i + offset + 1);
-
-    // Accumulate the effect of prediction quality decay.
-    if (!flash_detected) {
-      decay_accumulator *= get_prediction_decay_rate(cpi, this_frame);
-      decay_accumulator = decay_accumulator < MIN_DECAY_FACTOR
-                          ? MIN_DECAY_FACTOR : decay_accumulator;
-    }
-
-    boost_score += decay_accumulator * calc_frame_boost(cpi, this_frame,
-                                                        this_frame_mv_in_out,
-                                                        GF_MAX_BOOST);
-  }
-
-  *f_boost = (int)boost_score;
-
-  // Reset for backward looking loop.
-  boost_score = 0.0;
-  mv_ratio_accumulator = 0.0;
-  decay_accumulator = 1.0;
-  this_frame_mv_in_out = 0.0;
-  mv_in_out_accumulator = 0.0;
-  abs_mv_in_out_accumulator = 0.0;
-
-  // Search backward towards last gf position.
-  for (i = -1; i >= -b_frames; --i) {
-    const FIRSTPASS_STATS *this_frame = read_frame_stats(twopass, i + offset);
-    if (this_frame == NULL)
-      break;
-
-    // Update the motion related elements to the boost calculation.
-    accumulate_frame_motion_stats(this_frame,
-                                  &this_frame_mv_in_out, &mv_in_out_accumulator,
-                                  &abs_mv_in_out_accumulator,
-                                  &mv_ratio_accumulator);
-
-    // We want to discount the the flash frame itself and the recovery
-    // frame that follows as both will have poor scores.
-    flash_detected = detect_flash(twopass, i + offset) ||
-                     detect_flash(twopass, i + offset + 1);
-
-    // Cumulative effect of prediction quality decay.
-    if (!flash_detected) {
-      decay_accumulator *= get_prediction_decay_rate(cpi, this_frame);
-      decay_accumulator = decay_accumulator < MIN_DECAY_FACTOR
-                              ? MIN_DECAY_FACTOR : decay_accumulator;
-    }
-
-    boost_score += decay_accumulator * calc_frame_boost(cpi, this_frame,
-                                                        this_frame_mv_in_out,
-                                                        GF_MAX_BOOST);
-  }
-  *b_boost = (int)boost_score;
-
-  arf_boost = (*f_boost + *b_boost);
-  if (arf_boost < ((b_frames + f_frames) * 20))
-    arf_boost = ((b_frames + f_frames) * 20);
-  arf_boost = VPXMAX(arf_boost, MIN_ARF_GF_BOOST);
-
-  return arf_boost;
-}
-
-// Calculate a section intra ratio used in setting max loop filter.
-static int calculate_section_intra_ratio(const FIRSTPASS_STATS *begin,
-                                         const FIRSTPASS_STATS *end,
-                                         int section_length) {
-  const FIRSTPASS_STATS *s = begin;
-  double intra_error = 0.0;
-  double coded_error = 0.0;
-  int i = 0;
-
-  while (s < end && i < section_length) {
-    intra_error += s->intra_error;
-    coded_error += s->coded_error;
-    ++s;
-    ++i;
-  }
-
-  return (int)(intra_error / DOUBLE_DIVIDE_CHECK(coded_error));
-}
-
-// Calculate the total bits to allocate in this GF/ARF group.
-static int64_t calculate_total_gf_group_bits(VP9_COMP *cpi,
-                                             double gf_group_err) {
-  const RATE_CONTROL *const rc = &cpi->rc;
-  const TWO_PASS *const twopass = &cpi->twopass;
-  const int max_bits = frame_max_bits(rc, &cpi->oxcf);
-  int64_t total_group_bits;
-
-  // Calculate the bits to be allocated to the group as a whole.
-  if ((twopass->kf_group_bits > 0) && (twopass->kf_group_error_left > 0)) {
-    total_group_bits = (int64_t)(twopass->kf_group_bits *
-                                 (gf_group_err / twopass->kf_group_error_left));
-  } else {
-    total_group_bits = 0;
-  }
-
-  // Clamp odd edge cases.
-  total_group_bits = (total_group_bits < 0) ?
-     0 : (total_group_bits > twopass->kf_group_bits) ?
-     twopass->kf_group_bits : total_group_bits;
-
-  // Clip based on user supplied data rate variability limit.
-  if (total_group_bits > (int64_t)max_bits * rc->baseline_gf_interval)
-    total_group_bits = (int64_t)max_bits * rc->baseline_gf_interval;
-
-  return total_group_bits;
-}
-
-// Calculate the number bits extra to assign to boosted frames in a group.
-static int calculate_boost_bits(int frame_count,
-                                int boost, int64_t total_group_bits) {
-  int allocation_chunks;
-
-  // return 0 for invalid inputs (could arise e.g. through rounding errors)
-  if (!boost || (total_group_bits <= 0) || (frame_count <= 0) )
-    return 0;
-
-  allocation_chunks = (frame_count * 100) + boost;
-
-  // Prevent overflow.
-  if (boost > 1023) {
-    int divisor = boost >> 10;
-    boost /= divisor;
-    allocation_chunks /= divisor;
-  }
-
-  // Calculate the number of extra bits for use in the boosted frame or frames.
-  return VPXMAX((int)(((int64_t)boost * total_group_bits) / allocation_chunks),
-                0);
-}
-
-// Current limit on maximum number of active arfs in a GF/ARF group.
-#define MAX_ACTIVE_ARFS 2
-#define ARF_SLOT1 2
-#define ARF_SLOT2 3
-// This function indirects the choice of buffers for arfs.
-// At the moment the values are fixed but this may change as part of
-// the integration process with other codec features that swap buffers around.
-static void get_arf_buffer_indices(unsigned char *arf_buffer_indices) {
-  arf_buffer_indices[0] = ARF_SLOT1;
-  arf_buffer_indices[1] = ARF_SLOT2;
-}
-
-static void allocate_gf_group_bits(VP9_COMP *cpi, int64_t gf_group_bits,
-                                   double group_error, int gf_arf_bits) {
-  RATE_CONTROL *const rc = &cpi->rc;
-  const VP9EncoderConfig *const oxcf = &cpi->oxcf;
-  TWO_PASS *const twopass = &cpi->twopass;
-  GF_GROUP *const gf_group = &twopass->gf_group;
-  FIRSTPASS_STATS frame_stats;
-  int i;
-  int frame_index = 1;
-  int target_frame_size;
-  int key_frame;
-  const int max_bits = frame_max_bits(&cpi->rc, &cpi->oxcf);
-  int64_t total_group_bits = gf_group_bits;
-  double modified_err = 0.0;
-  double err_fraction;
-  int mid_boost_bits = 0;
-  int mid_frame_idx;
-  unsigned char arf_buffer_indices[MAX_ACTIVE_ARFS];
-  int alt_frame_index = frame_index;
-  int has_temporal_layers = is_two_pass_svc(cpi) &&
-                            cpi->svc.number_temporal_layers > 1;
-
-  // Only encode alt reference frame in temporal base layer.
-  if (has_temporal_layers)
-    alt_frame_index = cpi->svc.number_temporal_layers;
-
-  key_frame = cpi->common.frame_type == KEY_FRAME ||
-              vp9_is_upper_layer_key_frame(cpi);
-
-  get_arf_buffer_indices(arf_buffer_indices);
-
-  // For key frames the frame target rate is already set and it
-  // is also the golden frame.
-  if (!key_frame) {
-    if (rc->source_alt_ref_active) {
-      gf_group->update_type[0] = OVERLAY_UPDATE;
-      gf_group->rf_level[0] = INTER_NORMAL;
-      gf_group->bit_allocation[0] = 0;
-    } else {
-      gf_group->update_type[0] = GF_UPDATE;
-      gf_group->rf_level[0] = GF_ARF_STD;
-      gf_group->bit_allocation[0] = gf_arf_bits;
-    }
-    gf_group->arf_update_idx[0] = arf_buffer_indices[0];
-    gf_group->arf_ref_idx[0] = arf_buffer_indices[0];
-
-    // Step over the golden frame / overlay frame
-    if (EOF == input_stats(twopass, &frame_stats))
-      return;
-  }
-
-  // Deduct the boost bits for arf (or gf if it is not a key frame)
-  // from the group total.
-  if (rc->source_alt_ref_pending || !key_frame)
-    total_group_bits -= gf_arf_bits;
-
-  // Store the bits to spend on the ARF if there is one.
-  if (rc->source_alt_ref_pending) {
-    gf_group->update_type[alt_frame_index] = ARF_UPDATE;
-    gf_group->rf_level[alt_frame_index] = GF_ARF_STD;
-    gf_group->bit_allocation[alt_frame_index] = gf_arf_bits;
-
-    if (has_temporal_layers)
-      gf_group->arf_src_offset[alt_frame_index] =
-          (unsigned char)(rc->baseline_gf_interval -
-                          cpi->svc.number_temporal_layers);
-    else
-      gf_group->arf_src_offset[alt_frame_index] =
-          (unsigned char)(rc->baseline_gf_interval - 1);
-
-    gf_group->arf_update_idx[alt_frame_index] = arf_buffer_indices[0];
-    gf_group->arf_ref_idx[alt_frame_index] =
-      arf_buffer_indices[cpi->multi_arf_last_grp_enabled &&
-                         rc->source_alt_ref_active];
-    if (!has_temporal_layers)
-      ++frame_index;
-
-    if (cpi->multi_arf_enabled) {
-      // Set aside a slot for a level 1 arf.
-      gf_group->update_type[frame_index] = ARF_UPDATE;
-      gf_group->rf_level[frame_index] = GF_ARF_LOW;
-      gf_group->arf_src_offset[frame_index] =
-        (unsigned char)((rc->baseline_gf_interval >> 1) - 1);
-      gf_group->arf_update_idx[frame_index] = arf_buffer_indices[1];
-      gf_group->arf_ref_idx[frame_index] = arf_buffer_indices[0];
-      ++frame_index;
-    }
-  }
-
-  // Define middle frame
-  mid_frame_idx = frame_index + (rc->baseline_gf_interval >> 1) - 1;
-
-  // Allocate bits to the other frames in the group.
-  for (i = 0; i < rc->baseline_gf_interval - rc->source_alt_ref_pending; ++i) {
-    int arf_idx = 0;
-    if (EOF == input_stats(twopass, &frame_stats))
-      break;
-
-    if (has_temporal_layers && frame_index == alt_frame_index) {
-      ++frame_index;
-    }
-
-    modified_err = calculate_modified_err(cpi, twopass, oxcf, &frame_stats);
-
-    if (group_error > 0)
-      err_fraction = modified_err / DOUBLE_DIVIDE_CHECK(group_error);
-    else
-      err_fraction = 0.0;
-
-    target_frame_size = (int)((double)total_group_bits * err_fraction);
-
-    if (rc->source_alt_ref_pending && cpi->multi_arf_enabled) {
-      mid_boost_bits += (target_frame_size >> 4);
-      target_frame_size -= (target_frame_size >> 4);
-
-      if (frame_index <= mid_frame_idx)
-        arf_idx = 1;
-    }
-    gf_group->arf_update_idx[frame_index] = arf_buffer_indices[arf_idx];
-    gf_group->arf_ref_idx[frame_index] = arf_buffer_indices[arf_idx];
-
-    target_frame_size = clamp(target_frame_size, 0,
-                              VPXMIN(max_bits, (int)total_group_bits));
-
-    gf_group->update_type[frame_index] = LF_UPDATE;
-    gf_group->rf_level[frame_index] = INTER_NORMAL;
-
-    gf_group->bit_allocation[frame_index] = target_frame_size;
-    ++frame_index;
-  }
-
-  // Note:
-  // We need to configure the frame at the end of the sequence + 1 that will be
-  // the start frame for the next group. Otherwise prior to the call to
-  // vp9_rc_get_second_pass_params() the data will be undefined.
-  gf_group->arf_update_idx[frame_index] = arf_buffer_indices[0];
-  gf_group->arf_ref_idx[frame_index] = arf_buffer_indices[0];
-
-  if (rc->source_alt_ref_pending) {
-    gf_group->update_type[frame_index] = OVERLAY_UPDATE;
-    gf_group->rf_level[frame_index] = INTER_NORMAL;
-
-    // Final setup for second arf and its overlay.
-    if (cpi->multi_arf_enabled) {
-      gf_group->bit_allocation[2] =
-          gf_group->bit_allocation[mid_frame_idx] + mid_boost_bits;
-      gf_group->update_type[mid_frame_idx] = OVERLAY_UPDATE;
-      gf_group->bit_allocation[mid_frame_idx] = 0;
-    }
-  } else {
-    gf_group->update_type[frame_index] = GF_UPDATE;
-    gf_group->rf_level[frame_index] = GF_ARF_STD;
-  }
-
-  // Note whether multi-arf was enabled this group for next time.
-  cpi->multi_arf_last_grp_enabled = cpi->multi_arf_enabled;
-}
-
-// Analyse and define a gf/arf group.
-static void define_gf_group(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) {
-  VP9_COMMON *const cm = &cpi->common;
-  RATE_CONTROL *const rc = &cpi->rc;
-  VP9EncoderConfig *const oxcf = &cpi->oxcf;
-  TWO_PASS *const twopass = &cpi->twopass;
-  FIRSTPASS_STATS next_frame;
-  const FIRSTPASS_STATS *const start_pos = twopass->stats_in;
-  int i;
-
-  double boost_score = 0.0;
-  double old_boost_score = 0.0;
-  double gf_group_err = 0.0;
-  double gf_group_raw_error = 0.0;
-  double gf_group_skip_pct = 0.0;
-  double gf_group_inactive_zone_rows = 0.0;
-  double gf_first_frame_err = 0.0;
-  double mod_frame_err = 0.0;
-
-  double mv_ratio_accumulator = 0.0;
-  double decay_accumulator = 1.0;
-  double zero_motion_accumulator = 1.0;
-
-  double loop_decay_rate = 1.00;
-  double last_loop_decay_rate = 1.00;
-
-  double this_frame_mv_in_out = 0.0;
-  double mv_in_out_accumulator = 0.0;
-  double abs_mv_in_out_accumulator = 0.0;
-  double mv_ratio_accumulator_thresh;
-  unsigned int allow_alt_ref = is_altref_enabled(cpi);
-
-  int f_boost = 0;
-  int b_boost = 0;
-  int flash_detected;
-  int active_max_gf_interval;
-  int active_min_gf_interval;
-  int64_t gf_group_bits;
-  double gf_group_error_left;
-  int gf_arf_bits;
-  const int is_key_frame = frame_is_intra_only(cm);
-  const int arf_active_or_kf = is_key_frame || rc->source_alt_ref_active;
-
-  // Reset the GF group data structures unless this is a key
-  // frame in which case it will already have been done.
-  if (is_key_frame == 0) {
-    vp9_zero(twopass->gf_group);
-  }
-
-  vpx_clear_system_state();
-  vp9_zero(next_frame);
-
-  // Load stats for the current frame.
-  mod_frame_err = calculate_modified_err(cpi, twopass, oxcf, this_frame);
-
-  // Note the error of the frame at the start of the group. This will be
-  // the GF frame error if we code a normal gf.
-  gf_first_frame_err = mod_frame_err;
-
-  // If this is a key frame or the overlay from a previous arf then
-  // the error score / cost of this frame has already been accounted for.
-  if (arf_active_or_kf) {
-    gf_group_err -= gf_first_frame_err;
-    gf_group_raw_error -= this_frame->coded_error;
-    gf_group_skip_pct -= this_frame->intra_skip_pct;
-    gf_group_inactive_zone_rows -= this_frame->inactive_zone_rows;
-  }
-
-  // Motion breakout threshold for loop below depends on image size.
-  mv_ratio_accumulator_thresh =
-      (cpi->initial_height + cpi->initial_width) / 4.0;
-
-  // Set a maximum and minimum interval for the GF group.
-  // If the image appears almost completely static we can extend beyond this.
-  {
-    int int_max_q =
-      (int)(vp9_convert_qindex_to_q(twopass->active_worst_quality,
-                                   cpi->common.bit_depth));
-    int int_lbq =
-      (int)(vp9_convert_qindex_to_q(rc->last_boosted_qindex,
-                                   cpi->common.bit_depth));
-    active_min_gf_interval =
-      rc->min_gf_interval + arf_active_or_kf + VPXMIN(2, int_max_q / 200);
-    if (active_min_gf_interval > rc->max_gf_interval)
-      active_min_gf_interval = rc->max_gf_interval;
-
-    if (cpi->multi_arf_allowed) {
-      active_max_gf_interval = rc->max_gf_interval;
-    } else {
-      // The value chosen depends on the active Q range. At low Q we have
-      // bits to spare and are better with a smaller interval and smaller boost.
-      // At high Q when there are few bits to spare we are better with a longer
-      // interval to spread the cost of the GF.
-      active_max_gf_interval =
-        12 + arf_active_or_kf + VPXMIN(4, (int_lbq / 6));
-
-      // We have: active_min_gf_interval <= rc->max_gf_interval
-      if (active_max_gf_interval < active_min_gf_interval)
-        active_max_gf_interval = active_min_gf_interval;
-      else if (active_max_gf_interval > rc->max_gf_interval)
-        active_max_gf_interval = rc->max_gf_interval;
-
-      // Would the active max drop us out just before the near the next kf?
-      if ((active_max_gf_interval <= rc->frames_to_key) &&
-          (active_max_gf_interval >=
-              (rc->frames_to_key - rc->min_gf_interval)))
-        active_max_gf_interval = rc->frames_to_key / 2;
-    }
-  }
-
-  i = 0;
-  while (i < rc->static_scene_max_gf_interval && i < rc->frames_to_key) {
-    ++i;
-
-    // Accumulate error score of frames in this gf group.
-    mod_frame_err = calculate_modified_err(cpi, twopass, oxcf, this_frame);
-    gf_group_err += mod_frame_err;
-    gf_group_raw_error += this_frame->coded_error;
-    gf_group_skip_pct += this_frame->intra_skip_pct;
-    gf_group_inactive_zone_rows += this_frame->inactive_zone_rows;
-
-    if (EOF == input_stats(twopass, &next_frame))
-      break;
-
-    // Test for the case where there is a brief flash but the prediction
-    // quality back to an earlier frame is then restored.
-    flash_detected = detect_flash(twopass, 0);
-
-    // Update the motion related elements to the boost calculation.
-    accumulate_frame_motion_stats(&next_frame,
-                                  &this_frame_mv_in_out, &mv_in_out_accumulator,
-                                  &abs_mv_in_out_accumulator,
-                                  &mv_ratio_accumulator);
-
-    // Accumulate the effect of prediction quality decay.
-    if (!flash_detected) {
-      last_loop_decay_rate = loop_decay_rate;
-      loop_decay_rate = get_prediction_decay_rate(cpi, &next_frame);
-
-      decay_accumulator = decay_accumulator * loop_decay_rate;
-
-      // Monitor for static sections.
-      zero_motion_accumulator = VPXMIN(
-          zero_motion_accumulator, get_zero_motion_factor(cpi, &next_frame));
-
-      // Break clause to detect very still sections after motion. For example,
-      // a static image after a fade or other transition.
-      if (detect_transition_to_still(cpi, i, 5, loop_decay_rate,
-                                     last_loop_decay_rate)) {
-        allow_alt_ref = 0;
-        break;
-      }
-    }
-
-    // Calculate a boost number for this frame.
-    boost_score += decay_accumulator * calc_frame_boost(cpi, &next_frame,
-                                                        this_frame_mv_in_out,
-                                                        GF_MAX_BOOST);
-
-    // Break out conditions.
-    if (
-      // Break at active_max_gf_interval unless almost totally static.
-      ((i >= active_max_gf_interval) &&
-       (zero_motion_accumulator < 0.995)) ||
-      (
-        // Don't break out with a very short interval.
-        (i >= active_min_gf_interval) &&
-        // If possible dont break very close to a kf
-        ((rc->frames_to_key - i) >= rc->min_gf_interval) &&
-        (!flash_detected) &&
-        ((mv_ratio_accumulator > mv_ratio_accumulator_thresh) ||
-         (abs_mv_in_out_accumulator > 3.0) ||
-         (mv_in_out_accumulator < -2.0) ||
-         ((boost_score - old_boost_score) < BOOST_BREAKOUT)))) {
-      boost_score = old_boost_score;
-      break;
-    }
-
-    *this_frame = next_frame;
-    old_boost_score = boost_score;
-  }
-
-  // Was the group length constrained by the requirement for a new KF?
-  rc->constrained_gf_group = (i >= rc->frames_to_key) ? 1 : 0;
-
-  // Should we use the alternate reference frame.
-  if (allow_alt_ref &&
-    (i < cpi->oxcf.lag_in_frames) &&
-    (i >= rc->min_gf_interval)) {
-    // Calculate the boost for alt ref.
-    rc->gfu_boost = calc_arf_boost(cpi, 0, (i - 1), (i - 1), &f_boost,
-      &b_boost);
-    rc->source_alt_ref_pending = 1;
-
-    // Test to see if multi arf is appropriate.
-    cpi->multi_arf_enabled =
-      (cpi->multi_arf_allowed && (rc->baseline_gf_interval >= 6) &&
-      (zero_motion_accumulator < 0.995)) ? 1 : 0;
-  } else {
-    rc->gfu_boost = VPXMAX((int)boost_score, MIN_ARF_GF_BOOST);
-    rc->source_alt_ref_pending = 0;
-  }
-
-  // Set the interval until the next gf.
-  rc->baseline_gf_interval = i - (is_key_frame || rc->source_alt_ref_pending);
-
-  // Only encode alt reference frame in temporal base layer. So
-  // baseline_gf_interval should be multiple of a temporal layer group
-  // (typically the frame distance between two base layer frames)
-  if (is_two_pass_svc(cpi) && cpi->svc.number_temporal_layers > 1) {
-    int count = (1 << (cpi->svc.number_temporal_layers - 1)) - 1;
-    int new_gf_interval = (rc->baseline_gf_interval + count) & (~count);
-    int j;
-    for (j = 0; j < new_gf_interval - rc->baseline_gf_interval; ++j) {
-      if (EOF == input_stats(twopass, this_frame))
-        break;
-      gf_group_err += calculate_modified_err(cpi, twopass, oxcf, this_frame);
-      gf_group_raw_error += this_frame->coded_error;
-      gf_group_skip_pct += this_frame->intra_skip_pct;
-      gf_group_inactive_zone_rows += this_frame->inactive_zone_rows;
-    }
-    rc->baseline_gf_interval = new_gf_interval;
-  }
-
-  rc->frames_till_gf_update_due = rc->baseline_gf_interval;
-
-  // Reset the file position.
-  reset_fpf_position(twopass, start_pos);
-
-  // Calculate the bits to be allocated to the gf/arf group as a whole
-  gf_group_bits = calculate_total_gf_group_bits(cpi, gf_group_err);
-
-  // Calculate an estimate of the maxq needed for the group.
-  // We are more agressive about correcting for sections
-  // where there could be significant overshoot than for easier
-  // sections where we do not wish to risk creating an overshoot
-  // of the allocated bit budget.
-  if ((cpi->oxcf.rc_mode != VPX_Q) && (rc->baseline_gf_interval > 1)) {
-    const int vbr_group_bits_per_frame =
-      (int)(gf_group_bits / rc->baseline_gf_interval);
-    const double group_av_err = gf_group_raw_error  / rc->baseline_gf_interval;
-    const double group_av_skip_pct =
-      gf_group_skip_pct / rc->baseline_gf_interval;
-    const double group_av_inactive_zone =
-      ((gf_group_inactive_zone_rows * 2) /
-       (rc->baseline_gf_interval * (double)cm->mb_rows));
-    int tmp_q =
-        get_twopass_worst_quality(cpi, group_av_err,
-                                  (group_av_skip_pct + group_av_inactive_zone),
-                                  vbr_group_bits_per_frame);
-    twopass->active_worst_quality =
-        (tmp_q + (twopass->active_worst_quality * 3)) >> 2;
-  }
-
-  // Calculate the extra bits to be used for boosted frame(s)
-  gf_arf_bits = calculate_boost_bits(rc->baseline_gf_interval,
-                                     rc->gfu_boost, gf_group_bits);
-
-  // Adjust KF group bits and error remaining.
-  twopass->kf_group_error_left -= (int64_t)gf_group_err;
-
-  // If this is an arf update we want to remove the score for the overlay
-  // frame at the end which will usually be very cheap to code.
-  // The overlay frame has already, in effect, been coded so we want to spread
-  // the remaining bits among the other frames.
-  // For normal GFs remove the score for the GF itself unless this is
-  // also a key frame in which case it has already been accounted for.
-  if (rc->source_alt_ref_pending) {
-    gf_group_error_left = gf_group_err - mod_frame_err;
-  } else if (is_key_frame == 0) {
-    gf_group_error_left = gf_group_err - gf_first_frame_err;
-  } else {
-    gf_group_error_left = gf_group_err;
-  }
-
-  // Allocate bits to each of the frames in the GF group.
-  allocate_gf_group_bits(cpi, gf_group_bits, gf_group_error_left, gf_arf_bits);
-
-  // Reset the file position.
-  reset_fpf_position(twopass, start_pos);
-
-  // Calculate a section intra ratio used in setting max loop filter.
-  if (cpi->common.frame_type != KEY_FRAME) {
-    twopass->section_intra_rating =
-        calculate_section_intra_ratio(start_pos, twopass->stats_in_end,
-                                      rc->baseline_gf_interval);
-  }
-
-  if (oxcf->resize_mode == RESIZE_DYNAMIC) {
-    // Default to starting GF groups at normal frame size.
-    cpi->rc.next_frame_size_selector = UNSCALED;
-  }
-
-  // Reset rolling actual and target bits counters for ARF groups.
-  twopass->rolling_arf_group_target_bits = 0;
-  twopass->rolling_arf_group_actual_bits = 0;
-}
-
-// Threshold for use of the lagging second reference frame. High second ref
-// usage may point to a transient event like a flash or occlusion rather than
-// a real scene cut.
-#define SECOND_REF_USEAGE_THRESH 0.1
-// Minimum % intra coding observed in first pass (1.0 = 100%)
-#define MIN_INTRA_LEVEL 0.25
-// Minimum ratio between the % of intra coding and inter coding in the first
-// pass after discounting neutral blocks (discounting neutral blocks in this
-// way helps catch scene cuts in clips with very flat areas or letter box
-// format clips with image padding.
-#define INTRA_VS_INTER_THRESH 2.0
-// Hard threshold where the first pass chooses intra for almost all blocks.
-// In such a case even if the frame is not a scene cut coding a key frame
-// may be a good option.
-#define VERY_LOW_INTER_THRESH 0.05
-// Maximum threshold for the relative ratio of intra error score vs best
-// inter error score.
-#define KF_II_ERR_THRESHOLD 2.5
-// In real scene cuts there is almost always a sharp change in the intra
-// or inter error score.
-#define ERR_CHANGE_THRESHOLD 0.4
-// For real scene cuts we expect an improvment in the intra inter error
-// ratio in the next frame.
-#define II_IMPROVEMENT_THRESHOLD 3.5
-#define KF_II_MAX 128.0
-
-static int test_candidate_kf(TWO_PASS *twopass,
-                             const FIRSTPASS_STATS *last_frame,
-                             const FIRSTPASS_STATS *this_frame,
-                             const FIRSTPASS_STATS *next_frame) {
-  int is_viable_kf = 0;
-  double pcnt_intra = 1.0 - this_frame->pcnt_inter;
-  double modified_pcnt_inter =
-    this_frame->pcnt_inter - this_frame->pcnt_neutral;
-
-  // Does the frame satisfy the primary criteria of a key frame?
-  // See above for an explanation of the test criteria.
-  // If so, then examine how well it predicts subsequent frames.
-  if ((this_frame->pcnt_second_ref < SECOND_REF_USEAGE_THRESH) &&
-      (next_frame->pcnt_second_ref < SECOND_REF_USEAGE_THRESH) &&
-      ((this_frame->pcnt_inter < VERY_LOW_INTER_THRESH) ||
-       ((pcnt_intra > MIN_INTRA_LEVEL) &&
-        (pcnt_intra > (INTRA_VS_INTER_THRESH * modified_pcnt_inter)) &&
-        ((this_frame->intra_error /
-          DOUBLE_DIVIDE_CHECK(this_frame->coded_error)) <
-          KF_II_ERR_THRESHOLD) &&
-        ((fabs(last_frame->coded_error - this_frame->coded_error) /
-          DOUBLE_DIVIDE_CHECK(this_frame->coded_error) >
-          ERR_CHANGE_THRESHOLD) ||
-         (fabs(last_frame->intra_error - this_frame->intra_error) /
-          DOUBLE_DIVIDE_CHECK(this_frame->intra_error) >
-          ERR_CHANGE_THRESHOLD) ||
-         ((next_frame->intra_error /
-          DOUBLE_DIVIDE_CHECK(next_frame->coded_error)) >
-          II_IMPROVEMENT_THRESHOLD))))) {
-    int i;
-    const FIRSTPASS_STATS *start_pos = twopass->stats_in;
-    FIRSTPASS_STATS local_next_frame = *next_frame;
-    double boost_score = 0.0;
-    double old_boost_score = 0.0;
-    double decay_accumulator = 1.0;
-
-    // Examine how well the key frame predicts subsequent frames.
-    for (i = 0; i < 16; ++i) {
-      double next_iiratio = (BOOST_FACTOR * local_next_frame.intra_error /
-                             DOUBLE_DIVIDE_CHECK(local_next_frame.coded_error));
-
-      if (next_iiratio > KF_II_MAX)
-        next_iiratio = KF_II_MAX;
-
-      // Cumulative effect of decay in prediction quality.
-      if (local_next_frame.pcnt_inter > 0.85)
-        decay_accumulator *= local_next_frame.pcnt_inter;
-      else
-        decay_accumulator *= (0.85 + local_next_frame.pcnt_inter) / 2.0;
-
-      // Keep a running total.
-      boost_score += (decay_accumulator * next_iiratio);
-
-      // Test various breakout clauses.
-      if ((local_next_frame.pcnt_inter < 0.05) ||
-          (next_iiratio < 1.5) ||
-          (((local_next_frame.pcnt_inter -
-             local_next_frame.pcnt_neutral) < 0.20) &&
-           (next_iiratio < 3.0)) ||
-          ((boost_score - old_boost_score) < 3.0) ||
-          (local_next_frame.intra_error < 200)) {
-        break;
-      }
-
-      old_boost_score = boost_score;
-
-      // Get the next frame details
-      if (EOF == input_stats(twopass, &local_next_frame))
-        break;
-    }
-
-    // If there is tolerable prediction for at least the next 3 frames then
-    // break out else discard this potential key frame and move on
-    if (boost_score > 30.0 && (i > 3)) {
-      is_viable_kf = 1;
-    } else {
-      // Reset the file position
-      reset_fpf_position(twopass, start_pos);
-
-      is_viable_kf = 0;
-    }
-  }
-
-  return is_viable_kf;
-}
-
-#define FRAMES_TO_CHECK_DECAY 8
-
-static void find_next_key_frame(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) {
-  int i, j;
-  RATE_CONTROL *const rc = &cpi->rc;
-  TWO_PASS *const twopass = &cpi->twopass;
-  GF_GROUP *const gf_group = &twopass->gf_group;
-  const VP9EncoderConfig *const oxcf = &cpi->oxcf;
-  const FIRSTPASS_STATS first_frame = *this_frame;
-  const FIRSTPASS_STATS *const start_position = twopass->stats_in;
-  FIRSTPASS_STATS next_frame;
-  FIRSTPASS_STATS last_frame;
-  int kf_bits = 0;
-  int loop_decay_counter = 0;
-  double decay_accumulator = 1.0;
-  double av_decay_accumulator = 0.0;
-  double zero_motion_accumulator = 1.0;
-  double boost_score = 0.0;
-  double kf_mod_err = 0.0;
-  double kf_group_err = 0.0;
-  double recent_loop_decay[FRAMES_TO_CHECK_DECAY];
-
-  vp9_zero(next_frame);
-
-  cpi->common.frame_type = KEY_FRAME;
-
-  // Reset the GF group data structures.
-  vp9_zero(*gf_group);
-
-  // Is this a forced key frame by interval.
-  rc->this_key_frame_forced = rc->next_key_frame_forced;
-
-  // Clear the alt ref active flag and last group multi arf flags as they
-  // can never be set for a key frame.
-  rc->source_alt_ref_active = 0;
-  cpi->multi_arf_last_grp_enabled = 0;
-
-  // KF is always a GF so clear frames till next gf counter.
-  rc->frames_till_gf_update_due = 0;
-
-  rc->frames_to_key = 1;
-
-  twopass->kf_group_bits = 0;        // Total bits available to kf group
-  twopass->kf_group_error_left = 0;  // Group modified error score.
-
-  kf_mod_err = calculate_modified_err(cpi, twopass, oxcf, this_frame);
-
-  // Initialize the decay rates for the recent frames to check
-  for (j = 0; j < FRAMES_TO_CHECK_DECAY; ++j)
-    recent_loop_decay[j] = 1.0;
-
-  // Find the next keyframe.
-  i = 0;
-  while (twopass->stats_in < twopass->stats_in_end &&
-         rc->frames_to_key < cpi->oxcf.key_freq) {
-    // Accumulate kf group error.
-    kf_group_err += calculate_modified_err(cpi, twopass, oxcf, this_frame);
-
-    // Load the next frame's stats.
-    last_frame = *this_frame;
-    input_stats(twopass, this_frame);
-
-    // Provided that we are not at the end of the file...
-    if (cpi->oxcf.auto_key && twopass->stats_in < twopass->stats_in_end) {
-      double loop_decay_rate;
-
-      // Check for a scene cut.
-      if (test_candidate_kf(twopass, &last_frame, this_frame,
-                            twopass->stats_in))
-        break;
-
-      // How fast is the prediction quality decaying?
-      loop_decay_rate = get_prediction_decay_rate(cpi, twopass->stats_in);
-
-      // We want to know something about the recent past... rather than
-      // as used elsewhere where we are concerned with decay in prediction
-      // quality since the last GF or KF.
-      recent_loop_decay[i % FRAMES_TO_CHECK_DECAY] = loop_decay_rate;
-      decay_accumulator = 1.0;
-      for (j = 0; j < FRAMES_TO_CHECK_DECAY; ++j)
-        decay_accumulator *= recent_loop_decay[j];
-
-      // Special check for transition or high motion followed by a
-      // static scene.
-      if (detect_transition_to_still(cpi, i, cpi->oxcf.key_freq - i,
-                                     loop_decay_rate, decay_accumulator))
-        break;
-
-      // Step on to the next frame.
-      ++rc->frames_to_key;
-
-      // If we don't have a real key frame within the next two
-      // key_freq intervals then break out of the loop.
-      if (rc->frames_to_key >= 2 * cpi->oxcf.key_freq)
-        break;
-    } else {
-      ++rc->frames_to_key;
-    }
-    ++i;
-  }
-
-  // If there is a max kf interval set by the user we must obey it.
-  // We already breakout of the loop above at 2x max.
-  // This code centers the extra kf if the actual natural interval
-  // is between 1x and 2x.
-  if (cpi->oxcf.auto_key &&
-      rc->frames_to_key > cpi->oxcf.key_freq) {
-    FIRSTPASS_STATS tmp_frame = first_frame;
-
-    rc->frames_to_key /= 2;
-
-    // Reset to the start of the group.
-    reset_fpf_position(twopass, start_position);
-
-    kf_group_err = 0.0;
-
-    // Rescan to get the correct error data for the forced kf group.
-    for (i = 0; i < rc->frames_to_key; ++i) {
-      kf_group_err += calculate_modified_err(cpi, twopass, oxcf, &tmp_frame);
-      input_stats(twopass, &tmp_frame);
-    }
-    rc->next_key_frame_forced = 1;
-  } else if (twopass->stats_in == twopass->stats_in_end ||
-             rc->frames_to_key >= cpi->oxcf.key_freq) {
-    rc->next_key_frame_forced = 1;
-  } else {
-    rc->next_key_frame_forced = 0;
-  }
-
-  if (is_two_pass_svc(cpi) && cpi->svc.number_temporal_layers > 1) {
-    int count = (1 << (cpi->svc.number_temporal_layers - 1)) - 1;
-    int new_frame_to_key = (rc->frames_to_key + count) & (~count);
-    int j;
-    for (j = 0; j < new_frame_to_key - rc->frames_to_key; ++j) {
-      if (EOF == input_stats(twopass, this_frame))
-        break;
-      kf_group_err += calculate_modified_err(cpi, twopass, oxcf, this_frame);
-    }
-    rc->frames_to_key = new_frame_to_key;
-  }
-
-  // Special case for the last key frame of the file.
-  if (twopass->stats_in >= twopass->stats_in_end) {
-    // Accumulate kf group error.
-    kf_group_err += calculate_modified_err(cpi, twopass, oxcf, this_frame);
-  }
-
-  // Calculate the number of bits that should be assigned to the kf group.
-  if (twopass->bits_left > 0 && twopass->modified_error_left > 0.0) {
-    // Maximum number of bits for a single normal frame (not key frame).
-    const int max_bits = frame_max_bits(rc, &cpi->oxcf);
-
-    // Maximum number of bits allocated to the key frame group.
-    int64_t max_grp_bits;
-
-    // Default allocation based on bits left and relative
-    // complexity of the section.
-    twopass->kf_group_bits = (int64_t)(twopass->bits_left *
-       (kf_group_err / twopass->modified_error_left));
-
-    // Clip based on maximum per frame rate defined by the user.
-    max_grp_bits = (int64_t)max_bits * (int64_t)rc->frames_to_key;
-    if (twopass->kf_group_bits > max_grp_bits)
-      twopass->kf_group_bits = max_grp_bits;
-  } else {
-    twopass->kf_group_bits = 0;
-  }
-  twopass->kf_group_bits = VPXMAX(0, twopass->kf_group_bits);
-
-  // Reset the first pass file position.
-  reset_fpf_position(twopass, start_position);
-
-  // Scan through the kf group collating various stats used to determine
-  // how many bits to spend on it.
-  decay_accumulator = 1.0;
-  boost_score = 0.0;
-  for (i = 0; i < (rc->frames_to_key - 1); ++i) {
-    if (EOF == input_stats(twopass, &next_frame))
-      break;
-
-    // Monitor for static sections.
-    zero_motion_accumulator = VPXMIN(
-        zero_motion_accumulator, get_zero_motion_factor(cpi, &next_frame));
-
-    // Not all frames in the group are necessarily used in calculating boost.
-    if ((i <= rc->max_gf_interval) ||
-        ((i <= (rc->max_gf_interval * 4)) && (decay_accumulator > 0.5))) {
-      const double frame_boost =
-        calc_frame_boost(cpi, &next_frame, 0, KF_MAX_BOOST);
-
-      // How fast is prediction quality decaying.
-      if (!detect_flash(twopass, 0)) {
-        const double loop_decay_rate =
-          get_prediction_decay_rate(cpi, &next_frame);
-        decay_accumulator *= loop_decay_rate;
-        decay_accumulator = VPXMAX(decay_accumulator, MIN_DECAY_FACTOR);
-        av_decay_accumulator += decay_accumulator;
-        ++loop_decay_counter;
-      }
-      boost_score += (decay_accumulator * frame_boost);
-    }
-  }
-  av_decay_accumulator /= (double)loop_decay_counter;
-
-  reset_fpf_position(twopass, start_position);
-
-  // Store the zero motion percentage
-  twopass->kf_zeromotion_pct = (int)(zero_motion_accumulator * 100.0);
-
-  // Calculate a section intra ratio used in setting max loop filter.
-  twopass->section_intra_rating =
-      calculate_section_intra_ratio(start_position, twopass->stats_in_end,
-                                    rc->frames_to_key);
-
-  // Apply various clamps for min and max boost
-  rc->kf_boost = (int)(av_decay_accumulator * boost_score);
-  rc->kf_boost = VPXMAX(rc->kf_boost, (rc->frames_to_key * 3));
-  rc->kf_boost = VPXMAX(rc->kf_boost, MIN_KF_BOOST);
-
-  // Work out how many bits to allocate for the key frame itself.
-  kf_bits = calculate_boost_bits((rc->frames_to_key - 1),
-                                  rc->kf_boost, twopass->kf_group_bits);
-
-  twopass->kf_group_bits -= kf_bits;
-
-  // Save the bits to spend on the key frame.
-  gf_group->bit_allocation[0] = kf_bits;
-  gf_group->update_type[0] = KF_UPDATE;
-  gf_group->rf_level[0] = KF_STD;
-
-  // Note the total error score of the kf group minus the key frame itself.
-  twopass->kf_group_error_left = (int)(kf_group_err - kf_mod_err);
-
-  // Adjust the count of total modified error left.
-  // The count of bits left is adjusted elsewhere based on real coded frame
-  // sizes.
-  twopass->modified_error_left -= kf_group_err;
-
-  if (oxcf->resize_mode == RESIZE_DYNAMIC) {
-    // Default to normal-sized frame on keyframes.
-    cpi->rc.next_frame_size_selector = UNSCALED;
-  }
-}
-
-// Define the reference buffers that will be updated post encode.
-static void configure_buffer_updates(VP9_COMP *cpi) {
-  TWO_PASS *const twopass = &cpi->twopass;
-
-  cpi->rc.is_src_frame_alt_ref = 0;
-  switch (twopass->gf_group.update_type[twopass->gf_group.index]) {
-    case KF_UPDATE:
-      cpi->refresh_last_frame = 1;
-      cpi->refresh_golden_frame = 1;
-      cpi->refresh_alt_ref_frame = 1;
-      break;
-    case LF_UPDATE:
-      cpi->refresh_last_frame = 1;
-      cpi->refresh_golden_frame = 0;
-      cpi->refresh_alt_ref_frame = 0;
-      break;
-    case GF_UPDATE:
-      cpi->refresh_last_frame = 1;
-      cpi->refresh_golden_frame = 1;
-      cpi->refresh_alt_ref_frame = 0;
-      break;
-    case OVERLAY_UPDATE:
-      cpi->refresh_last_frame = 0;
-      cpi->refresh_golden_frame = 1;
-      cpi->refresh_alt_ref_frame = 0;
-      cpi->rc.is_src_frame_alt_ref = 1;
-      break;
-    case ARF_UPDATE:
-      cpi->refresh_last_frame = 0;
-      cpi->refresh_golden_frame = 0;
-      cpi->refresh_alt_ref_frame = 1;
-      break;
-    default:
-      assert(0);
-      break;
-  }
-  if (is_two_pass_svc(cpi)) {
-    if (cpi->svc.temporal_layer_id > 0) {
-      cpi->refresh_last_frame = 0;
-      cpi->refresh_golden_frame = 0;
-    }
-    if (cpi->svc.layer_context[cpi->svc.spatial_layer_id].gold_ref_idx < 0)
-      cpi->refresh_golden_frame = 0;
-    if (cpi->alt_ref_source == NULL)
-      cpi->refresh_alt_ref_frame = 0;
-  }
-}
-
-static int is_skippable_frame(const VP9_COMP *cpi) {
-  // If the current frame does not have non-zero motion vector detected in the
-  // first  pass, and so do its previous and forward frames, then this frame
-  // can be skipped for partition check, and the partition size is assigned
-  // according to the variance
-  const SVC *const svc = &cpi->svc;
-  const TWO_PASS *const twopass = is_two_pass_svc(cpi) ?
-      &svc->layer_context[svc->spatial_layer_id].twopass : &cpi->twopass;
-
-  return (!frame_is_intra_only(&cpi->common) &&
-    twopass->stats_in - 2 > twopass->stats_in_start &&
-    twopass->stats_in < twopass->stats_in_end &&
-    (twopass->stats_in - 1)->pcnt_inter - (twopass->stats_in - 1)->pcnt_motion
-    == 1 &&
-    (twopass->stats_in - 2)->pcnt_inter - (twopass->stats_in - 2)->pcnt_motion
-    == 1 &&
-    twopass->stats_in->pcnt_inter - twopass->stats_in->pcnt_motion == 1);
-}
-
-void vp9_rc_get_second_pass_params(VP9_COMP *cpi) {
-  VP9_COMMON *const cm = &cpi->common;
-  RATE_CONTROL *const rc = &cpi->rc;
-  TWO_PASS *const twopass = &cpi->twopass;
-  GF_GROUP *const gf_group = &twopass->gf_group;
-  FIRSTPASS_STATS this_frame;
-
-  int target_rate;
-  LAYER_CONTEXT *const lc = is_two_pass_svc(cpi) ?
-        &cpi->svc.layer_context[cpi->svc.spatial_layer_id] : 0;
-
-  if (!twopass->stats_in)
-    return;
-
-  // If this is an arf frame then we dont want to read the stats file or
-  // advance the input pointer as we already have what we need.
-  if (gf_group->update_type[gf_group->index] == ARF_UPDATE) {
-    int target_rate;
-    configure_buffer_updates(cpi);
-    target_rate = gf_group->bit_allocation[gf_group->index];
-    target_rate = vp9_rc_clamp_pframe_target_size(cpi, target_rate);
-    rc->base_frame_target = target_rate;
-
-    cm->frame_type = INTER_FRAME;
-
-    if (lc != NULL) {
-      if (cpi->svc.spatial_layer_id == 0) {
-        lc->is_key_frame = 0;
-      } else {
-        lc->is_key_frame = cpi->svc.layer_context[0].is_key_frame;
-
-        if (lc->is_key_frame)
-          cpi->ref_frame_flags &= (~VP9_LAST_FLAG);
-      }
-    }
-
-    // Do the firstpass stats indicate that this frame is skippable for the
-    // partition search?
-    if (cpi->sf.allow_partition_search_skip &&
-        cpi->oxcf.pass == 2 && (!cpi->use_svc || is_two_pass_svc(cpi))) {
-      cpi->partition_search_skippable_frame = is_skippable_frame(cpi);
-    }
-
-    return;
-  }
-
-  vpx_clear_system_state();
-
-  if (cpi->oxcf.rc_mode == VPX_Q) {
-    twopass->active_worst_quality = cpi->oxcf.cq_level;
-  } else if (cm->current_video_frame == 0 ||
-             (lc != NULL && lc->current_video_frame_in_layer == 0)) {
-    const int frames_left = (int)(twopass->total_stats.count -
-        ((lc != NULL) ? lc->current_video_frame_in_layer
-                      : cm->current_video_frame));
-    // Special case code for first frame.
-    const int section_target_bandwidth = (int)(twopass->bits_left /
-                                               frames_left);
-    const double section_length = twopass->total_left_stats.count;
-    const double section_error =
-      twopass->total_left_stats.coded_error / section_length;
-    const double section_intra_skip =
-      twopass->total_left_stats.intra_skip_pct / section_length;
-    const double section_inactive_zone =
-      (twopass->total_left_stats.inactive_zone_rows * 2) /
-      ((double)cm->mb_rows * section_length);
-    int tmp_q;
-
-    tmp_q = get_twopass_worst_quality(cpi, section_error,
-        section_intra_skip + section_inactive_zone, section_target_bandwidth);
-
-    twopass->active_worst_quality = tmp_q;
-    twopass->baseline_active_worst_quality = tmp_q;
-    rc->ni_av_qi = tmp_q;
-    rc->last_q[INTER_FRAME] = tmp_q;
-    rc->avg_q = vp9_convert_qindex_to_q(tmp_q, cm->bit_depth);
-    rc->avg_frame_qindex[INTER_FRAME] = tmp_q;
-    rc->last_q[KEY_FRAME] = (tmp_q + cpi->oxcf.best_allowed_q) / 2;
-    rc->avg_frame_qindex[KEY_FRAME] = rc->last_q[KEY_FRAME];
-  }
-  vp9_zero(this_frame);
-  if (EOF == input_stats(twopass, &this_frame))
-    return;
-
-  // Set the frame content type flag.
-  if (this_frame.intra_skip_pct >= FC_ANIMATION_THRESH)
-    twopass->fr_content_type = FC_GRAPHICS_ANIMATION;
-  else
-    twopass->fr_content_type = FC_NORMAL;
-
-  // Keyframe and section processing.
-  if (rc->frames_to_key == 0 || (cpi->frame_flags & FRAMEFLAGS_KEY)) {
-    FIRSTPASS_STATS this_frame_copy;
-    this_frame_copy = this_frame;
-    // Define next KF group and assign bits to it.
-    find_next_key_frame(cpi, &this_frame);
-    this_frame = this_frame_copy;
-  } else {
-    cm->frame_type = INTER_FRAME;
-  }
-
-  if (lc != NULL) {
-    if (cpi->svc.spatial_layer_id == 0) {
-      lc->is_key_frame = (cm->frame_type == KEY_FRAME);
-      if (lc->is_key_frame) {
-        cpi->ref_frame_flags &=
-            (~VP9_LAST_FLAG & ~VP9_GOLD_FLAG & ~VP9_ALT_FLAG);
-        lc->frames_from_key_frame = 0;
-        // Encode an intra only empty frame since we have a key frame.
-        cpi->svc.encode_intra_empty_frame = 1;
-      }
-    } else {
-      cm->frame_type = INTER_FRAME;
-      lc->is_key_frame = cpi->svc.layer_context[0].is_key_frame;
-
-      if (lc->is_key_frame) {
-        cpi->ref_frame_flags &= (~VP9_LAST_FLAG);
-        lc->frames_from_key_frame = 0;
-      }
-    }
-  }
-
-  // Define a new GF/ARF group. (Should always enter here for key frames).
-  if (rc->frames_till_gf_update_due == 0) {
-    define_gf_group(cpi, &this_frame);
-
-    rc->frames_till_gf_update_due = rc->baseline_gf_interval;
-    if (lc != NULL)
-      cpi->refresh_golden_frame = 1;
-
-#if ARF_STATS_OUTPUT
-    {
-      FILE *fpfile;
-      fpfile = fopen("arf.stt", "a");
-      ++arf_count;
-      fprintf(fpfile, "%10d %10ld %10d %10d %10ld\n",
-              cm->current_video_frame, rc->frames_till_gf_update_due,
-              rc->kf_boost, arf_count, rc->gfu_boost);
-
-      fclose(fpfile);
-    }
-#endif
-  }
-
-  configure_buffer_updates(cpi);
-
-  // Do the firstpass stats indicate that this frame is skippable for the
-  // partition search?
-  if (cpi->sf.allow_partition_search_skip && cpi->oxcf.pass == 2 &&
-      (!cpi->use_svc || is_two_pass_svc(cpi))) {
-    cpi->partition_search_skippable_frame = is_skippable_frame(cpi);
-  }
-
-  target_rate = gf_group->bit_allocation[gf_group->index];
-  rc->base_frame_target = target_rate;
-
-  {
-    const int num_mbs = (cpi->oxcf.resize_mode != RESIZE_NONE)
-                        ? cpi->initial_mbs : cpi->common.MBs;
-    // The multiplication by 256 reverses a scaling factor of (>> 8)
-    // applied when combining MB error values for the frame.
-    twopass->mb_av_energy =
-      log(((this_frame.intra_error * 256.0) / num_mbs) + 1.0);
-    twopass->mb_smooth_pct = this_frame.intra_smooth_pct;
-  }
-
-  // Update the total stats remaining structure.
-  subtract_stats(&twopass->total_left_stats, &this_frame);
-}
-
-#define MINQ_ADJ_LIMIT 48
-#define MINQ_ADJ_LIMIT_CQ 20
-#define HIGH_UNDERSHOOT_RATIO 2
-void vp9_twopass_postencode_update(VP9_COMP *cpi) {
-  TWO_PASS *const twopass = &cpi->twopass;
-  RATE_CONTROL *const rc = &cpi->rc;
-  VP9_COMMON *const cm = &cpi->common;
-  const int bits_used = rc->base_frame_target;
-
-  // VBR correction is done through rc->vbr_bits_off_target. Based on the
-  // sign of this value, a limited % adjustment is made to the target rate
-  // of subsequent frames, to try and push it back towards 0. This method
-  // is designed to prevent extreme behaviour at the end of a clip
-  // or group of frames.
-  rc->vbr_bits_off_target += rc->base_frame_target - rc->projected_frame_size;
-  twopass->bits_left = VPXMAX(twopass->bits_left - bits_used, 0);
-
-  // Target vs actual bits for this arf group.
-  twopass->rolling_arf_group_target_bits += rc->this_frame_target;
-  twopass->rolling_arf_group_actual_bits += rc->projected_frame_size;
-
-  // Calculate the pct rc error.
-  if (rc->total_actual_bits) {
-    rc->rate_error_estimate =
-      (int)((rc->vbr_bits_off_target * 100) / rc->total_actual_bits);
-    rc->rate_error_estimate = clamp(rc->rate_error_estimate, -100, 100);
-  } else {
-    rc->rate_error_estimate = 0;
-  }
-
-  if (cpi->common.frame_type != KEY_FRAME &&
-      !vp9_is_upper_layer_key_frame(cpi)) {
-    twopass->kf_group_bits -= bits_used;
-    twopass->last_kfgroup_zeromotion_pct = twopass->kf_zeromotion_pct;
-  }
-  twopass->kf_group_bits = VPXMAX(twopass->kf_group_bits, 0);
-
-  // Increment the gf group index ready for the next frame.
-  ++twopass->gf_group.index;
-
-  // If the rate control is drifting consider adjustment to min or maxq.
-  if ((cpi->oxcf.rc_mode != VPX_Q) &&
-      !cpi->rc.is_src_frame_alt_ref) {
-    const int maxq_adj_limit =
-      rc->worst_quality - twopass->active_worst_quality;
-    const int minq_adj_limit =
-        (cpi->oxcf.rc_mode == VPX_CQ ? MINQ_ADJ_LIMIT_CQ : MINQ_ADJ_LIMIT);
-    int aq_extend_min = 0;
-    int aq_extend_max = 0;
-
-    // Extend min or Max Q range to account for imbalance from the base
-    // value when using AQ.
-    if (cpi->oxcf.aq_mode != NO_AQ) {
-      if (cm->seg.aq_av_offset < 0) {
-        // The balance of the AQ map tends towarda lowering the average Q.
-        aq_extend_min = 0;
-        aq_extend_max = VPXMIN(maxq_adj_limit, -cm->seg.aq_av_offset);
-      } else {
-        // The balance of the AQ map tends towards raising the average Q.
-        aq_extend_min = VPXMIN(minq_adj_limit, cm->seg.aq_av_offset);
-        aq_extend_max = 0;
-      }
-    }
-
-    // Undershoot.
-    if (rc->rate_error_estimate > cpi->oxcf.under_shoot_pct) {
-      --twopass->extend_maxq;
-      if (rc->rolling_target_bits >= rc->rolling_actual_bits)
-        ++twopass->extend_minq;
-    // Overshoot.
-    } else if (rc->rate_error_estimate < -cpi->oxcf.over_shoot_pct) {
-      --twopass->extend_minq;
-      if (rc->rolling_target_bits < rc->rolling_actual_bits)
-        ++twopass->extend_maxq;
-    } else {
-      // Adjustment for extreme local overshoot.
-      if (rc->projected_frame_size > (2 * rc->base_frame_target) &&
-          rc->projected_frame_size > (2 * rc->avg_frame_bandwidth))
-        ++twopass->extend_maxq;
-
-      // Unwind undershoot or overshoot adjustment.
-      if (rc->rolling_target_bits < rc->rolling_actual_bits)
-        --twopass->extend_minq;
-      else if (rc->rolling_target_bits > rc->rolling_actual_bits)
-        --twopass->extend_maxq;
-    }
-
-    twopass->extend_minq =
-        clamp(twopass->extend_minq, aq_extend_min, minq_adj_limit);
-    twopass->extend_maxq =
-        clamp(twopass->extend_maxq, aq_extend_max, maxq_adj_limit);
-
-    // If there is a big and undexpected undershoot then feed the extra
-    // bits back in quickly. One situation where this may happen is if a
-    // frame is unexpectedly almost perfectly predicted by the ARF or GF
-    // but not very well predcited by the previous frame.
-    if (!frame_is_kf_gf_arf(cpi) && !cpi->rc.is_src_frame_alt_ref) {
-      int fast_extra_thresh = rc->base_frame_target / HIGH_UNDERSHOOT_RATIO;
-      if (rc->projected_frame_size < fast_extra_thresh) {
-        rc->vbr_bits_off_target_fast +=
-          fast_extra_thresh - rc->projected_frame_size;
-        rc->vbr_bits_off_target_fast =
-          VPXMIN(rc->vbr_bits_off_target_fast, (4 * rc->avg_frame_bandwidth));
-
-        // Fast adaptation of minQ if necessary to use up the extra bits.
-        if (rc->avg_frame_bandwidth) {
-          twopass->extend_minq_fast =
-            (int)(rc->vbr_bits_off_target_fast * 8 / rc->avg_frame_bandwidth);
-        }
-        twopass->extend_minq_fast = VPXMIN(
-            twopass->extend_minq_fast, minq_adj_limit - twopass->extend_minq);
-      } else if (rc->vbr_bits_off_target_fast) {
-        twopass->extend_minq_fast = VPXMIN(
-            twopass->extend_minq_fast, minq_adj_limit - twopass->extend_minq);
-      } else {
-        twopass->extend_minq_fast = 0;
-      }
-    }
-  }
-}
diff --git a/vp9/encoder/vp9_firstpass.h b/vp9/encoder/vp9_firstpass.h
deleted file mode 100644 (file)
index 7607288..0000000
+++ /dev/null
@@ -1,163 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#ifndef VP9_ENCODER_VP9_FIRSTPASS_H_
-#define VP9_ENCODER_VP9_FIRSTPASS_H_
-
-#include "vp9/encoder/vp9_lookahead.h"
-#include "vp9/encoder/vp9_ratectrl.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#if CONFIG_FP_MB_STATS
-
-#define FPMB_DCINTRA_MASK 0x01
-
-#define FPMB_MOTION_ZERO_MASK 0x02
-#define FPMB_MOTION_LEFT_MASK 0x04
-#define FPMB_MOTION_RIGHT_MASK 0x08
-#define FPMB_MOTION_UP_MASK 0x10
-#define FPMB_MOTION_DOWN_MASK 0x20
-
-#define FPMB_ERROR_SMALL_MASK 0x40
-#define FPMB_ERROR_LARGE_MASK 0x80
-#define FPMB_ERROR_SMALL_TH 2000
-#define FPMB_ERROR_LARGE_TH 48000
-
-typedef struct {
-  uint8_t *mb_stats_start;
-  uint8_t *mb_stats_end;
-} FIRSTPASS_MB_STATS;
-#endif
-
-typedef struct {
-  double frame;
-  double weight;
-  double intra_error;
-  double coded_error;
-  double sr_coded_error;
-  double pcnt_inter;
-  double pcnt_motion;
-  double pcnt_second_ref;
-  double pcnt_neutral;
-  double intra_skip_pct;
-  double intra_smooth_pct;    // % of blocks that are smooth
-  double inactive_zone_rows;  // Image mask rows top and bottom.
-  double inactive_zone_cols;  // Image mask columns at left and right edges.
-  double MVr;
-  double mvr_abs;
-  double MVc;
-  double mvc_abs;
-  double MVrv;
-  double MVcv;
-  double mv_in_out_count;
-  double new_mv_count;
-  double duration;
-  double count;
-  int64_t spatial_layer_id;
-} FIRSTPASS_STATS;
-
-typedef enum {
-  KF_UPDATE = 0,
-  LF_UPDATE = 1,
-  GF_UPDATE = 2,
-  ARF_UPDATE = 3,
-  OVERLAY_UPDATE = 4,
-  FRAME_UPDATE_TYPES = 5
-} FRAME_UPDATE_TYPE;
-
-#define FC_ANIMATION_THRESH 0.15
-typedef enum {
-  FC_NORMAL = 0,
-  FC_GRAPHICS_ANIMATION = 1,
-  FRAME_CONTENT_TYPES = 2
-} FRAME_CONTENT_TYPE;
-
-typedef struct {
-  unsigned char index;
-  RATE_FACTOR_LEVEL rf_level[(MAX_LAG_BUFFERS * 2) + 1];
-  FRAME_UPDATE_TYPE update_type[(MAX_LAG_BUFFERS * 2) + 1];
-  unsigned char arf_src_offset[(MAX_LAG_BUFFERS * 2) + 1];
-  unsigned char arf_update_idx[(MAX_LAG_BUFFERS * 2) + 1];
-  unsigned char arf_ref_idx[(MAX_LAG_BUFFERS * 2) + 1];
-  int bit_allocation[(MAX_LAG_BUFFERS * 2) + 1];
-} GF_GROUP;
-
-typedef struct {
-  unsigned int section_intra_rating;
-  FIRSTPASS_STATS total_stats;
-  FIRSTPASS_STATS this_frame_stats;
-  const FIRSTPASS_STATS *stats_in;
-  const FIRSTPASS_STATS *stats_in_start;
-  const FIRSTPASS_STATS *stats_in_end;
-  FIRSTPASS_STATS total_left_stats;
-  int first_pass_done;
-  int64_t bits_left;
-  double modified_error_min;
-  double modified_error_max;
-  double modified_error_left;
-  double mb_av_energy;
-  double mb_smooth_pct;
-
-#if CONFIG_FP_MB_STATS
-  uint8_t *frame_mb_stats_buf;
-  uint8_t *this_frame_mb_stats;
-  FIRSTPASS_MB_STATS firstpass_mb_stats;
-#endif
-  // An indication of the content type of the current frame
-  FRAME_CONTENT_TYPE fr_content_type;
-
-  // Projected total bits available for a key frame group of frames
-  int64_t kf_group_bits;
-
-  // Error score of frames still to be coded in kf group
-  int64_t kf_group_error_left;
-
-  double bpm_factor;
-  int rolling_arf_group_target_bits;
-  int rolling_arf_group_actual_bits;
-
-  int sr_update_lag;
-  int kf_zeromotion_pct;
-  int last_kfgroup_zeromotion_pct;
-  int active_worst_quality;
-  int baseline_active_worst_quality;
-  int extend_minq;
-  int extend_maxq;
-  int extend_minq_fast;
-
-  GF_GROUP gf_group;
-} TWO_PASS;
-
-struct VP9_COMP;
-
-void vp9_init_first_pass(struct VP9_COMP *cpi);
-void vp9_rc_get_first_pass_params(struct VP9_COMP *cpi);
-void vp9_first_pass(struct VP9_COMP *cpi, const struct lookahead_entry *source);
-void vp9_end_first_pass(struct VP9_COMP *cpi);
-
-void vp9_init_second_pass(struct VP9_COMP *cpi);
-void vp9_rc_get_second_pass_params(struct VP9_COMP *cpi);
-void vp9_twopass_postencode_update(struct VP9_COMP *cpi);
-
-// Post encode update of the rate control parameters for 2-pass
-void vp9_twopass_postencode_update(struct VP9_COMP *cpi);
-
-void calculate_coded_size(struct VP9_COMP *cpi,
-                          int *scaled_frame_width,
-                          int *scaled_frame_height);
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP9_ENCODER_VP9_FIRSTPASS_H_
diff --git a/vp9/encoder/vp9_lookahead.c b/vp9/encoder/vp9_lookahead.c
deleted file mode 100644 (file)
index 441280c..0000000
+++ /dev/null
@@ -1,245 +0,0 @@
-/*
- *  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.
- */
-#include <assert.h>
-#include <stdlib.h>
-
-#include "./vpx_config.h"
-
-#include "vp9/common/vp9_common.h"
-
-#include "vp9/encoder/vp9_encoder.h"
-#include "vp9/encoder/vp9_extend.h"
-#include "vp9/encoder/vp9_lookahead.h"
-
-/* Return the buffer at the given absolute index and increment the index */
-static struct lookahead_entry *pop(struct lookahead_ctx *ctx,
-                                   int *idx) {
-  int index = *idx;
-  struct lookahead_entry *buf = ctx->buf + index;
-
-  assert(index < ctx->max_sz);
-  if (++index >= ctx->max_sz)
-    index -= ctx->max_sz;
-  *idx = index;
-  return buf;
-}
-
-
-void vp9_lookahead_destroy(struct lookahead_ctx *ctx) {
-  if (ctx) {
-    if (ctx->buf) {
-      int i;
-
-      for (i = 0; i < ctx->max_sz; i++)
-        vpx_free_frame_buffer(&ctx->buf[i].img);
-      free(ctx->buf);
-    }
-    free(ctx);
-  }
-}
-
-
-struct lookahead_ctx *vp9_lookahead_init(unsigned int width,
-                                         unsigned int height,
-                                         unsigned int subsampling_x,
-                                         unsigned int subsampling_y,
-#if CONFIG_VP9_HIGHBITDEPTH
-                                         int use_highbitdepth,
-#endif
-                                         unsigned int depth) {
-  struct lookahead_ctx *ctx = NULL;
-
-  // Clamp the lookahead queue depth
-  depth = clamp(depth, 1, MAX_LAG_BUFFERS);
-
-  // Allocate memory to keep previous source frames available.
-  depth += MAX_PRE_FRAMES;
-
-  // Allocate the lookahead structures
-  ctx = calloc(1, sizeof(*ctx));
-  if (ctx) {
-    const int legacy_byte_alignment = 0;
-    unsigned int i;
-    ctx->max_sz = depth;
-    ctx->buf = calloc(depth, sizeof(*ctx->buf));
-    if (!ctx->buf)
-      goto bail;
-    for (i = 0; i < depth; i++)
-      if (vpx_alloc_frame_buffer(&ctx->buf[i].img,
-                                 width, height, subsampling_x, subsampling_y,
-#if CONFIG_VP9_HIGHBITDEPTH
-                                 use_highbitdepth,
-#endif
-                                 VP9_ENC_BORDER_IN_PIXELS,
-                                 legacy_byte_alignment))
-        goto bail;
-  }
-  return ctx;
- bail:
-  vp9_lookahead_destroy(ctx);
-  return NULL;
-}
-
-#define USE_PARTIAL_COPY 0
-
-int vp9_lookahead_push(struct lookahead_ctx *ctx, YV12_BUFFER_CONFIG   *src,
-                       int64_t ts_start, int64_t ts_end,
-#if CONFIG_VP9_HIGHBITDEPTH
-                       int use_highbitdepth,
-#endif
-                       unsigned int flags) {
-  struct lookahead_entry *buf;
-#if USE_PARTIAL_COPY
-  int row, col, active_end;
-  int mb_rows = (src->y_height + 15) >> 4;
-  int mb_cols = (src->y_width + 15) >> 4;
-#endif
-  int width = src->y_crop_width;
-  int height = src->y_crop_height;
-  int uv_width = src->uv_crop_width;
-  int uv_height = src->uv_crop_height;
-  int subsampling_x = src->subsampling_x;
-  int subsampling_y = src->subsampling_y;
-  int larger_dimensions, new_dimensions;
-
-  if (ctx->sz + 1  + MAX_PRE_FRAMES > ctx->max_sz)
-    return 1;
-  ctx->sz++;
-  buf = pop(ctx, &ctx->write_idx);
-
-  new_dimensions = width != buf->img.y_crop_width ||
-                   height != buf->img.y_crop_height ||
-                   uv_width != buf->img.uv_crop_width ||
-                   uv_height != buf->img.uv_crop_height;
-  larger_dimensions = width > buf->img.y_width ||
-                      height > buf->img.y_height ||
-                      uv_width > buf->img.uv_width ||
-                      uv_height > buf->img.uv_height;
-  assert(!larger_dimensions || new_dimensions);
-
-#if USE_PARTIAL_COPY
-  // TODO(jkoleszar): This is disabled for now, as
-  // vp9_copy_and_extend_frame_with_rect is not subsampling/alpha aware.
-
-  // Only do this partial copy if the following conditions are all met:
-  // 1. Lookahead queue has has size of 1.
-  // 2. Active map is provided.
-  // 3. This is not a key frame, golden nor altref frame.
-  if (!new_dimensions && ctx->max_sz == 1 && active_map && !flags) {
-    for (row = 0; row < mb_rows; ++row) {
-      col = 0;
-
-      while (1) {
-        // Find the first active macroblock in this row.
-        for (; col < mb_cols; ++col) {
-          if (active_map[col])
-            break;
-        }
-
-        // No more active macroblock in this row.
-        if (col == mb_cols)
-          break;
-
-        // Find the end of active region in this row.
-        active_end = col;
-
-        for (; active_end < mb_cols; ++active_end) {
-          if (!active_map[active_end])
-            break;
-        }
-
-        // Only copy this active region.
-        vp9_copy_and_extend_frame_with_rect(src, &buf->img,
-                                            row << 4,
-                                            col << 4, 16,
-                                            (active_end - col) << 4);
-
-        // Start again from the end of this active region.
-        col = active_end;
-      }
-
-      active_map += mb_cols;
-    }
-  } else {
-#endif
-    if (larger_dimensions) {
-      YV12_BUFFER_CONFIG new_img;
-      memset(&new_img, 0, sizeof(new_img));
-      if (vpx_alloc_frame_buffer(&new_img,
-                                 width, height, subsampling_x, subsampling_y,
-#if CONFIG_VP9_HIGHBITDEPTH
-                                 use_highbitdepth,
-#endif
-                                 VP9_ENC_BORDER_IN_PIXELS,
-                                 0))
-          return 1;
-      vpx_free_frame_buffer(&buf->img);
-      buf->img = new_img;
-    } else if (new_dimensions) {
-      buf->img.y_crop_width = src->y_crop_width;
-      buf->img.y_crop_height = src->y_crop_height;
-      buf->img.uv_crop_width = src->uv_crop_width;
-      buf->img.uv_crop_height = src->uv_crop_height;
-      buf->img.subsampling_x = src->subsampling_x;
-      buf->img.subsampling_y = src->subsampling_y;
-    }
-    // Partial copy not implemented yet
-    vp9_copy_and_extend_frame(src, &buf->img);
-#if USE_PARTIAL_COPY
-  }
-#endif
-
-  buf->ts_start = ts_start;
-  buf->ts_end = ts_end;
-  buf->flags = flags;
-  return 0;
-}
-
-
-struct lookahead_entry *vp9_lookahead_pop(struct lookahead_ctx *ctx,
-                                          int drain) {
-  struct lookahead_entry *buf = NULL;
-
-  if (ctx && ctx->sz && (drain || ctx->sz == ctx->max_sz - MAX_PRE_FRAMES)) {
-    buf = pop(ctx, &ctx->read_idx);
-    ctx->sz--;
-  }
-  return buf;
-}
-
-
-struct lookahead_entry *vp9_lookahead_peek(struct lookahead_ctx *ctx,
-                                           int index) {
-  struct lookahead_entry *buf = NULL;
-
-  if (index >= 0) {
-    // Forward peek
-    if (index < ctx->sz) {
-      index += ctx->read_idx;
-      if (index >= ctx->max_sz)
-        index -= ctx->max_sz;
-      buf = ctx->buf + index;
-    }
-  } else if (index < 0) {
-    // Backward peek
-    if (-index <= MAX_PRE_FRAMES) {
-      index += ctx->read_idx;
-      if (index < 0)
-        index += ctx->max_sz;
-      buf = ctx->buf + index;
-    }
-  }
-
-  return buf;
-}
-
-unsigned int vp9_lookahead_depth(struct lookahead_ctx *ctx) {
-  return ctx->sz;
-}
diff --git a/vp9/encoder/vp9_lookahead.h b/vp9/encoder/vp9_lookahead.h
deleted file mode 100644 (file)
index db0fd1c..0000000
+++ /dev/null
@@ -1,124 +0,0 @@
-/*
- *  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.
- */
-
-#ifndef VP9_ENCODER_VP9_LOOKAHEAD_H_
-#define VP9_ENCODER_VP9_LOOKAHEAD_H_
-
-#include "vpx_scale/yv12config.h"
-#include "vpx/vpx_integer.h"
-
-#if CONFIG_SPATIAL_SVC
-#include "vpx/vp8cx.h"
-#include "vpx/vpx_encoder.h"
-#endif
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define MAX_LAG_BUFFERS 25
-
-struct lookahead_entry {
-  YV12_BUFFER_CONFIG  img;
-  int64_t             ts_start;
-  int64_t             ts_end;
-  unsigned int        flags;
-};
-
-// The max of past frames we want to keep in the queue.
-#define MAX_PRE_FRAMES 1
-
-struct lookahead_ctx {
-  int max_sz;                  /* Absolute size of the queue */
-  int sz;                      /* Number of buffers currently in the queue */
-  int read_idx;                /* Read index */
-  int write_idx;               /* Write index */
-  struct lookahead_entry *buf; /* Buffer list */
-};
-
-/**\brief Initializes the lookahead stage
- *
- * The lookahead stage is a queue of frame buffers on which some analysis
- * may be done when buffers are enqueued.
- */
-struct lookahead_ctx *vp9_lookahead_init(unsigned int width,
-                                         unsigned int height,
-                                         unsigned int subsampling_x,
-                                         unsigned int subsampling_y,
-#if CONFIG_VP9_HIGHBITDEPTH
-                                         int use_highbitdepth,
-#endif
-                                         unsigned int depth);
-
-
-/**\brief Destroys the lookahead stage
- */
-void vp9_lookahead_destroy(struct lookahead_ctx *ctx);
-
-
-/**\brief Enqueue a source buffer
- *
- * This function will copy the source image into a new framebuffer with
- * the expected stride/border.
- *
- * If active_map is non-NULL and there is only one frame in the queue, then copy
- * only active macroblocks.
- *
- * \param[in] ctx         Pointer to the lookahead context
- * \param[in] src         Pointer to the image to enqueue
- * \param[in] ts_start    Timestamp for the start of this frame
- * \param[in] ts_end      Timestamp for the end of this frame
- * \param[in] flags       Flags set on this frame
- * \param[in] active_map  Map that specifies which macroblock is active
- */
-int vp9_lookahead_push(struct lookahead_ctx *ctx, YV12_BUFFER_CONFIG *src,
-                       int64_t ts_start, int64_t ts_end,
-#if CONFIG_VP9_HIGHBITDEPTH
-                       int use_highbitdepth,
-#endif
-                       unsigned int flags);
-
-
-/**\brief Get the next source buffer to encode
- *
- *
- * \param[in] ctx       Pointer to the lookahead context
- * \param[in] drain     Flag indicating the buffer should be drained
- *                      (return a buffer regardless of the current queue depth)
- *
- * \retval NULL, if drain set and queue is empty
- * \retval NULL, if drain not set and queue not of the configured depth
- */
-struct lookahead_entry *vp9_lookahead_pop(struct lookahead_ctx *ctx,
-                                          int drain);
-
-
-/**\brief Get a future source buffer to encode
- *
- * \param[in] ctx       Pointer to the lookahead context
- * \param[in] index     Index of the frame to be returned, 0 == next frame
- *
- * \retval NULL, if no buffer exists at the specified index
- */
-struct lookahead_entry *vp9_lookahead_peek(struct lookahead_ctx *ctx,
-                                           int index);
-
-
-/**\brief Get the number of frames currently in the lookahead queue
- *
- * \param[in] ctx       Pointer to the lookahead context
- */
-unsigned int vp9_lookahead_depth(struct lookahead_ctx *ctx);
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP9_ENCODER_VP9_LOOKAHEAD_H_
diff --git a/vp9/encoder/vp9_mbgraph.c b/vp9/encoder/vp9_mbgraph.c
deleted file mode 100644 (file)
index 14a0b16..0000000
+++ /dev/null
@@ -1,428 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#include <limits.h>
-
-#include "./vp9_rtcd.h"
-#include "./vpx_dsp_rtcd.h"
-
-#include "vpx_dsp/vpx_dsp_common.h"
-#include "vpx_mem/vpx_mem.h"
-#include "vpx_ports/system_state.h"
-#include "vp9/encoder/vp9_segmentation.h"
-#include "vp9/encoder/vp9_mcomp.h"
-#include "vp9/common/vp9_blockd.h"
-#include "vp9/common/vp9_reconinter.h"
-#include "vp9/common/vp9_reconintra.h"
-
-
-static unsigned int do_16x16_motion_iteration(VP9_COMP *cpi,
-                                              const MV *ref_mv,
-                                              MV *dst_mv,
-                                              int mb_row,
-                                              int mb_col) {
-  MACROBLOCK *const x = &cpi->td.mb;
-  MACROBLOCKD *const xd = &x->e_mbd;
-  MV_SPEED_FEATURES *const mv_sf = &cpi->sf.mv;
-  const SEARCH_METHODS old_search_method = mv_sf->search_method;
-  const vp9_variance_fn_ptr_t v_fn_ptr = cpi->fn_ptr[BLOCK_16X16];
-
-  const int tmp_col_min = x->mv_col_min;
-  const int tmp_col_max = x->mv_col_max;
-  const int tmp_row_min = x->mv_row_min;
-  const int tmp_row_max = x->mv_row_max;
-  MV ref_full;
-  int cost_list[5];
-
-  // Further step/diamond searches as necessary
-  int step_param = mv_sf->reduce_first_step_size;
-  step_param = VPXMIN(step_param, MAX_MVSEARCH_STEPS - 2);
-
-  vp9_set_mv_search_range(x, ref_mv);
-
-  ref_full.col = ref_mv->col >> 3;
-  ref_full.row = ref_mv->row >> 3;
-
-  mv_sf->search_method = HEX;
-  vp9_full_pixel_search(cpi, x, BLOCK_16X16, &ref_full, step_param,
-                        x->errorperbit, cond_cost_list(cpi, cost_list), ref_mv,
-                        dst_mv, 0, 0);
-  mv_sf->search_method = old_search_method;
-
-  // Try sub-pixel MC
-  // if (bestsme > error_thresh && bestsme < INT_MAX)
-  {
-    uint32_t distortion;
-    uint32_t sse;
-    cpi->find_fractional_mv_step(
-        x, dst_mv, ref_mv, cpi->common.allow_high_precision_mv, x->errorperbit,
-        &v_fn_ptr, 0, mv_sf->subpel_iters_per_step,
-        cond_cost_list(cpi, cost_list),
-        NULL, NULL,
-        &distortion, &sse, NULL, 0, 0);
-  }
-
-  xd->mi[0]->mode = NEWMV;
-  xd->mi[0]->mv[0].as_mv = *dst_mv;
-
-  vp9_build_inter_predictors_sby(xd, mb_row, mb_col, BLOCK_16X16);
-
-  /* restore UMV window */
-  x->mv_col_min = tmp_col_min;
-  x->mv_col_max = tmp_col_max;
-  x->mv_row_min = tmp_row_min;
-  x->mv_row_max = tmp_row_max;
-
-  return vpx_sad16x16(x->plane[0].src.buf, x->plane[0].src.stride,
-                      xd->plane[0].dst.buf, xd->plane[0].dst.stride);
-}
-
-static int do_16x16_motion_search(VP9_COMP *cpi, const MV *ref_mv,
-                                  int_mv *dst_mv, int mb_row, int mb_col) {
-  MACROBLOCK *const x = &cpi->td.mb;
-  MACROBLOCKD *const xd = &x->e_mbd;
-  unsigned int err, tmp_err;
-  MV tmp_mv;
-
-  // Try zero MV first
-  // FIXME should really use something like near/nearest MV and/or MV prediction
-  err = vpx_sad16x16(x->plane[0].src.buf, x->plane[0].src.stride,
-                     xd->plane[0].pre[0].buf, xd->plane[0].pre[0].stride);
-  dst_mv->as_int = 0;
-
-  // Test last reference frame using the previous best mv as the
-  // starting point (best reference) for the search
-  tmp_err = do_16x16_motion_iteration(cpi, ref_mv, &tmp_mv, mb_row, mb_col);
-  if (tmp_err < err) {
-    err = tmp_err;
-    dst_mv->as_mv = tmp_mv;
-  }
-
-  // If the current best reference mv is not centered on 0,0 then do a 0,0
-  // based search as well.
-  if (ref_mv->row != 0 || ref_mv->col != 0) {
-    unsigned int tmp_err;
-    MV zero_ref_mv = {0, 0}, tmp_mv;
-
-    tmp_err = do_16x16_motion_iteration(cpi, &zero_ref_mv, &tmp_mv,
-                                        mb_row, mb_col);
-    if (tmp_err < err) {
-      dst_mv->as_mv = tmp_mv;
-      err = tmp_err;
-    }
-  }
-
-  return err;
-}
-
-static int do_16x16_zerozero_search(VP9_COMP *cpi, int_mv *dst_mv) {
-  MACROBLOCK *const x = &cpi->td.mb;
-  MACROBLOCKD *const xd = &x->e_mbd;
-  unsigned int err;
-
-  // Try zero MV first
-  // FIXME should really use something like near/nearest MV and/or MV prediction
-  err = vpx_sad16x16(x->plane[0].src.buf, x->plane[0].src.stride,
-                     xd->plane[0].pre[0].buf, xd->plane[0].pre[0].stride);
-
-  dst_mv->as_int = 0;
-
-  return err;
-}
-static int find_best_16x16_intra(VP9_COMP *cpi, PREDICTION_MODE *pbest_mode) {
-  MACROBLOCK   *const x  = &cpi->td.mb;
-  MACROBLOCKD *const xd = &x->e_mbd;
-  PREDICTION_MODE best_mode = -1, mode;
-  unsigned int best_err = INT_MAX;
-
-  // calculate SATD for each intra prediction mode;
-  // we're intentionally not doing 4x4, we just want a rough estimate
-  for (mode = DC_PRED; mode <= TM_PRED; mode++) {
-    unsigned int err;
-
-    xd->mi[0]->mode = mode;
-    vp9_predict_intra_block(xd, 2, TX_16X16, mode,
-                            x->plane[0].src.buf, x->plane[0].src.stride,
-                            xd->plane[0].dst.buf, xd->plane[0].dst.stride,
-                            0, 0, 0);
-    err = vpx_sad16x16(x->plane[0].src.buf, x->plane[0].src.stride,
-                       xd->plane[0].dst.buf, xd->plane[0].dst.stride);
-
-    // find best
-    if (err < best_err) {
-      best_err  = err;
-      best_mode = mode;
-    }
-  }
-
-  if (pbest_mode)
-    *pbest_mode = best_mode;
-
-  return best_err;
-}
-
-static void update_mbgraph_mb_stats
-(
-  VP9_COMP *cpi,
-  MBGRAPH_MB_STATS *stats,
-  YV12_BUFFER_CONFIG *buf,
-  int mb_y_offset,
-  YV12_BUFFER_CONFIG *golden_ref,
-  const MV *prev_golden_ref_mv,
-  YV12_BUFFER_CONFIG *alt_ref,
-  int mb_row,
-  int mb_col
-) {
-  MACROBLOCK *const x = &cpi->td.mb;
-  MACROBLOCKD *const xd = &x->e_mbd;
-  int intra_error;
-  VP9_COMMON *cm = &cpi->common;
-
-  // FIXME in practice we're completely ignoring chroma here
-  x->plane[0].src.buf = buf->y_buffer + mb_y_offset;
-  x->plane[0].src.stride = buf->y_stride;
-
-  xd->plane[0].dst.buf = get_frame_new_buffer(cm)->y_buffer + mb_y_offset;
-  xd->plane[0].dst.stride = get_frame_new_buffer(cm)->y_stride;
-
-  // do intra 16x16 prediction
-  intra_error = find_best_16x16_intra(cpi,
-                                      &stats->ref[INTRA_FRAME].m.mode);
-  if (intra_error <= 0)
-    intra_error = 1;
-  stats->ref[INTRA_FRAME].err = intra_error;
-
-  // Golden frame MV search, if it exists and is different than last frame
-  if (golden_ref) {
-    int g_motion_error;
-    xd->plane[0].pre[0].buf = golden_ref->y_buffer + mb_y_offset;
-    xd->plane[0].pre[0].stride = golden_ref->y_stride;
-    g_motion_error = do_16x16_motion_search(cpi,
-                                            prev_golden_ref_mv,
-                                            &stats->ref[GOLDEN_FRAME].m.mv,
-                                            mb_row, mb_col);
-    stats->ref[GOLDEN_FRAME].err = g_motion_error;
-  } else {
-    stats->ref[GOLDEN_FRAME].err = INT_MAX;
-    stats->ref[GOLDEN_FRAME].m.mv.as_int = 0;
-  }
-
-  // Do an Alt-ref frame MV search, if it exists and is different than
-  // last/golden frame.
-  if (alt_ref) {
-    int a_motion_error;
-    xd->plane[0].pre[0].buf = alt_ref->y_buffer + mb_y_offset;
-    xd->plane[0].pre[0].stride = alt_ref->y_stride;
-    a_motion_error = do_16x16_zerozero_search(cpi,
-                                              &stats->ref[ALTREF_FRAME].m.mv);
-
-    stats->ref[ALTREF_FRAME].err = a_motion_error;
-  } else {
-    stats->ref[ALTREF_FRAME].err = INT_MAX;
-    stats->ref[ALTREF_FRAME].m.mv.as_int = 0;
-  }
-}
-
-static void update_mbgraph_frame_stats(VP9_COMP *cpi,
-                                       MBGRAPH_FRAME_STATS *stats,
-                                       YV12_BUFFER_CONFIG *buf,
-                                       YV12_BUFFER_CONFIG *golden_ref,
-                                       YV12_BUFFER_CONFIG *alt_ref) {
-  MACROBLOCK *const x = &cpi->td.mb;
-  MACROBLOCKD *const xd = &x->e_mbd;
-  VP9_COMMON *const cm = &cpi->common;
-
-  int mb_col, mb_row, offset = 0;
-  int mb_y_offset = 0, arf_y_offset = 0, gld_y_offset = 0;
-  MV gld_top_mv = {0, 0};
-  MODE_INFO mi_local;
-  MODE_INFO mi_above, mi_left;
-
-  vp9_zero(mi_local);
-  // Set up limit values for motion vectors to prevent them extending outside
-  // the UMV borders.
-  x->mv_row_min     = -BORDER_MV_PIXELS_B16;
-  x->mv_row_max     = (cm->mb_rows - 1) * 8 + BORDER_MV_PIXELS_B16;
-  // Signal to vp9_predict_intra_block() that above is not available
-  xd->above_mi = NULL;
-
-  xd->plane[0].dst.stride  = buf->y_stride;
-  xd->plane[0].pre[0].stride  = buf->y_stride;
-  xd->plane[1].dst.stride = buf->uv_stride;
-  xd->mi[0] = &mi_local;
-  mi_local.sb_type = BLOCK_16X16;
-  mi_local.ref_frame[0] = LAST_FRAME;
-  mi_local.ref_frame[1] = NONE;
-
-  for (mb_row = 0; mb_row < cm->mb_rows; mb_row++) {
-    MV gld_left_mv = gld_top_mv;
-    int mb_y_in_offset  = mb_y_offset;
-    int arf_y_in_offset = arf_y_offset;
-    int gld_y_in_offset = gld_y_offset;
-
-    // Set up limit values for motion vectors to prevent them extending outside
-    // the UMV borders.
-    x->mv_col_min      = -BORDER_MV_PIXELS_B16;
-    x->mv_col_max      = (cm->mb_cols - 1) * 8 + BORDER_MV_PIXELS_B16;
-    // Signal to vp9_predict_intra_block() that left is not available
-    xd->left_mi = NULL;
-
-    for (mb_col = 0; mb_col < cm->mb_cols; mb_col++) {
-      MBGRAPH_MB_STATS *mb_stats = &stats->mb_stats[offset + mb_col];
-
-      update_mbgraph_mb_stats(cpi, mb_stats, buf, mb_y_in_offset,
-                              golden_ref, &gld_left_mv, alt_ref,
-                              mb_row, mb_col);
-      gld_left_mv = mb_stats->ref[GOLDEN_FRAME].m.mv.as_mv;
-      if (mb_col == 0) {
-        gld_top_mv = gld_left_mv;
-      }
-      // Signal to vp9_predict_intra_block() that left is available
-      xd->left_mi = &mi_left;
-
-      mb_y_in_offset    += 16;
-      gld_y_in_offset   += 16;
-      arf_y_in_offset   += 16;
-      x->mv_col_min     -= 16;
-      x->mv_col_max     -= 16;
-    }
-
-    // Signal to vp9_predict_intra_block() that above is available
-    xd->above_mi = &mi_above;
-
-    mb_y_offset     += buf->y_stride * 16;
-    gld_y_offset    += golden_ref->y_stride * 16;
-    if (alt_ref)
-      arf_y_offset    += alt_ref->y_stride * 16;
-    x->mv_row_min   -= 16;
-    x->mv_row_max   -= 16;
-    offset          += cm->mb_cols;
-  }
-}
-
-// void separate_arf_mbs_byzz
-static void separate_arf_mbs(VP9_COMP *cpi) {
-  VP9_COMMON *const cm = &cpi->common;
-  int mb_col, mb_row, offset, i;
-  int mi_row, mi_col;
-  int ncnt[4] = { 0 };
-  int n_frames = cpi->mbgraph_n_frames;
-
-  int *arf_not_zz;
-
-  CHECK_MEM_ERROR(cm, arf_not_zz,
-                  vpx_calloc(cm->mb_rows * cm->mb_cols * sizeof(*arf_not_zz),
-                             1));
-
-  // We are not interested in results beyond the alt ref itself.
-  if (n_frames > cpi->rc.frames_till_gf_update_due)
-    n_frames = cpi->rc.frames_till_gf_update_due;
-
-  // defer cost to reference frames
-  for (i = n_frames - 1; i >= 0; i--) {
-    MBGRAPH_FRAME_STATS *frame_stats = &cpi->mbgraph_stats[i];
-
-    for (offset = 0, mb_row = 0; mb_row < cm->mb_rows;
-         offset += cm->mb_cols, mb_row++) {
-      for (mb_col = 0; mb_col < cm->mb_cols; mb_col++) {
-        MBGRAPH_MB_STATS *mb_stats = &frame_stats->mb_stats[offset + mb_col];
-
-        int altref_err = mb_stats->ref[ALTREF_FRAME].err;
-        int intra_err  = mb_stats->ref[INTRA_FRAME ].err;
-        int golden_err = mb_stats->ref[GOLDEN_FRAME].err;
-
-        // Test for altref vs intra and gf and that its mv was 0,0.
-        if (altref_err > 1000 ||
-            altref_err > intra_err ||
-            altref_err > golden_err) {
-          arf_not_zz[offset + mb_col]++;
-        }
-      }
-    }
-  }
-
-  // arf_not_zz is indexed by MB, but this loop is indexed by MI to avoid out
-  // of bound access in segmentation_map
-  for (mi_row = 0; mi_row < cm->mi_rows; mi_row++) {
-    for (mi_col = 0; mi_col < cm->mi_cols; mi_col++) {
-      // If any of the blocks in the sequence failed then the MB
-      // goes in segment 0
-      if (arf_not_zz[mi_row / 2 * cm->mb_cols + mi_col / 2]) {
-        ncnt[0]++;
-        cpi->segmentation_map[mi_row * cm->mi_cols + mi_col] = 0;
-      } else {
-        cpi->segmentation_map[mi_row * cm->mi_cols + mi_col] = 1;
-        ncnt[1]++;
-      }
-    }
-  }
-
-  // Only bother with segmentation if over 10% of the MBs in static segment
-  // if ( ncnt[1] && (ncnt[0] / ncnt[1] < 10) )
-  if (1) {
-    // Note % of blocks that are marked as static
-    if (cm->MBs)
-      cpi->static_mb_pct = (ncnt[1] * 100) / (cm->mi_rows * cm->mi_cols);
-
-    // This error case should not be reachable as this function should
-    // never be called with the common data structure uninitialized.
-    else
-      cpi->static_mb_pct = 0;
-
-    vp9_enable_segmentation(&cm->seg);
-  } else {
-    cpi->static_mb_pct = 0;
-    vp9_disable_segmentation(&cm->seg);
-  }
-
-  // Free localy allocated storage
-  vpx_free(arf_not_zz);
-}
-
-void vp9_update_mbgraph_stats(VP9_COMP *cpi) {
-  VP9_COMMON *const cm = &cpi->common;
-  int i, n_frames = vp9_lookahead_depth(cpi->lookahead);
-  YV12_BUFFER_CONFIG *golden_ref = get_ref_frame_buffer(cpi, GOLDEN_FRAME);
-
-  assert(golden_ref != NULL);
-
-  // we need to look ahead beyond where the ARF transitions into
-  // being a GF - so exit if we don't look ahead beyond that
-  if (n_frames <= cpi->rc.frames_till_gf_update_due)
-    return;
-
-  if (n_frames > MAX_LAG_BUFFERS)
-    n_frames = MAX_LAG_BUFFERS;
-
-  cpi->mbgraph_n_frames = n_frames;
-  for (i = 0; i < n_frames; i++) {
-    MBGRAPH_FRAME_STATS *frame_stats = &cpi->mbgraph_stats[i];
-    memset(frame_stats->mb_stats, 0,
-           cm->mb_rows * cm->mb_cols * sizeof(*cpi->mbgraph_stats[i].mb_stats));
-  }
-
-  // do motion search to find contribution of each reference to data
-  // later on in this GF group
-  // FIXME really, the GF/last MC search should be done forward, and
-  // the ARF MC search backwards, to get optimal results for MV caching
-  for (i = 0; i < n_frames; i++) {
-    MBGRAPH_FRAME_STATS *frame_stats = &cpi->mbgraph_stats[i];
-    struct lookahead_entry *q_cur = vp9_lookahead_peek(cpi->lookahead, i);
-
-    assert(q_cur != NULL);
-
-    update_mbgraph_frame_stats(cpi, frame_stats, &q_cur->img,
-                               golden_ref, cpi->Source);
-  }
-
-  vpx_clear_system_state();
-
-  separate_arf_mbs(cpi);
-}
diff --git a/vp9/encoder/vp9_mbgraph.h b/vp9/encoder/vp9_mbgraph.h
deleted file mode 100644 (file)
index c3af972..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#ifndef VP9_ENCODER_VP9_MBGRAPH_H_
-#define VP9_ENCODER_VP9_MBGRAPH_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef struct {
-  struct {
-    int err;
-    union {
-      int_mv mv;
-      PREDICTION_MODE mode;
-    } m;
-  } ref[MAX_REF_FRAMES];
-} MBGRAPH_MB_STATS;
-
-typedef struct {
-  MBGRAPH_MB_STATS *mb_stats;
-} MBGRAPH_FRAME_STATS;
-
-struct VP9_COMP;
-
-void vp9_update_mbgraph_stats(struct VP9_COMP *cpi);
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP9_ENCODER_VP9_MBGRAPH_H_
diff --git a/vp9/encoder/vp9_mcomp.c b/vp9/encoder/vp9_mcomp.c
deleted file mode 100644 (file)
index e747277..0000000
+++ /dev/null
@@ -1,2575 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#include <limits.h>
-#include <math.h>
-#include <stdio.h>
-
-#include "./vpx_config.h"
-#include "./vpx_dsp_rtcd.h"
-
-#include "vpx_dsp/vpx_dsp_common.h"
-#include "vpx_mem/vpx_mem.h"
-#include "vpx_ports/mem.h"
-
-#include "vp9/common/vp9_common.h"
-#include "vp9/common/vp9_reconinter.h"
-
-#include "vp9/encoder/vp9_encoder.h"
-#include "vp9/encoder/vp9_mcomp.h"
-
-// #define NEW_DIAMOND_SEARCH
-
-static INLINE const uint8_t *get_buf_from_mv(const struct buf_2d *buf,
-                                             const MV *mv) {
-  return &buf->buf[mv->row * buf->stride + mv->col];
-}
-
-void vp9_set_mv_search_range(MACROBLOCK *x, const MV *mv) {
-  int col_min = (mv->col >> 3) - MAX_FULL_PEL_VAL + (mv->col & 7 ? 1 : 0);
-  int row_min = (mv->row >> 3) - MAX_FULL_PEL_VAL + (mv->row & 7 ? 1 : 0);
-  int col_max = (mv->col >> 3) + MAX_FULL_PEL_VAL;
-  int row_max = (mv->row >> 3) + MAX_FULL_PEL_VAL;
-
-  col_min = VPXMAX(col_min, (MV_LOW >> 3) + 1);
-  row_min = VPXMAX(row_min, (MV_LOW >> 3) + 1);
-  col_max = VPXMIN(col_max, (MV_UPP >> 3) - 1);
-  row_max = VPXMIN(row_max, (MV_UPP >> 3) - 1);
-
-  // Get intersection of UMV window and valid MV window to reduce # of checks
-  // in diamond search.
-  if (x->mv_col_min < col_min)
-    x->mv_col_min = col_min;
-  if (x->mv_col_max > col_max)
-    x->mv_col_max = col_max;
-  if (x->mv_row_min < row_min)
-    x->mv_row_min = row_min;
-  if (x->mv_row_max > row_max)
-    x->mv_row_max = row_max;
-}
-
-int vp9_init_search_range(int size) {
-  int sr = 0;
-  // Minimum search size no matter what the passed in value.
-  size = VPXMAX(16, size);
-
-  while ((size << sr) < MAX_FULL_PEL_VAL)
-    sr++;
-
-  sr = VPXMIN(sr, MAX_MVSEARCH_STEPS - 2);
-  return sr;
-}
-
-static INLINE int mv_cost(const MV *mv,
-                          const int *joint_cost, int *const comp_cost[2]) {
-  return joint_cost[vp9_get_mv_joint(mv)] +
-             comp_cost[0][mv->row] + comp_cost[1][mv->col];
-}
-
-int vp9_mv_bit_cost(const MV *mv, const MV *ref,
-                    const int *mvjcost, int *mvcost[2], int weight) {
-  const MV diff = { mv->row - ref->row,
-                    mv->col - ref->col };
-  return ROUND_POWER_OF_TWO(mv_cost(&diff, mvjcost, mvcost) * weight, 7);
-}
-
-#define PIXEL_TRANSFORM_ERROR_SCALE 4
-static int mv_err_cost(const MV *mv, const MV *ref, const int *mvjcost,
-                       int *mvcost[2], int error_per_bit) {
-  if (mvcost) {
-    const MV diff = {mv->row - ref->row, mv->col - ref->col};
-    // This product sits at a 32-bit ceiling right now and any additional
-    // accuracy in either bit cost or error cost will cause it to overflow.
-    return ROUND_POWER_OF_TWO(
-        (unsigned)mv_cost(&diff, mvjcost, mvcost) * error_per_bit,
-        RDDIV_BITS + VP9_PROB_COST_SHIFT - RD_EPB_SHIFT +
-            PIXEL_TRANSFORM_ERROR_SCALE);
-  }
-  return 0;
-}
-
-static int mvsad_err_cost(const MACROBLOCK *x, const MV *mv, const MV *ref,
-                          int sad_per_bit) {
-  const MV diff = { mv->row - ref->row,
-                    mv->col - ref->col };
-  return ROUND_POWER_OF_TWO(
-      (unsigned)mv_cost(&diff, x->nmvjointsadcost, x->nmvsadcost) *
-          sad_per_bit,
-      VP9_PROB_COST_SHIFT);
-}
-
-void vp9_init_dsmotion_compensation(search_site_config *cfg, int stride) {
-  int len;
-  int ss_count = 0;
-
-  for (len = MAX_FIRST_STEP; len > 0; len /= 2) {
-    // Generate offsets for 4 search sites per step.
-    const MV ss_mvs[] = {{-len, 0}, {len, 0}, {0, -len}, {0, len}};
-    int i;
-    for (i = 0; i < 4; ++i, ++ss_count) {
-      cfg->ss_mv[ss_count] = ss_mvs[i];
-      cfg->ss_os[ss_count] = ss_mvs[i].row * stride + ss_mvs[i].col;
-    }
-  }
-
-  cfg->searches_per_step = 4;
-  cfg->total_steps = ss_count / cfg->searches_per_step;
-}
-
-void vp9_init3smotion_compensation(search_site_config *cfg, int stride) {
-  int len;
-  int ss_count = 0;
-
-  for (len = MAX_FIRST_STEP; len > 0; len /= 2) {
-    // Generate offsets for 8 search sites per step.
-    const MV ss_mvs[8] = {
-      {-len,  0  }, {len,  0  }, { 0,   -len}, {0,    len},
-      {-len, -len}, {-len, len}, {len,  -len}, {len,  len}
-    };
-    int i;
-    for (i = 0; i < 8; ++i, ++ss_count) {
-      cfg->ss_mv[ss_count] = ss_mvs[i];
-      cfg->ss_os[ss_count] = ss_mvs[i].row * stride + ss_mvs[i].col;
-    }
-  }
-
-  cfg->searches_per_step = 8;
-  cfg->total_steps = ss_count / cfg->searches_per_step;
-}
-
-/* Estimated (square) error cost of a motion vector (r,c). The 14 scale comes
- * from the same math as in mv_err_cost(). */
-#define MVC(r, c)                                              \
-    (mvcost ?                                                  \
-     ((unsigned)(mvjcost[((r) != rr) * 2 + ((c) != rc)] +      \
-       mvcost[0][((r) - rr)] + mvcost[1][((c) - rc)]) *        \
-      error_per_bit + 8192) >> 14 : 0)
-
-
-// convert motion vector component to offset for sv[a]f calc
-static INLINE int sp(int x) {
-  return x & 7;
-}
-
-static INLINE const uint8_t *pre(const uint8_t *buf, int stride, int r, int c) {
-  return &buf[(r >> 3) * stride + (c >> 3)];
-}
-
-#if CONFIG_VP9_HIGHBITDEPTH
-/* checks if (r, c) has better score than previous best */
-#define CHECK_BETTER(v, r, c) \
-  if (c >= minc && c <= maxc && r >= minr && r <= maxr) {              \
-    int64_t tmpmse;                                                    \
-    if (second_pred == NULL) {                                         \
-      thismse = vfp->svf(pre(y, y_stride, r, c), y_stride, sp(c),      \
-                         sp(r), z, src_stride, &sse);                  \
-    } else {                                                           \
-      thismse = vfp->svaf(pre(y, y_stride, r, c), y_stride, sp(c),     \
-                          sp(r), z, src_stride, &sse, second_pred);    \
-    }                                                                  \
-    tmpmse = thismse;                                                  \
-    tmpmse += MVC(r, c);                                               \
-    if (tmpmse >= INT_MAX) {                                           \
-      v = INT_MAX;                                                     \
-    } else if ((v = (uint32_t)tmpmse) < besterr) {                     \
-      besterr = v;                                                     \
-      br = r;                                                          \
-      bc = c;                                                          \
-      *distortion = thismse;                                           \
-      *sse1 = sse;                                                     \
-    }                                                                  \
-  } else {                                                             \
-    v = INT_MAX;                                                       \
-  }
-#else
-/* checks if (r, c) has better score than previous best */
-#define CHECK_BETTER(v, r, c) \
-  if (c >= minc && c <= maxc && r >= minr && r <= maxr) {              \
-    if (second_pred == NULL)                                           \
-      thismse = vfp->svf(pre(y, y_stride, r, c), y_stride, sp(c), sp(r), z, \
-                             src_stride, &sse);                        \
-    else                                                               \
-      thismse = vfp->svaf(pre(y, y_stride, r, c), y_stride, sp(c), sp(r), \
-                              z, src_stride, &sse, second_pred);       \
-    if ((v = MVC(r, c) + thismse) < besterr) {                         \
-      besterr = v;                                                     \
-      br = r;                                                          \
-      bc = c;                                                          \
-      *distortion = thismse;                                           \
-      *sse1 = sse;                                                     \
-    }                                                                  \
-  } else {                                                             \
-    v = INT_MAX;                                                       \
-  }
-
-#endif
-#define FIRST_LEVEL_CHECKS                              \
-  {                                                     \
-    unsigned int left, right, up, down, diag;           \
-    CHECK_BETTER(left, tr, tc - hstep);                 \
-    CHECK_BETTER(right, tr, tc + hstep);                \
-    CHECK_BETTER(up, tr - hstep, tc);                   \
-    CHECK_BETTER(down, tr + hstep, tc);                 \
-    whichdir = (left < right ? 0 : 1) +                 \
-               (up < down ? 0 : 2);                     \
-    switch (whichdir) {                                 \
-      case 0:                                           \
-        CHECK_BETTER(diag, tr - hstep, tc - hstep);     \
-        break;                                          \
-      case 1:                                           \
-        CHECK_BETTER(diag, tr - hstep, tc + hstep);     \
-        break;                                          \
-      case 2:                                           \
-        CHECK_BETTER(diag, tr + hstep, tc - hstep);     \
-        break;                                          \
-      case 3:                                           \
-        CHECK_BETTER(diag, tr + hstep, tc + hstep);     \
-        break;                                          \
-    }                                                   \
-  }
-
-#define SECOND_LEVEL_CHECKS                             \
-  {                                                     \
-    int kr, kc;                                         \
-    unsigned int second;                                \
-    if (tr != br && tc != bc) {                         \
-      kr = br - tr;                                     \
-      kc = bc - tc;                                     \
-      CHECK_BETTER(second, tr + kr, tc + 2 * kc);       \
-      CHECK_BETTER(second, tr + 2 * kr, tc + kc);       \
-    } else if (tr == br && tc != bc) {                  \
-      kc = bc - tc;                                     \
-      CHECK_BETTER(second, tr + hstep, tc + 2 * kc);    \
-      CHECK_BETTER(second, tr - hstep, tc + 2 * kc);    \
-      switch (whichdir) {                               \
-        case 0:                                         \
-        case 1:                                         \
-          CHECK_BETTER(second, tr + hstep, tc + kc);    \
-          break;                                        \
-        case 2:                                         \
-        case 3:                                         \
-          CHECK_BETTER(second, tr - hstep, tc + kc);    \
-          break;                                        \
-      }                                                 \
-    } else if (tr != br && tc == bc) {                  \
-      kr = br - tr;                                     \
-      CHECK_BETTER(second, tr + 2 * kr, tc + hstep);    \
-      CHECK_BETTER(second, tr + 2 * kr, tc - hstep);    \
-      switch (whichdir) {                               \
-        case 0:                                         \
-        case 2:                                         \
-          CHECK_BETTER(second, tr + kr, tc + hstep);    \
-          break;                                        \
-        case 1:                                         \
-        case 3:                                         \
-          CHECK_BETTER(second, tr + kr, tc - hstep);    \
-          break;                                        \
-      }                                                 \
-    }                                                   \
-  }
-
-// TODO(yunqingwang): SECOND_LEVEL_CHECKS_BEST was a rewrote of
-// SECOND_LEVEL_CHECKS, and SECOND_LEVEL_CHECKS should be rewritten
-// later in the same way.
-#define SECOND_LEVEL_CHECKS_BEST                        \
-  {                                                     \
-    unsigned int second;                                \
-    int br0 = br;                                       \
-    int bc0 = bc;                                       \
-    assert(tr == br || tc == bc);                       \
-    if (tr == br && tc != bc) {                         \
-      kc = bc - tc;                                     \
-    } else if (tr != br && tc == bc) {                  \
-      kr = br - tr;                                     \
-    }                                                   \
-    CHECK_BETTER(second, br0 + kr, bc0);                \
-    CHECK_BETTER(second, br0, bc0 + kc);                \
-    if (br0 != br || bc0 != bc) {                       \
-      CHECK_BETTER(second, br0 + kr, bc0 + kc);         \
-    }                                                   \
-  }
-
-#define SETUP_SUBPEL_SEARCH                                                \
-  const uint8_t *const z = x->plane[0].src.buf;                            \
-  const int src_stride = x->plane[0].src.stride;                           \
-  const MACROBLOCKD *xd = &x->e_mbd;                                       \
-  unsigned int besterr = INT_MAX;                                          \
-  unsigned int sse;                                                        \
-  unsigned int whichdir;                                                   \
-  int thismse;                                                             \
-  const unsigned int halfiters = iters_per_step;                           \
-  const unsigned int quarteriters = iters_per_step;                        \
-  const unsigned int eighthiters = iters_per_step;                         \
-  const int y_stride = xd->plane[0].pre[0].stride;                         \
-  const int offset = bestmv->row * y_stride + bestmv->col;                 \
-  const uint8_t *const y = xd->plane[0].pre[0].buf;                        \
-                                                                           \
-  int rr = ref_mv->row;                                                    \
-  int rc = ref_mv->col;                                                    \
-  int br = bestmv->row * 8;                                                \
-  int bc = bestmv->col * 8;                                                \
-  int hstep = 4;                                                           \
-  const int minc = VPXMAX(x->mv_col_min * 8, ref_mv->col - MV_MAX);        \
-  const int maxc = VPXMIN(x->mv_col_max * 8, ref_mv->col + MV_MAX);        \
-  const int minr = VPXMAX(x->mv_row_min * 8, ref_mv->row - MV_MAX);        \
-  const int maxr = VPXMIN(x->mv_row_max * 8, ref_mv->row + MV_MAX);        \
-  int tr = br;                                                             \
-  int tc = bc;                                                             \
-                                                                           \
-  bestmv->row *= 8;                                                        \
-  bestmv->col *= 8;
-
-static unsigned int setup_center_error(const MACROBLOCKD *xd,
-                                       const MV *bestmv,
-                                       const MV *ref_mv,
-                                       int error_per_bit,
-                                       const vp9_variance_fn_ptr_t *vfp,
-                                       const uint8_t *const src,
-                                       const int src_stride,
-                                       const uint8_t *const y,
-                                       int y_stride,
-                                       const uint8_t *second_pred,
-                                       int w, int h, int offset,
-                                       int *mvjcost, int *mvcost[2],
-                                       uint32_t *sse1,
-                                       uint32_t *distortion) {
-#if CONFIG_VP9_HIGHBITDEPTH
-  uint64_t besterr;
-  if (second_pred != NULL) {
-    if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
-      DECLARE_ALIGNED(16, uint16_t, comp_pred16[64 * 64]);
-      vpx_highbd_comp_avg_pred(comp_pred16, second_pred, w, h, y + offset,
-                               y_stride);
-      besterr = vfp->vf(CONVERT_TO_BYTEPTR(comp_pred16), w, src, src_stride,
-                        sse1);
-    } else {
-      DECLARE_ALIGNED(16, uint8_t, comp_pred[64 * 64]);
-      vpx_comp_avg_pred(comp_pred, second_pred, w, h, y + offset, y_stride);
-      besterr = vfp->vf(comp_pred, w, src, src_stride, sse1);
-    }
-  } else {
-    besterr = vfp->vf(y + offset, y_stride, src, src_stride, sse1);
-  }
-  *distortion = (uint32_t)besterr;
-  besterr += mv_err_cost(bestmv, ref_mv, mvjcost, mvcost, error_per_bit);
-  if (besterr >= UINT32_MAX)
-    return UINT32_MAX;
-  return (uint32_t)besterr;
-#else
-  uint32_t besterr;
-  (void) xd;
-  if (second_pred != NULL) {
-    DECLARE_ALIGNED(16, uint8_t, comp_pred[64 * 64]);
-    vpx_comp_avg_pred(comp_pred, second_pred, w, h, y + offset, y_stride);
-    besterr = vfp->vf(comp_pred, w, src, src_stride, sse1);
-  } else {
-    besterr = vfp->vf(y + offset, y_stride, src, src_stride, sse1);
-  }
-  *distortion = besterr;
-  besterr += mv_err_cost(bestmv, ref_mv, mvjcost, mvcost, error_per_bit);
-  return besterr;
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-}
-
-static INLINE int divide_and_round(const int n, const int d) {
-  return ((n < 0) ^ (d < 0)) ? ((n - d / 2) / d) : ((n + d / 2) / d);
-}
-
-static INLINE int is_cost_list_wellbehaved(int *cost_list) {
-  return cost_list[0] < cost_list[1] &&
-         cost_list[0] < cost_list[2] &&
-         cost_list[0] < cost_list[3] &&
-         cost_list[0] < cost_list[4];
-}
-
-// Returns surface minima estimate at given precision in 1/2^n bits.
-// Assume a model for the cost surface: S = A(x - x0)^2 + B(y - y0)^2 + C
-// For a given set of costs S0, S1, S2, S3, S4 at points
-// (y, x) = (0, 0), (0, -1), (1, 0), (0, 1) and (-1, 0) respectively,
-// the solution for the location of the minima (x0, y0) is given by:
-// x0 = 1/2 (S1 - S3)/(S1 + S3 - 2*S0),
-// y0 = 1/2 (S4 - S2)/(S4 + S2 - 2*S0).
-// The code below is an integerized version of that.
-static void get_cost_surf_min(int *cost_list, int *ir, int *ic,
-                              int bits) {
-  *ic = divide_and_round((cost_list[1] - cost_list[3]) * (1 << (bits - 1)),
-                         (cost_list[1] - 2 * cost_list[0] + cost_list[3]));
-  *ir = divide_and_round((cost_list[4] - cost_list[2]) * (1 << (bits - 1)),
-                         (cost_list[4] - 2 * cost_list[0] + cost_list[2]));
-}
-
-uint32_t vp9_skip_sub_pixel_tree(
-    const MACROBLOCK *x,
-    MV *bestmv, const MV *ref_mv,
-    int allow_hp,
-    int error_per_bit,
-    const vp9_variance_fn_ptr_t *vfp,
-    int forced_stop,
-    int iters_per_step,
-    int *cost_list,
-    int *mvjcost, int *mvcost[2],
-    uint32_t *distortion,
-    uint32_t *sse1,
-    const uint8_t *second_pred,
-    int w, int h) {
-  SETUP_SUBPEL_SEARCH;
-  besterr = setup_center_error(xd, bestmv, ref_mv, error_per_bit, vfp,
-                               z, src_stride, y, y_stride, second_pred,
-                               w, h, offset, mvjcost, mvcost,
-                               sse1, distortion);
-  (void) halfiters;
-  (void) quarteriters;
-  (void) eighthiters;
-  (void) whichdir;
-  (void) allow_hp;
-  (void) forced_stop;
-  (void) hstep;
-  (void) rr;
-  (void) rc;
-  (void) minr;
-  (void) minc;
-  (void) maxr;
-  (void) maxc;
-  (void) tr;
-  (void) tc;
-  (void) sse;
-  (void) thismse;
-  (void) cost_list;
-
-  if ((abs(bestmv->col - ref_mv->col) > (MAX_FULL_PEL_VAL << 3)) ||
-      (abs(bestmv->row - ref_mv->row) > (MAX_FULL_PEL_VAL << 3)))
-    return INT_MAX;
-
-  return besterr;
-}
-
-uint32_t vp9_find_best_sub_pixel_tree_pruned_evenmore(
-    const MACROBLOCK *x,
-    MV *bestmv, const MV *ref_mv,
-    int allow_hp,
-    int error_per_bit,
-    const vp9_variance_fn_ptr_t *vfp,
-    int forced_stop,
-    int iters_per_step,
-    int *cost_list,
-    int *mvjcost, int *mvcost[2],
-    uint32_t *distortion,
-    uint32_t *sse1,
-    const uint8_t *second_pred,
-    int w, int h) {
-  SETUP_SUBPEL_SEARCH;
-  besterr = setup_center_error(xd, bestmv, ref_mv, error_per_bit, vfp,
-                               z, src_stride, y, y_stride, second_pred,
-                               w, h, offset, mvjcost, mvcost,
-                               sse1, distortion);
-  (void) halfiters;
-  (void) quarteriters;
-  (void) eighthiters;
-  (void) whichdir;
-  (void) allow_hp;
-  (void) forced_stop;
-  (void) hstep;
-
-  if (cost_list &&
-      cost_list[0] != INT_MAX && cost_list[1] != INT_MAX &&
-      cost_list[2] != INT_MAX && cost_list[3] != INT_MAX &&
-      cost_list[4] != INT_MAX &&
-      is_cost_list_wellbehaved(cost_list)) {
-    int ir, ic;
-    unsigned int minpt;
-    get_cost_surf_min(cost_list, &ir, &ic, 2);
-    if (ir != 0 || ic != 0) {
-      CHECK_BETTER(minpt, tr + 2 * ir, tc + 2 * ic);
-    }
-  } else {
-    FIRST_LEVEL_CHECKS;
-    if (halfiters > 1) {
-      SECOND_LEVEL_CHECKS;
-    }
-
-    tr = br;
-    tc = bc;
-
-    // Each subsequent iteration checks at least one point in common with
-    // the last iteration could be 2 ( if diag selected) 1/4 pel
-    // Note forced_stop: 0 - full, 1 - qtr only, 2 - half only
-    if (forced_stop != 2) {
-      hstep >>= 1;
-      FIRST_LEVEL_CHECKS;
-      if (quarteriters > 1) {
-        SECOND_LEVEL_CHECKS;
-      }
-    }
-  }
-
-  tr = br;
-  tc = bc;
-
-  if (allow_hp && use_mv_hp(ref_mv) && forced_stop == 0) {
-    hstep >>= 1;
-    FIRST_LEVEL_CHECKS;
-    if (eighthiters > 1) {
-      SECOND_LEVEL_CHECKS;
-    }
-  }
-
-  bestmv->row = br;
-  bestmv->col = bc;
-
-  if ((abs(bestmv->col - ref_mv->col) > (MAX_FULL_PEL_VAL << 3)) ||
-      (abs(bestmv->row - ref_mv->row) > (MAX_FULL_PEL_VAL << 3)))
-    return INT_MAX;
-
-  return besterr;
-}
-
-uint32_t vp9_find_best_sub_pixel_tree_pruned_more(const MACROBLOCK *x,
-                                             MV *bestmv, const MV *ref_mv,
-                                             int allow_hp,
-                                             int error_per_bit,
-                                             const vp9_variance_fn_ptr_t *vfp,
-                                             int forced_stop,
-                                             int iters_per_step,
-                                             int *cost_list,
-                                             int *mvjcost, int *mvcost[2],
-                                             uint32_t *distortion,
-                                             uint32_t *sse1,
-                                             const uint8_t *second_pred,
-                                             int w, int h) {
-  SETUP_SUBPEL_SEARCH;
-  besterr = setup_center_error(xd, bestmv, ref_mv, error_per_bit, vfp,
-                               z, src_stride, y, y_stride, second_pred,
-                               w, h, offset, mvjcost, mvcost,
-                               sse1, distortion);
-  if (cost_list &&
-      cost_list[0] != INT_MAX && cost_list[1] != INT_MAX &&
-      cost_list[2] != INT_MAX && cost_list[3] != INT_MAX &&
-      cost_list[4] != INT_MAX &&
-      is_cost_list_wellbehaved(cost_list)) {
-    unsigned int minpt;
-    int ir, ic;
-    get_cost_surf_min(cost_list, &ir, &ic, 1);
-    if (ir != 0 || ic != 0) {
-      CHECK_BETTER(minpt, tr + ir * hstep, tc + ic * hstep);
-    }
-  } else {
-    FIRST_LEVEL_CHECKS;
-    if (halfiters > 1) {
-      SECOND_LEVEL_CHECKS;
-    }
-  }
-
-  // Each subsequent iteration checks at least one point in common with
-  // the last iteration could be 2 ( if diag selected) 1/4 pel
-
-  // Note forced_stop: 0 - full, 1 - qtr only, 2 - half only
-  if (forced_stop != 2) {
-    tr = br;
-    tc = bc;
-    hstep >>= 1;
-    FIRST_LEVEL_CHECKS;
-    if (quarteriters > 1) {
-      SECOND_LEVEL_CHECKS;
-    }
-  }
-
-  if (allow_hp && use_mv_hp(ref_mv) && forced_stop == 0) {
-    tr = br;
-    tc = bc;
-    hstep >>= 1;
-    FIRST_LEVEL_CHECKS;
-    if (eighthiters > 1) {
-      SECOND_LEVEL_CHECKS;
-    }
-  }
-  // These lines insure static analysis doesn't warn that
-  // tr and tc aren't used after the above point.
-  (void) tr;
-  (void) tc;
-
-  bestmv->row = br;
-  bestmv->col = bc;
-
-  if ((abs(bestmv->col - ref_mv->col) > (MAX_FULL_PEL_VAL << 3)) ||
-      (abs(bestmv->row - ref_mv->row) > (MAX_FULL_PEL_VAL << 3)))
-    return INT_MAX;
-
-  return besterr;
-}
-
-uint32_t vp9_find_best_sub_pixel_tree_pruned(const MACROBLOCK *x,
-                                        MV *bestmv, const MV *ref_mv,
-                                        int allow_hp,
-                                        int error_per_bit,
-                                        const vp9_variance_fn_ptr_t *vfp,
-                                        int forced_stop,
-                                        int iters_per_step,
-                                        int *cost_list,
-                                        int *mvjcost, int *mvcost[2],
-                                        uint32_t *distortion,
-                                        uint32_t *sse1,
-                                        const uint8_t *second_pred,
-                                        int w, int h) {
-  SETUP_SUBPEL_SEARCH;
-  besterr = setup_center_error(xd, bestmv, ref_mv, error_per_bit, vfp,
-                               z, src_stride, y, y_stride, second_pred,
-                               w, h, offset, mvjcost, mvcost,
-                               sse1, distortion);
-  if (cost_list &&
-      cost_list[0] != INT_MAX && cost_list[1] != INT_MAX &&
-      cost_list[2] != INT_MAX && cost_list[3] != INT_MAX &&
-      cost_list[4] != INT_MAX) {
-    unsigned int left, right, up, down, diag;
-    whichdir = (cost_list[1] < cost_list[3] ? 0 : 1) +
-               (cost_list[2] < cost_list[4] ? 0 : 2);
-    switch (whichdir) {
-      case 0:
-        CHECK_BETTER(left, tr, tc - hstep);
-        CHECK_BETTER(down, tr + hstep, tc);
-        CHECK_BETTER(diag, tr + hstep, tc - hstep);
-        break;
-      case 1:
-        CHECK_BETTER(right, tr, tc + hstep);
-        CHECK_BETTER(down, tr + hstep, tc);
-        CHECK_BETTER(diag, tr + hstep, tc + hstep);
-        break;
-      case 2:
-        CHECK_BETTER(left, tr, tc - hstep);
-        CHECK_BETTER(up, tr - hstep, tc);
-        CHECK_BETTER(diag, tr - hstep, tc - hstep);
-        break;
-      case 3:
-        CHECK_BETTER(right, tr, tc + hstep);
-        CHECK_BETTER(up, tr - hstep, tc);
-        CHECK_BETTER(diag, tr - hstep, tc + hstep);
-        break;
-    }
-  } else {
-    FIRST_LEVEL_CHECKS;
-    if (halfiters > 1) {
-      SECOND_LEVEL_CHECKS;
-    }
-  }
-
-  tr = br;
-  tc = bc;
-
-  // Each subsequent iteration checks at least one point in common with
-  // the last iteration could be 2 ( if diag selected) 1/4 pel
-
-  // Note forced_stop: 0 - full, 1 - qtr only, 2 - half only
-  if (forced_stop != 2) {
-    hstep >>= 1;
-    FIRST_LEVEL_CHECKS;
-    if (quarteriters > 1) {
-      SECOND_LEVEL_CHECKS;
-    }
-    tr = br;
-    tc = bc;
-  }
-
-  if (allow_hp && use_mv_hp(ref_mv) && forced_stop == 0) {
-    hstep >>= 1;
-    FIRST_LEVEL_CHECKS;
-    if (eighthiters > 1) {
-      SECOND_LEVEL_CHECKS;
-    }
-    tr = br;
-    tc = bc;
-  }
-  // These lines insure static analysis doesn't warn that
-  // tr and tc aren't used after the above point.
-  (void) tr;
-  (void) tc;
-
-  bestmv->row = br;
-  bestmv->col = bc;
-
-  if ((abs(bestmv->col - ref_mv->col) > (MAX_FULL_PEL_VAL << 3)) ||
-      (abs(bestmv->row - ref_mv->row) > (MAX_FULL_PEL_VAL << 3)))
-    return INT_MAX;
-
-  return besterr;
-}
-
-static const MV search_step_table[12] = {
-    // left, right, up, down
-    {0, -4}, {0, 4}, {-4, 0}, {4, 0},
-    {0, -2}, {0, 2}, {-2, 0}, {2, 0},
-    {0, -1}, {0, 1}, {-1, 0}, {1, 0}
-};
-
-uint32_t vp9_find_best_sub_pixel_tree(const MACROBLOCK *x,
-                                      MV *bestmv, const MV *ref_mv,
-                                      int allow_hp,
-                                      int error_per_bit,
-                                      const vp9_variance_fn_ptr_t *vfp,
-                                      int forced_stop,
-                                      int iters_per_step,
-                                      int *cost_list,
-                                      int *mvjcost, int *mvcost[2],
-                                      uint32_t *distortion,
-                                      uint32_t *sse1,
-                                      const uint8_t *second_pred,
-                                      int w, int h) {
-  const uint8_t *const z = x->plane[0].src.buf;
-  const uint8_t *const src_address = z;
-  const int src_stride = x->plane[0].src.stride;
-  const MACROBLOCKD *xd = &x->e_mbd;
-  unsigned int besterr = INT_MAX;
-  unsigned int sse;
-  int thismse;
-  const int y_stride = xd->plane[0].pre[0].stride;
-  const int offset = bestmv->row * y_stride + bestmv->col;
-  const uint8_t *const y = xd->plane[0].pre[0].buf;
-
-  int rr = ref_mv->row;
-  int rc = ref_mv->col;
-  int br = bestmv->row * 8;
-  int bc = bestmv->col * 8;
-  int hstep = 4;
-  int iter, round = 3 - forced_stop;
-  const int minc = VPXMAX(x->mv_col_min * 8, ref_mv->col - MV_MAX);
-  const int maxc = VPXMIN(x->mv_col_max * 8, ref_mv->col + MV_MAX);
-  const int minr = VPXMAX(x->mv_row_min * 8, ref_mv->row - MV_MAX);
-  const int maxr = VPXMIN(x->mv_row_max * 8, ref_mv->row + MV_MAX);
-  int tr = br;
-  int tc = bc;
-  const MV *search_step = search_step_table;
-  int idx, best_idx = -1;
-  unsigned int cost_array[5];
-  int kr, kc;
-
-  if (!(allow_hp && use_mv_hp(ref_mv)))
-    if (round == 3)
-      round = 2;
-
-  bestmv->row *= 8;
-  bestmv->col *= 8;
-
-  besterr = setup_center_error(xd, bestmv, ref_mv, error_per_bit, vfp,
-                               z, src_stride, y, y_stride, second_pred,
-                               w, h, offset, mvjcost, mvcost,
-                               sse1, distortion);
-
-  (void) cost_list;  // to silence compiler warning
-
-  for (iter = 0; iter < round; ++iter) {
-    // Check vertical and horizontal sub-pixel positions.
-    for (idx = 0; idx < 4; ++idx) {
-      tr = br + search_step[idx].row;
-      tc = bc + search_step[idx].col;
-      if (tc >= minc && tc <= maxc && tr >= minr && tr <= maxr) {
-        const uint8_t *const pre_address = y + (tr >> 3) * y_stride + (tc >> 3);
-        MV this_mv;
-        this_mv.row = tr;
-        this_mv.col = tc;
-        if (second_pred == NULL)
-          thismse = vfp->svf(pre_address, y_stride, sp(tc), sp(tr),
-                             src_address, src_stride, &sse);
-        else
-          thismse = vfp->svaf(pre_address, y_stride, sp(tc), sp(tr),
-                              src_address, src_stride, &sse, second_pred);
-        cost_array[idx] = thismse +
-            mv_err_cost(&this_mv, ref_mv, mvjcost, mvcost, error_per_bit);
-
-        if (cost_array[idx] < besterr) {
-          best_idx = idx;
-          besterr = cost_array[idx];
-          *distortion = thismse;
-          *sse1 = sse;
-        }
-      } else {
-        cost_array[idx] = INT_MAX;
-      }
-    }
-
-    // Check diagonal sub-pixel position
-    kc = (cost_array[0] <= cost_array[1] ? -hstep : hstep);
-    kr = (cost_array[2] <= cost_array[3] ? -hstep : hstep);
-
-    tc = bc + kc;
-    tr = br + kr;
-    if (tc >= minc && tc <= maxc && tr >= minr && tr <= maxr) {
-      const uint8_t *const pre_address = y + (tr >> 3) * y_stride + (tc >> 3);
-      MV this_mv = {tr, tc};
-      if (second_pred == NULL)
-        thismse = vfp->svf(pre_address, y_stride, sp(tc), sp(tr),
-                           src_address, src_stride, &sse);
-      else
-        thismse = vfp->svaf(pre_address, y_stride, sp(tc), sp(tr),
-                            src_address, src_stride, &sse, second_pred);
-      cost_array[4] = thismse +
-          mv_err_cost(&this_mv, ref_mv, mvjcost, mvcost, error_per_bit);
-
-      if (cost_array[4] < besterr) {
-        best_idx = 4;
-        besterr = cost_array[4];
-        *distortion = thismse;
-        *sse1 = sse;
-      }
-    } else {
-      cost_array[idx] = INT_MAX;
-    }
-
-    if (best_idx < 4 && best_idx >= 0) {
-      br += search_step[best_idx].row;
-      bc += search_step[best_idx].col;
-    } else if (best_idx == 4) {
-      br = tr;
-      bc = tc;
-    }
-
-    if (iters_per_step > 1 && best_idx != -1)
-      SECOND_LEVEL_CHECKS_BEST;
-
-    tr = br;
-    tc = bc;
-
-    search_step += 4;
-    hstep >>= 1;
-    best_idx = -1;
-  }
-
-  // Each subsequent iteration checks at least one point in common with
-  // the last iteration could be 2 ( if diag selected) 1/4 pel
-
-  // These lines insure static analysis doesn't warn that
-  // tr and tc aren't used after the above point.
-  (void) tr;
-  (void) tc;
-
-  bestmv->row = br;
-  bestmv->col = bc;
-
-  if ((abs(bestmv->col - ref_mv->col) > (MAX_FULL_PEL_VAL << 3)) ||
-      (abs(bestmv->row - ref_mv->row) > (MAX_FULL_PEL_VAL << 3)))
-    return INT_MAX;
-
-  return besterr;
-}
-
-#undef MVC
-#undef CHECK_BETTER
-
-static INLINE int check_bounds(const MACROBLOCK *x, int row, int col,
-                               int range) {
-  return ((row - range) >= x->mv_row_min) &
-         ((row + range) <= x->mv_row_max) &
-         ((col - range) >= x->mv_col_min) &
-         ((col + range) <= x->mv_col_max);
-}
-
-static INLINE int is_mv_in(const MACROBLOCK *x, const MV *mv) {
-  return (mv->col >= x->mv_col_min) && (mv->col <= x->mv_col_max) &&
-         (mv->row >= x->mv_row_min) && (mv->row <= x->mv_row_max);
-}
-
-#define CHECK_BETTER \
-  {\
-    if (thissad < bestsad) {\
-      if (use_mvcost) \
-        thissad += mvsad_err_cost(x, &this_mv, &fcenter_mv, sad_per_bit);\
-      if (thissad < bestsad) {\
-        bestsad = thissad;\
-        best_site = i;\
-      }\
-    }\
-  }
-
-#define MAX_PATTERN_SCALES         11
-#define MAX_PATTERN_CANDIDATES      8  // max number of canddiates per scale
-#define PATTERN_CANDIDATES_REF      3  // number of refinement candidates
-
-// Calculate and return a sad+mvcost list around an integer best pel.
-static INLINE void calc_int_cost_list(const MACROBLOCK *x,
-                                      const MV *ref_mv,
-                                      int sadpb,
-                                      const vp9_variance_fn_ptr_t *fn_ptr,
-                                      const MV *best_mv,
-                                      int *cost_list) {
-  static const MV neighbors[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}};
-  const struct buf_2d *const what = &x->plane[0].src;
-  const struct buf_2d *const in_what = &x->e_mbd.plane[0].pre[0];
-  const MV fcenter_mv = {ref_mv->row >> 3, ref_mv->col >> 3};
-  int br = best_mv->row;
-  int bc = best_mv->col;
-  MV this_mv;
-  int i;
-  unsigned int sse;
-
-  this_mv.row = br;
-  this_mv.col = bc;
-  cost_list[0] = fn_ptr->vf(what->buf, what->stride,
-                            get_buf_from_mv(in_what, &this_mv),
-                            in_what->stride, &sse) +
-      mvsad_err_cost(x, &this_mv, &fcenter_mv, sadpb);
-  if (check_bounds(x, br, bc, 1)) {
-    for (i = 0; i < 4; i++) {
-      const MV this_mv = {br + neighbors[i].row,
-        bc + neighbors[i].col};
-      cost_list[i + 1] = fn_ptr->vf(what->buf, what->stride,
-                                    get_buf_from_mv(in_what, &this_mv),
-                                    in_what->stride, &sse) +
-                                    mv_err_cost(&this_mv, &fcenter_mv,
-                                                x->nmvjointcost, x->mvcost,
-                                                x->errorperbit);
-    }
-  } else {
-    for (i = 0; i < 4; i++) {
-      const MV this_mv = {br + neighbors[i].row,
-        bc + neighbors[i].col};
-      if (!is_mv_in(x, &this_mv))
-        cost_list[i + 1] = INT_MAX;
-      else
-        cost_list[i + 1] = fn_ptr->vf(what->buf, what->stride,
-                                      get_buf_from_mv(in_what, &this_mv),
-                                      in_what->stride, &sse) +
-                                      mv_err_cost(&this_mv, &fcenter_mv,
-                                                  x->nmvjointcost, x->mvcost,
-                                                  x->errorperbit);
-    }
-  }
-}
-
-// Generic pattern search function that searches over multiple scales.
-// Each scale can have a different number of candidates and shape of
-// candidates as indicated in the num_candidates and candidates arrays
-// passed into this function
-//
-static int vp9_pattern_search(const MACROBLOCK *x,
-                              MV *ref_mv,
-                              int search_param,
-                              int sad_per_bit,
-                              int do_init_search,
-                              int *cost_list,
-                              const vp9_variance_fn_ptr_t *vfp,
-                              int use_mvcost,
-                              const MV *center_mv,
-                              MV *best_mv,
-                              const int num_candidates[MAX_PATTERN_SCALES],
-                              const MV candidates[MAX_PATTERN_SCALES]
-                                                 [MAX_PATTERN_CANDIDATES]) {
-  const MACROBLOCKD *const xd = &x->e_mbd;
-  static const int search_param_to_steps[MAX_MVSEARCH_STEPS] = {
-    10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0,
-  };
-  int i, s, t;
-  const struct buf_2d *const what = &x->plane[0].src;
-  const struct buf_2d *const in_what = &xd->plane[0].pre[0];
-  int br, bc;
-  int bestsad = INT_MAX;
-  int thissad;
-  int k = -1;
-  const MV fcenter_mv = {center_mv->row >> 3, center_mv->col >> 3};
-  int best_init_s = search_param_to_steps[search_param];
-  // adjust ref_mv to make sure it is within MV range
-  clamp_mv(ref_mv, x->mv_col_min, x->mv_col_max, x->mv_row_min, x->mv_row_max);
-  br = ref_mv->row;
-  bc = ref_mv->col;
-
-  // Work out the start point for the search
-  bestsad = vfp->sdf(what->buf, what->stride,
-                     get_buf_from_mv(in_what, ref_mv), in_what->stride) +
-      mvsad_err_cost(x, ref_mv, &fcenter_mv, sad_per_bit);
-
-  // Search all possible scales upto the search param around the center point
-  // pick the scale of the point that is best as the starting scale of
-  // further steps around it.
-  if (do_init_search) {
-    s = best_init_s;
-    best_init_s = -1;
-    for (t = 0; t <= s; ++t) {
-      int best_site = -1;
-      if (check_bounds(x, br, bc, 1 << t)) {
-        for (i = 0; i < num_candidates[t]; i++) {
-          const MV this_mv = {br + candidates[t][i].row,
-                              bc + candidates[t][i].col};
-          thissad = vfp->sdf(what->buf, what->stride,
-                             get_buf_from_mv(in_what, &this_mv),
-                             in_what->stride);
-          CHECK_BETTER
-        }
-      } else {
-        for (i = 0; i < num_candidates[t]; i++) {
-          const MV this_mv = {br + candidates[t][i].row,
-                              bc + candidates[t][i].col};
-          if (!is_mv_in(x, &this_mv))
-            continue;
-          thissad = vfp->sdf(what->buf, what->stride,
-                             get_buf_from_mv(in_what, &this_mv),
-                             in_what->stride);
-          CHECK_BETTER
-        }
-      }
-      if (best_site == -1) {
-        continue;
-      } else {
-        best_init_s = t;
-        k = best_site;
-      }
-    }
-    if (best_init_s != -1) {
-      br += candidates[best_init_s][k].row;
-      bc += candidates[best_init_s][k].col;
-    }
-  }
-
-  // If the center point is still the best, just skip this and move to
-  // the refinement step.
-  if (best_init_s != -1) {
-    int best_site = -1;
-    s = best_init_s;
-
-    do {
-      // No need to search all 6 points the 1st time if initial search was used
-      if (!do_init_search || s != best_init_s) {
-        if (check_bounds(x, br, bc, 1 << s)) {
-          for (i = 0; i < num_candidates[s]; i++) {
-            const MV this_mv = {br + candidates[s][i].row,
-                                bc + candidates[s][i].col};
-            thissad = vfp->sdf(what->buf, what->stride,
-                               get_buf_from_mv(in_what, &this_mv),
-                               in_what->stride);
-            CHECK_BETTER
-          }
-        } else {
-          for (i = 0; i < num_candidates[s]; i++) {
-            const MV this_mv = {br + candidates[s][i].row,
-                                bc + candidates[s][i].col};
-            if (!is_mv_in(x, &this_mv))
-              continue;
-            thissad = vfp->sdf(what->buf, what->stride,
-                               get_buf_from_mv(in_what, &this_mv),
-                               in_what->stride);
-            CHECK_BETTER
-          }
-        }
-
-        if (best_site == -1) {
-          continue;
-        } else {
-          br += candidates[s][best_site].row;
-          bc += candidates[s][best_site].col;
-          k = best_site;
-        }
-      }
-
-      do {
-        int next_chkpts_indices[PATTERN_CANDIDATES_REF];
-        best_site = -1;
-        next_chkpts_indices[0] = (k == 0) ? num_candidates[s] - 1 : k - 1;
-        next_chkpts_indices[1] = k;
-        next_chkpts_indices[2] = (k == num_candidates[s] - 1) ? 0 : k + 1;
-
-        if (check_bounds(x, br, bc, 1 << s)) {
-          for (i = 0; i < PATTERN_CANDIDATES_REF; i++) {
-            const MV this_mv = {br + candidates[s][next_chkpts_indices[i]].row,
-                                bc + candidates[s][next_chkpts_indices[i]].col};
-            thissad = vfp->sdf(what->buf, what->stride,
-                               get_buf_from_mv(in_what, &this_mv),
-                               in_what->stride);
-            CHECK_BETTER
-          }
-        } else {
-          for (i = 0; i < PATTERN_CANDIDATES_REF; i++) {
-            const MV this_mv = {br + candidates[s][next_chkpts_indices[i]].row,
-                                bc + candidates[s][next_chkpts_indices[i]].col};
-            if (!is_mv_in(x, &this_mv))
-              continue;
-            thissad = vfp->sdf(what->buf, what->stride,
-                               get_buf_from_mv(in_what, &this_mv),
-                               in_what->stride);
-            CHECK_BETTER
-          }
-        }
-
-        if (best_site != -1) {
-          k = next_chkpts_indices[best_site];
-          br += candidates[s][k].row;
-          bc += candidates[s][k].col;
-        }
-      } while (best_site != -1);
-    } while (s--);
-  }
-
-  // Returns the one-away integer pel sad values around the best as follows:
-  // cost_list[0]: cost at the best integer pel
-  // cost_list[1]: cost at delta {0, -1} (left)   from the best integer pel
-  // cost_list[2]: cost at delta { 1, 0} (bottom) from the best integer pel
-  // cost_list[3]: cost at delta { 0, 1} (right)  from the best integer pel
-  // cost_list[4]: cost at delta {-1, 0} (top)    from the best integer pel
-  if (cost_list) {
-    const MV best_mv = { br, bc };
-    calc_int_cost_list(x, &fcenter_mv, sad_per_bit, vfp, &best_mv, cost_list);
-  }
-  best_mv->row = br;
-  best_mv->col = bc;
-  return bestsad;
-}
-
-// A specialized function where the smallest scale search candidates
-// are 4 1-away neighbors, and cost_list is non-null
-// TODO(debargha): Merge this function with the one above. Also remove
-// use_mvcost option since it is always 1, to save unnecessary branches.
-static int vp9_pattern_search_sad(const MACROBLOCK *x,
-                                  MV *ref_mv,
-                                  int search_param,
-                                  int sad_per_bit,
-                                  int do_init_search,
-                                  int *cost_list,
-                                  const vp9_variance_fn_ptr_t *vfp,
-                                  int use_mvcost,
-                                  const MV *center_mv,
-                                  MV *best_mv,
-                                  const int num_candidates[MAX_PATTERN_SCALES],
-                                  const MV candidates[MAX_PATTERN_SCALES]
-                                                     [MAX_PATTERN_CANDIDATES]) {
-  const MACROBLOCKD *const xd = &x->e_mbd;
-  static const int search_param_to_steps[MAX_MVSEARCH_STEPS] = {
-    10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0,
-  };
-  int i, s, t;
-  const struct buf_2d *const what = &x->plane[0].src;
-  const struct buf_2d *const in_what = &xd->plane[0].pre[0];
-  int br, bc;
-  int bestsad = INT_MAX;
-  int thissad;
-  int k = -1;
-  const MV fcenter_mv = {center_mv->row >> 3, center_mv->col >> 3};
-  int best_init_s = search_param_to_steps[search_param];
-  // adjust ref_mv to make sure it is within MV range
-  clamp_mv(ref_mv, x->mv_col_min, x->mv_col_max, x->mv_row_min, x->mv_row_max);
-  br = ref_mv->row;
-  bc = ref_mv->col;
-  if (cost_list != NULL) {
-    cost_list[0] = cost_list[1] = cost_list[2] = cost_list[3] = cost_list[4] =
-        INT_MAX;
-  }
-
-  // Work out the start point for the search
-  bestsad = vfp->sdf(what->buf, what->stride,
-                     get_buf_from_mv(in_what, ref_mv), in_what->stride) +
-      mvsad_err_cost(x, ref_mv, &fcenter_mv, sad_per_bit);
-
-  // Search all possible scales upto the search param around the center point
-  // pick the scale of the point that is best as the starting scale of
-  // further steps around it.
-  if (do_init_search) {
-    s = best_init_s;
-    best_init_s = -1;
-    for (t = 0; t <= s; ++t) {
-      int best_site = -1;
-      if (check_bounds(x, br, bc, 1 << t)) {
-        for (i = 0; i < num_candidates[t]; i++) {
-          const MV this_mv = {br + candidates[t][i].row,
-                              bc + candidates[t][i].col};
-          thissad = vfp->sdf(what->buf, what->stride,
-                             get_buf_from_mv(in_what, &this_mv),
-                             in_what->stride);
-          CHECK_BETTER
-        }
-      } else {
-        for (i = 0; i < num_candidates[t]; i++) {
-          const MV this_mv = {br + candidates[t][i].row,
-                              bc + candidates[t][i].col};
-          if (!is_mv_in(x, &this_mv))
-            continue;
-          thissad = vfp->sdf(what->buf, what->stride,
-                             get_buf_from_mv(in_what, &this_mv),
-                             in_what->stride);
-          CHECK_BETTER
-        }
-      }
-      if (best_site == -1) {
-        continue;
-      } else {
-        best_init_s = t;
-        k = best_site;
-      }
-    }
-    if (best_init_s != -1) {
-      br += candidates[best_init_s][k].row;
-      bc += candidates[best_init_s][k].col;
-    }
-  }
-
-  // If the center point is still the best, just skip this and move to
-  // the refinement step.
-  if (best_init_s != -1) {
-    int do_sad = (num_candidates[0] == 4 && cost_list != NULL);
-    int best_site = -1;
-    s = best_init_s;
-
-    for (; s >= do_sad; s--) {
-      if (!do_init_search || s != best_init_s) {
-        if (check_bounds(x, br, bc, 1 << s)) {
-          for (i = 0; i < num_candidates[s]; i++) {
-            const MV this_mv = {br + candidates[s][i].row,
-                                bc + candidates[s][i].col};
-            thissad = vfp->sdf(what->buf, what->stride,
-                               get_buf_from_mv(in_what, &this_mv),
-                               in_what->stride);
-            CHECK_BETTER
-          }
-        } else {
-          for (i = 0; i < num_candidates[s]; i++) {
-            const MV this_mv = {br + candidates[s][i].row,
-                                bc + candidates[s][i].col};
-            if (!is_mv_in(x, &this_mv))
-              continue;
-            thissad = vfp->sdf(what->buf, what->stride,
-                               get_buf_from_mv(in_what, &this_mv),
-                               in_what->stride);
-            CHECK_BETTER
-          }
-        }
-
-        if (best_site == -1) {
-          continue;
-        } else {
-          br += candidates[s][best_site].row;
-          bc += candidates[s][best_site].col;
-          k = best_site;
-        }
-      }
-
-      do {
-        int next_chkpts_indices[PATTERN_CANDIDATES_REF];
-        best_site = -1;
-        next_chkpts_indices[0] = (k == 0) ? num_candidates[s] - 1 : k - 1;
-        next_chkpts_indices[1] = k;
-        next_chkpts_indices[2] = (k == num_candidates[s] - 1) ? 0 : k + 1;
-
-        if (check_bounds(x, br, bc, 1 << s)) {
-          for (i = 0; i < PATTERN_CANDIDATES_REF; i++) {
-            const MV this_mv = {br + candidates[s][next_chkpts_indices[i]].row,
-                                bc + candidates[s][next_chkpts_indices[i]].col};
-            thissad = vfp->sdf(what->buf, what->stride,
-                               get_buf_from_mv(in_what, &this_mv),
-                               in_what->stride);
-            CHECK_BETTER
-          }
-        } else {
-          for (i = 0; i < PATTERN_CANDIDATES_REF; i++) {
-            const MV this_mv = {br + candidates[s][next_chkpts_indices[i]].row,
-                                bc + candidates[s][next_chkpts_indices[i]].col};
-            if (!is_mv_in(x, &this_mv))
-              continue;
-            thissad = vfp->sdf(what->buf, what->stride,
-                               get_buf_from_mv(in_what, &this_mv),
-                               in_what->stride);
-            CHECK_BETTER
-          }
-        }
-
-        if (best_site != -1) {
-          k = next_chkpts_indices[best_site];
-          br += candidates[s][k].row;
-          bc += candidates[s][k].col;
-        }
-      } while (best_site != -1);
-    }
-
-    // Note: If we enter the if below, then cost_list must be non-NULL.
-    if (s == 0) {
-      cost_list[0] = bestsad;
-      if (!do_init_search || s != best_init_s) {
-        if (check_bounds(x, br, bc, 1 << s)) {
-          for (i = 0; i < num_candidates[s]; i++) {
-            const MV this_mv = {br + candidates[s][i].row,
-                                bc + candidates[s][i].col};
-            cost_list[i + 1] =
-            thissad = vfp->sdf(what->buf, what->stride,
-                               get_buf_from_mv(in_what, &this_mv),
-                               in_what->stride);
-            CHECK_BETTER
-          }
-        } else {
-          for (i = 0; i < num_candidates[s]; i++) {
-            const MV this_mv = {br + candidates[s][i].row,
-                                bc + candidates[s][i].col};
-            if (!is_mv_in(x, &this_mv))
-              continue;
-            cost_list[i + 1] =
-            thissad = vfp->sdf(what->buf, what->stride,
-                               get_buf_from_mv(in_what, &this_mv),
-                               in_what->stride);
-            CHECK_BETTER
-          }
-        }
-
-        if (best_site != -1) {
-          br += candidates[s][best_site].row;
-          bc += candidates[s][best_site].col;
-          k = best_site;
-        }
-      }
-      while (best_site != -1) {
-        int next_chkpts_indices[PATTERN_CANDIDATES_REF];
-        best_site = -1;
-        next_chkpts_indices[0] = (k == 0) ? num_candidates[s] - 1 : k - 1;
-        next_chkpts_indices[1] = k;
-        next_chkpts_indices[2] = (k == num_candidates[s] - 1) ? 0 : k + 1;
-        cost_list[1] = cost_list[2] = cost_list[3] = cost_list[4] = INT_MAX;
-        cost_list[((k + 2) % 4) + 1] = cost_list[0];
-        cost_list[0] = bestsad;
-
-        if (check_bounds(x, br, bc, 1 << s)) {
-          for (i = 0; i < PATTERN_CANDIDATES_REF; i++) {
-            const MV this_mv = {br + candidates[s][next_chkpts_indices[i]].row,
-                                bc + candidates[s][next_chkpts_indices[i]].col};
-            cost_list[next_chkpts_indices[i] + 1] =
-            thissad = vfp->sdf(what->buf, what->stride,
-                               get_buf_from_mv(in_what, &this_mv),
-                               in_what->stride);
-            CHECK_BETTER
-          }
-        } else {
-          for (i = 0; i < PATTERN_CANDIDATES_REF; i++) {
-            const MV this_mv = {br + candidates[s][next_chkpts_indices[i]].row,
-                                bc + candidates[s][next_chkpts_indices[i]].col};
-            if (!is_mv_in(x, &this_mv)) {
-              cost_list[next_chkpts_indices[i] + 1] = INT_MAX;
-              continue;
-            }
-            cost_list[next_chkpts_indices[i] + 1] =
-            thissad = vfp->sdf(what->buf, what->stride,
-                               get_buf_from_mv(in_what, &this_mv),
-                               in_what->stride);
-            CHECK_BETTER
-          }
-        }
-
-        if (best_site != -1) {
-          k = next_chkpts_indices[best_site];
-          br += candidates[s][k].row;
-          bc += candidates[s][k].col;
-        }
-      }
-    }
-  }
-
-  // Returns the one-away integer pel sad values around the best as follows:
-  // cost_list[0]: sad at the best integer pel
-  // cost_list[1]: sad at delta {0, -1} (left)   from the best integer pel
-  // cost_list[2]: sad at delta { 1, 0} (bottom) from the best integer pel
-  // cost_list[3]: sad at delta { 0, 1} (right)  from the best integer pel
-  // cost_list[4]: sad at delta {-1, 0} (top)    from the best integer pel
-  if (cost_list) {
-    static const MV neighbors[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}};
-    if (cost_list[0] == INT_MAX) {
-      cost_list[0] = bestsad;
-      if (check_bounds(x, br, bc, 1)) {
-        for (i = 0; i < 4; i++) {
-          const MV this_mv = { br + neighbors[i].row,
-                               bc + neighbors[i].col };
-          cost_list[i + 1] = vfp->sdf(what->buf, what->stride,
-                                     get_buf_from_mv(in_what, &this_mv),
-                                     in_what->stride);
-        }
-      } else {
-        for (i = 0; i < 4; i++) {
-          const MV this_mv = {br + neighbors[i].row,
-            bc + neighbors[i].col};
-          if (!is_mv_in(x, &this_mv))
-            cost_list[i + 1] = INT_MAX;
-          else
-            cost_list[i + 1] = vfp->sdf(what->buf, what->stride,
-                                       get_buf_from_mv(in_what, &this_mv),
-                                       in_what->stride);
-        }
-      }
-    } else {
-      if (use_mvcost) {
-        for (i = 0; i < 4; i++) {
-          const MV this_mv = {br + neighbors[i].row,
-            bc + neighbors[i].col};
-          if (cost_list[i + 1] != INT_MAX) {
-            cost_list[i + 1] +=
-                mvsad_err_cost(x, &this_mv, &fcenter_mv, sad_per_bit);
-          }
-        }
-      }
-    }
-  }
-  best_mv->row = br;
-  best_mv->col = bc;
-  return bestsad;
-}
-
-int vp9_get_mvpred_var(const MACROBLOCK *x,
-                       const MV *best_mv, const MV *center_mv,
-                       const vp9_variance_fn_ptr_t *vfp,
-                       int use_mvcost) {
-  const MACROBLOCKD *const xd = &x->e_mbd;
-  const struct buf_2d *const what = &x->plane[0].src;
-  const struct buf_2d *const in_what = &xd->plane[0].pre[0];
-  const MV mv = {best_mv->row * 8, best_mv->col * 8};
-  uint32_t unused;
-#if CONFIG_VP9_HIGHBITDEPTH
-  uint64_t err= vfp->vf(what->buf, what->stride,
-                        get_buf_from_mv(in_what, best_mv),
-                        in_what->stride, &unused);
-  err += (use_mvcost ?  mv_err_cost(&mv, center_mv, x->nmvjointcost,
-                                    x->mvcost, x->errorperbit) : 0);
-  if (err >= INT_MAX)
-    return INT_MAX;
-  return (int)err;
-#else
-  return vfp->vf(what->buf, what->stride,
-                 get_buf_from_mv(in_what, best_mv), in_what->stride, &unused) +
-      (use_mvcost ?  mv_err_cost(&mv, center_mv, x->nmvjointcost,
-                                 x->mvcost, x->errorperbit) : 0);
-#endif
-}
-
-int vp9_get_mvpred_av_var(const MACROBLOCK *x,
-                          const MV *best_mv, const MV *center_mv,
-                          const uint8_t *second_pred,
-                          const vp9_variance_fn_ptr_t *vfp,
-                          int use_mvcost) {
-  const MACROBLOCKD *const xd = &x->e_mbd;
-  const struct buf_2d *const what = &x->plane[0].src;
-  const struct buf_2d *const in_what = &xd->plane[0].pre[0];
-  const MV mv = {best_mv->row * 8, best_mv->col * 8};
-  unsigned int unused;
-
-  return vfp->svaf(get_buf_from_mv(in_what, best_mv), in_what->stride, 0, 0,
-                   what->buf, what->stride, &unused, second_pred) +
-      (use_mvcost ?  mv_err_cost(&mv, center_mv, x->nmvjointcost,
-                                 x->mvcost, x->errorperbit) : 0);
-}
-
-static int hex_search(const MACROBLOCK *x,
-                      MV *ref_mv,
-                      int search_param,
-                      int sad_per_bit,
-                      int do_init_search,
-                      int *cost_list,
-                      const vp9_variance_fn_ptr_t *vfp,
-                      int use_mvcost,
-                      const MV *center_mv, MV *best_mv) {
-  // First scale has 8-closest points, the rest have 6 points in hex shape
-  // at increasing scales
-  static const int hex_num_candidates[MAX_PATTERN_SCALES] = {
-    8, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6
-  };
-  // Note that the largest candidate step at each scale is 2^scale
-  static const MV hex_candidates[MAX_PATTERN_SCALES][MAX_PATTERN_CANDIDATES] = {
-    {{-1, -1}, {0, -1}, {1, -1}, {1, 0}, {1, 1}, { 0, 1}, { -1, 1}, {-1, 0}},
-    {{-1, -2}, {1, -2}, {2, 0}, {1, 2}, { -1, 2}, { -2, 0}},
-    {{-2, -4}, {2, -4}, {4, 0}, {2, 4}, { -2, 4}, { -4, 0}},
-    {{-4, -8}, {4, -8}, {8, 0}, {4, 8}, { -4, 8}, { -8, 0}},
-    {{-8, -16}, {8, -16}, {16, 0}, {8, 16}, { -8, 16}, { -16, 0}},
-    {{-16, -32}, {16, -32}, {32, 0}, {16, 32}, { -16, 32}, { -32, 0}},
-    {{-32, -64}, {32, -64}, {64, 0}, {32, 64}, { -32, 64}, { -64, 0}},
-    {{-64, -128}, {64, -128}, {128, 0}, {64, 128}, { -64, 128}, { -128, 0}},
-    {{-128, -256}, {128, -256}, {256, 0}, {128, 256}, { -128, 256}, { -256, 0}},
-    {{-256, -512}, {256, -512}, {512, 0}, {256, 512}, { -256, 512}, { -512, 0}},
-    {{-512, -1024}, {512, -1024}, {1024, 0}, {512, 1024}, { -512, 1024},
-      { -1024, 0}},
-  };
-  return vp9_pattern_search(x, ref_mv, search_param, sad_per_bit,
-                            do_init_search, cost_list, vfp, use_mvcost,
-                            center_mv, best_mv,
-                            hex_num_candidates, hex_candidates);
-}
-
-static int bigdia_search(const MACROBLOCK *x,
-                         MV *ref_mv,
-                         int search_param,
-                         int sad_per_bit,
-                         int do_init_search,
-                         int *cost_list,
-                         const vp9_variance_fn_ptr_t *vfp,
-                         int use_mvcost,
-                         const MV *center_mv,
-                         MV *best_mv) {
-  // First scale has 4-closest points, the rest have 8 points in diamond
-  // shape at increasing scales
-  static const int bigdia_num_candidates[MAX_PATTERN_SCALES] = {
-    4, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
-  };
-  // Note that the largest candidate step at each scale is 2^scale
-  static const MV bigdia_candidates[MAX_PATTERN_SCALES]
-                                   [MAX_PATTERN_CANDIDATES] = {
-    {{0, -1}, {1, 0}, { 0, 1}, {-1, 0}},
-    {{-1, -1}, {0, -2}, {1, -1}, {2, 0}, {1, 1}, {0, 2}, {-1, 1}, {-2, 0}},
-    {{-2, -2}, {0, -4}, {2, -2}, {4, 0}, {2, 2}, {0, 4}, {-2, 2}, {-4, 0}},
-    {{-4, -4}, {0, -8}, {4, -4}, {8, 0}, {4, 4}, {0, 8}, {-4, 4}, {-8, 0}},
-    {{-8, -8}, {0, -16}, {8, -8}, {16, 0}, {8, 8}, {0, 16}, {-8, 8}, {-16, 0}},
-    {{-16, -16}, {0, -32}, {16, -16}, {32, 0}, {16, 16}, {0, 32},
-      {-16, 16}, {-32, 0}},
-    {{-32, -32}, {0, -64}, {32, -32}, {64, 0}, {32, 32}, {0, 64},
-      {-32, 32}, {-64, 0}},
-    {{-64, -64}, {0, -128}, {64, -64}, {128, 0}, {64, 64}, {0, 128},
-      {-64, 64}, {-128, 0}},
-    {{-128, -128}, {0, -256}, {128, -128}, {256, 0}, {128, 128}, {0, 256},
-      {-128, 128}, {-256, 0}},
-    {{-256, -256}, {0, -512}, {256, -256}, {512, 0}, {256, 256}, {0, 512},
-      {-256, 256}, {-512, 0}},
-    {{-512, -512}, {0, -1024}, {512, -512}, {1024, 0}, {512, 512}, {0, 1024},
-      {-512, 512}, {-1024, 0}},
-  };
-  return vp9_pattern_search_sad(x, ref_mv, search_param, sad_per_bit,
-                                do_init_search, cost_list, vfp, use_mvcost,
-                                center_mv, best_mv,
-                                bigdia_num_candidates, bigdia_candidates);
-}
-
-static int square_search(const MACROBLOCK *x,
-                         MV *ref_mv,
-                         int search_param,
-                         int sad_per_bit,
-                         int do_init_search,
-                         int *cost_list,
-                         const vp9_variance_fn_ptr_t *vfp,
-                         int use_mvcost,
-                         const MV *center_mv,
-                         MV *best_mv) {
-  // All scales have 8 closest points in square shape
-  static const int square_num_candidates[MAX_PATTERN_SCALES] = {
-    8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
-  };
-  // Note that the largest candidate step at each scale is 2^scale
-  static const MV square_candidates[MAX_PATTERN_SCALES]
-                                   [MAX_PATTERN_CANDIDATES] = {
-    {{-1, -1}, {0, -1}, {1, -1}, {1, 0}, {1, 1}, {0, 1}, {-1, 1}, {-1, 0}},
-    {{-2, -2}, {0, -2}, {2, -2}, {2, 0}, {2, 2}, {0, 2}, {-2, 2}, {-2, 0}},
-    {{-4, -4}, {0, -4}, {4, -4}, {4, 0}, {4, 4}, {0, 4}, {-4, 4}, {-4, 0}},
-    {{-8, -8}, {0, -8}, {8, -8}, {8, 0}, {8, 8}, {0, 8}, {-8, 8}, {-8, 0}},
-    {{-16, -16}, {0, -16}, {16, -16}, {16, 0}, {16, 16}, {0, 16},
-      {-16, 16}, {-16, 0}},
-    {{-32, -32}, {0, -32}, {32, -32}, {32, 0}, {32, 32}, {0, 32},
-      {-32, 32}, {-32, 0}},
-    {{-64, -64}, {0, -64}, {64, -64}, {64, 0}, {64, 64}, {0, 64},
-      {-64, 64}, {-64, 0}},
-    {{-128, -128}, {0, -128}, {128, -128}, {128, 0}, {128, 128}, {0, 128},
-      {-128, 128}, {-128, 0}},
-    {{-256, -256}, {0, -256}, {256, -256}, {256, 0}, {256, 256}, {0, 256},
-      {-256, 256}, {-256, 0}},
-    {{-512, -512}, {0, -512}, {512, -512}, {512, 0}, {512, 512}, {0, 512},
-      {-512, 512}, {-512, 0}},
-    {{-1024, -1024}, {0, -1024}, {1024, -1024}, {1024, 0}, {1024, 1024},
-      {0, 1024}, {-1024, 1024}, {-1024, 0}},
-  };
-  return vp9_pattern_search(x, ref_mv, search_param, sad_per_bit,
-                            do_init_search, cost_list, vfp, use_mvcost,
-                            center_mv, best_mv,
-                            square_num_candidates, square_candidates);
-}
-
-static int fast_hex_search(const MACROBLOCK *x,
-                           MV *ref_mv,
-                           int search_param,
-                           int sad_per_bit,
-                           int do_init_search,  // must be zero for fast_hex
-                           int *cost_list,
-                           const vp9_variance_fn_ptr_t *vfp,
-                           int use_mvcost,
-                           const MV *center_mv,
-                           MV *best_mv) {
-  return hex_search(x, ref_mv, VPXMAX(MAX_MVSEARCH_STEPS - 2, search_param),
-                    sad_per_bit, do_init_search, cost_list, vfp, use_mvcost,
-                    center_mv, best_mv);
-}
-
-static int fast_dia_search(const MACROBLOCK *x,
-                           MV *ref_mv,
-                           int search_param,
-                           int sad_per_bit,
-                           int do_init_search,
-                           int *cost_list,
-                           const vp9_variance_fn_ptr_t *vfp,
-                           int use_mvcost,
-                           const MV *center_mv,
-                           MV *best_mv) {
-  return bigdia_search(
-      x, ref_mv, VPXMAX(MAX_MVSEARCH_STEPS - 2, search_param), sad_per_bit,
-      do_init_search, cost_list, vfp, use_mvcost, center_mv, best_mv);
-}
-
-#undef CHECK_BETTER
-
-// Exhuastive motion search around a given centre position with a given
-// step size.
-static int exhuastive_mesh_search(const MACROBLOCK *x,
-                                  MV *ref_mv, MV *best_mv,
-                                  int range, int step, int sad_per_bit,
-                                  const vp9_variance_fn_ptr_t *fn_ptr,
-                                  const MV *center_mv) {
-  const MACROBLOCKD *const xd = &x->e_mbd;
-  const struct buf_2d *const what = &x->plane[0].src;
-  const struct buf_2d *const in_what = &xd->plane[0].pre[0];
-  MV fcenter_mv = {center_mv->row, center_mv->col};
-  unsigned int best_sad = INT_MAX;
-  int r, c, i;
-  int start_col, end_col, start_row, end_row;
-  int col_step = (step > 1) ? step : 4;
-
-  assert(step >= 1);
-
-  clamp_mv(&fcenter_mv, x->mv_col_min, x->mv_col_max,
-           x->mv_row_min, x->mv_row_max);
-  *best_mv = fcenter_mv;
-  best_sad = fn_ptr->sdf(what->buf, what->stride,
-             get_buf_from_mv(in_what, &fcenter_mv), in_what->stride) +
-             mvsad_err_cost(x, &fcenter_mv, ref_mv, sad_per_bit);
-  start_row = VPXMAX(-range, x->mv_row_min - fcenter_mv.row);
-  start_col = VPXMAX(-range, x->mv_col_min - fcenter_mv.col);
-  end_row = VPXMIN(range, x->mv_row_max - fcenter_mv.row);
-  end_col = VPXMIN(range, x->mv_col_max - fcenter_mv.col);
-
-  for (r = start_row; r <= end_row; r += step) {
-    for (c = start_col; c <= end_col; c += col_step) {
-      // Step > 1 means we are not checking every location in this pass.
-      if (step > 1) {
-        const MV mv = {fcenter_mv.row + r, fcenter_mv.col + c};
-        unsigned int sad = fn_ptr->sdf(what->buf, what->stride,
-                           get_buf_from_mv(in_what, &mv), in_what->stride);
-        if (sad < best_sad) {
-          sad += mvsad_err_cost(x, &mv, ref_mv, sad_per_bit);
-          if (sad < best_sad) {
-            best_sad = sad;
-            *best_mv = mv;
-          }
-        }
-      } else {
-        // 4 sads in a single call if we are checking every location
-        if (c + 3 <= end_col) {
-          unsigned int sads[4];
-          const uint8_t *addrs[4];
-          for (i = 0; i < 4; ++i) {
-            const MV mv = {fcenter_mv.row + r, fcenter_mv.col + c + i};
-            addrs[i] = get_buf_from_mv(in_what, &mv);
-          }
-          fn_ptr->sdx4df(what->buf, what->stride, addrs,
-                         in_what->stride, sads);
-
-          for (i = 0; i < 4; ++i) {
-            if (sads[i] < best_sad) {
-              const MV mv = {fcenter_mv.row + r, fcenter_mv.col + c + i};
-              const unsigned int sad = sads[i] +
-                  mvsad_err_cost(x, &mv, ref_mv, sad_per_bit);
-              if (sad < best_sad) {
-                best_sad = sad;
-                *best_mv = mv;
-              }
-            }
-          }
-        } else {
-          for (i = 0; i < end_col - c; ++i) {
-            const MV mv = {fcenter_mv.row + r, fcenter_mv.col + c + i};
-            unsigned int sad = fn_ptr->sdf(what->buf, what->stride,
-                get_buf_from_mv(in_what, &mv), in_what->stride);
-            if (sad < best_sad) {
-              sad += mvsad_err_cost(x, &mv, ref_mv, sad_per_bit);
-              if (sad < best_sad) {
-                best_sad = sad;
-                *best_mv = mv;
-              }
-            }
-          }
-        }
-      }
-    }
-  }
-
-  return best_sad;
-}
-
-int vp9_diamond_search_sad_c(const MACROBLOCK *x,
-                             const search_site_config *cfg,
-                             MV *ref_mv, MV *best_mv, int search_param,
-                             int sad_per_bit, int *num00,
-                             const vp9_variance_fn_ptr_t *fn_ptr,
-                             const MV *center_mv) {
-  int i, j, step;
-
-  const MACROBLOCKD *const xd = &x->e_mbd;
-  uint8_t *what = x->plane[0].src.buf;
-  const int what_stride = x->plane[0].src.stride;
-  const uint8_t *in_what;
-  const int in_what_stride = xd->plane[0].pre[0].stride;
-  const uint8_t *best_address;
-
-  unsigned int bestsad = INT_MAX;
-  int best_site = -1;
-  int last_site = -1;
-
-  int ref_row;
-  int ref_col;
-
-  // search_param determines the length of the initial step and hence the number
-  // of iterations.
-  // 0 = initial step (MAX_FIRST_STEP) pel
-  // 1 = (MAX_FIRST_STEP/2) pel,
-  // 2 = (MAX_FIRST_STEP/4) pel...
-//  const search_site *ss = &cfg->ss[search_param * cfg->searches_per_step];
-  const MV *ss_mv = &cfg->ss_mv[search_param * cfg->searches_per_step];
-  const intptr_t *ss_os = &cfg->ss_os[search_param * cfg->searches_per_step];
-  const int tot_steps = cfg->total_steps - search_param;
-
-  const MV fcenter_mv = {center_mv->row >> 3, center_mv->col >> 3};
-  clamp_mv(ref_mv, x->mv_col_min, x->mv_col_max, x->mv_row_min, x->mv_row_max);
-  ref_row = ref_mv->row;
-  ref_col = ref_mv->col;
-  *num00 = 0;
-  best_mv->row = ref_row;
-  best_mv->col = ref_col;
-
-  // Work out the start point for the search
-  in_what = xd->plane[0].pre[0].buf + ref_row * in_what_stride + ref_col;
-  best_address = in_what;
-
-  // Check the starting position
-  bestsad = fn_ptr->sdf(what, what_stride, in_what, in_what_stride)
-                + mvsad_err_cost(x, best_mv, &fcenter_mv, sad_per_bit);
-
-  i = 0;
-
-  for (step = 0; step < tot_steps; step++) {
-    int all_in = 1, t;
-
-    // All_in is true if every one of the points we are checking are within
-    // the bounds of the image.
-    all_in &= ((best_mv->row + ss_mv[i].row) > x->mv_row_min);
-    all_in &= ((best_mv->row + ss_mv[i + 1].row) < x->mv_row_max);
-    all_in &= ((best_mv->col + ss_mv[i + 2].col) > x->mv_col_min);
-    all_in &= ((best_mv->col + ss_mv[i + 3].col) < x->mv_col_max);
-
-    // If all the pixels are within the bounds we don't check whether the
-    // search point is valid in this loop,  otherwise we check each point
-    // for validity..
-    if (all_in) {
-      unsigned int sad_array[4];
-
-      for (j = 0; j < cfg->searches_per_step; j += 4) {
-        unsigned char const *block_offset[4];
-
-        for (t = 0; t < 4; t++)
-          block_offset[t] = ss_os[i + t] + best_address;
-
-        fn_ptr->sdx4df(what, what_stride, block_offset, in_what_stride,
-                       sad_array);
-
-        for (t = 0; t < 4; t++, i++) {
-          if (sad_array[t] < bestsad) {
-            const MV this_mv = {best_mv->row + ss_mv[i].row,
-                                best_mv->col + ss_mv[i].col};
-            sad_array[t] += mvsad_err_cost(x, &this_mv, &fcenter_mv,
-                                           sad_per_bit);
-            if (sad_array[t] < bestsad) {
-              bestsad = sad_array[t];
-              best_site = i;
-            }
-          }
-        }
-      }
-    } else {
-      for (j = 0; j < cfg->searches_per_step; j++) {
-        // Trap illegal vectors
-        const MV this_mv = {best_mv->row + ss_mv[i].row,
-                            best_mv->col + ss_mv[i].col};
-
-        if (is_mv_in(x, &this_mv)) {
-          const uint8_t *const check_here = ss_os[i] + best_address;
-          unsigned int thissad = fn_ptr->sdf(what, what_stride, check_here,
-                                             in_what_stride);
-
-          if (thissad < bestsad) {
-            thissad += mvsad_err_cost(x, &this_mv, &fcenter_mv, sad_per_bit);
-            if (thissad < bestsad) {
-              bestsad = thissad;
-              best_site = i;
-            }
-          }
-        }
-        i++;
-      }
-    }
-    if (best_site != last_site) {
-      best_mv->row += ss_mv[best_site].row;
-      best_mv->col += ss_mv[best_site].col;
-      best_address += ss_os[best_site];
-      last_site = best_site;
-#if defined(NEW_DIAMOND_SEARCH)
-      while (1) {
-        const MV this_mv = {best_mv->row + ss_mv[best_site].row,
-                            best_mv->col + ss_mv[best_site].col};
-        if (is_mv_in(x, &this_mv)) {
-          const uint8_t *const check_here = ss_os[best_site] + best_address;
-          unsigned int thissad = fn_ptr->sdf(what, what_stride, check_here,
-                                             in_what_stride);
-          if (thissad < bestsad) {
-            thissad += mvsad_err_cost(x, &this_mv, &fcenter_mv, sad_per_bit);
-            if (thissad < bestsad) {
-              bestsad = thissad;
-              best_mv->row += ss_mv[best_site].row;
-              best_mv->col += ss_mv[best_site].col;
-              best_address += ss_os[best_site];
-              continue;
-            }
-          }
-        }
-        break;
-      }
-#endif
-    } else if (best_address == in_what) {
-      (*num00)++;
-    }
-  }
-  return bestsad;
-}
-
-static int vector_match(int16_t *ref, int16_t *src, int bwl) {
-  int best_sad = INT_MAX;
-  int this_sad;
-  int d;
-  int center, offset = 0;
-  int bw = 4 << bwl;  // redundant variable, to be changed in the experiments.
-  for (d = 0; d <= bw; d += 16) {
-    this_sad = vpx_vector_var(&ref[d], src, bwl);
-    if (this_sad < best_sad) {
-      best_sad = this_sad;
-      offset = d;
-    }
-  }
-  center = offset;
-
-  for (d = -8; d <= 8; d += 16) {
-    int this_pos = offset + d;
-    // check limit
-    if (this_pos < 0 || this_pos > bw)
-      continue;
-    this_sad = vpx_vector_var(&ref[this_pos], src, bwl);
-    if (this_sad < best_sad) {
-      best_sad = this_sad;
-      center = this_pos;
-    }
-  }
-  offset = center;
-
-  for (d = -4; d <= 4; d += 8) {
-    int this_pos = offset + d;
-    // check limit
-    if (this_pos < 0 || this_pos > bw)
-      continue;
-    this_sad = vpx_vector_var(&ref[this_pos], src, bwl);
-    if (this_sad < best_sad) {
-      best_sad = this_sad;
-      center = this_pos;
-    }
-  }
-  offset = center;
-
-  for (d = -2; d <= 2; d += 4) {
-    int this_pos = offset + d;
-    // check limit
-    if (this_pos < 0 || this_pos > bw)
-      continue;
-    this_sad = vpx_vector_var(&ref[this_pos], src, bwl);
-    if (this_sad < best_sad) {
-      best_sad = this_sad;
-      center = this_pos;
-    }
-  }
-  offset = center;
-
-  for (d = -1; d <= 1; d += 2) {
-    int this_pos = offset + d;
-    // check limit
-    if (this_pos < 0 || this_pos > bw)
-      continue;
-    this_sad = vpx_vector_var(&ref[this_pos], src, bwl);
-    if (this_sad < best_sad) {
-      best_sad = this_sad;
-      center = this_pos;
-    }
-  }
-
-  return (center - (bw >> 1));
-}
-
-static const MV search_pos[4] = {
-    {-1, 0}, {0, -1}, {0, 1}, {1, 0},
-};
-
-unsigned int vp9_int_pro_motion_estimation(const VP9_COMP *cpi, MACROBLOCK *x,
-                                           BLOCK_SIZE bsize,
-                                           int mi_row, int mi_col) {
-  MACROBLOCKD *xd = &x->e_mbd;
-  MODE_INFO *mi = xd->mi[0];
-  struct buf_2d backup_yv12[MAX_MB_PLANE] = {{0, 0}};
-  DECLARE_ALIGNED(16, int16_t, hbuf[128]);
-  DECLARE_ALIGNED(16, int16_t, vbuf[128]);
-  DECLARE_ALIGNED(16, int16_t, src_hbuf[64]);
-  DECLARE_ALIGNED(16, int16_t, src_vbuf[64]);
-  int idx;
-  const int bw = 4 << b_width_log2_lookup[bsize];
-  const int bh = 4 << b_height_log2_lookup[bsize];
-  const int search_width = bw << 1;
-  const int search_height = bh << 1;
-  const int src_stride = x->plane[0].src.stride;
-  const int ref_stride = xd->plane[0].pre[0].stride;
-  uint8_t const *ref_buf, *src_buf;
-  MV *tmp_mv = &xd->mi[0]->mv[0].as_mv;
-  unsigned int best_sad, tmp_sad, this_sad[4];
-  MV this_mv;
-  const int norm_factor = 3 + (bw >> 5);
-  const YV12_BUFFER_CONFIG *scaled_ref_frame =
-      vp9_get_scaled_ref_frame(cpi, mi->ref_frame[0]);
-
-  if (scaled_ref_frame) {
-    int i;
-    // Swap out the reference frame for a version that's been scaled to
-    // match the resolution of the current frame, allowing the existing
-    // motion search code to be used without additional modifications.
-    for (i = 0; i < MAX_MB_PLANE; i++)
-      backup_yv12[i] = xd->plane[i].pre[0];
-    vp9_setup_pre_planes(xd, 0, scaled_ref_frame, mi_row, mi_col, NULL);
-  }
-
-#if CONFIG_VP9_HIGHBITDEPTH
-  {
-    unsigned int this_sad;
-    tmp_mv->row = 0;
-    tmp_mv->col = 0;
-    this_sad = cpi->fn_ptr[bsize].sdf(x->plane[0].src.buf, src_stride,
-                                      xd->plane[0].pre[0].buf, ref_stride);
-
-    if (scaled_ref_frame) {
-      int i;
-      for (i = 0; i < MAX_MB_PLANE; i++)
-        xd->plane[i].pre[0] = backup_yv12[i];
-    }
-    return this_sad;
-  }
-#endif
-
-  // Set up prediction 1-D reference set
-  ref_buf = xd->plane[0].pre[0].buf - (bw >> 1);
-  for (idx = 0; idx < search_width; idx += 16) {
-    vpx_int_pro_row(&hbuf[idx], ref_buf, ref_stride, bh);
-    ref_buf += 16;
-  }
-
-  ref_buf = xd->plane[0].pre[0].buf - (bh >> 1) * ref_stride;
-  for (idx = 0; idx < search_height; ++idx) {
-    vbuf[idx] = vpx_int_pro_col(ref_buf, bw) >> norm_factor;
-    ref_buf += ref_stride;
-  }
-
-  // Set up src 1-D reference set
-  for (idx = 0; idx < bw; idx += 16) {
-    src_buf = x->plane[0].src.buf + idx;
-    vpx_int_pro_row(&src_hbuf[idx], src_buf, src_stride, bh);
-  }
-
-  src_buf = x->plane[0].src.buf;
-  for (idx = 0; idx < bh; ++idx) {
-    src_vbuf[idx] = vpx_int_pro_col(src_buf, bw) >> norm_factor;
-    src_buf += src_stride;
-  }
-
-  // Find the best match per 1-D search
-  tmp_mv->col = vector_match(hbuf, src_hbuf, b_width_log2_lookup[bsize]);
-  tmp_mv->row = vector_match(vbuf, src_vbuf, b_height_log2_lookup[bsize]);
-
-  this_mv = *tmp_mv;
-  src_buf = x->plane[0].src.buf;
-  ref_buf = xd->plane[0].pre[0].buf + this_mv.row * ref_stride + this_mv.col;
-  best_sad = cpi->fn_ptr[bsize].sdf(src_buf, src_stride, ref_buf, ref_stride);
-
-  {
-    const uint8_t * const pos[4] = {
-        ref_buf - ref_stride,
-        ref_buf - 1,
-        ref_buf + 1,
-        ref_buf + ref_stride,
-    };
-
-    cpi->fn_ptr[bsize].sdx4df(src_buf, src_stride, pos, ref_stride, this_sad);
-  }
-
-  for (idx = 0; idx < 4; ++idx) {
-    if (this_sad[idx] < best_sad) {
-      best_sad = this_sad[idx];
-      tmp_mv->row = search_pos[idx].row + this_mv.row;
-      tmp_mv->col = search_pos[idx].col + this_mv.col;
-    }
-  }
-
-  if (this_sad[0] < this_sad[3])
-    this_mv.row -= 1;
-  else
-    this_mv.row += 1;
-
-  if (this_sad[1] < this_sad[2])
-    this_mv.col -= 1;
-  else
-    this_mv.col += 1;
-
-  ref_buf = xd->plane[0].pre[0].buf + this_mv.row * ref_stride + this_mv.col;
-
-  tmp_sad = cpi->fn_ptr[bsize].sdf(src_buf, src_stride,
-                                   ref_buf, ref_stride);
-  if (best_sad > tmp_sad) {
-    *tmp_mv = this_mv;
-    best_sad = tmp_sad;
-  }
-
-  tmp_mv->row *= 8;
-  tmp_mv->col *= 8;
-
-  if (scaled_ref_frame) {
-    int i;
-    for (i = 0; i < MAX_MB_PLANE; i++)
-      xd->plane[i].pre[0] = backup_yv12[i];
-  }
-
-  return best_sad;
-}
-
-// Runs sequence of diamond searches in smaller steps for RD.
-/* do_refine: If last step (1-away) of n-step search doesn't pick the center
-              point as the best match, we will do a final 1-away diamond
-              refining search  */
-static int full_pixel_diamond(const VP9_COMP *cpi, MACROBLOCK *x,
-                              MV *mvp_full, int step_param,
-                              int sadpb, int further_steps, int do_refine,
-                              int *cost_list,
-                              const vp9_variance_fn_ptr_t *fn_ptr,
-                              const MV *ref_mv, MV *dst_mv) {
-  MV temp_mv;
-  int thissme, n, num00 = 0;
-  int bestsme = cpi->diamond_search_sad(x, &cpi->ss_cfg, mvp_full, &temp_mv,
-                                        step_param, sadpb, &n,
-                                        fn_ptr, ref_mv);
-  if (bestsme < INT_MAX)
-    bestsme = vp9_get_mvpred_var(x, &temp_mv, ref_mv, fn_ptr, 1);
-  *dst_mv = temp_mv;
-
-  // If there won't be more n-step search, check to see if refining search is
-  // needed.
-  if (n > further_steps)
-    do_refine = 0;
-
-  while (n < further_steps) {
-    ++n;
-
-    if (num00) {
-      num00--;
-    } else {
-      thissme = cpi->diamond_search_sad(x, &cpi->ss_cfg, mvp_full, &temp_mv,
-                                        step_param + n, sadpb, &num00,
-                                        fn_ptr, ref_mv);
-      if (thissme < INT_MAX)
-        thissme = vp9_get_mvpred_var(x, &temp_mv, ref_mv, fn_ptr, 1);
-
-      // check to see if refining search is needed.
-      if (num00 > further_steps - n)
-        do_refine = 0;
-
-      if (thissme < bestsme) {
-        bestsme = thissme;
-        *dst_mv = temp_mv;
-      }
-    }
-  }
-
-  // final 1-away diamond refining search
-  if (do_refine) {
-    const int search_range = 8;
-    MV best_mv = *dst_mv;
-    thissme = vp9_refining_search_sad(x, &best_mv, sadpb, search_range,
-                                       fn_ptr, ref_mv);
-    if (thissme < INT_MAX)
-      thissme = vp9_get_mvpred_var(x, &best_mv, ref_mv, fn_ptr, 1);
-    if (thissme < bestsme) {
-      bestsme = thissme;
-      *dst_mv = best_mv;
-    }
-  }
-
-  // Return cost list.
-  if (cost_list) {
-    calc_int_cost_list(x, ref_mv, sadpb, fn_ptr, dst_mv, cost_list);
-  }
-  return bestsme;
-}
-
-#define MIN_RANGE 7
-#define MAX_RANGE 256
-#define MIN_INTERVAL 1
-// Runs an limited range exhaustive mesh search using a pattern set
-// according to the encode speed profile.
-static int full_pixel_exhaustive(VP9_COMP *cpi, MACROBLOCK *x,
-                                 MV *centre_mv_full, int sadpb,  int *cost_list,
-                                 const vp9_variance_fn_ptr_t *fn_ptr,
-                                 const MV *ref_mv, MV *dst_mv) {
-  const SPEED_FEATURES *const sf = &cpi->sf;
-  MV temp_mv = {centre_mv_full->row, centre_mv_full->col};
-  MV f_ref_mv = {ref_mv->row >> 3, ref_mv->col >> 3};
-  int bestsme;
-  int i;
-  int interval = sf->mesh_patterns[0].interval;
-  int range = sf->mesh_patterns[0].range;
-  int baseline_interval_divisor;
-
-  // Keep track of number of exhaustive calls (this frame in this thread).
-  ++(*x->ex_search_count_ptr);
-
-  // Trap illegal values for interval and range for this function.
-  if ((range < MIN_RANGE) || (range > MAX_RANGE) ||
-      (interval < MIN_INTERVAL) || (interval > range))
-    return INT_MAX;
-
-  baseline_interval_divisor = range / interval;
-
-  // Check size of proposed first range against magnitude of the centre
-  // value used as a starting point.
-  range = VPXMAX(range, (5 * VPXMAX(abs(temp_mv.row), abs(temp_mv.col))) / 4);
-  range = VPXMIN(range, MAX_RANGE);
-  interval = VPXMAX(interval, range / baseline_interval_divisor);
-
-  // initial search
-  bestsme = exhuastive_mesh_search(x, &f_ref_mv, &temp_mv, range,
-                                  interval, sadpb, fn_ptr, &temp_mv);
-
-  if ((interval > MIN_INTERVAL) && (range > MIN_RANGE)) {
-    // Progressive searches with range and step size decreasing each time
-    // till we reach a step size of 1. Then break out.
-    for (i = 1; i < MAX_MESH_STEP; ++i) {
-      // First pass with coarser step and longer range
-      bestsme = exhuastive_mesh_search(x, &f_ref_mv, &temp_mv,
-                                       sf->mesh_patterns[i].range,
-                                       sf->mesh_patterns[i].interval,
-                                       sadpb, fn_ptr, &temp_mv);
-
-      if (sf->mesh_patterns[i].interval == 1)
-        break;
-    }
-  }
-
-  if (bestsme < INT_MAX)
-    bestsme = vp9_get_mvpred_var(x, &temp_mv, ref_mv, fn_ptr, 1);
-  *dst_mv = temp_mv;
-
-  // Return cost list.
-  if (cost_list) {
-    calc_int_cost_list(x, ref_mv, sadpb, fn_ptr, dst_mv, cost_list);
-  }
-  return bestsme;
-}
-
-int vp9_full_search_sad_c(const MACROBLOCK *x, const MV *ref_mv,
-                          int sad_per_bit, int distance,
-                          const vp9_variance_fn_ptr_t *fn_ptr,
-                          const MV *center_mv, MV *best_mv) {
-  int r, c;
-  const MACROBLOCKD *const xd = &x->e_mbd;
-  const struct buf_2d *const what = &x->plane[0].src;
-  const struct buf_2d *const in_what = &xd->plane[0].pre[0];
-  const int row_min = VPXMAX(ref_mv->row - distance, x->mv_row_min);
-  const int row_max = VPXMIN(ref_mv->row + distance, x->mv_row_max);
-  const int col_min = VPXMAX(ref_mv->col - distance, x->mv_col_min);
-  const int col_max = VPXMIN(ref_mv->col + distance, x->mv_col_max);
-  const MV fcenter_mv = {center_mv->row >> 3, center_mv->col >> 3};
-  int best_sad = fn_ptr->sdf(what->buf, what->stride,
-      get_buf_from_mv(in_what, ref_mv), in_what->stride) +
-      mvsad_err_cost(x, ref_mv, &fcenter_mv, sad_per_bit);
-  *best_mv = *ref_mv;
-
-  for (r = row_min; r < row_max; ++r) {
-    for (c = col_min; c < col_max; ++c) {
-      const MV mv = {r, c};
-      const int sad = fn_ptr->sdf(what->buf, what->stride,
-          get_buf_from_mv(in_what, &mv), in_what->stride) +
-              mvsad_err_cost(x, &mv, &fcenter_mv, sad_per_bit);
-      if (sad < best_sad) {
-        best_sad = sad;
-        *best_mv = mv;
-      }
-    }
-  }
-  return best_sad;
-}
-
-int vp9_full_search_sadx3(const MACROBLOCK *x, const MV *ref_mv,
-                          int sad_per_bit, int distance,
-                          const vp9_variance_fn_ptr_t *fn_ptr,
-                          const MV *center_mv, MV *best_mv) {
-  int r;
-  const MACROBLOCKD *const xd = &x->e_mbd;
-  const struct buf_2d *const what = &x->plane[0].src;
-  const struct buf_2d *const in_what = &xd->plane[0].pre[0];
-  const int row_min = VPXMAX(ref_mv->row - distance, x->mv_row_min);
-  const int row_max = VPXMIN(ref_mv->row + distance, x->mv_row_max);
-  const int col_min = VPXMAX(ref_mv->col - distance, x->mv_col_min);
-  const int col_max = VPXMIN(ref_mv->col + distance, x->mv_col_max);
-  const MV fcenter_mv = {center_mv->row >> 3, center_mv->col >> 3};
-  unsigned int best_sad = fn_ptr->sdf(what->buf, what->stride,
-      get_buf_from_mv(in_what, ref_mv), in_what->stride) +
-      mvsad_err_cost(x, ref_mv, &fcenter_mv, sad_per_bit);
-  *best_mv = *ref_mv;
-
-  for (r = row_min; r < row_max; ++r) {
-    int c = col_min;
-    const uint8_t *check_here = &in_what->buf[r * in_what->stride + c];
-
-    if (fn_ptr->sdx3f != NULL) {
-      while ((c + 2) < col_max) {
-        int i;
-        DECLARE_ALIGNED(16, uint32_t, sads[3]);
-
-        fn_ptr->sdx3f(what->buf, what->stride, check_here, in_what->stride,
-                      sads);
-
-        for (i = 0; i < 3; ++i) {
-          unsigned int sad = sads[i];
-          if (sad < best_sad) {
-            const MV mv = {r, c};
-            sad += mvsad_err_cost(x, &mv, &fcenter_mv, sad_per_bit);
-            if (sad < best_sad) {
-              best_sad = sad;
-              *best_mv = mv;
-            }
-          }
-          ++check_here;
-          ++c;
-        }
-      }
-    }
-
-    while (c < col_max) {
-      unsigned int sad = fn_ptr->sdf(what->buf, what->stride,
-                                     check_here, in_what->stride);
-      if (sad < best_sad) {
-        const MV mv = {r, c};
-        sad += mvsad_err_cost(x, &mv, &fcenter_mv, sad_per_bit);
-        if (sad < best_sad) {
-          best_sad = sad;
-          *best_mv = mv;
-        }
-      }
-      ++check_here;
-      ++c;
-    }
-  }
-
-  return best_sad;
-}
-
-int vp9_full_search_sadx8(const MACROBLOCK *x, const MV *ref_mv,
-                          int sad_per_bit, int distance,
-                          const vp9_variance_fn_ptr_t *fn_ptr,
-                          const MV *center_mv, MV *best_mv) {
-  int r;
-  const MACROBLOCKD *const xd = &x->e_mbd;
-  const struct buf_2d *const what = &x->plane[0].src;
-  const struct buf_2d *const in_what = &xd->plane[0].pre[0];
-  const int row_min = VPXMAX(ref_mv->row - distance, x->mv_row_min);
-  const int row_max = VPXMIN(ref_mv->row + distance, x->mv_row_max);
-  const int col_min = VPXMAX(ref_mv->col - distance, x->mv_col_min);
-  const int col_max = VPXMIN(ref_mv->col + distance, x->mv_col_max);
-  const MV fcenter_mv = {center_mv->row >> 3, center_mv->col >> 3};
-  unsigned int best_sad = fn_ptr->sdf(what->buf, what->stride,
-      get_buf_from_mv(in_what, ref_mv), in_what->stride) +
-      mvsad_err_cost(x, ref_mv, &fcenter_mv, sad_per_bit);
-  *best_mv = *ref_mv;
-
-  for (r = row_min; r < row_max; ++r) {
-    int c = col_min;
-    const uint8_t *check_here = &in_what->buf[r * in_what->stride + c];
-
-    if (fn_ptr->sdx8f != NULL) {
-      while ((c + 7) < col_max) {
-        int i;
-        DECLARE_ALIGNED(16, uint32_t, sads[8]);
-
-        fn_ptr->sdx8f(what->buf, what->stride, check_here, in_what->stride,
-                      sads);
-
-        for (i = 0; i < 8; ++i) {
-          unsigned int sad = sads[i];
-          if (sad < best_sad) {
-            const MV mv = {r, c};
-            sad += mvsad_err_cost(x, &mv, &fcenter_mv, sad_per_bit);
-            if (sad < best_sad) {
-              best_sad = sad;
-              *best_mv = mv;
-            }
-          }
-          ++check_here;
-          ++c;
-        }
-      }
-    }
-
-    if (fn_ptr->sdx3f != NULL) {
-      while ((c + 2) < col_max) {
-        int i;
-        DECLARE_ALIGNED(16, uint32_t, sads[3]);
-
-        fn_ptr->sdx3f(what->buf, what->stride, check_here, in_what->stride,
-                      sads);
-
-        for (i = 0; i < 3; ++i) {
-          unsigned int sad = sads[i];
-          if (sad < best_sad) {
-            const MV mv = {r, c};
-            sad += mvsad_err_cost(x, &mv, &fcenter_mv, sad_per_bit);
-            if (sad < best_sad) {
-              best_sad = sad;
-              *best_mv = mv;
-            }
-          }
-          ++check_here;
-          ++c;
-        }
-      }
-    }
-
-    while (c < col_max) {
-      unsigned int sad = fn_ptr->sdf(what->buf, what->stride,
-                                     check_here, in_what->stride);
-      if (sad < best_sad) {
-        const MV mv = {r, c};
-        sad += mvsad_err_cost(x, &mv, &fcenter_mv, sad_per_bit);
-        if (sad < best_sad) {
-          best_sad = sad;
-          *best_mv = mv;
-        }
-      }
-      ++check_here;
-      ++c;
-    }
-  }
-
-  return best_sad;
-}
-
-int vp9_refining_search_sad(const MACROBLOCK *x,
-                            MV *ref_mv, int error_per_bit,
-                            int search_range,
-                            const vp9_variance_fn_ptr_t *fn_ptr,
-                            const MV *center_mv) {
-  const MACROBLOCKD *const xd = &x->e_mbd;
-  const MV neighbors[4] = {{ -1, 0}, {0, -1}, {0, 1}, {1, 0}};
-  const struct buf_2d *const what = &x->plane[0].src;
-  const struct buf_2d *const in_what = &xd->plane[0].pre[0];
-  const MV fcenter_mv = {center_mv->row >> 3, center_mv->col >> 3};
-  const uint8_t *best_address = get_buf_from_mv(in_what, ref_mv);
-  unsigned int best_sad = fn_ptr->sdf(what->buf, what->stride, best_address,
-                                    in_what->stride) +
-      mvsad_err_cost(x, ref_mv, &fcenter_mv, error_per_bit);
-  int i, j;
-
-  for (i = 0; i < search_range; i++) {
-    int best_site = -1;
-    const int all_in = ((ref_mv->row - 1) > x->mv_row_min) &
-                       ((ref_mv->row + 1) < x->mv_row_max) &
-                       ((ref_mv->col - 1) > x->mv_col_min) &
-                       ((ref_mv->col + 1) < x->mv_col_max);
-
-    if (all_in) {
-      unsigned int sads[4];
-      const uint8_t *const positions[4] = {
-        best_address - in_what->stride,
-        best_address - 1,
-        best_address + 1,
-        best_address + in_what->stride
-      };
-
-      fn_ptr->sdx4df(what->buf, what->stride, positions, in_what->stride, sads);
-
-      for (j = 0; j < 4; ++j) {
-        if (sads[j] < best_sad) {
-          const MV mv = {ref_mv->row + neighbors[j].row,
-                         ref_mv->col + neighbors[j].col};
-          sads[j] += mvsad_err_cost(x, &mv, &fcenter_mv, error_per_bit);
-          if (sads[j] < best_sad) {
-            best_sad = sads[j];
-            best_site = j;
-          }
-        }
-      }
-    } else {
-      for (j = 0; j < 4; ++j) {
-        const MV mv = {ref_mv->row + neighbors[j].row,
-                       ref_mv->col + neighbors[j].col};
-
-        if (is_mv_in(x, &mv)) {
-          unsigned int sad = fn_ptr->sdf(what->buf, what->stride,
-                                         get_buf_from_mv(in_what, &mv),
-                                         in_what->stride);
-          if (sad < best_sad) {
-            sad += mvsad_err_cost(x, &mv, &fcenter_mv, error_per_bit);
-            if (sad < best_sad) {
-              best_sad = sad;
-              best_site = j;
-            }
-          }
-        }
-      }
-    }
-
-    if (best_site == -1) {
-      break;
-    } else {
-      ref_mv->row += neighbors[best_site].row;
-      ref_mv->col += neighbors[best_site].col;
-      best_address = get_buf_from_mv(in_what, ref_mv);
-    }
-  }
-
-  return best_sad;
-}
-
-// This function is called when we do joint motion search in comp_inter_inter
-// mode.
-int vp9_refining_search_8p_c(const MACROBLOCK *x,
-                             MV *ref_mv, int error_per_bit,
-                             int search_range,
-                             const vp9_variance_fn_ptr_t *fn_ptr,
-                             const MV *center_mv,
-                             const uint8_t *second_pred) {
-  const MV neighbors[8] = {{-1, 0}, {0, -1}, {0, 1}, {1, 0},
-                           {-1, -1}, {1, -1}, {-1, 1}, {1, 1}};
-  const MACROBLOCKD *const xd = &x->e_mbd;
-  const struct buf_2d *const what = &x->plane[0].src;
-  const struct buf_2d *const in_what = &xd->plane[0].pre[0];
-  const MV fcenter_mv = {center_mv->row >> 3, center_mv->col >> 3};
-  unsigned int best_sad = fn_ptr->sdaf(what->buf, what->stride,
-      get_buf_from_mv(in_what, ref_mv), in_what->stride, second_pred) +
-      mvsad_err_cost(x, ref_mv, &fcenter_mv, error_per_bit);
-  int i, j;
-
-  for (i = 0; i < search_range; ++i) {
-    int best_site = -1;
-
-    for (j = 0; j < 8; ++j) {
-      const MV mv = {ref_mv->row + neighbors[j].row,
-                     ref_mv->col + neighbors[j].col};
-
-      if (is_mv_in(x, &mv)) {
-        unsigned int sad = fn_ptr->sdaf(what->buf, what->stride,
-            get_buf_from_mv(in_what, &mv), in_what->stride, second_pred);
-        if (sad < best_sad) {
-          sad += mvsad_err_cost(x, &mv, &fcenter_mv, error_per_bit);
-          if (sad < best_sad) {
-            best_sad = sad;
-            best_site = j;
-          }
-        }
-      }
-    }
-
-    if (best_site == -1) {
-      break;
-    } else {
-      ref_mv->row += neighbors[best_site].row;
-      ref_mv->col += neighbors[best_site].col;
-    }
-  }
-  return best_sad;
-}
-
-#define MIN_EX_SEARCH_LIMIT 128
-static int is_exhaustive_allowed(VP9_COMP *cpi, MACROBLOCK *x) {
-  const SPEED_FEATURES *const sf = &cpi->sf;
-  const int max_ex = VPXMAX(MIN_EX_SEARCH_LIMIT,
-      (*x->m_search_count_ptr * sf->max_exaustive_pct) / 100);
-
-  return sf->allow_exhaustive_searches &&
-      (sf->exhaustive_searches_thresh < INT_MAX) &&
-      (*x->ex_search_count_ptr <= max_ex) &&
-      !cpi->rc.is_src_frame_alt_ref;
-}
-
-int vp9_full_pixel_search(VP9_COMP *cpi, MACROBLOCK *x,
-                          BLOCK_SIZE bsize, MV *mvp_full,
-                          int step_param, int error_per_bit,
-                          int *cost_list,
-                          const MV *ref_mv, MV *tmp_mv,
-                          int var_max, int rd) {
-  const SPEED_FEATURES *const sf = &cpi->sf;
-  const SEARCH_METHODS method = sf->mv.search_method;
-  vp9_variance_fn_ptr_t *fn_ptr = &cpi->fn_ptr[bsize];
-  int var = 0;
-  if (cost_list) {
-    cost_list[0] = INT_MAX;
-    cost_list[1] = INT_MAX;
-    cost_list[2] = INT_MAX;
-    cost_list[3] = INT_MAX;
-    cost_list[4] = INT_MAX;
-  }
-
-  // Keep track of number of searches (this frame in this thread).
-  ++(*x->m_search_count_ptr);
-
-  switch (method) {
-    case FAST_DIAMOND:
-      var = fast_dia_search(x, mvp_full, step_param, error_per_bit, 0,
-                            cost_list, fn_ptr, 1, ref_mv, tmp_mv);
-      break;
-    case FAST_HEX:
-      var = fast_hex_search(x, mvp_full, step_param, error_per_bit, 0,
-                            cost_list, fn_ptr, 1, ref_mv, tmp_mv);
-      break;
-    case HEX:
-      var = hex_search(x, mvp_full, step_param, error_per_bit, 1,
-                       cost_list, fn_ptr, 1, ref_mv, tmp_mv);
-      break;
-    case SQUARE:
-      var = square_search(x, mvp_full, step_param, error_per_bit, 1,
-                          cost_list, fn_ptr, 1, ref_mv, tmp_mv);
-      break;
-    case BIGDIA:
-      var = bigdia_search(x, mvp_full, step_param, error_per_bit, 1,
-                          cost_list, fn_ptr, 1, ref_mv, tmp_mv);
-      break;
-    case NSTEP:
-      var = full_pixel_diamond(cpi, x, mvp_full, step_param, error_per_bit,
-                               MAX_MVSEARCH_STEPS - 1 - step_param,
-                               1, cost_list, fn_ptr, ref_mv, tmp_mv);
-
-      // Should we allow a follow on exhaustive search?
-      if (is_exhaustive_allowed(cpi, x)) {
-        int64_t exhuastive_thr = sf->exhaustive_searches_thresh;
-        exhuastive_thr >>= 8 - (b_width_log2_lookup[bsize] +
-                                b_height_log2_lookup[bsize]);
-
-        // Threshold variance for an exhaustive full search.
-        if (var > exhuastive_thr) {
-            int var_ex;
-          MV tmp_mv_ex;
-          var_ex = full_pixel_exhaustive(cpi, x, tmp_mv,
-                                         error_per_bit, cost_list, fn_ptr,
-                                         ref_mv, &tmp_mv_ex);
-
-          if (var_ex < var) {
-            var = var_ex;
-            *tmp_mv = tmp_mv_ex;
-          }
-        }
-      }
-      break;
-    default:
-      assert(0 && "Invalid search method.");
-  }
-
-  if (method != NSTEP && rd && var < var_max)
-    var = vp9_get_mvpred_var(x, tmp_mv, ref_mv, fn_ptr, 1);
-
-  return var;
-}
diff --git a/vp9/encoder/vp9_mcomp.h b/vp9/encoder/vp9_mcomp.h
deleted file mode 100644 (file)
index 86cd267..0000000
+++ /dev/null
@@ -1,136 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#ifndef VP9_ENCODER_VP9_MCOMP_H_
-#define VP9_ENCODER_VP9_MCOMP_H_
-
-#include "vp9/encoder/vp9_block.h"
-#include "vpx_dsp/variance.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-// The maximum number of steps in a step search given the largest
-// allowed initial step
-#define MAX_MVSEARCH_STEPS 11
-// Max full pel mv specified in the unit of full pixel
-// Enable the use of motion vector in range [-1023, 1023].
-#define MAX_FULL_PEL_VAL ((1 << (MAX_MVSEARCH_STEPS - 1)) - 1)
-// Maximum size of the first step in full pel units
-#define MAX_FIRST_STEP (1 << (MAX_MVSEARCH_STEPS-1))
-// Allowed motion vector pixel distance outside image border
-// for Block_16x16
-#define BORDER_MV_PIXELS_B16 (16 + VP9_INTERP_EXTEND)
-
-typedef struct search_site_config {
-  // motion search sites
-  MV  ss_mv[8 * MAX_MVSEARCH_STEPS];        // Motion vector
-  intptr_t ss_os[8 * MAX_MVSEARCH_STEPS];   // Offset
-  int searches_per_step;
-  int total_steps;
-} search_site_config;
-
-void vp9_init_dsmotion_compensation(search_site_config *cfg, int stride);
-void vp9_init3smotion_compensation(search_site_config *cfg,  int stride);
-
-void vp9_set_mv_search_range(MACROBLOCK *x, const MV *mv);
-int vp9_mv_bit_cost(const MV *mv, const MV *ref,
-                    const int *mvjcost, int *mvcost[2], int weight);
-
-// Utility to compute variance + MV rate cost for a given MV
-int vp9_get_mvpred_var(const MACROBLOCK *x,
-                       const MV *best_mv, const MV *center_mv,
-                       const vp9_variance_fn_ptr_t *vfp,
-                       int use_mvcost);
-int vp9_get_mvpred_av_var(const MACROBLOCK *x,
-                          const MV *best_mv, const MV *center_mv,
-                          const uint8_t *second_pred,
-                          const vp9_variance_fn_ptr_t *vfp,
-                          int use_mvcost);
-
-struct VP9_COMP;
-struct SPEED_FEATURES;
-
-int vp9_init_search_range(int size);
-
-int vp9_refining_search_sad(const struct macroblock *x,
-                            struct mv *ref_mv,
-                            int sad_per_bit, int distance,
-                            const struct vp9_variance_vtable *fn_ptr,
-                            const struct mv *center_mv);
-
-// Perform integral projection based motion estimation.
-unsigned int vp9_int_pro_motion_estimation(const struct VP9_COMP *cpi,
-                                           MACROBLOCK *x,
-                                           BLOCK_SIZE bsize,
-                                           int mi_row, int mi_col);
-
-typedef uint32_t (fractional_mv_step_fp) (
-    const MACROBLOCK *x,
-    MV *bestmv, const MV *ref_mv,
-    int allow_hp,
-    int error_per_bit,
-    const vp9_variance_fn_ptr_t *vfp,
-    int forced_stop,  // 0 - full, 1 - qtr only, 2 - half only
-    int iters_per_step,
-    int *cost_list,
-    int *mvjcost, int *mvcost[2],
-    uint32_t *distortion, uint32_t *sse1,
-    const uint8_t *second_pred,
-    int w, int h);
-
-extern fractional_mv_step_fp vp9_find_best_sub_pixel_tree;
-extern fractional_mv_step_fp vp9_find_best_sub_pixel_tree_pruned;
-extern fractional_mv_step_fp vp9_find_best_sub_pixel_tree_pruned_more;
-extern fractional_mv_step_fp vp9_find_best_sub_pixel_tree_pruned_evenmore;
-extern fractional_mv_step_fp vp9_skip_sub_pixel_tree;
-
-typedef int (*vp9_full_search_fn_t)(const MACROBLOCK *x,
-                                    const MV *ref_mv, int sad_per_bit,
-                                    int distance,
-                                    const vp9_variance_fn_ptr_t *fn_ptr,
-                                    const MV *center_mv, MV *best_mv);
-
-typedef int (*vp9_refining_search_fn_t)(const MACROBLOCK *x,
-                                        MV *ref_mv, int sad_per_bit,
-                                        int distance,
-                                        const vp9_variance_fn_ptr_t *fn_ptr,
-                                        const MV *center_mv);
-
-typedef int (*vp9_diamond_search_fn_t)(const MACROBLOCK *x,
-                                       const search_site_config *cfg,
-                                       MV *ref_mv, MV *best_mv,
-                                       int search_param, int sad_per_bit,
-                                       int *num00,
-                                       const vp9_variance_fn_ptr_t *fn_ptr,
-                                       const MV *center_mv);
-
-int vp9_refining_search_8p_c(const MACROBLOCK *x,
-                             MV *ref_mv, int error_per_bit,
-                             int search_range,
-                             const vp9_variance_fn_ptr_t *fn_ptr,
-                             const MV *center_mv, const uint8_t *second_pred);
-
-struct VP9_COMP;
-
-int vp9_full_pixel_search(struct VP9_COMP *cpi, MACROBLOCK *x,
-                          BLOCK_SIZE bsize, MV *mvp_full,
-                          int step_param, int error_per_bit,
-                          int *cost_list,
-                          const MV *ref_mv, MV *tmp_mv,
-                          int var_max, int rd);
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP9_ENCODER_VP9_MCOMP_H_
diff --git a/vp9/encoder/vp9_noise_estimate.c b/vp9/encoder/vp9_noise_estimate.c
deleted file mode 100644 (file)
index 4b43b38..0000000
+++ /dev/null
@@ -1,263 +0,0 @@
-/*
- *  Copyright (c) 2015 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.
- */
-
-#include <assert.h>
-#include <limits.h>
-#include <math.h>
-
-#include "./vpx_dsp_rtcd.h"
-#include "vpx_dsp/vpx_dsp_common.h"
-#include "vpx_scale/yv12config.h"
-#include "vpx/vpx_integer.h"
-#include "vp9/common/vp9_reconinter.h"
-#include "vp9/encoder/vp9_context_tree.h"
-#include "vp9/encoder/vp9_noise_estimate.h"
-#include "vp9/encoder/vp9_encoder.h"
-
-void vp9_noise_estimate_init(NOISE_ESTIMATE *const ne,
-                             int width,
-                             int height) {
-  ne->enabled = 0;
-  ne->level = kLowLow;
-  ne->value = 0;
-  ne->count = 0;
-  ne->thresh = 90;
-  ne->last_w = 0;
-  ne->last_h = 0;
-  if (width * height >= 1920 * 1080) {
-    ne->thresh = 200;
-  } else if (width * height >= 1280 * 720) {
-    ne->thresh = 130;
-  }
-  ne->num_frames_estimate = 20;
-}
-
-static int enable_noise_estimation(VP9_COMP *const cpi) {
-  // Enable noise estimation if denoising is on.
-#if CONFIG_VP9_TEMPORAL_DENOISING
-  if (cpi->oxcf.noise_sensitivity > 0)
-    return 1;
-#endif
-  // Only allow noise estimate under certain encoding mode.
-  // Enabled for 1 pass CBR, speed >=5, and if resolution is same as original.
-  // Not enabled for SVC mode and screen_content_mode.
-  // Not enabled for low resolutions.
-  if (cpi->oxcf.pass == 0 &&
-      cpi->oxcf.rc_mode == VPX_CBR &&
-      cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ &&
-      cpi->oxcf.speed >= 5 &&
-      cpi->resize_state == ORIG &&
-      cpi->resize_pending == 0 &&
-      !cpi->use_svc &&
-      cpi->oxcf.content != VP9E_CONTENT_SCREEN &&
-      cpi->common.width >= 640 &&
-      cpi->common.height >= 480)
-    return 1;
-  else
-    return 0;
-}
-
-#if CONFIG_VP9_TEMPORAL_DENOISING
-static void copy_frame(YV12_BUFFER_CONFIG * const dest,
-                       const YV12_BUFFER_CONFIG * const src) {
-  int r;
-  const uint8_t *srcbuf = src->y_buffer;
-  uint8_t *destbuf = dest->y_buffer;
-
-  assert(dest->y_width == src->y_width);
-  assert(dest->y_height == src->y_height);
-
-  for (r = 0; r < dest->y_height; ++r) {
-    memcpy(destbuf, srcbuf, dest->y_width);
-    destbuf += dest->y_stride;
-    srcbuf += src->y_stride;
-  }
-}
-#endif  // CONFIG_VP9_TEMPORAL_DENOISING
-
-NOISE_LEVEL vp9_noise_estimate_extract_level(NOISE_ESTIMATE *const ne) {
-  int noise_level = kLowLow;
-  if (ne->value > (ne->thresh << 1)) {
-    noise_level = kHigh;
-  } else {
-    if (ne->value > ne->thresh)
-      noise_level = kMedium;
-    else if (ne->value > ((9 * ne->thresh) >> 4))
-      noise_level = kLow;
-    else
-      noise_level = kLowLow;
-  }
-  return noise_level;
-}
-
-void vp9_update_noise_estimate(VP9_COMP *const cpi) {
-  const VP9_COMMON *const cm = &cpi->common;
-  NOISE_ESTIMATE *const ne = &cpi->noise_estimate;
-  // Estimate of noise level every frame_period frames.
-  int frame_period = 8;
-  int thresh_consec_zeromv = 6;
-  unsigned int thresh_sum_diff = 100;
-  unsigned int thresh_sum_spatial = (200 * 200) << 8;
-  unsigned int thresh_spatial_var = (32 * 32) << 8;
-  int min_blocks_estimate = cm->mi_rows * cm->mi_cols >> 7;
-  // Estimate is between current source and last source.
-  YV12_BUFFER_CONFIG *last_source = cpi->Last_Source;
-#if CONFIG_VP9_TEMPORAL_DENOISING
-  if (cpi->oxcf.noise_sensitivity > 0)
-    last_source = &cpi->denoiser.last_source;
-#endif
-  ne->enabled = enable_noise_estimation(cpi);
-  if (!ne->enabled ||
-      cm->current_video_frame % frame_period != 0 ||
-      last_source == NULL ||
-      ne->last_w != cm->width ||
-      ne->last_h != cm->height) {
-#if CONFIG_VP9_TEMPORAL_DENOISING
-  if (cpi->oxcf.noise_sensitivity > 0)
-    copy_frame(&cpi->denoiser.last_source, cpi->Source);
-#endif
-    if (last_source != NULL) {
-      ne->last_w = cm->width;
-      ne->last_h = cm->height;
-    }
-    return;
-  } else if (cpi->rc.avg_frame_low_motion < 50) {
-    // Force noise estimation to 0 and denoiser off if content has high motion.
-    ne->level = kLowLow;
-#if CONFIG_VP9_TEMPORAL_DENOISING
-    if (cpi->oxcf.noise_sensitivity > 0)
-      vp9_denoiser_set_noise_level(&cpi->denoiser, ne->level);
-#endif
-    return;
-  } else {
-    int num_samples = 0;
-    uint64_t avg_est = 0;
-    int bsize = BLOCK_16X16;
-    static const unsigned char const_source[16] = {
-        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
-    // Loop over sub-sample of 16x16 blocks of frame, and for blocks that have
-    // been encoded as zero/small mv at least x consecutive frames, compute
-    // the variance to update estimate of noise in the source.
-    const uint8_t *src_y = cpi->Source->y_buffer;
-    const int src_ystride = cpi->Source->y_stride;
-    const uint8_t *last_src_y = last_source->y_buffer;
-    const int last_src_ystride = last_source->y_stride;
-    const uint8_t *src_u = cpi->Source->u_buffer;
-    const uint8_t *src_v = cpi->Source->v_buffer;
-    const int src_uvstride = cpi->Source->uv_stride;
-    int mi_row, mi_col;
-    int num_low_motion = 0;
-    int frame_low_motion = 1;
-    for (mi_row = 0; mi_row < cm->mi_rows; mi_row++) {
-      for (mi_col = 0; mi_col < cm->mi_cols; mi_col++) {
-        int bl_index = mi_row * cm->mi_cols + mi_col;
-        if (cpi->consec_zero_mv[bl_index] > thresh_consec_zeromv)
-          num_low_motion++;
-      }
-    }
-    if (num_low_motion < ((3 * cm->mi_rows * cm->mi_cols) >> 3))
-      frame_low_motion = 0;
-    for (mi_row = 0; mi_row < cm->mi_rows; mi_row++) {
-      for (mi_col = 0; mi_col < cm->mi_cols; mi_col++) {
-        // 16x16 blocks, 1/4 sample of frame.
-        if (mi_row % 4 == 0 && mi_col % 4 == 0 &&
-            mi_row < cm->mi_rows - 1 &&
-            mi_col < cm->mi_cols - 1) {
-          int bl_index = mi_row * cm->mi_cols + mi_col;
-          int bl_index1 = bl_index + 1;
-          int bl_index2 = bl_index + cm->mi_cols;
-          int bl_index3 = bl_index2 + 1;
-          // Only consider blocks that are likely steady background. i.e, have
-          // been encoded as zero/low motion x (= thresh_consec_zeromv) frames
-          // in a row. consec_zero_mv[] defined for 8x8 blocks, so consider all
-          // 4 sub-blocks for 16x16 block. Also, avoid skin blocks.
-          int consec_zeromv = VPXMIN(cpi->consec_zero_mv[bl_index],
-                                     VPXMIN(cpi->consec_zero_mv[bl_index1],
-                                     VPXMIN(cpi->consec_zero_mv[bl_index2],
-                                     cpi->consec_zero_mv[bl_index3])));
-          int is_skin = 0;
-          if (cpi->use_skin_detection) {
-            is_skin = vp9_compute_skin_block(src_y,
-                                             src_u,
-                                             src_v,
-                                             src_ystride,
-                                             src_uvstride,
-                                             bsize,
-                                             consec_zeromv,
-                                             0);
-          }
-          if (frame_low_motion &&
-              cpi->consec_zero_mv[bl_index] > thresh_consec_zeromv &&
-              cpi->consec_zero_mv[bl_index1] > thresh_consec_zeromv &&
-              cpi->consec_zero_mv[bl_index2] > thresh_consec_zeromv &&
-              cpi->consec_zero_mv[bl_index3] > thresh_consec_zeromv &&
-              !is_skin) {
-            // Compute variance.
-            unsigned int sse;
-            unsigned int variance = cpi->fn_ptr[bsize].vf(src_y,
-                                                          src_ystride,
-                                                          last_src_y,
-                                                          last_src_ystride,
-                                                          &sse);
-            // Only consider this block as valid for noise measurement if the
-            // average term (sse - variance = N * avg^{2}, N = 16X16) of the
-            // temporal residual is small (avoid effects from lighting change).
-            if ((sse - variance) < thresh_sum_diff) {
-              unsigned int sse2;
-              const unsigned int spatial_variance =
-                  cpi->fn_ptr[bsize].vf(src_y, src_ystride, const_source,
-                                        0, &sse2);
-              // Avoid blocks with high brightness and high spatial variance.
-              if ((sse2 - spatial_variance) < thresh_sum_spatial &&
-                  spatial_variance < thresh_spatial_var) {
-                avg_est += variance / ((spatial_variance >> 9) + 1);
-                num_samples++;
-              }
-            }
-          }
-        }
-        src_y += 8;
-        last_src_y += 8;
-        src_u += 4;
-        src_v += 4;
-      }
-      src_y += (src_ystride << 3) - (cm->mi_cols << 3);
-      last_src_y += (last_src_ystride << 3) - (cm->mi_cols << 3);
-      src_u += (src_uvstride << 2) - (cm->mi_cols << 2);
-      src_v += (src_uvstride << 2) - (cm->mi_cols << 2);
-    }
-    ne->last_w = cm->width;
-    ne->last_h = cm->height;
-    // Update noise estimate if we have at a minimum number of block samples,
-    // and avg_est > 0 (avg_est == 0 can happen if the application inputs
-    // duplicate frames).
-    if (num_samples > min_blocks_estimate && avg_est > 0) {
-      // Normalize.
-      avg_est = avg_est / num_samples;
-      // Update noise estimate.
-      ne->value = (int)((15 * ne->value + avg_est) >> 4);
-      ne->count++;
-      if (ne->count == ne->num_frames_estimate) {
-        // Reset counter and check noise level condition.
-        ne->num_frames_estimate = 30;
-        ne->count = 0;
-        ne->level = vp9_noise_estimate_extract_level(ne);
-#if CONFIG_VP9_TEMPORAL_DENOISING
-        if (cpi->oxcf.noise_sensitivity > 0)
-          vp9_denoiser_set_noise_level(&cpi->denoiser, ne->level);
-#endif
-      }
-    }
-  }
-#if CONFIG_VP9_TEMPORAL_DENOISING
-  if (cpi->oxcf.noise_sensitivity > 0)
-    copy_frame(&cpi->denoiser.last_source, cpi->Source);
-#endif
-}
diff --git a/vp9/encoder/vp9_noise_estimate.h b/vp9/encoder/vp9_noise_estimate.h
deleted file mode 100644 (file)
index 826d125..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- *  Copyright (c) 2012 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.
- */
-
-#ifndef VP9_ENCODER_NOISE_ESTIMATE_H_
-#define VP9_ENCODER_NOISE_ESTIMATE_H_
-
-#include "vp9/encoder/vp9_block.h"
-#include "vp9/encoder/vp9_skin_detection.h"
-#include "vpx_scale/yv12config.h"
-
-#if CONFIG_VP9_TEMPORAL_DENOISING
-#include "vp9/encoder/vp9_denoiser.h"
-#endif
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef enum noise_level {
-  kLowLow,
-  kLow,
-  kMedium,
-  kHigh
-} NOISE_LEVEL;
-
-typedef struct noise_estimate {
-  int enabled;
-  NOISE_LEVEL level;
-  int value;
-  int thresh;
-  int count;
-  int last_w;
-  int last_h;
-  int num_frames_estimate;
-} NOISE_ESTIMATE;
-
-struct VP9_COMP;
-
-void vp9_noise_estimate_init(NOISE_ESTIMATE *const ne,
-                             int width,
-                             int height);
-
-NOISE_LEVEL vp9_noise_estimate_extract_level(NOISE_ESTIMATE *const ne);
-
-void vp9_update_noise_estimate(struct VP9_COMP *const cpi);
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP9_ENCODER_NOISE_ESTIMATE_H_
diff --git a/vp9/encoder/vp9_picklpf.c b/vp9/encoder/vp9_picklpf.c
deleted file mode 100644 (file)
index 80ab238..0000000
+++ /dev/null
@@ -1,195 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#include <assert.h>
-#include <limits.h>
-
-#include "./vpx_scale_rtcd.h"
-#include "vpx_dsp/psnr.h"
-#include "vpx_mem/vpx_mem.h"
-#include "vpx_ports/mem.h"
-
-#include "vp9/common/vp9_loopfilter.h"
-#include "vp9/common/vp9_onyxc_int.h"
-#include "vp9/common/vp9_quant_common.h"
-
-#include "vp9/encoder/vp9_encoder.h"
-#include "vp9/encoder/vp9_picklpf.h"
-#include "vp9/encoder/vp9_quantize.h"
-
-static int get_max_filter_level(const VP9_COMP *cpi) {
-  if (cpi->oxcf.pass == 2) {
-    return cpi->twopass.section_intra_rating > 8 ? MAX_LOOP_FILTER * 3 / 4
-                                                 : MAX_LOOP_FILTER;
-  } else {
-    return MAX_LOOP_FILTER;
-  }
-}
-
-
-static int64_t try_filter_frame(const YV12_BUFFER_CONFIG *sd,
-                                VP9_COMP *const cpi,
-                                int filt_level, int partial_frame) {
-  VP9_COMMON *const cm = &cpi->common;
-  int64_t filt_err;
-
-  vp9_build_mask_frame(cm, filt_level, partial_frame);
-
-  if (cpi->num_workers > 1)
-    vp9_loop_filter_frame_mt(cm->frame_to_show, cm, cpi->td.mb.e_mbd.plane,
-                             filt_level, 1, partial_frame,
-                             cpi->workers, cpi->num_workers, &cpi->lf_row_sync);
-  else
-    vp9_loop_filter_frame(cm->frame_to_show, cm, &cpi->td.mb.e_mbd, filt_level,
-                          1, partial_frame);
-
-#if CONFIG_VP9_HIGHBITDEPTH
-  if (cm->use_highbitdepth) {
-    filt_err = vpx_highbd_get_y_sse(sd, cm->frame_to_show);
-  } else {
-    filt_err = vpx_get_y_sse(sd, cm->frame_to_show);
-  }
-#else
-  filt_err = vpx_get_y_sse(sd, cm->frame_to_show);
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-
-  // Re-instate the unfiltered frame
-  vpx_yv12_copy_y(&cpi->last_frame_uf, cm->frame_to_show);
-
-  return filt_err;
-}
-
-static int search_filter_level(const YV12_BUFFER_CONFIG *sd, VP9_COMP *cpi,
-                               int partial_frame) {
-  const VP9_COMMON *const cm = &cpi->common;
-  const struct loopfilter *const lf = &cm->lf;
-  const int min_filter_level = 0;
-  const int max_filter_level = get_max_filter_level(cpi);
-  int filt_direction = 0;
-  int64_t best_err;
-  int filt_best;
-
-  // Start the search at the previous frame filter level unless it is now out of
-  // range.
-  int filt_mid =
-      clamp(lf->last_filt_level, min_filter_level, max_filter_level);
-  int filter_step = filt_mid < 16 ? 4 : filt_mid / 4;
-  // Sum squared error at each filter level
-  int64_t ss_err[MAX_LOOP_FILTER + 1];
-
-  // Set each entry to -1
-  memset(ss_err, 0xFF, sizeof(ss_err));
-
-  //  Make a copy of the unfiltered / processed recon buffer
-  vpx_yv12_copy_y(cm->frame_to_show, &cpi->last_frame_uf);
-
-  best_err = try_filter_frame(sd, cpi, filt_mid, partial_frame);
-  filt_best = filt_mid;
-  ss_err[filt_mid] = best_err;
-
-  while (filter_step > 0) {
-    const int filt_high = VPXMIN(filt_mid + filter_step, max_filter_level);
-    const int filt_low = VPXMAX(filt_mid - filter_step, min_filter_level);
-
-    // Bias against raising loop filter in favor of lowering it.
-    int64_t bias = (best_err >> (15 - (filt_mid / 8))) * filter_step;
-
-    if ((cpi->oxcf.pass == 2) && (cpi->twopass.section_intra_rating < 20))
-      bias = (bias * cpi->twopass.section_intra_rating) / 20;
-
-    // yx, bias less for large block size
-    if (cm->tx_mode != ONLY_4X4)
-      bias >>= 1;
-
-    if (filt_direction <= 0 && filt_low != filt_mid) {
-      // Get Low filter error score
-      if (ss_err[filt_low] < 0) {
-        ss_err[filt_low] = try_filter_frame(sd, cpi, filt_low, partial_frame);
-      }
-      // If value is close to the best so far then bias towards a lower loop
-      // filter value.
-      if ((ss_err[filt_low] - bias) < best_err) {
-        // Was it actually better than the previous best?
-        if (ss_err[filt_low] < best_err)
-          best_err = ss_err[filt_low];
-
-        filt_best = filt_low;
-      }
-    }
-
-    // Now look at filt_high
-    if (filt_direction >= 0 && filt_high != filt_mid) {
-      if (ss_err[filt_high] < 0) {
-        ss_err[filt_high] = try_filter_frame(sd, cpi, filt_high, partial_frame);
-      }
-      // Was it better than the previous best?
-      if (ss_err[filt_high] < (best_err - bias)) {
-        best_err = ss_err[filt_high];
-        filt_best = filt_high;
-      }
-    }
-
-    // Half the step distance if the best filter value was the same as last time
-    if (filt_best == filt_mid) {
-      filter_step /= 2;
-      filt_direction = 0;
-    } else {
-      filt_direction = (filt_best < filt_mid) ? -1 : 1;
-      filt_mid = filt_best;
-    }
-  }
-
-  return filt_best;
-}
-
-void vp9_pick_filter_level(const YV12_BUFFER_CONFIG *sd, VP9_COMP *cpi,
-                           LPF_PICK_METHOD method) {
-  VP9_COMMON *const cm = &cpi->common;
-  struct loopfilter *const lf = &cm->lf;
-
-  lf->sharpness_level = cm->frame_type == KEY_FRAME ? 0
-                                                    : cpi->oxcf.sharpness;
-
-  if (method == LPF_PICK_MINIMAL_LPF && lf->filter_level) {
-      lf->filter_level = 0;
-  } else if (method >= LPF_PICK_FROM_Q) {
-    const int min_filter_level = 0;
-    const int max_filter_level = get_max_filter_level(cpi);
-    const int q = vp9_ac_quant(cm->base_qindex, 0, cm->bit_depth);
-    // These values were determined by linear fitting the result of the
-    // searched level, filt_guess = q * 0.316206 + 3.87252
-#if CONFIG_VP9_HIGHBITDEPTH
-    int filt_guess;
-    switch (cm->bit_depth) {
-      case VPX_BITS_8:
-        filt_guess = ROUND_POWER_OF_TWO(q * 20723 + 1015158, 18);
-        break;
-      case VPX_BITS_10:
-        filt_guess = ROUND_POWER_OF_TWO(q * 20723 + 4060632, 20);
-        break;
-      case VPX_BITS_12:
-        filt_guess = ROUND_POWER_OF_TWO(q * 20723 + 16242526, 22);
-        break;
-      default:
-        assert(0 && "bit_depth should be VPX_BITS_8, VPX_BITS_10 "
-                    "or VPX_BITS_12");
-        return;
-    }
-#else
-    int filt_guess = ROUND_POWER_OF_TWO(q * 20723 + 1015158, 18);
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-    if (cm->frame_type == KEY_FRAME)
-      filt_guess -= 4;
-    lf->filter_level = clamp(filt_guess, min_filter_level, max_filter_level);
-  } else {
-    lf->filter_level = search_filter_level(sd, cpi,
-                                           method == LPF_PICK_FROM_SUBIMAGE);
-  }
-}
diff --git a/vp9/encoder/vp9_picklpf.h b/vp9/encoder/vp9_picklpf.h
deleted file mode 100644 (file)
index 33c490f..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#ifndef VP9_ENCODER_VP9_PICKLPF_H_
-#define VP9_ENCODER_VP9_PICKLPF_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include "vp9/encoder/vp9_encoder.h"
-
-struct yv12_buffer_config;
-struct VP9_COMP;
-
-void vp9_pick_filter_level(const struct yv12_buffer_config *sd,
-                           struct VP9_COMP *cpi, LPF_PICK_METHOD method);
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP9_ENCODER_VP9_PICKLPF_H_
diff --git a/vp9/encoder/vp9_pickmode.c b/vp9/encoder/vp9_pickmode.c
deleted file mode 100644 (file)
index c13f24f..0000000
+++ /dev/null
@@ -1,2315 +0,0 @@
-/*
- *  Copyright (c) 2014 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.
- */
-
-#include <assert.h>
-#include <limits.h>
-#include <math.h>
-#include <stdio.h>
-
-#include "./vp9_rtcd.h"
-#include "./vpx_dsp_rtcd.h"
-
-#include "vpx_dsp/vpx_dsp_common.h"
-#include "vpx_mem/vpx_mem.h"
-#include "vpx_ports/mem.h"
-
-#include "vp9/common/vp9_blockd.h"
-#include "vp9/common/vp9_common.h"
-#include "vp9/common/vp9_mvref_common.h"
-#include "vp9/common/vp9_pred_common.h"
-#include "vp9/common/vp9_reconinter.h"
-#include "vp9/common/vp9_reconintra.h"
-#include "vp9/common/vp9_scan.h"
-
-#include "vp9/encoder/vp9_cost.h"
-#include "vp9/encoder/vp9_encoder.h"
-#include "vp9/encoder/vp9_pickmode.h"
-#include "vp9/encoder/vp9_ratectrl.h"
-#include "vp9/encoder/vp9_rd.h"
-
-typedef struct {
-  uint8_t *data;
-  int stride;
-  int in_use;
-} PRED_BUFFER;
-
-
-static const int pos_shift_16x16[4][4] = {
-  {9, 10, 13, 14},
-  {11, 12, 15, 16},
-  {17, 18, 21, 22},
-  {19, 20, 23, 24}
-};
-
-static int mv_refs_rt(VP9_COMP *cpi, const VP9_COMMON *cm,
-                      const MACROBLOCK *x,
-                      const MACROBLOCKD *xd,
-                      const TileInfo *const tile,
-                      MODE_INFO *mi, MV_REFERENCE_FRAME ref_frame,
-                      int_mv *mv_ref_list, int_mv *base_mv,
-                      int mi_row, int mi_col, int use_base_mv) {
-  const int *ref_sign_bias = cm->ref_frame_sign_bias;
-  int i, refmv_count = 0;
-
-  const POSITION *const mv_ref_search = mv_ref_blocks[mi->sb_type];
-
-  int different_ref_found = 0;
-  int context_counter = 0;
-  int const_motion = 0;
-
-  // Blank the reference vector list
-  memset(mv_ref_list, 0, sizeof(*mv_ref_list) * MAX_MV_REF_CANDIDATES);
-
-  // The nearest 2 blocks are treated differently
-  // if the size < 8x8 we get the mv from the bmi substructure,
-  // and we also need to keep a mode count.
-  for (i = 0; i < 2; ++i) {
-    const POSITION *const mv_ref = &mv_ref_search[i];
-    if (is_inside(tile, mi_col, mi_row, cm->mi_rows, mv_ref)) {
-      const MODE_INFO *const candidate_mi = xd->mi[mv_ref->col + mv_ref->row *
-                                                   xd->mi_stride];
-      // Keep counts for entropy encoding.
-      context_counter += mode_2_counter[candidate_mi->mode];
-      different_ref_found = 1;
-
-      if (candidate_mi->ref_frame[0] == ref_frame)
-        ADD_MV_REF_LIST(get_sub_block_mv(candidate_mi, 0, mv_ref->col, -1),
-                        refmv_count, mv_ref_list, Done);
-    }
-  }
-
-  const_motion = 1;
-
-  // Check the rest of the neighbors in much the same way
-  // as before except we don't need to keep track of sub blocks or
-  // mode counts.
-  for (; i < MVREF_NEIGHBOURS && !refmv_count; ++i) {
-    const POSITION *const mv_ref = &mv_ref_search[i];
-    if (is_inside(tile, mi_col, mi_row, cm->mi_rows, mv_ref)) {
-      const MODE_INFO *const candidate_mi = xd->mi[mv_ref->col + mv_ref->row *
-                                                   xd->mi_stride];
-      different_ref_found = 1;
-
-      if (candidate_mi->ref_frame[0] == ref_frame)
-        ADD_MV_REF_LIST(candidate_mi->mv[0], refmv_count, mv_ref_list, Done);
-    }
-  }
-
-  // Since we couldn't find 2 mvs from the same reference frame
-  // go back through the neighbors and find motion vectors from
-  // different reference frames.
-  if (different_ref_found && !refmv_count) {
-    for (i = 0; i < MVREF_NEIGHBOURS; ++i) {
-      const POSITION *mv_ref = &mv_ref_search[i];
-      if (is_inside(tile, mi_col, mi_row, cm->mi_rows, mv_ref)) {
-        const MODE_INFO *const candidate_mi = xd->mi[mv_ref->col + mv_ref->row
-                                              * xd->mi_stride];
-
-        // If the candidate is INTRA we don't want to consider its mv.
-        IF_DIFF_REF_FRAME_ADD_MV(candidate_mi, ref_frame, ref_sign_bias,
-                                 refmv_count, mv_ref_list, Done);
-      }
-    }
-  }
-  if (use_base_mv &&
-      !cpi->svc.layer_context[cpi->svc.temporal_layer_id].is_key_frame &&
-      ref_frame == LAST_FRAME) {
-    // Get base layer mv.
-    MV_REF *candidate =
-        &cm->prev_frame->mvs[(mi_col>>1) + (mi_row>>1) * (cm->mi_cols>>1)];
-    if (candidate->mv[0].as_int != INVALID_MV) {
-        base_mv->as_mv.row = (candidate->mv[0].as_mv.row * 2);
-        base_mv->as_mv.col = (candidate->mv[0].as_mv.col * 2);
-      clamp_mv_ref(&base_mv->as_mv, xd);
-    } else {
-      base_mv->as_int = INVALID_MV;
-    }
-  }
-
- Done:
-
-  x->mbmi_ext->mode_context[ref_frame] = counter_to_context[context_counter];
-
-  // Clamp vectors
-  for (i = 0; i < MAX_MV_REF_CANDIDATES; ++i)
-    clamp_mv_ref(&mv_ref_list[i].as_mv, xd);
-
-  return const_motion;
-}
-
-static int combined_motion_search(VP9_COMP *cpi, MACROBLOCK *x,
-                                  BLOCK_SIZE bsize, int mi_row, int mi_col,
-                                  int_mv *tmp_mv, int *rate_mv,
-                                  int64_t best_rd_sofar, int use_base_mv) {
-  MACROBLOCKD *xd = &x->e_mbd;
-  MODE_INFO *mi = xd->mi[0];
-  struct buf_2d backup_yv12[MAX_MB_PLANE] = {{0, 0}};
-  const int step_param = cpi->sf.mv.fullpel_search_step_param;
-  const int sadpb = x->sadperbit16;
-  MV mvp_full;
-  const int ref = mi->ref_frame[0];
-  const MV ref_mv = x->mbmi_ext->ref_mvs[ref][0].as_mv;
-  MV center_mv;
-  uint32_t dis;
-  int rate_mode;
-  const int tmp_col_min = x->mv_col_min;
-  const int tmp_col_max = x->mv_col_max;
-  const int tmp_row_min = x->mv_row_min;
-  const int tmp_row_max = x->mv_row_max;
-  int rv = 0;
-  int cost_list[5];
-  const YV12_BUFFER_CONFIG *scaled_ref_frame = vp9_get_scaled_ref_frame(cpi,
-                                                                        ref);
-  if (scaled_ref_frame) {
-    int i;
-    // Swap out the reference frame for a version that's been scaled to
-    // match the resolution of the current frame, allowing the existing
-    // motion search code to be used without additional modifications.
-    for (i = 0; i < MAX_MB_PLANE; i++)
-      backup_yv12[i] = xd->plane[i].pre[0];
-    vp9_setup_pre_planes(xd, 0, scaled_ref_frame, mi_row, mi_col, NULL);
-  }
-  vp9_set_mv_search_range(x, &ref_mv);
-
-  assert(x->mv_best_ref_index[ref] <= 2);
-  if (x->mv_best_ref_index[ref] < 2)
-    mvp_full = x->mbmi_ext->ref_mvs[ref][x->mv_best_ref_index[ref]].as_mv;
-  else
-    mvp_full = x->pred_mv[ref];
-
-  mvp_full.col >>= 3;
-  mvp_full.row >>= 3;
-
-  if (!use_base_mv)
-    center_mv = ref_mv;
-  else
-    center_mv = tmp_mv->as_mv;
-
-  vp9_full_pixel_search(cpi, x, bsize, &mvp_full, step_param, sadpb,
-                        cond_cost_list(cpi, cost_list),
-                        &center_mv, &tmp_mv->as_mv, INT_MAX, 0);
-
-  x->mv_col_min = tmp_col_min;
-  x->mv_col_max = tmp_col_max;
-  x->mv_row_min = tmp_row_min;
-  x->mv_row_max = tmp_row_max;
-
-  // calculate the bit cost on motion vector
-  mvp_full.row = tmp_mv->as_mv.row * 8;
-  mvp_full.col = tmp_mv->as_mv.col * 8;
-
-  *rate_mv = vp9_mv_bit_cost(&mvp_full, &ref_mv,
-                             x->nmvjointcost, x->mvcost, MV_COST_WEIGHT);
-
-  rate_mode = cpi->inter_mode_cost[x->mbmi_ext->mode_context[ref]]
-                                  [INTER_OFFSET(NEWMV)];
-  rv = !(RDCOST(x->rdmult, x->rddiv, (*rate_mv + rate_mode), 0) >
-         best_rd_sofar);
-
-  if (rv) {
-    cpi->find_fractional_mv_step(x, &tmp_mv->as_mv, &ref_mv,
-                                 cpi->common.allow_high_precision_mv,
-                                 x->errorperbit,
-                                 &cpi->fn_ptr[bsize],
-                                 cpi->sf.mv.subpel_force_stop,
-                                 cpi->sf.mv.subpel_iters_per_step,
-                                 cond_cost_list(cpi, cost_list),
-                                 x->nmvjointcost, x->mvcost,
-                                 &dis, &x->pred_sse[ref], NULL, 0, 0);
-    *rate_mv = vp9_mv_bit_cost(&tmp_mv->as_mv, &ref_mv,
-                               x->nmvjointcost, x->mvcost, MV_COST_WEIGHT);
-  }
-
-  if (scaled_ref_frame) {
-    int i;
-    for (i = 0; i < MAX_MB_PLANE; i++)
-      xd->plane[i].pre[0] = backup_yv12[i];
-  }
-  return rv;
-}
-
-static void block_variance(const uint8_t *src, int src_stride,
-                           const uint8_t *ref, int ref_stride,
-                           int w, int h, unsigned int *sse, int *sum,
-                           int block_size, unsigned int *sse8x8,
-                           int *sum8x8, unsigned int *var8x8) {
-  int i, j, k = 0;
-
-  *sse = 0;
-  *sum = 0;
-
-  for (i = 0; i < h; i += block_size) {
-    for (j = 0; j < w; j += block_size) {
-      vpx_get8x8var(src + src_stride * i + j, src_stride,
-                    ref + ref_stride * i + j, ref_stride,
-                    &sse8x8[k], &sum8x8[k]);
-      *sse += sse8x8[k];
-      *sum += sum8x8[k];
-      var8x8[k] = sse8x8[k] - (uint32_t)(((int64_t)sum8x8[k] * sum8x8[k]) >> 6);
-      k++;
-    }
-  }
-}
-
-static void calculate_variance(int bw, int bh, TX_SIZE tx_size,
-                               unsigned int *sse_i, int *sum_i,
-                               unsigned int *var_o, unsigned int *sse_o,
-                               int *sum_o) {
-  const BLOCK_SIZE unit_size = txsize_to_bsize[tx_size];
-  const int nw = 1 << (bw - b_width_log2_lookup[unit_size]);
-  const int nh = 1 << (bh - b_height_log2_lookup[unit_size]);
-  int i, j, k = 0;
-
-  for (i = 0; i < nh; i += 2) {
-    for (j = 0; j < nw; j += 2) {
-      sse_o[k] = sse_i[i * nw + j] + sse_i[i * nw + j + 1] +
-          sse_i[(i + 1) * nw + j] + sse_i[(i + 1) * nw + j + 1];
-      sum_o[k] = sum_i[i * nw + j] + sum_i[i * nw + j + 1] +
-          sum_i[(i + 1) * nw + j] + sum_i[(i + 1) * nw + j + 1];
-      var_o[k] = sse_o[k] - (uint32_t)(((int64_t)sum_o[k] * sum_o[k]) >>
-          (b_width_log2_lookup[unit_size] +
-              b_height_log2_lookup[unit_size] + 6));
-      k++;
-    }
-  }
-}
-
-static void model_rd_for_sb_y_large(VP9_COMP *cpi, BLOCK_SIZE bsize,
-                                    MACROBLOCK *x, MACROBLOCKD *xd,
-                                    int *out_rate_sum, int64_t *out_dist_sum,
-                                    unsigned int *var_y, unsigned int *sse_y,
-                                    int mi_row, int mi_col, int *early_term) {
-  // Note our transform coeffs are 8 times an orthogonal transform.
-  // Hence quantizer step is also 8 times. To get effective quantizer
-  // we need to divide by 8 before sending to modeling function.
-  unsigned int sse;
-  int rate;
-  int64_t dist;
-  struct macroblock_plane *const p = &x->plane[0];
-  struct macroblockd_plane *const pd = &xd->plane[0];
-  const uint32_t dc_quant = pd->dequant[0];
-  const uint32_t ac_quant = pd->dequant[1];
-  const int64_t dc_thr = dc_quant * dc_quant >> 6;
-  const int64_t ac_thr = ac_quant * ac_quant >> 6;
-  unsigned int var;
-  int sum;
-  int skip_dc = 0;
-
-  const int bw = b_width_log2_lookup[bsize];
-  const int bh = b_height_log2_lookup[bsize];
-  const int num8x8 = 1 << (bw + bh - 2);
-  unsigned int sse8x8[64] = {0};
-  int sum8x8[64] = {0};
-  unsigned int var8x8[64] = {0};
-  TX_SIZE tx_size;
-  int i, k;
-
-  // Calculate variance for whole partition, and also save 8x8 blocks' variance
-  // to be used in following transform skipping test.
-  block_variance(p->src.buf, p->src.stride, pd->dst.buf, pd->dst.stride,
-                 4 << bw, 4 << bh, &sse, &sum, 8, sse8x8, sum8x8, var8x8);
-  var = sse - (((int64_t)sum * sum) >> (bw + bh + 4));
-
-  *var_y = var;
-  *sse_y = sse;
-
-  if (cpi->common.tx_mode == TX_MODE_SELECT) {
-    if (sse > (var << 2))
-      tx_size = VPXMIN(max_txsize_lookup[bsize],
-                       tx_mode_to_biggest_tx_size[cpi->common.tx_mode]);
-    else
-      tx_size = TX_8X8;
-
-    if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ &&
-        cyclic_refresh_segment_id_boosted(xd->mi[0]->segment_id))
-      tx_size = TX_8X8;
-    else if (tx_size > TX_16X16)
-      tx_size = TX_16X16;
-  } else {
-    tx_size = VPXMIN(max_txsize_lookup[bsize],
-                     tx_mode_to_biggest_tx_size[cpi->common.tx_mode]);
-  }
-
-  assert(tx_size >= TX_8X8);
-  xd->mi[0]->tx_size = tx_size;
-
-  // Evaluate if the partition block is a skippable block in Y plane.
-  {
-    unsigned int sse16x16[16] = {0};
-    int sum16x16[16] = {0};
-    unsigned int var16x16[16] = {0};
-    const int num16x16 = num8x8 >> 2;
-
-    unsigned int sse32x32[4] = {0};
-    int sum32x32[4] = {0};
-    unsigned int var32x32[4] = {0};
-    const int num32x32 = num8x8 >> 4;
-
-    int ac_test = 1;
-    int dc_test = 1;
-    const int num = (tx_size == TX_8X8) ? num8x8 :
-        ((tx_size == TX_16X16) ? num16x16 : num32x32);
-    const unsigned int *sse_tx = (tx_size == TX_8X8) ? sse8x8 :
-        ((tx_size == TX_16X16) ? sse16x16 : sse32x32);
-    const unsigned int *var_tx = (tx_size == TX_8X8) ? var8x8 :
-        ((tx_size == TX_16X16) ? var16x16 : var32x32);
-
-    // Calculate variance if tx_size > TX_8X8
-    if (tx_size >= TX_16X16)
-      calculate_variance(bw, bh, TX_8X8, sse8x8, sum8x8, var16x16, sse16x16,
-                         sum16x16);
-    if (tx_size == TX_32X32)
-      calculate_variance(bw, bh, TX_16X16, sse16x16, sum16x16, var32x32,
-                         sse32x32, sum32x32);
-
-    // Skipping test
-    x->skip_txfm[0] = SKIP_TXFM_NONE;
-    for (k = 0; k < num; k++)
-      // Check if all ac coefficients can be quantized to zero.
-      if (!(var_tx[k] < ac_thr || var == 0)) {
-        ac_test = 0;
-        break;
-      }
-
-    for (k = 0; k < num; k++)
-      // Check if dc coefficient can be quantized to zero.
-      if (!(sse_tx[k] - var_tx[k] < dc_thr || sse == var)) {
-        dc_test = 0;
-        break;
-      }
-
-    if (ac_test) {
-      x->skip_txfm[0] = SKIP_TXFM_AC_ONLY;
-
-      if (dc_test)
-        x->skip_txfm[0] = SKIP_TXFM_AC_DC;
-    } else if (dc_test) {
-      skip_dc = 1;
-    }
-  }
-
-  if (x->skip_txfm[0] == SKIP_TXFM_AC_DC) {
-    int skip_uv[2] = {0};
-    unsigned int var_uv[2];
-    unsigned int sse_uv[2];
-
-    *out_rate_sum = 0;
-    *out_dist_sum = sse << 4;
-
-    // Transform skipping test in UV planes.
-    for (i = 1; i <= 2; i++) {
-      struct macroblock_plane *const p = &x->plane[i];
-      struct macroblockd_plane *const pd = &xd->plane[i];
-      const TX_SIZE uv_tx_size = get_uv_tx_size(xd->mi[0], pd);
-      const BLOCK_SIZE unit_size = txsize_to_bsize[uv_tx_size];
-      const BLOCK_SIZE uv_bsize = get_plane_block_size(bsize, pd);
-      const int uv_bw = b_width_log2_lookup[uv_bsize];
-      const int uv_bh = b_height_log2_lookup[uv_bsize];
-      const int sf = (uv_bw - b_width_log2_lookup[unit_size]) +
-          (uv_bh - b_height_log2_lookup[unit_size]);
-      const uint32_t uv_dc_thr = pd->dequant[0] * pd->dequant[0] >> (6 - sf);
-      const uint32_t uv_ac_thr = pd->dequant[1] * pd->dequant[1] >> (6 - sf);
-      int j = i - 1;
-
-      vp9_build_inter_predictors_sbp(xd, mi_row, mi_col, bsize, i);
-      var_uv[j] = cpi->fn_ptr[uv_bsize].vf(p->src.buf, p->src.stride,
-          pd->dst.buf, pd->dst.stride, &sse_uv[j]);
-
-      if ((var_uv[j] < uv_ac_thr || var_uv[j] == 0) &&
-          (sse_uv[j] - var_uv[j] < uv_dc_thr || sse_uv[j] == var_uv[j]))
-        skip_uv[j] = 1;
-      else
-        break;
-    }
-
-    // If the transform in YUV planes are skippable, the mode search checks
-    // fewer inter modes and doesn't check intra modes.
-    if (skip_uv[0] & skip_uv[1]) {
-      *early_term = 1;
-    }
-
-    return;
-  }
-
-  if (!skip_dc) {
-#if CONFIG_VP9_HIGHBITDEPTH
-    if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
-      vp9_model_rd_from_var_lapndz(sse - var, num_pels_log2_lookup[bsize],
-                                   dc_quant >> (xd->bd - 5), &rate, &dist);
-    } else {
-      vp9_model_rd_from_var_lapndz(sse - var, num_pels_log2_lookup[bsize],
-                                   dc_quant >> 3, &rate, &dist);
-    }
-#else
-    vp9_model_rd_from_var_lapndz(sse - var, num_pels_log2_lookup[bsize],
-                                 dc_quant >> 3, &rate, &dist);
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-  }
-
-  if (!skip_dc) {
-    *out_rate_sum = rate >> 1;
-    *out_dist_sum = dist << 3;
-  } else {
-    *out_rate_sum = 0;
-    *out_dist_sum = (sse - var) << 4;
-  }
-
-#if CONFIG_VP9_HIGHBITDEPTH
-  if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
-    vp9_model_rd_from_var_lapndz(var, num_pels_log2_lookup[bsize],
-                                 ac_quant >> (xd->bd - 5), &rate, &dist);
-  } else {
-    vp9_model_rd_from_var_lapndz(var, num_pels_log2_lookup[bsize],
-                                 ac_quant >> 3, &rate, &dist);
-  }
-#else
-  vp9_model_rd_from_var_lapndz(var, num_pels_log2_lookup[bsize],
-                               ac_quant >> 3, &rate, &dist);
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-
-  *out_rate_sum += rate;
-  *out_dist_sum += dist << 4;
-}
-
-static void model_rd_for_sb_y(VP9_COMP *cpi, BLOCK_SIZE bsize,
-                              MACROBLOCK *x, MACROBLOCKD *xd,
-                              int *out_rate_sum, int64_t *out_dist_sum,
-                              unsigned int *var_y, unsigned int *sse_y) {
-  // Note our transform coeffs are 8 times an orthogonal transform.
-  // Hence quantizer step is also 8 times. To get effective quantizer
-  // we need to divide by 8 before sending to modeling function.
-  unsigned int sse;
-  int rate;
-  int64_t dist;
-  struct macroblock_plane *const p = &x->plane[0];
-  struct macroblockd_plane *const pd = &xd->plane[0];
-  const int64_t dc_thr = p->quant_thred[0] >> 6;
-  const int64_t ac_thr = p->quant_thred[1] >> 6;
-  const uint32_t dc_quant = pd->dequant[0];
-  const uint32_t ac_quant = pd->dequant[1];
-  unsigned int var = cpi->fn_ptr[bsize].vf(p->src.buf, p->src.stride,
-                                           pd->dst.buf, pd->dst.stride, &sse);
-  int skip_dc = 0;
-
-  *var_y = var;
-  *sse_y = sse;
-
-  if (cpi->common.tx_mode == TX_MODE_SELECT) {
-    if (sse > (var << 2))
-      xd->mi[0]->tx_size =
-          VPXMIN(max_txsize_lookup[bsize],
-                 tx_mode_to_biggest_tx_size[cpi->common.tx_mode]);
-    else
-      xd->mi[0]->tx_size = TX_8X8;
-
-    if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ &&
-        cyclic_refresh_segment_id_boosted(xd->mi[0]->segment_id))
-      xd->mi[0]->tx_size = TX_8X8;
-    else if (xd->mi[0]->tx_size > TX_16X16)
-      xd->mi[0]->tx_size = TX_16X16;
-  } else {
-    xd->mi[0]->tx_size =
-        VPXMIN(max_txsize_lookup[bsize],
-               tx_mode_to_biggest_tx_size[cpi->common.tx_mode]);
-  }
-
-  // Evaluate if the partition block is a skippable block in Y plane.
-  {
-    const BLOCK_SIZE unit_size =
-        txsize_to_bsize[xd->mi[0]->tx_size];
-    const unsigned int num_blk_log2 =
-        (b_width_log2_lookup[bsize] - b_width_log2_lookup[unit_size]) +
-        (b_height_log2_lookup[bsize] - b_height_log2_lookup[unit_size]);
-    const unsigned int sse_tx = sse >> num_blk_log2;
-    const unsigned int var_tx = var >> num_blk_log2;
-
-    x->skip_txfm[0] = SKIP_TXFM_NONE;
-    // Check if all ac coefficients can be quantized to zero.
-    if (var_tx < ac_thr || var == 0) {
-      x->skip_txfm[0] = SKIP_TXFM_AC_ONLY;
-      // Check if dc coefficient can be quantized to zero.
-      if (sse_tx - var_tx < dc_thr || sse == var)
-        x->skip_txfm[0] = SKIP_TXFM_AC_DC;
-    } else {
-      if (sse_tx - var_tx < dc_thr || sse == var)
-        skip_dc = 1;
-    }
-  }
-
-  if (x->skip_txfm[0] == SKIP_TXFM_AC_DC) {
-    *out_rate_sum = 0;
-    *out_dist_sum = sse << 4;
-    return;
-  }
-
-  if (!skip_dc) {
-#if CONFIG_VP9_HIGHBITDEPTH
-    if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
-      vp9_model_rd_from_var_lapndz(sse - var, num_pels_log2_lookup[bsize],
-                                   dc_quant >> (xd->bd - 5), &rate, &dist);
-    } else {
-      vp9_model_rd_from_var_lapndz(sse - var, num_pels_log2_lookup[bsize],
-                                   dc_quant >> 3, &rate, &dist);
-    }
-#else
-    vp9_model_rd_from_var_lapndz(sse - var, num_pels_log2_lookup[bsize],
-                                 dc_quant >> 3, &rate, &dist);
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-  }
-
-  if (!skip_dc) {
-    *out_rate_sum = rate >> 1;
-    *out_dist_sum = dist << 3;
-  } else {
-    *out_rate_sum = 0;
-    *out_dist_sum = (sse - var) << 4;
-  }
-
-#if CONFIG_VP9_HIGHBITDEPTH
-  if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
-    vp9_model_rd_from_var_lapndz(var, num_pels_log2_lookup[bsize],
-                                 ac_quant >> (xd->bd - 5), &rate, &dist);
-  } else {
-    vp9_model_rd_from_var_lapndz(var, num_pels_log2_lookup[bsize],
-                                 ac_quant >> 3, &rate, &dist);
-  }
-#else
-  vp9_model_rd_from_var_lapndz(var, num_pels_log2_lookup[bsize],
-                               ac_quant >> 3, &rate, &dist);
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-
-  *out_rate_sum += rate;
-  *out_dist_sum += dist << 4;
-}
-
-#if CONFIG_VP9_HIGHBITDEPTH
-static void block_yrd(VP9_COMP *cpi, MACROBLOCK *x, RD_COST *this_rdc,
-                      int *skippable, int64_t *sse, BLOCK_SIZE bsize,
-                      TX_SIZE tx_size) {
-  MACROBLOCKD *xd = &x->e_mbd;
-  unsigned int var_y, sse_y;
-
-  (void)tx_size;
-  model_rd_for_sb_y(cpi, bsize, x, xd, &this_rdc->rate, &this_rdc->dist, &var_y,
-                    &sse_y);
-  *sse = INT_MAX;
-  *skippable = 0;
-  return;
-}
-#else
-static void block_yrd(VP9_COMP *cpi, MACROBLOCK *x, RD_COST *this_rdc,
-                      int *skippable, int64_t *sse, BLOCK_SIZE bsize,
-                      TX_SIZE tx_size) {
-  MACROBLOCKD *xd = &x->e_mbd;
-  const struct macroblockd_plane *pd = &xd->plane[0];
-  struct macroblock_plane *const p = &x->plane[0];
-  const int num_4x4_w = num_4x4_blocks_wide_lookup[bsize];
-  const int num_4x4_h = num_4x4_blocks_high_lookup[bsize];
-  const int step = 1 << (tx_size << 1);
-  const int block_step = (1 << tx_size);
-  int block = 0, r, c;
-  const int max_blocks_wide = num_4x4_w + (xd->mb_to_right_edge >= 0 ? 0 :
-      xd->mb_to_right_edge >> 5);
-  const int max_blocks_high = num_4x4_h + (xd->mb_to_bottom_edge >= 0 ? 0 :
-      xd->mb_to_bottom_edge >> 5);
-  int eob_cost = 0;
-  const int bw = 4 * num_4x4_w;
-  const int bh = 4 * num_4x4_h;
-
-  (void)cpi;
-
-  // The max tx_size passed in is TX_16X16.
-  assert(tx_size != TX_32X32);
-
-  vpx_subtract_block(bh, bw, p->src_diff, bw, p->src.buf, p->src.stride,
-                     pd->dst.buf, pd->dst.stride);
-  *skippable = 1;
-  // Keep track of the row and column of the blocks we use so that we know
-  // if we are in the unrestricted motion border.
-  for (r = 0; r < max_blocks_high; r += block_step) {
-    for (c = 0; c < num_4x4_w; c += block_step) {
-      if (c < max_blocks_wide) {
-        const scan_order *const scan_order = &vp9_default_scan_orders[tx_size];
-        tran_low_t *const coeff = BLOCK_OFFSET(p->coeff, block);
-        tran_low_t *const qcoeff = BLOCK_OFFSET(p->qcoeff, block);
-        tran_low_t *const dqcoeff = BLOCK_OFFSET(pd->dqcoeff, block);
-        uint16_t *const eob = &p->eobs[block];
-        const int diff_stride = bw;
-        const int16_t *src_diff;
-        src_diff = &p->src_diff[(r * diff_stride + c) << 2];
-
-        switch (tx_size) {
-          case TX_16X16:
-            vpx_hadamard_16x16(src_diff, diff_stride, (int16_t *)coeff);
-            vp9_quantize_fp(coeff, 256, x->skip_block, p->zbin, p->round_fp,
-                            p->quant_fp, p->quant_shift, qcoeff, dqcoeff,
-                            pd->dequant, eob,
-                            scan_order->scan, scan_order->iscan);
-            break;
-          case TX_8X8:
-            vpx_hadamard_8x8(src_diff, diff_stride, (int16_t *)coeff);
-            vp9_quantize_fp(coeff, 64, x->skip_block, p->zbin, p->round_fp,
-                            p->quant_fp, p->quant_shift, qcoeff, dqcoeff,
-                            pd->dequant, eob,
-                            scan_order->scan, scan_order->iscan);
-            break;
-          case TX_4X4:
-            x->fwd_txm4x4(src_diff, coeff, diff_stride);
-            vp9_quantize_fp(coeff, 16, x->skip_block, p->zbin, p->round_fp,
-                            p->quant_fp, p->quant_shift, qcoeff, dqcoeff,
-                            pd->dequant, eob,
-                            scan_order->scan, scan_order->iscan);
-            break;
-          default:
-            assert(0);
-            break;
-        }
-        *skippable &= (*eob == 0);
-        eob_cost += 1;
-      }
-      block += step;
-    }
-  }
-
-  this_rdc->rate = 0;
-  if (*sse < INT64_MAX) {
-    *sse = (*sse << 6) >> 2;
-    if (*skippable) {
-      this_rdc->dist = *sse;
-      return;
-    }
-  }
-
-  block = 0;
-  this_rdc->dist = 0;
-  for (r = 0; r < max_blocks_high; r += block_step) {
-    for (c = 0; c < num_4x4_w; c += block_step) {
-      if (c < max_blocks_wide) {
-        tran_low_t *const coeff = BLOCK_OFFSET(p->coeff, block);
-        tran_low_t *const qcoeff = BLOCK_OFFSET(p->qcoeff, block);
-        tran_low_t *const dqcoeff = BLOCK_OFFSET(pd->dqcoeff, block);
-        uint16_t *const eob = &p->eobs[block];
-
-        if (*eob == 1)
-          this_rdc->rate += (int)abs(qcoeff[0]);
-        else if (*eob > 1)
-          this_rdc->rate += vpx_satd((const int16_t *)qcoeff, step << 4);
-
-        this_rdc->dist +=
-            vp9_block_error_fp(coeff, dqcoeff, step << 4) >> 2;
-      }
-      block += step;
-    }
-  }
-
-  // If skippable is set, rate gets clobbered later.
-  this_rdc->rate <<= (2 + VP9_PROB_COST_SHIFT);
-  this_rdc->rate += (eob_cost << VP9_PROB_COST_SHIFT);
-}
-#endif
-
-static void model_rd_for_sb_uv(VP9_COMP *cpi, BLOCK_SIZE plane_bsize,
-                               MACROBLOCK *x, MACROBLOCKD *xd,
-                               RD_COST *this_rdc,
-                               unsigned int *var_y, unsigned int *sse_y,
-                               int start_plane, int stop_plane) {
-  // Note our transform coeffs are 8 times an orthogonal transform.
-  // Hence quantizer step is also 8 times. To get effective quantizer
-  // we need to divide by 8 before sending to modeling function.
-  unsigned int sse;
-  int rate;
-  int64_t dist;
-  int i;
-
-  this_rdc->rate = 0;
-  this_rdc->dist = 0;
-
-  for (i = start_plane; i <= stop_plane; ++i) {
-    struct macroblock_plane *const p = &x->plane[i];
-    struct macroblockd_plane *const pd = &xd->plane[i];
-    const uint32_t dc_quant = pd->dequant[0];
-    const uint32_t ac_quant = pd->dequant[1];
-    const BLOCK_SIZE bs = plane_bsize;
-    unsigned int var;
-
-    if (!x->color_sensitivity[i - 1])
-      continue;
-
-    var = cpi->fn_ptr[bs].vf(p->src.buf, p->src.stride,
-                             pd->dst.buf, pd->dst.stride, &sse);
-    *var_y += var;
-    *sse_y += sse;
-
-  #if CONFIG_VP9_HIGHBITDEPTH
-    if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
-      vp9_model_rd_from_var_lapndz(sse - var, num_pels_log2_lookup[bs],
-                                   dc_quant >> (xd->bd - 5), &rate, &dist);
-    } else {
-      vp9_model_rd_from_var_lapndz(sse - var, num_pels_log2_lookup[bs],
-                                   dc_quant >> 3, &rate, &dist);
-    }
-  #else
-    vp9_model_rd_from_var_lapndz(sse - var, num_pels_log2_lookup[bs],
-                                 dc_quant >> 3, &rate, &dist);
-  #endif  // CONFIG_VP9_HIGHBITDEPTH
-
-    this_rdc->rate += rate >> 1;
-    this_rdc->dist += dist << 3;
-
-  #if CONFIG_VP9_HIGHBITDEPTH
-    if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
-      vp9_model_rd_from_var_lapndz(var, num_pels_log2_lookup[bs],
-                                   ac_quant >> (xd->bd - 5), &rate, &dist);
-    } else {
-      vp9_model_rd_from_var_lapndz(var, num_pels_log2_lookup[bs],
-                                   ac_quant >> 3, &rate, &dist);
-    }
-  #else
-    vp9_model_rd_from_var_lapndz(var, num_pels_log2_lookup[bs],
-                                 ac_quant >> 3, &rate, &dist);
-  #endif  // CONFIG_VP9_HIGHBITDEPTH
-
-    this_rdc->rate += rate;
-    this_rdc->dist += dist << 4;
-  }
-}
-
-static int get_pred_buffer(PRED_BUFFER *p, int len) {
-  int i;
-
-  for (i = 0; i < len; i++) {
-    if (!p[i].in_use) {
-      p[i].in_use = 1;
-      return i;
-    }
-  }
-  return -1;
-}
-
-static void free_pred_buffer(PRED_BUFFER *p) {
-  if (p != NULL)
-    p->in_use = 0;
-}
-
-static void encode_breakout_test(VP9_COMP *cpi, MACROBLOCK *x,
-                                 BLOCK_SIZE bsize, int mi_row, int mi_col,
-                                 MV_REFERENCE_FRAME ref_frame,
-                                 PREDICTION_MODE this_mode,
-                                 unsigned int var_y, unsigned int sse_y,
-                                 struct buf_2d yv12_mb[][MAX_MB_PLANE],
-                                 int *rate, int64_t *dist) {
-  MACROBLOCKD *xd = &x->e_mbd;
-  MODE_INFO *const mi = xd->mi[0];
-  const BLOCK_SIZE uv_size = get_plane_block_size(bsize, &xd->plane[1]);
-  unsigned int var = var_y, sse = sse_y;
-  // Skipping threshold for ac.
-  unsigned int thresh_ac;
-  // Skipping threshold for dc.
-  unsigned int thresh_dc;
-  int motion_low = 1;
-  if (mi->mv[0].as_mv.row > 64 ||
-      mi->mv[0].as_mv.row < -64 ||
-      mi->mv[0].as_mv.col > 64 ||
-      mi->mv[0].as_mv.col < -64)
-    motion_low = 0;
-  if (x->encode_breakout > 0 && motion_low == 1) {
-    // Set a maximum for threshold to avoid big PSNR loss in low bit rate
-    // case. Use extreme low threshold for static frames to limit
-    // skipping.
-    const unsigned int max_thresh = 36000;
-    // The encode_breakout input
-    const unsigned int min_thresh =
-        VPXMIN(((unsigned int)x->encode_breakout << 4), max_thresh);
-#if CONFIG_VP9_HIGHBITDEPTH
-    const int shift = (xd->bd << 1) - 16;
-#endif
-
-    // Calculate threshold according to dequant value.
-    thresh_ac = (xd->plane[0].dequant[1] * xd->plane[0].dequant[1]) >> 3;
-#if CONFIG_VP9_HIGHBITDEPTH
-    if ((xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) && shift > 0) {
-      thresh_ac = ROUND_POWER_OF_TWO(thresh_ac, shift);
-    }
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-    thresh_ac = clamp(thresh_ac, min_thresh, max_thresh);
-
-    // Adjust ac threshold according to partition size.
-    thresh_ac >>=
-        8 - (b_width_log2_lookup[bsize] + b_height_log2_lookup[bsize]);
-
-    thresh_dc = (xd->plane[0].dequant[0] * xd->plane[0].dequant[0] >> 6);
-#if CONFIG_VP9_HIGHBITDEPTH
-    if ((xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) && shift > 0) {
-      thresh_dc = ROUND_POWER_OF_TWO(thresh_dc, shift);
-    }
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-  } else {
-    thresh_ac = 0;
-    thresh_dc = 0;
-  }
-
-  // Y skipping condition checking for ac and dc.
-  if (var <= thresh_ac && (sse - var) <= thresh_dc) {
-    unsigned int sse_u, sse_v;
-    unsigned int var_u, var_v;
-    unsigned int thresh_ac_uv = thresh_ac;
-    unsigned int thresh_dc_uv = thresh_dc;
-    if (x->sb_is_skin) {
-      thresh_ac_uv = 0;
-      thresh_dc_uv = 0;
-    }
-
-    // Skip UV prediction unless breakout is zero (lossless) to save
-    // computation with low impact on the result
-    if (x->encode_breakout == 0) {
-      xd->plane[1].pre[0] = yv12_mb[ref_frame][1];
-      xd->plane[2].pre[0] = yv12_mb[ref_frame][2];
-      vp9_build_inter_predictors_sbuv(xd, mi_row, mi_col, bsize);
-    }
-
-    var_u = cpi->fn_ptr[uv_size].vf(x->plane[1].src.buf,
-                                    x->plane[1].src.stride,
-                                    xd->plane[1].dst.buf,
-                                    xd->plane[1].dst.stride, &sse_u);
-
-    // U skipping condition checking
-    if (((var_u << 2) <= thresh_ac_uv) && (sse_u - var_u <= thresh_dc_uv)) {
-      var_v = cpi->fn_ptr[uv_size].vf(x->plane[2].src.buf,
-                                      x->plane[2].src.stride,
-                                      xd->plane[2].dst.buf,
-                                      xd->plane[2].dst.stride, &sse_v);
-
-      // V skipping condition checking
-      if (((var_v << 2) <= thresh_ac_uv) && (sse_v - var_v <= thresh_dc_uv)) {
-        x->skip = 1;
-
-        // The cost of skip bit needs to be added.
-        *rate = cpi->inter_mode_cost[x->mbmi_ext->mode_context[ref_frame]]
-                                    [INTER_OFFSET(this_mode)];
-
-        // More on this part of rate
-        // rate += vp9_cost_bit(vp9_get_skip_prob(cm, xd), 1);
-
-        // Scaling factor for SSE from spatial domain to frequency
-        // domain is 16. Adjust distortion accordingly.
-        // TODO(yunqingwang): In this function, only y-plane dist is
-        // calculated.
-        *dist = (sse << 4);  // + ((sse_u + sse_v) << 4);
-
-        // *disable_skip = 1;
-      }
-    }
-  }
-}
-
-struct estimate_block_intra_args {
-  VP9_COMP *cpi;
-  MACROBLOCK *x;
-  PREDICTION_MODE mode;
-  int skippable;
-  RD_COST *rdc;
-};
-
-static void estimate_block_intra(int plane, int block, BLOCK_SIZE plane_bsize,
-                                 TX_SIZE tx_size, void *arg) {
-  struct estimate_block_intra_args* const args = arg;
-  VP9_COMP *const cpi = args->cpi;
-  MACROBLOCK *const x = args->x;
-  MACROBLOCKD *const xd = &x->e_mbd;
-  struct macroblock_plane *const p = &x->plane[0];
-  struct macroblockd_plane *const pd = &xd->plane[0];
-  const BLOCK_SIZE bsize_tx = txsize_to_bsize[tx_size];
-  uint8_t *const src_buf_base = p->src.buf;
-  uint8_t *const dst_buf_base = pd->dst.buf;
-  const int src_stride = p->src.stride;
-  const int dst_stride = pd->dst.stride;
-  int i, j;
-  RD_COST this_rdc;
-
-  txfrm_block_to_raster_xy(plane_bsize, tx_size, block, &i, &j);
-
-  p->src.buf = &src_buf_base[4 * (j * src_stride + i)];
-  pd->dst.buf = &dst_buf_base[4 * (j * dst_stride + i)];
-  // Use source buffer as an approximation for the fully reconstructed buffer.
-  vp9_predict_intra_block(xd, b_width_log2_lookup[plane_bsize],
-                          tx_size, args->mode,
-                          x->skip_encode ? p->src.buf : pd->dst.buf,
-                          x->skip_encode ? src_stride : dst_stride,
-                          pd->dst.buf, dst_stride,
-                          i, j, plane);
-
-  if (plane == 0) {
-    int64_t this_sse = INT64_MAX;
-    // TODO(jingning): This needs further refactoring.
-    block_yrd(cpi, x, &this_rdc, &args->skippable, &this_sse, bsize_tx,
-              VPXMIN(tx_size, TX_16X16));
-  } else {
-    unsigned int var = 0;
-    unsigned int sse = 0;
-    model_rd_for_sb_uv(cpi, plane_bsize, x, xd, &this_rdc, &var, &sse, plane,
-                       plane);
-  }
-
-  p->src.buf = src_buf_base;
-  pd->dst.buf = dst_buf_base;
-  args->rdc->rate += this_rdc.rate;
-  args->rdc->dist += this_rdc.dist;
-}
-
-static const THR_MODES mode_idx[MAX_REF_FRAMES - 1][4] = {
-  {THR_DC, THR_V_PRED, THR_H_PRED, THR_TM},
-  {THR_NEARESTMV, THR_NEARMV, THR_ZEROMV, THR_NEWMV},
-  {THR_NEARESTG, THR_NEARG, THR_ZEROG, THR_NEWG},
-};
-
-static const PREDICTION_MODE intra_mode_list[] = {
-  DC_PRED, V_PRED, H_PRED, TM_PRED
-};
-
-static int mode_offset(const PREDICTION_MODE mode) {
-  if (mode >= NEARESTMV) {
-    return INTER_OFFSET(mode);
-  } else {
-    switch (mode) {
-      case DC_PRED:
-        return 0;
-      case V_PRED:
-        return 1;
-      case H_PRED:
-        return 2;
-      case TM_PRED:
-        return 3;
-      default:
-        return -1;
-    }
-  }
-}
-
-static INLINE void update_thresh_freq_fact(VP9_COMP *cpi,
-                                           TileDataEnc *tile_data,
-                                           BLOCK_SIZE bsize,
-                                           MV_REFERENCE_FRAME ref_frame,
-                                           THR_MODES best_mode_idx,
-                                           PREDICTION_MODE mode) {
-  THR_MODES thr_mode_idx = mode_idx[ref_frame][mode_offset(mode)];
-  int *freq_fact = &tile_data->thresh_freq_fact[bsize][thr_mode_idx];
-  if (thr_mode_idx == best_mode_idx)
-    *freq_fact -= (*freq_fact >> 4);
-  else
-    *freq_fact = VPXMIN(*freq_fact + RD_THRESH_INC,
-                        cpi->sf.adaptive_rd_thresh * RD_THRESH_MAX_FACT);
-}
-
-void vp9_pick_intra_mode(VP9_COMP *cpi, MACROBLOCK *x, RD_COST *rd_cost,
-                         BLOCK_SIZE bsize, PICK_MODE_CONTEXT *ctx) {
-  MACROBLOCKD *const xd = &x->e_mbd;
-  MODE_INFO *const mi = xd->mi[0];
-  RD_COST this_rdc, best_rdc;
-  PREDICTION_MODE this_mode;
-  struct estimate_block_intra_args args = { cpi, x, DC_PRED, 1, 0 };
-  const TX_SIZE intra_tx_size =
-      VPXMIN(max_txsize_lookup[bsize],
-             tx_mode_to_biggest_tx_size[cpi->common.tx_mode]);
-  MODE_INFO *const mic = xd->mi[0];
-  int *bmode_costs;
-  const MODE_INFO *above_mi = xd->above_mi;
-  const MODE_INFO *left_mi = xd->left_mi;
-  const PREDICTION_MODE A = vp9_above_block_mode(mic, above_mi, 0);
-  const PREDICTION_MODE L = vp9_left_block_mode(mic, left_mi, 0);
-  bmode_costs = cpi->y_mode_costs[A][L];
-
-  (void) ctx;
-  vp9_rd_cost_reset(&best_rdc);
-  vp9_rd_cost_reset(&this_rdc);
-
-  mi->ref_frame[0] = INTRA_FRAME;
-  mi->mv[0].as_int = INVALID_MV;
-  mi->uv_mode = DC_PRED;
-  memset(x->skip_txfm, 0, sizeof(x->skip_txfm));
-
-  // Change the limit of this loop to add other intra prediction
-  // mode tests.
-  for (this_mode = DC_PRED; this_mode <= H_PRED; ++this_mode) {
-    this_rdc.dist = this_rdc.rate = 0;
-    args.mode = this_mode;
-    args.skippable = 1;
-    args.rdc = &this_rdc;
-    mi->tx_size = intra_tx_size;
-    vp9_foreach_transformed_block_in_plane(xd, bsize, 0,
-                                           estimate_block_intra, &args);
-    if (args.skippable) {
-      x->skip_txfm[0] = SKIP_TXFM_AC_DC;
-      this_rdc.rate = vp9_cost_bit(vp9_get_skip_prob(&cpi->common, xd), 1);
-    } else {
-      x->skip_txfm[0] = SKIP_TXFM_NONE;
-      this_rdc.rate += vp9_cost_bit(vp9_get_skip_prob(&cpi->common, xd), 0);
-    }
-    this_rdc.rate += bmode_costs[this_mode];
-    this_rdc.rdcost = RDCOST(x->rdmult, x->rddiv,
-                             this_rdc.rate, this_rdc.dist);
-
-    if (this_rdc.rdcost < best_rdc.rdcost) {
-      best_rdc = this_rdc;
-      mi->mode = this_mode;
-    }
-  }
-
-  *rd_cost = best_rdc;
-}
-
-static void init_ref_frame_cost(VP9_COMMON *const cm,
-                                MACROBLOCKD *const xd,
-                                int ref_frame_cost[MAX_REF_FRAMES]) {
-  vpx_prob intra_inter_p = vp9_get_intra_inter_prob(cm, xd);
-  vpx_prob ref_single_p1 = vp9_get_pred_prob_single_ref_p1(cm, xd);
-  vpx_prob ref_single_p2 = vp9_get_pred_prob_single_ref_p2(cm, xd);
-
-  ref_frame_cost[INTRA_FRAME] = vp9_cost_bit(intra_inter_p, 0);
-  ref_frame_cost[LAST_FRAME] = ref_frame_cost[GOLDEN_FRAME] =
-    ref_frame_cost[ALTREF_FRAME] = vp9_cost_bit(intra_inter_p, 1);
-
-  ref_frame_cost[LAST_FRAME] += vp9_cost_bit(ref_single_p1, 0);
-  ref_frame_cost[GOLDEN_FRAME] += vp9_cost_bit(ref_single_p1, 1);
-  ref_frame_cost[ALTREF_FRAME] += vp9_cost_bit(ref_single_p1, 1);
-  ref_frame_cost[GOLDEN_FRAME] += vp9_cost_bit(ref_single_p2, 0);
-  ref_frame_cost[ALTREF_FRAME] += vp9_cost_bit(ref_single_p2, 1);
-}
-
-typedef struct {
-  MV_REFERENCE_FRAME ref_frame;
-  PREDICTION_MODE pred_mode;
-} REF_MODE;
-
-#define RT_INTER_MODES 8
-static const REF_MODE ref_mode_set[RT_INTER_MODES] = {
-    {LAST_FRAME, ZEROMV},
-    {LAST_FRAME, NEARESTMV},
-    {GOLDEN_FRAME, ZEROMV},
-    {LAST_FRAME, NEARMV},
-    {LAST_FRAME, NEWMV},
-    {GOLDEN_FRAME, NEARESTMV},
-    {GOLDEN_FRAME, NEARMV},
-    {GOLDEN_FRAME, NEWMV}
-};
-static const REF_MODE ref_mode_set_svc[RT_INTER_MODES] = {
-    {LAST_FRAME, ZEROMV},
-    {GOLDEN_FRAME, ZEROMV},
-    {LAST_FRAME, NEARESTMV},
-    {LAST_FRAME, NEARMV},
-    {GOLDEN_FRAME, NEARESTMV},
-    {GOLDEN_FRAME, NEARMV},
-    {LAST_FRAME, NEWMV},
-    {GOLDEN_FRAME, NEWMV}
-};
-
-static int set_intra_cost_penalty(const VP9_COMP *const cpi, BLOCK_SIZE bsize) {
-  const VP9_COMMON *const cm = &cpi->common;
-  // Reduce the intra cost penalty for small blocks (<=16x16).
-  int reduction_fac =
-      (bsize <= BLOCK_16X16) ? ((bsize <= BLOCK_8X8) ? 4 : 2) : 0;
-  if (cpi->noise_estimate.enabled && cpi->noise_estimate.level == kHigh)
-     // Don't reduce intra cost penalty if estimated noise level is high.
-     reduction_fac = 0;
-  return vp9_get_intra_cost_penalty(
-      cm->base_qindex, cm->y_dc_delta_q, cm->bit_depth) >> reduction_fac;
-}
-
-static INLINE void find_predictors(VP9_COMP *cpi, MACROBLOCK *x,
-                                 MV_REFERENCE_FRAME ref_frame,
-                                 int_mv frame_mv[MB_MODE_COUNT][MAX_REF_FRAMES],
-                                 int const_motion[MAX_REF_FRAMES],
-                                 int *ref_frame_skip_mask,
-                                 const int flag_list[4],
-                                 TileDataEnc *tile_data,
-                                 int mi_row, int mi_col,
-                                 struct buf_2d yv12_mb[4][MAX_MB_PLANE],
-                                 BLOCK_SIZE bsize,
-                                 int force_skip_low_temp_var) {
-  VP9_COMMON *const cm = &cpi->common;
-  MACROBLOCKD *const xd = &x->e_mbd;
-  const YV12_BUFFER_CONFIG *yv12 = get_ref_frame_buffer(cpi, ref_frame);
-  TileInfo *const tile_info = &tile_data->tile_info;
-  // TODO(jingning) placeholder for inter-frame non-RD mode decision.
-  x->pred_mv_sad[ref_frame] = INT_MAX;
-  frame_mv[NEWMV][ref_frame].as_int = INVALID_MV;
-  frame_mv[ZEROMV][ref_frame].as_int = 0;
-  // this needs various further optimizations. to be continued..
-  if ((cpi->ref_frame_flags & flag_list[ref_frame]) && (yv12 != NULL)) {
-    int_mv *const candidates = x->mbmi_ext->ref_mvs[ref_frame];
-    const struct scale_factors *const sf = &cm->frame_refs[ref_frame - 1].sf;
-    vp9_setup_pred_block(xd, yv12_mb[ref_frame], yv12, mi_row, mi_col,
-                         sf, sf);
-    if (cm->use_prev_frame_mvs) {
-      vp9_find_mv_refs(cm, xd, xd->mi[0], ref_frame,
-                       candidates, mi_row, mi_col,
-                       x->mbmi_ext->mode_context);
-    } else {
-      const_motion[ref_frame] =
-          mv_refs_rt(cpi, cm, x, xd, tile_info, xd->mi[0], ref_frame,
-                     candidates, &frame_mv[NEWMV][ref_frame], mi_row, mi_col,
-                     (int)(cpi->svc.use_base_mv && cpi->svc.spatial_layer_id));
-    }
-    vp9_find_best_ref_mvs(xd, cm->allow_high_precision_mv, candidates,
-                          &frame_mv[NEARESTMV][ref_frame],
-                          &frame_mv[NEARMV][ref_frame]);
-    // Early exit for golden frame if force_skip_low_temp_var is set.
-    if (!vp9_is_scaled(sf) && bsize >= BLOCK_8X8 &&
-        !(force_skip_low_temp_var && ref_frame == GOLDEN_FRAME)) {
-      vp9_mv_pred(cpi, x, yv12_mb[ref_frame][0].buf, yv12->y_stride,
-                  ref_frame, bsize);
-    }
-  } else {
-    *ref_frame_skip_mask |= (1 << ref_frame);
-  }
-}
-
-static void vp9_large_block_mv_bias(const NOISE_ESTIMATE *ne, RD_COST *this_rdc,
-                                    BLOCK_SIZE bsize, int mv_row, int mv_col,
-                                    int is_last_frame) {
-  // Bias against non-zero (above some threshold) motion for large blocks.
-  // This is temporary fix to avoid selection of large mv for big blocks.
-  if (mv_row > 64 || mv_row < -64 || mv_col > 64 || mv_col < -64) {
-    if (bsize == BLOCK_64X64)
-      this_rdc->rdcost = this_rdc->rdcost << 1;
-    else if (bsize >= BLOCK_32X32)
-      this_rdc->rdcost = 3 * this_rdc->rdcost >> 1;
-  }
-  // If noise estimation is enabled, and estimated level is above threshold,
-  // add a bias to LAST reference with small motion, for large blocks.
-  if (ne->enabled && ne->level >= kMedium &&
-      bsize >= BLOCK_32X32 && is_last_frame &&
-      mv_row < 8 && mv_row > -8 && mv_col < 8 && mv_col > -8) {
-    this_rdc->rdcost = 7 * this_rdc->rdcost >> 3;
-  }
-}
-
-#if CONFIG_VP9_TEMPORAL_DENOISING
-static void vp9_pickmode_ctx_den_update(
-    VP9_PICKMODE_CTX_DEN *ctx_den,
-    int64_t zero_last_cost_orig,
-    int ref_frame_cost[MAX_REF_FRAMES],
-    int_mv frame_mv[MB_MODE_COUNT][MAX_REF_FRAMES],
-    int reuse_inter_pred,
-    TX_SIZE best_tx_size,
-    PREDICTION_MODE best_mode,
-    MV_REFERENCE_FRAME best_ref_frame,
-    INTERP_FILTER best_pred_filter,
-    uint8_t best_mode_skip_txfm) {
-  ctx_den->zero_last_cost_orig = zero_last_cost_orig;
-  ctx_den->ref_frame_cost = ref_frame_cost;
-  ctx_den->frame_mv = frame_mv;
-  ctx_den->reuse_inter_pred = reuse_inter_pred;
-  ctx_den->best_tx_size = best_tx_size;
-  ctx_den->best_mode = best_mode;
-  ctx_den->best_ref_frame = best_ref_frame;
-  ctx_den->best_pred_filter = best_pred_filter;
-  ctx_den->best_mode_skip_txfm = best_mode_skip_txfm;
-}
-
-static void recheck_zeromv_after_denoising(
-    VP9_COMP *cpi, MODE_INFO *const mi, MACROBLOCK *x, MACROBLOCKD *const xd,
-    VP9_DENOISER_DECISION decision, VP9_PICKMODE_CTX_DEN *ctx_den,
-    struct buf_2d yv12_mb[4][MAX_MB_PLANE], RD_COST *best_rdc, BLOCK_SIZE bsize,
-    int mi_row, int mi_col) {
-  // If INTRA or GOLDEN reference was selected, re-evaluate ZEROMV on
-  // denoised result. Only do this under noise conditions, and if rdcost of
-  // ZEROMV onoriginal source is not significantly higher than rdcost of best
-  // mode.
-  if (cpi->noise_estimate.enabled &&
-      cpi->noise_estimate.level > kLow &&
-      ctx_den->zero_last_cost_orig < (best_rdc->rdcost << 3) &&
-      ((ctx_den->best_ref_frame == INTRA_FRAME && decision >= FILTER_BLOCK) ||
-       (ctx_den->best_ref_frame == GOLDEN_FRAME &&
-        decision == FILTER_ZEROMV_BLOCK))) {
-    // Check if we should pick ZEROMV on denoised signal.
-    int rate = 0;
-    int64_t dist = 0;
-    uint32_t var_y = UINT_MAX;
-    uint32_t sse_y = UINT_MAX;
-    RD_COST this_rdc;
-    mi->mode = ZEROMV;
-    mi->ref_frame[0] = LAST_FRAME;
-    mi->ref_frame[1] = NONE;
-    mi->mv[0].as_int = 0;
-    mi->interp_filter = EIGHTTAP;
-    xd->plane[0].pre[0] = yv12_mb[LAST_FRAME][0];
-    vp9_build_inter_predictors_sby(xd, mi_row, mi_col, bsize);
-    model_rd_for_sb_y(cpi, bsize, x, xd, &rate, &dist, &var_y, &sse_y);
-    this_rdc.rate = rate + ctx_den->ref_frame_cost[LAST_FRAME] +
-        cpi->inter_mode_cost[x->mbmi_ext->mode_context[LAST_FRAME]]
-                            [INTER_OFFSET(ZEROMV)];
-    this_rdc.dist = dist;
-    this_rdc.rdcost = RDCOST(x->rdmult, x->rddiv, rate, dist);
-    // Switch to ZEROMV if the rdcost for ZEROMV on denoised source
-    // is lower than best_ref mode (on original source).
-    if (this_rdc.rdcost > best_rdc->rdcost) {
-      this_rdc = *best_rdc;
-      mi->mode = ctx_den->best_mode;
-      mi->ref_frame[0] = ctx_den->best_ref_frame;
-      mi->interp_filter = ctx_den->best_pred_filter;
-      if (ctx_den->best_ref_frame == INTRA_FRAME)
-        mi->mv[0].as_int = INVALID_MV;
-      else if (ctx_den->best_ref_frame == GOLDEN_FRAME) {
-        mi->mv[0].as_int = ctx_den->frame_mv[ctx_den->best_mode]
-                                            [ctx_den->best_ref_frame].as_int;
-        if (ctx_den->reuse_inter_pred) {
-          xd->plane[0].pre[0] = yv12_mb[GOLDEN_FRAME][0];
-          vp9_build_inter_predictors_sby(xd, mi_row, mi_col, bsize);
-        }
-      }
-      mi->tx_size = ctx_den->best_tx_size;
-      x->skip_txfm[0] = ctx_den->best_mode_skip_txfm;
-    } else {
-      ctx_den->best_ref_frame = LAST_FRAME;
-      *best_rdc = this_rdc;
-    }
-  }
-}
-#endif  // CONFIG_VP9_TEMPORAL_DENOISING
-
-static INLINE int get_force_skip_low_temp_var(uint8_t *variance_low,
-                                              int mi_row, int mi_col,
-                                              BLOCK_SIZE bsize) {
-  const int i = (mi_row & 0x7) >> 1;
-  const int j = (mi_col & 0x7) >> 1;
-  int force_skip_low_temp_var = 0;
-  // Set force_skip_low_temp_var based on the block size and block offset.
-  if (bsize == BLOCK_64X64) {
-    force_skip_low_temp_var = variance_low[0];
-  } else if (bsize == BLOCK_64X32) {
-    if (!(mi_col & 0x7) && !(mi_row & 0x7)) {
-      force_skip_low_temp_var = variance_low[1];
-    } else if (!(mi_col & 0x7) && (mi_row & 0x7)) {
-      force_skip_low_temp_var = variance_low[2];
-    }
-  } else if (bsize == BLOCK_32X64) {
-    if (!(mi_col & 0x7) && !(mi_row & 0x7)) {
-      force_skip_low_temp_var = variance_low[3];
-    } else if ((mi_col & 0x7) && !(mi_row & 0x7)) {
-      force_skip_low_temp_var = variance_low[4];
-    }
-  } else if (bsize == BLOCK_32X32) {
-    if (!(mi_col & 0x7) && !(mi_row & 0x7)) {
-      force_skip_low_temp_var = variance_low[5];
-    } else if ((mi_col & 0x7) && !(mi_row & 0x7)) {
-      force_skip_low_temp_var = variance_low[6];
-    } else if (!(mi_col & 0x7) && (mi_row & 0x7)) {
-      force_skip_low_temp_var = variance_low[7];
-    } else if ((mi_col & 0x7) && (mi_row & 0x7)) {
-      force_skip_low_temp_var = variance_low[8];
-    }
-  } else if (bsize == BLOCK_16X16) {
-    force_skip_low_temp_var = variance_low[pos_shift_16x16[i][j]];
-  } else if (bsize == BLOCK_32X16) {
-    // The col shift index for the second 16x16 block.
-    const int j2 = ((mi_col + 2) & 0x7) >> 1;
-    // Only if each 16x16 block inside has low temporal variance.
-    force_skip_low_temp_var = variance_low[pos_shift_16x16[i][j]] &&
-                              variance_low[pos_shift_16x16[i][j2]];
-  } else if (bsize == BLOCK_16X32) {
-    // The row shift index for the second 16x16 block.
-    const int i2 = ((mi_row + 2) & 0x7) >> 1;
-    force_skip_low_temp_var = variance_low[pos_shift_16x16[i][j]] &&
-                              variance_low[pos_shift_16x16[i2][j]];
-  }
-  return force_skip_low_temp_var;
-}
-
-void vp9_pick_inter_mode(VP9_COMP *cpi, MACROBLOCK *x,
-                         TileDataEnc *tile_data,
-                         int mi_row, int mi_col, RD_COST *rd_cost,
-                         BLOCK_SIZE bsize, PICK_MODE_CONTEXT *ctx) {
-  VP9_COMMON *const cm = &cpi->common;
-  SPEED_FEATURES *const sf = &cpi->sf;
-  const SVC *const svc = &cpi->svc;
-  MACROBLOCKD *const xd = &x->e_mbd;
-  MODE_INFO *const mi = xd->mi[0];
-  struct macroblockd_plane *const pd = &xd->plane[0];
-  PREDICTION_MODE best_mode = ZEROMV;
-  MV_REFERENCE_FRAME ref_frame, best_ref_frame = LAST_FRAME;
-  MV_REFERENCE_FRAME usable_ref_frame;
-  TX_SIZE best_tx_size = TX_SIZES;
-  INTERP_FILTER best_pred_filter = EIGHTTAP;
-  int_mv frame_mv[MB_MODE_COUNT][MAX_REF_FRAMES];
-  struct buf_2d yv12_mb[4][MAX_MB_PLANE];
-  static const int flag_list[4] = { 0, VP9_LAST_FLAG, VP9_GOLD_FLAG,
-                                    VP9_ALT_FLAG };
-  RD_COST this_rdc, best_rdc;
-  uint8_t skip_txfm = SKIP_TXFM_NONE, best_mode_skip_txfm = SKIP_TXFM_NONE;
-  // var_y and sse_y are saved to be used in skipping checking
-  unsigned int var_y = UINT_MAX;
-  unsigned int sse_y = UINT_MAX;
-  const int intra_cost_penalty = set_intra_cost_penalty(cpi, bsize);
-  int64_t inter_mode_thresh = RDCOST(x->rdmult, x->rddiv,
-                                           intra_cost_penalty, 0);
-  const int *const rd_threshes = cpi->rd.threshes[mi->segment_id][bsize];
-  const int *const rd_thresh_freq_fact = tile_data->thresh_freq_fact[bsize];
-  INTERP_FILTER filter_ref;
-  const int bsl = mi_width_log2_lookup[bsize];
-  const int pred_filter_search = cm->interp_filter == SWITCHABLE ?
-      (((mi_row + mi_col) >> bsl) +
-       get_chessboard_index(cm->current_video_frame)) & 0x1 : 0;
-  int const_motion[MAX_REF_FRAMES] = { 0 };
-  const int bh = num_4x4_blocks_high_lookup[bsize] << 2;
-  const int bw = num_4x4_blocks_wide_lookup[bsize] << 2;
-  // For speed 6, the result of interp filter is reused later in actual encoding
-  // process.
-  // tmp[3] points to dst buffer, and the other 3 point to allocated buffers.
-  PRED_BUFFER tmp[4];
-  DECLARE_ALIGNED(16, uint8_t, pred_buf[3 * 64 * 64]);
-#if CONFIG_VP9_HIGHBITDEPTH
-  DECLARE_ALIGNED(16, uint16_t, pred_buf_16[3 * 64 * 64]);
-#endif
-  struct buf_2d orig_dst = pd->dst;
-  PRED_BUFFER *best_pred = NULL;
-  PRED_BUFFER *this_mode_pred = NULL;
-  const int pixels_in_block = bh * bw;
-  int reuse_inter_pred = cpi->sf.reuse_inter_pred_sby && ctx->pred_pixel_ready;
-  int ref_frame_skip_mask = 0;
-  int idx;
-  int best_pred_sad = INT_MAX;
-  int best_early_term = 0;
-  int ref_frame_cost[MAX_REF_FRAMES];
-  int svc_force_zero_mode[3] = {0};
-  int perform_intra_pred = 1;
-  int use_golden_nonzeromv = 1;
-  int force_skip_low_temp_var = 0;
-#if CONFIG_VP9_TEMPORAL_DENOISING
-  VP9_PICKMODE_CTX_DEN ctx_den;
-  int64_t zero_last_cost_orig = INT64_MAX;
-#endif
-
-  init_ref_frame_cost(cm, xd, ref_frame_cost);
-
-  if (reuse_inter_pred) {
-    int i;
-    for (i = 0; i < 3; i++) {
-#if CONFIG_VP9_HIGHBITDEPTH
-      if (cm->use_highbitdepth)
-        tmp[i].data = CONVERT_TO_BYTEPTR(&pred_buf_16[pixels_in_block * i]);
-      else
-        tmp[i].data = &pred_buf[pixels_in_block * i];
-#else
-      tmp[i].data = &pred_buf[pixels_in_block * i];
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-      tmp[i].stride = bw;
-      tmp[i].in_use = 0;
-    }
-    tmp[3].data = pd->dst.buf;
-    tmp[3].stride = pd->dst.stride;
-    tmp[3].in_use = 0;
-  }
-
-  x->skip_encode = cpi->sf.skip_encode_frame && x->q_index < QIDX_SKIP_THRESH;
-  x->skip = 0;
-
-  if (xd->above_mi)
-    filter_ref = xd->above_mi->interp_filter;
-  else if (xd->left_mi)
-    filter_ref = xd->left_mi->interp_filter;
-  else
-    filter_ref = cm->interp_filter;
-
-  // initialize mode decisions
-  vp9_rd_cost_reset(&best_rdc);
-  vp9_rd_cost_reset(rd_cost);
-  mi->sb_type = bsize;
-  mi->ref_frame[0] = NONE;
-  mi->ref_frame[1] = NONE;
-  mi->tx_size = VPXMIN(max_txsize_lookup[bsize],
-                       tx_mode_to_biggest_tx_size[cm->tx_mode]);
-
-  if (sf->short_circuit_flat_blocks) {
-#if CONFIG_VP9_HIGHBITDEPTH
-    if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH)
-      x->source_variance = vp9_high_get_sby_perpixel_variance(
-          cpi, &x->plane[0].src, bsize, xd->bd);
-    else
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-      x->source_variance =
-          vp9_get_sby_perpixel_variance(cpi, &x->plane[0].src, bsize);
-  }
-
-#if CONFIG_VP9_TEMPORAL_DENOISING
-  if (cpi->oxcf.noise_sensitivity > 0 &&
-      cpi->denoiser.denoising_level > kDenLowLow) {
-    vp9_denoiser_reset_frame_stats(ctx);
-  }
-#endif
-
-  if (cpi->rc.frames_since_golden == 0 && !cpi->use_svc) {
-    usable_ref_frame = LAST_FRAME;
-  } else {
-    usable_ref_frame = GOLDEN_FRAME;
-  }
-
-  // For svc mode, on spatial_layer_id > 0: if the reference has different scale
-  // constrain the inter mode to only test zero motion.
-  if (cpi->use_svc &&
-      svc ->force_zero_mode_spatial_ref &&
-      cpi->svc.spatial_layer_id > 0) {
-    if (cpi->ref_frame_flags & flag_list[LAST_FRAME]) {
-      struct scale_factors *const sf = &cm->frame_refs[LAST_FRAME - 1].sf;
-      if (vp9_is_scaled(sf))
-        svc_force_zero_mode[LAST_FRAME - 1] = 1;
-    }
-    if (cpi->ref_frame_flags & flag_list[GOLDEN_FRAME]) {
-      struct scale_factors *const sf = &cm->frame_refs[GOLDEN_FRAME - 1].sf;
-      if (vp9_is_scaled(sf))
-        svc_force_zero_mode[GOLDEN_FRAME - 1] = 1;
-    }
-  }
-
-  if (cpi->sf.short_circuit_low_temp_var) {
-    force_skip_low_temp_var =
-        get_force_skip_low_temp_var(&x->variance_low[0], mi_row, mi_col, bsize);
-  }
-
-  if (!((cpi->ref_frame_flags & flag_list[GOLDEN_FRAME]) &&
-      !svc_force_zero_mode[GOLDEN_FRAME - 1] && !force_skip_low_temp_var))
-    use_golden_nonzeromv = 0;
-
-  for (ref_frame = LAST_FRAME; ref_frame <= usable_ref_frame; ++ref_frame) {
-    find_predictors(cpi, x, ref_frame, frame_mv, const_motion,
-                    &ref_frame_skip_mask, flag_list, tile_data, mi_row, mi_col,
-                    yv12_mb, bsize, force_skip_low_temp_var);
-  }
-
-  for (idx = 0; idx < RT_INTER_MODES; ++idx) {
-    int rate_mv = 0;
-    int mode_rd_thresh;
-    int mode_index;
-    int i;
-    int64_t this_sse;
-    int is_skippable;
-    int this_early_term = 0;
-    PREDICTION_MODE this_mode = ref_mode_set[idx].pred_mode;
-
-    if (cpi->use_svc)
-      this_mode = ref_mode_set_svc[idx].pred_mode;
-
-    if (sf->short_circuit_flat_blocks && x->source_variance == 0 &&
-        this_mode != NEARESTMV) {
-      continue;
-    }
-
-    if (!(cpi->sf.inter_mode_mask[bsize] & (1 << this_mode)))
-      continue;
-
-    ref_frame = ref_mode_set[idx].ref_frame;
-    if (cpi->use_svc) {
-      ref_frame = ref_mode_set_svc[idx].ref_frame;
-    }
-
-    if (!(cpi->ref_frame_flags & flag_list[ref_frame]))
-      continue;
-
-    if (const_motion[ref_frame] && this_mode == NEARMV)
-      continue;
-
-    // Skip non-zeromv mode search for golden frame if force_skip_low_temp_var
-    // is set. If nearestmv for golden frame is 0, zeromv mode will be skipped
-    // later.
-    if (force_skip_low_temp_var && ref_frame == GOLDEN_FRAME &&
-        frame_mv[this_mode][ref_frame].as_int != 0) {
-      continue;
-    }
-
-    if (cpi->sf.short_circuit_low_temp_var == 2 &&
-        force_skip_low_temp_var && ref_frame == LAST_FRAME &&
-        this_mode == NEWMV) {
-      continue;
-    }
-
-    if (cpi->use_svc) {
-      if (svc_force_zero_mode[ref_frame - 1] &&
-          frame_mv[this_mode][ref_frame].as_int != 0)
-        continue;
-    }
-
-    if (!force_skip_low_temp_var &&
-        !(frame_mv[this_mode][ref_frame].as_int == 0 &&
-          ref_frame == LAST_FRAME)) {
-      i = (ref_frame == LAST_FRAME) ? GOLDEN_FRAME : LAST_FRAME;
-      if ((cpi->ref_frame_flags & flag_list[i]) && sf->reference_masking)
-        if (x->pred_mv_sad[ref_frame] > (x->pred_mv_sad[i] << 1))
-          ref_frame_skip_mask |= (1 << ref_frame);
-    }
-    if (ref_frame_skip_mask & (1 << ref_frame))
-      continue;
-
-    // Select prediction reference frames.
-    for (i = 0; i < MAX_MB_PLANE; i++)
-      xd->plane[i].pre[0] = yv12_mb[ref_frame][i];
-
-    mi->ref_frame[0] = ref_frame;
-    set_ref_ptrs(cm, xd, ref_frame, NONE);
-
-    mode_index = mode_idx[ref_frame][INTER_OFFSET(this_mode)];
-    mode_rd_thresh = best_mode_skip_txfm ?
-            rd_threshes[mode_index] << 1 : rd_threshes[mode_index];
-    if (rd_less_than_thresh(best_rdc.rdcost, mode_rd_thresh,
-                            rd_thresh_freq_fact[mode_index]))
-      continue;
-
-    if (this_mode == NEWMV) {
-      if (ref_frame > LAST_FRAME &&
-          !cpi->use_svc &&
-          cpi->oxcf.rc_mode == VPX_CBR) {
-        int tmp_sad;
-        uint32_t dis;
-        int cost_list[5];
-
-        if (bsize < BLOCK_16X16)
-          continue;
-
-        tmp_sad = vp9_int_pro_motion_estimation(cpi, x, bsize, mi_row, mi_col);
-
-        if (tmp_sad > x->pred_mv_sad[LAST_FRAME])
-          continue;
-        if (tmp_sad + (num_pels_log2_lookup[bsize] << 4) > best_pred_sad)
-          continue;
-
-        frame_mv[NEWMV][ref_frame].as_int = mi->mv[0].as_int;
-        rate_mv = vp9_mv_bit_cost(&frame_mv[NEWMV][ref_frame].as_mv,
-          &x->mbmi_ext->ref_mvs[ref_frame][0].as_mv,
-          x->nmvjointcost, x->mvcost, MV_COST_WEIGHT);
-        frame_mv[NEWMV][ref_frame].as_mv.row >>= 3;
-        frame_mv[NEWMV][ref_frame].as_mv.col >>= 3;
-
-        cpi->find_fractional_mv_step(x, &frame_mv[NEWMV][ref_frame].as_mv,
-          &x->mbmi_ext->ref_mvs[ref_frame][0].as_mv,
-          cpi->common.allow_high_precision_mv,
-          x->errorperbit,
-          &cpi->fn_ptr[bsize],
-          cpi->sf.mv.subpel_force_stop,
-          cpi->sf.mv.subpel_iters_per_step,
-          cond_cost_list(cpi, cost_list),
-          x->nmvjointcost, x->mvcost, &dis,
-          &x->pred_sse[ref_frame], NULL, 0, 0);
-      } else if (svc->use_base_mv && svc->spatial_layer_id) {
-        if (frame_mv[NEWMV][ref_frame].as_int != INVALID_MV &&
-            frame_mv[NEWMV][ref_frame].as_int != 0) {
-          const int pre_stride = xd->plane[0].pre[0].stride;
-          int base_mv_sad = INT_MAX;
-          const uint8_t * const pre_buf = xd->plane[0].pre[0].buf +
-              (frame_mv[NEWMV][ref_frame].as_mv.row >> 3) * pre_stride +
-              (frame_mv[NEWMV][ref_frame].as_mv.col >> 3);
-          base_mv_sad = cpi->fn_ptr[bsize].sdf(x->plane[0].src.buf,
-                                       x->plane[0].src.stride,
-                                       pre_buf, pre_stride);
-
-          // TODO(wonkap): make the decision to use base layer mv on RD;
-          // not just SAD.
-          if (base_mv_sad < x->pred_mv_sad[ref_frame]) {
-            // Base layer mv is good.
-            if (!combined_motion_search(cpi, x, bsize, mi_row, mi_col,
-                &frame_mv[NEWMV][ref_frame], &rate_mv, best_rdc.rdcost, 1)) {
-                continue;
-            }
-          } else if (!combined_motion_search(cpi, x, bsize, mi_row, mi_col,
-            &frame_mv[NEWMV][ref_frame], &rate_mv, best_rdc.rdcost, 0)) {
-            continue;
-          }
-        } else if (!combined_motion_search(cpi, x, bsize, mi_row, mi_col,
-          &frame_mv[NEWMV][ref_frame], &rate_mv, best_rdc.rdcost, 0)) {
-          continue;
-        }
-      } else if (!combined_motion_search(cpi, x, bsize, mi_row, mi_col,
-        &frame_mv[NEWMV][ref_frame], &rate_mv, best_rdc.rdcost, 0)) {
-        continue;
-      }
-    }
-
-    // If use_golden_nonzeromv is false, NEWMV mode is skipped for golden, no
-    // need to compute best_pred_sad which is only used to skip golden NEWMV.
-    if (use_golden_nonzeromv && this_mode == NEWMV &&
-        ref_frame == LAST_FRAME &&
-        frame_mv[NEWMV][LAST_FRAME].as_int != INVALID_MV) {
-      const int pre_stride = xd->plane[0].pre[0].stride;
-      const uint8_t * const pre_buf = xd->plane[0].pre[0].buf +
-          (frame_mv[NEWMV][LAST_FRAME].as_mv.row >> 3) * pre_stride +
-          (frame_mv[NEWMV][LAST_FRAME].as_mv.col >> 3);
-      best_pred_sad = cpi->fn_ptr[bsize].sdf(x->plane[0].src.buf,
-                                   x->plane[0].src.stride,
-                                   pre_buf, pre_stride);
-      x->pred_mv_sad[LAST_FRAME] = best_pred_sad;
-    }
-
-    if (this_mode != NEARESTMV &&
-        frame_mv[this_mode][ref_frame].as_int ==
-            frame_mv[NEARESTMV][ref_frame].as_int)
-      continue;
-
-    mi->mode = this_mode;
-    mi->mv[0].as_int = frame_mv[this_mode][ref_frame].as_int;
-
-    // Search for the best prediction filter type, when the resulting
-    // motion vector is at sub-pixel accuracy level for luma component, i.e.,
-    // the last three bits are all zeros.
-    if (reuse_inter_pred) {
-      if (!this_mode_pred) {
-        this_mode_pred = &tmp[3];
-      } else {
-        this_mode_pred = &tmp[get_pred_buffer(tmp, 3)];
-        pd->dst.buf = this_mode_pred->data;
-        pd->dst.stride = bw;
-      }
-    }
-
-    if ((this_mode == NEWMV || filter_ref == SWITCHABLE) && pred_filter_search
-        && (ref_frame == LAST_FRAME ||
-           (ref_frame == GOLDEN_FRAME &&
-           (cpi->use_svc || cpi->oxcf.rc_mode == VPX_VBR))) &&
-           (((mi->mv[0].as_mv.row | mi->mv[0].as_mv.col) & 0x07) != 0)) {
-      int pf_rate[3];
-      int64_t pf_dist[3];
-      unsigned int pf_var[3];
-      unsigned int pf_sse[3];
-      TX_SIZE pf_tx_size[3];
-      int64_t best_cost = INT64_MAX;
-      INTERP_FILTER best_filter = SWITCHABLE, filter;
-      PRED_BUFFER *current_pred = this_mode_pred;
-
-      for (filter = EIGHTTAP; filter <= EIGHTTAP_SMOOTH; ++filter) {
-        int64_t cost;
-        mi->interp_filter = filter;
-        vp9_build_inter_predictors_sby(xd, mi_row, mi_col, bsize);
-        model_rd_for_sb_y(cpi, bsize, x, xd, &pf_rate[filter], &pf_dist[filter],
-                          &pf_var[filter], &pf_sse[filter]);
-        pf_rate[filter] += vp9_get_switchable_rate(cpi, xd);
-        cost = RDCOST(x->rdmult, x->rddiv, pf_rate[filter], pf_dist[filter]);
-        pf_tx_size[filter] = mi->tx_size;
-        if (cost < best_cost) {
-          best_filter = filter;
-          best_cost = cost;
-          skip_txfm = x->skip_txfm[0];
-
-          if (reuse_inter_pred) {
-            if (this_mode_pred != current_pred) {
-              free_pred_buffer(this_mode_pred);
-              this_mode_pred = current_pred;
-            }
-            current_pred = &tmp[get_pred_buffer(tmp, 3)];
-            pd->dst.buf = current_pred->data;
-            pd->dst.stride = bw;
-          }
-        }
-      }
-
-      if (reuse_inter_pred && this_mode_pred != current_pred)
-        free_pred_buffer(current_pred);
-
-      mi->interp_filter = best_filter;
-      mi->tx_size = pf_tx_size[best_filter];
-      this_rdc.rate = pf_rate[best_filter];
-      this_rdc.dist = pf_dist[best_filter];
-      var_y = pf_var[best_filter];
-      sse_y = pf_sse[best_filter];
-      x->skip_txfm[0] = skip_txfm;
-      if (reuse_inter_pred) {
-        pd->dst.buf = this_mode_pred->data;
-        pd->dst.stride = this_mode_pred->stride;
-      }
-    } else {
-      mi->interp_filter = (filter_ref == SWITCHABLE) ? EIGHTTAP : filter_ref;
-      vp9_build_inter_predictors_sby(xd, mi_row, mi_col, bsize);
-
-      // For large partition blocks, extra testing is done.
-      if (cpi->oxcf.rc_mode == VPX_CBR && bsize > BLOCK_32X32 &&
-        !cyclic_refresh_segment_id_boosted(xd->mi[0]->segment_id) &&
-        cm->base_qindex) {
-        model_rd_for_sb_y_large(cpi, bsize, x, xd, &this_rdc.rate,
-                                &this_rdc.dist, &var_y, &sse_y, mi_row, mi_col,
-                                &this_early_term);
-      } else {
-        model_rd_for_sb_y(cpi, bsize, x, xd, &this_rdc.rate, &this_rdc.dist,
-                          &var_y, &sse_y);
-      }
-    }
-
-    if (!this_early_term) {
-      this_sse = (int64_t)sse_y;
-      block_yrd(cpi, x, &this_rdc, &is_skippable, &this_sse, bsize,
-                VPXMIN(mi->tx_size, TX_16X16));
-      x->skip_txfm[0] = is_skippable;
-      if (is_skippable) {
-        this_rdc.rate = vp9_cost_bit(vp9_get_skip_prob(cm, xd), 1);
-      } else {
-        if (RDCOST(x->rdmult, x->rddiv, this_rdc.rate, this_rdc.dist) <
-            RDCOST(x->rdmult, x->rddiv, 0, this_sse)) {
-          this_rdc.rate += vp9_cost_bit(vp9_get_skip_prob(cm, xd), 0);
-        } else {
-          this_rdc.rate = vp9_cost_bit(vp9_get_skip_prob(cm, xd), 1);
-          this_rdc.dist = this_sse;
-          x->skip_txfm[0] = SKIP_TXFM_AC_DC;
-        }
-      }
-
-      if (cm->interp_filter == SWITCHABLE) {
-        if ((mi->mv[0].as_mv.row | mi->mv[0].as_mv.col) & 0x07)
-          this_rdc.rate += vp9_get_switchable_rate(cpi, xd);
-      }
-    } else {
-      this_rdc.rate += cm->interp_filter == SWITCHABLE ?
-          vp9_get_switchable_rate(cpi, xd) : 0;
-      this_rdc.rate += vp9_cost_bit(vp9_get_skip_prob(cm, xd), 1);
-    }
-
-    if (x->color_sensitivity[0] || x->color_sensitivity[1]) {
-      RD_COST rdc_uv;
-      const BLOCK_SIZE uv_bsize = get_plane_block_size(bsize, &xd->plane[1]);
-      if (x->color_sensitivity[0])
-        vp9_build_inter_predictors_sbp(xd, mi_row, mi_col, bsize, 1);
-      if (x->color_sensitivity[1])
-        vp9_build_inter_predictors_sbp(xd, mi_row, mi_col, bsize, 2);
-      model_rd_for_sb_uv(cpi, uv_bsize, x, xd, &rdc_uv, &var_y, &sse_y, 1, 2);
-      this_rdc.rate += rdc_uv.rate;
-      this_rdc.dist += rdc_uv.dist;
-    }
-
-    this_rdc.rate += rate_mv;
-    this_rdc.rate +=
-        cpi->inter_mode_cost[x->mbmi_ext->mode_context[ref_frame]][INTER_OFFSET(
-            this_mode)];
-    this_rdc.rate += ref_frame_cost[ref_frame];
-    this_rdc.rdcost = RDCOST(x->rdmult, x->rddiv, this_rdc.rate, this_rdc.dist);
-
-    // Bias against non-zero motion
-    if (cpi->oxcf.rc_mode == VPX_CBR &&
-        cpi->oxcf.speed >= 5 &&
-        cpi->oxcf.content != VP9E_CONTENT_SCREEN &&
-        !x->sb_is_skin) {
-      vp9_large_block_mv_bias(&cpi->noise_estimate, &this_rdc, bsize,
-                              frame_mv[this_mode][ref_frame].as_mv.row,
-                              frame_mv[this_mode][ref_frame].as_mv.col,
-                              ref_frame == LAST_FRAME);
-    }
-
-    // Skipping checking: test to see if this block can be reconstructed by
-    // prediction only.
-    if (cpi->allow_encode_breakout) {
-      encode_breakout_test(cpi, x, bsize, mi_row, mi_col, ref_frame, this_mode,
-                           var_y, sse_y, yv12_mb, &this_rdc.rate,
-                           &this_rdc.dist);
-      if (x->skip) {
-        this_rdc.rate += rate_mv;
-        this_rdc.rdcost = RDCOST(x->rdmult, x->rddiv, this_rdc.rate,
-                                 this_rdc.dist);
-      }
-    }
-
-#if CONFIG_VP9_TEMPORAL_DENOISING
-    if (cpi->oxcf.noise_sensitivity > 0 &&
-        cpi->denoiser.denoising_level > kDenLowLow) {
-      vp9_denoiser_update_frame_stats(mi, sse_y, this_mode, ctx);
-      // Keep track of zero_last cost.
-      if (ref_frame == LAST_FRAME && frame_mv[this_mode][ref_frame].as_int == 0)
-        zero_last_cost_orig = this_rdc.rdcost;
-    }
-#else
-    (void)ctx;
-#endif
-
-    if (this_rdc.rdcost < best_rdc.rdcost || x->skip) {
-      best_rdc = this_rdc;
-      best_mode = this_mode;
-      best_pred_filter = mi->interp_filter;
-      best_tx_size = mi->tx_size;
-      best_ref_frame = ref_frame;
-      best_mode_skip_txfm = x->skip_txfm[0];
-      best_early_term = this_early_term;
-
-      if (reuse_inter_pred) {
-        free_pred_buffer(best_pred);
-        best_pred = this_mode_pred;
-      }
-    } else {
-      if (reuse_inter_pred)
-        free_pred_buffer(this_mode_pred);
-    }
-
-    if (x->skip)
-      break;
-
-    // If early termination flag is 1 and at least 2 modes are checked,
-    // the mode search is terminated.
-    if (best_early_term && idx > 0) {
-      x->skip = 1;
-      break;
-    }
-  }
-
-  mi->mode          = best_mode;
-  mi->interp_filter = best_pred_filter;
-  mi->tx_size       = best_tx_size;
-  mi->ref_frame[0]  = best_ref_frame;
-  mi->mv[0].as_int  = frame_mv[best_mode][best_ref_frame].as_int;
-  xd->mi[0]->bmi[0].as_mv[0].as_int = mi->mv[0].as_int;
-  x->skip_txfm[0] = best_mode_skip_txfm;
-
-  // For spatial enhancemanent layer: perform intra prediction only if base
-  // layer is chosen as the reference. Always perform intra prediction if
-  // LAST is the only reference or is_key_frame is set.
-  if (cpi->svc.spatial_layer_id) {
-    perform_intra_pred =
-        cpi->svc.layer_context[cpi->svc.temporal_layer_id].is_key_frame ||
-        !(cpi->ref_frame_flags & flag_list[GOLDEN_FRAME])  ||
-        (!cpi->svc.layer_context[cpi->svc.temporal_layer_id].is_key_frame
-            && svc_force_zero_mode[best_ref_frame - 1]);
-    inter_mode_thresh = (inter_mode_thresh << 1) + inter_mode_thresh;
-  }
-  // Perform intra prediction search, if the best SAD is above a certain
-  // threshold.
-  if ((!force_skip_low_temp_var || bsize < BLOCK_32X32) &&
-      perform_intra_pred &&
-      (best_rdc.rdcost == INT64_MAX ||
-       (!x->skip && best_rdc.rdcost > inter_mode_thresh &&
-        bsize <= cpi->sf.max_intra_bsize))) {
-    struct estimate_block_intra_args args = { cpi, x, DC_PRED, 1, 0 };
-    int i;
-    TX_SIZE best_intra_tx_size = TX_SIZES;
-    TX_SIZE intra_tx_size =
-        VPXMIN(max_txsize_lookup[bsize],
-               tx_mode_to_biggest_tx_size[cpi->common.tx_mode]);
-    if (cpi->oxcf.content != VP9E_CONTENT_SCREEN && intra_tx_size > TX_16X16)
-      intra_tx_size = TX_16X16;
-
-    if (reuse_inter_pred && best_pred != NULL) {
-      if (best_pred->data == orig_dst.buf) {
-        this_mode_pred = &tmp[get_pred_buffer(tmp, 3)];
-#if CONFIG_VP9_HIGHBITDEPTH
-        if (cm->use_highbitdepth)
-          vpx_highbd_convolve_copy(best_pred->data, best_pred->stride,
-                                   this_mode_pred->data, this_mode_pred->stride,
-                                   NULL, 0, NULL, 0, bw, bh, xd->bd);
-        else
-          vpx_convolve_copy(best_pred->data, best_pred->stride,
-                          this_mode_pred->data, this_mode_pred->stride,
-                          NULL, 0, NULL, 0, bw, bh);
-#else
-        vpx_convolve_copy(best_pred->data, best_pred->stride,
-                          this_mode_pred->data, this_mode_pred->stride,
-                          NULL, 0, NULL, 0, bw, bh);
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-        best_pred = this_mode_pred;
-      }
-    }
-    pd->dst = orig_dst;
-
-    for (i = 0; i < 4; ++i) {
-      const PREDICTION_MODE this_mode = intra_mode_list[i];
-      THR_MODES mode_index = mode_idx[INTRA_FRAME][mode_offset(this_mode)];
-      int mode_rd_thresh = rd_threshes[mode_index];
-      if (sf->short_circuit_flat_blocks && x->source_variance == 0 &&
-          this_mode != DC_PRED) {
-        continue;
-      }
-
-      if (!((1 << this_mode) & cpi->sf.intra_y_mode_bsize_mask[bsize]))
-        continue;
-
-      if (rd_less_than_thresh(best_rdc.rdcost, mode_rd_thresh,
-                              rd_thresh_freq_fact[mode_index]))
-        continue;
-
-      mi->mode = this_mode;
-      mi->ref_frame[0] = INTRA_FRAME;
-      this_rdc.dist = this_rdc.rate = 0;
-      args.mode = this_mode;
-      args.skippable = 1;
-      args.rdc = &this_rdc;
-      mi->tx_size = intra_tx_size;
-      vp9_foreach_transformed_block_in_plane(xd, bsize, 0,
-                                             estimate_block_intra, &args);
-      // Check skip cost here since skippable is not set for for uv, this
-      // mirrors the behavior used by inter
-      if (args.skippable) {
-        x->skip_txfm[0] = SKIP_TXFM_AC_DC;
-        this_rdc.rate = vp9_cost_bit(vp9_get_skip_prob(&cpi->common, xd), 1);
-      } else {
-        x->skip_txfm[0] = SKIP_TXFM_NONE;
-        this_rdc.rate += vp9_cost_bit(vp9_get_skip_prob(&cpi->common, xd), 0);
-      }
-      // Inter and intra RD will mismatch in scale for non-screen content.
-      if (cpi->oxcf.content == VP9E_CONTENT_SCREEN) {
-        if (x->color_sensitivity[0])
-          vp9_foreach_transformed_block_in_plane(xd, bsize, 1,
-                                                 estimate_block_intra, &args);
-        if (x->color_sensitivity[1])
-          vp9_foreach_transformed_block_in_plane(xd, bsize, 2,
-                                                 estimate_block_intra, &args);
-      }
-      this_rdc.rate += cpi->mbmode_cost[this_mode];
-      this_rdc.rate += ref_frame_cost[INTRA_FRAME];
-      this_rdc.rate += intra_cost_penalty;
-      this_rdc.rdcost = RDCOST(x->rdmult, x->rddiv,
-                               this_rdc.rate, this_rdc.dist);
-
-      if (this_rdc.rdcost < best_rdc.rdcost) {
-        best_rdc = this_rdc;
-        best_mode = this_mode;
-        best_intra_tx_size = mi->tx_size;
-        best_ref_frame = INTRA_FRAME;
-        mi->uv_mode = this_mode;
-        mi->mv[0].as_int = INVALID_MV;
-        best_mode_skip_txfm = x->skip_txfm[0];
-      }
-    }
-
-    // Reset mb_mode_info to the best inter mode.
-    if (best_ref_frame != INTRA_FRAME) {
-      mi->tx_size = best_tx_size;
-    } else {
-      mi->tx_size = best_intra_tx_size;
-    }
-  }
-
-  pd->dst = orig_dst;
-  mi->mode = best_mode;
-  mi->ref_frame[0] = best_ref_frame;
-  x->skip_txfm[0] = best_mode_skip_txfm;
-
-  if (reuse_inter_pred && best_pred != NULL) {
-    if (best_pred->data != orig_dst.buf && is_inter_mode(mi->mode)) {
-#if CONFIG_VP9_HIGHBITDEPTH
-      if (cm->use_highbitdepth)
-        vpx_highbd_convolve_copy(best_pred->data, best_pred->stride,
-                                 pd->dst.buf, pd->dst.stride, NULL, 0,
-                                 NULL, 0, bw, bh, xd->bd);
-      else
-        vpx_convolve_copy(best_pred->data, best_pred->stride,
-                          pd->dst.buf, pd->dst.stride, NULL, 0,
-                          NULL, 0, bw, bh);
-#else
-      vpx_convolve_copy(best_pred->data, best_pred->stride,
-                        pd->dst.buf, pd->dst.stride, NULL, 0,
-                        NULL, 0, bw, bh);
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-    }
-  }
-
-#if CONFIG_VP9_TEMPORAL_DENOISING
-  if (cpi->oxcf.noise_sensitivity > 0 &&
-      cpi->resize_pending == 0 &&
-      cpi->denoiser.denoising_level > kDenLowLow &&
-      cpi->denoiser.reset == 0) {
-    VP9_DENOISER_DECISION decision = COPY_BLOCK;
-    vp9_pickmode_ctx_den_update(&ctx_den, zero_last_cost_orig, ref_frame_cost,
-                                frame_mv, reuse_inter_pred, best_tx_size,
-                                best_mode, best_ref_frame, best_pred_filter,
-                                best_mode_skip_txfm);
-    vp9_denoiser_denoise(cpi, x, mi_row, mi_col, bsize, ctx, &decision);
-    recheck_zeromv_after_denoising(cpi, mi, x, xd, decision, &ctx_den, yv12_mb,
-                                   &best_rdc, bsize, mi_row, mi_col);
-    best_ref_frame = ctx_den.best_ref_frame;
-  }
-#endif
-
-  if (cpi->sf.adaptive_rd_thresh) {
-    THR_MODES best_mode_idx = mode_idx[best_ref_frame][mode_offset(mi->mode)];
-
-    if (best_ref_frame == INTRA_FRAME) {
-      // Only consider the modes that are included in the intra_mode_list.
-      int intra_modes = sizeof(intra_mode_list)/sizeof(PREDICTION_MODE);
-      int i;
-
-      // TODO(yunqingwang): Check intra mode mask and only update freq_fact
-      // for those valid modes.
-      for (i = 0; i < intra_modes; i++) {
-        update_thresh_freq_fact(cpi, tile_data, bsize, INTRA_FRAME,
-                                best_mode_idx, intra_mode_list[i]);
-      }
-    } else {
-      for (ref_frame = LAST_FRAME; ref_frame <= GOLDEN_FRAME; ++ref_frame) {
-        PREDICTION_MODE this_mode;
-        if (best_ref_frame != ref_frame) continue;
-        for (this_mode = NEARESTMV; this_mode <= NEWMV; ++this_mode) {
-          update_thresh_freq_fact(cpi, tile_data, bsize, ref_frame,
-                                  best_mode_idx, this_mode);
-        }
-      }
-    }
-  }
-
-  *rd_cost = best_rdc;
-}
-
-void vp9_pick_inter_mode_sub8x8(VP9_COMP *cpi, MACROBLOCK *x,
-                                int mi_row, int mi_col, RD_COST *rd_cost,
-                                BLOCK_SIZE bsize, PICK_MODE_CONTEXT *ctx) {
-  VP9_COMMON *const cm = &cpi->common;
-  SPEED_FEATURES *const sf = &cpi->sf;
-  MACROBLOCKD *const xd = &x->e_mbd;
-  MODE_INFO *const mi = xd->mi[0];
-  MB_MODE_INFO_EXT *const mbmi_ext = x->mbmi_ext;
-  const struct segmentation *const seg = &cm->seg;
-  MV_REFERENCE_FRAME ref_frame, second_ref_frame = NONE;
-  MV_REFERENCE_FRAME best_ref_frame = NONE;
-  unsigned char segment_id = mi->segment_id;
-  struct buf_2d yv12_mb[4][MAX_MB_PLANE];
-  static const int flag_list[4] = { 0, VP9_LAST_FLAG, VP9_GOLD_FLAG,
-                                    VP9_ALT_FLAG };
-  int64_t best_rd = INT64_MAX;
-  b_mode_info bsi[MAX_REF_FRAMES][4];
-  int ref_frame_skip_mask = 0;
-  const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[bsize];
-  const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[bsize];
-  int idx, idy;
-
-  x->skip_encode = sf->skip_encode_frame && x->q_index < QIDX_SKIP_THRESH;
-  ctx->pred_pixel_ready = 0;
-
-  for (ref_frame = LAST_FRAME; ref_frame <= GOLDEN_FRAME; ++ref_frame) {
-    const YV12_BUFFER_CONFIG *yv12 = get_ref_frame_buffer(cpi, ref_frame);
-    int_mv dummy_mv[2];
-    x->pred_mv_sad[ref_frame] = INT_MAX;
-
-    if ((cpi->ref_frame_flags & flag_list[ref_frame]) && (yv12 != NULL)) {
-      int_mv *const candidates = mbmi_ext->ref_mvs[ref_frame];
-      const struct scale_factors *const sf =
-                             &cm->frame_refs[ref_frame - 1].sf;
-      vp9_setup_pred_block(xd, yv12_mb[ref_frame], yv12, mi_row, mi_col,
-                           sf, sf);
-      vp9_find_mv_refs(cm, xd, xd->mi[0], ref_frame,
-                       candidates, mi_row, mi_col, mbmi_ext->mode_context);
-
-      vp9_find_best_ref_mvs(xd, cm->allow_high_precision_mv, candidates,
-                            &dummy_mv[0], &dummy_mv[1]);
-    } else {
-      ref_frame_skip_mask |= (1 << ref_frame);
-    }
-  }
-
-  mi->sb_type = bsize;
-  mi->tx_size = TX_4X4;
-  mi->uv_mode = DC_PRED;
-  mi->ref_frame[0] = LAST_FRAME;
-  mi->ref_frame[1] = NONE;
-  mi->interp_filter = cm->interp_filter == SWITCHABLE ? EIGHTTAP
-                                                      : cm->interp_filter;
-
-  for (ref_frame = LAST_FRAME; ref_frame <= GOLDEN_FRAME; ++ref_frame) {
-    int64_t this_rd = 0;
-    int plane;
-
-    if (ref_frame_skip_mask & (1 << ref_frame))
-      continue;
-
-#if CONFIG_BETTER_HW_COMPATIBILITY
-    if ((bsize == BLOCK_8X4 || bsize == BLOCK_4X8) &&
-        ref_frame > INTRA_FRAME &&
-        vp9_is_scaled(&cm->frame_refs[ref_frame - 1].sf))
-      continue;
-#endif
-
-    // TODO(jingning, agrange): Scaling reference frame not supported for
-    // sub8x8 blocks. Is this supported now?
-    if (ref_frame > INTRA_FRAME &&
-        vp9_is_scaled(&cm->frame_refs[ref_frame - 1].sf))
-      continue;
-
-    // If the segment reference frame feature is enabled....
-    // then do nothing if the current ref frame is not allowed..
-    if (segfeature_active(seg, segment_id, SEG_LVL_REF_FRAME) &&
-        get_segdata(seg, segment_id, SEG_LVL_REF_FRAME) != (int)ref_frame)
-      continue;
-
-    mi->ref_frame[0] = ref_frame;
-    x->skip = 0;
-    set_ref_ptrs(cm, xd, ref_frame, second_ref_frame);
-
-    // Select prediction reference frames.
-    for (plane = 0; plane < MAX_MB_PLANE; plane++)
-      xd->plane[plane].pre[0] = yv12_mb[ref_frame][plane];
-
-    for (idy = 0; idy < 2; idy += num_4x4_blocks_high) {
-      for (idx = 0; idx < 2; idx += num_4x4_blocks_wide) {
-        int_mv b_mv[MB_MODE_COUNT];
-        int64_t b_best_rd = INT64_MAX;
-        const int i = idy * 2 + idx;
-        PREDICTION_MODE this_mode;
-        RD_COST this_rdc;
-        unsigned int var_y, sse_y;
-
-        struct macroblock_plane *p = &x->plane[0];
-        struct macroblockd_plane *pd = &xd->plane[0];
-
-        const struct buf_2d orig_src = p->src;
-        const struct buf_2d orig_dst = pd->dst;
-        struct buf_2d orig_pre[2];
-        memcpy(orig_pre, xd->plane[0].pre, sizeof(orig_pre));
-
-        // set buffer pointers for sub8x8 motion search.
-        p->src.buf =
-            &p->src.buf[vp9_raster_block_offset(BLOCK_8X8, i, p->src.stride)];
-        pd->dst.buf =
-            &pd->dst.buf[vp9_raster_block_offset(BLOCK_8X8, i, pd->dst.stride)];
-        pd->pre[0].buf =
-            &pd->pre[0].buf[vp9_raster_block_offset(BLOCK_8X8,
-                                                    i, pd->pre[0].stride)];
-
-        b_mv[ZEROMV].as_int = 0;
-        b_mv[NEWMV].as_int = INVALID_MV;
-        vp9_append_sub8x8_mvs_for_idx(cm, xd, i, 0, mi_row, mi_col,
-                                      &b_mv[NEARESTMV],
-                                      &b_mv[NEARMV],
-                                      mbmi_ext->mode_context);
-
-        for (this_mode = NEARESTMV; this_mode <= NEWMV; ++this_mode) {
-          int b_rate = 0;
-          xd->mi[0]->bmi[i].as_mv[0].as_int = b_mv[this_mode].as_int;
-
-          if (this_mode == NEWMV) {
-            const int step_param = cpi->sf.mv.fullpel_search_step_param;
-            MV mvp_full;
-            MV tmp_mv;
-            int cost_list[5];
-            const int tmp_col_min = x->mv_col_min;
-            const int tmp_col_max = x->mv_col_max;
-            const int tmp_row_min = x->mv_row_min;
-            const int tmp_row_max = x->mv_row_max;
-            uint32_t dummy_dist;
-
-            if (i == 0) {
-              mvp_full.row = b_mv[NEARESTMV].as_mv.row >> 3;
-              mvp_full.col = b_mv[NEARESTMV].as_mv.col >> 3;
-            } else {
-              mvp_full.row = xd->mi[0]->bmi[0].as_mv[0].as_mv.row >> 3;
-              mvp_full.col = xd->mi[0]->bmi[0].as_mv[0].as_mv.col >> 3;
-            }
-
-            vp9_set_mv_search_range(x, &mbmi_ext->ref_mvs[0]->as_mv);
-
-            vp9_full_pixel_search(
-                cpi, x, bsize, &mvp_full, step_param, x->sadperbit4,
-                cond_cost_list(cpi, cost_list),
-                &mbmi_ext->ref_mvs[ref_frame][0].as_mv, &tmp_mv,
-                INT_MAX, 0);
-
-            x->mv_col_min = tmp_col_min;
-            x->mv_col_max = tmp_col_max;
-            x->mv_row_min = tmp_row_min;
-            x->mv_row_max = tmp_row_max;
-
-            // calculate the bit cost on motion vector
-            mvp_full.row = tmp_mv.row * 8;
-            mvp_full.col = tmp_mv.col * 8;
-
-            b_rate += vp9_mv_bit_cost(&mvp_full,
-                                      &mbmi_ext->ref_mvs[ref_frame][0].as_mv,
-                                      x->nmvjointcost, x->mvcost,
-                                      MV_COST_WEIGHT);
-
-            b_rate += cpi->inter_mode_cost[x->mbmi_ext->mode_context[ref_frame]]
-                                          [INTER_OFFSET(NEWMV)];
-            if (RDCOST(x->rdmult, x->rddiv, b_rate, 0) > b_best_rd)
-              continue;
-
-            cpi->find_fractional_mv_step(x, &tmp_mv,
-                                         &mbmi_ext->ref_mvs[ref_frame][0].as_mv,
-                                         cpi->common.allow_high_precision_mv,
-                                         x->errorperbit,
-                                         &cpi->fn_ptr[bsize],
-                                         cpi->sf.mv.subpel_force_stop,
-                                         cpi->sf.mv.subpel_iters_per_step,
-                                         cond_cost_list(cpi, cost_list),
-                                         x->nmvjointcost, x->mvcost,
-                                         &dummy_dist,
-                                         &x->pred_sse[ref_frame], NULL, 0, 0);
-
-            xd->mi[0]->bmi[i].as_mv[0].as_mv = tmp_mv;
-          } else {
-            b_rate += cpi->inter_mode_cost[x->mbmi_ext->mode_context[ref_frame]]
-                                          [INTER_OFFSET(this_mode)];
-          }
-
-#if CONFIG_VP9_HIGHBITDEPTH
-          if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
-            vp9_highbd_build_inter_predictor(pd->pre[0].buf, pd->pre[0].stride,
-                                    pd->dst.buf, pd->dst.stride,
-                                    &xd->mi[0]->bmi[i].as_mv[0].as_mv,
-                                    &xd->block_refs[0]->sf,
-                                    4 * num_4x4_blocks_wide,
-                                    4 * num_4x4_blocks_high, 0,
-                                    vp9_filter_kernels[mi->interp_filter],
-                                    MV_PRECISION_Q3,
-                                    mi_col * MI_SIZE + 4 * (i & 0x01),
-                                    mi_row * MI_SIZE + 4 * (i >> 1), xd->bd);
-          } else {
-#endif
-            vp9_build_inter_predictor(pd->pre[0].buf, pd->pre[0].stride,
-                                     pd->dst.buf, pd->dst.stride,
-                                     &xd->mi[0]->bmi[i].as_mv[0].as_mv,
-                                     &xd->block_refs[0]->sf,
-                                     4 * num_4x4_blocks_wide,
-                                     4 * num_4x4_blocks_high, 0,
-                                     vp9_filter_kernels[mi->interp_filter],
-                                     MV_PRECISION_Q3,
-                                     mi_col * MI_SIZE + 4 * (i & 0x01),
-                                     mi_row * MI_SIZE + 4 * (i >> 1));
-
-#if CONFIG_VP9_HIGHBITDEPTH
-          }
-#endif
-
-          model_rd_for_sb_y(cpi, bsize, x, xd, &this_rdc.rate, &this_rdc.dist,
-                            &var_y, &sse_y);
-
-          this_rdc.rate += b_rate;
-          this_rdc.rdcost = RDCOST(x->rdmult, x->rddiv,
-                                   this_rdc.rate, this_rdc.dist);
-          if (this_rdc.rdcost < b_best_rd) {
-            b_best_rd = this_rdc.rdcost;
-            bsi[ref_frame][i].as_mode = this_mode;
-            bsi[ref_frame][i].as_mv[0].as_mv = xd->mi[0]->bmi[i].as_mv[0].as_mv;
-          }
-        }  // mode search
-
-        // restore source and prediction buffer pointers.
-        p->src = orig_src;
-        pd->pre[0] = orig_pre[0];
-        pd->dst = orig_dst;
-        this_rd += b_best_rd;
-
-        xd->mi[0]->bmi[i] = bsi[ref_frame][i];
-        if (num_4x4_blocks_wide > 1)
-          xd->mi[0]->bmi[i + 1] = xd->mi[0]->bmi[i];
-        if (num_4x4_blocks_high > 1)
-          xd->mi[0]->bmi[i + 2] = xd->mi[0]->bmi[i];
-      }
-    }  // loop through sub8x8 blocks
-
-    if (this_rd < best_rd) {
-      best_rd = this_rd;
-      best_ref_frame = ref_frame;
-    }
-  }  // reference frames
-
-  mi->tx_size = TX_4X4;
-  mi->ref_frame[0] = best_ref_frame;
-  for (idy = 0; idy < 2; idy += num_4x4_blocks_high) {
-    for (idx = 0; idx < 2; idx += num_4x4_blocks_wide) {
-      const int block = idy * 2 + idx;
-      xd->mi[0]->bmi[block] = bsi[best_ref_frame][block];
-      if (num_4x4_blocks_wide > 1)
-        xd->mi[0]->bmi[block + 1] = bsi[best_ref_frame][block];
-      if (num_4x4_blocks_high > 1)
-        xd->mi[0]->bmi[block + 2] = bsi[best_ref_frame][block];
-    }
-  }
-  mi->mode = xd->mi[0]->bmi[3].as_mode;
-  ctx->mic = *(xd->mi[0]);
-  ctx->mbmi_ext = *x->mbmi_ext;
-  ctx->skip_txfm[0] = SKIP_TXFM_NONE;
-  ctx->skip = 0;
-  // Dummy assignment for speed -5. No effect in speed -6.
-  rd_cost->rdcost = best_rd;
-}
diff --git a/vp9/encoder/vp9_pickmode.h b/vp9/encoder/vp9_pickmode.h
deleted file mode 100644 (file)
index a43bb81..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- *  Copyright (c) 2014 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.
- */
-
-#ifndef VP9_ENCODER_VP9_PICKMODE_H_
-#define VP9_ENCODER_VP9_PICKMODE_H_
-
-#include "vp9/encoder/vp9_encoder.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-void vp9_pick_intra_mode(VP9_COMP *cpi, MACROBLOCK *x, RD_COST *rd_cost,
-                         BLOCK_SIZE bsize, PICK_MODE_CONTEXT *ctx);
-
-void vp9_pick_inter_mode(VP9_COMP *cpi, MACROBLOCK *x,
-                         TileDataEnc *tile_data,
-                         int mi_row, int mi_col, RD_COST *rd_cost,
-                         BLOCK_SIZE bsize,
-                         PICK_MODE_CONTEXT *ctx);
-
-void vp9_pick_inter_mode_sub8x8(VP9_COMP *cpi, MACROBLOCK *x,
-                                int mi_row, int mi_col, RD_COST *rd_cost,
-                                BLOCK_SIZE bsize,
-                                PICK_MODE_CONTEXT *ctx);
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP9_ENCODER_VP9_PICKMODE_H_
diff --git a/vp9/encoder/vp9_quantize.c b/vp9/encoder/vp9_quantize.c
deleted file mode 100644 (file)
index d68b684..0000000
+++ /dev/null
@@ -1,388 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#include <math.h>
-#include "./vpx_dsp_rtcd.h"
-#include "vpx_mem/vpx_mem.h"
-#include "vpx_ports/mem.h"
-
-#include "vp9/common/vp9_quant_common.h"
-#include "vp9/common/vp9_seg_common.h"
-
-#include "vp9/encoder/vp9_encoder.h"
-#include "vp9/encoder/vp9_quantize.h"
-#include "vp9/encoder/vp9_rd.h"
-
-void vp9_quantize_fp_c(const tran_low_t *coeff_ptr, intptr_t n_coeffs,
-                       int skip_block,
-                       const int16_t *zbin_ptr, const int16_t *round_ptr,
-                       const int16_t *quant_ptr, const int16_t *quant_shift_ptr,
-                       tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr,
-                       const int16_t *dequant_ptr,
-                       uint16_t *eob_ptr,
-                       const int16_t *scan, const int16_t *iscan) {
-  int i, eob = -1;
-  // TODO(jingning) Decide the need of these arguments after the
-  // quantization process is completed.
-  (void)zbin_ptr;
-  (void)quant_shift_ptr;
-  (void)iscan;
-
-  memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr));
-  memset(dqcoeff_ptr, 0, n_coeffs * sizeof(*dqcoeff_ptr));
-
-  if (!skip_block) {
-    // Quantization pass: All coefficients with index >= zero_flag are
-    // skippable. Note: zero_flag can be zero.
-    for (i = 0; i < n_coeffs; i++) {
-      const int rc = scan[i];
-      const int coeff = coeff_ptr[rc];
-      const int coeff_sign = (coeff >> 31);
-      const int abs_coeff = (coeff ^ coeff_sign) - coeff_sign;
-
-      int tmp = clamp(abs_coeff + round_ptr[rc != 0], INT16_MIN, INT16_MAX);
-      tmp = (tmp * quant_ptr[rc != 0]) >> 16;
-
-      qcoeff_ptr[rc] = (tmp ^ coeff_sign) - coeff_sign;
-      dqcoeff_ptr[rc] = qcoeff_ptr[rc] * dequant_ptr[rc != 0];
-
-      if (tmp)
-        eob = i;
-    }
-  }
-  *eob_ptr = eob + 1;
-}
-
-#if CONFIG_VP9_HIGHBITDEPTH
-void vp9_highbd_quantize_fp_c(const tran_low_t *coeff_ptr,
-                              intptr_t count,
-                              int skip_block,
-                              const int16_t *zbin_ptr,
-                              const int16_t *round_ptr,
-                              const int16_t *quant_ptr,
-                              const int16_t *quant_shift_ptr,
-                              tran_low_t *qcoeff_ptr,
-                              tran_low_t *dqcoeff_ptr,
-                              const int16_t *dequant_ptr,
-                              uint16_t *eob_ptr,
-                              const int16_t *scan,
-                              const int16_t *iscan) {
-  int i;
-  int eob = -1;
-  // TODO(jingning) Decide the need of these arguments after the
-  // quantization process is completed.
-  (void)zbin_ptr;
-  (void)quant_shift_ptr;
-  (void)iscan;
-
-  memset(qcoeff_ptr, 0, count * sizeof(*qcoeff_ptr));
-  memset(dqcoeff_ptr, 0, count * sizeof(*dqcoeff_ptr));
-
-  if (!skip_block) {
-    // Quantization pass: All coefficients with index >= zero_flag are
-    // skippable. Note: zero_flag can be zero.
-    for (i = 0; i < count; i++) {
-      const int rc = scan[i];
-      const int coeff = coeff_ptr[rc];
-      const int coeff_sign = (coeff >> 31);
-      const int abs_coeff = (coeff ^ coeff_sign) - coeff_sign;
-      const int64_t tmp = abs_coeff + round_ptr[rc != 0];
-      const int abs_qcoeff = (int)((tmp * quant_ptr[rc != 0]) >> 16);
-      qcoeff_ptr[rc] = (tran_low_t)((abs_qcoeff ^ coeff_sign) - coeff_sign);
-      dqcoeff_ptr[rc] = qcoeff_ptr[rc] * dequant_ptr[rc != 0];
-      if (abs_qcoeff)
-        eob = i;
-    }
-  }
-  *eob_ptr = eob + 1;
-}
-#endif
-
-// TODO(jingning) Refactor this file and combine functions with similar
-// operations.
-void vp9_quantize_fp_32x32_c(const tran_low_t *coeff_ptr, intptr_t n_coeffs,
-                             int skip_block,
-                             const int16_t *zbin_ptr, const int16_t *round_ptr,
-                             const int16_t *quant_ptr,
-                             const int16_t *quant_shift_ptr,
-                             tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr,
-                             const int16_t *dequant_ptr,
-                             uint16_t *eob_ptr,
-                             const int16_t *scan, const int16_t *iscan) {
-  int i, eob = -1;
-  (void)zbin_ptr;
-  (void)quant_shift_ptr;
-  (void)iscan;
-
-  memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr));
-  memset(dqcoeff_ptr, 0, n_coeffs * sizeof(*dqcoeff_ptr));
-
-  if (!skip_block) {
-    for (i = 0; i < n_coeffs; i++) {
-      const int rc = scan[i];
-      const int coeff = coeff_ptr[rc];
-      const int coeff_sign = (coeff >> 31);
-      int tmp = 0;
-      int abs_coeff = (coeff ^ coeff_sign) - coeff_sign;
-
-      if (abs_coeff >= (dequant_ptr[rc != 0] >> 2)) {
-        abs_coeff += ROUND_POWER_OF_TWO(round_ptr[rc != 0], 1);
-        abs_coeff = clamp(abs_coeff, INT16_MIN, INT16_MAX);
-        tmp = (abs_coeff * quant_ptr[rc != 0]) >> 15;
-        qcoeff_ptr[rc] = (tmp ^ coeff_sign) - coeff_sign;
-        dqcoeff_ptr[rc] = qcoeff_ptr[rc] * dequant_ptr[rc != 0] / 2;
-      }
-
-      if (tmp)
-        eob = i;
-    }
-  }
-  *eob_ptr = eob + 1;
-}
-
-#if CONFIG_VP9_HIGHBITDEPTH
-void vp9_highbd_quantize_fp_32x32_c(const tran_low_t *coeff_ptr,
-                                    intptr_t n_coeffs, int skip_block,
-                                    const int16_t *zbin_ptr,
-                                    const int16_t *round_ptr,
-                                    const int16_t *quant_ptr,
-                                    const int16_t *quant_shift_ptr,
-                                    tran_low_t *qcoeff_ptr,
-                                    tran_low_t *dqcoeff_ptr,
-                                    const int16_t *dequant_ptr,
-                                    uint16_t *eob_ptr,
-                                    const int16_t *scan, const int16_t *iscan) {
-  int i, eob = -1;
-  (void)zbin_ptr;
-  (void)quant_shift_ptr;
-  (void)iscan;
-
-  memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr));
-  memset(dqcoeff_ptr, 0, n_coeffs * sizeof(*dqcoeff_ptr));
-
-  if (!skip_block) {
-    for (i = 0; i < n_coeffs; i++) {
-      uint32_t abs_qcoeff = 0;
-      const int rc = scan[i];
-      const int coeff = coeff_ptr[rc];
-      const int coeff_sign = (coeff >> 31);
-      const int abs_coeff = (coeff ^ coeff_sign) - coeff_sign;
-
-      if (abs_coeff >= (dequant_ptr[rc != 0] >> 2)) {
-        const int64_t tmp = abs_coeff
-                           + ROUND_POWER_OF_TWO(round_ptr[rc != 0], 1);
-        abs_qcoeff = (uint32_t) ((tmp * quant_ptr[rc != 0]) >> 15);
-        qcoeff_ptr[rc] = (tran_low_t)((abs_qcoeff ^ coeff_sign) - coeff_sign);
-        dqcoeff_ptr[rc] = qcoeff_ptr[rc] * dequant_ptr[rc != 0] / 2;
-      }
-
-      if (abs_qcoeff)
-        eob = i;
-    }
-  }
-  *eob_ptr = eob + 1;
-}
-#endif
-
-void vp9_regular_quantize_b_4x4(MACROBLOCK *x, int plane, int block,
-                                const int16_t *scan, const int16_t *iscan) {
-  MACROBLOCKD *const xd = &x->e_mbd;
-  struct macroblock_plane *p = &x->plane[plane];
-  struct macroblockd_plane *pd = &xd->plane[plane];
-
-#if CONFIG_VP9_HIGHBITDEPTH
-  if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
-    vpx_highbd_quantize_b(BLOCK_OFFSET(p->coeff, block),
-                          16, x->skip_block,
-                          p->zbin, p->round, p->quant, p->quant_shift,
-                          BLOCK_OFFSET(p->qcoeff, block),
-                          BLOCK_OFFSET(pd->dqcoeff, block),
-                          pd->dequant, &p->eobs[block],
-                          scan, iscan);
-    return;
-  }
-#endif
-  vpx_quantize_b(BLOCK_OFFSET(p->coeff, block),
-                 16, x->skip_block,
-                 p->zbin, p->round, p->quant, p->quant_shift,
-                 BLOCK_OFFSET(p->qcoeff, block),
-                 BLOCK_OFFSET(pd->dqcoeff, block),
-                 pd->dequant, &p->eobs[block], scan, iscan);
-}
-
-static void invert_quant(int16_t *quant, int16_t *shift, int d) {
-  unsigned t;
-  int l, m;
-  t = d;
-  for (l = 0; t > 1; l++)
-    t >>= 1;
-  m = 1 + (1 << (16 + l)) / d;
-  *quant = (int16_t)(m - (1 << 16));
-  *shift = 1 << (16 - l);
-}
-
-static int get_qzbin_factor(int q, vpx_bit_depth_t bit_depth) {
-  const int quant = vp9_dc_quant(q, 0, bit_depth);
-#if CONFIG_VP9_HIGHBITDEPTH
-  switch (bit_depth) {
-    case VPX_BITS_8:
-      return q == 0 ? 64 : (quant < 148 ? 84 : 80);
-    case VPX_BITS_10:
-      return q == 0 ? 64 : (quant < 592 ? 84 : 80);
-    case VPX_BITS_12:
-      return q == 0 ? 64 : (quant < 2368 ? 84 : 80);
-    default:
-      assert(0 && "bit_depth should be VPX_BITS_8, VPX_BITS_10 or VPX_BITS_12");
-      return -1;
-  }
-#else
-  (void) bit_depth;
-  return q == 0 ? 64 : (quant < 148 ? 84 : 80);
-#endif
-}
-
-void vp9_init_quantizer(VP9_COMP *cpi) {
-  VP9_COMMON *const cm = &cpi->common;
-  QUANTS *const quants = &cpi->quants;
-  int i, q, quant;
-
-  for (q = 0; q < QINDEX_RANGE; q++) {
-    const int qzbin_factor = get_qzbin_factor(q, cm->bit_depth);
-    const int qrounding_factor = q == 0 ? 64 : 48;
-
-    for (i = 0; i < 2; ++i) {
-      int qrounding_factor_fp = i == 0 ? 48 : 42;
-      if (q == 0)
-        qrounding_factor_fp = 64;
-
-      // y
-      quant = i == 0 ? vp9_dc_quant(q, cm->y_dc_delta_q, cm->bit_depth)
-                     : vp9_ac_quant(q, 0, cm->bit_depth);
-      invert_quant(&quants->y_quant[q][i], &quants->y_quant_shift[q][i], quant);
-      quants->y_quant_fp[q][i] = (1 << 16) / quant;
-      quants->y_round_fp[q][i] = (qrounding_factor_fp * quant) >> 7;
-      quants->y_zbin[q][i] = ROUND_POWER_OF_TWO(qzbin_factor * quant, 7);
-      quants->y_round[q][i] = (qrounding_factor * quant) >> 7;
-      cpi->y_dequant[q][i] = quant;
-
-      // uv
-      quant = i == 0 ? vp9_dc_quant(q, cm->uv_dc_delta_q, cm->bit_depth)
-                     : vp9_ac_quant(q, cm->uv_ac_delta_q, cm->bit_depth);
-      invert_quant(&quants->uv_quant[q][i],
-                   &quants->uv_quant_shift[q][i], quant);
-      quants->uv_quant_fp[q][i] = (1 << 16) / quant;
-      quants->uv_round_fp[q][i] = (qrounding_factor_fp * quant) >> 7;
-      quants->uv_zbin[q][i] = ROUND_POWER_OF_TWO(qzbin_factor * quant, 7);
-      quants->uv_round[q][i] = (qrounding_factor * quant) >> 7;
-      cpi->uv_dequant[q][i] = quant;
-    }
-
-    for (i = 2; i < 8; i++) {
-      quants->y_quant[q][i] = quants->y_quant[q][1];
-      quants->y_quant_fp[q][i] = quants->y_quant_fp[q][1];
-      quants->y_round_fp[q][i] = quants->y_round_fp[q][1];
-      quants->y_quant_shift[q][i] = quants->y_quant_shift[q][1];
-      quants->y_zbin[q][i] = quants->y_zbin[q][1];
-      quants->y_round[q][i] = quants->y_round[q][1];
-      cpi->y_dequant[q][i] = cpi->y_dequant[q][1];
-
-      quants->uv_quant[q][i] = quants->uv_quant[q][1];
-      quants->uv_quant_fp[q][i] = quants->uv_quant_fp[q][1];
-      quants->uv_round_fp[q][i] = quants->uv_round_fp[q][1];
-      quants->uv_quant_shift[q][i] = quants->uv_quant_shift[q][1];
-      quants->uv_zbin[q][i] = quants->uv_zbin[q][1];
-      quants->uv_round[q][i] = quants->uv_round[q][1];
-      cpi->uv_dequant[q][i] = cpi->uv_dequant[q][1];
-    }
-  }
-}
-
-void vp9_init_plane_quantizers(VP9_COMP *cpi, MACROBLOCK *x) {
-  const VP9_COMMON *const cm = &cpi->common;
-  MACROBLOCKD *const xd = &x->e_mbd;
-  QUANTS *const quants = &cpi->quants;
-  const int segment_id = xd->mi[0]->segment_id;
-  const int qindex = vp9_get_qindex(&cm->seg, segment_id, cm->base_qindex);
-  const int rdmult = vp9_compute_rd_mult(cpi, qindex + cm->y_dc_delta_q);
-  int i;
-
-  // Y
-  x->plane[0].quant = quants->y_quant[qindex];
-  x->plane[0].quant_fp = quants->y_quant_fp[qindex];
-  x->plane[0].round_fp = quants->y_round_fp[qindex];
-  x->plane[0].quant_shift = quants->y_quant_shift[qindex];
-  x->plane[0].zbin = quants->y_zbin[qindex];
-  x->plane[0].round = quants->y_round[qindex];
-  xd->plane[0].dequant = cpi->y_dequant[qindex];
-
-  x->plane[0].quant_thred[0] = x->plane[0].zbin[0] * x->plane[0].zbin[0];
-  x->plane[0].quant_thred[1] = x->plane[0].zbin[1] * x->plane[0].zbin[1];
-
-  // UV
-  for (i = 1; i < 3; i++) {
-    x->plane[i].quant = quants->uv_quant[qindex];
-    x->plane[i].quant_fp = quants->uv_quant_fp[qindex];
-    x->plane[i].round_fp = quants->uv_round_fp[qindex];
-    x->plane[i].quant_shift = quants->uv_quant_shift[qindex];
-    x->plane[i].zbin = quants->uv_zbin[qindex];
-    x->plane[i].round = quants->uv_round[qindex];
-    xd->plane[i].dequant = cpi->uv_dequant[qindex];
-
-    x->plane[i].quant_thred[0] = x->plane[i].zbin[0] * x->plane[i].zbin[0];
-    x->plane[i].quant_thred[1] = x->plane[i].zbin[1] * x->plane[i].zbin[1];
-  }
-
-  x->skip_block = segfeature_active(&cm->seg, segment_id, SEG_LVL_SKIP);
-  x->q_index = qindex;
-
-  set_error_per_bit(x, rdmult);
-
-  vp9_initialize_me_consts(cpi, x, x->q_index);
-}
-
-void vp9_frame_init_quantizer(VP9_COMP *cpi) {
-  vp9_init_plane_quantizers(cpi, &cpi->td.mb);
-}
-
-void vp9_set_quantizer(VP9_COMMON *cm, int q) {
-  // quantizer has to be reinitialized with vp9_init_quantizer() if any
-  // delta_q changes.
-  cm->base_qindex = q;
-  cm->y_dc_delta_q = 0;
-  cm->uv_dc_delta_q = 0;
-  cm->uv_ac_delta_q = 0;
-}
-
-// Table that converts 0-63 Q-range values passed in outside to the Qindex
-// range used internally.
-static const int quantizer_to_qindex[] = {
-  0,    4,   8,  12,  16,  20,  24,  28,
-  32,   36,  40,  44,  48,  52,  56,  60,
-  64,   68,  72,  76,  80,  84,  88,  92,
-  96,  100, 104, 108, 112, 116, 120, 124,
-  128, 132, 136, 140, 144, 148, 152, 156,
-  160, 164, 168, 172, 176, 180, 184, 188,
-  192, 196, 200, 204, 208, 212, 216, 220,
-  224, 228, 232, 236, 240, 244, 249, 255,
-};
-
-int vp9_quantizer_to_qindex(int quantizer) {
-  return quantizer_to_qindex[quantizer];
-}
-
-int vp9_qindex_to_quantizer(int qindex) {
-  int quantizer;
-
-  for (quantizer = 0; quantizer < 64; ++quantizer)
-    if (quantizer_to_qindex[quantizer] >= qindex)
-      return quantizer;
-
-  return 63;
-}
diff --git a/vp9/encoder/vp9_quantize.h b/vp9/encoder/vp9_quantize.h
deleted file mode 100644 (file)
index 6132036..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#ifndef VP9_ENCODER_VP9_QUANTIZE_H_
-#define VP9_ENCODER_VP9_QUANTIZE_H_
-
-#include "./vpx_config.h"
-#include "vp9/encoder/vp9_block.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef struct {
-  DECLARE_ALIGNED(16, int16_t, y_quant[QINDEX_RANGE][8]);
-  DECLARE_ALIGNED(16, int16_t, y_quant_shift[QINDEX_RANGE][8]);
-  DECLARE_ALIGNED(16, int16_t, y_zbin[QINDEX_RANGE][8]);
-  DECLARE_ALIGNED(16, int16_t, y_round[QINDEX_RANGE][8]);
-
-  // TODO(jingning): in progress of re-working the quantization. will decide
-  // if we want to deprecate the current use of y_quant.
-  DECLARE_ALIGNED(16, int16_t, y_quant_fp[QINDEX_RANGE][8]);
-  DECLARE_ALIGNED(16, int16_t, uv_quant_fp[QINDEX_RANGE][8]);
-  DECLARE_ALIGNED(16, int16_t, y_round_fp[QINDEX_RANGE][8]);
-  DECLARE_ALIGNED(16, int16_t, uv_round_fp[QINDEX_RANGE][8]);
-
-  DECLARE_ALIGNED(16, int16_t, uv_quant[QINDEX_RANGE][8]);
-  DECLARE_ALIGNED(16, int16_t, uv_quant_shift[QINDEX_RANGE][8]);
-  DECLARE_ALIGNED(16, int16_t, uv_zbin[QINDEX_RANGE][8]);
-  DECLARE_ALIGNED(16, int16_t, uv_round[QINDEX_RANGE][8]);
-} QUANTS;
-
-void vp9_regular_quantize_b_4x4(MACROBLOCK *x, int plane, int block,
-                                const int16_t *scan, const int16_t *iscan);
-
-struct VP9_COMP;
-struct VP9Common;
-
-void vp9_frame_init_quantizer(struct VP9_COMP *cpi);
-
-void vp9_init_plane_quantizers(struct VP9_COMP *cpi, MACROBLOCK *x);
-
-void vp9_init_quantizer(struct VP9_COMP *cpi);
-
-void vp9_set_quantizer(struct VP9Common *cm, int q);
-
-int vp9_quantizer_to_qindex(int quantizer);
-
-int vp9_qindex_to_quantizer(int qindex);
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP9_ENCODER_VP9_QUANTIZE_H_
diff --git a/vp9/encoder/vp9_ratectrl.c b/vp9/encoder/vp9_ratectrl.c
deleted file mode 100644 (file)
index b45f8d0..0000000
+++ /dev/null
@@ -1,2238 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#include <assert.h>
-#include <limits.h>
-#include <math.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "vpx_dsp/vpx_dsp_common.h"
-#include "vpx_mem/vpx_mem.h"
-#include "vpx_ports/mem.h"
-#include "vpx_ports/system_state.h"
-
-#include "vp9/common/vp9_alloccommon.h"
-#include "vp9/encoder/vp9_aq_cyclicrefresh.h"
-#include "vp9/common/vp9_common.h"
-#include "vp9/common/vp9_entropymode.h"
-#include "vp9/common/vp9_quant_common.h"
-#include "vp9/common/vp9_seg_common.h"
-
-#include "vp9/encoder/vp9_encodemv.h"
-#include "vp9/encoder/vp9_ratectrl.h"
-
-// Max rate target for 1080P and below encodes under normal circumstances
-// (1920 * 1080 / (16 * 16)) * MAX_MB_RATE bits per MB
-#define MAX_MB_RATE 250
-#define MAXRATE_1080P 2025000
-
-#define DEFAULT_KF_BOOST 2000
-#define DEFAULT_GF_BOOST 2000
-
-#define LIMIT_QRANGE_FOR_ALTREF_AND_KEY 1
-
-#define MIN_BPB_FACTOR 0.005
-#define MAX_BPB_FACTOR 50
-
-#define FRAME_OVERHEAD_BITS 200
-
-#if CONFIG_VP9_HIGHBITDEPTH
-#define ASSIGN_MINQ_TABLE(bit_depth, name) \
-  do { \
-    switch (bit_depth) { \
-      case VPX_BITS_8: \
-        name = name##_8; \
-        break; \
-      case VPX_BITS_10: \
-        name = name##_10; \
-        break; \
-      case VPX_BITS_12: \
-        name = name##_12; \
-        break; \
-      default: \
-        assert(0 && "bit_depth should be VPX_BITS_8, VPX_BITS_10" \
-                    " or VPX_BITS_12"); \
-        name = NULL; \
-    } \
-  } while (0)
-#else
-#define ASSIGN_MINQ_TABLE(bit_depth, name) \
-  do { \
-    (void) bit_depth; \
-    name = name##_8; \
-  } while (0)
-#endif
-
-// Tables relating active max Q to active min Q
-static int kf_low_motion_minq_8[QINDEX_RANGE];
-static int kf_high_motion_minq_8[QINDEX_RANGE];
-static int arfgf_low_motion_minq_8[QINDEX_RANGE];
-static int arfgf_high_motion_minq_8[QINDEX_RANGE];
-static int inter_minq_8[QINDEX_RANGE];
-static int rtc_minq_8[QINDEX_RANGE];
-
-#if CONFIG_VP9_HIGHBITDEPTH
-static int kf_low_motion_minq_10[QINDEX_RANGE];
-static int kf_high_motion_minq_10[QINDEX_RANGE];
-static int arfgf_low_motion_minq_10[QINDEX_RANGE];
-static int arfgf_high_motion_minq_10[QINDEX_RANGE];
-static int inter_minq_10[QINDEX_RANGE];
-static int rtc_minq_10[QINDEX_RANGE];
-static int kf_low_motion_minq_12[QINDEX_RANGE];
-static int kf_high_motion_minq_12[QINDEX_RANGE];
-static int arfgf_low_motion_minq_12[QINDEX_RANGE];
-static int arfgf_high_motion_minq_12[QINDEX_RANGE];
-static int inter_minq_12[QINDEX_RANGE];
-static int rtc_minq_12[QINDEX_RANGE];
-#endif
-
-static int gf_high = 2000;
-static int gf_low = 400;
-static int kf_high = 5000;
-static int kf_low = 400;
-
-// Functions to compute the active minq lookup table entries based on a
-// formulaic approach to facilitate easier adjustment of the Q tables.
-// The formulae were derived from computing a 3rd order polynomial best
-// fit to the original data (after plotting real maxq vs minq (not q index))
-static int get_minq_index(double maxq, double x3, double x2, double x1,
-                          vpx_bit_depth_t bit_depth) {
-  int i;
-  const double minqtarget = VPXMIN(((x3 * maxq + x2) * maxq + x1) * maxq,
-                                   maxq);
-
-  // Special case handling to deal with the step from q2.0
-  // down to lossless mode represented by q 1.0.
-  if (minqtarget <= 2.0)
-    return 0;
-
-  for (i = 0; i < QINDEX_RANGE; i++) {
-    if (minqtarget <= vp9_convert_qindex_to_q(i, bit_depth))
-      return i;
-  }
-
-  return QINDEX_RANGE - 1;
-}
-
-static void init_minq_luts(int *kf_low_m, int *kf_high_m,
-                           int *arfgf_low, int *arfgf_high,
-                           int *inter, int *rtc, vpx_bit_depth_t bit_depth) {
-  int i;
-  for (i = 0; i < QINDEX_RANGE; i++) {
-    const double maxq = vp9_convert_qindex_to_q(i, bit_depth);
-    kf_low_m[i] = get_minq_index(maxq, 0.000001, -0.0004, 0.150, bit_depth);
-    kf_high_m[i] = get_minq_index(maxq, 0.0000021, -0.00125, 0.55, bit_depth);
-    arfgf_low[i] = get_minq_index(maxq, 0.0000015, -0.0009, 0.30, bit_depth);
-    arfgf_high[i] = get_minq_index(maxq, 0.0000021, -0.00125, 0.55, bit_depth);
-    inter[i] = get_minq_index(maxq, 0.00000271, -0.00113, 0.70, bit_depth);
-    rtc[i] = get_minq_index(maxq, 0.00000271, -0.00113, 0.70, bit_depth);
-  }
-}
-
-void vp9_rc_init_minq_luts(void) {
-  init_minq_luts(kf_low_motion_minq_8, kf_high_motion_minq_8,
-                 arfgf_low_motion_minq_8, arfgf_high_motion_minq_8,
-                 inter_minq_8, rtc_minq_8, VPX_BITS_8);
-#if CONFIG_VP9_HIGHBITDEPTH
-  init_minq_luts(kf_low_motion_minq_10, kf_high_motion_minq_10,
-                 arfgf_low_motion_minq_10, arfgf_high_motion_minq_10,
-                 inter_minq_10, rtc_minq_10, VPX_BITS_10);
-  init_minq_luts(kf_low_motion_minq_12, kf_high_motion_minq_12,
-                 arfgf_low_motion_minq_12, arfgf_high_motion_minq_12,
-                 inter_minq_12, rtc_minq_12, VPX_BITS_12);
-#endif
-}
-
-// These functions use formulaic calculations to make playing with the
-// quantizer tables easier. If necessary they can be replaced by lookup
-// tables if and when things settle down in the experimental bitstream
-double vp9_convert_qindex_to_q(int qindex, vpx_bit_depth_t bit_depth) {
-  // Convert the index to a real Q value (scaled down to match old Q values)
-#if CONFIG_VP9_HIGHBITDEPTH
-  switch (bit_depth) {
-    case VPX_BITS_8:
-      return vp9_ac_quant(qindex, 0, bit_depth) / 4.0;
-    case VPX_BITS_10:
-      return vp9_ac_quant(qindex, 0, bit_depth) / 16.0;
-    case VPX_BITS_12:
-      return vp9_ac_quant(qindex, 0, bit_depth) / 64.0;
-    default:
-      assert(0 && "bit_depth should be VPX_BITS_8, VPX_BITS_10 or VPX_BITS_12");
-      return -1.0;
-  }
-#else
-  return vp9_ac_quant(qindex, 0, bit_depth) / 4.0;
-#endif
-}
-
-int vp9_rc_bits_per_mb(FRAME_TYPE frame_type, int qindex,
-                       double correction_factor,
-                       vpx_bit_depth_t bit_depth) {
-  const double q = vp9_convert_qindex_to_q(qindex, bit_depth);
-  int enumerator = frame_type == KEY_FRAME ? 2700000 : 1800000;
-
-  assert(correction_factor <= MAX_BPB_FACTOR &&
-         correction_factor >= MIN_BPB_FACTOR);
-
-  // q based adjustment to baseline enumerator
-  enumerator += (int)(enumerator * q) >> 12;
-  return (int)(enumerator * correction_factor / q);
-}
-
-int vp9_estimate_bits_at_q(FRAME_TYPE frame_type, int q, int mbs,
-                           double correction_factor,
-                           vpx_bit_depth_t bit_depth) {
-  const int bpm = (int)(vp9_rc_bits_per_mb(frame_type, q, correction_factor,
-                                           bit_depth));
-  return VPXMAX(FRAME_OVERHEAD_BITS,
-                (int)((uint64_t)bpm * mbs) >> BPER_MB_NORMBITS);
-}
-
-int vp9_rc_clamp_pframe_target_size(const VP9_COMP *const cpi, int target) {
-  const RATE_CONTROL *rc = &cpi->rc;
-  const VP9EncoderConfig *oxcf = &cpi->oxcf;
-  const int min_frame_target = VPXMAX(rc->min_frame_bandwidth,
-                                      rc->avg_frame_bandwidth >> 5);
-  if (target < min_frame_target)
-    target = min_frame_target;
-  if (cpi->refresh_golden_frame && rc->is_src_frame_alt_ref) {
-    // If there is an active ARF at this location use the minimum
-    // bits on this frame even if it is a constructed arf.
-    // The active maximum quantizer insures that an appropriate
-    // number of bits will be spent if needed for constructed ARFs.
-    target = min_frame_target;
-  }
-  // Clip the frame target to the maximum allowed value.
-  if (target > rc->max_frame_bandwidth)
-    target = rc->max_frame_bandwidth;
-  if (oxcf->rc_max_inter_bitrate_pct) {
-    const int max_rate = rc->avg_frame_bandwidth *
-                         oxcf->rc_max_inter_bitrate_pct / 100;
-    target = VPXMIN(target, max_rate);
-  }
-  return target;
-}
-
-int vp9_rc_clamp_iframe_target_size(const VP9_COMP *const cpi, int target) {
-  const RATE_CONTROL *rc = &cpi->rc;
-  const VP9EncoderConfig *oxcf = &cpi->oxcf;
-  if (oxcf->rc_max_intra_bitrate_pct) {
-    const int max_rate = rc->avg_frame_bandwidth *
-                             oxcf->rc_max_intra_bitrate_pct / 100;
-    target = VPXMIN(target, max_rate);
-  }
-  if (target > rc->max_frame_bandwidth)
-    target = rc->max_frame_bandwidth;
-  return target;
-}
-
-// Update the buffer level for higher temporal layers, given the encoded current
-// temporal layer.
-static void update_layer_buffer_level(SVC *svc, int encoded_frame_size) {
-  int i = 0;
-  int current_temporal_layer = svc->temporal_layer_id;
-  for (i = current_temporal_layer + 1;
-      i < svc->number_temporal_layers; ++i) {
-    const int layer = LAYER_IDS_TO_IDX(svc->spatial_layer_id, i,
-                                       svc->number_temporal_layers);
-    LAYER_CONTEXT *lc = &svc->layer_context[layer];
-    RATE_CONTROL *lrc = &lc->rc;
-    int bits_off_for_this_layer = (int)(lc->target_bandwidth / lc->framerate -
-        encoded_frame_size);
-    lrc->bits_off_target += bits_off_for_this_layer;
-
-    // Clip buffer level to maximum buffer size for the layer.
-    lrc->bits_off_target =
-        VPXMIN(lrc->bits_off_target, lrc->maximum_buffer_size);
-    lrc->buffer_level = lrc->bits_off_target;
-  }
-}
-
-// Update the buffer level: leaky bucket model.
-static void update_buffer_level(VP9_COMP *cpi, int encoded_frame_size) {
-  const VP9_COMMON *const cm = &cpi->common;
-  RATE_CONTROL *const rc = &cpi->rc;
-
-  // Non-viewable frames are a special case and are treated as pure overhead.
-  if (!cm->show_frame) {
-    rc->bits_off_target -= encoded_frame_size;
-  } else {
-    rc->bits_off_target += rc->avg_frame_bandwidth - encoded_frame_size;
-  }
-
-  // Clip the buffer level to the maximum specified buffer size.
-  rc->bits_off_target = VPXMIN(rc->bits_off_target, rc->maximum_buffer_size);
-
-  // For screen-content mode, and if frame-dropper is off, don't let buffer
-  // level go below threshold, given here as -rc->maximum_ buffer_size.
-  if (cpi->oxcf.content == VP9E_CONTENT_SCREEN &&
-      cpi->oxcf.drop_frames_water_mark == 0)
-    rc->bits_off_target = VPXMAX(rc->bits_off_target, -rc->maximum_buffer_size);
-
-  rc->buffer_level = rc->bits_off_target;
-
-  if (is_one_pass_cbr_svc(cpi)) {
-    update_layer_buffer_level(&cpi->svc, encoded_frame_size);
-  }
-}
-
-int vp9_rc_get_default_min_gf_interval(
-    int width, int height, double framerate) {
-  // Assume we do not need any constraint lower than 4K 20 fps
-  static const double factor_safe = 3840 * 2160 * 20.0;
-  const double factor = width * height * framerate;
-  const int default_interval =
-      clamp((int)(framerate * 0.125), MIN_GF_INTERVAL, MAX_GF_INTERVAL);
-
-  if (factor <= factor_safe)
-    return default_interval;
-  else
-    return VPXMAX(default_interval,
-                  (int)(MIN_GF_INTERVAL * factor / factor_safe + 0.5));
-  // Note this logic makes:
-  // 4K24: 5
-  // 4K30: 6
-  // 4K60: 12
-}
-
-int vp9_rc_get_default_max_gf_interval(double framerate, int min_gf_interval) {
-  int interval = VPXMIN(MAX_GF_INTERVAL, (int)(framerate * 0.75));
-  interval += (interval & 0x01);  // Round to even value
-  return VPXMAX(interval, min_gf_interval);
-}
-
-void vp9_rc_init(const VP9EncoderConfig *oxcf, int pass, RATE_CONTROL *rc) {
-  int i;
-
-  if (pass == 0 && oxcf->rc_mode == VPX_CBR) {
-    rc->avg_frame_qindex[KEY_FRAME] = oxcf->worst_allowed_q;
-    rc->avg_frame_qindex[INTER_FRAME] = oxcf->worst_allowed_q;
-  } else {
-    rc->avg_frame_qindex[KEY_FRAME] = (oxcf->worst_allowed_q +
-                                       oxcf->best_allowed_q) / 2;
-    rc->avg_frame_qindex[INTER_FRAME] = (oxcf->worst_allowed_q +
-                                         oxcf->best_allowed_q) / 2;
-  }
-
-  rc->last_q[KEY_FRAME] = oxcf->best_allowed_q;
-  rc->last_q[INTER_FRAME] = oxcf->worst_allowed_q;
-
-  rc->buffer_level =    rc->starting_buffer_level;
-  rc->bits_off_target = rc->starting_buffer_level;
-
-  rc->rolling_target_bits      = rc->avg_frame_bandwidth;
-  rc->rolling_actual_bits      = rc->avg_frame_bandwidth;
-  rc->long_rolling_target_bits = rc->avg_frame_bandwidth;
-  rc->long_rolling_actual_bits = rc->avg_frame_bandwidth;
-
-  rc->total_actual_bits = 0;
-  rc->total_target_bits = 0;
-  rc->total_target_vs_actual = 0;
-  rc->avg_frame_low_motion = 0;
-  rc->high_source_sad = 0;
-  rc->count_last_scene_change = 0;
-  rc->avg_source_sad = 0;
-
-  rc->frames_since_key = 8;  // Sensible default for first frame.
-  rc->this_key_frame_forced = 0;
-  rc->next_key_frame_forced = 0;
-  rc->source_alt_ref_pending = 0;
-  rc->source_alt_ref_active = 0;
-
-  rc->frames_till_gf_update_due = 0;
-  rc->ni_av_qi = oxcf->worst_allowed_q;
-  rc->ni_tot_qi = 0;
-  rc->ni_frames = 0;
-
-  rc->tot_q = 0.0;
-  rc->avg_q = vp9_convert_qindex_to_q(oxcf->worst_allowed_q, oxcf->bit_depth);
-
-  for (i = 0; i < RATE_FACTOR_LEVELS; ++i) {
-    rc->rate_correction_factors[i] = 1.0;
-  }
-
-  rc->min_gf_interval = oxcf->min_gf_interval;
-  rc->max_gf_interval = oxcf->max_gf_interval;
-  if (rc->min_gf_interval == 0)
-    rc->min_gf_interval = vp9_rc_get_default_min_gf_interval(
-        oxcf->width, oxcf->height, oxcf->init_framerate);
-  if (rc->max_gf_interval == 0)
-    rc->max_gf_interval = vp9_rc_get_default_max_gf_interval(
-        oxcf->init_framerate, rc->min_gf_interval);
-  rc->baseline_gf_interval = (rc->min_gf_interval + rc->max_gf_interval) / 2;
-}
-
-int vp9_rc_drop_frame(VP9_COMP *cpi) {
-  const VP9EncoderConfig *oxcf = &cpi->oxcf;
-  RATE_CONTROL *const rc = &cpi->rc;
-  if (!oxcf->drop_frames_water_mark ||
-      (is_one_pass_cbr_svc(cpi) &&
-       cpi->svc.spatial_layer_id > cpi->svc.first_spatial_layer_to_encode)) {
-    return 0;
-  } else {
-    if (rc->buffer_level < 0) {
-      // Always drop if buffer is below 0.
-      return 1;
-    } else {
-      // If buffer is below drop_mark, for now just drop every other frame
-      // (starting with the next frame) until it increases back over drop_mark.
-      int drop_mark = (int)(oxcf->drop_frames_water_mark *
-          rc->optimal_buffer_level / 100);
-      if ((rc->buffer_level > drop_mark) &&
-          (rc->decimation_factor > 0)) {
-        --rc->decimation_factor;
-      } else if (rc->buffer_level <= drop_mark &&
-          rc->decimation_factor == 0) {
-        rc->decimation_factor = 1;
-      }
-      if (rc->decimation_factor > 0) {
-        if (rc->decimation_count > 0) {
-          --rc->decimation_count;
-          return 1;
-        } else {
-          rc->decimation_count = rc->decimation_factor;
-          return 0;
-        }
-      } else {
-        rc->decimation_count = 0;
-        return 0;
-      }
-    }
-  }
-}
-
-static double get_rate_correction_factor(const VP9_COMP *cpi) {
-  const RATE_CONTROL *const rc = &cpi->rc;
-  double rcf;
-
-  if (cpi->common.frame_type == KEY_FRAME) {
-    rcf = rc->rate_correction_factors[KF_STD];
-  } else if (cpi->oxcf.pass == 2) {
-    RATE_FACTOR_LEVEL rf_lvl =
-      cpi->twopass.gf_group.rf_level[cpi->twopass.gf_group.index];
-    rcf = rc->rate_correction_factors[rf_lvl];
-  } else {
-    if ((cpi->refresh_alt_ref_frame || cpi->refresh_golden_frame) &&
-        !rc->is_src_frame_alt_ref && !cpi->use_svc &&
-        (cpi->oxcf.rc_mode != VPX_CBR || cpi->oxcf.gf_cbr_boost_pct > 20))
-      rcf = rc->rate_correction_factors[GF_ARF_STD];
-    else
-      rcf = rc->rate_correction_factors[INTER_NORMAL];
-  }
-  rcf *= rcf_mult[rc->frame_size_selector];
-  return fclamp(rcf, MIN_BPB_FACTOR, MAX_BPB_FACTOR);
-}
-
-static void set_rate_correction_factor(VP9_COMP *cpi, double factor) {
-  RATE_CONTROL *const rc = &cpi->rc;
-
-  // Normalize RCF to account for the size-dependent scaling factor.
-  factor /= rcf_mult[cpi->rc.frame_size_selector];
-
-  factor = fclamp(factor, MIN_BPB_FACTOR, MAX_BPB_FACTOR);
-
-  if (cpi->common.frame_type == KEY_FRAME) {
-    rc->rate_correction_factors[KF_STD] = factor;
-  } else if (cpi->oxcf.pass == 2) {
-    RATE_FACTOR_LEVEL rf_lvl =
-      cpi->twopass.gf_group.rf_level[cpi->twopass.gf_group.index];
-    rc->rate_correction_factors[rf_lvl] = factor;
-  } else {
-    if ((cpi->refresh_alt_ref_frame || cpi->refresh_golden_frame) &&
-        !rc->is_src_frame_alt_ref && !cpi->use_svc &&
-        (cpi->oxcf.rc_mode != VPX_CBR || cpi->oxcf.gf_cbr_boost_pct > 20))
-      rc->rate_correction_factors[GF_ARF_STD] = factor;
-    else
-      rc->rate_correction_factors[INTER_NORMAL] = factor;
-  }
-}
-
-void vp9_rc_update_rate_correction_factors(VP9_COMP *cpi) {
-  const VP9_COMMON *const cm = &cpi->common;
-  int correction_factor = 100;
-  double rate_correction_factor = get_rate_correction_factor(cpi);
-  double adjustment_limit;
-
-  int projected_size_based_on_q = 0;
-
-  // Do not update the rate factors for arf overlay frames.
-  if (cpi->rc.is_src_frame_alt_ref)
-    return;
-
-  // Clear down mmx registers to allow floating point in what follows
-  vpx_clear_system_state();
-
-  // Work out how big we would have expected the frame to be at this Q given
-  // the current correction factor.
-  // Stay in double to avoid int overflow when values are large
-  if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ && cpi->common.seg.enabled) {
-    projected_size_based_on_q =
-        vp9_cyclic_refresh_estimate_bits_at_q(cpi, rate_correction_factor);
-  } else {
-    projected_size_based_on_q = vp9_estimate_bits_at_q(cpi->common.frame_type,
-                                                       cm->base_qindex,
-                                                       cm->MBs,
-                                                       rate_correction_factor,
-                                                       cm->bit_depth);
-  }
-  // Work out a size correction factor.
-  if (projected_size_based_on_q > FRAME_OVERHEAD_BITS)
-    correction_factor = (int)((100 * (int64_t)cpi->rc.projected_frame_size) /
-                        projected_size_based_on_q);
-
-  // More heavily damped adjustment used if we have been oscillating either side
-  // of target.
-  adjustment_limit = 0.25 +
-      0.5 * VPXMIN(1, fabs(log10(0.01 * correction_factor)));
-
-  cpi->rc.q_2_frame = cpi->rc.q_1_frame;
-  cpi->rc.q_1_frame = cm->base_qindex;
-  cpi->rc.rc_2_frame = cpi->rc.rc_1_frame;
-  if (correction_factor > 110)
-    cpi->rc.rc_1_frame = -1;
-  else if (correction_factor < 90)
-    cpi->rc.rc_1_frame = 1;
-  else
-    cpi->rc.rc_1_frame = 0;
-
-  // Turn off oscilation detection in the case of massive overshoot.
-  if (cpi->rc.rc_1_frame == -1 && cpi->rc.rc_2_frame == 1 &&
-      correction_factor > 1000) {
-    cpi->rc.rc_2_frame = 0;
-  }
-
-  if (correction_factor > 102) {
-    // We are not already at the worst allowable quality
-    correction_factor = (int)(100 + ((correction_factor - 100) *
-                                  adjustment_limit));
-    rate_correction_factor = (rate_correction_factor * correction_factor) / 100;
-    // Keep rate_correction_factor within limits
-    if (rate_correction_factor > MAX_BPB_FACTOR)
-      rate_correction_factor = MAX_BPB_FACTOR;
-  } else if (correction_factor < 99) {
-    // We are not already at the best allowable quality
-    correction_factor = (int)(100 - ((100 - correction_factor) *
-                                  adjustment_limit));
-    rate_correction_factor = (rate_correction_factor * correction_factor) / 100;
-
-    // Keep rate_correction_factor within limits
-    if (rate_correction_factor < MIN_BPB_FACTOR)
-      rate_correction_factor = MIN_BPB_FACTOR;
-  }
-
-  set_rate_correction_factor(cpi, rate_correction_factor);
-}
-
-
-int vp9_rc_regulate_q(const VP9_COMP *cpi, int target_bits_per_frame,
-                      int active_best_quality, int active_worst_quality) {
-  const VP9_COMMON *const cm = &cpi->common;
-  int q = active_worst_quality;
-  int last_error = INT_MAX;
-  int i, target_bits_per_mb, bits_per_mb_at_this_q;
-  const double correction_factor = get_rate_correction_factor(cpi);
-
-  // Calculate required scaling factor based on target frame size and size of
-  // frame produced using previous Q.
-  target_bits_per_mb =
-      ((uint64_t)target_bits_per_frame << BPER_MB_NORMBITS) / cm->MBs;
-
-  i = active_best_quality;
-
-  do {
-    if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ &&
-        cm->seg.enabled &&
-        cpi->svc.temporal_layer_id == 0) {
-      bits_per_mb_at_this_q =
-          (int)vp9_cyclic_refresh_rc_bits_per_mb(cpi, i, correction_factor);
-    } else {
-      bits_per_mb_at_this_q = (int)vp9_rc_bits_per_mb(cm->frame_type, i,
-                                                      correction_factor,
-                                                      cm->bit_depth);
-    }
-
-    if (bits_per_mb_at_this_q <= target_bits_per_mb) {
-      if ((target_bits_per_mb - bits_per_mb_at_this_q) <= last_error)
-        q = i;
-      else
-        q = i - 1;
-
-      break;
-    } else {
-      last_error = bits_per_mb_at_this_q - target_bits_per_mb;
-    }
-  } while (++i <= active_worst_quality);
-
-  // In CBR mode, this makes sure q is between oscillating Qs to prevent
-  // resonance.
-  if (cpi->oxcf.rc_mode == VPX_CBR &&
-      (cpi->rc.rc_1_frame * cpi->rc.rc_2_frame == -1) &&
-      cpi->rc.q_1_frame != cpi->rc.q_2_frame) {
-    q = clamp(q, VPXMIN(cpi->rc.q_1_frame, cpi->rc.q_2_frame),
-              VPXMAX(cpi->rc.q_1_frame, cpi->rc.q_2_frame));
-  }
-  return q;
-}
-
-static int get_active_quality(int q, int gfu_boost, int low, int high,
-                              int *low_motion_minq, int *high_motion_minq) {
-  if (gfu_boost > high) {
-    return low_motion_minq[q];
-  } else if (gfu_boost < low) {
-    return high_motion_minq[q];
-  } else {
-    const int gap = high - low;
-    const int offset = high - gfu_boost;
-    const int qdiff = high_motion_minq[q] - low_motion_minq[q];
-    const int adjustment = ((offset * qdiff) + (gap >> 1)) / gap;
-    return low_motion_minq[q] + adjustment;
-  }
-}
-
-static int get_kf_active_quality(const RATE_CONTROL *const rc, int q,
-                                 vpx_bit_depth_t bit_depth) {
-  int *kf_low_motion_minq;
-  int *kf_high_motion_minq;
-  ASSIGN_MINQ_TABLE(bit_depth, kf_low_motion_minq);
-  ASSIGN_MINQ_TABLE(bit_depth, kf_high_motion_minq);
-  return get_active_quality(q, rc->kf_boost, kf_low, kf_high,
-                            kf_low_motion_minq, kf_high_motion_minq);
-}
-
-static int get_gf_active_quality(const RATE_CONTROL *const rc, int q,
-                                 vpx_bit_depth_t bit_depth) {
-  int *arfgf_low_motion_minq;
-  int *arfgf_high_motion_minq;
-  ASSIGN_MINQ_TABLE(bit_depth, arfgf_low_motion_minq);
-  ASSIGN_MINQ_TABLE(bit_depth, arfgf_high_motion_minq);
-  return get_active_quality(q, rc->gfu_boost, gf_low, gf_high,
-                            arfgf_low_motion_minq, arfgf_high_motion_minq);
-}
-
-static int calc_active_worst_quality_one_pass_vbr(const VP9_COMP *cpi) {
-  const RATE_CONTROL *const rc = &cpi->rc;
-  const unsigned int curr_frame = cpi->common.current_video_frame;
-  int active_worst_quality;
-
-  if (cpi->common.frame_type == KEY_FRAME) {
-    active_worst_quality = curr_frame == 0 ? rc->worst_quality
-                                           : rc->last_q[KEY_FRAME] << 1;
-  } else {
-    if (!rc->is_src_frame_alt_ref &&
-        (cpi->refresh_golden_frame || cpi->refresh_alt_ref_frame)) {
-      active_worst_quality =  curr_frame == 1 ? rc->last_q[KEY_FRAME] * 5 >> 2
-                                              : rc->last_q[INTER_FRAME];
-    } else {
-      active_worst_quality = curr_frame == 1 ? rc->last_q[KEY_FRAME] << 1 :
-          VPXMIN(rc->last_q[INTER_FRAME] << 1,
-                (rc->avg_frame_qindex[INTER_FRAME] * 3 >> 1));
-    }
-  }
-  return VPXMIN(active_worst_quality, rc->worst_quality);
-}
-
-// Adjust active_worst_quality level based on buffer level.
-static int calc_active_worst_quality_one_pass_cbr(const VP9_COMP *cpi) {
-  // Adjust active_worst_quality: If buffer is above the optimal/target level,
-  // bring active_worst_quality down depending on fullness of buffer.
-  // If buffer is below the optimal level, let the active_worst_quality go from
-  // ambient Q (at buffer = optimal level) to worst_quality level
-  // (at buffer = critical level).
-  const VP9_COMMON *const cm = &cpi->common;
-  const RATE_CONTROL *rc = &cpi->rc;
-  // Buffer level below which we push active_worst to worst_quality.
-  int64_t critical_level = rc->optimal_buffer_level >> 3;
-  int64_t buff_lvl_step = 0;
-  int adjustment = 0;
-  int active_worst_quality;
-  int ambient_qp;
-  unsigned int num_frames_weight_key = 5 * cpi->svc.number_temporal_layers;
-  if (cm->frame_type == KEY_FRAME)
-    return rc->worst_quality;
-  // For ambient_qp we use minimum of avg_frame_qindex[KEY_FRAME/INTER_FRAME]
-  // for the first few frames following key frame. These are both initialized
-  // to worst_quality and updated with (3/4, 1/4) average in postencode_update.
-  // So for first few frames following key, the qp of that key frame is weighted
-  // into the active_worst_quality setting.
-  ambient_qp = (cm->current_video_frame < num_frames_weight_key) ?
-                   VPXMIN(rc->avg_frame_qindex[INTER_FRAME],
-                          rc->avg_frame_qindex[KEY_FRAME]) :
-                   rc->avg_frame_qindex[INTER_FRAME];
-  active_worst_quality = VPXMIN(rc->worst_quality, ambient_qp * 5 >> 2);
-  if (rc->buffer_level > rc->optimal_buffer_level) {
-    // Adjust down.
-    // Maximum limit for down adjustment, ~30%.
-    int max_adjustment_down = active_worst_quality / 3;
-    if (max_adjustment_down) {
-      buff_lvl_step = ((rc->maximum_buffer_size -
-                        rc->optimal_buffer_level) / max_adjustment_down);
-      if (buff_lvl_step)
-        adjustment = (int)((rc->buffer_level - rc->optimal_buffer_level) /
-                            buff_lvl_step);
-      active_worst_quality -= adjustment;
-    }
-  } else if (rc->buffer_level > critical_level) {
-    // Adjust up from ambient Q.
-    if (critical_level) {
-      buff_lvl_step = (rc->optimal_buffer_level - critical_level);
-      if (buff_lvl_step) {
-        adjustment = (int)((rc->worst_quality - ambient_qp) *
-                           (rc->optimal_buffer_level - rc->buffer_level) /
-                           buff_lvl_step);
-      }
-      active_worst_quality = ambient_qp + adjustment;
-    }
-  } else {
-    // Set to worst_quality if buffer is below critical level.
-    active_worst_quality = rc->worst_quality;
-  }
-  return active_worst_quality;
-}
-
-static int rc_pick_q_and_bounds_one_pass_cbr(const VP9_COMP *cpi,
-                                             int *bottom_index,
-                                             int *top_index) {
-  const VP9_COMMON *const cm = &cpi->common;
-  const RATE_CONTROL *const rc = &cpi->rc;
-  int active_best_quality;
-  int active_worst_quality = calc_active_worst_quality_one_pass_cbr(cpi);
-  int q;
-  int *rtc_minq;
-  ASSIGN_MINQ_TABLE(cm->bit_depth, rtc_minq);
-
-  if (frame_is_intra_only(cm)) {
-    active_best_quality = rc->best_quality;
-    // Handle the special case for key frames forced when we have reached
-    // the maximum key frame interval. Here force the Q to a range
-    // based on the ambient Q to reduce the risk of popping.
-    if (rc->this_key_frame_forced) {
-      int qindex = rc->last_boosted_qindex;
-      double last_boosted_q = vp9_convert_qindex_to_q(qindex, cm->bit_depth);
-      int delta_qindex = vp9_compute_qdelta(rc, last_boosted_q,
-                                            (last_boosted_q * 0.75),
-                                            cm->bit_depth);
-      active_best_quality = VPXMAX(qindex + delta_qindex, rc->best_quality);
-    } else if (cm->current_video_frame > 0) {
-      // not first frame of one pass and kf_boost is set
-      double q_adj_factor = 1.0;
-      double q_val;
-
-      active_best_quality =
-          get_kf_active_quality(rc, rc->avg_frame_qindex[KEY_FRAME],
-                                cm->bit_depth);
-
-      // Allow somewhat lower kf minq with small image formats.
-      if ((cm->width * cm->height) <= (352 * 288)) {
-        q_adj_factor -= 0.25;
-      }
-
-      // Convert the adjustment factor to a qindex delta
-      // on active_best_quality.
-      q_val = vp9_convert_qindex_to_q(active_best_quality, cm->bit_depth);
-      active_best_quality += vp9_compute_qdelta(rc, q_val,
-                                                q_val * q_adj_factor,
-                                                cm->bit_depth);
-    }
-  } else if (!rc->is_src_frame_alt_ref &&
-             !cpi->use_svc &&
-             (cpi->refresh_golden_frame || cpi->refresh_alt_ref_frame)) {
-    // Use the lower of active_worst_quality and recent
-    // average Q as basis for GF/ARF best Q limit unless last frame was
-    // a key frame.
-    if (rc->frames_since_key > 1 &&
-        rc->avg_frame_qindex[INTER_FRAME] < active_worst_quality) {
-      q = rc->avg_frame_qindex[INTER_FRAME];
-    } else {
-      q = active_worst_quality;
-    }
-    active_best_quality = get_gf_active_quality(rc, q, cm->bit_depth);
-  } else {
-    // Use the lower of active_worst_quality and recent/average Q.
-    if (cm->current_video_frame > 1) {
-      if (rc->avg_frame_qindex[INTER_FRAME] < active_worst_quality)
-        active_best_quality = rtc_minq[rc->avg_frame_qindex[INTER_FRAME]];
-      else
-        active_best_quality = rtc_minq[active_worst_quality];
-    } else {
-      if (rc->avg_frame_qindex[KEY_FRAME] < active_worst_quality)
-        active_best_quality = rtc_minq[rc->avg_frame_qindex[KEY_FRAME]];
-      else
-        active_best_quality = rtc_minq[active_worst_quality];
-    }
-  }
-
-  // Clip the active best and worst quality values to limits
-  active_best_quality = clamp(active_best_quality,
-                              rc->best_quality, rc->worst_quality);
-  active_worst_quality = clamp(active_worst_quality,
-                               active_best_quality, rc->worst_quality);
-
-  *top_index = active_worst_quality;
-  *bottom_index = active_best_quality;
-
-#if LIMIT_QRANGE_FOR_ALTREF_AND_KEY
-  // Limit Q range for the adaptive loop.
-  if (cm->frame_type == KEY_FRAME &&
-      !rc->this_key_frame_forced  &&
-      !(cm->current_video_frame == 0)) {
-    int qdelta = 0;
-    vpx_clear_system_state();
-    qdelta = vp9_compute_qdelta_by_rate(&cpi->rc, cm->frame_type,
-                                        active_worst_quality, 2.0,
-                                        cm->bit_depth);
-    *top_index = active_worst_quality + qdelta;
-    *top_index = (*top_index > *bottom_index) ? *top_index : *bottom_index;
-  }
-#endif
-
-  // Special case code to try and match quality with forced key frames
-  if (cm->frame_type == KEY_FRAME && rc->this_key_frame_forced) {
-    q = rc->last_boosted_qindex;
-  } else {
-    q = vp9_rc_regulate_q(cpi, rc->this_frame_target,
-                          active_best_quality, active_worst_quality);
-    if (q > *top_index) {
-      // Special case when we are targeting the max allowed rate
-      if (rc->this_frame_target >= rc->max_frame_bandwidth)
-        *top_index = q;
-      else
-        q = *top_index;
-    }
-  }
-  assert(*top_index <= rc->worst_quality &&
-         *top_index >= rc->best_quality);
-  assert(*bottom_index <= rc->worst_quality &&
-         *bottom_index >= rc->best_quality);
-  assert(q <= rc->worst_quality && q >= rc->best_quality);
-  return q;
-}
-
-static int get_active_cq_level_one_pass(
-    const RATE_CONTROL *rc, const VP9EncoderConfig *const oxcf) {
-  static const double cq_adjust_threshold = 0.1;
-  int active_cq_level = oxcf->cq_level;
-  if (oxcf->rc_mode == VPX_CQ &&
-      rc->total_target_bits > 0) {
-    const double x = (double)rc->total_actual_bits / rc->total_target_bits;
-    if (x < cq_adjust_threshold) {
-      active_cq_level = (int)(active_cq_level * x / cq_adjust_threshold);
-    }
-  }
-  return active_cq_level;
-}
-
-#define SMOOTH_PCT_MIN  0.1
-#define SMOOTH_PCT_DIV  0.05
-static int get_active_cq_level_two_pass(
-    const TWO_PASS *twopass, const RATE_CONTROL *rc,
-    const VP9EncoderConfig *const oxcf) {
-  static const double cq_adjust_threshold = 0.1;
-  int active_cq_level = oxcf->cq_level;
-  if (oxcf->rc_mode == VPX_CQ) {
-    if (twopass->mb_smooth_pct > SMOOTH_PCT_MIN) {
-      active_cq_level -= (int)((twopass->mb_smooth_pct - SMOOTH_PCT_MIN) /
-          SMOOTH_PCT_DIV);
-      active_cq_level = VPXMAX(active_cq_level, 0);
-    }
-    if (rc->total_target_bits > 0) {
-      const double x = (double)rc->total_actual_bits / rc->total_target_bits;
-      if (x < cq_adjust_threshold) {
-        active_cq_level = (int)(active_cq_level * x / cq_adjust_threshold);
-      }
-    }
-  }
-  return active_cq_level;
-}
-
-static int rc_pick_q_and_bounds_one_pass_vbr(const VP9_COMP *cpi,
-                                             int *bottom_index,
-                                             int *top_index) {
-  const VP9_COMMON *const cm = &cpi->common;
-  const RATE_CONTROL *const rc = &cpi->rc;
-  const VP9EncoderConfig *const oxcf = &cpi->oxcf;
-  const int cq_level = get_active_cq_level_one_pass(rc, oxcf);
-  int active_best_quality;
-  int active_worst_quality = calc_active_worst_quality_one_pass_vbr(cpi);
-  int q;
-  int *inter_minq;
-  ASSIGN_MINQ_TABLE(cm->bit_depth, inter_minq);
-
-  if (frame_is_intra_only(cm)) {
-    if (oxcf->rc_mode == VPX_Q) {
-      int qindex = cq_level;
-      double q = vp9_convert_qindex_to_q(qindex, cm->bit_depth);
-      int delta_qindex = vp9_compute_qdelta(rc, q, q * 0.25,
-                                            cm->bit_depth);
-      active_best_quality = VPXMAX(qindex + delta_qindex, rc->best_quality);
-    } else if (rc->this_key_frame_forced) {
-      // Handle the special case for key frames forced when we have reached
-      // the maximum key frame interval. Here force the Q to a range
-      // based on the ambient Q to reduce the risk of popping.
-      int qindex = rc->last_boosted_qindex;
-      double last_boosted_q = vp9_convert_qindex_to_q(qindex, cm->bit_depth);
-      int delta_qindex = vp9_compute_qdelta(rc, last_boosted_q,
-                                            last_boosted_q * 0.75,
-                                            cm->bit_depth);
-      active_best_quality = VPXMAX(qindex + delta_qindex, rc->best_quality);
-    } else {
-      // not first frame of one pass and kf_boost is set
-      double q_adj_factor = 1.0;
-      double q_val;
-
-      active_best_quality =
-          get_kf_active_quality(rc, rc->avg_frame_qindex[KEY_FRAME],
-                                cm->bit_depth);
-
-      // Allow somewhat lower kf minq with small image formats.
-      if ((cm->width * cm->height) <= (352 * 288)) {
-        q_adj_factor -= 0.25;
-      }
-
-      // Convert the adjustment factor to a qindex delta
-      // on active_best_quality.
-      q_val = vp9_convert_qindex_to_q(active_best_quality, cm->bit_depth);
-      active_best_quality += vp9_compute_qdelta(rc, q_val,
-                                                q_val * q_adj_factor,
-                                                cm->bit_depth);
-    }
-  } else if (!rc->is_src_frame_alt_ref &&
-             (cpi->refresh_golden_frame || cpi->refresh_alt_ref_frame)) {
-    // Use the lower of active_worst_quality and recent
-    // average Q as basis for GF/ARF best Q limit unless last frame was
-    // a key frame.
-    if (rc->frames_since_key > 1) {
-      if (rc->avg_frame_qindex[INTER_FRAME] < active_worst_quality) {
-        q = rc->avg_frame_qindex[INTER_FRAME];
-      } else {
-        q = active_worst_quality;
-      }
-    } else {
-      q = rc->avg_frame_qindex[KEY_FRAME];
-    }
-    // For constrained quality dont allow Q less than the cq level
-    if (oxcf->rc_mode == VPX_CQ) {
-      if (q < cq_level)
-        q = cq_level;
-
-      active_best_quality = get_gf_active_quality(rc, q, cm->bit_depth);
-
-      // Constrained quality use slightly lower active best.
-      active_best_quality = active_best_quality * 15 / 16;
-
-    } else if (oxcf->rc_mode == VPX_Q) {
-      int qindex = cq_level;
-      double q = vp9_convert_qindex_to_q(qindex, cm->bit_depth);
-      int delta_qindex;
-      if (cpi->refresh_alt_ref_frame)
-        delta_qindex = vp9_compute_qdelta(rc, q, q * 0.40, cm->bit_depth);
-      else
-        delta_qindex = vp9_compute_qdelta(rc, q, q * 0.50, cm->bit_depth);
-      active_best_quality = VPXMAX(qindex + delta_qindex, rc->best_quality);
-    } else {
-      active_best_quality = get_gf_active_quality(rc, q, cm->bit_depth);
-    }
-  } else {
-    if (oxcf->rc_mode == VPX_Q) {
-      int qindex = cq_level;
-      double q = vp9_convert_qindex_to_q(qindex, cm->bit_depth);
-      double delta_rate[FIXED_GF_INTERVAL] =
-          {0.50, 1.0, 0.85, 1.0, 0.70, 1.0, 0.85, 1.0};
-      int delta_qindex =
-          vp9_compute_qdelta(rc, q,
-                             q * delta_rate[cm->current_video_frame %
-                             FIXED_GF_INTERVAL], cm->bit_depth);
-      active_best_quality = VPXMAX(qindex + delta_qindex, rc->best_quality);
-    } else {
-      // Use the min of the average Q and active_worst_quality as basis for
-      // active_best.
-      if (cm->current_video_frame > 1) {
-        q = VPXMIN(rc->avg_frame_qindex[INTER_FRAME], active_worst_quality);
-        active_best_quality = inter_minq[q];
-      } else {
-        active_best_quality = inter_minq[rc->avg_frame_qindex[KEY_FRAME]];
-      }
-      // For the constrained quality mode we don't want
-      // q to fall below the cq level.
-      if ((oxcf->rc_mode == VPX_CQ) &&
-          (active_best_quality < cq_level)) {
-        active_best_quality = cq_level;
-      }
-    }
-  }
-
-  // Clip the active best and worst quality values to limits
-  active_best_quality = clamp(active_best_quality,
-                              rc->best_quality, rc->worst_quality);
-  active_worst_quality = clamp(active_worst_quality,
-                               active_best_quality, rc->worst_quality);
-
-  *top_index = active_worst_quality;
-  *bottom_index = active_best_quality;
-
-#if LIMIT_QRANGE_FOR_ALTREF_AND_KEY
-  {
-    int qdelta = 0;
-    vpx_clear_system_state();
-
-    // Limit Q range for the adaptive loop.
-    if (cm->frame_type == KEY_FRAME &&
-        !rc->this_key_frame_forced &&
-        !(cm->current_video_frame == 0)) {
-      qdelta = vp9_compute_qdelta_by_rate(&cpi->rc, cm->frame_type,
-                                          active_worst_quality, 2.0,
-                                          cm->bit_depth);
-    } else if (!rc->is_src_frame_alt_ref &&
-               (cpi->refresh_golden_frame || cpi->refresh_alt_ref_frame)) {
-      qdelta = vp9_compute_qdelta_by_rate(&cpi->rc, cm->frame_type,
-                                          active_worst_quality, 1.75,
-                                          cm->bit_depth);
-    }
-    *top_index = active_worst_quality + qdelta;
-    *top_index = (*top_index > *bottom_index) ? *top_index : *bottom_index;
-  }
-#endif
-
-  if (oxcf->rc_mode == VPX_Q) {
-    q = active_best_quality;
-  // Special case code to try and match quality with forced key frames
-  } else if ((cm->frame_type == KEY_FRAME) && rc->this_key_frame_forced) {
-    q = rc->last_boosted_qindex;
-  } else {
-    q = vp9_rc_regulate_q(cpi, rc->this_frame_target,
-                          active_best_quality, active_worst_quality);
-    if (q > *top_index) {
-      // Special case when we are targeting the max allowed rate
-      if (rc->this_frame_target >= rc->max_frame_bandwidth)
-        *top_index = q;
-      else
-        q = *top_index;
-    }
-  }
-
-  assert(*top_index <= rc->worst_quality &&
-         *top_index >= rc->best_quality);
-  assert(*bottom_index <= rc->worst_quality &&
-         *bottom_index >= rc->best_quality);
-  assert(q <= rc->worst_quality && q >= rc->best_quality);
-  return q;
-}
-
-int vp9_frame_type_qdelta(const VP9_COMP *cpi, int rf_level, int q) {
-  static const double rate_factor_deltas[RATE_FACTOR_LEVELS] = {
-    1.00,  // INTER_NORMAL
-    1.00,  // INTER_HIGH
-    1.50,  // GF_ARF_LOW
-    1.75,  // GF_ARF_STD
-    2.00,  // KF_STD
-  };
-  static const FRAME_TYPE frame_type[RATE_FACTOR_LEVELS] =
-      {INTER_FRAME, INTER_FRAME, INTER_FRAME, INTER_FRAME, KEY_FRAME};
-  const VP9_COMMON *const cm = &cpi->common;
-  int qdelta = vp9_compute_qdelta_by_rate(&cpi->rc, frame_type[rf_level],
-                                          q, rate_factor_deltas[rf_level],
-                                          cm->bit_depth);
-  return qdelta;
-}
-
-#define STATIC_MOTION_THRESH 95
-static int rc_pick_q_and_bounds_two_pass(const VP9_COMP *cpi,
-                                         int *bottom_index,
-                                         int *top_index) {
-  const VP9_COMMON *const cm = &cpi->common;
-  const RATE_CONTROL *const rc = &cpi->rc;
-  const VP9EncoderConfig *const oxcf = &cpi->oxcf;
-  const GF_GROUP *gf_group = &cpi->twopass.gf_group;
-  const int cq_level = get_active_cq_level_two_pass(&cpi->twopass, rc, oxcf);
-  int active_best_quality;
-  int active_worst_quality = cpi->twopass.active_worst_quality;
-  int q;
-  int *inter_minq;
-  ASSIGN_MINQ_TABLE(cm->bit_depth, inter_minq);
-
-  if (frame_is_intra_only(cm) || vp9_is_upper_layer_key_frame(cpi)) {
-    // Handle the special case for key frames forced when we have reached
-    // the maximum key frame interval. Here force the Q to a range
-    // based on the ambient Q to reduce the risk of popping.
-    if (rc->this_key_frame_forced) {
-      double last_boosted_q;
-      int delta_qindex;
-      int qindex;
-
-      if (cpi->twopass.last_kfgroup_zeromotion_pct >= STATIC_MOTION_THRESH) {
-        qindex = VPXMIN(rc->last_kf_qindex, rc->last_boosted_qindex);
-        active_best_quality = qindex;
-        last_boosted_q = vp9_convert_qindex_to_q(qindex, cm->bit_depth);
-        delta_qindex = vp9_compute_qdelta(rc, last_boosted_q,
-                                              last_boosted_q * 1.25,
-                                              cm->bit_depth);
-        active_worst_quality =
-            VPXMIN(qindex + delta_qindex, active_worst_quality);
-      } else {
-        qindex = rc->last_boosted_qindex;
-        last_boosted_q = vp9_convert_qindex_to_q(qindex, cm->bit_depth);
-        delta_qindex = vp9_compute_qdelta(rc, last_boosted_q,
-                                              last_boosted_q * 0.75,
-                                              cm->bit_depth);
-        active_best_quality = VPXMAX(qindex + delta_qindex, rc->best_quality);
-      }
-    } else {
-      // Not forced keyframe.
-      double q_adj_factor = 1.0;
-      double q_val;
-      // Baseline value derived from cpi->active_worst_quality and kf boost.
-      active_best_quality = get_kf_active_quality(rc, active_worst_quality,
-                                                  cm->bit_depth);
-
-      // Allow somewhat lower kf minq with small image formats.
-      if ((cm->width * cm->height) <= (352 * 288)) {
-        q_adj_factor -= 0.25;
-      }
-
-      // Make a further adjustment based on the kf zero motion measure.
-      q_adj_factor += 0.05 - (0.001 * (double)cpi->twopass.kf_zeromotion_pct);
-
-      // Convert the adjustment factor to a qindex delta
-      // on active_best_quality.
-      q_val = vp9_convert_qindex_to_q(active_best_quality, cm->bit_depth);
-      active_best_quality += vp9_compute_qdelta(rc, q_val,
-                                                q_val * q_adj_factor,
-                                                cm->bit_depth);
-    }
-  } else if (!rc->is_src_frame_alt_ref &&
-             (cpi->refresh_golden_frame || cpi->refresh_alt_ref_frame)) {
-    // Use the lower of active_worst_quality and recent
-    // average Q as basis for GF/ARF best Q limit unless last frame was
-    // a key frame.
-    if (rc->frames_since_key > 1 &&
-        rc->avg_frame_qindex[INTER_FRAME] < active_worst_quality) {
-      q = rc->avg_frame_qindex[INTER_FRAME];
-    } else {
-      q = active_worst_quality;
-    }
-    // For constrained quality dont allow Q less than the cq level
-    if (oxcf->rc_mode == VPX_CQ) {
-      if (q < cq_level)
-        q = cq_level;
-
-      active_best_quality = get_gf_active_quality(rc, q, cm->bit_depth);
-
-      // Constrained quality use slightly lower active best.
-      active_best_quality = active_best_quality * 15 / 16;
-
-    } else if (oxcf->rc_mode == VPX_Q) {
-      if (!cpi->refresh_alt_ref_frame) {
-        active_best_quality = cq_level;
-      } else {
-        active_best_quality = get_gf_active_quality(rc, q, cm->bit_depth);
-
-        // Modify best quality for second level arfs. For mode VPX_Q this
-        // becomes the baseline frame q.
-        if (gf_group->rf_level[gf_group->index] == GF_ARF_LOW)
-          active_best_quality = (active_best_quality + cq_level + 1) / 2;
-      }
-    } else {
-      active_best_quality = get_gf_active_quality(rc, q, cm->bit_depth);
-    }
-  } else {
-    if (oxcf->rc_mode == VPX_Q) {
-      active_best_quality = cq_level;
-    } else {
-      active_best_quality = inter_minq[active_worst_quality];
-
-      // For the constrained quality mode we don't want
-      // q to fall below the cq level.
-      if ((oxcf->rc_mode == VPX_CQ) &&
-          (active_best_quality < cq_level)) {
-        active_best_quality = cq_level;
-      }
-    }
-  }
-
-  // Extension to max or min Q if undershoot or overshoot is outside
-  // the permitted range.
-  if (cpi->oxcf.rc_mode != VPX_Q) {
-    if (frame_is_intra_only(cm) ||
-        (!rc->is_src_frame_alt_ref &&
-         (cpi->refresh_golden_frame || cpi->refresh_alt_ref_frame))) {
-      active_best_quality -=
-        (cpi->twopass.extend_minq + cpi->twopass.extend_minq_fast);
-      active_worst_quality += (cpi->twopass.extend_maxq / 2);
-    } else {
-      active_best_quality -=
-        (cpi->twopass.extend_minq + cpi->twopass.extend_minq_fast) / 2;
-      active_worst_quality += cpi->twopass.extend_maxq;
-    }
-  }
-
-#if LIMIT_QRANGE_FOR_ALTREF_AND_KEY
-  vpx_clear_system_state();
-  // Static forced key frames Q restrictions dealt with elsewhere.
-  if (!((frame_is_intra_only(cm) || vp9_is_upper_layer_key_frame(cpi))) ||
-      !rc->this_key_frame_forced ||
-      (cpi->twopass.last_kfgroup_zeromotion_pct < STATIC_MOTION_THRESH)) {
-    int qdelta = vp9_frame_type_qdelta(cpi, gf_group->rf_level[gf_group->index],
-                                       active_worst_quality);
-    active_worst_quality = VPXMAX(active_worst_quality + qdelta,
-                                  active_best_quality);
-  }
-#endif
-
-  // Modify active_best_quality for downscaled normal frames.
-  if (rc->frame_size_selector != UNSCALED && !frame_is_kf_gf_arf(cpi)) {
-    int qdelta = vp9_compute_qdelta_by_rate(rc, cm->frame_type,
-                                            active_best_quality, 2.0,
-                                            cm->bit_depth);
-    active_best_quality =
-        VPXMAX(active_best_quality + qdelta, rc->best_quality);
-  }
-
-  active_best_quality = clamp(active_best_quality,
-                              rc->best_quality, rc->worst_quality);
-  active_worst_quality = clamp(active_worst_quality,
-                               active_best_quality, rc->worst_quality);
-
-  if (oxcf->rc_mode == VPX_Q) {
-    q = active_best_quality;
-  // Special case code to try and match quality with forced key frames.
-  } else if ((frame_is_intra_only(cm) || vp9_is_upper_layer_key_frame(cpi)) &&
-             rc->this_key_frame_forced) {
-    // If static since last kf use better of last boosted and last kf q.
-    if (cpi->twopass.last_kfgroup_zeromotion_pct >= STATIC_MOTION_THRESH) {
-      q = VPXMIN(rc->last_kf_qindex, rc->last_boosted_qindex);
-    } else {
-      q = rc->last_boosted_qindex;
-    }
-  } else {
-    q = vp9_rc_regulate_q(cpi, rc->this_frame_target,
-                          active_best_quality, active_worst_quality);
-    if (q > active_worst_quality) {
-      // Special case when we are targeting the max allowed rate.
-      if (rc->this_frame_target >= rc->max_frame_bandwidth)
-        active_worst_quality = q;
-      else
-        q = active_worst_quality;
-    }
-  }
-  clamp(q, active_best_quality, active_worst_quality);
-
-  *top_index = active_worst_quality;
-  *bottom_index = active_best_quality;
-
-  assert(*top_index <= rc->worst_quality &&
-         *top_index >= rc->best_quality);
-  assert(*bottom_index <= rc->worst_quality &&
-         *bottom_index >= rc->best_quality);
-  assert(q <= rc->worst_quality && q >= rc->best_quality);
-  return q;
-}
-
-int vp9_rc_pick_q_and_bounds(const VP9_COMP *cpi,
-                             int *bottom_index, int *top_index) {
-  int q;
-  if (cpi->oxcf.pass == 0) {
-    if (cpi->oxcf.rc_mode == VPX_CBR)
-      q = rc_pick_q_and_bounds_one_pass_cbr(cpi, bottom_index, top_index);
-    else
-      q = rc_pick_q_and_bounds_one_pass_vbr(cpi, bottom_index, top_index);
-  } else {
-    q = rc_pick_q_and_bounds_two_pass(cpi, bottom_index, top_index);
-  }
-  if (cpi->sf.use_nonrd_pick_mode) {
-    if (cpi->sf.force_frame_boost == 1)
-      q -= cpi->sf.max_delta_qindex;
-
-    if (q < *bottom_index)
-      *bottom_index = q;
-    else if (q > *top_index)
-      *top_index = q;
-  }
-  return q;
-}
-
-void vp9_rc_compute_frame_size_bounds(const VP9_COMP *cpi,
-                                      int frame_target,
-                                      int *frame_under_shoot_limit,
-                                      int *frame_over_shoot_limit) {
-  if (cpi->oxcf.rc_mode == VPX_Q) {
-    *frame_under_shoot_limit = 0;
-    *frame_over_shoot_limit  = INT_MAX;
-  } else {
-    // For very small rate targets where the fractional adjustment
-    // may be tiny make sure there is at least a minimum range.
-    const int tolerance = (cpi->sf.recode_tolerance * frame_target) / 100;
-    *frame_under_shoot_limit = VPXMAX(frame_target - tolerance - 200, 0);
-    *frame_over_shoot_limit = VPXMIN(frame_target + tolerance + 200,
-                                     cpi->rc.max_frame_bandwidth);
-  }
-}
-
-void vp9_rc_set_frame_target(VP9_COMP *cpi, int target) {
-  const VP9_COMMON *const cm = &cpi->common;
-  RATE_CONTROL *const rc = &cpi->rc;
-
-  rc->this_frame_target = target;
-
-  // Modify frame size target when down-scaling.
-  if (cpi->oxcf.resize_mode == RESIZE_DYNAMIC &&
-      rc->frame_size_selector != UNSCALED)
-    rc->this_frame_target = (int)(rc->this_frame_target
-        * rate_thresh_mult[rc->frame_size_selector]);
-
-  // Target rate per SB64 (including partial SB64s.
-  rc->sb64_target_rate = ((int64_t)rc->this_frame_target * 64 * 64) /
-                             (cm->width * cm->height);
-}
-
-static void update_alt_ref_frame_stats(VP9_COMP *cpi) {
-  // this frame refreshes means next frames don't unless specified by user
-  RATE_CONTROL *const rc = &cpi->rc;
-  rc->frames_since_golden = 0;
-
-  // Mark the alt ref as done (setting to 0 means no further alt refs pending).
-  rc->source_alt_ref_pending = 0;
-
-  // Set the alternate reference frame active flag
-  rc->source_alt_ref_active = 1;
-}
-
-static void update_golden_frame_stats(VP9_COMP *cpi) {
-  RATE_CONTROL *const rc = &cpi->rc;
-
-  // Update the Golden frame usage counts.
-  if (cpi->refresh_golden_frame) {
-    // this frame refreshes means next frames don't unless specified by user
-    rc->frames_since_golden = 0;
-
-    // If we are not using alt ref in the up and coming group clear the arf
-    // active flag. In multi arf group case, if the index is not 0 then
-    // we are overlaying a mid group arf so should not reset the flag.
-    if (cpi->oxcf.pass == 2) {
-      if (!rc->source_alt_ref_pending && (cpi->twopass.gf_group.index == 0))
-        rc->source_alt_ref_active = 0;
-    } else if (!rc->source_alt_ref_pending) {
-      rc->source_alt_ref_active = 0;
-    }
-
-    // Decrement count down till next gf
-    if (rc->frames_till_gf_update_due > 0)
-      rc->frames_till_gf_update_due--;
-
-  } else if (!cpi->refresh_alt_ref_frame) {
-    // Decrement count down till next gf
-    if (rc->frames_till_gf_update_due > 0)
-      rc->frames_till_gf_update_due--;
-
-    rc->frames_since_golden++;
-  }
-}
-
-static void compute_frame_low_motion(VP9_COMP *const cpi) {
-  VP9_COMMON *const cm = &cpi->common;
-  int mi_row, mi_col;
-  MODE_INFO **mi = cm->mi_grid_visible;
-  RATE_CONTROL *const rc = &cpi->rc;
-  const int rows = cm->mi_rows, cols = cm->mi_cols;
-  int cnt_zeromv = 0;
-  for (mi_row = 0; mi_row < rows; mi_row++) {
-    for (mi_col = 0; mi_col < cols; mi_col++) {
-      if (abs(mi[0]->mv[0].as_mv.row) < 16 &&
-          abs(mi[0]->mv[0].as_mv.col) < 16)
-        cnt_zeromv++;
-      mi++;
-    }
-    mi += 8;
-  }
-  cnt_zeromv = 100 * cnt_zeromv / (rows * cols);
-  rc->avg_frame_low_motion = (3 * rc->avg_frame_low_motion + cnt_zeromv) >> 2;
-}
-
-void vp9_rc_postencode_update(VP9_COMP *cpi, uint64_t bytes_used) {
-  const VP9_COMMON *const cm = &cpi->common;
-  const VP9EncoderConfig *const oxcf = &cpi->oxcf;
-  RATE_CONTROL *const rc = &cpi->rc;
-  const int qindex = cm->base_qindex;
-
-  if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ && cm->seg.enabled) {
-    vp9_cyclic_refresh_postencode(cpi);
-  }
-
-  // Update rate control heuristics
-  rc->projected_frame_size = (int)(bytes_used << 3);
-
-  // Post encode loop adjustment of Q prediction.
-  vp9_rc_update_rate_correction_factors(cpi);
-
-  // Keep a record of last Q and ambient average Q.
-  if (cm->frame_type == KEY_FRAME) {
-    rc->last_q[KEY_FRAME] = qindex;
-    rc->avg_frame_qindex[KEY_FRAME] =
-        ROUND_POWER_OF_TWO(3 * rc->avg_frame_qindex[KEY_FRAME] + qindex, 2);
-    if (cpi->use_svc) {
-      int i = 0;
-      SVC *svc = &cpi->svc;
-      for (i = 0; i < svc->number_temporal_layers; ++i) {
-        const int layer = LAYER_IDS_TO_IDX(svc->spatial_layer_id, i,
-                                           svc->number_temporal_layers);
-        LAYER_CONTEXT *lc = &svc->layer_context[layer];
-        RATE_CONTROL *lrc = &lc->rc;
-        lrc->last_q[KEY_FRAME] = rc->last_q[KEY_FRAME];
-        lrc->avg_frame_qindex[KEY_FRAME] = rc->avg_frame_qindex[KEY_FRAME];
-      }
-    }
-  } else {
-    if ((cpi->use_svc && oxcf->rc_mode == VPX_CBR) ||
-        (!rc->is_src_frame_alt_ref &&
-         !(cpi->refresh_golden_frame || cpi->refresh_alt_ref_frame))) {
-      rc->last_q[INTER_FRAME] = qindex;
-      rc->avg_frame_qindex[INTER_FRAME] =
-        ROUND_POWER_OF_TWO(3 * rc->avg_frame_qindex[INTER_FRAME] + qindex, 2);
-      rc->ni_frames++;
-      rc->tot_q += vp9_convert_qindex_to_q(qindex, cm->bit_depth);
-      rc->avg_q = rc->tot_q / rc->ni_frames;
-      // Calculate the average Q for normal inter frames (not key or GFU
-      // frames).
-      rc->ni_tot_qi += qindex;
-      rc->ni_av_qi = rc->ni_tot_qi / rc->ni_frames;
-    }
-  }
-
-  // Keep record of last boosted (KF/KF/ARF) Q value.
-  // If the current frame is coded at a lower Q then we also update it.
-  // If all mbs in this group are skipped only update if the Q value is
-  // better than that already stored.
-  // This is used to help set quality in forced key frames to reduce popping
-  if ((qindex < rc->last_boosted_qindex) ||
-      (cm->frame_type == KEY_FRAME) ||
-      (!rc->constrained_gf_group &&
-       (cpi->refresh_alt_ref_frame ||
-        (cpi->refresh_golden_frame && !rc->is_src_frame_alt_ref)))) {
-    rc->last_boosted_qindex = qindex;
-  }
-  if (cm->frame_type == KEY_FRAME)
-    rc->last_kf_qindex = qindex;
-
-  update_buffer_level(cpi, rc->projected_frame_size);
-
-  // Rolling monitors of whether we are over or underspending used to help
-  // regulate min and Max Q in two pass.
-  if (cm->frame_type != KEY_FRAME) {
-    rc->rolling_target_bits = ROUND_POWER_OF_TWO(
-        rc->rolling_target_bits * 3 + rc->this_frame_target, 2);
-    rc->rolling_actual_bits = ROUND_POWER_OF_TWO(
-        rc->rolling_actual_bits * 3 + rc->projected_frame_size, 2);
-    rc->long_rolling_target_bits = ROUND_POWER_OF_TWO(
-        rc->long_rolling_target_bits * 31 + rc->this_frame_target, 5);
-    rc->long_rolling_actual_bits = ROUND_POWER_OF_TWO(
-        rc->long_rolling_actual_bits * 31 + rc->projected_frame_size, 5);
-  }
-
-  // Actual bits spent
-  rc->total_actual_bits += rc->projected_frame_size;
-  rc->total_target_bits += cm->show_frame ? rc->avg_frame_bandwidth : 0;
-
-  rc->total_target_vs_actual = rc->total_actual_bits - rc->total_target_bits;
-
-  if (!cpi->use_svc || is_two_pass_svc(cpi)) {
-    if (is_altref_enabled(cpi) && cpi->refresh_alt_ref_frame &&
-        (cm->frame_type != KEY_FRAME))
-      // Update the alternate reference frame stats as appropriate.
-      update_alt_ref_frame_stats(cpi);
-    else
-      // Update the Golden frame stats as appropriate.
-      update_golden_frame_stats(cpi);
-  }
-
-  if (cm->frame_type == KEY_FRAME)
-    rc->frames_since_key = 0;
-  if (cm->show_frame) {
-    rc->frames_since_key++;
-    rc->frames_to_key--;
-  }
-
-  // Trigger the resizing of the next frame if it is scaled.
-  if (oxcf->pass != 0) {
-    cpi->resize_pending =
-        rc->next_frame_size_selector != rc->frame_size_selector;
-    rc->frame_size_selector = rc->next_frame_size_selector;
-  }
-
-  if (oxcf->pass == 0) {
-    if (cm->frame_type != KEY_FRAME)
-      compute_frame_low_motion(cpi);
-  }
-}
-
-void vp9_rc_postencode_update_drop_frame(VP9_COMP *cpi) {
-  // Update buffer level with zero size, update frame counters, and return.
-  update_buffer_level(cpi, 0);
-  cpi->rc.frames_since_key++;
-  cpi->rc.frames_to_key--;
-  cpi->rc.rc_2_frame = 0;
-  cpi->rc.rc_1_frame = 0;
-}
-
-// Use this macro to turn on/off use of alt-refs in one-pass mode.
-#define USE_ALTREF_FOR_ONE_PASS   1
-
-static int calc_pframe_target_size_one_pass_vbr(const VP9_COMP *const cpi) {
-  static const int af_ratio = 10;
-  const RATE_CONTROL *const rc = &cpi->rc;
-  int target;
-#if USE_ALTREF_FOR_ONE_PASS
-  target = (!rc->is_src_frame_alt_ref &&
-            (cpi->refresh_golden_frame || cpi->refresh_alt_ref_frame)) ?
-      (rc->avg_frame_bandwidth * rc->baseline_gf_interval * af_ratio) /
-      (rc->baseline_gf_interval + af_ratio - 1) :
-      (rc->avg_frame_bandwidth * rc->baseline_gf_interval) /
-      (rc->baseline_gf_interval + af_ratio - 1);
-#else
-  target = rc->avg_frame_bandwidth;
-#endif
-  return vp9_rc_clamp_pframe_target_size(cpi, target);
-}
-
-static int calc_iframe_target_size_one_pass_vbr(const VP9_COMP *const cpi) {
-  static const int kf_ratio = 25;
-  const RATE_CONTROL *rc = &cpi->rc;
-  const int target = rc->avg_frame_bandwidth * kf_ratio;
-  return vp9_rc_clamp_iframe_target_size(cpi, target);
-}
-
-static void adjust_gf_key_frame(VP9_COMP *cpi) {
-  RATE_CONTROL *const rc = &cpi->rc;
-  rc->constrained_gf_group = 0;
-  // Reset gf interval to make more equal spacing for up-coming key frame.
-  if ((rc->frames_to_key <= 7 * rc->baseline_gf_interval >> 2) &&
-      (rc->frames_to_key > rc->baseline_gf_interval)) {
-    rc->baseline_gf_interval = rc->frames_to_key >> 1;
-    if (rc->baseline_gf_interval < 5)
-      rc->baseline_gf_interval = rc->frames_to_key;
-    rc->constrained_gf_group = 1;
-  } else {
-    // Reset since frames_till_gf_update_due must be <= frames_to_key.
-    if (rc->baseline_gf_interval > rc->frames_to_key) {
-      rc->baseline_gf_interval = rc->frames_to_key;
-      rc->constrained_gf_group = 1;
-    }
-  }
-}
-void vp9_rc_get_one_pass_vbr_params(VP9_COMP *cpi) {
-  VP9_COMMON *const cm = &cpi->common;
-  RATE_CONTROL *const rc = &cpi->rc;
-  int target;
-  // TODO(yaowu): replace the "auto_key && 0" below with proper decision logic.
-  if (!cpi->refresh_alt_ref_frame &&
-      (cm->current_video_frame == 0 ||
-       (cpi->frame_flags & FRAMEFLAGS_KEY) ||
-       rc->frames_to_key == 0 ||
-       (cpi->oxcf.auto_key && 0))) {
-    cm->frame_type = KEY_FRAME;
-    rc->this_key_frame_forced = cm->current_video_frame != 0 &&
-                                rc->frames_to_key == 0;
-    rc->frames_to_key = cpi->oxcf.key_freq;
-    rc->kf_boost = DEFAULT_KF_BOOST;
-    rc->source_alt_ref_active = 0;
-  } else {
-    cm->frame_type = INTER_FRAME;
-  }
-  if (rc->frames_till_gf_update_due == 0) {
-    double rate_err = 1.0;
-    rc->gfu_boost = DEFAULT_GF_BOOST;
-    if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ && cpi->oxcf.pass == 0) {
-      vp9_cyclic_refresh_set_golden_update(cpi);
-    } else {
-      rc->baseline_gf_interval =
-          (rc->min_gf_interval + rc->max_gf_interval) / 2;
-    }
-    if (rc->rolling_target_bits > 0)
-      rate_err =
-          (double)rc->rolling_actual_bits / (double)rc->rolling_target_bits;
-    // Increase gf interval at high Q and high overshoot.
-    if (cm->current_video_frame > 30 &&
-        rc->avg_frame_qindex[INTER_FRAME] > (7 * rc->worst_quality) >> 3 &&
-        rate_err > 3.5) {
-      rc->baseline_gf_interval =
-          VPXMIN(15, (3 * rc->baseline_gf_interval) >> 1);
-    } else if (cm->current_video_frame > 30 &&
-               rc->avg_frame_low_motion < 20) {
-      // Decrease boost and gf interval for high motion case.
-      rc->gfu_boost = DEFAULT_GF_BOOST >> 1;
-      rc->baseline_gf_interval = VPXMAX(5, rc->baseline_gf_interval >> 1);
-    }
-    adjust_gf_key_frame(cpi);
-    rc->frames_till_gf_update_due = rc->baseline_gf_interval;
-    cpi->refresh_golden_frame = 1;
-    rc->source_alt_ref_pending = USE_ALTREF_FOR_ONE_PASS;
-  }
-  if (cm->frame_type == KEY_FRAME)
-    target = calc_iframe_target_size_one_pass_vbr(cpi);
-  else
-    target = calc_pframe_target_size_one_pass_vbr(cpi);
-  vp9_rc_set_frame_target(cpi, target);
-  if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ && cpi->oxcf.pass == 0)
-    vp9_cyclic_refresh_update_parameters(cpi);
-}
-
-static int calc_pframe_target_size_one_pass_cbr(const VP9_COMP *cpi) {
-  const VP9EncoderConfig *oxcf = &cpi->oxcf;
-  const RATE_CONTROL *rc = &cpi->rc;
-  const SVC *const svc = &cpi->svc;
-  const int64_t diff = rc->optimal_buffer_level - rc->buffer_level;
-  const int64_t one_pct_bits = 1 + rc->optimal_buffer_level / 100;
-  int min_frame_target =
-      VPXMAX(rc->avg_frame_bandwidth >> 4, FRAME_OVERHEAD_BITS);
-  int target;
-
-  if (oxcf->gf_cbr_boost_pct) {
-    const int af_ratio_pct = oxcf->gf_cbr_boost_pct + 100;
-    target =  cpi->refresh_golden_frame ?
-      (rc->avg_frame_bandwidth * rc->baseline_gf_interval * af_ratio_pct) /
-      (rc->baseline_gf_interval * 100 + af_ratio_pct - 100) :
-      (rc->avg_frame_bandwidth * rc->baseline_gf_interval * 100) /
-      (rc->baseline_gf_interval * 100 + af_ratio_pct - 100);
-  } else {
-    target = rc->avg_frame_bandwidth;
-  }
-  if (is_one_pass_cbr_svc(cpi)) {
-    // Note that for layers, avg_frame_bandwidth is the cumulative
-    // per-frame-bandwidth. For the target size of this frame, use the
-    // layer average frame size (i.e., non-cumulative per-frame-bw).
-    int layer =
-        LAYER_IDS_TO_IDX(svc->spatial_layer_id,
-            svc->temporal_layer_id, svc->number_temporal_layers);
-    const LAYER_CONTEXT *lc = &svc->layer_context[layer];
-    target = lc->avg_frame_size;
-    min_frame_target = VPXMAX(lc->avg_frame_size >> 4, FRAME_OVERHEAD_BITS);
-  }
-  if (diff > 0) {
-    // Lower the target bandwidth for this frame.
-    const int pct_low = (int)VPXMIN(diff / one_pct_bits, oxcf->under_shoot_pct);
-    target -= (target * pct_low) / 200;
-  } else if (diff < 0) {
-    // Increase the target bandwidth for this frame.
-    const int pct_high =
-        (int)VPXMIN(-diff / one_pct_bits, oxcf->over_shoot_pct);
-    target += (target * pct_high) / 200;
-  }
-  if (oxcf->rc_max_inter_bitrate_pct) {
-    const int max_rate = rc->avg_frame_bandwidth *
-                         oxcf->rc_max_inter_bitrate_pct / 100;
-    target = VPXMIN(target, max_rate);
-  }
-  return VPXMAX(min_frame_target, target);
-}
-
-static int calc_iframe_target_size_one_pass_cbr(const VP9_COMP *cpi) {
-  const RATE_CONTROL *rc = &cpi->rc;
-  const VP9EncoderConfig *oxcf = &cpi->oxcf;
-  const SVC *const svc = &cpi->svc;
-  int target;
-  if (cpi->common.current_video_frame == 0) {
-    target = ((rc->starting_buffer_level / 2) > INT_MAX)
-      ? INT_MAX : (int)(rc->starting_buffer_level / 2);
-  } else {
-    int kf_boost = 32;
-    double framerate = cpi->framerate;
-    if (svc->number_temporal_layers > 1 &&
-        oxcf->rc_mode == VPX_CBR) {
-      // Use the layer framerate for temporal layers CBR mode.
-      const int layer = LAYER_IDS_TO_IDX(svc->spatial_layer_id,
-          svc->temporal_layer_id, svc->number_temporal_layers);
-      const LAYER_CONTEXT *lc = &svc->layer_context[layer];
-      framerate = lc->framerate;
-    }
-    kf_boost = VPXMAX(kf_boost, (int)(2 * framerate - 16));
-    if (rc->frames_since_key <  framerate / 2) {
-      kf_boost = (int)(kf_boost * rc->frames_since_key /
-                       (framerate / 2));
-    }
-    target = ((16 + kf_boost) * rc->avg_frame_bandwidth) >> 4;
-  }
-  return vp9_rc_clamp_iframe_target_size(cpi, target);
-}
-
-void vp9_rc_get_svc_params(VP9_COMP *cpi) {
-  VP9_COMMON *const cm = &cpi->common;
-  RATE_CONTROL *const rc = &cpi->rc;
-  int target = rc->avg_frame_bandwidth;
-  int layer = LAYER_IDS_TO_IDX(cpi->svc.spatial_layer_id,
-      cpi->svc.temporal_layer_id, cpi->svc.number_temporal_layers);
-  // Periodic key frames is based on the super-frame counter
-  // (svc.current_superframe), also only base spatial layer is key frame.
-  if ((cm->current_video_frame == 0) ||
-      (cpi->frame_flags & FRAMEFLAGS_KEY) ||
-      (cpi->oxcf.auto_key &&
-       (cpi->svc.current_superframe % cpi->oxcf.key_freq == 0) &&
-       cpi->svc.spatial_layer_id == 0)) {
-    cm->frame_type = KEY_FRAME;
-    rc->source_alt_ref_active = 0;
-    if (is_two_pass_svc(cpi)) {
-      cpi->svc.layer_context[layer].is_key_frame = 1;
-      cpi->ref_frame_flags &=
-          (~VP9_LAST_FLAG & ~VP9_GOLD_FLAG & ~VP9_ALT_FLAG);
-    } else if (is_one_pass_cbr_svc(cpi)) {
-      if (cm->current_video_frame > 0)
-        vp9_svc_reset_key_frame(cpi);
-      layer = LAYER_IDS_TO_IDX(cpi->svc.spatial_layer_id,
-           cpi->svc.temporal_layer_id, cpi->svc.number_temporal_layers);
-      cpi->svc.layer_context[layer].is_key_frame = 1;
-      cpi->ref_frame_flags &=
-                (~VP9_LAST_FLAG & ~VP9_GOLD_FLAG & ~VP9_ALT_FLAG);
-      // Assumption here is that LAST_FRAME is being updated for a keyframe.
-      // Thus no change in update flags.
-      target = calc_iframe_target_size_one_pass_cbr(cpi);
-    }
-  } else {
-    cm->frame_type = INTER_FRAME;
-    if (is_two_pass_svc(cpi)) {
-      LAYER_CONTEXT *lc = &cpi->svc.layer_context[layer];
-      if (cpi->svc.spatial_layer_id == 0) {
-        lc->is_key_frame = 0;
-      } else {
-        lc->is_key_frame =
-            cpi->svc.layer_context[cpi->svc.temporal_layer_id].is_key_frame;
-        if (lc->is_key_frame)
-          cpi->ref_frame_flags &= (~VP9_LAST_FLAG);
-      }
-      cpi->ref_frame_flags &= (~VP9_ALT_FLAG);
-    } else if (is_one_pass_cbr_svc(cpi)) {
-      LAYER_CONTEXT *lc = &cpi->svc.layer_context[layer];
-      if (cpi->svc.spatial_layer_id == cpi->svc.first_spatial_layer_to_encode) {
-        lc->is_key_frame = 0;
-      } else {
-        lc->is_key_frame =
-            cpi->svc.layer_context[cpi->svc.temporal_layer_id].is_key_frame;
-      }
-      target = calc_pframe_target_size_one_pass_cbr(cpi);
-    }
-  }
-
-  // Any update/change of global cyclic refresh parameters (amount/delta-qp)
-  // should be done here, before the frame qp is selected.
-  if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ)
-    vp9_cyclic_refresh_update_parameters(cpi);
-
-  vp9_rc_set_frame_target(cpi, target);
-  rc->frames_till_gf_update_due = INT_MAX;
-  rc->baseline_gf_interval = INT_MAX;
-}
-
-void vp9_rc_get_one_pass_cbr_params(VP9_COMP *cpi) {
-  VP9_COMMON *const cm = &cpi->common;
-  RATE_CONTROL *const rc = &cpi->rc;
-  int target;
-  // TODO(yaowu): replace the "auto_key && 0" below with proper decision logic.
-  if ((cm->current_video_frame == 0 ||
-      (cpi->frame_flags & FRAMEFLAGS_KEY) ||
-      rc->frames_to_key == 0 ||
-      (cpi->oxcf.auto_key && 0))) {
-    cm->frame_type = KEY_FRAME;
-    rc->this_key_frame_forced = cm->current_video_frame != 0 &&
-                                rc->frames_to_key == 0;
-    rc->frames_to_key = cpi->oxcf.key_freq;
-    rc->kf_boost = DEFAULT_KF_BOOST;
-    rc->source_alt_ref_active = 0;
-  } else {
-    cm->frame_type = INTER_FRAME;
-  }
-  if (rc->frames_till_gf_update_due == 0) {
-    if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ)
-      vp9_cyclic_refresh_set_golden_update(cpi);
-    else
-      rc->baseline_gf_interval =
-          (rc->min_gf_interval + rc->max_gf_interval) / 2;
-    rc->frames_till_gf_update_due = rc->baseline_gf_interval;
-    // NOTE: frames_till_gf_update_due must be <= frames_to_key.
-    if (rc->frames_till_gf_update_due > rc->frames_to_key)
-      rc->frames_till_gf_update_due = rc->frames_to_key;
-    cpi->refresh_golden_frame = 1;
-    rc->gfu_boost = DEFAULT_GF_BOOST;
-  }
-
-  // Any update/change of global cyclic refresh parameters (amount/delta-qp)
-  // should be done here, before the frame qp is selected.
-  if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ)
-    vp9_cyclic_refresh_update_parameters(cpi);
-
-  if (cm->frame_type == KEY_FRAME)
-    target = calc_iframe_target_size_one_pass_cbr(cpi);
-  else
-    target = calc_pframe_target_size_one_pass_cbr(cpi);
-
-  vp9_rc_set_frame_target(cpi, target);
-  if (cpi->oxcf.resize_mode == RESIZE_DYNAMIC)
-    cpi->resize_pending = vp9_resize_one_pass_cbr(cpi);
-  else
-    cpi->resize_pending = 0;
-}
-
-int vp9_compute_qdelta(const RATE_CONTROL *rc, double qstart, double qtarget,
-                       vpx_bit_depth_t bit_depth) {
-  int start_index = rc->worst_quality;
-  int target_index = rc->worst_quality;
-  int i;
-
-  // Convert the average q value to an index.
-  for (i = rc->best_quality; i < rc->worst_quality; ++i) {
-    start_index = i;
-    if (vp9_convert_qindex_to_q(i, bit_depth) >= qstart)
-      break;
-  }
-
-  // Convert the q target to an index
-  for (i = rc->best_quality; i < rc->worst_quality; ++i) {
-    target_index = i;
-    if (vp9_convert_qindex_to_q(i, bit_depth) >= qtarget)
-      break;
-  }
-
-  return target_index - start_index;
-}
-
-int vp9_compute_qdelta_by_rate(const RATE_CONTROL *rc, FRAME_TYPE frame_type,
-                               int qindex, double rate_target_ratio,
-                               vpx_bit_depth_t bit_depth) {
-  int target_index = rc->worst_quality;
-  int i;
-
-  // Look up the current projected bits per block for the base index
-  const int base_bits_per_mb = vp9_rc_bits_per_mb(frame_type, qindex, 1.0,
-                                                  bit_depth);
-
-  // Find the target bits per mb based on the base value and given ratio.
-  const int target_bits_per_mb = (int)(rate_target_ratio * base_bits_per_mb);
-
-  // Convert the q target to an index
-  for (i = rc->best_quality; i < rc->worst_quality; ++i) {
-    if (vp9_rc_bits_per_mb(frame_type, i, 1.0, bit_depth) <=
-        target_bits_per_mb) {
-      target_index = i;
-      break;
-    }
-  }
-  return target_index - qindex;
-}
-
-void vp9_rc_set_gf_interval_range(const VP9_COMP *const cpi,
-                                  RATE_CONTROL *const rc) {
-  const VP9EncoderConfig *const oxcf = &cpi->oxcf;
-
-  // Special case code for 1 pass fixed Q mode tests
-  if ((oxcf->pass == 0) && (oxcf->rc_mode == VPX_Q)) {
-    rc->max_gf_interval = FIXED_GF_INTERVAL;
-    rc->min_gf_interval = FIXED_GF_INTERVAL;
-    rc->static_scene_max_gf_interval = FIXED_GF_INTERVAL;
-  } else {
-    // Set Maximum gf/arf interval
-    rc->max_gf_interval = oxcf->max_gf_interval;
-    rc->min_gf_interval = oxcf->min_gf_interval;
-    if (rc->min_gf_interval == 0)
-      rc->min_gf_interval = vp9_rc_get_default_min_gf_interval(
-          oxcf->width, oxcf->height, cpi->framerate);
-    if (rc->max_gf_interval == 0)
-      rc->max_gf_interval = vp9_rc_get_default_max_gf_interval(
-          cpi->framerate, rc->min_gf_interval);
-
-    // Extended interval for genuinely static scenes
-    rc->static_scene_max_gf_interval = MAX_LAG_BUFFERS * 2;
-
-    if (is_altref_enabled(cpi)) {
-      if (rc->static_scene_max_gf_interval > oxcf->lag_in_frames - 1)
-        rc->static_scene_max_gf_interval = oxcf->lag_in_frames - 1;
-    }
-
-    if (rc->max_gf_interval > rc->static_scene_max_gf_interval)
-      rc->max_gf_interval = rc->static_scene_max_gf_interval;
-
-    // Clamp min to max
-    rc->min_gf_interval = VPXMIN(rc->min_gf_interval, rc->max_gf_interval);
-  }
-}
-
-void vp9_rc_update_framerate(VP9_COMP *cpi) {
-  const VP9_COMMON *const cm = &cpi->common;
-  const VP9EncoderConfig *const oxcf = &cpi->oxcf;
-  RATE_CONTROL *const rc = &cpi->rc;
-  int vbr_max_bits;
-
-  rc->avg_frame_bandwidth = (int)(oxcf->target_bandwidth / cpi->framerate);
-  rc->min_frame_bandwidth = (int)(rc->avg_frame_bandwidth *
-                                oxcf->two_pass_vbrmin_section / 100);
-
-  rc->min_frame_bandwidth =
-      VPXMAX(rc->min_frame_bandwidth, FRAME_OVERHEAD_BITS);
-
-  // A maximum bitrate for a frame is defined.
-  // The baseline for this aligns with HW implementations that
-  // can support decode of 1080P content up to a bitrate of MAX_MB_RATE bits
-  // per 16x16 MB (averaged over a frame). However this limit is extended if
-  // a very high rate is given on the command line or the the rate cannnot
-  // be acheived because of a user specificed max q (e.g. when the user
-  // specifies lossless encode.
-  vbr_max_bits = (int)(((int64_t)rc->avg_frame_bandwidth *
-                     oxcf->two_pass_vbrmax_section) / 100);
-  rc->max_frame_bandwidth =
-      VPXMAX(VPXMAX((cm->MBs * MAX_MB_RATE), MAXRATE_1080P), vbr_max_bits);
-
-  vp9_rc_set_gf_interval_range(cpi, rc);
-}
-
-#define VBR_PCT_ADJUSTMENT_LIMIT 50
-// For VBR...adjustment to the frame target based on error from previous frames
-static void vbr_rate_correction(VP9_COMP *cpi, int *this_frame_target) {
-  RATE_CONTROL *const rc = &cpi->rc;
-  int64_t vbr_bits_off_target = rc->vbr_bits_off_target;
-  int max_delta;
-  int frame_window = VPXMIN(16,
-      ((int)cpi->twopass.total_stats.count - cpi->common.current_video_frame));
-
-  // Calcluate the adjustment to rate for this frame.
-  if (frame_window > 0) {
-    max_delta = (vbr_bits_off_target > 0)
-        ? (int)(vbr_bits_off_target / frame_window)
-        : (int)(-vbr_bits_off_target / frame_window);
-
-    max_delta = VPXMIN(max_delta,
-        ((*this_frame_target * VBR_PCT_ADJUSTMENT_LIMIT) / 100));
-
-    // vbr_bits_off_target > 0 means we have extra bits to spend
-    if (vbr_bits_off_target > 0) {
-      *this_frame_target +=
-        (vbr_bits_off_target > max_delta) ? max_delta
-                                          : (int)vbr_bits_off_target;
-    } else {
-      *this_frame_target -=
-        (vbr_bits_off_target < -max_delta) ? max_delta
-                                           : (int)-vbr_bits_off_target;
-    }
-  }
-
-  // Fast redistribution of bits arising from massive local undershoot.
-  // Dont do it for kf,arf,gf or overlay frames.
-  if (!frame_is_kf_gf_arf(cpi) && !rc->is_src_frame_alt_ref &&
-      rc->vbr_bits_off_target_fast) {
-    int one_frame_bits = VPXMAX(rc->avg_frame_bandwidth, *this_frame_target);
-    int fast_extra_bits;
-    fast_extra_bits = (int)VPXMIN(rc->vbr_bits_off_target_fast, one_frame_bits);
-    fast_extra_bits = (int)VPXMIN(
-        fast_extra_bits,
-        VPXMAX(one_frame_bits / 8, rc->vbr_bits_off_target_fast / 8));
-    *this_frame_target += (int)fast_extra_bits;
-    rc->vbr_bits_off_target_fast -= fast_extra_bits;
-  }
-}
-
-void vp9_set_target_rate(VP9_COMP *cpi) {
-  RATE_CONTROL *const rc = &cpi->rc;
-  int target_rate = rc->base_frame_target;
-
-  if (cpi->common.frame_type == KEY_FRAME)
-    target_rate = vp9_rc_clamp_iframe_target_size(cpi, target_rate);
-  else
-    target_rate = vp9_rc_clamp_pframe_target_size(cpi, target_rate);
-
-  // Correction to rate target based on prior over or under shoot.
-  if (cpi->oxcf.rc_mode == VPX_VBR || cpi->oxcf.rc_mode == VPX_CQ)
-    vbr_rate_correction(cpi, &target_rate);
-  vp9_rc_set_frame_target(cpi, target_rate);
-}
-
-// Check if we should resize, based on average QP from past x frames.
-// Only allow for resize at most one scale down for now, scaling factor is 2.
-int vp9_resize_one_pass_cbr(VP9_COMP *cpi) {
-  const VP9_COMMON *const cm = &cpi->common;
-  RATE_CONTROL *const rc = &cpi->rc;
-  RESIZE_ACTION resize_action = NO_RESIZE;
-  int avg_qp_thr1 = 70;
-  int avg_qp_thr2 = 50;
-  int min_width = 180;
-  int min_height = 180;
-  int down_size_on = 1;
-  cpi->resize_scale_num = 1;
-  cpi->resize_scale_den = 1;
-  // Don't resize on key frame; reset the counters on key frame.
-  if (cm->frame_type == KEY_FRAME) {
-    cpi->resize_avg_qp = 0;
-    cpi->resize_count = 0;
-    return 0;
-  }
-  // Check current frame reslution to avoid generating frames smaller than
-  // the minimum resolution.
-  if (ONEHALFONLY_RESIZE) {
-    if ((cm->width >> 1) < min_width || (cm->height >> 1) < min_height)
-      down_size_on = 0;
-  } else {
-    if (cpi->resize_state == ORIG &&
-        (cm->width * 3 / 4 < min_width ||
-         cm->height * 3 / 4 < min_height))
-      return 0;
-    else if (cpi->resize_state == THREE_QUARTER &&
-             ((cpi->oxcf.width >> 1) < min_width ||
-              (cpi->oxcf.height >> 1) < min_height))
-      down_size_on = 0;
-  }
-
-#if CONFIG_VP9_TEMPORAL_DENOISING
-  // If denoiser is on, apply a smaller qp threshold.
-  if (cpi->oxcf.noise_sensitivity > 0) {
-    avg_qp_thr1 = 60;
-    avg_qp_thr2 = 40;
-  }
-#endif
-
-  // Resize based on average buffer underflow and QP over some window.
-  // Ignore samples close to key frame, since QP is usually high after key.
-  if (cpi->rc.frames_since_key > 2 * cpi->framerate) {
-    const int window = (int)(4 * cpi->framerate);
-    cpi->resize_avg_qp += cm->base_qindex;
-    if (cpi->rc.buffer_level < (int)(30 * rc->optimal_buffer_level / 100))
-      ++cpi->resize_buffer_underflow;
-    ++cpi->resize_count;
-    // Check for resize action every "window" frames.
-    if (cpi->resize_count >= window) {
-      int avg_qp = cpi->resize_avg_qp / cpi->resize_count;
-      // Resize down if buffer level has underflowed sufficient amount in past
-      // window, and we are at original or 3/4 of original resolution.
-      // Resize back up if average QP is low, and we are currently in a resized
-      // down state, i.e. 1/2 or 3/4 of original resolution.
-      // Currently, use a flag to turn 3/4 resizing feature on/off.
-      if (cpi->resize_buffer_underflow > (cpi->resize_count >> 2)) {
-        if (cpi->resize_state == THREE_QUARTER && down_size_on) {
-          resize_action = DOWN_ONEHALF;
-          cpi->resize_state = ONE_HALF;
-        } else if (cpi->resize_state == ORIG) {
-          resize_action = ONEHALFONLY_RESIZE ? DOWN_ONEHALF : DOWN_THREEFOUR;
-          cpi->resize_state = ONEHALFONLY_RESIZE ? ONE_HALF : THREE_QUARTER;
-        }
-      } else if (cpi->resize_state != ORIG &&
-                 avg_qp < avg_qp_thr1 * cpi->rc.worst_quality / 100) {
-        if (cpi->resize_state == THREE_QUARTER ||
-            avg_qp < avg_qp_thr2 * cpi->rc.worst_quality / 100 ||
-            ONEHALFONLY_RESIZE) {
-          resize_action = UP_ORIG;
-          cpi->resize_state = ORIG;
-        } else if (cpi->resize_state == ONE_HALF) {
-          resize_action = UP_THREEFOUR;
-          cpi->resize_state = THREE_QUARTER;
-        }
-      }
-      // Reset for next window measurement.
-      cpi->resize_avg_qp = 0;
-      cpi->resize_count = 0;
-      cpi->resize_buffer_underflow = 0;
-    }
-  }
-  // If decision is to resize, reset some quantities, and check is we should
-  // reduce rate correction factor,
-  if (resize_action != NO_RESIZE) {
-    int target_bits_per_frame;
-    int active_worst_quality;
-    int qindex;
-    int tot_scale_change;
-    if (resize_action == DOWN_THREEFOUR || resize_action == UP_THREEFOUR) {
-      cpi->resize_scale_num = 3;
-      cpi->resize_scale_den = 4;
-    } else if (resize_action == DOWN_ONEHALF) {
-      cpi->resize_scale_num = 1;
-      cpi->resize_scale_den = 2;
-    } else {  // UP_ORIG or anything else
-      cpi->resize_scale_num = 1;
-      cpi->resize_scale_den = 1;
-    }
-    tot_scale_change = (cpi->resize_scale_den * cpi->resize_scale_den) /
-        (cpi->resize_scale_num * cpi->resize_scale_num);
-    // Reset buffer level to optimal, update target size.
-    rc->buffer_level = rc->optimal_buffer_level;
-    rc->bits_off_target = rc->optimal_buffer_level;
-    rc->this_frame_target = calc_pframe_target_size_one_pass_cbr(cpi);
-    // Get the projected qindex, based on the scaled target frame size (scaled
-    // so target_bits_per_mb in vp9_rc_regulate_q will be correct target).
-    target_bits_per_frame = (resize_action >= 0) ?
-        rc->this_frame_target * tot_scale_change :
-        rc->this_frame_target / tot_scale_change;
-    active_worst_quality = calc_active_worst_quality_one_pass_cbr(cpi);
-    qindex = vp9_rc_regulate_q(cpi,
-                               target_bits_per_frame,
-                               rc->best_quality,
-                               active_worst_quality);
-    // If resize is down, check if projected q index is close to worst_quality,
-    // and if so, reduce the rate correction factor (since likely can afford
-    // lower q for resized frame).
-    if (resize_action > 0 &&
-        qindex > 90 * cpi->rc.worst_quality / 100) {
-      rc->rate_correction_factors[INTER_NORMAL] *= 0.85;
-    }
-    // If resize is back up, check if projected q index is too much above the
-    // current base_qindex, and if so, reduce the rate correction factor
-    // (since prefer to keep q for resized frame at least close to previous q).
-    if (resize_action < 0 &&
-       qindex > 130 * cm->base_qindex / 100) {
-      rc->rate_correction_factors[INTER_NORMAL] *= 0.9;
-    }
-  }
-  return resize_action;
-}
-
-// Compute average source sad (temporal sad: between current source and
-// previous source) over a subset of superblocks. Use this is detect big changes
-// in content and allow rate control to react.
-// TODO(marpan): Superblock sad is computed again in variance partition for
-// non-rd mode (but based on last reconstructed frame). Should try to reuse
-// these computations.
-void vp9_avg_source_sad(VP9_COMP *cpi) {
-  VP9_COMMON * const cm = &cpi->common;
-  RATE_CONTROL *const rc = &cpi->rc;
-  rc->high_source_sad = 0;
-  if (cpi->Last_Source != NULL &&
-      cpi->Last_Source->y_width == cpi->Source->y_width &&
-      cpi->Last_Source->y_height == cpi->Source->y_height) {
-    const uint8_t *src_y = cpi->Source->y_buffer;
-    const int src_ystride = cpi->Source->y_stride;
-    const uint8_t *last_src_y = cpi->Last_Source->y_buffer;
-    const int last_src_ystride = cpi->Last_Source->y_stride;
-    int sbi_row, sbi_col;
-    const BLOCK_SIZE bsize = BLOCK_64X64;
-    uint32_t min_thresh = 4000;
-    float thresh = 8.0f;
-    // Loop over sub-sample of frame, and compute average sad over 64x64 blocks.
-    uint64_t avg_sad = 0;
-    int num_samples = 0;
-    int sb_cols = (cm->mi_cols + MI_BLOCK_SIZE - 1) / MI_BLOCK_SIZE;
-    int sb_rows = (cm->mi_rows + MI_BLOCK_SIZE - 1) / MI_BLOCK_SIZE;
-    for (sbi_row = 0; sbi_row < sb_rows; sbi_row ++) {
-      for (sbi_col = 0; sbi_col < sb_cols; sbi_col ++) {
-        // Checker-board pattern, ignore boundary.
-        if ((sbi_row > 0 && sbi_col > 0) &&
-            (sbi_row < sb_rows - 1 && sbi_col < sb_cols - 1) &&
-            ((sbi_row % 2 == 0 && sbi_col % 2 == 0) ||
-            (sbi_row % 2 != 0 && sbi_col % 2 != 0))) {
-          num_samples++;
-          avg_sad += cpi->fn_ptr[bsize].sdf(src_y,
-                                            src_ystride,
-                                            last_src_y,
-                                            last_src_ystride);
-        }
-        src_y += 64;
-        last_src_y += 64;
-      }
-      src_y += (src_ystride << 6) - (sb_cols << 6);
-      last_src_y += (last_src_ystride << 6) - (sb_cols << 6);
-    }
-    if (num_samples > 0)
-      avg_sad = avg_sad / num_samples;
-    // Set high_source_sad flag if we detect very high increase in avg_sad
-    // between current and the previous frame value(s). Use a minimum threshold
-    // for cases where there is small change from content that is completely
-    // static.
-    if (cpi->oxcf.rc_mode == VPX_VBR) {
-      min_thresh = 60000;
-      thresh = 2.1f;
-    }
-    if (avg_sad >
-        VPXMAX(min_thresh, (unsigned int)(rc->avg_source_sad  * thresh)) &&
-        rc->frames_since_key > 1)
-      rc->high_source_sad = 1;
-    else
-      rc->high_source_sad = 0;
-    if (avg_sad > 0 || cpi->oxcf.rc_mode == VPX_CBR)
-      rc->avg_source_sad = (3 * rc->avg_source_sad + avg_sad) >> 2;
-    // For VBR, under scene change/high content change, force golden refresh.
-    if (cpi->oxcf.rc_mode == VPX_VBR &&
-        rc->high_source_sad &&
-        rc->frames_to_key > 3 &&
-        rc->count_last_scene_change > 4 &&
-        cpi->ext_refresh_frame_flags_pending == 0) {
-      int target;
-      cpi->refresh_golden_frame = 1;
-      rc->gfu_boost = DEFAULT_GF_BOOST >> 1;
-      rc->baseline_gf_interval = VPXMIN(20,
-          VPXMAX(10, rc->baseline_gf_interval));
-      adjust_gf_key_frame(cpi);
-      rc->frames_till_gf_update_due = rc->baseline_gf_interval;
-      target = calc_pframe_target_size_one_pass_vbr(cpi);
-      vp9_rc_set_frame_target(cpi, target);
-      rc->count_last_scene_change = 0;
-    } else {
-      rc->count_last_scene_change++;
-    }
-  }
-}
-
-// Test if encoded frame will significantly overshoot the target bitrate, and
-// if so, set the QP, reset/adjust some rate control parameters, and return 1.
-int vp9_encodedframe_overshoot(VP9_COMP *cpi,
-                               int frame_size,
-                               int *q) {
-  VP9_COMMON * const cm = &cpi->common;
-  RATE_CONTROL *const rc = &cpi->rc;
-  int thresh_qp = 3 * (rc->worst_quality >> 2);
-  int thresh_rate = rc->avg_frame_bandwidth * 10;
-  if (cm->base_qindex < thresh_qp &&
-      frame_size > thresh_rate) {
-    double rate_correction_factor =
-        cpi->rc.rate_correction_factors[INTER_NORMAL];
-    const int target_size = cpi->rc.avg_frame_bandwidth;
-    double new_correction_factor;
-    int target_bits_per_mb;
-    double q2;
-    int enumerator;
-    // Force a re-encode, and for now use max-QP.
-    *q = cpi->rc.worst_quality;
-    // Adjust avg_frame_qindex, buffer_level, and rate correction factors, as
-    // these parameters will affect QP selection for subsequent frames. If they
-    // have settled down to a very different (low QP) state, then not adjusting
-    // them may cause next frame to select low QP and overshoot again.
-    cpi->rc.avg_frame_qindex[INTER_FRAME] = *q;
-    rc->buffer_level = rc->optimal_buffer_level;
-    rc->bits_off_target = rc->optimal_buffer_level;
-    // Reset rate under/over-shoot flags.
-    cpi->rc.rc_1_frame = 0;
-    cpi->rc.rc_2_frame = 0;
-    // Adjust rate correction factor.
-    target_bits_per_mb = ((uint64_t)target_size << BPER_MB_NORMBITS) / cm->MBs;
-    // Rate correction factor based on target_bits_per_mb and qp (==max_QP).
-    // This comes from the inverse computation of vp9_rc_bits_per_mb().
-    q2 = vp9_convert_qindex_to_q(*q, cm->bit_depth);
-    enumerator = 1800000;  // Factor for inter frame.
-    enumerator += (int)(enumerator * q2) >> 12;
-    new_correction_factor = (double)target_bits_per_mb * q2 / enumerator;
-    if (new_correction_factor > rate_correction_factor) {
-      rate_correction_factor =
-          VPXMIN(2.0 * rate_correction_factor, new_correction_factor);
-      if (rate_correction_factor > MAX_BPB_FACTOR)
-        rate_correction_factor = MAX_BPB_FACTOR;
-      cpi->rc.rate_correction_factors[INTER_NORMAL] = rate_correction_factor;
-    }
-    // For temporal layers, reset the rate control parametes across all
-    // temporal layers.
-    if (cpi->use_svc) {
-      int i = 0;
-      SVC *svc = &cpi->svc;
-      for (i = 0; i < svc->number_temporal_layers; ++i) {
-        const int layer = LAYER_IDS_TO_IDX(svc->spatial_layer_id, i,
-                                           svc->number_temporal_layers);
-        LAYER_CONTEXT *lc = &svc->layer_context[layer];
-        RATE_CONTROL *lrc = &lc->rc;
-        lrc->avg_frame_qindex[INTER_FRAME] = *q;
-        lrc->buffer_level = rc->optimal_buffer_level;
-        lrc->bits_off_target = rc->optimal_buffer_level;
-        lrc->rc_1_frame = 0;
-        lrc->rc_2_frame = 0;
-        lrc->rate_correction_factors[INTER_NORMAL] =
-            rate_correction_factor;
-      }
-    }
-    return 1;
-  } else {
-    return 0;
-  }
-}
diff --git a/vp9/encoder/vp9_ratectrl.h b/vp9/encoder/vp9_ratectrl.h
deleted file mode 100644 (file)
index 7024bcf..0000000
+++ /dev/null
@@ -1,288 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#ifndef VP9_ENCODER_VP9_RATECTRL_H_
-#define VP9_ENCODER_VP9_RATECTRL_H_
-
-#include "vpx/vpx_codec.h"
-#include "vpx/vpx_integer.h"
-
-#include "vp9/common/vp9_blockd.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-// Bits Per MB at different Q (Multiplied by 512)
-#define BPER_MB_NORMBITS    9
-
-#define MIN_GF_INTERVAL     4
-#define MAX_GF_INTERVAL     16
-#define FIXED_GF_INTERVAL   8    // Used in some testing modes only
-#define ONEHALFONLY_RESIZE  0
-
-typedef enum {
-  INTER_NORMAL = 0,
-  INTER_HIGH = 1,
-  GF_ARF_LOW = 2,
-  GF_ARF_STD = 3,
-  KF_STD = 4,
-  RATE_FACTOR_LEVELS = 5
-} RATE_FACTOR_LEVEL;
-
-// Internal frame scaling level.
-typedef enum {
-  UNSCALED = 0,     // Frame is unscaled.
-  SCALE_STEP1 = 1,  // First-level down-scaling.
-  FRAME_SCALE_STEPS
-} FRAME_SCALE_LEVEL;
-
-typedef enum {
-  NO_RESIZE = 0,
-  DOWN_THREEFOUR = 1,  // From orig to 3/4.
-  DOWN_ONEHALF = 2,    // From orig or 3/4 to 1/2.
-  UP_THREEFOUR = -1,   // From 1/2 to 3/4.
-  UP_ORIG = -2,        // From 1/2 or 3/4 to orig.
-} RESIZE_ACTION;
-
-typedef enum {
-  ORIG = 0,
-  THREE_QUARTER = 1,
-  ONE_HALF = 2
-} RESIZE_STATE;
-
-// Frame dimensions multiplier wrt the native frame size, in 1/16ths,
-// specified for the scale-up case.
-// e.g. 24 => 16/24 = 2/3 of native size. The restriction to 1/16th is
-// intended to match the capabilities of the normative scaling filters,
-// giving precedence to the up-scaling accuracy.
-static const int frame_scale_factor[FRAME_SCALE_STEPS] = {16, 24};
-
-// Multiplier of the target rate to be used as threshold for triggering scaling.
-static const double rate_thresh_mult[FRAME_SCALE_STEPS] = {1.0, 2.0};
-
-// Scale dependent Rate Correction Factor multipliers. Compensates for the
-// greater number of bits per pixel generated in down-scaled frames.
-static const double rcf_mult[FRAME_SCALE_STEPS] = {1.0, 2.0};
-
-typedef struct {
-  // Rate targetting variables
-  int base_frame_target;           // A baseline frame target before adjustment
-                                   // for previous under or over shoot.
-  int this_frame_target;           // Actual frame target after rc adjustment.
-  int projected_frame_size;
-  int sb64_target_rate;
-  int last_q[FRAME_TYPES];         // Separate values for Intra/Inter
-  int last_boosted_qindex;         // Last boosted GF/KF/ARF q
-  int last_kf_qindex;              // Q index of the last key frame coded.
-
-  int gfu_boost;
-  int last_boost;
-  int kf_boost;
-
-  double rate_correction_factors[RATE_FACTOR_LEVELS];
-
-  int frames_since_golden;
-  int frames_till_gf_update_due;
-  int min_gf_interval;
-  int max_gf_interval;
-  int static_scene_max_gf_interval;
-  int baseline_gf_interval;
-  int constrained_gf_group;
-  int frames_to_key;
-  int frames_since_key;
-  int this_key_frame_forced;
-  int next_key_frame_forced;
-  int source_alt_ref_pending;
-  int source_alt_ref_active;
-  int is_src_frame_alt_ref;
-
-  int avg_frame_bandwidth;  // Average frame size target for clip
-  int min_frame_bandwidth;  // Minimum allocation used for any frame
-  int max_frame_bandwidth;  // Maximum burst rate allowed for a frame.
-
-  int ni_av_qi;
-  int ni_tot_qi;
-  int ni_frames;
-  int avg_frame_qindex[FRAME_TYPES];
-  double tot_q;
-  double avg_q;
-
-  int64_t buffer_level;
-  int64_t bits_off_target;
-  int64_t vbr_bits_off_target;
-  int64_t vbr_bits_off_target_fast;
-
-  int decimation_factor;
-  int decimation_count;
-
-  int rolling_target_bits;
-  int rolling_actual_bits;
-
-  int long_rolling_target_bits;
-  int long_rolling_actual_bits;
-
-  int rate_error_estimate;
-
-  int64_t total_actual_bits;
-  int64_t total_target_bits;
-  int64_t total_target_vs_actual;
-
-  int worst_quality;
-  int best_quality;
-
-  int64_t starting_buffer_level;
-  int64_t optimal_buffer_level;
-  int64_t maximum_buffer_size;
-
-  // rate control history for last frame(1) and the frame before(2).
-  // -1: undershot
-  //  1: overshoot
-  //  0: not initialized.
-  int rc_1_frame;
-  int rc_2_frame;
-  int q_1_frame;
-  int q_2_frame;
-
-  // Auto frame-scaling variables.
-  FRAME_SCALE_LEVEL frame_size_selector;
-  FRAME_SCALE_LEVEL next_frame_size_selector;
-  int frame_width[FRAME_SCALE_STEPS];
-  int frame_height[FRAME_SCALE_STEPS];
-  int rf_level_maxq[RATE_FACTOR_LEVELS];
-
-  uint64_t avg_source_sad;
-  int high_source_sad;
-  int count_last_scene_change;
-  int avg_frame_low_motion;
-} RATE_CONTROL;
-
-struct VP9_COMP;
-struct VP9EncoderConfig;
-
-void vp9_rc_init(const struct VP9EncoderConfig *oxcf, int pass,
-                 RATE_CONTROL *rc);
-
-int vp9_estimate_bits_at_q(FRAME_TYPE frame_kind, int q, int mbs,
-                           double correction_factor,
-                           vpx_bit_depth_t bit_depth);
-
-double vp9_convert_qindex_to_q(int qindex, vpx_bit_depth_t bit_depth);
-
-void vp9_rc_init_minq_luts(void);
-
-int vp9_rc_get_default_min_gf_interval(int width, int height, double framerate);
-// Note vp9_rc_get_default_max_gf_interval() requires the min_gf_interval to
-// be passed in to ensure that the max_gf_interval returned is at least as bis
-// as that.
-int vp9_rc_get_default_max_gf_interval(double framerate, int min_frame_rate);
-
-// Generally at the high level, the following flow is expected
-// to be enforced for rate control:
-// First call per frame, one of:
-//   vp9_rc_get_one_pass_vbr_params()
-//   vp9_rc_get_one_pass_cbr_params()
-//   vp9_rc_get_svc_params()
-//   vp9_rc_get_first_pass_params()
-//   vp9_rc_get_second_pass_params()
-// depending on the usage to set the rate control encode parameters desired.
-//
-// Then, call encode_frame_to_data_rate() to perform the
-// actual encode. This function will in turn call encode_frame()
-// one or more times, followed by one of:
-//   vp9_rc_postencode_update()
-//   vp9_rc_postencode_update_drop_frame()
-//
-// The majority of rate control parameters are only expected
-// to be set in the vp9_rc_get_..._params() functions and
-// updated during the vp9_rc_postencode_update...() functions.
-// The only exceptions are vp9_rc_drop_frame() and
-// vp9_rc_update_rate_correction_factors() functions.
-
-// Functions to set parameters for encoding before the actual
-// encode_frame_to_data_rate() function.
-void vp9_rc_get_one_pass_vbr_params(struct VP9_COMP *cpi);
-void vp9_rc_get_one_pass_cbr_params(struct VP9_COMP *cpi);
-void vp9_rc_get_svc_params(struct VP9_COMP *cpi);
-
-// Post encode update of the rate control parameters based
-// on bytes used
-void vp9_rc_postencode_update(struct VP9_COMP *cpi, uint64_t bytes_used);
-// Post encode update of the rate control parameters for dropped frames
-void vp9_rc_postencode_update_drop_frame(struct VP9_COMP *cpi);
-
-// Updates rate correction factors
-// Changes only the rate correction factors in the rate control structure.
-void vp9_rc_update_rate_correction_factors(struct VP9_COMP *cpi);
-
-// Decide if we should drop this frame: For 1-pass CBR.
-// Changes only the decimation count in the rate control structure
-int vp9_rc_drop_frame(struct VP9_COMP *cpi);
-
-// Computes frame size bounds.
-void vp9_rc_compute_frame_size_bounds(const struct VP9_COMP *cpi,
-                                      int this_frame_target,
-                                      int *frame_under_shoot_limit,
-                                      int *frame_over_shoot_limit);
-
-// Picks q and q bounds given the target for bits
-int vp9_rc_pick_q_and_bounds(const struct VP9_COMP *cpi,
-                             int *bottom_index,
-                             int *top_index);
-
-// Estimates q to achieve a target bits per frame
-int vp9_rc_regulate_q(const struct VP9_COMP *cpi, int target_bits_per_frame,
-                      int active_best_quality, int active_worst_quality);
-
-// Estimates bits per mb for a given qindex and correction factor.
-int vp9_rc_bits_per_mb(FRAME_TYPE frame_type, int qindex,
-                       double correction_factor, vpx_bit_depth_t bit_depth);
-
-// Clamping utilities for bitrate targets for iframes and pframes.
-int vp9_rc_clamp_iframe_target_size(const struct VP9_COMP *const cpi,
-                                    int target);
-int vp9_rc_clamp_pframe_target_size(const struct VP9_COMP *const cpi,
-                                    int target);
-// Utility to set frame_target into the RATE_CONTROL structure
-// This function is called only from the vp9_rc_get_..._params() functions.
-void vp9_rc_set_frame_target(struct VP9_COMP *cpi, int target);
-
-// Computes a q delta (in "q index" terms) to get from a starting q value
-// to a target q value
-int vp9_compute_qdelta(const RATE_CONTROL *rc, double qstart, double qtarget,
-                       vpx_bit_depth_t bit_depth);
-
-// Computes a q delta (in "q index" terms) to get from a starting q value
-// to a value that should equate to the given rate ratio.
-int vp9_compute_qdelta_by_rate(const RATE_CONTROL *rc, FRAME_TYPE frame_type,
-                               int qindex, double rate_target_ratio,
-                               vpx_bit_depth_t bit_depth);
-
-int vp9_frame_type_qdelta(const struct VP9_COMP *cpi, int rf_level, int q);
-
-void vp9_rc_update_framerate(struct VP9_COMP *cpi);
-
-void vp9_rc_set_gf_interval_range(const struct VP9_COMP *const cpi,
-                                  RATE_CONTROL *const rc);
-
-void vp9_set_target_rate(struct VP9_COMP *cpi);
-
-int vp9_resize_one_pass_cbr(struct VP9_COMP *cpi);
-
-void vp9_avg_source_sad(struct VP9_COMP *cpi);
-
-int vp9_encodedframe_overshoot(struct VP9_COMP *cpi, int frame_size, int *q);
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP9_ENCODER_VP9_RATECTRL_H_
diff --git a/vp9/encoder/vp9_rd.c b/vp9/encoder/vp9_rd.c
deleted file mode 100644 (file)
index 5ec7b25..0000000
+++ /dev/null
@@ -1,678 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#include <assert.h>
-#include <math.h>
-#include <stdio.h>
-
-#include "./vp9_rtcd.h"
-
-#include "vpx_dsp/vpx_dsp_common.h"
-#include "vpx_mem/vpx_mem.h"
-#include "vpx_ports/bitops.h"
-#include "vpx_ports/mem.h"
-#include "vpx_ports/system_state.h"
-
-#include "vp9/common/vp9_common.h"
-#include "vp9/common/vp9_entropy.h"
-#include "vp9/common/vp9_entropymode.h"
-#include "vp9/common/vp9_mvref_common.h"
-#include "vp9/common/vp9_pred_common.h"
-#include "vp9/common/vp9_quant_common.h"
-#include "vp9/common/vp9_reconinter.h"
-#include "vp9/common/vp9_reconintra.h"
-#include "vp9/common/vp9_seg_common.h"
-
-#include "vp9/encoder/vp9_cost.h"
-#include "vp9/encoder/vp9_encodemb.h"
-#include "vp9/encoder/vp9_encodemv.h"
-#include "vp9/encoder/vp9_encoder.h"
-#include "vp9/encoder/vp9_mcomp.h"
-#include "vp9/encoder/vp9_quantize.h"
-#include "vp9/encoder/vp9_ratectrl.h"
-#include "vp9/encoder/vp9_rd.h"
-#include "vp9/encoder/vp9_tokenize.h"
-
-#define RD_THRESH_POW      1.25
-
-// Factor to weigh the rate for switchable interp filters.
-#define SWITCHABLE_INTERP_RATE_FACTOR 1
-
-void vp9_rd_cost_reset(RD_COST *rd_cost) {
-  rd_cost->rate = INT_MAX;
-  rd_cost->dist = INT64_MAX;
-  rd_cost->rdcost = INT64_MAX;
-}
-
-void vp9_rd_cost_init(RD_COST *rd_cost) {
-  rd_cost->rate = 0;
-  rd_cost->dist = 0;
-  rd_cost->rdcost = 0;
-}
-
-// The baseline rd thresholds for breaking out of the rd loop for
-// certain modes are assumed to be based on 8x8 blocks.
-// This table is used to correct for block size.
-// The factors here are << 2 (2 = x0.5, 32 = x8 etc).
-static const uint8_t rd_thresh_block_size_factor[BLOCK_SIZES] = {
-  2, 3, 3, 4, 6, 6, 8, 12, 12, 16, 24, 24, 32
-};
-
-static void fill_mode_costs(VP9_COMP *cpi) {
-  const FRAME_CONTEXT *const fc = cpi->common.fc;
-  int i, j;
-
-  for (i = 0; i < INTRA_MODES; ++i)
-    for (j = 0; j < INTRA_MODES; ++j)
-      vp9_cost_tokens(cpi->y_mode_costs[i][j], vp9_kf_y_mode_prob[i][j],
-                      vp9_intra_mode_tree);
-
-  vp9_cost_tokens(cpi->mbmode_cost, fc->y_mode_prob[1], vp9_intra_mode_tree);
-  for (i = 0; i < INTRA_MODES; ++i) {
-    vp9_cost_tokens(cpi->intra_uv_mode_cost[KEY_FRAME][i],
-                    vp9_kf_uv_mode_prob[i], vp9_intra_mode_tree);
-    vp9_cost_tokens(cpi->intra_uv_mode_cost[INTER_FRAME][i],
-                    fc->uv_mode_prob[i], vp9_intra_mode_tree);
-  }
-
-  for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; ++i)
-    vp9_cost_tokens(cpi->switchable_interp_costs[i],
-                    fc->switchable_interp_prob[i], vp9_switchable_interp_tree);
-}
-
-static void fill_token_costs(vp9_coeff_cost *c,
-                             vp9_coeff_probs_model (*p)[PLANE_TYPES]) {
-  int i, j, k, l;
-  TX_SIZE t;
-  for (t = TX_4X4; t <= TX_32X32; ++t)
-    for (i = 0; i < PLANE_TYPES; ++i)
-      for (j = 0; j < REF_TYPES; ++j)
-        for (k = 0; k < COEF_BANDS; ++k)
-          for (l = 0; l < BAND_COEFF_CONTEXTS(k); ++l) {
-            vpx_prob probs[ENTROPY_NODES];
-            vp9_model_to_full_probs(p[t][i][j][k][l], probs);
-            vp9_cost_tokens((int *)c[t][i][j][k][0][l], probs,
-                            vp9_coef_tree);
-            vp9_cost_tokens_skip((int *)c[t][i][j][k][1][l], probs,
-                                 vp9_coef_tree);
-            assert(c[t][i][j][k][0][l][EOB_TOKEN] ==
-                   c[t][i][j][k][1][l][EOB_TOKEN]);
-          }
-}
-
-// Values are now correlated to quantizer.
-static int sad_per_bit16lut_8[QINDEX_RANGE];
-static int sad_per_bit4lut_8[QINDEX_RANGE];
-
-#if CONFIG_VP9_HIGHBITDEPTH
-static int sad_per_bit16lut_10[QINDEX_RANGE];
-static int sad_per_bit4lut_10[QINDEX_RANGE];
-static int sad_per_bit16lut_12[QINDEX_RANGE];
-static int sad_per_bit4lut_12[QINDEX_RANGE];
-#endif
-
-static void init_me_luts_bd(int *bit16lut, int *bit4lut, int range,
-                            vpx_bit_depth_t bit_depth) {
-  int i;
-  // Initialize the sad lut tables using a formulaic calculation for now.
-  // This is to make it easier to resolve the impact of experimental changes
-  // to the quantizer tables.
-  for (i = 0; i < range; i++) {
-    const double q = vp9_convert_qindex_to_q(i, bit_depth);
-    bit16lut[i] = (int)(0.0418 * q + 2.4107);
-    bit4lut[i] = (int)(0.063 * q + 2.742);
-  }
-}
-
-void vp9_init_me_luts(void) {
-  init_me_luts_bd(sad_per_bit16lut_8, sad_per_bit4lut_8, QINDEX_RANGE,
-                  VPX_BITS_8);
-#if CONFIG_VP9_HIGHBITDEPTH
-  init_me_luts_bd(sad_per_bit16lut_10, sad_per_bit4lut_10, QINDEX_RANGE,
-                  VPX_BITS_10);
-  init_me_luts_bd(sad_per_bit16lut_12, sad_per_bit4lut_12, QINDEX_RANGE,
-                  VPX_BITS_12);
-#endif
-}
-
-static const int rd_boost_factor[16] = {
-  64, 32, 32, 32, 24, 16, 12, 12,
-  8, 8, 4, 4, 2, 2, 1, 0
-};
-static const int rd_frame_type_factor[FRAME_UPDATE_TYPES] = {
-  128, 144, 128, 128, 144
-};
-
-int vp9_compute_rd_mult(const VP9_COMP *cpi, int qindex) {
-  const int64_t q = vp9_dc_quant(qindex, 0, cpi->common.bit_depth);
-#if CONFIG_VP9_HIGHBITDEPTH
-  int64_t rdmult = 0;
-  switch (cpi->common.bit_depth) {
-    case VPX_BITS_8:
-      rdmult = 88 * q * q / 24;
-      break;
-    case VPX_BITS_10:
-      rdmult = ROUND_POWER_OF_TWO(88 * q * q / 24, 4);
-      break;
-    case VPX_BITS_12:
-      rdmult = ROUND_POWER_OF_TWO(88 * q * q / 24, 8);
-      break;
-    default:
-      assert(0 && "bit_depth should be VPX_BITS_8, VPX_BITS_10 or VPX_BITS_12");
-      return -1;
-  }
-#else
-  int64_t rdmult = 88 * q * q / 24;
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-  if (cpi->oxcf.pass == 2 && (cpi->common.frame_type != KEY_FRAME)) {
-    const GF_GROUP *const gf_group = &cpi->twopass.gf_group;
-    const FRAME_UPDATE_TYPE frame_type = gf_group->update_type[gf_group->index];
-    const int boost_index = VPXMIN(15, (cpi->rc.gfu_boost / 100));
-
-    rdmult = (rdmult * rd_frame_type_factor[frame_type]) >> 7;
-    rdmult += ((rdmult * rd_boost_factor[boost_index]) >> 7);
-  }
-  if (rdmult < 1)
-    rdmult = 1;
-  return (int)rdmult;
-}
-
-static int compute_rd_thresh_factor(int qindex, vpx_bit_depth_t bit_depth) {
-  double q;
-#if CONFIG_VP9_HIGHBITDEPTH
-  switch (bit_depth) {
-    case VPX_BITS_8:
-      q = vp9_dc_quant(qindex, 0, VPX_BITS_8) / 4.0;
-      break;
-    case VPX_BITS_10:
-      q = vp9_dc_quant(qindex, 0, VPX_BITS_10) / 16.0;
-      break;
-    case VPX_BITS_12:
-      q = vp9_dc_quant(qindex, 0, VPX_BITS_12) / 64.0;
-      break;
-    default:
-      assert(0 && "bit_depth should be VPX_BITS_8, VPX_BITS_10 or VPX_BITS_12");
-      return -1;
-  }
-#else
-  (void) bit_depth;
-  q = vp9_dc_quant(qindex, 0, VPX_BITS_8) / 4.0;
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-  // TODO(debargha): Adjust the function below.
-  return VPXMAX((int)(pow(q, RD_THRESH_POW) * 5.12), 8);
-}
-
-void vp9_initialize_me_consts(VP9_COMP *cpi, MACROBLOCK *x, int qindex) {
-#if CONFIG_VP9_HIGHBITDEPTH
-  switch (cpi->common.bit_depth) {
-    case VPX_BITS_8:
-      x->sadperbit16 = sad_per_bit16lut_8[qindex];
-      x->sadperbit4 = sad_per_bit4lut_8[qindex];
-      break;
-    case VPX_BITS_10:
-      x->sadperbit16 = sad_per_bit16lut_10[qindex];
-      x->sadperbit4 = sad_per_bit4lut_10[qindex];
-      break;
-    case VPX_BITS_12:
-      x->sadperbit16 = sad_per_bit16lut_12[qindex];
-      x->sadperbit4 = sad_per_bit4lut_12[qindex];
-      break;
-    default:
-      assert(0 && "bit_depth should be VPX_BITS_8, VPX_BITS_10 or VPX_BITS_12");
-  }
-#else
-  (void)cpi;
-  x->sadperbit16 = sad_per_bit16lut_8[qindex];
-  x->sadperbit4 = sad_per_bit4lut_8[qindex];
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-}
-
-static void set_block_thresholds(const VP9_COMMON *cm, RD_OPT *rd) {
-  int i, bsize, segment_id;
-
-  for (segment_id = 0; segment_id < MAX_SEGMENTS; ++segment_id) {
-    const int qindex =
-        clamp(vp9_get_qindex(&cm->seg, segment_id, cm->base_qindex) +
-              cm->y_dc_delta_q, 0, MAXQ);
-    const int q = compute_rd_thresh_factor(qindex, cm->bit_depth);
-
-    for (bsize = 0; bsize < BLOCK_SIZES; ++bsize) {
-      // Threshold here seems unnecessarily harsh but fine given actual
-      // range of values used for cpi->sf.thresh_mult[].
-      const int t = q * rd_thresh_block_size_factor[bsize];
-      const int thresh_max = INT_MAX / t;
-
-      if (bsize >= BLOCK_8X8) {
-        for (i = 0; i < MAX_MODES; ++i)
-          rd->threshes[segment_id][bsize][i] =
-              rd->thresh_mult[i] < thresh_max
-                  ? rd->thresh_mult[i] * t / 4
-                  : INT_MAX;
-      } else {
-        for (i = 0; i < MAX_REFS; ++i)
-          rd->threshes[segment_id][bsize][i] =
-              rd->thresh_mult_sub8x8[i] < thresh_max
-                  ? rd->thresh_mult_sub8x8[i] * t / 4
-                  : INT_MAX;
-      }
-    }
-  }
-}
-
-void vp9_initialize_rd_consts(VP9_COMP *cpi) {
-  VP9_COMMON *const cm = &cpi->common;
-  MACROBLOCK *const x = &cpi->td.mb;
-  MACROBLOCKD *const xd = &cpi->td.mb.e_mbd;
-  RD_OPT *const rd = &cpi->rd;
-  int i;
-
-  vpx_clear_system_state();
-
-  rd->RDDIV = RDDIV_BITS;  // In bits (to multiply D by 128).
-  rd->RDMULT = vp9_compute_rd_mult(cpi, cm->base_qindex + cm->y_dc_delta_q);
-
-  set_error_per_bit(x, rd->RDMULT);
-
-  x->select_tx_size = (cpi->sf.tx_size_search_method == USE_LARGESTALL &&
-                       cm->frame_type != KEY_FRAME) ? 0 : 1;
-
-  set_block_thresholds(cm, rd);
-  set_partition_probs(cm, xd);
-
-  if (cpi->oxcf.pass == 1) {
-    if (!frame_is_intra_only(cm))
-      vp9_build_nmv_cost_table(
-          x->nmvjointcost,
-          cm->allow_high_precision_mv ? x->nmvcost_hp : x->nmvcost,
-          &cm->fc->nmvc, cm->allow_high_precision_mv);
-  } else {
-    if (!cpi->sf.use_nonrd_pick_mode || cm->frame_type == KEY_FRAME)
-      fill_token_costs(x->token_costs, cm->fc->coef_probs);
-
-    if (cpi->sf.partition_search_type != VAR_BASED_PARTITION ||
-        cm->frame_type == KEY_FRAME) {
-      for (i = 0; i < PARTITION_CONTEXTS; ++i)
-        vp9_cost_tokens(cpi->partition_cost[i], get_partition_probs(xd, i),
-                        vp9_partition_tree);
-    }
-
-    if (!cpi->sf.use_nonrd_pick_mode || (cm->current_video_frame & 0x07) == 1 ||
-        cm->frame_type == KEY_FRAME) {
-      fill_mode_costs(cpi);
-
-      if (!frame_is_intra_only(cm)) {
-        vp9_build_nmv_cost_table(
-            x->nmvjointcost,
-            cm->allow_high_precision_mv ? x->nmvcost_hp : x->nmvcost,
-            &cm->fc->nmvc, cm->allow_high_precision_mv);
-
-        for (i = 0; i < INTER_MODE_CONTEXTS; ++i)
-          vp9_cost_tokens((int *)cpi->inter_mode_cost[i],
-                          cm->fc->inter_mode_probs[i], vp9_inter_mode_tree);
-      }
-    }
-  }
-}
-
-static void model_rd_norm(int xsq_q10, int *r_q10, int *d_q10) {
-  // NOTE: The tables below must be of the same size.
-
-  // The functions described below are sampled at the four most significant
-  // bits of x^2 + 8 / 256.
-
-  // Normalized rate:
-  // This table models the rate for a Laplacian source with given variance
-  // when quantized with a uniform quantizer with given stepsize. The
-  // closed form expression is:
-  // Rn(x) = H(sqrt(r)) + sqrt(r)*[1 + H(r)/(1 - r)],
-  // where r = exp(-sqrt(2) * x) and x = qpstep / sqrt(variance),
-  // and H(x) is the binary entropy function.
-  static const int rate_tab_q10[] = {
-    65536,  6086,  5574,  5275,  5063,  4899,  4764,  4651,
-     4553,  4389,  4255,  4142,  4044,  3958,  3881,  3811,
-     3748,  3635,  3538,  3453,  3376,  3307,  3244,  3186,
-     3133,  3037,  2952,  2877,  2809,  2747,  2690,  2638,
-     2589,  2501,  2423,  2353,  2290,  2232,  2179,  2130,
-     2084,  2001,  1928,  1862,  1802,  1748,  1698,  1651,
-     1608,  1530,  1460,  1398,  1342,  1290,  1243,  1199,
-     1159,  1086,  1021,   963,   911,   864,   821,   781,
-      745,   680,   623,   574,   530,   490,   455,   424,
-      395,   345,   304,   269,   239,   213,   190,   171,
-      154,   126,   104,    87,    73,    61,    52,    44,
-       38,    28,    21,    16,    12,    10,     8,     6,
-        5,     3,     2,     1,     1,     1,     0,     0,
-  };
-  // Normalized distortion:
-  // This table models the normalized distortion for a Laplacian source
-  // with given variance when quantized with a uniform quantizer
-  // with given stepsize. The closed form expression is:
-  // Dn(x) = 1 - 1/sqrt(2) * x / sinh(x/sqrt(2))
-  // where x = qpstep / sqrt(variance).
-  // Note the actual distortion is Dn * variance.
-  static const int dist_tab_q10[] = {
-       0,     0,     1,     1,     1,     2,     2,     2,
-       3,     3,     4,     5,     5,     6,     7,     7,
-       8,     9,    11,    12,    13,    15,    16,    17,
-      18,    21,    24,    26,    29,    31,    34,    36,
-      39,    44,    49,    54,    59,    64,    69,    73,
-      78,    88,    97,   106,   115,   124,   133,   142,
-     151,   167,   184,   200,   215,   231,   245,   260,
-     274,   301,   327,   351,   375,   397,   418,   439,
-     458,   495,   528,   559,   587,   613,   637,   659,
-     680,   717,   749,   777,   801,   823,   842,   859,
-     874,   899,   919,   936,   949,   960,   969,   977,
-     983,   994,  1001,  1006,  1010,  1013,  1015,  1017,
-    1018,  1020,  1022,  1022,  1023,  1023,  1023,  1024,
-  };
-  static const int xsq_iq_q10[] = {
-         0,      4,      8,     12,     16,     20,     24,     28,
-        32,     40,     48,     56,     64,     72,     80,     88,
-        96,    112,    128,    144,    160,    176,    192,    208,
-       224,    256,    288,    320,    352,    384,    416,    448,
-       480,    544,    608,    672,    736,    800,    864,    928,
-       992,   1120,   1248,   1376,   1504,   1632,   1760,   1888,
-      2016,   2272,   2528,   2784,   3040,   3296,   3552,   3808,
-      4064,   4576,   5088,   5600,   6112,   6624,   7136,   7648,
-      8160,   9184,  10208,  11232,  12256,  13280,  14304,  15328,
-     16352,  18400,  20448,  22496,  24544,  26592,  28640,  30688,
-     32736,  36832,  40928,  45024,  49120,  53216,  57312,  61408,
-     65504,  73696,  81888,  90080,  98272, 106464, 114656, 122848,
-    131040, 147424, 163808, 180192, 196576, 212960, 229344, 245728,
-  };
-  const int tmp = (xsq_q10 >> 2) + 8;
-  const int k = get_msb(tmp) - 3;
-  const int xq = (k << 3) + ((tmp >> k) & 0x7);
-  const int one_q10 = 1 << 10;
-  const int a_q10 = ((xsq_q10 - xsq_iq_q10[xq]) << 10) >> (2 + k);
-  const int b_q10 = one_q10 - a_q10;
-  *r_q10 = (rate_tab_q10[xq] * b_q10 + rate_tab_q10[xq + 1] * a_q10) >> 10;
-  *d_q10 = (dist_tab_q10[xq] * b_q10 + dist_tab_q10[xq + 1] * a_q10) >> 10;
-}
-
-void vp9_model_rd_from_var_lapndz(unsigned int var, unsigned int n_log2,
-                                  unsigned int qstep, int *rate,
-                                  int64_t *dist) {
-  // This function models the rate and distortion for a Laplacian
-  // source with given variance when quantized with a uniform quantizer
-  // with given stepsize. The closed form expressions are in:
-  // Hang and Chen, "Source Model for transform video coder and its
-  // application - Part I: Fundamental Theory", IEEE Trans. Circ.
-  // Sys. for Video Tech., April 1997.
-  if (var == 0) {
-    *rate = 0;
-    *dist = 0;
-  } else {
-    int d_q10, r_q10;
-    static const uint32_t MAX_XSQ_Q10 = 245727;
-    const uint64_t xsq_q10_64 =
-        (((uint64_t)qstep * qstep << (n_log2 + 10)) + (var >> 1)) / var;
-    const int xsq_q10 = (int)VPXMIN(xsq_q10_64, MAX_XSQ_Q10);
-    model_rd_norm(xsq_q10, &r_q10, &d_q10);
-    *rate = ROUND_POWER_OF_TWO(r_q10 << n_log2, 10 - VP9_PROB_COST_SHIFT);
-    *dist = (var * (int64_t)d_q10 + 512) >> 10;
-  }
-}
-
-void vp9_get_entropy_contexts(BLOCK_SIZE bsize, TX_SIZE tx_size,
-                              const struct macroblockd_plane *pd,
-                              ENTROPY_CONTEXT t_above[16],
-                              ENTROPY_CONTEXT t_left[16]) {
-  const BLOCK_SIZE plane_bsize = get_plane_block_size(bsize, pd);
-  const int num_4x4_w = num_4x4_blocks_wide_lookup[plane_bsize];
-  const int num_4x4_h = num_4x4_blocks_high_lookup[plane_bsize];
-  const ENTROPY_CONTEXT *const above = pd->above_context;
-  const ENTROPY_CONTEXT *const left = pd->left_context;
-
-  int i;
-  switch (tx_size) {
-    case TX_4X4:
-      memcpy(t_above, above, sizeof(ENTROPY_CONTEXT) * num_4x4_w);
-      memcpy(t_left, left, sizeof(ENTROPY_CONTEXT) * num_4x4_h);
-      break;
-    case TX_8X8:
-      for (i = 0; i < num_4x4_w; i += 2)
-        t_above[i] = !!*(const uint16_t *)&above[i];
-      for (i = 0; i < num_4x4_h; i += 2)
-        t_left[i] = !!*(const uint16_t *)&left[i];
-      break;
-    case TX_16X16:
-      for (i = 0; i < num_4x4_w; i += 4)
-        t_above[i] = !!*(const uint32_t *)&above[i];
-      for (i = 0; i < num_4x4_h; i += 4)
-        t_left[i] = !!*(const uint32_t *)&left[i];
-      break;
-    case TX_32X32:
-      for (i = 0; i < num_4x4_w; i += 8)
-        t_above[i] = !!*(const uint64_t *)&above[i];
-      for (i = 0; i < num_4x4_h; i += 8)
-        t_left[i] = !!*(const uint64_t *)&left[i];
-      break;
-    default:
-      assert(0 && "Invalid transform size.");
-      break;
-  }
-}
-
-void vp9_mv_pred(VP9_COMP *cpi, MACROBLOCK *x,
-                 uint8_t *ref_y_buffer, int ref_y_stride,
-                 int ref_frame, BLOCK_SIZE block_size) {
-  int i;
-  int zero_seen = 0;
-  int best_index = 0;
-  int best_sad = INT_MAX;
-  int this_sad = INT_MAX;
-  int max_mv = 0;
-  int near_same_nearest;
-  uint8_t *src_y_ptr = x->plane[0].src.buf;
-  uint8_t *ref_y_ptr;
-  const int num_mv_refs = MAX_MV_REF_CANDIDATES +
-                    (cpi->sf.adaptive_motion_search &&
-                     block_size < x->max_partition_size);
-
-  MV pred_mv[3];
-  pred_mv[0] = x->mbmi_ext->ref_mvs[ref_frame][0].as_mv;
-  pred_mv[1] = x->mbmi_ext->ref_mvs[ref_frame][1].as_mv;
-  pred_mv[2] = x->pred_mv[ref_frame];
-  assert(num_mv_refs <= (int)(sizeof(pred_mv) / sizeof(pred_mv[0])));
-
-  near_same_nearest =
-      x->mbmi_ext->ref_mvs[ref_frame][0].as_int ==
-          x->mbmi_ext->ref_mvs[ref_frame][1].as_int;
-  // Get the sad for each candidate reference mv.
-  for (i = 0; i < num_mv_refs; ++i) {
-    const MV *this_mv = &pred_mv[i];
-    int fp_row, fp_col;
-
-    if (i == 1 && near_same_nearest)
-      continue;
-    fp_row = (this_mv->row + 3 + (this_mv->row >= 0)) >> 3;
-    fp_col = (this_mv->col + 3 + (this_mv->col >= 0)) >> 3;
-    max_mv = VPXMAX(max_mv, VPXMAX(abs(this_mv->row), abs(this_mv->col)) >> 3);
-
-    if (fp_row ==0 && fp_col == 0 && zero_seen)
-      continue;
-    zero_seen |= (fp_row ==0 && fp_col == 0);
-
-    ref_y_ptr =&ref_y_buffer[ref_y_stride * fp_row + fp_col];
-    // Find sad for current vector.
-    this_sad = cpi->fn_ptr[block_size].sdf(src_y_ptr, x->plane[0].src.stride,
-                                           ref_y_ptr, ref_y_stride);
-    // Note if it is the best so far.
-    if (this_sad < best_sad) {
-      best_sad = this_sad;
-      best_index = i;
-    }
-  }
-
-  // Note the index of the mv that worked best in the reference list.
-  x->mv_best_ref_index[ref_frame] = best_index;
-  x->max_mv_context[ref_frame] = max_mv;
-  x->pred_mv_sad[ref_frame] = best_sad;
-}
-
-void vp9_setup_pred_block(const MACROBLOCKD *xd,
-                          struct buf_2d dst[MAX_MB_PLANE],
-                          const YV12_BUFFER_CONFIG *src,
-                          int mi_row, int mi_col,
-                          const struct scale_factors *scale,
-                          const struct scale_factors *scale_uv) {
-  int i;
-
-  dst[0].buf = src->y_buffer;
-  dst[0].stride = src->y_stride;
-  dst[1].buf = src->u_buffer;
-  dst[2].buf = src->v_buffer;
-  dst[1].stride = dst[2].stride = src->uv_stride;
-
-  for (i = 0; i < MAX_MB_PLANE; ++i) {
-    setup_pred_plane(dst + i, dst[i].buf, dst[i].stride, mi_row, mi_col,
-                     i ? scale_uv : scale,
-                     xd->plane[i].subsampling_x, xd->plane[i].subsampling_y);
-  }
-}
-
-int vp9_raster_block_offset(BLOCK_SIZE plane_bsize,
-                            int raster_block, int stride) {
-  const int bw = b_width_log2_lookup[plane_bsize];
-  const int y = 4 * (raster_block >> bw);
-  const int x = 4 * (raster_block & ((1 << bw) - 1));
-  return y * stride + x;
-}
-
-int16_t* vp9_raster_block_offset_int16(BLOCK_SIZE plane_bsize,
-                                       int raster_block, int16_t *base) {
-  const int stride = 4 * num_4x4_blocks_wide_lookup[plane_bsize];
-  return base + vp9_raster_block_offset(plane_bsize, raster_block, stride);
-}
-
-YV12_BUFFER_CONFIG *vp9_get_scaled_ref_frame(const VP9_COMP *cpi,
-                                             int ref_frame) {
-  const VP9_COMMON *const cm = &cpi->common;
-  const int scaled_idx = cpi->scaled_ref_idx[ref_frame - 1];
-  const int ref_idx = get_ref_frame_buf_idx(cpi, ref_frame);
-  return
-      (scaled_idx != ref_idx && scaled_idx != INVALID_IDX) ?
-          &cm->buffer_pool->frame_bufs[scaled_idx].buf : NULL;
-}
-
-int vp9_get_switchable_rate(const VP9_COMP *cpi, const MACROBLOCKD *const xd) {
-  const MODE_INFO *const mi = xd->mi[0];
-  const int ctx = vp9_get_pred_context_switchable_interp(xd);
-  return SWITCHABLE_INTERP_RATE_FACTOR *
-             cpi->switchable_interp_costs[ctx][mi->interp_filter];
-}
-
-void vp9_set_rd_speed_thresholds(VP9_COMP *cpi) {
-  int i;
-  RD_OPT *const rd = &cpi->rd;
-  SPEED_FEATURES *const sf = &cpi->sf;
-
-  // Set baseline threshold values.
-  for (i = 0; i < MAX_MODES; ++i)
-    rd->thresh_mult[i] = cpi->oxcf.mode == BEST ? -500 : 0;
-
-  if (sf->adaptive_rd_thresh) {
-    rd->thresh_mult[THR_NEARESTMV] = 300;
-    rd->thresh_mult[THR_NEARESTG] = 300;
-    rd->thresh_mult[THR_NEARESTA] = 300;
-  } else {
-    rd->thresh_mult[THR_NEARESTMV] = 0;
-    rd->thresh_mult[THR_NEARESTG] = 0;
-    rd->thresh_mult[THR_NEARESTA] = 0;
-  }
-
-  rd->thresh_mult[THR_DC] += 1000;
-
-  rd->thresh_mult[THR_NEWMV] += 1000;
-  rd->thresh_mult[THR_NEWA] += 1000;
-  rd->thresh_mult[THR_NEWG] += 1000;
-
-  rd->thresh_mult[THR_NEARMV] += 1000;
-  rd->thresh_mult[THR_NEARA] += 1000;
-  rd->thresh_mult[THR_NEARG] += 1000;
-
-  rd->thresh_mult[THR_ZEROMV] += 2000;
-  rd->thresh_mult[THR_ZEROG] += 2000;
-  rd->thresh_mult[THR_ZEROA] += 2000;
-
-  rd->thresh_mult[THR_COMP_NEARESTLA] += 1000;
-  rd->thresh_mult[THR_COMP_NEARESTGA] += 1000;
-
-  rd->thresh_mult[THR_TM] += 1000;
-
-  rd->thresh_mult[THR_COMP_NEARLA] += 1500;
-  rd->thresh_mult[THR_COMP_NEWLA] += 2000;
-  rd->thresh_mult[THR_COMP_NEARGA] += 1500;
-  rd->thresh_mult[THR_COMP_NEWGA] += 2000;
-
-  rd->thresh_mult[THR_COMP_ZEROLA] += 2500;
-  rd->thresh_mult[THR_COMP_ZEROGA] += 2500;
-
-  rd->thresh_mult[THR_H_PRED] += 2000;
-  rd->thresh_mult[THR_V_PRED] += 2000;
-  rd->thresh_mult[THR_D45_PRED ] += 2500;
-  rd->thresh_mult[THR_D135_PRED] += 2500;
-  rd->thresh_mult[THR_D117_PRED] += 2500;
-  rd->thresh_mult[THR_D153_PRED] += 2500;
-  rd->thresh_mult[THR_D207_PRED] += 2500;
-  rd->thresh_mult[THR_D63_PRED] += 2500;
-}
-
-void vp9_set_rd_speed_thresholds_sub8x8(VP9_COMP *cpi) {
-  static const int thresh_mult[2][MAX_REFS] = {
-    {2500, 2500, 2500, 4500, 4500, 2500},
-    {2000, 2000, 2000, 4000, 4000, 2000}
-  };
-  RD_OPT *const rd = &cpi->rd;
-  const int idx = cpi->oxcf.mode == BEST;
-  memcpy(rd->thresh_mult_sub8x8, thresh_mult[idx], sizeof(thresh_mult[idx]));
-}
-
-void vp9_update_rd_thresh_fact(int (*factor_buf)[MAX_MODES], int rd_thresh,
-                               int bsize, int best_mode_index) {
-  if (rd_thresh > 0) {
-    const int top_mode = bsize < BLOCK_8X8 ? MAX_REFS : MAX_MODES;
-    int mode;
-    for (mode = 0; mode < top_mode; ++mode) {
-      const BLOCK_SIZE min_size = VPXMAX(bsize - 1, BLOCK_4X4);
-      const BLOCK_SIZE max_size = VPXMIN(bsize + 2, BLOCK_64X64);
-      BLOCK_SIZE bs;
-      for (bs = min_size; bs <= max_size; ++bs) {
-        int *const fact = &factor_buf[bs][mode];
-        if (mode == best_mode_index) {
-          *fact -= (*fact >> 4);
-        } else {
-          *fact = VPXMIN(*fact + RD_THRESH_INC, rd_thresh * RD_THRESH_MAX_FACT);
-        }
-      }
-    }
-  }
-}
-
-int vp9_get_intra_cost_penalty(int qindex, int qdelta,
-                               vpx_bit_depth_t bit_depth) {
-  const int q = vp9_dc_quant(qindex, qdelta, bit_depth);
-#if CONFIG_VP9_HIGHBITDEPTH
-  switch (bit_depth) {
-    case VPX_BITS_8:
-      return 20 * q;
-    case VPX_BITS_10:
-      return 5 * q;
-    case VPX_BITS_12:
-      return ROUND_POWER_OF_TWO(5 * q, 2);
-    default:
-      assert(0 && "bit_depth should be VPX_BITS_8, VPX_BITS_10 or VPX_BITS_12");
-      return -1;
-  }
-#else
-  return 20 * q;
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-}
-
diff --git a/vp9/encoder/vp9_rd.h b/vp9/encoder/vp9_rd.h
deleted file mode 100644 (file)
index 9b8e273..0000000
+++ /dev/null
@@ -1,204 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#ifndef VP9_ENCODER_VP9_RD_H_
-#define VP9_ENCODER_VP9_RD_H_
-
-#include <limits.h>
-
-#include "vp9/common/vp9_blockd.h"
-
-#include "vp9/encoder/vp9_block.h"
-#include "vp9/encoder/vp9_context_tree.h"
-#include "vp9/encoder/vp9_cost.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define RDDIV_BITS          7
-#define RD_EPB_SHIFT        6
-
-#define RDCOST(RM, DM, R, D) \
-  (ROUND_POWER_OF_TWO(((int64_t)R) * (RM), VP9_PROB_COST_SHIFT) + (D << DM))
-#define QIDX_SKIP_THRESH     115
-
-#define MV_COST_WEIGHT      108
-#define MV_COST_WEIGHT_SUB  120
-
-#define INVALID_MV 0x80008000
-
-#define MAX_MODES 30
-#define MAX_REFS  6
-
-#define RD_THRESH_MAX_FACT 64
-#define RD_THRESH_INC      1
-
-// This enumerator type needs to be kept aligned with the mode order in
-// const MODE_DEFINITION vp9_mode_order[MAX_MODES] used in the rd code.
-typedef enum {
-  THR_NEARESTMV,
-  THR_NEARESTA,
-  THR_NEARESTG,
-
-  THR_DC,
-
-  THR_NEWMV,
-  THR_NEWA,
-  THR_NEWG,
-
-  THR_NEARMV,
-  THR_NEARA,
-  THR_NEARG,
-
-  THR_ZEROMV,
-  THR_ZEROG,
-  THR_ZEROA,
-
-  THR_COMP_NEARESTLA,
-  THR_COMP_NEARESTGA,
-
-  THR_TM,
-
-  THR_COMP_NEARLA,
-  THR_COMP_NEWLA,
-  THR_COMP_NEARGA,
-  THR_COMP_NEWGA,
-
-  THR_COMP_ZEROLA,
-  THR_COMP_ZEROGA,
-
-  THR_H_PRED,
-  THR_V_PRED,
-  THR_D135_PRED,
-  THR_D207_PRED,
-  THR_D153_PRED,
-  THR_D63_PRED,
-  THR_D117_PRED,
-  THR_D45_PRED,
-} THR_MODES;
-
-typedef enum {
-  THR_LAST,
-  THR_GOLD,
-  THR_ALTR,
-  THR_COMP_LA,
-  THR_COMP_GA,
-  THR_INTRA,
-} THR_MODES_SUB8X8;
-
-typedef struct RD_OPT {
-  // Thresh_mult is used to set a threshold for the rd score. A higher value
-  // means that we will accept the best mode so far more often. This number
-  // is used in combination with the current block size, and thresh_freq_fact
-  // to pick a threshold.
-  int thresh_mult[MAX_MODES];
-  int thresh_mult_sub8x8[MAX_REFS];
-
-  int threshes[MAX_SEGMENTS][BLOCK_SIZES][MAX_MODES];
-
-  int64_t prediction_type_threshes[MAX_REF_FRAMES][REFERENCE_MODES];
-
-  int64_t filter_threshes[MAX_REF_FRAMES][SWITCHABLE_FILTER_CONTEXTS];
-
-  int RDMULT;
-  int RDDIV;
-} RD_OPT;
-
-typedef struct RD_COST {
-  int rate;
-  int64_t dist;
-  int64_t rdcost;
-} RD_COST;
-
-// Reset the rate distortion cost values to maximum (invalid) value.
-void vp9_rd_cost_reset(RD_COST *rd_cost);
-// Initialize the rate distortion cost values to zero.
-void vp9_rd_cost_init(RD_COST *rd_cost);
-
-struct TileInfo;
-struct TileDataEnc;
-struct VP9_COMP;
-struct macroblock;
-
-int vp9_compute_rd_mult(const struct VP9_COMP *cpi, int qindex);
-
-void vp9_initialize_rd_consts(struct VP9_COMP *cpi);
-
-void vp9_initialize_me_consts(struct VP9_COMP *cpi, MACROBLOCK *x, int qindex);
-
-void vp9_model_rd_from_var_lapndz(unsigned int var, unsigned int n,
-                                  unsigned int qstep, int *rate,
-                                  int64_t *dist);
-
-int vp9_get_switchable_rate(const struct VP9_COMP *cpi,
-                            const MACROBLOCKD *const xd);
-
-int vp9_raster_block_offset(BLOCK_SIZE plane_bsize,
-                            int raster_block, int stride);
-
-int16_t* vp9_raster_block_offset_int16(BLOCK_SIZE plane_bsize,
-                                       int raster_block, int16_t *base);
-
-YV12_BUFFER_CONFIG *vp9_get_scaled_ref_frame(const struct VP9_COMP *cpi,
-                                             int ref_frame);
-
-void vp9_init_me_luts(void);
-
-void vp9_get_entropy_contexts(BLOCK_SIZE bsize, TX_SIZE tx_size,
-                              const struct macroblockd_plane *pd,
-                              ENTROPY_CONTEXT t_above[16],
-                              ENTROPY_CONTEXT t_left[16]);
-
-void vp9_set_rd_speed_thresholds(struct VP9_COMP *cpi);
-
-void vp9_set_rd_speed_thresholds_sub8x8(struct VP9_COMP *cpi);
-
-void vp9_update_rd_thresh_fact(int (*fact)[MAX_MODES], int rd_thresh,
-                               int bsize, int best_mode_index);
-
-static INLINE int rd_less_than_thresh(int64_t best_rd, int thresh,
-                                      int thresh_fact) {
-    return best_rd < ((int64_t)thresh * thresh_fact >> 5) || thresh == INT_MAX;
-}
-
-static INLINE void set_error_per_bit(MACROBLOCK *x, int rdmult) {
-  x->errorperbit = rdmult >> RD_EPB_SHIFT;
-  x->errorperbit += (x->errorperbit == 0);
-}
-
-void vp9_mv_pred(struct VP9_COMP *cpi, MACROBLOCK *x,
-                 uint8_t *ref_y_buffer, int ref_y_stride,
-                 int ref_frame, BLOCK_SIZE block_size);
-
-void vp9_setup_pred_block(const MACROBLOCKD *xd,
-                          struct buf_2d dst[MAX_MB_PLANE],
-                          const YV12_BUFFER_CONFIG *src,
-                          int mi_row, int mi_col,
-                          const struct scale_factors *scale,
-                          const struct scale_factors *scale_uv);
-
-int vp9_get_intra_cost_penalty(int qindex, int qdelta,
-                               vpx_bit_depth_t bit_depth);
-
-unsigned int vp9_get_sby_perpixel_variance(struct VP9_COMP *cpi,
-                                           const struct buf_2d *ref,
-                                           BLOCK_SIZE bs);
-#if CONFIG_VP9_HIGHBITDEPTH
-unsigned int vp9_high_get_sby_perpixel_variance(struct VP9_COMP *cpi,
-                                                const struct buf_2d *ref,
-                                                BLOCK_SIZE bs, int bd);
-#endif
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP9_ENCODER_VP9_RD_H_
diff --git a/vp9/encoder/vp9_rdopt.c b/vp9/encoder/vp9_rdopt.c
deleted file mode 100644 (file)
index 0ed0850..0000000
+++ /dev/null
@@ -1,4397 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#include <assert.h>
-#include <math.h>
-
-#include "./vp9_rtcd.h"
-#include "./vpx_dsp_rtcd.h"
-
-#include "vpx_dsp/vpx_dsp_common.h"
-#include "vpx_mem/vpx_mem.h"
-#include "vpx_ports/mem.h"
-#include "vpx_ports/system_state.h"
-
-#include "vp9/common/vp9_common.h"
-#include "vp9/common/vp9_entropy.h"
-#include "vp9/common/vp9_entropymode.h"
-#include "vp9/common/vp9_idct.h"
-#include "vp9/common/vp9_mvref_common.h"
-#include "vp9/common/vp9_pred_common.h"
-#include "vp9/common/vp9_quant_common.h"
-#include "vp9/common/vp9_reconinter.h"
-#include "vp9/common/vp9_reconintra.h"
-#include "vp9/common/vp9_scan.h"
-#include "vp9/common/vp9_seg_common.h"
-
-#include "vp9/encoder/vp9_cost.h"
-#include "vp9/encoder/vp9_encodemb.h"
-#include "vp9/encoder/vp9_encodemv.h"
-#include "vp9/encoder/vp9_encoder.h"
-#include "vp9/encoder/vp9_mcomp.h"
-#include "vp9/encoder/vp9_quantize.h"
-#include "vp9/encoder/vp9_ratectrl.h"
-#include "vp9/encoder/vp9_rd.h"
-#include "vp9/encoder/vp9_rdopt.h"
-#include "vp9/encoder/vp9_aq_variance.h"
-
-#define LAST_FRAME_MODE_MASK    ((1 << GOLDEN_FRAME) | (1 << ALTREF_FRAME) | \
-                                 (1 << INTRA_FRAME))
-#define GOLDEN_FRAME_MODE_MASK  ((1 << LAST_FRAME) | (1 << ALTREF_FRAME) | \
-                                 (1 << INTRA_FRAME))
-#define ALT_REF_MODE_MASK       ((1 << LAST_FRAME) | (1 << GOLDEN_FRAME) | \
-                                 (1 << INTRA_FRAME))
-
-#define SECOND_REF_FRAME_MASK   ((1 << ALTREF_FRAME) | 0x01)
-
-#define MIN_EARLY_TERM_INDEX    3
-#define NEW_MV_DISCOUNT_FACTOR  8
-
-typedef struct {
-  PREDICTION_MODE mode;
-  MV_REFERENCE_FRAME ref_frame[2];
-} MODE_DEFINITION;
-
-typedef struct {
-  MV_REFERENCE_FRAME ref_frame[2];
-} REF_DEFINITION;
-
-struct rdcost_block_args {
-  MACROBLOCK *x;
-  ENTROPY_CONTEXT t_above[16];
-  ENTROPY_CONTEXT t_left[16];
-  int this_rate;
-  int64_t this_dist;
-  int64_t this_sse;
-  int64_t this_rd;
-  int64_t best_rd;
-  int exit_early;
-  int use_fast_coef_costing;
-  const scan_order *so;
-  uint8_t skippable;
-};
-
-#define LAST_NEW_MV_INDEX 6
-static const MODE_DEFINITION vp9_mode_order[MAX_MODES] = {
-  {NEARESTMV, {LAST_FRAME,   NONE}},
-  {NEARESTMV, {ALTREF_FRAME, NONE}},
-  {NEARESTMV, {GOLDEN_FRAME, NONE}},
-
-  {DC_PRED,   {INTRA_FRAME,  NONE}},
-
-  {NEWMV,     {LAST_FRAME,   NONE}},
-  {NEWMV,     {ALTREF_FRAME, NONE}},
-  {NEWMV,     {GOLDEN_FRAME, NONE}},
-
-  {NEARMV,    {LAST_FRAME,   NONE}},
-  {NEARMV,    {ALTREF_FRAME, NONE}},
-  {NEARMV,    {GOLDEN_FRAME, NONE}},
-
-  {ZEROMV,    {LAST_FRAME,   NONE}},
-  {ZEROMV,    {GOLDEN_FRAME, NONE}},
-  {ZEROMV,    {ALTREF_FRAME, NONE}},
-
-  {NEARESTMV, {LAST_FRAME,   ALTREF_FRAME}},
-  {NEARESTMV, {GOLDEN_FRAME, ALTREF_FRAME}},
-
-  {TM_PRED,   {INTRA_FRAME,  NONE}},
-
-  {NEARMV,    {LAST_FRAME,   ALTREF_FRAME}},
-  {NEWMV,     {LAST_FRAME,   ALTREF_FRAME}},
-  {NEARMV,    {GOLDEN_FRAME, ALTREF_FRAME}},
-  {NEWMV,     {GOLDEN_FRAME, ALTREF_FRAME}},
-
-  {ZEROMV,    {LAST_FRAME,   ALTREF_FRAME}},
-  {ZEROMV,    {GOLDEN_FRAME, ALTREF_FRAME}},
-
-  {H_PRED,    {INTRA_FRAME,  NONE}},
-  {V_PRED,    {INTRA_FRAME,  NONE}},
-  {D135_PRED, {INTRA_FRAME,  NONE}},
-  {D207_PRED, {INTRA_FRAME,  NONE}},
-  {D153_PRED, {INTRA_FRAME,  NONE}},
-  {D63_PRED,  {INTRA_FRAME,  NONE}},
-  {D117_PRED, {INTRA_FRAME,  NONE}},
-  {D45_PRED,  {INTRA_FRAME,  NONE}},
-};
-
-static const REF_DEFINITION vp9_ref_order[MAX_REFS] = {
-  {{LAST_FRAME,   NONE}},
-  {{GOLDEN_FRAME, NONE}},
-  {{ALTREF_FRAME, NONE}},
-  {{LAST_FRAME,   ALTREF_FRAME}},
-  {{GOLDEN_FRAME, ALTREF_FRAME}},
-  {{INTRA_FRAME,  NONE}},
-};
-
-static void swap_block_ptr(MACROBLOCK *x, PICK_MODE_CONTEXT *ctx,
-                           int m, int n, int min_plane, int max_plane) {
-  int i;
-
-  for (i = min_plane; i < max_plane; ++i) {
-    struct macroblock_plane *const p = &x->plane[i];
-    struct macroblockd_plane *const pd = &x->e_mbd.plane[i];
-
-    p->coeff    = ctx->coeff_pbuf[i][m];
-    p->qcoeff   = ctx->qcoeff_pbuf[i][m];
-    pd->dqcoeff = ctx->dqcoeff_pbuf[i][m];
-    p->eobs     = ctx->eobs_pbuf[i][m];
-
-    ctx->coeff_pbuf[i][m]   = ctx->coeff_pbuf[i][n];
-    ctx->qcoeff_pbuf[i][m]  = ctx->qcoeff_pbuf[i][n];
-    ctx->dqcoeff_pbuf[i][m] = ctx->dqcoeff_pbuf[i][n];
-    ctx->eobs_pbuf[i][m]    = ctx->eobs_pbuf[i][n];
-
-    ctx->coeff_pbuf[i][n]   = p->coeff;
-    ctx->qcoeff_pbuf[i][n]  = p->qcoeff;
-    ctx->dqcoeff_pbuf[i][n] = pd->dqcoeff;
-    ctx->eobs_pbuf[i][n]    = p->eobs;
-  }
-}
-
-static void model_rd_for_sb(VP9_COMP *cpi, BLOCK_SIZE bsize,
-                            MACROBLOCK *x, MACROBLOCKD *xd,
-                            int *out_rate_sum, int64_t *out_dist_sum,
-                            int *skip_txfm_sb, int64_t *skip_sse_sb) {
-  // Note our transform coeffs are 8 times an orthogonal transform.
-  // Hence quantizer step is also 8 times. To get effective quantizer
-  // we need to divide by 8 before sending to modeling function.
-  int i;
-  int64_t rate_sum = 0;
-  int64_t dist_sum = 0;
-  const int ref = xd->mi[0]->ref_frame[0];
-  unsigned int sse;
-  unsigned int var = 0;
-  unsigned int sum_sse = 0;
-  int64_t total_sse = 0;
-  int skip_flag = 1;
-  const int shift = 6;
-  int rate;
-  int64_t dist;
-  const int dequant_shift =
-#if CONFIG_VP9_HIGHBITDEPTH
-      (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) ?
-          xd->bd - 5 :
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-          3;
-
-  x->pred_sse[ref] = 0;
-
-  for (i = 0; i < MAX_MB_PLANE; ++i) {
-    struct macroblock_plane *const p = &x->plane[i];
-    struct macroblockd_plane *const pd = &xd->plane[i];
-    const BLOCK_SIZE bs = get_plane_block_size(bsize, pd);
-    const TX_SIZE max_tx_size = max_txsize_lookup[bs];
-    const BLOCK_SIZE unit_size = txsize_to_bsize[max_tx_size];
-    const int64_t dc_thr = p->quant_thred[0] >> shift;
-    const int64_t ac_thr = p->quant_thred[1] >> shift;
-    // The low thresholds are used to measure if the prediction errors are
-    // low enough so that we can skip the mode search.
-    const int64_t low_dc_thr = VPXMIN(50, dc_thr >> 2);
-    const int64_t low_ac_thr = VPXMIN(80, ac_thr >> 2);
-    int bw = 1 << (b_width_log2_lookup[bs] - b_width_log2_lookup[unit_size]);
-    int bh = 1 << (b_height_log2_lookup[bs] - b_width_log2_lookup[unit_size]);
-    int idx, idy;
-    int lw = b_width_log2_lookup[unit_size] + 2;
-    int lh = b_height_log2_lookup[unit_size] + 2;
-
-    sum_sse = 0;
-
-    for (idy = 0; idy < bh; ++idy) {
-      for (idx = 0; idx < bw; ++idx) {
-        uint8_t *src = p->src.buf + (idy * p->src.stride << lh) + (idx << lw);
-        uint8_t *dst = pd->dst.buf + (idy * pd->dst.stride << lh) + (idx << lh);
-        int block_idx = (idy << 1) + idx;
-        int low_err_skip = 0;
-
-        var = cpi->fn_ptr[unit_size].vf(src, p->src.stride,
-                                        dst, pd->dst.stride, &sse);
-        x->bsse[(i << 2) + block_idx] = sse;
-        sum_sse += sse;
-
-        x->skip_txfm[(i << 2) + block_idx] = SKIP_TXFM_NONE;
-        if (!x->select_tx_size) {
-          // Check if all ac coefficients can be quantized to zero.
-          if (var < ac_thr || var == 0) {
-            x->skip_txfm[(i << 2) + block_idx] = SKIP_TXFM_AC_ONLY;
-
-            // Check if dc coefficient can be quantized to zero.
-            if (sse - var < dc_thr || sse == var) {
-              x->skip_txfm[(i << 2) + block_idx] = SKIP_TXFM_AC_DC;
-
-              if (!sse || (var < low_ac_thr && sse - var < low_dc_thr))
-                low_err_skip = 1;
-            }
-          }
-        }
-
-        if (skip_flag && !low_err_skip)
-          skip_flag = 0;
-
-        if (i == 0)
-          x->pred_sse[ref] += sse;
-      }
-    }
-
-    total_sse += sum_sse;
-
-    // Fast approximate the modelling function.
-    if (cpi->sf.simple_model_rd_from_var) {
-      int64_t rate;
-      const int64_t square_error = sum_sse;
-      int quantizer = (pd->dequant[1] >> dequant_shift);
-
-      if (quantizer < 120)
-        rate = (square_error * (280 - quantizer)) >> (16 - VP9_PROB_COST_SHIFT);
-      else
-        rate = 0;
-      dist = (square_error * quantizer) >> 8;
-      rate_sum += rate;
-      dist_sum += dist;
-    } else {
-      vp9_model_rd_from_var_lapndz(sum_sse, num_pels_log2_lookup[bs],
-                                   pd->dequant[1] >> dequant_shift,
-                                   &rate, &dist);
-      rate_sum += rate;
-      dist_sum += dist;
-    }
-  }
-
-  *skip_txfm_sb = skip_flag;
-  *skip_sse_sb = total_sse << 4;
-  *out_rate_sum = (int)rate_sum;
-  *out_dist_sum = dist_sum << 4;
-}
-
-#if CONFIG_VP9_HIGHBITDEPTH
-int64_t vp9_highbd_block_error_c(const tran_low_t *coeff,
-                                 const tran_low_t *dqcoeff,
-                                 intptr_t block_size,
-                                 int64_t *ssz, int bd) {
-  int i;
-  int64_t error = 0, sqcoeff = 0;
-  int shift = 2 * (bd - 8);
-  int rounding = shift > 0 ? 1 << (shift - 1) : 0;
-
-  for (i = 0; i < block_size; i++) {
-    const int64_t diff = coeff[i] - dqcoeff[i];
-    error +=  diff * diff;
-    sqcoeff += (int64_t)coeff[i] * (int64_t)coeff[i];
-  }
-  assert(error >= 0 && sqcoeff >= 0);
-  error = (error + rounding) >> shift;
-  sqcoeff = (sqcoeff + rounding) >> shift;
-
-  *ssz = sqcoeff;
-  return error;
-}
-
-int64_t vp9_highbd_block_error_8bit_c(const tran_low_t *coeff,
-                                      const tran_low_t *dqcoeff,
-                                      intptr_t block_size,
-                                      int64_t *ssz) {
-  // Note that the C versions of these 2 functions (vp9_block_error and
-  // vp9_highbd_block_error_8bit are the same, but the optimized assembly
-  // routines are not compatible in the non high bitdepth configuration, so
-  // they still cannot share the same name.
-  return vp9_block_error_c(coeff, dqcoeff, block_size, ssz);
-}
-
-static int64_t vp9_highbd_block_error_dispatch(const tran_low_t *coeff,
-                                               const tran_low_t *dqcoeff,
-                                               intptr_t block_size,
-                                               int64_t *ssz, int bd) {
-  if (bd == 8) {
-    return vp9_highbd_block_error_8bit(coeff, dqcoeff, block_size, ssz);
-  } else {
-    return vp9_highbd_block_error(coeff, dqcoeff, block_size, ssz, bd);
-  }
-}
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-
-int64_t vp9_block_error_c(const tran_low_t *coeff, const tran_low_t *dqcoeff,
-                          intptr_t block_size, int64_t *ssz) {
-  int i;
-  int64_t error = 0, sqcoeff = 0;
-
-  for (i = 0; i < block_size; i++) {
-    const int diff = coeff[i] - dqcoeff[i];
-    error +=  diff * diff;
-    sqcoeff += coeff[i] * coeff[i];
-  }
-
-  *ssz = sqcoeff;
-  return error;
-}
-
-int64_t vp9_block_error_fp_c(const int16_t *coeff, const int16_t *dqcoeff,
-                             int block_size) {
-  int i;
-  int64_t error = 0;
-
-  for (i = 0; i < block_size; i++) {
-    const int diff = coeff[i] - dqcoeff[i];
-    error +=  diff * diff;
-  }
-
-  return error;
-}
-
-/* The trailing '0' is a terminator which is used inside cost_coeffs() to
- * decide whether to include cost of a trailing EOB node or not (i.e. we
- * can skip this if the last coefficient in this transform block, e.g. the
- * 16th coefficient in a 4x4 block or the 64th coefficient in a 8x8 block,
- * were non-zero). */
-static const int16_t band_counts[TX_SIZES][8] = {
-  { 1, 2, 3, 4,  3,   16 - 13, 0 },
-  { 1, 2, 3, 4, 11,   64 - 21, 0 },
-  { 1, 2, 3, 4, 11,  256 - 21, 0 },
-  { 1, 2, 3, 4, 11, 1024 - 21, 0 },
-};
-static int cost_coeffs(MACROBLOCK *x,
-                       int plane, int block,
-                       ENTROPY_CONTEXT *A, ENTROPY_CONTEXT *L,
-                       TX_SIZE tx_size,
-                       const int16_t *scan, const int16_t *nb,
-                       int use_fast_coef_costing) {
-  MACROBLOCKD *const xd = &x->e_mbd;
-  MODE_INFO *mi = xd->mi[0];
-  const struct macroblock_plane *p = &x->plane[plane];
-  const PLANE_TYPE type = get_plane_type(plane);
-  const int16_t *band_count = &band_counts[tx_size][1];
-  const int eob = p->eobs[block];
-  const tran_low_t *const qcoeff = BLOCK_OFFSET(p->qcoeff, block);
-  unsigned int (*token_costs)[2][COEFF_CONTEXTS][ENTROPY_TOKENS] =
-                   x->token_costs[tx_size][type][is_inter_block(mi)];
-  uint8_t token_cache[32 * 32];
-  int pt = combine_entropy_contexts(*A, *L);
-  int c, cost;
-#if CONFIG_VP9_HIGHBITDEPTH
-  const int *cat6_high_cost = vp9_get_high_cost_table(xd->bd);
-#else
-  const int *cat6_high_cost = vp9_get_high_cost_table(8);
-#endif
-
-  // Check for consistency of tx_size with mode info
-  assert(type == PLANE_TYPE_Y ? mi->tx_size == tx_size :
-         get_uv_tx_size(mi, &xd->plane[plane]) == tx_size);
-
-  if (eob == 0) {
-    // single eob token
-    cost = token_costs[0][0][pt][EOB_TOKEN];
-    c = 0;
-  } else {
-    if (use_fast_coef_costing) {
-      int band_left = *band_count++;
-
-      // dc token
-      int v = qcoeff[0];
-      int16_t prev_t;
-      cost = vp9_get_token_cost(v, &prev_t, cat6_high_cost);
-      cost += (*token_costs)[0][pt][prev_t];
-
-      token_cache[0] = vp9_pt_energy_class[prev_t];
-      ++token_costs;
-
-      // ac tokens
-      for (c = 1; c < eob; c++) {
-        const int rc = scan[c];
-        int16_t t;
-
-        v = qcoeff[rc];
-        cost += vp9_get_token_cost(v, &t, cat6_high_cost);
-        cost += (*token_costs)[!prev_t][!prev_t][t];
-        prev_t = t;
-        if (!--band_left) {
-          band_left = *band_count++;
-          ++token_costs;
-        }
-      }
-
-      // eob token
-      if (band_left)
-        cost += (*token_costs)[0][!prev_t][EOB_TOKEN];
-
-    } else {  // !use_fast_coef_costing
-      int band_left = *band_count++;
-
-      // dc token
-      int v = qcoeff[0];
-      int16_t tok;
-      unsigned int (*tok_cost_ptr)[COEFF_CONTEXTS][ENTROPY_TOKENS];
-      cost = vp9_get_token_cost(v, &tok, cat6_high_cost);
-      cost += (*token_costs)[0][pt][tok];
-
-      token_cache[0] = vp9_pt_energy_class[tok];
-      ++token_costs;
-
-      tok_cost_ptr = &((*token_costs)[!tok]);
-
-      // ac tokens
-      for (c = 1; c < eob; c++) {
-        const int rc = scan[c];
-
-        v = qcoeff[rc];
-        cost += vp9_get_token_cost(v, &tok, cat6_high_cost);
-        pt = get_coef_context(nb, token_cache, c);
-        cost += (*tok_cost_ptr)[pt][tok];
-        token_cache[rc] = vp9_pt_energy_class[tok];
-        if (!--band_left) {
-          band_left = *band_count++;
-          ++token_costs;
-        }
-        tok_cost_ptr = &((*token_costs)[!tok]);
-      }
-
-      // eob token
-      if (band_left) {
-        pt = get_coef_context(nb, token_cache, c);
-        cost += (*token_costs)[0][pt][EOB_TOKEN];
-      }
-    }
-  }
-
-  // is eob first coefficient;
-  *A = *L = (c > 0);
-
-  return cost;
-}
-
-static void dist_block(MACROBLOCK *x, int plane, int block, TX_SIZE tx_size,
-                       int64_t *out_dist, int64_t *out_sse) {
-  const int ss_txfrm_size = tx_size << 1;
-  MACROBLOCKD* const xd = &x->e_mbd;
-  const struct macroblock_plane *const p = &x->plane[plane];
-  const struct macroblockd_plane *const pd = &xd->plane[plane];
-  int64_t this_sse;
-  int shift = tx_size == TX_32X32 ? 0 : 2;
-  tran_low_t *const coeff = BLOCK_OFFSET(p->coeff, block);
-  tran_low_t *const dqcoeff = BLOCK_OFFSET(pd->dqcoeff, block);
-#if CONFIG_VP9_HIGHBITDEPTH
-  const int bd = (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) ? xd->bd : 8;
-  *out_dist = vp9_highbd_block_error_dispatch(coeff, dqcoeff,
-                                              16 << ss_txfrm_size,
-                                              &this_sse, bd) >> shift;
-#else
-  *out_dist = vp9_block_error(coeff, dqcoeff, 16 << ss_txfrm_size,
-                              &this_sse) >> shift;
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-  *out_sse = this_sse >> shift;
-
-  if (x->skip_encode && !is_inter_block(xd->mi[0])) {
-    // TODO(jingning): tune the model to better capture the distortion.
-    int64_t p = (pd->dequant[1] * pd->dequant[1] *
-                    (1 << ss_txfrm_size)) >>
-#if CONFIG_VP9_HIGHBITDEPTH
-                        (shift + 2 + (bd - 8) * 2);
-#else
-                        (shift + 2);
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-    *out_dist += (p >> 4);
-    *out_sse  += p;
-  }
-}
-
-static int rate_block(int plane, int block, BLOCK_SIZE plane_bsize,
-                      TX_SIZE tx_size, struct rdcost_block_args* args) {
-  int x_idx, y_idx;
-  txfrm_block_to_raster_xy(plane_bsize, tx_size, block, &x_idx, &y_idx);
-
-  return cost_coeffs(args->x, plane, block, args->t_above + x_idx,
-                     args->t_left + y_idx, tx_size,
-                     args->so->scan, args->so->neighbors,
-                     args->use_fast_coef_costing);
-}
-
-static void block_rd_txfm(int plane, int block, BLOCK_SIZE plane_bsize,
-                          TX_SIZE tx_size, void *arg) {
-  struct rdcost_block_args *args = arg;
-  MACROBLOCK *const x = args->x;
-  MACROBLOCKD *const xd = &x->e_mbd;
-  MODE_INFO *const mi = xd->mi[0];
-  int64_t rd1, rd2, rd;
-  int rate;
-  int64_t dist;
-  int64_t sse;
-
-  if (args->exit_early)
-    return;
-
-  if (!is_inter_block(mi)) {
-    struct encode_b_args arg = {x, NULL, &mi->skip};
-    vp9_encode_block_intra(plane, block, plane_bsize, tx_size, &arg);
-    dist_block(x, plane, block, tx_size, &dist, &sse);
-  } else if (max_txsize_lookup[plane_bsize] == tx_size) {
-    if (x->skip_txfm[(plane << 2) + (block >> (tx_size << 1))] ==
-        SKIP_TXFM_NONE) {
-      // full forward transform and quantization
-      vp9_xform_quant(x, plane, block, plane_bsize, tx_size);
-      dist_block(x, plane, block, tx_size, &dist, &sse);
-    } else if (x->skip_txfm[(plane << 2) + (block >> (tx_size << 1))] ==
-               SKIP_TXFM_AC_ONLY) {
-      // compute DC coefficient
-      tran_low_t *const coeff   = BLOCK_OFFSET(x->plane[plane].coeff, block);
-      tran_low_t *const dqcoeff = BLOCK_OFFSET(xd->plane[plane].dqcoeff, block);
-      vp9_xform_quant_dc(x, plane, block, plane_bsize, tx_size);
-      sse  = x->bsse[(plane << 2) + (block >> (tx_size << 1))] << 4;
-      dist = sse;
-      if (x->plane[plane].eobs[block]) {
-        const int64_t orig_sse = (int64_t)coeff[0] * coeff[0];
-        const int64_t resd_sse = coeff[0] - dqcoeff[0];
-        int64_t dc_correct = orig_sse - resd_sse * resd_sse;
-#if CONFIG_VP9_HIGHBITDEPTH
-        dc_correct >>= ((xd->bd - 8) * 2);
-#endif
-        if (tx_size != TX_32X32)
-          dc_correct >>= 2;
-
-        dist = VPXMAX(0, sse - dc_correct);
-      }
-    } else {
-      // SKIP_TXFM_AC_DC
-      // skip forward transform
-      x->plane[plane].eobs[block] = 0;
-      sse  = x->bsse[(plane << 2) + (block >> (tx_size << 1))] << 4;
-      dist = sse;
-    }
-  } else {
-    // full forward transform and quantization
-    vp9_xform_quant(x, plane, block, plane_bsize, tx_size);
-    dist_block(x, plane, block, tx_size, &dist, &sse);
-  }
-
-  rd = RDCOST(x->rdmult, x->rddiv, 0, dist);
-  if (args->this_rd + rd > args->best_rd) {
-    args->exit_early = 1;
-    return;
-  }
-
-  rate = rate_block(plane, block, plane_bsize, tx_size, args);
-  rd1 = RDCOST(x->rdmult, x->rddiv, rate, dist);
-  rd2 = RDCOST(x->rdmult, x->rddiv, 0, sse);
-
-  // TODO(jingning): temporarily enabled only for luma component
-  rd = VPXMIN(rd1, rd2);
-  if (plane == 0)
-    x->zcoeff_blk[tx_size][block] = !x->plane[plane].eobs[block] ||
-                                    (rd1 > rd2 && !xd->lossless);
-
-  args->this_rate += rate;
-  args->this_dist += dist;
-  args->this_sse += sse;
-  args->this_rd += rd;
-
-  if (args->this_rd > args->best_rd) {
-    args->exit_early = 1;
-    return;
-  }
-
-  args->skippable &= !x->plane[plane].eobs[block];
-}
-
-static void txfm_rd_in_plane(MACROBLOCK *x,
-                             int *rate, int64_t *distortion,
-                             int *skippable, int64_t *sse,
-                             int64_t ref_best_rd, int plane,
-                             BLOCK_SIZE bsize, TX_SIZE tx_size,
-                             int use_fast_coef_casting) {
-  MACROBLOCKD *const xd = &x->e_mbd;
-  const struct macroblockd_plane *const pd = &xd->plane[plane];
-  struct rdcost_block_args args;
-  vp9_zero(args);
-  args.x = x;
-  args.best_rd = ref_best_rd;
-  args.use_fast_coef_costing = use_fast_coef_casting;
-  args.skippable = 1;
-
-  if (plane == 0)
-    xd->mi[0]->tx_size = tx_size;
-
-  vp9_get_entropy_contexts(bsize, tx_size, pd, args.t_above, args.t_left);
-
-  args.so = get_scan(xd, tx_size, get_plane_type(plane), 0);
-
-  vp9_foreach_transformed_block_in_plane(xd, bsize, plane,
-                                         block_rd_txfm, &args);
-  if (args.exit_early) {
-    *rate       = INT_MAX;
-    *distortion = INT64_MAX;
-    *sse        = INT64_MAX;
-    *skippable  = 0;
-  } else {
-    *distortion = args.this_dist;
-    *rate       = args.this_rate;
-    *sse        = args.this_sse;
-    *skippable  = args.skippable;
-  }
-}
-
-static void choose_largest_tx_size(VP9_COMP *cpi, MACROBLOCK *x,
-                                   int *rate, int64_t *distortion,
-                                   int *skip, int64_t *sse,
-                                   int64_t ref_best_rd,
-                                   BLOCK_SIZE bs) {
-  const TX_SIZE max_tx_size = max_txsize_lookup[bs];
-  VP9_COMMON *const cm = &cpi->common;
-  const TX_SIZE largest_tx_size = tx_mode_to_biggest_tx_size[cm->tx_mode];
-  MACROBLOCKD *const xd = &x->e_mbd;
-  MODE_INFO *const mi = xd->mi[0];
-
-  mi->tx_size = VPXMIN(max_tx_size, largest_tx_size);
-
-  txfm_rd_in_plane(x, rate, distortion, skip,
-                   sse, ref_best_rd, 0, bs,
-                   mi->tx_size, cpi->sf.use_fast_coef_costing);
-}
-
-static void choose_tx_size_from_rd(VP9_COMP *cpi, MACROBLOCK *x,
-                                   int *rate,
-                                   int64_t *distortion,
-                                   int *skip,
-                                   int64_t *psse,
-                                   int64_t ref_best_rd,
-                                   BLOCK_SIZE bs) {
-  const TX_SIZE max_tx_size = max_txsize_lookup[bs];
-  VP9_COMMON *const cm = &cpi->common;
-  MACROBLOCKD *const xd = &x->e_mbd;
-  MODE_INFO *const mi = xd->mi[0];
-  vpx_prob skip_prob = vp9_get_skip_prob(cm, xd);
-  int r[TX_SIZES][2], s[TX_SIZES];
-  int64_t d[TX_SIZES], sse[TX_SIZES];
-  int64_t rd[TX_SIZES][2] = {{INT64_MAX, INT64_MAX},
-                             {INT64_MAX, INT64_MAX},
-                             {INT64_MAX, INT64_MAX},
-                             {INT64_MAX, INT64_MAX}};
-  int n, m;
-  int s0, s1;
-  int64_t best_rd = INT64_MAX;
-  TX_SIZE best_tx = max_tx_size;
-  int start_tx, end_tx;
-
-  const vpx_prob *tx_probs = get_tx_probs2(max_tx_size, xd, &cm->fc->tx_probs);
-  assert(skip_prob > 0);
-  s0 = vp9_cost_bit(skip_prob, 0);
-  s1 = vp9_cost_bit(skip_prob, 1);
-
-  if (cm->tx_mode == TX_MODE_SELECT) {
-    start_tx = max_tx_size;
-    end_tx = 0;
-  } else {
-    TX_SIZE chosen_tx_size = VPXMIN(max_tx_size,
-                                    tx_mode_to_biggest_tx_size[cm->tx_mode]);
-    start_tx = chosen_tx_size;
-    end_tx = chosen_tx_size;
-  }
-
-  for (n = start_tx; n >= end_tx; n--) {
-    int r_tx_size = 0;
-    for (m = 0; m <= n - (n == (int) max_tx_size); m++) {
-      if (m == n)
-        r_tx_size += vp9_cost_zero(tx_probs[m]);
-      else
-        r_tx_size += vp9_cost_one(tx_probs[m]);
-    }
-    txfm_rd_in_plane(x, &r[n][0], &d[n], &s[n],
-                     &sse[n], ref_best_rd, 0, bs, n,
-                     cpi->sf.use_fast_coef_costing);
-    r[n][1] = r[n][0];
-    if (r[n][0] < INT_MAX) {
-      r[n][1] += r_tx_size;
-    }
-    if (d[n] == INT64_MAX || r[n][0] == INT_MAX) {
-      rd[n][0] = rd[n][1] = INT64_MAX;
-    } else if (s[n]) {
-      if (is_inter_block(mi)) {
-        rd[n][0] = rd[n][1] = RDCOST(x->rdmult, x->rddiv, s1, sse[n]);
-        r[n][1] -= r_tx_size;
-      } else {
-        rd[n][0] = RDCOST(x->rdmult, x->rddiv, s1, sse[n]);
-        rd[n][1] = RDCOST(x->rdmult, x->rddiv, s1 + r_tx_size, sse[n]);
-      }
-    } else {
-      rd[n][0] = RDCOST(x->rdmult, x->rddiv, r[n][0] + s0, d[n]);
-      rd[n][1] = RDCOST(x->rdmult, x->rddiv, r[n][1] + s0, d[n]);
-    }
-
-    if (is_inter_block(mi) && !xd->lossless && !s[n] && sse[n] != INT64_MAX) {
-      rd[n][0] = VPXMIN(rd[n][0], RDCOST(x->rdmult, x->rddiv, s1, sse[n]));
-      rd[n][1] = VPXMIN(rd[n][1], RDCOST(x->rdmult, x->rddiv, s1, sse[n]));
-    }
-
-    // Early termination in transform size search.
-    if (cpi->sf.tx_size_search_breakout &&
-        (rd[n][1] == INT64_MAX ||
-        (n < (int) max_tx_size && rd[n][1] > rd[n + 1][1]) ||
-        s[n] == 1))
-      break;
-
-    if (rd[n][1] < best_rd) {
-      best_tx = n;
-      best_rd = rd[n][1];
-    }
-  }
-  mi->tx_size = best_tx;
-
-  *distortion = d[mi->tx_size];
-  *rate       = r[mi->tx_size][cm->tx_mode == TX_MODE_SELECT];
-  *skip       = s[mi->tx_size];
-  *psse       = sse[mi->tx_size];
-}
-
-static void super_block_yrd(VP9_COMP *cpi, MACROBLOCK *x, int *rate,
-                            int64_t *distortion, int *skip,
-                            int64_t *psse, BLOCK_SIZE bs,
-                            int64_t ref_best_rd) {
-  MACROBLOCKD *xd = &x->e_mbd;
-  int64_t sse;
-  int64_t *ret_sse = psse ? psse : &sse;
-
-  assert(bs == xd->mi[0]->sb_type);
-
-  if (cpi->sf.tx_size_search_method == USE_LARGESTALL || xd->lossless) {
-    choose_largest_tx_size(cpi, x, rate, distortion, skip, ret_sse, ref_best_rd,
-                           bs);
-  } else {
-    choose_tx_size_from_rd(cpi, x, rate, distortion, skip, ret_sse,
-                           ref_best_rd, bs);
-  }
-}
-
-static int conditional_skipintra(PREDICTION_MODE mode,
-                                 PREDICTION_MODE best_intra_mode) {
-  if (mode == D117_PRED &&
-      best_intra_mode != V_PRED &&
-      best_intra_mode != D135_PRED)
-    return 1;
-  if (mode == D63_PRED &&
-      best_intra_mode != V_PRED &&
-      best_intra_mode != D45_PRED)
-    return 1;
-  if (mode == D207_PRED &&
-      best_intra_mode != H_PRED &&
-      best_intra_mode != D45_PRED)
-    return 1;
-  if (mode == D153_PRED &&
-      best_intra_mode != H_PRED &&
-      best_intra_mode != D135_PRED)
-    return 1;
-  return 0;
-}
-
-static int64_t rd_pick_intra4x4block(VP9_COMP *cpi, MACROBLOCK *x,
-                                     int row, int col,
-                                     PREDICTION_MODE *best_mode,
-                                     const int *bmode_costs,
-                                     ENTROPY_CONTEXT *a, ENTROPY_CONTEXT *l,
-                                     int *bestrate, int *bestratey,
-                                     int64_t *bestdistortion,
-                                     BLOCK_SIZE bsize, int64_t rd_thresh) {
-  PREDICTION_MODE mode;
-  MACROBLOCKD *const xd = &x->e_mbd;
-  int64_t best_rd = rd_thresh;
-  struct macroblock_plane *p = &x->plane[0];
-  struct macroblockd_plane *pd = &xd->plane[0];
-  const int src_stride = p->src.stride;
-  const int dst_stride = pd->dst.stride;
-  const uint8_t *src_init = &p->src.buf[row * 4 * src_stride + col * 4];
-  uint8_t *dst_init = &pd->dst.buf[row * 4 * src_stride + col * 4];
-  ENTROPY_CONTEXT ta[2], tempa[2];
-  ENTROPY_CONTEXT tl[2], templ[2];
-  const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[bsize];
-  const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[bsize];
-  int idx, idy;
-  uint8_t best_dst[8 * 8];
-#if CONFIG_VP9_HIGHBITDEPTH
-  uint16_t best_dst16[8 * 8];
-#endif
-  memcpy(ta, a, num_4x4_blocks_wide * sizeof(a[0]));
-  memcpy(tl, l, num_4x4_blocks_high * sizeof(l[0]));
-
-  xd->mi[0]->tx_size = TX_4X4;
-
-#if CONFIG_VP9_HIGHBITDEPTH
-  if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
-    for (mode = DC_PRED; mode <= TM_PRED; ++mode) {
-      int64_t this_rd;
-      int ratey = 0;
-      int64_t distortion = 0;
-      int rate = bmode_costs[mode];
-
-      if (!(cpi->sf.intra_y_mode_mask[TX_4X4] & (1 << mode)))
-        continue;
-
-      // Only do the oblique modes if the best so far is
-      // one of the neighboring directional modes
-      if (cpi->sf.mode_search_skip_flags & FLAG_SKIP_INTRA_DIRMISMATCH) {
-        if (conditional_skipintra(mode, *best_mode))
-            continue;
-      }
-
-      memcpy(tempa, ta, num_4x4_blocks_wide * sizeof(ta[0]));
-      memcpy(templ, tl, num_4x4_blocks_high * sizeof(tl[0]));
-
-      for (idy = 0; idy < num_4x4_blocks_high; ++idy) {
-        for (idx = 0; idx < num_4x4_blocks_wide; ++idx) {
-          const int block = (row + idy) * 2 + (col + idx);
-          const uint8_t *const src = &src_init[idx * 4 + idy * 4 * src_stride];
-          uint8_t *const dst = &dst_init[idx * 4 + idy * 4 * dst_stride];
-          int16_t *const src_diff = vp9_raster_block_offset_int16(BLOCK_8X8,
-                                                                  block,
-                                                                  p->src_diff);
-          tran_low_t *const coeff = BLOCK_OFFSET(x->plane[0].coeff, block);
-          xd->mi[0]->bmi[block].as_mode = mode;
-          vp9_predict_intra_block(xd, 1, TX_4X4, mode,
-                                  x->skip_encode ? src : dst,
-                                  x->skip_encode ? src_stride : dst_stride,
-                                  dst, dst_stride,
-                                  col + idx, row + idy, 0);
-          vpx_highbd_subtract_block(4, 4, src_diff, 8, src, src_stride,
-                                    dst, dst_stride, xd->bd);
-          if (xd->lossless) {
-            const scan_order *so = &vp9_default_scan_orders[TX_4X4];
-            vp9_highbd_fwht4x4(src_diff, coeff, 8);
-            vp9_regular_quantize_b_4x4(x, 0, block, so->scan, so->iscan);
-            ratey += cost_coeffs(x, 0, block, tempa + idx, templ + idy, TX_4X4,
-                                 so->scan, so->neighbors,
-                                 cpi->sf.use_fast_coef_costing);
-            if (RDCOST(x->rdmult, x->rddiv, ratey, distortion) >= best_rd)
-              goto next_highbd;
-            vp9_highbd_iwht4x4_add(BLOCK_OFFSET(pd->dqcoeff, block),
-                                   dst, dst_stride,
-                                   p->eobs[block], xd->bd);
-          } else {
-            int64_t unused;
-            const TX_TYPE tx_type = get_tx_type_4x4(PLANE_TYPE_Y, xd, block);
-            const scan_order *so = &vp9_scan_orders[TX_4X4][tx_type];
-            if (tx_type == DCT_DCT)
-              vpx_highbd_fdct4x4(src_diff, coeff, 8);
-            else
-              vp9_highbd_fht4x4(src_diff, coeff, 8, tx_type);
-            vp9_regular_quantize_b_4x4(x, 0, block, so->scan, so->iscan);
-            ratey += cost_coeffs(x, 0, block, tempa + idx, templ + idy, TX_4X4,
-                                 so->scan, so->neighbors,
-                                 cpi->sf.use_fast_coef_costing);
-            distortion += vp9_highbd_block_error_dispatch(
-                coeff, BLOCK_OFFSET(pd->dqcoeff, block),
-                16, &unused, xd->bd) >> 2;
-            if (RDCOST(x->rdmult, x->rddiv, ratey, distortion) >= best_rd)
-              goto next_highbd;
-            vp9_highbd_iht4x4_add(tx_type, BLOCK_OFFSET(pd->dqcoeff, block),
-                                  dst, dst_stride, p->eobs[block], xd->bd);
-          }
-        }
-      }
-
-      rate += ratey;
-      this_rd = RDCOST(x->rdmult, x->rddiv, rate, distortion);
-
-      if (this_rd < best_rd) {
-        *bestrate = rate;
-        *bestratey = ratey;
-        *bestdistortion = distortion;
-        best_rd = this_rd;
-        *best_mode = mode;
-        memcpy(a, tempa, num_4x4_blocks_wide * sizeof(tempa[0]));
-        memcpy(l, templ, num_4x4_blocks_high * sizeof(templ[0]));
-        for (idy = 0; idy < num_4x4_blocks_high * 4; ++idy) {
-          memcpy(best_dst16 + idy * 8,
-                 CONVERT_TO_SHORTPTR(dst_init + idy * dst_stride),
-                 num_4x4_blocks_wide * 4 * sizeof(uint16_t));
-        }
-      }
-    next_highbd:
-      {}
-    }
-    if (best_rd >= rd_thresh || x->skip_encode)
-      return best_rd;
-
-    for (idy = 0; idy < num_4x4_blocks_high * 4; ++idy) {
-      memcpy(CONVERT_TO_SHORTPTR(dst_init + idy * dst_stride),
-             best_dst16 + idy * 8,
-             num_4x4_blocks_wide * 4 * sizeof(uint16_t));
-    }
-
-    return best_rd;
-  }
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-
-  for (mode = DC_PRED; mode <= TM_PRED; ++mode) {
-    int64_t this_rd;
-    int ratey = 0;
-    int64_t distortion = 0;
-    int rate = bmode_costs[mode];
-
-    if (!(cpi->sf.intra_y_mode_mask[TX_4X4] & (1 << mode)))
-      continue;
-
-    // Only do the oblique modes if the best so far is
-    // one of the neighboring directional modes
-    if (cpi->sf.mode_search_skip_flags & FLAG_SKIP_INTRA_DIRMISMATCH) {
-      if (conditional_skipintra(mode, *best_mode))
-          continue;
-    }
-
-    memcpy(tempa, ta, num_4x4_blocks_wide * sizeof(ta[0]));
-    memcpy(templ, tl, num_4x4_blocks_high * sizeof(tl[0]));
-
-    for (idy = 0; idy < num_4x4_blocks_high; ++idy) {
-      for (idx = 0; idx < num_4x4_blocks_wide; ++idx) {
-        const int block = (row + idy) * 2 + (col + idx);
-        const uint8_t *const src = &src_init[idx * 4 + idy * 4 * src_stride];
-        uint8_t *const dst = &dst_init[idx * 4 + idy * 4 * dst_stride];
-        int16_t *const src_diff =
-            vp9_raster_block_offset_int16(BLOCK_8X8, block, p->src_diff);
-        tran_low_t *const coeff = BLOCK_OFFSET(x->plane[0].coeff, block);
-        xd->mi[0]->bmi[block].as_mode = mode;
-        vp9_predict_intra_block(xd, 1, TX_4X4, mode,
-                                x->skip_encode ? src : dst,
-                                x->skip_encode ? src_stride : dst_stride,
-                                dst, dst_stride, col + idx, row + idy, 0);
-        vpx_subtract_block(4, 4, src_diff, 8, src, src_stride, dst, dst_stride);
-
-        if (xd->lossless) {
-          const scan_order *so = &vp9_default_scan_orders[TX_4X4];
-          vp9_fwht4x4(src_diff, coeff, 8);
-          vp9_regular_quantize_b_4x4(x, 0, block, so->scan, so->iscan);
-          ratey += cost_coeffs(x, 0, block, tempa + idx, templ + idy, TX_4X4,
-                               so->scan, so->neighbors,
-                               cpi->sf.use_fast_coef_costing);
-          if (RDCOST(x->rdmult, x->rddiv, ratey, distortion) >= best_rd)
-            goto next;
-          vp9_iwht4x4_add(BLOCK_OFFSET(pd->dqcoeff, block), dst, dst_stride,
-                          p->eobs[block]);
-        } else {
-          int64_t unused;
-          const TX_TYPE tx_type = get_tx_type_4x4(PLANE_TYPE_Y, xd, block);
-          const scan_order *so = &vp9_scan_orders[TX_4X4][tx_type];
-          vp9_fht4x4(src_diff, coeff, 8, tx_type);
-          vp9_regular_quantize_b_4x4(x, 0, block, so->scan, so->iscan);
-          ratey += cost_coeffs(x, 0, block, tempa + idx, templ + idy, TX_4X4,
-                             so->scan, so->neighbors,
-                             cpi->sf.use_fast_coef_costing);
-#if CONFIG_VP9_HIGHBITDEPTH
-          distortion += vp9_highbd_block_error_8bit(
-              coeff, BLOCK_OFFSET(pd->dqcoeff, block), 16, &unused) >> 2;
-#else
-          distortion += vp9_block_error(coeff, BLOCK_OFFSET(pd->dqcoeff, block),
-                                        16, &unused) >> 2;
-#endif
-          if (RDCOST(x->rdmult, x->rddiv, ratey, distortion) >= best_rd)
-            goto next;
-          vp9_iht4x4_add(tx_type, BLOCK_OFFSET(pd->dqcoeff, block),
-                         dst, dst_stride, p->eobs[block]);
-        }
-      }
-    }
-
-    rate += ratey;
-    this_rd = RDCOST(x->rdmult, x->rddiv, rate, distortion);
-
-    if (this_rd < best_rd) {
-      *bestrate = rate;
-      *bestratey = ratey;
-      *bestdistortion = distortion;
-      best_rd = this_rd;
-      *best_mode = mode;
-      memcpy(a, tempa, num_4x4_blocks_wide * sizeof(tempa[0]));
-      memcpy(l, templ, num_4x4_blocks_high * sizeof(templ[0]));
-      for (idy = 0; idy < num_4x4_blocks_high * 4; ++idy)
-        memcpy(best_dst + idy * 8, dst_init + idy * dst_stride,
-               num_4x4_blocks_wide * 4);
-    }
-  next:
-    {}
-  }
-
-  if (best_rd >= rd_thresh || x->skip_encode)
-    return best_rd;
-
-  for (idy = 0; idy < num_4x4_blocks_high * 4; ++idy)
-    memcpy(dst_init + idy * dst_stride, best_dst + idy * 8,
-           num_4x4_blocks_wide * 4);
-
-  return best_rd;
-}
-
-static int64_t rd_pick_intra_sub_8x8_y_mode(VP9_COMP *cpi, MACROBLOCK *mb,
-                                            int *rate, int *rate_y,
-                                            int64_t *distortion,
-                                            int64_t best_rd) {
-  int i, j;
-  const MACROBLOCKD *const xd = &mb->e_mbd;
-  MODE_INFO *const mic = xd->mi[0];
-  const MODE_INFO *above_mi = xd->above_mi;
-  const MODE_INFO *left_mi = xd->left_mi;
-  const BLOCK_SIZE bsize = xd->mi[0]->sb_type;
-  const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[bsize];
-  const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[bsize];
-  int idx, idy;
-  int cost = 0;
-  int64_t total_distortion = 0;
-  int tot_rate_y = 0;
-  int64_t total_rd = 0;
-  const int *bmode_costs = cpi->mbmode_cost;
-
-  // Pick modes for each sub-block (of size 4x4, 4x8, or 8x4) in an 8x8 block.
-  for (idy = 0; idy < 2; idy += num_4x4_blocks_high) {
-    for (idx = 0; idx < 2; idx += num_4x4_blocks_wide) {
-      PREDICTION_MODE best_mode = DC_PRED;
-      int r = INT_MAX, ry = INT_MAX;
-      int64_t d = INT64_MAX, this_rd = INT64_MAX;
-      i = idy * 2 + idx;
-      if (cpi->common.frame_type == KEY_FRAME) {
-        const PREDICTION_MODE A = vp9_above_block_mode(mic, above_mi, i);
-        const PREDICTION_MODE L = vp9_left_block_mode(mic, left_mi, i);
-
-        bmode_costs  = cpi->y_mode_costs[A][L];
-      }
-
-      this_rd = rd_pick_intra4x4block(cpi, mb, idy, idx, &best_mode,
-                                      bmode_costs,
-                                      xd->plane[0].above_context + idx,
-                                      xd->plane[0].left_context + idy,
-                                      &r, &ry, &d, bsize, best_rd - total_rd);
-
-      if (this_rd >= best_rd - total_rd)
-        return INT64_MAX;
-
-      total_rd += this_rd;
-      cost += r;
-      total_distortion += d;
-      tot_rate_y += ry;
-
-      mic->bmi[i].as_mode = best_mode;
-      for (j = 1; j < num_4x4_blocks_high; ++j)
-        mic->bmi[i + j * 2].as_mode = best_mode;
-      for (j = 1; j < num_4x4_blocks_wide; ++j)
-        mic->bmi[i + j].as_mode = best_mode;
-
-      if (total_rd >= best_rd)
-        return INT64_MAX;
-    }
-  }
-
-  *rate = cost;
-  *rate_y = tot_rate_y;
-  *distortion = total_distortion;
-  mic->mode = mic->bmi[3].as_mode;
-
-  return RDCOST(mb->rdmult, mb->rddiv, cost, total_distortion);
-}
-
-// This function is used only for intra_only frames
-static int64_t rd_pick_intra_sby_mode(VP9_COMP *cpi, MACROBLOCK *x,
-                                      int *rate, int *rate_tokenonly,
-                                      int64_t *distortion, int *skippable,
-                                      BLOCK_SIZE bsize,
-                                      int64_t best_rd) {
-  PREDICTION_MODE mode;
-  PREDICTION_MODE mode_selected = DC_PRED;
-  MACROBLOCKD *const xd = &x->e_mbd;
-  MODE_INFO *const mic = xd->mi[0];
-  int this_rate, this_rate_tokenonly, s;
-  int64_t this_distortion, this_rd;
-  TX_SIZE best_tx = TX_4X4;
-  int *bmode_costs;
-  const MODE_INFO *above_mi = xd->above_mi;
-  const MODE_INFO *left_mi = xd->left_mi;
-  const PREDICTION_MODE A = vp9_above_block_mode(mic, above_mi, 0);
-  const PREDICTION_MODE L = vp9_left_block_mode(mic, left_mi, 0);
-  bmode_costs = cpi->y_mode_costs[A][L];
-
-  memset(x->skip_txfm, SKIP_TXFM_NONE, sizeof(x->skip_txfm));
-  /* Y Search for intra prediction mode */
-  for (mode = DC_PRED; mode <= TM_PRED; mode++) {
-    if (cpi->sf.use_nonrd_pick_mode) {
-      // These speed features are turned on in hybrid non-RD and RD mode
-      // for key frame coding in the context of real-time setting.
-      if (conditional_skipintra(mode, mode_selected))
-          continue;
-      if (*skippable)
-        break;
-    }
-
-    mic->mode = mode;
-
-    super_block_yrd(cpi, x, &this_rate_tokenonly, &this_distortion,
-        &s, NULL, bsize, best_rd);
-
-    if (this_rate_tokenonly == INT_MAX)
-      continue;
-
-    this_rate = this_rate_tokenonly + bmode_costs[mode];
-    this_rd = RDCOST(x->rdmult, x->rddiv, this_rate, this_distortion);
-
-    if (this_rd < best_rd) {
-      mode_selected   = mode;
-      best_rd         = this_rd;
-      best_tx         = mic->tx_size;
-      *rate           = this_rate;
-      *rate_tokenonly = this_rate_tokenonly;
-      *distortion     = this_distortion;
-      *skippable      = s;
-    }
-  }
-
-  mic->mode = mode_selected;
-  mic->tx_size = best_tx;
-
-  return best_rd;
-}
-
-// Return value 0: early termination triggered, no valid rd cost available;
-//              1: rd cost values are valid.
-static int super_block_uvrd(const VP9_COMP *cpi, MACROBLOCK *x,
-                            int *rate, int64_t *distortion, int *skippable,
-                            int64_t *sse, BLOCK_SIZE bsize,
-                            int64_t ref_best_rd) {
-  MACROBLOCKD *const xd = &x->e_mbd;
-  MODE_INFO *const mi = xd->mi[0];
-  const TX_SIZE uv_tx_size = get_uv_tx_size(mi, &xd->plane[1]);
-  int plane;
-  int pnrate = 0, pnskip = 1;
-  int64_t pndist = 0, pnsse = 0;
-  int is_cost_valid = 1;
-
-  if (ref_best_rd < 0)
-    is_cost_valid = 0;
-
-  if (is_inter_block(mi) && is_cost_valid) {
-    int plane;
-    for (plane = 1; plane < MAX_MB_PLANE; ++plane)
-      vp9_subtract_plane(x, bsize, plane);
-  }
-
-  *rate = 0;
-  *distortion = 0;
-  *sse = 0;
-  *skippable = 1;
-
-  for (plane = 1; plane < MAX_MB_PLANE; ++plane) {
-    txfm_rd_in_plane(x, &pnrate, &pndist, &pnskip, &pnsse,
-                     ref_best_rd, plane, bsize, uv_tx_size,
-                     cpi->sf.use_fast_coef_costing);
-    if (pnrate == INT_MAX) {
-      is_cost_valid = 0;
-      break;
-    }
-    *rate += pnrate;
-    *distortion += pndist;
-    *sse += pnsse;
-    *skippable &= pnskip;
-  }
-
-  if (!is_cost_valid) {
-    // reset cost value
-    *rate = INT_MAX;
-    *distortion = INT64_MAX;
-    *sse = INT64_MAX;
-    *skippable = 0;
-  }
-
-  return is_cost_valid;
-}
-
-static int64_t rd_pick_intra_sbuv_mode(VP9_COMP *cpi, MACROBLOCK *x,
-                                       PICK_MODE_CONTEXT *ctx,
-                                       int *rate, int *rate_tokenonly,
-                                       int64_t *distortion, int *skippable,
-                                       BLOCK_SIZE bsize, TX_SIZE max_tx_size) {
-  MACROBLOCKD *xd = &x->e_mbd;
-  PREDICTION_MODE mode;
-  PREDICTION_MODE mode_selected = DC_PRED;
-  int64_t best_rd = INT64_MAX, this_rd;
-  int this_rate_tokenonly, this_rate, s;
-  int64_t this_distortion, this_sse;
-
-  memset(x->skip_txfm, SKIP_TXFM_NONE, sizeof(x->skip_txfm));
-  for (mode = DC_PRED; mode <= TM_PRED; ++mode) {
-    if (!(cpi->sf.intra_uv_mode_mask[max_tx_size] & (1 << mode)))
-      continue;
-#if CONFIG_BETTER_HW_COMPATIBILITY && CONFIG_VP9_HIGHBITDEPTH
-    if ((xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) &&
-        (xd->above_mi == NULL || xd->left_mi == NULL) && need_top_left[mode])
-      continue;
-#endif  // CONFIG_BETTER_HW_COMPATIBILITY && CONFIG_VP9_HIGHBITDEPTH
-
-    xd->mi[0]->uv_mode = mode;
-
-    if (!super_block_uvrd(cpi, x, &this_rate_tokenonly,
-                          &this_distortion, &s, &this_sse, bsize, best_rd))
-      continue;
-    this_rate = this_rate_tokenonly +
-        cpi->intra_uv_mode_cost[cpi->common.frame_type]
-                                [xd->mi[0]->mode][mode];
-    this_rd = RDCOST(x->rdmult, x->rddiv, this_rate, this_distortion);
-
-    if (this_rd < best_rd) {
-      mode_selected   = mode;
-      best_rd         = this_rd;
-      *rate           = this_rate;
-      *rate_tokenonly = this_rate_tokenonly;
-      *distortion     = this_distortion;
-      *skippable      = s;
-      if (!x->select_tx_size)
-        swap_block_ptr(x, ctx, 2, 0, 1, MAX_MB_PLANE);
-    }
-  }
-
-  xd->mi[0]->uv_mode = mode_selected;
-  return best_rd;
-}
-
-static int64_t rd_sbuv_dcpred(const VP9_COMP *cpi, MACROBLOCK *x,
-                              int *rate, int *rate_tokenonly,
-                              int64_t *distortion, int *skippable,
-                              BLOCK_SIZE bsize) {
-  const VP9_COMMON *cm = &cpi->common;
-  int64_t unused;
-
-  x->e_mbd.mi[0]->uv_mode = DC_PRED;
-  memset(x->skip_txfm, SKIP_TXFM_NONE, sizeof(x->skip_txfm));
-  super_block_uvrd(cpi, x, rate_tokenonly, distortion,
-                   skippable, &unused, bsize, INT64_MAX);
-  *rate = *rate_tokenonly +
-      cpi->intra_uv_mode_cost[cm->frame_type]
-                              [x->e_mbd.mi[0]->mode][DC_PRED];
-  return RDCOST(x->rdmult, x->rddiv, *rate, *distortion);
-}
-
-static void choose_intra_uv_mode(VP9_COMP *cpi, MACROBLOCK *const x,
-                                 PICK_MODE_CONTEXT *ctx,
-                                 BLOCK_SIZE bsize, TX_SIZE max_tx_size,
-                                 int *rate_uv, int *rate_uv_tokenonly,
-                                 int64_t *dist_uv, int *skip_uv,
-                                 PREDICTION_MODE *mode_uv) {
-  // Use an estimated rd for uv_intra based on DC_PRED if the
-  // appropriate speed flag is set.
-  if (cpi->sf.use_uv_intra_rd_estimate) {
-    rd_sbuv_dcpred(cpi, x, rate_uv, rate_uv_tokenonly, dist_uv,
-                   skip_uv, bsize < BLOCK_8X8 ? BLOCK_8X8 : bsize);
-  // Else do a proper rd search for each possible transform size that may
-  // be considered in the main rd loop.
-  } else {
-    rd_pick_intra_sbuv_mode(cpi, x, ctx,
-                            rate_uv, rate_uv_tokenonly, dist_uv, skip_uv,
-                            bsize < BLOCK_8X8 ? BLOCK_8X8 : bsize, max_tx_size);
-  }
-  *mode_uv = x->e_mbd.mi[0]->uv_mode;
-}
-
-static int cost_mv_ref(const VP9_COMP *cpi, PREDICTION_MODE mode,
-                       int mode_context) {
-  assert(is_inter_mode(mode));
-  return cpi->inter_mode_cost[mode_context][INTER_OFFSET(mode)];
-}
-
-static int set_and_cost_bmi_mvs(VP9_COMP *cpi, MACROBLOCK *x, MACROBLOCKD *xd,
-                                int i,
-                                PREDICTION_MODE mode, int_mv this_mv[2],
-                                int_mv frame_mv[MB_MODE_COUNT][MAX_REF_FRAMES],
-                                int_mv seg_mvs[MAX_REF_FRAMES],
-                                int_mv *best_ref_mv[2], const int *mvjcost,
-                                int *mvcost[2]) {
-  MODE_INFO *const mi = xd->mi[0];
-  const MB_MODE_INFO_EXT *const mbmi_ext = x->mbmi_ext;
-  int thismvcost = 0;
-  int idx, idy;
-  const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[mi->sb_type];
-  const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[mi->sb_type];
-  const int is_compound = has_second_ref(mi);
-
-  switch (mode) {
-    case NEWMV:
-      this_mv[0].as_int = seg_mvs[mi->ref_frame[0]].as_int;
-      thismvcost += vp9_mv_bit_cost(&this_mv[0].as_mv, &best_ref_mv[0]->as_mv,
-                                    mvjcost, mvcost, MV_COST_WEIGHT_SUB);
-      if (is_compound) {
-        this_mv[1].as_int = seg_mvs[mi->ref_frame[1]].as_int;
-        thismvcost += vp9_mv_bit_cost(&this_mv[1].as_mv, &best_ref_mv[1]->as_mv,
-                                      mvjcost, mvcost, MV_COST_WEIGHT_SUB);
-      }
-      break;
-    case NEARMV:
-    case NEARESTMV:
-      this_mv[0].as_int = frame_mv[mode][mi->ref_frame[0]].as_int;
-      if (is_compound)
-        this_mv[1].as_int = frame_mv[mode][mi->ref_frame[1]].as_int;
-      break;
-    case ZEROMV:
-      this_mv[0].as_int = 0;
-      if (is_compound)
-        this_mv[1].as_int = 0;
-      break;
-    default:
-      break;
-  }
-
-  mi->bmi[i].as_mv[0].as_int = this_mv[0].as_int;
-  if (is_compound)
-    mi->bmi[i].as_mv[1].as_int = this_mv[1].as_int;
-
-  mi->bmi[i].as_mode = mode;
-
-  for (idy = 0; idy < num_4x4_blocks_high; ++idy)
-    for (idx = 0; idx < num_4x4_blocks_wide; ++idx)
-      memmove(&mi->bmi[i + idy * 2 + idx], &mi->bmi[i], sizeof(mi->bmi[i]));
-
-  return cost_mv_ref(cpi, mode, mbmi_ext->mode_context[mi->ref_frame[0]]) +
-            thismvcost;
-}
-
-static int64_t encode_inter_mb_segment(VP9_COMP *cpi,
-                                       MACROBLOCK *x,
-                                       int64_t best_yrd,
-                                       int i,
-                                       int *labelyrate,
-                                       int64_t *distortion, int64_t *sse,
-                                       ENTROPY_CONTEXT *ta,
-                                       ENTROPY_CONTEXT *tl,
-                                       int mi_row, int mi_col) {
-  int k;
-  MACROBLOCKD *xd = &x->e_mbd;
-  struct macroblockd_plane *const pd = &xd->plane[0];
-  struct macroblock_plane *const p = &x->plane[0];
-  MODE_INFO *const mi = xd->mi[0];
-  const BLOCK_SIZE plane_bsize = get_plane_block_size(mi->sb_type, pd);
-  const int width = 4 * num_4x4_blocks_wide_lookup[plane_bsize];
-  const int height = 4 * num_4x4_blocks_high_lookup[plane_bsize];
-  int idx, idy;
-
-  const uint8_t *const src =
-      &p->src.buf[vp9_raster_block_offset(BLOCK_8X8, i, p->src.stride)];
-  uint8_t *const dst = &pd->dst.buf[vp9_raster_block_offset(BLOCK_8X8, i,
-                                                            pd->dst.stride)];
-  int64_t thisdistortion = 0, thissse = 0;
-  int thisrate = 0, ref;
-  const scan_order *so = &vp9_default_scan_orders[TX_4X4];
-  const int is_compound = has_second_ref(mi);
-  const InterpKernel *kernel = vp9_filter_kernels[mi->interp_filter];
-
-  for (ref = 0; ref < 1 + is_compound; ++ref) {
-    const int bw = b_width_log2_lookup[BLOCK_8X8];
-    const int h = 4 * (i >> bw);
-    const int w = 4 * (i & ((1 << bw) - 1));
-    const struct scale_factors *sf = &xd->block_refs[ref]->sf;
-    int y_stride = pd->pre[ref].stride;
-    uint8_t *pre = pd->pre[ref].buf + (h * pd->pre[ref].stride + w);
-
-    if (vp9_is_scaled(sf)) {
-      const int x_start = (-xd->mb_to_left_edge >> (3 + pd->subsampling_x));
-      const int y_start = (-xd->mb_to_top_edge >> (3 + pd->subsampling_y));
-
-      y_stride = xd->block_refs[ref]->buf->y_stride;
-      pre = xd->block_refs[ref]->buf->y_buffer;
-      pre += scaled_buffer_offset(x_start + w, y_start + h,
-                                  y_stride, sf);
-    }
-#if CONFIG_VP9_HIGHBITDEPTH
-  if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
-    vp9_highbd_build_inter_predictor(pre, y_stride,
-                                     dst, pd->dst.stride,
-                                     &mi->bmi[i].as_mv[ref].as_mv,
-                                     &xd->block_refs[ref]->sf, width, height,
-                                     ref, kernel, MV_PRECISION_Q3,
-                                     mi_col * MI_SIZE + 4 * (i % 2),
-                                     mi_row * MI_SIZE + 4 * (i / 2), xd->bd);
-  } else {
-    vp9_build_inter_predictor(pre, y_stride,
-                              dst, pd->dst.stride,
-                              &mi->bmi[i].as_mv[ref].as_mv,
-                              &xd->block_refs[ref]->sf, width, height, ref,
-                              kernel, MV_PRECISION_Q3,
-                              mi_col * MI_SIZE + 4 * (i % 2),
-                              mi_row * MI_SIZE + 4 * (i / 2));
-  }
-#else
-    vp9_build_inter_predictor(pre, y_stride,
-                              dst, pd->dst.stride,
-                              &mi->bmi[i].as_mv[ref].as_mv,
-                              &xd->block_refs[ref]->sf, width, height, ref,
-                              kernel, MV_PRECISION_Q3,
-                              mi_col * MI_SIZE + 4 * (i % 2),
-                              mi_row * MI_SIZE + 4 * (i / 2));
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-  }
-
-#if CONFIG_VP9_HIGHBITDEPTH
-  if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
-    vpx_highbd_subtract_block(
-        height, width, vp9_raster_block_offset_int16(BLOCK_8X8, i, p->src_diff),
-        8, src, p->src.stride, dst, pd->dst.stride, xd->bd);
-  } else {
-    vpx_subtract_block(
-        height, width, vp9_raster_block_offset_int16(BLOCK_8X8, i, p->src_diff),
-        8, src, p->src.stride, dst, pd->dst.stride);
-  }
-#else
-  vpx_subtract_block(height, width,
-                     vp9_raster_block_offset_int16(BLOCK_8X8, i, p->src_diff),
-                     8, src, p->src.stride, dst, pd->dst.stride);
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-
-  k = i;
-  for (idy = 0; idy < height / 4; ++idy) {
-    for (idx = 0; idx < width / 4; ++idx) {
-#if CONFIG_VP9_HIGHBITDEPTH
-      const int bd = (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) ? xd->bd : 8;
-#endif
-      int64_t ssz, rd, rd1, rd2;
-      tran_low_t* coeff;
-
-      k += (idy * 2 + idx);
-      coeff = BLOCK_OFFSET(p->coeff, k);
-      x->fwd_txm4x4(vp9_raster_block_offset_int16(BLOCK_8X8, k, p->src_diff),
-                    coeff, 8);
-      vp9_regular_quantize_b_4x4(x, 0, k, so->scan, so->iscan);
-#if CONFIG_VP9_HIGHBITDEPTH
-      thisdistortion += vp9_highbd_block_error_dispatch(
-          coeff, BLOCK_OFFSET(pd->dqcoeff, k), 16, &ssz, bd);
-#else
-      thisdistortion += vp9_block_error(coeff, BLOCK_OFFSET(pd->dqcoeff, k),
-                                        16, &ssz);
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-      thissse += ssz;
-      thisrate += cost_coeffs(x, 0, k, ta + (k & 1), tl + (k >> 1), TX_4X4,
-                              so->scan, so->neighbors,
-                              cpi->sf.use_fast_coef_costing);
-      rd1 = RDCOST(x->rdmult, x->rddiv, thisrate, thisdistortion >> 2);
-      rd2 = RDCOST(x->rdmult, x->rddiv, 0, thissse >> 2);
-      rd = VPXMIN(rd1, rd2);
-      if (rd >= best_yrd)
-        return INT64_MAX;
-    }
-  }
-
-  *distortion = thisdistortion >> 2;
-  *labelyrate = thisrate;
-  *sse = thissse >> 2;
-
-  return RDCOST(x->rdmult, x->rddiv, *labelyrate, *distortion);
-}
-
-typedef struct {
-  int eobs;
-  int brate;
-  int byrate;
-  int64_t bdist;
-  int64_t bsse;
-  int64_t brdcost;
-  int_mv mvs[2];
-  ENTROPY_CONTEXT ta[2];
-  ENTROPY_CONTEXT tl[2];
-} SEG_RDSTAT;
-
-typedef struct {
-  int_mv *ref_mv[2];
-  int_mv mvp;
-
-  int64_t segment_rd;
-  int r;
-  int64_t d;
-  int64_t sse;
-  int segment_yrate;
-  PREDICTION_MODE modes[4];
-  SEG_RDSTAT rdstat[4][INTER_MODES];
-  int mvthresh;
-} BEST_SEG_INFO;
-
-static INLINE int mv_check_bounds(const MACROBLOCK *x, const MV *mv) {
-  return (mv->row >> 3) < x->mv_row_min ||
-         (mv->row >> 3) > x->mv_row_max ||
-         (mv->col >> 3) < x->mv_col_min ||
-         (mv->col >> 3) > x->mv_col_max;
-}
-
-static INLINE void mi_buf_shift(MACROBLOCK *x, int i) {
-  MODE_INFO *const mi = x->e_mbd.mi[0];
-  struct macroblock_plane *const p = &x->plane[0];
-  struct macroblockd_plane *const pd = &x->e_mbd.plane[0];
-
-  p->src.buf = &p->src.buf[vp9_raster_block_offset(BLOCK_8X8, i,
-                                                   p->src.stride)];
-  assert(((intptr_t)pd->pre[0].buf & 0x7) == 0);
-  pd->pre[0].buf = &pd->pre[0].buf[vp9_raster_block_offset(BLOCK_8X8, i,
-                                                           pd->pre[0].stride)];
-  if (has_second_ref(mi))
-    pd->pre[1].buf = &pd->pre[1].buf[vp9_raster_block_offset(BLOCK_8X8, i,
-                                                           pd->pre[1].stride)];
-}
-
-static INLINE void mi_buf_restore(MACROBLOCK *x, struct buf_2d orig_src,
-                                  struct buf_2d orig_pre[2]) {
-  MODE_INFO *mi = x->e_mbd.mi[0];
-  x->plane[0].src = orig_src;
-  x->e_mbd.plane[0].pre[0] = orig_pre[0];
-  if (has_second_ref(mi))
-    x->e_mbd.plane[0].pre[1] = orig_pre[1];
-}
-
-static INLINE int mv_has_subpel(const MV *mv) {
-  return (mv->row & 0x0F) || (mv->col & 0x0F);
-}
-
-// Check if NEARESTMV/NEARMV/ZEROMV is the cheapest way encode zero motion.
-// TODO(aconverse): Find out if this is still productive then clean up or remove
-static int check_best_zero_mv(
-    const VP9_COMP *cpi, const uint8_t mode_context[MAX_REF_FRAMES],
-    int_mv frame_mv[MB_MODE_COUNT][MAX_REF_FRAMES], int this_mode,
-    const MV_REFERENCE_FRAME ref_frames[2]) {
-  if ((this_mode == NEARMV || this_mode == NEARESTMV || this_mode == ZEROMV) &&
-      frame_mv[this_mode][ref_frames[0]].as_int == 0 &&
-      (ref_frames[1] == NONE ||
-       frame_mv[this_mode][ref_frames[1]].as_int == 0)) {
-    int rfc = mode_context[ref_frames[0]];
-    int c1 = cost_mv_ref(cpi, NEARMV, rfc);
-    int c2 = cost_mv_ref(cpi, NEARESTMV, rfc);
-    int c3 = cost_mv_ref(cpi, ZEROMV, rfc);
-
-    if (this_mode == NEARMV) {
-      if (c1 > c3) return 0;
-    } else if (this_mode == NEARESTMV) {
-      if (c2 > c3) return 0;
-    } else {
-      assert(this_mode == ZEROMV);
-      if (ref_frames[1] == NONE) {
-        if ((c3 >= c2 && frame_mv[NEARESTMV][ref_frames[0]].as_int == 0) ||
-            (c3 >= c1 && frame_mv[NEARMV][ref_frames[0]].as_int == 0))
-          return 0;
-      } else {
-        if ((c3 >= c2 && frame_mv[NEARESTMV][ref_frames[0]].as_int == 0 &&
-             frame_mv[NEARESTMV][ref_frames[1]].as_int == 0) ||
-            (c3 >= c1 && frame_mv[NEARMV][ref_frames[0]].as_int == 0 &&
-             frame_mv[NEARMV][ref_frames[1]].as_int == 0))
-          return 0;
-      }
-    }
-  }
-  return 1;
-}
-
-static void joint_motion_search(VP9_COMP *cpi, MACROBLOCK *x,
-                                BLOCK_SIZE bsize,
-                                int_mv *frame_mv,
-                                int mi_row, int mi_col,
-                                int_mv single_newmv[MAX_REF_FRAMES],
-                                int *rate_mv) {
-  const VP9_COMMON *const cm = &cpi->common;
-  const int pw = 4 * num_4x4_blocks_wide_lookup[bsize];
-  const int ph = 4 * num_4x4_blocks_high_lookup[bsize];
-  MACROBLOCKD *xd = &x->e_mbd;
-  MODE_INFO *mi = xd->mi[0];
-  const int refs[2] = {mi->ref_frame[0],
-                       mi->ref_frame[1] < 0 ? 0 : mi->ref_frame[1]};
-  int_mv ref_mv[2];
-  int ite, ref;
-  const InterpKernel *kernel = vp9_filter_kernels[mi->interp_filter];
-  struct scale_factors sf;
-
-  // Do joint motion search in compound mode to get more accurate mv.
-  struct buf_2d backup_yv12[2][MAX_MB_PLANE];
-  int last_besterr[2] = {INT_MAX, INT_MAX};
-  const YV12_BUFFER_CONFIG *const scaled_ref_frame[2] = {
-    vp9_get_scaled_ref_frame(cpi, mi->ref_frame[0]),
-    vp9_get_scaled_ref_frame(cpi, mi->ref_frame[1])
-  };
-
-  // Prediction buffer from second frame.
-#if CONFIG_VP9_HIGHBITDEPTH
-  DECLARE_ALIGNED(16, uint16_t, second_pred_alloc_16[64 * 64]);
-  uint8_t *second_pred;
-#else
-  DECLARE_ALIGNED(16, uint8_t, second_pred[64 * 64]);
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-
-  for (ref = 0; ref < 2; ++ref) {
-    ref_mv[ref] = x->mbmi_ext->ref_mvs[refs[ref]][0];
-
-    if (scaled_ref_frame[ref]) {
-      int i;
-      // Swap out the reference frame for a version that's been scaled to
-      // match the resolution of the current frame, allowing the existing
-      // motion search code to be used without additional modifications.
-      for (i = 0; i < MAX_MB_PLANE; i++)
-        backup_yv12[ref][i] = xd->plane[i].pre[ref];
-      vp9_setup_pre_planes(xd, ref, scaled_ref_frame[ref], mi_row, mi_col,
-                           NULL);
-    }
-
-    frame_mv[refs[ref]].as_int = single_newmv[refs[ref]].as_int;
-  }
-
-  // Since we have scaled the reference frames to match the size of the current
-  // frame we must use a unit scaling factor during mode selection.
-#if CONFIG_VP9_HIGHBITDEPTH
-  vp9_setup_scale_factors_for_frame(&sf, cm->width, cm->height,
-                                    cm->width, cm->height,
-                                    cm->use_highbitdepth);
-#else
-  vp9_setup_scale_factors_for_frame(&sf, cm->width, cm->height,
-                                    cm->width, cm->height);
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-
-  // Allow joint search multiple times iteratively for each reference frame
-  // and break out of the search loop if it couldn't find a better mv.
-  for (ite = 0; ite < 4; ite++) {
-    struct buf_2d ref_yv12[2];
-    int bestsme = INT_MAX;
-    int sadpb = x->sadperbit16;
-    MV tmp_mv;
-    int search_range = 3;
-
-    int tmp_col_min = x->mv_col_min;
-    int tmp_col_max = x->mv_col_max;
-    int tmp_row_min = x->mv_row_min;
-    int tmp_row_max = x->mv_row_max;
-    int id = ite % 2;  // Even iterations search in the first reference frame,
-                       // odd iterations search in the second. The predictor
-                       // found for the 'other' reference frame is factored in.
-
-    // Initialized here because of compiler problem in Visual Studio.
-    ref_yv12[0] = xd->plane[0].pre[0];
-    ref_yv12[1] = xd->plane[0].pre[1];
-
-    // Get the prediction block from the 'other' reference frame.
-#if CONFIG_VP9_HIGHBITDEPTH
-    if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
-      second_pred = CONVERT_TO_BYTEPTR(second_pred_alloc_16);
-      vp9_highbd_build_inter_predictor(ref_yv12[!id].buf,
-                                       ref_yv12[!id].stride,
-                                       second_pred, pw,
-                                       &frame_mv[refs[!id]].as_mv,
-                                       &sf, pw, ph, 0,
-                                       kernel, MV_PRECISION_Q3,
-                                       mi_col * MI_SIZE, mi_row * MI_SIZE,
-                                       xd->bd);
-    } else {
-      second_pred = (uint8_t *)second_pred_alloc_16;
-      vp9_build_inter_predictor(ref_yv12[!id].buf,
-                                ref_yv12[!id].stride,
-                                second_pred, pw,
-                                &frame_mv[refs[!id]].as_mv,
-                                &sf, pw, ph, 0,
-                                kernel, MV_PRECISION_Q3,
-                                mi_col * MI_SIZE, mi_row * MI_SIZE);
-    }
-#else
-    vp9_build_inter_predictor(ref_yv12[!id].buf,
-                              ref_yv12[!id].stride,
-                              second_pred, pw,
-                              &frame_mv[refs[!id]].as_mv,
-                              &sf, pw, ph, 0,
-                              kernel, MV_PRECISION_Q3,
-                              mi_col * MI_SIZE, mi_row * MI_SIZE);
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-
-    // Do compound motion search on the current reference frame.
-    if (id)
-      xd->plane[0].pre[0] = ref_yv12[id];
-    vp9_set_mv_search_range(x, &ref_mv[id].as_mv);
-
-    // Use the mv result from the single mode as mv predictor.
-    tmp_mv = frame_mv[refs[id]].as_mv;
-
-    tmp_mv.col >>= 3;
-    tmp_mv.row >>= 3;
-
-    // Small-range full-pixel motion search.
-    bestsme = vp9_refining_search_8p_c(x, &tmp_mv, sadpb,
-                                       search_range,
-                                       &cpi->fn_ptr[bsize],
-                                       &ref_mv[id].as_mv, second_pred);
-    if (bestsme < INT_MAX)
-      bestsme = vp9_get_mvpred_av_var(x, &tmp_mv, &ref_mv[id].as_mv,
-                                      second_pred, &cpi->fn_ptr[bsize], 1);
-
-    x->mv_col_min = tmp_col_min;
-    x->mv_col_max = tmp_col_max;
-    x->mv_row_min = tmp_row_min;
-    x->mv_row_max = tmp_row_max;
-
-    if (bestsme < INT_MAX) {
-      uint32_t dis; /* TODO: use dis in distortion calculation later. */
-      uint32_t sse;
-      bestsme = cpi->find_fractional_mv_step(
-          x, &tmp_mv,
-          &ref_mv[id].as_mv,
-          cpi->common.allow_high_precision_mv,
-          x->errorperbit,
-          &cpi->fn_ptr[bsize],
-          0, cpi->sf.mv.subpel_iters_per_step,
-          NULL,
-          x->nmvjointcost, x->mvcost,
-          &dis, &sse, second_pred,
-          pw, ph);
-    }
-
-    // Restore the pointer to the first (possibly scaled) prediction buffer.
-    if (id)
-      xd->plane[0].pre[0] = ref_yv12[0];
-
-    if (bestsme < last_besterr[id]) {
-      frame_mv[refs[id]].as_mv = tmp_mv;
-      last_besterr[id] = bestsme;
-    } else {
-      break;
-    }
-  }
-
-  *rate_mv = 0;
-
-  for (ref = 0; ref < 2; ++ref) {
-    if (scaled_ref_frame[ref]) {
-      // Restore the prediction frame pointers to their unscaled versions.
-      int i;
-      for (i = 0; i < MAX_MB_PLANE; i++)
-        xd->plane[i].pre[ref] = backup_yv12[ref][i];
-    }
-
-    *rate_mv += vp9_mv_bit_cost(&frame_mv[refs[ref]].as_mv,
-                                &x->mbmi_ext->ref_mvs[refs[ref]][0].as_mv,
-                                x->nmvjointcost, x->mvcost, MV_COST_WEIGHT);
-  }
-}
-
-static int64_t rd_pick_best_sub8x8_mode(VP9_COMP *cpi, MACROBLOCK *x,
-                                        int_mv *best_ref_mv,
-                                        int_mv *second_best_ref_mv,
-                                        int64_t best_rd, int *returntotrate,
-                                        int *returnyrate,
-                                        int64_t *returndistortion,
-                                        int *skippable, int64_t *psse,
-                                        int mvthresh,
-                                        int_mv seg_mvs[4][MAX_REF_FRAMES],
-                                        BEST_SEG_INFO *bsi_buf, int filter_idx,
-                                        int mi_row, int mi_col) {
-  int i;
-  BEST_SEG_INFO *bsi = bsi_buf + filter_idx;
-  MACROBLOCKD *xd = &x->e_mbd;
-  MODE_INFO *mi = xd->mi[0];
-  int mode_idx;
-  int k, br = 0, idx, idy;
-  int64_t bd = 0, block_sse = 0;
-  PREDICTION_MODE this_mode;
-  VP9_COMMON *cm = &cpi->common;
-  struct macroblock_plane *const p = &x->plane[0];
-  struct macroblockd_plane *const pd = &xd->plane[0];
-  const int label_count = 4;
-  int64_t this_segment_rd = 0;
-  int label_mv_thresh;
-  int segmentyrate = 0;
-  const BLOCK_SIZE bsize = mi->sb_type;
-  const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[bsize];
-  const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[bsize];
-  ENTROPY_CONTEXT t_above[2], t_left[2];
-  int subpelmv = 1, have_ref = 0;
-  SPEED_FEATURES *const sf = &cpi->sf;
-  const int has_second_rf = has_second_ref(mi);
-  const int inter_mode_mask = sf->inter_mode_mask[bsize];
-  MB_MODE_INFO_EXT *const mbmi_ext = x->mbmi_ext;
-
-  vp9_zero(*bsi);
-
-  bsi->segment_rd = best_rd;
-  bsi->ref_mv[0] = best_ref_mv;
-  bsi->ref_mv[1] = second_best_ref_mv;
-  bsi->mvp.as_int = best_ref_mv->as_int;
-  bsi->mvthresh = mvthresh;
-
-  for (i = 0; i < 4; i++)
-    bsi->modes[i] = ZEROMV;
-
-  memcpy(t_above, pd->above_context, sizeof(t_above));
-  memcpy(t_left, pd->left_context, sizeof(t_left));
-
-  // 64 makes this threshold really big effectively
-  // making it so that we very rarely check mvs on
-  // segments.   setting this to 1 would make mv thresh
-  // roughly equal to what it is for macroblocks
-  label_mv_thresh = 1 * bsi->mvthresh / label_count;
-
-  // Segmentation method overheads
-  for (idy = 0; idy < 2; idy += num_4x4_blocks_high) {
-    for (idx = 0; idx < 2; idx += num_4x4_blocks_wide) {
-      // TODO(jingning,rbultje): rewrite the rate-distortion optimization
-      // loop for 4x4/4x8/8x4 block coding. to be replaced with new rd loop
-      int_mv mode_mv[MB_MODE_COUNT][2];
-      int_mv frame_mv[MB_MODE_COUNT][MAX_REF_FRAMES];
-      PREDICTION_MODE mode_selected = ZEROMV;
-      int64_t best_rd = INT64_MAX;
-      const int i = idy * 2 + idx;
-      int ref;
-
-      for (ref = 0; ref < 1 + has_second_rf; ++ref) {
-        const MV_REFERENCE_FRAME frame = mi->ref_frame[ref];
-        frame_mv[ZEROMV][frame].as_int = 0;
-        vp9_append_sub8x8_mvs_for_idx(cm, xd, i, ref, mi_row, mi_col,
-                                      &frame_mv[NEARESTMV][frame],
-                                      &frame_mv[NEARMV][frame],
-                                      mbmi_ext->mode_context);
-      }
-
-      // search for the best motion vector on this segment
-      for (this_mode = NEARESTMV; this_mode <= NEWMV; ++this_mode) {
-        const struct buf_2d orig_src = x->plane[0].src;
-        struct buf_2d orig_pre[2];
-
-        mode_idx = INTER_OFFSET(this_mode);
-        bsi->rdstat[i][mode_idx].brdcost = INT64_MAX;
-        if (!(inter_mode_mask & (1 << this_mode)))
-          continue;
-
-        if (!check_best_zero_mv(cpi, mbmi_ext->mode_context, frame_mv,
-                                this_mode, mi->ref_frame))
-          continue;
-
-        memcpy(orig_pre, pd->pre, sizeof(orig_pre));
-        memcpy(bsi->rdstat[i][mode_idx].ta, t_above,
-               sizeof(bsi->rdstat[i][mode_idx].ta));
-        memcpy(bsi->rdstat[i][mode_idx].tl, t_left,
-               sizeof(bsi->rdstat[i][mode_idx].tl));
-
-        // motion search for newmv (single predictor case only)
-        if (!has_second_rf && this_mode == NEWMV &&
-            seg_mvs[i][mi->ref_frame[0]].as_int == INVALID_MV) {
-          MV *const new_mv = &mode_mv[NEWMV][0].as_mv;
-          int step_param = 0;
-          int bestsme = INT_MAX;
-          int sadpb = x->sadperbit4;
-          MV mvp_full;
-          int max_mv;
-          int cost_list[5];
-
-          /* Is the best so far sufficiently good that we cant justify doing
-           * and new motion search. */
-          if (best_rd < label_mv_thresh)
-            break;
-
-          if (cpi->oxcf.mode != BEST) {
-            // use previous block's result as next block's MV predictor.
-            if (i > 0) {
-              bsi->mvp.as_int = mi->bmi[i - 1].as_mv[0].as_int;
-              if (i == 2)
-                bsi->mvp.as_int = mi->bmi[i - 2].as_mv[0].as_int;
-            }
-          }
-          if (i == 0)
-            max_mv = x->max_mv_context[mi->ref_frame[0]];
-          else
-            max_mv =
-                VPXMAX(abs(bsi->mvp.as_mv.row), abs(bsi->mvp.as_mv.col)) >> 3;
-
-          if (sf->mv.auto_mv_step_size && cm->show_frame) {
-            // Take wtd average of the step_params based on the last frame's
-            // max mv magnitude and the best ref mvs of the current block for
-            // the given reference.
-            step_param = (vp9_init_search_range(max_mv) +
-                              cpi->mv_step_param) / 2;
-          } else {
-            step_param = cpi->mv_step_param;
-          }
-
-          mvp_full.row = bsi->mvp.as_mv.row >> 3;
-          mvp_full.col = bsi->mvp.as_mv.col >> 3;
-
-          if (sf->adaptive_motion_search) {
-            mvp_full.row = x->pred_mv[mi->ref_frame[0]].row >> 3;
-            mvp_full.col = x->pred_mv[mi->ref_frame[0]].col >> 3;
-            step_param = VPXMAX(step_param, 8);
-          }
-
-          // adjust src pointer for this block
-          mi_buf_shift(x, i);
-
-          vp9_set_mv_search_range(x, &bsi->ref_mv[0]->as_mv);
-
-          bestsme = vp9_full_pixel_search(
-              cpi, x, bsize, &mvp_full, step_param, sadpb,
-              sf->mv.subpel_search_method != SUBPEL_TREE ? cost_list : NULL,
-              &bsi->ref_mv[0]->as_mv, new_mv,
-              INT_MAX, 1);
-
-          if (bestsme < INT_MAX) {
-            uint32_t distortion;
-            cpi->find_fractional_mv_step(
-                x,
-                new_mv,
-                &bsi->ref_mv[0]->as_mv,
-                cm->allow_high_precision_mv,
-                x->errorperbit, &cpi->fn_ptr[bsize],
-                sf->mv.subpel_force_stop,
-                sf->mv.subpel_iters_per_step,
-                cond_cost_list(cpi, cost_list),
-                x->nmvjointcost, x->mvcost,
-                &distortion,
-                &x->pred_sse[mi->ref_frame[0]],
-                NULL, 0, 0);
-
-            // save motion search result for use in compound prediction
-            seg_mvs[i][mi->ref_frame[0]].as_mv = *new_mv;
-          }
-
-          if (sf->adaptive_motion_search)
-            x->pred_mv[mi->ref_frame[0]] = *new_mv;
-
-          // restore src pointers
-          mi_buf_restore(x, orig_src, orig_pre);
-        }
-
-        if (has_second_rf) {
-          if (seg_mvs[i][mi->ref_frame[1]].as_int == INVALID_MV ||
-              seg_mvs[i][mi->ref_frame[0]].as_int == INVALID_MV)
-            continue;
-        }
-
-        if (has_second_rf && this_mode == NEWMV &&
-            mi->interp_filter == EIGHTTAP) {
-          // adjust src pointers
-          mi_buf_shift(x, i);
-          if (sf->comp_inter_joint_search_thresh <= bsize) {
-            int rate_mv;
-            joint_motion_search(cpi, x, bsize, frame_mv[this_mode],
-                                mi_row, mi_col, seg_mvs[i],
-                                &rate_mv);
-            seg_mvs[i][mi->ref_frame[0]].as_int =
-                frame_mv[this_mode][mi->ref_frame[0]].as_int;
-            seg_mvs[i][mi->ref_frame[1]].as_int =
-                frame_mv[this_mode][mi->ref_frame[1]].as_int;
-          }
-          // restore src pointers
-          mi_buf_restore(x, orig_src, orig_pre);
-        }
-
-        bsi->rdstat[i][mode_idx].brate =
-            set_and_cost_bmi_mvs(cpi, x, xd, i, this_mode, mode_mv[this_mode],
-                                 frame_mv, seg_mvs[i], bsi->ref_mv,
-                                 x->nmvjointcost, x->mvcost);
-
-        for (ref = 0; ref < 1 + has_second_rf; ++ref) {
-          bsi->rdstat[i][mode_idx].mvs[ref].as_int =
-              mode_mv[this_mode][ref].as_int;
-          if (num_4x4_blocks_wide > 1)
-            bsi->rdstat[i + 1][mode_idx].mvs[ref].as_int =
-                mode_mv[this_mode][ref].as_int;
-          if (num_4x4_blocks_high > 1)
-            bsi->rdstat[i + 2][mode_idx].mvs[ref].as_int =
-                mode_mv[this_mode][ref].as_int;
-        }
-
-        // Trap vectors that reach beyond the UMV borders
-        if (mv_check_bounds(x, &mode_mv[this_mode][0].as_mv) ||
-            (has_second_rf &&
-             mv_check_bounds(x, &mode_mv[this_mode][1].as_mv)))
-          continue;
-
-        if (filter_idx > 0) {
-          BEST_SEG_INFO *ref_bsi = bsi_buf;
-          subpelmv = 0;
-          have_ref = 1;
-
-          for (ref = 0; ref < 1 + has_second_rf; ++ref) {
-            subpelmv |= mv_has_subpel(&mode_mv[this_mode][ref].as_mv);
-            have_ref &= mode_mv[this_mode][ref].as_int ==
-                ref_bsi->rdstat[i][mode_idx].mvs[ref].as_int;
-          }
-
-          if (filter_idx > 1 && !subpelmv && !have_ref) {
-            ref_bsi = bsi_buf + 1;
-            have_ref = 1;
-            for (ref = 0; ref < 1 + has_second_rf; ++ref)
-              have_ref &= mode_mv[this_mode][ref].as_int ==
-                  ref_bsi->rdstat[i][mode_idx].mvs[ref].as_int;
-          }
-
-          if (!subpelmv && have_ref &&
-              ref_bsi->rdstat[i][mode_idx].brdcost < INT64_MAX) {
-            memcpy(&bsi->rdstat[i][mode_idx], &ref_bsi->rdstat[i][mode_idx],
-                   sizeof(SEG_RDSTAT));
-            if (num_4x4_blocks_wide > 1)
-              bsi->rdstat[i + 1][mode_idx].eobs =
-                  ref_bsi->rdstat[i + 1][mode_idx].eobs;
-            if (num_4x4_blocks_high > 1)
-              bsi->rdstat[i + 2][mode_idx].eobs =
-                  ref_bsi->rdstat[i + 2][mode_idx].eobs;
-
-            if (bsi->rdstat[i][mode_idx].brdcost < best_rd) {
-              mode_selected = this_mode;
-              best_rd = bsi->rdstat[i][mode_idx].brdcost;
-            }
-            continue;
-          }
-        }
-
-        bsi->rdstat[i][mode_idx].brdcost =
-            encode_inter_mb_segment(cpi, x,
-                                    bsi->segment_rd - this_segment_rd, i,
-                                    &bsi->rdstat[i][mode_idx].byrate,
-                                    &bsi->rdstat[i][mode_idx].bdist,
-                                    &bsi->rdstat[i][mode_idx].bsse,
-                                    bsi->rdstat[i][mode_idx].ta,
-                                    bsi->rdstat[i][mode_idx].tl,
-                                    mi_row, mi_col);
-        if (bsi->rdstat[i][mode_idx].brdcost < INT64_MAX) {
-          bsi->rdstat[i][mode_idx].brdcost += RDCOST(x->rdmult, x->rddiv,
-                                            bsi->rdstat[i][mode_idx].brate, 0);
-          bsi->rdstat[i][mode_idx].brate += bsi->rdstat[i][mode_idx].byrate;
-          bsi->rdstat[i][mode_idx].eobs = p->eobs[i];
-          if (num_4x4_blocks_wide > 1)
-            bsi->rdstat[i + 1][mode_idx].eobs = p->eobs[i + 1];
-          if (num_4x4_blocks_high > 1)
-            bsi->rdstat[i + 2][mode_idx].eobs = p->eobs[i + 2];
-        }
-
-        if (bsi->rdstat[i][mode_idx].brdcost < best_rd) {
-          mode_selected = this_mode;
-          best_rd = bsi->rdstat[i][mode_idx].brdcost;
-        }
-      } /*for each 4x4 mode*/
-
-      if (best_rd == INT64_MAX) {
-        int iy, midx;
-        for (iy = i + 1; iy < 4; ++iy)
-          for (midx = 0; midx < INTER_MODES; ++midx)
-            bsi->rdstat[iy][midx].brdcost = INT64_MAX;
-        bsi->segment_rd = INT64_MAX;
-        return INT64_MAX;
-      }
-
-      mode_idx = INTER_OFFSET(mode_selected);
-      memcpy(t_above, bsi->rdstat[i][mode_idx].ta, sizeof(t_above));
-      memcpy(t_left, bsi->rdstat[i][mode_idx].tl, sizeof(t_left));
-
-      set_and_cost_bmi_mvs(cpi, x, xd, i, mode_selected, mode_mv[mode_selected],
-                           frame_mv, seg_mvs[i], bsi->ref_mv, x->nmvjointcost,
-                           x->mvcost);
-
-      br += bsi->rdstat[i][mode_idx].brate;
-      bd += bsi->rdstat[i][mode_idx].bdist;
-      block_sse += bsi->rdstat[i][mode_idx].bsse;
-      segmentyrate += bsi->rdstat[i][mode_idx].byrate;
-      this_segment_rd += bsi->rdstat[i][mode_idx].brdcost;
-
-      if (this_segment_rd > bsi->segment_rd) {
-        int iy, midx;
-        for (iy = i + 1; iy < 4; ++iy)
-          for (midx = 0; midx < INTER_MODES; ++midx)
-            bsi->rdstat[iy][midx].brdcost = INT64_MAX;
-        bsi->segment_rd = INT64_MAX;
-        return INT64_MAX;
-      }
-    }
-  } /* for each label */
-
-  bsi->r = br;
-  bsi->d = bd;
-  bsi->segment_yrate = segmentyrate;
-  bsi->segment_rd = this_segment_rd;
-  bsi->sse = block_sse;
-
-  // update the coding decisions
-  for (k = 0; k < 4; ++k)
-    bsi->modes[k] = mi->bmi[k].as_mode;
-
-  if (bsi->segment_rd > best_rd)
-    return INT64_MAX;
-  /* set it to the best */
-  for (i = 0; i < 4; i++) {
-    mode_idx = INTER_OFFSET(bsi->modes[i]);
-    mi->bmi[i].as_mv[0].as_int = bsi->rdstat[i][mode_idx].mvs[0].as_int;
-    if (has_second_ref(mi))
-      mi->bmi[i].as_mv[1].as_int = bsi->rdstat[i][mode_idx].mvs[1].as_int;
-    x->plane[0].eobs[i] = bsi->rdstat[i][mode_idx].eobs;
-    mi->bmi[i].as_mode = bsi->modes[i];
-  }
-
-  /*
-   * used to set mbmi->mv.as_int
-   */
-  *returntotrate = bsi->r;
-  *returndistortion = bsi->d;
-  *returnyrate = bsi->segment_yrate;
-  *skippable = vp9_is_skippable_in_plane(x, BLOCK_8X8, 0);
-  *psse = bsi->sse;
-  mi->mode = bsi->modes[3];
-
-  return bsi->segment_rd;
-}
-
-static void estimate_ref_frame_costs(const VP9_COMMON *cm,
-                                     const MACROBLOCKD *xd,
-                                     int segment_id,
-                                     unsigned int *ref_costs_single,
-                                     unsigned int *ref_costs_comp,
-                                     vpx_prob *comp_mode_p) {
-  int seg_ref_active = segfeature_active(&cm->seg, segment_id,
-                                         SEG_LVL_REF_FRAME);
-  if (seg_ref_active) {
-    memset(ref_costs_single, 0, MAX_REF_FRAMES * sizeof(*ref_costs_single));
-    memset(ref_costs_comp,   0, MAX_REF_FRAMES * sizeof(*ref_costs_comp));
-    *comp_mode_p = 128;
-  } else {
-    vpx_prob intra_inter_p = vp9_get_intra_inter_prob(cm, xd);
-    vpx_prob comp_inter_p = 128;
-
-    if (cm->reference_mode == REFERENCE_MODE_SELECT) {
-      comp_inter_p = vp9_get_reference_mode_prob(cm, xd);
-      *comp_mode_p = comp_inter_p;
-    } else {
-      *comp_mode_p = 128;
-    }
-
-    ref_costs_single[INTRA_FRAME] = vp9_cost_bit(intra_inter_p, 0);
-
-    if (cm->reference_mode != COMPOUND_REFERENCE) {
-      vpx_prob ref_single_p1 = vp9_get_pred_prob_single_ref_p1(cm, xd);
-      vpx_prob ref_single_p2 = vp9_get_pred_prob_single_ref_p2(cm, xd);
-      unsigned int base_cost = vp9_cost_bit(intra_inter_p, 1);
-
-      if (cm->reference_mode == REFERENCE_MODE_SELECT)
-        base_cost += vp9_cost_bit(comp_inter_p, 0);
-
-      ref_costs_single[LAST_FRAME] = ref_costs_single[GOLDEN_FRAME] =
-          ref_costs_single[ALTREF_FRAME] = base_cost;
-      ref_costs_single[LAST_FRAME]   += vp9_cost_bit(ref_single_p1, 0);
-      ref_costs_single[GOLDEN_FRAME] += vp9_cost_bit(ref_single_p1, 1);
-      ref_costs_single[ALTREF_FRAME] += vp9_cost_bit(ref_single_p1, 1);
-      ref_costs_single[GOLDEN_FRAME] += vp9_cost_bit(ref_single_p2, 0);
-      ref_costs_single[ALTREF_FRAME] += vp9_cost_bit(ref_single_p2, 1);
-    } else {
-      ref_costs_single[LAST_FRAME]   = 512;
-      ref_costs_single[GOLDEN_FRAME] = 512;
-      ref_costs_single[ALTREF_FRAME] = 512;
-    }
-    if (cm->reference_mode != SINGLE_REFERENCE) {
-      vpx_prob ref_comp_p = vp9_get_pred_prob_comp_ref_p(cm, xd);
-      unsigned int base_cost = vp9_cost_bit(intra_inter_p, 1);
-
-      if (cm->reference_mode == REFERENCE_MODE_SELECT)
-        base_cost += vp9_cost_bit(comp_inter_p, 1);
-
-      ref_costs_comp[LAST_FRAME]   = base_cost + vp9_cost_bit(ref_comp_p, 0);
-      ref_costs_comp[GOLDEN_FRAME] = base_cost + vp9_cost_bit(ref_comp_p, 1);
-    } else {
-      ref_costs_comp[LAST_FRAME]   = 512;
-      ref_costs_comp[GOLDEN_FRAME] = 512;
-    }
-  }
-}
-
-static void store_coding_context(MACROBLOCK *x, PICK_MODE_CONTEXT *ctx,
-                         int mode_index,
-                         int64_t comp_pred_diff[REFERENCE_MODES],
-                         int64_t best_filter_diff[SWITCHABLE_FILTER_CONTEXTS],
-                         int skippable) {
-  MACROBLOCKD *const xd = &x->e_mbd;
-
-  // Take a snapshot of the coding context so it can be
-  // restored if we decide to encode this way
-  ctx->skip = x->skip;
-  ctx->skippable = skippable;
-  ctx->best_mode_index = mode_index;
-  ctx->mic = *xd->mi[0];
-  ctx->mbmi_ext = *x->mbmi_ext;
-  ctx->single_pred_diff = (int)comp_pred_diff[SINGLE_REFERENCE];
-  ctx->comp_pred_diff   = (int)comp_pred_diff[COMPOUND_REFERENCE];
-  ctx->hybrid_pred_diff = (int)comp_pred_diff[REFERENCE_MODE_SELECT];
-
-  memcpy(ctx->best_filter_diff, best_filter_diff,
-         sizeof(*best_filter_diff) * SWITCHABLE_FILTER_CONTEXTS);
-}
-
-static void setup_buffer_inter(VP9_COMP *cpi, MACROBLOCK *x,
-                               MV_REFERENCE_FRAME ref_frame,
-                               BLOCK_SIZE block_size,
-                               int mi_row, int mi_col,
-                               int_mv frame_nearest_mv[MAX_REF_FRAMES],
-                               int_mv frame_near_mv[MAX_REF_FRAMES],
-                               struct buf_2d yv12_mb[4][MAX_MB_PLANE]) {
-  const VP9_COMMON *cm = &cpi->common;
-  const YV12_BUFFER_CONFIG *yv12 = get_ref_frame_buffer(cpi, ref_frame);
-  MACROBLOCKD *const xd = &x->e_mbd;
-  MODE_INFO *const mi = xd->mi[0];
-  int_mv *const candidates = x->mbmi_ext->ref_mvs[ref_frame];
-  const struct scale_factors *const sf = &cm->frame_refs[ref_frame - 1].sf;
-  MB_MODE_INFO_EXT *const mbmi_ext = x->mbmi_ext;
-
-  assert(yv12 != NULL);
-
-  // TODO(jkoleszar): Is the UV buffer ever used here? If so, need to make this
-  // use the UV scaling factors.
-  vp9_setup_pred_block(xd, yv12_mb[ref_frame], yv12, mi_row, mi_col, sf, sf);
-
-  // Gets an initial list of candidate vectors from neighbours and orders them
-  vp9_find_mv_refs(cm, xd, mi, ref_frame, candidates, mi_row, mi_col,
-                   mbmi_ext->mode_context);
-
-  // Candidate refinement carried out at encoder and decoder
-  vp9_find_best_ref_mvs(xd, cm->allow_high_precision_mv, candidates,
-                        &frame_nearest_mv[ref_frame],
-                        &frame_near_mv[ref_frame]);
-
-  // Further refinement that is encode side only to test the top few candidates
-  // in full and choose the best as the centre point for subsequent searches.
-  // The current implementation doesn't support scaling.
-  if (!vp9_is_scaled(sf) && block_size >= BLOCK_8X8)
-    vp9_mv_pred(cpi, x, yv12_mb[ref_frame][0].buf, yv12->y_stride,
-                ref_frame, block_size);
-}
-
-static void single_motion_search(VP9_COMP *cpi, MACROBLOCK *x,
-                                 BLOCK_SIZE bsize,
-                                 int mi_row, int mi_col,
-                                 int_mv *tmp_mv, int *rate_mv) {
-  MACROBLOCKD *xd = &x->e_mbd;
-  const VP9_COMMON *cm = &cpi->common;
-  MODE_INFO *mi = xd->mi[0];
-  struct buf_2d backup_yv12[MAX_MB_PLANE] = {{0, 0}};
-  int bestsme = INT_MAX;
-  int step_param;
-  int sadpb = x->sadperbit16;
-  MV mvp_full;
-  int ref = mi->ref_frame[0];
-  MV ref_mv = x->mbmi_ext->ref_mvs[ref][0].as_mv;
-
-  int tmp_col_min = x->mv_col_min;
-  int tmp_col_max = x->mv_col_max;
-  int tmp_row_min = x->mv_row_min;
-  int tmp_row_max = x->mv_row_max;
-  int cost_list[5];
-
-  const YV12_BUFFER_CONFIG *scaled_ref_frame = vp9_get_scaled_ref_frame(cpi,
-                                                                        ref);
-
-  MV pred_mv[3];
-  pred_mv[0] = x->mbmi_ext->ref_mvs[ref][0].as_mv;
-  pred_mv[1] = x->mbmi_ext->ref_mvs[ref][1].as_mv;
-  pred_mv[2] = x->pred_mv[ref];
-
-  if (scaled_ref_frame) {
-    int i;
-    // Swap out the reference frame for a version that's been scaled to
-    // match the resolution of the current frame, allowing the existing
-    // motion search code to be used without additional modifications.
-    for (i = 0; i < MAX_MB_PLANE; i++)
-      backup_yv12[i] = xd->plane[i].pre[0];
-
-    vp9_setup_pre_planes(xd, 0, scaled_ref_frame, mi_row, mi_col, NULL);
-  }
-
-  vp9_set_mv_search_range(x, &ref_mv);
-
-  // Work out the size of the first step in the mv step search.
-  // 0 here is maximum length first step. 1 is VPXMAX >> 1 etc.
-  if (cpi->sf.mv.auto_mv_step_size && cm->show_frame) {
-    // Take wtd average of the step_params based on the last frame's
-    // max mv magnitude and that based on the best ref mvs of the current
-    // block for the given reference.
-    step_param = (vp9_init_search_range(x->max_mv_context[ref]) +
-                    cpi->mv_step_param) / 2;
-  } else {
-    step_param = cpi->mv_step_param;
-  }
-
-  if (cpi->sf.adaptive_motion_search && bsize < BLOCK_64X64) {
-    int boffset =
-        2 * (b_width_log2_lookup[BLOCK_64X64] -
-             VPXMIN(b_height_log2_lookup[bsize], b_width_log2_lookup[bsize]));
-    step_param = VPXMAX(step_param, boffset);
-  }
-
-  if (cpi->sf.adaptive_motion_search) {
-    int bwl = b_width_log2_lookup[bsize];
-    int bhl = b_height_log2_lookup[bsize];
-    int tlevel = x->pred_mv_sad[ref] >> (bwl + bhl + 4);
-
-    if (tlevel < 5)
-      step_param += 2;
-
-    // prev_mv_sad is not setup for dynamically scaled frames.
-    if (cpi->oxcf.resize_mode != RESIZE_DYNAMIC) {
-      int i;
-      for (i = LAST_FRAME; i <= ALTREF_FRAME && cm->show_frame; ++i) {
-        if ((x->pred_mv_sad[ref] >> 3) > x->pred_mv_sad[i]) {
-          x->pred_mv[ref].row = 0;
-          x->pred_mv[ref].col = 0;
-          tmp_mv->as_int = INVALID_MV;
-
-          if (scaled_ref_frame) {
-            int i;
-            for (i = 0; i < MAX_MB_PLANE; ++i)
-              xd->plane[i].pre[0] = backup_yv12[i];
-          }
-          return;
-        }
-      }
-    }
-  }
-
-  mvp_full = pred_mv[x->mv_best_ref_index[ref]];
-
-  mvp_full.col >>= 3;
-  mvp_full.row >>= 3;
-
-  bestsme = vp9_full_pixel_search(cpi, x, bsize, &mvp_full, step_param, sadpb,
-                                  cond_cost_list(cpi, cost_list),
-                                  &ref_mv, &tmp_mv->as_mv, INT_MAX, 1);
-
-  x->mv_col_min = tmp_col_min;
-  x->mv_col_max = tmp_col_max;
-  x->mv_row_min = tmp_row_min;
-  x->mv_row_max = tmp_row_max;
-
-  if (bestsme < INT_MAX) {
-    uint32_t dis;  /* TODO: use dis in distortion calculation later. */
-    cpi->find_fractional_mv_step(x, &tmp_mv->as_mv, &ref_mv,
-                                 cm->allow_high_precision_mv,
-                                 x->errorperbit,
-                                 &cpi->fn_ptr[bsize],
-                                 cpi->sf.mv.subpel_force_stop,
-                                 cpi->sf.mv.subpel_iters_per_step,
-                                 cond_cost_list(cpi, cost_list),
-                                 x->nmvjointcost, x->mvcost,
-                                 &dis, &x->pred_sse[ref], NULL, 0, 0);
-  }
-  *rate_mv = vp9_mv_bit_cost(&tmp_mv->as_mv, &ref_mv,
-                             x->nmvjointcost, x->mvcost, MV_COST_WEIGHT);
-
-  if (cpi->sf.adaptive_motion_search)
-    x->pred_mv[ref] = tmp_mv->as_mv;
-
-  if (scaled_ref_frame) {
-    int i;
-    for (i = 0; i < MAX_MB_PLANE; i++)
-      xd->plane[i].pre[0] = backup_yv12[i];
-  }
-}
-
-
-
-static INLINE void restore_dst_buf(MACROBLOCKD *xd,
-                                   uint8_t *orig_dst[MAX_MB_PLANE],
-                                   int orig_dst_stride[MAX_MB_PLANE]) {
-  int i;
-  for (i = 0; i < MAX_MB_PLANE; i++) {
-    xd->plane[i].dst.buf = orig_dst[i];
-    xd->plane[i].dst.stride = orig_dst_stride[i];
-  }
-}
-
-// In some situations we want to discount tha pparent cost of a new motion
-// vector. Where there is a subtle motion field and especially where there is
-// low spatial complexity then it can be hard to cover the cost of a new motion
-// vector in a single block, even if that motion vector reduces distortion.
-// However, once established that vector may be usable through the nearest and
-// near mv modes to reduce distortion in subsequent blocks and also improve
-// visual quality.
-static int discount_newmv_test(const VP9_COMP *cpi,
-                               int this_mode,
-                               int_mv this_mv,
-                               int_mv (*mode_mv)[MAX_REF_FRAMES],
-                               int ref_frame) {
-  return (!cpi->rc.is_src_frame_alt_ref &&
-          (this_mode == NEWMV) &&
-          (this_mv.as_int != 0) &&
-          ((mode_mv[NEARESTMV][ref_frame].as_int == 0) ||
-           (mode_mv[NEARESTMV][ref_frame].as_int == INVALID_MV)) &&
-          ((mode_mv[NEARMV][ref_frame].as_int == 0) ||
-           (mode_mv[NEARMV][ref_frame].as_int == INVALID_MV)));
-}
-
-static int64_t handle_inter_mode(VP9_COMP *cpi, MACROBLOCK *x,
-                                 BLOCK_SIZE bsize,
-                                 int *rate2, int64_t *distortion,
-                                 int *skippable,
-                                 int *rate_y, int *rate_uv,
-                                 int *disable_skip,
-                                 int_mv (*mode_mv)[MAX_REF_FRAMES],
-                                 int mi_row, int mi_col,
-                                 int_mv single_newmv[MAX_REF_FRAMES],
-                                 INTERP_FILTER (*single_filter)[MAX_REF_FRAMES],
-                                 int (*single_skippable)[MAX_REF_FRAMES],
-                                 int64_t *psse,
-                                 const int64_t ref_best_rd,
-                                 int64_t *mask_filter,
-                                 int64_t filter_cache[]) {
-  VP9_COMMON *cm = &cpi->common;
-  MACROBLOCKD *xd = &x->e_mbd;
-  MODE_INFO *mi = xd->mi[0];
-  MB_MODE_INFO_EXT *const mbmi_ext = x->mbmi_ext;
-  const int is_comp_pred = has_second_ref(mi);
-  const int this_mode = mi->mode;
-  int_mv *frame_mv = mode_mv[this_mode];
-  int i;
-  int refs[2] = { mi->ref_frame[0],
-    (mi->ref_frame[1] < 0 ? 0 : mi->ref_frame[1]) };
-  int_mv cur_mv[2];
-#if CONFIG_VP9_HIGHBITDEPTH
-  DECLARE_ALIGNED(16, uint16_t, tmp_buf16[MAX_MB_PLANE * 64 * 64]);
-  uint8_t *tmp_buf;
-#else
-  DECLARE_ALIGNED(16, uint8_t, tmp_buf[MAX_MB_PLANE * 64 * 64]);
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-  int pred_exists = 0;
-  int intpel_mv;
-  int64_t rd, tmp_rd, best_rd = INT64_MAX;
-  int best_needs_copy = 0;
-  uint8_t *orig_dst[MAX_MB_PLANE];
-  int orig_dst_stride[MAX_MB_PLANE];
-  int rs = 0;
-  INTERP_FILTER best_filter = SWITCHABLE;
-  uint8_t skip_txfm[MAX_MB_PLANE << 2] = {0};
-  int64_t bsse[MAX_MB_PLANE << 2] = {0};
-
-  int bsl = mi_width_log2_lookup[bsize];
-  int pred_filter_search = cpi->sf.cb_pred_filter_search ?
-      (((mi_row + mi_col) >> bsl) +
-       get_chessboard_index(cm->current_video_frame)) & 0x1 : 0;
-
-  int skip_txfm_sb = 0;
-  int64_t skip_sse_sb = INT64_MAX;
-  int64_t distortion_y = 0, distortion_uv = 0;
-
-#if CONFIG_VP9_HIGHBITDEPTH
-  if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
-    tmp_buf = CONVERT_TO_BYTEPTR(tmp_buf16);
-  } else {
-    tmp_buf = (uint8_t *)tmp_buf16;
-  }
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-
-  if (pred_filter_search) {
-    INTERP_FILTER af = SWITCHABLE, lf = SWITCHABLE;
-    if (xd->above_mi)
-      af = xd->above_mi->interp_filter;
-    if (xd->left_mi)
-      lf = xd->left_mi->interp_filter;
-
-    if ((this_mode != NEWMV) || (af == lf))
-      best_filter = af;
-  }
-
-  if (is_comp_pred) {
-    if (frame_mv[refs[0]].as_int == INVALID_MV ||
-        frame_mv[refs[1]].as_int == INVALID_MV)
-      return INT64_MAX;
-
-    if (cpi->sf.adaptive_mode_search) {
-      if (single_filter[this_mode][refs[0]] ==
-          single_filter[this_mode][refs[1]])
-        best_filter = single_filter[this_mode][refs[0]];
-    }
-  }
-
-  if (this_mode == NEWMV) {
-    int rate_mv;
-    if (is_comp_pred) {
-      // Initialize mv using single prediction mode result.
-      frame_mv[refs[0]].as_int = single_newmv[refs[0]].as_int;
-      frame_mv[refs[1]].as_int = single_newmv[refs[1]].as_int;
-
-      if (cpi->sf.comp_inter_joint_search_thresh <= bsize) {
-        joint_motion_search(cpi, x, bsize, frame_mv,
-                            mi_row, mi_col, single_newmv, &rate_mv);
-      } else {
-        rate_mv  = vp9_mv_bit_cost(&frame_mv[refs[0]].as_mv,
-                                   &x->mbmi_ext->ref_mvs[refs[0]][0].as_mv,
-                                   x->nmvjointcost, x->mvcost, MV_COST_WEIGHT);
-        rate_mv += vp9_mv_bit_cost(&frame_mv[refs[1]].as_mv,
-                                   &x->mbmi_ext->ref_mvs[refs[1]][0].as_mv,
-                                   x->nmvjointcost, x->mvcost, MV_COST_WEIGHT);
-      }
-      *rate2 += rate_mv;
-    } else {
-      int_mv tmp_mv;
-      single_motion_search(cpi, x, bsize, mi_row, mi_col,
-                           &tmp_mv, &rate_mv);
-      if (tmp_mv.as_int == INVALID_MV)
-        return INT64_MAX;
-
-      frame_mv[refs[0]].as_int =
-          xd->mi[0]->bmi[0].as_mv[0].as_int = tmp_mv.as_int;
-      single_newmv[refs[0]].as_int = tmp_mv.as_int;
-
-      // Estimate the rate implications of a new mv but discount this
-      // under certain circumstances where we want to help initiate a weak
-      // motion field, where the distortion gain for a single block may not
-      // be enough to overcome the cost of a new mv.
-      if (discount_newmv_test(cpi, this_mode, tmp_mv, mode_mv, refs[0])) {
-        *rate2 += VPXMAX((rate_mv / NEW_MV_DISCOUNT_FACTOR), 1);
-      } else {
-        *rate2 += rate_mv;
-      }
-    }
-  }
-
-  for (i = 0; i < is_comp_pred + 1; ++i) {
-    cur_mv[i] = frame_mv[refs[i]];
-    // Clip "next_nearest" so that it does not extend to far out of image
-    if (this_mode != NEWMV)
-      clamp_mv2(&cur_mv[i].as_mv, xd);
-
-    if (mv_check_bounds(x, &cur_mv[i].as_mv))
-      return INT64_MAX;
-    mi->mv[i].as_int = cur_mv[i].as_int;
-  }
-
-  // do first prediction into the destination buffer. Do the next
-  // prediction into a temporary buffer. Then keep track of which one
-  // of these currently holds the best predictor, and use the other
-  // one for future predictions. In the end, copy from tmp_buf to
-  // dst if necessary.
-  for (i = 0; i < MAX_MB_PLANE; i++) {
-    orig_dst[i] = xd->plane[i].dst.buf;
-    orig_dst_stride[i] = xd->plane[i].dst.stride;
-  }
-
-  // We don't include the cost of the second reference here, because there
-  // are only two options: Last/ARF or Golden/ARF; The second one is always
-  // known, which is ARF.
-  //
-  // Under some circumstances we discount the cost of new mv mode to encourage
-  // initiation of a motion field.
-  if (discount_newmv_test(cpi, this_mode, frame_mv[refs[0]],
-                          mode_mv, refs[0])) {
-    *rate2 += VPXMIN(cost_mv_ref(cpi, this_mode,
-                                 mbmi_ext->mode_context[refs[0]]),
-                     cost_mv_ref(cpi, NEARESTMV,
-                                 mbmi_ext->mode_context[refs[0]]));
-  } else {
-    *rate2 += cost_mv_ref(cpi, this_mode, mbmi_ext->mode_context[refs[0]]);
-  }
-
-  if (RDCOST(x->rdmult, x->rddiv, *rate2, 0) > ref_best_rd &&
-      mi->mode != NEARESTMV)
-    return INT64_MAX;
-
-  pred_exists = 0;
-  // Are all MVs integer pel for Y and UV
-  intpel_mv = !mv_has_subpel(&mi->mv[0].as_mv);
-  if (is_comp_pred)
-    intpel_mv &= !mv_has_subpel(&mi->mv[1].as_mv);
-
-  // Search for best switchable filter by checking the variance of
-  // pred error irrespective of whether the filter will be used
-  for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; ++i)
-    filter_cache[i] = INT64_MAX;
-
-  if (cm->interp_filter != BILINEAR) {
-    if (x->source_variance < cpi->sf.disable_filter_search_var_thresh) {
-      best_filter = EIGHTTAP;
-    } else if (best_filter == SWITCHABLE) {
-      int newbest;
-      int tmp_rate_sum = 0;
-      int64_t tmp_dist_sum = 0;
-
-      for (i = 0; i < SWITCHABLE_FILTERS; ++i) {
-        int j;
-        int64_t rs_rd;
-        int tmp_skip_sb = 0;
-        int64_t tmp_skip_sse = INT64_MAX;
-
-        mi->interp_filter = i;
-        rs = vp9_get_switchable_rate(cpi, xd);
-        rs_rd = RDCOST(x->rdmult, x->rddiv, rs, 0);
-
-        if (i > 0 && intpel_mv) {
-          rd = RDCOST(x->rdmult, x->rddiv, tmp_rate_sum, tmp_dist_sum);
-          filter_cache[i] = rd;
-          filter_cache[SWITCHABLE_FILTERS] =
-              VPXMIN(filter_cache[SWITCHABLE_FILTERS], rd + rs_rd);
-          if (cm->interp_filter == SWITCHABLE)
-            rd += rs_rd;
-          *mask_filter = VPXMAX(*mask_filter, rd);
-        } else {
-          int rate_sum = 0;
-          int64_t dist_sum = 0;
-          if (i > 0 && cpi->sf.adaptive_interp_filter_search &&
-              (cpi->sf.interp_filter_search_mask & (1 << i))) {
-            rate_sum = INT_MAX;
-            dist_sum = INT64_MAX;
-            continue;
-          }
-
-          if ((cm->interp_filter == SWITCHABLE &&
-               (!i || best_needs_copy)) ||
-              (cm->interp_filter != SWITCHABLE &&
-               (cm->interp_filter == mi->interp_filter ||
-                (i == 0 && intpel_mv)))) {
-            restore_dst_buf(xd, orig_dst, orig_dst_stride);
-          } else {
-            for (j = 0; j < MAX_MB_PLANE; j++) {
-              xd->plane[j].dst.buf = tmp_buf + j * 64 * 64;
-              xd->plane[j].dst.stride = 64;
-            }
-          }
-          vp9_build_inter_predictors_sb(xd, mi_row, mi_col, bsize);
-          model_rd_for_sb(cpi, bsize, x, xd, &rate_sum, &dist_sum,
-                          &tmp_skip_sb, &tmp_skip_sse);
-
-          rd = RDCOST(x->rdmult, x->rddiv, rate_sum, dist_sum);
-          filter_cache[i] = rd;
-          filter_cache[SWITCHABLE_FILTERS] =
-              VPXMIN(filter_cache[SWITCHABLE_FILTERS], rd + rs_rd);
-          if (cm->interp_filter == SWITCHABLE)
-            rd += rs_rd;
-          *mask_filter = VPXMAX(*mask_filter, rd);
-
-          if (i == 0 && intpel_mv) {
-            tmp_rate_sum = rate_sum;
-            tmp_dist_sum = dist_sum;
-          }
-        }
-
-        if (i == 0 && cpi->sf.use_rd_breakout && ref_best_rd < INT64_MAX) {
-          if (rd / 2 > ref_best_rd) {
-            restore_dst_buf(xd, orig_dst, orig_dst_stride);
-            return INT64_MAX;
-          }
-        }
-        newbest = i == 0 || rd < best_rd;
-
-        if (newbest) {
-          best_rd = rd;
-          best_filter = mi->interp_filter;
-          if (cm->interp_filter == SWITCHABLE && i && !intpel_mv)
-            best_needs_copy = !best_needs_copy;
-        }
-
-        if ((cm->interp_filter == SWITCHABLE && newbest) ||
-            (cm->interp_filter != SWITCHABLE &&
-             cm->interp_filter == mi->interp_filter)) {
-          pred_exists = 1;
-          tmp_rd = best_rd;
-
-          skip_txfm_sb = tmp_skip_sb;
-          skip_sse_sb = tmp_skip_sse;
-          memcpy(skip_txfm, x->skip_txfm, sizeof(skip_txfm));
-          memcpy(bsse, x->bsse, sizeof(bsse));
-        }
-      }
-      restore_dst_buf(xd, orig_dst, orig_dst_stride);
-    }
-  }
-  // Set the appropriate filter
-  mi->interp_filter = cm->interp_filter != SWITCHABLE ?
-      cm->interp_filter : best_filter;
-  rs = cm->interp_filter == SWITCHABLE ? vp9_get_switchable_rate(cpi, xd) : 0;
-
-  if (pred_exists) {
-    if (best_needs_copy) {
-      // again temporarily set the buffers to local memory to prevent a memcpy
-      for (i = 0; i < MAX_MB_PLANE; i++) {
-        xd->plane[i].dst.buf = tmp_buf + i * 64 * 64;
-        xd->plane[i].dst.stride = 64;
-      }
-    }
-    rd = tmp_rd + RDCOST(x->rdmult, x->rddiv, rs, 0);
-  } else {
-    int tmp_rate;
-    int64_t tmp_dist;
-    // Handles the special case when a filter that is not in the
-    // switchable list (ex. bilinear) is indicated at the frame level, or
-    // skip condition holds.
-    vp9_build_inter_predictors_sb(xd, mi_row, mi_col, bsize);
-    model_rd_for_sb(cpi, bsize, x, xd, &tmp_rate, &tmp_dist,
-                    &skip_txfm_sb, &skip_sse_sb);
-    rd = RDCOST(x->rdmult, x->rddiv, rs + tmp_rate, tmp_dist);
-    memcpy(skip_txfm, x->skip_txfm, sizeof(skip_txfm));
-    memcpy(bsse, x->bsse, sizeof(bsse));
-  }
-
-  if (!is_comp_pred)
-    single_filter[this_mode][refs[0]] = mi->interp_filter;
-
-  if (cpi->sf.adaptive_mode_search)
-    if (is_comp_pred)
-      if (single_skippable[this_mode][refs[0]] &&
-          single_skippable[this_mode][refs[1]])
-        memset(skip_txfm, SKIP_TXFM_AC_DC, sizeof(skip_txfm));
-
-  if (cpi->sf.use_rd_breakout && ref_best_rd < INT64_MAX) {
-    // if current pred_error modeled rd is substantially more than the best
-    // so far, do not bother doing full rd
-    if (rd / 2 > ref_best_rd) {
-      restore_dst_buf(xd, orig_dst, orig_dst_stride);
-      return INT64_MAX;
-    }
-  }
-
-  if (cm->interp_filter == SWITCHABLE)
-    *rate2 += rs;
-
-  memcpy(x->skip_txfm, skip_txfm, sizeof(skip_txfm));
-  memcpy(x->bsse, bsse, sizeof(bsse));
-
-  if (!skip_txfm_sb) {
-    int skippable_y, skippable_uv;
-    int64_t sseuv = INT64_MAX;
-    int64_t rdcosty = INT64_MAX;
-
-    // Y cost and distortion
-    vp9_subtract_plane(x, bsize, 0);
-    super_block_yrd(cpi, x, rate_y, &distortion_y, &skippable_y, psse,
-                    bsize, ref_best_rd);
-
-    if (*rate_y == INT_MAX) {
-      *rate2 = INT_MAX;
-      *distortion = INT64_MAX;
-      restore_dst_buf(xd, orig_dst, orig_dst_stride);
-      return INT64_MAX;
-    }
-
-    *rate2 += *rate_y;
-    *distortion += distortion_y;
-
-    rdcosty = RDCOST(x->rdmult, x->rddiv, *rate2, *distortion);
-    rdcosty = VPXMIN(rdcosty, RDCOST(x->rdmult, x->rddiv, 0, *psse));
-
-    if (!super_block_uvrd(cpi, x, rate_uv, &distortion_uv, &skippable_uv,
-                          &sseuv, bsize, ref_best_rd - rdcosty)) {
-      *rate2 = INT_MAX;
-      *distortion = INT64_MAX;
-      restore_dst_buf(xd, orig_dst, orig_dst_stride);
-      return INT64_MAX;
-    }
-
-    *psse += sseuv;
-    *rate2 += *rate_uv;
-    *distortion += distortion_uv;
-    *skippable = skippable_y && skippable_uv;
-  } else {
-    x->skip = 1;
-    *disable_skip = 1;
-
-    // The cost of skip bit needs to be added.
-    *rate2 += vp9_cost_bit(vp9_get_skip_prob(cm, xd), 1);
-
-    *distortion = skip_sse_sb;
-  }
-
-  if (!is_comp_pred)
-    single_skippable[this_mode][refs[0]] = *skippable;
-
-  restore_dst_buf(xd, orig_dst, orig_dst_stride);
-  return 0;  // The rate-distortion cost will be re-calculated by caller.
-}
-
-void vp9_rd_pick_intra_mode_sb(VP9_COMP *cpi, MACROBLOCK *x,
-                               RD_COST *rd_cost, BLOCK_SIZE bsize,
-                               PICK_MODE_CONTEXT *ctx, int64_t best_rd) {
-  VP9_COMMON *const cm = &cpi->common;
-  MACROBLOCKD *const xd = &x->e_mbd;
-  struct macroblockd_plane *const pd = xd->plane;
-  int rate_y = 0, rate_uv = 0, rate_y_tokenonly = 0, rate_uv_tokenonly = 0;
-  int y_skip = 0, uv_skip = 0;
-  int64_t dist_y = 0, dist_uv = 0;
-  TX_SIZE max_uv_tx_size;
-  x->skip_encode = 0;
-  ctx->skip = 0;
-  xd->mi[0]->ref_frame[0] = INTRA_FRAME;
-  xd->mi[0]->ref_frame[1] = NONE;
-
-  if (bsize >= BLOCK_8X8) {
-    if (rd_pick_intra_sby_mode(cpi, x, &rate_y, &rate_y_tokenonly,
-                               &dist_y, &y_skip, bsize,
-                               best_rd) >= best_rd) {
-      rd_cost->rate = INT_MAX;
-      return;
-    }
-  } else {
-    y_skip = 0;
-    if (rd_pick_intra_sub_8x8_y_mode(cpi, x, &rate_y, &rate_y_tokenonly,
-                                     &dist_y, best_rd) >= best_rd) {
-      rd_cost->rate = INT_MAX;
-      return;
-    }
-  }
-  max_uv_tx_size = get_uv_tx_size_impl(xd->mi[0]->tx_size, bsize,
-                                       pd[1].subsampling_x,
-                                       pd[1].subsampling_y);
-  rd_pick_intra_sbuv_mode(cpi, x, ctx, &rate_uv, &rate_uv_tokenonly,
-                          &dist_uv, &uv_skip, VPXMAX(BLOCK_8X8, bsize),
-                          max_uv_tx_size);
-
-  if (y_skip && uv_skip) {
-    rd_cost->rate = rate_y + rate_uv - rate_y_tokenonly - rate_uv_tokenonly +
-                    vp9_cost_bit(vp9_get_skip_prob(cm, xd), 1);
-    rd_cost->dist = dist_y + dist_uv;
-  } else {
-    rd_cost->rate = rate_y + rate_uv +
-                      vp9_cost_bit(vp9_get_skip_prob(cm, xd), 0);
-    rd_cost->dist = dist_y + dist_uv;
-  }
-
-  ctx->mic = *xd->mi[0];
-  ctx->mbmi_ext = *x->mbmi_ext;
-  rd_cost->rdcost = RDCOST(x->rdmult, x->rddiv, rd_cost->rate, rd_cost->dist);
-}
-
-// This function is designed to apply a bias or adjustment to an rd value based
-// on the relative variance of the source and reconstruction.
-#define LOW_VAR_THRESH 16
-#define VLOW_ADJ_MAX 25
-#define VHIGH_ADJ_MAX 8
-static void rd_variance_adjustment(VP9_COMP *cpi,
-                                   MACROBLOCK *x,
-                                   BLOCK_SIZE bsize,
-                                   int64_t *this_rd,
-                                   MV_REFERENCE_FRAME ref_frame,
-                                   unsigned int source_variance) {
-  MACROBLOCKD *const xd = &x->e_mbd;
-  unsigned int recon_variance;
-  unsigned int absvar_diff = 0;
-  int64_t var_error = 0;
-  int64_t var_factor = 0;
-
-  if (*this_rd == INT64_MAX)
-    return;
-
-#if CONFIG_VP9_HIGHBITDEPTH
-  if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
-    recon_variance =
-      vp9_high_get_sby_perpixel_variance(cpi, &xd->plane[0].dst, bsize, xd->bd);
-  } else {
-    recon_variance =
-      vp9_get_sby_perpixel_variance(cpi, &xd->plane[0].dst, bsize);
-  }
-#else
-  recon_variance =
-    vp9_get_sby_perpixel_variance(cpi, &xd->plane[0].dst, bsize);
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-
-  if ((source_variance + recon_variance) > LOW_VAR_THRESH) {
-    absvar_diff = (source_variance > recon_variance)
-      ? (source_variance - recon_variance)
-      : (recon_variance - source_variance);
-
-    var_error = ((int64_t)200 * source_variance * recon_variance) /
-      (((int64_t)source_variance * source_variance) +
-       ((int64_t)recon_variance * recon_variance));
-    var_error = 100 - var_error;
-  }
-
-  // Source variance above a threshold and ref frame is intra.
-  // This case is targeted mainly at discouraging intra modes that give rise
-  // to a predictor with a low spatial complexity compared to the source.
-  if ((source_variance > LOW_VAR_THRESH) && (ref_frame == INTRA_FRAME) &&
-      (source_variance > recon_variance)) {
-    var_factor = VPXMIN(absvar_diff, VPXMIN(VLOW_ADJ_MAX, var_error));
-  // A second possible case of interest is where the source variance
-  // is very low and we wish to discourage false texture or motion trails.
-  } else if ((source_variance < (LOW_VAR_THRESH >> 1)) &&
-             (recon_variance > source_variance)) {
-    var_factor = VPXMIN(absvar_diff, VPXMIN(VHIGH_ADJ_MAX, var_error));
-  }
-  *this_rd += (*this_rd * var_factor) / 100;
-}
-
-
-// Do we have an internal image edge (e.g. formatting bars).
-int vp9_internal_image_edge(VP9_COMP *cpi) {
-  return (cpi->oxcf.pass == 2) &&
-    ((cpi->twopass.this_frame_stats.inactive_zone_rows > 0) ||
-    (cpi->twopass.this_frame_stats.inactive_zone_cols > 0));
-}
-
-// Checks to see if a super block is on a horizontal image edge.
-// In most cases this is the "real" edge unless there are formatting
-// bars embedded in the stream.
-int vp9_active_h_edge(VP9_COMP *cpi, int mi_row, int mi_step) {
-  int top_edge = 0;
-  int bottom_edge = cpi->common.mi_rows;
-  int is_active_h_edge = 0;
-
-  // For two pass account for any formatting bars detected.
-  if (cpi->oxcf.pass == 2) {
-    TWO_PASS *twopass = &cpi->twopass;
-
-    // The inactive region is specified in MBs not mi units.
-    // The image edge is in the following MB row.
-    top_edge += (int)(twopass->this_frame_stats.inactive_zone_rows * 2);
-
-    bottom_edge -= (int)(twopass->this_frame_stats.inactive_zone_rows * 2);
-    bottom_edge = VPXMAX(top_edge, bottom_edge);
-  }
-
-  if (((top_edge >= mi_row) && (top_edge < (mi_row + mi_step))) ||
-      ((bottom_edge >= mi_row) && (bottom_edge < (mi_row + mi_step)))) {
-    is_active_h_edge = 1;
-  }
-  return is_active_h_edge;
-}
-
-// Checks to see if a super block is on a vertical image edge.
-// In most cases this is the "real" edge unless there are formatting
-// bars embedded in the stream.
-int vp9_active_v_edge(VP9_COMP *cpi, int mi_col, int mi_step) {
-  int left_edge = 0;
-  int right_edge = cpi->common.mi_cols;
-  int is_active_v_edge = 0;
-
-  // For two pass account for any formatting bars detected.
-  if (cpi->oxcf.pass == 2) {
-    TWO_PASS *twopass = &cpi->twopass;
-
-    // The inactive region is specified in MBs not mi units.
-    // The image edge is in the following MB row.
-    left_edge += (int)(twopass->this_frame_stats.inactive_zone_cols * 2);
-
-    right_edge -= (int)(twopass->this_frame_stats.inactive_zone_cols * 2);
-    right_edge = VPXMAX(left_edge, right_edge);
-  }
-
-  if (((left_edge >= mi_col) && (left_edge < (mi_col + mi_step))) ||
-      ((right_edge >= mi_col) && (right_edge < (mi_col + mi_step)))) {
-    is_active_v_edge = 1;
-  }
-  return is_active_v_edge;
-}
-
-// Checks to see if a super block is at the edge of the active image.
-// In most cases this is the "real" edge unless there are formatting
-// bars embedded in the stream.
-int vp9_active_edge_sb(VP9_COMP *cpi,
-                       int mi_row, int mi_col) {
-  return vp9_active_h_edge(cpi, mi_row, MI_BLOCK_SIZE) ||
-         vp9_active_v_edge(cpi, mi_col, MI_BLOCK_SIZE);
-}
-
-void vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi,
-                               TileDataEnc *tile_data,
-                               MACROBLOCK *x,
-                               int mi_row, int mi_col,
-                               RD_COST *rd_cost, BLOCK_SIZE bsize,
-                               PICK_MODE_CONTEXT *ctx,
-                               int64_t best_rd_so_far) {
-  VP9_COMMON *const cm = &cpi->common;
-  TileInfo *const tile_info = &tile_data->tile_info;
-  RD_OPT *const rd_opt = &cpi->rd;
-  SPEED_FEATURES *const sf = &cpi->sf;
-  MACROBLOCKD *const xd = &x->e_mbd;
-  MODE_INFO *const mi = xd->mi[0];
-  MB_MODE_INFO_EXT *const mbmi_ext = x->mbmi_ext;
-  const struct segmentation *const seg = &cm->seg;
-  PREDICTION_MODE this_mode;
-  MV_REFERENCE_FRAME ref_frame, second_ref_frame;
-  unsigned char segment_id = mi->segment_id;
-  int comp_pred, i, k;
-  int_mv frame_mv[MB_MODE_COUNT][MAX_REF_FRAMES];
-  struct buf_2d yv12_mb[4][MAX_MB_PLANE];
-  int_mv single_newmv[MAX_REF_FRAMES] = { { 0 } };
-  INTERP_FILTER single_inter_filter[MB_MODE_COUNT][MAX_REF_FRAMES];
-  int single_skippable[MB_MODE_COUNT][MAX_REF_FRAMES];
-  static const int flag_list[4] = { 0, VP9_LAST_FLAG, VP9_GOLD_FLAG,
-                                    VP9_ALT_FLAG };
-  int64_t best_rd = best_rd_so_far;
-  int64_t best_pred_diff[REFERENCE_MODES];
-  int64_t best_pred_rd[REFERENCE_MODES];
-  int64_t best_filter_rd[SWITCHABLE_FILTER_CONTEXTS];
-  int64_t best_filter_diff[SWITCHABLE_FILTER_CONTEXTS];
-  MODE_INFO best_mbmode;
-  int best_mode_skippable = 0;
-  int midx, best_mode_index = -1;
-  unsigned int ref_costs_single[MAX_REF_FRAMES], ref_costs_comp[MAX_REF_FRAMES];
-  vpx_prob comp_mode_p;
-  int64_t best_intra_rd = INT64_MAX;
-  unsigned int best_pred_sse = UINT_MAX;
-  PREDICTION_MODE best_intra_mode = DC_PRED;
-  int rate_uv_intra[TX_SIZES], rate_uv_tokenonly[TX_SIZES];
-  int64_t dist_uv[TX_SIZES];
-  int skip_uv[TX_SIZES];
-  PREDICTION_MODE mode_uv[TX_SIZES];
-  const int intra_cost_penalty = vp9_get_intra_cost_penalty(
-      cm->base_qindex, cm->y_dc_delta_q, cm->bit_depth);
-  int best_skip2 = 0;
-  uint8_t ref_frame_skip_mask[2] = { 0 };
-  uint16_t mode_skip_mask[MAX_REF_FRAMES] = { 0 };
-  int mode_skip_start = sf->mode_skip_start + 1;
-  const int *const rd_threshes = rd_opt->threshes[segment_id][bsize];
-  const int *const rd_thresh_freq_fact = tile_data->thresh_freq_fact[bsize];
-  int64_t mode_threshold[MAX_MODES];
-  int *mode_map = tile_data->mode_map[bsize];
-  const int mode_search_skip_flags = sf->mode_search_skip_flags;
-  int64_t mask_filter = 0;
-  int64_t filter_cache[SWITCHABLE_FILTER_CONTEXTS];
-
-  vp9_zero(best_mbmode);
-
-  x->skip_encode = sf->skip_encode_frame && x->q_index < QIDX_SKIP_THRESH;
-
-  for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; ++i)
-    filter_cache[i] = INT64_MAX;
-
-  estimate_ref_frame_costs(cm, xd, segment_id, ref_costs_single, ref_costs_comp,
-                           &comp_mode_p);
-
-  for (i = 0; i < REFERENCE_MODES; ++i)
-    best_pred_rd[i] = INT64_MAX;
-  for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++)
-    best_filter_rd[i] = INT64_MAX;
-  for (i = 0; i < TX_SIZES; i++)
-    rate_uv_intra[i] = INT_MAX;
-  for (i = 0; i < MAX_REF_FRAMES; ++i)
-    x->pred_sse[i] = INT_MAX;
-  for (i = 0; i < MB_MODE_COUNT; ++i) {
-    for (k = 0; k < MAX_REF_FRAMES; ++k) {
-      single_inter_filter[i][k] = SWITCHABLE;
-      single_skippable[i][k] = 0;
-    }
-  }
-
-  rd_cost->rate = INT_MAX;
-
-  for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) {
-    x->pred_mv_sad[ref_frame] = INT_MAX;
-    if (cpi->ref_frame_flags & flag_list[ref_frame]) {
-      assert(get_ref_frame_buffer(cpi, ref_frame) != NULL);
-      setup_buffer_inter(cpi, x, ref_frame, bsize, mi_row, mi_col,
-                         frame_mv[NEARESTMV], frame_mv[NEARMV], yv12_mb);
-    }
-    frame_mv[NEWMV][ref_frame].as_int = INVALID_MV;
-    frame_mv[ZEROMV][ref_frame].as_int = 0;
-  }
-
-  for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) {
-    if (!(cpi->ref_frame_flags & flag_list[ref_frame])) {
-      // Skip checking missing references in both single and compound reference
-      // modes. Note that a mode will be skipped if both reference frames
-      // are masked out.
-      ref_frame_skip_mask[0] |= (1 << ref_frame);
-      ref_frame_skip_mask[1] |= SECOND_REF_FRAME_MASK;
-    } else if (sf->reference_masking) {
-      for (i = LAST_FRAME; i <= ALTREF_FRAME; ++i) {
-        // Skip fixed mv modes for poor references
-        if ((x->pred_mv_sad[ref_frame] >> 2) > x->pred_mv_sad[i]) {
-          mode_skip_mask[ref_frame] |= INTER_NEAREST_NEAR_ZERO;
-          break;
-        }
-      }
-    }
-    // If the segment reference frame feature is enabled....
-    // then do nothing if the current ref frame is not allowed..
-    if (segfeature_active(seg, segment_id, SEG_LVL_REF_FRAME) &&
-        get_segdata(seg, segment_id, SEG_LVL_REF_FRAME) != (int)ref_frame) {
-      ref_frame_skip_mask[0] |= (1 << ref_frame);
-      ref_frame_skip_mask[1] |= SECOND_REF_FRAME_MASK;
-    }
-  }
-
-  // Disable this drop out case if the ref frame
-  // segment level feature is enabled for this segment. This is to
-  // prevent the possibility that we end up unable to pick any mode.
-  if (!segfeature_active(seg, segment_id, SEG_LVL_REF_FRAME)) {
-    // Only consider ZEROMV/ALTREF_FRAME for alt ref frame,
-    // unless ARNR filtering is enabled in which case we want
-    // an unfiltered alternative. We allow near/nearest as well
-    // because they may result in zero-zero MVs but be cheaper.
-    if (cpi->rc.is_src_frame_alt_ref && (cpi->oxcf.arnr_max_frames == 0)) {
-      ref_frame_skip_mask[0] = (1 << LAST_FRAME) | (1 << GOLDEN_FRAME);
-      ref_frame_skip_mask[1] = SECOND_REF_FRAME_MASK;
-      mode_skip_mask[ALTREF_FRAME] = ~INTER_NEAREST_NEAR_ZERO;
-      if (frame_mv[NEARMV][ALTREF_FRAME].as_int != 0)
-        mode_skip_mask[ALTREF_FRAME] |= (1 << NEARMV);
-      if (frame_mv[NEARESTMV][ALTREF_FRAME].as_int != 0)
-        mode_skip_mask[ALTREF_FRAME] |= (1 << NEARESTMV);
-    }
-  }
-
-  if (cpi->rc.is_src_frame_alt_ref) {
-    if (sf->alt_ref_search_fp) {
-      mode_skip_mask[ALTREF_FRAME] = 0;
-      ref_frame_skip_mask[0] = ~(1 << ALTREF_FRAME);
-      ref_frame_skip_mask[1] = SECOND_REF_FRAME_MASK;
-    }
-  }
-
-  if (sf->alt_ref_search_fp)
-    if (!cm->show_frame && x->pred_mv_sad[GOLDEN_FRAME] < INT_MAX)
-      if (x->pred_mv_sad[ALTREF_FRAME] > (x->pred_mv_sad[GOLDEN_FRAME] << 1))
-        mode_skip_mask[ALTREF_FRAME] |= INTER_ALL;
-
-  if (sf->adaptive_mode_search) {
-    if (cm->show_frame && !cpi->rc.is_src_frame_alt_ref &&
-        cpi->rc.frames_since_golden >= 3)
-      if (x->pred_mv_sad[GOLDEN_FRAME] > (x->pred_mv_sad[LAST_FRAME] << 1))
-        mode_skip_mask[GOLDEN_FRAME] |= INTER_ALL;
-  }
-
-  if (bsize > sf->max_intra_bsize) {
-    ref_frame_skip_mask[0] |= (1 << INTRA_FRAME);
-    ref_frame_skip_mask[1] |= (1 << INTRA_FRAME);
-  }
-
-  mode_skip_mask[INTRA_FRAME] |=
-      ~(sf->intra_y_mode_mask[max_txsize_lookup[bsize]]);
-
-  for (i = 0; i <= LAST_NEW_MV_INDEX; ++i)
-    mode_threshold[i] = 0;
-  for (i = LAST_NEW_MV_INDEX + 1; i < MAX_MODES; ++i)
-    mode_threshold[i] = ((int64_t)rd_threshes[i] * rd_thresh_freq_fact[i]) >> 5;
-
-  midx =  sf->schedule_mode_search ? mode_skip_start : 0;
-  while (midx > 4) {
-    uint8_t end_pos = 0;
-    for (i = 5; i < midx; ++i) {
-      if (mode_threshold[mode_map[i - 1]] > mode_threshold[mode_map[i]]) {
-        uint8_t tmp = mode_map[i];
-        mode_map[i] = mode_map[i - 1];
-        mode_map[i - 1] = tmp;
-        end_pos = i;
-      }
-    }
-    midx = end_pos;
-  }
-
-  for (midx = 0; midx < MAX_MODES; ++midx) {
-    int mode_index = mode_map[midx];
-    int mode_excluded = 0;
-    int64_t this_rd = INT64_MAX;
-    int disable_skip = 0;
-    int compmode_cost = 0;
-    int rate2 = 0, rate_y = 0, rate_uv = 0;
-    int64_t distortion2 = 0, distortion_y = 0, distortion_uv = 0;
-    int skippable = 0;
-    int this_skip2 = 0;
-    int64_t total_sse = INT64_MAX;
-    int early_term = 0;
-
-    this_mode = vp9_mode_order[mode_index].mode;
-    ref_frame = vp9_mode_order[mode_index].ref_frame[0];
-    second_ref_frame = vp9_mode_order[mode_index].ref_frame[1];
-
-    // Look at the reference frame of the best mode so far and set the
-    // skip mask to look at a subset of the remaining modes.
-    if (midx == mode_skip_start && best_mode_index >= 0) {
-      switch (best_mbmode.ref_frame[0]) {
-        case INTRA_FRAME:
-          break;
-        case LAST_FRAME:
-          ref_frame_skip_mask[0] |= LAST_FRAME_MODE_MASK;
-          ref_frame_skip_mask[1] |= SECOND_REF_FRAME_MASK;
-          break;
-        case GOLDEN_FRAME:
-          ref_frame_skip_mask[0] |= GOLDEN_FRAME_MODE_MASK;
-          ref_frame_skip_mask[1] |= SECOND_REF_FRAME_MASK;
-          break;
-        case ALTREF_FRAME:
-          ref_frame_skip_mask[0] |= ALT_REF_MODE_MASK;
-          break;
-        case NONE:
-        case MAX_REF_FRAMES:
-          assert(0 && "Invalid Reference frame");
-          break;
-      }
-    }
-
-    if ((ref_frame_skip_mask[0] & (1 << ref_frame)) &&
-        (ref_frame_skip_mask[1] & (1 << VPXMAX(0, second_ref_frame))))
-      continue;
-
-    if (mode_skip_mask[ref_frame] & (1 << this_mode))
-      continue;
-
-    // Test best rd so far against threshold for trying this mode.
-    if (best_mode_skippable && sf->schedule_mode_search)
-      mode_threshold[mode_index] <<= 1;
-
-    if (best_rd < mode_threshold[mode_index])
-      continue;
-
-    if (sf->motion_field_mode_search) {
-      const int mi_width  = VPXMIN(num_8x8_blocks_wide_lookup[bsize],
-                                   tile_info->mi_col_end - mi_col);
-      const int mi_height = VPXMIN(num_8x8_blocks_high_lookup[bsize],
-                                   tile_info->mi_row_end - mi_row);
-      const int bsl = mi_width_log2_lookup[bsize];
-      int cb_partition_search_ctrl = (((mi_row + mi_col) >> bsl)
-          + get_chessboard_index(cm->current_video_frame)) & 0x1;
-      MODE_INFO *ref_mi;
-      int const_motion = 1;
-      int skip_ref_frame = !cb_partition_search_ctrl;
-      MV_REFERENCE_FRAME rf = NONE;
-      int_mv ref_mv;
-      ref_mv.as_int = INVALID_MV;
-
-      if ((mi_row - 1) >= tile_info->mi_row_start) {
-        ref_mv = xd->mi[-xd->mi_stride]->mv[0];
-        rf = xd->mi[-xd->mi_stride]->ref_frame[0];
-        for (i = 0; i < mi_width; ++i) {
-          ref_mi = xd->mi[-xd->mi_stride + i];
-          const_motion &= (ref_mv.as_int == ref_mi->mv[0].as_int) &&
-                          (ref_frame == ref_mi->ref_frame[0]);
-          skip_ref_frame &= (rf == ref_mi->ref_frame[0]);
-        }
-      }
-
-      if ((mi_col - 1) >= tile_info->mi_col_start) {
-        if (ref_mv.as_int == INVALID_MV)
-          ref_mv = xd->mi[-1]->mv[0];
-        if (rf == NONE)
-          rf = xd->mi[-1]->ref_frame[0];
-        for (i = 0; i < mi_height; ++i) {
-          ref_mi = xd->mi[i * xd->mi_stride - 1];
-          const_motion &= (ref_mv.as_int == ref_mi->mv[0].as_int) &&
-                          (ref_frame == ref_mi->ref_frame[0]);
-          skip_ref_frame &= (rf == ref_mi->ref_frame[0]);
-        }
-      }
-
-      if (skip_ref_frame && this_mode != NEARESTMV && this_mode != NEWMV)
-        if (rf > INTRA_FRAME)
-          if (ref_frame != rf)
-            continue;
-
-      if (const_motion)
-        if (this_mode == NEARMV || this_mode == ZEROMV)
-          continue;
-    }
-
-    comp_pred = second_ref_frame > INTRA_FRAME;
-    if (comp_pred) {
-      if (!cpi->allow_comp_inter_inter)
-        continue;
-
-      // Skip compound inter modes if ARF is not available.
-      if (!(cpi->ref_frame_flags & flag_list[second_ref_frame]))
-        continue;
-
-      // Do not allow compound prediction if the segment level reference frame
-      // feature is in use as in this case there can only be one reference.
-      if (segfeature_active(seg, segment_id, SEG_LVL_REF_FRAME))
-        continue;
-
-      if ((mode_search_skip_flags & FLAG_SKIP_COMP_BESTINTRA) &&
-          best_mode_index >= 0 && best_mbmode.ref_frame[0] == INTRA_FRAME)
-        continue;
-
-      mode_excluded = cm->reference_mode == SINGLE_REFERENCE;
-    } else {
-      if (ref_frame != INTRA_FRAME)
-        mode_excluded = cm->reference_mode == COMPOUND_REFERENCE;
-    }
-
-    if (ref_frame == INTRA_FRAME) {
-      if (sf->adaptive_mode_search)
-        if ((x->source_variance << num_pels_log2_lookup[bsize]) > best_pred_sse)
-          continue;
-
-      if (this_mode != DC_PRED) {
-        // Disable intra modes other than DC_PRED for blocks with low variance
-        // Threshold for intra skipping based on source variance
-        // TODO(debargha): Specialize the threshold for super block sizes
-        const unsigned int skip_intra_var_thresh = 64;
-        if ((mode_search_skip_flags & FLAG_SKIP_INTRA_LOWVAR) &&
-            x->source_variance < skip_intra_var_thresh)
-          continue;
-        // Only search the oblique modes if the best so far is
-        // one of the neighboring directional modes
-        if ((mode_search_skip_flags & FLAG_SKIP_INTRA_BESTINTER) &&
-            (this_mode >= D45_PRED && this_mode <= TM_PRED)) {
-          if (best_mode_index >= 0 &&
-              best_mbmode.ref_frame[0] > INTRA_FRAME)
-            continue;
-        }
-        if (mode_search_skip_flags & FLAG_SKIP_INTRA_DIRMISMATCH) {
-          if (conditional_skipintra(this_mode, best_intra_mode))
-              continue;
-        }
-      }
-    } else {
-      const MV_REFERENCE_FRAME ref_frames[2] = {ref_frame, second_ref_frame};
-      if (!check_best_zero_mv(cpi, mbmi_ext->mode_context, frame_mv,
-                              this_mode, ref_frames))
-        continue;
-    }
-
-    mi->mode = this_mode;
-    mi->uv_mode = DC_PRED;
-    mi->ref_frame[0] = ref_frame;
-    mi->ref_frame[1] = second_ref_frame;
-    // Evaluate all sub-pel filters irrespective of whether we can use
-    // them for this frame.
-    mi->interp_filter = cm->interp_filter == SWITCHABLE ? EIGHTTAP
-                                                          : cm->interp_filter;
-    mi->mv[0].as_int = mi->mv[1].as_int = 0;
-
-    x->skip = 0;
-    set_ref_ptrs(cm, xd, ref_frame, second_ref_frame);
-
-    // Select prediction reference frames.
-    for (i = 0; i < MAX_MB_PLANE; i++) {
-      xd->plane[i].pre[0] = yv12_mb[ref_frame][i];
-      if (comp_pred)
-        xd->plane[i].pre[1] = yv12_mb[second_ref_frame][i];
-    }
-
-    if (ref_frame == INTRA_FRAME) {
-      TX_SIZE uv_tx;
-      struct macroblockd_plane *const pd = &xd->plane[1];
-      memset(x->skip_txfm, 0, sizeof(x->skip_txfm));
-      super_block_yrd(cpi, x, &rate_y, &distortion_y, &skippable,
-                      NULL, bsize, best_rd);
-      if (rate_y == INT_MAX)
-        continue;
-
-      uv_tx = get_uv_tx_size_impl(mi->tx_size, bsize, pd->subsampling_x,
-                                  pd->subsampling_y);
-      if (rate_uv_intra[uv_tx] == INT_MAX) {
-        choose_intra_uv_mode(cpi, x, ctx, bsize, uv_tx,
-                             &rate_uv_intra[uv_tx], &rate_uv_tokenonly[uv_tx],
-                             &dist_uv[uv_tx], &skip_uv[uv_tx], &mode_uv[uv_tx]);
-      }
-
-      rate_uv = rate_uv_tokenonly[uv_tx];
-      distortion_uv = dist_uv[uv_tx];
-      skippable = skippable && skip_uv[uv_tx];
-      mi->uv_mode = mode_uv[uv_tx];
-
-      rate2 = rate_y + cpi->mbmode_cost[mi->mode] + rate_uv_intra[uv_tx];
-      if (this_mode != DC_PRED && this_mode != TM_PRED)
-        rate2 += intra_cost_penalty;
-      distortion2 = distortion_y + distortion_uv;
-    } else {
-      this_rd = handle_inter_mode(cpi, x, bsize,
-                                  &rate2, &distortion2, &skippable,
-                                  &rate_y, &rate_uv,
-                                  &disable_skip, frame_mv,
-                                  mi_row, mi_col,
-                                  single_newmv, single_inter_filter,
-                                  single_skippable, &total_sse, best_rd,
-                                  &mask_filter, filter_cache);
-      if (this_rd == INT64_MAX)
-        continue;
-
-      compmode_cost = vp9_cost_bit(comp_mode_p, comp_pred);
-
-      if (cm->reference_mode == REFERENCE_MODE_SELECT)
-        rate2 += compmode_cost;
-    }
-
-    // Estimate the reference frame signaling cost and add it
-    // to the rolling cost variable.
-    if (comp_pred) {
-      rate2 += ref_costs_comp[ref_frame];
-    } else {
-      rate2 += ref_costs_single[ref_frame];
-    }
-
-    if (!disable_skip) {
-      const vpx_prob skip_prob = vp9_get_skip_prob(cm, xd);
-      const int skip_cost0 = vp9_cost_bit(skip_prob, 0);
-      const int skip_cost1 = vp9_cost_bit(skip_prob, 1);
-
-      if (skippable) {
-        // Back out the coefficient coding costs
-        rate2 -= (rate_y + rate_uv);
-
-        // Cost the skip mb case
-        rate2 += skip_cost1;
-      } else if (ref_frame != INTRA_FRAME && !xd->lossless) {
-        if (RDCOST(x->rdmult, x->rddiv,
-                   rate_y + rate_uv + skip_cost0, distortion2) <
-            RDCOST(x->rdmult, x->rddiv, skip_cost1, total_sse)) {
-          // Add in the cost of the no skip flag.
-          rate2 += skip_cost0;
-        } else {
-          // FIXME(rbultje) make this work for splitmv also
-          rate2 += skip_cost1;
-          distortion2 = total_sse;
-          assert(total_sse >= 0);
-          rate2 -= (rate_y + rate_uv);
-          this_skip2 = 1;
-        }
-      } else {
-        // Add in the cost of the no skip flag.
-        rate2 += skip_cost0;
-      }
-
-      // Calculate the final RD estimate for this mode.
-      this_rd = RDCOST(x->rdmult, x->rddiv, rate2, distortion2);
-    }
-
-    // Apply an adjustment to the rd value based on the similarity of the
-    // source variance and reconstructed variance.
-    rd_variance_adjustment(cpi, x, bsize, &this_rd,
-                           ref_frame, x->source_variance);
-
-    if (ref_frame == INTRA_FRAME) {
-    // Keep record of best intra rd
-      if (this_rd < best_intra_rd) {
-        best_intra_rd = this_rd;
-        best_intra_mode = mi->mode;
-      }
-    }
-
-    if (!disable_skip && ref_frame == INTRA_FRAME) {
-      for (i = 0; i < REFERENCE_MODES; ++i)
-        best_pred_rd[i] = VPXMIN(best_pred_rd[i], this_rd);
-      for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++)
-        best_filter_rd[i] = VPXMIN(best_filter_rd[i], this_rd);
-    }
-
-    // Did this mode help.. i.e. is it the new best mode
-    if (this_rd < best_rd || x->skip) {
-      int max_plane = MAX_MB_PLANE;
-      if (!mode_excluded) {
-        // Note index of best mode so far
-        best_mode_index = mode_index;
-
-        if (ref_frame == INTRA_FRAME) {
-          /* required for left and above block mv */
-          mi->mv[0].as_int = 0;
-          max_plane = 1;
-        } else {
-          best_pred_sse = x->pred_sse[ref_frame];
-        }
-
-        rd_cost->rate = rate2;
-        rd_cost->dist = distortion2;
-        rd_cost->rdcost = this_rd;
-        best_rd = this_rd;
-        best_mbmode = *mi;
-        best_skip2 = this_skip2;
-        best_mode_skippable = skippable;
-
-        if (!x->select_tx_size)
-          swap_block_ptr(x, ctx, 1, 0, 0, max_plane);
-        memcpy(ctx->zcoeff_blk, x->zcoeff_blk[mi->tx_size],
-               sizeof(ctx->zcoeff_blk[0]) * ctx->num_4x4_blk);
-
-        // TODO(debargha): enhance this test with a better distortion prediction
-        // based on qp, activity mask and history
-        if ((mode_search_skip_flags & FLAG_EARLY_TERMINATE) &&
-            (mode_index > MIN_EARLY_TERM_INDEX)) {
-          int qstep = xd->plane[0].dequant[1];
-          // TODO(debargha): Enhance this by specializing for each mode_index
-          int scale = 4;
-#if CONFIG_VP9_HIGHBITDEPTH
-          if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
-            qstep >>= (xd->bd - 8);
-          }
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-          if (x->source_variance < UINT_MAX) {
-            const int var_adjust = (x->source_variance < 16);
-            scale -= var_adjust;
-          }
-          if (ref_frame > INTRA_FRAME &&
-              distortion2 * scale < qstep * qstep) {
-            early_term = 1;
-          }
-        }
-      }
-    }
-
-    /* keep record of best compound/single-only prediction */
-    if (!disable_skip && ref_frame != INTRA_FRAME) {
-      int64_t single_rd, hybrid_rd, single_rate, hybrid_rate;
-
-      if (cm->reference_mode == REFERENCE_MODE_SELECT) {
-        single_rate = rate2 - compmode_cost;
-        hybrid_rate = rate2;
-      } else {
-        single_rate = rate2;
-        hybrid_rate = rate2 + compmode_cost;
-      }
-
-      single_rd = RDCOST(x->rdmult, x->rddiv, single_rate, distortion2);
-      hybrid_rd = RDCOST(x->rdmult, x->rddiv, hybrid_rate, distortion2);
-
-      if (!comp_pred) {
-        if (single_rd < best_pred_rd[SINGLE_REFERENCE])
-          best_pred_rd[SINGLE_REFERENCE] = single_rd;
-      } else {
-        if (single_rd < best_pred_rd[COMPOUND_REFERENCE])
-          best_pred_rd[COMPOUND_REFERENCE] = single_rd;
-      }
-      if (hybrid_rd < best_pred_rd[REFERENCE_MODE_SELECT])
-        best_pred_rd[REFERENCE_MODE_SELECT] = hybrid_rd;
-
-      /* keep record of best filter type */
-      if (!mode_excluded && cm->interp_filter != BILINEAR) {
-        int64_t ref = filter_cache[cm->interp_filter == SWITCHABLE ?
-                              SWITCHABLE_FILTERS : cm->interp_filter];
-
-        for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++) {
-          int64_t adj_rd;
-          if (ref == INT64_MAX)
-            adj_rd = 0;
-          else if (filter_cache[i] == INT64_MAX)
-            // when early termination is triggered, the encoder does not have
-            // access to the rate-distortion cost. it only knows that the cost
-            // should be above the maximum valid value. hence it takes the known
-            // maximum plus an arbitrary constant as the rate-distortion cost.
-            adj_rd = mask_filter - ref + 10;
-          else
-            adj_rd = filter_cache[i] - ref;
-
-          adj_rd += this_rd;
-          best_filter_rd[i] = VPXMIN(best_filter_rd[i], adj_rd);
-        }
-      }
-    }
-
-    if (early_term)
-      break;
-
-    if (x->skip && !comp_pred)
-      break;
-  }
-
-  // The inter modes' rate costs are not calculated precisely in some cases.
-  // Therefore, sometimes, NEWMV is chosen instead of NEARESTMV, NEARMV, and
-  // ZEROMV. Here, checks are added for those cases, and the mode decisions
-  // are corrected.
-  if (best_mbmode.mode == NEWMV) {
-    const MV_REFERENCE_FRAME refs[2] = {best_mbmode.ref_frame[0],
-        best_mbmode.ref_frame[1]};
-    int comp_pred_mode = refs[1] > INTRA_FRAME;
-
-    if (frame_mv[NEARESTMV][refs[0]].as_int == best_mbmode.mv[0].as_int &&
-        ((comp_pred_mode && frame_mv[NEARESTMV][refs[1]].as_int ==
-            best_mbmode.mv[1].as_int) || !comp_pred_mode))
-      best_mbmode.mode = NEARESTMV;
-    else if (frame_mv[NEARMV][refs[0]].as_int == best_mbmode.mv[0].as_int &&
-        ((comp_pred_mode && frame_mv[NEARMV][refs[1]].as_int ==
-            best_mbmode.mv[1].as_int) || !comp_pred_mode))
-      best_mbmode.mode = NEARMV;
-    else if (best_mbmode.mv[0].as_int == 0 &&
-        ((comp_pred_mode && best_mbmode.mv[1].as_int == 0) || !comp_pred_mode))
-      best_mbmode.mode = ZEROMV;
-  }
-
-  if (best_mode_index < 0 || best_rd >= best_rd_so_far) {
-    rd_cost->rate = INT_MAX;
-    rd_cost->rdcost = INT64_MAX;
-    return;
-  }
-
-  // If we used an estimate for the uv intra rd in the loop above...
-  if (sf->use_uv_intra_rd_estimate) {
-    // Do Intra UV best rd mode selection if best mode choice above was intra.
-    if (best_mbmode.ref_frame[0] == INTRA_FRAME) {
-      TX_SIZE uv_tx_size;
-      *mi = best_mbmode;
-      uv_tx_size = get_uv_tx_size(mi, &xd->plane[1]);
-      rd_pick_intra_sbuv_mode(cpi, x, ctx, &rate_uv_intra[uv_tx_size],
-                              &rate_uv_tokenonly[uv_tx_size],
-                              &dist_uv[uv_tx_size],
-                              &skip_uv[uv_tx_size],
-                              bsize < BLOCK_8X8 ? BLOCK_8X8 : bsize,
-                              uv_tx_size);
-    }
-  }
-
-  assert((cm->interp_filter == SWITCHABLE) ||
-         (cm->interp_filter == best_mbmode.interp_filter) ||
-         !is_inter_block(&best_mbmode));
-
-  if (!cpi->rc.is_src_frame_alt_ref)
-    vp9_update_rd_thresh_fact(tile_data->thresh_freq_fact,
-                              sf->adaptive_rd_thresh, bsize, best_mode_index);
-
-  // macroblock modes
-  *mi = best_mbmode;
-  x->skip |= best_skip2;
-
-  for (i = 0; i < REFERENCE_MODES; ++i) {
-    if (best_pred_rd[i] == INT64_MAX)
-      best_pred_diff[i] = INT_MIN;
-    else
-      best_pred_diff[i] = best_rd - best_pred_rd[i];
-  }
-
-  if (!x->skip) {
-    for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++) {
-      if (best_filter_rd[i] == INT64_MAX)
-        best_filter_diff[i] = 0;
-      else
-        best_filter_diff[i] = best_rd - best_filter_rd[i];
-    }
-    if (cm->interp_filter == SWITCHABLE)
-      assert(best_filter_diff[SWITCHABLE_FILTERS] == 0);
-  } else {
-    vp9_zero(best_filter_diff);
-  }
-
-  // TODO(yunqingwang): Moving this line in front of the above best_filter_diff
-  // updating code causes PSNR loss. Need to figure out the confliction.
-  x->skip |= best_mode_skippable;
-
-  if (!x->skip && !x->select_tx_size) {
-    int has_high_freq_coeff = 0;
-    int plane;
-    int max_plane = is_inter_block(xd->mi[0])
-                        ? MAX_MB_PLANE : 1;
-    for (plane = 0; plane < max_plane; ++plane) {
-      x->plane[plane].eobs = ctx->eobs_pbuf[plane][1];
-      has_high_freq_coeff |= vp9_has_high_freq_in_plane(x, bsize, plane);
-    }
-
-    for (plane = max_plane; plane < MAX_MB_PLANE; ++plane) {
-      x->plane[plane].eobs = ctx->eobs_pbuf[plane][2];
-      has_high_freq_coeff |= vp9_has_high_freq_in_plane(x, bsize, plane);
-    }
-
-    best_mode_skippable |= !has_high_freq_coeff;
-  }
-
-  assert(best_mode_index >= 0);
-
-  store_coding_context(x, ctx, best_mode_index, best_pred_diff,
-                       best_filter_diff, best_mode_skippable);
-}
-
-void vp9_rd_pick_inter_mode_sb_seg_skip(VP9_COMP *cpi,
-                                        TileDataEnc *tile_data,
-                                        MACROBLOCK *x,
-                                        RD_COST *rd_cost,
-                                        BLOCK_SIZE bsize,
-                                        PICK_MODE_CONTEXT *ctx,
-                                        int64_t best_rd_so_far) {
-  VP9_COMMON *const cm = &cpi->common;
-  MACROBLOCKD *const xd = &x->e_mbd;
-  MODE_INFO *const mi = xd->mi[0];
-  unsigned char segment_id = mi->segment_id;
-  const int comp_pred = 0;
-  int i;
-  int64_t best_pred_diff[REFERENCE_MODES];
-  int64_t best_filter_diff[SWITCHABLE_FILTER_CONTEXTS];
-  unsigned int ref_costs_single[MAX_REF_FRAMES], ref_costs_comp[MAX_REF_FRAMES];
-  vpx_prob comp_mode_p;
-  INTERP_FILTER best_filter = SWITCHABLE;
-  int64_t this_rd = INT64_MAX;
-  int rate2 = 0;
-  const int64_t distortion2 = 0;
-
-  x->skip_encode = cpi->sf.skip_encode_frame && x->q_index < QIDX_SKIP_THRESH;
-
-  estimate_ref_frame_costs(cm, xd, segment_id, ref_costs_single, ref_costs_comp,
-                           &comp_mode_p);
-
-  for (i = 0; i < MAX_REF_FRAMES; ++i)
-    x->pred_sse[i] = INT_MAX;
-  for (i = LAST_FRAME; i < MAX_REF_FRAMES; ++i)
-    x->pred_mv_sad[i] = INT_MAX;
-
-  rd_cost->rate = INT_MAX;
-
-  assert(segfeature_active(&cm->seg, segment_id, SEG_LVL_SKIP));
-
-  mi->mode = ZEROMV;
-  mi->uv_mode = DC_PRED;
-  mi->ref_frame[0] = LAST_FRAME;
-  mi->ref_frame[1] = NONE;
-  mi->mv[0].as_int = 0;
-  x->skip = 1;
-
-  if (cm->interp_filter != BILINEAR) {
-    best_filter = EIGHTTAP;
-    if (cm->interp_filter == SWITCHABLE &&
-        x->source_variance >= cpi->sf.disable_filter_search_var_thresh) {
-      int rs;
-      int best_rs = INT_MAX;
-      for (i = 0; i < SWITCHABLE_FILTERS; ++i) {
-        mi->interp_filter = i;
-        rs = vp9_get_switchable_rate(cpi, xd);
-        if (rs < best_rs) {
-          best_rs = rs;
-          best_filter = mi->interp_filter;
-        }
-      }
-    }
-  }
-  // Set the appropriate filter
-  if (cm->interp_filter == SWITCHABLE) {
-    mi->interp_filter = best_filter;
-    rate2 += vp9_get_switchable_rate(cpi, xd);
-  } else {
-    mi->interp_filter = cm->interp_filter;
-  }
-
-  if (cm->reference_mode == REFERENCE_MODE_SELECT)
-    rate2 += vp9_cost_bit(comp_mode_p, comp_pred);
-
-  // Estimate the reference frame signaling cost and add it
-  // to the rolling cost variable.
-  rate2 += ref_costs_single[LAST_FRAME];
-  this_rd = RDCOST(x->rdmult, x->rddiv, rate2, distortion2);
-
-  rd_cost->rate = rate2;
-  rd_cost->dist = distortion2;
-  rd_cost->rdcost = this_rd;
-
-  if (this_rd >= best_rd_so_far) {
-    rd_cost->rate = INT_MAX;
-    rd_cost->rdcost = INT64_MAX;
-    return;
-  }
-
-  assert((cm->interp_filter == SWITCHABLE) ||
-         (cm->interp_filter == mi->interp_filter));
-
-  vp9_update_rd_thresh_fact(tile_data->thresh_freq_fact,
-                            cpi->sf.adaptive_rd_thresh, bsize, THR_ZEROMV);
-
-  vp9_zero(best_pred_diff);
-  vp9_zero(best_filter_diff);
-
-  if (!x->select_tx_size)
-    swap_block_ptr(x, ctx, 1, 0, 0, MAX_MB_PLANE);
-  store_coding_context(x, ctx, THR_ZEROMV,
-                       best_pred_diff, best_filter_diff, 0);
-}
-
-void vp9_rd_pick_inter_mode_sub8x8(VP9_COMP *cpi,
-                                   TileDataEnc *tile_data,
-                                   MACROBLOCK *x,
-                                   int mi_row, int mi_col,
-                                   RD_COST *rd_cost,
-                                   BLOCK_SIZE bsize,
-                                   PICK_MODE_CONTEXT *ctx,
-                                   int64_t best_rd_so_far) {
-  VP9_COMMON *const cm = &cpi->common;
-  RD_OPT *const rd_opt = &cpi->rd;
-  SPEED_FEATURES *const sf = &cpi->sf;
-  MACROBLOCKD *const xd = &x->e_mbd;
-  MODE_INFO *const mi = xd->mi[0];
-  const struct segmentation *const seg = &cm->seg;
-  MV_REFERENCE_FRAME ref_frame, second_ref_frame;
-  unsigned char segment_id = mi->segment_id;
-  int comp_pred, i;
-  int_mv frame_mv[MB_MODE_COUNT][MAX_REF_FRAMES];
-  struct buf_2d yv12_mb[4][MAX_MB_PLANE];
-  static const int flag_list[4] = { 0, VP9_LAST_FLAG, VP9_GOLD_FLAG,
-                                    VP9_ALT_FLAG };
-  int64_t best_rd = best_rd_so_far;
-  int64_t best_yrd = best_rd_so_far;  // FIXME(rbultje) more precise
-  int64_t best_pred_diff[REFERENCE_MODES];
-  int64_t best_pred_rd[REFERENCE_MODES];
-  int64_t best_filter_rd[SWITCHABLE_FILTER_CONTEXTS];
-  int64_t best_filter_diff[SWITCHABLE_FILTER_CONTEXTS];
-  MODE_INFO best_mbmode;
-  int ref_index, best_ref_index = 0;
-  unsigned int ref_costs_single[MAX_REF_FRAMES], ref_costs_comp[MAX_REF_FRAMES];
-  vpx_prob comp_mode_p;
-  INTERP_FILTER tmp_best_filter = SWITCHABLE;
-  int rate_uv_intra, rate_uv_tokenonly;
-  int64_t dist_uv;
-  int skip_uv;
-  PREDICTION_MODE mode_uv = DC_PRED;
-  const int intra_cost_penalty = vp9_get_intra_cost_penalty(
-    cm->base_qindex, cm->y_dc_delta_q, cm->bit_depth);
-  int_mv seg_mvs[4][MAX_REF_FRAMES];
-  b_mode_info best_bmodes[4];
-  int best_skip2 = 0;
-  int ref_frame_skip_mask[2] = { 0 };
-  int64_t mask_filter = 0;
-  int64_t filter_cache[SWITCHABLE_FILTER_CONTEXTS];
-  int internal_active_edge =
-    vp9_active_edge_sb(cpi, mi_row, mi_col) && vp9_internal_image_edge(cpi);
-
-  x->skip_encode = sf->skip_encode_frame && x->q_index < QIDX_SKIP_THRESH;
-  memset(x->zcoeff_blk[TX_4X4], 0, 4);
-  vp9_zero(best_mbmode);
-
-  for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; ++i)
-    filter_cache[i] = INT64_MAX;
-
-  for (i = 0; i < 4; i++) {
-    int j;
-    for (j = 0; j < MAX_REF_FRAMES; j++)
-      seg_mvs[i][j].as_int = INVALID_MV;
-  }
-
-  estimate_ref_frame_costs(cm, xd, segment_id, ref_costs_single, ref_costs_comp,
-                           &comp_mode_p);
-
-  for (i = 0; i < REFERENCE_MODES; ++i)
-    best_pred_rd[i] = INT64_MAX;
-  for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++)
-    best_filter_rd[i] = INT64_MAX;
-  rate_uv_intra = INT_MAX;
-
-  rd_cost->rate = INT_MAX;
-
-  for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ref_frame++) {
-    if (cpi->ref_frame_flags & flag_list[ref_frame]) {
-      setup_buffer_inter(cpi, x, ref_frame, bsize, mi_row, mi_col,
-                         frame_mv[NEARESTMV], frame_mv[NEARMV],
-                         yv12_mb);
-    } else {
-      ref_frame_skip_mask[0] |= (1 << ref_frame);
-      ref_frame_skip_mask[1] |= SECOND_REF_FRAME_MASK;
-    }
-    frame_mv[NEWMV][ref_frame].as_int = INVALID_MV;
-    frame_mv[ZEROMV][ref_frame].as_int = 0;
-  }
-
-  for (ref_index = 0; ref_index < MAX_REFS; ++ref_index) {
-    int mode_excluded = 0;
-    int64_t this_rd = INT64_MAX;
-    int disable_skip = 0;
-    int compmode_cost = 0;
-    int rate2 = 0, rate_y = 0, rate_uv = 0;
-    int64_t distortion2 = 0, distortion_y = 0, distortion_uv = 0;
-    int skippable = 0;
-    int i;
-    int this_skip2 = 0;
-    int64_t total_sse = INT_MAX;
-    int early_term = 0;
-    struct buf_2d backup_yv12[2][MAX_MB_PLANE];
-
-    ref_frame = vp9_ref_order[ref_index].ref_frame[0];
-    second_ref_frame = vp9_ref_order[ref_index].ref_frame[1];
-
-#if CONFIG_BETTER_HW_COMPATIBILITY
-    // forbid 8X4 and 4X8 partitions if any reference frame is scaled.
-    if (bsize == BLOCK_8X4 || bsize == BLOCK_4X8) {
-      int ref_scaled = vp9_is_scaled(&cm->frame_refs[ref_frame - 1].sf);
-      if (second_ref_frame > INTRA_FRAME)
-        ref_scaled += vp9_is_scaled(&cm->frame_refs[second_ref_frame - 1].sf);
-      if (ref_scaled)
-        continue;
-    }
-#endif
-    // Look at the reference frame of the best mode so far and set the
-    // skip mask to look at a subset of the remaining modes.
-    if (ref_index > 2 && sf->mode_skip_start < MAX_MODES) {
-      if (ref_index == 3) {
-        switch (best_mbmode.ref_frame[0]) {
-          case INTRA_FRAME:
-            break;
-          case LAST_FRAME:
-            ref_frame_skip_mask[0] |= (1 << GOLDEN_FRAME) | (1 << ALTREF_FRAME);
-            ref_frame_skip_mask[1] |= SECOND_REF_FRAME_MASK;
-            break;
-          case GOLDEN_FRAME:
-            ref_frame_skip_mask[0] |= (1 << LAST_FRAME) | (1 << ALTREF_FRAME);
-            ref_frame_skip_mask[1] |= SECOND_REF_FRAME_MASK;
-            break;
-          case ALTREF_FRAME:
-            ref_frame_skip_mask[0] |= (1 << GOLDEN_FRAME) | (1 << LAST_FRAME);
-            break;
-          case NONE:
-          case MAX_REF_FRAMES:
-            assert(0 && "Invalid Reference frame");
-            break;
-        }
-      }
-    }
-
-    if ((ref_frame_skip_mask[0] & (1 << ref_frame)) &&
-        (ref_frame_skip_mask[1] & (1 << VPXMAX(0, second_ref_frame))))
-      continue;
-
-    // Test best rd so far against threshold for trying this mode.
-    if (!internal_active_edge &&
-        rd_less_than_thresh(best_rd,
-                            rd_opt->threshes[segment_id][bsize][ref_index],
-                            tile_data->thresh_freq_fact[bsize][ref_index]))
-      continue;
-
-    comp_pred = second_ref_frame > INTRA_FRAME;
-    if (comp_pred) {
-      if (!cpi->allow_comp_inter_inter)
-        continue;
-      if (!(cpi->ref_frame_flags & flag_list[second_ref_frame]))
-        continue;
-      // Do not allow compound prediction if the segment level reference frame
-      // feature is in use as in this case there can only be one reference.
-      if (segfeature_active(seg, segment_id, SEG_LVL_REF_FRAME))
-        continue;
-
-      if ((sf->mode_search_skip_flags & FLAG_SKIP_COMP_BESTINTRA) &&
-          best_mbmode.ref_frame[0] == INTRA_FRAME)
-        continue;
-    }
-
-    if (comp_pred)
-      mode_excluded = cm->reference_mode == SINGLE_REFERENCE;
-    else if (ref_frame != INTRA_FRAME)
-      mode_excluded = cm->reference_mode == COMPOUND_REFERENCE;
-
-    // If the segment reference frame feature is enabled....
-    // then do nothing if the current ref frame is not allowed..
-    if (segfeature_active(seg, segment_id, SEG_LVL_REF_FRAME) &&
-        get_segdata(seg, segment_id, SEG_LVL_REF_FRAME) != (int)ref_frame) {
-      continue;
-    // Disable this drop out case if the ref frame
-    // segment level feature is enabled for this segment. This is to
-    // prevent the possibility that we end up unable to pick any mode.
-    } else if (!segfeature_active(seg, segment_id, SEG_LVL_REF_FRAME)) {
-      // Only consider ZEROMV/ALTREF_FRAME for alt ref frame,
-      // unless ARNR filtering is enabled in which case we want
-      // an unfiltered alternative. We allow near/nearest as well
-      // because they may result in zero-zero MVs but be cheaper.
-      if (cpi->rc.is_src_frame_alt_ref && (cpi->oxcf.arnr_max_frames == 0))
-        continue;
-    }
-
-    mi->tx_size = TX_4X4;
-    mi->uv_mode = DC_PRED;
-    mi->ref_frame[0] = ref_frame;
-    mi->ref_frame[1] = second_ref_frame;
-    // Evaluate all sub-pel filters irrespective of whether we can use
-    // them for this frame.
-    mi->interp_filter = cm->interp_filter == SWITCHABLE ? EIGHTTAP
-                                                        : cm->interp_filter;
-    x->skip = 0;
-    set_ref_ptrs(cm, xd, ref_frame, second_ref_frame);
-
-    // Select prediction reference frames.
-    for (i = 0; i < MAX_MB_PLANE; i++) {
-      xd->plane[i].pre[0] = yv12_mb[ref_frame][i];
-      if (comp_pred)
-        xd->plane[i].pre[1] = yv12_mb[second_ref_frame][i];
-    }
-
-    if (ref_frame == INTRA_FRAME) {
-      int rate;
-      if (rd_pick_intra_sub_8x8_y_mode(cpi, x, &rate, &rate_y,
-                                       &distortion_y, best_rd) >= best_rd)
-        continue;
-      rate2 += rate;
-      rate2 += intra_cost_penalty;
-      distortion2 += distortion_y;
-
-      if (rate_uv_intra == INT_MAX) {
-        choose_intra_uv_mode(cpi, x, ctx, bsize, TX_4X4,
-                             &rate_uv_intra,
-                             &rate_uv_tokenonly,
-                             &dist_uv, &skip_uv,
-                             &mode_uv);
-      }
-      rate2 += rate_uv_intra;
-      rate_uv = rate_uv_tokenonly;
-      distortion2 += dist_uv;
-      distortion_uv = dist_uv;
-      mi->uv_mode = mode_uv;
-    } else {
-      int rate;
-      int64_t distortion;
-      int64_t this_rd_thresh;
-      int64_t tmp_rd, tmp_best_rd = INT64_MAX, tmp_best_rdu = INT64_MAX;
-      int tmp_best_rate = INT_MAX, tmp_best_ratey = INT_MAX;
-      int64_t tmp_best_distortion = INT_MAX, tmp_best_sse, uv_sse;
-      int tmp_best_skippable = 0;
-      int switchable_filter_index;
-      int_mv *second_ref = comp_pred ?
-                             &x->mbmi_ext->ref_mvs[second_ref_frame][0] : NULL;
-      b_mode_info tmp_best_bmodes[16];
-      MODE_INFO tmp_best_mbmode;
-      BEST_SEG_INFO bsi[SWITCHABLE_FILTERS];
-      int pred_exists = 0;
-      int uv_skippable;
-
-      YV12_BUFFER_CONFIG *scaled_ref_frame[2] = {NULL, NULL};
-      int ref;
-
-      for (ref = 0; ref < 2; ++ref) {
-        scaled_ref_frame[ref] = mi->ref_frame[ref] > INTRA_FRAME ?
-            vp9_get_scaled_ref_frame(cpi, mi->ref_frame[ref]) : NULL;
-
-        if (scaled_ref_frame[ref]) {
-          int i;
-          // Swap out the reference frame for a version that's been scaled to
-          // match the resolution of the current frame, allowing the existing
-          // motion search code to be used without additional modifications.
-          for (i = 0; i < MAX_MB_PLANE; i++)
-            backup_yv12[ref][i] = xd->plane[i].pre[ref];
-          vp9_setup_pre_planes(xd, ref, scaled_ref_frame[ref], mi_row, mi_col,
-                               NULL);
-        }
-      }
-
-      this_rd_thresh = (ref_frame == LAST_FRAME) ?
-          rd_opt->threshes[segment_id][bsize][THR_LAST] :
-          rd_opt->threshes[segment_id][bsize][THR_ALTR];
-      this_rd_thresh = (ref_frame == GOLDEN_FRAME) ?
-      rd_opt->threshes[segment_id][bsize][THR_GOLD] : this_rd_thresh;
-      for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; ++i)
-        filter_cache[i] = INT64_MAX;
-
-      if (cm->interp_filter != BILINEAR) {
-        tmp_best_filter = EIGHTTAP;
-        if (x->source_variance < sf->disable_filter_search_var_thresh) {
-          tmp_best_filter = EIGHTTAP;
-        } else if (sf->adaptive_pred_interp_filter == 1 &&
-                   ctx->pred_interp_filter < SWITCHABLE) {
-          tmp_best_filter = ctx->pred_interp_filter;
-        } else if (sf->adaptive_pred_interp_filter == 2) {
-          tmp_best_filter = ctx->pred_interp_filter < SWITCHABLE ?
-                              ctx->pred_interp_filter : 0;
-        } else {
-          for (switchable_filter_index = 0;
-               switchable_filter_index < SWITCHABLE_FILTERS;
-               ++switchable_filter_index) {
-            int newbest, rs;
-            int64_t rs_rd;
-            MB_MODE_INFO_EXT *mbmi_ext = x->mbmi_ext;
-            mi->interp_filter = switchable_filter_index;
-            tmp_rd = rd_pick_best_sub8x8_mode(cpi, x,
-                                              &mbmi_ext->ref_mvs[ref_frame][0],
-                                              second_ref, best_yrd, &rate,
-                                              &rate_y, &distortion,
-                                              &skippable, &total_sse,
-                                              (int) this_rd_thresh, seg_mvs,
-                                              bsi, switchable_filter_index,
-                                              mi_row, mi_col);
-
-            if (tmp_rd == INT64_MAX)
-              continue;
-            rs = vp9_get_switchable_rate(cpi, xd);
-            rs_rd = RDCOST(x->rdmult, x->rddiv, rs, 0);
-            filter_cache[switchable_filter_index] = tmp_rd;
-            filter_cache[SWITCHABLE_FILTERS] =
-                VPXMIN(filter_cache[SWITCHABLE_FILTERS], tmp_rd + rs_rd);
-            if (cm->interp_filter == SWITCHABLE)
-              tmp_rd += rs_rd;
-
-            mask_filter = VPXMAX(mask_filter, tmp_rd);
-
-            newbest = (tmp_rd < tmp_best_rd);
-            if (newbest) {
-              tmp_best_filter = mi->interp_filter;
-              tmp_best_rd = tmp_rd;
-            }
-            if ((newbest && cm->interp_filter == SWITCHABLE) ||
-                (mi->interp_filter == cm->interp_filter &&
-                 cm->interp_filter != SWITCHABLE)) {
-              tmp_best_rdu = tmp_rd;
-              tmp_best_rate = rate;
-              tmp_best_ratey = rate_y;
-              tmp_best_distortion = distortion;
-              tmp_best_sse = total_sse;
-              tmp_best_skippable = skippable;
-              tmp_best_mbmode = *mi;
-              for (i = 0; i < 4; i++) {
-                tmp_best_bmodes[i] = xd->mi[0]->bmi[i];
-                x->zcoeff_blk[TX_4X4][i] = !x->plane[0].eobs[i];
-              }
-              pred_exists = 1;
-              if (switchable_filter_index == 0 &&
-                  sf->use_rd_breakout &&
-                  best_rd < INT64_MAX) {
-                if (tmp_best_rdu / 2 > best_rd) {
-                  // skip searching the other filters if the first is
-                  // already substantially larger than the best so far
-                  tmp_best_filter = mi->interp_filter;
-                  tmp_best_rdu = INT64_MAX;
-                  break;
-                }
-              }
-            }
-          }  // switchable_filter_index loop
-        }
-      }
-
-      if (tmp_best_rdu == INT64_MAX && pred_exists)
-        continue;
-
-      mi->interp_filter = (cm->interp_filter == SWITCHABLE ?
-                           tmp_best_filter : cm->interp_filter);
-      if (!pred_exists) {
-        // Handles the special case when a filter that is not in the
-        // switchable list (bilinear, 6-tap) is indicated at the frame level
-        tmp_rd = rd_pick_best_sub8x8_mode(cpi, x,
-                                          &x->mbmi_ext->ref_mvs[ref_frame][0],
-                                          second_ref, best_yrd, &rate, &rate_y,
-                                          &distortion, &skippable, &total_sse,
-                                          (int) this_rd_thresh, seg_mvs, bsi, 0,
-                                          mi_row, mi_col);
-        if (tmp_rd == INT64_MAX)
-          continue;
-      } else {
-        total_sse = tmp_best_sse;
-        rate = tmp_best_rate;
-        rate_y = tmp_best_ratey;
-        distortion = tmp_best_distortion;
-        skippable = tmp_best_skippable;
-        *mi = tmp_best_mbmode;
-        for (i = 0; i < 4; i++)
-          xd->mi[0]->bmi[i] = tmp_best_bmodes[i];
-      }
-
-      rate2 += rate;
-      distortion2 += distortion;
-
-      if (cm->interp_filter == SWITCHABLE)
-        rate2 += vp9_get_switchable_rate(cpi, xd);
-
-      if (!mode_excluded)
-        mode_excluded = comp_pred ? cm->reference_mode == SINGLE_REFERENCE
-                                  : cm->reference_mode == COMPOUND_REFERENCE;
-
-      compmode_cost = vp9_cost_bit(comp_mode_p, comp_pred);
-
-      tmp_best_rdu =
-          best_rd - VPXMIN(RDCOST(x->rdmult, x->rddiv, rate2, distortion2),
-                           RDCOST(x->rdmult, x->rddiv, 0, total_sse));
-
-      if (tmp_best_rdu > 0) {
-        // If even the 'Y' rd value of split is higher than best so far
-        // then dont bother looking at UV
-        vp9_build_inter_predictors_sbuv(&x->e_mbd, mi_row, mi_col,
-                                        BLOCK_8X8);
-        memset(x->skip_txfm, SKIP_TXFM_NONE, sizeof(x->skip_txfm));
-        if (!super_block_uvrd(cpi, x, &rate_uv, &distortion_uv, &uv_skippable,
-                              &uv_sse, BLOCK_8X8, tmp_best_rdu)) {
-          for (ref = 0; ref < 2; ++ref) {
-            if (scaled_ref_frame[ref]) {
-              int i;
-              for (i = 0; i < MAX_MB_PLANE; ++i)
-                xd->plane[i].pre[ref] = backup_yv12[ref][i];
-            }
-          }
-          continue;
-        }
-
-        rate2 += rate_uv;
-        distortion2 += distortion_uv;
-        skippable = skippable && uv_skippable;
-        total_sse += uv_sse;
-      }
-
-      for (ref = 0; ref < 2; ++ref) {
-        if (scaled_ref_frame[ref]) {
-          // Restore the prediction frame pointers to their unscaled versions.
-          int i;
-          for (i = 0; i < MAX_MB_PLANE; ++i)
-            xd->plane[i].pre[ref] = backup_yv12[ref][i];
-        }
-      }
-    }
-
-    if (cm->reference_mode == REFERENCE_MODE_SELECT)
-      rate2 += compmode_cost;
-
-    // Estimate the reference frame signaling cost and add it
-    // to the rolling cost variable.
-    if (second_ref_frame > INTRA_FRAME) {
-      rate2 += ref_costs_comp[ref_frame];
-    } else {
-      rate2 += ref_costs_single[ref_frame];
-    }
-
-    if (!disable_skip) {
-      const vpx_prob skip_prob = vp9_get_skip_prob(cm, xd);
-      const int skip_cost0 = vp9_cost_bit(skip_prob, 0);
-      const int skip_cost1 = vp9_cost_bit(skip_prob, 1);
-
-      // Skip is never coded at the segment level for sub8x8 blocks and instead
-      // always coded in the bitstream at the mode info level.
-      if (ref_frame != INTRA_FRAME && !xd->lossless) {
-        if (RDCOST(x->rdmult, x->rddiv,
-                   rate_y + rate_uv + skip_cost0, distortion2) <
-            RDCOST(x->rdmult, x->rddiv, skip_cost1, total_sse)) {
-          // Add in the cost of the no skip flag.
-          rate2 += skip_cost0;
-        } else {
-          // FIXME(rbultje) make this work for splitmv also
-          rate2 += skip_cost1;
-          distortion2 = total_sse;
-          assert(total_sse >= 0);
-          rate2 -= (rate_y + rate_uv);
-          rate_y = 0;
-          rate_uv = 0;
-          this_skip2 = 1;
-        }
-      } else {
-        // Add in the cost of the no skip flag.
-        rate2 += skip_cost0;
-      }
-
-      // Calculate the final RD estimate for this mode.
-      this_rd = RDCOST(x->rdmult, x->rddiv, rate2, distortion2);
-    }
-
-    if (!disable_skip && ref_frame == INTRA_FRAME) {
-      for (i = 0; i < REFERENCE_MODES; ++i)
-        best_pred_rd[i] = VPXMIN(best_pred_rd[i], this_rd);
-      for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++)
-        best_filter_rd[i] = VPXMIN(best_filter_rd[i], this_rd);
-    }
-
-    // Did this mode help.. i.e. is it the new best mode
-    if (this_rd < best_rd || x->skip) {
-      if (!mode_excluded) {
-        int max_plane = MAX_MB_PLANE;
-        // Note index of best mode so far
-        best_ref_index = ref_index;
-
-        if (ref_frame == INTRA_FRAME) {
-          /* required for left and above block mv */
-          mi->mv[0].as_int = 0;
-          max_plane = 1;
-        }
-
-        rd_cost->rate = rate2;
-        rd_cost->dist = distortion2;
-        rd_cost->rdcost = this_rd;
-        best_rd = this_rd;
-        best_yrd = best_rd -
-                   RDCOST(x->rdmult, x->rddiv, rate_uv, distortion_uv);
-        best_mbmode = *mi;
-        best_skip2 = this_skip2;
-        if (!x->select_tx_size)
-          swap_block_ptr(x, ctx, 1, 0, 0, max_plane);
-        memcpy(ctx->zcoeff_blk, x->zcoeff_blk[TX_4X4],
-               sizeof(ctx->zcoeff_blk[0]) * ctx->num_4x4_blk);
-
-        for (i = 0; i < 4; i++)
-          best_bmodes[i] = xd->mi[0]->bmi[i];
-
-        // TODO(debargha): enhance this test with a better distortion prediction
-        // based on qp, activity mask and history
-        if ((sf->mode_search_skip_flags & FLAG_EARLY_TERMINATE) &&
-            (ref_index > MIN_EARLY_TERM_INDEX)) {
-          int qstep = xd->plane[0].dequant[1];
-          // TODO(debargha): Enhance this by specializing for each mode_index
-          int scale = 4;
-#if CONFIG_VP9_HIGHBITDEPTH
-          if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
-            qstep >>= (xd->bd - 8);
-          }
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-          if (x->source_variance < UINT_MAX) {
-            const int var_adjust = (x->source_variance < 16);
-            scale -= var_adjust;
-          }
-          if (ref_frame > INTRA_FRAME &&
-              distortion2 * scale < qstep * qstep) {
-            early_term = 1;
-          }
-        }
-      }
-    }
-
-    /* keep record of best compound/single-only prediction */
-    if (!disable_skip && ref_frame != INTRA_FRAME) {
-      int64_t single_rd, hybrid_rd, single_rate, hybrid_rate;
-
-      if (cm->reference_mode == REFERENCE_MODE_SELECT) {
-        single_rate = rate2 - compmode_cost;
-        hybrid_rate = rate2;
-      } else {
-        single_rate = rate2;
-        hybrid_rate = rate2 + compmode_cost;
-      }
-
-      single_rd = RDCOST(x->rdmult, x->rddiv, single_rate, distortion2);
-      hybrid_rd = RDCOST(x->rdmult, x->rddiv, hybrid_rate, distortion2);
-
-      if (!comp_pred && single_rd < best_pred_rd[SINGLE_REFERENCE])
-        best_pred_rd[SINGLE_REFERENCE] = single_rd;
-      else if (comp_pred && single_rd < best_pred_rd[COMPOUND_REFERENCE])
-        best_pred_rd[COMPOUND_REFERENCE] = single_rd;
-
-      if (hybrid_rd < best_pred_rd[REFERENCE_MODE_SELECT])
-        best_pred_rd[REFERENCE_MODE_SELECT] = hybrid_rd;
-    }
-
-    /* keep record of best filter type */
-    if (!mode_excluded && !disable_skip && ref_frame != INTRA_FRAME &&
-        cm->interp_filter != BILINEAR) {
-      int64_t ref = filter_cache[cm->interp_filter == SWITCHABLE ?
-                              SWITCHABLE_FILTERS : cm->interp_filter];
-      int64_t adj_rd;
-      for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++) {
-        if (ref == INT64_MAX)
-          adj_rd = 0;
-        else if (filter_cache[i] == INT64_MAX)
-          // when early termination is triggered, the encoder does not have
-          // access to the rate-distortion cost. it only knows that the cost
-          // should be above the maximum valid value. hence it takes the known
-          // maximum plus an arbitrary constant as the rate-distortion cost.
-          adj_rd = mask_filter - ref + 10;
-        else
-          adj_rd = filter_cache[i] - ref;
-
-        adj_rd += this_rd;
-        best_filter_rd[i] = VPXMIN(best_filter_rd[i], adj_rd);
-      }
-    }
-
-    if (early_term)
-      break;
-
-    if (x->skip && !comp_pred)
-      break;
-  }
-
-  if (best_rd >= best_rd_so_far) {
-    rd_cost->rate = INT_MAX;
-    rd_cost->rdcost = INT64_MAX;
-    return;
-  }
-
-  // If we used an estimate for the uv intra rd in the loop above...
-  if (sf->use_uv_intra_rd_estimate) {
-    // Do Intra UV best rd mode selection if best mode choice above was intra.
-    if (best_mbmode.ref_frame[0] == INTRA_FRAME) {
-      *mi = best_mbmode;
-      rd_pick_intra_sbuv_mode(cpi, x, ctx, &rate_uv_intra,
-                              &rate_uv_tokenonly,
-                              &dist_uv,
-                              &skip_uv,
-                              BLOCK_8X8, TX_4X4);
-    }
-  }
-
-  if (best_rd == INT64_MAX) {
-    rd_cost->rate = INT_MAX;
-    rd_cost->dist = INT64_MAX;
-    rd_cost->rdcost = INT64_MAX;
-    return;
-  }
-
-  assert((cm->interp_filter == SWITCHABLE) ||
-         (cm->interp_filter == best_mbmode.interp_filter) ||
-         !is_inter_block(&best_mbmode));
-
-  vp9_update_rd_thresh_fact(tile_data->thresh_freq_fact,
-                            sf->adaptive_rd_thresh, bsize, best_ref_index);
-
-  // macroblock modes
-  *mi = best_mbmode;
-  x->skip |= best_skip2;
-  if (!is_inter_block(&best_mbmode)) {
-    for (i = 0; i < 4; i++)
-      xd->mi[0]->bmi[i].as_mode = best_bmodes[i].as_mode;
-  } else {
-    for (i = 0; i < 4; ++i)
-      memcpy(&xd->mi[0]->bmi[i], &best_bmodes[i], sizeof(b_mode_info));
-
-    mi->mv[0].as_int = xd->mi[0]->bmi[3].as_mv[0].as_int;
-    mi->mv[1].as_int = xd->mi[0]->bmi[3].as_mv[1].as_int;
-  }
-
-  for (i = 0; i < REFERENCE_MODES; ++i) {
-    if (best_pred_rd[i] == INT64_MAX)
-      best_pred_diff[i] = INT_MIN;
-    else
-      best_pred_diff[i] = best_rd - best_pred_rd[i];
-  }
-
-  if (!x->skip) {
-    for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++) {
-      if (best_filter_rd[i] == INT64_MAX)
-        best_filter_diff[i] = 0;
-      else
-        best_filter_diff[i] = best_rd - best_filter_rd[i];
-    }
-    if (cm->interp_filter == SWITCHABLE)
-      assert(best_filter_diff[SWITCHABLE_FILTERS] == 0);
-  } else {
-    vp9_zero(best_filter_diff);
-  }
-
-  store_coding_context(x, ctx, best_ref_index,
-                       best_pred_diff, best_filter_diff, 0);
-}
diff --git a/vp9/encoder/vp9_rdopt.h b/vp9/encoder/vp9_rdopt.h
deleted file mode 100644 (file)
index 253e4a0..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#ifndef VP9_ENCODER_VP9_RDOPT_H_
-#define VP9_ENCODER_VP9_RDOPT_H_
-
-#include "vp9/common/vp9_blockd.h"
-
-#include "vp9/encoder/vp9_block.h"
-#include "vp9/encoder/vp9_context_tree.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-struct TileInfo;
-struct VP9_COMP;
-struct macroblock;
-struct RD_COST;
-
-void vp9_rd_pick_intra_mode_sb(struct VP9_COMP *cpi, struct macroblock *x,
-                               struct RD_COST *rd_cost, BLOCK_SIZE bsize,
-                               PICK_MODE_CONTEXT *ctx, int64_t best_rd);
-
-void vp9_rd_pick_inter_mode_sb(struct VP9_COMP *cpi,
-                               struct TileDataEnc *tile_data,
-                               struct macroblock *x,
-                               int mi_row, int mi_col,
-                               struct RD_COST *rd_cost,
-                               BLOCK_SIZE bsize, PICK_MODE_CONTEXT *ctx,
-                               int64_t best_rd_so_far);
-
-void vp9_rd_pick_inter_mode_sb_seg_skip(struct VP9_COMP *cpi,
-                                        struct TileDataEnc *tile_data,
-                                        struct macroblock *x,
-                                        struct RD_COST *rd_cost,
-                                        BLOCK_SIZE bsize,
-                                        PICK_MODE_CONTEXT *ctx,
-                                        int64_t best_rd_so_far);
-
-int vp9_internal_image_edge(struct VP9_COMP *cpi);
-int vp9_active_h_edge(struct VP9_COMP *cpi, int mi_row, int mi_step);
-int vp9_active_v_edge(struct VP9_COMP *cpi, int mi_col, int mi_step);
-int vp9_active_edge_sb(struct VP9_COMP *cpi, int mi_row, int mi_col);
-
-void vp9_rd_pick_inter_mode_sub8x8(struct VP9_COMP *cpi,
-                                   struct TileDataEnc *tile_data,
-                                   struct macroblock *x,
-                                   int mi_row, int mi_col,
-                                   struct RD_COST *rd_cost,
-                                   BLOCK_SIZE bsize, PICK_MODE_CONTEXT *ctx,
-                                   int64_t best_rd_so_far);
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP9_ENCODER_VP9_RDOPT_H_
diff --git a/vp9/encoder/vp9_resize.c b/vp9/encoder/vp9_resize.c
deleted file mode 100644 (file)
index 307a112..0000000
+++ /dev/null
@@ -1,929 +0,0 @@
-/*
- *  Copyright (c) 2014 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.
- */
-
-#include <assert.h>
-#include <limits.h>
-#include <math.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "./vpx_config.h"
-#if CONFIG_VP9_HIGHBITDEPTH
-#include "vpx_dsp/vpx_dsp_common.h"
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-#include "vpx_ports/mem.h"
-#include "vp9/common/vp9_common.h"
-#include "vp9/encoder/vp9_resize.h"
-
-#define FILTER_BITS               7
-
-#define INTERP_TAPS               8
-#define SUBPEL_BITS               5
-#define SUBPEL_MASK               ((1 << SUBPEL_BITS) - 1)
-#define INTERP_PRECISION_BITS     32
-
-typedef int16_t interp_kernel[INTERP_TAPS];
-
-// Filters for interpolation (0.5-band) - note this also filters integer pels.
-static const interp_kernel filteredinterp_filters500[(1 << SUBPEL_BITS)] = {
-  {-3,  0, 35, 64, 35,  0, -3, 0},
-  {-3, -1, 34, 64, 36,  1, -3, 0},
-  {-3, -1, 32, 64, 38,  1, -3, 0},
-  {-2, -2, 31, 63, 39,  2, -3, 0},
-  {-2, -2, 29, 63, 41,  2, -3, 0},
-  {-2, -2, 28, 63, 42,  3, -4, 0},
-  {-2, -3, 27, 63, 43,  4, -4, 0},
-  {-2, -3, 25, 62, 45,  5, -4, 0},
-  {-2, -3, 24, 62, 46,  5, -4, 0},
-  {-2, -3, 23, 61, 47,  6, -4, 0},
-  {-2, -3, 21, 60, 49,  7, -4, 0},
-  {-1, -4, 20, 60, 50,  8, -4, -1},
-  {-1, -4, 19, 59, 51,  9, -4, -1},
-  {-1, -4, 17, 58, 52, 10, -4, 0},
-  {-1, -4, 16, 57, 53, 12, -4, -1},
-  {-1, -4, 15, 56, 54, 13, -4, -1},
-  {-1, -4, 14, 55, 55, 14, -4, -1},
-  {-1, -4, 13, 54, 56, 15, -4, -1},
-  {-1, -4, 12, 53, 57, 16, -4, -1},
-  {0, -4, 10, 52, 58, 17, -4, -1},
-  {-1, -4,  9, 51, 59, 19, -4, -1},
-  {-1, -4,  8, 50, 60, 20, -4, -1},
-  {0, -4,  7, 49, 60, 21, -3, -2},
-  {0, -4,  6, 47, 61, 23, -3, -2},
-  {0, -4,  5, 46, 62, 24, -3, -2},
-  {0, -4,  5, 45, 62, 25, -3, -2},
-  {0, -4,  4, 43, 63, 27, -3, -2},
-  {0, -4,  3, 42, 63, 28, -2, -2},
-  {0, -3,  2, 41, 63, 29, -2, -2},
-  {0, -3,  2, 39, 63, 31, -2, -2},
-  {0, -3,  1, 38, 64, 32, -1, -3},
-  {0, -3,  1, 36, 64, 34, -1, -3}
-};
-
-// Filters for interpolation (0.625-band) - note this also filters integer pels.
-static const interp_kernel filteredinterp_filters625[(1 << SUBPEL_BITS)] = {
-  {-1, -8, 33, 80, 33, -8, -1, 0},
-  {-1, -8, 30, 80, 35, -8, -1, 1},
-  {-1, -8, 28, 80, 37, -7, -2, 1},
-  {0, -8, 26, 79, 39, -7, -2, 1},
-  {0, -8, 24, 79, 41, -7, -2, 1},
-  {0, -8, 22, 78, 43, -6, -2, 1},
-  {0, -8, 20, 78, 45, -5, -3, 1},
-  {0, -8, 18, 77, 48, -5, -3, 1},
-  {0, -8, 16, 76, 50, -4, -3, 1},
-  {0, -8, 15, 75, 52, -3, -4, 1},
-  {0, -7, 13, 74, 54, -3, -4, 1},
-  {0, -7, 11, 73, 56, -2, -4, 1},
-  {0, -7, 10, 71, 58, -1, -4, 1},
-  {1, -7,  8, 70, 60,  0, -5, 1},
-  {1, -6,  6, 68, 62,  1, -5, 1},
-  {1, -6,  5, 67, 63,  2, -5, 1},
-  {1, -6,  4, 65, 65,  4, -6, 1},
-  {1, -5,  2, 63, 67,  5, -6, 1},
-  {1, -5,  1, 62, 68,  6, -6, 1},
-  {1, -5,  0, 60, 70,  8, -7, 1},
-  {1, -4, -1, 58, 71, 10, -7, 0},
-  {1, -4, -2, 56, 73, 11, -7, 0},
-  {1, -4, -3, 54, 74, 13, -7, 0},
-  {1, -4, -3, 52, 75, 15, -8, 0},
-  {1, -3, -4, 50, 76, 16, -8, 0},
-  {1, -3, -5, 48, 77, 18, -8, 0},
-  {1, -3, -5, 45, 78, 20, -8, 0},
-  {1, -2, -6, 43, 78, 22, -8, 0},
-  {1, -2, -7, 41, 79, 24, -8, 0},
-  {1, -2, -7, 39, 79, 26, -8, 0},
-  {1, -2, -7, 37, 80, 28, -8, -1},
-  {1, -1, -8, 35, 80, 30, -8, -1},
-};
-
-// Filters for interpolation (0.75-band) - note this also filters integer pels.
-static const interp_kernel filteredinterp_filters750[(1 << SUBPEL_BITS)] = {
-  {2, -11,  25,  96,  25, -11,   2, 0},
-  {2, -11,  22,  96,  28, -11,   2, 0},
-  {2, -10,  19,  95,  31, -11,   2, 0},
-  {2, -10,  17,  95,  34, -12,   2, 0},
-  {2,  -9,  14,  94,  37, -12,   2, 0},
-  {2,  -8,  12,  93,  40, -12,   1, 0},
-  {2,  -8,   9,  92,  43, -12,   1, 1},
-  {2,  -7,   7,  91,  46, -12,   1, 0},
-  {2,  -7,   5,  90,  49, -12,   1, 0},
-  {2,  -6,   3,  88,  52, -12,   0, 1},
-  {2,  -5,   1,  86,  55, -12,   0, 1},
-  {2,  -5,  -1,  84,  58, -11,   0, 1},
-  {2,  -4,  -2,  82,  61, -11,  -1, 1},
-  {2,  -4,  -4,  80,  64, -10,  -1, 1},
-  {1, -3, -5, 77, 67, -9, -1, 1},
-  {1, -3, -6, 75, 70, -8, -2, 1},
-  {1, -2, -7, 72, 72, -7, -2, 1},
-  {1, -2, -8, 70, 75, -6, -3, 1},
-  {1, -1, -9, 67, 77, -5, -3, 1},
-  {1,  -1, -10,  64,  80,  -4,  -4, 2},
-  {1,  -1, -11,  61,  82,  -2,  -4, 2},
-  {1,   0, -11,  58,  84,  -1,  -5, 2},
-  {1,   0, -12,  55,  86,   1,  -5, 2},
-  {1,   0, -12,  52,  88,   3,  -6, 2},
-  {0,   1, -12,  49,  90,   5,  -7, 2},
-  {0,   1, -12,  46,  91,   7,  -7, 2},
-  {1,   1, -12,  43,  92,   9,  -8, 2},
-  {0,   1, -12,  40,  93,  12,  -8, 2},
-  {0,   2, -12,  37,  94,  14,  -9, 2},
-  {0,   2, -12,  34,  95,  17, -10, 2},
-  {0,   2, -11,  31,  95,  19, -10, 2},
-  {0,   2, -11,  28,  96,  22, -11, 2}
-};
-
-// Filters for interpolation (0.875-band) - note this also filters integer pels.
-static const interp_kernel filteredinterp_filters875[(1 << SUBPEL_BITS)] = {
-  {3,  -8,  13, 112,  13,  -8,   3, 0},
-  {3,  -7,  10, 112,  17,  -9,   3, -1},
-  {2,  -6,   7, 111,  21,  -9,   3, -1},
-  {2,  -5,   4, 111,  24, -10,   3, -1},
-  {2,  -4,   1, 110,  28, -11,   3, -1},
-  {1,  -3,  -1, 108,  32, -12,   4, -1},
-  {1,  -2,  -3, 106,  36, -13,   4, -1},
-  {1,  -1,  -6, 105,  40, -14,   4, -1},
-  {1,  -1,  -7, 102,  44, -14,   4, -1},
-  {1,   0,  -9, 100,  48, -15,   4, -1},
-  {1,   1, -11,  97,  53, -16,   4, -1},
-  {0,   1, -12,  95,  57, -16,   4, -1},
-  {0,   2, -13,  91,  61, -16,   4, -1},
-  {0,   2, -14,  88,  65, -16,   4, -1},
-  {0,   3, -15,  84,  69, -17,   4, 0},
-  {0,   3, -16,  81,  73, -16,   3, 0},
-  {0,   3, -16,  77,  77, -16,   3, 0},
-  {0,   3, -16,  73,  81, -16,   3, 0},
-  {0,   4, -17,  69,  84, -15,   3, 0},
-  {-1,   4, -16,  65,  88, -14,   2, 0},
-  {-1,   4, -16,  61,  91, -13,   2, 0},
-  {-1,   4, -16,  57,  95, -12,   1, 0},
-  {-1,   4, -16,  53,  97, -11,   1, 1},
-  {-1,   4, -15,  48, 100,  -9,   0, 1},
-  {-1,   4, -14,  44, 102,  -7,  -1, 1},
-  {-1,   4, -14,  40, 105,  -6,  -1, 1},
-  {-1,   4, -13,  36, 106,  -3,  -2, 1},
-  {-1,   4, -12,  32, 108,  -1,  -3, 1},
-  {-1,   3, -11,  28, 110,   1,  -4, 2},
-  {-1,   3, -10,  24, 111,   4,  -5, 2},
-  {-1,   3,  -9,  21, 111,   7,  -6, 2},
-  {-1,   3,  -9,  17, 112,  10,  -7, 3}
-};
-
-// Filters for interpolation (full-band) - no filtering for integer pixels
-static const interp_kernel filteredinterp_filters1000[(1 << SUBPEL_BITS)] = {
-  {0,   0,   0, 128,   0,   0,   0, 0},
-  {0,   1,  -3, 128,   3,  -1,   0, 0},
-  {-1,   2,  -6, 127,   7,  -2,   1, 0},
-  {-1,   3,  -9, 126,  12,  -4,   1, 0},
-  {-1,   4, -12, 125,  16,  -5,   1, 0},
-  {-1,   4, -14, 123,  20,  -6,   2, 0},
-  {-1,   5, -15, 120,  25,  -8,   2, 0},
-  {-1,   5, -17, 118,  30,  -9,   3, -1},
-  {-1,   6, -18, 114,  35, -10,   3, -1},
-  {-1,   6, -19, 111,  41, -12,   3, -1},
-  {-1,   6, -20, 107,  46, -13,   4, -1},
-  {-1,   6, -21, 103,  52, -14,   4, -1},
-  {-1,   6, -21,  99,  57, -16,   5, -1},
-  {-1,   6, -21,  94,  63, -17,   5, -1},
-  {-1,   6, -20,  89,  68, -18,   5, -1},
-  {-1,   6, -20,  84,  73, -19,   6, -1},
-  {-1,   6, -20,  79,  79, -20,   6, -1},
-  {-1,   6, -19,  73,  84, -20,   6, -1},
-  {-1,   5, -18,  68,  89, -20,   6, -1},
-  {-1,   5, -17,  63,  94, -21,   6, -1},
-  {-1,   5, -16,  57,  99, -21,   6, -1},
-  {-1,   4, -14,  52, 103, -21,   6, -1},
-  {-1,   4, -13,  46, 107, -20,   6, -1},
-  {-1,   3, -12,  41, 111, -19,   6, -1},
-  {-1,   3, -10,  35, 114, -18,   6, -1},
-  {-1,   3,  -9,  30, 118, -17,   5, -1},
-  {0,   2,  -8,  25, 120, -15,   5, -1},
-  {0,   2,  -6,  20, 123, -14,   4, -1},
-  {0,   1,  -5,  16, 125, -12,   4, -1},
-  {0,   1,  -4,  12, 126,  -9,   3, -1},
-  {0,   1,  -2,   7, 127,  -6,   2, -1},
-  {0,   0,  -1,   3, 128,  -3,   1, 0}
-};
-
-// Filters for factor of 2 downsampling.
-static const int16_t vp9_down2_symeven_half_filter[] = {56, 12, -3, -1};
-static const int16_t vp9_down2_symodd_half_filter[] = {64, 35, 0, -3};
-
-static const interp_kernel *choose_interp_filter(int inlength, int outlength) {
-  int outlength16 = outlength * 16;
-  if (outlength16 >= inlength * 16)
-    return filteredinterp_filters1000;
-  else if (outlength16 >= inlength * 13)
-    return filteredinterp_filters875;
-  else if (outlength16 >= inlength * 11)
-    return filteredinterp_filters750;
-  else if (outlength16 >= inlength * 9)
-    return filteredinterp_filters625;
-  else
-    return filteredinterp_filters500;
-}
-
-static void interpolate(const uint8_t *const input, int inlength,
-                        uint8_t *output, int outlength) {
-  const int64_t delta = (((uint64_t)inlength << 32) + outlength / 2) /
-      outlength;
-  const int64_t offset = inlength > outlength ?
-      (((int64_t)(inlength - outlength) << 31) + outlength / 2) / outlength :
-      -(((int64_t)(outlength - inlength) << 31) + outlength / 2) / outlength;
-  uint8_t *optr = output;
-  int x, x1, x2, sum, k, int_pel, sub_pel;
-  int64_t y;
-
-  const interp_kernel *interp_filters =
-      choose_interp_filter(inlength, outlength);
-
-  x = 0;
-  y = offset;
-  while ((y >> INTERP_PRECISION_BITS) < (INTERP_TAPS / 2 - 1)) {
-    x++;
-    y += delta;
-  }
-  x1 = x;
-  x = outlength - 1;
-  y = delta * x + offset;
-  while ((y >> INTERP_PRECISION_BITS) +
-         (int64_t)(INTERP_TAPS / 2) >= inlength) {
-    x--;
-    y -= delta;
-  }
-  x2 = x;
-  if (x1 > x2) {
-    for (x = 0, y = offset; x < outlength; ++x, y += delta) {
-      const int16_t *filter;
-      int_pel = y >> INTERP_PRECISION_BITS;
-      sub_pel = (y >> (INTERP_PRECISION_BITS - SUBPEL_BITS)) & SUBPEL_MASK;
-      filter = interp_filters[sub_pel];
-      sum = 0;
-      for (k = 0; k < INTERP_TAPS; ++k) {
-        const int pk = int_pel - INTERP_TAPS / 2 + 1 + k;
-        sum += filter[k] * input[(pk < 0 ? 0 :
-                                  (pk >= inlength ? inlength - 1 : pk))];
-      }
-      *optr++ = clip_pixel(ROUND_POWER_OF_TWO(sum, FILTER_BITS));
-    }
-  } else {
-    // Initial part.
-    for (x = 0, y = offset; x < x1; ++x, y += delta) {
-      const int16_t *filter;
-      int_pel = y >> INTERP_PRECISION_BITS;
-      sub_pel = (y >> (INTERP_PRECISION_BITS - SUBPEL_BITS)) & SUBPEL_MASK;
-      filter = interp_filters[sub_pel];
-      sum = 0;
-      for (k = 0; k < INTERP_TAPS; ++k)
-        sum += filter[k] * input[(int_pel - INTERP_TAPS / 2 + 1 + k < 0 ?
-                                  0 :
-                                  int_pel - INTERP_TAPS / 2 + 1 + k)];
-      *optr++ = clip_pixel(ROUND_POWER_OF_TWO(sum, FILTER_BITS));
-    }
-    // Middle part.
-    for (; x <= x2; ++x, y += delta) {
-      const int16_t *filter;
-      int_pel = y >> INTERP_PRECISION_BITS;
-      sub_pel = (y >> (INTERP_PRECISION_BITS - SUBPEL_BITS)) & SUBPEL_MASK;
-      filter = interp_filters[sub_pel];
-      sum = 0;
-      for (k = 0; k < INTERP_TAPS; ++k)
-        sum += filter[k] * input[int_pel - INTERP_TAPS / 2 + 1 + k];
-      *optr++ = clip_pixel(ROUND_POWER_OF_TWO(sum, FILTER_BITS));
-    }
-    // End part.
-    for (; x < outlength; ++x, y += delta) {
-      const int16_t *filter;
-      int_pel = y >> INTERP_PRECISION_BITS;
-      sub_pel = (y >> (INTERP_PRECISION_BITS - SUBPEL_BITS)) & SUBPEL_MASK;
-      filter = interp_filters[sub_pel];
-      sum = 0;
-      for (k = 0; k < INTERP_TAPS; ++k)
-        sum += filter[k] * input[(int_pel - INTERP_TAPS / 2 + 1 + k >=
-                                  inlength ?  inlength - 1 :
-                                  int_pel - INTERP_TAPS / 2 + 1 + k)];
-      *optr++ = clip_pixel(ROUND_POWER_OF_TWO(sum, FILTER_BITS));
-    }
-  }
-}
-
-static void down2_symeven(const uint8_t *const input, int length,
-                          uint8_t *output) {
-  // Actual filter len = 2 * filter_len_half.
-  const int16_t *filter = vp9_down2_symeven_half_filter;
-  const int filter_len_half = sizeof(vp9_down2_symeven_half_filter) / 2;
-  int i, j;
-  uint8_t *optr = output;
-  int l1 = filter_len_half;
-  int l2 = (length - filter_len_half);
-  l1 += (l1 & 1);
-  l2 += (l2 & 1);
-  if (l1 > l2) {
-    // Short input length.
-    for (i = 0; i < length; i += 2) {
-      int sum = (1 << (FILTER_BITS - 1));
-      for (j = 0; j < filter_len_half; ++j) {
-        sum += (input[(i - j < 0 ? 0 : i - j)] +
-                input[(i + 1 + j >= length ? length - 1 : i + 1 + j)]) *
-            filter[j];
-      }
-      sum >>= FILTER_BITS;
-      *optr++ = clip_pixel(sum);
-    }
-  } else {
-    // Initial part.
-    for (i = 0; i < l1; i += 2) {
-      int sum = (1 << (FILTER_BITS - 1));
-      for (j = 0; j < filter_len_half; ++j) {
-        sum += (input[(i - j < 0 ? 0 : i - j)] + input[i + 1 + j]) * filter[j];
-      }
-      sum >>= FILTER_BITS;
-      *optr++ = clip_pixel(sum);
-    }
-    // Middle part.
-    for (; i < l2; i += 2) {
-      int sum = (1 << (FILTER_BITS - 1));
-      for (j = 0; j < filter_len_half; ++j) {
-        sum += (input[i - j] + input[i + 1 + j]) * filter[j];
-      }
-      sum >>= FILTER_BITS;
-      *optr++ = clip_pixel(sum);
-    }
-    // End part.
-    for (; i < length; i += 2) {
-      int sum = (1 << (FILTER_BITS - 1));
-      for (j = 0; j < filter_len_half; ++j) {
-        sum += (input[i - j] +
-                input[(i + 1 + j >= length ? length - 1 : i + 1 + j)]) *
-            filter[j];
-      }
-      sum >>= FILTER_BITS;
-      *optr++ = clip_pixel(sum);
-    }
-  }
-}
-
-static void down2_symodd(const uint8_t *const input, int length,
-                         uint8_t *output) {
-  // Actual filter len = 2 * filter_len_half - 1.
-  const int16_t *filter = vp9_down2_symodd_half_filter;
-  const int filter_len_half = sizeof(vp9_down2_symodd_half_filter) / 2;
-  int i, j;
-  uint8_t *optr = output;
-  int l1 = filter_len_half - 1;
-  int l2 = (length - filter_len_half + 1);
-  l1 += (l1 & 1);
-  l2 += (l2 & 1);
-  if (l1 > l2) {
-    // Short input length.
-    for (i = 0; i < length; i += 2) {
-      int sum = (1 << (FILTER_BITS - 1)) + input[i] * filter[0];
-      for (j = 1; j < filter_len_half; ++j) {
-        sum += (input[(i - j < 0 ? 0 : i - j)] +
-                input[(i + j >= length ? length - 1 : i + j)]) *
-            filter[j];
-      }
-      sum >>= FILTER_BITS;
-      *optr++ = clip_pixel(sum);
-    }
-  } else {
-    // Initial part.
-    for (i = 0; i < l1; i += 2) {
-      int sum = (1 << (FILTER_BITS - 1)) + input[i] * filter[0];
-      for (j = 1; j < filter_len_half; ++j) {
-        sum += (input[(i - j < 0 ? 0 : i - j)] + input[i + j]) * filter[j];
-      }
-      sum >>= FILTER_BITS;
-      *optr++ = clip_pixel(sum);
-    }
-    // Middle part.
-    for (; i < l2; i += 2) {
-      int sum = (1 << (FILTER_BITS - 1)) + input[i] * filter[0];
-      for (j = 1; j < filter_len_half; ++j) {
-        sum += (input[i - j] + input[i + j]) * filter[j];
-      }
-      sum >>= FILTER_BITS;
-      *optr++ = clip_pixel(sum);
-    }
-    // End part.
-    for (; i < length; i += 2) {
-      int sum = (1 << (FILTER_BITS - 1)) + input[i] * filter[0];
-      for (j = 1; j < filter_len_half; ++j) {
-        sum += (input[i - j] + input[(i + j >= length ? length - 1 : i + j)]) *
-            filter[j];
-      }
-      sum >>= FILTER_BITS;
-      *optr++ = clip_pixel(sum);
-    }
-  }
-}
-
-static int get_down2_length(int length, int steps) {
-  int s;
-  for (s = 0; s < steps; ++s)
-    length = (length + 1) >> 1;
-  return length;
-}
-
-static int get_down2_steps(int in_length, int out_length) {
-  int steps = 0;
-  int proj_in_length;
-  while ((proj_in_length = get_down2_length(in_length, 1)) >= out_length) {
-    ++steps;
-    in_length = proj_in_length;
-  }
-  return steps;
-}
-
-static void resize_multistep(const uint8_t *const input,
-                             int length,
-                             uint8_t *output,
-                             int olength,
-                             uint8_t *otmp) {
-  int steps;
-  if (length == olength) {
-    memcpy(output, input, sizeof(output[0]) * length);
-    return;
-  }
-  steps = get_down2_steps(length, olength);
-
-  if (steps > 0) {
-    int s;
-    uint8_t *out = NULL;
-    uint8_t *otmp2;
-    int filteredlength = length;
-
-    assert(otmp != NULL);
-    otmp2 = otmp + get_down2_length(length, 1);
-    for (s = 0; s < steps; ++s) {
-      const int proj_filteredlength = get_down2_length(filteredlength, 1);
-      const uint8_t *const in = (s == 0 ? input : out);
-      if (s == steps - 1 && proj_filteredlength == olength)
-        out = output;
-      else
-        out = (s & 1 ? otmp2 : otmp);
-      if (filteredlength & 1)
-        down2_symodd(in, filteredlength, out);
-      else
-        down2_symeven(in, filteredlength, out);
-      filteredlength = proj_filteredlength;
-    }
-    if (filteredlength != olength) {
-      interpolate(out, filteredlength, output, olength);
-    }
-  } else {
-    interpolate(input, length, output, olength);
-  }
-}
-
-static void fill_col_to_arr(uint8_t *img, int stride, int len, uint8_t *arr) {
-  int i;
-  uint8_t *iptr = img;
-  uint8_t *aptr = arr;
-  for (i = 0; i < len; ++i, iptr += stride) {
-    *aptr++ = *iptr;
-  }
-}
-
-static void fill_arr_to_col(uint8_t *img, int stride, int len, uint8_t *arr) {
-  int i;
-  uint8_t *iptr = img;
-  uint8_t *aptr = arr;
-  for (i = 0; i < len; ++i, iptr += stride) {
-    *iptr = *aptr++;
-  }
-}
-
-void vp9_resize_plane(const uint8_t *const input,
-                      int height,
-                      int width,
-                      int in_stride,
-                      uint8_t *output,
-                      int height2,
-                      int width2,
-                      int out_stride) {
-  int i;
-  uint8_t *intbuf = (uint8_t *)malloc(sizeof(uint8_t) * width2 * height);
-  uint8_t *tmpbuf = (uint8_t *)malloc(sizeof(uint8_t) *
-                                      (width < height ? height : width));
-  uint8_t *arrbuf = (uint8_t *)malloc(sizeof(uint8_t) * height);
-  uint8_t *arrbuf2 = (uint8_t *)malloc(sizeof(uint8_t) * height2);
-  if (intbuf == NULL || tmpbuf == NULL ||
-      arrbuf == NULL || arrbuf2 == NULL)
-    goto Error;
-  assert(width > 0);
-  assert(height > 0);
-  assert(width2 > 0);
-  assert(height2 > 0);
-  for (i = 0; i < height; ++i)
-    resize_multistep(input + in_stride * i, width,
-                     intbuf + width2 * i, width2, tmpbuf);
-  for (i = 0; i < width2; ++i) {
-    fill_col_to_arr(intbuf + i, width2, height, arrbuf);
-    resize_multistep(arrbuf, height, arrbuf2, height2, tmpbuf);
-    fill_arr_to_col(output + i, out_stride, height2, arrbuf2);
-  }
-
- Error:
-  free(intbuf);
-  free(tmpbuf);
-  free(arrbuf);
-  free(arrbuf2);
-}
-
-#if CONFIG_VP9_HIGHBITDEPTH
-static void highbd_interpolate(const uint16_t *const input, int inlength,
-                               uint16_t *output, int outlength, int bd) {
-  const int64_t delta =
-      (((uint64_t)inlength << 32) + outlength / 2) / outlength;
-  const int64_t offset = inlength > outlength ?
-      (((int64_t)(inlength - outlength) << 31) + outlength / 2) / outlength :
-      -(((int64_t)(outlength - inlength) << 31) + outlength / 2) / outlength;
-  uint16_t *optr = output;
-  int x, x1, x2, sum, k, int_pel, sub_pel;
-  int64_t y;
-
-  const interp_kernel *interp_filters =
-      choose_interp_filter(inlength, outlength);
-
-  x = 0;
-  y = offset;
-  while ((y >> INTERP_PRECISION_BITS) < (INTERP_TAPS / 2 - 1)) {
-    x++;
-    y += delta;
-  }
-  x1 = x;
-  x = outlength - 1;
-  y = delta * x + offset;
-  while ((y >> INTERP_PRECISION_BITS) +
-         (int64_t)(INTERP_TAPS / 2) >= inlength) {
-    x--;
-    y -= delta;
-  }
-  x2 = x;
-  if (x1 > x2) {
-    for (x = 0, y = offset; x < outlength; ++x, y += delta) {
-      const int16_t *filter;
-      int_pel = y >> INTERP_PRECISION_BITS;
-      sub_pel = (y >> (INTERP_PRECISION_BITS - SUBPEL_BITS)) & SUBPEL_MASK;
-      filter = interp_filters[sub_pel];
-      sum = 0;
-      for (k = 0; k < INTERP_TAPS; ++k) {
-        const int pk = int_pel - INTERP_TAPS / 2 + 1 + k;
-        sum += filter[k] *
-            input[(pk < 0 ? 0 : (pk >= inlength ? inlength - 1 : pk))];
-      }
-      *optr++ = clip_pixel_highbd(ROUND_POWER_OF_TWO(sum, FILTER_BITS), bd);
-    }
-  } else {
-    // Initial part.
-    for (x = 0, y = offset; x < x1; ++x, y += delta) {
-      const int16_t *filter;
-      int_pel = y >> INTERP_PRECISION_BITS;
-      sub_pel = (y >> (INTERP_PRECISION_BITS - SUBPEL_BITS)) & SUBPEL_MASK;
-      filter = interp_filters[sub_pel];
-      sum = 0;
-      for (k = 0; k < INTERP_TAPS; ++k)
-        sum += filter[k] *
-            input[(int_pel - INTERP_TAPS / 2 + 1 + k < 0 ?
-                   0 : int_pel - INTERP_TAPS / 2 + 1 + k)];
-      *optr++ = clip_pixel_highbd(ROUND_POWER_OF_TWO(sum, FILTER_BITS), bd);
-    }
-    // Middle part.
-    for (; x <= x2; ++x, y += delta) {
-      const int16_t *filter;
-      int_pel = y >> INTERP_PRECISION_BITS;
-      sub_pel = (y >> (INTERP_PRECISION_BITS - SUBPEL_BITS)) & SUBPEL_MASK;
-      filter = interp_filters[sub_pel];
-      sum = 0;
-      for (k = 0; k < INTERP_TAPS; ++k)
-        sum += filter[k] * input[int_pel - INTERP_TAPS / 2 + 1 + k];
-      *optr++ = clip_pixel_highbd(ROUND_POWER_OF_TWO(sum, FILTER_BITS), bd);
-    }
-    // End part.
-    for (; x < outlength; ++x, y += delta) {
-      const int16_t *filter;
-      int_pel = y >> INTERP_PRECISION_BITS;
-      sub_pel = (y >> (INTERP_PRECISION_BITS - SUBPEL_BITS)) & SUBPEL_MASK;
-      filter = interp_filters[sub_pel];
-      sum = 0;
-      for (k = 0; k < INTERP_TAPS; ++k)
-        sum += filter[k] * input[(int_pel - INTERP_TAPS / 2 + 1 + k >=
-                                  inlength ?  inlength - 1 :
-                                  int_pel - INTERP_TAPS / 2 + 1 + k)];
-      *optr++ = clip_pixel_highbd(ROUND_POWER_OF_TWO(sum, FILTER_BITS), bd);
-    }
-  }
-}
-
-static void highbd_down2_symeven(const uint16_t *const input, int length,
-                                 uint16_t *output, int bd) {
-  // Actual filter len = 2 * filter_len_half.
-  static const int16_t *filter = vp9_down2_symeven_half_filter;
-  const int filter_len_half = sizeof(vp9_down2_symeven_half_filter) / 2;
-  int i, j;
-  uint16_t *optr = output;
-  int l1 = filter_len_half;
-  int l2 = (length - filter_len_half);
-  l1 += (l1 & 1);
-  l2 += (l2 & 1);
-  if (l1 > l2) {
-    // Short input length.
-    for (i = 0; i < length; i += 2) {
-      int sum = (1 << (FILTER_BITS - 1));
-      for (j = 0; j < filter_len_half; ++j) {
-        sum += (input[(i - j < 0 ? 0 : i - j)] +
-                input[(i + 1 + j >= length ? length - 1 : i + 1 + j)]) *
-            filter[j];
-      }
-      sum >>= FILTER_BITS;
-      *optr++ = clip_pixel_highbd(sum, bd);
-    }
-  } else {
-    // Initial part.
-    for (i = 0; i < l1; i += 2) {
-      int sum = (1 << (FILTER_BITS - 1));
-      for (j = 0; j < filter_len_half; ++j) {
-        sum += (input[(i - j < 0 ? 0 : i - j)] + input[i + 1 + j]) * filter[j];
-      }
-      sum >>= FILTER_BITS;
-      *optr++ = clip_pixel_highbd(sum, bd);
-    }
-    // Middle part.
-    for (; i < l2; i += 2) {
-      int sum = (1 << (FILTER_BITS - 1));
-      for (j = 0; j < filter_len_half; ++j) {
-        sum += (input[i - j] + input[i + 1 + j]) * filter[j];
-      }
-      sum >>= FILTER_BITS;
-      *optr++ = clip_pixel_highbd(sum, bd);
-    }
-    // End part.
-    for (; i < length; i += 2) {
-      int sum = (1 << (FILTER_BITS - 1));
-      for (j = 0; j < filter_len_half; ++j) {
-        sum += (input[i - j] +
-                input[(i + 1 + j >= length ? length - 1 : i + 1 + j)]) *
-            filter[j];
-      }
-      sum >>= FILTER_BITS;
-      *optr++ = clip_pixel_highbd(sum, bd);
-    }
-  }
-}
-
-static void highbd_down2_symodd(const uint16_t *const input, int length,
-                              uint16_t *output, int bd) {
-  // Actual filter len = 2 * filter_len_half - 1.
-  static const int16_t *filter = vp9_down2_symodd_half_filter;
-  const int filter_len_half = sizeof(vp9_down2_symodd_half_filter) / 2;
-  int i, j;
-  uint16_t *optr = output;
-  int l1 = filter_len_half - 1;
-  int l2 = (length - filter_len_half + 1);
-  l1 += (l1 & 1);
-  l2 += (l2 & 1);
-  if (l1 > l2) {
-    // Short input length.
-    for (i = 0; i < length; i += 2) {
-      int sum = (1 << (FILTER_BITS - 1)) + input[i] * filter[0];
-      for (j = 1; j < filter_len_half; ++j) {
-        sum += (input[(i - j < 0 ? 0 : i - j)] +
-                input[(i + j >= length ? length - 1 : i + j)]) *
-            filter[j];
-      }
-      sum >>= FILTER_BITS;
-      *optr++ = clip_pixel_highbd(sum, bd);
-    }
-  } else {
-    // Initial part.
-    for (i = 0; i < l1; i += 2) {
-      int sum = (1 << (FILTER_BITS - 1)) + input[i] * filter[0];
-      for (j = 1; j < filter_len_half; ++j) {
-        sum += (input[(i - j < 0 ? 0 : i - j)] + input[i + j]) * filter[j];
-      }
-      sum >>= FILTER_BITS;
-      *optr++ = clip_pixel_highbd(sum, bd);
-    }
-    // Middle part.
-    for (; i < l2; i += 2) {
-      int sum = (1 << (FILTER_BITS - 1)) + input[i] * filter[0];
-      for (j = 1; j < filter_len_half; ++j) {
-        sum += (input[i - j] + input[i + j]) * filter[j];
-      }
-      sum >>= FILTER_BITS;
-      *optr++ = clip_pixel_highbd(sum, bd);
-    }
-    // End part.
-    for (; i < length; i += 2) {
-      int sum = (1 << (FILTER_BITS - 1)) + input[i] * filter[0];
-      for (j = 1; j < filter_len_half; ++j) {
-        sum += (input[i - j] + input[(i + j >= length ? length - 1 : i + j)]) *
-            filter[j];
-      }
-      sum >>= FILTER_BITS;
-      *optr++ = clip_pixel_highbd(sum, bd);
-    }
-  }
-}
-
-static void highbd_resize_multistep(const uint16_t *const input,
-                                    int length,
-                                    uint16_t *output,
-                                    int olength,
-                                    uint16_t *otmp,
-                                    int bd) {
-  int steps;
-  if (length == olength) {
-    memcpy(output, input, sizeof(output[0]) * length);
-    return;
-  }
-  steps = get_down2_steps(length, olength);
-
-  if (steps > 0) {
-    int s;
-    uint16_t *out = NULL;
-    uint16_t *otmp2;
-    int filteredlength = length;
-
-    assert(otmp != NULL);
-    otmp2 = otmp + get_down2_length(length, 1);
-    for (s = 0; s < steps; ++s) {
-      const int proj_filteredlength = get_down2_length(filteredlength, 1);
-      const uint16_t *const in = (s == 0 ? input : out);
-      if (s == steps - 1 && proj_filteredlength == olength)
-        out = output;
-      else
-        out = (s & 1 ? otmp2 : otmp);
-      if (filteredlength & 1)
-        highbd_down2_symodd(in, filteredlength, out, bd);
-      else
-        highbd_down2_symeven(in, filteredlength, out, bd);
-      filteredlength = proj_filteredlength;
-    }
-    if (filteredlength != olength) {
-      highbd_interpolate(out, filteredlength, output, olength, bd);
-    }
-  } else {
-    highbd_interpolate(input, length, output, olength, bd);
-  }
-}
-
-static void highbd_fill_col_to_arr(uint16_t *img, int stride, int len,
-                                   uint16_t *arr) {
-  int i;
-  uint16_t *iptr = img;
-  uint16_t *aptr = arr;
-  for (i = 0; i < len; ++i, iptr += stride) {
-    *aptr++ = *iptr;
-  }
-}
-
-static void highbd_fill_arr_to_col(uint16_t *img, int stride, int len,
-                                   uint16_t *arr) {
-  int i;
-  uint16_t *iptr = img;
-  uint16_t *aptr = arr;
-  for (i = 0; i < len; ++i, iptr += stride) {
-    *iptr = *aptr++;
-  }
-}
-
-void vp9_highbd_resize_plane(const uint8_t *const input,
-                             int height,
-                             int width,
-                             int in_stride,
-                             uint8_t *output,
-                             int height2,
-                             int width2,
-                             int out_stride,
-                             int bd) {
-  int i;
-  uint16_t *intbuf = (uint16_t *)malloc(sizeof(uint16_t) * width2 * height);
-  uint16_t *tmpbuf = (uint16_t *)malloc(sizeof(uint16_t) *
-                                        (width < height ? height : width));
-  uint16_t *arrbuf = (uint16_t *)malloc(sizeof(uint16_t) * height);
-  uint16_t *arrbuf2 = (uint16_t *)malloc(sizeof(uint16_t) * height2);
-  if (intbuf == NULL || tmpbuf == NULL ||
-      arrbuf == NULL || arrbuf2 == NULL)
-    goto Error;
-  for (i = 0; i < height; ++i) {
-    highbd_resize_multistep(CONVERT_TO_SHORTPTR(input + in_stride * i), width,
-                            intbuf + width2 * i, width2, tmpbuf, bd);
-  }
-  for (i = 0; i < width2; ++i) {
-    highbd_fill_col_to_arr(intbuf + i, width2, height, arrbuf);
-    highbd_resize_multistep(arrbuf, height, arrbuf2, height2, tmpbuf,
-                            bd);
-    highbd_fill_arr_to_col(CONVERT_TO_SHORTPTR(output + i), out_stride, height2,
-                           arrbuf2);
-  }
-
- Error:
-  free(intbuf);
-  free(tmpbuf);
-  free(arrbuf);
-  free(arrbuf2);
-}
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-
-void vp9_resize_frame420(const uint8_t *const y,
-                         int y_stride,
-                         const uint8_t *const u, const uint8_t *const v,
-                         int uv_stride,
-                         int height, int width,
-                         uint8_t *oy, int oy_stride,
-                         uint8_t *ou, uint8_t *ov, int ouv_stride,
-                         int oheight, int owidth) {
-  vp9_resize_plane(y, height, width, y_stride,
-                   oy, oheight, owidth, oy_stride);
-  vp9_resize_plane(u, height / 2, width / 2, uv_stride,
-                   ou, oheight / 2, owidth / 2, ouv_stride);
-  vp9_resize_plane(v, height / 2, width / 2, uv_stride,
-                   ov, oheight / 2, owidth / 2, ouv_stride);
-}
-
-void vp9_resize_frame422(const uint8_t *const y, int y_stride,
-                         const uint8_t *const u, const uint8_t *const v,
-                         int uv_stride,
-                         int height, int width,
-                         uint8_t *oy, int oy_stride,
-                         uint8_t *ou, uint8_t *ov, int ouv_stride,
-                         int oheight, int owidth) {
-  vp9_resize_plane(y, height, width, y_stride,
-                   oy, oheight, owidth, oy_stride);
-  vp9_resize_plane(u, height, width / 2, uv_stride,
-                   ou, oheight, owidth / 2, ouv_stride);
-  vp9_resize_plane(v, height, width / 2, uv_stride,
-                   ov, oheight, owidth / 2, ouv_stride);
-}
-
-void vp9_resize_frame444(const uint8_t *const y, int y_stride,
-                         const uint8_t *const u, const uint8_t *const v,
-                         int uv_stride,
-                         int height, int width,
-                         uint8_t *oy, int oy_stride,
-                         uint8_t *ou, uint8_t *ov, int ouv_stride,
-                         int oheight, int owidth) {
-  vp9_resize_plane(y, height, width, y_stride,
-                   oy, oheight, owidth, oy_stride);
-  vp9_resize_plane(u, height, width, uv_stride,
-                   ou, oheight, owidth, ouv_stride);
-  vp9_resize_plane(v, height, width, uv_stride,
-                   ov, oheight, owidth, ouv_stride);
-}
-
-#if CONFIG_VP9_HIGHBITDEPTH
-void vp9_highbd_resize_frame420(const uint8_t *const y,
-                                int y_stride,
-                                const uint8_t *const u, const uint8_t *const v,
-                                int uv_stride,
-                                int height, int width,
-                                uint8_t *oy, int oy_stride,
-                                uint8_t *ou, uint8_t *ov, int ouv_stride,
-                                int oheight, int owidth, int bd) {
-  vp9_highbd_resize_plane(y, height, width, y_stride,
-                          oy, oheight, owidth, oy_stride, bd);
-  vp9_highbd_resize_plane(u, height / 2, width / 2, uv_stride,
-                          ou, oheight / 2, owidth / 2, ouv_stride, bd);
-  vp9_highbd_resize_plane(v, height / 2, width / 2, uv_stride,
-                          ov, oheight / 2, owidth / 2, ouv_stride, bd);
-}
-
-void vp9_highbd_resize_frame422(const uint8_t *const y, int y_stride,
-                                const uint8_t *const u, const uint8_t *const v,
-                                int uv_stride,
-                                int height, int width,
-                                uint8_t *oy, int oy_stride,
-                                uint8_t *ou, uint8_t *ov, int ouv_stride,
-                                int oheight, int owidth, int bd) {
-  vp9_highbd_resize_plane(y, height, width, y_stride,
-                          oy, oheight, owidth, oy_stride, bd);
-  vp9_highbd_resize_plane(u, height, width / 2, uv_stride,
-                          ou, oheight, owidth / 2, ouv_stride, bd);
-  vp9_highbd_resize_plane(v, height, width / 2, uv_stride,
-                          ov, oheight, owidth / 2, ouv_stride, bd);
-}
-
-void vp9_highbd_resize_frame444(const uint8_t *const y, int y_stride,
-                                const uint8_t *const u, const uint8_t *const v,
-                                int uv_stride,
-                                int height, int width,
-                                uint8_t *oy, int oy_stride,
-                                uint8_t *ou, uint8_t *ov, int ouv_stride,
-                                int oheight, int owidth, int bd) {
-  vp9_highbd_resize_plane(y, height, width, y_stride,
-                          oy, oheight, owidth, oy_stride, bd);
-  vp9_highbd_resize_plane(u, height, width, uv_stride,
-                          ou, oheight, owidth, ouv_stride, bd);
-  vp9_highbd_resize_plane(v, height, width, uv_stride,
-                          ov, oheight, owidth, ouv_stride, bd);
-}
-#endif  // CONFIG_VP9_HIGHBITDEPTH
diff --git a/vp9/encoder/vp9_resize.h b/vp9/encoder/vp9_resize.h
deleted file mode 100644 (file)
index b5feb38..0000000
+++ /dev/null
@@ -1,133 +0,0 @@
-/*
- *  Copyright (c) 2014 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.
- */
-
-#ifndef VP9_ENCODER_VP9_RESIZE_H_
-#define VP9_ENCODER_VP9_RESIZE_H_
-
-#include <stdio.h>
-#include "vpx/vpx_integer.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-void vp9_resize_plane(const uint8_t *const input,
-                      int height,
-                      int width,
-                      int in_stride,
-                      uint8_t *output,
-                      int height2,
-                      int width2,
-                      int out_stride);
-void vp9_resize_frame420(const uint8_t *const y,
-                         int y_stride,
-                         const uint8_t *const u,
-                         const uint8_t *const v,
-                         int uv_stride,
-                         int height,
-                         int width,
-                         uint8_t *oy,
-                         int oy_stride,
-                         uint8_t *ou,
-                         uint8_t *ov,
-                         int ouv_stride,
-                         int oheight,
-                         int owidth);
-void vp9_resize_frame422(const uint8_t *const y,
-                         int y_stride,
-                         const uint8_t *const u,
-                         const uint8_t *const v,
-                         int uv_stride,
-                         int height,
-                         int width,
-                         uint8_t *oy,
-                         int oy_stride,
-                         uint8_t *ou,
-                         uint8_t *ov,
-                         int ouv_stride,
-                         int oheight,
-                         int owidth);
-void vp9_resize_frame444(const uint8_t *const y,
-                         int y_stride,
-                         const uint8_t *const u,
-                         const uint8_t *const v,
-                         int uv_stride,
-                         int height,
-                         int width,
-                         uint8_t *oy,
-                         int oy_stride,
-                         uint8_t *ou,
-                         uint8_t *ov,
-                         int ouv_stride,
-                         int oheight,
-                         int owidth);
-
-#if CONFIG_VP9_HIGHBITDEPTH
-void vp9_highbd_resize_plane(const uint8_t *const input,
-                             int height,
-                             int width,
-                             int in_stride,
-                             uint8_t *output,
-                             int height2,
-                             int width2,
-                             int out_stride,
-                             int bd);
-void vp9_highbd_resize_frame420(const uint8_t *const y,
-                                int y_stride,
-                                const uint8_t *const u,
-                                const uint8_t *const v,
-                                int uv_stride,
-                                int height,
-                                int width,
-                                uint8_t *oy,
-                                int oy_stride,
-                                uint8_t *ou,
-                                uint8_t *ov,
-                                int ouv_stride,
-                                int oheight,
-                                int owidth,
-                                int bd);
-void vp9_highbd_resize_frame422(const uint8_t *const y,
-                                int y_stride,
-                                const uint8_t *const u,
-                                const uint8_t *const v,
-                                int uv_stride,
-                                int height,
-                                int width,
-                                uint8_t *oy,
-                                int oy_stride,
-                                uint8_t *ou,
-                                uint8_t *ov,
-                                int ouv_stride,
-                                int oheight,
-                                int owidth,
-                                int bd);
-void vp9_highbd_resize_frame444(const uint8_t *const y,
-                                int y_stride,
-                                const uint8_t *const u,
-                                const uint8_t *const v,
-                                int uv_stride,
-                                int height,
-                                int width,
-                                uint8_t *oy,
-                                int oy_stride,
-                                uint8_t *ou,
-                                uint8_t *ov,
-                                int ouv_stride,
-                                int oheight,
-                                int owidth,
-                                int bd);
-#endif    // CONFIG_VP9_HIGHBITDEPTH
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif    // VP9_ENCODER_VP9_RESIZE_H_
diff --git a/vp9/encoder/vp9_segmentation.c b/vp9/encoder/vp9_segmentation.c
deleted file mode 100644 (file)
index 5a0a23d..0000000
+++ /dev/null
@@ -1,281 +0,0 @@
-/*
- *  Copyright (c) 2012 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.
- */
-
-
-#include <limits.h>
-
-#include "vpx_mem/vpx_mem.h"
-
-#include "vp9/common/vp9_pred_common.h"
-#include "vp9/common/vp9_tile_common.h"
-
-#include "vp9/encoder/vp9_cost.h"
-#include "vp9/encoder/vp9_segmentation.h"
-
-void vp9_enable_segmentation(struct segmentation *seg) {
-  seg->enabled = 1;
-  seg->update_map = 1;
-  seg->update_data = 1;
-}
-
-void vp9_disable_segmentation(struct segmentation *seg) {
-  seg->enabled = 0;
-  seg->update_map = 0;
-  seg->update_data = 0;
-}
-
-void vp9_set_segment_data(struct segmentation *seg,
-                          signed char *feature_data,
-                          unsigned char abs_delta) {
-  seg->abs_delta = abs_delta;
-
-  memcpy(seg->feature_data, feature_data, sizeof(seg->feature_data));
-}
-void vp9_disable_segfeature(struct segmentation *seg, int segment_id,
-                            SEG_LVL_FEATURES feature_id) {
-  seg->feature_mask[segment_id] &= ~(1 << feature_id);
-}
-
-void vp9_clear_segdata(struct segmentation *seg, int segment_id,
-                       SEG_LVL_FEATURES feature_id) {
-  seg->feature_data[segment_id][feature_id] = 0;
-}
-
-// Based on set of segment counts calculate a probability tree
-static void calc_segtree_probs(int *segcounts, vpx_prob *segment_tree_probs) {
-  // Work out probabilities of each segment
-  const int c01 = segcounts[0] + segcounts[1];
-  const int c23 = segcounts[2] + segcounts[3];
-  const int c45 = segcounts[4] + segcounts[5];
-  const int c67 = segcounts[6] + segcounts[7];
-
-  segment_tree_probs[0] = get_binary_prob(c01 + c23, c45 + c67);
-  segment_tree_probs[1] = get_binary_prob(c01, c23);
-  segment_tree_probs[2] = get_binary_prob(c45, c67);
-  segment_tree_probs[3] = get_binary_prob(segcounts[0], segcounts[1]);
-  segment_tree_probs[4] = get_binary_prob(segcounts[2], segcounts[3]);
-  segment_tree_probs[5] = get_binary_prob(segcounts[4], segcounts[5]);
-  segment_tree_probs[6] = get_binary_prob(segcounts[6], segcounts[7]);
-}
-
-// Based on set of segment counts and probabilities calculate a cost estimate
-static int cost_segmap(int *segcounts, vpx_prob *probs) {
-  const int c01 = segcounts[0] + segcounts[1];
-  const int c23 = segcounts[2] + segcounts[3];
-  const int c45 = segcounts[4] + segcounts[5];
-  const int c67 = segcounts[6] + segcounts[7];
-  const int c0123 = c01 + c23;
-  const int c4567 = c45 + c67;
-
-  // Cost the top node of the tree
-  int cost = c0123 * vp9_cost_zero(probs[0]) +
-             c4567 * vp9_cost_one(probs[0]);
-
-  // Cost subsequent levels
-  if (c0123 > 0) {
-    cost += c01 * vp9_cost_zero(probs[1]) +
-            c23 * vp9_cost_one(probs[1]);
-
-    if (c01 > 0)
-      cost += segcounts[0] * vp9_cost_zero(probs[3]) +
-              segcounts[1] * vp9_cost_one(probs[3]);
-    if (c23 > 0)
-      cost += segcounts[2] * vp9_cost_zero(probs[4]) +
-              segcounts[3] * vp9_cost_one(probs[4]);
-  }
-
-  if (c4567 > 0) {
-    cost += c45 * vp9_cost_zero(probs[2]) +
-            c67 * vp9_cost_one(probs[2]);
-
-    if (c45 > 0)
-      cost += segcounts[4] * vp9_cost_zero(probs[5]) +
-              segcounts[5] * vp9_cost_one(probs[5]);
-    if (c67 > 0)
-      cost += segcounts[6] * vp9_cost_zero(probs[6]) +
-              segcounts[7] * vp9_cost_one(probs[6]);
-  }
-
-  return cost;
-}
-
-static void count_segs(const VP9_COMMON *cm, MACROBLOCKD *xd,
-                       const TileInfo *tile, MODE_INFO **mi,
-                       int *no_pred_segcounts,
-                       int (*temporal_predictor_count)[2],
-                       int *t_unpred_seg_counts,
-                       int bw, int bh, int mi_row, int mi_col) {
-  int segment_id;
-
-  if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols)
-    return;
-
-  xd->mi = mi;
-  segment_id = xd->mi[0]->segment_id;
-
-  set_mi_row_col(xd, tile, mi_row, bh, mi_col, bw, cm->mi_rows, cm->mi_cols);
-
-  // Count the number of hits on each segment with no prediction
-  no_pred_segcounts[segment_id]++;
-
-  // Temporal prediction not allowed on key frames
-  if (cm->frame_type != KEY_FRAME) {
-    const BLOCK_SIZE bsize = xd->mi[0]->sb_type;
-    // Test to see if the segment id matches the predicted value.
-    const int pred_segment_id = get_segment_id(cm, cm->last_frame_seg_map,
-                                               bsize, mi_row, mi_col);
-    const int pred_flag = pred_segment_id == segment_id;
-    const int pred_context = vp9_get_pred_context_seg_id(xd);
-
-    // Store the prediction status for this mb and update counts
-    // as appropriate
-    xd->mi[0]->seg_id_predicted = pred_flag;
-    temporal_predictor_count[pred_context][pred_flag]++;
-
-    // Update the "unpredicted" segment count
-    if (!pred_flag)
-      t_unpred_seg_counts[segment_id]++;
-  }
-}
-
-static void count_segs_sb(const VP9_COMMON *cm, MACROBLOCKD *xd,
-                          const TileInfo *tile, MODE_INFO **mi,
-                          int *no_pred_segcounts,
-                          int (*temporal_predictor_count)[2],
-                          int *t_unpred_seg_counts,
-                          int mi_row, int mi_col,
-                          BLOCK_SIZE bsize) {
-  const int mis = cm->mi_stride;
-  int bw, bh;
-  const int bs = num_8x8_blocks_wide_lookup[bsize], hbs = bs / 2;
-
-  if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols)
-    return;
-
-  bw = num_8x8_blocks_wide_lookup[mi[0]->sb_type];
-  bh = num_8x8_blocks_high_lookup[mi[0]->sb_type];
-
-  if (bw == bs && bh == bs) {
-    count_segs(cm, xd, tile, mi, no_pred_segcounts, temporal_predictor_count,
-               t_unpred_seg_counts, bs, bs, mi_row, mi_col);
-  } else if (bw == bs && bh < bs) {
-    count_segs(cm, xd, tile, mi, no_pred_segcounts, temporal_predictor_count,
-               t_unpred_seg_counts, bs, hbs, mi_row, mi_col);
-    count_segs(cm, xd, tile, mi + hbs * mis, no_pred_segcounts,
-               temporal_predictor_count, t_unpred_seg_counts, bs, hbs,
-               mi_row + hbs, mi_col);
-  } else if (bw < bs && bh == bs) {
-    count_segs(cm, xd, tile, mi, no_pred_segcounts, temporal_predictor_count,
-               t_unpred_seg_counts, hbs, bs, mi_row, mi_col);
-    count_segs(cm, xd, tile, mi + hbs,
-               no_pred_segcounts, temporal_predictor_count, t_unpred_seg_counts,
-               hbs, bs, mi_row, mi_col + hbs);
-  } else {
-    const BLOCK_SIZE subsize = subsize_lookup[PARTITION_SPLIT][bsize];
-    int n;
-
-    assert(bw < bs && bh < bs);
-
-    for (n = 0; n < 4; n++) {
-      const int mi_dc = hbs * (n & 1);
-      const int mi_dr = hbs * (n >> 1);
-
-      count_segs_sb(cm, xd, tile, &mi[mi_dr * mis + mi_dc],
-                    no_pred_segcounts, temporal_predictor_count,
-                    t_unpred_seg_counts,
-                    mi_row + mi_dr, mi_col + mi_dc, subsize);
-    }
-  }
-}
-
-void vp9_choose_segmap_coding_method(VP9_COMMON *cm, MACROBLOCKD *xd) {
-  struct segmentation *seg = &cm->seg;
-
-  int no_pred_cost;
-  int t_pred_cost = INT_MAX;
-
-  int i, tile_col, mi_row, mi_col;
-
-  int temporal_predictor_count[PREDICTION_PROBS][2] = { { 0 } };
-  int no_pred_segcounts[MAX_SEGMENTS] = { 0 };
-  int t_unpred_seg_counts[MAX_SEGMENTS] = { 0 };
-
-  vpx_prob no_pred_tree[SEG_TREE_PROBS];
-  vpx_prob t_pred_tree[SEG_TREE_PROBS];
-  vpx_prob t_nopred_prob[PREDICTION_PROBS];
-
-  // Set default state for the segment tree probabilities and the
-  // temporal coding probabilities
-  memset(seg->tree_probs, 255, sizeof(seg->tree_probs));
-  memset(seg->pred_probs, 255, sizeof(seg->pred_probs));
-
-  // First of all generate stats regarding how well the last segment map
-  // predicts this one
-  for (tile_col = 0; tile_col < 1 << cm->log2_tile_cols; tile_col++) {
-    TileInfo tile;
-    MODE_INFO **mi_ptr;
-    vp9_tile_init(&tile, cm, 0, tile_col);
-
-    mi_ptr = cm->mi_grid_visible + tile.mi_col_start;
-    for (mi_row = 0; mi_row < cm->mi_rows;
-         mi_row += 8, mi_ptr += 8 * cm->mi_stride) {
-      MODE_INFO **mi = mi_ptr;
-      for (mi_col = tile.mi_col_start; mi_col < tile.mi_col_end;
-           mi_col += 8, mi += 8)
-        count_segs_sb(cm, xd, &tile, mi, no_pred_segcounts,
-                      temporal_predictor_count, t_unpred_seg_counts,
-                      mi_row, mi_col, BLOCK_64X64);
-    }
-  }
-
-  // Work out probability tree for coding segments without prediction
-  // and the cost.
-  calc_segtree_probs(no_pred_segcounts, no_pred_tree);
-  no_pred_cost = cost_segmap(no_pred_segcounts, no_pred_tree);
-
-  // Key frames cannot use temporal prediction
-  if (!frame_is_intra_only(cm)) {
-    // Work out probability tree for coding those segments not
-    // predicted using the temporal method and the cost.
-    calc_segtree_probs(t_unpred_seg_counts, t_pred_tree);
-    t_pred_cost = cost_segmap(t_unpred_seg_counts, t_pred_tree);
-
-    // Add in the cost of the signaling for each prediction context.
-    for (i = 0; i < PREDICTION_PROBS; i++) {
-      const int count0 = temporal_predictor_count[i][0];
-      const int count1 = temporal_predictor_count[i][1];
-
-      t_nopred_prob[i] = get_binary_prob(count0, count1);
-
-      // Add in the predictor signaling cost
-      t_pred_cost += count0 * vp9_cost_zero(t_nopred_prob[i]) +
-                     count1 * vp9_cost_one(t_nopred_prob[i]);
-    }
-  }
-
-  // Now choose which coding method to use.
-  if (t_pred_cost < no_pred_cost) {
-    seg->temporal_update = 1;
-    memcpy(seg->tree_probs, t_pred_tree, sizeof(t_pred_tree));
-    memcpy(seg->pred_probs, t_nopred_prob, sizeof(t_nopred_prob));
-  } else {
-    seg->temporal_update = 0;
-    memcpy(seg->tree_probs, no_pred_tree, sizeof(no_pred_tree));
-  }
-}
-
-void vp9_reset_segment_features(struct segmentation *seg) {
-  // Set up default state for MB feature flags
-  seg->enabled = 0;
-  seg->update_map = 0;
-  seg->update_data = 0;
-  memset(seg->tree_probs, 255, sizeof(seg->tree_probs));
-  vp9_clearall_segfeatures(seg);
-}
diff --git a/vp9/encoder/vp9_segmentation.h b/vp9/encoder/vp9_segmentation.h
deleted file mode 100644 (file)
index 8c6944a..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-
-#ifndef VP9_ENCODER_VP9_SEGMENTATION_H_
-#define VP9_ENCODER_VP9_SEGMENTATION_H_
-
-#include "vp9/common/vp9_blockd.h"
-#include "vp9/encoder/vp9_encoder.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-void vp9_enable_segmentation(struct segmentation *seg);
-void vp9_disable_segmentation(struct segmentation *seg);
-
-void vp9_disable_segfeature(struct segmentation *seg,
-                            int segment_id,
-                            SEG_LVL_FEATURES feature_id);
-void vp9_clear_segdata(struct segmentation *seg,
-                       int segment_id,
-                       SEG_LVL_FEATURES feature_id);
-
-// The values given for each segment can be either deltas (from the default
-// value chosen for the frame) or absolute values.
-//
-// Valid range for abs values is (0-127 for MB_LVL_ALT_Q), (0-63 for
-// SEGMENT_ALT_LF)
-// Valid range for delta values are (+/-127 for MB_LVL_ALT_Q), (+/-63 for
-// SEGMENT_ALT_LF)
-//
-// abs_delta = SEGMENT_DELTADATA (deltas) abs_delta = SEGMENT_ABSDATA (use
-// the absolute values given).
-void vp9_set_segment_data(struct segmentation *seg, signed char *feature_data,
-                          unsigned char abs_delta);
-
-void vp9_choose_segmap_coding_method(VP9_COMMON *cm, MACROBLOCKD *xd);
-
-void vp9_reset_segment_features(struct segmentation *seg);
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP9_ENCODER_VP9_SEGMENTATION_H_
diff --git a/vp9/encoder/vp9_skin_detection.c b/vp9/encoder/vp9_skin_detection.c
deleted file mode 100644 (file)
index 23a5fc7..0000000
+++ /dev/null
@@ -1,208 +0,0 @@
-/*
- *  Copyright (c) 2015 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.
- */
-
-#include <limits.h>
-#include <math.h>
-
-#include "vp9/common/vp9_blockd.h"
-#include "vp9/encoder/vp9_encoder.h"
-#include "vp9/encoder/vp9_skin_detection.h"
-
-#define MODEL_MODE 1
-
-// Fixed-point skin color model parameters.
-static const int skin_mean[5][2] = {
-    {7463, 9614}, {6400, 10240}, {7040, 10240}, {8320, 9280}, {6800, 9614}};
-static const int skin_inv_cov[4] = {4107, 1663, 1663, 2157};  // q16
-static const int skin_threshold[6] = {1570636, 1400000, 800000, 800000, 800000,
-    800000};  // q18
-
-// Thresholds on luminance.
-static const int y_low = 40;
-static const int y_high = 220;
-
-// Evaluates the Mahalanobis distance measure for the input CbCr values.
-static int evaluate_skin_color_difference(int cb, int cr, int idx) {
-  const int cb_q6 = cb << 6;
-  const int cr_q6 = cr << 6;
-  const int cb_diff_q12 =
-      (cb_q6 - skin_mean[idx][0]) * (cb_q6 - skin_mean[idx][0]);
-  const int cbcr_diff_q12 =
-      (cb_q6 - skin_mean[idx][0]) * (cr_q6 - skin_mean[idx][1]);
-  const int cr_diff_q12 =
-      (cr_q6 - skin_mean[idx][1]) * (cr_q6 - skin_mean[idx][1]);
-  const int cb_diff_q2 = (cb_diff_q12 + (1 << 9)) >> 10;
-  const int cbcr_diff_q2 = (cbcr_diff_q12 + (1 << 9)) >> 10;
-  const int cr_diff_q2 = (cr_diff_q12 + (1 << 9)) >> 10;
-  const int skin_diff = skin_inv_cov[0] * cb_diff_q2 +
-      skin_inv_cov[1] * cbcr_diff_q2 +
-      skin_inv_cov[2] * cbcr_diff_q2 +
-      skin_inv_cov[3] * cr_diff_q2;
-  return skin_diff;
-}
-
-int vp9_skin_pixel(const uint8_t y, const uint8_t cb, const uint8_t cr,
-                   int motion) {
-  if (y < y_low || y > y_high) {
-    return 0;
-  } else {
-    if (MODEL_MODE == 0) {
-      return (evaluate_skin_color_difference(cb, cr, 0) < skin_threshold[0]);
-    } else {
-      int i = 0;
-      // Exit on grey.
-      if (cb == 128 && cr == 128)
-        return 0;
-      // Exit on very strong cb.
-      if (cb > 150 && cr < 110)
-        return 0;
-      for (; i < 5; i++) {
-        int skin_color_diff = evaluate_skin_color_difference(cb, cr, i);
-        if (skin_color_diff < skin_threshold[i + 1]) {
-           if (y < 60 && skin_color_diff > 3 * (skin_threshold[i + 1] >> 2))
-             return 0;
-           else if (motion == 0 &&
-                    skin_color_diff > (skin_threshold[i + 1] >> 1))
-             return 0;
-           else
-            return 1;
-        }
-        // Exit if difference is much large than the threshold.
-        if (skin_color_diff > (skin_threshold[i + 1] << 3)) {
-          return 0;
-        }
-      }
-      return 0;
-    }
-  }
-}
-
-int vp9_compute_skin_block(const uint8_t *y, const uint8_t *u, const uint8_t *v,
-                           int stride, int strideuv, int bsize,
-                           int consec_zeromv, int curr_motion_magn) {
-  // No skin if block has been zero/small motion for long consecutive time.
-  if (consec_zeromv > 60 && curr_motion_magn == 0) {
-    return 0;
-  } else {
-    int motion = 1;
-    // Take center pixel in block to determine is_skin.
-    const int y_width_shift = (4 << b_width_log2_lookup[bsize]) >> 1;
-    const int y_height_shift = (4 << b_height_log2_lookup[bsize]) >> 1;
-    const int uv_width_shift = y_width_shift >> 1;
-    const int uv_height_shift = y_height_shift >> 1;
-    const uint8_t ysource = y[y_height_shift * stride + y_width_shift];
-    const uint8_t usource = u[uv_height_shift * strideuv + uv_width_shift];
-    const uint8_t vsource = v[uv_height_shift * strideuv + uv_width_shift];
-    if (consec_zeromv > 25 && curr_motion_magn == 0)
-      motion = 0;
-    return vp9_skin_pixel(ysource, usource, vsource, motion);
-  }
-}
-
-
-#ifdef OUTPUT_YUV_SKINMAP
-// For viewing skin map on input source.
-void vp9_compute_skin_map(VP9_COMP *const cpi, FILE *yuv_skinmap_file) {
-  int i, j, mi_row, mi_col, num_bl;
-  VP9_COMMON *const cm = &cpi->common;
-  uint8_t *y;
-  const uint8_t *src_y = cpi->Source->y_buffer;
-  const uint8_t *src_u = cpi->Source->u_buffer;
-  const uint8_t *src_v = cpi->Source->v_buffer;
-  const int src_ystride = cpi->Source->y_stride;
-  const int src_uvstride = cpi->Source->uv_stride;
-  int y_bsize = 16;  // Use 8x8 or 16x16.
-  int uv_bsize = y_bsize >> 1;
-  int ypos = y_bsize >> 1;
-  int uvpos = uv_bsize >> 1;
-  int shy = (y_bsize == 8) ? 3 : 4;
-  int shuv = shy - 1;
-  int fac = y_bsize / 8;
-  // Use center pixel or average of center 2x2 pixels.
-  int mode_filter = 0;
-  YV12_BUFFER_CONFIG skinmap;
-  memset(&skinmap, 0, sizeof(YV12_BUFFER_CONFIG));
-  if (vpx_alloc_frame_buffer(&skinmap, cm->width, cm->height,
-                               cm->subsampling_x, cm->subsampling_y,
-                               VP9_ENC_BORDER_IN_PIXELS, cm->byte_alignment)) {
-      vpx_free_frame_buffer(&skinmap);
-      return;
-  }
-  memset(skinmap.buffer_alloc, 128, skinmap.frame_size);
-  y = skinmap.y_buffer;
-  // Loop through blocks and set skin map based on center pixel of block.
-  // Set y to white for skin block, otherwise set to source with gray scale.
-  // Ignore rightmost/bottom boundary blocks.
-  for (mi_row = 0; mi_row < cm->mi_rows - 1; mi_row += fac) {
-    num_bl = 0;
-    for (mi_col = 0; mi_col < cm->mi_cols - 1; mi_col += fac) {
-      int is_skin = 0;
-      if (mode_filter == 1) {
-        // Use 2x2 average at center.
-        uint8_t ysource = src_y[ypos * src_ystride + ypos];
-        uint8_t usource = src_u[uvpos * src_uvstride + uvpos];
-        uint8_t vsource = src_v[uvpos * src_uvstride + uvpos];
-        uint8_t ysource2 = src_y[(ypos + 1) * src_ystride + ypos];
-        uint8_t usource2 = src_u[(uvpos + 1) * src_uvstride + uvpos];
-        uint8_t vsource2 = src_v[(uvpos + 1) * src_uvstride + uvpos];
-        uint8_t ysource3 = src_y[ypos * src_ystride + (ypos + 1)];
-        uint8_t usource3 = src_u[uvpos * src_uvstride + (uvpos  + 1)];
-        uint8_t vsource3 = src_v[uvpos * src_uvstride + (uvpos +  1)];
-        uint8_t ysource4 = src_y[(ypos + 1) * src_ystride + (ypos + 1)];
-        uint8_t usource4 = src_u[(uvpos + 1) * src_uvstride + (uvpos  + 1)];
-        uint8_t vsource4 = src_v[(uvpos + 1) * src_uvstride + (uvpos +  1)];
-        ysource = (ysource + ysource2 + ysource3 + ysource4) >> 2;
-        usource = (usource + usource2 + usource3 + usource4) >> 2;
-        vsource = (vsource + vsource2 + vsource3 + vsource4) >> 2;
-        is_skin = vp9_skin_pixel(ysource, usource, vsource, 1);
-      } else {
-        int block_size = BLOCK_8X8;
-        int consec_zeromv = 0;
-        int bl_index = mi_row * cm->mi_cols + mi_col;
-        int bl_index1 = bl_index + 1;
-        int bl_index2 = bl_index + cm->mi_cols;
-        int bl_index3 = bl_index2 + 1;
-        if (y_bsize == 8)
-          consec_zeromv = cpi->consec_zero_mv[bl_index];
-        else
-          consec_zeromv = VPXMIN(cpi->consec_zero_mv[bl_index],
-                                 VPXMIN(cpi->consec_zero_mv[bl_index1],
-                                 VPXMIN(cpi->consec_zero_mv[bl_index2],
-                                 cpi->consec_zero_mv[bl_index3])));
-        if (y_bsize == 16)
-          block_size = BLOCK_16X16;
-        is_skin  = vp9_compute_skin_block(src_y, src_u, src_v, src_ystride,
-                                          src_uvstride, block_size,
-                                          consec_zeromv,
-                                          0);
-      }
-      for (i = 0; i < y_bsize; i++) {
-        for (j = 0; j < y_bsize; j++) {
-          if (is_skin)
-            y[i * src_ystride + j] = 255;
-          else
-            y[i * src_ystride + j] = src_y[i * src_ystride + j];
-        }
-      }
-      num_bl++;
-      y += y_bsize;
-      src_y += y_bsize;
-      src_u += uv_bsize;
-      src_v += uv_bsize;
-    }
-    y += (src_ystride << shy) - (num_bl << shy);
-    src_y += (src_ystride << shy) - (num_bl << shy);
-    src_u += (src_uvstride << shuv) - (num_bl << shuv);
-    src_v += (src_uvstride << shuv) - (num_bl << shuv);
-  }
-  vp9_write_yuv_frame_420(&skinmap, yuv_skinmap_file);
-  vpx_free_frame_buffer(&skinmap);
-}
-#endif
diff --git a/vp9/encoder/vp9_skin_detection.h b/vp9/encoder/vp9_skin_detection.h
deleted file mode 100644 (file)
index c77382d..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- *  Copyright (c) 2015 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.
- */
-
-#ifndef VP9_ENCODER_VP9_SKIN_MAP_H_
-#define VP9_ENCODER_VP9_SKIN_MAP_H_
-
-#include "vp9/common/vp9_blockd.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-struct VP9_COMP;
-
-// #define OUTPUT_YUV_SKINMAP
-
-int vp9_skin_pixel(const uint8_t y, const uint8_t cb, const uint8_t cr,
-                   int motion);
-
-int vp9_compute_skin_block(const uint8_t *y, const uint8_t *u, const uint8_t *v,
-                           int stride, int strideuv, int bsize,
-                           int consec_zeromv, int curr_motion_magn);
-
-#ifdef OUTPUT_YUV_SKINMAP
-// For viewing skin map on input source.
-void vp9_compute_skin_map(struct VP9_COMP *const cpi, FILE *yuv_skinmap_file);
-extern void vp9_write_yuv_frame_420(YV12_BUFFER_CONFIG *s, FILE *f);
-#endif
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP9_ENCODER_VP9_SKIN_MAP_H_
diff --git a/vp9/encoder/vp9_speed_features.c b/vp9/encoder/vp9_speed_features.c
deleted file mode 100644 (file)
index e7f04a2..0000000
+++ /dev/null
@@ -1,650 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#include <limits.h>
-
-#include "vp9/encoder/vp9_encoder.h"
-#include "vp9/encoder/vp9_speed_features.h"
-#include "vp9/encoder/vp9_rdopt.h"
-#include "vpx_dsp/vpx_dsp_common.h"
-
-// Mesh search patters for various speed settings
-static MESH_PATTERN best_quality_mesh_pattern[MAX_MESH_STEP] =
-    {{64, 4}, {28, 2}, {15, 1}, {7, 1}};
-
-#define MAX_MESH_SPEED 5  // Max speed setting for mesh motion method
-static MESH_PATTERN good_quality_mesh_patterns[MAX_MESH_SPEED + 1]
-                                              [MAX_MESH_STEP] =
-    {{{64, 8}, {28, 4}, {15, 1}, {7, 1}},
-     {{64, 8}, {28, 4}, {15, 1}, {7, 1}},
-     {{64, 8},  {14, 2}, {7, 1},  {7, 1}},
-     {{64, 16}, {24, 8}, {12, 4}, {7, 1}},
-     {{64, 16}, {24, 8}, {12, 4}, {7, 1}},
-     {{64, 16}, {24, 8}, {12, 4}, {7, 1}},
-    };
-static unsigned char good_quality_max_mesh_pct[MAX_MESH_SPEED + 1] =
-    {50, 25, 15, 5, 1, 1};
-
-// Intra only frames, golden frames (except alt ref overlays) and
-// alt ref frames tend to be coded at a higher than ambient quality
-static int frame_is_boosted(const VP9_COMP *cpi) {
-  return frame_is_kf_gf_arf(cpi) || vp9_is_upper_layer_key_frame(cpi);
-}
-
-// Sets a partition size down to which the auto partition code will always
-// search (can go lower), based on the image dimensions. The logic here
-// is that the extent to which ringing artefacts are offensive, depends
-// partly on the screen area that over which they propogate. Propogation is
-// limited by transform block size but the screen area take up by a given block
-// size will be larger for a small image format stretched to full screen.
-static BLOCK_SIZE set_partition_min_limit(VP9_COMMON *const cm) {
-  unsigned int screen_area = (cm->width * cm->height);
-
-  // Select block size based on image format size.
-  if (screen_area < 1280 * 720) {
-    // Formats smaller in area than 720P
-    return BLOCK_4X4;
-  } else if (screen_area < 1920 * 1080) {
-    // Format >= 720P and < 1080P
-    return BLOCK_8X8;
-  } else {
-    // Formats 1080P and up
-    return BLOCK_16X16;
-  }
-}
-
-static void set_good_speed_feature_framesize_dependent(VP9_COMP *cpi,
-                                                       SPEED_FEATURES *sf,
-                                                       int speed) {
-  VP9_COMMON *const cm = &cpi->common;
-
-  if (speed >= 1) {
-    if (VPXMIN(cm->width, cm->height) >= 720) {
-      sf->disable_split_mask = cm->show_frame ? DISABLE_ALL_SPLIT
-                                              : DISABLE_ALL_INTER_SPLIT;
-      sf->partition_search_breakout_dist_thr = (1 << 23);
-    } else {
-      sf->disable_split_mask = DISABLE_COMPOUND_SPLIT;
-      sf->partition_search_breakout_dist_thr = (1 << 21);
-    }
-  }
-
-  if (speed >= 2) {
-    if (VPXMIN(cm->width, cm->height) >= 720) {
-      sf->disable_split_mask = cm->show_frame ? DISABLE_ALL_SPLIT
-                                              : DISABLE_ALL_INTER_SPLIT;
-      sf->adaptive_pred_interp_filter = 0;
-      sf->partition_search_breakout_dist_thr = (1 << 24);
-      sf->partition_search_breakout_rate_thr = 120;
-    } else {
-      sf->disable_split_mask = LAST_AND_INTRA_SPLIT_ONLY;
-      sf->partition_search_breakout_dist_thr = (1 << 22);
-      sf->partition_search_breakout_rate_thr = 100;
-    }
-    sf->rd_auto_partition_min_limit = set_partition_min_limit(cm);
-  }
-
-  if (speed >= 3) {
-    if (VPXMIN(cm->width, cm->height) >= 720) {
-      sf->disable_split_mask = DISABLE_ALL_SPLIT;
-      sf->schedule_mode_search = cm->base_qindex < 220 ? 1 : 0;
-      sf->partition_search_breakout_dist_thr = (1 << 25);
-      sf->partition_search_breakout_rate_thr = 200;
-    } else {
-      sf->max_intra_bsize = BLOCK_32X32;
-      sf->disable_split_mask = DISABLE_ALL_INTER_SPLIT;
-      sf->schedule_mode_search = cm->base_qindex < 175 ? 1 : 0;
-      sf->partition_search_breakout_dist_thr = (1 << 23);
-      sf->partition_search_breakout_rate_thr = 120;
-    }
-  }
-
-  // If this is a two pass clip that fits the criteria for animated or
-  // graphics content then reset disable_split_mask for speeds 1-4.
-  // Also if the image edge is internal to the coded area.
-  if ((speed >= 1) && (cpi->oxcf.pass == 2) &&
-      ((cpi->twopass.fr_content_type == FC_GRAPHICS_ANIMATION) ||
-       (vp9_internal_image_edge(cpi)))) {
-    sf->disable_split_mask = DISABLE_COMPOUND_SPLIT;
-  }
-
-  if (speed >= 4) {
-    if (VPXMIN(cm->width, cm->height) >= 720) {
-      sf->partition_search_breakout_dist_thr = (1 << 26);
-    } else {
-      sf->partition_search_breakout_dist_thr = (1 << 24);
-    }
-    sf->disable_split_mask = DISABLE_ALL_SPLIT;
-  }
-}
-
-static void set_good_speed_feature(VP9_COMP *cpi, VP9_COMMON *cm,
-                                   SPEED_FEATURES *sf, int speed) {
-  const int boosted = frame_is_boosted(cpi);
-
-  sf->partition_search_breakout_dist_thr = (1 << 20);
-  sf->partition_search_breakout_rate_thr = 80;
-  sf->tx_size_search_breakout = 1;
-  sf->adaptive_rd_thresh = 1;
-  sf->allow_skip_recode = 1;
-  sf->less_rectangular_check = 1;
-  sf->use_square_partition_only = !frame_is_boosted(cpi);
-  sf->use_square_only_threshold = BLOCK_16X16;
-
-  if (speed >= 1) {
-    if ((cpi->twopass.fr_content_type == FC_GRAPHICS_ANIMATION) ||
-        vp9_internal_image_edge(cpi)) {
-      sf->use_square_partition_only = !frame_is_boosted(cpi);
-    } else {
-      sf->use_square_partition_only = !frame_is_intra_only(cm);
-    }
-    sf->use_square_only_threshold = BLOCK_4X4;
-
-    sf->less_rectangular_check  = 1;
-
-    sf->use_rd_breakout = 1;
-    sf->adaptive_motion_search = 1;
-    sf->mv.auto_mv_step_size = 1;
-    sf->adaptive_rd_thresh = 2;
-    sf->mv.subpel_iters_per_step = 1;
-    sf->mode_skip_start = 10;
-    sf->adaptive_pred_interp_filter = 1;
-
-    sf->recode_loop = ALLOW_RECODE_KFARFGF;
-    sf->intra_y_mode_mask[TX_32X32] = INTRA_DC_H_V;
-    sf->intra_uv_mode_mask[TX_32X32] = INTRA_DC_H_V;
-    sf->intra_y_mode_mask[TX_16X16] = INTRA_DC_H_V;
-    sf->intra_uv_mode_mask[TX_16X16] = INTRA_DC_H_V;
-  }
-
-  if (speed >= 2) {
-    sf->tx_size_search_method = frame_is_boosted(cpi) ? USE_FULL_RD
-                                                      : USE_LARGESTALL;
-
-    // Reference masking is not supported in dynamic scaling mode.
-    sf->reference_masking = cpi->oxcf.resize_mode != RESIZE_DYNAMIC ? 1 : 0;
-
-    sf->mode_search_skip_flags = (cm->frame_type == KEY_FRAME) ? 0 :
-                                 FLAG_SKIP_INTRA_DIRMISMATCH |
-                                 FLAG_SKIP_INTRA_BESTINTER |
-                                 FLAG_SKIP_COMP_BESTINTRA |
-                                 FLAG_SKIP_INTRA_LOWVAR;
-    sf->disable_filter_search_var_thresh = 100;
-    sf->comp_inter_joint_search_thresh = BLOCK_SIZES;
-    sf->auto_min_max_partition_size = RELAXED_NEIGHBORING_MIN_MAX;
-    sf->allow_partition_search_skip = 1;
-  }
-
-  if (speed >= 3) {
-    sf->use_square_partition_only = !frame_is_intra_only(cm);
-    sf->tx_size_search_method = frame_is_intra_only(cm) ? USE_FULL_RD
-                                                        : USE_LARGESTALL;
-    sf->mv.subpel_search_method = SUBPEL_TREE_PRUNED;
-    sf->adaptive_pred_interp_filter = 0;
-    sf->adaptive_mode_search = 1;
-    sf->cb_partition_search = !boosted;
-    sf->cb_pred_filter_search = 1;
-    sf->alt_ref_search_fp = 1;
-    sf->recode_loop = ALLOW_RECODE_KFMAXBW;
-    sf->adaptive_rd_thresh = 3;
-    sf->mode_skip_start = 6;
-    sf->intra_y_mode_mask[TX_32X32] = INTRA_DC;
-    sf->intra_uv_mode_mask[TX_32X32] = INTRA_DC;
-    sf->adaptive_interp_filter_search = 1;
-  }
-
-  if (speed >= 4) {
-    sf->use_square_partition_only = 1;
-    sf->tx_size_search_method = USE_LARGESTALL;
-    sf->mv.search_method = BIGDIA;
-    sf->mv.subpel_search_method = SUBPEL_TREE_PRUNED_MORE;
-    sf->adaptive_rd_thresh = 4;
-    if (cm->frame_type != KEY_FRAME)
-      sf->mode_search_skip_flags |= FLAG_EARLY_TERMINATE;
-    sf->disable_filter_search_var_thresh = 200;
-    sf->use_lp32x32fdct = 1;
-    sf->use_fast_coef_updates = ONE_LOOP_REDUCED;
-    sf->use_fast_coef_costing = 1;
-    sf->motion_field_mode_search = !boosted;
-    sf->partition_search_breakout_rate_thr = 300;
-  }
-
-  if (speed >= 5) {
-    int i;
-    sf->optimize_coefficients = 0;
-    sf->mv.search_method = HEX;
-    sf->disable_filter_search_var_thresh = 500;
-    for (i = 0; i < TX_SIZES; ++i) {
-      sf->intra_y_mode_mask[i] = INTRA_DC;
-      sf->intra_uv_mode_mask[i] = INTRA_DC;
-    }
-    sf->partition_search_breakout_rate_thr = 500;
-    sf->mv.reduce_first_step_size = 1;
-    sf->simple_model_rd_from_var = 1;
-  }
-}
-
-static void set_rt_speed_feature_framesize_dependent(VP9_COMP *cpi,
-    SPEED_FEATURES *sf, int speed) {
-  VP9_COMMON *const cm = &cpi->common;
-
-  if (speed >= 1) {
-    if (VPXMIN(cm->width, cm->height) >= 720) {
-      sf->disable_split_mask = cm->show_frame ? DISABLE_ALL_SPLIT
-                                              : DISABLE_ALL_INTER_SPLIT;
-    } else {
-      sf->disable_split_mask = DISABLE_COMPOUND_SPLIT;
-    }
-  }
-
-  if (speed >= 2) {
-    if (VPXMIN(cm->width, cm->height) >= 720) {
-      sf->disable_split_mask = cm->show_frame ? DISABLE_ALL_SPLIT
-                                              : DISABLE_ALL_INTER_SPLIT;
-    } else {
-      sf->disable_split_mask = LAST_AND_INTRA_SPLIT_ONLY;
-    }
-  }
-
-  if (speed >= 5) {
-    if (VPXMIN(cm->width, cm->height) >= 720) {
-      sf->partition_search_breakout_dist_thr = (1 << 25);
-    } else {
-      sf->partition_search_breakout_dist_thr = (1 << 23);
-    }
-  }
-
-  if (speed >= 7) {
-    sf->encode_breakout_thresh = (VPXMIN(cm->width, cm->height) >= 720) ?
-        800 : 300;
-  }
-}
-
-static void set_rt_speed_feature(VP9_COMP *cpi, SPEED_FEATURES *sf,
-                                 int speed, vp9e_tune_content content) {
-  VP9_COMMON *const cm = &cpi->common;
-  const int is_keyframe = cm->frame_type == KEY_FRAME;
-  const int frames_since_key = is_keyframe ? 0 : cpi->rc.frames_since_key;
-  sf->static_segmentation = 0;
-  sf->adaptive_rd_thresh = 1;
-  sf->use_fast_coef_costing = 1;
-  sf->allow_exhaustive_searches = 0;
-  sf->exhaustive_searches_thresh = INT_MAX;
-
-  if (speed >= 1) {
-    sf->use_square_partition_only = !frame_is_intra_only(cm);
-    sf->less_rectangular_check = 1;
-    sf->tx_size_search_method = frame_is_intra_only(cm) ? USE_FULL_RD
-                                                        : USE_LARGESTALL;
-
-    sf->use_rd_breakout = 1;
-
-    sf->adaptive_motion_search = 1;
-    sf->adaptive_pred_interp_filter = 1;
-    sf->mv.auto_mv_step_size = 1;
-    sf->adaptive_rd_thresh = 2;
-    sf->intra_y_mode_mask[TX_32X32] = INTRA_DC_H_V;
-    sf->intra_uv_mode_mask[TX_32X32] = INTRA_DC_H_V;
-    sf->intra_uv_mode_mask[TX_16X16] = INTRA_DC_H_V;
-  }
-
-  if (speed >= 2) {
-    sf->mode_search_skip_flags = (cm->frame_type == KEY_FRAME) ? 0 :
-                                 FLAG_SKIP_INTRA_DIRMISMATCH |
-                                 FLAG_SKIP_INTRA_BESTINTER |
-                                 FLAG_SKIP_COMP_BESTINTRA |
-                                 FLAG_SKIP_INTRA_LOWVAR;
-    sf->adaptive_pred_interp_filter = 2;
-
-    // Reference masking only enabled for 1 spatial layer, and if none of the
-    // references have been scaled. The latter condition needs to be checked
-    // for external or internal dynamic resize.
-    sf->reference_masking = (cpi->svc.number_spatial_layers == 1);
-    if (sf->reference_masking == 1 &&
-        (cpi->external_resize == 1 ||
-         cpi->oxcf.resize_mode == RESIZE_DYNAMIC)) {
-      MV_REFERENCE_FRAME ref_frame;
-      static const int flag_list[4] =
-          {0, VP9_LAST_FLAG, VP9_GOLD_FLAG, VP9_ALT_FLAG};
-      for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) {
-        const YV12_BUFFER_CONFIG *yv12 = get_ref_frame_buffer(cpi, ref_frame);
-        if (yv12 != NULL && (cpi->ref_frame_flags & flag_list[ref_frame])) {
-          const struct scale_factors *const scale_fac =
-              &cm->frame_refs[ref_frame - 1].sf;
-          if (vp9_is_scaled(scale_fac))
-            sf->reference_masking = 0;
-        }
-      }
-    }
-
-    sf->disable_filter_search_var_thresh = 50;
-    sf->comp_inter_joint_search_thresh = BLOCK_SIZES;
-    sf->auto_min_max_partition_size = RELAXED_NEIGHBORING_MIN_MAX;
-    sf->lf_motion_threshold = LOW_MOTION_THRESHOLD;
-    sf->adjust_partitioning_from_last_frame = 1;
-    sf->last_partitioning_redo_frequency = 3;
-    sf->use_lp32x32fdct = 1;
-    sf->mode_skip_start = 11;
-    sf->intra_y_mode_mask[TX_16X16] = INTRA_DC_H_V;
-  }
-
-  if (speed >= 3) {
-    sf->use_square_partition_only = 1;
-    sf->disable_filter_search_var_thresh = 100;
-    sf->use_uv_intra_rd_estimate = 1;
-    sf->skip_encode_sb = 1;
-    sf->mv.subpel_iters_per_step = 1;
-    sf->adaptive_rd_thresh = 4;
-    sf->mode_skip_start = 6;
-    sf->allow_skip_recode = 0;
-    sf->optimize_coefficients = 0;
-    sf->disable_split_mask = DISABLE_ALL_SPLIT;
-    sf->lpf_pick = LPF_PICK_FROM_Q;
-  }
-
-  if (speed >= 4) {
-    int i;
-    sf->last_partitioning_redo_frequency = 4;
-    sf->adaptive_rd_thresh = 5;
-    sf->use_fast_coef_costing = 0;
-    sf->auto_min_max_partition_size = STRICT_NEIGHBORING_MIN_MAX;
-    sf->adjust_partitioning_from_last_frame =
-        cm->last_frame_type != cm->frame_type || (0 ==
-        (frames_since_key + 1) % sf->last_partitioning_redo_frequency);
-    sf->mv.subpel_force_stop = 1;
-    for (i = 0; i < TX_SIZES; i++) {
-      sf->intra_y_mode_mask[i] = INTRA_DC_H_V;
-      sf->intra_uv_mode_mask[i] = INTRA_DC;
-    }
-    sf->intra_y_mode_mask[TX_32X32] = INTRA_DC;
-    sf->frame_parameter_update = 0;
-    sf->mv.search_method = FAST_HEX;
-
-    sf->inter_mode_mask[BLOCK_32X32] = INTER_NEAREST_NEAR_NEW;
-    sf->inter_mode_mask[BLOCK_32X64] = INTER_NEAREST;
-    sf->inter_mode_mask[BLOCK_64X32] = INTER_NEAREST;
-    sf->inter_mode_mask[BLOCK_64X64] = INTER_NEAREST;
-    sf->max_intra_bsize = BLOCK_32X32;
-    sf->allow_skip_recode = 1;
-  }
-
-  if (speed >= 5) {
-    sf->use_quant_fp = !is_keyframe;
-    sf->auto_min_max_partition_size = is_keyframe ? RELAXED_NEIGHBORING_MIN_MAX
-                                                  : STRICT_NEIGHBORING_MIN_MAX;
-    sf->default_max_partition_size = BLOCK_32X32;
-    sf->default_min_partition_size = BLOCK_8X8;
-    sf->force_frame_boost = is_keyframe ||
-        (frames_since_key % (sf->last_partitioning_redo_frequency << 1) == 1);
-    sf->max_delta_qindex = is_keyframe ? 20 : 15;
-    sf->partition_search_type = REFERENCE_PARTITION;
-    sf->use_nonrd_pick_mode = 1;
-    sf->allow_skip_recode = 0;
-    sf->inter_mode_mask[BLOCK_32X32] = INTER_NEAREST_NEW_ZERO;
-    sf->inter_mode_mask[BLOCK_32X64] = INTER_NEAREST_NEW_ZERO;
-    sf->inter_mode_mask[BLOCK_64X32] = INTER_NEAREST_NEW_ZERO;
-    sf->inter_mode_mask[BLOCK_64X64] = INTER_NEAREST_NEW_ZERO;
-    sf->adaptive_rd_thresh = 2;
-    // This feature is only enabled when partition search is disabled.
-    sf->reuse_inter_pred_sby = 1;
-    sf->partition_search_breakout_rate_thr = 200;
-    sf->coeff_prob_appx_step = 4;
-    sf->use_fast_coef_updates = is_keyframe ? TWO_LOOP : ONE_LOOP_REDUCED;
-    sf->mode_search_skip_flags = FLAG_SKIP_INTRA_DIRMISMATCH;
-    sf->tx_size_search_method = is_keyframe ? USE_LARGESTALL : USE_TX_8X8;
-    sf->simple_model_rd_from_var = 1;
-    if (cpi->oxcf.rc_mode == VPX_VBR)
-      sf->mv.search_method = NSTEP;
-
-    if (!is_keyframe) {
-      int i;
-      if (content == VP9E_CONTENT_SCREEN) {
-        for (i = 0; i < BLOCK_SIZES; ++i)
-          sf->intra_y_mode_bsize_mask[i] = INTRA_DC_TM_H_V;
-      } else {
-        for (i = 0; i < BLOCK_SIZES; ++i)
-          if (i > BLOCK_16X16)
-            sf->intra_y_mode_bsize_mask[i] = INTRA_DC;
-          else
-            // Use H and V intra mode for block sizes <= 16X16.
-            sf->intra_y_mode_bsize_mask[i] = INTRA_DC_H_V;
-      }
-    }
-    if (content == VP9E_CONTENT_SCREEN) {
-      sf->short_circuit_flat_blocks = 1;
-    }
-  }
-
-  if (speed >= 6) {
-    sf->partition_search_type = VAR_BASED_PARTITION;
-    // Turn on this to use non-RD key frame coding mode.
-    sf->use_nonrd_pick_mode = 1;
-    sf->mv.search_method = NSTEP;
-    sf->mv.reduce_first_step_size = 1;
-    sf->skip_encode_sb = 0;
-    if (!cpi->use_svc && cpi->oxcf.rc_mode == VPX_CBR &&
-        content != VP9E_CONTENT_SCREEN) {
-      // Enable short circuit for low temporal variance.
-      sf->short_circuit_low_temp_var = 1;
-    }
-  }
-
-  if (speed >= 7) {
-    sf->adaptive_rd_thresh = 3;
-    sf->mv.search_method = FAST_DIAMOND;
-    sf->mv.fullpel_search_step_param = 10;
-    if (cpi->svc.number_temporal_layers > 2 &&
-        cpi->svc.temporal_layer_id == 0) {
-      sf->mv.search_method = NSTEP;
-      sf->mv.fullpel_search_step_param = 6;
-    }
-  }
-  if (speed >= 8) {
-    sf->adaptive_rd_thresh = 4;
-    sf->mv.subpel_force_stop = (content == VP9E_CONTENT_SCREEN) ? 3 : 2;
-    sf->lpf_pick = LPF_PICK_MINIMAL_LPF;
-    // Only keep INTRA_DC mode for speed 8.
-    if (!is_keyframe) {
-      int i = 0;
-      for (i = 0; i < BLOCK_SIZES; ++i)
-        sf->intra_y_mode_bsize_mask[i] = INTRA_DC;
-    }
-    if (!cpi->use_svc && cpi->oxcf.rc_mode == VPX_CBR &&
-        content != VP9E_CONTENT_SCREEN) {
-      // More aggressive short circuit for speed 8.
-      sf->short_circuit_low_temp_var = 2;
-    }
-  }
-}
-
-void vp9_set_speed_features_framesize_dependent(VP9_COMP *cpi) {
-  SPEED_FEATURES *const sf = &cpi->sf;
-  const VP9EncoderConfig *const oxcf = &cpi->oxcf;
-  RD_OPT *const rd = &cpi->rd;
-  int i;
-
-  if (oxcf->mode == REALTIME) {
-    set_rt_speed_feature_framesize_dependent(cpi, sf, oxcf->speed);
-  } else if (oxcf->mode == GOOD) {
-    set_good_speed_feature_framesize_dependent(cpi, sf, oxcf->speed);
-  }
-
-  if (sf->disable_split_mask == DISABLE_ALL_SPLIT) {
-    sf->adaptive_pred_interp_filter = 0;
-  }
-
-  if (cpi->encode_breakout && oxcf->mode == REALTIME &&
-      sf->encode_breakout_thresh > cpi->encode_breakout) {
-    cpi->encode_breakout = sf->encode_breakout_thresh;
-  }
-
-  // Check for masked out split cases.
-  for (i = 0; i < MAX_REFS; ++i) {
-    if (sf->disable_split_mask & (1 << i)) {
-      rd->thresh_mult_sub8x8[i] = INT_MAX;
-    }
-  }
-}
-
-void vp9_set_speed_features_framesize_independent(VP9_COMP *cpi) {
-  SPEED_FEATURES *const sf = &cpi->sf;
-  VP9_COMMON *const cm = &cpi->common;
-  MACROBLOCK *const x = &cpi->td.mb;
-  const VP9EncoderConfig *const oxcf = &cpi->oxcf;
-  int i;
-
-  // best quality defaults
-  sf->frame_parameter_update = 1;
-  sf->mv.search_method = NSTEP;
-  sf->recode_loop = ALLOW_RECODE;
-  sf->mv.subpel_search_method = SUBPEL_TREE;
-  sf->mv.subpel_iters_per_step = 2;
-  sf->mv.subpel_force_stop = 0;
-  sf->optimize_coefficients = !is_lossless_requested(&cpi->oxcf);
-  sf->mv.reduce_first_step_size = 0;
-  sf->coeff_prob_appx_step = 1;
-  sf->mv.auto_mv_step_size = 0;
-  sf->mv.fullpel_search_step_param = 6;
-  sf->comp_inter_joint_search_thresh = BLOCK_4X4;
-  sf->tx_size_search_method = USE_FULL_RD;
-  sf->use_lp32x32fdct = 0;
-  sf->adaptive_motion_search = 0;
-  sf->adaptive_pred_interp_filter = 0;
-  sf->adaptive_mode_search = 0;
-  sf->cb_pred_filter_search = 0;
-  sf->cb_partition_search = 0;
-  sf->motion_field_mode_search = 0;
-  sf->alt_ref_search_fp = 0;
-  sf->use_quant_fp = 0;
-  sf->reference_masking = 0;
-  sf->partition_search_type = SEARCH_PARTITION;
-  sf->less_rectangular_check = 0;
-  sf->use_square_partition_only = 0;
-  sf->use_square_only_threshold = BLOCK_SIZES;
-  sf->auto_min_max_partition_size = NOT_IN_USE;
-  sf->rd_auto_partition_min_limit = BLOCK_4X4;
-  sf->default_max_partition_size = BLOCK_64X64;
-  sf->default_min_partition_size = BLOCK_4X4;
-  sf->adjust_partitioning_from_last_frame = 0;
-  sf->last_partitioning_redo_frequency = 4;
-  sf->disable_split_mask = 0;
-  sf->mode_search_skip_flags = 0;
-  sf->force_frame_boost = 0;
-  sf->max_delta_qindex = 0;
-  sf->disable_filter_search_var_thresh = 0;
-  sf->adaptive_interp_filter_search = 0;
-  sf->allow_partition_search_skip = 0;
-
-  for (i = 0; i < TX_SIZES; i++) {
-    sf->intra_y_mode_mask[i] = INTRA_ALL;
-    sf->intra_uv_mode_mask[i] = INTRA_ALL;
-  }
-  sf->use_rd_breakout = 0;
-  sf->skip_encode_sb = 0;
-  sf->use_uv_intra_rd_estimate = 0;
-  sf->allow_skip_recode = 0;
-  sf->lpf_pick = LPF_PICK_FROM_FULL_IMAGE;
-  sf->use_fast_coef_updates = TWO_LOOP;
-  sf->use_fast_coef_costing = 0;
-  sf->mode_skip_start = MAX_MODES;  // Mode index at which mode skip mask set
-  sf->schedule_mode_search = 0;
-  sf->use_nonrd_pick_mode = 0;
-  for (i = 0; i < BLOCK_SIZES; ++i)
-    sf->inter_mode_mask[i] = INTER_ALL;
-  sf->max_intra_bsize = BLOCK_64X64;
-  sf->reuse_inter_pred_sby = 0;
-  // This setting only takes effect when partition_search_type is set
-  // to FIXED_PARTITION.
-  sf->always_this_block_size = BLOCK_16X16;
-  sf->search_type_check_frequency = 50;
-  sf->encode_breakout_thresh = 0;
-  // Recode loop tolerance %.
-  sf->recode_tolerance = 25;
-  sf->default_interp_filter = SWITCHABLE;
-  sf->simple_model_rd_from_var = 0;
-  sf->short_circuit_flat_blocks = 0;
-  sf->short_circuit_low_temp_var = 0;
-
-  // Some speed-up features even for best quality as minimal impact on quality.
-  sf->adaptive_rd_thresh = 1;
-  sf->tx_size_search_breakout = 1;
-  sf->partition_search_breakout_dist_thr = (1 << 19);
-  sf->partition_search_breakout_rate_thr = 80;
-
-  if (oxcf->mode == REALTIME)
-    set_rt_speed_feature(cpi, sf, oxcf->speed, oxcf->content);
-  else if (oxcf->mode == GOOD)
-    set_good_speed_feature(cpi, cm, sf, oxcf->speed);
-
-  cpi->full_search_sad = vp9_full_search_sad;
-  cpi->diamond_search_sad = vp9_diamond_search_sad;
-
-  sf->allow_exhaustive_searches = 1;
-  if (oxcf->mode == BEST) {
-    if (cpi->twopass.fr_content_type == FC_GRAPHICS_ANIMATION)
-      sf->exhaustive_searches_thresh = (1 << 20);
-    else
-      sf->exhaustive_searches_thresh = (1 << 21);
-    sf->max_exaustive_pct = 100;
-    for (i = 0; i < MAX_MESH_STEP; ++i) {
-      sf->mesh_patterns[i].range = best_quality_mesh_pattern[i].range;
-      sf->mesh_patterns[i].interval = best_quality_mesh_pattern[i].interval;
-    }
-  } else {
-    int speed = (oxcf->speed > MAX_MESH_SPEED) ? MAX_MESH_SPEED : oxcf->speed;
-    if (cpi->twopass.fr_content_type == FC_GRAPHICS_ANIMATION)
-      sf->exhaustive_searches_thresh = (1 << 22);
-    else
-      sf->exhaustive_searches_thresh = (1 << 23);
-    sf->max_exaustive_pct = good_quality_max_mesh_pct[speed];
-    if (speed > 0)
-      sf->exhaustive_searches_thresh = sf->exhaustive_searches_thresh << 1;
-
-    for (i = 0; i < MAX_MESH_STEP; ++i) {
-      sf->mesh_patterns[i].range =
-          good_quality_mesh_patterns[speed][i].range;
-      sf->mesh_patterns[i].interval =
-          good_quality_mesh_patterns[speed][i].interval;
-    }
-  }
-
-  // Slow quant, dct and trellis not worthwhile for first pass
-  // so make sure they are always turned off.
-  if (oxcf->pass == 1)
-    sf->optimize_coefficients = 0;
-
-  // No recode for 1 pass.
-  if (oxcf->pass == 0) {
-    sf->recode_loop = DISALLOW_RECODE;
-    sf->optimize_coefficients = 0;
-  }
-
-  if (sf->mv.subpel_force_stop == 3) {
-    // Whole pel only
-    cpi->find_fractional_mv_step = vp9_skip_sub_pixel_tree;
-  } else if (sf->mv.subpel_search_method == SUBPEL_TREE) {
-    cpi->find_fractional_mv_step = vp9_find_best_sub_pixel_tree;
-  } else if (sf->mv.subpel_search_method == SUBPEL_TREE_PRUNED) {
-    cpi->find_fractional_mv_step = vp9_find_best_sub_pixel_tree_pruned;
-  } else if (sf->mv.subpel_search_method == SUBPEL_TREE_PRUNED_MORE) {
-    cpi->find_fractional_mv_step = vp9_find_best_sub_pixel_tree_pruned_more;
-  } else if (sf->mv.subpel_search_method == SUBPEL_TREE_PRUNED_EVENMORE) {
-    cpi->find_fractional_mv_step = vp9_find_best_sub_pixel_tree_pruned_evenmore;
-  }
-
-  x->optimize = sf->optimize_coefficients == 1 && oxcf->pass != 1;
-
-  x->min_partition_size = sf->default_min_partition_size;
-  x->max_partition_size = sf->default_max_partition_size;
-
-  if (!cpi->oxcf.frame_periodic_boost) {
-    sf->max_delta_qindex = 0;
-  }
-}
diff --git a/vp9/encoder/vp9_speed_features.h b/vp9/encoder/vp9_speed_features.h
deleted file mode 100644 (file)
index e88a7df..0000000
+++ /dev/null
@@ -1,468 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#ifndef VP9_ENCODER_VP9_SPEED_FEATURES_H_
-#define VP9_ENCODER_VP9_SPEED_FEATURES_H_
-
-#include "vp9/common/vp9_enums.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-enum {
-  INTRA_ALL       = (1 << DC_PRED) |
-                    (1 << V_PRED) | (1 << H_PRED) |
-                    (1 << D45_PRED) | (1 << D135_PRED) |
-                    (1 << D117_PRED) | (1 << D153_PRED) |
-                    (1 << D207_PRED) | (1 << D63_PRED) |
-                    (1 << TM_PRED),
-  INTRA_DC        = (1 << DC_PRED),
-  INTRA_DC_TM     = (1 << DC_PRED) | (1 << TM_PRED),
-  INTRA_DC_H_V    = (1 << DC_PRED) | (1 << V_PRED) | (1 << H_PRED),
-  INTRA_DC_TM_H_V = (1 << DC_PRED) | (1 << TM_PRED) | (1 << V_PRED) |
-                    (1 << H_PRED)
-};
-
-enum {
-  INTER_ALL = (1 << NEARESTMV) | (1 << NEARMV) | (1 << ZEROMV) | (1 << NEWMV),
-  INTER_NEAREST = (1 << NEARESTMV),
-  INTER_NEAREST_NEW = (1 << NEARESTMV) | (1 << NEWMV),
-  INTER_NEAREST_ZERO = (1 << NEARESTMV) | (1 << ZEROMV),
-  INTER_NEAREST_NEW_ZERO = (1 << NEARESTMV) | (1 << ZEROMV) | (1 << NEWMV),
-  INTER_NEAREST_NEAR_NEW = (1 << NEARESTMV) | (1 << NEARMV) | (1 << NEWMV),
-  INTER_NEAREST_NEAR_ZERO = (1 << NEARESTMV) | (1 << NEARMV) | (1 << ZEROMV),
-};
-
-enum {
-  DISABLE_ALL_INTER_SPLIT   = (1 << THR_COMP_GA) |
-                              (1 << THR_COMP_LA) |
-                              (1 << THR_ALTR) |
-                              (1 << THR_GOLD) |
-                              (1 << THR_LAST),
-
-  DISABLE_ALL_SPLIT         = (1 << THR_INTRA) | DISABLE_ALL_INTER_SPLIT,
-
-  DISABLE_COMPOUND_SPLIT    = (1 << THR_COMP_GA) | (1 << THR_COMP_LA),
-
-  LAST_AND_INTRA_SPLIT_ONLY = (1 << THR_COMP_GA) |
-                              (1 << THR_COMP_LA) |
-                              (1 << THR_ALTR) |
-                              (1 << THR_GOLD)
-};
-
-typedef enum {
-  DIAMOND = 0,
-  NSTEP = 1,
-  HEX = 2,
-  BIGDIA = 3,
-  SQUARE = 4,
-  FAST_HEX = 5,
-  FAST_DIAMOND = 6
-} SEARCH_METHODS;
-
-typedef enum {
-  // No recode.
-  DISALLOW_RECODE = 0,
-  // Allow recode for KF and exceeding maximum frame bandwidth.
-  ALLOW_RECODE_KFMAXBW = 1,
-  // Allow recode only for KF/ARF/GF frames.
-  ALLOW_RECODE_KFARFGF = 2,
-  // Allow recode for all frames based on bitrate constraints.
-  ALLOW_RECODE = 3,
-} RECODE_LOOP_TYPE;
-
-typedef enum {
-  SUBPEL_TREE = 0,
-  SUBPEL_TREE_PRUNED = 1,           // Prunes 1/2-pel searches
-  SUBPEL_TREE_PRUNED_MORE = 2,      // Prunes 1/2-pel searches more aggressively
-  SUBPEL_TREE_PRUNED_EVENMORE = 3,  // Prunes 1/2- and 1/4-pel searches
-  // Other methods to come
-} SUBPEL_SEARCH_METHODS;
-
-typedef enum {
-  NO_MOTION_THRESHOLD = 0,
-  LOW_MOTION_THRESHOLD = 7
-} MOTION_THRESHOLD;
-
-typedef enum {
-  USE_FULL_RD = 0,
-  USE_LARGESTALL,
-  USE_TX_8X8
-} TX_SIZE_SEARCH_METHOD;
-
-typedef enum {
-  NOT_IN_USE = 0,
-  RELAXED_NEIGHBORING_MIN_MAX = 1,
-  STRICT_NEIGHBORING_MIN_MAX = 2
-} AUTO_MIN_MAX_MODE;
-
-typedef enum {
-  // Try the full image with different values.
-  LPF_PICK_FROM_FULL_IMAGE,
-  // Try a small portion of the image with different values.
-  LPF_PICK_FROM_SUBIMAGE,
-  // Estimate the level based on quantizer and frame type
-  LPF_PICK_FROM_Q,
-  // Pick 0 to disable LPF if LPF was enabled last frame
-  LPF_PICK_MINIMAL_LPF
-} LPF_PICK_METHOD;
-
-typedef enum {
-  // Terminate search early based on distortion so far compared to
-  // qp step, distortion in the neighborhood of the frame, etc.
-  FLAG_EARLY_TERMINATE = 1 << 0,
-
-  // Skips comp inter modes if the best so far is an intra mode.
-  FLAG_SKIP_COMP_BESTINTRA = 1 << 1,
-
-  // Skips oblique intra modes if the best so far is an inter mode.
-  FLAG_SKIP_INTRA_BESTINTER = 1 << 3,
-
-  // Skips oblique intra modes  at angles 27, 63, 117, 153 if the best
-  // intra so far is not one of the neighboring directions.
-  FLAG_SKIP_INTRA_DIRMISMATCH = 1 << 4,
-
-  // Skips intra modes other than DC_PRED if the source variance is small
-  FLAG_SKIP_INTRA_LOWVAR = 1 << 5,
-} MODE_SEARCH_SKIP_LOGIC;
-
-typedef enum {
-  FLAG_SKIP_EIGHTTAP = 1 << EIGHTTAP,
-  FLAG_SKIP_EIGHTTAP_SMOOTH = 1 << EIGHTTAP_SMOOTH,
-  FLAG_SKIP_EIGHTTAP_SHARP = 1 << EIGHTTAP_SHARP,
-} INTERP_FILTER_MASK;
-
-typedef enum {
-  // Search partitions using RD/NONRD criterion
-  SEARCH_PARTITION,
-
-  // Always use a fixed size partition
-  FIXED_PARTITION,
-
-  REFERENCE_PARTITION,
-
-  // Use an arbitrary partitioning scheme based on source variance within
-  // a 64X64 SB
-  VAR_BASED_PARTITION,
-
-  // Use non-fixed partitions based on source variance
-  SOURCE_VAR_BASED_PARTITION
-} PARTITION_SEARCH_TYPE;
-
-typedef enum {
-  // Does a dry run to see if any of the contexts need to be updated or not,
-  // before the final run.
-  TWO_LOOP = 0,
-
-  // No dry run, also only half the coef contexts and bands are updated.
-  // The rest are not updated at all.
-  ONE_LOOP_REDUCED = 1
-} FAST_COEFF_UPDATE;
-
-typedef struct MV_SPEED_FEATURES {
-  // Motion search method (Diamond, NSTEP, Hex, Big Diamond, Square, etc).
-  SEARCH_METHODS search_method;
-
-  // This parameter controls which step in the n-step process we start at.
-  // It's changed adaptively based on circumstances.
-  int reduce_first_step_size;
-
-  // If this is set to 1, we limit the motion search range to 2 times the
-  // largest motion vector found in the last frame.
-  int auto_mv_step_size;
-
-  // Subpel_search_method can only be subpel_tree which does a subpixel
-  // logarithmic search that keeps stepping at 1/2 pixel units until
-  // you stop getting a gain, and then goes on to 1/4 and repeats
-  // the same process. Along the way it skips many diagonals.
-  SUBPEL_SEARCH_METHODS subpel_search_method;
-
-  // Maximum number of steps in logarithmic subpel search before giving up.
-  int subpel_iters_per_step;
-
-  // Control when to stop subpel search:
-  // 0: Full subpel search.
-  // 1: Stop at quarter pixel.
-  // 2: Stop at half pixel.
-  // 3: Stop at full pixel.
-  int subpel_force_stop;
-
-  // This variable sets the step_param used in full pel motion search.
-  int fullpel_search_step_param;
-} MV_SPEED_FEATURES;
-
-#define MAX_MESH_STEP 4
-
-typedef struct MESH_PATTERN {
-  int range;
-  int interval;
-} MESH_PATTERN;
-
-typedef struct SPEED_FEATURES {
-  MV_SPEED_FEATURES mv;
-
-  // Frame level coding parameter update
-  int frame_parameter_update;
-
-  RECODE_LOOP_TYPE recode_loop;
-
-  // Trellis (dynamic programming) optimization of quantized values (+1, 0).
-  int optimize_coefficients;
-
-  // Always set to 0. If on it enables 0 cost background transmission
-  // (except for the initial transmission of the segmentation). The feature is
-  // disabled because the addition of very large block sizes make the
-  // backgrounds very to cheap to encode, and the segmentation we have
-  // adds overhead.
-  int static_segmentation;
-
-  // If 1 we iterate finding a best reference for 2 ref frames together - via
-  // a log search that iterates 4 times (check around mv for last for best
-  // error of combined predictor then check around mv for alt). If 0 we
-  // we just use the best motion vector found for each frame by itself.
-  BLOCK_SIZE comp_inter_joint_search_thresh;
-
-  // This variable is used to cap the maximum number of times we skip testing a
-  // mode to be evaluated. A high value means we will be faster.
-  int adaptive_rd_thresh;
-
-  // Enables skipping the reconstruction step (idct, recon) in the
-  // intermediate steps assuming the last frame didn't have too many intra
-  // blocks and the q is less than a threshold.
-  int skip_encode_sb;
-  int skip_encode_frame;
-  // Speed feature to allow or disallow skipping of recode at block
-  // level within a frame.
-  int allow_skip_recode;
-
-  // Coefficient probability model approximation step size
-  int coeff_prob_appx_step;
-
-  // The threshold is to determine how slow the motino is, it is used when
-  // use_lastframe_partitioning is set to LAST_FRAME_PARTITION_LOW_MOTION
-  MOTION_THRESHOLD lf_motion_threshold;
-
-  // Determine which method we use to determine transform size. We can choose
-  // between options like full rd, largest for prediction size, largest
-  // for intra and model coefs for the rest.
-  TX_SIZE_SEARCH_METHOD tx_size_search_method;
-
-  // Low precision 32x32 fdct keeps everything in 16 bits and thus is less
-  // precise but significantly faster than the non lp version.
-  int use_lp32x32fdct;
-
-  // After looking at the first set of modes (set by index here), skip
-  // checking modes for reference frames that don't match the reference frame
-  // of the best so far.
-  int mode_skip_start;
-
-  // TODO(JBB): Remove this.
-  int reference_masking;
-
-  PARTITION_SEARCH_TYPE partition_search_type;
-
-  // Used if partition_search_type = FIXED_SIZE_PARTITION
-  BLOCK_SIZE always_this_block_size;
-
-  // Skip rectangular partition test when partition type none gives better
-  // rd than partition type split.
-  int less_rectangular_check;
-
-  // Disable testing non square partitions. (eg 16x32)
-  int use_square_partition_only;
-  BLOCK_SIZE use_square_only_threshold;
-
-  // Sets min and max partition sizes for this 64x64 region based on the
-  // same 64x64 in last encoded frame, and the left and above neighbor.
-  AUTO_MIN_MAX_MODE auto_min_max_partition_size;
-  // Ensures the rd based auto partition search will always
-  // go down at least to the specified level.
-  BLOCK_SIZE rd_auto_partition_min_limit;
-
-  // Min and max partition size we enable (block_size) as per auto
-  // min max, but also used by adjust partitioning, and pick_partitioning.
-  BLOCK_SIZE default_min_partition_size;
-  BLOCK_SIZE default_max_partition_size;
-
-  // Whether or not we allow partitions one smaller or one greater than the last
-  // frame's partitioning. Only used if use_lastframe_partitioning is set.
-  int adjust_partitioning_from_last_frame;
-
-  // How frequently we re do the partitioning from scratch. Only used if
-  // use_lastframe_partitioning is set.
-  int last_partitioning_redo_frequency;
-
-  // Disables sub 8x8 blocksizes in different scenarios: Choices are to disable
-  // it always, to allow it for only Last frame and Intra, disable it for all
-  // inter modes or to enable it always.
-  int disable_split_mask;
-
-  // TODO(jingning): combine the related motion search speed features
-  // This allows us to use motion search at other sizes as a starting
-  // point for this motion search and limits the search range around it.
-  int adaptive_motion_search;
-
-  // Flag for allowing some use of exhaustive searches;
-  int allow_exhaustive_searches;
-
-  // Threshold for allowing exhaistive motion search.
-  int exhaustive_searches_thresh;
-
-  // Maximum number of exhaustive searches for a frame.
-  int max_exaustive_pct;
-
-  // Pattern to be used for any exhaustive mesh searches.
-  MESH_PATTERN mesh_patterns[MAX_MESH_STEP];
-
-  int schedule_mode_search;
-
-  // Allows sub 8x8 modes to use the prediction filter that was determined
-  // best for 8x8 mode. If set to 0 we always re check all the filters for
-  // sizes less than 8x8, 1 means we check all filter modes if no 8x8 filter
-  // was selected, and 2 means we use 8 tap if no 8x8 filter mode was selected.
-  int adaptive_pred_interp_filter;
-
-  // Adaptive prediction mode search
-  int adaptive_mode_search;
-
-  // Chessboard pattern prediction filter type search
-  int cb_pred_filter_search;
-
-  int cb_partition_search;
-
-  int motion_field_mode_search;
-
-  int alt_ref_search_fp;
-
-  // Fast quantization process path
-  int use_quant_fp;
-
-  // Use finer quantizer in every other few frames that run variable block
-  // partition type search.
-  int force_frame_boost;
-
-  // Maximally allowed base quantization index fluctuation.
-  int max_delta_qindex;
-
-  // Implements various heuristics to skip searching modes
-  // The heuristics selected are based on  flags
-  // defined in the MODE_SEARCH_SKIP_HEURISTICS enum
-  unsigned int mode_search_skip_flags;
-
-  // A source variance threshold below which filter search is disabled
-  // Choose a very large value (UINT_MAX) to use 8-tap always
-  unsigned int disable_filter_search_var_thresh;
-
-  // These bit masks allow you to enable or disable intra modes for each
-  // transform size separately.
-  int intra_y_mode_mask[TX_SIZES];
-  int intra_uv_mode_mask[TX_SIZES];
-
-  // These bit masks allow you to enable or disable intra modes for each
-  // prediction block size separately.
-  int intra_y_mode_bsize_mask[BLOCK_SIZES];
-
-  // This variable enables an early break out of mode testing if the model for
-  // rd built from the prediction signal indicates a value that's much
-  // higher than the best rd we've seen so far.
-  int use_rd_breakout;
-
-  // This enables us to use an estimate for intra rd based on dc mode rather
-  // than choosing an actual uv mode in the stage of encoding before the actual
-  // final encode.
-  int use_uv_intra_rd_estimate;
-
-  // This feature controls how the loop filter level is determined.
-  LPF_PICK_METHOD lpf_pick;
-
-  // This feature limits the number of coefficients updates we actually do
-  // by only looking at counts from 1/2 the bands.
-  FAST_COEFF_UPDATE use_fast_coef_updates;
-
-  // This flag controls the use of non-RD mode decision.
-  int use_nonrd_pick_mode;
-
-  // A binary mask indicating if NEARESTMV, NEARMV, ZEROMV, NEWMV
-  // modes are used in order from LSB to MSB for each BLOCK_SIZE.
-  int inter_mode_mask[BLOCK_SIZES];
-
-  // This feature controls whether we do the expensive context update and
-  // calculation in the rd coefficient costing loop.
-  int use_fast_coef_costing;
-
-  // This feature controls the tolerence vs target used in deciding whether to
-  // recode a frame. It has no meaning if recode is disabled.
-  int recode_tolerance;
-
-  // This variable controls the maximum block size where intra blocks can be
-  // used in inter frames.
-  // TODO(aconverse): Fold this into one of the other many mode skips
-  BLOCK_SIZE max_intra_bsize;
-
-  // The frequency that we check if SOURCE_VAR_BASED_PARTITION or
-  // FIXED_PARTITION search type should be used.
-  int search_type_check_frequency;
-
-  // When partition is pre-set, the inter prediction result from pick_inter_mode
-  // can be reused in final block encoding process. It is enabled only for real-
-  // time mode speed 6.
-  int reuse_inter_pred_sby;
-
-  // This variable sets the encode_breakout threshold. Currently, it is only
-  // enabled in real time mode.
-  int encode_breakout_thresh;
-
-  // default interp filter choice
-  INTERP_FILTER default_interp_filter;
-
-  // Early termination in transform size search, which only applies while
-  // tx_size_search_method is USE_FULL_RD.
-  int tx_size_search_breakout;
-
-  // adaptive interp_filter search to allow skip of certain filter types.
-  int adaptive_interp_filter_search;
-
-  // mask for skip evaluation of certain interp_filter type.
-  INTERP_FILTER_MASK interp_filter_search_mask;
-
-  // Partition search early breakout thresholds.
-  int64_t partition_search_breakout_dist_thr;
-  int partition_search_breakout_rate_thr;
-
-  // Allow skipping partition search for still image frame
-  int allow_partition_search_skip;
-
-  // Fast approximation of vp9_model_rd_from_var_lapndz
-  int simple_model_rd_from_var;
-
-  // Skip a number of expensive mode evaluations for blocks with zero source
-  // variance.
-  int short_circuit_flat_blocks;
-
-  // Skip a number of expensive mode evaluations for blocks with very low
-  // temporal variance.
-  // 1: Skip golden non-zeromv and ALL INTRA for bsize >= 32x32.
-  // 2: Skip golden non-zeromv and newmv-last for bsize >= 16x16, skip ALL
-  // INTRA for bsize >= 32x32 and vert/horz INTRA for bsize 16x16, 16x32 and
-  // 32x16.
-  int short_circuit_low_temp_var;
-} SPEED_FEATURES;
-
-struct VP9_COMP;
-
-void vp9_set_speed_features_framesize_independent(struct VP9_COMP *cpi);
-void vp9_set_speed_features_framesize_dependent(struct VP9_COMP *cpi);
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP9_ENCODER_VP9_SPEED_FEATURES_H_
diff --git a/vp9/encoder/vp9_subexp.c b/vp9/encoder/vp9_subexp.c
deleted file mode 100644 (file)
index 29db015..0000000
+++ /dev/null
@@ -1,198 +0,0 @@
-/*
- *  Copyright (c) 2013 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.
- */
-#include "vpx_dsp/bitwriter.h"
-
-#include "vp9/common/vp9_common.h"
-#include "vp9/common/vp9_entropy.h"
-#include "vp9/encoder/vp9_cost.h"
-#include "vp9/encoder/vp9_subexp.h"
-
-static const uint8_t update_bits[255] = {
-   5,  5,  5,  5,  5,  5,  5,  5,  5,  5,  5,  5,  5,  5,  5,  5,
-   6,  6,  6,  6,  6,  6,  6,  6,  6,  6,  6,  6,  6,  6,  6,  6,
-   8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,
-   8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,
-  10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
-  10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
-  10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
-  10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
-  10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
-  11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
-  11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
-  11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
-  11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
-  11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
-  11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
-  11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,  0,
-};
-#define MIN_DELP_BITS 5
-
-static int recenter_nonneg(int v, int m) {
-  if (v > (m << 1))
-    return v;
-  else if (v >= m)
-    return ((v - m) << 1);
-  else
-    return ((m - v) << 1) - 1;
-}
-
-static int remap_prob(int v, int m) {
-  int i;
-  static const uint8_t map_table[MAX_PROB - 1] = {
-    // generated by:
-    //   map_table[j] = split_index(j, MAX_PROB - 1, MODULUS_PARAM);
-     20,  21,  22,  23,  24,  25,   0,  26,  27,  28,  29,  30,  31,  32,  33,
-     34,  35,  36,  37,   1,  38,  39,  40,  41,  42,  43,  44,  45,  46,  47,
-     48,  49,   2,  50,  51,  52,  53,  54,  55,  56,  57,  58,  59,  60,  61,
-      3,  62,  63,  64,  65,  66,  67,  68,  69,  70,  71,  72,  73,   4,  74,
-     75,  76,  77,  78,  79,  80,  81,  82,  83,  84,  85,   5,  86,  87,  88,
-     89,  90,  91,  92,  93,  94,  95,  96,  97,   6,  98,  99, 100, 101, 102,
-    103, 104, 105, 106, 107, 108, 109,   7, 110, 111, 112, 113, 114, 115, 116,
-    117, 118, 119, 120, 121,   8, 122, 123, 124, 125, 126, 127, 128, 129, 130,
-    131, 132, 133,   9, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144,
-    145,  10, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157,  11,
-    158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169,  12, 170, 171,
-    172, 173, 174, 175, 176, 177, 178, 179, 180, 181,  13, 182, 183, 184, 185,
-    186, 187, 188, 189, 190, 191, 192, 193,  14, 194, 195, 196, 197, 198, 199,
-    200, 201, 202, 203, 204, 205,  15, 206, 207, 208, 209, 210, 211, 212, 213,
-    214, 215, 216, 217,  16, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227,
-    228, 229,  17, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241,
-     18, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253,  19,
-  };
-  v--;
-  m--;
-  if ((m << 1) <= MAX_PROB)
-    i = recenter_nonneg(v, m) - 1;
-  else
-    i = recenter_nonneg(MAX_PROB - 1 - v, MAX_PROB - 1 - m) - 1;
-
-  i = map_table[i];
-  return i;
-}
-
-static int prob_diff_update_cost(vpx_prob newp, vpx_prob oldp) {
-  int delp = remap_prob(newp, oldp);
-  return update_bits[delp] << VP9_PROB_COST_SHIFT;
-}
-
-static void encode_uniform(vpx_writer *w, int v) {
-  const int l = 8;
-  const int m = (1 << l) - 191;
-  if (v < m) {
-    vpx_write_literal(w, v, l - 1);
-  } else {
-    vpx_write_literal(w, m + ((v - m) >> 1), l - 1);
-    vpx_write_literal(w, (v - m) & 1, 1);
-  }
-}
-
-static INLINE int write_bit_gte(vpx_writer *w, int word, int test) {
-  vpx_write_literal(w, word >= test, 1);
-  return word >= test;
-}
-
-static void encode_term_subexp(vpx_writer *w, int word) {
-  if (!write_bit_gte(w, word, 16)) {
-    vpx_write_literal(w, word, 4);
-  } else if (!write_bit_gte(w, word, 32)) {
-    vpx_write_literal(w, word - 16, 4);
-  } else if (!write_bit_gte(w, word, 64)) {
-    vpx_write_literal(w, word - 32, 5);
-  } else {
-    encode_uniform(w, word - 64);
-  }
-}
-
-void vp9_write_prob_diff_update(vpx_writer *w, vpx_prob newp, vpx_prob oldp) {
-  const int delp = remap_prob(newp, oldp);
-  encode_term_subexp(w, delp);
-}
-
-int vp9_prob_diff_update_savings_search(const unsigned int *ct,
-                                        vpx_prob oldp, vpx_prob *bestp,
-                                        vpx_prob upd) {
-  const int old_b = cost_branch256(ct, oldp);
-  int bestsavings = 0;
-  vpx_prob newp, bestnewp = oldp;
-  const int step = *bestp > oldp ? -1 : 1;
-  const int upd_cost = vp9_cost_one(upd) - vp9_cost_zero(upd);
-
-  if (old_b > upd_cost + (MIN_DELP_BITS << VP9_PROB_COST_SHIFT)) {
-    for (newp = *bestp; newp != oldp; newp += step) {
-      const int new_b = cost_branch256(ct, newp);
-      const int update_b = prob_diff_update_cost(newp, oldp) + upd_cost;
-      const int savings = old_b - new_b - update_b;
-      if (savings > bestsavings) {
-        bestsavings = savings;
-        bestnewp = newp;
-      }
-    }
-  }
-  *bestp = bestnewp;
-  return bestsavings;
-}
-
-int vp9_prob_diff_update_savings_search_model(const unsigned int *ct,
-                                              const vpx_prob oldp,
-                                              vpx_prob *bestp,
-                                              vpx_prob upd,
-                                              int stepsize) {
-  int i, old_b, new_b, update_b, savings, bestsavings;
-  int newp;
-  const int step_sign = *bestp > oldp ? -1 : 1;
-  const int step = stepsize * step_sign;
-  const int upd_cost = vp9_cost_one(upd) - vp9_cost_zero(upd);
-  const vpx_prob *newplist, *oldplist;
-  vpx_prob bestnewp;
-  oldplist = vp9_pareto8_full[oldp - 1];
-  old_b = cost_branch256(ct + 2 * PIVOT_NODE, oldp);
-  for (i = UNCONSTRAINED_NODES; i < ENTROPY_NODES; ++i)
-    old_b += cost_branch256(ct + 2 * i, oldplist[i - UNCONSTRAINED_NODES]);
-
-  bestsavings = 0;
-  bestnewp = oldp;
-
-  assert(stepsize > 0);
-
-  if (old_b > upd_cost + (MIN_DELP_BITS << VP9_PROB_COST_SHIFT)) {
-    for (newp = *bestp; (newp - oldp) * step_sign < 0; newp += step) {
-      if (newp < 1 || newp > 255) continue;
-      newplist = vp9_pareto8_full[newp - 1];
-      new_b = cost_branch256(ct + 2 * PIVOT_NODE, newp);
-      for (i = UNCONSTRAINED_NODES; i < ENTROPY_NODES; ++i)
-        new_b += cost_branch256(ct + 2 * i, newplist[i - UNCONSTRAINED_NODES]);
-      update_b = prob_diff_update_cost(newp, oldp) + upd_cost;
-      savings = old_b - new_b - update_b;
-      if (savings > bestsavings) {
-        bestsavings = savings;
-        bestnewp = newp;
-      }
-    }
-  }
-
-  *bestp = bestnewp;
-  return bestsavings;
-}
-
-void vp9_cond_prob_diff_update(vpx_writer *w, vpx_prob *oldp,
-                               const unsigned int ct[2]) {
-  const vpx_prob upd = DIFF_UPDATE_PROB;
-  vpx_prob newp = get_binary_prob(ct[0], ct[1]);
-  const int savings = vp9_prob_diff_update_savings_search(ct, *oldp, &newp,
-                                                          upd);
-  assert(newp >= 1);
-  if (savings > 0) {
-    vpx_write(w, 1, upd);
-    vp9_write_prob_diff_update(w, newp, *oldp);
-    *oldp = newp;
-  } else {
-    vpx_write(w, 0, upd);
-  }
-}
diff --git a/vp9/encoder/vp9_subexp.h b/vp9/encoder/vp9_subexp.h
deleted file mode 100644 (file)
index efe62c0..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- *  Copyright (c) 2013 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.
- */
-
-
-#ifndef VP9_ENCODER_VP9_SUBEXP_H_
-#define VP9_ENCODER_VP9_SUBEXP_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include "vpx_dsp/prob.h"
-
-struct vpx_writer;
-
-void vp9_write_prob_diff_update(struct vpx_writer *w,
-                                vpx_prob newp, vpx_prob oldp);
-
-void vp9_cond_prob_diff_update(struct vpx_writer *w, vpx_prob *oldp,
-                               const unsigned int ct[2]);
-
-int vp9_prob_diff_update_savings_search(const unsigned int *ct,
-                                        vpx_prob oldp, vpx_prob *bestp,
-                                        vpx_prob upd);
-
-
-int vp9_prob_diff_update_savings_search_model(const unsigned int *ct,
-                                              const vpx_prob oldp,
-                                              vpx_prob *bestp,
-                                              vpx_prob upd,
-                                              int stepsize);
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP9_ENCODER_VP9_SUBEXP_H_
diff --git a/vp9/encoder/vp9_svc_layercontext.c b/vp9/encoder/vp9_svc_layercontext.c
deleted file mode 100644 (file)
index 1814a32..0000000
+++ /dev/null
@@ -1,842 +0,0 @@
-/*
- *  Copyright (c) 2014 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.
- */
-
-#include <math.h>
-
-#include "vp9/encoder/vp9_aq_cyclicrefresh.h"
-#include "vp9/encoder/vp9_encoder.h"
-#include "vp9/encoder/vp9_svc_layercontext.h"
-#include "vp9/encoder/vp9_extend.h"
-#include "vpx_dsp/vpx_dsp_common.h"
-
-#define SMALL_FRAME_WIDTH  32
-#define SMALL_FRAME_HEIGHT 16
-
-void vp9_init_layer_context(VP9_COMP *const cpi) {
-  SVC *const svc = &cpi->svc;
-  const VP9EncoderConfig *const oxcf = &cpi->oxcf;
-  int mi_rows = cpi->common.mi_rows;
-  int mi_cols = cpi->common.mi_cols;
-  int sl, tl, i;
-  int alt_ref_idx = svc->number_spatial_layers;
-
-  svc->spatial_layer_id = 0;
-  svc->temporal_layer_id = 0;
-  svc->first_spatial_layer_to_encode = 0;
-  svc->rc_drop_superframe = 0;
-  svc->force_zero_mode_spatial_ref = 0;
-  svc->use_base_mv = 0;
-  svc->current_superframe = 0;
-  for (i = 0; i < REF_FRAMES; ++i)
-    svc->ref_frame_index[i] = -1;
-  for (sl = 0; sl < oxcf->ss_number_layers; ++sl) {
-    cpi->svc.ext_frame_flags[sl] = 0;
-    cpi->svc.ext_lst_fb_idx[sl] = 0;
-    cpi->svc.ext_gld_fb_idx[sl] = 1;
-    cpi->svc.ext_alt_fb_idx[sl] = 2;
-  }
-
-  // For 1 pass cbr: allocate scaled_frame that may be used as an intermediate
-  // buffer for a 2 stage down-sampling: two stages of 1:2 down-sampling for a
-  // target of 1/4x1/4.
-  if (cpi->oxcf.pass == 0 && cpi->oxcf.rc_mode == VPX_CBR) {
-    if (vpx_realloc_frame_buffer(&cpi->svc.scaled_temp,
-                                 cpi->common.width >> 1,
-                                 cpi->common.height >> 1,
-                                 cpi->common.subsampling_x,
-                                 cpi->common.subsampling_y,
-#if CONFIG_VP9_HIGHBITDEPTH
-                                 cpi->common.use_highbitdepth,
-#endif
-                                 VP9_ENC_BORDER_IN_PIXELS,
-                                 cpi->common.byte_alignment,
-                                 NULL, NULL, NULL))
-      vpx_internal_error(&cpi->common.error, VPX_CODEC_MEM_ERROR,
-                         "Failed to allocate scaled_frame for svc ");
-  }
-
-
-  if (cpi->oxcf.error_resilient_mode == 0 && cpi->oxcf.pass == 2) {
-    if (vpx_realloc_frame_buffer(&cpi->svc.empty_frame.img,
-                                 SMALL_FRAME_WIDTH, SMALL_FRAME_HEIGHT,
-                                 cpi->common.subsampling_x,
-                                 cpi->common.subsampling_y,
-#if CONFIG_VP9_HIGHBITDEPTH
-                                 cpi->common.use_highbitdepth,
-#endif
-                                 VP9_ENC_BORDER_IN_PIXELS,
-                                 cpi->common.byte_alignment,
-                                 NULL, NULL, NULL))
-      vpx_internal_error(&cpi->common.error, VPX_CODEC_MEM_ERROR,
-                         "Failed to allocate empty frame for multiple frame "
-                         "contexts");
-
-    memset(cpi->svc.empty_frame.img.buffer_alloc, 0x80,
-           cpi->svc.empty_frame.img.buffer_alloc_sz);
-  }
-
-  for (sl = 0; sl < oxcf->ss_number_layers; ++sl) {
-    for (tl = 0; tl < oxcf->ts_number_layers; ++tl) {
-      int layer = LAYER_IDS_TO_IDX(sl, tl, oxcf->ts_number_layers);
-      LAYER_CONTEXT *const lc = &svc->layer_context[layer];
-      RATE_CONTROL *const lrc = &lc->rc;
-      int i;
-      lc->current_video_frame_in_layer = 0;
-      lc->layer_size = 0;
-      lc->frames_from_key_frame = 0;
-      lc->last_frame_type = FRAME_TYPES;
-      lrc->ni_av_qi = oxcf->worst_allowed_q;
-      lrc->total_actual_bits = 0;
-      lrc->total_target_vs_actual = 0;
-      lrc->ni_tot_qi = 0;
-      lrc->tot_q = 0.0;
-      lrc->avg_q = 0.0;
-      lrc->ni_frames = 0;
-      lrc->decimation_count = 0;
-      lrc->decimation_factor = 0;
-
-      for (i = 0; i < RATE_FACTOR_LEVELS; ++i) {
-        lrc->rate_correction_factors[i] = 1.0;
-      }
-
-      if (cpi->oxcf.rc_mode == VPX_CBR) {
-        lc->target_bandwidth = oxcf->layer_target_bitrate[layer];
-        lrc->last_q[INTER_FRAME] = oxcf->worst_allowed_q;
-        lrc->avg_frame_qindex[INTER_FRAME] = oxcf->worst_allowed_q;
-        lrc->avg_frame_qindex[KEY_FRAME] = oxcf->worst_allowed_q;
-      } else {
-        lc->target_bandwidth = oxcf->layer_target_bitrate[layer];
-        lrc->last_q[KEY_FRAME] = oxcf->best_allowed_q;
-        lrc->last_q[INTER_FRAME] = oxcf->best_allowed_q;
-        lrc->avg_frame_qindex[KEY_FRAME] = (oxcf->worst_allowed_q +
-                                            oxcf->best_allowed_q) / 2;
-        lrc->avg_frame_qindex[INTER_FRAME] = (oxcf->worst_allowed_q +
-                                              oxcf->best_allowed_q) / 2;
-        if (oxcf->ss_enable_auto_arf[sl])
-          lc->alt_ref_idx = alt_ref_idx++;
-        else
-          lc->alt_ref_idx = INVALID_IDX;
-        lc->gold_ref_idx = INVALID_IDX;
-      }
-
-      lrc->buffer_level = oxcf->starting_buffer_level_ms *
-                              lc->target_bandwidth / 1000;
-      lrc->bits_off_target = lrc->buffer_level;
-
-      // Initialize the cyclic refresh parameters. If spatial layers are used
-      // (i.e., ss_number_layers > 1), these need to be updated per spatial
-      // layer.
-      // Cyclic refresh is only applied on base temporal layer.
-      if (oxcf->ss_number_layers > 1 &&
-          tl == 0) {
-        size_t last_coded_q_map_size;
-        size_t consec_zero_mv_size;
-        VP9_COMMON *const cm = &cpi->common;
-        lc->sb_index = 0;
-        CHECK_MEM_ERROR(cm, lc->map,
-                        vpx_malloc(mi_rows * mi_cols * sizeof(*lc->map)));
-        memset(lc->map, 0, mi_rows * mi_cols);
-        last_coded_q_map_size = mi_rows * mi_cols *
-                                sizeof(*lc->last_coded_q_map);
-        CHECK_MEM_ERROR(cm, lc->last_coded_q_map,
-                        vpx_malloc(last_coded_q_map_size));
-        assert(MAXQ <= 255);
-        memset(lc->last_coded_q_map, MAXQ, last_coded_q_map_size);
-        consec_zero_mv_size = mi_rows * mi_cols * sizeof(*lc->consec_zero_mv);
-        CHECK_MEM_ERROR(cm, lc->consec_zero_mv,
-                        vpx_malloc(consec_zero_mv_size));
-        memset(lc->consec_zero_mv, 0, consec_zero_mv_size);
-       }
-    }
-  }
-
-  // Still have extra buffer for base layer golden frame
-  if (!(svc->number_temporal_layers > 1 && cpi->oxcf.rc_mode == VPX_CBR)
-      && alt_ref_idx < REF_FRAMES)
-    svc->layer_context[0].gold_ref_idx = alt_ref_idx;
-}
-
-// Update the layer context from a change_config() call.
-void vp9_update_layer_context_change_config(VP9_COMP *const cpi,
-                                            const int target_bandwidth) {
-  SVC *const svc = &cpi->svc;
-  const VP9EncoderConfig *const oxcf = &cpi->oxcf;
-  const RATE_CONTROL *const rc = &cpi->rc;
-  int sl, tl, layer = 0, spatial_layer_target;
-  float bitrate_alloc = 1.0;
-
-  if (svc->temporal_layering_mode != VP9E_TEMPORAL_LAYERING_MODE_NOLAYERING) {
-    for (sl = 0; sl < oxcf->ss_number_layers; ++sl) {
-      for (tl = 0; tl < oxcf->ts_number_layers; ++tl) {
-        layer = LAYER_IDS_TO_IDX(sl, tl, oxcf->ts_number_layers);
-        svc->layer_context[layer].target_bandwidth =
-            oxcf->layer_target_bitrate[layer];
-      }
-
-      layer = LAYER_IDS_TO_IDX(sl, ((oxcf->ts_number_layers - 1) < 0 ?
-          0 : (oxcf->ts_number_layers - 1)), oxcf->ts_number_layers);
-      spatial_layer_target =
-          svc->layer_context[layer].target_bandwidth =
-              oxcf->layer_target_bitrate[layer];
-
-      for (tl = 0; tl < oxcf->ts_number_layers; ++tl) {
-        LAYER_CONTEXT *const lc =
-            &svc->layer_context[sl * oxcf->ts_number_layers + tl];
-        RATE_CONTROL *const lrc = &lc->rc;
-
-        lc->spatial_layer_target_bandwidth = spatial_layer_target;
-        bitrate_alloc = (float)lc->target_bandwidth / spatial_layer_target;
-        lrc->starting_buffer_level =
-            (int64_t)(rc->starting_buffer_level * bitrate_alloc);
-        lrc->optimal_buffer_level =
-            (int64_t)(rc->optimal_buffer_level * bitrate_alloc);
-        lrc->maximum_buffer_size =
-            (int64_t)(rc->maximum_buffer_size * bitrate_alloc);
-        lrc->bits_off_target =
-            VPXMIN(lrc->bits_off_target, lrc->maximum_buffer_size);
-        lrc->buffer_level = VPXMIN(lrc->buffer_level, lrc->maximum_buffer_size);
-        lc->framerate = cpi->framerate / oxcf->ts_rate_decimator[tl];
-        lrc->avg_frame_bandwidth = (int)(lc->target_bandwidth / lc->framerate);
-        lrc->max_frame_bandwidth = rc->max_frame_bandwidth;
-        lrc->worst_quality = rc->worst_quality;
-        lrc->best_quality = rc->best_quality;
-      }
-    }
-  } else {
-    int layer_end;
-
-    if (svc->number_temporal_layers > 1 && cpi->oxcf.rc_mode == VPX_CBR) {
-      layer_end = svc->number_temporal_layers;
-    } else {
-      layer_end = svc->number_spatial_layers;
-    }
-
-    for (layer = 0; layer < layer_end; ++layer) {
-      LAYER_CONTEXT *const lc = &svc->layer_context[layer];
-      RATE_CONTROL *const lrc = &lc->rc;
-
-      lc->target_bandwidth = oxcf->layer_target_bitrate[layer];
-
-      bitrate_alloc = (float)lc->target_bandwidth / target_bandwidth;
-      // Update buffer-related quantities.
-      lrc->starting_buffer_level =
-          (int64_t)(rc->starting_buffer_level * bitrate_alloc);
-      lrc->optimal_buffer_level =
-          (int64_t)(rc->optimal_buffer_level * bitrate_alloc);
-      lrc->maximum_buffer_size =
-          (int64_t)(rc->maximum_buffer_size * bitrate_alloc);
-      lrc->bits_off_target = VPXMIN(lrc->bits_off_target,
-                                    lrc->maximum_buffer_size);
-      lrc->buffer_level = VPXMIN(lrc->buffer_level, lrc->maximum_buffer_size);
-      // Update framerate-related quantities.
-      if (svc->number_temporal_layers > 1 && cpi->oxcf.rc_mode == VPX_CBR) {
-        lc->framerate = cpi->framerate / oxcf->ts_rate_decimator[layer];
-      } else {
-        lc->framerate = cpi->framerate;
-      }
-      lrc->avg_frame_bandwidth = (int)(lc->target_bandwidth / lc->framerate);
-      lrc->max_frame_bandwidth = rc->max_frame_bandwidth;
-      // Update qp-related quantities.
-      lrc->worst_quality = rc->worst_quality;
-      lrc->best_quality = rc->best_quality;
-    }
-  }
-}
-
-static LAYER_CONTEXT *get_layer_context(VP9_COMP *const cpi) {
-  if (is_one_pass_cbr_svc(cpi))
-    return &cpi->svc.layer_context[cpi->svc.spatial_layer_id *
-        cpi->svc.number_temporal_layers + cpi->svc.temporal_layer_id];
-  else
-    return (cpi->svc.number_temporal_layers > 1 &&
-            cpi->oxcf.rc_mode == VPX_CBR) ?
-             &cpi->svc.layer_context[cpi->svc.temporal_layer_id] :
-             &cpi->svc.layer_context[cpi->svc.spatial_layer_id];
-}
-
-void vp9_update_temporal_layer_framerate(VP9_COMP *const cpi) {
-  SVC *const svc = &cpi->svc;
-  const VP9EncoderConfig *const oxcf = &cpi->oxcf;
-  LAYER_CONTEXT *const lc = get_layer_context(cpi);
-  RATE_CONTROL *const lrc = &lc->rc;
-  // Index into spatial+temporal arrays.
-  const int st_idx = svc->spatial_layer_id * svc->number_temporal_layers +
-      svc->temporal_layer_id;
-  const int tl = svc->temporal_layer_id;
-
-  lc->framerate = cpi->framerate / oxcf->ts_rate_decimator[tl];
-  lrc->avg_frame_bandwidth = (int)(lc->target_bandwidth / lc->framerate);
-  lrc->max_frame_bandwidth = cpi->rc.max_frame_bandwidth;
-  // Update the average layer frame size (non-cumulative per-frame-bw).
-  if (tl == 0) {
-    lc->avg_frame_size = lrc->avg_frame_bandwidth;
-  } else {
-    const double prev_layer_framerate =
-        cpi->framerate / oxcf->ts_rate_decimator[tl - 1];
-    const int prev_layer_target_bandwidth =
-        oxcf->layer_target_bitrate[st_idx - 1];
-    lc->avg_frame_size =
-        (int)((lc->target_bandwidth - prev_layer_target_bandwidth) /
-              (lc->framerate - prev_layer_framerate));
-  }
-}
-
-void vp9_update_spatial_layer_framerate(VP9_COMP *const cpi, double framerate) {
-  const VP9EncoderConfig *const oxcf = &cpi->oxcf;
-  LAYER_CONTEXT *const lc = get_layer_context(cpi);
-  RATE_CONTROL *const lrc = &lc->rc;
-
-  lc->framerate = framerate;
-  lrc->avg_frame_bandwidth = (int)(lc->target_bandwidth / lc->framerate);
-  lrc->min_frame_bandwidth = (int)(lrc->avg_frame_bandwidth *
-                                   oxcf->two_pass_vbrmin_section / 100);
-  lrc->max_frame_bandwidth = (int)(((int64_t)lrc->avg_frame_bandwidth *
-                                   oxcf->two_pass_vbrmax_section) / 100);
-  vp9_rc_set_gf_interval_range(cpi, lrc);
-}
-
-void vp9_restore_layer_context(VP9_COMP *const cpi) {
-  LAYER_CONTEXT *const lc = get_layer_context(cpi);
-  const int old_frame_since_key = cpi->rc.frames_since_key;
-  const int old_frame_to_key = cpi->rc.frames_to_key;
-
-  cpi->rc = lc->rc;
-  cpi->twopass = lc->twopass;
-  cpi->oxcf.target_bandwidth = lc->target_bandwidth;
-  cpi->alt_ref_source = lc->alt_ref_source;
-  // Reset the frames_since_key and frames_to_key counters to their values
-  // before the layer restore. Keep these defined for the stream (not layer).
-  if (cpi->svc.number_temporal_layers > 1 ||
-      (cpi->svc.number_spatial_layers > 1 && !is_two_pass_svc(cpi))) {
-    cpi->rc.frames_since_key = old_frame_since_key;
-    cpi->rc.frames_to_key = old_frame_to_key;
-  }
-
-  // For spatial-svc, allow cyclic-refresh to be applied on the spatial layers,
-  // for the base temporal layer.
-  if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ &&
-      cpi->svc.number_spatial_layers > 1 &&
-      cpi->svc.temporal_layer_id == 0) {
-    CYCLIC_REFRESH *const cr = cpi->cyclic_refresh;
-    signed char *temp = cr->map;
-    uint8_t *temp2 = cr->last_coded_q_map;
-    uint8_t *temp3 = cpi->consec_zero_mv;
-    cr->map = lc->map;
-    lc->map = temp;
-    cr->last_coded_q_map = lc->last_coded_q_map;
-    lc->last_coded_q_map = temp2;
-    cpi->consec_zero_mv = lc->consec_zero_mv;
-    lc->consec_zero_mv = temp3;
-    cr->sb_index = lc->sb_index;
-  }
-}
-
-void vp9_save_layer_context(VP9_COMP *const cpi) {
-  const VP9EncoderConfig *const oxcf = &cpi->oxcf;
-  LAYER_CONTEXT *const lc = get_layer_context(cpi);
-
-  lc->rc = cpi->rc;
-  lc->twopass = cpi->twopass;
-  lc->target_bandwidth = (int)oxcf->target_bandwidth;
-  lc->alt_ref_source = cpi->alt_ref_source;
-
-  // For spatial-svc, allow cyclic-refresh to be applied on the spatial layers,
-  // for the base temporal layer.
-  if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ &&
-      cpi->svc.number_spatial_layers > 1 &&
-      cpi->svc.temporal_layer_id == 0) {
-    CYCLIC_REFRESH *const cr = cpi->cyclic_refresh;
-    signed char *temp = lc->map;
-    uint8_t *temp2 = lc->last_coded_q_map;
-    uint8_t *temp3 = lc->consec_zero_mv;
-    lc->map = cr->map;
-    cr->map = temp;
-    lc->last_coded_q_map = cr->last_coded_q_map;
-    cr->last_coded_q_map = temp2;
-    lc->consec_zero_mv = cpi->consec_zero_mv;
-    cpi->consec_zero_mv = temp3;
-    lc->sb_index = cr->sb_index;
-  }
-}
-
-void vp9_init_second_pass_spatial_svc(VP9_COMP *cpi) {
-  SVC *const svc = &cpi->svc;
-  int i;
-
-  for (i = 0; i < svc->number_spatial_layers; ++i) {
-    TWO_PASS *const twopass = &svc->layer_context[i].twopass;
-
-    svc->spatial_layer_id = i;
-    vp9_init_second_pass(cpi);
-
-    twopass->total_stats.spatial_layer_id = i;
-    twopass->total_left_stats.spatial_layer_id = i;
-  }
-  svc->spatial_layer_id = 0;
-}
-
-void vp9_inc_frame_in_layer(VP9_COMP *const cpi) {
-  LAYER_CONTEXT *const lc =
-      &cpi->svc.layer_context[cpi->svc.spatial_layer_id *
-                              cpi->svc.number_temporal_layers];
-  ++lc->current_video_frame_in_layer;
-  ++lc->frames_from_key_frame;
-  if (cpi->svc.spatial_layer_id == cpi->svc.number_spatial_layers - 1)
-    ++cpi->svc.current_superframe;
-}
-
-int vp9_is_upper_layer_key_frame(const VP9_COMP *const cpi) {
-  return is_two_pass_svc(cpi) &&
-         cpi->svc.spatial_layer_id > 0 &&
-         cpi->svc.layer_context[cpi->svc.spatial_layer_id *
-                                cpi->svc.number_temporal_layers +
-                                cpi->svc.temporal_layer_id].is_key_frame;
-}
-
-static void get_layer_resolution(const int width_org, const int height_org,
-                                 const int num, const int den,
-                                 int *width_out, int *height_out) {
-  int w, h;
-
-  if (width_out == NULL || height_out == NULL || den == 0)
-    return;
-
-  w = width_org * num / den;
-  h = height_org * num / den;
-
-  // make height and width even to make chrome player happy
-  w += w % 2;
-  h += h % 2;
-
-  *width_out = w;
-  *height_out = h;
-}
-
-// The function sets proper ref_frame_flags, buffer indices, and buffer update
-// variables for temporal layering mode 3 - that does 0-2-1-2 temporal layering
-// scheme.
-static void set_flags_and_fb_idx_for_temporal_mode3(VP9_COMP *const cpi) {
-  int frame_num_within_temporal_struct = 0;
-  int spatial_id, temporal_id;
-  spatial_id = cpi->svc.spatial_layer_id = cpi->svc.spatial_layer_to_encode;
-  frame_num_within_temporal_struct =
-      cpi->svc.layer_context[cpi->svc.spatial_layer_id *
-      cpi->svc.number_temporal_layers].current_video_frame_in_layer % 4;
-  temporal_id = cpi->svc.temporal_layer_id =
-      (frame_num_within_temporal_struct & 1) ? 2 :
-      (frame_num_within_temporal_struct >> 1);
-  cpi->ext_refresh_last_frame = cpi->ext_refresh_golden_frame =
-      cpi->ext_refresh_alt_ref_frame = 0;
-  if (!temporal_id) {
-    cpi->ext_refresh_frame_flags_pending = 1;
-    cpi->ext_refresh_last_frame = 1;
-    if (!spatial_id) {
-      cpi->ref_frame_flags = VP9_LAST_FLAG;
-    } else if (cpi->svc.layer_context[temporal_id].is_key_frame) {
-      // base layer is a key frame.
-      cpi->ref_frame_flags = VP9_LAST_FLAG;
-      cpi->ext_refresh_last_frame = 0;
-      cpi->ext_refresh_golden_frame = 1;
-    } else {
-      cpi->ref_frame_flags = VP9_LAST_FLAG | VP9_GOLD_FLAG;
-    }
-  } else if (temporal_id == 1) {
-    cpi->ext_refresh_frame_flags_pending = 1;
-    cpi->ext_refresh_alt_ref_frame = 1;
-    if (!spatial_id) {
-      cpi->ref_frame_flags = VP9_LAST_FLAG;
-    } else {
-      cpi->ref_frame_flags = VP9_LAST_FLAG | VP9_GOLD_FLAG;
-    }
-  } else {
-    if (frame_num_within_temporal_struct == 1) {
-      // the first tl2 picture
-      if (spatial_id == cpi->svc.number_spatial_layers - 1) {  // top layer
-        cpi->ext_refresh_frame_flags_pending = 1;
-        if (!spatial_id)
-          cpi->ref_frame_flags = VP9_LAST_FLAG;
-        else
-          cpi->ref_frame_flags = VP9_LAST_FLAG | VP9_GOLD_FLAG;
-      } else if (!spatial_id) {
-        cpi->ext_refresh_frame_flags_pending = 1;
-        cpi->ext_refresh_alt_ref_frame = 1;
-        cpi->ref_frame_flags = VP9_LAST_FLAG;
-      } else if (spatial_id < cpi->svc.number_spatial_layers - 1) {
-        cpi->ext_refresh_frame_flags_pending = 1;
-        cpi->ext_refresh_alt_ref_frame = 1;
-        cpi->ref_frame_flags = VP9_LAST_FLAG | VP9_GOLD_FLAG;
-      }
-    } else {
-      //  The second tl2 picture
-      if (spatial_id == cpi->svc.number_spatial_layers - 1) {  // top layer
-        cpi->ext_refresh_frame_flags_pending = 1;
-        if (!spatial_id)
-        cpi->ref_frame_flags = VP9_LAST_FLAG;
-        else
-          cpi->ref_frame_flags = VP9_LAST_FLAG | VP9_GOLD_FLAG;
-      } else if (!spatial_id) {
-        cpi->ext_refresh_frame_flags_pending = 1;
-        cpi->ref_frame_flags = VP9_LAST_FLAG;
-        cpi->ext_refresh_alt_ref_frame = 1;
-      } else {  // top layer
-        cpi->ext_refresh_frame_flags_pending = 1;
-        cpi->ref_frame_flags = VP9_LAST_FLAG | VP9_GOLD_FLAG;
-        cpi->ext_refresh_alt_ref_frame = 1;
-      }
-    }
-  }
-  if (temporal_id == 0) {
-    cpi->lst_fb_idx = spatial_id;
-    if (spatial_id) {
-      if (cpi->svc.layer_context[temporal_id].is_key_frame) {
-        cpi->lst_fb_idx = spatial_id - 1;
-        cpi->gld_fb_idx = spatial_id;
-      } else {
-      cpi->gld_fb_idx = spatial_id - 1;
-      }
-    } else {
-      cpi->gld_fb_idx = 0;
-    }
-    cpi->alt_fb_idx = 0;
-  } else if (temporal_id == 1) {
-    cpi->lst_fb_idx = spatial_id;
-    cpi->gld_fb_idx = cpi->svc.number_spatial_layers + spatial_id - 1;
-    cpi->alt_fb_idx = cpi->svc.number_spatial_layers + spatial_id;
-  } else if (frame_num_within_temporal_struct == 1) {
-    cpi->lst_fb_idx = spatial_id;
-    cpi->gld_fb_idx = cpi->svc.number_spatial_layers + spatial_id - 1;
-    cpi->alt_fb_idx = cpi->svc.number_spatial_layers + spatial_id;
-  } else {
-    cpi->lst_fb_idx = cpi->svc.number_spatial_layers + spatial_id;
-    cpi->gld_fb_idx = cpi->svc.number_spatial_layers + spatial_id - 1;
-    cpi->alt_fb_idx = cpi->svc.number_spatial_layers + spatial_id;
-  }
-}
-
-// The function sets proper ref_frame_flags, buffer indices, and buffer update
-// variables for temporal layering mode 2 - that does 0-1-0-1 temporal layering
-// scheme.
-static void set_flags_and_fb_idx_for_temporal_mode2(VP9_COMP *const cpi) {
-  int spatial_id, temporal_id;
-  spatial_id = cpi->svc.spatial_layer_id = cpi->svc.spatial_layer_to_encode;
-  temporal_id = cpi->svc.temporal_layer_id =
-      cpi->svc.layer_context[cpi->svc.spatial_layer_id *
-      cpi->svc.number_temporal_layers].current_video_frame_in_layer & 1;
-  cpi->ext_refresh_last_frame = cpi->ext_refresh_golden_frame =
-                                cpi->ext_refresh_alt_ref_frame = 0;
-  if (!temporal_id) {
-    cpi->ext_refresh_frame_flags_pending = 1;
-    cpi->ext_refresh_last_frame = 1;
-    if (!spatial_id) {
-      cpi->ref_frame_flags = VP9_LAST_FLAG;
-    } else if (cpi->svc.layer_context[temporal_id].is_key_frame) {
-      // base layer is a key frame.
-      cpi->ref_frame_flags = VP9_LAST_FLAG;
-      cpi->ext_refresh_last_frame = 0;
-      cpi->ext_refresh_golden_frame = 1;
-    } else {
-      cpi->ref_frame_flags = VP9_LAST_FLAG | VP9_GOLD_FLAG;
-    }
-  } else if (temporal_id == 1) {
-    cpi->ext_refresh_frame_flags_pending = 1;
-    cpi->ext_refresh_alt_ref_frame = 1;
-    if (!spatial_id) {
-      cpi->ref_frame_flags = VP9_LAST_FLAG;
-    } else {
-      cpi->ref_frame_flags = VP9_LAST_FLAG | VP9_GOLD_FLAG;
-    }
-  }
-
-  if (temporal_id == 0) {
-    cpi->lst_fb_idx = spatial_id;
-    if (spatial_id) {
-      if (cpi->svc.layer_context[temporal_id].is_key_frame) {
-        cpi->lst_fb_idx = spatial_id - 1;
-        cpi->gld_fb_idx = spatial_id;
-      } else {
-      cpi->gld_fb_idx = spatial_id - 1;
-      }
-    } else {
-      cpi->gld_fb_idx = 0;
-    }
-    cpi->alt_fb_idx = 0;
-  } else if (temporal_id == 1) {
-    cpi->lst_fb_idx = spatial_id;
-    cpi->gld_fb_idx = cpi->svc.number_spatial_layers + spatial_id - 1;
-    cpi->alt_fb_idx = cpi->svc.number_spatial_layers + spatial_id;
-  }
-}
-
-// The function sets proper ref_frame_flags, buffer indices, and buffer update
-// variables for temporal layering mode 0 - that has no temporal layering.
-static void set_flags_and_fb_idx_for_temporal_mode_noLayering(
-    VP9_COMP *const cpi) {
-  int spatial_id;
-  spatial_id = cpi->svc.spatial_layer_id = cpi->svc.spatial_layer_to_encode;
-  cpi->ext_refresh_last_frame =
-      cpi->ext_refresh_golden_frame = cpi->ext_refresh_alt_ref_frame = 0;
-  cpi->ext_refresh_frame_flags_pending = 1;
-  cpi->ext_refresh_last_frame = 1;
-  if (!spatial_id) {
-    cpi->ref_frame_flags = VP9_LAST_FLAG;
-  } else if (cpi->svc.layer_context[0].is_key_frame) {
-    cpi->ref_frame_flags = VP9_LAST_FLAG;
-    cpi->ext_refresh_last_frame = 0;
-    cpi->ext_refresh_golden_frame = 1;
-  } else {
-    cpi->ref_frame_flags = VP9_LAST_FLAG | VP9_GOLD_FLAG;
-  }
-  cpi->lst_fb_idx = spatial_id;
-  if (spatial_id) {
-    if (cpi->svc.layer_context[0].is_key_frame) {
-      cpi->lst_fb_idx = spatial_id - 1;
-      cpi->gld_fb_idx = spatial_id;
-    } else {
-    cpi->gld_fb_idx = spatial_id - 1;
-    }
-  } else {
-    cpi->gld_fb_idx = 0;
-  }
-}
-
-int vp9_one_pass_cbr_svc_start_layer(VP9_COMP *const cpi) {
-  int width = 0, height = 0;
-  LAYER_CONTEXT *lc = NULL;
-  if (cpi->svc.number_spatial_layers > 1)
-    cpi->svc.use_base_mv = 1;
-  cpi->svc.force_zero_mode_spatial_ref = 1;
-
-  if (cpi->svc.temporal_layering_mode == VP9E_TEMPORAL_LAYERING_MODE_0212) {
-    set_flags_and_fb_idx_for_temporal_mode3(cpi);
-  } else if (cpi->svc.temporal_layering_mode ==
-           VP9E_TEMPORAL_LAYERING_MODE_NOLAYERING) {
-    set_flags_and_fb_idx_for_temporal_mode_noLayering(cpi);
-  } else if (cpi->svc.temporal_layering_mode ==
-           VP9E_TEMPORAL_LAYERING_MODE_0101) {
-    set_flags_and_fb_idx_for_temporal_mode2(cpi);
-  } else if (cpi->svc.temporal_layering_mode ==
-      VP9E_TEMPORAL_LAYERING_MODE_BYPASS) {
-    // In the BYPASS/flexible mode, the encoder is relying on the application
-    // to specify, for each spatial layer, the flags and buffer indices for the
-    // layering.
-    // Note that the check (cpi->ext_refresh_frame_flags_pending == 0) is
-    // needed to support the case where the frame flags may be passed in via
-    // vpx_codec_encode(), which can be used for the temporal-only svc case.
-    // TODO(marpan): Consider adding an enc_config parameter to better handle
-    // this case.
-    if (cpi->ext_refresh_frame_flags_pending == 0) {
-      int sl;
-      cpi->svc.spatial_layer_id = cpi->svc.spatial_layer_to_encode;
-      sl = cpi->svc.spatial_layer_id;
-      vp9_apply_encoding_flags(cpi, cpi->svc.ext_frame_flags[sl]);
-      cpi->lst_fb_idx = cpi->svc.ext_lst_fb_idx[sl];
-      cpi->gld_fb_idx = cpi->svc.ext_gld_fb_idx[sl];
-      cpi->alt_fb_idx = cpi->svc.ext_alt_fb_idx[sl];
-    }
-  }
-
-  if (cpi->svc.spatial_layer_id == cpi->svc.first_spatial_layer_to_encode)
-    cpi->svc.rc_drop_superframe = 0;
-
-  lc = &cpi->svc.layer_context[cpi->svc.spatial_layer_id *
-                               cpi->svc.number_temporal_layers +
-                               cpi->svc.temporal_layer_id];
-
-  // Setting the worst/best_quality via the encoder control: SET_SVC_PARAMETERS,
-  // only for non-BYPASS mode for now.
-  if (cpi->svc.temporal_layering_mode != VP9E_TEMPORAL_LAYERING_MODE_BYPASS) {
-    RATE_CONTROL *const lrc = &lc->rc;
-    lrc->worst_quality = vp9_quantizer_to_qindex(lc->max_q);
-    lrc->best_quality =  vp9_quantizer_to_qindex(lc->min_q);
-  }
-
-  get_layer_resolution(cpi->oxcf.width, cpi->oxcf.height,
-                       lc->scaling_factor_num, lc->scaling_factor_den,
-                       &width, &height);
-
-  if (vp9_set_size_literal(cpi, width, height) != 0)
-    return VPX_CODEC_INVALID_PARAM;
-
-  return 0;
-}
-
-#if CONFIG_SPATIAL_SVC
-#define SMALL_FRAME_FB_IDX 7
-
-int vp9_svc_start_frame(VP9_COMP *const cpi) {
-  int width = 0, height = 0;
-  LAYER_CONTEXT *lc;
-  struct lookahead_entry *buf;
-  int count = 1 << (cpi->svc.number_temporal_layers - 1);
-
-  cpi->svc.spatial_layer_id = cpi->svc.spatial_layer_to_encode;
-  lc = &cpi->svc.layer_context[cpi->svc.spatial_layer_id];
-
-  cpi->svc.temporal_layer_id = 0;
-  while ((lc->current_video_frame_in_layer % count) != 0) {
-    ++cpi->svc.temporal_layer_id;
-    count >>= 1;
-  }
-
-  cpi->ref_frame_flags = VP9_ALT_FLAG | VP9_GOLD_FLAG | VP9_LAST_FLAG;
-
-  cpi->lst_fb_idx = cpi->svc.spatial_layer_id;
-
-  if (cpi->svc.spatial_layer_id == 0)
-    cpi->gld_fb_idx = (lc->gold_ref_idx >= 0) ?
-                      lc->gold_ref_idx : cpi->lst_fb_idx;
-  else
-    cpi->gld_fb_idx = cpi->svc.spatial_layer_id - 1;
-
-  if (lc->current_video_frame_in_layer == 0) {
-    if (cpi->svc.spatial_layer_id >= 2) {
-      cpi->alt_fb_idx = cpi->svc.spatial_layer_id - 2;
-    } else {
-      cpi->alt_fb_idx = cpi->lst_fb_idx;
-      cpi->ref_frame_flags &= (~VP9_LAST_FLAG & ~VP9_ALT_FLAG);
-    }
-  } else {
-    if (cpi->oxcf.ss_enable_auto_arf[cpi->svc.spatial_layer_id]) {
-      cpi->alt_fb_idx = lc->alt_ref_idx;
-      if (!lc->has_alt_frame)
-        cpi->ref_frame_flags &= (~VP9_ALT_FLAG);
-    } else {
-      // Find a proper alt_fb_idx for layers that don't have alt ref frame
-      if (cpi->svc.spatial_layer_id == 0) {
-        cpi->alt_fb_idx = cpi->lst_fb_idx;
-      } else {
-        LAYER_CONTEXT *lc_lower =
-            &cpi->svc.layer_context[cpi->svc.spatial_layer_id - 1];
-
-        if (cpi->oxcf.ss_enable_auto_arf[cpi->svc.spatial_layer_id - 1] &&
-            lc_lower->alt_ref_source != NULL)
-          cpi->alt_fb_idx = lc_lower->alt_ref_idx;
-        else if (cpi->svc.spatial_layer_id >= 2)
-          cpi->alt_fb_idx = cpi->svc.spatial_layer_id - 2;
-        else
-          cpi->alt_fb_idx = cpi->lst_fb_idx;
-      }
-    }
-  }
-
-  get_layer_resolution(cpi->oxcf.width, cpi->oxcf.height,
-                       lc->scaling_factor_num, lc->scaling_factor_den,
-                       &width, &height);
-
-  // Workaround for multiple frame contexts. In some frames we can't use prev_mi
-  // since its previous frame could be changed during decoding time. The idea is
-  // we put a empty invisible frame in front of them, then we will not use
-  // prev_mi when encoding these frames.
-
-  buf = vp9_lookahead_peek(cpi->lookahead, 0);
-  if (cpi->oxcf.error_resilient_mode == 0 && cpi->oxcf.pass == 2 &&
-      cpi->svc.encode_empty_frame_state == NEED_TO_ENCODE &&
-      lc->rc.frames_to_key != 0 &&
-      !(buf != NULL && (buf->flags & VPX_EFLAG_FORCE_KF))) {
-    if ((cpi->svc.number_temporal_layers > 1 &&
-         cpi->svc.temporal_layer_id < cpi->svc.number_temporal_layers - 1) ||
-        (cpi->svc.number_spatial_layers > 1 &&
-         cpi->svc.spatial_layer_id == 0)) {
-      struct lookahead_entry *buf = vp9_lookahead_peek(cpi->lookahead, 0);
-
-      if (buf != NULL) {
-        cpi->svc.empty_frame.ts_start = buf->ts_start;
-        cpi->svc.empty_frame.ts_end = buf->ts_end;
-        cpi->svc.encode_empty_frame_state = ENCODING;
-        cpi->common.show_frame = 0;
-        cpi->ref_frame_flags = 0;
-        cpi->common.frame_type = INTER_FRAME;
-        cpi->lst_fb_idx =
-            cpi->gld_fb_idx = cpi->alt_fb_idx = SMALL_FRAME_FB_IDX;
-
-        if (cpi->svc.encode_intra_empty_frame != 0)
-          cpi->common.intra_only = 1;
-
-        width = SMALL_FRAME_WIDTH;
-        height = SMALL_FRAME_HEIGHT;
-      }
-    }
-  }
-
-  cpi->oxcf.worst_allowed_q = vp9_quantizer_to_qindex(lc->max_q);
-  cpi->oxcf.best_allowed_q = vp9_quantizer_to_qindex(lc->min_q);
-
-  vp9_change_config(cpi, &cpi->oxcf);
-
-  if (vp9_set_size_literal(cpi, width, height) != 0)
-    return VPX_CODEC_INVALID_PARAM;
-
-  vp9_set_high_precision_mv(cpi, 1);
-
-  cpi->alt_ref_source = get_layer_context(cpi)->alt_ref_source;
-
-  return 0;
-}
-
-#undef SMALL_FRAME_FB_IDX
-#endif  // CONFIG_SPATIAL_SVC
-
-struct lookahead_entry *vp9_svc_lookahead_pop(VP9_COMP *const cpi,
-                                              struct lookahead_ctx *ctx,
-                                              int drain) {
-  struct lookahead_entry *buf = NULL;
-  if (ctx->sz && (drain || ctx->sz == ctx->max_sz - MAX_PRE_FRAMES)) {
-    buf = vp9_lookahead_peek(ctx, 0);
-    if (buf != NULL) {
-      // Only remove the buffer when pop the highest layer.
-      if (cpi->svc.spatial_layer_id == cpi->svc.number_spatial_layers - 1) {
-        vp9_lookahead_pop(ctx, drain);
-      }
-    }
-  }
-  return buf;
-}
-
-void vp9_free_svc_cyclic_refresh(VP9_COMP *const cpi) {
-  int sl, tl;
-  SVC *const svc = &cpi->svc;
-  const VP9EncoderConfig *const oxcf = &cpi->oxcf;
-  for (sl = 0; sl < oxcf->ss_number_layers; ++sl) {
-    for (tl = 0; tl < oxcf->ts_number_layers; ++tl) {
-      int layer = LAYER_IDS_TO_IDX(sl, tl, oxcf->ts_number_layers);
-      LAYER_CONTEXT *const lc = &svc->layer_context[layer];
-        if (lc->map)
-          vpx_free(lc->map);
-        if (lc->last_coded_q_map)
-          vpx_free(lc->last_coded_q_map);
-        if (lc->consec_zero_mv)
-          vpx_free(lc->consec_zero_mv);
-    }
-  }
-}
-
-// Reset on key frame: reset counters, references and buffer updates.
-void vp9_svc_reset_key_frame(VP9_COMP *const cpi) {
-  int sl, tl;
-  SVC *const svc = &cpi->svc;
-  LAYER_CONTEXT *lc = NULL;
-  for (sl = 0; sl < svc->number_spatial_layers; ++sl) {
-    for (tl = 0; tl < svc->number_temporal_layers; ++tl) {
-      lc = &cpi->svc.layer_context[sl * svc->number_temporal_layers + tl];
-      lc->current_video_frame_in_layer = 0;
-      lc->frames_from_key_frame = 0;
-    }
-  }
-  if (svc->temporal_layering_mode == VP9E_TEMPORAL_LAYERING_MODE_0212) {
-    set_flags_and_fb_idx_for_temporal_mode3(cpi);
-  } else if (svc->temporal_layering_mode ==
-             VP9E_TEMPORAL_LAYERING_MODE_NOLAYERING) {
-     set_flags_and_fb_idx_for_temporal_mode_noLayering(cpi);
-  } else if (svc->temporal_layering_mode == VP9E_TEMPORAL_LAYERING_MODE_0101) {
-     set_flags_and_fb_idx_for_temporal_mode2(cpi);
-  }
-  vp9_update_temporal_layer_framerate(cpi);
-  vp9_restore_layer_context(cpi);
-}
diff --git a/vp9/encoder/vp9_svc_layercontext.h b/vp9/encoder/vp9_svc_layercontext.h
deleted file mode 100644 (file)
index 9f386fb..0000000
+++ /dev/null
@@ -1,145 +0,0 @@
-/*
- *  Copyright (c) 2014 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.
- */
-
-#ifndef VP9_ENCODER_VP9_SVC_LAYERCONTEXT_H_
-#define VP9_ENCODER_VP9_SVC_LAYERCONTEXT_H_
-
-#include "vpx/vpx_encoder.h"
-
-#include "vp9/encoder/vp9_ratectrl.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef struct {
-  RATE_CONTROL rc;
-  int target_bandwidth;
-  int spatial_layer_target_bandwidth;  // Target for the spatial layer.
-  double framerate;
-  int avg_frame_size;
-  int max_q;
-  int min_q;
-  int scaling_factor_num;
-  int scaling_factor_den;
-  TWO_PASS twopass;
-  vpx_fixed_buf_t rc_twopass_stats_in;
-  unsigned int current_video_frame_in_layer;
-  int is_key_frame;
-  int frames_from_key_frame;
-  FRAME_TYPE last_frame_type;
-  struct lookahead_entry  *alt_ref_source;
-  int alt_ref_idx;
-  int gold_ref_idx;
-  int has_alt_frame;
-  size_t layer_size;
-  struct vpx_psnr_pkt psnr_pkt;
-  // Cyclic refresh parameters (aq-mode=3), that need to be updated per-frame.
-  int sb_index;
-  signed char *map;
-  uint8_t *last_coded_q_map;
-  uint8_t *consec_zero_mv;
-} LAYER_CONTEXT;
-
-typedef struct {
-  int spatial_layer_id;
-  int temporal_layer_id;
-  int number_spatial_layers;
-  int number_temporal_layers;
-
-  int spatial_layer_to_encode;
-  int first_spatial_layer_to_encode;
-  int rc_drop_superframe;
-
-  // Workaround for multiple frame contexts
-  enum {
-    ENCODED = 0,
-    ENCODING,
-    NEED_TO_ENCODE
-  }encode_empty_frame_state;
-  struct lookahead_entry empty_frame;
-  int encode_intra_empty_frame;
-
-  // Store scaled source frames to be used for temporal filter to generate
-  // a alt ref frame.
-  YV12_BUFFER_CONFIG scaled_frames[MAX_LAG_BUFFERS];
-  // Temp buffer used for 2-stage down-sampling, for real-time mode.
-  YV12_BUFFER_CONFIG scaled_temp;
-
-  // Layer context used for rate control in one pass temporal CBR mode or
-  // two pass spatial mode.
-  LAYER_CONTEXT layer_context[VPX_MAX_LAYERS];
-  // Indicates what sort of temporal layering is used.
-  // Currently, this only works for CBR mode.
-  VP9E_TEMPORAL_LAYERING_MODE temporal_layering_mode;
-  // Frame flags and buffer indexes for each spatial layer, set by the
-  // application (external settings).
-  int ext_frame_flags[VPX_MAX_LAYERS];
-  int ext_lst_fb_idx[VPX_MAX_LAYERS];
-  int ext_gld_fb_idx[VPX_MAX_LAYERS];
-  int ext_alt_fb_idx[VPX_MAX_LAYERS];
-  int ref_frame_index[REF_FRAMES];
-  int force_zero_mode_spatial_ref;
-  int current_superframe;
-  int use_base_mv;
-} SVC;
-
-struct VP9_COMP;
-
-// Initialize layer context data from init_config().
-void vp9_init_layer_context(struct VP9_COMP *const cpi);
-
-// Update the layer context from a change_config() call.
-void vp9_update_layer_context_change_config(struct VP9_COMP *const cpi,
-                                            const int target_bandwidth);
-
-// Prior to encoding the frame, update framerate-related quantities
-// for the current temporal layer.
-void vp9_update_temporal_layer_framerate(struct VP9_COMP *const cpi);
-
-// Update framerate-related quantities for the current spatial layer.
-void vp9_update_spatial_layer_framerate(struct VP9_COMP *const cpi,
-                                        double framerate);
-
-// Prior to encoding the frame, set the layer context, for the current layer
-// to be encoded, to the cpi struct.
-void vp9_restore_layer_context(struct VP9_COMP *const cpi);
-
-// Save the layer context after encoding the frame.
-void vp9_save_layer_context(struct VP9_COMP *const cpi);
-
-// Initialize second pass rc for spatial svc.
-void vp9_init_second_pass_spatial_svc(struct VP9_COMP *cpi);
-
-// Increment number of video frames in layer
-void vp9_inc_frame_in_layer(struct VP9_COMP *const cpi);
-
-// Check if current layer is key frame in spatial upper layer
-int vp9_is_upper_layer_key_frame(const struct VP9_COMP *const cpi);
-
-// Get the next source buffer to encode
-struct lookahead_entry *vp9_svc_lookahead_pop(struct VP9_COMP *const cpi,
-                                              struct lookahead_ctx *ctx,
-                                              int drain);
-
-// Start a frame and initialize svc parameters
-int vp9_svc_start_frame(struct VP9_COMP *const cpi);
-
-int vp9_one_pass_cbr_svc_start_layer(struct VP9_COMP *const cpi);
-
-void vp9_free_svc_cyclic_refresh(struct VP9_COMP *const cpi);
-
-void vp9_svc_reset_key_frame(struct VP9_COMP *const cpi);
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP9_ENCODER_VP9_SVC_LAYERCONTEXT_
diff --git a/vp9/encoder/vp9_temporal_filter.c b/vp9/encoder/vp9_temporal_filter.c
deleted file mode 100644 (file)
index 02bcf5a..0000000
+++ /dev/null
@@ -1,797 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#include <math.h>
-#include <limits.h>
-
-#include "vp9/common/vp9_alloccommon.h"
-#include "vp9/common/vp9_onyxc_int.h"
-#include "vp9/common/vp9_quant_common.h"
-#include "vp9/common/vp9_reconinter.h"
-#include "vp9/encoder/vp9_extend.h"
-#include "vp9/encoder/vp9_firstpass.h"
-#include "vp9/encoder/vp9_mcomp.h"
-#include "vp9/encoder/vp9_encoder.h"
-#include "vp9/encoder/vp9_quantize.h"
-#include "vp9/encoder/vp9_ratectrl.h"
-#include "vp9/encoder/vp9_segmentation.h"
-#include "vp9/encoder/vp9_temporal_filter.h"
-#include "vpx_dsp/vpx_dsp_common.h"
-#include "vpx_mem/vpx_mem.h"
-#include "vpx_ports/mem.h"
-#include "vpx_ports/vpx_timer.h"
-#include "vpx_scale/vpx_scale.h"
-
-static int fixed_divide[512];
-
-static void temporal_filter_predictors_mb_c(MACROBLOCKD *xd,
-                                            uint8_t *y_mb_ptr,
-                                            uint8_t *u_mb_ptr,
-                                            uint8_t *v_mb_ptr,
-                                            int stride,
-                                            int uv_block_width,
-                                            int uv_block_height,
-                                            int mv_row,
-                                            int mv_col,
-                                            uint8_t *pred,
-                                            struct scale_factors *scale,
-                                            int x, int y) {
-  const int which_mv = 0;
-  const MV mv = { mv_row, mv_col };
-  const InterpKernel *const kernel = vp9_filter_kernels[EIGHTTAP_SHARP];
-
-  enum mv_precision mv_precision_uv;
-  int uv_stride;
-  if (uv_block_width == 8) {
-    uv_stride = (stride + 1) >> 1;
-    mv_precision_uv = MV_PRECISION_Q4;
-  } else {
-    uv_stride = stride;
-    mv_precision_uv = MV_PRECISION_Q3;
-  }
-
-#if CONFIG_VP9_HIGHBITDEPTH
-  if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
-    vp9_highbd_build_inter_predictor(y_mb_ptr, stride,
-                                     &pred[0], 16,
-                                     &mv,
-                                     scale,
-                                     16, 16,
-                                     which_mv,
-                                     kernel, MV_PRECISION_Q3, x, y, xd->bd);
-
-    vp9_highbd_build_inter_predictor(u_mb_ptr, uv_stride,
-                                     &pred[256], uv_block_width,
-                                     &mv,
-                                     scale,
-                                     uv_block_width, uv_block_height,
-                                     which_mv,
-                                     kernel, mv_precision_uv, x, y, xd->bd);
-
-    vp9_highbd_build_inter_predictor(v_mb_ptr, uv_stride,
-                                     &pred[512], uv_block_width,
-                                     &mv,
-                                     scale,
-                                     uv_block_width, uv_block_height,
-                                     which_mv,
-                                     kernel, mv_precision_uv, x, y, xd->bd);
-    return;
-  }
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-  (void)xd;
-  vp9_build_inter_predictor(y_mb_ptr, stride,
-                            &pred[0], 16,
-                            &mv,
-                            scale,
-                            16, 16,
-                            which_mv,
-                            kernel, MV_PRECISION_Q3, x, y);
-
-  vp9_build_inter_predictor(u_mb_ptr, uv_stride,
-                            &pred[256], uv_block_width,
-                            &mv,
-                            scale,
-                            uv_block_width, uv_block_height,
-                            which_mv,
-                            kernel, mv_precision_uv, x, y);
-
-  vp9_build_inter_predictor(v_mb_ptr, uv_stride,
-                            &pred[512], uv_block_width,
-                            &mv,
-                            scale,
-                            uv_block_width, uv_block_height,
-                            which_mv,
-                            kernel, mv_precision_uv, x, y);
-}
-
-void vp9_temporal_filter_init(void) {
-  int i;
-
-  fixed_divide[0] = 0;
-  for (i = 1; i < 512; ++i)
-    fixed_divide[i] = 0x80000 / i;
-}
-
-void vp9_temporal_filter_apply_c(uint8_t *frame1,
-                                 unsigned int stride,
-                                 uint8_t *frame2,
-                                 unsigned int block_width,
-                                 unsigned int block_height,
-                                 int strength,
-                                 int filter_weight,
-                                 unsigned int *accumulator,
-                                 uint16_t *count) {
-  unsigned int i, j, k;
-  int modifier;
-  int byte = 0;
-  const int rounding = strength > 0 ? 1 << (strength - 1) : 0;
-
-  for (i = 0, k = 0; i < block_height; i++) {
-    for (j = 0; j < block_width; j++, k++) {
-      int pixel_value = *frame2;
-
-      // non-local mean approach
-      int diff_sse[9] = { 0 };
-      int idx, idy, index = 0;
-
-      for (idy = -1; idy <= 1; ++idy) {
-        for (idx = -1; idx <= 1; ++idx) {
-          int row = (int)i + idy;
-          int col = (int)j + idx;
-
-          if (row >= 0 && row < (int)block_height &&
-              col >= 0 && col < (int)block_width) {
-            int diff = frame1[byte + idy * (int)stride + idx] -
-                frame2[idy * (int)block_width + idx];
-            diff_sse[index] = diff * diff;
-            ++index;
-          }
-        }
-      }
-
-      assert(index > 0);
-
-      modifier = 0;
-      for (idx = 0; idx < 9; ++idx)
-        modifier += diff_sse[idx];
-
-      modifier *= 3;
-      modifier /= index;
-
-      ++frame2;
-
-      modifier  += rounding;
-      modifier >>= strength;
-
-      if (modifier > 16)
-        modifier = 16;
-
-      modifier = 16 - modifier;
-      modifier *= filter_weight;
-
-      count[k] += modifier;
-      accumulator[k] += modifier * pixel_value;
-
-      byte++;
-    }
-
-    byte += stride - block_width;
-  }
-}
-
-#if CONFIG_VP9_HIGHBITDEPTH
-void vp9_highbd_temporal_filter_apply_c(uint8_t *frame1_8,
-                                        unsigned int stride,
-                                        uint8_t *frame2_8,
-                                        unsigned int block_width,
-                                        unsigned int block_height,
-                                        int strength,
-                                        int filter_weight,
-                                        unsigned int *accumulator,
-                                        uint16_t *count) {
-  uint16_t *frame1 = CONVERT_TO_SHORTPTR(frame1_8);
-  uint16_t *frame2 = CONVERT_TO_SHORTPTR(frame2_8);
-  unsigned int i, j, k;
-  int modifier;
-  int byte = 0;
-  const int rounding = strength > 0 ? 1 << (strength - 1) : 0;
-
-  for (i = 0, k = 0; i < block_height; i++) {
-    for (j = 0; j < block_width; j++, k++) {
-      int pixel_value = *frame2;
-      int diff_sse[9] = { 0 };
-      int idx, idy, index = 0;
-
-      for (idy = -1; idy <= 1; ++idy) {
-        for (idx = -1; idx <= 1; ++idx) {
-          int row = (int)i + idy;
-          int col = (int)j + idx;
-
-          if (row >= 0 && row < (int)block_height &&
-              col >= 0 && col < (int)block_width) {
-            int diff = frame1[byte + idy * (int)stride + idx] -
-                frame2[idy * (int)block_width + idx];
-            diff_sse[index] = diff * diff;
-            ++index;
-          }
-        }
-      }
-      assert(index > 0);
-
-      modifier = 0;
-      for (idx = 0; idx < 9; ++idx)
-        modifier += diff_sse[idx];
-
-      modifier *= 3;
-      modifier /= index;
-
-      ++frame2;
-      modifier += rounding;
-      modifier >>= strength;
-
-      if (modifier > 16)
-        modifier = 16;
-
-      modifier = 16 - modifier;
-      modifier *= filter_weight;
-
-      count[k] += modifier;
-      accumulator[k] += modifier * pixel_value;
-
-      byte++;
-    }
-
-    byte += stride - block_width;
-  }
-}
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-
-static int temporal_filter_find_matching_mb_c(VP9_COMP *cpi,
-                                              uint8_t *arf_frame_buf,
-                                              uint8_t *frame_ptr_buf,
-                                              int stride) {
-  MACROBLOCK *const x = &cpi->td.mb;
-  MACROBLOCKD *const xd = &x->e_mbd;
-  MV_SPEED_FEATURES *const mv_sf = &cpi->sf.mv;
-  const SEARCH_METHODS old_search_method = mv_sf->search_method;
-  int step_param;
-  int sadpb = x->sadperbit16;
-  int bestsme = INT_MAX;
-  uint32_t distortion;
-  uint32_t sse;
-  int cost_list[5];
-
-  MV best_ref_mv1 = {0, 0};
-  MV best_ref_mv1_full; /* full-pixel value of best_ref_mv1 */
-  MV *ref_mv = &x->e_mbd.mi[0]->bmi[0].as_mv[0].as_mv;
-
-  // Save input state
-  struct buf_2d src = x->plane[0].src;
-  struct buf_2d pre = xd->plane[0].pre[0];
-
-  best_ref_mv1_full.col = best_ref_mv1.col >> 3;
-  best_ref_mv1_full.row = best_ref_mv1.row >> 3;
-
-  // Setup frame pointers
-  x->plane[0].src.buf = arf_frame_buf;
-  x->plane[0].src.stride = stride;
-  xd->plane[0].pre[0].buf = frame_ptr_buf;
-  xd->plane[0].pre[0].stride = stride;
-
-  step_param = mv_sf->reduce_first_step_size;
-  step_param = VPXMIN(step_param, MAX_MVSEARCH_STEPS - 2);
-
-  mv_sf->search_method = HEX;
-  vp9_full_pixel_search(cpi, x, BLOCK_16X16, &best_ref_mv1_full, step_param,
-                        sadpb, cond_cost_list(cpi, cost_list), &best_ref_mv1,
-                        ref_mv, 0, 0);
-  mv_sf->search_method = old_search_method;
-
-  // Ignore mv costing by sending NULL pointer instead of cost array
-  bestsme = cpi->find_fractional_mv_step(x, ref_mv,
-                                         &best_ref_mv1,
-                                         cpi->common.allow_high_precision_mv,
-                                         x->errorperbit,
-                                         &cpi->fn_ptr[BLOCK_16X16],
-                                         0, mv_sf->subpel_iters_per_step,
-                                         cond_cost_list(cpi, cost_list),
-                                         NULL, NULL,
-                                         &distortion, &sse, NULL, 0, 0);
-
-  // Restore input state
-  x->plane[0].src = src;
-  xd->plane[0].pre[0] = pre;
-
-  return bestsme;
-}
-
-static void temporal_filter_iterate_c(VP9_COMP *cpi,
-                                      YV12_BUFFER_CONFIG **frames,
-                                      int frame_count,
-                                      int alt_ref_index,
-                                      int strength,
-                                      struct scale_factors *scale) {
-  int byte;
-  int frame;
-  int mb_col, mb_row;
-  unsigned int filter_weight;
-  int mb_cols = (frames[alt_ref_index]->y_crop_width + 15) >> 4;
-  int mb_rows = (frames[alt_ref_index]->y_crop_height + 15) >> 4;
-  int mb_y_offset = 0;
-  int mb_uv_offset = 0;
-  DECLARE_ALIGNED(16, unsigned int, accumulator[16 * 16 * 3]);
-  DECLARE_ALIGNED(16, uint16_t, count[16 * 16 * 3]);
-  MACROBLOCKD *mbd = &cpi->td.mb.e_mbd;
-  YV12_BUFFER_CONFIG *f = frames[alt_ref_index];
-  uint8_t *dst1, *dst2;
-#if CONFIG_VP9_HIGHBITDEPTH
-  DECLARE_ALIGNED(16, uint16_t,  predictor16[16 * 16 * 3]);
-  DECLARE_ALIGNED(16, uint8_t,  predictor8[16 * 16 * 3]);
-  uint8_t *predictor;
-#else
-  DECLARE_ALIGNED(16, uint8_t,  predictor[16 * 16 * 3]);
-#endif
-  const int mb_uv_height = 16 >> mbd->plane[1].subsampling_y;
-  const int mb_uv_width  = 16 >> mbd->plane[1].subsampling_x;
-
-  // Save input state
-  uint8_t* input_buffer[MAX_MB_PLANE];
-  int i;
-#if CONFIG_VP9_HIGHBITDEPTH
-  if (mbd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
-    predictor = CONVERT_TO_BYTEPTR(predictor16);
-  } else {
-    predictor = predictor8;
-  }
-#endif
-
-  for (i = 0; i < MAX_MB_PLANE; i++)
-    input_buffer[i] = mbd->plane[i].pre[0].buf;
-
-  for (mb_row = 0; mb_row < mb_rows; mb_row++) {
-    // Source frames are extended to 16 pixels. This is different than
-    //  L/A/G reference frames that have a border of 32 (VP9ENCBORDERINPIXELS)
-    // A 6/8 tap filter is used for motion search.  This requires 2 pixels
-    //  before and 3 pixels after.  So the largest Y mv on a border would
-    //  then be 16 - VP9_INTERP_EXTEND. The UV blocks are half the size of the
-    //  Y and therefore only extended by 8.  The largest mv that a UV block
-    //  can support is 8 - VP9_INTERP_EXTEND.  A UV mv is half of a Y mv.
-    //  (16 - VP9_INTERP_EXTEND) >> 1 which is greater than
-    //  8 - VP9_INTERP_EXTEND.
-    // To keep the mv in play for both Y and UV planes the max that it
-    //  can be on a border is therefore 16 - (2*VP9_INTERP_EXTEND+1).
-    cpi->td.mb.mv_row_min = -((mb_row * 16) + (17 - 2 * VP9_INTERP_EXTEND));
-    cpi->td.mb.mv_row_max = ((mb_rows - 1 - mb_row) * 16)
-                         + (17 - 2 * VP9_INTERP_EXTEND);
-
-    for (mb_col = 0; mb_col < mb_cols; mb_col++) {
-      int i, j, k;
-      int stride;
-
-      memset(accumulator, 0, 16 * 16 * 3 * sizeof(accumulator[0]));
-      memset(count, 0, 16 * 16 * 3 * sizeof(count[0]));
-
-      cpi->td.mb.mv_col_min = -((mb_col * 16) + (17 - 2 * VP9_INTERP_EXTEND));
-      cpi->td.mb.mv_col_max = ((mb_cols - 1 - mb_col) * 16)
-                           + (17 - 2 * VP9_INTERP_EXTEND);
-
-      for (frame = 0; frame < frame_count; frame++) {
-        const int thresh_low  = 10000;
-        const int thresh_high = 20000;
-
-        if (frames[frame] == NULL)
-          continue;
-
-        mbd->mi[0]->bmi[0].as_mv[0].as_mv.row = 0;
-        mbd->mi[0]->bmi[0].as_mv[0].as_mv.col = 0;
-
-        if (frame == alt_ref_index) {
-          filter_weight = 2;
-        } else {
-          // Find best match in this frame by MC
-          int err = temporal_filter_find_matching_mb_c(cpi,
-              frames[alt_ref_index]->y_buffer + mb_y_offset,
-              frames[frame]->y_buffer + mb_y_offset,
-              frames[frame]->y_stride);
-
-          // Assign higher weight to matching MB if it's error
-          // score is lower. If not applying MC default behavior
-          // is to weight all MBs equal.
-          filter_weight = err < thresh_low
-                          ? 2 : err < thresh_high ? 1 : 0;
-        }
-
-        if (filter_weight != 0) {
-          // Construct the predictors
-          temporal_filter_predictors_mb_c(mbd,
-              frames[frame]->y_buffer + mb_y_offset,
-              frames[frame]->u_buffer + mb_uv_offset,
-              frames[frame]->v_buffer + mb_uv_offset,
-              frames[frame]->y_stride,
-              mb_uv_width, mb_uv_height,
-              mbd->mi[0]->bmi[0].as_mv[0].as_mv.row,
-              mbd->mi[0]->bmi[0].as_mv[0].as_mv.col,
-              predictor, scale,
-              mb_col * 16, mb_row * 16);
-
-#if CONFIG_VP9_HIGHBITDEPTH
-          if (mbd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
-            int adj_strength = strength + 2 * (mbd->bd - 8);
-            // Apply the filter (YUV)
-            vp9_highbd_temporal_filter_apply_c(f->y_buffer + mb_y_offset,
-                                               f->y_stride,
-                                               predictor, 16, 16, adj_strength,
-                                               filter_weight,
-                                               accumulator, count);
-            vp9_highbd_temporal_filter_apply_c(f->u_buffer + mb_uv_offset,
-                                               f->uv_stride, predictor + 256,
-                                               mb_uv_width, mb_uv_height,
-                                               adj_strength,
-                                               filter_weight, accumulator + 256,
-                                               count + 256);
-            vp9_highbd_temporal_filter_apply_c(f->v_buffer + mb_uv_offset,
-                                               f->uv_stride, predictor + 512,
-                                               mb_uv_width, mb_uv_height,
-                                               adj_strength, filter_weight,
-                                               accumulator + 512, count + 512);
-          } else {
-            // Apply the filter (YUV)
-            vp9_temporal_filter_apply_c(f->y_buffer + mb_y_offset, f->y_stride,
-                                        predictor, 16, 16,
-                                        strength, filter_weight,
-                                        accumulator, count);
-            vp9_temporal_filter_apply_c(f->u_buffer + mb_uv_offset,
-                                        f->uv_stride,
-                                        predictor + 256,
-                                        mb_uv_width, mb_uv_height, strength,
-                                        filter_weight, accumulator + 256,
-                                        count + 256);
-            vp9_temporal_filter_apply_c(f->v_buffer + mb_uv_offset,
-                                        f->uv_stride,
-                                        predictor + 512,
-                                        mb_uv_width, mb_uv_height, strength,
-                                        filter_weight, accumulator + 512,
-                                        count + 512);
-          }
-#else
-          // Apply the filter (YUV)
-          // TODO(jingning): Need SIMD optimization for this.
-          vp9_temporal_filter_apply_c(f->y_buffer + mb_y_offset, f->y_stride,
-                                      predictor, 16, 16,
-                                      strength, filter_weight,
-                                      accumulator, count);
-          vp9_temporal_filter_apply_c(f->u_buffer + mb_uv_offset, f->uv_stride,
-                                      predictor + 256,
-                                      mb_uv_width, mb_uv_height, strength,
-                                      filter_weight, accumulator + 256,
-                                      count + 256);
-          vp9_temporal_filter_apply_c(f->v_buffer + mb_uv_offset, f->uv_stride,
-                                      predictor + 512,
-                                      mb_uv_width, mb_uv_height, strength,
-                                      filter_weight, accumulator + 512,
-                                      count + 512);
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-        }
-      }
-
-#if CONFIG_VP9_HIGHBITDEPTH
-      if (mbd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
-        uint16_t *dst1_16;
-        uint16_t *dst2_16;
-        // Normalize filter output to produce AltRef frame
-        dst1 = cpi->alt_ref_buffer.y_buffer;
-        dst1_16 = CONVERT_TO_SHORTPTR(dst1);
-        stride = cpi->alt_ref_buffer.y_stride;
-        byte = mb_y_offset;
-        for (i = 0, k = 0; i < 16; i++) {
-          for (j = 0; j < 16; j++, k++) {
-            unsigned int pval = accumulator[k] + (count[k] >> 1);
-            pval *= fixed_divide[count[k]];
-            pval >>= 19;
-
-            dst1_16[byte] = (uint16_t)pval;
-
-            // move to next pixel
-            byte++;
-          }
-
-          byte += stride - 16;
-        }
-
-        dst1 = cpi->alt_ref_buffer.u_buffer;
-        dst2 = cpi->alt_ref_buffer.v_buffer;
-        dst1_16 = CONVERT_TO_SHORTPTR(dst1);
-        dst2_16 = CONVERT_TO_SHORTPTR(dst2);
-        stride = cpi->alt_ref_buffer.uv_stride;
-        byte = mb_uv_offset;
-        for (i = 0, k = 256; i < mb_uv_height; i++) {
-          for (j = 0; j < mb_uv_width; j++, k++) {
-            int m = k + 256;
-
-            // U
-            unsigned int pval = accumulator[k] + (count[k] >> 1);
-            pval *= fixed_divide[count[k]];
-            pval >>= 19;
-            dst1_16[byte] = (uint16_t)pval;
-
-            // V
-            pval = accumulator[m] + (count[m] >> 1);
-            pval *= fixed_divide[count[m]];
-            pval >>= 19;
-            dst2_16[byte] = (uint16_t)pval;
-
-            // move to next pixel
-            byte++;
-          }
-
-          byte += stride - mb_uv_width;
-        }
-      } else {
-        // Normalize filter output to produce AltRef frame
-        dst1 = cpi->alt_ref_buffer.y_buffer;
-        stride = cpi->alt_ref_buffer.y_stride;
-        byte = mb_y_offset;
-        for (i = 0, k = 0; i < 16; i++) {
-          for (j = 0; j < 16; j++, k++) {
-            unsigned int pval = accumulator[k] + (count[k] >> 1);
-            pval *= fixed_divide[count[k]];
-            pval >>= 19;
-
-            dst1[byte] = (uint8_t)pval;
-
-            // move to next pixel
-            byte++;
-          }
-          byte += stride - 16;
-        }
-
-        dst1 = cpi->alt_ref_buffer.u_buffer;
-        dst2 = cpi->alt_ref_buffer.v_buffer;
-        stride = cpi->alt_ref_buffer.uv_stride;
-        byte = mb_uv_offset;
-        for (i = 0, k = 256; i < mb_uv_height; i++) {
-          for (j = 0; j < mb_uv_width; j++, k++) {
-            int m = k + 256;
-
-            // U
-            unsigned int pval = accumulator[k] + (count[k] >> 1);
-            pval *= fixed_divide[count[k]];
-            pval >>= 19;
-            dst1[byte] = (uint8_t)pval;
-
-            // V
-            pval = accumulator[m] + (count[m] >> 1);
-            pval *= fixed_divide[count[m]];
-            pval >>= 19;
-            dst2[byte] = (uint8_t)pval;
-
-            // move to next pixel
-            byte++;
-          }
-          byte += stride - mb_uv_width;
-        }
-      }
-#else
-      // Normalize filter output to produce AltRef frame
-      dst1 = cpi->alt_ref_buffer.y_buffer;
-      stride = cpi->alt_ref_buffer.y_stride;
-      byte = mb_y_offset;
-      for (i = 0, k = 0; i < 16; i++) {
-        for (j = 0; j < 16; j++, k++) {
-          unsigned int pval = accumulator[k] + (count[k] >> 1);
-          pval *= fixed_divide[count[k]];
-          pval >>= 19;
-
-          dst1[byte] = (uint8_t)pval;
-
-          // move to next pixel
-          byte++;
-        }
-        byte += stride - 16;
-      }
-
-      dst1 = cpi->alt_ref_buffer.u_buffer;
-      dst2 = cpi->alt_ref_buffer.v_buffer;
-      stride = cpi->alt_ref_buffer.uv_stride;
-      byte = mb_uv_offset;
-      for (i = 0, k = 256; i < mb_uv_height; i++) {
-        for (j = 0; j < mb_uv_width; j++, k++) {
-          int m = k + 256;
-
-          // U
-          unsigned int pval = accumulator[k] + (count[k] >> 1);
-          pval *= fixed_divide[count[k]];
-          pval >>= 19;
-          dst1[byte] = (uint8_t)pval;
-
-          // V
-          pval = accumulator[m] + (count[m] >> 1);
-          pval *= fixed_divide[count[m]];
-          pval >>= 19;
-          dst2[byte] = (uint8_t)pval;
-
-          // move to next pixel
-          byte++;
-        }
-        byte += stride - mb_uv_width;
-      }
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-      mb_y_offset += 16;
-      mb_uv_offset += mb_uv_width;
-    }
-    mb_y_offset += 16 * (f->y_stride - mb_cols);
-    mb_uv_offset += mb_uv_height * f->uv_stride - mb_uv_width * mb_cols;
-  }
-
-  // Restore input state
-  for (i = 0; i < MAX_MB_PLANE; i++)
-    mbd->plane[i].pre[0].buf = input_buffer[i];
-}
-
-// Apply buffer limits and context specific adjustments to arnr filter.
-static void adjust_arnr_filter(VP9_COMP *cpi,
-                               int distance, int group_boost,
-                               int *arnr_frames, int *arnr_strength) {
-  const VP9EncoderConfig *const oxcf = &cpi->oxcf;
-  const int frames_after_arf =
-      vp9_lookahead_depth(cpi->lookahead) - distance - 1;
-  int frames_fwd = (cpi->oxcf.arnr_max_frames - 1) >> 1;
-  int frames_bwd;
-  int q, frames, strength;
-
-  // Define the forward and backwards filter limits for this arnr group.
-  if (frames_fwd > frames_after_arf)
-    frames_fwd = frames_after_arf;
-  if (frames_fwd > distance)
-    frames_fwd = distance;
-
-  frames_bwd = frames_fwd;
-
-  // For even length filter there is one more frame backward
-  // than forward: e.g. len=6 ==> bbbAff, len=7 ==> bbbAfff.
-  if (frames_bwd < distance)
-    frames_bwd += (oxcf->arnr_max_frames + 1) & 0x1;
-
-  // Set the baseline active filter size.
-  frames = frames_bwd + 1 + frames_fwd;
-
-  // Adjust the strength based on active max q.
-  if (cpi->common.current_video_frame > 1)
-    q = ((int)vp9_convert_qindex_to_q(
-        cpi->rc.avg_frame_qindex[INTER_FRAME], cpi->common.bit_depth));
-  else
-    q = ((int)vp9_convert_qindex_to_q(
-        cpi->rc.avg_frame_qindex[KEY_FRAME], cpi->common.bit_depth));
-  if (q > 16) {
-    strength = oxcf->arnr_strength;
-  } else {
-    strength = oxcf->arnr_strength - ((16 - q) / 2);
-    if (strength < 0)
-      strength = 0;
-  }
-
-  // Adjust number of frames in filter and strength based on gf boost level.
-  if (frames > group_boost / 150) {
-    frames = group_boost / 150;
-    frames += !(frames & 1);
-  }
-
-  if (strength > group_boost / 300) {
-    strength = group_boost / 300;
-  }
-
-  // Adjustments for second level arf in multi arf case.
-  if (cpi->oxcf.pass == 2 && cpi->multi_arf_allowed) {
-    const GF_GROUP *const gf_group = &cpi->twopass.gf_group;
-    if (gf_group->rf_level[gf_group->index] != GF_ARF_STD) {
-      strength >>= 1;
-    }
-  }
-
-  *arnr_frames = frames;
-  *arnr_strength = strength;
-}
-
-void vp9_temporal_filter(VP9_COMP *cpi, int distance) {
-  VP9_COMMON *const cm = &cpi->common;
-  RATE_CONTROL *const rc = &cpi->rc;
-  MACROBLOCKD *const xd = &cpi->td.mb.e_mbd;
-  int frame;
-  int frames_to_blur;
-  int start_frame;
-  int strength;
-  int frames_to_blur_backward;
-  int frames_to_blur_forward;
-  struct scale_factors sf;
-  YV12_BUFFER_CONFIG *frames[MAX_LAG_BUFFERS] = {NULL};
-
-  // Apply context specific adjustments to the arnr filter parameters.
-  adjust_arnr_filter(cpi, distance, rc->gfu_boost, &frames_to_blur, &strength);
-  frames_to_blur_backward = (frames_to_blur / 2);
-  frames_to_blur_forward = ((frames_to_blur - 1) / 2);
-  start_frame = distance + frames_to_blur_forward;
-
-  // Setup frame pointers, NULL indicates frame not included in filter.
-  for (frame = 0; frame < frames_to_blur; ++frame) {
-    const int which_buffer = start_frame - frame;
-    struct lookahead_entry *buf = vp9_lookahead_peek(cpi->lookahead,
-                                                     which_buffer);
-    frames[frames_to_blur - 1 - frame] = &buf->img;
-  }
-
-  if (frames_to_blur > 0) {
-    // Setup scaling factors. Scaling on each of the arnr frames is not
-    // supported.
-    if (cpi->use_svc) {
-      // In spatial svc the scaling factors might be less then 1/2.
-      // So we will use non-normative scaling.
-      int frame_used = 0;
-#if CONFIG_VP9_HIGHBITDEPTH
-      vp9_setup_scale_factors_for_frame(
-          &sf,
-          get_frame_new_buffer(cm)->y_crop_width,
-          get_frame_new_buffer(cm)->y_crop_height,
-          get_frame_new_buffer(cm)->y_crop_width,
-          get_frame_new_buffer(cm)->y_crop_height,
-          cm->use_highbitdepth);
-#else
-      vp9_setup_scale_factors_for_frame(
-          &sf,
-          get_frame_new_buffer(cm)->y_crop_width,
-          get_frame_new_buffer(cm)->y_crop_height,
-          get_frame_new_buffer(cm)->y_crop_width,
-          get_frame_new_buffer(cm)->y_crop_height);
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-
-      for (frame = 0; frame < frames_to_blur; ++frame) {
-        if (cm->mi_cols * MI_SIZE != frames[frame]->y_width ||
-            cm->mi_rows * MI_SIZE != frames[frame]->y_height) {
-          if (vpx_realloc_frame_buffer(&cpi->svc.scaled_frames[frame_used],
-                                       cm->width, cm->height,
-                                       cm->subsampling_x, cm->subsampling_y,
-#if CONFIG_VP9_HIGHBITDEPTH
-                                       cm->use_highbitdepth,
-#endif
-                                       VP9_ENC_BORDER_IN_PIXELS,
-                                       cm->byte_alignment,
-                                       NULL, NULL, NULL)) {
-            vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR,
-                               "Failed to reallocate alt_ref_buffer");
-          }
-          frames[frame] = vp9_scale_if_required(
-              cm, frames[frame], &cpi->svc.scaled_frames[frame_used], 0);
-          ++frame_used;
-        }
-      }
-      cm->mi = cm->mip + cm->mi_stride + 1;
-      xd->mi = cm->mi_grid_visible;
-      xd->mi[0] = cm->mi;
-    } else {
-      // ARF is produced at the native frame size and resized when coded.
-#if CONFIG_VP9_HIGHBITDEPTH
-      vp9_setup_scale_factors_for_frame(&sf,
-                                        frames[0]->y_crop_width,
-                                        frames[0]->y_crop_height,
-                                        frames[0]->y_crop_width,
-                                        frames[0]->y_crop_height,
-                                        cm->use_highbitdepth);
-#else
-      vp9_setup_scale_factors_for_frame(&sf,
-                                        frames[0]->y_crop_width,
-                                        frames[0]->y_crop_height,
-                                        frames[0]->y_crop_width,
-                                        frames[0]->y_crop_height);
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-    }
-  }
-
-  temporal_filter_iterate_c(cpi, frames, frames_to_blur,
-                            frames_to_blur_backward, strength, &sf);
-}
diff --git a/vp9/encoder/vp9_temporal_filter.h b/vp9/encoder/vp9_temporal_filter.h
deleted file mode 100644 (file)
index f537b88..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#ifndef VP9_ENCODER_VP9_TEMPORAL_FILTER_H_
-#define VP9_ENCODER_VP9_TEMPORAL_FILTER_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-void vp9_temporal_filter_init(void);
-void vp9_temporal_filter(VP9_COMP *cpi, int distance);
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP9_ENCODER_VP9_TEMPORAL_FILTER_H_
diff --git a/vp9/encoder/vp9_tokenize.c b/vp9/encoder/vp9_tokenize.c
deleted file mode 100644 (file)
index edec755..0000000
+++ /dev/null
@@ -1,500 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#include <assert.h>
-#include <math.h>
-#include <stdio.h>
-#include <string.h>
-
-#include "vpx_mem/vpx_mem.h"
-
-#include "vp9/common/vp9_entropy.h"
-#include "vp9/common/vp9_pred_common.h"
-#include "vp9/common/vp9_scan.h"
-
-#include "vp9/encoder/vp9_cost.h"
-#include "vp9/encoder/vp9_encoder.h"
-#include "vp9/encoder/vp9_tokenize.h"
-
-static const TOKENVALUE dct_cat_lt_10_value_tokens[] = {
-  {9, 63}, {9, 61}, {9, 59}, {9, 57}, {9, 55}, {9, 53}, {9, 51}, {9, 49},
-  {9, 47}, {9, 45}, {9, 43}, {9, 41}, {9, 39}, {9, 37}, {9, 35}, {9, 33},
-  {9, 31}, {9, 29}, {9, 27}, {9, 25}, {9, 23}, {9, 21}, {9, 19}, {9, 17},
-  {9, 15}, {9, 13}, {9, 11}, {9, 9}, {9, 7}, {9, 5}, {9, 3}, {9, 1},
-  {8, 31}, {8, 29}, {8, 27}, {8, 25}, {8, 23}, {8, 21},
-  {8, 19}, {8, 17}, {8, 15}, {8, 13}, {8, 11}, {8, 9},
-  {8, 7}, {8, 5}, {8, 3}, {8, 1},
-  {7, 15}, {7, 13}, {7, 11}, {7, 9}, {7, 7}, {7, 5}, {7, 3}, {7, 1},
-  {6, 7}, {6, 5}, {6, 3}, {6, 1}, {5, 3}, {5, 1},
-  {4, 1}, {3, 1}, {2, 1}, {1, 1}, {0, 0},
-  {1, 0},  {2, 0}, {3, 0}, {4, 0},
-  {5, 0}, {5, 2}, {6, 0}, {6, 2}, {6, 4}, {6, 6},
-  {7, 0}, {7, 2}, {7, 4}, {7, 6}, {7, 8}, {7, 10}, {7, 12}, {7, 14},
-  {8, 0}, {8, 2}, {8, 4}, {8, 6}, {8, 8}, {8, 10}, {8, 12},
-  {8, 14}, {8, 16}, {8, 18}, {8, 20}, {8, 22}, {8, 24},
-  {8, 26}, {8, 28}, {8, 30}, {9, 0}, {9, 2},
-  {9, 4}, {9, 6}, {9, 8}, {9, 10}, {9, 12}, {9, 14}, {9, 16},
-  {9, 18}, {9, 20}, {9, 22}, {9, 24}, {9, 26}, {9, 28},
-  {9, 30}, {9, 32}, {9, 34}, {9, 36}, {9, 38}, {9, 40},
-  {9, 42}, {9, 44}, {9, 46}, {9, 48}, {9, 50}, {9, 52},
-  {9, 54}, {9, 56}, {9, 58}, {9, 60}, {9, 62}
-};
-const TOKENVALUE *vp9_dct_cat_lt_10_value_tokens = dct_cat_lt_10_value_tokens +
-    (sizeof(dct_cat_lt_10_value_tokens) / sizeof(*dct_cat_lt_10_value_tokens))
-    / 2;
-// The corresponding costs of the extrabits for the tokens in the above table
-// are stored in the table below. The values are obtained from looking up the
-// entry for the specified extrabits in the table corresponding to the token
-// (as defined in cost element vp9_extra_bits)
-// e.g. {9, 63} maps to cat5_cost[63 >> 1], {1, 1} maps to sign_cost[1 >> 1]
-static const int dct_cat_lt_10_value_cost[] = {
-  3773, 3750, 3704, 3681, 3623, 3600, 3554, 3531,
-  3432, 3409, 3363, 3340, 3282, 3259, 3213, 3190,
-  3136, 3113, 3067, 3044, 2986, 2963, 2917, 2894,
-  2795, 2772, 2726, 2703, 2645, 2622, 2576, 2553,
-  3197, 3116, 3058, 2977, 2881, 2800,
-  2742, 2661, 2615, 2534, 2476, 2395,
-  2299, 2218, 2160, 2079,
-  2566, 2427, 2334, 2195, 2023, 1884, 1791, 1652,
-  1893, 1696, 1453, 1256, 1229, 864,
-  512, 512, 512, 512, 0,
-  512, 512, 512, 512,
-  864, 1229, 1256, 1453, 1696, 1893,
-  1652, 1791, 1884, 2023, 2195, 2334, 2427, 2566,
-  2079, 2160, 2218, 2299, 2395, 2476, 2534, 2615,
-  2661, 2742, 2800, 2881, 2977, 3058, 3116, 3197,
-  2553, 2576, 2622, 2645, 2703, 2726, 2772, 2795,
-  2894, 2917, 2963, 2986, 3044, 3067, 3113, 3136,
-  3190, 3213, 3259, 3282, 3340, 3363, 3409, 3432,
-  3531, 3554, 3600, 3623, 3681, 3704, 3750, 3773,
-};
-const int *vp9_dct_cat_lt_10_value_cost = dct_cat_lt_10_value_cost +
-    (sizeof(dct_cat_lt_10_value_cost) / sizeof(*dct_cat_lt_10_value_cost))
-    / 2;
-
-// Array indices are identical to previously-existing CONTEXT_NODE indices
-const vpx_tree_index vp9_coef_tree[TREE_SIZE(ENTROPY_TOKENS)] = {
-  -EOB_TOKEN, 2,                       // 0  = EOB
-  -ZERO_TOKEN, 4,                      // 1  = ZERO
-  -ONE_TOKEN, 6,                       // 2  = ONE
-  8, 12,                               // 3  = LOW_VAL
-  -TWO_TOKEN, 10,                      // 4  = TWO
-  -THREE_TOKEN, -FOUR_TOKEN,           // 5  = THREE
-  14, 16,                              // 6  = HIGH_LOW
-  -CATEGORY1_TOKEN, -CATEGORY2_TOKEN,  // 7  = CAT_ONE
-  18, 20,                              // 8  = CAT_THREEFOUR
-  -CATEGORY3_TOKEN, -CATEGORY4_TOKEN,  // 9  = CAT_THREE
-  -CATEGORY5_TOKEN, -CATEGORY6_TOKEN   // 10 = CAT_FIVE
-};
-
-static const int16_t zero_cost[] = {0};
-static const int16_t sign_cost[1] = {512};
-static const int16_t cat1_cost[1 << 1] = {864, 1229};
-static const int16_t cat2_cost[1 << 2] = {1256, 1453, 1696, 1893};
-static const int16_t cat3_cost[1 << 3] = {1652, 1791, 1884, 2023,
-                                          2195, 2334, 2427, 2566};
-static const int16_t cat4_cost[1 << 4] = {2079, 2160, 2218, 2299, 2395, 2476,
-                                          2534, 2615, 2661, 2742, 2800, 2881,
-                                          2977, 3058, 3116, 3197};
-static const int16_t cat5_cost[1 << 5] = {
-    2553, 2576, 2622, 2645, 2703, 2726, 2772, 2795, 2894, 2917, 2963,
-    2986, 3044, 3067, 3113, 3136, 3190, 3213, 3259, 3282, 3340, 3363,
-    3409, 3432, 3531, 3554, 3600, 3623, 3681, 3704, 3750, 3773};
-const int16_t vp9_cat6_low_cost[256] = {
-    3378, 3390, 3401, 3413, 3435, 3447, 3458, 3470, 3517, 3529, 3540, 3552,
-    3574, 3586, 3597, 3609, 3671, 3683, 3694, 3706, 3728, 3740, 3751, 3763,
-    3810, 3822, 3833, 3845, 3867, 3879, 3890, 3902, 3973, 3985, 3996, 4008,
-    4030, 4042, 4053, 4065, 4112, 4124, 4135, 4147, 4169, 4181, 4192, 4204,
-    4266, 4278, 4289, 4301, 4323, 4335, 4346, 4358, 4405, 4417, 4428, 4440,
-    4462, 4474, 4485, 4497, 4253, 4265, 4276, 4288, 4310, 4322, 4333, 4345,
-    4392, 4404, 4415, 4427, 4449, 4461, 4472, 4484, 4546, 4558, 4569, 4581,
-    4603, 4615, 4626, 4638, 4685, 4697, 4708, 4720, 4742, 4754, 4765, 4777,
-    4848, 4860, 4871, 4883, 4905, 4917, 4928, 4940, 4987, 4999, 5010, 5022,
-    5044, 5056, 5067, 5079, 5141, 5153, 5164, 5176, 5198, 5210, 5221, 5233,
-    5280, 5292, 5303, 5315, 5337, 5349, 5360, 5372, 4988, 5000, 5011, 5023,
-    5045, 5057, 5068, 5080, 5127, 5139, 5150, 5162, 5184, 5196, 5207, 5219,
-    5281, 5293, 5304, 5316, 5338, 5350, 5361, 5373, 5420, 5432, 5443, 5455,
-    5477, 5489, 5500, 5512, 5583, 5595, 5606, 5618, 5640, 5652, 5663, 5675,
-    5722, 5734, 5745, 5757, 5779, 5791, 5802, 5814, 5876, 5888, 5899, 5911,
-    5933, 5945, 5956, 5968, 6015, 6027, 6038, 6050, 6072, 6084, 6095, 6107,
-    5863, 5875, 5886, 5898, 5920, 5932, 5943, 5955, 6002, 6014, 6025, 6037,
-    6059, 6071, 6082, 6094, 6156, 6168, 6179, 6191, 6213, 6225, 6236, 6248,
-    6295, 6307, 6318, 6330, 6352, 6364, 6375, 6387, 6458, 6470, 6481, 6493,
-    6515, 6527, 6538, 6550, 6597, 6609, 6620, 6632, 6654, 6666, 6677, 6689,
-    6751, 6763, 6774, 6786, 6808, 6820, 6831, 6843, 6890, 6902, 6913, 6925,
-    6947, 6959, 6970, 6982};
-const int vp9_cat6_high_cost[64] = {
-    88,    2251,  2727,  4890,  3148,  5311,  5787,  7950,  3666,  5829,  6305,
-    8468,  6726,  8889,  9365,  11528, 3666,  5829,  6305,  8468,  6726,  8889,
-    9365,  11528, 7244,  9407,  9883,  12046, 10304, 12467, 12943, 15106, 3666,
-    5829,  6305,  8468,  6726,  8889,  9365,  11528, 7244,  9407,  9883,  12046,
-    10304, 12467, 12943, 15106, 7244,  9407,  9883,  12046, 10304, 12467, 12943,
-    15106, 10822, 12985, 13461, 15624, 13882, 16045, 16521, 18684};
-
-#if CONFIG_VP9_HIGHBITDEPTH
-const int vp9_cat6_high10_high_cost[256] = {
-    94,    2257,  2733,  4896,  3154,  5317,  5793,  7956,  3672,  5835,  6311,
-    8474,  6732,  8895,  9371,  11534, 3672,  5835,  6311,  8474,  6732,  8895,
-    9371,  11534, 7250,  9413,  9889,  12052, 10310, 12473, 12949, 15112, 3672,
-    5835,  6311,  8474,  6732,  8895,  9371,  11534, 7250,  9413,  9889,  12052,
-    10310, 12473, 12949, 15112, 7250,  9413,  9889,  12052, 10310, 12473, 12949,
-    15112, 10828, 12991, 13467, 15630, 13888, 16051, 16527, 18690, 4187,  6350,
-    6826,  8989,  7247,  9410,  9886,  12049, 7765,  9928,  10404, 12567, 10825,
-    12988, 13464, 15627, 7765,  9928,  10404, 12567, 10825, 12988, 13464, 15627,
-    11343, 13506, 13982, 16145, 14403, 16566, 17042, 19205, 7765,  9928,  10404,
-    12567, 10825, 12988, 13464, 15627, 11343, 13506, 13982, 16145, 14403, 16566,
-    17042, 19205, 11343, 13506, 13982, 16145, 14403, 16566, 17042, 19205, 14921,
-    17084, 17560, 19723, 17981, 20144, 20620, 22783, 4187,  6350,  6826,  8989,
-    7247,  9410,  9886,  12049, 7765,  9928,  10404, 12567, 10825, 12988, 13464,
-    15627, 7765,  9928,  10404, 12567, 10825, 12988, 13464, 15627, 11343, 13506,
-    13982, 16145, 14403, 16566, 17042, 19205, 7765,  9928,  10404, 12567, 10825,
-    12988, 13464, 15627, 11343, 13506, 13982, 16145, 14403, 16566, 17042, 19205,
-    11343, 13506, 13982, 16145, 14403, 16566, 17042, 19205, 14921, 17084, 17560,
-    19723, 17981, 20144, 20620, 22783, 8280,  10443, 10919, 13082, 11340, 13503,
-    13979, 16142, 11858, 14021, 14497, 16660, 14918, 17081, 17557, 19720, 11858,
-    14021, 14497, 16660, 14918, 17081, 17557, 19720, 15436, 17599, 18075, 20238,
-    18496, 20659, 21135, 23298, 11858, 14021, 14497, 16660, 14918, 17081, 17557,
-    19720, 15436, 17599, 18075, 20238, 18496, 20659, 21135, 23298, 15436, 17599,
-    18075, 20238, 18496, 20659, 21135, 23298, 19014, 21177, 21653, 23816, 22074,
-    24237, 24713, 26876};
-const int vp9_cat6_high12_high_cost[1024] = {
-    100,   2263,  2739,  4902,  3160,  5323,  5799,  7962,  3678,  5841,  6317,
-    8480,  6738,  8901,  9377,  11540, 3678,  5841,  6317,  8480,  6738,  8901,
-    9377,  11540, 7256,  9419,  9895,  12058, 10316, 12479, 12955, 15118, 3678,
-    5841,  6317,  8480,  6738,  8901,  9377,  11540, 7256,  9419,  9895,  12058,
-    10316, 12479, 12955, 15118, 7256,  9419,  9895,  12058, 10316, 12479, 12955,
-    15118, 10834, 12997, 13473, 15636, 13894, 16057, 16533, 18696, 4193,  6356,
-    6832,  8995,  7253,  9416,  9892,  12055, 7771,  9934,  10410, 12573, 10831,
-    12994, 13470, 15633, 7771,  9934,  10410, 12573, 10831, 12994, 13470, 15633,
-    11349, 13512, 13988, 16151, 14409, 16572, 17048, 19211, 7771,  9934,  10410,
-    12573, 10831, 12994, 13470, 15633, 11349, 13512, 13988, 16151, 14409, 16572,
-    17048, 19211, 11349, 13512, 13988, 16151, 14409, 16572, 17048, 19211, 14927,
-    17090, 17566, 19729, 17987, 20150, 20626, 22789, 4193,  6356,  6832,  8995,
-    7253,  9416,  9892,  12055, 7771,  9934,  10410, 12573, 10831, 12994, 13470,
-    15633, 7771,  9934,  10410, 12573, 10831, 12994, 13470, 15633, 11349, 13512,
-    13988, 16151, 14409, 16572, 17048, 19211, 7771,  9934,  10410, 12573, 10831,
-    12994, 13470, 15633, 11349, 13512, 13988, 16151, 14409, 16572, 17048, 19211,
-    11349, 13512, 13988, 16151, 14409, 16572, 17048, 19211, 14927, 17090, 17566,
-    19729, 17987, 20150, 20626, 22789, 8286,  10449, 10925, 13088, 11346, 13509,
-    13985, 16148, 11864, 14027, 14503, 16666, 14924, 17087, 17563, 19726, 11864,
-    14027, 14503, 16666, 14924, 17087, 17563, 19726, 15442, 17605, 18081, 20244,
-    18502, 20665, 21141, 23304, 11864, 14027, 14503, 16666, 14924, 17087, 17563,
-    19726, 15442, 17605, 18081, 20244, 18502, 20665, 21141, 23304, 15442, 17605,
-    18081, 20244, 18502, 20665, 21141, 23304, 19020, 21183, 21659, 23822, 22080,
-    24243, 24719, 26882, 4193,  6356,  6832,  8995,  7253,  9416,  9892,  12055,
-    7771,  9934,  10410, 12573, 10831, 12994, 13470, 15633, 7771,  9934,  10410,
-    12573, 10831, 12994, 13470, 15633, 11349, 13512, 13988, 16151, 14409, 16572,
-    17048, 19211, 7771,  9934,  10410, 12573, 10831, 12994, 13470, 15633, 11349,
-    13512, 13988, 16151, 14409, 16572, 17048, 19211, 11349, 13512, 13988, 16151,
-    14409, 16572, 17048, 19211, 14927, 17090, 17566, 19729, 17987, 20150, 20626,
-    22789, 8286,  10449, 10925, 13088, 11346, 13509, 13985, 16148, 11864, 14027,
-    14503, 16666, 14924, 17087, 17563, 19726, 11864, 14027, 14503, 16666, 14924,
-    17087, 17563, 19726, 15442, 17605, 18081, 20244, 18502, 20665, 21141, 23304,
-    11864, 14027, 14503, 16666, 14924, 17087, 17563, 19726, 15442, 17605, 18081,
-    20244, 18502, 20665, 21141, 23304, 15442, 17605, 18081, 20244, 18502, 20665,
-    21141, 23304, 19020, 21183, 21659, 23822, 22080, 24243, 24719, 26882, 8286,
-    10449, 10925, 13088, 11346, 13509, 13985, 16148, 11864, 14027, 14503, 16666,
-    14924, 17087, 17563, 19726, 11864, 14027, 14503, 16666, 14924, 17087, 17563,
-    19726, 15442, 17605, 18081, 20244, 18502, 20665, 21141, 23304, 11864, 14027,
-    14503, 16666, 14924, 17087, 17563, 19726, 15442, 17605, 18081, 20244, 18502,
-    20665, 21141, 23304, 15442, 17605, 18081, 20244, 18502, 20665, 21141, 23304,
-    19020, 21183, 21659, 23822, 22080, 24243, 24719, 26882, 12379, 14542, 15018,
-    17181, 15439, 17602, 18078, 20241, 15957, 18120, 18596, 20759, 19017, 21180,
-    21656, 23819, 15957, 18120, 18596, 20759, 19017, 21180, 21656, 23819, 19535,
-    21698, 22174, 24337, 22595, 24758, 25234, 27397, 15957, 18120, 18596, 20759,
-    19017, 21180, 21656, 23819, 19535, 21698, 22174, 24337, 22595, 24758, 25234,
-    27397, 19535, 21698, 22174, 24337, 22595, 24758, 25234, 27397, 23113, 25276,
-    25752, 27915, 26173, 28336, 28812, 30975, 4193,  6356,  6832,  8995,  7253,
-    9416,  9892,  12055, 7771,  9934,  10410, 12573, 10831, 12994, 13470, 15633,
-    7771,  9934,  10410, 12573, 10831, 12994, 13470, 15633, 11349, 13512, 13988,
-    16151, 14409, 16572, 17048, 19211, 7771,  9934,  10410, 12573, 10831, 12994,
-    13470, 15633, 11349, 13512, 13988, 16151, 14409, 16572, 17048, 19211, 11349,
-    13512, 13988, 16151, 14409, 16572, 17048, 19211, 14927, 17090, 17566, 19729,
-    17987, 20150, 20626, 22789, 8286,  10449, 10925, 13088, 11346, 13509, 13985,
-    16148, 11864, 14027, 14503, 16666, 14924, 17087, 17563, 19726, 11864, 14027,
-    14503, 16666, 14924, 17087, 17563, 19726, 15442, 17605, 18081, 20244, 18502,
-    20665, 21141, 23304, 11864, 14027, 14503, 16666, 14924, 17087, 17563, 19726,
-    15442, 17605, 18081, 20244, 18502, 20665, 21141, 23304, 15442, 17605, 18081,
-    20244, 18502, 20665, 21141, 23304, 19020, 21183, 21659, 23822, 22080, 24243,
-    24719, 26882, 8286,  10449, 10925, 13088, 11346, 13509, 13985, 16148, 11864,
-    14027, 14503, 16666, 14924, 17087, 17563, 19726, 11864, 14027, 14503, 16666,
-    14924, 17087, 17563, 19726, 15442, 17605, 18081, 20244, 18502, 20665, 21141,
-    23304, 11864, 14027, 14503, 16666, 14924, 17087, 17563, 19726, 15442, 17605,
-    18081, 20244, 18502, 20665, 21141, 23304, 15442, 17605, 18081, 20244, 18502,
-    20665, 21141, 23304, 19020, 21183, 21659, 23822, 22080, 24243, 24719, 26882,
-    12379, 14542, 15018, 17181, 15439, 17602, 18078, 20241, 15957, 18120, 18596,
-    20759, 19017, 21180, 21656, 23819, 15957, 18120, 18596, 20759, 19017, 21180,
-    21656, 23819, 19535, 21698, 22174, 24337, 22595, 24758, 25234, 27397, 15957,
-    18120, 18596, 20759, 19017, 21180, 21656, 23819, 19535, 21698, 22174, 24337,
-    22595, 24758, 25234, 27397, 19535, 21698, 22174, 24337, 22595, 24758, 25234,
-    27397, 23113, 25276, 25752, 27915, 26173, 28336, 28812, 30975, 8286,  10449,
-    10925, 13088, 11346, 13509, 13985, 16148, 11864, 14027, 14503, 16666, 14924,
-    17087, 17563, 19726, 11864, 14027, 14503, 16666, 14924, 17087, 17563, 19726,
-    15442, 17605, 18081, 20244, 18502, 20665, 21141, 23304, 11864, 14027, 14503,
-    16666, 14924, 17087, 17563, 19726, 15442, 17605, 18081, 20244, 18502, 20665,
-    21141, 23304, 15442, 17605, 18081, 20244, 18502, 20665, 21141, 23304, 19020,
-    21183, 21659, 23822, 22080, 24243, 24719, 26882, 12379, 14542, 15018, 17181,
-    15439, 17602, 18078, 20241, 15957, 18120, 18596, 20759, 19017, 21180, 21656,
-    23819, 15957, 18120, 18596, 20759, 19017, 21180, 21656, 23819, 19535, 21698,
-    22174, 24337, 22595, 24758, 25234, 27397, 15957, 18120, 18596, 20759, 19017,
-    21180, 21656, 23819, 19535, 21698, 22174, 24337, 22595, 24758, 25234, 27397,
-    19535, 21698, 22174, 24337, 22595, 24758, 25234, 27397, 23113, 25276, 25752,
-    27915, 26173, 28336, 28812, 30975, 12379, 14542, 15018, 17181, 15439, 17602,
-    18078, 20241, 15957, 18120, 18596, 20759, 19017, 21180, 21656, 23819, 15957,
-    18120, 18596, 20759, 19017, 21180, 21656, 23819, 19535, 21698, 22174, 24337,
-    22595, 24758, 25234, 27397, 15957, 18120, 18596, 20759, 19017, 21180, 21656,
-    23819, 19535, 21698, 22174, 24337, 22595, 24758, 25234, 27397, 19535, 21698,
-    22174, 24337, 22595, 24758, 25234, 27397, 23113, 25276, 25752, 27915, 26173,
-    28336, 28812, 30975, 16472, 18635, 19111, 21274, 19532, 21695, 22171, 24334,
-    20050, 22213, 22689, 24852, 23110, 25273, 25749, 27912, 20050, 22213, 22689,
-    24852, 23110, 25273, 25749, 27912, 23628, 25791, 26267, 28430, 26688, 28851,
-    29327, 31490, 20050, 22213, 22689, 24852, 23110, 25273, 25749, 27912, 23628,
-    25791, 26267, 28430, 26688, 28851, 29327, 31490, 23628, 25791, 26267, 28430,
-    26688, 28851, 29327, 31490, 27206, 29369, 29845, 32008, 30266, 32429, 32905,
-    35068};
-#endif
-
-const vp9_extra_bit vp9_extra_bits[ENTROPY_TOKENS] = {
-  {0, 0, 0, zero_cost},                          // ZERO_TOKEN
-  {0, 0, 1, sign_cost},                          // ONE_TOKEN
-  {0, 0, 2, sign_cost},                          // TWO_TOKEN
-  {0, 0, 3, sign_cost},                          // THREE_TOKEN
-  {0, 0, 4, sign_cost},                          // FOUR_TOKEN
-  {vp9_cat1_prob, 1,  CAT1_MIN_VAL, cat1_cost},  // CATEGORY1_TOKEN
-  {vp9_cat2_prob, 2,  CAT2_MIN_VAL, cat2_cost},  // CATEGORY2_TOKEN
-  {vp9_cat3_prob, 3,  CAT3_MIN_VAL, cat3_cost},  // CATEGORY3_TOKEN
-  {vp9_cat4_prob, 4,  CAT4_MIN_VAL, cat4_cost},  // CATEGORY4_TOKEN
-  {vp9_cat5_prob, 5,  CAT5_MIN_VAL, cat5_cost},  // CATEGORY5_TOKEN
-  {vp9_cat6_prob, 14, CAT6_MIN_VAL, 0},          // CATEGORY6_TOKEN
-  {0, 0, 0, zero_cost}                           // EOB_TOKEN
-};
-
-#if CONFIG_VP9_HIGHBITDEPTH
-const vp9_extra_bit vp9_extra_bits_high10[ENTROPY_TOKENS] = {
-  {0, 0, 0, zero_cost},                             // ZERO
-  {0, 0, 1, sign_cost},                             // ONE
-  {0, 0, 2, sign_cost},                             // TWO
-  {0, 0, 3, sign_cost},                             // THREE
-  {0, 0, 4, sign_cost},                             // FOUR
-  {vp9_cat1_prob, 1,  CAT1_MIN_VAL, cat1_cost},     // CAT1
-  {vp9_cat2_prob, 2,  CAT2_MIN_VAL, cat2_cost},     // CAT2
-  {vp9_cat3_prob, 3,  CAT3_MIN_VAL, cat3_cost},     // CAT3
-  {vp9_cat4_prob, 4,  CAT4_MIN_VAL, cat4_cost},     // CAT4
-  {vp9_cat5_prob, 5,  CAT5_MIN_VAL, cat5_cost},     // CAT5
-  {vp9_cat6_prob_high12 + 2, 16, CAT6_MIN_VAL, 0},  // CAT6
-  {0, 0, 0, zero_cost}                              // EOB
-};
-const vp9_extra_bit vp9_extra_bits_high12[ENTROPY_TOKENS] = {
-  {0, 0, 0, zero_cost},                          // ZERO
-  {0, 0, 1, sign_cost},                          // ONE
-  {0, 0, 2, sign_cost},                          // TWO
-  {0, 0, 3, sign_cost},                          // THREE
-  {0, 0, 4, sign_cost},                          // FOUR
-  {vp9_cat1_prob, 1,  CAT1_MIN_VAL, cat1_cost},  // CAT1
-  {vp9_cat2_prob, 2,  CAT2_MIN_VAL, cat2_cost},  // CAT2
-  {vp9_cat3_prob, 3,  CAT3_MIN_VAL, cat3_cost},  // CAT3
-  {vp9_cat4_prob, 4,  CAT4_MIN_VAL, cat4_cost},  // CAT4
-  {vp9_cat5_prob, 5,  CAT5_MIN_VAL, cat5_cost},  // CAT5
-  {vp9_cat6_prob_high12, 18, CAT6_MIN_VAL, 0},   // CAT6
-  {0, 0, 0, zero_cost}                           // EOB
-};
-#endif
-
-const struct vp9_token vp9_coef_encodings[ENTROPY_TOKENS] = {
-  {2, 2}, {6, 3}, {28, 5}, {58, 6}, {59, 6}, {60, 6}, {61, 6}, {124, 7},
-  {125, 7}, {126, 7}, {127, 7}, {0, 1}
-};
-
-
-struct tokenize_b_args {
-  VP9_COMP *cpi;
-  ThreadData *td;
-  TOKENEXTRA **tp;
-};
-
-static void set_entropy_context_b(int plane, int block, BLOCK_SIZE plane_bsize,
-                                  TX_SIZE tx_size, void *arg) {
-  struct tokenize_b_args* const args = arg;
-  ThreadData *const td = args->td;
-  MACROBLOCK *const x = &td->mb;
-  MACROBLOCKD *const xd = &x->e_mbd;
-  struct macroblock_plane *p = &x->plane[plane];
-  struct macroblockd_plane *pd = &xd->plane[plane];
-  int aoff, loff;
-  txfrm_block_to_raster_xy(plane_bsize, tx_size, block, &aoff, &loff);
-  vp9_set_contexts(xd, pd, plane_bsize, tx_size, p->eobs[block] > 0,
-                   aoff, loff);
-}
-
-static INLINE void add_token(TOKENEXTRA **t, const vpx_prob *context_tree,
-                             int16_t token, EXTRABIT extra,
-                             unsigned int *counts) {
-  (*t)->context_tree = context_tree;
-  (*t)->token = token;
-  (*t)->extra = extra;
-  (*t)++;
-  ++counts[token];
-}
-
-static INLINE void add_token_no_extra(TOKENEXTRA **t,
-                                      const vpx_prob *context_tree,
-                                      int16_t token,
-                                      unsigned int *counts) {
-  (*t)->context_tree = context_tree;
-  (*t)->token = token;
-  (*t)++;
-  ++counts[token];
-}
-
-static void tokenize_b(int plane, int block, BLOCK_SIZE plane_bsize,
-                       TX_SIZE tx_size, void *arg) {
-  struct tokenize_b_args* const args = arg;
-  VP9_COMP *cpi = args->cpi;
-  ThreadData *const td = args->td;
-  MACROBLOCK *const x = &td->mb;
-  MACROBLOCKD *const xd = &x->e_mbd;
-  TOKENEXTRA **tp = args->tp;
-  uint8_t token_cache[32 * 32];
-  struct macroblock_plane *p = &x->plane[plane];
-  struct macroblockd_plane *pd = &xd->plane[plane];
-  MODE_INFO *mi = xd->mi[0];
-  int pt; /* near block/prev token context index */
-  int c;
-  TOKENEXTRA *t = *tp;        /* store tokens starting here */
-  int eob = p->eobs[block];
-  const PLANE_TYPE type = get_plane_type(plane);
-  const tran_low_t *qcoeff = BLOCK_OFFSET(p->qcoeff, block);
-  const int16_t *scan, *nb;
-  const scan_order *so;
-  const int ref = is_inter_block(mi);
-  unsigned int (*const counts)[COEFF_CONTEXTS][ENTROPY_TOKENS] =
-      td->rd_counts.coef_counts[tx_size][type][ref];
-  vpx_prob (*const coef_probs)[COEFF_CONTEXTS][UNCONSTRAINED_NODES] =
-      cpi->common.fc->coef_probs[tx_size][type][ref];
-  unsigned int (*const eob_branch)[COEFF_CONTEXTS] =
-      td->counts->eob_branch[tx_size][type][ref];
-  const uint8_t *const band = get_band_translate(tx_size);
-  const int tx_eob = 16 << (tx_size << 1);
-  int16_t token;
-  EXTRABIT extra;
-  int aoff, loff;
-  txfrm_block_to_raster_xy(plane_bsize, tx_size, block, &aoff, &loff);
-
-  pt = get_entropy_context(tx_size, pd->above_context + aoff,
-                           pd->left_context + loff);
-  so = get_scan(xd, tx_size, type, block);
-  scan = so->scan;
-  nb = so->neighbors;
-  c = 0;
-
-  while (c < eob) {
-    int v = 0;
-    v = qcoeff[scan[c]];
-    ++eob_branch[band[c]][pt];
-
-    while (!v) {
-      add_token_no_extra(&t, coef_probs[band[c]][pt], ZERO_TOKEN,
-                         counts[band[c]][pt]);
-
-      token_cache[scan[c]] = 0;
-      ++c;
-      pt = get_coef_context(nb, token_cache, c);
-      v = qcoeff[scan[c]];
-    }
-
-    vp9_get_token_extra(v, &token, &extra);
-
-    add_token(&t, coef_probs[band[c]][pt], token, extra,
-              counts[band[c]][pt]);
-
-    token_cache[scan[c]] = vp9_pt_energy_class[token];
-    ++c;
-    pt = get_coef_context(nb, token_cache, c);
-  }
-  if (c < tx_eob) {
-    ++eob_branch[band[c]][pt];
-    add_token_no_extra(&t, coef_probs[band[c]][pt], EOB_TOKEN,
-                       counts[band[c]][pt]);
-  }
-
-  *tp = t;
-
-  vp9_set_contexts(xd, pd, plane_bsize, tx_size, c > 0, aoff, loff);
-}
-
-struct is_skippable_args {
-  uint16_t *eobs;
-  int *skippable;
-};
-static void is_skippable(int plane, int block,
-                         BLOCK_SIZE plane_bsize, TX_SIZE tx_size,
-                         void *argv) {
-  struct is_skippable_args *args = argv;
-  (void)plane;
-  (void)plane_bsize;
-  (void)tx_size;
-  args->skippable[0] &= (!args->eobs[block]);
-}
-
-// TODO(yaowu): rewrite and optimize this function to remove the usage of
-//              vp9_foreach_transform_block() and simplify is_skippable().
-int vp9_is_skippable_in_plane(MACROBLOCK *x, BLOCK_SIZE bsize, int plane) {
-  int result = 1;
-  struct is_skippable_args args = {x->plane[plane].eobs, &result};
-  vp9_foreach_transformed_block_in_plane(&x->e_mbd, bsize, plane, is_skippable,
-                                         &args);
-  return result;
-}
-
-static void has_high_freq_coeff(int plane, int block,
-                                BLOCK_SIZE plane_bsize, TX_SIZE tx_size,
-                                void *argv) {
-  struct is_skippable_args *args = argv;
-  int eobs = (tx_size == TX_4X4) ? 3 : 10;
-  (void) plane;
-  (void) plane_bsize;
-
-  *(args->skippable) |= (args->eobs[block] > eobs);
-}
-
-int vp9_has_high_freq_in_plane(MACROBLOCK *x, BLOCK_SIZE bsize, int plane) {
-  int result = 0;
-  struct is_skippable_args args = {x->plane[plane].eobs, &result};
-  vp9_foreach_transformed_block_in_plane(&x->e_mbd, bsize, plane,
-                                         has_high_freq_coeff, &args);
-  return result;
-}
-
-void vp9_tokenize_sb(VP9_COMP *cpi, ThreadData *td, TOKENEXTRA **t,
-                     int dry_run, int seg_skip, BLOCK_SIZE bsize) {
-  MACROBLOCK *const x = &td->mb;
-  MACROBLOCKD *const xd = &x->e_mbd;
-  MODE_INFO *const mi = xd->mi[0];
-  const int ctx = vp9_get_skip_context(xd);
-  struct tokenize_b_args arg = {cpi, td, t};
-
-  if (seg_skip) {
-    assert(mi->skip);
-  }
-
-  if (mi->skip) {
-    if (!dry_run && !seg_skip)
-      ++td->counts->skip[ctx][1];
-    reset_skip_context(xd, bsize);
-    return;
-  }
-
-  if (!dry_run) {
-    ++td->counts->skip[ctx][0];
-    vp9_foreach_transformed_block(xd, bsize, tokenize_b, &arg);
-  } else {
-    vp9_foreach_transformed_block(xd, bsize, set_entropy_context_b, &arg);
-  }
-}
diff --git a/vp9/encoder/vp9_tokenize.h b/vp9/encoder/vp9_tokenize.h
deleted file mode 100644 (file)
index 1caab2a..0000000
+++ /dev/null
@@ -1,139 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#ifndef VP9_ENCODER_VP9_TOKENIZE_H_
-#define VP9_ENCODER_VP9_TOKENIZE_H_
-
-#include "vp9/common/vp9_entropy.h"
-
-#include "vp9/encoder/vp9_block.h"
-#include "vp9/encoder/vp9_treewriter.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define EOSB_TOKEN 127     // Not signalled, encoder only
-
-#if CONFIG_VP9_HIGHBITDEPTH
-  typedef int32_t EXTRABIT;
-#else
-  typedef int16_t EXTRABIT;
-#endif
-
-
-typedef struct {
-  int16_t token;
-  EXTRABIT extra;
-} TOKENVALUE;
-
-typedef struct {
-  const vpx_prob *context_tree;
-  int16_t token;
-  EXTRABIT extra;
-} TOKENEXTRA;
-
-extern const vpx_tree_index vp9_coef_tree[];
-extern const vpx_tree_index vp9_coef_con_tree[];
-extern const struct vp9_token vp9_coef_encodings[];
-
-int vp9_is_skippable_in_plane(MACROBLOCK *x, BLOCK_SIZE bsize, int plane);
-int vp9_has_high_freq_in_plane(MACROBLOCK *x, BLOCK_SIZE bsize, int plane);
-
-struct VP9_COMP;
-struct ThreadData;
-
-void vp9_tokenize_sb(struct VP9_COMP *cpi, struct ThreadData *td,
-                     TOKENEXTRA **t, int dry_run, int seg_skip,
-                     BLOCK_SIZE bsize);
-
-typedef struct {
-  const vpx_prob *prob;
-  int len;
-  int base_val;
-  const int16_t *cost;
-} vp9_extra_bit;
-
-// indexed by token value
-extern const vp9_extra_bit vp9_extra_bits[ENTROPY_TOKENS];
-#if CONFIG_VP9_HIGHBITDEPTH
-extern const vp9_extra_bit vp9_extra_bits_high10[ENTROPY_TOKENS];
-extern const vp9_extra_bit vp9_extra_bits_high12[ENTROPY_TOKENS];
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-
-extern const int16_t *vp9_dct_value_cost_ptr;
-/* TODO: The Token field should be broken out into a separate char array to
- *  improve cache locality, since it's needed for costing when the rest of the
- *  fields are not.
- */
-extern const TOKENVALUE *vp9_dct_value_tokens_ptr;
-extern const TOKENVALUE *vp9_dct_cat_lt_10_value_tokens;
-extern const int *vp9_dct_cat_lt_10_value_cost;
-extern const int16_t vp9_cat6_low_cost[256];
-extern const int vp9_cat6_high_cost[64];
-extern const int vp9_cat6_high10_high_cost[256];
-extern const int vp9_cat6_high12_high_cost[1024];
-static INLINE int vp9_get_cost(int16_t token, EXTRABIT extrabits,
-                               const int *cat6_high_table) {
-  if (token != CATEGORY6_TOKEN)
-    return vp9_extra_bits[token].cost[extrabits >> 1];
-  return vp9_cat6_low_cost[(extrabits >> 1) & 0xff]
-      + cat6_high_table[extrabits >> 9];
-}
-
-#if CONFIG_VP9_HIGHBITDEPTH
-static INLINE const int* vp9_get_high_cost_table(int bit_depth) {
-  return bit_depth == 8 ? vp9_cat6_high_cost
-      : (bit_depth == 10 ? vp9_cat6_high10_high_cost :
-         vp9_cat6_high12_high_cost);
-}
-#else
-static INLINE const int* vp9_get_high_cost_table(int bit_depth) {
-  (void) bit_depth;
-  return vp9_cat6_high_cost;
-}
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-
-static INLINE void vp9_get_token_extra(int v, int16_t *token, EXTRABIT *extra) {
-  if (v >= CAT6_MIN_VAL || v <= -CAT6_MIN_VAL) {
-    *token = CATEGORY6_TOKEN;
-    if (v >= CAT6_MIN_VAL)
-      *extra = 2 * v - 2 * CAT6_MIN_VAL;
-    else
-      *extra = -2 * v - 2 * CAT6_MIN_VAL + 1;
-    return;
-  }
-  *token = vp9_dct_cat_lt_10_value_tokens[v].token;
-  *extra = vp9_dct_cat_lt_10_value_tokens[v].extra;
-}
-static INLINE int16_t vp9_get_token(int v) {
-  if (v >= CAT6_MIN_VAL || v <= -CAT6_MIN_VAL)
-    return 10;
-  return vp9_dct_cat_lt_10_value_tokens[v].token;
-}
-
-static INLINE int vp9_get_token_cost(int v, int16_t *token,
-                                     const int *cat6_high_table) {
-  if (v >= CAT6_MIN_VAL || v <= -CAT6_MIN_VAL) {
-    EXTRABIT extrabits;
-    *token = CATEGORY6_TOKEN;
-    extrabits = abs(v) - CAT6_MIN_VAL;
-    return vp9_cat6_low_cost[extrabits & 0xff] +
-           cat6_high_table[extrabits >> 8];
-  }
-  *token = vp9_dct_cat_lt_10_value_tokens[v].token;
-  return vp9_dct_cat_lt_10_value_cost[v];
-}
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP9_ENCODER_VP9_TOKENIZE_H_
diff --git a/vp9/encoder/vp9_treewriter.c b/vp9/encoder/vp9_treewriter.c
deleted file mode 100644 (file)
index 0fc078e..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#include "vp9/encoder/vp9_treewriter.h"
-
-static void tree2tok(struct vp9_token *tokens, const vpx_tree_index *tree,
-                     int i, int v, int l) {
-  v += v;
-  ++l;
-
-  do {
-    const vpx_tree_index j = tree[i++];
-    if (j <= 0) {
-      tokens[-j].value = v;
-      tokens[-j].len = l;
-    } else {
-      tree2tok(tokens, tree, j, v, l);
-    }
-  } while (++v & 1);
-}
-
-void vp9_tokens_from_tree(struct vp9_token *tokens,
-                          const vpx_tree_index *tree) {
-  tree2tok(tokens, tree, 0, 0, 0);
-}
-
-static unsigned int convert_distribution(unsigned int i, vpx_tree tree,
-                                         unsigned int branch_ct[][2],
-                                         const unsigned int num_events[]) {
-  unsigned int left, right;
-
-  if (tree[i] <= 0)
-    left = num_events[-tree[i]];
-  else
-    left = convert_distribution(tree[i], tree, branch_ct, num_events);
-
-  if (tree[i + 1] <= 0)
-    right = num_events[-tree[i + 1]];
-  else
-    right = convert_distribution(tree[i + 1], tree, branch_ct, num_events);
-
-  branch_ct[i >> 1][0] = left;
-  branch_ct[i >> 1][1] = right;
-  return left + right;
-}
-
-void vp9_tree_probs_from_distribution(vpx_tree tree,
-                                      unsigned int branch_ct[/* n-1 */][2],
-                                      const unsigned int num_events[/* n */]) {
-  convert_distribution(0, tree, branch_ct, num_events);
-}
diff --git a/vp9/encoder/vp9_treewriter.h b/vp9/encoder/vp9_treewriter.h
deleted file mode 100644 (file)
index 0f89350..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#ifndef VP9_ENCODER_VP9_TREEWRITER_H_
-#define VP9_ENCODER_VP9_TREEWRITER_H_
-
-#include "vpx_dsp/bitwriter.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-void vp9_tree_probs_from_distribution(vpx_tree tree,
-                                      unsigned int branch_ct[ /* n - 1 */ ][2],
-                                      const unsigned int num_events[ /* n */ ]);
-
-struct vp9_token {
-  int value;
-  int len;
-};
-
-void vp9_tokens_from_tree(struct vp9_token*, const vpx_tree_index *);
-
-static INLINE void vp9_write_tree(vpx_writer *w, const vpx_tree_index *tree,
-                                  const vpx_prob *probs, int bits, int len,
-                                  vpx_tree_index i) {
-  do {
-    const int bit = (bits >> --len) & 1;
-    vpx_write(w, bit, probs[i >> 1]);
-    i = tree[i + bit];
-  } while (len);
-}
-
-static INLINE void vp9_write_token(vpx_writer *w, const vpx_tree_index *tree,
-                                   const vpx_prob *probs,
-                                   const struct vp9_token *token) {
-  vp9_write_tree(w, tree, probs, token->value, token->len, 0);
-}
-
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
-#endif  // VP9_ENCODER_VP9_TREEWRITER_H_
diff --git a/vp9/encoder/x86/vp9_dct_intrin_sse2.c b/vp9/encoder/x86/vp9_dct_intrin_sse2.c
deleted file mode 100644 (file)
index fa37b6f..0000000
+++ /dev/null
@@ -1,2058 +0,0 @@
-/*
- *  Copyright (c) 2012 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.
- */
-
-#include <assert.h>
-#include <emmintrin.h>  // SSE2
-
-#include "./vp9_rtcd.h"
-#include "./vpx_dsp_rtcd.h"
-#include "vpx_dsp/txfm_common.h"
-#include "vpx_dsp/x86/fwd_txfm_sse2.h"
-#include "vpx_dsp/x86/txfm_common_sse2.h"
-#include "vpx_ports/mem.h"
-
-static INLINE void load_buffer_4x4(const int16_t *input, __m128i *in,
-                                   int stride) {
-  const __m128i k__nonzero_bias_a = _mm_setr_epi16(0, 1, 1, 1, 1, 1, 1, 1);
-  const __m128i k__nonzero_bias_b = _mm_setr_epi16(1, 0, 0, 0, 0, 0, 0, 0);
-  __m128i mask;
-
-  in[0] = _mm_loadl_epi64((const __m128i *)(input + 0 * stride));
-  in[1] = _mm_loadl_epi64((const __m128i *)(input + 1 * stride));
-  in[2] = _mm_loadl_epi64((const __m128i *)(input + 2 * stride));
-  in[3] = _mm_loadl_epi64((const __m128i *)(input + 3 * stride));
-
-  in[0] = _mm_slli_epi16(in[0], 4);
-  in[1] = _mm_slli_epi16(in[1], 4);
-  in[2] = _mm_slli_epi16(in[2], 4);
-  in[3] = _mm_slli_epi16(in[3], 4);
-
-  mask = _mm_cmpeq_epi16(in[0], k__nonzero_bias_a);
-  in[0] = _mm_add_epi16(in[0], mask);
-  in[0] = _mm_add_epi16(in[0], k__nonzero_bias_b);
-}
-
-static INLINE void write_buffer_4x4(tran_low_t *output, __m128i *res) {
-  const __m128i kOne = _mm_set1_epi16(1);
-  __m128i in01 = _mm_unpacklo_epi64(res[0], res[1]);
-  __m128i in23 = _mm_unpacklo_epi64(res[2], res[3]);
-  __m128i out01 = _mm_add_epi16(in01, kOne);
-  __m128i out23 = _mm_add_epi16(in23, kOne);
-  out01 = _mm_srai_epi16(out01, 2);
-  out23 = _mm_srai_epi16(out23, 2);
-  store_output(&out01, (output + 0 * 8));
-  store_output(&out23, (output + 1 * 8));
-}
-
-static INLINE void transpose_4x4(__m128i *res) {
-  // Combine and transpose
-  // 00 01 02 03 20 21 22 23
-  // 10 11 12 13 30 31 32 33
-  const __m128i tr0_0 = _mm_unpacklo_epi16(res[0], res[1]);
-  const __m128i tr0_1 = _mm_unpackhi_epi16(res[0], res[1]);
-
-  // 00 10 01 11 02 12 03 13
-  // 20 30 21 31 22 32 23 33
-  res[0] = _mm_unpacklo_epi32(tr0_0, tr0_1);
-  res[2] = _mm_unpackhi_epi32(tr0_0, tr0_1);
-
-  // 00 10 20 30 01 11 21 31
-  // 02 12 22 32 03 13 23 33
-  // only use the first 4 16-bit integers
-  res[1] = _mm_unpackhi_epi64(res[0], res[0]);
-  res[3] = _mm_unpackhi_epi64(res[2], res[2]);
-}
-
-static void fdct4_sse2(__m128i *in) {
-  const __m128i k__cospi_p16_p16 = _mm_set1_epi16((int16_t)cospi_16_64);
-  const __m128i k__cospi_p16_m16 = pair_set_epi16(cospi_16_64, -cospi_16_64);
-  const __m128i k__cospi_p08_p24 = pair_set_epi16(cospi_8_64, cospi_24_64);
-  const __m128i k__cospi_p24_m08 = pair_set_epi16(cospi_24_64, -cospi_8_64);
-  const __m128i k__DCT_CONST_ROUNDING = _mm_set1_epi32(DCT_CONST_ROUNDING);
-
-  __m128i u[4], v[4];
-  u[0]=_mm_unpacklo_epi16(in[0], in[1]);
-  u[1]=_mm_unpacklo_epi16(in[3], in[2]);
-
-  v[0] = _mm_add_epi16(u[0], u[1]);
-  v[1] = _mm_sub_epi16(u[0], u[1]);
-
-  u[0] = _mm_madd_epi16(v[0], k__cospi_p16_p16);  // 0
-  u[1] = _mm_madd_epi16(v[0], k__cospi_p16_m16);  // 2
-  u[2] = _mm_madd_epi16(v[1], k__cospi_p08_p24);  // 1
-  u[3] = _mm_madd_epi16(v[1], k__cospi_p24_m08);  // 3
-
-  v[0] = _mm_add_epi32(u[0], k__DCT_CONST_ROUNDING);
-  v[1] = _mm_add_epi32(u[1], k__DCT_CONST_ROUNDING);
-  v[2] = _mm_add_epi32(u[2], k__DCT_CONST_ROUNDING);
-  v[3] = _mm_add_epi32(u[3], k__DCT_CONST_ROUNDING);
-  u[0] = _mm_srai_epi32(v[0], DCT_CONST_BITS);
-  u[1] = _mm_srai_epi32(v[1], DCT_CONST_BITS);
-  u[2] = _mm_srai_epi32(v[2], DCT_CONST_BITS);
-  u[3] = _mm_srai_epi32(v[3], DCT_CONST_BITS);
-
-  in[0] = _mm_packs_epi32(u[0], u[1]);
-  in[1] = _mm_packs_epi32(u[2], u[3]);
-  transpose_4x4(in);
-}
-
-static void fadst4_sse2(__m128i *in) {
-  const __m128i k__sinpi_p01_p02 = pair_set_epi16(sinpi_1_9, sinpi_2_9);
-  const __m128i k__sinpi_p04_m01 = pair_set_epi16(sinpi_4_9, -sinpi_1_9);
-  const __m128i k__sinpi_p03_p04 = pair_set_epi16(sinpi_3_9, sinpi_4_9);
-  const __m128i k__sinpi_m03_p02 = pair_set_epi16(-sinpi_3_9, sinpi_2_9);
-  const __m128i k__sinpi_p03_p03 = _mm_set1_epi16((int16_t)sinpi_3_9);
-  const __m128i kZero = _mm_set1_epi16(0);
-  const __m128i k__DCT_CONST_ROUNDING = _mm_set1_epi32(DCT_CONST_ROUNDING);
-  __m128i u[8], v[8];
-  __m128i in7 = _mm_add_epi16(in[0], in[1]);
-
-  u[0] = _mm_unpacklo_epi16(in[0], in[1]);
-  u[1] = _mm_unpacklo_epi16(in[2], in[3]);
-  u[2] = _mm_unpacklo_epi16(in7, kZero);
-  u[3] = _mm_unpacklo_epi16(in[2], kZero);
-  u[4] = _mm_unpacklo_epi16(in[3], kZero);
-
-  v[0] = _mm_madd_epi16(u[0], k__sinpi_p01_p02);  // s0 + s2
-  v[1] = _mm_madd_epi16(u[1], k__sinpi_p03_p04);  // s4 + s5
-  v[2] = _mm_madd_epi16(u[2], k__sinpi_p03_p03);  // x1
-  v[3] = _mm_madd_epi16(u[0], k__sinpi_p04_m01);  // s1 - s3
-  v[4] = _mm_madd_epi16(u[1], k__sinpi_m03_p02);  // -s4 + s6
-  v[5] = _mm_madd_epi16(u[3], k__sinpi_p03_p03);  // s4
-  v[6] = _mm_madd_epi16(u[4], k__sinpi_p03_p03);
-
-  u[0] = _mm_add_epi32(v[0], v[1]);
-  u[1] = _mm_sub_epi32(v[2], v[6]);
-  u[2] = _mm_add_epi32(v[3], v[4]);
-  u[3] = _mm_sub_epi32(u[2], u[0]);
-  u[4] = _mm_slli_epi32(v[5], 2);
-  u[5] = _mm_sub_epi32(u[4], v[5]);
-  u[6] = _mm_add_epi32(u[3], u[5]);
-
-  v[0] = _mm_add_epi32(u[0], k__DCT_CONST_ROUNDING);
-  v[1] = _mm_add_epi32(u[1], k__DCT_CONST_ROUNDING);
-  v[2] = _mm_add_epi32(u[2], k__DCT_CONST_ROUNDING);
-  v[3] = _mm_add_epi32(u[6], k__DCT_CONST_ROUNDING);
-
-  u[0] = _mm_srai_epi32(v[0], DCT_CONST_BITS);
-  u[1] = _mm_srai_epi32(v[1], DCT_CONST_BITS);
-  u[2] = _mm_srai_epi32(v[2], DCT_CONST_BITS);
-  u[3] = _mm_srai_epi32(v[3], DCT_CONST_BITS);
-
-  in[0] = _mm_packs_epi32(u[0], u[2]);
-  in[1] = _mm_packs_epi32(u[1], u[3]);
-  transpose_4x4(in);
-}
-
-void vp9_fht4x4_sse2(const int16_t *input, tran_low_t *output,
-                     int stride, int tx_type) {
-  __m128i in[4];
-
-  switch (tx_type) {
-    case DCT_DCT:
-      vpx_fdct4x4_sse2(input, output, stride);
-      break;
-    case ADST_DCT:
-      load_buffer_4x4(input, in, stride);
-      fadst4_sse2(in);
-      fdct4_sse2(in);
-      write_buffer_4x4(output, in);
-      break;
-    case DCT_ADST:
-      load_buffer_4x4(input, in, stride);
-      fdct4_sse2(in);
-      fadst4_sse2(in);
-      write_buffer_4x4(output, in);
-      break;
-    case ADST_ADST:
-      load_buffer_4x4(input, in, stride);
-      fadst4_sse2(in);
-      fadst4_sse2(in);
-      write_buffer_4x4(output, in);
-      break;
-   default:
-     assert(0);
-     break;
-  }
-}
-
-void vp9_fdct8x8_quant_sse2(const int16_t *input, int stride,
-                            int16_t* coeff_ptr, intptr_t n_coeffs,
-                            int skip_block, const int16_t* zbin_ptr,
-                            const int16_t* round_ptr, const int16_t* quant_ptr,
-                            const int16_t* quant_shift_ptr, int16_t* qcoeff_ptr,
-                            int16_t* dqcoeff_ptr, const int16_t* dequant_ptr,
-                            uint16_t* eob_ptr,
-                            const int16_t* scan_ptr,
-                            const int16_t* iscan_ptr) {
-  __m128i zero;
-  int pass;
-  // Constants
-  //    When we use them, in one case, they are all the same. In all others
-  //    it's a pair of them that we need to repeat four times. This is done
-  //    by constructing the 32 bit constant corresponding to that pair.
-  const __m128i k__cospi_p16_p16 = _mm_set1_epi16((int16_t)cospi_16_64);
-  const __m128i k__cospi_p16_m16 = pair_set_epi16(cospi_16_64, -cospi_16_64);
-  const __m128i k__cospi_p24_p08 = pair_set_epi16(cospi_24_64, cospi_8_64);
-  const __m128i k__cospi_m08_p24 = pair_set_epi16(-cospi_8_64, cospi_24_64);
-  const __m128i k__cospi_p28_p04 = pair_set_epi16(cospi_28_64, cospi_4_64);
-  const __m128i k__cospi_m04_p28 = pair_set_epi16(-cospi_4_64, cospi_28_64);
-  const __m128i k__cospi_p12_p20 = pair_set_epi16(cospi_12_64, cospi_20_64);
-  const __m128i k__cospi_m20_p12 = pair_set_epi16(-cospi_20_64, cospi_12_64);
-  const __m128i k__DCT_CONST_ROUNDING = _mm_set1_epi32(DCT_CONST_ROUNDING);
-  // Load input
-  __m128i in0  = _mm_load_si128((const __m128i *)(input + 0 * stride));
-  __m128i in1  = _mm_load_si128((const __m128i *)(input + 1 * stride));
-  __m128i in2  = _mm_load_si128((const __m128i *)(input + 2 * stride));
-  __m128i in3  = _mm_load_si128((const __m128i *)(input + 3 * stride));
-  __m128i in4  = _mm_load_si128((const __m128i *)(input + 4 * stride));
-  __m128i in5  = _mm_load_si128((const __m128i *)(input + 5 * stride));
-  __m128i in6  = _mm_load_si128((const __m128i *)(input + 6 * stride));
-  __m128i in7  = _mm_load_si128((const __m128i *)(input + 7 * stride));
-  __m128i *in[8];
-  int index = 0;
-
-  (void)scan_ptr;
-  (void)zbin_ptr;
-  (void)quant_shift_ptr;
-  (void)coeff_ptr;
-
-  // Pre-condition input (shift by two)
-  in0 = _mm_slli_epi16(in0, 2);
-  in1 = _mm_slli_epi16(in1, 2);
-  in2 = _mm_slli_epi16(in2, 2);
-  in3 = _mm_slli_epi16(in3, 2);
-  in4 = _mm_slli_epi16(in4, 2);
-  in5 = _mm_slli_epi16(in5, 2);
-  in6 = _mm_slli_epi16(in6, 2);
-  in7 = _mm_slli_epi16(in7, 2);
-
-  in[0] = &in0;
-  in[1] = &in1;
-  in[2] = &in2;
-  in[3] = &in3;
-  in[4] = &in4;
-  in[5] = &in5;
-  in[6] = &in6;
-  in[7] = &in7;
-
-  // We do two passes, first the columns, then the rows. The results of the
-  // first pass are transposed so that the same column code can be reused. The
-  // results of the second pass are also transposed so that the rows (processed
-  // as columns) are put back in row positions.
-  for (pass = 0; pass < 2; pass++) {
-    // To store results of each pass before the transpose.
-    __m128i res0, res1, res2, res3, res4, res5, res6, res7;
-    // Add/subtract
-    const __m128i q0 = _mm_add_epi16(in0, in7);
-    const __m128i q1 = _mm_add_epi16(in1, in6);
-    const __m128i q2 = _mm_add_epi16(in2, in5);
-    const __m128i q3 = _mm_add_epi16(in3, in4);
-    const __m128i q4 = _mm_sub_epi16(in3, in4);
-    const __m128i q5 = _mm_sub_epi16(in2, in5);
-    const __m128i q6 = _mm_sub_epi16(in1, in6);
-    const __m128i q7 = _mm_sub_epi16(in0, in7);
-    // Work on first four results
-    {
-      // Add/subtract
-      const __m128i r0 = _mm_add_epi16(q0, q3);
-      const __m128i r1 = _mm_add_epi16(q1, q2);
-      const __m128i r2 = _mm_sub_epi16(q1, q2);
-      const __m128i r3 = _mm_sub_epi16(q0, q3);
-      // Interleave to do the multiply by constants which gets us into 32bits
-      const __m128i t0 = _mm_unpacklo_epi16(r0, r1);
-      const __m128i t1 = _mm_unpackhi_epi16(r0, r1);
-      const __m128i t2 = _mm_unpacklo_epi16(r2, r3);
-      const __m128i t3 = _mm_unpackhi_epi16(r2, r3);
-      const __m128i u0 = _mm_madd_epi16(t0, k__cospi_p16_p16);
-      const __m128i u1 = _mm_madd_epi16(t1, k__cospi_p16_p16);
-      const __m128i u2 = _mm_madd_epi16(t0, k__cospi_p16_m16);
-      const __m128i u3 = _mm_madd_epi16(t1, k__cospi_p16_m16);
-      const __m128i u4 = _mm_madd_epi16(t2, k__cospi_p24_p08);
-      const __m128i u5 = _mm_madd_epi16(t3, k__cospi_p24_p08);
-      const __m128i u6 = _mm_madd_epi16(t2, k__cospi_m08_p24);
-      const __m128i u7 = _mm_madd_epi16(t3, k__cospi_m08_p24);
-      // dct_const_round_shift
-      const __m128i v0 = _mm_add_epi32(u0, k__DCT_CONST_ROUNDING);
-      const __m128i v1 = _mm_add_epi32(u1, k__DCT_CONST_ROUNDING);
-      const __m128i v2 = _mm_add_epi32(u2, k__DCT_CONST_ROUNDING);
-      const __m128i v3 = _mm_add_epi32(u3, k__DCT_CONST_ROUNDING);
-      const __m128i v4 = _mm_add_epi32(u4, k__DCT_CONST_ROUNDING);
-      const __m128i v5 = _mm_add_epi32(u5, k__DCT_CONST_ROUNDING);
-      const __m128i v6 = _mm_add_epi32(u6, k__DCT_CONST_ROUNDING);
-      const __m128i v7 = _mm_add_epi32(u7, k__DCT_CONST_ROUNDING);
-      const __m128i w0 = _mm_srai_epi32(v0, DCT_CONST_BITS);
-      const __m128i w1 = _mm_srai_epi32(v1, DCT_CONST_BITS);
-      const __m128i w2 = _mm_srai_epi32(v2, DCT_CONST_BITS);
-      const __m128i w3 = _mm_srai_epi32(v3, DCT_CONST_BITS);
-      const __m128i w4 = _mm_srai_epi32(v4, DCT_CONST_BITS);
-      const __m128i w5 = _mm_srai_epi32(v5, DCT_CONST_BITS);
-      const __m128i w6 = _mm_srai_epi32(v6, DCT_CONST_BITS);
-      const __m128i w7 = _mm_srai_epi32(v7, DCT_CONST_BITS);
-      // Combine
-      res0 = _mm_packs_epi32(w0, w1);
-      res4 = _mm_packs_epi32(w2, w3);
-      res2 = _mm_packs_epi32(w4, w5);
-      res6 = _mm_packs_epi32(w6, w7);
-    }
-    // Work on next four results
-    {
-      // Interleave to do the multiply by constants which gets us into 32bits
-      const __m128i d0 = _mm_unpacklo_epi16(q6, q5);
-      const __m128i d1 = _mm_unpackhi_epi16(q6, q5);
-      const __m128i e0 = _mm_madd_epi16(d0, k__cospi_p16_m16);
-      const __m128i e1 = _mm_madd_epi16(d1, k__cospi_p16_m16);
-      const __m128i e2 = _mm_madd_epi16(d0, k__cospi_p16_p16);
-      const __m128i e3 = _mm_madd_epi16(d1, k__cospi_p16_p16);
-      // dct_const_round_shift
-      const __m128i f0 = _mm_add_epi32(e0, k__DCT_CONST_ROUNDING);
-      const __m128i f1 = _mm_add_epi32(e1, k__DCT_CONST_ROUNDING);
-      const __m128i f2 = _mm_add_epi32(e2, k__DCT_CONST_ROUNDING);
-      const __m128i f3 = _mm_add_epi32(e3, k__DCT_CONST_ROUNDING);
-      const __m128i s0 = _mm_srai_epi32(f0, DCT_CONST_BITS);
-      const __m128i s1 = _mm_srai_epi32(f1, DCT_CONST_BITS);
-      const __m128i s2 = _mm_srai_epi32(f2, DCT_CONST_BITS);
-      const __m128i s3 = _mm_srai_epi32(f3, DCT_CONST_BITS);
-      // Combine
-      const __m128i r0 = _mm_packs_epi32(s0, s1);
-      const __m128i r1 = _mm_packs_epi32(s2, s3);
-      // Add/subtract
-      const __m128i x0 = _mm_add_epi16(q4, r0);
-      const __m128i x1 = _mm_sub_epi16(q4, r0);
-      const __m128i x2 = _mm_sub_epi16(q7, r1);
-      const __m128i x3 = _mm_add_epi16(q7, r1);
-      // Interleave to do the multiply by constants which gets us into 32bits
-      const __m128i t0 = _mm_unpacklo_epi16(x0, x3);
-      const __m128i t1 = _mm_unpackhi_epi16(x0, x3);
-      const __m128i t2 = _mm_unpacklo_epi16(x1, x2);
-      const __m128i t3 = _mm_unpackhi_epi16(x1, x2);
-      const __m128i u0 = _mm_madd_epi16(t0, k__cospi_p28_p04);
-      const __m128i u1 = _mm_madd_epi16(t1, k__cospi_p28_p04);
-      const __m128i u2 = _mm_madd_epi16(t0, k__cospi_m04_p28);
-      const __m128i u3 = _mm_madd_epi16(t1, k__cospi_m04_p28);
-      const __m128i u4 = _mm_madd_epi16(t2, k__cospi_p12_p20);
-      const __m128i u5 = _mm_madd_epi16(t3, k__cospi_p12_p20);
-      const __m128i u6 = _mm_madd_epi16(t2, k__cospi_m20_p12);
-      const __m128i u7 = _mm_madd_epi16(t3, k__cospi_m20_p12);
-      // dct_const_round_shift
-      const __m128i v0 = _mm_add_epi32(u0, k__DCT_CONST_ROUNDING);
-      const __m128i v1 = _mm_add_epi32(u1, k__DCT_CONST_ROUNDING);
-      const __m128i v2 = _mm_add_epi32(u2, k__DCT_CONST_ROUNDING);
-      const __m128i v3 = _mm_add_epi32(u3, k__DCT_CONST_ROUNDING);
-      const __m128i v4 = _mm_add_epi32(u4, k__DCT_CONST_ROUNDING);
-      const __m128i v5 = _mm_add_epi32(u5, k__DCT_CONST_ROUNDING);
-      const __m128i v6 = _mm_add_epi32(u6, k__DCT_CONST_ROUNDING);
-      const __m128i v7 = _mm_add_epi32(u7, k__DCT_CONST_ROUNDING);
-      const __m128i w0 = _mm_srai_epi32(v0, DCT_CONST_BITS);
-      const __m128i w1 = _mm_srai_epi32(v1, DCT_CONST_BITS);
-      const __m128i w2 = _mm_srai_epi32(v2, DCT_CONST_BITS);
-      const __m128i w3 = _mm_srai_epi32(v3, DCT_CONST_BITS);
-      const __m128i w4 = _mm_srai_epi32(v4, DCT_CONST_BITS);
-      const __m128i w5 = _mm_srai_epi32(v5, DCT_CONST_BITS);
-      const __m128i w6 = _mm_srai_epi32(v6, DCT_CONST_BITS);
-      const __m128i w7 = _mm_srai_epi32(v7, DCT_CONST_BITS);
-      // Combine
-      res1 = _mm_packs_epi32(w0, w1);
-      res7 = _mm_packs_epi32(w2, w3);
-      res5 = _mm_packs_epi32(w4, w5);
-      res3 = _mm_packs_epi32(w6, w7);
-    }
-    // Transpose the 8x8.
-    {
-      // 00 01 02 03 04 05 06 07
-      // 10 11 12 13 14 15 16 17
-      // 20 21 22 23 24 25 26 27
-      // 30 31 32 33 34 35 36 37
-      // 40 41 42 43 44 45 46 47
-      // 50 51 52 53 54 55 56 57
-      // 60 61 62 63 64 65 66 67
-      // 70 71 72 73 74 75 76 77
-      const __m128i tr0_0 = _mm_unpacklo_epi16(res0, res1);
-      const __m128i tr0_1 = _mm_unpacklo_epi16(res2, res3);
-      const __m128i tr0_2 = _mm_unpackhi_epi16(res0, res1);
-      const __m128i tr0_3 = _mm_unpackhi_epi16(res2, res3);
-      const __m128i tr0_4 = _mm_unpacklo_epi16(res4, res5);
-      const __m128i tr0_5 = _mm_unpacklo_epi16(res6, res7);
-      const __m128i tr0_6 = _mm_unpackhi_epi16(res4, res5);
-      const __m128i tr0_7 = _mm_unpackhi_epi16(res6, res7);
-      // 00 10 01 11 02 12 03 13
-      // 20 30 21 31 22 32 23 33
-      // 04 14 05 15 06 16 07 17
-      // 24 34 25 35 26 36 27 37
-      // 40 50 41 51 42 52 43 53
-      // 60 70 61 71 62 72 63 73
-      // 54 54 55 55 56 56 57 57
-      // 64 74 65 75 66 76 67 77
-      const __m128i tr1_0 = _mm_unpacklo_epi32(tr0_0, tr0_1);
-      const __m128i tr1_1 = _mm_unpacklo_epi32(tr0_2, tr0_3);
-      const __m128i tr1_2 = _mm_unpackhi_epi32(tr0_0, tr0_1);
-      const __m128i tr1_3 = _mm_unpackhi_epi32(tr0_2, tr0_3);
-      const __m128i tr1_4 = _mm_unpacklo_epi32(tr0_4, tr0_5);
-      const __m128i tr1_5 = _mm_unpacklo_epi32(tr0_6, tr0_7);
-      const __m128i tr1_6 = _mm_unpackhi_epi32(tr0_4, tr0_5);
-      const __m128i tr1_7 = _mm_unpackhi_epi32(tr0_6, tr0_7);
-      // 00 10 20 30 01 11 21 31
-      // 40 50 60 70 41 51 61 71
-      // 02 12 22 32 03 13 23 33
-      // 42 52 62 72 43 53 63 73
-      // 04 14 24 34 05 15 21 36
-      // 44 54 64 74 45 55 61 76
-      // 06 16 26 36 07 17 27 37
-      // 46 56 66 76 47 57 67 77
-      in0 = _mm_unpacklo_epi64(tr1_0, tr1_4);
-      in1 = _mm_unpackhi_epi64(tr1_0, tr1_4);
-      in2 = _mm_unpacklo_epi64(tr1_2, tr1_6);
-      in3 = _mm_unpackhi_epi64(tr1_2, tr1_6);
-      in4 = _mm_unpacklo_epi64(tr1_1, tr1_5);
-      in5 = _mm_unpackhi_epi64(tr1_1, tr1_5);
-      in6 = _mm_unpacklo_epi64(tr1_3, tr1_7);
-      in7 = _mm_unpackhi_epi64(tr1_3, tr1_7);
-      // 00 10 20 30 40 50 60 70
-      // 01 11 21 31 41 51 61 71
-      // 02 12 22 32 42 52 62 72
-      // 03 13 23 33 43 53 63 73
-      // 04 14 24 34 44 54 64 74
-      // 05 15 25 35 45 55 65 75
-      // 06 16 26 36 46 56 66 76
-      // 07 17 27 37 47 57 67 77
-    }
-  }
-  // Post-condition output and store it
-  {
-    // Post-condition (division by two)
-    //    division of two 16 bits signed numbers using shifts
-    //    n / 2 = (n - (n >> 15)) >> 1
-    const __m128i sign_in0 = _mm_srai_epi16(in0, 15);
-    const __m128i sign_in1 = _mm_srai_epi16(in1, 15);
-    const __m128i sign_in2 = _mm_srai_epi16(in2, 15);
-    const __m128i sign_in3 = _mm_srai_epi16(in3, 15);
-    const __m128i sign_in4 = _mm_srai_epi16(in4, 15);
-    const __m128i sign_in5 = _mm_srai_epi16(in5, 15);
-    const __m128i sign_in6 = _mm_srai_epi16(in6, 15);
-    const __m128i sign_in7 = _mm_srai_epi16(in7, 15);
-    in0 = _mm_sub_epi16(in0, sign_in0);
-    in1 = _mm_sub_epi16(in1, sign_in1);
-    in2 = _mm_sub_epi16(in2, sign_in2);
-    in3 = _mm_sub_epi16(in3, sign_in3);
-    in4 = _mm_sub_epi16(in4, sign_in4);
-    in5 = _mm_sub_epi16(in5, sign_in5);
-    in6 = _mm_sub_epi16(in6, sign_in6);
-    in7 = _mm_sub_epi16(in7, sign_in7);
-    in0 = _mm_srai_epi16(in0, 1);
-    in1 = _mm_srai_epi16(in1, 1);
-    in2 = _mm_srai_epi16(in2, 1);
-    in3 = _mm_srai_epi16(in3, 1);
-    in4 = _mm_srai_epi16(in4, 1);
-    in5 = _mm_srai_epi16(in5, 1);
-    in6 = _mm_srai_epi16(in6, 1);
-    in7 = _mm_srai_epi16(in7, 1);
-  }
-
-  iscan_ptr += n_coeffs;
-  qcoeff_ptr += n_coeffs;
-  dqcoeff_ptr += n_coeffs;
-  n_coeffs = -n_coeffs;
-  zero = _mm_setzero_si128();
-
-  if (!skip_block) {
-    __m128i eob;
-    __m128i round, quant, dequant;
-    {
-      __m128i coeff0, coeff1;
-
-      // Setup global values
-      {
-        round = _mm_load_si128((const __m128i*)round_ptr);
-        quant = _mm_load_si128((const __m128i*)quant_ptr);
-        dequant = _mm_load_si128((const __m128i*)dequant_ptr);
-      }
-
-      {
-        __m128i coeff0_sign, coeff1_sign;
-        __m128i qcoeff0, qcoeff1;
-        __m128i qtmp0, qtmp1;
-        // Do DC and first 15 AC
-        coeff0 = *in[0];
-        coeff1 = *in[1];
-
-        // Poor man's sign extract
-        coeff0_sign = _mm_srai_epi16(coeff0, 15);
-        coeff1_sign = _mm_srai_epi16(coeff1, 15);
-        qcoeff0 = _mm_xor_si128(coeff0, coeff0_sign);
-        qcoeff1 = _mm_xor_si128(coeff1, coeff1_sign);
-        qcoeff0 = _mm_sub_epi16(qcoeff0, coeff0_sign);
-        qcoeff1 = _mm_sub_epi16(qcoeff1, coeff1_sign);
-
-        qcoeff0 = _mm_adds_epi16(qcoeff0, round);
-        round = _mm_unpackhi_epi64(round, round);
-        qcoeff1 = _mm_adds_epi16(qcoeff1, round);
-        qtmp0 = _mm_mulhi_epi16(qcoeff0, quant);
-        quant = _mm_unpackhi_epi64(quant, quant);
-        qtmp1 = _mm_mulhi_epi16(qcoeff1, quant);
-
-        // Reinsert signs
-        qcoeff0 = _mm_xor_si128(qtmp0, coeff0_sign);
-        qcoeff1 = _mm_xor_si128(qtmp1, coeff1_sign);
-        qcoeff0 = _mm_sub_epi16(qcoeff0, coeff0_sign);
-        qcoeff1 = _mm_sub_epi16(qcoeff1, coeff1_sign);
-
-        _mm_store_si128((__m128i*)(qcoeff_ptr + n_coeffs), qcoeff0);
-        _mm_store_si128((__m128i*)(qcoeff_ptr + n_coeffs) + 1, qcoeff1);
-
-        coeff0 = _mm_mullo_epi16(qcoeff0, dequant);
-        dequant = _mm_unpackhi_epi64(dequant, dequant);
-        coeff1 = _mm_mullo_epi16(qcoeff1, dequant);
-
-        _mm_store_si128((__m128i*)(dqcoeff_ptr + n_coeffs), coeff0);
-        _mm_store_si128((__m128i*)(dqcoeff_ptr + n_coeffs) + 1, coeff1);
-      }
-
-      {
-        // Scan for eob
-        __m128i zero_coeff0, zero_coeff1;
-        __m128i nzero_coeff0, nzero_coeff1;
-        __m128i iscan0, iscan1;
-        __m128i eob1;
-        zero_coeff0 = _mm_cmpeq_epi16(coeff0, zero);
-        zero_coeff1 = _mm_cmpeq_epi16(coeff1, zero);
-        nzero_coeff0 = _mm_cmpeq_epi16(zero_coeff0, zero);
-        nzero_coeff1 = _mm_cmpeq_epi16(zero_coeff1, zero);
-        iscan0 = _mm_load_si128((const __m128i*)(iscan_ptr + n_coeffs));
-        iscan1 = _mm_load_si128((const __m128i*)(iscan_ptr + n_coeffs) + 1);
-        // Add one to convert from indices to counts
-        iscan0 = _mm_sub_epi16(iscan0, nzero_coeff0);
-        iscan1 = _mm_sub_epi16(iscan1, nzero_coeff1);
-        eob = _mm_and_si128(iscan0, nzero_coeff0);
-        eob1 = _mm_and_si128(iscan1, nzero_coeff1);
-        eob = _mm_max_epi16(eob, eob1);
-      }
-      n_coeffs += 8 * 2;
-    }
-
-    // AC only loop
-    index = 2;
-    while (n_coeffs < 0) {
-      __m128i coeff0, coeff1;
-      {
-        __m128i coeff0_sign, coeff1_sign;
-        __m128i qcoeff0, qcoeff1;
-        __m128i qtmp0, qtmp1;
-
-        assert(index < (int)(sizeof(in) / sizeof(in[0])) - 1);
-        coeff0 = *in[index];
-        coeff1 = *in[index + 1];
-
-        // Poor man's sign extract
-        coeff0_sign = _mm_srai_epi16(coeff0, 15);
-        coeff1_sign = _mm_srai_epi16(coeff1, 15);
-        qcoeff0 = _mm_xor_si128(coeff0, coeff0_sign);
-        qcoeff1 = _mm_xor_si128(coeff1, coeff1_sign);
-        qcoeff0 = _mm_sub_epi16(qcoeff0, coeff0_sign);
-        qcoeff1 = _mm_sub_epi16(qcoeff1, coeff1_sign);
-
-        qcoeff0 = _mm_adds_epi16(qcoeff0, round);
-        qcoeff1 = _mm_adds_epi16(qcoeff1, round);
-        qtmp0 = _mm_mulhi_epi16(qcoeff0, quant);
-        qtmp1 = _mm_mulhi_epi16(qcoeff1, quant);
-
-        // Reinsert signs
-        qcoeff0 = _mm_xor_si128(qtmp0, coeff0_sign);
-        qcoeff1 = _mm_xor_si128(qtmp1, coeff1_sign);
-        qcoeff0 = _mm_sub_epi16(qcoeff0, coeff0_sign);
-        qcoeff1 = _mm_sub_epi16(qcoeff1, coeff1_sign);
-
-        _mm_store_si128((__m128i*)(qcoeff_ptr + n_coeffs), qcoeff0);
-        _mm_store_si128((__m128i*)(qcoeff_ptr + n_coeffs) + 1, qcoeff1);
-
-        coeff0 = _mm_mullo_epi16(qcoeff0, dequant);
-        coeff1 = _mm_mullo_epi16(qcoeff1, dequant);
-
-        _mm_store_si128((__m128i*)(dqcoeff_ptr + n_coeffs), coeff0);
-        _mm_store_si128((__m128i*)(dqcoeff_ptr + n_coeffs) + 1, coeff1);
-      }
-
-      {
-        // Scan for eob
-        __m128i zero_coeff0, zero_coeff1;
-        __m128i nzero_coeff0, nzero_coeff1;
-        __m128i iscan0, iscan1;
-        __m128i eob0, eob1;
-        zero_coeff0 = _mm_cmpeq_epi16(coeff0, zero);
-        zero_coeff1 = _mm_cmpeq_epi16(coeff1, zero);
-        nzero_coeff0 = _mm_cmpeq_epi16(zero_coeff0, zero);
-        nzero_coeff1 = _mm_cmpeq_epi16(zero_coeff1, zero);
-        iscan0 = _mm_load_si128((const __m128i*)(iscan_ptr + n_coeffs));
-        iscan1 = _mm_load_si128((const __m128i*)(iscan_ptr + n_coeffs) + 1);
-        // Add one to convert from indices to counts
-        iscan0 = _mm_sub_epi16(iscan0, nzero_coeff0);
-        iscan1 = _mm_sub_epi16(iscan1, nzero_coeff1);
-        eob0 = _mm_and_si128(iscan0, nzero_coeff0);
-        eob1 = _mm_and_si128(iscan1, nzero_coeff1);
-        eob0 = _mm_max_epi16(eob0, eob1);
-        eob = _mm_max_epi16(eob, eob0);
-      }
-      n_coeffs += 8 * 2;
-      index += 2;
-    }
-
-    // Accumulate EOB
-    {
-      __m128i eob_shuffled;
-      eob_shuffled = _mm_shuffle_epi32(eob, 0xe);
-      eob = _mm_max_epi16(eob, eob_shuffled);
-      eob_shuffled = _mm_shufflelo_epi16(eob, 0xe);
-      eob = _mm_max_epi16(eob, eob_shuffled);
-      eob_shuffled = _mm_shufflelo_epi16(eob, 0x1);
-      eob = _mm_max_epi16(eob, eob_shuffled);
-      *eob_ptr = _mm_extract_epi16(eob, 1);
-    }
-  } else {
-    do {
-      _mm_store_si128((__m128i*)(dqcoeff_ptr + n_coeffs), zero);
-      _mm_store_si128((__m128i*)(dqcoeff_ptr + n_coeffs) + 1, zero);
-      _mm_store_si128((__m128i*)(qcoeff_ptr + n_coeffs), zero);
-      _mm_store_si128((__m128i*)(qcoeff_ptr + n_coeffs) + 1, zero);
-      n_coeffs += 8 * 2;
-    } while (n_coeffs < 0);
-    *eob_ptr = 0;
-  }
-}
-
-// load 8x8 array
-static INLINE void load_buffer_8x8(const int16_t *input, __m128i *in,
-                                   int stride) {
-  in[0]  = _mm_load_si128((const __m128i *)(input + 0 * stride));
-  in[1]  = _mm_load_si128((const __m128i *)(input + 1 * stride));
-  in[2]  = _mm_load_si128((const __m128i *)(input + 2 * stride));
-  in[3]  = _mm_load_si128((const __m128i *)(input + 3 * stride));
-  in[4]  = _mm_load_si128((const __m128i *)(input + 4 * stride));
-  in[5]  = _mm_load_si128((const __m128i *)(input + 5 * stride));
-  in[6]  = _mm_load_si128((const __m128i *)(input + 6 * stride));
-  in[7]  = _mm_load_si128((const __m128i *)(input + 7 * stride));
-
-  in[0] = _mm_slli_epi16(in[0], 2);
-  in[1] = _mm_slli_epi16(in[1], 2);
-  in[2] = _mm_slli_epi16(in[2], 2);
-  in[3] = _mm_slli_epi16(in[3], 2);
-  in[4] = _mm_slli_epi16(in[4], 2);
-  in[5] = _mm_slli_epi16(in[5], 2);
-  in[6] = _mm_slli_epi16(in[6], 2);
-  in[7] = _mm_slli_epi16(in[7], 2);
-}
-
-// right shift and rounding
-static INLINE void right_shift_8x8(__m128i *res, const int bit) {
-  __m128i sign0 = _mm_srai_epi16(res[0], 15);
-  __m128i sign1 = _mm_srai_epi16(res[1], 15);
-  __m128i sign2 = _mm_srai_epi16(res[2], 15);
-  __m128i sign3 = _mm_srai_epi16(res[3], 15);
-  __m128i sign4 = _mm_srai_epi16(res[4], 15);
-  __m128i sign5 = _mm_srai_epi16(res[5], 15);
-  __m128i sign6 = _mm_srai_epi16(res[6], 15);
-  __m128i sign7 = _mm_srai_epi16(res[7], 15);
-
-  if (bit == 2) {
-    const __m128i const_rounding = _mm_set1_epi16(1);
-    res[0] = _mm_add_epi16(res[0], const_rounding);
-    res[1] = _mm_add_epi16(res[1], const_rounding);
-    res[2] = _mm_add_epi16(res[2], const_rounding);
-    res[3] = _mm_add_epi16(res[3], const_rounding);
-    res[4] = _mm_add_epi16(res[4], const_rounding);
-    res[5] = _mm_add_epi16(res[5], const_rounding);
-    res[6] = _mm_add_epi16(res[6], const_rounding);
-    res[7] = _mm_add_epi16(res[7], const_rounding);
-  }
-
-  res[0] = _mm_sub_epi16(res[0], sign0);
-  res[1] = _mm_sub_epi16(res[1], sign1);
-  res[2] = _mm_sub_epi16(res[2], sign2);
-  res[3] = _mm_sub_epi16(res[3], sign3);
-  res[4] = _mm_sub_epi16(res[4], sign4);
-  res[5] = _mm_sub_epi16(res[5], sign5);
-  res[6] = _mm_sub_epi16(res[6], sign6);
-  res[7] = _mm_sub_epi16(res[7], sign7);
-
-  if (bit == 1) {
-    res[0] = _mm_srai_epi16(res[0], 1);
-    res[1] = _mm_srai_epi16(res[1], 1);
-    res[2] = _mm_srai_epi16(res[2], 1);
-    res[3] = _mm_srai_epi16(res[3], 1);
-    res[4] = _mm_srai_epi16(res[4], 1);
-    res[5] = _mm_srai_epi16(res[5], 1);
-    res[6] = _mm_srai_epi16(res[6], 1);
-    res[7] = _mm_srai_epi16(res[7], 1);
-  } else {
-    res[0] = _mm_srai_epi16(res[0], 2);
-    res[1] = _mm_srai_epi16(res[1], 2);
-    res[2] = _mm_srai_epi16(res[2], 2);
-    res[3] = _mm_srai_epi16(res[3], 2);
-    res[4] = _mm_srai_epi16(res[4], 2);
-    res[5] = _mm_srai_epi16(res[5], 2);
-    res[6] = _mm_srai_epi16(res[6], 2);
-    res[7] = _mm_srai_epi16(res[7], 2);
-  }
-}
-
-// write 8x8 array
-static INLINE void write_buffer_8x8(tran_low_t *output, __m128i *res,
-                                    int stride) {
-  store_output(&res[0], (output + 0 * stride));
-  store_output(&res[1], (output + 1 * stride));
-  store_output(&res[2], (output + 2 * stride));
-  store_output(&res[3], (output + 3 * stride));
-  store_output(&res[4], (output + 4 * stride));
-  store_output(&res[5], (output + 5 * stride));
-  store_output(&res[6], (output + 6 * stride));
-  store_output(&res[7], (output + 7 * stride));
-}
-
-// perform in-place transpose
-static INLINE void array_transpose_8x8(__m128i *in, __m128i *res) {
-  const __m128i tr0_0 = _mm_unpacklo_epi16(in[0], in[1]);
-  const __m128i tr0_1 = _mm_unpacklo_epi16(in[2], in[3]);
-  const __m128i tr0_2 = _mm_unpackhi_epi16(in[0], in[1]);
-  const __m128i tr0_3 = _mm_unpackhi_epi16(in[2], in[3]);
-  const __m128i tr0_4 = _mm_unpacklo_epi16(in[4], in[5]);
-  const __m128i tr0_5 = _mm_unpacklo_epi16(in[6], in[7]);
-  const __m128i tr0_6 = _mm_unpackhi_epi16(in[4], in[5]);
-  const __m128i tr0_7 = _mm_unpackhi_epi16(in[6], in[7]);
-  // 00 10 01 11 02 12 03 13
-  // 20 30 21 31 22 32 23 33
-  // 04 14 05 15 06 16 07 17
-  // 24 34 25 35 26 36 27 37
-  // 40 50 41 51 42 52 43 53
-  // 60 70 61 71 62 72 63 73
-  // 44 54 45 55 46 56 47 57
-  // 64 74 65 75 66 76 67 77
-  const __m128i tr1_0 = _mm_unpacklo_epi32(tr0_0, tr0_1);
-  const __m128i tr1_1 = _mm_unpacklo_epi32(tr0_4, tr0_5);
-  const __m128i tr1_2 = _mm_unpackhi_epi32(tr0_0, tr0_1);
-  const __m128i tr1_3 = _mm_unpackhi_epi32(tr0_4, tr0_5);
-  const __m128i tr1_4 = _mm_unpacklo_epi32(tr0_2, tr0_3);
-  const __m128i tr1_5 = _mm_unpacklo_epi32(tr0_6, tr0_7);
-  const __m128i tr1_6 = _mm_unpackhi_epi32(tr0_2, tr0_3);
-  const __m128i tr1_7 = _mm_unpackhi_epi32(tr0_6, tr0_7);
-  // 00 10 20 30 01 11 21 31
-  // 40 50 60 70 41 51 61 71
-  // 02 12 22 32 03 13 23 33
-  // 42 52 62 72 43 53 63 73
-  // 04 14 24 34 05 15 25 35
-  // 44 54 64 74 45 55 65 75
-  // 06 16 26 36 07 17 27 37
-  // 46 56 66 76 47 57 67 77
-  res[0] = _mm_unpacklo_epi64(tr1_0, tr1_1);
-  res[1] = _mm_unpackhi_epi64(tr1_0, tr1_1);
-  res[2] = _mm_unpacklo_epi64(tr1_2, tr1_3);
-  res[3] = _mm_unpackhi_epi64(tr1_2, tr1_3);
-  res[4] = _mm_unpacklo_epi64(tr1_4, tr1_5);
-  res[5] = _mm_unpackhi_epi64(tr1_4, tr1_5);
-  res[6] = _mm_unpacklo_epi64(tr1_6, tr1_7);
-  res[7] = _mm_unpackhi_epi64(tr1_6, tr1_7);
-  // 00 10 20 30 40 50 60 70
-  // 01 11 21 31 41 51 61 71
-  // 02 12 22 32 42 52 62 72
-  // 03 13 23 33 43 53 63 73
-  // 04 14 24 34 44 54 64 74
-  // 05 15 25 35 45 55 65 75
-  // 06 16 26 36 46 56 66 76
-  // 07 17 27 37 47 57 67 77
-}
-
-static void fdct8_sse2(__m128i *in) {
-  // constants
-  const __m128i k__cospi_p16_p16 = _mm_set1_epi16((int16_t)cospi_16_64);
-  const __m128i k__cospi_p16_m16 = pair_set_epi16(cospi_16_64, -cospi_16_64);
-  const __m128i k__cospi_p24_p08 = pair_set_epi16(cospi_24_64, cospi_8_64);
-  const __m128i k__cospi_m08_p24 = pair_set_epi16(-cospi_8_64, cospi_24_64);
-  const __m128i k__cospi_p28_p04 = pair_set_epi16(cospi_28_64, cospi_4_64);
-  const __m128i k__cospi_m04_p28 = pair_set_epi16(-cospi_4_64, cospi_28_64);
-  const __m128i k__cospi_p12_p20 = pair_set_epi16(cospi_12_64, cospi_20_64);
-  const __m128i k__cospi_m20_p12 = pair_set_epi16(-cospi_20_64, cospi_12_64);
-  const __m128i k__DCT_CONST_ROUNDING = _mm_set1_epi32(DCT_CONST_ROUNDING);
-  __m128i u0, u1, u2, u3, u4, u5, u6, u7;
-  __m128i v0, v1, v2, v3, v4, v5, v6, v7;
-  __m128i s0, s1, s2, s3, s4, s5, s6, s7;
-
-  // stage 1
-  s0 = _mm_add_epi16(in[0], in[7]);
-  s1 = _mm_add_epi16(in[1], in[6]);
-  s2 = _mm_add_epi16(in[2], in[5]);
-  s3 = _mm_add_epi16(in[3], in[4]);
-  s4 = _mm_sub_epi16(in[3], in[4]);
-  s5 = _mm_sub_epi16(in[2], in[5]);
-  s6 = _mm_sub_epi16(in[1], in[6]);
-  s7 = _mm_sub_epi16(in[0], in[7]);
-
-  u0 = _mm_add_epi16(s0, s3);
-  u1 = _mm_add_epi16(s1, s2);
-  u2 = _mm_sub_epi16(s1, s2);
-  u3 = _mm_sub_epi16(s0, s3);
-  // interleave and perform butterfly multiplication/addition
-  v0 = _mm_unpacklo_epi16(u0, u1);
-  v1 = _mm_unpackhi_epi16(u0, u1);
-  v2 = _mm_unpacklo_epi16(u2, u3);
-  v3 = _mm_unpackhi_epi16(u2, u3);
-
-  u0 = _mm_madd_epi16(v0, k__cospi_p16_p16);
-  u1 = _mm_madd_epi16(v1, k__cospi_p16_p16);
-  u2 = _mm_madd_epi16(v0, k__cospi_p16_m16);
-  u3 = _mm_madd_epi16(v1, k__cospi_p16_m16);
-  u4 = _mm_madd_epi16(v2, k__cospi_p24_p08);
-  u5 = _mm_madd_epi16(v3, k__cospi_p24_p08);
-  u6 = _mm_madd_epi16(v2, k__cospi_m08_p24);
-  u7 = _mm_madd_epi16(v3, k__cospi_m08_p24);
-
-  // shift and rounding
-  v0 = _mm_add_epi32(u0, k__DCT_CONST_ROUNDING);
-  v1 = _mm_add_epi32(u1, k__DCT_CONST_ROUNDING);
-  v2 = _mm_add_epi32(u2, k__DCT_CONST_ROUNDING);
-  v3 = _mm_add_epi32(u3, k__DCT_CONST_ROUNDING);
-  v4 = _mm_add_epi32(u4, k__DCT_CONST_ROUNDING);
-  v5 = _mm_add_epi32(u5, k__DCT_CONST_ROUNDING);
-  v6 = _mm_add_epi32(u6, k__DCT_CONST_ROUNDING);
-  v7 = _mm_add_epi32(u7, k__DCT_CONST_ROUNDING);
-
-  u0 = _mm_srai_epi32(v0, DCT_CONST_BITS);
-  u1 = _mm_srai_epi32(v1, DCT_CONST_BITS);
-  u2 = _mm_srai_epi32(v2, DCT_CONST_BITS);
-  u3 = _mm_srai_epi32(v3, DCT_CONST_BITS);
-  u4 = _mm_srai_epi32(v4, DCT_CONST_BITS);
-  u5 = _mm_srai_epi32(v5, DCT_CONST_BITS);
-  u6 = _mm_srai_epi32(v6, DCT_CONST_BITS);
-  u7 = _mm_srai_epi32(v7, DCT_CONST_BITS);
-
-  in[0] = _mm_packs_epi32(u0, u1);
-  in[2] = _mm_packs_epi32(u4, u5);
-  in[4] = _mm_packs_epi32(u2, u3);
-  in[6] = _mm_packs_epi32(u6, u7);
-
-  // stage 2
-  // interleave and perform butterfly multiplication/addition
-  u0 = _mm_unpacklo_epi16(s6, s5);
-  u1 = _mm_unpackhi_epi16(s6, s5);
-  v0 = _mm_madd_epi16(u0, k__cospi_p16_m16);
-  v1 = _mm_madd_epi16(u1, k__cospi_p16_m16);
-  v2 = _mm_madd_epi16(u0, k__cospi_p16_p16);
-  v3 = _mm_madd_epi16(u1, k__cospi_p16_p16);
-
-  // shift and rounding
-  u0 = _mm_add_epi32(v0, k__DCT_CONST_ROUNDING);
-  u1 = _mm_add_epi32(v1, k__DCT_CONST_ROUNDING);
-  u2 = _mm_add_epi32(v2, k__DCT_CONST_ROUNDING);
-  u3 = _mm_add_epi32(v3, k__DCT_CONST_ROUNDING);
-
-  v0 = _mm_srai_epi32(u0, DCT_CONST_BITS);
-  v1 = _mm_srai_epi32(u1, DCT_CONST_BITS);
-  v2 = _mm_srai_epi32(u2, DCT_CONST_BITS);
-  v3 = _mm_srai_epi32(u3, DCT_CONST_BITS);
-
-  u0 = _mm_packs_epi32(v0, v1);
-  u1 = _mm_packs_epi32(v2, v3);
-
-  // stage 3
-  s0 = _mm_add_epi16(s4, u0);
-  s1 = _mm_sub_epi16(s4, u0);
-  s2 = _mm_sub_epi16(s7, u1);
-  s3 = _mm_add_epi16(s7, u1);
-
-  // stage 4
-  u0 = _mm_unpacklo_epi16(s0, s3);
-  u1 = _mm_unpackhi_epi16(s0, s3);
-  u2 = _mm_unpacklo_epi16(s1, s2);
-  u3 = _mm_unpackhi_epi16(s1, s2);
-
-  v0 = _mm_madd_epi16(u0, k__cospi_p28_p04);
-  v1 = _mm_madd_epi16(u1, k__cospi_p28_p04);
-  v2 = _mm_madd_epi16(u2, k__cospi_p12_p20);
-  v3 = _mm_madd_epi16(u3, k__cospi_p12_p20);
-  v4 = _mm_madd_epi16(u2, k__cospi_m20_p12);
-  v5 = _mm_madd_epi16(u3, k__cospi_m20_p12);
-  v6 = _mm_madd_epi16(u0, k__cospi_m04_p28);
-  v7 = _mm_madd_epi16(u1, k__cospi_m04_p28);
-
-  // shift and rounding
-  u0 = _mm_add_epi32(v0, k__DCT_CONST_ROUNDING);
-  u1 = _mm_add_epi32(v1, k__DCT_CONST_ROUNDING);
-  u2 = _mm_add_epi32(v2, k__DCT_CONST_ROUNDING);
-  u3 = _mm_add_epi32(v3, k__DCT_CONST_ROUNDING);
-  u4 = _mm_add_epi32(v4, k__DCT_CONST_ROUNDING);
-  u5 = _mm_add_epi32(v5, k__DCT_CONST_ROUNDING);
-  u6 = _mm_add_epi32(v6, k__DCT_CONST_ROUNDING);
-  u7 = _mm_add_epi32(v7, k__DCT_CONST_ROUNDING);
-
-  v0 = _mm_srai_epi32(u0, DCT_CONST_BITS);
-  v1 = _mm_srai_epi32(u1, DCT_CONST_BITS);
-  v2 = _mm_srai_epi32(u2, DCT_CONST_BITS);
-  v3 = _mm_srai_epi32(u3, DCT_CONST_BITS);
-  v4 = _mm_srai_epi32(u4, DCT_CONST_BITS);
-  v5 = _mm_srai_epi32(u5, DCT_CONST_BITS);
-  v6 = _mm_srai_epi32(u6, DCT_CONST_BITS);
-  v7 = _mm_srai_epi32(u7, DCT_CONST_BITS);
-
-  in[1] = _mm_packs_epi32(v0, v1);
-  in[3] = _mm_packs_epi32(v4, v5);
-  in[5] = _mm_packs_epi32(v2, v3);
-  in[7] = _mm_packs_epi32(v6, v7);
-
-  // transpose
-  array_transpose_8x8(in, in);
-}
-
-static void fadst8_sse2(__m128i *in) {
-  // Constants
-  const __m128i k__cospi_p02_p30 = pair_set_epi16(cospi_2_64, cospi_30_64);
-  const __m128i k__cospi_p30_m02 = pair_set_epi16(cospi_30_64, -cospi_2_64);
-  const __m128i k__cospi_p10_p22 = pair_set_epi16(cospi_10_64, cospi_22_64);
-  const __m128i k__cospi_p22_m10 = pair_set_epi16(cospi_22_64, -cospi_10_64);
-  const __m128i k__cospi_p18_p14 = pair_set_epi16(cospi_18_64, cospi_14_64);
-  const __m128i k__cospi_p14_m18 = pair_set_epi16(cospi_14_64, -cospi_18_64);
-  const __m128i k__cospi_p26_p06 = pair_set_epi16(cospi_26_64, cospi_6_64);
-  const __m128i k__cospi_p06_m26 = pair_set_epi16(cospi_6_64, -cospi_26_64);
-  const __m128i k__cospi_p08_p24 = pair_set_epi16(cospi_8_64, cospi_24_64);
-  const __m128i k__cospi_p24_m08 = pair_set_epi16(cospi_24_64, -cospi_8_64);
-  const __m128i k__cospi_m24_p08 = pair_set_epi16(-cospi_24_64, cospi_8_64);
-  const __m128i k__cospi_p16_m16 = pair_set_epi16(cospi_16_64, -cospi_16_64);
-  const __m128i k__cospi_p16_p16 = _mm_set1_epi16((int16_t)cospi_16_64);
-  const __m128i k__const_0 = _mm_set1_epi16(0);
-  const __m128i k__DCT_CONST_ROUNDING = _mm_set1_epi32(DCT_CONST_ROUNDING);
-
-  __m128i u0, u1, u2, u3, u4, u5, u6, u7, u8, u9, u10, u11, u12, u13, u14, u15;
-  __m128i v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15;
-  __m128i w0, w1, w2, w3, w4, w5, w6, w7, w8, w9, w10, w11, w12, w13, w14, w15;
-  __m128i s0, s1, s2, s3, s4, s5, s6, s7;
-  __m128i in0, in1, in2, in3, in4, in5, in6, in7;
-
-  // properly aligned for butterfly input
-  in0  = in[7];
-  in1  = in[0];
-  in2  = in[5];
-  in3  = in[2];
-  in4  = in[3];
-  in5  = in[4];
-  in6  = in[1];
-  in7  = in[6];
-
-  // column transformation
-  // stage 1
-  // interleave and multiply/add into 32-bit integer
-  s0 = _mm_unpacklo_epi16(in0, in1);
-  s1 = _mm_unpackhi_epi16(in0, in1);
-  s2 = _mm_unpacklo_epi16(in2, in3);
-  s3 = _mm_unpackhi_epi16(in2, in3);
-  s4 = _mm_unpacklo_epi16(in4, in5);
-  s5 = _mm_unpackhi_epi16(in4, in5);
-  s6 = _mm_unpacklo_epi16(in6, in7);
-  s7 = _mm_unpackhi_epi16(in6, in7);
-
-  u0 = _mm_madd_epi16(s0, k__cospi_p02_p30);
-  u1 = _mm_madd_epi16(s1, k__cospi_p02_p30);
-  u2 = _mm_madd_epi16(s0, k__cospi_p30_m02);
-  u3 = _mm_madd_epi16(s1, k__cospi_p30_m02);
-  u4 = _mm_madd_epi16(s2, k__cospi_p10_p22);
-  u5 = _mm_madd_epi16(s3, k__cospi_p10_p22);
-  u6 = _mm_madd_epi16(s2, k__cospi_p22_m10);
-  u7 = _mm_madd_epi16(s3, k__cospi_p22_m10);
-  u8 = _mm_madd_epi16(s4, k__cospi_p18_p14);
-  u9 = _mm_madd_epi16(s5, k__cospi_p18_p14);
-  u10 = _mm_madd_epi16(s4, k__cospi_p14_m18);
-  u11 = _mm_madd_epi16(s5, k__cospi_p14_m18);
-  u12 = _mm_madd_epi16(s6, k__cospi_p26_p06);
-  u13 = _mm_madd_epi16(s7, k__cospi_p26_p06);
-  u14 = _mm_madd_epi16(s6, k__cospi_p06_m26);
-  u15 = _mm_madd_epi16(s7, k__cospi_p06_m26);
-
-  // addition
-  w0 = _mm_add_epi32(u0, u8);
-  w1 = _mm_add_epi32(u1, u9);
-  w2 = _mm_add_epi32(u2, u10);
-  w3 = _mm_add_epi32(u3, u11);
-  w4 = _mm_add_epi32(u4, u12);
-  w5 = _mm_add_epi32(u5, u13);
-  w6 = _mm_add_epi32(u6, u14);
-  w7 = _mm_add_epi32(u7, u15);
-  w8 = _mm_sub_epi32(u0, u8);
-  w9 = _mm_sub_epi32(u1, u9);
-  w10 = _mm_sub_epi32(u2, u10);
-  w11 = _mm_sub_epi32(u3, u11);
-  w12 = _mm_sub_epi32(u4, u12);
-  w13 = _mm_sub_epi32(u5, u13);
-  w14 = _mm_sub_epi32(u6, u14);
-  w15 = _mm_sub_epi32(u7, u15);
-
-  // shift and rounding
-  v0 = _mm_add_epi32(w0, k__DCT_CONST_ROUNDING);
-  v1 = _mm_add_epi32(w1, k__DCT_CONST_ROUNDING);
-  v2 = _mm_add_epi32(w2, k__DCT_CONST_ROUNDING);
-  v3 = _mm_add_epi32(w3, k__DCT_CONST_ROUNDING);
-  v4 = _mm_add_epi32(w4, k__DCT_CONST_ROUNDING);
-  v5 = _mm_add_epi32(w5, k__DCT_CONST_ROUNDING);
-  v6 = _mm_add_epi32(w6, k__DCT_CONST_ROUNDING);
-  v7 = _mm_add_epi32(w7, k__DCT_CONST_ROUNDING);
-  v8 = _mm_add_epi32(w8, k__DCT_CONST_ROUNDING);
-  v9 = _mm_add_epi32(w9, k__DCT_CONST_ROUNDING);
-  v10 = _mm_add_epi32(w10, k__DCT_CONST_ROUNDING);
-  v11 = _mm_add_epi32(w11, k__DCT_CONST_ROUNDING);
-  v12 = _mm_add_epi32(w12, k__DCT_CONST_ROUNDING);
-  v13 = _mm_add_epi32(w13, k__DCT_CONST_ROUNDING);
-  v14 = _mm_add_epi32(w14, k__DCT_CONST_ROUNDING);
-  v15 = _mm_add_epi32(w15, k__DCT_CONST_ROUNDING);
-
-  u0 = _mm_srai_epi32(v0, DCT_CONST_BITS);
-  u1 = _mm_srai_epi32(v1, DCT_CONST_BITS);
-  u2 = _mm_srai_epi32(v2, DCT_CONST_BITS);
-  u3 = _mm_srai_epi32(v3, DCT_CONST_BITS);
-  u4 = _mm_srai_epi32(v4, DCT_CONST_BITS);
-  u5 = _mm_srai_epi32(v5, DCT_CONST_BITS);
-  u6 = _mm_srai_epi32(v6, DCT_CONST_BITS);
-  u7 = _mm_srai_epi32(v7, DCT_CONST_BITS);
-  u8 = _mm_srai_epi32(v8, DCT_CONST_BITS);
-  u9 = _mm_srai_epi32(v9, DCT_CONST_BITS);
-  u10 = _mm_srai_epi32(v10, DCT_CONST_BITS);
-  u11 = _mm_srai_epi32(v11, DCT_CONST_BITS);
-  u12 = _mm_srai_epi32(v12, DCT_CONST_BITS);
-  u13 = _mm_srai_epi32(v13, DCT_CONST_BITS);
-  u14 = _mm_srai_epi32(v14, DCT_CONST_BITS);
-  u15 = _mm_srai_epi32(v15, DCT_CONST_BITS);
-
-  // back to 16-bit and pack 8 integers into __m128i
-  in[0] = _mm_packs_epi32(u0, u1);
-  in[1] = _mm_packs_epi32(u2, u3);
-  in[2] = _mm_packs_epi32(u4, u5);
-  in[3] = _mm_packs_epi32(u6, u7);
-  in[4] = _mm_packs_epi32(u8, u9);
-  in[5] = _mm_packs_epi32(u10, u11);
-  in[6] = _mm_packs_epi32(u12, u13);
-  in[7] = _mm_packs_epi32(u14, u15);
-
-  // stage 2
-  s0 = _mm_add_epi16(in[0], in[2]);
-  s1 = _mm_add_epi16(in[1], in[3]);
-  s2 = _mm_sub_epi16(in[0], in[2]);
-  s3 = _mm_sub_epi16(in[1], in[3]);
-  u0 = _mm_unpacklo_epi16(in[4], in[5]);
-  u1 = _mm_unpackhi_epi16(in[4], in[5]);
-  u2 = _mm_unpacklo_epi16(in[6], in[7]);
-  u3 = _mm_unpackhi_epi16(in[6], in[7]);
-
-  v0 = _mm_madd_epi16(u0, k__cospi_p08_p24);
-  v1 = _mm_madd_epi16(u1, k__cospi_p08_p24);
-  v2 = _mm_madd_epi16(u0, k__cospi_p24_m08);
-  v3 = _mm_madd_epi16(u1, k__cospi_p24_m08);
-  v4 = _mm_madd_epi16(u2, k__cospi_m24_p08);
-  v5 = _mm_madd_epi16(u3, k__cospi_m24_p08);
-  v6 = _mm_madd_epi16(u2, k__cospi_p08_p24);
-  v7 = _mm_madd_epi16(u3, k__cospi_p08_p24);
-
-  w0 = _mm_add_epi32(v0, v4);
-  w1 = _mm_add_epi32(v1, v5);
-  w2 = _mm_add_epi32(v2, v6);
-  w3 = _mm_add_epi32(v3, v7);
-  w4 = _mm_sub_epi32(v0, v4);
-  w5 = _mm_sub_epi32(v1, v5);
-  w6 = _mm_sub_epi32(v2, v6);
-  w7 = _mm_sub_epi32(v3, v7);
-
-  v0 = _mm_add_epi32(w0, k__DCT_CONST_ROUNDING);
-  v1 = _mm_add_epi32(w1, k__DCT_CONST_ROUNDING);
-  v2 = _mm_add_epi32(w2, k__DCT_CONST_ROUNDING);
-  v3 = _mm_add_epi32(w3, k__DCT_CONST_ROUNDING);
-  v4 = _mm_add_epi32(w4, k__DCT_CONST_ROUNDING);
-  v5 = _mm_add_epi32(w5, k__DCT_CONST_ROUNDING);
-  v6 = _mm_add_epi32(w6, k__DCT_CONST_ROUNDING);
-  v7 = _mm_add_epi32(w7, k__DCT_CONST_ROUNDING);
-
-  u0 = _mm_srai_epi32(v0, DCT_CONST_BITS);
-  u1 = _mm_srai_epi32(v1, DCT_CONST_BITS);
-  u2 = _mm_srai_epi32(v2, DCT_CONST_BITS);
-  u3 = _mm_srai_epi32(v3, DCT_CONST_BITS);
-  u4 = _mm_srai_epi32(v4, DCT_CONST_BITS);
-  u5 = _mm_srai_epi32(v5, DCT_CONST_BITS);
-  u6 = _mm_srai_epi32(v6, DCT_CONST_BITS);
-  u7 = _mm_srai_epi32(v7, DCT_CONST_BITS);
-
-  // back to 16-bit intergers
-  s4 = _mm_packs_epi32(u0, u1);
-  s5 = _mm_packs_epi32(u2, u3);
-  s6 = _mm_packs_epi32(u4, u5);
-  s7 = _mm_packs_epi32(u6, u7);
-
-  // stage 3
-  u0 = _mm_unpacklo_epi16(s2, s3);
-  u1 = _mm_unpackhi_epi16(s2, s3);
-  u2 = _mm_unpacklo_epi16(s6, s7);
-  u3 = _mm_unpackhi_epi16(s6, s7);
-
-  v0 = _mm_madd_epi16(u0, k__cospi_p16_p16);
-  v1 = _mm_madd_epi16(u1, k__cospi_p16_p16);
-  v2 = _mm_madd_epi16(u0, k__cospi_p16_m16);
-  v3 = _mm_madd_epi16(u1, k__cospi_p16_m16);
-  v4 = _mm_madd_epi16(u2, k__cospi_p16_p16);
-  v5 = _mm_madd_epi16(u3, k__cospi_p16_p16);
-  v6 = _mm_madd_epi16(u2, k__cospi_p16_m16);
-  v7 = _mm_madd_epi16(u3, k__cospi_p16_m16);
-
-  u0 = _mm_add_epi32(v0, k__DCT_CONST_ROUNDING);
-  u1 = _mm_add_epi32(v1, k__DCT_CONST_ROUNDING);
-  u2 = _mm_add_epi32(v2, k__DCT_CONST_ROUNDING);
-  u3 = _mm_add_epi32(v3, k__DCT_CONST_ROUNDING);
-  u4 = _mm_add_epi32(v4, k__DCT_CONST_ROUNDING);
-  u5 = _mm_add_epi32(v5, k__DCT_CONST_ROUNDING);
-  u6 = _mm_add_epi32(v6, k__DCT_CONST_ROUNDING);
-  u7 = _mm_add_epi32(v7, k__DCT_CONST_ROUNDING);
-
-  v0 = _mm_srai_epi32(u0, DCT_CONST_BITS);
-  v1 = _mm_srai_epi32(u1, DCT_CONST_BITS);
-  v2 = _mm_srai_epi32(u2, DCT_CONST_BITS);
-  v3 = _mm_srai_epi32(u3, DCT_CONST_BITS);
-  v4 = _mm_srai_epi32(u4, DCT_CONST_BITS);
-  v5 = _mm_srai_epi32(u5, DCT_CONST_BITS);
-  v6 = _mm_srai_epi32(u6, DCT_CONST_BITS);
-  v7 = _mm_srai_epi32(u7, DCT_CONST_BITS);
-
-  s2 = _mm_packs_epi32(v0, v1);
-  s3 = _mm_packs_epi32(v2, v3);
-  s6 = _mm_packs_epi32(v4, v5);
-  s7 = _mm_packs_epi32(v6, v7);
-
-  // FIXME(jingning): do subtract using bit inversion?
-  in[0] = s0;
-  in[1] = _mm_sub_epi16(k__const_0, s4);
-  in[2] = s6;
-  in[3] = _mm_sub_epi16(k__const_0, s2);
-  in[4] = s3;
-  in[5] = _mm_sub_epi16(k__const_0, s7);
-  in[6] = s5;
-  in[7] = _mm_sub_epi16(k__const_0, s1);
-
-  // transpose
-  array_transpose_8x8(in, in);
-}
-
-void vp9_fht8x8_sse2(const int16_t *input, tran_low_t *output,
-                     int stride, int tx_type) {
-  __m128i in[8];
-
-  switch (tx_type) {
-    case DCT_DCT:
-      vpx_fdct8x8_sse2(input, output, stride);
-      break;
-    case ADST_DCT:
-      load_buffer_8x8(input, in, stride);
-      fadst8_sse2(in);
-      fdct8_sse2(in);
-      right_shift_8x8(in, 1);
-      write_buffer_8x8(output, in, 8);
-      break;
-    case DCT_ADST:
-      load_buffer_8x8(input, in, stride);
-      fdct8_sse2(in);
-      fadst8_sse2(in);
-      right_shift_8x8(in, 1);
-      write_buffer_8x8(output, in, 8);
-      break;
-    case ADST_ADST:
-      load_buffer_8x8(input, in, stride);
-      fadst8_sse2(in);
-      fadst8_sse2(in);
-      right_shift_8x8(in, 1);
-      write_buffer_8x8(output, in, 8);
-      break;
-    default:
-      assert(0);
-      break;
-  }
-}
-
-static INLINE void load_buffer_16x16(const int16_t* input, __m128i *in0,
-                                     __m128i *in1, int stride) {
-  // load first 8 columns
-  load_buffer_8x8(input, in0, stride);
-  load_buffer_8x8(input + 8 * stride, in0 + 8, stride);
-
-  input += 8;
-  // load second 8 columns
-  load_buffer_8x8(input, in1, stride);
-  load_buffer_8x8(input + 8 * stride, in1 + 8, stride);
-}
-
-static INLINE void write_buffer_16x16(tran_low_t *output, __m128i *in0,
-                                      __m128i *in1, int stride) {
-  // write first 8 columns
-  write_buffer_8x8(output, in0, stride);
-  write_buffer_8x8(output + 8 * stride, in0 + 8, stride);
-  // write second 8 columns
-  output += 8;
-  write_buffer_8x8(output, in1, stride);
-  write_buffer_8x8(output + 8 * stride, in1 + 8, stride);
-}
-
-static INLINE void array_transpose_16x16(__m128i *res0, __m128i *res1) {
-  __m128i tbuf[8];
-  array_transpose_8x8(res0, res0);
-  array_transpose_8x8(res1, tbuf);
-  array_transpose_8x8(res0 + 8, res1);
-  array_transpose_8x8(res1 + 8, res1 + 8);
-
-  res0[8] = tbuf[0];
-  res0[9] = tbuf[1];
-  res0[10] = tbuf[2];
-  res0[11] = tbuf[3];
-  res0[12] = tbuf[4];
-  res0[13] = tbuf[5];
-  res0[14] = tbuf[6];
-  res0[15] = tbuf[7];
-}
-
-static INLINE void right_shift_16x16(__m128i *res0, __m128i *res1) {
-  // perform rounding operations
-  right_shift_8x8(res0, 2);
-  right_shift_8x8(res0 + 8, 2);
-  right_shift_8x8(res1, 2);
-  right_shift_8x8(res1 + 8, 2);
-}
-
-static void fdct16_8col(__m128i *in) {
-  // perform 16x16 1-D DCT for 8 columns
-  __m128i i[8], s[8], p[8], t[8], u[16], v[16];
-  const __m128i k__cospi_p16_p16 = _mm_set1_epi16((int16_t)cospi_16_64);
-  const __m128i k__cospi_p16_m16 = pair_set_epi16(cospi_16_64, -cospi_16_64);
-  const __m128i k__cospi_m16_p16 = pair_set_epi16(-cospi_16_64, cospi_16_64);
-  const __m128i k__cospi_p24_p08 = pair_set_epi16(cospi_24_64, cospi_8_64);
-  const __m128i k__cospi_p08_m24 = pair_set_epi16(cospi_8_64, -cospi_24_64);
-  const __m128i k__cospi_m08_p24 = pair_set_epi16(-cospi_8_64, cospi_24_64);
-  const __m128i k__cospi_p28_p04 = pair_set_epi16(cospi_28_64, cospi_4_64);
-  const __m128i k__cospi_m04_p28 = pair_set_epi16(-cospi_4_64, cospi_28_64);
-  const __m128i k__cospi_p12_p20 = pair_set_epi16(cospi_12_64, cospi_20_64);
-  const __m128i k__cospi_m20_p12 = pair_set_epi16(-cospi_20_64, cospi_12_64);
-  const __m128i k__cospi_p30_p02 = pair_set_epi16(cospi_30_64, cospi_2_64);
-  const __m128i k__cospi_p14_p18 = pair_set_epi16(cospi_14_64, cospi_18_64);
-  const __m128i k__cospi_m02_p30 = pair_set_epi16(-cospi_2_64, cospi_30_64);
-  const __m128i k__cospi_m18_p14 = pair_set_epi16(-cospi_18_64, cospi_14_64);
-  const __m128i k__cospi_p22_p10 = pair_set_epi16(cospi_22_64, cospi_10_64);
-  const __m128i k__cospi_p06_p26 = pair_set_epi16(cospi_6_64, cospi_26_64);
-  const __m128i k__cospi_m10_p22 = pair_set_epi16(-cospi_10_64, cospi_22_64);
-  const __m128i k__cospi_m26_p06 = pair_set_epi16(-cospi_26_64, cospi_6_64);
-  const __m128i k__DCT_CONST_ROUNDING = _mm_set1_epi32(DCT_CONST_ROUNDING);
-
-  // stage 1
-  i[0] = _mm_add_epi16(in[0], in[15]);
-  i[1] = _mm_add_epi16(in[1], in[14]);
-  i[2] = _mm_add_epi16(in[2], in[13]);
-  i[3] = _mm_add_epi16(in[3], in[12]);
-  i[4] = _mm_add_epi16(in[4], in[11]);
-  i[5] = _mm_add_epi16(in[5], in[10]);
-  i[6] = _mm_add_epi16(in[6], in[9]);
-  i[7] = _mm_add_epi16(in[7], in[8]);
-
-  s[0] = _mm_sub_epi16(in[7], in[8]);
-  s[1] = _mm_sub_epi16(in[6], in[9]);
-  s[2] = _mm_sub_epi16(in[5], in[10]);
-  s[3] = _mm_sub_epi16(in[4], in[11]);
-  s[4] = _mm_sub_epi16(in[3], in[12]);
-  s[5] = _mm_sub_epi16(in[2], in[13]);
-  s[6] = _mm_sub_epi16(in[1], in[14]);
-  s[7] = _mm_sub_epi16(in[0], in[15]);
-
-  p[0] = _mm_add_epi16(i[0], i[7]);
-  p[1] = _mm_add_epi16(i[1], i[6]);
-  p[2] = _mm_add_epi16(i[2], i[5]);
-  p[3] = _mm_add_epi16(i[3], i[4]);
-  p[4] = _mm_sub_epi16(i[3], i[4]);
-  p[5] = _mm_sub_epi16(i[2], i[5]);
-  p[6] = _mm_sub_epi16(i[1], i[6]);
-  p[7] = _mm_sub_epi16(i[0], i[7]);
-
-  u[0] = _mm_add_epi16(p[0], p[3]);
-  u[1] = _mm_add_epi16(p[1], p[2]);
-  u[2] = _mm_sub_epi16(p[1], p[2]);
-  u[3] = _mm_sub_epi16(p[0], p[3]);
-
-  v[0] = _mm_unpacklo_epi16(u[0], u[1]);
-  v[1] = _mm_unpackhi_epi16(u[0], u[1]);
-  v[2] = _mm_unpacklo_epi16(u[2], u[3]);
-  v[3] = _mm_unpackhi_epi16(u[2], u[3]);
-
-  u[0] = _mm_madd_epi16(v[0], k__cospi_p16_p16);
-  u[1] = _mm_madd_epi16(v[1], k__cospi_p16_p16);
-  u[2] = _mm_madd_epi16(v[0], k__cospi_p16_m16);
-  u[3] = _mm_madd_epi16(v[1], k__cospi_p16_m16);
-  u[4] = _mm_madd_epi16(v[2], k__cospi_p24_p08);
-  u[5] = _mm_madd_epi16(v[3], k__cospi_p24_p08);
-  u[6] = _mm_madd_epi16(v[2], k__cospi_m08_p24);
-  u[7] = _mm_madd_epi16(v[3], k__cospi_m08_p24);
-
-  v[0] = _mm_add_epi32(u[0], k__DCT_CONST_ROUNDING);
-  v[1] = _mm_add_epi32(u[1], k__DCT_CONST_ROUNDING);
-  v[2] = _mm_add_epi32(u[2], k__DCT_CONST_ROUNDING);
-  v[3] = _mm_add_epi32(u[3], k__DCT_CONST_ROUNDING);
-  v[4] = _mm_add_epi32(u[4], k__DCT_CONST_ROUNDING);
-  v[5] = _mm_add_epi32(u[5], k__DCT_CONST_ROUNDING);
-  v[6] = _mm_add_epi32(u[6], k__DCT_CONST_ROUNDING);
-  v[7] = _mm_add_epi32(u[7], k__DCT_CONST_ROUNDING);
-
-  u[0] = _mm_srai_epi32(v[0], DCT_CONST_BITS);
-  u[1] = _mm_srai_epi32(v[1], DCT_CONST_BITS);
-  u[2] = _mm_srai_epi32(v[2], DCT_CONST_BITS);
-  u[3] = _mm_srai_epi32(v[3], DCT_CONST_BITS);
-  u[4] = _mm_srai_epi32(v[4], DCT_CONST_BITS);
-  u[5] = _mm_srai_epi32(v[5], DCT_CONST_BITS);
-  u[6] = _mm_srai_epi32(v[6], DCT_CONST_BITS);
-  u[7] = _mm_srai_epi32(v[7], DCT_CONST_BITS);
-
-  in[0] = _mm_packs_epi32(u[0], u[1]);
-  in[4] = _mm_packs_epi32(u[4], u[5]);
-  in[8] = _mm_packs_epi32(u[2], u[3]);
-  in[12] = _mm_packs_epi32(u[6], u[7]);
-
-  u[0] = _mm_unpacklo_epi16(p[5], p[6]);
-  u[1] = _mm_unpackhi_epi16(p[5], p[6]);
-  v[0] = _mm_madd_epi16(u[0], k__cospi_m16_p16);
-  v[1] = _mm_madd_epi16(u[1], k__cospi_m16_p16);
-  v[2] = _mm_madd_epi16(u[0], k__cospi_p16_p16);
-  v[3] = _mm_madd_epi16(u[1], k__cospi_p16_p16);
-
-  u[0] = _mm_add_epi32(v[0], k__DCT_CONST_ROUNDING);
-  u[1] = _mm_add_epi32(v[1], k__DCT_CONST_ROUNDING);
-  u[2] = _mm_add_epi32(v[2], k__DCT_CONST_ROUNDING);
-  u[3] = _mm_add_epi32(v[3], k__DCT_CONST_ROUNDING);
-
-  v[0] = _mm_srai_epi32(u[0], DCT_CONST_BITS);
-  v[1] = _mm_srai_epi32(u[1], DCT_CONST_BITS);
-  v[2] = _mm_srai_epi32(u[2], DCT_CONST_BITS);
-  v[3] = _mm_srai_epi32(u[3], DCT_CONST_BITS);
-
-  u[0] = _mm_packs_epi32(v[0], v[1]);
-  u[1] = _mm_packs_epi32(v[2], v[3]);
-
-  t[0] = _mm_add_epi16(p[4], u[0]);
-  t[1] = _mm_sub_epi16(p[4], u[0]);
-  t[2] = _mm_sub_epi16(p[7], u[1]);
-  t[3] = _mm_add_epi16(p[7], u[1]);
-
-  u[0] = _mm_unpacklo_epi16(t[0], t[3]);
-  u[1] = _mm_unpackhi_epi16(t[0], t[3]);
-  u[2] = _mm_unpacklo_epi16(t[1], t[2]);
-  u[3] = _mm_unpackhi_epi16(t[1], t[2]);
-
-  v[0] = _mm_madd_epi16(u[0], k__cospi_p28_p04);
-  v[1] = _mm_madd_epi16(u[1], k__cospi_p28_p04);
-  v[2] = _mm_madd_epi16(u[2], k__cospi_p12_p20);
-  v[3] = _mm_madd_epi16(u[3], k__cospi_p12_p20);
-  v[4] = _mm_madd_epi16(u[2], k__cospi_m20_p12);
-  v[5] = _mm_madd_epi16(u[3], k__cospi_m20_p12);
-  v[6] = _mm_madd_epi16(u[0], k__cospi_m04_p28);
-  v[7] = _mm_madd_epi16(u[1], k__cospi_m04_p28);
-
-  u[0] = _mm_add_epi32(v[0], k__DCT_CONST_ROUNDING);
-  u[1] = _mm_add_epi32(v[1], k__DCT_CONST_ROUNDING);
-  u[2] = _mm_add_epi32(v[2], k__DCT_CONST_ROUNDING);
-  u[3] = _mm_add_epi32(v[3], k__DCT_CONST_ROUNDING);
-  u[4] = _mm_add_epi32(v[4], k__DCT_CONST_ROUNDING);
-  u[5] = _mm_add_epi32(v[5], k__DCT_CONST_ROUNDING);
-  u[6] = _mm_add_epi32(v[6], k__DCT_CONST_ROUNDING);
-  u[7] = _mm_add_epi32(v[7], k__DCT_CONST_ROUNDING);
-
-  v[0] = _mm_srai_epi32(u[0], DCT_CONST_BITS);
-  v[1] = _mm_srai_epi32(u[1], DCT_CONST_BITS);
-  v[2] = _mm_srai_epi32(u[2], DCT_CONST_BITS);
-  v[3] = _mm_srai_epi32(u[3], DCT_CONST_BITS);
-  v[4] = _mm_srai_epi32(u[4], DCT_CONST_BITS);
-  v[5] = _mm_srai_epi32(u[5], DCT_CONST_BITS);
-  v[6] = _mm_srai_epi32(u[6], DCT_CONST_BITS);
-  v[7] = _mm_srai_epi32(u[7], DCT_CONST_BITS);
-
-  in[2] = _mm_packs_epi32(v[0], v[1]);
-  in[6] = _mm_packs_epi32(v[4], v[5]);
-  in[10] = _mm_packs_epi32(v[2], v[3]);
-  in[14] = _mm_packs_epi32(v[6], v[7]);
-
-  // stage 2
-  u[0] = _mm_unpacklo_epi16(s[2], s[5]);
-  u[1] = _mm_unpackhi_epi16(s[2], s[5]);
-  u[2] = _mm_unpacklo_epi16(s[3], s[4]);
-  u[3] = _mm_unpackhi_epi16(s[3], s[4]);
-
-  v[0] = _mm_madd_epi16(u[0], k__cospi_m16_p16);
-  v[1] = _mm_madd_epi16(u[1], k__cospi_m16_p16);
-  v[2] = _mm_madd_epi16(u[2], k__cospi_m16_p16);
-  v[3] = _mm_madd_epi16(u[3], k__cospi_m16_p16);
-  v[4] = _mm_madd_epi16(u[2], k__cospi_p16_p16);
-  v[5] = _mm_madd_epi16(u[3], k__cospi_p16_p16);
-  v[6] = _mm_madd_epi16(u[0], k__cospi_p16_p16);
-  v[7] = _mm_madd_epi16(u[1], k__cospi_p16_p16);
-
-  u[0] = _mm_add_epi32(v[0], k__DCT_CONST_ROUNDING);
-  u[1] = _mm_add_epi32(v[1], k__DCT_CONST_ROUNDING);
-  u[2] = _mm_add_epi32(v[2], k__DCT_CONST_ROUNDING);
-  u[3] = _mm_add_epi32(v[3], k__DCT_CONST_ROUNDING);
-  u[4] = _mm_add_epi32(v[4], k__DCT_CONST_ROUNDING);
-  u[5] = _mm_add_epi32(v[5], k__DCT_CONST_ROUNDING);
-  u[6] = _mm_add_epi32(v[6], k__DCT_CONST_ROUNDING);
-  u[7] = _mm_add_epi32(v[7], k__DCT_CONST_ROUNDING);
-
-  v[0] = _mm_srai_epi32(u[0], DCT_CONST_BITS);
-  v[1] = _mm_srai_epi32(u[1], DCT_CONST_BITS);
-  v[2] = _mm_srai_epi32(u[2], DCT_CONST_BITS);
-  v[3] = _mm_srai_epi32(u[3], DCT_CONST_BITS);
-  v[4] = _mm_srai_epi32(u[4], DCT_CONST_BITS);
-  v[5] = _mm_srai_epi32(u[5], DCT_CONST_BITS);
-  v[6] = _mm_srai_epi32(u[6], DCT_CONST_BITS);
-  v[7] = _mm_srai_epi32(u[7], DCT_CONST_BITS);
-
-  t[2] = _mm_packs_epi32(v[0], v[1]);
-  t[3] = _mm_packs_epi32(v[2], v[3]);
-  t[4] = _mm_packs_epi32(v[4], v[5]);
-  t[5] = _mm_packs_epi32(v[6], v[7]);
-
-  // stage 3
-  p[0] = _mm_add_epi16(s[0], t[3]);
-  p[1] = _mm_add_epi16(s[1], t[2]);
-  p[2] = _mm_sub_epi16(s[1], t[2]);
-  p[3] = _mm_sub_epi16(s[0], t[3]);
-  p[4] = _mm_sub_epi16(s[7], t[4]);
-  p[5] = _mm_sub_epi16(s[6], t[5]);
-  p[6] = _mm_add_epi16(s[6], t[5]);
-  p[7] = _mm_add_epi16(s[7], t[4]);
-
-  // stage 4
-  u[0] = _mm_unpacklo_epi16(p[1], p[6]);
-  u[1] = _mm_unpackhi_epi16(p[1], p[6]);
-  u[2] = _mm_unpacklo_epi16(p[2], p[5]);
-  u[3] = _mm_unpackhi_epi16(p[2], p[5]);
-
-  v[0] = _mm_madd_epi16(u[0], k__cospi_m08_p24);
-  v[1] = _mm_madd_epi16(u[1], k__cospi_m08_p24);
-  v[2] = _mm_madd_epi16(u[2], k__cospi_p24_p08);
-  v[3] = _mm_madd_epi16(u[3], k__cospi_p24_p08);
-  v[4] = _mm_madd_epi16(u[2], k__cospi_p08_m24);
-  v[5] = _mm_madd_epi16(u[3], k__cospi_p08_m24);
-  v[6] = _mm_madd_epi16(u[0], k__cospi_p24_p08);
-  v[7] = _mm_madd_epi16(u[1], k__cospi_p24_p08);
-
-  u[0] = _mm_add_epi32(v[0], k__DCT_CONST_ROUNDING);
-  u[1] = _mm_add_epi32(v[1], k__DCT_CONST_ROUNDING);
-  u[2] = _mm_add_epi32(v[2], k__DCT_CONST_ROUNDING);
-  u[3] = _mm_add_epi32(v[3], k__DCT_CONST_ROUNDING);
-  u[4] = _mm_add_epi32(v[4], k__DCT_CONST_ROUNDING);
-  u[5] = _mm_add_epi32(v[5], k__DCT_CONST_ROUNDING);
-  u[6] = _mm_add_epi32(v[6], k__DCT_CONST_ROUNDING);
-  u[7] = _mm_add_epi32(v[7], k__DCT_CONST_ROUNDING);
-
-  v[0] = _mm_srai_epi32(u[0], DCT_CONST_BITS);
-  v[1] = _mm_srai_epi32(u[1], DCT_CONST_BITS);
-  v[2] = _mm_srai_epi32(u[2], DCT_CONST_BITS);
-  v[3] = _mm_srai_epi32(u[3], DCT_CONST_BITS);
-  v[4] = _mm_srai_epi32(u[4], DCT_CONST_BITS);
-  v[5] = _mm_srai_epi32(u[5], DCT_CONST_BITS);
-  v[6] = _mm_srai_epi32(u[6], DCT_CONST_BITS);
-  v[7] = _mm_srai_epi32(u[7], DCT_CONST_BITS);
-
-  t[1] = _mm_packs_epi32(v[0], v[1]);
-  t[2] = _mm_packs_epi32(v[2], v[3]);
-  t[5] = _mm_packs_epi32(v[4], v[5]);
-  t[6] = _mm_packs_epi32(v[6], v[7]);
-
-  // stage 5
-  s[0] = _mm_add_epi16(p[0], t[1]);
-  s[1] = _mm_sub_epi16(p[0], t[1]);
-  s[2] = _mm_add_epi16(p[3], t[2]);
-  s[3] = _mm_sub_epi16(p[3], t[2]);
-  s[4] = _mm_sub_epi16(p[4], t[5]);
-  s[5] = _mm_add_epi16(p[4], t[5]);
-  s[6] = _mm_sub_epi16(p[7], t[6]);
-  s[7] = _mm_add_epi16(p[7], t[6]);
-
-  // stage 6
-  u[0] = _mm_unpacklo_epi16(s[0], s[7]);
-  u[1] = _mm_unpackhi_epi16(s[0], s[7]);
-  u[2] = _mm_unpacklo_epi16(s[1], s[6]);
-  u[3] = _mm_unpackhi_epi16(s[1], s[6]);
-  u[4] = _mm_unpacklo_epi16(s[2], s[5]);
-  u[5] = _mm_unpackhi_epi16(s[2], s[5]);
-  u[6] = _mm_unpacklo_epi16(s[3], s[4]);
-  u[7] = _mm_unpackhi_epi16(s[3], s[4]);
-
-  v[0] = _mm_madd_epi16(u[0], k__cospi_p30_p02);
-  v[1] = _mm_madd_epi16(u[1], k__cospi_p30_p02);
-  v[2] = _mm_madd_epi16(u[2], k__cospi_p14_p18);
-  v[3] = _mm_madd_epi16(u[3], k__cospi_p14_p18);
-  v[4] = _mm_madd_epi16(u[4], k__cospi_p22_p10);
-  v[5] = _mm_madd_epi16(u[5], k__cospi_p22_p10);
-  v[6] = _mm_madd_epi16(u[6], k__cospi_p06_p26);
-  v[7] = _mm_madd_epi16(u[7], k__cospi_p06_p26);
-  v[8] = _mm_madd_epi16(u[6], k__cospi_m26_p06);
-  v[9] = _mm_madd_epi16(u[7], k__cospi_m26_p06);
-  v[10] = _mm_madd_epi16(u[4], k__cospi_m10_p22);
-  v[11] = _mm_madd_epi16(u[5], k__cospi_m10_p22);
-  v[12] = _mm_madd_epi16(u[2], k__cospi_m18_p14);
-  v[13] = _mm_madd_epi16(u[3], k__cospi_m18_p14);
-  v[14] = _mm_madd_epi16(u[0], k__cospi_m02_p30);
-  v[15] = _mm_madd_epi16(u[1], k__cospi_m02_p30);
-
-  u[0] = _mm_add_epi32(v[0], k__DCT_CONST_ROUNDING);
-  u[1] = _mm_add_epi32(v[1], k__DCT_CONST_ROUNDING);
-  u[2] = _mm_add_epi32(v[2], k__DCT_CONST_ROUNDING);
-  u[3] = _mm_add_epi32(v[3], k__DCT_CONST_ROUNDING);
-  u[4] = _mm_add_epi32(v[4], k__DCT_CONST_ROUNDING);
-  u[5] = _mm_add_epi32(v[5], k__DCT_CONST_ROUNDING);
-  u[6] = _mm_add_epi32(v[6], k__DCT_CONST_ROUNDING);
-  u[7] = _mm_add_epi32(v[7], k__DCT_CONST_ROUNDING);
-  u[8] = _mm_add_epi32(v[8], k__DCT_CONST_ROUNDING);
-  u[9] = _mm_add_epi32(v[9], k__DCT_CONST_ROUNDING);
-  u[10] = _mm_add_epi32(v[10], k__DCT_CONST_ROUNDING);
-  u[11] = _mm_add_epi32(v[11], k__DCT_CONST_ROUNDING);
-  u[12] = _mm_add_epi32(v[12], k__DCT_CONST_ROUNDING);
-  u[13] = _mm_add_epi32(v[13], k__DCT_CONST_ROUNDING);
-  u[14] = _mm_add_epi32(v[14], k__DCT_CONST_ROUNDING);
-  u[15] = _mm_add_epi32(v[15], k__DCT_CONST_ROUNDING);
-
-  v[0] = _mm_srai_epi32(u[0], DCT_CONST_BITS);
-  v[1] = _mm_srai_epi32(u[1], DCT_CONST_BITS);
-  v[2] = _mm_srai_epi32(u[2], DCT_CONST_BITS);
-  v[3] = _mm_srai_epi32(u[3], DCT_CONST_BITS);
-  v[4] = _mm_srai_epi32(u[4], DCT_CONST_BITS);
-  v[5] = _mm_srai_epi32(u[5], DCT_CONST_BITS);
-  v[6] = _mm_srai_epi32(u[6], DCT_CONST_BITS);
-  v[7] = _mm_srai_epi32(u[7], DCT_CONST_BITS);
-  v[8] = _mm_srai_epi32(u[8], DCT_CONST_BITS);
-  v[9] = _mm_srai_epi32(u[9], DCT_CONST_BITS);
-  v[10] = _mm_srai_epi32(u[10], DCT_CONST_BITS);
-  v[11] = _mm_srai_epi32(u[11], DCT_CONST_BITS);
-  v[12] = _mm_srai_epi32(u[12], DCT_CONST_BITS);
-  v[13] = _mm_srai_epi32(u[13], DCT_CONST_BITS);
-  v[14] = _mm_srai_epi32(u[14], DCT_CONST_BITS);
-  v[15] = _mm_srai_epi32(u[15], DCT_CONST_BITS);
-
-  in[1]  = _mm_packs_epi32(v[0], v[1]);
-  in[9]  = _mm_packs_epi32(v[2], v[3]);
-  in[5]  = _mm_packs_epi32(v[4], v[5]);
-  in[13] = _mm_packs_epi32(v[6], v[7]);
-  in[3]  = _mm_packs_epi32(v[8], v[9]);
-  in[11] = _mm_packs_epi32(v[10], v[11]);
-  in[7]  = _mm_packs_epi32(v[12], v[13]);
-  in[15] = _mm_packs_epi32(v[14], v[15]);
-}
-
-static void fadst16_8col(__m128i *in) {
-  // perform 16x16 1-D ADST for 8 columns
-  __m128i s[16], x[16], u[32], v[32];
-  const __m128i k__cospi_p01_p31 = pair_set_epi16(cospi_1_64, cospi_31_64);
-  const __m128i k__cospi_p31_m01 = pair_set_epi16(cospi_31_64, -cospi_1_64);
-  const __m128i k__cospi_p05_p27 = pair_set_epi16(cospi_5_64, cospi_27_64);
-  const __m128i k__cospi_p27_m05 = pair_set_epi16(cospi_27_64, -cospi_5_64);
-  const __m128i k__cospi_p09_p23 = pair_set_epi16(cospi_9_64, cospi_23_64);
-  const __m128i k__cospi_p23_m09 = pair_set_epi16(cospi_23_64, -cospi_9_64);
-  const __m128i k__cospi_p13_p19 = pair_set_epi16(cospi_13_64, cospi_19_64);
-  const __m128i k__cospi_p19_m13 = pair_set_epi16(cospi_19_64, -cospi_13_64);
-  const __m128i k__cospi_p17_p15 = pair_set_epi16(cospi_17_64, cospi_15_64);
-  const __m128i k__cospi_p15_m17 = pair_set_epi16(cospi_15_64, -cospi_17_64);
-  const __m128i k__cospi_p21_p11 = pair_set_epi16(cospi_21_64, cospi_11_64);
-  const __m128i k__cospi_p11_m21 = pair_set_epi16(cospi_11_64, -cospi_21_64);
-  const __m128i k__cospi_p25_p07 = pair_set_epi16(cospi_25_64, cospi_7_64);
-  const __m128i k__cospi_p07_m25 = pair_set_epi16(cospi_7_64, -cospi_25_64);
-  const __m128i k__cospi_p29_p03 = pair_set_epi16(cospi_29_64, cospi_3_64);
-  const __m128i k__cospi_p03_m29 = pair_set_epi16(cospi_3_64, -cospi_29_64);
-  const __m128i k__cospi_p04_p28 = pair_set_epi16(cospi_4_64, cospi_28_64);
-  const __m128i k__cospi_p28_m04 = pair_set_epi16(cospi_28_64, -cospi_4_64);
-  const __m128i k__cospi_p20_p12 = pair_set_epi16(cospi_20_64, cospi_12_64);
-  const __m128i k__cospi_p12_m20 = pair_set_epi16(cospi_12_64, -cospi_20_64);
-  const __m128i k__cospi_m28_p04 = pair_set_epi16(-cospi_28_64, cospi_4_64);
-  const __m128i k__cospi_m12_p20 = pair_set_epi16(-cospi_12_64, cospi_20_64);
-  const __m128i k__cospi_p08_p24 = pair_set_epi16(cospi_8_64, cospi_24_64);
-  const __m128i k__cospi_p24_m08 = pair_set_epi16(cospi_24_64, -cospi_8_64);
-  const __m128i k__cospi_m24_p08 = pair_set_epi16(-cospi_24_64, cospi_8_64);
-  const __m128i k__cospi_m16_m16 = _mm_set1_epi16((int16_t)-cospi_16_64);
-  const __m128i k__cospi_p16_p16 = _mm_set1_epi16((int16_t)cospi_16_64);
-  const __m128i k__cospi_p16_m16 = pair_set_epi16(cospi_16_64, -cospi_16_64);
-  const __m128i k__cospi_m16_p16 = pair_set_epi16(-cospi_16_64, cospi_16_64);
-  const __m128i k__DCT_CONST_ROUNDING = _mm_set1_epi32(DCT_CONST_ROUNDING);
-  const __m128i kZero = _mm_set1_epi16(0);
-
-  u[0] = _mm_unpacklo_epi16(in[15], in[0]);
-  u[1] = _mm_unpackhi_epi16(in[15], in[0]);
-  u[2] = _mm_unpacklo_epi16(in[13], in[2]);
-  u[3] = _mm_unpackhi_epi16(in[13], in[2]);
-  u[4] = _mm_unpacklo_epi16(in[11], in[4]);
-  u[5] = _mm_unpackhi_epi16(in[11], in[4]);
-  u[6] = _mm_unpacklo_epi16(in[9], in[6]);
-  u[7] = _mm_unpackhi_epi16(in[9], in[6]);
-  u[8] = _mm_unpacklo_epi16(in[7], in[8]);
-  u[9] = _mm_unpackhi_epi16(in[7], in[8]);
-  u[10] = _mm_unpacklo_epi16(in[5], in[10]);
-  u[11] = _mm_unpackhi_epi16(in[5], in[10]);
-  u[12] = _mm_unpacklo_epi16(in[3], in[12]);
-  u[13] = _mm_unpackhi_epi16(in[3], in[12]);
-  u[14] = _mm_unpacklo_epi16(in[1], in[14]);
-  u[15] = _mm_unpackhi_epi16(in[1], in[14]);
-
-  v[0] = _mm_madd_epi16(u[0], k__cospi_p01_p31);
-  v[1] = _mm_madd_epi16(u[1], k__cospi_p01_p31);
-  v[2] = _mm_madd_epi16(u[0], k__cospi_p31_m01);
-  v[3] = _mm_madd_epi16(u[1], k__cospi_p31_m01);
-  v[4] = _mm_madd_epi16(u[2], k__cospi_p05_p27);
-  v[5] = _mm_madd_epi16(u[3], k__cospi_p05_p27);
-  v[6] = _mm_madd_epi16(u[2], k__cospi_p27_m05);
-  v[7] = _mm_madd_epi16(u[3], k__cospi_p27_m05);
-  v[8] = _mm_madd_epi16(u[4], k__cospi_p09_p23);
-  v[9] = _mm_madd_epi16(u[5], k__cospi_p09_p23);
-  v[10] = _mm_madd_epi16(u[4], k__cospi_p23_m09);
-  v[11] = _mm_madd_epi16(u[5], k__cospi_p23_m09);
-  v[12] = _mm_madd_epi16(u[6], k__cospi_p13_p19);
-  v[13] = _mm_madd_epi16(u[7], k__cospi_p13_p19);
-  v[14] = _mm_madd_epi16(u[6], k__cospi_p19_m13);
-  v[15] = _mm_madd_epi16(u[7], k__cospi_p19_m13);
-  v[16] = _mm_madd_epi16(u[8], k__cospi_p17_p15);
-  v[17] = _mm_madd_epi16(u[9], k__cospi_p17_p15);
-  v[18] = _mm_madd_epi16(u[8], k__cospi_p15_m17);
-  v[19] = _mm_madd_epi16(u[9], k__cospi_p15_m17);
-  v[20] = _mm_madd_epi16(u[10], k__cospi_p21_p11);
-  v[21] = _mm_madd_epi16(u[11], k__cospi_p21_p11);
-  v[22] = _mm_madd_epi16(u[10], k__cospi_p11_m21);
-  v[23] = _mm_madd_epi16(u[11], k__cospi_p11_m21);
-  v[24] = _mm_madd_epi16(u[12], k__cospi_p25_p07);
-  v[25] = _mm_madd_epi16(u[13], k__cospi_p25_p07);
-  v[26] = _mm_madd_epi16(u[12], k__cospi_p07_m25);
-  v[27] = _mm_madd_epi16(u[13], k__cospi_p07_m25);
-  v[28] = _mm_madd_epi16(u[14], k__cospi_p29_p03);
-  v[29] = _mm_madd_epi16(u[15], k__cospi_p29_p03);
-  v[30] = _mm_madd_epi16(u[14], k__cospi_p03_m29);
-  v[31] = _mm_madd_epi16(u[15], k__cospi_p03_m29);
-
-  u[0] = _mm_add_epi32(v[0], v[16]);
-  u[1] = _mm_add_epi32(v[1], v[17]);
-  u[2] = _mm_add_epi32(v[2], v[18]);
-  u[3] = _mm_add_epi32(v[3], v[19]);
-  u[4] = _mm_add_epi32(v[4], v[20]);
-  u[5] = _mm_add_epi32(v[5], v[21]);
-  u[6] = _mm_add_epi32(v[6], v[22]);
-  u[7] = _mm_add_epi32(v[7], v[23]);
-  u[8] = _mm_add_epi32(v[8], v[24]);
-  u[9] = _mm_add_epi32(v[9], v[25]);
-  u[10] = _mm_add_epi32(v[10], v[26]);
-  u[11] = _mm_add_epi32(v[11], v[27]);
-  u[12] = _mm_add_epi32(v[12], v[28]);
-  u[13] = _mm_add_epi32(v[13], v[29]);
-  u[14] = _mm_add_epi32(v[14], v[30]);
-  u[15] = _mm_add_epi32(v[15], v[31]);
-  u[16] = _mm_sub_epi32(v[0], v[16]);
-  u[17] = _mm_sub_epi32(v[1], v[17]);
-  u[18] = _mm_sub_epi32(v[2], v[18]);
-  u[19] = _mm_sub_epi32(v[3], v[19]);
-  u[20] = _mm_sub_epi32(v[4], v[20]);
-  u[21] = _mm_sub_epi32(v[5], v[21]);
-  u[22] = _mm_sub_epi32(v[6], v[22]);
-  u[23] = _mm_sub_epi32(v[7], v[23]);
-  u[24] = _mm_sub_epi32(v[8], v[24]);
-  u[25] = _mm_sub_epi32(v[9], v[25]);
-  u[26] = _mm_sub_epi32(v[10], v[26]);
-  u[27] = _mm_sub_epi32(v[11], v[27]);
-  u[28] = _mm_sub_epi32(v[12], v[28]);
-  u[29] = _mm_sub_epi32(v[13], v[29]);
-  u[30] = _mm_sub_epi32(v[14], v[30]);
-  u[31] = _mm_sub_epi32(v[15], v[31]);
-
-  v[0] = _mm_add_epi32(u[0], k__DCT_CONST_ROUNDING);
-  v[1] = _mm_add_epi32(u[1], k__DCT_CONST_ROUNDING);
-  v[2] = _mm_add_epi32(u[2], k__DCT_CONST_ROUNDING);
-  v[3] = _mm_add_epi32(u[3], k__DCT_CONST_ROUNDING);
-  v[4] = _mm_add_epi32(u[4], k__DCT_CONST_ROUNDING);
-  v[5] = _mm_add_epi32(u[5], k__DCT_CONST_ROUNDING);
-  v[6] = _mm_add_epi32(u[6], k__DCT_CONST_ROUNDING);
-  v[7] = _mm_add_epi32(u[7], k__DCT_CONST_ROUNDING);
-  v[8] = _mm_add_epi32(u[8], k__DCT_CONST_ROUNDING);
-  v[9] = _mm_add_epi32(u[9], k__DCT_CONST_ROUNDING);
-  v[10] = _mm_add_epi32(u[10], k__DCT_CONST_ROUNDING);
-  v[11] = _mm_add_epi32(u[11], k__DCT_CONST_ROUNDING);
-  v[12] = _mm_add_epi32(u[12], k__DCT_CONST_ROUNDING);
-  v[13] = _mm_add_epi32(u[13], k__DCT_CONST_ROUNDING);
-  v[14] = _mm_add_epi32(u[14], k__DCT_CONST_ROUNDING);
-  v[15] = _mm_add_epi32(u[15], k__DCT_CONST_ROUNDING);
-  v[16] = _mm_add_epi32(u[16], k__DCT_CONST_ROUNDING);
-  v[17] = _mm_add_epi32(u[17], k__DCT_CONST_ROUNDING);
-  v[18] = _mm_add_epi32(u[18], k__DCT_CONST_ROUNDING);
-  v[19] = _mm_add_epi32(u[19], k__DCT_CONST_ROUNDING);
-  v[20] = _mm_add_epi32(u[20], k__DCT_CONST_ROUNDING);
-  v[21] = _mm_add_epi32(u[21], k__DCT_CONST_ROUNDING);
-  v[22] = _mm_add_epi32(u[22], k__DCT_CONST_ROUNDING);
-  v[23] = _mm_add_epi32(u[23], k__DCT_CONST_ROUNDING);
-  v[24] = _mm_add_epi32(u[24], k__DCT_CONST_ROUNDING);
-  v[25] = _mm_add_epi32(u[25], k__DCT_CONST_ROUNDING);
-  v[26] = _mm_add_epi32(u[26], k__DCT_CONST_ROUNDING);
-  v[27] = _mm_add_epi32(u[27], k__DCT_CONST_ROUNDING);
-  v[28] = _mm_add_epi32(u[28], k__DCT_CONST_ROUNDING);
-  v[29] = _mm_add_epi32(u[29], k__DCT_CONST_ROUNDING);
-  v[30] = _mm_add_epi32(u[30], k__DCT_CONST_ROUNDING);
-  v[31] = _mm_add_epi32(u[31], k__DCT_CONST_ROUNDING);
-
-  u[0] = _mm_srai_epi32(v[0], DCT_CONST_BITS);
-  u[1] = _mm_srai_epi32(v[1], DCT_CONST_BITS);
-  u[2] = _mm_srai_epi32(v[2], DCT_CONST_BITS);
-  u[3] = _mm_srai_epi32(v[3], DCT_CONST_BITS);
-  u[4] = _mm_srai_epi32(v[4], DCT_CONST_BITS);
-  u[5] = _mm_srai_epi32(v[5], DCT_CONST_BITS);
-  u[6] = _mm_srai_epi32(v[6], DCT_CONST_BITS);
-  u[7] = _mm_srai_epi32(v[7], DCT_CONST_BITS);
-  u[8] = _mm_srai_epi32(v[8], DCT_CONST_BITS);
-  u[9] = _mm_srai_epi32(v[9], DCT_CONST_BITS);
-  u[10] = _mm_srai_epi32(v[10], DCT_CONST_BITS);
-  u[11] = _mm_srai_epi32(v[11], DCT_CONST_BITS);
-  u[12] = _mm_srai_epi32(v[12], DCT_CONST_BITS);
-  u[13] = _mm_srai_epi32(v[13], DCT_CONST_BITS);
-  u[14] = _mm_srai_epi32(v[14], DCT_CONST_BITS);
-  u[15] = _mm_srai_epi32(v[15], DCT_CONST_BITS);
-  u[16] = _mm_srai_epi32(v[16], DCT_CONST_BITS);
-  u[17] = _mm_srai_epi32(v[17], DCT_CONST_BITS);
-  u[18] = _mm_srai_epi32(v[18], DCT_CONST_BITS);
-  u[19] = _mm_srai_epi32(v[19], DCT_CONST_BITS);
-  u[20] = _mm_srai_epi32(v[20], DCT_CONST_BITS);
-  u[21] = _mm_srai_epi32(v[21], DCT_CONST_BITS);
-  u[22] = _mm_srai_epi32(v[22], DCT_CONST_BITS);
-  u[23] = _mm_srai_epi32(v[23], DCT_CONST_BITS);
-  u[24] = _mm_srai_epi32(v[24], DCT_CONST_BITS);
-  u[25] = _mm_srai_epi32(v[25], DCT_CONST_BITS);
-  u[26] = _mm_srai_epi32(v[26], DCT_CONST_BITS);
-  u[27] = _mm_srai_epi32(v[27], DCT_CONST_BITS);
-  u[28] = _mm_srai_epi32(v[28], DCT_CONST_BITS);
-  u[29] = _mm_srai_epi32(v[29], DCT_CONST_BITS);
-  u[30] = _mm_srai_epi32(v[30], DCT_CONST_BITS);
-  u[31] = _mm_srai_epi32(v[31], DCT_CONST_BITS);
-
-  s[0] = _mm_packs_epi32(u[0], u[1]);
-  s[1] = _mm_packs_epi32(u[2], u[3]);
-  s[2] = _mm_packs_epi32(u[4], u[5]);
-  s[3] = _mm_packs_epi32(u[6], u[7]);
-  s[4] = _mm_packs_epi32(u[8], u[9]);
-  s[5] = _mm_packs_epi32(u[10], u[11]);
-  s[6] = _mm_packs_epi32(u[12], u[13]);
-  s[7] = _mm_packs_epi32(u[14], u[15]);
-  s[8] = _mm_packs_epi32(u[16], u[17]);
-  s[9] = _mm_packs_epi32(u[18], u[19]);
-  s[10] = _mm_packs_epi32(u[20], u[21]);
-  s[11] = _mm_packs_epi32(u[22], u[23]);
-  s[12] = _mm_packs_epi32(u[24], u[25]);
-  s[13] = _mm_packs_epi32(u[26], u[27]);
-  s[14] = _mm_packs_epi32(u[28], u[29]);
-  s[15] = _mm_packs_epi32(u[30], u[31]);
-
-  // stage 2
-  u[0] = _mm_unpacklo_epi16(s[8], s[9]);
-  u[1] = _mm_unpackhi_epi16(s[8], s[9]);
-  u[2] = _mm_unpacklo_epi16(s[10], s[11]);
-  u[3] = _mm_unpackhi_epi16(s[10], s[11]);
-  u[4] = _mm_unpacklo_epi16(s[12], s[13]);
-  u[5] = _mm_unpackhi_epi16(s[12], s[13]);
-  u[6] = _mm_unpacklo_epi16(s[14], s[15]);
-  u[7] = _mm_unpackhi_epi16(s[14], s[15]);
-
-  v[0] = _mm_madd_epi16(u[0], k__cospi_p04_p28);
-  v[1] = _mm_madd_epi16(u[1], k__cospi_p04_p28);
-  v[2] = _mm_madd_epi16(u[0], k__cospi_p28_m04);
-  v[3] = _mm_madd_epi16(u[1], k__cospi_p28_m04);
-  v[4] = _mm_madd_epi16(u[2], k__cospi_p20_p12);
-  v[5] = _mm_madd_epi16(u[3], k__cospi_p20_p12);
-  v[6] = _mm_madd_epi16(u[2], k__cospi_p12_m20);
-  v[7] = _mm_madd_epi16(u[3], k__cospi_p12_m20);
-  v[8] = _mm_madd_epi16(u[4], k__cospi_m28_p04);
-  v[9] = _mm_madd_epi16(u[5], k__cospi_m28_p04);
-  v[10] = _mm_madd_epi16(u[4], k__cospi_p04_p28);
-  v[11] = _mm_madd_epi16(u[5], k__cospi_p04_p28);
-  v[12] = _mm_madd_epi16(u[6], k__cospi_m12_p20);
-  v[13] = _mm_madd_epi16(u[7], k__cospi_m12_p20);
-  v[14] = _mm_madd_epi16(u[6], k__cospi_p20_p12);
-  v[15] = _mm_madd_epi16(u[7], k__cospi_p20_p12);
-
-  u[0] = _mm_add_epi32(v[0], v[8]);
-  u[1] = _mm_add_epi32(v[1], v[9]);
-  u[2] = _mm_add_epi32(v[2], v[10]);
-  u[3] = _mm_add_epi32(v[3], v[11]);
-  u[4] = _mm_add_epi32(v[4], v[12]);
-  u[5] = _mm_add_epi32(v[5], v[13]);
-  u[6] = _mm_add_epi32(v[6], v[14]);
-  u[7] = _mm_add_epi32(v[7], v[15]);
-  u[8] = _mm_sub_epi32(v[0], v[8]);
-  u[9] = _mm_sub_epi32(v[1], v[9]);
-  u[10] = _mm_sub_epi32(v[2], v[10]);
-  u[11] = _mm_sub_epi32(v[3], v[11]);
-  u[12] = _mm_sub_epi32(v[4], v[12]);
-  u[13] = _mm_sub_epi32(v[5], v[13]);
-  u[14] = _mm_sub_epi32(v[6], v[14]);
-  u[15] = _mm_sub_epi32(v[7], v[15]);
-
-  v[0] = _mm_add_epi32(u[0], k__DCT_CONST_ROUNDING);
-  v[1] = _mm_add_epi32(u[1], k__DCT_CONST_ROUNDING);
-  v[2] = _mm_add_epi32(u[2], k__DCT_CONST_ROUNDING);
-  v[3] = _mm_add_epi32(u[3], k__DCT_CONST_ROUNDING);
-  v[4] = _mm_add_epi32(u[4], k__DCT_CONST_ROUNDING);
-  v[5] = _mm_add_epi32(u[5], k__DCT_CONST_ROUNDING);
-  v[6] = _mm_add_epi32(u[6], k__DCT_CONST_ROUNDING);
-  v[7] = _mm_add_epi32(u[7], k__DCT_CONST_ROUNDING);
-  v[8] = _mm_add_epi32(u[8], k__DCT_CONST_ROUNDING);
-  v[9] = _mm_add_epi32(u[9], k__DCT_CONST_ROUNDING);
-  v[10] = _mm_add_epi32(u[10], k__DCT_CONST_ROUNDING);
-  v[11] = _mm_add_epi32(u[11], k__DCT_CONST_ROUNDING);
-  v[12] = _mm_add_epi32(u[12], k__DCT_CONST_ROUNDING);
-  v[13] = _mm_add_epi32(u[13], k__DCT_CONST_ROUNDING);
-  v[14] = _mm_add_epi32(u[14], k__DCT_CONST_ROUNDING);
-  v[15] = _mm_add_epi32(u[15], k__DCT_CONST_ROUNDING);
-
-  u[0] = _mm_srai_epi32(v[0], DCT_CONST_BITS);
-  u[1] = _mm_srai_epi32(v[1], DCT_CONST_BITS);
-  u[2] = _mm_srai_epi32(v[2], DCT_CONST_BITS);
-  u[3] = _mm_srai_epi32(v[3], DCT_CONST_BITS);
-  u[4] = _mm_srai_epi32(v[4], DCT_CONST_BITS);
-  u[5] = _mm_srai_epi32(v[5], DCT_CONST_BITS);
-  u[6] = _mm_srai_epi32(v[6], DCT_CONST_BITS);
-  u[7] = _mm_srai_epi32(v[7], DCT_CONST_BITS);
-  u[8] = _mm_srai_epi32(v[8], DCT_CONST_BITS);
-  u[9] = _mm_srai_epi32(v[9], DCT_CONST_BITS);
-  u[10] = _mm_srai_epi32(v[10], DCT_CONST_BITS);
-  u[11] = _mm_srai_epi32(v[11], DCT_CONST_BITS);
-  u[12] = _mm_srai_epi32(v[12], DCT_CONST_BITS);
-  u[13] = _mm_srai_epi32(v[13], DCT_CONST_BITS);
-  u[14] = _mm_srai_epi32(v[14], DCT_CONST_BITS);
-  u[15] = _mm_srai_epi32(v[15], DCT_CONST_BITS);
-
-  x[0] = _mm_add_epi16(s[0], s[4]);
-  x[1] = _mm_add_epi16(s[1], s[5]);
-  x[2] = _mm_add_epi16(s[2], s[6]);
-  x[3] = _mm_add_epi16(s[3], s[7]);
-  x[4] = _mm_sub_epi16(s[0], s[4]);
-  x[5] = _mm_sub_epi16(s[1], s[5]);
-  x[6] = _mm_sub_epi16(s[2], s[6]);
-  x[7] = _mm_sub_epi16(s[3], s[7]);
-  x[8] = _mm_packs_epi32(u[0], u[1]);
-  x[9] = _mm_packs_epi32(u[2], u[3]);
-  x[10] = _mm_packs_epi32(u[4], u[5]);
-  x[11] = _mm_packs_epi32(u[6], u[7]);
-  x[12] = _mm_packs_epi32(u[8], u[9]);
-  x[13] = _mm_packs_epi32(u[10], u[11]);
-  x[14] = _mm_packs_epi32(u[12], u[13]);
-  x[15] = _mm_packs_epi32(u[14], u[15]);
-
-  // stage 3
-  u[0] = _mm_unpacklo_epi16(x[4], x[5]);
-  u[1] = _mm_unpackhi_epi16(x[4], x[5]);
-  u[2] = _mm_unpacklo_epi16(x[6], x[7]);
-  u[3] = _mm_unpackhi_epi16(x[6], x[7]);
-  u[4] = _mm_unpacklo_epi16(x[12], x[13]);
-  u[5] = _mm_unpackhi_epi16(x[12], x[13]);
-  u[6] = _mm_unpacklo_epi16(x[14], x[15]);
-  u[7] = _mm_unpackhi_epi16(x[14], x[15]);
-
-  v[0] = _mm_madd_epi16(u[0], k__cospi_p08_p24);
-  v[1] = _mm_madd_epi16(u[1], k__cospi_p08_p24);
-  v[2] = _mm_madd_epi16(u[0], k__cospi_p24_m08);
-  v[3] = _mm_madd_epi16(u[1], k__cospi_p24_m08);
-  v[4] = _mm_madd_epi16(u[2], k__cospi_m24_p08);
-  v[5] = _mm_madd_epi16(u[3], k__cospi_m24_p08);
-  v[6] = _mm_madd_epi16(u[2], k__cospi_p08_p24);
-  v[7] = _mm_madd_epi16(u[3], k__cospi_p08_p24);
-  v[8] = _mm_madd_epi16(u[4], k__cospi_p08_p24);
-  v[9] = _mm_madd_epi16(u[5], k__cospi_p08_p24);
-  v[10] = _mm_madd_epi16(u[4], k__cospi_p24_m08);
-  v[11] = _mm_madd_epi16(u[5], k__cospi_p24_m08);
-  v[12] = _mm_madd_epi16(u[6], k__cospi_m24_p08);
-  v[13] = _mm_madd_epi16(u[7], k__cospi_m24_p08);
-  v[14] = _mm_madd_epi16(u[6], k__cospi_p08_p24);
-  v[15] = _mm_madd_epi16(u[7], k__cospi_p08_p24);
-
-  u[0] = _mm_add_epi32(v[0], v[4]);
-  u[1] = _mm_add_epi32(v[1], v[5]);
-  u[2] = _mm_add_epi32(v[2], v[6]);
-  u[3] = _mm_add_epi32(v[3], v[7]);
-  u[4] = _mm_sub_epi32(v[0], v[4]);
-  u[5] = _mm_sub_epi32(v[1], v[5]);
-  u[6] = _mm_sub_epi32(v[2], v[6]);
-  u[7] = _mm_sub_epi32(v[3], v[7]);
-  u[8] = _mm_add_epi32(v[8], v[12]);
-  u[9] = _mm_add_epi32(v[9], v[13]);
-  u[10] = _mm_add_epi32(v[10], v[14]);
-  u[11] = _mm_add_epi32(v[11], v[15]);
-  u[12] = _mm_sub_epi32(v[8], v[12]);
-  u[13] = _mm_sub_epi32(v[9], v[13]);
-  u[14] = _mm_sub_epi32(v[10], v[14]);
-  u[15] = _mm_sub_epi32(v[11], v[15]);
-
-  u[0] = _mm_add_epi32(u[0], k__DCT_CONST_ROUNDING);
-  u[1] = _mm_add_epi32(u[1], k__DCT_CONST_ROUNDING);
-  u[2] = _mm_add_epi32(u[2], k__DCT_CONST_ROUNDING);
-  u[3] = _mm_add_epi32(u[3], k__DCT_CONST_ROUNDING);
-  u[4] = _mm_add_epi32(u[4], k__DCT_CONST_ROUNDING);
-  u[5] = _mm_add_epi32(u[5], k__DCT_CONST_ROUNDING);
-  u[6] = _mm_add_epi32(u[6], k__DCT_CONST_ROUNDING);
-  u[7] = _mm_add_epi32(u[7], k__DCT_CONST_ROUNDING);
-  u[8] = _mm_add_epi32(u[8], k__DCT_CONST_ROUNDING);
-  u[9] = _mm_add_epi32(u[9], k__DCT_CONST_ROUNDING);
-  u[10] = _mm_add_epi32(u[10], k__DCT_CONST_ROUNDING);
-  u[11] = _mm_add_epi32(u[11], k__DCT_CONST_ROUNDING);
-  u[12] = _mm_add_epi32(u[12], k__DCT_CONST_ROUNDING);
-  u[13] = _mm_add_epi32(u[13], k__DCT_CONST_ROUNDING);
-  u[14] = _mm_add_epi32(u[14], k__DCT_CONST_ROUNDING);
-  u[15] = _mm_add_epi32(u[15], k__DCT_CONST_ROUNDING);
-
-  v[0] = _mm_srai_epi32(u[0], DCT_CONST_BITS);
-  v[1] = _mm_srai_epi32(u[1], DCT_CONST_BITS);
-  v[2] = _mm_srai_epi32(u[2], DCT_CONST_BITS);
-  v[3] = _mm_srai_epi32(u[3], DCT_CONST_BITS);
-  v[4] = _mm_srai_epi32(u[4], DCT_CONST_BITS);
-  v[5] = _mm_srai_epi32(u[5], DCT_CONST_BITS);
-  v[6] = _mm_srai_epi32(u[6], DCT_CONST_BITS);
-  v[7] = _mm_srai_epi32(u[7], DCT_CONST_BITS);
-  v[8] = _mm_srai_epi32(u[8], DCT_CONST_BITS);
-  v[9] = _mm_srai_epi32(u[9], DCT_CONST_BITS);
-  v[10] = _mm_srai_epi32(u[10], DCT_CONST_BITS);
-  v[11] = _mm_srai_epi32(u[11], DCT_CONST_BITS);
-  v[12] = _mm_srai_epi32(u[12], DCT_CONST_BITS);
-  v[13] = _mm_srai_epi32(u[13], DCT_CONST_BITS);
-  v[14] = _mm_srai_epi32(u[14], DCT_CONST_BITS);
-  v[15] = _mm_srai_epi32(u[15], DCT_CONST_BITS);
-
-  s[0] = _mm_add_epi16(x[0], x[2]);
-  s[1] = _mm_add_epi16(x[1], x[3]);
-  s[2] = _mm_sub_epi16(x[0], x[2]);
-  s[3] = _mm_sub_epi16(x[1], x[3]);
-  s[4] = _mm_packs_epi32(v[0], v[1]);
-  s[5] = _mm_packs_epi32(v[2], v[3]);
-  s[6] = _mm_packs_epi32(v[4], v[5]);
-  s[7] = _mm_packs_epi32(v[6], v[7]);
-  s[8] = _mm_add_epi16(x[8], x[10]);
-  s[9] = _mm_add_epi16(x[9], x[11]);
-  s[10] = _mm_sub_epi16(x[8], x[10]);
-  s[11] = _mm_sub_epi16(x[9], x[11]);
-  s[12] = _mm_packs_epi32(v[8], v[9]);
-  s[13] = _mm_packs_epi32(v[10], v[11]);
-  s[14] = _mm_packs_epi32(v[12], v[13]);
-  s[15] = _mm_packs_epi32(v[14], v[15]);
-
-  // stage 4
-  u[0] = _mm_unpacklo_epi16(s[2], s[3]);
-  u[1] = _mm_unpackhi_epi16(s[2], s[3]);
-  u[2] = _mm_unpacklo_epi16(s[6], s[7]);
-  u[3] = _mm_unpackhi_epi16(s[6], s[7]);
-  u[4] = _mm_unpacklo_epi16(s[10], s[11]);
-  u[5] = _mm_unpackhi_epi16(s[10], s[11]);
-  u[6] = _mm_unpacklo_epi16(s[14], s[15]);
-  u[7] = _mm_unpackhi_epi16(s[14], s[15]);
-
-  v[0] = _mm_madd_epi16(u[0], k__cospi_m16_m16);
-  v[1] = _mm_madd_epi16(u[1], k__cospi_m16_m16);
-  v[2] = _mm_madd_epi16(u[0], k__cospi_p16_m16);
-  v[3] = _mm_madd_epi16(u[1], k__cospi_p16_m16);
-  v[4] = _mm_madd_epi16(u[2], k__cospi_p16_p16);
-  v[5] = _mm_madd_epi16(u[3], k__cospi_p16_p16);
-  v[6] = _mm_madd_epi16(u[2], k__cospi_m16_p16);
-  v[7] = _mm_madd_epi16(u[3], k__cospi_m16_p16);
-  v[8] = _mm_madd_epi16(u[4], k__cospi_p16_p16);
-  v[9] = _mm_madd_epi16(u[5], k__cospi_p16_p16);
-  v[10] = _mm_madd_epi16(u[4], k__cospi_m16_p16);
-  v[11] = _mm_madd_epi16(u[5], k__cospi_m16_p16);
-  v[12] = _mm_madd_epi16(u[6], k__cospi_m16_m16);
-  v[13] = _mm_madd_epi16(u[7], k__cospi_m16_m16);
-  v[14] = _mm_madd_epi16(u[6], k__cospi_p16_m16);
-  v[15] = _mm_madd_epi16(u[7], k__cospi_p16_m16);
-
-  u[0] = _mm_add_epi32(v[0], k__DCT_CONST_ROUNDING);
-  u[1] = _mm_add_epi32(v[1], k__DCT_CONST_ROUNDING);
-  u[2] = _mm_add_epi32(v[2], k__DCT_CONST_ROUNDING);
-  u[3] = _mm_add_epi32(v[3], k__DCT_CONST_ROUNDING);
-  u[4] = _mm_add_epi32(v[4], k__DCT_CONST_ROUNDING);
-  u[5] = _mm_add_epi32(v[5], k__DCT_CONST_ROUNDING);
-  u[6] = _mm_add_epi32(v[6], k__DCT_CONST_ROUNDING);
-  u[7] = _mm_add_epi32(v[7], k__DCT_CONST_ROUNDING);
-  u[8] = _mm_add_epi32(v[8], k__DCT_CONST_ROUNDING);
-  u[9] = _mm_add_epi32(v[9], k__DCT_CONST_ROUNDING);
-  u[10] = _mm_add_epi32(v[10], k__DCT_CONST_ROUNDING);
-  u[11] = _mm_add_epi32(v[11], k__DCT_CONST_ROUNDING);
-  u[12] = _mm_add_epi32(v[12], k__DCT_CONST_ROUNDING);
-  u[13] = _mm_add_epi32(v[13], k__DCT_CONST_ROUNDING);
-  u[14] = _mm_add_epi32(v[14], k__DCT_CONST_ROUNDING);
-  u[15] = _mm_add_epi32(v[15], k__DCT_CONST_ROUNDING);
-
-  v[0] = _mm_srai_epi32(u[0], DCT_CONST_BITS);
-  v[1] = _mm_srai_epi32(u[1], DCT_CONST_BITS);
-  v[2] = _mm_srai_epi32(u[2], DCT_CONST_BITS);
-  v[3] = _mm_srai_epi32(u[3], DCT_CONST_BITS);
-  v[4] = _mm_srai_epi32(u[4], DCT_CONST_BITS);
-  v[5] = _mm_srai_epi32(u[5], DCT_CONST_BITS);
-  v[6] = _mm_srai_epi32(u[6], DCT_CONST_BITS);
-  v[7] = _mm_srai_epi32(u[7], DCT_CONST_BITS);
-  v[8] = _mm_srai_epi32(u[8], DCT_CONST_BITS);
-  v[9] = _mm_srai_epi32(u[9], DCT_CONST_BITS);
-  v[10] = _mm_srai_epi32(u[10], DCT_CONST_BITS);
-  v[11] = _mm_srai_epi32(u[11], DCT_CONST_BITS);
-  v[12] = _mm_srai_epi32(u[12], DCT_CONST_BITS);
-  v[13] = _mm_srai_epi32(u[13], DCT_CONST_BITS);
-  v[14] = _mm_srai_epi32(u[14], DCT_CONST_BITS);
-  v[15] = _mm_srai_epi32(u[15], DCT_CONST_BITS);
-
-  in[0] = s[0];
-  in[1] = _mm_sub_epi16(kZero, s[8]);
-  in[2] = s[12];
-  in[3] = _mm_sub_epi16(kZero, s[4]);
-  in[4] = _mm_packs_epi32(v[4], v[5]);
-  in[5] = _mm_packs_epi32(v[12], v[13]);
-  in[6] = _mm_packs_epi32(v[8], v[9]);
-  in[7] = _mm_packs_epi32(v[0], v[1]);
-  in[8] = _mm_packs_epi32(v[2], v[3]);
-  in[9] = _mm_packs_epi32(v[10], v[11]);
-  in[10] = _mm_packs_epi32(v[14], v[15]);
-  in[11] = _mm_packs_epi32(v[6], v[7]);
-  in[12] = s[5];
-  in[13] = _mm_sub_epi16(kZero, s[13]);
-  in[14] = s[9];
-  in[15] = _mm_sub_epi16(kZero, s[1]);
-}
-
-static void fdct16_sse2(__m128i *in0, __m128i *in1) {
-  fdct16_8col(in0);
-  fdct16_8col(in1);
-  array_transpose_16x16(in0, in1);
-}
-
-static void fadst16_sse2(__m128i *in0, __m128i *in1) {
-  fadst16_8col(in0);
-  fadst16_8col(in1);
-  array_transpose_16x16(in0, in1);
-}
-
-void vp9_fht16x16_sse2(const int16_t *input, tran_low_t *output,
-                       int stride, int tx_type) {
-  __m128i in0[16], in1[16];
-
-  switch (tx_type) {
-    case DCT_DCT:
-      vpx_fdct16x16_sse2(input, output, stride);
-      break;
-    case ADST_DCT:
-      load_buffer_16x16(input, in0, in1, stride);
-      fadst16_sse2(in0, in1);
-      right_shift_16x16(in0, in1);
-      fdct16_sse2(in0, in1);
-      write_buffer_16x16(output, in0, in1, 16);
-      break;
-    case DCT_ADST:
-      load_buffer_16x16(input, in0, in1, stride);
-      fdct16_sse2(in0, in1);
-      right_shift_16x16(in0, in1);
-      fadst16_sse2(in0, in1);
-      write_buffer_16x16(output, in0, in1, 16);
-      break;
-    case ADST_ADST:
-      load_buffer_16x16(input, in0, in1, stride);
-      fadst16_sse2(in0, in1);
-      right_shift_16x16(in0, in1);
-      fadst16_sse2(in0, in1);
-      write_buffer_16x16(output, in0, in1, 16);
-      break;
-    default:
-      assert(0);
-      break;
-  }
-}
diff --git a/vp9/encoder/x86/vp9_dct_sse2.asm b/vp9/encoder/x86/vp9_dct_sse2.asm
deleted file mode 100644 (file)
index d3b2a27..0000000
+++ /dev/null
@@ -1,87 +0,0 @@
-;
-;  Copyright (c) 2016 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.
-;
-
-%define private_prefix vp9
-
-%include "third_party/x86inc/x86inc.asm"
-
-SECTION .text
-
-%macro TRANSFORM_COLS 0
-  paddw           m0,        m1
-  movq            m4,        m0
-  psubw           m3,        m2
-  psubw           m4,        m3
-  psraw           m4,        1
-  movq            m5,        m4
-  psubw           m5,        m1 ;b1
-  psubw           m4,        m2 ;c1
-  psubw           m0,        m4
-  paddw           m3,        m5
-                                ; m0 a0
-  SWAP            1,         4  ; m1 c1
-  SWAP            2,         3  ; m2 d1
-  SWAP            3,         5  ; m3 b1
-%endmacro
-
-%macro TRANSPOSE_4X4 0
-                                ; 00 01 02 03
-                                ; 10 11 12 13
-                                ; 20 21 22 23
-                                ; 30 31 32 33
-  punpcklwd       m0,        m1 ; 00 10 01 11  02 12 03 13
-  punpcklwd       m2,        m3 ; 20 30 21 31  22 32 23 33
-  mova            m1,        m0
-  punpckldq       m0,        m2 ; 00 10 20 30  01 11 21 31
-  punpckhdq       m1,        m2 ; 02 12 22 32  03 13 23 33
-%endmacro
-
-INIT_XMM sse2
-cglobal fwht4x4, 3, 4, 8, input, output, stride
-; TODO(linfeng): The duplication with vp10 should be resolved.
-  lea             r3q,       [inputq + strideq*4]
-  movq            m0,        [inputq] ;a1
-  movq            m1,        [inputq + strideq*2] ;b1
-  movq            m2,        [r3q] ;c1
-  movq            m3,        [r3q + strideq*2] ;d1
-
-  TRANSFORM_COLS
-  TRANSPOSE_4X4
-  SWAP            1,         2
-  psrldq          m1,        m0, 8
-  psrldq          m3,        m2, 8
-  TRANSFORM_COLS
-  TRANSPOSE_4X4
-
-  psllw           m0,        2
-  psllw           m1,        2
-
-%if CONFIG_VP9_HIGHBITDEPTH
-  ; sign extension
-  mova            m2,             m0
-  mova            m3,             m1
-  punpcklwd       m0,             m0
-  punpcklwd       m1,             m1
-  punpckhwd       m2,             m2
-  punpckhwd       m3,             m3
-  psrad           m0,             16
-  psrad           m1,             16
-  psrad           m2,             16
-  psrad           m3,             16
-  mova            [outputq],      m0
-  mova            [outputq + 16], m2
-  mova            [outputq + 32], m1
-  mova            [outputq + 48], m3
-%else
-  mova            [outputq],      m0
-  mova            [outputq + 16], m1
-%endif
-
-  RET
diff --git a/vp9/encoder/x86/vp9_dct_ssse3.c b/vp9/encoder/x86/vp9_dct_ssse3.c
deleted file mode 100644 (file)
index 1a1d4ea..0000000
+++ /dev/null
@@ -1,467 +0,0 @@
-/*
- *  Copyright (c) 2014 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.
- */
-
-#include <assert.h>
-#include <tmmintrin.h>  // SSSE3
-
-#include "./vp9_rtcd.h"
-#include "vpx_dsp/x86/inv_txfm_sse2.h"
-#include "vpx_dsp/x86/txfm_common_sse2.h"
-
-void vp9_fdct8x8_quant_ssse3(const int16_t *input, int stride,
-                             int16_t* coeff_ptr, intptr_t n_coeffs,
-                             int skip_block, const int16_t* zbin_ptr,
-                             const int16_t* round_ptr, const int16_t* quant_ptr,
-                             const int16_t* quant_shift_ptr,
-                             int16_t* qcoeff_ptr,
-                             int16_t* dqcoeff_ptr, const int16_t* dequant_ptr,
-                             uint16_t* eob_ptr,
-                             const int16_t* scan_ptr,
-                             const int16_t* iscan_ptr) {
-  __m128i zero;
-  int pass;
-  // Constants
-  //    When we use them, in one case, they are all the same. In all others
-  //    it's a pair of them that we need to repeat four times. This is done
-  //    by constructing the 32 bit constant corresponding to that pair.
-  const __m128i k__dual_p16_p16 = dual_set_epi16(23170, 23170);
-  const __m128i k__cospi_p16_p16 = _mm_set1_epi16((int16_t)cospi_16_64);
-  const __m128i k__cospi_p16_m16 = pair_set_epi16(cospi_16_64, -cospi_16_64);
-  const __m128i k__cospi_p24_p08 = pair_set_epi16(cospi_24_64, cospi_8_64);
-  const __m128i k__cospi_m08_p24 = pair_set_epi16(-cospi_8_64, cospi_24_64);
-  const __m128i k__cospi_p28_p04 = pair_set_epi16(cospi_28_64, cospi_4_64);
-  const __m128i k__cospi_m04_p28 = pair_set_epi16(-cospi_4_64, cospi_28_64);
-  const __m128i k__cospi_p12_p20 = pair_set_epi16(cospi_12_64, cospi_20_64);
-  const __m128i k__cospi_m20_p12 = pair_set_epi16(-cospi_20_64, cospi_12_64);
-  const __m128i k__DCT_CONST_ROUNDING = _mm_set1_epi32(DCT_CONST_ROUNDING);
-  // Load input
-  __m128i in0  = _mm_load_si128((const __m128i *)(input + 0 * stride));
-  __m128i in1  = _mm_load_si128((const __m128i *)(input + 1 * stride));
-  __m128i in2  = _mm_load_si128((const __m128i *)(input + 2 * stride));
-  __m128i in3  = _mm_load_si128((const __m128i *)(input + 3 * stride));
-  __m128i in4  = _mm_load_si128((const __m128i *)(input + 4 * stride));
-  __m128i in5  = _mm_load_si128((const __m128i *)(input + 5 * stride));
-  __m128i in6  = _mm_load_si128((const __m128i *)(input + 6 * stride));
-  __m128i in7  = _mm_load_si128((const __m128i *)(input + 7 * stride));
-  __m128i *in[8];
-  int index = 0;
-
-  (void)scan_ptr;
-  (void)zbin_ptr;
-  (void)quant_shift_ptr;
-  (void)coeff_ptr;
-
-  // Pre-condition input (shift by two)
-  in0 = _mm_slli_epi16(in0, 2);
-  in1 = _mm_slli_epi16(in1, 2);
-  in2 = _mm_slli_epi16(in2, 2);
-  in3 = _mm_slli_epi16(in3, 2);
-  in4 = _mm_slli_epi16(in4, 2);
-  in5 = _mm_slli_epi16(in5, 2);
-  in6 = _mm_slli_epi16(in6, 2);
-  in7 = _mm_slli_epi16(in7, 2);
-
-  in[0] = &in0;
-  in[1] = &in1;
-  in[2] = &in2;
-  in[3] = &in3;
-  in[4] = &in4;
-  in[5] = &in5;
-  in[6] = &in6;
-  in[7] = &in7;
-
-  // We do two passes, first the columns, then the rows. The results of the
-  // first pass are transposed so that the same column code can be reused. The
-  // results of the second pass are also transposed so that the rows (processed
-  // as columns) are put back in row positions.
-  for (pass = 0; pass < 2; pass++) {
-    // To store results of each pass before the transpose.
-    __m128i res0, res1, res2, res3, res4, res5, res6, res7;
-    // Add/subtract
-    const __m128i q0 = _mm_add_epi16(in0, in7);
-    const __m128i q1 = _mm_add_epi16(in1, in6);
-    const __m128i q2 = _mm_add_epi16(in2, in5);
-    const __m128i q3 = _mm_add_epi16(in3, in4);
-    const __m128i q4 = _mm_sub_epi16(in3, in4);
-    const __m128i q5 = _mm_sub_epi16(in2, in5);
-    const __m128i q6 = _mm_sub_epi16(in1, in6);
-    const __m128i q7 = _mm_sub_epi16(in0, in7);
-    // Work on first four results
-    {
-      // Add/subtract
-      const __m128i r0 = _mm_add_epi16(q0, q3);
-      const __m128i r1 = _mm_add_epi16(q1, q2);
-      const __m128i r2 = _mm_sub_epi16(q1, q2);
-      const __m128i r3 = _mm_sub_epi16(q0, q3);
-      // Interleave to do the multiply by constants which gets us into 32bits
-      const __m128i t0 = _mm_unpacklo_epi16(r0, r1);
-      const __m128i t1 = _mm_unpackhi_epi16(r0, r1);
-      const __m128i t2 = _mm_unpacklo_epi16(r2, r3);
-      const __m128i t3 = _mm_unpackhi_epi16(r2, r3);
-
-      const __m128i u0 = _mm_madd_epi16(t0, k__cospi_p16_p16);
-      const __m128i u1 = _mm_madd_epi16(t1, k__cospi_p16_p16);
-      const __m128i u2 = _mm_madd_epi16(t0, k__cospi_p16_m16);
-      const __m128i u3 = _mm_madd_epi16(t1, k__cospi_p16_m16);
-
-      const __m128i u4 = _mm_madd_epi16(t2, k__cospi_p24_p08);
-      const __m128i u5 = _mm_madd_epi16(t3, k__cospi_p24_p08);
-      const __m128i u6 = _mm_madd_epi16(t2, k__cospi_m08_p24);
-      const __m128i u7 = _mm_madd_epi16(t3, k__cospi_m08_p24);
-      // dct_const_round_shift
-
-      const __m128i v0 = _mm_add_epi32(u0, k__DCT_CONST_ROUNDING);
-      const __m128i v1 = _mm_add_epi32(u1, k__DCT_CONST_ROUNDING);
-      const __m128i v2 = _mm_add_epi32(u2, k__DCT_CONST_ROUNDING);
-      const __m128i v3 = _mm_add_epi32(u3, k__DCT_CONST_ROUNDING);
-
-      const __m128i v4 = _mm_add_epi32(u4, k__DCT_CONST_ROUNDING);
-      const __m128i v5 = _mm_add_epi32(u5, k__DCT_CONST_ROUNDING);
-      const __m128i v6 = _mm_add_epi32(u6, k__DCT_CONST_ROUNDING);
-      const __m128i v7 = _mm_add_epi32(u7, k__DCT_CONST_ROUNDING);
-
-      const __m128i w0 = _mm_srai_epi32(v0, DCT_CONST_BITS);
-      const __m128i w1 = _mm_srai_epi32(v1, DCT_CONST_BITS);
-      const __m128i w2 = _mm_srai_epi32(v2, DCT_CONST_BITS);
-      const __m128i w3 = _mm_srai_epi32(v3, DCT_CONST_BITS);
-
-      const __m128i w4 = _mm_srai_epi32(v4, DCT_CONST_BITS);
-      const __m128i w5 = _mm_srai_epi32(v5, DCT_CONST_BITS);
-      const __m128i w6 = _mm_srai_epi32(v6, DCT_CONST_BITS);
-      const __m128i w7 = _mm_srai_epi32(v7, DCT_CONST_BITS);
-      // Combine
-
-      res0 = _mm_packs_epi32(w0, w1);
-      res4 = _mm_packs_epi32(w2, w3);
-      res2 = _mm_packs_epi32(w4, w5);
-      res6 = _mm_packs_epi32(w6, w7);
-    }
-    // Work on next four results
-    {
-      // Interleave to do the multiply by constants which gets us into 32bits
-      const __m128i d0 = _mm_sub_epi16(q6, q5);
-      const __m128i d1 = _mm_add_epi16(q6, q5);
-      const __m128i r0 = _mm_mulhrs_epi16(d0, k__dual_p16_p16);
-      const __m128i r1 = _mm_mulhrs_epi16(d1, k__dual_p16_p16);
-
-      // Add/subtract
-      const __m128i x0 = _mm_add_epi16(q4, r0);
-      const __m128i x1 = _mm_sub_epi16(q4, r0);
-      const __m128i x2 = _mm_sub_epi16(q7, r1);
-      const __m128i x3 = _mm_add_epi16(q7, r1);
-      // Interleave to do the multiply by constants which gets us into 32bits
-      const __m128i t0 = _mm_unpacklo_epi16(x0, x3);
-      const __m128i t1 = _mm_unpackhi_epi16(x0, x3);
-      const __m128i t2 = _mm_unpacklo_epi16(x1, x2);
-      const __m128i t3 = _mm_unpackhi_epi16(x1, x2);
-      const __m128i u0 = _mm_madd_epi16(t0, k__cospi_p28_p04);
-      const __m128i u1 = _mm_madd_epi16(t1, k__cospi_p28_p04);
-      const __m128i u2 = _mm_madd_epi16(t0, k__cospi_m04_p28);
-      const __m128i u3 = _mm_madd_epi16(t1, k__cospi_m04_p28);
-      const __m128i u4 = _mm_madd_epi16(t2, k__cospi_p12_p20);
-      const __m128i u5 = _mm_madd_epi16(t3, k__cospi_p12_p20);
-      const __m128i u6 = _mm_madd_epi16(t2, k__cospi_m20_p12);
-      const __m128i u7 = _mm_madd_epi16(t3, k__cospi_m20_p12);
-      // dct_const_round_shift
-      const __m128i v0 = _mm_add_epi32(u0, k__DCT_CONST_ROUNDING);
-      const __m128i v1 = _mm_add_epi32(u1, k__DCT_CONST_ROUNDING);
-      const __m128i v2 = _mm_add_epi32(u2, k__DCT_CONST_ROUNDING);
-      const __m128i v3 = _mm_add_epi32(u3, k__DCT_CONST_ROUNDING);
-      const __m128i v4 = _mm_add_epi32(u4, k__DCT_CONST_ROUNDING);
-      const __m128i v5 = _mm_add_epi32(u5, k__DCT_CONST_ROUNDING);
-      const __m128i v6 = _mm_add_epi32(u6, k__DCT_CONST_ROUNDING);
-      const __m128i v7 = _mm_add_epi32(u7, k__DCT_CONST_ROUNDING);
-      const __m128i w0 = _mm_srai_epi32(v0, DCT_CONST_BITS);
-      const __m128i w1 = _mm_srai_epi32(v1, DCT_CONST_BITS);
-      const __m128i w2 = _mm_srai_epi32(v2, DCT_CONST_BITS);
-      const __m128i w3 = _mm_srai_epi32(v3, DCT_CONST_BITS);
-      const __m128i w4 = _mm_srai_epi32(v4, DCT_CONST_BITS);
-      const __m128i w5 = _mm_srai_epi32(v5, DCT_CONST_BITS);
-      const __m128i w6 = _mm_srai_epi32(v6, DCT_CONST_BITS);
-      const __m128i w7 = _mm_srai_epi32(v7, DCT_CONST_BITS);
-      // Combine
-      res1 = _mm_packs_epi32(w0, w1);
-      res7 = _mm_packs_epi32(w2, w3);
-      res5 = _mm_packs_epi32(w4, w5);
-      res3 = _mm_packs_epi32(w6, w7);
-    }
-    // Transpose the 8x8.
-    {
-      // 00 01 02 03 04 05 06 07
-      // 10 11 12 13 14 15 16 17
-      // 20 21 22 23 24 25 26 27
-      // 30 31 32 33 34 35 36 37
-      // 40 41 42 43 44 45 46 47
-      // 50 51 52 53 54 55 56 57
-      // 60 61 62 63 64 65 66 67
-      // 70 71 72 73 74 75 76 77
-      const __m128i tr0_0 = _mm_unpacklo_epi16(res0, res1);
-      const __m128i tr0_1 = _mm_unpacklo_epi16(res2, res3);
-      const __m128i tr0_2 = _mm_unpackhi_epi16(res0, res1);
-      const __m128i tr0_3 = _mm_unpackhi_epi16(res2, res3);
-      const __m128i tr0_4 = _mm_unpacklo_epi16(res4, res5);
-      const __m128i tr0_5 = _mm_unpacklo_epi16(res6, res7);
-      const __m128i tr0_6 = _mm_unpackhi_epi16(res4, res5);
-      const __m128i tr0_7 = _mm_unpackhi_epi16(res6, res7);
-      // 00 10 01 11 02 12 03 13
-      // 20 30 21 31 22 32 23 33
-      // 04 14 05 15 06 16 07 17
-      // 24 34 25 35 26 36 27 37
-      // 40 50 41 51 42 52 43 53
-      // 60 70 61 71 62 72 63 73
-      // 54 54 55 55 56 56 57 57
-      // 64 74 65 75 66 76 67 77
-      const __m128i tr1_0 = _mm_unpacklo_epi32(tr0_0, tr0_1);
-      const __m128i tr1_1 = _mm_unpacklo_epi32(tr0_2, tr0_3);
-      const __m128i tr1_2 = _mm_unpackhi_epi32(tr0_0, tr0_1);
-      const __m128i tr1_3 = _mm_unpackhi_epi32(tr0_2, tr0_3);
-      const __m128i tr1_4 = _mm_unpacklo_epi32(tr0_4, tr0_5);
-      const __m128i tr1_5 = _mm_unpacklo_epi32(tr0_6, tr0_7);
-      const __m128i tr1_6 = _mm_unpackhi_epi32(tr0_4, tr0_5);
-      const __m128i tr1_7 = _mm_unpackhi_epi32(tr0_6, tr0_7);
-      // 00 10 20 30 01 11 21 31
-      // 40 50 60 70 41 51 61 71
-      // 02 12 22 32 03 13 23 33
-      // 42 52 62 72 43 53 63 73
-      // 04 14 24 34 05 15 21 36
-      // 44 54 64 74 45 55 61 76
-      // 06 16 26 36 07 17 27 37
-      // 46 56 66 76 47 57 67 77
-      in0 = _mm_unpacklo_epi64(tr1_0, tr1_4);
-      in1 = _mm_unpackhi_epi64(tr1_0, tr1_4);
-      in2 = _mm_unpacklo_epi64(tr1_2, tr1_6);
-      in3 = _mm_unpackhi_epi64(tr1_2, tr1_6);
-      in4 = _mm_unpacklo_epi64(tr1_1, tr1_5);
-      in5 = _mm_unpackhi_epi64(tr1_1, tr1_5);
-      in6 = _mm_unpacklo_epi64(tr1_3, tr1_7);
-      in7 = _mm_unpackhi_epi64(tr1_3, tr1_7);
-      // 00 10 20 30 40 50 60 70
-      // 01 11 21 31 41 51 61 71
-      // 02 12 22 32 42 52 62 72
-      // 03 13 23 33 43 53 63 73
-      // 04 14 24 34 44 54 64 74
-      // 05 15 25 35 45 55 65 75
-      // 06 16 26 36 46 56 66 76
-      // 07 17 27 37 47 57 67 77
-    }
-  }
-  // Post-condition output and store it
-  {
-    // Post-condition (division by two)
-    //    division of two 16 bits signed numbers using shifts
-    //    n / 2 = (n - (n >> 15)) >> 1
-    const __m128i sign_in0 = _mm_srai_epi16(in0, 15);
-    const __m128i sign_in1 = _mm_srai_epi16(in1, 15);
-    const __m128i sign_in2 = _mm_srai_epi16(in2, 15);
-    const __m128i sign_in3 = _mm_srai_epi16(in3, 15);
-    const __m128i sign_in4 = _mm_srai_epi16(in4, 15);
-    const __m128i sign_in5 = _mm_srai_epi16(in5, 15);
-    const __m128i sign_in6 = _mm_srai_epi16(in6, 15);
-    const __m128i sign_in7 = _mm_srai_epi16(in7, 15);
-    in0 = _mm_sub_epi16(in0, sign_in0);
-    in1 = _mm_sub_epi16(in1, sign_in1);
-    in2 = _mm_sub_epi16(in2, sign_in2);
-    in3 = _mm_sub_epi16(in3, sign_in3);
-    in4 = _mm_sub_epi16(in4, sign_in4);
-    in5 = _mm_sub_epi16(in5, sign_in5);
-    in6 = _mm_sub_epi16(in6, sign_in6);
-    in7 = _mm_sub_epi16(in7, sign_in7);
-    in0 = _mm_srai_epi16(in0, 1);
-    in1 = _mm_srai_epi16(in1, 1);
-    in2 = _mm_srai_epi16(in2, 1);
-    in3 = _mm_srai_epi16(in3, 1);
-    in4 = _mm_srai_epi16(in4, 1);
-    in5 = _mm_srai_epi16(in5, 1);
-    in6 = _mm_srai_epi16(in6, 1);
-    in7 = _mm_srai_epi16(in7, 1);
-  }
-
-  iscan_ptr += n_coeffs;
-  qcoeff_ptr += n_coeffs;
-  dqcoeff_ptr += n_coeffs;
-  n_coeffs = -n_coeffs;
-  zero = _mm_setzero_si128();
-
-  if (!skip_block) {
-    __m128i eob;
-    __m128i round, quant, dequant, thr;
-    int16_t nzflag;
-    {
-      __m128i coeff0, coeff1;
-
-      // Setup global values
-      {
-        round = _mm_load_si128((const __m128i*)round_ptr);
-        quant = _mm_load_si128((const __m128i*)quant_ptr);
-        dequant = _mm_load_si128((const __m128i*)dequant_ptr);
-      }
-
-      {
-        __m128i coeff0_sign, coeff1_sign;
-        __m128i qcoeff0, qcoeff1;
-        __m128i qtmp0, qtmp1;
-        // Do DC and first 15 AC
-        coeff0 = *in[0];
-        coeff1 = *in[1];
-
-        // Poor man's sign extract
-        coeff0_sign = _mm_srai_epi16(coeff0, 15);
-        coeff1_sign = _mm_srai_epi16(coeff1, 15);
-        qcoeff0 = _mm_xor_si128(coeff0, coeff0_sign);
-        qcoeff1 = _mm_xor_si128(coeff1, coeff1_sign);
-        qcoeff0 = _mm_sub_epi16(qcoeff0, coeff0_sign);
-        qcoeff1 = _mm_sub_epi16(qcoeff1, coeff1_sign);
-
-        qcoeff0 = _mm_adds_epi16(qcoeff0, round);
-        round = _mm_unpackhi_epi64(round, round);
-        qcoeff1 = _mm_adds_epi16(qcoeff1, round);
-        qtmp0 = _mm_mulhi_epi16(qcoeff0, quant);
-        quant = _mm_unpackhi_epi64(quant, quant);
-        qtmp1 = _mm_mulhi_epi16(qcoeff1, quant);
-
-        // Reinsert signs
-        qcoeff0 = _mm_xor_si128(qtmp0, coeff0_sign);
-        qcoeff1 = _mm_xor_si128(qtmp1, coeff1_sign);
-        qcoeff0 = _mm_sub_epi16(qcoeff0, coeff0_sign);
-        qcoeff1 = _mm_sub_epi16(qcoeff1, coeff1_sign);
-
-        _mm_store_si128((__m128i*)(qcoeff_ptr + n_coeffs), qcoeff0);
-        _mm_store_si128((__m128i*)(qcoeff_ptr + n_coeffs) + 1, qcoeff1);
-
-        coeff0 = _mm_mullo_epi16(qcoeff0, dequant);
-        dequant = _mm_unpackhi_epi64(dequant, dequant);
-        coeff1 = _mm_mullo_epi16(qcoeff1, dequant);
-
-        _mm_store_si128((__m128i*)(dqcoeff_ptr + n_coeffs), coeff0);
-        _mm_store_si128((__m128i*)(dqcoeff_ptr + n_coeffs) + 1, coeff1);
-      }
-
-      {
-        // Scan for eob
-        __m128i zero_coeff0, zero_coeff1;
-        __m128i nzero_coeff0, nzero_coeff1;
-        __m128i iscan0, iscan1;
-        __m128i eob1;
-        zero_coeff0 = _mm_cmpeq_epi16(coeff0, zero);
-        zero_coeff1 = _mm_cmpeq_epi16(coeff1, zero);
-        nzero_coeff0 = _mm_cmpeq_epi16(zero_coeff0, zero);
-        nzero_coeff1 = _mm_cmpeq_epi16(zero_coeff1, zero);
-        iscan0 = _mm_load_si128((const __m128i*)(iscan_ptr + n_coeffs));
-        iscan1 = _mm_load_si128((const __m128i*)(iscan_ptr + n_coeffs) + 1);
-        // Add one to convert from indices to counts
-        iscan0 = _mm_sub_epi16(iscan0, nzero_coeff0);
-        iscan1 = _mm_sub_epi16(iscan1, nzero_coeff1);
-        eob = _mm_and_si128(iscan0, nzero_coeff0);
-        eob1 = _mm_and_si128(iscan1, nzero_coeff1);
-        eob = _mm_max_epi16(eob, eob1);
-      }
-      n_coeffs += 8 * 2;
-    }
-
-    // AC only loop
-    index = 2;
-    thr = _mm_srai_epi16(dequant, 1);
-    while (n_coeffs < 0) {
-      __m128i coeff0, coeff1;
-      {
-        __m128i coeff0_sign, coeff1_sign;
-        __m128i qcoeff0, qcoeff1;
-        __m128i qtmp0, qtmp1;
-
-        assert(index < (int)(sizeof(in) / sizeof(in[0])) - 1);
-        coeff0 = *in[index];
-        coeff1 = *in[index + 1];
-
-        // Poor man's sign extract
-        coeff0_sign = _mm_srai_epi16(coeff0, 15);
-        coeff1_sign = _mm_srai_epi16(coeff1, 15);
-        qcoeff0 = _mm_xor_si128(coeff0, coeff0_sign);
-        qcoeff1 = _mm_xor_si128(coeff1, coeff1_sign);
-        qcoeff0 = _mm_sub_epi16(qcoeff0, coeff0_sign);
-        qcoeff1 = _mm_sub_epi16(qcoeff1, coeff1_sign);
-
-        nzflag = _mm_movemask_epi8(_mm_cmpgt_epi16(qcoeff0, thr)) |
-            _mm_movemask_epi8(_mm_cmpgt_epi16(qcoeff1, thr));
-
-        if (nzflag) {
-          qcoeff0 = _mm_adds_epi16(qcoeff0, round);
-          qcoeff1 = _mm_adds_epi16(qcoeff1, round);
-          qtmp0 = _mm_mulhi_epi16(qcoeff0, quant);
-          qtmp1 = _mm_mulhi_epi16(qcoeff1, quant);
-
-          // Reinsert signs
-          qcoeff0 = _mm_xor_si128(qtmp0, coeff0_sign);
-          qcoeff1 = _mm_xor_si128(qtmp1, coeff1_sign);
-          qcoeff0 = _mm_sub_epi16(qcoeff0, coeff0_sign);
-          qcoeff1 = _mm_sub_epi16(qcoeff1, coeff1_sign);
-
-          _mm_store_si128((__m128i*)(qcoeff_ptr + n_coeffs), qcoeff0);
-          _mm_store_si128((__m128i*)(qcoeff_ptr + n_coeffs) + 1, qcoeff1);
-
-          coeff0 = _mm_mullo_epi16(qcoeff0, dequant);
-          coeff1 = _mm_mullo_epi16(qcoeff1, dequant);
-
-          _mm_store_si128((__m128i*)(dqcoeff_ptr + n_coeffs), coeff0);
-          _mm_store_si128((__m128i*)(dqcoeff_ptr + n_coeffs) + 1, coeff1);
-        } else {
-          _mm_store_si128((__m128i*)(qcoeff_ptr + n_coeffs), zero);
-          _mm_store_si128((__m128i*)(qcoeff_ptr + n_coeffs) + 1, zero);
-
-          _mm_store_si128((__m128i*)(dqcoeff_ptr + n_coeffs), zero);
-          _mm_store_si128((__m128i*)(dqcoeff_ptr + n_coeffs) + 1, zero);
-        }
-      }
-
-      if (nzflag) {
-        // Scan for eob
-        __m128i zero_coeff0, zero_coeff1;
-        __m128i nzero_coeff0, nzero_coeff1;
-        __m128i iscan0, iscan1;
-        __m128i eob0, eob1;
-        zero_coeff0 = _mm_cmpeq_epi16(coeff0, zero);
-        zero_coeff1 = _mm_cmpeq_epi16(coeff1, zero);
-        nzero_coeff0 = _mm_cmpeq_epi16(zero_coeff0, zero);
-        nzero_coeff1 = _mm_cmpeq_epi16(zero_coeff1, zero);
-        iscan0 = _mm_load_si128((const __m128i*)(iscan_ptr + n_coeffs));
-        iscan1 = _mm_load_si128((const __m128i*)(iscan_ptr + n_coeffs) + 1);
-        // Add one to convert from indices to counts
-        iscan0 = _mm_sub_epi16(iscan0, nzero_coeff0);
-        iscan1 = _mm_sub_epi16(iscan1, nzero_coeff1);
-        eob0 = _mm_and_si128(iscan0, nzero_coeff0);
-        eob1 = _mm_and_si128(iscan1, nzero_coeff1);
-        eob0 = _mm_max_epi16(eob0, eob1);
-        eob = _mm_max_epi16(eob, eob0);
-      }
-      n_coeffs += 8 * 2;
-      index += 2;
-    }
-
-    // Accumulate EOB
-    {
-      __m128i eob_shuffled;
-      eob_shuffled = _mm_shuffle_epi32(eob, 0xe);
-      eob = _mm_max_epi16(eob, eob_shuffled);
-      eob_shuffled = _mm_shufflelo_epi16(eob, 0xe);
-      eob = _mm_max_epi16(eob, eob_shuffled);
-      eob_shuffled = _mm_shufflelo_epi16(eob, 0x1);
-      eob = _mm_max_epi16(eob, eob_shuffled);
-      *eob_ptr = _mm_extract_epi16(eob, 1);
-    }
-  } else {
-    do {
-      _mm_store_si128((__m128i*)(dqcoeff_ptr + n_coeffs), zero);
-      _mm_store_si128((__m128i*)(dqcoeff_ptr + n_coeffs) + 1, zero);
-      _mm_store_si128((__m128i*)(qcoeff_ptr + n_coeffs), zero);
-      _mm_store_si128((__m128i*)(qcoeff_ptr + n_coeffs) + 1, zero);
-      n_coeffs += 8 * 2;
-    } while (n_coeffs < 0);
-    *eob_ptr = 0;
-  }
-}
diff --git a/vp9/encoder/x86/vp9_denoiser_sse2.c b/vp9/encoder/x86/vp9_denoiser_sse2.c
deleted file mode 100644 (file)
index 883507a..0000000
+++ /dev/null
@@ -1,341 +0,0 @@
-/*
- *  Copyright (c) 2014 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.
- */
-
-#include <emmintrin.h>
-
-#include "./vpx_config.h"
-#include "./vp9_rtcd.h"
-
-#include "vpx_ports/emmintrin_compat.h"
-#include "vpx/vpx_integer.h"
-#include "vp9/common/vp9_reconinter.h"
-#include "vp9/encoder/vp9_context_tree.h"
-#include "vp9/encoder/vp9_denoiser.h"
-#include "vpx_mem/vpx_mem.h"
-
-// Compute the sum of all pixel differences of this MB.
-static INLINE int sum_diff_16x1(__m128i acc_diff) {
-  const __m128i k_1 = _mm_set1_epi16(1);
-  const __m128i acc_diff_lo =
-      _mm_srai_epi16(_mm_unpacklo_epi8(acc_diff, acc_diff), 8);
-  const __m128i acc_diff_hi =
-      _mm_srai_epi16(_mm_unpackhi_epi8(acc_diff, acc_diff), 8);
-  const __m128i acc_diff_16 = _mm_add_epi16(acc_diff_lo, acc_diff_hi);
-  const __m128i hg_fe_dc_ba = _mm_madd_epi16(acc_diff_16, k_1);
-  const __m128i hgfe_dcba =
-      _mm_add_epi32(hg_fe_dc_ba, _mm_srli_si128(hg_fe_dc_ba, 8));
-  const __m128i hgfedcba =
-      _mm_add_epi32(hgfe_dcba, _mm_srli_si128(hgfe_dcba, 4));
-  return _mm_cvtsi128_si32(hgfedcba);
-}
-
-// Denoise a 16x1 vector.
-static INLINE __m128i vp9_denoiser_16x1_sse2(const uint8_t *sig,
-                                             const uint8_t *mc_running_avg_y,
-                                             uint8_t *running_avg_y,
-                                             const __m128i *k_0,
-                                             const __m128i *k_4,
-                                             const __m128i *k_8,
-                                             const __m128i *k_16,
-                                             const __m128i *l3,
-                                             const __m128i *l32,
-                                             const __m128i *l21,
-                                             __m128i acc_diff) {
-  // Calculate differences
-  const __m128i v_sig = _mm_loadu_si128((const __m128i *)(&sig[0]));
-  const __m128i v_mc_running_avg_y =
-      _mm_loadu_si128((const __m128i *)(&mc_running_avg_y[0]));
-  __m128i v_running_avg_y;
-  const __m128i pdiff = _mm_subs_epu8(v_mc_running_avg_y, v_sig);
-  const __m128i ndiff = _mm_subs_epu8(v_sig, v_mc_running_avg_y);
-  // Obtain the sign. FF if diff is negative.
-  const __m128i diff_sign = _mm_cmpeq_epi8(pdiff, *k_0);
-  // Clamp absolute difference to 16 to be used to get mask. Doing this
-  // allows us to use _mm_cmpgt_epi8, which operates on signed byte.
-  const __m128i clamped_absdiff =
-      _mm_min_epu8(_mm_or_si128(pdiff, ndiff), *k_16);
-  // Get masks for l2 l1 and l0 adjustments.
-  const __m128i mask2 = _mm_cmpgt_epi8(*k_16, clamped_absdiff);
-  const __m128i mask1 = _mm_cmpgt_epi8(*k_8, clamped_absdiff);
-  const __m128i mask0 = _mm_cmpgt_epi8(*k_4, clamped_absdiff);
-  // Get adjustments for l2, l1, and l0.
-  __m128i adj2 = _mm_and_si128(mask2, *l32);
-  const __m128i adj1 = _mm_and_si128(mask1, *l21);
-  const __m128i adj0 = _mm_and_si128(mask0, clamped_absdiff);
-  __m128i adj,  padj, nadj;
-
-  // Combine the adjustments and get absolute adjustments.
-  adj2 = _mm_add_epi8(adj2, adj1);
-  adj = _mm_sub_epi8(*l3, adj2);
-  adj = _mm_andnot_si128(mask0, adj);
-  adj = _mm_or_si128(adj, adj0);
-
-  // Restore the sign and get positive and negative adjustments.
-  padj = _mm_andnot_si128(diff_sign, adj);
-  nadj = _mm_and_si128(diff_sign, adj);
-
-  // Calculate filtered value.
-  v_running_avg_y = _mm_adds_epu8(v_sig, padj);
-  v_running_avg_y = _mm_subs_epu8(v_running_avg_y, nadj);
-  _mm_storeu_si128((__m128i *)running_avg_y, v_running_avg_y);
-
-  // Adjustments <=7, and each element in acc_diff can fit in signed
-  // char.
-  acc_diff = _mm_adds_epi8(acc_diff, padj);
-  acc_diff = _mm_subs_epi8(acc_diff, nadj);
-  return acc_diff;
-}
-
-// Denoise a 16x1 vector with a weaker filter.
-static INLINE __m128i vp9_denoiser_adj_16x1_sse2(
-    const uint8_t *sig, const uint8_t *mc_running_avg_y,
-    uint8_t *running_avg_y, const __m128i k_0,
-    const __m128i k_delta, __m128i acc_diff) {
-  __m128i v_running_avg_y = _mm_loadu_si128((__m128i *)(&running_avg_y[0]));
-  // Calculate differences.
-  const __m128i v_sig = _mm_loadu_si128((const __m128i *)(&sig[0]));
-  const __m128i v_mc_running_avg_y =
-      _mm_loadu_si128((const __m128i *)(&mc_running_avg_y[0]));
-  const __m128i pdiff = _mm_subs_epu8(v_mc_running_avg_y, v_sig);
-  const __m128i ndiff = _mm_subs_epu8(v_sig, v_mc_running_avg_y);
-  // Obtain the sign. FF if diff is negative.
-  const __m128i diff_sign = _mm_cmpeq_epi8(pdiff, k_0);
-  // Clamp absolute difference to delta to get the adjustment.
-  const __m128i adj =
-      _mm_min_epu8(_mm_or_si128(pdiff, ndiff), k_delta);
-  // Restore the sign and get positive and negative adjustments.
-  __m128i padj, nadj;
-  padj = _mm_andnot_si128(diff_sign, adj);
-  nadj = _mm_and_si128(diff_sign, adj);
-  // Calculate filtered value.
-  v_running_avg_y = _mm_subs_epu8(v_running_avg_y, padj);
-  v_running_avg_y = _mm_adds_epu8(v_running_avg_y, nadj);
-  _mm_storeu_si128((__m128i *)running_avg_y, v_running_avg_y);
-
-  // Accumulate the adjustments.
-  acc_diff = _mm_subs_epi8(acc_diff, padj);
-  acc_diff = _mm_adds_epi8(acc_diff, nadj);
-  return acc_diff;
-}
-
-// Denoise 8x8 and 8x16 blocks.
-static int vp9_denoiser_NxM_sse2_small(
-    const uint8_t *sig, int sig_stride, const uint8_t *mc_running_avg_y,
-    int mc_avg_y_stride, uint8_t *running_avg_y, int avg_y_stride,
-    int increase_denoising, BLOCK_SIZE bs, int motion_magnitude, int width) {
-  int sum_diff_thresh, r, sum_diff = 0;
-  const int shift_inc  = (increase_denoising &&
-                          motion_magnitude <= MOTION_MAGNITUDE_THRESHOLD) ?
-                         1 : 0;
-  uint8_t sig_buffer[8][16], mc_running_buffer[8][16], running_buffer[8][16];
-  __m128i acc_diff = _mm_setzero_si128();
-  const __m128i k_0 = _mm_setzero_si128();
-  const __m128i k_4 = _mm_set1_epi8(4 + shift_inc);
-  const __m128i k_8 = _mm_set1_epi8(8);
-  const __m128i k_16 = _mm_set1_epi8(16);
-  // Modify each level's adjustment according to motion_magnitude.
-  const __m128i l3 = _mm_set1_epi8(
-      (motion_magnitude <= MOTION_MAGNITUDE_THRESHOLD) ? 7 + shift_inc : 6);
-  // Difference between level 3 and level 2 is 2.
-  const __m128i l32 = _mm_set1_epi8(2);
-  // Difference between level 2 and level 1 is 1.
-  const __m128i l21 = _mm_set1_epi8(1);
-  const int b_height = (4 << b_height_log2_lookup[bs]) >> 1;
-
-  for (r = 0; r < b_height; ++r) {
-    memcpy(sig_buffer[r], sig, width);
-    memcpy(sig_buffer[r] + width, sig + sig_stride, width);
-    memcpy(mc_running_buffer[r], mc_running_avg_y, width);
-    memcpy(mc_running_buffer[r] + width,
-           mc_running_avg_y + mc_avg_y_stride, width);
-    memcpy(running_buffer[r], running_avg_y, width);
-    memcpy(running_buffer[r] + width, running_avg_y + avg_y_stride, width);
-    acc_diff = vp9_denoiser_16x1_sse2(sig_buffer[r],
-                                      mc_running_buffer[r],
-                                      running_buffer[r],
-                                      &k_0, &k_4, &k_8, &k_16,
-                                      &l3, &l32, &l21, acc_diff);
-    memcpy(running_avg_y, running_buffer[r], width);
-    memcpy(running_avg_y + avg_y_stride, running_buffer[r] + width, width);
-    // Update pointers for next iteration.
-    sig += (sig_stride << 1);
-    mc_running_avg_y += (mc_avg_y_stride << 1);
-    running_avg_y += (avg_y_stride << 1);
-  }
-
-  {
-    sum_diff = sum_diff_16x1(acc_diff);
-    sum_diff_thresh = total_adj_strong_thresh(bs, increase_denoising);
-    if (abs(sum_diff) > sum_diff_thresh) {
-      // Before returning to copy the block (i.e., apply no denoising),
-      // check if we can still apply some (weaker) temporal filtering to
-      // this block, that would otherwise not be denoised at all. Simplest
-      // is to apply an additional adjustment to running_avg_y to bring it
-      // closer to sig. The adjustment is capped by a maximum delta, and
-      // chosen such that in most cases the resulting sum_diff will be
-      // within the acceptable range given by sum_diff_thresh.
-
-      // The delta is set by the excess of absolute pixel diff over the
-      // threshold.
-      const int delta = ((abs(sum_diff) - sum_diff_thresh) >>
-                         num_pels_log2_lookup[bs]) + 1;
-      // Only apply the adjustment for max delta up to 3.
-      if (delta < 4) {
-        const __m128i k_delta = _mm_set1_epi8(delta);
-        running_avg_y -= avg_y_stride * (b_height << 1);
-        for (r = 0; r < b_height; ++r) {
-          acc_diff = vp9_denoiser_adj_16x1_sse2(
-              sig_buffer[r], mc_running_buffer[r], running_buffer[r],
-              k_0, k_delta, acc_diff);
-          memcpy(running_avg_y, running_buffer[r], width);
-          memcpy(running_avg_y + avg_y_stride,
-                 running_buffer[r] + width, width);
-          // Update pointers for next iteration.
-          running_avg_y += (avg_y_stride << 1);
-        }
-        sum_diff = sum_diff_16x1(acc_diff);
-        if (abs(sum_diff) > sum_diff_thresh) {
-          return COPY_BLOCK;
-        }
-      } else {
-        return COPY_BLOCK;
-      }
-    }
-  }
-  return FILTER_BLOCK;
-}
-
-// Denoise 16x16, 16x32, 32x16, 32x32, 32x64, 64x32 and 64x64 blocks.
-static int vp9_denoiser_NxM_sse2_big(const uint8_t *sig, int sig_stride,
-                                     const uint8_t *mc_running_avg_y,
-                                     int mc_avg_y_stride,
-                                     uint8_t *running_avg_y,
-                                     int avg_y_stride,
-                                     int increase_denoising, BLOCK_SIZE bs,
-                                     int motion_magnitude) {
-  int sum_diff_thresh, r, c, sum_diff = 0;
-  const int shift_inc  = (increase_denoising &&
-                          motion_magnitude <= MOTION_MAGNITUDE_THRESHOLD) ?
-                         1 : 0;
-  __m128i acc_diff[4][4];
-  const __m128i k_0 = _mm_setzero_si128();
-  const __m128i k_4 = _mm_set1_epi8(4 + shift_inc);
-  const __m128i k_8 = _mm_set1_epi8(8);
-  const __m128i k_16 = _mm_set1_epi8(16);
-  // Modify each level's adjustment according to motion_magnitude.
-  const __m128i l3 = _mm_set1_epi8(
-      (motion_magnitude <= MOTION_MAGNITUDE_THRESHOLD) ? 7 + shift_inc : 6);
-  // Difference between level 3 and level 2 is 2.
-  const __m128i l32 = _mm_set1_epi8(2);
-  // Difference between level 2 and level 1 is 1.
-  const __m128i l21 = _mm_set1_epi8(1);
-  const int b_width = (4 << b_width_log2_lookup[bs]);
-  const int b_height = (4 << b_height_log2_lookup[bs]);
-  const int b_width_shift4 = b_width >> 4;
-
-  for (r = 0; r < 4; ++r) {
-    for (c = 0; c < b_width_shift4; ++c) {
-      acc_diff[c][r] = _mm_setzero_si128();
-    }
-  }
-
-  for (r = 0; r < b_height; ++r) {
-    for (c = 0; c < b_width_shift4; ++c) {
-      acc_diff[c][r>>4] = vp9_denoiser_16x1_sse2(
-          sig, mc_running_avg_y, running_avg_y, &k_0, &k_4,
-          &k_8, &k_16, &l3, &l32, &l21, acc_diff[c][r>>4]);
-      // Update pointers for next iteration.
-      sig += 16;
-      mc_running_avg_y += 16;
-      running_avg_y += 16;
-    }
-
-    if ((r & 0xf) == 0xf || (bs == BLOCK_16X8 && r == 7)) {
-      for (c = 0; c < b_width_shift4; ++c) {
-        sum_diff += sum_diff_16x1(acc_diff[c][r>>4]);
-      }
-    }
-
-    // Update pointers for next iteration.
-    sig = sig - b_width + sig_stride;
-    mc_running_avg_y = mc_running_avg_y - b_width + mc_avg_y_stride;
-    running_avg_y = running_avg_y - b_width + avg_y_stride;
-  }
-
-  {
-    sum_diff_thresh = total_adj_strong_thresh(bs, increase_denoising);
-    if (abs(sum_diff) > sum_diff_thresh) {
-      const int delta = ((abs(sum_diff) - sum_diff_thresh) >>
-                         num_pels_log2_lookup[bs]) + 1;
-
-      // Only apply the adjustment for max delta up to 3.
-      if (delta < 4) {
-        const __m128i k_delta = _mm_set1_epi8(delta);
-        sig -= sig_stride * b_height;
-        mc_running_avg_y -= mc_avg_y_stride * b_height;
-        running_avg_y -= avg_y_stride * b_height;
-        sum_diff = 0;
-        for (r = 0; r < b_height; ++r) {
-          for (c = 0; c < b_width_shift4; ++c) {
-            acc_diff[c][r>>4] = vp9_denoiser_adj_16x1_sse2(
-                sig, mc_running_avg_y, running_avg_y, k_0,
-                k_delta, acc_diff[c][r>>4]);
-            // Update pointers for next iteration.
-            sig += 16;
-            mc_running_avg_y += 16;
-            running_avg_y += 16;
-          }
-
-          if ((r & 0xf) == 0xf || (bs == BLOCK_16X8 && r == 7)) {
-            for (c = 0; c < b_width_shift4; ++c) {
-              sum_diff += sum_diff_16x1(acc_diff[c][r>>4]);
-            }
-          }
-          sig = sig - b_width + sig_stride;
-          mc_running_avg_y = mc_running_avg_y - b_width + mc_avg_y_stride;
-          running_avg_y = running_avg_y - b_width + avg_y_stride;
-        }
-        if (abs(sum_diff) > sum_diff_thresh) {
-          return COPY_BLOCK;
-        }
-      } else {
-        return COPY_BLOCK;
-      }
-    }
-  }
-  return FILTER_BLOCK;
-}
-
-int vp9_denoiser_filter_sse2(const uint8_t *sig, int sig_stride,
-                             const uint8_t *mc_avg,
-                             int mc_avg_stride,
-                             uint8_t *avg, int avg_stride,
-                             int increase_denoising,
-                             BLOCK_SIZE bs,
-                             int motion_magnitude) {
-  // Rank by frequency of the block type to have an early termination.
-  if (bs == BLOCK_16X16 || bs == BLOCK_32X32 || bs == BLOCK_64X64 ||
-      bs == BLOCK_16X32 || bs == BLOCK_16X8 || bs == BLOCK_32X16 ||
-      bs == BLOCK_32X64 || bs == BLOCK_64X32) {
-    return vp9_denoiser_NxM_sse2_big(sig, sig_stride,
-                                     mc_avg, mc_avg_stride,
-                                     avg, avg_stride,
-                                     increase_denoising,
-                                     bs, motion_magnitude);
-  } else if (bs == BLOCK_8X8 || bs == BLOCK_8X16) {
-    return vp9_denoiser_NxM_sse2_small(sig, sig_stride,
-                                       mc_avg, mc_avg_stride,
-                                       avg, avg_stride,
-                                       increase_denoising,
-                                       bs, motion_magnitude, 8);
-  } else {
-    return COPY_BLOCK;
-  }
-}
diff --git a/vp9/encoder/x86/vp9_diamond_search_sad_avx.c b/vp9/encoder/x86/vp9_diamond_search_sad_avx.c
deleted file mode 100644 (file)
index cd3e87e..0000000
+++ /dev/null
@@ -1,314 +0,0 @@
-/*
- *  Copyright (c) 2015 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.
- */
-
-#if defined(_MSC_VER)
-# include <intrin.h>
-#endif
-#include <emmintrin.h>
-#include <smmintrin.h>
-
-#include "vpx_dsp/vpx_dsp_common.h"
-#include "vp9/encoder/vp9_encoder.h"
-#include "vpx_ports/mem.h"
-
-#ifdef __GNUC__
-# define LIKELY(v)    __builtin_expect(v, 1)
-# define UNLIKELY(v)  __builtin_expect(v, 0)
-#else
-# define LIKELY(v)    (v)
-# define UNLIKELY(v)  (v)
-#endif
-
-static INLINE int_mv pack_int_mv(int16_t row, int16_t col) {
-  int_mv result;
-  result.as_mv.row = row;
-  result.as_mv.col = col;
-  return result;
-}
-
-static INLINE MV_JOINT_TYPE get_mv_joint(const int_mv mv) {
-  // This is simplified from the C implementation to utilise that
-  //  x->nmvjointsadcost[1] == x->nmvjointsadcost[2]  and
-  //  x->nmvjointsadcost[1] == x->nmvjointsadcost[3]
-  return mv.as_int == 0 ? 0 : 1;
-}
-
-static INLINE int mv_cost(const int_mv mv,
-                          const int *joint_cost, int *const comp_cost[2]) {
-  return joint_cost[get_mv_joint(mv)] +
-         comp_cost[0][mv.as_mv.row] + comp_cost[1][mv.as_mv.col];
-}
-
-static int mvsad_err_cost(const MACROBLOCK *x, const int_mv mv, const MV *ref,
-                          int sad_per_bit) {
-  const int_mv diff = pack_int_mv(mv.as_mv.row - ref->row,
-                                  mv.as_mv.col - ref->col);
-  return ROUND_POWER_OF_TWO((unsigned)mv_cost(diff, x->nmvjointsadcost,
-                                              x->nmvsadcost) *
-                                              sad_per_bit, VP9_PROB_COST_SHIFT);
-}
-
-/*****************************************************************************
- * This function utilizes 3 properties of the cost function lookup tables,   *
- * constructed in using 'cal_nmvjointsadcost' and 'cal_nmvsadcosts' in       *
- * vp9_encoder.c.                                                            *
- * For the joint cost:                                                       *
- *   - mvjointsadcost[1] == mvjointsadcost[2] == mvjointsadcost[3]           *
- * For the component costs:                                                  *
- *   - For all i: mvsadcost[0][i] == mvsadcost[1][i]                         *
- *         (Equal costs for both components)                                 *
- *   - For all i: mvsadcost[0][i] == mvsadcost[0][-i]                        *
- *         (Cost function is even)                                           *
- * If these do not hold, then this function cannot be used without           *
- * modification, in which case you can revert to using the C implementation, *
- * which does not rely on these properties.                                  *
- *****************************************************************************/
-int vp9_diamond_search_sad_avx(const MACROBLOCK *x,
-                               const search_site_config *cfg,
-                               MV *ref_mv, MV *best_mv, int search_param,
-                               int sad_per_bit, int *num00,
-                               const vp9_variance_fn_ptr_t *fn_ptr,
-                               const MV *center_mv) {
-  const int_mv maxmv = pack_int_mv(x->mv_row_max, x->mv_col_max);
-  const __m128i v_max_mv_w = _mm_set1_epi32(maxmv.as_int);
-  const int_mv minmv = pack_int_mv(x->mv_row_min, x->mv_col_min);
-  const __m128i v_min_mv_w = _mm_set1_epi32(minmv.as_int);
-
-  const __m128i v_spb_d = _mm_set1_epi32(sad_per_bit);
-
-  const __m128i v_joint_cost_0_d = _mm_set1_epi32(x->nmvjointsadcost[0]);
-  const __m128i v_joint_cost_1_d = _mm_set1_epi32(x->nmvjointsadcost[1]);
-
-  // search_param determines the length of the initial step and hence the number
-  // of iterations.
-  // 0 = initial step (MAX_FIRST_STEP) pel
-  // 1 = (MAX_FIRST_STEP/2) pel,
-  // 2 = (MAX_FIRST_STEP/4) pel...
-  const       MV *ss_mv = &cfg->ss_mv[cfg->searches_per_step * search_param];
-  const intptr_t *ss_os = &cfg->ss_os[cfg->searches_per_step * search_param];
-  const int tot_steps = cfg->total_steps - search_param;
-
-  const int_mv fcenter_mv = pack_int_mv(center_mv->row >> 3,
-                                        center_mv->col >> 3);
-  const __m128i vfcmv = _mm_set1_epi32(fcenter_mv.as_int);
-
-  const int ref_row = clamp(ref_mv->row, minmv.as_mv.row, maxmv.as_mv.row);
-  const int ref_col = clamp(ref_mv->col, minmv.as_mv.col, maxmv.as_mv.col);
-
-  int_mv bmv = pack_int_mv(ref_row, ref_col);
-  int_mv new_bmv = bmv;
-  __m128i v_bmv_w = _mm_set1_epi32(bmv.as_int);
-
-  const int what_stride = x->plane[0].src.stride;
-  const int in_what_stride = x->e_mbd.plane[0].pre[0].stride;
-  const uint8_t *const what = x->plane[0].src.buf;
-  const uint8_t *const in_what = x->e_mbd.plane[0].pre[0].buf +
-                                 ref_row * in_what_stride + ref_col;
-
-  // Work out the start point for the search
-  const uint8_t *best_address = in_what;
-  const uint8_t *new_best_address = best_address;
-#if ARCH_X86_64
-  __m128i v_ba_q = _mm_set1_epi64x((intptr_t)best_address);
-#else
-  __m128i v_ba_d = _mm_set1_epi32((intptr_t)best_address);
-#endif
-
-  unsigned int best_sad;
-  int i, j, step;
-
-  // Check the prerequisite cost function properties that are easy to check
-  // in an assert. See the function-level documentation for details on all
-  // prerequisites.
-  assert(x->nmvjointsadcost[1] == x->nmvjointsadcost[2]);
-  assert(x->nmvjointsadcost[1] == x->nmvjointsadcost[3]);
-
-  // Check the starting position
-  best_sad = fn_ptr->sdf(what, what_stride, in_what, in_what_stride);
-  best_sad += mvsad_err_cost(x, bmv, &fcenter_mv.as_mv, sad_per_bit);
-
-  *num00 = 0;
-
-  for (i = 0, step = 0; step < tot_steps; step++) {
-    for (j = 0; j < cfg->searches_per_step; j += 4, i += 4) {
-      __m128i v_sad_d, v_cost_d, v_outside_d, v_inside_d, v_diff_mv_w;
-#if ARCH_X86_64
-      __m128i v_blocka[2];
-#else
-      __m128i v_blocka[1];
-#endif
-
-      // Compute the candidate motion vectors
-      const __m128i v_ss_mv_w = _mm_loadu_si128((const __m128i *)&ss_mv[i]);
-      const __m128i v_these_mv_w = _mm_add_epi16(v_bmv_w, v_ss_mv_w);
-      // Clamp them to the search bounds
-      __m128i v_these_mv_clamp_w = v_these_mv_w;
-      v_these_mv_clamp_w = _mm_min_epi16(v_these_mv_clamp_w, v_max_mv_w);
-      v_these_mv_clamp_w = _mm_max_epi16(v_these_mv_clamp_w, v_min_mv_w);
-      // The ones that did not change are inside the search area
-      v_inside_d = _mm_cmpeq_epi32(v_these_mv_clamp_w, v_these_mv_w);
-
-      // If none of them are inside, then move on
-      if (LIKELY(_mm_test_all_zeros(v_inside_d, v_inside_d))) {
-        continue;
-      }
-
-      // The inverse mask indicates which of the MVs are outside
-      v_outside_d = _mm_xor_si128(v_inside_d, _mm_set1_epi8(0xff));
-      // Shift right to keep the sign bit clear, we will use this later
-      // to set the cost to the maximum value.
-      v_outside_d = _mm_srli_epi32(v_outside_d, 1);
-
-      // Compute the difference MV
-      v_diff_mv_w = _mm_sub_epi16(v_these_mv_clamp_w, vfcmv);
-      // We utilise the fact that the cost function is even, and use the
-      // absolute difference. This allows us to use unsigned indexes later
-      // and reduces cache pressure somewhat as only a half of the table
-      // is ever referenced.
-      v_diff_mv_w = _mm_abs_epi16(v_diff_mv_w);
-
-      // Compute the SIMD pointer offsets.
-      {
-#if ARCH_X86_64  //  sizeof(intptr_t) == 8
-        // Load the offsets
-        __m128i v_bo10_q = _mm_loadu_si128((const __m128i *)&ss_os[i + 0]);
-        __m128i v_bo32_q = _mm_loadu_si128((const __m128i *)&ss_os[i + 2]);
-        // Set the ones falling outside to zero
-        v_bo10_q = _mm_and_si128(v_bo10_q,
-                                 _mm_cvtepi32_epi64(v_inside_d));
-        v_bo32_q = _mm_and_si128(v_bo32_q,
-                                 _mm_unpackhi_epi32(v_inside_d, v_inside_d));
-        // Compute the candidate addresses
-        v_blocka[0] = _mm_add_epi64(v_ba_q, v_bo10_q);
-        v_blocka[1] = _mm_add_epi64(v_ba_q, v_bo32_q);
-#else  // ARCH_X86 //  sizeof(intptr_t) == 4
-        __m128i v_bo_d = _mm_loadu_si128((const __m128i *)&ss_os[i]);
-        v_bo_d = _mm_and_si128(v_bo_d, v_inside_d);
-        v_blocka[0] = _mm_add_epi32(v_ba_d, v_bo_d);
-#endif
-      }
-
-      fn_ptr->sdx4df(what, what_stride,
-                     (const uint8_t **)&v_blocka[0], in_what_stride,
-                     (uint32_t*)&v_sad_d);
-
-      // Look up the component cost of the residual motion vector
-      {
-        const int32_t row0 = _mm_extract_epi16(v_diff_mv_w, 0);
-        const int32_t col0 = _mm_extract_epi16(v_diff_mv_w, 1);
-        const int32_t row1 = _mm_extract_epi16(v_diff_mv_w, 2);
-        const int32_t col1 = _mm_extract_epi16(v_diff_mv_w, 3);
-        const int32_t row2 = _mm_extract_epi16(v_diff_mv_w, 4);
-        const int32_t col2 = _mm_extract_epi16(v_diff_mv_w, 5);
-        const int32_t row3 = _mm_extract_epi16(v_diff_mv_w, 6);
-        const int32_t col3 = _mm_extract_epi16(v_diff_mv_w, 7);
-
-        // Note: This is a use case for vpgather in AVX2
-        const uint32_t cost0 = x->nmvsadcost[0][row0] + x->nmvsadcost[0][col0];
-        const uint32_t cost1 = x->nmvsadcost[0][row1] + x->nmvsadcost[0][col1];
-        const uint32_t cost2 = x->nmvsadcost[0][row2] + x->nmvsadcost[0][col2];
-        const uint32_t cost3 = x->nmvsadcost[0][row3] + x->nmvsadcost[0][col3];
-
-        __m128i v_cost_10_d, v_cost_32_d;
-        v_cost_10_d = _mm_cvtsi32_si128(cost0);
-        v_cost_10_d = _mm_insert_epi32(v_cost_10_d, cost1, 1);
-        v_cost_32_d = _mm_cvtsi32_si128(cost2);
-        v_cost_32_d = _mm_insert_epi32(v_cost_32_d, cost3, 1);
-        v_cost_d = _mm_unpacklo_epi64(v_cost_10_d, v_cost_32_d);
-      }
-
-      // Now add in the joint cost
-      {
-        const __m128i v_sel_d = _mm_cmpeq_epi32(v_diff_mv_w,
-                                                _mm_setzero_si128());
-        const __m128i v_joint_cost_d = _mm_blendv_epi8(v_joint_cost_1_d,
-                                                       v_joint_cost_0_d,
-                                                       v_sel_d);
-        v_cost_d = _mm_add_epi32(v_cost_d, v_joint_cost_d);
-      }
-
-      // Multiply by sad_per_bit
-      v_cost_d = _mm_mullo_epi32(v_cost_d, v_spb_d);
-      // ROUND_POWER_OF_TWO(v_cost_d, VP9_PROB_COST_SHIFT)
-      v_cost_d = _mm_add_epi32(v_cost_d,
-                               _mm_set1_epi32(1 << (VP9_PROB_COST_SHIFT - 1)));
-      v_cost_d = _mm_srai_epi32(v_cost_d, VP9_PROB_COST_SHIFT);
-      // Add the cost to the sad
-      v_sad_d = _mm_add_epi32(v_sad_d, v_cost_d);
-
-      // Make the motion vectors outside the search area have max cost
-      // by or'ing in the comparison mask, this way the minimum search won't
-      // pick them.
-      v_sad_d = _mm_or_si128(v_sad_d, v_outside_d);
-
-      // Find the minimum value and index horizontally in v_sad_d
-      {
-        // Try speculatively on 16 bits, so we can use the minpos intrinsic
-        const __m128i v_sad_w = _mm_packus_epi32(v_sad_d, v_sad_d);
-        const __m128i v_minp_w = _mm_minpos_epu16(v_sad_w);
-
-        uint32_t local_best_sad = _mm_extract_epi16(v_minp_w, 0);
-        uint32_t local_best_idx = _mm_extract_epi16(v_minp_w, 1);
-
-        // If the local best value is not saturated, just use it, otherwise
-        // find the horizontal minimum again the hard way on 32 bits.
-        // This is executed rarely.
-        if (UNLIKELY(local_best_sad == 0xffff)) {
-          __m128i v_loval_d, v_hival_d, v_loidx_d, v_hiidx_d, v_sel_d;
-
-          v_loval_d = v_sad_d;
-          v_loidx_d = _mm_set_epi32(3, 2, 1, 0);
-          v_hival_d = _mm_srli_si128(v_loval_d, 8);
-          v_hiidx_d = _mm_srli_si128(v_loidx_d, 8);
-
-          v_sel_d = _mm_cmplt_epi32(v_hival_d, v_loval_d);
-
-          v_loval_d = _mm_blendv_epi8(v_loval_d, v_hival_d, v_sel_d);
-          v_loidx_d = _mm_blendv_epi8(v_loidx_d, v_hiidx_d, v_sel_d);
-          v_hival_d = _mm_srli_si128(v_loval_d, 4);
-          v_hiidx_d = _mm_srli_si128(v_loidx_d, 4);
-
-          v_sel_d = _mm_cmplt_epi32(v_hival_d, v_loval_d);
-
-          v_loval_d = _mm_blendv_epi8(v_loval_d, v_hival_d, v_sel_d);
-          v_loidx_d = _mm_blendv_epi8(v_loidx_d, v_hiidx_d, v_sel_d);
-
-          local_best_sad = _mm_extract_epi32(v_loval_d, 0);
-          local_best_idx = _mm_extract_epi32(v_loidx_d, 0);
-        }
-
-        // Update the global minimum if the local minimum is smaller
-        if (LIKELY(local_best_sad < best_sad)) {
-          new_bmv = ((const int_mv *)&v_these_mv_w)[local_best_idx];
-          new_best_address = ((const uint8_t **)v_blocka)[local_best_idx];
-
-          best_sad = local_best_sad;
-        }
-      }
-    }
-
-    bmv = new_bmv;
-    best_address = new_best_address;
-
-    v_bmv_w = _mm_set1_epi32(bmv.as_int);
-#if ARCH_X86_64
-    v_ba_q = _mm_set1_epi64x((intptr_t)best_address);
-#else
-    v_ba_d = _mm_set1_epi32((intptr_t)best_address);
-#endif
-
-    if (UNLIKELY(best_address == in_what)) {
-      (*num00)++;
-    }
-  }
-
-  *best_mv = bmv.as_mv;
-  return best_sad;
-}
diff --git a/vp9/encoder/x86/vp9_error_intrin_avx2.c b/vp9/encoder/x86/vp9_error_intrin_avx2.c
deleted file mode 100644 (file)
index dfebaab..0000000
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- *  Copyright (c) 2014 The WebM project authors. All Rights Reserved.
- *
- *  Usee 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.
- */
-
-#include <immintrin.h>  // AVX2
-
-#include "./vp9_rtcd.h"
-#include "vpx/vpx_integer.h"
-
-int64_t vp9_block_error_avx2(const int16_t *coeff,
-                             const int16_t *dqcoeff,
-                             intptr_t block_size,
-                             int64_t *ssz) {
-  __m256i sse_reg, ssz_reg, coeff_reg, dqcoeff_reg;
-  __m256i exp_dqcoeff_lo, exp_dqcoeff_hi, exp_coeff_lo, exp_coeff_hi;
-  __m256i sse_reg_64hi, ssz_reg_64hi;
-  __m128i sse_reg128, ssz_reg128;
-  int64_t sse;
-  int i;
-  const __m256i zero_reg = _mm256_set1_epi16(0);
-
-  // init sse and ssz registerd to zero
-  sse_reg = _mm256_set1_epi16(0);
-  ssz_reg = _mm256_set1_epi16(0);
-
-  for (i = 0 ; i < block_size ; i+= 16) {
-    // load 32 bytes from coeff and dqcoeff
-    coeff_reg = _mm256_loadu_si256((const __m256i *)(coeff + i));
-    dqcoeff_reg = _mm256_loadu_si256((const __m256i *)(dqcoeff + i));
-    // dqcoeff - coeff
-    dqcoeff_reg = _mm256_sub_epi16(dqcoeff_reg, coeff_reg);
-    // madd (dqcoeff - coeff)
-    dqcoeff_reg = _mm256_madd_epi16(dqcoeff_reg, dqcoeff_reg);
-    // madd coeff
-    coeff_reg = _mm256_madd_epi16(coeff_reg, coeff_reg);
-    // expand each double word of madd (dqcoeff - coeff) to quad word
-    exp_dqcoeff_lo = _mm256_unpacklo_epi32(dqcoeff_reg, zero_reg);
-    exp_dqcoeff_hi = _mm256_unpackhi_epi32(dqcoeff_reg, zero_reg);
-    // expand each double word of madd (coeff) to quad word
-    exp_coeff_lo = _mm256_unpacklo_epi32(coeff_reg, zero_reg);
-    exp_coeff_hi = _mm256_unpackhi_epi32(coeff_reg, zero_reg);
-    // add each quad word of madd (dqcoeff - coeff) and madd (coeff)
-    sse_reg = _mm256_add_epi64(sse_reg, exp_dqcoeff_lo);
-    ssz_reg = _mm256_add_epi64(ssz_reg, exp_coeff_lo);
-    sse_reg = _mm256_add_epi64(sse_reg, exp_dqcoeff_hi);
-    ssz_reg = _mm256_add_epi64(ssz_reg, exp_coeff_hi);
-  }
-  // save the higher 64 bit of each 128 bit lane
-  sse_reg_64hi = _mm256_srli_si256(sse_reg, 8);
-  ssz_reg_64hi = _mm256_srli_si256(ssz_reg, 8);
-  // add the higher 64 bit to the low 64 bit
-  sse_reg = _mm256_add_epi64(sse_reg, sse_reg_64hi);
-  ssz_reg = _mm256_add_epi64(ssz_reg, ssz_reg_64hi);
-
-  // add each 64 bit from each of the 128 bit lane of the 256 bit
-  sse_reg128 = _mm_add_epi64(_mm256_castsi256_si128(sse_reg),
-                             _mm256_extractf128_si256(sse_reg, 1));
-
-  ssz_reg128 = _mm_add_epi64(_mm256_castsi256_si128(ssz_reg),
-                             _mm256_extractf128_si256(ssz_reg, 1));
-
-  // store the results
-  _mm_storel_epi64((__m128i*)(&sse), sse_reg128);
-
-  _mm_storel_epi64((__m128i*)(ssz), ssz_reg128);
-  return sse;
-}
diff --git a/vp9/encoder/x86/vp9_error_sse2.asm b/vp9/encoder/x86/vp9_error_sse2.asm
deleted file mode 100644 (file)
index 5b02382..0000000
+++ /dev/null
@@ -1,122 +0,0 @@
-;
-;  Copyright (c) 2010 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.
-;
-
-%define private_prefix vp9
-
-%include "third_party/x86inc/x86inc.asm"
-
-SECTION .text
-
-; int64_t vp9_block_error(int16_t *coeff, int16_t *dqcoeff, intptr_t block_size,
-;                         int64_t *ssz)
-
-INIT_XMM sse2
-cglobal block_error, 3, 3, 8, uqc, dqc, size, ssz
-  pxor      m4, m4                 ; sse accumulator
-  pxor      m6, m6                 ; ssz accumulator
-  pxor      m5, m5                 ; dedicated zero register
-  lea     uqcq, [uqcq+sizeq*2]
-  lea     dqcq, [dqcq+sizeq*2]
-  neg    sizeq
-.loop:
-  mova      m2, [uqcq+sizeq*2]
-  mova      m0, [dqcq+sizeq*2]
-  mova      m3, [uqcq+sizeq*2+mmsize]
-  mova      m1, [dqcq+sizeq*2+mmsize]
-  psubw     m0, m2
-  psubw     m1, m3
-  ; individual errors are max. 15bit+sign, so squares are 30bit, and
-  ; thus the sum of 2 should fit in a 31bit integer (+ unused sign bit)
-  pmaddwd   m0, m0
-  pmaddwd   m1, m1
-  pmaddwd   m2, m2
-  pmaddwd   m3, m3
-  ; accumulate in 64bit
-  punpckldq m7, m0, m5
-  punpckhdq m0, m5
-  paddq     m4, m7
-  punpckldq m7, m1, m5
-  paddq     m4, m0
-  punpckhdq m1, m5
-  paddq     m4, m7
-  punpckldq m7, m2, m5
-  paddq     m4, m1
-  punpckhdq m2, m5
-  paddq     m6, m7
-  punpckldq m7, m3, m5
-  paddq     m6, m2
-  punpckhdq m3, m5
-  paddq     m6, m7
-  paddq     m6, m3
-  add    sizeq, mmsize
-  jl .loop
-
-  ; accumulate horizontally and store in return value
-  movhlps   m5, m4
-  movhlps   m7, m6
-  paddq     m4, m5
-  paddq     m6, m7
-%if ARCH_X86_64
-  movq    rax, m4
-  movq [sszq], m6
-%else
-  mov     eax, sszm
-  pshufd   m5, m4, 0x1
-  movq  [eax], m6
-  movd    eax, m4
-  movd    edx, m5
-%endif
-  RET
-
-; Compute the sum of squared difference between two int16_t vectors.
-; int64_t vp9_block_error_fp(int16_t *coeff, int16_t *dqcoeff,
-;                            intptr_t block_size)
-
-INIT_XMM sse2
-cglobal block_error_fp, 3, 3, 6, uqc, dqc, size
-  pxor      m4, m4                 ; sse accumulator
-  pxor      m5, m5                 ; dedicated zero register
-  lea     uqcq, [uqcq+sizeq*2]
-  lea     dqcq, [dqcq+sizeq*2]
-  neg    sizeq
-.loop:
-  mova      m2, [uqcq+sizeq*2]
-  mova      m0, [dqcq+sizeq*2]
-  mova      m3, [uqcq+sizeq*2+mmsize]
-  mova      m1, [dqcq+sizeq*2+mmsize]
-  psubw     m0, m2
-  psubw     m1, m3
-  ; individual errors are max. 15bit+sign, so squares are 30bit, and
-  ; thus the sum of 2 should fit in a 31bit integer (+ unused sign bit)
-  pmaddwd   m0, m0
-  pmaddwd   m1, m1
-  ; accumulate in 64bit
-  punpckldq m3, m0, m5
-  punpckhdq m0, m5
-  paddq     m4, m3
-  punpckldq m3, m1, m5
-  paddq     m4, m0
-  punpckhdq m1, m5
-  paddq     m4, m3
-  paddq     m4, m1
-  add    sizeq, mmsize
-  jl .loop
-
-  ; accumulate horizontally and store in return value
-  movhlps   m5, m4
-  paddq     m4, m5
-%if ARCH_X86_64
-  movq    rax, m4
-%else
-  pshufd   m5, m4, 0x1
-  movd    eax, m4
-  movd    edx, m5
-%endif
-  RET
diff --git a/vp9/encoder/x86/vp9_frame_scale_ssse3.c b/vp9/encoder/x86/vp9_frame_scale_ssse3.c
deleted file mode 100644 (file)
index 23325d6..0000000
+++ /dev/null
@@ -1,206 +0,0 @@
-/*
- *  Copyright (c) 2016 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.
- */
-
-#include <tmmintrin.h>  // SSSE3
-
-#include "./vp9_rtcd.h"
-#include "./vpx_dsp_rtcd.h"
-#include "./vpx_scale_rtcd.h"
-#include "vpx_scale/yv12config.h"
-
-extern void vp9_scale_and_extend_frame_c(const YV12_BUFFER_CONFIG *src,
-                                         YV12_BUFFER_CONFIG *dst);
-
-static void downsample_2_to_1_ssse3(const uint8_t *src, ptrdiff_t src_stride,
-                                    uint8_t *dst, ptrdiff_t dst_stride,
-                                    int w, int h) {
-  const __m128i mask = _mm_set1_epi16(0x00FF);
-  const int max_width = w & ~15;
-  int y;
-  for (y = 0; y < h; ++y) {
-    int x;
-    for (x = 0; x < max_width; x += 16) {
-      const __m128i a = _mm_loadu_si128((const __m128i *)(src + x * 2 +  0));
-      const __m128i b = _mm_loadu_si128((const __m128i *)(src + x * 2 + 16));
-      const __m128i a_and = _mm_and_si128(a, mask);
-      const __m128i b_and = _mm_and_si128(b, mask);
-      const __m128i c = _mm_packus_epi16(a_and, b_and);
-      _mm_storeu_si128((__m128i *)(dst + x), c);
-    }
-    for (; x < w; ++x)
-      dst[x] = src[x * 2];
-    src += src_stride * 2;
-    dst += dst_stride;
-  }
-}
-
-static INLINE __m128i filter(const __m128i *const a, const __m128i *const b,
-                             const __m128i *const c, const __m128i *const d,
-                             const __m128i *const e, const __m128i *const f,
-                             const __m128i *const g, const __m128i *const h) {
-  const __m128i coeffs_ab =
-      _mm_set_epi8(6, -1, 6, -1, 6, -1, 6, -1, 6, -1, 6, -1, 6, -1, 6, -1);
-  const __m128i coeffs_cd =
-      _mm_set_epi8(78, -19, 78, -19, 78, -19, 78, -19, 78, -19, 78, -19,
-                   78, -19, 78, -19);
-  const __m128i const64_x16 = _mm_set1_epi16(64);
-  const __m128i ab = _mm_unpacklo_epi8(*a, *b);
-  const __m128i cd = _mm_unpacklo_epi8(*c, *d);
-  const __m128i fe = _mm_unpacklo_epi8(*f, *e);
-  const __m128i hg = _mm_unpacklo_epi8(*h, *g);
-  const __m128i ab_terms = _mm_maddubs_epi16(ab, coeffs_ab);
-  const __m128i cd_terms = _mm_maddubs_epi16(cd, coeffs_cd);
-  const __m128i fe_terms = _mm_maddubs_epi16(fe, coeffs_cd);
-  const __m128i hg_terms = _mm_maddubs_epi16(hg, coeffs_ab);
-  // can not overflow
-  const __m128i abcd_terms = _mm_add_epi16(ab_terms, cd_terms);
-  // can not overflow
-  const __m128i fehg_terms = _mm_add_epi16(fe_terms, hg_terms);
-  // can overflow, use saturating add
-  const __m128i terms = _mm_adds_epi16(abcd_terms, fehg_terms);
-  const __m128i round = _mm_adds_epi16(terms, const64_x16);
-  const __m128i shift = _mm_srai_epi16(round, 7);
-  return _mm_packus_epi16(shift, shift);
-}
-
-static void eight_tap_row_ssse3(const uint8_t *src, uint8_t *dst, int w) {
-  const int max_width = w & ~7;
-  int x = 0;
-  for (; x < max_width; x += 8) {
-    const __m128i a = _mm_loadl_epi64((const __m128i *)(src + x + 0));
-    const __m128i b = _mm_loadl_epi64((const __m128i *)(src + x + 1));
-    const __m128i c = _mm_loadl_epi64((const __m128i *)(src + x + 2));
-    const __m128i d = _mm_loadl_epi64((const __m128i *)(src + x + 3));
-    const __m128i e = _mm_loadl_epi64((const __m128i *)(src + x + 4));
-    const __m128i f = _mm_loadl_epi64((const __m128i *)(src + x + 5));
-    const __m128i g = _mm_loadl_epi64((const __m128i *)(src + x + 6));
-    const __m128i h = _mm_loadl_epi64((const __m128i *)(src + x + 7));
-    const __m128i pack = filter(&a, &b, &c, &d, &e, &f, &g, &h);
-    _mm_storel_epi64((__m128i *)(dst + x), pack);
-  }
-}
-
-static void upsample_1_to_2_ssse3(const uint8_t *src, ptrdiff_t src_stride,
-                                  uint8_t *dst, ptrdiff_t dst_stride,
-                                  int dst_w, int dst_h) {
-  dst_w /= 2;
-  dst_h /= 2;
-  {
-    DECLARE_ALIGNED(16, uint8_t, tmp[1920 * 8]);
-    uint8_t *tmp0 = tmp + dst_w * 0;
-    uint8_t *tmp1 = tmp + dst_w * 1;
-    uint8_t *tmp2 = tmp + dst_w * 2;
-    uint8_t *tmp3 = tmp + dst_w * 3;
-    uint8_t *tmp4 = tmp + dst_w * 4;
-    uint8_t *tmp5 = tmp + dst_w * 5;
-    uint8_t *tmp6 = tmp + dst_w * 6;
-    uint8_t *tmp7 = tmp + dst_w * 7;
-    uint8_t *tmp8 = NULL;
-    const int max_width = dst_w & ~7;
-    int y;
-    eight_tap_row_ssse3(src - src_stride * 3 - 3, tmp0, dst_w);
-    eight_tap_row_ssse3(src - src_stride * 2 - 3, tmp1, dst_w);
-    eight_tap_row_ssse3(src - src_stride * 1 - 3, tmp2, dst_w);
-    eight_tap_row_ssse3(src + src_stride * 0 - 3, tmp3, dst_w);
-    eight_tap_row_ssse3(src + src_stride * 1 - 3, tmp4, dst_w);
-    eight_tap_row_ssse3(src + src_stride * 2 - 3, tmp5, dst_w);
-    eight_tap_row_ssse3(src + src_stride * 3 - 3, tmp6, dst_w);
-    for (y = 0; y < dst_h; y++) {
-      int x;
-      eight_tap_row_ssse3(src + src_stride * 4 - 3, tmp7, dst_w);
-      for (x = 0; x < max_width; x += 8) {
-        const __m128i A = _mm_loadl_epi64((const __m128i *)(src  + x));
-        const __m128i B = _mm_loadl_epi64((const __m128i *)(tmp3 + x));
-        const __m128i AB = _mm_unpacklo_epi8(A, B);
-        __m128i C, D, CD;
-        _mm_storeu_si128((__m128i *)(dst + x * 2), AB);
-        {
-          const __m128i a =
-              _mm_loadl_epi64((const __m128i *)(src + x - src_stride * 3));
-          const __m128i b =
-              _mm_loadl_epi64((const __m128i *)(src + x - src_stride * 2));
-          const __m128i c =
-              _mm_loadl_epi64((const __m128i *)(src + x - src_stride * 1));
-          const __m128i d =
-              _mm_loadl_epi64((const __m128i *)(src + x + src_stride * 0));
-          const __m128i e =
-              _mm_loadl_epi64((const __m128i *)(src + x + src_stride * 1));
-          const __m128i f =
-              _mm_loadl_epi64((const __m128i *)(src + x + src_stride * 2));
-          const __m128i g =
-              _mm_loadl_epi64((const __m128i *)(src + x + src_stride * 3));
-          const __m128i h =
-              _mm_loadl_epi64((const __m128i *)(src + x + src_stride * 4));
-          C = filter(&a, &b, &c, &d, &e, &f, &g, &h);
-        }
-        {
-          const __m128i a = _mm_loadl_epi64((const __m128i *)(tmp0 + x));
-          const __m128i b = _mm_loadl_epi64((const __m128i *)(tmp1 + x));
-          const __m128i c = _mm_loadl_epi64((const __m128i *)(tmp2 + x));
-          const __m128i d = _mm_loadl_epi64((const __m128i *)(tmp3 + x));
-          const __m128i e = _mm_loadl_epi64((const __m128i *)(tmp4 + x));
-          const __m128i f = _mm_loadl_epi64((const __m128i *)(tmp5 + x));
-          const __m128i g = _mm_loadl_epi64((const __m128i *)(tmp6 + x));
-          const __m128i h = _mm_loadl_epi64((const __m128i *)(tmp7 + x));
-          D = filter(&a, &b, &c, &d, &e, &f, &g, &h);
-        }
-        CD = _mm_unpacklo_epi8(C, D);
-        _mm_storeu_si128((__m128i *)(dst + x * 2 + dst_stride), CD);
-      }
-      src += src_stride;
-      dst += dst_stride * 2;
-      tmp8 = tmp0;
-      tmp0 = tmp1;
-      tmp1 = tmp2;
-      tmp2 = tmp3;
-      tmp3 = tmp4;
-      tmp4 = tmp5;
-      tmp5 = tmp6;
-      tmp6 = tmp7;
-      tmp7 = tmp8;
-    }
-  }
-}
-
-void vp9_scale_and_extend_frame_ssse3(const YV12_BUFFER_CONFIG *src,
-                                      YV12_BUFFER_CONFIG *dst) {
-  const int src_w = src->y_crop_width;
-  const int src_h = src->y_crop_height;
-  const int dst_w = dst->y_crop_width;
-  const int dst_h = dst->y_crop_height;
-  const int dst_uv_w = dst_w / 2;
-  const int dst_uv_h = dst_h / 2;
-
-  if (dst_w * 2 == src_w && dst_h * 2 == src_h) {
-    downsample_2_to_1_ssse3(src->y_buffer, src->y_stride,
-                            dst->y_buffer, dst->y_stride, dst_w, dst_h);
-    downsample_2_to_1_ssse3(src->u_buffer, src->uv_stride,
-                            dst->u_buffer, dst->uv_stride, dst_uv_w, dst_uv_h);
-    downsample_2_to_1_ssse3(src->v_buffer, src->uv_stride,
-                            dst->v_buffer, dst->uv_stride, dst_uv_w, dst_uv_h);
-    vpx_extend_frame_borders(dst);
-  } else if (dst_w == src_w * 2 && dst_h == src_h * 2) {
-    // The upsample() supports widths up to 1920 * 2.  If greater, fall back
-    // to vp9_scale_and_extend_frame_c().
-    if (dst_w/2 <= 1920) {
-      upsample_1_to_2_ssse3(src->y_buffer, src->y_stride,
-                            dst->y_buffer, dst->y_stride, dst_w, dst_h);
-      upsample_1_to_2_ssse3(src->u_buffer, src->uv_stride,
-                            dst->u_buffer, dst->uv_stride, dst_uv_w, dst_uv_h);
-      upsample_1_to_2_ssse3(src->v_buffer, src->uv_stride,
-                            dst->v_buffer, dst->uv_stride, dst_uv_w, dst_uv_h);
-      vpx_extend_frame_borders(dst);
-    } else {
-      vp9_scale_and_extend_frame_c(src, dst);
-    }
-  } else {
-    vp9_scale_and_extend_frame_c(src, dst);
-  }
-}
diff --git a/vp9/encoder/x86/vp9_highbd_block_error_intrin_sse2.c b/vp9/encoder/x86/vp9_highbd_block_error_intrin_sse2.c
deleted file mode 100644 (file)
index c245cca..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- *  Copyright (c) 2014 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.
- */
-
-#include <emmintrin.h>
-#include <stdio.h>
-
-#include "vp9/common/vp9_common.h"
-
-int64_t vp9_highbd_block_error_sse2(tran_low_t *coeff, tran_low_t *dqcoeff,
-                                    intptr_t block_size, int64_t *ssz,
-                                    int bps) {
-  int i, j, test;
-  uint32_t temp[4];
-  __m128i max, min, cmp0, cmp1, cmp2, cmp3;
-  int64_t error = 0, sqcoeff = 0;
-  const int shift = 2 * (bps - 8);
-  const int rounding = shift > 0 ? 1 << (shift - 1) : 0;
-
-  for (i = 0; i < block_size; i+=8) {
-    // Load the data into xmm registers
-    __m128i mm_coeff = _mm_load_si128((__m128i*) (coeff + i));
-    __m128i mm_coeff2 = _mm_load_si128((__m128i*) (coeff + i + 4));
-    __m128i mm_dqcoeff = _mm_load_si128((__m128i*) (dqcoeff + i));
-    __m128i mm_dqcoeff2 = _mm_load_si128((__m128i*) (dqcoeff + i + 4));
-    // Check if any values require more than 15 bit
-    max = _mm_set1_epi32(0x3fff);
-    min = _mm_set1_epi32(0xffffc000);
-    cmp0 = _mm_xor_si128(_mm_cmpgt_epi32(mm_coeff, max),
-            _mm_cmplt_epi32(mm_coeff, min));
-    cmp1 = _mm_xor_si128(_mm_cmpgt_epi32(mm_coeff2, max),
-            _mm_cmplt_epi32(mm_coeff2, min));
-    cmp2 = _mm_xor_si128(_mm_cmpgt_epi32(mm_dqcoeff, max),
-            _mm_cmplt_epi32(mm_dqcoeff, min));
-    cmp3 = _mm_xor_si128(_mm_cmpgt_epi32(mm_dqcoeff2, max),
-            _mm_cmplt_epi32(mm_dqcoeff2, min));
-    test = _mm_movemask_epi8(_mm_or_si128(_mm_or_si128(cmp0, cmp1),
-            _mm_or_si128(cmp2, cmp3)));
-
-    if (!test) {
-      __m128i mm_diff, error_sse2, sqcoeff_sse2;;
-      mm_coeff = _mm_packs_epi32(mm_coeff, mm_coeff2);
-      mm_dqcoeff = _mm_packs_epi32(mm_dqcoeff, mm_dqcoeff2);
-      mm_diff = _mm_sub_epi16(mm_coeff, mm_dqcoeff);
-      error_sse2 = _mm_madd_epi16(mm_diff, mm_diff);
-      sqcoeff_sse2 = _mm_madd_epi16(mm_coeff, mm_coeff);
-      _mm_storeu_si128((__m128i*)temp, error_sse2);
-      error = error + temp[0] + temp[1] + temp[2] + temp[3];
-      _mm_storeu_si128((__m128i*)temp, sqcoeff_sse2);
-      sqcoeff += temp[0] + temp[1] + temp[2] + temp[3];
-    } else {
-      for (j = 0; j < 8; j++) {
-        const int64_t diff = coeff[i + j] - dqcoeff[i + j];
-        error +=  diff * diff;
-        sqcoeff += (int64_t)coeff[i + j] * (int64_t)coeff[i + j];
-      }
-    }
-  }
-  assert(error >= 0 && sqcoeff >= 0);
-  error = (error + rounding) >> shift;
-  sqcoeff = (sqcoeff + rounding) >> shift;
-
-  *ssz = sqcoeff;
-  return error;
-}
diff --git a/vp9/encoder/x86/vp9_highbd_error_avx.asm b/vp9/encoder/x86/vp9_highbd_error_avx.asm
deleted file mode 100644 (file)
index e476323..0000000
+++ /dev/null
@@ -1,261 +0,0 @@
-;
-;  Copyright (c) 2015 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.
-;
-
-%define private_prefix vp9
-
-%include "third_party/x86inc/x86inc.asm"
-
-SECTION .text
-ALIGN 16
-
-;
-; int64_t vp9_highbd_block_error_8bit(int32_t *coeff, int32_t *dqcoeff,
-;                                     intptr_t block_size, int64_t *ssz)
-;
-
-INIT_XMM avx
-cglobal highbd_block_error_8bit, 4, 5, 8, uqc, dqc, size, ssz
-  vzeroupper
-
-  ; If only one iteration is required, then handle this as a special case.
-  ; It is the most frequent case, so we can have a significant gain here
-  ; by not setting up a loop and accumulators.
-  cmp    sizeq, 16
-  jne   .generic
-
-  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-  ;; Common case of size == 16
-  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
-  ; Load input vectors
-  mova      xm0, [dqcq]
-  packssdw  xm0, [dqcq+16]
-  mova      xm2, [uqcq]
-  packssdw  xm2, [uqcq+16]
-
-  mova      xm1, [dqcq+32]
-  packssdw  xm1, [dqcq+48]
-  mova      xm3, [uqcq+32]
-  packssdw  xm3, [uqcq+48]
-
-  ; Compute the errors.
-  psubw     xm0, xm2
-  psubw     xm1, xm3
-
-  ; Individual errors are max 15bit+sign, so squares are 30bit, and
-  ; thus the sum of 2 should fit in a 31bit integer (+ unused sign bit).
-  pmaddwd   xm2, xm2
-  pmaddwd   xm3, xm3
-
-  pmaddwd   xm0, xm0
-  pmaddwd   xm1, xm1
-
-  ; Squares are always positive, so we can use unsigned arithmetic after
-  ; squaring. As mentioned earlier 2 sums fit in 31 bits, so 4 sums will
-  ; fit in 32bits
-  paddd     xm2, xm3
-  paddd     xm0, xm1
-
-  ; Accumulate horizontally in 64 bits, there is no chance of overflow here
-  pxor      xm5, xm5
-
-  pblendw   xm3, xm5, xm2, 0x33 ; Zero extended  low of a pair of 32 bits
-  psrlq     xm2, 32             ; Zero extended high of a pair of 32 bits
-
-  pblendw   xm1, xm5, xm0, 0x33 ; Zero extended  low of a pair of 32 bits
-  psrlq     xm0, 32             ; Zero extended high of a pair of 32 bits
-
-  paddq     xm2, xm3
-  paddq     xm0, xm1
-
-  psrldq    xm3, xm2, 8
-  psrldq    xm1, xm0, 8
-
-  paddq     xm2, xm3
-  paddq     xm0, xm1
-
-  ; Store the return value
-%if ARCH_X86_64
-  movq      rax, xm0
-  movq   [sszq], xm2
-%else
-  movd      eax, xm0
-  pextrd    edx, xm0, 1
-  movq   [sszd], xm2
-%endif
-  RET
-
-  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-  ;; Generic case of size != 16, speculative low precision
-  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-  ALIGN 16
-.generic:
-  pxor      xm4, xm4                ; sse accumulator
-  pxor      xm5, xm5                ; overflow detection register for xm4
-  pxor      xm6, xm6                ; ssz accumulator
-  pxor      xm7, xm7                ; overflow detection register for xm6
-  lea      uqcq, [uqcq+sizeq*4]
-  lea      dqcq, [dqcq+sizeq*4]
-  neg     sizeq
-
-  ; Push the negative size as the high precision code might need it
-  push    sizeq
-
-.loop:
-  ; Load input vectors
-  mova      xm0, [dqcq+sizeq*4]
-  packssdw  xm0, [dqcq+sizeq*4+16]
-  mova      xm2, [uqcq+sizeq*4]
-  packssdw  xm2, [uqcq+sizeq*4+16]
-
-  mova      xm1, [dqcq+sizeq*4+32]
-  packssdw  xm1, [dqcq+sizeq*4+48]
-  mova      xm3, [uqcq+sizeq*4+32]
-  packssdw  xm3, [uqcq+sizeq*4+48]
-
-  add     sizeq, 16
-
-  ; Compute the squared errors.
-  ; Individual errors are max 15bit+sign, so squares are 30bit, and
-  ; thus the sum of 2 should fit in a 31bit integer (+ unused sign bit).
-  psubw     xm0, xm2
-  pmaddwd   xm2, xm2
-  pmaddwd   xm0, xm0
-
-  psubw     xm1, xm3
-  pmaddwd   xm3, xm3
-  pmaddwd   xm1, xm1
-
-  ; Squares are always positive, so we can use unsigned arithmetic after
-  ; squaring. As mentioned earlier 2 sums fit in 31 bits, so 4 sums will
-  ; fit in 32bits
-  paddd     xm2, xm3
-  paddd     xm0, xm1
-
-  ; We accumulate using 32 bit arithmetic, but detect potential overflow
-  ; by checking if the MSB of the accumulators have ever been a set bit.
-  ; If yes, we redo the whole compute at the end on higher precision, but
-  ; this happens extremely rarely, so we still achieve a net gain.
-  paddd     xm4, xm0
-  paddd     xm6, xm2
-  por       xm5, xm4  ; OR in the accumulator for overflow detection
-  por       xm7, xm6  ; OR in the accumulator for overflow detection
-
-  jnz .loop
-
-  ; Add pairs horizontally (still only on 32 bits)
-  phaddd    xm4, xm4
-  por       xm5, xm4  ; OR in the accumulator for overflow detection
-  phaddd    xm6, xm6
-  por       xm7, xm6  ; OR in the accumulator for overflow detection
-
-  ; Check for possibility of overflow by testing if bit 32 of each dword lane
-  ; have ever been set. If they were not, then there was no overflow and the
-  ; final sum will fit in 32 bits. If overflow happened, then
-  ; we redo the whole computation on higher precision.
-  por       xm7, xm5
-  pmovmskb   r4, xm7
-  test       r4, 0x8888
-  jnz .highprec
-
-  phaddd    xm4, xm4
-  phaddd    xm6, xm6
-  pmovzxdq  xm4, xm4
-  pmovzxdq  xm6, xm6
-
-  ; Restore stack
-  pop     sizeq
-
-  ; Store the return value
-%if ARCH_X86_64
-  movq      rax, xm4
-  movq   [sszq], xm6
-%else
-  movd      eax, xm4
-  pextrd    edx, xm4, 1
-  movq   [sszd], xm6
-%endif
-  RET
-
-  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-  ;; Generic case of size != 16, high precision case
-  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-.highprec:
-  pxor      xm4, xm4                 ; sse accumulator
-  pxor      xm5, xm5                 ; dedicated zero register
-  pxor      xm6, xm6                 ; ssz accumulator
-  pop     sizeq
-
-.loophp:
-  mova      xm0, [dqcq+sizeq*4]
-  packssdw  xm0, [dqcq+sizeq*4+16]
-  mova      xm2, [uqcq+sizeq*4]
-  packssdw  xm2, [uqcq+sizeq*4+16]
-
-  mova      xm1, [dqcq+sizeq*4+32]
-  packssdw  xm1, [dqcq+sizeq*4+48]
-  mova      xm3, [uqcq+sizeq*4+32]
-  packssdw  xm3, [uqcq+sizeq*4+48]
-
-  add     sizeq, 16
-
-  ; individual errors are max. 15bit+sign, so squares are 30bit, and
-  ; thus the sum of 2 should fit in a 31bit integer (+ unused sign bit)
-
-  psubw     xm0, xm2
-  pmaddwd   xm2, xm2
-  pmaddwd   xm0, xm0
-
-  psubw     xm1, xm3
-  pmaddwd   xm3, xm3
-  pmaddwd   xm1, xm1
-
-  ; accumulate in 64bit
-  punpckldq xm7, xm0, xm5
-  punpckhdq xm0, xm5
-  paddq     xm4, xm7
-
-  punpckldq xm7, xm2, xm5
-  punpckhdq xm2, xm5
-  paddq     xm6, xm7
-
-  punpckldq xm7, xm1, xm5
-  punpckhdq xm1, xm5
-  paddq     xm4, xm7
-
-  punpckldq xm7, xm3, xm5
-  punpckhdq xm3, xm5
-  paddq     xm6, xm7
-
-  paddq     xm4, xm0
-  paddq     xm4, xm1
-  paddq     xm6, xm2
-  paddq     xm6, xm3
-
-  jnz .loophp
-
-  ; Accumulate horizontally
-  movhlps   xm5, xm4
-  movhlps   xm7, xm6
-  paddq     xm4, xm5
-  paddq     xm6, xm7
-
-  ; Store the return value
-%if ARCH_X86_64
-  movq      rax, xm4
-  movq   [sszq], xm6
-%else
-  movd      eax, xm4
-  pextrd    edx, xm4, 1
-  movq   [sszd], xm6
-%endif
-  RET
-
-END
diff --git a/vp9/encoder/x86/vp9_highbd_error_sse2.asm b/vp9/encoder/x86/vp9_highbd_error_sse2.asm
deleted file mode 100644 (file)
index f3b8f01..0000000
+++ /dev/null
@@ -1,98 +0,0 @@
-;
-;  Copyright (c) 2010 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.
-;
-
-%define private_prefix vp9
-
-%include "third_party/x86inc/x86inc.asm"
-
-SECTION .text
-ALIGN 16
-
-;
-; int64_t vp9_highbd_block_error_8bit(int32_t *coeff, int32_t *dqcoeff,
-;                                     intptr_t block_size, int64_t *ssz)
-;
-
-INIT_XMM sse2
-cglobal highbd_block_error_8bit, 3, 3, 8, uqc, dqc, size, ssz
-  pxor      m4, m4                 ; sse accumulator
-  pxor      m6, m6                 ; ssz accumulator
-  pxor      m5, m5                 ; dedicated zero register
-  lea     uqcq, [uqcq+sizeq*4]
-  lea     dqcq, [dqcq+sizeq*4]
-  neg    sizeq
-
-  ALIGN 16
-
-.loop:
-  mova      m0, [dqcq+sizeq*4]
-  packssdw  m0, [dqcq+sizeq*4+mmsize]
-  mova      m2, [uqcq+sizeq*4]
-  packssdw  m2, [uqcq+sizeq*4+mmsize]
-
-  mova      m1, [dqcq+sizeq*4+mmsize*2]
-  packssdw  m1, [dqcq+sizeq*4+mmsize*3]
-  mova      m3, [uqcq+sizeq*4+mmsize*2]
-  packssdw  m3, [uqcq+sizeq*4+mmsize*3]
-
-  add    sizeq, mmsize
-
-  ; individual errors are max. 15bit+sign, so squares are 30bit, and
-  ; thus the sum of 2 should fit in a 31bit integer (+ unused sign bit)
-
-  psubw     m0, m2
-  pmaddwd   m2, m2
-  pmaddwd   m0, m0
-
-  psubw     m1, m3
-  pmaddwd   m3, m3
-  pmaddwd   m1, m1
-
-  ; accumulate in 64bit
-  punpckldq m7, m0, m5
-  punpckhdq m0, m5
-  paddq     m4, m7
-
-  punpckldq m7, m2, m5
-  punpckhdq m2, m5
-  paddq     m6, m7
-
-  punpckldq m7, m1, m5
-  punpckhdq m1, m5
-  paddq     m4, m7
-
-  punpckldq m7, m3, m5
-  punpckhdq m3, m5
-  paddq     m6, m7
-
-  paddq     m4, m0
-  paddq     m4, m1
-  paddq     m6, m2
-  paddq     m6, m3
-
-  jnz .loop
-
-  ; accumulate horizontally and store in return value
-  movhlps   m5, m4
-  movhlps   m7, m6
-  paddq     m4, m5
-  paddq     m6, m7
-
-%if ARCH_X86_64
-  movq    rax, m4
-  movq [sszq], m6
-%else
-  mov     eax, sszm
-  pshufd   m5, m4, 0x1
-  movq  [eax], m6
-  movd    eax, m4
-  movd    edx, m5
-%endif
-  RET
diff --git a/vp9/encoder/x86/vp9_quantize_sse2.c b/vp9/encoder/x86/vp9_quantize_sse2.c
deleted file mode 100644 (file)
index 2071dfe..0000000
+++ /dev/null
@@ -1,211 +0,0 @@
-/*
- *  Copyright (c) 2014 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.
- */
-
-#include <emmintrin.h>
-#include <xmmintrin.h>
-
-#include "./vp9_rtcd.h"
-#include "vpx/vpx_integer.h"
-
-void vp9_quantize_fp_sse2(const int16_t* coeff_ptr, intptr_t n_coeffs,
-                          int skip_block, const int16_t* zbin_ptr,
-                          const int16_t* round_ptr, const int16_t* quant_ptr,
-                          const int16_t* quant_shift_ptr, int16_t* qcoeff_ptr,
-                          int16_t* dqcoeff_ptr, const int16_t* dequant_ptr,
-                          uint16_t* eob_ptr,
-                          const int16_t* scan_ptr,
-                          const int16_t* iscan_ptr) {
-  __m128i zero;
-  __m128i thr;
-  int16_t nzflag;
-  (void)scan_ptr;
-  (void)zbin_ptr;
-  (void)quant_shift_ptr;
-
-  coeff_ptr += n_coeffs;
-  iscan_ptr += n_coeffs;
-  qcoeff_ptr += n_coeffs;
-  dqcoeff_ptr += n_coeffs;
-  n_coeffs = -n_coeffs;
-  zero = _mm_setzero_si128();
-
-  if (!skip_block) {
-    __m128i eob;
-    __m128i round, quant, dequant;
-    {
-      __m128i coeff0, coeff1;
-
-      // Setup global values
-      {
-        round = _mm_load_si128((const __m128i*)round_ptr);
-        quant = _mm_load_si128((const __m128i*)quant_ptr);
-        dequant = _mm_load_si128((const __m128i*)dequant_ptr);
-      }
-
-      {
-        __m128i coeff0_sign, coeff1_sign;
-        __m128i qcoeff0, qcoeff1;
-        __m128i qtmp0, qtmp1;
-        // Do DC and first 15 AC
-        coeff0 = _mm_load_si128((const __m128i*)(coeff_ptr + n_coeffs));
-        coeff1 = _mm_load_si128((const __m128i*)(coeff_ptr + n_coeffs) + 1);
-
-        // Poor man's sign extract
-        coeff0_sign = _mm_srai_epi16(coeff0, 15);
-        coeff1_sign = _mm_srai_epi16(coeff1, 15);
-        qcoeff0 = _mm_xor_si128(coeff0, coeff0_sign);
-        qcoeff1 = _mm_xor_si128(coeff1, coeff1_sign);
-        qcoeff0 = _mm_sub_epi16(qcoeff0, coeff0_sign);
-        qcoeff1 = _mm_sub_epi16(qcoeff1, coeff1_sign);
-
-        qcoeff0 = _mm_adds_epi16(qcoeff0, round);
-        round = _mm_unpackhi_epi64(round, round);
-        qcoeff1 = _mm_adds_epi16(qcoeff1, round);
-        qtmp0 = _mm_mulhi_epi16(qcoeff0, quant);
-        quant = _mm_unpackhi_epi64(quant, quant);
-        qtmp1 = _mm_mulhi_epi16(qcoeff1, quant);
-
-        // Reinsert signs
-        qcoeff0 = _mm_xor_si128(qtmp0, coeff0_sign);
-        qcoeff1 = _mm_xor_si128(qtmp1, coeff1_sign);
-        qcoeff0 = _mm_sub_epi16(qcoeff0, coeff0_sign);
-        qcoeff1 = _mm_sub_epi16(qcoeff1, coeff1_sign);
-
-        _mm_store_si128((__m128i*)(qcoeff_ptr + n_coeffs), qcoeff0);
-        _mm_store_si128((__m128i*)(qcoeff_ptr + n_coeffs) + 1, qcoeff1);
-
-        coeff0 = _mm_mullo_epi16(qcoeff0, dequant);
-        dequant = _mm_unpackhi_epi64(dequant, dequant);
-        coeff1 = _mm_mullo_epi16(qcoeff1, dequant);
-
-        _mm_store_si128((__m128i*)(dqcoeff_ptr + n_coeffs), coeff0);
-        _mm_store_si128((__m128i*)(dqcoeff_ptr + n_coeffs) + 1, coeff1);
-      }
-
-      {
-        // Scan for eob
-        __m128i zero_coeff0, zero_coeff1;
-        __m128i nzero_coeff0, nzero_coeff1;
-        __m128i iscan0, iscan1;
-        __m128i eob1;
-        zero_coeff0 = _mm_cmpeq_epi16(coeff0, zero);
-        zero_coeff1 = _mm_cmpeq_epi16(coeff1, zero);
-        nzero_coeff0 = _mm_cmpeq_epi16(zero_coeff0, zero);
-        nzero_coeff1 = _mm_cmpeq_epi16(zero_coeff1, zero);
-        iscan0 = _mm_load_si128((const __m128i*)(iscan_ptr + n_coeffs));
-        iscan1 = _mm_load_si128((const __m128i*)(iscan_ptr + n_coeffs) + 1);
-        // Add one to convert from indices to counts
-        iscan0 = _mm_sub_epi16(iscan0, nzero_coeff0);
-        iscan1 = _mm_sub_epi16(iscan1, nzero_coeff1);
-        eob = _mm_and_si128(iscan0, nzero_coeff0);
-        eob1 = _mm_and_si128(iscan1, nzero_coeff1);
-        eob = _mm_max_epi16(eob, eob1);
-      }
-      n_coeffs += 8 * 2;
-    }
-
-    thr = _mm_srai_epi16(dequant, 1);
-
-    // AC only loop
-    while (n_coeffs < 0) {
-      __m128i coeff0, coeff1;
-      {
-        __m128i coeff0_sign, coeff1_sign;
-        __m128i qcoeff0, qcoeff1;
-        __m128i qtmp0, qtmp1;
-
-        coeff0 = _mm_load_si128((const __m128i*)(coeff_ptr + n_coeffs));
-        coeff1 = _mm_load_si128((const __m128i*)(coeff_ptr + n_coeffs) + 1);
-
-        // Poor man's sign extract
-        coeff0_sign = _mm_srai_epi16(coeff0, 15);
-        coeff1_sign = _mm_srai_epi16(coeff1, 15);
-        qcoeff0 = _mm_xor_si128(coeff0, coeff0_sign);
-        qcoeff1 = _mm_xor_si128(coeff1, coeff1_sign);
-        qcoeff0 = _mm_sub_epi16(qcoeff0, coeff0_sign);
-        qcoeff1 = _mm_sub_epi16(qcoeff1, coeff1_sign);
-
-        nzflag = _mm_movemask_epi8(_mm_cmpgt_epi16(qcoeff0, thr)) |
-            _mm_movemask_epi8(_mm_cmpgt_epi16(qcoeff1, thr));
-
-        if (nzflag) {
-          qcoeff0 = _mm_adds_epi16(qcoeff0, round);
-          qcoeff1 = _mm_adds_epi16(qcoeff1, round);
-          qtmp0 = _mm_mulhi_epi16(qcoeff0, quant);
-          qtmp1 = _mm_mulhi_epi16(qcoeff1, quant);
-
-          // Reinsert signs
-          qcoeff0 = _mm_xor_si128(qtmp0, coeff0_sign);
-          qcoeff1 = _mm_xor_si128(qtmp1, coeff1_sign);
-          qcoeff0 = _mm_sub_epi16(qcoeff0, coeff0_sign);
-          qcoeff1 = _mm_sub_epi16(qcoeff1, coeff1_sign);
-
-          _mm_store_si128((__m128i*)(qcoeff_ptr + n_coeffs), qcoeff0);
-          _mm_store_si128((__m128i*)(qcoeff_ptr + n_coeffs) + 1, qcoeff1);
-
-          coeff0 = _mm_mullo_epi16(qcoeff0, dequant);
-          coeff1 = _mm_mullo_epi16(qcoeff1, dequant);
-
-          _mm_store_si128((__m128i*)(dqcoeff_ptr + n_coeffs), coeff0);
-          _mm_store_si128((__m128i*)(dqcoeff_ptr + n_coeffs) + 1, coeff1);
-        } else {
-          _mm_store_si128((__m128i*)(qcoeff_ptr + n_coeffs), zero);
-          _mm_store_si128((__m128i*)(qcoeff_ptr + n_coeffs) + 1, zero);
-
-          _mm_store_si128((__m128i*)(dqcoeff_ptr + n_coeffs), zero);
-          _mm_store_si128((__m128i*)(dqcoeff_ptr + n_coeffs) + 1, zero);
-        }
-      }
-
-      if (nzflag) {
-        // Scan for eob
-        __m128i zero_coeff0, zero_coeff1;
-        __m128i nzero_coeff0, nzero_coeff1;
-        __m128i iscan0, iscan1;
-        __m128i eob0, eob1;
-        zero_coeff0 = _mm_cmpeq_epi16(coeff0, zero);
-        zero_coeff1 = _mm_cmpeq_epi16(coeff1, zero);
-        nzero_coeff0 = _mm_cmpeq_epi16(zero_coeff0, zero);
-        nzero_coeff1 = _mm_cmpeq_epi16(zero_coeff1, zero);
-        iscan0 = _mm_load_si128((const __m128i*)(iscan_ptr + n_coeffs));
-        iscan1 = _mm_load_si128((const __m128i*)(iscan_ptr + n_coeffs) + 1);
-        // Add one to convert from indices to counts
-        iscan0 = _mm_sub_epi16(iscan0, nzero_coeff0);
-        iscan1 = _mm_sub_epi16(iscan1, nzero_coeff1);
-        eob0 = _mm_and_si128(iscan0, nzero_coeff0);
-        eob1 = _mm_and_si128(iscan1, nzero_coeff1);
-        eob0 = _mm_max_epi16(eob0, eob1);
-        eob = _mm_max_epi16(eob, eob0);
-      }
-      n_coeffs += 8 * 2;
-    }
-
-    // Accumulate EOB
-    {
-      __m128i eob_shuffled;
-      eob_shuffled = _mm_shuffle_epi32(eob, 0xe);
-      eob = _mm_max_epi16(eob, eob_shuffled);
-      eob_shuffled = _mm_shufflelo_epi16(eob, 0xe);
-      eob = _mm_max_epi16(eob, eob_shuffled);
-      eob_shuffled = _mm_shufflelo_epi16(eob, 0x1);
-      eob = _mm_max_epi16(eob, eob_shuffled);
-      *eob_ptr = _mm_extract_epi16(eob, 1);
-    }
-  } else {
-    do {
-      _mm_store_si128((__m128i*)(dqcoeff_ptr + n_coeffs), zero);
-      _mm_store_si128((__m128i*)(dqcoeff_ptr + n_coeffs) + 1, zero);
-      _mm_store_si128((__m128i*)(qcoeff_ptr + n_coeffs), zero);
-      _mm_store_si128((__m128i*)(qcoeff_ptr + n_coeffs) + 1, zero);
-      n_coeffs += 8 * 2;
-    } while (n_coeffs < 0);
-    *eob_ptr = 0;
-  }
-}
diff --git a/vp9/encoder/x86/vp9_quantize_ssse3_x86_64.asm b/vp9/encoder/x86/vp9_quantize_ssse3_x86_64.asm
deleted file mode 100644 (file)
index ec61c0c..0000000
+++ /dev/null
@@ -1,201 +0,0 @@
-;
-;  Copyright (c) 2010 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.
-;
-
-%define private_prefix vp9
-
-%include "third_party/x86inc/x86inc.asm"
-
-SECTION_RODATA
-pw_1: times 8 dw 1
-
-SECTION .text
-
-%macro QUANTIZE_FP 2
-cglobal quantize_%1, 0, %2, 15, coeff, ncoeff, skip, zbin, round, quant, \
-                                shift, qcoeff, dqcoeff, dequant, \
-                                eob, scan, iscan
-  cmp                    dword skipm, 0
-  jne .blank
-
-  ; actual quantize loop - setup pointers, rounders, etc.
-  movifnidn                   coeffq, coeffmp
-  movifnidn                  ncoeffq, ncoeffmp
-  mov                             r2, dequantmp
-  movifnidn                    zbinq, zbinmp
-  movifnidn                   roundq, roundmp
-  movifnidn                   quantq, quantmp
-  mova                            m1, [roundq]             ; m1 = round
-  mova                            m2, [quantq]             ; m2 = quant
-%ifidn %1, fp_32x32
-  pcmpeqw                         m5, m5
-  psrlw                           m5, 15
-  paddw                           m1, m5
-  psrlw                           m1, 1                    ; m1 = (m1 + 1) / 2
-%endif
-  mova                            m3, [r2q]                ; m3 = dequant
-  mov                             r3, qcoeffmp
-  mov                             r4, dqcoeffmp
-  mov                             r5, iscanmp
-%ifidn %1, fp_32x32
-  psllw                           m2, 1
-%endif
-  pxor                            m5, m5                   ; m5 = dedicated zero
-
-  lea                         coeffq, [  coeffq+ncoeffq*2]
-  lea                            r5q, [  r5q+ncoeffq*2]
-  lea                            r3q, [ r3q+ncoeffq*2]
-  lea                            r4q, [r4q+ncoeffq*2]
-  neg                        ncoeffq
-
-  ; get DC and first 15 AC coeffs
-  mova                            m9, [  coeffq+ncoeffq*2+ 0] ; m9 = c[i]
-  mova                           m10, [  coeffq+ncoeffq*2+16] ; m10 = c[i]
-  pabsw                           m6, m9                   ; m6 = abs(m9)
-  pabsw                          m11, m10                  ; m11 = abs(m10)
-  pcmpeqw                         m7, m7
-
-  paddsw                          m6, m1                   ; m6 += round
-  punpckhqdq                      m1, m1
-  paddsw                         m11, m1                   ; m11 += round
-  pmulhw                          m8, m6, m2               ; m8 = m6*q>>16
-  punpckhqdq                      m2, m2
-  pmulhw                         m13, m11, m2              ; m13 = m11*q>>16
-  psignw                          m8, m9                   ; m8 = reinsert sign
-  psignw                         m13, m10                  ; m13 = reinsert sign
-  mova            [r3q+ncoeffq*2+ 0], m8
-  mova            [r3q+ncoeffq*2+16], m13
-%ifidn %1, fp_32x32
-  pabsw                           m8, m8
-  pabsw                          m13, m13
-%endif
-  pmullw                          m8, m3                   ; r4[i] = r3[i] * q
-  punpckhqdq                      m3, m3
-  pmullw                         m13, m3                   ; r4[i] = r3[i] * q
-%ifidn %1, fp_32x32
-  psrlw                           m8, 1
-  psrlw                          m13, 1
-  psignw                          m8, m9
-  psignw                         m13, m10
-  psrlw                           m0, m3, 2
-%else
-  psrlw                           m0, m3, 1
-%endif
-  mova            [r4q+ncoeffq*2+ 0], m8
-  mova            [r4q+ncoeffq*2+16], m13
-  pcmpeqw                         m8, m5                   ; m8 = c[i] == 0
-  pcmpeqw                        m13, m5                   ; m13 = c[i] == 0
-  mova                            m6, [  r5q+ncoeffq*2+ 0] ; m6 = scan[i]
-  mova                           m11, [  r5q+ncoeffq*2+16] ; m11 = scan[i]
-  psubw                           m6, m7                   ; m6 = scan[i] + 1
-  psubw                          m11, m7                   ; m11 = scan[i] + 1
-  pandn                           m8, m6                   ; m8 = max(eob)
-  pandn                          m13, m11                  ; m13 = max(eob)
-  pmaxsw                          m8, m13
-  add                        ncoeffq, mmsize
-  jz .accumulate_eob
-
-.ac_only_loop:
-  mova                            m9, [  coeffq+ncoeffq*2+ 0] ; m9 = c[i]
-  mova                           m10, [  coeffq+ncoeffq*2+16] ; m10 = c[i]
-  pabsw                           m6, m9                   ; m6 = abs(m9)
-  pabsw                          m11, m10                  ; m11 = abs(m10)
-
-  pcmpgtw                         m7, m6,  m0
-  pcmpgtw                        m12, m11, m0
-  pmovmskb                       r6d, m7
-  pmovmskb                       r2d, m12
-
-  or                              r6, r2
-  jz .skip_iter
-
-  pcmpeqw                         m7, m7
-
-  paddsw                          m6, m1                   ; m6 += round
-  paddsw                         m11, m1                   ; m11 += round
-  pmulhw                         m14, m6, m2               ; m14 = m6*q>>16
-  pmulhw                         m13, m11, m2              ; m13 = m11*q>>16
-  psignw                         m14, m9                   ; m14 = reinsert sign
-  psignw                         m13, m10                  ; m13 = reinsert sign
-  mova            [r3q+ncoeffq*2+ 0], m14
-  mova            [r3q+ncoeffq*2+16], m13
-%ifidn %1, fp_32x32
-  pabsw                          m14, m14
-  pabsw                          m13, m13
-%endif
-  pmullw                         m14, m3                   ; r4[i] = r3[i] * q
-  pmullw                         m13, m3                   ; r4[i] = r3[i] * q
-%ifidn %1, fp_32x32
-  psrlw                          m14, 1
-  psrlw                          m13, 1
-  psignw                         m14, m9
-  psignw                         m13, m10
-%endif
-  mova            [r4q+ncoeffq*2+ 0], m14
-  mova            [r4q+ncoeffq*2+16], m13
-  pcmpeqw                        m14, m5                   ; m14 = c[i] == 0
-  pcmpeqw                        m13, m5                   ; m13 = c[i] == 0
-  mova                            m6, [  r5q+ncoeffq*2+ 0] ; m6 = scan[i]
-  mova                           m11, [  r5q+ncoeffq*2+16] ; m11 = scan[i]
-  psubw                           m6, m7                   ; m6 = scan[i] + 1
-  psubw                          m11, m7                   ; m11 = scan[i] + 1
-  pandn                          m14, m6                   ; m14 = max(eob)
-  pandn                          m13, m11                  ; m13 = max(eob)
-  pmaxsw                          m8, m14
-  pmaxsw                          m8, m13
-  add                        ncoeffq, mmsize
-  jl .ac_only_loop
-
-  jmp .accumulate_eob
-.skip_iter:
-  mova            [r3q+ncoeffq*2+ 0], m5
-  mova            [r3q+ncoeffq*2+16], m5
-  mova            [r4q+ncoeffq*2+ 0], m5
-  mova            [r4q+ncoeffq*2+16], m5
-  add                        ncoeffq, mmsize
-  jl .ac_only_loop
-
-.accumulate_eob:
-  ; horizontally accumulate/max eobs and write into [eob] memory pointer
-  mov                             r2, eobmp
-  pshufd                          m7, m8, 0xe
-  pmaxsw                          m8, m7
-  pshuflw                         m7, m8, 0xe
-  pmaxsw                          m8, m7
-  pshuflw                         m7, m8, 0x1
-  pmaxsw                          m8, m7
-  pextrw                          r6, m8, 0
-  mov                           [r2], r6
-  RET
-
-  ; skip-block, i.e. just write all zeroes
-.blank:
-  mov                             r0, dqcoeffmp
-  movifnidn                  ncoeffq, ncoeffmp
-  mov                             r2, qcoeffmp
-  mov                             r3, eobmp
-
-  lea                            r0q, [r0q+ncoeffq*2]
-  lea                            r2q, [r2q+ncoeffq*2]
-  neg                        ncoeffq
-  pxor                            m7, m7
-.blank_loop:
-  mova            [r0q+ncoeffq*2+ 0], m7
-  mova            [r0q+ncoeffq*2+16], m7
-  mova            [r2q+ncoeffq*2+ 0], m7
-  mova            [r2q+ncoeffq*2+16], m7
-  add                        ncoeffq, mmsize
-  jl .blank_loop
-  mov                     word [r3q], 0
-  RET
-%endmacro
-
-INIT_XMM ssse3
-QUANTIZE_FP fp, 7
-QUANTIZE_FP fp_32x32, 7
diff --git a/vp9/encoder/x86/vp9_temporal_filter_apply_sse2.asm b/vp9/encoder/x86/vp9_temporal_filter_apply_sse2.asm
deleted file mode 100644 (file)
index 21aaa93..0000000
+++ /dev/null
@@ -1,212 +0,0 @@
-;
-;  Copyright (c) 2010 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.
-;
-
-
-%include "vpx_ports/x86_abi_support.asm"
-
-; void vp9_temporal_filter_apply_sse2 | arg
-;  (unsigned char  *frame1,           |  0
-;   unsigned int    stride,           |  1
-;   unsigned char  *frame2,           |  2
-;   unsigned int    block_width,      |  3
-;   unsigned int    block_height,     |  4
-;   int             strength,         |  5
-;   int             filter_weight,    |  6
-;   unsigned int   *accumulator,      |  7
-;   unsigned short *count)            |  8
-global sym(vp9_temporal_filter_apply_sse2) PRIVATE
-sym(vp9_temporal_filter_apply_sse2):
-
-    push        rbp
-    mov         rbp, rsp
-    SHADOW_ARGS_TO_STACK 9
-    SAVE_XMM 7
-    GET_GOT     rbx
-    push        rsi
-    push        rdi
-    ALIGN_STACK 16, rax
-    %define block_width    0
-    %define block_height  16
-    %define strength      32
-    %define filter_weight 48
-    %define rounding_bit  64
-    %define rbp_backup    80
-    %define stack_size    96
-    sub         rsp,           stack_size
-    mov         [rsp + rbp_backup], rbp
-    ; end prolog
-
-        mov         edx,            arg(3)
-        mov         [rsp + block_width], rdx
-        mov         edx,            arg(4)
-        mov         [rsp + block_height], rdx
-        movd        xmm6,           arg(5)
-        movdqa      [rsp + strength], xmm6 ; where strength is used, all 16 bytes are read
-
-        ; calculate the rounding bit outside the loop
-        ; 0x8000 >> (16 - strength)
-        mov         rdx,            16
-        sub         rdx,            arg(5) ; 16 - strength
-        movq        xmm4,           rdx    ; can't use rdx w/ shift
-        movdqa      xmm5,           [GLOBAL(_const_top_bit)]
-        psrlw       xmm5,           xmm4
-        movdqa      [rsp + rounding_bit], xmm5
-
-        mov         rsi,            arg(0) ; src/frame1
-        mov         rdx,            arg(2) ; predictor frame
-        mov         rdi,            arg(7) ; accumulator
-        mov         rax,            arg(8) ; count
-
-        ; dup the filter weight and store for later
-        movd        xmm0,           arg(6) ; filter_weight
-        pshuflw     xmm0,           xmm0, 0
-        punpcklwd   xmm0,           xmm0
-        movdqa      [rsp + filter_weight], xmm0
-
-        mov         rbp,            arg(1) ; stride
-        pxor        xmm7,           xmm7   ; zero for extraction
-
-        mov         rcx,            [rsp + block_width]
-        imul        rcx,            [rsp + block_height]
-        add         rcx,            rdx
-        cmp         dword ptr [rsp + block_width], 8
-        jne         .temporal_filter_apply_load_16
-
-.temporal_filter_apply_load_8:
-        movq        xmm0,           [rsi]  ; first row
-        lea         rsi,            [rsi + rbp] ; += stride
-        punpcklbw   xmm0,           xmm7   ; src[ 0- 7]
-        movq        xmm1,           [rsi]  ; second row
-        lea         rsi,            [rsi + rbp] ; += stride
-        punpcklbw   xmm1,           xmm7   ; src[ 8-15]
-        jmp         .temporal_filter_apply_load_finished
-
-.temporal_filter_apply_load_16:
-        movdqa      xmm0,           [rsi]  ; src (frame1)
-        lea         rsi,            [rsi + rbp] ; += stride
-        movdqa      xmm1,           xmm0
-        punpcklbw   xmm0,           xmm7   ; src[ 0- 7]
-        punpckhbw   xmm1,           xmm7   ; src[ 8-15]
-
-.temporal_filter_apply_load_finished:
-        movdqa      xmm2,           [rdx]  ; predictor (frame2)
-        movdqa      xmm3,           xmm2
-        punpcklbw   xmm2,           xmm7   ; pred[ 0- 7]
-        punpckhbw   xmm3,           xmm7   ; pred[ 8-15]
-
-        ; modifier = src_byte - pixel_value
-        psubw       xmm0,           xmm2   ; src - pred[ 0- 7]
-        psubw       xmm1,           xmm3   ; src - pred[ 8-15]
-
-        ; modifier *= modifier
-        pmullw      xmm0,           xmm0   ; modifer[ 0- 7]^2
-        pmullw      xmm1,           xmm1   ; modifer[ 8-15]^2
-
-        ; modifier *= 3
-        pmullw      xmm0,           [GLOBAL(_const_3w)]
-        pmullw      xmm1,           [GLOBAL(_const_3w)]
-
-        ; modifer += 0x8000 >> (16 - strength)
-        paddw       xmm0,           [rsp + rounding_bit]
-        paddw       xmm1,           [rsp + rounding_bit]
-
-        ; modifier >>= strength
-        psrlw       xmm0,           [rsp + strength]
-        psrlw       xmm1,           [rsp + strength]
-
-        ; modifier = 16 - modifier
-        ; saturation takes care of modifier > 16
-        movdqa      xmm3,           [GLOBAL(_const_16w)]
-        movdqa      xmm2,           [GLOBAL(_const_16w)]
-        psubusw     xmm3,           xmm1
-        psubusw     xmm2,           xmm0
-
-        ; modifier *= filter_weight
-        pmullw      xmm2,           [rsp + filter_weight]
-        pmullw      xmm3,           [rsp + filter_weight]
-
-        ; count
-        movdqa      xmm4,           [rax]
-        movdqa      xmm5,           [rax+16]
-        ; += modifier
-        paddw       xmm4,           xmm2
-        paddw       xmm5,           xmm3
-        ; write back
-        movdqa      [rax],          xmm4
-        movdqa      [rax+16],       xmm5
-        lea         rax,            [rax + 16*2] ; count += 16*(sizeof(short))
-
-        ; load and extract the predictor up to shorts
-        pxor        xmm7,           xmm7
-        movdqa      xmm0,           [rdx]
-        lea         rdx,            [rdx + 16*1] ; pred += 16*(sizeof(char))
-        movdqa      xmm1,           xmm0
-        punpcklbw   xmm0,           xmm7   ; pred[ 0- 7]
-        punpckhbw   xmm1,           xmm7   ; pred[ 8-15]
-
-        ; modifier *= pixel_value
-        pmullw      xmm0,           xmm2
-        pmullw      xmm1,           xmm3
-
-        ; expand to double words
-        movdqa      xmm2,           xmm0
-        punpcklwd   xmm0,           xmm7   ; [ 0- 3]
-        punpckhwd   xmm2,           xmm7   ; [ 4- 7]
-        movdqa      xmm3,           xmm1
-        punpcklwd   xmm1,           xmm7   ; [ 8-11]
-        punpckhwd   xmm3,           xmm7   ; [12-15]
-
-        ; accumulator
-        movdqa      xmm4,           [rdi]
-        movdqa      xmm5,           [rdi+16]
-        movdqa      xmm6,           [rdi+32]
-        movdqa      xmm7,           [rdi+48]
-        ; += modifier
-        paddd       xmm4,           xmm0
-        paddd       xmm5,           xmm2
-        paddd       xmm6,           xmm1
-        paddd       xmm7,           xmm3
-        ; write back
-        movdqa      [rdi],          xmm4
-        movdqa      [rdi+16],       xmm5
-        movdqa      [rdi+32],       xmm6
-        movdqa      [rdi+48],       xmm7
-        lea         rdi,            [rdi + 16*4] ; accumulator += 16*(sizeof(int))
-
-        cmp         rdx,            rcx
-        je          .temporal_filter_apply_epilog
-        pxor        xmm7,           xmm7   ; zero for extraction
-        cmp         dword ptr [rsp + block_width], 16
-        je          .temporal_filter_apply_load_16
-        jmp         .temporal_filter_apply_load_8
-
-.temporal_filter_apply_epilog:
-    ; begin epilog
-    mov         rbp,            [rsp + rbp_backup]
-    add         rsp,            stack_size
-    pop         rsp
-    pop         rdi
-    pop         rsi
-    RESTORE_GOT
-    RESTORE_XMM
-    UNSHADOW_ARGS
-    pop         rbp
-    ret
-
-SECTION_RODATA
-align 16
-_const_3w:
-    times 8 dw 3
-align 16
-_const_top_bit:
-    times 8 dw 1<<15
-align 16
-_const_16w
-    times 8 dw 16
diff --git a/vp9/exports_dec b/vp9/exports_dec
deleted file mode 100644 (file)
index 0a61fde..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-data vpx_codec_vp9_dx_algo
-text vpx_codec_vp9_dx
diff --git a/vp9/exports_enc b/vp9/exports_enc
deleted file mode 100644 (file)
index 2a0fef3..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-data vpx_codec_vp9_cx_algo
-text vpx_codec_vp9_cx
diff --git a/vp9/vp9_common.mk b/vp9/vp9_common.mk
deleted file mode 100644 (file)
index 2dbf0f6..0000000
+++ /dev/null
@@ -1,94 +0,0 @@
-##
-##  Copyright (c) 2010 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.
-##
-
-VP9_COMMON_SRCS-yes += vp9_common.mk
-VP9_COMMON_SRCS-yes += vp9_iface_common.h
-VP9_COMMON_SRCS-yes += common/vp9_ppflags.h
-VP9_COMMON_SRCS-yes += common/vp9_alloccommon.c
-VP9_COMMON_SRCS-yes += common/vp9_blockd.c
-VP9_COMMON_SRCS-yes += common/vp9_debugmodes.c
-VP9_COMMON_SRCS-yes += common/vp9_entropy.c
-VP9_COMMON_SRCS-yes += common/vp9_entropymode.c
-VP9_COMMON_SRCS-yes += common/vp9_entropymv.c
-VP9_COMMON_SRCS-yes += common/vp9_frame_buffers.c
-VP9_COMMON_SRCS-yes += common/vp9_frame_buffers.h
-VP9_COMMON_SRCS-yes += common/vp9_idct.c
-VP9_COMMON_SRCS-yes += common/vp9_alloccommon.h
-VP9_COMMON_SRCS-yes += common/vp9_blockd.h
-VP9_COMMON_SRCS-yes += common/vp9_common.h
-VP9_COMMON_SRCS-yes += common/vp9_entropy.h
-VP9_COMMON_SRCS-yes += common/vp9_entropymode.h
-VP9_COMMON_SRCS-yes += common/vp9_entropymv.h
-VP9_COMMON_SRCS-yes += common/vp9_enums.h
-VP9_COMMON_SRCS-yes += common/vp9_filter.h
-VP9_COMMON_SRCS-yes += common/vp9_filter.c
-VP9_COMMON_SRCS-yes += common/vp9_idct.h
-VP9_COMMON_SRCS-yes += common/vp9_loopfilter.h
-VP9_COMMON_SRCS-yes += common/vp9_thread_common.h
-VP9_COMMON_SRCS-yes += common/vp9_mv.h
-VP9_COMMON_SRCS-yes += common/vp9_onyxc_int.h
-VP9_COMMON_SRCS-yes += common/vp9_pred_common.h
-VP9_COMMON_SRCS-yes += common/vp9_pred_common.c
-VP9_COMMON_SRCS-yes += common/vp9_quant_common.h
-VP9_COMMON_SRCS-yes += common/vp9_reconinter.h
-VP9_COMMON_SRCS-yes += common/vp9_reconintra.h
-VP9_COMMON_SRCS-yes += common/vp9_rtcd.c
-VP9_COMMON_SRCS-yes += common/vp9_rtcd_defs.pl
-VP9_COMMON_SRCS-yes += common/vp9_scale.h
-VP9_COMMON_SRCS-yes += common/vp9_scale.c
-VP9_COMMON_SRCS-yes += common/vp9_seg_common.h
-VP9_COMMON_SRCS-yes += common/vp9_seg_common.c
-VP9_COMMON_SRCS-yes += common/vp9_textblit.h
-VP9_COMMON_SRCS-yes += common/vp9_tile_common.h
-VP9_COMMON_SRCS-yes += common/vp9_tile_common.c
-VP9_COMMON_SRCS-yes += common/vp9_loopfilter.c
-VP9_COMMON_SRCS-yes += common/vp9_thread_common.c
-VP9_COMMON_SRCS-yes += common/vp9_mvref_common.c
-VP9_COMMON_SRCS-yes += common/vp9_mvref_common.h
-VP9_COMMON_SRCS-yes += common/vp9_quant_common.c
-VP9_COMMON_SRCS-yes += common/vp9_reconinter.c
-VP9_COMMON_SRCS-yes += common/vp9_reconintra.c
-VP9_COMMON_SRCS-$(CONFIG_POSTPROC_VISUALIZER) += common/vp9_textblit.c
-VP9_COMMON_SRCS-yes += common/vp9_common_data.c
-VP9_COMMON_SRCS-yes += common/vp9_common_data.h
-VP9_COMMON_SRCS-yes += common/vp9_scan.c
-VP9_COMMON_SRCS-yes += common/vp9_scan.h
-
-VP9_COMMON_SRCS-$(CONFIG_VP9_POSTPROC) += common/vp9_postproc.h
-VP9_COMMON_SRCS-$(CONFIG_VP9_POSTPROC) += common/vp9_postproc.c
-VP9_COMMON_SRCS-$(CONFIG_VP9_POSTPROC) += common/vp9_mfqe.h
-VP9_COMMON_SRCS-$(CONFIG_VP9_POSTPROC) += common/vp9_mfqe.c
-ifeq ($(CONFIG_VP9_POSTPROC),yes)
-VP9_COMMON_SRCS-$(HAVE_SSE2) += common/x86/vp9_mfqe_sse2.asm
-endif
-
-ifneq ($(CONFIG_VP9_HIGHBITDEPTH),yes)
-VP9_COMMON_SRCS-$(HAVE_DSPR2)  += common/mips/dspr2/vp9_itrans4_dspr2.c
-VP9_COMMON_SRCS-$(HAVE_DSPR2)  += common/mips/dspr2/vp9_itrans8_dspr2.c
-VP9_COMMON_SRCS-$(HAVE_DSPR2)  += common/mips/dspr2/vp9_itrans16_dspr2.c
-endif
-
-# common (msa)
-VP9_COMMON_SRCS-$(HAVE_MSA) += common/mips/msa/vp9_idct4x4_msa.c
-VP9_COMMON_SRCS-$(HAVE_MSA) += common/mips/msa/vp9_idct8x8_msa.c
-VP9_COMMON_SRCS-$(HAVE_MSA) += common/mips/msa/vp9_idct16x16_msa.c
-
-ifeq ($(CONFIG_VP9_POSTPROC),yes)
-VP9_COMMON_SRCS-$(HAVE_MSA) += common/mips/msa/vp9_mfqe_msa.c
-endif
-
-VP9_COMMON_SRCS-$(HAVE_SSE2) += common/x86/vp9_idct_intrin_sse2.c
-
-ifneq ($(CONFIG_VP9_HIGHBITDEPTH),yes)
-VP9_COMMON_SRCS-$(HAVE_NEON) += common/arm/neon/vp9_iht4x4_add_neon.c
-VP9_COMMON_SRCS-$(HAVE_NEON) += common/arm/neon/vp9_iht8x8_add_neon.c
-endif
-
-$(eval $(call rtcd_h_template,vp9_rtcd,vp9/common/vp9_rtcd_defs.pl))
diff --git a/vp9/vp9_cx_iface.c b/vp9/vp9_cx_iface.c
deleted file mode 100644 (file)
index f4e989f..0000000
+++ /dev/null
@@ -1,1646 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#include <stdlib.h>
-#include <string.h>
-
-#include "./vpx_config.h"
-#include "vpx/vpx_encoder.h"
-#include "vpx_ports/vpx_once.h"
-#include "vpx_ports/system_state.h"
-#include "vpx/internal/vpx_codec_internal.h"
-#include "./vpx_version.h"
-#include "vp9/encoder/vp9_encoder.h"
-#include "vpx/vp8cx.h"
-#include "vp9/encoder/vp9_firstpass.h"
-#include "vp9/vp9_iface_common.h"
-
-struct vp9_extracfg {
-  int                         cpu_used;  // available cpu percentage in 1/16
-  unsigned int                enable_auto_alt_ref;
-  unsigned int                noise_sensitivity;
-  unsigned int                sharpness;
-  unsigned int                static_thresh;
-  unsigned int                tile_columns;
-  unsigned int                tile_rows;
-  unsigned int                arnr_max_frames;
-  unsigned int                arnr_strength;
-  unsigned int                min_gf_interval;
-  unsigned int                max_gf_interval;
-  vp8e_tuning                 tuning;
-  unsigned int                cq_level;  // constrained quality level
-  unsigned int                rc_max_intra_bitrate_pct;
-  unsigned int                rc_max_inter_bitrate_pct;
-  unsigned int                gf_cbr_boost_pct;
-  unsigned int                lossless;
-  unsigned int                target_level;
-  unsigned int                frame_parallel_decoding_mode;
-  AQ_MODE                     aq_mode;
-  unsigned int                frame_periodic_boost;
-  vpx_bit_depth_t             bit_depth;
-  vp9e_tune_content           content;
-  vpx_color_space_t           color_space;
-  vpx_color_range_t           color_range;
-  int                         render_width;
-  int                         render_height;
-};
-
-static struct vp9_extracfg default_extra_cfg = {
-  0,                          // cpu_used
-  1,                          // enable_auto_alt_ref
-  0,                          // noise_sensitivity
-  0,                          // sharpness
-  0,                          // static_thresh
-  6,                          // tile_columns
-  0,                          // tile_rows
-  7,                          // arnr_max_frames
-  5,                          // arnr_strength
-  0,                          // min_gf_interval; 0 -> default decision
-  0,                          // max_gf_interval; 0 -> default decision
-  VP8_TUNE_PSNR,              // tuning
-  10,                         // cq_level
-  0,                          // rc_max_intra_bitrate_pct
-  0,                          // rc_max_inter_bitrate_pct
-  0,                          // gf_cbr_boost_pct
-  0,                          // lossless
-  255,                        // target_level
-  1,                          // frame_parallel_decoding_mode
-  NO_AQ,                      // aq_mode
-  0,                          // frame_periodic_delta_q
-  VPX_BITS_8,                 // Bit depth
-  VP9E_CONTENT_DEFAULT,       // content
-  VPX_CS_UNKNOWN,             // color space
-  0,                          // color range
-  0,                          // render width
-  0,                          // render height
-};
-
-struct vpx_codec_alg_priv {
-  vpx_codec_priv_t        base;
-  vpx_codec_enc_cfg_t     cfg;
-  struct vp9_extracfg     extra_cfg;
-  VP9EncoderConfig        oxcf;
-  VP9_COMP               *cpi;
-  unsigned char          *cx_data;
-  size_t                  cx_data_sz;
-  unsigned char          *pending_cx_data;
-  size_t                  pending_cx_data_sz;
-  int                     pending_frame_count;
-  size_t                  pending_frame_sizes[8];
-  size_t                  pending_frame_magnitude;
-  vpx_image_t             preview_img;
-  vpx_enc_frame_flags_t   next_frame_flags;
-  vp8_postproc_cfg_t      preview_ppcfg;
-  vpx_codec_pkt_list_decl(256) pkt_list;
-  unsigned int                 fixed_kf_cntr;
-  vpx_codec_priv_output_cx_pkt_cb_pair_t output_cx_pkt_cb;
-  // BufferPool that holds all reference frames.
-  BufferPool              *buffer_pool;
-};
-
-static vpx_codec_err_t update_error_state(vpx_codec_alg_priv_t *ctx,
-    const struct vpx_internal_error_info *error) {
-  const vpx_codec_err_t res = error->error_code;
-
-  if (res != VPX_CODEC_OK)
-    ctx->base.err_detail = error->has_detail ? error->detail : NULL;
-
-  return res;
-}
-
-
-#undef ERROR
-#define ERROR(str) do {\
-    ctx->base.err_detail = str;\
-    return VPX_CODEC_INVALID_PARAM;\
-  } while (0)
-
-#define RANGE_CHECK(p, memb, lo, hi) do {\
-    if (!(((p)->memb == lo || (p)->memb > (lo)) && (p)->memb <= hi)) \
-      ERROR(#memb " out of range ["#lo".."#hi"]");\
-  } while (0)
-
-#define RANGE_CHECK_HI(p, memb, hi) do {\
-    if (!((p)->memb <= (hi))) \
-      ERROR(#memb " out of range [.."#hi"]");\
-  } while (0)
-
-#define RANGE_CHECK_LO(p, memb, lo) do {\
-    if (!((p)->memb >= (lo))) \
-      ERROR(#memb " out of range ["#lo"..]");\
-  } while (0)
-
-#define RANGE_CHECK_BOOL(p, memb) do {\
-    if (!!((p)->memb) != (p)->memb) ERROR(#memb " expected boolean");\
-  } while (0)
-
-static vpx_codec_err_t validate_config(vpx_codec_alg_priv_t *ctx,
-                                       const vpx_codec_enc_cfg_t *cfg,
-                                       const struct vp9_extracfg *extra_cfg) {
-  RANGE_CHECK(cfg, g_w,                   1, 65535);  // 16 bits available
-  RANGE_CHECK(cfg, g_h,                   1, 65535);  // 16 bits available
-  RANGE_CHECK(cfg, g_timebase.den,        1, 1000000000);
-  RANGE_CHECK(cfg, g_timebase.num,        1, 1000000000);
-  RANGE_CHECK_HI(cfg, g_profile,          3);
-
-  RANGE_CHECK_HI(cfg, rc_max_quantizer,   63);
-  RANGE_CHECK_HI(cfg, rc_min_quantizer,   cfg->rc_max_quantizer);
-  RANGE_CHECK_BOOL(extra_cfg, lossless);
-  RANGE_CHECK(extra_cfg, aq_mode,           0, AQ_MODE_COUNT - 1);
-  RANGE_CHECK(extra_cfg, frame_periodic_boost, 0, 1);
-  RANGE_CHECK_HI(cfg, g_threads,          64);
-  RANGE_CHECK_HI(cfg, g_lag_in_frames,    MAX_LAG_BUFFERS);
-  RANGE_CHECK(cfg, rc_end_usage,          VPX_VBR, VPX_Q);
-  RANGE_CHECK_HI(cfg, rc_undershoot_pct,  100);
-  RANGE_CHECK_HI(cfg, rc_overshoot_pct,   100);
-  RANGE_CHECK_HI(cfg, rc_2pass_vbr_bias_pct, 100);
-  RANGE_CHECK(cfg, kf_mode,               VPX_KF_DISABLED, VPX_KF_AUTO);
-  RANGE_CHECK_BOOL(cfg,                   rc_resize_allowed);
-  RANGE_CHECK_HI(cfg, rc_dropframe_thresh,   100);
-  RANGE_CHECK_HI(cfg, rc_resize_up_thresh,   100);
-  RANGE_CHECK_HI(cfg, rc_resize_down_thresh, 100);
-  RANGE_CHECK(cfg,        g_pass,         VPX_RC_ONE_PASS, VPX_RC_LAST_PASS);
-  RANGE_CHECK(extra_cfg, min_gf_interval, 0, (MAX_LAG_BUFFERS - 1));
-  RANGE_CHECK(extra_cfg, max_gf_interval, 0, (MAX_LAG_BUFFERS - 1));
-  if (extra_cfg->max_gf_interval > 0) {
-    RANGE_CHECK(extra_cfg, max_gf_interval, 2, (MAX_LAG_BUFFERS - 1));
-  }
-  if (extra_cfg->min_gf_interval > 0 && extra_cfg->max_gf_interval > 0) {
-    RANGE_CHECK(extra_cfg, max_gf_interval, extra_cfg->min_gf_interval,
-      (MAX_LAG_BUFFERS - 1));
-  }
-
-  if (cfg->rc_resize_allowed == 1) {
-    RANGE_CHECK(cfg, rc_scaled_width, 0, cfg->g_w);
-    RANGE_CHECK(cfg, rc_scaled_height, 0, cfg->g_h);
-  }
-
-  RANGE_CHECK(cfg, ss_number_layers, 1, VPX_SS_MAX_LAYERS);
-  RANGE_CHECK(cfg, ts_number_layers, 1, VPX_TS_MAX_LAYERS);
-
-  {
-    unsigned int level = extra_cfg->target_level;
-    if (level != LEVEL_1 && level != LEVEL_1_1 && level != LEVEL_2 &&
-        level != LEVEL_2_1 && level != LEVEL_3 && level != LEVEL_3_1 &&
-        level != LEVEL_4 && level != LEVEL_4_1 && level != LEVEL_5 &&
-        level != LEVEL_5_1 && level != LEVEL_5_2 && level != LEVEL_6 &&
-        level != LEVEL_6_1 && level != LEVEL_6_2 &&
-        level != LEVEL_UNKNOWN && level != LEVEL_MAX)
-    ERROR("target_level is invalid");
-  }
-
-  if (cfg->ss_number_layers * cfg->ts_number_layers > VPX_MAX_LAYERS)
-    ERROR("ss_number_layers * ts_number_layers is out of range");
-  if (cfg->ts_number_layers > 1) {
-    unsigned int sl, tl;
-    for (sl = 1; sl < cfg->ss_number_layers; ++sl) {
-      for (tl = 1; tl < cfg->ts_number_layers; ++tl) {
-        const int layer =
-            LAYER_IDS_TO_IDX(sl, tl, cfg->ts_number_layers);
-        if (cfg->layer_target_bitrate[layer] <
-            cfg->layer_target_bitrate[layer - 1])
-        ERROR("ts_target_bitrate entries are not increasing");
-      }
-    }
-
-    RANGE_CHECK(cfg, ts_rate_decimator[cfg->ts_number_layers - 1], 1, 1);
-    for (tl = cfg->ts_number_layers - 2; tl > 0; --tl)
-      if (cfg->ts_rate_decimator[tl - 1] != 2 * cfg->ts_rate_decimator[tl])
-        ERROR("ts_rate_decimator factors are not powers of 2");
-  }
-
-#if CONFIG_SPATIAL_SVC
-
-  if ((cfg->ss_number_layers > 1 || cfg->ts_number_layers > 1) &&
-      cfg->g_pass == VPX_RC_LAST_PASS) {
-    unsigned int i, alt_ref_sum = 0;
-    for (i = 0; i < cfg->ss_number_layers; ++i) {
-      if (cfg->ss_enable_auto_alt_ref[i])
-        ++alt_ref_sum;
-    }
-    if (alt_ref_sum > REF_FRAMES - cfg->ss_number_layers)
-      ERROR("Not enough ref buffers for svc alt ref frames");
-    if (cfg->ss_number_layers * cfg->ts_number_layers > 3 &&
-        cfg->g_error_resilient == 0)
-    ERROR("Multiple frame context are not supported for more than 3 layers");
-  }
-#endif
-
-  // VP9 does not support a lower bound on the keyframe interval in
-  // automatic keyframe placement mode.
-  if (cfg->kf_mode != VPX_KF_DISABLED &&
-      cfg->kf_min_dist != cfg->kf_max_dist &&
-      cfg->kf_min_dist > 0)
-    ERROR("kf_min_dist not supported in auto mode, use 0 "
-          "or kf_max_dist instead.");
-
-  RANGE_CHECK(extra_cfg, enable_auto_alt_ref, 0, 2);
-  RANGE_CHECK(extra_cfg, cpu_used, -8, 8);
-  RANGE_CHECK_HI(extra_cfg, noise_sensitivity, 6);
-  RANGE_CHECK(extra_cfg, tile_columns, 0, 6);
-  RANGE_CHECK(extra_cfg, tile_rows, 0, 2);
-  RANGE_CHECK_HI(extra_cfg, sharpness, 7);
-  RANGE_CHECK(extra_cfg, arnr_max_frames, 0, 15);
-  RANGE_CHECK_HI(extra_cfg, arnr_strength, 6);
-  RANGE_CHECK(extra_cfg, cq_level, 0, 63);
-  RANGE_CHECK(cfg, g_bit_depth, VPX_BITS_8, VPX_BITS_12);
-  RANGE_CHECK(cfg, g_input_bit_depth, 8, 12);
-  RANGE_CHECK(extra_cfg, content,
-              VP9E_CONTENT_DEFAULT, VP9E_CONTENT_INVALID - 1);
-
-  // TODO(yaowu): remove this when ssim tuning is implemented for vp9
-  if (extra_cfg->tuning == VP8_TUNE_SSIM)
-      ERROR("Option --tune=ssim is not currently supported in VP9.");
-
-  if (cfg->g_pass == VPX_RC_LAST_PASS) {
-    const size_t packet_sz = sizeof(FIRSTPASS_STATS);
-    const int n_packets = (int)(cfg->rc_twopass_stats_in.sz / packet_sz);
-    const FIRSTPASS_STATS *stats;
-
-    if (cfg->rc_twopass_stats_in.buf == NULL)
-      ERROR("rc_twopass_stats_in.buf not set.");
-
-    if (cfg->rc_twopass_stats_in.sz % packet_sz)
-      ERROR("rc_twopass_stats_in.sz indicates truncated packet.");
-
-    if (cfg->ss_number_layers > 1 || cfg->ts_number_layers > 1) {
-      int i;
-      unsigned int n_packets_per_layer[VPX_SS_MAX_LAYERS] = {0};
-
-      stats = cfg->rc_twopass_stats_in.buf;
-      for (i = 0; i < n_packets; ++i) {
-        const int layer_id = (int)stats[i].spatial_layer_id;
-        if (layer_id >= 0 && layer_id < (int)cfg->ss_number_layers) {
-          ++n_packets_per_layer[layer_id];
-        }
-      }
-
-      for (i = 0; i < (int)cfg->ss_number_layers; ++i) {
-        unsigned int layer_id;
-        if (n_packets_per_layer[i] < 2) {
-          ERROR("rc_twopass_stats_in requires at least two packets for each "
-                "layer.");
-        }
-
-        stats = (const FIRSTPASS_STATS *)cfg->rc_twopass_stats_in.buf +
-                n_packets - cfg->ss_number_layers + i;
-        layer_id = (int)stats->spatial_layer_id;
-
-        if (layer_id >= cfg->ss_number_layers
-            ||(unsigned int)(stats->count + 0.5) !=
-               n_packets_per_layer[layer_id] - 1)
-          ERROR("rc_twopass_stats_in missing EOS stats packet");
-      }
-    } else {
-      if (cfg->rc_twopass_stats_in.sz < 2 * packet_sz)
-        ERROR("rc_twopass_stats_in requires at least two packets.");
-
-      stats =
-          (const FIRSTPASS_STATS *)cfg->rc_twopass_stats_in.buf + n_packets - 1;
-
-      if ((int)(stats->count + 0.5) != n_packets - 1)
-        ERROR("rc_twopass_stats_in missing EOS stats packet");
-    }
-  }
-
-#if !CONFIG_VP9_HIGHBITDEPTH
-  if (cfg->g_profile > (unsigned int)PROFILE_1) {
-    ERROR("Profile > 1 not supported in this build configuration");
-  }
-#endif
-  if (cfg->g_profile <= (unsigned int)PROFILE_1 &&
-      cfg->g_bit_depth > VPX_BITS_8) {
-    ERROR("Codec high bit-depth not supported in profile < 2");
-  }
-  if (cfg->g_profile <= (unsigned int)PROFILE_1 &&
-      cfg->g_input_bit_depth > 8) {
-    ERROR("Source high bit-depth not supported in profile < 2");
-  }
-  if (cfg->g_profile > (unsigned int)PROFILE_1 &&
-      cfg->g_bit_depth == VPX_BITS_8) {
-    ERROR("Codec bit-depth 8 not supported in profile > 1");
-  }
-  RANGE_CHECK(extra_cfg, color_space, VPX_CS_UNKNOWN, VPX_CS_SRGB);
-  RANGE_CHECK(extra_cfg, color_range,
-              VPX_CR_STUDIO_RANGE, VPX_CR_FULL_RANGE);
-  return VPX_CODEC_OK;
-}
-
-static vpx_codec_err_t validate_img(vpx_codec_alg_priv_t *ctx,
-                                    const vpx_image_t *img) {
-  switch (img->fmt) {
-    case VPX_IMG_FMT_YV12:
-    case VPX_IMG_FMT_I420:
-    case VPX_IMG_FMT_I42016:
-      break;
-    case VPX_IMG_FMT_I422:
-    case VPX_IMG_FMT_I444:
-    case VPX_IMG_FMT_I440:
-      if (ctx->cfg.g_profile != (unsigned int)PROFILE_1) {
-        ERROR("Invalid image format. I422, I444, I440 images are "
-              "not supported in profile.");
-      }
-      break;
-    case VPX_IMG_FMT_I42216:
-    case VPX_IMG_FMT_I44416:
-    case VPX_IMG_FMT_I44016:
-      if (ctx->cfg.g_profile != (unsigned int)PROFILE_1 &&
-          ctx->cfg.g_profile != (unsigned int)PROFILE_3) {
-        ERROR("Invalid image format. 16-bit I422, I444, I440 images are "
-              "not supported in profile.");
-      }
-      break;
-    default:
-      ERROR("Invalid image format. Only YV12, I420, I422, I444 images are "
-            "supported.");
-      break;
-  }
-
-  if (img->d_w != ctx->cfg.g_w || img->d_h != ctx->cfg.g_h)
-    ERROR("Image size must match encoder init configuration size");
-
-  return VPX_CODEC_OK;
-}
-
-static int get_image_bps(const vpx_image_t *img) {
-  switch (img->fmt) {
-    case VPX_IMG_FMT_YV12:
-    case VPX_IMG_FMT_I420: return 12;
-    case VPX_IMG_FMT_I422: return 16;
-    case VPX_IMG_FMT_I444: return 24;
-    case VPX_IMG_FMT_I440: return 16;
-    case VPX_IMG_FMT_I42016: return 24;
-    case VPX_IMG_FMT_I42216: return 32;
-    case VPX_IMG_FMT_I44416: return 48;
-    case VPX_IMG_FMT_I44016: return 32;
-    default: assert(0 && "Invalid image format"); break;
-  }
-  return 0;
-}
-
-static vpx_codec_err_t set_encoder_config(
-  VP9EncoderConfig *oxcf,
-  const vpx_codec_enc_cfg_t *cfg,
-  const struct vp9_extracfg *extra_cfg) {
-  const int is_vbr = cfg->rc_end_usage == VPX_VBR;
-  int sl, tl;
-  oxcf->profile = cfg->g_profile;
-  oxcf->max_threads = (int)cfg->g_threads;
-  oxcf->width   = cfg->g_w;
-  oxcf->height  = cfg->g_h;
-  oxcf->bit_depth = cfg->g_bit_depth;
-  oxcf->input_bit_depth = cfg->g_input_bit_depth;
-  // guess a frame rate if out of whack, use 30
-  oxcf->init_framerate = (double)cfg->g_timebase.den / cfg->g_timebase.num;
-  if (oxcf->init_framerate > 180)
-    oxcf->init_framerate = 30;
-
-  oxcf->mode = GOOD;
-
-  switch (cfg->g_pass) {
-    case VPX_RC_ONE_PASS:
-      oxcf->pass = 0;
-      break;
-    case VPX_RC_FIRST_PASS:
-      oxcf->pass = 1;
-      break;
-    case VPX_RC_LAST_PASS:
-      oxcf->pass = 2;
-      break;
-  }
-
-  oxcf->lag_in_frames = cfg->g_pass == VPX_RC_FIRST_PASS ? 0
-                                                         : cfg->g_lag_in_frames;
-  oxcf->rc_mode = cfg->rc_end_usage;
-
-  // Convert target bandwidth from Kbit/s to Bit/s
-  oxcf->target_bandwidth = 1000 * cfg->rc_target_bitrate;
-  oxcf->rc_max_intra_bitrate_pct = extra_cfg->rc_max_intra_bitrate_pct;
-  oxcf->rc_max_inter_bitrate_pct = extra_cfg->rc_max_inter_bitrate_pct;
-  oxcf->gf_cbr_boost_pct = extra_cfg->gf_cbr_boost_pct;
-
-  oxcf->best_allowed_q =
-      extra_cfg->lossless ? 0 : vp9_quantizer_to_qindex(cfg->rc_min_quantizer);
-  oxcf->worst_allowed_q =
-      extra_cfg->lossless ? 0 : vp9_quantizer_to_qindex(cfg->rc_max_quantizer);
-  oxcf->cq_level        = vp9_quantizer_to_qindex(extra_cfg->cq_level);
-  oxcf->fixed_q = -1;
-
-  oxcf->under_shoot_pct         = cfg->rc_undershoot_pct;
-  oxcf->over_shoot_pct          = cfg->rc_overshoot_pct;
-
-  oxcf->scaled_frame_width  = cfg->rc_scaled_width;
-  oxcf->scaled_frame_height = cfg->rc_scaled_height;
-  if (cfg->rc_resize_allowed == 1) {
-    oxcf->resize_mode =
-        (oxcf->scaled_frame_width == 0 || oxcf->scaled_frame_height == 0) ?
-            RESIZE_DYNAMIC : RESIZE_FIXED;
-  } else {
-    oxcf->resize_mode = RESIZE_NONE;
-  }
-
-  oxcf->maximum_buffer_size_ms   = is_vbr ? 240000 : cfg->rc_buf_sz;
-  oxcf->starting_buffer_level_ms = is_vbr ? 60000 : cfg->rc_buf_initial_sz;
-  oxcf->optimal_buffer_level_ms  = is_vbr ? 60000 : cfg->rc_buf_optimal_sz;
-
-  oxcf->drop_frames_water_mark   = cfg->rc_dropframe_thresh;
-
-  oxcf->two_pass_vbrbias         = cfg->rc_2pass_vbr_bias_pct;
-  oxcf->two_pass_vbrmin_section  = cfg->rc_2pass_vbr_minsection_pct;
-  oxcf->two_pass_vbrmax_section  = cfg->rc_2pass_vbr_maxsection_pct;
-
-  oxcf->auto_key               = cfg->kf_mode == VPX_KF_AUTO &&
-                                 cfg->kf_min_dist != cfg->kf_max_dist;
-
-  oxcf->key_freq               = cfg->kf_max_dist;
-
-  oxcf->speed                  =  abs(extra_cfg->cpu_used);
-  oxcf->encode_breakout        =  extra_cfg->static_thresh;
-  oxcf->enable_auto_arf        =  extra_cfg->enable_auto_alt_ref;
-  oxcf->noise_sensitivity      =  extra_cfg->noise_sensitivity;
-  oxcf->sharpness              =  extra_cfg->sharpness;
-
-  oxcf->two_pass_stats_in      =  cfg->rc_twopass_stats_in;
-
-#if CONFIG_FP_MB_STATS
-  oxcf->firstpass_mb_stats_in  = cfg->rc_firstpass_mb_stats_in;
-#endif
-
-  oxcf->color_space = extra_cfg->color_space;
-  oxcf->color_range = extra_cfg->color_range;
-  oxcf->render_width  = extra_cfg->render_width;
-  oxcf->render_height = extra_cfg->render_height;
-  oxcf->arnr_max_frames = extra_cfg->arnr_max_frames;
-  oxcf->arnr_strength   = extra_cfg->arnr_strength;
-  oxcf->min_gf_interval = extra_cfg->min_gf_interval;
-  oxcf->max_gf_interval = extra_cfg->max_gf_interval;
-
-  oxcf->tuning = extra_cfg->tuning;
-  oxcf->content = extra_cfg->content;
-
-  oxcf->tile_columns = extra_cfg->tile_columns;
-
-  // TODO(yunqing): The dependencies between row tiles cause error in multi-
-  // threaded encoding. For now, tile_rows is forced to be 0 in this case.
-  // The further fix can be done by adding synchronizations after a tile row
-  // is encoded. But this will hurt multi-threaded encoder performance. So,
-  // it is recommended to use tile-rows=0 while encoding with threads > 1.
-  if (oxcf->max_threads > 1 && oxcf->tile_columns > 0)
-    oxcf->tile_rows  = 0;
-  else
-    oxcf->tile_rows  = extra_cfg->tile_rows;
-
-  oxcf->error_resilient_mode         = cfg->g_error_resilient;
-  oxcf->frame_parallel_decoding_mode = extra_cfg->frame_parallel_decoding_mode;
-
-  oxcf->aq_mode = extra_cfg->aq_mode;
-
-  oxcf->frame_periodic_boost =  extra_cfg->frame_periodic_boost;
-
-  oxcf->ss_number_layers = cfg->ss_number_layers;
-  oxcf->ts_number_layers = cfg->ts_number_layers;
-  oxcf->temporal_layering_mode = (enum vp9e_temporal_layering_mode)
-      cfg->temporal_layering_mode;
-
-  oxcf->target_level = extra_cfg->target_level;
-
-  for (sl = 0; sl < oxcf->ss_number_layers; ++sl) {
-#if CONFIG_SPATIAL_SVC
-    oxcf->ss_enable_auto_arf[sl] = cfg->ss_enable_auto_alt_ref[sl];
-#endif
-    for (tl = 0; tl < oxcf->ts_number_layers; ++tl) {
-      oxcf->layer_target_bitrate[sl * oxcf->ts_number_layers + tl] =
-          1000 * cfg->layer_target_bitrate[sl * oxcf->ts_number_layers + tl];
-    }
-  }
-  if (oxcf->ss_number_layers == 1 && oxcf->pass != 0) {
-    oxcf->ss_target_bitrate[0] = (int)oxcf->target_bandwidth;
-#if CONFIG_SPATIAL_SVC
-    oxcf->ss_enable_auto_arf[0] = extra_cfg->enable_auto_alt_ref;
-#endif
-  }
-  if (oxcf->ts_number_layers > 1) {
-    for (tl = 0; tl < VPX_TS_MAX_LAYERS; ++tl) {
-      oxcf->ts_rate_decimator[tl] = cfg->ts_rate_decimator[tl] ?
-          cfg->ts_rate_decimator[tl] : 1;
-    }
-  } else if (oxcf->ts_number_layers == 1) {
-    oxcf->ts_rate_decimator[0] = 1;
-  }
-  /*
-  printf("Current VP9 Settings: \n");
-  printf("target_bandwidth: %d\n", oxcf->target_bandwidth);
-  printf("target_level: %d\n", oxcf->target_level);
-  printf("noise_sensitivity: %d\n", oxcf->noise_sensitivity);
-  printf("sharpness: %d\n",    oxcf->sharpness);
-  printf("cpu_used: %d\n",  oxcf->cpu_used);
-  printf("Mode: %d\n",     oxcf->mode);
-  printf("auto_key: %d\n",  oxcf->auto_key);
-  printf("key_freq: %d\n", oxcf->key_freq);
-  printf("end_usage: %d\n", oxcf->end_usage);
-  printf("under_shoot_pct: %d\n", oxcf->under_shoot_pct);
-  printf("over_shoot_pct: %d\n", oxcf->over_shoot_pct);
-  printf("starting_buffer_level: %d\n", oxcf->starting_buffer_level);
-  printf("optimal_buffer_level: %d\n",  oxcf->optimal_buffer_level);
-  printf("maximum_buffer_size: %d\n", oxcf->maximum_buffer_size);
-  printf("fixed_q: %d\n",  oxcf->fixed_q);
-  printf("worst_allowed_q: %d\n", oxcf->worst_allowed_q);
-  printf("best_allowed_q: %d\n", oxcf->best_allowed_q);
-  printf("allow_spatial_resampling: %d\n", oxcf->allow_spatial_resampling);
-  printf("scaled_frame_width: %d\n", oxcf->scaled_frame_width);
-  printf("scaled_frame_height: %d\n", oxcf->scaled_frame_height);
-  printf("two_pass_vbrbias: %d\n",  oxcf->two_pass_vbrbias);
-  printf("two_pass_vbrmin_section: %d\n", oxcf->two_pass_vbrmin_section);
-  printf("two_pass_vbrmax_section: %d\n", oxcf->two_pass_vbrmax_section);
-  printf("lag_in_frames: %d\n", oxcf->lag_in_frames);
-  printf("enable_auto_arf: %d\n", oxcf->enable_auto_arf);
-  printf("Version: %d\n", oxcf->Version);
-  printf("encode_breakout: %d\n", oxcf->encode_breakout);
-  printf("error resilient: %d\n", oxcf->error_resilient_mode);
-  printf("frame parallel detokenization: %d\n",
-         oxcf->frame_parallel_decoding_mode);
-  */
-  return VPX_CODEC_OK;
-}
-
-static vpx_codec_err_t encoder_set_config(vpx_codec_alg_priv_t *ctx,
-                                          const vpx_codec_enc_cfg_t  *cfg) {
-  vpx_codec_err_t res;
-  int force_key = 0;
-
-  if (cfg->g_w != ctx->cfg.g_w || cfg->g_h != ctx->cfg.g_h) {
-    if (cfg->g_lag_in_frames > 1 || cfg->g_pass != VPX_RC_ONE_PASS)
-      ERROR("Cannot change width or height after initialization");
-    if (!valid_ref_frame_size(ctx->cfg.g_w, ctx->cfg.g_h, cfg->g_w, cfg->g_h) ||
-        (ctx->cpi->initial_width && (int)cfg->g_w > ctx->cpi->initial_width) ||
-        (ctx->cpi->initial_height && (int)cfg->g_h > ctx->cpi->initial_height))
-      force_key = 1;
-  }
-
-  // Prevent increasing lag_in_frames. This check is stricter than it needs
-  // to be -- the limit is not increasing past the first lag_in_frames
-  // value, but we don't track the initial config, only the last successful
-  // config.
-  if (cfg->g_lag_in_frames > ctx->cfg.g_lag_in_frames)
-    ERROR("Cannot increase lag_in_frames");
-
-  res = validate_config(ctx, cfg, &ctx->extra_cfg);
-
-  if (res == VPX_CODEC_OK) {
-    ctx->cfg = *cfg;
-    set_encoder_config(&ctx->oxcf, &ctx->cfg, &ctx->extra_cfg);
-    // On profile change, request a key frame
-    force_key |= ctx->cpi->common.profile != ctx->oxcf.profile;
-    vp9_change_config(ctx->cpi, &ctx->oxcf);
-  }
-
-  if (force_key)
-    ctx->next_frame_flags |= VPX_EFLAG_FORCE_KF;
-
-  return res;
-}
-
-static vpx_codec_err_t ctrl_get_quantizer(vpx_codec_alg_priv_t *ctx,
-                                          va_list args) {
-  int *const arg = va_arg(args, int *);
-  if (arg == NULL)
-    return VPX_CODEC_INVALID_PARAM;
-  *arg = vp9_get_quantizer(ctx->cpi);
-  return VPX_CODEC_OK;
-}
-
-static vpx_codec_err_t ctrl_get_quantizer64(vpx_codec_alg_priv_t *ctx,
-                                            va_list args) {
-  int *const arg = va_arg(args, int *);
-  if (arg == NULL)
-    return VPX_CODEC_INVALID_PARAM;
-  *arg = vp9_qindex_to_quantizer(vp9_get_quantizer(ctx->cpi));
-  return VPX_CODEC_OK;
-}
-
-static vpx_codec_err_t update_extra_cfg(vpx_codec_alg_priv_t *ctx,
-                                        const struct vp9_extracfg *extra_cfg) {
-  const vpx_codec_err_t res = validate_config(ctx, &ctx->cfg, extra_cfg);
-  if (res == VPX_CODEC_OK) {
-    ctx->extra_cfg = *extra_cfg;
-    set_encoder_config(&ctx->oxcf, &ctx->cfg, &ctx->extra_cfg);
-    vp9_change_config(ctx->cpi, &ctx->oxcf);
-  }
-  return res;
-}
-
-static vpx_codec_err_t ctrl_set_cpuused(vpx_codec_alg_priv_t *ctx,
-                                        va_list args) {
-  struct vp9_extracfg extra_cfg = ctx->extra_cfg;
-  extra_cfg.cpu_used = CAST(VP8E_SET_CPUUSED, args);
-  return update_extra_cfg(ctx, &extra_cfg);
-}
-
-static vpx_codec_err_t ctrl_set_enable_auto_alt_ref(vpx_codec_alg_priv_t *ctx,
-                                                    va_list args) {
-  struct vp9_extracfg extra_cfg = ctx->extra_cfg;
-  extra_cfg.enable_auto_alt_ref = CAST(VP8E_SET_ENABLEAUTOALTREF, args);
-  return update_extra_cfg(ctx, &extra_cfg);
-}
-
-static vpx_codec_err_t ctrl_set_noise_sensitivity(vpx_codec_alg_priv_t *ctx,
-                                                  va_list args) {
-  struct vp9_extracfg extra_cfg = ctx->extra_cfg;
-  extra_cfg.noise_sensitivity = CAST(VP9E_SET_NOISE_SENSITIVITY, args);
-  return update_extra_cfg(ctx, &extra_cfg);
-}
-
-static vpx_codec_err_t ctrl_set_sharpness(vpx_codec_alg_priv_t *ctx,
-                                          va_list args) {
-  struct vp9_extracfg extra_cfg = ctx->extra_cfg;
-  extra_cfg.sharpness = CAST(VP8E_SET_SHARPNESS, args);
-  return update_extra_cfg(ctx, &extra_cfg);
-}
-
-static vpx_codec_err_t ctrl_set_static_thresh(vpx_codec_alg_priv_t *ctx,
-                                              va_list args) {
-  struct vp9_extracfg extra_cfg = ctx->extra_cfg;
-  extra_cfg.static_thresh = CAST(VP8E_SET_STATIC_THRESHOLD, args);
-  return update_extra_cfg(ctx, &extra_cfg);
-}
-
-static vpx_codec_err_t ctrl_set_tile_columns(vpx_codec_alg_priv_t *ctx,
-                                             va_list args) {
-  struct vp9_extracfg extra_cfg = ctx->extra_cfg;
-  extra_cfg.tile_columns = CAST(VP9E_SET_TILE_COLUMNS, args);
-  return update_extra_cfg(ctx, &extra_cfg);
-}
-
-static vpx_codec_err_t ctrl_set_tile_rows(vpx_codec_alg_priv_t *ctx,
-                                          va_list args) {
-  struct vp9_extracfg extra_cfg = ctx->extra_cfg;
-  extra_cfg.tile_rows = CAST(VP9E_SET_TILE_ROWS, args);
-  return update_extra_cfg(ctx, &extra_cfg);
-}
-
-static vpx_codec_err_t ctrl_set_arnr_max_frames(vpx_codec_alg_priv_t *ctx,
-                                                va_list args) {
-  struct vp9_extracfg extra_cfg = ctx->extra_cfg;
-  extra_cfg.arnr_max_frames = CAST(VP8E_SET_ARNR_MAXFRAMES, args);
-  return update_extra_cfg(ctx, &extra_cfg);
-}
-
-static vpx_codec_err_t ctrl_set_arnr_strength(vpx_codec_alg_priv_t *ctx,
-                                              va_list args) {
-  struct vp9_extracfg extra_cfg = ctx->extra_cfg;
-  extra_cfg.arnr_strength = CAST(VP8E_SET_ARNR_STRENGTH, args);
-  return update_extra_cfg(ctx, &extra_cfg);
-}
-
-static vpx_codec_err_t ctrl_set_arnr_type(vpx_codec_alg_priv_t *ctx,
-                                          va_list args) {
-  (void)ctx;
-  (void)args;
-  return VPX_CODEC_OK;
-}
-
-static vpx_codec_err_t ctrl_set_tuning(vpx_codec_alg_priv_t *ctx,
-                                       va_list args) {
-  struct vp9_extracfg extra_cfg = ctx->extra_cfg;
-  extra_cfg.tuning = CAST(VP8E_SET_TUNING, args);
-  return update_extra_cfg(ctx, &extra_cfg);
-}
-
-static vpx_codec_err_t ctrl_set_cq_level(vpx_codec_alg_priv_t *ctx,
-                                         va_list args) {
-  struct vp9_extracfg extra_cfg = ctx->extra_cfg;
-  extra_cfg.cq_level = CAST(VP8E_SET_CQ_LEVEL, args);
-  return update_extra_cfg(ctx, &extra_cfg);
-}
-
-static vpx_codec_err_t ctrl_set_rc_max_intra_bitrate_pct(
-    vpx_codec_alg_priv_t *ctx, va_list args) {
-  struct vp9_extracfg extra_cfg = ctx->extra_cfg;
-  extra_cfg.rc_max_intra_bitrate_pct =
-      CAST(VP8E_SET_MAX_INTRA_BITRATE_PCT, args);
-  return update_extra_cfg(ctx, &extra_cfg);
-}
-
-static vpx_codec_err_t ctrl_set_rc_max_inter_bitrate_pct(
-    vpx_codec_alg_priv_t *ctx, va_list args) {
-  struct vp9_extracfg extra_cfg = ctx->extra_cfg;
-  extra_cfg.rc_max_inter_bitrate_pct =
-      CAST(VP8E_SET_MAX_INTER_BITRATE_PCT, args);
-  return update_extra_cfg(ctx, &extra_cfg);
-}
-
-static vpx_codec_err_t ctrl_set_rc_gf_cbr_boost_pct(
-    vpx_codec_alg_priv_t *ctx, va_list args) {
-  struct vp9_extracfg extra_cfg = ctx->extra_cfg;
-  extra_cfg.gf_cbr_boost_pct =
-      CAST(VP9E_SET_GF_CBR_BOOST_PCT, args);
-  return update_extra_cfg(ctx, &extra_cfg);
-}
-
-static vpx_codec_err_t ctrl_set_lossless(vpx_codec_alg_priv_t *ctx,
-                                         va_list args) {
-  struct vp9_extracfg extra_cfg = ctx->extra_cfg;
-  extra_cfg.lossless = CAST(VP9E_SET_LOSSLESS, args);
-  return update_extra_cfg(ctx, &extra_cfg);
-}
-
-static vpx_codec_err_t ctrl_set_frame_parallel_decoding_mode(
-    vpx_codec_alg_priv_t *ctx, va_list args) {
-  struct vp9_extracfg extra_cfg = ctx->extra_cfg;
-  extra_cfg.frame_parallel_decoding_mode =
-      CAST(VP9E_SET_FRAME_PARALLEL_DECODING, args);
-  return update_extra_cfg(ctx, &extra_cfg);
-}
-
-static vpx_codec_err_t ctrl_set_aq_mode(vpx_codec_alg_priv_t *ctx,
-                                        va_list args) {
-  struct vp9_extracfg extra_cfg = ctx->extra_cfg;
-  extra_cfg.aq_mode = CAST(VP9E_SET_AQ_MODE, args);
-  return update_extra_cfg(ctx, &extra_cfg);
-}
-
-static vpx_codec_err_t ctrl_set_min_gf_interval(vpx_codec_alg_priv_t *ctx,
-                                                va_list args) {
-  struct vp9_extracfg extra_cfg = ctx->extra_cfg;
-  extra_cfg.min_gf_interval = CAST(VP9E_SET_MIN_GF_INTERVAL, args);
-  return update_extra_cfg(ctx, &extra_cfg);
-}
-
-static vpx_codec_err_t ctrl_set_max_gf_interval(vpx_codec_alg_priv_t *ctx,
-                                                va_list args) {
-  struct vp9_extracfg extra_cfg = ctx->extra_cfg;
-  extra_cfg.max_gf_interval = CAST(VP9E_SET_MAX_GF_INTERVAL, args);
-  return update_extra_cfg(ctx, &extra_cfg);
-}
-
-static vpx_codec_err_t ctrl_set_frame_periodic_boost(vpx_codec_alg_priv_t *ctx,
-                                                     va_list args) {
-  struct vp9_extracfg extra_cfg = ctx->extra_cfg;
-  extra_cfg.frame_periodic_boost = CAST(VP9E_SET_FRAME_PERIODIC_BOOST, args);
-  return update_extra_cfg(ctx, &extra_cfg);
-}
-
-static vpx_codec_err_t ctrl_set_target_level(vpx_codec_alg_priv_t *ctx,
-                                             va_list args) {
-  struct vp9_extracfg extra_cfg = ctx->extra_cfg;
-  extra_cfg.target_level = CAST(VP9E_SET_TARGET_LEVEL, args);
-  return update_extra_cfg(ctx, &extra_cfg);
-}
-
-static vpx_codec_err_t ctrl_get_level(vpx_codec_alg_priv_t *ctx, va_list args) {
-  int *const arg = va_arg(args, int *);
-  if (arg == NULL) return VPX_CODEC_INVALID_PARAM;
-  *arg = (int)vp9_get_level(&ctx->cpi->level_info.level_spec);
-  return VPX_CODEC_OK;
-}
-
-static vpx_codec_err_t encoder_init(vpx_codec_ctx_t *ctx,
-                                    vpx_codec_priv_enc_mr_cfg_t *data) {
-  vpx_codec_err_t res = VPX_CODEC_OK;
-  (void)data;
-
-  if (ctx->priv == NULL) {
-    vpx_codec_alg_priv_t *const priv = vpx_calloc(1, sizeof(*priv));
-    if (priv == NULL)
-      return VPX_CODEC_MEM_ERROR;
-
-    ctx->priv = (vpx_codec_priv_t *)priv;
-    ctx->priv->init_flags = ctx->init_flags;
-    ctx->priv->enc.total_encoders = 1;
-    priv->buffer_pool =
-        (BufferPool *)vpx_calloc(1, sizeof(BufferPool));
-    if (priv->buffer_pool == NULL)
-      return VPX_CODEC_MEM_ERROR;
-
-#if CONFIG_MULTITHREAD
-    if (pthread_mutex_init(&priv->buffer_pool->pool_mutex, NULL)) {
-      return VPX_CODEC_MEM_ERROR;
-    }
-#endif
-
-    if (ctx->config.enc) {
-      // Update the reference to the config structure to an internal copy.
-      priv->cfg = *ctx->config.enc;
-      ctx->config.enc = &priv->cfg;
-    }
-
-    priv->extra_cfg = default_extra_cfg;
-    once(vp9_initialize_enc);
-
-    res = validate_config(priv, &priv->cfg, &priv->extra_cfg);
-
-    if (res == VPX_CODEC_OK) {
-      set_encoder_config(&priv->oxcf, &priv->cfg, &priv->extra_cfg);
-#if CONFIG_VP9_HIGHBITDEPTH
-      priv->oxcf.use_highbitdepth =
-          (ctx->init_flags & VPX_CODEC_USE_HIGHBITDEPTH) ? 1 : 0;
-#endif
-      priv->cpi = vp9_create_compressor(&priv->oxcf, priv->buffer_pool);
-      if (priv->cpi == NULL)
-        res = VPX_CODEC_MEM_ERROR;
-      else
-        priv->cpi->output_pkt_list = &priv->pkt_list.head;
-    }
-  }
-
-  return res;
-}
-
-static vpx_codec_err_t encoder_destroy(vpx_codec_alg_priv_t *ctx) {
-  free(ctx->cx_data);
-  vp9_remove_compressor(ctx->cpi);
-#if CONFIG_MULTITHREAD
-  pthread_mutex_destroy(&ctx->buffer_pool->pool_mutex);
-#endif
-  vpx_free(ctx->buffer_pool);
-  vpx_free(ctx);
-  return VPX_CODEC_OK;
-}
-
-static void pick_quickcompress_mode(vpx_codec_alg_priv_t *ctx,
-                                    unsigned long duration,
-                                    unsigned long deadline) {
-  MODE new_mode = BEST;
-
-  switch (ctx->cfg.g_pass) {
-    case VPX_RC_ONE_PASS:
-      if (deadline > 0) {
-        const vpx_codec_enc_cfg_t *const cfg = &ctx->cfg;
-
-        // Convert duration parameter from stream timebase to microseconds.
-        const uint64_t duration_us = (uint64_t)duration * 1000000 *
-           (uint64_t)cfg->g_timebase.num /(uint64_t)cfg->g_timebase.den;
-
-        // If the deadline is more that the duration this frame is to be shown,
-        // use good quality mode. Otherwise use realtime mode.
-        new_mode = (deadline > duration_us) ? GOOD : REALTIME;
-      } else {
-        new_mode = BEST;
-      }
-      break;
-    case VPX_RC_FIRST_PASS:
-      break;
-    case VPX_RC_LAST_PASS:
-      new_mode = deadline > 0 ? GOOD : BEST;
-      break;
-  }
-
-  if (deadline == VPX_DL_REALTIME) {
-    ctx->oxcf.pass = 0;
-    new_mode = REALTIME;
-  }
-
-  if (ctx->oxcf.mode != new_mode) {
-    ctx->oxcf.mode = new_mode;
-    vp9_change_config(ctx->cpi, &ctx->oxcf);
-  }
-}
-
-// Turn on to test if supplemental superframe data breaks decoding
-// #define TEST_SUPPLEMENTAL_SUPERFRAME_DATA
-static int write_superframe_index(vpx_codec_alg_priv_t *ctx) {
-  uint8_t marker = 0xc0;
-  unsigned int mask;
-  int mag, index_sz;
-
-  assert(ctx->pending_frame_count);
-  assert(ctx->pending_frame_count <= 8);
-
-  // Add the number of frames to the marker byte
-  marker |= ctx->pending_frame_count - 1;
-
-  // Choose the magnitude
-  for (mag = 0, mask = 0xff; mag < 4; mag++) {
-    if (ctx->pending_frame_magnitude < mask)
-      break;
-    mask <<= 8;
-    mask |= 0xff;
-  }
-  marker |= mag << 3;
-
-  // Write the index
-  index_sz = 2 + (mag + 1) * ctx->pending_frame_count;
-  if (ctx->pending_cx_data_sz + index_sz < ctx->cx_data_sz) {
-    uint8_t *x = ctx->pending_cx_data + ctx->pending_cx_data_sz;
-    int i, j;
-#ifdef TEST_SUPPLEMENTAL_SUPERFRAME_DATA
-    uint8_t marker_test = 0xc0;
-    int mag_test = 2;     // 1 - 4
-    int frames_test = 4;  // 1 - 8
-    int index_sz_test = 2 + mag_test * frames_test;
-    marker_test |= frames_test - 1;
-    marker_test |= (mag_test - 1) << 3;
-    *x++ = marker_test;
-    for (i = 0; i < mag_test * frames_test; ++i)
-      *x++ = 0;  // fill up with arbitrary data
-    *x++ = marker_test;
-    ctx->pending_cx_data_sz += index_sz_test;
-    printf("Added supplemental superframe data\n");
-#endif
-
-    *x++ = marker;
-    for (i = 0; i < ctx->pending_frame_count; i++) {
-      unsigned int this_sz = (unsigned int)ctx->pending_frame_sizes[i];
-
-      for (j = 0; j <= mag; j++) {
-        *x++ = this_sz & 0xff;
-        this_sz >>= 8;
-      }
-    }
-    *x++ = marker;
-    ctx->pending_cx_data_sz += index_sz;
-#ifdef TEST_SUPPLEMENTAL_SUPERFRAME_DATA
-    index_sz += index_sz_test;
-#endif
-  }
-  return index_sz;
-}
-
-static int64_t timebase_units_to_ticks(const vpx_rational_t *timebase,
-                                       int64_t n) {
-  return n * TICKS_PER_SEC * timebase->num / timebase->den;
-}
-
-static int64_t ticks_to_timebase_units(const vpx_rational_t *timebase,
-                                       int64_t n) {
-  const int64_t round = (int64_t)TICKS_PER_SEC * timebase->num / 2 - 1;
-  return (n * timebase->den + round) / timebase->num / TICKS_PER_SEC;
-}
-
-static vpx_codec_frame_flags_t get_frame_pkt_flags(const VP9_COMP *cpi,
-                                                   unsigned int lib_flags) {
-  vpx_codec_frame_flags_t flags = lib_flags << 16;
-
-  if (lib_flags & FRAMEFLAGS_KEY ||
-      (cpi->use_svc &&
-          cpi->svc.layer_context[cpi->svc.spatial_layer_id *
-              cpi->svc.number_temporal_layers +
-              cpi->svc.temporal_layer_id].is_key_frame)
-     )
-    flags |= VPX_FRAME_IS_KEY;
-
-  if (cpi->droppable)
-    flags |= VPX_FRAME_IS_DROPPABLE;
-
-  return flags;
-}
-
-const size_t kMinCompressedSize = 8192;
-static vpx_codec_err_t encoder_encode(vpx_codec_alg_priv_t  *ctx,
-                                      const vpx_image_t *img,
-                                      vpx_codec_pts_t pts,
-                                      unsigned long duration,
-                                      vpx_enc_frame_flags_t enc_flags,
-                                      unsigned long deadline) {
-  volatile vpx_codec_err_t res = VPX_CODEC_OK;
-  volatile vpx_enc_frame_flags_t flags = enc_flags;
-  VP9_COMP *const cpi = ctx->cpi;
-  const vpx_rational_t *const timebase = &ctx->cfg.g_timebase;
-  size_t data_sz;
-
-  if (cpi == NULL) return VPX_CODEC_INVALID_PARAM;
-
-  if (img != NULL) {
-    res = validate_img(ctx, img);
-    if (res == VPX_CODEC_OK) {
-      // There's no codec control for multiple alt-refs so check the encoder
-      // instance for its status to determine the compressed data size.
-      data_sz = ctx->cfg.g_w * ctx->cfg.g_h * get_image_bps(img) / 8 *
-                (cpi->multi_arf_allowed ? 8 : 2);
-      if (data_sz < kMinCompressedSize)
-        data_sz = kMinCompressedSize;
-      if (ctx->cx_data == NULL || ctx->cx_data_sz < data_sz) {
-        ctx->cx_data_sz = data_sz;
-        free(ctx->cx_data);
-        ctx->cx_data = (unsigned char*)malloc(ctx->cx_data_sz);
-        if (ctx->cx_data == NULL) {
-          return VPX_CODEC_MEM_ERROR;
-        }
-      }
-    }
-  }
-
-  pick_quickcompress_mode(ctx, duration, deadline);
-  vpx_codec_pkt_list_init(&ctx->pkt_list);
-
-  // Handle Flags
-  if (((flags & VP8_EFLAG_NO_UPD_GF) && (flags & VP8_EFLAG_FORCE_GF)) ||
-       ((flags & VP8_EFLAG_NO_UPD_ARF) && (flags & VP8_EFLAG_FORCE_ARF))) {
-    ctx->base.err_detail = "Conflicting flags.";
-    return VPX_CODEC_INVALID_PARAM;
-  }
-
-  if (setjmp(cpi->common.error.jmp)) {
-    cpi->common.error.setjmp = 0;
-    res = update_error_state(ctx, &cpi->common.error);
-    vpx_clear_system_state();
-    return res;
-  }
-  cpi->common.error.setjmp = 1;
-
-  vp9_apply_encoding_flags(cpi, flags);
-
-  // Handle fixed keyframe intervals
-  if (ctx->cfg.kf_mode == VPX_KF_AUTO &&
-      ctx->cfg.kf_min_dist == ctx->cfg.kf_max_dist) {
-    if (++ctx->fixed_kf_cntr > ctx->cfg.kf_min_dist) {
-      flags |= VPX_EFLAG_FORCE_KF;
-      ctx->fixed_kf_cntr = 1;
-    }
-  }
-
-  if (res == VPX_CODEC_OK) {
-    unsigned int lib_flags = 0;
-    YV12_BUFFER_CONFIG sd;
-    int64_t dst_time_stamp = timebase_units_to_ticks(timebase, pts);
-    int64_t dst_end_time_stamp =
-        timebase_units_to_ticks(timebase, pts + duration);
-    size_t size, cx_data_sz;
-    unsigned char *cx_data;
-
-    // Set up internal flags
-    if (ctx->base.init_flags & VPX_CODEC_USE_PSNR)
-      cpi->b_calculate_psnr = 1;
-
-    if (img != NULL) {
-      res = image2yuvconfig(img, &sd);
-
-      // Store the original flags in to the frame buffer. Will extract the
-      // key frame flag when we actually encode this frame.
-      if (vp9_receive_raw_frame(cpi, flags | ctx->next_frame_flags,
-                                &sd, dst_time_stamp, dst_end_time_stamp)) {
-        res = update_error_state(ctx, &cpi->common.error);
-      }
-      ctx->next_frame_flags = 0;
-    }
-
-    cx_data = ctx->cx_data;
-    cx_data_sz = ctx->cx_data_sz;
-
-    /* Any pending invisible frames? */
-    if (ctx->pending_cx_data) {
-      memmove(cx_data, ctx->pending_cx_data, ctx->pending_cx_data_sz);
-      ctx->pending_cx_data = cx_data;
-      cx_data += ctx->pending_cx_data_sz;
-      cx_data_sz -= ctx->pending_cx_data_sz;
-
-      /* TODO: this is a minimal check, the underlying codec doesn't respect
-       * the buffer size anyway.
-       */
-      if (cx_data_sz < ctx->cx_data_sz / 2) {
-        vpx_internal_error(&cpi->common.error, VPX_CODEC_ERROR,
-                           "Compressed data buffer too small");
-        return VPX_CODEC_ERROR;
-      }
-    }
-
-    while (cx_data_sz >= ctx->cx_data_sz / 2 &&
-           -1 != vp9_get_compressed_data(cpi, &lib_flags, &size,
-                                         cx_data, &dst_time_stamp,
-                                         &dst_end_time_stamp, !img)) {
-      if (size) {
-        vpx_codec_cx_pkt_t pkt;
-
-#if CONFIG_SPATIAL_SVC
-        if (cpi->use_svc)
-          cpi->svc.layer_context[cpi->svc.spatial_layer_id *
-              cpi->svc.number_temporal_layers].layer_size += size;
-#endif
-
-        // Pack invisible frames with the next visible frame
-        if (!cpi->common.show_frame ||
-            (cpi->use_svc &&
-             cpi->svc.spatial_layer_id < cpi->svc.number_spatial_layers - 1)
-            ) {
-          if (ctx->pending_cx_data == 0)
-            ctx->pending_cx_data = cx_data;
-          ctx->pending_cx_data_sz += size;
-          ctx->pending_frame_sizes[ctx->pending_frame_count++] = size;
-          ctx->pending_frame_magnitude |= size;
-          cx_data += size;
-          cx_data_sz -= size;
-
-          if (ctx->output_cx_pkt_cb.output_cx_pkt) {
-            pkt.kind = VPX_CODEC_CX_FRAME_PKT;
-            pkt.data.frame.pts = ticks_to_timebase_units(timebase,
-                                                         dst_time_stamp);
-            pkt.data.frame.duration =
-               (unsigned long)ticks_to_timebase_units(timebase,
-                   dst_end_time_stamp - dst_time_stamp);
-            pkt.data.frame.flags = get_frame_pkt_flags(cpi, lib_flags);
-            pkt.data.frame.buf = ctx->pending_cx_data;
-            pkt.data.frame.sz  = size;
-            ctx->pending_cx_data = NULL;
-            ctx->pending_cx_data_sz = 0;
-            ctx->pending_frame_count = 0;
-            ctx->pending_frame_magnitude = 0;
-            ctx->output_cx_pkt_cb.output_cx_pkt(
-                &pkt, ctx->output_cx_pkt_cb.user_priv);
-          }
-          continue;
-        }
-
-        // Add the frame packet to the list of returned packets.
-        pkt.kind = VPX_CODEC_CX_FRAME_PKT;
-        pkt.data.frame.pts = ticks_to_timebase_units(timebase, dst_time_stamp);
-        pkt.data.frame.duration =
-           (unsigned long)ticks_to_timebase_units(timebase,
-               dst_end_time_stamp - dst_time_stamp);
-        pkt.data.frame.flags = get_frame_pkt_flags(cpi, lib_flags);
-
-        if (ctx->pending_cx_data) {
-          ctx->pending_frame_sizes[ctx->pending_frame_count++] = size;
-          ctx->pending_frame_magnitude |= size;
-          ctx->pending_cx_data_sz += size;
-          // write the superframe only for the case when
-          if (!ctx->output_cx_pkt_cb.output_cx_pkt)
-            size += write_superframe_index(ctx);
-          pkt.data.frame.buf = ctx->pending_cx_data;
-          pkt.data.frame.sz  = ctx->pending_cx_data_sz;
-          ctx->pending_cx_data = NULL;
-          ctx->pending_cx_data_sz = 0;
-          ctx->pending_frame_count = 0;
-          ctx->pending_frame_magnitude = 0;
-        } else {
-          pkt.data.frame.buf = cx_data;
-          pkt.data.frame.sz  = size;
-        }
-        pkt.data.frame.partition_id = -1;
-
-        if(ctx->output_cx_pkt_cb.output_cx_pkt)
-          ctx->output_cx_pkt_cb.output_cx_pkt(&pkt,
-                                              ctx->output_cx_pkt_cb.user_priv);
-        else
-          vpx_codec_pkt_list_add(&ctx->pkt_list.head, &pkt);
-
-        cx_data += size;
-        cx_data_sz -= size;
-#if VPX_ENCODER_ABI_VERSION > (5 + VPX_CODEC_ABI_VERSION)
-#if CONFIG_SPATIAL_SVC
-        if (cpi->use_svc && !ctx->output_cx_pkt_cb.output_cx_pkt) {
-          vpx_codec_cx_pkt_t pkt_sizes, pkt_psnr;
-          int sl;
-          vp9_zero(pkt_sizes);
-          vp9_zero(pkt_psnr);
-          pkt_sizes.kind = VPX_CODEC_SPATIAL_SVC_LAYER_SIZES;
-          pkt_psnr.kind = VPX_CODEC_SPATIAL_SVC_LAYER_PSNR;
-          for (sl = 0; sl < cpi->svc.number_spatial_layers; ++sl) {
-            LAYER_CONTEXT *lc =
-                &cpi->svc.layer_context[sl * cpi->svc.number_temporal_layers];
-            pkt_sizes.data.layer_sizes[sl] = lc->layer_size;
-            pkt_psnr.data.layer_psnr[sl] = lc->psnr_pkt;
-            lc->layer_size = 0;
-          }
-
-          vpx_codec_pkt_list_add(&ctx->pkt_list.head, &pkt_sizes);
-
-          vpx_codec_pkt_list_add(&ctx->pkt_list.head, &pkt_psnr);
-        }
-#endif
-#endif
-        if (is_one_pass_cbr_svc(cpi) &&
-            (cpi->svc.spatial_layer_id == cpi->svc.number_spatial_layers - 1)) {
-          // Encoded all spatial layers; exit loop.
-          break;
-        }
-      }
-    }
-  }
-
-  cpi->common.error.setjmp = 0;
-  return res;
-}
-
-static const vpx_codec_cx_pkt_t *encoder_get_cxdata(vpx_codec_alg_priv_t *ctx,
-                                                    vpx_codec_iter_t *iter) {
-  return vpx_codec_pkt_list_get(&ctx->pkt_list.head, iter);
-}
-
-static vpx_codec_err_t ctrl_set_reference(vpx_codec_alg_priv_t *ctx,
-                                          va_list args) {
-  vpx_ref_frame_t *const frame = va_arg(args, vpx_ref_frame_t *);
-
-  if (frame != NULL) {
-    YV12_BUFFER_CONFIG sd;
-
-    image2yuvconfig(&frame->img, &sd);
-    vp9_set_reference_enc(ctx->cpi, ref_frame_to_vp9_reframe(frame->frame_type),
-                          &sd);
-    return VPX_CODEC_OK;
-  } else {
-    return VPX_CODEC_INVALID_PARAM;
-  }
-}
-
-static vpx_codec_err_t ctrl_copy_reference(vpx_codec_alg_priv_t *ctx,
-                                           va_list args) {
-  vpx_ref_frame_t *const frame = va_arg(args, vpx_ref_frame_t *);
-
-  if (frame != NULL) {
-    YV12_BUFFER_CONFIG sd;
-
-    image2yuvconfig(&frame->img, &sd);
-    vp9_copy_reference_enc(ctx->cpi,
-                           ref_frame_to_vp9_reframe(frame->frame_type), &sd);
-    return VPX_CODEC_OK;
-  } else {
-    return VPX_CODEC_INVALID_PARAM;
-  }
-}
-
-static vpx_codec_err_t ctrl_get_reference(vpx_codec_alg_priv_t *ctx,
-                                          va_list args) {
-  vp9_ref_frame_t *const frame = va_arg(args, vp9_ref_frame_t *);
-
-  if (frame != NULL) {
-    YV12_BUFFER_CONFIG *fb = get_ref_frame(&ctx->cpi->common, frame->idx);
-    if (fb == NULL) return VPX_CODEC_ERROR;
-
-    yuvconfig2image(&frame->img, fb, NULL);
-    return VPX_CODEC_OK;
-  } else {
-    return VPX_CODEC_INVALID_PARAM;
-  }
-}
-
-static vpx_codec_err_t ctrl_set_previewpp(vpx_codec_alg_priv_t *ctx,
-                                          va_list args) {
-#if CONFIG_VP9_POSTPROC
-  vp8_postproc_cfg_t *config = va_arg(args, vp8_postproc_cfg_t *);
-  if (config != NULL) {
-    ctx->preview_ppcfg = *config;
-    return VPX_CODEC_OK;
-  } else {
-    return VPX_CODEC_INVALID_PARAM;
-  }
-#else
-  (void)ctx;
-  (void)args;
-  return VPX_CODEC_INCAPABLE;
-#endif
-}
-
-
-static vpx_image_t *encoder_get_preview(vpx_codec_alg_priv_t *ctx) {
-  YV12_BUFFER_CONFIG sd;
-  vp9_ppflags_t flags;
-  vp9_zero(flags);
-
-  if (ctx->preview_ppcfg.post_proc_flag) {
-    flags.post_proc_flag   = ctx->preview_ppcfg.post_proc_flag;
-    flags.deblocking_level = ctx->preview_ppcfg.deblocking_level;
-    flags.noise_level      = ctx->preview_ppcfg.noise_level;
-  }
-
-  if (vp9_get_preview_raw_frame(ctx->cpi, &sd, &flags) == 0) {
-    yuvconfig2image(&ctx->preview_img, &sd, NULL);
-    return &ctx->preview_img;
-  } else {
-    return NULL;
-  }
-}
-
-static vpx_codec_err_t ctrl_set_roi_map(vpx_codec_alg_priv_t *ctx,
-                                        va_list args) {
-  (void)ctx;
-  (void)args;
-
-  // TODO(yaowu): Need to re-implement and test for VP9.
-  return VPX_CODEC_INVALID_PARAM;
-}
-
-
-static vpx_codec_err_t ctrl_set_active_map(vpx_codec_alg_priv_t *ctx,
-                                           va_list args) {
-  vpx_active_map_t *const map = va_arg(args, vpx_active_map_t *);
-
-  if (map) {
-    if (!vp9_set_active_map(ctx->cpi, map->active_map,
-                            (int)map->rows, (int)map->cols))
-      return VPX_CODEC_OK;
-    else
-      return VPX_CODEC_INVALID_PARAM;
-  } else {
-    return VPX_CODEC_INVALID_PARAM;
-  }
-}
-
-static vpx_codec_err_t ctrl_get_active_map(vpx_codec_alg_priv_t *ctx,
-                                           va_list args) {
-  vpx_active_map_t *const map = va_arg(args, vpx_active_map_t *);
-
-  if (map) {
-    if (!vp9_get_active_map(ctx->cpi, map->active_map,
-                            (int)map->rows, (int)map->cols))
-      return VPX_CODEC_OK;
-    else
-      return VPX_CODEC_INVALID_PARAM;
-  } else {
-    return VPX_CODEC_INVALID_PARAM;
-  }
-}
-
-static vpx_codec_err_t ctrl_set_scale_mode(vpx_codec_alg_priv_t *ctx,
-                                           va_list args) {
-  vpx_scaling_mode_t *const mode = va_arg(args, vpx_scaling_mode_t *);
-
-  if (mode) {
-    const int res = vp9_set_internal_size(ctx->cpi,
-                                          (VPX_SCALING)mode->h_scaling_mode,
-                                          (VPX_SCALING)mode->v_scaling_mode);
-    return (res == 0) ? VPX_CODEC_OK : VPX_CODEC_INVALID_PARAM;
-  } else {
-    return VPX_CODEC_INVALID_PARAM;
-  }
-}
-
-static vpx_codec_err_t ctrl_set_svc(vpx_codec_alg_priv_t *ctx, va_list args) {
-  int data = va_arg(args, int);
-  const vpx_codec_enc_cfg_t *cfg = &ctx->cfg;
-  // Both one-pass and two-pass RC are supported now.
-  // User setting this has to make sure of the following.
-  // In two-pass setting: either (but not both)
-  //      cfg->ss_number_layers > 1, or cfg->ts_number_layers > 1
-  // In one-pass setting:
-  //      either or both cfg->ss_number_layers > 1, or cfg->ts_number_layers > 1
-
-  vp9_set_svc(ctx->cpi, data);
-
-  if (data == 1 &&
-      (cfg->g_pass == VPX_RC_FIRST_PASS ||
-       cfg->g_pass == VPX_RC_LAST_PASS) &&
-       cfg->ss_number_layers > 1 &&
-       cfg->ts_number_layers > 1) {
-    return VPX_CODEC_INVALID_PARAM;
-  }
-  return VPX_CODEC_OK;
-}
-
-static vpx_codec_err_t ctrl_set_svc_layer_id(vpx_codec_alg_priv_t *ctx,
-                                             va_list args) {
-  vpx_svc_layer_id_t *const data = va_arg(args, vpx_svc_layer_id_t *);
-  VP9_COMP *const cpi = (VP9_COMP *)ctx->cpi;
-  SVC *const svc = &cpi->svc;
-
-  svc->first_spatial_layer_to_encode = data->spatial_layer_id;
-  svc->spatial_layer_to_encode = data->spatial_layer_id;
-  svc->temporal_layer_id = data->temporal_layer_id;
-  // Checks on valid layer_id input.
-  if (svc->temporal_layer_id < 0 ||
-      svc->temporal_layer_id >= (int)ctx->cfg.ts_number_layers) {
-    return VPX_CODEC_INVALID_PARAM;
-  }
-  if (svc->first_spatial_layer_to_encode < 0 ||
-      svc->first_spatial_layer_to_encode >= (int)ctx->cfg.ss_number_layers) {
-    return VPX_CODEC_INVALID_PARAM;
-  }
-  // First spatial layer to encode not implemented for two-pass.
-  if (is_two_pass_svc(cpi) && svc->first_spatial_layer_to_encode > 0)
-    return VPX_CODEC_INVALID_PARAM;
-  return VPX_CODEC_OK;
-}
-
-static vpx_codec_err_t ctrl_get_svc_layer_id(vpx_codec_alg_priv_t *ctx,
-                                             va_list args) {
-  vpx_svc_layer_id_t *data = va_arg(args, vpx_svc_layer_id_t *);
-  VP9_COMP *const cpi = (VP9_COMP *)ctx->cpi;
-  SVC *const svc = &cpi->svc;
-
-  data->spatial_layer_id = svc->spatial_layer_id;
-  data->temporal_layer_id = svc->temporal_layer_id;
-
-  return VPX_CODEC_OK;
-}
-
-static vpx_codec_err_t ctrl_set_svc_parameters(vpx_codec_alg_priv_t *ctx,
-                                               va_list args) {
-  VP9_COMP *const cpi = ctx->cpi;
-  vpx_svc_extra_cfg_t *const params = va_arg(args, vpx_svc_extra_cfg_t *);
-  int sl, tl;
-
-  // Number of temporal layers and number of spatial layers have to be set
-  // properly before calling this control function.
-  for (sl = 0; sl < cpi->svc.number_spatial_layers; ++sl) {
-    for (tl = 0; tl < cpi->svc.number_temporal_layers; ++tl) {
-      const int layer =
-          LAYER_IDS_TO_IDX(sl, tl, cpi->svc.number_temporal_layers);
-      LAYER_CONTEXT *lc =
-          &cpi->svc.layer_context[layer];
-      lc->max_q = params->max_quantizers[layer];
-      lc->min_q = params->min_quantizers[layer];
-      lc->scaling_factor_num = params->scaling_factor_num[sl];
-      lc->scaling_factor_den = params->scaling_factor_den[sl];
-    }
-  }
-
-  return VPX_CODEC_OK;
-}
-
-static vpx_codec_err_t ctrl_set_svc_ref_frame_config(vpx_codec_alg_priv_t *ctx,
-                                                     va_list args) {
-  VP9_COMP *const cpi = ctx->cpi;
-  vpx_svc_ref_frame_config_t *data = va_arg(args, vpx_svc_ref_frame_config_t *);
-  int sl;
-  for (sl = 0; sl < cpi->svc.number_spatial_layers; ++sl) {
-    cpi->svc.ext_frame_flags[sl] = data->frame_flags[sl];
-    cpi->svc.ext_lst_fb_idx[sl] = data->lst_fb_idx[sl];
-    cpi->svc.ext_gld_fb_idx[sl] = data->gld_fb_idx[sl];
-    cpi->svc.ext_alt_fb_idx[sl] = data->alt_fb_idx[sl];
-  }
-  return VPX_CODEC_OK;
-}
-
-static vpx_codec_err_t ctrl_register_cx_callback(vpx_codec_alg_priv_t *ctx,
-                                                 va_list args) {
-  vpx_codec_priv_output_cx_pkt_cb_pair_t *cbp =
-      (vpx_codec_priv_output_cx_pkt_cb_pair_t *)va_arg(args, void *);
-  ctx->output_cx_pkt_cb.output_cx_pkt = cbp->output_cx_pkt;
-  ctx->output_cx_pkt_cb.user_priv = cbp->user_priv;
-
-  return VPX_CODEC_OK;
-}
-
-static vpx_codec_err_t ctrl_set_tune_content(vpx_codec_alg_priv_t *ctx,
-                                             va_list args) {
-  struct vp9_extracfg extra_cfg = ctx->extra_cfg;
-  extra_cfg.content = CAST(VP9E_SET_TUNE_CONTENT, args);
-  return update_extra_cfg(ctx, &extra_cfg);
-}
-
-static vpx_codec_err_t ctrl_set_color_space(vpx_codec_alg_priv_t *ctx,
-                                            va_list args) {
-  struct vp9_extracfg extra_cfg = ctx->extra_cfg;
-  extra_cfg.color_space = CAST(VP9E_SET_COLOR_SPACE, args);
-  return update_extra_cfg(ctx, &extra_cfg);
-}
-
-static vpx_codec_err_t ctrl_set_color_range(vpx_codec_alg_priv_t *ctx,
-                                            va_list args) {
-  struct vp9_extracfg extra_cfg = ctx->extra_cfg;
-  extra_cfg.color_range = CAST(VP9E_SET_COLOR_RANGE, args);
-  return update_extra_cfg(ctx, &extra_cfg);
-}
-
-static vpx_codec_err_t ctrl_set_render_size(vpx_codec_alg_priv_t *ctx,
-                                            va_list args) {
-  struct vp9_extracfg extra_cfg = ctx->extra_cfg;
-  int *const render_size = va_arg(args, int *);
-  extra_cfg.render_width  = render_size[0];
-  extra_cfg.render_height = render_size[1];
-  return update_extra_cfg(ctx, &extra_cfg);
-}
-
-static vpx_codec_ctrl_fn_map_t encoder_ctrl_maps[] = {
-  {VP8_COPY_REFERENCE,                ctrl_copy_reference},
-
-  // Setters
-  {VP8_SET_REFERENCE,                 ctrl_set_reference},
-  {VP8_SET_POSTPROC,                  ctrl_set_previewpp},
-  {VP8E_SET_ROI_MAP,                  ctrl_set_roi_map},
-  {VP8E_SET_ACTIVEMAP,                ctrl_set_active_map},
-  {VP8E_SET_SCALEMODE,                ctrl_set_scale_mode},
-  {VP8E_SET_CPUUSED,                  ctrl_set_cpuused},
-  {VP8E_SET_ENABLEAUTOALTREF,         ctrl_set_enable_auto_alt_ref},
-  {VP8E_SET_SHARPNESS,                ctrl_set_sharpness},
-  {VP8E_SET_STATIC_THRESHOLD,         ctrl_set_static_thresh},
-  {VP9E_SET_TILE_COLUMNS,             ctrl_set_tile_columns},
-  {VP9E_SET_TILE_ROWS,                ctrl_set_tile_rows},
-  {VP8E_SET_ARNR_MAXFRAMES,           ctrl_set_arnr_max_frames},
-  {VP8E_SET_ARNR_STRENGTH,            ctrl_set_arnr_strength},
-  {VP8E_SET_ARNR_TYPE,                ctrl_set_arnr_type},
-  {VP8E_SET_TUNING,                   ctrl_set_tuning},
-  {VP8E_SET_CQ_LEVEL,                 ctrl_set_cq_level},
-  {VP8E_SET_MAX_INTRA_BITRATE_PCT,    ctrl_set_rc_max_intra_bitrate_pct},
-  {VP9E_SET_MAX_INTER_BITRATE_PCT,    ctrl_set_rc_max_inter_bitrate_pct},
-  {VP9E_SET_GF_CBR_BOOST_PCT,         ctrl_set_rc_gf_cbr_boost_pct},
-  {VP9E_SET_LOSSLESS,                 ctrl_set_lossless},
-  {VP9E_SET_FRAME_PARALLEL_DECODING,  ctrl_set_frame_parallel_decoding_mode},
-  {VP9E_SET_AQ_MODE,                  ctrl_set_aq_mode},
-  {VP9E_SET_FRAME_PERIODIC_BOOST,     ctrl_set_frame_periodic_boost},
-  {VP9E_SET_SVC,                      ctrl_set_svc},
-  {VP9E_SET_SVC_PARAMETERS,           ctrl_set_svc_parameters},
-  {VP9E_REGISTER_CX_CALLBACK,         ctrl_register_cx_callback},
-  {VP9E_SET_SVC_LAYER_ID,             ctrl_set_svc_layer_id},
-  {VP9E_SET_TUNE_CONTENT,             ctrl_set_tune_content},
-  {VP9E_SET_COLOR_SPACE,              ctrl_set_color_space},
-  {VP9E_SET_COLOR_RANGE,              ctrl_set_color_range},
-  {VP9E_SET_NOISE_SENSITIVITY,        ctrl_set_noise_sensitivity},
-  {VP9E_SET_MIN_GF_INTERVAL,          ctrl_set_min_gf_interval},
-  {VP9E_SET_MAX_GF_INTERVAL,          ctrl_set_max_gf_interval},
-  {VP9E_SET_SVC_REF_FRAME_CONFIG,     ctrl_set_svc_ref_frame_config},
-  {VP9E_SET_RENDER_SIZE,              ctrl_set_render_size},
-  {VP9E_SET_TARGET_LEVEL,             ctrl_set_target_level},
-
-  // Getters
-  {VP8E_GET_LAST_QUANTIZER,           ctrl_get_quantizer},
-  {VP8E_GET_LAST_QUANTIZER_64,        ctrl_get_quantizer64},
-  {VP9_GET_REFERENCE,                 ctrl_get_reference},
-  {VP9E_GET_SVC_LAYER_ID,             ctrl_get_svc_layer_id},
-  {VP9E_GET_ACTIVEMAP,                ctrl_get_active_map},
-  {VP9E_GET_LEVEL,                    ctrl_get_level},
-
-  { -1, NULL},
-};
-
-static vpx_codec_enc_cfg_map_t encoder_usage_cfg_map[] = {
-  {
-    0,
-    {  // NOLINT
-      0,                  // g_usage
-      8,                  // g_threads
-      0,                  // g_profile
-
-      320,                // g_width
-      240,                // g_height
-      VPX_BITS_8,         // g_bit_depth
-      8,                  // g_input_bit_depth
-
-      {1, 30},            // g_timebase
-
-      0,                  // g_error_resilient
-
-      VPX_RC_ONE_PASS,    // g_pass
-
-      25,                 // g_lag_in_frames
-
-      0,                  // rc_dropframe_thresh
-      0,                  // rc_resize_allowed
-      0,                  // rc_scaled_width
-      0,                  // rc_scaled_height
-      60,                 // rc_resize_down_thresold
-      30,                 // rc_resize_up_thresold
-
-      VPX_VBR,            // rc_end_usage
-      {NULL, 0},          // rc_twopass_stats_in
-      {NULL, 0},          // rc_firstpass_mb_stats_in
-      256,                // rc_target_bandwidth
-      0,                  // rc_min_quantizer
-      63,                 // rc_max_quantizer
-      25,                 // rc_undershoot_pct
-      25,                 // rc_overshoot_pct
-
-      6000,               // rc_max_buffer_size
-      4000,               // rc_buffer_initial_size
-      5000,               // rc_buffer_optimal_size
-
-      50,                 // rc_two_pass_vbrbias
-      0,                  // rc_two_pass_vbrmin_section
-      2000,               // rc_two_pass_vbrmax_section
-
-      // keyframing settings (kf)
-      VPX_KF_AUTO,        // g_kfmode
-      0,                  // kf_min_dist
-      128,                // kf_max_dist
-
-      VPX_SS_DEFAULT_LAYERS,  // ss_number_layers
-      {0},
-      {0},                    // ss_target_bitrate
-      1,                      // ts_number_layers
-      {0},                    // ts_target_bitrate
-      {0},                    // ts_rate_decimator
-      0,                      // ts_periodicity
-      {0},                    // ts_layer_id
-      {0},                  // layer_taget_bitrate
-      0                     // temporal_layering_mode
-    }
-  },
-};
-
-#ifndef VERSION_STRING
-#define VERSION_STRING
-#endif
-CODEC_INTERFACE(vpx_codec_vp9_cx) = {
-  "WebM Project VP9 Encoder" VERSION_STRING,
-  VPX_CODEC_INTERNAL_ABI_VERSION,
-#if CONFIG_VP9_HIGHBITDEPTH
-  VPX_CODEC_CAP_HIGHBITDEPTH |
-#endif
-  VPX_CODEC_CAP_ENCODER | VPX_CODEC_CAP_PSNR,  // vpx_codec_caps_t
-  encoder_init,       // vpx_codec_init_fn_t
-  encoder_destroy,    // vpx_codec_destroy_fn_t
-  encoder_ctrl_maps,  // vpx_codec_ctrl_fn_map_t
-  {  // NOLINT
-    NULL,  // vpx_codec_peek_si_fn_t
-    NULL,  // vpx_codec_get_si_fn_t
-    NULL,  // vpx_codec_decode_fn_t
-    NULL,  // vpx_codec_frame_get_fn_t
-    NULL   // vpx_codec_set_fb_fn_t
-  },
-  {  // NOLINT
-    1,                      // 1 cfg map
-    encoder_usage_cfg_map,  // vpx_codec_enc_cfg_map_t
-    encoder_encode,         // vpx_codec_encode_fn_t
-    encoder_get_cxdata,     // vpx_codec_get_cx_data_fn_t
-    encoder_set_config,     // vpx_codec_enc_config_set_fn_t
-    NULL,        // vpx_codec_get_global_headers_fn_t
-    encoder_get_preview,    // vpx_codec_get_preview_frame_fn_t
-    NULL         // vpx_codec_enc_mr_get_mem_loc_fn_t
-  }
-};
diff --git a/vp9/vp9_dx_iface.c b/vp9/vp9_dx_iface.c
deleted file mode 100644 (file)
index 4ee5ce1..0000000
+++ /dev/null
@@ -1,1085 +0,0 @@
-/*
- *  Copyright (c) 2010 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.
- */
-
-#include <stdlib.h>
-#include <string.h>
-
-#include "./vpx_config.h"
-#include "./vpx_version.h"
-
-#include "vpx/internal/vpx_codec_internal.h"
-#include "vpx/vp8dx.h"
-#include "vpx/vpx_decoder.h"
-#include "vpx_dsp/bitreader_buffer.h"
-#include "vpx_dsp/vpx_dsp_common.h"
-#include "vpx_util/vpx_thread.h"
-
-#include "vp9/common/vp9_alloccommon.h"
-#include "vp9/common/vp9_frame_buffers.h"
-
-#include "vp9/decoder/vp9_decodeframe.h"
-
-#include "vp9/vp9_dx_iface.h"
-#include "vp9/vp9_iface_common.h"
-
-#define VP9_CAP_POSTPROC (CONFIG_VP9_POSTPROC ? VPX_CODEC_CAP_POSTPROC : 0)
-
-static vpx_codec_err_t decoder_init(vpx_codec_ctx_t *ctx,
-                                    vpx_codec_priv_enc_mr_cfg_t *data) {
-  // This function only allocates space for the vpx_codec_alg_priv_t
-  // structure. More memory may be required at the time the stream
-  // information becomes known.
-  (void)data;
-
-  if (!ctx->priv) {
-    vpx_codec_alg_priv_t *const priv =
-        (vpx_codec_alg_priv_t *)vpx_calloc(1, sizeof(*priv));
-    if (priv == NULL)
-      return VPX_CODEC_MEM_ERROR;
-
-    ctx->priv = (vpx_codec_priv_t *)priv;
-    ctx->priv->init_flags = ctx->init_flags;
-    priv->si.sz = sizeof(priv->si);
-    priv->flushed = 0;
-    // Only do frame parallel decode when threads > 1.
-    priv->frame_parallel_decode =
-        (ctx->config.dec && (ctx->config.dec->threads > 1) &&
-         (ctx->init_flags & VPX_CODEC_USE_FRAME_THREADING)) ? 1 : 0;
-    if (ctx->config.dec) {
-      priv->cfg = *ctx->config.dec;
-      ctx->config.dec = &priv->cfg;
-    }
-  }
-
-  return VPX_CODEC_OK;
-}
-
-static vpx_codec_err_t decoder_destroy(vpx_codec_alg_priv_t *ctx) {
-  if (ctx->frame_workers != NULL) {
-    int i;
-    for (i = 0; i < ctx->num_frame_workers; ++i) {
-      VPxWorker *const worker = &ctx->frame_workers[i];
-      FrameWorkerData *const frame_worker_data =
-          (FrameWorkerData *)worker->data1;
-      vpx_get_worker_interface()->end(worker);
-      vp9_remove_common(&frame_worker_data->pbi->common);
-#if CONFIG_VP9_POSTPROC
-      vp9_free_postproc_buffers(&frame_worker_data->pbi->common);
-#endif
-      vp9_decoder_remove(frame_worker_data->pbi);
-      vpx_free(frame_worker_data->scratch_buffer);
-#if CONFIG_MULTITHREAD
-      pthread_mutex_destroy(&frame_worker_data->stats_mutex);
-      pthread_cond_destroy(&frame_worker_data->stats_cond);
-#endif
-      vpx_free(frame_worker_data);
-    }
-#if CONFIG_MULTITHREAD
-    pthread_mutex_destroy(&ctx->buffer_pool->pool_mutex);
-#endif
-  }
-
-  if (ctx->buffer_pool) {
-    vp9_free_ref_frame_buffers(ctx->buffer_pool);
-    vp9_free_internal_frame_buffers(&ctx->buffer_pool->int_frame_buffers);
-  }
-
-  vpx_free(ctx->frame_workers);
-  vpx_free(ctx->buffer_pool);
-  vpx_free(ctx);
-  return VPX_CODEC_OK;
-}
-
-static int parse_bitdepth_colorspace_sampling(
-    BITSTREAM_PROFILE profile, struct vpx_read_bit_buffer *rb) {
-  vpx_color_space_t color_space;
-  if (profile >= PROFILE_2)
-    rb->bit_offset += 1;  // Bit-depth 10 or 12.
-  color_space = (vpx_color_space_t)vpx_rb_read_literal(rb, 3);
-  if (color_space != VPX_CS_SRGB) {
-    rb->bit_offset += 1;  // [16,235] (including xvycc) vs [0,255] range.
-    if (profile == PROFILE_1 || profile == PROFILE_3) {
-      rb->bit_offset += 2;  // subsampling x/y.
-      rb->bit_offset += 1;  // unused.
-    }
-  } else {
-    if (profile == PROFILE_1 || profile == PROFILE_3) {
-      rb->bit_offset += 1;  // unused
-    } else {
-      // RGB is only available in version 1.
-      return 0;
-    }
-  }
-  return 1;
-}
-
-static vpx_codec_err_t decoder_peek_si_internal(const uint8_t *data,
-                                                unsigned int data_sz,
-                                                vpx_codec_stream_info_t *si,
-                                                int *is_intra_only,
-                                                vpx_decrypt_cb decrypt_cb,
-                                                void *decrypt_state) {
-  int intra_only_flag = 0;
-  uint8_t clear_buffer[9];
-
-  if (data + data_sz <= data)
-    return VPX_CODEC_INVALID_PARAM;
-
-  si->is_kf = 0;
-  si->w = si->h = 0;
-
-  if (decrypt_cb) {
-    data_sz = VPXMIN(sizeof(clear_buffer), data_sz);
-    decrypt_cb(decrypt_state, data, clear_buffer, data_sz);
-    data = clear_buffer;
-  }
-
-  {
-    int show_frame;
-    int error_resilient;
-    struct vpx_read_bit_buffer rb = { data, data + data_sz, 0, NULL, NULL };
-    const int frame_marker = vpx_rb_read_literal(&rb, 2);
-    const BITSTREAM_PROFILE profile = vp9_read_profile(&rb);
-
-    if (frame_marker != VP9_FRAME_MARKER)
-      return VPX_CODEC_UNSUP_BITSTREAM;
-
-    if (profile >= MAX_PROFILES)
-      return VPX_CODEC_UNSUP_BITSTREAM;
-
-    if ((profile >= 2 && data_sz <= 1) || data_sz < 1)
-      return VPX_CODEC_UNSUP_BITSTREAM;
-
-    if (vpx_rb_read_bit(&rb)) {  // show an existing frame
-      vpx_rb_read_literal(&rb, 3);  // Frame buffer to show.
-      return VPX_CODEC_OK;
-    }
-
-    if (data_sz <= 8)
-      return VPX_CODEC_UNSUP_BITSTREAM;
-
-    si->is_kf = !vpx_rb_read_bit(&rb);
-    show_frame = vpx_rb_read_bit(&rb);
-    error_resilient = vpx_rb_read_bit(&rb);
-
-    if (si->is_kf) {
-      if (!vp9_read_sync_code(&rb))
-        return VPX_CODEC_UNSUP_BITSTREAM;
-
-      if (!parse_bitdepth_colorspace_sampling(profile, &rb))
-        return VPX_CODEC_UNSUP_BITSTREAM;
-      vp9_read_frame_size(&rb, (int *)&si->w, (int *)&si->h);
-    } else {
-      intra_only_flag = show_frame ? 0 : vpx_rb_read_bit(&rb);
-
-      rb.bit_offset += error_resilient ? 0 : 2;  // reset_frame_context
-
-      if (intra_only_flag) {
-        if (!vp9_read_sync_code(&rb))
-          return VPX_CODEC_UNSUP_BITSTREAM;
-        if (profile > PROFILE_0) {
-          if (!parse_bitdepth_colorspace_sampling(profile, &rb))
-            return VPX_CODEC_UNSUP_BITSTREAM;
-        }
-        rb.bit_offset += REF_FRAMES;  // refresh_frame_flags
-        vp9_read_frame_size(&rb, (int *)&si->w, (int *)&si->h);
-      }
-    }
-  }
-  if (is_intra_only != NULL)
-    *is_intra_only = intra_only_flag;
-  return VPX_CODEC_OK;
-}
-
-static vpx_codec_err_t decoder_peek_si(const uint8_t *data,
-                                       unsigned int data_sz,
-                                       vpx_codec_stream_info_t *si) {
-  return decoder_peek_si_internal(data, data_sz, si, NULL, NULL, NULL);
-}
-
-static vpx_codec_err_t decoder_get_si(vpx_codec_alg_priv_t *ctx,
-                                      vpx_codec_stream_info_t *si) {
-  const size_t sz = (si->sz >= sizeof(vp9_stream_info_t))
-                       ? sizeof(vp9_stream_info_t)
-                       : sizeof(vpx_codec_stream_info_t);
-  memcpy(si, &ctx->si, sz);
-  si->sz = (unsigned int)sz;
-
-  return VPX_CODEC_OK;
-}
-
-static void set_error_detail(vpx_codec_alg_priv_t *ctx,
-                             const char *const error) {
-  ctx->base.err_detail = error;
-}
-
-static vpx_codec_err_t update_error_state(vpx_codec_alg_priv_t *ctx,
-                           const struct vpx_internal_error_info *error) {
-  if (error->error_code)
-    set_error_detail(ctx, error->has_detail ? error->detail : NULL);
-
-  return error->error_code;
-}
-
-static void init_buffer_callbacks(vpx_codec_alg_priv_t *ctx) {
-  int i;
-
-  for (i = 0; i < ctx->num_frame_workers; ++i) {
-    VPxWorker *const worker = &ctx->frame_workers[i];
-    FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1;
-    VP9_COMMON *const cm = &frame_worker_data->pbi->common;
-    BufferPool *const pool = cm->buffer_pool;
-
-    cm->new_fb_idx = INVALID_IDX;
-    cm->byte_alignment = ctx->byte_alignment;
-    cm->skip_loop_filter = ctx->skip_loop_filter;
-
-    if (ctx->get_ext_fb_cb != NULL && ctx->release_ext_fb_cb != NULL) {
-      pool->get_fb_cb = ctx->get_ext_fb_cb;
-      pool->release_fb_cb = ctx->release_ext_fb_cb;
-      pool->cb_priv = ctx->ext_priv;
-    } else {
-      pool->get_fb_cb = vp9_get_frame_buffer;
-      pool->release_fb_cb = vp9_release_frame_buffer;
-
-      if (vp9_alloc_internal_frame_buffers(&pool->int_frame_buffers))
-        vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR,
-                           "Failed to initialize internal frame buffers");
-
-      pool->cb_priv = &pool->int_frame_buffers;
-    }
-  }
-}
-
-static void set_default_ppflags(vp8_postproc_cfg_t *cfg) {
-  cfg->post_proc_flag = VP8_DEBLOCK | VP8_DEMACROBLOCK;
-  cfg->deblocking_level = 4;
-  cfg->noise_level = 0;
-}
-
-static void set_ppflags(const vpx_codec_alg_priv_t *ctx,
-                        vp9_ppflags_t *flags) {
-  flags->post_proc_flag =
-      ctx->postproc_cfg.post_proc_flag;
-
-  flags->deblocking_level = ctx->postproc_cfg.deblocking_level;
-  flags->noise_level = ctx->postproc_cfg.noise_level;
-}
-
-static int frame_worker_hook(void *arg1, void *arg2) {
-  FrameWorkerData *const frame_worker_data = (FrameWorkerData *)arg1;
-  const uint8_t *data = frame_worker_data->data;
-  (void)arg2;
-
-  frame_worker_data->result =
-      vp9_receive_compressed_data(frame_worker_data->pbi,
-                                  frame_worker_data->data_size,
-                                  &data);
-  frame_worker_data->data_end = data;
-
-  if (frame_worker_data->pbi->frame_parallel_decode) {
-    // In frame parallel decoding, a worker thread must successfully decode all
-    // the compressed data.
-    if (frame_worker_data->result != 0 ||
-        frame_worker_data->data + frame_worker_data->data_size - 1 > data) {
-      VPxWorker *const worker = frame_worker_data->pbi->frame_worker_owner;
-      BufferPool *const pool = frame_worker_data->pbi->common.buffer_pool;
-      // Signal all the other threads that are waiting for this frame.
-      vp9_frameworker_lock_stats(worker);
-      frame_worker_data->frame_context_ready = 1;
-      lock_buffer_pool(pool);
-      frame_worker_data->pbi->cur_buf->buf.corrupted = 1;
-      unlock_buffer_pool(pool);
-      frame_worker_data->pbi->need_resync = 1;
-      vp9_frameworker_signal_stats(worker);
-      vp9_frameworker_unlock_stats(worker);
-      return 0;
-    }
-  } else if (frame_worker_data->result != 0) {
-    // Check decode result in serial decode.
-    frame_worker_data->pbi->cur_buf->buf.corrupted = 1;
-    frame_worker_data->pbi->need_resync = 1;
-  }
-  return !frame_worker_data->result;
-}
-
-static vpx_codec_err_t init_decoder(vpx_codec_alg_priv_t *ctx) {
-  int i;
-  const VPxWorkerInterface *const winterface = vpx_get_worker_interface();
-
-  ctx->last_show_frame = -1;
-  ctx->next_submit_worker_id = 0;
-  ctx->last_submit_worker_id = 0;
-  ctx->next_output_worker_id = 0;
-  ctx->frame_cache_read = 0;
-  ctx->frame_cache_write = 0;
-  ctx->num_cache_frames = 0;
-  ctx->need_resync = 1;
-  ctx->num_frame_workers =
-      (ctx->frame_parallel_decode == 1) ? ctx->cfg.threads: 1;
-  if (ctx->num_frame_workers > MAX_DECODE_THREADS)
-    ctx->num_frame_workers = MAX_DECODE_THREADS;
-  ctx->available_threads = ctx->num_frame_workers;
-  ctx->flushed = 0;
-
-  ctx->buffer_pool = (BufferPool *)vpx_calloc(1, sizeof(BufferPool));
-  if (ctx->buffer_pool == NULL)
-    return VPX_CODEC_MEM_ERROR;
-
-#if CONFIG_MULTITHREAD
-    if (pthread_mutex_init(&ctx->buffer_pool->pool_mutex, NULL)) {
-      set_error_detail(ctx, "Failed to allocate buffer pool mutex");
-      return VPX_CODEC_MEM_ERROR;
-    }
-#endif
-
-  ctx->frame_workers = (VPxWorker *)
-      vpx_malloc(ctx->num_frame_workers * sizeof(*ctx->frame_workers));
-  if (ctx->frame_workers == NULL) {
-    set_error_detail(ctx, "Failed to allocate frame_workers");
-    return VPX_CODEC_MEM_ERROR;
-  }
-
-  for (i = 0; i < ctx->num_frame_workers; ++i) {
-    VPxWorker *const worker = &ctx->frame_workers[i];
-    FrameWorkerData *frame_worker_data = NULL;
-    winterface->init(worker);
-    worker->data1 = vpx_memalign(32, sizeof(FrameWorkerData));
-    if (worker->data1 == NULL) {
-      set_error_detail(ctx, "Failed to allocate frame_worker_data");
-      return VPX_CODEC_MEM_ERROR;
-    }
-    frame_worker_data = (FrameWorkerData *)worker->data1;
-    frame_worker_data->pbi = vp9_decoder_create(ctx->buffer_pool);
-    if (frame_worker_data->pbi == NULL) {
-      set_error_detail(ctx, "Failed to allocate frame_worker_data");
-      return VPX_CODEC_MEM_ERROR;
-    }
-    frame_worker_data->pbi->frame_worker_owner = worker;
-    frame_worker_data->worker_id = i;
-    frame_worker_data->scratch_buffer = NULL;
-    frame_worker_data->scratch_buffer_size = 0;
-    frame_worker_data->frame_context_ready = 0;
-    frame_worker_data->received_frame = 0;
-#if CONFIG_MULTITHREAD
-    if (pthread_mutex_init(&frame_worker_data->stats_mutex, NULL)) {
-      set_error_detail(ctx, "Failed to allocate frame_worker_data mutex");
-      return VPX_CODEC_MEM_ERROR;
-    }
-
-    if (pthread_cond_init(&frame_worker_data->stats_cond, NULL)) {
-      set_error_detail(ctx, "Failed to allocate frame_worker_data cond");
-      return VPX_CODEC_MEM_ERROR;
-    }
-#endif
-    // If decoding in serial mode, FrameWorker thread could create tile worker
-    // thread or loopfilter thread.
-    frame_worker_data->pbi->max_threads =
-        (ctx->frame_parallel_decode == 0) ? ctx->cfg.threads : 0;
-
-    frame_worker_data->pbi->inv_tile_order = ctx->invert_tile_order;
-    frame_worker_data->pbi->frame_parallel_decode = ctx->frame_parallel_decode;
-    frame_worker_data->pbi->common.frame_parallel_decode =
-        ctx->frame_parallel_decode;
-    worker->hook = (VPxWorkerHook)frame_worker_hook;
-    if (!winterface->reset(worker)) {
-      set_error_detail(ctx, "Frame Worker thread creation failed");
-      return VPX_CODEC_MEM_ERROR;
-    }
-  }
-
-  // If postprocessing was enabled by the application and a
-  // configuration has not been provided, default it.
-  if (!ctx->postproc_cfg_set &&
-      (ctx->base.init_flags & VPX_CODEC_USE_POSTPROC))
-    set_default_ppflags(&ctx->postproc_cfg);
-
-  init_buffer_callbacks(ctx);
-
-  return VPX_CODEC_OK;
-}
-
-static INLINE void check_resync(vpx_codec_alg_priv_t *const ctx,
-                                const VP9Decoder *const pbi) {
-  // Clear resync flag if worker got a key frame or intra only frame.
-  if (ctx->need_resync == 1 && pbi->need_resync == 0 &&
-      (pbi->common.intra_only || pbi->common.frame_type == KEY_FRAME))
-    ctx->need_resync = 0;
-}
-
-static vpx_codec_err_t decode_one(vpx_codec_alg_priv_t *ctx,
-                                  const uint8_t **data, unsigned int data_sz,
-                                  void *user_priv, int64_t deadline) {
-  const VPxWorkerInterface *const winterface = vpx_get_worker_interface();
-  (void)deadline;
-
-  // Determine the stream parameters. Note that we rely on peek_si to
-  // validate that we have a buffer that does not wrap around the top
-  // of the heap.
-  if (!ctx->si.h) {
-    int is_intra_only = 0;
-    const vpx_codec_err_t res =
-        decoder_peek_si_internal(*data, data_sz, &ctx->si, &is_intra_only,
-                                 ctx->decrypt_cb, ctx->decrypt_state);
-    if (res != VPX_CODEC_OK)
-      return res;
-
-    if (!ctx->si.is_kf && !is_intra_only)
-      return VPX_CODEC_ERROR;
-  }
-
-  if (!ctx->frame_parallel_decode) {
-    VPxWorker *const worker = ctx->frame_workers;
-    FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1;
-    frame_worker_data->data = *data;
-    frame_worker_data->data_size = data_sz;
-    frame_worker_data->user_priv = user_priv;
-    frame_worker_data->received_frame = 1;
-
-    // Set these even if already initialized.  The caller may have changed the
-    // decrypt config between frames.
-    frame_worker_data->pbi->decrypt_cb = ctx->decrypt_cb;
-    frame_worker_data->pbi->decrypt_state = ctx->decrypt_state;
-
-    worker->had_error = 0;
-    winterface->execute(worker);
-
-    // Update data pointer after decode.
-    *data = frame_worker_data->data_end;
-
-    if (worker->had_error)
-      return update_error_state(ctx, &frame_worker_data->pbi->common.error);
-
-    check_resync(ctx, frame_worker_data->pbi);
-  } else {
-    VPxWorker *const worker = &ctx->frame_workers[ctx->next_submit_worker_id];
-    FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1;
-    // Copy context from last worker thread to next worker thread.
-    if (ctx->next_submit_worker_id != ctx->last_submit_worker_id)
-      vp9_frameworker_copy_context(
-          &ctx->frame_workers[ctx->next_submit_worker_id],
-          &ctx->frame_workers[ctx->last_submit_worker_id]);
-
-    frame_worker_data->pbi->ready_for_new_data = 0;
-    // Copy the compressed data into worker's internal buffer.
-    // TODO(hkuang): Will all the workers allocate the same size
-    // as the size of the first intra frame be better? This will
-    // avoid too many deallocate and allocate.
-    if (frame_worker_data->scratch_buffer_size < data_sz) {
-      frame_worker_data->scratch_buffer =
-          (uint8_t *)vpx_realloc(frame_worker_data->scratch_buffer, data_sz);
-      if (frame_worker_data->scratch_buffer == NULL) {
-        set_error_detail(ctx, "Failed to reallocate scratch buffer");
-        return VPX_CODEC_MEM_ERROR;
-      }
-      frame_worker_data->scratch_buffer_size = data_sz;
-    }
-    frame_worker_data->data_size = data_sz;
-    memcpy(frame_worker_data->scratch_buffer, *data, data_sz);
-
-    frame_worker_data->frame_decoded = 0;
-    frame_worker_data->frame_context_ready = 0;
-    frame_worker_data->received_frame = 1;
-    frame_worker_data->data = frame_worker_data->scratch_buffer;
-    frame_worker_data->user_priv = user_priv;
-
-    if (ctx->next_submit_worker_id != ctx->last_submit_worker_id)
-      ctx->last_submit_worker_id =
-          (ctx->last_submit_worker_id + 1) % ctx->num_frame_workers;
-
-    ctx->next_submit_worker_id =
-        (ctx->next_submit_worker_id + 1) % ctx->num_frame_workers;
-    --ctx->available_threads;
-    worker->had_error = 0;
-    winterface->launch(worker);
-  }
-
-  return VPX_CODEC_OK;
-}
-
-static void wait_worker_and_cache_frame(vpx_codec_alg_priv_t *ctx) {
-  YV12_BUFFER_CONFIG sd;
-  vp9_ppflags_t flags = {0, 0, 0};
-  const VPxWorkerInterface *const winterface = vpx_get_worker_interface();
-  VPxWorker *const worker = &ctx->frame_workers[ctx->next_output_worker_id];
-  FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1;
-  ctx->next_output_worker_id =
-      (ctx->next_output_worker_id + 1) % ctx->num_frame_workers;
-  // TODO(hkuang): Add worker error handling here.
-  winterface->sync(worker);
-  frame_worker_data->received_frame = 0;
-  ++ctx->available_threads;
-
-  check_resync(ctx, frame_worker_data->pbi);
-
-  if (vp9_get_raw_frame(frame_worker_data->pbi, &sd, &flags) == 0) {
-    VP9_COMMON *const cm = &frame_worker_data->pbi->common;
-    RefCntBuffer *const frame_bufs = cm->buffer_pool->frame_bufs;
-    ctx->frame_cache[ctx->frame_cache_write].fb_idx = cm->new_fb_idx;
-    yuvconfig2image(&ctx->frame_cache[ctx->frame_cache_write].img, &sd,
-                    frame_worker_data->user_priv);
-    ctx->frame_cache[ctx->frame_cache_write].img.fb_priv =
-        frame_bufs[cm->new_fb_idx].raw_frame_buffer.priv;
-    ctx->frame_cache_write =
-        (ctx->frame_cache_write + 1) % FRAME_CACHE_SIZE;
-    ++ctx->num_cache_frames;
-  }
-}
-
-static vpx_codec_err_t decoder_decode(vpx_codec_alg_priv_t *ctx,
-                                      const uint8_t *data, unsigned int data_sz,
-                                      void *user_priv, long deadline) {
-  const uint8_t *data_start = data;
-  const uint8_t * const data_end = data + data_sz;
-  vpx_codec_err_t res;
-  uint32_t frame_sizes[8];
-  int frame_count;
-
-  if (data == NULL && data_sz == 0) {
-    ctx->flushed = 1;
-    return VPX_CODEC_OK;
-  }
-
-  // Reset flushed when receiving a valid frame.
-  ctx->flushed = 0;
-
-  // Initialize the decoder workers on the first frame.
-  if (ctx->frame_workers == NULL) {
-    const vpx_codec_err_t res = init_decoder(ctx);
-    if (res != VPX_CODEC_OK)
-      return res;
-  }
-
-  res = vp9_parse_superframe_index(data, data_sz, frame_sizes, &frame_count,
-                                   ctx->decrypt_cb, ctx->decrypt_state);
-  if (res != VPX_CODEC_OK)
-    return res;
-
-  if (ctx->frame_parallel_decode) {
-    // Decode in frame parallel mode. When decoding in this mode, the frame
-    // passed to the decoder must be either a normal frame or a superframe with
-    // superframe index so the decoder could get each frame's start position
-    // in the superframe.
-    if (frame_count > 0) {
-      int i;
-
-      for (i = 0; i < frame_count; ++i) {
-        const uint8_t *data_start_copy = data_start;
-        const uint32_t frame_size = frame_sizes[i];
-        if (data_start < data
-            || frame_size > (uint32_t) (data_end - data_start)) {
-          set_error_detail(ctx, "Invalid frame size in index");
-          return VPX_CODEC_CORRUPT_FRAME;
-        }
-
-        if (ctx->available_threads == 0) {
-          // No more threads for decoding. Wait until the next output worker
-          // finishes decoding. Then copy the decoded frame into cache.
-          if (ctx->num_cache_frames < FRAME_CACHE_SIZE) {
-            wait_worker_and_cache_frame(ctx);
-          } else {
-            // TODO(hkuang): Add unit test to test this path.
-            set_error_detail(ctx, "Frame output cache is full.");
-            return VPX_CODEC_ERROR;
-          }
-        }
-
-        res = decode_one(ctx, &data_start_copy, frame_size, user_priv,
-                         deadline);
-        if (res != VPX_CODEC_OK)
-          return res;
-        data_start += frame_size;
-      }
-    } else {
-      if (ctx->available_threads == 0) {
-        // No more threads for decoding. Wait until the next output worker
-        // finishes decoding. Then copy the decoded frame into cache.
-        if (ctx->num_cache_frames < FRAME_CACHE_SIZE) {
-          wait_worker_and_cache_frame(ctx);
-        } else {
-          // TODO(hkuang): Add unit test to test this path.
-          set_error_detail(ctx, "Frame output cache is full.");
-          return VPX_CODEC_ERROR;
-        }
-      }
-
-      res = decode_one(ctx, &data, data_sz, user_priv, deadline);
-      if (res != VPX_CODEC_OK)
-        return res;
-    }
-  } else {
-    // Decode in serial mode.
-    if (frame_count > 0) {
-      int i;
-
-      for (i = 0; i < frame_count; ++i) {
-        const uint8_t *data_start_copy = data_start;
-        const uint32_t frame_size = frame_sizes[i];
-        vpx_codec_err_t res;
-        if (data_start < data
-            || frame_size > (uint32_t) (data_end - data_start)) {
-          set_error_detail(ctx, "Invalid frame size in index");
-          return VPX_CODEC_CORRUPT_FRAME;
-        }
-
-        res = decode_one(ctx, &data_start_copy, frame_size, user_priv,
-                         deadline);
-        if (res != VPX_CODEC_OK)
-          return res;
-
-        data_start += frame_size;
-      }
-    } else {
-      while (data_start < data_end) {
-        const uint32_t frame_size = (uint32_t) (data_end - data_start);
-        const vpx_codec_err_t res = decode_one(ctx, &data_start, frame_size,
-                                               user_priv, deadline);
-        if (res != VPX_CODEC_OK)
-          return res;
-
-        // Account for suboptimal termination by the encoder.
-        while (data_start < data_end) {
-          const uint8_t marker = read_marker(ctx->decrypt_cb,
-                                             ctx->decrypt_state, data_start);
-          if (marker)
-            break;
-          ++data_start;
-        }
-      }
-    }
-  }
-
-  return res;
-}
-
-static void release_last_output_frame(vpx_codec_alg_priv_t *ctx) {
-  RefCntBuffer *const frame_bufs = ctx->buffer_pool->frame_bufs;
-  // Decrease reference count of last output frame in frame parallel mode.
-  if (ctx->frame_parallel_decode && ctx->last_show_frame >= 0) {
-    BufferPool *const pool = ctx->buffer_pool;
-    lock_buffer_pool(pool);
-    decrease_ref_count(ctx->last_show_frame, frame_bufs, pool);
-    unlock_buffer_pool(pool);
-  }
-}
-
-static vpx_image_t *decoder_get_frame(vpx_codec_alg_priv_t *ctx,
-                                      vpx_codec_iter_t *iter) {
-  vpx_image_t *img = NULL;
-
-  // Only return frame when all the cpu are busy or
-  // application fluhsed the decoder in frame parallel decode.
-  if (ctx->frame_parallel_decode && ctx->available_threads > 0 &&
-      !ctx->flushed) {
-    return NULL;
-  }
-
-  // Output the frames in the cache first.
-  if (ctx->num_cache_frames > 0) {
-    release_last_output_frame(ctx);
-    ctx->last_show_frame  = ctx->frame_cache[ctx->frame_cache_read].fb_idx;
-    if (ctx->need_resync)
-      return NULL;
-    img = &ctx->frame_cache[ctx->frame_cache_read].img;
-    ctx->frame_cache_read = (ctx->frame_cache_read + 1) % FRAME_CACHE_SIZE;
-    --ctx->num_cache_frames;
-    return img;
-  }
-
-  // iter acts as a flip flop, so an image is only returned on the first
-  // call to get_frame.
-  if (*iter == NULL && ctx->frame_workers != NULL) {
-    do {
-      YV12_BUFFER_CONFIG sd;
-      vp9_ppflags_t flags = {0, 0, 0};
-      const VPxWorkerInterface *const winterface = vpx_get_worker_interface();
-      VPxWorker *const worker =
-          &ctx->frame_workers[ctx->next_output_worker_id];
-      FrameWorkerData *const frame_worker_data =
-          (FrameWorkerData *)worker->data1;
-      ctx->next_output_worker_id =
-          (ctx->next_output_worker_id + 1) % ctx->num_frame_workers;
-      if (ctx->base.init_flags & VPX_CODEC_USE_POSTPROC)
-        set_ppflags(ctx, &flags);
-      // Wait for the frame from worker thread.
-      if (winterface->sync(worker)) {
-        // Check if worker has received any frames.
-        if (frame_worker_data->received_frame == 1) {
-          ++ctx->available_threads;
-          frame_worker_data->received_frame = 0;
-          check_resync(ctx, frame_worker_data->pbi);
-        }
-        if (vp9_get_raw_frame(frame_worker_data->pbi, &sd, &flags) == 0) {
-          VP9_COMMON *const cm = &frame_worker_data->pbi->common;
-          RefCntBuffer *const frame_bufs = cm->buffer_pool->frame_bufs;
-          release_last_output_frame(ctx);
-          ctx->last_show_frame = frame_worker_data->pbi->common.new_fb_idx;
-          if (ctx->need_resync)
-            return NULL;
-          yuvconfig2image(&ctx->img, &sd, frame_worker_data->user_priv);
-          ctx->img.fb_priv = frame_bufs[cm->new_fb_idx].raw_frame_buffer.priv;
-          img = &ctx->img;
-          return img;
-        }
-      } else {
-        // Decoding failed. Release the worker thread.
-        frame_worker_data->received_frame = 0;
-        ++ctx->available_threads;
-        ctx->need_resync = 1;
-        if (ctx->flushed != 1)
-          return NULL;
-      }
-    } while (ctx->next_output_worker_id != ctx->next_submit_worker_id);
-  }
-  return NULL;
-}
-
-static vpx_codec_err_t decoder_set_fb_fn(
-    vpx_codec_alg_priv_t *ctx,
-    vpx_get_frame_buffer_cb_fn_t cb_get,
-    vpx_release_frame_buffer_cb_fn_t cb_release, void *cb_priv) {
-  if (cb_get == NULL || cb_release == NULL) {
-    return VPX_CODEC_INVALID_PARAM;
-  } else if (ctx->frame_workers == NULL) {
-    // If the decoder has already been initialized, do not accept changes to
-    // the frame buffer functions.
-    ctx->get_ext_fb_cb = cb_get;
-    ctx->release_ext_fb_cb = cb_release;
-    ctx->ext_priv = cb_priv;
-    return VPX_CODEC_OK;
-  }
-
-  return VPX_CODEC_ERROR;
-}
-
-static vpx_codec_err_t ctrl_set_reference(vpx_codec_alg_priv_t *ctx,
-                                          va_list args) {
-  vpx_ref_frame_t *const data = va_arg(args, vpx_ref_frame_t *);
-
-  // Only support this function in serial decode.
-  if (ctx->frame_parallel_decode) {
-    set_error_detail(ctx, "Not supported in frame parallel decode");
-    return VPX_CODEC_INCAPABLE;
-  }
-
-  if (data) {
-    vpx_ref_frame_t *const frame = (vpx_ref_frame_t *)data;
-    YV12_BUFFER_CONFIG sd;
-    VPxWorker *const worker = ctx->frame_workers;
-    FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1;
-    image2yuvconfig(&frame->img, &sd);
-    return vp9_set_reference_dec(&frame_worker_data->pbi->common,
-                                 ref_frame_to_vp9_reframe(frame->frame_type),
-                                 &sd);
-  } else {
-    return VPX_CODEC_INVALID_PARAM;
-  }
-}
-
-static vpx_codec_err_t ctrl_copy_reference(vpx_codec_alg_priv_t *ctx,
-                                           va_list args) {
-  vpx_ref_frame_t *data = va_arg(args, vpx_ref_frame_t *);
-
-  // Only support this function in serial decode.
-  if (ctx->frame_parallel_decode) {
-    set_error_detail(ctx, "Not supported in frame parallel decode");
-    return VPX_CODEC_INCAPABLE;
-  }
-
-  if (data) {
-    vpx_ref_frame_t *frame = (vpx_ref_frame_t *) data;
-    YV12_BUFFER_CONFIG sd;
-    VPxWorker *const worker = ctx->frame_workers;
-    FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1;
-    image2yuvconfig(&frame->img, &sd);
-    return vp9_copy_reference_dec(frame_worker_data->pbi,
-                                  (VP9_REFFRAME)frame->frame_type, &sd);
-  } else {
-    return VPX_CODEC_INVALID_PARAM;
-  }
-}
-
-static vpx_codec_err_t ctrl_get_reference(vpx_codec_alg_priv_t *ctx,
-                                          va_list args) {
-  vp9_ref_frame_t *data = va_arg(args, vp9_ref_frame_t *);
-
-  // Only support this function in serial decode.
-  if (ctx->frame_parallel_decode) {
-    set_error_detail(ctx, "Not supported in frame parallel decode");
-    return VPX_CODEC_INCAPABLE;
-  }
-
-  if (data) {
-    YV12_BUFFER_CONFIG* fb;
-    VPxWorker *const worker = ctx->frame_workers;
-    FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1;
-    fb = get_ref_frame(&frame_worker_data->pbi->common, data->idx);
-    if (fb == NULL) return VPX_CODEC_ERROR;
-    yuvconfig2image(&data->img, fb, NULL);
-    return VPX_CODEC_OK;
-  } else {
-    return VPX_CODEC_INVALID_PARAM;
-  }
-}
-
-static vpx_codec_err_t ctrl_set_postproc(vpx_codec_alg_priv_t *ctx,
-                                         va_list args) {
-#if CONFIG_VP9_POSTPROC
-  vp8_postproc_cfg_t *data = va_arg(args, vp8_postproc_cfg_t *);
-
-  if (data) {
-    ctx->postproc_cfg_set = 1;
-    ctx->postproc_cfg = *((vp8_postproc_cfg_t *)data);
-    return VPX_CODEC_OK;
-  } else {
-    return VPX_CODEC_INVALID_PARAM;
-  }
-#else
-  (void)ctx;
-  (void)args;
-  return VPX_CODEC_INCAPABLE;
-#endif
-}
-
-static vpx_codec_err_t ctrl_set_dbg_options(vpx_codec_alg_priv_t *ctx,
-                                            va_list args) {
-  (void)ctx;
-  (void)args;
-  return VPX_CODEC_INCAPABLE;
-}
-
-static vpx_codec_err_t ctrl_get_last_ref_updates(vpx_codec_alg_priv_t *ctx,
-                                                 va_list args) {
-  int *const update_info = va_arg(args, int *);
-
-  // Only support this function in serial decode.
-  if (ctx->frame_parallel_decode) {
-    set_error_detail(ctx, "Not supported in frame parallel decode");
-    return VPX_CODEC_INCAPABLE;
-  }
-
-  if (update_info) {
-    if (ctx->frame_workers) {
-      VPxWorker *const worker = ctx->frame_workers;
-      FrameWorkerData *const frame_worker_data =
-          (FrameWorkerData *)worker->data1;
-      *update_info = frame_worker_data->pbi->refresh_frame_flags;
-      return VPX_CODEC_OK;
-    } else {
-      return VPX_CODEC_ERROR;
-    }
-  }
-
-  return VPX_CODEC_INVALID_PARAM;
-}
-
-static vpx_codec_err_t ctrl_get_frame_corrupted(vpx_codec_alg_priv_t *ctx,
-                                                va_list args) {
-  int *corrupted = va_arg(args, int *);
-
-  if (corrupted) {
-    if (ctx->frame_workers) {
-      VPxWorker *const worker = ctx->frame_workers;
-      FrameWorkerData *const frame_worker_data =
-          (FrameWorkerData *)worker->data1;
-      RefCntBuffer *const frame_bufs =
-          frame_worker_data->pbi->common.buffer_pool->frame_bufs;
-      if (frame_worker_data->pbi->common.frame_to_show == NULL)
-        return VPX_CODEC_ERROR;
-      if (ctx->last_show_frame >= 0)
-        *corrupted = frame_bufs[ctx->last_show_frame].buf.corrupted;
-      return VPX_CODEC_OK;
-    } else {
-      return VPX_CODEC_ERROR;
-    }
-  }
-
-  return VPX_CODEC_INVALID_PARAM;
-}
-
-static vpx_codec_err_t ctrl_get_frame_size(vpx_codec_alg_priv_t *ctx,
-                                           va_list args) {
-  int *const frame_size = va_arg(args, int *);
-
-  // Only support this function in serial decode.
-  if (ctx->frame_parallel_decode) {
-    set_error_detail(ctx, "Not supported in frame parallel decode");
-    return VPX_CODEC_INCAPABLE;
-  }
-
-  if (frame_size) {
-    if (ctx->frame_workers) {
-      VPxWorker *const worker = ctx->frame_workers;
-      FrameWorkerData *const frame_worker_data =
-          (FrameWorkerData *)worker->data1;
-      const VP9_COMMON *const cm = &frame_worker_data->pbi->common;
-      frame_size[0] = cm->width;
-      frame_size[1] = cm->height;
-      return VPX_CODEC_OK;
-    } else {
-      return VPX_CODEC_ERROR;
-    }
-  }
-
-  return VPX_CODEC_INVALID_PARAM;
-}
-
-static vpx_codec_err_t ctrl_get_render_size(vpx_codec_alg_priv_t *ctx,
-                                            va_list args) {
-  int *const render_size = va_arg(args, int *);
-
-  // Only support this function in serial decode.
-  if (ctx->frame_parallel_decode) {
-    set_error_detail(ctx, "Not supported in frame parallel decode");
-    return VPX_CODEC_INCAPABLE;
-  }
-
-  if (render_size) {
-    if (ctx->frame_workers) {
-      VPxWorker *const worker = ctx->frame_workers;
-      FrameWorkerData *const frame_worker_data =
-          (FrameWorkerData *)worker->data1;
-      const VP9_COMMON *const cm = &frame_worker_data->pbi->common;
-      render_size[0] = cm->render_width;
-      render_size[1] = cm->render_height;
-      return VPX_CODEC_OK;
-    } else {
-      return VPX_CODEC_ERROR;
-    }
-  }
-
-  return VPX_CODEC_INVALID_PARAM;
-}
-
-static vpx_codec_err_t ctrl_get_bit_depth(vpx_codec_alg_priv_t *ctx,
-                                          va_list args) {
-  unsigned int *const bit_depth = va_arg(args, unsigned int *);
-  VPxWorker *const worker = &ctx->frame_workers[ctx->next_output_worker_id];
-
-  if (bit_depth) {
-    if (worker) {
-      FrameWorkerData *const frame_worker_data =
-          (FrameWorkerData *)worker->data1;
-      const VP9_COMMON *const cm = &frame_worker_data->pbi->common;
-      *bit_depth = cm->bit_depth;
-      return VPX_CODEC_OK;
-    } else {
-      return VPX_CODEC_ERROR;
-    }
-  }
-
-  return VPX_CODEC_INVALID_PARAM;
-}
-
-static vpx_codec_err_t ctrl_set_invert_tile_order(vpx_codec_alg_priv_t *ctx,
-                                                  va_list args) {
-  ctx->invert_tile_order = va_arg(args, int);
-  return VPX_CODEC_OK;
-}
-
-static vpx_codec_err_t ctrl_set_decryptor(vpx_codec_alg_priv_t *ctx,
-                                          va_list args) {
-  vpx_decrypt_init *init = va_arg(args, vpx_decrypt_init *);
-  ctx->decrypt_cb = init ? init->decrypt_cb : NULL;
-  ctx->decrypt_state = init ? init->decrypt_state : NULL;
-  return VPX_CODEC_OK;
-}
-
-static vpx_codec_err_t ctrl_set_byte_alignment(vpx_codec_alg_priv_t *ctx,
-                                               va_list args) {
-  const int legacy_byte_alignment = 0;
-  const int min_byte_alignment = 32;
-  const int max_byte_alignment = 1024;
-  const int byte_alignment = va_arg(args, int);
-
-  if (byte_alignment != legacy_byte_alignment &&
-      (byte_alignment < min_byte_alignment ||
-       byte_alignment > max_byte_alignment ||
-       (byte_alignment & (byte_alignment - 1)) != 0))
-    return VPX_CODEC_INVALID_PARAM;
-
-  ctx->byte_alignment = byte_alignment;
-  if (ctx->frame_workers) {
-    VPxWorker *const worker = ctx->frame_workers;
-    FrameWorkerData *const frame_worker_data =
-        (FrameWorkerData *)worker->data1;
-    frame_worker_data->pbi->common.byte_alignment = byte_alignment;
-  }
-  return VPX_CODEC_OK;
-}
-
-static vpx_codec_err_t ctrl_set_skip_loop_filter(vpx_codec_alg_priv_t *ctx,
-                                                 va_list args) {
-  ctx->skip_loop_filter = va_arg(args, int);
-
-  if (ctx->frame_workers) {
-    VPxWorker *const worker = ctx->frame_workers;
-    FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1;
-    frame_worker_data->pbi->common.skip_loop_filter = ctx->skip_loop_filter;
-  }
-
-  return VPX_CODEC_OK;
-}
-
-static vpx_codec_ctrl_fn_map_t decoder_ctrl_maps[] = {
-  {VP8_COPY_REFERENCE,            ctrl_copy_reference},
-
-  // Setters
-  {VP8_SET_REFERENCE,             ctrl_set_reference},
-  {VP8_SET_POSTPROC,              ctrl_set_postproc},
-  {VP8_SET_DBG_COLOR_REF_FRAME,   ctrl_set_dbg_options},
-  {VP8_SET_DBG_COLOR_MB_MODES,    ctrl_set_dbg_options},
-  {VP8_SET_DBG_COLOR_B_MODES,     ctrl_set_dbg_options},
-  {VP8_SET_DBG_DISPLAY_MV,        ctrl_set_dbg_options},
-  {VP9_INVERT_TILE_DECODE_ORDER,  ctrl_set_invert_tile_order},
-  {VPXD_SET_DECRYPTOR,            ctrl_set_decryptor},
-  {VP9_SET_BYTE_ALIGNMENT,        ctrl_set_byte_alignment},
-  {VP9_SET_SKIP_LOOP_FILTER,      ctrl_set_skip_loop_filter},
-
-  // Getters
-  {VP8D_GET_LAST_REF_UPDATES,     ctrl_get_last_ref_updates},
-  {VP8D_GET_FRAME_CORRUPTED,      ctrl_get_frame_corrupted},
-  {VP9_GET_REFERENCE,             ctrl_get_reference},
-  {VP9D_GET_DISPLAY_SIZE,         ctrl_get_render_size},
-  {VP9D_GET_BIT_DEPTH,            ctrl_get_bit_depth},
-  {VP9D_GET_FRAME_SIZE,           ctrl_get_frame_size},
-
-  { -1, NULL},
-};
-
-#ifndef VERSION_STRING
-#define VERSION_STRING
-#endif
-CODEC_INTERFACE(vpx_codec_vp9_dx) = {
-  "WebM Project VP9 Decoder" VERSION_STRING,
-  VPX_CODEC_INTERNAL_ABI_VERSION,
-  VPX_CODEC_CAP_DECODER | VP9_CAP_POSTPROC |
-      VPX_CODEC_CAP_EXTERNAL_FRAME_BUFFER,  // vpx_codec_caps_t
-  decoder_init,       // vpx_codec_init_fn_t
-  decoder_destroy,    // vpx_codec_destroy_fn_t
-  decoder_ctrl_maps,  // vpx_codec_ctrl_fn_map_t
-  { // NOLINT
-    decoder_peek_si,    // vpx_codec_peek_si_fn_t
-    decoder_get_si,     // vpx_codec_get_si_fn_t
-    decoder_decode,     // vpx_codec_decode_fn_t
-    decoder_get_frame,  // vpx_codec_frame_get_fn_t
-    decoder_set_fb_fn,  // vpx_codec_set_fb_fn_t
-  },
-  { // NOLINT
-    0,
-    NULL,  // vpx_codec_enc_cfg_map_t
-    NULL,  // vpx_codec_encode_fn_t
-    NULL,  // vpx_codec_get_cx_data_fn_t
-    NULL,  // vpx_codec_enc_config_set_fn_t
-    NULL,  // vpx_codec_get_global_headers_fn_t
-    NULL,  // vpx_codec_get_preview_frame_fn_t
-    NULL   // vpx_codec_enc_mr_get_mem_loc_fn_t
-  }
-};
diff --git a/vp9/vp9_dx_iface.h b/vp9/vp9_dx_iface.h
deleted file mode 100644 (file)
index e0e948e..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- *  Copyright (c) 2015 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.
- */
-
-#ifndef VP9_VP9_DX_IFACE_H_
-#define VP9_VP9_DX_IFACE_H_
-
-#include "vp9/decoder/vp9_decoder.h"
-
-typedef vpx_codec_stream_info_t vp9_stream_info_t;
-
-// This limit is due to framebuffer numbers.
-// TODO(hkuang): Remove this limit after implementing ondemand framebuffers.
-#define FRAME_CACHE_SIZE 6   // Cache maximum 6 decoded frames.
-
-typedef struct cache_frame {
-  int fb_idx;
-  vpx_image_t img;
-} cache_frame;
-
-struct vpx_codec_alg_priv {
-  vpx_codec_priv_t        base;
-  vpx_codec_dec_cfg_t     cfg;
-  vp9_stream_info_t       si;
-  int                     postproc_cfg_set;
-  vp8_postproc_cfg_t      postproc_cfg;
-  vpx_decrypt_cb          decrypt_cb;
-  void                    *decrypt_state;
-  vpx_image_t             img;
-  int                     img_avail;
-  int                     flushed;
-  int                     invert_tile_order;
-  int                     last_show_frame;  // Index of last output frame.
-  int                     byte_alignment;
-  int                     skip_loop_filter;
-
-  // Frame parallel related.
-  int                     frame_parallel_decode;  // frame-based threading.
-  VPxWorker               *frame_workers;
-  int                     num_frame_workers;
-  int                     next_submit_worker_id;
-  int                     last_submit_worker_id;
-  int                     next_output_worker_id;
-  int                     available_threads;
-  cache_frame             frame_cache[FRAME_CACHE_SIZE];
-  int                     frame_cache_write;
-  int                     frame_cache_read;
-  int                     num_cache_frames;
-  int                     need_resync;      // wait for key/intra-only frame
-  // BufferPool that holds all reference frames. Shared by all the FrameWorkers.
-  BufferPool              *buffer_pool;
-
-  // External frame buffer info to save for VP9 common.
-  void *ext_priv;  // Private data associated with the external frame buffers.
-  vpx_get_frame_buffer_cb_fn_t get_ext_fb_cb;
-  vpx_release_frame_buffer_cb_fn_t release_ext_fb_cb;
-};
-
-#endif  // VP9_VP9_DX_IFACE_H_
diff --git a/vp9/vp9_iface_common.h b/vp9/vp9_iface_common.h
deleted file mode 100644 (file)
index 44a5e81..0000000
+++ /dev/null
@@ -1,148 +0,0 @@
-/*
- *  Copyright (c) 2013 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.
- */
-#ifndef VP9_VP9_IFACE_COMMON_H_
-#define VP9_VP9_IFACE_COMMON_H_
-
-#include "vpx_ports/mem.h"
-
-static void yuvconfig2image(vpx_image_t *img, const YV12_BUFFER_CONFIG  *yv12,
-                            void *user_priv) {
-  /** vpx_img_wrap() doesn't allow specifying independent strides for
-    * the Y, U, and V planes, nor other alignment adjustments that
-    * might be representable by a YV12_BUFFER_CONFIG, so we just
-    * initialize all the fields.*/
-  int bps;
-  if (!yv12->subsampling_y) {
-    if (!yv12->subsampling_x) {
-      img->fmt = VPX_IMG_FMT_I444;
-      bps = 24;
-    } else {
-      img->fmt = VPX_IMG_FMT_I422;
-      bps = 16;
-    }
-  } else {
-    if (!yv12->subsampling_x) {
-      img->fmt = VPX_IMG_FMT_I440;
-      bps = 16;
-    } else {
-      img->fmt = VPX_IMG_FMT_I420;
-      bps = 12;
-    }
-  }
-  img->cs = yv12->color_space;
-  img->range = yv12->color_range;
-  img->bit_depth = 8;
-  img->w = yv12->y_stride;
-  img->h = ALIGN_POWER_OF_TWO(yv12->y_height + 2 * VP9_ENC_BORDER_IN_PIXELS, 3);
-  img->d_w = yv12->y_crop_width;
-  img->d_h = yv12->y_crop_height;
-  img->r_w = yv12->render_width;
-  img->r_h = yv12->render_height;
-  img->x_chroma_shift = yv12->subsampling_x;
-  img->y_chroma_shift = yv12->subsampling_y;
-  img->planes[VPX_PLANE_Y] = yv12->y_buffer;
-  img->planes[VPX_PLANE_U] = yv12->u_buffer;
-  img->planes[VPX_PLANE_V] = yv12->v_buffer;
-  img->planes[VPX_PLANE_ALPHA] = NULL;
-  img->stride[VPX_PLANE_Y] = yv12->y_stride;
-  img->stride[VPX_PLANE_U] = yv12->uv_stride;
-  img->stride[VPX_PLANE_V] = yv12->uv_stride;
-  img->stride[VPX_PLANE_ALPHA] = yv12->y_stride;
-#if CONFIG_VP9_HIGHBITDEPTH
-  if (yv12->flags & YV12_FLAG_HIGHBITDEPTH) {
-    // vpx_image_t uses byte strides and a pointer to the first byte
-    // of the image.
-    img->fmt = (vpx_img_fmt_t)(img->fmt | VPX_IMG_FMT_HIGHBITDEPTH);
-    img->bit_depth = yv12->bit_depth;
-    img->planes[VPX_PLANE_Y] = (uint8_t*)CONVERT_TO_SHORTPTR(yv12->y_buffer);
-    img->planes[VPX_PLANE_U] = (uint8_t*)CONVERT_TO_SHORTPTR(yv12->u_buffer);
-    img->planes[VPX_PLANE_V] = (uint8_t*)CONVERT_TO_SHORTPTR(yv12->v_buffer);
-    img->planes[VPX_PLANE_ALPHA] = NULL;
-    img->stride[VPX_PLANE_Y] = 2 * yv12->y_stride;
-    img->stride[VPX_PLANE_U] = 2 * yv12->uv_stride;
-    img->stride[VPX_PLANE_V] = 2 * yv12->uv_stride;
-    img->stride[VPX_PLANE_ALPHA] = 2 * yv12->y_stride;
-  }
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-  img->bps = bps;
-  img->user_priv = user_priv;
-  img->img_data = yv12->buffer_alloc;
-  img->img_data_owner = 0;
-  img->self_allocd = 0;
-}
-
-static vpx_codec_err_t image2yuvconfig(const vpx_image_t *img,
-                                       YV12_BUFFER_CONFIG *yv12) {
-  yv12->y_buffer = img->planes[VPX_PLANE_Y];
-  yv12->u_buffer = img->planes[VPX_PLANE_U];
-  yv12->v_buffer = img->planes[VPX_PLANE_V];
-
-  yv12->y_crop_width  = img->d_w;
-  yv12->y_crop_height = img->d_h;
-  yv12->render_width  = img->r_w;
-  yv12->render_height = img->r_h;
-  yv12->y_width  = img->d_w;
-  yv12->y_height = img->d_h;
-
-  yv12->uv_width = img->x_chroma_shift == 1 ? (1 + yv12->y_width) / 2
-                                            : yv12->y_width;
-  yv12->uv_height = img->y_chroma_shift == 1 ? (1 + yv12->y_height) / 2
-                                             : yv12->y_height;
-  yv12->uv_crop_width = yv12->uv_width;
-  yv12->uv_crop_height = yv12->uv_height;
-
-  yv12->y_stride = img->stride[VPX_PLANE_Y];
-  yv12->uv_stride = img->stride[VPX_PLANE_U];
-  yv12->color_space = img->cs;
-  yv12->color_range = img->range;
-
-#if CONFIG_VP9_HIGHBITDEPTH
-  if (img->fmt & VPX_IMG_FMT_HIGHBITDEPTH) {
-    // In vpx_image_t
-    //     planes point to uint8 address of start of data
-    //     stride counts uint8s to reach next row
-    // In YV12_BUFFER_CONFIG
-    //     y_buffer, u_buffer, v_buffer point to uint16 address of data
-    //     stride and border counts in uint16s
-    // This means that all the address calculations in the main body of code
-    // should work correctly.
-    // However, before we do any pixel operations we need to cast the address
-    // to a uint16 ponter and double its value.
-    yv12->y_buffer = CONVERT_TO_BYTEPTR(yv12->y_buffer);
-    yv12->u_buffer = CONVERT_TO_BYTEPTR(yv12->u_buffer);
-    yv12->v_buffer = CONVERT_TO_BYTEPTR(yv12->v_buffer);
-    yv12->y_stride >>= 1;
-    yv12->uv_stride >>= 1;
-    yv12->flags = YV12_FLAG_HIGHBITDEPTH;
-  } else {
-    yv12->flags = 0;
-  }
-  yv12->border  = (yv12->y_stride - img->w) / 2;
-#else
-  yv12->border  = (img->stride[VPX_PLANE_Y] - img->w) / 2;
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-  yv12->subsampling_x = img->x_chroma_shift;
-  yv12->subsampling_y = img->y_chroma_shift;
-  return VPX_CODEC_OK;
-}
-
-static VP9_REFFRAME ref_frame_to_vp9_reframe(vpx_ref_frame_type_t frame) {
-  switch (frame) {
-    case VP8_LAST_FRAME:
-      return VP9_LAST_FLAG;
-    case VP8_GOLD_FRAME:
-      return VP9_GOLD_FLAG;
-    case VP8_ALTR_FRAME:
-      return VP9_ALT_FLAG;
-  }
-  assert(0 && "Invalid Reference Frame");
-  return VP9_LAST_FLAG;
-}
-#endif  // VP9_VP9_IFACE_COMMON_H_
diff --git a/vp9/vp9cx.mk b/vp9/vp9cx.mk
deleted file mode 100644 (file)
index b8342b9..0000000
+++ /dev/null
@@ -1,141 +0,0 @@
-##
-##  Copyright (c) 2010 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.
-##
-
-VP9_CX_EXPORTS += exports_enc
-
-VP9_CX_SRCS-yes += $(VP9_COMMON_SRCS-yes)
-VP9_CX_SRCS-no  += $(VP9_COMMON_SRCS-no)
-VP9_CX_SRCS_REMOVE-yes += $(VP9_COMMON_SRCS_REMOVE-yes)
-VP9_CX_SRCS_REMOVE-no  += $(VP9_COMMON_SRCS_REMOVE-no)
-
-VP9_CX_SRCS-yes += vp9_cx_iface.c
-
-VP9_CX_SRCS-yes += encoder/vp9_bitstream.c
-VP9_CX_SRCS-yes += encoder/vp9_context_tree.c
-VP9_CX_SRCS-yes += encoder/vp9_context_tree.h
-VP9_CX_SRCS-yes += encoder/vp9_cost.h
-VP9_CX_SRCS-yes += encoder/vp9_cost.c
-VP9_CX_SRCS-yes += encoder/vp9_dct.c
-VP9_CX_SRCS-$(CONFIG_VP9_TEMPORAL_DENOISING) += encoder/vp9_denoiser.c
-VP9_CX_SRCS-$(CONFIG_VP9_TEMPORAL_DENOISING) += encoder/vp9_denoiser.h
-VP9_CX_SRCS-yes += encoder/vp9_encodeframe.c
-VP9_CX_SRCS-yes += encoder/vp9_encodeframe.h
-VP9_CX_SRCS-yes += encoder/vp9_encodemb.c
-VP9_CX_SRCS-yes += encoder/vp9_encodemv.c
-VP9_CX_SRCS-yes += encoder/vp9_ethread.h
-VP9_CX_SRCS-yes += encoder/vp9_ethread.c
-VP9_CX_SRCS-yes += encoder/vp9_extend.c
-VP9_CX_SRCS-yes += encoder/vp9_firstpass.c
-VP9_CX_SRCS-yes += encoder/vp9_block.h
-VP9_CX_SRCS-yes += encoder/vp9_bitstream.h
-VP9_CX_SRCS-yes += encoder/vp9_encodemb.h
-VP9_CX_SRCS-yes += encoder/vp9_encodemv.h
-VP9_CX_SRCS-yes += encoder/vp9_extend.h
-VP9_CX_SRCS-yes += encoder/vp9_firstpass.h
-VP9_CX_SRCS-yes += encoder/vp9_lookahead.c
-VP9_CX_SRCS-yes += encoder/vp9_lookahead.h
-VP9_CX_SRCS-yes += encoder/vp9_mcomp.h
-VP9_CX_SRCS-yes += encoder/vp9_encoder.h
-VP9_CX_SRCS-yes += encoder/vp9_quantize.h
-VP9_CX_SRCS-yes += encoder/vp9_ratectrl.h
-VP9_CX_SRCS-yes += encoder/vp9_rd.h
-VP9_CX_SRCS-yes += encoder/vp9_rdopt.h
-VP9_CX_SRCS-yes += encoder/vp9_pickmode.h
-VP9_CX_SRCS-yes += encoder/vp9_svc_layercontext.h
-VP9_CX_SRCS-yes += encoder/vp9_tokenize.h
-VP9_CX_SRCS-yes += encoder/vp9_treewriter.h
-VP9_CX_SRCS-yes += encoder/vp9_mcomp.c
-VP9_CX_SRCS-yes += encoder/vp9_encoder.c
-VP9_CX_SRCS-yes += encoder/vp9_picklpf.c
-VP9_CX_SRCS-yes += encoder/vp9_picklpf.h
-VP9_CX_SRCS-yes += encoder/vp9_quantize.c
-VP9_CX_SRCS-yes += encoder/vp9_ratectrl.c
-VP9_CX_SRCS-yes += encoder/vp9_rd.c
-VP9_CX_SRCS-yes += encoder/vp9_rdopt.c
-VP9_CX_SRCS-yes += encoder/vp9_pickmode.c
-VP9_CX_SRCS-yes += encoder/vp9_segmentation.c
-VP9_CX_SRCS-yes += encoder/vp9_segmentation.h
-VP9_CX_SRCS-yes += encoder/vp9_speed_features.c
-VP9_CX_SRCS-yes += encoder/vp9_speed_features.h
-VP9_CX_SRCS-yes += encoder/vp9_subexp.c
-VP9_CX_SRCS-yes += encoder/vp9_subexp.h
-VP9_CX_SRCS-yes += encoder/vp9_svc_layercontext.c
-VP9_CX_SRCS-yes += encoder/vp9_resize.c
-VP9_CX_SRCS-yes += encoder/vp9_resize.h
-VP9_CX_SRCS-$(CONFIG_INTERNAL_STATS) += encoder/vp9_blockiness.c
-
-VP9_CX_SRCS-yes += encoder/vp9_tokenize.c
-VP9_CX_SRCS-yes += encoder/vp9_treewriter.c
-VP9_CX_SRCS-yes += encoder/vp9_aq_variance.c
-VP9_CX_SRCS-yes += encoder/vp9_aq_variance.h
-VP9_CX_SRCS-yes += encoder/vp9_aq_360.c
-VP9_CX_SRCS-yes += encoder/vp9_aq_360.h
-VP9_CX_SRCS-yes += encoder/vp9_aq_cyclicrefresh.c
-VP9_CX_SRCS-yes += encoder/vp9_aq_cyclicrefresh.h
-VP9_CX_SRCS-yes += encoder/vp9_aq_complexity.c
-VP9_CX_SRCS-yes += encoder/vp9_aq_complexity.h
-VP9_CX_SRCS-yes += encoder/vp9_skin_detection.c
-VP9_CX_SRCS-yes += encoder/vp9_skin_detection.h
-VP9_CX_SRCS-yes += encoder/vp9_noise_estimate.c
-VP9_CX_SRCS-yes += encoder/vp9_noise_estimate.h
-ifeq ($(CONFIG_VP9_POSTPROC),yes)
-VP9_CX_SRCS-$(CONFIG_INTERNAL_STATS) += common/vp9_postproc.h
-VP9_CX_SRCS-$(CONFIG_INTERNAL_STATS) += common/vp9_postproc.c
-endif
-VP9_CX_SRCS-yes += encoder/vp9_temporal_filter.c
-VP9_CX_SRCS-yes += encoder/vp9_temporal_filter.h
-VP9_CX_SRCS-yes += encoder/vp9_mbgraph.c
-VP9_CX_SRCS-yes += encoder/vp9_mbgraph.h
-
-VP9_CX_SRCS-$(HAVE_SSE2) += encoder/x86/vp9_temporal_filter_apply_sse2.asm
-VP9_CX_SRCS-$(HAVE_SSE2) += encoder/x86/vp9_quantize_sse2.c
-VP9_CX_SRCS-$(HAVE_AVX) += encoder/x86/vp9_diamond_search_sad_avx.c
-ifeq ($(CONFIG_VP9_HIGHBITDEPTH),yes)
-VP9_CX_SRCS-$(HAVE_SSE2) += encoder/x86/vp9_highbd_block_error_intrin_sse2.c
-endif
-
-VP9_CX_SRCS-$(HAVE_SSE2) += encoder/x86/vp9_dct_sse2.asm
-ifeq ($(CONFIG_VP9_HIGHBITDEPTH),yes)
-VP9_CX_SRCS-$(HAVE_SSE2) += encoder/x86/vp9_highbd_error_sse2.asm
-VP9_CX_SRCS-$(HAVE_AVX) += encoder/x86/vp9_highbd_error_avx.asm
-else
-VP9_CX_SRCS-$(HAVE_SSE2) += encoder/x86/vp9_error_sse2.asm
-endif
-
-ifeq ($(ARCH_X86_64),yes)
-VP9_CX_SRCS-$(HAVE_SSSE3) += encoder/x86/vp9_quantize_ssse3_x86_64.asm
-endif
-
-VP9_CX_SRCS-$(HAVE_SSE2) += encoder/x86/vp9_dct_intrin_sse2.c
-VP9_CX_SRCS-$(HAVE_SSSE3) += encoder/x86/vp9_dct_ssse3.c
-ifneq ($(CONFIG_VP9_HIGHBITDEPTH),yes)
-VP9_CX_SRCS-$(HAVE_SSSE3) += encoder/x86/vp9_frame_scale_ssse3.c
-endif
-
-ifeq ($(CONFIG_VP9_TEMPORAL_DENOISING),yes)
-VP9_CX_SRCS-$(HAVE_SSE2) += encoder/x86/vp9_denoiser_sse2.c
-endif
-
-VP9_CX_SRCS-$(HAVE_AVX2) += encoder/x86/vp9_error_intrin_avx2.c
-
-ifneq ($(CONFIG_VP9_HIGHBITDEPTH),yes)
-VP9_CX_SRCS-$(HAVE_NEON) += encoder/arm/neon/vp9_dct_neon.c
-VP9_CX_SRCS-$(HAVE_NEON) += encoder/arm/neon/vp9_error_neon.c
-endif
-VP9_CX_SRCS-$(HAVE_NEON) += encoder/arm/neon/vp9_quantize_neon.c
-
-VP9_CX_SRCS-$(HAVE_MSA) += encoder/mips/msa/vp9_error_msa.c
-VP9_CX_SRCS-$(HAVE_MSA) += encoder/mips/msa/vp9_fdct4x4_msa.c
-VP9_CX_SRCS-$(HAVE_MSA) += encoder/mips/msa/vp9_fdct8x8_msa.c
-VP9_CX_SRCS-$(HAVE_MSA) += encoder/mips/msa/vp9_fdct16x16_msa.c
-VP9_CX_SRCS-$(HAVE_MSA) += encoder/mips/msa/vp9_fdct_msa.h
-VP9_CX_SRCS-$(HAVE_MSA) += encoder/mips/msa/vp9_temporal_filter_msa.c
-
-VP9_CX_SRCS-yes := $(filter-out $(VP9_CX_SRCS_REMOVE-yes),$(VP9_CX_SRCS-yes))
diff --git a/vp9/vp9dx.mk b/vp9/vp9dx.mk
deleted file mode 100644 (file)
index 4c6fd00..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-##
-##  Copyright (c) 2010 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.
-##
-
-VP9_DX_EXPORTS += exports_dec
-
-VP9_DX_SRCS-yes += $(VP9_COMMON_SRCS-yes)
-VP9_DX_SRCS-no  += $(VP9_COMMON_SRCS-no)
-VP9_DX_SRCS_REMOVE-yes += $(VP9_COMMON_SRCS_REMOVE-yes)
-VP9_DX_SRCS_REMOVE-no  += $(VP9_COMMON_SRCS_REMOVE-no)
-
-VP9_DX_SRCS-yes += vp9_dx_iface.c
-VP9_DX_SRCS-yes += vp9_dx_iface.h
-
-VP9_DX_SRCS-yes += decoder/vp9_decodemv.c
-VP9_DX_SRCS-yes += decoder/vp9_decodeframe.c
-VP9_DX_SRCS-yes += decoder/vp9_decodeframe.h
-VP9_DX_SRCS-yes += decoder/vp9_detokenize.c
-VP9_DX_SRCS-yes += decoder/vp9_decodemv.h
-VP9_DX_SRCS-yes += decoder/vp9_detokenize.h
-VP9_DX_SRCS-yes += decoder/vp9_dthread.c
-VP9_DX_SRCS-yes += decoder/vp9_dthread.h
-VP9_DX_SRCS-yes += decoder/vp9_decoder.c
-VP9_DX_SRCS-yes += decoder/vp9_decoder.h
-VP9_DX_SRCS-yes += decoder/vp9_dsubexp.c
-VP9_DX_SRCS-yes += decoder/vp9_dsubexp.h
-
-VP9_DX_SRCS-yes := $(filter-out $(VP9_DX_SRCS_REMOVE-yes),$(VP9_DX_SRCS-yes))
index aaef8c03e5103fdf0da314c2f7cbb3c3c5b2596a..ab6e69ac7d5475e7493325fa88af11552cd1cd72 100644 (file)
@@ -57,22 +57,6 @@ typedef unsigned int (*vpx_subp_avg_variance_fn_t)(const uint8_t *a,
                                                    int b_stride,
                                                    unsigned int *sse,
                                                    const uint8_t *second_pred);
-#if CONFIG_VP8
-typedef struct variance_vtable {
-  vpx_sad_fn_t            sdf;
-  vpx_variance_fn_t       vf;
-  vpx_subpixvariance_fn_t svf;
-  vpx_variance_fn_t       svf_halfpix_h;
-  vpx_variance_fn_t       svf_halfpix_v;
-  vpx_variance_fn_t       svf_halfpix_hv;
-  vpx_sad_multi_fn_t      sdx3f;
-  vpx_sad_multi_fn_t      sdx8f;
-  vpx_sad_multi_d_fn_t    sdx4df;
-#if ARCH_X86 || ARCH_X86_64
-  vp8_copy32xn_fn_t       copymem;
-#endif
-} vp8_variance_fn_ptr_t;
-#endif  // CONFIG_VP8
 
 #if CONFIG_VP10 && CONFIG_EXT_INTER
 typedef unsigned int(*vpx_masked_sad_fn_t)(const uint8_t *src,
index 43a78a8784772433eda29fc53b3e4127e05ea3b6..c221bdf60ee05515b21471e2d4afb4de6efa4005 100644 (file)
@@ -185,7 +185,7 @@ DSP_SRCS-yes            += txfm_common.h
 DSP_SRCS-$(HAVE_SSE2)   += x86/txfm_common_sse2.h
 DSP_SRCS-$(HAVE_MSA)    += mips/txfm_macros_msa.h
 # forward transform
-ifneq ($(filter yes,$(CONFIG_VP9_ENCODER) $(CONFIG_VP10_ENCODER)),)
+ifeq ($(CONFIG_VP10),yes)
 DSP_SRCS-yes            += fwd_txfm.c
 DSP_SRCS-yes            += fwd_txfm.h
 DSP_SRCS-$(HAVE_SSE2)   += x86/fwd_txfm_sse2.h
index 9dd508d8e392fca8266717397ffb252bde5a7291..217ac57f5ee7f693a3512e38502f0f817716801e 100644 (file)
@@ -15,9 +15,6 @@
 #include "vpx_mem/vpx_mem.h"
 #include "vpx_ports/mem.h"
 #include "vpx_scale/yv12config.h"
-#if CONFIG_VP9_HIGHBITDEPTH
-#include "vp9/common/vp9_common.h"
-#endif
 
 static void extend_plane(uint8_t *const src, int src_stride,
                          int width, int height,
index d96b39cb48a356749acdcf2db16c623b22abd7c4..67b3b51c7e1bdf1e00c9c3457b5be607870cb5fb 100644 (file)
--- a/vpxdec.c
+++ b/vpxdec.c
@@ -28,7 +28,7 @@
 #include "vpx_ports/mem_ops.h"
 #include "vpx_ports/vpx_timer.h"
 
-#if CONFIG_VP8_DECODER || CONFIG_VP9_DECODER || CONFIG_VP10_DECODER
+#if CONFIG_VP10_DECODER
 #include "vpx/vp8dx.h"
 #endif
 
@@ -116,34 +116,6 @@ static const arg_def_t *all_args[] = {
   NULL
 };
 
-#if CONFIG_VP8_DECODER
-static const arg_def_t addnoise_level = ARG_DEF(
-    NULL, "noise-level", 1, "Enable VP8 postproc add noise");
-static const arg_def_t deblock = ARG_DEF(
-    NULL, "deblock", 0, "Enable VP8 deblocking");
-static const arg_def_t demacroblock_level = ARG_DEF(
-    NULL, "demacroblock-level", 1, "Enable VP8 demacroblocking, w/ level");
-static const arg_def_t pp_debug_info = ARG_DEF(
-    NULL, "pp-debug-info", 1, "Enable VP8 visible debug info");
-static const arg_def_t pp_disp_ref_frame = ARG_DEF(
-    NULL, "pp-dbg-ref-frame", 1,
-    "Display only selected reference frame per macro block");
-static const arg_def_t pp_disp_mb_modes = ARG_DEF(
-    NULL, "pp-dbg-mb-modes", 1, "Display only selected macro block modes");
-static const arg_def_t pp_disp_b_modes = ARG_DEF(
-    NULL, "pp-dbg-b-modes", 1, "Display only selected block modes");
-static const arg_def_t pp_disp_mvs = ARG_DEF(
-    NULL, "pp-dbg-mvs", 1, "Draw only selected motion vectors");
-static const arg_def_t mfqe = ARG_DEF(
-    NULL, "mfqe", 0, "Enable multiframe quality enhancement");
-
-static const arg_def_t *vp8_pp_args[] = {
-  &addnoise_level, &deblock, &demacroblock_level, &pp_debug_info,
-  &pp_disp_ref_frame, &pp_disp_mb_modes, &pp_disp_b_modes, &pp_disp_mvs, &mfqe,
-  NULL
-};
-#endif
-
 #if CONFIG_LIBYUV
 static INLINE int libyuv_scale(vpx_image_t *src, vpx_image_t *dst,
                                   FilterModeEnum mode) {
@@ -187,10 +159,6 @@ void usage_exit(void) {
   fprintf(stderr, "Usage: %s <options> filename\n\n"
           "Options:\n", exec_name);
   arg_show_usage(stderr, all_args);
-#if CONFIG_VP8_DECODER
-  fprintf(stderr, "\nVP8 Postprocessing Options:\n");
-  arg_show_usage(stderr, vp8_pp_args);
-#endif
   fprintf(stderr,
           "\nOutput File Patterns:\n\n"
           "  The -o argument specifies the name of the file(s) to "
@@ -578,13 +546,6 @@ static int main_loop(int argc, const char **argv_) {
   int                     tile_row = -1;
   int                     tile_col = -1;
 #endif  // CONFIG_EXT_TILE
-#if CONFIG_VP8_DECODER
-  vp8_postproc_cfg_t      vp8_pp_cfg = {0};
-  int                     vp8_dbg_color_ref_frame = 0;
-  int                     vp8_dbg_color_mb_modes = 0;
-  int                     vp8_dbg_color_b_modes = 0;
-  int                     vp8_dbg_display_mv = 0;
-#endif
   int                     frames_corrupted = 0;
   int                     dec_flags = 0;
   int                     do_scale = 0;
@@ -679,57 +640,6 @@ static int main_loop(int argc, const char **argv_) {
     else if (arg_match(&arg, &tilec, argi))
       tile_col = arg_parse_int(&arg);
 #endif  // CONFIG_EXT_TILE
-#if CONFIG_VP8_DECODER
-    else if (arg_match(&arg, &addnoise_level, argi)) {
-      postproc = 1;
-      vp8_pp_cfg.post_proc_flag |= VP8_ADDNOISE;
-      vp8_pp_cfg.noise_level = arg_parse_uint(&arg);
-    } else if (arg_match(&arg, &demacroblock_level, argi)) {
-      postproc = 1;
-      vp8_pp_cfg.post_proc_flag |= VP8_DEMACROBLOCK;
-      vp8_pp_cfg.deblocking_level = arg_parse_uint(&arg);
-    } else if (arg_match(&arg, &deblock, argi)) {
-      postproc = 1;
-      vp8_pp_cfg.post_proc_flag |= VP8_DEBLOCK;
-    } else if (arg_match(&arg, &mfqe, argi)) {
-      postproc = 1;
-      vp8_pp_cfg.post_proc_flag |= VP8_MFQE;
-    } else if (arg_match(&arg, &pp_debug_info, argi)) {
-      unsigned int level = arg_parse_uint(&arg);
-
-      postproc = 1;
-      vp8_pp_cfg.post_proc_flag &= ~0x7;
-
-      if (level)
-        vp8_pp_cfg.post_proc_flag |= level;
-    } else if (arg_match(&arg, &pp_disp_ref_frame, argi)) {
-      unsigned int flags = arg_parse_int(&arg);
-      if (flags) {
-        postproc = 1;
-        vp8_dbg_color_ref_frame = flags;
-      }
-    } else if (arg_match(&arg, &pp_disp_mb_modes, argi)) {
-      unsigned int flags = arg_parse_int(&arg);
-      if (flags) {
-        postproc = 1;
-        vp8_dbg_color_mb_modes = flags;
-      }
-    } else if (arg_match(&arg, &pp_disp_b_modes, argi)) {
-      unsigned int flags = arg_parse_int(&arg);
-      if (flags) {
-        postproc = 1;
-        vp8_dbg_color_b_modes = flags;
-      }
-    } else if (arg_match(&arg, &pp_disp_mvs, argi)) {
-      unsigned int flags = arg_parse_int(&arg);
-      if (flags) {
-        postproc = 1;
-        vp8_dbg_display_mv = flags;
-      }
-    } else if (arg_match(&arg, &error_concealment, argi)) {
-      ec_enabled = 1;
-    }
-#endif  // CONFIG_VP8_DECODER
     else
       argj++;
   }
@@ -830,47 +740,6 @@ static int main_loop(int argc, const char **argv_) {
   if (!quiet)
     fprintf(stderr, "%s\n", decoder.name);
 
-#if CONFIG_VP8_DECODER
-  if (vp8_pp_cfg.post_proc_flag
-      && vpx_codec_control(&decoder, VP8_SET_POSTPROC, &vp8_pp_cfg)) {
-    fprintf(stderr, "Failed to configure postproc: %s\n",
-            vpx_codec_error(&decoder));
-    return EXIT_FAILURE;
-  }
-
-  if (vp8_dbg_color_ref_frame
-      && vpx_codec_control(&decoder, VP8_SET_DBG_COLOR_REF_FRAME,
-                           vp8_dbg_color_ref_frame)) {
-    fprintf(stderr, "Failed to configure reference block visualizer: %s\n",
-            vpx_codec_error(&decoder));
-    return EXIT_FAILURE;
-  }
-
-  if (vp8_dbg_color_mb_modes
-      && vpx_codec_control(&decoder, VP8_SET_DBG_COLOR_MB_MODES,
-                           vp8_dbg_color_mb_modes)) {
-    fprintf(stderr, "Failed to configure macro block visualizer: %s\n",
-            vpx_codec_error(&decoder));
-    return EXIT_FAILURE;
-  }
-
-  if (vp8_dbg_color_b_modes
-      && vpx_codec_control(&decoder, VP8_SET_DBG_COLOR_B_MODES,
-                           vp8_dbg_color_b_modes)) {
-    fprintf(stderr, "Failed to configure block visualizer: %s\n",
-            vpx_codec_error(&decoder));
-    return EXIT_FAILURE;
-  }
-
-  if (vp8_dbg_display_mv
-      && vpx_codec_control(&decoder, VP8_SET_DBG_DISPLAY_MV,
-                           vp8_dbg_display_mv)) {
-    fprintf(stderr, "Failed to configure motion vector visualizer: %s\n",
-            vpx_codec_error(&decoder));
-    return EXIT_FAILURE;
-  }
-#endif
-
 #if CONFIG_VP10_DECODER && CONFIG_EXT_TILE
   if (strncmp(decoder.name, "WebM Project VP10", 17) == 0) {
     if (vpx_codec_control(&decoder, VP10_SET_DECODE_TILE_ROW, tile_row)) {
index 64633345005ef36e9b3cb0298961faab0e99a946..bfcf81c3427c3402037c6a0ac4a096ccd443bce8 100644 (file)
--- a/vpxenc.c
+++ b/vpxenc.c
 #include "./ivfenc.h"
 #include "./tools_common.h"
 
-#if CONFIG_VP8_ENCODER || CONFIG_VP9_ENCODER || CONFIG_VP10_ENCODER
+#if CONFIG_VP10_ENCODER
 #include "vpx/vp8cx.h"
 #endif
-#if CONFIG_VP8_DECODER || CONFIG_VP9_DECODER || CONFIG_VP10_DECODER
+#if CONFIG_VP10_DECODER
 #include "vpx/vp8dx.h"
 #endif
 
@@ -350,31 +350,8 @@ static const arg_def_t cq_level = ARG_DEF(
 static const arg_def_t max_intra_rate_pct = ARG_DEF(
     NULL, "max-intra-rate", 1, "Max I-frame bitrate (pct)");
 
-#if CONFIG_VP8_ENCODER
-static const arg_def_t cpu_used_vp8 = ARG_DEF(
-    NULL, "cpu-used", 1, "CPU Used (-16..16)");
-static const arg_def_t token_parts = ARG_DEF(
-    NULL, "token-parts", 1, "Number of token partitions to use, log2");
-static const arg_def_t screen_content_mode = ARG_DEF(
-    NULL, "screen-content-mode", 1, "Screen content mode");
-static const arg_def_t *vp8_args[] = {
-  &cpu_used_vp8, &auto_altref, &noise_sens, &sharpness, &static_thresh,
-  &token_parts, &arnr_maxframes, &arnr_strength, &arnr_type,
-  &tune_ssim, &cq_level, &max_intra_rate_pct, &screen_content_mode,
-  NULL
-};
-static const int vp8_arg_ctrl_map[] = {
-  VP8E_SET_CPUUSED, VP8E_SET_ENABLEAUTOALTREF,
-  VP8E_SET_NOISE_SENSITIVITY, VP8E_SET_SHARPNESS, VP8E_SET_STATIC_THRESHOLD,
-  VP8E_SET_TOKEN_PARTITIONS,
-  VP8E_SET_ARNR_MAXFRAMES, VP8E_SET_ARNR_STRENGTH, VP8E_SET_ARNR_TYPE,
-  VP8E_SET_TUNING, VP8E_SET_CQ_LEVEL, VP8E_SET_MAX_INTRA_BITRATE_PCT,
-  VP8E_SET_SCREEN_CONTENT_MODE,
-  0
-};
-#endif
 
-#if CONFIG_VP9_ENCODER || CONFIG_VP10_ENCODER
+#if CONFIG_VP10_ENCODER
 static const arg_def_t cpu_used_vp9 = ARG_DEF(
     NULL, "cpu-used", 1, "CPU Used (-8..8)");
 static const arg_def_t tile_cols = ARG_DEF(
@@ -451,34 +428,6 @@ static const arg_def_t target_level = ARG_DEF(
     " 11: level 1.1; ... 62: level 6.2)");
 #endif
 
-#if CONFIG_VP9_ENCODER
-static const arg_def_t *vp9_args[] = {
-  &cpu_used_vp9, &auto_altref, &sharpness, &static_thresh,
-  &tile_cols, &tile_rows, &arnr_maxframes, &arnr_strength, &arnr_type,
-  &tune_ssim, &cq_level, &max_intra_rate_pct, &max_inter_rate_pct,
-  &gf_cbr_boost_pct, &lossless,
-  &frame_parallel_decoding, &aq_mode, &frame_periodic_boost,
-  &noise_sens, &tune_content, &input_color_space,
-  &min_gf_interval, &max_gf_interval, &target_level,
-#if CONFIG_VP9_HIGHBITDEPTH
-  &bitdeptharg, &inbitdeptharg,
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-  NULL
-};
-static const int vp9_arg_ctrl_map[] = {
-  VP8E_SET_CPUUSED, VP8E_SET_ENABLEAUTOALTREF,
-  VP8E_SET_SHARPNESS, VP8E_SET_STATIC_THRESHOLD,
-  VP9E_SET_TILE_COLUMNS, VP9E_SET_TILE_ROWS,
-  VP8E_SET_ARNR_MAXFRAMES, VP8E_SET_ARNR_STRENGTH, VP8E_SET_ARNR_TYPE,
-  VP8E_SET_TUNING, VP8E_SET_CQ_LEVEL, VP8E_SET_MAX_INTRA_BITRATE_PCT,
-  VP9E_SET_MAX_INTER_BITRATE_PCT, VP9E_SET_GF_CBR_BOOST_PCT,
-  VP9E_SET_LOSSLESS, VP9E_SET_FRAME_PARALLEL_DECODING, VP9E_SET_AQ_MODE,
-  VP9E_SET_FRAME_PERIODIC_BOOST, VP9E_SET_NOISE_SENSITIVITY,
-  VP9E_SET_TUNE_CONTENT, VP9E_SET_COLOR_SPACE,
-  VP9E_SET_MIN_GF_INTERVAL, VP9E_SET_MAX_GF_INTERVAL, VP9E_SET_TARGET_LEVEL,
-  0
-};
-#endif
 
 #if CONFIG_VP10_ENCODER
 #if CONFIG_EXT_PARTITION
@@ -545,14 +494,6 @@ void usage_exit(void) {
   arg_show_usage(stderr, rc_twopass_args);
   fprintf(stderr, "\nKeyframe Placement Options:\n");
   arg_show_usage(stderr, kf_args);
-#if CONFIG_VP8_ENCODER
-  fprintf(stderr, "\nVP8 Specific Options:\n");
-  arg_show_usage(stderr, vp8_args);
-#endif
-#if CONFIG_VP9_ENCODER
-  fprintf(stderr, "\nVP9 Specific Options:\n");
-  arg_show_usage(stderr, vp9_args);
-#endif
 #if CONFIG_VP10_ENCODER
   fprintf(stderr, "\nVP10 Specific Options:\n");
   arg_show_usage(stderr, vp10_args);
@@ -804,10 +745,6 @@ static int compare_img(const vpx_image_t *const img1,
 #define NELEMENTS(x) (sizeof(x)/sizeof(x[0]))
 #if CONFIG_VP10_ENCODER
 #define ARG_CTRL_CNT_MAX NELEMENTS(vp10_arg_ctrl_map)
-#elif CONFIG_VP9_ENCODER
-#define ARG_CTRL_CNT_MAX NELEMENTS(vp9_arg_ctrl_map)
-#else
-#define ARG_CTRL_CNT_MAX NELEMENTS(vp8_arg_ctrl_map)
 #endif
 
 #if !CONFIG_WEBM_IO
@@ -971,7 +908,7 @@ static void parse_global_config(struct VpxEncoderConfig *global, char **argv) {
   }
   /* Validate global config */
   if (global->passes == 0) {
-#if CONFIG_VP9_ENCODER || CONFIG_VP10_ENCODER
+#if CONFIG_VP10_ENCODER
     // Make default VP9 passes = 2 until there is a better quality 1-pass
     // encoder
     if (global->codec != NULL && global->codec->name != NULL)
@@ -1119,16 +1056,6 @@ static int parse_stream_params(struct VpxEncoderConfig *global,
 
   // Handle codec specific options
   if (0) {
-#if CONFIG_VP8_ENCODER
-  } else if (strcmp(global->codec->name, "vp8") == 0) {
-    ctrl_args = vp8_args;
-    ctrl_args_map = vp8_arg_ctrl_map;
-#endif
-#if CONFIG_VP9_ENCODER
-  } else if (strcmp(global->codec->name, "vp9") == 0) {
-    ctrl_args = vp9_args;
-    ctrl_args_map = vp9_arg_ctrl_map;
-#endif
 #if CONFIG_VP10_ENCODER
   } else if (strcmp(global->codec->name, "vp10") == 0) {
     // TODO(jingning): Reuse VP9 specific encoder configuration parameters.