Coverage Report

Created: 2026-07-30 06:25

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
456k
static inline unsigned read_golomb(MsacContext *const msac) {
50
456k
    int len = 0;
51
456k
    unsigned val = 1;
52
53
790k
    while (!dav1d_msac_decode_bool_equi(msac) && len < 32) len++;
54
789k
    while (len--) val = (val << 1) + dav1d_msac_decode_bool_equi(msac);
55
56
456k
    return val - 1;
57
456k
}
58
59
static inline unsigned get_skip_ctx(const TxfmInfo *const t_dim,
60
                                    const enum BlockSize bs,
61
                                    const uint8_t *const a,
62
                                    const uint8_t *const l,
63
                                    const int chroma,
64
                                    const enum Dav1dPixelLayout layout)
65
4.76M
{
66
4.76M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
67
68
4.76M
    if (chroma) {
69
2.51M
        const int ss_ver = layout == DAV1D_PIXEL_LAYOUT_I420;
70
2.51M
        const int ss_hor = layout != DAV1D_PIXEL_LAYOUT_I444;
71
2.51M
        const int not_one_blk = b_dim[2] - (!!b_dim[2] && ss_hor) > t_dim->lw ||
72
1.53M
                                b_dim[3] - (!!b_dim[3] && ss_ver) > t_dim->lh;
73
2.51M
        unsigned ca, cl;
74
75
2.51M
#define MERGE_CTX(dir, type, no_val) \
76
5.04M
        c##dir = *(const type *) dir != no_val; \
77
5.04M
        break
78
79
2.51M
        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
918k
        case TX_4X4:   MERGE_CTX(a, uint8_t,  0x40);
87
497k
        case TX_8X8:   MERGE_CTX(a, uint16_t, 0x4040);
88
365k
        case TX_16X16: MERGE_CTX(a, uint32_t, 0x40404040U);
89
740k
        case TX_32X32: MERGE_CTX(a, uint64_t, 0x4040404040404040ULL);
90
2.51M
        }
91
2.51M
        switch (t_dim->lh) {
92
0
        default: assert(0); /* fall-through */
93
1.03M
        case TX_4X4:   MERGE_CTX(l, uint8_t,  0x40);
94
477k
        case TX_8X8:   MERGE_CTX(l, uint16_t, 0x4040);
95
285k
        case TX_16X16: MERGE_CTX(l, uint32_t, 0x40404040U);
96
720k
        case TX_32X32: MERGE_CTX(l, uint64_t, 0x4040404040404040ULL);
97
2.51M
        }
98
2.51M
#undef MERGE_CTX
99
100
2.51M
        return 7 + not_one_blk * 3 + ca + cl;
101
2.51M
    } else if (b_dim[2] == t_dim->lw && b_dim[3] == t_dim->lh) {
102
926k
        return 0;
103
1.32M
    } else {
104
1.32M
        unsigned la, ll;
105
106
1.32M
#define MERGE_CTX(dir, type, tx) \
107
2.79M
        if (tx == TX_64X64) { \
108
222k
            uint64_t tmp = *(const uint64_t *) dir; \
109
222k
            tmp |= *(const uint64_t *) &dir[8]; \
110
222k
            l##dir = (unsigned) (tmp >> 32) | (unsigned) tmp; \
111
222k
        } else \
112
2.79M
            l##dir = *(const type *) dir; \
113
2.79M
        if (tx == TX_32X32) l##dir |= *(const type *) &dir[sizeof(type)]; \
114
2.79M
        if (tx >= TX_16X16) l##dir |= l##dir >> 16; \
115
2.79M
        if (tx >= TX_8X8)   l##dir |= l##dir >> 8; \
116
2.79M
        break
117
118
1.32M
        switch (t_dim->lw) {
119
0
        default: assert(0); /* fall-through */
120
790k
        case TX_4X4:   MERGE_CTX(a, uint8_t,  TX_4X4);
121
267k
        case TX_8X8:   MERGE_CTX(a, uint16_t, TX_8X8);
122
210k
        case TX_16X16: MERGE_CTX(a, uint32_t, TX_16X16);
123
18.5k
        case TX_32X32: MERGE_CTX(a, uint32_t, TX_32X32);
124
111k
        case TX_64X64: MERGE_CTX(a, uint32_t, TX_64X64);
125
1.32M
        }
126
1.39M
        switch (t_dim->lh) {
127
0
        default: assert(0); /* fall-through */
128
800k
        case TX_4X4:   MERGE_CTX(l, uint8_t,  TX_4X4);
129
258k
        case TX_8X8:   MERGE_CTX(l, uint16_t, TX_8X8);
130
210k
        case TX_16X16: MERGE_CTX(l, uint32_t, TX_16X16);
131
19.1k
        case TX_32X32: MERGE_CTX(l, uint32_t, TX_32X32);
132
111k
        case TX_64X64: MERGE_CTX(l, uint32_t, TX_64X64);
133
1.39M
        }
134
1.39M
#undef MERGE_CTX
135
136
1.39M
        return dav1d_skip_ctx[umin(la & 0x3F, 4)][umin(ll & 0x3F, 4)];
137
1.39M
    }
138
4.76M
}
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.09M
{
144
2.09M
    uint64_t mask = 0xC0C0C0C0C0C0C0C0ULL, mul = 0x0101010101010101ULL;
145
2.09M
    int s;
146
147
2.09M
#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.09M
    __asm__("" : "+r"(mask), "+r"(mul));
151
2.09M
#endif
152
153
2.09M
    switch(tx) {
154
0
    default: assert(0); /* fall-through */
155
783k
    case TX_4X4: {
156
783k
        int t = *(const uint8_t *) a >> 6;
157
783k
        t    += *(const uint8_t *) l >> 6;
158
783k
        s = t - 1 - 1;
159
783k
        break;
160
0
    }
161
225k
    case TX_8X8: {
162
225k
        uint32_t t = *(const uint16_t *) a & (uint32_t) mask;
163
225k
        t         += *(const uint16_t *) l & (uint32_t) mask;
164
225k
        t *= 0x04040404U;
165
225k
        s = (int) (t >> 24) - 2 - 2;
166
225k
        break;
167
0
    }
168
178k
    case TX_16X16: {
169
178k
        uint32_t t = (*(const uint32_t *) a & (uint32_t) mask) >> 6;
170
178k
        t         += (*(const uint32_t *) l & (uint32_t) mask) >> 6;
171
178k
        t *= (uint32_t) mul;
172
178k
        s = (int) (t >> 24) - 4 - 4;
173
178k
        break;
174
0
    }
175
215k
    case TX_32X32: {
176
215k
        uint64_t t = (*(const uint64_t *) a & mask) >> 6;
177
215k
        t         += (*(const uint64_t *) l & mask) >> 6;
178
215k
        t *= mul;
179
215k
        s = (int) (t >> 56) - 8 - 8;
180
215k
        break;
181
0
    }
182
88.3k
    case TX_64X64: {
183
88.3k
        uint64_t t = (*(const uint64_t *) &a[0] & mask) >> 6;
184
88.3k
        t         += (*(const uint64_t *) &a[8] & mask) >> 6;
185
88.3k
        t         += (*(const uint64_t *) &l[0] & mask) >> 6;
186
88.3k
        t         += (*(const uint64_t *) &l[8] & mask) >> 6;
187
88.3k
        t *= mul;
188
88.3k
        s = (int) (t >> 56) - 16 - 16;
189
88.3k
        break;
190
0
    }
191
68.1k
    case RTX_4X8: {
192
68.1k
        uint32_t t = *(const uint8_t  *) a & (uint32_t) mask;
193
68.1k
        t         += *(const uint16_t *) l & (uint32_t) mask;
194
68.1k
        t *= 0x04040404U;
195
68.1k
        s = (int) (t >> 24) - 1 - 2;
196
68.1k
        break;
197
0
    }
198
99.6k
    case RTX_8X4: {
199
99.6k
        uint32_t t = *(const uint16_t *) a & (uint32_t) mask;
200
99.6k
        t         += *(const uint8_t  *) l & (uint32_t) mask;
201
99.6k
        t *= 0x04040404U;
202
99.6k
        s = (int) (t >> 24) - 2 - 1;
203
99.6k
        break;
204
0
    }
205
56.8k
    case RTX_8X16: {
206
56.8k
        uint32_t t = *(const uint16_t *) a & (uint32_t) mask;
207
56.8k
        t         += *(const uint32_t *) l & (uint32_t) mask;
208
56.8k
        t = (t >> 6) * (uint32_t) mul;
209
56.8k
        s = (int) (t >> 24) - 2 - 4;
210
56.8k
        break;
211
0
    }
212
108k
    case RTX_16X8: {
213
108k
        uint32_t t = *(const uint32_t *) a & (uint32_t) mask;
214
108k
        t         += *(const uint16_t *) l & (uint32_t) mask;
215
108k
        t = (t >> 6) * (uint32_t) mul;
216
108k
        s = (int) (t >> 24) - 4 - 2;
217
108k
        break;
218
0
    }
219
28.9k
    case RTX_16X32: {
220
28.9k
        uint64_t t = *(const uint32_t *) a & (uint32_t) mask;
221
28.9k
        t         += *(const uint64_t *) l & mask;
222
28.9k
        t = (t >> 6) * mul;
223
28.9k
        s = (int) (t >> 56) - 4 - 8;
224
28.9k
        break;
225
0
    }
226
48.0k
    case RTX_32X16: {
227
48.0k
        uint64_t t = *(const uint64_t *) a & mask;
228
48.0k
        t         += *(const uint32_t *) l & (uint32_t) mask;
229
48.0k
        t = (t >> 6) * mul;
230
48.0k
        s = (int) (t >> 56) - 8 - 4;
231
48.0k
        break;
232
0
    }
233
14.9k
    case RTX_32X64: {
234
14.9k
        uint64_t t = (*(const uint64_t *) &a[0] & mask) >> 6;
235
14.9k
        t         += (*(const uint64_t *) &l[0] & mask) >> 6;
236
14.9k
        t         += (*(const uint64_t *) &l[8] & mask) >> 6;
237
14.9k
        t *= mul;
238
14.9k
        s = (int) (t >> 56) - 8 - 16;
239
14.9k
        break;
240
0
    }
241
17.0k
    case RTX_64X32: {
242
17.0k
        uint64_t t = (*(const uint64_t *) &a[0] & mask) >> 6;
243
17.0k
        t         += (*(const uint64_t *) &a[8] & mask) >> 6;
244
17.0k
        t         += (*(const uint64_t *) &l[0] & mask) >> 6;
245
17.0k
        t *= mul;
246
17.0k
        s = (int) (t >> 56) - 16 - 8;
247
17.0k
        break;
248
0
    }
249
33.8k
    case RTX_4X16: {
250
33.8k
        uint32_t t = *(const uint8_t  *) a & (uint32_t) mask;
251
33.8k
        t         += *(const uint32_t *) l & (uint32_t) mask;
252
33.8k
        t = (t >> 6) * (uint32_t) mul;
253
33.8k
        s = (int) (t >> 24) - 1 - 4;
254
33.8k
        break;
255
0
    }
256
68.6k
    case RTX_16X4: {
257
68.6k
        uint32_t t = *(const uint32_t *) a & (uint32_t) mask;
258
68.6k
        t         += *(const uint8_t  *) l & (uint32_t) mask;
259
68.6k
        t = (t >> 6) * (uint32_t) mul;
260
68.6k
        s = (int) (t >> 24) - 4 - 1;
261
68.6k
        break;
262
0
    }
263
22.3k
    case RTX_8X32: {
264
22.3k
        uint64_t t = *(const uint16_t *) a & (uint32_t) mask;
265
22.3k
        t         += *(const uint64_t *) l & mask;
266
22.3k
        t = (t >> 6) * mul;
267
22.3k
        s = (int) (t >> 56) - 2 - 8;
268
22.3k
        break;
269
0
    }
270
29.4k
    case RTX_32X8: {
271
29.4k
        uint64_t t = *(const uint64_t *) a & mask;
272
29.4k
        t         += *(const uint16_t *) l & (uint32_t) mask;
273
29.4k
        t = (t >> 6) * mul;
274
29.4k
        s = (int) (t >> 56) - 8 - 2;
275
29.4k
        break;
276
0
    }
277
7.04k
    case RTX_16X64: {
278
7.04k
        uint64_t t = *(const uint32_t *) a & (uint32_t) mask;
279
7.04k
        t         += *(const uint64_t *) &l[0] & mask;
280
7.04k
        t = (t >> 6) + ((*(const uint64_t *) &l[8] & mask) >> 6);
281
7.04k
        t *= mul;
282
7.04k
        s = (int) (t >> 56) - 4 - 16;
283
7.04k
        break;
284
0
    }
285
4.37k
    case RTX_64X16: {
286
4.37k
        uint64_t t = *(const uint64_t *) &a[0] & mask;
287
4.37k
        t         += *(const uint32_t *) l & (uint32_t) mask;
288
4.37k
        t = (t >> 6) + ((*(const uint64_t *) &a[8] & mask) >> 6);
289
4.37k
        t *= mul;
290
4.37k
        s = (int) (t >> 56) - 16 - 4;
291
4.37k
        break;
292
0
    }
293
2.09M
    }
294
295
2.09M
    return (s != 0) + (s > 0);
296
2.09M
}
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.5M
{
305
40.5M
    unsigned mag = levels[0 * stride + 1] + levels[1 * stride + 0];
306
40.5M
    unsigned offset;
307
40.5M
    if (tx_class == TX_CLASS_2D) {
308
38.1M
        mag += levels[1 * stride + 1];
309
38.1M
        *hi_mag = mag;
310
38.1M
        mag += levels[0 * stride + 2] + levels[2 * stride + 0];
311
38.1M
        offset = ctx_offsets[umin(y, 4)][umin(x, 4)];
312
38.1M
    } else {
313
2.41M
        mag += levels[0 * stride + 2];
314
2.41M
        *hi_mag = mag;
315
2.41M
        mag += levels[0 * stride + 3] + levels[0 * stride + 4];
316
2.41M
        offset = 26 + (y > 1 ? 10 : y * 5);
317
2.41M
    }
318
40.5M
    return offset + (mag > 512 ? 4 : (mag + 64) >> 7);
319
40.5M
}
320
321
static int decode_coefs(Dav1dTaskContext *const t,
322
                        uint8_t *const a, uint8_t *const l,
323
                        const enum RectTxfmSize tx, const enum BlockSize bs,
324
                        const Av1Block *const b, const int intra,
325
                        const int plane, coef *cf,
326
                        enum TxfmType *const txtp, uint8_t *res_ctx)
327
4.76M
{
328
4.76M
    Dav1dTileState *const ts = t->ts;
329
4.76M
    const int chroma = !!plane;
330
4.76M
    const Dav1dFrameContext *const f = t->f;
331
4.76M
    const int lossless = f->frame_hdr->segmentation.lossless[b->seg_id];
332
4.76M
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[tx];
333
4.76M
    const int dbg = DEBUG_BLOCK_INFO && plane && 0;
334
335
4.76M
    if (dbg)
336
0
        printf("Start: r=%d\n", ts->msac.rng);
337
338
    // does this block have any non-zero coefficients
339
4.76M
    const int sctx = get_skip_ctx(t_dim, bs, a, l, chroma, f->cur.p.layout);
340
4.76M
    const int all_skip = dav1d_msac_decode_bool_adapt(&ts->msac,
341
4.76M
                             ts->cdf.coef.skip[t_dim->ctx][sctx]);
342
4.76M
    if (dbg)
343
0
        printf("Post-non-zero[%d][%d][%d]: r=%d\n",
344
0
               t_dim->ctx, sctx, all_skip, ts->msac.rng);
345
4.76M
    if (all_skip) {
346
2.26M
        *res_ctx = 0x40;
347
2.26M
        *txtp = lossless * WHT_WHT; /* lossless ? WHT_WHT : DCT_DCT */
348
2.26M
        return -1;
349
2.26M
    }
350
351
    // transform type (chroma: derived, luma: explicitly coded)
352
2.49M
    if (lossless) {
353
702k
        assert(t_dim->max == TX_4X4);
354
702k
        *txtp = WHT_WHT;
355
1.79M
    } else if (t_dim->max + intra >= TX_64X64) {
356
484k
        *txtp = DCT_DCT;
357
1.31M
    } else if (chroma) {
358
        // inferred from either the luma txtp (inter) or a LUT (intra)
359
310k
        *txtp = intra ? dav1d_txtp_from_uvmode[b->uv_mode] :
360
310k
                        get_uv_inter_txtp(t_dim, *txtp);
361
999k
    } else if (!f->frame_hdr->segmentation.qidx[b->seg_id]) {
362
        // In libaom, lossless is checked by a literal qidx == 0, but not all
363
        // such blocks are actually lossless. The remainder gets an implicit
364
        // transform type (for luma)
365
9.78k
        *txtp = DCT_DCT;
366
990k
    } else {
367
990k
        unsigned idx;
368
990k
        if (intra) {
369
793k
            const enum IntraPredMode y_mode_nofilt = b->y_mode == FILTER_PRED ?
370
640k
                dav1d_filter_mode_to_y_mode[b->y_angle] : b->y_mode;
371
793k
            if (f->frame_hdr->reduced_txtp_set || t_dim->min == TX_16X16) {
372
338k
                idx = dav1d_msac_decode_symbol_adapt8(&ts->msac,
373
338k
                          ts->cdf.m.txtp_intra2[t_dim->min][y_mode_nofilt], 4);
374
338k
                *txtp = dav1d_tx_types_per_set[idx + 0];
375
454k
            } else {
376
454k
                idx = dav1d_msac_decode_symbol_adapt8(&ts->msac,
377
454k
                          ts->cdf.m.txtp_intra1[t_dim->min][y_mode_nofilt], 6);
378
454k
                *txtp = dav1d_tx_types_per_set[idx + 5];
379
454k
            }
380
793k
            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
793k
        } else {
384
196k
            if (f->frame_hdr->reduced_txtp_set || t_dim->max == TX_32X32) {
385
58.2k
                idx = dav1d_msac_decode_bool_adapt(&ts->msac,
386
58.2k
                          ts->cdf.m.txtp_inter3[t_dim->min]);
387
58.2k
                *txtp = (idx - 1) & IDTX; /* idx ? DCT_DCT : IDTX */
388
138k
            } else if (t_dim->min == TX_16X16) {
389
21.1k
                idx = dav1d_msac_decode_symbol_adapt16(&ts->msac,
390
21.1k
                          ts->cdf.m.txtp_inter2, 11);
391
21.1k
                *txtp = dav1d_tx_types_per_set[idx + 12];
392
117k
            } else {
393
117k
                idx = dav1d_msac_decode_symbol_adapt16(&ts->msac,
394
117k
                          ts->cdf.m.txtp_inter1[t_dim->min], 15);
395
117k
                *txtp = dav1d_tx_types_per_set[idx + 24];
396
117k
            }
397
196k
            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
196k
        }
401
990k
    }
402
403
    // find end-of-block (eob)
404
2.49M
    int eob;
405
2.49M
    const int slw = imin(t_dim->lw, TX_32X32), slh = imin(t_dim->lh, TX_32X32);
406
2.49M
    const int tx2dszctx = slw + slh;
407
2.49M
    const enum TxClass tx_class = dav1d_tx_type_class[*txtp];
408
2.49M
    const int is_1d = tx_class != TX_CLASS_2D;
409
2.49M
    switch (tx2dszctx) {
410
0
#define case_sz(sz, bin, ns, is_1d) \
411
2.51M
    case sz: { \
412
2.51M
        uint16_t *const eob_bin_cdf = ts->cdf.coef.eob_bin_##bin[chroma]is_1d; \
413
2.51M
        eob = dav1d_msac_decode_symbol_adapt##ns(&ts->msac, eob_bin_cdf, 4 + sz); \
414
2.51M
        break; \
415
2.51M
    }
416
911k
    case_sz(0,   16,  8, [is_1d]);
417
215k
    case_sz(1,   32,  8, [is_1d]);
418
421k
    case_sz(2,   64,  8, [is_1d]);
419
215k
    case_sz(3,  128,  8, [is_1d]);
420
290k
    case_sz(4,  256, 16, [is_1d]);
421
101k
    case_sz(5,  512, 16,        );
422
356k
    case_sz(6, 1024, 16,        );
423
2.49M
#undef case_sz
424
2.49M
    }
425
2.49M
    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.49M
    if (eob > 1) {
429
1.53M
        const int eob_bin = eob - 2;
430
1.53M
        uint16_t *const eob_hi_bit_cdf =
431
1.53M
            ts->cdf.coef.eob_hi_bit[t_dim->ctx][chroma][eob_bin];
432
1.53M
        const int eob_hi_bit = dav1d_msac_decode_bool_adapt(&ts->msac, eob_hi_bit_cdf);
433
1.53M
        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.53M
        eob = ((eob_hi_bit | 2) << eob_bin) | dav1d_msac_decode_bools(&ts->msac, eob_bin);
437
1.53M
        if (dbg)
438
0
            printf("Post-eob[%d]: r=%d\n", eob, ts->msac.rng);
439
1.53M
    }
440
2.49M
    assert(eob >= 0);
441
442
    // base tokens
443
2.49M
    uint16_t (*const eob_cdf)[4] = ts->cdf.coef.eob_base_tok[t_dim->ctx][chroma];
444
2.49M
    uint16_t (*const hi_cdf)[4] = ts->cdf.coef.br_tok[imin(t_dim->ctx, 3)][chroma];
445
2.49M
    unsigned rc, dc_tok;
446
447
2.49M
    if (eob) {
448
1.60M
        uint16_t (*const lo_cdf)[4] = ts->cdf.coef.base_tok[t_dim->ctx][chroma];
449
1.60M
        uint8_t *const levels = t->scratch.levels; // bits 0-5: tok, 6-7: lo_tok
450
451
        /* eob */
452
1.60M
        unsigned ctx = 1 + (eob > 2 << tx2dszctx) + (eob > 4 << tx2dszctx);
453
1.60M
        int eob_tok = dav1d_msac_decode_symbol_adapt4(&ts->msac, eob_cdf[ctx], 2);
454
1.60M
        int tok = eob_tok + 1;
455
1.60M
        int level_tok = tok * 0x41;
456
1.60M
        unsigned mag;
457
458
1.60M
#define DECODE_COEFS_CLASS(tx_class) \
459
1.61M
        unsigned x, y; \
460
1.61M
        uint8_t *level; \
461
1.61M
        if (tx_class == TX_CLASS_2D) \
462
1.61M
            rc = scan[eob], x = rc >> shift, y = rc & mask; \
463
1.61M
        else if (tx_class == TX_CLASS_H) \
464
            /* Transposing reduces the stride and padding requirements */ \
465
120k
            x = eob & mask, y = eob >> shift, rc = eob; \
466
120k
        else /* tx_class == TX_CLASS_V */ \
467
120k
            x = eob & mask, y = eob >> shift, rc = (x << shift2) | y; \
468
1.61M
        if (dbg) \
469
1.61M
            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.61M
        if (eob_tok == 2) { \
472
33.0k
            ctx = (tx_class == TX_CLASS_2D ? (x | y) > 1 : y != 0) ? 14 : 7; \
473
33.0k
            tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[ctx]); \
474
33.0k
            level_tok = tok + (3 << 6); \
475
33.0k
            if (dbg) \
476
33.0k
                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
33.0k
        } \
480
1.61M
        cf[rc] = tok << 11; \
481
1.61M
        if (tx_class == TX_CLASS_2D) \
482
1.61M
            level = levels + rc; \
483
1.61M
        else \
484
1.61M
            level = levels + x * stride + y; \
485
1.61M
        *level = (uint8_t) level_tok; \
486
42.1M
        for (int i = eob - 1; i > 0; i--) { /* ac */ \
487
40.5M
            unsigned rc_i; \
488
40.5M
            if (tx_class == TX_CLASS_2D) \
489
40.5M
                rc_i = scan[i], x = rc_i >> shift, y = rc_i & mask; \
490
40.5M
            else if (tx_class == TX_CLASS_H) \
491
2.40M
                x = i & mask, y = i >> shift, rc_i = i; \
492
2.40M
            else /* tx_class == TX_CLASS_V */ \
493
2.40M
                x = i & mask, y = i >> shift, rc_i = (x << shift2) | y; \
494
40.5M
            assert(x < 32 && y < 32); \
495
40.5M
            if (tx_class == TX_CLASS_2D) \
496
40.5M
                level = levels + rc_i; \
497
40.5M
            else \
498
40.5M
                level = levels + x * stride + y; \
499
40.5M
            ctx = get_lo_ctx(level, tx_class, &mag, lo_ctx_offsets, x, y, stride); \
500
40.5M
            if (tx_class == TX_CLASS_2D) \
501
40.5M
                y |= x; \
502
40.5M
            tok = dav1d_msac_decode_symbol_adapt4(&ts->msac, lo_cdf[ctx], 3); \
503
40.5M
            if (dbg) \
504
40.5M
                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.5M
            if (tok == 3) { \
507
3.05M
                mag &= 63; \
508
3.05M
                ctx = (y > (tx_class == TX_CLASS_2D) ? 14 : 7) + \
509
3.05M
                      (mag > 12 ? 6 : (mag + 1) >> 1); \
510
3.05M
                tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[ctx]); \
511
3.05M
                if (dbg) \
512
3.05M
                    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.05M
                *level = (uint8_t) (tok + (3 << 6)); \
516
3.05M
                cf[rc_i] = (tok << 11) | rc; \
517
3.05M
                rc = rc_i; \
518
37.4M
            } else { \
519
                /* 0x1 for tok, 0x7ff as bitmask for rc, 0x41 for level_tok */ \
520
37.4M
                tok *= 0x17ff41; \
521
37.4M
                *level = (uint8_t) tok; \
522
                /* tok ? (tok << 11) | rc : 0 */ \
523
37.4M
                tok = (tok >> 9) & (rc + ~0x7ffu); \
524
37.4M
                if (tok) rc = rc_i; \
525
37.4M
                cf[rc_i] = tok; \
526
37.4M
            } \
527
40.5M
        } \
528
        /* dc */ \
529
1.61M
        ctx = (tx_class == TX_CLASS_2D) ? 0 : \
530
1.61M
            get_lo_ctx(levels, tx_class, &mag, lo_ctx_offsets, 0, 0, stride); \
531
1.61M
        dc_tok = dav1d_msac_decode_symbol_adapt4(&ts->msac, lo_cdf[ctx], 3); \
532
1.61M
        if (dbg) \
533
1.61M
            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.61M
        if (dc_tok == 3) { \
536
609k
            if (tx_class == TX_CLASS_2D) \
537
609k
                mag = levels[0 * stride + 1] + levels[1 * stride + 0] + \
538
597k
                      levels[1 * stride + 1]; \
539
609k
            mag &= 63; \
540
609k
            ctx = mag > 12 ? 6 : (mag + 1) >> 1; \
541
609k
            dc_tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[ctx]); \
542
609k
            if (dbg) \
543
609k
                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
609k
        } \
546
1.61M
        break
547
548
1.60M
        const uint16_t *scan;
549
1.60M
        switch (tx_class) {
550
1.48M
        case TX_CLASS_2D: {
551
1.48M
            const unsigned nonsquare_tx = tx >= RTX_4X8;
552
1.48M
            const uint8_t (*const lo_ctx_offsets)[5] =
553
1.48M
                dav1d_lo_ctx_offsets[nonsquare_tx + (tx & nonsquare_tx)];
554
1.48M
            scan = dav1d_scans[tx];
555
1.48M
            const ptrdiff_t stride = 4 << slh;
556
1.48M
            const unsigned shift = slh + 2, shift2 = 0;
557
1.48M
            const unsigned mask = (4 << slh) - 1;
558
1.48M
            memset(levels, 0, stride * ((4 << slw) + 2));
559
1.48M
            DECODE_COEFS_CLASS(TX_CLASS_2D);
560
1.48M
        }
561
82.0k
        case TX_CLASS_H: {
562
82.0k
            const uint8_t (*const lo_ctx_offsets)[5] = NULL;
563
82.0k
            const ptrdiff_t stride = 16;
564
82.0k
            const unsigned shift = slh + 2, shift2 = 0;
565
82.0k
            const unsigned mask = (4 << slh) - 1;
566
82.0k
            memset(levels, 0, stride * ((4 << slh) + 2));
567
82.0k
            DECODE_COEFS_CLASS(TX_CLASS_H);
568
82.0k
        }
569
44.5k
        case TX_CLASS_V: {
570
44.5k
            const uint8_t (*const lo_ctx_offsets)[5] = NULL;
571
44.5k
            const ptrdiff_t stride = 16;
572
44.5k
            const unsigned shift = slw + 2, shift2 = slh + 2;
573
44.5k
            const unsigned mask = (4 << slw) - 1;
574
44.5k
            memset(levels, 0, stride * ((4 << slw) + 2));
575
44.5k
            DECODE_COEFS_CLASS(TX_CLASS_V);
576
44.5k
        }
577
0
#undef DECODE_COEFS_CLASS
578
0
        default: assert(0);
579
1.60M
        }
580
1.60M
    } else { // dc-only
581
889k
        int tok_br = dav1d_msac_decode_symbol_adapt4(&ts->msac, eob_cdf[0], 2);
582
889k
        dc_tok = 1 + tok_br;
583
889k
        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
889k
        if (tok_br == 2) {
587
28.4k
            dc_tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[0]);
588
28.4k
            if (dbg)
589
0
                printf("Post-dc_hi_tok[%d][%d][0][%d]: r=%d\n",
590
0
                       imin(t_dim->ctx, 3), chroma, dc_tok, ts->msac.rng);
591
28.4k
        }
592
889k
        rc = 0;
593
889k
    }
594
595
    // residual and sign
596
2.51M
    const uint16_t *const dq_tbl = ts->dq[b->seg_id][plane];
597
2.51M
    const uint8_t *const qm_tbl = *txtp < IDTX ? f->qm[tx][plane] : NULL;
598
2.51M
    const int dq_shift = imax(0, t_dim->ctx - 2);
599
2.51M
    const int cf_max = ~(~127U << (BITDEPTH == 8 ? 8 : f->cur.p.bpc));
600
2.51M
    unsigned cul_level, dc_sign_level;
601
602
2.51M
    if (!dc_tok) {
603
410k
        cul_level = 0;
604
410k
        dc_sign_level = 1 << 6;
605
410k
        if (qm_tbl) goto ac_qm;
606
305k
        goto ac_noqm;
607
410k
    }
608
609
2.09M
    const int dc_sign_ctx = get_dc_sign_ctx(tx, a, l);
610
2.09M
    uint16_t *const dc_sign_cdf = ts->cdf.coef.dc_sign[chroma][dc_sign_ctx];
611
2.09M
    const int dc_sign = dav1d_msac_decode_bool_adapt(&ts->msac, dc_sign_cdf);
612
2.09M
    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.09M
    int dc_dq = dq_tbl[0];
617
2.09M
    dc_sign_level = (dc_sign - 1) & (2 << 6);
618
619
2.09M
    if (qm_tbl) {
620
559k
        dc_dq = (dc_dq * qm_tbl[0] + 16) >> 5;
621
622
559k
        if (dc_tok == 15) {
623
16.7k
            dc_tok = read_golomb(&ts->msac) + 15;
624
16.7k
            if (dbg)
625
0
                printf("Post-dc_residual[%d->%d]: r=%d\n",
626
0
                       dc_tok - 15, dc_tok, ts->msac.rng);
627
628
16.7k
            dc_tok &= 0xfffff;
629
16.7k
            dc_dq = (dc_dq * dc_tok) & 0xffffff;
630
542k
        } else {
631
542k
            dc_dq *= dc_tok;
632
542k
            assert(dc_dq <= 0xffffff);
633
542k
        }
634
559k
        cul_level = dc_tok;
635
559k
        dc_dq >>= dq_shift;
636
559k
        dc_dq = umin(dc_dq, cf_max + dc_sign);
637
559k
        cf[0] = (coef) (dc_sign ? -dc_dq : dc_dq);
638
639
822k
        if (rc) ac_qm: {
640
822k
            const unsigned ac_dq = dq_tbl[1];
641
5.83M
            do {
642
5.83M
                const int sign = dav1d_msac_decode_bool_equi(&ts->msac);
643
5.83M
                if (dbg)
644
0
                    printf("Post-sign[%d=%d]: r=%d\n", rc, sign, ts->msac.rng);
645
5.83M
                const unsigned rc_tok = cf[rc];
646
5.83M
                unsigned tok, dq = (ac_dq * qm_tbl[rc] + 16) >> 5;
647
5.83M
                int dq_sat;
648
649
5.83M
                if (rc_tok >= (15 << 11)) {
650
168k
                    tok = read_golomb(&ts->msac) + 15;
651
168k
                    if (dbg)
652
0
                        printf("Post-residual[%d=%d->%d]: r=%d\n",
653
0
                               rc, tok - 15, tok, ts->msac.rng);
654
655
168k
                    tok &= 0xfffff;
656
168k
                    dq = (dq * tok) & 0xffffff;
657
5.66M
                } else {
658
5.66M
                    tok = rc_tok >> 11;
659
5.66M
                    dq *= tok;
660
5.66M
                    assert(dq <= 0xffffff);
661
5.66M
                }
662
5.83M
                cul_level += tok;
663
5.83M
                dq >>= dq_shift;
664
5.83M
                dq_sat = umin(dq, cf_max + sign);
665
5.83M
                cf[rc] = (coef) (sign ? -dq_sat : dq_sat);
666
667
5.83M
                rc = rc_tok & 0x3ff;
668
5.83M
            } while (rc);
669
822k
        }
670
1.53M
    } else {
671
        // non-qmatrix is the common case and allows for additional optimizations
672
1.53M
        if (dc_tok == 15) {
673
50.4k
            dc_tok = read_golomb(&ts->msac) + 15;
674
50.4k
            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
50.4k
            dc_tok &= 0xfffff;
679
50.4k
            dc_dq = ((dc_dq * dc_tok) & 0xffffff) >> dq_shift;
680
50.4k
            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.53M
        cul_level = dc_tok;
686
1.53M
        cf[0] = (coef) (dc_sign ? -dc_dq : dc_dq);
687
688
2.02M
        if (rc) ac_noqm: {
689
2.02M
            const unsigned ac_dq = dq_tbl[1];
690
10.3M
            do {
691
10.3M
                const int sign = dav1d_msac_decode_bool_equi(&ts->msac);
692
10.3M
                if (dbg)
693
0
                    printf("Post-sign[%d=%d]: r=%d\n", rc, sign, ts->msac.rng);
694
10.3M
                const unsigned rc_tok = cf[rc];
695
10.3M
                unsigned tok;
696
10.3M
                int dq;
697
698
                // residual
699
10.3M
                if (rc_tok >= (15 << 11)) {
700
221k
                    tok = read_golomb(&ts->msac) + 15;
701
221k
                    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
221k
                    tok &= 0xfffff;
707
708
                    // dequant, see 7.12.3
709
221k
                    dq = ((ac_dq * tok) & 0xffffff) >> dq_shift;
710
221k
                    dq = umin(dq, cf_max + sign);
711
10.1M
                } else {
712
                    // cannot exceed cf_max, so we can avoid the clipping
713
10.1M
                    tok = rc_tok >> 11;
714
10.1M
                    dq = ((ac_dq * tok) >> dq_shift);
715
10.1M
                    assert(dq <= cf_max);
716
10.1M
                }
717
10.3M
                cul_level += tok;
718
10.3M
                cf[rc] = (coef) (sign ? -dq : dq);
719
720
10.3M
                rc = rc_tok & 0x3ff; // next non-zero rc, zero if eob
721
10.3M
            } while (rc);
722
2.02M
        }
723
1.53M
    }
724
725
    // context
726
2.48M
    *res_ctx = umin(cul_level, 63) | dc_sign_level;
727
728
2.48M
    return eob;
729
2.09M
}
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
511k
{
737
511k
    const Dav1dFrameContext *const f = t->f;
738
511k
    Dav1dTileState *const ts = t->ts;
739
511k
    const Dav1dDSPContext *const dsp = f->dsp;
740
511k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[ytx];
741
511k
    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
511k
    if (depth < 2 && tx_split[depth] &&
746
58.5k
        tx_split[depth] & (1 << (y_off * 4 + x_off)))
747
44.9k
    {
748
44.9k
        const enum RectTxfmSize sub = t_dim->sub;
749
44.9k
        const TxfmInfo *const sub_t_dim = &dav1d_txfm_dimensions[sub];
750
44.9k
        const int txsw = sub_t_dim->w, txsh = sub_t_dim->h;
751
752
44.9k
        read_coef_tree(t, bs, b, sub, depth + 1, tx_split,
753
44.9k
                       x_off * 2 + 0, y_off * 2 + 0, dst);
754
44.9k
        t->bx += txsw;
755
44.9k
        if (txw >= txh && t->bx < f->bw)
756
33.5k
            read_coef_tree(t, bs, b, sub, depth + 1, tx_split, x_off * 2 + 1,
757
33.5k
                           y_off * 2 + 0, dst ? &dst[4 * txsw] : NULL);
758
44.9k
        t->bx -= txsw;
759
44.9k
        t->by += txsh;
760
44.9k
        if (txh >= txw && t->by < f->bh) {
761
31.4k
            if (dst)
762
6.82k
                dst += 4 * txsh * PXSTRIDE(f->cur.stride[0]);
763
31.4k
            read_coef_tree(t, bs, b, sub, depth + 1, tx_split,
764
31.4k
                           x_off * 2 + 0, y_off * 2 + 1, dst);
765
31.4k
            t->bx += txsw;
766
31.4k
            if (txw >= txh && t->bx < f->bw)
767
20.1k
                read_coef_tree(t, bs, b, sub, depth + 1, tx_split, x_off * 2 + 1,
768
20.1k
                               y_off * 2 + 1, dst ? &dst[4 * txsw] : NULL);
769
31.4k
            t->bx -= txsw;
770
31.4k
        }
771
44.9k
        t->by -= txsh;
772
466k
    } else {
773
466k
        const int bx4 = t->bx & 31, by4 = t->by & 31;
774
466k
        enum TxfmType txtp;
775
466k
        uint8_t cf_ctx;
776
466k
        int eob;
777
466k
        coef *cf;
778
779
466k
        if (t->frame_thread.pass) {
780
466k
            const int p = t->frame_thread.pass & 1;
781
466k
            assert(ts->frame_thread[p].cf);
782
466k
            cf = ts->frame_thread[p].cf;
783
466k
            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
466k
        if (t->frame_thread.pass != 2) {
788
341k
            eob = decode_coefs(t, &t->a->lcoef[bx4], &t->l.lcoef[by4],
789
341k
                               ytx, bs, b, 0, 0, cf, &txtp, &cf_ctx);
790
341k
            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
341k
            dav1d_memset_likely_pow2(&t->a->lcoef[bx4], cf_ctx, imin(txw, f->bw - t->bx));
794
341k
            dav1d_memset_likely_pow2(&t->l.lcoef[by4], cf_ctx, imin(txh, f->bh - t->by));
795
341k
#define set_ctx(rep_macro) \
796
1.33M
            for (int y = 0; y < txh; y++) { \
797
995k
                rep_macro(txtp_map, 0, txtp); \
798
995k
                txtp_map += 32; \
799
995k
            }
800
341k
            uint8_t *txtp_map = &t->scratch.txtp_map[by4 * 32 + bx4];
801
341k
            case_set_upto16(t_dim->lw);
802
341k
#undef set_ctx
803
341k
            if (t->frame_thread.pass == 1)
804
341k
                *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
805
341k
        } else {
806
124k
            const int cbi = *ts->frame_thread[0].cbi++;
807
124k
            eob  = cbi >> 5;
808
124k
            txtp = cbi & 0x1f;
809
124k
        }
810
466k
        if (!(t->frame_thread.pass & 1)) {
811
125k
            assert(dst);
812
125k
            if (eob >= 0) {
813
100k
                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
100k
                dsp->itx.itxfm_add[ytx][txtp](dst, f->cur.stride[0], cf, eob
816
100k
                                              HIGHBD_CALL_SUFFIX);
817
100k
                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
100k
            }
820
125k
        }
821
466k
    }
822
511k
}
823
824
void bytefn(dav1d_read_coef_blocks)(Dav1dTaskContext *const t,
825
                                    const enum BlockSize bs, const Av1Block *const b)
826
2.49M
{
827
2.49M
    const Dav1dFrameContext *const f = t->f;
828
2.49M
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
829
2.49M
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
830
2.49M
    const int bx4 = t->bx & 31, by4 = t->by & 31;
831
2.49M
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
832
2.49M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
833
2.49M
    const int bw4 = b_dim[0], bh4 = b_dim[1];
834
2.49M
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
835
2.49M
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
836
2.06M
                           (bw4 > ss_hor || t->bx & 1) &&
837
1.93M
                           (bh4 > ss_ver || t->by & 1);
838
839
2.49M
    if (b->skip) {
840
1.39M
        BlockContext *const a = t->a;
841
1.39M
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
842
1.39M
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
843
1.39M
        if (has_chroma) {
844
1.00M
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
845
1.00M
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
846
1.00M
            memset_cw(&a->ccoef[0][cbx4], 0x40);
847
1.00M
            memset_cw(&a->ccoef[1][cbx4], 0x40);
848
1.00M
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
849
1.00M
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
850
1.00M
        }
851
1.39M
        return;
852
1.39M
    }
853
854
1.10M
    Dav1dTileState *const ts = t->ts;
855
1.10M
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
856
1.10M
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
857
1.10M
    assert(t->frame_thread.pass == 1);
858
1.10M
    assert(!b->skip);
859
1.10M
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
860
1.10M
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->intra ? b->tx : b->max_ytx];
861
1.10M
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
862
863
2.24M
    for (int init_y = 0; init_y < h4; init_y += 16) {
864
1.13M
        const int sub_h4 = imin(h4, 16 + init_y);
865
2.32M
        for (int init_x = 0; init_x < w4; init_x += 16) {
866
1.19M
            const int sub_w4 = imin(w4, init_x + 16);
867
1.19M
            int y_off = !!init_y, y, x;
868
2.57M
            for (y = init_y, t->by += init_y; y < sub_h4;
869
1.37M
                 y += t_dim->h, t->by += t_dim->h, y_off++)
870
1.37M
            {
871
1.37M
                int x_off = !!init_x;
872
3.61M
                for (x = init_x, t->bx += init_x; x < sub_w4;
873
2.23M
                     x += t_dim->w, t->bx += t_dim->w, x_off++)
874
2.23M
                {
875
2.23M
                    if (!b->intra) {
876
273k
                        read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
877
273k
                                       x_off, y_off, NULL);
878
1.96M
                    } else {
879
1.96M
                        uint8_t cf_ctx = 0x40;
880
1.96M
                        enum TxfmType txtp;
881
1.96M
                        const int eob =
882
1.96M
                            decode_coefs(t, &t->a->lcoef[bx4 + x],
883
1.96M
                                         &t->l.lcoef[by4 + y], b->tx, bs, b, 1,
884
1.96M
                                         0, ts->frame_thread[1].cf, &txtp, &cf_ctx);
885
1.96M
                        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.96M
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
889
1.96M
                        ts->frame_thread[1].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
890
1.96M
                        dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
891
1.96M
                        dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
892
1.96M
                    }
893
2.23M
                }
894
1.37M
                t->bx -= x;
895
1.37M
            }
896
1.19M
            t->by -= y;
897
898
1.19M
            if (!has_chroma) continue;
899
900
872k
            const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
901
872k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
902
2.61M
            for (int pl = 0; pl < 2; pl++) {
903
3.65M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
904
1.91M
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
905
1.91M
                {
906
4.40M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
907
2.48M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
908
2.48M
                    {
909
2.48M
                        uint8_t cf_ctx = 0x40;
910
2.48M
                        enum TxfmType txtp;
911
2.48M
                        if (!b->intra)
912
359k
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
913
359k
                                                        bx4 + (x << ss_hor)];
914
2.48M
                        const int eob =
915
2.48M
                            decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
916
2.48M
                                         &t->l.ccoef[pl][cby4 + y], b->uvtx, bs,
917
2.48M
                                         b, b->intra, 1 + pl, ts->frame_thread[1].cf,
918
2.48M
                                         &txtp, &cf_ctx);
919
2.48M
                        if (DEBUG_BLOCK_INFO)
920
0
                            printf("Post-uv-cf-blk[pl=%d,tx=%d,"
921
0
                                   "txtp=%d,eob=%d]: r=%d\n",
922
0
                                   pl, b->uvtx, txtp, eob, ts->msac.rng);
923
2.48M
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
924
2.48M
                        ts->frame_thread[1].cf += uv_t_dim->w * uv_t_dim->h * 16;
925
2.48M
                        int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
926
2.48M
                        int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
927
2.48M
                        dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
928
2.48M
                        dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
929
2.48M
                    }
930
1.91M
                    t->bx -= x << ss_hor;
931
1.91M
                }
932
1.73M
                t->by -= y << ss_ver;
933
1.73M
            }
934
872k
        }
935
1.13M
    }
936
1.10M
}
dav1d_read_coef_blocks_8bpc
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.24M
                           (bw4 > ss_hor || t->bx & 1) &&
837
1.14M
                           (bh4 > ss_ver || t->by & 1);
838
839
1.30M
    if (b->skip) {
840
735k
        BlockContext *const a = t->a;
841
735k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
842
735k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
843
735k
        if (has_chroma) {
844
584k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
845
584k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
846
584k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
847
584k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
848
584k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
849
584k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
850
584k
        }
851
735k
        return;
852
735k
    }
853
854
571k
    Dav1dTileState *const ts = t->ts;
855
571k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
856
571k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
857
571k
    assert(t->frame_thread.pass == 1);
858
571k
    assert(!b->skip);
859
571k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
860
571k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->intra ? b->tx : b->max_ytx];
861
571k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
862
863
1.16M
    for (int init_y = 0; init_y < h4; init_y += 16) {
864
589k
        const int sub_h4 = imin(h4, 16 + init_y);
865
1.21M
        for (int init_x = 0; init_x < w4; init_x += 16) {
866
621k
            const int sub_w4 = imin(w4, init_x + 16);
867
621k
            int y_off = !!init_y, y, x;
868
1.33M
            for (y = init_y, t->by += init_y; y < sub_h4;
869
713k
                 y += t_dim->h, t->by += t_dim->h, y_off++)
870
713k
            {
871
713k
                int x_off = !!init_x;
872
1.93M
                for (x = init_x, t->bx += init_x; x < sub_w4;
873
1.21M
                     x += t_dim->w, t->bx += t_dim->w, x_off++)
874
1.21M
                {
875
1.21M
                    if (!b->intra) {
876
181k
                        read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
877
181k
                                       x_off, y_off, NULL);
878
1.03M
                    } else {
879
1.03M
                        uint8_t cf_ctx = 0x40;
880
1.03M
                        enum TxfmType txtp;
881
1.03M
                        const int eob =
882
1.03M
                            decode_coefs(t, &t->a->lcoef[bx4 + x],
883
1.03M
                                         &t->l.lcoef[by4 + y], b->tx, bs, b, 1,
884
1.03M
                                         0, ts->frame_thread[1].cf, &txtp, &cf_ctx);
885
1.03M
                        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.03M
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
889
1.03M
                        ts->frame_thread[1].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
890
1.03M
                        dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
891
1.03M
                        dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
892
1.03M
                    }
893
1.21M
                }
894
713k
                t->bx -= x;
895
713k
            }
896
621k
            t->by -= y;
897
898
621k
            if (!has_chroma) continue;
899
900
504k
            const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
901
504k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
902
1.50M
            for (int pl = 0; pl < 2; pl++) {
903
2.08M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
904
1.07M
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
905
1.07M
                {
906
2.46M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
907
1.38M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
908
1.38M
                    {
909
1.38M
                        uint8_t cf_ctx = 0x40;
910
1.38M
                        enum TxfmType txtp;
911
1.38M
                        if (!b->intra)
912
223k
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
913
223k
                                                        bx4 + (x << ss_hor)];
914
1.38M
                        const int eob =
915
1.38M
                            decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
916
1.38M
                                         &t->l.ccoef[pl][cby4 + y], b->uvtx, bs,
917
1.38M
                                         b, b->intra, 1 + pl, ts->frame_thread[1].cf,
918
1.38M
                                         &txtp, &cf_ctx);
919
1.38M
                        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.38M
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
924
1.38M
                        ts->frame_thread[1].cf += uv_t_dim->w * uv_t_dim->h * 16;
925
1.38M
                        int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
926
1.38M
                        int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
927
1.38M
                        dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
928
1.38M
                        dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
929
1.38M
                    }
930
1.07M
                    t->bx -= x << ss_hor;
931
1.07M
                }
932
1.00M
                t->by -= y << ss_ver;
933
1.00M
            }
934
504k
        }
935
589k
    }
936
571k
}
dav1d_read_coef_blocks_16bpc
Line
Count
Source
826
1.19M
{
827
1.19M
    const Dav1dFrameContext *const f = t->f;
828
1.19M
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
829
1.19M
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
830
1.19M
    const int bx4 = t->bx & 31, by4 = t->by & 31;
831
1.19M
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
832
1.19M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
833
1.19M
    const int bw4 = b_dim[0], bh4 = b_dim[1];
834
1.19M
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
835
1.19M
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
836
821k
                           (bw4 > ss_hor || t->bx & 1) &&
837
791k
                           (bh4 > ss_ver || t->by & 1);
838
839
1.19M
    if (b->skip) {
840
658k
        BlockContext *const a = t->a;
841
658k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
842
658k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
843
658k
        if (has_chroma) {
844
421k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
845
421k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
846
421k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
847
421k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
848
421k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
849
421k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
850
421k
        }
851
658k
        return;
852
658k
    }
853
854
533k
    Dav1dTileState *const ts = t->ts;
855
533k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
856
533k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
857
533k
    assert(t->frame_thread.pass == 1);
858
533k
    assert(!b->skip);
859
533k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
860
533k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->intra ? b->tx : b->max_ytx];
861
533k
    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
546k
        const int sub_h4 = imin(h4, 16 + init_y);
865
1.11M
        for (int init_x = 0; init_x < w4; init_x += 16) {
866
569k
            const int sub_w4 = imin(w4, init_x + 16);
867
569k
            int y_off = !!init_y, y, x;
868
1.23M
            for (y = init_y, t->by += init_y; y < sub_h4;
869
665k
                 y += t_dim->h, t->by += t_dim->h, y_off++)
870
665k
            {
871
665k
                int x_off = !!init_x;
872
1.68M
                for (x = init_x, t->bx += init_x; x < sub_w4;
873
1.01M
                     x += t_dim->w, t->bx += t_dim->w, x_off++)
874
1.01M
                {
875
1.01M
                    if (!b->intra) {
876
91.3k
                        read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
877
91.3k
                                       x_off, y_off, NULL);
878
924k
                    } else {
879
924k
                        uint8_t cf_ctx = 0x40;
880
924k
                        enum TxfmType txtp;
881
924k
                        const int eob =
882
924k
                            decode_coefs(t, &t->a->lcoef[bx4 + x],
883
924k
                                         &t->l.lcoef[by4 + y], b->tx, bs, b, 1,
884
924k
                                         0, ts->frame_thread[1].cf, &txtp, &cf_ctx);
885
924k
                        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
924k
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
889
924k
                        ts->frame_thread[1].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
890
924k
                        dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
891
924k
                        dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
892
924k
                    }
893
1.01M
                }
894
665k
                t->bx -= x;
895
665k
            }
896
569k
            t->by -= y;
897
898
569k
            if (!has_chroma) continue;
899
900
368k
            const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
901
368k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
902
1.10M
            for (int pl = 0; pl < 2; pl++) {
903
1.57M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
904
838k
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
905
838k
                {
906
1.94M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
907
1.10M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
908
1.10M
                    {
909
1.10M
                        uint8_t cf_ctx = 0x40;
910
1.10M
                        enum TxfmType txtp;
911
1.10M
                        if (!b->intra)
912
136k
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
913
136k
                                                        bx4 + (x << ss_hor)];
914
1.10M
                        const int eob =
915
1.10M
                            decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
916
1.10M
                                         &t->l.ccoef[pl][cby4 + y], b->uvtx, bs,
917
1.10M
                                         b, b->intra, 1 + pl, ts->frame_thread[1].cf,
918
1.10M
                                         &txtp, &cf_ctx);
919
1.10M
                        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.10M
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
924
1.10M
                        ts->frame_thread[1].cf += uv_t_dim->w * uv_t_dim->h * 16;
925
1.10M
                        int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
926
1.10M
                        int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
927
1.10M
                        dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
928
1.10M
                        dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
929
1.10M
                    }
930
838k
                    t->bx -= x << ss_hor;
931
838k
                }
932
734k
                t->by -= y << ss_ver;
933
734k
            }
934
368k
        }
935
546k
    }
936
533k
}
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
499k
{
945
499k
    assert((dst8 != NULL) ^ (dst16 != NULL));
946
499k
    const Dav1dFrameContext *const f = t->f;
947
499k
    const int ss_ver = !!pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
948
499k
    const int ss_hor = !!pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
949
499k
    const int h_mul = 4 >> ss_hor, v_mul = 4 >> ss_ver;
950
499k
    const int mvx = mv.x, mvy = mv.y;
951
499k
    const int mx = mvx & (15 >> !ss_hor), my = mvy & (15 >> !ss_ver);
952
499k
    ptrdiff_t ref_stride = refp->p.stride[!!pl];
953
499k
    const pixel *ref;
954
955
499k
    if (refp->p.p.w == f->cur.p.w && refp->p.p.h == f->cur.p.h) {
956
320k
        const int dx = bx * h_mul + (mvx >> (3 + ss_hor));
957
320k
        const int dy = by * v_mul + (mvy >> (3 + ss_ver));
958
320k
        int w, h;
959
960
320k
        if (refp->p.data[0] != f->cur.data[0]) { // i.e. not for intrabc
961
111k
            w = (f->cur.p.w + ss_hor) >> ss_hor;
962
111k
            h = (f->cur.p.h + ss_ver) >> ss_ver;
963
209k
        } else {
964
209k
            w = f->bw * 4 >> ss_hor;
965
209k
            h = f->bh * 4 >> ss_ver;
966
209k
        }
967
320k
        if (dx < !!mx * 3 || dy < !!my * 3 ||
968
281k
            dx + bw4 * h_mul + !!mx * 4 > w ||
969
247k
            dy + bh4 * v_mul + !!my * 4 > h)
970
82.4k
        {
971
82.4k
            pixel *const emu_edge_buf = bitfn(t->scratch.emu_edge);
972
82.4k
            f->dsp->mc.emu_edge(bw4 * h_mul + !!mx * 7, bh4 * v_mul + !!my * 7,
973
82.4k
                                w, h, dx - !!mx * 3, dy - !!my * 3,
974
82.4k
                                emu_edge_buf, 192 * sizeof(pixel),
975
82.4k
                                refp->p.data[pl], ref_stride);
976
82.4k
            ref = &emu_edge_buf[192 * !!my * 3 + !!mx * 3];
977
82.4k
            ref_stride = 192 * sizeof(pixel);
978
237k
        } else {
979
237k
            ref = ((pixel *) refp->p.data[pl]) + PXSTRIDE(ref_stride) * dy + dx;
980
237k
        }
981
982
320k
        if (dst8 != NULL) {
983
291k
            f->dsp->mc.mc[filter_2d](dst8, dst_stride, ref, ref_stride, bw4 * h_mul,
984
291k
                                     bh4 * v_mul, mx << !ss_hor, my << !ss_ver
985
291k
                                     HIGHBD_CALL_SUFFIX);
986
291k
        } else {
987
28.4k
            f->dsp->mc.mct[filter_2d](dst16, ref, ref_stride, bw4 * h_mul,
988
28.4k
                                      bh4 * v_mul, mx << !ss_hor, my << !ss_ver
989
28.4k
                                      HIGHBD_CALL_SUFFIX);
990
28.4k
        }
991
320k
    } else {
992
179k
        assert(refp != &f->sr_cur);
993
994
179k
        const int orig_pos_y = (by * v_mul << 4) + mvy * (1 << !ss_ver);
995
179k
        const int orig_pos_x = (bx * h_mul << 4) + mvx * (1 << !ss_hor);
996
359k
#define scale_mv(res, val, scale) do { \
997
359k
            const int64_t tmp = (int64_t)(val) * scale + (scale - 0x4000) * 8; \
998
359k
            res = apply_sign64((int) ((llabs(tmp) + 128) >> 8), tmp) + 32;     \
999
359k
        } while (0)
1000
179k
        int pos_y, pos_x;
1001
179k
        scale_mv(pos_x, orig_pos_x, f->svc[refidx][0].scale);
1002
179k
        scale_mv(pos_y, orig_pos_y, f->svc[refidx][1].scale);
1003
179k
#undef scale_mv
1004
179k
        const int left = pos_x >> 10;
1005
179k
        const int top = pos_y >> 10;
1006
179k
        const int right =
1007
179k
            ((pos_x + (bw4 * h_mul - 1) * f->svc[refidx][0].step) >> 10) + 1;
1008
179k
        const int bottom =
1009
179k
            ((pos_y + (bh4 * v_mul - 1) * f->svc[refidx][1].step) >> 10) + 1;
1010
1011
179k
        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
179k
        const int w = (refp->p.p.w + ss_hor) >> ss_hor;
1018
179k
        const int h = (refp->p.p.h + ss_ver) >> ss_ver;
1019
179k
        if (left < 3 || top < 3 || right + 4 > w || bottom + 4 > h) {
1020
171k
            pixel *const emu_edge_buf = bitfn(t->scratch.emu_edge);
1021
171k
            f->dsp->mc.emu_edge(right - left + 7, bottom - top + 7,
1022
171k
                                w, h, left - 3, top - 3,
1023
171k
                                emu_edge_buf, 320 * sizeof(pixel),
1024
171k
                                refp->p.data[pl], ref_stride);
1025
171k
            ref = &emu_edge_buf[320 * 3 + 3];
1026
171k
            ref_stride = 320 * sizeof(pixel);
1027
171k
            if (DEBUG_BLOCK_INFO) printf("Emu\n");
1028
171k
        } else {
1029
8.77k
            ref = ((pixel *) refp->p.data[pl]) + PXSTRIDE(ref_stride) * top + left;
1030
8.77k
        }
1031
1032
179k
        if (dst8 != NULL) {
1033
123k
            f->dsp->mc.mc_scaled[filter_2d](dst8, dst_stride, ref, ref_stride,
1034
123k
                                            bw4 * h_mul, bh4 * v_mul,
1035
123k
                                            pos_x & 0x3ff, pos_y & 0x3ff,
1036
123k
                                            f->svc[refidx][0].step,
1037
123k
                                            f->svc[refidx][1].step
1038
123k
                                            HIGHBD_CALL_SUFFIX);
1039
123k
        } else {
1040
56.1k
            f->dsp->mc.mct_scaled[filter_2d](dst16, ref, ref_stride,
1041
56.1k
                                             bw4 * h_mul, bh4 * v_mul,
1042
56.1k
                                             pos_x & 0x3ff, pos_y & 0x3ff,
1043
56.1k
                                             f->svc[refidx][0].step,
1044
56.1k
                                             f->svc[refidx][1].step
1045
56.1k
                                             HIGHBD_CALL_SUFFIX);
1046
56.1k
        }
1047
179k
    }
1048
1049
499k
    return 0;
1050
499k
}
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
29.0k
{
1057
29.0k
    assert(!(t->bx & 1) && !(t->by & 1));
1058
29.0k
    const Dav1dFrameContext *const f = t->f;
1059
29.0k
    /*const*/ refmvs_block **r = &t->rt.r[(t->by & 31) + 5];
1060
29.0k
    pixel *const lap = bitfn(t->scratch.lap);
1061
29.0k
    const int ss_ver = !!pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1062
29.0k
    const int ss_hor = !!pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1063
29.0k
    const int h_mul = 4 >> ss_hor, v_mul = 4 >> ss_ver;
1064
29.0k
    int res;
1065
1066
29.0k
    if (t->by > t->ts->tiling.row_start &&
1067
25.2k
        (!pl || b_dim[0] * h_mul + b_dim[1] * v_mul >= 16))
1068
16.5k
    {
1069
35.2k
        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
18.7k
            const refmvs_block *const a_r = &r[-1][t->bx + x + 1];
1072
18.7k
            const uint8_t *const a_b_dim = dav1d_block_dimensions[a_r->bs];
1073
18.7k
            const int step4 = iclip(a_b_dim[0], 2, 16);
1074
1075
18.7k
            if (a_r->ref.ref[0] > 0) {
1076
18.4k
                const int ow4 = imin(step4, b_dim[0]);
1077
18.4k
                const int oh4 = imin(b_dim[1], 16) >> 1;
1078
18.4k
                res = mc(t, lap, NULL, ow4 * h_mul * sizeof(pixel), ow4, (oh4 * 3 + 3) >> 2,
1079
18.4k
                         t->bx + x, t->by, pl, a_r->mv.mv[0],
1080
18.4k
                         &f->refp[a_r->ref.ref[0] - 1], a_r->ref.ref[0] - 1,
1081
18.4k
                         dav1d_filter_2d[t->a->filter[1][bx4 + x + 1]][t->a->filter[0][bx4 + x + 1]]);
1082
18.4k
                if (res) return res;
1083
18.4k
                f->dsp->mc.blend_h(&dst[x * h_mul], dst_stride, lap,
1084
18.4k
                                   h_mul * ow4, v_mul * oh4);
1085
18.4k
                i++;
1086
18.4k
            }
1087
18.7k
            x += step4;
1088
18.7k
        }
1089
16.5k
    }
1090
1091
29.0k
    if (t->bx > t->ts->tiling.col_start)
1092
44.1k
        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
22.9k
            const refmvs_block *const l_r = &r[y + 1][t->bx - 1];
1095
22.9k
            const uint8_t *const l_b_dim = dav1d_block_dimensions[l_r->bs];
1096
22.9k
            const int step4 = iclip(l_b_dim[1], 2, 16);
1097
1098
22.9k
            if (l_r->ref.ref[0] > 0) {
1099
22.5k
                const int ow4 = imin(b_dim[0], 16) >> 1;
1100
22.5k
                const int oh4 = imin(step4, b_dim[1]);
1101
22.5k
                res = mc(t, lap, NULL, h_mul * ow4 * sizeof(pixel), ow4, oh4,
1102
22.5k
                         t->bx, t->by + y, pl, l_r->mv.mv[0],
1103
22.5k
                         &f->refp[l_r->ref.ref[0] - 1], l_r->ref.ref[0] - 1,
1104
22.5k
                         dav1d_filter_2d[t->l.filter[1][by4 + y + 1]][t->l.filter[0][by4 + y + 1]]);
1105
22.5k
                if (res) return res;
1106
22.5k
                f->dsp->mc.blend_v(&dst[y * v_mul * PXSTRIDE(dst_stride)],
1107
22.5k
                                   dst_stride, lap, h_mul * ow4, v_mul * oh4);
1108
22.5k
                i++;
1109
22.5k
            }
1110
22.9k
            y += step4;
1111
22.9k
        }
1112
29.0k
    return 0;
1113
29.0k
}
1114
1115
static int warp_affine(Dav1dTaskContext *const t,
1116
                       pixel *dst8, int16_t *dst16, const ptrdiff_t dstride,
1117
                       const uint8_t *const b_dim, const int pl,
1118
                       const Dav1dThreadPicture *const refp,
1119
                       const Dav1dWarpedMotionParams *const wmp)
1120
12.1k
{
1121
12.1k
    assert((dst8 != NULL) ^ (dst16 != NULL));
1122
12.1k
    const Dav1dFrameContext *const f = t->f;
1123
12.1k
    const Dav1dDSPContext *const dsp = f->dsp;
1124
12.1k
    const int ss_ver = !!pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1125
12.1k
    const int ss_hor = !!pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1126
12.1k
    const int h_mul = 4 >> ss_hor, v_mul = 4 >> ss_ver;
1127
12.1k
    assert(!((b_dim[0] * h_mul) & 7) && !((b_dim[1] * v_mul) & 7));
1128
12.1k
    const int32_t *const mat = wmp->matrix;
1129
12.1k
    const int width = (refp->p.p.w + ss_hor) >> ss_hor;
1130
12.1k
    const int height = (refp->p.p.h + ss_ver) >> ss_ver;
1131
1132
40.1k
    for (int y = 0; y < b_dim[1] * v_mul; y += 8) {
1133
28.0k
        const int src_y = t->by * 4 + ((y + 4) << ss_ver);
1134
28.0k
        const int64_t mat3_y = (int64_t) mat[3] * src_y + mat[0];
1135
28.0k
        const int64_t mat5_y = (int64_t) mat[5] * src_y + mat[1];
1136
100k
        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
72.0k
            const int src_x = t->bx * 4 + ((x + 4) << ss_hor);
1140
72.0k
            const int64_t mvx = ((int64_t) mat[2] * src_x + mat3_y) >> ss_hor;
1141
72.0k
            const int64_t mvy = ((int64_t) mat[4] * src_x + mat5_y) >> ss_ver;
1142
1143
72.0k
            const int dx = (int) (mvx >> 16) - 4;
1144
72.0k
            const int mx = (((int) mvx & 0xffff) - wmp->u.p.alpha * 4 -
1145
72.0k
                                                   wmp->u.p.beta  * 7) & ~0x3f;
1146
72.0k
            const int dy = (int) (mvy >> 16) - 4;
1147
72.0k
            const int my = (((int) mvy & 0xffff) - wmp->u.p.gamma * 4 -
1148
72.0k
                                                   wmp->u.p.delta * 4) & ~0x3f;
1149
1150
72.0k
            const pixel *ref_ptr;
1151
72.0k
            ptrdiff_t ref_stride = refp->p.stride[!!pl];
1152
1153
72.0k
            if (dx < 3 || dx + 8 + 4 > width || dy < 3 || dy + 8 + 4 > height) {
1154
36.9k
                pixel *const emu_edge_buf = bitfn(t->scratch.emu_edge);
1155
36.9k
                f->dsp->mc.emu_edge(15, 15, width, height, dx - 3, dy - 3,
1156
36.9k
                                    emu_edge_buf, 32 * sizeof(pixel),
1157
36.9k
                                    refp->p.data[pl], ref_stride);
1158
36.9k
                ref_ptr = &emu_edge_buf[32 * 3 + 3];
1159
36.9k
                ref_stride = 32 * sizeof(pixel);
1160
36.9k
            } else {
1161
35.1k
                ref_ptr = ((pixel *) refp->p.data[pl]) + PXSTRIDE(ref_stride) * dy + dx;
1162
35.1k
            }
1163
72.0k
            if (dst16 != NULL)
1164
8.58k
                dsp->mc.warp8x8t(&dst16[x], dstride, ref_ptr, ref_stride,
1165
8.58k
                                 wmp->u.abcd, mx, my HIGHBD_CALL_SUFFIX);
1166
63.5k
            else
1167
63.5k
                dsp->mc.warp8x8(&dst8[x], dstride, ref_ptr, ref_stride,
1168
63.5k
                                wmp->u.abcd, mx, my HIGHBD_CALL_SUFFIX);
1169
72.0k
        }
1170
28.0k
        if (dst8) dst8  += 8 * PXSTRIDE(dstride);
1171
2.71k
        else      dst16 += 8 * dstride;
1172
28.0k
    }
1173
12.1k
    return 0;
1174
12.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.14M
{
1180
1.14M
    Dav1dTileState *const ts = t->ts;
1181
1.14M
    const Dav1dFrameContext *const f = t->f;
1182
1.14M
    const Dav1dDSPContext *const dsp = f->dsp;
1183
1.14M
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1184
1.14M
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1185
1.14M
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1186
1.14M
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1187
1.14M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1188
1.14M
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1189
1.14M
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1190
1.14M
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1191
1.14M
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1192
822k
                           (bw4 > ss_hor || t->bx & 1) &&
1193
766k
                           (bh4 > ss_ver || t->by & 1);
1194
1.14M
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->tx];
1195
1.14M
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
1196
1197
    // coefficient coding
1198
1.14M
    pixel *const edge = bitfn(t->scratch.edge) + 128;
1199
1.14M
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
1200
1201
1.14M
    const int intra_edge_filter_flag = f->seq_hdr->intra_edge_filter << 10;
1202
1203
2.33M
    for (int init_y = 0; init_y < h4; init_y += 16) {
1204
1.18M
        const int sub_h4 = imin(h4, 16 + init_y);
1205
1.18M
        const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
1206
2.44M
        for (int init_x = 0; init_x < w4; init_x += 16) {
1207
1.25M
            if (b->pal_sz[0]) {
1208
6.04k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1209
6.04k
                             4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1210
6.04k
                const uint8_t *pal_idx;
1211
6.04k
                if (t->frame_thread.pass) {
1212
6.04k
                    const int p = t->frame_thread.pass & 1;
1213
6.04k
                    assert(ts->frame_thread[p].pal_idx);
1214
6.04k
                    pal_idx = ts->frame_thread[p].pal_idx;
1215
6.04k
                    ts->frame_thread[p].pal_idx += bw4 * bh4 * 8;
1216
6.04k
                } else {
1217
0
                    pal_idx = t->scratch.pal_idx_y;
1218
0
                }
1219
6.04k
                const pixel *const pal = t->frame_thread.pass ?
1220
6.04k
                    f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1221
6.04k
                                        ((t->bx >> 1) + (t->by & 1))][0] :
1222
6.04k
                    bytefn(t->scratch.pal)[0];
1223
6.04k
                f->dsp->ipred.pal_pred(dst, f->cur.stride[0], pal,
1224
6.04k
                                       pal_idx, bw4 * 4, bh4 * 4);
1225
6.04k
                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.04k
            }
1229
1230
1.25M
            const int intra_flags = (sm_flag(t->a, bx4) |
1231
1.25M
                                     sm_flag(&t->l, by4) |
1232
1.25M
                                     intra_edge_filter_flag);
1233
1.25M
            const int sb_has_tr = init_x + 16 < w4 ? 1 : init_y ? 0 :
1234
1.18M
                              intra_edge_flags & EDGE_I444_TOP_HAS_RIGHT;
1235
1.25M
            const int sb_has_bl = init_x ? 0 : init_y + 16 < h4 ? 1 :
1236
1.18M
                              intra_edge_flags & EDGE_I444_LEFT_HAS_BOTTOM;
1237
1.25M
            int y, x;
1238
1.25M
            const int sub_w4 = imin(w4, init_x + 16);
1239
2.81M
            for (y = init_y, t->by += init_y; y < sub_h4;
1240
1.56M
                 y += t_dim->h, t->by += t_dim->h)
1241
1.56M
            {
1242
1.56M
                pixel *dst = ((pixel *) f->cur.data[0]) +
1243
1.56M
                               4 * (t->by * PXSTRIDE(f->cur.stride[0]) +
1244
1.56M
                                    t->bx + init_x);
1245
5.05M
                for (x = init_x, t->bx += init_x; x < sub_w4;
1246
3.49M
                     x += t_dim->w, t->bx += t_dim->w)
1247
3.49M
                {
1248
3.49M
                    if (b->pal_sz[0]) goto skip_y_pred;
1249
1250
3.48M
                    int angle = b->y_angle;
1251
3.48M
                    const enum EdgeFlags edge_flags =
1252
3.48M
                        (((y > init_y || !sb_has_tr) && (x + t_dim->w >= sub_w4)) ?
1253
2.73M
                             0 : EDGE_I444_TOP_HAS_RIGHT) |
1254
3.48M
                        ((x > init_x || (!sb_has_bl && y + t_dim->h >= sub_h4)) ?
1255
2.63M
                             0 : EDGE_I444_LEFT_HAS_BOTTOM);
1256
3.48M
                    const pixel *top_sb_edge = NULL;
1257
3.48M
                    if (!(t->by & (f->sb_step - 1))) {
1258
416k
                        top_sb_edge = f->ipred_edge[0];
1259
416k
                        const int sby = t->by >> f->sb_shift;
1260
416k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1261
416k
                    }
1262
3.48M
                    const enum IntraPredMode m =
1263
3.48M
                        bytefn(dav1d_prepare_intra_edges)(t->bx,
1264
3.48M
                                                          t->bx > ts->tiling.col_start,
1265
3.48M
                                                          t->by,
1266
3.48M
                                                          t->by > ts->tiling.row_start,
1267
3.48M
                                                          ts->tiling.col_end,
1268
3.48M
                                                          ts->tiling.row_end,
1269
3.48M
                                                          edge_flags, dst,
1270
3.48M
                                                          f->cur.stride[0], top_sb_edge,
1271
3.48M
                                                          b->y_mode, &angle,
1272
3.48M
                                                          t_dim->w, t_dim->h,
1273
3.48M
                                                          f->seq_hdr->intra_edge_filter,
1274
3.48M
                                                          edge HIGHBD_CALL_SUFFIX);
1275
3.48M
                    dsp->ipred.intra_pred[m](dst, f->cur.stride[0], edge,
1276
3.48M
                                             t_dim->w * 4, t_dim->h * 4,
1277
3.48M
                                             angle | intra_flags,
1278
3.48M
                                             4 * f->bw - 4 * t->bx,
1279
3.48M
                                             4 * f->bh - 4 * t->by
1280
3.48M
                                             HIGHBD_CALL_SUFFIX);
1281
1282
3.48M
                    if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1283
0
                        hex_dump(edge - t_dim->h * 4, t_dim->h * 4,
1284
0
                                 t_dim->h * 4, 2, "l");
1285
0
                        hex_dump(edge, 0, 1, 1, "tl");
1286
0
                        hex_dump(edge + 1, t_dim->w * 4,
1287
0
                                 t_dim->w * 4, 2, "t");
1288
0
                        hex_dump(dst, f->cur.stride[0],
1289
0
                                 t_dim->w * 4, t_dim->h * 4, "y-intra-pred");
1290
0
                    }
1291
1292
3.49M
                skip_y_pred: {}
1293
3.49M
                    if (!b->skip) {
1294
925k
                        coef *cf;
1295
925k
                        int eob;
1296
925k
                        enum TxfmType txtp;
1297
925k
                        if (t->frame_thread.pass) {
1298
925k
                            const int p = t->frame_thread.pass & 1;
1299
925k
                            const int cbi = *ts->frame_thread[p].cbi++;
1300
925k
                            cf = ts->frame_thread[p].cf;
1301
925k
                            ts->frame_thread[p].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
1302
925k
                            eob  = cbi >> 5;
1303
925k
                            txtp = cbi & 0x1f;
1304
18.4E
                        } else {
1305
18.4E
                            uint8_t cf_ctx;
1306
18.4E
                            cf = bitfn(t->cf);
1307
18.4E
                            eob = decode_coefs(t, &t->a->lcoef[bx4 + x],
1308
18.4E
                                               &t->l.lcoef[by4 + y], b->tx, bs,
1309
18.4E
                                               b, 1, 0, cf, &txtp, &cf_ctx);
1310
18.4E
                            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
18.4E
                            dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
1314
18.4E
                            dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
1315
18.4E
                        }
1316
925k
                        if (eob >= 0) {
1317
732k
                            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
732k
                            dsp->itx.itxfm_add[b->tx]
1321
732k
                                              [txtp](dst,
1322
732k
                                                     f->cur.stride[0],
1323
732k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1324
732k
                            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
732k
                        }
1328
2.56M
                    } else if (!t->frame_thread.pass) {
1329
0
                        dav1d_memset_pow2[t_dim->lw](&t->a->lcoef[bx4 + x], 0x40);
1330
0
                        dav1d_memset_pow2[t_dim->lh](&t->l.lcoef[by4 + y], 0x40);
1331
0
                    }
1332
3.49M
                    dst += 4 * t_dim->w;
1333
3.49M
                }
1334
1.56M
                t->bx -= x;
1335
1.56M
            }
1336
1.25M
            t->by -= y;
1337
1338
1.25M
            if (!has_chroma) continue;
1339
1340
768k
            const ptrdiff_t stride = f->cur.stride[1];
1341
1342
768k
            if (b->uv_mode == CFL_PRED) {
1343
137k
                assert(!init_x && !init_y);
1344
1345
137k
                int16_t *const ac = t->scratch.ac;
1346
137k
                pixel *y_src = ((pixel *) f->cur.data[0]) + 4 * (t->bx & ~ss_hor) +
1347
137k
                                 4 * (t->by & ~ss_ver) * PXSTRIDE(f->cur.stride[0]);
1348
137k
                const ptrdiff_t uv_off = 4 * ((t->bx >> ss_hor) +
1349
137k
                                              (t->by >> ss_ver) * PXSTRIDE(stride));
1350
137k
                pixel *const uv_dst[2] = { ((pixel *) f->cur.data[1]) + uv_off,
1351
137k
                                           ((pixel *) f->cur.data[2]) + uv_off };
1352
1353
137k
                const int furthest_r =
1354
137k
                    ((cw4 << ss_hor) + t_dim->w - 1) & ~(t_dim->w - 1);
1355
137k
                const int furthest_b =
1356
137k
                    ((ch4 << ss_ver) + t_dim->h - 1) & ~(t_dim->h - 1);
1357
137k
                dsp->ipred.cfl_ac[f->cur.p.layout - 1](ac, y_src, f->cur.stride[0],
1358
137k
                                                         cbw4 - (furthest_r >> ss_hor),
1359
137k
                                                         cbh4 - (furthest_b >> ss_ver),
1360
137k
                                                         cbw4 * 4, cbh4 * 4);
1361
412k
                for (int pl = 0; pl < 2; pl++) {
1362
275k
                    if (!b->cfl_alpha[pl]) continue;
1363
211k
                    int angle = 0;
1364
211k
                    const pixel *top_sb_edge = NULL;
1365
211k
                    if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1366
38.7k
                        top_sb_edge = f->ipred_edge[pl + 1];
1367
38.7k
                        const int sby = t->by >> f->sb_shift;
1368
38.7k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1369
38.7k
                    }
1370
211k
                    const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1371
211k
                    const int xstart = ts->tiling.col_start >> ss_hor;
1372
211k
                    const int ystart = ts->tiling.row_start >> ss_ver;
1373
211k
                    const enum IntraPredMode m =
1374
211k
                        bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1375
211k
                                                          ypos, ypos > ystart,
1376
211k
                                                          ts->tiling.col_end >> ss_hor,
1377
211k
                                                          ts->tiling.row_end >> ss_ver,
1378
211k
                                                          0, uv_dst[pl], stride,
1379
211k
                                                          top_sb_edge, DC_PRED, &angle,
1380
211k
                                                          uv_t_dim->w, uv_t_dim->h, 0,
1381
211k
                                                          edge HIGHBD_CALL_SUFFIX);
1382
211k
                    dsp->ipred.cfl_pred[m](uv_dst[pl], stride, edge,
1383
211k
                                           uv_t_dim->w * 4,
1384
211k
                                           uv_t_dim->h * 4,
1385
211k
                                           ac, b->cfl_alpha[pl]
1386
211k
                                           HIGHBD_CALL_SUFFIX);
1387
211k
                }
1388
137k
                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
630k
            } else if (b->pal_sz[1]) {
1394
994
                const ptrdiff_t uv_dstoff = 4 * ((t->bx >> ss_hor) +
1395
994
                                              (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1396
994
                const pixel (*pal)[8];
1397
994
                const uint8_t *pal_idx;
1398
994
                if (t->frame_thread.pass) {
1399
994
                    const int p = t->frame_thread.pass & 1;
1400
994
                    assert(ts->frame_thread[p].pal_idx);
1401
994
                    pal = f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1402
994
                                              ((t->bx >> 1) + (t->by & 1))];
1403
994
                    pal_idx = ts->frame_thread[p].pal_idx;
1404
994
                    ts->frame_thread[p].pal_idx += cbw4 * cbh4 * 8;
1405
994
                } else {
1406
0
                    pal = bytefn(t->scratch.pal);
1407
0
                    pal_idx = t->scratch.pal_idx_uv;
1408
0
                }
1409
1410
994
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[1]) + uv_dstoff,
1411
994
                                       f->cur.stride[1], pal[1],
1412
994
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1413
994
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[2]) + uv_dstoff,
1414
994
                                       f->cur.stride[1], pal[2],
1415
994
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1416
994
                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
994
            }
1425
1426
768k
            const int sm_uv_fl = sm_uv_flag(t->a, cbx4) |
1427
768k
                                 sm_uv_flag(&t->l, cby4);
1428
768k
            const int uv_sb_has_tr =
1429
768k
                ((init_x + 16) >> ss_hor) < cw4 ? 1 : init_y ? 0 :
1430
727k
                intra_edge_flags & (EDGE_I420_TOP_HAS_RIGHT >> (f->cur.p.layout - 1));
1431
768k
            const int uv_sb_has_bl =
1432
768k
                init_x ? 0 : ((init_y + 16) >> ss_ver) < ch4 ? 1 :
1433
727k
                intra_edge_flags & (EDGE_I420_LEFT_HAS_BOTTOM >> (f->cur.p.layout - 1));
1434
768k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
1435
2.30M
            for (int pl = 0; pl < 2; pl++) {
1436
3.26M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
1437
1.72M
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
1438
1.72M
                {
1439
1.72M
                    pixel *dst = ((pixel *) f->cur.data[1 + pl]) +
1440
1.72M
                                   4 * ((t->by >> ss_ver) * PXSTRIDE(stride) +
1441
1.72M
                                        ((t->bx + init_x) >> ss_hor));
1442
4.01M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
1443
2.28M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
1444
2.28M
                    {
1445
2.28M
                        if ((b->uv_mode == CFL_PRED && b->cfl_alpha[pl]) ||
1446
2.07M
                            b->pal_sz[1])
1447
214k
                        {
1448
214k
                            goto skip_uv_pred;
1449
214k
                        }
1450
1451
2.07M
                        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.07M
                        const enum EdgeFlags edge_flags =
1456
2.07M
                            (((y > (init_y >> ss_ver) || !uv_sb_has_tr) &&
1457
1.04M
                              (x + uv_t_dim->w >= sub_cw4)) ?
1458
1.46M
                                 0 : EDGE_I444_TOP_HAS_RIGHT) |
1459
2.07M
                            ((x > (init_x >> ss_hor) ||
1460
1.51M
                              (!uv_sb_has_bl && y + uv_t_dim->h >= sub_ch4)) ?
1461
1.32M
                                 0 : EDGE_I444_LEFT_HAS_BOTTOM);
1462
2.07M
                        const pixel *top_sb_edge = NULL;
1463
2.07M
                        if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1464
482k
                            top_sb_edge = f->ipred_edge[1 + pl];
1465
482k
                            const int sby = t->by >> f->sb_shift;
1466
482k
                            top_sb_edge += f->sb128w * 128 * (sby - 1);
1467
482k
                        }
1468
2.07M
                        const enum IntraPredMode uv_mode =
1469
2.07M
                             b->uv_mode == CFL_PRED ? DC_PRED : b->uv_mode;
1470
2.07M
                        const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1471
2.07M
                        const int xstart = ts->tiling.col_start >> ss_hor;
1472
2.07M
                        const int ystart = ts->tiling.row_start >> ss_ver;
1473
2.07M
                        const enum IntraPredMode m =
1474
2.07M
                            bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1475
2.07M
                                                              ypos, ypos > ystart,
1476
2.07M
                                                              ts->tiling.col_end >> ss_hor,
1477
2.07M
                                                              ts->tiling.row_end >> ss_ver,
1478
2.07M
                                                              edge_flags, dst, stride,
1479
2.07M
                                                              top_sb_edge, uv_mode,
1480
2.07M
                                                              &angle, uv_t_dim->w,
1481
2.07M
                                                              uv_t_dim->h,
1482
2.07M
                                                              f->seq_hdr->intra_edge_filter,
1483
2.07M
                                                              edge HIGHBD_CALL_SUFFIX);
1484
2.07M
                        angle |= intra_edge_filter_flag;
1485
2.07M
                        dsp->ipred.intra_pred[m](dst, stride, edge,
1486
2.07M
                                                 uv_t_dim->w * 4,
1487
2.07M
                                                 uv_t_dim->h * 4,
1488
2.07M
                                                 angle | sm_uv_fl,
1489
2.07M
                                                 (4 * f->bw + ss_hor -
1490
2.07M
                                                  4 * (t->bx & ~ss_hor)) >> ss_hor,
1491
2.07M
                                                 (4 * f->bh + ss_ver -
1492
2.07M
                                                  4 * (t->by & ~ss_ver)) >> ss_ver
1493
2.07M
                                                 HIGHBD_CALL_SUFFIX);
1494
2.07M
                        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.28M
                    skip_uv_pred: {}
1505
2.28M
                        if (!b->skip) {
1506
799k
                            enum TxfmType txtp;
1507
799k
                            int eob;
1508
799k
                            coef *cf;
1509
799k
                            if (t->frame_thread.pass) {
1510
799k
                                const int p = t->frame_thread.pass & 1;
1511
799k
                                const int cbi = *ts->frame_thread[p].cbi++;
1512
799k
                                cf = ts->frame_thread[p].cf;
1513
799k
                                ts->frame_thread[p].cf += uv_t_dim->w * uv_t_dim->h * 16;
1514
799k
                                eob  = cbi >> 5;
1515
799k
                                txtp = cbi & 0x1f;
1516
18.4E
                            } else {
1517
18.4E
                                uint8_t cf_ctx;
1518
18.4E
                                cf = bitfn(t->cf);
1519
18.4E
                                eob = decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
1520
18.4E
                                                   &t->l.ccoef[pl][cby4 + y],
1521
18.4E
                                                   b->uvtx, bs, b, 1, 1 + pl, cf,
1522
18.4E
                                                   &txtp, &cf_ctx);
1523
18.4E
                                if (DEBUG_BLOCK_INFO)
1524
0
                                    printf("Post-uv-cf-blk[pl=%d,tx=%d,"
1525
0
                                           "txtp=%d,eob=%d]: r=%d [x=%d,cbx4=%d]\n",
1526
0
                                           pl, b->uvtx, txtp, eob, ts->msac.rng, x, cbx4);
1527
18.4E
                                int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
1528
18.4E
                                int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
1529
18.4E
                                dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
1530
18.4E
                                dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
1531
18.4E
                            }
1532
799k
                            if (eob >= 0) {
1533
236k
                                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
236k
                                dsp->itx.itxfm_add[b->uvtx]
1537
236k
                                                  [txtp](dst, stride,
1538
236k
                                                         cf, eob HIGHBD_CALL_SUFFIX);
1539
236k
                                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
236k
                            }
1543
1.48M
                        } 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.28M
                        dst += uv_t_dim->w * 4;
1548
2.28M
                    }
1549
1.72M
                    t->bx -= x << ss_hor;
1550
1.72M
                }
1551
1.53M
                t->by -= y << ss_ver;
1552
1.53M
            }
1553
768k
        }
1554
1.18M
    }
1555
1.14M
}
dav1d_recon_b_intra_8bpc
Line
Count
Source
1179
660k
{
1180
660k
    Dav1dTileState *const ts = t->ts;
1181
660k
    const Dav1dFrameContext *const f = t->f;
1182
660k
    const Dav1dDSPContext *const dsp = f->dsp;
1183
660k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1184
660k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1185
660k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1186
660k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1187
660k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1188
660k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1189
660k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1190
660k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1191
660k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1192
625k
                           (bw4 > ss_hor || t->bx & 1) &&
1193
579k
                           (bh4 > ss_ver || t->by & 1);
1194
660k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->tx];
1195
660k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
1196
1197
    // coefficient coding
1198
660k
    pixel *const edge = bitfn(t->scratch.edge) + 128;
1199
660k
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
1200
1201
660k
    const int intra_edge_filter_flag = f->seq_hdr->intra_edge_filter << 10;
1202
1203
1.34M
    for (int init_y = 0; init_y < h4; init_y += 16) {
1204
682k
        const int sub_h4 = imin(h4, 16 + init_y);
1205
682k
        const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
1206
1.40M
        for (int init_x = 0; init_x < w4; init_x += 16) {
1207
718k
            if (b->pal_sz[0]) {
1208
2.37k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1209
2.37k
                             4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1210
2.37k
                const uint8_t *pal_idx;
1211
2.37k
                if (t->frame_thread.pass) {
1212
2.37k
                    const int p = t->frame_thread.pass & 1;
1213
2.37k
                    assert(ts->frame_thread[p].pal_idx);
1214
2.37k
                    pal_idx = ts->frame_thread[p].pal_idx;
1215
2.37k
                    ts->frame_thread[p].pal_idx += bw4 * bh4 * 8;
1216
2.37k
                } else {
1217
0
                    pal_idx = t->scratch.pal_idx_y;
1218
0
                }
1219
2.37k
                const pixel *const pal = t->frame_thread.pass ?
1220
2.37k
                    f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1221
2.37k
                                        ((t->bx >> 1) + (t->by & 1))][0] :
1222
2.37k
                    bytefn(t->scratch.pal)[0];
1223
2.37k
                f->dsp->ipred.pal_pred(dst, f->cur.stride[0], pal,
1224
2.37k
                                       pal_idx, bw4 * 4, bh4 * 4);
1225
2.37k
                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
2.37k
            }
1229
1230
718k
            const int intra_flags = (sm_flag(t->a, bx4) |
1231
718k
                                     sm_flag(&t->l, by4) |
1232
718k
                                     intra_edge_filter_flag);
1233
718k
            const int sb_has_tr = init_x + 16 < w4 ? 1 : init_y ? 0 :
1234
682k
                              intra_edge_flags & EDGE_I444_TOP_HAS_RIGHT;
1235
718k
            const int sb_has_bl = init_x ? 0 : init_y + 16 < h4 ? 1 :
1236
682k
                              intra_edge_flags & EDGE_I444_LEFT_HAS_BOTTOM;
1237
718k
            int y, x;
1238
718k
            const int sub_w4 = imin(w4, init_x + 16);
1239
1.60M
            for (y = init_y, t->by += init_y; y < sub_h4;
1240
890k
                 y += t_dim->h, t->by += t_dim->h)
1241
891k
            {
1242
891k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1243
891k
                               4 * (t->by * PXSTRIDE(f->cur.stride[0]) +
1244
891k
                                    t->bx + init_x);
1245
3.24M
                for (x = init_x, t->bx += init_x; x < sub_w4;
1246
2.35M
                     x += t_dim->w, t->bx += t_dim->w)
1247
2.35M
                {
1248
2.35M
                    if (b->pal_sz[0]) goto skip_y_pred;
1249
1250
2.35M
                    int angle = b->y_angle;
1251
2.35M
                    const enum EdgeFlags edge_flags =
1252
2.35M
                        (((y > init_y || !sb_has_tr) && (x + t_dim->w >= sub_w4)) ?
1253
1.91M
                             0 : EDGE_I444_TOP_HAS_RIGHT) |
1254
2.35M
                        ((x > init_x || (!sb_has_bl && y + t_dim->h >= sub_h4)) ?
1255
1.86M
                             0 : EDGE_I444_LEFT_HAS_BOTTOM);
1256
2.35M
                    const pixel *top_sb_edge = NULL;
1257
2.35M
                    if (!(t->by & (f->sb_step - 1))) {
1258
223k
                        top_sb_edge = f->ipred_edge[0];
1259
223k
                        const int sby = t->by >> f->sb_shift;
1260
223k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1261
223k
                    }
1262
2.35M
                    const enum IntraPredMode m =
1263
2.35M
                        bytefn(dav1d_prepare_intra_edges)(t->bx,
1264
2.35M
                                                          t->bx > ts->tiling.col_start,
1265
2.35M
                                                          t->by,
1266
2.35M
                                                          t->by > ts->tiling.row_start,
1267
2.35M
                                                          ts->tiling.col_end,
1268
2.35M
                                                          ts->tiling.row_end,
1269
2.35M
                                                          edge_flags, dst,
1270
2.35M
                                                          f->cur.stride[0], top_sb_edge,
1271
2.35M
                                                          b->y_mode, &angle,
1272
2.35M
                                                          t_dim->w, t_dim->h,
1273
2.35M
                                                          f->seq_hdr->intra_edge_filter,
1274
2.35M
                                                          edge HIGHBD_CALL_SUFFIX);
1275
2.35M
                    dsp->ipred.intra_pred[m](dst, f->cur.stride[0], edge,
1276
2.35M
                                             t_dim->w * 4, t_dim->h * 4,
1277
2.35M
                                             angle | intra_flags,
1278
2.35M
                                             4 * f->bw - 4 * t->bx,
1279
2.35M
                                             4 * f->bh - 4 * t->by
1280
2.35M
                                             HIGHBD_CALL_SUFFIX);
1281
1282
2.35M
                    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
2.35M
                skip_y_pred: {}
1293
2.35M
                    if (!b->skip) {
1294
514k
                        coef *cf;
1295
514k
                        int eob;
1296
514k
                        enum TxfmType txtp;
1297
514k
                        if (t->frame_thread.pass) {
1298
514k
                            const int p = t->frame_thread.pass & 1;
1299
514k
                            const int cbi = *ts->frame_thread[p].cbi++;
1300
514k
                            cf = ts->frame_thread[p].cf;
1301
514k
                            ts->frame_thread[p].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
1302
514k
                            eob  = cbi >> 5;
1303
514k
                            txtp = cbi & 0x1f;
1304
18.4E
                        } else {
1305
18.4E
                            uint8_t cf_ctx;
1306
18.4E
                            cf = bitfn(t->cf);
1307
18.4E
                            eob = decode_coefs(t, &t->a->lcoef[bx4 + x],
1308
18.4E
                                               &t->l.lcoef[by4 + y], b->tx, bs,
1309
18.4E
                                               b, 1, 0, cf, &txtp, &cf_ctx);
1310
18.4E
                            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
18.4E
                            dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
1314
18.4E
                            dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
1315
18.4E
                        }
1316
514k
                        if (eob >= 0) {
1317
425k
                            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
425k
                            dsp->itx.itxfm_add[b->tx]
1321
425k
                                              [txtp](dst,
1322
425k
                                                     f->cur.stride[0],
1323
425k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1324
425k
                            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
425k
                        }
1328
1.84M
                    } 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
2.35M
                    dst += 4 * t_dim->w;
1333
2.35M
                }
1334
890k
                t->bx -= x;
1335
890k
            }
1336
718k
            t->by -= y;
1337
1338
718k
            if (!has_chroma) continue;
1339
1340
566k
            const ptrdiff_t stride = f->cur.stride[1];
1341
1342
566k
            if (b->uv_mode == CFL_PRED) {
1343
104k
                assert(!init_x && !init_y);
1344
1345
104k
                int16_t *const ac = t->scratch.ac;
1346
104k
                pixel *y_src = ((pixel *) f->cur.data[0]) + 4 * (t->bx & ~ss_hor) +
1347
104k
                                 4 * (t->by & ~ss_ver) * PXSTRIDE(f->cur.stride[0]);
1348
104k
                const ptrdiff_t uv_off = 4 * ((t->bx >> ss_hor) +
1349
104k
                                              (t->by >> ss_ver) * PXSTRIDE(stride));
1350
104k
                pixel *const uv_dst[2] = { ((pixel *) f->cur.data[1]) + uv_off,
1351
104k
                                           ((pixel *) f->cur.data[2]) + uv_off };
1352
1353
104k
                const int furthest_r =
1354
104k
                    ((cw4 << ss_hor) + t_dim->w - 1) & ~(t_dim->w - 1);
1355
104k
                const int furthest_b =
1356
104k
                    ((ch4 << ss_ver) + t_dim->h - 1) & ~(t_dim->h - 1);
1357
104k
                dsp->ipred.cfl_ac[f->cur.p.layout - 1](ac, y_src, f->cur.stride[0],
1358
104k
                                                         cbw4 - (furthest_r >> ss_hor),
1359
104k
                                                         cbh4 - (furthest_b >> ss_ver),
1360
104k
                                                         cbw4 * 4, cbh4 * 4);
1361
313k
                for (int pl = 0; pl < 2; pl++) {
1362
208k
                    if (!b->cfl_alpha[pl]) continue;
1363
158k
                    int angle = 0;
1364
158k
                    const pixel *top_sb_edge = NULL;
1365
158k
                    if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1366
21.7k
                        top_sb_edge = f->ipred_edge[pl + 1];
1367
21.7k
                        const int sby = t->by >> f->sb_shift;
1368
21.7k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1369
21.7k
                    }
1370
158k
                    const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1371
158k
                    const int xstart = ts->tiling.col_start >> ss_hor;
1372
158k
                    const int ystart = ts->tiling.row_start >> ss_ver;
1373
158k
                    const enum IntraPredMode m =
1374
158k
                        bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1375
158k
                                                          ypos, ypos > ystart,
1376
158k
                                                          ts->tiling.col_end >> ss_hor,
1377
158k
                                                          ts->tiling.row_end >> ss_ver,
1378
158k
                                                          0, uv_dst[pl], stride,
1379
158k
                                                          top_sb_edge, DC_PRED, &angle,
1380
158k
                                                          uv_t_dim->w, uv_t_dim->h, 0,
1381
158k
                                                          edge HIGHBD_CALL_SUFFIX);
1382
158k
                    dsp->ipred.cfl_pred[m](uv_dst[pl], stride, edge,
1383
158k
                                           uv_t_dim->w * 4,
1384
158k
                                           uv_t_dim->h * 4,
1385
158k
                                           ac, b->cfl_alpha[pl]
1386
158k
                                           HIGHBD_CALL_SUFFIX);
1387
158k
                }
1388
104k
                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
462k
            } else if (b->pal_sz[1]) {
1394
894
                const ptrdiff_t uv_dstoff = 4 * ((t->bx >> ss_hor) +
1395
894
                                              (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1396
894
                const pixel (*pal)[8];
1397
894
                const uint8_t *pal_idx;
1398
894
                if (t->frame_thread.pass) {
1399
894
                    const int p = t->frame_thread.pass & 1;
1400
894
                    assert(ts->frame_thread[p].pal_idx);
1401
894
                    pal = f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1402
894
                                              ((t->bx >> 1) + (t->by & 1))];
1403
894
                    pal_idx = ts->frame_thread[p].pal_idx;
1404
894
                    ts->frame_thread[p].pal_idx += cbw4 * cbh4 * 8;
1405
894
                } else {
1406
0
                    pal = bytefn(t->scratch.pal);
1407
0
                    pal_idx = t->scratch.pal_idx_uv;
1408
0
                }
1409
1410
894
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[1]) + uv_dstoff,
1411
894
                                       f->cur.stride[1], pal[1],
1412
894
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1413
894
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[2]) + uv_dstoff,
1414
894
                                       f->cur.stride[1], pal[2],
1415
894
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1416
894
                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
894
            }
1425
1426
566k
            const int sm_uv_fl = sm_uv_flag(t->a, cbx4) |
1427
566k
                                 sm_uv_flag(&t->l, cby4);
1428
566k
            const int uv_sb_has_tr =
1429
566k
                ((init_x + 16) >> ss_hor) < cw4 ? 1 : init_y ? 0 :
1430
541k
                intra_edge_flags & (EDGE_I420_TOP_HAS_RIGHT >> (f->cur.p.layout - 1));
1431
566k
            const int uv_sb_has_bl =
1432
566k
                init_x ? 0 : ((init_y + 16) >> ss_ver) < ch4 ? 1 :
1433
541k
                intra_edge_flags & (EDGE_I420_LEFT_HAS_BOTTOM >> (f->cur.p.layout - 1));
1434
566k
            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.67M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
1443
1.46M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
1444
1.46M
                    {
1445
1.46M
                        if ((b->uv_mode == CFL_PRED && b->cfl_alpha[pl]) ||
1446
1.30M
                            b->pal_sz[1])
1447
160k
                        {
1448
160k
                            goto skip_uv_pred;
1449
160k
                        }
1450
1451
1.29M
                        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.29M
                        const enum EdgeFlags edge_flags =
1456
1.29M
                            (((y > (init_y >> ss_ver) || !uv_sb_has_tr) &&
1457
608k
                              (x + uv_t_dim->w >= sub_cw4)) ?
1458
875k
                                 0 : EDGE_I444_TOP_HAS_RIGHT) |
1459
1.29M
                            ((x > (init_x >> ss_hor) ||
1460
1.05M
                              (!uv_sb_has_bl && y + uv_t_dim->h >= sub_ch4)) ?
1461
800k
                                 0 : EDGE_I444_LEFT_HAS_BOTTOM);
1462
1.29M
                        const pixel *top_sb_edge = NULL;
1463
1.29M
                        if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1464
278k
                            top_sb_edge = f->ipred_edge[1 + pl];
1465
278k
                            const int sby = t->by >> f->sb_shift;
1466
278k
                            top_sb_edge += f->sb128w * 128 * (sby - 1);
1467
278k
                        }
1468
1.29M
                        const enum IntraPredMode uv_mode =
1469
1.29M
                             b->uv_mode == CFL_PRED ? DC_PRED : b->uv_mode;
1470
1.29M
                        const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1471
1.29M
                        const int xstart = ts->tiling.col_start >> ss_hor;
1472
1.29M
                        const int ystart = ts->tiling.row_start >> ss_ver;
1473
1.29M
                        const enum IntraPredMode m =
1474
1.29M
                            bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1475
1.29M
                                                              ypos, ypos > ystart,
1476
1.29M
                                                              ts->tiling.col_end >> ss_hor,
1477
1.29M
                                                              ts->tiling.row_end >> ss_ver,
1478
1.29M
                                                              edge_flags, dst, stride,
1479
1.29M
                                                              top_sb_edge, uv_mode,
1480
1.29M
                                                              &angle, uv_t_dim->w,
1481
1.29M
                                                              uv_t_dim->h,
1482
1.29M
                                                              f->seq_hdr->intra_edge_filter,
1483
1.29M
                                                              edge HIGHBD_CALL_SUFFIX);
1484
1.29M
                        angle |= intra_edge_filter_flag;
1485
1.29M
                        dsp->ipred.intra_pred[m](dst, stride, edge,
1486
1.29M
                                                 uv_t_dim->w * 4,
1487
1.29M
                                                 uv_t_dim->h * 4,
1488
1.29M
                                                 angle | sm_uv_fl,
1489
1.29M
                                                 (4 * f->bw + ss_hor -
1490
1.29M
                                                  4 * (t->bx & ~ss_hor)) >> ss_hor,
1491
1.29M
                                                 (4 * f->bh + ss_ver -
1492
1.29M
                                                  4 * (t->by & ~ss_ver)) >> ss_ver
1493
1.29M
                                                 HIGHBD_CALL_SUFFIX);
1494
1.29M
                        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.46M
                    skip_uv_pred: {}
1505
1.46M
                        if (!b->skip) {
1506
534k
                            enum TxfmType txtp;
1507
534k
                            int eob;
1508
534k
                            coef *cf;
1509
534k
                            if (t->frame_thread.pass) {
1510
534k
                                const int p = t->frame_thread.pass & 1;
1511
534k
                                const int cbi = *ts->frame_thread[p].cbi++;
1512
534k
                                cf = ts->frame_thread[p].cf;
1513
534k
                                ts->frame_thread[p].cf += uv_t_dim->w * uv_t_dim->h * 16;
1514
534k
                                eob  = cbi >> 5;
1515
534k
                                txtp = cbi & 0x1f;
1516
18.4E
                            } else {
1517
18.4E
                                uint8_t cf_ctx;
1518
18.4E
                                cf = bitfn(t->cf);
1519
18.4E
                                eob = decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
1520
18.4E
                                                   &t->l.ccoef[pl][cby4 + y],
1521
18.4E
                                                   b->uvtx, bs, b, 1, 1 + pl, cf,
1522
18.4E
                                                   &txtp, &cf_ctx);
1523
18.4E
                                if (DEBUG_BLOCK_INFO)
1524
0
                                    printf("Post-uv-cf-blk[pl=%d,tx=%d,"
1525
0
                                           "txtp=%d,eob=%d]: r=%d [x=%d,cbx4=%d]\n",
1526
0
                                           pl, b->uvtx, txtp, eob, ts->msac.rng, x, cbx4);
1527
18.4E
                                int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
1528
18.4E
                                int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
1529
18.4E
                                dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
1530
18.4E
                                dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
1531
18.4E
                            }
1532
534k
                            if (eob >= 0) {
1533
141k
                                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
141k
                                dsp->itx.itxfm_add[b->uvtx]
1537
141k
                                                  [txtp](dst, stride,
1538
141k
                                                         cf, eob HIGHBD_CALL_SUFFIX);
1539
141k
                                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
141k
                            }
1543
925k
                        } 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.46M
                        dst += uv_t_dim->w * 4;
1548
1.46M
                    }
1549
1.21M
                    t->bx -= x << ss_hor;
1550
1.21M
                }
1551
1.13M
                t->by -= y << ss_ver;
1552
1.13M
            }
1553
566k
        }
1554
682k
    }
1555
660k
}
dav1d_recon_b_intra_16bpc
Line
Count
Source
1179
484k
{
1180
484k
    Dav1dTileState *const ts = t->ts;
1181
484k
    const Dav1dFrameContext *const f = t->f;
1182
484k
    const Dav1dDSPContext *const dsp = f->dsp;
1183
484k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1184
484k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1185
484k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1186
484k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1187
484k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1188
484k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1189
484k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1190
484k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1191
484k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1192
197k
                           (bw4 > ss_hor || t->bx & 1) &&
1193
186k
                           (bh4 > ss_ver || t->by & 1);
1194
484k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->tx];
1195
484k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
1196
1197
    // coefficient coding
1198
484k
    pixel *const edge = bitfn(t->scratch.edge) + 128;
1199
484k
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
1200
1201
484k
    const int intra_edge_filter_flag = f->seq_hdr->intra_edge_filter << 10;
1202
1203
990k
    for (int init_y = 0; init_y < h4; init_y += 16) {
1204
506k
        const int sub_h4 = imin(h4, 16 + init_y);
1205
506k
        const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
1206
1.04M
        for (int init_x = 0; init_x < w4; init_x += 16) {
1207
537k
            if (b->pal_sz[0]) {
1208
3.66k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1209
3.66k
                             4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1210
3.66k
                const uint8_t *pal_idx;
1211
3.66k
                if (t->frame_thread.pass) {
1212
3.66k
                    const int p = t->frame_thread.pass & 1;
1213
3.66k
                    assert(ts->frame_thread[p].pal_idx);
1214
3.66k
                    pal_idx = ts->frame_thread[p].pal_idx;
1215
3.66k
                    ts->frame_thread[p].pal_idx += bw4 * bh4 * 8;
1216
3.66k
                } else {
1217
0
                    pal_idx = t->scratch.pal_idx_y;
1218
0
                }
1219
3.66k
                const pixel *const pal = t->frame_thread.pass ?
1220
3.66k
                    f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1221
3.66k
                                        ((t->bx >> 1) + (t->by & 1))][0] :
1222
3.66k
                    bytefn(t->scratch.pal)[0];
1223
3.66k
                f->dsp->ipred.pal_pred(dst, f->cur.stride[0], pal,
1224
3.66k
                                       pal_idx, bw4 * 4, bh4 * 4);
1225
3.66k
                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1226
0
                    hex_dump(dst, PXSTRIDE(f->cur.stride[0]),
1227
0
                             bw4 * 4, bh4 * 4, "y-pal-pred");
1228
3.66k
            }
1229
1230
537k
            const int intra_flags = (sm_flag(t->a, bx4) |
1231
537k
                                     sm_flag(&t->l, by4) |
1232
537k
                                     intra_edge_filter_flag);
1233
537k
            const int sb_has_tr = init_x + 16 < w4 ? 1 : init_y ? 0 :
1234
506k
                              intra_edge_flags & EDGE_I444_TOP_HAS_RIGHT;
1235
537k
            const int sb_has_bl = init_x ? 0 : init_y + 16 < h4 ? 1 :
1236
506k
                              intra_edge_flags & EDGE_I444_LEFT_HAS_BOTTOM;
1237
537k
            int y, x;
1238
537k
            const int sub_w4 = imin(w4, init_x + 16);
1239
1.20M
            for (y = init_y, t->by += init_y; y < sub_h4;
1240
672k
                 y += t_dim->h, t->by += t_dim->h)
1241
672k
            {
1242
672k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1243
672k
                               4 * (t->by * PXSTRIDE(f->cur.stride[0]) +
1244
672k
                                    t->bx + init_x);
1245
1.81M
                for (x = init_x, t->bx += init_x; x < sub_w4;
1246
1.13M
                     x += t_dim->w, t->bx += t_dim->w)
1247
1.13M
                {
1248
1.13M
                    if (b->pal_sz[0]) goto skip_y_pred;
1249
1250
1.13M
                    int angle = b->y_angle;
1251
1.13M
                    const enum EdgeFlags edge_flags =
1252
1.13M
                        (((y > init_y || !sb_has_tr) && (x + t_dim->w >= sub_w4)) ?
1253
818k
                             0 : EDGE_I444_TOP_HAS_RIGHT) |
1254
1.13M
                        ((x > init_x || (!sb_has_bl && y + t_dim->h >= sub_h4)) ?
1255
767k
                             0 : EDGE_I444_LEFT_HAS_BOTTOM);
1256
1.13M
                    const pixel *top_sb_edge = NULL;
1257
1.13M
                    if (!(t->by & (f->sb_step - 1))) {
1258
193k
                        top_sb_edge = f->ipred_edge[0];
1259
193k
                        const int sby = t->by >> f->sb_shift;
1260
193k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1261
193k
                    }
1262
1.13M
                    const enum IntraPredMode m =
1263
1.13M
                        bytefn(dav1d_prepare_intra_edges)(t->bx,
1264
1.13M
                                                          t->bx > ts->tiling.col_start,
1265
1.13M
                                                          t->by,
1266
1.13M
                                                          t->by > ts->tiling.row_start,
1267
1.13M
                                                          ts->tiling.col_end,
1268
1.13M
                                                          ts->tiling.row_end,
1269
1.13M
                                                          edge_flags, dst,
1270
1.13M
                                                          f->cur.stride[0], top_sb_edge,
1271
1.13M
                                                          b->y_mode, &angle,
1272
1.13M
                                                          t_dim->w, t_dim->h,
1273
1.13M
                                                          f->seq_hdr->intra_edge_filter,
1274
1.13M
                                                          edge HIGHBD_CALL_SUFFIX);
1275
1.13M
                    dsp->ipred.intra_pred[m](dst, f->cur.stride[0], edge,
1276
1.13M
                                             t_dim->w * 4, t_dim->h * 4,
1277
1.13M
                                             angle | intra_flags,
1278
1.13M
                                             4 * f->bw - 4 * t->bx,
1279
1.13M
                                             4 * f->bh - 4 * t->by
1280
1.13M
                                             HIGHBD_CALL_SUFFIX);
1281
1282
1.13M
                    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.13M
                skip_y_pred: {}
1293
1.13M
                    if (!b->skip) {
1294
410k
                        coef *cf;
1295
410k
                        int eob;
1296
410k
                        enum TxfmType txtp;
1297
410k
                        if (t->frame_thread.pass) {
1298
410k
                            const int p = t->frame_thread.pass & 1;
1299
410k
                            const int cbi = *ts->frame_thread[p].cbi++;
1300
410k
                            cf = ts->frame_thread[p].cf;
1301
410k
                            ts->frame_thread[p].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
1302
410k
                            eob  = cbi >> 5;
1303
410k
                            txtp = cbi & 0x1f;
1304
410k
                        } 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
410k
                        if (eob >= 0) {
1317
307k
                            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
307k
                            dsp->itx.itxfm_add[b->tx]
1321
307k
                                              [txtp](dst,
1322
307k
                                                     f->cur.stride[0],
1323
307k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1324
307k
                            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
307k
                        }
1328
727k
                    } 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.13M
                    dst += 4 * t_dim->w;
1333
1.13M
                }
1334
672k
                t->bx -= x;
1335
672k
            }
1336
537k
            t->by -= y;
1337
1338
537k
            if (!has_chroma) continue;
1339
1340
201k
            const ptrdiff_t stride = f->cur.stride[1];
1341
1342
201k
            if (b->uv_mode == CFL_PRED) {
1343
33.1k
                assert(!init_x && !init_y);
1344
1345
33.1k
                int16_t *const ac = t->scratch.ac;
1346
33.1k
                pixel *y_src = ((pixel *) f->cur.data[0]) + 4 * (t->bx & ~ss_hor) +
1347
33.1k
                                 4 * (t->by & ~ss_ver) * PXSTRIDE(f->cur.stride[0]);
1348
33.1k
                const ptrdiff_t uv_off = 4 * ((t->bx >> ss_hor) +
1349
33.1k
                                              (t->by >> ss_ver) * PXSTRIDE(stride));
1350
33.1k
                pixel *const uv_dst[2] = { ((pixel *) f->cur.data[1]) + uv_off,
1351
33.1k
                                           ((pixel *) f->cur.data[2]) + uv_off };
1352
1353
33.1k
                const int furthest_r =
1354
33.1k
                    ((cw4 << ss_hor) + t_dim->w - 1) & ~(t_dim->w - 1);
1355
33.1k
                const int furthest_b =
1356
33.1k
                    ((ch4 << ss_ver) + t_dim->h - 1) & ~(t_dim->h - 1);
1357
33.1k
                dsp->ipred.cfl_ac[f->cur.p.layout - 1](ac, y_src, f->cur.stride[0],
1358
33.1k
                                                         cbw4 - (furthest_r >> ss_hor),
1359
33.1k
                                                         cbh4 - (furthest_b >> ss_ver),
1360
33.1k
                                                         cbw4 * 4, cbh4 * 4);
1361
99.3k
                for (int pl = 0; pl < 2; pl++) {
1362
66.2k
                    if (!b->cfl_alpha[pl]) continue;
1363
53.0k
                    int angle = 0;
1364
53.0k
                    const pixel *top_sb_edge = NULL;
1365
53.0k
                    if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1366
17.0k
                        top_sb_edge = f->ipred_edge[pl + 1];
1367
17.0k
                        const int sby = t->by >> f->sb_shift;
1368
17.0k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1369
17.0k
                    }
1370
53.0k
                    const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1371
53.0k
                    const int xstart = ts->tiling.col_start >> ss_hor;
1372
53.0k
                    const int ystart = ts->tiling.row_start >> ss_ver;
1373
53.0k
                    const enum IntraPredMode m =
1374
53.0k
                        bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1375
53.0k
                                                          ypos, ypos > ystart,
1376
53.0k
                                                          ts->tiling.col_end >> ss_hor,
1377
53.0k
                                                          ts->tiling.row_end >> ss_ver,
1378
53.0k
                                                          0, uv_dst[pl], stride,
1379
53.0k
                                                          top_sb_edge, DC_PRED, &angle,
1380
53.0k
                                                          uv_t_dim->w, uv_t_dim->h, 0,
1381
53.0k
                                                          edge HIGHBD_CALL_SUFFIX);
1382
53.0k
                    dsp->ipred.cfl_pred[m](uv_dst[pl], stride, edge,
1383
53.0k
                                           uv_t_dim->w * 4,
1384
53.0k
                                           uv_t_dim->h * 4,
1385
53.0k
                                           ac, b->cfl_alpha[pl]
1386
53.0k
                                           HIGHBD_CALL_SUFFIX);
1387
53.0k
                }
1388
33.1k
                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
168k
            } else if (b->pal_sz[1]) {
1394
100
                const ptrdiff_t uv_dstoff = 4 * ((t->bx >> ss_hor) +
1395
100
                                              (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1396
100
                const pixel (*pal)[8];
1397
100
                const uint8_t *pal_idx;
1398
100
                if (t->frame_thread.pass) {
1399
100
                    const int p = t->frame_thread.pass & 1;
1400
100
                    assert(ts->frame_thread[p].pal_idx);
1401
100
                    pal = f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1402
100
                                              ((t->bx >> 1) + (t->by & 1))];
1403
100
                    pal_idx = ts->frame_thread[p].pal_idx;
1404
100
                    ts->frame_thread[p].pal_idx += cbw4 * cbh4 * 8;
1405
100
                } else {
1406
0
                    pal = bytefn(t->scratch.pal);
1407
0
                    pal_idx = t->scratch.pal_idx_uv;
1408
0
                }
1409
1410
100
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[1]) + uv_dstoff,
1411
100
                                       f->cur.stride[1], pal[1],
1412
100
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1413
100
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[2]) + uv_dstoff,
1414
100
                                       f->cur.stride[1], pal[2],
1415
100
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1416
100
                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
100
            }
1425
1426
201k
            const int sm_uv_fl = sm_uv_flag(t->a, cbx4) |
1427
201k
                                 sm_uv_flag(&t->l, cby4);
1428
201k
            const int uv_sb_has_tr =
1429
201k
                ((init_x + 16) >> ss_hor) < cw4 ? 1 : init_y ? 0 :
1430
186k
                intra_edge_flags & (EDGE_I420_TOP_HAS_RIGHT >> (f->cur.p.layout - 1));
1431
201k
            const int uv_sb_has_bl =
1432
201k
                init_x ? 0 : ((init_y + 16) >> ss_ver) < ch4 ? 1 :
1433
186k
                intra_edge_flags & (EDGE_I420_LEFT_HAS_BOTTOM >> (f->cur.p.layout - 1));
1434
201k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
1435
604k
            for (int pl = 0; pl < 2; pl++) {
1436
910k
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
1437
506k
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
1438
507k
                {
1439
507k
                    pixel *dst = ((pixel *) f->cur.data[1 + pl]) +
1440
507k
                                   4 * ((t->by >> ss_ver) * PXSTRIDE(stride) +
1441
507k
                                        ((t->bx + init_x) >> ss_hor));
1442
1.33M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
1443
826k
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
1444
826k
                    {
1445
826k
                        if ((b->uv_mode == CFL_PRED && b->cfl_alpha[pl]) ||
1446
773k
                            b->pal_sz[1])
1447
53.5k
                        {
1448
53.5k
                            goto skip_uv_pred;
1449
53.5k
                        }
1450
1451
773k
                        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
773k
                        const enum EdgeFlags edge_flags =
1456
773k
                            (((y > (init_y >> ss_ver) || !uv_sb_has_tr) &&
1457
440k
                              (x + uv_t_dim->w >= sub_cw4)) ?
1458
584k
                                 0 : EDGE_I444_TOP_HAS_RIGHT) |
1459
773k
                            ((x > (init_x >> ss_hor) ||
1460
453k
                              (!uv_sb_has_bl && y + uv_t_dim->h >= sub_ch4)) ?
1461
525k
                                 0 : EDGE_I444_LEFT_HAS_BOTTOM);
1462
773k
                        const pixel *top_sb_edge = NULL;
1463
773k
                        if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1464
204k
                            top_sb_edge = f->ipred_edge[1 + pl];
1465
204k
                            const int sby = t->by >> f->sb_shift;
1466
204k
                            top_sb_edge += f->sb128w * 128 * (sby - 1);
1467
204k
                        }
1468
773k
                        const enum IntraPredMode uv_mode =
1469
773k
                             b->uv_mode == CFL_PRED ? DC_PRED : b->uv_mode;
1470
773k
                        const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1471
773k
                        const int xstart = ts->tiling.col_start >> ss_hor;
1472
773k
                        const int ystart = ts->tiling.row_start >> ss_ver;
1473
773k
                        const enum IntraPredMode m =
1474
773k
                            bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1475
773k
                                                              ypos, ypos > ystart,
1476
773k
                                                              ts->tiling.col_end >> ss_hor,
1477
773k
                                                              ts->tiling.row_end >> ss_ver,
1478
773k
                                                              edge_flags, dst, stride,
1479
773k
                                                              top_sb_edge, uv_mode,
1480
773k
                                                              &angle, uv_t_dim->w,
1481
773k
                                                              uv_t_dim->h,
1482
773k
                                                              f->seq_hdr->intra_edge_filter,
1483
773k
                                                              edge HIGHBD_CALL_SUFFIX);
1484
773k
                        angle |= intra_edge_filter_flag;
1485
773k
                        dsp->ipred.intra_pred[m](dst, stride, edge,
1486
773k
                                                 uv_t_dim->w * 4,
1487
773k
                                                 uv_t_dim->h * 4,
1488
773k
                                                 angle | sm_uv_fl,
1489
773k
                                                 (4 * f->bw + ss_hor -
1490
773k
                                                  4 * (t->bx & ~ss_hor)) >> ss_hor,
1491
773k
                                                 (4 * f->bh + ss_ver -
1492
773k
                                                  4 * (t->by & ~ss_ver)) >> ss_ver
1493
773k
                                                 HIGHBD_CALL_SUFFIX);
1494
773k
                        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
826k
                    skip_uv_pred: {}
1505
826k
                        if (!b->skip) {
1506
264k
                            enum TxfmType txtp;
1507
264k
                            int eob;
1508
264k
                            coef *cf;
1509
264k
                            if (t->frame_thread.pass) {
1510
264k
                                const int p = t->frame_thread.pass & 1;
1511
264k
                                const int cbi = *ts->frame_thread[p].cbi++;
1512
264k
                                cf = ts->frame_thread[p].cf;
1513
264k
                                ts->frame_thread[p].cf += uv_t_dim->w * uv_t_dim->h * 16;
1514
264k
                                eob  = cbi >> 5;
1515
264k
                                txtp = cbi & 0x1f;
1516
18.4E
                            } else {
1517
18.4E
                                uint8_t cf_ctx;
1518
18.4E
                                cf = bitfn(t->cf);
1519
18.4E
                                eob = decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
1520
18.4E
                                                   &t->l.ccoef[pl][cby4 + y],
1521
18.4E
                                                   b->uvtx, bs, b, 1, 1 + pl, cf,
1522
18.4E
                                                   &txtp, &cf_ctx);
1523
18.4E
                                if (DEBUG_BLOCK_INFO)
1524
0
                                    printf("Post-uv-cf-blk[pl=%d,tx=%d,"
1525
0
                                           "txtp=%d,eob=%d]: r=%d [x=%d,cbx4=%d]\n",
1526
0
                                           pl, b->uvtx, txtp, eob, ts->msac.rng, x, cbx4);
1527
18.4E
                                int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
1528
18.4E
                                int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
1529
18.4E
                                dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
1530
18.4E
                                dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
1531
18.4E
                            }
1532
264k
                            if (eob >= 0) {
1533
94.6k
                                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
94.6k
                                dsp->itx.itxfm_add[b->uvtx]
1537
94.6k
                                                  [txtp](dst, stride,
1538
94.6k
                                                         cf, eob HIGHBD_CALL_SUFFIX);
1539
94.6k
                                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
94.6k
                            }
1543
561k
                        } 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
826k
                        dst += uv_t_dim->w * 4;
1548
826k
                    }
1549
506k
                    t->bx -= x << ss_hor;
1550
506k
                }
1551
403k
                t->by -= y << ss_ver;
1552
403k
            }
1553
201k
        }
1554
506k
    }
1555
484k
}
1556
1557
int bytefn(dav1d_recon_b_inter)(Dav1dTaskContext *const t, const enum BlockSize bs,
1558
                                const Av1Block *const b)
1559
170k
{
1560
170k
    Dav1dTileState *const ts = t->ts;
1561
170k
    const Dav1dFrameContext *const f = t->f;
1562
170k
    const Dav1dDSPContext *const dsp = f->dsp;
1563
170k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1564
170k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1565
170k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1566
170k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1567
170k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1568
170k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1569
170k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1570
170k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1571
141k
                           (bw4 > ss_hor || t->bx & 1) &&
1572
129k
                           (bh4 > ss_ver || t->by & 1);
1573
170k
    const int chr_layout_idx = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I400 ? 0 :
1574
170k
                               DAV1D_PIXEL_LAYOUT_I444 - f->cur.p.layout;
1575
170k
    int res;
1576
1577
    // prediction
1578
170k
    const int cbh4 = (bh4 + ss_ver) >> ss_ver, cbw4 = (bw4 + ss_hor) >> ss_hor;
1579
170k
    pixel *dst = ((pixel *) f->cur.data[0]) +
1580
170k
        4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1581
170k
    const ptrdiff_t uvdstoff =
1582
170k
        4 * ((t->bx >> ss_hor) + (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1583
170k
    if (IS_KEY_OR_INTRA(f->frame_hdr)) {
1584
        // intrabc
1585
87.7k
        assert(!f->frame_hdr->super_res.enabled);
1586
87.7k
        res = mc(t, dst, NULL, f->cur.stride[0], bw4, bh4, t->bx, t->by, 0,
1587
87.7k
                 b->mv[0], &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1588
87.7k
        if (res) return res;
1589
181k
        if (has_chroma) for (int pl = 1; pl < 3; pl++) {
1590
121k
            res = mc(t, ((pixel *)f->cur.data[pl]) + uvdstoff, NULL, f->cur.stride[1],
1591
121k
                     bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1592
121k
                     t->bx & ~ss_hor, t->by & ~ss_ver, pl, b->mv[0],
1593
121k
                     &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1594
121k
            if (res) return res;
1595
121k
        }
1596
87.7k
    } else if (b->comp_type == COMP_INTER_NONE) {
1597
65.6k
        const Dav1dThreadPicture *const refp = &f->refp[b->ref[0]];
1598
65.6k
        const enum Filter2d filter_2d = b->filter2d;
1599
1600
65.6k
        if (imin(bw4, bh4) > 1 &&
1601
37.7k
            ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1602
33.6k
             (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1603
5.37k
        {
1604
5.37k
            res = warp_affine(t, dst, NULL, f->cur.stride[0], b_dim, 0, refp,
1605
5.37k
                              b->motion_mode == MM_WARP ? &t->warpmv :
1606
5.37k
                                  &f->frame_hdr->gmv[b->ref[0]]);
1607
5.37k
            if (res) return res;
1608
60.2k
        } else {
1609
60.2k
            res = mc(t, dst, NULL, f->cur.stride[0],
1610
60.2k
                     bw4, bh4, t->bx, t->by, 0, b->mv[0], refp, b->ref[0], filter_2d);
1611
60.2k
            if (res) return res;
1612
60.2k
            if (b->motion_mode == MM_OBMC) {
1613
11.0k
                res = obmc(t, dst, f->cur.stride[0], b_dim, 0, bx4, by4, w4, h4);
1614
11.0k
                if (res) return res;
1615
11.0k
            }
1616
60.2k
        }
1617
65.6k
        if (b->interintra_type) {
1618
4.18k
            pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1619
4.18k
            enum IntraPredMode m = b->interintra_mode == II_SMOOTH_PRED ?
1620
3.52k
                                   SMOOTH_PRED : b->interintra_mode;
1621
4.18k
            pixel *const tmp = bitfn(t->scratch.interintra);
1622
4.18k
            int angle = 0;
1623
4.18k
            const pixel *top_sb_edge = NULL;
1624
4.18k
            if (!(t->by & (f->sb_step - 1))) {
1625
1.01k
                top_sb_edge = f->ipred_edge[0];
1626
1.01k
                const int sby = t->by >> f->sb_shift;
1627
1.01k
                top_sb_edge += f->sb128w * 128 * (sby - 1);
1628
1.01k
            }
1629
4.18k
            m = bytefn(dav1d_prepare_intra_edges)(t->bx, t->bx > ts->tiling.col_start,
1630
4.18k
                                                  t->by, t->by > ts->tiling.row_start,
1631
4.18k
                                                  ts->tiling.col_end, ts->tiling.row_end,
1632
4.18k
                                                  0, dst, f->cur.stride[0], top_sb_edge,
1633
4.18k
                                                  m, &angle, bw4, bh4, 0, tl_edge
1634
4.18k
                                                  HIGHBD_CALL_SUFFIX);
1635
4.18k
            dsp->ipred.intra_pred[m](tmp, 4 * bw4 * sizeof(pixel),
1636
4.18k
                                     tl_edge, bw4 * 4, bh4 * 4, 0, 0, 0
1637
4.18k
                                     HIGHBD_CALL_SUFFIX);
1638
4.18k
            dsp->mc.blend(dst, f->cur.stride[0], tmp,
1639
4.18k
                          bw4 * 4, bh4 * 4, II_MASK(0, bs, b));
1640
4.18k
        }
1641
1642
65.6k
        if (!has_chroma) goto skip_inter_chroma_pred;
1643
1644
        // sub8x8 derivation
1645
44.0k
        int is_sub8x8 = bw4 == ss_hor || bh4 == ss_ver;
1646
44.0k
        refmvs_block *const *r;
1647
44.0k
        if (is_sub8x8) {
1648
7.83k
            assert(ss_hor == 1);
1649
7.83k
            r = &t->rt.r[(t->by & 31) + 5];
1650
7.83k
            if (bw4 == 1) is_sub8x8 &= r[0][t->bx - 1].ref.ref[0] > 0;
1651
7.83k
            if (bh4 == ss_ver) is_sub8x8 &= r[-1][t->bx].ref.ref[0] > 0;
1652
7.83k
            if (bw4 == 1 && bh4 == ss_ver)
1653
1.85k
                is_sub8x8 &= r[-1][t->bx - 1].ref.ref[0] > 0;
1654
7.83k
        }
1655
1656
        // chroma prediction
1657
44.0k
        if (is_sub8x8) {
1658
7.71k
            assert(ss_hor == 1);
1659
7.71k
            ptrdiff_t h_off = 0, v_off = 0;
1660
7.71k
            if (bw4 == 1 && bh4 == ss_ver) {
1661
5.46k
                for (int pl = 0; pl < 2; pl++) {
1662
3.64k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1663
3.64k
                             NULL, f->cur.stride[1],
1664
3.64k
                             bw4, bh4, t->bx - 1, t->by - 1, 1 + pl,
1665
3.64k
                             r[-1][t->bx - 1].mv.mv[0],
1666
3.64k
                             &f->refp[r[-1][t->bx - 1].ref.ref[0] - 1],
1667
3.64k
                             r[-1][t->bx - 1].ref.ref[0] - 1,
1668
3.64k
                             t->frame_thread.pass != 2 ? t->tl_4x4_filter :
1669
3.64k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx - 1].filter2d);
1670
3.64k
                    if (res) return res;
1671
3.64k
                }
1672
1.82k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1673
1.82k
                h_off = 2;
1674
1.82k
            }
1675
7.71k
            if (bw4 == 1) {
1676
4.69k
                const enum Filter2d left_filter_2d =
1677
4.69k
                    dav1d_filter_2d[t->l.filter[1][by4]][t->l.filter[0][by4]];
1678
14.0k
                for (int pl = 0; pl < 2; pl++) {
1679
9.38k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + v_off, NULL,
1680
9.38k
                             f->cur.stride[1], bw4, bh4, t->bx - 1,
1681
9.38k
                             t->by, 1 + pl, r[0][t->bx - 1].mv.mv[0],
1682
9.38k
                             &f->refp[r[0][t->bx - 1].ref.ref[0] - 1],
1683
9.38k
                             r[0][t->bx - 1].ref.ref[0] - 1,
1684
9.38k
                             t->frame_thread.pass != 2 ? left_filter_2d :
1685
9.38k
                                 f->frame_thread.b[(t->by * f->b4_stride) + t->bx - 1].filter2d);
1686
9.38k
                    if (res) return res;
1687
9.38k
                }
1688
4.69k
                h_off = 2;
1689
4.69k
            }
1690
7.71k
            if (bh4 == ss_ver) {
1691
4.84k
                const enum Filter2d top_filter_2d =
1692
4.84k
                    dav1d_filter_2d[t->a->filter[1][bx4]][t->a->filter[0][bx4]];
1693
14.5k
                for (int pl = 0; pl < 2; pl++) {
1694
9.68k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off, NULL,
1695
9.68k
                             f->cur.stride[1], bw4, bh4, t->bx, t->by - 1,
1696
9.68k
                             1 + pl, r[-1][t->bx].mv.mv[0],
1697
9.68k
                             &f->refp[r[-1][t->bx].ref.ref[0] - 1],
1698
9.68k
                             r[-1][t->bx].ref.ref[0] - 1,
1699
9.68k
                             t->frame_thread.pass != 2 ? top_filter_2d :
1700
9.68k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx].filter2d);
1701
9.68k
                    if (res) return res;
1702
9.68k
                }
1703
4.84k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1704
4.84k
            }
1705
23.1k
            for (int pl = 0; pl < 2; pl++) {
1706
15.4k
                res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off + v_off, NULL, f->cur.stride[1],
1707
15.4k
                         bw4, bh4, t->bx, t->by, 1 + pl, b->mv[0],
1708
15.4k
                         refp, b->ref[0], filter_2d);
1709
15.4k
                if (res) return res;
1710
15.4k
            }
1711
36.2k
        } else {
1712
36.2k
            if (imin(cbw4, cbh4) > 1 &&
1713
16.2k
                ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1714
14.3k
                 (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1715
2.82k
            {
1716
8.46k
                for (int pl = 0; pl < 2; pl++) {
1717
5.64k
                    res = warp_affine(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff, NULL,
1718
5.64k
                                      f->cur.stride[1], b_dim, 1 + pl, refp,
1719
5.64k
                                      b->motion_mode == MM_WARP ? &t->warpmv :
1720
5.64k
                                          &f->frame_hdr->gmv[b->ref[0]]);
1721
5.64k
                    if (res) return res;
1722
5.64k
                }
1723
33.4k
            } else {
1724
100k
                for (int pl = 0; pl < 2; pl++) {
1725
66.9k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1726
66.9k
                             NULL, f->cur.stride[1],
1727
66.9k
                             bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1728
66.9k
                             t->bx & ~ss_hor, t->by & ~ss_ver,
1729
66.9k
                             1 + pl, b->mv[0], refp, b->ref[0], filter_2d);
1730
66.9k
                    if (res) return res;
1731
66.9k
                    if (b->motion_mode == MM_OBMC) {
1732
17.9k
                        res = obmc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1733
17.9k
                                   f->cur.stride[1], b_dim, 1 + pl, bx4, by4, w4, h4);
1734
17.9k
                        if (res) return res;
1735
17.9k
                    }
1736
66.9k
                }
1737
33.4k
            }
1738
36.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.63k
                const uint8_t *const ii_mask = II_MASK(chr_layout_idx, bs, b);
1743
1744
10.9k
                for (int pl = 0; pl < 2; pl++) {
1745
7.27k
                    pixel *const tmp = bitfn(t->scratch.interintra);
1746
7.27k
                    pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1747
7.27k
                    enum IntraPredMode m =
1748
7.27k
                        b->interintra_mode == II_SMOOTH_PRED ?
1749
6.07k
                        SMOOTH_PRED : b->interintra_mode;
1750
7.27k
                    int angle = 0;
1751
7.27k
                    pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1752
7.27k
                    const pixel *top_sb_edge = NULL;
1753
7.27k
                    if (!(t->by & (f->sb_step - 1))) {
1754
1.45k
                        top_sb_edge = f->ipred_edge[pl + 1];
1755
1.45k
                        const int sby = t->by >> f->sb_shift;
1756
1.45k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1757
1.45k
                    }
1758
7.27k
                    m = bytefn(dav1d_prepare_intra_edges)(t->bx >> ss_hor,
1759
7.27k
                                                          (t->bx >> ss_hor) >
1760
7.27k
                                                              (ts->tiling.col_start >> ss_hor),
1761
7.27k
                                                          t->by >> ss_ver,
1762
7.27k
                                                          (t->by >> ss_ver) >
1763
7.27k
                                                              (ts->tiling.row_start >> ss_ver),
1764
7.27k
                                                          ts->tiling.col_end >> ss_hor,
1765
7.27k
                                                          ts->tiling.row_end >> ss_ver,
1766
7.27k
                                                          0, uvdst, f->cur.stride[1],
1767
7.27k
                                                          top_sb_edge, m,
1768
7.27k
                                                          &angle, cbw4, cbh4, 0, tl_edge
1769
7.27k
                                                          HIGHBD_CALL_SUFFIX);
1770
7.27k
                    dsp->ipred.intra_pred[m](tmp, cbw4 * 4 * sizeof(pixel),
1771
7.27k
                                             tl_edge, cbw4 * 4, cbh4 * 4, 0, 0, 0
1772
7.27k
                                             HIGHBD_CALL_SUFFIX);
1773
7.27k
                    dsp->mc.blend(uvdst, f->cur.stride[1], tmp,
1774
7.27k
                                  cbw4 * 4, cbh4 * 4, ii_mask);
1775
7.27k
                }
1776
3.63k
            }
1777
36.2k
        }
1778
1779
65.6k
    skip_inter_chroma_pred: {}
1780
65.6k
        t->tl_4x4_filter = filter_2d;
1781
65.6k
    } else {
1782
17.2k
        const enum Filter2d filter_2d = b->filter2d;
1783
        // Maximum super block size is 128x128
1784
17.2k
        int16_t (*tmp)[128 * 128] = t->scratch.compinter;
1785
17.2k
        int jnt_weight;
1786
17.2k
        uint8_t *const seg_mask = t->scratch.seg_mask;
1787
17.2k
        const uint8_t *mask;
1788
1789
51.8k
        for (int i = 0; i < 2; i++) {
1790
34.5k
            const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1791
1792
34.5k
            if (b->inter_mode == GLOBALMV_GLOBALMV && f->gmv_warp_allowed[b->ref[i]]) {
1793
647
                res = warp_affine(t, NULL, tmp[i], bw4 * 4, b_dim, 0, refp,
1794
647
                                  &f->frame_hdr->gmv[b->ref[i]]);
1795
647
                if (res) return res;
1796
33.9k
            } else {
1797
33.9k
                res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by, 0,
1798
33.9k
                         b->mv[i], refp, b->ref[i], filter_2d);
1799
33.9k
                if (res) return res;
1800
33.9k
            }
1801
34.5k
        }
1802
17.2k
        switch (b->comp_type) {
1803
12.4k
        case COMP_INTER_AVG:
1804
12.4k
            dsp->mc.avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1805
12.4k
                        bw4 * 4, bh4 * 4 HIGHBD_CALL_SUFFIX);
1806
12.4k
            break;
1807
1.12k
        case COMP_INTER_WEIGHTED_AVG:
1808
1.12k
            jnt_weight = f->jnt_weights[b->ref[0]][b->ref[1]];
1809
1.12k
            dsp->mc.w_avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1810
1.12k
                          bw4 * 4, bh4 * 4, jnt_weight HIGHBD_CALL_SUFFIX);
1811
1.12k
            break;
1812
2.62k
        case COMP_INTER_SEG:
1813
2.62k
            dsp->mc.w_mask[chr_layout_idx](dst, f->cur.stride[0],
1814
2.62k
                                           tmp[b->mask_sign], tmp[!b->mask_sign],
1815
2.62k
                                           bw4 * 4, bh4 * 4, seg_mask,
1816
2.62k
                                           b->mask_sign HIGHBD_CALL_SUFFIX);
1817
2.62k
            mask = seg_mask;
1818
2.62k
            break;
1819
1.07k
        case COMP_INTER_WEDGE:
1820
1.07k
            mask = WEDGE_MASK(0, bs, 0, b->wedge_idx);
1821
1.07k
            dsp->mc.mask(dst, f->cur.stride[0],
1822
1.07k
                         tmp[b->mask_sign], tmp[!b->mask_sign],
1823
1.07k
                         bw4 * 4, bh4 * 4, mask HIGHBD_CALL_SUFFIX);
1824
1.07k
            if (has_chroma)
1825
755
                mask = WEDGE_MASK(chr_layout_idx, bs, b->mask_sign, b->wedge_idx);
1826
1.07k
            break;
1827
17.2k
        }
1828
1829
        // chroma
1830
38.3k
        if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1831
76.7k
            for (int i = 0; i < 2; i++) {
1832
51.1k
                const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1833
51.1k
                if (b->inter_mode == GLOBALMV_GLOBALMV &&
1834
5.68k
                    imin(cbw4, cbh4) > 1 && f->gmv_warp_allowed[b->ref[i]])
1835
456
                {
1836
456
                    res = warp_affine(t, NULL, tmp[i], bw4 * 4 >> ss_hor,
1837
456
                                      b_dim, 1 + pl,
1838
456
                                      refp, &f->frame_hdr->gmv[b->ref[i]]);
1839
456
                    if (res) return res;
1840
50.6k
                } else {
1841
50.6k
                    res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by,
1842
50.6k
                             1 + pl, b->mv[i], refp, b->ref[i], filter_2d);
1843
50.6k
                    if (res) return res;
1844
50.6k
                }
1845
51.1k
            }
1846
25.5k
            pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1847
25.5k
            switch (b->comp_type) {
1848
18.7k
            case COMP_INTER_AVG:
1849
18.7k
                dsp->mc.avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1850
18.7k
                            bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver
1851
18.7k
                            HIGHBD_CALL_SUFFIX);
1852
18.7k
                break;
1853
1.70k
            case COMP_INTER_WEIGHTED_AVG:
1854
1.70k
                dsp->mc.w_avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1855
1.70k
                              bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, jnt_weight
1856
1.70k
                              HIGHBD_CALL_SUFFIX);
1857
1.70k
                break;
1858
1.51k
            case COMP_INTER_WEDGE:
1859
5.09k
            case COMP_INTER_SEG:
1860
5.09k
                dsp->mc.mask(uvdst, f->cur.stride[1],
1861
5.09k
                             tmp[b->mask_sign], tmp[!b->mask_sign],
1862
5.09k
                             bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, mask
1863
5.09k
                             HIGHBD_CALL_SUFFIX);
1864
5.09k
                break;
1865
25.5k
            }
1866
25.5k
        }
1867
17.2k
    }
1868
1869
170k
    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
170k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1880
1881
170k
    if (b->skip) {
1882
        // reset coef contexts
1883
73.1k
        BlockContext *const a = t->a;
1884
73.1k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
1885
73.1k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
1886
73.1k
        if (has_chroma) {
1887
45.0k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
1888
45.0k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
1889
45.0k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
1890
45.0k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
1891
45.0k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
1892
45.0k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
1893
45.0k
        }
1894
73.1k
        return 0;
1895
73.1k
    }
1896
1897
97.5k
    const TxfmInfo *const uvtx = &dav1d_txfm_dimensions[b->uvtx];
1898
97.5k
    const TxfmInfo *const ytx = &dav1d_txfm_dimensions[b->max_ytx];
1899
97.5k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
1900
1901
196k
    for (int init_y = 0; init_y < bh4; init_y += 16) {
1902
201k
        for (int init_x = 0; init_x < bw4; init_x += 16) {
1903
            // coefficient coding & inverse transforms
1904
102k
            int y_off = !!init_y, y;
1905
102k
            dst += PXSTRIDE(f->cur.stride[0]) * 4 * init_y;
1906
205k
            for (y = init_y, t->by += init_y; y < imin(h4, init_y + 16);
1907
103k
                 y += ytx->h, y_off++)
1908
103k
            {
1909
103k
                int x, x_off = !!init_x;
1910
211k
                for (x = init_x, t->bx += init_x; x < imin(w4, init_x + 16);
1911
108k
                     x += ytx->w, x_off++)
1912
108k
                {
1913
108k
                    read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
1914
108k
                                   x_off, y_off, &dst[x * 4]);
1915
108k
                    t->bx += ytx->w;
1916
108k
                }
1917
103k
                dst += PXSTRIDE(f->cur.stride[0]) * 4 * ytx->h;
1918
103k
                t->bx -= x;
1919
103k
                t->by += ytx->h;
1920
103k
            }
1921
102k
            dst -= PXSTRIDE(f->cur.stride[0]) * 4 * y;
1922
102k
            t->by -= y;
1923
1924
            // chroma coefs and inverse transform
1925
230k
            if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1926
153k
                pixel *uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff +
1927
153k
                    (PXSTRIDE(f->cur.stride[1]) * init_y * 4 >> ss_ver);
1928
153k
                for (y = init_y >> ss_ver, t->by += init_y;
1929
309k
                     y < imin(ch4, (init_y + 16) >> ss_ver); y += uvtx->h)
1930
155k
                {
1931
155k
                    int x;
1932
155k
                    for (x = init_x >> ss_hor, t->bx += init_x;
1933
314k
                         x < imin(cw4, (init_x + 16) >> ss_hor); x += uvtx->w)
1934
158k
                    {
1935
158k
                        coef *cf;
1936
158k
                        int eob;
1937
158k
                        enum TxfmType txtp;
1938
158k
                        if (t->frame_thread.pass) {
1939
158k
                            const int p = t->frame_thread.pass & 1;
1940
158k
                            const int cbi = *ts->frame_thread[p].cbi++;
1941
158k
                            cf = ts->frame_thread[p].cf;
1942
158k
                            ts->frame_thread[p].cf += uvtx->w * uvtx->h * 16;
1943
158k
                            eob  = cbi >> 5;
1944
158k
                            txtp = cbi & 0x1f;
1945
158k
                        } 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
158k
                        if (eob >= 0) {
1964
35.9k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1965
0
                                coef_dump(cf, uvtx->h * 4, uvtx->w * 4, 3, "dq");
1966
35.9k
                            dsp->itx.itxfm_add[b->uvtx]
1967
35.9k
                                              [txtp](&uvdst[4 * x],
1968
35.9k
                                                     f->cur.stride[1],
1969
35.9k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1970
35.9k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1971
0
                                hex_dump(&uvdst[4 * x], f->cur.stride[1],
1972
0
                                         uvtx->w * 4, uvtx->h * 4, "recon");
1973
35.9k
                        }
1974
158k
                        t->bx += uvtx->w << ss_hor;
1975
158k
                    }
1976
155k
                    uvdst += PXSTRIDE(f->cur.stride[1]) * 4 * uvtx->h;
1977
155k
                    t->bx -= x << ss_hor;
1978
155k
                    t->by += uvtx->h << ss_ver;
1979
155k
                }
1980
153k
                t->by -= y << ss_ver;
1981
153k
            }
1982
102k
        }
1983
99.2k
    }
1984
97.5k
    return 0;
1985
170k
}
dav1d_recon_b_inter_8bpc
Line
Count
Source
1559
114k
{
1560
114k
    Dav1dTileState *const ts = t->ts;
1561
114k
    const Dav1dFrameContext *const f = t->f;
1562
114k
    const Dav1dDSPContext *const dsp = f->dsp;
1563
114k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1564
114k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1565
114k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1566
114k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1567
114k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1568
114k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1569
114k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1570
114k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1571
106k
                           (bw4 > ss_hor || t->bx & 1) &&
1572
97.0k
                           (bh4 > ss_ver || t->by & 1);
1573
114k
    const int chr_layout_idx = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I400 ? 0 :
1574
114k
                               DAV1D_PIXEL_LAYOUT_I444 - f->cur.p.layout;
1575
114k
    int res;
1576
1577
    // prediction
1578
114k
    const int cbh4 = (bh4 + ss_ver) >> ss_ver, cbw4 = (bw4 + ss_hor) >> ss_hor;
1579
114k
    pixel *dst = ((pixel *) f->cur.data[0]) +
1580
114k
        4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1581
114k
    const ptrdiff_t uvdstoff =
1582
114k
        4 * ((t->bx >> ss_hor) + (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1583
114k
    if (IS_KEY_OR_INTRA(f->frame_hdr)) {
1584
        // intrabc
1585
68.8k
        assert(!f->frame_hdr->super_res.enabled);
1586
68.8k
        res = mc(t, dst, NULL, f->cur.stride[0], bw4, bh4, t->bx, t->by, 0,
1587
68.8k
                 b->mv[0], &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1588
68.8k
        if (res) return res;
1589
169k
        if (has_chroma) for (int pl = 1; pl < 3; pl++) {
1590
113k
            res = mc(t, ((pixel *)f->cur.data[pl]) + uvdstoff, NULL, f->cur.stride[1],
1591
113k
                     bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1592
113k
                     t->bx & ~ss_hor, t->by & ~ss_ver, pl, b->mv[0],
1593
113k
                     &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1594
113k
            if (res) return res;
1595
113k
        }
1596
68.8k
    } else if (b->comp_type == COMP_INTER_NONE) {
1597
36.4k
        const Dav1dThreadPicture *const refp = &f->refp[b->ref[0]];
1598
36.4k
        const enum Filter2d filter_2d = b->filter2d;
1599
1600
36.4k
        if (imin(bw4, bh4) > 1 &&
1601
20.7k
            ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1602
18.0k
             (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1603
3.44k
        {
1604
3.44k
            res = warp_affine(t, dst, NULL, f->cur.stride[0], b_dim, 0, refp,
1605
3.44k
                              b->motion_mode == MM_WARP ? &t->warpmv :
1606
3.44k
                                  &f->frame_hdr->gmv[b->ref[0]]);
1607
3.44k
            if (res) return res;
1608
33.0k
        } else {
1609
33.0k
            res = mc(t, dst, NULL, f->cur.stride[0],
1610
33.0k
                     bw4, bh4, t->bx, t->by, 0, b->mv[0], refp, b->ref[0], filter_2d);
1611
33.0k
            if (res) return res;
1612
33.0k
            if (b->motion_mode == MM_OBMC) {
1613
5.96k
                res = obmc(t, dst, f->cur.stride[0], b_dim, 0, bx4, by4, w4, h4);
1614
5.96k
                if (res) return res;
1615
5.96k
            }
1616
33.0k
        }
1617
36.4k
        if (b->interintra_type) {
1618
2.47k
            pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1619
2.47k
            enum IntraPredMode m = b->interintra_mode == II_SMOOTH_PRED ?
1620
2.10k
                                   SMOOTH_PRED : b->interintra_mode;
1621
2.47k
            pixel *const tmp = bitfn(t->scratch.interintra);
1622
2.47k
            int angle = 0;
1623
2.47k
            const pixel *top_sb_edge = NULL;
1624
2.47k
            if (!(t->by & (f->sb_step - 1))) {
1625
571
                top_sb_edge = f->ipred_edge[0];
1626
571
                const int sby = t->by >> f->sb_shift;
1627
571
                top_sb_edge += f->sb128w * 128 * (sby - 1);
1628
571
            }
1629
2.47k
            m = bytefn(dav1d_prepare_intra_edges)(t->bx, t->bx > ts->tiling.col_start,
1630
2.47k
                                                  t->by, t->by > ts->tiling.row_start,
1631
2.47k
                                                  ts->tiling.col_end, ts->tiling.row_end,
1632
2.47k
                                                  0, dst, f->cur.stride[0], top_sb_edge,
1633
2.47k
                                                  m, &angle, bw4, bh4, 0, tl_edge
1634
2.47k
                                                  HIGHBD_CALL_SUFFIX);
1635
2.47k
            dsp->ipred.intra_pred[m](tmp, 4 * bw4 * sizeof(pixel),
1636
2.47k
                                     tl_edge, bw4 * 4, bh4 * 4, 0, 0, 0
1637
2.47k
                                     HIGHBD_CALL_SUFFIX);
1638
2.47k
            dsp->mc.blend(dst, f->cur.stride[0], tmp,
1639
2.47k
                          bw4 * 4, bh4 * 4, II_MASK(0, bs, b));
1640
2.47k
        }
1641
1642
36.4k
        if (!has_chroma) goto skip_inter_chroma_pred;
1643
1644
        // sub8x8 derivation
1645
24.1k
        int is_sub8x8 = bw4 == ss_hor || bh4 == ss_ver;
1646
24.1k
        refmvs_block *const *r;
1647
24.1k
        if (is_sub8x8) {
1648
4.60k
            assert(ss_hor == 1);
1649
4.60k
            r = &t->rt.r[(t->by & 31) + 5];
1650
4.60k
            if (bw4 == 1) is_sub8x8 &= r[0][t->bx - 1].ref.ref[0] > 0;
1651
4.60k
            if (bh4 == ss_ver) is_sub8x8 &= r[-1][t->bx].ref.ref[0] > 0;
1652
4.60k
            if (bw4 == 1 && bh4 == ss_ver)
1653
1.07k
                is_sub8x8 &= r[-1][t->bx - 1].ref.ref[0] > 0;
1654
4.60k
        }
1655
1656
        // chroma prediction
1657
24.1k
        if (is_sub8x8) {
1658
4.51k
            assert(ss_hor == 1);
1659
4.51k
            ptrdiff_t h_off = 0, v_off = 0;
1660
4.51k
            if (bw4 == 1 && bh4 == ss_ver) {
1661
3.12k
                for (int pl = 0; pl < 2; pl++) {
1662
2.08k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1663
2.08k
                             NULL, f->cur.stride[1],
1664
2.08k
                             bw4, bh4, t->bx - 1, t->by - 1, 1 + pl,
1665
2.08k
                             r[-1][t->bx - 1].mv.mv[0],
1666
2.08k
                             &f->refp[r[-1][t->bx - 1].ref.ref[0] - 1],
1667
2.08k
                             r[-1][t->bx - 1].ref.ref[0] - 1,
1668
2.08k
                             t->frame_thread.pass != 2 ? t->tl_4x4_filter :
1669
2.08k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx - 1].filter2d);
1670
2.08k
                    if (res) return res;
1671
2.08k
                }
1672
1.04k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1673
1.04k
                h_off = 2;
1674
1.04k
            }
1675
4.51k
            if (bw4 == 1) {
1676
2.76k
                const enum Filter2d left_filter_2d =
1677
2.76k
                    dav1d_filter_2d[t->l.filter[1][by4]][t->l.filter[0][by4]];
1678
8.29k
                for (int pl = 0; pl < 2; pl++) {
1679
5.53k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + v_off, NULL,
1680
5.53k
                             f->cur.stride[1], bw4, bh4, t->bx - 1,
1681
5.53k
                             t->by, 1 + pl, r[0][t->bx - 1].mv.mv[0],
1682
5.53k
                             &f->refp[r[0][t->bx - 1].ref.ref[0] - 1],
1683
5.53k
                             r[0][t->bx - 1].ref.ref[0] - 1,
1684
5.53k
                             t->frame_thread.pass != 2 ? left_filter_2d :
1685
5.53k
                                 f->frame_thread.b[(t->by * f->b4_stride) + t->bx - 1].filter2d);
1686
5.53k
                    if (res) return res;
1687
5.53k
                }
1688
2.76k
                h_off = 2;
1689
2.76k
            }
1690
4.51k
            if (bh4 == ss_ver) {
1691
2.79k
                const enum Filter2d top_filter_2d =
1692
2.79k
                    dav1d_filter_2d[t->a->filter[1][bx4]][t->a->filter[0][bx4]];
1693
8.39k
                for (int pl = 0; pl < 2; pl++) {
1694
5.59k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off, NULL,
1695
5.59k
                             f->cur.stride[1], bw4, bh4, t->bx, t->by - 1,
1696
5.59k
                             1 + pl, r[-1][t->bx].mv.mv[0],
1697
5.59k
                             &f->refp[r[-1][t->bx].ref.ref[0] - 1],
1698
5.59k
                             r[-1][t->bx].ref.ref[0] - 1,
1699
5.59k
                             t->frame_thread.pass != 2 ? top_filter_2d :
1700
5.59k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx].filter2d);
1701
5.59k
                    if (res) return res;
1702
5.59k
                }
1703
2.79k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1704
2.79k
            }
1705
13.5k
            for (int pl = 0; pl < 2; pl++) {
1706
9.03k
                res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off + v_off, NULL, f->cur.stride[1],
1707
9.03k
                         bw4, bh4, t->bx, t->by, 1 + pl, b->mv[0],
1708
9.03k
                         refp, b->ref[0], filter_2d);
1709
9.03k
                if (res) return res;
1710
9.03k
            }
1711
19.6k
        } else {
1712
19.6k
            if (imin(cbw4, cbh4) > 1 &&
1713
8.55k
                ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1714
7.37k
                 (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1715
1.68k
            {
1716
5.06k
                for (int pl = 0; pl < 2; pl++) {
1717
3.37k
                    res = warp_affine(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff, NULL,
1718
3.37k
                                      f->cur.stride[1], b_dim, 1 + pl, refp,
1719
3.37k
                                      b->motion_mode == MM_WARP ? &t->warpmv :
1720
3.37k
                                          &f->frame_hdr->gmv[b->ref[0]]);
1721
3.37k
                    if (res) return res;
1722
3.37k
                }
1723
17.9k
            } else {
1724
53.8k
                for (int pl = 0; pl < 2; pl++) {
1725
35.9k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1726
35.9k
                             NULL, f->cur.stride[1],
1727
35.9k
                             bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1728
35.9k
                             t->bx & ~ss_hor, t->by & ~ss_ver,
1729
35.9k
                             1 + pl, b->mv[0], refp, b->ref[0], filter_2d);
1730
35.9k
                    if (res) return res;
1731
35.9k
                    if (b->motion_mode == MM_OBMC) {
1732
9.53k
                        res = obmc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1733
9.53k
                                   f->cur.stride[1], b_dim, 1 + pl, bx4, by4, w4, h4);
1734
9.53k
                        if (res) return res;
1735
9.53k
                    }
1736
35.9k
                }
1737
17.9k
            }
1738
19.6k
            if (b->interintra_type) {
1739
                // FIXME for 8x32 with 4:2:2 subsampling, this probably does
1740
                // the wrong thing since it will select 4x16, not 4x32, as a
1741
                // transform size...
1742
2.19k
                const uint8_t *const ii_mask = II_MASK(chr_layout_idx, bs, b);
1743
1744
6.58k
                for (int pl = 0; pl < 2; pl++) {
1745
4.39k
                    pixel *const tmp = bitfn(t->scratch.interintra);
1746
4.39k
                    pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1747
4.39k
                    enum IntraPredMode m =
1748
4.39k
                        b->interintra_mode == II_SMOOTH_PRED ?
1749
3.70k
                        SMOOTH_PRED : b->interintra_mode;
1750
4.39k
                    int angle = 0;
1751
4.39k
                    pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1752
4.39k
                    const pixel *top_sb_edge = NULL;
1753
4.39k
                    if (!(t->by & (f->sb_step - 1))) {
1754
906
                        top_sb_edge = f->ipred_edge[pl + 1];
1755
906
                        const int sby = t->by >> f->sb_shift;
1756
906
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1757
906
                    }
1758
4.39k
                    m = bytefn(dav1d_prepare_intra_edges)(t->bx >> ss_hor,
1759
4.39k
                                                          (t->bx >> ss_hor) >
1760
4.39k
                                                              (ts->tiling.col_start >> ss_hor),
1761
4.39k
                                                          t->by >> ss_ver,
1762
4.39k
                                                          (t->by >> ss_ver) >
1763
4.39k
                                                              (ts->tiling.row_start >> ss_ver),
1764
4.39k
                                                          ts->tiling.col_end >> ss_hor,
1765
4.39k
                                                          ts->tiling.row_end >> ss_ver,
1766
4.39k
                                                          0, uvdst, f->cur.stride[1],
1767
4.39k
                                                          top_sb_edge, m,
1768
4.39k
                                                          &angle, cbw4, cbh4, 0, tl_edge
1769
4.39k
                                                          HIGHBD_CALL_SUFFIX);
1770
4.39k
                    dsp->ipred.intra_pred[m](tmp, cbw4 * 4 * sizeof(pixel),
1771
4.39k
                                             tl_edge, cbw4 * 4, cbh4 * 4, 0, 0, 0
1772
4.39k
                                             HIGHBD_CALL_SUFFIX);
1773
4.39k
                    dsp->mc.blend(uvdst, f->cur.stride[1], tmp,
1774
4.39k
                                  cbw4 * 4, cbh4 * 4, ii_mask);
1775
4.39k
                }
1776
2.19k
            }
1777
19.6k
        }
1778
1779
36.4k
    skip_inter_chroma_pred: {}
1780
36.4k
        t->tl_4x4_filter = filter_2d;
1781
36.4k
    } else {
1782
9.53k
        const enum Filter2d filter_2d = b->filter2d;
1783
        // Maximum super block size is 128x128
1784
9.53k
        int16_t (*tmp)[128 * 128] = t->scratch.compinter;
1785
9.53k
        int jnt_weight;
1786
9.53k
        uint8_t *const seg_mask = t->scratch.seg_mask;
1787
9.53k
        const uint8_t *mask;
1788
1789
28.6k
        for (int i = 0; i < 2; i++) {
1790
19.0k
            const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1791
1792
19.0k
            if (b->inter_mode == GLOBALMV_GLOBALMV && f->gmv_warp_allowed[b->ref[i]]) {
1793
373
                res = warp_affine(t, NULL, tmp[i], bw4 * 4, b_dim, 0, refp,
1794
373
                                  &f->frame_hdr->gmv[b->ref[i]]);
1795
373
                if (res) return res;
1796
18.7k
            } else {
1797
18.7k
                res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by, 0,
1798
18.7k
                         b->mv[i], refp, b->ref[i], filter_2d);
1799
18.7k
                if (res) return res;
1800
18.7k
            }
1801
19.0k
        }
1802
9.53k
        switch (b->comp_type) {
1803
7.05k
        case COMP_INTER_AVG:
1804
7.05k
            dsp->mc.avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1805
7.05k
                        bw4 * 4, bh4 * 4 HIGHBD_CALL_SUFFIX);
1806
7.05k
            break;
1807
482
        case COMP_INTER_WEIGHTED_AVG:
1808
482
            jnt_weight = f->jnt_weights[b->ref[0]][b->ref[1]];
1809
482
            dsp->mc.w_avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1810
482
                          bw4 * 4, bh4 * 4, jnt_weight HIGHBD_CALL_SUFFIX);
1811
482
            break;
1812
1.45k
        case COMP_INTER_SEG:
1813
1.45k
            dsp->mc.w_mask[chr_layout_idx](dst, f->cur.stride[0],
1814
1.45k
                                           tmp[b->mask_sign], tmp[!b->mask_sign],
1815
1.45k
                                           bw4 * 4, bh4 * 4, seg_mask,
1816
1.45k
                                           b->mask_sign HIGHBD_CALL_SUFFIX);
1817
1.45k
            mask = seg_mask;
1818
1.45k
            break;
1819
542
        case COMP_INTER_WEDGE:
1820
542
            mask = WEDGE_MASK(0, bs, 0, b->wedge_idx);
1821
542
            dsp->mc.mask(dst, f->cur.stride[0],
1822
542
                         tmp[b->mask_sign], tmp[!b->mask_sign],
1823
542
                         bw4 * 4, bh4 * 4, mask HIGHBD_CALL_SUFFIX);
1824
542
            if (has_chroma)
1825
355
                mask = WEDGE_MASK(chr_layout_idx, bs, b->mask_sign, b->wedge_idx);
1826
542
            break;
1827
9.53k
        }
1828
1829
        // chroma
1830
20.4k
        if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1831
40.9k
            for (int i = 0; i < 2; i++) {
1832
27.3k
                const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1833
27.3k
                if (b->inter_mode == GLOBALMV_GLOBALMV &&
1834
3.01k
                    imin(cbw4, cbh4) > 1 && f->gmv_warp_allowed[b->ref[i]])
1835
176
                {
1836
176
                    res = warp_affine(t, NULL, tmp[i], bw4 * 4 >> ss_hor,
1837
176
                                      b_dim, 1 + pl,
1838
176
                                      refp, &f->frame_hdr->gmv[b->ref[i]]);
1839
176
                    if (res) return res;
1840
27.1k
                } else {
1841
27.1k
                    res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by,
1842
27.1k
                             1 + pl, b->mv[i], refp, b->ref[i], filter_2d);
1843
27.1k
                    if (res) return res;
1844
27.1k
                }
1845
27.3k
            }
1846
13.6k
            pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1847
13.6k
            switch (b->comp_type) {
1848
10.2k
            case COMP_INTER_AVG:
1849
10.2k
                dsp->mc.avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1850
10.2k
                            bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver
1851
10.2k
                            HIGHBD_CALL_SUFFIX);
1852
10.2k
                break;
1853
696
            case COMP_INTER_WEIGHTED_AVG:
1854
696
                dsp->mc.w_avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1855
696
                              bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, jnt_weight
1856
696
                              HIGHBD_CALL_SUFFIX);
1857
696
                break;
1858
710
            case COMP_INTER_WEDGE:
1859
2.69k
            case COMP_INTER_SEG:
1860
2.69k
                dsp->mc.mask(uvdst, f->cur.stride[1],
1861
2.69k
                             tmp[b->mask_sign], tmp[!b->mask_sign],
1862
2.69k
                             bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, mask
1863
2.69k
                             HIGHBD_CALL_SUFFIX);
1864
2.69k
                break;
1865
13.6k
            }
1866
13.6k
        }
1867
9.53k
    }
1868
1869
114k
    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
114k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1880
1881
114k
    if (b->skip) {
1882
        // reset coef contexts
1883
38.6k
        BlockContext *const a = t->a;
1884
38.6k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
1885
38.6k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
1886
38.6k
        if (has_chroma) {
1887
29.1k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
1888
29.1k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
1889
29.1k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
1890
29.1k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
1891
29.1k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
1892
29.1k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
1893
29.1k
        }
1894
38.6k
        return 0;
1895
38.6k
    }
1896
1897
76.1k
    const TxfmInfo *const uvtx = &dav1d_txfm_dimensions[b->uvtx];
1898
76.1k
    const TxfmInfo *const ytx = &dav1d_txfm_dimensions[b->max_ytx];
1899
76.1k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
1900
1901
153k
    for (int init_y = 0; init_y < bh4; init_y += 16) {
1902
157k
        for (int init_x = 0; init_x < bw4; init_x += 16) {
1903
            // coefficient coding & inverse transforms
1904
80.1k
            int y_off = !!init_y, y;
1905
80.1k
            dst += PXSTRIDE(f->cur.stride[0]) * 4 * init_y;
1906
161k
            for (y = init_y, t->by += init_y; y < imin(h4, init_y + 16);
1907
81.0k
                 y += ytx->h, y_off++)
1908
81.0k
            {
1909
81.0k
                int x, x_off = !!init_x;
1910
164k
                for (x = init_x, t->bx += init_x; x < imin(w4, init_x + 16);
1911
83.7k
                     x += ytx->w, x_off++)
1912
83.7k
                {
1913
83.7k
                    read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
1914
83.7k
                                   x_off, y_off, &dst[x * 4]);
1915
83.7k
                    t->bx += ytx->w;
1916
83.7k
                }
1917
81.0k
                dst += PXSTRIDE(f->cur.stride[0]) * 4 * ytx->h;
1918
81.0k
                t->bx -= x;
1919
81.0k
                t->by += ytx->h;
1920
81.0k
            }
1921
80.1k
            dst -= PXSTRIDE(f->cur.stride[0]) * 4 * y;
1922
80.1k
            t->by -= y;
1923
1924
            // chroma coefs and inverse transform
1925
186k
            if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1926
124k
                pixel *uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff +
1927
124k
                    (PXSTRIDE(f->cur.stride[1]) * init_y * 4 >> ss_ver);
1928
124k
                for (y = init_y >> ss_ver, t->by += init_y;
1929
250k
                     y < imin(ch4, (init_y + 16) >> ss_ver); y += uvtx->h)
1930
126k
                {
1931
126k
                    int x;
1932
126k
                    for (x = init_x >> ss_hor, t->bx += init_x;
1933
253k
                         x < imin(cw4, (init_x + 16) >> ss_hor); x += uvtx->w)
1934
127k
                    {
1935
127k
                        coef *cf;
1936
127k
                        int eob;
1937
127k
                        enum TxfmType txtp;
1938
127k
                        if (t->frame_thread.pass) {
1939
127k
                            const int p = t->frame_thread.pass & 1;
1940
127k
                            const int cbi = *ts->frame_thread[p].cbi++;
1941
127k
                            cf = ts->frame_thread[p].cf;
1942
127k
                            ts->frame_thread[p].cf += uvtx->w * uvtx->h * 16;
1943
127k
                            eob  = cbi >> 5;
1944
127k
                            txtp = cbi & 0x1f;
1945
127k
                        } 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
127k
                        if (eob >= 0) {
1964
29.2k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1965
0
                                coef_dump(cf, uvtx->h * 4, uvtx->w * 4, 3, "dq");
1966
29.2k
                            dsp->itx.itxfm_add[b->uvtx]
1967
29.2k
                                              [txtp](&uvdst[4 * x],
1968
29.2k
                                                     f->cur.stride[1],
1969
29.2k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1970
29.2k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1971
0
                                hex_dump(&uvdst[4 * x], f->cur.stride[1],
1972
0
                                         uvtx->w * 4, uvtx->h * 4, "recon");
1973
29.2k
                        }
1974
127k
                        t->bx += uvtx->w << ss_hor;
1975
127k
                    }
1976
126k
                    uvdst += PXSTRIDE(f->cur.stride[1]) * 4 * uvtx->h;
1977
126k
                    t->bx -= x << ss_hor;
1978
126k
                    t->by += uvtx->h << ss_ver;
1979
126k
                }
1980
124k
                t->by -= y << ss_ver;
1981
124k
            }
1982
80.1k
        }
1983
77.5k
    }
1984
76.1k
    return 0;
1985
114k
}
dav1d_recon_b_inter_16bpc
Line
Count
Source
1559
55.8k
{
1560
55.8k
    Dav1dTileState *const ts = t->ts;
1561
55.8k
    const Dav1dFrameContext *const f = t->f;
1562
55.8k
    const Dav1dDSPContext *const dsp = f->dsp;
1563
55.8k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1564
55.8k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1565
55.8k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1566
55.8k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1567
55.8k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1568
55.8k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1569
55.8k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1570
55.8k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1571
34.9k
                           (bw4 > ss_hor || t->bx & 1) &&
1572
32.1k
                           (bh4 > ss_ver || t->by & 1);
1573
55.8k
    const int chr_layout_idx = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I400 ? 0 :
1574
55.8k
                               DAV1D_PIXEL_LAYOUT_I444 - f->cur.p.layout;
1575
55.8k
    int res;
1576
1577
    // prediction
1578
55.8k
    const int cbh4 = (bh4 + ss_ver) >> ss_ver, cbw4 = (bw4 + ss_hor) >> ss_hor;
1579
55.8k
    pixel *dst = ((pixel *) f->cur.data[0]) +
1580
55.8k
        4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1581
55.8k
    const ptrdiff_t uvdstoff =
1582
55.8k
        4 * ((t->bx >> ss_hor) + (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1583
55.8k
    if (IS_KEY_OR_INTRA(f->frame_hdr)) {
1584
        // intrabc
1585
18.9k
        assert(!f->frame_hdr->super_res.enabled);
1586
18.9k
        res = mc(t, dst, NULL, f->cur.stride[0], bw4, bh4, t->bx, t->by, 0,
1587
18.9k
                 b->mv[0], &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1588
18.9k
        if (res) return res;
1589
18.9k
        if (has_chroma) for (int pl = 1; pl < 3; pl++) {
1590
8.12k
            res = mc(t, ((pixel *)f->cur.data[pl]) + uvdstoff, NULL, f->cur.stride[1],
1591
8.12k
                     bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1592
8.12k
                     t->bx & ~ss_hor, t->by & ~ss_ver, pl, b->mv[0],
1593
8.12k
                     &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1594
8.12k
            if (res) return res;
1595
8.12k
        }
1596
36.9k
    } else if (b->comp_type == COMP_INTER_NONE) {
1597
29.1k
        const Dav1dThreadPicture *const refp = &f->refp[b->ref[0]];
1598
29.1k
        const enum Filter2d filter_2d = b->filter2d;
1599
1600
29.1k
        if (imin(bw4, bh4) > 1 &&
1601
17.0k
            ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1602
15.5k
             (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1603
1.92k
        {
1604
1.92k
            res = warp_affine(t, dst, NULL, f->cur.stride[0], b_dim, 0, refp,
1605
1.92k
                              b->motion_mode == MM_WARP ? &t->warpmv :
1606
1.92k
                                  &f->frame_hdr->gmv[b->ref[0]]);
1607
1.92k
            if (res) return res;
1608
27.2k
        } else {
1609
27.2k
            res = mc(t, dst, NULL, f->cur.stride[0],
1610
27.2k
                     bw4, bh4, t->bx, t->by, 0, b->mv[0], refp, b->ref[0], filter_2d);
1611
27.2k
            if (res) return res;
1612
27.2k
            if (b->motion_mode == MM_OBMC) {
1613
5.09k
                res = obmc(t, dst, f->cur.stride[0], b_dim, 0, bx4, by4, w4, h4);
1614
5.09k
                if (res) return res;
1615
5.09k
            }
1616
27.2k
        }
1617
29.1k
        if (b->interintra_type) {
1618
1.70k
            pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1619
1.70k
            enum IntraPredMode m = b->interintra_mode == II_SMOOTH_PRED ?
1620
1.42k
                                   SMOOTH_PRED : b->interintra_mode;
1621
1.70k
            pixel *const tmp = bitfn(t->scratch.interintra);
1622
1.70k
            int angle = 0;
1623
1.70k
            const pixel *top_sb_edge = NULL;
1624
1.70k
            if (!(t->by & (f->sb_step - 1))) {
1625
439
                top_sb_edge = f->ipred_edge[0];
1626
439
                const int sby = t->by >> f->sb_shift;
1627
439
                top_sb_edge += f->sb128w * 128 * (sby - 1);
1628
439
            }
1629
1.70k
            m = bytefn(dav1d_prepare_intra_edges)(t->bx, t->bx > ts->tiling.col_start,
1630
1.70k
                                                  t->by, t->by > ts->tiling.row_start,
1631
1.70k
                                                  ts->tiling.col_end, ts->tiling.row_end,
1632
1.70k
                                                  0, dst, f->cur.stride[0], top_sb_edge,
1633
1.70k
                                                  m, &angle, bw4, bh4, 0, tl_edge
1634
1.70k
                                                  HIGHBD_CALL_SUFFIX);
1635
1.70k
            dsp->ipred.intra_pred[m](tmp, 4 * bw4 * sizeof(pixel),
1636
1.70k
                                     tl_edge, bw4 * 4, bh4 * 4, 0, 0, 0
1637
1.70k
                                     HIGHBD_CALL_SUFFIX);
1638
1.70k
            dsp->mc.blend(dst, f->cur.stride[0], tmp,
1639
1.70k
                          bw4 * 4, bh4 * 4, II_MASK(0, bs, b));
1640
1.70k
        }
1641
1642
29.1k
        if (!has_chroma) goto skip_inter_chroma_pred;
1643
1644
        // sub8x8 derivation
1645
19.8k
        int is_sub8x8 = bw4 == ss_hor || bh4 == ss_ver;
1646
19.8k
        refmvs_block *const *r;
1647
19.8k
        if (is_sub8x8) {
1648
3.23k
            assert(ss_hor == 1);
1649
3.23k
            r = &t->rt.r[(t->by & 31) + 5];
1650
3.23k
            if (bw4 == 1) is_sub8x8 &= r[0][t->bx - 1].ref.ref[0] > 0;
1651
3.23k
            if (bh4 == ss_ver) is_sub8x8 &= r[-1][t->bx].ref.ref[0] > 0;
1652
3.23k
            if (bw4 == 1 && bh4 == ss_ver)
1653
783
                is_sub8x8 &= r[-1][t->bx - 1].ref.ref[0] > 0;
1654
3.23k
        }
1655
1656
        // chroma prediction
1657
19.8k
        if (is_sub8x8) {
1658
3.19k
            assert(ss_hor == 1);
1659
3.19k
            ptrdiff_t h_off = 0, v_off = 0;
1660
3.19k
            if (bw4 == 1 && bh4 == ss_ver) {
1661
2.33k
                for (int pl = 0; pl < 2; pl++) {
1662
1.55k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1663
1.55k
                             NULL, f->cur.stride[1],
1664
1.55k
                             bw4, bh4, t->bx - 1, t->by - 1, 1 + pl,
1665
1.55k
                             r[-1][t->bx - 1].mv.mv[0],
1666
1.55k
                             &f->refp[r[-1][t->bx - 1].ref.ref[0] - 1],
1667
1.55k
                             r[-1][t->bx - 1].ref.ref[0] - 1,
1668
1.55k
                             t->frame_thread.pass != 2 ? t->tl_4x4_filter :
1669
1.55k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx - 1].filter2d);
1670
1.55k
                    if (res) return res;
1671
1.55k
                }
1672
777
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1673
777
                h_off = 2;
1674
777
            }
1675
3.19k
            if (bw4 == 1) {
1676
1.92k
                const enum Filter2d left_filter_2d =
1677
1.92k
                    dav1d_filter_2d[t->l.filter[1][by4]][t->l.filter[0][by4]];
1678
5.78k
                for (int pl = 0; pl < 2; pl++) {
1679
3.85k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + v_off, NULL,
1680
3.85k
                             f->cur.stride[1], bw4, bh4, t->bx - 1,
1681
3.85k
                             t->by, 1 + pl, r[0][t->bx - 1].mv.mv[0],
1682
3.85k
                             &f->refp[r[0][t->bx - 1].ref.ref[0] - 1],
1683
3.85k
                             r[0][t->bx - 1].ref.ref[0] - 1,
1684
3.85k
                             t->frame_thread.pass != 2 ? left_filter_2d :
1685
3.85k
                                 f->frame_thread.b[(t->by * f->b4_stride) + t->bx - 1].filter2d);
1686
3.85k
                    if (res) return res;
1687
3.85k
                }
1688
1.92k
                h_off = 2;
1689
1.92k
            }
1690
3.19k
            if (bh4 == ss_ver) {
1691
2.04k
                const enum Filter2d top_filter_2d =
1692
2.04k
                    dav1d_filter_2d[t->a->filter[1][bx4]][t->a->filter[0][bx4]];
1693
6.14k
                for (int pl = 0; pl < 2; pl++) {
1694
4.09k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off, NULL,
1695
4.09k
                             f->cur.stride[1], bw4, bh4, t->bx, t->by - 1,
1696
4.09k
                             1 + pl, r[-1][t->bx].mv.mv[0],
1697
4.09k
                             &f->refp[r[-1][t->bx].ref.ref[0] - 1],
1698
4.09k
                             r[-1][t->bx].ref.ref[0] - 1,
1699
4.09k
                             t->frame_thread.pass != 2 ? top_filter_2d :
1700
4.09k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx].filter2d);
1701
4.09k
                    if (res) return res;
1702
4.09k
                }
1703
2.04k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1704
2.04k
            }
1705
9.59k
            for (int pl = 0; pl < 2; pl++) {
1706
6.39k
                res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off + v_off, NULL, f->cur.stride[1],
1707
6.39k
                         bw4, bh4, t->bx, t->by, 1 + pl, b->mv[0],
1708
6.39k
                         refp, b->ref[0], filter_2d);
1709
6.39k
                if (res) return res;
1710
6.39k
            }
1711
16.6k
        } else {
1712
16.6k
            if (imin(cbw4, cbh4) > 1 &&
1713
7.71k
                ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1714
6.96k
                 (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1715
1.13k
            {
1716
3.40k
                for (int pl = 0; pl < 2; pl++) {
1717
2.26k
                    res = warp_affine(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff, NULL,
1718
2.26k
                                      f->cur.stride[1], b_dim, 1 + pl, refp,
1719
2.26k
                                      b->motion_mode == MM_WARP ? &t->warpmv :
1720
2.26k
                                          &f->frame_hdr->gmv[b->ref[0]]);
1721
2.26k
                    if (res) return res;
1722
2.26k
                }
1723
15.5k
            } else {
1724
46.5k
                for (int pl = 0; pl < 2; pl++) {
1725
31.0k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1726
31.0k
                             NULL, f->cur.stride[1],
1727
31.0k
                             bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1728
31.0k
                             t->bx & ~ss_hor, t->by & ~ss_ver,
1729
31.0k
                             1 + pl, b->mv[0], refp, b->ref[0], filter_2d);
1730
31.0k
                    if (res) return res;
1731
31.0k
                    if (b->motion_mode == MM_OBMC) {
1732
8.45k
                        res = obmc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1733
8.45k
                                   f->cur.stride[1], b_dim, 1 + pl, bx4, by4, w4, h4);
1734
8.45k
                        if (res) return res;
1735
8.45k
                    }
1736
31.0k
                }
1737
15.5k
            }
1738
16.6k
            if (b->interintra_type) {
1739
                // FIXME for 8x32 with 4:2:2 subsampling, this probably does
1740
                // the wrong thing since it will select 4x16, not 4x32, as a
1741
                // transform size...
1742
1.44k
                const uint8_t *const ii_mask = II_MASK(chr_layout_idx, bs, b);
1743
1744
4.32k
                for (int pl = 0; pl < 2; pl++) {
1745
2.88k
                    pixel *const tmp = bitfn(t->scratch.interintra);
1746
2.88k
                    pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1747
2.88k
                    enum IntraPredMode m =
1748
2.88k
                        b->interintra_mode == II_SMOOTH_PRED ?
1749
2.37k
                        SMOOTH_PRED : b->interintra_mode;
1750
2.88k
                    int angle = 0;
1751
2.88k
                    pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1752
2.88k
                    const pixel *top_sb_edge = NULL;
1753
2.88k
                    if (!(t->by & (f->sb_step - 1))) {
1754
548
                        top_sb_edge = f->ipred_edge[pl + 1];
1755
548
                        const int sby = t->by >> f->sb_shift;
1756
548
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1757
548
                    }
1758
2.88k
                    m = bytefn(dav1d_prepare_intra_edges)(t->bx >> ss_hor,
1759
2.88k
                                                          (t->bx >> ss_hor) >
1760
2.88k
                                                              (ts->tiling.col_start >> ss_hor),
1761
2.88k
                                                          t->by >> ss_ver,
1762
2.88k
                                                          (t->by >> ss_ver) >
1763
2.88k
                                                              (ts->tiling.row_start >> ss_ver),
1764
2.88k
                                                          ts->tiling.col_end >> ss_hor,
1765
2.88k
                                                          ts->tiling.row_end >> ss_ver,
1766
2.88k
                                                          0, uvdst, f->cur.stride[1],
1767
2.88k
                                                          top_sb_edge, m,
1768
2.88k
                                                          &angle, cbw4, cbh4, 0, tl_edge
1769
2.88k
                                                          HIGHBD_CALL_SUFFIX);
1770
2.88k
                    dsp->ipred.intra_pred[m](tmp, cbw4 * 4 * sizeof(pixel),
1771
2.88k
                                             tl_edge, cbw4 * 4, cbh4 * 4, 0, 0, 0
1772
2.88k
                                             HIGHBD_CALL_SUFFIX);
1773
2.88k
                    dsp->mc.blend(uvdst, f->cur.stride[1], tmp,
1774
2.88k
                                  cbw4 * 4, cbh4 * 4, ii_mask);
1775
2.88k
                }
1776
1.44k
            }
1777
16.6k
        }
1778
1779
29.1k
    skip_inter_chroma_pred: {}
1780
29.1k
        t->tl_4x4_filter = filter_2d;
1781
29.1k
    } else {
1782
7.73k
        const enum Filter2d filter_2d = b->filter2d;
1783
        // Maximum super block size is 128x128
1784
7.73k
        int16_t (*tmp)[128 * 128] = t->scratch.compinter;
1785
7.73k
        int jnt_weight;
1786
7.73k
        uint8_t *const seg_mask = t->scratch.seg_mask;
1787
7.73k
        const uint8_t *mask;
1788
1789
23.2k
        for (int i = 0; i < 2; i++) {
1790
15.4k
            const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1791
1792
15.4k
            if (b->inter_mode == GLOBALMV_GLOBALMV && f->gmv_warp_allowed[b->ref[i]]) {
1793
274
                res = warp_affine(t, NULL, tmp[i], bw4 * 4, b_dim, 0, refp,
1794
274
                                  &f->frame_hdr->gmv[b->ref[i]]);
1795
274
                if (res) return res;
1796
15.1k
            } else {
1797
15.1k
                res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by, 0,
1798
15.1k
                         b->mv[i], refp, b->ref[i], filter_2d);
1799
15.1k
                if (res) return res;
1800
15.1k
            }
1801
15.4k
        }
1802
7.73k
        switch (b->comp_type) {
1803
5.39k
        case COMP_INTER_AVG:
1804
5.39k
            dsp->mc.avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1805
5.39k
                        bw4 * 4, bh4 * 4 HIGHBD_CALL_SUFFIX);
1806
5.39k
            break;
1807
640
        case COMP_INTER_WEIGHTED_AVG:
1808
640
            jnt_weight = f->jnt_weights[b->ref[0]][b->ref[1]];
1809
640
            dsp->mc.w_avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1810
640
                          bw4 * 4, bh4 * 4, jnt_weight HIGHBD_CALL_SUFFIX);
1811
640
            break;
1812
1.16k
        case COMP_INTER_SEG:
1813
1.16k
            dsp->mc.w_mask[chr_layout_idx](dst, f->cur.stride[0],
1814
1.16k
                                           tmp[b->mask_sign], tmp[!b->mask_sign],
1815
1.16k
                                           bw4 * 4, bh4 * 4, seg_mask,
1816
1.16k
                                           b->mask_sign HIGHBD_CALL_SUFFIX);
1817
1.16k
            mask = seg_mask;
1818
1.16k
            break;
1819
536
        case COMP_INTER_WEDGE:
1820
536
            mask = WEDGE_MASK(0, bs, 0, b->wedge_idx);
1821
536
            dsp->mc.mask(dst, f->cur.stride[0],
1822
536
                         tmp[b->mask_sign], tmp[!b->mask_sign],
1823
536
                         bw4 * 4, bh4 * 4, mask HIGHBD_CALL_SUFFIX);
1824
536
            if (has_chroma)
1825
400
                mask = WEDGE_MASK(chr_layout_idx, bs, b->mask_sign, b->wedge_idx);
1826
536
            break;
1827
7.73k
        }
1828
1829
        // chroma
1830
17.8k
        if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1831
35.7k
            for (int i = 0; i < 2; i++) {
1832
23.8k
                const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1833
23.8k
                if (b->inter_mode == GLOBALMV_GLOBALMV &&
1834
2.66k
                    imin(cbw4, cbh4) > 1 && f->gmv_warp_allowed[b->ref[i]])
1835
280
                {
1836
280
                    res = warp_affine(t, NULL, tmp[i], bw4 * 4 >> ss_hor,
1837
280
                                      b_dim, 1 + pl,
1838
280
                                      refp, &f->frame_hdr->gmv[b->ref[i]]);
1839
280
                    if (res) return res;
1840
23.5k
                } else {
1841
23.5k
                    res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by,
1842
23.5k
                             1 + pl, b->mv[i], refp, b->ref[i], filter_2d);
1843
23.5k
                    if (res) return res;
1844
23.5k
                }
1845
23.8k
            }
1846
11.9k
            pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1847
11.9k
            switch (b->comp_type) {
1848
8.50k
            case COMP_INTER_AVG:
1849
8.50k
                dsp->mc.avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1850
8.50k
                            bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver
1851
8.50k
                            HIGHBD_CALL_SUFFIX);
1852
8.50k
                break;
1853
1.01k
            case COMP_INTER_WEIGHTED_AVG:
1854
1.01k
                dsp->mc.w_avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1855
1.01k
                              bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, jnt_weight
1856
1.01k
                              HIGHBD_CALL_SUFFIX);
1857
1.01k
                break;
1858
800
            case COMP_INTER_WEDGE:
1859
2.40k
            case COMP_INTER_SEG:
1860
2.40k
                dsp->mc.mask(uvdst, f->cur.stride[1],
1861
2.40k
                             tmp[b->mask_sign], tmp[!b->mask_sign],
1862
2.40k
                             bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, mask
1863
2.40k
                             HIGHBD_CALL_SUFFIX);
1864
2.40k
                break;
1865
11.9k
            }
1866
11.9k
        }
1867
7.73k
    }
1868
1869
55.8k
    if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1870
0
        hex_dump(dst, f->cur.stride[0], b_dim[0] * 4, b_dim[1] * 4, "y-pred");
1871
0
        if (has_chroma) {
1872
0
            hex_dump(&((pixel *) f->cur.data[1])[uvdstoff], f->cur.stride[1],
1873
0
                     cbw4 * 4, cbh4 * 4, "u-pred");
1874
0
            hex_dump(&((pixel *) f->cur.data[2])[uvdstoff], f->cur.stride[1],
1875
0
                     cbw4 * 4, cbh4 * 4, "v-pred");
1876
0
        }
1877
0
    }
1878
1879
55.8k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1880
1881
55.8k
    if (b->skip) {
1882
        // reset coef contexts
1883
34.4k
        BlockContext *const a = t->a;
1884
34.4k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
1885
34.4k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
1886
34.4k
        if (has_chroma) {
1887
15.8k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
1888
15.8k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
1889
15.8k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
1890
15.8k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
1891
15.8k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
1892
15.8k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
1893
15.8k
        }
1894
34.4k
        return 0;
1895
34.4k
    }
1896
1897
21.3k
    const TxfmInfo *const uvtx = &dav1d_txfm_dimensions[b->uvtx];
1898
21.3k
    const TxfmInfo *const ytx = &dav1d_txfm_dimensions[b->max_ytx];
1899
21.3k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
1900
1901
43.0k
    for (int init_y = 0; init_y < bh4; init_y += 16) {
1902
43.6k
        for (int init_x = 0; init_x < bw4; init_x += 16) {
1903
            // coefficient coding & inverse transforms
1904
21.9k
            int y_off = !!init_y, y;
1905
21.9k
            dst += PXSTRIDE(f->cur.stride[0]) * 4 * init_y;
1906
44.5k
            for (y = init_y, t->by += init_y; y < imin(h4, init_y + 16);
1907
22.5k
                 y += ytx->h, y_off++)
1908
22.5k
            {
1909
22.5k
                int x, x_off = !!init_x;
1910
47.1k
                for (x = init_x, t->bx += init_x; x < imin(w4, init_x + 16);
1911
24.5k
                     x += ytx->w, x_off++)
1912
24.5k
                {
1913
24.5k
                    read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
1914
24.5k
                                   x_off, y_off, &dst[x * 4]);
1915
24.5k
                    t->bx += ytx->w;
1916
24.5k
                }
1917
22.5k
                dst += PXSTRIDE(f->cur.stride[0]) * 4 * ytx->h;
1918
22.5k
                t->bx -= x;
1919
22.5k
                t->by += ytx->h;
1920
22.5k
            }
1921
21.9k
            dst -= PXSTRIDE(f->cur.stride[0]) * 4 * y;
1922
21.9k
            t->by -= y;
1923
1924
            // chroma coefs and inverse transform
1925
43.2k
            if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1926
28.8k
                pixel *uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff +
1927
28.8k
                    (PXSTRIDE(f->cur.stride[1]) * init_y * 4 >> ss_ver);
1928
28.8k
                for (y = init_y >> ss_ver, t->by += init_y;
1929
58.6k
                     y < imin(ch4, (init_y + 16) >> ss_ver); y += uvtx->h)
1930
29.8k
                {
1931
29.8k
                    int x;
1932
29.8k
                    for (x = init_x >> ss_hor, t->bx += init_x;
1933
60.8k
                         x < imin(cw4, (init_x + 16) >> ss_hor); x += uvtx->w)
1934
31.0k
                    {
1935
31.0k
                        coef *cf;
1936
31.0k
                        int eob;
1937
31.0k
                        enum TxfmType txtp;
1938
31.0k
                        if (t->frame_thread.pass) {
1939
31.0k
                            const int p = t->frame_thread.pass & 1;
1940
31.0k
                            const int cbi = *ts->frame_thread[p].cbi++;
1941
31.0k
                            cf = ts->frame_thread[p].cf;
1942
31.0k
                            ts->frame_thread[p].cf += uvtx->w * uvtx->h * 16;
1943
31.0k
                            eob  = cbi >> 5;
1944
31.0k
                            txtp = cbi & 0x1f;
1945
31.0k
                        } 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
31.0k
                        if (eob >= 0) {
1964
6.66k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1965
0
                                coef_dump(cf, uvtx->h * 4, uvtx->w * 4, 3, "dq");
1966
6.66k
                            dsp->itx.itxfm_add[b->uvtx]
1967
6.66k
                                              [txtp](&uvdst[4 * x],
1968
6.66k
                                                     f->cur.stride[1],
1969
6.66k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1970
6.66k
                            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
6.66k
                        }
1974
31.0k
                        t->bx += uvtx->w << ss_hor;
1975
31.0k
                    }
1976
29.8k
                    uvdst += PXSTRIDE(f->cur.stride[1]) * 4 * uvtx->h;
1977
29.8k
                    t->bx -= x << ss_hor;
1978
29.8k
                    t->by += uvtx->h << ss_ver;
1979
29.8k
                }
1980
28.8k
                t->by -= y << ss_ver;
1981
28.8k
            }
1982
21.9k
        }
1983
21.6k
    }
1984
21.3k
    return 0;
1985
55.8k
}
1986
1987
61.1k
void bytefn(dav1d_filter_sbrow_deblock_cols)(Dav1dFrameContext *const f, const int sby) {
1988
61.1k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK) ||
1989
61.1k
        (!f->frame_hdr->loopfilter.level_y[0] && !f->frame_hdr->loopfilter.level_y[1]))
1990
0
    {
1991
0
        return;
1992
0
    }
1993
61.1k
    const int y = sby * f->sb_step * 4;
1994
61.1k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1995
61.1k
    pixel *const p[3] = {
1996
61.1k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
1997
61.1k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
1998
61.1k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
1999
61.1k
    };
2000
61.1k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2001
61.1k
    bytefn(dav1d_loopfilter_sbrow_cols)(f, p, mask, sby,
2002
61.1k
                                        f->lf.start_of_tile_row[sby]);
2003
61.1k
}
dav1d_filter_sbrow_deblock_cols_8bpc
Line
Count
Source
1987
30.7k
void bytefn(dav1d_filter_sbrow_deblock_cols)(Dav1dFrameContext *const f, const int sby) {
1988
30.7k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK) ||
1989
30.7k
        (!f->frame_hdr->loopfilter.level_y[0] && !f->frame_hdr->loopfilter.level_y[1]))
1990
0
    {
1991
0
        return;
1992
0
    }
1993
30.7k
    const int y = sby * f->sb_step * 4;
1994
30.7k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1995
30.7k
    pixel *const p[3] = {
1996
30.7k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
1997
30.7k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
1998
30.7k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
1999
30.7k
    };
2000
30.7k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2001
30.7k
    bytefn(dav1d_loopfilter_sbrow_cols)(f, p, mask, sby,
2002
30.7k
                                        f->lf.start_of_tile_row[sby]);
2003
30.7k
}
dav1d_filter_sbrow_deblock_cols_16bpc
Line
Count
Source
1987
30.4k
void bytefn(dav1d_filter_sbrow_deblock_cols)(Dav1dFrameContext *const f, const int sby) {
1988
30.4k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK) ||
1989
30.4k
        (!f->frame_hdr->loopfilter.level_y[0] && !f->frame_hdr->loopfilter.level_y[1]))
1990
0
    {
1991
0
        return;
1992
0
    }
1993
30.4k
    const int y = sby * f->sb_step * 4;
1994
30.4k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1995
30.4k
    pixel *const p[3] = {
1996
30.4k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
1997
30.4k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
1998
30.4k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
1999
30.4k
    };
2000
30.4k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2001
30.4k
    bytefn(dav1d_loopfilter_sbrow_cols)(f, p, mask, sby,
2002
30.4k
                                        f->lf.start_of_tile_row[sby]);
2003
30.4k
}
2004
2005
83.7k
void bytefn(dav1d_filter_sbrow_deblock_rows)(Dav1dFrameContext *const f, const int sby) {
2006
83.7k
    const int y = sby * f->sb_step * 4;
2007
83.7k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2008
83.7k
    pixel *const p[3] = {
2009
83.7k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2010
83.7k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2011
83.7k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2012
83.7k
    };
2013
83.7k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2014
83.7k
    if (f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK &&
2015
83.7k
        (f->frame_hdr->loopfilter.level_y[0] || f->frame_hdr->loopfilter.level_y[1]))
2016
61.0k
    {
2017
61.0k
        bytefn(dav1d_loopfilter_sbrow_rows)(f, p, mask, sby);
2018
61.0k
    }
2019
83.7k
    if (f->seq_hdr->cdef || f->lf.restore_planes) {
2020
        // Store loop filtered pixels required by CDEF / LR
2021
70.7k
        bytefn(dav1d_copy_lpf)(f, p, sby);
2022
70.7k
    }
2023
83.7k
}
dav1d_filter_sbrow_deblock_rows_8bpc
Line
Count
Source
2005
41.6k
void bytefn(dav1d_filter_sbrow_deblock_rows)(Dav1dFrameContext *const f, const int sby) {
2006
41.6k
    const int y = sby * f->sb_step * 4;
2007
41.6k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2008
41.6k
    pixel *const p[3] = {
2009
41.6k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2010
41.6k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2011
41.6k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2012
41.6k
    };
2013
41.6k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2014
41.6k
    if (f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK &&
2015
41.6k
        (f->frame_hdr->loopfilter.level_y[0] || f->frame_hdr->loopfilter.level_y[1]))
2016
30.6k
    {
2017
30.6k
        bytefn(dav1d_loopfilter_sbrow_rows)(f, p, mask, sby);
2018
30.6k
    }
2019
41.6k
    if (f->seq_hdr->cdef || f->lf.restore_planes) {
2020
        // Store loop filtered pixels required by CDEF / LR
2021
34.3k
        bytefn(dav1d_copy_lpf)(f, p, sby);
2022
34.3k
    }
2023
41.6k
}
dav1d_filter_sbrow_deblock_rows_16bpc
Line
Count
Source
2005
42.1k
void bytefn(dav1d_filter_sbrow_deblock_rows)(Dav1dFrameContext *const f, const int sby) {
2006
42.1k
    const int y = sby * f->sb_step * 4;
2007
42.1k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2008
42.1k
    pixel *const p[3] = {
2009
42.1k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2010
42.1k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2011
42.1k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2012
42.1k
    };
2013
42.1k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2014
42.1k
    if (f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK &&
2015
42.1k
        (f->frame_hdr->loopfilter.level_y[0] || f->frame_hdr->loopfilter.level_y[1]))
2016
30.3k
    {
2017
30.3k
        bytefn(dav1d_loopfilter_sbrow_rows)(f, p, mask, sby);
2018
30.3k
    }
2019
42.1k
    if (f->seq_hdr->cdef || f->lf.restore_planes) {
2020
        // Store loop filtered pixels required by CDEF / LR
2021
36.4k
        bytefn(dav1d_copy_lpf)(f, p, sby);
2022
36.4k
    }
2023
42.1k
}
2024
2025
53.7k
void bytefn(dav1d_filter_sbrow_cdef)(Dav1dTaskContext *const tc, const int sby) {
2026
53.7k
    const Dav1dFrameContext *const f = tc->f;
2027
53.7k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_CDEF)) return;
2028
53.7k
    const int sbsz = f->sb_step;
2029
53.7k
    const int y = sby * sbsz * 4;
2030
53.7k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2031
53.7k
    pixel *const p[3] = {
2032
53.7k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2033
53.7k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2034
53.7k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2035
53.7k
    };
2036
53.7k
    Av1Filter *prev_mask = f->lf.mask + ((sby - 1) >> !f->seq_hdr->sb128) * f->sb128w;
2037
53.7k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2038
53.7k
    const int start = sby * sbsz;
2039
53.7k
    if (sby) {
2040
33.5k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2041
33.5k
        pixel *p_up[3] = {
2042
33.5k
            p[0] - 8 * PXSTRIDE(f->cur.stride[0]),
2043
33.5k
            p[1] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2044
33.5k
            p[2] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2045
33.5k
        };
2046
33.5k
        bytefn(dav1d_cdef_brow)(tc, p_up, prev_mask, start - 2, start, 1, sby);
2047
33.5k
    }
2048
53.7k
    const int n_blks = sbsz - 2 * (sby + 1 < f->sbh);
2049
53.7k
    const int end = imin(start + n_blks, f->bh);
2050
53.7k
    bytefn(dav1d_cdef_brow)(tc, p, mask, start, end, 0, sby);
2051
53.7k
}
dav1d_filter_sbrow_cdef_8bpc
Line
Count
Source
2025
26.9k
void bytefn(dav1d_filter_sbrow_cdef)(Dav1dTaskContext *const tc, const int sby) {
2026
26.9k
    const Dav1dFrameContext *const f = tc->f;
2027
26.9k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_CDEF)) return;
2028
26.9k
    const int sbsz = f->sb_step;
2029
26.9k
    const int y = sby * sbsz * 4;
2030
26.9k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2031
26.9k
    pixel *const p[3] = {
2032
26.9k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2033
26.9k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2034
26.9k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2035
26.9k
    };
2036
26.9k
    Av1Filter *prev_mask = f->lf.mask + ((sby - 1) >> !f->seq_hdr->sb128) * f->sb128w;
2037
26.9k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2038
26.9k
    const int start = sby * sbsz;
2039
26.9k
    if (sby) {
2040
18.1k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2041
18.1k
        pixel *p_up[3] = {
2042
18.1k
            p[0] - 8 * PXSTRIDE(f->cur.stride[0]),
2043
18.1k
            p[1] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2044
18.1k
            p[2] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2045
18.1k
        };
2046
18.1k
        bytefn(dav1d_cdef_brow)(tc, p_up, prev_mask, start - 2, start, 1, sby);
2047
18.1k
    }
2048
26.9k
    const int n_blks = sbsz - 2 * (sby + 1 < f->sbh);
2049
26.9k
    const int end = imin(start + n_blks, f->bh);
2050
26.9k
    bytefn(dav1d_cdef_brow)(tc, p, mask, start, end, 0, sby);
2051
26.9k
}
dav1d_filter_sbrow_cdef_16bpc
Line
Count
Source
2025
26.8k
void bytefn(dav1d_filter_sbrow_cdef)(Dav1dTaskContext *const tc, const int sby) {
2026
26.8k
    const Dav1dFrameContext *const f = tc->f;
2027
26.8k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_CDEF)) return;
2028
26.8k
    const int sbsz = f->sb_step;
2029
26.8k
    const int y = sby * sbsz * 4;
2030
26.8k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2031
26.8k
    pixel *const p[3] = {
2032
26.8k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2033
26.8k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2034
26.8k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2035
26.8k
    };
2036
26.8k
    Av1Filter *prev_mask = f->lf.mask + ((sby - 1) >> !f->seq_hdr->sb128) * f->sb128w;
2037
26.8k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2038
26.8k
    const int start = sby * sbsz;
2039
26.8k
    if (sby) {
2040
15.4k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2041
15.4k
        pixel *p_up[3] = {
2042
15.4k
            p[0] - 8 * PXSTRIDE(f->cur.stride[0]),
2043
15.4k
            p[1] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2044
15.4k
            p[2] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2045
15.4k
        };
2046
15.4k
        bytefn(dav1d_cdef_brow)(tc, p_up, prev_mask, start - 2, start, 1, sby);
2047
15.4k
    }
2048
26.8k
    const int n_blks = sbsz - 2 * (sby + 1 < f->sbh);
2049
26.8k
    const int end = imin(start + n_blks, f->bh);
2050
26.8k
    bytefn(dav1d_cdef_brow)(tc, p, mask, start, end, 0, sby);
2051
26.8k
}
2052
2053
21.8k
void bytefn(dav1d_filter_sbrow_resize)(Dav1dFrameContext *const f, const int sby) {
2054
21.8k
    const int sbsz = f->sb_step;
2055
21.8k
    const int y = sby * sbsz * 4;
2056
21.8k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2057
21.8k
    const pixel *const p[3] = {
2058
21.8k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2059
21.8k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2060
21.8k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2061
21.8k
    };
2062
21.8k
    pixel *const sr_p[3] = {
2063
21.8k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2064
21.8k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2065
21.8k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2066
21.8k
    };
2067
21.8k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400;
2068
75.5k
    for (int pl = 0; pl < 1 + 2 * has_chroma; pl++) {
2069
53.7k
        const int ss_ver = pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2070
53.7k
        const int h_start = 8 * !!sby >> ss_ver;
2071
53.7k
        const ptrdiff_t dst_stride = f->sr_cur.p.stride[!!pl];
2072
53.7k
        pixel *dst = sr_p[pl] - h_start * PXSTRIDE(dst_stride);
2073
53.7k
        const ptrdiff_t src_stride = f->cur.stride[!!pl];
2074
53.7k
        const pixel *src = p[pl] - h_start * PXSTRIDE(src_stride);
2075
53.7k
        const int h_end = 4 * (sbsz - 2 * (sby + 1 < f->sbh)) >> ss_ver;
2076
53.7k
        const int ss_hor = pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2077
53.7k
        const int dst_w = (f->sr_cur.p.p.w + ss_hor) >> ss_hor;
2078
53.7k
        const int src_w = (4 * f->bw + ss_hor) >> ss_hor;
2079
53.7k
        const int img_h = (f->cur.p.h - sbsz * 4 * sby + ss_ver) >> ss_ver;
2080
2081
53.7k
        f->dsp->mc.resize(dst, dst_stride, src, src_stride, dst_w,
2082
53.7k
                          imin(img_h, h_end) + h_start, src_w,
2083
53.7k
                          f->resize_step[!!pl], f->resize_start[!!pl]
2084
53.7k
                          HIGHBD_CALL_SUFFIX);
2085
53.7k
    }
2086
21.8k
}
dav1d_filter_sbrow_resize_8bpc
Line
Count
Source
2053
10.0k
void bytefn(dav1d_filter_sbrow_resize)(Dav1dFrameContext *const f, const int sby) {
2054
10.0k
    const int sbsz = f->sb_step;
2055
10.0k
    const int y = sby * sbsz * 4;
2056
10.0k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2057
10.0k
    const pixel *const p[3] = {
2058
10.0k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2059
10.0k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2060
10.0k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2061
10.0k
    };
2062
10.0k
    pixel *const sr_p[3] = {
2063
10.0k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2064
10.0k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2065
10.0k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2066
10.0k
    };
2067
10.0k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400;
2068
34.5k
    for (int pl = 0; pl < 1 + 2 * has_chroma; pl++) {
2069
24.5k
        const int ss_ver = pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2070
24.5k
        const int h_start = 8 * !!sby >> ss_ver;
2071
24.5k
        const ptrdiff_t dst_stride = f->sr_cur.p.stride[!!pl];
2072
24.5k
        pixel *dst = sr_p[pl] - h_start * PXSTRIDE(dst_stride);
2073
24.5k
        const ptrdiff_t src_stride = f->cur.stride[!!pl];
2074
24.5k
        const pixel *src = p[pl] - h_start * PXSTRIDE(src_stride);
2075
24.5k
        const int h_end = 4 * (sbsz - 2 * (sby + 1 < f->sbh)) >> ss_ver;
2076
24.5k
        const int ss_hor = pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2077
24.5k
        const int dst_w = (f->sr_cur.p.p.w + ss_hor) >> ss_hor;
2078
24.5k
        const int src_w = (4 * f->bw + ss_hor) >> ss_hor;
2079
24.5k
        const int img_h = (f->cur.p.h - sbsz * 4 * sby + ss_ver) >> ss_ver;
2080
2081
24.5k
        f->dsp->mc.resize(dst, dst_stride, src, src_stride, dst_w,
2082
24.5k
                          imin(img_h, h_end) + h_start, src_w,
2083
24.5k
                          f->resize_step[!!pl], f->resize_start[!!pl]
2084
24.5k
                          HIGHBD_CALL_SUFFIX);
2085
24.5k
    }
2086
10.0k
}
dav1d_filter_sbrow_resize_16bpc
Line
Count
Source
2053
11.8k
void bytefn(dav1d_filter_sbrow_resize)(Dav1dFrameContext *const f, const int sby) {
2054
11.8k
    const int sbsz = f->sb_step;
2055
11.8k
    const int y = sby * sbsz * 4;
2056
11.8k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2057
11.8k
    const pixel *const p[3] = {
2058
11.8k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2059
11.8k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2060
11.8k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2061
11.8k
    };
2062
11.8k
    pixel *const sr_p[3] = {
2063
11.8k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2064
11.8k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2065
11.8k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2066
11.8k
    };
2067
11.8k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400;
2068
41.0k
    for (int pl = 0; pl < 1 + 2 * has_chroma; pl++) {
2069
29.1k
        const int ss_ver = pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2070
29.1k
        const int h_start = 8 * !!sby >> ss_ver;
2071
29.1k
        const ptrdiff_t dst_stride = f->sr_cur.p.stride[!!pl];
2072
29.1k
        pixel *dst = sr_p[pl] - h_start * PXSTRIDE(dst_stride);
2073
29.1k
        const ptrdiff_t src_stride = f->cur.stride[!!pl];
2074
29.1k
        const pixel *src = p[pl] - h_start * PXSTRIDE(src_stride);
2075
29.1k
        const int h_end = 4 * (sbsz - 2 * (sby + 1 < f->sbh)) >> ss_ver;
2076
29.1k
        const int ss_hor = pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2077
29.1k
        const int dst_w = (f->sr_cur.p.p.w + ss_hor) >> ss_hor;
2078
29.1k
        const int src_w = (4 * f->bw + ss_hor) >> ss_hor;
2079
29.1k
        const int img_h = (f->cur.p.h - sbsz * 4 * sby + ss_ver) >> ss_ver;
2080
2081
29.1k
        f->dsp->mc.resize(dst, dst_stride, src, src_stride, dst_w,
2082
29.1k
                          imin(img_h, h_end) + h_start, src_w,
2083
29.1k
                          f->resize_step[!!pl], f->resize_start[!!pl]
2084
29.1k
                          HIGHBD_CALL_SUFFIX);
2085
29.1k
    }
2086
11.8k
}
2087
2088
34.3k
void bytefn(dav1d_filter_sbrow_lr)(Dav1dFrameContext *const f, const int sby) {
2089
34.3k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_RESTORATION)) return;
2090
34.3k
    const int y = sby * f->sb_step * 4;
2091
34.3k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2092
34.3k
    pixel *const sr_p[3] = {
2093
34.3k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2094
34.3k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2095
34.3k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2096
34.3k
    };
2097
34.3k
    bytefn(dav1d_lr_sbrow)(f, sr_p, sby);
2098
34.3k
}
dav1d_filter_sbrow_lr_8bpc
Line
Count
Source
2088
17.4k
void bytefn(dav1d_filter_sbrow_lr)(Dav1dFrameContext *const f, const int sby) {
2089
17.4k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_RESTORATION)) return;
2090
17.4k
    const int y = sby * f->sb_step * 4;
2091
17.4k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2092
17.4k
    pixel *const sr_p[3] = {
2093
17.4k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2094
17.4k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2095
17.4k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2096
17.4k
    };
2097
17.4k
    bytefn(dav1d_lr_sbrow)(f, sr_p, sby);
2098
17.4k
}
dav1d_filter_sbrow_lr_16bpc
Line
Count
Source
2088
16.9k
void bytefn(dav1d_filter_sbrow_lr)(Dav1dFrameContext *const f, const int sby) {
2089
16.9k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_RESTORATION)) return;
2090
16.9k
    const int y = sby * f->sb_step * 4;
2091
16.9k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2092
16.9k
    pixel *const sr_p[3] = {
2093
16.9k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2094
16.9k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2095
16.9k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2096
16.9k
    };
2097
16.9k
    bytefn(dav1d_lr_sbrow)(f, sr_p, sby);
2098
16.9k
}
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
101k
void bytefn(dav1d_backup_ipred_edge)(Dav1dTaskContext *const t) {
2112
101k
    const Dav1dFrameContext *const f = t->f;
2113
101k
    Dav1dTileState *const ts = t->ts;
2114
101k
    const int sby = t->by >> f->sb_shift;
2115
101k
    const int sby_off = f->sb128w * 128 * sby;
2116
101k
    const int x_off = ts->tiling.col_start;
2117
2118
101k
    const pixel *const y =
2119
101k
        ((const pixel *) f->cur.data[0]) + x_off * 4 +
2120
101k
                    ((t->by + f->sb_step) * 4 - 1) * PXSTRIDE(f->cur.stride[0]);
2121
101k
    pixel_copy(&f->ipred_edge[0][sby_off + x_off * 4], y,
2122
101k
               4 * (ts->tiling.col_end - x_off));
2123
2124
101k
    if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
2125
69.0k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2126
69.0k
        const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2127
2128
69.0k
        const ptrdiff_t uv_off = (x_off * 4 >> ss_hor) +
2129
69.0k
            (((t->by + f->sb_step) * 4 >> ss_ver) - 1) * PXSTRIDE(f->cur.stride[1]);
2130
207k
        for (int pl = 1; pl <= 2; pl++)
2131
138k
            pixel_copy(&f->ipred_edge[pl][sby_off + (x_off * 4 >> ss_hor)],
2132
67.6k
                       &((const pixel *) f->cur.data[pl])[uv_off],
2133
67.6k
                       4 * (ts->tiling.col_end - x_off) >> ss_hor);
2134
69.0k
    }
2135
101k
}
dav1d_backup_ipred_edge_8bpc
Line
Count
Source
2111
51.6k
void bytefn(dav1d_backup_ipred_edge)(Dav1dTaskContext *const t) {
2112
51.6k
    const Dav1dFrameContext *const f = t->f;
2113
51.6k
    Dav1dTileState *const ts = t->ts;
2114
51.6k
    const int sby = t->by >> f->sb_shift;
2115
51.6k
    const int sby_off = f->sb128w * 128 * sby;
2116
51.6k
    const int x_off = ts->tiling.col_start;
2117
2118
51.6k
    const pixel *const y =
2119
51.6k
        ((const pixel *) f->cur.data[0]) + x_off * 4 +
2120
51.6k
                    ((t->by + f->sb_step) * 4 - 1) * PXSTRIDE(f->cur.stride[0]);
2121
51.6k
    pixel_copy(&f->ipred_edge[0][sby_off + x_off * 4], y,
2122
51.6k
               4 * (ts->tiling.col_end - x_off));
2123
2124
51.6k
    if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
2125
33.8k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2126
33.8k
        const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2127
2128
33.8k
        const ptrdiff_t uv_off = (x_off * 4 >> ss_hor) +
2129
33.8k
            (((t->by + f->sb_step) * 4 >> ss_ver) - 1) * PXSTRIDE(f->cur.stride[1]);
2130
101k
        for (int pl = 1; pl <= 2; pl++)
2131
67.6k
            pixel_copy(&f->ipred_edge[pl][sby_off + (x_off * 4 >> ss_hor)],
2132
67.6k
                       &((const pixel *) f->cur.data[pl])[uv_off],
2133
67.6k
                       4 * (ts->tiling.col_end - x_off) >> ss_hor);
2134
33.8k
    }
2135
51.6k
}
dav1d_backup_ipred_edge_16bpc
Line
Count
Source
2111
50.1k
void bytefn(dav1d_backup_ipred_edge)(Dav1dTaskContext *const t) {
2112
50.1k
    const Dav1dFrameContext *const f = t->f;
2113
50.1k
    Dav1dTileState *const ts = t->ts;
2114
50.1k
    const int sby = t->by >> f->sb_shift;
2115
50.1k
    const int sby_off = f->sb128w * 128 * sby;
2116
50.1k
    const int x_off = ts->tiling.col_start;
2117
2118
50.1k
    const pixel *const y =
2119
50.1k
        ((const pixel *) f->cur.data[0]) + x_off * 4 +
2120
50.1k
                    ((t->by + f->sb_step) * 4 - 1) * PXSTRIDE(f->cur.stride[0]);
2121
50.1k
    pixel_copy(&f->ipred_edge[0][sby_off + x_off * 4], y,
2122
50.1k
               4 * (ts->tiling.col_end - x_off));
2123
2124
50.1k
    if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
2125
35.1k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2126
35.1k
        const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2127
2128
35.1k
        const ptrdiff_t uv_off = (x_off * 4 >> ss_hor) +
2129
35.1k
            (((t->by + f->sb_step) * 4 >> ss_ver) - 1) * PXSTRIDE(f->cur.stride[1]);
2130
105k
        for (int pl = 1; pl <= 2; pl++)
2131
70.3k
            pixel_copy(&f->ipred_edge[pl][sby_off + (x_off * 4 >> ss_hor)],
2132
35.1k
                       &((const pixel *) f->cur.data[pl])[uv_off],
2133
35.1k
                       4 * (ts->tiling.col_end - x_off) >> ss_hor);
2134
35.1k
    }
2135
50.1k
}
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
22.0k
{
2142
22.0k
    const Dav1dFrameContext *const f = t->f;
2143
22.0k
    pixel *const pal = t->frame_thread.pass ?
2144
22.0k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2145
22.0k
                            ((t->bx >> 1) + (t->by & 1))][0] :
2146
22.0k
        bytefn(t->scratch.pal)[0];
2147
104k
    for (int x = 0; x < bw4; x++)
2148
82.7k
        memcpy(bytefn(t->al_pal)[0][bx4 + x][0], pal, 8 * sizeof(pixel));
2149
90.2k
    for (int y = 0; y < bh4; y++)
2150
68.2k
        memcpy(bytefn(t->al_pal)[1][by4 + y][0], pal, 8 * sizeof(pixel));
2151
22.0k
}
dav1d_copy_pal_block_y_8bpc
Line
Count
Source
2141
8.73k
{
2142
8.73k
    const Dav1dFrameContext *const f = t->f;
2143
8.73k
    pixel *const pal = t->frame_thread.pass ?
2144
8.73k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2145
8.73k
                            ((t->bx >> 1) + (t->by & 1))][0] :
2146
8.73k
        bytefn(t->scratch.pal)[0];
2147
43.4k
    for (int x = 0; x < bw4; x++)
2148
34.7k
        memcpy(bytefn(t->al_pal)[0][bx4 + x][0], pal, 8 * sizeof(pixel));
2149
36.6k
    for (int y = 0; y < bh4; y++)
2150
27.8k
        memcpy(bytefn(t->al_pal)[1][by4 + y][0], pal, 8 * sizeof(pixel));
2151
8.73k
}
dav1d_copy_pal_block_y_16bpc
Line
Count
Source
2141
13.2k
{
2142
13.2k
    const Dav1dFrameContext *const f = t->f;
2143
13.2k
    pixel *const pal = t->frame_thread.pass ?
2144
13.2k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2145
13.2k
                            ((t->bx >> 1) + (t->by & 1))][0] :
2146
13.2k
        bytefn(t->scratch.pal)[0];
2147
61.2k
    for (int x = 0; x < bw4; x++)
2148
48.0k
        memcpy(bytefn(t->al_pal)[0][bx4 + x][0], pal, 8 * sizeof(pixel));
2149
53.6k
    for (int y = 0; y < bh4; y++)
2150
40.3k
        memcpy(bytefn(t->al_pal)[1][by4 + y][0], pal, 8 * sizeof(pixel));
2151
13.2k
}
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.52k
{
2158
7.52k
    const Dav1dFrameContext *const f = t->f;
2159
7.52k
    const pixel (*const pal)[8] = t->frame_thread.pass ?
2160
7.52k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2161
7.52k
                            ((t->bx >> 1) + (t->by & 1))] :
2162
7.52k
        bytefn(t->scratch.pal);
2163
    // see aomedia bug 2183 for why we use luma coordinates here
2164
22.5k
    for (int pl = 1; pl <= 2; pl++) {
2165
85.2k
        for (int x = 0; x < bw4; x++)
2166
70.2k
            memcpy(bytefn(t->al_pal)[0][bx4 + x][pl], pal[pl], 8 * sizeof(pixel));
2167
68.9k
        for (int y = 0; y < bh4; y++)
2168
53.8k
            memcpy(bytefn(t->al_pal)[1][by4 + y][pl], pal[pl], 8 * sizeof(pixel));
2169
15.0k
    }
2170
7.52k
}
dav1d_copy_pal_block_uv_8bpc
Line
Count
Source
2157
3.17k
{
2158
3.17k
    const Dav1dFrameContext *const f = t->f;
2159
3.17k
    const pixel (*const pal)[8] = t->frame_thread.pass ?
2160
3.17k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2161
3.17k
                            ((t->bx >> 1) + (t->by & 1))] :
2162
3.17k
        bytefn(t->scratch.pal);
2163
    // see aomedia bug 2183 for why we use luma coordinates here
2164
9.52k
    for (int pl = 1; pl <= 2; pl++) {
2165
35.7k
        for (int x = 0; x < bw4; x++)
2166
29.4k
            memcpy(bytefn(t->al_pal)[0][bx4 + x][pl], pal[pl], 8 * sizeof(pixel));
2167
30.5k
        for (int y = 0; y < bh4; y++)
2168
24.2k
            memcpy(bytefn(t->al_pal)[1][by4 + y][pl], pal[pl], 8 * sizeof(pixel));
2169
6.34k
    }
2170
3.17k
}
dav1d_copy_pal_block_uv_16bpc
Line
Count
Source
2157
4.35k
{
2158
4.35k
    const Dav1dFrameContext *const f = t->f;
2159
4.35k
    const pixel (*const pal)[8] = t->frame_thread.pass ?
2160
4.35k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2161
4.35k
                            ((t->bx >> 1) + (t->by & 1))] :
2162
4.35k
        bytefn(t->scratch.pal);
2163
    // see aomedia bug 2183 for why we use luma coordinates here
2164
13.0k
    for (int pl = 1; pl <= 2; pl++) {
2165
49.4k
        for (int x = 0; x < bw4; x++)
2166
40.7k
            memcpy(bytefn(t->al_pal)[0][bx4 + x][pl], pal[pl], 8 * sizeof(pixel));
2167
38.3k
        for (int y = 0; y < bh4; y++)
2168
29.6k
            memcpy(bytefn(t->al_pal)[1][by4 + y][pl], pal[pl], 8 * sizeof(pixel));
2169
8.71k
    }
2170
4.35k
}
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
29.5k
{
2176
29.5k
    Dav1dTileState *const ts = t->ts;
2177
29.5k
    const Dav1dFrameContext *const f = t->f;
2178
29.5k
    const int pal_sz = b->pal_sz[pl] = dav1d_msac_decode_symbol_adapt8(&ts->msac,
2179
29.5k
                                           ts->cdf.m.pal_sz[pl][sz_ctx], 6) + 2;
2180
29.5k
    pixel cache[16], used_cache[8];
2181
29.5k
    int l_cache = pl ? t->pal_sz_uv[1][by4] : t->l.pal_sz[by4];
2182
29.5k
    int n_cache = 0;
2183
    // don't reuse above palette outside SB64 boundaries
2184
29.5k
    int a_cache = by4 & 15 ? pl ? t->pal_sz_uv[0][bx4] : t->a->pal_sz[bx4] : 0;
2185
29.5k
    const pixel *l = bytefn(t->al_pal)[1][by4][pl];
2186
29.5k
    const pixel *a = bytefn(t->al_pal)[0][bx4][pl];
2187
2188
    // fill/sort cache
2189
47.9k
    while (l_cache && a_cache) {
2190
18.4k
        if (*l < *a) {
2191
6.76k
            if (!n_cache || cache[n_cache - 1] != *l)
2192
6.69k
                cache[n_cache++] = *l;
2193
6.76k
            l++;
2194
6.76k
            l_cache--;
2195
11.6k
        } else {
2196
11.6k
            if (*a == *l) {
2197
4.79k
                l++;
2198
4.79k
                l_cache--;
2199
4.79k
            }
2200
11.6k
            if (!n_cache || cache[n_cache - 1] != *a)
2201
11.2k
                cache[n_cache++] = *a;
2202
11.6k
            a++;
2203
11.6k
            a_cache--;
2204
11.6k
        }
2205
18.4k
    }
2206
29.5k
    if (l_cache) {
2207
34.6k
        do {
2208
34.6k
            if (!n_cache || cache[n_cache - 1] != *l)
2209
27.9k
                cache[n_cache++] = *l;
2210
34.6k
            l++;
2211
34.6k
        } while (--l_cache > 0);
2212
21.1k
    } else if (a_cache) {
2213
24.7k
        do {
2214
24.7k
            if (!n_cache || cache[n_cache - 1] != *a)
2215
19.4k
                cache[n_cache++] = *a;
2216
24.7k
            a++;
2217
24.7k
        } while (--a_cache > 0);
2218
6.16k
    }
2219
2220
    // find reused cache entries
2221
29.5k
    int i = 0;
2222
88.0k
    for (int n = 0; n < n_cache && i < pal_sz; n++)
2223
58.5k
        if (dav1d_msac_decode_bool_equi(&ts->msac))
2224
28.9k
            used_cache[i++] = cache[n];
2225
29.5k
    const int n_used_cache = i;
2226
2227
    // parse new entries
2228
29.5k
    pixel *const pal = t->frame_thread.pass ?
2229
29.5k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2230
29.5k
                            ((t->bx >> 1) + (t->by & 1))][pl] :
2231
29.5k
        bytefn(t->scratch.pal)[pl];
2232
29.5k
    if (i < pal_sz) {
2233
25.8k
        const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2234
25.8k
        int prev = pal[i++] = dav1d_msac_decode_bools(&ts->msac, bpc);
2235
2236
25.8k
        if (i < pal_sz) {
2237
23.4k
            int bits = bpc - 3 + dav1d_msac_decode_bools(&ts->msac, 2);
2238
23.4k
            const int max = (1 << bpc) - 1;
2239
2240
53.9k
            do {
2241
53.9k
                const int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2242
53.9k
                prev = pal[i++] = imin(prev + delta + !pl, max);
2243
53.9k
                if (prev + !pl >= max) {
2244
31.2k
                    for (; i < pal_sz; i++)
2245
20.3k
                        pal[i] = max;
2246
10.8k
                    break;
2247
10.8k
                }
2248
43.0k
                bits = imin(bits, 1 + ulog2(max - prev - !pl));
2249
43.0k
            } while (i < pal_sz);
2250
23.4k
        }
2251
2252
        // merge cache+new entries
2253
25.8k
        int n = 0, m = n_used_cache;
2254
144k
        for (i = 0; i < pal_sz; i++) {
2255
119k
            if (n < n_used_cache && (m >= pal_sz || used_cache[n] <= pal[m])) {
2256
19.0k
                pal[i] = used_cache[n++];
2257
100k
            } else {
2258
100k
                assert(m < pal_sz);
2259
100k
                pal[i] = pal[m++];
2260
100k
            }
2261
119k
        }
2262
25.8k
    } else {
2263
3.72k
        memcpy(pal, used_cache, n_used_cache * sizeof(*used_cache));
2264
3.72k
    }
2265
2266
29.5k
    if (DEBUG_BLOCK_INFO) {
2267
0
        printf("Post-pal[pl=%d,sz=%d,cache_size=%d,used_cache=%d]: r=%d, cache=",
2268
0
               pl, pal_sz, n_cache, n_used_cache, ts->msac.rng);
2269
0
        for (int n = 0; n < n_cache; n++)
2270
0
            printf("%c%02x", n ? ' ' : '[', cache[n]);
2271
0
        printf("%s, pal=", n_cache ? "]" : "[]");
2272
0
        for (int n = 0; n < pal_sz; n++)
2273
0
            printf("%c%02x", n ? ' ' : '[', pal[n]);
2274
0
        printf("]\n");
2275
0
    }
2276
29.5k
}
dav1d_read_pal_plane_8bpc
Line
Count
Source
2175
11.9k
{
2176
11.9k
    Dav1dTileState *const ts = t->ts;
2177
11.9k
    const Dav1dFrameContext *const f = t->f;
2178
11.9k
    const int pal_sz = b->pal_sz[pl] = dav1d_msac_decode_symbol_adapt8(&ts->msac,
2179
11.9k
                                           ts->cdf.m.pal_sz[pl][sz_ctx], 6) + 2;
2180
11.9k
    pixel cache[16], used_cache[8];
2181
11.9k
    int l_cache = pl ? t->pal_sz_uv[1][by4] : t->l.pal_sz[by4];
2182
11.9k
    int n_cache = 0;
2183
    // don't reuse above palette outside SB64 boundaries
2184
11.9k
    int a_cache = by4 & 15 ? pl ? t->pal_sz_uv[0][bx4] : t->a->pal_sz[bx4] : 0;
2185
11.9k
    const pixel *l = bytefn(t->al_pal)[1][by4][pl];
2186
11.9k
    const pixel *a = bytefn(t->al_pal)[0][bx4][pl];
2187
2188
    // fill/sort cache
2189
19.8k
    while (l_cache && a_cache) {
2190
7.91k
        if (*l < *a) {
2191
2.87k
            if (!n_cache || cache[n_cache - 1] != *l)
2192
2.83k
                cache[n_cache++] = *l;
2193
2.87k
            l++;
2194
2.87k
            l_cache--;
2195
5.04k
        } else {
2196
5.04k
            if (*a == *l) {
2197
2.09k
                l++;
2198
2.09k
                l_cache--;
2199
2.09k
            }
2200
5.04k
            if (!n_cache || cache[n_cache - 1] != *a)
2201
4.84k
                cache[n_cache++] = *a;
2202
5.04k
            a++;
2203
5.04k
            a_cache--;
2204
5.04k
        }
2205
7.91k
    }
2206
11.9k
    if (l_cache) {
2207
13.8k
        do {
2208
13.8k
            if (!n_cache || cache[n_cache - 1] != *l)
2209
10.9k
                cache[n_cache++] = *l;
2210
13.8k
            l++;
2211
13.8k
        } while (--l_cache > 0);
2212
8.56k
    } else if (a_cache) {
2213
9.48k
        do {
2214
9.48k
            if (!n_cache || cache[n_cache - 1] != *a)
2215
7.16k
                cache[n_cache++] = *a;
2216
9.48k
            a++;
2217
9.48k
        } while (--a_cache > 0);
2218
2.34k
    }
2219
2220
    // find reused cache entries
2221
11.9k
    int i = 0;
2222
35.1k
    for (int n = 0; n < n_cache && i < pal_sz; n++)
2223
23.1k
        if (dav1d_msac_decode_bool_equi(&ts->msac))
2224
11.5k
            used_cache[i++] = cache[n];
2225
11.9k
    const int n_used_cache = i;
2226
2227
    // parse new entries
2228
11.9k
    pixel *const pal = t->frame_thread.pass ?
2229
11.9k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2230
11.9k
                            ((t->bx >> 1) + (t->by & 1))][pl] :
2231
18.4E
        bytefn(t->scratch.pal)[pl];
2232
11.9k
    if (i < pal_sz) {
2233
10.5k
        const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2234
10.5k
        int prev = pal[i++] = dav1d_msac_decode_bools(&ts->msac, bpc);
2235
2236
10.5k
        if (i < pal_sz) {
2237
9.53k
            int bits = bpc - 3 + dav1d_msac_decode_bools(&ts->msac, 2);
2238
9.53k
            const int max = (1 << bpc) - 1;
2239
2240
21.9k
            do {
2241
21.9k
                const int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2242
21.9k
                prev = pal[i++] = imin(prev + delta + !pl, max);
2243
21.9k
                if (prev + !pl >= max) {
2244
13.2k
                    for (; i < pal_sz; i++)
2245
8.70k
                        pal[i] = max;
2246
4.52k
                    break;
2247
4.52k
                }
2248
17.4k
                bits = imin(bits, 1 + ulog2(max - prev - !pl));
2249
17.4k
            } while (i < pal_sz);
2250
9.53k
        }
2251
2252
        // merge cache+new entries
2253
10.5k
        int n = 0, m = n_used_cache;
2254
59.4k
        for (i = 0; i < pal_sz; i++) {
2255
48.8k
            if (n < n_used_cache && (m >= pal_sz || used_cache[n] <= pal[m])) {
2256
7.70k
                pal[i] = used_cache[n++];
2257
41.1k
            } else {
2258
41.1k
                assert(m < pal_sz);
2259
41.1k
                pal[i] = pal[m++];
2260
41.1k
            }
2261
48.8k
        }
2262
10.5k
    } else {
2263
1.38k
        memcpy(pal, used_cache, n_used_cache * sizeof(*used_cache));
2264
1.38k
    }
2265
2266
11.9k
    if (DEBUG_BLOCK_INFO) {
2267
0
        printf("Post-pal[pl=%d,sz=%d,cache_size=%d,used_cache=%d]: r=%d, cache=",
2268
0
               pl, pal_sz, n_cache, n_used_cache, ts->msac.rng);
2269
0
        for (int n = 0; n < n_cache; n++)
2270
0
            printf("%c%02x", n ? ' ' : '[', cache[n]);
2271
0
        printf("%s, pal=", n_cache ? "]" : "[]");
2272
0
        for (int n = 0; n < pal_sz; n++)
2273
0
            printf("%c%02x", n ? ' ' : '[', pal[n]);
2274
0
        printf("]\n");
2275
0
    }
2276
11.9k
}
dav1d_read_pal_plane_16bpc
Line
Count
Source
2175
17.6k
{
2176
17.6k
    Dav1dTileState *const ts = t->ts;
2177
17.6k
    const Dav1dFrameContext *const f = t->f;
2178
17.6k
    const int pal_sz = b->pal_sz[pl] = dav1d_msac_decode_symbol_adapt8(&ts->msac,
2179
17.6k
                                           ts->cdf.m.pal_sz[pl][sz_ctx], 6) + 2;
2180
17.6k
    pixel cache[16], used_cache[8];
2181
17.6k
    int l_cache = pl ? t->pal_sz_uv[1][by4] : t->l.pal_sz[by4];
2182
17.6k
    int n_cache = 0;
2183
    // don't reuse above palette outside SB64 boundaries
2184
17.6k
    int a_cache = by4 & 15 ? pl ? t->pal_sz_uv[0][bx4] : t->a->pal_sz[bx4] : 0;
2185
17.6k
    const pixel *l = bytefn(t->al_pal)[1][by4][pl];
2186
17.6k
    const pixel *a = bytefn(t->al_pal)[0][bx4][pl];
2187
2188
    // fill/sort cache
2189
28.1k
    while (l_cache && a_cache) {
2190
10.5k
        if (*l < *a) {
2191
3.88k
            if (!n_cache || cache[n_cache - 1] != *l)
2192
3.86k
                cache[n_cache++] = *l;
2193
3.88k
            l++;
2194
3.88k
            l_cache--;
2195
6.61k
        } else {
2196
6.61k
            if (*a == *l) {
2197
2.70k
                l++;
2198
2.70k
                l_cache--;
2199
2.70k
            }
2200
6.61k
            if (!n_cache || cache[n_cache - 1] != *a)
2201
6.37k
                cache[n_cache++] = *a;
2202
6.61k
            a++;
2203
6.61k
            a_cache--;
2204
6.61k
        }
2205
10.5k
    }
2206
17.6k
    if (l_cache) {
2207
20.7k
        do {
2208
20.7k
            if (!n_cache || cache[n_cache - 1] != *l)
2209
16.9k
                cache[n_cache++] = *l;
2210
20.7k
            l++;
2211
20.7k
        } while (--l_cache > 0);
2212
12.5k
    } else if (a_cache) {
2213
15.2k
        do {
2214
15.2k
            if (!n_cache || cache[n_cache - 1] != *a)
2215
12.2k
                cache[n_cache++] = *a;
2216
15.2k
            a++;
2217
15.2k
        } while (--a_cache > 0);
2218
3.81k
    }
2219
2220
    // find reused cache entries
2221
17.6k
    int i = 0;
2222
52.9k
    for (int n = 0; n < n_cache && i < pal_sz; n++)
2223
35.3k
        if (dav1d_msac_decode_bool_equi(&ts->msac))
2224
17.4k
            used_cache[i++] = cache[n];
2225
17.6k
    const int n_used_cache = i;
2226
2227
    // parse new entries
2228
17.6k
    pixel *const pal = t->frame_thread.pass ?
2229
17.6k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2230
17.6k
                            ((t->bx >> 1) + (t->by & 1))][pl] :
2231
17.6k
        bytefn(t->scratch.pal)[pl];
2232
17.6k
    if (i < pal_sz) {
2233
15.2k
        const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2234
15.2k
        int prev = pal[i++] = dav1d_msac_decode_bools(&ts->msac, bpc);
2235
2236
15.2k
        if (i < pal_sz) {
2237
13.8k
            int bits = bpc - 3 + dav1d_msac_decode_bools(&ts->msac, 2);
2238
13.8k
            const int max = (1 << bpc) - 1;
2239
2240
32.0k
            do {
2241
32.0k
                const int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2242
32.0k
                prev = pal[i++] = imin(prev + delta + !pl, max);
2243
32.0k
                if (prev + !pl >= max) {
2244
17.9k
                    for (; i < pal_sz; i++)
2245
11.6k
                        pal[i] = max;
2246
6.36k
                    break;
2247
6.36k
                }
2248
25.6k
                bits = imin(bits, 1 + ulog2(max - prev - !pl));
2249
25.6k
            } while (i < pal_sz);
2250
13.8k
        }
2251
2252
        // merge cache+new entries
2253
15.2k
        int n = 0, m = n_used_cache;
2254
85.5k
        for (i = 0; i < pal_sz; i++) {
2255
70.2k
            if (n < n_used_cache && (m >= pal_sz || used_cache[n] <= pal[m])) {
2256
11.2k
                pal[i] = used_cache[n++];
2257
58.9k
            } else {
2258
58.9k
                assert(m < pal_sz);
2259
58.9k
                pal[i] = pal[m++];
2260
58.9k
            }
2261
70.2k
        }
2262
15.2k
    } else {
2263
2.34k
        memcpy(pal, used_cache, n_used_cache * sizeof(*used_cache));
2264
2.34k
    }
2265
2266
17.6k
    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
17.6k
}
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.53k
{
2281
7.53k
    bytefn(dav1d_read_pal_plane)(t, b, 1, sz_ctx, bx4, by4);
2282
2283
    // V pal coding
2284
7.53k
    Dav1dTileState *const ts = t->ts;
2285
7.53k
    const Dav1dFrameContext *const f = t->f;
2286
7.53k
    pixel *const pal = t->frame_thread.pass ?
2287
7.53k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2288
7.53k
                            ((t->bx >> 1) + (t->by & 1))][2] :
2289
18.4E
        bytefn(t->scratch.pal)[2];
2290
7.53k
    const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2291
7.53k
    if (dav1d_msac_decode_bool_equi(&ts->msac)) {
2292
4.15k
        const int bits = bpc - 4 + dav1d_msac_decode_bools(&ts->msac, 2);
2293
4.15k
        int prev = pal[0] = dav1d_msac_decode_bools(&ts->msac, bpc);
2294
4.15k
        const int max = (1 << bpc) - 1;
2295
17.6k
        for (int i = 1; i < b->pal_sz[1]; i++) {
2296
13.4k
            int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2297
13.4k
            if (delta && dav1d_msac_decode_bool_equi(&ts->msac)) delta = -delta;
2298
13.4k
            prev = pal[i] = (prev + delta) & max;
2299
13.4k
        }
2300
4.15k
    } else {
2301
17.3k
        for (int i = 0; i < b->pal_sz[1]; i++)
2302
13.9k
            pal[i] = dav1d_msac_decode_bools(&ts->msac, bpc);
2303
3.37k
    }
2304
7.53k
    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.53k
}
dav1d_read_pal_uv_8bpc
Line
Count
Source
2280
3.17k
{
2281
3.17k
    bytefn(dav1d_read_pal_plane)(t, b, 1, sz_ctx, bx4, by4);
2282
2283
    // V pal coding
2284
3.17k
    Dav1dTileState *const ts = t->ts;
2285
3.17k
    const Dav1dFrameContext *const f = t->f;
2286
3.17k
    pixel *const pal = t->frame_thread.pass ?
2287
3.17k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2288
3.17k
                            ((t->bx >> 1) + (t->by & 1))][2] :
2289
18.4E
        bytefn(t->scratch.pal)[2];
2290
18.4E
    const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2291
3.17k
    if (dav1d_msac_decode_bool_equi(&ts->msac)) {
2292
1.72k
        const int bits = bpc - 4 + dav1d_msac_decode_bools(&ts->msac, 2);
2293
1.72k
        int prev = pal[0] = dav1d_msac_decode_bools(&ts->msac, bpc);
2294
1.72k
        const int max = (1 << bpc) - 1;
2295
7.54k
        for (int i = 1; i < b->pal_sz[1]; i++) {
2296
5.82k
            int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2297
5.82k
            if (delta && dav1d_msac_decode_bool_equi(&ts->msac)) delta = -delta;
2298
5.82k
            prev = pal[i] = (prev + delta) & max;
2299
5.82k
        }
2300
1.72k
    } else {
2301
7.35k
        for (int i = 0; i < b->pal_sz[1]; i++)
2302
5.90k
            pal[i] = dav1d_msac_decode_bools(&ts->msac, bpc);
2303
1.44k
    }
2304
3.17k
    if (DEBUG_BLOCK_INFO) {
2305
0
        printf("Post-pal[pl=2]: r=%d ", ts->msac.rng);
2306
0
        for (int n = 0; n < b->pal_sz[1]; n++)
2307
0
            printf("%c%02x", n ? ' ' : '[', pal[n]);
2308
0
        printf("]\n");
2309
0
    }
2310
3.17k
}
dav1d_read_pal_uv_16bpc
Line
Count
Source
2280
4.35k
{
2281
4.35k
    bytefn(dav1d_read_pal_plane)(t, b, 1, sz_ctx, bx4, by4);
2282
2283
    // V pal coding
2284
4.35k
    Dav1dTileState *const ts = t->ts;
2285
4.35k
    const Dav1dFrameContext *const f = t->f;
2286
4.35k
    pixel *const pal = t->frame_thread.pass ?
2287
4.35k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2288
4.35k
                            ((t->bx >> 1) + (t->by & 1))][2] :
2289
4.35k
        bytefn(t->scratch.pal)[2];
2290
4.35k
    const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2291
4.35k
    if (dav1d_msac_decode_bool_equi(&ts->msac)) {
2292
2.42k
        const int bits = bpc - 4 + dav1d_msac_decode_bools(&ts->msac, 2);
2293
2.42k
        int prev = pal[0] = dav1d_msac_decode_bools(&ts->msac, bpc);
2294
2.42k
        const int max = (1 << bpc) - 1;
2295
10.0k
        for (int i = 1; i < b->pal_sz[1]; i++) {
2296
7.65k
            int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2297
7.65k
            if (delta && dav1d_msac_decode_bool_equi(&ts->msac)) delta = -delta;
2298
7.65k
            prev = pal[i] = (prev + delta) & max;
2299
7.65k
        }
2300
2.42k
    } else {
2301
9.99k
        for (int i = 0; i < b->pal_sz[1]; i++)
2302
8.05k
            pal[i] = dav1d_msac_decode_bools(&ts->msac, bpc);
2303
1.93k
    }
2304
4.35k
    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.35k
}