- RansEncRenorm(rans, rans_offset, freq, prob_bits);
- rans = ((rans / freq) << prob_bits) + (rans % freq) + start;
+ uint x_max = sym.x;
+ uint rcp_freq = sym.y;
+ uint bias = sym.z;
+ uint rcp_shift = (sym.w & 0xffffu);
+ uint cmpl_freq = (sym.w >> 16);
+
+ // renormalize
+ while (enc.rans >= x_max) {
+ RansPutByte(enc.rans & 0xffu, enc);
+ enc.rans >>= 8;
+ }
+
+ uint q, unused;
+ umulExtended(enc.rans, rcp_freq, q, unused);
+ enc.rans += bias + (q >> rcp_shift) * cmpl_freq;