+void RansEncPutSymbol(inout uint rans, inout uint rans_offset, uvec4 sym)
+{
+ 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
+ if (rans >= x_max) {
+ do {
+ rans_output[--rans_offset] = uint8_t(rans & 0xffu);
+ rans >>= 8;
+ } while (rans >= x_max);
+ }
+
+ uint q, unused;
+ umulExtended(rans, rcp_freq, q, unused);
+ rans += bias + (q >> rcp_shift) * cmpl_freq;
+}
+