Coverage Report

Created: 2026-07-16 06:29

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