Skip to content

libvmaf/adm: do not left-shift negative filter taps in adm_dwt2_16_avx2/avx512 - #1727

Open
lusoris wants to merge 1 commit into
Netflix:masterfrom
vidiko:fix/adm-dwt2-16-tap-shift
Open

lusoris wants to merge 1 commit into
Netflix:masterfrom
vidiko:fix/adm-dwt2-16-tap-shift

Conversation

@lusoris

@lusoris lusoris commented Nov 18, 2026

Copy link
Copy Markdown

adm_dwt2_16_avx2() and adm_dwt2_16_avx512() pack two int16_t filter taps into one 32-bit lane with (uint32_t)(filter_lo[k] << 16). Three of the taps that go through this expression are negative (-4240, -7345, -15826), and left-shifting a negative int is undefined behaviour. This is one of the two concerns PR 1601 mixed together; the vertical-pass sum goes in a separate PR.

Fix

Convert the tap to uint32_t before the shift: ((uint32_t)filter_lo[k] << 16). Eight lines, four in each file. The packed constants are the same.

Before and after

UBSan build (-Db_sanitize=undefined), 16-bit 576x324 pair src01_hrc00/src01_hrc01 (yuv420p16le, from the clips that lived in python/test/resource/yuv before bac8b607), --feature adm:

master cf677baa this branch
"left shift of negative value" reports, AVX-512 path (default dispatch on the test host) 3 0
same, AVX2 path (--cpumask 16) 3 0
ADM scores, release build reference byte-equal JSON

The reports on master are at adm_avx2.c:2923-2925 and adm_avx512.c:3012-3014.

Tests

No test added. In a release build with GCC 16.2.1 the disassembly of both functions is identical before and after the change, so no value-based test can tell the two apart; the UBSan run above is the evidence.

Validation

  • x86-64 Linux, GCC 16.2.1, release build on master cf677baa: the libvmaf unit suite passes 27 of 27.
  • CI on a fork branch with this commit plus one fork-only commit that pins the workflow actions to commit SHAs (the fork requires pinned actions): libvmaf, Windows, Docker, ffmpeg, checkasm, all green.

…x2/avx512

The 16-bit DWT packs two int16_t taps into one 32-bit lane with
(uint32_t)(filter[k] << 16). Three of the taps are negative, and
shifting a negative int is undefined. Convert to uint32_t before
shifting; the packed constants are unchanged.

Signed-off-by: Lusoris <lusoris@pm.me>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant