Coverage Report

Created: 2023-01-17 06:24

/src/htslib/htscodecs/htscodecs/utils.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (c) 2019-2022 Genome Research Ltd.
3
 * Author(s): James Bonfield
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions are met:
7
 *
8
 *    1. Redistributions of source code must retain the above copyright notice,
9
 *       this list of conditions and the following disclaimer.
10
 *
11
 *    2. Redistributions in binary form must reproduce the above
12
 *       copyright notice, this list of conditions and the following
13
 *       disclaimer in the documentation and/or other materials provided
14
 *       with the distribution.
15
 *
16
 *    3. Neither the names Genome Research Ltd and Wellcome Trust Sanger
17
 *       Institute nor the names of its contributors may be used to endorse
18
 *       or promote products derived from this software without specific
19
 *       prior written permission.
20
 *
21
 * THIS SOFTWARE IS PROVIDED BY GENOME RESEARCH LTD AND CONTRIBUTORS "AS
22
 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
24
 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GENOME RESEARCH
25
 * LTD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
 */
33
34
#ifndef RANS_UTILS_H
35
#define RANS_UTILS_H
36
37
#include <string.h>
38
#include <stdlib.h>
39
#include <math.h>
40
41
#if defined(__GNUC__) || defined(__clang__)
42
#  if !defined(__clang__) && __GNUC__ >= 100
43
     // better still on gcc10 for O1 decode of old rans 4x8
44
     // gcc 10=246/205 11=243/205 12=230/197
45
#    define likely(x)      __builtin_expect_with_probability((x), 1, 0.99)
46
#  else
47
     // gcc 10=193/168 11=195/161 12=199/176
48
0
#    define likely(x)      __builtin_expect((x), 1)
49
#  endif
50
85
#  define unlikely(x)     __builtin_expect((x), 0)
51
#else
52
#  define likely(x)   (x)
53
#  define unlikely(x) (x)
54
#endif
55
56
/*
57
 * Allocates size bytes from the global Thread Local Storage pool.
58
 * This is shared by all subsequent calls within this thread.
59
 *
60
 * Note this is NOT a general purpose allocator and usage outside of this
61
 * library is not advised due to assumptions and limitations in the design.
62
 */
63
void *htscodecs_tls_alloc(size_t size);
64
void *htscodecs_tls_calloc(size_t nmemb, size_t size);
65
void  htscodecs_tls_free(void *ptr);
66
67
68
/* Fast approximate log base 2 */
69
0
static inline double fast_log(double a) {
70
0
  union { double d; long long x; } u = { a };
71
0
  return (u.x - 4606921278410026770) * 1.539095918623324e-16; /* 1 / 6497320848556798.0; */
72
0
}
Unexecuted instantiation: arith_dynamic.c:fast_log
Unexecuted instantiation: fqzcomp_qual.c:fast_log
Unexecuted instantiation: rANS_static4x16pr.c:fast_log
Unexecuted instantiation: rANS_static32x16pr_avx2.c:fast_log
Unexecuted instantiation: rANS_static32x16pr_avx512.c:fast_log
Unexecuted instantiation: rANS_static32x16pr_sse4.c:fast_log
Unexecuted instantiation: rANS_static32x16pr.c:fast_log
Unexecuted instantiation: rANS_static.c:fast_log
Unexecuted instantiation: tokenise_name3.c:fast_log
Unexecuted instantiation: utils.c:fast_log
73
74
/*
75
 * Data transpose by N.  Common to rANS4x16 and arith_dynamic decoders.
76
 *
77
 * Tuned for specific common cases of N.
78
 */
79
static inline void unstripe(unsigned char *out, unsigned char *outN,
80
                            unsigned int ulen, unsigned int N,
81
72
                            unsigned int idxN[256]) {
82
72
    int j = 0, k;
83
84
72
    if (ulen >= N) {
85
52
        switch (N) {
86
32
        case 4:
87
211
#define LLN 16
88
32
            if (ulen >= 4*LLN) {
89
25
                while (j < ulen-4*LLN) {
90
7
                    int l;
91
119
                    for (l = 0; l < LLN; l++) {
92
560
                        for (k = 0; k < 4; k++)
93
448
                            out[j+k+l*4] = outN[idxN[k]+l];
94
112
                    }
95
35
                    for (k = 0; k < 4; k++)
96
28
                        idxN[k] += LLN;
97
7
                    j += 4*LLN;
98
7
                }
99
18
            }
100
223
            while (j < ulen-4) {
101
955
                for (k = 0; k < 4; k++)
102
764
                    out[j++] = outN[idxN[k]++];
103
191
            }
104
32
#undef LLN
105
32
            break;
106
107
0
        case 2:
108
0
#define LLN 4
109
0
            if (ulen >= 2*LLN) {
110
0
                while (j < ulen-2*LLN) {
111
0
                    int l;
112
0
                    for (l = 0; l < LLN; l++) {
113
0
                        for (k = 0; k < 2; k++)
114
0
                            out[j++] = outN[idxN[k]+l];
115
0
                    }
116
0
                    for (k = 0; k < 2; k++)
117
0
                        idxN[k] += l;
118
0
                }
119
0
            }
120
0
            while (j < ulen-2) {
121
0
                for (k = 0; k < 2; k++)
122
0
                    out[j++] = outN[idxN[k]++];
123
0
            }
124
0
#undef LLN
125
0
            break;
126
127
20
        default:
128
            // General case, around 25% slower overall decode
129
91
            while (j < ulen-N) {
130
820
                for (k = 0; k < N; k++)
131
749
                    out[j++] = outN[idxN[k]++];
132
71
            }
133
20
            break;
134
52
        }
135
52
    }
136
499
    for (k = 0; j < ulen; k++)
137
427
        out[j++] = outN[idxN[k]++];
138
72
}
arith_dynamic.c:unstripe
Line
Count
Source
81
41
                            unsigned int idxN[256]) {
82
41
    int j = 0, k;
83
84
41
    if (ulen >= N) {
85
21
        switch (N) {
86
21
        case 4:
87
21
#define LLN 16
88
21
            if (ulen >= 4*LLN) {
89
20
                while (j < ulen-4*LLN) {
90
7
                    int l;
91
119
                    for (l = 0; l < LLN; l++) {
92
560
                        for (k = 0; k < 4; k++)
93
448
                            out[j+k+l*4] = outN[idxN[k]+l];
94
112
                    }
95
35
                    for (k = 0; k < 4; k++)
96
28
                        idxN[k] += LLN;
97
7
                    j += 4*LLN;
98
7
                }
99
13
            }
100
137
            while (j < ulen-4) {
101
580
                for (k = 0; k < 4; k++)
102
464
                    out[j++] = outN[idxN[k]++];
103
116
            }
104
21
#undef LLN
105
21
            break;
106
107
0
        case 2:
108
0
#define LLN 4
109
0
            if (ulen >= 2*LLN) {
110
0
                while (j < ulen-2*LLN) {
111
0
                    int l;
112
0
                    for (l = 0; l < LLN; l++) {
113
0
                        for (k = 0; k < 2; k++)
114
0
                            out[j++] = outN[idxN[k]+l];
115
0
                    }
116
0
                    for (k = 0; k < 2; k++)
117
0
                        idxN[k] += l;
118
0
                }
119
0
            }
120
0
            while (j < ulen-2) {
121
0
                for (k = 0; k < 2; k++)
122
0
                    out[j++] = outN[idxN[k]++];
123
0
            }
124
0
#undef LLN
125
0
            break;
126
127
0
        default:
128
            // General case, around 25% slower overall decode
129
0
            while (j < ulen-N) {
130
0
                for (k = 0; k < N; k++)
131
0
                    out[j++] = outN[idxN[k]++];
132
0
            }
133
0
            break;
134
21
        }
135
21
    }
136
116
    for (k = 0; j < ulen; k++)
137
75
        out[j++] = outN[idxN[k]++];
138
41
}
Unexecuted instantiation: fqzcomp_qual.c:unstripe
rANS_static4x16pr.c:unstripe
Line
Count
Source
81
31
                            unsigned int idxN[256]) {
82
31
    int j = 0, k;
83
84
31
    if (ulen >= N) {
85
31
        switch (N) {
86
11
        case 4:
87
11
#define LLN 16
88
11
            if (ulen >= 4*LLN) {
89
5
                while (j < ulen-4*LLN) {
90
0
                    int l;
91
0
                    for (l = 0; l < LLN; l++) {
92
0
                        for (k = 0; k < 4; k++)
93
0
                            out[j+k+l*4] = outN[idxN[k]+l];
94
0
                    }
95
0
                    for (k = 0; k < 4; k++)
96
0
                        idxN[k] += LLN;
97
0
                    j += 4*LLN;
98
0
                }
99
5
            }
100
86
            while (j < ulen-4) {
101
375
                for (k = 0; k < 4; k++)
102
300
                    out[j++] = outN[idxN[k]++];
103
75
            }
104
11
#undef LLN
105
11
            break;
106
107
0
        case 2:
108
0
#define LLN 4
109
0
            if (ulen >= 2*LLN) {
110
0
                while (j < ulen-2*LLN) {
111
0
                    int l;
112
0
                    for (l = 0; l < LLN; l++) {
113
0
                        for (k = 0; k < 2; k++)
114
0
                            out[j++] = outN[idxN[k]+l];
115
0
                    }
116
0
                    for (k = 0; k < 2; k++)
117
0
                        idxN[k] += l;
118
0
                }
119
0
            }
120
0
            while (j < ulen-2) {
121
0
                for (k = 0; k < 2; k++)
122
0
                    out[j++] = outN[idxN[k]++];
123
0
            }
124
0
#undef LLN
125
0
            break;
126
127
20
        default:
128
            // General case, around 25% slower overall decode
129
91
            while (j < ulen-N) {
130
820
                for (k = 0; k < N; k++)
131
749
                    out[j++] = outN[idxN[k]++];
132
71
            }
133
20
            break;
134
31
        }
135
31
    }
136
383
    for (k = 0; j < ulen; k++)
137
352
        out[j++] = outN[idxN[k]++];
138
31
}
Unexecuted instantiation: rANS_static32x16pr_avx2.c:unstripe
Unexecuted instantiation: rANS_static32x16pr_avx512.c:unstripe
Unexecuted instantiation: rANS_static32x16pr_sse4.c:unstripe
Unexecuted instantiation: rANS_static32x16pr.c:unstripe
Unexecuted instantiation: rANS_static.c:unstripe
Unexecuted instantiation: tokenise_name3.c:unstripe
Unexecuted instantiation: utils.c:unstripe
139
140
#define MAGIC 8
141
142
/*
143
 * Order 0 histogram construction.  8-way unrolled to avoid cache collisions.
144
 */
145
static inline
146
0
void hist8(unsigned char *in, unsigned int in_size, uint32_t F0[256]) {
147
0
    if (in_size > 500000) {
148
0
        uint32_t *f0 = htscodecs_tls_calloc((65536+37)*3, sizeof(*f0));
149
0
        uint32_t *f1 = f0 + 65536+37;
150
0
        uint32_t *f2 = f1 + 65536+37;
151
152
0
        uint32_t i, i8 = in_size & ~15;
153
154
0
        for (i = 0; i < i8; i+=16) {
155
0
            uint16_t i16a[4], i16b[4];
156
0
            memcpy(i16a, in+i, 8);
157
0
            f0[i16a[0]]++;
158
0
            f1[i16a[1]]++;
159
0
            f2[i16a[2]]++;
160
0
            f0[i16a[3]]++;
161
162
0
            memcpy(i16b, in+i+8, 8);
163
0
            f1[i16b[0]]++;
164
0
            f0[i16b[1]]++;
165
0
            f1[i16b[2]]++;
166
0
            f2[i16b[3]]++;
167
0
        }
168
169
0
        while (i < in_size)
170
0
            F0[in[i++]]++;
171
172
0
        for (i = 0; i < 65536; i++) {
173
0
            F0[i & 0xff] += f0[i] + f1[i] + f2[i];
174
0
            F0[i >> 8  ] += f0[i] + f1[i] + f2[i];
175
0
        }
176
0
        htscodecs_tls_free(f0);
177
0
    } else {
178
0
        uint32_t F1[256+MAGIC] = {0}, F2[256+MAGIC] = {0}, F3[256+MAGIC] = {0};
179
0
        uint32_t i, i8 = in_size & ~7;
180
181
0
        for (i = 0; i < i8; i+=8) {
182
0
            F0[in[i+0]]++;
183
0
            F1[in[i+1]]++;
184
0
            F2[in[i+2]]++;
185
0
            F3[in[i+3]]++;
186
0
            F0[in[i+4]]++;
187
0
            F1[in[i+5]]++;
188
0
            F2[in[i+6]]++;
189
0
            F3[in[i+7]]++;
190
0
        }
191
192
0
        while (i < in_size)
193
0
            F0[in[i++]]++;
194
195
0
        for (i = 0; i < 256; i++)
196
0
            F0[i] += F1[i] + F2[i] + F3[i];
197
0
    }
198
0
}
Unexecuted instantiation: arith_dynamic.c:hist8
Unexecuted instantiation: fqzcomp_qual.c:hist8
Unexecuted instantiation: rANS_static4x16pr.c:hist8
Unexecuted instantiation: rANS_static32x16pr_avx2.c:hist8
Unexecuted instantiation: rANS_static32x16pr_avx512.c:hist8
Unexecuted instantiation: rANS_static32x16pr_sse4.c:hist8
Unexecuted instantiation: rANS_static32x16pr.c:hist8
Unexecuted instantiation: rANS_static.c:hist8
Unexecuted instantiation: tokenise_name3.c:hist8
Unexecuted instantiation: utils.c:hist8
199
200
// Hist8 with a crude entropy (bits / byte) estimator.
201
static inline
202
0
double hist8e(unsigned char *in, unsigned int in_size, uint32_t F0[256]) {
203
0
    uint32_t F1[256+MAGIC] = {0}, F2[256+MAGIC] = {0}, F3[256+MAGIC] = {0};
204
0
    uint32_t F4[256+MAGIC] = {0}, F5[256+MAGIC] = {0}, F6[256+MAGIC] = {0};
205
0
    uint32_t F7[256+MAGIC] = {0};
206
207
0
#ifdef __GNUC__
208
0
    double e = 0, in_size_r2 = log(1.0/in_size)/log(2);
209
#else
210
    double e = 0, in_size_r2 = log(1.0/in_size);
211
#endif
212
213
0
    unsigned int i, i8 = in_size & ~7;
214
0
    for (i = 0; i < i8; i+=8) {
215
0
        F0[in[i+0]]++;
216
0
        F1[in[i+1]]++;
217
0
        F2[in[i+2]]++;
218
0
        F3[in[i+3]]++;
219
0
        F4[in[i+4]]++;
220
0
        F5[in[i+5]]++;
221
0
        F6[in[i+6]]++;
222
0
        F7[in[i+7]]++;
223
0
    }
224
0
    while (i < in_size)
225
0
        F0[in[i++]]++;
226
227
0
    for (i = 0; i < 256; i++) {
228
0
        F0[i] += F1[i] + F2[i] + F3[i] + F4[i] + F5[i] + F6[i] + F7[i];
229
0
#ifdef __GNUC__
230
0
        e -= F0[i] * (32 - __builtin_clz(F0[i]|1) + in_size_r2);
231
#else
232
        e -= F0[i] * (fast_log(F0[i]) + in_size_r2);
233
#endif
234
0
    }
235
236
#ifndef __GNUC__
237
    e /= log(2);
238
#endif
239
0
    return e/in_size;
240
0
}
Unexecuted instantiation: arith_dynamic.c:hist8e
Unexecuted instantiation: fqzcomp_qual.c:hist8e
Unexecuted instantiation: rANS_static4x16pr.c:hist8e
Unexecuted instantiation: rANS_static32x16pr_avx2.c:hist8e
Unexecuted instantiation: rANS_static32x16pr_avx512.c:hist8e
Unexecuted instantiation: rANS_static32x16pr_sse4.c:hist8e
Unexecuted instantiation: rANS_static32x16pr.c:hist8e
Unexecuted instantiation: rANS_static.c:hist8e
Unexecuted instantiation: tokenise_name3.c:hist8e
Unexecuted instantiation: utils.c:hist8e
241
242
/*
243
 * A variant of hist8 that simply marks the presence of a symbol rather
244
 * than its frequency.
245
 */
246
static inline
247
void present8(unsigned char *in, unsigned int in_size,
248
0
              uint32_t F0[256]) {
249
0
    uint32_t F1[256+MAGIC] = {0}, F2[256+MAGIC] = {0}, F3[256+MAGIC] = {0};
250
0
    uint32_t F4[256+MAGIC] = {0}, F5[256+MAGIC] = {0}, F6[256+MAGIC] = {0};
251
0
    uint32_t F7[256+MAGIC] = {0};
252
0
253
0
    unsigned int i, i8 = in_size & ~7;
254
0
    for (i = 0; i < i8; i+=8) {
255
0
        F0[in[i+0]]=1;
256
0
        F1[in[i+1]]=1;
257
0
        F2[in[i+2]]=1;
258
0
        F3[in[i+3]]=1;
259
0
        F4[in[i+4]]=1;
260
0
        F5[in[i+5]]=1;
261
0
        F6[in[i+6]]=1;
262
0
        F7[in[i+7]]=1;
263
0
    }
264
0
    while (i < in_size)
265
0
        F0[in[i++]]=1;
266
0
267
0
    for (i = 0; i < 256; i++)
268
0
        F0[i] += F1[i] + F2[i] + F3[i] + F4[i] + F5[i] + F6[i] + F7[i];
269
0
}
Unexecuted instantiation: arith_dynamic.c:present8
Unexecuted instantiation: fqzcomp_qual.c:present8
Unexecuted instantiation: rANS_static4x16pr.c:present8
Unexecuted instantiation: rANS_static32x16pr_avx2.c:present8
Unexecuted instantiation: rANS_static32x16pr_avx512.c:present8
Unexecuted instantiation: rANS_static32x16pr_sse4.c:present8
Unexecuted instantiation: rANS_static32x16pr.c:present8
Unexecuted instantiation: rANS_static.c:present8
Unexecuted instantiation: tokenise_name3.c:present8
Unexecuted instantiation: utils.c:present8
270
271
/*
272
 * Order 1 histogram construction.  4-way unrolled to avoid cache collisions.
273
 */
274
#if 1
275
static inline
276
void hist1_4(unsigned char *in, unsigned int in_size,
277
0
             uint32_t F0[256][256], uint32_t *T0) {
278
0
    unsigned char l = 0, c;
279
0
    unsigned char *in_end = in + in_size;
280
281
0
    unsigned char cc[5] = {0};
282
0
    if (in_size > 500000) {
283
0
        uint32_t (*F1)[259] = htscodecs_tls_calloc(256, sizeof(*F1));
284
0
        while (in < in_end-8) {
285
0
            memcpy(cc, in, 4); in += 4;
286
0
            F0[cc[4]][cc[0]]++;
287
0
            F1[cc[0]][cc[1]]++;
288
0
            F0[cc[1]][cc[2]]++;
289
0
            F1[cc[2]][cc[3]]++;
290
0
            cc[4] = cc[3];
291
292
0
            memcpy(cc, in, 4); in += 4;
293
0
            F0[cc[4]][cc[0]]++;
294
0
            F1[cc[0]][cc[1]]++;
295
0
            F0[cc[1]][cc[2]]++;
296
0
            F1[cc[2]][cc[3]]++;
297
0
            cc[4] = cc[3];
298
0
        }
299
0
        l = cc[3];
300
301
0
        while (in < in_end) {
302
0
            F0[l][c = *in++]++;
303
0
            l = c;
304
0
        }
305
0
        T0[l]++;
306
307
0
        int i, j;
308
0
        for (i = 0; i < 256; i++) {
309
0
            int tt = 0;
310
0
            for (j = 0; j < 256; j++) {
311
0
                F0[i][j] += F1[i][j];
312
0
                tt += F0[i][j];
313
0
            }
314
0
            T0[i]+=tt;
315
0
        }
316
0
        htscodecs_tls_free(F1);
317
0
    } else {
318
0
        while (in < in_end-8) {
319
0
            memcpy(cc, in, 4); in += 4;
320
0
            F0[cc[4]][cc[0]]++;
321
0
            F0[cc[0]][cc[1]]++;
322
0
            F0[cc[1]][cc[2]]++;
323
0
            F0[cc[2]][cc[3]]++;
324
0
            cc[4] = cc[3];
325
326
0
            memcpy(cc, in, 4); in += 4;
327
0
            F0[cc[4]][cc[0]]++;
328
0
            F0[cc[0]][cc[1]]++;
329
0
            F0[cc[1]][cc[2]]++;
330
0
            F0[cc[2]][cc[3]]++;
331
0
            cc[4] = cc[3];
332
0
        }
333
0
        l = cc[3];
334
335
0
        while (in < in_end) {
336
0
            F0[l][c = *in++]++;
337
0
            l = c;
338
0
        }
339
0
        T0[l]++;
340
341
0
        int i, j;
342
0
        for (i = 0; i < 256; i++) {
343
0
            int tt = 0;
344
0
            for (j = 0; j < 256; j++)
345
0
                tt += F0[i][j];
346
0
            T0[i]+=tt;
347
0
        }
348
0
    }
349
0
}
Unexecuted instantiation: arith_dynamic.c:hist1_4
Unexecuted instantiation: fqzcomp_qual.c:hist1_4
Unexecuted instantiation: rANS_static4x16pr.c:hist1_4
Unexecuted instantiation: rANS_static32x16pr_avx2.c:hist1_4
Unexecuted instantiation: rANS_static32x16pr_avx512.c:hist1_4
Unexecuted instantiation: rANS_static32x16pr_sse4.c:hist1_4
Unexecuted instantiation: rANS_static32x16pr.c:hist1_4
Unexecuted instantiation: rANS_static.c:hist1_4
Unexecuted instantiation: tokenise_name3.c:hist1_4
Unexecuted instantiation: utils.c:hist1_4
350
351
#else
352
// 16 bit mode, similar to O0 freq.
353
// This is better on some low entropy data, but generally we prefer to do
354
// bit-packing and/or RLE to turn it into higher-entropy data first.
355
//
356
// Kept here for posterity incase we need it again, as it's quick tricky.
357
static inline
358
void hist1_4(unsigned char *in, unsigned int in_size,
359
             uint32_t F0[256][256], uint32_t *T0) {
360
    uint32_t f0[65536+MAGIC] = {0};
361
    uint32_t f1[65536+MAGIC] = {0};
362
363
    uint32_t i, i8 = (in_size-1) & ~15;
364
365
    T0[0]++; f0[in[0]<<8]++;
366
    for (i = 0; i < i8; i+=16) {
367
        uint16_t i16a[16];
368
        memcpy(i16a,   in+i,   16); // faster in 2 as gcc recognises this
369
        memcpy(i16a+8, in+i+1, 16); // faster in 2 as gcc recognises this
370
371
        f0[i16a[0]]++;
372
        f1[i16a[1]]++;
373
        f0[i16a[2]]++;
374
        f1[i16a[3]]++;
375
        f0[i16a[4]]++;
376
        f1[i16a[5]]++;
377
        f0[i16a[6]]++;
378
        f1[i16a[7]]++;
379
        f0[i16a[8]]++;
380
        f1[i16a[9]]++;
381
        f0[i16a[10]]++;
382
        f1[i16a[11]]++;
383
        f0[i16a[12]]++;
384
        f1[i16a[13]]++;
385
        f0[i16a[14]]++;
386
        f1[i16a[15]]++;
387
    }
388
389
    while (i < in_size-1) {
390
        F0[in[i]][in[i+1]]++;
391
        T0[in[i+1]]++;
392
        i++;
393
    }
394
395
    for (i = 0; i < 65536; i++) {
396
        F0[i&0xff][i>>8] += f0[i] + f1[i];
397
        T0[i>>8]         += f0[i] + f1[i];
398
    }
399
}
400
#endif
401
402
#endif /* RANS_UTILS_H */