Coverage Report

Created: 2026-10-17 06:55

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