Coverage Report

Created: 2026-10-28 06:18

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/work/dav1d/src/recon_tmpl.c
Line
Count
Source
1
/*
2
 * Copyright © 2018-2021, VideoLAN and dav1d authors
3
 * Copyright © 2018, Two Orioles, LLC
4
 * All rights reserved.
5
 *
6
 * Redistribution and use in source and binary forms, with or without
7
 * modification, are permitted provided that the following conditions are met:
8
 *
9
 * 1. Redistributions of source code must retain the above copyright notice, this
10
 *    list of conditions and the following disclaimer.
11
 *
12
 * 2. Redistributions in binary form must reproduce the above copyright notice,
13
 *    this list of conditions and the following disclaimer in the documentation
14
 *    and/or other materials provided with the distribution.
15
 *
16
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
 */
27
28
#include "config.h"
29
30
#include <string.h>
31
#include <stdio.h>
32
33
#include "common/attributes.h"
34
#include "common/bitdepth.h"
35
#include "common/dump.h"
36
#include "common/frame.h"
37
#include "common/intops.h"
38
39
#include "src/cdef_apply.h"
40
#include "src/ctx.h"
41
#include "src/ipred_prepare.h"
42
#include "src/lf_apply.h"
43
#include "src/lr_apply.h"
44
#include "src/recon.h"
45
#include "src/scan.h"
46
#include "src/tables.h"
47
#include "src/wedge.h"
48
49
1.03M
static inline unsigned read_golomb(MsacContext *const msac) {
50
1.03M
    int len = 0;
51
1.03M
    unsigned val = 1;
52
53
1.97M
    while (!dav1d_msac_decode_bool_equi(msac) && len < 32) len++;
54
1.97M
    while (len--) val = (val << 1) + dav1d_msac_decode_bool_equi(msac);
55
56
1.03M
    return val - 1;
57
1.03M
}
58
59
static inline unsigned get_skip_ctx(const TxfmInfo *const t_dim,
60
                                    const enum BlockSize bs,
61
                                    const uint8_t *const a,
62
                                    const uint8_t *const l,
63
                                    const int chroma,
64
                                    const enum Dav1dPixelLayout layout)
65
5.42M
{
66
5.42M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
67
68
5.42M
    if (chroma) {
69
2.50M
        const int ss_ver = layout == DAV1D_PIXEL_LAYOUT_I420;
70
2.50M
        const int ss_hor = layout != DAV1D_PIXEL_LAYOUT_I444;
71
2.50M
        const int not_one_blk = b_dim[2] - (!!b_dim[2] && ss_hor) > t_dim->lw ||
72
1.94M
                                b_dim[3] - (!!b_dim[3] && ss_ver) > t_dim->lh;
73
2.50M
        unsigned ca, cl;
74
75
2.50M
#define MERGE_CTX(dir, type, no_val) \
76
5.00M
        c##dir = *(const type *) dir != no_val; \
77
5.00M
        break
78
79
2.50M
        switch (t_dim->lw) {
80
        /* For some reason the MSVC CRT _wassert() function is not flagged as
81
         * __declspec(noreturn), so when using those headers the compiler will
82
         * expect execution to continue after an assertion has been triggered
83
         * and will therefore complain about the use of uninitialized variables
84
         * when compiled in debug mode if we put the default case at the end. */
85
0
        default: assert(0); /* fall-through */
86
1.05M
        case TX_4X4:   MERGE_CTX(a, uint8_t,  0x40);
87
656k
        case TX_8X8:   MERGE_CTX(a, uint16_t, 0x4040);
88
336k
        case TX_16X16: MERGE_CTX(a, uint32_t, 0x40404040U);
89
449k
        case TX_32X32: MERGE_CTX(a, uint64_t, 0x4040404040404040ULL);
90
2.50M
        }
91
2.50M
        switch (t_dim->lh) {
92
0
        default: assert(0); /* fall-through */
93
1.20M
        case TX_4X4:   MERGE_CTX(l, uint8_t,  0x40);
94
551k
        case TX_8X8:   MERGE_CTX(l, uint16_t, 0x4040);
95
286k
        case TX_16X16: MERGE_CTX(l, uint32_t, 0x40404040U);
96
460k
        case TX_32X32: MERGE_CTX(l, uint64_t, 0x4040404040404040ULL);
97
2.50M
        }
98
2.50M
#undef MERGE_CTX
99
100
2.50M
        return 7 + not_one_blk * 3 + ca + cl;
101
2.92M
    } else if (b_dim[2] == t_dim->lw && b_dim[3] == t_dim->lh) {
102
1.22M
        return 0;
103
1.69M
    } else {
104
1.69M
        unsigned la, ll;
105
106
1.69M
#define MERGE_CTX(dir, type, tx) \
107
3.40M
        if (tx == TX_64X64) { \
108
146k
            uint64_t tmp = *(const uint64_t *) dir; \
109
146k
            tmp |= *(const uint64_t *) &dir[8]; \
110
146k
            l##dir = (unsigned) (tmp >> 32) | (unsigned) tmp; \
111
146k
        } else \
112
3.40M
            l##dir = *(const type *) dir; \
113
3.40M
        if (tx == TX_32X32) l##dir |= *(const type *) &dir[sizeof(type)]; \
114
3.40M
        if (tx >= TX_16X16) l##dir |= l##dir >> 16; \
115
3.40M
        if (tx >= TX_8X8)   l##dir |= l##dir >> 8; \
116
3.40M
        break
117
118
1.69M
        switch (t_dim->lw) {
119
0
        default: assert(0); /* fall-through */
120
911k
        case TX_4X4:   MERGE_CTX(a, uint8_t,  TX_4X4);
121
423k
        case TX_8X8:   MERGE_CTX(a, uint16_t, TX_8X8);
122
267k
        case TX_16X16: MERGE_CTX(a, uint32_t, TX_16X16);
123
26.2k
        case TX_32X32: MERGE_CTX(a, uint32_t, TX_32X32);
124
73.3k
        case TX_64X64: MERGE_CTX(a, uint32_t, TX_64X64);
125
1.69M
        }
126
1.70M
        switch (t_dim->lh) {
127
0
        default: assert(0); /* fall-through */
128
925k
        case TX_4X4:   MERGE_CTX(l, uint8_t,  TX_4X4);
129
411k
        case TX_8X8:   MERGE_CTX(l, uint16_t, TX_8X8);
130
265k
        case TX_16X16: MERGE_CTX(l, uint32_t, TX_16X16);
131
26.0k
        case TX_32X32: MERGE_CTX(l, uint32_t, TX_32X32);
132
73.3k
        case TX_64X64: MERGE_CTX(l, uint32_t, TX_64X64);
133
1.70M
        }
134
1.70M
#undef MERGE_CTX
135
136
1.70M
        return dav1d_skip_ctx[umin(la & 0x3F, 4)][umin(ll & 0x3F, 4)];
137
1.70M
    }
138
5.42M
}
139
140
static inline unsigned get_dc_sign_ctx(const int /*enum RectTxfmSize*/ tx,
141
                                       const uint8_t *const a,
142
                                       const uint8_t *const l)
143
2.70M
{
144
2.70M
    uint64_t mask = 0xC0C0C0C0C0C0C0C0ULL, mul = 0x0101010101010101ULL;
145
2.70M
    int s;
146
147
2.70M
#if ARCH_X86_64 && defined(__GNUC__)
148
    /* Coerce compilers into producing better code. For some reason
149
     * every x86-64 compiler is awful at handling 64-bit constants. */
150
2.70M
    __asm__("" : "+r"(mask), "+r"(mul));
151
2.70M
#endif
152
153
2.70M
    switch(tx) {
154
0
    default: assert(0); /* fall-through */
155
1.04M
    case TX_4X4: {
156
1.04M
        int t = *(const uint8_t *) a >> 6;
157
1.04M
        t    += *(const uint8_t *) l >> 6;
158
1.04M
        s = t - 1 - 1;
159
1.04M
        break;
160
0
    }
161
351k
    case TX_8X8: {
162
351k
        uint32_t t = *(const uint16_t *) a & (uint32_t) mask;
163
351k
        t         += *(const uint16_t *) l & (uint32_t) mask;
164
351k
        t *= 0x04040404U;
165
351k
        s = (int) (t >> 24) - 2 - 2;
166
351k
        break;
167
0
    }
168
223k
    case TX_16X16: {
169
223k
        uint32_t t = (*(const uint32_t *) a & (uint32_t) mask) >> 6;
170
223k
        t         += (*(const uint32_t *) l & (uint32_t) mask) >> 6;
171
223k
        t *= (uint32_t) mul;
172
223k
        s = (int) (t >> 24) - 4 - 4;
173
223k
        break;
174
0
    }
175
188k
    case TX_32X32: {
176
188k
        uint64_t t = (*(const uint64_t *) a & mask) >> 6;
177
188k
        t         += (*(const uint64_t *) l & mask) >> 6;
178
188k
        t *= mul;
179
188k
        s = (int) (t >> 56) - 8 - 8;
180
188k
        break;
181
0
    }
182
100k
    case TX_64X64: {
183
100k
        uint64_t t = (*(const uint64_t *) &a[0] & mask) >> 6;
184
100k
        t         += (*(const uint64_t *) &a[8] & mask) >> 6;
185
100k
        t         += (*(const uint64_t *) &l[0] & mask) >> 6;
186
100k
        t         += (*(const uint64_t *) &l[8] & mask) >> 6;
187
100k
        t *= mul;
188
100k
        s = (int) (t >> 56) - 16 - 16;
189
100k
        break;
190
0
    }
191
107k
    case RTX_4X8: {
192
107k
        uint32_t t = *(const uint8_t  *) a & (uint32_t) mask;
193
107k
        t         += *(const uint16_t *) l & (uint32_t) mask;
194
107k
        t *= 0x04040404U;
195
107k
        s = (int) (t >> 24) - 1 - 2;
196
107k
        break;
197
0
    }
198
154k
    case RTX_8X4: {
199
154k
        uint32_t t = *(const uint16_t *) a & (uint32_t) mask;
200
154k
        t         += *(const uint8_t  *) l & (uint32_t) mask;
201
154k
        t *= 0x04040404U;
202
154k
        s = (int) (t >> 24) - 2 - 1;
203
154k
        break;
204
0
    }
205
91.2k
    case RTX_8X16: {
206
91.2k
        uint32_t t = *(const uint16_t *) a & (uint32_t) mask;
207
91.2k
        t         += *(const uint32_t *) l & (uint32_t) mask;
208
91.2k
        t = (t >> 6) * (uint32_t) mul;
209
91.2k
        s = (int) (t >> 24) - 2 - 4;
210
91.2k
        break;
211
0
    }
212
112k
    case RTX_16X8: {
213
112k
        uint32_t t = *(const uint32_t *) a & (uint32_t) mask;
214
112k
        t         += *(const uint16_t *) l & (uint32_t) mask;
215
112k
        t = (t >> 6) * (uint32_t) mul;
216
112k
        s = (int) (t >> 24) - 4 - 2;
217
112k
        break;
218
0
    }
219
45.8k
    case RTX_16X32: {
220
45.8k
        uint64_t t = *(const uint32_t *) a & (uint32_t) mask;
221
45.8k
        t         += *(const uint64_t *) l & mask;
222
45.8k
        t = (t >> 6) * mul;
223
45.8k
        s = (int) (t >> 56) - 4 - 8;
224
45.8k
        break;
225
0
    }
226
39.4k
    case RTX_32X16: {
227
39.4k
        uint64_t t = *(const uint64_t *) a & mask;
228
39.4k
        t         += *(const uint32_t *) l & (uint32_t) mask;
229
39.4k
        t = (t >> 6) * mul;
230
39.4k
        s = (int) (t >> 56) - 8 - 4;
231
39.4k
        break;
232
0
    }
233
18.7k
    case RTX_32X64: {
234
18.7k
        uint64_t t = (*(const uint64_t *) &a[0] & mask) >> 6;
235
18.7k
        t         += (*(const uint64_t *) &l[0] & mask) >> 6;
236
18.7k
        t         += (*(const uint64_t *) &l[8] & mask) >> 6;
237
18.7k
        t *= mul;
238
18.7k
        s = (int) (t >> 56) - 8 - 16;
239
18.7k
        break;
240
0
    }
241
10.5k
    case RTX_64X32: {
242
10.5k
        uint64_t t = (*(const uint64_t *) &a[0] & mask) >> 6;
243
10.5k
        t         += (*(const uint64_t *) &a[8] & mask) >> 6;
244
10.5k
        t         += (*(const uint64_t *) &l[0] & mask) >> 6;
245
10.5k
        t *= mul;
246
10.5k
        s = (int) (t >> 56) - 16 - 8;
247
10.5k
        break;
248
0
    }
249
44.2k
    case RTX_4X16: {
250
44.2k
        uint32_t t = *(const uint8_t  *) a & (uint32_t) mask;
251
44.2k
        t         += *(const uint32_t *) l & (uint32_t) mask;
252
44.2k
        t = (t >> 6) * (uint32_t) mul;
253
44.2k
        s = (int) (t >> 24) - 1 - 4;
254
44.2k
        break;
255
0
    }
256
94.2k
    case RTX_16X4: {
257
94.2k
        uint32_t t = *(const uint32_t *) a & (uint32_t) mask;
258
94.2k
        t         += *(const uint8_t  *) l & (uint32_t) mask;
259
94.2k
        t = (t >> 6) * (uint32_t) mul;
260
94.2k
        s = (int) (t >> 24) - 4 - 1;
261
94.2k
        break;
262
0
    }
263
22.9k
    case RTX_8X32: {
264
22.9k
        uint64_t t = *(const uint16_t *) a & (uint32_t) mask;
265
22.9k
        t         += *(const uint64_t *) l & mask;
266
22.9k
        t = (t >> 6) * mul;
267
22.9k
        s = (int) (t >> 56) - 2 - 8;
268
22.9k
        break;
269
0
    }
270
37.5k
    case RTX_32X8: {
271
37.5k
        uint64_t t = *(const uint64_t *) a & mask;
272
37.5k
        t         += *(const uint16_t *) l & (uint32_t) mask;
273
37.5k
        t = (t >> 6) * mul;
274
37.5k
        s = (int) (t >> 56) - 8 - 2;
275
37.5k
        break;
276
0
    }
277
10.7k
    case RTX_16X64: {
278
10.7k
        uint64_t t = *(const uint32_t *) a & (uint32_t) mask;
279
10.7k
        t         += *(const uint64_t *) &l[0] & mask;
280
10.7k
        t = (t >> 6) + ((*(const uint64_t *) &l[8] & mask) >> 6);
281
10.7k
        t *= mul;
282
10.7k
        s = (int) (t >> 56) - 4 - 16;
283
10.7k
        break;
284
0
    }
285
7.12k
    case RTX_64X16: {
286
7.12k
        uint64_t t = *(const uint64_t *) &a[0] & mask;
287
7.12k
        t         += *(const uint32_t *) l & (uint32_t) mask;
288
7.12k
        t = (t >> 6) + ((*(const uint64_t *) &a[8] & mask) >> 6);
289
7.12k
        t *= mul;
290
7.12k
        s = (int) (t >> 56) - 16 - 4;
291
7.12k
        break;
292
0
    }
293
2.70M
    }
294
295
2.70M
    return (s != 0) + (s > 0);
296
2.70M
}
297
298
static inline unsigned get_lo_ctx(const uint8_t *const levels,
299
                                  const enum TxClass tx_class,
300
                                  unsigned *const hi_mag,
301
                                  const uint8_t (*const ctx_offsets)[5],
302
                                  const unsigned x, const unsigned y,
303
                                  const ptrdiff_t stride)
304
57.4M
{
305
57.4M
    unsigned mag = levels[0 * stride + 1] + levels[1 * stride + 0];
306
57.4M
    unsigned offset;
307
57.4M
    if (tx_class == TX_CLASS_2D) {
308
52.3M
        mag += levels[1 * stride + 1];
309
52.3M
        *hi_mag = mag;
310
52.3M
        mag += levels[0 * stride + 2] + levels[2 * stride + 0];
311
52.3M
        offset = ctx_offsets[umin(y, 4)][umin(x, 4)];
312
52.3M
    } else {
313
5.07M
        mag += levels[0 * stride + 2];
314
5.07M
        *hi_mag = mag;
315
5.07M
        mag += levels[0 * stride + 3] + levels[0 * stride + 4];
316
5.07M
        offset = 26 + (y > 1 ? 10 : y * 5);
317
5.07M
    }
318
57.4M
    return offset + (mag > 512 ? 4 : (mag + 64) >> 7);
319
57.4M
}
320
321
static int decode_coefs(Dav1dTaskContext *const t,
322
                        uint8_t *const a, uint8_t *const l,
323
                        const enum RectTxfmSize tx, const enum BlockSize bs,
324
                        const Av1Block *const b, const int intra,
325
                        const int plane, coef *cf,
326
                        enum TxfmType *const txtp, uint8_t *res_ctx)
327
5.42M
{
328
5.42M
    Dav1dTileState *const ts = t->ts;
329
5.42M
    const int chroma = !!plane;
330
5.42M
    const Dav1dFrameContext *const f = t->f;
331
5.42M
    const int lossless = f->frame_hdr->segmentation.lossless[b->seg_id];
332
5.42M
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[tx];
333
5.42M
    const int dbg = DEBUG_BLOCK_INFO && plane && 0;
334
335
5.42M
    if (dbg)
336
0
        printf("Start: r=%d\n", ts->msac.rng);
337
338
    // does this block have any non-zero coefficients
339
5.42M
    const int sctx = get_skip_ctx(t_dim, bs, a, l, chroma, f->cur.p.layout);
340
5.42M
    const int all_skip = dav1d_msac_decode_bool_adapt(&ts->msac,
341
5.42M
                             ts->cdf.coef.skip[t_dim->ctx][sctx]);
342
5.42M
    if (dbg)
343
0
        printf("Post-non-zero[%d][%d][%d]: r=%d\n",
344
0
               t_dim->ctx, sctx, all_skip, ts->msac.rng);
345
5.42M
    if (all_skip) {
346
2.16M
        *res_ctx = 0x40;
347
2.16M
        *txtp = lossless * WHT_WHT; /* lossless ? WHT_WHT : DCT_DCT */
348
2.16M
        return -1;
349
2.16M
    }
350
351
    // transform type (chroma: derived, luma: explicitly coded)
352
3.26M
    if (lossless) {
353
791k
        assert(t_dim->max == TX_4X4);
354
791k
        *txtp = WHT_WHT;
355
2.47M
    } else if (t_dim->max + intra >= TX_64X64) {
356
476k
        *txtp = DCT_DCT;
357
1.99M
    } else if (chroma) {
358
        // inferred from either the luma txtp (inter) or a LUT (intra)
359
523k
        *txtp = intra ? dav1d_txtp_from_uvmode[b->uv_mode] :
360
523k
                        get_uv_inter_txtp(t_dim, *txtp);
361
1.47M
    } else if (!f->frame_hdr->segmentation.qidx[b->seg_id]) {
362
        // In libaom, lossless is checked by a literal qidx == 0, but not all
363
        // such blocks are actually lossless. The remainder gets an implicit
364
        // transform type (for luma)
365
3.15k
        *txtp = DCT_DCT;
366
1.46M
    } else {
367
1.46M
        unsigned idx;
368
1.46M
        if (intra) {
369
1.04M
            const enum IntraPredMode y_mode_nofilt = b->y_mode == FILTER_PRED ?
370
871k
                dav1d_filter_mode_to_y_mode[b->y_angle] : b->y_mode;
371
1.04M
            if (f->frame_hdr->reduced_txtp_set || t_dim->min == TX_16X16) {
372
419k
                idx = dav1d_msac_decode_symbol_adapt8(&ts->msac,
373
419k
                          ts->cdf.m.txtp_intra2[t_dim->min][y_mode_nofilt], 4);
374
419k
                *txtp = dav1d_tx_types_per_set[idx + 0];
375
624k
            } else {
376
624k
                idx = dav1d_msac_decode_symbol_adapt8(&ts->msac,
377
624k
                          ts->cdf.m.txtp_intra1[t_dim->min][y_mode_nofilt], 6);
378
624k
                *txtp = dav1d_tx_types_per_set[idx + 5];
379
624k
            }
380
1.04M
            if (dbg)
381
0
                printf("Post-txtp-intra[%d->%d][%d][%d->%d]: r=%d\n",
382
0
                       tx, t_dim->min, y_mode_nofilt, idx, *txtp, ts->msac.rng);
383
1.04M
        } else {
384
424k
            if (f->frame_hdr->reduced_txtp_set || t_dim->max == TX_32X32) {
385
119k
                idx = dav1d_msac_decode_bool_adapt(&ts->msac,
386
119k
                          ts->cdf.m.txtp_inter3[t_dim->min]);
387
119k
                *txtp = (idx - 1) & IDTX; /* idx ? DCT_DCT : IDTX */
388
304k
            } else if (t_dim->min == TX_16X16) {
389
31.9k
                idx = dav1d_msac_decode_symbol_adapt16(&ts->msac,
390
31.9k
                          ts->cdf.m.txtp_inter2, 11);
391
31.9k
                *txtp = dav1d_tx_types_per_set[idx + 12];
392
272k
            } else {
393
272k
                idx = dav1d_msac_decode_symbol_adapt16(&ts->msac,
394
272k
                          ts->cdf.m.txtp_inter1[t_dim->min], 15);
395
272k
                *txtp = dav1d_tx_types_per_set[idx + 24];
396
272k
            }
397
424k
            if (dbg)
398
0
                printf("Post-txtp-inter[%d->%d][%d->%d]: r=%d\n",
399
0
                       tx, t_dim->min, idx, *txtp, ts->msac.rng);
400
424k
        }
401
1.46M
    }
402
403
    // find end-of-block (eob)
404
3.26M
    int eob;
405
3.26M
    const int slw = imin(t_dim->lw, TX_32X32), slh = imin(t_dim->lh, TX_32X32);
406
3.26M
    const int tx2dszctx = slw + slh;
407
3.26M
    const enum TxClass tx_class = dav1d_tx_type_class[*txtp];
408
3.26M
    const int is_1d = tx_class != TX_CLASS_2D;
409
3.26M
    switch (tx2dszctx) {
410
0
#define case_sz(sz, bin, ns, is_1d) \
411
3.26M
    case sz: { \
412
3.26M
        uint16_t *const eob_bin_cdf = ts->cdf.coef.eob_bin_##bin[chroma]is_1d; \
413
3.26M
        eob = dav1d_msac_decode_symbol_adapt##ns(&ts->msac, eob_bin_cdf, 4 + sz); \
414
3.26M
        break; \
415
3.26M
    }
416
1.17M
    case_sz(0,   16,  8, [is_1d]);
417
352k
    case_sz(1,   32,  8, [is_1d]);
418
645k
    case_sz(2,   64,  8, [is_1d]);
419
278k
    case_sz(3,  128,  8, [is_1d]);
420
358k
    case_sz(4,  256, 16, [is_1d]);
421
118k
    case_sz(5,  512, 16,        );
422
339k
    case_sz(6, 1024, 16,        );
423
3.26M
#undef case_sz
424
3.26M
    }
425
3.26M
    if (dbg)
426
0
        printf("Post-eob_bin_%d[%d][%d][%d]: r=%d\n",
427
0
               16 << tx2dszctx, chroma, is_1d, eob, ts->msac.rng);
428
3.26M
    if (eob > 1) {
429
1.95M
        const int eob_bin = eob - 2;
430
1.95M
        uint16_t *const eob_hi_bit_cdf =
431
1.95M
            ts->cdf.coef.eob_hi_bit[t_dim->ctx][chroma][eob_bin];
432
1.95M
        const int eob_hi_bit = dav1d_msac_decode_bool_adapt(&ts->msac, eob_hi_bit_cdf);
433
1.95M
        if (dbg)
434
0
            printf("Post-eob_hi_bit[%d][%d][%d][%d]: r=%d\n",
435
0
                   t_dim->ctx, chroma, eob_bin, eob_hi_bit, ts->msac.rng);
436
1.95M
        eob = ((eob_hi_bit | 2) << eob_bin) | dav1d_msac_decode_bools(&ts->msac, eob_bin);
437
1.95M
        if (dbg)
438
0
            printf("Post-eob[%d]: r=%d\n", eob, ts->msac.rng);
439
1.95M
    }
440
3.26M
    assert(eob >= 0);
441
442
    // base tokens
443
3.26M
    uint16_t (*const eob_cdf)[4] = ts->cdf.coef.eob_base_tok[t_dim->ctx][chroma];
444
3.26M
    uint16_t (*const hi_cdf)[4] = ts->cdf.coef.br_tok[imin(t_dim->ctx, 3)][chroma];
445
3.26M
    unsigned rc, dc_tok;
446
447
3.26M
    if (eob) {
448
2.04M
        uint16_t (*const lo_cdf)[4] = ts->cdf.coef.base_tok[t_dim->ctx][chroma];
449
2.04M
        uint8_t *const levels = t->scratch.levels; // bits 0-5: tok, 6-7: lo_tok
450
451
        /* eob */
452
2.04M
        unsigned ctx = 1 + (eob > 2 << tx2dszctx) + (eob > 4 << tx2dszctx);
453
2.04M
        int eob_tok = dav1d_msac_decode_symbol_adapt4(&ts->msac, eob_cdf[ctx], 2);
454
2.04M
        int tok = eob_tok + 1;
455
2.04M
        int level_tok = tok * 0x41;
456
2.04M
        unsigned mag;
457
458
2.04M
#define DECODE_COEFS_CLASS(tx_class) \
459
2.04M
        unsigned x, y; \
460
2.04M
        uint8_t *level; \
461
2.04M
        if (tx_class == TX_CLASS_2D) \
462
2.04M
            rc = scan[eob], x = rc >> shift, y = rc & mask; \
463
2.04M
        else if (tx_class == TX_CLASS_H) \
464
            /* Transposing reduces the stride and padding requirements */ \
465
217k
            x = eob & mask, y = eob >> shift, rc = eob; \
466
217k
        else /* tx_class == TX_CLASS_V */ \
467
217k
            x = eob & mask, y = eob >> shift, rc = (x << shift2) | y; \
468
2.04M
        if (dbg) \
469
2.04M
            printf("Post-lo_tok[%d][%d][%d][%d=%d=%d]: r=%d\n", \
470
0
                   t_dim->ctx, chroma, ctx, eob, rc, tok, ts->msac.rng); \
471
2.04M
        if (eob_tok == 2) { \
472
45.5k
            ctx = (tx_class == TX_CLASS_2D ? (x | y) > 1 : y != 0) ? 14 : 7; \
473
45.5k
            tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[ctx]); \
474
45.5k
            level_tok = tok + (3 << 6); \
475
45.5k
            if (dbg) \
476
45.5k
                printf("Post-hi_tok[%d][%d][%d][%d=%d=%d]: r=%d\n", \
477
0
                       imin(t_dim->ctx, 3), chroma, ctx, eob, rc, tok, \
478
0
                       ts->msac.rng); \
479
45.5k
        } \
480
2.04M
        cf[rc] = tok << 11; \
481
2.04M
        if (tx_class == TX_CLASS_2D) \
482
2.04M
            level = levels + rc; \
483
2.04M
        else \
484
2.04M
            level = levels + x * stride + y; \
485
2.04M
        *level = (uint8_t) level_tok; \
486
59.2M
        for (int i = eob - 1; i > 0; i--) { /* ac */ \
487
57.2M
            unsigned rc_i; \
488
57.2M
            if (tx_class == TX_CLASS_2D) \
489
57.2M
                rc_i = scan[i], x = rc_i >> shift, y = rc_i & mask; \
490
57.2M
            else if (tx_class == TX_CLASS_H) \
491
4.88M
                x = i & mask, y = i >> shift, rc_i = i; \
492
4.88M
            else /* tx_class == TX_CLASS_V */ \
493
4.88M
                x = i & mask, y = i >> shift, rc_i = (x << shift2) | y; \
494
57.2M
            assert(x < 32 && y < 32); \
495
57.2M
            if (tx_class == TX_CLASS_2D) \
496
57.2M
                level = levels + rc_i; \
497
57.2M
            else \
498
57.2M
                level = levels + x * stride + y; \
499
57.2M
            ctx = get_lo_ctx(level, tx_class, &mag, lo_ctx_offsets, x, y, stride); \
500
57.2M
            if (tx_class == TX_CLASS_2D) \
501
57.2M
                y |= x; \
502
57.2M
            tok = dav1d_msac_decode_symbol_adapt4(&ts->msac, lo_cdf[ctx], 3); \
503
57.2M
            if (dbg) \
504
57.2M
                printf("Post-lo_tok[%d][%d][%d][%d=%d=%d]: r=%d\n", \
505
0
                       t_dim->ctx, chroma, ctx, i, rc_i, tok, ts->msac.rng); \
506
57.2M
            if (tok == 3) { \
507
4.61M
                mag &= 63; \
508
4.61M
                ctx = (y > (tx_class == TX_CLASS_2D) ? 14 : 7) + \
509
4.61M
                      (mag > 12 ? 6 : (mag + 1) >> 1); \
510
4.61M
                tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[ctx]); \
511
4.61M
                if (dbg) \
512
4.61M
                    printf("Post-hi_tok[%d][%d][%d][%d=%d=%d]: r=%d\n", \
513
0
                           imin(t_dim->ctx, 3), chroma, ctx, i, rc_i, tok, \
514
0
                           ts->msac.rng); \
515
4.61M
                *level = (uint8_t) (tok + (3 << 6)); \
516
4.61M
                cf[rc_i] = (tok << 11) | rc; \
517
4.61M
                rc = rc_i; \
518
52.6M
            } else { \
519
                /* 0x1 for tok, 0x7ff as bitmask for rc, 0x41 for level_tok */ \
520
52.6M
                tok *= 0x17ff41; \
521
52.6M
                *level = (uint8_t) tok; \
522
                /* tok ? (tok << 11) | rc : 0 */ \
523
52.6M
                tok = (tok >> 9) & (rc + ~0x7ffu); \
524
52.6M
                if (tok) rc = rc_i; \
525
52.6M
                cf[rc_i] = tok; \
526
52.6M
            } \
527
57.2M
        } \
528
        /* dc */ \
529
2.04M
        ctx = (tx_class == TX_CLASS_2D) ? 0 : \
530
2.04M
            get_lo_ctx(levels, tx_class, &mag, lo_ctx_offsets, 0, 0, stride); \
531
2.04M
        dc_tok = dav1d_msac_decode_symbol_adapt4(&ts->msac, lo_cdf[ctx], 3); \
532
2.04M
        if (dbg) \
533
2.04M
            printf("Post-dc_lo_tok[%d][%d][%d][%d]: r=%d\n", \
534
0
                   t_dim->ctx, chroma, ctx, dc_tok, ts->msac.rng); \
535
2.04M
        if (dc_tok == 3) { \
536
731k
            if (tx_class == TX_CLASS_2D) \
537
731k
                mag = levels[0 * stride + 1] + levels[1 * stride + 0] + \
538
710k
                      levels[1 * stride + 1]; \
539
731k
            mag &= 63; \
540
731k
            ctx = mag > 12 ? 6 : (mag + 1) >> 1; \
541
731k
            dc_tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[ctx]); \
542
731k
            if (dbg) \
543
731k
                printf("Post-dc_hi_tok[%d][%d][0][%d]: r=%d\n", \
544
0
                       imin(t_dim->ctx, 3), chroma, dc_tok, ts->msac.rng); \
545
731k
        } \
546
2.04M
        break
547
548
2.04M
        const uint16_t *scan;
549
2.04M
        switch (tx_class) {
550
1.83M
        case TX_CLASS_2D: {
551
1.83M
            const unsigned nonsquare_tx = tx >= RTX_4X8;
552
1.83M
            const uint8_t (*const lo_ctx_offsets)[5] =
553
1.83M
                dav1d_lo_ctx_offsets[nonsquare_tx + (tx & nonsquare_tx)];
554
1.83M
            scan = dav1d_scans[tx];
555
1.83M
            const ptrdiff_t stride = 4 << slh;
556
1.83M
            const unsigned shift = slh + 2, shift2 = 0;
557
1.83M
            const unsigned mask = (4 << slh) - 1;
558
1.83M
            memset(levels, 0, stride * ((4 << slw) + 2));
559
1.83M
            DECODE_COEFS_CLASS(TX_CLASS_2D);
560
1.83M
        }
561
139k
        case TX_CLASS_H: {
562
139k
            const uint8_t (*const lo_ctx_offsets)[5] = NULL;
563
139k
            const ptrdiff_t stride = 16;
564
139k
            const unsigned shift = slh + 2, shift2 = 0;
565
139k
            const unsigned mask = (4 << slh) - 1;
566
139k
            memset(levels, 0, stride * ((4 << slh) + 2));
567
139k
            DECODE_COEFS_CLASS(TX_CLASS_H);
568
139k
        }
569
77.7k
        case TX_CLASS_V: {
570
77.7k
            const uint8_t (*const lo_ctx_offsets)[5] = NULL;
571
77.7k
            const ptrdiff_t stride = 16;
572
77.7k
            const unsigned shift = slw + 2, shift2 = slh + 2;
573
77.7k
            const unsigned mask = (4 << slw) - 1;
574
77.7k
            memset(levels, 0, stride * ((4 << slw) + 2));
575
77.7k
            DECODE_COEFS_CLASS(TX_CLASS_V);
576
77.7k
        }
577
0
#undef DECODE_COEFS_CLASS
578
0
        default: assert(0);
579
2.04M
        }
580
2.04M
    } else { // dc-only
581
1.21M
        int tok_br = dav1d_msac_decode_symbol_adapt4(&ts->msac, eob_cdf[0], 2);
582
1.21M
        dc_tok = 1 + tok_br;
583
1.21M
        if (dbg)
584
0
            printf("Post-dc_lo_tok[%d][%d][%d][%d]: r=%d\n",
585
0
                   t_dim->ctx, chroma, 0, dc_tok, ts->msac.rng);
586
1.21M
        if (tok_br == 2) {
587
34.0k
            dc_tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[0]);
588
34.0k
            if (dbg)
589
0
                printf("Post-dc_hi_tok[%d][%d][0][%d]: r=%d\n",
590
0
                       imin(t_dim->ctx, 3), chroma, dc_tok, ts->msac.rng);
591
34.0k
        }
592
1.21M
        rc = 0;
593
1.21M
    }
594
595
    // residual and sign
596
3.26M
    const uint16_t *const dq_tbl = ts->dq[b->seg_id][plane];
597
3.26M
    const uint8_t *const qm_tbl = *txtp < IDTX ? f->qm[tx][plane] : NULL;
598
3.26M
    const int dq_shift = imax(0, t_dim->ctx - 2);
599
3.26M
    const int cf_max = ~(~127U << (BITDEPTH == 8 ? 8 : f->cur.p.bpc));
600
3.26M
    unsigned cul_level, dc_sign_level;
601
602
3.26M
    if (!dc_tok) {
603
556k
        cul_level = 0;
604
556k
        dc_sign_level = 1 << 6;
605
556k
        if (qm_tbl) goto ac_qm;
606
371k
        goto ac_noqm;
607
556k
    }
608
609
2.70M
    const int dc_sign_ctx = get_dc_sign_ctx(tx, a, l);
610
2.70M
    uint16_t *const dc_sign_cdf = ts->cdf.coef.dc_sign[chroma][dc_sign_ctx];
611
2.70M
    const int dc_sign = dav1d_msac_decode_bool_adapt(&ts->msac, dc_sign_cdf);
612
2.70M
    if (dbg)
613
0
        printf("Post-dc_sign[%d][%d][%d]: r=%d\n",
614
0
               chroma, dc_sign_ctx, dc_sign, ts->msac.rng);
615
616
2.70M
    int dc_dq = dq_tbl[0];
617
2.70M
    dc_sign_level = (dc_sign - 1) & (2 << 6);
618
619
2.70M
    if (qm_tbl) {
620
933k
        dc_dq = (dc_dq * qm_tbl[0] + 16) >> 5;
621
622
933k
        if (dc_tok == 15) {
623
27.8k
            dc_tok = read_golomb(&ts->msac) + 15;
624
27.8k
            if (dbg)
625
0
                printf("Post-dc_residual[%d->%d]: r=%d\n",
626
0
                       dc_tok - 15, dc_tok, ts->msac.rng);
627
628
27.8k
            dc_tok &= 0xfffff;
629
27.8k
            dc_dq = (dc_dq * dc_tok) & 0xffffff;
630
905k
        } else {
631
905k
            dc_dq *= dc_tok;
632
905k
            assert(dc_dq <= 0xffffff);
633
905k
        }
634
933k
        cul_level = dc_tok;
635
933k
        dc_dq >>= dq_shift;
636
933k
        dc_dq = umin(dc_dq, cf_max + dc_sign);
637
933k
        cf[0] = (coef) (dc_sign ? -dc_dq : dc_dq);
638
639
1.40M
        if (rc) ac_qm: {
640
1.40M
            const unsigned ac_dq = dq_tbl[1];
641
9.84M
            do {
642
9.84M
                const int sign = dav1d_msac_decode_bool_equi(&ts->msac);
643
9.84M
                if (dbg)
644
0
                    printf("Post-sign[%d=%d]: r=%d\n", rc, sign, ts->msac.rng);
645
9.84M
                const unsigned rc_tok = cf[rc];
646
9.84M
                unsigned tok, dq = (ac_dq * qm_tbl[rc] + 16) >> 5;
647
9.84M
                int dq_sat;
648
649
9.84M
                if (rc_tok >= (15 << 11)) {
650
681k
                    tok = read_golomb(&ts->msac) + 15;
651
681k
                    if (dbg)
652
0
                        printf("Post-residual[%d=%d->%d]: r=%d\n",
653
0
                               rc, tok - 15, tok, ts->msac.rng);
654
655
681k
                    tok &= 0xfffff;
656
681k
                    dq = (dq * tok) & 0xffffff;
657
9.16M
                } else {
658
9.16M
                    tok = rc_tok >> 11;
659
9.16M
                    dq *= tok;
660
9.16M
                    assert(dq <= 0xffffff);
661
9.16M
                }
662
9.84M
                cul_level += tok;
663
9.84M
                dq >>= dq_shift;
664
9.84M
                dq_sat = umin(dq, cf_max + sign);
665
9.84M
                cf[rc] = (coef) (sign ? -dq_sat : dq_sat);
666
667
9.84M
                rc = rc_tok & 0x3ff;
668
9.84M
            } while (rc);
669
1.40M
        }
670
1.77M
    } else {
671
        // non-qmatrix is the common case and allows for additional optimizations
672
1.77M
        if (dc_tok == 15) {
673
49.2k
            dc_tok = read_golomb(&ts->msac) + 15;
674
49.2k
            if (dbg)
675
0
                printf("Post-dc_residual[%d->%d]: r=%d\n",
676
0
                       dc_tok - 15, dc_tok, ts->msac.rng);
677
678
49.2k
            dc_tok &= 0xfffff;
679
49.2k
            dc_dq = ((dc_dq * dc_tok) & 0xffffff) >> dq_shift;
680
49.2k
            dc_dq = umin(dc_dq, cf_max + dc_sign);
681
1.72M
        } else {
682
1.72M
            dc_dq = ((dc_dq * dc_tok) >> dq_shift);
683
1.72M
            assert(dc_dq <= cf_max);
684
1.72M
        }
685
1.77M
        cul_level = dc_tok;
686
1.77M
        cf[0] = (coef) (dc_sign ? -dc_dq : dc_dq);
687
688
2.13M
        if (rc) ac_noqm: {
689
2.13M
            const unsigned ac_dq = dq_tbl[1];
690
12.0M
            do {
691
12.0M
                const int sign = dav1d_msac_decode_bool_equi(&ts->msac);
692
12.0M
                if (dbg)
693
0
                    printf("Post-sign[%d=%d]: r=%d\n", rc, sign, ts->msac.rng);
694
12.0M
                const unsigned rc_tok = cf[rc];
695
12.0M
                unsigned tok;
696
12.0M
                int dq;
697
698
                // residual
699
12.0M
                if (rc_tok >= (15 << 11)) {
700
273k
                    tok = read_golomb(&ts->msac) + 15;
701
273k
                    if (dbg)
702
0
                        printf("Post-residual[%d=%d->%d]: r=%d\n",
703
0
                               rc, tok - 15, tok, ts->msac.rng);
704
705
                    // coefficient parsing, see 5.11.39
706
273k
                    tok &= 0xfffff;
707
708
                    // dequant, see 7.12.3
709
273k
                    dq = ((ac_dq * tok) & 0xffffff) >> dq_shift;
710
273k
                    dq = umin(dq, cf_max + sign);
711
11.7M
                } else {
712
                    // cannot exceed cf_max, so we can avoid the clipping
713
11.7M
                    tok = rc_tok >> 11;
714
11.7M
                    dq = ((ac_dq * tok) >> dq_shift);
715
11.7M
                    assert(dq <= cf_max);
716
11.7M
                }
717
12.0M
                cul_level += tok;
718
12.0M
                cf[rc] = (coef) (sign ? -dq : dq);
719
720
12.0M
                rc = rc_tok & 0x3ff; // next non-zero rc, zero if eob
721
12.0M
            } while (rc);
722
2.13M
        }
723
1.77M
    }
724
725
    // context
726
3.26M
    *res_ctx = umin(cul_level, 63) | dc_sign_level;
727
728
3.26M
    return eob;
729
2.70M
}
730
731
static void read_coef_tree(Dav1dTaskContext *const t,
732
                           const enum BlockSize bs, const Av1Block *const b,
733
                           const enum RectTxfmSize ytx, const int depth,
734
                           const uint16_t *const tx_split,
735
                           const int x_off, const int y_off, pixel *dst)
736
899k
{
737
899k
    const Dav1dFrameContext *const f = t->f;
738
899k
    Dav1dTileState *const ts = t->ts;
739
899k
    const Dav1dDSPContext *const dsp = f->dsp;
740
899k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[ytx];
741
899k
    const int txw = t_dim->w, txh = t_dim->h;
742
743
    /* y_off can be larger than 3 since lossless blocks use TX_4X4 but can't
744
     * be splitted. Aviods an undefined left shift. */
745
899k
    if (depth < 2 && tx_split[depth] &&
746
98.3k
        tx_split[depth] & (1 << (y_off * 4 + x_off)))
747
73.7k
    {
748
73.7k
        const enum RectTxfmSize sub = t_dim->sub;
749
73.7k
        const TxfmInfo *const sub_t_dim = &dav1d_txfm_dimensions[sub];
750
73.7k
        const int txsw = sub_t_dim->w, txsh = sub_t_dim->h;
751
752
73.7k
        read_coef_tree(t, bs, b, sub, depth + 1, tx_split,
753
73.7k
                       x_off * 2 + 0, y_off * 2 + 0, dst);
754
73.7k
        t->bx += txsw;
755
73.7k
        if (txw >= txh && t->bx < f->bw)
756
60.0k
            read_coef_tree(t, bs, b, sub, depth + 1, tx_split, x_off * 2 + 1,
757
60.0k
                           y_off * 2 + 0, dst ? &dst[4 * txsw] : NULL);
758
73.7k
        t->bx -= txsw;
759
73.7k
        t->by += txsh;
760
73.7k
        if (txh >= txw && t->by < f->bh) {
761
51.6k
            if (dst)
762
16.1k
                dst += 4 * txsh * PXSTRIDE(f->cur.stride[0]);
763
51.6k
            read_coef_tree(t, bs, b, sub, depth + 1, tx_split,
764
51.6k
                           x_off * 2 + 0, y_off * 2 + 1, dst);
765
51.6k
            t->bx += txsw;
766
51.6k
            if (txw >= txh && t->bx < f->bw)
767
38.1k
                read_coef_tree(t, bs, b, sub, depth + 1, tx_split, x_off * 2 + 1,
768
38.1k
                               y_off * 2 + 1, dst ? &dst[4 * txsw] : NULL);
769
51.6k
            t->bx -= txsw;
770
51.6k
        }
771
73.7k
        t->by -= txsh;
772
826k
    } else {
773
826k
        const int bx4 = t->bx & 31, by4 = t->by & 31;
774
826k
        enum TxfmType txtp;
775
826k
        uint8_t cf_ctx;
776
826k
        int eob;
777
826k
        coef *cf;
778
779
826k
        if (t->frame_thread.pass) {
780
826k
            const int p = t->frame_thread.pass & 1;
781
826k
            assert(ts->frame_thread[p].cf);
782
826k
            cf = ts->frame_thread[p].cf;
783
826k
            ts->frame_thread[p].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
784
18.4E
        } else {
785
18.4E
            cf = bitfn(t->cf);
786
18.4E
        }
787
826k
        if (t->frame_thread.pass != 2) {
788
560k
            eob = decode_coefs(t, &t->a->lcoef[bx4], &t->l.lcoef[by4],
789
560k
                               ytx, bs, b, 0, 0, cf, &txtp, &cf_ctx);
790
560k
            if (DEBUG_BLOCK_INFO)
791
0
                printf("Post-y-cf-blk[tx=%d,txtp=%d,eob=%d]: r=%d\n",
792
0
                       ytx, txtp, eob, ts->msac.rng);
793
560k
            dav1d_memset_likely_pow2(&t->a->lcoef[bx4], cf_ctx, imin(txw, f->bw - t->bx));
794
560k
            dav1d_memset_likely_pow2(&t->l.lcoef[by4], cf_ctx, imin(txh, f->bh - t->by));
795
560k
#define set_ctx(rep_macro) \
796
2.18M
            for (int y = 0; y < txh; y++) { \
797
1.62M
                rep_macro(txtp_map, 0, txtp); \
798
1.62M
                txtp_map += 32; \
799
1.62M
            }
800
560k
            uint8_t *txtp_map = &t->scratch.txtp_map[by4 * 32 + bx4];
801
560k
            case_set_upto16(t_dim->lw);
802
560k
#undef set_ctx
803
560k
            if (t->frame_thread.pass == 1)
804
560k
                *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
805
560k
        } else {
806
265k
            const int cbi = *ts->frame_thread[0].cbi++;
807
265k
            eob  = cbi >> 5;
808
265k
            txtp = cbi & 0x1f;
809
265k
        }
810
826k
        if (!(t->frame_thread.pass & 1)) {
811
265k
            assert(dst);
812
265k
            if (eob >= 0) {
813
223k
                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
814
0
                    coef_dump(cf, imin(t_dim->h, 8) * 4, imin(t_dim->w, 8) * 4, 3, "dq");
815
223k
                dsp->itx.itxfm_add[ytx][txtp](dst, f->cur.stride[0], cf, eob
816
223k
                                              HIGHBD_CALL_SUFFIX);
817
223k
                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
818
0
                    hex_dump(dst, f->cur.stride[0], t_dim->w * 4, t_dim->h * 4, "recon");
819
223k
            }
820
265k
        }
821
826k
    }
822
899k
}
823
824
void bytefn(dav1d_read_coef_blocks)(Dav1dTaskContext *const t,
825
                                    const enum BlockSize bs, const Av1Block *const b)
826
3.17M
{
827
3.17M
    const Dav1dFrameContext *const f = t->f;
828
3.17M
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
829
3.17M
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
830
3.17M
    const int bx4 = t->bx & 31, by4 = t->by & 31;
831
3.17M
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
832
3.17M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
833
3.17M
    const int bw4 = b_dim[0], bh4 = b_dim[1];
834
3.17M
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
835
3.17M
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
836
2.34M
                           (bw4 > ss_hor || t->bx & 1) &&
837
2.15M
                           (bh4 > ss_ver || t->by & 1);
838
839
3.17M
    if (b->skip) {
840
1.72M
        BlockContext *const a = t->a;
841
1.72M
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
842
1.72M
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
843
1.72M
        if (has_chroma) {
844
976k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
845
976k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
846
976k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
847
976k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
848
976k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
849
976k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
850
976k
        }
851
1.72M
        return;
852
1.72M
    }
853
854
1.44M
    Dav1dTileState *const ts = t->ts;
855
1.44M
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
856
1.44M
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
857
1.44M
    assert(t->frame_thread.pass == 1);
858
1.44M
    assert(!b->skip);
859
1.44M
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
860
1.44M
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->intra ? b->tx : b->max_ytx];
861
1.44M
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
862
863
2.91M
    for (int init_y = 0; init_y < h4; init_y += 16) {
864
1.46M
        const int sub_h4 = imin(h4, 16 + init_y);
865
2.97M
        for (int init_x = 0; init_x < w4; init_x += 16) {
866
1.50M
            const int sub_w4 = imin(w4, init_x + 16);
867
1.50M
            int y_off = !!init_y, y, x;
868
3.24M
            for (y = init_y, t->by += init_y; y < sub_h4;
869
1.74M
                 y += t_dim->h, t->by += t_dim->h, y_off++)
870
1.74M
            {
871
1.74M
                int x_off = !!init_x;
872
4.56M
                for (x = init_x, t->bx += init_x; x < sub_w4;
873
2.82M
                     x += t_dim->w, t->bx += t_dim->w, x_off++)
874
2.82M
                {
875
2.82M
                    if (!b->intra) {
876
457k
                        read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
877
457k
                                       x_off, y_off, NULL);
878
2.36M
                    } else {
879
2.36M
                        uint8_t cf_ctx = 0x40;
880
2.36M
                        enum TxfmType txtp;
881
2.36M
                        const int eob =
882
2.36M
                            decode_coefs(t, &t->a->lcoef[bx4 + x],
883
2.36M
                                         &t->l.lcoef[by4 + y], b->tx, bs, b, 1,
884
2.36M
                                         0, ts->frame_thread[1].cf, &txtp, &cf_ctx);
885
2.36M
                        if (DEBUG_BLOCK_INFO)
886
0
                            printf("Post-y-cf-blk[tx=%d,txtp=%d,eob=%d]: r=%d\n",
887
0
                                   b->tx, txtp, eob, ts->msac.rng);
888
2.36M
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
889
2.36M
                        ts->frame_thread[1].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
890
2.36M
                        dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
891
2.36M
                        dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
892
2.36M
                    }
893
2.82M
                }
894
1.74M
                t->bx -= x;
895
1.74M
            }
896
1.50M
            t->by -= y;
897
898
1.50M
            if (!has_chroma) continue;
899
900
1.02M
            const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
901
1.02M
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
902
3.08M
            for (int pl = 0; pl < 2; pl++) {
903
4.21M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
904
2.15M
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
905
2.15M
                {
906
4.66M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
907
2.50M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
908
2.50M
                    {
909
2.50M
                        uint8_t cf_ctx = 0x40;
910
2.50M
                        enum TxfmType txtp;
911
2.50M
                        if (!b->intra)
912
569k
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
913
569k
                                                        bx4 + (x << ss_hor)];
914
2.50M
                        const int eob =
915
2.50M
                            decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
916
2.50M
                                         &t->l.ccoef[pl][cby4 + y], b->uvtx, bs,
917
2.50M
                                         b, b->intra, 1 + pl, ts->frame_thread[1].cf,
918
2.50M
                                         &txtp, &cf_ctx);
919
2.50M
                        if (DEBUG_BLOCK_INFO)
920
0
                            printf("Post-uv-cf-blk[pl=%d,tx=%d,"
921
0
                                   "txtp=%d,eob=%d]: r=%d\n",
922
0
                                   pl, b->uvtx, txtp, eob, ts->msac.rng);
923
2.50M
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
924
2.50M
                        ts->frame_thread[1].cf += uv_t_dim->w * uv_t_dim->h * 16;
925
2.50M
                        int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
926
2.50M
                        int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
927
2.50M
                        dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
928
2.50M
                        dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
929
2.50M
                    }
930
2.15M
                    t->bx -= x << ss_hor;
931
2.15M
                }
932
2.05M
                t->by -= y << ss_ver;
933
2.05M
            }
934
1.02M
        }
935
1.46M
    }
936
1.44M
}
dav1d_read_coef_blocks_8bpc
Line
Count
Source
826
1.71M
{
827
1.71M
    const Dav1dFrameContext *const f = t->f;
828
1.71M
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
829
1.71M
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
830
1.71M
    const int bx4 = t->bx & 31, by4 = t->by & 31;
831
1.71M
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
832
1.71M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
833
1.71M
    const int bw4 = b_dim[0], bh4 = b_dim[1];
834
1.71M
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
835
1.71M
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
836
1.12M
                           (bw4 > ss_hor || t->bx & 1) &&
837
1.02M
                           (bh4 > ss_ver || t->by & 1);
838
839
1.71M
    if (b->skip) {
840
940k
        BlockContext *const a = t->a;
841
940k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
842
940k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
843
940k
        if (has_chroma) {
844
468k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
845
468k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
846
468k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
847
468k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
848
468k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
849
468k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
850
468k
        }
851
940k
        return;
852
940k
    }
853
854
777k
    Dav1dTileState *const ts = t->ts;
855
777k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
856
777k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
857
777k
    assert(t->frame_thread.pass == 1);
858
777k
    assert(!b->skip);
859
777k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
860
777k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->intra ? b->tx : b->max_ytx];
861
777k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
862
863
1.56M
    for (int init_y = 0; init_y < h4; init_y += 16) {
864
784k
        const int sub_h4 = imin(h4, 16 + init_y);
865
1.58M
        for (int init_x = 0; init_x < w4; init_x += 16) {
866
796k
            const int sub_w4 = imin(w4, init_x + 16);
867
796k
            int y_off = !!init_y, y, x;
868
1.72M
            for (y = init_y, t->by += init_y; y < sub_h4;
869
929k
                 y += t_dim->h, t->by += t_dim->h, y_off++)
870
929k
            {
871
929k
                int x_off = !!init_x;
872
2.56M
                for (x = init_x, t->bx += init_x; x < sub_w4;
873
1.63M
                     x += t_dim->w, t->bx += t_dim->w, x_off++)
874
1.63M
                {
875
1.63M
                    if (!b->intra) {
876
265k
                        read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
877
265k
                                       x_off, y_off, NULL);
878
1.37M
                    } else {
879
1.37M
                        uint8_t cf_ctx = 0x40;
880
1.37M
                        enum TxfmType txtp;
881
1.37M
                        const int eob =
882
1.37M
                            decode_coefs(t, &t->a->lcoef[bx4 + x],
883
1.37M
                                         &t->l.lcoef[by4 + y], b->tx, bs, b, 1,
884
1.37M
                                         0, ts->frame_thread[1].cf, &txtp, &cf_ctx);
885
1.37M
                        if (DEBUG_BLOCK_INFO)
886
0
                            printf("Post-y-cf-blk[tx=%d,txtp=%d,eob=%d]: r=%d\n",
887
0
                                   b->tx, txtp, eob, ts->msac.rng);
888
1.37M
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
889
1.37M
                        ts->frame_thread[1].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
890
1.37M
                        dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
891
1.37M
                        dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
892
1.37M
                    }
893
1.63M
                }
894
929k
                t->bx -= x;
895
929k
            }
896
796k
            t->by -= y;
897
898
796k
            if (!has_chroma) continue;
899
900
468k
            const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
901
468k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
902
1.40M
            for (int pl = 0; pl < 2; pl++) {
903
1.92M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
904
984k
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
905
984k
                {
906
2.14M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
907
1.16M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
908
1.16M
                    {
909
1.16M
                        uint8_t cf_ctx = 0x40;
910
1.16M
                        enum TxfmType txtp;
911
1.16M
                        if (!b->intra)
912
297k
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
913
297k
                                                        bx4 + (x << ss_hor)];
914
1.16M
                        const int eob =
915
1.16M
                            decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
916
1.16M
                                         &t->l.ccoef[pl][cby4 + y], b->uvtx, bs,
917
1.16M
                                         b, b->intra, 1 + pl, ts->frame_thread[1].cf,
918
1.16M
                                         &txtp, &cf_ctx);
919
1.16M
                        if (DEBUG_BLOCK_INFO)
920
0
                            printf("Post-uv-cf-blk[pl=%d,tx=%d,"
921
0
                                   "txtp=%d,eob=%d]: r=%d\n",
922
0
                                   pl, b->uvtx, txtp, eob, ts->msac.rng);
923
1.16M
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
924
1.16M
                        ts->frame_thread[1].cf += uv_t_dim->w * uv_t_dim->h * 16;
925
1.16M
                        int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
926
1.16M
                        int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
927
1.16M
                        dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
928
1.16M
                        dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
929
1.16M
                    }
930
984k
                    t->bx -= x << ss_hor;
931
984k
                }
932
936k
                t->by -= y << ss_ver;
933
936k
            }
934
468k
        }
935
784k
    }
936
777k
}
dav1d_read_coef_blocks_16bpc
Line
Count
Source
826
1.45M
{
827
1.45M
    const Dav1dFrameContext *const f = t->f;
828
1.45M
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
829
1.45M
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
830
1.45M
    const int bx4 = t->bx & 31, by4 = t->by & 31;
831
1.45M
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
832
1.45M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
833
1.45M
    const int bw4 = b_dim[0], bh4 = b_dim[1];
834
1.45M
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
835
1.45M
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
836
1.21M
                           (bw4 > ss_hor || t->bx & 1) &&
837
1.12M
                           (bh4 > ss_ver || t->by & 1);
838
839
1.45M
    if (b->skip) {
840
785k
        BlockContext *const a = t->a;
841
785k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
842
785k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
843
785k
        if (has_chroma) {
844
507k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
845
507k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
846
507k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
847
507k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
848
507k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
849
507k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
850
507k
        }
851
785k
        return;
852
785k
    }
853
854
667k
    Dav1dTileState *const ts = t->ts;
855
667k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
856
667k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
857
667k
    assert(t->frame_thread.pass == 1);
858
667k
    assert(!b->skip);
859
667k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
860
667k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->intra ? b->tx : b->max_ytx];
861
667k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
862
863
1.34M
    for (int init_y = 0; init_y < h4; init_y += 16) {
864
682k
        const int sub_h4 = imin(h4, 16 + init_y);
865
1.39M
        for (int init_x = 0; init_x < w4; init_x += 16) {
866
709k
            const int sub_w4 = imin(w4, init_x + 16);
867
709k
            int y_off = !!init_y, y, x;
868
1.52M
            for (y = init_y, t->by += init_y; y < sub_h4;
869
813k
                 y += t_dim->h, t->by += t_dim->h, y_off++)
870
813k
            {
871
813k
                int x_off = !!init_x;
872
1.99M
                for (x = init_x, t->bx += init_x; x < sub_w4;
873
1.18M
                     x += t_dim->w, t->bx += t_dim->w, x_off++)
874
1.18M
                {
875
1.18M
                    if (!b->intra) {
876
191k
                        read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
877
191k
                                       x_off, y_off, NULL);
878
993k
                    } else {
879
993k
                        uint8_t cf_ctx = 0x40;
880
993k
                        enum TxfmType txtp;
881
993k
                        const int eob =
882
993k
                            decode_coefs(t, &t->a->lcoef[bx4 + x],
883
993k
                                         &t->l.lcoef[by4 + y], b->tx, bs, b, 1,
884
993k
                                         0, ts->frame_thread[1].cf, &txtp, &cf_ctx);
885
993k
                        if (DEBUG_BLOCK_INFO)
886
0
                            printf("Post-y-cf-blk[tx=%d,txtp=%d,eob=%d]: r=%d\n",
887
0
                                   b->tx, txtp, eob, ts->msac.rng);
888
993k
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
889
993k
                        ts->frame_thread[1].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
890
993k
                        dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
891
993k
                        dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
892
993k
                    }
893
1.18M
                }
894
813k
                t->bx -= x;
895
813k
            }
896
709k
            t->by -= y;
897
898
709k
            if (!has_chroma) continue;
899
900
560k
            const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
901
560k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
902
1.68M
            for (int pl = 0; pl < 2; pl++) {
903
2.29M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
904
1.17M
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
905
1.17M
                {
906
2.51M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
907
1.34M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
908
1.34M
                    {
909
1.34M
                        uint8_t cf_ctx = 0x40;
910
1.34M
                        enum TxfmType txtp;
911
1.34M
                        if (!b->intra)
912
272k
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
913
272k
                                                        bx4 + (x << ss_hor)];
914
1.34M
                        const int eob =
915
1.34M
                            decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
916
1.34M
                                         &t->l.ccoef[pl][cby4 + y], b->uvtx, bs,
917
1.34M
                                         b, b->intra, 1 + pl, ts->frame_thread[1].cf,
918
1.34M
                                         &txtp, &cf_ctx);
919
1.34M
                        if (DEBUG_BLOCK_INFO)
920
0
                            printf("Post-uv-cf-blk[pl=%d,tx=%d,"
921
0
                                   "txtp=%d,eob=%d]: r=%d\n",
922
0
                                   pl, b->uvtx, txtp, eob, ts->msac.rng);
923
1.34M
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
924
1.34M
                        ts->frame_thread[1].cf += uv_t_dim->w * uv_t_dim->h * 16;
925
1.34M
                        int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
926
1.34M
                        int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
927
1.34M
                        dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
928
1.34M
                        dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
929
1.34M
                    }
930
1.17M
                    t->bx -= x << ss_hor;
931
1.17M
                }
932
1.12M
                t->by -= y << ss_ver;
933
1.12M
            }
934
560k
        }
935
682k
    }
936
667k
}
937
938
static int mc(Dav1dTaskContext *const t,
939
              pixel *const dst8, int16_t *const dst16, const ptrdiff_t dst_stride,
940
              const int bw4, const int bh4,
941
              const int bx, const int by, const int pl,
942
              const mv mv, const Dav1dThreadPicture *const refp, const int refidx,
943
              const enum Filter2d filter_2d)
944
690k
{
945
690k
    assert((dst8 != NULL) ^ (dst16 != NULL));
946
690k
    const Dav1dFrameContext *const f = t->f;
947
690k
    const int ss_ver = !!pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
948
690k
    const int ss_hor = !!pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
949
690k
    const int h_mul = 4 >> ss_hor, v_mul = 4 >> ss_ver;
950
690k
    const int mvx = mv.x, mvy = mv.y;
951
690k
    const int mx = mvx & (15 >> !ss_hor), my = mvy & (15 >> !ss_ver);
952
690k
    ptrdiff_t ref_stride = refp->p.stride[!!pl];
953
690k
    const pixel *ref;
954
955
690k
    if (refp->p.p.w == f->cur.p.w && refp->p.p.h == f->cur.p.h) {
956
605k
        const int dx = bx * h_mul + (mvx >> (3 + ss_hor));
957
605k
        const int dy = by * v_mul + (mvy >> (3 + ss_ver));
958
605k
        int w, h;
959
960
605k
        if (refp->p.data[0] != f->cur.data[0]) { // i.e. not for intrabc
961
71.8k
            w = (f->cur.p.w + ss_hor) >> ss_hor;
962
71.8k
            h = (f->cur.p.h + ss_ver) >> ss_ver;
963
534k
        } else {
964
534k
            w = f->bw * 4 >> ss_hor;
965
534k
            h = f->bh * 4 >> ss_ver;
966
534k
        }
967
605k
        if (dx < !!mx * 3 || dy < !!my * 3 ||
968
579k
            dx + bw4 * h_mul + !!mx * 4 > w ||
969
522k
            dy + bh4 * v_mul + !!my * 4 > h)
970
95.7k
        {
971
95.7k
            pixel *const emu_edge_buf = bitfn(t->scratch.emu_edge);
972
95.7k
            f->dsp->mc.emu_edge(bw4 * h_mul + !!mx * 7, bh4 * v_mul + !!my * 7,
973
95.7k
                                w, h, dx - !!mx * 3, dy - !!my * 3,
974
95.7k
                                emu_edge_buf, 192 * sizeof(pixel),
975
95.7k
                                refp->p.data[pl], ref_stride);
976
95.7k
            ref = &emu_edge_buf[192 * !!my * 3 + !!mx * 3];
977
95.7k
            ref_stride = 192 * sizeof(pixel);
978
510k
        } else {
979
510k
            ref = ((pixel *) refp->p.data[pl]) + PXSTRIDE(ref_stride) * dy + dx;
980
510k
        }
981
982
605k
        if (dst8 != NULL) {
983
580k
            f->dsp->mc.mc[filter_2d](dst8, dst_stride, ref, ref_stride, bw4 * h_mul,
984
580k
                                     bh4 * v_mul, mx << !ss_hor, my << !ss_ver
985
580k
                                     HIGHBD_CALL_SUFFIX);
986
580k
        } else {
987
25.6k
            f->dsp->mc.mct[filter_2d](dst16, ref, ref_stride, bw4 * h_mul,
988
25.6k
                                      bh4 * v_mul, mx << !ss_hor, my << !ss_ver
989
25.6k
                                      HIGHBD_CALL_SUFFIX);
990
25.6k
        }
991
605k
    } else {
992
84.3k
        assert(refp != &f->sr_cur);
993
994
84.3k
        const int orig_pos_y = (by * v_mul << 4) + mvy * (1 << !ss_ver);
995
84.3k
        const int orig_pos_x = (bx * h_mul << 4) + mvx * (1 << !ss_hor);
996
168k
#define scale_mv(res, val, scale) do { \
997
168k
            const int64_t tmp = (int64_t)(val) * scale + (scale - 0x4000) * 8; \
998
168k
            res = apply_sign64((int) ((llabs(tmp) + 128) >> 8), tmp) + 32;     \
999
168k
        } while (0)
1000
84.3k
        int pos_y, pos_x;
1001
84.3k
        scale_mv(pos_x, orig_pos_x, f->svc[refidx][0].scale);
1002
84.3k
        scale_mv(pos_y, orig_pos_y, f->svc[refidx][1].scale);
1003
84.3k
#undef scale_mv
1004
84.3k
        const int left = pos_x >> 10;
1005
84.3k
        const int top = pos_y >> 10;
1006
84.3k
        const int right =
1007
84.3k
            ((pos_x + (bw4 * h_mul - 1) * f->svc[refidx][0].step) >> 10) + 1;
1008
84.3k
        const int bottom =
1009
84.3k
            ((pos_y + (bh4 * v_mul - 1) * f->svc[refidx][1].step) >> 10) + 1;
1010
1011
84.3k
        if (DEBUG_BLOCK_INFO)
1012
0
            printf("Off %dx%d [%d,%d,%d], size %dx%d [%d,%d]\n",
1013
0
                   left, top, orig_pos_x, f->svc[refidx][0].scale, refidx,
1014
0
                   right-left, bottom-top,
1015
0
                   f->svc[refidx][0].step, f->svc[refidx][1].step);
1016
1017
84.3k
        const int w = (refp->p.p.w + ss_hor) >> ss_hor;
1018
84.3k
        const int h = (refp->p.p.h + ss_ver) >> ss_ver;
1019
84.3k
        if (left < 3 || top < 3 || right + 4 > w || bottom + 4 > h) {
1020
61.0k
            pixel *const emu_edge_buf = bitfn(t->scratch.emu_edge);
1021
61.0k
            f->dsp->mc.emu_edge(right - left + 7, bottom - top + 7,
1022
61.0k
                                w, h, left - 3, top - 3,
1023
61.0k
                                emu_edge_buf, 320 * sizeof(pixel),
1024
61.0k
                                refp->p.data[pl], ref_stride);
1025
61.0k
            ref = &emu_edge_buf[320 * 3 + 3];
1026
61.0k
            ref_stride = 320 * sizeof(pixel);
1027
61.0k
            if (DEBUG_BLOCK_INFO) printf("Emu\n");
1028
61.0k
        } else {
1029
23.3k
            ref = ((pixel *) refp->p.data[pl]) + PXSTRIDE(ref_stride) * top + left;
1030
23.3k
        }
1031
1032
84.3k
        if (dst8 != NULL) {
1033
58.8k
            f->dsp->mc.mc_scaled[filter_2d](dst8, dst_stride, ref, ref_stride,
1034
58.8k
                                            bw4 * h_mul, bh4 * v_mul,
1035
58.8k
                                            pos_x & 0x3ff, pos_y & 0x3ff,
1036
58.8k
                                            f->svc[refidx][0].step,
1037
58.8k
                                            f->svc[refidx][1].step
1038
58.8k
                                            HIGHBD_CALL_SUFFIX);
1039
58.8k
        } else {
1040
25.5k
            f->dsp->mc.mct_scaled[filter_2d](dst16, ref, ref_stride,
1041
25.5k
                                             bw4 * h_mul, bh4 * v_mul,
1042
25.5k
                                             pos_x & 0x3ff, pos_y & 0x3ff,
1043
25.5k
                                             f->svc[refidx][0].step,
1044
25.5k
                                             f->svc[refidx][1].step
1045
25.5k
                                             HIGHBD_CALL_SUFFIX);
1046
25.5k
        }
1047
84.3k
    }
1048
1049
690k
    return 0;
1050
690k
}
1051
1052
static int obmc(Dav1dTaskContext *const t,
1053
                pixel *const dst, const ptrdiff_t dst_stride,
1054
                const uint8_t *const b_dim, const int pl,
1055
                const int bx4, const int by4, const int w4, const int h4)
1056
13.0k
{
1057
13.0k
    assert(!(t->bx & 1) && !(t->by & 1));
1058
13.0k
    const Dav1dFrameContext *const f = t->f;
1059
13.0k
    /*const*/ refmvs_block **r = &t->rt.r[(t->by & 31) + 5];
1060
13.0k
    pixel *const lap = bitfn(t->scratch.lap);
1061
13.0k
    const int ss_ver = !!pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1062
13.0k
    const int ss_hor = !!pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1063
13.0k
    const int h_mul = 4 >> ss_hor, v_mul = 4 >> ss_ver;
1064
13.0k
    int res;
1065
1066
13.0k
    if (t->by > t->ts->tiling.row_start &&
1067
10.4k
        (!pl || b_dim[0] * h_mul + b_dim[1] * v_mul >= 16))
1068
8.15k
    {
1069
17.4k
        for (int i = 0, x = 0; x < w4 && i < imin(b_dim[2], 4); ) {
1070
            // only odd blocks are considered for overlap handling, hence +1
1071
9.27k
            const refmvs_block *const a_r = &r[-1][t->bx + x + 1];
1072
9.27k
            const uint8_t *const a_b_dim = dav1d_block_dimensions[a_r->bs];
1073
9.27k
            const int step4 = iclip(a_b_dim[0], 2, 16);
1074
1075
9.27k
            if (a_r->ref.ref[0] > 0) {
1076
9.10k
                const int ow4 = imin(step4, b_dim[0]);
1077
9.10k
                const int oh4 = imin(b_dim[1], 16) >> 1;
1078
9.10k
                res = mc(t, lap, NULL, ow4 * h_mul * sizeof(pixel), ow4, (oh4 * 3 + 3) >> 2,
1079
9.10k
                         t->bx + x, t->by, pl, a_r->mv.mv[0],
1080
9.10k
                         &f->refp[a_r->ref.ref[0] - 1], a_r->ref.ref[0] - 1,
1081
9.10k
                         dav1d_filter_2d[t->a->filter[1][bx4 + x + 1]][t->a->filter[0][bx4 + x + 1]]);
1082
9.10k
                if (res) return res;
1083
9.10k
                f->dsp->mc.blend_h(&dst[x * h_mul], dst_stride, lap,
1084
9.10k
                                   h_mul * ow4, v_mul * oh4);
1085
9.10k
                i++;
1086
9.10k
            }
1087
9.27k
            x += step4;
1088
9.27k
        }
1089
8.15k
    }
1090
1091
13.0k
    if (t->bx > t->ts->tiling.col_start)
1092
21.0k
        for (int i = 0, y = 0; y < h4 && i < imin(b_dim[3], 4); ) {
1093
            // only odd blocks are considered for overlap handling, hence +1
1094
10.9k
            const refmvs_block *const l_r = &r[y + 1][t->bx - 1];
1095
10.9k
            const uint8_t *const l_b_dim = dav1d_block_dimensions[l_r->bs];
1096
10.9k
            const int step4 = iclip(l_b_dim[1], 2, 16);
1097
1098
10.9k
            if (l_r->ref.ref[0] > 0) {
1099
10.7k
                const int ow4 = imin(b_dim[0], 16) >> 1;
1100
10.7k
                const int oh4 = imin(step4, b_dim[1]);
1101
10.7k
                res = mc(t, lap, NULL, h_mul * ow4 * sizeof(pixel), ow4, oh4,
1102
10.7k
                         t->bx, t->by + y, pl, l_r->mv.mv[0],
1103
10.7k
                         &f->refp[l_r->ref.ref[0] - 1], l_r->ref.ref[0] - 1,
1104
10.7k
                         dav1d_filter_2d[t->l.filter[1][by4 + y + 1]][t->l.filter[0][by4 + y + 1]]);
1105
10.7k
                if (res) return res;
1106
10.7k
                f->dsp->mc.blend_v(&dst[y * v_mul * PXSTRIDE(dst_stride)],
1107
10.7k
                                   dst_stride, lap, h_mul * ow4, v_mul * oh4);
1108
10.7k
                i++;
1109
10.7k
            }
1110
10.9k
            y += step4;
1111
10.9k
        }
1112
13.0k
    return 0;
1113
13.0k
}
1114
1115
static int warp_affine(Dav1dTaskContext *const t,
1116
                       pixel *dst8, int16_t *dst16, const ptrdiff_t dstride,
1117
                       const uint8_t *const b_dim, const int pl,
1118
                       const Dav1dThreadPicture *const refp,
1119
                       const Dav1dWarpedMotionParams *const wmp)
1120
8.75k
{
1121
8.75k
    assert((dst8 != NULL) ^ (dst16 != NULL));
1122
8.75k
    const Dav1dFrameContext *const f = t->f;
1123
8.75k
    const Dav1dDSPContext *const dsp = f->dsp;
1124
8.75k
    const int ss_ver = !!pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1125
8.75k
    const int ss_hor = !!pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1126
8.75k
    const int h_mul = 4 >> ss_hor, v_mul = 4 >> ss_ver;
1127
8.75k
    assert(!((b_dim[0] * h_mul) & 7) && !((b_dim[1] * v_mul) & 7));
1128
8.75k
    const int32_t *const mat = wmp->matrix;
1129
8.75k
    const int width = (refp->p.p.w + ss_hor) >> ss_hor;
1130
8.75k
    const int height = (refp->p.p.h + ss_ver) >> ss_ver;
1131
1132
54.4k
    for (int y = 0; y < b_dim[1] * v_mul; y += 8) {
1133
45.7k
        const int src_y = t->by * 4 + ((y + 4) << ss_ver);
1134
45.7k
        const int64_t mat3_y = (int64_t) mat[3] * src_y + mat[0];
1135
45.7k
        const int64_t mat5_y = (int64_t) mat[5] * src_y + mat[1];
1136
421k
        for (int x = 0; x < b_dim[0] * h_mul; x += 8) {
1137
            // calculate transformation relative to center of 8x8 block in
1138
            // luma pixel units
1139
376k
            const int src_x = t->bx * 4 + ((x + 4) << ss_hor);
1140
376k
            const int64_t mvx = ((int64_t) mat[2] * src_x + mat3_y) >> ss_hor;
1141
376k
            const int64_t mvy = ((int64_t) mat[4] * src_x + mat5_y) >> ss_ver;
1142
1143
376k
            const int dx = (int) (mvx >> 16) - 4;
1144
376k
            const int mx = (((int) mvx & 0xffff) - wmp->u.p.alpha * 4 -
1145
376k
                                                   wmp->u.p.beta  * 7) & ~0x3f;
1146
376k
            const int dy = (int) (mvy >> 16) - 4;
1147
376k
            const int my = (((int) mvy & 0xffff) - wmp->u.p.gamma * 4 -
1148
376k
                                                   wmp->u.p.delta * 4) & ~0x3f;
1149
1150
376k
            const pixel *ref_ptr;
1151
376k
            ptrdiff_t ref_stride = refp->p.stride[!!pl];
1152
1153
376k
            if (dx < 3 || dx + 8 + 4 > width || dy < 3 || dy + 8 + 4 > height) {
1154
150k
                pixel *const emu_edge_buf = bitfn(t->scratch.emu_edge);
1155
150k
                f->dsp->mc.emu_edge(15, 15, width, height, dx - 3, dy - 3,
1156
150k
                                    emu_edge_buf, 32 * sizeof(pixel),
1157
150k
                                    refp->p.data[pl], ref_stride);
1158
150k
                ref_ptr = &emu_edge_buf[32 * 3 + 3];
1159
150k
                ref_stride = 32 * sizeof(pixel);
1160
226k
            } else {
1161
226k
                ref_ptr = ((pixel *) refp->p.data[pl]) + PXSTRIDE(ref_stride) * dy + dx;
1162
226k
            }
1163
376k
            if (dst16 != NULL)
1164
24.8k
                dsp->mc.warp8x8t(&dst16[x], dstride, ref_ptr, ref_stride,
1165
24.8k
                                 wmp->u.abcd, mx, my HIGHBD_CALL_SUFFIX);
1166
351k
            else
1167
351k
                dsp->mc.warp8x8(&dst8[x], dstride, ref_ptr, ref_stride,
1168
351k
                                wmp->u.abcd, mx, my HIGHBD_CALL_SUFFIX);
1169
376k
        }
1170
45.7k
        if (dst8) dst8  += 8 * PXSTRIDE(dstride);
1171
3.96k
        else      dst16 += 8 * dstride;
1172
45.7k
    }
1173
8.75k
    return 0;
1174
8.75k
}
1175
1176
void bytefn(dav1d_recon_b_intra)(Dav1dTaskContext *const t, const enum BlockSize bs,
1177
                                 const enum EdgeFlags intra_edge_flags,
1178
                                 const Av1Block *const b)
1179
1.85M
{
1180
1.85M
    Dav1dTileState *const ts = t->ts;
1181
1.85M
    const Dav1dFrameContext *const f = t->f;
1182
1.85M
    const Dav1dDSPContext *const dsp = f->dsp;
1183
1.85M
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1184
1.85M
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1185
1.85M
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1186
1.85M
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1187
1.85M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1188
1.85M
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1189
1.85M
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1190
1.85M
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1191
1.85M
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1192
1.36M
                           (bw4 > ss_hor || t->bx & 1) &&
1193
1.26M
                           (bh4 > ss_ver || t->by & 1);
1194
1.85M
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->tx];
1195
1.85M
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
1196
1197
    // coefficient coding
1198
1.85M
    pixel *const edge = bitfn(t->scratch.edge) + 128;
1199
1.85M
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
1200
1201
1.85M
    const int intra_edge_filter_flag = f->seq_hdr->intra_edge_filter << 10;
1202
1203
3.74M
    for (int init_y = 0; init_y < h4; init_y += 16) {
1204
1.88M
        const int sub_h4 = imin(h4, 16 + init_y);
1205
1.88M
        const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
1206
3.84M
        for (int init_x = 0; init_x < w4; init_x += 16) {
1207
1.94M
            if (b->pal_sz[0]) {
1208
12.6k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1209
12.6k
                             4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1210
12.6k
                const uint8_t *pal_idx;
1211
12.6k
                if (t->frame_thread.pass) {
1212
12.6k
                    const int p = t->frame_thread.pass & 1;
1213
12.6k
                    assert(ts->frame_thread[p].pal_idx);
1214
12.6k
                    pal_idx = ts->frame_thread[p].pal_idx;
1215
12.6k
                    ts->frame_thread[p].pal_idx += bw4 * bh4 * 8;
1216
12.6k
                } else {
1217
0
                    pal_idx = t->scratch.pal_idx_y;
1218
0
                }
1219
12.6k
                const pixel *const pal = t->frame_thread.pass ?
1220
12.6k
                    f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1221
12.6k
                                        ((t->bx >> 1) + (t->by & 1))][0] :
1222
12.6k
                    bytefn(t->scratch.pal)[0];
1223
12.6k
                f->dsp->ipred.pal_pred(dst, f->cur.stride[0], pal,
1224
12.6k
                                       pal_idx, bw4 * 4, bh4 * 4);
1225
12.6k
                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1226
0
                    hex_dump(dst, PXSTRIDE(f->cur.stride[0]),
1227
0
                             bw4 * 4, bh4 * 4, "y-pal-pred");
1228
12.6k
            }
1229
1230
1.94M
            const int intra_flags = (sm_flag(t->a, bx4) |
1231
1.94M
                                     sm_flag(&t->l, by4) |
1232
1.94M
                                     intra_edge_filter_flag);
1233
1.94M
            const int sb_has_tr = init_x + 16 < w4 ? 1 : init_y ? 0 :
1234
1.88M
                              intra_edge_flags & EDGE_I444_TOP_HAS_RIGHT;
1235
1.94M
            const int sb_has_bl = init_x ? 0 : init_y + 16 < h4 ? 1 :
1236
1.88M
                              intra_edge_flags & EDGE_I444_LEFT_HAS_BOTTOM;
1237
1.94M
            int y, x;
1238
1.94M
            const int sub_w4 = imin(w4, init_x + 16);
1239
4.40M
            for (y = init_y, t->by += init_y; y < sub_h4;
1240
2.45M
                 y += t_dim->h, t->by += t_dim->h)
1241
2.45M
            {
1242
2.45M
                pixel *dst = ((pixel *) f->cur.data[0]) +
1243
2.45M
                               4 * (t->by * PXSTRIDE(f->cur.stride[0]) +
1244
2.45M
                                    t->bx + init_x);
1245
7.87M
                for (x = init_x, t->bx += init_x; x < sub_w4;
1246
5.42M
                     x += t_dim->w, t->bx += t_dim->w)
1247
5.41M
                {
1248
5.41M
                    if (b->pal_sz[0]) goto skip_y_pred;
1249
1250
5.40M
                    int angle = b->y_angle;
1251
5.40M
                    const enum EdgeFlags edge_flags =
1252
5.40M
                        (((y > init_y || !sb_has_tr) && (x + t_dim->w >= sub_w4)) ?
1253
4.28M
                             0 : EDGE_I444_TOP_HAS_RIGHT) |
1254
5.40M
                        ((x > init_x || (!sb_has_bl && y + t_dim->h >= sub_h4)) ?
1255
4.07M
                             0 : EDGE_I444_LEFT_HAS_BOTTOM);
1256
5.40M
                    const pixel *top_sb_edge = NULL;
1257
5.40M
                    if (!(t->by & (f->sb_step - 1))) {
1258
860k
                        top_sb_edge = f->ipred_edge[0];
1259
860k
                        const int sby = t->by >> f->sb_shift;
1260
860k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1261
860k
                    }
1262
5.40M
                    const enum IntraPredMode m =
1263
5.40M
                        bytefn(dav1d_prepare_intra_edges)(t->bx,
1264
5.40M
                                                          t->bx > ts->tiling.col_start,
1265
5.40M
                                                          t->by,
1266
5.40M
                                                          t->by > ts->tiling.row_start,
1267
5.40M
                                                          ts->tiling.col_end,
1268
5.40M
                                                          ts->tiling.row_end,
1269
5.40M
                                                          edge_flags, dst,
1270
5.40M
                                                          f->cur.stride[0], top_sb_edge,
1271
5.40M
                                                          b->y_mode, &angle,
1272
5.40M
                                                          t_dim->w, t_dim->h,
1273
5.40M
                                                          f->seq_hdr->intra_edge_filter,
1274
5.40M
                                                          edge HIGHBD_CALL_SUFFIX);
1275
5.40M
                    dsp->ipred.intra_pred[m](dst, f->cur.stride[0], edge,
1276
5.40M
                                             t_dim->w * 4, t_dim->h * 4,
1277
5.40M
                                             angle | intra_flags,
1278
5.40M
                                             4 * f->bw - 4 * t->bx,
1279
5.40M
                                             4 * f->bh - 4 * t->by
1280
5.40M
                                             HIGHBD_CALL_SUFFIX);
1281
1282
5.40M
                    if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1283
0
                        hex_dump(edge - t_dim->h * 4, t_dim->h * 4,
1284
0
                                 t_dim->h * 4, 2, "l");
1285
0
                        hex_dump(edge, 0, 1, 1, "tl");
1286
0
                        hex_dump(edge + 1, t_dim->w * 4,
1287
0
                                 t_dim->w * 4, 2, "t");
1288
0
                        hex_dump(dst, f->cur.stride[0],
1289
0
                                 t_dim->w * 4, t_dim->h * 4, "y-intra-pred");
1290
0
                    }
1291
1292
5.42M
                skip_y_pred: {}
1293
5.42M
                    if (!b->skip) {
1294
1.57M
                        coef *cf;
1295
1.57M
                        int eob;
1296
1.57M
                        enum TxfmType txtp;
1297
1.57M
                        if (t->frame_thread.pass) {
1298
1.57M
                            const int p = t->frame_thread.pass & 1;
1299
1.57M
                            const int cbi = *ts->frame_thread[p].cbi++;
1300
1.57M
                            cf = ts->frame_thread[p].cf;
1301
1.57M
                            ts->frame_thread[p].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
1302
1.57M
                            eob  = cbi >> 5;
1303
1.57M
                            txtp = cbi & 0x1f;
1304
1.57M
                        } else {
1305
0
                            uint8_t cf_ctx;
1306
0
                            cf = bitfn(t->cf);
1307
0
                            eob = decode_coefs(t, &t->a->lcoef[bx4 + x],
1308
0
                                               &t->l.lcoef[by4 + y], b->tx, bs,
1309
0
                                               b, 1, 0, cf, &txtp, &cf_ctx);
1310
0
                            if (DEBUG_BLOCK_INFO)
1311
0
                                printf("Post-y-cf-blk[tx=%d,txtp=%d,eob=%d]: r=%d\n",
1312
0
                                       b->tx, txtp, eob, ts->msac.rng);
1313
0
                            dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
1314
0
                            dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
1315
0
                        }
1316
1.57M
                        if (eob >= 0) {
1317
1.22M
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1318
0
                                coef_dump(cf, imin(t_dim->h, 8) * 4,
1319
0
                                          imin(t_dim->w, 8) * 4, 3, "dq");
1320
1.22M
                            dsp->itx.itxfm_add[b->tx]
1321
1.22M
                                              [txtp](dst,
1322
1.22M
                                                     f->cur.stride[0],
1323
1.22M
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1324
1.22M
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1325
0
                                hex_dump(dst, f->cur.stride[0],
1326
0
                                         t_dim->w * 4, t_dim->h * 4, "recon");
1327
1.22M
                        }
1328
3.85M
                    } else if (!t->frame_thread.pass) {
1329
0
                        dav1d_memset_pow2[t_dim->lw](&t->a->lcoef[bx4 + x], 0x40);
1330
0
                        dav1d_memset_pow2[t_dim->lh](&t->l.lcoef[by4 + y], 0x40);
1331
0
                    }
1332
5.42M
                    dst += 4 * t_dim->w;
1333
5.42M
                }
1334
2.45M
                t->bx -= x;
1335
2.45M
            }
1336
1.95M
            t->by -= y;
1337
1338
1.95M
            if (!has_chroma) continue;
1339
1340
1.23M
            const ptrdiff_t stride = f->cur.stride[1];
1341
1342
1.23M
            if (b->uv_mode == CFL_PRED) {
1343
230k
                assert(!init_x && !init_y);
1344
1345
230k
                int16_t *const ac = t->scratch.ac;
1346
230k
                pixel *y_src = ((pixel *) f->cur.data[0]) + 4 * (t->bx & ~ss_hor) +
1347
230k
                                 4 * (t->by & ~ss_ver) * PXSTRIDE(f->cur.stride[0]);
1348
230k
                const ptrdiff_t uv_off = 4 * ((t->bx >> ss_hor) +
1349
230k
                                              (t->by >> ss_ver) * PXSTRIDE(stride));
1350
230k
                pixel *const uv_dst[2] = { ((pixel *) f->cur.data[1]) + uv_off,
1351
230k
                                           ((pixel *) f->cur.data[2]) + uv_off };
1352
1353
230k
                const int furthest_r =
1354
230k
                    ((cw4 << ss_hor) + t_dim->w - 1) & ~(t_dim->w - 1);
1355
230k
                const int furthest_b =
1356
230k
                    ((ch4 << ss_ver) + t_dim->h - 1) & ~(t_dim->h - 1);
1357
230k
                dsp->ipred.cfl_ac[f->cur.p.layout - 1](ac, y_src, f->cur.stride[0],
1358
230k
                                                         cbw4 - (furthest_r >> ss_hor),
1359
230k
                                                         cbh4 - (furthest_b >> ss_ver),
1360
230k
                                                         cbw4 * 4, cbh4 * 4);
1361
692k
                for (int pl = 0; pl < 2; pl++) {
1362
461k
                    if (!b->cfl_alpha[pl]) continue;
1363
375k
                    int angle = 0;
1364
375k
                    const pixel *top_sb_edge = NULL;
1365
375k
                    if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1366
109k
                        top_sb_edge = f->ipred_edge[pl + 1];
1367
109k
                        const int sby = t->by >> f->sb_shift;
1368
109k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1369
109k
                    }
1370
375k
                    const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1371
375k
                    const int xstart = ts->tiling.col_start >> ss_hor;
1372
375k
                    const int ystart = ts->tiling.row_start >> ss_ver;
1373
375k
                    const enum IntraPredMode m =
1374
375k
                        bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1375
375k
                                                          ypos, ypos > ystart,
1376
375k
                                                          ts->tiling.col_end >> ss_hor,
1377
375k
                                                          ts->tiling.row_end >> ss_ver,
1378
375k
                                                          0, uv_dst[pl], stride,
1379
375k
                                                          top_sb_edge, DC_PRED, &angle,
1380
375k
                                                          uv_t_dim->w, uv_t_dim->h, 0,
1381
375k
                                                          edge HIGHBD_CALL_SUFFIX);
1382
375k
                    dsp->ipred.cfl_pred[m](uv_dst[pl], stride, edge,
1383
375k
                                           uv_t_dim->w * 4,
1384
375k
                                           uv_t_dim->h * 4,
1385
375k
                                           ac, b->cfl_alpha[pl]
1386
375k
                                           HIGHBD_CALL_SUFFIX);
1387
375k
                }
1388
230k
                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1389
0
                    ac_dump(ac, 4*cbw4, 4*cbh4, "ac");
1390
0
                    hex_dump(uv_dst[0], stride, cbw4 * 4, cbh4 * 4, "u-cfl-pred");
1391
0
                    hex_dump(uv_dst[1], stride, cbw4 * 4, cbh4 * 4, "v-cfl-pred");
1392
0
                }
1393
1.00M
            } else if (b->pal_sz[1]) {
1394
3.49k
                const ptrdiff_t uv_dstoff = 4 * ((t->bx >> ss_hor) +
1395
3.49k
                                              (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1396
3.49k
                const pixel (*pal)[8];
1397
3.49k
                const uint8_t *pal_idx;
1398
3.49k
                if (t->frame_thread.pass) {
1399
3.49k
                    const int p = t->frame_thread.pass & 1;
1400
3.49k
                    assert(ts->frame_thread[p].pal_idx);
1401
3.49k
                    pal = f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1402
3.49k
                                              ((t->bx >> 1) + (t->by & 1))];
1403
3.49k
                    pal_idx = ts->frame_thread[p].pal_idx;
1404
3.49k
                    ts->frame_thread[p].pal_idx += cbw4 * cbh4 * 8;
1405
3.49k
                } else {
1406
0
                    pal = bytefn(t->scratch.pal);
1407
0
                    pal_idx = t->scratch.pal_idx_uv;
1408
0
                }
1409
1410
3.49k
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[1]) + uv_dstoff,
1411
3.49k
                                       f->cur.stride[1], pal[1],
1412
3.49k
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1413
3.49k
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[2]) + uv_dstoff,
1414
3.49k
                                       f->cur.stride[1], pal[2],
1415
3.49k
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1416
3.49k
                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1417
0
                    hex_dump(((pixel *) f->cur.data[1]) + uv_dstoff,
1418
0
                             PXSTRIDE(f->cur.stride[1]),
1419
0
                             cbw4 * 4, cbh4 * 4, "u-pal-pred");
1420
0
                    hex_dump(((pixel *) f->cur.data[2]) + uv_dstoff,
1421
0
                             PXSTRIDE(f->cur.stride[1]),
1422
0
                             cbw4 * 4, cbh4 * 4, "v-pal-pred");
1423
0
                }
1424
3.49k
            }
1425
1426
1.23M
            const int sm_uv_fl = sm_uv_flag(t->a, cbx4) |
1427
1.23M
                                 sm_uv_flag(&t->l, cby4);
1428
1.23M
            const int uv_sb_has_tr =
1429
1.23M
                ((init_x + 16) >> ss_hor) < cw4 ? 1 : init_y ? 0 :
1430
1.19M
                intra_edge_flags & (EDGE_I420_TOP_HAS_RIGHT >> (f->cur.p.layout - 1));
1431
1.23M
            const int uv_sb_has_bl =
1432
1.23M
                init_x ? 0 : ((init_y + 16) >> ss_ver) < ch4 ? 1 :
1433
1.19M
                intra_edge_flags & (EDGE_I420_LEFT_HAS_BOTTOM >> (f->cur.p.layout - 1));
1434
1.23M
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
1435
3.70M
            for (int pl = 0; pl < 2; pl++) {
1436
5.09M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
1437
2.62M
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
1438
2.62M
                {
1439
2.62M
                    pixel *dst = ((pixel *) f->cur.data[1 + pl]) +
1440
2.62M
                                   4 * ((t->by >> ss_ver) * PXSTRIDE(stride) +
1441
2.62M
                                        ((t->bx + init_x) >> ss_hor));
1442
5.91M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
1443
3.28M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
1444
3.28M
                    {
1445
3.28M
                        if ((b->uv_mode == CFL_PRED && b->cfl_alpha[pl]) ||
1446
2.91M
                            b->pal_sz[1])
1447
382k
                        {
1448
382k
                            goto skip_uv_pred;
1449
382k
                        }
1450
1451
2.90M
                        int angle = b->uv_angle;
1452
                        // this probably looks weird because we're using
1453
                        // luma flags in a chroma loop, but that's because
1454
                        // prepare_intra_edges() expects luma flags as input
1455
2.90M
                        const enum EdgeFlags edge_flags =
1456
2.90M
                            (((y > (init_y >> ss_ver) || !uv_sb_has_tr) &&
1457
1.32M
                              (x + uv_t_dim->w >= sub_cw4)) ?
1458
2.13M
                                 0 : EDGE_I444_TOP_HAS_RIGHT) |
1459
2.90M
                            ((x > (init_x >> ss_hor) ||
1460
2.24M
                              (!uv_sb_has_bl && y + uv_t_dim->h >= sub_ch4)) ?
1461
1.85M
                                 0 : EDGE_I444_LEFT_HAS_BOTTOM);
1462
2.90M
                        const pixel *top_sb_edge = NULL;
1463
2.90M
                        if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1464
775k
                            top_sb_edge = f->ipred_edge[1 + pl];
1465
775k
                            const int sby = t->by >> f->sb_shift;
1466
775k
                            top_sb_edge += f->sb128w * 128 * (sby - 1);
1467
775k
                        }
1468
2.90M
                        const enum IntraPredMode uv_mode =
1469
2.90M
                             b->uv_mode == CFL_PRED ? DC_PRED : b->uv_mode;
1470
2.90M
                        const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1471
2.90M
                        const int xstart = ts->tiling.col_start >> ss_hor;
1472
2.90M
                        const int ystart = ts->tiling.row_start >> ss_ver;
1473
2.90M
                        const enum IntraPredMode m =
1474
2.90M
                            bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1475
2.90M
                                                              ypos, ypos > ystart,
1476
2.90M
                                                              ts->tiling.col_end >> ss_hor,
1477
2.90M
                                                              ts->tiling.row_end >> ss_ver,
1478
2.90M
                                                              edge_flags, dst, stride,
1479
2.90M
                                                              top_sb_edge, uv_mode,
1480
2.90M
                                                              &angle, uv_t_dim->w,
1481
2.90M
                                                              uv_t_dim->h,
1482
2.90M
                                                              f->seq_hdr->intra_edge_filter,
1483
2.90M
                                                              edge HIGHBD_CALL_SUFFIX);
1484
2.90M
                        angle |= intra_edge_filter_flag;
1485
2.90M
                        dsp->ipred.intra_pred[m](dst, stride, edge,
1486
2.90M
                                                 uv_t_dim->w * 4,
1487
2.90M
                                                 uv_t_dim->h * 4,
1488
2.90M
                                                 angle | sm_uv_fl,
1489
2.90M
                                                 (4 * f->bw + ss_hor -
1490
2.90M
                                                  4 * (t->bx & ~ss_hor)) >> ss_hor,
1491
2.90M
                                                 (4 * f->bh + ss_ver -
1492
2.90M
                                                  4 * (t->by & ~ss_ver)) >> ss_ver
1493
2.90M
                                                 HIGHBD_CALL_SUFFIX);
1494
2.90M
                        if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1495
0
                            hex_dump(edge - uv_t_dim->h * 4, uv_t_dim->h * 4,
1496
0
                                     uv_t_dim->h * 4, 2, "l");
1497
0
                            hex_dump(edge, 0, 1, 1, "tl");
1498
0
                            hex_dump(edge + 1, uv_t_dim->w * 4,
1499
0
                                     uv_t_dim->w * 4, 2, "t");
1500
0
                            hex_dump(dst, stride, uv_t_dim->w * 4,
1501
0
                                     uv_t_dim->h * 4, pl ? "v-intra-pred" : "u-intra-pred");
1502
0
                        }
1503
1504
3.28M
                    skip_uv_pred: {}
1505
3.28M
                        if (!b->skip) {
1506
1.27M
                            enum TxfmType txtp;
1507
1.27M
                            int eob;
1508
1.27M
                            coef *cf;
1509
1.27M
                            if (t->frame_thread.pass) {
1510
1.27M
                                const int p = t->frame_thread.pass & 1;
1511
1.27M
                                const int cbi = *ts->frame_thread[p].cbi++;
1512
1.27M
                                cf = ts->frame_thread[p].cf;
1513
1.27M
                                ts->frame_thread[p].cf += uv_t_dim->w * uv_t_dim->h * 16;
1514
1.27M
                                eob  = cbi >> 5;
1515
1.27M
                                txtp = cbi & 0x1f;
1516
18.4E
                            } else {
1517
18.4E
                                uint8_t cf_ctx;
1518
18.4E
                                cf = bitfn(t->cf);
1519
18.4E
                                eob = decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
1520
18.4E
                                                   &t->l.ccoef[pl][cby4 + y],
1521
18.4E
                                                   b->uvtx, bs, b, 1, 1 + pl, cf,
1522
18.4E
                                                   &txtp, &cf_ctx);
1523
18.4E
                                if (DEBUG_BLOCK_INFO)
1524
0
                                    printf("Post-uv-cf-blk[pl=%d,tx=%d,"
1525
0
                                           "txtp=%d,eob=%d]: r=%d [x=%d,cbx4=%d]\n",
1526
0
                                           pl, b->uvtx, txtp, eob, ts->msac.rng, x, cbx4);
1527
18.4E
                                int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
1528
18.4E
                                int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
1529
18.4E
                                dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
1530
18.4E
                                dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
1531
18.4E
                            }
1532
1.27M
                            if (eob >= 0) {
1533
518k
                                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1534
0
                                    coef_dump(cf, uv_t_dim->h * 4,
1535
0
                                              uv_t_dim->w * 4, 3, "dq");
1536
518k
                                dsp->itx.itxfm_add[b->uvtx]
1537
518k
                                                  [txtp](dst, stride,
1538
518k
                                                         cf, eob HIGHBD_CALL_SUFFIX);
1539
518k
                                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1540
0
                                    hex_dump(dst, stride, uv_t_dim->w * 4,
1541
0
                                             uv_t_dim->h * 4, "recon");
1542
518k
                            }
1543
2.01M
                        } else if (!t->frame_thread.pass) {
1544
0
                            dav1d_memset_pow2[uv_t_dim->lw](&t->a->ccoef[pl][cbx4 + x], 0x40);
1545
0
                            dav1d_memset_pow2[uv_t_dim->lh](&t->l.ccoef[pl][cby4 + y], 0x40);
1546
0
                        }
1547
3.28M
                        dst += uv_t_dim->w * 4;
1548
3.28M
                    }
1549
2.62M
                    t->bx -= x << ss_hor;
1550
2.62M
                }
1551
2.46M
                t->by -= y << ss_ver;
1552
2.46M
            }
1553
1.23M
        }
1554
1.88M
    }
1555
1.85M
}
dav1d_recon_b_intra_8bpc
Line
Count
Source
1179
1.06M
{
1180
1.06M
    Dav1dTileState *const ts = t->ts;
1181
1.06M
    const Dav1dFrameContext *const f = t->f;
1182
1.06M
    const Dav1dDSPContext *const dsp = f->dsp;
1183
1.06M
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1184
1.06M
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1185
1.06M
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1186
1.06M
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1187
1.06M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1188
1.06M
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1189
1.06M
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1190
1.06M
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1191
1.06M
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1192
695k
                           (bw4 > ss_hor || t->bx & 1) &&
1193
631k
                           (bh4 > ss_ver || t->by & 1);
1194
1.06M
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->tx];
1195
1.06M
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
1196
1197
    // coefficient coding
1198
1.06M
    pixel *const edge = bitfn(t->scratch.edge) + 128;
1199
1.06M
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
1200
1201
1.06M
    const int intra_edge_filter_flag = f->seq_hdr->intra_edge_filter << 10;
1202
1203
2.14M
    for (int init_y = 0; init_y < h4; init_y += 16) {
1204
1.07M
        const int sub_h4 = imin(h4, 16 + init_y);
1205
1.07M
        const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
1206
2.19M
        for (int init_x = 0; init_x < w4; init_x += 16) {
1207
1.10M
            if (b->pal_sz[0]) {
1208
5.92k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1209
5.92k
                             4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1210
5.92k
                const uint8_t *pal_idx;
1211
5.92k
                if (t->frame_thread.pass) {
1212
5.92k
                    const int p = t->frame_thread.pass & 1;
1213
5.92k
                    assert(ts->frame_thread[p].pal_idx);
1214
5.92k
                    pal_idx = ts->frame_thread[p].pal_idx;
1215
5.92k
                    ts->frame_thread[p].pal_idx += bw4 * bh4 * 8;
1216
5.92k
                } else {
1217
0
                    pal_idx = t->scratch.pal_idx_y;
1218
0
                }
1219
5.92k
                const pixel *const pal = t->frame_thread.pass ?
1220
5.92k
                    f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1221
5.92k
                                        ((t->bx >> 1) + (t->by & 1))][0] :
1222
5.92k
                    bytefn(t->scratch.pal)[0];
1223
5.92k
                f->dsp->ipred.pal_pred(dst, f->cur.stride[0], pal,
1224
5.92k
                                       pal_idx, bw4 * 4, bh4 * 4);
1225
5.92k
                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1226
0
                    hex_dump(dst, PXSTRIDE(f->cur.stride[0]),
1227
0
                             bw4 * 4, bh4 * 4, "y-pal-pred");
1228
5.92k
            }
1229
1230
1.10M
            const int intra_flags = (sm_flag(t->a, bx4) |
1231
1.10M
                                     sm_flag(&t->l, by4) |
1232
1.10M
                                     intra_edge_filter_flag);
1233
1.10M
            const int sb_has_tr = init_x + 16 < w4 ? 1 : init_y ? 0 :
1234
1.07M
                              intra_edge_flags & EDGE_I444_TOP_HAS_RIGHT;
1235
1.10M
            const int sb_has_bl = init_x ? 0 : init_y + 16 < h4 ? 1 :
1236
1.07M
                              intra_edge_flags & EDGE_I444_LEFT_HAS_BOTTOM;
1237
1.10M
            int y, x;
1238
1.10M
            const int sub_w4 = imin(w4, init_x + 16);
1239
2.55M
            for (y = init_y, t->by += init_y; y < sub_h4;
1240
1.44M
                 y += t_dim->h, t->by += t_dim->h)
1241
1.44M
            {
1242
1.44M
                pixel *dst = ((pixel *) f->cur.data[0]) +
1243
1.44M
                               4 * (t->by * PXSTRIDE(f->cur.stride[0]) +
1244
1.44M
                                    t->bx + init_x);
1245
4.93M
                for (x = init_x, t->bx += init_x; x < sub_w4;
1246
3.49M
                     x += t_dim->w, t->bx += t_dim->w)
1247
3.48M
                {
1248
3.48M
                    if (b->pal_sz[0]) goto skip_y_pred;
1249
1250
3.47M
                    int angle = b->y_angle;
1251
3.47M
                    const enum EdgeFlags edge_flags =
1252
3.47M
                        (((y > init_y || !sb_has_tr) && (x + t_dim->w >= sub_w4)) ?
1253
2.81M
                             0 : EDGE_I444_TOP_HAS_RIGHT) |
1254
3.47M
                        ((x > init_x || (!sb_has_bl && y + t_dim->h >= sub_h4)) ?
1255
2.68M
                             0 : EDGE_I444_LEFT_HAS_BOTTOM);
1256
3.47M
                    const pixel *top_sb_edge = NULL;
1257
3.47M
                    if (!(t->by & (f->sb_step - 1))) {
1258
541k
                        top_sb_edge = f->ipred_edge[0];
1259
541k
                        const int sby = t->by >> f->sb_shift;
1260
541k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1261
541k
                    }
1262
3.47M
                    const enum IntraPredMode m =
1263
3.47M
                        bytefn(dav1d_prepare_intra_edges)(t->bx,
1264
3.47M
                                                          t->bx > ts->tiling.col_start,
1265
3.47M
                                                          t->by,
1266
3.47M
                                                          t->by > ts->tiling.row_start,
1267
3.47M
                                                          ts->tiling.col_end,
1268
3.47M
                                                          ts->tiling.row_end,
1269
3.47M
                                                          edge_flags, dst,
1270
3.47M
                                                          f->cur.stride[0], top_sb_edge,
1271
3.47M
                                                          b->y_mode, &angle,
1272
3.47M
                                                          t_dim->w, t_dim->h,
1273
3.47M
                                                          f->seq_hdr->intra_edge_filter,
1274
3.47M
                                                          edge HIGHBD_CALL_SUFFIX);
1275
3.47M
                    dsp->ipred.intra_pred[m](dst, f->cur.stride[0], edge,
1276
3.47M
                                             t_dim->w * 4, t_dim->h * 4,
1277
3.47M
                                             angle | intra_flags,
1278
3.47M
                                             4 * f->bw - 4 * t->bx,
1279
3.47M
                                             4 * f->bh - 4 * t->by
1280
3.47M
                                             HIGHBD_CALL_SUFFIX);
1281
1282
3.47M
                    if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1283
0
                        hex_dump(edge - t_dim->h * 4, t_dim->h * 4,
1284
0
                                 t_dim->h * 4, 2, "l");
1285
0
                        hex_dump(edge, 0, 1, 1, "tl");
1286
0
                        hex_dump(edge + 1, t_dim->w * 4,
1287
0
                                 t_dim->w * 4, 2, "t");
1288
0
                        hex_dump(dst, f->cur.stride[0],
1289
0
                                 t_dim->w * 4, t_dim->h * 4, "y-intra-pred");
1290
0
                    }
1291
1292
3.49M
                skip_y_pred: {}
1293
3.49M
                    if (!b->skip) {
1294
969k
                        coef *cf;
1295
969k
                        int eob;
1296
969k
                        enum TxfmType txtp;
1297
969k
                        if (t->frame_thread.pass) {
1298
969k
                            const int p = t->frame_thread.pass & 1;
1299
969k
                            const int cbi = *ts->frame_thread[p].cbi++;
1300
969k
                            cf = ts->frame_thread[p].cf;
1301
969k
                            ts->frame_thread[p].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
1302
969k
                            eob  = cbi >> 5;
1303
969k
                            txtp = cbi & 0x1f;
1304
969k
                        } else {
1305
0
                            uint8_t cf_ctx;
1306
0
                            cf = bitfn(t->cf);
1307
0
                            eob = decode_coefs(t, &t->a->lcoef[bx4 + x],
1308
0
                                               &t->l.lcoef[by4 + y], b->tx, bs,
1309
0
                                               b, 1, 0, cf, &txtp, &cf_ctx);
1310
0
                            if (DEBUG_BLOCK_INFO)
1311
0
                                printf("Post-y-cf-blk[tx=%d,txtp=%d,eob=%d]: r=%d\n",
1312
0
                                       b->tx, txtp, eob, ts->msac.rng);
1313
0
                            dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
1314
0
                            dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
1315
0
                        }
1316
969k
                        if (eob >= 0) {
1317
787k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1318
0
                                coef_dump(cf, imin(t_dim->h, 8) * 4,
1319
0
                                          imin(t_dim->w, 8) * 4, 3, "dq");
1320
787k
                            dsp->itx.itxfm_add[b->tx]
1321
787k
                                              [txtp](dst,
1322
787k
                                                     f->cur.stride[0],
1323
787k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1324
787k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1325
0
                                hex_dump(dst, f->cur.stride[0],
1326
0
                                         t_dim->w * 4, t_dim->h * 4, "recon");
1327
787k
                        }
1328
2.52M
                    } else if (!t->frame_thread.pass) {
1329
0
                        dav1d_memset_pow2[t_dim->lw](&t->a->lcoef[bx4 + x], 0x40);
1330
0
                        dav1d_memset_pow2[t_dim->lh](&t->l.lcoef[by4 + y], 0x40);
1331
0
                    }
1332
3.49M
                    dst += 4 * t_dim->w;
1333
3.49M
                }
1334
1.44M
                t->bx -= x;
1335
1.44M
            }
1336
1.11M
            t->by -= y;
1337
1338
1.11M
            if (!has_chroma) continue;
1339
1340
615k
            const ptrdiff_t stride = f->cur.stride[1];
1341
1342
615k
            if (b->uv_mode == CFL_PRED) {
1343
112k
                assert(!init_x && !init_y);
1344
1345
112k
                int16_t *const ac = t->scratch.ac;
1346
112k
                pixel *y_src = ((pixel *) f->cur.data[0]) + 4 * (t->bx & ~ss_hor) +
1347
112k
                                 4 * (t->by & ~ss_ver) * PXSTRIDE(f->cur.stride[0]);
1348
112k
                const ptrdiff_t uv_off = 4 * ((t->bx >> ss_hor) +
1349
112k
                                              (t->by >> ss_ver) * PXSTRIDE(stride));
1350
112k
                pixel *const uv_dst[2] = { ((pixel *) f->cur.data[1]) + uv_off,
1351
112k
                                           ((pixel *) f->cur.data[2]) + uv_off };
1352
1353
112k
                const int furthest_r =
1354
112k
                    ((cw4 << ss_hor) + t_dim->w - 1) & ~(t_dim->w - 1);
1355
112k
                const int furthest_b =
1356
112k
                    ((ch4 << ss_ver) + t_dim->h - 1) & ~(t_dim->h - 1);
1357
112k
                dsp->ipred.cfl_ac[f->cur.p.layout - 1](ac, y_src, f->cur.stride[0],
1358
112k
                                                         cbw4 - (furthest_r >> ss_hor),
1359
112k
                                                         cbh4 - (furthest_b >> ss_ver),
1360
112k
                                                         cbw4 * 4, cbh4 * 4);
1361
338k
                for (int pl = 0; pl < 2; pl++) {
1362
225k
                    if (!b->cfl_alpha[pl]) continue;
1363
182k
                    int angle = 0;
1364
182k
                    const pixel *top_sb_edge = NULL;
1365
182k
                    if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1366
51.9k
                        top_sb_edge = f->ipred_edge[pl + 1];
1367
51.9k
                        const int sby = t->by >> f->sb_shift;
1368
51.9k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1369
51.9k
                    }
1370
182k
                    const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1371
182k
                    const int xstart = ts->tiling.col_start >> ss_hor;
1372
182k
                    const int ystart = ts->tiling.row_start >> ss_ver;
1373
182k
                    const enum IntraPredMode m =
1374
182k
                        bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1375
182k
                                                          ypos, ypos > ystart,
1376
182k
                                                          ts->tiling.col_end >> ss_hor,
1377
182k
                                                          ts->tiling.row_end >> ss_ver,
1378
182k
                                                          0, uv_dst[pl], stride,
1379
182k
                                                          top_sb_edge, DC_PRED, &angle,
1380
182k
                                                          uv_t_dim->w, uv_t_dim->h, 0,
1381
182k
                                                          edge HIGHBD_CALL_SUFFIX);
1382
182k
                    dsp->ipred.cfl_pred[m](uv_dst[pl], stride, edge,
1383
182k
                                           uv_t_dim->w * 4,
1384
182k
                                           uv_t_dim->h * 4,
1385
182k
                                           ac, b->cfl_alpha[pl]
1386
182k
                                           HIGHBD_CALL_SUFFIX);
1387
182k
                }
1388
112k
                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1389
0
                    ac_dump(ac, 4*cbw4, 4*cbh4, "ac");
1390
0
                    hex_dump(uv_dst[0], stride, cbw4 * 4, cbh4 * 4, "u-cfl-pred");
1391
0
                    hex_dump(uv_dst[1], stride, cbw4 * 4, cbh4 * 4, "v-cfl-pred");
1392
0
                }
1393
502k
            } else if (b->pal_sz[1]) {
1394
1.91k
                const ptrdiff_t uv_dstoff = 4 * ((t->bx >> ss_hor) +
1395
1.91k
                                              (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1396
1.91k
                const pixel (*pal)[8];
1397
1.91k
                const uint8_t *pal_idx;
1398
1.91k
                if (t->frame_thread.pass) {
1399
1.91k
                    const int p = t->frame_thread.pass & 1;
1400
1.91k
                    assert(ts->frame_thread[p].pal_idx);
1401
1.91k
                    pal = f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1402
1.91k
                                              ((t->bx >> 1) + (t->by & 1))];
1403
1.91k
                    pal_idx = ts->frame_thread[p].pal_idx;
1404
1.91k
                    ts->frame_thread[p].pal_idx += cbw4 * cbh4 * 8;
1405
1.91k
                } else {
1406
0
                    pal = bytefn(t->scratch.pal);
1407
0
                    pal_idx = t->scratch.pal_idx_uv;
1408
0
                }
1409
1410
1.91k
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[1]) + uv_dstoff,
1411
1.91k
                                       f->cur.stride[1], pal[1],
1412
1.91k
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1413
1.91k
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[2]) + uv_dstoff,
1414
1.91k
                                       f->cur.stride[1], pal[2],
1415
1.91k
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1416
1.91k
                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1417
0
                    hex_dump(((pixel *) f->cur.data[1]) + uv_dstoff,
1418
0
                             PXSTRIDE(f->cur.stride[1]),
1419
0
                             cbw4 * 4, cbh4 * 4, "u-pal-pred");
1420
0
                    hex_dump(((pixel *) f->cur.data[2]) + uv_dstoff,
1421
0
                             PXSTRIDE(f->cur.stride[1]),
1422
0
                             cbw4 * 4, cbh4 * 4, "v-pal-pred");
1423
0
                }
1424
1.91k
            }
1425
1426
615k
            const int sm_uv_fl = sm_uv_flag(t->a, cbx4) |
1427
615k
                                 sm_uv_flag(&t->l, cby4);
1428
615k
            const int uv_sb_has_tr =
1429
615k
                ((init_x + 16) >> ss_hor) < cw4 ? 1 : init_y ? 0 :
1430
592k
                intra_edge_flags & (EDGE_I420_TOP_HAS_RIGHT >> (f->cur.p.layout - 1));
1431
615k
            const int uv_sb_has_bl =
1432
615k
                init_x ? 0 : ((init_y + 16) >> ss_ver) < ch4 ? 1 :
1433
592k
                intra_edge_flags & (EDGE_I420_LEFT_HAS_BOTTOM >> (f->cur.p.layout - 1));
1434
615k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
1435
1.83M
            for (int pl = 0; pl < 2; pl++) {
1436
2.51M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
1437
1.29M
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
1438
1.29M
                {
1439
1.29M
                    pixel *dst = ((pixel *) f->cur.data[1 + pl]) +
1440
1.29M
                                   4 * ((t->by >> ss_ver) * PXSTRIDE(stride) +
1441
1.29M
                                        ((t->bx + init_x) >> ss_hor));
1442
2.95M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
1443
1.65M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
1444
1.65M
                    {
1445
1.65M
                        if ((b->uv_mode == CFL_PRED && b->cfl_alpha[pl]) ||
1446
1.46M
                            b->pal_sz[1])
1447
186k
                        {
1448
186k
                            goto skip_uv_pred;
1449
186k
                        }
1450
1451
1.46M
                        int angle = b->uv_angle;
1452
                        // this probably looks weird because we're using
1453
                        // luma flags in a chroma loop, but that's because
1454
                        // prepare_intra_edges() expects luma flags as input
1455
1.46M
                        const enum EdgeFlags edge_flags =
1456
1.46M
                            (((y > (init_y >> ss_ver) || !uv_sb_has_tr) &&
1457
653k
                              (x + uv_t_dim->w >= sub_cw4)) ?
1458
1.11M
                                 0 : EDGE_I444_TOP_HAS_RIGHT) |
1459
1.46M
                            ((x > (init_x >> ss_hor) ||
1460
1.11M
                              (!uv_sb_has_bl && y + uv_t_dim->h >= sub_ch4)) ?
1461
945k
                                 0 : EDGE_I444_LEFT_HAS_BOTTOM);
1462
1.46M
                        const pixel *top_sb_edge = NULL;
1463
1.46M
                        if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1464
409k
                            top_sb_edge = f->ipred_edge[1 + pl];
1465
409k
                            const int sby = t->by >> f->sb_shift;
1466
409k
                            top_sb_edge += f->sb128w * 128 * (sby - 1);
1467
409k
                        }
1468
1.46M
                        const enum IntraPredMode uv_mode =
1469
1.46M
                             b->uv_mode == CFL_PRED ? DC_PRED : b->uv_mode;
1470
1.46M
                        const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1471
1.46M
                        const int xstart = ts->tiling.col_start >> ss_hor;
1472
1.46M
                        const int ystart = ts->tiling.row_start >> ss_ver;
1473
1.46M
                        const enum IntraPredMode m =
1474
1.46M
                            bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1475
1.46M
                                                              ypos, ypos > ystart,
1476
1.46M
                                                              ts->tiling.col_end >> ss_hor,
1477
1.46M
                                                              ts->tiling.row_end >> ss_ver,
1478
1.46M
                                                              edge_flags, dst, stride,
1479
1.46M
                                                              top_sb_edge, uv_mode,
1480
1.46M
                                                              &angle, uv_t_dim->w,
1481
1.46M
                                                              uv_t_dim->h,
1482
1.46M
                                                              f->seq_hdr->intra_edge_filter,
1483
1.46M
                                                              edge HIGHBD_CALL_SUFFIX);
1484
1.46M
                        angle |= intra_edge_filter_flag;
1485
1.46M
                        dsp->ipred.intra_pred[m](dst, stride, edge,
1486
1.46M
                                                 uv_t_dim->w * 4,
1487
1.46M
                                                 uv_t_dim->h * 4,
1488
1.46M
                                                 angle | sm_uv_fl,
1489
1.46M
                                                 (4 * f->bw + ss_hor -
1490
1.46M
                                                  4 * (t->bx & ~ss_hor)) >> ss_hor,
1491
1.46M
                                                 (4 * f->bh + ss_ver -
1492
1.46M
                                                  4 * (t->by & ~ss_ver)) >> ss_ver
1493
1.46M
                                                 HIGHBD_CALL_SUFFIX);
1494
1.46M
                        if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1495
0
                            hex_dump(edge - uv_t_dim->h * 4, uv_t_dim->h * 4,
1496
0
                                     uv_t_dim->h * 4, 2, "l");
1497
0
                            hex_dump(edge, 0, 1, 1, "tl");
1498
0
                            hex_dump(edge + 1, uv_t_dim->w * 4,
1499
0
                                     uv_t_dim->w * 4, 2, "t");
1500
0
                            hex_dump(dst, stride, uv_t_dim->w * 4,
1501
0
                                     uv_t_dim->h * 4, pl ? "v-intra-pred" : "u-intra-pred");
1502
0
                        }
1503
1504
1.65M
                    skip_uv_pred: {}
1505
1.65M
                        if (!b->skip) {
1506
618k
                            enum TxfmType txtp;
1507
618k
                            int eob;
1508
618k
                            coef *cf;
1509
618k
                            if (t->frame_thread.pass) {
1510
618k
                                const int p = t->frame_thread.pass & 1;
1511
618k
                                const int cbi = *ts->frame_thread[p].cbi++;
1512
618k
                                cf = ts->frame_thread[p].cf;
1513
618k
                                ts->frame_thread[p].cf += uv_t_dim->w * uv_t_dim->h * 16;
1514
618k
                                eob  = cbi >> 5;
1515
618k
                                txtp = cbi & 0x1f;
1516
18.4E
                            } else {
1517
18.4E
                                uint8_t cf_ctx;
1518
18.4E
                                cf = bitfn(t->cf);
1519
18.4E
                                eob = decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
1520
18.4E
                                                   &t->l.ccoef[pl][cby4 + y],
1521
18.4E
                                                   b->uvtx, bs, b, 1, 1 + pl, cf,
1522
18.4E
                                                   &txtp, &cf_ctx);
1523
18.4E
                                if (DEBUG_BLOCK_INFO)
1524
0
                                    printf("Post-uv-cf-blk[pl=%d,tx=%d,"
1525
0
                                           "txtp=%d,eob=%d]: r=%d [x=%d,cbx4=%d]\n",
1526
0
                                           pl, b->uvtx, txtp, eob, ts->msac.rng, x, cbx4);
1527
18.4E
                                int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
1528
18.4E
                                int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
1529
18.4E
                                dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
1530
18.4E
                                dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
1531
18.4E
                            }
1532
618k
                            if (eob >= 0) {
1533
292k
                                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1534
0
                                    coef_dump(cf, uv_t_dim->h * 4,
1535
0
                                              uv_t_dim->w * 4, 3, "dq");
1536
292k
                                dsp->itx.itxfm_add[b->uvtx]
1537
292k
                                                  [txtp](dst, stride,
1538
292k
                                                         cf, eob HIGHBD_CALL_SUFFIX);
1539
292k
                                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1540
0
                                    hex_dump(dst, stride, uv_t_dim->w * 4,
1541
0
                                             uv_t_dim->h * 4, "recon");
1542
292k
                            }
1543
1.03M
                        } else if (!t->frame_thread.pass) {
1544
0
                            dav1d_memset_pow2[uv_t_dim->lw](&t->a->ccoef[pl][cbx4 + x], 0x40);
1545
0
                            dav1d_memset_pow2[uv_t_dim->lh](&t->l.ccoef[pl][cby4 + y], 0x40);
1546
0
                        }
1547
1.65M
                        dst += uv_t_dim->w * 4;
1548
1.65M
                    }
1549
1.29M
                    t->bx -= x << ss_hor;
1550
1.29M
                }
1551
1.22M
                t->by -= y << ss_ver;
1552
1.22M
            }
1553
615k
        }
1554
1.07M
    }
1555
1.06M
}
dav1d_recon_b_intra_16bpc
Line
Count
Source
1179
789k
{
1180
789k
    Dav1dTileState *const ts = t->ts;
1181
789k
    const Dav1dFrameContext *const f = t->f;
1182
789k
    const Dav1dDSPContext *const dsp = f->dsp;
1183
789k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1184
789k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1185
789k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1186
789k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1187
789k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1188
789k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1189
789k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1190
789k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1191
789k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1192
670k
                           (bw4 > ss_hor || t->bx & 1) &&
1193
628k
                           (bh4 > ss_ver || t->by & 1);
1194
789k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->tx];
1195
789k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
1196
1197
    // coefficient coding
1198
789k
    pixel *const edge = bitfn(t->scratch.edge) + 128;
1199
789k
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
1200
1201
789k
    const int intra_edge_filter_flag = f->seq_hdr->intra_edge_filter << 10;
1202
1203
1.59M
    for (int init_y = 0; init_y < h4; init_y += 16) {
1204
808k
        const int sub_h4 = imin(h4, 16 + init_y);
1205
808k
        const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
1206
1.64M
        for (int init_x = 0; init_x < w4; init_x += 16) {
1207
838k
            if (b->pal_sz[0]) {
1208
6.75k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1209
6.75k
                             4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1210
6.75k
                const uint8_t *pal_idx;
1211
6.75k
                if (t->frame_thread.pass) {
1212
6.75k
                    const int p = t->frame_thread.pass & 1;
1213
6.75k
                    assert(ts->frame_thread[p].pal_idx);
1214
6.75k
                    pal_idx = ts->frame_thread[p].pal_idx;
1215
6.75k
                    ts->frame_thread[p].pal_idx += bw4 * bh4 * 8;
1216
6.75k
                } else {
1217
0
                    pal_idx = t->scratch.pal_idx_y;
1218
0
                }
1219
6.75k
                const pixel *const pal = t->frame_thread.pass ?
1220
6.75k
                    f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1221
6.75k
                                        ((t->bx >> 1) + (t->by & 1))][0] :
1222
6.75k
                    bytefn(t->scratch.pal)[0];
1223
6.75k
                f->dsp->ipred.pal_pred(dst, f->cur.stride[0], pal,
1224
6.75k
                                       pal_idx, bw4 * 4, bh4 * 4);
1225
6.75k
                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1226
0
                    hex_dump(dst, PXSTRIDE(f->cur.stride[0]),
1227
0
                             bw4 * 4, bh4 * 4, "y-pal-pred");
1228
6.75k
            }
1229
1230
838k
            const int intra_flags = (sm_flag(t->a, bx4) |
1231
838k
                                     sm_flag(&t->l, by4) |
1232
838k
                                     intra_edge_filter_flag);
1233
838k
            const int sb_has_tr = init_x + 16 < w4 ? 1 : init_y ? 0 :
1234
808k
                              intra_edge_flags & EDGE_I444_TOP_HAS_RIGHT;
1235
838k
            const int sb_has_bl = init_x ? 0 : init_y + 16 < h4 ? 1 :
1236
808k
                              intra_edge_flags & EDGE_I444_LEFT_HAS_BOTTOM;
1237
838k
            int y, x;
1238
838k
            const int sub_w4 = imin(w4, init_x + 16);
1239
1.84M
            for (y = init_y, t->by += init_y; y < sub_h4;
1240
1.01M
                 y += t_dim->h, t->by += t_dim->h)
1241
1.00M
            {
1242
1.00M
                pixel *dst = ((pixel *) f->cur.data[0]) +
1243
1.00M
                               4 * (t->by * PXSTRIDE(f->cur.stride[0]) +
1244
1.00M
                                    t->bx + init_x);
1245
2.94M
                for (x = init_x, t->bx += init_x; x < sub_w4;
1246
1.93M
                     x += t_dim->w, t->bx += t_dim->w)
1247
1.93M
                {
1248
1.93M
                    if (b->pal_sz[0]) goto skip_y_pred;
1249
1250
1.92M
                    int angle = b->y_angle;
1251
1.92M
                    const enum EdgeFlags edge_flags =
1252
1.92M
                        (((y > init_y || !sb_has_tr) && (x + t_dim->w >= sub_w4)) ?
1253
1.47M
                             0 : EDGE_I444_TOP_HAS_RIGHT) |
1254
1.92M
                        ((x > init_x || (!sb_has_bl && y + t_dim->h >= sub_h4)) ?
1255
1.39M
                             0 : EDGE_I444_LEFT_HAS_BOTTOM);
1256
1.92M
                    const pixel *top_sb_edge = NULL;
1257
1.92M
                    if (!(t->by & (f->sb_step - 1))) {
1258
318k
                        top_sb_edge = f->ipred_edge[0];
1259
318k
                        const int sby = t->by >> f->sb_shift;
1260
318k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1261
318k
                    }
1262
1.92M
                    const enum IntraPredMode m =
1263
1.92M
                        bytefn(dav1d_prepare_intra_edges)(t->bx,
1264
1.92M
                                                          t->bx > ts->tiling.col_start,
1265
1.92M
                                                          t->by,
1266
1.92M
                                                          t->by > ts->tiling.row_start,
1267
1.92M
                                                          ts->tiling.col_end,
1268
1.92M
                                                          ts->tiling.row_end,
1269
1.92M
                                                          edge_flags, dst,
1270
1.92M
                                                          f->cur.stride[0], top_sb_edge,
1271
1.92M
                                                          b->y_mode, &angle,
1272
1.92M
                                                          t_dim->w, t_dim->h,
1273
1.92M
                                                          f->seq_hdr->intra_edge_filter,
1274
1.92M
                                                          edge HIGHBD_CALL_SUFFIX);
1275
1.92M
                    dsp->ipred.intra_pred[m](dst, f->cur.stride[0], edge,
1276
1.92M
                                             t_dim->w * 4, t_dim->h * 4,
1277
1.92M
                                             angle | intra_flags,
1278
1.92M
                                             4 * f->bw - 4 * t->bx,
1279
1.92M
                                             4 * f->bh - 4 * t->by
1280
1.92M
                                             HIGHBD_CALL_SUFFIX);
1281
1282
1.92M
                    if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1283
0
                        hex_dump(edge - t_dim->h * 4, t_dim->h * 4,
1284
0
                                 t_dim->h * 4, 2, "l");
1285
0
                        hex_dump(edge, 0, 1, 1, "tl");
1286
0
                        hex_dump(edge + 1, t_dim->w * 4,
1287
0
                                 t_dim->w * 4, 2, "t");
1288
0
                        hex_dump(dst, f->cur.stride[0],
1289
0
                                 t_dim->w * 4, t_dim->h * 4, "y-intra-pred");
1290
0
                    }
1291
1292
1.93M
                skip_y_pred: {}
1293
1.93M
                    if (!b->skip) {
1294
603k
                        coef *cf;
1295
603k
                        int eob;
1296
603k
                        enum TxfmType txtp;
1297
603k
                        if (t->frame_thread.pass) {
1298
603k
                            const int p = t->frame_thread.pass & 1;
1299
603k
                            const int cbi = *ts->frame_thread[p].cbi++;
1300
603k
                            cf = ts->frame_thread[p].cf;
1301
603k
                            ts->frame_thread[p].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
1302
603k
                            eob  = cbi >> 5;
1303
603k
                            txtp = cbi & 0x1f;
1304
603k
                        } else {
1305
0
                            uint8_t cf_ctx;
1306
0
                            cf = bitfn(t->cf);
1307
0
                            eob = decode_coefs(t, &t->a->lcoef[bx4 + x],
1308
0
                                               &t->l.lcoef[by4 + y], b->tx, bs,
1309
0
                                               b, 1, 0, cf, &txtp, &cf_ctx);
1310
0
                            if (DEBUG_BLOCK_INFO)
1311
0
                                printf("Post-y-cf-blk[tx=%d,txtp=%d,eob=%d]: r=%d\n",
1312
0
                                       b->tx, txtp, eob, ts->msac.rng);
1313
0
                            dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
1314
0
                            dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
1315
0
                        }
1316
603k
                        if (eob >= 0) {
1317
440k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1318
0
                                coef_dump(cf, imin(t_dim->h, 8) * 4,
1319
0
                                          imin(t_dim->w, 8) * 4, 3, "dq");
1320
440k
                            dsp->itx.itxfm_add[b->tx]
1321
440k
                                              [txtp](dst,
1322
440k
                                                     f->cur.stride[0],
1323
440k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1324
440k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1325
0
                                hex_dump(dst, f->cur.stride[0],
1326
0
                                         t_dim->w * 4, t_dim->h * 4, "recon");
1327
440k
                        }
1328
1.32M
                    } else if (!t->frame_thread.pass) {
1329
0
                        dav1d_memset_pow2[t_dim->lw](&t->a->lcoef[bx4 + x], 0x40);
1330
0
                        dav1d_memset_pow2[t_dim->lh](&t->l.lcoef[by4 + y], 0x40);
1331
0
                    }
1332
1.93M
                    dst += 4 * t_dim->w;
1333
1.93M
                }
1334
1.01M
                t->bx -= x;
1335
1.01M
            }
1336
839k
            t->by -= y;
1337
1338
839k
            if (!has_chroma) continue;
1339
1340
622k
            const ptrdiff_t stride = f->cur.stride[1];
1341
1342
622k
            if (b->uv_mode == CFL_PRED) {
1343
117k
                assert(!init_x && !init_y);
1344
1345
117k
                int16_t *const ac = t->scratch.ac;
1346
117k
                pixel *y_src = ((pixel *) f->cur.data[0]) + 4 * (t->bx & ~ss_hor) +
1347
117k
                                 4 * (t->by & ~ss_ver) * PXSTRIDE(f->cur.stride[0]);
1348
117k
                const ptrdiff_t uv_off = 4 * ((t->bx >> ss_hor) +
1349
117k
                                              (t->by >> ss_ver) * PXSTRIDE(stride));
1350
117k
                pixel *const uv_dst[2] = { ((pixel *) f->cur.data[1]) + uv_off,
1351
117k
                                           ((pixel *) f->cur.data[2]) + uv_off };
1352
1353
117k
                const int furthest_r =
1354
117k
                    ((cw4 << ss_hor) + t_dim->w - 1) & ~(t_dim->w - 1);
1355
117k
                const int furthest_b =
1356
117k
                    ((ch4 << ss_ver) + t_dim->h - 1) & ~(t_dim->h - 1);
1357
117k
                dsp->ipred.cfl_ac[f->cur.p.layout - 1](ac, y_src, f->cur.stride[0],
1358
117k
                                                         cbw4 - (furthest_r >> ss_hor),
1359
117k
                                                         cbh4 - (furthest_b >> ss_ver),
1360
117k
                                                         cbw4 * 4, cbh4 * 4);
1361
353k
                for (int pl = 0; pl < 2; pl++) {
1362
235k
                    if (!b->cfl_alpha[pl]) continue;
1363
192k
                    int angle = 0;
1364
192k
                    const pixel *top_sb_edge = NULL;
1365
192k
                    if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1366
57.5k
                        top_sb_edge = f->ipred_edge[pl + 1];
1367
57.5k
                        const int sby = t->by >> f->sb_shift;
1368
57.5k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1369
57.5k
                    }
1370
192k
                    const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1371
192k
                    const int xstart = ts->tiling.col_start >> ss_hor;
1372
192k
                    const int ystart = ts->tiling.row_start >> ss_ver;
1373
192k
                    const enum IntraPredMode m =
1374
192k
                        bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1375
192k
                                                          ypos, ypos > ystart,
1376
192k
                                                          ts->tiling.col_end >> ss_hor,
1377
192k
                                                          ts->tiling.row_end >> ss_ver,
1378
192k
                                                          0, uv_dst[pl], stride,
1379
192k
                                                          top_sb_edge, DC_PRED, &angle,
1380
192k
                                                          uv_t_dim->w, uv_t_dim->h, 0,
1381
192k
                                                          edge HIGHBD_CALL_SUFFIX);
1382
192k
                    dsp->ipred.cfl_pred[m](uv_dst[pl], stride, edge,
1383
192k
                                           uv_t_dim->w * 4,
1384
192k
                                           uv_t_dim->h * 4,
1385
192k
                                           ac, b->cfl_alpha[pl]
1386
192k
                                           HIGHBD_CALL_SUFFIX);
1387
192k
                }
1388
117k
                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1389
0
                    ac_dump(ac, 4*cbw4, 4*cbh4, "ac");
1390
0
                    hex_dump(uv_dst[0], stride, cbw4 * 4, cbh4 * 4, "u-cfl-pred");
1391
0
                    hex_dump(uv_dst[1], stride, cbw4 * 4, cbh4 * 4, "v-cfl-pred");
1392
0
                }
1393
504k
            } else if (b->pal_sz[1]) {
1394
1.58k
                const ptrdiff_t uv_dstoff = 4 * ((t->bx >> ss_hor) +
1395
1.58k
                                              (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1396
1.58k
                const pixel (*pal)[8];
1397
1.58k
                const uint8_t *pal_idx;
1398
1.58k
                if (t->frame_thread.pass) {
1399
1.58k
                    const int p = t->frame_thread.pass & 1;
1400
1.58k
                    assert(ts->frame_thread[p].pal_idx);
1401
1.58k
                    pal = f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1402
1.58k
                                              ((t->bx >> 1) + (t->by & 1))];
1403
1.58k
                    pal_idx = ts->frame_thread[p].pal_idx;
1404
1.58k
                    ts->frame_thread[p].pal_idx += cbw4 * cbh4 * 8;
1405
1.58k
                } else {
1406
0
                    pal = bytefn(t->scratch.pal);
1407
0
                    pal_idx = t->scratch.pal_idx_uv;
1408
0
                }
1409
1410
1.58k
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[1]) + uv_dstoff,
1411
1.58k
                                       f->cur.stride[1], pal[1],
1412
1.58k
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1413
1.58k
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[2]) + uv_dstoff,
1414
1.58k
                                       f->cur.stride[1], pal[2],
1415
1.58k
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1416
1.58k
                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1417
0
                    hex_dump(((pixel *) f->cur.data[1]) + uv_dstoff,
1418
0
                             PXSTRIDE(f->cur.stride[1]),
1419
0
                             cbw4 * 4, cbh4 * 4, "u-pal-pred");
1420
0
                    hex_dump(((pixel *) f->cur.data[2]) + uv_dstoff,
1421
0
                             PXSTRIDE(f->cur.stride[1]),
1422
0
                             cbw4 * 4, cbh4 * 4, "v-pal-pred");
1423
0
                }
1424
1.58k
            }
1425
1426
622k
            const int sm_uv_fl = sm_uv_flag(t->a, cbx4) |
1427
622k
                                 sm_uv_flag(&t->l, cby4);
1428
622k
            const int uv_sb_has_tr =
1429
622k
                ((init_x + 16) >> ss_hor) < cw4 ? 1 : init_y ? 0 :
1430
598k
                intra_edge_flags & (EDGE_I420_TOP_HAS_RIGHT >> (f->cur.p.layout - 1));
1431
622k
            const int uv_sb_has_bl =
1432
622k
                init_x ? 0 : ((init_y + 16) >> ss_ver) < ch4 ? 1 :
1433
598k
                intra_edge_flags & (EDGE_I420_LEFT_HAS_BOTTOM >> (f->cur.p.layout - 1));
1434
622k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
1435
1.86M
            for (int pl = 0; pl < 2; pl++) {
1436
2.57M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
1437
1.32M
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
1438
1.32M
                {
1439
1.32M
                    pixel *dst = ((pixel *) f->cur.data[1 + pl]) +
1440
1.32M
                                   4 * ((t->by >> ss_ver) * PXSTRIDE(stride) +
1441
1.32M
                                        ((t->bx + init_x) >> ss_hor));
1442
2.96M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
1443
1.63M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
1444
1.63M
                    {
1445
1.63M
                        if ((b->uv_mode == CFL_PRED && b->cfl_alpha[pl]) ||
1446
1.44M
                            b->pal_sz[1])
1447
195k
                        {
1448
195k
                            goto skip_uv_pred;
1449
195k
                        }
1450
1451
1.44M
                        int angle = b->uv_angle;
1452
                        // this probably looks weird because we're using
1453
                        // luma flags in a chroma loop, but that's because
1454
                        // prepare_intra_edges() expects luma flags as input
1455
1.44M
                        const enum EdgeFlags edge_flags =
1456
1.44M
                            (((y > (init_y >> ss_ver) || !uv_sb_has_tr) &&
1457
674k
                              (x + uv_t_dim->w >= sub_cw4)) ?
1458
1.01M
                                 0 : EDGE_I444_TOP_HAS_RIGHT) |
1459
1.44M
                            ((x > (init_x >> ss_hor) ||
1460
1.13M
                              (!uv_sb_has_bl && y + uv_t_dim->h >= sub_ch4)) ?
1461
911k
                                 0 : EDGE_I444_LEFT_HAS_BOTTOM);
1462
1.44M
                        const pixel *top_sb_edge = NULL;
1463
1.44M
                        if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1464
366k
                            top_sb_edge = f->ipred_edge[1 + pl];
1465
366k
                            const int sby = t->by >> f->sb_shift;
1466
366k
                            top_sb_edge += f->sb128w * 128 * (sby - 1);
1467
366k
                        }
1468
1.44M
                        const enum IntraPredMode uv_mode =
1469
1.44M
                             b->uv_mode == CFL_PRED ? DC_PRED : b->uv_mode;
1470
1.44M
                        const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1471
1.44M
                        const int xstart = ts->tiling.col_start >> ss_hor;
1472
1.44M
                        const int ystart = ts->tiling.row_start >> ss_ver;
1473
1.44M
                        const enum IntraPredMode m =
1474
1.44M
                            bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1475
1.44M
                                                              ypos, ypos > ystart,
1476
1.44M
                                                              ts->tiling.col_end >> ss_hor,
1477
1.44M
                                                              ts->tiling.row_end >> ss_ver,
1478
1.44M
                                                              edge_flags, dst, stride,
1479
1.44M
                                                              top_sb_edge, uv_mode,
1480
1.44M
                                                              &angle, uv_t_dim->w,
1481
1.44M
                                                              uv_t_dim->h,
1482
1.44M
                                                              f->seq_hdr->intra_edge_filter,
1483
1.44M
                                                              edge HIGHBD_CALL_SUFFIX);
1484
1.44M
                        angle |= intra_edge_filter_flag;
1485
1.44M
                        dsp->ipred.intra_pred[m](dst, stride, edge,
1486
1.44M
                                                 uv_t_dim->w * 4,
1487
1.44M
                                                 uv_t_dim->h * 4,
1488
1.44M
                                                 angle | sm_uv_fl,
1489
1.44M
                                                 (4 * f->bw + ss_hor -
1490
1.44M
                                                  4 * (t->bx & ~ss_hor)) >> ss_hor,
1491
1.44M
                                                 (4 * f->bh + ss_ver -
1492
1.44M
                                                  4 * (t->by & ~ss_ver)) >> ss_ver
1493
1.44M
                                                 HIGHBD_CALL_SUFFIX);
1494
1.44M
                        if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1495
0
                            hex_dump(edge - uv_t_dim->h * 4, uv_t_dim->h * 4,
1496
0
                                     uv_t_dim->h * 4, 2, "l");
1497
0
                            hex_dump(edge, 0, 1, 1, "tl");
1498
0
                            hex_dump(edge + 1, uv_t_dim->w * 4,
1499
0
                                     uv_t_dim->w * 4, 2, "t");
1500
0
                            hex_dump(dst, stride, uv_t_dim->w * 4,
1501
0
                                     uv_t_dim->h * 4, pl ? "v-intra-pred" : "u-intra-pred");
1502
0
                        }
1503
1504
1.63M
                    skip_uv_pred: {}
1505
1.63M
                        if (!b->skip) {
1506
658k
                            enum TxfmType txtp;
1507
658k
                            int eob;
1508
658k
                            coef *cf;
1509
658k
                            if (t->frame_thread.pass) {
1510
658k
                                const int p = t->frame_thread.pass & 1;
1511
658k
                                const int cbi = *ts->frame_thread[p].cbi++;
1512
658k
                                cf = ts->frame_thread[p].cf;
1513
658k
                                ts->frame_thread[p].cf += uv_t_dim->w * uv_t_dim->h * 16;
1514
658k
                                eob  = cbi >> 5;
1515
658k
                                txtp = cbi & 0x1f;
1516
658k
                            } else {
1517
0
                                uint8_t cf_ctx;
1518
0
                                cf = bitfn(t->cf);
1519
0
                                eob = decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
1520
0
                                                   &t->l.ccoef[pl][cby4 + y],
1521
0
                                                   b->uvtx, bs, b, 1, 1 + pl, cf,
1522
0
                                                   &txtp, &cf_ctx);
1523
0
                                if (DEBUG_BLOCK_INFO)
1524
0
                                    printf("Post-uv-cf-blk[pl=%d,tx=%d,"
1525
0
                                           "txtp=%d,eob=%d]: r=%d [x=%d,cbx4=%d]\n",
1526
0
                                           pl, b->uvtx, txtp, eob, ts->msac.rng, x, cbx4);
1527
0
                                int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
1528
0
                                int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
1529
0
                                dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
1530
0
                                dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
1531
0
                            }
1532
658k
                            if (eob >= 0) {
1533
225k
                                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1534
0
                                    coef_dump(cf, uv_t_dim->h * 4,
1535
0
                                              uv_t_dim->w * 4, 3, "dq");
1536
225k
                                dsp->itx.itxfm_add[b->uvtx]
1537
225k
                                                  [txtp](dst, stride,
1538
225k
                                                         cf, eob HIGHBD_CALL_SUFFIX);
1539
225k
                                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1540
0
                                    hex_dump(dst, stride, uv_t_dim->w * 4,
1541
0
                                             uv_t_dim->h * 4, "recon");
1542
225k
                            }
1543
977k
                        } else if (!t->frame_thread.pass) {
1544
0
                            dav1d_memset_pow2[uv_t_dim->lw](&t->a->ccoef[pl][cbx4 + x], 0x40);
1545
0
                            dav1d_memset_pow2[uv_t_dim->lh](&t->l.ccoef[pl][cby4 + y], 0x40);
1546
0
                        }
1547
1.63M
                        dst += uv_t_dim->w * 4;
1548
1.63M
                    }
1549
1.32M
                    t->bx -= x << ss_hor;
1550
1.32M
                }
1551
1.24M
                t->by -= y << ss_ver;
1552
1.24M
            }
1553
622k
        }
1554
808k
    }
1555
789k
}
1556
1557
int bytefn(dav1d_recon_b_inter)(Dav1dTaskContext *const t, const enum BlockSize bs,
1558
                                const Av1Block *const b)
1559
276k
{
1560
276k
    Dav1dTileState *const ts = t->ts;
1561
276k
    const Dav1dFrameContext *const f = t->f;
1562
276k
    const Dav1dDSPContext *const dsp = f->dsp;
1563
276k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1564
276k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1565
276k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1566
276k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1567
276k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1568
276k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1569
276k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1570
276k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1571
218k
                           (bw4 > ss_hor || t->bx & 1) &&
1572
203k
                           (bh4 > ss_ver || t->by & 1);
1573
276k
    const int chr_layout_idx = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I400 ? 0 :
1574
276k
                               DAV1D_PIXEL_LAYOUT_I444 - f->cur.p.layout;
1575
276k
    int res;
1576
1577
    // prediction
1578
276k
    const int cbh4 = (bh4 + ss_ver) >> ss_ver, cbw4 = (bw4 + ss_hor) >> ss_hor;
1579
276k
    pixel *dst = ((pixel *) f->cur.data[0]) +
1580
276k
        4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1581
276k
    const ptrdiff_t uvdstoff =
1582
276k
        4 * ((t->bx >> ss_hor) + (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1583
276k
    if (IS_KEY_OR_INTRA(f->frame_hdr)) {
1584
        // intrabc
1585
212k
        assert(!f->frame_hdr->super_res.enabled);
1586
212k
        res = mc(t, dst, NULL, f->cur.stride[0], bw4, bh4, t->bx, t->by, 0,
1587
212k
                 b->mv[0], &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1588
212k
        if (res) return res;
1589
482k
        if (has_chroma) for (int pl = 1; pl < 3; pl++) {
1590
321k
            res = mc(t, ((pixel *)f->cur.data[pl]) + uvdstoff, NULL, f->cur.stride[1],
1591
321k
                     bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1592
321k
                     t->bx & ~ss_hor, t->by & ~ss_ver, pl, b->mv[0],
1593
321k
                     &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1594
321k
            if (res) return res;
1595
321k
        }
1596
212k
    } else if (b->comp_type == COMP_INTER_NONE) {
1597
51.7k
        const Dav1dThreadPicture *const refp = &f->refp[b->ref[0]];
1598
51.7k
        const enum Filter2d filter_2d = b->filter2d;
1599
1600
51.7k
        if (imin(bw4, bh4) > 1 &&
1601
33.5k
            ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1602
27.1k
             (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1603
6.64k
        {
1604
6.64k
            res = warp_affine(t, dst, NULL, f->cur.stride[0], b_dim, 0, refp,
1605
6.64k
                              b->motion_mode == MM_WARP ? &t->warpmv :
1606
6.64k
                                  &f->frame_hdr->gmv[b->ref[0]]);
1607
6.64k
            if (res) return res;
1608
45.1k
        } else {
1609
45.1k
            res = mc(t, dst, NULL, f->cur.stride[0],
1610
45.1k
                     bw4, bh4, t->bx, t->by, 0, b->mv[0], refp, b->ref[0], filter_2d);
1611
45.1k
            if (res) return res;
1612
45.1k
            if (b->motion_mode == MM_OBMC) {
1613
5.56k
                res = obmc(t, dst, f->cur.stride[0], b_dim, 0, bx4, by4, w4, h4);
1614
5.56k
                if (res) return res;
1615
5.56k
            }
1616
45.1k
        }
1617
51.7k
        if (b->interintra_type) {
1618
2.62k
            pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1619
2.62k
            enum IntraPredMode m = b->interintra_mode == II_SMOOTH_PRED ?
1620
2.05k
                                   SMOOTH_PRED : b->interintra_mode;
1621
2.62k
            pixel *const tmp = bitfn(t->scratch.interintra);
1622
2.62k
            int angle = 0;
1623
2.62k
            const pixel *top_sb_edge = NULL;
1624
2.62k
            if (!(t->by & (f->sb_step - 1))) {
1625
590
                top_sb_edge = f->ipred_edge[0];
1626
590
                const int sby = t->by >> f->sb_shift;
1627
590
                top_sb_edge += f->sb128w * 128 * (sby - 1);
1628
590
            }
1629
2.62k
            m = bytefn(dav1d_prepare_intra_edges)(t->bx, t->bx > ts->tiling.col_start,
1630
2.62k
                                                  t->by, t->by > ts->tiling.row_start,
1631
2.62k
                                                  ts->tiling.col_end, ts->tiling.row_end,
1632
2.62k
                                                  0, dst, f->cur.stride[0], top_sb_edge,
1633
2.62k
                                                  m, &angle, bw4, bh4, 0, tl_edge
1634
2.62k
                                                  HIGHBD_CALL_SUFFIX);
1635
2.62k
            dsp->ipred.intra_pred[m](tmp, 4 * bw4 * sizeof(pixel),
1636
2.62k
                                     tl_edge, bw4 * 4, bh4 * 4, 0, 0, 0
1637
2.62k
                                     HIGHBD_CALL_SUFFIX);
1638
2.62k
            dsp->mc.blend(dst, f->cur.stride[0], tmp,
1639
2.62k
                          bw4 * 4, bh4 * 4, II_MASK(0, bs, b));
1640
2.62k
        }
1641
1642
51.7k
        if (!has_chroma) goto skip_inter_chroma_pred;
1643
1644
        // sub8x8 derivation
1645
18.2k
        int is_sub8x8 = bw4 == ss_hor || bh4 == ss_ver;
1646
18.2k
        refmvs_block *const *r;
1647
18.2k
        if (is_sub8x8) {
1648
1.72k
            assert(ss_hor == 1);
1649
1.72k
            r = &t->rt.r[(t->by & 31) + 5];
1650
1.72k
            if (bw4 == 1) is_sub8x8 &= r[0][t->bx - 1].ref.ref[0] > 0;
1651
1.72k
            if (bh4 == ss_ver) is_sub8x8 &= r[-1][t->bx].ref.ref[0] > 0;
1652
1.72k
            if (bw4 == 1 && bh4 == ss_ver)
1653
312
                is_sub8x8 &= r[-1][t->bx - 1].ref.ref[0] > 0;
1654
1.72k
        }
1655
1656
        // chroma prediction
1657
18.2k
        if (is_sub8x8) {
1658
1.65k
            assert(ss_hor == 1);
1659
1.65k
            ptrdiff_t h_off = 0, v_off = 0;
1660
1.65k
            if (bw4 == 1 && bh4 == ss_ver) {
1661
843
                for (int pl = 0; pl < 2; pl++) {
1662
562
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1663
562
                             NULL, f->cur.stride[1],
1664
562
                             bw4, bh4, t->bx - 1, t->by - 1, 1 + pl,
1665
562
                             r[-1][t->bx - 1].mv.mv[0],
1666
562
                             &f->refp[r[-1][t->bx - 1].ref.ref[0] - 1],
1667
562
                             r[-1][t->bx - 1].ref.ref[0] - 1,
1668
562
                             t->frame_thread.pass != 2 ? t->tl_4x4_filter :
1669
562
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx - 1].filter2d);
1670
562
                    if (res) return res;
1671
562
                }
1672
281
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1673
281
                h_off = 2;
1674
281
            }
1675
1.65k
            if (bw4 == 1) {
1676
811
                const enum Filter2d left_filter_2d =
1677
811
                    dav1d_filter_2d[t->l.filter[1][by4]][t->l.filter[0][by4]];
1678
2.43k
                for (int pl = 0; pl < 2; pl++) {
1679
1.62k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + v_off, NULL,
1680
1.62k
                             f->cur.stride[1], bw4, bh4, t->bx - 1,
1681
1.62k
                             t->by, 1 + pl, r[0][t->bx - 1].mv.mv[0],
1682
1.62k
                             &f->refp[r[0][t->bx - 1].ref.ref[0] - 1],
1683
1.62k
                             r[0][t->bx - 1].ref.ref[0] - 1,
1684
1.62k
                             t->frame_thread.pass != 2 ? left_filter_2d :
1685
1.62k
                                 f->frame_thread.b[(t->by * f->b4_stride) + t->bx - 1].filter2d);
1686
1.62k
                    if (res) return res;
1687
1.62k
                }
1688
811
                h_off = 2;
1689
811
            }
1690
1.65k
            if (bh4 == ss_ver) {
1691
1.12k
                const enum Filter2d top_filter_2d =
1692
1.12k
                    dav1d_filter_2d[t->a->filter[1][bx4]][t->a->filter[0][bx4]];
1693
3.36k
                for (int pl = 0; pl < 2; pl++) {
1694
2.24k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off, NULL,
1695
2.24k
                             f->cur.stride[1], bw4, bh4, t->bx, t->by - 1,
1696
2.24k
                             1 + pl, r[-1][t->bx].mv.mv[0],
1697
2.24k
                             &f->refp[r[-1][t->bx].ref.ref[0] - 1],
1698
2.24k
                             r[-1][t->bx].ref.ref[0] - 1,
1699
2.24k
                             t->frame_thread.pass != 2 ? top_filter_2d :
1700
2.24k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx].filter2d);
1701
2.24k
                    if (res) return res;
1702
2.24k
                }
1703
1.12k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1704
1.12k
            }
1705
4.95k
            for (int pl = 0; pl < 2; pl++) {
1706
3.30k
                res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off + v_off, NULL, f->cur.stride[1],
1707
3.30k
                         bw4, bh4, t->bx, t->by, 1 + pl, b->mv[0],
1708
3.30k
                         refp, b->ref[0], filter_2d);
1709
3.30k
                if (res) return res;
1710
3.30k
            }
1711
16.6k
        } else {
1712
16.6k
            if (imin(cbw4, cbh4) > 1 &&
1713
7.96k
                ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1714
7.65k
                 (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1715
531
            {
1716
1.59k
                for (int pl = 0; pl < 2; pl++) {
1717
1.06k
                    res = warp_affine(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff, NULL,
1718
1.06k
                                      f->cur.stride[1], b_dim, 1 + pl, refp,
1719
1.06k
                                      b->motion_mode == MM_WARP ? &t->warpmv :
1720
1.06k
                                          &f->frame_hdr->gmv[b->ref[0]]);
1721
1.06k
                    if (res) return res;
1722
1.06k
                }
1723
16.0k
            } else {
1724
48.2k
                for (int pl = 0; pl < 2; pl++) {
1725
32.1k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1726
32.1k
                             NULL, f->cur.stride[1],
1727
32.1k
                             bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1728
32.1k
                             t->bx & ~ss_hor, t->by & ~ss_ver,
1729
32.1k
                             1 + pl, b->mv[0], refp, b->ref[0], filter_2d);
1730
32.1k
                    if (res) return res;
1731
32.1k
                    if (b->motion_mode == MM_OBMC) {
1732
7.52k
                        res = obmc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1733
7.52k
                                   f->cur.stride[1], b_dim, 1 + pl, bx4, by4, w4, h4);
1734
7.52k
                        if (res) return res;
1735
7.52k
                    }
1736
32.1k
                }
1737
16.0k
            }
1738
16.6k
            if (b->interintra_type) {
1739
                // FIXME for 8x32 with 4:2:2 subsampling, this probably does
1740
                // the wrong thing since it will select 4x16, not 4x32, as a
1741
                // transform size...
1742
982
                const uint8_t *const ii_mask = II_MASK(chr_layout_idx, bs, b);
1743
1744
2.94k
                for (int pl = 0; pl < 2; pl++) {
1745
1.96k
                    pixel *const tmp = bitfn(t->scratch.interintra);
1746
1.96k
                    pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1747
1.96k
                    enum IntraPredMode m =
1748
1.96k
                        b->interintra_mode == II_SMOOTH_PRED ?
1749
1.51k
                        SMOOTH_PRED : b->interintra_mode;
1750
1.96k
                    int angle = 0;
1751
1.96k
                    pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1752
1.96k
                    const pixel *top_sb_edge = NULL;
1753
1.96k
                    if (!(t->by & (f->sb_step - 1))) {
1754
606
                        top_sb_edge = f->ipred_edge[pl + 1];
1755
606
                        const int sby = t->by >> f->sb_shift;
1756
606
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1757
606
                    }
1758
1.96k
                    m = bytefn(dav1d_prepare_intra_edges)(t->bx >> ss_hor,
1759
1.96k
                                                          (t->bx >> ss_hor) >
1760
1.96k
                                                              (ts->tiling.col_start >> ss_hor),
1761
1.96k
                                                          t->by >> ss_ver,
1762
1.96k
                                                          (t->by >> ss_ver) >
1763
1.96k
                                                              (ts->tiling.row_start >> ss_ver),
1764
1.96k
                                                          ts->tiling.col_end >> ss_hor,
1765
1.96k
                                                          ts->tiling.row_end >> ss_ver,
1766
1.96k
                                                          0, uvdst, f->cur.stride[1],
1767
1.96k
                                                          top_sb_edge, m,
1768
1.96k
                                                          &angle, cbw4, cbh4, 0, tl_edge
1769
1.96k
                                                          HIGHBD_CALL_SUFFIX);
1770
1.96k
                    dsp->ipred.intra_pred[m](tmp, cbw4 * 4 * sizeof(pixel),
1771
1.96k
                                             tl_edge, cbw4 * 4, cbh4 * 4, 0, 0, 0
1772
1.96k
                                             HIGHBD_CALL_SUFFIX);
1773
1.96k
                    dsp->mc.blend(uvdst, f->cur.stride[1], tmp,
1774
1.96k
                                  cbw4 * 4, cbh4 * 4, ii_mask);
1775
1.96k
                }
1776
982
            }
1777
16.6k
        }
1778
1779
51.7k
    skip_inter_chroma_pred: {}
1780
51.7k
        t->tl_4x4_filter = filter_2d;
1781
51.7k
    } else {
1782
12.2k
        const enum Filter2d filter_2d = b->filter2d;
1783
        // Maximum super block size is 128x128
1784
12.2k
        int16_t (*tmp)[128 * 128] = t->scratch.compinter;
1785
12.2k
        int jnt_weight;
1786
12.2k
        uint8_t *const seg_mask = t->scratch.seg_mask;
1787
12.2k
        const uint8_t *mask;
1788
1789
36.7k
        for (int i = 0; i < 2; i++) {
1790
24.5k
            const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1791
1792
24.5k
            if (b->inter_mode == GLOBALMV_GLOBALMV && f->gmv_warp_allowed[b->ref[i]]) {
1793
754
                res = warp_affine(t, NULL, tmp[i], bw4 * 4, b_dim, 0, refp,
1794
754
                                  &f->frame_hdr->gmv[b->ref[i]]);
1795
754
                if (res) return res;
1796
23.7k
            } else {
1797
23.7k
                res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by, 0,
1798
23.7k
                         b->mv[i], refp, b->ref[i], filter_2d);
1799
23.7k
                if (res) return res;
1800
23.7k
            }
1801
24.5k
        }
1802
12.2k
        switch (b->comp_type) {
1803
9.68k
        case COMP_INTER_AVG:
1804
9.68k
            dsp->mc.avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1805
9.68k
                        bw4 * 4, bh4 * 4 HIGHBD_CALL_SUFFIX);
1806
9.68k
            break;
1807
355
        case COMP_INTER_WEIGHTED_AVG:
1808
355
            jnt_weight = f->jnt_weights[b->ref[0]][b->ref[1]];
1809
355
            dsp->mc.w_avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1810
355
                          bw4 * 4, bh4 * 4, jnt_weight HIGHBD_CALL_SUFFIX);
1811
355
            break;
1812
1.45k
        case COMP_INTER_SEG:
1813
1.45k
            dsp->mc.w_mask[chr_layout_idx](dst, f->cur.stride[0],
1814
1.45k
                                           tmp[b->mask_sign], tmp[!b->mask_sign],
1815
1.45k
                                           bw4 * 4, bh4 * 4, seg_mask,
1816
1.45k
                                           b->mask_sign HIGHBD_CALL_SUFFIX);
1817
1.45k
            mask = seg_mask;
1818
1.45k
            break;
1819
760
        case COMP_INTER_WEDGE:
1820
760
            mask = WEDGE_MASK(0, bs, 0, b->wedge_idx);
1821
760
            dsp->mc.mask(dst, f->cur.stride[0],
1822
760
                         tmp[b->mask_sign], tmp[!b->mask_sign],
1823
760
                         bw4 * 4, bh4 * 4, mask HIGHBD_CALL_SUFFIX);
1824
760
            if (has_chroma)
1825
469
                mask = WEDGE_MASK(chr_layout_idx, bs, b->mask_sign, b->wedge_idx);
1826
760
            break;
1827
12.2k
        }
1828
1829
        // chroma
1830
20.8k
        if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1831
41.6k
            for (int i = 0; i < 2; i++) {
1832
27.7k
                const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1833
27.7k
                if (b->inter_mode == GLOBALMV_GLOBALMV &&
1834
3.50k
                    imin(cbw4, cbh4) > 1 && f->gmv_warp_allowed[b->ref[i]])
1835
296
                {
1836
296
                    res = warp_affine(t, NULL, tmp[i], bw4 * 4 >> ss_hor,
1837
296
                                      b_dim, 1 + pl,
1838
296
                                      refp, &f->frame_hdr->gmv[b->ref[i]]);
1839
296
                    if (res) return res;
1840
27.4k
                } else {
1841
27.4k
                    res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by,
1842
27.4k
                             1 + pl, b->mv[i], refp, b->ref[i], filter_2d);
1843
27.4k
                    if (res) return res;
1844
27.4k
                }
1845
27.7k
            }
1846
13.8k
            pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1847
13.8k
            switch (b->comp_type) {
1848
10.8k
            case COMP_INTER_AVG:
1849
10.8k
                dsp->mc.avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1850
10.8k
                            bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver
1851
10.8k
                            HIGHBD_CALL_SUFFIX);
1852
10.8k
                break;
1853
500
            case COMP_INTER_WEIGHTED_AVG:
1854
500
                dsp->mc.w_avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1855
500
                              bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, jnt_weight
1856
500
                              HIGHBD_CALL_SUFFIX);
1857
500
                break;
1858
938
            case COMP_INTER_WEDGE:
1859
2.55k
            case COMP_INTER_SEG:
1860
2.55k
                dsp->mc.mask(uvdst, f->cur.stride[1],
1861
2.55k
                             tmp[b->mask_sign], tmp[!b->mask_sign],
1862
2.55k
                             bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, mask
1863
2.55k
                             HIGHBD_CALL_SUFFIX);
1864
2.55k
                break;
1865
13.8k
            }
1866
13.8k
        }
1867
12.2k
    }
1868
1869
276k
    if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1870
0
        hex_dump(dst, f->cur.stride[0], b_dim[0] * 4, b_dim[1] * 4, "y-pred");
1871
0
        if (has_chroma) {
1872
0
            hex_dump(&((pixel *) f->cur.data[1])[uvdstoff], f->cur.stride[1],
1873
0
                     cbw4 * 4, cbh4 * 4, "u-pred");
1874
0
            hex_dump(&((pixel *) f->cur.data[2])[uvdstoff], f->cur.stride[1],
1875
0
                     cbw4 * 4, cbh4 * 4, "v-pred");
1876
0
        }
1877
0
    }
1878
1879
276k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1880
1881
276k
    if (b->skip) {
1882
        // reset coef contexts
1883
83.7k
        BlockContext *const a = t->a;
1884
83.7k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
1885
83.7k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
1886
83.7k
        if (has_chroma) {
1887
36.0k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
1888
36.0k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
1889
36.0k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
1890
36.0k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
1891
36.0k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
1892
36.0k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
1893
36.0k
        }
1894
83.7k
        return 0;
1895
83.7k
    }
1896
1897
192k
    const TxfmInfo *const uvtx = &dav1d_txfm_dimensions[b->uvtx];
1898
192k
    const TxfmInfo *const ytx = &dav1d_txfm_dimensions[b->max_ytx];
1899
192k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
1900
1901
386k
    for (int init_y = 0; init_y < bh4; init_y += 16) {
1902
390k
        for (int init_x = 0; init_x < bw4; init_x += 16) {
1903
            // coefficient coding & inverse transforms
1904
196k
            int y_off = !!init_y, y;
1905
196k
            dst += PXSTRIDE(f->cur.stride[0]) * 4 * init_y;
1906
399k
            for (y = init_y, t->by += init_y; y < imin(h4, init_y + 16);
1907
202k
                 y += ytx->h, y_off++)
1908
202k
            {
1909
202k
                int x, x_off = !!init_x;
1910
421k
                for (x = init_x, t->bx += init_x; x < imin(w4, init_x + 16);
1911
219k
                     x += ytx->w, x_off++)
1912
219k
                {
1913
219k
                    read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
1914
219k
                                   x_off, y_off, &dst[x * 4]);
1915
219k
                    t->bx += ytx->w;
1916
219k
                }
1917
202k
                dst += PXSTRIDE(f->cur.stride[0]) * 4 * ytx->h;
1918
202k
                t->bx -= x;
1919
202k
                t->by += ytx->h;
1920
202k
            }
1921
196k
            dst -= PXSTRIDE(f->cur.stride[0]) * 4 * y;
1922
196k
            t->by -= y;
1923
1924
            // chroma coefs and inverse transform
1925
455k
            if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1926
303k
                pixel *uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff +
1927
303k
                    (PXSTRIDE(f->cur.stride[1]) * init_y * 4 >> ss_ver);
1928
303k
                for (y = init_y >> ss_ver, t->by += init_y;
1929
622k
                     y < imin(ch4, (init_y + 16) >> ss_ver); y += uvtx->h)
1930
318k
                {
1931
318k
                    int x;
1932
318k
                    for (x = init_x >> ss_hor, t->bx += init_x;
1933
657k
                         x < imin(cw4, (init_x + 16) >> ss_hor); x += uvtx->w)
1934
339k
                    {
1935
339k
                        coef *cf;
1936
339k
                        int eob;
1937
339k
                        enum TxfmType txtp;
1938
339k
                        if (t->frame_thread.pass) {
1939
339k
                            const int p = t->frame_thread.pass & 1;
1940
339k
                            const int cbi = *ts->frame_thread[p].cbi++;
1941
339k
                            cf = ts->frame_thread[p].cf;
1942
339k
                            ts->frame_thread[p].cf += uvtx->w * uvtx->h * 16;
1943
339k
                            eob  = cbi >> 5;
1944
339k
                            txtp = cbi & 0x1f;
1945
339k
                        } else {
1946
1
                            uint8_t cf_ctx;
1947
1
                            cf = bitfn(t->cf);
1948
1
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
1949
1
                                                        bx4 + (x << ss_hor)];
1950
1
                            eob = decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
1951
1
                                               &t->l.ccoef[pl][cby4 + y],
1952
1
                                               b->uvtx, bs, b, 0, 1 + pl,
1953
1
                                               cf, &txtp, &cf_ctx);
1954
1
                            if (DEBUG_BLOCK_INFO)
1955
0
                                printf("Post-uv-cf-blk[pl=%d,tx=%d,"
1956
0
                                       "txtp=%d,eob=%d]: r=%d\n",
1957
0
                                       pl, b->uvtx, txtp, eob, ts->msac.rng);
1958
1
                            int ctw = imin(uvtx->w, (f->bw - t->bx + ss_hor) >> ss_hor);
1959
1
                            int cth = imin(uvtx->h, (f->bh - t->by + ss_ver) >> ss_ver);
1960
1
                            dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
1961
1
                            dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
1962
1
                        }
1963
339k
                        if (eob >= 0) {
1964
116k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1965
0
                                coef_dump(cf, uvtx->h * 4, uvtx->w * 4, 3, "dq");
1966
116k
                            dsp->itx.itxfm_add[b->uvtx]
1967
116k
                                              [txtp](&uvdst[4 * x],
1968
116k
                                                     f->cur.stride[1],
1969
116k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1970
116k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1971
0
                                hex_dump(&uvdst[4 * x], f->cur.stride[1],
1972
0
                                         uvtx->w * 4, uvtx->h * 4, "recon");
1973
116k
                        }
1974
339k
                        t->bx += uvtx->w << ss_hor;
1975
339k
                    }
1976
318k
                    uvdst += PXSTRIDE(f->cur.stride[1]) * 4 * uvtx->h;
1977
318k
                    t->bx -= x << ss_hor;
1978
318k
                    t->by += uvtx->h << ss_ver;
1979
318k
                }
1980
303k
                t->by -= y << ss_ver;
1981
303k
            }
1982
196k
        }
1983
193k
    }
1984
192k
    return 0;
1985
276k
}
dav1d_recon_b_inter_8bpc
Line
Count
Source
1559
162k
{
1560
162k
    Dav1dTileState *const ts = t->ts;
1561
162k
    const Dav1dFrameContext *const f = t->f;
1562
162k
    const Dav1dDSPContext *const dsp = f->dsp;
1563
162k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1564
162k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1565
162k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1566
162k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1567
162k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1568
162k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1569
162k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1570
162k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1571
111k
                           (bw4 > ss_hor || t->bx & 1) &&
1572
102k
                           (bh4 > ss_ver || t->by & 1);
1573
162k
    const int chr_layout_idx = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I400 ? 0 :
1574
162k
                               DAV1D_PIXEL_LAYOUT_I444 - f->cur.p.layout;
1575
162k
    int res;
1576
1577
    // prediction
1578
162k
    const int cbh4 = (bh4 + ss_ver) >> ss_ver, cbw4 = (bw4 + ss_hor) >> ss_hor;
1579
162k
    pixel *dst = ((pixel *) f->cur.data[0]) +
1580
162k
        4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1581
162k
    const ptrdiff_t uvdstoff =
1582
162k
        4 * ((t->bx >> ss_hor) + (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1583
162k
    if (IS_KEY_OR_INTRA(f->frame_hdr)) {
1584
        // intrabc
1585
117k
        assert(!f->frame_hdr->super_res.enabled);
1586
117k
        res = mc(t, dst, NULL, f->cur.stride[0], bw4, bh4, t->bx, t->by, 0,
1587
117k
                 b->mv[0], &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1588
117k
        if (res) return res;
1589
242k
        if (has_chroma) for (int pl = 1; pl < 3; pl++) {
1590
161k
            res = mc(t, ((pixel *)f->cur.data[pl]) + uvdstoff, NULL, f->cur.stride[1],
1591
161k
                     bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1592
161k
                     t->bx & ~ss_hor, t->by & ~ss_ver, pl, b->mv[0],
1593
161k
                     &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1594
161k
            if (res) return res;
1595
161k
        }
1596
117k
    } else if (b->comp_type == COMP_INTER_NONE) {
1597
36.6k
        const Dav1dThreadPicture *const refp = &f->refp[b->ref[0]];
1598
36.6k
        const enum Filter2d filter_2d = b->filter2d;
1599
1600
36.6k
        if (imin(bw4, bh4) > 1 &&
1601
24.2k
            ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1602
19.3k
             (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1603
5.01k
        {
1604
5.01k
            res = warp_affine(t, dst, NULL, f->cur.stride[0], b_dim, 0, refp,
1605
5.01k
                              b->motion_mode == MM_WARP ? &t->warpmv :
1606
5.01k
                                  &f->frame_hdr->gmv[b->ref[0]]);
1607
5.01k
            if (res) return res;
1608
31.6k
        } else {
1609
31.6k
            res = mc(t, dst, NULL, f->cur.stride[0],
1610
31.6k
                     bw4, bh4, t->bx, t->by, 0, b->mv[0], refp, b->ref[0], filter_2d);
1611
31.6k
            if (res) return res;
1612
31.6k
            if (b->motion_mode == MM_OBMC) {
1613
3.57k
                res = obmc(t, dst, f->cur.stride[0], b_dim, 0, bx4, by4, w4, h4);
1614
3.57k
                if (res) return res;
1615
3.57k
            }
1616
31.6k
        }
1617
36.6k
        if (b->interintra_type) {
1618
2.00k
            pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1619
2.00k
            enum IntraPredMode m = b->interintra_mode == II_SMOOTH_PRED ?
1620
1.57k
                                   SMOOTH_PRED : b->interintra_mode;
1621
2.00k
            pixel *const tmp = bitfn(t->scratch.interintra);
1622
2.00k
            int angle = 0;
1623
2.00k
            const pixel *top_sb_edge = NULL;
1624
2.00k
            if (!(t->by & (f->sb_step - 1))) {
1625
443
                top_sb_edge = f->ipred_edge[0];
1626
443
                const int sby = t->by >> f->sb_shift;
1627
443
                top_sb_edge += f->sb128w * 128 * (sby - 1);
1628
443
            }
1629
2.00k
            m = bytefn(dav1d_prepare_intra_edges)(t->bx, t->bx > ts->tiling.col_start,
1630
2.00k
                                                  t->by, t->by > ts->tiling.row_start,
1631
2.00k
                                                  ts->tiling.col_end, ts->tiling.row_end,
1632
2.00k
                                                  0, dst, f->cur.stride[0], top_sb_edge,
1633
2.00k
                                                  m, &angle, bw4, bh4, 0, tl_edge
1634
2.00k
                                                  HIGHBD_CALL_SUFFIX);
1635
2.00k
            dsp->ipred.intra_pred[m](tmp, 4 * bw4 * sizeof(pixel),
1636
2.00k
                                     tl_edge, bw4 * 4, bh4 * 4, 0, 0, 0
1637
2.00k
                                     HIGHBD_CALL_SUFFIX);
1638
2.00k
            dsp->mc.blend(dst, f->cur.stride[0], tmp,
1639
2.00k
                          bw4 * 4, bh4 * 4, II_MASK(0, bs, b));
1640
2.00k
        }
1641
1642
36.6k
        if (!has_chroma) goto skip_inter_chroma_pred;
1643
1644
        // sub8x8 derivation
1645
9.62k
        int is_sub8x8 = bw4 == ss_hor || bh4 == ss_ver;
1646
9.62k
        refmvs_block *const *r;
1647
9.62k
        if (is_sub8x8) {
1648
915
            assert(ss_hor == 1);
1649
915
            r = &t->rt.r[(t->by & 31) + 5];
1650
915
            if (bw4 == 1) is_sub8x8 &= r[0][t->bx - 1].ref.ref[0] > 0;
1651
915
            if (bh4 == ss_ver) is_sub8x8 &= r[-1][t->bx].ref.ref[0] > 0;
1652
915
            if (bw4 == 1 && bh4 == ss_ver)
1653
142
                is_sub8x8 &= r[-1][t->bx - 1].ref.ref[0] > 0;
1654
915
        }
1655
1656
        // chroma prediction
1657
9.62k
        if (is_sub8x8) {
1658
879
            assert(ss_hor == 1);
1659
879
            ptrdiff_t h_off = 0, v_off = 0;
1660
879
            if (bw4 == 1 && bh4 == ss_ver) {
1661
363
                for (int pl = 0; pl < 2; pl++) {
1662
242
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1663
242
                             NULL, f->cur.stride[1],
1664
242
                             bw4, bh4, t->bx - 1, t->by - 1, 1 + pl,
1665
242
                             r[-1][t->bx - 1].mv.mv[0],
1666
242
                             &f->refp[r[-1][t->bx - 1].ref.ref[0] - 1],
1667
242
                             r[-1][t->bx - 1].ref.ref[0] - 1,
1668
242
                             t->frame_thread.pass != 2 ? t->tl_4x4_filter :
1669
242
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx - 1].filter2d);
1670
242
                    if (res) return res;
1671
242
                }
1672
121
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1673
121
                h_off = 2;
1674
121
            }
1675
879
            if (bw4 == 1) {
1676
423
                const enum Filter2d left_filter_2d =
1677
423
                    dav1d_filter_2d[t->l.filter[1][by4]][t->l.filter[0][by4]];
1678
1.26k
                for (int pl = 0; pl < 2; pl++) {
1679
846
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + v_off, NULL,
1680
846
                             f->cur.stride[1], bw4, bh4, t->bx - 1,
1681
846
                             t->by, 1 + pl, r[0][t->bx - 1].mv.mv[0],
1682
846
                             &f->refp[r[0][t->bx - 1].ref.ref[0] - 1],
1683
846
                             r[0][t->bx - 1].ref.ref[0] - 1,
1684
846
                             t->frame_thread.pass != 2 ? left_filter_2d :
1685
846
                                 f->frame_thread.b[(t->by * f->b4_stride) + t->bx - 1].filter2d);
1686
846
                    if (res) return res;
1687
846
                }
1688
423
                h_off = 2;
1689
423
            }
1690
879
            if (bh4 == ss_ver) {
1691
577
                const enum Filter2d top_filter_2d =
1692
577
                    dav1d_filter_2d[t->a->filter[1][bx4]][t->a->filter[0][bx4]];
1693
1.73k
                for (int pl = 0; pl < 2; pl++) {
1694
1.15k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off, NULL,
1695
1.15k
                             f->cur.stride[1], bw4, bh4, t->bx, t->by - 1,
1696
1.15k
                             1 + pl, r[-1][t->bx].mv.mv[0],
1697
1.15k
                             &f->refp[r[-1][t->bx].ref.ref[0] - 1],
1698
1.15k
                             r[-1][t->bx].ref.ref[0] - 1,
1699
1.15k
                             t->frame_thread.pass != 2 ? top_filter_2d :
1700
1.15k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx].filter2d);
1701
1.15k
                    if (res) return res;
1702
1.15k
                }
1703
577
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1704
577
            }
1705
2.63k
            for (int pl = 0; pl < 2; pl++) {
1706
1.75k
                res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off + v_off, NULL, f->cur.stride[1],
1707
1.75k
                         bw4, bh4, t->bx, t->by, 1 + pl, b->mv[0],
1708
1.75k
                         refp, b->ref[0], filter_2d);
1709
1.75k
                if (res) return res;
1710
1.75k
            }
1711
8.74k
        } else {
1712
8.74k
            if (imin(cbw4, cbh4) > 1 &&
1713
4.27k
                ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1714
4.08k
                 (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1715
292
            {
1716
876
                for (int pl = 0; pl < 2; pl++) {
1717
584
                    res = warp_affine(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff, NULL,
1718
584
                                      f->cur.stride[1], b_dim, 1 + pl, refp,
1719
584
                                      b->motion_mode == MM_WARP ? &t->warpmv :
1720
584
                                          &f->frame_hdr->gmv[b->ref[0]]);
1721
584
                    if (res) return res;
1722
584
                }
1723
8.45k
            } else {
1724
25.3k
                for (int pl = 0; pl < 2; pl++) {
1725
16.9k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1726
16.9k
                             NULL, f->cur.stride[1],
1727
16.9k
                             bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1728
16.9k
                             t->bx & ~ss_hor, t->by & ~ss_ver,
1729
16.9k
                             1 + pl, b->mv[0], refp, b->ref[0], filter_2d);
1730
16.9k
                    if (res) return res;
1731
16.9k
                    if (b->motion_mode == MM_OBMC) {
1732
3.80k
                        res = obmc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1733
3.80k
                                   f->cur.stride[1], b_dim, 1 + pl, bx4, by4, w4, h4);
1734
3.80k
                        if (res) return res;
1735
3.80k
                    }
1736
16.9k
                }
1737
8.45k
            }
1738
8.74k
            if (b->interintra_type) {
1739
                // FIXME for 8x32 with 4:2:2 subsampling, this probably does
1740
                // the wrong thing since it will select 4x16, not 4x32, as a
1741
                // transform size...
1742
444
                const uint8_t *const ii_mask = II_MASK(chr_layout_idx, bs, b);
1743
1744
1.33k
                for (int pl = 0; pl < 2; pl++) {
1745
888
                    pixel *const tmp = bitfn(t->scratch.interintra);
1746
888
                    pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1747
888
                    enum IntraPredMode m =
1748
888
                        b->interintra_mode == II_SMOOTH_PRED ?
1749
666
                        SMOOTH_PRED : b->interintra_mode;
1750
888
                    int angle = 0;
1751
888
                    pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1752
888
                    const pixel *top_sb_edge = NULL;
1753
888
                    if (!(t->by & (f->sb_step - 1))) {
1754
384
                        top_sb_edge = f->ipred_edge[pl + 1];
1755
384
                        const int sby = t->by >> f->sb_shift;
1756
384
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1757
384
                    }
1758
888
                    m = bytefn(dav1d_prepare_intra_edges)(t->bx >> ss_hor,
1759
888
                                                          (t->bx >> ss_hor) >
1760
888
                                                              (ts->tiling.col_start >> ss_hor),
1761
888
                                                          t->by >> ss_ver,
1762
888
                                                          (t->by >> ss_ver) >
1763
888
                                                              (ts->tiling.row_start >> ss_ver),
1764
888
                                                          ts->tiling.col_end >> ss_hor,
1765
888
                                                          ts->tiling.row_end >> ss_ver,
1766
888
                                                          0, uvdst, f->cur.stride[1],
1767
888
                                                          top_sb_edge, m,
1768
888
                                                          &angle, cbw4, cbh4, 0, tl_edge
1769
888
                                                          HIGHBD_CALL_SUFFIX);
1770
888
                    dsp->ipred.intra_pred[m](tmp, cbw4 * 4 * sizeof(pixel),
1771
888
                                             tl_edge, cbw4 * 4, cbh4 * 4, 0, 0, 0
1772
888
                                             HIGHBD_CALL_SUFFIX);
1773
888
                    dsp->mc.blend(uvdst, f->cur.stride[1], tmp,
1774
888
                                  cbw4 * 4, cbh4 * 4, ii_mask);
1775
888
                }
1776
444
            }
1777
8.74k
        }
1778
1779
36.6k
    skip_inter_chroma_pred: {}
1780
36.6k
        t->tl_4x4_filter = filter_2d;
1781
36.6k
    } else {
1782
8.66k
        const enum Filter2d filter_2d = b->filter2d;
1783
        // Maximum super block size is 128x128
1784
8.66k
        int16_t (*tmp)[128 * 128] = t->scratch.compinter;
1785
8.66k
        int jnt_weight;
1786
8.66k
        uint8_t *const seg_mask = t->scratch.seg_mask;
1787
8.66k
        const uint8_t *mask;
1788
1789
25.9k
        for (int i = 0; i < 2; i++) {
1790
17.3k
            const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1791
1792
17.3k
            if (b->inter_mode == GLOBALMV_GLOBALMV && f->gmv_warp_allowed[b->ref[i]]) {
1793
593
                res = warp_affine(t, NULL, tmp[i], bw4 * 4, b_dim, 0, refp,
1794
593
                                  &f->frame_hdr->gmv[b->ref[i]]);
1795
593
                if (res) return res;
1796
16.7k
            } else {
1797
16.7k
                res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by, 0,
1798
16.7k
                         b->mv[i], refp, b->ref[i], filter_2d);
1799
16.7k
                if (res) return res;
1800
16.7k
            }
1801
17.3k
        }
1802
8.66k
        switch (b->comp_type) {
1803
6.91k
        case COMP_INTER_AVG:
1804
6.91k
            dsp->mc.avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1805
6.91k
                        bw4 * 4, bh4 * 4 HIGHBD_CALL_SUFFIX);
1806
6.91k
            break;
1807
181
        case COMP_INTER_WEIGHTED_AVG:
1808
181
            jnt_weight = f->jnt_weights[b->ref[0]][b->ref[1]];
1809
181
            dsp->mc.w_avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1810
181
                          bw4 * 4, bh4 * 4, jnt_weight HIGHBD_CALL_SUFFIX);
1811
181
            break;
1812
1.02k
        case COMP_INTER_SEG:
1813
1.02k
            dsp->mc.w_mask[chr_layout_idx](dst, f->cur.stride[0],
1814
1.02k
                                           tmp[b->mask_sign], tmp[!b->mask_sign],
1815
1.02k
                                           bw4 * 4, bh4 * 4, seg_mask,
1816
1.02k
                                           b->mask_sign HIGHBD_CALL_SUFFIX);
1817
1.02k
            mask = seg_mask;
1818
1.02k
            break;
1819
546
        case COMP_INTER_WEDGE:
1820
546
            mask = WEDGE_MASK(0, bs, 0, b->wedge_idx);
1821
546
            dsp->mc.mask(dst, f->cur.stride[0],
1822
546
                         tmp[b->mask_sign], tmp[!b->mask_sign],
1823
546
                         bw4 * 4, bh4 * 4, mask HIGHBD_CALL_SUFFIX);
1824
546
            if (has_chroma)
1825
282
                mask = WEDGE_MASK(chr_layout_idx, bs, b->mask_sign, b->wedge_idx);
1826
546
            break;
1827
8.66k
        }
1828
1829
        // chroma
1830
11.7k
        if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1831
23.4k
            for (int i = 0; i < 2; i++) {
1832
15.6k
                const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1833
15.6k
                if (b->inter_mode == GLOBALMV_GLOBALMV &&
1834
1.87k
                    imin(cbw4, cbh4) > 1 && f->gmv_warp_allowed[b->ref[i]])
1835
102
                {
1836
102
                    res = warp_affine(t, NULL, tmp[i], bw4 * 4 >> ss_hor,
1837
102
                                      b_dim, 1 + pl,
1838
102
                                      refp, &f->frame_hdr->gmv[b->ref[i]]);
1839
102
                    if (res) return res;
1840
15.5k
                } else {
1841
15.5k
                    res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by,
1842
15.5k
                             1 + pl, b->mv[i], refp, b->ref[i], filter_2d);
1843
15.5k
                    if (res) return res;
1844
15.5k
                }
1845
15.6k
            }
1846
7.81k
            pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1847
7.81k
            switch (b->comp_type) {
1848
6.10k
            case COMP_INTER_AVG:
1849
6.10k
                dsp->mc.avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1850
6.10k
                            bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver
1851
6.10k
                            HIGHBD_CALL_SUFFIX);
1852
6.10k
                break;
1853
268
            case COMP_INTER_WEIGHTED_AVG:
1854
268
                dsp->mc.w_avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1855
268
                              bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, jnt_weight
1856
268
                              HIGHBD_CALL_SUFFIX);
1857
268
                break;
1858
564
            case COMP_INTER_WEDGE:
1859
1.44k
            case COMP_INTER_SEG:
1860
1.44k
                dsp->mc.mask(uvdst, f->cur.stride[1],
1861
1.44k
                             tmp[b->mask_sign], tmp[!b->mask_sign],
1862
1.44k
                             bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, mask
1863
1.44k
                             HIGHBD_CALL_SUFFIX);
1864
1.44k
                break;
1865
7.81k
            }
1866
7.81k
        }
1867
8.66k
    }
1868
1869
162k
    if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1870
0
        hex_dump(dst, f->cur.stride[0], b_dim[0] * 4, b_dim[1] * 4, "y-pred");
1871
0
        if (has_chroma) {
1872
0
            hex_dump(&((pixel *) f->cur.data[1])[uvdstoff], f->cur.stride[1],
1873
0
                     cbw4 * 4, cbh4 * 4, "u-pred");
1874
0
            hex_dump(&((pixel *) f->cur.data[2])[uvdstoff], f->cur.stride[1],
1875
0
                     cbw4 * 4, cbh4 * 4, "v-pred");
1876
0
        }
1877
0
    }
1878
1879
162k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1880
1881
162k
    if (b->skip) {
1882
        // reset coef contexts
1883
50.8k
        BlockContext *const a = t->a;
1884
50.8k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
1885
50.8k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
1886
50.8k
        if (has_chroma) {
1887
11.5k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
1888
11.5k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
1889
11.5k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
1890
11.5k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
1891
11.5k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
1892
11.5k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
1893
11.5k
        }
1894
50.8k
        return 0;
1895
50.8k
    }
1896
1897
111k
    const TxfmInfo *const uvtx = &dav1d_txfm_dimensions[b->uvtx];
1898
111k
    const TxfmInfo *const ytx = &dav1d_txfm_dimensions[b->max_ytx];
1899
111k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
1900
1901
224k
    for (int init_y = 0; init_y < bh4; init_y += 16) {
1902
226k
        for (int init_x = 0; init_x < bw4; init_x += 16) {
1903
            // coefficient coding & inverse transforms
1904
114k
            int y_off = !!init_y, y;
1905
114k
            dst += PXSTRIDE(f->cur.stride[0]) * 4 * init_y;
1906
232k
            for (y = init_y, t->by += init_y; y < imin(h4, init_y + 16);
1907
117k
                 y += ytx->h, y_off++)
1908
117k
            {
1909
117k
                int x, x_off = !!init_x;
1910
246k
                for (x = init_x, t->bx += init_x; x < imin(w4, init_x + 16);
1911
129k
                     x += ytx->w, x_off++)
1912
129k
                {
1913
129k
                    read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
1914
129k
                                   x_off, y_off, &dst[x * 4]);
1915
129k
                    t->bx += ytx->w;
1916
129k
                }
1917
117k
                dst += PXSTRIDE(f->cur.stride[0]) * 4 * ytx->h;
1918
117k
                t->bx -= x;
1919
117k
                t->by += ytx->h;
1920
117k
            }
1921
114k
            dst -= PXSTRIDE(f->cur.stride[0]) * 4 * y;
1922
114k
            t->by -= y;
1923
1924
            // chroma coefs and inverse transform
1925
250k
            if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1926
166k
                pixel *uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff +
1927
166k
                    (PXSTRIDE(f->cur.stride[1]) * init_y * 4 >> ss_ver);
1928
166k
                for (y = init_y >> ss_ver, t->by += init_y;
1929
341k
                     y < imin(ch4, (init_y + 16) >> ss_ver); y += uvtx->h)
1930
174k
                {
1931
174k
                    int x;
1932
174k
                    for (x = init_x >> ss_hor, t->bx += init_x;
1933
358k
                         x < imin(cw4, (init_x + 16) >> ss_hor); x += uvtx->w)
1934
184k
                    {
1935
184k
                        coef *cf;
1936
184k
                        int eob;
1937
184k
                        enum TxfmType txtp;
1938
184k
                        if (t->frame_thread.pass) {
1939
184k
                            const int p = t->frame_thread.pass & 1;
1940
184k
                            const int cbi = *ts->frame_thread[p].cbi++;
1941
184k
                            cf = ts->frame_thread[p].cf;
1942
184k
                            ts->frame_thread[p].cf += uvtx->w * uvtx->h * 16;
1943
184k
                            eob  = cbi >> 5;
1944
184k
                            txtp = cbi & 0x1f;
1945
184k
                        } else {
1946
0
                            uint8_t cf_ctx;
1947
0
                            cf = bitfn(t->cf);
1948
0
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
1949
0
                                                        bx4 + (x << ss_hor)];
1950
0
                            eob = decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
1951
0
                                               &t->l.ccoef[pl][cby4 + y],
1952
0
                                               b->uvtx, bs, b, 0, 1 + pl,
1953
0
                                               cf, &txtp, &cf_ctx);
1954
0
                            if (DEBUG_BLOCK_INFO)
1955
0
                                printf("Post-uv-cf-blk[pl=%d,tx=%d,"
1956
0
                                       "txtp=%d,eob=%d]: r=%d\n",
1957
0
                                       pl, b->uvtx, txtp, eob, ts->msac.rng);
1958
0
                            int ctw = imin(uvtx->w, (f->bw - t->bx + ss_hor) >> ss_hor);
1959
0
                            int cth = imin(uvtx->h, (f->bh - t->by + ss_ver) >> ss_ver);
1960
0
                            dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
1961
0
                            dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
1962
0
                        }
1963
184k
                        if (eob >= 0) {
1964
60.0k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1965
0
                                coef_dump(cf, uvtx->h * 4, uvtx->w * 4, 3, "dq");
1966
60.0k
                            dsp->itx.itxfm_add[b->uvtx]
1967
60.0k
                                              [txtp](&uvdst[4 * x],
1968
60.0k
                                                     f->cur.stride[1],
1969
60.0k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1970
60.0k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1971
0
                                hex_dump(&uvdst[4 * x], f->cur.stride[1],
1972
0
                                         uvtx->w * 4, uvtx->h * 4, "recon");
1973
60.0k
                        }
1974
184k
                        t->bx += uvtx->w << ss_hor;
1975
184k
                    }
1976
174k
                    uvdst += PXSTRIDE(f->cur.stride[1]) * 4 * uvtx->h;
1977
174k
                    t->bx -= x << ss_hor;
1978
174k
                    t->by += uvtx->h << ss_ver;
1979
174k
                }
1980
166k
                t->by -= y << ss_ver;
1981
166k
            }
1982
114k
        }
1983
112k
    }
1984
111k
    return 0;
1985
162k
}
dav1d_recon_b_inter_16bpc
Line
Count
Source
1559
113k
{
1560
113k
    Dav1dTileState *const ts = t->ts;
1561
113k
    const Dav1dFrameContext *const f = t->f;
1562
113k
    const Dav1dDSPContext *const dsp = f->dsp;
1563
113k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1564
113k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1565
113k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1566
113k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1567
113k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1568
113k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1569
113k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1570
113k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1571
107k
                           (bw4 > ss_hor || t->bx & 1) &&
1572
100k
                           (bh4 > ss_ver || t->by & 1);
1573
113k
    const int chr_layout_idx = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I400 ? 0 :
1574
113k
                               DAV1D_PIXEL_LAYOUT_I444 - f->cur.p.layout;
1575
113k
    int res;
1576
1577
    // prediction
1578
113k
    const int cbh4 = (bh4 + ss_ver) >> ss_ver, cbw4 = (bw4 + ss_hor) >> ss_hor;
1579
113k
    pixel *dst = ((pixel *) f->cur.data[0]) +
1580
113k
        4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1581
113k
    const ptrdiff_t uvdstoff =
1582
113k
        4 * ((t->bx >> ss_hor) + (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1583
113k
    if (IS_KEY_OR_INTRA(f->frame_hdr)) {
1584
        // intrabc
1585
94.9k
        assert(!f->frame_hdr->super_res.enabled);
1586
94.9k
        res = mc(t, dst, NULL, f->cur.stride[0], bw4, bh4, t->bx, t->by, 0,
1587
94.9k
                 b->mv[0], &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1588
94.9k
        if (res) return res;
1589
240k
        if (has_chroma) for (int pl = 1; pl < 3; pl++) {
1590
160k
            res = mc(t, ((pixel *)f->cur.data[pl]) + uvdstoff, NULL, f->cur.stride[1],
1591
160k
                     bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1592
160k
                     t->bx & ~ss_hor, t->by & ~ss_ver, pl, b->mv[0],
1593
160k
                     &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1594
160k
            if (res) return res;
1595
160k
        }
1596
94.9k
    } else if (b->comp_type == COMP_INTER_NONE) {
1597
15.0k
        const Dav1dThreadPicture *const refp = &f->refp[b->ref[0]];
1598
15.0k
        const enum Filter2d filter_2d = b->filter2d;
1599
1600
15.0k
        if (imin(bw4, bh4) > 1 &&
1601
9.21k
            ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1602
7.76k
             (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1603
1.63k
        {
1604
1.63k
            res = warp_affine(t, dst, NULL, f->cur.stride[0], b_dim, 0, refp,
1605
1.63k
                              b->motion_mode == MM_WARP ? &t->warpmv :
1606
1.63k
                                  &f->frame_hdr->gmv[b->ref[0]]);
1607
1.63k
            if (res) return res;
1608
13.4k
        } else {
1609
13.4k
            res = mc(t, dst, NULL, f->cur.stride[0],
1610
13.4k
                     bw4, bh4, t->bx, t->by, 0, b->mv[0], refp, b->ref[0], filter_2d);
1611
13.4k
            if (res) return res;
1612
13.4k
            if (b->motion_mode == MM_OBMC) {
1613
1.99k
                res = obmc(t, dst, f->cur.stride[0], b_dim, 0, bx4, by4, w4, h4);
1614
1.99k
                if (res) return res;
1615
1.99k
            }
1616
13.4k
        }
1617
15.0k
        if (b->interintra_type) {
1618
620
            pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1619
620
            enum IntraPredMode m = b->interintra_mode == II_SMOOTH_PRED ?
1620
482
                                   SMOOTH_PRED : b->interintra_mode;
1621
620
            pixel *const tmp = bitfn(t->scratch.interintra);
1622
620
            int angle = 0;
1623
620
            const pixel *top_sb_edge = NULL;
1624
620
            if (!(t->by & (f->sb_step - 1))) {
1625
147
                top_sb_edge = f->ipred_edge[0];
1626
147
                const int sby = t->by >> f->sb_shift;
1627
147
                top_sb_edge += f->sb128w * 128 * (sby - 1);
1628
147
            }
1629
620
            m = bytefn(dav1d_prepare_intra_edges)(t->bx, t->bx > ts->tiling.col_start,
1630
620
                                                  t->by, t->by > ts->tiling.row_start,
1631
620
                                                  ts->tiling.col_end, ts->tiling.row_end,
1632
620
                                                  0, dst, f->cur.stride[0], top_sb_edge,
1633
620
                                                  m, &angle, bw4, bh4, 0, tl_edge
1634
620
                                                  HIGHBD_CALL_SUFFIX);
1635
620
            dsp->ipred.intra_pred[m](tmp, 4 * bw4 * sizeof(pixel),
1636
620
                                     tl_edge, bw4 * 4, bh4 * 4, 0, 0, 0
1637
620
                                     HIGHBD_CALL_SUFFIX);
1638
620
            dsp->mc.blend(dst, f->cur.stride[0], tmp,
1639
620
                          bw4 * 4, bh4 * 4, II_MASK(0, bs, b));
1640
620
        }
1641
1642
15.0k
        if (!has_chroma) goto skip_inter_chroma_pred;
1643
1644
        // sub8x8 derivation
1645
8.64k
        int is_sub8x8 = bw4 == ss_hor || bh4 == ss_ver;
1646
8.64k
        refmvs_block *const *r;
1647
8.64k
        if (is_sub8x8) {
1648
809
            assert(ss_hor == 1);
1649
809
            r = &t->rt.r[(t->by & 31) + 5];
1650
809
            if (bw4 == 1) is_sub8x8 &= r[0][t->bx - 1].ref.ref[0] > 0;
1651
809
            if (bh4 == ss_ver) is_sub8x8 &= r[-1][t->bx].ref.ref[0] > 0;
1652
809
            if (bw4 == 1 && bh4 == ss_ver)
1653
170
                is_sub8x8 &= r[-1][t->bx - 1].ref.ref[0] > 0;
1654
809
        }
1655
1656
        // chroma prediction
1657
8.64k
        if (is_sub8x8) {
1658
774
            assert(ss_hor == 1);
1659
774
            ptrdiff_t h_off = 0, v_off = 0;
1660
774
            if (bw4 == 1 && bh4 == ss_ver) {
1661
480
                for (int pl = 0; pl < 2; pl++) {
1662
320
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1663
320
                             NULL, f->cur.stride[1],
1664
320
                             bw4, bh4, t->bx - 1, t->by - 1, 1 + pl,
1665
320
                             r[-1][t->bx - 1].mv.mv[0],
1666
320
                             &f->refp[r[-1][t->bx - 1].ref.ref[0] - 1],
1667
320
                             r[-1][t->bx - 1].ref.ref[0] - 1,
1668
320
                             t->frame_thread.pass != 2 ? t->tl_4x4_filter :
1669
320
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx - 1].filter2d);
1670
320
                    if (res) return res;
1671
320
                }
1672
160
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1673
160
                h_off = 2;
1674
160
            }
1675
774
            if (bw4 == 1) {
1676
388
                const enum Filter2d left_filter_2d =
1677
388
                    dav1d_filter_2d[t->l.filter[1][by4]][t->l.filter[0][by4]];
1678
1.16k
                for (int pl = 0; pl < 2; pl++) {
1679
776
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + v_off, NULL,
1680
776
                             f->cur.stride[1], bw4, bh4, t->bx - 1,
1681
776
                             t->by, 1 + pl, r[0][t->bx - 1].mv.mv[0],
1682
776
                             &f->refp[r[0][t->bx - 1].ref.ref[0] - 1],
1683
776
                             r[0][t->bx - 1].ref.ref[0] - 1,
1684
776
                             t->frame_thread.pass != 2 ? left_filter_2d :
1685
776
                                 f->frame_thread.b[(t->by * f->b4_stride) + t->bx - 1].filter2d);
1686
776
                    if (res) return res;
1687
776
                }
1688
388
                h_off = 2;
1689
388
            }
1690
774
            if (bh4 == ss_ver) {
1691
546
                const enum Filter2d top_filter_2d =
1692
546
                    dav1d_filter_2d[t->a->filter[1][bx4]][t->a->filter[0][bx4]];
1693
1.63k
                for (int pl = 0; pl < 2; pl++) {
1694
1.09k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off, NULL,
1695
1.09k
                             f->cur.stride[1], bw4, bh4, t->bx, t->by - 1,
1696
1.09k
                             1 + pl, r[-1][t->bx].mv.mv[0],
1697
1.09k
                             &f->refp[r[-1][t->bx].ref.ref[0] - 1],
1698
1.09k
                             r[-1][t->bx].ref.ref[0] - 1,
1699
1.09k
                             t->frame_thread.pass != 2 ? top_filter_2d :
1700
1.09k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx].filter2d);
1701
1.09k
                    if (res) return res;
1702
1.09k
                }
1703
546
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1704
546
            }
1705
2.32k
            for (int pl = 0; pl < 2; pl++) {
1706
1.54k
                res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off + v_off, NULL, f->cur.stride[1],
1707
1.54k
                         bw4, bh4, t->bx, t->by, 1 + pl, b->mv[0],
1708
1.54k
                         refp, b->ref[0], filter_2d);
1709
1.54k
                if (res) return res;
1710
1.54k
            }
1711
7.86k
        } else {
1712
7.86k
            if (imin(cbw4, cbh4) > 1 &&
1713
3.69k
                ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1714
3.56k
                 (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1715
239
            {
1716
717
                for (int pl = 0; pl < 2; pl++) {
1717
478
                    res = warp_affine(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff, NULL,
1718
478
                                      f->cur.stride[1], b_dim, 1 + pl, refp,
1719
478
                                      b->motion_mode == MM_WARP ? &t->warpmv :
1720
478
                                          &f->frame_hdr->gmv[b->ref[0]]);
1721
478
                    if (res) return res;
1722
478
                }
1723
7.62k
            } else {
1724
22.8k
                for (int pl = 0; pl < 2; pl++) {
1725
15.2k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1726
15.2k
                             NULL, f->cur.stride[1],
1727
15.2k
                             bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1728
15.2k
                             t->bx & ~ss_hor, t->by & ~ss_ver,
1729
15.2k
                             1 + pl, b->mv[0], refp, b->ref[0], filter_2d);
1730
15.2k
                    if (res) return res;
1731
15.2k
                    if (b->motion_mode == MM_OBMC) {
1732
3.72k
                        res = obmc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1733
3.72k
                                   f->cur.stride[1], b_dim, 1 + pl, bx4, by4, w4, h4);
1734
3.72k
                        if (res) return res;
1735
3.72k
                    }
1736
15.2k
                }
1737
7.62k
            }
1738
7.86k
            if (b->interintra_type) {
1739
                // FIXME for 8x32 with 4:2:2 subsampling, this probably does
1740
                // the wrong thing since it will select 4x16, not 4x32, as a
1741
                // transform size...
1742
538
                const uint8_t *const ii_mask = II_MASK(chr_layout_idx, bs, b);
1743
1744
1.61k
                for (int pl = 0; pl < 2; pl++) {
1745
1.07k
                    pixel *const tmp = bitfn(t->scratch.interintra);
1746
1.07k
                    pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1747
1.07k
                    enum IntraPredMode m =
1748
1.07k
                        b->interintra_mode == II_SMOOTH_PRED ?
1749
852
                        SMOOTH_PRED : b->interintra_mode;
1750
1.07k
                    int angle = 0;
1751
1.07k
                    pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1752
1.07k
                    const pixel *top_sb_edge = NULL;
1753
1.07k
                    if (!(t->by & (f->sb_step - 1))) {
1754
222
                        top_sb_edge = f->ipred_edge[pl + 1];
1755
222
                        const int sby = t->by >> f->sb_shift;
1756
222
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1757
222
                    }
1758
1.07k
                    m = bytefn(dav1d_prepare_intra_edges)(t->bx >> ss_hor,
1759
1.07k
                                                          (t->bx >> ss_hor) >
1760
1.07k
                                                              (ts->tiling.col_start >> ss_hor),
1761
1.07k
                                                          t->by >> ss_ver,
1762
1.07k
                                                          (t->by >> ss_ver) >
1763
1.07k
                                                              (ts->tiling.row_start >> ss_ver),
1764
1.07k
                                                          ts->tiling.col_end >> ss_hor,
1765
1.07k
                                                          ts->tiling.row_end >> ss_ver,
1766
1.07k
                                                          0, uvdst, f->cur.stride[1],
1767
1.07k
                                                          top_sb_edge, m,
1768
1.07k
                                                          &angle, cbw4, cbh4, 0, tl_edge
1769
1.07k
                                                          HIGHBD_CALL_SUFFIX);
1770
1.07k
                    dsp->ipred.intra_pred[m](tmp, cbw4 * 4 * sizeof(pixel),
1771
1.07k
                                             tl_edge, cbw4 * 4, cbh4 * 4, 0, 0, 0
1772
1.07k
                                             HIGHBD_CALL_SUFFIX);
1773
1.07k
                    dsp->mc.blend(uvdst, f->cur.stride[1], tmp,
1774
1.07k
                                  cbw4 * 4, cbh4 * 4, ii_mask);
1775
1.07k
                }
1776
538
            }
1777
7.86k
        }
1778
1779
15.0k
    skip_inter_chroma_pred: {}
1780
15.0k
        t->tl_4x4_filter = filter_2d;
1781
15.0k
    } else {
1782
3.59k
        const enum Filter2d filter_2d = b->filter2d;
1783
        // Maximum super block size is 128x128
1784
3.59k
        int16_t (*tmp)[128 * 128] = t->scratch.compinter;
1785
3.59k
        int jnt_weight;
1786
3.59k
        uint8_t *const seg_mask = t->scratch.seg_mask;
1787
3.59k
        const uint8_t *mask;
1788
1789
10.7k
        for (int i = 0; i < 2; i++) {
1790
7.19k
            const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1791
1792
7.19k
            if (b->inter_mode == GLOBALMV_GLOBALMV && f->gmv_warp_allowed[b->ref[i]]) {
1793
161
                res = warp_affine(t, NULL, tmp[i], bw4 * 4, b_dim, 0, refp,
1794
161
                                  &f->frame_hdr->gmv[b->ref[i]]);
1795
161
                if (res) return res;
1796
7.03k
            } else {
1797
7.03k
                res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by, 0,
1798
7.03k
                         b->mv[i], refp, b->ref[i], filter_2d);
1799
7.03k
                if (res) return res;
1800
7.03k
            }
1801
7.19k
        }
1802
3.59k
        switch (b->comp_type) {
1803
2.77k
        case COMP_INTER_AVG:
1804
2.77k
            dsp->mc.avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1805
2.77k
                        bw4 * 4, bh4 * 4 HIGHBD_CALL_SUFFIX);
1806
2.77k
            break;
1807
174
        case COMP_INTER_WEIGHTED_AVG:
1808
174
            jnt_weight = f->jnt_weights[b->ref[0]][b->ref[1]];
1809
174
            dsp->mc.w_avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1810
174
                          bw4 * 4, bh4 * 4, jnt_weight HIGHBD_CALL_SUFFIX);
1811
174
            break;
1812
432
        case COMP_INTER_SEG:
1813
432
            dsp->mc.w_mask[chr_layout_idx](dst, f->cur.stride[0],
1814
432
                                           tmp[b->mask_sign], tmp[!b->mask_sign],
1815
432
                                           bw4 * 4, bh4 * 4, seg_mask,
1816
432
                                           b->mask_sign HIGHBD_CALL_SUFFIX);
1817
432
            mask = seg_mask;
1818
432
            break;
1819
214
        case COMP_INTER_WEDGE:
1820
214
            mask = WEDGE_MASK(0, bs, 0, b->wedge_idx);
1821
214
            dsp->mc.mask(dst, f->cur.stride[0],
1822
214
                         tmp[b->mask_sign], tmp[!b->mask_sign],
1823
214
                         bw4 * 4, bh4 * 4, mask HIGHBD_CALL_SUFFIX);
1824
214
            if (has_chroma)
1825
187
                mask = WEDGE_MASK(chr_layout_idx, bs, b->mask_sign, b->wedge_idx);
1826
214
            break;
1827
3.59k
        }
1828
1829
        // chroma
1830
9.12k
        if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1831
18.2k
            for (int i = 0; i < 2; i++) {
1832
12.1k
                const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1833
12.1k
                if (b->inter_mode == GLOBALMV_GLOBALMV &&
1834
1.63k
                    imin(cbw4, cbh4) > 1 && f->gmv_warp_allowed[b->ref[i]])
1835
194
                {
1836
194
                    res = warp_affine(t, NULL, tmp[i], bw4 * 4 >> ss_hor,
1837
194
                                      b_dim, 1 + pl,
1838
194
                                      refp, &f->frame_hdr->gmv[b->ref[i]]);
1839
194
                    if (res) return res;
1840
11.9k
                } else {
1841
11.9k
                    res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by,
1842
11.9k
                             1 + pl, b->mv[i], refp, b->ref[i], filter_2d);
1843
11.9k
                    if (res) return res;
1844
11.9k
                }
1845
12.1k
            }
1846
6.08k
            pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1847
6.08k
            switch (b->comp_type) {
1848
4.73k
            case COMP_INTER_AVG:
1849
4.73k
                dsp->mc.avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1850
4.73k
                            bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver
1851
4.73k
                            HIGHBD_CALL_SUFFIX);
1852
4.73k
                break;
1853
232
            case COMP_INTER_WEIGHTED_AVG:
1854
232
                dsp->mc.w_avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1855
232
                              bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, jnt_weight
1856
232
                              HIGHBD_CALL_SUFFIX);
1857
232
                break;
1858
374
            case COMP_INTER_WEDGE:
1859
1.11k
            case COMP_INTER_SEG:
1860
1.11k
                dsp->mc.mask(uvdst, f->cur.stride[1],
1861
1.11k
                             tmp[b->mask_sign], tmp[!b->mask_sign],
1862
1.11k
                             bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, mask
1863
1.11k
                             HIGHBD_CALL_SUFFIX);
1864
1.11k
                break;
1865
6.08k
            }
1866
6.08k
        }
1867
3.59k
    }
1868
1869
113k
    if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1870
0
        hex_dump(dst, f->cur.stride[0], b_dim[0] * 4, b_dim[1] * 4, "y-pred");
1871
0
        if (has_chroma) {
1872
0
            hex_dump(&((pixel *) f->cur.data[1])[uvdstoff], f->cur.stride[1],
1873
0
                     cbw4 * 4, cbh4 * 4, "u-pred");
1874
0
            hex_dump(&((pixel *) f->cur.data[2])[uvdstoff], f->cur.stride[1],
1875
0
                     cbw4 * 4, cbh4 * 4, "v-pred");
1876
0
        }
1877
0
    }
1878
1879
113k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1880
1881
113k
    if (b->skip) {
1882
        // reset coef contexts
1883
32.8k
        BlockContext *const a = t->a;
1884
32.8k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
1885
32.8k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
1886
32.8k
        if (has_chroma) {
1887
24.4k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
1888
24.4k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
1889
24.4k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
1890
24.4k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
1891
24.4k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
1892
24.4k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
1893
24.4k
        }
1894
32.8k
        return 0;
1895
32.8k
    }
1896
1897
80.8k
    const TxfmInfo *const uvtx = &dav1d_txfm_dimensions[b->uvtx];
1898
80.8k
    const TxfmInfo *const ytx = &dav1d_txfm_dimensions[b->max_ytx];
1899
80.8k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
1900
1901
162k
    for (int init_y = 0; init_y < bh4; init_y += 16) {
1902
163k
        for (int init_x = 0; init_x < bw4; init_x += 16) {
1903
            // coefficient coding & inverse transforms
1904
82.3k
            int y_off = !!init_y, y;
1905
82.3k
            dst += PXSTRIDE(f->cur.stride[0]) * 4 * init_y;
1906
166k
            for (y = init_y, t->by += init_y; y < imin(h4, init_y + 16);
1907
84.5k
                 y += ytx->h, y_off++)
1908
84.5k
            {
1909
84.5k
                int x, x_off = !!init_x;
1910
174k
                for (x = init_x, t->bx += init_x; x < imin(w4, init_x + 16);
1911
90.1k
                     x += ytx->w, x_off++)
1912
90.1k
                {
1913
90.1k
                    read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
1914
90.1k
                                   x_off, y_off, &dst[x * 4]);
1915
90.1k
                    t->bx += ytx->w;
1916
90.1k
                }
1917
84.5k
                dst += PXSTRIDE(f->cur.stride[0]) * 4 * ytx->h;
1918
84.5k
                t->bx -= x;
1919
84.5k
                t->by += ytx->h;
1920
84.5k
            }
1921
82.3k
            dst -= PXSTRIDE(f->cur.stride[0]) * 4 * y;
1922
82.3k
            t->by -= y;
1923
1924
            // chroma coefs and inverse transform
1925
205k
            if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1926
137k
                pixel *uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff +
1927
137k
                    (PXSTRIDE(f->cur.stride[1]) * init_y * 4 >> ss_ver);
1928
137k
                for (y = init_y >> ss_ver, t->by += init_y;
1929
281k
                     y < imin(ch4, (init_y + 16) >> ss_ver); y += uvtx->h)
1930
144k
                {
1931
144k
                    int x;
1932
144k
                    for (x = init_x >> ss_hor, t->bx += init_x;
1933
299k
                         x < imin(cw4, (init_x + 16) >> ss_hor); x += uvtx->w)
1934
154k
                    {
1935
154k
                        coef *cf;
1936
154k
                        int eob;
1937
154k
                        enum TxfmType txtp;
1938
154k
                        if (t->frame_thread.pass) {
1939
154k
                            const int p = t->frame_thread.pass & 1;
1940
154k
                            const int cbi = *ts->frame_thread[p].cbi++;
1941
154k
                            cf = ts->frame_thread[p].cf;
1942
154k
                            ts->frame_thread[p].cf += uvtx->w * uvtx->h * 16;
1943
154k
                            eob  = cbi >> 5;
1944
154k
                            txtp = cbi & 0x1f;
1945
154k
                        } else {
1946
1
                            uint8_t cf_ctx;
1947
1
                            cf = bitfn(t->cf);
1948
1
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
1949
1
                                                        bx4 + (x << ss_hor)];
1950
1
                            eob = decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
1951
1
                                               &t->l.ccoef[pl][cby4 + y],
1952
1
                                               b->uvtx, bs, b, 0, 1 + pl,
1953
1
                                               cf, &txtp, &cf_ctx);
1954
1
                            if (DEBUG_BLOCK_INFO)
1955
0
                                printf("Post-uv-cf-blk[pl=%d,tx=%d,"
1956
0
                                       "txtp=%d,eob=%d]: r=%d\n",
1957
0
                                       pl, b->uvtx, txtp, eob, ts->msac.rng);
1958
1
                            int ctw = imin(uvtx->w, (f->bw - t->bx + ss_hor) >> ss_hor);
1959
1
                            int cth = imin(uvtx->h, (f->bh - t->by + ss_ver) >> ss_ver);
1960
1
                            dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
1961
1
                            dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
1962
1
                        }
1963
154k
                        if (eob >= 0) {
1964
56.2k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1965
0
                                coef_dump(cf, uvtx->h * 4, uvtx->w * 4, 3, "dq");
1966
56.2k
                            dsp->itx.itxfm_add[b->uvtx]
1967
56.2k
                                              [txtp](&uvdst[4 * x],
1968
56.2k
                                                     f->cur.stride[1],
1969
56.2k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1970
56.2k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1971
0
                                hex_dump(&uvdst[4 * x], f->cur.stride[1],
1972
0
                                         uvtx->w * 4, uvtx->h * 4, "recon");
1973
56.2k
                        }
1974
154k
                        t->bx += uvtx->w << ss_hor;
1975
154k
                    }
1976
144k
                    uvdst += PXSTRIDE(f->cur.stride[1]) * 4 * uvtx->h;
1977
144k
                    t->bx -= x << ss_hor;
1978
144k
                    t->by += uvtx->h << ss_ver;
1979
144k
                }
1980
137k
                t->by -= y << ss_ver;
1981
137k
            }
1982
82.3k
        }
1983
81.3k
    }
1984
80.8k
    return 0;
1985
113k
}
1986
1987
78.0k
void bytefn(dav1d_filter_sbrow_deblock_cols)(Dav1dFrameContext *const f, const int sby) {
1988
78.0k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK) ||
1989
78.0k
        (!f->frame_hdr->loopfilter.level_y[0] && !f->frame_hdr->loopfilter.level_y[1]))
1990
0
    {
1991
0
        return;
1992
0
    }
1993
78.0k
    const int y = sby * f->sb_step * 4;
1994
78.0k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1995
78.0k
    pixel *const p[3] = {
1996
78.0k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
1997
78.0k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
1998
78.0k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
1999
78.0k
    };
2000
78.0k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2001
78.0k
    bytefn(dav1d_loopfilter_sbrow_cols)(f, p, mask, sby,
2002
78.0k
                                        f->lf.start_of_tile_row[sby]);
2003
78.0k
}
dav1d_filter_sbrow_deblock_cols_8bpc
Line
Count
Source
1987
50.4k
void bytefn(dav1d_filter_sbrow_deblock_cols)(Dav1dFrameContext *const f, const int sby) {
1988
50.4k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK) ||
1989
50.4k
        (!f->frame_hdr->loopfilter.level_y[0] && !f->frame_hdr->loopfilter.level_y[1]))
1990
0
    {
1991
0
        return;
1992
0
    }
1993
50.4k
    const int y = sby * f->sb_step * 4;
1994
50.4k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1995
50.4k
    pixel *const p[3] = {
1996
50.4k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
1997
50.4k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
1998
50.4k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
1999
50.4k
    };
2000
50.4k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2001
50.4k
    bytefn(dav1d_loopfilter_sbrow_cols)(f, p, mask, sby,
2002
50.4k
                                        f->lf.start_of_tile_row[sby]);
2003
50.4k
}
dav1d_filter_sbrow_deblock_cols_16bpc
Line
Count
Source
1987
27.6k
void bytefn(dav1d_filter_sbrow_deblock_cols)(Dav1dFrameContext *const f, const int sby) {
1988
27.6k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK) ||
1989
27.6k
        (!f->frame_hdr->loopfilter.level_y[0] && !f->frame_hdr->loopfilter.level_y[1]))
1990
0
    {
1991
0
        return;
1992
0
    }
1993
27.6k
    const int y = sby * f->sb_step * 4;
1994
27.6k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1995
27.6k
    pixel *const p[3] = {
1996
27.6k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
1997
27.6k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
1998
27.6k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
1999
27.6k
    };
2000
27.6k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2001
27.6k
    bytefn(dav1d_loopfilter_sbrow_cols)(f, p, mask, sby,
2002
27.6k
                                        f->lf.start_of_tile_row[sby]);
2003
27.6k
}
2004
2005
95.1k
void bytefn(dav1d_filter_sbrow_deblock_rows)(Dav1dFrameContext *const f, const int sby) {
2006
95.1k
    const int y = sby * f->sb_step * 4;
2007
95.1k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2008
95.1k
    pixel *const p[3] = {
2009
95.1k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2010
95.1k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2011
95.1k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2012
95.1k
    };
2013
95.1k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2014
95.1k
    if (f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK &&
2015
95.1k
        (f->frame_hdr->loopfilter.level_y[0] || f->frame_hdr->loopfilter.level_y[1]))
2016
77.8k
    {
2017
77.8k
        bytefn(dav1d_loopfilter_sbrow_rows)(f, p, mask, sby);
2018
77.8k
    }
2019
95.1k
    if (f->seq_hdr->cdef || f->lf.restore_planes) {
2020
        // Store loop filtered pixels required by CDEF / LR
2021
82.3k
        bytefn(dav1d_copy_lpf)(f, p, sby);
2022
82.3k
    }
2023
95.1k
}
dav1d_filter_sbrow_deblock_rows_8bpc
Line
Count
Source
2005
61.0k
void bytefn(dav1d_filter_sbrow_deblock_rows)(Dav1dFrameContext *const f, const int sby) {
2006
61.0k
    const int y = sby * f->sb_step * 4;
2007
61.0k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2008
61.0k
    pixel *const p[3] = {
2009
61.0k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2010
61.0k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2011
61.0k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2012
61.0k
    };
2013
61.0k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2014
61.0k
    if (f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK &&
2015
61.0k
        (f->frame_hdr->loopfilter.level_y[0] || f->frame_hdr->loopfilter.level_y[1]))
2016
50.3k
    {
2017
50.3k
        bytefn(dav1d_loopfilter_sbrow_rows)(f, p, mask, sby);
2018
50.3k
    }
2019
61.0k
    if (f->seq_hdr->cdef || f->lf.restore_planes) {
2020
        // Store loop filtered pixels required by CDEF / LR
2021
51.7k
        bytefn(dav1d_copy_lpf)(f, p, sby);
2022
51.7k
    }
2023
61.0k
}
dav1d_filter_sbrow_deblock_rows_16bpc
Line
Count
Source
2005
34.0k
void bytefn(dav1d_filter_sbrow_deblock_rows)(Dav1dFrameContext *const f, const int sby) {
2006
34.0k
    const int y = sby * f->sb_step * 4;
2007
34.0k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2008
34.0k
    pixel *const p[3] = {
2009
34.0k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2010
34.0k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2011
34.0k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2012
34.0k
    };
2013
34.0k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2014
34.0k
    if (f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK &&
2015
34.0k
        (f->frame_hdr->loopfilter.level_y[0] || f->frame_hdr->loopfilter.level_y[1]))
2016
27.5k
    {
2017
27.5k
        bytefn(dav1d_loopfilter_sbrow_rows)(f, p, mask, sby);
2018
27.5k
    }
2019
34.0k
    if (f->seq_hdr->cdef || f->lf.restore_planes) {
2020
        // Store loop filtered pixels required by CDEF / LR
2021
30.5k
        bytefn(dav1d_copy_lpf)(f, p, sby);
2022
30.5k
    }
2023
34.0k
}
2024
2025
63.6k
void bytefn(dav1d_filter_sbrow_cdef)(Dav1dTaskContext *const tc, const int sby) {
2026
63.6k
    const Dav1dFrameContext *const f = tc->f;
2027
63.6k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_CDEF)) return;
2028
63.6k
    const int sbsz = f->sb_step;
2029
63.6k
    const int y = sby * sbsz * 4;
2030
63.6k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2031
63.6k
    pixel *const p[3] = {
2032
63.6k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2033
63.6k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2034
63.6k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2035
63.6k
    };
2036
63.6k
    Av1Filter *prev_mask = f->lf.mask + ((sby - 1) >> !f->seq_hdr->sb128) * f->sb128w;
2037
63.6k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2038
63.6k
    const int start = sby * sbsz;
2039
63.6k
    if (sby) {
2040
55.7k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2041
55.7k
        pixel *p_up[3] = {
2042
55.7k
            p[0] - 8 * PXSTRIDE(f->cur.stride[0]),
2043
55.7k
            p[1] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2044
55.7k
            p[2] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2045
55.7k
        };
2046
55.7k
        bytefn(dav1d_cdef_brow)(tc, p_up, prev_mask, start - 2, start, 1, sby);
2047
55.7k
    }
2048
63.6k
    const int n_blks = sbsz - 2 * (sby + 1 < f->sbh);
2049
63.6k
    const int end = imin(start + n_blks, f->bh);
2050
63.6k
    bytefn(dav1d_cdef_brow)(tc, p, mask, start, end, 0, sby);
2051
63.6k
}
dav1d_filter_sbrow_cdef_8bpc
Line
Count
Source
2025
42.8k
void bytefn(dav1d_filter_sbrow_cdef)(Dav1dTaskContext *const tc, const int sby) {
2026
42.8k
    const Dav1dFrameContext *const f = tc->f;
2027
42.8k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_CDEF)) return;
2028
42.8k
    const int sbsz = f->sb_step;
2029
42.8k
    const int y = sby * sbsz * 4;
2030
42.8k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2031
42.8k
    pixel *const p[3] = {
2032
42.8k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2033
42.8k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2034
42.8k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2035
42.8k
    };
2036
42.8k
    Av1Filter *prev_mask = f->lf.mask + ((sby - 1) >> !f->seq_hdr->sb128) * f->sb128w;
2037
42.8k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2038
42.8k
    const int start = sby * sbsz;
2039
42.8k
    if (sby) {
2040
39.6k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2041
39.6k
        pixel *p_up[3] = {
2042
39.6k
            p[0] - 8 * PXSTRIDE(f->cur.stride[0]),
2043
39.6k
            p[1] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2044
39.6k
            p[2] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2045
39.6k
        };
2046
39.6k
        bytefn(dav1d_cdef_brow)(tc, p_up, prev_mask, start - 2, start, 1, sby);
2047
39.6k
    }
2048
42.8k
    const int n_blks = sbsz - 2 * (sby + 1 < f->sbh);
2049
42.8k
    const int end = imin(start + n_blks, f->bh);
2050
42.8k
    bytefn(dav1d_cdef_brow)(tc, p, mask, start, end, 0, sby);
2051
42.8k
}
dav1d_filter_sbrow_cdef_16bpc
Line
Count
Source
2025
20.7k
void bytefn(dav1d_filter_sbrow_cdef)(Dav1dTaskContext *const tc, const int sby) {
2026
20.7k
    const Dav1dFrameContext *const f = tc->f;
2027
20.7k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_CDEF)) return;
2028
20.7k
    const int sbsz = f->sb_step;
2029
20.7k
    const int y = sby * sbsz * 4;
2030
20.7k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2031
20.7k
    pixel *const p[3] = {
2032
20.7k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2033
20.7k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2034
20.7k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2035
20.7k
    };
2036
20.7k
    Av1Filter *prev_mask = f->lf.mask + ((sby - 1) >> !f->seq_hdr->sb128) * f->sb128w;
2037
20.7k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2038
20.7k
    const int start = sby * sbsz;
2039
20.7k
    if (sby) {
2040
16.0k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2041
16.0k
        pixel *p_up[3] = {
2042
16.0k
            p[0] - 8 * PXSTRIDE(f->cur.stride[0]),
2043
16.0k
            p[1] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2044
16.0k
            p[2] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2045
16.0k
        };
2046
16.0k
        bytefn(dav1d_cdef_brow)(tc, p_up, prev_mask, start - 2, start, 1, sby);
2047
16.0k
    }
2048
20.7k
    const int n_blks = sbsz - 2 * (sby + 1 < f->sbh);
2049
20.7k
    const int end = imin(start + n_blks, f->bh);
2050
20.7k
    bytefn(dav1d_cdef_brow)(tc, p, mask, start, end, 0, sby);
2051
20.7k
}
2052
2053
19.8k
void bytefn(dav1d_filter_sbrow_resize)(Dav1dFrameContext *const f, const int sby) {
2054
19.8k
    const int sbsz = f->sb_step;
2055
19.8k
    const int y = sby * sbsz * 4;
2056
19.8k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2057
19.8k
    const pixel *const p[3] = {
2058
19.8k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2059
19.8k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2060
19.8k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2061
19.8k
    };
2062
19.8k
    pixel *const sr_p[3] = {
2063
19.8k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2064
19.8k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2065
19.8k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2066
19.8k
    };
2067
19.8k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400;
2068
74.0k
    for (int pl = 0; pl < 1 + 2 * has_chroma; pl++) {
2069
54.2k
        const int ss_ver = pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2070
54.2k
        const int h_start = 8 * !!sby >> ss_ver;
2071
54.2k
        const ptrdiff_t dst_stride = f->sr_cur.p.stride[!!pl];
2072
54.2k
        pixel *dst = sr_p[pl] - h_start * PXSTRIDE(dst_stride);
2073
54.2k
        const ptrdiff_t src_stride = f->cur.stride[!!pl];
2074
54.2k
        const pixel *src = p[pl] - h_start * PXSTRIDE(src_stride);
2075
54.2k
        const int h_end = 4 * (sbsz - 2 * (sby + 1 < f->sbh)) >> ss_ver;
2076
54.2k
        const int ss_hor = pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2077
54.2k
        const int dst_w = (f->sr_cur.p.p.w + ss_hor) >> ss_hor;
2078
54.2k
        const int src_w = (4 * f->bw + ss_hor) >> ss_hor;
2079
54.2k
        const int img_h = (f->cur.p.h - sbsz * 4 * sby + ss_ver) >> ss_ver;
2080
2081
54.2k
        f->dsp->mc.resize(dst, dst_stride, src, src_stride, dst_w,
2082
54.2k
                          imin(img_h, h_end) + h_start, src_w,
2083
54.2k
                          f->resize_step[!!pl], f->resize_start[!!pl]
2084
54.2k
                          HIGHBD_CALL_SUFFIX);
2085
54.2k
    }
2086
19.8k
}
dav1d_filter_sbrow_resize_8bpc
Line
Count
Source
2053
10.4k
void bytefn(dav1d_filter_sbrow_resize)(Dav1dFrameContext *const f, const int sby) {
2054
10.4k
    const int sbsz = f->sb_step;
2055
10.4k
    const int y = sby * sbsz * 4;
2056
10.4k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2057
10.4k
    const pixel *const p[3] = {
2058
10.4k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2059
10.4k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2060
10.4k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2061
10.4k
    };
2062
10.4k
    pixel *const sr_p[3] = {
2063
10.4k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2064
10.4k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2065
10.4k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2066
10.4k
    };
2067
10.4k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400;
2068
39.6k
    for (int pl = 0; pl < 1 + 2 * has_chroma; pl++) {
2069
29.1k
        const int ss_ver = pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2070
29.1k
        const int h_start = 8 * !!sby >> ss_ver;
2071
29.1k
        const ptrdiff_t dst_stride = f->sr_cur.p.stride[!!pl];
2072
29.1k
        pixel *dst = sr_p[pl] - h_start * PXSTRIDE(dst_stride);
2073
29.1k
        const ptrdiff_t src_stride = f->cur.stride[!!pl];
2074
29.1k
        const pixel *src = p[pl] - h_start * PXSTRIDE(src_stride);
2075
29.1k
        const int h_end = 4 * (sbsz - 2 * (sby + 1 < f->sbh)) >> ss_ver;
2076
29.1k
        const int ss_hor = pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2077
29.1k
        const int dst_w = (f->sr_cur.p.p.w + ss_hor) >> ss_hor;
2078
29.1k
        const int src_w = (4 * f->bw + ss_hor) >> ss_hor;
2079
29.1k
        const int img_h = (f->cur.p.h - sbsz * 4 * sby + ss_ver) >> ss_ver;
2080
2081
29.1k
        f->dsp->mc.resize(dst, dst_stride, src, src_stride, dst_w,
2082
29.1k
                          imin(img_h, h_end) + h_start, src_w,
2083
29.1k
                          f->resize_step[!!pl], f->resize_start[!!pl]
2084
29.1k
                          HIGHBD_CALL_SUFFIX);
2085
29.1k
    }
2086
10.4k
}
dav1d_filter_sbrow_resize_16bpc
Line
Count
Source
2053
9.31k
void bytefn(dav1d_filter_sbrow_resize)(Dav1dFrameContext *const f, const int sby) {
2054
9.31k
    const int sbsz = f->sb_step;
2055
9.31k
    const int y = sby * sbsz * 4;
2056
9.31k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2057
9.31k
    const pixel *const p[3] = {
2058
9.31k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2059
9.31k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2060
9.31k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2061
9.31k
    };
2062
9.31k
    pixel *const sr_p[3] = {
2063
9.31k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2064
9.31k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2065
9.31k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2066
9.31k
    };
2067
9.31k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400;
2068
34.4k
    for (int pl = 0; pl < 1 + 2 * has_chroma; pl++) {
2069
25.1k
        const int ss_ver = pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2070
25.1k
        const int h_start = 8 * !!sby >> ss_ver;
2071
25.1k
        const ptrdiff_t dst_stride = f->sr_cur.p.stride[!!pl];
2072
25.1k
        pixel *dst = sr_p[pl] - h_start * PXSTRIDE(dst_stride);
2073
25.1k
        const ptrdiff_t src_stride = f->cur.stride[!!pl];
2074
25.1k
        const pixel *src = p[pl] - h_start * PXSTRIDE(src_stride);
2075
25.1k
        const int h_end = 4 * (sbsz - 2 * (sby + 1 < f->sbh)) >> ss_ver;
2076
25.1k
        const int ss_hor = pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2077
25.1k
        const int dst_w = (f->sr_cur.p.p.w + ss_hor) >> ss_hor;
2078
25.1k
        const int src_w = (4 * f->bw + ss_hor) >> ss_hor;
2079
25.1k
        const int img_h = (f->cur.p.h - sbsz * 4 * sby + ss_ver) >> ss_ver;
2080
2081
25.1k
        f->dsp->mc.resize(dst, dst_stride, src, src_stride, dst_w,
2082
25.1k
                          imin(img_h, h_end) + h_start, src_w,
2083
25.1k
                          f->resize_step[!!pl], f->resize_start[!!pl]
2084
25.1k
                          HIGHBD_CALL_SUFFIX);
2085
25.1k
    }
2086
9.31k
}
2087
2088
58.8k
void bytefn(dav1d_filter_sbrow_lr)(Dav1dFrameContext *const f, const int sby) {
2089
58.8k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_RESTORATION)) return;
2090
58.8k
    const int y = sby * f->sb_step * 4;
2091
58.8k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2092
58.8k
    pixel *const sr_p[3] = {
2093
58.8k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2094
58.8k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2095
58.8k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2096
58.8k
    };
2097
58.8k
    bytefn(dav1d_lr_sbrow)(f, sr_p, sby);
2098
58.8k
}
dav1d_filter_sbrow_lr_8bpc
Line
Count
Source
2088
39.3k
void bytefn(dav1d_filter_sbrow_lr)(Dav1dFrameContext *const f, const int sby) {
2089
39.3k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_RESTORATION)) return;
2090
39.3k
    const int y = sby * f->sb_step * 4;
2091
39.3k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2092
39.3k
    pixel *const sr_p[3] = {
2093
39.3k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2094
39.3k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2095
39.3k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2096
39.3k
    };
2097
39.3k
    bytefn(dav1d_lr_sbrow)(f, sr_p, sby);
2098
39.3k
}
dav1d_filter_sbrow_lr_16bpc
Line
Count
Source
2088
19.5k
void bytefn(dav1d_filter_sbrow_lr)(Dav1dFrameContext *const f, const int sby) {
2089
19.5k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_RESTORATION)) return;
2090
19.5k
    const int y = sby * f->sb_step * 4;
2091
19.5k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2092
19.5k
    pixel *const sr_p[3] = {
2093
19.5k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2094
19.5k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2095
19.5k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2096
19.5k
    };
2097
19.5k
    bytefn(dav1d_lr_sbrow)(f, sr_p, sby);
2098
19.5k
}
2099
2100
0
void bytefn(dav1d_filter_sbrow)(Dav1dFrameContext *const f, const int sby) {
2101
0
    bytefn(dav1d_filter_sbrow_deblock_cols)(f, sby);
2102
0
    bytefn(dav1d_filter_sbrow_deblock_rows)(f, sby);
2103
0
    if (f->seq_hdr->cdef)
2104
0
        bytefn(dav1d_filter_sbrow_cdef)(f->c->tc, sby);
2105
0
    if (f->frame_hdr->width[0] != f->frame_hdr->width[1])
2106
0
        bytefn(dav1d_filter_sbrow_resize)(f, sby);
2107
0
    if (f->lf.restore_planes)
2108
0
        bytefn(dav1d_filter_sbrow_lr)(f, sby);
2109
0
}
Unexecuted instantiation: dav1d_filter_sbrow_8bpc
Unexecuted instantiation: dav1d_filter_sbrow_16bpc
2110
2111
137k
void bytefn(dav1d_backup_ipred_edge)(Dav1dTaskContext *const t) {
2112
137k
    const Dav1dFrameContext *const f = t->f;
2113
137k
    Dav1dTileState *const ts = t->ts;
2114
137k
    const int sby = t->by >> f->sb_shift;
2115
137k
    const int sby_off = f->sb128w * 128 * sby;
2116
137k
    const int x_off = ts->tiling.col_start;
2117
2118
137k
    const pixel *const y =
2119
137k
        ((const pixel *) f->cur.data[0]) + x_off * 4 +
2120
137k
                    ((t->by + f->sb_step) * 4 - 1) * PXSTRIDE(f->cur.stride[0]);
2121
137k
    pixel_copy(&f->ipred_edge[0][sby_off + x_off * 4], y,
2122
137k
               4 * (ts->tiling.col_end - x_off));
2123
2124
137k
    if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
2125
105k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2126
105k
        const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2127
2128
105k
        const ptrdiff_t uv_off = (x_off * 4 >> ss_hor) +
2129
105k
            (((t->by + f->sb_step) * 4 >> ss_ver) - 1) * PXSTRIDE(f->cur.stride[1]);
2130
315k
        for (int pl = 1; pl <= 2; pl++)
2131
210k
            pixel_copy(&f->ipred_edge[pl][sby_off + (x_off * 4 >> ss_hor)],
2132
138k
                       &((const pixel *) f->cur.data[pl])[uv_off],
2133
138k
                       4 * (ts->tiling.col_end - x_off) >> ss_hor);
2134
105k
    }
2135
137k
}
dav1d_backup_ipred_edge_8bpc
Line
Count
Source
2111
90.8k
void bytefn(dav1d_backup_ipred_edge)(Dav1dTaskContext *const t) {
2112
90.8k
    const Dav1dFrameContext *const f = t->f;
2113
90.8k
    Dav1dTileState *const ts = t->ts;
2114
90.8k
    const int sby = t->by >> f->sb_shift;
2115
90.8k
    const int sby_off = f->sb128w * 128 * sby;
2116
90.8k
    const int x_off = ts->tiling.col_start;
2117
2118
90.8k
    const pixel *const y =
2119
90.8k
        ((const pixel *) f->cur.data[0]) + x_off * 4 +
2120
90.8k
                    ((t->by + f->sb_step) * 4 - 1) * PXSTRIDE(f->cur.stride[0]);
2121
90.8k
    pixel_copy(&f->ipred_edge[0][sby_off + x_off * 4], y,
2122
90.8k
               4 * (ts->tiling.col_end - x_off));
2123
2124
90.8k
    if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
2125
69.1k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2126
69.1k
        const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2127
2128
69.1k
        const ptrdiff_t uv_off = (x_off * 4 >> ss_hor) +
2129
69.1k
            (((t->by + f->sb_step) * 4 >> ss_ver) - 1) * PXSTRIDE(f->cur.stride[1]);
2130
207k
        for (int pl = 1; pl <= 2; pl++)
2131
138k
            pixel_copy(&f->ipred_edge[pl][sby_off + (x_off * 4 >> ss_hor)],
2132
138k
                       &((const pixel *) f->cur.data[pl])[uv_off],
2133
138k
                       4 * (ts->tiling.col_end - x_off) >> ss_hor);
2134
69.1k
    }
2135
90.8k
}
dav1d_backup_ipred_edge_16bpc
Line
Count
Source
2111
46.3k
void bytefn(dav1d_backup_ipred_edge)(Dav1dTaskContext *const t) {
2112
46.3k
    const Dav1dFrameContext *const f = t->f;
2113
46.3k
    Dav1dTileState *const ts = t->ts;
2114
46.3k
    const int sby = t->by >> f->sb_shift;
2115
46.3k
    const int sby_off = f->sb128w * 128 * sby;
2116
46.3k
    const int x_off = ts->tiling.col_start;
2117
2118
46.3k
    const pixel *const y =
2119
46.3k
        ((const pixel *) f->cur.data[0]) + x_off * 4 +
2120
46.3k
                    ((t->by + f->sb_step) * 4 - 1) * PXSTRIDE(f->cur.stride[0]);
2121
46.3k
    pixel_copy(&f->ipred_edge[0][sby_off + x_off * 4], y,
2122
46.3k
               4 * (ts->tiling.col_end - x_off));
2123
2124
46.3k
    if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
2125
36.1k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2126
36.1k
        const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2127
2128
36.1k
        const ptrdiff_t uv_off = (x_off * 4 >> ss_hor) +
2129
36.1k
            (((t->by + f->sb_step) * 4 >> ss_ver) - 1) * PXSTRIDE(f->cur.stride[1]);
2130
108k
        for (int pl = 1; pl <= 2; pl++)
2131
72.2k
            pixel_copy(&f->ipred_edge[pl][sby_off + (x_off * 4 >> ss_hor)],
2132
36.1k
                       &((const pixel *) f->cur.data[pl])[uv_off],
2133
36.1k
                       4 * (ts->tiling.col_end - x_off) >> ss_hor);
2134
36.1k
    }
2135
46.3k
}
2136
2137
void bytefn(dav1d_copy_pal_block_y)(Dav1dTaskContext *const t,
2138
                                    const int bx4, const int by4,
2139
                                    const int bw4, const int bh4)
2140
2141
28.9k
{
2142
28.9k
    const Dav1dFrameContext *const f = t->f;
2143
28.9k
    pixel *const pal = t->frame_thread.pass ?
2144
28.9k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2145
28.9k
                            ((t->bx >> 1) + (t->by & 1))][0] :
2146
28.9k
        bytefn(t->scratch.pal)[0];
2147
135k
    for (int x = 0; x < bw4; x++)
2148
106k
        memcpy(bytefn(t->al_pal)[0][bx4 + x][0], pal, 8 * sizeof(pixel));
2149
117k
    for (int y = 0; y < bh4; y++)
2150
88.9k
        memcpy(bytefn(t->al_pal)[1][by4 + y][0], pal, 8 * sizeof(pixel));
2151
28.9k
}
dav1d_copy_pal_block_y_8bpc
Line
Count
Source
2141
12.5k
{
2142
12.5k
    const Dav1dFrameContext *const f = t->f;
2143
12.5k
    pixel *const pal = t->frame_thread.pass ?
2144
12.5k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2145
12.5k
                            ((t->bx >> 1) + (t->by & 1))][0] :
2146
12.5k
        bytefn(t->scratch.pal)[0];
2147
55.9k
    for (int x = 0; x < bw4; x++)
2148
43.3k
        memcpy(bytefn(t->al_pal)[0][bx4 + x][0], pal, 8 * sizeof(pixel));
2149
48.6k
    for (int y = 0; y < bh4; y++)
2150
36.0k
        memcpy(bytefn(t->al_pal)[1][by4 + y][0], pal, 8 * sizeof(pixel));
2151
12.5k
}
dav1d_copy_pal_block_y_16bpc
Line
Count
Source
2141
16.4k
{
2142
16.4k
    const Dav1dFrameContext *const f = t->f;
2143
16.4k
    pixel *const pal = t->frame_thread.pass ?
2144
16.4k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2145
16.4k
                            ((t->bx >> 1) + (t->by & 1))][0] :
2146
16.4k
        bytefn(t->scratch.pal)[0];
2147
79.5k
    for (int x = 0; x < bw4; x++)
2148
63.1k
        memcpy(bytefn(t->al_pal)[0][bx4 + x][0], pal, 8 * sizeof(pixel));
2149
69.2k
    for (int y = 0; y < bh4; y++)
2150
52.8k
        memcpy(bytefn(t->al_pal)[1][by4 + y][0], pal, 8 * sizeof(pixel));
2151
16.4k
}
2152
2153
void bytefn(dav1d_copy_pal_block_uv)(Dav1dTaskContext *const t,
2154
                                     const int bx4, const int by4,
2155
                                     const int bw4, const int bh4)
2156
2157
8.92k
{
2158
8.92k
    const Dav1dFrameContext *const f = t->f;
2159
8.92k
    const pixel (*const pal)[8] = t->frame_thread.pass ?
2160
8.92k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2161
8.92k
                            ((t->bx >> 1) + (t->by & 1))] :
2162
8.92k
        bytefn(t->scratch.pal);
2163
    // see aomedia bug 2183 for why we use luma coordinates here
2164
26.7k
    for (int pl = 1; pl <= 2; pl++) {
2165
99.5k
        for (int x = 0; x < bw4; x++)
2166
81.7k
            memcpy(bytefn(t->al_pal)[0][bx4 + x][pl], pal[pl], 8 * sizeof(pixel));
2167
94.7k
        for (int y = 0; y < bh4; y++)
2168
76.9k
            memcpy(bytefn(t->al_pal)[1][by4 + y][pl], pal[pl], 8 * sizeof(pixel));
2169
17.8k
    }
2170
8.92k
}
dav1d_copy_pal_block_uv_8bpc
Line
Count
Source
2157
4.15k
{
2158
4.15k
    const Dav1dFrameContext *const f = t->f;
2159
4.15k
    const pixel (*const pal)[8] = t->frame_thread.pass ?
2160
4.15k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2161
4.15k
                            ((t->bx >> 1) + (t->by & 1))] :
2162
4.15k
        bytefn(t->scratch.pal);
2163
    // see aomedia bug 2183 for why we use luma coordinates here
2164
12.4k
    for (int pl = 1; pl <= 2; pl++) {
2165
47.5k
        for (int x = 0; x < bw4; x++)
2166
39.2k
            memcpy(bytefn(t->al_pal)[0][bx4 + x][pl], pal[pl], 8 * sizeof(pixel));
2167
45.5k
        for (int y = 0; y < bh4; y++)
2168
37.2k
            memcpy(bytefn(t->al_pal)[1][by4 + y][pl], pal[pl], 8 * sizeof(pixel));
2169
8.30k
    }
2170
4.15k
}
dav1d_copy_pal_block_uv_16bpc
Line
Count
Source
2157
4.77k
{
2158
4.77k
    const Dav1dFrameContext *const f = t->f;
2159
4.77k
    const pixel (*const pal)[8] = t->frame_thread.pass ?
2160
4.77k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2161
4.77k
                            ((t->bx >> 1) + (t->by & 1))] :
2162
4.77k
        bytefn(t->scratch.pal);
2163
    // see aomedia bug 2183 for why we use luma coordinates here
2164
14.3k
    for (int pl = 1; pl <= 2; pl++) {
2165
51.9k
        for (int x = 0; x < bw4; x++)
2166
42.4k
            memcpy(bytefn(t->al_pal)[0][bx4 + x][pl], pal[pl], 8 * sizeof(pixel));
2167
49.2k
        for (int y = 0; y < bh4; y++)
2168
39.6k
            memcpy(bytefn(t->al_pal)[1][by4 + y][pl], pal[pl], 8 * sizeof(pixel));
2169
9.55k
    }
2170
4.77k
}
2171
2172
void bytefn(dav1d_read_pal_plane)(Dav1dTaskContext *const t, Av1Block *const b,
2173
                                  const int pl, const int sz_ctx,
2174
                                  const int bx4, const int by4)
2175
37.9k
{
2176
37.9k
    Dav1dTileState *const ts = t->ts;
2177
37.9k
    const Dav1dFrameContext *const f = t->f;
2178
37.9k
    const int pal_sz = b->pal_sz[pl] = dav1d_msac_decode_symbol_adapt8(&ts->msac,
2179
37.9k
                                           ts->cdf.m.pal_sz[pl][sz_ctx], 6) + 2;
2180
37.9k
    pixel cache[16], used_cache[8];
2181
37.9k
    int l_cache = pl ? t->pal_sz_uv[1][by4] : t->l.pal_sz[by4];
2182
37.9k
    int n_cache = 0;
2183
    // don't reuse above palette outside SB64 boundaries
2184
37.9k
    int a_cache = by4 & 15 ? pl ? t->pal_sz_uv[0][bx4] : t->a->pal_sz[bx4] : 0;
2185
37.9k
    const pixel *l = bytefn(t->al_pal)[1][by4][pl];
2186
37.9k
    const pixel *a = bytefn(t->al_pal)[0][bx4][pl];
2187
2188
    // fill/sort cache
2189
67.8k
    while (l_cache && a_cache) {
2190
29.8k
        if (*l < *a) {
2191
11.9k
            if (!n_cache || cache[n_cache - 1] != *l)
2192
11.8k
                cache[n_cache++] = *l;
2193
11.9k
            l++;
2194
11.9k
            l_cache--;
2195
17.9k
        } else {
2196
17.9k
            if (*a == *l) {
2197
6.92k
                l++;
2198
6.92k
                l_cache--;
2199
6.92k
            }
2200
17.9k
            if (!n_cache || cache[n_cache - 1] != *a)
2201
17.4k
                cache[n_cache++] = *a;
2202
17.9k
            a++;
2203
17.9k
            a_cache--;
2204
17.9k
        }
2205
29.8k
    }
2206
37.9k
    if (l_cache) {
2207
44.6k
        do {
2208
44.6k
            if (!n_cache || cache[n_cache - 1] != *l)
2209
36.7k
                cache[n_cache++] = *l;
2210
44.6k
            l++;
2211
44.6k
        } while (--l_cache > 0);
2212
26.9k
    } else if (a_cache) {
2213
37.1k
        do {
2214
37.1k
            if (!n_cache || cache[n_cache - 1] != *a)
2215
29.7k
                cache[n_cache++] = *a;
2216
37.1k
            a++;
2217
37.1k
        } while (--a_cache > 0);
2218
8.96k
    }
2219
2220
    // find reused cache entries
2221
37.9k
    int i = 0;
2222
122k
    for (int n = 0; n < n_cache && i < pal_sz; n++)
2223
84.3k
        if (dav1d_msac_decode_bool_equi(&ts->msac))
2224
41.3k
            used_cache[i++] = cache[n];
2225
37.9k
    const int n_used_cache = i;
2226
2227
    // parse new entries
2228
37.9k
    pixel *const pal = t->frame_thread.pass ?
2229
37.9k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2230
37.9k
                            ((t->bx >> 1) + (t->by & 1))][pl] :
2231
37.9k
        bytefn(t->scratch.pal)[pl];
2232
37.9k
    if (i < pal_sz) {
2233
32.6k
        const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2234
32.6k
        int prev = pal[i++] = dav1d_msac_decode_bools(&ts->msac, bpc);
2235
2236
32.6k
        if (i < pal_sz) {
2237
29.4k
            int bits = bpc - 3 + dav1d_msac_decode_bools(&ts->msac, 2);
2238
29.4k
            const int max = (1 << bpc) - 1;
2239
2240
69.4k
            do {
2241
69.4k
                const int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2242
69.4k
                prev = pal[i++] = imin(prev + delta + !pl, max);
2243
69.4k
                if (prev + !pl >= max) {
2244
38.0k
                    for (; i < pal_sz; i++)
2245
24.8k
                        pal[i] = max;
2246
13.1k
                    break;
2247
13.1k
                }
2248
56.3k
                bits = imin(bits, 1 + ulog2(max - prev - !pl));
2249
56.3k
            } while (i < pal_sz);
2250
29.4k
        }
2251
2252
        // merge cache+new entries
2253
32.6k
        int n = 0, m = n_used_cache;
2254
186k
        for (i = 0; i < pal_sz; i++) {
2255
154k
            if (n < n_used_cache && (m >= pal_sz || used_cache[n] <= pal[m])) {
2256
27.1k
                pal[i] = used_cache[n++];
2257
127k
            } else {
2258
127k
                assert(m < pal_sz);
2259
127k
                pal[i] = pal[m++];
2260
127k
            }
2261
154k
        }
2262
32.6k
    } else {
2263
5.25k
        memcpy(pal, used_cache, n_used_cache * sizeof(*used_cache));
2264
5.25k
    }
2265
2266
37.9k
    if (DEBUG_BLOCK_INFO) {
2267
0
        printf("Post-pal[pl=%d,sz=%d,cache_size=%d,used_cache=%d]: r=%d, cache=",
2268
0
               pl, pal_sz, n_cache, n_used_cache, ts->msac.rng);
2269
0
        for (int n = 0; n < n_cache; n++)
2270
0
            printf("%c%02x", n ? ' ' : '[', cache[n]);
2271
0
        printf("%s, pal=", n_cache ? "]" : "[]");
2272
0
        for (int n = 0; n < pal_sz; n++)
2273
0
            printf("%c%02x", n ? ' ' : '[', pal[n]);
2274
0
        printf("]\n");
2275
0
    }
2276
37.9k
}
dav1d_read_pal_plane_8bpc
Line
Count
Source
2175
16.7k
{
2176
16.7k
    Dav1dTileState *const ts = t->ts;
2177
16.7k
    const Dav1dFrameContext *const f = t->f;
2178
16.7k
    const int pal_sz = b->pal_sz[pl] = dav1d_msac_decode_symbol_adapt8(&ts->msac,
2179
16.7k
                                           ts->cdf.m.pal_sz[pl][sz_ctx], 6) + 2;
2180
16.7k
    pixel cache[16], used_cache[8];
2181
16.7k
    int l_cache = pl ? t->pal_sz_uv[1][by4] : t->l.pal_sz[by4];
2182
16.7k
    int n_cache = 0;
2183
    // don't reuse above palette outside SB64 boundaries
2184
16.7k
    int a_cache = by4 & 15 ? pl ? t->pal_sz_uv[0][bx4] : t->a->pal_sz[bx4] : 0;
2185
16.7k
    const pixel *l = bytefn(t->al_pal)[1][by4][pl];
2186
16.7k
    const pixel *a = bytefn(t->al_pal)[0][bx4][pl];
2187
2188
    // fill/sort cache
2189
27.8k
    while (l_cache && a_cache) {
2190
11.1k
        if (*l < *a) {
2191
4.40k
            if (!n_cache || cache[n_cache - 1] != *l)
2192
4.35k
                cache[n_cache++] = *l;
2193
4.40k
            l++;
2194
4.40k
            l_cache--;
2195
6.73k
        } else {
2196
6.73k
            if (*a == *l) {
2197
2.65k
                l++;
2198
2.65k
                l_cache--;
2199
2.65k
            }
2200
6.73k
            if (!n_cache || cache[n_cache - 1] != *a)
2201
6.45k
                cache[n_cache++] = *a;
2202
6.73k
            a++;
2203
6.73k
            a_cache--;
2204
6.73k
        }
2205
11.1k
    }
2206
16.7k
    if (l_cache) {
2207
18.0k
        do {
2208
18.0k
            if (!n_cache || cache[n_cache - 1] != *l)
2209
14.4k
                cache[n_cache++] = *l;
2210
18.0k
            l++;
2211
18.0k
        } while (--l_cache > 0);
2212
12.4k
    } else if (a_cache) {
2213
16.0k
        do {
2214
16.0k
            if (!n_cache || cache[n_cache - 1] != *a)
2215
12.5k
                cache[n_cache++] = *a;
2216
16.0k
            a++;
2217
16.0k
        } while (--a_cache > 0);
2218
3.78k
    }
2219
2220
    // find reused cache entries
2221
16.7k
    int i = 0;
2222
50.1k
    for (int n = 0; n < n_cache && i < pal_sz; n++)
2223
33.4k
        if (dav1d_msac_decode_bool_equi(&ts->msac))
2224
16.3k
            used_cache[i++] = cache[n];
2225
16.7k
    const int n_used_cache = i;
2226
2227
    // parse new entries
2228
16.7k
    pixel *const pal = t->frame_thread.pass ?
2229
16.7k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2230
16.7k
                            ((t->bx >> 1) + (t->by & 1))][pl] :
2231
16.7k
        bytefn(t->scratch.pal)[pl];
2232
16.7k
    if (i < pal_sz) {
2233
14.7k
        const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2234
14.7k
        int prev = pal[i++] = dav1d_msac_decode_bools(&ts->msac, bpc);
2235
2236
14.7k
        if (i < pal_sz) {
2237
13.4k
            int bits = bpc - 3 + dav1d_msac_decode_bools(&ts->msac, 2);
2238
13.4k
            const int max = (1 << bpc) - 1;
2239
2240
31.6k
            do {
2241
31.6k
                const int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2242
31.6k
                prev = pal[i++] = imin(prev + delta + !pl, max);
2243
31.6k
                if (prev + !pl >= max) {
2244
18.6k
                    for (; i < pal_sz; i++)
2245
12.3k
                        pal[i] = max;
2246
6.27k
                    break;
2247
6.27k
                }
2248
25.3k
                bits = imin(bits, 1 + ulog2(max - prev - !pl));
2249
25.3k
            } while (i < pal_sz);
2250
13.4k
        }
2251
2252
        // merge cache+new entries
2253
14.7k
        int n = 0, m = n_used_cache;
2254
84.3k
        for (i = 0; i < pal_sz; i++) {
2255
69.6k
            if (n < n_used_cache && (m >= pal_sz || used_cache[n] <= pal[m])) {
2256
10.9k
                pal[i] = used_cache[n++];
2257
58.6k
            } else {
2258
58.6k
                assert(m < pal_sz);
2259
58.6k
                pal[i] = pal[m++];
2260
58.6k
            }
2261
69.6k
        }
2262
14.7k
    } else {
2263
2.01k
        memcpy(pal, used_cache, n_used_cache * sizeof(*used_cache));
2264
2.01k
    }
2265
2266
16.7k
    if (DEBUG_BLOCK_INFO) {
2267
0
        printf("Post-pal[pl=%d,sz=%d,cache_size=%d,used_cache=%d]: r=%d, cache=",
2268
0
               pl, pal_sz, n_cache, n_used_cache, ts->msac.rng);
2269
0
        for (int n = 0; n < n_cache; n++)
2270
0
            printf("%c%02x", n ? ' ' : '[', cache[n]);
2271
0
        printf("%s, pal=", n_cache ? "]" : "[]");
2272
0
        for (int n = 0; n < pal_sz; n++)
2273
0
            printf("%c%02x", n ? ' ' : '[', pal[n]);
2274
0
        printf("]\n");
2275
0
    }
2276
16.7k
}
dav1d_read_pal_plane_16bpc
Line
Count
Source
2175
21.1k
{
2176
21.1k
    Dav1dTileState *const ts = t->ts;
2177
21.1k
    const Dav1dFrameContext *const f = t->f;
2178
21.1k
    const int pal_sz = b->pal_sz[pl] = dav1d_msac_decode_symbol_adapt8(&ts->msac,
2179
21.1k
                                           ts->cdf.m.pal_sz[pl][sz_ctx], 6) + 2;
2180
21.1k
    pixel cache[16], used_cache[8];
2181
21.1k
    int l_cache = pl ? t->pal_sz_uv[1][by4] : t->l.pal_sz[by4];
2182
21.1k
    int n_cache = 0;
2183
    // don't reuse above palette outside SB64 boundaries
2184
21.1k
    int a_cache = by4 & 15 ? pl ? t->pal_sz_uv[0][bx4] : t->a->pal_sz[bx4] : 0;
2185
21.1k
    const pixel *l = bytefn(t->al_pal)[1][by4][pl];
2186
21.1k
    const pixel *a = bytefn(t->al_pal)[0][bx4][pl];
2187
2188
    // fill/sort cache
2189
39.9k
    while (l_cache && a_cache) {
2190
18.7k
        if (*l < *a) {
2191
7.53k
            if (!n_cache || cache[n_cache - 1] != *l)
2192
7.51k
                cache[n_cache++] = *l;
2193
7.53k
            l++;
2194
7.53k
            l_cache--;
2195
11.2k
        } else {
2196
11.2k
            if (*a == *l) {
2197
4.27k
                l++;
2198
4.27k
                l_cache--;
2199
4.27k
            }
2200
11.2k
            if (!n_cache || cache[n_cache - 1] != *a)
2201
10.9k
                cache[n_cache++] = *a;
2202
11.2k
            a++;
2203
11.2k
            a_cache--;
2204
11.2k
        }
2205
18.7k
    }
2206
21.1k
    if (l_cache) {
2207
26.6k
        do {
2208
26.6k
            if (!n_cache || cache[n_cache - 1] != *l)
2209
22.2k
                cache[n_cache++] = *l;
2210
26.6k
            l++;
2211
26.6k
        } while (--l_cache > 0);
2212
14.5k
    } else if (a_cache) {
2213
21.1k
        do {
2214
21.1k
            if (!n_cache || cache[n_cache - 1] != *a)
2215
17.2k
                cache[n_cache++] = *a;
2216
21.1k
            a++;
2217
21.1k
        } while (--a_cache > 0);
2218
5.17k
    }
2219
2220
    // find reused cache entries
2221
21.1k
    int i = 0;
2222
72.0k
    for (int n = 0; n < n_cache && i < pal_sz; n++)
2223
50.8k
        if (dav1d_msac_decode_bool_equi(&ts->msac))
2224
24.9k
            used_cache[i++] = cache[n];
2225
21.1k
    const int n_used_cache = i;
2226
2227
    // parse new entries
2228
21.1k
    pixel *const pal = t->frame_thread.pass ?
2229
21.1k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2230
21.1k
                            ((t->bx >> 1) + (t->by & 1))][pl] :
2231
21.1k
        bytefn(t->scratch.pal)[pl];
2232
21.1k
    if (i < pal_sz) {
2233
17.9k
        const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2234
17.9k
        int prev = pal[i++] = dav1d_msac_decode_bools(&ts->msac, bpc);
2235
2236
17.9k
        if (i < pal_sz) {
2237
16.0k
            int bits = bpc - 3 + dav1d_msac_decode_bools(&ts->msac, 2);
2238
16.0k
            const int max = (1 << bpc) - 1;
2239
2240
37.8k
            do {
2241
37.8k
                const int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2242
37.8k
                prev = pal[i++] = imin(prev + delta + !pl, max);
2243
37.8k
                if (prev + !pl >= max) {
2244
19.4k
                    for (; i < pal_sz; i++)
2245
12.5k
                        pal[i] = max;
2246
6.90k
                    break;
2247
6.90k
                }
2248
30.9k
                bits = imin(bits, 1 + ulog2(max - prev - !pl));
2249
30.9k
            } while (i < pal_sz);
2250
16.0k
        }
2251
2252
        // merge cache+new entries
2253
17.9k
        int n = 0, m = n_used_cache;
2254
102k
        for (i = 0; i < pal_sz; i++) {
2255
84.5k
            if (n < n_used_cache && (m >= pal_sz || used_cache[n] <= pal[m])) {
2256
16.2k
                pal[i] = used_cache[n++];
2257
68.3k
            } else {
2258
68.3k
                assert(m < pal_sz);
2259
68.3k
                pal[i] = pal[m++];
2260
68.3k
            }
2261
84.5k
        }
2262
17.9k
    } else {
2263
3.24k
        memcpy(pal, used_cache, n_used_cache * sizeof(*used_cache));
2264
3.24k
    }
2265
2266
21.1k
    if (DEBUG_BLOCK_INFO) {
2267
0
        printf("Post-pal[pl=%d,sz=%d,cache_size=%d,used_cache=%d]: r=%d, cache=",
2268
0
               pl, pal_sz, n_cache, n_used_cache, ts->msac.rng);
2269
0
        for (int n = 0; n < n_cache; n++)
2270
0
            printf("%c%02x", n ? ' ' : '[', cache[n]);
2271
0
        printf("%s, pal=", n_cache ? "]" : "[]");
2272
0
        for (int n = 0; n < pal_sz; n++)
2273
0
            printf("%c%02x", n ? ' ' : '[', pal[n]);
2274
0
        printf("]\n");
2275
0
    }
2276
21.1k
}
2277
2278
void bytefn(dav1d_read_pal_uv)(Dav1dTaskContext *const t, Av1Block *const b,
2279
                               const int sz_ctx, const int bx4, const int by4)
2280
8.92k
{
2281
8.92k
    bytefn(dav1d_read_pal_plane)(t, b, 1, sz_ctx, bx4, by4);
2282
2283
    // V pal coding
2284
8.92k
    Dav1dTileState *const ts = t->ts;
2285
8.92k
    const Dav1dFrameContext *const f = t->f;
2286
8.92k
    pixel *const pal = t->frame_thread.pass ?
2287
8.92k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2288
8.92k
                            ((t->bx >> 1) + (t->by & 1))][2] :
2289
8.92k
        bytefn(t->scratch.pal)[2];
2290
8.92k
    const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2291
8.92k
    if (dav1d_msac_decode_bool_equi(&ts->msac)) {
2292
4.35k
        const int bits = bpc - 4 + dav1d_msac_decode_bools(&ts->msac, 2);
2293
4.35k
        int prev = pal[0] = dav1d_msac_decode_bools(&ts->msac, bpc);
2294
4.35k
        const int max = (1 << bpc) - 1;
2295
18.2k
        for (int i = 1; i < b->pal_sz[1]; i++) {
2296
13.9k
            int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2297
13.9k
            if (delta && dav1d_msac_decode_bool_equi(&ts->msac)) delta = -delta;
2298
13.9k
            prev = pal[i] = (prev + delta) & max;
2299
13.9k
        }
2300
4.57k
    } else {
2301
23.1k
        for (int i = 0; i < b->pal_sz[1]; i++)
2302
18.6k
            pal[i] = dav1d_msac_decode_bools(&ts->msac, bpc);
2303
4.57k
    }
2304
8.92k
    if (DEBUG_BLOCK_INFO) {
2305
0
        printf("Post-pal[pl=2]: r=%d ", ts->msac.rng);
2306
0
        for (int n = 0; n < b->pal_sz[1]; n++)
2307
0
            printf("%c%02x", n ? ' ' : '[', pal[n]);
2308
0
        printf("]\n");
2309
0
    }
2310
8.92k
}
dav1d_read_pal_uv_8bpc
Line
Count
Source
2280
4.15k
{
2281
4.15k
    bytefn(dav1d_read_pal_plane)(t, b, 1, sz_ctx, bx4, by4);
2282
2283
    // V pal coding
2284
4.15k
    Dav1dTileState *const ts = t->ts;
2285
4.15k
    const Dav1dFrameContext *const f = t->f;
2286
4.15k
    pixel *const pal = t->frame_thread.pass ?
2287
4.15k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2288
4.15k
                            ((t->bx >> 1) + (t->by & 1))][2] :
2289
4.15k
        bytefn(t->scratch.pal)[2];
2290
4.15k
    const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2291
4.15k
    if (dav1d_msac_decode_bool_equi(&ts->msac)) {
2292
2.01k
        const int bits = bpc - 4 + dav1d_msac_decode_bools(&ts->msac, 2);
2293
2.01k
        int prev = pal[0] = dav1d_msac_decode_bools(&ts->msac, bpc);
2294
2.01k
        const int max = (1 << bpc) - 1;
2295
8.46k
        for (int i = 1; i < b->pal_sz[1]; i++) {
2296
6.45k
            int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2297
6.45k
            if (delta && dav1d_msac_decode_bool_equi(&ts->msac)) delta = -delta;
2298
6.45k
            prev = pal[i] = (prev + delta) & max;
2299
6.45k
        }
2300
2.13k
    } else {
2301
10.7k
        for (int i = 0; i < b->pal_sz[1]; i++)
2302
8.57k
            pal[i] = dav1d_msac_decode_bools(&ts->msac, bpc);
2303
2.13k
    }
2304
4.15k
    if (DEBUG_BLOCK_INFO) {
2305
0
        printf("Post-pal[pl=2]: r=%d ", ts->msac.rng);
2306
0
        for (int n = 0; n < b->pal_sz[1]; n++)
2307
0
            printf("%c%02x", n ? ' ' : '[', pal[n]);
2308
0
        printf("]\n");
2309
0
    }
2310
4.15k
}
dav1d_read_pal_uv_16bpc
Line
Count
Source
2280
4.77k
{
2281
4.77k
    bytefn(dav1d_read_pal_plane)(t, b, 1, sz_ctx, bx4, by4);
2282
2283
    // V pal coding
2284
4.77k
    Dav1dTileState *const ts = t->ts;
2285
4.77k
    const Dav1dFrameContext *const f = t->f;
2286
4.77k
    pixel *const pal = t->frame_thread.pass ?
2287
4.77k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2288
4.77k
                            ((t->bx >> 1) + (t->by & 1))][2] :
2289
4.77k
        bytefn(t->scratch.pal)[2];
2290
4.77k
    const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2291
4.77k
    if (dav1d_msac_decode_bool_equi(&ts->msac)) {
2292
2.34k
        const int bits = bpc - 4 + dav1d_msac_decode_bools(&ts->msac, 2);
2293
2.34k
        int prev = pal[0] = dav1d_msac_decode_bools(&ts->msac, bpc);
2294
2.34k
        const int max = (1 << bpc) - 1;
2295
9.81k
        for (int i = 1; i < b->pal_sz[1]; i++) {
2296
7.47k
            int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2297
7.47k
            if (delta && dav1d_msac_decode_bool_equi(&ts->msac)) delta = -delta;
2298
7.47k
            prev = pal[i] = (prev + delta) & max;
2299
7.47k
        }
2300
2.43k
    } else {
2301
12.4k
        for (int i = 0; i < b->pal_sz[1]; i++)
2302
10.0k
            pal[i] = dav1d_msac_decode_bools(&ts->msac, bpc);
2303
2.43k
    }
2304
4.77k
    if (DEBUG_BLOCK_INFO) {
2305
0
        printf("Post-pal[pl=2]: r=%d ", ts->msac.rng);
2306
0
        for (int n = 0; n < b->pal_sz[1]; n++)
2307
0
            printf("%c%02x", n ? ' ' : '[', pal[n]);
2308
0
        printf("]\n");
2309
0
    }
2310
4.77k
}