Coverage Report

Created: 2026-07-30 06:25

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/work/dav1d/src/recon_tmpl.c
Line
Count
Source
1
/*
2
 * Copyright © 2018-2021, VideoLAN and dav1d authors
3
 * Copyright © 2018, Two Orioles, LLC
4
 * All rights reserved.
5
 *
6
 * Redistribution and use in source and binary forms, with or without
7
 * modification, are permitted provided that the following conditions are met:
8
 *
9
 * 1. Redistributions of source code must retain the above copyright notice, this
10
 *    list of conditions and the following disclaimer.
11
 *
12
 * 2. Redistributions in binary form must reproduce the above copyright notice,
13
 *    this list of conditions and the following disclaimer in the documentation
14
 *    and/or other materials provided with the distribution.
15
 *
16
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
 */
27
28
#include "config.h"
29
30
#include <string.h>
31
#include <stdio.h>
32
33
#include "common/attributes.h"
34
#include "common/bitdepth.h"
35
#include "common/dump.h"
36
#include "common/frame.h"
37
#include "common/intops.h"
38
39
#include "src/cdef_apply.h"
40
#include "src/ctx.h"
41
#include "src/ipred_prepare.h"
42
#include "src/lf_apply.h"
43
#include "src/lr_apply.h"
44
#include "src/recon.h"
45
#include "src/scan.h"
46
#include "src/tables.h"
47
#include "src/wedge.h"
48
49
740k
static inline unsigned read_golomb(MsacContext *const msac) {
50
740k
    int len = 0;
51
740k
    unsigned val = 1;
52
53
1.36M
    while (!dav1d_msac_decode_bool_equi(msac) && len < 32) len++;
54
1.36M
    while (len--) val = (val << 1) + dav1d_msac_decode_bool_equi(msac);
55
56
740k
    return val - 1;
57
740k
}
58
59
static inline unsigned get_skip_ctx(const TxfmInfo *const t_dim,
60
                                    const enum BlockSize bs,
61
                                    const uint8_t *const a,
62
                                    const uint8_t *const l,
63
                                    const int chroma,
64
                                    const enum Dav1dPixelLayout layout)
65
4.49M
{
66
4.49M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
67
68
4.49M
    if (chroma) {
69
2.45M
        const int ss_ver = layout == DAV1D_PIXEL_LAYOUT_I420;
70
2.45M
        const int ss_hor = layout != DAV1D_PIXEL_LAYOUT_I444;
71
2.45M
        const int not_one_blk = b_dim[2] - (!!b_dim[2] && ss_hor) > t_dim->lw ||
72
1.42M
                                b_dim[3] - (!!b_dim[3] && ss_ver) > t_dim->lh;
73
2.45M
        unsigned ca, cl;
74
75
2.45M
#define MERGE_CTX(dir, type, no_val) \
76
4.91M
        c##dir = *(const type *) dir != no_val; \
77
4.91M
        break
78
79
2.45M
        switch (t_dim->lw) {
80
        /* For some reason the MSVC CRT _wassert() function is not flagged as
81
         * __declspec(noreturn), so when using those headers the compiler will
82
         * expect execution to continue after an assertion has been triggered
83
         * and will therefore complain about the use of uninitialized variables
84
         * when compiled in debug mode if we put the default case at the end. */
85
0
        default: assert(0); /* fall-through */
86
1.13M
        case TX_4X4:   MERGE_CTX(a, uint8_t,  0x40);
87
465k
        case TX_8X8:   MERGE_CTX(a, uint16_t, 0x4040);
88
297k
        case TX_16X16: MERGE_CTX(a, uint32_t, 0x40404040U);
89
558k
        case TX_32X32: MERGE_CTX(a, uint64_t, 0x4040404040404040ULL);
90
2.45M
        }
91
2.45M
        switch (t_dim->lh) {
92
0
        default: assert(0); /* fall-through */
93
1.24M
        case TX_4X4:   MERGE_CTX(l, uint8_t,  0x40);
94
418k
        case TX_8X8:   MERGE_CTX(l, uint16_t, 0x4040);
95
252k
        case TX_16X16: MERGE_CTX(l, uint32_t, 0x40404040U);
96
546k
        case TX_32X32: MERGE_CTX(l, uint64_t, 0x4040404040404040ULL);
97
2.45M
        }
98
2.45M
#undef MERGE_CTX
99
100
2.45M
        return 7 + not_one_blk * 3 + ca + cl;
101
2.45M
    } else if (b_dim[2] == t_dim->lw && b_dim[3] == t_dim->lh) {
102
793k
        return 0;
103
1.24M
    } else {
104
1.24M
        unsigned la, ll;
105
106
1.24M
#define MERGE_CTX(dir, type, tx) \
107
2.58M
        if (tx == TX_64X64) { \
108
200k
            uint64_t tmp = *(const uint64_t *) dir; \
109
200k
            tmp |= *(const uint64_t *) &dir[8]; \
110
200k
            l##dir = (unsigned) (tmp >> 32) | (unsigned) tmp; \
111
200k
        } else \
112
2.58M
            l##dir = *(const type *) dir; \
113
2.58M
        if (tx == TX_32X32) l##dir |= *(const type *) &dir[sizeof(type)]; \
114
2.58M
        if (tx >= TX_16X16) l##dir |= l##dir >> 16; \
115
2.58M
        if (tx >= TX_8X8)   l##dir |= l##dir >> 8; \
116
2.58M
        break
117
118
1.24M
        switch (t_dim->lw) {
119
0
        default: assert(0); /* fall-through */
120
679k
        case TX_4X4:   MERGE_CTX(a, uint8_t,  TX_4X4);
121
267k
        case TX_8X8:   MERGE_CTX(a, uint16_t, TX_8X8);
122
228k
        case TX_16X16: MERGE_CTX(a, uint32_t, TX_16X16);
123
16.1k
        case TX_32X32: MERGE_CTX(a, uint32_t, TX_32X32);
124
100k
        case TX_64X64: MERGE_CTX(a, uint32_t, TX_64X64);
125
1.24M
        }
126
1.29M
        switch (t_dim->lh) {
127
0
        default: assert(0); /* fall-through */
128
690k
        case TX_4X4:   MERGE_CTX(l, uint8_t,  TX_4X4);
129
259k
        case TX_8X8:   MERGE_CTX(l, uint16_t, TX_8X8);
130
227k
        case TX_16X16: MERGE_CTX(l, uint32_t, TX_16X16);
131
15.8k
        case TX_32X32: MERGE_CTX(l, uint32_t, TX_32X32);
132
100k
        case TX_64X64: MERGE_CTX(l, uint32_t, TX_64X64);
133
1.29M
        }
134
1.29M
#undef MERGE_CTX
135
136
1.29M
        return dav1d_skip_ctx[umin(la & 0x3F, 4)][umin(ll & 0x3F, 4)];
137
1.29M
    }
138
4.49M
}
139
140
static inline unsigned get_dc_sign_ctx(const int /*enum RectTxfmSize*/ tx,
141
                                       const uint8_t *const a,
142
                                       const uint8_t *const l)
143
1.89M
{
144
1.89M
    uint64_t mask = 0xC0C0C0C0C0C0C0C0ULL, mul = 0x0101010101010101ULL;
145
1.89M
    int s;
146
147
1.89M
#if ARCH_X86_64 && defined(__GNUC__)
148
    /* Coerce compilers into producing better code. For some reason
149
     * every x86-64 compiler is awful at handling 64-bit constants. */
150
1.89M
    __asm__("" : "+r"(mask), "+r"(mul));
151
1.89M
#endif
152
153
1.89M
    switch(tx) {
154
0
    default: assert(0); /* fall-through */
155
725k
    case TX_4X4: {
156
725k
        int t = *(const uint8_t *) a >> 6;
157
725k
        t    += *(const uint8_t *) l >> 6;
158
725k
        s = t - 1 - 1;
159
725k
        break;
160
0
    }
161
212k
    case TX_8X8: {
162
212k
        uint32_t t = *(const uint16_t *) a & (uint32_t) mask;
163
212k
        t         += *(const uint16_t *) l & (uint32_t) mask;
164
212k
        t *= 0x04040404U;
165
212k
        s = (int) (t >> 24) - 2 - 2;
166
212k
        break;
167
0
    }
168
178k
    case TX_16X16: {
169
178k
        uint32_t t = (*(const uint32_t *) a & (uint32_t) mask) >> 6;
170
178k
        t         += (*(const uint32_t *) l & (uint32_t) mask) >> 6;
171
178k
        t *= (uint32_t) mul;
172
178k
        s = (int) (t >> 24) - 4 - 4;
173
178k
        break;
174
0
    }
175
168k
    case TX_32X32: {
176
168k
        uint64_t t = (*(const uint64_t *) a & mask) >> 6;
177
168k
        t         += (*(const uint64_t *) l & mask) >> 6;
178
168k
        t *= mul;
179
168k
        s = (int) (t >> 56) - 8 - 8;
180
168k
        break;
181
0
    }
182
86.7k
    case TX_64X64: {
183
86.7k
        uint64_t t = (*(const uint64_t *) &a[0] & mask) >> 6;
184
86.7k
        t         += (*(const uint64_t *) &a[8] & mask) >> 6;
185
86.7k
        t         += (*(const uint64_t *) &l[0] & mask) >> 6;
186
86.7k
        t         += (*(const uint64_t *) &l[8] & mask) >> 6;
187
86.7k
        t *= mul;
188
86.7k
        s = (int) (t >> 56) - 16 - 16;
189
86.7k
        break;
190
0
    }
191
64.9k
    case RTX_4X8: {
192
64.9k
        uint32_t t = *(const uint8_t  *) a & (uint32_t) mask;
193
64.9k
        t         += *(const uint16_t *) l & (uint32_t) mask;
194
64.9k
        t *= 0x04040404U;
195
64.9k
        s = (int) (t >> 24) - 1 - 2;
196
64.9k
        break;
197
0
    }
198
97.6k
    case RTX_8X4: {
199
97.6k
        uint32_t t = *(const uint16_t *) a & (uint32_t) mask;
200
97.6k
        t         += *(const uint8_t  *) l & (uint32_t) mask;
201
97.6k
        t *= 0x04040404U;
202
97.6k
        s = (int) (t >> 24) - 2 - 1;
203
97.6k
        break;
204
0
    }
205
51.6k
    case RTX_8X16: {
206
51.6k
        uint32_t t = *(const uint16_t *) a & (uint32_t) mask;
207
51.6k
        t         += *(const uint32_t *) l & (uint32_t) mask;
208
51.6k
        t = (t >> 6) * (uint32_t) mul;
209
51.6k
        s = (int) (t >> 24) - 2 - 4;
210
51.6k
        break;
211
0
    }
212
80.2k
    case RTX_16X8: {
213
80.2k
        uint32_t t = *(const uint32_t *) a & (uint32_t) mask;
214
80.2k
        t         += *(const uint16_t *) l & (uint32_t) mask;
215
80.2k
        t = (t >> 6) * (uint32_t) mul;
216
80.2k
        s = (int) (t >> 24) - 4 - 2;
217
80.2k
        break;
218
0
    }
219
29.5k
    case RTX_16X32: {
220
29.5k
        uint64_t t = *(const uint32_t *) a & (uint32_t) mask;
221
29.5k
        t         += *(const uint64_t *) l & mask;
222
29.5k
        t = (t >> 6) * mul;
223
29.5k
        s = (int) (t >> 56) - 4 - 8;
224
29.5k
        break;
225
0
    }
226
33.4k
    case RTX_32X16: {
227
33.4k
        uint64_t t = *(const uint64_t *) a & mask;
228
33.4k
        t         += *(const uint32_t *) l & (uint32_t) mask;
229
33.4k
        t = (t >> 6) * mul;
230
33.4k
        s = (int) (t >> 56) - 8 - 4;
231
33.4k
        break;
232
0
    }
233
13.5k
    case RTX_32X64: {
234
13.5k
        uint64_t t = (*(const uint64_t *) &a[0] & mask) >> 6;
235
13.5k
        t         += (*(const uint64_t *) &l[0] & mask) >> 6;
236
13.5k
        t         += (*(const uint64_t *) &l[8] & mask) >> 6;
237
13.5k
        t *= mul;
238
13.5k
        s = (int) (t >> 56) - 8 - 16;
239
13.5k
        break;
240
0
    }
241
10.9k
    case RTX_64X32: {
242
10.9k
        uint64_t t = (*(const uint64_t *) &a[0] & mask) >> 6;
243
10.9k
        t         += (*(const uint64_t *) &a[8] & mask) >> 6;
244
10.9k
        t         += (*(const uint64_t *) &l[0] & mask) >> 6;
245
10.9k
        t *= mul;
246
10.9k
        s = (int) (t >> 56) - 16 - 8;
247
10.9k
        break;
248
0
    }
249
31.1k
    case RTX_4X16: {
250
31.1k
        uint32_t t = *(const uint8_t  *) a & (uint32_t) mask;
251
31.1k
        t         += *(const uint32_t *) l & (uint32_t) mask;
252
31.1k
        t = (t >> 6) * (uint32_t) mul;
253
31.1k
        s = (int) (t >> 24) - 1 - 4;
254
31.1k
        break;
255
0
    }
256
59.1k
    case RTX_16X4: {
257
59.1k
        uint32_t t = *(const uint32_t *) a & (uint32_t) mask;
258
59.1k
        t         += *(const uint8_t  *) l & (uint32_t) mask;
259
59.1k
        t = (t >> 6) * (uint32_t) mul;
260
59.1k
        s = (int) (t >> 24) - 4 - 1;
261
59.1k
        break;
262
0
    }
263
19.7k
    case RTX_8X32: {
264
19.7k
        uint64_t t = *(const uint16_t *) a & (uint32_t) mask;
265
19.7k
        t         += *(const uint64_t *) l & mask;
266
19.7k
        t = (t >> 6) * mul;
267
19.7k
        s = (int) (t >> 56) - 2 - 8;
268
19.7k
        break;
269
0
    }
270
28.3k
    case RTX_32X8: {
271
28.3k
        uint64_t t = *(const uint64_t *) a & mask;
272
28.3k
        t         += *(const uint16_t *) l & (uint32_t) mask;
273
28.3k
        t = (t >> 6) * mul;
274
28.3k
        s = (int) (t >> 56) - 8 - 2;
275
28.3k
        break;
276
0
    }
277
5.36k
    case RTX_16X64: {
278
5.36k
        uint64_t t = *(const uint32_t *) a & (uint32_t) mask;
279
5.36k
        t         += *(const uint64_t *) &l[0] & mask;
280
5.36k
        t = (t >> 6) + ((*(const uint64_t *) &l[8] & mask) >> 6);
281
5.36k
        t *= mul;
282
5.36k
        s = (int) (t >> 56) - 4 - 16;
283
5.36k
        break;
284
0
    }
285
5.10k
    case RTX_64X16: {
286
5.10k
        uint64_t t = *(const uint64_t *) &a[0] & mask;
287
5.10k
        t         += *(const uint32_t *) l & (uint32_t) mask;
288
5.10k
        t = (t >> 6) + ((*(const uint64_t *) &a[8] & mask) >> 6);
289
5.10k
        t *= mul;
290
5.10k
        s = (int) (t >> 56) - 16 - 4;
291
5.10k
        break;
292
0
    }
293
1.89M
    }
294
295
1.89M
    return (s != 0) + (s > 0);
296
1.89M
}
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
39.7M
{
305
39.7M
    unsigned mag = levels[0 * stride + 1] + levels[1 * stride + 0];
306
39.7M
    unsigned offset;
307
39.7M
    if (tx_class == TX_CLASS_2D) {
308
37.2M
        mag += levels[1 * stride + 1];
309
37.2M
        *hi_mag = mag;
310
37.2M
        mag += levels[0 * stride + 2] + levels[2 * stride + 0];
311
37.2M
        offset = ctx_offsets[umin(y, 4)][umin(x, 4)];
312
37.2M
    } else {
313
2.50M
        mag += levels[0 * stride + 2];
314
2.50M
        *hi_mag = mag;
315
2.50M
        mag += levels[0 * stride + 3] + levels[0 * stride + 4];
316
2.50M
        offset = 26 + (y > 1 ? 10 : y * 5);
317
2.50M
    }
318
39.7M
    return offset + (mag > 512 ? 4 : (mag + 64) >> 7);
319
39.7M
}
320
321
static int decode_coefs(Dav1dTaskContext *const t,
322
                        uint8_t *const a, uint8_t *const l,
323
                        const enum RectTxfmSize tx, const enum BlockSize bs,
324
                        const Av1Block *const b, const int intra,
325
                        const int plane, coef *cf,
326
                        enum TxfmType *const txtp, uint8_t *res_ctx)
327
4.48M
{
328
4.48M
    Dav1dTileState *const ts = t->ts;
329
4.48M
    const int chroma = !!plane;
330
4.48M
    const Dav1dFrameContext *const f = t->f;
331
4.48M
    const int lossless = f->frame_hdr->segmentation.lossless[b->seg_id];
332
4.48M
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[tx];
333
4.48M
    const int dbg = DEBUG_BLOCK_INFO && plane && 0;
334
335
4.48M
    if (dbg)
336
0
        printf("Start: r=%d\n", ts->msac.rng);
337
338
    // does this block have any non-zero coefficients
339
4.48M
    const int sctx = get_skip_ctx(t_dim, bs, a, l, chroma, f->cur.p.layout);
340
4.48M
    const int all_skip = dav1d_msac_decode_bool_adapt(&ts->msac,
341
4.48M
                             ts->cdf.coef.skip[t_dim->ctx][sctx]);
342
4.48M
    if (dbg)
343
0
        printf("Post-non-zero[%d][%d][%d]: r=%d\n",
344
0
               t_dim->ctx, sctx, all_skip, ts->msac.rng);
345
4.48M
    if (all_skip) {
346
2.20M
        *res_ctx = 0x40;
347
2.20M
        *txtp = lossless * WHT_WHT; /* lossless ? WHT_WHT : DCT_DCT */
348
2.20M
        return -1;
349
2.20M
    }
350
351
    // transform type (chroma: derived, luma: explicitly coded)
352
2.27M
    if (lossless) {
353
668k
        assert(t_dim->max == TX_4X4);
354
668k
        *txtp = WHT_WHT;
355
1.60M
    } else if (t_dim->max + intra >= TX_64X64) {
356
404k
        *txtp = DCT_DCT;
357
1.20M
    } else if (chroma) {
358
        // inferred from either the luma txtp (inter) or a LUT (intra)
359
340k
        *txtp = intra ? dav1d_txtp_from_uvmode[b->uv_mode] :
360
340k
                        get_uv_inter_txtp(t_dim, *txtp);
361
863k
    } 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
5.53k
        *txtp = DCT_DCT;
366
858k
    } else {
367
858k
        unsigned idx;
368
858k
        if (intra) {
369
680k
            const enum IntraPredMode y_mode_nofilt = b->y_mode == FILTER_PRED ?
370
589k
                dav1d_filter_mode_to_y_mode[b->y_angle] : b->y_mode;
371
680k
            if (f->frame_hdr->reduced_txtp_set || t_dim->min == TX_16X16) {
372
324k
                idx = dav1d_msac_decode_symbol_adapt8(&ts->msac,
373
324k
                          ts->cdf.m.txtp_intra2[t_dim->min][y_mode_nofilt], 4);
374
324k
                *txtp = dav1d_tx_types_per_set[idx + 0];
375
355k
            } else {
376
355k
                idx = dav1d_msac_decode_symbol_adapt8(&ts->msac,
377
355k
                          ts->cdf.m.txtp_intra1[t_dim->min][y_mode_nofilt], 6);
378
355k
                *txtp = dav1d_tx_types_per_set[idx + 5];
379
355k
            }
380
680k
            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
680k
        } else {
384
177k
            if (f->frame_hdr->reduced_txtp_set || t_dim->max == TX_32X32) {
385
58.4k
                idx = dav1d_msac_decode_bool_adapt(&ts->msac,
386
58.4k
                          ts->cdf.m.txtp_inter3[t_dim->min]);
387
58.4k
                *txtp = (idx - 1) & IDTX; /* idx ? DCT_DCT : IDTX */
388
119k
            } else if (t_dim->min == TX_16X16) {
389
14.4k
                idx = dav1d_msac_decode_symbol_adapt16(&ts->msac,
390
14.4k
                          ts->cdf.m.txtp_inter2, 11);
391
14.4k
                *txtp = dav1d_tx_types_per_set[idx + 12];
392
104k
            } else {
393
104k
                idx = dav1d_msac_decode_symbol_adapt16(&ts->msac,
394
104k
                          ts->cdf.m.txtp_inter1[t_dim->min], 15);
395
104k
                *txtp = dav1d_tx_types_per_set[idx + 24];
396
104k
            }
397
177k
            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
177k
        }
401
858k
    }
402
403
    // find end-of-block (eob)
404
2.27M
    int eob;
405
2.27M
    const int slw = imin(t_dim->lw, TX_32X32), slh = imin(t_dim->lh, TX_32X32);
406
2.27M
    const int tx2dszctx = slw + slh;
407
2.27M
    const enum TxClass tx_class = dav1d_tx_type_class[*txtp];
408
2.27M
    const int is_1d = tx_class != TX_CLASS_2D;
409
2.27M
    switch (tx2dszctx) {
410
0
#define case_sz(sz, bin, ns, is_1d) \
411
2.29M
    case sz: { \
412
2.29M
        uint16_t *const eob_bin_cdf = ts->cdf.coef.eob_bin_##bin[chroma]is_1d; \
413
2.29M
        eob = dav1d_msac_decode_symbol_adapt##ns(&ts->msac, eob_bin_cdf, 4 + sz); \
414
2.29M
        break; \
415
2.29M
    }
416
852k
    case_sz(0,   16,  8, [is_1d]);
417
210k
    case_sz(1,   32,  8, [is_1d]);
418
392k
    case_sz(2,   64,  8, [is_1d]);
419
173k
    case_sz(3,  128,  8, [is_1d]);
420
281k
    case_sz(4,  256, 16, [is_1d]);
421
84.8k
    case_sz(5,  512, 16,        );
422
303k
    case_sz(6, 1024, 16,        );
423
2.27M
#undef case_sz
424
2.27M
    }
425
2.28M
    if (dbg)
426
0
        printf("Post-eob_bin_%d[%d][%d][%d]: r=%d\n",
427
0
               16 << tx2dszctx, chroma, is_1d, eob, ts->msac.rng);
428
2.28M
    if (eob > 1) {
429
1.43M
        const int eob_bin = eob - 2;
430
1.43M
        uint16_t *const eob_hi_bit_cdf =
431
1.43M
            ts->cdf.coef.eob_hi_bit[t_dim->ctx][chroma][eob_bin];
432
1.43M
        const int eob_hi_bit = dav1d_msac_decode_bool_adapt(&ts->msac, eob_hi_bit_cdf);
433
1.43M
        if (dbg)
434
0
            printf("Post-eob_hi_bit[%d][%d][%d][%d]: r=%d\n",
435
0
                   t_dim->ctx, chroma, eob_bin, eob_hi_bit, ts->msac.rng);
436
1.43M
        eob = ((eob_hi_bit | 2) << eob_bin) | dav1d_msac_decode_bools(&ts->msac, eob_bin);
437
1.43M
        if (dbg)
438
0
            printf("Post-eob[%d]: r=%d\n", eob, ts->msac.rng);
439
1.43M
    }
440
2.28M
    assert(eob >= 0);
441
442
    // base tokens
443
2.28M
    uint16_t (*const eob_cdf)[4] = ts->cdf.coef.eob_base_tok[t_dim->ctx][chroma];
444
2.28M
    uint16_t (*const hi_cdf)[4] = ts->cdf.coef.br_tok[imin(t_dim->ctx, 3)][chroma];
445
2.28M
    unsigned rc, dc_tok;
446
447
2.28M
    if (eob) {
448
1.51M
        uint16_t (*const lo_cdf)[4] = ts->cdf.coef.base_tok[t_dim->ctx][chroma];
449
1.51M
        uint8_t *const levels = t->scratch.levels; // bits 0-5: tok, 6-7: lo_tok
450
451
        /* eob */
452
1.51M
        unsigned ctx = 1 + (eob > 2 << tx2dszctx) + (eob > 4 << tx2dszctx);
453
1.51M
        int eob_tok = dav1d_msac_decode_symbol_adapt4(&ts->msac, eob_cdf[ctx], 2);
454
1.51M
        int tok = eob_tok + 1;
455
1.51M
        int level_tok = tok * 0x41;
456
1.51M
        unsigned mag;
457
458
1.51M
#define DECODE_COEFS_CLASS(tx_class) \
459
1.52M
        unsigned x, y; \
460
1.52M
        uint8_t *level; \
461
1.52M
        if (tx_class == TX_CLASS_2D) \
462
1.52M
            rc = scan[eob], x = rc >> shift, y = rc & mask; \
463
1.52M
        else if (tx_class == TX_CLASS_H) \
464
            /* Transposing reduces the stride and padding requirements */ \
465
113k
            x = eob & mask, y = eob >> shift, rc = eob; \
466
113k
        else /* tx_class == TX_CLASS_V */ \
467
113k
            x = eob & mask, y = eob >> shift, rc = (x << shift2) | y; \
468
1.52M
        if (dbg) \
469
1.52M
            printf("Post-lo_tok[%d][%d][%d][%d=%d=%d]: r=%d\n", \
470
0
                   t_dim->ctx, chroma, ctx, eob, rc, tok, ts->msac.rng); \
471
1.52M
        if (eob_tok == 2) { \
472
28.5k
            ctx = (tx_class == TX_CLASS_2D ? (x | y) > 1 : y != 0) ? 14 : 7; \
473
28.5k
            tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[ctx]); \
474
28.5k
            level_tok = tok + (3 << 6); \
475
28.5k
            if (dbg) \
476
28.5k
                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
28.5k
        } \
480
1.52M
        cf[rc] = tok << 11; \
481
1.52M
        if (tx_class == TX_CLASS_2D) \
482
1.52M
            level = levels + rc; \
483
1.52M
        else \
484
1.52M
            level = levels + x * stride + y; \
485
1.52M
        *level = (uint8_t) level_tok; \
486
41.2M
        for (int i = eob - 1; i > 0; i--) { /* ac */ \
487
39.7M
            unsigned rc_i; \
488
39.7M
            if (tx_class == TX_CLASS_2D) \
489
39.7M
                rc_i = scan[i], x = rc_i >> shift, y = rc_i & mask; \
490
39.7M
            else if (tx_class == TX_CLASS_H) \
491
2.47M
                x = i & mask, y = i >> shift, rc_i = i; \
492
2.47M
            else /* tx_class == TX_CLASS_V */ \
493
2.47M
                x = i & mask, y = i >> shift, rc_i = (x << shift2) | y; \
494
39.7M
            assert(x < 32 && y < 32); \
495
39.7M
            if (tx_class == TX_CLASS_2D) \
496
39.7M
                level = levels + rc_i; \
497
39.7M
            else \
498
39.7M
                level = levels + x * stride + y; \
499
39.7M
            ctx = get_lo_ctx(level, tx_class, &mag, lo_ctx_offsets, x, y, stride); \
500
39.7M
            if (tx_class == TX_CLASS_2D) \
501
39.7M
                y |= x; \
502
39.7M
            tok = dav1d_msac_decode_symbol_adapt4(&ts->msac, lo_cdf[ctx], 3); \
503
39.7M
            if (dbg) \
504
39.7M
                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
39.7M
            if (tok == 3) { \
507
3.23M
                mag &= 63; \
508
3.23M
                ctx = (y > (tx_class == TX_CLASS_2D) ? 14 : 7) + \
509
3.23M
                      (mag > 12 ? 6 : (mag + 1) >> 1); \
510
3.23M
                tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[ctx]); \
511
3.23M
                if (dbg) \
512
3.23M
                    printf("Post-hi_tok[%d][%d][%d][%d=%d=%d]: r=%d\n", \
513
0
                           imin(t_dim->ctx, 3), chroma, ctx, i, rc_i, tok, \
514
0
                           ts->msac.rng); \
515
3.23M
                *level = (uint8_t) (tok + (3 << 6)); \
516
3.23M
                cf[rc_i] = (tok << 11) | rc; \
517
3.23M
                rc = rc_i; \
518
36.4M
            } else { \
519
                /* 0x1 for tok, 0x7ff as bitmask for rc, 0x41 for level_tok */ \
520
36.4M
                tok *= 0x17ff41; \
521
36.4M
                *level = (uint8_t) tok; \
522
                /* tok ? (tok << 11) | rc : 0 */ \
523
36.4M
                tok = (tok >> 9) & (rc + ~0x7ffu); \
524
36.4M
                if (tok) rc = rc_i; \
525
36.4M
                cf[rc_i] = tok; \
526
36.4M
            } \
527
39.7M
        } \
528
        /* dc */ \
529
1.52M
        ctx = (tx_class == TX_CLASS_2D) ? 0 : \
530
1.52M
            get_lo_ctx(levels, tx_class, &mag, lo_ctx_offsets, 0, 0, stride); \
531
1.52M
        dc_tok = dav1d_msac_decode_symbol_adapt4(&ts->msac, lo_cdf[ctx], 3); \
532
1.52M
        if (dbg) \
533
1.52M
            printf("Post-dc_lo_tok[%d][%d][%d][%d]: r=%d\n", \
534
0
                   t_dim->ctx, chroma, ctx, dc_tok, ts->msac.rng); \
535
1.52M
        if (dc_tok == 3) { \
536
543k
            if (tx_class == TX_CLASS_2D) \
537
543k
                mag = levels[0 * stride + 1] + levels[1 * stride + 0] + \
538
530k
                      levels[1 * stride + 1]; \
539
543k
            mag &= 63; \
540
543k
            ctx = mag > 12 ? 6 : (mag + 1) >> 1; \
541
543k
            dc_tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[ctx]); \
542
543k
            if (dbg) \
543
543k
                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
543k
        } \
546
1.52M
        break
547
548
1.51M
        const uint16_t *scan;
549
1.51M
        switch (tx_class) {
550
1.40M
        case TX_CLASS_2D: {
551
1.40M
            const unsigned nonsquare_tx = tx >= RTX_4X8;
552
1.40M
            const uint8_t (*const lo_ctx_offsets)[5] =
553
1.40M
                dav1d_lo_ctx_offsets[nonsquare_tx + (tx & nonsquare_tx)];
554
1.40M
            scan = dav1d_scans[tx];
555
1.40M
            const ptrdiff_t stride = 4 << slh;
556
1.40M
            const unsigned shift = slh + 2, shift2 = 0;
557
1.40M
            const unsigned mask = (4 << slh) - 1;
558
1.40M
            memset(levels, 0, stride * ((4 << slw) + 2));
559
1.40M
            DECODE_COEFS_CLASS(TX_CLASS_2D);
560
1.40M
        }
561
76.7k
        case TX_CLASS_H: {
562
76.7k
            const uint8_t (*const lo_ctx_offsets)[5] = NULL;
563
76.7k
            const ptrdiff_t stride = 16;
564
76.7k
            const unsigned shift = slh + 2, shift2 = 0;
565
76.7k
            const unsigned mask = (4 << slh) - 1;
566
76.7k
            memset(levels, 0, stride * ((4 << slh) + 2));
567
76.7k
            DECODE_COEFS_CLASS(TX_CLASS_H);
568
76.7k
        }
569
42.7k
        case TX_CLASS_V: {
570
42.7k
            const uint8_t (*const lo_ctx_offsets)[5] = NULL;
571
42.7k
            const ptrdiff_t stride = 16;
572
42.7k
            const unsigned shift = slw + 2, shift2 = slh + 2;
573
42.7k
            const unsigned mask = (4 << slw) - 1;
574
42.7k
            memset(levels, 0, stride * ((4 << slw) + 2));
575
42.7k
            DECODE_COEFS_CLASS(TX_CLASS_V);
576
42.7k
        }
577
0
#undef DECODE_COEFS_CLASS
578
0
        default: assert(0);
579
1.51M
        }
580
1.51M
    } else { // dc-only
581
764k
        int tok_br = dav1d_msac_decode_symbol_adapt4(&ts->msac, eob_cdf[0], 2);
582
764k
        dc_tok = 1 + tok_br;
583
764k
        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
764k
        if (tok_br == 2) {
587
30.7k
            dc_tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[0]);
588
30.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
30.7k
        }
592
764k
        rc = 0;
593
764k
    }
594
595
    // residual and sign
596
2.29M
    const uint16_t *const dq_tbl = ts->dq[b->seg_id][plane];
597
2.29M
    const uint8_t *const qm_tbl = *txtp < IDTX ? f->qm[tx][plane] : NULL;
598
2.29M
    const int dq_shift = imax(0, t_dim->ctx - 2);
599
2.29M
    const int cf_max = ~(~127U << (BITDEPTH == 8 ? 8 : f->cur.p.bpc));
600
2.29M
    unsigned cul_level, dc_sign_level;
601
602
2.29M
    if (!dc_tok) {
603
398k
        cul_level = 0;
604
398k
        dc_sign_level = 1 << 6;
605
398k
        if (qm_tbl) goto ac_qm;
606
259k
        goto ac_noqm;
607
398k
    }
608
609
1.89M
    const int dc_sign_ctx = get_dc_sign_ctx(tx, a, l);
610
1.89M
    uint16_t *const dc_sign_cdf = ts->cdf.coef.dc_sign[chroma][dc_sign_ctx];
611
1.89M
    const int dc_sign = dav1d_msac_decode_bool_adapt(&ts->msac, dc_sign_cdf);
612
1.89M
    if (dbg)
613
0
        printf("Post-dc_sign[%d][%d][%d]: r=%d\n",
614
0
               chroma, dc_sign_ctx, dc_sign, ts->msac.rng);
615
616
1.89M
    int dc_dq = dq_tbl[0];
617
1.89M
    dc_sign_level = (dc_sign - 1) & (2 << 6);
618
619
1.89M
    if (qm_tbl) {
620
714k
        dc_dq = (dc_dq * qm_tbl[0] + 16) >> 5;
621
622
714k
        if (dc_tok == 15) {
623
17.9k
            dc_tok = read_golomb(&ts->msac) + 15;
624
17.9k
            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
17.9k
            dc_tok &= 0xfffff;
629
17.9k
            dc_dq = (dc_dq * dc_tok) & 0xffffff;
630
696k
        } else {
631
696k
            dc_dq *= dc_tok;
632
696k
            assert(dc_dq <= 0xffffff);
633
696k
        }
634
714k
        cul_level = dc_tok;
635
714k
        dc_dq >>= dq_shift;
636
714k
        dc_dq = umin(dc_dq, cf_max + dc_sign);
637
714k
        cf[0] = (coef) (dc_sign ? -dc_dq : dc_dq);
638
639
1.04M
        if (rc) ac_qm: {
640
1.04M
            const unsigned ac_dq = dq_tbl[1];
641
7.66M
            do {
642
7.66M
                const int sign = dav1d_msac_decode_bool_equi(&ts->msac);
643
7.66M
                if (dbg)
644
0
                    printf("Post-sign[%d=%d]: r=%d\n", rc, sign, ts->msac.rng);
645
7.66M
                const unsigned rc_tok = cf[rc];
646
7.66M
                unsigned tok, dq = (ac_dq * qm_tbl[rc] + 16) >> 5;
647
7.66M
                int dq_sat;
648
649
7.66M
                if (rc_tok >= (15 << 11)) {
650
557k
                    tok = read_golomb(&ts->msac) + 15;
651
557k
                    if (dbg)
652
0
                        printf("Post-residual[%d=%d->%d]: r=%d\n",
653
0
                               rc, tok - 15, tok, ts->msac.rng);
654
655
557k
                    tok &= 0xfffff;
656
557k
                    dq = (dq * tok) & 0xffffff;
657
7.11M
                } else {
658
7.11M
                    tok = rc_tok >> 11;
659
7.11M
                    dq *= tok;
660
7.11M
                    assert(dq <= 0xffffff);
661
7.11M
                }
662
7.66M
                cul_level += tok;
663
7.66M
                dq >>= dq_shift;
664
7.66M
                dq_sat = umin(dq, cf_max + sign);
665
7.66M
                cf[rc] = (coef) (sign ? -dq_sat : dq_sat);
666
667
7.66M
                rc = rc_tok & 0x3ff;
668
7.66M
            } while (rc);
669
1.04M
        }
670
1.17M
    } else {
671
        // non-qmatrix is the common case and allows for additional optimizations
672
1.17M
        if (dc_tok == 15) {
673
37.8k
            dc_tok = read_golomb(&ts->msac) + 15;
674
37.8k
            if (dbg)
675
0
                printf("Post-dc_residual[%d->%d]: r=%d\n",
676
0
                       dc_tok - 15, dc_tok, ts->msac.rng);
677
678
37.8k
            dc_tok &= 0xfffff;
679
37.8k
            dc_dq = ((dc_dq * dc_tok) & 0xffffff) >> dq_shift;
680
37.8k
            dc_dq = umin(dc_dq, cf_max + dc_sign);
681
1.14M
        } else {
682
1.14M
            dc_dq = ((dc_dq * dc_tok) >> dq_shift);
683
1.14M
            assert(dc_dq <= cf_max);
684
1.14M
        }
685
1.17M
        cul_level = dc_tok;
686
1.17M
        cf[0] = (coef) (dc_sign ? -dc_dq : dc_dq);
687
688
1.63M
        if (rc) ac_noqm: {
689
1.63M
            const unsigned ac_dq = dq_tbl[1];
690
7.62M
            do {
691
7.62M
                const int sign = dav1d_msac_decode_bool_equi(&ts->msac);
692
7.62M
                if (dbg)
693
0
                    printf("Post-sign[%d=%d]: r=%d\n", rc, sign, ts->msac.rng);
694
7.62M
                const unsigned rc_tok = cf[rc];
695
7.62M
                unsigned tok;
696
7.62M
                int dq;
697
698
                // residual
699
7.62M
                if (rc_tok >= (15 << 11)) {
700
127k
                    tok = read_golomb(&ts->msac) + 15;
701
127k
                    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
127k
                    tok &= 0xfffff;
707
708
                    // dequant, see 7.12.3
709
127k
                    dq = ((ac_dq * tok) & 0xffffff) >> dq_shift;
710
127k
                    dq = umin(dq, cf_max + sign);
711
7.49M
                } else {
712
                    // cannot exceed cf_max, so we can avoid the clipping
713
7.49M
                    tok = rc_tok >> 11;
714
7.49M
                    dq = ((ac_dq * tok) >> dq_shift);
715
7.49M
                    assert(dq <= cf_max);
716
7.49M
                }
717
7.62M
                cul_level += tok;
718
7.62M
                cf[rc] = (coef) (sign ? -dq : dq);
719
720
7.62M
                rc = rc_tok & 0x3ff; // next non-zero rc, zero if eob
721
7.62M
            } while (rc);
722
1.63M
        }
723
1.17M
    }
724
725
    // context
726
2.27M
    *res_ctx = umin(cul_level, 63) | dc_sign_level;
727
728
2.27M
    return eob;
729
1.89M
}
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
846k
{
737
846k
    const Dav1dFrameContext *const f = t->f;
738
846k
    Dav1dTileState *const ts = t->ts;
739
846k
    const Dav1dDSPContext *const dsp = f->dsp;
740
846k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[ytx];
741
846k
    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
846k
    if (depth < 2 && tx_split[depth] &&
746
59.3k
        tx_split[depth] & (1 << (y_off * 4 + x_off)))
747
47.0k
    {
748
47.0k
        const enum RectTxfmSize sub = t_dim->sub;
749
47.0k
        const TxfmInfo *const sub_t_dim = &dav1d_txfm_dimensions[sub];
750
47.0k
        const int txsw = sub_t_dim->w, txsh = sub_t_dim->h;
751
752
47.0k
        read_coef_tree(t, bs, b, sub, depth + 1, tx_split,
753
47.0k
                       x_off * 2 + 0, y_off * 2 + 0, dst);
754
47.0k
        t->bx += txsw;
755
47.0k
        if (txw >= txh && t->bx < f->bw)
756
35.3k
            read_coef_tree(t, bs, b, sub, depth + 1, tx_split, x_off * 2 + 1,
757
35.3k
                           y_off * 2 + 0, dst ? &dst[4 * txsw] : NULL);
758
47.0k
        t->bx -= txsw;
759
47.0k
        t->by += txsh;
760
47.0k
        if (txh >= txw && t->by < f->bh) {
761
33.3k
            if (dst)
762
12.4k
                dst += 4 * txsh * PXSTRIDE(f->cur.stride[0]);
763
33.3k
            read_coef_tree(t, bs, b, sub, depth + 1, tx_split,
764
33.3k
                           x_off * 2 + 0, y_off * 2 + 1, dst);
765
33.3k
            t->bx += txsw;
766
33.3k
            if (txw >= txh && t->bx < f->bw)
767
22.3k
                read_coef_tree(t, bs, b, sub, depth + 1, tx_split, x_off * 2 + 1,
768
22.3k
                               y_off * 2 + 1, dst ? &dst[4 * txsw] : NULL);
769
33.3k
            t->bx -= txsw;
770
33.3k
        }
771
47.0k
        t->by -= txsh;
772
799k
    } else {
773
799k
        const int bx4 = t->bx & 31, by4 = t->by & 31;
774
799k
        enum TxfmType txtp;
775
799k
        uint8_t cf_ctx;
776
799k
        int eob;
777
799k
        coef *cf;
778
779
799k
        if (t->frame_thread.pass) {
780
799k
            const int p = t->frame_thread.pass & 1;
781
799k
            assert(ts->frame_thread[p].cf);
782
799k
            cf = ts->frame_thread[p].cf;
783
799k
            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
799k
        if (t->frame_thread.pass != 2) {
788
522k
            eob = decode_coefs(t, &t->a->lcoef[bx4], &t->l.lcoef[by4],
789
522k
                               ytx, bs, b, 0, 0, cf, &txtp, &cf_ctx);
790
522k
            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
522k
            dav1d_memset_likely_pow2(&t->a->lcoef[bx4], cf_ctx, imin(txw, f->bw - t->bx));
794
522k
            dav1d_memset_likely_pow2(&t->l.lcoef[by4], cf_ctx, imin(txh, f->bh - t->by));
795
522k
#define set_ctx(rep_macro) \
796
1.88M
            for (int y = 0; y < txh; y++) { \
797
1.36M
                rep_macro(txtp_map, 0, txtp); \
798
1.36M
                txtp_map += 32; \
799
1.36M
            }
800
522k
            uint8_t *txtp_map = &t->scratch.txtp_map[by4 * 32 + bx4];
801
523k
            case_set_upto16(t_dim->lw);
802
523k
#undef set_ctx
803
523k
            if (t->frame_thread.pass == 1)
804
523k
                *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
805
523k
        } else {
806
276k
            const int cbi = *ts->frame_thread[0].cbi++;
807
276k
            eob  = cbi >> 5;
808
276k
            txtp = cbi & 0x1f;
809
276k
        }
810
799k
        if (!(t->frame_thread.pass & 1)) {
811
276k
            assert(dst);
812
276k
            if (eob >= 0) {
813
170k
                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
170k
                dsp->itx.itxfm_add[ytx][txtp](dst, f->cur.stride[0], cf, eob
816
170k
                                              HIGHBD_CALL_SUFFIX);
817
170k
                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
170k
            }
820
276k
        }
821
799k
    }
822
846k
}
823
824
void bytefn(dav1d_read_coef_blocks)(Dav1dTaskContext *const t,
825
                                    const enum BlockSize bs, const Av1Block *const b)
826
2.56M
{
827
2.56M
    const Dav1dFrameContext *const f = t->f;
828
2.56M
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
829
2.56M
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
830
2.56M
    const int bx4 = t->bx & 31, by4 = t->by & 31;
831
2.56M
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
832
2.56M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
833
2.56M
    const int bw4 = b_dim[0], bh4 = b_dim[1];
834
2.56M
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
835
2.56M
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
836
2.27M
                           (bw4 > ss_hor || t->bx & 1) &&
837
2.12M
                           (bh4 > ss_ver || t->by & 1);
838
839
2.56M
    if (b->skip) {
840
1.60M
        BlockContext *const a = t->a;
841
1.60M
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
842
1.60M
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
843
1.60M
        if (has_chroma) {
844
1.22M
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
845
1.22M
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
846
1.22M
            memset_cw(&a->ccoef[0][cbx4], 0x40);
847
1.22M
            memset_cw(&a->ccoef[1][cbx4], 0x40);
848
1.22M
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
849
1.22M
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
850
1.22M
        }
851
1.60M
        return;
852
1.60M
    }
853
854
960k
    Dav1dTileState *const ts = t->ts;
855
960k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
856
960k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
857
960k
    assert(t->frame_thread.pass == 1);
858
960k
    assert(!b->skip);
859
960k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
860
960k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->intra ? b->tx : b->max_ytx];
861
960k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
862
863
1.95M
    for (int init_y = 0; init_y < h4; init_y += 16) {
864
997k
        const int sub_h4 = imin(h4, 16 + init_y);
865
2.04M
        for (int init_x = 0; init_x < w4; init_x += 16) {
866
1.04M
            const int sub_w4 = imin(w4, init_x + 16);
867
1.04M
            int y_off = !!init_y, y, x;
868
2.28M
            for (y = init_y, t->by += init_y; y < sub_h4;
869
1.23M
                 y += t_dim->h, t->by += t_dim->h, y_off++)
870
1.23M
            {
871
1.23M
                int x_off = !!init_x;
872
3.24M
                for (x = init_x, t->bx += init_x; x < sub_w4;
873
2.00M
                     x += t_dim->w, t->bx += t_dim->w, x_off++)
874
2.00M
                {
875
2.00M
                    if (!b->intra) {
876
465k
                        read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
877
465k
                                       x_off, y_off, NULL);
878
1.53M
                    } else {
879
1.53M
                        uint8_t cf_ctx = 0x40;
880
1.53M
                        enum TxfmType txtp;
881
1.53M
                        const int eob =
882
1.53M
                            decode_coefs(t, &t->a->lcoef[bx4 + x],
883
1.53M
                                         &t->l.lcoef[by4 + y], b->tx, bs, b, 1,
884
1.53M
                                         0, ts->frame_thread[1].cf, &txtp, &cf_ctx);
885
1.53M
                        if (DEBUG_BLOCK_INFO)
886
0
                            printf("Post-y-cf-blk[tx=%d,txtp=%d,eob=%d]: r=%d\n",
887
0
                                   b->tx, txtp, eob, ts->msac.rng);
888
1.53M
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
889
1.53M
                        ts->frame_thread[1].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
890
1.53M
                        dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
891
1.53M
                        dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
892
1.53M
                    }
893
2.00M
                }
894
1.23M
                t->bx -= x;
895
1.23M
            }
896
1.04M
            t->by -= y;
897
898
1.04M
            if (!has_chroma) continue;
899
900
826k
            const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
901
826k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
902
2.47M
            for (int pl = 0; pl < 2; pl++) {
903
3.46M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
904
1.81M
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
905
1.81M
                {
906
4.23M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
907
2.42M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
908
2.42M
                    {
909
2.42M
                        uint8_t cf_ctx = 0x40;
910
2.42M
                        enum TxfmType txtp;
911
2.42M
                        if (!b->intra)
912
852k
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
913
852k
                                                        bx4 + (x << ss_hor)];
914
2.42M
                        const int eob =
915
2.42M
                            decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
916
2.42M
                                         &t->l.ccoef[pl][cby4 + y], b->uvtx, bs,
917
2.42M
                                         b, b->intra, 1 + pl, ts->frame_thread[1].cf,
918
2.42M
                                         &txtp, &cf_ctx);
919
2.42M
                        if (DEBUG_BLOCK_INFO)
920
0
                            printf("Post-uv-cf-blk[pl=%d,tx=%d,"
921
0
                                   "txtp=%d,eob=%d]: r=%d\n",
922
0
                                   pl, b->uvtx, txtp, eob, ts->msac.rng);
923
2.42M
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
924
2.42M
                        ts->frame_thread[1].cf += uv_t_dim->w * uv_t_dim->h * 16;
925
2.42M
                        int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
926
2.42M
                        int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
927
2.42M
                        dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
928
2.42M
                        dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
929
2.42M
                    }
930
1.81M
                    t->bx -= x << ss_hor;
931
1.81M
                }
932
1.64M
                t->by -= y << ss_ver;
933
1.64M
            }
934
826k
        }
935
997k
    }
936
960k
}
dav1d_read_coef_blocks_8bpc
Line
Count
Source
826
1.35M
{
827
1.35M
    const Dav1dFrameContext *const f = t->f;
828
1.35M
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
829
1.35M
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
830
1.35M
    const int bx4 = t->bx & 31, by4 = t->by & 31;
831
1.35M
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
832
1.35M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
833
1.35M
    const int bw4 = b_dim[0], bh4 = b_dim[1];
834
1.35M
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
835
1.35M
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
836
1.24M
                           (bw4 > ss_hor || t->bx & 1) &&
837
1.16M
                           (bh4 > ss_ver || t->by & 1);
838
839
1.35M
    if (b->skip) {
840
897k
        BlockContext *const a = t->a;
841
897k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
842
897k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
843
897k
        if (has_chroma) {
844
727k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
845
727k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
846
727k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
847
727k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
848
727k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
849
727k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
850
727k
        }
851
897k
        return;
852
897k
    }
853
854
457k
    Dav1dTileState *const ts = t->ts;
855
457k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
856
457k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
857
457k
    assert(t->frame_thread.pass == 1);
858
457k
    assert(!b->skip);
859
457k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
860
457k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->intra ? b->tx : b->max_ytx];
861
457k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
862
863
930k
    for (int init_y = 0; init_y < h4; init_y += 16) {
864
472k
        const int sub_h4 = imin(h4, 16 + init_y);
865
963k
        for (int init_x = 0; init_x < w4; init_x += 16) {
866
491k
            const int sub_w4 = imin(w4, init_x + 16);
867
491k
            int y_off = !!init_y, y, x;
868
1.06M
            for (y = init_y, t->by += init_y; y < sub_h4;
869
574k
                 y += t_dim->h, t->by += t_dim->h, y_off++)
870
574k
            {
871
574k
                int x_off = !!init_x;
872
1.48M
                for (x = init_x, t->bx += init_x; x < sub_w4;
873
909k
                     x += t_dim->w, t->bx += t_dim->w, x_off++)
874
909k
                {
875
909k
                    if (!b->intra) {
876
172k
                        read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
877
172k
                                       x_off, y_off, NULL);
878
736k
                    } else {
879
736k
                        uint8_t cf_ctx = 0x40;
880
736k
                        enum TxfmType txtp;
881
736k
                        const int eob =
882
736k
                            decode_coefs(t, &t->a->lcoef[bx4 + x],
883
736k
                                         &t->l.lcoef[by4 + y], b->tx, bs, b, 1,
884
736k
                                         0, ts->frame_thread[1].cf, &txtp, &cf_ctx);
885
736k
                        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
736k
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
889
736k
                        ts->frame_thread[1].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
890
736k
                        dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
891
736k
                        dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
892
736k
                    }
893
909k
                }
894
574k
                t->bx -= x;
895
574k
            }
896
491k
            t->by -= y;
897
898
491k
            if (!has_chroma) continue;
899
900
393k
            const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
901
393k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
902
1.17M
            for (int pl = 0; pl < 2; pl++) {
903
1.62M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
904
842k
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
905
842k
                {
906
1.87M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
907
1.03M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
908
1.03M
                    {
909
1.03M
                        uint8_t cf_ctx = 0x40;
910
1.03M
                        enum TxfmType txtp;
911
1.03M
                        if (!b->intra)
912
323k
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
913
323k
                                                        bx4 + (x << ss_hor)];
914
1.03M
                        const int eob =
915
1.03M
                            decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
916
1.03M
                                         &t->l.ccoef[pl][cby4 + y], b->uvtx, bs,
917
1.03M
                                         b, b->intra, 1 + pl, ts->frame_thread[1].cf,
918
1.03M
                                         &txtp, &cf_ctx);
919
1.03M
                        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.03M
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
924
1.03M
                        ts->frame_thread[1].cf += uv_t_dim->w * uv_t_dim->h * 16;
925
1.03M
                        int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
926
1.03M
                        int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
927
1.03M
                        dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
928
1.03M
                        dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
929
1.03M
                    }
930
842k
                    t->bx -= x << ss_hor;
931
842k
                }
932
784k
                t->by -= y << ss_ver;
933
784k
            }
934
393k
        }
935
472k
    }
936
457k
}
dav1d_read_coef_blocks_16bpc
Line
Count
Source
826
1.20M
{
827
1.20M
    const Dav1dFrameContext *const f = t->f;
828
1.20M
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
829
1.20M
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
830
1.20M
    const int bx4 = t->bx & 31, by4 = t->by & 31;
831
1.20M
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
832
1.20M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
833
1.20M
    const int bw4 = b_dim[0], bh4 = b_dim[1];
834
1.20M
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
835
1.20M
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
836
1.03M
                           (bw4 > ss_hor || t->bx & 1) &&
837
956k
                           (bh4 > ss_ver || t->by & 1);
838
839
1.20M
    if (b->skip) {
840
705k
        BlockContext *const a = t->a;
841
705k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
842
705k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
843
705k
        if (has_chroma) {
844
497k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
845
497k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
846
497k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
847
497k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
848
497k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
849
497k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
850
497k
        }
851
705k
        return;
852
705k
    }
853
854
503k
    Dav1dTileState *const ts = t->ts;
855
503k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
856
503k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
857
503k
    assert(t->frame_thread.pass == 1);
858
503k
    assert(!b->skip);
859
503k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
860
503k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->intra ? b->tx : b->max_ytx];
861
503k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
862
863
1.02M
    for (int init_y = 0; init_y < h4; init_y += 16) {
864
524k
        const int sub_h4 = imin(h4, 16 + init_y);
865
1.07M
        for (int init_x = 0; init_x < w4; init_x += 16) {
866
553k
            const int sub_w4 = imin(w4, init_x + 16);
867
553k
            int y_off = !!init_y, y, x;
868
1.21M
            for (y = init_y, t->by += init_y; y < sub_h4;
869
664k
                 y += t_dim->h, t->by += t_dim->h, y_off++)
870
664k
            {
871
664k
                int x_off = !!init_x;
872
1.75M
                for (x = init_x, t->bx += init_x; x < sub_w4;
873
1.09M
                     x += t_dim->w, t->bx += t_dim->w, x_off++)
874
1.09M
                {
875
1.09M
                    if (!b->intra) {
876
292k
                        read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
877
292k
                                       x_off, y_off, NULL);
878
800k
                    } else {
879
800k
                        uint8_t cf_ctx = 0x40;
880
800k
                        enum TxfmType txtp;
881
800k
                        const int eob =
882
800k
                            decode_coefs(t, &t->a->lcoef[bx4 + x],
883
800k
                                         &t->l.lcoef[by4 + y], b->tx, bs, b, 1,
884
800k
                                         0, ts->frame_thread[1].cf, &txtp, &cf_ctx);
885
800k
                        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
800k
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
889
800k
                        ts->frame_thread[1].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
890
800k
                        dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
891
800k
                        dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
892
800k
                    }
893
1.09M
                }
894
664k
                t->bx -= x;
895
664k
            }
896
553k
            t->by -= y;
897
898
553k
            if (!has_chroma) continue;
899
900
432k
            const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
901
432k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
902
1.29M
            for (int pl = 0; pl < 2; pl++) {
903
1.83M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
904
969k
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
905
969k
                {
906
2.36M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
907
1.39M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
908
1.39M
                    {
909
1.39M
                        uint8_t cf_ctx = 0x40;
910
1.39M
                        enum TxfmType txtp;
911
1.39M
                        if (!b->intra)
912
528k
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
913
528k
                                                        bx4 + (x << ss_hor)];
914
1.39M
                        const int eob =
915
1.39M
                            decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
916
1.39M
                                         &t->l.ccoef[pl][cby4 + y], b->uvtx, bs,
917
1.39M
                                         b, b->intra, 1 + pl, ts->frame_thread[1].cf,
918
1.39M
                                         &txtp, &cf_ctx);
919
1.39M
                        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.39M
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
924
1.39M
                        ts->frame_thread[1].cf += uv_t_dim->w * uv_t_dim->h * 16;
925
1.39M
                        int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
926
1.39M
                        int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
927
1.39M
                        dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
928
1.39M
                        dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
929
1.39M
                    }
930
969k
                    t->bx -= x << ss_hor;
931
969k
                }
932
862k
                t->by -= y << ss_ver;
933
862k
            }
934
432k
        }
935
524k
    }
936
503k
}
937
938
static int mc(Dav1dTaskContext *const t,
939
              pixel *const dst8, int16_t *const dst16, const ptrdiff_t dst_stride,
940
              const int bw4, const int bh4,
941
              const int bx, const int by, const int pl,
942
              const mv mv, const Dav1dThreadPicture *const refp, const int refidx,
943
              const enum Filter2d filter_2d)
944
1.12M
{
945
1.12M
    assert((dst8 != NULL) ^ (dst16 != NULL));
946
1.12M
    const Dav1dFrameContext *const f = t->f;
947
1.12M
    const int ss_ver = !!pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
948
1.12M
    const int ss_hor = !!pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
949
1.12M
    const int h_mul = 4 >> ss_hor, v_mul = 4 >> ss_ver;
950
1.12M
    const int mvx = mv.x, mvy = mv.y;
951
1.12M
    const int mx = mvx & (15 >> !ss_hor), my = mvy & (15 >> !ss_ver);
952
1.12M
    ptrdiff_t ref_stride = refp->p.stride[!!pl];
953
1.12M
    const pixel *ref;
954
955
1.12M
    if (refp->p.p.w == f->cur.p.w && refp->p.p.h == f->cur.p.h) {
956
510k
        const int dx = bx * h_mul + (mvx >> (3 + ss_hor));
957
510k
        const int dy = by * v_mul + (mvy >> (3 + ss_ver));
958
510k
        int w, h;
959
960
510k
        if (refp->p.data[0] != f->cur.data[0]) { // i.e. not for intrabc
961
392k
            w = (f->cur.p.w + ss_hor) >> ss_hor;
962
392k
            h = (f->cur.p.h + ss_ver) >> ss_ver;
963
392k
        } else {
964
117k
            w = f->bw * 4 >> ss_hor;
965
117k
            h = f->bh * 4 >> ss_ver;
966
117k
        }
967
510k
        if (dx < !!mx * 3 || dy < !!my * 3 ||
968
389k
            dx + bw4 * h_mul + !!mx * 4 > w ||
969
269k
            dy + bh4 * v_mul + !!my * 4 > h)
970
300k
        {
971
300k
            pixel *const emu_edge_buf = bitfn(t->scratch.emu_edge);
972
300k
            f->dsp->mc.emu_edge(bw4 * h_mul + !!mx * 7, bh4 * v_mul + !!my * 7,
973
300k
                                w, h, dx - !!mx * 3, dy - !!my * 3,
974
300k
                                emu_edge_buf, 192 * sizeof(pixel),
975
300k
                                refp->p.data[pl], ref_stride);
976
300k
            ref = &emu_edge_buf[192 * !!my * 3 + !!mx * 3];
977
300k
            ref_stride = 192 * sizeof(pixel);
978
300k
        } else {
979
209k
            ref = ((pixel *) refp->p.data[pl]) + PXSTRIDE(ref_stride) * dy + dx;
980
209k
        }
981
982
510k
        if (dst8 != NULL) {
983
418k
            f->dsp->mc.mc[filter_2d](dst8, dst_stride, ref, ref_stride, bw4 * h_mul,
984
418k
                                     bh4 * v_mul, mx << !ss_hor, my << !ss_ver
985
418k
                                     HIGHBD_CALL_SUFFIX);
986
418k
        } else {
987
92.1k
            f->dsp->mc.mct[filter_2d](dst16, ref, ref_stride, bw4 * h_mul,
988
92.1k
                                      bh4 * v_mul, mx << !ss_hor, my << !ss_ver
989
92.1k
                                      HIGHBD_CALL_SUFFIX);
990
92.1k
        }
991
613k
    } else {
992
613k
        assert(refp != &f->sr_cur);
993
994
613k
        const int orig_pos_y = (by * v_mul << 4) + mvy * (1 << !ss_ver);
995
613k
        const int orig_pos_x = (bx * h_mul << 4) + mvx * (1 << !ss_hor);
996
1.22M
#define scale_mv(res, val, scale) do { \
997
1.22M
            const int64_t tmp = (int64_t)(val) * scale + (scale - 0x4000) * 8; \
998
1.22M
            res = apply_sign64((int) ((llabs(tmp) + 128) >> 8), tmp) + 32;     \
999
1.22M
        } while (0)
1000
613k
        int pos_y, pos_x;
1001
613k
        scale_mv(pos_x, orig_pos_x, f->svc[refidx][0].scale);
1002
613k
        scale_mv(pos_y, orig_pos_y, f->svc[refidx][1].scale);
1003
613k
#undef scale_mv
1004
613k
        const int left = pos_x >> 10;
1005
613k
        const int top = pos_y >> 10;
1006
613k
        const int right =
1007
613k
            ((pos_x + (bw4 * h_mul - 1) * f->svc[refidx][0].step) >> 10) + 1;
1008
613k
        const int bottom =
1009
613k
            ((pos_y + (bh4 * v_mul - 1) * f->svc[refidx][1].step) >> 10) + 1;
1010
1011
613k
        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
613k
        const int w = (refp->p.p.w + ss_hor) >> ss_hor;
1018
613k
        const int h = (refp->p.p.h + ss_ver) >> ss_ver;
1019
613k
        if (left < 3 || top < 3 || right + 4 > w || bottom + 4 > h) {
1020
240k
            pixel *const emu_edge_buf = bitfn(t->scratch.emu_edge);
1021
240k
            f->dsp->mc.emu_edge(right - left + 7, bottom - top + 7,
1022
240k
                                w, h, left - 3, top - 3,
1023
240k
                                emu_edge_buf, 320 * sizeof(pixel),
1024
240k
                                refp->p.data[pl], ref_stride);
1025
240k
            ref = &emu_edge_buf[320 * 3 + 3];
1026
240k
            ref_stride = 320 * sizeof(pixel);
1027
240k
            if (DEBUG_BLOCK_INFO) printf("Emu\n");
1028
373k
        } else {
1029
373k
            ref = ((pixel *) refp->p.data[pl]) + PXSTRIDE(ref_stride) * top + left;
1030
373k
        }
1031
1032
613k
        if (dst8 != NULL) {
1033
560k
            f->dsp->mc.mc_scaled[filter_2d](dst8, dst_stride, ref, ref_stride,
1034
560k
                                            bw4 * h_mul, bh4 * v_mul,
1035
560k
                                            pos_x & 0x3ff, pos_y & 0x3ff,
1036
560k
                                            f->svc[refidx][0].step,
1037
560k
                                            f->svc[refidx][1].step
1038
560k
                                            HIGHBD_CALL_SUFFIX);
1039
560k
        } else {
1040
53.0k
            f->dsp->mc.mct_scaled[filter_2d](dst16, ref, ref_stride,
1041
53.0k
                                             bw4 * h_mul, bh4 * v_mul,
1042
53.0k
                                             pos_x & 0x3ff, pos_y & 0x3ff,
1043
53.0k
                                             f->svc[refidx][0].step,
1044
53.0k
                                             f->svc[refidx][1].step
1045
53.0k
                                             HIGHBD_CALL_SUFFIX);
1046
53.0k
        }
1047
613k
    }
1048
1049
1.12M
    return 0;
1050
1.12M
}
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
114k
{
1057
114k
    assert(!(t->bx & 1) && !(t->by & 1));
1058
114k
    const Dav1dFrameContext *const f = t->f;
1059
114k
    /*const*/ refmvs_block **r = &t->rt.r[(t->by & 31) + 5];
1060
114k
    pixel *const lap = bitfn(t->scratch.lap);
1061
114k
    const int ss_ver = !!pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1062
114k
    const int ss_hor = !!pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1063
114k
    const int h_mul = 4 >> ss_hor, v_mul = 4 >> ss_ver;
1064
114k
    int res;
1065
1066
114k
    if (t->by > t->ts->tiling.row_start &&
1067
102k
        (!pl || b_dim[0] * h_mul + b_dim[1] * v_mul >= 16))
1068
94.2k
    {
1069
198k
        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
104k
            const refmvs_block *const a_r = &r[-1][t->bx + x + 1];
1072
104k
            const uint8_t *const a_b_dim = dav1d_block_dimensions[a_r->bs];
1073
104k
            const int step4 = iclip(a_b_dim[0], 2, 16);
1074
1075
104k
            if (a_r->ref.ref[0] > 0) {
1076
103k
                const int ow4 = imin(step4, b_dim[0]);
1077
103k
                const int oh4 = imin(b_dim[1], 16) >> 1;
1078
103k
                res = mc(t, lap, NULL, ow4 * h_mul * sizeof(pixel), ow4, (oh4 * 3 + 3) >> 2,
1079
103k
                         t->bx + x, t->by, pl, a_r->mv.mv[0],
1080
103k
                         &f->refp[a_r->ref.ref[0] - 1], a_r->ref.ref[0] - 1,
1081
103k
                         dav1d_filter_2d[t->a->filter[1][bx4 + x + 1]][t->a->filter[0][bx4 + x + 1]]);
1082
103k
                if (res) return res;
1083
103k
                f->dsp->mc.blend_h(&dst[x * h_mul], dst_stride, lap,
1084
103k
                                   h_mul * ow4, v_mul * oh4);
1085
103k
                i++;
1086
103k
            }
1087
104k
            x += step4;
1088
104k
        }
1089
94.2k
    }
1090
1091
114k
    if (t->bx > t->ts->tiling.col_start)
1092
223k
        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
116k
            const refmvs_block *const l_r = &r[y + 1][t->bx - 1];
1095
116k
            const uint8_t *const l_b_dim = dav1d_block_dimensions[l_r->bs];
1096
116k
            const int step4 = iclip(l_b_dim[1], 2, 16);
1097
1098
116k
            if (l_r->ref.ref[0] > 0) {
1099
115k
                const int ow4 = imin(b_dim[0], 16) >> 1;
1100
115k
                const int oh4 = imin(step4, b_dim[1]);
1101
115k
                res = mc(t, lap, NULL, h_mul * ow4 * sizeof(pixel), ow4, oh4,
1102
115k
                         t->bx, t->by + y, pl, l_r->mv.mv[0],
1103
115k
                         &f->refp[l_r->ref.ref[0] - 1], l_r->ref.ref[0] - 1,
1104
115k
                         dav1d_filter_2d[t->l.filter[1][by4 + y + 1]][t->l.filter[0][by4 + y + 1]]);
1105
115k
                if (res) return res;
1106
115k
                f->dsp->mc.blend_v(&dst[y * v_mul * PXSTRIDE(dst_stride)],
1107
115k
                                   dst_stride, lap, h_mul * ow4, v_mul * oh4);
1108
115k
                i++;
1109
115k
            }
1110
116k
            y += step4;
1111
116k
        }
1112
114k
    return 0;
1113
114k
}
1114
1115
static int warp_affine(Dav1dTaskContext *const t,
1116
                       pixel *dst8, int16_t *dst16, const ptrdiff_t dstride,
1117
                       const uint8_t *const b_dim, const int pl,
1118
                       const Dav1dThreadPicture *const refp,
1119
                       const Dav1dWarpedMotionParams *const wmp)
1120
21.5k
{
1121
21.5k
    assert((dst8 != NULL) ^ (dst16 != NULL));
1122
21.5k
    const Dav1dFrameContext *const f = t->f;
1123
21.5k
    const Dav1dDSPContext *const dsp = f->dsp;
1124
21.5k
    const int ss_ver = !!pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1125
21.5k
    const int ss_hor = !!pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1126
21.5k
    const int h_mul = 4 >> ss_hor, v_mul = 4 >> ss_ver;
1127
21.5k
    assert(!((b_dim[0] * h_mul) & 7) && !((b_dim[1] * v_mul) & 7));
1128
21.5k
    const int32_t *const mat = wmp->matrix;
1129
21.5k
    const int width = (refp->p.p.w + ss_hor) >> ss_hor;
1130
21.5k
    const int height = (refp->p.p.h + ss_ver) >> ss_ver;
1131
1132
60.8k
    for (int y = 0; y < b_dim[1] * v_mul; y += 8) {
1133
39.2k
        const int src_y = t->by * 4 + ((y + 4) << ss_ver);
1134
39.2k
        const int64_t mat3_y = (int64_t) mat[3] * src_y + mat[0];
1135
39.2k
        const int64_t mat5_y = (int64_t) mat[5] * src_y + mat[1];
1136
169k
        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
130k
            const int src_x = t->bx * 4 + ((x + 4) << ss_hor);
1140
130k
            const int64_t mvx = ((int64_t) mat[2] * src_x + mat3_y) >> ss_hor;
1141
130k
            const int64_t mvy = ((int64_t) mat[4] * src_x + mat5_y) >> ss_ver;
1142
1143
130k
            const int dx = (int) (mvx >> 16) - 4;
1144
130k
            const int mx = (((int) mvx & 0xffff) - wmp->u.p.alpha * 4 -
1145
130k
                                                   wmp->u.p.beta  * 7) & ~0x3f;
1146
130k
            const int dy = (int) (mvy >> 16) - 4;
1147
130k
            const int my = (((int) mvy & 0xffff) - wmp->u.p.gamma * 4 -
1148
130k
                                                   wmp->u.p.delta * 4) & ~0x3f;
1149
1150
130k
            const pixel *ref_ptr;
1151
130k
            ptrdiff_t ref_stride = refp->p.stride[!!pl];
1152
1153
130k
            if (dx < 3 || dx + 8 + 4 > width || dy < 3 || dy + 8 + 4 > height) {
1154
89.8k
                pixel *const emu_edge_buf = bitfn(t->scratch.emu_edge);
1155
89.8k
                f->dsp->mc.emu_edge(15, 15, width, height, dx - 3, dy - 3,
1156
89.8k
                                    emu_edge_buf, 32 * sizeof(pixel),
1157
89.8k
                                    refp->p.data[pl], ref_stride);
1158
89.8k
                ref_ptr = &emu_edge_buf[32 * 3 + 3];
1159
89.8k
                ref_stride = 32 * sizeof(pixel);
1160
89.8k
            } else {
1161
40.2k
                ref_ptr = ((pixel *) refp->p.data[pl]) + PXSTRIDE(ref_stride) * dy + dx;
1162
40.2k
            }
1163
130k
            if (dst16 != NULL)
1164
27.1k
                dsp->mc.warp8x8t(&dst16[x], dstride, ref_ptr, ref_stride,
1165
27.1k
                                 wmp->u.abcd, mx, my HIGHBD_CALL_SUFFIX);
1166
103k
            else
1167
103k
                dsp->mc.warp8x8(&dst8[x], dstride, ref_ptr, ref_stride,
1168
103k
                                wmp->u.abcd, mx, my HIGHBD_CALL_SUFFIX);
1169
130k
        }
1170
39.2k
        if (dst8) dst8  += 8 * PXSTRIDE(dstride);
1171
11.6k
        else      dst16 += 8 * dstride;
1172
39.2k
    }
1173
21.5k
    return 0;
1174
21.5k
}
1175
1176
void bytefn(dav1d_recon_b_intra)(Dav1dTaskContext *const t, const enum BlockSize bs,
1177
                                 const enum EdgeFlags intra_edge_flags,
1178
                                 const Av1Block *const b)
1179
1.19M
{
1180
1.19M
    Dav1dTileState *const ts = t->ts;
1181
1.19M
    const Dav1dFrameContext *const f = t->f;
1182
1.19M
    const Dav1dDSPContext *const dsp = f->dsp;
1183
1.19M
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1184
1.19M
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1185
1.19M
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1186
1.19M
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1187
1.19M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1188
1.19M
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1189
1.19M
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1190
1.19M
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1191
1.19M
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1192
1.08M
                           (bw4 > ss_hor || t->bx & 1) &&
1193
1.00M
                           (bh4 > ss_ver || t->by & 1);
1194
1.19M
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->tx];
1195
1.19M
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
1196
1197
    // coefficient coding
1198
1.19M
    pixel *const edge = bitfn(t->scratch.edge) + 128;
1199
1.19M
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
1200
1201
1.19M
    const int intra_edge_filter_flag = f->seq_hdr->intra_edge_filter << 10;
1202
1203
2.41M
    for (int init_y = 0; init_y < h4; init_y += 16) {
1204
1.22M
        const int sub_h4 = imin(h4, 16 + init_y);
1205
1.22M
        const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
1206
2.49M
        for (int init_x = 0; init_x < w4; init_x += 16) {
1207
1.27M
            if (b->pal_sz[0]) {
1208
7.62k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1209
7.62k
                             4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1210
7.62k
                const uint8_t *pal_idx;
1211
7.62k
                if (t->frame_thread.pass) {
1212
7.62k
                    const int p = t->frame_thread.pass & 1;
1213
7.62k
                    assert(ts->frame_thread[p].pal_idx);
1214
7.62k
                    pal_idx = ts->frame_thread[p].pal_idx;
1215
7.62k
                    ts->frame_thread[p].pal_idx += bw4 * bh4 * 8;
1216
7.62k
                } else {
1217
0
                    pal_idx = t->scratch.pal_idx_y;
1218
0
                }
1219
7.62k
                const pixel *const pal = t->frame_thread.pass ?
1220
7.62k
                    f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1221
7.62k
                                        ((t->bx >> 1) + (t->by & 1))][0] :
1222
7.62k
                    bytefn(t->scratch.pal)[0];
1223
7.62k
                f->dsp->ipred.pal_pred(dst, f->cur.stride[0], pal,
1224
7.62k
                                       pal_idx, bw4 * 4, bh4 * 4);
1225
7.62k
                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1226
0
                    hex_dump(dst, PXSTRIDE(f->cur.stride[0]),
1227
0
                             bw4 * 4, bh4 * 4, "y-pal-pred");
1228
7.62k
            }
1229
1230
1.27M
            const int intra_flags = (sm_flag(t->a, bx4) |
1231
1.27M
                                     sm_flag(&t->l, by4) |
1232
1.27M
                                     intra_edge_filter_flag);
1233
1.27M
            const int sb_has_tr = init_x + 16 < w4 ? 1 : init_y ? 0 :
1234
1.22M
                              intra_edge_flags & EDGE_I444_TOP_HAS_RIGHT;
1235
1.27M
            const int sb_has_bl = init_x ? 0 : init_y + 16 < h4 ? 1 :
1236
1.22M
                              intra_edge_flags & EDGE_I444_LEFT_HAS_BOTTOM;
1237
1.27M
            int y, x;
1238
1.27M
            const int sub_w4 = imin(w4, init_x + 16);
1239
2.87M
            for (y = init_y, t->by += init_y; y < sub_h4;
1240
1.60M
                 y += t_dim->h, t->by += t_dim->h)
1241
1.60M
            {
1242
1.60M
                pixel *dst = ((pixel *) f->cur.data[0]) +
1243
1.60M
                               4 * (t->by * PXSTRIDE(f->cur.stride[0]) +
1244
1.60M
                                    t->bx + init_x);
1245
4.37M
                for (x = init_x, t->bx += init_x; x < sub_w4;
1246
2.76M
                     x += t_dim->w, t->bx += t_dim->w)
1247
2.76M
                {
1248
2.76M
                    if (b->pal_sz[0]) goto skip_y_pred;
1249
1250
2.75M
                    int angle = b->y_angle;
1251
2.75M
                    const enum EdgeFlags edge_flags =
1252
2.75M
                        (((y > init_y || !sb_has_tr) && (x + t_dim->w >= sub_w4)) ?
1253
2.00M
                             0 : EDGE_I444_TOP_HAS_RIGHT) |
1254
2.75M
                        ((x > init_x || (!sb_has_bl && y + t_dim->h >= sub_h4)) ?
1255
1.89M
                             0 : EDGE_I444_LEFT_HAS_BOTTOM);
1256
2.75M
                    const pixel *top_sb_edge = NULL;
1257
2.75M
                    if (!(t->by & (f->sb_step - 1))) {
1258
491k
                        top_sb_edge = f->ipred_edge[0];
1259
491k
                        const int sby = t->by >> f->sb_shift;
1260
491k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1261
491k
                    }
1262
2.75M
                    const enum IntraPredMode m =
1263
2.75M
                        bytefn(dav1d_prepare_intra_edges)(t->bx,
1264
2.75M
                                                          t->bx > ts->tiling.col_start,
1265
2.75M
                                                          t->by,
1266
2.75M
                                                          t->by > ts->tiling.row_start,
1267
2.75M
                                                          ts->tiling.col_end,
1268
2.75M
                                                          ts->tiling.row_end,
1269
2.75M
                                                          edge_flags, dst,
1270
2.75M
                                                          f->cur.stride[0], top_sb_edge,
1271
2.75M
                                                          b->y_mode, &angle,
1272
2.75M
                                                          t_dim->w, t_dim->h,
1273
2.75M
                                                          f->seq_hdr->intra_edge_filter,
1274
2.75M
                                                          edge HIGHBD_CALL_SUFFIX);
1275
2.75M
                    dsp->ipred.intra_pred[m](dst, f->cur.stride[0], edge,
1276
2.75M
                                             t_dim->w * 4, t_dim->h * 4,
1277
2.75M
                                             angle | intra_flags,
1278
2.75M
                                             4 * f->bw - 4 * t->bx,
1279
2.75M
                                             4 * f->bh - 4 * t->by
1280
2.75M
                                             HIGHBD_CALL_SUFFIX);
1281
1282
2.75M
                    if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1283
0
                        hex_dump(edge - t_dim->h * 4, t_dim->h * 4,
1284
0
                                 t_dim->h * 4, 2, "l");
1285
0
                        hex_dump(edge, 0, 1, 1, "tl");
1286
0
                        hex_dump(edge + 1, t_dim->w * 4,
1287
0
                                 t_dim->w * 4, 2, "t");
1288
0
                        hex_dump(dst, f->cur.stride[0],
1289
0
                                 t_dim->w * 4, t_dim->h * 4, "y-intra-pred");
1290
0
                    }
1291
1292
2.76M
                skip_y_pred: {}
1293
2.76M
                    if (!b->skip) {
1294
797k
                        coef *cf;
1295
797k
                        int eob;
1296
797k
                        enum TxfmType txtp;
1297
797k
                        if (t->frame_thread.pass) {
1298
797k
                            const int p = t->frame_thread.pass & 1;
1299
797k
                            const int cbi = *ts->frame_thread[p].cbi++;
1300
797k
                            cf = ts->frame_thread[p].cf;
1301
797k
                            ts->frame_thread[p].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
1302
797k
                            eob  = cbi >> 5;
1303
797k
                            txtp = cbi & 0x1f;
1304
797k
                        } 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
797k
                        if (eob >= 0) {
1317
557k
                            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
557k
                            dsp->itx.itxfm_add[b->tx]
1321
557k
                                              [txtp](dst,
1322
557k
                                                     f->cur.stride[0],
1323
557k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1324
557k
                            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
557k
                        }
1328
1.96M
                    } else if (!t->frame_thread.pass) {
1329
0
                        dav1d_memset_pow2[t_dim->lw](&t->a->lcoef[bx4 + x], 0x40);
1330
0
                        dav1d_memset_pow2[t_dim->lh](&t->l.lcoef[by4 + y], 0x40);
1331
0
                    }
1332
2.76M
                    dst += 4 * t_dim->w;
1333
2.76M
                }
1334
1.60M
                t->bx -= x;
1335
1.60M
            }
1336
1.27M
            t->by -= y;
1337
1338
1.27M
            if (!has_chroma) continue;
1339
1340
992k
            const ptrdiff_t stride = f->cur.stride[1];
1341
1342
992k
            if (b->uv_mode == CFL_PRED) {
1343
181k
                assert(!init_x && !init_y);
1344
1345
181k
                int16_t *const ac = t->scratch.ac;
1346
181k
                pixel *y_src = ((pixel *) f->cur.data[0]) + 4 * (t->bx & ~ss_hor) +
1347
181k
                                 4 * (t->by & ~ss_ver) * PXSTRIDE(f->cur.stride[0]);
1348
181k
                const ptrdiff_t uv_off = 4 * ((t->bx >> ss_hor) +
1349
181k
                                              (t->by >> ss_ver) * PXSTRIDE(stride));
1350
181k
                pixel *const uv_dst[2] = { ((pixel *) f->cur.data[1]) + uv_off,
1351
181k
                                           ((pixel *) f->cur.data[2]) + uv_off };
1352
1353
181k
                const int furthest_r =
1354
181k
                    ((cw4 << ss_hor) + t_dim->w - 1) & ~(t_dim->w - 1);
1355
181k
                const int furthest_b =
1356
181k
                    ((ch4 << ss_ver) + t_dim->h - 1) & ~(t_dim->h - 1);
1357
181k
                dsp->ipred.cfl_ac[f->cur.p.layout - 1](ac, y_src, f->cur.stride[0],
1358
181k
                                                         cbw4 - (furthest_r >> ss_hor),
1359
181k
                                                         cbh4 - (furthest_b >> ss_ver),
1360
181k
                                                         cbw4 * 4, cbh4 * 4);
1361
545k
                for (int pl = 0; pl < 2; pl++) {
1362
363k
                    if (!b->cfl_alpha[pl]) continue;
1363
290k
                    int angle = 0;
1364
290k
                    const pixel *top_sb_edge = NULL;
1365
290k
                    if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1366
67.5k
                        top_sb_edge = f->ipred_edge[pl + 1];
1367
67.5k
                        const int sby = t->by >> f->sb_shift;
1368
67.5k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1369
67.5k
                    }
1370
290k
                    const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1371
290k
                    const int xstart = ts->tiling.col_start >> ss_hor;
1372
290k
                    const int ystart = ts->tiling.row_start >> ss_ver;
1373
290k
                    const enum IntraPredMode m =
1374
290k
                        bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1375
290k
                                                          ypos, ypos > ystart,
1376
290k
                                                          ts->tiling.col_end >> ss_hor,
1377
290k
                                                          ts->tiling.row_end >> ss_ver,
1378
290k
                                                          0, uv_dst[pl], stride,
1379
290k
                                                          top_sb_edge, DC_PRED, &angle,
1380
290k
                                                          uv_t_dim->w, uv_t_dim->h, 0,
1381
290k
                                                          edge HIGHBD_CALL_SUFFIX);
1382
290k
                    dsp->ipred.cfl_pred[m](uv_dst[pl], stride, edge,
1383
290k
                                           uv_t_dim->w * 4,
1384
290k
                                           uv_t_dim->h * 4,
1385
290k
                                           ac, b->cfl_alpha[pl]
1386
290k
                                           HIGHBD_CALL_SUFFIX);
1387
290k
                }
1388
181k
                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
810k
            } else if (b->pal_sz[1]) {
1394
3.44k
                const ptrdiff_t uv_dstoff = 4 * ((t->bx >> ss_hor) +
1395
3.44k
                                              (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1396
3.44k
                const pixel (*pal)[8];
1397
3.44k
                const uint8_t *pal_idx;
1398
3.44k
                if (t->frame_thread.pass) {
1399
3.44k
                    const int p = t->frame_thread.pass & 1;
1400
3.44k
                    assert(ts->frame_thread[p].pal_idx);
1401
3.44k
                    pal = f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1402
3.44k
                                              ((t->bx >> 1) + (t->by & 1))];
1403
3.44k
                    pal_idx = ts->frame_thread[p].pal_idx;
1404
3.44k
                    ts->frame_thread[p].pal_idx += cbw4 * cbh4 * 8;
1405
3.44k
                } else {
1406
0
                    pal = bytefn(t->scratch.pal);
1407
0
                    pal_idx = t->scratch.pal_idx_uv;
1408
0
                }
1409
1410
3.44k
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[1]) + uv_dstoff,
1411
3.44k
                                       f->cur.stride[1], pal[1],
1412
3.44k
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1413
3.44k
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[2]) + uv_dstoff,
1414
3.44k
                                       f->cur.stride[1], pal[2],
1415
3.44k
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1416
3.44k
                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
3.44k
            }
1425
1426
992k
            const int sm_uv_fl = sm_uv_flag(t->a, cbx4) |
1427
992k
                                 sm_uv_flag(&t->l, cby4);
1428
992k
            const int uv_sb_has_tr =
1429
992k
                ((init_x + 16) >> ss_hor) < cw4 ? 1 : init_y ? 0 :
1430
948k
                intra_edge_flags & (EDGE_I420_TOP_HAS_RIGHT >> (f->cur.p.layout - 1));
1431
992k
            const int uv_sb_has_bl =
1432
992k
                init_x ? 0 : ((init_y + 16) >> ss_ver) < ch4 ? 1 :
1433
948k
                intra_edge_flags & (EDGE_I420_LEFT_HAS_BOTTOM >> (f->cur.p.layout - 1));
1434
992k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
1435
2.97M
            for (int pl = 0; pl < 2; pl++) {
1436
4.07M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
1437
2.09M
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
1438
2.09M
                {
1439
2.09M
                    pixel *dst = ((pixel *) f->cur.data[1 + pl]) +
1440
2.09M
                                   4 * ((t->by >> ss_ver) * PXSTRIDE(stride) +
1441
2.09M
                                        ((t->bx + init_x) >> ss_hor));
1442
4.58M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
1443
2.48M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
1444
2.49M
                    {
1445
2.49M
                        if ((b->uv_mode == CFL_PRED && b->cfl_alpha[pl]) ||
1446
2.20M
                            b->pal_sz[1])
1447
297k
                        {
1448
297k
                            goto skip_uv_pred;
1449
297k
                        }
1450
1451
2.19M
                        int angle = b->uv_angle;
1452
                        // this probably looks weird because we're using
1453
                        // luma flags in a chroma loop, but that's because
1454
                        // prepare_intra_edges() expects luma flags as input
1455
2.19M
                        const enum EdgeFlags edge_flags =
1456
2.19M
                            (((y > (init_y >> ss_ver) || !uv_sb_has_tr) &&
1457
961k
                              (x + uv_t_dim->w >= sub_cw4)) ?
1458
1.57M
                                 0 : EDGE_I444_TOP_HAS_RIGHT) |
1459
2.19M
                            ((x > (init_x >> ss_hor) ||
1460
1.79M
                              (!uv_sb_has_bl && y + uv_t_dim->h >= sub_ch4)) ?
1461
1.41M
                                 0 : EDGE_I444_LEFT_HAS_BOTTOM);
1462
2.19M
                        const pixel *top_sb_edge = NULL;
1463
2.19M
                        if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1464
628k
                            top_sb_edge = f->ipred_edge[1 + pl];
1465
628k
                            const int sby = t->by >> f->sb_shift;
1466
628k
                            top_sb_edge += f->sb128w * 128 * (sby - 1);
1467
628k
                        }
1468
2.19M
                        const enum IntraPredMode uv_mode =
1469
2.19M
                             b->uv_mode == CFL_PRED ? DC_PRED : b->uv_mode;
1470
2.19M
                        const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1471
2.19M
                        const int xstart = ts->tiling.col_start >> ss_hor;
1472
2.19M
                        const int ystart = ts->tiling.row_start >> ss_ver;
1473
2.19M
                        const enum IntraPredMode m =
1474
2.19M
                            bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1475
2.19M
                                                              ypos, ypos > ystart,
1476
2.19M
                                                              ts->tiling.col_end >> ss_hor,
1477
2.19M
                                                              ts->tiling.row_end >> ss_ver,
1478
2.19M
                                                              edge_flags, dst, stride,
1479
2.19M
                                                              top_sb_edge, uv_mode,
1480
2.19M
                                                              &angle, uv_t_dim->w,
1481
2.19M
                                                              uv_t_dim->h,
1482
2.19M
                                                              f->seq_hdr->intra_edge_filter,
1483
2.19M
                                                              edge HIGHBD_CALL_SUFFIX);
1484
2.19M
                        angle |= intra_edge_filter_flag;
1485
2.19M
                        dsp->ipred.intra_pred[m](dst, stride, edge,
1486
2.19M
                                                 uv_t_dim->w * 4,
1487
2.19M
                                                 uv_t_dim->h * 4,
1488
2.19M
                                                 angle | sm_uv_fl,
1489
2.19M
                                                 (4 * f->bw + ss_hor -
1490
2.19M
                                                  4 * (t->bx & ~ss_hor)) >> ss_hor,
1491
2.19M
                                                 (4 * f->bh + ss_ver -
1492
2.19M
                                                  4 * (t->by & ~ss_ver)) >> ss_ver
1493
2.19M
                                                 HIGHBD_CALL_SUFFIX);
1494
2.19M
                        if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1495
0
                            hex_dump(edge - uv_t_dim->h * 4, uv_t_dim->h * 4,
1496
0
                                     uv_t_dim->h * 4, 2, "l");
1497
0
                            hex_dump(edge, 0, 1, 1, "tl");
1498
0
                            hex_dump(edge + 1, uv_t_dim->w * 4,
1499
0
                                     uv_t_dim->w * 4, 2, "t");
1500
0
                            hex_dump(dst, stride, uv_t_dim->w * 4,
1501
0
                                     uv_t_dim->h * 4, pl ? "v-intra-pred" : "u-intra-pred");
1502
0
                        }
1503
1504
2.48M
                    skip_uv_pred: {}
1505
2.48M
                        if (!b->skip) {
1506
830k
                            enum TxfmType txtp;
1507
830k
                            int eob;
1508
830k
                            coef *cf;
1509
830k
                            if (t->frame_thread.pass) {
1510
830k
                                const int p = t->frame_thread.pass & 1;
1511
830k
                                const int cbi = *ts->frame_thread[p].cbi++;
1512
830k
                                cf = ts->frame_thread[p].cf;
1513
830k
                                ts->frame_thread[p].cf += uv_t_dim->w * uv_t_dim->h * 16;
1514
830k
                                eob  = cbi >> 5;
1515
830k
                                txtp = cbi & 0x1f;
1516
830k
                            } else {
1517
1
                                uint8_t cf_ctx;
1518
1
                                cf = bitfn(t->cf);
1519
1
                                eob = decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
1520
1
                                                   &t->l.ccoef[pl][cby4 + y],
1521
1
                                                   b->uvtx, bs, b, 1, 1 + pl, cf,
1522
1
                                                   &txtp, &cf_ctx);
1523
1
                                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
1
                                int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
1528
1
                                int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
1529
1
                                dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
1530
1
                                dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
1531
1
                            }
1532
830k
                            if (eob >= 0) {
1533
283k
                                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
283k
                                dsp->itx.itxfm_add[b->uvtx]
1537
283k
                                                  [txtp](dst, stride,
1538
283k
                                                         cf, eob HIGHBD_CALL_SUFFIX);
1539
283k
                                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
283k
                            }
1543
1.65M
                        } else if (!t->frame_thread.pass) {
1544
0
                            dav1d_memset_pow2[uv_t_dim->lw](&t->a->ccoef[pl][cbx4 + x], 0x40);
1545
0
                            dav1d_memset_pow2[uv_t_dim->lh](&t->l.ccoef[pl][cby4 + y], 0x40);
1546
0
                        }
1547
2.48M
                        dst += uv_t_dim->w * 4;
1548
2.48M
                    }
1549
2.09M
                    t->bx -= x << ss_hor;
1550
2.09M
                }
1551
1.98M
                t->by -= y << ss_ver;
1552
1.98M
            }
1553
992k
        }
1554
1.22M
    }
1555
1.19M
}
dav1d_recon_b_intra_8bpc
Line
Count
Source
1179
626k
{
1180
626k
    Dav1dTileState *const ts = t->ts;
1181
626k
    const Dav1dFrameContext *const f = t->f;
1182
626k
    const Dav1dDSPContext *const dsp = f->dsp;
1183
626k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1184
626k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1185
626k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1186
626k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1187
626k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1188
626k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1189
626k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1190
626k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1191
626k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1192
587k
                           (bw4 > ss_hor || t->bx & 1) &&
1193
543k
                           (bh4 > ss_ver || t->by & 1);
1194
626k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->tx];
1195
626k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
1196
1197
    // coefficient coding
1198
626k
    pixel *const edge = bitfn(t->scratch.edge) + 128;
1199
626k
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
1200
1201
626k
    const int intra_edge_filter_flag = f->seq_hdr->intra_edge_filter << 10;
1202
1203
1.27M
    for (int init_y = 0; init_y < h4; init_y += 16) {
1204
638k
        const int sub_h4 = imin(h4, 16 + init_y);
1205
638k
        const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
1206
1.30M
        for (int init_x = 0; init_x < w4; init_x += 16) {
1207
657k
            if (b->pal_sz[0]) {
1208
4.08k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1209
4.08k
                             4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1210
4.08k
                const uint8_t *pal_idx;
1211
4.08k
                if (t->frame_thread.pass) {
1212
4.08k
                    const int p = t->frame_thread.pass & 1;
1213
4.08k
                    assert(ts->frame_thread[p].pal_idx);
1214
4.08k
                    pal_idx = ts->frame_thread[p].pal_idx;
1215
4.08k
                    ts->frame_thread[p].pal_idx += bw4 * bh4 * 8;
1216
4.08k
                } else {
1217
0
                    pal_idx = t->scratch.pal_idx_y;
1218
0
                }
1219
4.08k
                const pixel *const pal = t->frame_thread.pass ?
1220
4.08k
                    f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1221
4.08k
                                        ((t->bx >> 1) + (t->by & 1))][0] :
1222
4.08k
                    bytefn(t->scratch.pal)[0];
1223
4.08k
                f->dsp->ipred.pal_pred(dst, f->cur.stride[0], pal,
1224
4.08k
                                       pal_idx, bw4 * 4, bh4 * 4);
1225
4.08k
                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1226
0
                    hex_dump(dst, PXSTRIDE(f->cur.stride[0]),
1227
0
                             bw4 * 4, bh4 * 4, "y-pal-pred");
1228
4.08k
            }
1229
1230
657k
            const int intra_flags = (sm_flag(t->a, bx4) |
1231
657k
                                     sm_flag(&t->l, by4) |
1232
657k
                                     intra_edge_filter_flag);
1233
657k
            const int sb_has_tr = init_x + 16 < w4 ? 1 : init_y ? 0 :
1234
638k
                              intra_edge_flags & EDGE_I444_TOP_HAS_RIGHT;
1235
657k
            const int sb_has_bl = init_x ? 0 : init_y + 16 < h4 ? 1 :
1236
638k
                              intra_edge_flags & EDGE_I444_LEFT_HAS_BOTTOM;
1237
657k
            int y, x;
1238
657k
            const int sub_w4 = imin(w4, init_x + 16);
1239
1.48M
            for (y = init_y, t->by += init_y; y < sub_h4;
1240
829k
                 y += t_dim->h, t->by += t_dim->h)
1241
824k
            {
1242
824k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1243
824k
                               4 * (t->by * PXSTRIDE(f->cur.stride[0]) +
1244
824k
                                    t->bx + init_x);
1245
2.22M
                for (x = init_x, t->bx += init_x; x < sub_w4;
1246
1.39M
                     x += t_dim->w, t->bx += t_dim->w)
1247
1.39M
                {
1248
1.39M
                    if (b->pal_sz[0]) goto skip_y_pred;
1249
1250
1.38M
                    int angle = b->y_angle;
1251
1.38M
                    const enum EdgeFlags edge_flags =
1252
1.38M
                        (((y > init_y || !sb_has_tr) && (x + t_dim->w >= sub_w4)) ?
1253
1.01M
                             0 : EDGE_I444_TOP_HAS_RIGHT) |
1254
1.38M
                        ((x > init_x || (!sb_has_bl && y + t_dim->h >= sub_h4)) ?
1255
948k
                             0 : EDGE_I444_LEFT_HAS_BOTTOM);
1256
1.38M
                    const pixel *top_sb_edge = NULL;
1257
1.38M
                    if (!(t->by & (f->sb_step - 1))) {
1258
268k
                        top_sb_edge = f->ipred_edge[0];
1259
268k
                        const int sby = t->by >> f->sb_shift;
1260
268k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1261
268k
                    }
1262
1.38M
                    const enum IntraPredMode m =
1263
1.38M
                        bytefn(dav1d_prepare_intra_edges)(t->bx,
1264
1.38M
                                                          t->bx > ts->tiling.col_start,
1265
1.38M
                                                          t->by,
1266
1.38M
                                                          t->by > ts->tiling.row_start,
1267
1.38M
                                                          ts->tiling.col_end,
1268
1.38M
                                                          ts->tiling.row_end,
1269
1.38M
                                                          edge_flags, dst,
1270
1.38M
                                                          f->cur.stride[0], top_sb_edge,
1271
1.38M
                                                          b->y_mode, &angle,
1272
1.38M
                                                          t_dim->w, t_dim->h,
1273
1.38M
                                                          f->seq_hdr->intra_edge_filter,
1274
1.38M
                                                          edge HIGHBD_CALL_SUFFIX);
1275
1.38M
                    dsp->ipred.intra_pred[m](dst, f->cur.stride[0], edge,
1276
1.38M
                                             t_dim->w * 4, t_dim->h * 4,
1277
1.38M
                                             angle | intra_flags,
1278
1.38M
                                             4 * f->bw - 4 * t->bx,
1279
1.38M
                                             4 * f->bh - 4 * t->by
1280
1.38M
                                             HIGHBD_CALL_SUFFIX);
1281
1282
1.38M
                    if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1283
0
                        hex_dump(edge - t_dim->h * 4, t_dim->h * 4,
1284
0
                                 t_dim->h * 4, 2, "l");
1285
0
                        hex_dump(edge, 0, 1, 1, "tl");
1286
0
                        hex_dump(edge + 1, t_dim->w * 4,
1287
0
                                 t_dim->w * 4, 2, "t");
1288
0
                        hex_dump(dst, f->cur.stride[0],
1289
0
                                 t_dim->w * 4, t_dim->h * 4, "y-intra-pred");
1290
0
                    }
1291
1292
1.39M
                skip_y_pred: {}
1293
1.39M
                    if (!b->skip) {
1294
371k
                        coef *cf;
1295
371k
                        int eob;
1296
371k
                        enum TxfmType txtp;
1297
371k
                        if (t->frame_thread.pass) {
1298
371k
                            const int p = t->frame_thread.pass & 1;
1299
371k
                            const int cbi = *ts->frame_thread[p].cbi++;
1300
371k
                            cf = ts->frame_thread[p].cf;
1301
371k
                            ts->frame_thread[p].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
1302
371k
                            eob  = cbi >> 5;
1303
371k
                            txtp = cbi & 0x1f;
1304
371k
                        } 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
371k
                        if (eob >= 0) {
1317
255k
                            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
255k
                            dsp->itx.itxfm_add[b->tx]
1321
255k
                                              [txtp](dst,
1322
255k
                                                     f->cur.stride[0],
1323
255k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1324
255k
                            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
255k
                        }
1328
1.02M
                    } else if (!t->frame_thread.pass) {
1329
0
                        dav1d_memset_pow2[t_dim->lw](&t->a->lcoef[bx4 + x], 0x40);
1330
0
                        dav1d_memset_pow2[t_dim->lh](&t->l.lcoef[by4 + y], 0x40);
1331
0
                    }
1332
1.39M
                    dst += 4 * t_dim->w;
1333
1.39M
                }
1334
829k
                t->bx -= x;
1335
829k
            }
1336
662k
            t->by -= y;
1337
1338
662k
            if (!has_chroma) continue;
1339
1340
530k
            const ptrdiff_t stride = f->cur.stride[1];
1341
1342
530k
            if (b->uv_mode == CFL_PRED) {
1343
98.1k
                assert(!init_x && !init_y);
1344
1345
98.1k
                int16_t *const ac = t->scratch.ac;
1346
98.1k
                pixel *y_src = ((pixel *) f->cur.data[0]) + 4 * (t->bx & ~ss_hor) +
1347
98.1k
                                 4 * (t->by & ~ss_ver) * PXSTRIDE(f->cur.stride[0]);
1348
98.1k
                const ptrdiff_t uv_off = 4 * ((t->bx >> ss_hor) +
1349
98.1k
                                              (t->by >> ss_ver) * PXSTRIDE(stride));
1350
98.1k
                pixel *const uv_dst[2] = { ((pixel *) f->cur.data[1]) + uv_off,
1351
98.1k
                                           ((pixel *) f->cur.data[2]) + uv_off };
1352
1353
98.1k
                const int furthest_r =
1354
98.1k
                    ((cw4 << ss_hor) + t_dim->w - 1) & ~(t_dim->w - 1);
1355
98.1k
                const int furthest_b =
1356
98.1k
                    ((ch4 << ss_ver) + t_dim->h - 1) & ~(t_dim->h - 1);
1357
98.1k
                dsp->ipred.cfl_ac[f->cur.p.layout - 1](ac, y_src, f->cur.stride[0],
1358
98.1k
                                                         cbw4 - (furthest_r >> ss_hor),
1359
98.1k
                                                         cbh4 - (furthest_b >> ss_ver),
1360
98.1k
                                                         cbw4 * 4, cbh4 * 4);
1361
294k
                for (int pl = 0; pl < 2; pl++) {
1362
196k
                    if (!b->cfl_alpha[pl]) continue;
1363
157k
                    int angle = 0;
1364
157k
                    const pixel *top_sb_edge = NULL;
1365
157k
                    if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1366
37.5k
                        top_sb_edge = f->ipred_edge[pl + 1];
1367
37.5k
                        const int sby = t->by >> f->sb_shift;
1368
37.5k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1369
37.5k
                    }
1370
157k
                    const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1371
157k
                    const int xstart = ts->tiling.col_start >> ss_hor;
1372
157k
                    const int ystart = ts->tiling.row_start >> ss_ver;
1373
157k
                    const enum IntraPredMode m =
1374
157k
                        bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1375
157k
                                                          ypos, ypos > ystart,
1376
157k
                                                          ts->tiling.col_end >> ss_hor,
1377
157k
                                                          ts->tiling.row_end >> ss_ver,
1378
157k
                                                          0, uv_dst[pl], stride,
1379
157k
                                                          top_sb_edge, DC_PRED, &angle,
1380
157k
                                                          uv_t_dim->w, uv_t_dim->h, 0,
1381
157k
                                                          edge HIGHBD_CALL_SUFFIX);
1382
157k
                    dsp->ipred.cfl_pred[m](uv_dst[pl], stride, edge,
1383
157k
                                           uv_t_dim->w * 4,
1384
157k
                                           uv_t_dim->h * 4,
1385
157k
                                           ac, b->cfl_alpha[pl]
1386
157k
                                           HIGHBD_CALL_SUFFIX);
1387
157k
                }
1388
98.1k
                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1389
0
                    ac_dump(ac, 4*cbw4, 4*cbh4, "ac");
1390
0
                    hex_dump(uv_dst[0], stride, cbw4 * 4, cbh4 * 4, "u-cfl-pred");
1391
0
                    hex_dump(uv_dst[1], stride, cbw4 * 4, cbh4 * 4, "v-cfl-pred");
1392
0
                }
1393
432k
            } else if (b->pal_sz[1]) {
1394
1.80k
                const ptrdiff_t uv_dstoff = 4 * ((t->bx >> ss_hor) +
1395
1.80k
                                              (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1396
1.80k
                const pixel (*pal)[8];
1397
1.80k
                const uint8_t *pal_idx;
1398
1.80k
                if (t->frame_thread.pass) {
1399
1.80k
                    const int p = t->frame_thread.pass & 1;
1400
1.80k
                    assert(ts->frame_thread[p].pal_idx);
1401
1.80k
                    pal = f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1402
1.80k
                                              ((t->bx >> 1) + (t->by & 1))];
1403
1.80k
                    pal_idx = ts->frame_thread[p].pal_idx;
1404
1.80k
                    ts->frame_thread[p].pal_idx += cbw4 * cbh4 * 8;
1405
1.80k
                } else {
1406
0
                    pal = bytefn(t->scratch.pal);
1407
0
                    pal_idx = t->scratch.pal_idx_uv;
1408
0
                }
1409
1410
1.80k
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[1]) + uv_dstoff,
1411
1.80k
                                       f->cur.stride[1], pal[1],
1412
1.80k
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1413
1.80k
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[2]) + uv_dstoff,
1414
1.80k
                                       f->cur.stride[1], pal[2],
1415
1.80k
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1416
1.80k
                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1417
0
                    hex_dump(((pixel *) f->cur.data[1]) + uv_dstoff,
1418
0
                             PXSTRIDE(f->cur.stride[1]),
1419
0
                             cbw4 * 4, cbh4 * 4, "u-pal-pred");
1420
0
                    hex_dump(((pixel *) f->cur.data[2]) + uv_dstoff,
1421
0
                             PXSTRIDE(f->cur.stride[1]),
1422
0
                             cbw4 * 4, cbh4 * 4, "v-pal-pred");
1423
0
                }
1424
1.80k
            }
1425
1426
530k
            const int sm_uv_fl = sm_uv_flag(t->a, cbx4) |
1427
530k
                                 sm_uv_flag(&t->l, cby4);
1428
530k
            const int uv_sb_has_tr =
1429
530k
                ((init_x + 16) >> ss_hor) < cw4 ? 1 : init_y ? 0 :
1430
512k
                intra_edge_flags & (EDGE_I420_TOP_HAS_RIGHT >> (f->cur.p.layout - 1));
1431
530k
            const int uv_sb_has_bl =
1432
530k
                init_x ? 0 : ((init_y + 16) >> ss_ver) < ch4 ? 1 :
1433
512k
                intra_edge_flags & (EDGE_I420_LEFT_HAS_BOTTOM >> (f->cur.p.layout - 1));
1434
530k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
1435
1.58M
            for (int pl = 0; pl < 2; pl++) {
1436
2.14M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
1437
1.09M
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
1438
1.09M
                {
1439
1.09M
                    pixel *dst = ((pixel *) f->cur.data[1 + pl]) +
1440
1.09M
                                   4 * ((t->by >> ss_ver) * PXSTRIDE(stride) +
1441
1.09M
                                        ((t->bx + init_x) >> ss_hor));
1442
2.33M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
1443
1.24M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
1444
1.24M
                    {
1445
1.24M
                        if ((b->uv_mode == CFL_PRED && b->cfl_alpha[pl]) ||
1446
1.08M
                            b->pal_sz[1])
1447
161k
                        {
1448
161k
                            goto skip_uv_pred;
1449
161k
                        }
1450
1451
1.08M
                        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.08M
                        const enum EdgeFlags edge_flags =
1456
1.08M
                            (((y > (init_y >> ss_ver) || !uv_sb_has_tr) &&
1457
426k
                              (x + uv_t_dim->w >= sub_cw4)) ?
1458
782k
                                 0 : EDGE_I444_TOP_HAS_RIGHT) |
1459
1.08M
                            ((x > (init_x >> ss_hor) ||
1460
933k
                              (!uv_sb_has_bl && y + uv_t_dim->h >= sub_ch4)) ?
1461
693k
                                 0 : EDGE_I444_LEFT_HAS_BOTTOM);
1462
1.08M
                        const pixel *top_sb_edge = NULL;
1463
1.08M
                        if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1464
352k
                            top_sb_edge = f->ipred_edge[1 + pl];
1465
352k
                            const int sby = t->by >> f->sb_shift;
1466
352k
                            top_sb_edge += f->sb128w * 128 * (sby - 1);
1467
352k
                        }
1468
1.08M
                        const enum IntraPredMode uv_mode =
1469
1.08M
                             b->uv_mode == CFL_PRED ? DC_PRED : b->uv_mode;
1470
1.08M
                        const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1471
1.08M
                        const int xstart = ts->tiling.col_start >> ss_hor;
1472
1.08M
                        const int ystart = ts->tiling.row_start >> ss_ver;
1473
1.08M
                        const enum IntraPredMode m =
1474
1.08M
                            bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1475
1.08M
                                                              ypos, ypos > ystart,
1476
1.08M
                                                              ts->tiling.col_end >> ss_hor,
1477
1.08M
                                                              ts->tiling.row_end >> ss_ver,
1478
1.08M
                                                              edge_flags, dst, stride,
1479
1.08M
                                                              top_sb_edge, uv_mode,
1480
1.08M
                                                              &angle, uv_t_dim->w,
1481
1.08M
                                                              uv_t_dim->h,
1482
1.08M
                                                              f->seq_hdr->intra_edge_filter,
1483
1.08M
                                                              edge HIGHBD_CALL_SUFFIX);
1484
1.08M
                        angle |= intra_edge_filter_flag;
1485
1.08M
                        dsp->ipred.intra_pred[m](dst, stride, edge,
1486
1.08M
                                                 uv_t_dim->w * 4,
1487
1.08M
                                                 uv_t_dim->h * 4,
1488
1.08M
                                                 angle | sm_uv_fl,
1489
1.08M
                                                 (4 * f->bw + ss_hor -
1490
1.08M
                                                  4 * (t->bx & ~ss_hor)) >> ss_hor,
1491
1.08M
                                                 (4 * f->bh + ss_ver -
1492
1.08M
                                                  4 * (t->by & ~ss_ver)) >> ss_ver
1493
1.08M
                                                 HIGHBD_CALL_SUFFIX);
1494
1.08M
                        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.24M
                    skip_uv_pred: {}
1505
1.24M
                        if (!b->skip) {
1506
356k
                            enum TxfmType txtp;
1507
356k
                            int eob;
1508
356k
                            coef *cf;
1509
356k
                            if (t->frame_thread.pass) {
1510
356k
                                const int p = t->frame_thread.pass & 1;
1511
356k
                                const int cbi = *ts->frame_thread[p].cbi++;
1512
356k
                                cf = ts->frame_thread[p].cf;
1513
356k
                                ts->frame_thread[p].cf += uv_t_dim->w * uv_t_dim->h * 16;
1514
356k
                                eob  = cbi >> 5;
1515
356k
                                txtp = cbi & 0x1f;
1516
356k
                            } 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
356k
                            if (eob >= 0) {
1533
129k
                                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
129k
                                dsp->itx.itxfm_add[b->uvtx]
1537
129k
                                                  [txtp](dst, stride,
1538
129k
                                                         cf, eob HIGHBD_CALL_SUFFIX);
1539
129k
                                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
129k
                            }
1543
888k
                        } 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.24M
                        dst += uv_t_dim->w * 4;
1548
1.24M
                    }
1549
1.09M
                    t->bx -= x << ss_hor;
1550
1.09M
                }
1551
1.05M
                t->by -= y << ss_ver;
1552
1.05M
            }
1553
530k
        }
1554
638k
    }
1555
626k
}
dav1d_recon_b_intra_16bpc
Line
Count
Source
1179
566k
{
1180
566k
    Dav1dTileState *const ts = t->ts;
1181
566k
    const Dav1dFrameContext *const f = t->f;
1182
566k
    const Dav1dDSPContext *const dsp = f->dsp;
1183
566k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1184
566k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1185
566k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1186
566k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1187
566k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1188
566k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1189
566k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1190
566k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1191
566k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1192
496k
                           (bw4 > ss_hor || t->bx & 1) &&
1193
462k
                           (bh4 > ss_ver || t->by & 1);
1194
566k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->tx];
1195
566k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
1196
1197
    // coefficient coding
1198
566k
    pixel *const edge = bitfn(t->scratch.edge) + 128;
1199
566k
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
1200
1201
566k
    const int intra_edge_filter_flag = f->seq_hdr->intra_edge_filter << 10;
1202
1203
1.14M
    for (int init_y = 0; init_y < h4; init_y += 16) {
1204
584k
        const int sub_h4 = imin(h4, 16 + init_y);
1205
584k
        const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
1206
1.19M
        for (int init_x = 0; init_x < w4; init_x += 16) {
1207
614k
            if (b->pal_sz[0]) {
1208
3.54k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1209
3.54k
                             4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1210
3.54k
                const uint8_t *pal_idx;
1211
3.54k
                if (t->frame_thread.pass) {
1212
3.54k
                    const int p = t->frame_thread.pass & 1;
1213
3.54k
                    assert(ts->frame_thread[p].pal_idx);
1214
3.54k
                    pal_idx = ts->frame_thread[p].pal_idx;
1215
3.54k
                    ts->frame_thread[p].pal_idx += bw4 * bh4 * 8;
1216
3.54k
                } else {
1217
0
                    pal_idx = t->scratch.pal_idx_y;
1218
0
                }
1219
3.54k
                const pixel *const pal = t->frame_thread.pass ?
1220
3.54k
                    f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1221
3.54k
                                        ((t->bx >> 1) + (t->by & 1))][0] :
1222
3.54k
                    bytefn(t->scratch.pal)[0];
1223
3.54k
                f->dsp->ipred.pal_pred(dst, f->cur.stride[0], pal,
1224
3.54k
                                       pal_idx, bw4 * 4, bh4 * 4);
1225
3.54k
                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1226
0
                    hex_dump(dst, PXSTRIDE(f->cur.stride[0]),
1227
0
                             bw4 * 4, bh4 * 4, "y-pal-pred");
1228
3.54k
            }
1229
1230
614k
            const int intra_flags = (sm_flag(t->a, bx4) |
1231
614k
                                     sm_flag(&t->l, by4) |
1232
614k
                                     intra_edge_filter_flag);
1233
614k
            const int sb_has_tr = init_x + 16 < w4 ? 1 : init_y ? 0 :
1234
584k
                              intra_edge_flags & EDGE_I444_TOP_HAS_RIGHT;
1235
614k
            const int sb_has_bl = init_x ? 0 : init_y + 16 < h4 ? 1 :
1236
584k
                              intra_edge_flags & EDGE_I444_LEFT_HAS_BOTTOM;
1237
614k
            int y, x;
1238
614k
            const int sub_w4 = imin(w4, init_x + 16);
1239
1.39M
            for (y = init_y, t->by += init_y; y < sub_h4;
1240
778k
                 y += t_dim->h, t->by += t_dim->h)
1241
783k
            {
1242
783k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1243
783k
                               4 * (t->by * PXSTRIDE(f->cur.stride[0]) +
1244
783k
                                    t->bx + init_x);
1245
2.15M
                for (x = init_x, t->bx += init_x; x < sub_w4;
1246
1.36M
                     x += t_dim->w, t->bx += t_dim->w)
1247
1.37M
                {
1248
1.37M
                    if (b->pal_sz[0]) goto skip_y_pred;
1249
1250
1.36M
                    int angle = b->y_angle;
1251
1.36M
                    const enum EdgeFlags edge_flags =
1252
1.36M
                        (((y > init_y || !sb_has_tr) && (x + t_dim->w >= sub_w4)) ?
1253
994k
                             0 : EDGE_I444_TOP_HAS_RIGHT) |
1254
1.36M
                        ((x > init_x || (!sb_has_bl && y + t_dim->h >= sub_h4)) ?
1255
941k
                             0 : EDGE_I444_LEFT_HAS_BOTTOM);
1256
1.36M
                    const pixel *top_sb_edge = NULL;
1257
1.36M
                    if (!(t->by & (f->sb_step - 1))) {
1258
223k
                        top_sb_edge = f->ipred_edge[0];
1259
223k
                        const int sby = t->by >> f->sb_shift;
1260
223k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1261
223k
                    }
1262
1.36M
                    const enum IntraPredMode m =
1263
1.36M
                        bytefn(dav1d_prepare_intra_edges)(t->bx,
1264
1.36M
                                                          t->bx > ts->tiling.col_start,
1265
1.36M
                                                          t->by,
1266
1.36M
                                                          t->by > ts->tiling.row_start,
1267
1.36M
                                                          ts->tiling.col_end,
1268
1.36M
                                                          ts->tiling.row_end,
1269
1.36M
                                                          edge_flags, dst,
1270
1.36M
                                                          f->cur.stride[0], top_sb_edge,
1271
1.36M
                                                          b->y_mode, &angle,
1272
1.36M
                                                          t_dim->w, t_dim->h,
1273
1.36M
                                                          f->seq_hdr->intra_edge_filter,
1274
1.36M
                                                          edge HIGHBD_CALL_SUFFIX);
1275
1.36M
                    dsp->ipred.intra_pred[m](dst, f->cur.stride[0], edge,
1276
1.36M
                                             t_dim->w * 4, t_dim->h * 4,
1277
1.36M
                                             angle | intra_flags,
1278
1.36M
                                             4 * f->bw - 4 * t->bx,
1279
1.36M
                                             4 * f->bh - 4 * t->by
1280
1.36M
                                             HIGHBD_CALL_SUFFIX);
1281
1282
1.36M
                    if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1283
0
                        hex_dump(edge - t_dim->h * 4, t_dim->h * 4,
1284
0
                                 t_dim->h * 4, 2, "l");
1285
0
                        hex_dump(edge, 0, 1, 1, "tl");
1286
0
                        hex_dump(edge + 1, t_dim->w * 4,
1287
0
                                 t_dim->w * 4, 2, "t");
1288
0
                        hex_dump(dst, f->cur.stride[0],
1289
0
                                 t_dim->w * 4, t_dim->h * 4, "y-intra-pred");
1290
0
                    }
1291
1292
1.36M
                skip_y_pred: {}
1293
1.36M
                    if (!b->skip) {
1294
425k
                        coef *cf;
1295
425k
                        int eob;
1296
425k
                        enum TxfmType txtp;
1297
425k
                        if (t->frame_thread.pass) {
1298
425k
                            const int p = t->frame_thread.pass & 1;
1299
425k
                            const int cbi = *ts->frame_thread[p].cbi++;
1300
425k
                            cf = ts->frame_thread[p].cf;
1301
425k
                            ts->frame_thread[p].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
1302
425k
                            eob  = cbi >> 5;
1303
425k
                            txtp = cbi & 0x1f;
1304
425k
                        } 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
425k
                        if (eob >= 0) {
1317
301k
                            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
301k
                            dsp->itx.itxfm_add[b->tx]
1321
301k
                                              [txtp](dst,
1322
301k
                                                     f->cur.stride[0],
1323
301k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1324
301k
                            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
301k
                        }
1328
943k
                    } else if (!t->frame_thread.pass) {
1329
0
                        dav1d_memset_pow2[t_dim->lw](&t->a->lcoef[bx4 + x], 0x40);
1330
0
                        dav1d_memset_pow2[t_dim->lh](&t->l.lcoef[by4 + y], 0x40);
1331
0
                    }
1332
1.36M
                    dst += 4 * t_dim->w;
1333
1.36M
                }
1334
778k
                t->bx -= x;
1335
778k
            }
1336
609k
            t->by -= y;
1337
1338
609k
            if (!has_chroma) continue;
1339
1340
461k
            const ptrdiff_t stride = f->cur.stride[1];
1341
1342
461k
            if (b->uv_mode == CFL_PRED) {
1343
83.5k
                assert(!init_x && !init_y);
1344
1345
83.5k
                int16_t *const ac = t->scratch.ac;
1346
83.5k
                pixel *y_src = ((pixel *) f->cur.data[0]) + 4 * (t->bx & ~ss_hor) +
1347
83.5k
                                 4 * (t->by & ~ss_ver) * PXSTRIDE(f->cur.stride[0]);
1348
83.5k
                const ptrdiff_t uv_off = 4 * ((t->bx >> ss_hor) +
1349
83.5k
                                              (t->by >> ss_ver) * PXSTRIDE(stride));
1350
83.5k
                pixel *const uv_dst[2] = { ((pixel *) f->cur.data[1]) + uv_off,
1351
83.5k
                                           ((pixel *) f->cur.data[2]) + uv_off };
1352
1353
83.5k
                const int furthest_r =
1354
83.5k
                    ((cw4 << ss_hor) + t_dim->w - 1) & ~(t_dim->w - 1);
1355
83.5k
                const int furthest_b =
1356
83.5k
                    ((ch4 << ss_ver) + t_dim->h - 1) & ~(t_dim->h - 1);
1357
83.5k
                dsp->ipred.cfl_ac[f->cur.p.layout - 1](ac, y_src, f->cur.stride[0],
1358
83.5k
                                                         cbw4 - (furthest_r >> ss_hor),
1359
83.5k
                                                         cbh4 - (furthest_b >> ss_ver),
1360
83.5k
                                                         cbw4 * 4, cbh4 * 4);
1361
250k
                for (int pl = 0; pl < 2; pl++) {
1362
167k
                    if (!b->cfl_alpha[pl]) continue;
1363
133k
                    int angle = 0;
1364
133k
                    const pixel *top_sb_edge = NULL;
1365
133k
                    if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1366
30.0k
                        top_sb_edge = f->ipred_edge[pl + 1];
1367
30.0k
                        const int sby = t->by >> f->sb_shift;
1368
30.0k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1369
30.0k
                    }
1370
133k
                    const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1371
133k
                    const int xstart = ts->tiling.col_start >> ss_hor;
1372
133k
                    const int ystart = ts->tiling.row_start >> ss_ver;
1373
133k
                    const enum IntraPredMode m =
1374
133k
                        bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1375
133k
                                                          ypos, ypos > ystart,
1376
133k
                                                          ts->tiling.col_end >> ss_hor,
1377
133k
                                                          ts->tiling.row_end >> ss_ver,
1378
133k
                                                          0, uv_dst[pl], stride,
1379
133k
                                                          top_sb_edge, DC_PRED, &angle,
1380
133k
                                                          uv_t_dim->w, uv_t_dim->h, 0,
1381
133k
                                                          edge HIGHBD_CALL_SUFFIX);
1382
133k
                    dsp->ipred.cfl_pred[m](uv_dst[pl], stride, edge,
1383
133k
                                           uv_t_dim->w * 4,
1384
133k
                                           uv_t_dim->h * 4,
1385
133k
                                           ac, b->cfl_alpha[pl]
1386
133k
                                           HIGHBD_CALL_SUFFIX);
1387
133k
                }
1388
83.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
377k
            } else if (b->pal_sz[1]) {
1394
1.63k
                const ptrdiff_t uv_dstoff = 4 * ((t->bx >> ss_hor) +
1395
1.63k
                                              (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1396
1.63k
                const pixel (*pal)[8];
1397
1.63k
                const uint8_t *pal_idx;
1398
1.63k
                if (t->frame_thread.pass) {
1399
1.63k
                    const int p = t->frame_thread.pass & 1;
1400
1.63k
                    assert(ts->frame_thread[p].pal_idx);
1401
1.63k
                    pal = f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1402
1.63k
                                              ((t->bx >> 1) + (t->by & 1))];
1403
1.63k
                    pal_idx = ts->frame_thread[p].pal_idx;
1404
1.63k
                    ts->frame_thread[p].pal_idx += cbw4 * cbh4 * 8;
1405
1.63k
                } else {
1406
0
                    pal = bytefn(t->scratch.pal);
1407
0
                    pal_idx = t->scratch.pal_idx_uv;
1408
0
                }
1409
1410
1.63k
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[1]) + uv_dstoff,
1411
1.63k
                                       f->cur.stride[1], pal[1],
1412
1.63k
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1413
1.63k
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[2]) + uv_dstoff,
1414
1.63k
                                       f->cur.stride[1], pal[2],
1415
1.63k
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1416
1.63k
                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1417
0
                    hex_dump(((pixel *) f->cur.data[1]) + uv_dstoff,
1418
0
                             PXSTRIDE(f->cur.stride[1]),
1419
0
                             cbw4 * 4, cbh4 * 4, "u-pal-pred");
1420
0
                    hex_dump(((pixel *) f->cur.data[2]) + uv_dstoff,
1421
0
                             PXSTRIDE(f->cur.stride[1]),
1422
0
                             cbw4 * 4, cbh4 * 4, "v-pal-pred");
1423
0
                }
1424
1.63k
            }
1425
1426
461k
            const int sm_uv_fl = sm_uv_flag(t->a, cbx4) |
1427
461k
                                 sm_uv_flag(&t->l, cby4);
1428
461k
            const int uv_sb_has_tr =
1429
461k
                ((init_x + 16) >> ss_hor) < cw4 ? 1 : init_y ? 0 :
1430
435k
                intra_edge_flags & (EDGE_I420_TOP_HAS_RIGHT >> (f->cur.p.layout - 1));
1431
461k
            const int uv_sb_has_bl =
1432
461k
                init_x ? 0 : ((init_y + 16) >> ss_ver) < ch4 ? 1 :
1433
435k
                intra_edge_flags & (EDGE_I420_LEFT_HAS_BOTTOM >> (f->cur.p.layout - 1));
1434
461k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
1435
1.39M
            for (int pl = 0; pl < 2; pl++) {
1436
1.92M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
1437
996k
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
1438
998k
                {
1439
998k
                    pixel *dst = ((pixel *) f->cur.data[1 + pl]) +
1440
998k
                                   4 * ((t->by >> ss_ver) * PXSTRIDE(stride) +
1441
998k
                                        ((t->bx + init_x) >> ss_hor));
1442
2.24M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
1443
1.24M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
1444
1.24M
                    {
1445
1.24M
                        if ((b->uv_mode == CFL_PRED && b->cfl_alpha[pl]) ||
1446
1.11M
                            b->pal_sz[1])
1447
136k
                        {
1448
136k
                            goto skip_uv_pred;
1449
136k
                        }
1450
1451
1.11M
                        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.11M
                        const enum EdgeFlags edge_flags =
1456
1.11M
                            (((y > (init_y >> ss_ver) || !uv_sb_has_tr) &&
1457
535k
                              (x + uv_t_dim->w >= sub_cw4)) ?
1458
793k
                                 0 : EDGE_I444_TOP_HAS_RIGHT) |
1459
1.11M
                            ((x > (init_x >> ss_hor) ||
1460
862k
                              (!uv_sb_has_bl && y + uv_t_dim->h >= sub_ch4)) ?
1461
721k
                                 0 : EDGE_I444_LEFT_HAS_BOTTOM);
1462
1.11M
                        const pixel *top_sb_edge = NULL;
1463
1.11M
                        if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1464
275k
                            top_sb_edge = f->ipred_edge[1 + pl];
1465
275k
                            const int sby = t->by >> f->sb_shift;
1466
275k
                            top_sb_edge += f->sb128w * 128 * (sby - 1);
1467
275k
                        }
1468
1.11M
                        const enum IntraPredMode uv_mode =
1469
1.11M
                             b->uv_mode == CFL_PRED ? DC_PRED : b->uv_mode;
1470
1.11M
                        const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1471
1.11M
                        const int xstart = ts->tiling.col_start >> ss_hor;
1472
1.11M
                        const int ystart = ts->tiling.row_start >> ss_ver;
1473
1.11M
                        const enum IntraPredMode m =
1474
1.11M
                            bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1475
1.11M
                                                              ypos, ypos > ystart,
1476
1.11M
                                                              ts->tiling.col_end >> ss_hor,
1477
1.11M
                                                              ts->tiling.row_end >> ss_ver,
1478
1.11M
                                                              edge_flags, dst, stride,
1479
1.11M
                                                              top_sb_edge, uv_mode,
1480
1.11M
                                                              &angle, uv_t_dim->w,
1481
1.11M
                                                              uv_t_dim->h,
1482
1.11M
                                                              f->seq_hdr->intra_edge_filter,
1483
1.11M
                                                              edge HIGHBD_CALL_SUFFIX);
1484
1.11M
                        angle |= intra_edge_filter_flag;
1485
1.11M
                        dsp->ipred.intra_pred[m](dst, stride, edge,
1486
1.11M
                                                 uv_t_dim->w * 4,
1487
1.11M
                                                 uv_t_dim->h * 4,
1488
1.11M
                                                 angle | sm_uv_fl,
1489
1.11M
                                                 (4 * f->bw + ss_hor -
1490
1.11M
                                                  4 * (t->bx & ~ss_hor)) >> ss_hor,
1491
1.11M
                                                 (4 * f->bh + ss_ver -
1492
1.11M
                                                  4 * (t->by & ~ss_ver)) >> ss_ver
1493
1.11M
                                                 HIGHBD_CALL_SUFFIX);
1494
1.11M
                        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.24M
                    skip_uv_pred: {}
1505
1.24M
                        if (!b->skip) {
1506
474k
                            enum TxfmType txtp;
1507
474k
                            int eob;
1508
474k
                            coef *cf;
1509
474k
                            if (t->frame_thread.pass) {
1510
474k
                                const int p = t->frame_thread.pass & 1;
1511
474k
                                const int cbi = *ts->frame_thread[p].cbi++;
1512
474k
                                cf = ts->frame_thread[p].cf;
1513
474k
                                ts->frame_thread[p].cf += uv_t_dim->w * uv_t_dim->h * 16;
1514
474k
                                eob  = cbi >> 5;
1515
474k
                                txtp = cbi & 0x1f;
1516
474k
                            } else {
1517
1
                                uint8_t cf_ctx;
1518
1
                                cf = bitfn(t->cf);
1519
1
                                eob = decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
1520
1
                                                   &t->l.ccoef[pl][cby4 + y],
1521
1
                                                   b->uvtx, bs, b, 1, 1 + pl, cf,
1522
1
                                                   &txtp, &cf_ctx);
1523
1
                                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
1
                                int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
1528
1
                                int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
1529
1
                                dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
1530
1
                                dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
1531
1
                            }
1532
474k
                            if (eob >= 0) {
1533
153k
                                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
153k
                                dsp->itx.itxfm_add[b->uvtx]
1537
153k
                                                  [txtp](dst, stride,
1538
153k
                                                         cf, eob HIGHBD_CALL_SUFFIX);
1539
153k
                                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
153k
                            }
1543
770k
                        } 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.24M
                        dst += uv_t_dim->w * 4;
1548
1.24M
                    }
1549
996k
                    t->bx -= x << ss_hor;
1550
996k
                }
1551
929k
                t->by -= y << ss_ver;
1552
929k
            }
1553
461k
        }
1554
584k
    }
1555
566k
}
1556
1557
int bytefn(dav1d_recon_b_inter)(Dav1dTaskContext *const t, const enum BlockSize bs,
1558
                                const Av1Block *const b)
1559
323k
{
1560
323k
    Dav1dTileState *const ts = t->ts;
1561
323k
    const Dav1dFrameContext *const f = t->f;
1562
323k
    const Dav1dDSPContext *const dsp = f->dsp;
1563
323k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1564
323k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1565
323k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1566
323k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1567
323k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1568
323k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1569
323k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1570
323k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1571
269k
                           (bw4 > ss_hor || t->bx & 1) &&
1572
261k
                           (bh4 > ss_ver || t->by & 1);
1573
323k
    const int chr_layout_idx = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I400 ? 0 :
1574
323k
                               DAV1D_PIXEL_LAYOUT_I444 - f->cur.p.layout;
1575
323k
    int res;
1576
1577
    // prediction
1578
323k
    const int cbh4 = (bh4 + ss_ver) >> ss_ver, cbw4 = (bw4 + ss_hor) >> ss_hor;
1579
323k
    pixel *dst = ((pixel *) f->cur.data[0]) +
1580
323k
        4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1581
323k
    const ptrdiff_t uvdstoff =
1582
323k
        4 * ((t->bx >> ss_hor) + (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1583
323k
    if (IS_KEY_OR_INTRA(f->frame_hdr)) {
1584
        // intrabc
1585
60.4k
        assert(!f->frame_hdr->super_res.enabled);
1586
60.4k
        res = mc(t, dst, NULL, f->cur.stride[0], bw4, bh4, t->bx, t->by, 0,
1587
60.4k
                 b->mv[0], &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1588
60.4k
        if (res) return res;
1589
86.2k
        if (has_chroma) for (int pl = 1; pl < 3; pl++) {
1590
57.5k
            res = mc(t, ((pixel *)f->cur.data[pl]) + uvdstoff, NULL, f->cur.stride[1],
1591
57.5k
                     bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1592
57.5k
                     t->bx & ~ss_hor, t->by & ~ss_ver, pl, b->mv[0],
1593
57.5k
                     &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1594
57.5k
            if (res) return res;
1595
57.5k
        }
1596
262k
    } else if (b->comp_type == COMP_INTER_NONE) {
1597
232k
        const Dav1dThreadPicture *const refp = &f->refp[b->ref[0]];
1598
232k
        const enum Filter2d filter_2d = b->filter2d;
1599
1600
232k
        if (imin(bw4, bh4) > 1 &&
1601
153k
            ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1602
151k
             (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1603
4.25k
        {
1604
4.25k
            res = warp_affine(t, dst, NULL, f->cur.stride[0], b_dim, 0, refp,
1605
4.25k
                              b->motion_mode == MM_WARP ? &t->warpmv :
1606
4.25k
                                  &f->frame_hdr->gmv[b->ref[0]]);
1607
4.25k
            if (res) return res;
1608
228k
        } else {
1609
228k
            res = mc(t, dst, NULL, f->cur.stride[0],
1610
228k
                     bw4, bh4, t->bx, t->by, 0, b->mv[0], refp, b->ref[0], filter_2d);
1611
228k
            if (res) return res;
1612
228k
            if (b->motion_mode == MM_OBMC) {
1613
40.3k
                res = obmc(t, dst, f->cur.stride[0], b_dim, 0, bx4, by4, w4, h4);
1614
40.3k
                if (res) return res;
1615
40.3k
            }
1616
228k
        }
1617
232k
        if (b->interintra_type) {
1618
9.22k
            pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1619
9.22k
            enum IntraPredMode m = b->interintra_mode == II_SMOOTH_PRED ?
1620
7.43k
                                   SMOOTH_PRED : b->interintra_mode;
1621
9.22k
            pixel *const tmp = bitfn(t->scratch.interintra);
1622
9.22k
            int angle = 0;
1623
9.22k
            const pixel *top_sb_edge = NULL;
1624
9.22k
            if (!(t->by & (f->sb_step - 1))) {
1625
2.98k
                top_sb_edge = f->ipred_edge[0];
1626
2.98k
                const int sby = t->by >> f->sb_shift;
1627
2.98k
                top_sb_edge += f->sb128w * 128 * (sby - 1);
1628
2.98k
            }
1629
9.22k
            m = bytefn(dav1d_prepare_intra_edges)(t->bx, t->bx > ts->tiling.col_start,
1630
9.22k
                                                  t->by, t->by > ts->tiling.row_start,
1631
9.22k
                                                  ts->tiling.col_end, ts->tiling.row_end,
1632
9.22k
                                                  0, dst, f->cur.stride[0], top_sb_edge,
1633
9.22k
                                                  m, &angle, bw4, bh4, 0, tl_edge
1634
9.22k
                                                  HIGHBD_CALL_SUFFIX);
1635
9.22k
            dsp->ipred.intra_pred[m](tmp, 4 * bw4 * sizeof(pixel),
1636
9.22k
                                     tl_edge, bw4 * 4, bh4 * 4, 0, 0, 0
1637
9.22k
                                     HIGHBD_CALL_SUFFIX);
1638
9.22k
            dsp->mc.blend(dst, f->cur.stride[0], tmp,
1639
9.22k
                          bw4 * 4, bh4 * 4, II_MASK(0, bs, b));
1640
9.22k
        }
1641
1642
232k
        if (!has_chroma) goto skip_inter_chroma_pred;
1643
1644
        // sub8x8 derivation
1645
200k
        int is_sub8x8 = bw4 == ss_hor || bh4 == ss_ver;
1646
200k
        refmvs_block *const *r;
1647
200k
        if (is_sub8x8) {
1648
8.02k
            assert(ss_hor == 1);
1649
8.02k
            r = &t->rt.r[(t->by & 31) + 5];
1650
8.02k
            if (bw4 == 1) is_sub8x8 &= r[0][t->bx - 1].ref.ref[0] > 0;
1651
8.02k
            if (bh4 == ss_ver) is_sub8x8 &= r[-1][t->bx].ref.ref[0] > 0;
1652
8.02k
            if (bw4 == 1 && bh4 == ss_ver)
1653
945
                is_sub8x8 &= r[-1][t->bx - 1].ref.ref[0] > 0;
1654
8.02k
        }
1655
1656
        // chroma prediction
1657
200k
        if (is_sub8x8) {
1658
7.91k
            assert(ss_hor == 1);
1659
7.91k
            ptrdiff_t h_off = 0, v_off = 0;
1660
7.91k
            if (bw4 == 1 && bh4 == ss_ver) {
1661
2.74k
                for (int pl = 0; pl < 2; pl++) {
1662
1.83k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1663
1.83k
                             NULL, f->cur.stride[1],
1664
1.83k
                             bw4, bh4, t->bx - 1, t->by - 1, 1 + pl,
1665
1.83k
                             r[-1][t->bx - 1].mv.mv[0],
1666
1.83k
                             &f->refp[r[-1][t->bx - 1].ref.ref[0] - 1],
1667
1.83k
                             r[-1][t->bx - 1].ref.ref[0] - 1,
1668
1.83k
                             t->frame_thread.pass != 2 ? t->tl_4x4_filter :
1669
1.83k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx - 1].filter2d);
1670
1.83k
                    if (res) return res;
1671
1.83k
                }
1672
915
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1673
915
                h_off = 2;
1674
915
            }
1675
7.91k
            if (bw4 == 1) {
1676
3.90k
                const enum Filter2d left_filter_2d =
1677
3.90k
                    dav1d_filter_2d[t->l.filter[1][by4]][t->l.filter[0][by4]];
1678
11.7k
                for (int pl = 0; pl < 2; pl++) {
1679
7.81k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + v_off, NULL,
1680
7.81k
                             f->cur.stride[1], bw4, bh4, t->bx - 1,
1681
7.81k
                             t->by, 1 + pl, r[0][t->bx - 1].mv.mv[0],
1682
7.81k
                             &f->refp[r[0][t->bx - 1].ref.ref[0] - 1],
1683
7.81k
                             r[0][t->bx - 1].ref.ref[0] - 1,
1684
7.81k
                             t->frame_thread.pass != 2 ? left_filter_2d :
1685
7.81k
                                 f->frame_thread.b[(t->by * f->b4_stride) + t->bx - 1].filter2d);
1686
7.81k
                    if (res) return res;
1687
7.81k
                }
1688
3.90k
                h_off = 2;
1689
3.90k
            }
1690
7.91k
            if (bh4 == ss_ver) {
1691
4.91k
                const enum Filter2d top_filter_2d =
1692
4.91k
                    dav1d_filter_2d[t->a->filter[1][bx4]][t->a->filter[0][bx4]];
1693
14.7k
                for (int pl = 0; pl < 2; pl++) {
1694
9.83k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off, NULL,
1695
9.83k
                             f->cur.stride[1], bw4, bh4, t->bx, t->by - 1,
1696
9.83k
                             1 + pl, r[-1][t->bx].mv.mv[0],
1697
9.83k
                             &f->refp[r[-1][t->bx].ref.ref[0] - 1],
1698
9.83k
                             r[-1][t->bx].ref.ref[0] - 1,
1699
9.83k
                             t->frame_thread.pass != 2 ? top_filter_2d :
1700
9.83k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx].filter2d);
1701
9.83k
                    if (res) return res;
1702
9.83k
                }
1703
4.91k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1704
4.91k
            }
1705
23.7k
            for (int pl = 0; pl < 2; pl++) {
1706
15.8k
                res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off + v_off, NULL, f->cur.stride[1],
1707
15.8k
                         bw4, bh4, t->bx, t->by, 1 + pl, b->mv[0],
1708
15.8k
                         refp, b->ref[0], filter_2d);
1709
15.8k
                if (res) return res;
1710
15.8k
            }
1711
193k
        } else {
1712
193k
            if (imin(cbw4, cbh4) > 1 &&
1713
112k
                ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1714
110k
                 (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1715
3.99k
            {
1716
11.9k
                for (int pl = 0; pl < 2; pl++) {
1717
7.99k
                    res = warp_affine(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff, NULL,
1718
7.99k
                                      f->cur.stride[1], b_dim, 1 + pl, refp,
1719
7.99k
                                      b->motion_mode == MM_WARP ? &t->warpmv :
1720
7.99k
                                          &f->frame_hdr->gmv[b->ref[0]]);
1721
7.99k
                    if (res) return res;
1722
7.99k
                }
1723
189k
            } else {
1724
567k
                for (int pl = 0; pl < 2; pl++) {
1725
378k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1726
378k
                             NULL, f->cur.stride[1],
1727
378k
                             bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1728
378k
                             t->bx & ~ss_hor, t->by & ~ss_ver,
1729
378k
                             1 + pl, b->mv[0], refp, b->ref[0], filter_2d);
1730
378k
                    if (res) return res;
1731
378k
                    if (b->motion_mode == MM_OBMC) {
1732
74.0k
                        res = obmc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1733
74.0k
                                   f->cur.stride[1], b_dim, 1 + pl, bx4, by4, w4, h4);
1734
74.0k
                        if (res) return res;
1735
74.0k
                    }
1736
378k
                }
1737
189k
            }
1738
193k
            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
8.53k
                const uint8_t *const ii_mask = II_MASK(chr_layout_idx, bs, b);
1743
1744
25.6k
                for (int pl = 0; pl < 2; pl++) {
1745
17.0k
                    pixel *const tmp = bitfn(t->scratch.interintra);
1746
17.0k
                    pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1747
17.0k
                    enum IntraPredMode m =
1748
17.0k
                        b->interintra_mode == II_SMOOTH_PRED ?
1749
13.9k
                        SMOOTH_PRED : b->interintra_mode;
1750
17.0k
                    int angle = 0;
1751
17.0k
                    pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1752
17.0k
                    const pixel *top_sb_edge = NULL;
1753
17.0k
                    if (!(t->by & (f->sb_step - 1))) {
1754
4.70k
                        top_sb_edge = f->ipred_edge[pl + 1];
1755
4.70k
                        const int sby = t->by >> f->sb_shift;
1756
4.70k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1757
4.70k
                    }
1758
17.0k
                    m = bytefn(dav1d_prepare_intra_edges)(t->bx >> ss_hor,
1759
17.0k
                                                          (t->bx >> ss_hor) >
1760
17.0k
                                                              (ts->tiling.col_start >> ss_hor),
1761
17.0k
                                                          t->by >> ss_ver,
1762
17.0k
                                                          (t->by >> ss_ver) >
1763
17.0k
                                                              (ts->tiling.row_start >> ss_ver),
1764
17.0k
                                                          ts->tiling.col_end >> ss_hor,
1765
17.0k
                                                          ts->tiling.row_end >> ss_ver,
1766
17.0k
                                                          0, uvdst, f->cur.stride[1],
1767
17.0k
                                                          top_sb_edge, m,
1768
17.0k
                                                          &angle, cbw4, cbh4, 0, tl_edge
1769
17.0k
                                                          HIGHBD_CALL_SUFFIX);
1770
17.0k
                    dsp->ipred.intra_pred[m](tmp, cbw4 * 4 * sizeof(pixel),
1771
17.0k
                                             tl_edge, cbw4 * 4, cbh4 * 4, 0, 0, 0
1772
17.0k
                                             HIGHBD_CALL_SUFFIX);
1773
17.0k
                    dsp->mc.blend(uvdst, f->cur.stride[1], tmp,
1774
17.0k
                                  cbw4 * 4, cbh4 * 4, ii_mask);
1775
17.0k
                }
1776
8.53k
            }
1777
193k
        }
1778
1779
232k
    skip_inter_chroma_pred: {}
1780
232k
        t->tl_4x4_filter = filter_2d;
1781
232k
    } else {
1782
29.7k
        const enum Filter2d filter_2d = b->filter2d;
1783
        // Maximum super block size is 128x128
1784
29.7k
        int16_t (*tmp)[128 * 128] = t->scratch.compinter;
1785
29.7k
        int jnt_weight;
1786
29.7k
        uint8_t *const seg_mask = t->scratch.seg_mask;
1787
29.7k
        const uint8_t *mask;
1788
1789
89.2k
        for (int i = 0; i < 2; i++) {
1790
59.4k
            const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1791
1792
59.4k
            if (b->inter_mode == GLOBALMV_GLOBALMV && f->gmv_warp_allowed[b->ref[i]]) {
1793
4.12k
                res = warp_affine(t, NULL, tmp[i], bw4 * 4, b_dim, 0, refp,
1794
4.12k
                                  &f->frame_hdr->gmv[b->ref[i]]);
1795
4.12k
                if (res) return res;
1796
55.3k
            } else {
1797
55.3k
                res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by, 0,
1798
55.3k
                         b->mv[i], refp, b->ref[i], filter_2d);
1799
55.3k
                if (res) return res;
1800
55.3k
            }
1801
59.4k
        }
1802
29.7k
        switch (b->comp_type) {
1803
23.3k
        case COMP_INTER_AVG:
1804
23.3k
            dsp->mc.avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1805
23.3k
                        bw4 * 4, bh4 * 4 HIGHBD_CALL_SUFFIX);
1806
23.3k
            break;
1807
2.07k
        case COMP_INTER_WEIGHTED_AVG:
1808
2.07k
            jnt_weight = f->jnt_weights[b->ref[0]][b->ref[1]];
1809
2.07k
            dsp->mc.w_avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1810
2.07k
                          bw4 * 4, bh4 * 4, jnt_weight HIGHBD_CALL_SUFFIX);
1811
2.07k
            break;
1812
2.63k
        case COMP_INTER_SEG:
1813
2.63k
            dsp->mc.w_mask[chr_layout_idx](dst, f->cur.stride[0],
1814
2.63k
                                           tmp[b->mask_sign], tmp[!b->mask_sign],
1815
2.63k
                                           bw4 * 4, bh4 * 4, seg_mask,
1816
2.63k
                                           b->mask_sign HIGHBD_CALL_SUFFIX);
1817
2.63k
            mask = seg_mask;
1818
2.63k
            break;
1819
1.72k
        case COMP_INTER_WEDGE:
1820
1.72k
            mask = WEDGE_MASK(0, bs, 0, b->wedge_idx);
1821
1.72k
            dsp->mc.mask(dst, f->cur.stride[0],
1822
1.72k
                         tmp[b->mask_sign], tmp[!b->mask_sign],
1823
1.72k
                         bw4 * 4, bh4 * 4, mask HIGHBD_CALL_SUFFIX);
1824
1.72k
            if (has_chroma)
1825
1.16k
                mask = WEDGE_MASK(chr_layout_idx, bs, b->mask_sign, b->wedge_idx);
1826
1.72k
            break;
1827
29.7k
        }
1828
1829
        // chroma
1830
71.4k
        if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1831
142k
            for (int i = 0; i < 2; i++) {
1832
95.1k
                const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1833
95.1k
                if (b->inter_mode == GLOBALMV_GLOBALMV &&
1834
16.8k
                    imin(cbw4, cbh4) > 1 && f->gmv_warp_allowed[b->ref[i]])
1835
5.22k
                {
1836
5.22k
                    res = warp_affine(t, NULL, tmp[i], bw4 * 4 >> ss_hor,
1837
5.22k
                                      b_dim, 1 + pl,
1838
5.22k
                                      refp, &f->frame_hdr->gmv[b->ref[i]]);
1839
5.22k
                    if (res) return res;
1840
89.9k
                } else {
1841
89.9k
                    res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by,
1842
89.9k
                             1 + pl, b->mv[i], refp, b->ref[i], filter_2d);
1843
89.9k
                    if (res) return res;
1844
89.9k
                }
1845
95.1k
            }
1846
47.6k
            pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1847
47.6k
            switch (b->comp_type) {
1848
38.1k
            case COMP_INTER_AVG:
1849
38.1k
                dsp->mc.avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1850
38.1k
                            bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver
1851
38.1k
                            HIGHBD_CALL_SUFFIX);
1852
38.1k
                break;
1853
2.72k
            case COMP_INTER_WEIGHTED_AVG:
1854
2.72k
                dsp->mc.w_avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1855
2.72k
                              bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, jnt_weight
1856
2.72k
                              HIGHBD_CALL_SUFFIX);
1857
2.72k
                break;
1858
2.32k
            case COMP_INTER_WEDGE:
1859
6.72k
            case COMP_INTER_SEG:
1860
6.72k
                dsp->mc.mask(uvdst, f->cur.stride[1],
1861
6.72k
                             tmp[b->mask_sign], tmp[!b->mask_sign],
1862
6.72k
                             bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, mask
1863
6.72k
                             HIGHBD_CALL_SUFFIX);
1864
6.72k
                break;
1865
47.6k
            }
1866
47.6k
        }
1867
29.7k
    }
1868
1869
323k
    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
323k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1880
1881
323k
    if (b->skip) {
1882
        // reset coef contexts
1883
177k
        BlockContext *const a = t->a;
1884
177k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
1885
177k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
1886
177k
        if (has_chroma) {
1887
140k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
1888
140k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
1889
140k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
1890
140k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
1891
140k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
1892
140k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
1893
140k
        }
1894
177k
        return 0;
1895
177k
    }
1896
1897
146k
    const TxfmInfo *const uvtx = &dav1d_txfm_dimensions[b->uvtx];
1898
146k
    const TxfmInfo *const ytx = &dav1d_txfm_dimensions[b->max_ytx];
1899
146k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
1900
1901
298k
    for (int init_y = 0; init_y < bh4; init_y += 16) {
1902
309k
        for (int init_x = 0; init_x < bw4; init_x += 16) {
1903
            // coefficient coding & inverse transforms
1904
156k
            int y_off = !!init_y, y;
1905
156k
            dst += PXSTRIDE(f->cur.stride[0]) * 4 * init_y;
1906
330k
            for (y = init_y, t->by += init_y; y < imin(h4, init_y + 16);
1907
173k
                 y += ytx->h, y_off++)
1908
173k
            {
1909
173k
                int x, x_off = !!init_x;
1910
416k
                for (x = init_x, t->bx += init_x; x < imin(w4, init_x + 16);
1911
242k
                     x += ytx->w, x_off++)
1912
242k
                {
1913
242k
                    read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
1914
242k
                                   x_off, y_off, &dst[x * 4]);
1915
242k
                    t->bx += ytx->w;
1916
242k
                }
1917
173k
                dst += PXSTRIDE(f->cur.stride[0]) * 4 * ytx->h;
1918
173k
                t->bx -= x;
1919
173k
                t->by += ytx->h;
1920
173k
            }
1921
156k
            dst -= PXSTRIDE(f->cur.stride[0]) * 4 * y;
1922
156k
            t->by -= y;
1923
1924
            // chroma coefs and inverse transform
1925
366k
            if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1926
244k
                pixel *uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff +
1927
244k
                    (PXSTRIDE(f->cur.stride[1]) * init_y * 4 >> ss_ver);
1928
244k
                for (y = init_y >> ss_ver, t->by += init_y;
1929
532k
                     y < imin(ch4, (init_y + 16) >> ss_ver); y += uvtx->h)
1930
288k
                {
1931
288k
                    int x;
1932
288k
                    for (x = init_x >> ss_hor, t->bx += init_x;
1933
727k
                         x < imin(cw4, (init_x + 16) >> ss_hor); x += uvtx->w)
1934
438k
                    {
1935
438k
                        coef *cf;
1936
438k
                        int eob;
1937
438k
                        enum TxfmType txtp;
1938
438k
                        if (t->frame_thread.pass) {
1939
438k
                            const int p = t->frame_thread.pass & 1;
1940
438k
                            const int cbi = *ts->frame_thread[p].cbi++;
1941
438k
                            cf = ts->frame_thread[p].cf;
1942
438k
                            ts->frame_thread[p].cf += uvtx->w * uvtx->h * 16;
1943
438k
                            eob  = cbi >> 5;
1944
438k
                            txtp = cbi & 0x1f;
1945
438k
                        } 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
438k
                        if (eob >= 0) {
1964
154k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1965
0
                                coef_dump(cf, uvtx->h * 4, uvtx->w * 4, 3, "dq");
1966
154k
                            dsp->itx.itxfm_add[b->uvtx]
1967
154k
                                              [txtp](&uvdst[4 * x],
1968
154k
                                                     f->cur.stride[1],
1969
154k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1970
154k
                            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
154k
                        }
1974
438k
                        t->bx += uvtx->w << ss_hor;
1975
438k
                    }
1976
288k
                    uvdst += PXSTRIDE(f->cur.stride[1]) * 4 * uvtx->h;
1977
288k
                    t->bx -= x << ss_hor;
1978
288k
                    t->by += uvtx->h << ss_ver;
1979
288k
                }
1980
244k
                t->by -= y << ss_ver;
1981
244k
            }
1982
156k
        }
1983
152k
    }
1984
146k
    return 0;
1985
323k
}
dav1d_recon_b_inter_8bpc
Line
Count
Source
1559
187k
{
1560
187k
    Dav1dTileState *const ts = t->ts;
1561
187k
    const Dav1dFrameContext *const f = t->f;
1562
187k
    const Dav1dDSPContext *const dsp = f->dsp;
1563
187k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1564
187k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1565
187k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1566
187k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1567
187k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1568
187k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1569
187k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1570
187k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1571
161k
                           (bw4 > ss_hor || t->bx & 1) &&
1572
156k
                           (bh4 > ss_ver || t->by & 1);
1573
187k
    const int chr_layout_idx = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I400 ? 0 :
1574
187k
                               DAV1D_PIXEL_LAYOUT_I444 - f->cur.p.layout;
1575
187k
    int res;
1576
1577
    // prediction
1578
187k
    const int cbh4 = (bh4 + ss_ver) >> ss_ver, cbw4 = (bw4 + ss_hor) >> ss_hor;
1579
187k
    pixel *dst = ((pixel *) f->cur.data[0]) +
1580
187k
        4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1581
187k
    const ptrdiff_t uvdstoff =
1582
187k
        4 * ((t->bx >> ss_hor) + (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1583
187k
    if (IS_KEY_OR_INTRA(f->frame_hdr)) {
1584
        // intrabc
1585
29.6k
        assert(!f->frame_hdr->super_res.enabled);
1586
29.6k
        res = mc(t, dst, NULL, f->cur.stride[0], bw4, bh4, t->bx, t->by, 0,
1587
29.6k
                 b->mv[0], &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1588
29.6k
        if (res) return res;
1589
29.6k
        if (has_chroma) for (int pl = 1; pl < 3; pl++) {
1590
18.7k
            res = mc(t, ((pixel *)f->cur.data[pl]) + uvdstoff, NULL, f->cur.stride[1],
1591
18.7k
                     bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1592
18.7k
                     t->bx & ~ss_hor, t->by & ~ss_ver, pl, b->mv[0],
1593
18.7k
                     &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1594
18.7k
            if (res) return res;
1595
18.7k
        }
1596
158k
    } else if (b->comp_type == COMP_INTER_NONE) {
1597
143k
        const Dav1dThreadPicture *const refp = &f->refp[b->ref[0]];
1598
143k
        const enum Filter2d filter_2d = b->filter2d;
1599
1600
143k
        if (imin(bw4, bh4) > 1 &&
1601
98.2k
            ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1602
97.0k
             (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1603
2.22k
        {
1604
2.22k
            res = warp_affine(t, dst, NULL, f->cur.stride[0], b_dim, 0, refp,
1605
2.22k
                              b->motion_mode == MM_WARP ? &t->warpmv :
1606
2.22k
                                  &f->frame_hdr->gmv[b->ref[0]]);
1607
2.22k
            if (res) return res;
1608
141k
        } else {
1609
141k
            res = mc(t, dst, NULL, f->cur.stride[0],
1610
141k
                     bw4, bh4, t->bx, t->by, 0, b->mv[0], refp, b->ref[0], filter_2d);
1611
141k
            if (res) return res;
1612
141k
            if (b->motion_mode == MM_OBMC) {
1613
24.1k
                res = obmc(t, dst, f->cur.stride[0], b_dim, 0, bx4, by4, w4, h4);
1614
24.1k
                if (res) return res;
1615
24.1k
            }
1616
141k
        }
1617
143k
        if (b->interintra_type) {
1618
5.60k
            pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1619
5.60k
            enum IntraPredMode m = b->interintra_mode == II_SMOOTH_PRED ?
1620
4.47k
                                   SMOOTH_PRED : b->interintra_mode;
1621
5.60k
            pixel *const tmp = bitfn(t->scratch.interintra);
1622
5.60k
            int angle = 0;
1623
5.60k
            const pixel *top_sb_edge = NULL;
1624
5.60k
            if (!(t->by & (f->sb_step - 1))) {
1625
1.74k
                top_sb_edge = f->ipred_edge[0];
1626
1.74k
                const int sby = t->by >> f->sb_shift;
1627
1.74k
                top_sb_edge += f->sb128w * 128 * (sby - 1);
1628
1.74k
            }
1629
5.60k
            m = bytefn(dav1d_prepare_intra_edges)(t->bx, t->bx > ts->tiling.col_start,
1630
5.60k
                                                  t->by, t->by > ts->tiling.row_start,
1631
5.60k
                                                  ts->tiling.col_end, ts->tiling.row_end,
1632
5.60k
                                                  0, dst, f->cur.stride[0], top_sb_edge,
1633
5.60k
                                                  m, &angle, bw4, bh4, 0, tl_edge
1634
5.60k
                                                  HIGHBD_CALL_SUFFIX);
1635
5.60k
            dsp->ipred.intra_pred[m](tmp, 4 * bw4 * sizeof(pixel),
1636
5.60k
                                     tl_edge, bw4 * 4, bh4 * 4, 0, 0, 0
1637
5.60k
                                     HIGHBD_CALL_SUFFIX);
1638
5.60k
            dsp->mc.blend(dst, f->cur.stride[0], tmp,
1639
5.60k
                          bw4 * 4, bh4 * 4, II_MASK(0, bs, b));
1640
5.60k
        }
1641
1642
143k
        if (!has_chroma) goto skip_inter_chroma_pred;
1643
1644
        // sub8x8 derivation
1645
130k
        int is_sub8x8 = bw4 == ss_hor || bh4 == ss_ver;
1646
130k
        refmvs_block *const *r;
1647
130k
        if (is_sub8x8) {
1648
6.20k
            assert(ss_hor == 1);
1649
6.20k
            r = &t->rt.r[(t->by & 31) + 5];
1650
6.20k
            if (bw4 == 1) is_sub8x8 &= r[0][t->bx - 1].ref.ref[0] > 0;
1651
6.20k
            if (bh4 == ss_ver) is_sub8x8 &= r[-1][t->bx].ref.ref[0] > 0;
1652
6.20k
            if (bw4 == 1 && bh4 == ss_ver)
1653
670
                is_sub8x8 &= r[-1][t->bx - 1].ref.ref[0] > 0;
1654
6.20k
        }
1655
1656
        // chroma prediction
1657
130k
        if (is_sub8x8) {
1658
6.17k
            assert(ss_hor == 1);
1659
6.17k
            ptrdiff_t h_off = 0, v_off = 0;
1660
6.17k
            if (bw4 == 1 && bh4 == ss_ver) {
1661
1.98k
                for (int pl = 0; pl < 2; pl++) {
1662
1.32k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1663
1.32k
                             NULL, f->cur.stride[1],
1664
1.32k
                             bw4, bh4, t->bx - 1, t->by - 1, 1 + pl,
1665
1.32k
                             r[-1][t->bx - 1].mv.mv[0],
1666
1.32k
                             &f->refp[r[-1][t->bx - 1].ref.ref[0] - 1],
1667
1.32k
                             r[-1][t->bx - 1].ref.ref[0] - 1,
1668
1.32k
                             t->frame_thread.pass != 2 ? t->tl_4x4_filter :
1669
1.32k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx - 1].filter2d);
1670
1.32k
                    if (res) return res;
1671
1.32k
                }
1672
660
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1673
660
                h_off = 2;
1674
660
            }
1675
6.17k
            if (bw4 == 1) {
1676
3.06k
                const enum Filter2d left_filter_2d =
1677
3.06k
                    dav1d_filter_2d[t->l.filter[1][by4]][t->l.filter[0][by4]];
1678
9.18k
                for (int pl = 0; pl < 2; pl++) {
1679
6.12k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + v_off, NULL,
1680
6.12k
                             f->cur.stride[1], bw4, bh4, t->bx - 1,
1681
6.12k
                             t->by, 1 + pl, r[0][t->bx - 1].mv.mv[0],
1682
6.12k
                             &f->refp[r[0][t->bx - 1].ref.ref[0] - 1],
1683
6.12k
                             r[0][t->bx - 1].ref.ref[0] - 1,
1684
6.12k
                             t->frame_thread.pass != 2 ? left_filter_2d :
1685
6.12k
                                 f->frame_thread.b[(t->by * f->b4_stride) + t->bx - 1].filter2d);
1686
6.12k
                    if (res) return res;
1687
6.12k
                }
1688
3.06k
                h_off = 2;
1689
3.06k
            }
1690
6.17k
            if (bh4 == ss_ver) {
1691
3.77k
                const enum Filter2d top_filter_2d =
1692
3.77k
                    dav1d_filter_2d[t->a->filter[1][bx4]][t->a->filter[0][bx4]];
1693
11.3k
                for (int pl = 0; pl < 2; pl++) {
1694
7.54k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off, NULL,
1695
7.54k
                             f->cur.stride[1], bw4, bh4, t->bx, t->by - 1,
1696
7.54k
                             1 + pl, r[-1][t->bx].mv.mv[0],
1697
7.54k
                             &f->refp[r[-1][t->bx].ref.ref[0] - 1],
1698
7.54k
                             r[-1][t->bx].ref.ref[0] - 1,
1699
7.54k
                             t->frame_thread.pass != 2 ? top_filter_2d :
1700
7.54k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx].filter2d);
1701
7.54k
                    if (res) return res;
1702
7.54k
                }
1703
3.77k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1704
3.77k
            }
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
124k
        } else {
1712
124k
            if (imin(cbw4, cbh4) > 1 &&
1713
71.7k
                ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1714
70.6k
                 (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1715
2.12k
            {
1716
6.36k
                for (int pl = 0; pl < 2; pl++) {
1717
4.24k
                    res = warp_affine(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff, NULL,
1718
4.24k
                                      f->cur.stride[1], b_dim, 1 + pl, refp,
1719
4.24k
                                      b->motion_mode == MM_WARP ? &t->warpmv :
1720
4.24k
                                          &f->frame_hdr->gmv[b->ref[0]]);
1721
4.24k
                    if (res) return res;
1722
4.24k
                }
1723
122k
            } else {
1724
366k
                for (int pl = 0; pl < 2; pl++) {
1725
244k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1726
244k
                             NULL, f->cur.stride[1],
1727
244k
                             bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1728
244k
                             t->bx & ~ss_hor, t->by & ~ss_ver,
1729
244k
                             1 + pl, b->mv[0], refp, b->ref[0], filter_2d);
1730
244k
                    if (res) return res;
1731
244k
                    if (b->motion_mode == MM_OBMC) {
1732
46.7k
                        res = obmc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1733
46.7k
                                   f->cur.stride[1], b_dim, 1 + pl, bx4, by4, w4, h4);
1734
46.7k
                        if (res) return res;
1735
46.7k
                    }
1736
244k
                }
1737
122k
            }
1738
124k
            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
5.10k
                const uint8_t *const ii_mask = II_MASK(chr_layout_idx, bs, b);
1743
1744
15.3k
                for (int pl = 0; pl < 2; pl++) {
1745
10.2k
                    pixel *const tmp = bitfn(t->scratch.interintra);
1746
10.2k
                    pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1747
10.2k
                    enum IntraPredMode m =
1748
10.2k
                        b->interintra_mode == II_SMOOTH_PRED ?
1749
8.24k
                        SMOOTH_PRED : b->interintra_mode;
1750
10.2k
                    int angle = 0;
1751
10.2k
                    pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1752
10.2k
                    const pixel *top_sb_edge = NULL;
1753
10.2k
                    if (!(t->by & (f->sb_step - 1))) {
1754
2.54k
                        top_sb_edge = f->ipred_edge[pl + 1];
1755
2.54k
                        const int sby = t->by >> f->sb_shift;
1756
2.54k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1757
2.54k
                    }
1758
10.2k
                    m = bytefn(dav1d_prepare_intra_edges)(t->bx >> ss_hor,
1759
10.2k
                                                          (t->bx >> ss_hor) >
1760
10.2k
                                                              (ts->tiling.col_start >> ss_hor),
1761
10.2k
                                                          t->by >> ss_ver,
1762
10.2k
                                                          (t->by >> ss_ver) >
1763
10.2k
                                                              (ts->tiling.row_start >> ss_ver),
1764
10.2k
                                                          ts->tiling.col_end >> ss_hor,
1765
10.2k
                                                          ts->tiling.row_end >> ss_ver,
1766
10.2k
                                                          0, uvdst, f->cur.stride[1],
1767
10.2k
                                                          top_sb_edge, m,
1768
10.2k
                                                          &angle, cbw4, cbh4, 0, tl_edge
1769
10.2k
                                                          HIGHBD_CALL_SUFFIX);
1770
10.2k
                    dsp->ipred.intra_pred[m](tmp, cbw4 * 4 * sizeof(pixel),
1771
10.2k
                                             tl_edge, cbw4 * 4, cbh4 * 4, 0, 0, 0
1772
10.2k
                                             HIGHBD_CALL_SUFFIX);
1773
10.2k
                    dsp->mc.blend(uvdst, f->cur.stride[1], tmp,
1774
10.2k
                                  cbw4 * 4, cbh4 * 4, ii_mask);
1775
10.2k
                }
1776
5.10k
            }
1777
124k
        }
1778
1779
143k
    skip_inter_chroma_pred: {}
1780
143k
        t->tl_4x4_filter = filter_2d;
1781
143k
    } else {
1782
14.2k
        const enum Filter2d filter_2d = b->filter2d;
1783
        // Maximum super block size is 128x128
1784
14.2k
        int16_t (*tmp)[128 * 128] = t->scratch.compinter;
1785
14.2k
        int jnt_weight;
1786
14.2k
        uint8_t *const seg_mask = t->scratch.seg_mask;
1787
14.2k
        const uint8_t *mask;
1788
1789
42.6k
        for (int i = 0; i < 2; i++) {
1790
28.4k
            const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1791
1792
28.4k
            if (b->inter_mode == GLOBALMV_GLOBALMV && f->gmv_warp_allowed[b->ref[i]]) {
1793
1.58k
                res = warp_affine(t, NULL, tmp[i], bw4 * 4, b_dim, 0, refp,
1794
1.58k
                                  &f->frame_hdr->gmv[b->ref[i]]);
1795
1.58k
                if (res) return res;
1796
26.8k
            } else {
1797
26.8k
                res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by, 0,
1798
26.8k
                         b->mv[i], refp, b->ref[i], filter_2d);
1799
26.8k
                if (res) return res;
1800
26.8k
            }
1801
28.4k
        }
1802
14.2k
        switch (b->comp_type) {
1803
11.1k
        case COMP_INTER_AVG:
1804
11.1k
            dsp->mc.avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1805
11.1k
                        bw4 * 4, bh4 * 4 HIGHBD_CALL_SUFFIX);
1806
11.1k
            break;
1807
856
        case COMP_INTER_WEIGHTED_AVG:
1808
856
            jnt_weight = f->jnt_weights[b->ref[0]][b->ref[1]];
1809
856
            dsp->mc.w_avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1810
856
                          bw4 * 4, bh4 * 4, jnt_weight HIGHBD_CALL_SUFFIX);
1811
856
            break;
1812
1.19k
        case COMP_INTER_SEG:
1813
1.19k
            dsp->mc.w_mask[chr_layout_idx](dst, f->cur.stride[0],
1814
1.19k
                                           tmp[b->mask_sign], tmp[!b->mask_sign],
1815
1.19k
                                           bw4 * 4, bh4 * 4, seg_mask,
1816
1.19k
                                           b->mask_sign HIGHBD_CALL_SUFFIX);
1817
1.19k
            mask = seg_mask;
1818
1.19k
            break;
1819
999
        case COMP_INTER_WEDGE:
1820
999
            mask = WEDGE_MASK(0, bs, 0, b->wedge_idx);
1821
999
            dsp->mc.mask(dst, f->cur.stride[0],
1822
999
                         tmp[b->mask_sign], tmp[!b->mask_sign],
1823
999
                         bw4 * 4, bh4 * 4, mask HIGHBD_CALL_SUFFIX);
1824
999
            if (has_chroma)
1825
735
                mask = WEDGE_MASK(chr_layout_idx, bs, b->mask_sign, b->wedge_idx);
1826
999
            break;
1827
14.2k
        }
1828
1829
        // chroma
1830
34.1k
        if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1831
68.2k
            for (int i = 0; i < 2; i++) {
1832
45.4k
                const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1833
45.4k
                if (b->inter_mode == GLOBALMV_GLOBALMV &&
1834
7.67k
                    imin(cbw4, cbh4) > 1 && f->gmv_warp_allowed[b->ref[i]])
1835
2.54k
                {
1836
2.54k
                    res = warp_affine(t, NULL, tmp[i], bw4 * 4 >> ss_hor,
1837
2.54k
                                      b_dim, 1 + pl,
1838
2.54k
                                      refp, &f->frame_hdr->gmv[b->ref[i]]);
1839
2.54k
                    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
45.4k
            }
1846
22.7k
            pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1847
22.7k
            switch (b->comp_type) {
1848
18.5k
            case COMP_INTER_AVG:
1849
18.5k
                dsp->mc.avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1850
18.5k
                            bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver
1851
18.5k
                            HIGHBD_CALL_SUFFIX);
1852
18.5k
                break;
1853
668
            case COMP_INTER_WEIGHTED_AVG:
1854
668
                dsp->mc.w_avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1855
668
                              bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, jnt_weight
1856
668
                              HIGHBD_CALL_SUFFIX);
1857
668
                break;
1858
1.47k
            case COMP_INTER_WEDGE:
1859
3.53k
            case COMP_INTER_SEG:
1860
3.53k
                dsp->mc.mask(uvdst, f->cur.stride[1],
1861
3.53k
                             tmp[b->mask_sign], tmp[!b->mask_sign],
1862
3.53k
                             bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, mask
1863
3.53k
                             HIGHBD_CALL_SUFFIX);
1864
3.53k
                break;
1865
22.7k
            }
1866
22.7k
        }
1867
14.2k
    }
1868
1869
187k
    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
187k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1880
1881
187k
    if (b->skip) {
1882
        // reset coef contexts
1883
114k
        BlockContext *const a = t->a;
1884
114k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
1885
114k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
1886
114k
        if (has_chroma) {
1887
91.4k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
1888
91.4k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
1889
91.4k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
1890
91.4k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
1891
91.4k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
1892
91.4k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
1893
91.4k
        }
1894
114k
        return 0;
1895
114k
    }
1896
1897
73.0k
    const TxfmInfo *const uvtx = &dav1d_txfm_dimensions[b->uvtx];
1898
73.0k
    const TxfmInfo *const ytx = &dav1d_txfm_dimensions[b->max_ytx];
1899
73.0k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
1900
1901
149k
    for (int init_y = 0; init_y < bh4; init_y += 16) {
1902
154k
        for (int init_x = 0; init_x < bw4; init_x += 16) {
1903
            // coefficient coding & inverse transforms
1904
78.7k
            int y_off = !!init_y, y;
1905
78.7k
            dst += PXSTRIDE(f->cur.stride[0]) * 4 * init_y;
1906
164k
            for (y = init_y, t->by += init_y; y < imin(h4, init_y + 16);
1907
86.1k
                 y += ytx->h, y_off++)
1908
86.1k
            {
1909
86.1k
                int x, x_off = !!init_x;
1910
204k
                for (x = init_x, t->bx += init_x; x < imin(w4, init_x + 16);
1911
118k
                     x += ytx->w, x_off++)
1912
118k
                {
1913
118k
                    read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
1914
118k
                                   x_off, y_off, &dst[x * 4]);
1915
118k
                    t->bx += ytx->w;
1916
118k
                }
1917
86.1k
                dst += PXSTRIDE(f->cur.stride[0]) * 4 * ytx->h;
1918
86.1k
                t->bx -= x;
1919
86.1k
                t->by += ytx->h;
1920
86.1k
            }
1921
78.7k
            dst -= PXSTRIDE(f->cur.stride[0]) * 4 * y;
1922
78.7k
            t->by -= y;
1923
1924
            // chroma coefs and inverse transform
1925
194k
            if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1926
129k
                pixel *uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff +
1927
129k
                    (PXSTRIDE(f->cur.stride[1]) * init_y * 4 >> ss_ver);
1928
129k
                for (y = init_y >> ss_ver, t->by += init_y;
1929
282k
                     y < imin(ch4, (init_y + 16) >> ss_ver); y += uvtx->h)
1930
152k
                {
1931
152k
                    int x;
1932
152k
                    for (x = init_x >> ss_hor, t->bx += init_x;
1933
379k
                         x < imin(cw4, (init_x + 16) >> ss_hor); x += uvtx->w)
1934
226k
                    {
1935
226k
                        coef *cf;
1936
226k
                        int eob;
1937
226k
                        enum TxfmType txtp;
1938
226k
                        if (t->frame_thread.pass) {
1939
226k
                            const int p = t->frame_thread.pass & 1;
1940
226k
                            const int cbi = *ts->frame_thread[p].cbi++;
1941
226k
                            cf = ts->frame_thread[p].cf;
1942
226k
                            ts->frame_thread[p].cf += uvtx->w * uvtx->h * 16;
1943
226k
                            eob  = cbi >> 5;
1944
226k
                            txtp = cbi & 0x1f;
1945
226k
                        } 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
226k
                        if (eob >= 0) {
1964
76.5k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1965
0
                                coef_dump(cf, uvtx->h * 4, uvtx->w * 4, 3, "dq");
1966
76.5k
                            dsp->itx.itxfm_add[b->uvtx]
1967
76.5k
                                              [txtp](&uvdst[4 * x],
1968
76.5k
                                                     f->cur.stride[1],
1969
76.5k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1970
76.5k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1971
0
                                hex_dump(&uvdst[4 * x], f->cur.stride[1],
1972
0
                                         uvtx->w * 4, uvtx->h * 4, "recon");
1973
76.5k
                        }
1974
226k
                        t->bx += uvtx->w << ss_hor;
1975
226k
                    }
1976
152k
                    uvdst += PXSTRIDE(f->cur.stride[1]) * 4 * uvtx->h;
1977
152k
                    t->bx -= x << ss_hor;
1978
152k
                    t->by += uvtx->h << ss_ver;
1979
152k
                }
1980
129k
                t->by -= y << ss_ver;
1981
129k
            }
1982
78.7k
        }
1983
76.1k
    }
1984
73.0k
    return 0;
1985
187k
}
dav1d_recon_b_inter_16bpc
Line
Count
Source
1559
135k
{
1560
135k
    Dav1dTileState *const ts = t->ts;
1561
135k
    const Dav1dFrameContext *const f = t->f;
1562
135k
    const Dav1dDSPContext *const dsp = f->dsp;
1563
135k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1564
135k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1565
135k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1566
135k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1567
135k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1568
135k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1569
135k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1570
135k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1571
108k
                           (bw4 > ss_hor || t->bx & 1) &&
1572
105k
                           (bh4 > ss_ver || t->by & 1);
1573
135k
    const int chr_layout_idx = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I400 ? 0 :
1574
135k
                               DAV1D_PIXEL_LAYOUT_I444 - f->cur.p.layout;
1575
135k
    int res;
1576
1577
    // prediction
1578
135k
    const int cbh4 = (bh4 + ss_ver) >> ss_ver, cbw4 = (bw4 + ss_hor) >> ss_hor;
1579
135k
    pixel *dst = ((pixel *) f->cur.data[0]) +
1580
135k
        4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1581
135k
    const ptrdiff_t uvdstoff =
1582
135k
        4 * ((t->bx >> ss_hor) + (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1583
135k
    if (IS_KEY_OR_INTRA(f->frame_hdr)) {
1584
        // intrabc
1585
30.7k
        assert(!f->frame_hdr->super_res.enabled);
1586
30.7k
        res = mc(t, dst, NULL, f->cur.stride[0], bw4, bh4, t->bx, t->by, 0,
1587
30.7k
                 b->mv[0], &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1588
30.7k
        if (res) return res;
1589
58.2k
        if (has_chroma) for (int pl = 1; pl < 3; pl++) {
1590
38.8k
            res = mc(t, ((pixel *)f->cur.data[pl]) + uvdstoff, NULL, f->cur.stride[1],
1591
38.8k
                     bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1592
38.8k
                     t->bx & ~ss_hor, t->by & ~ss_ver, pl, b->mv[0],
1593
38.8k
                     &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1594
38.8k
            if (res) return res;
1595
38.8k
        }
1596
104k
    } else if (b->comp_type == COMP_INTER_NONE) {
1597
89.1k
        const Dav1dThreadPicture *const refp = &f->refp[b->ref[0]];
1598
89.1k
        const enum Filter2d filter_2d = b->filter2d;
1599
1600
89.1k
        if (imin(bw4, bh4) > 1 &&
1601
55.5k
            ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1602
54.8k
             (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1603
2.03k
        {
1604
2.03k
            res = warp_affine(t, dst, NULL, f->cur.stride[0], b_dim, 0, refp,
1605
2.03k
                              b->motion_mode == MM_WARP ? &t->warpmv :
1606
2.03k
                                  &f->frame_hdr->gmv[b->ref[0]]);
1607
2.03k
            if (res) return res;
1608
87.1k
        } else {
1609
87.1k
            res = mc(t, dst, NULL, f->cur.stride[0],
1610
87.1k
                     bw4, bh4, t->bx, t->by, 0, b->mv[0], refp, b->ref[0], filter_2d);
1611
87.1k
            if (res) return res;
1612
87.1k
            if (b->motion_mode == MM_OBMC) {
1613
16.1k
                res = obmc(t, dst, f->cur.stride[0], b_dim, 0, bx4, by4, w4, h4);
1614
16.1k
                if (res) return res;
1615
16.1k
            }
1616
87.1k
        }
1617
89.1k
        if (b->interintra_type) {
1618
3.61k
            pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1619
3.61k
            enum IntraPredMode m = b->interintra_mode == II_SMOOTH_PRED ?
1620
2.96k
                                   SMOOTH_PRED : b->interintra_mode;
1621
3.61k
            pixel *const tmp = bitfn(t->scratch.interintra);
1622
3.61k
            int angle = 0;
1623
3.61k
            const pixel *top_sb_edge = NULL;
1624
3.61k
            if (!(t->by & (f->sb_step - 1))) {
1625
1.24k
                top_sb_edge = f->ipred_edge[0];
1626
1.24k
                const int sby = t->by >> f->sb_shift;
1627
1.24k
                top_sb_edge += f->sb128w * 128 * (sby - 1);
1628
1.24k
            }
1629
3.61k
            m = bytefn(dav1d_prepare_intra_edges)(t->bx, t->bx > ts->tiling.col_start,
1630
3.61k
                                                  t->by, t->by > ts->tiling.row_start,
1631
3.61k
                                                  ts->tiling.col_end, ts->tiling.row_end,
1632
3.61k
                                                  0, dst, f->cur.stride[0], top_sb_edge,
1633
3.61k
                                                  m, &angle, bw4, bh4, 0, tl_edge
1634
3.61k
                                                  HIGHBD_CALL_SUFFIX);
1635
3.61k
            dsp->ipred.intra_pred[m](tmp, 4 * bw4 * sizeof(pixel),
1636
3.61k
                                     tl_edge, bw4 * 4, bh4 * 4, 0, 0, 0
1637
3.61k
                                     HIGHBD_CALL_SUFFIX);
1638
3.61k
            dsp->mc.blend(dst, f->cur.stride[0], tmp,
1639
3.61k
                          bw4 * 4, bh4 * 4, II_MASK(0, bs, b));
1640
3.61k
        }
1641
1642
89.1k
        if (!has_chroma) goto skip_inter_chroma_pred;
1643
1644
        // sub8x8 derivation
1645
70.4k
        int is_sub8x8 = bw4 == ss_hor || bh4 == ss_ver;
1646
70.4k
        refmvs_block *const *r;
1647
70.4k
        if (is_sub8x8) {
1648
1.82k
            assert(ss_hor == 1);
1649
1.82k
            r = &t->rt.r[(t->by & 31) + 5];
1650
1.82k
            if (bw4 == 1) is_sub8x8 &= r[0][t->bx - 1].ref.ref[0] > 0;
1651
1.82k
            if (bh4 == ss_ver) is_sub8x8 &= r[-1][t->bx].ref.ref[0] > 0;
1652
1.82k
            if (bw4 == 1 && bh4 == ss_ver)
1653
275
                is_sub8x8 &= r[-1][t->bx - 1].ref.ref[0] > 0;
1654
1.82k
        }
1655
1656
        // chroma prediction
1657
70.4k
        if (is_sub8x8) {
1658
1.74k
            assert(ss_hor == 1);
1659
1.74k
            ptrdiff_t h_off = 0, v_off = 0;
1660
1.74k
            if (bw4 == 1 && bh4 == ss_ver) {
1661
765
                for (int pl = 0; pl < 2; pl++) {
1662
510
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1663
510
                             NULL, f->cur.stride[1],
1664
510
                             bw4, bh4, t->bx - 1, t->by - 1, 1 + pl,
1665
510
                             r[-1][t->bx - 1].mv.mv[0],
1666
510
                             &f->refp[r[-1][t->bx - 1].ref.ref[0] - 1],
1667
510
                             r[-1][t->bx - 1].ref.ref[0] - 1,
1668
510
                             t->frame_thread.pass != 2 ? t->tl_4x4_filter :
1669
510
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx - 1].filter2d);
1670
510
                    if (res) return res;
1671
510
                }
1672
255
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1673
255
                h_off = 2;
1674
255
            }
1675
1.74k
            if (bw4 == 1) {
1676
848
                const enum Filter2d left_filter_2d =
1677
848
                    dav1d_filter_2d[t->l.filter[1][by4]][t->l.filter[0][by4]];
1678
2.54k
                for (int pl = 0; pl < 2; pl++) {
1679
1.69k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + v_off, NULL,
1680
1.69k
                             f->cur.stride[1], bw4, bh4, t->bx - 1,
1681
1.69k
                             t->by, 1 + pl, r[0][t->bx - 1].mv.mv[0],
1682
1.69k
                             &f->refp[r[0][t->bx - 1].ref.ref[0] - 1],
1683
1.69k
                             r[0][t->bx - 1].ref.ref[0] - 1,
1684
1.69k
                             t->frame_thread.pass != 2 ? left_filter_2d :
1685
1.69k
                                 f->frame_thread.b[(t->by * f->b4_stride) + t->bx - 1].filter2d);
1686
1.69k
                    if (res) return res;
1687
1.69k
                }
1688
848
                h_off = 2;
1689
848
            }
1690
1.74k
            if (bh4 == ss_ver) {
1691
1.14k
                const enum Filter2d top_filter_2d =
1692
1.14k
                    dav1d_filter_2d[t->a->filter[1][bx4]][t->a->filter[0][bx4]];
1693
3.44k
                for (int pl = 0; pl < 2; pl++) {
1694
2.29k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off, NULL,
1695
2.29k
                             f->cur.stride[1], bw4, bh4, t->bx, t->by - 1,
1696
2.29k
                             1 + pl, r[-1][t->bx].mv.mv[0],
1697
2.29k
                             &f->refp[r[-1][t->bx].ref.ref[0] - 1],
1698
2.29k
                             r[-1][t->bx].ref.ref[0] - 1,
1699
2.29k
                             t->frame_thread.pass != 2 ? top_filter_2d :
1700
2.29k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx].filter2d);
1701
2.29k
                    if (res) return res;
1702
2.29k
                }
1703
1.14k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1704
1.14k
            }
1705
5.22k
            for (int pl = 0; pl < 2; pl++) {
1706
3.48k
                res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off + v_off, NULL, f->cur.stride[1],
1707
3.48k
                         bw4, bh4, t->bx, t->by, 1 + pl, b->mv[0],
1708
3.48k
                         refp, b->ref[0], filter_2d);
1709
3.48k
                if (res) return res;
1710
3.48k
            }
1711
68.7k
        } else {
1712
68.7k
            if (imin(cbw4, cbh4) > 1 &&
1713
40.3k
                ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1714
39.6k
                 (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1715
1.87k
            {
1716
5.63k
                for (int pl = 0; pl < 2; pl++) {
1717
3.75k
                    res = warp_affine(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff, NULL,
1718
3.75k
                                      f->cur.stride[1], b_dim, 1 + pl, refp,
1719
3.75k
                                      b->motion_mode == MM_WARP ? &t->warpmv :
1720
3.75k
                                          &f->frame_hdr->gmv[b->ref[0]]);
1721
3.75k
                    if (res) return res;
1722
3.75k
                }
1723
66.8k
            } else {
1724
200k
                for (int pl = 0; pl < 2; pl++) {
1725
133k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1726
133k
                             NULL, f->cur.stride[1],
1727
133k
                             bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1728
133k
                             t->bx & ~ss_hor, t->by & ~ss_ver,
1729
133k
                             1 + pl, b->mv[0], refp, b->ref[0], filter_2d);
1730
133k
                    if (res) return res;
1731
133k
                    if (b->motion_mode == MM_OBMC) {
1732
27.2k
                        res = obmc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1733
27.2k
                                   f->cur.stride[1], b_dim, 1 + pl, bx4, by4, w4, h4);
1734
27.2k
                        if (res) return res;
1735
27.2k
                    }
1736
133k
                }
1737
66.8k
            }
1738
68.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
3.42k
                const uint8_t *const ii_mask = II_MASK(chr_layout_idx, bs, b);
1743
1744
10.2k
                for (int pl = 0; pl < 2; pl++) {
1745
6.85k
                    pixel *const tmp = bitfn(t->scratch.interintra);
1746
6.85k
                    pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1747
6.85k
                    enum IntraPredMode m =
1748
6.85k
                        b->interintra_mode == II_SMOOTH_PRED ?
1749
5.65k
                        SMOOTH_PRED : b->interintra_mode;
1750
6.85k
                    int angle = 0;
1751
6.85k
                    pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1752
6.85k
                    const pixel *top_sb_edge = NULL;
1753
6.85k
                    if (!(t->by & (f->sb_step - 1))) {
1754
2.16k
                        top_sb_edge = f->ipred_edge[pl + 1];
1755
2.16k
                        const int sby = t->by >> f->sb_shift;
1756
2.16k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1757
2.16k
                    }
1758
6.85k
                    m = bytefn(dav1d_prepare_intra_edges)(t->bx >> ss_hor,
1759
6.85k
                                                          (t->bx >> ss_hor) >
1760
6.85k
                                                              (ts->tiling.col_start >> ss_hor),
1761
6.85k
                                                          t->by >> ss_ver,
1762
6.85k
                                                          (t->by >> ss_ver) >
1763
6.85k
                                                              (ts->tiling.row_start >> ss_ver),
1764
6.85k
                                                          ts->tiling.col_end >> ss_hor,
1765
6.85k
                                                          ts->tiling.row_end >> ss_ver,
1766
6.85k
                                                          0, uvdst, f->cur.stride[1],
1767
6.85k
                                                          top_sb_edge, m,
1768
6.85k
                                                          &angle, cbw4, cbh4, 0, tl_edge
1769
6.85k
                                                          HIGHBD_CALL_SUFFIX);
1770
6.85k
                    dsp->ipred.intra_pred[m](tmp, cbw4 * 4 * sizeof(pixel),
1771
6.85k
                                             tl_edge, cbw4 * 4, cbh4 * 4, 0, 0, 0
1772
6.85k
                                             HIGHBD_CALL_SUFFIX);
1773
6.85k
                    dsp->mc.blend(uvdst, f->cur.stride[1], tmp,
1774
6.85k
                                  cbw4 * 4, cbh4 * 4, ii_mask);
1775
6.85k
                }
1776
3.42k
            }
1777
68.7k
        }
1778
1779
89.1k
    skip_inter_chroma_pred: {}
1780
89.1k
        t->tl_4x4_filter = filter_2d;
1781
89.1k
    } else {
1782
15.5k
        const enum Filter2d filter_2d = b->filter2d;
1783
        // Maximum super block size is 128x128
1784
15.5k
        int16_t (*tmp)[128 * 128] = t->scratch.compinter;
1785
15.5k
        int jnt_weight;
1786
15.5k
        uint8_t *const seg_mask = t->scratch.seg_mask;
1787
15.5k
        const uint8_t *mask;
1788
1789
46.5k
        for (int i = 0; i < 2; i++) {
1790
31.0k
            const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1791
1792
31.0k
            if (b->inter_mode == GLOBALMV_GLOBALMV && f->gmv_warp_allowed[b->ref[i]]) {
1793
2.53k
                res = warp_affine(t, NULL, tmp[i], bw4 * 4, b_dim, 0, refp,
1794
2.53k
                                  &f->frame_hdr->gmv[b->ref[i]]);
1795
2.53k
                if (res) return res;
1796
28.5k
            } else {
1797
28.5k
                res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by, 0,
1798
28.5k
                         b->mv[i], refp, b->ref[i], filter_2d);
1799
28.5k
                if (res) return res;
1800
28.5k
            }
1801
31.0k
        }
1802
15.5k
        switch (b->comp_type) {
1803
12.1k
        case COMP_INTER_AVG:
1804
12.1k
            dsp->mc.avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1805
12.1k
                        bw4 * 4, bh4 * 4 HIGHBD_CALL_SUFFIX);
1806
12.1k
            break;
1807
1.21k
        case COMP_INTER_WEIGHTED_AVG:
1808
1.21k
            jnt_weight = f->jnt_weights[b->ref[0]][b->ref[1]];
1809
1.21k
            dsp->mc.w_avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1810
1.21k
                          bw4 * 4, bh4 * 4, jnt_weight HIGHBD_CALL_SUFFIX);
1811
1.21k
            break;
1812
1.43k
        case COMP_INTER_SEG:
1813
1.43k
            dsp->mc.w_mask[chr_layout_idx](dst, f->cur.stride[0],
1814
1.43k
                                           tmp[b->mask_sign], tmp[!b->mask_sign],
1815
1.43k
                                           bw4 * 4, bh4 * 4, seg_mask,
1816
1.43k
                                           b->mask_sign HIGHBD_CALL_SUFFIX);
1817
1.43k
            mask = seg_mask;
1818
1.43k
            break;
1819
722
        case COMP_INTER_WEDGE:
1820
722
            mask = WEDGE_MASK(0, bs, 0, b->wedge_idx);
1821
722
            dsp->mc.mask(dst, f->cur.stride[0],
1822
722
                         tmp[b->mask_sign], tmp[!b->mask_sign],
1823
722
                         bw4 * 4, bh4 * 4, mask HIGHBD_CALL_SUFFIX);
1824
722
            if (has_chroma)
1825
428
                mask = WEDGE_MASK(chr_layout_idx, bs, b->mask_sign, b->wedge_idx);
1826
722
            break;
1827
15.5k
        }
1828
1829
        // chroma
1830
37.2k
        if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1831
74.5k
            for (int i = 0; i < 2; i++) {
1832
49.7k
                const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1833
49.7k
                if (b->inter_mode == GLOBALMV_GLOBALMV &&
1834
9.18k
                    imin(cbw4, cbh4) > 1 && f->gmv_warp_allowed[b->ref[i]])
1835
2.68k
                {
1836
2.68k
                    res = warp_affine(t, NULL, tmp[i], bw4 * 4 >> ss_hor,
1837
2.68k
                                      b_dim, 1 + pl,
1838
2.68k
                                      refp, &f->frame_hdr->gmv[b->ref[i]]);
1839
2.68k
                    if (res) return res;
1840
47.0k
                } else {
1841
47.0k
                    res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by,
1842
47.0k
                             1 + pl, b->mv[i], refp, b->ref[i], filter_2d);
1843
47.0k
                    if (res) return res;
1844
47.0k
                }
1845
49.7k
            }
1846
24.8k
            pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1847
24.8k
            switch (b->comp_type) {
1848
19.6k
            case COMP_INTER_AVG:
1849
19.6k
                dsp->mc.avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1850
19.6k
                            bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver
1851
19.6k
                            HIGHBD_CALL_SUFFIX);
1852
19.6k
                break;
1853
2.05k
            case COMP_INTER_WEIGHTED_AVG:
1854
2.05k
                dsp->mc.w_avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1855
2.05k
                              bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, jnt_weight
1856
2.05k
                              HIGHBD_CALL_SUFFIX);
1857
2.05k
                break;
1858
856
            case COMP_INTER_WEDGE:
1859
3.19k
            case COMP_INTER_SEG:
1860
3.19k
                dsp->mc.mask(uvdst, f->cur.stride[1],
1861
3.19k
                             tmp[b->mask_sign], tmp[!b->mask_sign],
1862
3.19k
                             bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, mask
1863
3.19k
                             HIGHBD_CALL_SUFFIX);
1864
3.19k
                break;
1865
24.8k
            }
1866
24.8k
        }
1867
15.5k
    }
1868
1869
135k
    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
135k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1880
1881
135k
    if (b->skip) {
1882
        // reset coef contexts
1883
62.4k
        BlockContext *const a = t->a;
1884
62.4k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
1885
62.4k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
1886
62.4k
        if (has_chroma) {
1887
49.4k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
1888
49.4k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
1889
49.4k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
1890
49.4k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
1891
49.4k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
1892
49.4k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
1893
49.4k
        }
1894
62.4k
        return 0;
1895
62.4k
    }
1896
1897
73.0k
    const TxfmInfo *const uvtx = &dav1d_txfm_dimensions[b->uvtx];
1898
73.0k
    const TxfmInfo *const ytx = &dav1d_txfm_dimensions[b->max_ytx];
1899
73.0k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
1900
1901
149k
    for (int init_y = 0; init_y < bh4; init_y += 16) {
1902
154k
        for (int init_x = 0; init_x < bw4; init_x += 16) {
1903
            // coefficient coding & inverse transforms
1904
78.1k
            int y_off = !!init_y, y;
1905
78.1k
            dst += PXSTRIDE(f->cur.stride[0]) * 4 * init_y;
1906
165k
            for (y = init_y, t->by += init_y; y < imin(h4, init_y + 16);
1907
87.2k
                 y += ytx->h, y_off++)
1908
87.2k
            {
1909
87.2k
                int x, x_off = !!init_x;
1910
211k
                for (x = init_x, t->bx += init_x; x < imin(w4, init_x + 16);
1911
124k
                     x += ytx->w, x_off++)
1912
124k
                {
1913
124k
                    read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
1914
124k
                                   x_off, y_off, &dst[x * 4]);
1915
124k
                    t->bx += ytx->w;
1916
124k
                }
1917
87.2k
                dst += PXSTRIDE(f->cur.stride[0]) * 4 * ytx->h;
1918
87.2k
                t->bx -= x;
1919
87.2k
                t->by += ytx->h;
1920
87.2k
            }
1921
78.1k
            dst -= PXSTRIDE(f->cur.stride[0]) * 4 * y;
1922
78.1k
            t->by -= y;
1923
1924
            // chroma coefs and inverse transform
1925
172k
            if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1926
114k
                pixel *uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff +
1927
114k
                    (PXSTRIDE(f->cur.stride[1]) * init_y * 4 >> ss_ver);
1928
114k
                for (y = init_y >> ss_ver, t->by += init_y;
1929
250k
                     y < imin(ch4, (init_y + 16) >> ss_ver); y += uvtx->h)
1930
135k
                {
1931
135k
                    int x;
1932
135k
                    for (x = init_x >> ss_hor, t->bx += init_x;
1933
348k
                         x < imin(cw4, (init_x + 16) >> ss_hor); x += uvtx->w)
1934
212k
                    {
1935
212k
                        coef *cf;
1936
212k
                        int eob;
1937
212k
                        enum TxfmType txtp;
1938
212k
                        if (t->frame_thread.pass) {
1939
212k
                            const int p = t->frame_thread.pass & 1;
1940
212k
                            const int cbi = *ts->frame_thread[p].cbi++;
1941
212k
                            cf = ts->frame_thread[p].cf;
1942
212k
                            ts->frame_thread[p].cf += uvtx->w * uvtx->h * 16;
1943
212k
                            eob  = cbi >> 5;
1944
212k
                            txtp = cbi & 0x1f;
1945
212k
                        } 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
212k
                        if (eob >= 0) {
1964
78.3k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1965
0
                                coef_dump(cf, uvtx->h * 4, uvtx->w * 4, 3, "dq");
1966
78.3k
                            dsp->itx.itxfm_add[b->uvtx]
1967
78.3k
                                              [txtp](&uvdst[4 * x],
1968
78.3k
                                                     f->cur.stride[1],
1969
78.3k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1970
78.3k
                            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
78.3k
                        }
1974
212k
                        t->bx += uvtx->w << ss_hor;
1975
212k
                    }
1976
135k
                    uvdst += PXSTRIDE(f->cur.stride[1]) * 4 * uvtx->h;
1977
135k
                    t->bx -= x << ss_hor;
1978
135k
                    t->by += uvtx->h << ss_ver;
1979
135k
                }
1980
114k
                t->by -= y << ss_ver;
1981
114k
            }
1982
78.1k
        }
1983
76.6k
    }
1984
73.0k
    return 0;
1985
135k
}
1986
1987
115k
void bytefn(dav1d_filter_sbrow_deblock_cols)(Dav1dFrameContext *const f, const int sby) {
1988
115k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK) ||
1989
115k
        (!f->frame_hdr->loopfilter.level_y[0] && !f->frame_hdr->loopfilter.level_y[1]))
1990
0
    {
1991
0
        return;
1992
0
    }
1993
115k
    const int y = sby * f->sb_step * 4;
1994
115k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1995
115k
    pixel *const p[3] = {
1996
115k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
1997
115k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
1998
115k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
1999
115k
    };
2000
115k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2001
115k
    bytefn(dav1d_loopfilter_sbrow_cols)(f, p, mask, sby,
2002
115k
                                        f->lf.start_of_tile_row[sby]);
2003
115k
}
dav1d_filter_sbrow_deblock_cols_8bpc
Line
Count
Source
1987
64.4k
void bytefn(dav1d_filter_sbrow_deblock_cols)(Dav1dFrameContext *const f, const int sby) {
1988
64.4k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK) ||
1989
64.4k
        (!f->frame_hdr->loopfilter.level_y[0] && !f->frame_hdr->loopfilter.level_y[1]))
1990
0
    {
1991
0
        return;
1992
0
    }
1993
64.4k
    const int y = sby * f->sb_step * 4;
1994
64.4k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1995
64.4k
    pixel *const p[3] = {
1996
64.4k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
1997
64.4k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
1998
64.4k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
1999
64.4k
    };
2000
64.4k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2001
64.4k
    bytefn(dav1d_loopfilter_sbrow_cols)(f, p, mask, sby,
2002
64.4k
                                        f->lf.start_of_tile_row[sby]);
2003
64.4k
}
dav1d_filter_sbrow_deblock_cols_16bpc
Line
Count
Source
1987
50.7k
void bytefn(dav1d_filter_sbrow_deblock_cols)(Dav1dFrameContext *const f, const int sby) {
1988
50.7k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK) ||
1989
50.7k
        (!f->frame_hdr->loopfilter.level_y[0] && !f->frame_hdr->loopfilter.level_y[1]))
1990
0
    {
1991
0
        return;
1992
0
    }
1993
50.7k
    const int y = sby * f->sb_step * 4;
1994
50.7k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1995
50.7k
    pixel *const p[3] = {
1996
50.7k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
1997
50.7k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
1998
50.7k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
1999
50.7k
    };
2000
50.7k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2001
50.7k
    bytefn(dav1d_loopfilter_sbrow_cols)(f, p, mask, sby,
2002
50.7k
                                        f->lf.start_of_tile_row[sby]);
2003
50.7k
}
2004
2005
130k
void bytefn(dav1d_filter_sbrow_deblock_rows)(Dav1dFrameContext *const f, const int sby) {
2006
130k
    const int y = sby * f->sb_step * 4;
2007
130k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2008
130k
    pixel *const p[3] = {
2009
130k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2010
130k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2011
130k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2012
130k
    };
2013
130k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2014
130k
    if (f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK &&
2015
130k
        (f->frame_hdr->loopfilter.level_y[0] || f->frame_hdr->loopfilter.level_y[1]))
2016
115k
    {
2017
115k
        bytefn(dav1d_loopfilter_sbrow_rows)(f, p, mask, sby);
2018
115k
    }
2019
130k
    if (f->seq_hdr->cdef || f->lf.restore_planes) {
2020
        // Store loop filtered pixels required by CDEF / LR
2021
106k
        bytefn(dav1d_copy_lpf)(f, p, sby);
2022
106k
    }
2023
130k
}
dav1d_filter_sbrow_deblock_rows_8bpc
Line
Count
Source
2005
71.2k
void bytefn(dav1d_filter_sbrow_deblock_rows)(Dav1dFrameContext *const f, const int sby) {
2006
71.2k
    const int y = sby * f->sb_step * 4;
2007
71.2k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2008
71.2k
    pixel *const p[3] = {
2009
71.2k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2010
71.2k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2011
71.2k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2012
71.2k
    };
2013
71.2k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2014
71.2k
    if (f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK &&
2015
71.2k
        (f->frame_hdr->loopfilter.level_y[0] || f->frame_hdr->loopfilter.level_y[1]))
2016
64.3k
    {
2017
64.3k
        bytefn(dav1d_loopfilter_sbrow_rows)(f, p, mask, sby);
2018
64.3k
    }
2019
71.2k
    if (f->seq_hdr->cdef || f->lf.restore_planes) {
2020
        // Store loop filtered pixels required by CDEF / LR
2021
54.2k
        bytefn(dav1d_copy_lpf)(f, p, sby);
2022
54.2k
    }
2023
71.2k
}
dav1d_filter_sbrow_deblock_rows_16bpc
Line
Count
Source
2005
58.7k
void bytefn(dav1d_filter_sbrow_deblock_rows)(Dav1dFrameContext *const f, const int sby) {
2006
58.7k
    const int y = sby * f->sb_step * 4;
2007
58.7k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2008
58.7k
    pixel *const p[3] = {
2009
58.7k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2010
58.7k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2011
58.7k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2012
58.7k
    };
2013
58.7k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2014
58.7k
    if (f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK &&
2015
58.7k
        (f->frame_hdr->loopfilter.level_y[0] || f->frame_hdr->loopfilter.level_y[1]))
2016
50.7k
    {
2017
50.7k
        bytefn(dav1d_loopfilter_sbrow_rows)(f, p, mask, sby);
2018
50.7k
    }
2019
58.7k
    if (f->seq_hdr->cdef || f->lf.restore_planes) {
2020
        // Store loop filtered pixels required by CDEF / LR
2021
52.2k
        bytefn(dav1d_copy_lpf)(f, p, sby);
2022
52.2k
    }
2023
58.7k
}
2024
2025
70.9k
void bytefn(dav1d_filter_sbrow_cdef)(Dav1dTaskContext *const tc, const int sby) {
2026
70.9k
    const Dav1dFrameContext *const f = tc->f;
2027
70.9k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_CDEF)) return;
2028
70.9k
    const int sbsz = f->sb_step;
2029
70.9k
    const int y = sby * sbsz * 4;
2030
70.9k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2031
70.9k
    pixel *const p[3] = {
2032
70.9k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2033
70.9k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2034
70.9k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2035
70.9k
    };
2036
70.9k
    Av1Filter *prev_mask = f->lf.mask + ((sby - 1) >> !f->seq_hdr->sb128) * f->sb128w;
2037
70.9k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2038
70.9k
    const int start = sby * sbsz;
2039
70.9k
    if (sby) {
2040
27.0k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2041
27.0k
        pixel *p_up[3] = {
2042
27.0k
            p[0] - 8 * PXSTRIDE(f->cur.stride[0]),
2043
27.0k
            p[1] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2044
27.0k
            p[2] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2045
27.0k
        };
2046
27.0k
        bytefn(dav1d_cdef_brow)(tc, p_up, prev_mask, start - 2, start, 1, sby);
2047
27.0k
    }
2048
70.9k
    const int n_blks = sbsz - 2 * (sby + 1 < f->sbh);
2049
70.9k
    const int end = imin(start + n_blks, f->bh);
2050
70.9k
    bytefn(dav1d_cdef_brow)(tc, p, mask, start, end, 0, sby);
2051
70.9k
}
dav1d_filter_sbrow_cdef_8bpc
Line
Count
Source
2025
33.4k
void bytefn(dav1d_filter_sbrow_cdef)(Dav1dTaskContext *const tc, const int sby) {
2026
33.4k
    const Dav1dFrameContext *const f = tc->f;
2027
33.4k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_CDEF)) return;
2028
33.4k
    const int sbsz = f->sb_step;
2029
33.4k
    const int y = sby * sbsz * 4;
2030
33.4k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2031
33.4k
    pixel *const p[3] = {
2032
33.4k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2033
33.4k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2034
33.4k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2035
33.4k
    };
2036
33.4k
    Av1Filter *prev_mask = f->lf.mask + ((sby - 1) >> !f->seq_hdr->sb128) * f->sb128w;
2037
33.4k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2038
33.4k
    const int start = sby * sbsz;
2039
33.4k
    if (sby) {
2040
12.4k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2041
12.4k
        pixel *p_up[3] = {
2042
12.4k
            p[0] - 8 * PXSTRIDE(f->cur.stride[0]),
2043
12.4k
            p[1] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2044
12.4k
            p[2] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2045
12.4k
        };
2046
12.4k
        bytefn(dav1d_cdef_brow)(tc, p_up, prev_mask, start - 2, start, 1, sby);
2047
12.4k
    }
2048
33.4k
    const int n_blks = sbsz - 2 * (sby + 1 < f->sbh);
2049
33.4k
    const int end = imin(start + n_blks, f->bh);
2050
33.4k
    bytefn(dav1d_cdef_brow)(tc, p, mask, start, end, 0, sby);
2051
33.4k
}
dav1d_filter_sbrow_cdef_16bpc
Line
Count
Source
2025
37.4k
void bytefn(dav1d_filter_sbrow_cdef)(Dav1dTaskContext *const tc, const int sby) {
2026
37.4k
    const Dav1dFrameContext *const f = tc->f;
2027
37.4k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_CDEF)) return;
2028
37.4k
    const int sbsz = f->sb_step;
2029
37.4k
    const int y = sby * sbsz * 4;
2030
37.4k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2031
37.4k
    pixel *const p[3] = {
2032
37.4k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2033
37.4k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2034
37.4k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2035
37.4k
    };
2036
37.4k
    Av1Filter *prev_mask = f->lf.mask + ((sby - 1) >> !f->seq_hdr->sb128) * f->sb128w;
2037
37.4k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2038
37.4k
    const int start = sby * sbsz;
2039
37.4k
    if (sby) {
2040
14.6k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2041
14.6k
        pixel *p_up[3] = {
2042
14.6k
            p[0] - 8 * PXSTRIDE(f->cur.stride[0]),
2043
14.6k
            p[1] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2044
14.6k
            p[2] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2045
14.6k
        };
2046
14.6k
        bytefn(dav1d_cdef_brow)(tc, p_up, prev_mask, start - 2, start, 1, sby);
2047
14.6k
    }
2048
37.4k
    const int n_blks = sbsz - 2 * (sby + 1 < f->sbh);
2049
37.4k
    const int end = imin(start + n_blks, f->bh);
2050
37.4k
    bytefn(dav1d_cdef_brow)(tc, p, mask, start, end, 0, sby);
2051
37.4k
}
2052
2053
25.5k
void bytefn(dav1d_filter_sbrow_resize)(Dav1dFrameContext *const f, const int sby) {
2054
25.5k
    const int sbsz = f->sb_step;
2055
25.5k
    const int y = sby * sbsz * 4;
2056
25.5k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2057
25.5k
    const pixel *const p[3] = {
2058
25.5k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2059
25.5k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2060
25.5k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2061
25.5k
    };
2062
25.5k
    pixel *const sr_p[3] = {
2063
25.5k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2064
25.5k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2065
25.5k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2066
25.5k
    };
2067
25.5k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400;
2068
93.5k
    for (int pl = 0; pl < 1 + 2 * has_chroma; pl++) {
2069
67.9k
        const int ss_ver = pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2070
67.9k
        const int h_start = 8 * !!sby >> ss_ver;
2071
67.9k
        const ptrdiff_t dst_stride = f->sr_cur.p.stride[!!pl];
2072
67.9k
        pixel *dst = sr_p[pl] - h_start * PXSTRIDE(dst_stride);
2073
67.9k
        const ptrdiff_t src_stride = f->cur.stride[!!pl];
2074
67.9k
        const pixel *src = p[pl] - h_start * PXSTRIDE(src_stride);
2075
67.9k
        const int h_end = 4 * (sbsz - 2 * (sby + 1 < f->sbh)) >> ss_ver;
2076
67.9k
        const int ss_hor = pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2077
67.9k
        const int dst_w = (f->sr_cur.p.p.w + ss_hor) >> ss_hor;
2078
67.9k
        const int src_w = (4 * f->bw + ss_hor) >> ss_hor;
2079
67.9k
        const int img_h = (f->cur.p.h - sbsz * 4 * sby + ss_ver) >> ss_ver;
2080
2081
67.9k
        f->dsp->mc.resize(dst, dst_stride, src, src_stride, dst_w,
2082
67.9k
                          imin(img_h, h_end) + h_start, src_w,
2083
67.9k
                          f->resize_step[!!pl], f->resize_start[!!pl]
2084
67.9k
                          HIGHBD_CALL_SUFFIX);
2085
67.9k
    }
2086
25.5k
}
dav1d_filter_sbrow_resize_8bpc
Line
Count
Source
2053
12.5k
void bytefn(dav1d_filter_sbrow_resize)(Dav1dFrameContext *const f, const int sby) {
2054
12.5k
    const int sbsz = f->sb_step;
2055
12.5k
    const int y = sby * sbsz * 4;
2056
12.5k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2057
12.5k
    const pixel *const p[3] = {
2058
12.5k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2059
12.5k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2060
12.5k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2061
12.5k
    };
2062
12.5k
    pixel *const sr_p[3] = {
2063
12.5k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2064
12.5k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2065
12.5k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2066
12.5k
    };
2067
12.5k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400;
2068
44.6k
    for (int pl = 0; pl < 1 + 2 * has_chroma; pl++) {
2069
32.0k
        const int ss_ver = pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2070
32.0k
        const int h_start = 8 * !!sby >> ss_ver;
2071
32.0k
        const ptrdiff_t dst_stride = f->sr_cur.p.stride[!!pl];
2072
32.0k
        pixel *dst = sr_p[pl] - h_start * PXSTRIDE(dst_stride);
2073
32.0k
        const ptrdiff_t src_stride = f->cur.stride[!!pl];
2074
32.0k
        const pixel *src = p[pl] - h_start * PXSTRIDE(src_stride);
2075
32.0k
        const int h_end = 4 * (sbsz - 2 * (sby + 1 < f->sbh)) >> ss_ver;
2076
32.0k
        const int ss_hor = pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2077
32.0k
        const int dst_w = (f->sr_cur.p.p.w + ss_hor) >> ss_hor;
2078
32.0k
        const int src_w = (4 * f->bw + ss_hor) >> ss_hor;
2079
32.0k
        const int img_h = (f->cur.p.h - sbsz * 4 * sby + ss_ver) >> ss_ver;
2080
2081
32.0k
        f->dsp->mc.resize(dst, dst_stride, src, src_stride, dst_w,
2082
32.0k
                          imin(img_h, h_end) + h_start, src_w,
2083
32.0k
                          f->resize_step[!!pl], f->resize_start[!!pl]
2084
32.0k
                          HIGHBD_CALL_SUFFIX);
2085
32.0k
    }
2086
12.5k
}
dav1d_filter_sbrow_resize_16bpc
Line
Count
Source
2053
12.9k
void bytefn(dav1d_filter_sbrow_resize)(Dav1dFrameContext *const f, const int sby) {
2054
12.9k
    const int sbsz = f->sb_step;
2055
12.9k
    const int y = sby * sbsz * 4;
2056
12.9k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2057
12.9k
    const pixel *const p[3] = {
2058
12.9k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2059
12.9k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2060
12.9k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2061
12.9k
    };
2062
12.9k
    pixel *const sr_p[3] = {
2063
12.9k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2064
12.9k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2065
12.9k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2066
12.9k
    };
2067
12.9k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400;
2068
48.9k
    for (int pl = 0; pl < 1 + 2 * has_chroma; pl++) {
2069
35.9k
        const int ss_ver = pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2070
35.9k
        const int h_start = 8 * !!sby >> ss_ver;
2071
35.9k
        const ptrdiff_t dst_stride = f->sr_cur.p.stride[!!pl];
2072
35.9k
        pixel *dst = sr_p[pl] - h_start * PXSTRIDE(dst_stride);
2073
35.9k
        const ptrdiff_t src_stride = f->cur.stride[!!pl];
2074
35.9k
        const pixel *src = p[pl] - h_start * PXSTRIDE(src_stride);
2075
35.9k
        const int h_end = 4 * (sbsz - 2 * (sby + 1 < f->sbh)) >> ss_ver;
2076
35.9k
        const int ss_hor = pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2077
35.9k
        const int dst_w = (f->sr_cur.p.p.w + ss_hor) >> ss_hor;
2078
35.9k
        const int src_w = (4 * f->bw + ss_hor) >> ss_hor;
2079
35.9k
        const int img_h = (f->cur.p.h - sbsz * 4 * sby + ss_ver) >> ss_ver;
2080
2081
35.9k
        f->dsp->mc.resize(dst, dst_stride, src, src_stride, dst_w,
2082
35.9k
                          imin(img_h, h_end) + h_start, src_w,
2083
35.9k
                          f->resize_step[!!pl], f->resize_start[!!pl]
2084
35.9k
                          HIGHBD_CALL_SUFFIX);
2085
35.9k
    }
2086
12.9k
}
2087
2088
72.9k
void bytefn(dav1d_filter_sbrow_lr)(Dav1dFrameContext *const f, const int sby) {
2089
72.9k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_RESTORATION)) return;
2090
72.9k
    const int y = sby * f->sb_step * 4;
2091
72.9k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2092
72.9k
    pixel *const sr_p[3] = {
2093
72.9k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2094
72.9k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2095
72.9k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2096
72.9k
    };
2097
72.9k
    bytefn(dav1d_lr_sbrow)(f, sr_p, sby);
2098
72.9k
}
dav1d_filter_sbrow_lr_8bpc
Line
Count
Source
2088
41.3k
void bytefn(dav1d_filter_sbrow_lr)(Dav1dFrameContext *const f, const int sby) {
2089
41.3k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_RESTORATION)) return;
2090
41.3k
    const int y = sby * f->sb_step * 4;
2091
41.3k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2092
41.3k
    pixel *const sr_p[3] = {
2093
41.3k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2094
41.3k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2095
41.3k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2096
41.3k
    };
2097
41.3k
    bytefn(dav1d_lr_sbrow)(f, sr_p, sby);
2098
41.3k
}
dav1d_filter_sbrow_lr_16bpc
Line
Count
Source
2088
31.6k
void bytefn(dav1d_filter_sbrow_lr)(Dav1dFrameContext *const f, const int sby) {
2089
31.6k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_RESTORATION)) return;
2090
31.6k
    const int y = sby * f->sb_step * 4;
2091
31.6k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2092
31.6k
    pixel *const sr_p[3] = {
2093
31.6k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2094
31.6k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2095
31.6k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2096
31.6k
    };
2097
31.6k
    bytefn(dav1d_lr_sbrow)(f, sr_p, sby);
2098
31.6k
}
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
142k
void bytefn(dav1d_backup_ipred_edge)(Dav1dTaskContext *const t) {
2112
142k
    const Dav1dFrameContext *const f = t->f;
2113
142k
    Dav1dTileState *const ts = t->ts;
2114
142k
    const int sby = t->by >> f->sb_shift;
2115
142k
    const int sby_off = f->sb128w * 128 * sby;
2116
142k
    const int x_off = ts->tiling.col_start;
2117
2118
142k
    const pixel *const y =
2119
142k
        ((const pixel *) f->cur.data[0]) + x_off * 4 +
2120
142k
                    ((t->by + f->sb_step) * 4 - 1) * PXSTRIDE(f->cur.stride[0]);
2121
142k
    pixel_copy(&f->ipred_edge[0][sby_off + x_off * 4], y,
2122
142k
               4 * (ts->tiling.col_end - x_off));
2123
2124
142k
    if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
2125
112k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2126
112k
        const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2127
2128
112k
        const ptrdiff_t uv_off = (x_off * 4 >> ss_hor) +
2129
112k
            (((t->by + f->sb_step) * 4 >> ss_ver) - 1) * PXSTRIDE(f->cur.stride[1]);
2130
336k
        for (int pl = 1; pl <= 2; pl++)
2131
224k
            pixel_copy(&f->ipred_edge[pl][sby_off + (x_off * 4 >> ss_hor)],
2132
129k
                       &((const pixel *) f->cur.data[pl])[uv_off],
2133
129k
                       4 * (ts->tiling.col_end - x_off) >> ss_hor);
2134
112k
    }
2135
142k
}
dav1d_backup_ipred_edge_8bpc
Line
Count
Source
2111
77.0k
void bytefn(dav1d_backup_ipred_edge)(Dav1dTaskContext *const t) {
2112
77.0k
    const Dav1dFrameContext *const f = t->f;
2113
77.0k
    Dav1dTileState *const ts = t->ts;
2114
77.0k
    const int sby = t->by >> f->sb_shift;
2115
77.0k
    const int sby_off = f->sb128w * 128 * sby;
2116
77.0k
    const int x_off = ts->tiling.col_start;
2117
2118
77.0k
    const pixel *const y =
2119
77.0k
        ((const pixel *) f->cur.data[0]) + x_off * 4 +
2120
77.0k
                    ((t->by + f->sb_step) * 4 - 1) * PXSTRIDE(f->cur.stride[0]);
2121
77.0k
    pixel_copy(&f->ipred_edge[0][sby_off + x_off * 4], y,
2122
77.0k
               4 * (ts->tiling.col_end - x_off));
2123
2124
77.0k
    if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
2125
64.9k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2126
64.9k
        const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2127
2128
64.9k
        const ptrdiff_t uv_off = (x_off * 4 >> ss_hor) +
2129
64.9k
            (((t->by + f->sb_step) * 4 >> ss_ver) - 1) * PXSTRIDE(f->cur.stride[1]);
2130
194k
        for (int pl = 1; pl <= 2; pl++)
2131
129k
            pixel_copy(&f->ipred_edge[pl][sby_off + (x_off * 4 >> ss_hor)],
2132
129k
                       &((const pixel *) f->cur.data[pl])[uv_off],
2133
129k
                       4 * (ts->tiling.col_end - x_off) >> ss_hor);
2134
64.9k
    }
2135
77.0k
}
dav1d_backup_ipred_edge_16bpc
Line
Count
Source
2111
65.7k
void bytefn(dav1d_backup_ipred_edge)(Dav1dTaskContext *const t) {
2112
65.7k
    const Dav1dFrameContext *const f = t->f;
2113
65.7k
    Dav1dTileState *const ts = t->ts;
2114
65.7k
    const int sby = t->by >> f->sb_shift;
2115
65.7k
    const int sby_off = f->sb128w * 128 * sby;
2116
65.7k
    const int x_off = ts->tiling.col_start;
2117
2118
65.7k
    const pixel *const y =
2119
65.7k
        ((const pixel *) f->cur.data[0]) + x_off * 4 +
2120
65.7k
                    ((t->by + f->sb_step) * 4 - 1) * PXSTRIDE(f->cur.stride[0]);
2121
65.7k
    pixel_copy(&f->ipred_edge[0][sby_off + x_off * 4], y,
2122
65.7k
               4 * (ts->tiling.col_end - x_off));
2123
2124
65.7k
    if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
2125
47.1k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2126
47.1k
        const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2127
2128
47.1k
        const ptrdiff_t uv_off = (x_off * 4 >> ss_hor) +
2129
47.1k
            (((t->by + f->sb_step) * 4 >> ss_ver) - 1) * PXSTRIDE(f->cur.stride[1]);
2130
141k
        for (int pl = 1; pl <= 2; pl++)
2131
94.3k
            pixel_copy(&f->ipred_edge[pl][sby_off + (x_off * 4 >> ss_hor)],
2132
47.1k
                       &((const pixel *) f->cur.data[pl])[uv_off],
2133
47.1k
                       4 * (ts->tiling.col_end - x_off) >> ss_hor);
2134
47.1k
    }
2135
65.7k
}
2136
2137
void bytefn(dav1d_copy_pal_block_y)(Dav1dTaskContext *const t,
2138
                                    const int bx4, const int by4,
2139
                                    const int bw4, const int bh4)
2140
2141
18.1k
{
2142
18.1k
    const Dav1dFrameContext *const f = t->f;
2143
18.1k
    pixel *const pal = t->frame_thread.pass ?
2144
18.1k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2145
18.1k
                            ((t->bx >> 1) + (t->by & 1))][0] :
2146
18.1k
        bytefn(t->scratch.pal)[0];
2147
86.0k
    for (int x = 0; x < bw4; x++)
2148
67.9k
        memcpy(bytefn(t->al_pal)[0][bx4 + x][0], pal, 8 * sizeof(pixel));
2149
76.6k
    for (int y = 0; y < bh4; y++)
2150
58.5k
        memcpy(bytefn(t->al_pal)[1][by4 + y][0], pal, 8 * sizeof(pixel));
2151
18.1k
}
dav1d_copy_pal_block_y_8bpc
Line
Count
Source
2141
9.13k
{
2142
9.13k
    const Dav1dFrameContext *const f = t->f;
2143
9.13k
    pixel *const pal = t->frame_thread.pass ?
2144
9.13k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2145
9.13k
                            ((t->bx >> 1) + (t->by & 1))][0] :
2146
9.13k
        bytefn(t->scratch.pal)[0];
2147
39.4k
    for (int x = 0; x < bw4; x++)
2148
30.3k
        memcpy(bytefn(t->al_pal)[0][bx4 + x][0], pal, 8 * sizeof(pixel));
2149
37.0k
    for (int y = 0; y < bh4; y++)
2150
27.8k
        memcpy(bytefn(t->al_pal)[1][by4 + y][0], pal, 8 * sizeof(pixel));
2151
9.13k
}
dav1d_copy_pal_block_y_16bpc
Line
Count
Source
2141
8.97k
{
2142
8.97k
    const Dav1dFrameContext *const f = t->f;
2143
8.97k
    pixel *const pal = t->frame_thread.pass ?
2144
8.97k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2145
8.97k
                            ((t->bx >> 1) + (t->by & 1))][0] :
2146
8.97k
        bytefn(t->scratch.pal)[0];
2147
46.5k
    for (int x = 0; x < bw4; x++)
2148
37.5k
        memcpy(bytefn(t->al_pal)[0][bx4 + x][0], pal, 8 * sizeof(pixel));
2149
39.6k
    for (int y = 0; y < bh4; y++)
2150
30.6k
        memcpy(bytefn(t->al_pal)[1][by4 + y][0], pal, 8 * sizeof(pixel));
2151
8.97k
}
2152
2153
void bytefn(dav1d_copy_pal_block_uv)(Dav1dTaskContext *const t,
2154
                                     const int bx4, const int by4,
2155
                                     const int bw4, const int bh4)
2156
2157
7.17k
{
2158
7.17k
    const Dav1dFrameContext *const f = t->f;
2159
7.17k
    const pixel (*const pal)[8] = t->frame_thread.pass ?
2160
7.17k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2161
7.17k
                            ((t->bx >> 1) + (t->by & 1))] :
2162
7.17k
        bytefn(t->scratch.pal);
2163
    // see aomedia bug 2183 for why we use luma coordinates here
2164
21.5k
    for (int pl = 1; pl <= 2; pl++) {
2165
79.8k
        for (int x = 0; x < bw4; x++)
2166
65.5k
            memcpy(bytefn(t->al_pal)[0][bx4 + x][pl], pal[pl], 8 * sizeof(pixel));
2167
73.5k
        for (int y = 0; y < bh4; y++)
2168
59.1k
            memcpy(bytefn(t->al_pal)[1][by4 + y][pl], pal[pl], 8 * sizeof(pixel));
2169
14.3k
    }
2170
7.17k
}
dav1d_copy_pal_block_uv_8bpc
Line
Count
Source
2157
3.58k
{
2158
3.58k
    const Dav1dFrameContext *const f = t->f;
2159
3.58k
    const pixel (*const pal)[8] = t->frame_thread.pass ?
2160
3.58k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2161
3.58k
                            ((t->bx >> 1) + (t->by & 1))] :
2162
3.58k
        bytefn(t->scratch.pal);
2163
    // see aomedia bug 2183 for why we use luma coordinates here
2164
10.7k
    for (int pl = 1; pl <= 2; pl++) {
2165
38.4k
        for (int x = 0; x < bw4; x++)
2166
31.3k
            memcpy(bytefn(t->al_pal)[0][bx4 + x][pl], pal[pl], 8 * sizeof(pixel));
2167
36.9k
        for (int y = 0; y < bh4; y++)
2168
29.7k
            memcpy(bytefn(t->al_pal)[1][by4 + y][pl], pal[pl], 8 * sizeof(pixel));
2169
7.17k
    }
2170
3.58k
}
dav1d_copy_pal_block_uv_16bpc
Line
Count
Source
2157
3.58k
{
2158
3.58k
    const Dav1dFrameContext *const f = t->f;
2159
3.58k
    const pixel (*const pal)[8] = t->frame_thread.pass ?
2160
3.58k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2161
3.58k
                            ((t->bx >> 1) + (t->by & 1))] :
2162
3.58k
        bytefn(t->scratch.pal);
2163
    // see aomedia bug 2183 for why we use luma coordinates here
2164
10.7k
    for (int pl = 1; pl <= 2; pl++) {
2165
41.3k
        for (int x = 0; x < bw4; x++)
2166
34.1k
            memcpy(bytefn(t->al_pal)[0][bx4 + x][pl], pal[pl], 8 * sizeof(pixel));
2167
36.5k
        for (int y = 0; y < bh4; y++)
2168
29.4k
            memcpy(bytefn(t->al_pal)[1][by4 + y][pl], pal[pl], 8 * sizeof(pixel));
2169
7.16k
    }
2170
3.58k
}
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
25.2k
{
2176
25.2k
    Dav1dTileState *const ts = t->ts;
2177
25.2k
    const Dav1dFrameContext *const f = t->f;
2178
25.2k
    const int pal_sz = b->pal_sz[pl] = dav1d_msac_decode_symbol_adapt8(&ts->msac,
2179
25.2k
                                           ts->cdf.m.pal_sz[pl][sz_ctx], 6) + 2;
2180
25.2k
    pixel cache[16], used_cache[8];
2181
25.2k
    int l_cache = pl ? t->pal_sz_uv[1][by4] : t->l.pal_sz[by4];
2182
25.2k
    int n_cache = 0;
2183
    // don't reuse above palette outside SB64 boundaries
2184
25.2k
    int a_cache = by4 & 15 ? pl ? t->pal_sz_uv[0][bx4] : t->a->pal_sz[bx4] : 0;
2185
25.2k
    const pixel *l = bytefn(t->al_pal)[1][by4][pl];
2186
25.2k
    const pixel *a = bytefn(t->al_pal)[0][bx4][pl];
2187
2188
    // fill/sort cache
2189
44.3k
    while (l_cache && a_cache) {
2190
19.0k
        if (*l < *a) {
2191
7.11k
            if (!n_cache || cache[n_cache - 1] != *l)
2192
7.03k
                cache[n_cache++] = *l;
2193
7.11k
            l++;
2194
7.11k
            l_cache--;
2195
11.9k
        } else {
2196
11.9k
            if (*a == *l) {
2197
4.73k
                l++;
2198
4.73k
                l_cache--;
2199
4.73k
            }
2200
11.9k
            if (!n_cache || cache[n_cache - 1] != *a)
2201
11.5k
                cache[n_cache++] = *a;
2202
11.9k
            a++;
2203
11.9k
            a_cache--;
2204
11.9k
        }
2205
19.0k
    }
2206
25.2k
    if (l_cache) {
2207
29.4k
        do {
2208
29.4k
            if (!n_cache || cache[n_cache - 1] != *l)
2209
24.5k
                cache[n_cache++] = *l;
2210
29.4k
            l++;
2211
29.4k
        } while (--l_cache > 0);
2212
18.0k
    } else if (a_cache) {
2213
22.2k
        do {
2214
22.2k
            if (!n_cache || cache[n_cache - 1] != *a)
2215
17.8k
                cache[n_cache++] = *a;
2216
22.2k
            a++;
2217
22.2k
        } while (--a_cache > 0);
2218
5.57k
    }
2219
2220
    // find reused cache entries
2221
25.2k
    int i = 0;
2222
79.0k
    for (int n = 0; n < n_cache && i < pal_sz; n++)
2223
53.8k
        if (dav1d_msac_decode_bool_equi(&ts->msac))
2224
26.8k
            used_cache[i++] = cache[n];
2225
25.2k
    const int n_used_cache = i;
2226
2227
    // parse new entries
2228
25.2k
    pixel *const pal = t->frame_thread.pass ?
2229
25.2k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2230
25.2k
                            ((t->bx >> 1) + (t->by & 1))][pl] :
2231
25.2k
        bytefn(t->scratch.pal)[pl];
2232
25.2k
    if (i < pal_sz) {
2233
21.9k
        const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2234
21.9k
        int prev = pal[i++] = dav1d_msac_decode_bools(&ts->msac, bpc);
2235
2236
21.9k
        if (i < pal_sz) {
2237
19.7k
            int bits = bpc - 3 + dav1d_msac_decode_bools(&ts->msac, 2);
2238
19.7k
            const int max = (1 << bpc) - 1;
2239
2240
46.3k
            do {
2241
46.3k
                const int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2242
46.3k
                prev = pal[i++] = imin(prev + delta + !pl, max);
2243
46.3k
                if (prev + !pl >= max) {
2244
24.7k
                    for (; i < pal_sz; i++)
2245
15.9k
                        pal[i] = max;
2246
8.75k
                    break;
2247
8.75k
                }
2248
37.5k
                bits = imin(bits, 1 + ulog2(max - prev - !pl));
2249
37.5k
            } while (i < pal_sz);
2250
19.7k
        }
2251
2252
        // merge cache+new entries
2253
21.9k
        int n = 0, m = n_used_cache;
2254
123k
        for (i = 0; i < pal_sz; i++) {
2255
102k
            if (n < n_used_cache && (m >= pal_sz || used_cache[n] <= pal[m])) {
2256
17.8k
                pal[i] = used_cache[n++];
2257
84.2k
            } else {
2258
84.2k
                assert(m < pal_sz);
2259
84.2k
                pal[i] = pal[m++];
2260
84.2k
            }
2261
102k
        }
2262
21.9k
    } else {
2263
3.34k
        memcpy(pal, used_cache, n_used_cache * sizeof(*used_cache));
2264
3.34k
    }
2265
2266
25.2k
    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
25.2k
}
dav1d_read_pal_plane_8bpc
Line
Count
Source
2175
12.7k
{
2176
12.7k
    Dav1dTileState *const ts = t->ts;
2177
12.7k
    const Dav1dFrameContext *const f = t->f;
2178
12.7k
    const int pal_sz = b->pal_sz[pl] = dav1d_msac_decode_symbol_adapt8(&ts->msac,
2179
12.7k
                                           ts->cdf.m.pal_sz[pl][sz_ctx], 6) + 2;
2180
12.7k
    pixel cache[16], used_cache[8];
2181
12.7k
    int l_cache = pl ? t->pal_sz_uv[1][by4] : t->l.pal_sz[by4];
2182
12.7k
    int n_cache = 0;
2183
    // don't reuse above palette outside SB64 boundaries
2184
12.7k
    int a_cache = by4 & 15 ? pl ? t->pal_sz_uv[0][bx4] : t->a->pal_sz[bx4] : 0;
2185
12.7k
    const pixel *l = bytefn(t->al_pal)[1][by4][pl];
2186
12.7k
    const pixel *a = bytefn(t->al_pal)[0][bx4][pl];
2187
2188
    // fill/sort cache
2189
23.5k
    while (l_cache && a_cache) {
2190
10.8k
        if (*l < *a) {
2191
4.14k
            if (!n_cache || cache[n_cache - 1] != *l)
2192
4.07k
                cache[n_cache++] = *l;
2193
4.14k
            l++;
2194
4.14k
            l_cache--;
2195
6.71k
        } else {
2196
6.71k
            if (*a == *l) {
2197
2.72k
                l++;
2198
2.72k
                l_cache--;
2199
2.72k
            }
2200
6.71k
            if (!n_cache || cache[n_cache - 1] != *a)
2201
6.51k
                cache[n_cache++] = *a;
2202
6.71k
            a++;
2203
6.71k
            a_cache--;
2204
6.71k
        }
2205
10.8k
    }
2206
12.7k
    if (l_cache) {
2207
14.7k
        do {
2208
14.7k
            if (!n_cache || cache[n_cache - 1] != *l)
2209
12.1k
                cache[n_cache++] = *l;
2210
14.7k
            l++;
2211
14.7k
        } while (--l_cache > 0);
2212
9.06k
    } else if (a_cache) {
2213
11.5k
        do {
2214
11.5k
            if (!n_cache || cache[n_cache - 1] != *a)
2215
9.28k
                cache[n_cache++] = *a;
2216
11.5k
            a++;
2217
11.5k
        } while (--a_cache > 0);
2218
2.95k
    }
2219
2220
    // find reused cache entries
2221
12.7k
    int i = 0;
2222
41.0k
    for (int n = 0; n < n_cache && i < pal_sz; n++)
2223
28.2k
        if (dav1d_msac_decode_bool_equi(&ts->msac))
2224
14.1k
            used_cache[i++] = cache[n];
2225
12.7k
    const int n_used_cache = i;
2226
2227
    // parse new entries
2228
12.7k
    pixel *const pal = t->frame_thread.pass ?
2229
12.7k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2230
12.7k
                            ((t->bx >> 1) + (t->by & 1))][pl] :
2231
12.7k
        bytefn(t->scratch.pal)[pl];
2232
12.7k
    if (i < pal_sz) {
2233
10.9k
        const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2234
10.9k
        int prev = pal[i++] = dav1d_msac_decode_bools(&ts->msac, bpc);
2235
2236
10.9k
        if (i < pal_sz) {
2237
9.73k
            int bits = bpc - 3 + dav1d_msac_decode_bools(&ts->msac, 2);
2238
9.73k
            const int max = (1 << bpc) - 1;
2239
2240
22.4k
            do {
2241
22.4k
                const int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2242
22.4k
                prev = pal[i++] = imin(prev + delta + !pl, max);
2243
22.4k
                if (prev + !pl >= max) {
2244
12.4k
                    for (; i < pal_sz; i++)
2245
8.03k
                        pal[i] = max;
2246
4.37k
                    break;
2247
4.37k
                }
2248
18.0k
                bits = imin(bits, 1 + ulog2(max - prev - !pl));
2249
18.0k
            } while (i < pal_sz);
2250
9.73k
        }
2251
2252
        // merge cache+new entries
2253
10.9k
        int n = 0, m = n_used_cache;
2254
61.6k
        for (i = 0; i < pal_sz; i++) {
2255
50.7k
            if (n < n_used_cache && (m >= pal_sz || used_cache[n] <= pal[m])) {
2256
9.29k
                pal[i] = used_cache[n++];
2257
41.4k
            } else {
2258
41.4k
                assert(m < pal_sz);
2259
41.4k
                pal[i] = pal[m++];
2260
41.4k
            }
2261
50.7k
        }
2262
10.9k
    } else {
2263
1.77k
        memcpy(pal, used_cache, n_used_cache * sizeof(*used_cache));
2264
1.77k
    }
2265
2266
12.7k
    if (DEBUG_BLOCK_INFO) {
2267
0
        printf("Post-pal[pl=%d,sz=%d,cache_size=%d,used_cache=%d]: r=%d, cache=",
2268
0
               pl, pal_sz, n_cache, n_used_cache, ts->msac.rng);
2269
0
        for (int n = 0; n < n_cache; n++)
2270
0
            printf("%c%02x", n ? ' ' : '[', cache[n]);
2271
0
        printf("%s, pal=", n_cache ? "]" : "[]");
2272
0
        for (int n = 0; n < pal_sz; n++)
2273
0
            printf("%c%02x", n ? ' ' : '[', pal[n]);
2274
0
        printf("]\n");
2275
0
    }
2276
12.7k
}
dav1d_read_pal_plane_16bpc
Line
Count
Source
2175
12.5k
{
2176
12.5k
    Dav1dTileState *const ts = t->ts;
2177
12.5k
    const Dav1dFrameContext *const f = t->f;
2178
12.5k
    const int pal_sz = b->pal_sz[pl] = dav1d_msac_decode_symbol_adapt8(&ts->msac,
2179
12.5k
                                           ts->cdf.m.pal_sz[pl][sz_ctx], 6) + 2;
2180
12.5k
    pixel cache[16], used_cache[8];
2181
12.5k
    int l_cache = pl ? t->pal_sz_uv[1][by4] : t->l.pal_sz[by4];
2182
12.5k
    int n_cache = 0;
2183
    // don't reuse above palette outside SB64 boundaries
2184
12.5k
    int a_cache = by4 & 15 ? pl ? t->pal_sz_uv[0][bx4] : t->a->pal_sz[bx4] : 0;
2185
12.5k
    const pixel *l = bytefn(t->al_pal)[1][by4][pl];
2186
12.5k
    const pixel *a = bytefn(t->al_pal)[0][bx4][pl];
2187
2188
    // fill/sort cache
2189
20.7k
    while (l_cache && a_cache) {
2190
8.15k
        if (*l < *a) {
2191
2.97k
            if (!n_cache || cache[n_cache - 1] != *l)
2192
2.95k
                cache[n_cache++] = *l;
2193
2.97k
            l++;
2194
2.97k
            l_cache--;
2195
5.18k
        } else {
2196
5.18k
            if (*a == *l) {
2197
2.00k
                l++;
2198
2.00k
                l_cache--;
2199
2.00k
            }
2200
5.18k
            if (!n_cache || cache[n_cache - 1] != *a)
2201
4.99k
                cache[n_cache++] = *a;
2202
5.18k
            a++;
2203
5.18k
            a_cache--;
2204
5.18k
        }
2205
8.15k
    }
2206
12.5k
    if (l_cache) {
2207
14.6k
        do {
2208
14.6k
            if (!n_cache || cache[n_cache - 1] != *l)
2209
12.3k
                cache[n_cache++] = *l;
2210
14.6k
            l++;
2211
14.6k
        } while (--l_cache > 0);
2212
9.02k
    } else if (a_cache) {
2213
10.6k
        do {
2214
10.6k
            if (!n_cache || cache[n_cache - 1] != *a)
2215
8.59k
                cache[n_cache++] = *a;
2216
10.6k
            a++;
2217
10.6k
        } while (--a_cache > 0);
2218
2.61k
    }
2219
2220
    // find reused cache entries
2221
12.5k
    int i = 0;
2222
38.0k
    for (int n = 0; n < n_cache && i < pal_sz; n++)
2223
25.5k
        if (dav1d_msac_decode_bool_equi(&ts->msac))
2224
12.7k
            used_cache[i++] = cache[n];
2225
12.5k
    const int n_used_cache = i;
2226
2227
    // parse new entries
2228
12.5k
    pixel *const pal = t->frame_thread.pass ?
2229
12.5k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2230
12.5k
                            ((t->bx >> 1) + (t->by & 1))][pl] :
2231
12.5k
        bytefn(t->scratch.pal)[pl];
2232
12.5k
    if (i < pal_sz) {
2233
10.9k
        const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2234
10.9k
        int prev = pal[i++] = dav1d_msac_decode_bools(&ts->msac, bpc);
2235
2236
10.9k
        if (i < pal_sz) {
2237
10.0k
            int bits = bpc - 3 + dav1d_msac_decode_bools(&ts->msac, 2);
2238
10.0k
            const int max = (1 << bpc) - 1;
2239
2240
23.8k
            do {
2241
23.8k
                const int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2242
23.8k
                prev = pal[i++] = imin(prev + delta + !pl, max);
2243
23.8k
                if (prev + !pl >= max) {
2244
12.3k
                    for (; i < pal_sz; i++)
2245
7.94k
                        pal[i] = max;
2246
4.38k
                    break;
2247
4.38k
                }
2248
19.4k
                bits = imin(bits, 1 + ulog2(max - prev - !pl));
2249
19.4k
            } while (i < pal_sz);
2250
10.0k
        }
2251
2252
        // merge cache+new entries
2253
10.9k
        int n = 0, m = n_used_cache;
2254
62.2k
        for (i = 0; i < pal_sz; i++) {
2255
51.3k
            if (n < n_used_cache && (m >= pal_sz || used_cache[n] <= pal[m])) {
2256
8.54k
                pal[i] = used_cache[n++];
2257
42.7k
            } else {
2258
42.7k
                assert(m < pal_sz);
2259
42.7k
                pal[i] = pal[m++];
2260
42.7k
            }
2261
51.3k
        }
2262
10.9k
    } else {
2263
1.57k
        memcpy(pal, used_cache, n_used_cache * sizeof(*used_cache));
2264
1.57k
    }
2265
2266
12.5k
    if (DEBUG_BLOCK_INFO) {
2267
0
        printf("Post-pal[pl=%d,sz=%d,cache_size=%d,used_cache=%d]: r=%d, cache=",
2268
0
               pl, pal_sz, n_cache, n_used_cache, ts->msac.rng);
2269
0
        for (int n = 0; n < n_cache; n++)
2270
0
            printf("%c%02x", n ? ' ' : '[', cache[n]);
2271
0
        printf("%s, pal=", n_cache ? "]" : "[]");
2272
0
        for (int n = 0; n < pal_sz; n++)
2273
0
            printf("%c%02x", n ? ' ' : '[', pal[n]);
2274
0
        printf("]\n");
2275
0
    }
2276
12.5k
}
2277
2278
void bytefn(dav1d_read_pal_uv)(Dav1dTaskContext *const t, Av1Block *const b,
2279
                               const int sz_ctx, const int bx4, const int by4)
2280
7.17k
{
2281
7.17k
    bytefn(dav1d_read_pal_plane)(t, b, 1, sz_ctx, bx4, by4);
2282
2283
    // V pal coding
2284
7.17k
    Dav1dTileState *const ts = t->ts;
2285
7.17k
    const Dav1dFrameContext *const f = t->f;
2286
7.17k
    pixel *const pal = t->frame_thread.pass ?
2287
7.17k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2288
7.17k
                            ((t->bx >> 1) + (t->by & 1))][2] :
2289
7.17k
        bytefn(t->scratch.pal)[2];
2290
7.17k
    const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2291
7.17k
    if (dav1d_msac_decode_bool_equi(&ts->msac)) {
2292
3.53k
        const int bits = bpc - 4 + dav1d_msac_decode_bools(&ts->msac, 2);
2293
3.53k
        int prev = pal[0] = dav1d_msac_decode_bools(&ts->msac, bpc);
2294
3.53k
        const int max = (1 << bpc) - 1;
2295
14.3k
        for (int i = 1; i < b->pal_sz[1]; i++) {
2296
10.8k
            int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2297
10.8k
            if (delta && dav1d_msac_decode_bool_equi(&ts->msac)) delta = -delta;
2298
10.8k
            prev = pal[i] = (prev + delta) & max;
2299
10.8k
        }
2300
3.63k
    } else {
2301
18.7k
        for (int i = 0; i < b->pal_sz[1]; i++)
2302
15.1k
            pal[i] = dav1d_msac_decode_bools(&ts->msac, bpc);
2303
3.63k
    }
2304
7.17k
    if (DEBUG_BLOCK_INFO) {
2305
0
        printf("Post-pal[pl=2]: r=%d ", ts->msac.rng);
2306
0
        for (int n = 0; n < b->pal_sz[1]; n++)
2307
0
            printf("%c%02x", n ? ' ' : '[', pal[n]);
2308
0
        printf("]\n");
2309
0
    }
2310
7.17k
}
dav1d_read_pal_uv_8bpc
Line
Count
Source
2280
3.58k
{
2281
3.58k
    bytefn(dav1d_read_pal_plane)(t, b, 1, sz_ctx, bx4, by4);
2282
2283
    // V pal coding
2284
3.58k
    Dav1dTileState *const ts = t->ts;
2285
3.58k
    const Dav1dFrameContext *const f = t->f;
2286
3.58k
    pixel *const pal = t->frame_thread.pass ?
2287
3.58k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2288
3.58k
                            ((t->bx >> 1) + (t->by & 1))][2] :
2289
3.58k
        bytefn(t->scratch.pal)[2];
2290
3.58k
    const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2291
3.58k
    if (dav1d_msac_decode_bool_equi(&ts->msac)) {
2292
1.79k
        const int bits = bpc - 4 + dav1d_msac_decode_bools(&ts->msac, 2);
2293
1.79k
        int prev = pal[0] = dav1d_msac_decode_bools(&ts->msac, bpc);
2294
1.79k
        const int max = (1 << bpc) - 1;
2295
7.42k
        for (int i = 1; i < b->pal_sz[1]; i++) {
2296
5.62k
            int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2297
5.62k
            if (delta && dav1d_msac_decode_bool_equi(&ts->msac)) delta = -delta;
2298
5.62k
            prev = pal[i] = (prev + delta) & max;
2299
5.62k
        }
2300
1.79k
    } else {
2301
9.27k
        for (int i = 0; i < b->pal_sz[1]; i++)
2302
7.48k
            pal[i] = dav1d_msac_decode_bools(&ts->msac, bpc);
2303
1.79k
    }
2304
3.58k
    if (DEBUG_BLOCK_INFO) {
2305
0
        printf("Post-pal[pl=2]: r=%d ", ts->msac.rng);
2306
0
        for (int n = 0; n < b->pal_sz[1]; n++)
2307
0
            printf("%c%02x", n ? ' ' : '[', pal[n]);
2308
0
        printf("]\n");
2309
0
    }
2310
3.58k
}
dav1d_read_pal_uv_16bpc
Line
Count
Source
2280
3.58k
{
2281
3.58k
    bytefn(dav1d_read_pal_plane)(t, b, 1, sz_ctx, bx4, by4);
2282
2283
    // V pal coding
2284
3.58k
    Dav1dTileState *const ts = t->ts;
2285
3.58k
    const Dav1dFrameContext *const f = t->f;
2286
3.58k
    pixel *const pal = t->frame_thread.pass ?
2287
3.58k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2288
3.58k
                            ((t->bx >> 1) + (t->by & 1))][2] :
2289
3.58k
        bytefn(t->scratch.pal)[2];
2290
3.58k
    const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2291
3.58k
    if (dav1d_msac_decode_bool_equi(&ts->msac)) {
2292
1.74k
        const int bits = bpc - 4 + dav1d_msac_decode_bools(&ts->msac, 2);
2293
1.74k
        int prev = pal[0] = dav1d_msac_decode_bools(&ts->msac, bpc);
2294
1.74k
        const int max = (1 << bpc) - 1;
2295
6.95k
        for (int i = 1; i < b->pal_sz[1]; i++) {
2296
5.21k
            int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2297
5.21k
            if (delta && dav1d_msac_decode_bool_equi(&ts->msac)) delta = -delta;
2298
5.21k
            prev = pal[i] = (prev + delta) & max;
2299
5.21k
        }
2300
1.84k
    } else {
2301
9.47k
        for (int i = 0; i < b->pal_sz[1]; i++)
2302
7.63k
            pal[i] = dav1d_msac_decode_bools(&ts->msac, bpc);
2303
1.84k
    }
2304
3.58k
    if (DEBUG_BLOCK_INFO) {
2305
0
        printf("Post-pal[pl=2]: r=%d ", ts->msac.rng);
2306
0
        for (int n = 0; n < b->pal_sz[1]; n++)
2307
0
            printf("%c%02x", n ? ' ' : '[', pal[n]);
2308
0
        printf("]\n");
2309
0
    }
2310
3.58k
}