diff --git a/libcelt/vq.c b/libcelt/vq.c index 4c747f28..d8bfc63c 100644 --- a/libcelt/vq.c +++ b/libcelt/vq.c @@ -135,11 +135,13 @@ void alg_quant(celt_norm_t *X, celt_mask_t *W, int N, int K, const celt_norm_t * xy = yy = yp = 0; pulsesLeft = K; - while (pulsesLeft > 0) + while (pulsesLeft > 1) { int pulsesAtOnce=1; int best_id; celt_word16_t magnitude; + celt_word32_t best_num = -VERY_LARGE16; + celt_word16_t best_den = 0; #ifdef FIXED_POINT int rshift; #endif @@ -157,70 +159,30 @@ void alg_quant(celt_norm_t *X, celt_mask_t *W, int N, int K, const celt_norm_t * add it outside the loop */ yy = MAC16_16(yy, magnitude,magnitude); /* Choose between fast and accurate strategy depending on where we are in the search */ - if (pulsesLeft>1) - { /* This should ensure that anything we can process will have a better score */ - celt_word32_t best_num = -VERY_LARGE16; - celt_word16_t best_den = 0; - j=0; - do { - celt_word16_t Rxy, Ryy; - /* Select sign based on X[j] alone */ - s = MULT16_16(signx[j],magnitude); - /* Temporary sums of the new pulse(s) */ - Rxy = EXTRACT16(SHR32(MAC16_16(xy, s,X[j]),rshift)); - /* We're multiplying y[j] by two so we don't have to do it here */ - Ryy = EXTRACT16(SHR32(MAC16_16(yy, s,y[j]),rshift)); + j=0; + do { + celt_word16_t Rxy, Ryy; + /* Select sign based on X[j] alone */ + s = MULT16_16(signx[j],magnitude); + /* Temporary sums of the new pulse(s) */ + Rxy = EXTRACT16(SHR32(MAC16_16(xy, s,X[j]),rshift)); + /* We're multiplying y[j] by two so we don't have to do it here */ + Ryy = EXTRACT16(SHR32(MAC16_16(yy, s,y[j]),rshift)); /* Approximate score: we maximise Rxy/sqrt(Ryy) (we're guaranteed that - Rxy is positive because the sign is pre-computed) */ - Rxy = MULT16_16_Q15(Rxy,Rxy); + Rxy is positive because the sign is pre-computed) */ + Rxy = MULT16_16_Q15(Rxy,Rxy); /* The idea is to check for num/den >= best_num/best_den, but that way - we can do it without any division */ - /* OPT: Make sure to use conditional moves here */ - if (MULT16_16(best_den, Rxy) > MULT16_16(Ryy, best_num)) - { - best_den = Ryy; - best_num = Rxy; - best_id = j; - } - } while (++j MULT16_16(Ryy, best_num)) - { - best_den = Ryy; - best_num = num; - best_id = j; - } - } while (++j MULT16_16(Ryy, best_num)) + { + best_den = Ryy; + best_num = Rxy; + best_id = j; + } + } while (++j MULT16_16(Ryy, best_num)) + { + best_den = Ryy; + best_num = num; + best_id = j; + } + } while (++j