Coverage Report

Created: 2026-09-13 06:34

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
881k
static inline unsigned read_golomb(MsacContext *const msac) {
50
881k
    int len = 0;
51
881k
    unsigned val = 1;
52
53
1.64M
    while (!dav1d_msac_decode_bool_equi(msac) && len < 32) len++;
54
1.64M
    while (len--) val = (val << 1) + dav1d_msac_decode_bool_equi(msac);
55
56
881k
    return val - 1;
57
881k
}
58
59
static inline unsigned get_skip_ctx(const TxfmInfo *const t_dim,
60
                                    const enum BlockSize bs,
61
                                    const uint8_t *const a,
62
                                    const uint8_t *const l,
63
                                    const int chroma,
64
                                    const enum Dav1dPixelLayout layout)
65
5.64M
{
66
5.64M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
67
68
5.64M
    if (chroma) {
69
3.14M
        const int ss_ver = layout == DAV1D_PIXEL_LAYOUT_I420;
70
3.14M
        const int ss_hor = layout != DAV1D_PIXEL_LAYOUT_I444;
71
3.14M
        const int not_one_blk = b_dim[2] - (!!b_dim[2] && ss_hor) > t_dim->lw ||
72
1.66M
                                b_dim[3] - (!!b_dim[3] && ss_ver) > t_dim->lh;
73
3.14M
        unsigned ca, cl;
74
75
3.14M
#define MERGE_CTX(dir, type, no_val) \
76
6.28M
        c##dir = *(const type *) dir != no_val; \
77
6.28M
        break
78
79
3.14M
        switch (t_dim->lw) {
80
        /* For some reason the MSVC CRT _wassert() function is not flagged as
81
         * __declspec(noreturn), so when using those headers the compiler will
82
         * expect execution to continue after an assertion has been triggered
83
         * and will therefore complain about the use of uninitialized variables
84
         * when compiled in debug mode if we put the default case at the end. */
85
0
        default: assert(0); /* fall-through */
86
1.57M
        case TX_4X4:   MERGE_CTX(a, uint8_t,  0x40);
87
524k
        case TX_8X8:   MERGE_CTX(a, uint16_t, 0x4040);
88
378k
        case TX_16X16: MERGE_CTX(a, uint32_t, 0x40404040U);
89
667k
        case TX_32X32: MERGE_CTX(a, uint64_t, 0x4040404040404040ULL);
90
3.14M
        }
91
3.14M
        switch (t_dim->lh) {
92
0
        default: assert(0); /* fall-through */
93
1.69M
        case TX_4X4:   MERGE_CTX(l, uint8_t,  0x40);
94
522k
        case TX_8X8:   MERGE_CTX(l, uint16_t, 0x4040);
95
297k
        case TX_16X16: MERGE_CTX(l, uint32_t, 0x40404040U);
96
633k
        case TX_32X32: MERGE_CTX(l, uint64_t, 0x4040404040404040ULL);
97
3.14M
        }
98
3.14M
#undef MERGE_CTX
99
100
3.14M
        return 7 + not_one_blk * 3 + ca + cl;
101
3.14M
    } else if (b_dim[2] == t_dim->lw && b_dim[3] == t_dim->lh) {
102
830k
        return 0;
103
1.66M
    } else {
104
1.66M
        unsigned la, ll;
105
106
1.66M
#define MERGE_CTX(dir, type, tx) \
107
3.34M
        if (tx == TX_64X64) { \
108
225k
            uint64_t tmp = *(const uint64_t *) dir; \
109
225k
            tmp |= *(const uint64_t *) &dir[8]; \
110
225k
            l##dir = (unsigned) (tmp >> 32) | (unsigned) tmp; \
111
225k
        } else \
112
3.34M
            l##dir = *(const type *) dir; \
113
3.34M
        if (tx == TX_32X32) l##dir |= *(const type *) &dir[sizeof(type)]; \
114
3.34M
        if (tx >= TX_16X16) l##dir |= l##dir >> 16; \
115
3.34M
        if (tx >= TX_8X8)   l##dir |= l##dir >> 8; \
116
3.34M
        break
117
118
1.66M
        switch (t_dim->lw) {
119
0
        default: assert(0); /* fall-through */
120
950k
        case TX_4X4:   MERGE_CTX(a, uint8_t,  TX_4X4);
121
330k
        case TX_8X8:   MERGE_CTX(a, uint16_t, TX_8X8);
122
260k
        case TX_16X16: MERGE_CTX(a, uint32_t, TX_16X16);
123
20.6k
        case TX_32X32: MERGE_CTX(a, uint32_t, TX_32X32);
124
112k
        case TX_64X64: MERGE_CTX(a, uint32_t, TX_64X64);
125
1.66M
        }
126
1.67M
        switch (t_dim->lh) {
127
0
        default: assert(0); /* fall-through */
128
959k
        case TX_4X4:   MERGE_CTX(l, uint8_t,  TX_4X4);
129
322k
        case TX_8X8:   MERGE_CTX(l, uint16_t, TX_8X8);
130
259k
        case TX_16X16: MERGE_CTX(l, uint32_t, TX_16X16);
131
20.3k
        case TX_32X32: MERGE_CTX(l, uint32_t, TX_32X32);
132
112k
        case TX_64X64: MERGE_CTX(l, uint32_t, TX_64X64);
133
1.67M
        }
134
1.67M
#undef MERGE_CTX
135
136
1.67M
        return dav1d_skip_ctx[umin(la & 0x3F, 4)][umin(ll & 0x3F, 4)];
137
1.67M
    }
138
5.64M
}
139
140
static inline unsigned get_dc_sign_ctx(const int /*enum RectTxfmSize*/ tx,
141
                                       const uint8_t *const a,
142
                                       const uint8_t *const l)
143
2.37M
{
144
2.37M
    uint64_t mask = 0xC0C0C0C0C0C0C0C0ULL, mul = 0x0101010101010101ULL;
145
2.37M
    int s;
146
147
2.37M
#if ARCH_X86_64 && defined(__GNUC__)
148
    /* Coerce compilers into producing better code. For some reason
149
     * every x86-64 compiler is awful at handling 64-bit constants. */
150
2.37M
    __asm__("" : "+r"(mask), "+r"(mul));
151
2.37M
#endif
152
153
2.37M
    switch(tx) {
154
0
    default: assert(0); /* fall-through */
155
1.15M
    case TX_4X4: {
156
1.15M
        int t = *(const uint8_t *) a >> 6;
157
1.15M
        t    += *(const uint8_t *) l >> 6;
158
1.15M
        s = t - 1 - 1;
159
1.15M
        break;
160
0
    }
161
243k
    case TX_8X8: {
162
243k
        uint32_t t = *(const uint16_t *) a & (uint32_t) mask;
163
243k
        t         += *(const uint16_t *) l & (uint32_t) mask;
164
243k
        t *= 0x04040404U;
165
243k
        s = (int) (t >> 24) - 2 - 2;
166
243k
        break;
167
0
    }
168
186k
    case TX_16X16: {
169
186k
        uint32_t t = (*(const uint32_t *) a & (uint32_t) mask) >> 6;
170
186k
        t         += (*(const uint32_t *) l & (uint32_t) mask) >> 6;
171
186k
        t *= (uint32_t) mul;
172
186k
        s = (int) (t >> 24) - 4 - 4;
173
186k
        break;
174
0
    }
175
166k
    case TX_32X32: {
176
166k
        uint64_t t = (*(const uint64_t *) a & mask) >> 6;
177
166k
        t         += (*(const uint64_t *) l & mask) >> 6;
178
166k
        t *= mul;
179
166k
        s = (int) (t >> 56) - 8 - 8;
180
166k
        break;
181
0
    }
182
77.0k
    case TX_64X64: {
183
77.0k
        uint64_t t = (*(const uint64_t *) &a[0] & mask) >> 6;
184
77.0k
        t         += (*(const uint64_t *) &a[8] & mask) >> 6;
185
77.0k
        t         += (*(const uint64_t *) &l[0] & mask) >> 6;
186
77.0k
        t         += (*(const uint64_t *) &l[8] & mask) >> 6;
187
77.0k
        t *= mul;
188
77.0k
        s = (int) (t >> 56) - 16 - 16;
189
77.0k
        break;
190
0
    }
191
64.6k
    case RTX_4X8: {
192
64.6k
        uint32_t t = *(const uint8_t  *) a & (uint32_t) mask;
193
64.6k
        t         += *(const uint16_t *) l & (uint32_t) mask;
194
64.6k
        t *= 0x04040404U;
195
64.6k
        s = (int) (t >> 24) - 1 - 2;
196
64.6k
        break;
197
0
    }
198
96.1k
    case RTX_8X4: {
199
96.1k
        uint32_t t = *(const uint16_t *) a & (uint32_t) mask;
200
96.1k
        t         += *(const uint8_t  *) l & (uint32_t) mask;
201
96.1k
        t *= 0x04040404U;
202
96.1k
        s = (int) (t >> 24) - 2 - 1;
203
96.1k
        break;
204
0
    }
205
53.4k
    case RTX_8X16: {
206
53.4k
        uint32_t t = *(const uint16_t *) a & (uint32_t) mask;
207
53.4k
        t         += *(const uint32_t *) l & (uint32_t) mask;
208
53.4k
        t = (t >> 6) * (uint32_t) mul;
209
53.4k
        s = (int) (t >> 24) - 2 - 4;
210
53.4k
        break;
211
0
    }
212
96.1k
    case RTX_16X8: {
213
96.1k
        uint32_t t = *(const uint32_t *) a & (uint32_t) mask;
214
96.1k
        t         += *(const uint16_t *) l & (uint32_t) mask;
215
96.1k
        t = (t >> 6) * (uint32_t) mul;
216
96.1k
        s = (int) (t >> 24) - 4 - 2;
217
96.1k
        break;
218
0
    }
219
25.5k
    case RTX_16X32: {
220
25.5k
        uint64_t t = *(const uint32_t *) a & (uint32_t) mask;
221
25.5k
        t         += *(const uint64_t *) l & mask;
222
25.5k
        t = (t >> 6) * mul;
223
25.5k
        s = (int) (t >> 56) - 4 - 8;
224
25.5k
        break;
225
0
    }
226
42.9k
    case RTX_32X16: {
227
42.9k
        uint64_t t = *(const uint64_t *) a & mask;
228
42.9k
        t         += *(const uint32_t *) l & (uint32_t) mask;
229
42.9k
        t = (t >> 6) * mul;
230
42.9k
        s = (int) (t >> 56) - 8 - 4;
231
42.9k
        break;
232
0
    }
233
12.0k
    case RTX_32X64: {
234
12.0k
        uint64_t t = (*(const uint64_t *) &a[0] & mask) >> 6;
235
12.0k
        t         += (*(const uint64_t *) &l[0] & mask) >> 6;
236
12.0k
        t         += (*(const uint64_t *) &l[8] & mask) >> 6;
237
12.0k
        t *= mul;
238
12.0k
        s = (int) (t >> 56) - 8 - 16;
239
12.0k
        break;
240
0
    }
241
13.9k
    case RTX_64X32: {
242
13.9k
        uint64_t t = (*(const uint64_t *) &a[0] & mask) >> 6;
243
13.9k
        t         += (*(const uint64_t *) &a[8] & mask) >> 6;
244
13.9k
        t         += (*(const uint64_t *) &l[0] & mask) >> 6;
245
13.9k
        t *= mul;
246
13.9k
        s = (int) (t >> 56) - 16 - 8;
247
13.9k
        break;
248
0
    }
249
27.2k
    case RTX_4X16: {
250
27.2k
        uint32_t t = *(const uint8_t  *) a & (uint32_t) mask;
251
27.2k
        t         += *(const uint32_t *) l & (uint32_t) mask;
252
27.2k
        t = (t >> 6) * (uint32_t) mul;
253
27.2k
        s = (int) (t >> 24) - 1 - 4;
254
27.2k
        break;
255
0
    }
256
56.9k
    case RTX_16X4: {
257
56.9k
        uint32_t t = *(const uint32_t *) a & (uint32_t) mask;
258
56.9k
        t         += *(const uint8_t  *) l & (uint32_t) mask;
259
56.9k
        t = (t >> 6) * (uint32_t) mul;
260
56.9k
        s = (int) (t >> 24) - 4 - 1;
261
56.9k
        break;
262
0
    }
263
16.6k
    case RTX_8X32: {
264
16.6k
        uint64_t t = *(const uint16_t *) a & (uint32_t) mask;
265
16.6k
        t         += *(const uint64_t *) l & mask;
266
16.6k
        t = (t >> 6) * mul;
267
16.6k
        s = (int) (t >> 56) - 2 - 8;
268
16.6k
        break;
269
0
    }
270
27.4k
    case RTX_32X8: {
271
27.4k
        uint64_t t = *(const uint64_t *) a & mask;
272
27.4k
        t         += *(const uint16_t *) l & (uint32_t) mask;
273
27.4k
        t = (t >> 6) * mul;
274
27.4k
        s = (int) (t >> 56) - 8 - 2;
275
27.4k
        break;
276
0
    }
277
6.31k
    case RTX_16X64: {
278
6.31k
        uint64_t t = *(const uint32_t *) a & (uint32_t) mask;
279
6.31k
        t         += *(const uint64_t *) &l[0] & mask;
280
6.31k
        t = (t >> 6) + ((*(const uint64_t *) &l[8] & mask) >> 6);
281
6.31k
        t *= mul;
282
6.31k
        s = (int) (t >> 56) - 4 - 16;
283
6.31k
        break;
284
0
    }
285
3.80k
    case RTX_64X16: {
286
3.80k
        uint64_t t = *(const uint64_t *) &a[0] & mask;
287
3.80k
        t         += *(const uint32_t *) l & (uint32_t) mask;
288
3.80k
        t = (t >> 6) + ((*(const uint64_t *) &a[8] & mask) >> 6);
289
3.80k
        t *= mul;
290
3.80k
        s = (int) (t >> 56) - 16 - 4;
291
3.80k
        break;
292
0
    }
293
2.37M
    }
294
295
2.37M
    return (s != 0) + (s > 0);
296
2.37M
}
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
40.4M
{
305
40.4M
    unsigned mag = levels[0 * stride + 1] + levels[1 * stride + 0];
306
40.4M
    unsigned offset;
307
40.4M
    if (tx_class == TX_CLASS_2D) {
308
37.6M
        mag += levels[1 * stride + 1];
309
37.6M
        *hi_mag = mag;
310
37.6M
        mag += levels[0 * stride + 2] + levels[2 * stride + 0];
311
37.6M
        offset = ctx_offsets[umin(y, 4)][umin(x, 4)];
312
37.6M
    } else {
313
2.81M
        mag += levels[0 * stride + 2];
314
2.81M
        *hi_mag = mag;
315
2.81M
        mag += levels[0 * stride + 3] + levels[0 * stride + 4];
316
2.81M
        offset = 26 + (y > 1 ? 10 : y * 5);
317
2.81M
    }
318
40.4M
    return offset + (mag > 512 ? 4 : (mag + 64) >> 7);
319
40.4M
}
320
321
static int decode_coefs(Dav1dTaskContext *const t,
322
                        uint8_t *const a, uint8_t *const l,
323
                        const enum RectTxfmSize tx, const enum BlockSize bs,
324
                        const Av1Block *const b, const int intra,
325
                        const int plane, coef *cf,
326
                        enum TxfmType *const txtp, uint8_t *res_ctx)
327
5.64M
{
328
5.64M
    Dav1dTileState *const ts = t->ts;
329
5.64M
    const int chroma = !!plane;
330
5.64M
    const Dav1dFrameContext *const f = t->f;
331
5.64M
    const int lossless = f->frame_hdr->segmentation.lossless[b->seg_id];
332
5.64M
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[tx];
333
5.64M
    const int dbg = DEBUG_BLOCK_INFO && plane && 0;
334
335
5.64M
    if (dbg)
336
0
        printf("Start: r=%d\n", ts->msac.rng);
337
338
    // does this block have any non-zero coefficients
339
5.64M
    const int sctx = get_skip_ctx(t_dim, bs, a, l, chroma, f->cur.p.layout);
340
5.64M
    const int all_skip = dav1d_msac_decode_bool_adapt(&ts->msac,
341
5.64M
                             ts->cdf.coef.skip[t_dim->ctx][sctx]);
342
5.64M
    if (dbg)
343
0
        printf("Post-non-zero[%d][%d][%d]: r=%d\n",
344
0
               t_dim->ctx, sctx, all_skip, ts->msac.rng);
345
5.64M
    if (all_skip) {
346
2.82M
        *res_ctx = 0x40;
347
2.82M
        *txtp = lossless * WHT_WHT; /* lossless ? WHT_WHT : DCT_DCT */
348
2.82M
        return -1;
349
2.82M
    }
350
351
    // transform type (chroma: derived, luma: explicitly coded)
352
2.81M
    if (lossless) {
353
1.09M
        assert(t_dim->max == TX_4X4);
354
1.09M
        *txtp = WHT_WHT;
355
1.72M
    } else if (t_dim->max + intra >= TX_64X64) {
356
372k
        *txtp = DCT_DCT;
357
1.34M
    } else if (chroma) {
358
        // inferred from either the luma txtp (inter) or a LUT (intra)
359
351k
        *txtp = intra ? dav1d_txtp_from_uvmode[b->uv_mode] :
360
351k
                        get_uv_inter_txtp(t_dim, *txtp);
361
997k
    } 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
4.55k
        *txtp = DCT_DCT;
366
992k
    } else {
367
992k
        unsigned idx;
368
992k
        if (intra) {
369
698k
            const enum IntraPredMode y_mode_nofilt = b->y_mode == FILTER_PRED ?
370
603k
                dav1d_filter_mode_to_y_mode[b->y_angle] : b->y_mode;
371
698k
            if (f->frame_hdr->reduced_txtp_set || t_dim->min == TX_16X16) {
372
360k
                idx = dav1d_msac_decode_symbol_adapt8(&ts->msac,
373
360k
                          ts->cdf.m.txtp_intra2[t_dim->min][y_mode_nofilt], 4);
374
360k
                *txtp = dav1d_tx_types_per_set[idx + 0];
375
360k
            } else {
376
338k
                idx = dav1d_msac_decode_symbol_adapt8(&ts->msac,
377
338k
                          ts->cdf.m.txtp_intra1[t_dim->min][y_mode_nofilt], 6);
378
338k
                *txtp = dav1d_tx_types_per_set[idx + 5];
379
338k
            }
380
698k
            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
698k
        } else {
384
293k
            if (f->frame_hdr->reduced_txtp_set || t_dim->max == TX_32X32) {
385
60.9k
                idx = dav1d_msac_decode_bool_adapt(&ts->msac,
386
60.9k
                          ts->cdf.m.txtp_inter3[t_dim->min]);
387
60.9k
                *txtp = (idx - 1) & IDTX; /* idx ? DCT_DCT : IDTX */
388
232k
            } else if (t_dim->min == TX_16X16) {
389
21.3k
                idx = dav1d_msac_decode_symbol_adapt16(&ts->msac,
390
21.3k
                          ts->cdf.m.txtp_inter2, 11);
391
21.3k
                *txtp = dav1d_tx_types_per_set[idx + 12];
392
211k
            } else {
393
211k
                idx = dav1d_msac_decode_symbol_adapt16(&ts->msac,
394
211k
                          ts->cdf.m.txtp_inter1[t_dim->min], 15);
395
211k
                *txtp = dav1d_tx_types_per_set[idx + 24];
396
211k
            }
397
293k
            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
293k
        }
401
992k
    }
402
403
    // find end-of-block (eob)
404
2.81M
    int eob;
405
2.81M
    const int slw = imin(t_dim->lw, TX_32X32), slh = imin(t_dim->lh, TX_32X32);
406
2.81M
    const int tx2dszctx = slw + slh;
407
2.81M
    const enum TxClass tx_class = dav1d_tx_type_class[*txtp];
408
2.81M
    const int is_1d = tx_class != TX_CLASS_2D;
409
2.81M
    switch (tx2dszctx) {
410
0
#define case_sz(sz, bin, ns, is_1d) \
411
2.82M
    case sz: { \
412
2.82M
        uint16_t *const eob_bin_cdf = ts->cdf.coef.eob_bin_##bin[chroma]is_1d; \
413
2.82M
        eob = dav1d_msac_decode_symbol_adapt##ns(&ts->msac, eob_bin_cdf, 4 + sz); \
414
2.82M
        break; \
415
2.82M
    }
416
1.31M
    case_sz(0,   16,  8, [is_1d]);
417
212k
    case_sz(1,   32,  8, [is_1d]);
418
430k
    case_sz(2,   64,  8, [is_1d]);
419
198k
    case_sz(3,  128,  8, [is_1d]);
420
285k
    case_sz(4,  256, 16, [is_1d]);
421
89.9k
    case_sz(5,  512, 16,        );
422
290k
    case_sz(6, 1024, 16,        );
423
2.81M
#undef case_sz
424
2.81M
    }
425
2.82M
    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.82M
    if (eob > 1) {
429
1.60M
        const int eob_bin = eob - 2;
430
1.60M
        uint16_t *const eob_hi_bit_cdf =
431
1.60M
            ts->cdf.coef.eob_hi_bit[t_dim->ctx][chroma][eob_bin];
432
1.60M
        const int eob_hi_bit = dav1d_msac_decode_bool_adapt(&ts->msac, eob_hi_bit_cdf);
433
1.60M
        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.60M
        eob = ((eob_hi_bit | 2) << eob_bin) | dav1d_msac_decode_bools(&ts->msac, eob_bin);
437
1.60M
        if (dbg)
438
0
            printf("Post-eob[%d]: r=%d\n", eob, ts->msac.rng);
439
1.60M
    }
440
2.82M
    assert(eob >= 0);
441
442
    // base tokens
443
2.82M
    uint16_t (*const eob_cdf)[4] = ts->cdf.coef.eob_base_tok[t_dim->ctx][chroma];
444
2.82M
    uint16_t (*const hi_cdf)[4] = ts->cdf.coef.br_tok[imin(t_dim->ctx, 3)][chroma];
445
2.82M
    unsigned rc, dc_tok;
446
447
2.82M
    if (eob) {
448
1.71M
        uint16_t (*const lo_cdf)[4] = ts->cdf.coef.base_tok[t_dim->ctx][chroma];
449
1.71M
        uint8_t *const levels = t->scratch.levels; // bits 0-5: tok, 6-7: lo_tok
450
451
        /* eob */
452
1.71M
        unsigned ctx = 1 + (eob > 2 << tx2dszctx) + (eob > 4 << tx2dszctx);
453
1.71M
        int eob_tok = dav1d_msac_decode_symbol_adapt4(&ts->msac, eob_cdf[ctx], 2);
454
1.71M
        int tok = eob_tok + 1;
455
1.71M
        int level_tok = tok * 0x41;
456
1.71M
        unsigned mag;
457
458
1.71M
#define DECODE_COEFS_CLASS(tx_class) \
459
1.71M
        unsigned x, y; \
460
1.71M
        uint8_t *level; \
461
1.71M
        if (tx_class == TX_CLASS_2D) \
462
1.71M
            rc = scan[eob], x = rc >> shift, y = rc & mask; \
463
1.71M
        else if (tx_class == TX_CLASS_H) \
464
            /* Transposing reduces the stride and padding requirements */ \
465
150k
            x = eob & mask, y = eob >> shift, rc = eob; \
466
150k
        else /* tx_class == TX_CLASS_V */ \
467
150k
            x = eob & mask, y = eob >> shift, rc = (x << shift2) | y; \
468
1.71M
        if (dbg) \
469
1.71M
            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.71M
        if (eob_tok == 2) { \
472
32.7k
            ctx = (tx_class == TX_CLASS_2D ? (x | y) > 1 : y != 0) ? 14 : 7; \
473
32.7k
            tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[ctx]); \
474
32.7k
            level_tok = tok + (3 << 6); \
475
32.7k
            if (dbg) \
476
32.7k
                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
32.7k
        } \
480
1.71M
        cf[rc] = tok << 11; \
481
1.71M
        if (tx_class == TX_CLASS_2D) \
482
1.71M
            level = levels + rc; \
483
1.71M
        else \
484
1.71M
            level = levels + x * stride + y; \
485
1.71M
        *level = (uint8_t) level_tok; \
486
42.0M
        for (int i = eob - 1; i > 0; i--) { /* ac */ \
487
40.3M
            unsigned rc_i; \
488
40.3M
            if (tx_class == TX_CLASS_2D) \
489
40.3M
                rc_i = scan[i], x = rc_i >> shift, y = rc_i & mask; \
490
40.3M
            else if (tx_class == TX_CLASS_H) \
491
2.71M
                x = i & mask, y = i >> shift, rc_i = i; \
492
2.71M
            else /* tx_class == TX_CLASS_V */ \
493
2.71M
                x = i & mask, y = i >> shift, rc_i = (x << shift2) | y; \
494
40.3M
            assert(x < 32 && y < 32); \
495
40.3M
            if (tx_class == TX_CLASS_2D) \
496
40.3M
                level = levels + rc_i; \
497
40.3M
            else \
498
40.3M
                level = levels + x * stride + y; \
499
40.3M
            ctx = get_lo_ctx(level, tx_class, &mag, lo_ctx_offsets, x, y, stride); \
500
40.3M
            if (tx_class == TX_CLASS_2D) \
501
40.3M
                y |= x; \
502
40.3M
            tok = dav1d_msac_decode_symbol_adapt4(&ts->msac, lo_cdf[ctx], 3); \
503
40.3M
            if (dbg) \
504
40.3M
                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
40.3M
            if (tok == 3) { \
507
3.38M
                mag &= 63; \
508
3.38M
                ctx = (y > (tx_class == TX_CLASS_2D) ? 14 : 7) + \
509
3.38M
                      (mag > 12 ? 6 : (mag + 1) >> 1); \
510
3.38M
                tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[ctx]); \
511
3.38M
                if (dbg) \
512
3.38M
                    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
3.38M
                *level = (uint8_t) (tok + (3 << 6)); \
516
3.38M
                cf[rc_i] = (tok << 11) | rc; \
517
3.38M
                rc = rc_i; \
518
36.9M
            } else { \
519
                /* 0x1 for tok, 0x7ff as bitmask for rc, 0x41 for level_tok */ \
520
36.9M
                tok *= 0x17ff41; \
521
36.9M
                *level = (uint8_t) tok; \
522
                /* tok ? (tok << 11) | rc : 0 */ \
523
36.9M
                tok = (tok >> 9) & (rc + ~0x7ffu); \
524
36.9M
                if (tok) rc = rc_i; \
525
36.9M
                cf[rc_i] = tok; \
526
36.9M
            } \
527
40.3M
        } \
528
        /* dc */ \
529
1.71M
        ctx = (tx_class == TX_CLASS_2D) ? 0 : \
530
1.71M
            get_lo_ctx(levels, tx_class, &mag, lo_ctx_offsets, 0, 0, stride); \
531
1.71M
        dc_tok = dav1d_msac_decode_symbol_adapt4(&ts->msac, lo_cdf[ctx], 3); \
532
1.71M
        if (dbg) \
533
1.71M
            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.71M
        if (dc_tok == 3) { \
536
583k
            if (tx_class == TX_CLASS_2D) \
537
583k
                mag = levels[0 * stride + 1] + levels[1 * stride + 0] + \
538
570k
                      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.71M
        break
547
548
1.71M
        const uint16_t *scan;
549
1.71M
        switch (tx_class) {
550
1.56M
        case TX_CLASS_2D: {
551
1.56M
            const unsigned nonsquare_tx = tx >= RTX_4X8;
552
1.56M
            const uint8_t (*const lo_ctx_offsets)[5] =
553
1.56M
                dav1d_lo_ctx_offsets[nonsquare_tx + (tx & nonsquare_tx)];
554
1.56M
            scan = dav1d_scans[tx];
555
1.56M
            const ptrdiff_t stride = 4 << slh;
556
1.56M
            const unsigned shift = slh + 2, shift2 = 0;
557
1.56M
            const unsigned mask = (4 << slh) - 1;
558
1.56M
            memset(levels, 0, stride * ((4 << slw) + 2));
559
1.56M
            DECODE_COEFS_CLASS(TX_CLASS_2D);
560
1.56M
        }
561
97.0k
        case TX_CLASS_H: {
562
97.0k
            const uint8_t (*const lo_ctx_offsets)[5] = NULL;
563
97.0k
            const ptrdiff_t stride = 16;
564
97.0k
            const unsigned shift = slh + 2, shift2 = 0;
565
97.0k
            const unsigned mask = (4 << slh) - 1;
566
97.0k
            memset(levels, 0, stride * ((4 << slh) + 2));
567
97.0k
            DECODE_COEFS_CLASS(TX_CLASS_H);
568
97.0k
        }
569
53.0k
        case TX_CLASS_V: {
570
53.0k
            const uint8_t (*const lo_ctx_offsets)[5] = NULL;
571
53.0k
            const ptrdiff_t stride = 16;
572
53.0k
            const unsigned shift = slw + 2, shift2 = slh + 2;
573
53.0k
            const unsigned mask = (4 << slw) - 1;
574
53.0k
            memset(levels, 0, stride * ((4 << slw) + 2));
575
53.0k
            DECODE_COEFS_CLASS(TX_CLASS_V);
576
53.0k
        }
577
0
#undef DECODE_COEFS_CLASS
578
0
        default: assert(0);
579
1.71M
        }
580
1.71M
    } else { // dc-only
581
1.10M
        int tok_br = dav1d_msac_decode_symbol_adapt4(&ts->msac, eob_cdf[0], 2);
582
1.10M
        dc_tok = 1 + tok_br;
583
1.10M
        if (dbg)
584
0
            printf("Post-dc_lo_tok[%d][%d][%d][%d]: r=%d\n",
585
0
                   t_dim->ctx, chroma, 0, dc_tok, ts->msac.rng);
586
1.10M
        if (tok_br == 2) {
587
34.2k
            dc_tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[0]);
588
34.2k
            if (dbg)
589
0
                printf("Post-dc_hi_tok[%d][%d][0][%d]: r=%d\n",
590
0
                       imin(t_dim->ctx, 3), chroma, dc_tok, ts->msac.rng);
591
34.2k
        }
592
1.10M
        rc = 0;
593
1.10M
    }
594
595
    // residual and sign
596
2.82M
    const uint16_t *const dq_tbl = ts->dq[b->seg_id][plane];
597
2.82M
    const uint8_t *const qm_tbl = *txtp < IDTX ? f->qm[tx][plane] : NULL;
598
2.82M
    const int dq_shift = imax(0, t_dim->ctx - 2);
599
2.82M
    const int cf_max = ~(~127U << (BITDEPTH == 8 ? 8 : f->cur.p.bpc));
600
2.82M
    unsigned cul_level, dc_sign_level;
601
602
2.82M
    if (!dc_tok) {
603
452k
        cul_level = 0;
604
452k
        dc_sign_level = 1 << 6;
605
452k
        if (qm_tbl) goto ac_qm;
606
288k
        goto ac_noqm;
607
452k
    }
608
609
2.37M
    const int dc_sign_ctx = get_dc_sign_ctx(tx, a, l);
610
2.37M
    uint16_t *const dc_sign_cdf = ts->cdf.coef.dc_sign[chroma][dc_sign_ctx];
611
2.37M
    const int dc_sign = dav1d_msac_decode_bool_adapt(&ts->msac, dc_sign_cdf);
612
2.37M
    if (dbg)
613
0
        printf("Post-dc_sign[%d][%d][%d]: r=%d\n",
614
0
               chroma, dc_sign_ctx, dc_sign, ts->msac.rng);
615
616
2.37M
    int dc_dq = dq_tbl[0];
617
2.37M
    dc_sign_level = (dc_sign - 1) & (2 << 6);
618
619
2.37M
    if (qm_tbl) {
620
850k
        dc_dq = (dc_dq * qm_tbl[0] + 16) >> 5;
621
622
850k
        if (dc_tok == 15) {
623
20.5k
            dc_tok = read_golomb(&ts->msac) + 15;
624
20.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
20.5k
            dc_tok &= 0xfffff;
629
20.5k
            dc_dq = (dc_dq * dc_tok) & 0xffffff;
630
829k
        } else {
631
829k
            dc_dq *= dc_tok;
632
829k
            assert(dc_dq <= 0xffffff);
633
829k
        }
634
850k
        cul_level = dc_tok;
635
850k
        dc_dq >>= dq_shift;
636
850k
        dc_dq = umin(dc_dq, cf_max + dc_sign);
637
850k
        cf[0] = (coef) (dc_sign ? -dc_dq : dc_dq);
638
639
1.23M
        if (rc) ac_qm: {
640
1.23M
            const unsigned ac_dq = dq_tbl[1];
641
8.29M
            do {
642
8.29M
                const int sign = dav1d_msac_decode_bool_equi(&ts->msac);
643
8.29M
                if (dbg)
644
0
                    printf("Post-sign[%d=%d]: r=%d\n", rc, sign, ts->msac.rng);
645
8.29M
                const unsigned rc_tok = cf[rc];
646
8.29M
                unsigned tok, dq = (ac_dq * qm_tbl[rc] + 16) >> 5;
647
8.29M
                int dq_sat;
648
649
8.29M
                if (rc_tok >= (15 << 11)) {
650
696k
                    tok = read_golomb(&ts->msac) + 15;
651
696k
                    if (dbg)
652
0
                        printf("Post-residual[%d=%d->%d]: r=%d\n",
653
0
                               rc, tok - 15, tok, ts->msac.rng);
654
655
696k
                    tok &= 0xfffff;
656
696k
                    dq = (dq * tok) & 0xffffff;
657
7.59M
                } else {
658
7.59M
                    tok = rc_tok >> 11;
659
7.59M
                    dq *= tok;
660
7.59M
                    assert(dq <= 0xffffff);
661
7.59M
                }
662
8.29M
                cul_level += tok;
663
8.29M
                dq >>= dq_shift;
664
8.29M
                dq_sat = umin(dq, cf_max + sign);
665
8.29M
                cf[rc] = (coef) (sign ? -dq_sat : dq_sat);
666
667
8.29M
                rc = rc_tok & 0x3ff;
668
8.29M
            } while (rc);
669
1.23M
        }
670
1.52M
    } else {
671
        // non-qmatrix is the common case and allows for additional optimizations
672
1.52M
        if (dc_tok == 15) {
673
38.8k
            dc_tok = read_golomb(&ts->msac) + 15;
674
38.8k
            if (dbg)
675
0
                printf("Post-dc_residual[%d->%d]: r=%d\n",
676
0
                       dc_tok - 15, dc_tok, ts->msac.rng);
677
678
38.8k
            dc_tok &= 0xfffff;
679
38.8k
            dc_dq = ((dc_dq * dc_tok) & 0xffffff) >> dq_shift;
680
38.8k
            dc_dq = umin(dc_dq, cf_max + dc_sign);
681
1.48M
        } else {
682
1.48M
            dc_dq = ((dc_dq * dc_tok) >> dq_shift);
683
1.48M
            assert(dc_dq <= cf_max);
684
1.48M
        }
685
1.52M
        cul_level = dc_tok;
686
1.52M
        cf[0] = (coef) (dc_sign ? -dc_dq : dc_dq);
687
688
1.75M
        if (rc) ac_noqm: {
689
1.75M
            const unsigned ac_dq = dq_tbl[1];
690
7.67M
            do {
691
7.67M
                const int sign = dav1d_msac_decode_bool_equi(&ts->msac);
692
7.67M
                if (dbg)
693
0
                    printf("Post-sign[%d=%d]: r=%d\n", rc, sign, ts->msac.rng);
694
7.67M
                const unsigned rc_tok = cf[rc];
695
7.67M
                unsigned tok;
696
7.67M
                int dq;
697
698
                // residual
699
7.67M
                if (rc_tok >= (15 << 11)) {
700
125k
                    tok = read_golomb(&ts->msac) + 15;
701
125k
                    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
125k
                    tok &= 0xfffff;
707
708
                    // dequant, see 7.12.3
709
125k
                    dq = ((ac_dq * tok) & 0xffffff) >> dq_shift;
710
125k
                    dq = umin(dq, cf_max + sign);
711
7.54M
                } else {
712
                    // cannot exceed cf_max, so we can avoid the clipping
713
7.54M
                    tok = rc_tok >> 11;
714
7.54M
                    dq = ((ac_dq * tok) >> dq_shift);
715
7.54M
                    assert(dq <= cf_max);
716
7.54M
                }
717
7.67M
                cul_level += tok;
718
7.67M
                cf[rc] = (coef) (sign ? -dq : dq);
719
720
7.67M
                rc = rc_tok & 0x3ff; // next non-zero rc, zero if eob
721
7.67M
            } while (rc);
722
1.75M
        }
723
1.52M
    }
724
725
    // context
726
2.82M
    *res_ctx = umin(cul_level, 63) | dc_sign_level;
727
728
2.82M
    return eob;
729
2.37M
}
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
1.33M
{
737
1.33M
    const Dav1dFrameContext *const f = t->f;
738
1.33M
    Dav1dTileState *const ts = t->ts;
739
1.33M
    const Dav1dDSPContext *const dsp = f->dsp;
740
1.33M
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[ytx];
741
1.33M
    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
1.33M
    if (depth < 2 && tx_split[depth] &&
746
56.3k
        tx_split[depth] & (1 << (y_off * 4 + x_off)))
747
43.6k
    {
748
43.6k
        const enum RectTxfmSize sub = t_dim->sub;
749
43.6k
        const TxfmInfo *const sub_t_dim = &dav1d_txfm_dimensions[sub];
750
43.6k
        const int txsw = sub_t_dim->w, txsh = sub_t_dim->h;
751
752
43.6k
        read_coef_tree(t, bs, b, sub, depth + 1, tx_split,
753
43.6k
                       x_off * 2 + 0, y_off * 2 + 0, dst);
754
43.6k
        t->bx += txsw;
755
43.6k
        if (txw >= txh && t->bx < f->bw)
756
32.1k
            read_coef_tree(t, bs, b, sub, depth + 1, tx_split, x_off * 2 + 1,
757
32.1k
                           y_off * 2 + 0, dst ? &dst[4 * txsw] : NULL);
758
43.6k
        t->bx -= txsw;
759
43.6k
        t->by += txsh;
760
43.6k
        if (txh >= txw && t->by < f->bh) {
761
30.0k
            if (dst)
762
12.0k
                dst += 4 * txsh * PXSTRIDE(f->cur.stride[0]);
763
30.0k
            read_coef_tree(t, bs, b, sub, depth + 1, tx_split,
764
30.0k
                           x_off * 2 + 0, y_off * 2 + 1, dst);
765
30.0k
            t->bx += txsw;
766
30.0k
            if (txw >= txh && t->bx < f->bw)
767
19.4k
                read_coef_tree(t, bs, b, sub, depth + 1, tx_split, x_off * 2 + 1,
768
19.4k
                               y_off * 2 + 1, dst ? &dst[4 * txsw] : NULL);
769
30.0k
            t->bx -= txsw;
770
30.0k
        }
771
43.6k
        t->by -= txsh;
772
1.29M
    } else {
773
1.29M
        const int bx4 = t->bx & 31, by4 = t->by & 31;
774
1.29M
        enum TxfmType txtp;
775
1.29M
        uint8_t cf_ctx;
776
1.29M
        int eob;
777
1.29M
        coef *cf;
778
779
1.29M
        if (t->frame_thread.pass) {
780
1.29M
            const int p = t->frame_thread.pass & 1;
781
1.29M
            assert(ts->frame_thread[p].cf);
782
1.29M
            cf = ts->frame_thread[p].cf;
783
1.29M
            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
1.29M
        if (t->frame_thread.pass != 2) {
788
813k
            eob = decode_coefs(t, &t->a->lcoef[bx4], &t->l.lcoef[by4],
789
813k
                               ytx, bs, b, 0, 0, cf, &txtp, &cf_ctx);
790
813k
            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
813k
            dav1d_memset_likely_pow2(&t->a->lcoef[bx4], cf_ctx, imin(txw, f->bw - t->bx));
794
813k
            dav1d_memset_likely_pow2(&t->l.lcoef[by4], cf_ctx, imin(txh, f->bh - t->by));
795
813k
#define set_ctx(rep_macro) \
796
2.89M
            for (int y = 0; y < txh; y++) { \
797
2.07M
                rep_macro(txtp_map, 0, txtp); \
798
2.07M
                txtp_map += 32; \
799
2.07M
            }
800
813k
            uint8_t *txtp_map = &t->scratch.txtp_map[by4 * 32 + bx4];
801
813k
            case_set_upto16(t_dim->lw);
802
813k
#undef set_ctx
803
813k
            if (t->frame_thread.pass == 1)
804
813k
                *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
805
813k
        } else {
806
479k
            const int cbi = *ts->frame_thread[0].cbi++;
807
479k
            eob  = cbi >> 5;
808
479k
            txtp = cbi & 0x1f;
809
479k
        }
810
1.29M
        if (!(t->frame_thread.pass & 1)) {
811
479k
            assert(dst);
812
479k
            if (eob >= 0) {
813
270k
                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
270k
                dsp->itx.itxfm_add[ytx][txtp](dst, f->cur.stride[0], cf, eob
816
270k
                                              HIGHBD_CALL_SUFFIX);
817
270k
                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
270k
            }
820
479k
        }
821
1.29M
    }
822
1.33M
}
823
824
void bytefn(dav1d_read_coef_blocks)(Dav1dTaskContext *const t,
825
                                    const enum BlockSize bs, const Av1Block *const b)
826
2.78M
{
827
2.78M
    const Dav1dFrameContext *const f = t->f;
828
2.78M
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
829
2.78M
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
830
2.78M
    const int bx4 = t->bx & 31, by4 = t->by & 31;
831
2.78M
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
832
2.78M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
833
2.78M
    const int bw4 = b_dim[0], bh4 = b_dim[1];
834
2.78M
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
835
2.78M
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
836
2.39M
                           (bw4 > ss_hor || t->bx & 1) &&
837
2.23M
                           (bh4 > ss_ver || t->by & 1);
838
839
2.78M
    if (b->skip) {
840
1.72M
        BlockContext *const a = t->a;
841
1.72M
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
842
1.72M
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
843
1.72M
        if (has_chroma) {
844
1.19M
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
845
1.19M
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
846
1.19M
            memset_cw(&a->ccoef[0][cbx4], 0x40);
847
1.19M
            memset_cw(&a->ccoef[1][cbx4], 0x40);
848
1.19M
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
849
1.19M
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
850
1.19M
        }
851
1.72M
        return;
852
1.72M
    }
853
854
1.06M
    Dav1dTileState *const ts = t->ts;
855
1.06M
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
856
1.06M
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
857
1.06M
    assert(t->frame_thread.pass == 1);
858
1.06M
    assert(!b->skip);
859
1.06M
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
860
1.06M
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->intra ? b->tx : b->max_ytx];
861
1.06M
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
862
863
2.16M
    for (int init_y = 0; init_y < h4; init_y += 16) {
864
1.09M
        const int sub_h4 = imin(h4, 16 + init_y);
865
2.24M
        for (int init_x = 0; init_x < w4; init_x += 16) {
866
1.14M
            const int sub_w4 = imin(w4, init_x + 16);
867
1.14M
            int y_off = !!init_y, y, x;
868
2.55M
            for (y = init_y, t->by += init_y; y < sub_h4;
869
1.40M
                 y += t_dim->h, t->by += t_dim->h, y_off++)
870
1.40M
            {
871
1.40M
                int x_off = !!init_x;
872
3.85M
                for (x = init_x, t->bx += init_x; x < sub_w4;
873
2.45M
                     x += t_dim->w, t->bx += t_dim->w, x_off++)
874
2.45M
                {
875
2.45M
                    if (!b->intra) {
876
763k
                        read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
877
763k
                                       x_off, y_off, NULL);
878
1.69M
                    } else {
879
1.69M
                        uint8_t cf_ctx = 0x40;
880
1.69M
                        enum TxfmType txtp;
881
1.69M
                        const int eob =
882
1.69M
                            decode_coefs(t, &t->a->lcoef[bx4 + x],
883
1.69M
                                         &t->l.lcoef[by4 + y], b->tx, bs, b, 1,
884
1.69M
                                         0, ts->frame_thread[1].cf, &txtp, &cf_ctx);
885
1.69M
                        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.69M
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
889
1.69M
                        ts->frame_thread[1].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
890
1.69M
                        dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
891
1.69M
                        dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
892
1.69M
                    }
893
2.45M
                }
894
1.40M
                t->bx -= x;
895
1.40M
            }
896
1.14M
            t->by -= y;
897
898
1.14M
            if (!has_chroma) continue;
899
900
960k
            const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
901
960k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
902
2.88M
            for (int pl = 0; pl < 2; pl++) {
903
4.10M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
904
2.18M
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
905
2.18M
                {
906
5.32M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
907
3.14M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
908
3.14M
                    {
909
3.14M
                        uint8_t cf_ctx = 0x40;
910
3.14M
                        enum TxfmType txtp;
911
3.14M
                        if (!b->intra)
912
1.47M
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
913
1.47M
                                                        bx4 + (x << ss_hor)];
914
3.14M
                        const int eob =
915
3.14M
                            decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
916
3.14M
                                         &t->l.ccoef[pl][cby4 + y], b->uvtx, bs,
917
3.14M
                                         b, b->intra, 1 + pl, ts->frame_thread[1].cf,
918
3.14M
                                         &txtp, &cf_ctx);
919
3.14M
                        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
3.14M
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
924
3.14M
                        ts->frame_thread[1].cf += uv_t_dim->w * uv_t_dim->h * 16;
925
3.14M
                        int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
926
3.14M
                        int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
927
3.14M
                        dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
928
3.14M
                        dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
929
3.14M
                    }
930
2.18M
                    t->bx -= x << ss_hor;
931
2.18M
                }
932
1.92M
                t->by -= y << ss_ver;
933
1.92M
            }
934
960k
        }
935
1.09M
    }
936
1.06M
}
dav1d_read_coef_blocks_8bpc
Line
Count
Source
826
1.47M
{
827
1.47M
    const Dav1dFrameContext *const f = t->f;
828
1.47M
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
829
1.47M
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
830
1.47M
    const int bx4 = t->bx & 31, by4 = t->by & 31;
831
1.47M
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
832
1.47M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
833
1.47M
    const int bw4 = b_dim[0], bh4 = b_dim[1];
834
1.47M
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
835
1.47M
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
836
1.21M
                           (bw4 > ss_hor || t->bx & 1) &&
837
1.13M
                           (bh4 > ss_ver || t->by & 1);
838
839
1.47M
    if (b->skip) {
840
948k
        BlockContext *const a = t->a;
841
948k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
842
948k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
843
948k
        if (has_chroma) {
844
614k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
845
614k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
846
614k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
847
614k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
848
614k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
849
614k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
850
614k
        }
851
948k
        return;
852
948k
    }
853
854
529k
    Dav1dTileState *const ts = t->ts;
855
529k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
856
529k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
857
529k
    assert(t->frame_thread.pass == 1);
858
529k
    assert(!b->skip);
859
529k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
860
529k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->intra ? b->tx : b->max_ytx];
861
529k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
862
863
1.07M
    for (int init_y = 0; init_y < h4; init_y += 16) {
864
543k
        const int sub_h4 = imin(h4, 16 + init_y);
865
1.10M
        for (int init_x = 0; init_x < w4; init_x += 16) {
866
560k
            const int sub_w4 = imin(w4, init_x + 16);
867
560k
            int y_off = !!init_y, y, x;
868
1.22M
            for (y = init_y, t->by += init_y; y < sub_h4;
869
669k
                 y += t_dim->h, t->by += t_dim->h, y_off++)
870
669k
            {
871
669k
                int x_off = !!init_x;
872
1.79M
                for (x = init_x, t->bx += init_x; x < sub_w4;
873
1.12M
                     x += t_dim->w, t->bx += t_dim->w, x_off++)
874
1.12M
                {
875
1.12M
                    if (!b->intra) {
876
278k
                        read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
877
278k
                                       x_off, y_off, NULL);
878
843k
                    } else {
879
843k
                        uint8_t cf_ctx = 0x40;
880
843k
                        enum TxfmType txtp;
881
843k
                        const int eob =
882
843k
                            decode_coefs(t, &t->a->lcoef[bx4 + x],
883
843k
                                         &t->l.lcoef[by4 + y], b->tx, bs, b, 1,
884
843k
                                         0, ts->frame_thread[1].cf, &txtp, &cf_ctx);
885
843k
                        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
843k
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
889
843k
                        ts->frame_thread[1].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
890
843k
                        dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
891
843k
                        dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
892
843k
                    }
893
1.12M
                }
894
669k
                t->bx -= x;
895
669k
            }
896
560k
            t->by -= y;
897
898
560k
            if (!has_chroma) continue;
899
900
458k
            const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
901
458k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
902
1.37M
            for (int pl = 0; pl < 2; pl++) {
903
1.91M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
904
1.00M
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
905
1.00M
                {
906
2.28M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
907
1.28M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
908
1.28M
                    {
909
1.28M
                        uint8_t cf_ctx = 0x40;
910
1.28M
                        enum TxfmType txtp;
911
1.28M
                        if (!b->intra)
912
526k
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
913
526k
                                                        bx4 + (x << ss_hor)];
914
1.28M
                        const int eob =
915
1.28M
                            decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
916
1.28M
                                         &t->l.ccoef[pl][cby4 + y], b->uvtx, bs,
917
1.28M
                                         b, b->intra, 1 + pl, ts->frame_thread[1].cf,
918
1.28M
                                         &txtp, &cf_ctx);
919
1.28M
                        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.28M
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
924
1.28M
                        ts->frame_thread[1].cf += uv_t_dim->w * uv_t_dim->h * 16;
925
1.28M
                        int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
926
1.28M
                        int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
927
1.28M
                        dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
928
1.28M
                        dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
929
1.28M
                    }
930
1.00M
                    t->bx -= x << ss_hor;
931
1.00M
                }
932
917k
                t->by -= y << ss_ver;
933
917k
            }
934
458k
        }
935
543k
    }
936
529k
}
dav1d_read_coef_blocks_16bpc
Line
Count
Source
826
1.30M
{
827
1.30M
    const Dav1dFrameContext *const f = t->f;
828
1.30M
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
829
1.30M
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
830
1.30M
    const int bx4 = t->bx & 31, by4 = t->by & 31;
831
1.30M
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
832
1.30M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
833
1.30M
    const int bw4 = b_dim[0], bh4 = b_dim[1];
834
1.30M
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
835
1.30M
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
836
1.17M
                           (bw4 > ss_hor || t->bx & 1) &&
837
1.10M
                           (bh4 > ss_ver || t->by & 1);
838
839
1.30M
    if (b->skip) {
840
775k
        BlockContext *const a = t->a;
841
775k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
842
775k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
843
775k
        if (has_chroma) {
844
576k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
845
576k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
846
576k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
847
576k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
848
576k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
849
576k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
850
576k
        }
851
775k
        return;
852
775k
    }
853
854
531k
    Dav1dTileState *const ts = t->ts;
855
531k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
856
531k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
857
531k
    assert(t->frame_thread.pass == 1);
858
531k
    assert(!b->skip);
859
531k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
860
531k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->intra ? b->tx : b->max_ytx];
861
531k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
862
863
1.08M
    for (int init_y = 0; init_y < h4; init_y += 16) {
864
556k
        const int sub_h4 = imin(h4, 16 + init_y);
865
1.14M
        for (int init_x = 0; init_x < w4; init_x += 16) {
866
584k
            const int sub_w4 = imin(w4, init_x + 16);
867
584k
            int y_off = !!init_y, y, x;
868
1.32M
            for (y = init_y, t->by += init_y; y < sub_h4;
869
736k
                 y += t_dim->h, t->by += t_dim->h, y_off++)
870
736k
            {
871
736k
                int x_off = !!init_x;
872
2.06M
                for (x = init_x, t->bx += init_x; x < sub_w4;
873
1.33M
                     x += t_dim->w, t->bx += t_dim->w, x_off++)
874
1.33M
                {
875
1.33M
                    if (!b->intra) {
876
484k
                        read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
877
484k
                                       x_off, y_off, NULL);
878
846k
                    } else {
879
846k
                        uint8_t cf_ctx = 0x40;
880
846k
                        enum TxfmType txtp;
881
846k
                        const int eob =
882
846k
                            decode_coefs(t, &t->a->lcoef[bx4 + x],
883
846k
                                         &t->l.lcoef[by4 + y], b->tx, bs, b, 1,
884
846k
                                         0, ts->frame_thread[1].cf, &txtp, &cf_ctx);
885
846k
                        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
846k
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
889
846k
                        ts->frame_thread[1].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
890
846k
                        dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
891
846k
                        dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
892
846k
                    }
893
1.33M
                }
894
736k
                t->bx -= x;
895
736k
            }
896
584k
            t->by -= y;
897
898
584k
            if (!has_chroma) continue;
899
900
501k
            const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
901
501k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
902
1.50M
            for (int pl = 0; pl < 2; pl++) {
903
2.18M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
904
1.18M
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
905
1.18M
                {
906
3.04M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
907
1.85M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
908
1.85M
                    {
909
1.85M
                        uint8_t cf_ctx = 0x40;
910
1.85M
                        enum TxfmType txtp;
911
1.85M
                        if (!b->intra)
912
944k
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
913
944k
                                                        bx4 + (x << ss_hor)];
914
1.85M
                        const int eob =
915
1.85M
                            decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
916
1.85M
                                         &t->l.ccoef[pl][cby4 + y], b->uvtx, bs,
917
1.85M
                                         b, b->intra, 1 + pl, ts->frame_thread[1].cf,
918
1.85M
                                         &txtp, &cf_ctx);
919
1.85M
                        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.85M
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
924
1.85M
                        ts->frame_thread[1].cf += uv_t_dim->w * uv_t_dim->h * 16;
925
1.85M
                        int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
926
1.85M
                        int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
927
1.85M
                        dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
928
1.85M
                        dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
929
1.85M
                    }
930
1.18M
                    t->bx -= x << ss_hor;
931
1.18M
                }
932
1.00M
                t->by -= y << ss_ver;
933
1.00M
            }
934
501k
        }
935
556k
    }
936
531k
}
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.31M
{
945
1.31M
    assert((dst8 != NULL) ^ (dst16 != NULL));
946
1.31M
    const Dav1dFrameContext *const f = t->f;
947
1.31M
    const int ss_ver = !!pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
948
1.31M
    const int ss_hor = !!pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
949
1.31M
    const int h_mul = 4 >> ss_hor, v_mul = 4 >> ss_ver;
950
1.31M
    const int mvx = mv.x, mvy = mv.y;
951
1.31M
    const int mx = mvx & (15 >> !ss_hor), my = mvy & (15 >> !ss_ver);
952
1.31M
    ptrdiff_t ref_stride = refp->p.stride[!!pl];
953
1.31M
    const pixel *ref;
954
955
1.31M
    if (refp->p.p.w == f->cur.p.w && refp->p.p.h == f->cur.p.h) {
956
692k
        const int dx = bx * h_mul + (mvx >> (3 + ss_hor));
957
692k
        const int dy = by * v_mul + (mvy >> (3 + ss_ver));
958
692k
        int w, h;
959
960
692k
        if (refp->p.data[0] != f->cur.data[0]) { // i.e. not for intrabc
961
560k
            w = (f->cur.p.w + ss_hor) >> ss_hor;
962
560k
            h = (f->cur.p.h + ss_ver) >> ss_ver;
963
560k
        } else {
964
132k
            w = f->bw * 4 >> ss_hor;
965
132k
            h = f->bh * 4 >> ss_ver;
966
132k
        }
967
692k
        if (dx < !!mx * 3 || dy < !!my * 3 ||
968
516k
            dx + bw4 * h_mul + !!mx * 4 > w ||
969
265k
            dy + bh4 * v_mul + !!my * 4 > h)
970
486k
        {
971
486k
            pixel *const emu_edge_buf = bitfn(t->scratch.emu_edge);
972
486k
            f->dsp->mc.emu_edge(bw4 * h_mul + !!mx * 7, bh4 * v_mul + !!my * 7,
973
486k
                                w, h, dx - !!mx * 3, dy - !!my * 3,
974
486k
                                emu_edge_buf, 192 * sizeof(pixel),
975
486k
                                refp->p.data[pl], ref_stride);
976
486k
            ref = &emu_edge_buf[192 * !!my * 3 + !!mx * 3];
977
486k
            ref_stride = 192 * sizeof(pixel);
978
486k
        } else {
979
205k
            ref = ((pixel *) refp->p.data[pl]) + PXSTRIDE(ref_stride) * dy + dx;
980
205k
        }
981
982
692k
        if (dst8 != NULL) {
983
527k
            f->dsp->mc.mc[filter_2d](dst8, dst_stride, ref, ref_stride, bw4 * h_mul,
984
527k
                                     bh4 * v_mul, mx << !ss_hor, my << !ss_ver
985
527k
                                     HIGHBD_CALL_SUFFIX);
986
527k
        } else {
987
165k
            f->dsp->mc.mct[filter_2d](dst16, ref, ref_stride, bw4 * h_mul,
988
165k
                                      bh4 * v_mul, mx << !ss_hor, my << !ss_ver
989
165k
                                      HIGHBD_CALL_SUFFIX);
990
165k
        }
991
692k
    } else {
992
620k
        assert(refp != &f->sr_cur);
993
994
620k
        const int orig_pos_y = (by * v_mul << 4) + mvy * (1 << !ss_ver);
995
620k
        const int orig_pos_x = (bx * h_mul << 4) + mvx * (1 << !ss_hor);
996
1.24M
#define scale_mv(res, val, scale) do { \
997
1.24M
            const int64_t tmp = (int64_t)(val) * scale + (scale - 0x4000) * 8; \
998
1.24M
            res = apply_sign64((int) ((llabs(tmp) + 128) >> 8), tmp) + 32;     \
999
1.24M
        } while (0)
1000
620k
        int pos_y, pos_x;
1001
620k
        scale_mv(pos_x, orig_pos_x, f->svc[refidx][0].scale);
1002
620k
        scale_mv(pos_y, orig_pos_y, f->svc[refidx][1].scale);
1003
620k
#undef scale_mv
1004
620k
        const int left = pos_x >> 10;
1005
620k
        const int top = pos_y >> 10;
1006
620k
        const int right =
1007
620k
            ((pos_x + (bw4 * h_mul - 1) * f->svc[refidx][0].step) >> 10) + 1;
1008
620k
        const int bottom =
1009
620k
            ((pos_y + (bh4 * v_mul - 1) * f->svc[refidx][1].step) >> 10) + 1;
1010
1011
620k
        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
620k
        const int w = (refp->p.p.w + ss_hor) >> ss_hor;
1018
620k
        const int h = (refp->p.p.h + ss_ver) >> ss_ver;
1019
620k
        if (left < 3 || top < 3 || right + 4 > w || bottom + 4 > h) {
1020
290k
            pixel *const emu_edge_buf = bitfn(t->scratch.emu_edge);
1021
290k
            f->dsp->mc.emu_edge(right - left + 7, bottom - top + 7,
1022
290k
                                w, h, left - 3, top - 3,
1023
290k
                                emu_edge_buf, 320 * sizeof(pixel),
1024
290k
                                refp->p.data[pl], ref_stride);
1025
290k
            ref = &emu_edge_buf[320 * 3 + 3];
1026
290k
            ref_stride = 320 * sizeof(pixel);
1027
290k
            if (DEBUG_BLOCK_INFO) printf("Emu\n");
1028
329k
        } else {
1029
329k
            ref = ((pixel *) refp->p.data[pl]) + PXSTRIDE(ref_stride) * top + left;
1030
329k
        }
1031
1032
620k
        if (dst8 != NULL) {
1033
391k
            f->dsp->mc.mc_scaled[filter_2d](dst8, dst_stride, ref, ref_stride,
1034
391k
                                            bw4 * h_mul, bh4 * v_mul,
1035
391k
                                            pos_x & 0x3ff, pos_y & 0x3ff,
1036
391k
                                            f->svc[refidx][0].step,
1037
391k
                                            f->svc[refidx][1].step
1038
391k
                                            HIGHBD_CALL_SUFFIX);
1039
391k
        } else {
1040
228k
            f->dsp->mc.mct_scaled[filter_2d](dst16, ref, ref_stride,
1041
228k
                                             bw4 * h_mul, bh4 * v_mul,
1042
228k
                                             pos_x & 0x3ff, pos_y & 0x3ff,
1043
228k
                                             f->svc[refidx][0].step,
1044
228k
                                             f->svc[refidx][1].step
1045
228k
                                             HIGHBD_CALL_SUFFIX);
1046
228k
        }
1047
620k
    }
1048
1049
1.31M
    return 0;
1050
1.31M
}
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
94.6k
{
1057
94.6k
    assert(!(t->bx & 1) && !(t->by & 1));
1058
94.6k
    const Dav1dFrameContext *const f = t->f;
1059
94.6k
    /*const*/ refmvs_block **r = &t->rt.r[(t->by & 31) + 5];
1060
94.6k
    pixel *const lap = bitfn(t->scratch.lap);
1061
94.6k
    const int ss_ver = !!pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1062
94.6k
    const int ss_hor = !!pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1063
94.6k
    const int h_mul = 4 >> ss_hor, v_mul = 4 >> ss_ver;
1064
94.6k
    int res;
1065
1066
94.6k
    if (t->by > t->ts->tiling.row_start &&
1067
85.0k
        (!pl || b_dim[0] * h_mul + b_dim[1] * v_mul >= 16))
1068
78.7k
    {
1069
165k
        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
86.5k
            const refmvs_block *const a_r = &r[-1][t->bx + x + 1];
1072
86.5k
            const uint8_t *const a_b_dim = dav1d_block_dimensions[a_r->bs];
1073
86.5k
            const int step4 = iclip(a_b_dim[0], 2, 16);
1074
1075
86.5k
            if (a_r->ref.ref[0] > 0) {
1076
84.8k
                const int ow4 = imin(step4, b_dim[0]);
1077
84.8k
                const int oh4 = imin(b_dim[1], 16) >> 1;
1078
84.8k
                res = mc(t, lap, NULL, ow4 * h_mul * sizeof(pixel), ow4, (oh4 * 3 + 3) >> 2,
1079
84.8k
                         t->bx + x, t->by, pl, a_r->mv.mv[0],
1080
84.8k
                         &f->refp[a_r->ref.ref[0] - 1], a_r->ref.ref[0] - 1,
1081
84.8k
                         dav1d_filter_2d[t->a->filter[1][bx4 + x + 1]][t->a->filter[0][bx4 + x + 1]]);
1082
84.8k
                if (res) return res;
1083
84.8k
                f->dsp->mc.blend_h(&dst[x * h_mul], dst_stride, lap,
1084
84.8k
                                   h_mul * ow4, v_mul * oh4);
1085
84.8k
                i++;
1086
84.8k
            }
1087
86.5k
            x += step4;
1088
86.5k
        }
1089
78.7k
    }
1090
1091
94.6k
    if (t->bx > t->ts->tiling.col_start)
1092
165k
        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
87.2k
            const refmvs_block *const l_r = &r[y + 1][t->bx - 1];
1095
87.2k
            const uint8_t *const l_b_dim = dav1d_block_dimensions[l_r->bs];
1096
87.2k
            const int step4 = iclip(l_b_dim[1], 2, 16);
1097
1098
87.2k
            if (l_r->ref.ref[0] > 0) {
1099
85.4k
                const int ow4 = imin(b_dim[0], 16) >> 1;
1100
85.4k
                const int oh4 = imin(step4, b_dim[1]);
1101
85.4k
                res = mc(t, lap, NULL, h_mul * ow4 * sizeof(pixel), ow4, oh4,
1102
85.4k
                         t->bx, t->by + y, pl, l_r->mv.mv[0],
1103
85.4k
                         &f->refp[l_r->ref.ref[0] - 1], l_r->ref.ref[0] - 1,
1104
85.4k
                         dav1d_filter_2d[t->l.filter[1][by4 + y + 1]][t->l.filter[0][by4 + y + 1]]);
1105
85.4k
                if (res) return res;
1106
85.4k
                f->dsp->mc.blend_v(&dst[y * v_mul * PXSTRIDE(dst_stride)],
1107
85.4k
                                   dst_stride, lap, h_mul * ow4, v_mul * oh4);
1108
85.4k
                i++;
1109
85.4k
            }
1110
87.2k
            y += step4;
1111
87.2k
        }
1112
94.6k
    return 0;
1113
94.6k
}
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
23.1k
{
1121
23.1k
    assert((dst8 != NULL) ^ (dst16 != NULL));
1122
23.1k
    const Dav1dFrameContext *const f = t->f;
1123
23.1k
    const Dav1dDSPContext *const dsp = f->dsp;
1124
23.1k
    const int ss_ver = !!pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1125
23.1k
    const int ss_hor = !!pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1126
23.1k
    const int h_mul = 4 >> ss_hor, v_mul = 4 >> ss_ver;
1127
23.1k
    assert(!((b_dim[0] * h_mul) & 7) && !((b_dim[1] * v_mul) & 7));
1128
23.1k
    const int32_t *const mat = wmp->matrix;
1129
23.1k
    const int width = (refp->p.p.w + ss_hor) >> ss_hor;
1130
23.1k
    const int height = (refp->p.p.h + ss_ver) >> ss_ver;
1131
1132
83.5k
    for (int y = 0; y < b_dim[1] * v_mul; y += 8) {
1133
60.4k
        const int src_y = t->by * 4 + ((y + 4) << ss_ver);
1134
60.4k
        const int64_t mat3_y = (int64_t) mat[3] * src_y + mat[0];
1135
60.4k
        const int64_t mat5_y = (int64_t) mat[5] * src_y + mat[1];
1136
316k
        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
256k
            const int src_x = t->bx * 4 + ((x + 4) << ss_hor);
1140
256k
            const int64_t mvx = ((int64_t) mat[2] * src_x + mat3_y) >> ss_hor;
1141
256k
            const int64_t mvy = ((int64_t) mat[4] * src_x + mat5_y) >> ss_ver;
1142
1143
256k
            const int dx = (int) (mvx >> 16) - 4;
1144
256k
            const int mx = (((int) mvx & 0xffff) - wmp->u.p.alpha * 4 -
1145
256k
                                                   wmp->u.p.beta  * 7) & ~0x3f;
1146
256k
            const int dy = (int) (mvy >> 16) - 4;
1147
256k
            const int my = (((int) mvy & 0xffff) - wmp->u.p.gamma * 4 -
1148
256k
                                                   wmp->u.p.delta * 4) & ~0x3f;
1149
1150
256k
            const pixel *ref_ptr;
1151
256k
            ptrdiff_t ref_stride = refp->p.stride[!!pl];
1152
1153
256k
            if (dx < 3 || dx + 8 + 4 > width || dy < 3 || dy + 8 + 4 > height) {
1154
212k
                pixel *const emu_edge_buf = bitfn(t->scratch.emu_edge);
1155
212k
                f->dsp->mc.emu_edge(15, 15, width, height, dx - 3, dy - 3,
1156
212k
                                    emu_edge_buf, 32 * sizeof(pixel),
1157
212k
                                    refp->p.data[pl], ref_stride);
1158
212k
                ref_ptr = &emu_edge_buf[32 * 3 + 3];
1159
212k
                ref_stride = 32 * sizeof(pixel);
1160
212k
            } else {
1161
43.3k
                ref_ptr = ((pixel *) refp->p.data[pl]) + PXSTRIDE(ref_stride) * dy + dx;
1162
43.3k
            }
1163
256k
            if (dst16 != NULL)
1164
28.9k
                dsp->mc.warp8x8t(&dst16[x], dstride, ref_ptr, ref_stride,
1165
28.9k
                                 wmp->u.abcd, mx, my HIGHBD_CALL_SUFFIX);
1166
227k
            else
1167
227k
                dsp->mc.warp8x8(&dst8[x], dstride, ref_ptr, ref_stride,
1168
227k
                                wmp->u.abcd, mx, my HIGHBD_CALL_SUFFIX);
1169
256k
        }
1170
60.4k
        if (dst8) dst8  += 8 * PXSTRIDE(dstride);
1171
11.3k
        else      dst16 += 8 * dstride;
1172
60.4k
    }
1173
23.1k
    return 0;
1174
23.1k
}
1175
1176
void bytefn(dav1d_recon_b_intra)(Dav1dTaskContext *const t, const enum BlockSize bs,
1177
                                 const enum EdgeFlags intra_edge_flags,
1178
                                 const Av1Block *const b)
1179
1.45M
{
1180
1.45M
    Dav1dTileState *const ts = t->ts;
1181
1.45M
    const Dav1dFrameContext *const f = t->f;
1182
1.45M
    const Dav1dDSPContext *const dsp = f->dsp;
1183
1.45M
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1184
1.45M
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1185
1.45M
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1186
1.45M
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1187
1.45M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1188
1.45M
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1189
1.45M
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1190
1.45M
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1191
1.45M
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1192
1.21M
                           (bw4 > ss_hor || t->bx & 1) &&
1193
1.13M
                           (bh4 > ss_ver || t->by & 1);
1194
1.45M
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->tx];
1195
1.45M
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
1196
1197
    // coefficient coding
1198
1.45M
    pixel *const edge = bitfn(t->scratch.edge) + 128;
1199
1.45M
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
1200
1201
1.45M
    const int intra_edge_filter_flag = f->seq_hdr->intra_edge_filter << 10;
1202
1203
2.93M
    for (int init_y = 0; init_y < h4; init_y += 16) {
1204
1.47M
        const int sub_h4 = imin(h4, 16 + init_y);
1205
1.47M
        const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
1206
3.00M
        for (int init_x = 0; init_x < w4; init_x += 16) {
1207
1.52M
            if (b->pal_sz[0]) {
1208
13.5k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1209
13.5k
                             4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1210
13.5k
                const uint8_t *pal_idx;
1211
13.5k
                if (t->frame_thread.pass) {
1212
13.5k
                    const int p = t->frame_thread.pass & 1;
1213
13.5k
                    assert(ts->frame_thread[p].pal_idx);
1214
13.5k
                    pal_idx = ts->frame_thread[p].pal_idx;
1215
13.5k
                    ts->frame_thread[p].pal_idx += bw4 * bh4 * 8;
1216
13.5k
                } else {
1217
0
                    pal_idx = t->scratch.pal_idx_y;
1218
0
                }
1219
13.5k
                const pixel *const pal = t->frame_thread.pass ?
1220
13.5k
                    f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1221
13.5k
                                        ((t->bx >> 1) + (t->by & 1))][0] :
1222
13.5k
                    bytefn(t->scratch.pal)[0];
1223
13.5k
                f->dsp->ipred.pal_pred(dst, f->cur.stride[0], pal,
1224
13.5k
                                       pal_idx, bw4 * 4, bh4 * 4);
1225
13.5k
                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
13.5k
            }
1229
1230
1.52M
            const int intra_flags = (sm_flag(t->a, bx4) |
1231
1.52M
                                     sm_flag(&t->l, by4) |
1232
1.52M
                                     intra_edge_filter_flag);
1233
1.52M
            const int sb_has_tr = init_x + 16 < w4 ? 1 : init_y ? 0 :
1234
1.47M
                              intra_edge_flags & EDGE_I444_TOP_HAS_RIGHT;
1235
1.52M
            const int sb_has_bl = init_x ? 0 : init_y + 16 < h4 ? 1 :
1236
1.47M
                              intra_edge_flags & EDGE_I444_LEFT_HAS_BOTTOM;
1237
1.52M
            int y, x;
1238
1.52M
            const int sub_w4 = imin(w4, init_x + 16);
1239
3.40M
            for (y = init_y, t->by += init_y; y < sub_h4;
1240
1.88M
                 y += t_dim->h, t->by += t_dim->h)
1241
1.88M
            {
1242
1.88M
                pixel *dst = ((pixel *) f->cur.data[0]) +
1243
1.88M
                               4 * (t->by * PXSTRIDE(f->cur.stride[0]) +
1244
1.88M
                                    t->bx + init_x);
1245
4.93M
                for (x = init_x, t->bx += init_x; x < sub_w4;
1246
3.05M
                     x += t_dim->w, t->bx += t_dim->w)
1247
3.05M
                {
1248
3.05M
                    if (b->pal_sz[0]) goto skip_y_pred;
1249
1250
3.03M
                    int angle = b->y_angle;
1251
3.03M
                    const enum EdgeFlags edge_flags =
1252
3.03M
                        (((y > init_y || !sb_has_tr) && (x + t_dim->w >= sub_w4)) ?
1253
2.16M
                             0 : EDGE_I444_TOP_HAS_RIGHT) |
1254
3.03M
                        ((x > init_x || (!sb_has_bl && y + t_dim->h >= sub_h4)) ?
1255
2.00M
                             0 : EDGE_I444_LEFT_HAS_BOTTOM);
1256
3.03M
                    const pixel *top_sb_edge = NULL;
1257
3.03M
                    if (!(t->by & (f->sb_step - 1))) {
1258
604k
                        top_sb_edge = f->ipred_edge[0];
1259
604k
                        const int sby = t->by >> f->sb_shift;
1260
604k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1261
604k
                    }
1262
3.03M
                    const enum IntraPredMode m =
1263
3.03M
                        bytefn(dav1d_prepare_intra_edges)(t->bx,
1264
3.03M
                                                          t->bx > ts->tiling.col_start,
1265
3.03M
                                                          t->by,
1266
3.03M
                                                          t->by > ts->tiling.row_start,
1267
3.03M
                                                          ts->tiling.col_end,
1268
3.03M
                                                          ts->tiling.row_end,
1269
3.03M
                                                          edge_flags, dst,
1270
3.03M
                                                          f->cur.stride[0], top_sb_edge,
1271
3.03M
                                                          b->y_mode, &angle,
1272
3.03M
                                                          t_dim->w, t_dim->h,
1273
3.03M
                                                          f->seq_hdr->intra_edge_filter,
1274
3.03M
                                                          edge HIGHBD_CALL_SUFFIX);
1275
3.03M
                    dsp->ipred.intra_pred[m](dst, f->cur.stride[0], edge,
1276
3.03M
                                             t_dim->w * 4, t_dim->h * 4,
1277
3.03M
                                             angle | intra_flags,
1278
3.03M
                                             4 * f->bw - 4 * t->bx,
1279
3.03M
                                             4 * f->bh - 4 * t->by
1280
3.03M
                                             HIGHBD_CALL_SUFFIX);
1281
1282
3.03M
                    if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1283
0
                        hex_dump(edge - t_dim->h * 4, t_dim->h * 4,
1284
0
                                 t_dim->h * 4, 2, "l");
1285
0
                        hex_dump(edge, 0, 1, 1, "tl");
1286
0
                        hex_dump(edge + 1, t_dim->w * 4,
1287
0
                                 t_dim->w * 4, 2, "t");
1288
0
                        hex_dump(dst, f->cur.stride[0],
1289
0
                                 t_dim->w * 4, t_dim->h * 4, "y-intra-pred");
1290
0
                    }
1291
1292
3.05M
                skip_y_pred: {}
1293
3.05M
                    if (!b->skip) {
1294
879k
                        coef *cf;
1295
879k
                        int eob;
1296
879k
                        enum TxfmType txtp;
1297
879k
                        if (t->frame_thread.pass) {
1298
879k
                            const int p = t->frame_thread.pass & 1;
1299
879k
                            const int cbi = *ts->frame_thread[p].cbi++;
1300
879k
                            cf = ts->frame_thread[p].cf;
1301
879k
                            ts->frame_thread[p].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
1302
879k
                            eob  = cbi >> 5;
1303
879k
                            txtp = cbi & 0x1f;
1304
879k
                        } else {
1305
1
                            uint8_t cf_ctx;
1306
1
                            cf = bitfn(t->cf);
1307
1
                            eob = decode_coefs(t, &t->a->lcoef[bx4 + x],
1308
1
                                               &t->l.lcoef[by4 + y], b->tx, bs,
1309
1
                                               b, 1, 0, cf, &txtp, &cf_ctx);
1310
1
                            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
1
                            dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
1314
1
                            dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
1315
1
                        }
1316
879k
                        if (eob >= 0) {
1317
602k
                            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
602k
                            dsp->itx.itxfm_add[b->tx]
1321
602k
                                              [txtp](dst,
1322
602k
                                                     f->cur.stride[0],
1323
602k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1324
602k
                            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
602k
                        }
1328
2.17M
                    } else if (!t->frame_thread.pass) {
1329
0
                        dav1d_memset_pow2[t_dim->lw](&t->a->lcoef[bx4 + x], 0x40);
1330
0
                        dav1d_memset_pow2[t_dim->lh](&t->l.lcoef[by4 + y], 0x40);
1331
0
                    }
1332
3.05M
                    dst += 4 * t_dim->w;
1333
3.05M
                }
1334
1.88M
                t->bx -= x;
1335
1.88M
            }
1336
1.52M
            t->by -= y;
1337
1338
1.52M
            if (!has_chroma) continue;
1339
1340
1.10M
            const ptrdiff_t stride = f->cur.stride[1];
1341
1342
1.10M
            if (b->uv_mode == CFL_PRED) {
1343
208k
                assert(!init_x && !init_y);
1344
1345
208k
                int16_t *const ac = t->scratch.ac;
1346
208k
                pixel *y_src = ((pixel *) f->cur.data[0]) + 4 * (t->bx & ~ss_hor) +
1347
208k
                                 4 * (t->by & ~ss_ver) * PXSTRIDE(f->cur.stride[0]);
1348
208k
                const ptrdiff_t uv_off = 4 * ((t->bx >> ss_hor) +
1349
208k
                                              (t->by >> ss_ver) * PXSTRIDE(stride));
1350
208k
                pixel *const uv_dst[2] = { ((pixel *) f->cur.data[1]) + uv_off,
1351
208k
                                           ((pixel *) f->cur.data[2]) + uv_off };
1352
1353
208k
                const int furthest_r =
1354
208k
                    ((cw4 << ss_hor) + t_dim->w - 1) & ~(t_dim->w - 1);
1355
208k
                const int furthest_b =
1356
208k
                    ((ch4 << ss_ver) + t_dim->h - 1) & ~(t_dim->h - 1);
1357
208k
                dsp->ipred.cfl_ac[f->cur.p.layout - 1](ac, y_src, f->cur.stride[0],
1358
208k
                                                         cbw4 - (furthest_r >> ss_hor),
1359
208k
                                                         cbh4 - (furthest_b >> ss_ver),
1360
208k
                                                         cbw4 * 4, cbh4 * 4);
1361
626k
                for (int pl = 0; pl < 2; pl++) {
1362
417k
                    if (!b->cfl_alpha[pl]) continue;
1363
330k
                    int angle = 0;
1364
330k
                    const pixel *top_sb_edge = NULL;
1365
330k
                    if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1366
90.5k
                        top_sb_edge = f->ipred_edge[pl + 1];
1367
90.5k
                        const int sby = t->by >> f->sb_shift;
1368
90.5k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1369
90.5k
                    }
1370
330k
                    const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1371
330k
                    const int xstart = ts->tiling.col_start >> ss_hor;
1372
330k
                    const int ystart = ts->tiling.row_start >> ss_ver;
1373
330k
                    const enum IntraPredMode m =
1374
330k
                        bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1375
330k
                                                          ypos, ypos > ystart,
1376
330k
                                                          ts->tiling.col_end >> ss_hor,
1377
330k
                                                          ts->tiling.row_end >> ss_ver,
1378
330k
                                                          0, uv_dst[pl], stride,
1379
330k
                                                          top_sb_edge, DC_PRED, &angle,
1380
330k
                                                          uv_t_dim->w, uv_t_dim->h, 0,
1381
330k
                                                          edge HIGHBD_CALL_SUFFIX);
1382
330k
                    dsp->ipred.cfl_pred[m](uv_dst[pl], stride, edge,
1383
330k
                                           uv_t_dim->w * 4,
1384
330k
                                           uv_t_dim->h * 4,
1385
330k
                                           ac, b->cfl_alpha[pl]
1386
330k
                                           HIGHBD_CALL_SUFFIX);
1387
330k
                }
1388
208k
                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
894k
            } else if (b->pal_sz[1]) {
1394
2.72k
                const ptrdiff_t uv_dstoff = 4 * ((t->bx >> ss_hor) +
1395
2.72k
                                              (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1396
2.72k
                const pixel (*pal)[8];
1397
2.72k
                const uint8_t *pal_idx;
1398
2.72k
                if (t->frame_thread.pass) {
1399
2.72k
                    const int p = t->frame_thread.pass & 1;
1400
2.72k
                    assert(ts->frame_thread[p].pal_idx);
1401
2.72k
                    pal = f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1402
2.72k
                                              ((t->bx >> 1) + (t->by & 1))];
1403
2.72k
                    pal_idx = ts->frame_thread[p].pal_idx;
1404
2.72k
                    ts->frame_thread[p].pal_idx += cbw4 * cbh4 * 8;
1405
2.72k
                } else {
1406
0
                    pal = bytefn(t->scratch.pal);
1407
0
                    pal_idx = t->scratch.pal_idx_uv;
1408
0
                }
1409
1410
2.72k
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[1]) + uv_dstoff,
1411
2.72k
                                       f->cur.stride[1], pal[1],
1412
2.72k
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1413
2.72k
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[2]) + uv_dstoff,
1414
2.72k
                                       f->cur.stride[1], pal[2],
1415
2.72k
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1416
2.72k
                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
2.72k
            }
1425
1426
1.10M
            const int sm_uv_fl = sm_uv_flag(t->a, cbx4) |
1427
1.10M
                                 sm_uv_flag(&t->l, cby4);
1428
1.10M
            const int uv_sb_has_tr =
1429
1.10M
                ((init_x + 16) >> ss_hor) < cw4 ? 1 : init_y ? 0 :
1430
1.06M
                intra_edge_flags & (EDGE_I420_TOP_HAS_RIGHT >> (f->cur.p.layout - 1));
1431
1.10M
            const int uv_sb_has_bl =
1432
1.10M
                init_x ? 0 : ((init_y + 16) >> ss_ver) < ch4 ? 1 :
1433
1.06M
                intra_edge_flags & (EDGE_I420_LEFT_HAS_BOTTOM >> (f->cur.p.layout - 1));
1434
1.10M
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
1435
3.30M
            for (int pl = 0; pl < 2; pl++) {
1436
4.55M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
1437
2.35M
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
1438
2.35M
                {
1439
2.35M
                    pixel *dst = ((pixel *) f->cur.data[1 + pl]) +
1440
2.35M
                                   4 * ((t->by >> ss_ver) * PXSTRIDE(stride) +
1441
2.35M
                                        ((t->bx + init_x) >> ss_hor));
1442
5.08M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
1443
2.73M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
1444
2.73M
                    {
1445
2.73M
                        if ((b->uv_mode == CFL_PRED && b->cfl_alpha[pl]) ||
1446
2.40M
                            b->pal_sz[1])
1447
338k
                        {
1448
338k
                            goto skip_uv_pred;
1449
338k
                        }
1450
1451
2.39M
                        int angle = b->uv_angle;
1452
                        // this probably looks weird because we're using
1453
                        // luma flags in a chroma loop, but that's because
1454
                        // prepare_intra_edges() expects luma flags as input
1455
2.39M
                        const enum EdgeFlags edge_flags =
1456
2.39M
                            (((y > (init_y >> ss_ver) || !uv_sb_has_tr) &&
1457
1.01M
                              (x + uv_t_dim->w >= sub_cw4)) ?
1458
1.67M
                                 0 : EDGE_I444_TOP_HAS_RIGHT) |
1459
2.39M
                            ((x > (init_x >> ss_hor) ||
1460
2.01M
                              (!uv_sb_has_bl && y + uv_t_dim->h >= sub_ch4)) ?
1461
1.44M
                                 0 : EDGE_I444_LEFT_HAS_BOTTOM);
1462
2.39M
                        const pixel *top_sb_edge = NULL;
1463
2.39M
                        if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1464
699k
                            top_sb_edge = f->ipred_edge[1 + pl];
1465
699k
                            const int sby = t->by >> f->sb_shift;
1466
699k
                            top_sb_edge += f->sb128w * 128 * (sby - 1);
1467
699k
                        }
1468
2.39M
                        const enum IntraPredMode uv_mode =
1469
2.39M
                             b->uv_mode == CFL_PRED ? DC_PRED : b->uv_mode;
1470
2.39M
                        const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1471
2.39M
                        const int xstart = ts->tiling.col_start >> ss_hor;
1472
2.39M
                        const int ystart = ts->tiling.row_start >> ss_ver;
1473
2.39M
                        const enum IntraPredMode m =
1474
2.39M
                            bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1475
2.39M
                                                              ypos, ypos > ystart,
1476
2.39M
                                                              ts->tiling.col_end >> ss_hor,
1477
2.39M
                                                              ts->tiling.row_end >> ss_ver,
1478
2.39M
                                                              edge_flags, dst, stride,
1479
2.39M
                                                              top_sb_edge, uv_mode,
1480
2.39M
                                                              &angle, uv_t_dim->w,
1481
2.39M
                                                              uv_t_dim->h,
1482
2.39M
                                                              f->seq_hdr->intra_edge_filter,
1483
2.39M
                                                              edge HIGHBD_CALL_SUFFIX);
1484
2.39M
                        angle |= intra_edge_filter_flag;
1485
2.39M
                        dsp->ipred.intra_pred[m](dst, stride, edge,
1486
2.39M
                                                 uv_t_dim->w * 4,
1487
2.39M
                                                 uv_t_dim->h * 4,
1488
2.39M
                                                 angle | sm_uv_fl,
1489
2.39M
                                                 (4 * f->bw + ss_hor -
1490
2.39M
                                                  4 * (t->bx & ~ss_hor)) >> ss_hor,
1491
2.39M
                                                 (4 * f->bh + ss_ver -
1492
2.39M
                                                  4 * (t->by & ~ss_ver)) >> ss_ver
1493
2.39M
                                                 HIGHBD_CALL_SUFFIX);
1494
2.39M
                        if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1495
0
                            hex_dump(edge - uv_t_dim->h * 4, uv_t_dim->h * 4,
1496
0
                                     uv_t_dim->h * 4, 2, "l");
1497
0
                            hex_dump(edge, 0, 1, 1, "tl");
1498
0
                            hex_dump(edge + 1, uv_t_dim->w * 4,
1499
0
                                     uv_t_dim->w * 4, 2, "t");
1500
0
                            hex_dump(dst, stride, uv_t_dim->w * 4,
1501
0
                                     uv_t_dim->h * 4, pl ? "v-intra-pred" : "u-intra-pred");
1502
0
                        }
1503
1504
2.73M
                    skip_uv_pred: {}
1505
2.73M
                        if (!b->skip) {
1506
889k
                            enum TxfmType txtp;
1507
889k
                            int eob;
1508
889k
                            coef *cf;
1509
889k
                            if (t->frame_thread.pass) {
1510
889k
                                const int p = t->frame_thread.pass & 1;
1511
889k
                                const int cbi = *ts->frame_thread[p].cbi++;
1512
889k
                                cf = ts->frame_thread[p].cf;
1513
889k
                                ts->frame_thread[p].cf += uv_t_dim->w * uv_t_dim->h * 16;
1514
889k
                                eob  = cbi >> 5;
1515
889k
                                txtp = cbi & 0x1f;
1516
889k
                            } 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
889k
                            if (eob >= 0) {
1533
303k
                                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
303k
                                dsp->itx.itxfm_add[b->uvtx]
1537
303k
                                                  [txtp](dst, stride,
1538
303k
                                                         cf, eob HIGHBD_CALL_SUFFIX);
1539
303k
                                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
303k
                            }
1543
1.84M
                        } else if (!t->frame_thread.pass) {
1544
0
                            dav1d_memset_pow2[uv_t_dim->lw](&t->a->ccoef[pl][cbx4 + x], 0x40);
1545
0
                            dav1d_memset_pow2[uv_t_dim->lh](&t->l.ccoef[pl][cby4 + y], 0x40);
1546
0
                        }
1547
2.73M
                        dst += uv_t_dim->w * 4;
1548
2.73M
                    }
1549
2.35M
                    t->bx -= x << ss_hor;
1550
2.35M
                }
1551
2.20M
                t->by -= y << ss_ver;
1552
2.20M
            }
1553
1.10M
        }
1554
1.47M
    }
1555
1.45M
}
dav1d_recon_b_intra_8bpc
Line
Count
Source
1179
769k
{
1180
769k
    Dav1dTileState *const ts = t->ts;
1181
769k
    const Dav1dFrameContext *const f = t->f;
1182
769k
    const Dav1dDSPContext *const dsp = f->dsp;
1183
769k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1184
769k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1185
769k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1186
769k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1187
769k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1188
769k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1189
769k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1190
769k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1191
769k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1192
608k
                           (bw4 > ss_hor || t->bx & 1) &&
1193
561k
                           (bh4 > ss_ver || t->by & 1);
1194
769k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->tx];
1195
769k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
1196
1197
    // coefficient coding
1198
769k
    pixel *const edge = bitfn(t->scratch.edge) + 128;
1199
769k
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
1200
1201
769k
    const int intra_edge_filter_flag = f->seq_hdr->intra_edge_filter << 10;
1202
1203
1.54M
    for (int init_y = 0; init_y < h4; init_y += 16) {
1204
779k
        const int sub_h4 = imin(h4, 16 + init_y);
1205
779k
        const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
1206
1.57M
        for (int init_x = 0; init_x < w4; init_x += 16) {
1207
795k
            if (b->pal_sz[0]) {
1208
6.29k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1209
6.29k
                             4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1210
6.29k
                const uint8_t *pal_idx;
1211
6.29k
                if (t->frame_thread.pass) {
1212
6.29k
                    const int p = t->frame_thread.pass & 1;
1213
6.29k
                    assert(ts->frame_thread[p].pal_idx);
1214
6.29k
                    pal_idx = ts->frame_thread[p].pal_idx;
1215
6.29k
                    ts->frame_thread[p].pal_idx += bw4 * bh4 * 8;
1216
6.29k
                } else {
1217
0
                    pal_idx = t->scratch.pal_idx_y;
1218
0
                }
1219
6.29k
                const pixel *const pal = t->frame_thread.pass ?
1220
6.29k
                    f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1221
6.29k
                                        ((t->bx >> 1) + (t->by & 1))][0] :
1222
6.29k
                    bytefn(t->scratch.pal)[0];
1223
6.29k
                f->dsp->ipred.pal_pred(dst, f->cur.stride[0], pal,
1224
6.29k
                                       pal_idx, bw4 * 4, bh4 * 4);
1225
6.29k
                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1226
0
                    hex_dump(dst, PXSTRIDE(f->cur.stride[0]),
1227
0
                             bw4 * 4, bh4 * 4, "y-pal-pred");
1228
6.29k
            }
1229
1230
795k
            const int intra_flags = (sm_flag(t->a, bx4) |
1231
795k
                                     sm_flag(&t->l, by4) |
1232
795k
                                     intra_edge_filter_flag);
1233
795k
            const int sb_has_tr = init_x + 16 < w4 ? 1 : init_y ? 0 :
1234
779k
                              intra_edge_flags & EDGE_I444_TOP_HAS_RIGHT;
1235
795k
            const int sb_has_bl = init_x ? 0 : init_y + 16 < h4 ? 1 :
1236
779k
                              intra_edge_flags & EDGE_I444_LEFT_HAS_BOTTOM;
1237
795k
            int y, x;
1238
795k
            const int sub_w4 = imin(w4, init_x + 16);
1239
1.82M
            for (y = init_y, t->by += init_y; y < sub_h4;
1240
1.02M
                 y += t_dim->h, t->by += t_dim->h)
1241
1.02M
            {
1242
1.02M
                pixel *dst = ((pixel *) f->cur.data[0]) +
1243
1.02M
                               4 * (t->by * PXSTRIDE(f->cur.stride[0]) +
1244
1.02M
                                    t->bx + init_x);
1245
2.68M
                for (x = init_x, t->bx += init_x; x < sub_w4;
1246
1.65M
                     x += t_dim->w, t->bx += t_dim->w)
1247
1.65M
                {
1248
1.65M
                    if (b->pal_sz[0]) goto skip_y_pred;
1249
1250
1.64M
                    int angle = b->y_angle;
1251
1.64M
                    const enum EdgeFlags edge_flags =
1252
1.64M
                        (((y > init_y || !sb_has_tr) && (x + t_dim->w >= sub_w4)) ?
1253
1.16M
                             0 : EDGE_I444_TOP_HAS_RIGHT) |
1254
1.64M
                        ((x > init_x || (!sb_has_bl && y + t_dim->h >= sub_h4)) ?
1255
1.08M
                             0 : EDGE_I444_LEFT_HAS_BOTTOM);
1256
1.64M
                    const pixel *top_sb_edge = NULL;
1257
1.64M
                    if (!(t->by & (f->sb_step - 1))) {
1258
354k
                        top_sb_edge = f->ipred_edge[0];
1259
354k
                        const int sby = t->by >> f->sb_shift;
1260
354k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1261
354k
                    }
1262
1.64M
                    const enum IntraPredMode m =
1263
1.64M
                        bytefn(dav1d_prepare_intra_edges)(t->bx,
1264
1.64M
                                                          t->bx > ts->tiling.col_start,
1265
1.64M
                                                          t->by,
1266
1.64M
                                                          t->by > ts->tiling.row_start,
1267
1.64M
                                                          ts->tiling.col_end,
1268
1.64M
                                                          ts->tiling.row_end,
1269
1.64M
                                                          edge_flags, dst,
1270
1.64M
                                                          f->cur.stride[0], top_sb_edge,
1271
1.64M
                                                          b->y_mode, &angle,
1272
1.64M
                                                          t_dim->w, t_dim->h,
1273
1.64M
                                                          f->seq_hdr->intra_edge_filter,
1274
1.64M
                                                          edge HIGHBD_CALL_SUFFIX);
1275
1.64M
                    dsp->ipred.intra_pred[m](dst, f->cur.stride[0], edge,
1276
1.64M
                                             t_dim->w * 4, t_dim->h * 4,
1277
1.64M
                                             angle | intra_flags,
1278
1.64M
                                             4 * f->bw - 4 * t->bx,
1279
1.64M
                                             4 * f->bh - 4 * t->by
1280
1.64M
                                             HIGHBD_CALL_SUFFIX);
1281
1282
1.64M
                    if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1283
0
                        hex_dump(edge - t_dim->h * 4, t_dim->h * 4,
1284
0
                                 t_dim->h * 4, 2, "l");
1285
0
                        hex_dump(edge, 0, 1, 1, "tl");
1286
0
                        hex_dump(edge + 1, t_dim->w * 4,
1287
0
                                 t_dim->w * 4, 2, "t");
1288
0
                        hex_dump(dst, f->cur.stride[0],
1289
0
                                 t_dim->w * 4, t_dim->h * 4, "y-intra-pred");
1290
0
                    }
1291
1292
1.65M
                skip_y_pred: {}
1293
1.65M
                    if (!b->skip) {
1294
462k
                        coef *cf;
1295
462k
                        int eob;
1296
462k
                        enum TxfmType txtp;
1297
462k
                        if (t->frame_thread.pass) {
1298
462k
                            const int p = t->frame_thread.pass & 1;
1299
462k
                            const int cbi = *ts->frame_thread[p].cbi++;
1300
462k
                            cf = ts->frame_thread[p].cf;
1301
462k
                            ts->frame_thread[p].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
1302
462k
                            eob  = cbi >> 5;
1303
462k
                            txtp = cbi & 0x1f;
1304
462k
                        } else {
1305
1
                            uint8_t cf_ctx;
1306
1
                            cf = bitfn(t->cf);
1307
1
                            eob = decode_coefs(t, &t->a->lcoef[bx4 + x],
1308
1
                                               &t->l.lcoef[by4 + y], b->tx, bs,
1309
1
                                               b, 1, 0, cf, &txtp, &cf_ctx);
1310
1
                            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
1
                            dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
1314
1
                            dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
1315
1
                        }
1316
462k
                        if (eob >= 0) {
1317
317k
                            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
317k
                            dsp->itx.itxfm_add[b->tx]
1321
317k
                                              [txtp](dst,
1322
317k
                                                     f->cur.stride[0],
1323
317k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1324
317k
                            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
317k
                        }
1328
1.19M
                    } else if (!t->frame_thread.pass) {
1329
0
                        dav1d_memset_pow2[t_dim->lw](&t->a->lcoef[bx4 + x], 0x40);
1330
0
                        dav1d_memset_pow2[t_dim->lh](&t->l.lcoef[by4 + y], 0x40);
1331
0
                    }
1332
1.65M
                    dst += 4 * t_dim->w;
1333
1.65M
                }
1334
1.02M
                t->bx -= x;
1335
1.02M
            }
1336
795k
            t->by -= y;
1337
1338
795k
            if (!has_chroma) continue;
1339
1340
536k
            const ptrdiff_t stride = f->cur.stride[1];
1341
1342
536k
            if (b->uv_mode == CFL_PRED) {
1343
103k
                assert(!init_x && !init_y);
1344
1345
103k
                int16_t *const ac = t->scratch.ac;
1346
103k
                pixel *y_src = ((pixel *) f->cur.data[0]) + 4 * (t->bx & ~ss_hor) +
1347
103k
                                 4 * (t->by & ~ss_ver) * PXSTRIDE(f->cur.stride[0]);
1348
103k
                const ptrdiff_t uv_off = 4 * ((t->bx >> ss_hor) +
1349
103k
                                              (t->by >> ss_ver) * PXSTRIDE(stride));
1350
103k
                pixel *const uv_dst[2] = { ((pixel *) f->cur.data[1]) + uv_off,
1351
103k
                                           ((pixel *) f->cur.data[2]) + uv_off };
1352
1353
103k
                const int furthest_r =
1354
103k
                    ((cw4 << ss_hor) + t_dim->w - 1) & ~(t_dim->w - 1);
1355
103k
                const int furthest_b =
1356
103k
                    ((ch4 << ss_ver) + t_dim->h - 1) & ~(t_dim->h - 1);
1357
103k
                dsp->ipred.cfl_ac[f->cur.p.layout - 1](ac, y_src, f->cur.stride[0],
1358
103k
                                                         cbw4 - (furthest_r >> ss_hor),
1359
103k
                                                         cbh4 - (furthest_b >> ss_ver),
1360
103k
                                                         cbw4 * 4, cbh4 * 4);
1361
310k
                for (int pl = 0; pl < 2; pl++) {
1362
206k
                    if (!b->cfl_alpha[pl]) continue;
1363
163k
                    int angle = 0;
1364
163k
                    const pixel *top_sb_edge = NULL;
1365
163k
                    if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1366
50.0k
                        top_sb_edge = f->ipred_edge[pl + 1];
1367
50.0k
                        const int sby = t->by >> f->sb_shift;
1368
50.0k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1369
50.0k
                    }
1370
163k
                    const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1371
163k
                    const int xstart = ts->tiling.col_start >> ss_hor;
1372
163k
                    const int ystart = ts->tiling.row_start >> ss_ver;
1373
163k
                    const enum IntraPredMode m =
1374
163k
                        bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1375
163k
                                                          ypos, ypos > ystart,
1376
163k
                                                          ts->tiling.col_end >> ss_hor,
1377
163k
                                                          ts->tiling.row_end >> ss_ver,
1378
163k
                                                          0, uv_dst[pl], stride,
1379
163k
                                                          top_sb_edge, DC_PRED, &angle,
1380
163k
                                                          uv_t_dim->w, uv_t_dim->h, 0,
1381
163k
                                                          edge HIGHBD_CALL_SUFFIX);
1382
163k
                    dsp->ipred.cfl_pred[m](uv_dst[pl], stride, edge,
1383
163k
                                           uv_t_dim->w * 4,
1384
163k
                                           uv_t_dim->h * 4,
1385
163k
                                           ac, b->cfl_alpha[pl]
1386
163k
                                           HIGHBD_CALL_SUFFIX);
1387
163k
                }
1388
103k
                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
432k
            } else if (b->pal_sz[1]) {
1394
685
                const ptrdiff_t uv_dstoff = 4 * ((t->bx >> ss_hor) +
1395
685
                                              (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1396
685
                const pixel (*pal)[8];
1397
685
                const uint8_t *pal_idx;
1398
685
                if (t->frame_thread.pass) {
1399
685
                    const int p = t->frame_thread.pass & 1;
1400
685
                    assert(ts->frame_thread[p].pal_idx);
1401
685
                    pal = f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1402
685
                                              ((t->bx >> 1) + (t->by & 1))];
1403
685
                    pal_idx = ts->frame_thread[p].pal_idx;
1404
685
                    ts->frame_thread[p].pal_idx += cbw4 * cbh4 * 8;
1405
685
                } else {
1406
0
                    pal = bytefn(t->scratch.pal);
1407
0
                    pal_idx = t->scratch.pal_idx_uv;
1408
0
                }
1409
1410
685
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[1]) + uv_dstoff,
1411
685
                                       f->cur.stride[1], pal[1],
1412
685
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1413
685
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[2]) + uv_dstoff,
1414
685
                                       f->cur.stride[1], pal[2],
1415
685
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1416
685
                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
685
            }
1425
1426
536k
            const int sm_uv_fl = sm_uv_flag(t->a, cbx4) |
1427
536k
                                 sm_uv_flag(&t->l, cby4);
1428
536k
            const int uv_sb_has_tr =
1429
536k
                ((init_x + 16) >> ss_hor) < cw4 ? 1 : init_y ? 0 :
1430
521k
                intra_edge_flags & (EDGE_I420_TOP_HAS_RIGHT >> (f->cur.p.layout - 1));
1431
536k
            const int uv_sb_has_bl =
1432
536k
                init_x ? 0 : ((init_y + 16) >> ss_ver) < ch4 ? 1 :
1433
521k
                intra_edge_flags & (EDGE_I420_LEFT_HAS_BOTTOM >> (f->cur.p.layout - 1));
1434
536k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
1435
1.60M
            for (int pl = 0; pl < 2; pl++) {
1436
2.20M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
1437
1.13M
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
1438
1.13M
                {
1439
1.13M
                    pixel *dst = ((pixel *) f->cur.data[1 + pl]) +
1440
1.13M
                                   4 * ((t->by >> ss_ver) * PXSTRIDE(stride) +
1441
1.13M
                                        ((t->bx + init_x) >> ss_hor));
1442
2.43M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
1443
1.30M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
1444
1.30M
                    {
1445
1.30M
                        if ((b->uv_mode == CFL_PRED && b->cfl_alpha[pl]) ||
1446
1.14M
                            b->pal_sz[1])
1447
166k
                        {
1448
166k
                            goto skip_uv_pred;
1449
166k
                        }
1450
1451
1.13M
                        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.13M
                        const enum EdgeFlags edge_flags =
1456
1.13M
                            (((y > (init_y >> ss_ver) || !uv_sb_has_tr) &&
1457
458k
                              (x + uv_t_dim->w >= sub_cw4)) ?
1458
812k
                                 0 : EDGE_I444_TOP_HAS_RIGHT) |
1459
1.13M
                            ((x > (init_x >> ss_hor) ||
1460
968k
                              (!uv_sb_has_bl && y + uv_t_dim->h >= sub_ch4)) ?
1461
694k
                                 0 : EDGE_I444_LEFT_HAS_BOTTOM);
1462
1.13M
                        const pixel *top_sb_edge = NULL;
1463
1.13M
                        if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1464
367k
                            top_sb_edge = f->ipred_edge[1 + pl];
1465
367k
                            const int sby = t->by >> f->sb_shift;
1466
367k
                            top_sb_edge += f->sb128w * 128 * (sby - 1);
1467
367k
                        }
1468
1.13M
                        const enum IntraPredMode uv_mode =
1469
1.13M
                             b->uv_mode == CFL_PRED ? DC_PRED : b->uv_mode;
1470
1.13M
                        const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1471
1.13M
                        const int xstart = ts->tiling.col_start >> ss_hor;
1472
1.13M
                        const int ystart = ts->tiling.row_start >> ss_ver;
1473
1.13M
                        const enum IntraPredMode m =
1474
1.13M
                            bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1475
1.13M
                                                              ypos, ypos > ystart,
1476
1.13M
                                                              ts->tiling.col_end >> ss_hor,
1477
1.13M
                                                              ts->tiling.row_end >> ss_ver,
1478
1.13M
                                                              edge_flags, dst, stride,
1479
1.13M
                                                              top_sb_edge, uv_mode,
1480
1.13M
                                                              &angle, uv_t_dim->w,
1481
1.13M
                                                              uv_t_dim->h,
1482
1.13M
                                                              f->seq_hdr->intra_edge_filter,
1483
1.13M
                                                              edge HIGHBD_CALL_SUFFIX);
1484
1.13M
                        angle |= intra_edge_filter_flag;
1485
1.13M
                        dsp->ipred.intra_pred[m](dst, stride, edge,
1486
1.13M
                                                 uv_t_dim->w * 4,
1487
1.13M
                                                 uv_t_dim->h * 4,
1488
1.13M
                                                 angle | sm_uv_fl,
1489
1.13M
                                                 (4 * f->bw + ss_hor -
1490
1.13M
                                                  4 * (t->bx & ~ss_hor)) >> ss_hor,
1491
1.13M
                                                 (4 * f->bh + ss_ver -
1492
1.13M
                                                  4 * (t->by & ~ss_ver)) >> ss_ver
1493
1.13M
                                                 HIGHBD_CALL_SUFFIX);
1494
1.13M
                        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.30M
                    skip_uv_pred: {}
1505
1.30M
                        if (!b->skip) {
1506
392k
                            enum TxfmType txtp;
1507
392k
                            int eob;
1508
392k
                            coef *cf;
1509
392k
                            if (t->frame_thread.pass) {
1510
392k
                                const int p = t->frame_thread.pass & 1;
1511
392k
                                const int cbi = *ts->frame_thread[p].cbi++;
1512
392k
                                cf = ts->frame_thread[p].cf;
1513
392k
                                ts->frame_thread[p].cf += uv_t_dim->w * uv_t_dim->h * 16;
1514
392k
                                eob  = cbi >> 5;
1515
392k
                                txtp = cbi & 0x1f;
1516
392k
                            } 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
392k
                            if (eob >= 0) {
1533
164k
                                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
164k
                                dsp->itx.itxfm_add[b->uvtx]
1537
164k
                                                  [txtp](dst, stride,
1538
164k
                                                         cf, eob HIGHBD_CALL_SUFFIX);
1539
164k
                                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
164k
                            }
1543
912k
                        } 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.30M
                        dst += uv_t_dim->w * 4;
1548
1.30M
                    }
1549
1.13M
                    t->bx -= x << ss_hor;
1550
1.13M
                }
1551
1.07M
                t->by -= y << ss_ver;
1552
1.07M
            }
1553
536k
        }
1554
779k
    }
1555
769k
}
dav1d_recon_b_intra_16bpc
Line
Count
Source
1179
682k
{
1180
682k
    Dav1dTileState *const ts = t->ts;
1181
682k
    const Dav1dFrameContext *const f = t->f;
1182
682k
    const Dav1dDSPContext *const dsp = f->dsp;
1183
682k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1184
682k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1185
682k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1186
682k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1187
682k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1188
682k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1189
682k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1190
682k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1191
682k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1192
605k
                           (bw4 > ss_hor || t->bx & 1) &&
1193
570k
                           (bh4 > ss_ver || t->by & 1);
1194
682k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->tx];
1195
682k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
1196
1197
    // coefficient coding
1198
682k
    pixel *const edge = bitfn(t->scratch.edge) + 128;
1199
682k
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
1200
1201
682k
    const int intra_edge_filter_flag = f->seq_hdr->intra_edge_filter << 10;
1202
1203
1.38M
    for (int init_y = 0; init_y < h4; init_y += 16) {
1204
699k
        const int sub_h4 = imin(h4, 16 + init_y);
1205
699k
        const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
1206
1.42M
        for (int init_x = 0; init_x < w4; init_x += 16) {
1207
725k
            if (b->pal_sz[0]) {
1208
7.27k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1209
7.27k
                             4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1210
7.27k
                const uint8_t *pal_idx;
1211
7.27k
                if (t->frame_thread.pass) {
1212
7.27k
                    const int p = t->frame_thread.pass & 1;
1213
7.27k
                    assert(ts->frame_thread[p].pal_idx);
1214
7.27k
                    pal_idx = ts->frame_thread[p].pal_idx;
1215
7.27k
                    ts->frame_thread[p].pal_idx += bw4 * bh4 * 8;
1216
7.27k
                } else {
1217
0
                    pal_idx = t->scratch.pal_idx_y;
1218
0
                }
1219
7.27k
                const pixel *const pal = t->frame_thread.pass ?
1220
7.27k
                    f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1221
7.27k
                                        ((t->bx >> 1) + (t->by & 1))][0] :
1222
7.27k
                    bytefn(t->scratch.pal)[0];
1223
7.27k
                f->dsp->ipred.pal_pred(dst, f->cur.stride[0], pal,
1224
7.27k
                                       pal_idx, bw4 * 4, bh4 * 4);
1225
7.27k
                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
7.27k
            }
1229
1230
725k
            const int intra_flags = (sm_flag(t->a, bx4) |
1231
725k
                                     sm_flag(&t->l, by4) |
1232
725k
                                     intra_edge_filter_flag);
1233
725k
            const int sb_has_tr = init_x + 16 < w4 ? 1 : init_y ? 0 :
1234
699k
                              intra_edge_flags & EDGE_I444_TOP_HAS_RIGHT;
1235
725k
            const int sb_has_bl = init_x ? 0 : init_y + 16 < h4 ? 1 :
1236
699k
                              intra_edge_flags & EDGE_I444_LEFT_HAS_BOTTOM;
1237
725k
            int y, x;
1238
725k
            const int sub_w4 = imin(w4, init_x + 16);
1239
1.58M
            for (y = init_y, t->by += init_y; y < sub_h4;
1240
857k
                 y += t_dim->h, t->by += t_dim->h)
1241
856k
            {
1242
856k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1243
856k
                               4 * (t->by * PXSTRIDE(f->cur.stride[0]) +
1244
856k
                                    t->bx + init_x);
1245
2.25M
                for (x = init_x, t->bx += init_x; x < sub_w4;
1246
1.39M
                     x += t_dim->w, t->bx += t_dim->w)
1247
1.39M
                {
1248
1.39M
                    if (b->pal_sz[0]) goto skip_y_pred;
1249
1250
1.38M
                    int angle = b->y_angle;
1251
1.38M
                    const enum EdgeFlags edge_flags =
1252
1.38M
                        (((y > init_y || !sb_has_tr) && (x + t_dim->w >= sub_w4)) ?
1253
1.00M
                             0 : EDGE_I444_TOP_HAS_RIGHT) |
1254
1.38M
                        ((x > init_x || (!sb_has_bl && y + t_dim->h >= sub_h4)) ?
1255
925k
                             0 : EDGE_I444_LEFT_HAS_BOTTOM);
1256
1.38M
                    const pixel *top_sb_edge = NULL;
1257
1.38M
                    if (!(t->by & (f->sb_step - 1))) {
1258
249k
                        top_sb_edge = f->ipred_edge[0];
1259
249k
                        const int sby = t->by >> f->sb_shift;
1260
249k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1261
249k
                    }
1262
1.38M
                    const enum IntraPredMode m =
1263
1.38M
                        bytefn(dav1d_prepare_intra_edges)(t->bx,
1264
1.38M
                                                          t->bx > ts->tiling.col_start,
1265
1.38M
                                                          t->by,
1266
1.38M
                                                          t->by > ts->tiling.row_start,
1267
1.38M
                                                          ts->tiling.col_end,
1268
1.38M
                                                          ts->tiling.row_end,
1269
1.38M
                                                          edge_flags, dst,
1270
1.38M
                                                          f->cur.stride[0], top_sb_edge,
1271
1.38M
                                                          b->y_mode, &angle,
1272
1.38M
                                                          t_dim->w, t_dim->h,
1273
1.38M
                                                          f->seq_hdr->intra_edge_filter,
1274
1.38M
                                                          edge HIGHBD_CALL_SUFFIX);
1275
1.38M
                    dsp->ipred.intra_pred[m](dst, f->cur.stride[0], edge,
1276
1.38M
                                             t_dim->w * 4, t_dim->h * 4,
1277
1.38M
                                             angle | intra_flags,
1278
1.38M
                                             4 * f->bw - 4 * t->bx,
1279
1.38M
                                             4 * f->bh - 4 * t->by
1280
1.38M
                                             HIGHBD_CALL_SUFFIX);
1281
1282
1.38M
                    if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1283
0
                        hex_dump(edge - t_dim->h * 4, t_dim->h * 4,
1284
0
                                 t_dim->h * 4, 2, "l");
1285
0
                        hex_dump(edge, 0, 1, 1, "tl");
1286
0
                        hex_dump(edge + 1, t_dim->w * 4,
1287
0
                                 t_dim->w * 4, 2, "t");
1288
0
                        hex_dump(dst, f->cur.stride[0],
1289
0
                                 t_dim->w * 4, t_dim->h * 4, "y-intra-pred");
1290
0
                    }
1291
1292
1.39M
                skip_y_pred: {}
1293
1.39M
                    if (!b->skip) {
1294
416k
                        coef *cf;
1295
416k
                        int eob;
1296
416k
                        enum TxfmType txtp;
1297
416k
                        if (t->frame_thread.pass) {
1298
416k
                            const int p = t->frame_thread.pass & 1;
1299
416k
                            const int cbi = *ts->frame_thread[p].cbi++;
1300
416k
                            cf = ts->frame_thread[p].cf;
1301
416k
                            ts->frame_thread[p].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
1302
416k
                            eob  = cbi >> 5;
1303
416k
                            txtp = cbi & 0x1f;
1304
416k
                        } 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
416k
                        if (eob >= 0) {
1317
285k
                            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
285k
                            dsp->itx.itxfm_add[b->tx]
1321
285k
                                              [txtp](dst,
1322
285k
                                                     f->cur.stride[0],
1323
285k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1324
285k
                            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
285k
                        }
1328
979k
                    } else if (!t->frame_thread.pass) {
1329
0
                        dav1d_memset_pow2[t_dim->lw](&t->a->lcoef[bx4 + x], 0x40);
1330
0
                        dav1d_memset_pow2[t_dim->lh](&t->l.lcoef[by4 + y], 0x40);
1331
0
                    }
1332
1.39M
                    dst += 4 * t_dim->w;
1333
1.39M
                }
1334
857k
                t->bx -= x;
1335
857k
            }
1336
726k
            t->by -= y;
1337
1338
726k
            if (!has_chroma) continue;
1339
1340
567k
            const ptrdiff_t stride = f->cur.stride[1];
1341
1342
567k
            if (b->uv_mode == CFL_PRED) {
1343
105k
                assert(!init_x && !init_y);
1344
1345
105k
                int16_t *const ac = t->scratch.ac;
1346
105k
                pixel *y_src = ((pixel *) f->cur.data[0]) + 4 * (t->bx & ~ss_hor) +
1347
105k
                                 4 * (t->by & ~ss_ver) * PXSTRIDE(f->cur.stride[0]);
1348
105k
                const ptrdiff_t uv_off = 4 * ((t->bx >> ss_hor) +
1349
105k
                                              (t->by >> ss_ver) * PXSTRIDE(stride));
1350
105k
                pixel *const uv_dst[2] = { ((pixel *) f->cur.data[1]) + uv_off,
1351
105k
                                           ((pixel *) f->cur.data[2]) + uv_off };
1352
1353
105k
                const int furthest_r =
1354
105k
                    ((cw4 << ss_hor) + t_dim->w - 1) & ~(t_dim->w - 1);
1355
105k
                const int furthest_b =
1356
105k
                    ((ch4 << ss_ver) + t_dim->h - 1) & ~(t_dim->h - 1);
1357
105k
                dsp->ipred.cfl_ac[f->cur.p.layout - 1](ac, y_src, f->cur.stride[0],
1358
105k
                                                         cbw4 - (furthest_r >> ss_hor),
1359
105k
                                                         cbh4 - (furthest_b >> ss_ver),
1360
105k
                                                         cbw4 * 4, cbh4 * 4);
1361
316k
                for (int pl = 0; pl < 2; pl++) {
1362
210k
                    if (!b->cfl_alpha[pl]) continue;
1363
167k
                    int angle = 0;
1364
167k
                    const pixel *top_sb_edge = NULL;
1365
167k
                    if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1366
40.5k
                        top_sb_edge = f->ipred_edge[pl + 1];
1367
40.5k
                        const int sby = t->by >> f->sb_shift;
1368
40.5k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1369
40.5k
                    }
1370
167k
                    const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1371
167k
                    const int xstart = ts->tiling.col_start >> ss_hor;
1372
167k
                    const int ystart = ts->tiling.row_start >> ss_ver;
1373
167k
                    const enum IntraPredMode m =
1374
167k
                        bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1375
167k
                                                          ypos, ypos > ystart,
1376
167k
                                                          ts->tiling.col_end >> ss_hor,
1377
167k
                                                          ts->tiling.row_end >> ss_ver,
1378
167k
                                                          0, uv_dst[pl], stride,
1379
167k
                                                          top_sb_edge, DC_PRED, &angle,
1380
167k
                                                          uv_t_dim->w, uv_t_dim->h, 0,
1381
167k
                                                          edge HIGHBD_CALL_SUFFIX);
1382
167k
                    dsp->ipred.cfl_pred[m](uv_dst[pl], stride, edge,
1383
167k
                                           uv_t_dim->w * 4,
1384
167k
                                           uv_t_dim->h * 4,
1385
167k
                                           ac, b->cfl_alpha[pl]
1386
167k
                                           HIGHBD_CALL_SUFFIX);
1387
167k
                }
1388
105k
                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1389
0
                    ac_dump(ac, 4*cbw4, 4*cbh4, "ac");
1390
0
                    hex_dump(uv_dst[0], stride, cbw4 * 4, cbh4 * 4, "u-cfl-pred");
1391
0
                    hex_dump(uv_dst[1], stride, cbw4 * 4, cbh4 * 4, "v-cfl-pred");
1392
0
                }
1393
461k
            } else if (b->pal_sz[1]) {
1394
2.04k
                const ptrdiff_t uv_dstoff = 4 * ((t->bx >> ss_hor) +
1395
2.04k
                                              (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1396
2.04k
                const pixel (*pal)[8];
1397
2.04k
                const uint8_t *pal_idx;
1398
2.04k
                if (t->frame_thread.pass) {
1399
2.04k
                    const int p = t->frame_thread.pass & 1;
1400
2.04k
                    assert(ts->frame_thread[p].pal_idx);
1401
2.04k
                    pal = f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1402
2.04k
                                              ((t->bx >> 1) + (t->by & 1))];
1403
2.04k
                    pal_idx = ts->frame_thread[p].pal_idx;
1404
2.04k
                    ts->frame_thread[p].pal_idx += cbw4 * cbh4 * 8;
1405
2.04k
                } else {
1406
0
                    pal = bytefn(t->scratch.pal);
1407
0
                    pal_idx = t->scratch.pal_idx_uv;
1408
0
                }
1409
1410
2.04k
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[1]) + uv_dstoff,
1411
2.04k
                                       f->cur.stride[1], pal[1],
1412
2.04k
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1413
2.04k
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[2]) + uv_dstoff,
1414
2.04k
                                       f->cur.stride[1], pal[2],
1415
2.04k
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1416
2.04k
                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
2.04k
            }
1425
1426
567k
            const int sm_uv_fl = sm_uv_flag(t->a, cbx4) |
1427
567k
                                 sm_uv_flag(&t->l, cby4);
1428
567k
            const int uv_sb_has_tr =
1429
567k
                ((init_x + 16) >> ss_hor) < cw4 ? 1 : init_y ? 0 :
1430
543k
                intra_edge_flags & (EDGE_I420_TOP_HAS_RIGHT >> (f->cur.p.layout - 1));
1431
567k
            const int uv_sb_has_bl =
1432
567k
                init_x ? 0 : ((init_y + 16) >> ss_ver) < ch4 ? 1 :
1433
543k
                intra_edge_flags & (EDGE_I420_LEFT_HAS_BOTTOM >> (f->cur.p.layout - 1));
1434
567k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
1435
1.70M
            for (int pl = 0; pl < 2; pl++) {
1436
2.35M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
1437
1.21M
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
1438
1.21M
                {
1439
1.21M
                    pixel *dst = ((pixel *) f->cur.data[1 + pl]) +
1440
1.21M
                                   4 * ((t->by >> ss_ver) * PXSTRIDE(stride) +
1441
1.21M
                                        ((t->bx + init_x) >> ss_hor));
1442
2.65M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
1443
1.43M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
1444
1.43M
                    {
1445
1.43M
                        if ((b->uv_mode == CFL_PRED && b->cfl_alpha[pl]) ||
1446
1.26M
                            b->pal_sz[1])
1447
171k
                        {
1448
171k
                            goto skip_uv_pred;
1449
171k
                        }
1450
1451
1.25M
                        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.25M
                        const enum EdgeFlags edge_flags =
1456
1.25M
                            (((y > (init_y >> ss_ver) || !uv_sb_has_tr) &&
1457
560k
                              (x + uv_t_dim->w >= sub_cw4)) ?
1458
860k
                                 0 : EDGE_I444_TOP_HAS_RIGHT) |
1459
1.25M
                            ((x > (init_x >> ss_hor) ||
1460
1.04M
                              (!uv_sb_has_bl && y + uv_t_dim->h >= sub_ch4)) ?
1461
747k
                                 0 : EDGE_I444_LEFT_HAS_BOTTOM);
1462
1.25M
                        const pixel *top_sb_edge = NULL;
1463
1.25M
                        if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1464
332k
                            top_sb_edge = f->ipred_edge[1 + pl];
1465
332k
                            const int sby = t->by >> f->sb_shift;
1466
332k
                            top_sb_edge += f->sb128w * 128 * (sby - 1);
1467
332k
                        }
1468
1.25M
                        const enum IntraPredMode uv_mode =
1469
1.25M
                             b->uv_mode == CFL_PRED ? DC_PRED : b->uv_mode;
1470
1.25M
                        const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1471
1.25M
                        const int xstart = ts->tiling.col_start >> ss_hor;
1472
1.25M
                        const int ystart = ts->tiling.row_start >> ss_ver;
1473
1.25M
                        const enum IntraPredMode m =
1474
1.25M
                            bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1475
1.25M
                                                              ypos, ypos > ystart,
1476
1.25M
                                                              ts->tiling.col_end >> ss_hor,
1477
1.25M
                                                              ts->tiling.row_end >> ss_ver,
1478
1.25M
                                                              edge_flags, dst, stride,
1479
1.25M
                                                              top_sb_edge, uv_mode,
1480
1.25M
                                                              &angle, uv_t_dim->w,
1481
1.25M
                                                              uv_t_dim->h,
1482
1.25M
                                                              f->seq_hdr->intra_edge_filter,
1483
1.25M
                                                              edge HIGHBD_CALL_SUFFIX);
1484
1.25M
                        angle |= intra_edge_filter_flag;
1485
1.25M
                        dsp->ipred.intra_pred[m](dst, stride, edge,
1486
1.25M
                                                 uv_t_dim->w * 4,
1487
1.25M
                                                 uv_t_dim->h * 4,
1488
1.25M
                                                 angle | sm_uv_fl,
1489
1.25M
                                                 (4 * f->bw + ss_hor -
1490
1.25M
                                                  4 * (t->bx & ~ss_hor)) >> ss_hor,
1491
1.25M
                                                 (4 * f->bh + ss_ver -
1492
1.25M
                                                  4 * (t->by & ~ss_ver)) >> ss_ver
1493
1.25M
                                                 HIGHBD_CALL_SUFFIX);
1494
1.25M
                        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.43M
                    skip_uv_pred: {}
1505
1.43M
                        if (!b->skip) {
1506
496k
                            enum TxfmType txtp;
1507
496k
                            int eob;
1508
496k
                            coef *cf;
1509
496k
                            if (t->frame_thread.pass) {
1510
496k
                                const int p = t->frame_thread.pass & 1;
1511
496k
                                const int cbi = *ts->frame_thread[p].cbi++;
1512
496k
                                cf = ts->frame_thread[p].cf;
1513
496k
                                ts->frame_thread[p].cf += uv_t_dim->w * uv_t_dim->h * 16;
1514
496k
                                eob  = cbi >> 5;
1515
496k
                                txtp = cbi & 0x1f;
1516
496k
                            } 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
496k
                            if (eob >= 0) {
1533
138k
                                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
138k
                                dsp->itx.itxfm_add[b->uvtx]
1537
138k
                                                  [txtp](dst, stride,
1538
138k
                                                         cf, eob HIGHBD_CALL_SUFFIX);
1539
138k
                                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
138k
                            }
1543
935k
                        } 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.43M
                        dst += uv_t_dim->w * 4;
1548
1.43M
                    }
1549
1.21M
                    t->bx -= x << ss_hor;
1550
1.21M
                }
1551
1.13M
                t->by -= y << ss_ver;
1552
1.13M
            }
1553
567k
        }
1554
699k
    }
1555
682k
}
1556
1557
int bytefn(dav1d_recon_b_inter)(Dav1dTaskContext *const t, const enum BlockSize bs,
1558
                                const Av1Block *const b)
1559
358k
{
1560
358k
    Dav1dTileState *const ts = t->ts;
1561
358k
    const Dav1dFrameContext *const f = t->f;
1562
358k
    const Dav1dDSPContext *const dsp = f->dsp;
1563
358k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1564
358k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1565
358k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1566
358k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1567
358k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1568
358k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1569
358k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1570
358k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1571
309k
                           (bw4 > ss_hor || t->bx & 1) &&
1572
293k
                           (bh4 > ss_ver || t->by & 1);
1573
358k
    const int chr_layout_idx = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I400 ? 0 :
1574
358k
                               DAV1D_PIXEL_LAYOUT_I444 - f->cur.p.layout;
1575
358k
    int res;
1576
1577
    // prediction
1578
358k
    const int cbh4 = (bh4 + ss_ver) >> ss_ver, cbw4 = (bw4 + ss_hor) >> ss_hor;
1579
358k
    pixel *dst = ((pixel *) f->cur.data[0]) +
1580
358k
        4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1581
358k
    const ptrdiff_t uvdstoff =
1582
358k
        4 * ((t->bx >> ss_hor) + (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1583
358k
    if (IS_KEY_OR_INTRA(f->frame_hdr)) {
1584
        // intrabc
1585
64.6k
        assert(!f->frame_hdr->super_res.enabled);
1586
64.6k
        res = mc(t, dst, NULL, f->cur.stride[0], bw4, bh4, t->bx, t->by, 0,
1587
64.6k
                 b->mv[0], &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1588
64.6k
        if (res) return res;
1589
101k
        if (has_chroma) for (int pl = 1; pl < 3; pl++) {
1590
67.4k
            res = mc(t, ((pixel *)f->cur.data[pl]) + uvdstoff, NULL, f->cur.stride[1],
1591
67.4k
                     bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1592
67.4k
                     t->bx & ~ss_hor, t->by & ~ss_ver, pl, b->mv[0],
1593
67.4k
                     &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1594
67.4k
            if (res) return res;
1595
67.4k
        }
1596
293k
    } else if (b->comp_type == COMP_INTER_NONE) {
1597
223k
        const Dav1dThreadPicture *const refp = &f->refp[b->ref[0]];
1598
223k
        const enum Filter2d filter_2d = b->filter2d;
1599
1600
223k
        if (imin(bw4, bh4) > 1 &&
1601
121k
            ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1602
119k
             (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1603
4.91k
        {
1604
4.91k
            res = warp_affine(t, dst, NULL, f->cur.stride[0], b_dim, 0, refp,
1605
4.91k
                              b->motion_mode == MM_WARP ? &t->warpmv :
1606
4.91k
                                  &f->frame_hdr->gmv[b->ref[0]]);
1607
4.91k
            if (res) return res;
1608
218k
        } else {
1609
218k
            res = mc(t, dst, NULL, f->cur.stride[0],
1610
218k
                     bw4, bh4, t->bx, t->by, 0, b->mv[0], refp, b->ref[0], filter_2d);
1611
218k
            if (res) return res;
1612
218k
            if (b->motion_mode == MM_OBMC) {
1613
32.1k
                res = obmc(t, dst, f->cur.stride[0], b_dim, 0, bx4, by4, w4, h4);
1614
32.1k
                if (res) return res;
1615
32.1k
            }
1616
218k
        }
1617
223k
        if (b->interintra_type) {
1618
7.42k
            pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1619
7.42k
            enum IntraPredMode m = b->interintra_mode == II_SMOOTH_PRED ?
1620
6.14k
                                   SMOOTH_PRED : b->interintra_mode;
1621
7.42k
            pixel *const tmp = bitfn(t->scratch.interintra);
1622
7.42k
            int angle = 0;
1623
7.42k
            const pixel *top_sb_edge = NULL;
1624
7.42k
            if (!(t->by & (f->sb_step - 1))) {
1625
2.35k
                top_sb_edge = f->ipred_edge[0];
1626
2.35k
                const int sby = t->by >> f->sb_shift;
1627
2.35k
                top_sb_edge += f->sb128w * 128 * (sby - 1);
1628
2.35k
            }
1629
7.42k
            m = bytefn(dav1d_prepare_intra_edges)(t->bx, t->bx > ts->tiling.col_start,
1630
7.42k
                                                  t->by, t->by > ts->tiling.row_start,
1631
7.42k
                                                  ts->tiling.col_end, ts->tiling.row_end,
1632
7.42k
                                                  0, dst, f->cur.stride[0], top_sb_edge,
1633
7.42k
                                                  m, &angle, bw4, bh4, 0, tl_edge
1634
7.42k
                                                  HIGHBD_CALL_SUFFIX);
1635
7.42k
            dsp->ipred.intra_pred[m](tmp, 4 * bw4 * sizeof(pixel),
1636
7.42k
                                     tl_edge, bw4 * 4, bh4 * 4, 0, 0, 0
1637
7.42k
                                     HIGHBD_CALL_SUFFIX);
1638
7.42k
            dsp->mc.blend(dst, f->cur.stride[0], tmp,
1639
7.42k
                          bw4 * 4, bh4 * 4, II_MASK(0, bs, b));
1640
7.42k
        }
1641
1642
223k
        if (!has_chroma) goto skip_inter_chroma_pred;
1643
1644
        // sub8x8 derivation
1645
183k
        int is_sub8x8 = bw4 == ss_hor || bh4 == ss_ver;
1646
183k
        refmvs_block *const *r;
1647
183k
        if (is_sub8x8) {
1648
14.2k
            assert(ss_hor == 1);
1649
14.2k
            r = &t->rt.r[(t->by & 31) + 5];
1650
14.2k
            if (bw4 == 1) is_sub8x8 &= r[0][t->bx - 1].ref.ref[0] > 0;
1651
14.2k
            if (bh4 == ss_ver) is_sub8x8 &= r[-1][t->bx].ref.ref[0] > 0;
1652
14.2k
            if (bw4 == 1 && bh4 == ss_ver)
1653
4.39k
                is_sub8x8 &= r[-1][t->bx - 1].ref.ref[0] > 0;
1654
14.2k
        }
1655
1656
        // chroma prediction
1657
183k
        if (is_sub8x8) {
1658
12.9k
            assert(ss_hor == 1);
1659
12.9k
            ptrdiff_t h_off = 0, v_off = 0;
1660
12.9k
            if (bw4 == 1 && bh4 == ss_ver) {
1661
10.4k
                for (int pl = 0; pl < 2; pl++) {
1662
6.93k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1663
6.93k
                             NULL, f->cur.stride[1],
1664
6.93k
                             bw4, bh4, t->bx - 1, t->by - 1, 1 + pl,
1665
6.93k
                             r[-1][t->bx - 1].mv.mv[0],
1666
6.93k
                             &f->refp[r[-1][t->bx - 1].ref.ref[0] - 1],
1667
6.93k
                             r[-1][t->bx - 1].ref.ref[0] - 1,
1668
6.93k
                             t->frame_thread.pass != 2 ? t->tl_4x4_filter :
1669
6.93k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx - 1].filter2d);
1670
6.93k
                    if (res) return res;
1671
6.93k
                }
1672
3.46k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1673
3.46k
                h_off = 2;
1674
3.46k
            }
1675
12.9k
            if (bw4 == 1) {
1676
8.92k
                const enum Filter2d left_filter_2d =
1677
8.92k
                    dav1d_filter_2d[t->l.filter[1][by4]][t->l.filter[0][by4]];
1678
26.7k
                for (int pl = 0; pl < 2; pl++) {
1679
17.8k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + v_off, NULL,
1680
17.8k
                             f->cur.stride[1], bw4, bh4, t->bx - 1,
1681
17.8k
                             t->by, 1 + pl, r[0][t->bx - 1].mv.mv[0],
1682
17.8k
                             &f->refp[r[0][t->bx - 1].ref.ref[0] - 1],
1683
17.8k
                             r[0][t->bx - 1].ref.ref[0] - 1,
1684
17.8k
                             t->frame_thread.pass != 2 ? left_filter_2d :
1685
17.8k
                                 f->frame_thread.b[(t->by * f->b4_stride) + t->bx - 1].filter2d);
1686
17.8k
                    if (res) return res;
1687
17.8k
                }
1688
8.92k
                h_off = 2;
1689
8.92k
            }
1690
12.9k
            if (bh4 == ss_ver) {
1691
7.51k
                const enum Filter2d top_filter_2d =
1692
7.51k
                    dav1d_filter_2d[t->a->filter[1][bx4]][t->a->filter[0][bx4]];
1693
22.5k
                for (int pl = 0; pl < 2; pl++) {
1694
15.0k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off, NULL,
1695
15.0k
                             f->cur.stride[1], bw4, bh4, t->bx, t->by - 1,
1696
15.0k
                             1 + pl, r[-1][t->bx].mv.mv[0],
1697
15.0k
                             &f->refp[r[-1][t->bx].ref.ref[0] - 1],
1698
15.0k
                             r[-1][t->bx].ref.ref[0] - 1,
1699
15.0k
                             t->frame_thread.pass != 2 ? top_filter_2d :
1700
15.0k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx].filter2d);
1701
15.0k
                    if (res) return res;
1702
15.0k
                }
1703
7.51k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1704
7.51k
            }
1705
38.9k
            for (int pl = 0; pl < 2; pl++) {
1706
25.9k
                res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off + v_off, NULL, f->cur.stride[1],
1707
25.9k
                         bw4, bh4, t->bx, t->by, 1 + pl, b->mv[0],
1708
25.9k
                         refp, b->ref[0], filter_2d);
1709
25.9k
                if (res) return res;
1710
25.9k
            }
1711
170k
        } else {
1712
170k
            if (imin(cbw4, cbh4) > 1 &&
1713
90.3k
                ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1714
88.7k
                 (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1715
4.60k
            {
1716
13.8k
                for (int pl = 0; pl < 2; pl++) {
1717
9.20k
                    res = warp_affine(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff, NULL,
1718
9.20k
                                      f->cur.stride[1], b_dim, 1 + pl, refp,
1719
9.20k
                                      b->motion_mode == MM_WARP ? &t->warpmv :
1720
9.20k
                                          &f->frame_hdr->gmv[b->ref[0]]);
1721
9.20k
                    if (res) return res;
1722
9.20k
                }
1723
166k
            } else {
1724
498k
                for (int pl = 0; pl < 2; pl++) {
1725
332k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1726
332k
                             NULL, f->cur.stride[1],
1727
332k
                             bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1728
332k
                             t->bx & ~ss_hor, t->by & ~ss_ver,
1729
332k
                             1 + pl, b->mv[0], refp, b->ref[0], filter_2d);
1730
332k
                    if (res) return res;
1731
332k
                    if (b->motion_mode == MM_OBMC) {
1732
62.4k
                        res = obmc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1733
62.4k
                                   f->cur.stride[1], b_dim, 1 + pl, bx4, by4, w4, h4);
1734
62.4k
                        if (res) return res;
1735
62.4k
                    }
1736
332k
                }
1737
166k
            }
1738
170k
            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
6.56k
                const uint8_t *const ii_mask = II_MASK(chr_layout_idx, bs, b);
1743
1744
19.6k
                for (int pl = 0; pl < 2; pl++) {
1745
13.1k
                    pixel *const tmp = bitfn(t->scratch.interintra);
1746
13.1k
                    pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1747
13.1k
                    enum IntraPredMode m =
1748
13.1k
                        b->interintra_mode == II_SMOOTH_PRED ?
1749
10.9k
                        SMOOTH_PRED : b->interintra_mode;
1750
13.1k
                    int angle = 0;
1751
13.1k
                    pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1752
13.1k
                    const pixel *top_sb_edge = NULL;
1753
13.1k
                    if (!(t->by & (f->sb_step - 1))) {
1754
3.18k
                        top_sb_edge = f->ipred_edge[pl + 1];
1755
3.18k
                        const int sby = t->by >> f->sb_shift;
1756
3.18k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1757
3.18k
                    }
1758
13.1k
                    m = bytefn(dav1d_prepare_intra_edges)(t->bx >> ss_hor,
1759
13.1k
                                                          (t->bx >> ss_hor) >
1760
13.1k
                                                              (ts->tiling.col_start >> ss_hor),
1761
13.1k
                                                          t->by >> ss_ver,
1762
13.1k
                                                          (t->by >> ss_ver) >
1763
13.1k
                                                              (ts->tiling.row_start >> ss_ver),
1764
13.1k
                                                          ts->tiling.col_end >> ss_hor,
1765
13.1k
                                                          ts->tiling.row_end >> ss_ver,
1766
13.1k
                                                          0, uvdst, f->cur.stride[1],
1767
13.1k
                                                          top_sb_edge, m,
1768
13.1k
                                                          &angle, cbw4, cbh4, 0, tl_edge
1769
13.1k
                                                          HIGHBD_CALL_SUFFIX);
1770
13.1k
                    dsp->ipred.intra_pred[m](tmp, cbw4 * 4 * sizeof(pixel),
1771
13.1k
                                             tl_edge, cbw4 * 4, cbh4 * 4, 0, 0, 0
1772
13.1k
                                             HIGHBD_CALL_SUFFIX);
1773
13.1k
                    dsp->mc.blend(uvdst, f->cur.stride[1], tmp,
1774
13.1k
                                  cbw4 * 4, cbh4 * 4, ii_mask);
1775
13.1k
                }
1776
6.56k
            }
1777
170k
        }
1778
1779
223k
    skip_inter_chroma_pred: {}
1780
223k
        t->tl_4x4_filter = filter_2d;
1781
223k
    } else {
1782
70.1k
        const enum Filter2d filter_2d = b->filter2d;
1783
        // Maximum super block size is 128x128
1784
70.1k
        int16_t (*tmp)[128 * 128] = t->scratch.compinter;
1785
70.1k
        int jnt_weight;
1786
70.1k
        uint8_t *const seg_mask = t->scratch.seg_mask;
1787
70.1k
        const uint8_t *mask;
1788
1789
210k
        for (int i = 0; i < 2; i++) {
1790
140k
            const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1791
1792
140k
            if (b->inter_mode == GLOBALMV_GLOBALMV && f->gmv_warp_allowed[b->ref[i]]) {
1793
4.90k
                res = warp_affine(t, NULL, tmp[i], bw4 * 4, b_dim, 0, refp,
1794
4.90k
                                  &f->frame_hdr->gmv[b->ref[i]]);
1795
4.90k
                if (res) return res;
1796
135k
            } else {
1797
135k
                res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by, 0,
1798
135k
                         b->mv[i], refp, b->ref[i], filter_2d);
1799
135k
                if (res) return res;
1800
135k
            }
1801
140k
        }
1802
70.1k
        switch (b->comp_type) {
1803
46.7k
        case COMP_INTER_AVG:
1804
46.7k
            dsp->mc.avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1805
46.7k
                        bw4 * 4, bh4 * 4 HIGHBD_CALL_SUFFIX);
1806
46.7k
            break;
1807
8.64k
        case COMP_INTER_WEIGHTED_AVG:
1808
8.64k
            jnt_weight = f->jnt_weights[b->ref[0]][b->ref[1]];
1809
8.64k
            dsp->mc.w_avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1810
8.64k
                          bw4 * 4, bh4 * 4, jnt_weight HIGHBD_CALL_SUFFIX);
1811
8.64k
            break;
1812
8.71k
        case COMP_INTER_SEG:
1813
8.71k
            dsp->mc.w_mask[chr_layout_idx](dst, f->cur.stride[0],
1814
8.71k
                                           tmp[b->mask_sign], tmp[!b->mask_sign],
1815
8.71k
                                           bw4 * 4, bh4 * 4, seg_mask,
1816
8.71k
                                           b->mask_sign HIGHBD_CALL_SUFFIX);
1817
8.71k
            mask = seg_mask;
1818
8.71k
            break;
1819
5.99k
        case COMP_INTER_WEDGE:
1820
5.99k
            mask = WEDGE_MASK(0, bs, 0, b->wedge_idx);
1821
5.99k
            dsp->mc.mask(dst, f->cur.stride[0],
1822
5.99k
                         tmp[b->mask_sign], tmp[!b->mask_sign],
1823
5.99k
                         bw4 * 4, bh4 * 4, mask HIGHBD_CALL_SUFFIX);
1824
5.99k
            if (has_chroma)
1825
5.03k
                mask = WEDGE_MASK(chr_layout_idx, bs, b->mask_sign, b->wedge_idx);
1826
5.99k
            break;
1827
70.1k
        }
1828
1829
        // chroma
1830
196k
        if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1831
393k
            for (int i = 0; i < 2; i++) {
1832
262k
                const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1833
262k
                if (b->inter_mode == GLOBALMV_GLOBALMV &&
1834
38.7k
                    imin(cbw4, cbh4) > 1 && f->gmv_warp_allowed[b->ref[i]])
1835
4.14k
                {
1836
4.14k
                    res = warp_affine(t, NULL, tmp[i], bw4 * 4 >> ss_hor,
1837
4.14k
                                      b_dim, 1 + pl,
1838
4.14k
                                      refp, &f->frame_hdr->gmv[b->ref[i]]);
1839
4.14k
                    if (res) return res;
1840
258k
                } else {
1841
258k
                    res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by,
1842
258k
                             1 + pl, b->mv[i], refp, b->ref[i], filter_2d);
1843
258k
                    if (res) return res;
1844
258k
                }
1845
262k
            }
1846
131k
            pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1847
131k
            switch (b->comp_type) {
1848
89.0k
            case COMP_INTER_AVG:
1849
89.0k
                dsp->mc.avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1850
89.0k
                            bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver
1851
89.0k
                            HIGHBD_CALL_SUFFIX);
1852
89.0k
                break;
1853
15.1k
            case COMP_INTER_WEIGHTED_AVG:
1854
15.1k
                dsp->mc.w_avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1855
15.1k
                              bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, jnt_weight
1856
15.1k
                              HIGHBD_CALL_SUFFIX);
1857
15.1k
                break;
1858
10.0k
            case COMP_INTER_WEDGE:
1859
26.9k
            case COMP_INTER_SEG:
1860
26.9k
                dsp->mc.mask(uvdst, f->cur.stride[1],
1861
26.9k
                             tmp[b->mask_sign], tmp[!b->mask_sign],
1862
26.9k
                             bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, mask
1863
26.9k
                             HIGHBD_CALL_SUFFIX);
1864
26.9k
                break;
1865
131k
            }
1866
131k
        }
1867
70.1k
    }
1868
1869
358k
    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
358k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1880
1881
358k
    if (b->skip) {
1882
        // reset coef contexts
1883
103k
        BlockContext *const a = t->a;
1884
103k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
1885
103k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
1886
103k
        if (has_chroma) {
1887
69.2k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
1888
69.2k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
1889
69.2k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
1890
69.2k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
1891
69.2k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
1892
69.2k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
1893
69.2k
        }
1894
103k
        return 0;
1895
103k
    }
1896
1897
254k
    const TxfmInfo *const uvtx = &dav1d_txfm_dimensions[b->uvtx];
1898
254k
    const TxfmInfo *const ytx = &dav1d_txfm_dimensions[b->max_ytx];
1899
254k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
1900
1901
524k
    for (int init_y = 0; init_y < bh4; init_y += 16) {
1902
544k
        for (int init_x = 0; init_x < bw4; init_x += 16) {
1903
            // coefficient coding & inverse transforms
1904
274k
            int y_off = !!init_y, y;
1905
274k
            dst += PXSTRIDE(f->cur.stride[0]) * 4 * init_y;
1906
582k
            for (y = init_y, t->by += init_y; y < imin(h4, init_y + 16);
1907
307k
                 y += ytx->h, y_off++)
1908
307k
            {
1909
307k
                int x, x_off = !!init_x;
1910
755k
                for (x = init_x, t->bx += init_x; x < imin(w4, init_x + 16);
1911
447k
                     x += ytx->w, x_off++)
1912
447k
                {
1913
447k
                    read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
1914
447k
                                   x_off, y_off, &dst[x * 4]);
1915
447k
                    t->bx += ytx->w;
1916
447k
                }
1917
307k
                dst += PXSTRIDE(f->cur.stride[0]) * 4 * ytx->h;
1918
307k
                t->bx -= x;
1919
307k
                t->by += ytx->h;
1920
307k
            }
1921
274k
            dst -= PXSTRIDE(f->cur.stride[0]) * 4 * y;
1922
274k
            t->by -= y;
1923
1924
            // chroma coefs and inverse transform
1925
694k
            if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1926
462k
                pixel *uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff +
1927
462k
                    (PXSTRIDE(f->cur.stride[1]) * init_y * 4 >> ss_ver);
1928
462k
                for (y = init_y >> ss_ver, t->by += init_y;
1929
1.01M
                     y < imin(ch4, (init_y + 16) >> ss_ver); y += uvtx->h)
1930
548k
                {
1931
548k
                    int x;
1932
548k
                    for (x = init_x >> ss_hor, t->bx += init_x;
1933
1.39M
                         x < imin(cw4, (init_x + 16) >> ss_hor); x += uvtx->w)
1934
851k
                    {
1935
851k
                        coef *cf;
1936
851k
                        int eob;
1937
851k
                        enum TxfmType txtp;
1938
851k
                        if (t->frame_thread.pass) {
1939
851k
                            const int p = t->frame_thread.pass & 1;
1940
851k
                            const int cbi = *ts->frame_thread[p].cbi++;
1941
851k
                            cf = ts->frame_thread[p].cf;
1942
851k
                            ts->frame_thread[p].cf += uvtx->w * uvtx->h * 16;
1943
851k
                            eob  = cbi >> 5;
1944
851k
                            txtp = cbi & 0x1f;
1945
851k
                        } 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
851k
                        if (eob >= 0) {
1964
293k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1965
0
                                coef_dump(cf, uvtx->h * 4, uvtx->w * 4, 3, "dq");
1966
293k
                            dsp->itx.itxfm_add[b->uvtx]
1967
293k
                                              [txtp](&uvdst[4 * x],
1968
293k
                                                     f->cur.stride[1],
1969
293k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1970
293k
                            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
293k
                        }
1974
851k
                        t->bx += uvtx->w << ss_hor;
1975
851k
                    }
1976
548k
                    uvdst += PXSTRIDE(f->cur.stride[1]) * 4 * uvtx->h;
1977
548k
                    t->bx -= x << ss_hor;
1978
548k
                    t->by += uvtx->h << ss_ver;
1979
548k
                }
1980
462k
                t->by -= y << ss_ver;
1981
462k
            }
1982
274k
        }
1983
269k
    }
1984
254k
    return 0;
1985
358k
}
dav1d_recon_b_inter_8bpc
Line
Count
Source
1559
191k
{
1560
191k
    Dav1dTileState *const ts = t->ts;
1561
191k
    const Dav1dFrameContext *const f = t->f;
1562
191k
    const Dav1dDSPContext *const dsp = f->dsp;
1563
191k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1564
191k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1565
191k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1566
191k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1567
191k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1568
191k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1569
191k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1570
191k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1571
161k
                           (bw4 > ss_hor || t->bx & 1) &&
1572
152k
                           (bh4 > ss_ver || t->by & 1);
1573
191k
    const int chr_layout_idx = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I400 ? 0 :
1574
191k
                               DAV1D_PIXEL_LAYOUT_I444 - f->cur.p.layout;
1575
191k
    int res;
1576
1577
    // prediction
1578
191k
    const int cbh4 = (bh4 + ss_ver) >> ss_ver, cbw4 = (bw4 + ss_hor) >> ss_hor;
1579
191k
    pixel *dst = ((pixel *) f->cur.data[0]) +
1580
191k
        4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1581
191k
    const ptrdiff_t uvdstoff =
1582
191k
        4 * ((t->bx >> ss_hor) + (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1583
191k
    if (IS_KEY_OR_INTRA(f->frame_hdr)) {
1584
        // intrabc
1585
42.3k
        assert(!f->frame_hdr->super_res.enabled);
1586
42.3k
        res = mc(t, dst, NULL, f->cur.stride[0], bw4, bh4, t->bx, t->by, 0,
1587
42.3k
                 b->mv[0], &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1588
42.3k
        if (res) return res;
1589
57.1k
        if (has_chroma) for (int pl = 1; pl < 3; pl++) {
1590
38.1k
            res = mc(t, ((pixel *)f->cur.data[pl]) + uvdstoff, NULL, f->cur.stride[1],
1591
38.1k
                     bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1592
38.1k
                     t->bx & ~ss_hor, t->by & ~ss_ver, pl, b->mv[0],
1593
38.1k
                     &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1594
38.1k
            if (res) return res;
1595
38.1k
        }
1596
148k
    } 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
59.1k
            ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1602
58.0k
             (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1603
2.07k
        {
1604
2.07k
            res = warp_affine(t, dst, NULL, f->cur.stride[0], b_dim, 0, refp,
1605
2.07k
                              b->motion_mode == MM_WARP ? &t->warpmv :
1606
2.07k
                                  &f->frame_hdr->gmv[b->ref[0]]);
1607
2.07k
            if (res) return res;
1608
110k
        } else {
1609
110k
            res = mc(t, dst, NULL, f->cur.stride[0],
1610
110k
                     bw4, bh4, t->bx, t->by, 0, b->mv[0], refp, b->ref[0], filter_2d);
1611
110k
            if (res) return res;
1612
110k
            if (b->motion_mode == MM_OBMC) {
1613
13.8k
                res = obmc(t, dst, f->cur.stride[0], b_dim, 0, bx4, by4, w4, h4);
1614
13.8k
                if (res) return res;
1615
13.8k
            }
1616
110k
        }
1617
113k
        if (b->interintra_type) {
1618
3.65k
            pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1619
3.65k
            enum IntraPredMode m = b->interintra_mode == II_SMOOTH_PRED ?
1620
3.01k
                                   SMOOTH_PRED : b->interintra_mode;
1621
3.65k
            pixel *const tmp = bitfn(t->scratch.interintra);
1622
3.65k
            int angle = 0;
1623
3.65k
            const pixel *top_sb_edge = NULL;
1624
3.65k
            if (!(t->by & (f->sb_step - 1))) {
1625
974
                top_sb_edge = f->ipred_edge[0];
1626
974
                const int sby = t->by >> f->sb_shift;
1627
974
                top_sb_edge += f->sb128w * 128 * (sby - 1);
1628
974
            }
1629
3.65k
            m = bytefn(dav1d_prepare_intra_edges)(t->bx, t->bx > ts->tiling.col_start,
1630
3.65k
                                                  t->by, t->by > ts->tiling.row_start,
1631
3.65k
                                                  ts->tiling.col_end, ts->tiling.row_end,
1632
3.65k
                                                  0, dst, f->cur.stride[0], top_sb_edge,
1633
3.65k
                                                  m, &angle, bw4, bh4, 0, tl_edge
1634
3.65k
                                                  HIGHBD_CALL_SUFFIX);
1635
3.65k
            dsp->ipred.intra_pred[m](tmp, 4 * bw4 * sizeof(pixel),
1636
3.65k
                                     tl_edge, bw4 * 4, bh4 * 4, 0, 0, 0
1637
3.65k
                                     HIGHBD_CALL_SUFFIX);
1638
3.65k
            dsp->mc.blend(dst, f->cur.stride[0], tmp,
1639
3.65k
                          bw4 * 4, bh4 * 4, II_MASK(0, bs, b));
1640
3.65k
        }
1641
1642
113k
        if (!has_chroma) goto skip_inter_chroma_pred;
1643
1644
        // sub8x8 derivation
1645
93.3k
        int is_sub8x8 = bw4 == ss_hor || bh4 == ss_ver;
1646
93.3k
        refmvs_block *const *r;
1647
93.3k
        if (is_sub8x8) {
1648
8.28k
            assert(ss_hor == 1);
1649
8.28k
            r = &t->rt.r[(t->by & 31) + 5];
1650
8.28k
            if (bw4 == 1) is_sub8x8 &= r[0][t->bx - 1].ref.ref[0] > 0;
1651
8.28k
            if (bh4 == ss_ver) is_sub8x8 &= r[-1][t->bx].ref.ref[0] > 0;
1652
8.28k
            if (bw4 == 1 && bh4 == ss_ver)
1653
2.63k
                is_sub8x8 &= r[-1][t->bx - 1].ref.ref[0] > 0;
1654
8.28k
        }
1655
1656
        // chroma prediction
1657
93.3k
        if (is_sub8x8) {
1658
7.11k
            assert(ss_hor == 1);
1659
7.11k
            ptrdiff_t h_off = 0, v_off = 0;
1660
7.11k
            if (bw4 == 1 && bh4 == ss_ver) {
1661
5.29k
                for (int pl = 0; pl < 2; pl++) {
1662
3.53k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1663
3.53k
                             NULL, f->cur.stride[1],
1664
3.53k
                             bw4, bh4, t->bx - 1, t->by - 1, 1 + pl,
1665
3.53k
                             r[-1][t->bx - 1].mv.mv[0],
1666
3.53k
                             &f->refp[r[-1][t->bx - 1].ref.ref[0] - 1],
1667
3.53k
                             r[-1][t->bx - 1].ref.ref[0] - 1,
1668
3.53k
                             t->frame_thread.pass != 2 ? t->tl_4x4_filter :
1669
3.53k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx - 1].filter2d);
1670
3.53k
                    if (res) return res;
1671
3.53k
                }
1672
1.76k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1673
1.76k
                h_off = 2;
1674
1.76k
            }
1675
7.11k
            if (bw4 == 1) {
1676
4.42k
                const enum Filter2d left_filter_2d =
1677
4.42k
                    dav1d_filter_2d[t->l.filter[1][by4]][t->l.filter[0][by4]];
1678
13.2k
                for (int pl = 0; pl < 2; pl++) {
1679
8.84k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + v_off, NULL,
1680
8.84k
                             f->cur.stride[1], bw4, bh4, t->bx - 1,
1681
8.84k
                             t->by, 1 + pl, r[0][t->bx - 1].mv.mv[0],
1682
8.84k
                             &f->refp[r[0][t->bx - 1].ref.ref[0] - 1],
1683
8.84k
                             r[0][t->bx - 1].ref.ref[0] - 1,
1684
8.84k
                             t->frame_thread.pass != 2 ? left_filter_2d :
1685
8.84k
                                 f->frame_thread.b[(t->by * f->b4_stride) + t->bx - 1].filter2d);
1686
8.84k
                    if (res) return res;
1687
8.84k
                }
1688
4.42k
                h_off = 2;
1689
4.42k
            }
1690
7.11k
            if (bh4 == ss_ver) {
1691
4.45k
                const enum Filter2d top_filter_2d =
1692
4.45k
                    dav1d_filter_2d[t->a->filter[1][bx4]][t->a->filter[0][bx4]];
1693
13.3k
                for (int pl = 0; pl < 2; pl++) {
1694
8.91k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off, NULL,
1695
8.91k
                             f->cur.stride[1], bw4, bh4, t->bx, t->by - 1,
1696
8.91k
                             1 + pl, r[-1][t->bx].mv.mv[0],
1697
8.91k
                             &f->refp[r[-1][t->bx].ref.ref[0] - 1],
1698
8.91k
                             r[-1][t->bx].ref.ref[0] - 1,
1699
8.91k
                             t->frame_thread.pass != 2 ? top_filter_2d :
1700
8.91k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx].filter2d);
1701
8.91k
                    if (res) return res;
1702
8.91k
                }
1703
4.45k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1704
4.45k
            }
1705
21.3k
            for (int pl = 0; pl < 2; pl++) {
1706
14.2k
                res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off + v_off, NULL, f->cur.stride[1],
1707
14.2k
                         bw4, bh4, t->bx, t->by, 1 + pl, b->mv[0],
1708
14.2k
                         refp, b->ref[0], filter_2d);
1709
14.2k
                if (res) return res;
1710
14.2k
            }
1711
86.2k
        } else {
1712
86.2k
            if (imin(cbw4, cbh4) > 1 &&
1713
42.0k
                ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1714
41.0k
                 (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1715
1.97k
            {
1716
5.93k
                for (int pl = 0; pl < 2; pl++) {
1717
3.95k
                    res = warp_affine(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff, NULL,
1718
3.95k
                                      f->cur.stride[1], b_dim, 1 + pl, refp,
1719
3.95k
                                      b->motion_mode == MM_WARP ? &t->warpmv :
1720
3.95k
                                          &f->frame_hdr->gmv[b->ref[0]]);
1721
3.95k
                    if (res) return res;
1722
3.95k
                }
1723
84.2k
            } else {
1724
252k
                for (int pl = 0; pl < 2; pl++) {
1725
168k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1726
168k
                             NULL, f->cur.stride[1],
1727
168k
                             bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1728
168k
                             t->bx & ~ss_hor, t->by & ~ss_ver,
1729
168k
                             1 + pl, b->mv[0], refp, b->ref[0], filter_2d);
1730
168k
                    if (res) return res;
1731
168k
                    if (b->motion_mode == MM_OBMC) {
1732
26.7k
                        res = obmc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1733
26.7k
                                   f->cur.stride[1], b_dim, 1 + pl, bx4, by4, w4, h4);
1734
26.7k
                        if (res) return res;
1735
26.7k
                    }
1736
168k
                }
1737
84.2k
            }
1738
86.2k
            if (b->interintra_type) {
1739
                // FIXME for 8x32 with 4:2:2 subsampling, this probably does
1740
                // the wrong thing since it will select 4x16, not 4x32, as a
1741
                // transform size...
1742
3.48k
                const uint8_t *const ii_mask = II_MASK(chr_layout_idx, bs, b);
1743
1744
10.4k
                for (int pl = 0; pl < 2; pl++) {
1745
6.97k
                    pixel *const tmp = bitfn(t->scratch.interintra);
1746
6.97k
                    pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1747
6.97k
                    enum IntraPredMode m =
1748
6.97k
                        b->interintra_mode == II_SMOOTH_PRED ?
1749
5.70k
                        SMOOTH_PRED : b->interintra_mode;
1750
6.97k
                    int angle = 0;
1751
6.97k
                    pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1752
6.97k
                    const pixel *top_sb_edge = NULL;
1753
6.97k
                    if (!(t->by & (f->sb_step - 1))) {
1754
1.75k
                        top_sb_edge = f->ipred_edge[pl + 1];
1755
1.75k
                        const int sby = t->by >> f->sb_shift;
1756
1.75k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1757
1.75k
                    }
1758
6.97k
                    m = bytefn(dav1d_prepare_intra_edges)(t->bx >> ss_hor,
1759
6.97k
                                                          (t->bx >> ss_hor) >
1760
6.97k
                                                              (ts->tiling.col_start >> ss_hor),
1761
6.97k
                                                          t->by >> ss_ver,
1762
6.97k
                                                          (t->by >> ss_ver) >
1763
6.97k
                                                              (ts->tiling.row_start >> ss_ver),
1764
6.97k
                                                          ts->tiling.col_end >> ss_hor,
1765
6.97k
                                                          ts->tiling.row_end >> ss_ver,
1766
6.97k
                                                          0, uvdst, f->cur.stride[1],
1767
6.97k
                                                          top_sb_edge, m,
1768
6.97k
                                                          &angle, cbw4, cbh4, 0, tl_edge
1769
6.97k
                                                          HIGHBD_CALL_SUFFIX);
1770
6.97k
                    dsp->ipred.intra_pred[m](tmp, cbw4 * 4 * sizeof(pixel),
1771
6.97k
                                             tl_edge, cbw4 * 4, cbh4 * 4, 0, 0, 0
1772
6.97k
                                             HIGHBD_CALL_SUFFIX);
1773
6.97k
                    dsp->mc.blend(uvdst, f->cur.stride[1], tmp,
1774
6.97k
                                  cbw4 * 4, cbh4 * 4, ii_mask);
1775
6.97k
                }
1776
3.48k
            }
1777
86.2k
        }
1778
1779
113k
    skip_inter_chroma_pred: {}
1780
113k
        t->tl_4x4_filter = filter_2d;
1781
113k
    } else {
1782
35.6k
        const enum Filter2d filter_2d = b->filter2d;
1783
        // Maximum super block size is 128x128
1784
35.6k
        int16_t (*tmp)[128 * 128] = t->scratch.compinter;
1785
35.6k
        int jnt_weight;
1786
35.6k
        uint8_t *const seg_mask = t->scratch.seg_mask;
1787
35.6k
        const uint8_t *mask;
1788
1789
106k
        for (int i = 0; i < 2; i++) {
1790
71.2k
            const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1791
1792
71.2k
            if (b->inter_mode == GLOBALMV_GLOBALMV && f->gmv_warp_allowed[b->ref[i]]) {
1793
2.39k
                res = warp_affine(t, NULL, tmp[i], bw4 * 4, b_dim, 0, refp,
1794
2.39k
                                  &f->frame_hdr->gmv[b->ref[i]]);
1795
2.39k
                if (res) return res;
1796
68.8k
            } else {
1797
68.8k
                res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by, 0,
1798
68.8k
                         b->mv[i], refp, b->ref[i], filter_2d);
1799
68.8k
                if (res) return res;
1800
68.8k
            }
1801
71.2k
        }
1802
35.6k
        switch (b->comp_type) {
1803
26.3k
        case COMP_INTER_AVG:
1804
26.3k
            dsp->mc.avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1805
26.3k
                        bw4 * 4, bh4 * 4 HIGHBD_CALL_SUFFIX);
1806
26.3k
            break;
1807
1.42k
        case COMP_INTER_WEIGHTED_AVG:
1808
1.42k
            jnt_weight = f->jnt_weights[b->ref[0]][b->ref[1]];
1809
1.42k
            dsp->mc.w_avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1810
1.42k
                          bw4 * 4, bh4 * 4, jnt_weight HIGHBD_CALL_SUFFIX);
1811
1.42k
            break;
1812
4.65k
        case COMP_INTER_SEG:
1813
4.65k
            dsp->mc.w_mask[chr_layout_idx](dst, f->cur.stride[0],
1814
4.65k
                                           tmp[b->mask_sign], tmp[!b->mask_sign],
1815
4.65k
                                           bw4 * 4, bh4 * 4, seg_mask,
1816
4.65k
                                           b->mask_sign HIGHBD_CALL_SUFFIX);
1817
4.65k
            mask = seg_mask;
1818
4.65k
            break;
1819
3.16k
        case COMP_INTER_WEDGE:
1820
3.16k
            mask = WEDGE_MASK(0, bs, 0, b->wedge_idx);
1821
3.16k
            dsp->mc.mask(dst, f->cur.stride[0],
1822
3.16k
                         tmp[b->mask_sign], tmp[!b->mask_sign],
1823
3.16k
                         bw4 * 4, bh4 * 4, mask HIGHBD_CALL_SUFFIX);
1824
3.16k
            if (has_chroma)
1825
2.73k
                mask = WEDGE_MASK(chr_layout_idx, bs, b->mask_sign, b->wedge_idx);
1826
3.16k
            break;
1827
35.6k
        }
1828
1829
        // chroma
1830
99.2k
        if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1831
198k
            for (int i = 0; i < 2; i++) {
1832
132k
                const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1833
132k
                if (b->inter_mode == GLOBALMV_GLOBALMV &&
1834
17.8k
                    imin(cbw4, cbh4) > 1 && f->gmv_warp_allowed[b->ref[i]])
1835
1.86k
                {
1836
1.86k
                    res = warp_affine(t, NULL, tmp[i], bw4 * 4 >> ss_hor,
1837
1.86k
                                      b_dim, 1 + pl,
1838
1.86k
                                      refp, &f->frame_hdr->gmv[b->ref[i]]);
1839
1.86k
                    if (res) return res;
1840
130k
                } else {
1841
130k
                    res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by,
1842
130k
                             1 + pl, b->mv[i], refp, b->ref[i], filter_2d);
1843
130k
                    if (res) return res;
1844
130k
                }
1845
132k
            }
1846
66.1k
            pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1847
66.1k
            switch (b->comp_type) {
1848
50.6k
            case COMP_INTER_AVG:
1849
50.6k
                dsp->mc.avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1850
50.6k
                            bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver
1851
50.6k
                            HIGHBD_CALL_SUFFIX);
1852
50.6k
                break;
1853
982
            case COMP_INTER_WEIGHTED_AVG:
1854
982
                dsp->mc.w_avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1855
982
                              bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, jnt_weight
1856
982
                              HIGHBD_CALL_SUFFIX);
1857
982
                break;
1858
5.47k
            case COMP_INTER_WEDGE:
1859
14.5k
            case COMP_INTER_SEG:
1860
14.5k
                dsp->mc.mask(uvdst, f->cur.stride[1],
1861
14.5k
                             tmp[b->mask_sign], tmp[!b->mask_sign],
1862
14.5k
                             bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, mask
1863
14.5k
                             HIGHBD_CALL_SUFFIX);
1864
14.5k
                break;
1865
66.1k
            }
1866
66.1k
        }
1867
35.6k
    }
1868
1869
191k
    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
191k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1880
1881
191k
    if (b->skip) {
1882
        // reset coef contexts
1883
56.7k
        BlockContext *const a = t->a;
1884
56.7k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
1885
56.7k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
1886
56.7k
        if (has_chroma) {
1887
33.0k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
1888
33.0k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
1889
33.0k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
1890
33.0k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
1891
33.0k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
1892
33.0k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
1893
33.0k
        }
1894
56.7k
        return 0;
1895
56.7k
    }
1896
1897
134k
    const TxfmInfo *const uvtx = &dav1d_txfm_dimensions[b->uvtx];
1898
134k
    const TxfmInfo *const ytx = &dav1d_txfm_dimensions[b->max_ytx];
1899
134k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
1900
1901
274k
    for (int init_y = 0; init_y < bh4; init_y += 16) {
1902
282k
        for (int init_x = 0; init_x < bw4; init_x += 16) {
1903
            // coefficient coding & inverse transforms
1904
142k
            int y_off = !!init_y, y;
1905
142k
            dst += PXSTRIDE(f->cur.stride[0]) * 4 * init_y;
1906
296k
            for (y = init_y, t->by += init_y; y < imin(h4, init_y + 16);
1907
153k
                 y += ytx->h, y_off++)
1908
153k
            {
1909
153k
                int x, x_off = !!init_x;
1910
350k
                for (x = init_x, t->bx += init_x; x < imin(w4, init_x + 16);
1911
197k
                     x += ytx->w, x_off++)
1912
197k
                {
1913
197k
                    read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
1914
197k
                                   x_off, y_off, &dst[x * 4]);
1915
197k
                    t->bx += ytx->w;
1916
197k
                }
1917
153k
                dst += PXSTRIDE(f->cur.stride[0]) * 4 * ytx->h;
1918
153k
                t->bx -= x;
1919
153k
                t->by += ytx->h;
1920
153k
            }
1921
142k
            dst -= PXSTRIDE(f->cur.stride[0]) * 4 * y;
1922
142k
            t->by -= y;
1923
1924
            // chroma coefs and inverse transform
1925
357k
            if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1926
238k
                pixel *uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff +
1927
238k
                    (PXSTRIDE(f->cur.stride[1]) * init_y * 4 >> ss_ver);
1928
238k
                for (y = init_y >> ss_ver, t->by += init_y;
1929
507k
                     y < imin(ch4, (init_y + 16) >> ss_ver); y += uvtx->h)
1930
269k
                {
1931
269k
                    int x;
1932
269k
                    for (x = init_x >> ss_hor, t->bx += init_x;
1933
636k
                         x < imin(cw4, (init_x + 16) >> ss_hor); x += uvtx->w)
1934
367k
                    {
1935
367k
                        coef *cf;
1936
367k
                        int eob;
1937
367k
                        enum TxfmType txtp;
1938
367k
                        if (t->frame_thread.pass) {
1939
367k
                            const int p = t->frame_thread.pass & 1;
1940
367k
                            const int cbi = *ts->frame_thread[p].cbi++;
1941
367k
                            cf = ts->frame_thread[p].cf;
1942
367k
                            ts->frame_thread[p].cf += uvtx->w * uvtx->h * 16;
1943
367k
                            eob  = cbi >> 5;
1944
367k
                            txtp = cbi & 0x1f;
1945
367k
                        } 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
367k
                        if (eob >= 0) {
1964
105k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1965
0
                                coef_dump(cf, uvtx->h * 4, uvtx->w * 4, 3, "dq");
1966
105k
                            dsp->itx.itxfm_add[b->uvtx]
1967
105k
                                              [txtp](&uvdst[4 * x],
1968
105k
                                                     f->cur.stride[1],
1969
105k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1970
105k
                            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
105k
                        }
1974
367k
                        t->bx += uvtx->w << ss_hor;
1975
367k
                    }
1976
269k
                    uvdst += PXSTRIDE(f->cur.stride[1]) * 4 * uvtx->h;
1977
269k
                    t->bx -= x << ss_hor;
1978
269k
                    t->by += uvtx->h << ss_ver;
1979
269k
                }
1980
238k
                t->by -= y << ss_ver;
1981
238k
            }
1982
142k
        }
1983
140k
    }
1984
134k
    return 0;
1985
191k
}
dav1d_recon_b_inter_16bpc
Line
Count
Source
1559
167k
{
1560
167k
    Dav1dTileState *const ts = t->ts;
1561
167k
    const Dav1dFrameContext *const f = t->f;
1562
167k
    const Dav1dDSPContext *const dsp = f->dsp;
1563
167k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1564
167k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1565
167k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1566
167k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1567
167k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1568
167k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1569
167k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1570
167k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1571
148k
                           (bw4 > ss_hor || t->bx & 1) &&
1572
141k
                           (bh4 > ss_ver || t->by & 1);
1573
167k
    const int chr_layout_idx = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I400 ? 0 :
1574
167k
                               DAV1D_PIXEL_LAYOUT_I444 - f->cur.p.layout;
1575
167k
    int res;
1576
1577
    // prediction
1578
167k
    const int cbh4 = (bh4 + ss_ver) >> ss_ver, cbw4 = (bw4 + ss_hor) >> ss_hor;
1579
167k
    pixel *dst = ((pixel *) f->cur.data[0]) +
1580
167k
        4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1581
167k
    const ptrdiff_t uvdstoff =
1582
167k
        4 * ((t->bx >> ss_hor) + (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1583
167k
    if (IS_KEY_OR_INTRA(f->frame_hdr)) {
1584
        // intrabc
1585
22.2k
        assert(!f->frame_hdr->super_res.enabled);
1586
22.2k
        res = mc(t, dst, NULL, f->cur.stride[0], bw4, bh4, t->bx, t->by, 0,
1587
22.2k
                 b->mv[0], &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1588
22.2k
        if (res) return res;
1589
44.0k
        if (has_chroma) for (int pl = 1; pl < 3; pl++) {
1590
29.3k
            res = mc(t, ((pixel *)f->cur.data[pl]) + uvdstoff, NULL, f->cur.stride[1],
1591
29.3k
                     bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1592
29.3k
                     t->bx & ~ss_hor, t->by & ~ss_ver, pl, b->mv[0],
1593
29.3k
                     &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1594
29.3k
            if (res) return res;
1595
29.3k
        }
1596
145k
    } else if (b->comp_type == COMP_INTER_NONE) {
1597
110k
        const Dav1dThreadPicture *const refp = &f->refp[b->ref[0]];
1598
110k
        const enum Filter2d filter_2d = b->filter2d;
1599
1600
110k
        if (imin(bw4, bh4) > 1 &&
1601
62.6k
            ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1602
61.9k
             (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1603
2.83k
        {
1604
2.83k
            res = warp_affine(t, dst, NULL, f->cur.stride[0], b_dim, 0, refp,
1605
2.83k
                              b->motion_mode == MM_WARP ? &t->warpmv :
1606
2.83k
                                  &f->frame_hdr->gmv[b->ref[0]]);
1607
2.83k
            if (res) return res;
1608
107k
        } else {
1609
107k
            res = mc(t, dst, NULL, f->cur.stride[0],
1610
107k
                     bw4, bh4, t->bx, t->by, 0, b->mv[0], refp, b->ref[0], filter_2d);
1611
107k
            if (res) return res;
1612
107k
            if (b->motion_mode == MM_OBMC) {
1613
18.2k
                res = obmc(t, dst, f->cur.stride[0], b_dim, 0, bx4, by4, w4, h4);
1614
18.2k
                if (res) return res;
1615
18.2k
            }
1616
107k
        }
1617
110k
        if (b->interintra_type) {
1618
3.76k
            pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1619
3.76k
            enum IntraPredMode m = b->interintra_mode == II_SMOOTH_PRED ?
1620
3.12k
                                   SMOOTH_PRED : b->interintra_mode;
1621
3.76k
            pixel *const tmp = bitfn(t->scratch.interintra);
1622
3.76k
            int angle = 0;
1623
3.76k
            const pixel *top_sb_edge = NULL;
1624
3.76k
            if (!(t->by & (f->sb_step - 1))) {
1625
1.37k
                top_sb_edge = f->ipred_edge[0];
1626
1.37k
                const int sby = t->by >> f->sb_shift;
1627
1.37k
                top_sb_edge += f->sb128w * 128 * (sby - 1);
1628
1.37k
            }
1629
3.76k
            m = bytefn(dav1d_prepare_intra_edges)(t->bx, t->bx > ts->tiling.col_start,
1630
3.76k
                                                  t->by, t->by > ts->tiling.row_start,
1631
3.76k
                                                  ts->tiling.col_end, ts->tiling.row_end,
1632
3.76k
                                                  0, dst, f->cur.stride[0], top_sb_edge,
1633
3.76k
                                                  m, &angle, bw4, bh4, 0, tl_edge
1634
3.76k
                                                  HIGHBD_CALL_SUFFIX);
1635
3.76k
            dsp->ipred.intra_pred[m](tmp, 4 * bw4 * sizeof(pixel),
1636
3.76k
                                     tl_edge, bw4 * 4, bh4 * 4, 0, 0, 0
1637
3.76k
                                     HIGHBD_CALL_SUFFIX);
1638
3.76k
            dsp->mc.blend(dst, f->cur.stride[0], tmp,
1639
3.76k
                          bw4 * 4, bh4 * 4, II_MASK(0, bs, b));
1640
3.76k
        }
1641
1642
110k
        if (!has_chroma) goto skip_inter_chroma_pred;
1643
1644
        // sub8x8 derivation
1645
90.4k
        int is_sub8x8 = bw4 == ss_hor || bh4 == ss_ver;
1646
90.4k
        refmvs_block *const *r;
1647
90.4k
        if (is_sub8x8) {
1648
5.94k
            assert(ss_hor == 1);
1649
5.94k
            r = &t->rt.r[(t->by & 31) + 5];
1650
5.94k
            if (bw4 == 1) is_sub8x8 &= r[0][t->bx - 1].ref.ref[0] > 0;
1651
5.94k
            if (bh4 == ss_ver) is_sub8x8 &= r[-1][t->bx].ref.ref[0] > 0;
1652
5.94k
            if (bw4 == 1 && bh4 == ss_ver)
1653
1.76k
                is_sub8x8 &= r[-1][t->bx - 1].ref.ref[0] > 0;
1654
5.94k
        }
1655
1656
        // chroma prediction
1657
90.4k
        if (is_sub8x8) {
1658
5.86k
            assert(ss_hor == 1);
1659
5.86k
            ptrdiff_t h_off = 0, v_off = 0;
1660
5.86k
            if (bw4 == 1 && bh4 == ss_ver) {
1661
5.10k
                for (int pl = 0; pl < 2; pl++) {
1662
3.40k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1663
3.40k
                             NULL, f->cur.stride[1],
1664
3.40k
                             bw4, bh4, t->bx - 1, t->by - 1, 1 + pl,
1665
3.40k
                             r[-1][t->bx - 1].mv.mv[0],
1666
3.40k
                             &f->refp[r[-1][t->bx - 1].ref.ref[0] - 1],
1667
3.40k
                             r[-1][t->bx - 1].ref.ref[0] - 1,
1668
3.40k
                             t->frame_thread.pass != 2 ? t->tl_4x4_filter :
1669
3.40k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx - 1].filter2d);
1670
3.40k
                    if (res) return res;
1671
3.40k
                }
1672
1.70k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1673
1.70k
                h_off = 2;
1674
1.70k
            }
1675
5.86k
            if (bw4 == 1) {
1676
4.49k
                const enum Filter2d left_filter_2d =
1677
4.49k
                    dav1d_filter_2d[t->l.filter[1][by4]][t->l.filter[0][by4]];
1678
13.4k
                for (int pl = 0; pl < 2; pl++) {
1679
8.99k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + v_off, NULL,
1680
8.99k
                             f->cur.stride[1], bw4, bh4, t->bx - 1,
1681
8.99k
                             t->by, 1 + pl, r[0][t->bx - 1].mv.mv[0],
1682
8.99k
                             &f->refp[r[0][t->bx - 1].ref.ref[0] - 1],
1683
8.99k
                             r[0][t->bx - 1].ref.ref[0] - 1,
1684
8.99k
                             t->frame_thread.pass != 2 ? left_filter_2d :
1685
8.99k
                                 f->frame_thread.b[(t->by * f->b4_stride) + t->bx - 1].filter2d);
1686
8.99k
                    if (res) return res;
1687
8.99k
                }
1688
4.49k
                h_off = 2;
1689
4.49k
            }
1690
5.86k
            if (bh4 == ss_ver) {
1691
3.06k
                const enum Filter2d top_filter_2d =
1692
3.06k
                    dav1d_filter_2d[t->a->filter[1][bx4]][t->a->filter[0][bx4]];
1693
9.18k
                for (int pl = 0; pl < 2; pl++) {
1694
6.12k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off, NULL,
1695
6.12k
                             f->cur.stride[1], bw4, bh4, t->bx, t->by - 1,
1696
6.12k
                             1 + pl, r[-1][t->bx].mv.mv[0],
1697
6.12k
                             &f->refp[r[-1][t->bx].ref.ref[0] - 1],
1698
6.12k
                             r[-1][t->bx].ref.ref[0] - 1,
1699
6.12k
                             t->frame_thread.pass != 2 ? top_filter_2d :
1700
6.12k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx].filter2d);
1701
6.12k
                    if (res) return res;
1702
6.12k
                }
1703
3.06k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1704
3.06k
            }
1705
17.5k
            for (int pl = 0; pl < 2; pl++) {
1706
11.7k
                res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off + v_off, NULL, f->cur.stride[1],
1707
11.7k
                         bw4, bh4, t->bx, t->by, 1 + pl, b->mv[0],
1708
11.7k
                         refp, b->ref[0], filter_2d);
1709
11.7k
                if (res) return res;
1710
11.7k
            }
1711
84.5k
        } else {
1712
84.5k
            if (imin(cbw4, cbh4) > 1 &&
1713
48.2k
                ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1714
47.7k
                 (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1715
2.62k
            {
1716
7.87k
                for (int pl = 0; pl < 2; pl++) {
1717
5.25k
                    res = warp_affine(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff, NULL,
1718
5.25k
                                      f->cur.stride[1], b_dim, 1 + pl, refp,
1719
5.25k
                                      b->motion_mode == MM_WARP ? &t->warpmv :
1720
5.25k
                                          &f->frame_hdr->gmv[b->ref[0]]);
1721
5.25k
                    if (res) return res;
1722
5.25k
                }
1723
81.9k
            } else {
1724
245k
                for (int pl = 0; pl < 2; pl++) {
1725
163k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1726
163k
                             NULL, f->cur.stride[1],
1727
163k
                             bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1728
163k
                             t->bx & ~ss_hor, t->by & ~ss_ver,
1729
163k
                             1 + pl, b->mv[0], refp, b->ref[0], filter_2d);
1730
163k
                    if (res) return res;
1731
163k
                    if (b->motion_mode == MM_OBMC) {
1732
35.7k
                        res = obmc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1733
35.7k
                                   f->cur.stride[1], b_dim, 1 + pl, bx4, by4, w4, h4);
1734
35.7k
                        if (res) return res;
1735
35.7k
                    }
1736
163k
                }
1737
81.9k
            }
1738
84.5k
            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.07k
                const uint8_t *const ii_mask = II_MASK(chr_layout_idx, bs, b);
1743
1744
9.23k
                for (int pl = 0; pl < 2; pl++) {
1745
6.15k
                    pixel *const tmp = bitfn(t->scratch.interintra);
1746
6.15k
                    pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1747
6.15k
                    enum IntraPredMode m =
1748
6.15k
                        b->interintra_mode == II_SMOOTH_PRED ?
1749
5.28k
                        SMOOTH_PRED : b->interintra_mode;
1750
6.15k
                    int angle = 0;
1751
6.15k
                    pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1752
6.15k
                    const pixel *top_sb_edge = NULL;
1753
6.15k
                    if (!(t->by & (f->sb_step - 1))) {
1754
1.42k
                        top_sb_edge = f->ipred_edge[pl + 1];
1755
1.42k
                        const int sby = t->by >> f->sb_shift;
1756
1.42k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1757
1.42k
                    }
1758
6.15k
                    m = bytefn(dav1d_prepare_intra_edges)(t->bx >> ss_hor,
1759
6.15k
                                                          (t->bx >> ss_hor) >
1760
6.15k
                                                              (ts->tiling.col_start >> ss_hor),
1761
6.15k
                                                          t->by >> ss_ver,
1762
6.15k
                                                          (t->by >> ss_ver) >
1763
6.15k
                                                              (ts->tiling.row_start >> ss_ver),
1764
6.15k
                                                          ts->tiling.col_end >> ss_hor,
1765
6.15k
                                                          ts->tiling.row_end >> ss_ver,
1766
6.15k
                                                          0, uvdst, f->cur.stride[1],
1767
6.15k
                                                          top_sb_edge, m,
1768
6.15k
                                                          &angle, cbw4, cbh4, 0, tl_edge
1769
6.15k
                                                          HIGHBD_CALL_SUFFIX);
1770
6.15k
                    dsp->ipred.intra_pred[m](tmp, cbw4 * 4 * sizeof(pixel),
1771
6.15k
                                             tl_edge, cbw4 * 4, cbh4 * 4, 0, 0, 0
1772
6.15k
                                             HIGHBD_CALL_SUFFIX);
1773
6.15k
                    dsp->mc.blend(uvdst, f->cur.stride[1], tmp,
1774
6.15k
                                  cbw4 * 4, cbh4 * 4, ii_mask);
1775
6.15k
                }
1776
3.07k
            }
1777
84.5k
        }
1778
1779
110k
    skip_inter_chroma_pred: {}
1780
110k
        t->tl_4x4_filter = filter_2d;
1781
110k
    } else {
1782
34.4k
        const enum Filter2d filter_2d = b->filter2d;
1783
        // Maximum super block size is 128x128
1784
34.4k
        int16_t (*tmp)[128 * 128] = t->scratch.compinter;
1785
34.4k
        int jnt_weight;
1786
34.4k
        uint8_t *const seg_mask = t->scratch.seg_mask;
1787
34.4k
        const uint8_t *mask;
1788
1789
103k
        for (int i = 0; i < 2; i++) {
1790
68.9k
            const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1791
1792
68.9k
            if (b->inter_mode == GLOBALMV_GLOBALMV && f->gmv_warp_allowed[b->ref[i]]) {
1793
2.50k
                res = warp_affine(t, NULL, tmp[i], bw4 * 4, b_dim, 0, refp,
1794
2.50k
                                  &f->frame_hdr->gmv[b->ref[i]]);
1795
2.50k
                if (res) return res;
1796
66.4k
            } else {
1797
66.4k
                res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by, 0,
1798
66.4k
                         b->mv[i], refp, b->ref[i], filter_2d);
1799
66.4k
                if (res) return res;
1800
66.4k
            }
1801
68.9k
        }
1802
34.4k
        switch (b->comp_type) {
1803
20.3k
        case COMP_INTER_AVG:
1804
20.3k
            dsp->mc.avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1805
20.3k
                        bw4 * 4, bh4 * 4 HIGHBD_CALL_SUFFIX);
1806
20.3k
            break;
1807
7.21k
        case COMP_INTER_WEIGHTED_AVG:
1808
7.21k
            jnt_weight = f->jnt_weights[b->ref[0]][b->ref[1]];
1809
7.21k
            dsp->mc.w_avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1810
7.21k
                          bw4 * 4, bh4 * 4, jnt_weight HIGHBD_CALL_SUFFIX);
1811
7.21k
            break;
1812
4.05k
        case COMP_INTER_SEG:
1813
4.05k
            dsp->mc.w_mask[chr_layout_idx](dst, f->cur.stride[0],
1814
4.05k
                                           tmp[b->mask_sign], tmp[!b->mask_sign],
1815
4.05k
                                           bw4 * 4, bh4 * 4, seg_mask,
1816
4.05k
                                           b->mask_sign HIGHBD_CALL_SUFFIX);
1817
4.05k
            mask = seg_mask;
1818
4.05k
            break;
1819
2.83k
        case COMP_INTER_WEDGE:
1820
2.83k
            mask = WEDGE_MASK(0, bs, 0, b->wedge_idx);
1821
2.83k
            dsp->mc.mask(dst, f->cur.stride[0],
1822
2.83k
                         tmp[b->mask_sign], tmp[!b->mask_sign],
1823
2.83k
                         bw4 * 4, bh4 * 4, mask HIGHBD_CALL_SUFFIX);
1824
2.83k
            if (has_chroma)
1825
2.29k
                mask = WEDGE_MASK(chr_layout_idx, bs, b->mask_sign, b->wedge_idx);
1826
2.83k
            break;
1827
34.4k
        }
1828
1829
        // chroma
1830
97.4k
        if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1831
194k
            for (int i = 0; i < 2; i++) {
1832
129k
                const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1833
129k
                if (b->inter_mode == GLOBALMV_GLOBALMV &&
1834
20.8k
                    imin(cbw4, cbh4) > 1 && f->gmv_warp_allowed[b->ref[i]])
1835
2.27k
                {
1836
2.27k
                    res = warp_affine(t, NULL, tmp[i], bw4 * 4 >> ss_hor,
1837
2.27k
                                      b_dim, 1 + pl,
1838
2.27k
                                      refp, &f->frame_hdr->gmv[b->ref[i]]);
1839
2.27k
                    if (res) return res;
1840
127k
                } else {
1841
127k
                    res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by,
1842
127k
                             1 + pl, b->mv[i], refp, b->ref[i], filter_2d);
1843
127k
                    if (res) return res;
1844
127k
                }
1845
129k
            }
1846
64.9k
            pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1847
64.9k
            switch (b->comp_type) {
1848
38.3k
            case COMP_INTER_AVG:
1849
38.3k
                dsp->mc.avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1850
38.3k
                            bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver
1851
38.3k
                            HIGHBD_CALL_SUFFIX);
1852
38.3k
                break;
1853
14.1k
            case COMP_INTER_WEIGHTED_AVG:
1854
14.1k
                dsp->mc.w_avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1855
14.1k
                              bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, jnt_weight
1856
14.1k
                              HIGHBD_CALL_SUFFIX);
1857
14.1k
                break;
1858
4.59k
            case COMP_INTER_WEDGE:
1859
12.3k
            case COMP_INTER_SEG:
1860
12.3k
                dsp->mc.mask(uvdst, f->cur.stride[1],
1861
12.3k
                             tmp[b->mask_sign], tmp[!b->mask_sign],
1862
12.3k
                             bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, mask
1863
12.3k
                             HIGHBD_CALL_SUFFIX);
1864
12.3k
                break;
1865
64.9k
            }
1866
64.9k
        }
1867
34.4k
    }
1868
1869
167k
    if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1870
0
        hex_dump(dst, f->cur.stride[0], b_dim[0] * 4, b_dim[1] * 4, "y-pred");
1871
0
        if (has_chroma) {
1872
0
            hex_dump(&((pixel *) f->cur.data[1])[uvdstoff], f->cur.stride[1],
1873
0
                     cbw4 * 4, cbh4 * 4, "u-pred");
1874
0
            hex_dump(&((pixel *) f->cur.data[2])[uvdstoff], f->cur.stride[1],
1875
0
                     cbw4 * 4, cbh4 * 4, "v-pred");
1876
0
        }
1877
0
    }
1878
1879
167k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1880
1881
167k
    if (b->skip) {
1882
        // reset coef contexts
1883
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
36.2k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
1888
36.2k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
1889
36.2k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
1890
36.2k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
1891
36.2k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
1892
36.2k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
1893
36.2k
        }
1894
46.9k
        return 0;
1895
46.9k
    }
1896
1897
120k
    const TxfmInfo *const uvtx = &dav1d_txfm_dimensions[b->uvtx];
1898
120k
    const TxfmInfo *const ytx = &dav1d_txfm_dimensions[b->max_ytx];
1899
120k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
1900
1901
250k
    for (int init_y = 0; init_y < bh4; init_y += 16) {
1902
261k
        for (int init_x = 0; init_x < bw4; init_x += 16) {
1903
            // coefficient coding & inverse transforms
1904
132k
            int y_off = !!init_y, y;
1905
132k
            dst += PXSTRIDE(f->cur.stride[0]) * 4 * init_y;
1906
286k
            for (y = init_y, t->by += init_y; y < imin(h4, init_y + 16);
1907
154k
                 y += ytx->h, y_off++)
1908
154k
            {
1909
154k
                int x, x_off = !!init_x;
1910
404k
                for (x = init_x, t->bx += init_x; x < imin(w4, init_x + 16);
1911
250k
                     x += ytx->w, x_off++)
1912
250k
                {
1913
250k
                    read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
1914
250k
                                   x_off, y_off, &dst[x * 4]);
1915
250k
                    t->bx += ytx->w;
1916
250k
                }
1917
154k
                dst += PXSTRIDE(f->cur.stride[0]) * 4 * ytx->h;
1918
154k
                t->bx -= x;
1919
154k
                t->by += ytx->h;
1920
154k
            }
1921
132k
            dst -= PXSTRIDE(f->cur.stride[0]) * 4 * y;
1922
132k
            t->by -= y;
1923
1924
            // chroma coefs and inverse transform
1925
336k
            if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1926
224k
                pixel *uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff +
1927
224k
                    (PXSTRIDE(f->cur.stride[1]) * init_y * 4 >> ss_ver);
1928
224k
                for (y = init_y >> ss_ver, t->by += init_y;
1929
503k
                     y < imin(ch4, (init_y + 16) >> ss_ver); y += uvtx->h)
1930
279k
                {
1931
279k
                    int x;
1932
279k
                    for (x = init_x >> ss_hor, t->bx += init_x;
1933
763k
                         x < imin(cw4, (init_x + 16) >> ss_hor); x += uvtx->w)
1934
483k
                    {
1935
483k
                        coef *cf;
1936
483k
                        int eob;
1937
483k
                        enum TxfmType txtp;
1938
483k
                        if (t->frame_thread.pass) {
1939
483k
                            const int p = t->frame_thread.pass & 1;
1940
483k
                            const int cbi = *ts->frame_thread[p].cbi++;
1941
483k
                            cf = ts->frame_thread[p].cf;
1942
483k
                            ts->frame_thread[p].cf += uvtx->w * uvtx->h * 16;
1943
483k
                            eob  = cbi >> 5;
1944
483k
                            txtp = cbi & 0x1f;
1945
483k
                        } 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
483k
                        if (eob >= 0) {
1964
188k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1965
0
                                coef_dump(cf, uvtx->h * 4, uvtx->w * 4, 3, "dq");
1966
188k
                            dsp->itx.itxfm_add[b->uvtx]
1967
188k
                                              [txtp](&uvdst[4 * x],
1968
188k
                                                     f->cur.stride[1],
1969
188k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1970
188k
                            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
188k
                        }
1974
483k
                        t->bx += uvtx->w << ss_hor;
1975
483k
                    }
1976
279k
                    uvdst += PXSTRIDE(f->cur.stride[1]) * 4 * uvtx->h;
1977
279k
                    t->bx -= x << ss_hor;
1978
279k
                    t->by += uvtx->h << ss_ver;
1979
279k
                }
1980
224k
                t->by -= y << ss_ver;
1981
224k
            }
1982
132k
        }
1983
129k
    }
1984
120k
    return 0;
1985
167k
}
1986
1987
143k
void bytefn(dav1d_filter_sbrow_deblock_cols)(Dav1dFrameContext *const f, const int sby) {
1988
143k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK) ||
1989
143k
        (!f->frame_hdr->loopfilter.level_y[0] && !f->frame_hdr->loopfilter.level_y[1]))
1990
0
    {
1991
0
        return;
1992
0
    }
1993
143k
    const int y = sby * f->sb_step * 4;
1994
143k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1995
143k
    pixel *const p[3] = {
1996
143k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
1997
143k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
1998
143k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
1999
143k
    };
2000
143k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2001
143k
    bytefn(dav1d_loopfilter_sbrow_cols)(f, p, mask, sby,
2002
143k
                                        f->lf.start_of_tile_row[sby]);
2003
143k
}
dav1d_filter_sbrow_deblock_cols_8bpc
Line
Count
Source
1987
75.3k
void bytefn(dav1d_filter_sbrow_deblock_cols)(Dav1dFrameContext *const f, const int sby) {
1988
75.3k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK) ||
1989
75.3k
        (!f->frame_hdr->loopfilter.level_y[0] && !f->frame_hdr->loopfilter.level_y[1]))
1990
0
    {
1991
0
        return;
1992
0
    }
1993
75.3k
    const int y = sby * f->sb_step * 4;
1994
75.3k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1995
75.3k
    pixel *const p[3] = {
1996
75.3k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
1997
75.3k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
1998
75.3k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
1999
75.3k
    };
2000
75.3k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2001
75.3k
    bytefn(dav1d_loopfilter_sbrow_cols)(f, p, mask, sby,
2002
75.3k
                                        f->lf.start_of_tile_row[sby]);
2003
75.3k
}
dav1d_filter_sbrow_deblock_cols_16bpc
Line
Count
Source
1987
68.1k
void bytefn(dav1d_filter_sbrow_deblock_cols)(Dav1dFrameContext *const f, const int sby) {
1988
68.1k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK) ||
1989
68.1k
        (!f->frame_hdr->loopfilter.level_y[0] && !f->frame_hdr->loopfilter.level_y[1]))
1990
0
    {
1991
0
        return;
1992
0
    }
1993
68.1k
    const int y = sby * f->sb_step * 4;
1994
68.1k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1995
68.1k
    pixel *const p[3] = {
1996
68.1k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
1997
68.1k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
1998
68.1k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
1999
68.1k
    };
2000
68.1k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2001
68.1k
    bytefn(dav1d_loopfilter_sbrow_cols)(f, p, mask, sby,
2002
68.1k
                                        f->lf.start_of_tile_row[sby]);
2003
68.1k
}
2004
2005
155k
void bytefn(dav1d_filter_sbrow_deblock_rows)(Dav1dFrameContext *const f, const int sby) {
2006
155k
    const int y = sby * f->sb_step * 4;
2007
155k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2008
155k
    pixel *const p[3] = {
2009
155k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2010
155k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2011
155k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2012
155k
    };
2013
155k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2014
155k
    if (f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK &&
2015
155k
        (f->frame_hdr->loopfilter.level_y[0] || f->frame_hdr->loopfilter.level_y[1]))
2016
143k
    {
2017
143k
        bytefn(dav1d_loopfilter_sbrow_rows)(f, p, mask, sby);
2018
143k
    }
2019
155k
    if (f->seq_hdr->cdef || f->lf.restore_planes) {
2020
        // Store loop filtered pixels required by CDEF / LR
2021
134k
        bytefn(dav1d_copy_lpf)(f, p, sby);
2022
134k
    }
2023
155k
}
dav1d_filter_sbrow_deblock_rows_8bpc
Line
Count
Source
2005
82.6k
void bytefn(dav1d_filter_sbrow_deblock_rows)(Dav1dFrameContext *const f, const int sby) {
2006
82.6k
    const int y = sby * f->sb_step * 4;
2007
82.6k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2008
82.6k
    pixel *const p[3] = {
2009
82.6k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2010
82.6k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2011
82.6k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2012
82.6k
    };
2013
82.6k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2014
82.6k
    if (f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK &&
2015
82.6k
        (f->frame_hdr->loopfilter.level_y[0] || f->frame_hdr->loopfilter.level_y[1]))
2016
75.2k
    {
2017
75.2k
        bytefn(dav1d_loopfilter_sbrow_rows)(f, p, mask, sby);
2018
75.2k
    }
2019
82.6k
    if (f->seq_hdr->cdef || f->lf.restore_planes) {
2020
        // Store loop filtered pixels required by CDEF / LR
2021
68.8k
        bytefn(dav1d_copy_lpf)(f, p, sby);
2022
68.8k
    }
2023
82.6k
}
dav1d_filter_sbrow_deblock_rows_16bpc
Line
Count
Source
2005
73.2k
void bytefn(dav1d_filter_sbrow_deblock_rows)(Dav1dFrameContext *const f, const int sby) {
2006
73.2k
    const int y = sby * f->sb_step * 4;
2007
73.2k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2008
73.2k
    pixel *const p[3] = {
2009
73.2k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2010
73.2k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2011
73.2k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2012
73.2k
    };
2013
73.2k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2014
73.2k
    if (f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK &&
2015
73.2k
        (f->frame_hdr->loopfilter.level_y[0] || f->frame_hdr->loopfilter.level_y[1]))
2016
68.0k
    {
2017
68.0k
        bytefn(dav1d_loopfilter_sbrow_rows)(f, p, mask, sby);
2018
68.0k
    }
2019
73.2k
    if (f->seq_hdr->cdef || f->lf.restore_planes) {
2020
        // Store loop filtered pixels required by CDEF / LR
2021
65.7k
        bytefn(dav1d_copy_lpf)(f, p, sby);
2022
65.7k
    }
2023
73.2k
}
2024
2025
82.2k
void bytefn(dav1d_filter_sbrow_cdef)(Dav1dTaskContext *const tc, const int sby) {
2026
82.2k
    const Dav1dFrameContext *const f = tc->f;
2027
82.2k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_CDEF)) return;
2028
82.2k
    const int sbsz = f->sb_step;
2029
82.2k
    const int y = sby * sbsz * 4;
2030
82.2k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2031
82.2k
    pixel *const p[3] = {
2032
82.2k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2033
82.2k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2034
82.2k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2035
82.2k
    };
2036
82.2k
    Av1Filter *prev_mask = f->lf.mask + ((sby - 1) >> !f->seq_hdr->sb128) * f->sb128w;
2037
82.2k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2038
82.2k
    const int start = sby * sbsz;
2039
82.2k
    if (sby) {
2040
33.7k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2041
33.7k
        pixel *p_up[3] = {
2042
33.7k
            p[0] - 8 * PXSTRIDE(f->cur.stride[0]),
2043
33.7k
            p[1] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2044
33.7k
            p[2] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2045
33.7k
        };
2046
33.7k
        bytefn(dav1d_cdef_brow)(tc, p_up, prev_mask, start - 2, start, 1, sby);
2047
33.7k
    }
2048
82.2k
    const int n_blks = sbsz - 2 * (sby + 1 < f->sbh);
2049
82.2k
    const int end = imin(start + n_blks, f->bh);
2050
82.2k
    bytefn(dav1d_cdef_brow)(tc, p, mask, start, end, 0, sby);
2051
82.2k
}
dav1d_filter_sbrow_cdef_8bpc
Line
Count
Source
2025
43.2k
void bytefn(dav1d_filter_sbrow_cdef)(Dav1dTaskContext *const tc, const int sby) {
2026
43.2k
    const Dav1dFrameContext *const f = tc->f;
2027
43.2k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_CDEF)) return;
2028
43.2k
    const int sbsz = f->sb_step;
2029
43.2k
    const int y = sby * sbsz * 4;
2030
43.2k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2031
43.2k
    pixel *const p[3] = {
2032
43.2k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2033
43.2k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2034
43.2k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2035
43.2k
    };
2036
43.2k
    Av1Filter *prev_mask = f->lf.mask + ((sby - 1) >> !f->seq_hdr->sb128) * f->sb128w;
2037
43.2k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2038
43.2k
    const int start = sby * sbsz;
2039
43.2k
    if (sby) {
2040
19.3k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2041
19.3k
        pixel *p_up[3] = {
2042
19.3k
            p[0] - 8 * PXSTRIDE(f->cur.stride[0]),
2043
19.3k
            p[1] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2044
19.3k
            p[2] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2045
19.3k
        };
2046
19.3k
        bytefn(dav1d_cdef_brow)(tc, p_up, prev_mask, start - 2, start, 1, sby);
2047
19.3k
    }
2048
43.2k
    const int n_blks = sbsz - 2 * (sby + 1 < f->sbh);
2049
43.2k
    const int end = imin(start + n_blks, f->bh);
2050
43.2k
    bytefn(dav1d_cdef_brow)(tc, p, mask, start, end, 0, sby);
2051
43.2k
}
dav1d_filter_sbrow_cdef_16bpc
Line
Count
Source
2025
38.9k
void bytefn(dav1d_filter_sbrow_cdef)(Dav1dTaskContext *const tc, const int sby) {
2026
38.9k
    const Dav1dFrameContext *const f = tc->f;
2027
38.9k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_CDEF)) return;
2028
38.9k
    const int sbsz = f->sb_step;
2029
38.9k
    const int y = sby * sbsz * 4;
2030
38.9k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2031
38.9k
    pixel *const p[3] = {
2032
38.9k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2033
38.9k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2034
38.9k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2035
38.9k
    };
2036
38.9k
    Av1Filter *prev_mask = f->lf.mask + ((sby - 1) >> !f->seq_hdr->sb128) * f->sb128w;
2037
38.9k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2038
38.9k
    const int start = sby * sbsz;
2039
38.9k
    if (sby) {
2040
14.4k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2041
14.4k
        pixel *p_up[3] = {
2042
14.4k
            p[0] - 8 * PXSTRIDE(f->cur.stride[0]),
2043
14.4k
            p[1] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2044
14.4k
            p[2] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2045
14.4k
        };
2046
14.4k
        bytefn(dav1d_cdef_brow)(tc, p_up, prev_mask, start - 2, start, 1, sby);
2047
14.4k
    }
2048
38.9k
    const int n_blks = sbsz - 2 * (sby + 1 < f->sbh);
2049
38.9k
    const int end = imin(start + n_blks, f->bh);
2050
38.9k
    bytefn(dav1d_cdef_brow)(tc, p, mask, start, end, 0, sby);
2051
38.9k
}
2052
2053
15.2k
void bytefn(dav1d_filter_sbrow_resize)(Dav1dFrameContext *const f, const int sby) {
2054
15.2k
    const int sbsz = f->sb_step;
2055
15.2k
    const int y = sby * sbsz * 4;
2056
15.2k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2057
15.2k
    const pixel *const p[3] = {
2058
15.2k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2059
15.2k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2060
15.2k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2061
15.2k
    };
2062
15.2k
    pixel *const sr_p[3] = {
2063
15.2k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2064
15.2k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2065
15.2k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2066
15.2k
    };
2067
15.2k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400;
2068
51.9k
    for (int pl = 0; pl < 1 + 2 * has_chroma; pl++) {
2069
36.6k
        const int ss_ver = pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2070
36.6k
        const int h_start = 8 * !!sby >> ss_ver;
2071
36.6k
        const ptrdiff_t dst_stride = f->sr_cur.p.stride[!!pl];
2072
36.6k
        pixel *dst = sr_p[pl] - h_start * PXSTRIDE(dst_stride);
2073
36.6k
        const ptrdiff_t src_stride = f->cur.stride[!!pl];
2074
36.6k
        const pixel *src = p[pl] - h_start * PXSTRIDE(src_stride);
2075
36.6k
        const int h_end = 4 * (sbsz - 2 * (sby + 1 < f->sbh)) >> ss_ver;
2076
36.6k
        const int ss_hor = pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2077
36.6k
        const int dst_w = (f->sr_cur.p.p.w + ss_hor) >> ss_hor;
2078
36.6k
        const int src_w = (4 * f->bw + ss_hor) >> ss_hor;
2079
36.6k
        const int img_h = (f->cur.p.h - sbsz * 4 * sby + ss_ver) >> ss_ver;
2080
2081
36.6k
        f->dsp->mc.resize(dst, dst_stride, src, src_stride, dst_w,
2082
36.6k
                          imin(img_h, h_end) + h_start, src_w,
2083
36.6k
                          f->resize_step[!!pl], f->resize_start[!!pl]
2084
36.6k
                          HIGHBD_CALL_SUFFIX);
2085
36.6k
    }
2086
15.2k
}
dav1d_filter_sbrow_resize_8bpc
Line
Count
Source
2053
9.24k
void bytefn(dav1d_filter_sbrow_resize)(Dav1dFrameContext *const f, const int sby) {
2054
9.24k
    const int sbsz = f->sb_step;
2055
9.24k
    const int y = sby * sbsz * 4;
2056
9.24k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2057
9.24k
    const pixel *const p[3] = {
2058
9.24k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2059
9.24k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2060
9.24k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2061
9.24k
    };
2062
9.24k
    pixel *const sr_p[3] = {
2063
9.24k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2064
9.24k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2065
9.24k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2066
9.24k
    };
2067
9.24k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400;
2068
30.3k
    for (int pl = 0; pl < 1 + 2 * has_chroma; pl++) {
2069
21.1k
        const int ss_ver = pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2070
21.1k
        const int h_start = 8 * !!sby >> ss_ver;
2071
21.1k
        const ptrdiff_t dst_stride = f->sr_cur.p.stride[!!pl];
2072
21.1k
        pixel *dst = sr_p[pl] - h_start * PXSTRIDE(dst_stride);
2073
21.1k
        const ptrdiff_t src_stride = f->cur.stride[!!pl];
2074
21.1k
        const pixel *src = p[pl] - h_start * PXSTRIDE(src_stride);
2075
21.1k
        const int h_end = 4 * (sbsz - 2 * (sby + 1 < f->sbh)) >> ss_ver;
2076
21.1k
        const int ss_hor = pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2077
21.1k
        const int dst_w = (f->sr_cur.p.p.w + ss_hor) >> ss_hor;
2078
21.1k
        const int src_w = (4 * f->bw + ss_hor) >> ss_hor;
2079
21.1k
        const int img_h = (f->cur.p.h - sbsz * 4 * sby + ss_ver) >> ss_ver;
2080
2081
21.1k
        f->dsp->mc.resize(dst, dst_stride, src, src_stride, dst_w,
2082
21.1k
                          imin(img_h, h_end) + h_start, src_w,
2083
21.1k
                          f->resize_step[!!pl], f->resize_start[!!pl]
2084
21.1k
                          HIGHBD_CALL_SUFFIX);
2085
21.1k
    }
2086
9.24k
}
dav1d_filter_sbrow_resize_16bpc
Line
Count
Source
2053
6.01k
void bytefn(dav1d_filter_sbrow_resize)(Dav1dFrameContext *const f, const int sby) {
2054
6.01k
    const int sbsz = f->sb_step;
2055
6.01k
    const int y = sby * sbsz * 4;
2056
6.01k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2057
6.01k
    const pixel *const p[3] = {
2058
6.01k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2059
6.01k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2060
6.01k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2061
6.01k
    };
2062
6.01k
    pixel *const sr_p[3] = {
2063
6.01k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2064
6.01k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2065
6.01k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2066
6.01k
    };
2067
6.01k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400;
2068
21.5k
    for (int pl = 0; pl < 1 + 2 * has_chroma; pl++) {
2069
15.5k
        const int ss_ver = pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2070
15.5k
        const int h_start = 8 * !!sby >> ss_ver;
2071
15.5k
        const ptrdiff_t dst_stride = f->sr_cur.p.stride[!!pl];
2072
15.5k
        pixel *dst = sr_p[pl] - h_start * PXSTRIDE(dst_stride);
2073
15.5k
        const ptrdiff_t src_stride = f->cur.stride[!!pl];
2074
15.5k
        const pixel *src = p[pl] - h_start * PXSTRIDE(src_stride);
2075
15.5k
        const int h_end = 4 * (sbsz - 2 * (sby + 1 < f->sbh)) >> ss_ver;
2076
15.5k
        const int ss_hor = pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2077
15.5k
        const int dst_w = (f->sr_cur.p.p.w + ss_hor) >> ss_hor;
2078
15.5k
        const int src_w = (4 * f->bw + ss_hor) >> ss_hor;
2079
15.5k
        const int img_h = (f->cur.p.h - sbsz * 4 * sby + ss_ver) >> ss_ver;
2080
2081
15.5k
        f->dsp->mc.resize(dst, dst_stride, src, src_stride, dst_w,
2082
15.5k
                          imin(img_h, h_end) + h_start, src_w,
2083
15.5k
                          f->resize_step[!!pl], f->resize_start[!!pl]
2084
15.5k
                          HIGHBD_CALL_SUFFIX);
2085
15.5k
    }
2086
6.01k
}
2087
2088
104k
void bytefn(dav1d_filter_sbrow_lr)(Dav1dFrameContext *const f, const int sby) {
2089
104k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_RESTORATION)) return;
2090
104k
    const int y = sby * f->sb_step * 4;
2091
104k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2092
104k
    pixel *const sr_p[3] = {
2093
104k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2094
104k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2095
104k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2096
104k
    };
2097
104k
    bytefn(dav1d_lr_sbrow)(f, sr_p, sby);
2098
104k
}
dav1d_filter_sbrow_lr_8bpc
Line
Count
Source
2088
54.8k
void bytefn(dav1d_filter_sbrow_lr)(Dav1dFrameContext *const f, const int sby) {
2089
54.8k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_RESTORATION)) return;
2090
54.8k
    const int y = sby * f->sb_step * 4;
2091
54.8k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2092
54.8k
    pixel *const sr_p[3] = {
2093
54.8k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2094
54.8k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2095
54.8k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2096
54.8k
    };
2097
54.8k
    bytefn(dav1d_lr_sbrow)(f, sr_p, sby);
2098
54.8k
}
dav1d_filter_sbrow_lr_16bpc
Line
Count
Source
2088
49.5k
void bytefn(dav1d_filter_sbrow_lr)(Dav1dFrameContext *const f, const int sby) {
2089
49.5k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_RESTORATION)) return;
2090
49.5k
    const int y = sby * f->sb_step * 4;
2091
49.5k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2092
49.5k
    pixel *const sr_p[3] = {
2093
49.5k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2094
49.5k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2095
49.5k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2096
49.5k
    };
2097
49.5k
    bytefn(dav1d_lr_sbrow)(f, sr_p, sby);
2098
49.5k
}
2099
2100
0
void bytefn(dav1d_filter_sbrow)(Dav1dFrameContext *const f, const int sby) {
2101
0
    bytefn(dav1d_filter_sbrow_deblock_cols)(f, sby);
2102
0
    bytefn(dav1d_filter_sbrow_deblock_rows)(f, sby);
2103
0
    if (f->seq_hdr->cdef)
2104
0
        bytefn(dav1d_filter_sbrow_cdef)(f->c->tc, sby);
2105
0
    if (f->frame_hdr->width[0] != f->frame_hdr->width[1])
2106
0
        bytefn(dav1d_filter_sbrow_resize)(f, sby);
2107
0
    if (f->lf.restore_planes)
2108
0
        bytefn(dav1d_filter_sbrow_lr)(f, sby);
2109
0
}
Unexecuted instantiation: dav1d_filter_sbrow_8bpc
Unexecuted instantiation: dav1d_filter_sbrow_16bpc
2110
2111
172k
void bytefn(dav1d_backup_ipred_edge)(Dav1dTaskContext *const t) {
2112
172k
    const Dav1dFrameContext *const f = t->f;
2113
172k
    Dav1dTileState *const ts = t->ts;
2114
172k
    const int sby = t->by >> f->sb_shift;
2115
172k
    const int sby_off = f->sb128w * 128 * sby;
2116
172k
    const int x_off = ts->tiling.col_start;
2117
2118
172k
    const pixel *const y =
2119
172k
        ((const pixel *) f->cur.data[0]) + x_off * 4 +
2120
172k
                    ((t->by + f->sb_step) * 4 - 1) * PXSTRIDE(f->cur.stride[0]);
2121
172k
    pixel_copy(&f->ipred_edge[0][sby_off + x_off * 4], y,
2122
172k
               4 * (ts->tiling.col_end - x_off));
2123
2124
172k
    if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
2125
141k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2126
141k
        const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2127
2128
141k
        const ptrdiff_t uv_off = (x_off * 4 >> ss_hor) +
2129
141k
            (((t->by + f->sb_step) * 4 >> ss_ver) - 1) * PXSTRIDE(f->cur.stride[1]);
2130
423k
        for (int pl = 1; pl <= 2; pl++)
2131
282k
            pixel_copy(&f->ipred_edge[pl][sby_off + (x_off * 4 >> ss_hor)],
2132
147k
                       &((const pixel *) f->cur.data[pl])[uv_off],
2133
147k
                       4 * (ts->tiling.col_end - x_off) >> ss_hor);
2134
141k
    }
2135
172k
}
dav1d_backup_ipred_edge_8bpc
Line
Count
Source
2111
91.0k
void bytefn(dav1d_backup_ipred_edge)(Dav1dTaskContext *const t) {
2112
91.0k
    const Dav1dFrameContext *const f = t->f;
2113
91.0k
    Dav1dTileState *const ts = t->ts;
2114
91.0k
    const int sby = t->by >> f->sb_shift;
2115
91.0k
    const int sby_off = f->sb128w * 128 * sby;
2116
91.0k
    const int x_off = ts->tiling.col_start;
2117
2118
91.0k
    const pixel *const y =
2119
91.0k
        ((const pixel *) f->cur.data[0]) + x_off * 4 +
2120
91.0k
                    ((t->by + f->sb_step) * 4 - 1) * PXSTRIDE(f->cur.stride[0]);
2121
91.0k
    pixel_copy(&f->ipred_edge[0][sby_off + x_off * 4], y,
2122
91.0k
               4 * (ts->tiling.col_end - x_off));
2123
2124
91.0k
    if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
2125
73.6k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2126
73.6k
        const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2127
2128
73.6k
        const ptrdiff_t uv_off = (x_off * 4 >> ss_hor) +
2129
73.6k
            (((t->by + f->sb_step) * 4 >> ss_ver) - 1) * PXSTRIDE(f->cur.stride[1]);
2130
220k
        for (int pl = 1; pl <= 2; pl++)
2131
147k
            pixel_copy(&f->ipred_edge[pl][sby_off + (x_off * 4 >> ss_hor)],
2132
147k
                       &((const pixel *) f->cur.data[pl])[uv_off],
2133
147k
                       4 * (ts->tiling.col_end - x_off) >> ss_hor);
2134
73.6k
    }
2135
91.0k
}
dav1d_backup_ipred_edge_16bpc
Line
Count
Source
2111
81.8k
void bytefn(dav1d_backup_ipred_edge)(Dav1dTaskContext *const t) {
2112
81.8k
    const Dav1dFrameContext *const f = t->f;
2113
81.8k
    Dav1dTileState *const ts = t->ts;
2114
81.8k
    const int sby = t->by >> f->sb_shift;
2115
81.8k
    const int sby_off = f->sb128w * 128 * sby;
2116
81.8k
    const int x_off = ts->tiling.col_start;
2117
2118
81.8k
    const pixel *const y =
2119
81.8k
        ((const pixel *) f->cur.data[0]) + x_off * 4 +
2120
81.8k
                    ((t->by + f->sb_step) * 4 - 1) * PXSTRIDE(f->cur.stride[0]);
2121
81.8k
    pixel_copy(&f->ipred_edge[0][sby_off + x_off * 4], y,
2122
81.8k
               4 * (ts->tiling.col_end - x_off));
2123
2124
81.8k
    if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
2125
67.5k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2126
67.5k
        const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2127
2128
67.5k
        const ptrdiff_t uv_off = (x_off * 4 >> ss_hor) +
2129
67.5k
            (((t->by + f->sb_step) * 4 >> ss_ver) - 1) * PXSTRIDE(f->cur.stride[1]);
2130
202k
        for (int pl = 1; pl <= 2; pl++)
2131
135k
            pixel_copy(&f->ipred_edge[pl][sby_off + (x_off * 4 >> ss_hor)],
2132
67.5k
                       &((const pixel *) f->cur.data[pl])[uv_off],
2133
67.5k
                       4 * (ts->tiling.col_end - x_off) >> ss_hor);
2134
67.5k
    }
2135
81.8k
}
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
25.9k
{
2142
25.9k
    const Dav1dFrameContext *const f = t->f;
2143
25.9k
    pixel *const pal = t->frame_thread.pass ?
2144
25.9k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2145
25.9k
                            ((t->bx >> 1) + (t->by & 1))][0] :
2146
25.9k
        bytefn(t->scratch.pal)[0];
2147
123k
    for (int x = 0; x < bw4; x++)
2148
97.2k
        memcpy(bytefn(t->al_pal)[0][bx4 + x][0], pal, 8 * sizeof(pixel));
2149
107k
    for (int y = 0; y < bh4; y++)
2150
81.1k
        memcpy(bytefn(t->al_pal)[1][by4 + y][0], pal, 8 * sizeof(pixel));
2151
25.9k
}
dav1d_copy_pal_block_y_8bpc
Line
Count
Source
2141
12.1k
{
2142
12.1k
    const Dav1dFrameContext *const f = t->f;
2143
12.1k
    pixel *const pal = t->frame_thread.pass ?
2144
12.1k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2145
12.1k
                            ((t->bx >> 1) + (t->by & 1))][0] :
2146
12.1k
        bytefn(t->scratch.pal)[0];
2147
55.0k
    for (int x = 0; x < bw4; x++)
2148
42.8k
        memcpy(bytefn(t->al_pal)[0][bx4 + x][0], pal, 8 * sizeof(pixel));
2149
49.1k
    for (int y = 0; y < bh4; y++)
2150
36.9k
        memcpy(bytefn(t->al_pal)[1][by4 + y][0], pal, 8 * sizeof(pixel));
2151
12.1k
}
dav1d_copy_pal_block_y_16bpc
Line
Count
Source
2141
13.7k
{
2142
13.7k
    const Dav1dFrameContext *const f = t->f;
2143
13.7k
    pixel *const pal = t->frame_thread.pass ?
2144
13.7k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2145
13.7k
                            ((t->bx >> 1) + (t->by & 1))][0] :
2146
13.7k
        bytefn(t->scratch.pal)[0];
2147
68.1k
    for (int x = 0; x < bw4; x++)
2148
54.3k
        memcpy(bytefn(t->al_pal)[0][bx4 + x][0], pal, 8 * sizeof(pixel));
2149
57.9k
    for (int y = 0; y < bh4; y++)
2150
44.1k
        memcpy(bytefn(t->al_pal)[1][by4 + y][0], pal, 8 * sizeof(pixel));
2151
13.7k
}
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
7.15k
{
2158
7.15k
    const Dav1dFrameContext *const f = t->f;
2159
7.15k
    const pixel (*const pal)[8] = t->frame_thread.pass ?
2160
7.15k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2161
7.15k
                            ((t->bx >> 1) + (t->by & 1))] :
2162
7.15k
        bytefn(t->scratch.pal);
2163
    // see aomedia bug 2183 for why we use luma coordinates here
2164
21.4k
    for (int pl = 1; pl <= 2; pl++) {
2165
79.3k
        for (int x = 0; x < bw4; x++)
2166
64.9k
            memcpy(bytefn(t->al_pal)[0][bx4 + x][pl], pal[pl], 8 * sizeof(pixel));
2167
74.4k
        for (int y = 0; y < bh4; y++)
2168
60.1k
            memcpy(bytefn(t->al_pal)[1][by4 + y][pl], pal[pl], 8 * sizeof(pixel));
2169
14.3k
    }
2170
7.15k
}
dav1d_copy_pal_block_uv_8bpc
Line
Count
Source
2157
2.16k
{
2158
2.16k
    const Dav1dFrameContext *const f = t->f;
2159
2.16k
    const pixel (*const pal)[8] = t->frame_thread.pass ?
2160
2.16k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2161
2.16k
                            ((t->bx >> 1) + (t->by & 1))] :
2162
2.16k
        bytefn(t->scratch.pal);
2163
    // see aomedia bug 2183 for why we use luma coordinates here
2164
6.49k
    for (int pl = 1; pl <= 2; pl++) {
2165
24.6k
        for (int x = 0; x < bw4; x++)
2166
20.3k
            memcpy(bytefn(t->al_pal)[0][bx4 + x][pl], pal[pl], 8 * sizeof(pixel));
2167
23.6k
        for (int y = 0; y < bh4; y++)
2168
19.3k
            memcpy(bytefn(t->al_pal)[1][by4 + y][pl], pal[pl], 8 * sizeof(pixel));
2169
4.33k
    }
2170
2.16k
}
dav1d_copy_pal_block_uv_16bpc
Line
Count
Source
2157
4.99k
{
2158
4.99k
    const Dav1dFrameContext *const f = t->f;
2159
4.99k
    const pixel (*const pal)[8] = t->frame_thread.pass ?
2160
4.99k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2161
4.99k
                            ((t->bx >> 1) + (t->by & 1))] :
2162
4.99k
        bytefn(t->scratch.pal);
2163
    // see aomedia bug 2183 for why we use luma coordinates here
2164
14.9k
    for (int pl = 1; pl <= 2; pl++) {
2165
54.6k
        for (int x = 0; x < bw4; x++)
2166
44.6k
            memcpy(bytefn(t->al_pal)[0][bx4 + x][pl], pal[pl], 8 * sizeof(pixel));
2167
50.7k
        for (int y = 0; y < bh4; y++)
2168
40.7k
            memcpy(bytefn(t->al_pal)[1][by4 + y][pl], pal[pl], 8 * sizeof(pixel));
2169
9.98k
    }
2170
4.99k
}
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
33.1k
{
2176
33.1k
    Dav1dTileState *const ts = t->ts;
2177
33.1k
    const Dav1dFrameContext *const f = t->f;
2178
33.1k
    const int pal_sz = b->pal_sz[pl] = dav1d_msac_decode_symbol_adapt8(&ts->msac,
2179
33.1k
                                           ts->cdf.m.pal_sz[pl][sz_ctx], 6) + 2;
2180
33.1k
    pixel cache[16], used_cache[8];
2181
33.1k
    int l_cache = pl ? t->pal_sz_uv[1][by4] : t->l.pal_sz[by4];
2182
33.1k
    int n_cache = 0;
2183
    // don't reuse above palette outside SB64 boundaries
2184
33.1k
    int a_cache = by4 & 15 ? pl ? t->pal_sz_uv[0][bx4] : t->a->pal_sz[bx4] : 0;
2185
33.1k
    const pixel *l = bytefn(t->al_pal)[1][by4][pl];
2186
33.1k
    const pixel *a = bytefn(t->al_pal)[0][bx4][pl];
2187
2188
    // fill/sort cache
2189
56.4k
    while (l_cache && a_cache) {
2190
23.3k
        if (*l < *a) {
2191
8.64k
            if (!n_cache || cache[n_cache - 1] != *l)
2192
8.57k
                cache[n_cache++] = *l;
2193
8.64k
            l++;
2194
8.64k
            l_cache--;
2195
14.6k
        } else {
2196
14.6k
            if (*a == *l) {
2197
5.56k
                l++;
2198
5.56k
                l_cache--;
2199
5.56k
            }
2200
14.6k
            if (!n_cache || cache[n_cache - 1] != *a)
2201
14.2k
                cache[n_cache++] = *a;
2202
14.6k
            a++;
2203
14.6k
            a_cache--;
2204
14.6k
        }
2205
23.3k
    }
2206
33.1k
    if (l_cache) {
2207
40.8k
        do {
2208
40.8k
            if (!n_cache || cache[n_cache - 1] != *l)
2209
33.2k
                cache[n_cache++] = *l;
2210
40.8k
            l++;
2211
40.8k
        } while (--l_cache > 0);
2212
23.2k
    } else if (a_cache) {
2213
31.3k
        do {
2214
31.3k
            if (!n_cache || cache[n_cache - 1] != *a)
2215
25.0k
                cache[n_cache++] = *a;
2216
31.3k
            a++;
2217
31.3k
        } while (--a_cache > 0);
2218
7.66k
    }
2219
2220
    // find reused cache entries
2221
33.1k
    int i = 0;
2222
104k
    for (int n = 0; n < n_cache && i < pal_sz; n++)
2223
71.6k
        if (dav1d_msac_decode_bool_equi(&ts->msac))
2224
35.6k
            used_cache[i++] = cache[n];
2225
33.1k
    const int n_used_cache = i;
2226
2227
    // parse new entries
2228
33.1k
    pixel *const pal = t->frame_thread.pass ?
2229
33.1k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2230
33.1k
                            ((t->bx >> 1) + (t->by & 1))][pl] :
2231
33.1k
        bytefn(t->scratch.pal)[pl];
2232
33.1k
    if (i < pal_sz) {
2233
28.5k
        const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2234
28.5k
        int prev = pal[i++] = dav1d_msac_decode_bools(&ts->msac, bpc);
2235
2236
28.5k
        if (i < pal_sz) {
2237
25.8k
            int bits = bpc - 3 + dav1d_msac_decode_bools(&ts->msac, 2);
2238
25.8k
            const int max = (1 << bpc) - 1;
2239
2240
60.7k
            do {
2241
60.7k
                const int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2242
60.7k
                prev = pal[i++] = imin(prev + delta + !pl, max);
2243
60.7k
                if (prev + !pl >= max) {
2244
34.0k
                    for (; i < pal_sz; i++)
2245
22.1k
                        pal[i] = max;
2246
11.8k
                    break;
2247
11.8k
                }
2248
48.8k
                bits = imin(bits, 1 + ulog2(max - prev - !pl));
2249
48.8k
            } while (i < pal_sz);
2250
25.8k
        }
2251
2252
        // merge cache+new entries
2253
28.5k
        int n = 0, m = n_used_cache;
2254
163k
        for (i = 0; i < pal_sz; i++) {
2255
134k
            if (n < n_used_cache && (m >= pal_sz || used_cache[n] <= pal[m])) {
2256
23.4k
                pal[i] = used_cache[n++];
2257
111k
            } else {
2258
111k
                assert(m < pal_sz);
2259
111k
                pal[i] = pal[m++];
2260
111k
            }
2261
134k
        }
2262
28.5k
    } else {
2263
4.60k
        memcpy(pal, used_cache, n_used_cache * sizeof(*used_cache));
2264
4.60k
    }
2265
2266
33.1k
    if (DEBUG_BLOCK_INFO) {
2267
0
        printf("Post-pal[pl=%d,sz=%d,cache_size=%d,used_cache=%d]: r=%d, cache=",
2268
0
               pl, pal_sz, n_cache, n_used_cache, ts->msac.rng);
2269
0
        for (int n = 0; n < n_cache; n++)
2270
0
            printf("%c%02x", n ? ' ' : '[', cache[n]);
2271
0
        printf("%s, pal=", n_cache ? "]" : "[]");
2272
0
        for (int n = 0; n < pal_sz; n++)
2273
0
            printf("%c%02x", n ? ' ' : '[', pal[n]);
2274
0
        printf("]\n");
2275
0
    }
2276
33.1k
}
dav1d_read_pal_plane_8bpc
Line
Count
Source
2175
14.3k
{
2176
14.3k
    Dav1dTileState *const ts = t->ts;
2177
14.3k
    const Dav1dFrameContext *const f = t->f;
2178
14.3k
    const int pal_sz = b->pal_sz[pl] = dav1d_msac_decode_symbol_adapt8(&ts->msac,
2179
14.3k
                                           ts->cdf.m.pal_sz[pl][sz_ctx], 6) + 2;
2180
14.3k
    pixel cache[16], used_cache[8];
2181
14.3k
    int l_cache = pl ? t->pal_sz_uv[1][by4] : t->l.pal_sz[by4];
2182
14.3k
    int n_cache = 0;
2183
    // don't reuse above palette outside SB64 boundaries
2184
14.3k
    int a_cache = by4 & 15 ? pl ? t->pal_sz_uv[0][bx4] : t->a->pal_sz[bx4] : 0;
2185
14.3k
    const pixel *l = bytefn(t->al_pal)[1][by4][pl];
2186
14.3k
    const pixel *a = bytefn(t->al_pal)[0][bx4][pl];
2187
2188
    // fill/sort cache
2189
23.0k
    while (l_cache && a_cache) {
2190
8.65k
        if (*l < *a) {
2191
3.09k
            if (!n_cache || cache[n_cache - 1] != *l)
2192
3.05k
                cache[n_cache++] = *l;
2193
3.09k
            l++;
2194
3.09k
            l_cache--;
2195
5.56k
        } else {
2196
5.56k
            if (*a == *l) {
2197
2.23k
                l++;
2198
2.23k
                l_cache--;
2199
2.23k
            }
2200
5.56k
            if (!n_cache || cache[n_cache - 1] != *a)
2201
5.27k
                cache[n_cache++] = *a;
2202
5.56k
            a++;
2203
5.56k
            a_cache--;
2204
5.56k
        }
2205
8.65k
    }
2206
14.3k
    if (l_cache) {
2207
17.8k
        do {
2208
17.8k
            if (!n_cache || cache[n_cache - 1] != *l)
2209
14.2k
                cache[n_cache++] = *l;
2210
17.8k
            l++;
2211
17.8k
        } while (--l_cache > 0);
2212
10.1k
    } else if (a_cache) {
2213
13.7k
        do {
2214
13.7k
            if (!n_cache || cache[n_cache - 1] != *a)
2215
11.0k
                cache[n_cache++] = *a;
2216
13.7k
            a++;
2217
13.7k
        } while (--a_cache > 0);
2218
3.36k
    }
2219
2220
    // find reused cache entries
2221
14.3k
    int i = 0;
2222
44.3k
    for (int n = 0; n < n_cache && i < pal_sz; n++)
2223
29.9k
        if (dav1d_msac_decode_bool_equi(&ts->msac))
2224
15.0k
            used_cache[i++] = cache[n];
2225
14.3k
    const int n_used_cache = i;
2226
2227
    // parse new entries
2228
14.3k
    pixel *const pal = t->frame_thread.pass ?
2229
14.3k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2230
14.3k
                            ((t->bx >> 1) + (t->by & 1))][pl] :
2231
14.3k
        bytefn(t->scratch.pal)[pl];
2232
14.3k
    if (i < pal_sz) {
2233
12.5k
        const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2234
12.5k
        int prev = pal[i++] = dav1d_msac_decode_bools(&ts->msac, bpc);
2235
2236
12.5k
        if (i < pal_sz) {
2237
11.3k
            int bits = bpc - 3 + dav1d_msac_decode_bools(&ts->msac, 2);
2238
11.3k
            const int max = (1 << bpc) - 1;
2239
2240
26.9k
            do {
2241
26.9k
                const int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2242
26.9k
                prev = pal[i++] = imin(prev + delta + !pl, max);
2243
26.9k
                if (prev + !pl >= max) {
2244
15.8k
                    for (; i < pal_sz; i++)
2245
10.4k
                        pal[i] = max;
2246
5.40k
                    break;
2247
5.40k
                }
2248
21.5k
                bits = imin(bits, 1 + ulog2(max - prev - !pl));
2249
21.5k
            } while (i < pal_sz);
2250
11.3k
        }
2251
2252
        // merge cache+new entries
2253
12.5k
        int n = 0, m = n_used_cache;
2254
72.5k
        for (i = 0; i < pal_sz; i++) {
2255
60.0k
            if (n < n_used_cache && (m >= pal_sz || used_cache[n] <= pal[m])) {
2256
10.1k
                pal[i] = used_cache[n++];
2257
49.9k
            } else {
2258
49.9k
                assert(m < pal_sz);
2259
49.9k
                pal[i] = pal[m++];
2260
49.9k
            }
2261
60.0k
        }
2262
12.5k
    } else {
2263
1.83k
        memcpy(pal, used_cache, n_used_cache * sizeof(*used_cache));
2264
1.83k
    }
2265
2266
14.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
14.3k
}
dav1d_read_pal_plane_16bpc
Line
Count
Source
2175
18.7k
{
2176
18.7k
    Dav1dTileState *const ts = t->ts;
2177
18.7k
    const Dav1dFrameContext *const f = t->f;
2178
18.7k
    const int pal_sz = b->pal_sz[pl] = dav1d_msac_decode_symbol_adapt8(&ts->msac,
2179
18.7k
                                           ts->cdf.m.pal_sz[pl][sz_ctx], 6) + 2;
2180
18.7k
    pixel cache[16], used_cache[8];
2181
18.7k
    int l_cache = pl ? t->pal_sz_uv[1][by4] : t->l.pal_sz[by4];
2182
18.7k
    int n_cache = 0;
2183
    // don't reuse above palette outside SB64 boundaries
2184
18.7k
    int a_cache = by4 & 15 ? pl ? t->pal_sz_uv[0][bx4] : t->a->pal_sz[bx4] : 0;
2185
18.7k
    const pixel *l = bytefn(t->al_pal)[1][by4][pl];
2186
18.7k
    const pixel *a = bytefn(t->al_pal)[0][bx4][pl];
2187
2188
    // fill/sort cache
2189
33.4k
    while (l_cache && a_cache) {
2190
14.6k
        if (*l < *a) {
2191
5.54k
            if (!n_cache || cache[n_cache - 1] != *l)
2192
5.51k
                cache[n_cache++] = *l;
2193
5.54k
            l++;
2194
5.54k
            l_cache--;
2195
9.13k
        } else {
2196
9.13k
            if (*a == *l) {
2197
3.32k
                l++;
2198
3.32k
                l_cache--;
2199
3.32k
            }
2200
9.13k
            if (!n_cache || cache[n_cache - 1] != *a)
2201
8.92k
                cache[n_cache++] = *a;
2202
9.13k
            a++;
2203
9.13k
            a_cache--;
2204
9.13k
        }
2205
14.6k
    }
2206
18.7k
    if (l_cache) {
2207
22.9k
        do {
2208
22.9k
            if (!n_cache || cache[n_cache - 1] != *l)
2209
19.0k
                cache[n_cache++] = *l;
2210
22.9k
            l++;
2211
22.9k
        } while (--l_cache > 0);
2212
13.0k
    } else if (a_cache) {
2213
17.5k
        do {
2214
17.5k
            if (!n_cache || cache[n_cache - 1] != *a)
2215
13.9k
                cache[n_cache++] = *a;
2216
17.5k
            a++;
2217
17.5k
        } while (--a_cache > 0);
2218
4.29k
    }
2219
2220
    // find reused cache entries
2221
18.7k
    int i = 0;
2222
60.4k
    for (int n = 0; n < n_cache && i < pal_sz; n++)
2223
41.7k
        if (dav1d_msac_decode_bool_equi(&ts->msac))
2224
20.6k
            used_cache[i++] = cache[n];
2225
18.7k
    const int n_used_cache = i;
2226
2227
    // parse new entries
2228
18.7k
    pixel *const pal = t->frame_thread.pass ?
2229
18.7k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2230
18.7k
                            ((t->bx >> 1) + (t->by & 1))][pl] :
2231
18.7k
        bytefn(t->scratch.pal)[pl];
2232
18.7k
    if (i < pal_sz) {
2233
15.9k
        const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2234
15.9k
        int prev = pal[i++] = dav1d_msac_decode_bools(&ts->msac, bpc);
2235
2236
15.9k
        if (i < pal_sz) {
2237
14.5k
            int bits = bpc - 3 + dav1d_msac_decode_bools(&ts->msac, 2);
2238
14.5k
            const int max = (1 << bpc) - 1;
2239
2240
33.7k
            do {
2241
33.7k
                const int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2242
33.7k
                prev = pal[i++] = imin(prev + delta + !pl, max);
2243
33.7k
                if (prev + !pl >= max) {
2244
18.2k
                    for (; i < pal_sz; i++)
2245
11.7k
                        pal[i] = max;
2246
6.47k
                    break;
2247
6.47k
                }
2248
27.3k
                bits = imin(bits, 1 + ulog2(max - prev - !pl));
2249
27.3k
            } while (i < pal_sz);
2250
14.5k
        }
2251
2252
        // merge cache+new entries
2253
15.9k
        int n = 0, m = n_used_cache;
2254
90.8k
        for (i = 0; i < pal_sz; i++) {
2255
74.8k
            if (n < n_used_cache && (m >= pal_sz || used_cache[n] <= pal[m])) {
2256
13.3k
                pal[i] = used_cache[n++];
2257
61.5k
            } else {
2258
61.5k
                assert(m < pal_sz);
2259
61.5k
                pal[i] = pal[m++];
2260
61.5k
            }
2261
74.8k
        }
2262
15.9k
    } else {
2263
2.76k
        memcpy(pal, used_cache, n_used_cache * sizeof(*used_cache));
2264
2.76k
    }
2265
2266
18.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
18.7k
}
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
7.15k
{
2281
7.15k
    bytefn(dav1d_read_pal_plane)(t, b, 1, sz_ctx, bx4, by4);
2282
2283
    // V pal coding
2284
7.15k
    Dav1dTileState *const ts = t->ts;
2285
7.15k
    const Dav1dFrameContext *const f = t->f;
2286
7.15k
    pixel *const pal = t->frame_thread.pass ?
2287
7.15k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2288
7.15k
                            ((t->bx >> 1) + (t->by & 1))][2] :
2289
7.15k
        bytefn(t->scratch.pal)[2];
2290
7.15k
    const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2291
7.15k
    if (dav1d_msac_decode_bool_equi(&ts->msac)) {
2292
3.47k
        const int bits = bpc - 4 + dav1d_msac_decode_bools(&ts->msac, 2);
2293
3.47k
        int prev = pal[0] = dav1d_msac_decode_bools(&ts->msac, bpc);
2294
3.47k
        const int max = (1 << bpc) - 1;
2295
14.3k
        for (int i = 1; i < b->pal_sz[1]; i++) {
2296
10.8k
            int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2297
10.8k
            if (delta && dav1d_msac_decode_bool_equi(&ts->msac)) delta = -delta;
2298
10.8k
            prev = pal[i] = (prev + delta) & max;
2299
10.8k
        }
2300
3.67k
    } else {
2301
18.4k
        for (int i = 0; i < b->pal_sz[1]; i++)
2302
14.8k
            pal[i] = dav1d_msac_decode_bools(&ts->msac, bpc);
2303
3.67k
    }
2304
7.15k
    if (DEBUG_BLOCK_INFO) {
2305
0
        printf("Post-pal[pl=2]: r=%d ", ts->msac.rng);
2306
0
        for (int n = 0; n < b->pal_sz[1]; n++)
2307
0
            printf("%c%02x", n ? ' ' : '[', pal[n]);
2308
0
        printf("]\n");
2309
0
    }
2310
7.15k
}
dav1d_read_pal_uv_8bpc
Line
Count
Source
2280
2.16k
{
2281
2.16k
    bytefn(dav1d_read_pal_plane)(t, b, 1, sz_ctx, bx4, by4);
2282
2283
    // V pal coding
2284
2.16k
    Dav1dTileState *const ts = t->ts;
2285
2.16k
    const Dav1dFrameContext *const f = t->f;
2286
2.16k
    pixel *const pal = t->frame_thread.pass ?
2287
2.16k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2288
2.16k
                            ((t->bx >> 1) + (t->by & 1))][2] :
2289
2.16k
        bytefn(t->scratch.pal)[2];
2290
2.16k
    const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2291
2.16k
    if (dav1d_msac_decode_bool_equi(&ts->msac)) {
2292
970
        const int bits = bpc - 4 + dav1d_msac_decode_bools(&ts->msac, 2);
2293
970
        int prev = pal[0] = dav1d_msac_decode_bools(&ts->msac, bpc);
2294
970
        const int max = (1 << bpc) - 1;
2295
4.13k
        for (int i = 1; i < b->pal_sz[1]; i++) {
2296
3.16k
            int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2297
3.16k
            if (delta && dav1d_msac_decode_bool_equi(&ts->msac)) delta = -delta;
2298
3.16k
            prev = pal[i] = (prev + delta) & max;
2299
3.16k
        }
2300
1.19k
    } else {
2301
6.18k
        for (int i = 0; i < b->pal_sz[1]; i++)
2302
4.98k
            pal[i] = dav1d_msac_decode_bools(&ts->msac, bpc);
2303
1.19k
    }
2304
2.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
2.16k
}
dav1d_read_pal_uv_16bpc
Line
Count
Source
2280
4.99k
{
2281
4.99k
    bytefn(dav1d_read_pal_plane)(t, b, 1, sz_ctx, bx4, by4);
2282
2283
    // V pal coding
2284
4.99k
    Dav1dTileState *const ts = t->ts;
2285
4.99k
    const Dav1dFrameContext *const f = t->f;
2286
4.99k
    pixel *const pal = t->frame_thread.pass ?
2287
4.99k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2288
4.99k
                            ((t->bx >> 1) + (t->by & 1))][2] :
2289
4.99k
        bytefn(t->scratch.pal)[2];
2290
4.99k
    const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2291
4.99k
    if (dav1d_msac_decode_bool_equi(&ts->msac)) {
2292
2.50k
        const int bits = bpc - 4 + dav1d_msac_decode_bools(&ts->msac, 2);
2293
2.50k
        int prev = pal[0] = dav1d_msac_decode_bools(&ts->msac, bpc);
2294
2.50k
        const int max = (1 << bpc) - 1;
2295
10.2k
        for (int i = 1; i < b->pal_sz[1]; i++) {
2296
7.69k
            int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2297
7.69k
            if (delta && dav1d_msac_decode_bool_equi(&ts->msac)) delta = -delta;
2298
7.69k
            prev = pal[i] = (prev + delta) & max;
2299
7.69k
        }
2300
2.50k
    } else {
2301
12.3k
        for (int i = 0; i < b->pal_sz[1]; i++)
2302
9.82k
            pal[i] = dav1d_msac_decode_bools(&ts->msac, bpc);
2303
2.48k
    }
2304
4.99k
    if (DEBUG_BLOCK_INFO) {
2305
0
        printf("Post-pal[pl=2]: r=%d ", ts->msac.rng);
2306
0
        for (int n = 0; n < b->pal_sz[1]; n++)
2307
0
            printf("%c%02x", n ? ' ' : '[', pal[n]);
2308
0
        printf("]\n");
2309
0
    }
2310
4.99k
}