load("@rules_cc//cc:cc_library.bzl", "cc_library")

package(
    default_visibility = [
        "//visibility:private",
    ],
)

libvpx_generic_c_srcs = [
    "vp8/common/vp8_loopfilter.c",
    "vpx_dsp/sum_squares.c",
    "vp9/encoder/vp9_tpl_model.c",
    "vp9/decoder/vp9_decodemv.c",
    "vp9/encoder/vp9_tokenize.c",
    "vpx_dsp/loopfilter.c",
    "vp9/common/vp9_alloccommon.c",
    "vp9/common/vp9_filter.c",
    "vp8/common/reconinter.c",
    "vpx_util/vpx_write_yuv_frame.c",
    "vp8/common/blockd.c",
    "vp9/encoder/vp9_picklpf.c",
    "vp8/common/swapyv12buffer.c",
    "vp8/encoder/denoising.c",
    "vp9/common/vp9_quant_common.c",
    "vp9/encoder/vp9_frame_scale.c",
    "vpx_scale/vpx_scale_rtcd.c",
    "vp9/encoder/vp9_ext_ratectrl.c",
    "vpx_dsp/inv_txfm.c",
    "vp8/common/treecoder.c",
    "vp9/encoder/vp9_aq_cyclicrefresh.c",
    "vpx_scale/generic/gen_scalers.c",
    "vpx_dsp/skin_detection.c",
    "vpx_dsp/sad.c",
    "vp9/encoder/vp9_dct.c",
    "vp9/common/vp9_thread_common.c",
    "vp9/encoder/vp9_speed_features.c",
    "vp8/vp8_dx_iface.c",
    "vp8/encoder/lookahead.c",
    "vpx_dsp/avg.c",
    "vp8/encoder/encodemb.c",
    "vp8/encoder/encodemv.c",
    "vpx/src/vpx_image.c",
    "vpx_mem/vpx_mem.c",
    "vp9/common/vp9_blockd.c",
    "vp8/decoder/decodemv.c",
    "vpx/src/vpx_codec.c",
    "vp9/encoder/vp9_encodeframe.c",
    "vp8/encoder/treewriter.c",
    "vp9/encoder/vp9_pickmode.c",
    "vpx_dsp/sse.c",
    "vp9/decoder/vp9_dsubexp.c",
    "vpx/src/vpx_decoder.c",
    "vp8/encoder/onyx_if.c",
    "vp9/encoder/vp9_rd.c",
    "vp8/encoder/rdopt.c",
    "vpx_dsp/bitreader.c",
    "vp9/common/vp9_frame_buffers.c",
    "vp8/common/mbpitch.c",
    "vp8/common/idctllm.c",
    "vp9/encoder/vp9_ratectrl.c",
    "vpx_dsp/fwd_txfm.c",
    "vp8/common/generic/systemdependent.c",
    "vpx_dsp/intrapred.c",
    "vp8/common/quant_common.c",
    "vp8/vp8_cx_iface.c",
    "vp8/encoder/ethreading.c",
    "vp8/encoder/encodeframe.c",
    "vp9/decoder/vp9_detokenize.c",
    "vp9/encoder/vp9_encodemv.c",
    "vp9/encoder/vp9_quantize.c",
    "vp8/encoder/modecosts.c",
    "vp9/encoder/vp9_skin_detection.c",
    "vp8/encoder/picklpf.c",
    "vp8/encoder/ratectrl.c",
    "vp9/common/vp9_common_data.c",
    "vp9/encoder/vp9_ethread.c",
    "vp8/encoder/boolhuff.c",
    "vpx/src/vpx_encoder.c",
    "vp9/common/vp9_scan.c",
    "vp9/common/vp9_seg_common.c",
    "vpx_dsp/subtract.c",
    "vp9/encoder/vp9_subexp.c",
    "vpx_dsp/prob.c",
    "vp9/decoder/vp9_decoder.c",
    "vp9/decoder/vp9_decodeframe.c",
    "vp8/common/rtcd.c",
    "vp9/common/vp9_scale.c",
    "vp8/decoder/threading.c",
    "vp8/encoder/encodeintra.c",
    "vp9/encoder/vp9_lookahead.c",
    "vp8/common/reconintra.c",
    "vpx_dsp/variance.c",
    "vp9/encoder/vp9_noise_estimate.c",
    "vp8/common/modecont.c",
    "vp8/common/alloccommon.c",
    "vp9/common/vp9_reconintra.c",
    "vp8/common/dequantize.c",
    "vp9/common/vp9_tile_common.c",
    "vp9/encoder/vp9_bitstream.c",
    "vpx_dsp/quantize.c",
    "vp8/common/filter.c",
    "vp9/common/vp9_loopfilter.c",
    "vp8/encoder/vp8_quantize.c",
    "vp8/common/vp8_skin_detection.c",
    "vp8/encoder/tokenize.c",
    "vp9/common/vp9_rtcd.c",
    "vp8/encoder/bitstream.c",
    "vp8/common/findnearmv.c",
    "vpx_scale/generic/yv12config.c",
    "vp9/encoder/vp9_svc_layercontext.c",
    "vp9/vp9_iface_common.c",
    "vp9/common/vp9_reconinter.c",
    "vp9/decoder/vp9_job_queue.c",
    "vpx_dsp/bitreader_buffer.c",
    "vp8/common/reconintra4x4.c",
    "vp8/decoder/detokenize.c",
    "vpx_util/vpx_thread.c",
    "vp9/encoder/vp9_encoder.c",
    "vp9/encoder/vp9_segmentation.c",
    "vp8/common/entropy.c",
    "vp8/decoder/onyxd_if.c",
    "vp9/encoder/vp9_mcomp.c",
    "vp9/encoder/vp9_cost.c",
    "vp9/encoder/vp9_context_tree.c",
    "vp9/encoder/vp9_extend.c",
    "vpx_dsp/bitwriter_buffer.c",
    "vp8/encoder/segmentation.c",
    "vp9/common/vp9_entropymode.c",
    "vpx_scale/generic/vpx_scale.c",
    "vp9/common/vp9_mvref_common.c",
    "vp8/common/entropymode.c",
    "vp8/encoder/mcomp.c",
    "vp8/decoder/decodeframe.c",
    "vp9/common/vp9_idct.c",
    "vpx_dsp/psnr.c",
    "vp8/encoder/pickinter.c",
    "vp9/vp9_dx_iface.c",
    "vp9/encoder/vp9_multi_thread.c",
    "vp8/common/loopfilter_filters.c",
    "vp8/common/extend.c",
    "vp9/common/vp9_pred_common.c",
    "vp9/encoder/vp9_resize.c",
    "vp9/encoder/vp9_rdopt.c",
    "vpx_scale/generic/yv12extend.c",
    "vp8/common/idct_blk.c",
    "vp8/decoder/dboolhuff.c",
    "vp9/common/vp9_entropy.c",
    "vp8/common/setupintrarecon.c",
    "vp8/encoder/copy_c.c",
    "vp9/encoder/vp9_encodemb.c",
    "vp9/common/vp9_entropymv.c",
    "vpx_dsp/vpx_convolve.c",
    "vpx_dsp/vpx_dsp_rtcd.c",
    "vpx_dsp/bitwriter.c",
    "vp9/vp9_cx_iface.c",
    "vp8/encoder/dct.c",
    "vp9/encoder/vp9_treewriter.c",
    "vp8/common/entropymv.c",
]

libvpx_arm64_neon_dotprod_c_srcs = [
    "vpx_dsp/arm/highbd_variance_neon_dotprod.c",
    "vpx_dsp/arm/sad4d_neon_dotprod.c",
    "vpx_dsp/arm/sad_neon_dotprod.c",
    "vpx_dsp/arm/sse_neon_dotprod.c",
    "vpx_dsp/arm/variance_neon_dotprod.c",
    "vpx_dsp/arm/vpx_convolve8_neon_dotprod.c",
]

libvpx_arm64_neon_i8mm_c_srcs = [
    "vpx_dsp/arm/vpx_convolve8_neon_i8mm.c",
]

libvpx_arm64_sve_c_srcs = [
    "vp9/encoder/arm/neon/vp9_error_sve.c",
    "vpx_dsp/arm/highbd_variance_sve.c",
    "vpx_dsp/arm/highbd_vpx_convolve8_sve.c",
    "vpx_dsp/arm/sum_squares_sve.c",
]

libvpx_arm64_sve2_c_srcs = [
    "vpx_dsp/arm/highbd_vpx_convolve8_sve2.c",
]

libvpx_arm64_c_srcs = libvpx_generic_c_srcs + [
    "vpx_dsp/arm/highbd_loopfilter_neon.c",
    "vpx_dsp/arm/idct8x8_1_add_neon.c",
    "vp8/common/arm/neon/iwalsh_neon.c",
    "vp8/common/arm/neon/idct_blk_neon.c",
    "vp9/encoder/arm/neon/vp9_quantize_neon.c",
    "vp9/common/arm/neon/vp9_iht8x8_add_neon.c",
    "vp8/common/arm/neon/loopfiltersimplehorizontaledge_neon.c",
    "vpx_dsp/arm/fdct32x32_neon.c",
    "vpx_dsp/arm/vpx_convolve8_neon.c",
    "vpx_dsp/arm/highbd_sad_neon.c",
    "vp8/encoder/arm/neon/fastquantizeb_neon.c",
    "vp8/common/arm/neon/dequant_idct_neon.c",
    "vpx_dsp/arm/idct32x32_add_neon.c",
    "vp8/encoder/arm/neon/denoising_neon.c",
    "vpx_dsp/arm/highbd_idct32x32_34_add_neon.c",
    "vpx_dsp/arm/avg_neon.c",
    "vpx_dsp/arm/variance_neon.c",
    "vpx_dsp/arm/loopfilter_neon.c",
    "vp8/common/arm/neon/vp8_loopfilter_neon.c",
    "vp8/common/arm/neon/dequantizeb_neon.c",
    "vpx_dsp/arm/subpel_variance_neon.c",
    "vpx_dsp/arm/sad4d_neon.c",
    "vp9/common/arm/neon/vp9_highbd_iht4x4_add_neon.c",
    "vpx_dsp/arm/idct4x4_1_add_neon.c",
    "vp9/encoder/arm/neon/vp9_highbd_error_neon.c",
    "vp8/common/arm/neon/bilinearpredict_neon.c",
    "vpx_dsp/arm/subtract_neon.c",
    "vpx_dsp/arm/idct32x32_34_add_neon.c",
    "vpx_dsp/arm/vpx_convolve_avg_neon.c",
    "vpx_dsp/arm/highbd_idct32x32_1024_add_neon.c",
    "vpx_dsp/arm/idct32x32_1_add_neon.c",
    "vpx_dsp/arm/highbd_idct4x4_add_neon.c",
    "vpx_dsp/arm/highbd_avg_pred_neon.c",
    "vpx_dsp/arm/idct16x16_add_neon.c",
    "vpx_dsp/arm/highbd_idct16x16_add_neon.c",
    "vp8/common/arm/neon/shortidct4x4llm_neon.c",
    "vp8/common/arm/neon/copymem_neon.c",
    "vpx_dsp/arm/highbd_intrapred_neon.c",
    "vpx_dsp/arm/highbd_avg_neon.c",
    "vpx_dsp/arm/fdct8x8_neon.c",
    "vpx_dsp/arm/hadamard_neon.c",
    "vpx_dsp/arm/highbd_hadamard_neon.c",
    "vpx_dsp/arm/vpx_scaled_convolve8_neon.c",
    "vp9/common/arm/neon/vp9_iht4x4_add_neon.c",
    "vp9/encoder/arm/neon/vp9_frame_scale_neon.c",
    "vpx_dsp/arm/vpx_convolve_copy_neon.c",
    "vp9/common/arm/neon/vp9_highbd_iht16x16_add_neon.c",
    "vp8/common/arm/neon/mbloopfilter_neon.c",
    "vp8/common/arm/neon/sixtappredict_neon.c",
    "vp9/common/arm/neon/vp9_highbd_iht8x8_add_neon.c",
    "vpx_dsp/arm/sum_squares_neon.c",
    "vpx_dsp/arm/highbd_idct32x32_135_add_neon.c",
    "vpx_dsp/arm/highbd_vpx_convolve_copy_neon.c",
    "vpx_dsp/arm/highbd_variance_neon.c",
    "vp9/encoder/arm/neon/vp9_dct_neon.c",
    "vpx_dsp/arm/highbd_idct32x32_add_neon.c",
    "vpx_dsp/arm/fdct16x16_neon.c",
    "vp9/encoder/arm/neon/vp9_error_neon.c",
    "vpx_dsp/arm/idct32x32_135_add_neon.c",
    "vpx_dsp/arm/intrapred_neon.c",
    "vpx_dsp/arm/highbd_idct8x8_add_neon.c",
    "vpx_dsp/arm/idct4x4_add_neon.c",
    "vpx_dsp/arm/avg_pred_neon.c",
    "vpx_ports/aarch64_cpudetect.c",
    "vp8/common/arm/neon/dc_only_idct_add_neon.c",
    "vpx_dsp/arm/highbd_quantize_neon.c",
    "vpx_dsp/arm/highbd_vpx_convolve8_neon.c",
    "vpx_dsp/arm/sad_neon.c",
    "vpx_dsp/arm/fdct4x4_neon.c",
    "vpx_dsp/arm/idct16x16_1_add_neon.c",
    "vpx_dsp/arm/highbd_sad4d_neon.c",
    "vpx_dsp/arm/highbd_vpx_convolve_avg_neon.c",
    "vpx_dsp/arm/vpx_convolve_neon.c",
    "vpx_dsp/arm/highbd_sse_neon.c",
    "vp8/common/arm/loopfilter_arm.c",
    "vpx_dsp/arm/idct8x8_add_neon.c",
    "vpx_dsp/arm/sse_neon.c",
    "vp9/common/arm/neon/vp9_iht16x16_add_neon.c",
    "vp9/encoder/arm/neon/vp9_diamond_search_sad_neon.c",
    "vpx_dsp/arm/fdct_partial_neon.c",
    "vp8/encoder/arm/neon/shortfdct_neon.c",
    "vpx_dsp/arm/highbd_subpel_variance_neon.c",
    "vp8/common/arm/neon/loopfiltersimpleverticaledge_neon.c",
    "vpx_dsp/arm/quantize_neon.c",
    "vp8/encoder/arm/neon/vp8_shortwalsh4x4_neon.c",
]

libvpx_x86_64_sse4_c_srcs = [
    "vp8/encoder/x86/quantize_sse4.c",
    "vp9/common/x86/vp9_highbd_iht4x4_add_sse4.c",
    "vp9/common/x86/vp9_highbd_iht8x8_add_sse4.c",
    "vp9/common/x86/vp9_highbd_iht16x16_add_sse4.c",
    "vpx_dsp/x86/highbd_idct4x4_add_sse4.c",
    "vpx_dsp/x86/highbd_idct8x8_add_sse4.c",
    "vpx_dsp/x86/highbd_idct16x16_add_sse4.c",
    "vpx_dsp/x86/highbd_idct32x32_add_sse4.c",
    "vpx_dsp/x86/sse_sse4.c",
]

libvpx_x86_64_avx_c_srcs = [
    "vpx_dsp/x86/quantize_avx.c",
]

libvpx_x86_64_avx2_c_srcs = [
    "vp9/encoder/x86/vp9_error_avx2.c",
    "vp9/encoder/x86/vp9_quantize_avx2.c",
    "vpx_dsp/x86/avg_intrin_avx2.c",
    "vpx_dsp/x86/avg_pred_avx2.c",
    "vpx_dsp/x86/highbd_convolve_avx2.c",
    "vpx_dsp/x86/highbd_quantize_intrin_avx2.c",
    "vpx_dsp/x86/highbd_sad4d_avx2.c",
    "vpx_dsp/x86/highbd_sad_avx2.c",
    "vpx_dsp/x86/inv_txfm_avx2.c",
    "vpx_dsp/x86/loopfilter_avx2.c",
    "vpx_dsp/x86/quantize_avx2.c",
    "vpx_dsp/x86/sad4d_avx2.c",
    "vpx_dsp/x86/sad_avx2.c",
    "vpx_dsp/x86/sse_avx2.c",
    "vpx_dsp/x86/subtract_avx2.c",
    "vpx_dsp/x86/variance_avx2.c",
    "vpx_dsp/x86/vpx_subpixel_8t_intrin_avx2.c",
]

libvpx_x86_64_avx512_c_srcs = [
    "vpx_dsp/x86/sad4d_avx512.c",
]

libvpx_x86_64_c_srcs = libvpx_generic_c_srcs + [
    "vpx_dsp/x86/highbd_intrapred_intrin_ssse3.c",
    "vpx_dsp/x86/highbd_quantize_intrin_sse2.c",
    "vpx_dsp/x86/sum_squares_sse2.c",
    "vpx_dsp/x86/quantize_sse2.c",
    "vpx_dsp/x86/highbd_idct32x32_add_sse2.c",
    "vpx_dsp/x86/highbd_idct8x8_add_sse2.c",
    "vp8/encoder/x86/vp8_quantize_ssse3.c",
    "vp9/encoder/x86/vp9_quantize_sse2.c",
    "vp8/common/x86/vp8_asm_stubs.c",
    "vp9/encoder/x86/vp9_dct_intrin_sse2.c",
    "vp9/encoder/x86/vp9_frame_scale_ssse3.c",
    "vpx_dsp/x86/highbd_variance_sse2.c",
    "vp9/common/x86/vp9_idct_intrin_sse2.c",
    "vpx_dsp/x86/fwd_txfm_sse2.c",
    "vp8/common/x86/idct_blk_sse2.c",
    "vp8/common/x86/bilinear_filter_sse2.c",
    "vpx_dsp/x86/highbd_loopfilter_sse2.c",
    "vpx_dsp/x86/vpx_subpixel_8t_intrin_ssse3.c",
    "vpx_dsp/x86/loopfilter_sse2.c",
    "vpx_dsp/x86/inv_txfm_sse2.c",
    "vpx_dsp/x86/variance_sse2.c",
    "vpx_dsp/x86/avg_pred_sse2.c",
    "vpx_dsp/x86/vpx_subpixel_4t_intrin_sse2.c",
    "vpx_dsp/x86/highbd_intrapred_intrin_sse2.c",
    "vpx_dsp/x86/avg_intrin_sse2.c",
    "vp8/encoder/x86/vp8_enc_stubs_sse2.c",
    "vp8/encoder/x86/denoising_sse2.c",
    "vpx_dsp/x86/post_proc_sse2.c",
    "vp8/common/postproc.c",
    "vp8/common/x86/idct_blk_mmx.c",
    "vp9/encoder/x86/vp9_highbd_block_error_intrin_sse2.c",
    "vpx_dsp/deblock.c",
    "vpx_dsp/x86/highbd_idct4x4_add_sse2.c",
    "vpx_dsp/x86/highbd_idct16x16_add_sse2.c",
    "vpx_dsp/x86/quantize_ssse3.c",
    "vpx_dsp/x86/inv_txfm_ssse3.c",
    "vp8/common/mfqe.c",
    "vp8/encoder/x86/vp8_quantize_sse2.c",
    "vp8/common/x86/loopfilter_x86.c",
    "vpx_dsp/add_noise.c",
    "vp9/encoder/x86/vp9_quantize_ssse3.c",
]

libvpx_x86_64_asm_srcs = [
    "third_party/x86inc/x86inc.asm",
    "vp8/common/x86/dequantize_mmx.asm",
    "vp8/common/x86/idctllm_mmx.asm",
    "vp8/common/x86/idctllm_sse2.asm",
    "vp8/common/x86/iwalsh_sse2.asm",
    "vp8/common/x86/loopfilter_block_sse2_x86_64.asm",
    "vp8/common/x86/loopfilter_sse2.asm",
    "vp8/common/x86/mfqe_sse2.asm",
    "vp8/common/x86/recon_mmx.asm",
    "vp8/common/x86/recon_sse2.asm",
    "vp8/common/x86/subpixel_mmx.asm",
    "vp8/common/x86/subpixel_sse2.asm",
    "vp8/common/x86/subpixel_ssse3.asm",
    "vp8/encoder/x86/block_error_sse2.asm",
    "vp8/encoder/x86/copy_sse2.asm",
    "vp8/encoder/x86/copy_sse3.asm",
    "vp8/encoder/x86/dct_sse2.asm",
    "vp8/encoder/x86/fwalsh_sse2.asm",
    "vp9/encoder/x86/vp9_dct_sse2.asm",
    "vp9/encoder/x86/vp9_error_sse2.asm",
    "vpx_dsp/x86/add_noise_sse2.asm",
    "vpx_dsp/x86/avg_ssse3_x86_64.asm",
    "vpx_dsp/x86/bitdepth_conversion_sse2.asm",
    "vpx_dsp/x86/deblock_sse2.asm",
    "vpx_dsp/x86/fwd_txfm_ssse3_x86_64.asm",
    "vpx_dsp/x86/highbd_intrapred_sse2.asm",
    "vpx_dsp/x86/highbd_sad4d_sse2.asm",
    "vpx_dsp/x86/highbd_sad_sse2.asm",
    "vpx_dsp/x86/highbd_subpel_variance_impl_sse2.asm",
    "vpx_dsp/x86/highbd_variance_impl_sse2.asm",
    "vpx_dsp/x86/intrapred_sse2.asm",
    "vpx_dsp/x86/intrapred_ssse3.asm",
    "vpx_dsp/x86/inv_wht_sse2.asm",
    "vpx_dsp/x86/sad4d_sse2.asm",
    "vpx_dsp/x86/sad_sse2.asm",
    "vpx_dsp/x86/ssim_opt_x86_64.asm",
    "vpx_dsp/x86/subpel_variance_sse2.asm",
    "vpx_dsp/x86/subtract_sse2.asm",
    "vpx_dsp/x86/vpx_convolve_copy_sse2.asm",
    "vpx_dsp/x86/vpx_high_subpixel_8t_sse2.asm",
    "vpx_dsp/x86/vpx_high_subpixel_bilinear_sse2.asm",
    "vpx_dsp/x86/vpx_subpixel_8t_sse2.asm",
    "vpx_dsp/x86/vpx_subpixel_8t_ssse3.asm",
    "vpx_dsp/x86/vpx_subpixel_bilinear_sse2.asm",
    "vpx_dsp/x86/vpx_subpixel_bilinear_ssse3.asm",
    "vpx_ports/emms_mmx.asm",
    "vpx_ports/x86_abi_support.asm",
]

libvpx_x86_64_asm_objs = [f + ".o" for f in libvpx_x86_64_asm_srcs]

libvpx_common_c_hdrs = glob([
    "vp8/common/*.h",
    "vp8/decoder/*.h",
    "vp8/encoder/*.h",
    "vp9/vp9_*.h",
    "vp9/common/vp9_*.h",
    "vp9/decoder/vp9_*.h",
    "vp9/encoder/vp9_*.h",
    "vpx/*.h",
    "vpx/internal/vpx_*.h",
    "vpx_dsp/*.h",
    "vpx_mem/include/vpx_*.h",
    "vpx_mem/vpx_*.h",
    "vpx_ports/*.h",
    "vpx_scale/*.h",
    "vpx_util/*.h",
])

libvpx_x86_64_c_hdrs = glob([
    "vpx_dsp/x86/*.h",
])

libvpx_config_c_srcs = [
    "vp8_rtcd.h",
    "vp9_rtcd.h",
    "vpx_config.c",
    "vpx_config.h",
    "vpx_dsp_rtcd.h",
    "vpx_scale_rtcd.h",
    "vpx_version.h",
]

config_cmd_template = " && ".join([
    "$(location @//build_external/libvpx:genconfigs.sh) $$(dirname $(location video_common.h))",
    "cp config/ARCHITECTURE/* $(RULEDIR)",
])

genrule(
    name = "libvpx_config",
    srcs = glob(["**/*"]),
    outs = libvpx_config_c_srcs + [
        "vpx_config.asm",
    ],
    cmd = select({
        "@platforms//cpu:aarch64": config_cmd_template.replace("ARCHITECTURE", "arm64"),
        "@platforms//cpu:x86_64": config_cmd_template.replace("ARCHITECTURE", "x86_64"),
        "//conditions:default": config_cmd_template.replace("ARCHITECTURE", "generic"),
    }),
    tools = [
        "@//build_external/libvpx:genconfigs.sh",
        "@//build_external/libvpx:lint_config.sh",
    ],
)

cc_library(
    name = "libvpx_avx",
    srcs = select({
        "@platforms//cpu:x86_64": libvpx_x86_64_avx_c_srcs + libvpx_x86_64_c_hdrs,
        "//conditions:default": [],
    }) + libvpx_common_c_hdrs + libvpx_config_c_srcs,
    copts = [
        "-O3",
        "-Xclang -target-feature",
        "-Xclang +avx",
    ],
)

cc_library(
    name = "libvpx_avx2",
    srcs = select({
        "@platforms//cpu:x86_64": libvpx_x86_64_avx2_c_srcs + libvpx_x86_64_c_hdrs,
        "//conditions:default": [],
    }) + libvpx_common_c_hdrs + libvpx_config_c_srcs,
    copts = [
        "-O3",
        "-Xclang -target-feature",
        "-Xclang +avx2",
    ],
)

cc_library(
    name = "libvpx_avx512",
    srcs = select({
        "@platforms//cpu:x86_64": libvpx_x86_64_avx512_c_srcs + libvpx_x86_64_c_hdrs,
        "//conditions:default": [],
    }) + libvpx_common_c_hdrs + libvpx_config_c_srcs,
    copts = [
        "-O3",
        "-Xclang -target-feature",
        "-Xclang +avx512f",
        "-Xclang -target-feature",
        "-Xclang +avx512cd",
        "-Xclang -target-feature",
        "-Xclang +avx512bw",
        "-Xclang -target-feature",
        "-Xclang +avx512dq",
        "-Xclang -target-feature",
        "-Xclang +avx512vl",
    ],
)

libvpx_arm_c_hdrs = glob([
    "vpx_dsp/arm/*.h",
    "vp8/common/arm/*.h",
    "vp9/common/arm/neon/*.h",
])

cc_library(
    name = "libvpx_neon_dotprod",
    srcs = select({
        "@platforms//cpu:aarch64": libvpx_arm64_neon_dotprod_c_srcs + libvpx_arm_c_hdrs,
        "//conditions:default": [],
    }) + libvpx_common_c_hdrs + libvpx_config_c_srcs,
    copts = [
        "-O3",
        "-Xclang -target-feature",
        "-Xclang +dotprod",
    ],
)

cc_library(
    name = "libvpx_neon_i8mm",
    srcs = select({
        "@platforms//cpu:aarch64": libvpx_arm64_neon_i8mm_c_srcs + libvpx_arm_c_hdrs,
        "//conditions:default": [],
    }) + libvpx_common_c_hdrs + libvpx_config_c_srcs,
    copts = [
        "-O3",
        "-Xclang -target-feature",
        "-Xclang +dotprod",
        "-Xclang -target-feature",
        "-Xclang +i8mm",
    ],
)

cc_library(
    name = "libvpx_sse4",
    srcs = select({
        "@platforms//cpu:x86_64": libvpx_x86_64_sse4_c_srcs + libvpx_x86_64_c_hdrs,
        "//conditions:default": [],
    }) + libvpx_common_c_hdrs + libvpx_config_c_srcs,
    copts = [
        "-O3",
        "-Xclang -target-feature",
        "-Xclang +sse4.1",
    ],
)

cc_library(
    name = "libvpx_sve",
    srcs = select({
        "@platforms//cpu:aarch64": libvpx_arm64_sve_c_srcs + libvpx_arm_c_hdrs,
        "//conditions:default": [],
    }) + libvpx_common_c_hdrs + libvpx_config_c_srcs,
    copts = [
        "-O3",
        "-Xclang -target-feature",
        "-Xclang +dotprod",
        "-Xclang -target-feature",
        "-Xclang +i8mm",
        "-Xclang -target-feature",
        "-Xclang +sve",
    ],
)

cc_library(
    name = "libvpx_sve2",
    srcs = select({
        "@platforms//cpu:aarch64": libvpx_arm64_sve2_c_srcs + libvpx_arm_c_hdrs,
        "//conditions:default": [],
    }) + libvpx_common_c_hdrs + libvpx_config_c_srcs,
    copts = [
        "-O3",
        "-Xclang -target-feature",
        "-Xclang +dotprod",
        "-Xclang -target-feature",
        "-Xclang +i8mm",
        "-Xclang -target-feature",
        "-Xclang +sve",
        "-Xclang -target-feature",
        "-Xclang +sve2",
    ],
)

genrule(
    name = "libvpx_x86_64_asm_build",
    srcs = libvpx_x86_64_asm_srcs + ["vpx_config.asm"],
    outs = libvpx_x86_64_asm_objs,
    cmd = " && ".join([
        "mkdir -p $$(dirname $(RULEDIR)/" + f + ") && " +
        "$(location @nasm) -f elf64 -I$$(dirname $(location vpx_ports/x86_abi_support.asm))/../ " +
        "-I\"$$(dirname $(location vpx_config.asm))\"/ " +
        "-o $(RULEDIR)/" + f + ".o $(location " + f + ")"
        for f in libvpx_x86_64_asm_srcs
    ]),
    tools = ["@nasm"],
)

cc_library(
    name = "libvpx_asm",
    srcs = select({
        "@platforms//cpu:x86_64": libvpx_x86_64_asm_objs,
    }),
    target_compatible_with = select({
        "@platforms//cpu:x86_64": [],
        "//conditions:default": ["@platforms//:incompatible"],
    }),
)

cc_library(
    name = "libvpx",
    srcs = select({
        "@platforms//cpu:aarch64": libvpx_arm64_c_srcs,
        "@platforms//cpu:x86_64": libvpx_x86_64_c_srcs + libvpx_x86_64_c_hdrs,
        "//conditions:default": libvpx_generic_c_srcs,
    }) + libvpx_common_c_hdrs + libvpx_config_c_srcs,
    hdrs = [
        "vpx/vp8.h",
        "vpx/vp8cx.h",
        "vpx/vp8dx.h",
        "vpx/vpx_codec.h",
        "vpx/vpx_decoder.h",
        "vpx/vpx_encoder.h",
        "vpx/vpx_ext_ratectrl.h",
        "vpx/vpx_frame_buffer.h",
        "vpx/vpx_image.h",
        "vpx/vpx_integer.h",
        "vpx/vpx_tpl.h",
    ],
    copts = [
        "-O3",
        "-Wno-unused-parameter",
    ] + select({
        "@platforms//cpu:x86_64": [
            "-mssse3",
        ],
        "//conditions:default": [],
    }),
    includes = ["."],
    visibility = ["//visibility:public"],
    deps = select({
        "@platforms//cpu:aarch64": [
            ":libvpx_neon_dotprod",
            ":libvpx_neon_i8mm",
            ":libvpx_sve",
            ":libvpx_sve2",
        ],
        "@platforms//cpu:x86_64": [
            ":libvpx_asm",
            ":libvpx_avx",
            ":libvpx_avx2",
            ":libvpx_avx512",
            ":libvpx_sse4",
        ],
        "//conditions:default": [],
    }),
)
