Coverage Report

Created: 2026-08-13 07:20

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
324k
static inline unsigned read_golomb(MsacContext *const msac) {
50
324k
    int len = 0;
51
324k
    unsigned val = 1;
52
53
560k
    while (!dav1d_msac_decode_bool_equi(msac) && len < 32) len++;
54
560k
    while (len--) val = (val << 1) + dav1d_msac_decode_bool_equi(msac);
55
56
324k
    return val - 1;
57
324k
}
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
3.74M
{
66
3.74M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
67
68
3.74M
    if (chroma) {
69
1.96M
        const int ss_ver = layout == DAV1D_PIXEL_LAYOUT_I420;
70
1.96M
        const int ss_hor = layout != DAV1D_PIXEL_LAYOUT_I444;
71
1.96M
        const int not_one_blk = b_dim[2] - (!!b_dim[2] && ss_hor) > t_dim->lw ||
72
1.27M
                                b_dim[3] - (!!b_dim[3] && ss_ver) > t_dim->lh;
73
1.96M
        unsigned ca, cl;
74
75
1.96M
#define MERGE_CTX(dir, type, no_val) \
76
3.92M
        c##dir = *(const type *) dir != no_val; \
77
3.92M
        break
78
79
1.96M
        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
767k
        case TX_4X4:   MERGE_CTX(a, uint8_t,  0x40);
87
423k
        case TX_8X8:   MERGE_CTX(a, uint16_t, 0x4040);
88
289k
        case TX_16X16: MERGE_CTX(a, uint32_t, 0x40404040U);
89
482k
        case TX_32X32: MERGE_CTX(a, uint64_t, 0x4040404040404040ULL);
90
1.96M
        }
91
1.96M
        switch (t_dim->lh) {
92
0
        default: assert(0); /* fall-through */
93
871k
        case TX_4X4:   MERGE_CTX(l, uint8_t,  0x40);
94
393k
        case TX_8X8:   MERGE_CTX(l, uint16_t, 0x4040);
95
227k
        case TX_16X16: MERGE_CTX(l, uint32_t, 0x40404040U);
96
471k
        case TX_32X32: MERGE_CTX(l, uint64_t, 0x4040404040404040ULL);
97
1.96M
        }
98
1.96M
#undef MERGE_CTX
99
100
1.96M
        return 7 + not_one_blk * 3 + ca + cl;
101
1.96M
    } else if (b_dim[2] == t_dim->lw && b_dim[3] == t_dim->lh) {
102
800k
        return 0;
103
985k
    } else {
104
985k
        unsigned la, ll;
105
106
985k
#define MERGE_CTX(dir, type, tx) \
107
1.99M
        if (tx == TX_64X64) { \
108
178k
            uint64_t tmp = *(const uint64_t *) dir; \
109
178k
            tmp |= *(const uint64_t *) &dir[8]; \
110
178k
            l##dir = (unsigned) (tmp >> 32) | (unsigned) tmp; \
111
178k
        } else \
112
1.99M
            l##dir = *(const type *) dir; \
113
1.99M
        if (tx == TX_32X32) l##dir |= *(const type *) &dir[sizeof(type)]; \
114
1.99M
        if (tx >= TX_16X16) l##dir |= l##dir >> 16; \
115
1.99M
        if (tx >= TX_8X8)   l##dir |= l##dir >> 8; \
116
1.99M
        break
117
118
985k
        switch (t_dim->lw) {
119
0
        default: assert(0); /* fall-through */
120
480k
        case TX_4X4:   MERGE_CTX(a, uint8_t,  TX_4X4);
121
238k
        case TX_8X8:   MERGE_CTX(a, uint16_t, TX_8X8);
122
173k
        case TX_16X16: MERGE_CTX(a, uint32_t, TX_16X16);
123
15.3k
        case TX_32X32: MERGE_CTX(a, uint32_t, TX_32X32);
124
89.4k
        case TX_64X64: MERGE_CTX(a, uint32_t, TX_64X64);
125
985k
        }
126
997k
        switch (t_dim->lh) {
127
0
        default: assert(0); /* fall-through */
128
489k
        case TX_4X4:   MERGE_CTX(l, uint8_t,  TX_4X4);
129
231k
        case TX_8X8:   MERGE_CTX(l, uint16_t, TX_8X8);
130
172k
        case TX_16X16: MERGE_CTX(l, uint32_t, TX_16X16);
131
15.5k
        case TX_32X32: MERGE_CTX(l, uint32_t, TX_32X32);
132
89.4k
        case TX_64X64: MERGE_CTX(l, uint32_t, TX_64X64);
133
997k
        }
134
997k
#undef MERGE_CTX
135
136
997k
        return dav1d_skip_ctx[umin(la & 0x3F, 4)][umin(ll & 0x3F, 4)];
137
997k
    }
138
3.74M
}
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
1.56M
{
144
1.56M
    uint64_t mask = 0xC0C0C0C0C0C0C0C0ULL, mul = 0x0101010101010101ULL;
145
1.56M
    int s;
146
147
1.56M
#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
1.56M
    __asm__("" : "+r"(mask), "+r"(mul));
151
1.56M
#endif
152
153
1.56M
    switch(tx) {
154
0
    default: assert(0); /* fall-through */
155
505k
    case TX_4X4: {
156
505k
        int t = *(const uint8_t *) a >> 6;
157
505k
        t    += *(const uint8_t *) l >> 6;
158
505k
        s = t - 1 - 1;
159
505k
        break;
160
0
    }
161
202k
    case TX_8X8: {
162
202k
        uint32_t t = *(const uint16_t *) a & (uint32_t) mask;
163
202k
        t         += *(const uint16_t *) l & (uint32_t) mask;
164
202k
        t *= 0x04040404U;
165
202k
        s = (int) (t >> 24) - 2 - 2;
166
202k
        break;
167
0
    }
168
153k
    case TX_16X16: {
169
153k
        uint32_t t = (*(const uint32_t *) a & (uint32_t) mask) >> 6;
170
153k
        t         += (*(const uint32_t *) l & (uint32_t) mask) >> 6;
171
153k
        t *= (uint32_t) mul;
172
153k
        s = (int) (t >> 24) - 4 - 4;
173
153k
        break;
174
0
    }
175
116k
    case TX_32X32: {
176
116k
        uint64_t t = (*(const uint64_t *) a & mask) >> 6;
177
116k
        t         += (*(const uint64_t *) l & mask) >> 6;
178
116k
        t *= mul;
179
116k
        s = (int) (t >> 56) - 8 - 8;
180
116k
        break;
181
0
    }
182
70.1k
    case TX_64X64: {
183
70.1k
        uint64_t t = (*(const uint64_t *) &a[0] & mask) >> 6;
184
70.1k
        t         += (*(const uint64_t *) &a[8] & mask) >> 6;
185
70.1k
        t         += (*(const uint64_t *) &l[0] & mask) >> 6;
186
70.1k
        t         += (*(const uint64_t *) &l[8] & mask) >> 6;
187
70.1k
        t *= mul;
188
70.1k
        s = (int) (t >> 56) - 16 - 16;
189
70.1k
        break;
190
0
    }
191
61.6k
    case RTX_4X8: {
192
61.6k
        uint32_t t = *(const uint8_t  *) a & (uint32_t) mask;
193
61.6k
        t         += *(const uint16_t *) l & (uint32_t) mask;
194
61.6k
        t *= 0x04040404U;
195
61.6k
        s = (int) (t >> 24) - 1 - 2;
196
61.6k
        break;
197
0
    }
198
86.7k
    case RTX_8X4: {
199
86.7k
        uint32_t t = *(const uint16_t *) a & (uint32_t) mask;
200
86.7k
        t         += *(const uint8_t  *) l & (uint32_t) mask;
201
86.7k
        t *= 0x04040404U;
202
86.7k
        s = (int) (t >> 24) - 2 - 1;
203
86.7k
        break;
204
0
    }
205
49.8k
    case RTX_8X16: {
206
49.8k
        uint32_t t = *(const uint16_t *) a & (uint32_t) mask;
207
49.8k
        t         += *(const uint32_t *) l & (uint32_t) mask;
208
49.8k
        t = (t >> 6) * (uint32_t) mul;
209
49.8k
        s = (int) (t >> 24) - 2 - 4;
210
49.8k
        break;
211
0
    }
212
87.8k
    case RTX_16X8: {
213
87.8k
        uint32_t t = *(const uint32_t *) a & (uint32_t) mask;
214
87.8k
        t         += *(const uint16_t *) l & (uint32_t) mask;
215
87.8k
        t = (t >> 6) * (uint32_t) mul;
216
87.8k
        s = (int) (t >> 24) - 4 - 2;
217
87.8k
        break;
218
0
    }
219
24.8k
    case RTX_16X32: {
220
24.8k
        uint64_t t = *(const uint32_t *) a & (uint32_t) mask;
221
24.8k
        t         += *(const uint64_t *) l & mask;
222
24.8k
        t = (t >> 6) * mul;
223
24.8k
        s = (int) (t >> 56) - 4 - 8;
224
24.8k
        break;
225
0
    }
226
36.8k
    case RTX_32X16: {
227
36.8k
        uint64_t t = *(const uint64_t *) a & mask;
228
36.8k
        t         += *(const uint32_t *) l & (uint32_t) mask;
229
36.8k
        t = (t >> 6) * mul;
230
36.8k
        s = (int) (t >> 56) - 8 - 4;
231
36.8k
        break;
232
0
    }
233
11.0k
    case RTX_32X64: {
234
11.0k
        uint64_t t = (*(const uint64_t *) &a[0] & mask) >> 6;
235
11.0k
        t         += (*(const uint64_t *) &l[0] & mask) >> 6;
236
11.0k
        t         += (*(const uint64_t *) &l[8] & mask) >> 6;
237
11.0k
        t *= mul;
238
11.0k
        s = (int) (t >> 56) - 8 - 16;
239
11.0k
        break;
240
0
    }
241
11.8k
    case RTX_64X32: {
242
11.8k
        uint64_t t = (*(const uint64_t *) &a[0] & mask) >> 6;
243
11.8k
        t         += (*(const uint64_t *) &a[8] & mask) >> 6;
244
11.8k
        t         += (*(const uint64_t *) &l[0] & mask) >> 6;
245
11.8k
        t *= mul;
246
11.8k
        s = (int) (t >> 56) - 16 - 8;
247
11.8k
        break;
248
0
    }
249
29.2k
    case RTX_4X16: {
250
29.2k
        uint32_t t = *(const uint8_t  *) a & (uint32_t) mask;
251
29.2k
        t         += *(const uint32_t *) l & (uint32_t) mask;
252
29.2k
        t = (t >> 6) * (uint32_t) mul;
253
29.2k
        s = (int) (t >> 24) - 1 - 4;
254
29.2k
        break;
255
0
    }
256
61.7k
    case RTX_16X4: {
257
61.7k
        uint32_t t = *(const uint32_t *) a & (uint32_t) mask;
258
61.7k
        t         += *(const uint8_t  *) l & (uint32_t) mask;
259
61.7k
        t = (t >> 6) * (uint32_t) mul;
260
61.7k
        s = (int) (t >> 24) - 4 - 1;
261
61.7k
        break;
262
0
    }
263
18.4k
    case RTX_8X32: {
264
18.4k
        uint64_t t = *(const uint16_t *) a & (uint32_t) mask;
265
18.4k
        t         += *(const uint64_t *) l & mask;
266
18.4k
        t = (t >> 6) * mul;
267
18.4k
        s = (int) (t >> 56) - 2 - 8;
268
18.4k
        break;
269
0
    }
270
25.7k
    case RTX_32X8: {
271
25.7k
        uint64_t t = *(const uint64_t *) a & mask;
272
25.7k
        t         += *(const uint16_t *) l & (uint32_t) mask;
273
25.7k
        t = (t >> 6) * mul;
274
25.7k
        s = (int) (t >> 56) - 8 - 2;
275
25.7k
        break;
276
0
    }
277
6.97k
    case RTX_16X64: {
278
6.97k
        uint64_t t = *(const uint32_t *) a & (uint32_t) mask;
279
6.97k
        t         += *(const uint64_t *) &l[0] & mask;
280
6.97k
        t = (t >> 6) + ((*(const uint64_t *) &l[8] & mask) >> 6);
281
6.97k
        t *= mul;
282
6.97k
        s = (int) (t >> 56) - 4 - 16;
283
6.97k
        break;
284
0
    }
285
4.31k
    case RTX_64X16: {
286
4.31k
        uint64_t t = *(const uint64_t *) &a[0] & mask;
287
4.31k
        t         += *(const uint32_t *) l & (uint32_t) mask;
288
4.31k
        t = (t >> 6) + ((*(const uint64_t *) &a[8] & mask) >> 6);
289
4.31k
        t *= mul;
290
4.31k
        s = (int) (t >> 56) - 16 - 4;
291
4.31k
        break;
292
0
    }
293
1.56M
    }
294
295
1.56M
    return (s != 0) + (s > 0);
296
1.56M
}
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
35.5M
{
305
35.5M
    unsigned mag = levels[0 * stride + 1] + levels[1 * stride + 0];
306
35.5M
    unsigned offset;
307
35.5M
    if (tx_class == TX_CLASS_2D) {
308
33.1M
        mag += levels[1 * stride + 1];
309
33.1M
        *hi_mag = mag;
310
33.1M
        mag += levels[0 * stride + 2] + levels[2 * stride + 0];
311
33.1M
        offset = ctx_offsets[umin(y, 4)][umin(x, 4)];
312
33.1M
    } else {
313
2.44M
        mag += levels[0 * stride + 2];
314
2.44M
        *hi_mag = mag;
315
2.44M
        mag += levels[0 * stride + 3] + levels[0 * stride + 4];
316
2.44M
        offset = 26 + (y > 1 ? 10 : y * 5);
317
2.44M
    }
318
35.5M
    return offset + (mag > 512 ? 4 : (mag + 64) >> 7);
319
35.5M
}
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
3.74M
{
328
3.74M
    Dav1dTileState *const ts = t->ts;
329
3.74M
    const int chroma = !!plane;
330
3.74M
    const Dav1dFrameContext *const f = t->f;
331
3.74M
    const int lossless = f->frame_hdr->segmentation.lossless[b->seg_id];
332
3.74M
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[tx];
333
3.74M
    const int dbg = DEBUG_BLOCK_INFO && plane && 0;
334
335
3.74M
    if (dbg)
336
0
        printf("Start: r=%d\n", ts->msac.rng);
337
338
    // does this block have any non-zero coefficients
339
3.74M
    const int sctx = get_skip_ctx(t_dim, bs, a, l, chroma, f->cur.p.layout);
340
3.74M
    const int all_skip = dav1d_msac_decode_bool_adapt(&ts->msac,
341
3.74M
                             ts->cdf.coef.skip[t_dim->ctx][sctx]);
342
3.74M
    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
3.74M
    if (all_skip) {
346
1.85M
        *res_ctx = 0x40;
347
1.85M
        *txtp = lossless * WHT_WHT; /* lossless ? WHT_WHT : DCT_DCT */
348
1.85M
        return -1;
349
1.85M
    }
350
351
    // transform type (chroma: derived, luma: explicitly coded)
352
1.89M
    if (lossless) {
353
412k
        assert(t_dim->max == TX_4X4);
354
412k
        *txtp = WHT_WHT;
355
1.47M
    } else if (t_dim->max + intra >= TX_64X64) {
356
324k
        *txtp = DCT_DCT;
357
1.15M
    } else if (chroma) {
358
        // inferred from either the luma txtp (inter) or a LUT (intra)
359
255k
        *txtp = intra ? dav1d_txtp_from_uvmode[b->uv_mode] :
360
255k
                        get_uv_inter_txtp(t_dim, *txtp);
361
899k
    } 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
8.63k
        *txtp = DCT_DCT;
366
890k
    } else {
367
890k
        unsigned idx;
368
890k
        if (intra) {
369
651k
            const enum IntraPredMode y_mode_nofilt = b->y_mode == FILTER_PRED ?
370
547k
                dav1d_filter_mode_to_y_mode[b->y_angle] : b->y_mode;
371
651k
            if (f->frame_hdr->reduced_txtp_set || t_dim->min == TX_16X16) {
372
288k
                idx = dav1d_msac_decode_symbol_adapt8(&ts->msac,
373
288k
                          ts->cdf.m.txtp_intra2[t_dim->min][y_mode_nofilt], 4);
374
288k
                *txtp = dav1d_tx_types_per_set[idx + 0];
375
363k
            } else {
376
363k
                idx = dav1d_msac_decode_symbol_adapt8(&ts->msac,
377
363k
                          ts->cdf.m.txtp_intra1[t_dim->min][y_mode_nofilt], 6);
378
363k
                *txtp = dav1d_tx_types_per_set[idx + 5];
379
363k
            }
380
651k
            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
651k
        } else {
384
239k
            if (f->frame_hdr->reduced_txtp_set || t_dim->max == TX_32X32) {
385
68.4k
                idx = dav1d_msac_decode_bool_adapt(&ts->msac,
386
68.4k
                          ts->cdf.m.txtp_inter3[t_dim->min]);
387
68.4k
                *txtp = (idx - 1) & IDTX; /* idx ? DCT_DCT : IDTX */
388
170k
            } else if (t_dim->min == TX_16X16) {
389
24.9k
                idx = dav1d_msac_decode_symbol_adapt16(&ts->msac,
390
24.9k
                          ts->cdf.m.txtp_inter2, 11);
391
24.9k
                *txtp = dav1d_tx_types_per_set[idx + 12];
392
145k
            } else {
393
145k
                idx = dav1d_msac_decode_symbol_adapt16(&ts->msac,
394
145k
                          ts->cdf.m.txtp_inter1[t_dim->min], 15);
395
145k
                *txtp = dav1d_tx_types_per_set[idx + 24];
396
145k
            }
397
239k
            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
239k
        }
401
890k
    }
402
403
    // find end-of-block (eob)
404
1.89M
    int eob;
405
1.89M
    const int slw = imin(t_dim->lw, TX_32X32), slh = imin(t_dim->lh, TX_32X32);
406
1.89M
    const int tx2dszctx = slw + slh;
407
1.89M
    const enum TxClass tx_class = dav1d_tx_type_class[*txtp];
408
1.89M
    const int is_1d = tx_class != TX_CLASS_2D;
409
1.89M
    switch (tx2dszctx) {
410
0
#define case_sz(sz, bin, ns, is_1d) \
411
1.89M
    case sz: { \
412
1.89M
        uint16_t *const eob_bin_cdf = ts->cdf.coef.eob_bin_##bin[chroma]is_1d; \
413
1.89M
        eob = dav1d_msac_decode_symbol_adapt##ns(&ts->msac, eob_bin_cdf, 4 + sz); \
414
1.89M
        break; \
415
1.89M
    }
416
592k
    case_sz(0,   16,  8, [is_1d]);
417
191k
    case_sz(1,   32,  8, [is_1d]);
418
377k
    case_sz(2,   64,  8, [is_1d]);
419
181k
    case_sz(3,  128,  8, [is_1d]);
420
246k
    case_sz(4,  256, 16, [is_1d]);
421
83.5k
    case_sz(5,  512, 16,        );
422
225k
    case_sz(6, 1024, 16,        );
423
1.89M
#undef case_sz
424
1.89M
    }
425
1.89M
    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
1.89M
    if (eob > 1) {
429
1.26M
        const int eob_bin = eob - 2;
430
1.26M
        uint16_t *const eob_hi_bit_cdf =
431
1.26M
            ts->cdf.coef.eob_hi_bit[t_dim->ctx][chroma][eob_bin];
432
1.26M
        const int eob_hi_bit = dav1d_msac_decode_bool_adapt(&ts->msac, eob_hi_bit_cdf);
433
1.26M
        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.26M
        eob = ((eob_hi_bit | 2) << eob_bin) | dav1d_msac_decode_bools(&ts->msac, eob_bin);
437
1.26M
        if (dbg)
438
0
            printf("Post-eob[%d]: r=%d\n", eob, ts->msac.rng);
439
1.26M
    }
440
1.89M
    assert(eob >= 0);
441
442
    // base tokens
443
1.89M
    uint16_t (*const eob_cdf)[4] = ts->cdf.coef.eob_base_tok[t_dim->ctx][chroma];
444
1.89M
    uint16_t (*const hi_cdf)[4] = ts->cdf.coef.br_tok[imin(t_dim->ctx, 3)][chroma];
445
1.89M
    unsigned rc, dc_tok;
446
447
1.89M
    if (eob) {
448
1.34M
        uint16_t (*const lo_cdf)[4] = ts->cdf.coef.base_tok[t_dim->ctx][chroma];
449
1.34M
        uint8_t *const levels = t->scratch.levels; // bits 0-5: tok, 6-7: lo_tok
450
451
        /* eob */
452
1.34M
        unsigned ctx = 1 + (eob > 2 << tx2dszctx) + (eob > 4 << tx2dszctx);
453
1.34M
        int eob_tok = dav1d_msac_decode_symbol_adapt4(&ts->msac, eob_cdf[ctx], 2);
454
1.34M
        int tok = eob_tok + 1;
455
1.34M
        int level_tok = tok * 0x41;
456
1.34M
        unsigned mag;
457
458
1.34M
#define DECODE_COEFS_CLASS(tx_class) \
459
1.34M
        unsigned x, y; \
460
1.34M
        uint8_t *level; \
461
1.34M
        if (tx_class == TX_CLASS_2D) \
462
1.34M
            rc = scan[eob], x = rc >> shift, y = rc & mask; \
463
1.34M
        else if (tx_class == TX_CLASS_H) \
464
            /* Transposing reduces the stride and padding requirements */ \
465
116k
            x = eob & mask, y = eob >> shift, rc = eob; \
466
116k
        else /* tx_class == TX_CLASS_V */ \
467
116k
            x = eob & mask, y = eob >> shift, rc = (x << shift2) | y; \
468
1.34M
        if (dbg) \
469
1.34M
            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
1.34M
        if (eob_tok == 2) { \
472
23.9k
            ctx = (tx_class == TX_CLASS_2D ? (x | y) > 1 : y != 0) ? 14 : 7; \
473
23.9k
            tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[ctx]); \
474
23.9k
            level_tok = tok + (3 << 6); \
475
23.9k
            if (dbg) \
476
23.9k
                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
23.9k
        } \
480
1.34M
        cf[rc] = tok << 11; \
481
1.34M
        if (tx_class == TX_CLASS_2D) \
482
1.34M
            level = levels + rc; \
483
1.34M
        else \
484
1.34M
            level = levels + x * stride + y; \
485
1.34M
        *level = (uint8_t) level_tok; \
486
36.8M
        for (int i = eob - 1; i > 0; i--) { /* ac */ \
487
35.4M
            unsigned rc_i; \
488
35.4M
            if (tx_class == TX_CLASS_2D) \
489
35.4M
                rc_i = scan[i], x = rc_i >> shift, y = rc_i & mask; \
490
35.4M
            else if (tx_class == TX_CLASS_H) \
491
2.37M
                x = i & mask, y = i >> shift, rc_i = i; \
492
2.37M
            else /* tx_class == TX_CLASS_V */ \
493
2.37M
                x = i & mask, y = i >> shift, rc_i = (x << shift2) | y; \
494
35.4M
            assert(x < 32 && y < 32); \
495
35.4M
            if (tx_class == TX_CLASS_2D) \
496
35.4M
                level = levels + rc_i; \
497
35.4M
            else \
498
35.4M
                level = levels + x * stride + y; \
499
35.4M
            ctx = get_lo_ctx(level, tx_class, &mag, lo_ctx_offsets, x, y, stride); \
500
35.4M
            if (tx_class == TX_CLASS_2D) \
501
35.4M
                y |= x; \
502
35.4M
            tok = dav1d_msac_decode_symbol_adapt4(&ts->msac, lo_cdf[ctx], 3); \
503
35.4M
            if (dbg) \
504
35.4M
                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
35.4M
            if (tok == 3) { \
507
2.44M
                mag &= 63; \
508
2.44M
                ctx = (y > (tx_class == TX_CLASS_2D) ? 14 : 7) + \
509
2.44M
                      (mag > 12 ? 6 : (mag + 1) >> 1); \
510
2.44M
                tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[ctx]); \
511
2.44M
                if (dbg) \
512
2.44M
                    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
2.44M
                *level = (uint8_t) (tok + (3 << 6)); \
516
2.44M
                cf[rc_i] = (tok << 11) | rc; \
517
2.44M
                rc = rc_i; \
518
33.0M
            } else { \
519
                /* 0x1 for tok, 0x7ff as bitmask for rc, 0x41 for level_tok */ \
520
33.0M
                tok *= 0x17ff41; \
521
33.0M
                *level = (uint8_t) tok; \
522
                /* tok ? (tok << 11) | rc : 0 */ \
523
33.0M
                tok = (tok >> 9) & (rc + ~0x7ffu); \
524
33.0M
                if (tok) rc = rc_i; \
525
33.0M
                cf[rc_i] = tok; \
526
33.0M
            } \
527
35.4M
        } \
528
        /* dc */ \
529
1.34M
        ctx = (tx_class == TX_CLASS_2D) ? 0 : \
530
1.34M
            get_lo_ctx(levels, tx_class, &mag, lo_ctx_offsets, 0, 0, stride); \
531
1.34M
        dc_tok = dav1d_msac_decode_symbol_adapt4(&ts->msac, lo_cdf[ctx], 3); \
532
1.34M
        if (dbg) \
533
1.34M
            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
1.34M
        if (dc_tok == 3) { \
536
489k
            if (tx_class == TX_CLASS_2D) \
537
489k
                mag = levels[0 * stride + 1] + levels[1 * stride + 0] + \
538
477k
                      levels[1 * stride + 1]; \
539
489k
            mag &= 63; \
540
489k
            ctx = mag > 12 ? 6 : (mag + 1) >> 1; \
541
489k
            dc_tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[ctx]); \
542
489k
            if (dbg) \
543
489k
                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
489k
        } \
546
1.34M
        break
547
548
1.34M
        const uint16_t *scan;
549
1.34M
        switch (tx_class) {
550
1.23M
        case TX_CLASS_2D: {
551
1.23M
            const unsigned nonsquare_tx = tx >= RTX_4X8;
552
1.23M
            const uint8_t (*const lo_ctx_offsets)[5] =
553
1.23M
                dav1d_lo_ctx_offsets[nonsquare_tx + (tx & nonsquare_tx)];
554
1.23M
            scan = dav1d_scans[tx];
555
1.23M
            const ptrdiff_t stride = 4 << slh;
556
1.23M
            const unsigned shift = slh + 2, shift2 = 0;
557
1.23M
            const unsigned mask = (4 << slh) - 1;
558
1.23M
            memset(levels, 0, stride * ((4 << slw) + 2));
559
1.23M
            DECODE_COEFS_CLASS(TX_CLASS_2D);
560
1.23M
        }
561
74.8k
        case TX_CLASS_H: {
562
74.8k
            const uint8_t (*const lo_ctx_offsets)[5] = NULL;
563
74.8k
            const ptrdiff_t stride = 16;
564
74.8k
            const unsigned shift = slh + 2, shift2 = 0;
565
74.8k
            const unsigned mask = (4 << slh) - 1;
566
74.8k
            memset(levels, 0, stride * ((4 << slh) + 2));
567
74.8k
            DECODE_COEFS_CLASS(TX_CLASS_H);
568
74.8k
        }
569
41.2k
        case TX_CLASS_V: {
570
41.2k
            const uint8_t (*const lo_ctx_offsets)[5] = NULL;
571
41.2k
            const ptrdiff_t stride = 16;
572
41.2k
            const unsigned shift = slw + 2, shift2 = slh + 2;
573
41.2k
            const unsigned mask = (4 << slw) - 1;
574
41.2k
            memset(levels, 0, stride * ((4 << slw) + 2));
575
41.2k
            DECODE_COEFS_CLASS(TX_CLASS_V);
576
41.2k
        }
577
0
#undef DECODE_COEFS_CLASS
578
0
        default: assert(0);
579
1.34M
        }
580
1.34M
    } else { // dc-only
581
550k
        int tok_br = dav1d_msac_decode_symbol_adapt4(&ts->msac, eob_cdf[0], 2);
582
550k
        dc_tok = 1 + tok_br;
583
550k
        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
550k
        if (tok_br == 2) {
587
21.9k
            dc_tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[0]);
588
21.9k
            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
21.9k
        }
592
550k
        rc = 0;
593
550k
    }
594
595
    // residual and sign
596
1.89M
    const uint16_t *const dq_tbl = ts->dq[b->seg_id][plane];
597
1.89M
    const uint8_t *const qm_tbl = *txtp < IDTX ? f->qm[tx][plane] : NULL;
598
1.89M
    const int dq_shift = imax(0, t_dim->ctx - 2);
599
1.89M
    const int cf_max = ~(~127U << (BITDEPTH == 8 ? 8 : f->cur.p.bpc));
600
1.89M
    unsigned cul_level, dc_sign_level;
601
602
1.89M
    if (!dc_tok) {
603
334k
        cul_level = 0;
604
334k
        dc_sign_level = 1 << 6;
605
334k
        if (qm_tbl) goto ac_qm;
606
246k
        goto ac_noqm;
607
334k
    }
608
609
1.55M
    const int dc_sign_ctx = get_dc_sign_ctx(tx, a, l);
610
1.55M
    uint16_t *const dc_sign_cdf = ts->cdf.coef.dc_sign[chroma][dc_sign_ctx];
611
1.55M
    const int dc_sign = dav1d_msac_decode_bool_adapt(&ts->msac, dc_sign_cdf);
612
1.55M
    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
1.55M
    int dc_dq = dq_tbl[0];
617
1.55M
    dc_sign_level = (dc_sign - 1) & (2 << 6);
618
619
1.55M
    if (qm_tbl) {
620
480k
        dc_dq = (dc_dq * qm_tbl[0] + 16) >> 5;
621
622
480k
        if (dc_tok == 15) {
623
16.4k
            dc_tok = read_golomb(&ts->msac) + 15;
624
16.4k
            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
16.4k
            dc_tok &= 0xfffff;
629
16.4k
            dc_dq = (dc_dq * dc_tok) & 0xffffff;
630
463k
        } else {
631
463k
            dc_dq *= dc_tok;
632
463k
            assert(dc_dq <= 0xffffff);
633
463k
        }
634
480k
        cul_level = dc_tok;
635
480k
        dc_dq >>= dq_shift;
636
480k
        dc_dq = umin(dc_dq, cf_max + dc_sign);
637
480k
        cf[0] = (coef) (dc_sign ? -dc_dq : dc_dq);
638
639
736k
        if (rc) ac_qm: {
640
736k
            const unsigned ac_dq = dq_tbl[1];
641
5.38M
            do {
642
5.38M
                const int sign = dav1d_msac_decode_bool_equi(&ts->msac);
643
5.38M
                if (dbg)
644
0
                    printf("Post-sign[%d=%d]: r=%d\n", rc, sign, ts->msac.rng);
645
5.38M
                const unsigned rc_tok = cf[rc];
646
5.38M
                unsigned tok, dq = (ac_dq * qm_tbl[rc] + 16) >> 5;
647
5.38M
                int dq_sat;
648
649
5.38M
                if (rc_tok >= (15 << 11)) {
650
130k
                    tok = read_golomb(&ts->msac) + 15;
651
130k
                    if (dbg)
652
0
                        printf("Post-residual[%d=%d->%d]: r=%d\n",
653
0
                               rc, tok - 15, tok, ts->msac.rng);
654
655
130k
                    tok &= 0xfffff;
656
130k
                    dq = (dq * tok) & 0xffffff;
657
5.25M
                } else {
658
5.25M
                    tok = rc_tok >> 11;
659
5.25M
                    dq *= tok;
660
5.25M
                    assert(dq <= 0xffffff);
661
5.25M
                }
662
5.38M
                cul_level += tok;
663
5.38M
                dq >>= dq_shift;
664
5.38M
                dq_sat = umin(dq, cf_max + sign);
665
5.38M
                cf[rc] = (coef) (sign ? -dq_sat : dq_sat);
666
667
5.38M
                rc = rc_tok & 0x3ff;
668
5.38M
            } while (rc);
669
736k
        }
670
1.07M
    } else {
671
        // non-qmatrix is the common case and allows for additional optimizations
672
1.07M
        if (dc_tok == 15) {
673
33.8k
            dc_tok = read_golomb(&ts->msac) + 15;
674
33.8k
            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
33.8k
            dc_tok &= 0xfffff;
679
33.8k
            dc_dq = ((dc_dq * dc_tok) & 0xffffff) >> dq_shift;
680
33.8k
            dc_dq = umin(dc_dq, cf_max + dc_sign);
681
1.04M
        } else {
682
1.04M
            dc_dq = ((dc_dq * dc_tok) >> dq_shift);
683
1.04M
            assert(dc_dq <= cf_max);
684
1.04M
        }
685
1.07M
        cul_level = dc_tok;
686
1.07M
        cf[0] = (coef) (dc_sign ? -dc_dq : dc_dq);
687
688
1.62M
        if (rc) ac_noqm: {
689
1.62M
            const unsigned ac_dq = dq_tbl[1];
690
8.01M
            do {
691
8.01M
                const int sign = dav1d_msac_decode_bool_equi(&ts->msac);
692
8.01M
                if (dbg)
693
0
                    printf("Post-sign[%d=%d]: r=%d\n", rc, sign, ts->msac.rng);
694
8.01M
                const unsigned rc_tok = cf[rc];
695
8.01M
                unsigned tok;
696
8.01M
                int dq;
697
698
                // residual
699
8.01M
                if (rc_tok >= (15 << 11)) {
700
144k
                    tok = read_golomb(&ts->msac) + 15;
701
144k
                    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
144k
                    tok &= 0xfffff;
707
708
                    // dequant, see 7.12.3
709
144k
                    dq = ((ac_dq * tok) & 0xffffff) >> dq_shift;
710
144k
                    dq = umin(dq, cf_max + sign);
711
7.87M
                } else {
712
                    // cannot exceed cf_max, so we can avoid the clipping
713
7.87M
                    tok = rc_tok >> 11;
714
7.87M
                    dq = ((ac_dq * tok) >> dq_shift);
715
7.87M
                    assert(dq <= cf_max);
716
7.87M
                }
717
8.01M
                cul_level += tok;
718
8.01M
                cf[rc] = (coef) (sign ? -dq : dq);
719
720
8.01M
                rc = rc_tok & 0x3ff; // next non-zero rc, zero if eob
721
8.01M
            } while (rc);
722
1.62M
        }
723
1.07M
    }
724
725
    // context
726
1.89M
    *res_ctx = umin(cul_level, 63) | dc_sign_level;
727
728
1.89M
    return eob;
729
1.55M
}
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
574k
{
737
574k
    const Dav1dFrameContext *const f = t->f;
738
574k
    Dav1dTileState *const ts = t->ts;
739
574k
    const Dav1dDSPContext *const dsp = f->dsp;
740
574k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[ytx];
741
574k
    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
574k
    if (depth < 2 && tx_split[depth] &&
746
78.9k
        tx_split[depth] & (1 << (y_off * 4 + x_off)))
747
60.0k
    {
748
60.0k
        const enum RectTxfmSize sub = t_dim->sub;
749
60.0k
        const TxfmInfo *const sub_t_dim = &dav1d_txfm_dimensions[sub];
750
60.0k
        const int txsw = sub_t_dim->w, txsh = sub_t_dim->h;
751
752
60.0k
        read_coef_tree(t, bs, b, sub, depth + 1, tx_split,
753
60.0k
                       x_off * 2 + 0, y_off * 2 + 0, dst);
754
60.0k
        t->bx += txsw;
755
60.0k
        if (txw >= txh && t->bx < f->bw)
756
46.9k
            read_coef_tree(t, bs, b, sub, depth + 1, tx_split, x_off * 2 + 1,
757
46.9k
                           y_off * 2 + 0, dst ? &dst[4 * txsw] : NULL);
758
60.0k
        t->bx -= txsw;
759
60.0k
        t->by += txsh;
760
60.0k
        if (txh >= txw && t->by < f->bh) {
761
42.6k
            if (dst)
762
12.5k
                dst += 4 * txsh * PXSTRIDE(f->cur.stride[0]);
763
42.6k
            read_coef_tree(t, bs, b, sub, depth + 1, tx_split,
764
42.6k
                           x_off * 2 + 0, y_off * 2 + 1, dst);
765
42.6k
            t->bx += txsw;
766
42.6k
            if (txw >= txh && t->bx < f->bw)
767
29.8k
                read_coef_tree(t, bs, b, sub, depth + 1, tx_split, x_off * 2 + 1,
768
29.8k
                               y_off * 2 + 1, dst ? &dst[4 * txsw] : NULL);
769
42.6k
            t->bx -= txsw;
770
42.6k
        }
771
60.0k
        t->by -= txsh;
772
514k
    } else {
773
514k
        const int bx4 = t->bx & 31, by4 = t->by & 31;
774
514k
        enum TxfmType txtp;
775
514k
        uint8_t cf_ctx;
776
514k
        int eob;
777
514k
        coef *cf;
778
779
514k
        if (t->frame_thread.pass) {
780
514k
            const int p = t->frame_thread.pass & 1;
781
514k
            assert(ts->frame_thread[p].cf);
782
514k
            cf = ts->frame_thread[p].cf;
783
514k
            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
514k
        if (t->frame_thread.pass != 2) {
788
351k
            eob = decode_coefs(t, &t->a->lcoef[bx4], &t->l.lcoef[by4],
789
351k
                               ytx, bs, b, 0, 0, cf, &txtp, &cf_ctx);
790
351k
            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
351k
            dav1d_memset_likely_pow2(&t->a->lcoef[bx4], cf_ctx, imin(txw, f->bw - t->bx));
794
351k
            dav1d_memset_likely_pow2(&t->l.lcoef[by4], cf_ctx, imin(txh, f->bh - t->by));
795
351k
#define set_ctx(rep_macro) \
796
1.44M
            for (int y = 0; y < txh; y++) { \
797
1.09M
                rep_macro(txtp_map, 0, txtp); \
798
1.09M
                txtp_map += 32; \
799
1.09M
            }
800
351k
            uint8_t *txtp_map = &t->scratch.txtp_map[by4 * 32 + bx4];
801
351k
            case_set_upto16(t_dim->lw);
802
351k
#undef set_ctx
803
351k
            if (t->frame_thread.pass == 1)
804
351k
                *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
805
351k
        } else {
806
162k
            const int cbi = *ts->frame_thread[0].cbi++;
807
162k
            eob  = cbi >> 5;
808
162k
            txtp = cbi & 0x1f;
809
162k
        }
810
514k
        if (!(t->frame_thread.pass & 1)) {
811
162k
            assert(dst);
812
162k
            if (eob >= 0) {
813
133k
                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
133k
                dsp->itx.itxfm_add[ytx][txtp](dst, f->cur.stride[0], cf, eob
816
133k
                                              HIGHBD_CALL_SUFFIX);
817
133k
                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
133k
            }
820
162k
        }
821
514k
    }
822
574k
}
823
824
void bytefn(dav1d_read_coef_blocks)(Dav1dTaskContext *const t,
825
                                    const enum BlockSize bs, const Av1Block *const b)
826
2.27M
{
827
2.27M
    const Dav1dFrameContext *const f = t->f;
828
2.27M
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
829
2.27M
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
830
2.27M
    const int bx4 = t->bx & 31, by4 = t->by & 31;
831
2.27M
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
832
2.27M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
833
2.27M
    const int bw4 = b_dim[0], bh4 = b_dim[1];
834
2.27M
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
835
2.27M
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
836
1.94M
                           (bw4 > ss_hor || t->bx & 1) &&
837
1.81M
                           (bh4 > ss_ver || t->by & 1);
838
839
2.27M
    if (b->skip) {
840
1.32M
        BlockContext *const a = t->a;
841
1.32M
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
842
1.32M
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
843
1.32M
        if (has_chroma) {
844
1.02M
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
845
1.02M
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
846
1.02M
            memset_cw(&a->ccoef[0][cbx4], 0x40);
847
1.02M
            memset_cw(&a->ccoef[1][cbx4], 0x40);
848
1.02M
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
849
1.02M
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
850
1.02M
        }
851
1.32M
        return;
852
1.32M
    }
853
854
948k
    Dav1dTileState *const ts = t->ts;
855
948k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
856
948k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
857
948k
    assert(t->frame_thread.pass == 1);
858
948k
    assert(!b->skip);
859
948k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
860
948k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->intra ? b->tx : b->max_ytx];
861
948k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
862
863
1.92M
    for (int init_y = 0; init_y < h4; init_y += 16) {
864
973k
        const int sub_h4 = imin(h4, 16 + init_y);
865
1.99M
        for (int init_x = 0; init_x < w4; init_x += 16) {
866
1.01M
            const int sub_w4 = imin(w4, init_x + 16);
867
1.01M
            int y_off = !!init_y, y, x;
868
2.17M
            for (y = init_y, t->by += init_y; y < sub_h4;
869
1.15M
                 y += t_dim->h, t->by += t_dim->h, y_off++)
870
1.15M
            {
871
1.15M
                int x_off = !!init_x;
872
2.87M
                for (x = init_x, t->bx += init_x; x < sub_w4;
873
1.71M
                     x += t_dim->w, t->bx += t_dim->w, x_off++)
874
1.71M
                {
875
1.71M
                    if (!b->intra) {
876
266k
                        read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
877
266k
                                       x_off, y_off, NULL);
878
1.44M
                    } else {
879
1.44M
                        uint8_t cf_ctx = 0x40;
880
1.44M
                        enum TxfmType txtp;
881
1.44M
                        const int eob =
882
1.44M
                            decode_coefs(t, &t->a->lcoef[bx4 + x],
883
1.44M
                                         &t->l.lcoef[by4 + y], b->tx, bs, b, 1,
884
1.44M
                                         0, ts->frame_thread[1].cf, &txtp, &cf_ctx);
885
1.44M
                        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.44M
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
889
1.44M
                        ts->frame_thread[1].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
890
1.44M
                        dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
891
1.44M
                        dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
892
1.44M
                    }
893
1.71M
                }
894
1.15M
                t->bx -= x;
895
1.15M
            }
896
1.01M
            t->by -= y;
897
898
1.01M
            if (!has_chroma) continue;
899
900
706k
            const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
901
706k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
902
2.11M
            for (int pl = 0; pl < 2; pl++) {
903
2.94M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
904
1.52M
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
905
1.52M
                {
906
3.49M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
907
1.96M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
908
1.96M
                    {
909
1.96M
                        uint8_t cf_ctx = 0x40;
910
1.96M
                        enum TxfmType txtp;
911
1.96M
                        if (!b->intra)
912
295k
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
913
295k
                                                        bx4 + (x << ss_hor)];
914
1.96M
                        const int eob =
915
1.96M
                            decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
916
1.96M
                                         &t->l.ccoef[pl][cby4 + y], b->uvtx, bs,
917
1.96M
                                         b, b->intra, 1 + pl, ts->frame_thread[1].cf,
918
1.96M
                                         &txtp, &cf_ctx);
919
1.96M
                        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.96M
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
924
1.96M
                        ts->frame_thread[1].cf += uv_t_dim->w * uv_t_dim->h * 16;
925
1.96M
                        int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
926
1.96M
                        int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
927
1.96M
                        dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
928
1.96M
                        dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
929
1.96M
                    }
930
1.52M
                    t->bx -= x << ss_hor;
931
1.52M
                }
932
1.41M
                t->by -= y << ss_ver;
933
1.41M
            }
934
706k
        }
935
973k
    }
936
948k
}
dav1d_read_coef_blocks_8bpc
Line
Count
Source
826
928k
{
827
928k
    const Dav1dFrameContext *const f = t->f;
828
928k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
829
928k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
830
928k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
831
928k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
832
928k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
833
928k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
834
928k
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
835
928k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
836
878k
                           (bw4 > ss_hor || t->bx & 1) &&
837
813k
                           (bh4 > ss_ver || t->by & 1);
838
839
928k
    if (b->skip) {
840
510k
        BlockContext *const a = t->a;
841
510k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
842
510k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
843
510k
        if (has_chroma) {
844
405k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
845
405k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
846
405k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
847
405k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
848
405k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
849
405k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
850
405k
        }
851
510k
        return;
852
510k
    }
853
854
418k
    Dav1dTileState *const ts = t->ts;
855
418k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
856
418k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
857
418k
    assert(t->frame_thread.pass == 1);
858
418k
    assert(!b->skip);
859
418k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
860
418k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->intra ? b->tx : b->max_ytx];
861
418k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
862
863
851k
    for (int init_y = 0; init_y < h4; init_y += 16) {
864
432k
        const int sub_h4 = imin(h4, 16 + init_y);
865
888k
        for (int init_x = 0; init_x < w4; init_x += 16) {
866
455k
            const int sub_w4 = imin(w4, init_x + 16);
867
455k
            int y_off = !!init_y, y, x;
868
963k
            for (y = init_y, t->by += init_y; y < sub_h4;
869
507k
                 y += t_dim->h, t->by += t_dim->h, y_off++)
870
507k
            {
871
507k
                int x_off = !!init_x;
872
1.19M
                for (x = init_x, t->bx += init_x; x < sub_w4;
873
687k
                     x += t_dim->w, t->bx += t_dim->w, x_off++)
874
687k
                {
875
687k
                    if (!b->intra) {
876
148k
                        read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
877
148k
                                       x_off, y_off, NULL);
878
538k
                    } else {
879
538k
                        uint8_t cf_ctx = 0x40;
880
538k
                        enum TxfmType txtp;
881
538k
                        const int eob =
882
538k
                            decode_coefs(t, &t->a->lcoef[bx4 + x],
883
538k
                                         &t->l.lcoef[by4 + y], b->tx, bs, b, 1,
884
538k
                                         0, ts->frame_thread[1].cf, &txtp, &cf_ctx);
885
538k
                        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
538k
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
889
538k
                        ts->frame_thread[1].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
890
538k
                        dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
891
538k
                        dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
892
538k
                    }
893
687k
                }
894
507k
                t->bx -= x;
895
507k
            }
896
455k
            t->by -= y;
897
898
455k
            if (!has_chroma) continue;
899
900
373k
            const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
901
373k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
902
1.12M
            for (int pl = 0; pl < 2; pl++) {
903
1.53M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
904
783k
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
905
783k
                {
906
1.66M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
907
878k
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
908
878k
                    {
909
878k
                        uint8_t cf_ctx = 0x40;
910
878k
                        enum TxfmType txtp;
911
878k
                        if (!b->intra)
912
198k
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
913
198k
                                                        bx4 + (x << ss_hor)];
914
878k
                        const int eob =
915
878k
                            decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
916
878k
                                         &t->l.ccoef[pl][cby4 + y], b->uvtx, bs,
917
878k
                                         b, b->intra, 1 + pl, ts->frame_thread[1].cf,
918
878k
                                         &txtp, &cf_ctx);
919
878k
                        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
878k
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
924
878k
                        ts->frame_thread[1].cf += uv_t_dim->w * uv_t_dim->h * 16;
925
878k
                        int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
926
878k
                        int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
927
878k
                        dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
928
878k
                        dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
929
878k
                    }
930
783k
                    t->bx -= x << ss_hor;
931
783k
                }
932
747k
                t->by -= y << ss_ver;
933
747k
            }
934
373k
        }
935
432k
    }
936
418k
}
dav1d_read_coef_blocks_16bpc
Line
Count
Source
826
1.34M
{
827
1.34M
    const Dav1dFrameContext *const f = t->f;
828
1.34M
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
829
1.34M
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
830
1.34M
    const int bx4 = t->bx & 31, by4 = t->by & 31;
831
1.34M
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
832
1.34M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
833
1.34M
    const int bw4 = b_dim[0], bh4 = b_dim[1];
834
1.34M
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
835
1.34M
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
836
1.07M
                           (bw4 > ss_hor || t->bx & 1) &&
837
1.00M
                           (bh4 > ss_ver || t->by & 1);
838
839
1.34M
    if (b->skip) {
840
814k
        BlockContext *const a = t->a;
841
814k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
842
814k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
843
814k
        if (has_chroma) {
844
615k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
845
615k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
846
615k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
847
615k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
848
615k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
849
615k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
850
615k
        }
851
814k
        return;
852
814k
    }
853
854
529k
    Dav1dTileState *const ts = t->ts;
855
529k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
856
529k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
857
529k
    assert(t->frame_thread.pass == 1);
858
529k
    assert(!b->skip);
859
529k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
860
529k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->intra ? b->tx : b->max_ytx];
861
529k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
862
863
1.07M
    for (int init_y = 0; init_y < h4; init_y += 16) {
864
541k
        const int sub_h4 = imin(h4, 16 + init_y);
865
1.10M
        for (int init_x = 0; init_x < w4; init_x += 16) {
866
562k
            const int sub_w4 = imin(w4, init_x + 16);
867
562k
            int y_off = !!init_y, y, x;
868
1.21M
            for (y = init_y, t->by += init_y; y < sub_h4;
869
649k
                 y += t_dim->h, t->by += t_dim->h, y_off++)
870
649k
            {
871
649k
                int x_off = !!init_x;
872
1.67M
                for (x = init_x, t->bx += init_x; x < sub_w4;
873
1.02M
                     x += t_dim->w, t->bx += t_dim->w, x_off++)
874
1.02M
                {
875
1.02M
                    if (!b->intra) {
876
117k
                        read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
877
117k
                                       x_off, y_off, NULL);
878
907k
                    } else {
879
907k
                        uint8_t cf_ctx = 0x40;
880
907k
                        enum TxfmType txtp;
881
907k
                        const int eob =
882
907k
                            decode_coefs(t, &t->a->lcoef[bx4 + x],
883
907k
                                         &t->l.lcoef[by4 + y], b->tx, bs, b, 1,
884
907k
                                         0, ts->frame_thread[1].cf, &txtp, &cf_ctx);
885
907k
                        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
907k
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
889
907k
                        ts->frame_thread[1].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
890
907k
                        dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
891
907k
                        dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
892
907k
                    }
893
1.02M
                }
894
649k
                t->bx -= x;
895
649k
            }
896
562k
            t->by -= y;
897
898
562k
            if (!has_chroma) continue;
899
900
332k
            const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
901
332k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
902
998k
            for (int pl = 0; pl < 2; pl++) {
903
1.41M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
904
745k
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
905
745k
                {
906
1.82M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
907
1.08M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
908
1.08M
                    {
909
1.08M
                        uint8_t cf_ctx = 0x40;
910
1.08M
                        enum TxfmType txtp;
911
1.08M
                        if (!b->intra)
912
96.4k
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
913
96.4k
                                                        bx4 + (x << ss_hor)];
914
1.08M
                        const int eob =
915
1.08M
                            decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
916
1.08M
                                         &t->l.ccoef[pl][cby4 + y], b->uvtx, bs,
917
1.08M
                                         b, b->intra, 1 + pl, ts->frame_thread[1].cf,
918
1.08M
                                         &txtp, &cf_ctx);
919
1.08M
                        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.08M
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
924
1.08M
                        ts->frame_thread[1].cf += uv_t_dim->w * uv_t_dim->h * 16;
925
1.08M
                        int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
926
1.08M
                        int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
927
1.08M
                        dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
928
1.08M
                        dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
929
1.08M
                    }
930
745k
                    t->bx -= x << ss_hor;
931
745k
                }
932
665k
                t->by -= y << ss_ver;
933
665k
            }
934
332k
        }
935
541k
    }
936
529k
}
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
425k
{
945
425k
    assert((dst8 != NULL) ^ (dst16 != NULL));
946
425k
    const Dav1dFrameContext *const f = t->f;
947
425k
    const int ss_ver = !!pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
948
425k
    const int ss_hor = !!pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
949
425k
    const int h_mul = 4 >> ss_hor, v_mul = 4 >> ss_ver;
950
425k
    const int mvx = mv.x, mvy = mv.y;
951
425k
    const int mx = mvx & (15 >> !ss_hor), my = mvy & (15 >> !ss_ver);
952
425k
    ptrdiff_t ref_stride = refp->p.stride[!!pl];
953
425k
    const pixel *ref;
954
955
425k
    if (refp->p.p.w == f->cur.p.w && refp->p.p.h == f->cur.p.h) {
956
293k
        const int dx = bx * h_mul + (mvx >> (3 + ss_hor));
957
293k
        const int dy = by * v_mul + (mvy >> (3 + ss_ver));
958
293k
        int w, h;
959
960
293k
        if (refp->p.data[0] != f->cur.data[0]) { // i.e. not for intrabc
961
82.8k
            w = (f->cur.p.w + ss_hor) >> ss_hor;
962
82.8k
            h = (f->cur.p.h + ss_ver) >> ss_ver;
963
210k
        } else {
964
210k
            w = f->bw * 4 >> ss_hor;
965
210k
            h = f->bh * 4 >> ss_ver;
966
210k
        }
967
293k
        if (dx < !!mx * 3 || dy < !!my * 3 ||
968
263k
            dx + bw4 * h_mul + !!mx * 4 > w ||
969
237k
            dy + bh4 * v_mul + !!my * 4 > h)
970
64.5k
        {
971
64.5k
            pixel *const emu_edge_buf = bitfn(t->scratch.emu_edge);
972
64.5k
            f->dsp->mc.emu_edge(bw4 * h_mul + !!mx * 7, bh4 * v_mul + !!my * 7,
973
64.5k
                                w, h, dx - !!mx * 3, dy - !!my * 3,
974
64.5k
                                emu_edge_buf, 192 * sizeof(pixel),
975
64.5k
                                refp->p.data[pl], ref_stride);
976
64.5k
            ref = &emu_edge_buf[192 * !!my * 3 + !!mx * 3];
977
64.5k
            ref_stride = 192 * sizeof(pixel);
978
228k
        } else {
979
228k
            ref = ((pixel *) refp->p.data[pl]) + PXSTRIDE(ref_stride) * dy + dx;
980
228k
        }
981
982
293k
        if (dst8 != NULL) {
983
271k
            f->dsp->mc.mc[filter_2d](dst8, dst_stride, ref, ref_stride, bw4 * h_mul,
984
271k
                                     bh4 * v_mul, mx << !ss_hor, my << !ss_ver
985
271k
                                     HIGHBD_CALL_SUFFIX);
986
271k
        } else {
987
21.9k
            f->dsp->mc.mct[filter_2d](dst16, ref, ref_stride, bw4 * h_mul,
988
21.9k
                                      bh4 * v_mul, mx << !ss_hor, my << !ss_ver
989
21.9k
                                      HIGHBD_CALL_SUFFIX);
990
21.9k
        }
991
293k
    } else {
992
132k
        assert(refp != &f->sr_cur);
993
994
132k
        const int orig_pos_y = (by * v_mul << 4) + mvy * (1 << !ss_ver);
995
132k
        const int orig_pos_x = (bx * h_mul << 4) + mvx * (1 << !ss_hor);
996
265k
#define scale_mv(res, val, scale) do { \
997
265k
            const int64_t tmp = (int64_t)(val) * scale + (scale - 0x4000) * 8; \
998
265k
            res = apply_sign64((int) ((llabs(tmp) + 128) >> 8), tmp) + 32;     \
999
265k
        } while (0)
1000
132k
        int pos_y, pos_x;
1001
132k
        scale_mv(pos_x, orig_pos_x, f->svc[refidx][0].scale);
1002
132k
        scale_mv(pos_y, orig_pos_y, f->svc[refidx][1].scale);
1003
132k
#undef scale_mv
1004
132k
        const int left = pos_x >> 10;
1005
132k
        const int top = pos_y >> 10;
1006
132k
        const int right =
1007
132k
            ((pos_x + (bw4 * h_mul - 1) * f->svc[refidx][0].step) >> 10) + 1;
1008
132k
        const int bottom =
1009
132k
            ((pos_y + (bh4 * v_mul - 1) * f->svc[refidx][1].step) >> 10) + 1;
1010
1011
132k
        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
132k
        const int w = (refp->p.p.w + ss_hor) >> ss_hor;
1018
132k
        const int h = (refp->p.p.h + ss_ver) >> ss_ver;
1019
132k
        if (left < 3 || top < 3 || right + 4 > w || bottom + 4 > h) {
1020
124k
            pixel *const emu_edge_buf = bitfn(t->scratch.emu_edge);
1021
124k
            f->dsp->mc.emu_edge(right - left + 7, bottom - top + 7,
1022
124k
                                w, h, left - 3, top - 3,
1023
124k
                                emu_edge_buf, 320 * sizeof(pixel),
1024
124k
                                refp->p.data[pl], ref_stride);
1025
124k
            ref = &emu_edge_buf[320 * 3 + 3];
1026
124k
            ref_stride = 320 * sizeof(pixel);
1027
124k
            if (DEBUG_BLOCK_INFO) printf("Emu\n");
1028
124k
        } else {
1029
8.13k
            ref = ((pixel *) refp->p.data[pl]) + PXSTRIDE(ref_stride) * top + left;
1030
8.13k
        }
1031
1032
132k
        if (dst8 != NULL) {
1033
95.4k
            f->dsp->mc.mc_scaled[filter_2d](dst8, dst_stride, ref, ref_stride,
1034
95.4k
                                            bw4 * h_mul, bh4 * v_mul,
1035
95.4k
                                            pos_x & 0x3ff, pos_y & 0x3ff,
1036
95.4k
                                            f->svc[refidx][0].step,
1037
95.4k
                                            f->svc[refidx][1].step
1038
95.4k
                                            HIGHBD_CALL_SUFFIX);
1039
95.4k
        } else {
1040
37.0k
            f->dsp->mc.mct_scaled[filter_2d](dst16, ref, ref_stride,
1041
37.0k
                                             bw4 * h_mul, bh4 * v_mul,
1042
37.0k
                                             pos_x & 0x3ff, pos_y & 0x3ff,
1043
37.0k
                                             f->svc[refidx][0].step,
1044
37.0k
                                             f->svc[refidx][1].step
1045
37.0k
                                             HIGHBD_CALL_SUFFIX);
1046
37.0k
        }
1047
132k
    }
1048
1049
425k
    return 0;
1050
425k
}
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
22.2k
{
1057
22.2k
    assert(!(t->bx & 1) && !(t->by & 1));
1058
22.2k
    const Dav1dFrameContext *const f = t->f;
1059
22.2k
    /*const*/ refmvs_block **r = &t->rt.r[(t->by & 31) + 5];
1060
22.2k
    pixel *const lap = bitfn(t->scratch.lap);
1061
22.2k
    const int ss_ver = !!pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1062
22.2k
    const int ss_hor = !!pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1063
22.2k
    const int h_mul = 4 >> ss_hor, v_mul = 4 >> ss_ver;
1064
22.2k
    int res;
1065
1066
22.2k
    if (t->by > t->ts->tiling.row_start &&
1067
19.2k
        (!pl || b_dim[0] * h_mul + b_dim[1] * v_mul >= 16))
1068
12.0k
    {
1069
25.8k
        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
13.8k
            const refmvs_block *const a_r = &r[-1][t->bx + x + 1];
1072
13.8k
            const uint8_t *const a_b_dim = dav1d_block_dimensions[a_r->bs];
1073
13.8k
            const int step4 = iclip(a_b_dim[0], 2, 16);
1074
1075
13.8k
            if (a_r->ref.ref[0] > 0) {
1076
13.5k
                const int ow4 = imin(step4, b_dim[0]);
1077
13.5k
                const int oh4 = imin(b_dim[1], 16) >> 1;
1078
13.5k
                res = mc(t, lap, NULL, ow4 * h_mul * sizeof(pixel), ow4, (oh4 * 3 + 3) >> 2,
1079
13.5k
                         t->bx + x, t->by, pl, a_r->mv.mv[0],
1080
13.5k
                         &f->refp[a_r->ref.ref[0] - 1], a_r->ref.ref[0] - 1,
1081
13.5k
                         dav1d_filter_2d[t->a->filter[1][bx4 + x + 1]][t->a->filter[0][bx4 + x + 1]]);
1082
13.5k
                if (res) return res;
1083
13.5k
                f->dsp->mc.blend_h(&dst[x * h_mul], dst_stride, lap,
1084
13.5k
                                   h_mul * ow4, v_mul * oh4);
1085
13.5k
                i++;
1086
13.5k
            }
1087
13.8k
            x += step4;
1088
13.8k
        }
1089
12.0k
    }
1090
1091
22.2k
    if (t->bx > t->ts->tiling.col_start)
1092
33.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
17.2k
            const refmvs_block *const l_r = &r[y + 1][t->bx - 1];
1095
17.2k
            const uint8_t *const l_b_dim = dav1d_block_dimensions[l_r->bs];
1096
17.2k
            const int step4 = iclip(l_b_dim[1], 2, 16);
1097
1098
17.2k
            if (l_r->ref.ref[0] > 0) {
1099
17.0k
                const int ow4 = imin(b_dim[0], 16) >> 1;
1100
17.0k
                const int oh4 = imin(step4, b_dim[1]);
1101
17.0k
                res = mc(t, lap, NULL, h_mul * ow4 * sizeof(pixel), ow4, oh4,
1102
17.0k
                         t->bx, t->by + y, pl, l_r->mv.mv[0],
1103
17.0k
                         &f->refp[l_r->ref.ref[0] - 1], l_r->ref.ref[0] - 1,
1104
17.0k
                         dav1d_filter_2d[t->l.filter[1][by4 + y + 1]][t->l.filter[0][by4 + y + 1]]);
1105
17.0k
                if (res) return res;
1106
17.0k
                f->dsp->mc.blend_v(&dst[y * v_mul * PXSTRIDE(dst_stride)],
1107
17.0k
                                   dst_stride, lap, h_mul * ow4, v_mul * oh4);
1108
17.0k
                i++;
1109
17.0k
            }
1110
17.2k
            y += step4;
1111
17.2k
        }
1112
22.2k
    return 0;
1113
22.2k
}
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
9.69k
{
1121
9.69k
    assert((dst8 != NULL) ^ (dst16 != NULL));
1122
9.69k
    const Dav1dFrameContext *const f = t->f;
1123
9.69k
    const Dav1dDSPContext *const dsp = f->dsp;
1124
9.69k
    const int ss_ver = !!pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1125
9.69k
    const int ss_hor = !!pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1126
9.69k
    const int h_mul = 4 >> ss_hor, v_mul = 4 >> ss_ver;
1127
9.69k
    assert(!((b_dim[0] * h_mul) & 7) && !((b_dim[1] * v_mul) & 7));
1128
9.69k
    const int32_t *const mat = wmp->matrix;
1129
9.69k
    const int width = (refp->p.p.w + ss_hor) >> ss_hor;
1130
9.69k
    const int height = (refp->p.p.h + ss_ver) >> ss_ver;
1131
1132
31.0k
    for (int y = 0; y < b_dim[1] * v_mul; y += 8) {
1133
21.3k
        const int src_y = t->by * 4 + ((y + 4) << ss_ver);
1134
21.3k
        const int64_t mat3_y = (int64_t) mat[3] * src_y + mat[0];
1135
21.3k
        const int64_t mat5_y = (int64_t) mat[5] * src_y + mat[1];
1136
73.4k
        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
52.1k
            const int src_x = t->bx * 4 + ((x + 4) << ss_hor);
1140
52.1k
            const int64_t mvx = ((int64_t) mat[2] * src_x + mat3_y) >> ss_hor;
1141
52.1k
            const int64_t mvy = ((int64_t) mat[4] * src_x + mat5_y) >> ss_ver;
1142
1143
52.1k
            const int dx = (int) (mvx >> 16) - 4;
1144
52.1k
            const int mx = (((int) mvx & 0xffff) - wmp->u.p.alpha * 4 -
1145
52.1k
                                                   wmp->u.p.beta  * 7) & ~0x3f;
1146
52.1k
            const int dy = (int) (mvy >> 16) - 4;
1147
52.1k
            const int my = (((int) mvy & 0xffff) - wmp->u.p.gamma * 4 -
1148
52.1k
                                                   wmp->u.p.delta * 4) & ~0x3f;
1149
1150
52.1k
            const pixel *ref_ptr;
1151
52.1k
            ptrdiff_t ref_stride = refp->p.stride[!!pl];
1152
1153
52.1k
            if (dx < 3 || dx + 8 + 4 > width || dy < 3 || dy + 8 + 4 > height) {
1154
24.9k
                pixel *const emu_edge_buf = bitfn(t->scratch.emu_edge);
1155
24.9k
                f->dsp->mc.emu_edge(15, 15, width, height, dx - 3, dy - 3,
1156
24.9k
                                    emu_edge_buf, 32 * sizeof(pixel),
1157
24.9k
                                    refp->p.data[pl], ref_stride);
1158
24.9k
                ref_ptr = &emu_edge_buf[32 * 3 + 3];
1159
24.9k
                ref_stride = 32 * sizeof(pixel);
1160
27.1k
            } else {
1161
27.1k
                ref_ptr = ((pixel *) refp->p.data[pl]) + PXSTRIDE(ref_stride) * dy + dx;
1162
27.1k
            }
1163
52.1k
            if (dst16 != NULL)
1164
6.44k
                dsp->mc.warp8x8t(&dst16[x], dstride, ref_ptr, ref_stride,
1165
6.44k
                                 wmp->u.abcd, mx, my HIGHBD_CALL_SUFFIX);
1166
45.6k
            else
1167
45.6k
                dsp->mc.warp8x8(&dst8[x], dstride, ref_ptr, ref_stride,
1168
45.6k
                                wmp->u.abcd, mx, my HIGHBD_CALL_SUFFIX);
1169
52.1k
        }
1170
21.3k
        if (dst8) dst8  += 8 * PXSTRIDE(dstride);
1171
2.13k
        else      dst16 += 8 * dstride;
1172
21.3k
    }
1173
9.69k
    return 0;
1174
9.69k
}
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.23M
{
1180
1.23M
    Dav1dTileState *const ts = t->ts;
1181
1.23M
    const Dav1dFrameContext *const f = t->f;
1182
1.23M
    const Dav1dDSPContext *const dsp = f->dsp;
1183
1.23M
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1184
1.23M
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1185
1.23M
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1186
1.23M
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1187
1.23M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1188
1.23M
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1189
1.23M
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1190
1.23M
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1191
1.23M
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1192
1.03M
                           (bw4 > ss_hor || t->bx & 1) &&
1193
952k
                           (bh4 > ss_ver || t->by & 1);
1194
1.23M
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->tx];
1195
1.23M
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
1196
1197
    // coefficient coding
1198
1.23M
    pixel *const edge = bitfn(t->scratch.edge) + 128;
1199
1.23M
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
1200
1201
1.23M
    const int intra_edge_filter_flag = f->seq_hdr->intra_edge_filter << 10;
1202
1203
2.50M
    for (int init_y = 0; init_y < h4; init_y += 16) {
1204
1.27M
        const int sub_h4 = imin(h4, 16 + init_y);
1205
1.27M
        const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
1206
2.59M
        for (int init_x = 0; init_x < w4; init_x += 16) {
1207
1.32M
            if (b->pal_sz[0]) {
1208
4.60k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1209
4.60k
                             4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1210
4.60k
                const uint8_t *pal_idx;
1211
4.60k
                if (t->frame_thread.pass) {
1212
4.60k
                    const int p = t->frame_thread.pass & 1;
1213
4.60k
                    assert(ts->frame_thread[p].pal_idx);
1214
4.60k
                    pal_idx = ts->frame_thread[p].pal_idx;
1215
4.60k
                    ts->frame_thread[p].pal_idx += bw4 * bh4 * 8;
1216
4.60k
                } else {
1217
0
                    pal_idx = t->scratch.pal_idx_y;
1218
0
                }
1219
4.60k
                const pixel *const pal = t->frame_thread.pass ?
1220
4.60k
                    f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1221
4.60k
                                        ((t->bx >> 1) + (t->by & 1))][0] :
1222
4.60k
                    bytefn(t->scratch.pal)[0];
1223
4.60k
                f->dsp->ipred.pal_pred(dst, f->cur.stride[0], pal,
1224
4.60k
                                       pal_idx, bw4 * 4, bh4 * 4);
1225
4.60k
                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
4.60k
            }
1229
1230
1.32M
            const int intra_flags = (sm_flag(t->a, bx4) |
1231
1.32M
                                     sm_flag(&t->l, by4) |
1232
1.32M
                                     intra_edge_filter_flag);
1233
1.32M
            const int sb_has_tr = init_x + 16 < w4 ? 1 : init_y ? 0 :
1234
1.27M
                              intra_edge_flags & EDGE_I444_TOP_HAS_RIGHT;
1235
1.32M
            const int sb_has_bl = init_x ? 0 : init_y + 16 < h4 ? 1 :
1236
1.27M
                              intra_edge_flags & EDGE_I444_LEFT_HAS_BOTTOM;
1237
1.32M
            int y, x;
1238
1.32M
            const int sub_w4 = imin(w4, init_x + 16);
1239
2.98M
            for (y = init_y, t->by += init_y; y < sub_h4;
1240
1.65M
                 y += t_dim->h, t->by += t_dim->h)
1241
1.65M
            {
1242
1.65M
                pixel *dst = ((pixel *) f->cur.data[0]) +
1243
1.65M
                               4 * (t->by * PXSTRIDE(f->cur.stride[0]) +
1244
1.65M
                                    t->bx + init_x);
1245
6.04M
                for (x = init_x, t->bx += init_x; x < sub_w4;
1246
4.38M
                     x += t_dim->w, t->bx += t_dim->w)
1247
4.38M
                {
1248
4.38M
                    if (b->pal_sz[0]) goto skip_y_pred;
1249
1250
4.37M
                    int angle = b->y_angle;
1251
4.37M
                    const enum EdgeFlags edge_flags =
1252
4.37M
                        (((y > init_y || !sb_has_tr) && (x + t_dim->w >= sub_w4)) ?
1253
3.55M
                             0 : EDGE_I444_TOP_HAS_RIGHT) |
1254
4.37M
                        ((x > init_x || (!sb_has_bl && y + t_dim->h >= sub_h4)) ?
1255
3.46M
                             0 : EDGE_I444_LEFT_HAS_BOTTOM);
1256
4.37M
                    const pixel *top_sb_edge = NULL;
1257
4.37M
                    if (!(t->by & (f->sb_step - 1))) {
1258
437k
                        top_sb_edge = f->ipred_edge[0];
1259
437k
                        const int sby = t->by >> f->sb_shift;
1260
437k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1261
437k
                    }
1262
4.37M
                    const enum IntraPredMode m =
1263
4.37M
                        bytefn(dav1d_prepare_intra_edges)(t->bx,
1264
4.37M
                                                          t->bx > ts->tiling.col_start,
1265
4.37M
                                                          t->by,
1266
4.37M
                                                          t->by > ts->tiling.row_start,
1267
4.37M
                                                          ts->tiling.col_end,
1268
4.37M
                                                          ts->tiling.row_end,
1269
4.37M
                                                          edge_flags, dst,
1270
4.37M
                                                          f->cur.stride[0], top_sb_edge,
1271
4.37M
                                                          b->y_mode, &angle,
1272
4.37M
                                                          t_dim->w, t_dim->h,
1273
4.37M
                                                          f->seq_hdr->intra_edge_filter,
1274
4.37M
                                                          edge HIGHBD_CALL_SUFFIX);
1275
4.37M
                    dsp->ipred.intra_pred[m](dst, f->cur.stride[0], edge,
1276
4.37M
                                             t_dim->w * 4, t_dim->h * 4,
1277
4.37M
                                             angle | intra_flags,
1278
4.37M
                                             4 * f->bw - 4 * t->bx,
1279
4.37M
                                             4 * f->bh - 4 * t->by
1280
4.37M
                                             HIGHBD_CALL_SUFFIX);
1281
1282
4.37M
                    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
4.38M
                skip_y_pred: {}
1293
4.38M
                    if (!b->skip) {
1294
684k
                        coef *cf;
1295
684k
                        int eob;
1296
684k
                        enum TxfmType txtp;
1297
684k
                        if (t->frame_thread.pass) {
1298
684k
                            const int p = t->frame_thread.pass & 1;
1299
684k
                            const int cbi = *ts->frame_thread[p].cbi++;
1300
684k
                            cf = ts->frame_thread[p].cf;
1301
684k
                            ts->frame_thread[p].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
1302
684k
                            eob  = cbi >> 5;
1303
684k
                            txtp = cbi & 0x1f;
1304
684k
                        } 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
684k
                        if (eob >= 0) {
1317
521k
                            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
521k
                            dsp->itx.itxfm_add[b->tx]
1321
521k
                                              [txtp](dst,
1322
521k
                                                     f->cur.stride[0],
1323
521k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1324
521k
                            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
521k
                        }
1328
3.70M
                    } 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
4.38M
                    dst += 4 * t_dim->w;
1333
4.38M
                }
1334
1.65M
                t->bx -= x;
1335
1.65M
            }
1336
1.32M
            t->by -= y;
1337
1338
1.32M
            if (!has_chroma) continue;
1339
1340
903k
            const ptrdiff_t stride = f->cur.stride[1];
1341
1342
903k
            if (b->uv_mode == CFL_PRED) {
1343
170k
                assert(!init_x && !init_y);
1344
1345
170k
                int16_t *const ac = t->scratch.ac;
1346
170k
                pixel *y_src = ((pixel *) f->cur.data[0]) + 4 * (t->bx & ~ss_hor) +
1347
170k
                                 4 * (t->by & ~ss_ver) * PXSTRIDE(f->cur.stride[0]);
1348
170k
                const ptrdiff_t uv_off = 4 * ((t->bx >> ss_hor) +
1349
170k
                                              (t->by >> ss_ver) * PXSTRIDE(stride));
1350
170k
                pixel *const uv_dst[2] = { ((pixel *) f->cur.data[1]) + uv_off,
1351
170k
                                           ((pixel *) f->cur.data[2]) + uv_off };
1352
1353
170k
                const int furthest_r =
1354
170k
                    ((cw4 << ss_hor) + t_dim->w - 1) & ~(t_dim->w - 1);
1355
170k
                const int furthest_b =
1356
170k
                    ((ch4 << ss_ver) + t_dim->h - 1) & ~(t_dim->h - 1);
1357
170k
                dsp->ipred.cfl_ac[f->cur.p.layout - 1](ac, y_src, f->cur.stride[0],
1358
170k
                                                         cbw4 - (furthest_r >> ss_hor),
1359
170k
                                                         cbh4 - (furthest_b >> ss_ver),
1360
170k
                                                         cbw4 * 4, cbh4 * 4);
1361
510k
                for (int pl = 0; pl < 2; pl++) {
1362
340k
                    if (!b->cfl_alpha[pl]) continue;
1363
260k
                    int angle = 0;
1364
260k
                    const pixel *top_sb_edge = NULL;
1365
260k
                    if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1366
52.3k
                        top_sb_edge = f->ipred_edge[pl + 1];
1367
52.3k
                        const int sby = t->by >> f->sb_shift;
1368
52.3k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1369
52.3k
                    }
1370
260k
                    const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1371
260k
                    const int xstart = ts->tiling.col_start >> ss_hor;
1372
260k
                    const int ystart = ts->tiling.row_start >> ss_ver;
1373
260k
                    const enum IntraPredMode m =
1374
260k
                        bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1375
260k
                                                          ypos, ypos > ystart,
1376
260k
                                                          ts->tiling.col_end >> ss_hor,
1377
260k
                                                          ts->tiling.row_end >> ss_ver,
1378
260k
                                                          0, uv_dst[pl], stride,
1379
260k
                                                          top_sb_edge, DC_PRED, &angle,
1380
260k
                                                          uv_t_dim->w, uv_t_dim->h, 0,
1381
260k
                                                          edge HIGHBD_CALL_SUFFIX);
1382
260k
                    dsp->ipred.cfl_pred[m](uv_dst[pl], stride, edge,
1383
260k
                                           uv_t_dim->w * 4,
1384
260k
                                           uv_t_dim->h * 4,
1385
260k
                                           ac, b->cfl_alpha[pl]
1386
260k
                                           HIGHBD_CALL_SUFFIX);
1387
260k
                }
1388
170k
                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
733k
            } else if (b->pal_sz[1]) {
1394
1.64k
                const ptrdiff_t uv_dstoff = 4 * ((t->bx >> ss_hor) +
1395
1.64k
                                              (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1396
1.64k
                const pixel (*pal)[8];
1397
1.64k
                const uint8_t *pal_idx;
1398
1.64k
                if (t->frame_thread.pass) {
1399
1.64k
                    const int p = t->frame_thread.pass & 1;
1400
1.64k
                    assert(ts->frame_thread[p].pal_idx);
1401
1.64k
                    pal = f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1402
1.64k
                                              ((t->bx >> 1) + (t->by & 1))];
1403
1.64k
                    pal_idx = ts->frame_thread[p].pal_idx;
1404
1.64k
                    ts->frame_thread[p].pal_idx += cbw4 * cbh4 * 8;
1405
1.64k
                } else {
1406
0
                    pal = bytefn(t->scratch.pal);
1407
0
                    pal_idx = t->scratch.pal_idx_uv;
1408
0
                }
1409
1410
1.64k
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[1]) + uv_dstoff,
1411
1.64k
                                       f->cur.stride[1], pal[1],
1412
1.64k
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1413
1.64k
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[2]) + uv_dstoff,
1414
1.64k
                                       f->cur.stride[1], pal[2],
1415
1.64k
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1416
1.64k
                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.64k
            }
1425
1426
903k
            const int sm_uv_fl = sm_uv_flag(t->a, cbx4) |
1427
903k
                                 sm_uv_flag(&t->l, cby4);
1428
903k
            const int uv_sb_has_tr =
1429
903k
                ((init_x + 16) >> ss_hor) < cw4 ? 1 : init_y ? 0 :
1430
876k
                intra_edge_flags & (EDGE_I420_TOP_HAS_RIGHT >> (f->cur.p.layout - 1));
1431
903k
            const int uv_sb_has_bl =
1432
903k
                init_x ? 0 : ((init_y + 16) >> ss_ver) < ch4 ? 1 :
1433
876k
                intra_edge_flags & (EDGE_I420_LEFT_HAS_BOTTOM >> (f->cur.p.layout - 1));
1434
903k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
1435
2.71M
            for (int pl = 0; pl < 2; pl++) {
1436
3.73M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
1437
1.92M
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
1438
1.92M
                {
1439
1.92M
                    pixel *dst = ((pixel *) f->cur.data[1 + pl]) +
1440
1.92M
                                   4 * ((t->by >> ss_ver) * PXSTRIDE(stride) +
1441
1.92M
                                        ((t->bx + init_x) >> ss_hor));
1442
4.10M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
1443
2.17M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
1444
2.17M
                    {
1445
2.17M
                        if ((b->uv_mode == CFL_PRED && b->cfl_alpha[pl]) ||
1446
1.91M
                            b->pal_sz[1])
1447
263k
                        {
1448
263k
                            goto skip_uv_pred;
1449
263k
                        }
1450
1451
1.91M
                        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.91M
                        const enum EdgeFlags edge_flags =
1456
1.91M
                            (((y > (init_y >> ss_ver) || !uv_sb_has_tr) &&
1457
822k
                              (x + uv_t_dim->w >= sub_cw4)) ?
1458
1.27M
                                 0 : EDGE_I444_TOP_HAS_RIGHT) |
1459
1.91M
                            ((x > (init_x >> ss_hor) ||
1460
1.65M
                              (!uv_sb_has_bl && y + uv_t_dim->h >= sub_ch4)) ?
1461
1.14M
                                 0 : EDGE_I444_LEFT_HAS_BOTTOM);
1462
1.91M
                        const pixel *top_sb_edge = NULL;
1463
1.91M
                        if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1464
470k
                            top_sb_edge = f->ipred_edge[1 + pl];
1465
470k
                            const int sby = t->by >> f->sb_shift;
1466
470k
                            top_sb_edge += f->sb128w * 128 * (sby - 1);
1467
470k
                        }
1468
1.91M
                        const enum IntraPredMode uv_mode =
1469
1.91M
                             b->uv_mode == CFL_PRED ? DC_PRED : b->uv_mode;
1470
1.91M
                        const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1471
1.91M
                        const int xstart = ts->tiling.col_start >> ss_hor;
1472
1.91M
                        const int ystart = ts->tiling.row_start >> ss_ver;
1473
1.91M
                        const enum IntraPredMode m =
1474
1.91M
                            bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1475
1.91M
                                                              ypos, ypos > ystart,
1476
1.91M
                                                              ts->tiling.col_end >> ss_hor,
1477
1.91M
                                                              ts->tiling.row_end >> ss_ver,
1478
1.91M
                                                              edge_flags, dst, stride,
1479
1.91M
                                                              top_sb_edge, uv_mode,
1480
1.91M
                                                              &angle, uv_t_dim->w,
1481
1.91M
                                                              uv_t_dim->h,
1482
1.91M
                                                              f->seq_hdr->intra_edge_filter,
1483
1.91M
                                                              edge HIGHBD_CALL_SUFFIX);
1484
1.91M
                        angle |= intra_edge_filter_flag;
1485
1.91M
                        dsp->ipred.intra_pred[m](dst, stride, edge,
1486
1.91M
                                                 uv_t_dim->w * 4,
1487
1.91M
                                                 uv_t_dim->h * 4,
1488
1.91M
                                                 angle | sm_uv_fl,
1489
1.91M
                                                 (4 * f->bw + ss_hor -
1490
1.91M
                                                  4 * (t->bx & ~ss_hor)) >> ss_hor,
1491
1.91M
                                                 (4 * f->bh + ss_ver -
1492
1.91M
                                                  4 * (t->by & ~ss_ver)) >> ss_ver
1493
1.91M
                                                 HIGHBD_CALL_SUFFIX);
1494
1.91M
                        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
2.17M
                    skip_uv_pred: {}
1505
2.17M
                        if (!b->skip) {
1506
648k
                            enum TxfmType txtp;
1507
648k
                            int eob;
1508
648k
                            coef *cf;
1509
648k
                            if (t->frame_thread.pass) {
1510
648k
                                const int p = t->frame_thread.pass & 1;
1511
648k
                                const int cbi = *ts->frame_thread[p].cbi++;
1512
648k
                                cf = ts->frame_thread[p].cf;
1513
648k
                                ts->frame_thread[p].cf += uv_t_dim->w * uv_t_dim->h * 16;
1514
648k
                                eob  = cbi >> 5;
1515
648k
                                txtp = cbi & 0x1f;
1516
648k
                            } 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
648k
                            if (eob >= 0) {
1533
147k
                                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
147k
                                dsp->itx.itxfm_add[b->uvtx]
1537
147k
                                                  [txtp](dst, stride,
1538
147k
                                                         cf, eob HIGHBD_CALL_SUFFIX);
1539
147k
                                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
147k
                            }
1543
1.53M
                        } 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
2.17M
                        dst += uv_t_dim->w * 4;
1548
2.17M
                    }
1549
1.92M
                    t->bx -= x << ss_hor;
1550
1.92M
                }
1551
1.80M
                t->by -= y << ss_ver;
1552
1.80M
            }
1553
903k
        }
1554
1.27M
    }
1555
1.23M
}
dav1d_recon_b_intra_8bpc
Line
Count
Source
1179
437k
{
1180
437k
    Dav1dTileState *const ts = t->ts;
1181
437k
    const Dav1dFrameContext *const f = t->f;
1182
437k
    const Dav1dDSPContext *const dsp = f->dsp;
1183
437k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1184
437k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1185
437k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1186
437k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1187
437k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1188
437k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1189
437k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1190
437k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1191
437k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1192
407k
                           (bw4 > ss_hor || t->bx & 1) &&
1193
379k
                           (bh4 > ss_ver || t->by & 1);
1194
437k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->tx];
1195
437k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
1196
1197
    // coefficient coding
1198
437k
    pixel *const edge = bitfn(t->scratch.edge) + 128;
1199
437k
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
1200
1201
437k
    const int intra_edge_filter_flag = f->seq_hdr->intra_edge_filter << 10;
1202
1203
890k
    for (int init_y = 0; init_y < h4; init_y += 16) {
1204
453k
        const int sub_h4 = imin(h4, 16 + init_y);
1205
453k
        const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
1206
934k
        for (int init_x = 0; init_x < w4; init_x += 16) {
1207
481k
            if (b->pal_sz[0]) {
1208
1.57k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1209
1.57k
                             4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1210
1.57k
                const uint8_t *pal_idx;
1211
1.57k
                if (t->frame_thread.pass) {
1212
1.57k
                    const int p = t->frame_thread.pass & 1;
1213
1.57k
                    assert(ts->frame_thread[p].pal_idx);
1214
1.57k
                    pal_idx = ts->frame_thread[p].pal_idx;
1215
1.57k
                    ts->frame_thread[p].pal_idx += bw4 * bh4 * 8;
1216
1.57k
                } else {
1217
0
                    pal_idx = t->scratch.pal_idx_y;
1218
0
                }
1219
1.57k
                const pixel *const pal = t->frame_thread.pass ?
1220
1.57k
                    f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1221
1.57k
                                        ((t->bx >> 1) + (t->by & 1))][0] :
1222
1.57k
                    bytefn(t->scratch.pal)[0];
1223
1.57k
                f->dsp->ipred.pal_pred(dst, f->cur.stride[0], pal,
1224
1.57k
                                       pal_idx, bw4 * 4, bh4 * 4);
1225
1.57k
                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
1.57k
            }
1229
1230
481k
            const int intra_flags = (sm_flag(t->a, bx4) |
1231
481k
                                     sm_flag(&t->l, by4) |
1232
481k
                                     intra_edge_filter_flag);
1233
481k
            const int sb_has_tr = init_x + 16 < w4 ? 1 : init_y ? 0 :
1234
453k
                              intra_edge_flags & EDGE_I444_TOP_HAS_RIGHT;
1235
481k
            const int sb_has_bl = init_x ? 0 : init_y + 16 < h4 ? 1 :
1236
453k
                              intra_edge_flags & EDGE_I444_LEFT_HAS_BOTTOM;
1237
481k
            int y, x;
1238
481k
            const int sub_w4 = imin(w4, init_x + 16);
1239
1.17M
            for (y = init_y, t->by += init_y; y < sub_h4;
1240
690k
                 y += t_dim->h, t->by += t_dim->h)
1241
690k
            {
1242
690k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1243
690k
                               4 * (t->by * PXSTRIDE(f->cur.stride[0]) +
1244
690k
                                    t->bx + init_x);
1245
3.73M
                for (x = init_x, t->bx += init_x; x < sub_w4;
1246
3.04M
                     x += t_dim->w, t->bx += t_dim->w)
1247
3.04M
                {
1248
3.04M
                    if (b->pal_sz[0]) goto skip_y_pred;
1249
1250
3.04M
                    int angle = b->y_angle;
1251
3.04M
                    const enum EdgeFlags edge_flags =
1252
3.04M
                        (((y > init_y || !sb_has_tr) && (x + t_dim->w >= sub_w4)) ?
1253
2.66M
                             0 : EDGE_I444_TOP_HAS_RIGHT) |
1254
3.04M
                        ((x > init_x || (!sb_has_bl && y + t_dim->h >= sub_h4)) ?
1255
2.62M
                             0 : EDGE_I444_LEFT_HAS_BOTTOM);
1256
3.04M
                    const pixel *top_sb_edge = NULL;
1257
3.04M
                    if (!(t->by & (f->sb_step - 1))) {
1258
207k
                        top_sb_edge = f->ipred_edge[0];
1259
207k
                        const int sby = t->by >> f->sb_shift;
1260
207k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1261
207k
                    }
1262
3.04M
                    const enum IntraPredMode m =
1263
3.04M
                        bytefn(dav1d_prepare_intra_edges)(t->bx,
1264
3.04M
                                                          t->bx > ts->tiling.col_start,
1265
3.04M
                                                          t->by,
1266
3.04M
                                                          t->by > ts->tiling.row_start,
1267
3.04M
                                                          ts->tiling.col_end,
1268
3.04M
                                                          ts->tiling.row_end,
1269
3.04M
                                                          edge_flags, dst,
1270
3.04M
                                                          f->cur.stride[0], top_sb_edge,
1271
3.04M
                                                          b->y_mode, &angle,
1272
3.04M
                                                          t_dim->w, t_dim->h,
1273
3.04M
                                                          f->seq_hdr->intra_edge_filter,
1274
3.04M
                                                          edge HIGHBD_CALL_SUFFIX);
1275
3.04M
                    dsp->ipred.intra_pred[m](dst, f->cur.stride[0], edge,
1276
3.04M
                                             t_dim->w * 4, t_dim->h * 4,
1277
3.04M
                                             angle | intra_flags,
1278
3.04M
                                             4 * f->bw - 4 * t->bx,
1279
3.04M
                                             4 * f->bh - 4 * t->by
1280
3.04M
                                             HIGHBD_CALL_SUFFIX);
1281
1282
3.04M
                    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.04M
                skip_y_pred: {}
1293
3.04M
                    if (!b->skip) {
1294
261k
                        coef *cf;
1295
261k
                        int eob;
1296
261k
                        enum TxfmType txtp;
1297
261k
                        if (t->frame_thread.pass) {
1298
261k
                            const int p = t->frame_thread.pass & 1;
1299
261k
                            const int cbi = *ts->frame_thread[p].cbi++;
1300
261k
                            cf = ts->frame_thread[p].cf;
1301
261k
                            ts->frame_thread[p].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
1302
261k
                            eob  = cbi >> 5;
1303
261k
                            txtp = cbi & 0x1f;
1304
261k
                        } 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
261k
                        if (eob >= 0) {
1317
195k
                            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
195k
                            dsp->itx.itxfm_add[b->tx]
1321
195k
                                              [txtp](dst,
1322
195k
                                                     f->cur.stride[0],
1323
195k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1324
195k
                            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
195k
                        }
1328
2.78M
                    } 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.04M
                    dst += 4 * t_dim->w;
1333
3.04M
                }
1334
690k
                t->bx -= x;
1335
690k
            }
1336
481k
            t->by -= y;
1337
1338
481k
            if (!has_chroma) continue;
1339
1340
371k
            const ptrdiff_t stride = f->cur.stride[1];
1341
1342
371k
            if (b->uv_mode == CFL_PRED) {
1343
64.3k
                assert(!init_x && !init_y);
1344
1345
64.3k
                int16_t *const ac = t->scratch.ac;
1346
64.3k
                pixel *y_src = ((pixel *) f->cur.data[0]) + 4 * (t->bx & ~ss_hor) +
1347
64.3k
                                 4 * (t->by & ~ss_ver) * PXSTRIDE(f->cur.stride[0]);
1348
64.3k
                const ptrdiff_t uv_off = 4 * ((t->bx >> ss_hor) +
1349
64.3k
                                              (t->by >> ss_ver) * PXSTRIDE(stride));
1350
64.3k
                pixel *const uv_dst[2] = { ((pixel *) f->cur.data[1]) + uv_off,
1351
64.3k
                                           ((pixel *) f->cur.data[2]) + uv_off };
1352
1353
64.3k
                const int furthest_r =
1354
64.3k
                    ((cw4 << ss_hor) + t_dim->w - 1) & ~(t_dim->w - 1);
1355
64.3k
                const int furthest_b =
1356
64.3k
                    ((ch4 << ss_ver) + t_dim->h - 1) & ~(t_dim->h - 1);
1357
64.3k
                dsp->ipred.cfl_ac[f->cur.p.layout - 1](ac, y_src, f->cur.stride[0],
1358
64.3k
                                                         cbw4 - (furthest_r >> ss_hor),
1359
64.3k
                                                         cbh4 - (furthest_b >> ss_ver),
1360
64.3k
                                                         cbw4 * 4, cbh4 * 4);
1361
193k
                for (int pl = 0; pl < 2; pl++) {
1362
128k
                    if (!b->cfl_alpha[pl]) continue;
1363
98.3k
                    int angle = 0;
1364
98.3k
                    const pixel *top_sb_edge = NULL;
1365
98.3k
                    if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1366
15.5k
                        top_sb_edge = f->ipred_edge[pl + 1];
1367
15.5k
                        const int sby = t->by >> f->sb_shift;
1368
15.5k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1369
15.5k
                    }
1370
98.3k
                    const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1371
98.3k
                    const int xstart = ts->tiling.col_start >> ss_hor;
1372
98.3k
                    const int ystart = ts->tiling.row_start >> ss_ver;
1373
98.3k
                    const enum IntraPredMode m =
1374
98.3k
                        bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1375
98.3k
                                                          ypos, ypos > ystart,
1376
98.3k
                                                          ts->tiling.col_end >> ss_hor,
1377
98.3k
                                                          ts->tiling.row_end >> ss_ver,
1378
98.3k
                                                          0, uv_dst[pl], stride,
1379
98.3k
                                                          top_sb_edge, DC_PRED, &angle,
1380
98.3k
                                                          uv_t_dim->w, uv_t_dim->h, 0,
1381
98.3k
                                                          edge HIGHBD_CALL_SUFFIX);
1382
98.3k
                    dsp->ipred.cfl_pred[m](uv_dst[pl], stride, edge,
1383
98.3k
                                           uv_t_dim->w * 4,
1384
98.3k
                                           uv_t_dim->h * 4,
1385
98.3k
                                           ac, b->cfl_alpha[pl]
1386
98.3k
                                           HIGHBD_CALL_SUFFIX);
1387
98.3k
                }
1388
64.3k
                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
307k
            } else if (b->pal_sz[1]) {
1394
905
                const ptrdiff_t uv_dstoff = 4 * ((t->bx >> ss_hor) +
1395
905
                                              (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1396
905
                const pixel (*pal)[8];
1397
905
                const uint8_t *pal_idx;
1398
905
                if (t->frame_thread.pass) {
1399
905
                    const int p = t->frame_thread.pass & 1;
1400
905
                    assert(ts->frame_thread[p].pal_idx);
1401
905
                    pal = f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1402
905
                                              ((t->bx >> 1) + (t->by & 1))];
1403
905
                    pal_idx = ts->frame_thread[p].pal_idx;
1404
905
                    ts->frame_thread[p].pal_idx += cbw4 * cbh4 * 8;
1405
905
                } else {
1406
0
                    pal = bytefn(t->scratch.pal);
1407
0
                    pal_idx = t->scratch.pal_idx_uv;
1408
0
                }
1409
1410
905
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[1]) + uv_dstoff,
1411
905
                                       f->cur.stride[1], pal[1],
1412
905
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1413
905
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[2]) + uv_dstoff,
1414
905
                                       f->cur.stride[1], pal[2],
1415
905
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1416
905
                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
905
            }
1425
1426
371k
            const int sm_uv_fl = sm_uv_flag(t->a, cbx4) |
1427
371k
                                 sm_uv_flag(&t->l, cby4);
1428
371k
            const int uv_sb_has_tr =
1429
371k
                ((init_x + 16) >> ss_hor) < cw4 ? 1 : init_y ? 0 :
1430
355k
                intra_edge_flags & (EDGE_I420_TOP_HAS_RIGHT >> (f->cur.p.layout - 1));
1431
371k
            const int uv_sb_has_bl =
1432
371k
                init_x ? 0 : ((init_y + 16) >> ss_ver) < ch4 ? 1 :
1433
355k
                intra_edge_flags & (EDGE_I420_LEFT_HAS_BOTTOM >> (f->cur.p.layout - 1));
1434
371k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
1435
1.11M
            for (int pl = 0; pl < 2; pl++) {
1436
1.54M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
1437
796k
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
1438
796k
                {
1439
796k
                    pixel *dst = ((pixel *) f->cur.data[1 + pl]) +
1440
796k
                                   4 * ((t->by >> ss_ver) * PXSTRIDE(stride) +
1441
796k
                                        ((t->bx + init_x) >> ss_hor));
1442
1.70M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
1443
906k
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
1444
906k
                    {
1445
906k
                        if ((b->uv_mode == CFL_PRED && b->cfl_alpha[pl]) ||
1446
808k
                            b->pal_sz[1])
1447
100k
                        {
1448
100k
                            goto skip_uv_pred;
1449
100k
                        }
1450
1451
806k
                        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
806k
                        const enum EdgeFlags edge_flags =
1456
806k
                            (((y > (init_y >> ss_ver) || !uv_sb_has_tr) &&
1457
341k
                              (x + uv_t_dim->w >= sub_cw4)) ?
1458
536k
                                 0 : EDGE_I444_TOP_HAS_RIGHT) |
1459
806k
                            ((x > (init_x >> ss_hor) ||
1460
696k
                              (!uv_sb_has_bl && y + uv_t_dim->h >= sub_ch4)) ?
1461
482k
                                 0 : EDGE_I444_LEFT_HAS_BOTTOM);
1462
806k
                        const pixel *top_sb_edge = NULL;
1463
806k
                        if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1464
198k
                            top_sb_edge = f->ipred_edge[1 + pl];
1465
198k
                            const int sby = t->by >> f->sb_shift;
1466
198k
                            top_sb_edge += f->sb128w * 128 * (sby - 1);
1467
198k
                        }
1468
806k
                        const enum IntraPredMode uv_mode =
1469
806k
                             b->uv_mode == CFL_PRED ? DC_PRED : b->uv_mode;
1470
806k
                        const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1471
806k
                        const int xstart = ts->tiling.col_start >> ss_hor;
1472
806k
                        const int ystart = ts->tiling.row_start >> ss_ver;
1473
806k
                        const enum IntraPredMode m =
1474
806k
                            bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1475
806k
                                                              ypos, ypos > ystart,
1476
806k
                                                              ts->tiling.col_end >> ss_hor,
1477
806k
                                                              ts->tiling.row_end >> ss_ver,
1478
806k
                                                              edge_flags, dst, stride,
1479
806k
                                                              top_sb_edge, uv_mode,
1480
806k
                                                              &angle, uv_t_dim->w,
1481
806k
                                                              uv_t_dim->h,
1482
806k
                                                              f->seq_hdr->intra_edge_filter,
1483
806k
                                                              edge HIGHBD_CALL_SUFFIX);
1484
806k
                        angle |= intra_edge_filter_flag;
1485
806k
                        dsp->ipred.intra_pred[m](dst, stride, edge,
1486
806k
                                                 uv_t_dim->w * 4,
1487
806k
                                                 uv_t_dim->h * 4,
1488
806k
                                                 angle | sm_uv_fl,
1489
806k
                                                 (4 * f->bw + ss_hor -
1490
806k
                                                  4 * (t->bx & ~ss_hor)) >> ss_hor,
1491
806k
                                                 (4 * f->bh + ss_ver -
1492
806k
                                                  4 * (t->by & ~ss_ver)) >> ss_ver
1493
806k
                                                 HIGHBD_CALL_SUFFIX);
1494
806k
                        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
906k
                    skip_uv_pred: {}
1505
906k
                        if (!b->skip) {
1506
335k
                            enum TxfmType txtp;
1507
335k
                            int eob;
1508
335k
                            coef *cf;
1509
335k
                            if (t->frame_thread.pass) {
1510
335k
                                const int p = t->frame_thread.pass & 1;
1511
335k
                                const int cbi = *ts->frame_thread[p].cbi++;
1512
335k
                                cf = ts->frame_thread[p].cf;
1513
335k
                                ts->frame_thread[p].cf += uv_t_dim->w * uv_t_dim->h * 16;
1514
335k
                                eob  = cbi >> 5;
1515
335k
                                txtp = cbi & 0x1f;
1516
335k
                            } 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
335k
                            if (eob >= 0) {
1533
83.1k
                                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
83.1k
                                dsp->itx.itxfm_add[b->uvtx]
1537
83.1k
                                                  [txtp](dst, stride,
1538
83.1k
                                                         cf, eob HIGHBD_CALL_SUFFIX);
1539
83.1k
                                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
83.1k
                            }
1543
571k
                        } 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
906k
                        dst += uv_t_dim->w * 4;
1548
906k
                    }
1549
796k
                    t->bx -= x << ss_hor;
1550
796k
                }
1551
743k
                t->by -= y << ss_ver;
1552
743k
            }
1553
371k
        }
1554
453k
    }
1555
437k
}
dav1d_recon_b_intra_16bpc
Line
Count
Source
1179
798k
{
1180
798k
    Dav1dTileState *const ts = t->ts;
1181
798k
    const Dav1dFrameContext *const f = t->f;
1182
798k
    const Dav1dDSPContext *const dsp = f->dsp;
1183
798k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1184
798k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1185
798k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1186
798k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1187
798k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1188
798k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1189
798k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1190
798k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1191
798k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1192
625k
                           (bw4 > ss_hor || t->bx & 1) &&
1193
573k
                           (bh4 > ss_ver || t->by & 1);
1194
798k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->tx];
1195
798k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
1196
1197
    // coefficient coding
1198
798k
    pixel *const edge = bitfn(t->scratch.edge) + 128;
1199
798k
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
1200
1201
798k
    const int intra_edge_filter_flag = f->seq_hdr->intra_edge_filter << 10;
1202
1203
1.61M
    for (int init_y = 0; init_y < h4; init_y += 16) {
1204
817k
        const int sub_h4 = imin(h4, 16 + init_y);
1205
817k
        const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
1206
1.66M
        for (int init_x = 0; init_x < w4; init_x += 16) {
1207
846k
            if (b->pal_sz[0]) {
1208
3.03k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1209
3.03k
                             4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1210
3.03k
                const uint8_t *pal_idx;
1211
3.03k
                if (t->frame_thread.pass) {
1212
3.03k
                    const int p = t->frame_thread.pass & 1;
1213
3.03k
                    assert(ts->frame_thread[p].pal_idx);
1214
3.03k
                    pal_idx = ts->frame_thread[p].pal_idx;
1215
3.03k
                    ts->frame_thread[p].pal_idx += bw4 * bh4 * 8;
1216
3.03k
                } else {
1217
0
                    pal_idx = t->scratch.pal_idx_y;
1218
0
                }
1219
3.03k
                const pixel *const pal = t->frame_thread.pass ?
1220
3.03k
                    f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1221
3.03k
                                        ((t->bx >> 1) + (t->by & 1))][0] :
1222
3.03k
                    bytefn(t->scratch.pal)[0];
1223
3.03k
                f->dsp->ipred.pal_pred(dst, f->cur.stride[0], pal,
1224
3.03k
                                       pal_idx, bw4 * 4, bh4 * 4);
1225
3.03k
                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
3.03k
            }
1229
1230
846k
            const int intra_flags = (sm_flag(t->a, bx4) |
1231
846k
                                     sm_flag(&t->l, by4) |
1232
846k
                                     intra_edge_filter_flag);
1233
846k
            const int sb_has_tr = init_x + 16 < w4 ? 1 : init_y ? 0 :
1234
817k
                              intra_edge_flags & EDGE_I444_TOP_HAS_RIGHT;
1235
846k
            const int sb_has_bl = init_x ? 0 : init_y + 16 < h4 ? 1 :
1236
817k
                              intra_edge_flags & EDGE_I444_LEFT_HAS_BOTTOM;
1237
846k
            int y, x;
1238
846k
            const int sub_w4 = imin(w4, init_x + 16);
1239
1.81M
            for (y = init_y, t->by += init_y; y < sub_h4;
1240
968k
                 y += t_dim->h, t->by += t_dim->h)
1241
968k
            {
1242
968k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1243
968k
                               4 * (t->by * PXSTRIDE(f->cur.stride[0]) +
1244
968k
                                    t->bx + init_x);
1245
2.30M
                for (x = init_x, t->bx += init_x; x < sub_w4;
1246
1.34M
                     x += t_dim->w, t->bx += t_dim->w)
1247
1.34M
                {
1248
1.34M
                    if (b->pal_sz[0]) goto skip_y_pred;
1249
1250
1.33M
                    int angle = b->y_angle;
1251
1.33M
                    const enum EdgeFlags edge_flags =
1252
1.33M
                        (((y > init_y || !sb_has_tr) && (x + t_dim->w >= sub_w4)) ?
1253
891k
                             0 : EDGE_I444_TOP_HAS_RIGHT) |
1254
1.33M
                        ((x > init_x || (!sb_has_bl && y + t_dim->h >= sub_h4)) ?
1255
836k
                             0 : EDGE_I444_LEFT_HAS_BOTTOM);
1256
1.33M
                    const pixel *top_sb_edge = NULL;
1257
1.33M
                    if (!(t->by & (f->sb_step - 1))) {
1258
229k
                        top_sb_edge = f->ipred_edge[0];
1259
229k
                        const int sby = t->by >> f->sb_shift;
1260
229k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1261
229k
                    }
1262
1.33M
                    const enum IntraPredMode m =
1263
1.33M
                        bytefn(dav1d_prepare_intra_edges)(t->bx,
1264
1.33M
                                                          t->bx > ts->tiling.col_start,
1265
1.33M
                                                          t->by,
1266
1.33M
                                                          t->by > ts->tiling.row_start,
1267
1.33M
                                                          ts->tiling.col_end,
1268
1.33M
                                                          ts->tiling.row_end,
1269
1.33M
                                                          edge_flags, dst,
1270
1.33M
                                                          f->cur.stride[0], top_sb_edge,
1271
1.33M
                                                          b->y_mode, &angle,
1272
1.33M
                                                          t_dim->w, t_dim->h,
1273
1.33M
                                                          f->seq_hdr->intra_edge_filter,
1274
1.33M
                                                          edge HIGHBD_CALL_SUFFIX);
1275
1.33M
                    dsp->ipred.intra_pred[m](dst, f->cur.stride[0], edge,
1276
1.33M
                                             t_dim->w * 4, t_dim->h * 4,
1277
1.33M
                                             angle | intra_flags,
1278
1.33M
                                             4 * f->bw - 4 * t->bx,
1279
1.33M
                                             4 * f->bh - 4 * t->by
1280
1.33M
                                             HIGHBD_CALL_SUFFIX);
1281
1282
1.33M
                    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.34M
                skip_y_pred: {}
1293
1.34M
                    if (!b->skip) {
1294
422k
                        coef *cf;
1295
422k
                        int eob;
1296
422k
                        enum TxfmType txtp;
1297
422k
                        if (t->frame_thread.pass) {
1298
422k
                            const int p = t->frame_thread.pass & 1;
1299
422k
                            const int cbi = *ts->frame_thread[p].cbi++;
1300
422k
                            cf = ts->frame_thread[p].cf;
1301
422k
                            ts->frame_thread[p].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
1302
422k
                            eob  = cbi >> 5;
1303
422k
                            txtp = cbi & 0x1f;
1304
422k
                        } 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
422k
                        if (eob >= 0) {
1317
326k
                            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
326k
                            dsp->itx.itxfm_add[b->tx]
1321
326k
                                              [txtp](dst,
1322
326k
                                                     f->cur.stride[0],
1323
326k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1324
326k
                            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
326k
                        }
1328
918k
                    } 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.34M
                    dst += 4 * t_dim->w;
1333
1.34M
                }
1334
968k
                t->bx -= x;
1335
968k
            }
1336
846k
            t->by -= y;
1337
1338
846k
            if (!has_chroma) continue;
1339
1340
532k
            const ptrdiff_t stride = f->cur.stride[1];
1341
1342
532k
            if (b->uv_mode == CFL_PRED) {
1343
105k
                assert(!init_x && !init_y);
1344
1345
105k
                int16_t *const ac = t->scratch.ac;
1346
105k
                pixel *y_src = ((pixel *) f->cur.data[0]) + 4 * (t->bx & ~ss_hor) +
1347
105k
                                 4 * (t->by & ~ss_ver) * PXSTRIDE(f->cur.stride[0]);
1348
105k
                const ptrdiff_t uv_off = 4 * ((t->bx >> ss_hor) +
1349
105k
                                              (t->by >> ss_ver) * PXSTRIDE(stride));
1350
105k
                pixel *const uv_dst[2] = { ((pixel *) f->cur.data[1]) + uv_off,
1351
105k
                                           ((pixel *) f->cur.data[2]) + uv_off };
1352
1353
105k
                const int furthest_r =
1354
105k
                    ((cw4 << ss_hor) + t_dim->w - 1) & ~(t_dim->w - 1);
1355
105k
                const int furthest_b =
1356
105k
                    ((ch4 << ss_ver) + t_dim->h - 1) & ~(t_dim->h - 1);
1357
105k
                dsp->ipred.cfl_ac[f->cur.p.layout - 1](ac, y_src, f->cur.stride[0],
1358
105k
                                                         cbw4 - (furthest_r >> ss_hor),
1359
105k
                                                         cbh4 - (furthest_b >> ss_ver),
1360
105k
                                                         cbw4 * 4, cbh4 * 4);
1361
317k
                for (int pl = 0; pl < 2; pl++) {
1362
211k
                    if (!b->cfl_alpha[pl]) continue;
1363
162k
                    int angle = 0;
1364
162k
                    const pixel *top_sb_edge = NULL;
1365
162k
                    if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1366
36.8k
                        top_sb_edge = f->ipred_edge[pl + 1];
1367
36.8k
                        const int sby = t->by >> f->sb_shift;
1368
36.8k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1369
36.8k
                    }
1370
162k
                    const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1371
162k
                    const int xstart = ts->tiling.col_start >> ss_hor;
1372
162k
                    const int ystart = ts->tiling.row_start >> ss_ver;
1373
162k
                    const enum IntraPredMode m =
1374
162k
                        bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1375
162k
                                                          ypos, ypos > ystart,
1376
162k
                                                          ts->tiling.col_end >> ss_hor,
1377
162k
                                                          ts->tiling.row_end >> ss_ver,
1378
162k
                                                          0, uv_dst[pl], stride,
1379
162k
                                                          top_sb_edge, DC_PRED, &angle,
1380
162k
                                                          uv_t_dim->w, uv_t_dim->h, 0,
1381
162k
                                                          edge HIGHBD_CALL_SUFFIX);
1382
162k
                    dsp->ipred.cfl_pred[m](uv_dst[pl], stride, edge,
1383
162k
                                           uv_t_dim->w * 4,
1384
162k
                                           uv_t_dim->h * 4,
1385
162k
                                           ac, b->cfl_alpha[pl]
1386
162k
                                           HIGHBD_CALL_SUFFIX);
1387
162k
                }
1388
105k
                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
426k
            } else if (b->pal_sz[1]) {
1394
738
                const ptrdiff_t uv_dstoff = 4 * ((t->bx >> ss_hor) +
1395
738
                                              (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1396
738
                const pixel (*pal)[8];
1397
738
                const uint8_t *pal_idx;
1398
738
                if (t->frame_thread.pass) {
1399
738
                    const int p = t->frame_thread.pass & 1;
1400
738
                    assert(ts->frame_thread[p].pal_idx);
1401
738
                    pal = f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1402
738
                                              ((t->bx >> 1) + (t->by & 1))];
1403
738
                    pal_idx = ts->frame_thread[p].pal_idx;
1404
738
                    ts->frame_thread[p].pal_idx += cbw4 * cbh4 * 8;
1405
738
                } else {
1406
0
                    pal = bytefn(t->scratch.pal);
1407
0
                    pal_idx = t->scratch.pal_idx_uv;
1408
0
                }
1409
1410
738
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[1]) + uv_dstoff,
1411
738
                                       f->cur.stride[1], pal[1],
1412
738
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1413
738
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[2]) + uv_dstoff,
1414
738
                                       f->cur.stride[1], pal[2],
1415
738
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1416
738
                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
738
            }
1425
1426
532k
            const int sm_uv_fl = sm_uv_flag(t->a, cbx4) |
1427
532k
                                 sm_uv_flag(&t->l, cby4);
1428
532k
            const int uv_sb_has_tr =
1429
532k
                ((init_x + 16) >> ss_hor) < cw4 ? 1 : init_y ? 0 :
1430
520k
                intra_edge_flags & (EDGE_I420_TOP_HAS_RIGHT >> (f->cur.p.layout - 1));
1431
532k
            const int uv_sb_has_bl =
1432
532k
                init_x ? 0 : ((init_y + 16) >> ss_ver) < ch4 ? 1 :
1433
520k
                intra_edge_flags & (EDGE_I420_LEFT_HAS_BOTTOM >> (f->cur.p.layout - 1));
1434
532k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
1435
1.59M
            for (int pl = 0; pl < 2; pl++) {
1436
2.19M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
1437
1.12M
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
1438
1.12M
                {
1439
1.12M
                    pixel *dst = ((pixel *) f->cur.data[1 + pl]) +
1440
1.12M
                                   4 * ((t->by >> ss_ver) * PXSTRIDE(stride) +
1441
1.12M
                                        ((t->bx + init_x) >> ss_hor));
1442
2.39M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
1443
1.27M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
1444
1.27M
                    {
1445
1.27M
                        if ((b->uv_mode == CFL_PRED && b->cfl_alpha[pl]) ||
1446
1.11M
                            b->pal_sz[1])
1447
163k
                        {
1448
163k
                            goto skip_uv_pred;
1449
163k
                        }
1450
1451
1.10M
                        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.10M
                        const enum EdgeFlags edge_flags =
1456
1.10M
                            (((y > (init_y >> ss_ver) || !uv_sb_has_tr) &&
1457
481k
                              (x + uv_t_dim->w >= sub_cw4)) ?
1458
734k
                                 0 : EDGE_I444_TOP_HAS_RIGHT) |
1459
1.10M
                            ((x > (init_x >> ss_hor) ||
1460
962k
                              (!uv_sb_has_bl && y + uv_t_dim->h >= sub_ch4)) ?
1461
660k
                                 0 : EDGE_I444_LEFT_HAS_BOTTOM);
1462
1.10M
                        const pixel *top_sb_edge = NULL;
1463
1.10M
                        if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1464
271k
                            top_sb_edge = f->ipred_edge[1 + pl];
1465
271k
                            const int sby = t->by >> f->sb_shift;
1466
271k
                            top_sb_edge += f->sb128w * 128 * (sby - 1);
1467
271k
                        }
1468
1.10M
                        const enum IntraPredMode uv_mode =
1469
1.10M
                             b->uv_mode == CFL_PRED ? DC_PRED : b->uv_mode;
1470
1.10M
                        const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1471
1.10M
                        const int xstart = ts->tiling.col_start >> ss_hor;
1472
1.10M
                        const int ystart = ts->tiling.row_start >> ss_ver;
1473
1.10M
                        const enum IntraPredMode m =
1474
1.10M
                            bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1475
1.10M
                                                              ypos, ypos > ystart,
1476
1.10M
                                                              ts->tiling.col_end >> ss_hor,
1477
1.10M
                                                              ts->tiling.row_end >> ss_ver,
1478
1.10M
                                                              edge_flags, dst, stride,
1479
1.10M
                                                              top_sb_edge, uv_mode,
1480
1.10M
                                                              &angle, uv_t_dim->w,
1481
1.10M
                                                              uv_t_dim->h,
1482
1.10M
                                                              f->seq_hdr->intra_edge_filter,
1483
1.10M
                                                              edge HIGHBD_CALL_SUFFIX);
1484
1.10M
                        angle |= intra_edge_filter_flag;
1485
1.10M
                        dsp->ipred.intra_pred[m](dst, stride, edge,
1486
1.10M
                                                 uv_t_dim->w * 4,
1487
1.10M
                                                 uv_t_dim->h * 4,
1488
1.10M
                                                 angle | sm_uv_fl,
1489
1.10M
                                                 (4 * f->bw + ss_hor -
1490
1.10M
                                                  4 * (t->bx & ~ss_hor)) >> ss_hor,
1491
1.10M
                                                 (4 * f->bh + ss_ver -
1492
1.10M
                                                  4 * (t->by & ~ss_ver)) >> ss_ver
1493
1.10M
                                                 HIGHBD_CALL_SUFFIX);
1494
1.10M
                        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.27M
                    skip_uv_pred: {}
1505
1.27M
                        if (!b->skip) {
1506
313k
                            enum TxfmType txtp;
1507
313k
                            int eob;
1508
313k
                            coef *cf;
1509
313k
                            if (t->frame_thread.pass) {
1510
313k
                                const int p = t->frame_thread.pass & 1;
1511
313k
                                const int cbi = *ts->frame_thread[p].cbi++;
1512
313k
                                cf = ts->frame_thread[p].cf;
1513
313k
                                ts->frame_thread[p].cf += uv_t_dim->w * uv_t_dim->h * 16;
1514
313k
                                eob  = cbi >> 5;
1515
313k
                                txtp = cbi & 0x1f;
1516
313k
                            } 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
313k
                            if (eob >= 0) {
1533
64.3k
                                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
64.3k
                                dsp->itx.itxfm_add[b->uvtx]
1537
64.3k
                                                  [txtp](dst, stride,
1538
64.3k
                                                         cf, eob HIGHBD_CALL_SUFFIX);
1539
64.3k
                                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
64.3k
                            }
1543
959k
                        } 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.27M
                        dst += uv_t_dim->w * 4;
1548
1.27M
                    }
1549
1.12M
                    t->bx -= x << ss_hor;
1550
1.12M
                }
1551
1.06M
                t->by -= y << ss_ver;
1552
1.06M
            }
1553
532k
        }
1554
817k
    }
1555
798k
}
1556
1557
int bytefn(dav1d_recon_b_inter)(Dav1dTaskContext *const t, const enum BlockSize bs,
1558
                                const Av1Block *const b)
1559
167k
{
1560
167k
    Dav1dTileState *const ts = t->ts;
1561
167k
    const Dav1dFrameContext *const f = t->f;
1562
167k
    const Dav1dDSPContext *const dsp = f->dsp;
1563
167k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1564
167k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1565
167k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1566
167k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1567
167k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1568
167k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1569
167k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1570
167k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1571
113k
                           (bw4 > ss_hor || t->bx & 1) &&
1572
103k
                           (bh4 > ss_ver || t->by & 1);
1573
167k
    const int chr_layout_idx = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I400 ? 0 :
1574
167k
                               DAV1D_PIXEL_LAYOUT_I444 - f->cur.p.layout;
1575
167k
    int res;
1576
1577
    // prediction
1578
167k
    const int cbh4 = (bh4 + ss_ver) >> ss_ver, cbw4 = (bw4 + ss_hor) >> ss_hor;
1579
167k
    pixel *dst = ((pixel *) f->cur.data[0]) +
1580
167k
        4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1581
167k
    const ptrdiff_t uvdstoff =
1582
167k
        4 * ((t->bx >> ss_hor) + (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1583
167k
    if (IS_KEY_OR_INTRA(f->frame_hdr)) {
1584
        // intrabc
1585
106k
        assert(!f->frame_hdr->super_res.enabled);
1586
106k
        res = mc(t, dst, NULL, f->cur.stride[0], bw4, bh4, t->bx, t->by, 0,
1587
106k
                 b->mv[0], &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1588
106k
        if (res) return res;
1589
155k
        if (has_chroma) for (int pl = 1; pl < 3; pl++) {
1590
103k
            res = mc(t, ((pixel *)f->cur.data[pl]) + uvdstoff, NULL, f->cur.stride[1],
1591
103k
                     bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1592
103k
                     t->bx & ~ss_hor, t->by & ~ss_ver, pl, b->mv[0],
1593
103k
                     &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1594
103k
            if (res) return res;
1595
103k
        }
1596
106k
    } else if (b->comp_type == COMP_INTER_NONE) {
1597
48.9k
        const Dav1dThreadPicture *const refp = &f->refp[b->ref[0]];
1598
48.9k
        const enum Filter2d filter_2d = b->filter2d;
1599
1600
48.9k
        if (imin(bw4, bh4) > 1 &&
1601
27.7k
            ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1602
23.5k
             (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1603
4.72k
        {
1604
4.72k
            res = warp_affine(t, dst, NULL, f->cur.stride[0], b_dim, 0, refp,
1605
4.72k
                              b->motion_mode == MM_WARP ? &t->warpmv :
1606
4.72k
                                  &f->frame_hdr->gmv[b->ref[0]]);
1607
4.72k
            if (res) return res;
1608
44.2k
        } else {
1609
44.2k
            res = mc(t, dst, NULL, f->cur.stride[0],
1610
44.2k
                     bw4, bh4, t->bx, t->by, 0, b->mv[0], refp, b->ref[0], filter_2d);
1611
44.2k
            if (res) return res;
1612
44.2k
            if (b->motion_mode == MM_OBMC) {
1613
8.19k
                res = obmc(t, dst, f->cur.stride[0], b_dim, 0, bx4, by4, w4, h4);
1614
8.19k
                if (res) return res;
1615
8.19k
            }
1616
44.2k
        }
1617
48.9k
        if (b->interintra_type) {
1618
3.39k
            pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1619
3.39k
            enum IntraPredMode m = b->interintra_mode == II_SMOOTH_PRED ?
1620
2.79k
                                   SMOOTH_PRED : b->interintra_mode;
1621
3.39k
            pixel *const tmp = bitfn(t->scratch.interintra);
1622
3.39k
            int angle = 0;
1623
3.39k
            const pixel *top_sb_edge = NULL;
1624
3.39k
            if (!(t->by & (f->sb_step - 1))) {
1625
824
                top_sb_edge = f->ipred_edge[0];
1626
824
                const int sby = t->by >> f->sb_shift;
1627
824
                top_sb_edge += f->sb128w * 128 * (sby - 1);
1628
824
            }
1629
3.39k
            m = bytefn(dav1d_prepare_intra_edges)(t->bx, t->bx > ts->tiling.col_start,
1630
3.39k
                                                  t->by, t->by > ts->tiling.row_start,
1631
3.39k
                                                  ts->tiling.col_end, ts->tiling.row_end,
1632
3.39k
                                                  0, dst, f->cur.stride[0], top_sb_edge,
1633
3.39k
                                                  m, &angle, bw4, bh4, 0, tl_edge
1634
3.39k
                                                  HIGHBD_CALL_SUFFIX);
1635
3.39k
            dsp->ipred.intra_pred[m](tmp, 4 * bw4 * sizeof(pixel),
1636
3.39k
                                     tl_edge, bw4 * 4, bh4 * 4, 0, 0, 0
1637
3.39k
                                     HIGHBD_CALL_SUFFIX);
1638
3.39k
            dsp->mc.blend(dst, f->cur.stride[0], tmp,
1639
3.39k
                          bw4 * 4, bh4 * 4, II_MASK(0, bs, b));
1640
3.39k
        }
1641
1642
48.9k
        if (!has_chroma) goto skip_inter_chroma_pred;
1643
1644
        // sub8x8 derivation
1645
33.6k
        int is_sub8x8 = bw4 == ss_hor || bh4 == ss_ver;
1646
33.6k
        refmvs_block *const *r;
1647
33.6k
        if (is_sub8x8) {
1648
6.44k
            assert(ss_hor == 1);
1649
6.44k
            r = &t->rt.r[(t->by & 31) + 5];
1650
6.44k
            if (bw4 == 1) is_sub8x8 &= r[0][t->bx - 1].ref.ref[0] > 0;
1651
6.44k
            if (bh4 == ss_ver) is_sub8x8 &= r[-1][t->bx].ref.ref[0] > 0;
1652
6.44k
            if (bw4 == 1 && bh4 == ss_ver)
1653
1.42k
                is_sub8x8 &= r[-1][t->bx - 1].ref.ref[0] > 0;
1654
6.44k
        }
1655
1656
        // chroma prediction
1657
33.6k
        if (is_sub8x8) {
1658
6.37k
            assert(ss_hor == 1);
1659
6.37k
            ptrdiff_t h_off = 0, v_off = 0;
1660
6.37k
            if (bw4 == 1 && bh4 == ss_ver) {
1661
4.23k
                for (int pl = 0; pl < 2; pl++) {
1662
2.82k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1663
2.82k
                             NULL, f->cur.stride[1],
1664
2.82k
                             bw4, bh4, t->bx - 1, t->by - 1, 1 + pl,
1665
2.82k
                             r[-1][t->bx - 1].mv.mv[0],
1666
2.82k
                             &f->refp[r[-1][t->bx - 1].ref.ref[0] - 1],
1667
2.82k
                             r[-1][t->bx - 1].ref.ref[0] - 1,
1668
2.82k
                             t->frame_thread.pass != 2 ? t->tl_4x4_filter :
1669
2.82k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx - 1].filter2d);
1670
2.82k
                    if (res) return res;
1671
2.82k
                }
1672
1.41k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1673
1.41k
                h_off = 2;
1674
1.41k
            }
1675
6.37k
            if (bw4 == 1) {
1676
3.95k
                const enum Filter2d left_filter_2d =
1677
3.95k
                    dav1d_filter_2d[t->l.filter[1][by4]][t->l.filter[0][by4]];
1678
11.8k
                for (int pl = 0; pl < 2; pl++) {
1679
7.90k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + v_off, NULL,
1680
7.90k
                             f->cur.stride[1], bw4, bh4, t->bx - 1,
1681
7.90k
                             t->by, 1 + pl, r[0][t->bx - 1].mv.mv[0],
1682
7.90k
                             &f->refp[r[0][t->bx - 1].ref.ref[0] - 1],
1683
7.90k
                             r[0][t->bx - 1].ref.ref[0] - 1,
1684
7.90k
                             t->frame_thread.pass != 2 ? left_filter_2d :
1685
7.90k
                                 f->frame_thread.b[(t->by * f->b4_stride) + t->bx - 1].filter2d);
1686
7.90k
                    if (res) return res;
1687
7.90k
                }
1688
3.95k
                h_off = 2;
1689
3.95k
            }
1690
6.37k
            if (bh4 == ss_ver) {
1691
3.83k
                const enum Filter2d top_filter_2d =
1692
3.83k
                    dav1d_filter_2d[t->a->filter[1][bx4]][t->a->filter[0][bx4]];
1693
11.4k
                for (int pl = 0; pl < 2; pl++) {
1694
7.66k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off, NULL,
1695
7.66k
                             f->cur.stride[1], bw4, bh4, t->bx, t->by - 1,
1696
7.66k
                             1 + pl, r[-1][t->bx].mv.mv[0],
1697
7.66k
                             &f->refp[r[-1][t->bx].ref.ref[0] - 1],
1698
7.66k
                             r[-1][t->bx].ref.ref[0] - 1,
1699
7.66k
                             t->frame_thread.pass != 2 ? top_filter_2d :
1700
7.66k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx].filter2d);
1701
7.66k
                    if (res) return res;
1702
7.66k
                }
1703
3.83k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1704
3.83k
            }
1705
19.1k
            for (int pl = 0; pl < 2; pl++) {
1706
12.7k
                res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off + v_off, NULL, f->cur.stride[1],
1707
12.7k
                         bw4, bh4, t->bx, t->by, 1 + pl, b->mv[0],
1708
12.7k
                         refp, b->ref[0], filter_2d);
1709
12.7k
                if (res) return res;
1710
12.7k
            }
1711
27.2k
        } else {
1712
27.2k
            if (imin(cbw4, cbh4) > 1 &&
1713
11.6k
                ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1714
9.99k
                 (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1715
2.06k
            {
1716
6.20k
                for (int pl = 0; pl < 2; pl++) {
1717
4.13k
                    res = warp_affine(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff, NULL,
1718
4.13k
                                      f->cur.stride[1], b_dim, 1 + pl, refp,
1719
4.13k
                                      b->motion_mode == MM_WARP ? &t->warpmv :
1720
4.13k
                                          &f->frame_hdr->gmv[b->ref[0]]);
1721
4.13k
                    if (res) return res;
1722
4.13k
                }
1723
25.1k
            } else {
1724
75.5k
                for (int pl = 0; pl < 2; pl++) {
1725
50.3k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1726
50.3k
                             NULL, f->cur.stride[1],
1727
50.3k
                             bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1728
50.3k
                             t->bx & ~ss_hor, t->by & ~ss_ver,
1729
50.3k
                             1 + pl, b->mv[0], refp, b->ref[0], filter_2d);
1730
50.3k
                    if (res) return res;
1731
50.3k
                    if (b->motion_mode == MM_OBMC) {
1732
14.0k
                        res = obmc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1733
14.0k
                                   f->cur.stride[1], b_dim, 1 + pl, bx4, by4, w4, h4);
1734
14.0k
                        if (res) return res;
1735
14.0k
                    }
1736
50.3k
                }
1737
25.1k
            }
1738
27.2k
            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
3.12k
                const uint8_t *const ii_mask = II_MASK(chr_layout_idx, bs, b);
1743
1744
9.38k
                for (int pl = 0; pl < 2; pl++) {
1745
6.25k
                    pixel *const tmp = bitfn(t->scratch.interintra);
1746
6.25k
                    pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1747
6.25k
                    enum IntraPredMode m =
1748
6.25k
                        b->interintra_mode == II_SMOOTH_PRED ?
1749
5.10k
                        SMOOTH_PRED : b->interintra_mode;
1750
6.25k
                    int angle = 0;
1751
6.25k
                    pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1752
6.25k
                    const pixel *top_sb_edge = NULL;
1753
6.25k
                    if (!(t->by & (f->sb_step - 1))) {
1754
1.35k
                        top_sb_edge = f->ipred_edge[pl + 1];
1755
1.35k
                        const int sby = t->by >> f->sb_shift;
1756
1.35k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1757
1.35k
                    }
1758
6.25k
                    m = bytefn(dav1d_prepare_intra_edges)(t->bx >> ss_hor,
1759
6.25k
                                                          (t->bx >> ss_hor) >
1760
6.25k
                                                              (ts->tiling.col_start >> ss_hor),
1761
6.25k
                                                          t->by >> ss_ver,
1762
6.25k
                                                          (t->by >> ss_ver) >
1763
6.25k
                                                              (ts->tiling.row_start >> ss_ver),
1764
6.25k
                                                          ts->tiling.col_end >> ss_hor,
1765
6.25k
                                                          ts->tiling.row_end >> ss_ver,
1766
6.25k
                                                          0, uvdst, f->cur.stride[1],
1767
6.25k
                                                          top_sb_edge, m,
1768
6.25k
                                                          &angle, cbw4, cbh4, 0, tl_edge
1769
6.25k
                                                          HIGHBD_CALL_SUFFIX);
1770
6.25k
                    dsp->ipred.intra_pred[m](tmp, cbw4 * 4 * sizeof(pixel),
1771
6.25k
                                             tl_edge, cbw4 * 4, cbh4 * 4, 0, 0, 0
1772
6.25k
                                             HIGHBD_CALL_SUFFIX);
1773
6.25k
                    dsp->mc.blend(uvdst, f->cur.stride[1], tmp,
1774
6.25k
                                  cbw4 * 4, cbh4 * 4, ii_mask);
1775
6.25k
                }
1776
3.12k
            }
1777
27.2k
        }
1778
1779
48.9k
    skip_inter_chroma_pred: {}
1780
48.9k
        t->tl_4x4_filter = filter_2d;
1781
48.9k
    } else {
1782
12.0k
        const enum Filter2d filter_2d = b->filter2d;
1783
        // Maximum super block size is 128x128
1784
12.0k
        int16_t (*tmp)[128 * 128] = t->scratch.compinter;
1785
12.0k
        int jnt_weight;
1786
12.0k
        uint8_t *const seg_mask = t->scratch.seg_mask;
1787
12.0k
        const uint8_t *mask;
1788
1789
36.2k
        for (int i = 0; i < 2; i++) {
1790
24.1k
            const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1791
1792
24.1k
            if (b->inter_mode == GLOBALMV_GLOBALMV && f->gmv_warp_allowed[b->ref[i]]) {
1793
479
                res = warp_affine(t, NULL, tmp[i], bw4 * 4, b_dim, 0, refp,
1794
479
                                  &f->frame_hdr->gmv[b->ref[i]]);
1795
479
                if (res) return res;
1796
23.6k
            } else {
1797
23.6k
                res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by, 0,
1798
23.6k
                         b->mv[i], refp, b->ref[i], filter_2d);
1799
23.6k
                if (res) return res;
1800
23.6k
            }
1801
24.1k
        }
1802
12.0k
        switch (b->comp_type) {
1803
8.73k
        case COMP_INTER_AVG:
1804
8.73k
            dsp->mc.avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1805
8.73k
                        bw4 * 4, bh4 * 4 HIGHBD_CALL_SUFFIX);
1806
8.73k
            break;
1807
804
        case COMP_INTER_WEIGHTED_AVG:
1808
804
            jnt_weight = f->jnt_weights[b->ref[0]][b->ref[1]];
1809
804
            dsp->mc.w_avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1810
804
                          bw4 * 4, bh4 * 4, jnt_weight HIGHBD_CALL_SUFFIX);
1811
804
            break;
1812
1.69k
        case COMP_INTER_SEG:
1813
1.69k
            dsp->mc.w_mask[chr_layout_idx](dst, f->cur.stride[0],
1814
1.69k
                                           tmp[b->mask_sign], tmp[!b->mask_sign],
1815
1.69k
                                           bw4 * 4, bh4 * 4, seg_mask,
1816
1.69k
                                           b->mask_sign HIGHBD_CALL_SUFFIX);
1817
1.69k
            mask = seg_mask;
1818
1.69k
            break;
1819
839
        case COMP_INTER_WEDGE:
1820
839
            mask = WEDGE_MASK(0, bs, 0, b->wedge_idx);
1821
839
            dsp->mc.mask(dst, f->cur.stride[0],
1822
839
                         tmp[b->mask_sign], tmp[!b->mask_sign],
1823
839
                         bw4 * 4, bh4 * 4, mask HIGHBD_CALL_SUFFIX);
1824
839
            if (has_chroma)
1825
607
                mask = WEDGE_MASK(chr_layout_idx, bs, b->mask_sign, b->wedge_idx);
1826
839
            break;
1827
12.0k
        }
1828
1829
        // chroma
1830
26.7k
        if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1831
53.5k
            for (int i = 0; i < 2; i++) {
1832
35.7k
                const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1833
35.7k
                if (b->inter_mode == GLOBALMV_GLOBALMV &&
1834
4.10k
                    imin(cbw4, cbh4) > 1 && f->gmv_warp_allowed[b->ref[i]])
1835
358
                {
1836
358
                    res = warp_affine(t, NULL, tmp[i], bw4 * 4 >> ss_hor,
1837
358
                                      b_dim, 1 + pl,
1838
358
                                      refp, &f->frame_hdr->gmv[b->ref[i]]);
1839
358
                    if (res) return res;
1840
35.3k
                } else {
1841
35.3k
                    res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by,
1842
35.3k
                             1 + pl, b->mv[i], refp, b->ref[i], filter_2d);
1843
35.3k
                    if (res) return res;
1844
35.3k
                }
1845
35.7k
            }
1846
17.8k
            pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1847
17.8k
            switch (b->comp_type) {
1848
12.9k
            case COMP_INTER_AVG:
1849
12.9k
                dsp->mc.avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1850
12.9k
                            bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver
1851
12.9k
                            HIGHBD_CALL_SUFFIX);
1852
12.9k
                break;
1853
1.19k
            case COMP_INTER_WEIGHTED_AVG:
1854
1.19k
                dsp->mc.w_avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1855
1.19k
                              bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, jnt_weight
1856
1.19k
                              HIGHBD_CALL_SUFFIX);
1857
1.19k
                break;
1858
1.21k
            case COMP_INTER_WEDGE:
1859
3.69k
            case COMP_INTER_SEG:
1860
3.69k
                dsp->mc.mask(uvdst, f->cur.stride[1],
1861
3.69k
                             tmp[b->mask_sign], tmp[!b->mask_sign],
1862
3.69k
                             bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, mask
1863
3.69k
                             HIGHBD_CALL_SUFFIX);
1864
3.69k
                break;
1865
17.8k
            }
1866
17.8k
        }
1867
12.0k
    }
1868
1869
167k
    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
167k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1880
1881
167k
    if (b->skip) {
1882
        // reset coef contexts
1883
51.1k
        BlockContext *const a = t->a;
1884
51.1k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
1885
51.1k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
1886
51.1k
        if (has_chroma) {
1887
34.4k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
1888
34.4k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
1889
34.4k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
1890
34.4k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
1891
34.4k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
1892
34.4k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
1893
34.4k
        }
1894
51.1k
        return 0;
1895
51.1k
    }
1896
1897
116k
    const TxfmInfo *const uvtx = &dav1d_txfm_dimensions[b->uvtx];
1898
116k
    const TxfmInfo *const ytx = &dav1d_txfm_dimensions[b->max_ytx];
1899
116k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
1900
1901
235k
    for (int init_y = 0; init_y < bh4; init_y += 16) {
1902
243k
        for (int init_x = 0; init_x < bw4; init_x += 16) {
1903
            // coefficient coding & inverse transforms
1904
124k
            int y_off = !!init_y, y;
1905
124k
            dst += PXSTRIDE(f->cur.stride[0]) * 4 * init_y;
1906
249k
            for (y = init_y, t->by += init_y; y < imin(h4, init_y + 16);
1907
125k
                 y += ytx->h, y_off++)
1908
125k
            {
1909
125k
                int x, x_off = !!init_x;
1910
253k
                for (x = init_x, t->bx += init_x; x < imin(w4, init_x + 16);
1911
128k
                     x += ytx->w, x_off++)
1912
128k
                {
1913
128k
                    read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
1914
128k
                                   x_off, y_off, &dst[x * 4]);
1915
128k
                    t->bx += ytx->w;
1916
128k
                }
1917
125k
                dst += PXSTRIDE(f->cur.stride[0]) * 4 * ytx->h;
1918
125k
                t->bx -= x;
1919
125k
                t->by += ytx->h;
1920
125k
            }
1921
124k
            dst -= PXSTRIDE(f->cur.stride[0]) * 4 * y;
1922
124k
            t->by -= y;
1923
1924
            // chroma coefs and inverse transform
1925
194k
            if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1926
129k
                pixel *uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff +
1927
129k
                    (PXSTRIDE(f->cur.stride[1]) * init_y * 4 >> ss_ver);
1928
129k
                for (y = init_y >> ss_ver, t->by += init_y;
1929
260k
                     y < imin(ch4, (init_y + 16) >> ss_ver); y += uvtx->h)
1930
130k
                {
1931
130k
                    int x;
1932
130k
                    for (x = init_x >> ss_hor, t->bx += init_x;
1933
262k
                         x < imin(cw4, (init_x + 16) >> ss_hor); x += uvtx->w)
1934
131k
                    {
1935
131k
                        coef *cf;
1936
131k
                        int eob;
1937
131k
                        enum TxfmType txtp;
1938
131k
                        if (t->frame_thread.pass) {
1939
131k
                            const int p = t->frame_thread.pass & 1;
1940
131k
                            const int cbi = *ts->frame_thread[p].cbi++;
1941
131k
                            cf = ts->frame_thread[p].cf;
1942
131k
                            ts->frame_thread[p].cf += uvtx->w * uvtx->h * 16;
1943
131k
                            eob  = cbi >> 5;
1944
131k
                            txtp = cbi & 0x1f;
1945
131k
                        } 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
131k
                        if (eob >= 0) {
1964
30.8k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1965
0
                                coef_dump(cf, uvtx->h * 4, uvtx->w * 4, 3, "dq");
1966
30.8k
                            dsp->itx.itxfm_add[b->uvtx]
1967
30.8k
                                              [txtp](&uvdst[4 * x],
1968
30.8k
                                                     f->cur.stride[1],
1969
30.8k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1970
30.8k
                            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
30.8k
                        }
1974
131k
                        t->bx += uvtx->w << ss_hor;
1975
131k
                    }
1976
130k
                    uvdst += PXSTRIDE(f->cur.stride[1]) * 4 * uvtx->h;
1977
130k
                    t->bx -= x << ss_hor;
1978
130k
                    t->by += uvtx->h << ss_ver;
1979
130k
                }
1980
129k
                t->by -= y << ss_ver;
1981
129k
            }
1982
124k
        }
1983
119k
    }
1984
116k
    return 0;
1985
167k
}
dav1d_recon_b_inter_8bpc
Line
Count
Source
1559
93.8k
{
1560
93.8k
    Dav1dTileState *const ts = t->ts;
1561
93.8k
    const Dav1dFrameContext *const f = t->f;
1562
93.8k
    const Dav1dDSPContext *const dsp = f->dsp;
1563
93.8k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1564
93.8k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1565
93.8k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1566
93.8k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1567
93.8k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1568
93.8k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1569
93.8k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1570
93.8k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1571
88.6k
                           (bw4 > ss_hor || t->bx & 1) &&
1572
80.8k
                           (bh4 > ss_ver || t->by & 1);
1573
93.8k
    const int chr_layout_idx = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I400 ? 0 :
1574
93.8k
                               DAV1D_PIXEL_LAYOUT_I444 - f->cur.p.layout;
1575
93.8k
    int res;
1576
1577
    // prediction
1578
93.8k
    const int cbh4 = (bh4 + ss_ver) >> ss_ver, cbw4 = (bw4 + ss_hor) >> ss_hor;
1579
93.8k
    pixel *dst = ((pixel *) f->cur.data[0]) +
1580
93.8k
        4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1581
93.8k
    const ptrdiff_t uvdstoff =
1582
93.8k
        4 * ((t->bx >> ss_hor) + (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1583
93.8k
    if (IS_KEY_OR_INTRA(f->frame_hdr)) {
1584
        // intrabc
1585
57.8k
        assert(!f->frame_hdr->super_res.enabled);
1586
57.8k
        res = mc(t, dst, NULL, f->cur.stride[0], bw4, bh4, t->bx, t->by, 0,
1587
57.8k
                 b->mv[0], &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1588
57.8k
        if (res) return res;
1589
143k
        if (has_chroma) for (int pl = 1; pl < 3; pl++) {
1590
95.8k
            res = mc(t, ((pixel *)f->cur.data[pl]) + uvdstoff, NULL, f->cur.stride[1],
1591
95.8k
                     bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1592
95.8k
                     t->bx & ~ss_hor, t->by & ~ss_ver, pl, b->mv[0],
1593
95.8k
                     &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1594
95.8k
            if (res) return res;
1595
95.8k
        }
1596
57.8k
    } else if (b->comp_type == COMP_INTER_NONE) {
1597
29.1k
        const Dav1dThreadPicture *const refp = &f->refp[b->ref[0]];
1598
29.1k
        const enum Filter2d filter_2d = b->filter2d;
1599
1600
29.1k
        if (imin(bw4, bh4) > 1 &&
1601
16.9k
            ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1602
14.1k
             (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1603
3.17k
        {
1604
3.17k
            res = warp_affine(t, dst, NULL, f->cur.stride[0], b_dim, 0, refp,
1605
3.17k
                              b->motion_mode == MM_WARP ? &t->warpmv :
1606
3.17k
                                  &f->frame_hdr->gmv[b->ref[0]]);
1607
3.17k
            if (res) return res;
1608
26.0k
        } else {
1609
26.0k
            res = mc(t, dst, NULL, f->cur.stride[0],
1610
26.0k
                     bw4, bh4, t->bx, t->by, 0, b->mv[0], refp, b->ref[0], filter_2d);
1611
26.0k
            if (res) return res;
1612
26.0k
            if (b->motion_mode == MM_OBMC) {
1613
4.72k
                res = obmc(t, dst, f->cur.stride[0], b_dim, 0, bx4, by4, w4, h4);
1614
4.72k
                if (res) return res;
1615
4.72k
            }
1616
26.0k
        }
1617
29.1k
        if (b->interintra_type) {
1618
2.41k
            pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1619
2.41k
            enum IntraPredMode m = b->interintra_mode == II_SMOOTH_PRED ?
1620
2.00k
                                   SMOOTH_PRED : b->interintra_mode;
1621
2.41k
            pixel *const tmp = bitfn(t->scratch.interintra);
1622
2.41k
            int angle = 0;
1623
2.41k
            const pixel *top_sb_edge = NULL;
1624
2.41k
            if (!(t->by & (f->sb_step - 1))) {
1625
511
                top_sb_edge = f->ipred_edge[0];
1626
511
                const int sby = t->by >> f->sb_shift;
1627
511
                top_sb_edge += f->sb128w * 128 * (sby - 1);
1628
511
            }
1629
2.41k
            m = bytefn(dav1d_prepare_intra_edges)(t->bx, t->bx > ts->tiling.col_start,
1630
2.41k
                                                  t->by, t->by > ts->tiling.row_start,
1631
2.41k
                                                  ts->tiling.col_end, ts->tiling.row_end,
1632
2.41k
                                                  0, dst, f->cur.stride[0], top_sb_edge,
1633
2.41k
                                                  m, &angle, bw4, bh4, 0, tl_edge
1634
2.41k
                                                  HIGHBD_CALL_SUFFIX);
1635
2.41k
            dsp->ipred.intra_pred[m](tmp, 4 * bw4 * sizeof(pixel),
1636
2.41k
                                     tl_edge, bw4 * 4, bh4 * 4, 0, 0, 0
1637
2.41k
                                     HIGHBD_CALL_SUFFIX);
1638
2.41k
            dsp->mc.blend(dst, f->cur.stride[0], tmp,
1639
2.41k
                          bw4 * 4, bh4 * 4, II_MASK(0, bs, b));
1640
2.41k
        }
1641
1642
29.1k
        if (!has_chroma) goto skip_inter_chroma_pred;
1643
1644
        // sub8x8 derivation
1645
20.1k
        int is_sub8x8 = bw4 == ss_hor || bh4 == ss_ver;
1646
20.1k
        refmvs_block *const *r;
1647
20.1k
        if (is_sub8x8) {
1648
4.11k
            assert(ss_hor == 1);
1649
4.11k
            r = &t->rt.r[(t->by & 31) + 5];
1650
4.11k
            if (bw4 == 1) is_sub8x8 &= r[0][t->bx - 1].ref.ref[0] > 0;
1651
4.11k
            if (bh4 == ss_ver) is_sub8x8 &= r[-1][t->bx].ref.ref[0] > 0;
1652
4.11k
            if (bw4 == 1 && bh4 == ss_ver)
1653
860
                is_sub8x8 &= r[-1][t->bx - 1].ref.ref[0] > 0;
1654
4.11k
        }
1655
1656
        // chroma prediction
1657
20.1k
        if (is_sub8x8) {
1658
4.05k
            assert(ss_hor == 1);
1659
4.05k
            ptrdiff_t h_off = 0, v_off = 0;
1660
4.05k
            if (bw4 == 1 && bh4 == ss_ver) {
1661
2.53k
                for (int pl = 0; pl < 2; pl++) {
1662
1.69k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1663
1.69k
                             NULL, f->cur.stride[1],
1664
1.69k
                             bw4, bh4, t->bx - 1, t->by - 1, 1 + pl,
1665
1.69k
                             r[-1][t->bx - 1].mv.mv[0],
1666
1.69k
                             &f->refp[r[-1][t->bx - 1].ref.ref[0] - 1],
1667
1.69k
                             r[-1][t->bx - 1].ref.ref[0] - 1,
1668
1.69k
                             t->frame_thread.pass != 2 ? t->tl_4x4_filter :
1669
1.69k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx - 1].filter2d);
1670
1.69k
                    if (res) return res;
1671
1.69k
                }
1672
845
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1673
845
                h_off = 2;
1674
845
            }
1675
4.05k
            if (bw4 == 1) {
1676
2.35k
                const enum Filter2d left_filter_2d =
1677
2.35k
                    dav1d_filter_2d[t->l.filter[1][by4]][t->l.filter[0][by4]];
1678
7.06k
                for (int pl = 0; pl < 2; pl++) {
1679
4.70k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + v_off, NULL,
1680
4.70k
                             f->cur.stride[1], bw4, bh4, t->bx - 1,
1681
4.70k
                             t->by, 1 + pl, r[0][t->bx - 1].mv.mv[0],
1682
4.70k
                             &f->refp[r[0][t->bx - 1].ref.ref[0] - 1],
1683
4.70k
                             r[0][t->bx - 1].ref.ref[0] - 1,
1684
4.70k
                             t->frame_thread.pass != 2 ? left_filter_2d :
1685
4.70k
                                 f->frame_thread.b[(t->by * f->b4_stride) + t->bx - 1].filter2d);
1686
4.70k
                    if (res) return res;
1687
4.70k
                }
1688
2.35k
                h_off = 2;
1689
2.35k
            }
1690
4.05k
            if (bh4 == ss_ver) {
1691
2.54k
                const enum Filter2d top_filter_2d =
1692
2.54k
                    dav1d_filter_2d[t->a->filter[1][bx4]][t->a->filter[0][bx4]];
1693
7.62k
                for (int pl = 0; pl < 2; pl++) {
1694
5.08k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off, NULL,
1695
5.08k
                             f->cur.stride[1], bw4, bh4, t->bx, t->by - 1,
1696
5.08k
                             1 + pl, r[-1][t->bx].mv.mv[0],
1697
5.08k
                             &f->refp[r[-1][t->bx].ref.ref[0] - 1],
1698
5.08k
                             r[-1][t->bx].ref.ref[0] - 1,
1699
5.08k
                             t->frame_thread.pass != 2 ? top_filter_2d :
1700
5.08k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx].filter2d);
1701
5.08k
                    if (res) return res;
1702
5.08k
                }
1703
2.54k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1704
2.54k
            }
1705
12.1k
            for (int pl = 0; pl < 2; pl++) {
1706
8.10k
                res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off + v_off, NULL, f->cur.stride[1],
1707
8.10k
                         bw4, bh4, t->bx, t->by, 1 + pl, b->mv[0],
1708
8.10k
                         refp, b->ref[0], filter_2d);
1709
8.10k
                if (res) return res;
1710
8.10k
            }
1711
16.0k
        } else {
1712
16.0k
            if (imin(cbw4, cbh4) > 1 &&
1713
6.51k
                ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1714
5.48k
                 (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1715
1.24k
            {
1716
3.72k
                for (int pl = 0; pl < 2; pl++) {
1717
2.48k
                    res = warp_affine(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff, NULL,
1718
2.48k
                                      f->cur.stride[1], b_dim, 1 + pl, refp,
1719
2.48k
                                      b->motion_mode == MM_WARP ? &t->warpmv :
1720
2.48k
                                          &f->frame_hdr->gmv[b->ref[0]]);
1721
2.48k
                    if (res) return res;
1722
2.48k
                }
1723
14.8k
            } else {
1724
44.5k
                for (int pl = 0; pl < 2; pl++) {
1725
29.6k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1726
29.6k
                             NULL, f->cur.stride[1],
1727
29.6k
                             bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1728
29.6k
                             t->bx & ~ss_hor, t->by & ~ss_ver,
1729
29.6k
                             1 + pl, b->mv[0], refp, b->ref[0], filter_2d);
1730
29.6k
                    if (res) return res;
1731
29.6k
                    if (b->motion_mode == MM_OBMC) {
1732
8.19k
                        res = obmc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1733
8.19k
                                   f->cur.stride[1], b_dim, 1 + pl, bx4, by4, w4, h4);
1734
8.19k
                        if (res) return res;
1735
8.19k
                    }
1736
29.6k
                }
1737
14.8k
            }
1738
16.0k
            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
2.31k
                const uint8_t *const ii_mask = II_MASK(chr_layout_idx, bs, b);
1743
1744
6.93k
                for (int pl = 0; pl < 2; pl++) {
1745
4.62k
                    pixel *const tmp = bitfn(t->scratch.interintra);
1746
4.62k
                    pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1747
4.62k
                    enum IntraPredMode m =
1748
4.62k
                        b->interintra_mode == II_SMOOTH_PRED ?
1749
3.84k
                        SMOOTH_PRED : b->interintra_mode;
1750
4.62k
                    int angle = 0;
1751
4.62k
                    pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1752
4.62k
                    const pixel *top_sb_edge = NULL;
1753
4.62k
                    if (!(t->by & (f->sb_step - 1))) {
1754
944
                        top_sb_edge = f->ipred_edge[pl + 1];
1755
944
                        const int sby = t->by >> f->sb_shift;
1756
944
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1757
944
                    }
1758
4.62k
                    m = bytefn(dav1d_prepare_intra_edges)(t->bx >> ss_hor,
1759
4.62k
                                                          (t->bx >> ss_hor) >
1760
4.62k
                                                              (ts->tiling.col_start >> ss_hor),
1761
4.62k
                                                          t->by >> ss_ver,
1762
4.62k
                                                          (t->by >> ss_ver) >
1763
4.62k
                                                              (ts->tiling.row_start >> ss_ver),
1764
4.62k
                                                          ts->tiling.col_end >> ss_hor,
1765
4.62k
                                                          ts->tiling.row_end >> ss_ver,
1766
4.62k
                                                          0, uvdst, f->cur.stride[1],
1767
4.62k
                                                          top_sb_edge, m,
1768
4.62k
                                                          &angle, cbw4, cbh4, 0, tl_edge
1769
4.62k
                                                          HIGHBD_CALL_SUFFIX);
1770
4.62k
                    dsp->ipred.intra_pred[m](tmp, cbw4 * 4 * sizeof(pixel),
1771
4.62k
                                             tl_edge, cbw4 * 4, cbh4 * 4, 0, 0, 0
1772
4.62k
                                             HIGHBD_CALL_SUFFIX);
1773
4.62k
                    dsp->mc.blend(uvdst, f->cur.stride[1], tmp,
1774
4.62k
                                  cbw4 * 4, cbh4 * 4, ii_mask);
1775
4.62k
                }
1776
2.31k
            }
1777
16.0k
        }
1778
1779
29.1k
    skip_inter_chroma_pred: {}
1780
29.1k
        t->tl_4x4_filter = filter_2d;
1781
29.1k
    } else {
1782
6.74k
        const enum Filter2d filter_2d = b->filter2d;
1783
        // Maximum super block size is 128x128
1784
6.74k
        int16_t (*tmp)[128 * 128] = t->scratch.compinter;
1785
6.74k
        int jnt_weight;
1786
6.74k
        uint8_t *const seg_mask = t->scratch.seg_mask;
1787
6.74k
        const uint8_t *mask;
1788
1789
20.2k
        for (int i = 0; i < 2; i++) {
1790
13.4k
            const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1791
1792
13.4k
            if (b->inter_mode == GLOBALMV_GLOBALMV && f->gmv_warp_allowed[b->ref[i]]) {
1793
237
                res = warp_affine(t, NULL, tmp[i], bw4 * 4, b_dim, 0, refp,
1794
237
                                  &f->frame_hdr->gmv[b->ref[i]]);
1795
237
                if (res) return res;
1796
13.2k
            } else {
1797
13.2k
                res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by, 0,
1798
13.2k
                         b->mv[i], refp, b->ref[i], filter_2d);
1799
13.2k
                if (res) return res;
1800
13.2k
            }
1801
13.4k
        }
1802
6.74k
        switch (b->comp_type) {
1803
5.02k
        case COMP_INTER_AVG:
1804
5.02k
            dsp->mc.avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1805
5.02k
                        bw4 * 4, bh4 * 4 HIGHBD_CALL_SUFFIX);
1806
5.02k
            break;
1807
374
        case COMP_INTER_WEIGHTED_AVG:
1808
374
            jnt_weight = f->jnt_weights[b->ref[0]][b->ref[1]];
1809
374
            dsp->mc.w_avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1810
374
                          bw4 * 4, bh4 * 4, jnt_weight HIGHBD_CALL_SUFFIX);
1811
374
            break;
1812
890
        case COMP_INTER_SEG:
1813
890
            dsp->mc.w_mask[chr_layout_idx](dst, f->cur.stride[0],
1814
890
                                           tmp[b->mask_sign], tmp[!b->mask_sign],
1815
890
                                           bw4 * 4, bh4 * 4, seg_mask,
1816
890
                                           b->mask_sign HIGHBD_CALL_SUFFIX);
1817
890
            mask = seg_mask;
1818
890
            break;
1819
462
        case COMP_INTER_WEDGE:
1820
462
            mask = WEDGE_MASK(0, bs, 0, b->wedge_idx);
1821
462
            dsp->mc.mask(dst, f->cur.stride[0],
1822
462
                         tmp[b->mask_sign], tmp[!b->mask_sign],
1823
462
                         bw4 * 4, bh4 * 4, mask HIGHBD_CALL_SUFFIX);
1824
462
            if (has_chroma)
1825
304
                mask = WEDGE_MASK(chr_layout_idx, bs, b->mask_sign, b->wedge_idx);
1826
462
            break;
1827
6.74k
        }
1828
1829
        // chroma
1830
14.4k
        if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1831
28.9k
            for (int i = 0; i < 2; i++) {
1832
19.2k
                const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1833
19.2k
                if (b->inter_mode == GLOBALMV_GLOBALMV &&
1834
2.27k
                    imin(cbw4, cbh4) > 1 && f->gmv_warp_allowed[b->ref[i]])
1835
104
                {
1836
104
                    res = warp_affine(t, NULL, tmp[i], bw4 * 4 >> ss_hor,
1837
104
                                      b_dim, 1 + pl,
1838
104
                                      refp, &f->frame_hdr->gmv[b->ref[i]]);
1839
104
                    if (res) return res;
1840
19.1k
                } else {
1841
19.1k
                    res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by,
1842
19.1k
                             1 + pl, b->mv[i], refp, b->ref[i], filter_2d);
1843
19.1k
                    if (res) return res;
1844
19.1k
                }
1845
19.2k
            }
1846
9.64k
            pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1847
9.64k
            switch (b->comp_type) {
1848
7.27k
            case COMP_INTER_AVG:
1849
7.27k
                dsp->mc.avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1850
7.27k
                            bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver
1851
7.27k
                            HIGHBD_CALL_SUFFIX);
1852
7.27k
                break;
1853
506
            case COMP_INTER_WEIGHTED_AVG:
1854
506
                dsp->mc.w_avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1855
506
                              bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, jnt_weight
1856
506
                              HIGHBD_CALL_SUFFIX);
1857
506
                break;
1858
608
            case COMP_INTER_WEDGE:
1859
1.86k
            case COMP_INTER_SEG:
1860
1.86k
                dsp->mc.mask(uvdst, f->cur.stride[1],
1861
1.86k
                             tmp[b->mask_sign], tmp[!b->mask_sign],
1862
1.86k
                             bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, mask
1863
1.86k
                             HIGHBD_CALL_SUFFIX);
1864
1.86k
                break;
1865
9.64k
            }
1866
9.64k
        }
1867
6.74k
    }
1868
1869
93.8k
    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
93.8k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1880
1881
93.8k
    if (b->skip) {
1882
        // reset coef contexts
1883
31.0k
        BlockContext *const a = t->a;
1884
31.0k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
1885
31.0k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
1886
31.0k
        if (has_chroma) {
1887
23.4k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
1888
23.4k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
1889
23.4k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
1890
23.4k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
1891
23.4k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
1892
23.4k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
1893
23.4k
        }
1894
31.0k
        return 0;
1895
31.0k
    }
1896
1897
62.7k
    const TxfmInfo *const uvtx = &dav1d_txfm_dimensions[b->uvtx];
1898
62.7k
    const TxfmInfo *const ytx = &dav1d_txfm_dimensions[b->max_ytx];
1899
62.7k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
1900
1901
127k
    for (int init_y = 0; init_y < bh4; init_y += 16) {
1902
131k
        for (int init_x = 0; init_x < bw4; init_x += 16) {
1903
            // coefficient coding & inverse transforms
1904
67.2k
            int y_off = !!init_y, y;
1905
67.2k
            dst += PXSTRIDE(f->cur.stride[0]) * 4 * init_y;
1906
135k
            for (y = init_y, t->by += init_y; y < imin(h4, init_y + 16);
1907
67.7k
                 y += ytx->h, y_off++)
1908
67.7k
            {
1909
67.7k
                int x, x_off = !!init_x;
1910
137k
                for (x = init_x, t->bx += init_x; x < imin(w4, init_x + 16);
1911
69.3k
                     x += ytx->w, x_off++)
1912
69.3k
                {
1913
69.3k
                    read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
1914
69.3k
                                   x_off, y_off, &dst[x * 4]);
1915
69.3k
                    t->bx += ytx->w;
1916
69.3k
                }
1917
67.7k
                dst += PXSTRIDE(f->cur.stride[0]) * 4 * ytx->h;
1918
67.7k
                t->bx -= x;
1919
67.7k
                t->by += ytx->h;
1920
67.7k
            }
1921
67.2k
            dst -= PXSTRIDE(f->cur.stride[0]) * 4 * y;
1922
67.2k
            t->by -= y;
1923
1924
            // chroma coefs and inverse transform
1925
161k
            if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1926
107k
                pixel *uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff +
1927
107k
                    (PXSTRIDE(f->cur.stride[1]) * init_y * 4 >> ss_ver);
1928
107k
                for (y = init_y >> ss_ver, t->by += init_y;
1929
216k
                     y < imin(ch4, (init_y + 16) >> ss_ver); y += uvtx->h)
1930
108k
                {
1931
108k
                    int x;
1932
108k
                    for (x = init_x >> ss_hor, t->bx += init_x;
1933
217k
                         x < imin(cw4, (init_x + 16) >> ss_hor); x += uvtx->w)
1934
109k
                    {
1935
109k
                        coef *cf;
1936
109k
                        int eob;
1937
109k
                        enum TxfmType txtp;
1938
109k
                        if (t->frame_thread.pass) {
1939
109k
                            const int p = t->frame_thread.pass & 1;
1940
109k
                            const int cbi = *ts->frame_thread[p].cbi++;
1941
109k
                            cf = ts->frame_thread[p].cf;
1942
109k
                            ts->frame_thread[p].cf += uvtx->w * uvtx->h * 16;
1943
109k
                            eob  = cbi >> 5;
1944
109k
                            txtp = cbi & 0x1f;
1945
109k
                        } 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
109k
                        if (eob >= 0) {
1964
25.9k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1965
0
                                coef_dump(cf, uvtx->h * 4, uvtx->w * 4, 3, "dq");
1966
25.9k
                            dsp->itx.itxfm_add[b->uvtx]
1967
25.9k
                                              [txtp](&uvdst[4 * x],
1968
25.9k
                                                     f->cur.stride[1],
1969
25.9k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1970
25.9k
                            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
25.9k
                        }
1974
109k
                        t->bx += uvtx->w << ss_hor;
1975
109k
                    }
1976
108k
                    uvdst += PXSTRIDE(f->cur.stride[1]) * 4 * uvtx->h;
1977
108k
                    t->bx -= x << ss_hor;
1978
108k
                    t->by += uvtx->h << ss_ver;
1979
108k
                }
1980
107k
                t->by -= y << ss_ver;
1981
107k
            }
1982
67.2k
        }
1983
64.3k
    }
1984
62.7k
    return 0;
1985
93.8k
}
dav1d_recon_b_inter_16bpc
Line
Count
Source
1559
73.8k
{
1560
73.8k
    Dav1dTileState *const ts = t->ts;
1561
73.8k
    const Dav1dFrameContext *const f = t->f;
1562
73.8k
    const Dav1dDSPContext *const dsp = f->dsp;
1563
73.8k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1564
73.8k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1565
73.8k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1566
73.8k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1567
73.8k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1568
73.8k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1569
73.8k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1570
73.8k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1571
25.3k
                           (bw4 > ss_hor || t->bx & 1) &&
1572
22.9k
                           (bh4 > ss_ver || t->by & 1);
1573
73.8k
    const int chr_layout_idx = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I400 ? 0 :
1574
73.8k
                               DAV1D_PIXEL_LAYOUT_I444 - f->cur.p.layout;
1575
73.8k
    int res;
1576
1577
    // prediction
1578
73.8k
    const int cbh4 = (bh4 + ss_ver) >> ss_ver, cbw4 = (bw4 + ss_hor) >> ss_hor;
1579
73.8k
    pixel *dst = ((pixel *) f->cur.data[0]) +
1580
73.8k
        4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1581
73.8k
    const ptrdiff_t uvdstoff =
1582
73.8k
        4 * ((t->bx >> ss_hor) + (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1583
73.8k
    if (IS_KEY_OR_INTRA(f->frame_hdr)) {
1584
        // intrabc
1585
48.7k
        assert(!f->frame_hdr->super_res.enabled);
1586
48.7k
        res = mc(t, dst, NULL, f->cur.stride[0], bw4, bh4, t->bx, t->by, 0,
1587
48.7k
                 b->mv[0], &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1588
48.7k
        if (res) return res;
1589
48.7k
        if (has_chroma) for (int pl = 1; pl < 3; pl++) {
1590
7.88k
            res = mc(t, ((pixel *)f->cur.data[pl]) + uvdstoff, NULL, f->cur.stride[1],
1591
7.88k
                     bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1592
7.88k
                     t->bx & ~ss_hor, t->by & ~ss_ver, pl, b->mv[0],
1593
7.88k
                     &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1594
7.88k
            if (res) return res;
1595
7.88k
        }
1596
48.7k
    } else if (b->comp_type == COMP_INTER_NONE) {
1597
19.7k
        const Dav1dThreadPicture *const refp = &f->refp[b->ref[0]];
1598
19.7k
        const enum Filter2d filter_2d = b->filter2d;
1599
1600
19.7k
        if (imin(bw4, bh4) > 1 &&
1601
10.7k
            ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1602
9.46k
             (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1603
1.55k
        {
1604
1.55k
            res = warp_affine(t, dst, NULL, f->cur.stride[0], b_dim, 0, refp,
1605
1.55k
                              b->motion_mode == MM_WARP ? &t->warpmv :
1606
1.55k
                                  &f->frame_hdr->gmv[b->ref[0]]);
1607
1.55k
            if (res) return res;
1608
18.2k
        } else {
1609
18.2k
            res = mc(t, dst, NULL, f->cur.stride[0],
1610
18.2k
                     bw4, bh4, t->bx, t->by, 0, b->mv[0], refp, b->ref[0], filter_2d);
1611
18.2k
            if (res) return res;
1612
18.2k
            if (b->motion_mode == MM_OBMC) {
1613
3.47k
                res = obmc(t, dst, f->cur.stride[0], b_dim, 0, bx4, by4, w4, h4);
1614
3.47k
                if (res) return res;
1615
3.47k
            }
1616
18.2k
        }
1617
19.7k
        if (b->interintra_type) {
1618
985
            pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1619
985
            enum IntraPredMode m = b->interintra_mode == II_SMOOTH_PRED ?
1620
791
                                   SMOOTH_PRED : b->interintra_mode;
1621
985
            pixel *const tmp = bitfn(t->scratch.interintra);
1622
985
            int angle = 0;
1623
985
            const pixel *top_sb_edge = NULL;
1624
985
            if (!(t->by & (f->sb_step - 1))) {
1625
313
                top_sb_edge = f->ipred_edge[0];
1626
313
                const int sby = t->by >> f->sb_shift;
1627
313
                top_sb_edge += f->sb128w * 128 * (sby - 1);
1628
313
            }
1629
985
            m = bytefn(dav1d_prepare_intra_edges)(t->bx, t->bx > ts->tiling.col_start,
1630
985
                                                  t->by, t->by > ts->tiling.row_start,
1631
985
                                                  ts->tiling.col_end, ts->tiling.row_end,
1632
985
                                                  0, dst, f->cur.stride[0], top_sb_edge,
1633
985
                                                  m, &angle, bw4, bh4, 0, tl_edge
1634
985
                                                  HIGHBD_CALL_SUFFIX);
1635
985
            dsp->ipred.intra_pred[m](tmp, 4 * bw4 * sizeof(pixel),
1636
985
                                     tl_edge, bw4 * 4, bh4 * 4, 0, 0, 0
1637
985
                                     HIGHBD_CALL_SUFFIX);
1638
985
            dsp->mc.blend(dst, f->cur.stride[0], tmp,
1639
985
                          bw4 * 4, bh4 * 4, II_MASK(0, bs, b));
1640
985
        }
1641
1642
19.7k
        if (!has_chroma) goto skip_inter_chroma_pred;
1643
1644
        // sub8x8 derivation
1645
13.4k
        int is_sub8x8 = bw4 == ss_hor || bh4 == ss_ver;
1646
13.4k
        refmvs_block *const *r;
1647
13.4k
        if (is_sub8x8) {
1648
2.32k
            assert(ss_hor == 1);
1649
2.32k
            r = &t->rt.r[(t->by & 31) + 5];
1650
2.32k
            if (bw4 == 1) is_sub8x8 &= r[0][t->bx - 1].ref.ref[0] > 0;
1651
2.32k
            if (bh4 == ss_ver) is_sub8x8 &= r[-1][t->bx].ref.ref[0] > 0;
1652
2.32k
            if (bw4 == 1 && bh4 == ss_ver)
1653
566
                is_sub8x8 &= r[-1][t->bx - 1].ref.ref[0] > 0;
1654
2.32k
        }
1655
1656
        // chroma prediction
1657
13.4k
        if (is_sub8x8) {
1658
2.32k
            assert(ss_hor == 1);
1659
2.32k
            ptrdiff_t h_off = 0, v_off = 0;
1660
2.32k
            if (bw4 == 1 && bh4 == ss_ver) {
1661
1.69k
                for (int pl = 0; pl < 2; pl++) {
1662
1.13k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1663
1.13k
                             NULL, f->cur.stride[1],
1664
1.13k
                             bw4, bh4, t->bx - 1, t->by - 1, 1 + pl,
1665
1.13k
                             r[-1][t->bx - 1].mv.mv[0],
1666
1.13k
                             &f->refp[r[-1][t->bx - 1].ref.ref[0] - 1],
1667
1.13k
                             r[-1][t->bx - 1].ref.ref[0] - 1,
1668
1.13k
                             t->frame_thread.pass != 2 ? t->tl_4x4_filter :
1669
1.13k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx - 1].filter2d);
1670
1.13k
                    if (res) return res;
1671
1.13k
                }
1672
566
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1673
566
                h_off = 2;
1674
566
            }
1675
2.32k
            if (bw4 == 1) {
1676
1.59k
                const enum Filter2d left_filter_2d =
1677
1.59k
                    dav1d_filter_2d[t->l.filter[1][by4]][t->l.filter[0][by4]];
1678
4.78k
                for (int pl = 0; pl < 2; pl++) {
1679
3.19k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + v_off, NULL,
1680
3.19k
                             f->cur.stride[1], bw4, bh4, t->bx - 1,
1681
3.19k
                             t->by, 1 + pl, r[0][t->bx - 1].mv.mv[0],
1682
3.19k
                             &f->refp[r[0][t->bx - 1].ref.ref[0] - 1],
1683
3.19k
                             r[0][t->bx - 1].ref.ref[0] - 1,
1684
3.19k
                             t->frame_thread.pass != 2 ? left_filter_2d :
1685
3.19k
                                 f->frame_thread.b[(t->by * f->b4_stride) + t->bx - 1].filter2d);
1686
3.19k
                    if (res) return res;
1687
3.19k
                }
1688
1.59k
                h_off = 2;
1689
1.59k
            }
1690
2.32k
            if (bh4 == ss_ver) {
1691
1.29k
                const enum Filter2d top_filter_2d =
1692
1.29k
                    dav1d_filter_2d[t->a->filter[1][bx4]][t->a->filter[0][bx4]];
1693
3.87k
                for (int pl = 0; pl < 2; pl++) {
1694
2.58k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off, NULL,
1695
2.58k
                             f->cur.stride[1], bw4, bh4, t->bx, t->by - 1,
1696
2.58k
                             1 + pl, r[-1][t->bx].mv.mv[0],
1697
2.58k
                             &f->refp[r[-1][t->bx].ref.ref[0] - 1],
1698
2.58k
                             r[-1][t->bx].ref.ref[0] - 1,
1699
2.58k
                             t->frame_thread.pass != 2 ? top_filter_2d :
1700
2.58k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx].filter2d);
1701
2.58k
                    if (res) return res;
1702
2.58k
                }
1703
1.29k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1704
1.29k
            }
1705
6.96k
            for (int pl = 0; pl < 2; pl++) {
1706
4.64k
                res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off + v_off, NULL, f->cur.stride[1],
1707
4.64k
                         bw4, bh4, t->bx, t->by, 1 + pl, b->mv[0],
1708
4.64k
                         refp, b->ref[0], filter_2d);
1709
4.64k
                if (res) return res;
1710
4.64k
            }
1711
11.1k
        } else {
1712
11.1k
            if (imin(cbw4, cbh4) > 1 &&
1713
5.16k
                ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1714
4.50k
                 (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1715
826
            {
1716
2.47k
                for (int pl = 0; pl < 2; pl++) {
1717
1.65k
                    res = warp_affine(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff, NULL,
1718
1.65k
                                      f->cur.stride[1], b_dim, 1 + pl, refp,
1719
1.65k
                                      b->motion_mode == MM_WARP ? &t->warpmv :
1720
1.65k
                                          &f->frame_hdr->gmv[b->ref[0]]);
1721
1.65k
                    if (res) return res;
1722
1.65k
                }
1723
10.3k
            } else {
1724
31.0k
                for (int pl = 0; pl < 2; pl++) {
1725
20.6k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1726
20.6k
                             NULL, f->cur.stride[1],
1727
20.6k
                             bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1728
20.6k
                             t->bx & ~ss_hor, t->by & ~ss_ver,
1729
20.6k
                             1 + pl, b->mv[0], refp, b->ref[0], filter_2d);
1730
20.6k
                    if (res) return res;
1731
20.6k
                    if (b->motion_mode == MM_OBMC) {
1732
5.86k
                        res = obmc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1733
5.86k
                                   f->cur.stride[1], b_dim, 1 + pl, bx4, by4, w4, h4);
1734
5.86k
                        if (res) return res;
1735
5.86k
                    }
1736
20.6k
                }
1737
10.3k
            }
1738
11.1k
            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
816
                const uint8_t *const ii_mask = II_MASK(chr_layout_idx, bs, b);
1743
1744
2.44k
                for (int pl = 0; pl < 2; pl++) {
1745
1.63k
                    pixel *const tmp = bitfn(t->scratch.interintra);
1746
1.63k
                    pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1747
1.63k
                    enum IntraPredMode m =
1748
1.63k
                        b->interintra_mode == II_SMOOTH_PRED ?
1749
1.26k
                        SMOOTH_PRED : b->interintra_mode;
1750
1.63k
                    int angle = 0;
1751
1.63k
                    pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1752
1.63k
                    const pixel *top_sb_edge = NULL;
1753
1.63k
                    if (!(t->by & (f->sb_step - 1))) {
1754
412
                        top_sb_edge = f->ipred_edge[pl + 1];
1755
412
                        const int sby = t->by >> f->sb_shift;
1756
412
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1757
412
                    }
1758
1.63k
                    m = bytefn(dav1d_prepare_intra_edges)(t->bx >> ss_hor,
1759
1.63k
                                                          (t->bx >> ss_hor) >
1760
1.63k
                                                              (ts->tiling.col_start >> ss_hor),
1761
1.63k
                                                          t->by >> ss_ver,
1762
1.63k
                                                          (t->by >> ss_ver) >
1763
1.63k
                                                              (ts->tiling.row_start >> ss_ver),
1764
1.63k
                                                          ts->tiling.col_end >> ss_hor,
1765
1.63k
                                                          ts->tiling.row_end >> ss_ver,
1766
1.63k
                                                          0, uvdst, f->cur.stride[1],
1767
1.63k
                                                          top_sb_edge, m,
1768
1.63k
                                                          &angle, cbw4, cbh4, 0, tl_edge
1769
1.63k
                                                          HIGHBD_CALL_SUFFIX);
1770
1.63k
                    dsp->ipred.intra_pred[m](tmp, cbw4 * 4 * sizeof(pixel),
1771
1.63k
                                             tl_edge, cbw4 * 4, cbh4 * 4, 0, 0, 0
1772
1.63k
                                             HIGHBD_CALL_SUFFIX);
1773
1.63k
                    dsp->mc.blend(uvdst, f->cur.stride[1], tmp,
1774
1.63k
                                  cbw4 * 4, cbh4 * 4, ii_mask);
1775
1.63k
                }
1776
816
            }
1777
11.1k
        }
1778
1779
19.7k
    skip_inter_chroma_pred: {}
1780
19.7k
        t->tl_4x4_filter = filter_2d;
1781
19.7k
    } else {
1782
5.32k
        const enum Filter2d filter_2d = b->filter2d;
1783
        // Maximum super block size is 128x128
1784
5.32k
        int16_t (*tmp)[128 * 128] = t->scratch.compinter;
1785
5.32k
        int jnt_weight;
1786
5.32k
        uint8_t *const seg_mask = t->scratch.seg_mask;
1787
5.32k
        const uint8_t *mask;
1788
1789
15.9k
        for (int i = 0; i < 2; i++) {
1790
10.6k
            const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1791
1792
10.6k
            if (b->inter_mode == GLOBALMV_GLOBALMV && f->gmv_warp_allowed[b->ref[i]]) {
1793
242
                res = warp_affine(t, NULL, tmp[i], bw4 * 4, b_dim, 0, refp,
1794
242
                                  &f->frame_hdr->gmv[b->ref[i]]);
1795
242
                if (res) return res;
1796
10.4k
            } else {
1797
10.4k
                res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by, 0,
1798
10.4k
                         b->mv[i], refp, b->ref[i], filter_2d);
1799
10.4k
                if (res) return res;
1800
10.4k
            }
1801
10.6k
        }
1802
5.32k
        switch (b->comp_type) {
1803
3.71k
        case COMP_INTER_AVG:
1804
3.71k
            dsp->mc.avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1805
3.71k
                        bw4 * 4, bh4 * 4 HIGHBD_CALL_SUFFIX);
1806
3.71k
            break;
1807
430
        case COMP_INTER_WEIGHTED_AVG:
1808
430
            jnt_weight = f->jnt_weights[b->ref[0]][b->ref[1]];
1809
430
            dsp->mc.w_avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1810
430
                          bw4 * 4, bh4 * 4, jnt_weight HIGHBD_CALL_SUFFIX);
1811
430
            break;
1812
804
        case COMP_INTER_SEG:
1813
804
            dsp->mc.w_mask[chr_layout_idx](dst, f->cur.stride[0],
1814
804
                                           tmp[b->mask_sign], tmp[!b->mask_sign],
1815
804
                                           bw4 * 4, bh4 * 4, seg_mask,
1816
804
                                           b->mask_sign HIGHBD_CALL_SUFFIX);
1817
804
            mask = seg_mask;
1818
804
            break;
1819
377
        case COMP_INTER_WEDGE:
1820
377
            mask = WEDGE_MASK(0, bs, 0, b->wedge_idx);
1821
377
            dsp->mc.mask(dst, f->cur.stride[0],
1822
377
                         tmp[b->mask_sign], tmp[!b->mask_sign],
1823
377
                         bw4 * 4, bh4 * 4, mask HIGHBD_CALL_SUFFIX);
1824
377
            if (has_chroma)
1825
303
                mask = WEDGE_MASK(chr_layout_idx, bs, b->mask_sign, b->wedge_idx);
1826
377
            break;
1827
5.32k
        }
1828
1829
        // chroma
1830
12.3k
        if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1831
24.6k
            for (int i = 0; i < 2; i++) {
1832
16.4k
                const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1833
16.4k
                if (b->inter_mode == GLOBALMV_GLOBALMV &&
1834
1.83k
                    imin(cbw4, cbh4) > 1 && f->gmv_warp_allowed[b->ref[i]])
1835
254
                {
1836
254
                    res = warp_affine(t, NULL, tmp[i], bw4 * 4 >> ss_hor,
1837
254
                                      b_dim, 1 + pl,
1838
254
                                      refp, &f->frame_hdr->gmv[b->ref[i]]);
1839
254
                    if (res) return res;
1840
16.1k
                } else {
1841
16.1k
                    res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by,
1842
16.1k
                             1 + pl, b->mv[i], refp, b->ref[i], filter_2d);
1843
16.1k
                    if (res) return res;
1844
16.1k
                }
1845
16.4k
            }
1846
8.20k
            pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1847
8.20k
            switch (b->comp_type) {
1848
5.68k
            case COMP_INTER_AVG:
1849
5.68k
                dsp->mc.avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1850
5.68k
                            bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver
1851
5.68k
                            HIGHBD_CALL_SUFFIX);
1852
5.68k
                break;
1853
688
            case COMP_INTER_WEIGHTED_AVG:
1854
688
                dsp->mc.w_avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1855
688
                              bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, jnt_weight
1856
688
                              HIGHBD_CALL_SUFFIX);
1857
688
                break;
1858
606
            case COMP_INTER_WEDGE:
1859
1.83k
            case COMP_INTER_SEG:
1860
1.83k
                dsp->mc.mask(uvdst, f->cur.stride[1],
1861
1.83k
                             tmp[b->mask_sign], tmp[!b->mask_sign],
1862
1.83k
                             bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, mask
1863
1.83k
                             HIGHBD_CALL_SUFFIX);
1864
1.83k
                break;
1865
8.20k
            }
1866
8.20k
        }
1867
5.32k
    }
1868
1869
73.8k
    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
73.8k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1880
1881
73.8k
    if (b->skip) {
1882
        // reset coef contexts
1883
20.0k
        BlockContext *const a = t->a;
1884
20.0k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
1885
20.0k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
1886
20.0k
        if (has_chroma) {
1887
11.0k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
1888
11.0k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
1889
11.0k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
1890
11.0k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
1891
11.0k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
1892
11.0k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
1893
11.0k
        }
1894
20.0k
        return 0;
1895
20.0k
    }
1896
1897
53.7k
    const TxfmInfo *const uvtx = &dav1d_txfm_dimensions[b->uvtx];
1898
53.7k
    const TxfmInfo *const ytx = &dav1d_txfm_dimensions[b->max_ytx];
1899
53.7k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
1900
1901
108k
    for (int init_y = 0; init_y < bh4; init_y += 16) {
1902
111k
        for (int init_x = 0; init_x < bw4; init_x += 16) {
1903
            // coefficient coding & inverse transforms
1904
56.8k
            int y_off = !!init_y, y;
1905
56.8k
            dst += PXSTRIDE(f->cur.stride[0]) * 4 * init_y;
1906
114k
            for (y = init_y, t->by += init_y; y < imin(h4, init_y + 16);
1907
57.4k
                 y += ytx->h, y_off++)
1908
57.4k
            {
1909
57.4k
                int x, x_off = !!init_x;
1910
116k
                for (x = init_x, t->bx += init_x; x < imin(w4, init_x + 16);
1911
59.0k
                     x += ytx->w, x_off++)
1912
59.0k
                {
1913
59.0k
                    read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
1914
59.0k
                                   x_off, y_off, &dst[x * 4]);
1915
59.0k
                    t->bx += ytx->w;
1916
59.0k
                }
1917
57.4k
                dst += PXSTRIDE(f->cur.stride[0]) * 4 * ytx->h;
1918
57.4k
                t->bx -= x;
1919
57.4k
                t->by += ytx->h;
1920
57.4k
            }
1921
56.8k
            dst -= PXSTRIDE(f->cur.stride[0]) * 4 * y;
1922
56.8k
            t->by -= y;
1923
1924
            // chroma coefs and inverse transform
1925
56.8k
            if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1926
21.8k
                pixel *uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff +
1927
21.8k
                    (PXSTRIDE(f->cur.stride[1]) * init_y * 4 >> ss_ver);
1928
21.8k
                for (y = init_y >> ss_ver, t->by += init_y;
1929
44.0k
                     y < imin(ch4, (init_y + 16) >> ss_ver); y += uvtx->h)
1930
22.2k
                {
1931
22.2k
                    int x;
1932
22.2k
                    for (x = init_x >> ss_hor, t->bx += init_x;
1933
45.0k
                         x < imin(cw4, (init_x + 16) >> ss_hor); x += uvtx->w)
1934
22.8k
                    {
1935
22.8k
                        coef *cf;
1936
22.8k
                        int eob;
1937
22.8k
                        enum TxfmType txtp;
1938
22.8k
                        if (t->frame_thread.pass) {
1939
22.8k
                            const int p = t->frame_thread.pass & 1;
1940
22.8k
                            const int cbi = *ts->frame_thread[p].cbi++;
1941
22.8k
                            cf = ts->frame_thread[p].cf;
1942
22.8k
                            ts->frame_thread[p].cf += uvtx->w * uvtx->h * 16;
1943
22.8k
                            eob  = cbi >> 5;
1944
22.8k
                            txtp = cbi & 0x1f;
1945
22.8k
                        } 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
22.8k
                        if (eob >= 0) {
1964
4.87k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1965
0
                                coef_dump(cf, uvtx->h * 4, uvtx->w * 4, 3, "dq");
1966
4.87k
                            dsp->itx.itxfm_add[b->uvtx]
1967
4.87k
                                              [txtp](&uvdst[4 * x],
1968
4.87k
                                                     f->cur.stride[1],
1969
4.87k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1970
4.87k
                            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
4.87k
                        }
1974
22.8k
                        t->bx += uvtx->w << ss_hor;
1975
22.8k
                    }
1976
22.2k
                    uvdst += PXSTRIDE(f->cur.stride[1]) * 4 * uvtx->h;
1977
22.2k
                    t->bx -= x << ss_hor;
1978
22.2k
                    t->by += uvtx->h << ss_ver;
1979
22.2k
                }
1980
21.8k
                t->by -= y << ss_ver;
1981
21.8k
            }
1982
56.8k
        }
1983
54.8k
    }
1984
53.7k
    return 0;
1985
73.8k
}
1986
1987
48.1k
void bytefn(dav1d_filter_sbrow_deblock_cols)(Dav1dFrameContext *const f, const int sby) {
1988
48.1k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK) ||
1989
48.1k
        (!f->frame_hdr->loopfilter.level_y[0] && !f->frame_hdr->loopfilter.level_y[1]))
1990
0
    {
1991
0
        return;
1992
0
    }
1993
48.1k
    const int y = sby * f->sb_step * 4;
1994
48.1k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1995
48.1k
    pixel *const p[3] = {
1996
48.1k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
1997
48.1k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
1998
48.1k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
1999
48.1k
    };
2000
48.1k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2001
48.1k
    bytefn(dav1d_loopfilter_sbrow_cols)(f, p, mask, sby,
2002
48.1k
                                        f->lf.start_of_tile_row[sby]);
2003
48.1k
}
dav1d_filter_sbrow_deblock_cols_8bpc
Line
Count
Source
1987
22.7k
void bytefn(dav1d_filter_sbrow_deblock_cols)(Dav1dFrameContext *const f, const int sby) {
1988
22.7k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK) ||
1989
22.7k
        (!f->frame_hdr->loopfilter.level_y[0] && !f->frame_hdr->loopfilter.level_y[1]))
1990
0
    {
1991
0
        return;
1992
0
    }
1993
22.7k
    const int y = sby * f->sb_step * 4;
1994
22.7k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1995
22.7k
    pixel *const p[3] = {
1996
22.7k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
1997
22.7k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
1998
22.7k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
1999
22.7k
    };
2000
22.7k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2001
22.7k
    bytefn(dav1d_loopfilter_sbrow_cols)(f, p, mask, sby,
2002
22.7k
                                        f->lf.start_of_tile_row[sby]);
2003
22.7k
}
dav1d_filter_sbrow_deblock_cols_16bpc
Line
Count
Source
1987
25.3k
void bytefn(dav1d_filter_sbrow_deblock_cols)(Dav1dFrameContext *const f, const int sby) {
1988
25.3k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK) ||
1989
25.3k
        (!f->frame_hdr->loopfilter.level_y[0] && !f->frame_hdr->loopfilter.level_y[1]))
1990
0
    {
1991
0
        return;
1992
0
    }
1993
25.3k
    const int y = sby * f->sb_step * 4;
1994
25.3k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1995
25.3k
    pixel *const p[3] = {
1996
25.3k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
1997
25.3k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
1998
25.3k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
1999
25.3k
    };
2000
25.3k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2001
25.3k
    bytefn(dav1d_loopfilter_sbrow_cols)(f, p, mask, sby,
2002
25.3k
                                        f->lf.start_of_tile_row[sby]);
2003
25.3k
}
2004
2005
62.6k
void bytefn(dav1d_filter_sbrow_deblock_rows)(Dav1dFrameContext *const f, const int sby) {
2006
62.6k
    const int y = sby * f->sb_step * 4;
2007
62.6k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2008
62.6k
    pixel *const p[3] = {
2009
62.6k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2010
62.6k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2011
62.6k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2012
62.6k
    };
2013
62.6k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2014
62.6k
    if (f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK &&
2015
62.6k
        (f->frame_hdr->loopfilter.level_y[0] || f->frame_hdr->loopfilter.level_y[1]))
2016
48.0k
    {
2017
48.0k
        bytefn(dav1d_loopfilter_sbrow_rows)(f, p, mask, sby);
2018
48.0k
    }
2019
62.6k
    if (f->seq_hdr->cdef || f->lf.restore_planes) {
2020
        // Store loop filtered pixels required by CDEF / LR
2021
52.5k
        bytefn(dav1d_copy_lpf)(f, p, sby);
2022
52.5k
    }
2023
62.6k
}
dav1d_filter_sbrow_deblock_rows_8bpc
Line
Count
Source
2005
29.1k
void bytefn(dav1d_filter_sbrow_deblock_rows)(Dav1dFrameContext *const f, const int sby) {
2006
29.1k
    const int y = sby * f->sb_step * 4;
2007
29.1k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2008
29.1k
    pixel *const p[3] = {
2009
29.1k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2010
29.1k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2011
29.1k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2012
29.1k
    };
2013
29.1k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2014
29.1k
    if (f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK &&
2015
29.1k
        (f->frame_hdr->loopfilter.level_y[0] || f->frame_hdr->loopfilter.level_y[1]))
2016
22.7k
    {
2017
22.7k
        bytefn(dav1d_loopfilter_sbrow_rows)(f, p, mask, sby);
2018
22.7k
    }
2019
29.1k
    if (f->seq_hdr->cdef || f->lf.restore_planes) {
2020
        // Store loop filtered pixels required by CDEF / LR
2021
23.4k
        bytefn(dav1d_copy_lpf)(f, p, sby);
2022
23.4k
    }
2023
29.1k
}
dav1d_filter_sbrow_deblock_rows_16bpc
Line
Count
Source
2005
33.4k
void bytefn(dav1d_filter_sbrow_deblock_rows)(Dav1dFrameContext *const f, const int sby) {
2006
33.4k
    const int y = sby * f->sb_step * 4;
2007
33.4k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2008
33.4k
    pixel *const p[3] = {
2009
33.4k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2010
33.4k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2011
33.4k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2012
33.4k
    };
2013
33.4k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2014
33.4k
    if (f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK &&
2015
33.4k
        (f->frame_hdr->loopfilter.level_y[0] || f->frame_hdr->loopfilter.level_y[1]))
2016
25.3k
    {
2017
25.3k
        bytefn(dav1d_loopfilter_sbrow_rows)(f, p, mask, sby);
2018
25.3k
    }
2019
33.4k
    if (f->seq_hdr->cdef || f->lf.restore_planes) {
2020
        // Store loop filtered pixels required by CDEF / LR
2021
29.1k
        bytefn(dav1d_copy_lpf)(f, p, sby);
2022
29.1k
    }
2023
33.4k
}
2024
2025
37.4k
void bytefn(dav1d_filter_sbrow_cdef)(Dav1dTaskContext *const tc, const int sby) {
2026
37.4k
    const Dav1dFrameContext *const f = tc->f;
2027
37.4k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_CDEF)) return;
2028
37.4k
    const int sbsz = f->sb_step;
2029
37.4k
    const int y = sby * sbsz * 4;
2030
37.4k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2031
37.4k
    pixel *const p[3] = {
2032
37.4k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2033
37.4k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2034
37.4k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2035
37.4k
    };
2036
37.4k
    Av1Filter *prev_mask = f->lf.mask + ((sby - 1) >> !f->seq_hdr->sb128) * f->sb128w;
2037
37.4k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2038
37.4k
    const int start = sby * sbsz;
2039
37.4k
    if (sby) {
2040
23.6k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2041
23.6k
        pixel *p_up[3] = {
2042
23.6k
            p[0] - 8 * PXSTRIDE(f->cur.stride[0]),
2043
23.6k
            p[1] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2044
23.6k
            p[2] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2045
23.6k
        };
2046
23.6k
        bytefn(dav1d_cdef_brow)(tc, p_up, prev_mask, start - 2, start, 1, sby);
2047
23.6k
    }
2048
37.4k
    const int n_blks = sbsz - 2 * (sby + 1 < f->sbh);
2049
37.4k
    const int end = imin(start + n_blks, f->bh);
2050
37.4k
    bytefn(dav1d_cdef_brow)(tc, p, mask, start, end, 0, sby);
2051
37.4k
}
dav1d_filter_sbrow_cdef_8bpc
Line
Count
Source
2025
18.3k
void bytefn(dav1d_filter_sbrow_cdef)(Dav1dTaskContext *const tc, const int sby) {
2026
18.3k
    const Dav1dFrameContext *const f = tc->f;
2027
18.3k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_CDEF)) return;
2028
18.3k
    const int sbsz = f->sb_step;
2029
18.3k
    const int y = sby * sbsz * 4;
2030
18.3k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2031
18.3k
    pixel *const p[3] = {
2032
18.3k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2033
18.3k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2034
18.3k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2035
18.3k
    };
2036
18.3k
    Av1Filter *prev_mask = f->lf.mask + ((sby - 1) >> !f->seq_hdr->sb128) * f->sb128w;
2037
18.3k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2038
18.3k
    const int start = sby * sbsz;
2039
18.3k
    if (sby) {
2040
12.3k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2041
12.3k
        pixel *p_up[3] = {
2042
12.3k
            p[0] - 8 * PXSTRIDE(f->cur.stride[0]),
2043
12.3k
            p[1] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2044
12.3k
            p[2] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2045
12.3k
        };
2046
12.3k
        bytefn(dav1d_cdef_brow)(tc, p_up, prev_mask, start - 2, start, 1, sby);
2047
12.3k
    }
2048
18.3k
    const int n_blks = sbsz - 2 * (sby + 1 < f->sbh);
2049
18.3k
    const int end = imin(start + n_blks, f->bh);
2050
18.3k
    bytefn(dav1d_cdef_brow)(tc, p, mask, start, end, 0, sby);
2051
18.3k
}
dav1d_filter_sbrow_cdef_16bpc
Line
Count
Source
2025
19.0k
void bytefn(dav1d_filter_sbrow_cdef)(Dav1dTaskContext *const tc, const int sby) {
2026
19.0k
    const Dav1dFrameContext *const f = tc->f;
2027
19.0k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_CDEF)) return;
2028
19.0k
    const int sbsz = f->sb_step;
2029
19.0k
    const int y = sby * sbsz * 4;
2030
19.0k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2031
19.0k
    pixel *const p[3] = {
2032
19.0k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2033
19.0k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2034
19.0k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2035
19.0k
    };
2036
19.0k
    Av1Filter *prev_mask = f->lf.mask + ((sby - 1) >> !f->seq_hdr->sb128) * f->sb128w;
2037
19.0k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2038
19.0k
    const int start = sby * sbsz;
2039
19.0k
    if (sby) {
2040
11.2k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2041
11.2k
        pixel *p_up[3] = {
2042
11.2k
            p[0] - 8 * PXSTRIDE(f->cur.stride[0]),
2043
11.2k
            p[1] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2044
11.2k
            p[2] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2045
11.2k
        };
2046
11.2k
        bytefn(dav1d_cdef_brow)(tc, p_up, prev_mask, start - 2, start, 1, sby);
2047
11.2k
    }
2048
19.0k
    const int n_blks = sbsz - 2 * (sby + 1 < f->sbh);
2049
19.0k
    const int end = imin(start + n_blks, f->bh);
2050
19.0k
    bytefn(dav1d_cdef_brow)(tc, p, mask, start, end, 0, sby);
2051
19.0k
}
2052
2053
14.6k
void bytefn(dav1d_filter_sbrow_resize)(Dav1dFrameContext *const f, const int sby) {
2054
14.6k
    const int sbsz = f->sb_step;
2055
14.6k
    const int y = sby * sbsz * 4;
2056
14.6k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2057
14.6k
    const pixel *const p[3] = {
2058
14.6k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2059
14.6k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2060
14.6k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2061
14.6k
    };
2062
14.6k
    pixel *const sr_p[3] = {
2063
14.6k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2064
14.6k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2065
14.6k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2066
14.6k
    };
2067
14.6k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400;
2068
48.9k
    for (int pl = 0; pl < 1 + 2 * has_chroma; pl++) {
2069
34.3k
        const int ss_ver = pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2070
34.3k
        const int h_start = 8 * !!sby >> ss_ver;
2071
34.3k
        const ptrdiff_t dst_stride = f->sr_cur.p.stride[!!pl];
2072
34.3k
        pixel *dst = sr_p[pl] - h_start * PXSTRIDE(dst_stride);
2073
34.3k
        const ptrdiff_t src_stride = f->cur.stride[!!pl];
2074
34.3k
        const pixel *src = p[pl] - h_start * PXSTRIDE(src_stride);
2075
34.3k
        const int h_end = 4 * (sbsz - 2 * (sby + 1 < f->sbh)) >> ss_ver;
2076
34.3k
        const int ss_hor = pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2077
34.3k
        const int dst_w = (f->sr_cur.p.p.w + ss_hor) >> ss_hor;
2078
34.3k
        const int src_w = (4 * f->bw + ss_hor) >> ss_hor;
2079
34.3k
        const int img_h = (f->cur.p.h - sbsz * 4 * sby + ss_ver) >> ss_ver;
2080
2081
34.3k
        f->dsp->mc.resize(dst, dst_stride, src, src_stride, dst_w,
2082
34.3k
                          imin(img_h, h_end) + h_start, src_w,
2083
34.3k
                          f->resize_step[!!pl], f->resize_start[!!pl]
2084
34.3k
                          HIGHBD_CALL_SUFFIX);
2085
34.3k
    }
2086
14.6k
}
dav1d_filter_sbrow_resize_8bpc
Line
Count
Source
2053
7.70k
void bytefn(dav1d_filter_sbrow_resize)(Dav1dFrameContext *const f, const int sby) {
2054
7.70k
    const int sbsz = f->sb_step;
2055
7.70k
    const int y = sby * sbsz * 4;
2056
7.70k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2057
7.70k
    const pixel *const p[3] = {
2058
7.70k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2059
7.70k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2060
7.70k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2061
7.70k
    };
2062
7.70k
    pixel *const sr_p[3] = {
2063
7.70k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2064
7.70k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2065
7.70k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2066
7.70k
    };
2067
7.70k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400;
2068
26.0k
    for (int pl = 0; pl < 1 + 2 * has_chroma; pl++) {
2069
18.3k
        const int ss_ver = pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2070
18.3k
        const int h_start = 8 * !!sby >> ss_ver;
2071
18.3k
        const ptrdiff_t dst_stride = f->sr_cur.p.stride[!!pl];
2072
18.3k
        pixel *dst = sr_p[pl] - h_start * PXSTRIDE(dst_stride);
2073
18.3k
        const ptrdiff_t src_stride = f->cur.stride[!!pl];
2074
18.3k
        const pixel *src = p[pl] - h_start * PXSTRIDE(src_stride);
2075
18.3k
        const int h_end = 4 * (sbsz - 2 * (sby + 1 < f->sbh)) >> ss_ver;
2076
18.3k
        const int ss_hor = pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2077
18.3k
        const int dst_w = (f->sr_cur.p.p.w + ss_hor) >> ss_hor;
2078
18.3k
        const int src_w = (4 * f->bw + ss_hor) >> ss_hor;
2079
18.3k
        const int img_h = (f->cur.p.h - sbsz * 4 * sby + ss_ver) >> ss_ver;
2080
2081
18.3k
        f->dsp->mc.resize(dst, dst_stride, src, src_stride, dst_w,
2082
18.3k
                          imin(img_h, h_end) + h_start, src_w,
2083
18.3k
                          f->resize_step[!!pl], f->resize_start[!!pl]
2084
18.3k
                          HIGHBD_CALL_SUFFIX);
2085
18.3k
    }
2086
7.70k
}
dav1d_filter_sbrow_resize_16bpc
Line
Count
Source
2053
6.91k
void bytefn(dav1d_filter_sbrow_resize)(Dav1dFrameContext *const f, const int sby) {
2054
6.91k
    const int sbsz = f->sb_step;
2055
6.91k
    const int y = sby * sbsz * 4;
2056
6.91k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2057
6.91k
    const pixel *const p[3] = {
2058
6.91k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2059
6.91k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2060
6.91k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2061
6.91k
    };
2062
6.91k
    pixel *const sr_p[3] = {
2063
6.91k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2064
6.91k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2065
6.91k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2066
6.91k
    };
2067
6.91k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400;
2068
22.9k
    for (int pl = 0; pl < 1 + 2 * has_chroma; pl++) {
2069
16.0k
        const int ss_ver = pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2070
16.0k
        const int h_start = 8 * !!sby >> ss_ver;
2071
16.0k
        const ptrdiff_t dst_stride = f->sr_cur.p.stride[!!pl];
2072
16.0k
        pixel *dst = sr_p[pl] - h_start * PXSTRIDE(dst_stride);
2073
16.0k
        const ptrdiff_t src_stride = f->cur.stride[!!pl];
2074
16.0k
        const pixel *src = p[pl] - h_start * PXSTRIDE(src_stride);
2075
16.0k
        const int h_end = 4 * (sbsz - 2 * (sby + 1 < f->sbh)) >> ss_ver;
2076
16.0k
        const int ss_hor = pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2077
16.0k
        const int dst_w = (f->sr_cur.p.p.w + ss_hor) >> ss_hor;
2078
16.0k
        const int src_w = (4 * f->bw + ss_hor) >> ss_hor;
2079
16.0k
        const int img_h = (f->cur.p.h - sbsz * 4 * sby + ss_ver) >> ss_ver;
2080
2081
16.0k
        f->dsp->mc.resize(dst, dst_stride, src, src_stride, dst_w,
2082
16.0k
                          imin(img_h, h_end) + h_start, src_w,
2083
16.0k
                          f->resize_step[!!pl], f->resize_start[!!pl]
2084
16.0k
                          HIGHBD_CALL_SUFFIX);
2085
16.0k
    }
2086
6.91k
}
2087
2088
29.2k
void bytefn(dav1d_filter_sbrow_lr)(Dav1dFrameContext *const f, const int sby) {
2089
29.2k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_RESTORATION)) return;
2090
29.2k
    const int y = sby * f->sb_step * 4;
2091
29.2k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2092
29.2k
    pixel *const sr_p[3] = {
2093
29.2k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2094
29.2k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2095
29.2k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2096
29.2k
    };
2097
29.2k
    bytefn(dav1d_lr_sbrow)(f, sr_p, sby);
2098
29.2k
}
dav1d_filter_sbrow_lr_8bpc
Line
Count
Source
2088
12.7k
void bytefn(dav1d_filter_sbrow_lr)(Dav1dFrameContext *const f, const int sby) {
2089
12.7k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_RESTORATION)) return;
2090
12.7k
    const int y = sby * f->sb_step * 4;
2091
12.7k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2092
12.7k
    pixel *const sr_p[3] = {
2093
12.7k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2094
12.7k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2095
12.7k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2096
12.7k
    };
2097
12.7k
    bytefn(dav1d_lr_sbrow)(f, sr_p, sby);
2098
12.7k
}
dav1d_filter_sbrow_lr_16bpc
Line
Count
Source
2088
16.4k
void bytefn(dav1d_filter_sbrow_lr)(Dav1dFrameContext *const f, const int sby) {
2089
16.4k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_RESTORATION)) return;
2090
16.4k
    const int y = sby * f->sb_step * 4;
2091
16.4k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2092
16.4k
    pixel *const sr_p[3] = {
2093
16.4k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2094
16.4k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2095
16.4k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2096
16.4k
    };
2097
16.4k
    bytefn(dav1d_lr_sbrow)(f, sr_p, sby);
2098
16.4k
}
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
76.3k
void bytefn(dav1d_backup_ipred_edge)(Dav1dTaskContext *const t) {
2112
76.3k
    const Dav1dFrameContext *const f = t->f;
2113
76.3k
    Dav1dTileState *const ts = t->ts;
2114
76.3k
    const int sby = t->by >> f->sb_shift;
2115
76.3k
    const int sby_off = f->sb128w * 128 * sby;
2116
76.3k
    const int x_off = ts->tiling.col_start;
2117
2118
76.3k
    const pixel *const y =
2119
76.3k
        ((const pixel *) f->cur.data[0]) + x_off * 4 +
2120
76.3k
                    ((t->by + f->sb_step) * 4 - 1) * PXSTRIDE(f->cur.stride[0]);
2121
76.3k
    pixel_copy(&f->ipred_edge[0][sby_off + x_off * 4], y,
2122
76.3k
               4 * (ts->tiling.col_end - x_off));
2123
2124
76.3k
    if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
2125
53.4k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2126
53.4k
        const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2127
2128
53.4k
        const ptrdiff_t uv_off = (x_off * 4 >> ss_hor) +
2129
53.4k
            (((t->by + f->sb_step) * 4 >> ss_ver) - 1) * PXSTRIDE(f->cur.stride[1]);
2130
160k
        for (int pl = 1; pl <= 2; pl++)
2131
106k
            pixel_copy(&f->ipred_edge[pl][sby_off + (x_off * 4 >> ss_hor)],
2132
50.3k
                       &((const pixel *) f->cur.data[pl])[uv_off],
2133
50.3k
                       4 * (ts->tiling.col_end - x_off) >> ss_hor);
2134
53.4k
    }
2135
76.3k
}
dav1d_backup_ipred_edge_8bpc
Line
Count
Source
2111
36.3k
void bytefn(dav1d_backup_ipred_edge)(Dav1dTaskContext *const t) {
2112
36.3k
    const Dav1dFrameContext *const f = t->f;
2113
36.3k
    Dav1dTileState *const ts = t->ts;
2114
36.3k
    const int sby = t->by >> f->sb_shift;
2115
36.3k
    const int sby_off = f->sb128w * 128 * sby;
2116
36.3k
    const int x_off = ts->tiling.col_start;
2117
2118
36.3k
    const pixel *const y =
2119
36.3k
        ((const pixel *) f->cur.data[0]) + x_off * 4 +
2120
36.3k
                    ((t->by + f->sb_step) * 4 - 1) * PXSTRIDE(f->cur.stride[0]);
2121
36.3k
    pixel_copy(&f->ipred_edge[0][sby_off + x_off * 4], y,
2122
36.3k
               4 * (ts->tiling.col_end - x_off));
2123
2124
36.3k
    if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
2125
25.1k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2126
25.1k
        const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2127
2128
25.1k
        const ptrdiff_t uv_off = (x_off * 4 >> ss_hor) +
2129
25.1k
            (((t->by + f->sb_step) * 4 >> ss_ver) - 1) * PXSTRIDE(f->cur.stride[1]);
2130
75.5k
        for (int pl = 1; pl <= 2; pl++)
2131
50.3k
            pixel_copy(&f->ipred_edge[pl][sby_off + (x_off * 4 >> ss_hor)],
2132
50.3k
                       &((const pixel *) f->cur.data[pl])[uv_off],
2133
50.3k
                       4 * (ts->tiling.col_end - x_off) >> ss_hor);
2134
25.1k
    }
2135
36.3k
}
dav1d_backup_ipred_edge_16bpc
Line
Count
Source
2111
39.9k
void bytefn(dav1d_backup_ipred_edge)(Dav1dTaskContext *const t) {
2112
39.9k
    const Dav1dFrameContext *const f = t->f;
2113
39.9k
    Dav1dTileState *const ts = t->ts;
2114
39.9k
    const int sby = t->by >> f->sb_shift;
2115
39.9k
    const int sby_off = f->sb128w * 128 * sby;
2116
39.9k
    const int x_off = ts->tiling.col_start;
2117
2118
39.9k
    const pixel *const y =
2119
39.9k
        ((const pixel *) f->cur.data[0]) + x_off * 4 +
2120
39.9k
                    ((t->by + f->sb_step) * 4 - 1) * PXSTRIDE(f->cur.stride[0]);
2121
39.9k
    pixel_copy(&f->ipred_edge[0][sby_off + x_off * 4], y,
2122
39.9k
               4 * (ts->tiling.col_end - x_off));
2123
2124
39.9k
    if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
2125
28.2k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2126
28.2k
        const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2127
2128
28.2k
        const ptrdiff_t uv_off = (x_off * 4 >> ss_hor) +
2129
28.2k
            (((t->by + f->sb_step) * 4 >> ss_ver) - 1) * PXSTRIDE(f->cur.stride[1]);
2130
84.7k
        for (int pl = 1; pl <= 2; pl++)
2131
56.4k
            pixel_copy(&f->ipred_edge[pl][sby_off + (x_off * 4 >> ss_hor)],
2132
28.2k
                       &((const pixel *) f->cur.data[pl])[uv_off],
2133
28.2k
                       4 * (ts->tiling.col_end - x_off) >> ss_hor);
2134
28.2k
    }
2135
39.9k
}
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
17.8k
{
2142
17.8k
    const Dav1dFrameContext *const f = t->f;
2143
17.8k
    pixel *const pal = t->frame_thread.pass ?
2144
17.8k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2145
17.8k
                            ((t->bx >> 1) + (t->by & 1))][0] :
2146
17.8k
        bytefn(t->scratch.pal)[0];
2147
83.5k
    for (int x = 0; x < bw4; x++)
2148
65.6k
        memcpy(bytefn(t->al_pal)[0][bx4 + x][0], pal, 8 * sizeof(pixel));
2149
71.2k
    for (int y = 0; y < bh4; y++)
2150
53.4k
        memcpy(bytefn(t->al_pal)[1][by4 + y][0], pal, 8 * sizeof(pixel));
2151
17.8k
}
dav1d_copy_pal_block_y_8bpc
Line
Count
Source
2141
7.89k
{
2142
7.89k
    const Dav1dFrameContext *const f = t->f;
2143
7.89k
    pixel *const pal = t->frame_thread.pass ?
2144
7.89k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2145
7.89k
                            ((t->bx >> 1) + (t->by & 1))][0] :
2146
7.89k
        bytefn(t->scratch.pal)[0];
2147
37.8k
    for (int x = 0; x < bw4; x++)
2148
29.9k
        memcpy(bytefn(t->al_pal)[0][bx4 + x][0], pal, 8 * sizeof(pixel));
2149
31.9k
    for (int y = 0; y < bh4; y++)
2150
24.0k
        memcpy(bytefn(t->al_pal)[1][by4 + y][0], pal, 8 * sizeof(pixel));
2151
7.89k
}
dav1d_copy_pal_block_y_16bpc
Line
Count
Source
2141
9.96k
{
2142
9.96k
    const Dav1dFrameContext *const f = t->f;
2143
9.96k
    pixel *const pal = t->frame_thread.pass ?
2144
9.96k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2145
9.96k
                            ((t->bx >> 1) + (t->by & 1))][0] :
2146
9.96k
        bytefn(t->scratch.pal)[0];
2147
45.7k
    for (int x = 0; x < bw4; x++)
2148
35.7k
        memcpy(bytefn(t->al_pal)[0][bx4 + x][0], pal, 8 * sizeof(pixel));
2149
39.3k
    for (int y = 0; y < bh4; y++)
2150
29.3k
        memcpy(bytefn(t->al_pal)[1][by4 + y][0], pal, 8 * sizeof(pixel));
2151
9.96k
}
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
6.50k
{
2158
6.50k
    const Dav1dFrameContext *const f = t->f;
2159
6.50k
    const pixel (*const pal)[8] = t->frame_thread.pass ?
2160
6.50k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2161
6.50k
                            ((t->bx >> 1) + (t->by & 1))] :
2162
6.50k
        bytefn(t->scratch.pal);
2163
    // see aomedia bug 2183 for why we use luma coordinates here
2164
19.5k
    for (int pl = 1; pl <= 2; pl++) {
2165
73.6k
        for (int x = 0; x < bw4; x++)
2166
60.6k
            memcpy(bytefn(t->al_pal)[0][bx4 + x][pl], pal[pl], 8 * sizeof(pixel));
2167
64.0k
        for (int y = 0; y < bh4; y++)
2168
51.0k
            memcpy(bytefn(t->al_pal)[1][by4 + y][pl], pal[pl], 8 * sizeof(pixel));
2169
13.0k
    }
2170
6.50k
}
dav1d_copy_pal_block_uv_8bpc
Line
Count
Source
2157
2.88k
{
2158
2.88k
    const Dav1dFrameContext *const f = t->f;
2159
2.88k
    const pixel (*const pal)[8] = t->frame_thread.pass ?
2160
2.88k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2161
2.88k
                            ((t->bx >> 1) + (t->by & 1))] :
2162
2.88k
        bytefn(t->scratch.pal);
2163
    // see aomedia bug 2183 for why we use luma coordinates here
2164
8.64k
    for (int pl = 1; pl <= 2; pl++) {
2165
33.9k
        for (int x = 0; x < bw4; x++)
2166
28.1k
            memcpy(bytefn(t->al_pal)[0][bx4 + x][pl], pal[pl], 8 * sizeof(pixel));
2167
28.6k
        for (int y = 0; y < bh4; y++)
2168
22.8k
            memcpy(bytefn(t->al_pal)[1][by4 + y][pl], pal[pl], 8 * sizeof(pixel));
2169
5.76k
    }
2170
2.88k
}
dav1d_copy_pal_block_uv_16bpc
Line
Count
Source
2157
3.61k
{
2158
3.61k
    const Dav1dFrameContext *const f = t->f;
2159
3.61k
    const pixel (*const pal)[8] = t->frame_thread.pass ?
2160
3.61k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2161
3.61k
                            ((t->bx >> 1) + (t->by & 1))] :
2162
3.61k
        bytefn(t->scratch.pal);
2163
    // see aomedia bug 2183 for why we use luma coordinates here
2164
10.8k
    for (int pl = 1; pl <= 2; pl++) {
2165
39.7k
        for (int x = 0; x < bw4; x++)
2166
32.4k
            memcpy(bytefn(t->al_pal)[0][bx4 + x][pl], pal[pl], 8 * sizeof(pixel));
2167
35.3k
        for (int y = 0; y < bh4; y++)
2168
28.1k
            memcpy(bytefn(t->al_pal)[1][by4 + y][pl], pal[pl], 8 * sizeof(pixel));
2169
7.23k
    }
2170
3.61k
}
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
24.3k
{
2176
24.3k
    Dav1dTileState *const ts = t->ts;
2177
24.3k
    const Dav1dFrameContext *const f = t->f;
2178
24.3k
    const int pal_sz = b->pal_sz[pl] = dav1d_msac_decode_symbol_adapt8(&ts->msac,
2179
24.3k
                                           ts->cdf.m.pal_sz[pl][sz_ctx], 6) + 2;
2180
24.3k
    pixel cache[16], used_cache[8];
2181
24.3k
    int l_cache = pl ? t->pal_sz_uv[1][by4] : t->l.pal_sz[by4];
2182
24.3k
    int n_cache = 0;
2183
    // don't reuse above palette outside SB64 boundaries
2184
24.3k
    int a_cache = by4 & 15 ? pl ? t->pal_sz_uv[0][bx4] : t->a->pal_sz[bx4] : 0;
2185
24.3k
    const pixel *l = bytefn(t->al_pal)[1][by4][pl];
2186
24.3k
    const pixel *a = bytefn(t->al_pal)[0][bx4][pl];
2187
2188
    // fill/sort cache
2189
39.6k
    while (l_cache && a_cache) {
2190
15.3k
        if (*l < *a) {
2191
5.74k
            if (!n_cache || cache[n_cache - 1] != *l)
2192
5.71k
                cache[n_cache++] = *l;
2193
5.74k
            l++;
2194
5.74k
            l_cache--;
2195
9.59k
        } else {
2196
9.59k
            if (*a == *l) {
2197
3.96k
                l++;
2198
3.96k
                l_cache--;
2199
3.96k
            }
2200
9.59k
            if (!n_cache || cache[n_cache - 1] != *a)
2201
9.23k
                cache[n_cache++] = *a;
2202
9.59k
            a++;
2203
9.59k
            a_cache--;
2204
9.59k
        }
2205
15.3k
    }
2206
24.3k
    if (l_cache) {
2207
28.7k
        do {
2208
28.7k
            if (!n_cache || cache[n_cache - 1] != *l)
2209
23.5k
                cache[n_cache++] = *l;
2210
28.7k
            l++;
2211
28.7k
        } while (--l_cache > 0);
2212
17.3k
    } else if (a_cache) {
2213
19.7k
        do {
2214
19.7k
            if (!n_cache || cache[n_cache - 1] != *a)
2215
15.9k
                cache[n_cache++] = *a;
2216
19.7k
            a++;
2217
19.7k
        } while (--a_cache > 0);
2218
5.13k
    }
2219
2220
    // find reused cache entries
2221
24.3k
    int i = 0;
2222
72.4k
    for (int n = 0; n < n_cache && i < pal_sz; n++)
2223
48.0k
        if (dav1d_msac_decode_bool_equi(&ts->msac))
2224
24.1k
            used_cache[i++] = cache[n];
2225
24.3k
    const int n_used_cache = i;
2226
2227
    // parse new entries
2228
24.3k
    pixel *const pal = t->frame_thread.pass ?
2229
24.3k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2230
24.3k
                            ((t->bx >> 1) + (t->by & 1))][pl] :
2231
18.4E
        bytefn(t->scratch.pal)[pl];
2232
24.3k
    if (i < pal_sz) {
2233
21.1k
        const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2234
21.1k
        int prev = pal[i++] = dav1d_msac_decode_bools(&ts->msac, bpc);
2235
2236
21.1k
        if (i < pal_sz) {
2237
19.1k
            int bits = bpc - 3 + dav1d_msac_decode_bools(&ts->msac, 2);
2238
19.1k
            const int max = (1 << bpc) - 1;
2239
2240
43.8k
            do {
2241
43.8k
                const int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2242
43.8k
                prev = pal[i++] = imin(prev + delta + !pl, max);
2243
43.8k
                if (prev + !pl >= max) {
2244
25.2k
                    for (; i < pal_sz; i++)
2245
16.4k
                        pal[i] = max;
2246
8.82k
                    break;
2247
8.82k
                }
2248
35.0k
                bits = imin(bits, 1 + ulog2(max - prev - !pl));
2249
35.0k
            } while (i < pal_sz);
2250
19.1k
        }
2251
2252
        // merge cache+new entries
2253
21.1k
        int n = 0, m = n_used_cache;
2254
118k
        for (i = 0; i < pal_sz; i++) {
2255
96.9k
            if (n < n_used_cache && (m >= pal_sz || used_cache[n] <= pal[m])) {
2256
15.5k
                pal[i] = used_cache[n++];
2257
81.4k
            } else {
2258
81.4k
                assert(m < pal_sz);
2259
81.4k
                pal[i] = pal[m++];
2260
81.4k
            }
2261
96.9k
        }
2262
21.1k
    } else {
2263
3.20k
        memcpy(pal, used_cache, n_used_cache * sizeof(*used_cache));
2264
3.20k
    }
2265
2266
24.3k
    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
24.3k
}
dav1d_read_pal_plane_8bpc
Line
Count
Source
2175
10.7k
{
2176
10.7k
    Dav1dTileState *const ts = t->ts;
2177
10.7k
    const Dav1dFrameContext *const f = t->f;
2178
10.7k
    const int pal_sz = b->pal_sz[pl] = dav1d_msac_decode_symbol_adapt8(&ts->msac,
2179
10.7k
                                           ts->cdf.m.pal_sz[pl][sz_ctx], 6) + 2;
2180
10.7k
    pixel cache[16], used_cache[8];
2181
10.7k
    int l_cache = pl ? t->pal_sz_uv[1][by4] : t->l.pal_sz[by4];
2182
10.7k
    int n_cache = 0;
2183
    // don't reuse above palette outside SB64 boundaries
2184
10.7k
    int a_cache = by4 & 15 ? pl ? t->pal_sz_uv[0][bx4] : t->a->pal_sz[bx4] : 0;
2185
10.7k
    const pixel *l = bytefn(t->al_pal)[1][by4][pl];
2186
10.7k
    const pixel *a = bytefn(t->al_pal)[0][bx4][pl];
2187
2188
    // fill/sort cache
2189
17.5k
    while (l_cache && a_cache) {
2190
6.79k
        if (*l < *a) {
2191
2.59k
            if (!n_cache || cache[n_cache - 1] != *l)
2192
2.57k
                cache[n_cache++] = *l;
2193
2.59k
            l++;
2194
2.59k
            l_cache--;
2195
4.19k
        } else {
2196
4.19k
            if (*a == *l) {
2197
1.67k
                l++;
2198
1.67k
                l_cache--;
2199
1.67k
            }
2200
4.19k
            if (!n_cache || cache[n_cache - 1] != *a)
2201
4.04k
                cache[n_cache++] = *a;
2202
4.19k
            a++;
2203
4.19k
            a_cache--;
2204
4.19k
        }
2205
6.79k
    }
2206
10.7k
    if (l_cache) {
2207
12.2k
        do {
2208
12.2k
            if (!n_cache || cache[n_cache - 1] != *l)
2209
10.0k
                cache[n_cache++] = *l;
2210
12.2k
            l++;
2211
12.2k
        } while (--l_cache > 0);
2212
7.81k
    } else if (a_cache) {
2213
8.31k
        do {
2214
8.31k
            if (!n_cache || cache[n_cache - 1] != *a)
2215
6.52k
                cache[n_cache++] = *a;
2216
8.31k
            a++;
2217
8.31k
        } while (--a_cache > 0);
2218
2.16k
    }
2219
2220
    // find reused cache entries
2221
10.7k
    int i = 0;
2222
31.2k
    for (int n = 0; n < n_cache && i < pal_sz; n++)
2223
20.4k
        if (dav1d_msac_decode_bool_equi(&ts->msac))
2224
10.2k
            used_cache[i++] = cache[n];
2225
10.7k
    const int n_used_cache = i;
2226
2227
    // parse new entries
2228
10.7k
    pixel *const pal = t->frame_thread.pass ?
2229
10.7k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2230
10.7k
                            ((t->bx >> 1) + (t->by & 1))][pl] :
2231
18.4E
        bytefn(t->scratch.pal)[pl];
2232
10.7k
    if (i < pal_sz) {
2233
9.43k
        const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2234
9.43k
        int prev = pal[i++] = dav1d_msac_decode_bools(&ts->msac, bpc);
2235
2236
9.43k
        if (i < pal_sz) {
2237
8.57k
            int bits = bpc - 3 + dav1d_msac_decode_bools(&ts->msac, 2);
2238
8.57k
            const int max = (1 << bpc) - 1;
2239
2240
19.3k
            do {
2241
19.3k
                const int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2242
19.3k
                prev = pal[i++] = imin(prev + delta + !pl, max);
2243
19.3k
                if (prev + !pl >= max) {
2244
11.6k
                    for (; i < pal_sz; i++)
2245
7.67k
                        pal[i] = max;
2246
4.02k
                    break;
2247
4.02k
                }
2248
15.2k
                bits = imin(bits, 1 + ulog2(max - prev - !pl));
2249
15.2k
            } while (i < pal_sz);
2250
8.57k
        }
2251
2252
        // merge cache+new entries
2253
9.43k
        int n = 0, m = n_used_cache;
2254
52.5k
        for (i = 0; i < pal_sz; i++) {
2255
43.1k
            if (n < n_used_cache && (m >= pal_sz || used_cache[n] <= pal[m])) {
2256
6.68k
                pal[i] = used_cache[n++];
2257
36.4k
            } else {
2258
36.4k
                assert(m < pal_sz);
2259
36.4k
                pal[i] = pal[m++];
2260
36.4k
            }
2261
43.1k
        }
2262
9.43k
    } else {
2263
1.33k
        memcpy(pal, used_cache, n_used_cache * sizeof(*used_cache));
2264
1.33k
    }
2265
2266
10.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
10.7k
}
dav1d_read_pal_plane_16bpc
Line
Count
Source
2175
13.5k
{
2176
13.5k
    Dav1dTileState *const ts = t->ts;
2177
13.5k
    const Dav1dFrameContext *const f = t->f;
2178
13.5k
    const int pal_sz = b->pal_sz[pl] = dav1d_msac_decode_symbol_adapt8(&ts->msac,
2179
13.5k
                                           ts->cdf.m.pal_sz[pl][sz_ctx], 6) + 2;
2180
13.5k
    pixel cache[16], used_cache[8];
2181
13.5k
    int l_cache = pl ? t->pal_sz_uv[1][by4] : t->l.pal_sz[by4];
2182
13.5k
    int n_cache = 0;
2183
    // don't reuse above palette outside SB64 boundaries
2184
13.5k
    int a_cache = by4 & 15 ? pl ? t->pal_sz_uv[0][bx4] : t->a->pal_sz[bx4] : 0;
2185
13.5k
    const pixel *l = bytefn(t->al_pal)[1][by4][pl];
2186
13.5k
    const pixel *a = bytefn(t->al_pal)[0][bx4][pl];
2187
2188
    // fill/sort cache
2189
22.1k
    while (l_cache && a_cache) {
2190
8.55k
        if (*l < *a) {
2191
3.15k
            if (!n_cache || cache[n_cache - 1] != *l)
2192
3.14k
                cache[n_cache++] = *l;
2193
3.15k
            l++;
2194
3.15k
            l_cache--;
2195
5.40k
        } else {
2196
5.40k
            if (*a == *l) {
2197
2.29k
                l++;
2198
2.29k
                l_cache--;
2199
2.29k
            }
2200
5.40k
            if (!n_cache || cache[n_cache - 1] != *a)
2201
5.18k
                cache[n_cache++] = *a;
2202
5.40k
            a++;
2203
5.40k
            a_cache--;
2204
5.40k
        }
2205
8.55k
    }
2206
13.5k
    if (l_cache) {
2207
16.5k
        do {
2208
16.5k
            if (!n_cache || cache[n_cache - 1] != *l)
2209
13.4k
                cache[n_cache++] = *l;
2210
16.5k
            l++;
2211
16.5k
        } while (--l_cache > 0);
2212
9.54k
    } else if (a_cache) {
2213
11.4k
        do {
2214
11.4k
            if (!n_cache || cache[n_cache - 1] != *a)
2215
9.38k
                cache[n_cache++] = *a;
2216
11.4k
            a++;
2217
11.4k
        } while (--a_cache > 0);
2218
2.97k
    }
2219
2220
    // find reused cache entries
2221
13.5k
    int i = 0;
2222
41.1k
    for (int n = 0; n < n_cache && i < pal_sz; n++)
2223
27.6k
        if (dav1d_msac_decode_bool_equi(&ts->msac))
2224
13.8k
            used_cache[i++] = cache[n];
2225
13.5k
    const int n_used_cache = i;
2226
2227
    // parse new entries
2228
13.5k
    pixel *const pal = t->frame_thread.pass ?
2229
13.5k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2230
13.5k
                            ((t->bx >> 1) + (t->by & 1))][pl] :
2231
13.5k
        bytefn(t->scratch.pal)[pl];
2232
13.5k
    if (i < pal_sz) {
2233
11.7k
        const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2234
11.7k
        int prev = pal[i++] = dav1d_msac_decode_bools(&ts->msac, bpc);
2235
2236
11.7k
        if (i < pal_sz) {
2237
10.5k
            int bits = bpc - 3 + dav1d_msac_decode_bools(&ts->msac, 2);
2238
10.5k
            const int max = (1 << bpc) - 1;
2239
2240
24.5k
            do {
2241
24.5k
                const int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2242
24.5k
                prev = pal[i++] = imin(prev + delta + !pl, max);
2243
24.5k
                if (prev + !pl >= max) {
2244
13.5k
                    for (; i < pal_sz; i++)
2245
8.74k
                        pal[i] = max;
2246
4.80k
                    break;
2247
4.80k
                }
2248
19.7k
                bits = imin(bits, 1 + ulog2(max - prev - !pl));
2249
19.7k
            } while (i < pal_sz);
2250
10.5k
        }
2251
2252
        // merge cache+new entries
2253
11.7k
        int n = 0, m = n_used_cache;
2254
65.5k
        for (i = 0; i < pal_sz; i++) {
2255
53.8k
            if (n < n_used_cache && (m >= pal_sz || used_cache[n] <= pal[m])) {
2256
8.83k
                pal[i] = used_cache[n++];
2257
44.9k
            } else {
2258
44.9k
                assert(m < pal_sz);
2259
44.9k
                pal[i] = pal[m++];
2260
44.9k
            }
2261
53.8k
        }
2262
11.7k
    } else {
2263
1.86k
        memcpy(pal, used_cache, n_used_cache * sizeof(*used_cache));
2264
1.86k
    }
2265
2266
13.5k
    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
13.5k
}
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
6.50k
{
2281
6.50k
    bytefn(dav1d_read_pal_plane)(t, b, 1, sz_ctx, bx4, by4);
2282
2283
    // V pal coding
2284
6.50k
    Dav1dTileState *const ts = t->ts;
2285
6.50k
    const Dav1dFrameContext *const f = t->f;
2286
6.50k
    pixel *const pal = t->frame_thread.pass ?
2287
6.50k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2288
6.50k
                            ((t->bx >> 1) + (t->by & 1))][2] :
2289
6.50k
        bytefn(t->scratch.pal)[2];
2290
6.50k
    const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2291
6.50k
    if (dav1d_msac_decode_bool_equi(&ts->msac)) {
2292
3.40k
        const int bits = bpc - 4 + dav1d_msac_decode_bools(&ts->msac, 2);
2293
3.40k
        int prev = pal[0] = dav1d_msac_decode_bools(&ts->msac, bpc);
2294
3.40k
        const int max = (1 << bpc) - 1;
2295
14.3k
        for (int i = 1; i < b->pal_sz[1]; i++) {
2296
10.9k
            int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2297
10.9k
            if (delta && dav1d_msac_decode_bool_equi(&ts->msac)) delta = -delta;
2298
10.9k
            prev = pal[i] = (prev + delta) & max;
2299
10.9k
        }
2300
3.40k
    } else {
2301
15.9k
        for (int i = 0; i < b->pal_sz[1]; i++)
2302
12.8k
            pal[i] = dav1d_msac_decode_bools(&ts->msac, bpc);
2303
3.09k
    }
2304
6.50k
    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
6.50k
}
dav1d_read_pal_uv_8bpc
Line
Count
Source
2280
2.88k
{
2281
2.88k
    bytefn(dav1d_read_pal_plane)(t, b, 1, sz_ctx, bx4, by4);
2282
2283
    // V pal coding
2284
2.88k
    Dav1dTileState *const ts = t->ts;
2285
2.88k
    const Dav1dFrameContext *const f = t->f;
2286
2.88k
    pixel *const pal = t->frame_thread.pass ?
2287
2.88k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2288
2.88k
                            ((t->bx >> 1) + (t->by & 1))][2] :
2289
2.88k
        bytefn(t->scratch.pal)[2];
2290
2.88k
    const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2291
2.88k
    if (dav1d_msac_decode_bool_equi(&ts->msac)) {
2292
1.51k
        const int bits = bpc - 4 + dav1d_msac_decode_bools(&ts->msac, 2);
2293
1.51k
        int prev = pal[0] = dav1d_msac_decode_bools(&ts->msac, bpc);
2294
1.51k
        const int max = (1 << bpc) - 1;
2295
6.41k
        for (int i = 1; i < b->pal_sz[1]; i++) {
2296
4.89k
            int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2297
4.89k
            if (delta && dav1d_msac_decode_bool_equi(&ts->msac)) delta = -delta;
2298
4.89k
            prev = pal[i] = (prev + delta) & max;
2299
4.89k
        }
2300
1.51k
    } else {
2301
6.96k
        for (int i = 0; i < b->pal_sz[1]; i++)
2302
5.60k
            pal[i] = dav1d_msac_decode_bools(&ts->msac, bpc);
2303
1.36k
    }
2304
2.88k
    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
2.88k
}
dav1d_read_pal_uv_16bpc
Line
Count
Source
2280
3.61k
{
2281
3.61k
    bytefn(dav1d_read_pal_plane)(t, b, 1, sz_ctx, bx4, by4);
2282
2283
    // V pal coding
2284
3.61k
    Dav1dTileState *const ts = t->ts;
2285
3.61k
    const Dav1dFrameContext *const f = t->f;
2286
3.61k
    pixel *const pal = t->frame_thread.pass ?
2287
3.61k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2288
3.61k
                            ((t->bx >> 1) + (t->by & 1))][2] :
2289
3.61k
        bytefn(t->scratch.pal)[2];
2290
3.61k
    const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2291
3.61k
    if (dav1d_msac_decode_bool_equi(&ts->msac)) {
2292
1.88k
        const int bits = bpc - 4 + dav1d_msac_decode_bools(&ts->msac, 2);
2293
1.88k
        int prev = pal[0] = dav1d_msac_decode_bools(&ts->msac, bpc);
2294
1.88k
        const int max = (1 << bpc) - 1;
2295
7.93k
        for (int i = 1; i < b->pal_sz[1]; i++) {
2296
6.05k
            int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2297
6.05k
            if (delta && dav1d_msac_decode_bool_equi(&ts->msac)) delta = -delta;
2298
6.05k
            prev = pal[i] = (prev + delta) & max;
2299
6.05k
        }
2300
1.88k
    } else {
2301
8.98k
        for (int i = 0; i < b->pal_sz[1]; i++)
2302
7.25k
            pal[i] = dav1d_msac_decode_bools(&ts->msac, bpc);
2303
1.73k
    }
2304
3.61k
    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
3.61k
}