Repository navigation
Conversation
adm_cm cubes the masked coefficient as (x_sq * x + round) >> shift on a 64-bit product. The C code shifts a signed int64_t; the AVX2 path used _mm256_srli_epi64, a logical shift. The two differ when the product is negative, which happens when the rounded square passes INT32_MAX and wraps in its 32-bit lane. Use the existing sra_epi64 helper so the AVX2 result matches the C code for every input. Applies to the scale 0 macro (both 64-bit halves) and the macro of scales 1 to 3. check_adm gains cases that put the rounded square on both sides of INT32_MAX at scale 0 and above it at scales 1 to 3. The inputs are synthetic: they exercise the arithmetic, not a decoded frame. With the logical shift each of these cases fails against the C reference. Signed-off-by: Lusoris <lusoris@pm.me>
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.
The AVX2 path of
adm_cmshifts the 64-bit cube product with a logical shift where the C code shifts a signed value. This is the second concern split out of PR 1602; the threshold-width change is PR 1728.The defect
adm_cmcubes the masked coefficient as(x_sq * x + round) >> shift, withx_sqthe rounded square held in a 32-bit lane. The C code does this on a signedint64_t. The two AVX2 macros use_mm256_srli_epi64, which shifts zeros in from the top. The results differ when the product is negative, and that happens when the rounded square is aboveINT32_MAXand wraps in its lane.Fix
Use the
sra_epi64helper thatadm_avx2.calready has, in the scale 0 macro (both 64-bit halves) and in the macro of scales 1 to 3. Three lines change. The AVX-512 path already uses_mm512_srai_epi64there.Can a real frame reach it?
I did not find one, and for the default options a bound on the coefficient range says no: with 8- to 16-bit input the largest rounded square stays below
INT32_MAXat every scale (the closest is scale 3 at 2109771130 against 2147483647).That bound does not hold for every option value. With
adm_csf_mode=1andadm_norm_view_dist=24the same worst-case coefficient at scale 2 gives a value far outside the 32-bit lane. This is a bound, not an input that I have shown to occur.So this PR is about making the AVX2 path compute what the C code computes, not about a score that is known to be wrong today.
Tests
check_admgains cases foradm_cm(scale 0) andi4_adm_cm(scales 1 to 3) that put the rounded square aboveINT32_MAX, plus scale 0 cases just below and just above the limit. The inputs are synthetic and say so in comments: they exercise the arithmetic, they are not what the extractor produces from a frame.With the logical shift put back and the tests kept, each of these cases fails against the C reference on seeds 1 to 20; with the fix they pass.
Validation
checkasm --test=admpasses with seeds 1 to 20; the libvmaf unit suite passes 28 of 28 on both.src01_hrc00/src01_hrc01pair, 8-bit and 16-bit, are byte-equal to mastercf677baaon the AVX-512, AVX2 (--cpumask 16) and scalar (--cpumask 63) paths.