Coverage Report

Created: 2026-09-02 06:39

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