Skip to content

Optimize SSE2 temporal-filter invariant calculations - #5315

Open
chengchen-google wants to merge 1 commit into
AOMediaCodec:av2-encfrom
chengchen-google:0824/0002_x86_sse2_temporal_filter_invariants
Open

Optimize SSE2 temporal-filter invariant calculations#5315
chengchen-google wants to merge 1 commit into
AOMediaCodec:av2-encfrom
chengchen-google:0824/0002_x86_sse2_temporal_filter_invariants

Conversation

@chengchen-google

@chengchen-google chengchen-google commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Precompute decay, normalization, motion-distance, and block-error
factors outside the per-pixel loops.

Align SSE2 implementation with C function to support 64x64 blocks
(TF_BLOCK_SIZE = BLOCK_64X64, 16 subblocks), enabling SSE2 SIMD
dispatch in the temporal filter.

Instantiate HBDTemporalFilterTest for C vs SSE2 in test/temporal_filter_test.cc.

Unit tests show that SSE2 is ~2.6x faster than C (61-62% reduction),
1.5-2x faster than the original SSE2.

[ RUN ] SSE2/HBDTemporalFilterTest.DISABLED_Speed/0
ref_time=2562927 us | tst_time=1012646 us | gain=2.53x (60.5% reduction) width=64 height=64
ref_time=2317598 us | tst_time=881671 us | gain=2.63x (62.0% reduction) width=64 height=64
ref_time=2431593 us | tst_time=954904 us | gain=2.55x (60.7% reduction) width=64 height=64

@chengchen-google
chengchen-google force-pushed the 0824/0002_x86_sse2_temporal_filter_invariants branch from af0b827 to 4ee3e2f Compare August 25, 2026 19:59
@chengchen-google
chengchen-google force-pushed the 0824/0002_x86_sse2_temporal_filter_invariants branch 2 times, most recently from f908b88 to 83a0ff7 Compare August 25, 2026 23:57

@yunqingwang1 yunqingwang1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

@jjustiss-apple jjustiss-apple left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, only two minor non-blocking comments.

if (plane > PLANE_TYPE_Y) assert(chroma_sq_error != NULL);

uint32_t acc_5x5_sse[BH][BW];
uint32_t acc_5x5_sse[BH][BW] = { 0 };

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does acc_5x5_sse need to be zero-init'd?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It aims to silence static analysis warning.

Comment thread test/temporal_filter_test.cc Outdated
const MV subblock_mvs[16] = { { 0, 0 }, { 1, 2 }, { 2, 1 }, { 3, 3 },
{ 5, 5 }, { 4, 6 }, { 6, 4 }, { 7, 7 },
{ 7, 8 }, { 8, 7 }, { 9, 6 }, { 6, 9 },
{ 2, 10 }, { 10, 2 }, { 11, 4 }, { 4, 11 } };

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor suggestion: with min_frame_size=360 and TF_SEARCH_DISTANCE_THRESHOLD=0.1 and distance_threshold=36, the largest MV magnitude is ~11.7, so d_factor = max(distance/36, 1) gets clamped to 1.0. This results in the distance-scaling path going untested. Would adding a large MV test (e.g. {30, 30} -> d_factor = 1.18) be useful to increase coverage?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion. Done.

Precompute decay, normalization, motion-distance, and block-error
factors outside the per-pixel loops.

Align SSE2 implementation with C function to support 64x64 blocks
(TF_BLOCK_SIZE = BLOCK_64X64, 16 subblocks), enabling SSE2 SIMD
dispatch in the temporal filter.

Instantiate HBDTemporalFilterTest for C vs SSE2 in test/temporal_filter_test.cc.

Unit tests show that SSE2 is ~2.6x faster than C (61-62% reduction),
1.5-2x faster than the original SSE2.

[ RUN      ] SSE2/HBDTemporalFilterTest.DISABLED_Speed/0
ref_time=2562927 us | tst_time=1012646 us | gain=2.53x (60.5% reduction) width=64 height=64
ref_time=2317598 us | tst_time=881671 us  | gain=2.63x (62.0% reduction) width=64 height=64
ref_time=2431593 us | tst_time=954904 us  | gain=2.55x (60.7% reduction) width=64 height=64

Change-Id: Ie7e18dd919eb8c14527c2be1506a3f78bcce6c65
@chengchen-google
chengchen-google force-pushed the 0824/0002_x86_sse2_temporal_filter_invariants branch from 83a0ff7 to c9f81f6 Compare August 26, 2026 17:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants