Guard lpc methods in flacdsp and add tests

This commit adds additional guards for the RISC-V lpc variants.

It also adds tests to exercise the guarded paths in checkasm/flacdsp.c.
This commit is contained in:
Thomas Guilbert
2026-05-21 01:22:37 +00:00
committed by michaelni
parent f956c41d7b
commit b3fb13e8dd
2 changed files with 45 additions and 16 deletions

View File

@@ -22,11 +22,11 @@
func ff_flac_lpc16_rvv, zve32x, b
lpad 0
ble a4, a2, 2f
vtype_vli t0, a2, t2, e32, ta, ma
vsetvl zero, a2, t0
vle32.v v8, (a1)
sub a4, a4, a2
blez a4, 2f
vle32.v v16, (a0)
sh2add a0, a2, a0
vmv.s.x v0, zero
@@ -49,6 +49,7 @@ endfunc
#if (__riscv_xlen == 64)
func ff_flac_lpc32_rvv, zve64x, zba
lpad 0
ble a4, a2, 2f
addi t2, a2, -16
ble t2, zero, ff_flac_lpc32_rvv_simple
vsetivli zero, 1, e64, m1, ta, ma
@@ -75,12 +76,13 @@ func ff_flac_lpc32_rvv, zve64x, zba
sw t0, (a0)
addi a0, a0, 4
bnez a4, 1b
2:
ret
endfunc
func ff_flac_lpc32_rvv_simple, zve64x, b
lpad 0
ble a4, a2, 2f
vtype_vli t3, a2, t1, e64, ta, ma
vntypei t2, t3
vsetvl zero, a2, t3 // e64
@@ -104,12 +106,13 @@ func ff_flac_lpc32_rvv_simple, zve64x, b
sw t0, (a0)
addi a0, a0, 4
bnez a4, 1b
2:
ret
endfunc
func ff_flac_lpc33_rvv, zve64x, b
lpad 0
ble a5, a3, 2f
vtype_vli t0, a3, t1, e64, ta, ma
vsetvl zero, a3, t0
vmv.s.x v0, zero
@@ -132,7 +135,7 @@ func ff_flac_lpc33_rvv, zve64x, b
sd t0, (a0)
addi a0, a0, 8
bnez a5, 1b
2:
ret
endfunc
#endif

View File

@@ -74,12 +74,25 @@ static void check_lpc(int pred_order, int bps)
for (int i = 0; i < BUF_SIZE; i++)
dst[i] = sign_extend(rnd(), bps);
memcpy(dst0, dst, BUF_SIZE * sizeof (int32_t));
memcpy(dst1, dst, BUF_SIZE * sizeof (int32_t));
call_ref(dst0, coeffs, pred_order, qlevel, BUF_SIZE);
call_new(dst1, coeffs, pred_order, qlevel, BUF_SIZE);
if (memcmp(dst0, dst1, BUF_SIZE * sizeof (int32_t)) != 0)
fail();
const int test_lens[] = {
0,
pred_order - 1,
pred_order,
pred_order + 1,
BUF_SIZE,
};
for (int k = 0; k < FF_ARRAY_ELEMS(test_lens); k++) {
int len = test_lens[k];
if (len < 0 || len > BUF_SIZE) continue;
memcpy(dst0, dst, BUF_SIZE * sizeof (int32_t));
memcpy(dst1, dst, BUF_SIZE * sizeof (int32_t));
call_ref(dst0, coeffs, pred_order, qlevel, len);
call_new(dst1, coeffs, pred_order, qlevel, len);
if (memcmp(dst0, dst1, BUF_SIZE * sizeof (int32_t)) != 0)
fail();
}
bench_new(dst, coeffs, pred_order, qlevel, BUF_SIZE);
}
@@ -103,12 +116,25 @@ static void check_lpc33(int pred_order)
dst[i] = sign_extend64(((int64_t)rnd() << 1) | (rnd() & 1), 33);
}
memcpy(dst0, dst, BUF_SIZE * sizeof (int64_t));
memcpy(dst1, dst, BUF_SIZE * sizeof (int64_t));
call_ref(dst0, residuals, coeffs, pred_order, qlevel, BUF_SIZE);
call_new(dst1, residuals, coeffs, pred_order, qlevel, BUF_SIZE);
if (memcmp(dst0, dst1, BUF_SIZE * sizeof (int64_t)) != 0)
fail();
const int test_lens[] = {
0,
pred_order - 1,
pred_order,
pred_order + 1,
BUF_SIZE,
};
for (int k = 0; k < FF_ARRAY_ELEMS(test_lens); k++) {
int len = test_lens[k];
if (len < 0 || len > BUF_SIZE) continue;
memcpy(dst0, dst, BUF_SIZE * sizeof (int64_t));
memcpy(dst1, dst, BUF_SIZE * sizeof (int64_t));
call_ref(dst0, residuals, coeffs, pred_order, qlevel, len);
call_new(dst1, residuals, coeffs, pred_order, qlevel, len);
if (memcmp(dst0, dst1, BUF_SIZE * sizeof (int64_t)) != 0)
fail();
}
bench_new(dst, residuals, coeffs, pred_order, qlevel, BUF_SIZE);
}