Add AVX2 SAD and SadFour functions for motion estimation#3933
Open
rbenaley wants to merge 1 commit intocisco:masterfrom
Open
Add AVX2 SAD and SadFour functions for motion estimation#3933rbenaley wants to merge 1 commit intocisco:masterfrom
rbenaley wants to merge 1 commit intocisco:masterfrom
Conversation
Implement AVX2-optimized SAD for block sizes 16x16, 16x8, 8x16, 8x8 (simple and SadFour variants). The 16-wide functions use vinserti128 to pack two rows into a ymm register, processing them with a single vpsadbw. SadFour variants compute SAD against four reference positions simultaneously, avoiding redundant source loads during diamond search. All code is guarded by %ifdef HAVE_AVX2 / WELS_CPU_AVX2 and selected at runtime via CPUID detection.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This adds AVX2-optimized SAD functions for the block sizes used in motion estimation: 16x16, 16x8, 8x16, and 8x8, in both simple and SadFour (4-reference) variants.
The existing SATD functions already have AVX2 implementations in
satd_sad.asm, but the corresponding SAD functions were missing. The SadFour variants are critical for the diamond search pattern, where computing SAD against four neighbor positions in a single call avoids redundant source block loads.The 16-wide functions use
vinserti128to pack two rows into a 256-bitymmregister, processing them with a singlevpsadbw. All loops are fully unrolled with%rep.Files changed:
codec/common/x86/satd_sad.asm— 8 functions + 5 macros (+386 lines)codec/common/inc/sad_common.h— declarations (+12 lines)codec/encoder/core/src/sample.cpp— function pointer registration (+11 lines)These optimizations were developed for Vauban, an open-source privileged access management (PAM) bastion that uses OpenH264 for real-time H.264 encoding of RDP desktop sessions streamed to web browsers. Enabling AVX2 across the encoder (including these new SAD functions) reduced CPU usage per session by approximately 50% on an Intel Xeon E-2246G running FreeBSD.
For a detailed technical writeup covering the encoding pipeline context, implementation choices, and performance measurements, see:
https://github.com/rbenaley/Vauban/blob/main/docs/technical/Vauban_OpenH264_AVX2_Optimizations_EN(1.0).md