Bug 918550 - Update libvpx to 1.3.0 r=glandium,cpearce
authorJan Gerber <j@mailb.org>
Fri, 06 Dec 2013 03:19:00 -0800
changeset 159183 f4f8faa3771c4033c296e1eae6279d5b9d6d5d73
parent 159182 5880bbf6182c99fa3e12928f6982834dec6bd7b1
child 159184 e070e04b0795949266c592c172fc689e8c5b16ad
push id25775
push userryanvm@gmail.com
push dateFri, 06 Dec 2013 20:30:09 +0000
treeherdermozilla-central@e070e04b0795 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersglandium, cpearce
bugs918550
milestone28.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 918550 - Update libvpx to 1.3.0 r=glandium,cpearce This updates our in-tree copy of libvpx to the v1.3.0 git tag (2e88f2f2ec777259bda1714e72f1ecd2519bceb5) libvpx 1.3.0 adds support for VP9. VP9 support is built but not yet exposed with this commit. Our update.sh script is replaced with update.py that can update the build system to a given git commit. - checkout out upstream git - create platform dependend config files - add/remove changed libvpx files - update moz.build - warn about new build categories in libvpx
configure.in
media/libvpx/Makefile.in
media/libvpx/README_MOZILLA
media/libvpx/build/make/ads2gas.pl
media/libvpx/build/make/obj_int_extract.c
media/libvpx/build/make/thumb.pm
media/libvpx/moz.build
media/libvpx/sources.mozbuild
media/libvpx/third_party/x86inc/x86inc.asm
media/libvpx/update.py
media/libvpx/update.sh
media/libvpx/vp8/common/alloccommon.c
media/libvpx/vp8/common/arm/armv6/filter_v6.asm
media/libvpx/vp8/common/arm/armv6/idct_blk_v6.c
media/libvpx/vp8/common/arm/bilinearfilter_arm.c
media/libvpx/vp8/common/arm/filter_arm.c
media/libvpx/vp8/common/arm/loopfilter_arm.c
media/libvpx/vp8/common/arm/neon/idct_blk_neon.c
media/libvpx/vp8/common/arm/neon/vp8_subpixelvariance16x16_neon.asm
media/libvpx/vp8/common/arm/reconintra_arm.c
media/libvpx/vp8/common/arm/variance_arm.c
media/libvpx/vp8/common/asm_com_offsets.c
media/libvpx/vp8/common/dequantize.c
media/libvpx/vp8/common/filter.c
media/libvpx/vp8/common/filter.h
media/libvpx/vp8/common/findnearmv.h
media/libvpx/vp8/common/generic/systemdependent.c
media/libvpx/vp8/common/idct_blk.c
media/libvpx/vp8/common/invtrans.h
media/libvpx/vp8/common/loopfilter.c
media/libvpx/vp8/common/loopfilter.h
media/libvpx/vp8/common/loopfilter_filters.c
media/libvpx/vp8/common/mfqe.c
media/libvpx/vp8/common/onyx.h
media/libvpx/vp8/common/onyxc_int.h
media/libvpx/vp8/common/onyxd.h
media/libvpx/vp8/common/postproc.c
media/libvpx/vp8/common/reconinter.c
media/libvpx/vp8/common/reconintra.c
media/libvpx/vp8/common/reconintra4x4.c
media/libvpx/vp8/common/rtcd.c
media/libvpx/vp8/common/systemdependent.h
media/libvpx/vp8/common/variance_c.c
media/libvpx/vp8/common/x86/filter_x86.c
media/libvpx/vp8/common/x86/filter_x86.h
media/libvpx/vp8/common/x86/idct_blk_mmx.c
media/libvpx/vp8/common/x86/idct_blk_sse2.c
media/libvpx/vp8/common/x86/iwalsh_mmx.asm
media/libvpx/vp8/common/x86/loopfilter_block_sse2.asm
media/libvpx/vp8/common/x86/mfqe_sse2.asm
media/libvpx/vp8/common/x86/postproc_mmx.asm
media/libvpx/vp8/common/x86/recon_wrapper_sse2.c
media/libvpx/vp8/common/x86/sad_sse3.asm
media/libvpx/vp8/common/x86/variance_mmx.c
media/libvpx/vp8/common/x86/variance_sse2.c
media/libvpx/vp8/common/x86/variance_ssse3.c
media/libvpx/vp8/common/x86/vp8_asm_stubs.c
media/libvpx/vp8/decoder/asm_dec_offsets.c
media/libvpx/vp8/decoder/dboolhuff.c
media/libvpx/vp8/decoder/dboolhuff.h
media/libvpx/vp8/decoder/decodemv.c
media/libvpx/vp8/decoder/decodemv.h
media/libvpx/vp8/decoder/decoderthreading.h
media/libvpx/vp8/decoder/decodframe.c
media/libvpx/vp8/decoder/detokenize.h
media/libvpx/vp8/decoder/ec_types.h
media/libvpx/vp8/decoder/error_concealment.c
media/libvpx/vp8/decoder/error_concealment.h
media/libvpx/vp8/decoder/onyxd_if.c
media/libvpx/vp8/decoder/onyxd_int.h
media/libvpx/vp8/decoder/threading.c
media/libvpx/vp8/decoder/treereader.h
media/libvpx/vp8/encoder/arm/armv5te/boolhuff_armv5te.asm
media/libvpx/vp8/encoder/arm/armv5te/vp8_packtokens_armv5.asm
media/libvpx/vp8/encoder/arm/armv5te/vp8_packtokens_mbrow_armv5.asm
media/libvpx/vp8/encoder/arm/armv5te/vp8_packtokens_partitions_armv5.asm
media/libvpx/vp8/encoder/arm/armv6/vp8_fast_quantize_b_armv6.asm
media/libvpx/vp8/encoder/arm/armv6/vp8_subtract_armv6.asm
media/libvpx/vp8/encoder/arm/dct_arm.c
media/libvpx/vp8/encoder/arm/neon/fastquantizeb_neon.asm
media/libvpx/vp8/encoder/arm/neon/shortfdct_neon.asm
media/libvpx/vp8/encoder/arm/neon/subtract_neon.asm
media/libvpx/vp8/encoder/arm/quantize_arm.c
media/libvpx/vp8/encoder/asm_enc_offsets.c
media/libvpx/vp8/encoder/bitstream.c
media/libvpx/vp8/encoder/block.h
media/libvpx/vp8/encoder/boolhuff.c
media/libvpx/vp8/encoder/boolhuff.h
media/libvpx/vp8/encoder/dct.c
media/libvpx/vp8/encoder/denoising.c
media/libvpx/vp8/encoder/encodeframe.c
media/libvpx/vp8/encoder/encodeintra.c
media/libvpx/vp8/encoder/encodemb.c
media/libvpx/vp8/encoder/encodemv.c
media/libvpx/vp8/encoder/firstpass.c
media/libvpx/vp8/encoder/mcomp.c
media/libvpx/vp8/encoder/mcomp.h
media/libvpx/vp8/encoder/onyx_if.c
media/libvpx/vp8/encoder/onyx_int.h
media/libvpx/vp8/encoder/pickinter.c
media/libvpx/vp8/encoder/picklpf.c
media/libvpx/vp8/encoder/psnr.c
media/libvpx/vp8/encoder/quantize.c
media/libvpx/vp8/encoder/ratectrl.c
media/libvpx/vp8/encoder/rdopt.c
media/libvpx/vp8/encoder/temporal_filter.c
media/libvpx/vp8/encoder/tokenize.c
media/libvpx/vp8/encoder/tokenize.h
media/libvpx/vp8/encoder/vp8_asm_enc_offsets.c
media/libvpx/vp8/encoder/x86/dct_sse2.asm
media/libvpx/vp8/encoder/x86/denoising_sse2.c
media/libvpx/vp8/encoder/x86/quantize_sse2.asm
media/libvpx/vp8/encoder/x86/quantize_sse2.c
media/libvpx/vp8/encoder/x86/quantize_sse4.asm
media/libvpx/vp8/encoder/x86/quantize_ssse3.asm
media/libvpx/vp8/encoder/x86/ssim_opt.asm
media/libvpx/vp8/encoder/x86/temporal_filter_apply_sse2.asm
media/libvpx/vp8/encoder/x86/vp8_enc_stubs_mmx.c
media/libvpx/vp8/encoder/x86/vp8_enc_stubs_sse2.c
media/libvpx/vp8/vp8_cx_iface.c
media/libvpx/vp8/vp8_dx_iface.c
media/libvpx/vp8_rtcd.h
media/libvpx/vp8_rtcd_armv7-android-gcc.h
media/libvpx/vp8_rtcd_generic-gnu.h
media/libvpx/vp8_rtcd_x86-darwin9-gcc.h
media/libvpx/vp8_rtcd_x86-linux-gcc.h
media/libvpx/vp8_rtcd_x86-win32-vs8.h
media/libvpx/vp8_rtcd_x86_64-darwin9-gcc.h
media/libvpx/vp8_rtcd_x86_64-linux-gcc.h
media/libvpx/vp8_rtcd_x86_64-win64-vs8.h
media/libvpx/vp9/common/arm/neon/vp9_avg_neon.asm
media/libvpx/vp9/common/arm/neon/vp9_convolve8_avg_neon.asm
media/libvpx/vp9/common/arm/neon/vp9_convolve8_neon.asm
media/libvpx/vp9/common/arm/neon/vp9_convolve_neon.c
media/libvpx/vp9/common/arm/neon/vp9_copy_neon.asm
media/libvpx/vp9/common/arm/neon/vp9_dc_only_idct_add_neon.asm
media/libvpx/vp9/common/arm/neon/vp9_idct16x16_neon.c
media/libvpx/vp9/common/arm/neon/vp9_loopfilter_neon.asm
media/libvpx/vp9/common/arm/neon/vp9_mb_lpf_neon.asm
media/libvpx/vp9/common/arm/neon/vp9_save_reg_neon.asm
media/libvpx/vp9/common/arm/neon/vp9_short_idct16x16_1_add_neon.asm
media/libvpx/vp9/common/arm/neon/vp9_short_idct16x16_add_neon.asm
media/libvpx/vp9/common/arm/neon/vp9_short_idct32x32_1_add_neon.asm
media/libvpx/vp9/common/arm/neon/vp9_short_idct32x32_add_neon.asm
media/libvpx/vp9/common/arm/neon/vp9_short_idct4x4_1_add_neon.asm
media/libvpx/vp9/common/arm/neon/vp9_short_idct4x4_add_neon.asm
media/libvpx/vp9/common/arm/neon/vp9_short_idct8x8_1_add_neon.asm
media/libvpx/vp9/common/arm/neon/vp9_short_idct8x8_add_neon.asm
media/libvpx/vp9/common/arm/neon/vp9_short_iht4x4_add_neon.asm
media/libvpx/vp9/common/arm/neon/vp9_short_iht8x8_add_neon.asm
media/libvpx/vp9/common/generic/vp9_systemdependent.c
media/libvpx/vp9/common/vp9_alloccommon.c
media/libvpx/vp9/common/vp9_alloccommon.h
media/libvpx/vp9/common/vp9_blockd.h
media/libvpx/vp9/common/vp9_common.h
media/libvpx/vp9/common/vp9_common_data.c
media/libvpx/vp9/common/vp9_common_data.h
media/libvpx/vp9/common/vp9_convolve.c
media/libvpx/vp9/common/vp9_convolve.h
media/libvpx/vp9/common/vp9_debugmodes.c
media/libvpx/vp9/common/vp9_default_coef_probs.h
media/libvpx/vp9/common/vp9_entropy.c
media/libvpx/vp9/common/vp9_entropy.h
media/libvpx/vp9/common/vp9_entropymode.c
media/libvpx/vp9/common/vp9_entropymode.h
media/libvpx/vp9/common/vp9_entropymv.c
media/libvpx/vp9/common/vp9_entropymv.h
media/libvpx/vp9/common/vp9_enums.h
media/libvpx/vp9/common/vp9_extend.c
media/libvpx/vp9/common/vp9_extend.h
media/libvpx/vp9/common/vp9_filter.c
media/libvpx/vp9/common/vp9_filter.h
media/libvpx/vp9/common/vp9_findnearmv.c
media/libvpx/vp9/common/vp9_findnearmv.h
media/libvpx/vp9/common/vp9_idct.c
media/libvpx/vp9/common/vp9_idct.h
media/libvpx/vp9/common/vp9_loopfilter.c
media/libvpx/vp9/common/vp9_loopfilter.h
media/libvpx/vp9/common/vp9_loopfilter_filters.c
media/libvpx/vp9/common/vp9_mv.h
media/libvpx/vp9/common/vp9_mvref_common.c
media/libvpx/vp9/common/vp9_mvref_common.h
media/libvpx/vp9/common/vp9_onyx.h
media/libvpx/vp9/common/vp9_onyxc_int.h
media/libvpx/vp9/common/vp9_postproc.c
media/libvpx/vp9/common/vp9_postproc.h
media/libvpx/vp9/common/vp9_ppflags.h
media/libvpx/vp9/common/vp9_pragmas.h
media/libvpx/vp9/common/vp9_pred_common.c
media/libvpx/vp9/common/vp9_pred_common.h
media/libvpx/vp9/common/vp9_quant_common.c
media/libvpx/vp9/common/vp9_quant_common.h
media/libvpx/vp9/common/vp9_reconinter.c
media/libvpx/vp9/common/vp9_reconinter.h
media/libvpx/vp9/common/vp9_reconintra.c
media/libvpx/vp9/common/vp9_reconintra.h
media/libvpx/vp9/common/vp9_rtcd.c
media/libvpx/vp9/common/vp9_sadmxn.h
media/libvpx/vp9/common/vp9_scale.c
media/libvpx/vp9/common/vp9_scale.h
media/libvpx/vp9/common/vp9_scan.c
media/libvpx/vp9/common/vp9_scan.h
media/libvpx/vp9/common/vp9_seg_common.c
media/libvpx/vp9/common/vp9_seg_common.h
media/libvpx/vp9/common/vp9_systemdependent.h
media/libvpx/vp9/common/vp9_tile_common.c
media/libvpx/vp9/common/vp9_tile_common.h
media/libvpx/vp9/common/vp9_treecoder.c
media/libvpx/vp9/common/vp9_treecoder.h
media/libvpx/vp9/common/x86/vp9_asm_stubs.c
media/libvpx/vp9/common/x86/vp9_copy_sse2.asm
media/libvpx/vp9/common/x86/vp9_idct_intrin_sse2.c
media/libvpx/vp9/common/x86/vp9_intrapred_sse2.asm
media/libvpx/vp9/common/x86/vp9_intrapred_ssse3.asm
media/libvpx/vp9/common/x86/vp9_loopfilter_intrin_avx2.c
media/libvpx/vp9/common/x86/vp9_loopfilter_intrin_sse2.c
media/libvpx/vp9/common/x86/vp9_loopfilter_mmx.asm
media/libvpx/vp9/common/x86/vp9_postproc_mmx.asm
media/libvpx/vp9/common/x86/vp9_postproc_sse2.asm
media/libvpx/vp9/common/x86/vp9_postproc_x86.h
media/libvpx/vp9/common/x86/vp9_subpixel_8t_sse2.asm
media/libvpx/vp9/common/x86/vp9_subpixel_8t_ssse3.asm
media/libvpx/vp9/decoder/vp9_dboolhuff.c
media/libvpx/vp9/decoder/vp9_dboolhuff.h
media/libvpx/vp9/decoder/vp9_decodemv.c
media/libvpx/vp9/decoder/vp9_decodemv.h
media/libvpx/vp9/decoder/vp9_decodframe.c
media/libvpx/vp9/decoder/vp9_decodframe.h
media/libvpx/vp9/decoder/vp9_detokenize.c
media/libvpx/vp9/decoder/vp9_detokenize.h
media/libvpx/vp9/decoder/vp9_dsubexp.c
media/libvpx/vp9/decoder/vp9_dsubexp.h
media/libvpx/vp9/decoder/vp9_onyxd.h
media/libvpx/vp9/decoder/vp9_onyxd_if.c
media/libvpx/vp9/decoder/vp9_onyxd_int.h
media/libvpx/vp9/decoder/vp9_read_bit_buffer.h
media/libvpx/vp9/decoder/vp9_thread.c
media/libvpx/vp9/decoder/vp9_thread.h
media/libvpx/vp9/decoder/vp9_treereader.h
media/libvpx/vp9/encoder/vp9_bitstream.c
media/libvpx/vp9/encoder/vp9_bitstream.h
media/libvpx/vp9/encoder/vp9_block.h
media/libvpx/vp9/encoder/vp9_boolhuff.c
media/libvpx/vp9/encoder/vp9_boolhuff.h
media/libvpx/vp9/encoder/vp9_dct.c
media/libvpx/vp9/encoder/vp9_dct.h
media/libvpx/vp9/encoder/vp9_encodeframe.c
media/libvpx/vp9/encoder/vp9_encodeframe.h
media/libvpx/vp9/encoder/vp9_encodeintra.c
media/libvpx/vp9/encoder/vp9_encodeintra.h
media/libvpx/vp9/encoder/vp9_encodemb.c
media/libvpx/vp9/encoder/vp9_encodemb.h
media/libvpx/vp9/encoder/vp9_encodemv.c
media/libvpx/vp9/encoder/vp9_encodemv.h
media/libvpx/vp9/encoder/vp9_firstpass.c
media/libvpx/vp9/encoder/vp9_firstpass.h
media/libvpx/vp9/encoder/vp9_lookahead.c
media/libvpx/vp9/encoder/vp9_lookahead.h
media/libvpx/vp9/encoder/vp9_mbgraph.c
media/libvpx/vp9/encoder/vp9_mbgraph.h
media/libvpx/vp9/encoder/vp9_mcomp.c
media/libvpx/vp9/encoder/vp9_mcomp.h
media/libvpx/vp9/encoder/vp9_modecosts.c
media/libvpx/vp9/encoder/vp9_modecosts.h
media/libvpx/vp9/encoder/vp9_onyx_if.c
media/libvpx/vp9/encoder/vp9_onyx_int.h
media/libvpx/vp9/encoder/vp9_picklpf.c
media/libvpx/vp9/encoder/vp9_picklpf.h
media/libvpx/vp9/encoder/vp9_psnr.c
media/libvpx/vp9/encoder/vp9_psnr.h
media/libvpx/vp9/encoder/vp9_quantize.c
media/libvpx/vp9/encoder/vp9_quantize.h
media/libvpx/vp9/encoder/vp9_ratectrl.c
media/libvpx/vp9/encoder/vp9_ratectrl.h
media/libvpx/vp9/encoder/vp9_rdopt.c
media/libvpx/vp9/encoder/vp9_rdopt.h
media/libvpx/vp9/encoder/vp9_sad_c.c
media/libvpx/vp9/encoder/vp9_segmentation.c
media/libvpx/vp9/encoder/vp9_segmentation.h
media/libvpx/vp9/encoder/vp9_subexp.c
media/libvpx/vp9/encoder/vp9_subexp.h
media/libvpx/vp9/encoder/vp9_temporal_filter.c
media/libvpx/vp9/encoder/vp9_temporal_filter.h
media/libvpx/vp9/encoder/vp9_tokenize.c
media/libvpx/vp9/encoder/vp9_tokenize.h
media/libvpx/vp9/encoder/vp9_treewriter.c
media/libvpx/vp9/encoder/vp9_treewriter.h
media/libvpx/vp9/encoder/vp9_vaq.c
media/libvpx/vp9/encoder/vp9_vaq.h
media/libvpx/vp9/encoder/vp9_variance.h
media/libvpx/vp9/encoder/vp9_variance_c.c
media/libvpx/vp9/encoder/vp9_write_bit_buffer.h
media/libvpx/vp9/encoder/x86/vp9_dct32x32_sse2.c
media/libvpx/vp9/encoder/x86/vp9_dct_sse2.c
media/libvpx/vp9/encoder/x86/vp9_error_sse2.asm
media/libvpx/vp9/encoder/x86/vp9_mcomp_x86.h
media/libvpx/vp9/encoder/x86/vp9_quantize_ssse3.asm
media/libvpx/vp9/encoder/x86/vp9_sad4d_sse2.asm
media/libvpx/vp9/encoder/x86/vp9_sad_mmx.asm
media/libvpx/vp9/encoder/x86/vp9_sad_sse2.asm
media/libvpx/vp9/encoder/x86/vp9_sad_sse3.asm
media/libvpx/vp9/encoder/x86/vp9_sad_sse4.asm
media/libvpx/vp9/encoder/x86/vp9_sad_ssse3.asm
media/libvpx/vp9/encoder/x86/vp9_subpel_variance.asm
media/libvpx/vp9/encoder/x86/vp9_subpel_variance_impl_sse2.asm
media/libvpx/vp9/encoder/x86/vp9_subtract_sse2.asm
media/libvpx/vp9/encoder/x86/vp9_temporal_filter_apply_sse2.asm
media/libvpx/vp9/encoder/x86/vp9_variance_impl_mmx.asm
media/libvpx/vp9/encoder/x86/vp9_variance_impl_sse2.asm
media/libvpx/vp9/encoder/x86/vp9_variance_mmx.c
media/libvpx/vp9/encoder/x86/vp9_variance_sse2.c
media/libvpx/vp9/vp9_cx_iface.c
media/libvpx/vp9/vp9_dx_iface.c
media/libvpx/vp9/vp9_iface_common.h
media/libvpx/vp9_rtcd.h
media/libvpx/vp9_rtcd_armv7-android-gcc.h
media/libvpx/vp9_rtcd_generic-gnu.h
media/libvpx/vp9_rtcd_x86-darwin9-gcc.h
media/libvpx/vp9_rtcd_x86-linux-gcc.h
media/libvpx/vp9_rtcd_x86-win32-vs8.h
media/libvpx/vp9_rtcd_x86_64-darwin9-gcc.h
media/libvpx/vp9_rtcd_x86_64-linux-gcc.h
media/libvpx/vp9_rtcd_x86_64-win64-vs8.h
media/libvpx/vpx/internal/vpx_codec_internal.h
media/libvpx/vpx/src/svc_encodeframe.c
media/libvpx/vpx/src/vpx_codec.c
media/libvpx/vpx/src/vpx_decoder.c
media/libvpx/vpx/src/vpx_encoder.c
media/libvpx/vpx/src/vpx_image.c
media/libvpx/vpx/svc_context.h
media/libvpx/vpx/vp8.h
media/libvpx/vpx/vp8cx.h
media/libvpx/vpx/vp8dx.h
media/libvpx/vpx/vpx_codec.h
media/libvpx/vpx/vpx_codec_impl_bottom.h
media/libvpx/vpx/vpx_codec_impl_top.h
media/libvpx/vpx/vpx_decoder.h
media/libvpx/vpx/vpx_encoder.h
media/libvpx/vpx/vpx_image.h
media/libvpx/vpx/vpx_integer.h
media/libvpx/vpx/vpx_integer.h.orig
media/libvpx/vpx_config_armv7-android-gcc.asm
media/libvpx/vpx_config_armv7-android-gcc.c
media/libvpx/vpx_config_armv7-android-gcc.h
media/libvpx/vpx_config_generic-gnu.asm
media/libvpx/vpx_config_generic-gnu.h
media/libvpx/vpx_config_x86-darwin9-gcc.asm
media/libvpx/vpx_config_x86-darwin9-gcc.c
media/libvpx/vpx_config_x86-darwin9-gcc.h
media/libvpx/vpx_config_x86-linux-gcc.asm
media/libvpx/vpx_config_x86-linux-gcc.c
media/libvpx/vpx_config_x86-linux-gcc.h
media/libvpx/vpx_config_x86-win32-vs8.asm
media/libvpx/vpx_config_x86-win32-vs8.h
media/libvpx/vpx_config_x86_64-darwin9-gcc.asm
media/libvpx/vpx_config_x86_64-darwin9-gcc.c
media/libvpx/vpx_config_x86_64-darwin9-gcc.h
media/libvpx/vpx_config_x86_64-linux-gcc.asm
media/libvpx/vpx_config_x86_64-linux-gcc.c
media/libvpx/vpx_config_x86_64-linux-gcc.h
media/libvpx/vpx_config_x86_64-win64-vs8.asm
media/libvpx/vpx_config_x86_64-win64-vs8.h
media/libvpx/vpx_mem/include/vpx_mem_intrnl.h
media/libvpx/vpx_mem/include/vpx_mem_tracker.h
media/libvpx/vpx_mem/vpx_mem.c
media/libvpx/vpx_mem/vpx_mem.h
media/libvpx/vpx_ports/arm_cpudetect.c
media/libvpx/vpx_ports/asm_offsets.h
media/libvpx/vpx_ports/config.h
media/libvpx/vpx_ports/emmintrin_compat.h
media/libvpx/vpx_ports/emms.asm
media/libvpx/vpx_ports/mem.h
media/libvpx/vpx_ports/mem_ops.h
media/libvpx/vpx_ports/mem_ops_aligned.h
media/libvpx/vpx_ports/vpx_once.h
media/libvpx/vpx_ports/vpx_timer.h
media/libvpx/vpx_ports/vpxtypes.h
media/libvpx/vpx_ports/x86.h
media/libvpx/vpx_ports/x86_abi_support.asm
media/libvpx/vpx_ports/x86_cpuid.c
media/libvpx/vpx_scale/arm/neon/vp8_vpxyv12_copy_y_neon.asm
media/libvpx/vpx_scale/arm/neon/vp8_vpxyv12_copyframe_func_neon.asm
media/libvpx/vpx_scale/arm/neon/vp8_vpxyv12_copysrcframe_func_neon.asm
media/libvpx/vpx_scale/arm/neon/vp8_vpxyv12_extendframeborders_neon.asm
media/libvpx/vpx_scale/arm/neon/yv12extend_arm.c
media/libvpx/vpx_scale/generic/gen_scalers.c
media/libvpx/vpx_scale/generic/vpx_scale.c
media/libvpx/vpx_scale/generic/vpxscale.c
media/libvpx/vpx_scale/generic/yv12config.c
media/libvpx/vpx_scale/generic/yv12extend.c
media/libvpx/vpx_scale/generic/yv12extend_generic.h
media/libvpx/vpx_scale/include/generic/vpxscale_arbitrary.h
media/libvpx/vpx_scale/include/generic/vpxscale_depricated.h
media/libvpx/vpx_scale/scale_mode.h
media/libvpx/vpx_scale/vpx_scale.h
media/libvpx/vpx_scale/vpx_scale_asm_offsets.c
media/libvpx/vpx_scale/vpx_scale_rtcd.c
media/libvpx/vpx_scale/vpxscale.h
media/libvpx/vpx_scale/yv12config.h
media/libvpx/vpx_scale_rtcd.h
media/libvpx/vpx_scale_rtcd_armv7-android-gcc.h
media/libvpx/vpx_scale_rtcd_generic-gnu.h
media/libvpx/vpx_scale_rtcd_x86-darwin9-gcc.h
media/libvpx/vpx_scale_rtcd_x86-linux-gcc.h
media/libvpx/vpx_scale_rtcd_x86-win32-vs8.h
media/libvpx/vpx_scale_rtcd_x86_64-darwin9-gcc.h
media/libvpx/vpx_scale_rtcd_x86_64-linux-gcc.h
media/libvpx/vpx_scale_rtcd_x86_64-win64-vs8.h
media/libvpx/vpx_version.h
--- a/configure.in
+++ b/configure.in
@@ -5469,17 +5469,17 @@ if test -n "$MOZ_VP8" -a -z "$MOZ_NATIVE
         VPX_DASH_C_FLAG="-c"
         VPX_AS_CONVERSION='$(PERL) $(topsrcdir)/media/libvpx/build/make/ads2gas.pl'
         VPX_ASM_SUFFIX="$ASM_SUFFIX"
         VPX_ARM_ASM=1
       fi
     ;;
     *:x86)
       if $CC -E -dM -</dev/null | grep -q __ELF__; then
-        VPX_ASFLAGS="-f elf32 -rnasm -pnasm"
+        VPX_ASFLAGS="-f elf32 -rnasm -pnasm -DPIC"
         VPX_X86_ASM=1
       fi
     ;;
     *:x86_64)
       if $CC -E -dM -</dev/null | grep -q __ELF__; then
         VPX_ASFLAGS="-f elf64 -rnasm -pnasm -DPIC"
         VPX_X86_ASM=1
       fi
--- a/media/libvpx/Makefile.in
+++ b/media/libvpx/Makefile.in
@@ -17,19 +17,19 @@ ifeq ($(OS_TARGET),Android)
 LOCAL_INCLUDES += -I$(ANDROID_NDK)/sources/android/cpufeatures
 ifndef MOZ_WEBRTC
 # For cpu-features.c
 VPATH += $(ANDROID_NDK)/sources/android/cpufeatures
 CSRCS += cpu-features.c
 endif
 endif
 
-ASM_OFFSETS = asm_com_offsets.asm
+ASM_OFFSETS = vpx_scale_asm_offsets.asm
 ifdef MOZ_VP8_ENCODER
-ASM_OFFSETS += asm_enc_offsets.asm
+ASM_OFFSETS += vp8_asm_enc_offsets.asm
 endif
 
 
 ifdef VPX_AS_CONVERSION
 # The ARM asm is written in ARM RVCT syntax, but we actually build it with
 # gas using GNU syntax. Add some rules to perform the conversion.
 
 GENERATED_DIRS += $(dir $(ASFILES))
@@ -48,107 +48,109 @@ ifdef VPX_NEED_OBJ_INT_EXTRACT
 # parse that format, and so only has limited support for cross-compilation.
 
 ifdef VPX_ARM_ASM
 VPX_OIE_FORMAT := rvds
 else
 VPX_OIE_FORMAT := gas
 endif
 
-GARBAGE += asm_com_offsets.$(OBJ_SUFFIX) asm_com_offsets.asm
+GARBAGE += vpx_scale_asm_offsets.$(OBJ_SUFFIX) vpx_scale_asm_offsets.asm
 
 ifdef MOZ_VP8_ENCODER
 
-GARBAGE += asm_enc_offsets.$(OBJ_SUFFIX) asm_enc_offsets.asm
+GARBAGE += vp8_asm_enc_offsets.$(OBJ_SUFFIX) vp8_asm_enc_offsets.asm
 endif
 
 else
 
 # We can extract the asm offsets directly from generated assembly using inline
 # asm. This is the preferred method.
 
-asm_com_offsets.s: CFLAGS += -DINLINE_ASM
+vpx_scale_asm_offsets.s: CFLAGS += -DINLINE_ASM
 
 OFFSET_PATTERN := '^[a-zA-Z0-9_]* EQU'
 
-# This rule, as well as the rule for asm_enc_offsets.s further below are here
+# This rule, as well as the rule for vp8_asm_enc_offsets.s further below are here
 # because the generic rule in rules.mk was made to not be implicit, and we
 # can't put the C files in CSRCS.
-asm_com_offsets.s: $(srcdir)/vp8/common/asm_com_offsets.c
+vpx_scale_asm_offsets.s: $(srcdir)/vpx_scale/vpx_scale_asm_offsets.c
 	$(REPORT_BUILD)
 	$(CC) -S $(COMPILE_CFLAGS) $(TARGET_LOCAL_INCLUDES) $(_VPATH_SRCS)
 
-asm_com_offsets.asm: asm_com_offsets.s
+vpx_scale_asm_offsets.asm: vpx_scale_asm_offsets.s
 	grep $(OFFSET_PATTERN) $< | sed -e 's/[$$\#]//g' \
 	    $(if $(VPX_AS_CONVERSION),| $(VPX_AS_CONVERSION)) > $@
 
-GARBAGE += asm_com_offsets.s asm_com_offsets.asm
+GARBAGE += vpx_scale_asm_offsets.s vpx_scale_asm_offsets.asm
 
 ifdef MOZ_VP8_ENCODER
 
-asm_enc_offsets.s: CFLAGS += -DINLINE_ASM
+vp8_asm_enc_offsets.s: CFLAGS += -DINLINE_ASM
 
-asm_enc_offsets.s: $(srcdir)/vp8/encoder/asm_enc_offsets.c
+vp8_asm_enc_offsets.s: $(srcdir)/vp8/encoder/vp8_asm_enc_offsets.c
 	$(REPORT_BUILD)
 	$(CC) -S $(COMPILE_CFLAGS) $(TARGET_LOCAL_INCLUDES) $(_VPATH_SRCS)
 
-asm_enc_offsets.asm: asm_enc_offsets.s
+vp8_asm_enc_offsets.asm: vp8_asm_enc_offsets.s
 	grep $(OFFSET_PATTERN) $< | sed -e 's/[$$\#]//g' \
 	    $(if $(VPX_AS_CONVERSION),| $(VPX_AS_CONVERSION)) > $@
 
-GARBAGE += asm_enc_offsets.s asm_enc_offsets.asm
+GARBAGE += vp8_asm_enc_offsets.s vp8_asm_enc_offsets.asm
 
 
 endif
 
 endif
 
-EXTRA_MDDEPEND_FILES = asm_enc_offsets.s.pp asm_enc_offsets.$(OBJ_SUFFIX).pp asm_com_offsets.s.pp asm_com_offsets.$(OBJ_SUFFIX).pp
+EXTRA_MDDEPEND_FILES = vp8_asm_enc_offsets.s.pp vp8_asm_enc_offsets.$(OBJ_SUFFIX).pp vpx_scale_asm_offsets.s.pp vpx_scale_asm_offsets.$(OBJ_SUFFIX).pp
 
 include $(topsrcdir)/config/rules.mk
 
 # This must be after rules.mk in order to use $(OBJ_SUFFIX) outside a
 # recursively-expanded variable.
 
+# dont add for MSVC
 ifndef _MSC_VER
 %_sse2.$(OBJ_SUFFIX): CFLAGS += -msse2
+%_ssse3.$(OBJ_SUFFIX): CFLAGS += -mssse3
+%_avx2.$(OBJ_SUFFIX): CFLAGS += -mavx2
 endif
 
-quantize_sse2.$(OBJ_SUFFIX): asm_enc_offsets.asm
-quantize_sse4.$(OBJ_SUFFIX): asm_enc_offsets.asm
-quantize_ssse3.$(OBJ_SUFFIX): asm_enc_offsets.asm
+quantize_sse4.$(OBJ_SUFFIX): vp8_asm_enc_offsets.asm
+quantize_ssse3.$(OBJ_SUFFIX): vp8_asm_enc_offsets.asm
 
 ifdef VPX_NEED_OBJ_INT_EXTRACT
 
 # only for MSVC
 ifdef _MSC_VER
-NO_PROFILE_GUIDED_OPTIMIZE := asm_com_offsets.c
+NO_PROFILE_GUIDED_OPTIMIZE := vpx_scale_asm_offsets.c
 endif
 
-asm_com_offsets.asm: asm_com_offsets.$(OBJ_SUFFIX) $(HOST_PROGRAM)
+vpx_scale_asm_offsets.asm: vpx_scale_asm_offsets.$(OBJ_SUFFIX) $(HOST_PROGRAM)
 	./$(HOST_PROGRAM) $(VPX_OIE_FORMAT) $< \
 	    $(if $(VPX_AS_CONVERSION),| $(VPX_AS_CONVERSION)) > $@
 
 # Filter out this object, because we don't want to link against it.
 # It was generated solely so it could be parsed by obj_int_extract.
-OBJS := $(filter-out asm_com_offsets.$(OBJ_SUFFIX),$(OBJS))
+OBJS := $(filter-out vpx_scale_asm_offsets.$(OBJ_SUFFIX),$(OBJS))
 
 ifdef MOZ_VP8_ENCODER
 
 ifdef _MSC_VER
-NO_PROFILE_GUIDED_OPTIMIZE += asm_enc_offsets.c
+NO_PROFILE_GUIDED_OPTIMIZE += vp8_asm_enc_offsets.c
 endif
 
-asm_enc_offsets.asm: asm_enc_offsets.$(OBJ_SUFFIX) $(HOST_PROGRAM)
+vp8_asm_enc_offsets.asm: vp8_asm_enc_offsets.$(OBJ_SUFFIX) $(HOST_PROGRAM)
 	./$(HOST_PROGRAM) $(VPX_OIE_FORMAT) $< \
 	    $(if $(VPX_AS_CONVERSION),| $(VPX_AS_CONVERSION)) > $@
 
 # Filter out this object, because we don't want to link against it.
 # It was generated solely so it could be parsed by obj_int_extract.
-OBJS := $(filter-out asm_enc_offsets.$(OBJ_SUFFIX),$(OBJS))
+OBJS := $(filter-out vp8_asm_enc_offsets.$(OBJ_SUFFIX),$(OBJS))
 
 endif
 endif
 
 # Workaround a bug of Sun Studio (CR 6963410)
 ifdef SOLARIS_SUNPRO_CC
 ifeq (86,$(findstring 86,$(OS_TEST)))
 filter.o: filter.c Makefile.in
--- a/media/libvpx/README_MOZILLA
+++ b/media/libvpx/README_MOZILLA
@@ -1,2 +1,11 @@
-Using the v1.2.0 release pulled from
-http://webm.googlecode.com/files/libvpx-v1.2.0.zip
+The source from this directory was copied from the libvpx
+git repository using the update.py script. The only changes
+made were those applied by update.py and the addition of
+moz.build and Makefile.in build files for the
+Mozilla build system.
+
+The libvpx git repository is:
+
+    https://gerrit.chromium.org/gerrit/webm/libvpx
+
+The git commit ID used was 2e88f2f2ec777259bda1714e72f1ecd2519bceb5
--- a/media/libvpx/build/make/ads2gas.pl
+++ b/media/libvpx/build/make/ads2gas.pl
@@ -12,19 +12,34 @@
 
 # ads2gas.pl
 # Author: Eric Fung (efung (at) acm.org)
 #
 # Convert ARM Developer Suite 1.0.1 syntax assembly source to GNU as format
 #
 # Usage: cat inputfile | perl ads2gas.pl > outputfile
 #
+
+use FindBin;
+use lib $FindBin::Bin;
+use thumb;
+
+my $thumb = 0;
+
+foreach my $arg (@ARGV) {
+    $thumb = 1 if ($arg eq "-thumb");
+}
+
 print "@ This file was created from a .asm file\n";
 print "@  using the ads2gas.pl script.\n";
 print "\t.equ DO1STROUNDING, 0\n";
+if ($thumb) {
+    print "\t.syntax unified\n";
+    print "\t.thumb\n";
+}
 
 # Stack of procedure names.
 @proc_stack = ();
 
 while (<STDIN>)
 {
     undef $comment;
     undef $line;
@@ -146,27 +161,36 @@ while (<STDIN>)
     # Labels need trailing colon
 #   s/^(\w+)/$1:/ if !/EQU/;
     # put the colon at the end of the line in the macro
     s/^([a-zA-Z_0-9\$]+)/$1:/ if !/EQU/;
 
     # ALIGN directive
     s/\bALIGN\b/.balign/g;
 
-    # ARM code
-    s/\sARM/.arm/g;
+    if ($thumb) {
+        # ARM code - we force everything to thumb with the declaration in the header
+        s/\sARM//g;
+    } else {
+        # ARM code
+        s/\sARM/.arm/g;
+    }
 
     # push/pop
     s/(push\s+)(r\d+)/stmdb sp\!, \{$2\}/g;
     s/(pop\s+)(r\d+)/ldmia sp\!, \{$2\}/g;
 
     # NEON code
     s/(vld1.\d+\s+)(q\d+)/$1\{$2\}/g;
     s/(vtbl.\d+\s+[^,]+),([^,]+)/$1,\{$2\}/g;
 
+    if ($thumb) {
+        thumb::FixThumbInstructions($_, 0);
+    }
+
     # eabi_attributes numerical equivalents can be found in the
     # "ARM IHI 0045C" document.
 
     # REQUIRE8 Stack is required to be 8-byte aligned
     s/\sREQUIRE8/.eabi_attribute 24, 1 \@Tag_ABI_align_needed/g;
 
     # PRESERVE8 Stack 8-byte align is preserved
     s/\sPRESERVE8/.eabi_attribute 25, 1 \@Tag_ABI_align_preserved/g;
--- a/media/libvpx/build/make/obj_int_extract.c
+++ b/media/libvpx/build/make/obj_int_extract.c
@@ -12,903 +12,816 @@
 #include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
 #include "vpx_config.h"
 #include "vpx/vpx_integer.h"
 
-typedef enum
-{
-    OUTPUT_FMT_PLAIN,
-    OUTPUT_FMT_RVDS,
-    OUTPUT_FMT_GAS,
+typedef enum {
+  OUTPUT_FMT_PLAIN,
+  OUTPUT_FMT_RVDS,
+  OUTPUT_FMT_GAS,
 } output_fmt_t;
 
-int log_msg(const char *fmt, ...)
-{
-    int res;
-    va_list ap;
-    va_start(ap, fmt);
-    res = vfprintf(stderr, fmt, ap);
-    va_end(ap);
-    return res;
+int log_msg(const char *fmt, ...) {
+  int res;
+  va_list ap;
+  va_start(ap, fmt);
+  res = vfprintf(stderr, fmt, ap);
+  va_end(ap);
+  return res;
 }
 
 #if defined(__GNUC__) && __GNUC__
 #if defined(__MACH__)
 
 #include <mach-o/loader.h>
 #include <mach-o/nlist.h>
 
-int parse_macho(uint8_t *base_buf, size_t sz)
-{
-    int i, j;
-    struct mach_header header;
-    uint8_t *buf = base_buf;
-    int base_data_section = 0;
-    int bits = 0;
+int print_macho_equ(output_fmt_t mode, uint8_t* name, int val) {
+  switch (mode) {
+    case OUTPUT_FMT_RVDS:
+      printf("%-40s EQU %5d\n", name, val);
+      return 0;
+    case  OUTPUT_FMT_GAS:
+      printf(".set %-40s, %5d\n", name, val);
+      return 0;
+    default:
+      log_msg("Unsupported mode: %d", mode);
+      return 1;
+  }
+}
+
+int parse_macho(uint8_t *base_buf, size_t sz, output_fmt_t mode) {
+  int i, j;
+  struct mach_header header;
+  uint8_t *buf = base_buf;
+  int base_data_section = 0;
+  int bits = 0;
+
+  /* We can read in mach_header for 32 and 64 bit architectures
+   * because it's identical to mach_header_64 except for the last
+   * element (uint32_t reserved), which we don't use. Then, when
+   * we know which architecture we're looking at, increment buf
+   * appropriately.
+   */
+  memcpy(&header, buf, sizeof(struct mach_header));
+
+  if (header.magic == MH_MAGIC) {
+    if (header.cputype == CPU_TYPE_ARM
+        || header.cputype == CPU_TYPE_X86) {
+      bits = 32;
+      buf += sizeof(struct mach_header);
+    } else {
+      log_msg("Bad cputype for object file. Currently only tested for CPU_TYPE_[ARM|X86].\n");
+      goto bail;
+    }
+  } else if (header.magic == MH_MAGIC_64) {
+    if (header.cputype == CPU_TYPE_X86_64) {
+      bits = 64;
+      buf += sizeof(struct mach_header_64);
+    } else {
+      log_msg("Bad cputype for object file. Currently only tested for CPU_TYPE_X86_64.\n");
+      goto bail;
+    }
+  } else {
+    log_msg("Bad magic number for object file. 0x%x or 0x%x expected, 0x%x found.\n",
+            MH_MAGIC, MH_MAGIC_64, header.magic);
+    goto bail;
+  }
 
-    /* We can read in mach_header for 32 and 64 bit architectures
-     * because it's identical to mach_header_64 except for the last
-     * element (uint32_t reserved), which we don't use. Then, when
-     * we know which architecture we're looking at, increment buf
-     * appropriately.
-     */
-    memcpy(&header, buf, sizeof(struct mach_header));
+  if (header.filetype != MH_OBJECT) {
+    log_msg("Bad filetype for object file. Currently only tested for MH_OBJECT.\n");
+    goto bail;
+  }
+
+  for (i = 0; i < header.ncmds; i++) {
+    struct load_command lc;
+
+    memcpy(&lc, buf, sizeof(struct load_command));
+
+    if (lc.cmd == LC_SEGMENT) {
+      uint8_t *seg_buf = buf;
+      struct section s;
+      struct segment_command seg_c;
+
+      memcpy(&seg_c, seg_buf, sizeof(struct segment_command));
+      seg_buf += sizeof(struct segment_command);
+
+      /* Although each section is given it's own offset, nlist.n_value
+       * references the offset of the first section. This isn't
+       * apparent without debug information because the offset of the
+       * data section is the same as the first section. However, with
+       * debug sections mixed in, the offset of the debug section
+       * increases but n_value still references the first section.
+       */
+      if (seg_c.nsects < 1) {
+        log_msg("Not enough sections\n");
+        goto bail;
+      }
 
-    if (header.magic == MH_MAGIC)
-    {
-        if (header.cputype == CPU_TYPE_ARM
-            || header.cputype == CPU_TYPE_X86)
-        {
-            bits = 32;
-            buf += sizeof(struct mach_header);
+      memcpy(&s, seg_buf, sizeof(struct section));
+      base_data_section = s.offset;
+    } else if (lc.cmd == LC_SEGMENT_64) {
+      uint8_t *seg_buf = buf;
+      struct section_64 s;
+      struct segment_command_64 seg_c;
+
+      memcpy(&seg_c, seg_buf, sizeof(struct segment_command_64));
+      seg_buf += sizeof(struct segment_command_64);
+
+      /* Explanation in LG_SEGMENT */
+      if (seg_c.nsects < 1) {
+        log_msg("Not enough sections\n");
+        goto bail;
+      }
+
+      memcpy(&s, seg_buf, sizeof(struct section_64));
+      base_data_section = s.offset;
+    } else if (lc.cmd == LC_SYMTAB) {
+      if (base_data_section != 0) {
+        struct symtab_command sc;
+        uint8_t *sym_buf = base_buf;
+        uint8_t *str_buf = base_buf;
+
+        memcpy(&sc, buf, sizeof(struct symtab_command));
+
+        if (sc.cmdsize != sizeof(struct symtab_command)) {
+          log_msg("Can't find symbol table!\n");
+          goto bail;
         }
-        else
-        {
-            log_msg("Bad cputype for object file. Currently only tested for CPU_TYPE_[ARM|X86].\n");
-            goto bail;
-        }
-    }
-    else if (header.magic == MH_MAGIC_64)
-    {
-        if (header.cputype == CPU_TYPE_X86_64)
-        {
-            bits = 64;
-            buf += sizeof(struct mach_header_64);
+
+        sym_buf += sc.symoff;
+        str_buf += sc.stroff;
+
+        for (j = 0; j < sc.nsyms; j++) {
+          /* Location of string is cacluated each time from the
+           * start of the string buffer.  On darwin the symbols
+           * are prefixed by "_", so we bump the pointer by 1.
+           * The target value is defined as an int in *_asm_*_offsets.c,
+           * which is 4 bytes on all targets we currently use.
+           */
+          if (bits == 32) {
+            struct nlist nl;
+            int val;
+
+            memcpy(&nl, sym_buf, sizeof(struct nlist));
+            sym_buf += sizeof(struct nlist);
+
+            memcpy(&val, base_buf + base_data_section + nl.n_value,
+                   sizeof(val));
+            print_macho_equ(mode, str_buf + nl.n_un.n_strx + 1, val);
+          } else { /* if (bits == 64) */
+            struct nlist_64 nl;
+            int val;
+
+            memcpy(&nl, sym_buf, sizeof(struct nlist_64));
+            sym_buf += sizeof(struct nlist_64);
+
+            memcpy(&val, base_buf + base_data_section + nl.n_value,
+                   sizeof(val));
+            print_macho_equ(mode, str_buf + nl.n_un.n_strx + 1, val);
+          }
         }
-        else
-        {
-            log_msg("Bad cputype for object file. Currently only tested for CPU_TYPE_X86_64.\n");
-            goto bail;
-        }
-    }
-    else
-    {
-        log_msg("Bad magic number for object file. 0x%x or 0x%x expected, 0x%x found.\n",
-                MH_MAGIC, MH_MAGIC_64, header.magic);
-        goto bail;
-    }
-
-    if (header.filetype != MH_OBJECT)
-    {
-        log_msg("Bad filetype for object file. Currently only tested for MH_OBJECT.\n");
-        goto bail;
+      }
     }
 
-    for (i = 0; i < header.ncmds; i++)
-    {
-        struct load_command lc;
-
-        memcpy(&lc, buf, sizeof(struct load_command));
-
-        if (lc.cmd == LC_SEGMENT)
-        {
-            uint8_t *seg_buf = buf;
-            struct section s;
-            struct segment_command seg_c;
-
-            memcpy(&seg_c, seg_buf, sizeof(struct segment_command));
-            seg_buf += sizeof(struct segment_command);
-
-            /* Although each section is given it's own offset, nlist.n_value
-             * references the offset of the first section. This isn't
-             * apparent without debug information because the offset of the
-             * data section is the same as the first section. However, with
-             * debug sections mixed in, the offset of the debug section
-             * increases but n_value still references the first section.
-             */
-            if (seg_c.nsects < 1)
-            {
-                log_msg("Not enough sections\n");
-                goto bail;
-            }
-
-            memcpy(&s, seg_buf, sizeof(struct section));
-            base_data_section = s.offset;
-        }
-        else if (lc.cmd == LC_SEGMENT_64)
-        {
-            uint8_t *seg_buf = buf;
-            struct section_64 s;
-            struct segment_command_64 seg_c;
-
-            memcpy(&seg_c, seg_buf, sizeof(struct segment_command_64));
-            seg_buf += sizeof(struct segment_command_64);
-
-            /* Explanation in LG_SEGMENT */
-            if (seg_c.nsects < 1)
-            {
-                log_msg("Not enough sections\n");
-                goto bail;
-            }
+    buf += lc.cmdsize;
+  }
 
-            memcpy(&s, seg_buf, sizeof(struct section_64));
-            base_data_section = s.offset;
-        }
-        else if (lc.cmd == LC_SYMTAB)
-        {
-            if (base_data_section != 0)
-            {
-                struct symtab_command sc;
-                uint8_t *sym_buf = base_buf;
-                uint8_t *str_buf = base_buf;
-
-                memcpy(&sc, buf, sizeof(struct symtab_command));
-
-                if (sc.cmdsize != sizeof(struct symtab_command))
-                {
-                    log_msg("Can't find symbol table!\n");
-                    goto bail;
-                }
-
-                sym_buf += sc.symoff;
-                str_buf += sc.stroff;
-
-                for (j = 0; j < sc.nsyms; j++)
-                {
-                    /* Location of string is cacluated each time from the
-                     * start of the string buffer.  On darwin the symbols
-                     * are prefixed by "_", so we bump the pointer by 1.
-                     * The target value is defined as an int in asm_*_offsets.c,
-                     * which is 4 bytes on all targets we currently use.
-                     */
-                    if (bits == 32)
-                    {
-                        struct nlist nl;
-                        int val;
-
-                        memcpy(&nl, sym_buf, sizeof(struct nlist));
-                        sym_buf += sizeof(struct nlist);
-
-                        memcpy(&val, base_buf + base_data_section + nl.n_value,
-                               sizeof(val));
-                        printf("%-40s EQU %5d\n",
-                               str_buf + nl.n_un.n_strx + 1, val);
-                    }
-                    else /* if (bits == 64) */
-                    {
-                        struct nlist_64 nl;
-                        int val;
-
-                        memcpy(&nl, sym_buf, sizeof(struct nlist_64));
-                        sym_buf += sizeof(struct nlist_64);
-
-                        memcpy(&val, base_buf + base_data_section + nl.n_value,
-                               sizeof(val));
-                        printf("%-40s EQU %5d\n",
-                               str_buf + nl.n_un.n_strx + 1, val);
-                    }
-                }
-            }
-        }
-
-        buf += lc.cmdsize;
-    }
-
-    return 0;
+  return 0;
 bail:
-    return 1;
+  return 1;
 
 }
 
 #elif defined(__ELF__)
 #include "elf.h"
 
 #define COPY_STRUCT(dst, buf, ofst, sz) do {\
-        if(ofst + sizeof((*(dst))) > sz) goto bail;\
-        memcpy(dst, buf+ofst, sizeof((*(dst))));\
-    } while(0)
+    if(ofst + sizeof((*(dst))) > sz) goto bail;\
+    memcpy(dst, buf+ofst, sizeof((*(dst))));\
+  } while(0)
 
 #define ENDIAN_ASSIGN(val, memb) do {\
-        if(!elf->le_data) {log_msg("Big Endian data not supported yet!\n");goto bail;}\
-        (val) = (memb);\
-    } while(0)
+    if(!elf->le_data) {log_msg("Big Endian data not supported yet!\n");goto bail;}\
+    (val) = (memb);\
+  } while(0)
 
 #define ENDIAN_ASSIGN_IN_PLACE(memb) do {\
-        ENDIAN_ASSIGN(memb, memb);\
-    } while(0)
+    ENDIAN_ASSIGN(memb, memb);\
+  } while(0)
 
-typedef struct
-{
-    uint8_t      *buf; /* Buffer containing ELF data */
-    size_t        sz;  /* Buffer size */
-    int           le_data; /* Data is little-endian */
-    unsigned char e_ident[EI_NIDENT]; /* Magic number and other info */
-    int           bits; /* 32 or 64 */
-    Elf32_Ehdr    hdr32;
-    Elf64_Ehdr    hdr64;
+typedef struct {
+  uint8_t      *buf; /* Buffer containing ELF data */
+  size_t        sz;  /* Buffer size */
+  int           le_data; /* Data is little-endian */
+  unsigned char e_ident[EI_NIDENT]; /* Magic number and other info */
+  int           bits; /* 32 or 64 */
+  Elf32_Ehdr    hdr32;
+  Elf64_Ehdr    hdr64;
 } elf_obj_t;
 
-int parse_elf_header(elf_obj_t *elf)
-{
-    int res;
-    /* Verify ELF Magic numbers */
-    COPY_STRUCT(&elf->e_ident, elf->buf, 0, elf->sz);
-    res = elf->e_ident[EI_MAG0] == ELFMAG0;
-    res &= elf->e_ident[EI_MAG1] == ELFMAG1;
-    res &= elf->e_ident[EI_MAG2] == ELFMAG2;
-    res &= elf->e_ident[EI_MAG3] == ELFMAG3;
-    res &= elf->e_ident[EI_CLASS] == ELFCLASS32
-        || elf->e_ident[EI_CLASS] == ELFCLASS64;
-    res &= elf->e_ident[EI_DATA] == ELFDATA2LSB;
+int parse_elf_header(elf_obj_t *elf) {
+  int res;
+  /* Verify ELF Magic numbers */
+  COPY_STRUCT(&elf->e_ident, elf->buf, 0, elf->sz);
+  res = elf->e_ident[EI_MAG0] == ELFMAG0;
+  res &= elf->e_ident[EI_MAG1] == ELFMAG1;
+  res &= elf->e_ident[EI_MAG2] == ELFMAG2;
+  res &= elf->e_ident[EI_MAG3] == ELFMAG3;
+  res &= elf->e_ident[EI_CLASS] == ELFCLASS32
+         || elf->e_ident[EI_CLASS] == ELFCLASS64;
+  res &= elf->e_ident[EI_DATA] == ELFDATA2LSB;
 
-    if (!res) goto bail;
+  if (!res) goto bail;
 
-    elf->le_data = elf->e_ident[EI_DATA] == ELFDATA2LSB;
+  elf->le_data = elf->e_ident[EI_DATA] == ELFDATA2LSB;
 
-    /* Read in relevant values */
-    if (elf->e_ident[EI_CLASS] == ELFCLASS32)
-    {
-        elf->bits = 32;
-        COPY_STRUCT(&elf->hdr32, elf->buf, 0, elf->sz);
+  /* Read in relevant values */
+  if (elf->e_ident[EI_CLASS] == ELFCLASS32) {
+    elf->bits = 32;
+    COPY_STRUCT(&elf->hdr32, elf->buf, 0, elf->sz);
 
-        ENDIAN_ASSIGN_IN_PLACE(elf->hdr32.e_type);
-        ENDIAN_ASSIGN_IN_PLACE(elf->hdr32.e_machine);
-        ENDIAN_ASSIGN_IN_PLACE(elf->hdr32.e_version);
-        ENDIAN_ASSIGN_IN_PLACE(elf->hdr32.e_entry);
-        ENDIAN_ASSIGN_IN_PLACE(elf->hdr32.e_phoff);
-        ENDIAN_ASSIGN_IN_PLACE(elf->hdr32.e_shoff);
-        ENDIAN_ASSIGN_IN_PLACE(elf->hdr32.e_flags);
-        ENDIAN_ASSIGN_IN_PLACE(elf->hdr32.e_ehsize);
-        ENDIAN_ASSIGN_IN_PLACE(elf->hdr32.e_phentsize);
-        ENDIAN_ASSIGN_IN_PLACE(elf->hdr32.e_phnum);
-        ENDIAN_ASSIGN_IN_PLACE(elf->hdr32.e_shentsize);
-        ENDIAN_ASSIGN_IN_PLACE(elf->hdr32.e_shnum);
-        ENDIAN_ASSIGN_IN_PLACE(elf->hdr32.e_shstrndx);
-    }
-    else /* if (elf->e_ident[EI_CLASS] == ELFCLASS64) */
-    {
-        elf->bits = 64;
-        COPY_STRUCT(&elf->hdr64, elf->buf, 0, elf->sz);
+    ENDIAN_ASSIGN_IN_PLACE(elf->hdr32.e_type);
+    ENDIAN_ASSIGN_IN_PLACE(elf->hdr32.e_machine);
+    ENDIAN_ASSIGN_IN_PLACE(elf->hdr32.e_version);
+    ENDIAN_ASSIGN_IN_PLACE(elf->hdr32.e_entry);
+    ENDIAN_ASSIGN_IN_PLACE(elf->hdr32.e_phoff);
+    ENDIAN_ASSIGN_IN_PLACE(elf->hdr32.e_shoff);
+    ENDIAN_ASSIGN_IN_PLACE(elf->hdr32.e_flags);
+    ENDIAN_ASSIGN_IN_PLACE(elf->hdr32.e_ehsize);
+    ENDIAN_ASSIGN_IN_PLACE(elf->hdr32.e_phentsize);
+    ENDIAN_ASSIGN_IN_PLACE(elf->hdr32.e_phnum);
+    ENDIAN_ASSIGN_IN_PLACE(elf->hdr32.e_shentsize);
+    ENDIAN_ASSIGN_IN_PLACE(elf->hdr32.e_shnum);
+    ENDIAN_ASSIGN_IN_PLACE(elf->hdr32.e_shstrndx);
+  } else { /* if (elf->e_ident[EI_CLASS] == ELFCLASS64) */
+    elf->bits = 64;
+    COPY_STRUCT(&elf->hdr64, elf->buf, 0, elf->sz);
 
-        ENDIAN_ASSIGN_IN_PLACE(elf->hdr64.e_type);
-        ENDIAN_ASSIGN_IN_PLACE(elf->hdr64.e_machine);
-        ENDIAN_ASSIGN_IN_PLACE(elf->hdr64.e_version);
-        ENDIAN_ASSIGN_IN_PLACE(elf->hdr64.e_entry);
-        ENDIAN_ASSIGN_IN_PLACE(elf->hdr64.e_phoff);
-        ENDIAN_ASSIGN_IN_PLACE(elf->hdr64.e_shoff);
-        ENDIAN_ASSIGN_IN_PLACE(elf->hdr64.e_flags);
-        ENDIAN_ASSIGN_IN_PLACE(elf->hdr64.e_ehsize);
-        ENDIAN_ASSIGN_IN_PLACE(elf->hdr64.e_phentsize);
-        ENDIAN_ASSIGN_IN_PLACE(elf->hdr64.e_phnum);
-        ENDIAN_ASSIGN_IN_PLACE(elf->hdr64.e_shentsize);
-        ENDIAN_ASSIGN_IN_PLACE(elf->hdr64.e_shnum);
-        ENDIAN_ASSIGN_IN_PLACE(elf->hdr64.e_shstrndx);
-    }
+    ENDIAN_ASSIGN_IN_PLACE(elf->hdr64.e_type);
+    ENDIAN_ASSIGN_IN_PLACE(elf->hdr64.e_machine);
+    ENDIAN_ASSIGN_IN_PLACE(elf->hdr64.e_version);
+    ENDIAN_ASSIGN_IN_PLACE(elf->hdr64.e_entry);
+    ENDIAN_ASSIGN_IN_PLACE(elf->hdr64.e_phoff);
+    ENDIAN_ASSIGN_IN_PLACE(elf->hdr64.e_shoff);
+    ENDIAN_ASSIGN_IN_PLACE(elf->hdr64.e_flags);
+    ENDIAN_ASSIGN_IN_PLACE(elf->hdr64.e_ehsize);
+    ENDIAN_ASSIGN_IN_PLACE(elf->hdr64.e_phentsize);
+    ENDIAN_ASSIGN_IN_PLACE(elf->hdr64.e_phnum);
+    ENDIAN_ASSIGN_IN_PLACE(elf->hdr64.e_shentsize);
+    ENDIAN_ASSIGN_IN_PLACE(elf->hdr64.e_shnum);
+    ENDIAN_ASSIGN_IN_PLACE(elf->hdr64.e_shstrndx);
+  }
 
-    return 0;
+  return 0;
 bail:
-    log_msg("Failed to parse ELF file header");
-    return 1;
+  log_msg("Failed to parse ELF file header");
+  return 1;
 }
 
-int parse_elf_section(elf_obj_t *elf, int idx, Elf32_Shdr *hdr32, Elf64_Shdr *hdr64)
-{
-    if (hdr32)
-    {
-        if (idx >= elf->hdr32.e_shnum)
-            goto bail;
-
-        COPY_STRUCT(hdr32, elf->buf, elf->hdr32.e_shoff + idx * elf->hdr32.e_shentsize,
-                    elf->sz);
-        ENDIAN_ASSIGN_IN_PLACE(hdr32->sh_name);
-        ENDIAN_ASSIGN_IN_PLACE(hdr32->sh_type);
-        ENDIAN_ASSIGN_IN_PLACE(hdr32->sh_flags);
-        ENDIAN_ASSIGN_IN_PLACE(hdr32->sh_addr);
-        ENDIAN_ASSIGN_IN_PLACE(hdr32->sh_offset);
-        ENDIAN_ASSIGN_IN_PLACE(hdr32->sh_size);
-        ENDIAN_ASSIGN_IN_PLACE(hdr32->sh_link);
-        ENDIAN_ASSIGN_IN_PLACE(hdr32->sh_info);
-        ENDIAN_ASSIGN_IN_PLACE(hdr32->sh_addralign);
-        ENDIAN_ASSIGN_IN_PLACE(hdr32->sh_entsize);
-    }
-    else /* if (hdr64) */
-    {
-        if (idx >= elf->hdr64.e_shnum)
-            goto bail;
-
-        COPY_STRUCT(hdr64, elf->buf, elf->hdr64.e_shoff + idx * elf->hdr64.e_shentsize,
-                    elf->sz);
-        ENDIAN_ASSIGN_IN_PLACE(hdr64->sh_name);
-        ENDIAN_ASSIGN_IN_PLACE(hdr64->sh_type);
-        ENDIAN_ASSIGN_IN_PLACE(hdr64->sh_flags);
-        ENDIAN_ASSIGN_IN_PLACE(hdr64->sh_addr);
-        ENDIAN_ASSIGN_IN_PLACE(hdr64->sh_offset);
-        ENDIAN_ASSIGN_IN_PLACE(hdr64->sh_size);
-        ENDIAN_ASSIGN_IN_PLACE(hdr64->sh_link);
-        ENDIAN_ASSIGN_IN_PLACE(hdr64->sh_info);
-        ENDIAN_ASSIGN_IN_PLACE(hdr64->sh_addralign);
-        ENDIAN_ASSIGN_IN_PLACE(hdr64->sh_entsize);
-    }
-
-    return 0;
-bail:
-    return 1;
-}
-
-char *parse_elf_string_table(elf_obj_t *elf, int s_idx, int idx)
-{
-    if (elf->bits == 32)
-    {
-        Elf32_Shdr shdr;
-
-        if (parse_elf_section(elf, s_idx, &shdr, NULL))
-        {
-            log_msg("Failed to parse ELF string table: section %d, index %d\n",
-                    s_idx, idx);
-            return "";
-        }
+int parse_elf_section(elf_obj_t *elf, int idx, Elf32_Shdr *hdr32, Elf64_Shdr *hdr64) {
+  if (hdr32) {
+    if (idx >= elf->hdr32.e_shnum)
+      goto bail;
 
-        return (char *)(elf->buf + shdr.sh_offset + idx);
-    }
-    else /* if (elf->bits == 64) */
-    {
-        Elf64_Shdr shdr;
-
-        if (parse_elf_section(elf, s_idx, NULL, &shdr))
-        {
-            log_msg("Failed to parse ELF string table: section %d, index %d\n",
-                    s_idx, idx);
-            return "";
-        }
-
-        return (char *)(elf->buf + shdr.sh_offset + idx);
-    }
-}
-
-int parse_elf_symbol(elf_obj_t *elf, unsigned int ofst, Elf32_Sym *sym32, Elf64_Sym *sym64)
-{
-    if (sym32)
-    {
-        COPY_STRUCT(sym32, elf->buf, ofst, elf->sz);
-        ENDIAN_ASSIGN_IN_PLACE(sym32->st_name);
-        ENDIAN_ASSIGN_IN_PLACE(sym32->st_value);
-        ENDIAN_ASSIGN_IN_PLACE(sym32->st_size);
-        ENDIAN_ASSIGN_IN_PLACE(sym32->st_info);
-        ENDIAN_ASSIGN_IN_PLACE(sym32->st_other);
-        ENDIAN_ASSIGN_IN_PLACE(sym32->st_shndx);
-    }
-    else /* if (sym64) */
-    {
-        COPY_STRUCT(sym64, elf->buf, ofst, elf->sz);
-        ENDIAN_ASSIGN_IN_PLACE(sym64->st_name);
-        ENDIAN_ASSIGN_IN_PLACE(sym64->st_value);
-        ENDIAN_ASSIGN_IN_PLACE(sym64->st_size);
-        ENDIAN_ASSIGN_IN_PLACE(sym64->st_info);
-        ENDIAN_ASSIGN_IN_PLACE(sym64->st_other);
-        ENDIAN_ASSIGN_IN_PLACE(sym64->st_shndx);
-    }
-    return 0;
-bail:
-    return 1;
-}
-
-int parse_elf(uint8_t *buf, size_t sz, output_fmt_t mode)
-{
-    elf_obj_t    elf;
-    unsigned int ofst;
-    int          i;
-    Elf32_Off    strtab_off32;
-    Elf64_Off    strtab_off64; /* save String Table offset for later use */
-
-    memset(&elf, 0, sizeof(elf));
-    elf.buf = buf;
-    elf.sz = sz;
-
-    /* Parse Header */
-    if (parse_elf_header(&elf))
+    COPY_STRUCT(hdr32, elf->buf, elf->hdr32.e_shoff + idx * elf->hdr32.e_shentsize,
+                elf->sz);
+    ENDIAN_ASSIGN_IN_PLACE(hdr32->sh_name);
+    ENDIAN_ASSIGN_IN_PLACE(hdr32->sh_type);
+    ENDIAN_ASSIGN_IN_PLACE(hdr32->sh_flags);
+    ENDIAN_ASSIGN_IN_PLACE(hdr32->sh_addr);
+    ENDIAN_ASSIGN_IN_PLACE(hdr32->sh_offset);
+    ENDIAN_ASSIGN_IN_PLACE(hdr32->sh_size);
+    ENDIAN_ASSIGN_IN_PLACE(hdr32->sh_link);
+    ENDIAN_ASSIGN_IN_PLACE(hdr32->sh_info);
+    ENDIAN_ASSIGN_IN_PLACE(hdr32->sh_addralign);
+    ENDIAN_ASSIGN_IN_PLACE(hdr32->sh_entsize);
+  } else { /* if (hdr64) */
+    if (idx >= elf->hdr64.e_shnum)
       goto bail;
 
-    if (elf.bits == 32)
-    {
-        Elf32_Shdr shdr;
-        for (i = 0; i < elf.hdr32.e_shnum; i++)
-        {
-            parse_elf_section(&elf, i, &shdr, NULL);
-
-            if (shdr.sh_type == SHT_STRTAB)
-            {
-                char strtsb_name[128];
+    COPY_STRUCT(hdr64, elf->buf, elf->hdr64.e_shoff + idx * elf->hdr64.e_shentsize,
+                elf->sz);
+    ENDIAN_ASSIGN_IN_PLACE(hdr64->sh_name);
+    ENDIAN_ASSIGN_IN_PLACE(hdr64->sh_type);
+    ENDIAN_ASSIGN_IN_PLACE(hdr64->sh_flags);
+    ENDIAN_ASSIGN_IN_PLACE(hdr64->sh_addr);
+    ENDIAN_ASSIGN_IN_PLACE(hdr64->sh_offset);
+    ENDIAN_ASSIGN_IN_PLACE(hdr64->sh_size);
+    ENDIAN_ASSIGN_IN_PLACE(hdr64->sh_link);
+    ENDIAN_ASSIGN_IN_PLACE(hdr64->sh_info);
+    ENDIAN_ASSIGN_IN_PLACE(hdr64->sh_addralign);
+    ENDIAN_ASSIGN_IN_PLACE(hdr64->sh_entsize);
+  }
 
-                strcpy(strtsb_name, (char *)(elf.buf + shdr.sh_offset + shdr.sh_name));
+  return 0;
+bail:
+  return 1;
+}
 
-                if (!(strcmp(strtsb_name, ".shstrtab")))
-                {
-                    /* log_msg("found section: %s\n", strtsb_name); */
-                    strtab_off32 = shdr.sh_offset;
-                    break;
-                }
-            }
-        }
+char *parse_elf_string_table(elf_obj_t *elf, int s_idx, int idx) {
+  if (elf->bits == 32) {
+    Elf32_Shdr shdr;
+
+    if (parse_elf_section(elf, s_idx, &shdr, NULL)) {
+      log_msg("Failed to parse ELF string table: section %d, index %d\n",
+              s_idx, idx);
+      return "";
     }
-    else /* if (elf.bits == 64) */
-    {
-        Elf64_Shdr shdr;
-        for (i = 0; i < elf.hdr64.e_shnum; i++)
-        {
-            parse_elf_section(&elf, i, NULL, &shdr);
 
-            if (shdr.sh_type == SHT_STRTAB)
-            {
-                char strtsb_name[128];
+    return (char *)(elf->buf + shdr.sh_offset + idx);
+  } else { /* if (elf->bits == 64) */
+    Elf64_Shdr shdr;
 
-                strcpy(strtsb_name, (char *)(elf.buf + shdr.sh_offset + shdr.sh_name));
-
-                if (!(strcmp(strtsb_name, ".shstrtab")))
-                {
-                    /* log_msg("found section: %s\n", strtsb_name); */
-                    strtab_off64 = shdr.sh_offset;
-                    break;
-                }
-            }
-        }
+    if (parse_elf_section(elf, s_idx, NULL, &shdr)) {
+      log_msg("Failed to parse ELF string table: section %d, index %d\n",
+              s_idx, idx);
+      return "";
     }
 
-    /* Parse all Symbol Tables */
-    if (elf.bits == 32)
-    {
-        Elf32_Shdr shdr;
-        for (i = 0; i < elf.hdr32.e_shnum; i++)
-        {
-            parse_elf_section(&elf, i, &shdr, NULL);
-
-            if (shdr.sh_type == SHT_SYMTAB)
-            {
-                for (ofst = shdr.sh_offset;
-                     ofst < shdr.sh_offset + shdr.sh_size;
-                     ofst += shdr.sh_entsize)
-                {
-                    Elf32_Sym sym;
-
-                    parse_elf_symbol(&elf, ofst, &sym, NULL);
+    return (char *)(elf->buf + shdr.sh_offset + idx);
+  }
+}
 
-                    /* For all OBJECTS (data objects), extract the value from the
-                     * proper data segment.
-                     */
-                    /* if (ELF32_ST_TYPE(sym.st_info) == STT_OBJECT && sym.st_name)
-                        log_msg("found data object %s\n",
-                                parse_elf_string_table(&elf,
-                                                       shdr.sh_link,
-                                                       sym.st_name));
-                     */
+int parse_elf_symbol(elf_obj_t *elf, unsigned int ofst, Elf32_Sym *sym32, Elf64_Sym *sym64) {
+  if (sym32) {
+    COPY_STRUCT(sym32, elf->buf, ofst, elf->sz);
+    ENDIAN_ASSIGN_IN_PLACE(sym32->st_name);
+    ENDIAN_ASSIGN_IN_PLACE(sym32->st_value);
+    ENDIAN_ASSIGN_IN_PLACE(sym32->st_size);
+    ENDIAN_ASSIGN_IN_PLACE(sym32->st_info);
+    ENDIAN_ASSIGN_IN_PLACE(sym32->st_other);
+    ENDIAN_ASSIGN_IN_PLACE(sym32->st_shndx);
+  } else { /* if (sym64) */
+    COPY_STRUCT(sym64, elf->buf, ofst, elf->sz);
+    ENDIAN_ASSIGN_IN_PLACE(sym64->st_name);
+    ENDIAN_ASSIGN_IN_PLACE(sym64->st_value);
+    ENDIAN_ASSIGN_IN_PLACE(sym64->st_size);
+    ENDIAN_ASSIGN_IN_PLACE(sym64->st_info);
+    ENDIAN_ASSIGN_IN_PLACE(sym64->st_other);
+    ENDIAN_ASSIGN_IN_PLACE(sym64->st_shndx);
+  }
+  return 0;
+bail:
+  return 1;
+}
 
-                    if (ELF32_ST_TYPE(sym.st_info) == STT_OBJECT
-                        && sym.st_size == 4)
-                    {
-                        Elf32_Shdr dhdr;
-                        int val = 0;
-                        char section_name[128];
+int parse_elf(uint8_t *buf, size_t sz, output_fmt_t mode) {
+  elf_obj_t    elf;
+  unsigned int ofst;
+  int          i;
+  Elf32_Off    strtab_off32;
+  Elf64_Off    strtab_off64; /* save String Table offset for later use */
 
-                        parse_elf_section(&elf, sym.st_shndx, &dhdr, NULL);
-
-                        /* For explanition - refer to _MSC_VER version of code */
-                        strcpy(section_name, (char *)(elf.buf + strtab_off32 + dhdr.sh_name));
-                        /* log_msg("Section_name: %s, Section_type: %d\n", section_name, dhdr.sh_type); */
+  memset(&elf, 0, sizeof(elf));
+  elf.buf = buf;
+  elf.sz = sz;
 
-                        if (strcmp(section_name, ".bss"))
-                        {
-                            if (sizeof(val) != sym.st_size)
-                            {
-                                /* The target value is declared as an int in
-                                 * asm_*_offsets.c, which is 4 bytes on all
-                                 * targets we currently use. Complain loudly if
-                                 * this is not true.
-                                 */
-                                log_msg("Symbol size is wrong\n");
-                                goto bail;
-                            }
+  /* Parse Header */
+  if (parse_elf_header(&elf))
+    goto bail;
 
-                            memcpy(&val,
-                                   elf.buf + dhdr.sh_offset + sym.st_value,
-                                   sym.st_size);
-                        }
+  if (elf.bits == 32) {
+    Elf32_Shdr shdr;
+    for (i = 0; i < elf.hdr32.e_shnum; i++) {
+      parse_elf_section(&elf, i, &shdr, NULL);
 
-                        if (!elf.le_data)
-                        {
-                            log_msg("Big Endian data not supported yet!\n");
-                            goto bail;
-                        }
+      if (shdr.sh_type == SHT_STRTAB) {
+        char strtsb_name[128];
+
+        strcpy(strtsb_name, (char *)(elf.buf + shdr.sh_offset + shdr.sh_name));
 
-                        switch (mode)
-                        {
-                            case OUTPUT_FMT_RVDS:
-                                printf("%-40s EQU %5d\n",
-                                       parse_elf_string_table(&elf,
-                                                              shdr.sh_link,
-                                                              sym.st_name),
-                                       val);
-                                break;
-                            case OUTPUT_FMT_GAS:
-                                printf(".equ %-40s, %5d\n",
-                                       parse_elf_string_table(&elf,
-                                                              shdr.sh_link,
-                                                              sym.st_name),
-                                       val);
-                                break;
-                            default:
-                                printf("%s = %d\n",
-                                       parse_elf_string_table(&elf,
-                                                              shdr.sh_link,
-                                                              sym.st_name),
-                                       val);
-                        }
-                    }
-                }
-            }
+        if (!(strcmp(strtsb_name, ".shstrtab"))) {
+          /* log_msg("found section: %s\n", strtsb_name); */
+          strtab_off32 = shdr.sh_offset;
+          break;
         }
+      }
+    }
+  } else { /* if (elf.bits == 64) */
+    Elf64_Shdr shdr;
+    for (i = 0; i < elf.hdr64.e_shnum; i++) {
+      parse_elf_section(&elf, i, NULL, &shdr);
+
+      if (shdr.sh_type == SHT_STRTAB) {
+        char strtsb_name[128];
+
+        strcpy(strtsb_name, (char *)(elf.buf + shdr.sh_offset + shdr.sh_name));
+
+        if (!(strcmp(strtsb_name, ".shstrtab"))) {
+          /* log_msg("found section: %s\n", strtsb_name); */
+          strtab_off64 = shdr.sh_offset;
+          break;
+        }
+      }
     }
-    else /* if (elf.bits == 64) */
-    {
-        Elf64_Shdr shdr;
-        for (i = 0; i < elf.hdr64.e_shnum; i++)
-        {
-            parse_elf_section(&elf, i, NULL, &shdr);
+  }
+
+  /* Parse all Symbol Tables */
+  if (elf.bits == 32) {
+    Elf32_Shdr shdr;
+    for (i = 0; i < elf.hdr32.e_shnum; i++) {
+      parse_elf_section(&elf, i, &shdr, NULL);
 
-            if (shdr.sh_type == SHT_SYMTAB)
-            {
-                for (ofst = shdr.sh_offset;
-                     ofst < shdr.sh_offset + shdr.sh_size;
-                     ofst += shdr.sh_entsize)
-                {
-                    Elf64_Sym sym;
+      if (shdr.sh_type == SHT_SYMTAB) {
+        for (ofst = shdr.sh_offset;
+             ofst < shdr.sh_offset + shdr.sh_size;
+             ofst += shdr.sh_entsize) {
+          Elf32_Sym sym;
+
+          parse_elf_symbol(&elf, ofst, &sym, NULL);
 
-                    parse_elf_symbol(&elf, ofst, NULL, &sym);
+          /* For all OBJECTS (data objects), extract the value from the
+           * proper data segment.
+           */
+          /* if (ELF32_ST_TYPE(sym.st_info) == STT_OBJECT && sym.st_name)
+              log_msg("found data object %s\n",
+                      parse_elf_string_table(&elf,
+                                             shdr.sh_link,
+                                             sym.st_name));
+           */
 
-                    /* For all OBJECTS (data objects), extract the value from the
-                     * proper data segment.
-                     */
-                    /* if (ELF64_ST_TYPE(sym.st_info) == STT_OBJECT && sym.st_name)
-                        log_msg("found data object %s\n",
-                                parse_elf_string_table(&elf,
-                                                       shdr.sh_link,
-                                                       sym.st_name));
-                     */
+          if (ELF32_ST_TYPE(sym.st_info) == STT_OBJECT
+              && sym.st_size == 4) {
+            Elf32_Shdr dhdr;
+            int val = 0;
+            char section_name[128];
+
+            parse_elf_section(&elf, sym.st_shndx, &dhdr, NULL);
+
+            /* For explanition - refer to _MSC_VER version of code */
+            strcpy(section_name, (char *)(elf.buf + strtab_off32 + dhdr.sh_name));
+            /* log_msg("Section_name: %s, Section_type: %d\n", section_name, dhdr.sh_type); */
 
-                    if (ELF64_ST_TYPE(sym.st_info) == STT_OBJECT
-                        && sym.st_size == 4)
-                    {
-                        Elf64_Shdr dhdr;
-                        int val = 0;
-                        char section_name[128];
+            if (strcmp(section_name, ".bss")) {
+              if (sizeof(val) != sym.st_size) {
+                /* The target value is declared as an int in
+                 * *_asm_*_offsets.c, which is 4 bytes on all
+                 * targets we currently use. Complain loudly if
+                 * this is not true.
+                 */
+                log_msg("Symbol size is wrong\n");
+                goto bail;
+              }
 
-                        parse_elf_section(&elf, sym.st_shndx, NULL, &dhdr);
+              memcpy(&val,
+                     elf.buf + dhdr.sh_offset + sym.st_value,
+                     sym.st_size);
+            }
 
-                        /* For explanition - refer to _MSC_VER version of code */
-                        strcpy(section_name, (char *)(elf.buf + strtab_off64 + dhdr.sh_name));
-                        /* log_msg("Section_name: %s, Section_type: %d\n", section_name, dhdr.sh_type); */
+            if (!elf.le_data) {
+              log_msg("Big Endian data not supported yet!\n");
+              goto bail;
+            }
 
-                        if ((strcmp(section_name, ".bss")))
-                        {
-                            if (sizeof(val) != sym.st_size)
-                            {
-                                /* The target value is declared as an int in
-                                 * asm_*_offsets.c, which is 4 bytes on all
-                                 * targets we currently use. Complain loudly if
-                                 * this is not true.
-                                 */
-                                log_msg("Symbol size is wrong\n");
-                                goto bail;
-                            }
+            switch (mode) {
+              case OUTPUT_FMT_RVDS:
+                printf("%-40s EQU %5d\n",
+                       parse_elf_string_table(&elf,
+                                              shdr.sh_link,
+                                              sym.st_name),
+                       val);
+                break;
+              case OUTPUT_FMT_GAS:
+                printf(".equ %-40s, %5d\n",
+                       parse_elf_string_table(&elf,
+                                              shdr.sh_link,
+                                              sym.st_name),
+                       val);
+                break;
+              default:
+                printf("%s = %d\n",
+                       parse_elf_string_table(&elf,
+                                              shdr.sh_link,
+                                              sym.st_name),
+                       val);
+            }
+          }
+        }
+      }
+    }
+  } else { /* if (elf.bits == 64) */
+    Elf64_Shdr shdr;
+    for (i = 0; i < elf.hdr64.e_shnum; i++) {
+      parse_elf_section(&elf, i, NULL, &shdr);
 
-                            memcpy(&val,
-                                   elf.buf + dhdr.sh_offset + sym.st_value,
-                                   sym.st_size);
-                        }
+      if (shdr.sh_type == SHT_SYMTAB) {
+        for (ofst = shdr.sh_offset;
+             ofst < shdr.sh_offset + shdr.sh_size;
+             ofst += shdr.sh_entsize) {
+          Elf64_Sym sym;
+
+          parse_elf_symbol(&elf, ofst, NULL, &sym);
 
-                        if (!elf.le_data)
-                        {
-                            log_msg("Big Endian data not supported yet!\n");
-                            goto bail;
-                        }
+          /* For all OBJECTS (data objects), extract the value from the
+           * proper data segment.
+           */
+          /* if (ELF64_ST_TYPE(sym.st_info) == STT_OBJECT && sym.st_name)
+              log_msg("found data object %s\n",
+                      parse_elf_string_table(&elf,
+                                             shdr.sh_link,
+                                             sym.st_name));
+           */
+
+          if (ELF64_ST_TYPE(sym.st_info) == STT_OBJECT
+              && sym.st_size == 4) {
+            Elf64_Shdr dhdr;
+            int val = 0;
+            char section_name[128];
+
+            parse_elf_section(&elf, sym.st_shndx, NULL, &dhdr);
 
-                        switch (mode)
-                        {
-                            case OUTPUT_FMT_RVDS:
-                                printf("%-40s EQU %5d\n",
-                                       parse_elf_string_table(&elf,
-                                                              shdr.sh_link,
-                                                              sym.st_name),
-                                       val);
-                                break;
-                            case OUTPUT_FMT_GAS:
-                                printf(".equ %-40s, %5d\n",
-                                       parse_elf_string_table(&elf,
-                                                              shdr.sh_link,
-                                                              sym.st_name),
-                                       val);
-                                break;
-                            default:
-                                printf("%s = %d\n",
-                                       parse_elf_string_table(&elf,
-                                                              shdr.sh_link,
-                                                              sym.st_name),
-                                       val);
-                        }
-                    }
-                }
+            /* For explanition - refer to _MSC_VER version of code */
+            strcpy(section_name, (char *)(elf.buf + strtab_off64 + dhdr.sh_name));
+            /* log_msg("Section_name: %s, Section_type: %d\n", section_name, dhdr.sh_type); */
+
+            if ((strcmp(section_name, ".bss"))) {
+              if (sizeof(val) != sym.st_size) {
+                /* The target value is declared as an int in
+                 * *_asm_*_offsets.c, which is 4 bytes on all
+                 * targets we currently use. Complain loudly if
+                 * this is not true.
+                 */
+                log_msg("Symbol size is wrong\n");
+                goto bail;
+              }
+
+              memcpy(&val,
+                     elf.buf + dhdr.sh_offset + sym.st_value,
+                     sym.st_size);
+            }
+
+            if (!elf.le_data) {
+              log_msg("Big Endian data not supported yet!\n");
+              goto bail;
             }
-        }
-    }
 
-    if (mode == OUTPUT_FMT_RVDS)
-        printf("    END\n");
+            switch (mode) {
+              case OUTPUT_FMT_RVDS:
+                printf("%-40s EQU %5d\n",
+                       parse_elf_string_table(&elf,
+                                              shdr.sh_link,
+                                              sym.st_name),
+                       val);
+                break;
+              case OUTPUT_FMT_GAS:
+                printf(".equ %-40s, %5d\n",
+                       parse_elf_string_table(&elf,
+                                              shdr.sh_link,
+                                              sym.st_name),
+                       val);
+                break;
+              default:
+                printf("%s = %d\n",
+                       parse_elf_string_table(&elf,
+                                              shdr.sh_link,
+                                              sym.st_name),
+                       val);
+            }
+          }
+        }
+      }
+    }
+  }
 
-    return 0;
+  if (mode == OUTPUT_FMT_RVDS)
+    printf("    END\n");
+
+  return 0;
 bail:
-    log_msg("Parse error: File does not appear to be valid ELF32 or ELF64\n");
-    return 1;
+  log_msg("Parse error: File does not appear to be valid ELF32 or ELF64\n");
+  return 1;
 }
 
 #endif
 #endif /* defined(__GNUC__) && __GNUC__ */
 
 
 #if defined(_MSC_VER) || defined(__MINGW32__) || defined(__CYGWIN__)
 /*  See "Microsoft Portable Executable and Common Object File Format Specification"
     for reference.
 */
 #define get_le32(x) ((*(x)) | (*(x+1)) << 8 |(*(x+2)) << 16 | (*(x+3)) << 24 )
 #define get_le16(x) ((*(x)) | (*(x+1)) << 8)
 
-int parse_coff(uint8_t *buf, size_t sz)
-{
-    unsigned int nsections, symtab_ptr, symtab_sz, strtab_ptr;
-    unsigned int sectionrawdata_ptr;
-    unsigned int i;
-    uint8_t *ptr;
-    uint32_t symoffset;
+int parse_coff(uint8_t *buf, size_t sz) {
+  unsigned int nsections, symtab_ptr, symtab_sz, strtab_ptr;
+  unsigned int sectionrawdata_ptr;
+  unsigned int i;
+  uint8_t *ptr;
+  uint32_t symoffset;
+
+  char **sectionlist;  // this array holds all section names in their correct order.
+  // it is used to check if the symbol is in .bss or .rdata section.
 
-    char **sectionlist;  //this array holds all section names in their correct order.
-    //it is used to check if the symbol is in .bss or .rdata section.
+  nsections = get_le16(buf + 2);
+  symtab_ptr = get_le32(buf + 8);
+  symtab_sz = get_le32(buf + 12);
+  strtab_ptr = symtab_ptr + symtab_sz * 18;
+
+  if (nsections > 96) {
+    log_msg("Too many sections\n");
+    return 1;
+  }
+
+  sectionlist = malloc(nsections * sizeof(sectionlist));
 
-    nsections = get_le16(buf + 2);
-    symtab_ptr = get_le32(buf + 8);
-    symtab_sz = get_le32(buf + 12);
-    strtab_ptr = symtab_ptr + symtab_sz * 18;
+  if (sectionlist == NULL) {
+    log_msg("Allocating first level of section list failed\n");
+    return 1;
+  }
+
+  // log_msg("COFF: Found %u symbols in %u sections.\n", symtab_sz, nsections);
+
+  /*
+  The size of optional header is always zero for an obj file. So, the section header
+  follows the file header immediately.
+  */
 
-    if (nsections > 96)
-    {
-        log_msg("Too many sections\n");
-        return 1;
-    }
+  ptr = buf + 20;     // section header
 
-    sectionlist = malloc(nsections * sizeof(sectionlist));
+  for (i = 0; i < nsections; i++) {
+    char sectionname[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
+    strncpy(sectionname, ptr, 8);
+    // log_msg("COFF: Parsing section %s\n",sectionname);
 
-    if (sectionlist == NULL)
-    {
-        log_msg("Allocating first level of section list failed\n");
-        return 1;
+    sectionlist[i] = malloc(strlen(sectionname) + 1);
+
+    if (sectionlist[i] == NULL) {
+      log_msg("Allocating storage for %s failed\n", sectionname);
+      goto bail;
     }
+    strcpy(sectionlist[i], sectionname);
 
-    //log_msg("COFF: Found %u symbols in %u sections.\n", symtab_sz, nsections);
+    if (!strcmp(sectionname, ".rdata")) sectionrawdata_ptr = get_le32(ptr + 20);
+
+    ptr += 40;
+  }
+
+  // log_msg("COFF: Symbol table at offset %u\n", symtab_ptr);
+  // log_msg("COFF: raw data pointer ofset for section .rdata is %u\n", sectionrawdata_ptr);
 
-    /*
-    The size of optional header is always zero for an obj file. So, the section header
-    follows the file header immediately.
-    */
+  /*  The compiler puts the data with non-zero offset in .rdata section, but puts the data with
+      zero offset in .bss section. So, if the data in in .bss section, set offset=0.
+      Note from Wiki: In an object module compiled from C, the bss section contains
+      the local variables (but not functions) that were declared with the static keyword,
+      except for those with non-zero initial values. (In C, static variables are initialized
+      to zero by default.) It also contains the non-local (both extern and static) variables
+      that are also initialized to zero (either explicitly or by default).
+      */
+  // move to symbol table
+  /* COFF symbol table:
+      offset      field
+      0           Name(*)
+      8           Value
+      12          SectionNumber
+      14          Type
+      16          StorageClass
+      17          NumberOfAuxSymbols
+      */
+  ptr = buf + symtab_ptr;
 
-    ptr = buf + 20;     //section header
+  for (i = 0; i < symtab_sz; i++) {
+    int16_t section = get_le16(ptr + 12); // section number
 
-    for (i = 0; i < nsections; i++)
-    {
-        char sectionname[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
-        strncpy(sectionname, ptr, 8);
-        //log_msg("COFF: Parsing section %s\n",sectionname);
-
-        sectionlist[i] = malloc(strlen(sectionname) + 1);
+    if (section > 0 && ptr[16] == 2) {
+      // if(section > 0 && ptr[16] == 3 && get_le32(ptr+8)) {
 
-        if (sectionlist[i] == NULL)
-        {
-            log_msg("Allocating storage for %s failed\n", sectionname);
-            goto bail;
-        }
-        strcpy(sectionlist[i], sectionname);
+      if (get_le32(ptr)) {
+        char name[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
+        strncpy(name, ptr, 8);
+        // log_msg("COFF: Parsing symbol %s\n",name);
+        /* The 64bit Windows compiler doesn't prefix with an _.
+         * Check what's there, and bump if necessary
+         */
+        if (name[0] == '_')
+          printf("%-40s EQU ", name + 1);
+        else
+          printf("%-40s EQU ", name);
+      } else {
+        // log_msg("COFF: Parsing symbol %s\n",
+        //        buf + strtab_ptr + get_le32(ptr+4));
+        if ((buf + strtab_ptr + get_le32(ptr + 4))[0] == '_')
+          printf("%-40s EQU ",
+                 buf + strtab_ptr + get_le32(ptr + 4) + 1);
+        else
+          printf("%-40s EQU ", buf + strtab_ptr + get_le32(ptr + 4));
+      }
 
-        if (!strcmp(sectionname, ".rdata")) sectionrawdata_ptr = get_le32(ptr + 20);
+      if (!(strcmp(sectionlist[section - 1], ".bss"))) {
+        symoffset = 0;
+      } else {
+        symoffset = get_le32(buf + sectionrawdata_ptr + get_le32(ptr + 8));
+      }
 
-        ptr += 40;
+      // log_msg("      Section: %d\n",section);
+      // log_msg("      Class:   %d\n",ptr[16]);
+      // log_msg("      Address: %u\n",get_le32(ptr+8));
+      // log_msg("      Offset: %u\n", symoffset);
+
+      printf("%5d\n", symoffset);
     }
 
-    //log_msg("COFF: Symbol table at offset %u\n", symtab_ptr);
-    //log_msg("COFF: raw data pointer ofset for section .rdata is %u\n", sectionrawdata_ptr);
+    ptr += 18;
+  }
 
-    /*  The compiler puts the data with non-zero offset in .rdata section, but puts the data with
-        zero offset in .bss section. So, if the data in in .bss section, set offset=0.
-        Note from Wiki: In an object module compiled from C, the bss section contains
-        the local variables (but not functions) that were declared with the static keyword,
-        except for those with non-zero initial values. (In C, static variables are initialized
-        to zero by default.) It also contains the non-local (both extern and static) variables
-        that are also initialized to zero (either explicitly or by default).
-        */
-    //move to symbol table
-    /* COFF symbol table:
-        offset      field
-        0           Name(*)
-        8           Value
-        12          SectionNumber
-        14          Type
-        16          StorageClass
-        17          NumberOfAuxSymbols
-        */
-    ptr = buf + symtab_ptr;
-
-    for (i = 0; i < symtab_sz; i++)
-    {
-        int16_t section = get_le16(ptr + 12); //section number
-
-        if (section > 0 && ptr[16] == 2)
-        {
-            //if(section > 0 && ptr[16] == 3 && get_le32(ptr+8)) {
+  printf("    END\n");
 
-            if (get_le32(ptr))
-            {
-                char name[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
-                strncpy(name, ptr, 8);
-                //log_msg("COFF: Parsing symbol %s\n",name);
-                /* The 64bit Windows compiler doesn't prefix with an _.
-                 * Check what's there, and bump if necessary
-                 */
-                if (name[0] == '_')
-                    printf("%-40s EQU ", name + 1);
-                else
-                    printf("%-40s EQU ", name);
-            }
-            else
-            {
-                //log_msg("COFF: Parsing symbol %s\n",
-                //        buf + strtab_ptr + get_le32(ptr+4));
-                if ((buf + strtab_ptr + get_le32(ptr + 4))[0] == '_')
-                    printf("%-40s EQU ",
-                           buf + strtab_ptr + get_le32(ptr + 4) + 1);
-                else
-                    printf("%-40s EQU ", buf + strtab_ptr + get_le32(ptr + 4));
-            }
+  for (i = 0; i < nsections; i++) {
+    free(sectionlist[i]);
+  }
 
-            if (!(strcmp(sectionlist[section-1], ".bss")))
-            {
-                symoffset = 0;
-            }
-            else
-            {
-                symoffset = get_le32(buf + sectionrawdata_ptr + get_le32(ptr + 8));
-            }
-
-            //log_msg("      Section: %d\n",section);
-            //log_msg("      Class:   %d\n",ptr[16]);
-            //log_msg("      Address: %u\n",get_le32(ptr+8));
-            //log_msg("      Offset: %u\n", symoffset);
+  free(sectionlist);
 
-            printf("%5d\n", symoffset);
-        }
-
-        ptr += 18;
-    }
-
-    printf("    END\n");
-
-    for (i = 0; i < nsections; i++)
-    {
-        free(sectionlist[i]);
-    }
-
-    free(sectionlist);
-
-    return 0;
+  return 0;
 bail:
 
-    for (i = 0; i < nsections; i++)
-    {
-        free(sectionlist[i]);
-    }
+  for (i = 0; i < nsections; i++) {
+    free(sectionlist[i]);
+  }
 
-    free(sectionlist);
+  free(sectionlist);
 
-    return 1;
+  return 1;
 }
 #endif /* defined(_MSC_VER) || defined(__MINGW32__) || defined(__CYGWIN__) */
 
-int main(int argc, char **argv)
-{
-    output_fmt_t mode = OUTPUT_FMT_PLAIN;
-    const char *f;
-    uint8_t *file_buf;
-    int res;
-    FILE *fp;
-    long int file_size;
+int main(int argc, char **argv) {
+  output_fmt_t mode = OUTPUT_FMT_PLAIN;
+  const char *f;
+  uint8_t *file_buf;
+  int res;
+  FILE *fp;
+  long int file_size;
 
-    if (argc < 2 || argc > 3)
-    {
-        fprintf(stderr, "Usage: %s [output format] <obj file>\n\n", argv[0]);
-        fprintf(stderr, "  <obj file>\tobject file to parse\n");
-        fprintf(stderr, "Output Formats:\n");
-        fprintf(stderr, "  gas  - compatible with GNU assembler\n");
-        fprintf(stderr, "  rvds - compatible with armasm\n");
-        goto bail;
-    }
+  if (argc < 2 || argc > 3) {
+    fprintf(stderr, "Usage: %s [output format] <obj file>\n\n", argv[0]);
+    fprintf(stderr, "  <obj file>\tobject file to parse\n");
+    fprintf(stderr, "Output Formats:\n");
+    fprintf(stderr, "  gas  - compatible with GNU assembler\n");
+    fprintf(stderr, "  rvds - compatible with armasm\n");
+    goto bail;
+  }
 
-    f = argv[2];
+  f = argv[2];
 
-    if (!strcmp(argv[1], "rvds"))
-        mode = OUTPUT_FMT_RVDS;
-    else if (!strcmp(argv[1], "gas"))
-        mode = OUTPUT_FMT_GAS;
-    else
-        f = argv[1];
+  if (!strcmp(argv[1], "rvds"))
+    mode = OUTPUT_FMT_RVDS;
+  else if (!strcmp(argv[1], "gas"))
+    mode = OUTPUT_FMT_GAS;
+  else
+    f = argv[1];
 
-    fp = fopen(f, "rb");
+  fp = fopen(f, "rb");
 
-    if (!fp)
-    {
-        perror("Unable to open file");
-        goto bail;
-    }
+  if (!fp) {
+    perror("Unable to open file");
+    goto bail;
+  }
 
-    if (fseek(fp, 0, SEEK_END))
-    {
-        perror("stat");
-        goto bail;
-    }
+  if (fseek(fp, 0, SEEK_END)) {
+    perror("stat");
+    goto bail;
+  }
 
-    file_size = ftell(fp);
-    file_buf = malloc(file_size);
+  file_size = ftell(fp);
+  file_buf = malloc(file_size);
 
-    if (!file_buf)
-    {
-        perror("malloc");
-        goto bail;
-    }
+  if (!file_buf) {
+    perror("malloc");
+    goto bail;
+  }
 
-    rewind(fp);
+  rewind(fp);
 
-    if (fread(file_buf, sizeof(char), file_size, fp) != file_size)
-    {
-        perror("read");
-        goto bail;
-    }
+  if (fread(file_buf, sizeof(char), file_size, fp) != file_size) {
+    perror("read");
+    goto bail;
+  }
 
-    if (fclose(fp))
-    {
-        perror("close");
-        goto bail;
-    }
+  if (fclose(fp)) {
+    perror("close");
+    goto bail;
+  }
 
 #if defined(__GNUC__) && __GNUC__
 #if defined(__MACH__)
-    res = parse_macho(file_buf, file_size);
+  res = parse_macho(file_buf, file_size, mode);
 #elif defined(__ELF__)
-    res = parse_elf(file_buf, file_size, mode);
+  res = parse_elf(file_buf, file_size, mode);
 #endif
 #endif
 #if defined(_MSC_VER) || defined(__MINGW32__) || defined(__CYGWIN__)
-    res = parse_coff(file_buf, file_size);
+  res = parse_coff(file_buf, file_size);
 #endif
 
-    free(file_buf);
+  free(file_buf);
 
-    if (!res)
-        return EXIT_SUCCESS;
+  if (!res)
+    return EXIT_SUCCESS;
 
 bail:
-    return EXIT_FAILURE;
+  return EXIT_FAILURE;
 }
new file mode 100644
--- /dev/null
+++ b/media/libvpx/build/make/thumb.pm
@@ -0,0 +1,70 @@
+#!/usr/bin/perl
+##
+##  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.
+##
+
+package thumb;
+
+sub FixThumbInstructions($$)
+{
+    my $short_branches = $_[1];
+    my $branch_shift_offset = $short_branches ? 1 : 0;
+
+    # Write additions with shifts, such as "add r10, r11, lsl #8",
+    # in three operand form, "add r10, r10, r11, lsl #8".
+    s/(add\s+)(r\d+),\s*(r\d+),\s*(lsl #\d+)/$1$2, $2, $3, $4/g;
+
+    # Convert additions with a non-constant shift into a sequence
+    # with left shift, addition and a right shift (to restore the
+    # register to the original value). Currently the right shift
+    # isn't necessary in the code base since the values in these
+    # registers aren't used, but doing the shift for consitency.
+    # This converts instructions such as "add r12, r12, r5, lsl r4"
+    # into the sequence "lsl r5, r4", "add r12, r12, r5", "lsr r5, r4".
+    s/^(\s*)(add)(\s+)(r\d+),\s*(r\d+),\s*(r\d+),\s*lsl (r\d+)/$1lsl$3$6, $7\n$1$2$3$4, $5, $6\n$1lsr$3$6, $7/g;
+
+    # Convert loads with right shifts in the indexing into a
+    # sequence of an add, load and sub. This converts
+    # "ldrb r4, [r9, lr, asr #1]" into "add r9, r9, lr, asr #1",
+    # "ldrb r9, [r9]", "sub r9, r9, lr, asr #1".
+    s/^(\s*)(ldrb)(\s+)(r\d+),\s*\[(\w+),\s*(\w+),\s*(asr #\d+)\]/$1add $3$5, $5, $6, $7\n$1$2$3$4, [$5]\n$1sub $3$5, $5, $6, $7/g;
+
+    # Convert register indexing with writeback into a separate add
+    # instruction. This converts "ldrb r12, [r1, r2]!" into
+    # "ldrb r12, [r1, r2]", "add r1, r1, r2".
+    s/^(\s*)(ldrb)(\s+)(r\d+),\s*\[(\w+),\s*(\w+)\]!/$1$2$3$4, [$5, $6]\n$1add $3$5, $6/g;
+
+    # Convert negative register indexing into separate sub/add instructions.
+    # This converts "ldrne r4, [src, -pstep, lsl #1]" into
+    # "subne src, src, pstep, lsl #1", "ldrne r4, [src]",
+    # "addne src, src, pstep, lsl #1". In a couple of cases where
+    # this is used, it's used for two subsequent load instructions,
+    # where a hand-written version of it could merge two subsequent
+    # add and sub instructions.
+    s/^(\s*)((ldr|str|pld)(ne)?)(\s+)(r\d+,\s*)?\[(\w+), -([^\]]+)\]/$1sub$4$5$7, $7, $8\n$1$2$5$6\[$7\]\n$1add$4$5$7, $7, $8/g;
+
+    # Convert register post indexing to a separate add instruction.
+    # This converts "ldrneb r9, [r0], r2" into "ldrneb r9, [r0]",
+    # "add r0, r2".
+    s/^(\s*)((ldr|str)(ne)?[bhd]?)(\s+)(\w+),(\s*\w+,)?\s*\[(\w+)\],\s*(\w+)/$1$2$5$6,$7 [$8]\n$1add$4$5$8, $8, $9/g;
+
+    # Convert a conditional addition to the pc register into a series of
+    # instructions. This converts "addlt pc, pc, r3, lsl #2" into
+    # "itttt lt", "movlt.n r12, pc", "addlt.w r12, #12",
+    # "addlt.w r12, r12, r3, lsl #2", "movlt.n pc, r12".
+    # This assumes that r12 is free at this point.
+    s/^(\s*)addlt(\s+)pc,\s*pc,\s*(\w+),\s*lsl\s*#(\d+)/$1itttt$2lt\n$1movlt.n$2r12, pc\n$1addlt.w$2r12, #12\n$1addlt.w$2r12, r12, $3, lsl #($4-$branch_shift_offset)\n$1movlt.n$2pc, r12/g;
+
+    # Convert "mov pc, lr" into "bx lr", since the former only works
+    # for switching from arm to thumb (and only in armv7), but not
+    # from thumb to arm.
+    s/mov(\s*)pc\s*,\s*lr/bx$1lr/g;
+}
+
+1;
--- a/media/libvpx/moz.build
+++ b/media/libvpx/moz.build
@@ -1,315 +1,75 @@
 # -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
 # vim: set filetype=python:
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
-EXPORTS.vpx += [
-    'vpx/vp8.h',
-    'vpx/vp8cx.h',
-    'vpx/vp8dx.h',
-    'vpx/vpx_codec.h',
-    'vpx/vpx_codec_impl_bottom.h',
-    'vpx/vpx_codec_impl_top.h',
-    'vpx/vpx_decoder.h',
-    'vpx/vpx_encoder.h',
-    'vpx/vpx_image.h',
-    'vpx/vpx_integer.h',
-    'vpx_mem/include/vpx_mem_intrnl.h',
-    'vpx_mem/vpx_mem.h',
-    'vpx_ports/arm.h',
-    'vpx_ports/mem.h',
-    'vpx_ports/vpx_timer.h',
-    'vpx_ports/x86.h',
-    'vpx_scale/scale_mode.h',
-    'vpx_scale/vpxscale.h',
-    'vpx_scale/yv12config.h',
-]
+include('sources.mozbuild')
+
+EXPORTS.vpx += files['EXPORTS']
 
 if CONFIG['VPX_NEED_OBJ_INT_EXTRACT']:
     HOST_SOURCES += [
         'build/make/obj_int_extract.c',
     ]
 
     HOST_PROGRAM = 'host_obj_int_extract'
 
-SOURCES += [
-    'vp8/common/alloccommon.c',
-    'vp8/common/blockd.c',
-    'vp8/common/debugmodes.c',
-    'vp8/common/dequantize.c',
-    'vp8/common/entropy.c',
-    'vp8/common/entropymode.c',
-    'vp8/common/entropymv.c',
-    'vp8/common/extend.c',
-    'vp8/common/filter.c',
-    'vp8/common/findnearmv.c',
-    'vp8/common/generic/systemdependent.c',
-    'vp8/common/idct_blk.c',
-    'vp8/common/idctllm.c',
-    'vp8/common/loopfilter.c',
-    'vp8/common/loopfilter_filters.c',
-    'vp8/common/mbpitch.c',
-    'vp8/common/modecont.c',
-    'vp8/common/quant_common.c',
-    'vp8/common/reconinter.c',
-    'vp8/common/reconintra.c',
-    'vp8/common/reconintra4x4.c',
-    'vp8/common/rtcd.c',
-    'vp8/common/sad_c.c',
-    'vp8/common/setupintrarecon.c',
-    'vp8/common/swapyv12buffer.c',
-    'vp8/common/treecoder.c',
-    'vp8/common/variance_c.c',
-    'vp8/decoder/asm_dec_offsets.c',
-    'vp8/decoder/dboolhuff.c',
-    'vp8/decoder/decodemv.c',
-    'vp8/decoder/decodframe.c',
-    'vp8/decoder/detokenize.c',
-    'vp8/decoder/onyxd_if.c',
-    'vp8/decoder/threading.c',
-    'vp8/vp8_dx_iface.c',
-    'vpx/src/vpx_codec.c',
-    'vpx/src/vpx_decoder.c',
-    'vpx/src/vpx_encoder.c',
-    'vpx/src/vpx_image.c',
-    'vpx_mem/vpx_mem.c',
-    'vpx_scale/generic/gen_scalers.c',
-    'vpx_scale/generic/vpxscale.c',
-    'vpx_scale/generic/yv12config.c',
-    'vpx_scale/generic/yv12extend.c',
-]
+SOURCES += files['COMMON']
 
 if CONFIG['MOZ_VP8_ERROR_CONCEALMENT']:
-    SOURCES += [
-        'vp8/decoder/error_concealment.c'
-    ]
+    SOURCES += files['ERROR_CONCEALMENT']
 
 if CONFIG['MOZ_VP8_ENCODER']:
-    SOURCES += [
-        'vp8/encoder/bitstream.c',
-        'vp8/encoder/dct.c',
-        'vp8/encoder/encodeframe.c',
-        'vp8/encoder/encodeintra.c',
-        'vp8/encoder/encodemb.c',
-        'vp8/encoder/encodemv.c',
-        'vp8/encoder/ethreading.c',
-        'vp8/encoder/firstpass.c',
-        'vp8/encoder/lookahead.c',
-        'vp8/encoder/mcomp.c',
-        'vp8/encoder/modecosts.c',
-        'vp8/encoder/mr_dissim.c',
-        'vp8/encoder/onyx_if.c',
-        'vp8/encoder/pickinter.c',
-        'vp8/encoder/picklpf.c',
-        'vp8/encoder/psnr.c',
-        'vp8/encoder/quantize.c',
-        'vp8/encoder/ratectrl.c',
-        'vp8/encoder/rdopt.c',
-        'vp8/encoder/segmentation.c',
-        'vp8/encoder/tokenize.c',
-        'vp8/encoder/treewriter.c',
-        'vp8/vp8_cx_iface.c',
-    ]
+    SOURCES += files['ENCODER']
 
 #postproc is only enabled on x86 with asm
 if CONFIG['VPX_X86_ASM']:
-    SOURCES += [
-        'vp8/common/mfqe.c',
-        'vp8/common/postproc.c',
-        'vp8/encoder/temporal_filter.c',
-    ]
+    SOURCES += files['VP8_POSTPROC']
 
 if CONFIG['VPX_X86_ASM'] and CONFIG['OS_TARGET'] == 'WINNT':
     SOURCES += [
-        'vp8/common/asm_com_offsets.c',
+        'vpx_scale/vpx_scale_asm_offsets.c',
     ]
     if CONFIG['MOZ_VP8_ENCODER']:
         SOURCES += [
-            'vp8/encoder/asm_enc_offsets.c',
+            'vp8/encoder/vp8_asm_enc_offsets.c',
         ]
 
 if CONFIG['VPX_X86_ASM']:
-    SOURCES += [
-        'vp8/common/x86/filter_x86.c',
-        'vp8/common/x86/idct_blk_mmx.c',
-        'vp8/common/x86/idct_blk_sse2.c',
-        'vp8/common/x86/loopfilter_x86.c',
-        'vp8/common/x86/postproc_x86.c',
-        'vp8/common/x86/recon_wrapper_sse2.c',
-        'vp8/common/x86/variance_mmx.c',
-        'vp8/common/x86/variance_sse2.c',
-        'vp8/common/x86/variance_ssse3.c',
-        'vp8/common/x86/vp8_asm_stubs.c',
-        'vpx_ports/x86_cpuid.c',
-    ]
-    SOURCES += [
-        'vp8/common/x86/dequantize_mmx.asm',
-        'vp8/common/x86/idctllm_mmx.asm',
-        'vp8/common/x86/idctllm_sse2.asm',
-        'vp8/common/x86/iwalsh_mmx.asm',
-        'vp8/common/x86/iwalsh_sse2.asm',
-        'vp8/common/x86/loopfilter_mmx.asm',
-        'vp8/common/x86/loopfilter_sse2.asm',
-        'vp8/common/x86/mfqe_sse2.asm',
-        'vp8/common/x86/postproc_mmx.asm',
-        'vp8/common/x86/postproc_sse2.asm',
-        'vp8/common/x86/recon_mmx.asm',
-        'vp8/common/x86/recon_sse2.asm',
-        'vp8/common/x86/sad_mmx.asm',
-        'vp8/common/x86/sad_sse2.asm',
-        'vp8/common/x86/sad_sse3.asm',
-        'vp8/common/x86/sad_sse4.asm',
-        'vp8/common/x86/sad_ssse3.asm',
-        'vp8/common/x86/subpixel_mmx.asm',
-        'vp8/common/x86/subpixel_sse2.asm',
-        'vp8/common/x86/subpixel_ssse3.asm',
-        'vp8/common/x86/variance_impl_mmx.asm',
-        'vp8/common/x86/variance_impl_sse2.asm',
-        'vp8/common/x86/variance_impl_ssse3.asm',
-        'vpx_ports/emms.asm',
-    ]
+    SOURCES += files['X86_ASM']
 
     if '64' in CONFIG['OS_TEST']:
-        SOURCES += [
-            'vp8/common/x86/loopfilter_block_sse2.asm',
-        ]
+        SOURCES += files['X86-64_ASM']
+
+    # AVX2 only supported on
+    # Darwin toolchain right now
+    if CONFIG['OS_TARGET'] == 'Darwin':
+        SOURCES += files['AVX2']
 
 if CONFIG['VPX_X86_ASM'] and CONFIG['MOZ_VP8_ENCODER']:
-    SOURCES += [
-        'vp8/encoder/x86/vp8_enc_stubs_mmx.c',
-        'vp8/encoder/x86/vp8_enc_stubs_sse2.c',
-    ]
-    SOURCES += [
-        'vp8/encoder/x86/dct_mmx.asm',
-        'vp8/encoder/x86/dct_sse2.asm',
-        'vp8/encoder/x86/encodeopt.asm',
-        'vp8/encoder/x86/fwalsh_sse2.asm',
-        'vp8/encoder/x86/quantize_mmx.asm',
-        'vp8/encoder/x86/quantize_sse2.asm',
-        'vp8/encoder/x86/quantize_sse4.asm',
-        'vp8/encoder/x86/quantize_ssse3.asm',
-        'vp8/encoder/x86/subtract_mmx.asm',
-        'vp8/encoder/x86/subtract_sse2.asm',
-        'vp8/encoder/x86/temporal_filter_apply_sse2.asm',
-
-    ]
-
-if CONFIG['MOZ_VP8_ENCODER']:
-    SOURCES += [
-        'vp8/encoder/denoising.c',
-    ]
-    if CONFIG['VPX_X86_ASM']:
-        SOURCES += [
-            'vp8/encoder/x86/denoising_sse2.c',
-        ]
+    SOURCES += files['X86_ASM_ENCODER']
+    if '64' in CONFIG['OS_TEST']:
+        SOURCES += files['X86-64_ASM_ENCODER']
 
 arm_asm_files = []
+if CONFIG['VPX_ARM_ASM']:
+    arm_asm_files += files['ARM_ASM']
+    if CONFIG['MOZ_VP8_ENCODER']:
+        arm_asm_files += files['ARM_ASM_ENCODER']
 
-if CONFIG['VPX_ARM_ASM']:
-    SOURCES += [
-        'vp8/common/arm/armv6/idct_blk_v6.c',
-        'vp8/common/arm/bilinearfilter_arm.c',
-        'vp8/common/arm/dequantize_arm.c',
-        'vp8/common/arm/filter_arm.c',
-        'vp8/common/arm/loopfilter_arm.c',
-        'vp8/common/arm/neon/idct_blk_neon.c',
-        'vp8/common/arm/reconintra_arm.c',
-        'vp8/common/arm/variance_arm.c',
-        'vpx_ports/arm_cpudetect.c',
-        'vpx_scale/arm/neon/yv12extend_arm.c',
-    ]
-    arm_asm_files += [
-        'vp8/common/arm/armv6/bilinearfilter_v6.asm',
-        'vp8/common/arm/armv6/copymem16x16_v6.asm',
-        'vp8/common/arm/armv6/copymem8x4_v6.asm',
-        'vp8/common/arm/armv6/copymem8x8_v6.asm',
-        'vp8/common/arm/armv6/dc_only_idct_add_v6.asm',
-        'vp8/common/arm/armv6/dequant_idct_v6.asm',
-        'vp8/common/arm/armv6/dequantize_v6.asm',
-        'vp8/common/arm/armv6/filter_v6.asm',
-        'vp8/common/arm/armv6/idct_v6.asm',
-        'vp8/common/arm/armv6/intra4x4_predict_v6.asm',
-        'vp8/common/arm/armv6/iwalsh_v6.asm',
-        'vp8/common/arm/armv6/loopfilter_v6.asm',
-        'vp8/common/arm/armv6/simpleloopfilter_v6.asm',
-        'vp8/common/arm/armv6/sixtappredict8x4_v6.asm',
-        'vp8/common/arm/armv6/vp8_sad16x16_armv6.asm',
-        'vp8/common/arm/armv6/vp8_variance16x16_armv6.asm',
-        'vp8/common/arm/armv6/vp8_variance8x8_armv6.asm',
-        'vp8/common/arm/armv6/vp8_variance_halfpixvar16x16_h_armv6.asm',
-        'vp8/common/arm/armv6/vp8_variance_halfpixvar16x16_hv_armv6.asm',
-        'vp8/common/arm/armv6/vp8_variance_halfpixvar16x16_v_armv6.asm',
-        'vp8/common/arm/neon/bilinearpredict16x16_neon.asm',
-        'vp8/common/arm/neon/bilinearpredict4x4_neon.asm',
-        'vp8/common/arm/neon/bilinearpredict8x4_neon.asm',
-        'vp8/common/arm/neon/bilinearpredict8x8_neon.asm',
-        'vp8/common/arm/neon/buildintrapredictorsmby_neon.asm',
-        'vp8/common/arm/neon/copymem16x16_neon.asm',
-        'vp8/common/arm/neon/copymem8x4_neon.asm',
-        'vp8/common/arm/neon/copymem8x8_neon.asm',
-        'vp8/common/arm/neon/dc_only_idct_add_neon.asm',
-        'vp8/common/arm/neon/dequant_idct_neon.asm',
-        'vp8/common/arm/neon/dequantizeb_neon.asm',
-        'vp8/common/arm/neon/idct_dequant_0_2x_neon.asm',
-        'vp8/common/arm/neon/idct_dequant_full_2x_neon.asm',
-        'vp8/common/arm/neon/iwalsh_neon.asm',
-        'vp8/common/arm/neon/loopfilter_neon.asm',
-        'vp8/common/arm/neon/loopfiltersimplehorizontaledge_neon.asm',
-        'vp8/common/arm/neon/loopfiltersimpleverticaledge_neon.asm',
-        'vp8/common/arm/neon/mbloopfilter_neon.asm',
-        'vp8/common/arm/neon/sad16_neon.asm',
-        'vp8/common/arm/neon/sad8_neon.asm',
-        'vp8/common/arm/neon/save_reg_neon.asm',
-        'vp8/common/arm/neon/shortidct4x4llm_neon.asm',
-        'vp8/common/arm/neon/sixtappredict16x16_neon.asm',
-        'vp8/common/arm/neon/sixtappredict4x4_neon.asm',
-        'vp8/common/arm/neon/sixtappredict8x4_neon.asm',
-        'vp8/common/arm/neon/sixtappredict8x8_neon.asm',
-        'vp8/common/arm/neon/variance_neon.asm',
-        'vp8/common/arm/neon/vp8_subpixelvariance16x16_neon.asm',
-        'vp8/common/arm/neon/vp8_subpixelvariance16x16s_neon.asm',
-        'vp8/common/arm/neon/vp8_subpixelvariance8x8_neon.asm',
-        'vp8/encoder/arm/armv6/vp8_mse16x16_armv6.asm',
-        'vp8/encoder/arm/neon/vp8_mse16x16_neon.asm',
-        'vpx_scale/arm/neon/vp8_vpxyv12_copy_y_neon.asm',
-        'vpx_scale/arm/neon/vp8_vpxyv12_copyframe_func_neon.asm',
-        'vpx_scale/arm/neon/vp8_vpxyv12_copysrcframe_func_neon.asm',
-        'vpx_scale/arm/neon/vp8_vpxyv12_extendframeborders_neon.asm',
-    ]
-
-if CONFIG['VPX_ARM_ASM'] and CONFIG['MOZ_VP8_ENCODER']:
-    SOURCES += [
-        'vp8/encoder/arm/boolhuff_arm.c',
-        'vp8/encoder/arm/dct_arm.c',
-        'vp8/encoder/arm/neon/picklpf_arm.c',
-        'vp8/encoder/arm/quantize_arm.c',
-    ]
-    arm_asm_files += [
-        'vp8/encoder/arm/armv5te/boolhuff_armv5te.asm',
-        'vp8/encoder/arm/armv5te/vp8_packtokens_armv5.asm',
-        'vp8/encoder/arm/armv5te/vp8_packtokens_mbrow_armv5.asm',
-        'vp8/encoder/arm/armv5te/vp8_packtokens_partitions_armv5.asm',
-        'vp8/encoder/arm/armv6/vp8_fast_quantize_b_armv6.asm',
-        'vp8/encoder/arm/armv6/vp8_short_fdct4x4_armv6.asm',
-        'vp8/encoder/arm/armv6/vp8_subtract_armv6.asm',
-        'vp8/encoder/arm/armv6/walsh_v6.asm',
-        'vp8/encoder/arm/neon/fastquantizeb_neon.asm',
-        'vp8/encoder/arm/neon/shortfdct_neon.asm',
-        'vp8/encoder/arm/neon/subtract_neon.asm',
-        'vp8/encoder/arm/neon/vp8_memcpy_neon.asm',
-        'vp8/encoder/arm/neon/vp8_shortwalsh4x4_neon.asm',
-    ]
-
-if arm_asm_files:
     if CONFIG['VPX_AS_CONVERSION']:
         GENERATED_SOURCES += [ "%s.%s" % (f, CONFIG['VPX_ASM_SUFFIX'])
-            for f in sorted(arm_asm_files)]
+            for f in sorted(arm_asm_files) if f.endswith('.asm')
+        ]
+        SOURCES += [
+            f for f in sorted(arm_asm_files) if not f.endswith('.asm')
+        ]
     else:
         SOURCES += sorted(arm_asm_files)
 
 # boolhuff_armv5te.asm defines the same functions as boolhuff.c instead of
 # using RTCD, so we have to make sure we only add one of the two.
 if CONFIG['MOZ_VP8_ENCODER'] \
     and 'vp8/encoder/arm/armv5te/boolhuff_armv5te.asm' not in arm_asm_files:
     SOURCES += [
new file mode 100644
--- /dev/null
+++ b/media/libvpx/sources.mozbuild
@@ -0,0 +1,333 @@
+files = {
+ 'ARM_ASM': ['vp8/common/arm/armv6/bilinearfilter_v6.asm',
+             'vp8/common/arm/armv6/copymem16x16_v6.asm',
+             'vp8/common/arm/armv6/copymem8x4_v6.asm',
+             'vp8/common/arm/armv6/copymem8x8_v6.asm',
+             'vp8/common/arm/armv6/dc_only_idct_add_v6.asm',
+             'vp8/common/arm/armv6/dequant_idct_v6.asm',
+             'vp8/common/arm/armv6/dequantize_v6.asm',
+             'vp8/common/arm/armv6/filter_v6.asm',
+             'vp8/common/arm/armv6/idct_blk_v6.c',
+             'vp8/common/arm/armv6/idct_v6.asm',
+             'vp8/common/arm/armv6/intra4x4_predict_v6.asm',
+             'vp8/common/arm/armv6/iwalsh_v6.asm',
+             'vp8/common/arm/armv6/loopfilter_v6.asm',
+             'vp8/common/arm/armv6/simpleloopfilter_v6.asm',
+             'vp8/common/arm/armv6/sixtappredict8x4_v6.asm',
+             'vp8/common/arm/armv6/vp8_sad16x16_armv6.asm',
+             'vp8/common/arm/armv6/vp8_variance16x16_armv6.asm',
+             'vp8/common/arm/armv6/vp8_variance8x8_armv6.asm',
+             'vp8/common/arm/armv6/vp8_variance_halfpixvar16x16_h_armv6.asm',
+             'vp8/common/arm/armv6/vp8_variance_halfpixvar16x16_hv_armv6.asm',
+             'vp8/common/arm/armv6/vp8_variance_halfpixvar16x16_v_armv6.asm',
+             'vp8/common/arm/bilinearfilter_arm.c',
+             'vp8/common/arm/dequantize_arm.c',
+             'vp8/common/arm/filter_arm.c',
+             'vp8/common/arm/loopfilter_arm.c',
+             'vp8/common/arm/neon/bilinearpredict16x16_neon.asm',
+             'vp8/common/arm/neon/bilinearpredict4x4_neon.asm',
+             'vp8/common/arm/neon/bilinearpredict8x4_neon.asm',
+             'vp8/common/arm/neon/bilinearpredict8x8_neon.asm',
+             'vp8/common/arm/neon/buildintrapredictorsmby_neon.asm',
+             'vp8/common/arm/neon/copymem16x16_neon.asm',
+             'vp8/common/arm/neon/copymem8x4_neon.asm',
+             'vp8/common/arm/neon/copymem8x8_neon.asm',
+             'vp8/common/arm/neon/dc_only_idct_add_neon.asm',
+             'vp8/common/arm/neon/dequant_idct_neon.asm',
+             'vp8/common/arm/neon/dequantizeb_neon.asm',
+             'vp8/common/arm/neon/idct_blk_neon.c',
+             'vp8/common/arm/neon/idct_dequant_0_2x_neon.asm',
+             'vp8/common/arm/neon/idct_dequant_full_2x_neon.asm',
+             'vp8/common/arm/neon/iwalsh_neon.asm',
+             'vp8/common/arm/neon/loopfilter_neon.asm',
+             'vp8/common/arm/neon/loopfiltersimplehorizontaledge_neon.asm',
+             'vp8/common/arm/neon/loopfiltersimpleverticaledge_neon.asm',
+             'vp8/common/arm/neon/mbloopfilter_neon.asm',
+             'vp8/common/arm/neon/sad16_neon.asm',
+             'vp8/common/arm/neon/sad8_neon.asm',
+             'vp8/common/arm/neon/save_reg_neon.asm',
+             'vp8/common/arm/neon/shortidct4x4llm_neon.asm',
+             'vp8/common/arm/neon/sixtappredict16x16_neon.asm',
+             'vp8/common/arm/neon/sixtappredict4x4_neon.asm',
+             'vp8/common/arm/neon/sixtappredict8x4_neon.asm',
+             'vp8/common/arm/neon/sixtappredict8x8_neon.asm',
+             'vp8/common/arm/neon/variance_neon.asm',
+             'vp8/common/arm/neon/vp8_subpixelvariance16x16_neon.asm',
+             'vp8/common/arm/neon/vp8_subpixelvariance16x16s_neon.asm',
+             'vp8/common/arm/neon/vp8_subpixelvariance8x8_neon.asm',
+             'vp8/common/arm/reconintra_arm.c',
+             'vp8/common/arm/variance_arm.c',
+             'vp9/common/arm/neon/vp9_avg_neon.asm',
+             'vp9/common/arm/neon/vp9_convolve8_avg_neon.asm',
+             'vp9/common/arm/neon/vp9_convolve8_neon.asm',
+             'vp9/common/arm/neon/vp9_convolve_neon.c',
+             'vp9/common/arm/neon/vp9_copy_neon.asm',
+             'vp9/common/arm/neon/vp9_dc_only_idct_add_neon.asm',
+             'vp9/common/arm/neon/vp9_idct16x16_neon.c',
+             'vp9/common/arm/neon/vp9_loopfilter_neon.asm',
+             'vp9/common/arm/neon/vp9_mb_lpf_neon.asm',
+             'vp9/common/arm/neon/vp9_save_reg_neon.asm',
+             'vp9/common/arm/neon/vp9_short_idct16x16_1_add_neon.asm',
+             'vp9/common/arm/neon/vp9_short_idct16x16_add_neon.asm',
+             'vp9/common/arm/neon/vp9_short_idct32x32_1_add_neon.asm',
+             'vp9/common/arm/neon/vp9_short_idct32x32_add_neon.asm',
+             'vp9/common/arm/neon/vp9_short_idct4x4_1_add_neon.asm',
+             'vp9/common/arm/neon/vp9_short_idct4x4_add_neon.asm',
+             'vp9/common/arm/neon/vp9_short_idct8x8_1_add_neon.asm',
+             'vp9/common/arm/neon/vp9_short_idct8x8_add_neon.asm',
+             'vp9/common/arm/neon/vp9_short_iht4x4_add_neon.asm',
+             'vp9/common/arm/neon/vp9_short_iht8x8_add_neon.asm',
+             'vpx_ports/arm_cpudetect.c',
+             'vpx_scale/arm/neon/vp8_vpxyv12_copy_y_neon.asm',
+             'vpx_scale/arm/neon/vp8_vpxyv12_copyframe_func_neon.asm',
+             'vpx_scale/arm/neon/vp8_vpxyv12_copysrcframe_func_neon.asm',
+             'vpx_scale/arm/neon/vp8_vpxyv12_extendframeborders_neon.asm',
+             'vpx_scale/arm/neon/yv12extend_arm.c'],
+ 'ARM_ASM_ENCODER': ['vp8/encoder/arm/armv5te/boolhuff_armv5te.asm',
+                     'vp8/encoder/arm/armv5te/vp8_packtokens_armv5.asm',
+                     'vp8/encoder/arm/armv5te/vp8_packtokens_mbrow_armv5.asm',
+                     'vp8/encoder/arm/armv5te/vp8_packtokens_partitions_armv5.asm',
+                     'vp8/encoder/arm/armv6/vp8_fast_quantize_b_armv6.asm',
+                     'vp8/encoder/arm/armv6/vp8_mse16x16_armv6.asm',
+                     'vp8/encoder/arm/armv6/vp8_short_fdct4x4_armv6.asm',
+                     'vp8/encoder/arm/armv6/vp8_subtract_armv6.asm',
+                     'vp8/encoder/arm/armv6/walsh_v6.asm',
+                     'vp8/encoder/arm/boolhuff_arm.c',
+                     'vp8/encoder/arm/dct_arm.c',
+                     'vp8/encoder/arm/neon/fastquantizeb_neon.asm',
+                     'vp8/encoder/arm/neon/picklpf_arm.c',
+                     'vp8/encoder/arm/neon/shortfdct_neon.asm',
+                     'vp8/encoder/arm/neon/subtract_neon.asm',
+                     'vp8/encoder/arm/neon/vp8_memcpy_neon.asm',
+                     'vp8/encoder/arm/neon/vp8_mse16x16_neon.asm',
+                     'vp8/encoder/arm/neon/vp8_shortwalsh4x4_neon.asm',
+                     'vp8/encoder/arm/quantize_arm.c'],
+ 'AVX2': ['vp9/common/x86/vp9_loopfilter_intrin_avx2.c'],
+ 'COMMON': ['vp8/common/alloccommon.c',
+            'vp8/common/blockd.c',
+            'vp8/common/debugmodes.c',
+            'vp8/common/dequantize.c',
+            'vp8/common/entropy.c',
+            'vp8/common/entropymode.c',
+            'vp8/common/entropymv.c',
+            'vp8/common/extend.c',
+            'vp8/common/filter.c',
+            'vp8/common/findnearmv.c',
+            'vp8/common/generic/systemdependent.c',
+            'vp8/common/idct_blk.c',
+            'vp8/common/idctllm.c',
+            'vp8/common/loopfilter.c',
+            'vp8/common/loopfilter_filters.c',
+            'vp8/common/mbpitch.c',
+            'vp8/common/modecont.c',
+            'vp8/common/quant_common.c',
+            'vp8/common/reconinter.c',
+            'vp8/common/reconintra.c',
+            'vp8/common/reconintra4x4.c',
+            'vp8/common/rtcd.c',
+            'vp8/common/sad_c.c',
+            'vp8/common/setupintrarecon.c',
+            'vp8/common/swapyv12buffer.c',
+            'vp8/common/treecoder.c',
+            'vp8/common/variance_c.c',
+            'vp8/decoder/dboolhuff.c',
+            'vp8/decoder/decodemv.c',
+            'vp8/decoder/decodframe.c',
+            'vp8/decoder/detokenize.c',
+            'vp8/decoder/onyxd_if.c',
+            'vp8/decoder/threading.c',
+            'vp8/vp8_dx_iface.c',
+            'vp9/common/generic/vp9_systemdependent.c',
+            'vp9/common/vp9_alloccommon.c',
+            'vp9/common/vp9_common_data.c',
+            'vp9/common/vp9_convolve.c',
+            'vp9/common/vp9_debugmodes.c',
+            'vp9/common/vp9_entropy.c',
+            'vp9/common/vp9_entropymode.c',
+            'vp9/common/vp9_entropymv.c',
+            'vp9/common/vp9_extend.c',
+            'vp9/common/vp9_filter.c',
+            'vp9/common/vp9_findnearmv.c',
+            'vp9/common/vp9_idct.c',
+            'vp9/common/vp9_loopfilter.c',
+            'vp9/common/vp9_loopfilter_filters.c',
+            'vp9/common/vp9_mvref_common.c',
+            'vp9/common/vp9_pred_common.c',
+            'vp9/common/vp9_quant_common.c',
+            'vp9/common/vp9_reconinter.c',
+            'vp9/common/vp9_reconintra.c',
+            'vp9/common/vp9_rtcd.c',
+            'vp9/common/vp9_scale.c',
+            'vp9/common/vp9_scan.c',
+            'vp9/common/vp9_seg_common.c',
+            'vp9/common/vp9_tile_common.c',
+            'vp9/common/vp9_treecoder.c',
+            'vp9/decoder/vp9_dboolhuff.c',
+            'vp9/decoder/vp9_decodemv.c',
+            'vp9/decoder/vp9_decodframe.c',
+            'vp9/decoder/vp9_detokenize.c',
+            'vp9/decoder/vp9_dsubexp.c',
+            'vp9/decoder/vp9_onyxd_if.c',
+            'vp9/decoder/vp9_thread.c',
+            'vp9/vp9_dx_iface.c',
+            'vpx/src/vpx_codec.c',
+            'vpx/src/vpx_decoder.c',
+            'vpx/src/vpx_encoder.c',
+            'vpx/src/vpx_image.c',
+            'vpx_mem/vpx_mem.c',
+            'vpx_scale/generic/gen_scalers.c',
+            'vpx_scale/generic/vpx_scale.c',
+            'vpx_scale/generic/yv12config.c',
+            'vpx_scale/generic/yv12extend.c',
+            'vpx_scale/vpx_scale_rtcd.c'],
+ 'ENCODER': ['vp8/encoder/bitstream.c',
+             'vp8/encoder/dct.c',
+             'vp8/encoder/denoising.c',
+             'vp8/encoder/encodeframe.c',
+             'vp8/encoder/encodeintra.c',
+             'vp8/encoder/encodemb.c',
+             'vp8/encoder/encodemv.c',
+             'vp8/encoder/ethreading.c',
+             'vp8/encoder/firstpass.c',
+             'vp8/encoder/lookahead.c',
+             'vp8/encoder/mcomp.c',
+             'vp8/encoder/modecosts.c',
+             'vp8/encoder/mr_dissim.c',
+             'vp8/encoder/onyx_if.c',
+             'vp8/encoder/pickinter.c',
+             'vp8/encoder/picklpf.c',
+             'vp8/encoder/psnr.c',
+             'vp8/encoder/quantize.c',
+             'vp8/encoder/ratectrl.c',
+             'vp8/encoder/rdopt.c',
+             'vp8/encoder/segmentation.c',
+             'vp8/encoder/temporal_filter.c',
+             'vp8/encoder/tokenize.c',
+             'vp8/encoder/treewriter.c',
+             'vp8/vp8_cx_iface.c',
+             'vp9/encoder/vp9_bitstream.c',
+             'vp9/encoder/vp9_boolhuff.c',
+             'vp9/encoder/vp9_dct.c',
+             'vp9/encoder/vp9_encodeframe.c',
+             'vp9/encoder/vp9_encodeintra.c',
+             'vp9/encoder/vp9_encodemb.c',
+             'vp9/encoder/vp9_encodemv.c',
+             'vp9/encoder/vp9_firstpass.c',
+             'vp9/encoder/vp9_lookahead.c',
+             'vp9/encoder/vp9_mbgraph.c',
+             'vp9/encoder/vp9_mcomp.c',
+             'vp9/encoder/vp9_modecosts.c',
+             'vp9/encoder/vp9_onyx_if.c',
+             'vp9/encoder/vp9_picklpf.c',
+             'vp9/encoder/vp9_psnr.c',
+             'vp9/encoder/vp9_quantize.c',
+             'vp9/encoder/vp9_ratectrl.c',
+             'vp9/encoder/vp9_rdopt.c',
+             'vp9/encoder/vp9_sad_c.c',
+             'vp9/encoder/vp9_segmentation.c',
+             'vp9/encoder/vp9_subexp.c',
+             'vp9/encoder/vp9_temporal_filter.c',
+             'vp9/encoder/vp9_tokenize.c',
+             'vp9/encoder/vp9_treewriter.c',
+             'vp9/encoder/vp9_vaq.c',
+             'vp9/encoder/vp9_variance_c.c',
+             'vp9/vp9_cx_iface.c',
+             'vpx/src/svc_encodeframe.c'],
+ 'ERROR_CONCEALMENT': ['vp8/decoder/error_concealment.c'],
+ 'EXPORTS': ['vpx/vp8.h',
+             'vpx/vp8cx.h',
+             'vpx/vp8dx.h',
+             'vpx/vpx_codec.h',
+             'vpx/vpx_decoder.h',
+             'vpx/vpx_encoder.h',
+             'vpx/vpx_image.h',
+             'vpx/vpx_integer.h',
+             'vpx_mem/include/vpx_mem_intrnl.h',
+             'vpx_mem/vpx_mem.h',
+             'vpx_ports/arm.h',
+             'vpx_ports/mem.h',
+             'vpx_ports/vpx_timer.h',
+             'vpx_ports/x86.h',
+             'vpx_scale/vpx_scale.h',
+             'vpx_scale/yv12config.h'],
+ 'VP8_POSTPROC': ['vp8/common/mfqe.c', 'vp8/common/postproc.c'],
+ 'VP9_POSTPROC': ['vp9/common/vp9_postproc.c'],
+ 'X86-64_ASM': ['third_party/x86inc/x86inc.asm',
+                'vp8/common/x86/loopfilter_block_sse2.asm'],
+ 'X86-64_ASM_ENCODER': ['vp9/encoder/x86/vp9_quantize_ssse3.asm'],
+ 'X86_ASM': ['vp8/common/x86/dequantize_mmx.asm',
+             'vp8/common/x86/filter_x86.c',
+             'vp8/common/x86/idct_blk_mmx.c',
+             'vp8/common/x86/idct_blk_sse2.c',
+             'vp8/common/x86/idctllm_mmx.asm',
+             'vp8/common/x86/idctllm_sse2.asm',
+             'vp8/common/x86/iwalsh_mmx.asm',
+             'vp8/common/x86/iwalsh_sse2.asm',
+             'vp8/common/x86/loopfilter_mmx.asm',
+             'vp8/common/x86/loopfilter_sse2.asm',
+             'vp8/common/x86/loopfilter_x86.c',
+             'vp8/common/x86/mfqe_sse2.asm',
+             'vp8/common/x86/postproc_mmx.asm',
+             'vp8/common/x86/postproc_sse2.asm',
+             'vp8/common/x86/postproc_x86.c',
+             'vp8/common/x86/recon_mmx.asm',
+             'vp8/common/x86/recon_sse2.asm',
+             'vp8/common/x86/recon_wrapper_sse2.c',
+             'vp8/common/x86/sad_mmx.asm',
+             'vp8/common/x86/sad_sse2.asm',
+             'vp8/common/x86/sad_sse3.asm',
+             'vp8/common/x86/sad_sse4.asm',
+             'vp8/common/x86/sad_ssse3.asm',
+             'vp8/common/x86/subpixel_mmx.asm',
+             'vp8/common/x86/subpixel_sse2.asm',
+             'vp8/common/x86/subpixel_ssse3.asm',
+             'vp8/common/x86/variance_impl_mmx.asm',
+             'vp8/common/x86/variance_impl_sse2.asm',
+             'vp8/common/x86/variance_impl_ssse3.asm',
+             'vp8/common/x86/variance_mmx.c',
+             'vp8/common/x86/variance_sse2.c',
+             'vp8/common/x86/variance_ssse3.c',
+             'vp8/common/x86/vp8_asm_stubs.c',
+             'vp9/common/x86/vp9_asm_stubs.c',
+             'vp9/common/x86/vp9_copy_sse2.asm',
+             'vp9/common/x86/vp9_idct_intrin_sse2.c',
+             'vp9/common/x86/vp9_intrapred_sse2.asm',
+             'vp9/common/x86/vp9_intrapred_ssse3.asm',
+             'vp9/common/x86/vp9_loopfilter_intrin_sse2.c',
+             'vp9/common/x86/vp9_loopfilter_mmx.asm',
+             'vp9/common/x86/vp9_subpixel_8t_sse2.asm',
+             'vp9/common/x86/vp9_subpixel_8t_ssse3.asm',
+             'vpx_ports/emms.asm',
+             'vpx_ports/x86_cpuid.c'],
+ 'X86_ASM_ENCODER': ['vp8/encoder/x86/dct_mmx.asm',
+                     'vp8/encoder/x86/dct_sse2.asm',
+                     'vp8/encoder/x86/denoising_sse2.c',
+                     'vp8/encoder/x86/encodeopt.asm',
+                     'vp8/encoder/x86/fwalsh_sse2.asm',
+                     'vp8/encoder/x86/quantize_mmx.asm',
+                     'vp8/encoder/x86/quantize_sse2.c',
+                     'vp8/encoder/x86/quantize_sse4.asm',
+                     'vp8/encoder/x86/quantize_ssse3.asm',
+                     'vp8/encoder/x86/subtract_mmx.asm',
+                     'vp8/encoder/x86/subtract_sse2.asm',
+                     'vp8/encoder/x86/temporal_filter_apply_sse2.asm',
+                     'vp8/encoder/x86/vp8_enc_stubs_mmx.c',
+                     'vp8/encoder/x86/vp8_enc_stubs_sse2.c',
+                     'vp9/encoder/x86/vp9_dct32x32_sse2.c',
+                     'vp9/encoder/x86/vp9_dct_sse2.c',
+                     'vp9/encoder/x86/vp9_error_sse2.asm',
+                     'vp9/encoder/x86/vp9_sad4d_sse2.asm',
+                     'vp9/encoder/x86/vp9_sad_mmx.asm',
+                     'vp9/encoder/x86/vp9_sad_sse2.asm',
+                     'vp9/encoder/x86/vp9_sad_sse3.asm',
+                     'vp9/encoder/x86/vp9_sad_sse4.asm',
+                     'vp9/encoder/x86/vp9_sad_ssse3.asm',
+                     'vp9/encoder/x86/vp9_subpel_variance.asm',
+                     'vp9/encoder/x86/vp9_subpel_variance_impl_sse2.asm',
+                     'vp9/encoder/x86/vp9_subtract_sse2.asm',
+                     'vp9/encoder/x86/vp9_temporal_filter_apply_sse2.asm',
+                     'vp9/encoder/x86/vp9_variance_impl_mmx.asm',
+                     'vp9/encoder/x86/vp9_variance_impl_sse2.asm',
+                     'vp9/encoder/x86/vp9_variance_mmx.c',
+                     'vp9/encoder/x86/vp9_variance_sse2.c']
+}
new file mode 100644
--- /dev/null
+++ b/media/libvpx/third_party/x86inc/x86inc.asm
@@ -0,0 +1,1199 @@
+;*****************************************************************************
+;* x86inc.asm: x264asm abstraction layer
+;*****************************************************************************
+;* Copyright (C) 2005-2012 x264 project
+;*
+;* Authors: Loren Merritt <lorenm@u.washington.edu>
+;*          Anton Mitrofanov <BugMaster@narod.ru>
+;*          Jason Garrett-Glaser <darkshikari@gmail.com>
+;*          Henrik Gramner <hengar-6@student.ltu.se>
+;*
+;* Permission to use, copy, modify, and/or distribute this software for any
+;* purpose with or without fee is hereby granted, provided that the above
+;* copyright notice and this permission notice appear in all copies.
+;*
+;* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+;* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+;* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+;* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+;* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+;* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+;* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+;*****************************************************************************
+
+; This is a header file for the x264ASM assembly language, which uses
+; NASM/YASM syntax combined with a large number of macros to provide easy
+; abstraction between different calling conventions (x86_32, win64, linux64).
+; It also has various other useful features to simplify writing the kind of
+; DSP functions that are most often used in x264.
+
+; Unlike the rest of x264, this file is available under an ISC license, as it
+; has significant usefulness outside of x264 and we want it to be available
+; to the largest audience possible.  Of course, if you modify it for your own
+; purposes to add a new feature, we strongly encourage contributing a patch
+; as this feature might be useful for others as well.  Send patches or ideas
+; to x264-devel@videolan.org .
+
+%include "vpx_config.asm"
+
+%define program_name vp9
+
+
+%define UNIX64 0
+%define WIN64  0
+%if ARCH_X86_64
+    %ifidn __OUTPUT_FORMAT__,win32
+        %define WIN64  1
+    %elifidn __OUTPUT_FORMAT__,win64
+        %define WIN64  1
+    %elifidn __OUTPUT_FORMAT__,x64
+        %define WIN64  1
+    %else
+        %define UNIX64 1
+    %endif
+%endif
+
+%ifidn   __OUTPUT_FORMAT__,elf32
+    %define mangle(x) x
+%elifidn __OUTPUT_FORMAT__,elf64
+    %define mangle(x) x
+%elifidn __OUTPUT_FORMAT__,elf
+    %define mangle(x) x
+%elifidn __OUTPUT_FORMAT__,x64
+    %define mangle(x) x
+%elifidn __OUTPUT_FORMAT__,win64
+    %define mangle(x) x
+%else
+    %define mangle(x) _ %+ x
+%endif
+
+; FIXME: All of the 64bit asm functions that take a stride as an argument
+; via register, assume that the high dword of that register is filled with 0.
+; This is true in practice (since we never do any 64bit arithmetic on strides,
+; and x264's strides are all positive), but is not guaranteed by the ABI.
+
+; Name of the .rodata section.
+; Kludge: Something on OS X fails to align .rodata even given an align attribute,
+; so use a different read-only section.
+%macro SECTION_RODATA 0-1 16
+    %ifidn __OUTPUT_FORMAT__,macho64
+        SECTION .text align=%1
+    %elifidn __OUTPUT_FORMAT__,macho
+        SECTION .text align=%1
+        fakegot:
+    %elifidn __OUTPUT_FORMAT__,aout
+        section .text
+    %else
+        SECTION .rodata align=%1
+    %endif
+%endmacro
+
+; aout does not support align=
+%macro SECTION_TEXT 0-1 16
+    %ifidn __OUTPUT_FORMAT__,aout
+        SECTION .text
+    %else
+        SECTION .text align=%1
+    %endif
+%endmacro
+
+; PIC macros are copied from vpx_ports/x86_abi_support.asm. The "define PIC"
+; from original code is added in for 64bit.
+%ifidn __OUTPUT_FORMAT__,elf32
+%define ABI_IS_32BIT 1
+%elifidn __OUTPUT_FORMAT__,macho32
+%define ABI_IS_32BIT 1
+%elifidn __OUTPUT_FORMAT__,win32
+%define ABI_IS_32BIT 1
+%elifidn __OUTPUT_FORMAT__,aout
+%define ABI_IS_32BIT 1
+%else
+%define ABI_IS_32BIT 0
+%endif
+
+%if ABI_IS_32BIT
+  %if CONFIG_PIC=1
+  %ifidn __OUTPUT_FORMAT__,elf32
+    %define GET_GOT_SAVE_ARG 1
+    %define WRT_PLT wrt ..plt
+    %macro GET_GOT 1
+      extern _GLOBAL_OFFSET_TABLE_
+      push %1
+      call %%get_got
+      %%sub_offset:
+      jmp %%exitGG
+      %%get_got:
+      mov %1, [esp]
+      add %1, _GLOBAL_OFFSET_TABLE_ + $$ - %%sub_offset wrt ..gotpc
+      ret
+      %%exitGG:
+      %undef GLOBAL
+      %define GLOBAL(x) x + %1 wrt ..gotoff
+      %undef RESTORE_GOT
+      %define RESTORE_GOT pop %1
+    %endmacro
+  %elifidn __OUTPUT_FORMAT__,macho32
+    %define GET_GOT_SAVE_ARG 1
+    %macro GET_GOT 1
+      push %1
+      call %%get_got
+      %%get_got:
+      pop  %1
+      %undef GLOBAL
+      %define GLOBAL(x) x + %1 - %%get_got
+      %undef RESTORE_GOT
+      %define RESTORE_GOT pop %1
+    %endmacro
+  %endif
+  %endif
+
+  %if ARCH_X86_64 == 0
+    %undef PIC
+  %endif
+
+%else
+  %macro GET_GOT 1
+  %endmacro
+  %define GLOBAL(x) rel x
+  %define WRT_PLT wrt ..plt
+
+  %if WIN64
+    %define PIC
+  %elifidn __OUTPUT_FORMAT__,macho64
+    %define PIC
+  %elif CONFIG_PIC
+    %define PIC
+  %endif
+%endif
+
+%ifnmacro GET_GOT
+    %macro GET_GOT 1
+    %endmacro
+    %define GLOBAL(x) x
+%endif
+%ifndef RESTORE_GOT
+%define RESTORE_GOT
+%endif
+%ifndef WRT_PLT
+%define WRT_PLT
+%endif
+
+%ifdef PIC
+    default rel
+%endif
+; Done with PIC macros
+
+; Always use long nops (reduces 0x90 spam in disassembly on x86_32)
+%ifndef __NASM_VER__
+CPU amdnop
+%else
+%use smartalign
+ALIGNMODE k7
+%endif
+
+; Macros to eliminate most code duplication between x86_32 and x86_64:
+; Currently this works only for leaf functions which load all their arguments
+; into registers at the start, and make no other use of the stack. Luckily that
+; covers most of x264's asm.
+
+; PROLOGUE:
+; %1 = number of arguments. loads them from stack if needed.
+; %2 = number of registers used. pushes callee-saved regs if needed.
+; %3 = number of xmm registers used. pushes callee-saved xmm regs if needed.
+; %4 = list of names to define to registers
+; PROLOGUE can also be invoked by adding the same options to cglobal
+
+; e.g.
+; cglobal foo, 2,3,0, dst, src, tmp
+; declares a function (foo), taking two args (dst and src) and one local variable (tmp)
+
+; TODO Some functions can use some args directly from the stack. If they're the
+; last args then you can just not declare them, but if they're in the middle
+; we need more flexible macro.
+
+; RET:
+; Pops anything that was pushed by PROLOGUE, and returns.
+
+; REP_RET:
+; Same, but if it doesn't pop anything it becomes a 2-byte ret, for athlons
+; which are slow when a normal ret follows a branch.
+
+; registers:
+; rN and rNq are the native-size register holding function argument N
+; rNd, rNw, rNb are dword, word, and byte size
+; rNm is the original location of arg N (a register or on the stack), dword
+; rNmp is native size
+
+%macro DECLARE_REG 5-6
+    %define r%1q %2
+    %define r%1d %3
+    %define r%1w %4
+    %define r%1b %5
+    %if %0 == 5
+        %define r%1m  %3
+        %define r%1mp %2
+    %elif ARCH_X86_64 ; memory
+        %define r%1m [rsp + stack_offset + %6]
+        %define r%1mp qword r %+ %1m
+    %else
+        %define r%1m [esp + stack_offset + %6]
+        %define r%1mp dword r %+ %1m
+    %endif
+    %define r%1  %2
+%endmacro
+
+%macro DECLARE_REG_SIZE 2
+    %define r%1q r%1
+    %define e%1q r%1
+    %define r%1d e%1
+    %define e%1d e%1
+    %define r%1w %1
+    %define e%1w %1
+    %define r%1b %2
+    %define e%1b %2
+%if ARCH_X86_64 == 0
+    %define r%1  e%1
+%endif
+%endmacro
+
+DECLARE_REG_SIZE ax, al
+DECLARE_REG_SIZE bx, bl
+DECLARE_REG_SIZE cx, cl
+DECLARE_REG_SIZE dx, dl
+DECLARE_REG_SIZE si, sil
+DECLARE_REG_SIZE di, dil
+DECLARE_REG_SIZE bp, bpl
+
+; t# defines for when per-arch register allocation is more complex than just function arguments
+
+%macro DECLARE_REG_TMP 1-*
+    %assign %%i 0
+    %rep %0
+        CAT_XDEFINE t, %%i, r%1
+        %assign %%i %%i+1
+        %rotate 1
+    %endrep
+%endmacro
+
+%macro DECLARE_REG_TMP_SIZE 0-*
+    %rep %0
+        %define t%1q t%1 %+ q
+        %define t%1d t%1 %+ d
+        %define t%1w t%1 %+ w
+        %define t%1b t%1 %+ b
+        %rotate 1
+    %endrep
+%endmacro
+
+DECLARE_REG_TMP_SIZE 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14
+
+%if ARCH_X86_64
+    %define gprsize 8
+%else
+    %define gprsize 4
+%endif
+
+%macro PUSH 1
+    push %1
+    %assign stack_offset stack_offset+gprsize
+%endmacro
+
+%macro POP 1
+    pop %1
+    %assign stack_offset stack_offset-gprsize
+%endmacro
+
+%macro PUSH_IF_USED 1-*
+    %rep %0
+        %if %1 < regs_used
+            PUSH r%1
+        %endif
+        %rotate 1
+    %endrep
+%endmacro
+
+%macro POP_IF_USED 1-*
+    %rep %0
+        %if %1 < regs_used
+            pop r%1
+        %endif
+        %rotate 1
+    %endrep
+%endmacro
+
+%macro LOAD_IF_USED 1-*
+    %rep %0
+        %if %1 < num_args
+            mov r%1, r %+ %1 %+ mp
+        %endif
+        %rotate 1
+    %endrep
+%endmacro
+
+%macro SUB 2
+    sub %1, %2
+    %ifidn %1, rsp
+        %assign stack_offset stack_offset+(%2)
+    %endif
+%endmacro
+
+%macro ADD 2
+    add %1, %2
+    %ifidn %1, rsp
+        %assign stack_offset stack_offset-(%2)
+    %endif
+%endmacro
+
+%macro movifnidn 2
+    %ifnidn %1, %2
+        mov %1, %2
+    %endif
+%endmacro
+
+%macro movsxdifnidn 2
+    %ifnidn %1, %2
+        movsxd %1, %2
+    %endif
+%endmacro
+
+%macro ASSERT 1
+    %if (%1) == 0
+        %error assert failed
+    %endif
+%endmacro
+
+%macro DEFINE_ARGS 0-*
+    %ifdef n_arg_names
+        %assign %%i 0
+        %rep n_arg_names
+            CAT_UNDEF arg_name %+ %%i, q
+            CAT_UNDEF arg_name %+ %%i, d
+            CAT_UNDEF arg_name %+ %%i, w
+            CAT_UNDEF arg_name %+ %%i, b
+            CAT_UNDEF arg_name %+ %%i, m
+            CAT_UNDEF arg_name %+ %%i, mp
+            CAT_UNDEF arg_name, %%i
+            %assign %%i %%i+1
+        %endrep
+    %endif
+
+    %xdefine %%stack_offset stack_offset
+    %undef stack_offset ; so that the current value of stack_offset doesn't get baked in by xdefine
+    %assign %%i 0
+    %rep %0
+        %xdefine %1q r %+ %%i %+ q
+        %xdefine %1d r %+ %%i %+ d
+        %xdefine %1w r %+ %%i %+ w
+        %xdefine %1b r %+ %%i %+ b
+        %xdefine %1m r %+ %%i %+ m
+        %xdefine %1mp r %+ %%i %+ mp
+        CAT_XDEFINE arg_name, %%i, %1
+        %assign %%i %%i+1
+        %rotate 1
+    %endrep
+    %xdefine stack_offset %%stack_offset
+    %assign n_arg_names %0
+%endmacro
+
+%if WIN64 ; Windows x64 ;=================================================
+
+DECLARE_REG 0,  rcx, ecx,  cx,   cl
+DECLARE_REG 1,  rdx, edx,  dx,   dl
+DECLARE_REG 2,  R8,  R8D,  R8W,  R8B
+DECLARE_REG 3,  R9,  R9D,  R9W,  R9B
+DECLARE_REG 4,  R10, R10D, R10W, R10B, 40
+DECLARE_REG 5,  R11, R11D, R11W, R11B, 48
+DECLARE_REG 6,  rax, eax,  ax,   al,   56
+DECLARE_REG 7,  rdi, edi,  di,   dil,  64
+DECLARE_REG 8,  rsi, esi,  si,   sil,  72
+DECLARE_REG 9,  rbx, ebx,  bx,   bl,   80
+DECLARE_REG 10, rbp, ebp,  bp,   bpl,  88
+DECLARE_REG 11, R12, R12D, R12W, R12B, 96
+DECLARE_REG 12, R13, R13D, R13W, R13B, 104
+DECLARE_REG 13, R14, R14D, R14W, R14B, 112
+DECLARE_REG 14, R15, R15D, R15W, R15B, 120
+
+%macro PROLOGUE 2-4+ 0 ; #args, #regs, #xmm_regs, arg_names...
+    %assign num_args %1
+    %assign regs_used %2
+    ASSERT regs_used >= num_args
+    ASSERT regs_used <= 15
+    PUSH_IF_USED 7, 8, 9, 10, 11, 12, 13, 14
+    %if mmsize == 8
+        %assign xmm_regs_used 0
+    %else
+        WIN64_SPILL_XMM %3
+    %endif
+    LOAD_IF_USED 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
+    DEFINE_ARGS %4
+%endmacro
+
+%macro WIN64_SPILL_XMM 1
+    %assign xmm_regs_used %1
+    ASSERT xmm_regs_used <= 16
+    %if xmm_regs_used > 6
+        SUB rsp, (xmm_regs_used-6)*16+16
+        %assign %%i xmm_regs_used
+        %rep (xmm_regs_used-6)
+            %assign %%i %%i-1
+            movdqa [rsp + (%%i-6)*16+(~stack_offset&8)], xmm %+ %%i
+        %endrep
+    %endif
+%endmacro
+
+%macro WIN64_RESTORE_XMM_INTERNAL 1
+    %if xmm_regs_used > 6
+        %assign %%i xmm_regs_used
+        %rep (xmm_regs_used-6)
+            %assign %%i %%i-1
+            movdqa xmm %+ %%i, [%1 + (%%i-6)*16+(~stack_offset&8)]
+        %endrep
+        add %1, (xmm_regs_used-6)*16+16
+    %endif
+%endmacro
+
+%macro WIN64_RESTORE_XMM 1
+    WIN64_RESTORE_XMM_INTERNAL %1
+    %assign stack_offset stack_offset-(xmm_regs_used-6)*16+16
+    %assign xmm_regs_used 0
+%endmacro
+
+%macro RET 0
+    WIN64_RESTORE_XMM_INTERNAL rsp
+    POP_IF_USED 14, 13, 12, 11, 10, 9, 8, 7
+    ret
+%endmacro
+
+%macro REP_RET 0
+    %if regs_used > 7 || xmm_regs_used > 6
+        RET
+    %else
+        rep ret
+    %endif
+%endmacro
+
+%elif ARCH_X86_64 ; *nix x64 ;=============================================
+
+DECLARE_REG 0,  rdi, edi,  di,   dil
+DECLARE_REG 1,  rsi, esi,  si,   sil
+DECLARE_REG 2,  rdx, edx,  dx,   dl
+DECLARE_REG 3,  rcx, ecx,  cx,   cl
+DECLARE_REG 4,  R8,  R8D,  R8W,  R8B
+DECLARE_REG 5,  R9,  R9D,  R9W,  R9B
+DECLARE_REG 6,  rax, eax,  ax,   al,   8
+DECLARE_REG 7,  R10, R10D, R10W, R10B, 16
+DECLARE_REG 8,  R11, R11D, R11W, R11B, 24
+DECLARE_REG 9,  rbx, ebx,  bx,   bl,   32
+DECLARE_REG 10, rbp, ebp,  bp,   bpl,  40
+DECLARE_REG 11, R12, R12D, R12W, R12B, 48
+DECLARE_REG 12, R13, R13D, R13W, R13B, 56
+DECLARE_REG 13, R14, R14D, R14W, R14B, 64
+DECLARE_REG 14, R15, R15D, R15W, R15B, 72
+
+%macro PROLOGUE 2-4+ ; #args, #regs, #xmm_regs, arg_names...
+    %assign num_args %1
+    %assign regs_used %2
+    ASSERT regs_used >= num_args
+    ASSERT regs_used <= 15
+    PUSH_IF_USED 9, 10, 11, 12, 13, 14
+    LOAD_IF_USED 6, 7, 8, 9, 10, 11, 12, 13, 14
+    DEFINE_ARGS %4
+%endmacro
+
+%macro RET 0
+    POP_IF_USED 14, 13, 12, 11, 10, 9
+    ret
+%endmacro
+
+%macro REP_RET 0
+    %if regs_used > 9
+        RET
+    %else
+        rep ret
+    %endif
+%endmacro
+
+%else ; X86_32 ;==============================================================
+
+DECLARE_REG 0, eax, eax, ax, al,   4
+DECLARE_REG 1, ecx, ecx, cx, cl,   8
+DECLARE_REG 2, edx, edx, dx, dl,   12
+DECLARE_REG 3, ebx, ebx, bx, bl,   16
+DECLARE_REG 4, esi, esi, si, null, 20
+DECLARE_REG 5, edi, edi, di, null, 24
+DECLARE_REG 6, ebp, ebp, bp, null, 28
+%define rsp esp
+
+%macro DECLARE_ARG 1-*
+    %rep %0
+        %define r%1m [esp + stack_offset + 4*%1 + 4]
+        %define r%1mp dword r%1m
+        %rotate 1
+    %endrep
+%endmacro
+
+DECLARE_ARG 7, 8, 9, 10, 11, 12, 13, 14
+
+%macro PROLOGUE 2-4+ ; #args, #regs, #xmm_regs, arg_names...
+    %assign num_args %1
+    %assign regs_used %2
+    %if regs_used > 7
+        %assign regs_used 7
+    %endif
+    ASSERT regs_used >= num_args
+    PUSH_IF_USED 3, 4, 5, 6
+    LOAD_IF_USED 0, 1, 2, 3, 4, 5, 6
+    DEFINE_ARGS %4
+%endmacro
+
+%macro RET 0
+    POP_IF_USED 6, 5, 4, 3
+    ret
+%endmacro
+
+%macro REP_RET 0
+    %if regs_used > 3
+        RET
+    %else
+        rep ret
+    %endif
+%endmacro
+
+%endif ;======================================================================
+
+%if WIN64 == 0
+%macro WIN64_SPILL_XMM 1
+%endmacro
+%macro WIN64_RESTORE_XMM 1
+%endmacro
+%endif
+
+;=============================================================================
+; arch-independent part
+;=============================================================================
+
+%assign function_align 16
+
+; Begin a function.
+; Applies any symbol mangling needed for C linkage, and sets up a define such that
+; subsequent uses of the function name automatically refer to the mangled version.
+; Appends cpuflags to the function name if cpuflags has been specified.
+%macro cglobal 1-2+ ; name, [PROLOGUE args]
+%if %0 == 1
+    cglobal_internal %1 %+ SUFFIX
+%else
+    cglobal_internal %1 %+ SUFFIX, %2
+%endif
+%endmacro
+%macro cglobal_internal 1-2+
+    %ifndef cglobaled_%1
+        %xdefine %1 mangle(program_name %+ _ %+ %1)
+        %xdefine %1.skip_prologue %1 %+ .skip_prologue
+        CAT_XDEFINE cglobaled_, %1, 1
+    %endif
+    %xdefine current_function %1
+    %ifidn __OUTPUT_FORMAT__,elf
+        global %1:function hidden
+    %elifidn __OUTPUT_FORMAT__,elf32
+        global %1:function hidden
+    %elifidn __OUTPUT_FORMAT__,elf64
+        global %1:function hidden
+    %elifidn __OUTPUT_FORMAT__,macho32
+        global %1:private_extern
+    %elifidn __OUTPUT_FORMAT__,macho64
+        global %1:private_extern
+    %else
+        global %1
+    %endif
+    align function_align
+    %1:
+    RESET_MM_PERMUTATION ; not really needed, but makes disassembly somewhat nicer
+    %assign stack_offset 0
+    %if %0 > 1
+        PROLOGUE %2
+    %endif
+%endmacro
+
+%macro cextern 1
+    %xdefine %1 mangle(program_name %+ _ %+ %1)
+    CAT_XDEFINE cglobaled_, %1, 1
+    extern %1
+%endmacro
+
+; like cextern, but without the prefix
+%macro cextern_naked 1
+    %xdefine %1 mangle(%1)
+    CAT_XDEFINE cglobaled_, %1, 1
+    extern %1
+%endmacro
+
+%macro const 2+
+    %xdefine %1 mangle(program_name %+ _ %+ %1)
+    global %1
+    %1: %2
+%endmacro
+
+; This is needed for ELF, otherwise the GNU linker assumes the stack is
+; executable by default.
+%ifidn __OUTPUT_FORMAT__,elf
+SECTION .note.GNU-stack noalloc noexec nowrite progbits
+%elifidn __OUTPUT_FORMAT__,elf32
+SECTION .note.GNU-stack noalloc noexec nowrite progbits
+%elifidn __OUTPUT_FORMAT__,elf64
+SECTION .note.GNU-stack noalloc noexec nowrite progbits
+%endif
+
+; cpuflags
+
+%assign cpuflags_mmx      (1<<0)
+%assign cpuflags_mmx2     (1<<1) | cpuflags_mmx
+%assign cpuflags_3dnow    (1<<2) | cpuflags_mmx
+%assign cpuflags_3dnow2   (1<<3) | cpuflags_3dnow
+%assign cpuflags_sse      (1<<4) | cpuflags_mmx2
+%assign cpuflags_sse2     (1<<5) | cpuflags_sse
+%assign cpuflags_sse2slow (1<<6) | cpuflags_sse2
+%assign cpuflags_sse3     (1<<7) | cpuflags_sse2
+%assign cpuflags_ssse3    (1<<8) | cpuflags_sse3
+%assign cpuflags_sse4     (1<<9) | cpuflags_ssse3
+%assign cpuflags_sse42    (1<<10)| cpuflags_sse4
+%assign cpuflags_avx      (1<<11)| cpuflags_sse42
+%assign cpuflags_xop      (1<<12)| cpuflags_avx
+%assign cpuflags_fma4     (1<<13)| cpuflags_avx
+
+%assign cpuflags_cache32  (1<<16)
+%assign cpuflags_cache64  (1<<17)
+%assign cpuflags_slowctz  (1<<18)
+%assign cpuflags_lzcnt    (1<<19)
+%assign cpuflags_misalign (1<<20)
+%assign cpuflags_aligned  (1<<21) ; not a cpu feature, but a function variant
+%assign cpuflags_atom     (1<<22)
+
+%define    cpuflag(x) ((cpuflags & (cpuflags_ %+ x)) == (cpuflags_ %+ x))
+%define notcpuflag(x) ((cpuflags & (cpuflags_ %+ x)) != (cpuflags_ %+ x))
+
+; Takes up to 2 cpuflags from the above list.
+; All subsequent functions (up to the next INIT_CPUFLAGS) is built for the specified cpu.
+; You shouldn't need to invoke this macro directly, it's a subroutine for INIT_MMX &co.
+%macro INIT_CPUFLAGS 0-2
+    %if %0 >= 1
+        %xdefine cpuname %1
+        %assign cpuflags cpuflags_%1
+        %if %0 >= 2
+            %xdefine cpuname %1_%2
+            %assign cpuflags cpuflags | cpuflags_%2
+        %endif
+        %xdefine SUFFIX _ %+ cpuname
+        %if cpuflag(avx)
+            %assign avx_enabled 1
+        %endif
+        %if mmsize == 16 && notcpuflag(sse2)
+            %define mova movaps
+            %define movu movups
+            %define movnta movntps
+        %endif
+        %if cpuflag(aligned)
+            %define movu mova
+        %elifidn %1, sse3
+            %define movu lddqu
+        %endif
+    %else
+        %xdefine SUFFIX
+        %undef cpuname
+        %undef cpuflags
+    %endif
+%endmacro
+
+; merge mmx and sse*
+
+%macro CAT_XDEFINE 3
+    %xdefine %1%2 %3
+%endmacro
+
+%macro CAT_UNDEF 2
+    %undef %1%2
+%endmacro
+
+%macro INIT_MMX 0-1+
+    %assign avx_enabled 0
+    %define RESET_MM_PERMUTATION INIT_MMX %1
+    %define mmsize 8
+    %define num_mmregs 8
+    %define mova movq
+    %define movu movq
+    %define movh movd
+    %define movnta movntq
+    %assign %%i 0
+    %rep 8
+    CAT_XDEFINE m, %%i, mm %+ %%i
+    CAT_XDEFINE nmm, %%i, %%i
+    %assign %%i %%i+1
+    %endrep
+    %rep 8
+    CAT_UNDEF m, %%i
+    CAT_UNDEF nmm, %%i
+    %assign %%i %%i+1
+    %endrep
+    INIT_CPUFLAGS %1
+%endmacro
+
+%macro INIT_XMM 0-1+
+    %assign avx_enabled 0
+    %define RESET_MM_PERMUTATION INIT_XMM %1
+    %define mmsize 16
+    %define num_mmregs 8
+    %if ARCH_X86_64
+    %define num_mmregs 16
+    %endif
+    %define mova movdqa
+    %define movu movdqu
+    %define movh movq
+    %define movnta movntdq
+    %assign %%i 0
+    %rep num_mmregs
+    CAT_XDEFINE m, %%i, xmm %+ %%i
+    CAT_XDEFINE nxmm, %%i, %%i
+    %assign %%i %%i+1
+    %endrep
+    INIT_CPUFLAGS %1
+%endmacro
+
+; FIXME: INIT_AVX can be replaced by INIT_XMM avx
+%macro INIT_AVX 0
+    INIT_XMM
+    %assign avx_enabled 1
+    %define PALIGNR PALIGNR_SSSE3
+    %define RESET_MM_PERMUTATION INIT_AVX
+%endmacro
+
+%macro INIT_YMM 0-1+
+    %assign avx_enabled 1
+    %define RESET_MM_PERMUTATION INIT_YMM %1
+    %define mmsize 32
+    %define num_mmregs 8
+    %if ARCH_X86_64
+    %define num_mmregs 16
+    %endif
+    %define mova vmovaps
+    %define movu vmovups
+    %undef movh
+    %define movnta vmovntps
+    %assign %%i 0
+    %rep num_mmregs
+    CAT_XDEFINE m, %%i, ymm %+ %%i
+    CAT_XDEFINE nymm, %%i, %%i
+    %assign %%i %%i+1
+    %endrep
+    INIT_CPUFLAGS %1
+%endmacro
+
+INIT_XMM
+
+; I often want to use macros that permute their arguments. e.g. there's no
+; efficient way to implement butterfly or transpose or dct without swapping some
+; arguments.
+;
+; I would like to not have to manually keep track of the permutations:
+; If I insert a permutation in the middle of a function, it should automatically
+; change everything that follows. For more complex macros I may also have multiple
+; implementations, e.g. the SSE2 and SSSE3 versions may have different permutations.
+;
+; Hence these macros. Insert a PERMUTE or some SWAPs at the end of a macro that
+; permutes its arguments. It's equivalent to exchanging the contents of the
+; registers, except that this way you exchange the register names instead, so it
+; doesn't cost any cycles.
+
+%macro PERMUTE 2-* ; takes a list of pairs to swap
+%rep %0/2
+    %xdefine tmp%2 m%2
+    %xdefine ntmp%2 nm%2
+    %rotate 2
+%endrep
+%rep %0/2
+    %xdefine m%1 tmp%2
+    %xdefine nm%1 ntmp%2
+    %undef tmp%2
+    %undef ntmp%2
+    %rotate 2
+%endrep
+%endmacro
+
+%macro SWAP 2-* ; swaps a single chain (sometimes more concise than pairs)
+%rep %0-1
+%ifdef m%1
+    %xdefine tmp m%1
+    %xdefine m%1 m%2
+    %xdefine m%2 tmp
+    CAT_XDEFINE n, m%1, %1
+    CAT_XDEFINE n, m%2, %2
+%else
+    ; If we were called as "SWAP m0,m1" rather than "SWAP 0,1" infer the original numbers here.
+    ; Be careful using this mode in nested macros though, as in some cases there may be
+    ; other copies of m# that have already been dereferenced and don't get updated correctly.
+    %xdefine %%n1 n %+ %1
+    %xdefine %%n2 n %+ %2
+    %xdefine tmp m %+ %%n1
+    CAT_XDEFINE m, %%n1, m %+ %%n2
+    CAT_XDEFINE m, %%n2, tmp
+    CAT_XDEFINE n, m %+ %%n1, %%n1
+    CAT_XDEFINE n, m %+ %%n2, %%n2
+%endif
+    %undef tmp
+    %rotate 1
+%endrep
+%endmacro
+
+; If SAVE_MM_PERMUTATION is placed at the end of a function, then any later
+; calls to that function will automatically load the permutation, so values can
+; be returned in mmregs.
+%macro SAVE_MM_PERMUTATION 0-1
+    %if %0
+        %xdefine %%f %1_m
+    %else
+        %xdefine %%f current_function %+ _m
+    %endif
+    %assign %%i 0
+    %rep num_mmregs
+        CAT_XDEFINE %%f, %%i, m %+ %%i
+    %assign %%i %%i+1
+    %endrep
+%endmacro
+
+%macro LOAD_MM_PERMUTATION 1 ; name to load from
+    %ifdef %1_m0
+        %assign %%i 0
+        %rep num_mmregs
+            CAT_XDEFINE m, %%i, %1_m %+ %%i
+            CAT_XDEFINE n, m %+ %%i, %%i
+        %assign %%i %%i+1
+        %endrep
+    %endif
+%endmacro
+
+; Append cpuflags to the callee's name iff the appended name is known and the plain name isn't
+%macro call 1
+    call_internal %1, %1 %+ SUFFIX
+%endmacro
+%macro call_internal 2
+    %xdefine %%i %1
+    %ifndef cglobaled_%1
+        %ifdef cglobaled_%2
+            %xdefine %%i %2
+        %endif
+    %endif
+    call %%i
+    LOAD_MM_PERMUTATION %%i
+%endmacro
+
+; Substitutions that reduce instruction size but are functionally equivalent
+%macro add 2
+    %ifnum %2
+        %if %2==128
+            sub %1, -128
+        %else
+            add %1, %2
+        %endif
+    %else
+        add %1, %2
+    %endif
+%endmacro
+
+%macro sub 2
+    %ifnum %2
+        %if %2==128
+            add %1, -128
+        %else
+            sub %1, %2
+        %endif
+    %else
+        sub %1, %2
+    %endif
+%endmacro
+
+;=============================================================================
+; AVX abstraction layer
+;=============================================================================
+
+%assign i 0
+%rep 16
+    %if i < 8
+        CAT_XDEFINE sizeofmm, i, 8
+    %endif
+    CAT_XDEFINE sizeofxmm, i, 16
+    CAT_XDEFINE sizeofymm, i, 32
+%assign i i+1
+%endrep
+%undef i
+
+;%1 == instruction
+;%2 == 1 if float, 0 if int
+;%3 == 1 if 4-operand (xmm, xmm, xmm, imm), 0 if 2- or 3-operand (xmm, xmm, xmm)
+;%4 == number of operands given
+;%5+: operands
+%macro RUN_AVX_INSTR 6-7+
+    %ifid %5
+        %define %%size sizeof%5
+    %else
+        %define %%size mmsize
+    %endif
+    %if %%size==32
+        %if %0 >= 7
+            v%1 %5, %6, %7
+        %else
+            v%1 %5, %6
+        %endif
+    %else
+        %if %%size==8
+            %define %%regmov movq
+        %elif %2
+            %define %%regmov movaps
+        %else
+            %define %%regmov movdqa
+        %endif
+
+        %if %4>=3+%3
+            %ifnidn %5, %6
+                %if avx_enabled && sizeof%5==16
+                    v%1 %5, %6, %7
+                %else
+                    %%regmov %5, %6
+                    %1 %5, %7
+                %endif
+            %else
+                %1 %5, %7
+            %endif
+        %elif %3
+            %1 %5, %6, %7
+        %else
+            %1 %5, %6
+        %endif
+    %endif
+%endmacro
+
+; 3arg AVX ops with a memory arg can only have it in src2,
+; whereas SSE emulation of 3arg prefers to have it in src1 (i.e. the mov).
+; So, if the op is symmetric and the wrong one is memory, swap them.
+%macro RUN_AVX_INSTR1 8
+    %assign %%swap 0
+    %if avx_enabled
+        %ifnid %6
+            %assign %%swap 1
+        %endif
+    %elifnidn %5, %6
+        %ifnid %7
+            %assign %%swap 1
+        %endif
+    %endif
+    %if %%swap && %3 == 0 && %8 == 1
+        RUN_AVX_INSTR %1, %2, %3, %4, %5, %7, %6
+    %else
+        RUN_AVX_INSTR %1, %2, %3, %4, %5, %6, %7
+    %endif
+%endmacro
+
+;%1 == instruction
+;%2 == 1 if float, 0 if int
+;%3 == 1 if 4-operand (xmm, xmm, xmm, imm), 0 if 3-operand (xmm, xmm, xmm)
+;%4 == 1 if symmetric (i.e. doesn't matter which src arg is which), 0 if not
+%macro AVX_INSTR 4
+    %macro %1 2-9 fnord, fnord, fnord, %1, %2, %3, %4
+        %ifidn %3, fnord
+            RUN_AVX_INSTR %6, %7, %8, 2, %1, %2
+        %elifidn %4, fnord
+            RUN_AVX_INSTR1 %6, %7, %8, 3, %1, %2, %3, %9
+        %elifidn %5, fnord
+            RUN_AVX_INSTR %6, %7, %8, 4, %1, %2, %3, %4
+        %else
+            RUN_AVX_INSTR %6, %7, %8, 5, %1, %2, %3, %4, %5
+        %endif
+    %endmacro
+%endmacro
+
+AVX_INSTR addpd, 1, 0, 1
+AVX_INSTR addps, 1, 0, 1
+AVX_INSTR addsd, 1, 0, 1
+AVX_INSTR addss, 1, 0, 1
+AVX_INSTR addsubpd, 1, 0, 0
+AVX_INSTR addsubps, 1, 0, 0
+AVX_INSTR andpd, 1, 0, 1
+AVX_INSTR andps, 1, 0, 1
+AVX_INSTR andnpd, 1, 0, 0
+AVX_INSTR andnps, 1, 0, 0
+AVX_INSTR blendpd, 1, 0, 0
+AVX_INSTR blendps, 1, 0, 0
+AVX_INSTR blendvpd, 1, 0, 0
+AVX_INSTR blendvps, 1, 0, 0
+AVX_INSTR cmppd, 1, 0, 0
+AVX_INSTR cmpps, 1, 0, 0
+AVX_INSTR cmpsd, 1, 0, 0
+AVX_INSTR cmpss, 1, 0, 0
+AVX_INSTR cvtdq2ps, 1, 0, 0
+AVX_INSTR cvtps2dq, 1, 0, 0
+AVX_INSTR divpd, 1, 0, 0
+AVX_INSTR divps, 1, 0, 0
+AVX_INSTR divsd, 1, 0, 0
+AVX_INSTR divss, 1, 0, 0
+AVX_INSTR dppd, 1, 1, 0
+AVX_INSTR dpps, 1, 1, 0
+AVX_INSTR haddpd, 1, 0, 0
+AVX_INSTR haddps, 1, 0, 0
+AVX_INSTR hsubpd, 1, 0, 0
+AVX_INSTR hsubps, 1, 0, 0
+AVX_INSTR maxpd, 1, 0, 1
+AVX_INSTR maxps, 1, 0, 1
+AVX_INSTR maxsd, 1, 0, 1
+AVX_INSTR maxss, 1, 0, 1
+AVX_INSTR minpd, 1, 0, 1
+AVX_INSTR minps, 1, 0, 1
+AVX_INSTR minsd, 1, 0, 1
+AVX_INSTR minss, 1, 0, 1
+AVX_INSTR movhlps, 1, 0, 0
+AVX_INSTR movlhps, 1, 0, 0
+AVX_INSTR movsd, 1, 0, 0
+AVX_INSTR movss, 1, 0, 0
+AVX_INSTR mpsadbw, 0, 1, 0
+AVX_INSTR mulpd, 1, 0, 1
+AVX_INSTR mulps, 1, 0, 1
+AVX_INSTR mulsd, 1, 0, 1
+AVX_INSTR mulss, 1, 0, 1
+AVX_INSTR orpd, 1, 0, 1
+AVX_INSTR orps, 1, 0, 1
+AVX_INSTR packsswb, 0, 0, 0
+AVX_INSTR packssdw, 0, 0, 0
+AVX_INSTR packuswb, 0, 0, 0
+AVX_INSTR packusdw, 0, 0, 0
+AVX_INSTR paddb, 0, 0, 1
+AVX_INSTR paddw, 0, 0, 1
+AVX_INSTR paddd, 0, 0, 1
+AVX_INSTR paddq, 0, 0, 1
+AVX_INSTR paddsb, 0, 0, 1
+AVX_INSTR paddsw, 0, 0, 1
+AVX_INSTR paddusb, 0, 0, 1
+AVX_INSTR paddusw, 0, 0, 1
+AVX_INSTR palignr, 0, 1, 0
+AVX_INSTR pand, 0, 0, 1
+AVX_INSTR pandn, 0, 0, 0
+AVX_INSTR pavgb, 0, 0, 1
+AVX_INSTR pavgw, 0, 0, 1
+AVX_INSTR pblendvb, 0, 0, 0
+AVX_INSTR pblendw, 0, 1, 0
+AVX_INSTR pcmpestri, 0, 0, 0
+AVX_INSTR pcmpestrm, 0, 0, 0
+AVX_INSTR pcmpistri, 0, 0, 0
+AVX_INSTR pcmpistrm, 0, 0, 0
+AVX_INSTR pcmpeqb, 0, 0, 1
+AVX_INSTR pcmpeqw, 0, 0, 1
+AVX_INSTR pcmpeqd, 0, 0, 1
+AVX_INSTR pcmpeqq, 0, 0, 1
+AVX_INSTR pcmpgtb, 0, 0, 0
+AVX_INSTR pcmpgtw, 0, 0, 0
+AVX_INSTR pcmpgtd, 0, 0, 0
+AVX_INSTR pcmpgtq, 0, 0, 0
+AVX_INSTR phaddw, 0, 0, 0
+AVX_INSTR phaddd, 0, 0, 0
+AVX_INSTR phaddsw, 0, 0, 0
+AVX_INSTR phsubw, 0, 0, 0
+AVX_INSTR phsubd, 0, 0, 0
+AVX_INSTR phsubsw, 0, 0, 0
+AVX_INSTR pmaddwd, 0, 0, 1
+AVX_INSTR pmaddubsw, 0, 0, 0
+AVX_INSTR pmaxsb, 0, 0, 1
+AVX_INSTR pmaxsw, 0, 0, 1
+AVX_INSTR pmaxsd, 0, 0, 1
+AVX_INSTR pmaxub, 0, 0, 1
+AVX_INSTR pmaxuw, 0, 0, 1
+AVX_INSTR pmaxud, 0, 0, 1
+AVX_INSTR pminsb, 0, 0, 1
+AVX_INSTR pminsw, 0, 0, 1
+AVX_INSTR pminsd, 0, 0, 1
+AVX_INSTR pminub, 0, 0, 1
+AVX_INSTR pminuw, 0, 0, 1
+AVX_INSTR pminud, 0, 0, 1
+AVX_INSTR pmulhuw, 0, 0, 1
+AVX_INSTR pmulhrsw, 0, 0, 1
+AVX_INSTR pmulhw, 0, 0, 1
+AVX_INSTR pmullw, 0, 0, 1
+AVX_INSTR pmulld, 0, 0, 1
+AVX_INSTR pmuludq, 0, 0, 1
+AVX_INSTR pmuldq, 0, 0, 1
+AVX_INSTR por, 0, 0, 1
+AVX_INSTR psadbw, 0, 0, 1
+AVX_INSTR pshufb, 0, 0, 0
+AVX_INSTR psignb, 0, 0, 0
+AVX_INSTR psignw, 0, 0, 0
+AVX_INSTR psignd, 0, 0, 0
+AVX_INSTR psllw, 0, 0, 0
+AVX_INSTR pslld, 0, 0, 0
+AVX_INSTR psllq, 0, 0, 0
+AVX_INSTR pslldq, 0, 0, 0
+AVX_INSTR psraw, 0, 0, 0
+AVX_INSTR psrad, 0, 0, 0
+AVX_INSTR psrlw, 0, 0, 0
+AVX_INSTR psrld, 0, 0, 0
+AVX_INSTR psrlq, 0, 0, 0
+AVX_INSTR psrldq, 0, 0, 0
+AVX_INSTR psubb, 0, 0, 0
+AVX_INSTR psubw, 0, 0, 0
+AVX_INSTR psubd, 0, 0, 0
+AVX_INSTR psubq, 0, 0, 0
+AVX_INSTR psubsb, 0, 0, 0
+AVX_INSTR psubsw, 0, 0, 0
+AVX_INSTR psubusb, 0, 0, 0
+AVX_INSTR psubusw, 0, 0, 0
+AVX_INSTR punpckhbw, 0, 0, 0
+AVX_INSTR punpckhwd, 0, 0, 0
+AVX_INSTR punpckhdq, 0, 0, 0
+AVX_INSTR punpckhqdq, 0, 0, 0
+AVX_INSTR punpcklbw, 0, 0, 0
+AVX_INSTR punpcklwd, 0, 0, 0
+AVX_INSTR punpckldq, 0, 0, 0
+AVX_INSTR punpcklqdq, 0, 0, 0
+AVX_INSTR pxor, 0, 0, 1
+AVX_INSTR shufps, 1, 1, 0
+AVX_INSTR subpd, 1, 0, 0
+AVX_INSTR subps, 1, 0, 0
+AVX_INSTR subsd, 1, 0, 0
+AVX_INSTR subss, 1, 0, 0
+AVX_INSTR unpckhpd, 1, 0, 0
+AVX_INSTR unpckhps, 1, 0, 0
+AVX_INSTR unpcklpd, 1, 0, 0
+AVX_INSTR unpcklps, 1, 0, 0
+AVX_INSTR xorpd, 1, 0, 1
+AVX_INSTR xorps, 1, 0, 1
+
+; 3DNow instructions, for sharing code between AVX, SSE and 3DN
+AVX_INSTR pfadd, 1, 0, 1
+AVX_INSTR pfsub, 1, 0, 0
+AVX_INSTR pfmul, 1, 0, 1
+
+; base-4 constants for shuffles
+%assign i 0
+%rep 256
+    %assign j ((i>>6)&3)*1000 + ((i>>4)&3)*100 + ((i>>2)&3)*10 + (i&3)
+    %if j < 10
+        CAT_XDEFINE q000, j, i
+    %elif j < 100
+        CAT_XDEFINE q00, j, i
+    %elif j < 1000
+        CAT_XDEFINE q0, j, i
+    %else
+        CAT_XDEFINE q, j, i
+    %endif
+%assign i i+1
+%endrep
+%undef i
+%undef j
+
+%macro FMA_INSTR 3
+    %macro %1 4-7 %1, %2, %3
+        %if cpuflag(xop)
+            v%5 %1, %2, %3, %4
+        %else
+            %6 %1, %2, %3
+            %7 %1, %4
+        %endif
+    %endmacro
+%endmacro
+
+FMA_INSTR  pmacsdd,  pmulld, paddd
+FMA_INSTR  pmacsww,  pmullw, paddw
+FMA_INSTR pmadcswd, pmaddwd, paddd
new file mode 100755
--- /dev/null
+++ b/media/libvpx/update.py
@@ -0,0 +1,531 @@
+#!/usr/bin/env python
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+import argparse
+import os
+import re
+import shutil
+import sys
+import subprocess
+from pprint import pprint
+from StringIO import StringIO
+
+PLATFORMS= [
+  'x86-win32-vs8',
+  'x86_64-win64-vs8',
+  'x86-linux-gcc',
+  'x86_64-linux-gcc',
+  'generic-gnu',
+  'x86-darwin9-gcc',
+  'x86_64-darwin9-gcc',
+  'armv7-android-gcc',
+]
+
+
+mk_files = [
+    'vp8/vp8_common.mk',
+    'vp8/vp8cx_arm.mk',
+    'vp8/vp8cx.mk',
+    'vp8/vp8dx.mk',
+    'vp9/vp9_common.mk',
+    'vp9/vp9cx.mk',
+    'vp9/vp9dx.mk',
+    'vpx_mem/vpx_mem.mk',
+    'vpx_ports/vpx_ports.mk',
+    'vpx_scale/vpx_scale.mk',
+    'vpx/vpx_codec.mk',
+]
+
+extensions = ['.asm', '.c', '.h']
+
+MODULES = {
+    'ENCODER': [
+        'API_DOC_SRCS-$(CONFIG_VP8_ENCODER)',
+        'API_SRCS-$(BUILD_LIBVPX)',
+        'API_SRCS-$(CONFIG_VP8_ENCODER)',
+        'API_SRCS-$(CONFIG_VP9_ENCODER)',
+        'VP8_CX_EXPORTS',
+        'VP8_CX_SRCS-$(CONFIG_MULTI_RES_ENCODING)',
+        'VP8_CX_SRCS-$(CONFIG_MULTITHREAD)',
+        'VP8_CX_SRCS-$(CONFIG_TEMPORAL_DENOISING)',
+        'VP8_CX_SRCS-no',
+        'VP8_CX_SRCS_REMOVE-no',
+        'VP8_CX_SRCS_REMOVE-yes',
+        'VP8_CX_SRCS-yes',
+        'VP9_CX_EXPORTS',
+        'VP9_CX_SRCS-no',
+        'VP9_CX_SRCS_REMOVE-no',
+        'VP9_CX_SRCS_REMOVE-yes',
+        'VP9_CX_SRCS-yes',
+    ],
+    'X86_ASM_ENCODER': [
+        'VP8_CX_SRCS-$(ARCH_X86)$(ARCH_X86_64)',
+        'VP8_CX_SRCS-$(HAVE_MMX)',
+        'VP8_CX_SRCS-$(HAVE_SSE2)',
+        'VP8_CX_SRCS-$(HAVE_SSE4_1)',
+        'VP8_CX_SRCS-$(HAVE_SSSE3)',
+        'VP8_CX_SRCS_REMOVE-$(HAVE_SSE2)',
+        'VP9_CX_SRCS-$(ARCH_X86)$(ARCH_X86_64)',
+        'VP9_CX_SRCS-$(HAVE_MMX)',
+        'VP9_CX_SRCS-$(HAVE_SSE2)',
+        'VP9_CX_SRCS-$(HAVE_SSE3)',
+        'VP9_CX_SRCS-$(HAVE_SSE4_1)',
+        'VP9_CX_SRCS-$(HAVE_SSSE3)',
+    ],
+    'X86-64_ASM_ENCODER': [
+        'VP8_CX_SRCS-$(ARCH_X86_64)',
+        'VP9_CX_SRCS-$(ARCH_X86_64)',
+    ],
+    'ARM_ASM_ENCODER': [
+        'VP8_CX_SRCS-$(ARCH_ARM)',
+        'VP8_CX_SRCS-$(HAVE_EDSP)',
+        'VP8_CX_SRCS-$(HAVE_MEDIA)',
+        'VP8_CX_SRCS-$(HAVE_NEON)',
+    ],
+    'COMMON': [
+        'API_DOC_SRCS-$(CONFIG_VP8_DECODER)',
+        'API_DOC_SRCS-yes',
+        'API_EXPORTS',
+        'API_SRCS-$(CONFIG_VP8_DECODER)',
+        'API_SRCS-yes',
+        'MEM_SRCS-yes',
+        'PORTS_SRCS-yes',
+        'SCALE_SRCS-$(CONFIG_SPATIAL_RESAMPLING)',
+        'SCALE_SRCS-no',
+        'SCALE_SRCS-yes',
+        'VP8_COMMON_SRCS-yes',
+        'VP8_DX_EXPORTS',
+        'VP8_DX_SRCS-$(CONFIG_MULTITHREAD)',
+        'VP8_DX_SRCS-no',
+        'VP8_DX_SRCS_REMOVE-no',
+        'VP8_DX_SRCS_REMOVE-yes',
+        'VP8_DX_SRCS-yes',
+        'VP9_COMMON_SRCS-yes',
+        'VP9_DX_EXPORTS',
+        'VP9_DX_SRCS-no',
+        'VP9_DX_SRCS_REMOVE-no',
+        'VP9_DX_SRCS_REMOVE-yes',
+        'VP9_DX_SRCS-yes',
+    ],
+    'ERROR_CONCEALMENT': [
+        'VP8_DX_SRCS-$(CONFIG_ERROR_CONCEALMENT)',
+    ],
+    'AVX2': [
+        'VP9_COMMON_SRCS-$(HAVE_AVX2)',
+    ],
+    'X86_ASM': [
+        'PORTS_SRCS-$(BUILD_LIBVPX)',
+        'VP8_COMMON_SRCS-$(ARCH_X86)$(ARCH_X86_64)',
+        'VP8_COMMON_SRCS-$(HAVE_MMX)',
+        'VP8_COMMON_SRCS-$(HAVE_SSE2)',
+        'VP8_COMMON_SRCS-$(HAVE_SSE3)',
+        'VP8_COMMON_SRCS-$(HAVE_SSE4_1)',
+        'VP8_COMMON_SRCS-$(HAVE_SSSE3)',
+        'VP9_COMMON_SRCS-$(ARCH_X86)$(ARCH_X86_64)',
+        'VP9_COMMON_SRCS-$(HAVE_MMX)',
+        'VP9_COMMON_SRCS-$(HAVE_SSE2)',
+        'VP9_COMMON_SRCS-$(HAVE_SSSE3)',
+    ],
+    'X86-64_ASM': [
+    ],
+    'ARM_ASM': [
+        'PORTS_SRCS-$(ARCH_ARM)',
+        'SCALE_SRCS-$(HAVE_NEON)',
+        'VP8_COMMON_SRCS-$(ARCH_ARM)',
+        'VP8_COMMON_SRCS-$(HAVE_MEDIA)',
+        'VP8_COMMON_SRCS-$(HAVE_NEON)',
+        'VP9_COMMON_SRCS-$(HAVE_NEON)',
+    ],
+    'VP8_POSTPROC': [
+        'VP8_COMMON_SRCS-$(CONFIG_POSTPROC)',
+    ],
+    'VP9_POSTPROC': [
+        'VP9_COMMON_SRCS-$(CONFIG_VP9_POSTPROC)',
+    ]
+}
+
+DISABLED_MODULES = [
+    'MEM_SRCS-$(CONFIG_MEM_MANAGER)',
+    'MEM_SRCS-$(CONFIG_MEM_TRACKER)',
+    'VP8_COMMON_SRCS-$(CONFIG_POSTPROC_VISUALIZER)',
+    'VP9_COMMON_SRCS-$(CONFIG_POSTPROC_VISUALIZER)',
+    'VP8_CX_SRCS-$(CONFIG_INTERNAL_STATS)',
+    'VP9_CX_SRCS-$(CONFIG_INTERNAL_STATS)',
+
+    # mips files are also ignored via ignored_folders
+    'SCALE_SRCS-$(HAVE_DSPR2)',
+    'VP8_COMMON_SRCS-$(HAVE_DSPR2)',
+    'VP9_COMMON_SRCS-$(HAVE_DSPR2)',
+    'VP8_CX_SRCS_REMOVE-$(HAVE_EDSP)',
+]
+
+libvpx_files = [
+    'build/make/obj_int_extract.c',
+    'build/make/ads2gas.pl',
+    'build/make/thumb.pm',
+    'LICENSE',
+    'PATENTS',
+]
+
+ignore_files = [
+    'vp8/common/context.c',
+    'vp8/common/textblit.c',
+    'vp8/encoder/ssim.c',
+    'vp8/encoder/x86/ssim_opt.asm',
+    'vp9/common/vp9_textblit.c',
+    'vp9/common/vp9_textblit.h',
+    'vp9/encoder/vp9_ssim.c',
+    'vp9/encoder/x86/vp9_ssim_opt.asm',
+    'vpx_mem/vpx_mem_tracker.c',
+    'vpx_scale/generic/bicubic_scaler.c',
+    'vpx_scale/win32/scaleopt.c',
+    'vpx_scale/win32/scalesystemdependent.c',
+]
+
+ignore_folders = [
+    'examples/',
+    'googletest/',
+    'libmkv/',
+    'libyuv/',
+    'mips/',
+    'nestegg/',
+    'objdir/',
+    'ppc/',
+    'test/',
+    'vpx_mem/memory_manager/',
+]
+files = {
+    'EXPORTS': [
+        'vpx_mem/include/vpx_mem_intrnl.h',
+        'vpx_mem/vpx_mem.h',
+        'vpx_ports/arm.h',
+        'vpx_ports/mem.h',
+        'vpx_ports/vpx_timer.h',
+        'vpx_ports/x86.h',
+        'vpx_scale/vpx_scale.h',
+        'vpx_scale/yv12config.h',
+        'vpx/vp8cx.h',
+        'vpx/vp8dx.h',
+        'vpx/vp8.h',
+        'vpx/vpx_codec.h',
+        'vpx/vpx_decoder.h',
+        'vpx/vpx_encoder.h',
+        'vpx/vpx_image.h',
+        'vpx/vpx_integer.h',
+    ],
+    'X86-64_ASM_ENCODER': [
+        'vp9/encoder/x86/vp9_quantize_ssse3.asm',
+    ],
+    'X86-64_ASM': [
+        'third_party/x86inc/x86inc.asm',
+        'vp8/common/x86/loopfilter_block_sse2.asm',
+    ],
+    'X86_ASM': [
+    ]
+}
+
+manual = [
+    # special case in moz.build
+    'vp8/encoder/boolhuff.c',
+
+    # 64bit only
+    'vp8/common/x86/loopfilter_block_sse2.asm',
+    'vp9/encoder/x86/vp9_quantize_ssse3.asm',
+
+    # offsets are special cased in Makefile.in
+    'vp8/encoder/vp8_asm_enc_offsets.c',
+    'vpx_scale/vpx_scale_asm_offsets.c',
+
+    # ignore while vp9 postproc is not enabled
+    'vp9/common/x86/vp9_postproc_mmx.asm',
+    'vp9/common/x86/vp9_postproc_sse2.asm',
+
+    # ssim_opt is not enabled
+    'vp8/encoder/x86/ssim_opt.asm',
+    'vp9/encoder/x86/vp9_ssim_opt.asm',
+
+    # asm includes
+    'vpx_ports/x86_abi_support.asm',
+]
+
+platform_files = [
+    'vp8_rtcd.h',
+    'vp9_rtcd.h',
+    'vpx_config.asm',
+    'vpx_config.c',
+    'vpx_config.h',
+    'vpx_scale_rtcd.h',
+]
+
+def prepare_upstream(prefix, commit=None):
+    if os.path.exists(prefix):
+        print "Please remove '%s' folder before running %s" % (prefix, sys.argv[0])
+        sys.exit(1)
+
+    upstream_url = 'https://gerrit.chromium.org/gerrit/webm/libvpx'
+    subprocess.call(['git', 'clone', upstream_url, prefix])
+    if commit:
+        os.chdir(prefix)
+        subprocess.call(['git', 'checkout', commit])
+    else:
+        os.chdir(prefix)
+        p = subprocess.Popen(['git', 'rev-parse', 'HEAD'], stdout=subprocess.PIPE)
+        stdout, stderr = p.communicate()
+        commit = stdout.strip()
+
+    for target in PLATFORMS:
+        target_objdir = os.path.join(prefix, 'objdir', target)
+        os.makedirs(target_objdir)
+        os.chdir(target_objdir)
+        configure = ['../../configure', '--target=%s' % target, '--disable-examples', '--disable-install-docs']
+
+        if 'darwin9' in target:
+            configure += ['--enable-pic']
+        if 'linux' in target:
+            configure += ['--enable-pic']
+            # mozilla linux toolchain currently does not support avx2,
+            # remove once gcc is updated
+            configure += ['--disable-avx2']
+        # x86inc.asm is not compatible with pic 32bit builds
+        if target == 'x86-linux-gcc':
+            configure += ['--disable-use-x86inc']
+
+        if target == 'armv7-android-gcc':
+            configure += ['--sdk-path=%s' % ndk_path]
+
+        subprocess.call(configure)
+        make_targets = [f for f in platform_files if not os.path.exists(f)]
+        if make_targets:
+            subprocess.call(['make'] + make_targets)
+        for f in make_targets:
+            if not os.path.exists(f):
+                print "%s missing from %s, check toolchain" % (f, target)
+                sys.exit(1)
+
+    os.chdir(base)
+    return commit
+
+def cleanup_upstream():
+    shutil.rmtree(os.path.join(base, 'upstream'))
+
+def get_module(key):
+    for module in MODULES:
+        if key in MODULES[module]:
+            return module
+
+def get_libvpx_files(prefix):
+    for root, folders, files in os.walk(prefix):
+        for f in files:
+            f = os.path.join(root, f)[len(prefix):]
+            if os.path.splitext(f)[-1] in extensions \
+              and os.sep in f \
+              and f not in ignore_files \
+              and not any(folder in f for folder in ignore_folders):
+                libvpx_files.append(f)
+    return libvpx_files
+
+def get_sources(prefix):
+    source = {}
+    unknown = {}
+    disabled = {}
+
+    for mk in mk_files:
+        with open(os.path.join(prefix, mk)) as f:
+            base = os.path.dirname(mk)
+            for l in f:
+                if '+=' in l:
+                    l = l.split('+=')
+                    key = l[0].strip()
+                    value = l[1].strip().replace('$(ASM)', '.asm')
+                    value = os.path.join(base, value)
+                    if not key.startswith('#') and os.path.splitext(value)[-1] in extensions:
+                        if key not in source:
+                            source[key] = []
+                        source[key].append(value)
+
+    for key in source:
+        for f in source[key]:
+            if key.endswith('EXPORTS') and f.endswith('.h'):
+                files['EXPORTS'].append(f)
+            if os.path.splitext(f)[-1] in ('.c', '.asm') and not f in manual:
+                module = get_module(key)
+                if module:
+                    if not module in files:
+                        files[module] = []
+                    t = files[module]
+                elif key in DISABLED_MODULES:
+                    if not key in disabled:
+                        disabled[key] = []
+                    t = disabled[key]
+                else:
+                    if not key in unknown:
+                        unknown[key] = []
+                    t = unknown[key]
+                t.append(f)
+
+    for key in files:
+        files[key] = list(sorted(set(files[key])))
+
+    return source, files, disabled, unknown
+
+def update_sources_mozbuild(files, sources_mozbuild):
+    f = StringIO()
+    pprint(files, stream=f)
+    sources_mozbuild_new = "files = {\n %s\n}\n" % f.getvalue().strip()[1:-1]
+    if sources_mozbuild != sources_mozbuild_new:
+        print 'updating sources.mozbuild'
+        with open('sources.mozbuild', 'w') as f:
+            f.write(sources_mozbuild_new)
+
+def get_current_files():
+    current_files = []
+    for root, folders, files in os.walk('.'):
+        for f in files:
+            f = os.path.join(root, f)[len('.%s'%os.sep):]
+            if 'upstream%s'%os.sep in f or not os.sep in f:
+                continue
+            if os.path.splitext(f)[-1] in extensions:
+                current_files.append(f)
+    return current_files
+
+def is_new(a, b):
+    return not os.path.exists(a) \
+        or not os.path.exists(b) \
+        or open(a).read() != open(b).read()
+
+def get_sources_mozbuild():
+    with open('sources.mozbuild') as f:
+        sources_mozbuild = f.read()
+    exec(sources_mozbuild)
+    return sources_mozbuild, files
+
+def update_and_remove_files(prefix, libvpx_files, files):
+    current_files = get_current_files()
+
+    def copy(src, dst):
+        print '    ', dst
+        shutil.copy(src, dst)
+
+    # Update files
+    first = True
+    for f in libvpx_files:
+        fdir = os.path.dirname(f)
+        if fdir and not os.path.exists(fdir):
+            os.makedirs(fdir)
+        s = os.path.join(prefix, f)
+        if is_new(f, s):
+            if first:
+                print "Copy files:"
+                first = False
+            copy(s, f)
+
+    # Copy configuration files for each platform
+    for target in PLATFORMS:
+        first = True
+        for f in platform_files:
+            t = os.path.splitext(f)
+            t = '%s_%s%s' % (t[0], target, t[1])
+            f = os.path.join(prefix, 'objdir', target, f)
+            if is_new(f, t):
+                if first:
+                    print "Copy files for %s:" % target
+                    first = False
+                copy(f, t)
+
+    # Copy vpx_version.h from one of the build targets
+    s = os.path.join(prefix, 'objdir/x86-linux-gcc/vpx_version.h')
+    f = 'vpx_version.h'
+    if is_new(s, f):
+        copy(s, f)
+
+    # Remove unknown files from tree
+    removed_files = [f for f in current_files if f not in libvpx_files]
+    if removed_files:
+        print "Remove files:"
+        for f in removed_files:
+            os.unlink(f)
+            print '    ', f
+
+def apply_patches():
+    # Patch to permit vpx users to specify their own <stdint.h> types.
+    os.system("patch -p3 < stdint.patch")
+
+def update_readme(commit):
+    with open('README_MOZILLA') as f:
+        readme = f.read()
+
+    if 'The git commit ID used was' in readme:
+        new_readme = re.sub('The git commit ID used was [a-f0-9]+',
+            'The git commit ID used was %s' % commit, readme)
+    else:
+        new_readme = "%s\n\nThe git commit ID used was %s\n" % (readme, commit)
+
+    if readme != new_readme:
+        with open('README_MOZILLA', 'w') as f:
+            f.write(new_readme)
+
+def print_info(source, files, disabled, unknown, moz_build_files):
+    for key in moz_build_files:
+        if key not in files:
+            print key, 'MISSING'
+        else:
+            gone = set(moz_build_files[key]) - set(files[key])
+            new = set(files[key]) - set(moz_build_files[key])
+            if gone:
+                print key, 'GONE:'
+                print '    '+ '\n    '.join(gone)
+            if new:
+                print key, 'NEW:'
+                print '    '+ '\n    '.join(new)
+
+    if unknown:
+        print "Please update this script, the following modules are unknown"
+        pprint(unknown)
+
+    if DEBUG:
+        print "===== SOURCE"
+        pprint(source)
+        print "===== FILES"
+        pprint(files)
+        print "===== DISABLED"
+        pprint(disabled)
+        print "===== UNKNOWN"
+        pprint(unknown)
+
+
+if __name__ == '__main__':
+    parser = argparse.ArgumentParser(description='''This script only works on Mac OS X since the OS X Toolchain is not available on other platforms.
+In addition you need XCode and the Android NDK installed.
+If commit hash is not provided, current git master is used.''')
+    parser.add_argument('--debug', dest='debug', action="store_true")
+    parser.add_argument('--ndk', dest='ndk', type=str)
+    parser.add_argument('--commit', dest='commit', type=str, default=None)
+
+    args = parser.parse_args()
+
+    if sys.platform != 'darwin' or not args.ndk:
+        parser.print_help()
+        sys.exit(1)
+
+    ndk_path = args.ndk
+    commit = args.commit
+    DEBUG = args.debug
+
+    base = os.path.abspath(os.curdir)
+    prefix = os.path.join(base, 'upstream/')
+
+    commit = prepare_upstream(prefix, commit)
+
+    libvpx_files = get_libvpx_files(prefix)
+    source, files, disabled, unknown = get_sources(prefix)
+
+    sources_mozbuild, moz_build_files = get_sources_mozbuild()
+
+    print_info(source, files, disabled, unknown, moz_build_files)
+    update_sources_mozbuild(files, sources_mozbuild)
+    update_and_remove_files(prefix, libvpx_files, files)
+    apply_patches()
+    update_readme(commit)
+
+    cleanup_upstream()
deleted file mode 100755
--- a/media/libvpx/update.sh
+++ /dev/null
@@ -1,362 +0,0 @@
-#!/bin/bash
-# This Source Code Form is subject to the terms of the Mozilla Public
-# License, v. 2.0. If a copy of the MPL was not distributed with this
-# file, You can obtain one at http://mozilla.org/MPL/2.0/.
-set -e
-
-PLATFORMS='
-  x86-win32-vs8
-  x86_64-win64-vs8
-  x86-linux-gcc
-  x86_64-linux-gcc
-  generic-gnu
-  x86-darwin9-gcc
-  x86_64-darwin9-gcc
-  armv7-android-gcc
-  '
-
-if [ $# -lt 1 ]; then
-  echo Usage: update.sh /path/to/libvpx/
-  echo The libvpx dir must contain a directory "objdir" with the following directories configured in it:
-  for target in ${PLATFORMS}; do
-    echo -e "   * objdir/${target}"
-  done
-  echo You can configure these from objdir/\$target with the following command:
-  echo $ ../../configure --target=\$target --disable-examples --disable-install-docs
-  echo For Android you need --sdk-path=/path/to/android-ndk-r\$REV
-  echo For Mac, you also need --enable-pic
-  exit -1
-fi
-
-# These are relative to SDK source dir.
-commonFiles=(
-  LICENSE
-  PATENTS
-  build/make/ads2gas.pl
-  build/make/obj_int_extract.c
-  vp8/common/alloccommon.c
-  vp8/common/alloccommon.h
-  vp8/common/arm/armv6/bilinearfilter_v6.asm
-  vp8/common/arm/armv6/copymem16x16_v6.asm
-  vp8/common/arm/armv6/copymem8x4_v6.asm
-  vp8/common/arm/armv6/copymem8x8_v6.asm
-  vp8/common/arm/armv6/dc_only_idct_add_v6.asm
-  vp8/common/arm/armv6/dequant_idct_v6.asm
-  vp8/common/arm/armv6/dequantize_v6.asm
-  vp8/common/arm/armv6/filter_v6.asm
-  vp8/common/arm/armv6/idct_blk_v6.c
-  vp8/common/arm/armv6/idct_v6.asm
-  vp8/common/arm/armv6/intra4x4_predict_v6.asm
-  vp8/common/arm/armv6/iwalsh_v6.asm
-  vp8/common/arm/armv6/loopfilter_v6.asm
-  vp8/common/arm/armv6/simpleloopfilter_v6.asm
-  vp8/common/arm/armv6/sixtappredict8x4_v6.asm
-  vp8/common/arm/armv6/vp8_sad16x16_armv6.asm
-  vp8/common/arm/armv6/vp8_variance16x16_armv6.asm
-  vp8/common/arm/armv6/vp8_variance8x8_armv6.asm
-  vp8/common/arm/armv6/vp8_variance_halfpixvar16x16_h_armv6.asm
-  vp8/common/arm/armv6/vp8_variance_halfpixvar16x16_hv_armv6.asm
-  vp8/common/arm/armv6/vp8_variance_halfpixvar16x16_v_armv6.asm
-  vp8/common/arm/bilinearfilter_arm.c
-  vp8/common/arm/bilinearfilter_arm.h
-  vp8/common/arm/dequantize_arm.c
-  vp8/common/arm/filter_arm.c
-  vp8/common/arm/loopfilter_arm.c
-  vp8/common/arm/neon/bilinearpredict16x16_neon.asm
-  vp8/common/arm/neon/bilinearpredict4x4_neon.asm
-  vp8/common/arm/neon/bilinearpredict8x4_neon.asm
-  vp8/common/arm/neon/bilinearpredict8x8_neon.asm
-  vp8/common/arm/neon/buildintrapredictorsmby_neon.asm
-  vp8/common/arm/neon/copymem16x16_neon.asm
-  vp8/common/arm/neon/copymem8x4_neon.asm
-  vp8/common/arm/neon/copymem8x8_neon.asm
-  vp8/common/arm/neon/dc_only_idct_add_neon.asm
-  vp8/common/arm/neon/dequant_idct_neon.asm
-  vp8/common/arm/neon/dequantizeb_neon.asm
-  vp8/common/arm/neon/idct_blk_neon.c
-  vp8/common/arm/neon/idct_dequant_0_2x_neon.asm
-  vp8/common/arm/neon/idct_dequant_full_2x_neon.asm
-  vp8/common/arm/neon/iwalsh_neon.asm
-  vp8/common/arm/neon/loopfilter_neon.asm
-  vp8/common/arm/neon/loopfiltersimplehorizontaledge_neon.asm
-  vp8/common/arm/neon/loopfiltersimpleverticaledge_neon.asm
-  vp8/common/arm/neon/mbloopfilter_neon.asm
-  vp8/common/arm/neon/sad16_neon.asm
-  vp8/common/arm/neon/sad8_neon.asm
-  vp8/common/arm/neon/save_reg_neon.asm
-  vp8/common/arm/neon/shortidct4x4llm_neon.asm
-  vp8/common/arm/neon/sixtappredict16x16_neon.asm
-  vp8/common/arm/neon/sixtappredict4x4_neon.asm
-  vp8/common/arm/neon/sixtappredict8x4_neon.asm
-  vp8/common/arm/neon/sixtappredict8x8_neon.asm
-  vp8/common/arm/neon/variance_neon.asm
-  vp8/common/arm/neon/vp8_subpixelvariance16x16_neon.asm
-  vp8/common/arm/neon/vp8_subpixelvariance16x16s_neon.asm
-  vp8/common/arm/neon/vp8_subpixelvariance8x8_neon.asm
-  vp8/common/arm/reconintra_arm.c
-  vp8/common/arm/variance_arm.c
-  vp8/common/asm_com_offsets.c
-  vp8/common/blockd.c
-  vp8/common/blockd.h
-  vp8/common/coefupdateprobs.h
-  vp8/common/common.h
-  vp8/common/debugmodes.c
-  vp8/common/default_coef_probs.h
-  vp8/common/dequantize.c
-  vp8/common/entropy.c
-  vp8/common/entropy.h
-  vp8/common/entropymode.c
-  vp8/common/entropymode.h
-  vp8/common/entropymv.c
-  vp8/common/entropymv.h
-  vp8/common/extend.c
-  vp8/common/extend.h
-  vp8/common/filter.c
-  vp8/common/filter.h
-  vp8/common/findnearmv.c
-  vp8/common/findnearmv.h
-  vp8/common/generic/systemdependent.c
-  vp8/common/header.h
-  vp8/common/idct_blk.c
-  vp8/common/idctllm.c
-  vp8/common/invtrans.h
-  vp8/common/loopfilter.c
-  vp8/common/loopfilter.h
-  vp8/common/loopfilter_filters.c
-  vp8/common/mbpitch.c
-  vp8/common/mfqe.c
-  vp8/common/modecont.c
-  vp8/common/modecont.h
-  vp8/common/mv.h
-  vp8/common/onyx.h
-  vp8/common/onyxc_int.h
-  vp8/common/onyxd.h
-  vp8/common/postproc.c
-  vp8/common/postproc.h
-  vp8/common/ppflags.h
-  vp8/common/pragmas.h
-  vp8/common/quant_common.c
-  vp8/common/quant_common.h
-  vp8/common/reconinter.c
-  vp8/common/reconinter.h
-  vp8/common/reconintra.c
-  vp8/common/reconintra4x4.c
-  vp8/common/reconintra4x4.h
-  vp8/common/rtcd.c
-  vp8/common/sad_c.c
-  vp8/common/setupintrarecon.c
-  vp8/common/setupintrarecon.h
-  vp8/common/swapyv12buffer.c
-  vp8/common/swapyv12buffer.h
-  vp8/common/systemdependent.h
-  vp8/common/threading.h
-  vp8/common/treecoder.c
-  vp8/common/treecoder.h
-  vp8/common/variance.h
-  vp8/common/variance_c.c
-  vp8/common/vp8_entropymodedata.h
-  vp8/common/x86/dequantize_mmx.asm
-  vp8/common/x86/filter_x86.c
-  vp8/common/x86/filter_x86.h
-  vp8/common/x86/idct_blk_mmx.c
-  vp8/common/x86/idct_blk_sse2.c
-  vp8/common/x86/idctllm_mmx.asm
-  vp8/common/x86/idctllm_sse2.asm
-  vp8/common/x86/iwalsh_mmx.asm
-  vp8/common/x86/iwalsh_sse2.asm
-  vp8/common/x86/loopfilter_block_sse2.asm
-  vp8/common/x86/loopfilter_mmx.asm
-  vp8/common/x86/loopfilter_sse2.asm
-  vp8/common/x86/loopfilter_x86.c
-  vp8/common/x86/mfqe_sse2.asm
-  vp8/common/x86/postproc_mmx.asm
-  vp8/common/x86/postproc_sse2.asm
-  vp8/common/x86/postproc_x86.c
-  vp8/common/x86/recon_mmx.asm
-  vp8/common/x86/recon_sse2.asm
-  vp8/common/x86/recon_wrapper_sse2.c
-  vp8/common/x86/sad_mmx.asm
-  vp8/common/x86/sad_sse2.asm
-  vp8/common/x86/sad_sse3.asm
-  vp8/common/x86/sad_sse4.asm
-  vp8/common/x86/sad_ssse3.asm
-  vp8/common/x86/subpixel_mmx.asm
-  vp8/common/x86/subpixel_sse2.asm
-  vp8/common/x86/subpixel_ssse3.asm
-  vp8/common/x86/variance_impl_mmx.asm
-  vp8/common/x86/variance_impl_sse2.asm
-  vp8/common/x86/variance_impl_ssse3.asm
-  vp8/common/x86/variance_mmx.c
-  vp8/common/x86/variance_sse2.c
-  vp8/common/x86/variance_ssse3.c
-  vp8/common/x86/vp8_asm_stubs.c
-  vp8/decoder/asm_dec_offsets.c
-  vp8/decoder/dboolhuff.c
-  vp8/decoder/dboolhuff.h
-  vp8/decoder/decodemv.c
-  vp8/decoder/decodemv.h
-  vp8/decoder/decoderthreading.h
-  vp8/decoder/decodframe.c
-  vp8/decoder/detokenize.c
-  vp8/decoder/detokenize.h
-  vp8/decoder/ec_types.h
-  vp8/decoder/error_concealment.c
-  vp8/decoder/error_concealment.h
-  vp8/decoder/onyxd_if.c
-  vp8/decoder/onyxd_int.h
-  vp8/decoder/threading.c
-  vp8/decoder/treereader.h
-  vp8/encoder/arm/armv5te/boolhuff_armv5te.asm
-  vp8/encoder/arm/armv5te/vp8_packtokens_armv5.asm
-  vp8/encoder/arm/armv5te/vp8_packtokens_mbrow_armv5.asm
-  vp8/encoder/arm/armv5te/vp8_packtokens_partitions_armv5.asm
-  vp8/encoder/arm/armv6/vp8_fast_quantize_b_armv6.asm
-  vp8/encoder/arm/armv6/vp8_mse16x16_armv6.asm
-  vp8/encoder/arm/armv6/vp8_short_fdct4x4_armv6.asm
-  vp8/encoder/arm/armv6/vp8_subtract_armv6.asm
-  vp8/encoder/arm/armv6/walsh_v6.asm
-  vp8/encoder/arm/boolhuff_arm.c
-  vp8/encoder/arm/dct_arm.c
-  vp8/encoder/arm/neon/fastquantizeb_neon.asm
-  vp8/encoder/arm/neon/picklpf_arm.c
-  vp8/encoder/arm/neon/shortfdct_neon.asm
-  vp8/encoder/arm/neon/subtract_neon.asm
-  vp8/encoder/arm/neon/vp8_memcpy_neon.asm
-  vp8/encoder/arm/neon/vp8_mse16x16_neon.asm
-  vp8/encoder/arm/neon/vp8_shortwalsh4x4_neon.asm
-  vp8/encoder/arm/quantize_arm.c
-  vp8/encoder/asm_enc_offsets.c
-  vp8/encoder/bitstream.c
-  vp8/encoder/bitstream.h
-  vp8/encoder/block.h
-  vp8/encoder/boolhuff.c
-  vp8/encoder/boolhuff.h
-  vp8/encoder/dct.c
-  vp8/encoder/dct_value_cost.h
-  vp8/encoder/dct_value_tokens.h
-  vp8/encoder/defaultcoefcounts.h
-  vp8/encoder/denoising.c
-  vp8/encoder/denoising.h
-  vp8/encoder/encodeframe.c
-  vp8/encoder/encodeframe.h
-  vp8/encoder/encodeintra.c
-  vp8/encoder/encodeintra.h
-  vp8/encoder/encodemb.c
-  vp8/encoder/encodemb.h
-  vp8/encoder/encodemv.c
-  vp8/encoder/encodemv.h
-  vp8/encoder/ethreading.c
-  vp8/encoder/firstpass.c
-  vp8/encoder/firstpass.h
-  vp8/encoder/lookahead.c
-  vp8/encoder/lookahead.h
-  vp8/encoder/mcomp.c
-  vp8/encoder/mcomp.h
-  vp8/encoder/modecosts.c
-  vp8/encoder/modecosts.h
-  vp8/encoder/mr_dissim.c
-  vp8/encoder/mr_dissim.h
-  vp8/encoder/onyx_if.c
-  vp8/encoder/onyx_int.h
-  vp8/encoder/pickinter.c
-  vp8/encoder/pickinter.h
-  vp8/encoder/picklpf.c
-  vp8/encoder/psnr.c
-  vp8/encoder/psnr.h
-  vp8/encoder/quantize.c
-  vp8/encoder/quantize.h
-  vp8/encoder/ratectrl.c
-  vp8/encoder/ratectrl.h
-  vp8/encoder/rdopt.c
-  vp8/encoder/rdopt.h
-  vp8/encoder/segmentation.c
-  vp8/encoder/segmentation.h
-  vp8/encoder/temporal_filter.c
-  vp8/encoder/tokenize.c
-  vp8/encoder/tokenize.h
-  vp8/encoder/treewriter.c
-  vp8/encoder/treewriter.h
-  vp8/encoder/x86/dct_mmx.asm
-  vp8/encoder/x86/dct_sse2.asm
-  vp8/encoder/x86/denoising_sse2.c
-  vp8/encoder/x86/encodeopt.asm
-  vp8/encoder/x86/fwalsh_sse2.asm
-  vp8/encoder/x86/quantize_mmx.asm
-  vp8/encoder/x86/quantize_sse2.asm
-  vp8/encoder/x86/quantize_sse4.asm
-  vp8/encoder/x86/quantize_ssse3.asm
-  vp8/encoder/x86/ssim_opt.asm
-  vp8/encoder/x86/subtract_mmx.asm
-  vp8/encoder/x86/subtract_sse2.asm
-  vp8/encoder/x86/temporal_filter_apply_sse2.asm
-  vp8/encoder/x86/vp8_enc_stubs_mmx.c
-  vp8/encoder/x86/vp8_enc_stubs_sse2.c
-  vp8/vp8_cx_iface.c
-  vp8/vp8_dx_iface.c
-  vpx/internal/vpx_codec_internal.h
-  vpx/src/vpx_codec.c
-  vpx/src/vpx_decoder.c
-  vpx/src/vpx_encoder.c
-  vpx/src/vpx_image.c
-  vpx/vp8.h
-  vpx/vp8cx.h
-  vpx/vp8dx.h
-  vpx/vpx_codec.h
-  vpx/vpx_codec_impl_bottom.h
-  vpx/vpx_codec_impl_top.h
-  vpx/vpx_decoder.h
-  vpx/vpx_encoder.h
-  vpx/vpx_image.h
-  vpx/vpx_integer.h
-  vpx_mem/include/vpx_mem_intrnl.h
-  vpx_mem/include/vpx_mem_tracker.h
-  vpx_mem/vpx_mem.c
-  vpx_mem/vpx_mem.h
-  vpx_ports/arm.h
-  vpx_ports/arm_cpudetect.c
-  vpx_ports/asm_offsets.h
-  vpx_ports/emms.asm
-  vpx_ports/mem.h
-  vpx_ports/mem_ops.h
-  vpx_ports/mem_ops_aligned.h
-  vpx_ports/vpx_timer.h
-  vpx_ports/vpxtypes.h
-  vpx_ports/x86.h
-  vpx_ports/x86_abi_support.asm
-  vpx_ports/x86_cpuid.c
-  vpx_scale/arm/neon/vp8_vpxyv12_copy_y_neon.asm
-  vpx_scale/arm/neon/vp8_vpxyv12_copyframe_func_neon.asm
-  vpx_scale/arm/neon/vp8_vpxyv12_copysrcframe_func_neon.asm
-  vpx_scale/arm/neon/vp8_vpxyv12_extendframeborders_neon.asm
-  vpx_scale/arm/neon/yv12extend_arm.c
-  vpx_scale/generic/gen_scalers.c
-  vpx_scale/generic/vpxscale.c
-  vpx_scale/generic/yv12config.c
-  vpx_scale/generic/yv12extend.c
-  vpx_scale/generic/yv12extend_generic.h
-  vpx_scale/include/generic/vpxscale_arbitrary.h
-  vpx_scale/include/generic/vpxscale_depricated.h
-  vpx_scale/scale_mode.h
-  vpx_scale/vpxscale.h
-  vpx_scale/yv12config.h
-)
-
-# Copy configuration files for each platform
-for target in ${PLATFORMS}; do
-  cp ${1}/objdir/${target}/vpx_config.h vpx_config_${target}.h
-  cp ${1}/objdir/${target}/vpx_config.c vpx_config_${target}.c
-  cp ${1}/objdir/${target}/vpx_rtcd.h vpx_rtcd_${target}.h
-done
-
-# Copy vpx_version.h from one of the build targets
-cp ${1}/objdir/x86-linux-gcc/vpx_version.h vpx_version.h
-
-# Copy common source files into mozilla tree.
-for f in ${commonFiles[@]}
-do
-  mkdir -p -v `dirname $f`
-  cp -v $1/$f $f
-done
-
-# Patch to permit vpx users to specify their own <stdint.h> types.
-patch -p3 < stdint.patch
--- a/media/libvpx/vp8/common/alloccommon.c
+++ b/media/libvpx/vp8/common/alloccommon.c
@@ -168,17 +168,16 @@ void vp8_create_common(VP8_COMMON *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->clr_type = REG_YUV;
     oci->clamp_type = RECON_CLAMP_REQUIRED;
 
     /* Initialize reference frame sign bias structure to defaults */
     vpx_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;
--- a/media/libvpx/vp8/common/arm/armv6/filter_v6.asm
+++ b/media/libvpx/vp8/common/arm/armv6/filter_v6.asm
@@ -389,17 +389,17 @@
     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, [r0, #-4]                   ; load the data
+    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
--- a/media/libvpx/vp8/common/arm/armv6/idct_blk_v6.c
+++ b/media/libvpx/vp8/common/arm/armv6/idct_blk_v6.c
@@ -4,17 +4,17 @@
  *  Use of this source code is governed by a BSD-style license
  *  that can be found in the LICENSE file in the root of the source
  *  tree. An additional intellectual property rights grant can 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_rtcd.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;
 
--- a/media/libvpx/vp8/common/arm/bilinearfilter_arm.c
+++ b/media/libvpx/vp8/common/arm/bilinearfilter_arm.c
@@ -4,17 +4,17 @@
  *  Use of this source code is governed by a BSD-style license
  *  that can be found in the LICENSE file in the root of the source
  *  tree. An additional intellectual property rights grant can 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_rtcd.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,
--- a/media/libvpx/vp8/common/arm/filter_arm.c
+++ b/media/libvpx/vp8/common/arm/filter_arm.c
@@ -5,17 +5,17 @@
  *  that can be found in the LICENSE file in the root of the source
  *  tree. An additional intellectual property rights grant can 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_rtcd.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,
--- a/media/libvpx/vp8/common/arm/loopfilter_arm.c
+++ b/media/libvpx/vp8/common/arm/loopfilter_arm.c
@@ -5,17 +5,17 @@
  *  that can be found in the LICENSE file in the root of the source
  *  tree. An additional intellectual property rights grant can 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_rtcd.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
--- a/media/libvpx/vp8/common/arm/neon/idct_blk_neon.c
+++ b/media/libvpx/vp8/common/arm/neon/idct_blk_neon.c
@@ -4,17 +4,17 @@
  *  Use of this source code is governed by a BSD-style license
  *  that can be found in the LICENSE file in the root of the source
  *  tree. An additional intellectual property rights grant can 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_rtcd.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);
--- a/media/libvpx/vp8/common/arm/neon/vp8_subpixelvariance16x16_neon.asm
+++ b/media/libvpx/vp8/common/arm/neon/vp8_subpixelvariance16x16_neon.asm
@@ -4,19 +4,16 @@
 ;  Use of this source code is governed by a BSD-style license
 ;  that can be found in the LICENSE file in the root of the source
 ;  tree. An additional intellectual property rights grant can be found
 ;  in the file PATENTS.  All contributing project authors may
 ;  be found in the AUTHORS file in the root of the source tree.
 ;
 
 
-bilinear_taps_coeff
-    DCD     128, 0, 112, 16, 96, 32, 80, 48, 64, 64, 48, 80, 32, 96, 16, 112
-
 ;-----------------
 
     EXPORT  |vp8_sub_pixel_variance16x16_neon_func|
     ARM
     REQUIRE8
     PRESERVE8
 
     AREA ||.text||, CODE, READONLY, ALIGN=2
@@ -24,16 +21,19 @@ bilinear_taps_coeff
 ; r1    int  src_pixels_per_line,
 ; r2    int  xoffset,
 ; r3    int  yoffset,
 ; stack(r4) unsigned char *dst_ptr,
 ; stack(r5) int dst_pixels_per_line,
 ; stack(r6) unsigned int *sse
 ;note: most of the code is copied from bilinear_predict16x16_neon and vp8_variance16x16_neon.
 
+bilinear_taps_coeff
+    DCD     128, 0, 112, 16, 96, 32, 80, 48, 64, 64, 48, 80, 32, 96, 16, 112
+
 |vp8_sub_pixel_variance16x16_neon_func| PROC
     push            {r4-r6, lr}
 
     adr             r12, bilinear_taps_coeff
     ldr             r4, [sp, #16]           ;load *dst_ptr from stack
     ldr             r5, [sp, #20]           ;load dst_pixels_per_line from stack
     ldr             r6, [sp, #24]           ;load *sse from stack
 
--- a/media/libvpx/vp8/common/arm/reconintra_arm.c
+++ b/media/libvpx/vp8/common/arm/reconintra_arm.c
@@ -5,17 +5,17 @@
  *  that can be found in the LICENSE file in the root of the source
  *  tree. An additional intellectual property rights grant can 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_rtcd.h"
+#include "vp8_rtcd.h"
 #include "vp8/common/blockd.h"
 #include "vpx_mem/vpx_mem.h"
 
 #if HAVE_NEON
 extern void vp8_build_intra_predictors_mby_neon_func(
     unsigned char *y_buffer,
     unsigned char *ypred_ptr,
     int y_stride,
--- a/media/libvpx/vp8/common/arm/variance_arm.c
+++ b/media/libvpx/vp8/common/arm/variance_arm.c
@@ -4,17 +4,17 @@
  *  Use of this source code is governed by a BSD-style license
  *  that can be found in the LICENSE file in the root of the source
  *  tree. An additional intellectual property rights grant can 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_rtcd.h"
+#include "vp8_rtcd.h"
 #include "vp8/common/variance.h"
 #include "vp8/common/filter.h"
 
 #if HAVE_MEDIA
 #include "vp8/common/arm/bilinearfilter_arm.h"
 
 unsigned int vp8_sub_pixel_variance8x8_armv6
 (
deleted file mode 100644
--- a/media/libvpx/vp8/common/asm_com_offsets.c
+++ /dev/null
@@ -1,71 +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 "vpx/vpx_codec.h"
-#include "vpx_ports/asm_offsets.h"
-#include "vpx_scale/yv12config.h"
-#include "vp8/common/blockd.h"
-
-#if CONFIG_POSTPROC
-#include "postproc.h"
-#endif /* CONFIG_POSTPROC */
-
-BEGIN
-
-/* vpx_scale */
-DEFINE(yv12_buffer_config_y_width,              offsetof(YV12_BUFFER_CONFIG, y_width));
-DEFINE(yv12_buffer_config_y_height,             offsetof(YV12_BUFFER_CONFIG, y_height));
-DEFINE(yv12_buffer_config_y_stride,             offsetof(YV12_BUFFER_CONFIG, y_stride));
-DEFINE(yv12_buffer_config_uv_width,             offsetof(YV12_BUFFER_CONFIG, uv_width));
-DEFINE(yv12_buffer_config_uv_height,            offsetof(YV12_BUFFER_CONFIG, uv_height));
-DEFINE(yv12_buffer_config_uv_stride,            offsetof(YV12_BUFFER_CONFIG, uv_stride));
-DEFINE(yv12_buffer_config_y_buffer,             offsetof(YV12_BUFFER_CONFIG, y_buffer));
-DEFINE(yv12_buffer_config_u_buffer,             offsetof(YV12_BUFFER_CONFIG, u_buffer));
-DEFINE(yv12_buffer_config_v_buffer,             offsetof(YV12_BUFFER_CONFIG, v_buffer));
-DEFINE(yv12_buffer_config_border,               offsetof(YV12_BUFFER_CONFIG, border));
-DEFINE(VP8BORDERINPIXELS_VAL,                   VP8BORDERINPIXELS);
-
-#if CONFIG_POSTPROC
-/* mfqe.c / filter_by_weight */
-DEFINE(MFQE_PRECISION_VAL,                      MFQE_PRECISION);
-#endif /* CONFIG_POSTPROC */
-
-END
-
-/* add asserts for any offset that is not supported by assembly code */
-/* add asserts for any size that is not supported by assembly code */
-
-#if HAVE_MEDIA
-/* switch case in vp8_intra4x4_predict_armv6 is based on these enumerated values */
-ct_assert(B_DC_PRED, B_DC_PRED == 0);
-ct_assert(B_TM_PRED, B_TM_PRED == 1);
-ct_assert(B_VE_PRED, B_VE_PRED == 2);
-ct_assert(B_HE_PRED, B_HE_PRED == 3);
-ct_assert(B_LD_PRED, B_LD_PRED == 4);
-ct_assert(B_RD_PRED, B_RD_PRED == 5);
-ct_assert(B_VR_PRED, B_VR_PRED == 6);
-ct_assert(B_VL_PRED, B_VL_PRED == 7);
-ct_assert(B_HD_PRED, B_HD_PRED == 8);
-ct_assert(B_HU_PRED, B_HU_PRED == 9);
-#endif
-
-#if HAVE_NEON
-/* vp8_yv12_extend_frame_borders_neon makes several assumptions based on this */
-ct_assert(VP8BORDERINPIXELS_VAL, VP8BORDERINPIXELS == 32)
-#endif
-
-#if HAVE_SSE2
-#if CONFIG_POSTPROC
-/* vp8_filter_by_weight16x16 and 8x8 */
-ct_assert(MFQE_PRECISION_VAL, MFQE_PRECISION == 4)
-#endif /* CONFIG_POSTPROC */
-#endif /* HAVE_SSE2 */
--- a/media/libvpx/vp8/common/dequantize.c
+++ b/media/libvpx/vp8/common/dequantize.c
@@ -5,17 +5,17 @@
  *  that can be found in the LICENSE file in the root of the source
  *  tree. An additional intellectual property rights grant can 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_rtcd.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;
--- a/media/libvpx/vp8/common/filter.c
+++ b/media/libvpx/vp8/common/filter.c
@@ -4,19 +4,17 @@
  *  Use of this source code is governed by a BSD-style license
  *  that can be found in the LICENSE file in the root of the source
  *  tree. An additional intellectual property rights grant can 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 "filter.h"
-#include "vpx_ports/mem.h"
 
 DECLARE_ALIGNED(16, const short, vp8_bilinear_filters[8][2]) =
 {
     { 128,   0 },
     { 112,  16 },
     {  96,  32 },
     {  80,  48 },
     {  64,  64 },
--- a/media/libvpx/vp8/common/filter.h
+++ b/media/libvpx/vp8/common/filter.h
@@ -7,16 +7,18 @@
  *  in the file PATENTS.  All contributing project authors may
  *  be found in the AUTHORS file in the root of the source tree.
  */
 
 
 #ifndef FILTER_H
 #define FILTER_H
 
+#include "vpx_ports/mem.h"
+
 #define BLOCK_HEIGHT_WIDTH 4
 #define VP8_FILTER_WEIGHT 128
 #define VP8_FILTER_SHIFT  7
 
-extern const short vp8_bilinear_filters[8][2];
-extern const short vp8_sub_pel_filters[8][6];
+extern DECLARE_ALIGNED(16, const short, vp8_bilinear_filters[8][2]);
+extern DECLARE_ALIGNED(16, const short, vp8_sub_pel_filters[8][6]);
 
 #endif
--- a/media/libvpx/vp8/common/findnearmv.h
+++ b/media/libvpx/vp8/common/findnearmv.h
@@ -119,17 +119,17 @@ static int above_block_mv(const MODE_INF
         /* 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;
+    return (cur_mb->bmi + (b - 4))->mv.as_int;
 }
 static 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)
--- a/media/libvpx/vp8/common/generic/systemdependent.c
+++ b/media/libvpx/vp8/common/generic/systemdependent.c
@@ -5,17 +5,17 @@
  *  that can be found in the LICENSE file in the root of the source
  *  tree. An additional intellectual property rights grant can 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_rtcd.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"
 
 #if CONFIG_MULTITHREAD
@@ -77,16 +77,17 @@ static int get_cpu_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
--- a/media/libvpx/vp8/common/idct_blk.c
+++ b/media/libvpx/vp8/common/idct_blk.c
@@ -4,17 +4,18 @@
  *  Use of this source code is governed by a BSD-style license
  *  that can be found in the LICENSE file in the root of the source
  *  tree. An additional intellectual property rights grant can 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_rtcd.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
@@ -27,17 +28,17 @@ void vp8_dequant_idct_add_y_block_c
     {
         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);
-                ((int *)q)[0] = 0;
+                vpx_memset(q, 0, 2 * sizeof(q[0]));
             }
 
             q   += 16;
             dst += 4;
         }
 
         dst += 4*stride - 16;
     }
@@ -53,17 +54,17 @@ void vp8_dequant_idct_add_uv_block_c
     {
         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);
-                ((int *)q)[0] = 0;
+                vpx_memset(q, 0, 2 * sizeof(q[0]));
             }
 
             q    += 16;
             dstu += 4;
         }
 
         dstu += 4*stride - 8;
     }
@@ -72,17 +73,17 @@ void vp8_dequant_idct_add_uv_block_c
     {
         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);
-                ((int *)q)[0] = 0;
+                vpx_memset(q, 0, 2 * sizeof(q[0]));
             }
 
             q    += 16;
             dstv += 4;
         }
 
         dstv += 4*stride - 8;
     }
--- a/media/libvpx/vp8/common/invtrans.h
+++ b/media/libvpx/vp8/common/invtrans.h
@@ -8,17 +8,17 @@
  *  be found in the AUTHORS file in the root of the source tree.
  */
 
 
 #ifndef __INC_INVTRANS_H
 #define __INC_INVTRANS_H
 
 #include "vpx_config.h"
-#include "vpx_rtcd.h"
+#include "vp8_rtcd.h"
 #include "blockd.h"
 #include "onyxc_int.h"
 
 #if CONFIG_MULTITHREAD
 #include "vpx_mem/vpx_mem.h"
 #endif
 
 static void eob_adjust(char *eobs, short *diff)
--- a/media/libvpx/vp8/common/loopfilter.c
+++ b/media/libvpx/vp8/common/loopfilter.c
@@ -5,17 +5,17 @@
  *  that can be found in the LICENSE file in the root of the source
  *  tree. An additional intellectual property rights grant can 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_rtcd.h"
+#include "vp8_rtcd.h"
 #include "loopfilter.h"
 #include "onyxc_int.h"
 #include "vpx_mem/vpx_mem.h"
 
 typedef unsigned char uc;
 
 static void lf_init_lut(loop_filter_info_n *lfi)
 {
@@ -151,49 +151,48 @@ void vp8_loop_filter_frame_init(VP8_COMM
         {
             /* we could get rid of this if we assume that deltas are set to
              * zero when not in use; encoder always uses deltas
              */
             vpx_memset(lfi->lvl[seg][0], lvl_seg, 4 * 4 );
             continue;
         }
 
-        lvl_ref = lvl_seg;
-
         /* INTRA_FRAME */
         ref = INTRA_FRAME;
 
         /* Apply delta for reference frame */
-        lvl_ref += mbd->ref_lf_deltas[ref];
+        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];
-        lvl_mode = (lvl_mode > 0) ? (lvl_mode > 63 ? 63 : lvl_mode) : 0; /* clamp */
+        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 */
-        lvl_mode = (lvl_ref > 0) ? (lvl_ref > 63 ? 63 : lvl_ref)  : 0; /* clamp */
+        /* 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++)
         {
-            int lvl_ref = lvl_seg;
-
             /* Apply delta for reference frame */
-            lvl_ref += mbd->ref_lf_deltas[ref];
+            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];
-                lvl_mode = (lvl_mode > 0) ? (lvl_mode > 63 ? 63 : lvl_mode) : 0; /* clamp */
+                /* clamp */
+                lvl_mode = (lvl_mode > 0) ? (lvl_mode > 63 ? 63 : lvl_mode) : 0;
 
                 lfi->lvl[seg][ref][mode] = lvl_mode;
             }
         }
     }
 }
 
 
@@ -562,73 +561,57 @@ void vp8_loop_filter_partial_frame
     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, i;
+    int linestocopy;
 
     loop_filter_info_n *lfi_n = &cm->lf_info;
     loop_filter_info lfi;
 
     int filter_level;
-    int alt_flt_enabled = mbd->segmentation_enabled;
     FRAME_TYPE frame_type = cm->frame_type;
 
     const MODE_INFO *mode_info_context;
 
-    int lvl_seg[MAX_MB_SEGMENTS];
+#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 */
 
-    /* Note the baseline filter values for each segment */
-    /* See vp8_loop_filter_frame_init. Rather than call that for each change
-     * to default_filt_lvl, copy the relevant calculation here.
-     */
-    if (alt_flt_enabled)
-    {
-        for (i = 0; i < MAX_MB_SEGMENTS; i++)
-        {    /* Abs value */
-            if (mbd->mb_segement_abs_delta == SEGMENT_ABSDATA)
-            {
-                lvl_seg[i] = mbd->segment_feature_data[MB_LVL_ALT_LF][i];
-            }
-            /* Delta Value */
-            else
-            {
-                lvl_seg[i] = default_filt_lvl
-                        + mbd->segment_feature_data[MB_LVL_ALT_LF][i];
-                lvl_seg[i] = (lvl_seg[i] > 0) ?
-                        ((lvl_seg[i] > 63) ? 63: lvl_seg[i]) : 0;
-            }
-        }
-    }
-
     /* 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);
 
-            if (alt_flt_enabled)
-                filter_level = lvl_seg[mode_info_context->mbmi.segment_id];
-            else
-                filter_level = default_filt_lvl;
+            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];
--- a/media/libvpx/vp8/common/loopfilter.h
+++ b/media/libvpx/vp8/common/loopfilter.h
@@ -9,17 +9,17 @@
  */
 
 
 #ifndef loopfilter_h
 #define loopfilter_h
 
 #include "vpx_ports/mem.h"
 #include "vpx_config.h"
-#include "vpx_rtcd.h"
+#include "vp8_rtcd.h"
 
 #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
 {
--- a/media/libvpx/vp8/common/loopfilter_filters.c
+++ b/media/libvpx/vp8/common/loopfilter_filters.c
@@ -49,54 +49,54 @@ static signed char vp8_hevmask(uc thresh
 }
 
 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 vp8_filter, Filter1, Filter2;
+    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 */
-    vp8_filter = vp8_signed_char_clamp(ps1 - qs1);
-    vp8_filter &= hev;
+    filter_value = vp8_signed_char_clamp(ps1 - qs1);
+    filter_value &= hev;
 
     /* inner taps */
-    vp8_filter = vp8_signed_char_clamp(vp8_filter + 3 * (qs0 - ps0));
-    vp8_filter &= mask;
+    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(vp8_filter + 4);
-    Filter2 = vp8_signed_char_clamp(vp8_filter + 3);
+    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;
-    vp8_filter = Filter1;
+    filter_value = Filter1;
 
     /* outer tap adjustments */
-    vp8_filter += 1;
-    vp8_filter >>= 1;
-    vp8_filter &= ~hev;
+    filter_value += 1;
+    filter_value >>= 1;
+    filter_value &= ~hev;
 
-    u = vp8_signed_char_clamp(qs1 - vp8_filter);
+    u = vp8_signed_char_clamp(qs1 - filter_value);
     *oq1 = u ^ 0x80;
-    u = vp8_signed_char_clamp(ps1 + vp8_filter);
+    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,
@@ -157,44 +157,44 @@ void vp8_loop_filter_vertical_edge_c
     }
     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 vp8_filter, Filter1, Filter2;
+    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 */
-    vp8_filter = vp8_signed_char_clamp(ps1 - qs1);
-    vp8_filter = vp8_signed_char_clamp(vp8_filter + 3 * (qs0 - ps0));
-    vp8_filter &= mask;
+    filter_value = vp8_signed_char_clamp(ps1 - qs1);
+    filter_value = vp8_signed_char_clamp(filter_value + 3 * (qs0 - ps0));
+    filter_value &= mask;
 
-    Filter2 = vp8_filter;
+    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 */
-    vp8_filter &= ~hev;
-    Filter2 = vp8_filter;
+    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;
 
@@ -286,34 +286,34 @@ static signed char vp8_simple_filter_mas
  *  (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 vp8_filter, Filter1, Filter2;
+    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;
 
-    vp8_filter = vp8_signed_char_clamp(p1 - q1);
-    vp8_filter = vp8_signed_char_clamp(vp8_filter + 3 * (q0 - p0));
-    vp8_filter &= mask;
+    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(vp8_filter + 4);
+    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(vp8_filter + 3);
+    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,
--- a/media/libvpx/vp8/common/mfqe.c
+++ b/media/libvpx/vp8/common/mfqe.c
@@ -15,17 +15,17 @@
  * 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 "postproc.h"
 #include "variance.h"
 #include "vpx_mem/vpx_mem.h"
-#include "vpx_rtcd.h"
+#include "vp8_rtcd.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)
@@ -275,17 +275,17 @@ 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->mi;
+    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;
--- a/media/libvpx/vp8/common/onyx.h
+++ b/media/libvpx/vp8/common/onyx.h
@@ -36,17 +36,18 @@ extern "C"
         ONETWO      = 3
 
     } VPX_SCALING;
 
     typedef enum
     {
         USAGE_STREAM_FROM_SERVER    = 0x0,
         USAGE_LOCAL_FILE_PLAYBACK   = 0x1,
-        USAGE_CONSTRAINED_QUALITY   = 0x2
+        USAGE_CONSTRAINED_QUALITY   = 0x2,
+        USAGE_CONSTANT_QUALITY      = 0x3
     } END_USAGE;
 
 
     typedef enum
     {
         MODE_REALTIME       = 0x0,
         MODE_GOODQUALITY    = 0x1,
         MODE_BESTQUALITY    = 0x2,
--- a/media/libvpx/vp8/common/onyxc_int.h
+++ b/media/libvpx/vp8/common/onyxc_int.h
@@ -8,17 +8,17 @@
  *  be found in the AUTHORS file in the root of the source tree.
  */
 
 
 #ifndef __INC_VP8C_INT_H
 #define __INC_VP8C_INT_H
 
 #include "vpx_config.h"
-#include "vpx_rtcd.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
 
@@ -67,17 +67,16 @@ typedef struct VP8Common
     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;
 
-    YUV_TYPE clr_type;
     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;
 
@@ -110,29 +109,27 @@ typedef struct VP8Common
     int base_qindex;
 
     int y1dc_delta_q;
     int y2dc_delta_q;
     int y2ac_delta_q;
     int uvdc_delta_q;
     int uvac_delta_q;
 
-    unsigned int frames_since_golden;
-    unsigned int frames_till_alt_ref_frame;
-
     /* 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;
 
@@ -151,26 +148,27 @@ typedef struct VP8Common
     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 near_boffset[3];
     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;
--- a/media/libvpx/vp8/common/onyxd.h
+++ b/media/libvpx/vp8/common/onyxd.h
@@ -29,17 +29,16 @@ extern "C"
     typedef struct
     {
         int     Width;
         int     Height;
         int     Version;
         int     postprocess;
         int     max_threads;
         int     error_concealment;
-        int     input_fragments;
     } VP8D_CONFIG;
 
     typedef enum
     {
         VP8D_OK = 0
     } VP8D_SETTING;
 
     void vp8dx_initialize(void);
@@ -51,18 +50,14 @@ extern "C"
     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);
 
-    struct VP8D_COMP* vp8dx_create_decompressor(VP8D_CONFIG *oxcf);
-
-    void vp8dx_remove_decompressor(struct VP8D_COMP* comp);
-
 #ifdef __cplusplus
 }
 #endif
 
 
 #endif
--- a/media/libvpx/vp8/common/postproc.c
+++ b/media/libvpx/vp8/common/postproc.c
@@ -5,21 +5,22 @@
  *  that can be found in the LICENSE file in the root of the source
  *  tree. An additional intellectual property rights grant can 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_rtcd.h"
+#include "vp8_rtcd.h"
+#include "vpx_scale_rtcd.h"
 #include "vpx_scale/yv12config.h"
 #include "postproc.h"
 #include "common.h"
-#include "vpx_scale/vpxscale.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)                                                                       \
@@ -328,17 +329,17 @@ void vp8_deblock(VP8_COMMON             
                  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->mi;
+    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;
@@ -433,39 +434,38 @@ double vp8_gaussian(double sigma, double
            (exp(-(x - mu) * (x - mu) / (2 * sigma * sigma)));
 }
 
 static void fillrd(struct postproc_state *state, int q, int a)
 {
     char char_dist[300];
 
     double sigma;
-    int ai = a, qi = q, i;
+    int i;
 
     vp8_clear_system_state();
 
 
-    sigma = ai + .5 + .6 * (63 - qi) / 63.0;
+    sigma = a + .5 + .6 * (63 - q) / 63.0;
 
     /* set up a lookup table of 256 entries that matches
      * a gaussian distribution with sigma determined by q.
      */
     {
-        double i;
         int next, j;
 
         next = 0;
 
         for (i = -32; i < 32; i++)
         {
-            int a = (int)(.5 + 256 * vp8_gaussian(sigma, 0, i));
+            const int v = (int)(.5 + 256 * vp8_gaussian(sigma, 0, i));
 
-            if (a)
+            if (v)
             {
-                for (j = 0; j < a; j++)
+                for (j = 0; j < v; j++)
                 {
                     char_dist[next+j] = (char) i;
                 }
 
                 next = next + j;
             }
 
         }
@@ -538,22 +538,22 @@ void vp8_plane_add_noise_c(unsigned char
     }
 }
 
 /* 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 y1, int u1, int v1, int alpha, int stride)
+                        int y_1, int u_1, int v_1, int alpha, int stride)
 {
     int i, j;
-    int y1_const = y1*((1<<16)-alpha);
-    int u1_const = u1*((1<<16)-alpha);
-    int v1_const = v1*((1<<16)-alpha);
+    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;
         }
@@ -576,22 +576,22 @@ void vp8_blend_mb_inner_c (unsigned char
         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 y1, int u1, int v1, int alpha, int stride)
+                        int y_1, int u_1, int v_1, int alpha, int stride)
 {
     int i, j;
-    int y1_const = y1*((1<<16)-alpha);
-    int u1_const = u1*((1<<16)-alpha);
-    int v1_const = v1*((1<<16)-alpha);
+    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;
@@ -640,22 +640,22 @@ void vp8_blend_mb_outer_c (unsigned char
     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 y1, int u1, int v1, int alpha, int stride)
+                        int y_1, int u_1, int v_1, int alpha, int stride)
 {
     int i, j;
-    int y1_const = y1*((1<<16)-alpha);
-    int u1_const = u1*((1<<16)-alpha);
-    int v1_const = v1*((1<<16)-alpha);
+    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;
@@ -670,56 +670,56 @@ void vp8_blend_b_c (unsigned char *y, un
             u[j] = (u[j]*alpha + u1_const)>>16;
             v[j] = (v[j]*alpha + v1_const)>>16;
         }
         u += stride;
         v += stride;
     }
 }
 
-static void constrain_line (int x0, int *x1, int y0, int *y1, int width, int height)
+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 (*x1 > width)
+    if (*x_1 > width)
     {
-        dx = *x1 - x0;
-        dy = *y1 - y0;
+        dx = *x_1 - x_0;
+        dy = *y_1 - y_0;
 
-        *x1 = width;
+        *x_1 = width;
         if (dx)
-            *y1 = ((width-x0)*dy)/dx + y0;
+            *y_1 = ((width-x_0)*dy)/dx + y_0;
     }
-    if (*x1 < 0)
+    if (*x_1 < 0)
     {
-        dx = *x1 - x0;
-        dy = *y1 - y0;
+        dx = *x_1 - x_0;
+        dy = *y_1 - y_0;
 
-        *x1 = 0;
+        *x_1 = 0;
         if (dx)
-            *y1 = ((0-x0)*dy)/dx + y0;
+            *y_1 = ((0-x_0)*dy)/dx + y_0;
     }
-    if (*y1 > height)
+    if (*y_1 > height)
     {
-        dx = *x1 - x0;
-        dy = *y1 - y0;
+        dx = *x_1 - x_0;
+        dy = *y_1 - y_0;
 
-        *y1 = height;
+        *y_1 = height;
         if (dy)
-            *x1 = ((height-y0)*dx)/dy + x0;
+            *x_1 = ((height-y_0)*dx)/dy + x_0;
     }
-    if (*y1 < 0)
+    if (*y_1 < 0)
     {
-        dx = *x1 - x0;
-        dy = *y1 - y0;
+        dx = *x_1 - x_0;
+        dy = *y_1 - y_0;
 
-        *y1 = 0;
+        *y_1 = 0;
         if (dy)
-            *x1 = ((0-y0)*dx)/dy + x0;
+            *x_1 = ((0-y_0)*dx)/dy + x_0;
     }
 }
 
 #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;
@@ -918,17 +918,17 @@ int vp8_post_proc_frame(VP8_COMMON *oci,
             y_ptr += post->y_stride  * 16 - post->y_width;
 
         }
     }
 
     if (flags & VP8D_DEBUG_TXT_RATE_INFO)
     {
         char message[512];
-        sprintf(message, "Bitrate: %10.2f frame_rate: %10.2f ", oci->bitrate, oci->framerate);
+        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;
--- a/media/libvpx/vp8/common/reconinter.c
+++ b/media/libvpx/vp8/common/reconinter.c
@@ -6,17 +6,17 @@
  *  tree. An additional intellectual property rights grant can 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_rtcd.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(
@@ -133,24 +133,20 @@ void vp8_build_inter_predictors_b(BLOCKD
     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++)
         {
-#if !(CONFIG_FAST_UNALIGNED)
             pred_ptr[0]  = ptr[0];
             pred_ptr[1]  = ptr[1];
             pred_ptr[2]  = ptr[2];
             pred_ptr[3]  = ptr[3];
-#else
-            *(uint32_t *)pred_ptr = *(uint32_t *)ptr ;
-#endif
             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)
 {
@@ -191,26 +187,22 @@ static void build_inter_predictors_b(BLO
     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++)
         {
-#if !(CONFIG_FAST_UNALIGNED)
           dst[0]  = ptr[0];
           dst[1]  = ptr[1];
           dst[2]  = ptr[2];
           dst[3]  = ptr[3];
-#else
-            *(uint32_t *)dst = *(uint32_t *)ptr ;
-#endif
-            dst     += dst_stride;
-            ptr     += pre_stride;
+          dst     += dst_stride;
+          ptr     += pre_stride;
         }
     }
 }
 
 
 /*encoder only*/
 void vp8_build_inter16x16_predictors_mbuv(MACROBLOCKD *x)
 {
@@ -265,26 +257,26 @@ void vp8_build_inter4x4_predictors_mbuv(
 
             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(int) * CHAR_BIT - 1)) << 3);
+            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(int) * CHAR_BIT - 1)) << 3);
+            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;
@@ -553,26 +545,26 @@ void build_4x4uvmvs(MACROBLOCKD *x)
 
             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(int) * CHAR_BIT - 1)) << 3);
+            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(int) * CHAR_BIT - 1)) << 3);
+            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;
         }
--- a/media/libvpx/vp8/common/reconintra.c
+++ b/media/libvpx/vp8/common/reconintra.c
@@ -5,17 +5,17 @@
  *  that can be found in the LICENSE file in the root of the source
  *  tree. An additional intellectual property rights grant can 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_rtcd.h"
+#include "vp8_rtcd.h"
 #include "vpx_mem/vpx_mem.h"
 #include "blockd.h"
 
 void vp8_build_intra_predictors_mby_s_c(MACROBLOCKD *x,
                                           unsigned char * yabove_row,
                                           unsigned char * yleft,
                                           int left_stride,
                                           unsigned char * ypred_ptr,
@@ -31,17 +31,16 @@ void vp8_build_intra_predictors_mby_s_c(
     }
 
     /* for Y */
     switch (x->mode_info_context->mbmi.mode)
     {
     case DC_PRED:
     {
         int expected_dc;
-        int i;
         int shift;
         int average = 0;
 
 
         if (x->up_available || x->left_available)
         {
             if (x->up_available)
             {
@@ -163,17 +162,16 @@ void vp8_build_intra_predictors_mbuv_s_c
     }
 
     switch (x->mode_info_context->mbmi.uv_mode)
     {
     case DC_PRED:
     {
         int expected_udc;
         int expected_vdc;
-        int i;
         int shift;
         int Uaverage = 0;
         int Vaverage = 0;
 
         if (x->up_available)
         {
             for (i = 0; i < 8; i++)
             {
@@ -212,46 +210,40 @@ void vp8_build_intra_predictors_mbuv_s_c
             vpx_memset(vpred_ptr, expected_vdc, 8);
             upred_ptr += pred_stride;
             vpred_ptr += pred_stride;
         }
     }
     break;
     case V_PRED:
     {
-        int i;
-
         for (i = 0; i < 8; i++)
         {
             vpx_memcpy(upred_ptr, uabove_row, 8);
             vpx_memcpy(vpred_ptr, vabove_row, 8);
             upred_ptr += pred_stride;
             vpred_ptr += pred_stride;
         }
 
     }
     break;
     case H_PRED:
     {
-        int i;
-
         for (i = 0; i < 8; i++)
         {
             vpx_memset(upred_ptr, uleft_col[i], 8);
             vpx_memset(vpred_ptr, vleft_col[i], 8);
             upred_ptr += pred_stride;
             vpred_ptr += pred_stride;
         }
     }
 
     break;
     case TM_PRED:
     {
-        int i;
-
         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;
 
                 if (predu < 0)
--- a/media/libvpx/vp8/common/reconintra4x4.c
+++ b/media/libvpx/vp8/common/reconintra4x4.c
@@ -5,27 +5,27 @@
  *  that can be found in the LICENSE file in the root of the source
  *  tree. An additional intellectual property rights grant can 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_rtcd.h"
+#include "vp8_rtcd.h"
 #include "blockd.h"
 
 void vp8_intra4x4_predict_c(unsigned char *Above,
                             unsigned char *yleft, int left_stride,
-                            B_PREDICTION_MODE b_mode,
+                            int           _b_mode,
                             unsigned char *dst, int dst_stride,
                             unsigned char top_left)
 {
     int i, r, c;
-
+    B_PREDICTION_MODE b_mode = (B_PREDICTION_MODE)_b_mode;
     unsigned char Left[4];
     Left[0] = yleft[0];
     Left[1] = yleft[left_stride];
     Left[2] = yleft[2 * left_stride];
     Left[3] = yleft[3 * left_stride];
 
     switch (b_mode)
     {
--- a/media/libvpx/vp8/common/rtcd.c
+++ b/media/libvpx/vp8/common/rtcd.c
@@ -4,102 +4,18 @@
  *  Use of this source code is governed by a BSD-style license
  *  that can be found in the LICENSE file in the root of the source
  *  tree. An additional intellectual property rights grant can 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 "vpx_rtcd.h"
-
-#if CONFIG_MULTITHREAD && defined(_WIN32)
-#include <windows.h>
-#include <stdlib.h>
-static void once(void (*func)(void))
-{
-    static CRITICAL_SECTION *lock;
-    static LONG waiters;
-    static int done;
-    void *lock_ptr = &lock;
-
-    /* If the initialization is complete, return early. This isn't just an
-     * optimization, it prevents races on the destruction of the global
-     * lock.
-     */
-    if(done)
-        return;
-
-    InterlockedIncrement(&waiters);
-
-    /* Get a lock. We create one and try to make it the one-true-lock,
-     * throwing it away if we lost the race.
-     */
-
-    {
-        /* Scope to protect access to new_lock */
-        CRITICAL_SECTION *new_lock = malloc(sizeof(CRITICAL_SECTION));
-        InitializeCriticalSection(new_lock);
-        if (InterlockedCompareExchangePointer(lock_ptr, new_lock, NULL) != NULL)
-        {
-            DeleteCriticalSection(new_lock);
-            free(new_lock);
-        }
-    }
-
-    /* At this point, we have a lock that can be synchronized on. We don't
-     * care which thread actually performed the allocation.
-     */
-
-    EnterCriticalSection(lock);
+#include "vp8_rtcd.h"
+#include "vpx_ports/vpx_once.h"
 
-    if (!done)
-    {
-        func();
-        done = 1;
-    }
-
-    LeaveCriticalSection(lock);
+extern void vpx_scale_rtcd(void);
 
-    /* Last one out should free resources. The destructed objects are
-     * protected by checking if(done) above.
-     */
-    if(!InterlockedDecrement(&waiters))
-    {
-        DeleteCriticalSection(lock);
-        free(lock);
-        lock = NULL;
-    }
-}
-
-
-#elif CONFIG_MULTITHREAD && HAVE_PTHREAD_H
-#include <pthread.h>
-static void once(void (*func)(void))
+void vp8_rtcd()
 {
-    static pthread_once_t lock = PTHREAD_ONCE_INIT;
-    pthread_once(&lock, func);
-}
-
-
-#else
-/* No-op version that performs no synchronization. vpx_rtcd() is idempotent,
- * so as long as your platform provides atomic loads/stores of pointers
- * no synchronization is strictly necessary.
- */
-
-static void once(void (*func)(void))
-{
-    static int done;
-
-    if(!done)
-    {
-        func();
-        done = 1;
-    }
-}
-#endif
-
-
-void vpx_rtcd()
-{
+    vpx_scale_rtcd();
     once(setup_rtcd_internal);
 }
--- a/media/libvpx/vp8/common/systemdependent.h
+++ b/media/libvpx/vp8/common/systemdependent.h
@@ -5,17 +5,11 @@
  *  that can be found in the LICENSE file in the root of the source
  *  tree. An additional intellectual property rights grant can 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"
-#if ARCH_X86 || ARCH_X86_64
-void vpx_reset_mmx_state(void);
-#define vp8_clear_system_state() vpx_reset_mmx_state()
-#else
-#define vp8_clear_system_state()
-#endif
 
 struct VP8Common;
 void vp8_machine_specific_config(struct VP8Common *);
--- a/media/libvpx/vp8/common/variance_c.c
+++ b/media/libvpx/vp8/common/variance_c.c
@@ -70,82 +70,82 @@ unsigned int vp8_variance16x16_c(
     unsigned int *sse)
 {
     unsigned int var;
     int avg;
 
 
     variance(src_ptr, source_stride, ref_ptr, recon_stride, 16, 16, &var, &avg);
     *sse = var;
-    return (var - ((unsigned int)(avg * avg) >> 8));
+    return (var - (((unsigned int)avg * avg) >> 8));
 }
 
 unsigned int vp8_variance8x16_c(
     const unsigned char *src_ptr,
     int  source_stride,
     const unsigned char *ref_ptr,
     int  recon_stride,
     unsigned int *sse)
 {
     unsigned int var;
     int avg;
 
 
     variance(src_ptr, source_stride, ref_ptr, recon_stride, 8, 16, &var, &avg);
     *sse = var;
-    return (var - ((unsigned int)(avg * avg) >> 7));
+    return (var - (((unsigned int)avg * avg) >> 7));
 }
 
 unsigned int vp8_variance16x8_c(
     const unsigned char *src_ptr,
     int  source_stride,
     const unsigned char *ref_ptr,
     int  recon_stride,
     unsigned int *sse)
 {
     unsigned int var;
     int avg;
 
 
     variance(src_ptr, source_stride, ref_ptr, recon_stride, 16, 8, &var, &avg);
     *sse = var;
-    return (var - ((unsigned int)(avg * avg) >> 7));
+    return (var - (((unsigned int)avg * avg) >> 7));
 }
 
 
 unsigned int vp8_variance8x8_c(
     const unsigned char *src_ptr,
     int  source_stride,
     const unsigned char *ref_ptr,
     int  recon_stride,
     unsigned int *sse)
 {
     unsigned int var;
     int avg;
 
 
     variance(src_ptr, source_stride, ref_ptr, recon_stride, 8, 8, &var, &avg);
     *sse = var;
-    return (var - ((unsigned int)(avg * avg) >> 6));
+    return (var - (((unsigned int)avg * avg) >> 6));
 }
 
 unsigned int vp8_variance4x4_c(
     const unsigned char *src_ptr,
     int  source_stride,
     const unsigned char *ref_ptr,
     int  recon_stride,
     unsigned int *sse)
 {
     unsigned int var;
     int avg;
 
 
     variance(src_ptr, source_stride, ref_ptr, recon_stride, 4, 4, &var, &avg);
     *sse = var;
-    return (var - ((unsigned int)(avg * avg) >> 4));
+    return (var - (((unsigned int)avg * avg) >> 4));
 }
 
 
 unsigned int vp8_mse16x16_c(
     const unsigned char *src_ptr,
     int  source_stride,
     const unsigned char *ref_ptr,
     int  recon_stride,
--- a/media/libvpx/vp8/common/x86/filter_x86.c
+++ b/media/libvpx/vp8/common/x86/filter_x86.c
@@ -3,17 +3,17 @@
  *
  *  Use of this source code is governed by a BSD-style license
  *  that can be found in the LICENSE file in the root of the source
  *  tree. An additional intellectual property rights grant can 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/mem.h"
+#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 },
--- a/media/libvpx/vp8/common/x86/filter_x86.h
+++ b/media/libvpx/vp8/common/x86/filter_x86.h
@@ -6,14 +6,20 @@
  *  tree. An additional intellectual property rights grant can 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 FILTER_X86_H
 #define FILTER_X86_H
 
+#include "vpx_ports/mem.h"
+
 /* x86 assembly specific copy of vp8/common/filter.c:vp8_bilinear_filters with
  * duplicated values */
-extern const short vp8_bilinear_filters_x86_4[8][8];  /* duplicated 4x */
-extern const short vp8_bilinear_filters_x86_8[8][16]; /* duplicated 8x */
+
+/* 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]);
 
 #endif /* FILTER_X86_H */
--- a/media/libvpx/vp8/common/x86/idct_blk_mmx.c
+++ b/media/libvpx/vp8/common/x86/idct_blk_mmx.c
@@ -4,18 +4,19 @@
  *  Use of this source code is governed by a BSD-style license
  *  that can be found in the LICENSE file in the root of the source
  *  tree. An additional intellectual property rights grant can 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_rtcd.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;
 
@@ -30,44 +31,44 @@ void vp8_dequant_idct_add_y_block_mmx
 
     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);
-            ((int *)q)[0] = 0;
+            vpx_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);
-            ((int *)(q+16))[0] = 0;
+            vpx_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);
-            ((int *)(q+32))[0] = 0;
+            vpx_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);
-            ((int *)(q+48))[0] = 0;
+            vpx_memset(q + 48, 0, 2 * sizeof(q[0]));
         }
 
         q    += 64;
         dst  += 4*stride;
         eobs += 4;
     }
 }
 
@@ -79,49 +80,49 @@ void vp8_dequant_idct_add_uv_block_mmx
 
     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);
-            ((int *)q)[0] = 0;
+            vpx_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);
-            ((int *)(q+16))[0] = 0;
+            vpx_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);
-            ((int *)q)[0] = 0;
+            vpx_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);
-            ((int *)(q+16))[0] = 0;
+            vpx_memset(q + 16, 0, 2 * sizeof(q[0]));
         }
 
         q    += 32;
         dstv += 4*stride;
         eobs += 2;
     }
 }
--- a/media/libvpx/vp8/common/x86/idct_blk_sse2.c
+++ b/media/libvpx/vp8/common/x86/idct_blk_sse2.c
@@ -4,17 +4,17 @@
  *  Use of this source code is governed by a BSD-style license
  *  that can be found in the LICENSE file in the root of the source
  *  tree. An additional intellectual property rights grant can 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_rtcd.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);
 
--- a/media/libvpx/vp8/common/x86/iwalsh_mmx.asm
+++ b/media/libvpx/vp8/common/x86/iwalsh_mmx.asm
@@ -19,17 +19,17 @@ sym(vp8_short_inv_walsh4x4_mmx):
     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]
-    movd        mm7, rax
+    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
--- a/media/libvpx/vp8/common/x86/loopfilter_block_sse2.asm
+++ b/media/libvpx/vp8/common/x86/loopfilter_block_sse2.asm
@@ -131,17 +131,17 @@
 ;    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):
 
-%ifidn __OUTPUT_FORMAT__,x64
+%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
@@ -251,17 +251,17 @@ LF_FILTER_HEV_MASK xmm4, xmm8, xmm0, xmm
         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
 
-%ifidn __OUTPUT_FORMAT__,x64
+%if LIBVPX_YASM_WIN64
     pop    r13
     pop    r12
     RESTORE_XMM
     pop    rbp
 %endif
 
     ret
 
@@ -273,17 +273,17 @@ LF_FILTER xmm0, xmm1, xmm3, xmm8, xmm4, 
 ;    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):
 
-%ifidn __OUTPUT_FORMAT__,x64
+%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
@@ -774,17 +774,17 @@ LF_FILTER xmm0, xmm1, xmm4, xmm8, xmm3, 
         movdqa      s15, xmm15
 
     ; free stack space
     add          rsp, stack_size
 
     ; un-ALIGN_STACK
     pop          rsp
 
-%ifidn __OUTPUT_FORMAT__,x64
+%if LIBVPX_YASM_WIN64
     pop    r13
     pop    r12
     RESTORE_XMM
     pop    rbp
 %endif
 
     ret
 
--- a/media/libvpx/vp8/common/x86/mfqe_sse2.asm
+++ b/media/libvpx/vp8/common/x86/mfqe_sse2.asm
@@ -266,16 +266,22 @@ sym(vp8_variance_and_sad_16x16_sse2):
     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
 
--- a/media/libvpx/vp8/common/x86/postproc_mmx.asm
+++ b/media/libvpx/vp8/common/x86/postproc_mmx.asm
@@ -56,17 +56,17 @@ sym(vp8_mbpost_proc_down_mmx):
             mov         rdx,        arg(2)
             sub         rdx,        9
             imul        rdx,        rax
             lea         rdi,        [rdi+rdx]
             movq        mm1,        QWORD ptr[rdi]              ; first row
             mov         rcx,        8
 .init_borderd                                                    ; initialize borders
             lea         rdi,        [rdi + rax]
-            movq        [rdi],      xmm1
+            movq        [rdi],      mm1
 
             dec         rcx
             jne         .init_borderd
 
             neg         rax                                     ; rax = -pitch
 
             ; this copies the first row up into the border 8 rows
             mov         rdi,        rsi
@@ -188,17 +188,16 @@ sym(vp8_mbpost_proc_down_mmx):
             movq        mm4,        [rax + rcx*2] ;vp8_rv[rcx*2]
             pop         rax
 %elif ABI_IS_32BIT=0
             movq        mm4,        [r8 + rcx*2] ;vp8_rv[rcx*2]
 %else
             movq        mm4,        [sym(vp8_rv) + rcx*2]
 %endif
             paddw       mm1,        mm4
-            ;paddw     xmm1,       eight8s
             psraw       mm1,        4
 
             packuswb    mm1,        mm0
             pand        mm1,        mm3
 
             pandn       mm3,        mm2
             por         mm1,        mm3
 
--- a/media/libvpx/vp8/common/x86/recon_wrapper_sse2.c
+++ b/media/libvpx/vp8/common/x86/recon_wrapper_sse2.c
@@ -4,17 +4,17 @@
  *  Use of this source code is governed by a BSD-style license
  *  that can be found in the LICENSE file in the root of the source
  *  tree. An additional intellectual property rights grant can 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_rtcd.h"
+#include "vp8_rtcd.h"
 #include "vpx_mem/vpx_mem.h"
 #include "vp8/common/blockd.h"
 
 #define build_intra_predictors_mbuv_prototype(sym) \
     void sym(unsigned char *dst, int dst_stride, \
              const unsigned char *above, \
              const unsigned char *left, int left_stride)
 typedef build_intra_predictors_mbuv_prototype((*build_intra_predictors_mbuv_fn_t));
--- a/media/libvpx/vp8/common/x86/sad_sse3.asm
+++ b/media/libvpx/vp8/common/x86/sad_sse3.asm
@@ -28,17 +28,17 @@
     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
-  %ifidn __OUTPUT_FORMAT__,x64
+  %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]
@@ -71,17 +71,17 @@
   %define     height
 
 %if ABI_IS_32BIT
     pop         rbx
     pop         rdi
     pop         rsi
     pop         rbp
 %else
-  %ifidn __OUTPUT_FORMAT__,x64
+  %if LIBVPX_YASM_WIN64
     RESTORE_XMM
   %endif
 %endif
     ret
 %endmacro
 
 %