Lines Matching refs:rs
88 static void init_rubin(struct rubin_state *rs, int div, int *bits) in init_rubin() argument
92 rs->q = 0; in init_rubin()
93 rs->p = (long) (2 * UPPER_BIT_RUBIN); in init_rubin()
94 rs->bit_number = (long) 0; in init_rubin()
95 rs->bit_divider = div; in init_rubin()
98 rs->bits[c] = bits[c]; in init_rubin()
102 static int encode(struct rubin_state *rs, long A, long B, int symbol) in encode() argument
108 while ((rs->q >= UPPER_BIT_RUBIN) || in encode()
109 ((rs->p + rs->q) <= UPPER_BIT_RUBIN)) { in encode()
110 rs->bit_number++; in encode()
112 ret = pushbit(&rs->pp, (rs->q & UPPER_BIT_RUBIN) ? 1 : 0, 0); in encode()
115 rs->q &= LOWER_BITS_RUBIN; in encode()
116 rs->q <<= 1; in encode()
117 rs->p <<= 1; in encode()
119 i0 = A * rs->p / (A + B); in encode()
123 if (i0 >= rs->p) in encode()
124 i0 = rs->p - 1; in encode()
126 i1 = rs->p - i0; in encode()
129 rs->p = i0; in encode()
131 rs->p = i1; in encode()
132 rs->q += i0; in encode()
138 static void end_rubin(struct rubin_state *rs) in end_rubin() argument
144 pushbit(&rs->pp, (UPPER_BIT_RUBIN & rs->q) ? 1 : 0, 1); in end_rubin()
145 rs->q &= LOWER_BITS_RUBIN; in end_rubin()
146 rs->q <<= 1; in end_rubin()
151 static void init_decode(struct rubin_state *rs, int div, int *bits) in init_decode() argument
153 init_rubin(rs, div, bits); in init_decode()
156 rs->rec_q = 0; in init_decode()
158 for (rs->bit_number = 0; rs->bit_number++ < RUBIN_REG_SIZE; in init_decode()
159 rs->rec_q = rs->rec_q * 2 + (long) (pullbit(&rs->pp))) in init_decode()
163 static void __do_decode(struct rubin_state *rs, unsigned long p, in __do_decode() argument
182 rs->p = p; in __do_decode()
183 rs->q = q; in __do_decode()
185 rs->bit_number += bits; in __do_decode()
190 rec_q = rs->rec_q; in __do_decode()
192 c = pullbit(&rs->pp); in __do_decode()
197 rs->rec_q = rec_q; in __do_decode()
200 static int decode(struct rubin_state *rs, long A, long B) in decode() argument
202 unsigned long p = rs->p, q = rs->q; in decode()
207 __do_decode(rs, p, q); in decode()
209 i0 = A * rs->p / (A + B); in decode()
213 if (i0 >= rs->p) in decode()
214 i0 = rs->p - 1; in decode()
216 threshold = rs->q + i0; in decode()
217 symbol = rs->rec_q >= threshold; in decode()
218 if (rs->rec_q >= threshold) { in decode()
219 rs->q += i0; in decode()
220 i0 = rs->p - i0; in decode()
223 rs->p = i0; in decode()
230 static int out_byte(struct rubin_state *rs, unsigned char byte) in out_byte() argument
234 rs_copy = *rs; in out_byte()
237 ret = encode(rs, rs->bit_divider-rs->bits[i], in out_byte()
238 rs->bits[i], byte & 1); in out_byte()
241 *rs = rs_copy; in out_byte()
249 static int in_byte(struct rubin_state *rs) in in_byte() argument
251 int i, result = 0, bit_divider = rs->bit_divider; in in_byte()
254 result |= decode(rs, bit_divider - rs->bits[i], in in_byte()
255 rs->bits[i]) << i; in in_byte()
268 struct rubin_state rs; in rubin_do_compress() local
270 init_pushpull(&rs.pp, cpage_out, *dstlen * 8, 0, 32); in rubin_do_compress()
272 init_rubin(&rs, bit_divider, bits); in rubin_do_compress()
274 while (pos < (*sourcelen) && !out_byte(&rs, data_in[pos])) in rubin_do_compress()
277 end_rubin(&rs); in rubin_do_compress()
287 outpos = (pushedbits(&rs.pp)+7)/8; in rubin_do_compress()
374 struct rubin_state rs; in rubin_do_decompress() local
376 init_pushpull(&rs.pp, cdata_in, srclen, 0, 0); in rubin_do_decompress()
377 init_decode(&rs, bit_divider, bits); in rubin_do_decompress()
380 page_out[outpos++] = in_byte(&rs); in rubin_do_decompress()