From 5a6935047e6c43ebb4dfb6bdf805474fa044c82a Mon Sep 17 00:00:00 2001 From: Michael Giacomelli Date: Fri, 18 Sep 2026 11:59:30 -0400 Subject: [PATCH] opus: hold cwrsi's row pair, and test it with one comparison 53% of the dimensions a decode walks hold no pulses, and that arm leaves _k alone, so the two CELT_PVQ_U_ROW pointers stay valid. U is non-decreasing in _k, so p <= _i < q is the single unsigned test (_i-p) < (q-p). Bit-exact over 8.2M samples. Modelled: -0.40% ARMv4, -0.78% ARMv5E; the function -4.8% and -7.1%. Measured: e200v1 39.19 -> 38.96 MHz, Clip+ 28.13 -> 28.08 MHz. Co-Authored-By: Claude Opus 5 Change-Id: Id50be222e101aeabd9a1f4cf5380d3244da610ff --- lib/rbcodec/codecs/libopus/celt/cwrs.c | 40 ++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/lib/rbcodec/codecs/libopus/celt/cwrs.c b/lib/rbcodec/codecs/libopus/celt/cwrs.c index 96b59184c7..6bb8b9be3b 100644 --- a/lib/rbcodec/codecs/libopus/celt/cwrs.c +++ b/lib/rbcodec/codecs/libopus/celt/cwrs.c @@ -461,13 +461,21 @@ void encode_pulses(const int *_y,int _n,int _k,ec_enc *_enc){ } static opus_val32 cwrsi(int _n,int _k,opus_uint32 _i,int *_y){ + const opus_uint32 *rk; + const opus_uint32 *rk1; opus_uint32 p; + opus_uint32 d; int s; int k0; + int kc; opus_int16 val; opus_val32 yy=0; celt_assert(_k>0); celt_assert(_n>1); + /*_k never goes negative, so this cannot match before the pair has been + loaded once.*/ + kc=-1; + rk=rk1=NULL; while(_n>2){ opus_uint32 q; /*Lots of pulses case:*/ @@ -495,12 +503,32 @@ static opus_val32 cwrsi(int _n,int _k,opus_uint32 _i,int *_y){ } /*Lots of dimensions case:*/ else{ - /*Are there any pulses in this dimension at all?*/ - p=CELT_PVQ_U_ROW[_k][_n]; - q=CELT_PVQ_U_ROW[_k+1][_n]; - if(p<=_i&&_i=_n)break; + p=rk[_n]; + q=rk1[_n]; + d=_i-p; + if(d>=q-p)break; + } + /*_n is already decremented for every dimension handled above.*/ + continue; } else{ /*Are the pulses in this dimension negative?*/