Coverage Report

Created: 2026-09-02 06:43

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
1.81M
static inline unsigned read_golomb(MsacContext *const msac) {
50
1.81M
    int len = 0;
51
1.81M
    unsigned val = 1;
52
53
3.36M
    while (!dav1d_msac_decode_bool_equi(msac) && len < 32) len++;
54
3.36M
    while (len--) val = (val << 1) + dav1d_msac_decode_bool_equi(msac);
55
56
1.81M
    return val - 1;
57
1.81M
}
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
12.9M
{
66
12.9M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
67
68
12.9M
    if (chroma) {
69
6.66M
        const int ss_ver = layout == DAV1D_PIXEL_LAYOUT_I420;
70
6.66M
        const int ss_hor = layout != DAV1D_PIXEL_LAYOUT_I444;
71
6.66M
        const int not_one_blk = b_dim[2] - (!!b_dim[2] && ss_hor) > t_dim->lw ||
72
4.29M
                                b_dim[3] - (!!b_dim[3] && ss_ver) > t_dim->lh;
73
6.66M
        unsigned ca, cl;
74
75
6.66M
#define MERGE_CTX(dir, type, no_val) \
76
13.3M
        c##dir = *(const type *) dir != no_val; \
77
13.3M
        break
78
79
6.66M
        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
2.69M
        case TX_4X4:   MERGE_CTX(a, uint8_t,  0x40);
87
1.37M
        case TX_8X8:   MERGE_CTX(a, uint16_t, 0x4040);
88
1.01M
        case TX_16X16: MERGE_CTX(a, uint32_t, 0x40404040U);
89
1.59M
        case TX_32X32: MERGE_CTX(a, uint64_t, 0x4040404040404040ULL);
90
6.66M
        }
91
6.67M
        switch (t_dim->lh) {
92
0
        default: assert(0); /* fall-through */
93
2.99M
        case TX_4X4:   MERGE_CTX(l, uint8_t,  0x40);
94
1.34M
        case TX_8X8:   MERGE_CTX(l, uint16_t, 0x4040);
95
796k
        case TX_16X16: MERGE_CTX(l, uint32_t, 0x40404040U);
96
1.53M
        case TX_32X32: MERGE_CTX(l, uint64_t, 0x4040404040404040ULL);
97
6.67M
        }
98
6.67M
#undef MERGE_CTX
99
100
6.67M
        return 7 + not_one_blk * 3 + ca + cl;
101
6.67M
    } else if (b_dim[2] == t_dim->lw && b_dim[3] == t_dim->lh) {
102
2.69M
        return 0;
103
3.57M
    } else {
104
3.57M
        unsigned la, ll;
105
106
3.57M
#define MERGE_CTX(dir, type, tx) \
107
7.38M
        if (tx == TX_64X64) { \
108
578k
            uint64_t tmp = *(const uint64_t *) dir; \
109
578k
            tmp |= *(const uint64_t *) &dir[8]; \
110
578k
            l##dir = (unsigned) (tmp >> 32) | (unsigned) tmp; \
111
578k
        } else \
112
7.38M
            l##dir = *(const type *) dir; \
113
7.38M
        if (tx == TX_32X32) l##dir |= *(const type *) &dir[sizeof(type)]; \
114
7.38M
        if (tx >= TX_16X16) l##dir |= l##dir >> 16; \
115
7.38M
        if (tx >= TX_8X8)   l##dir |= l##dir >> 8; \
116
7.38M
        break
117
118
3.57M
        switch (t_dim->lw) {
119
0
        default: assert(0); /* fall-through */
120
2.06M
        case TX_4X4:   MERGE_CTX(a, uint8_t,  TX_4X4);
121
732k
        case TX_8X8:   MERGE_CTX(a, uint16_t, TX_8X8);
122
550k
        case TX_16X16: MERGE_CTX(a, uint32_t, TX_16X16);
123
50.9k
        case TX_32X32: MERGE_CTX(a, uint32_t, TX_32X32);
124
289k
        case TX_64X64: MERGE_CTX(a, uint32_t, TX_64X64);
125
3.57M
        }
126
3.68M
        switch (t_dim->lh) {
127
0
        default: assert(0); /* fall-through */
128
2.09M
        case TX_4X4:   MERGE_CTX(l, uint8_t,  TX_4X4);
129
712k
        case TX_8X8:   MERGE_CTX(l, uint16_t, TX_8X8);
130
549k
        case TX_16X16: MERGE_CTX(l, uint32_t, TX_16X16);
131
51.6k
        case TX_32X32: MERGE_CTX(l, uint32_t, TX_32X32);
132
289k
        case TX_64X64: MERGE_CTX(l, uint32_t, TX_64X64);
133
3.68M
        }
134
3.69M
#undef MERGE_CTX
135
136
3.69M
        return dav1d_skip_ctx[umin(la & 0x3F, 4)][umin(ll & 0x3F, 4)];
137
3.68M
    }
138
12.9M
}
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
5.57M
{
144
5.57M
    uint64_t mask = 0xC0C0C0C0C0C0C0C0ULL, mul = 0x0101010101010101ULL;
145
5.57M
    int s;
146
147
5.57M
#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
5.57M
    __asm__("" : "+r"(mask), "+r"(mul));
151
5.57M
#endif
152
153
5.57M
    switch(tx) {
154
0
    default: assert(0); /* fall-through */
155
2.09M
    case TX_4X4: {
156
2.09M
        int t = *(const uint8_t *) a >> 6;
157
2.09M
        t    += *(const uint8_t *) l >> 6;
158
2.09M
        s = t - 1 - 1;
159
2.09M
        break;
160
0
    }
161
650k
    case TX_8X8: {
162
650k
        uint32_t t = *(const uint16_t *) a & (uint32_t) mask;
163
650k
        t         += *(const uint16_t *) l & (uint32_t) mask;
164
650k
        t *= 0x04040404U;
165
650k
        s = (int) (t >> 24) - 2 - 2;
166
650k
        break;
167
0
    }
168
468k
    case TX_16X16: {
169
468k
        uint32_t t = (*(const uint32_t *) a & (uint32_t) mask) >> 6;
170
468k
        t         += (*(const uint32_t *) l & (uint32_t) mask) >> 6;
171
468k
        t *= (uint32_t) mul;
172
468k
        s = (int) (t >> 24) - 4 - 4;
173
468k
        break;
174
0
    }
175
413k
    case TX_32X32: {
176
413k
        uint64_t t = (*(const uint64_t *) a & mask) >> 6;
177
413k
        t         += (*(const uint64_t *) l & mask) >> 6;
178
413k
        t *= mul;
179
413k
        s = (int) (t >> 56) - 8 - 8;
180
413k
        break;
181
0
    }
182
216k
    case TX_64X64: {
183
216k
        uint64_t t = (*(const uint64_t *) &a[0] & mask) >> 6;
184
216k
        t         += (*(const uint64_t *) &a[8] & mask) >> 6;
185
216k
        t         += (*(const uint64_t *) &l[0] & mask) >> 6;
186
216k
        t         += (*(const uint64_t *) &l[8] & mask) >> 6;
187
216k
        t *= mul;
188
216k
        s = (int) (t >> 56) - 16 - 16;
189
216k
        break;
190
0
    }
191
197k
    case RTX_4X8: {
192
197k
        uint32_t t = *(const uint8_t  *) a & (uint32_t) mask;
193
197k
        t         += *(const uint16_t *) l & (uint32_t) mask;
194
197k
        t *= 0x04040404U;
195
197k
        s = (int) (t >> 24) - 1 - 2;
196
197k
        break;
197
0
    }
198
292k
    case RTX_8X4: {
199
292k
        uint32_t t = *(const uint16_t *) a & (uint32_t) mask;
200
292k
        t         += *(const uint8_t  *) l & (uint32_t) mask;
201
292k
        t *= 0x04040404U;
202
292k
        s = (int) (t >> 24) - 2 - 1;
203
292k
        break;
204
0
    }
205
171k
    case RTX_8X16: {
206
171k
        uint32_t t = *(const uint16_t *) a & (uint32_t) mask;
207
171k
        t         += *(const uint32_t *) l & (uint32_t) mask;
208
171k
        t = (t >> 6) * (uint32_t) mul;
209
171k
        s = (int) (t >> 24) - 2 - 4;
210
171k
        break;
211
0
    }
212
306k
    case RTX_16X8: {
213
306k
        uint32_t t = *(const uint32_t *) a & (uint32_t) mask;
214
306k
        t         += *(const uint16_t *) l & (uint32_t) mask;
215
306k
        t = (t >> 6) * (uint32_t) mul;
216
306k
        s = (int) (t >> 24) - 4 - 2;
217
306k
        break;
218
0
    }
219
86.6k
    case RTX_16X32: {
220
86.6k
        uint64_t t = *(const uint32_t *) a & (uint32_t) mask;
221
86.6k
        t         += *(const uint64_t *) l & mask;
222
86.6k
        t = (t >> 6) * mul;
223
86.6k
        s = (int) (t >> 56) - 4 - 8;
224
86.6k
        break;
225
0
    }
226
140k
    case RTX_32X16: {
227
140k
        uint64_t t = *(const uint64_t *) a & mask;
228
140k
        t         += *(const uint32_t *) l & (uint32_t) mask;
229
140k
        t = (t >> 6) * mul;
230
140k
        s = (int) (t >> 56) - 8 - 4;
231
140k
        break;
232
0
    }
233
49.9k
    case RTX_32X64: {
234
49.9k
        uint64_t t = (*(const uint64_t *) &a[0] & mask) >> 6;
235
49.9k
        t         += (*(const uint64_t *) &l[0] & mask) >> 6;
236
49.9k
        t         += (*(const uint64_t *) &l[8] & mask) >> 6;
237
49.9k
        t *= mul;
238
49.9k
        s = (int) (t >> 56) - 8 - 16;
239
49.9k
        break;
240
0
    }
241
45.5k
    case RTX_64X32: {
242
45.5k
        uint64_t t = (*(const uint64_t *) &a[0] & mask) >> 6;
243
45.5k
        t         += (*(const uint64_t *) &a[8] & mask) >> 6;
244
45.5k
        t         += (*(const uint64_t *) &l[0] & mask) >> 6;
245
45.5k
        t *= mul;
246
45.5k
        s = (int) (t >> 56) - 16 - 8;
247
45.5k
        break;
248
0
    }
249
93.0k
    case RTX_4X16: {
250
93.0k
        uint32_t t = *(const uint8_t  *) a & (uint32_t) mask;
251
93.0k
        t         += *(const uint32_t *) l & (uint32_t) mask;
252
93.0k
        t = (t >> 6) * (uint32_t) mul;
253
93.0k
        s = (int) (t >> 24) - 1 - 4;
254
93.0k
        break;
255
0
    }
256
176k
    case RTX_16X4: {
257
176k
        uint32_t t = *(const uint32_t *) a & (uint32_t) mask;
258
176k
        t         += *(const uint8_t  *) l & (uint32_t) mask;
259
176k
        t = (t >> 6) * (uint32_t) mul;
260
176k
        s = (int) (t >> 24) - 4 - 1;
261
176k
        break;
262
0
    }
263
61.5k
    case RTX_8X32: {
264
61.5k
        uint64_t t = *(const uint16_t *) a & (uint32_t) mask;
265
61.5k
        t         += *(const uint64_t *) l & mask;
266
61.5k
        t = (t >> 6) * mul;
267
61.5k
        s = (int) (t >> 56) - 2 - 8;
268
61.5k
        break;
269
0
    }
270
79.1k
    case RTX_32X8: {
271
79.1k
        uint64_t t = *(const uint64_t *) a & mask;
272
79.1k
        t         += *(const uint16_t *) l & (uint32_t) mask;
273
79.1k
        t = (t >> 6) * mul;
274
79.1k
        s = (int) (t >> 56) - 8 - 2;
275
79.1k
        break;
276
0
    }
277
20.4k
    case RTX_16X64: {
278
20.4k
        uint64_t t = *(const uint32_t *) a & (uint32_t) mask;
279
20.4k
        t         += *(const uint64_t *) &l[0] & mask;
280
20.4k
        t = (t >> 6) + ((*(const uint64_t *) &l[8] & mask) >> 6);
281
20.4k
        t *= mul;
282
20.4k
        s = (int) (t >> 56) - 4 - 16;
283
20.4k
        break;
284
0
    }
285
14.0k
    case RTX_64X16: {
286
14.0k
        uint64_t t = *(const uint64_t *) &a[0] & mask;
287
14.0k
        t         += *(const uint32_t *) l & (uint32_t) mask;
288
14.0k
        t = (t >> 6) + ((*(const uint64_t *) &a[8] & mask) >> 6);
289
14.0k
        t *= mul;
290
14.0k
        s = (int) (t >> 56) - 16 - 4;
291
14.0k
        break;
292
0
    }
293
5.57M
    }
294
295
5.57M
    return (s != 0) + (s > 0);
296
5.57M
}
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
107M
{
305
107M
    unsigned mag = levels[0 * stride + 1] + levels[1 * stride + 0];
306
107M
    unsigned offset;
307
107M
    if (tx_class == TX_CLASS_2D) {
308
98.3M
        mag += levels[1 * stride + 1];
309
98.3M
        *hi_mag = mag;
310
98.3M
        mag += levels[0 * stride + 2] + levels[2 * stride + 0];
311
98.3M
        offset = ctx_offsets[umin(y, 4)][umin(x, 4)];
312
98.3M
    } else {
313
8.82M
        mag += levels[0 * stride + 2];
314
8.82M
        *hi_mag = mag;
315
8.82M
        mag += levels[0 * stride + 3] + levels[0 * stride + 4];
316
8.82M
        offset = 26 + (y > 1 ? 10 : y * 5);
317
8.82M
    }
318
107M
    return offset + (mag > 512 ? 4 : (mag + 64) >> 7);
319
107M
}
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
12.9M
{
328
12.9M
    Dav1dTileState *const ts = t->ts;
329
12.9M
    const int chroma = !!plane;
330
12.9M
    const Dav1dFrameContext *const f = t->f;
331
12.9M
    const int lossless = f->frame_hdr->segmentation.lossless[b->seg_id];
332
12.9M
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[tx];
333
12.9M
    const int dbg = DEBUG_BLOCK_INFO && plane && 0;
334
335
12.9M
    if (dbg)
336
0
        printf("Start: r=%d\n", ts->msac.rng);
337
338
    // does this block have any non-zero coefficients
339
12.9M
    const int sctx = get_skip_ctx(t_dim, bs, a, l, chroma, f->cur.p.layout);
340
12.9M
    const int all_skip = dav1d_msac_decode_bool_adapt(&ts->msac,
341
12.9M
                             ts->cdf.coef.skip[t_dim->ctx][sctx]);
342
12.9M
    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
12.9M
    if (all_skip) {
346
6.25M
        *res_ctx = 0x40;
347
6.25M
        *txtp = lossless * WHT_WHT; /* lossless ? WHT_WHT : DCT_DCT */
348
6.25M
        return -1;
349
6.25M
    }
350
351
    // transform type (chroma: derived, luma: explicitly coded)
352
6.67M
    if (lossless) {
353
1.83M
        assert(t_dim->max == TX_4X4);
354
1.83M
        *txtp = WHT_WHT;
355
4.83M
    } else if (t_dim->max + intra >= TX_64X64) {
356
1.02M
        *txtp = DCT_DCT;
357
3.81M
    } else if (chroma) {
358
        // inferred from either the luma txtp (inter) or a LUT (intra)
359
934k
        *txtp = intra ? dav1d_txtp_from_uvmode[b->uv_mode] :
360
934k
                        get_uv_inter_txtp(t_dim, *txtp);
361
2.88M
    } 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
25.8k
        *txtp = DCT_DCT;
366
2.85M
    } else {
367
2.85M
        unsigned idx;
368
2.85M
        if (intra) {
369
1.77M
            const enum IntraPredMode y_mode_nofilt = b->y_mode == FILTER_PRED ?
370
1.50M
                dav1d_filter_mode_to_y_mode[b->y_angle] : b->y_mode;
371
1.77M
            if (f->frame_hdr->reduced_txtp_set || t_dim->min == TX_16X16) {
372
751k
                idx = dav1d_msac_decode_symbol_adapt8(&ts->msac,
373
751k
                          ts->cdf.m.txtp_intra2[t_dim->min][y_mode_nofilt], 4);
374
751k
                *txtp = dav1d_tx_types_per_set[idx + 0];
375
1.02M
            } else {
376
1.02M
                idx = dav1d_msac_decode_symbol_adapt8(&ts->msac,
377
1.02M
                          ts->cdf.m.txtp_intra1[t_dim->min][y_mode_nofilt], 6);
378
1.02M
                *txtp = dav1d_tx_types_per_set[idx + 5];
379
1.02M
            }
380
1.77M
            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
1.77M
        } else {
384
1.07M
            if (f->frame_hdr->reduced_txtp_set || t_dim->max == TX_32X32) {
385
299k
                idx = dav1d_msac_decode_bool_adapt(&ts->msac,
386
299k
                          ts->cdf.m.txtp_inter3[t_dim->min]);
387
299k
                *txtp = (idx - 1) & IDTX; /* idx ? DCT_DCT : IDTX */
388
780k
            } else if (t_dim->min == TX_16X16) {
389
104k
                idx = dav1d_msac_decode_symbol_adapt16(&ts->msac,
390
104k
                          ts->cdf.m.txtp_inter2, 11);
391
104k
                *txtp = dav1d_tx_types_per_set[idx + 12];
392
675k
            } else {
393
675k
                idx = dav1d_msac_decode_symbol_adapt16(&ts->msac,
394
675k
                          ts->cdf.m.txtp_inter1[t_dim->min], 15);
395
675k
                *txtp = dav1d_tx_types_per_set[idx + 24];
396
675k
            }
397
1.07M
            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
1.07M
        }
401
2.85M
    }
402
403
    // find end-of-block (eob)
404
6.67M
    int eob;
405
6.67M
    const int slw = imin(t_dim->lw, TX_32X32), slh = imin(t_dim->lh, TX_32X32);
406
6.67M
    const int tx2dszctx = slw + slh;
407
6.67M
    const enum TxClass tx_class = dav1d_tx_type_class[*txtp];
408
6.67M
    const int is_1d = tx_class != TX_CLASS_2D;
409
6.67M
    switch (tx2dszctx) {
410
0
#define case_sz(sz, bin, ns, is_1d) \
411
6.77M
    case sz: { \
412
6.77M
        uint16_t *const eob_bin_cdf = ts->cdf.coef.eob_bin_##bin[chroma]is_1d; \
413
6.77M
        eob = dav1d_msac_decode_symbol_adapt##ns(&ts->msac, eob_bin_cdf, 4 + sz); \
414
6.77M
        break; \
415
6.77M
    }
416
2.42M
    case_sz(0,   16,  8, [is_1d]);
417
650k
    case_sz(1,   32,  8, [is_1d]);
418
1.20M
    case_sz(2,   64,  8, [is_1d]);
419
641k
    case_sz(3,  128,  8, [is_1d]);
420
761k
    case_sz(4,  256, 16, [is_1d]);
421
302k
    case_sz(5,  512, 16,        );
422
786k
    case_sz(6, 1024, 16,        );
423
6.67M
#undef case_sz
424
6.67M
    }
425
6.73M
    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
6.73M
    if (eob > 1) {
429
4.22M
        const int eob_bin = eob - 2;
430
4.22M
        uint16_t *const eob_hi_bit_cdf =
431
4.22M
            ts->cdf.coef.eob_hi_bit[t_dim->ctx][chroma][eob_bin];
432
4.22M
        const int eob_hi_bit = dav1d_msac_decode_bool_adapt(&ts->msac, eob_hi_bit_cdf);
433
4.22M
        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
4.22M
        eob = ((eob_hi_bit | 2) << eob_bin) | dav1d_msac_decode_bools(&ts->msac, eob_bin);
437
4.22M
        if (dbg)
438
0
            printf("Post-eob[%d]: r=%d\n", eob, ts->msac.rng);
439
4.22M
    }
440
6.73M
    assert(eob >= 0);
441
442
    // base tokens
443
6.73M
    uint16_t (*const eob_cdf)[4] = ts->cdf.coef.eob_base_tok[t_dim->ctx][chroma];
444
6.73M
    uint16_t (*const hi_cdf)[4] = ts->cdf.coef.br_tok[imin(t_dim->ctx, 3)][chroma];
445
6.73M
    unsigned rc, dc_tok;
446
447
6.73M
    if (eob) {
448
4.44M
        uint16_t (*const lo_cdf)[4] = ts->cdf.coef.base_tok[t_dim->ctx][chroma];
449
4.44M
        uint8_t *const levels = t->scratch.levels; // bits 0-5: tok, 6-7: lo_tok
450
451
        /* eob */
452
4.44M
        unsigned ctx = 1 + (eob > 2 << tx2dszctx) + (eob > 4 << tx2dszctx);
453
4.44M
        int eob_tok = dav1d_msac_decode_symbol_adapt4(&ts->msac, eob_cdf[ctx], 2);
454
4.44M
        int tok = eob_tok + 1;
455
4.44M
        int level_tok = tok * 0x41;
456
4.44M
        unsigned mag;
457
458
4.44M
#define DECODE_COEFS_CLASS(tx_class) \
459
4.44M
        unsigned x, y; \
460
4.44M
        uint8_t *level; \
461
4.44M
        if (tx_class == TX_CLASS_2D) \
462
4.44M
            rc = scan[eob], x = rc >> shift, y = rc & mask; \
463
4.44M
        else if (tx_class == TX_CLASS_H) \
464
            /* Transposing reduces the stride and padding requirements */ \
465
469k
            x = eob & mask, y = eob >> shift, rc = eob; \
466
469k
        else /* tx_class == TX_CLASS_V */ \
467
469k
            x = eob & mask, y = eob >> shift, rc = (x << shift2) | y; \
468
4.44M
        if (dbg) \
469
4.44M
            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
4.44M
        if (eob_tok == 2) { \
472
99.4k
            ctx = (tx_class == TX_CLASS_2D ? (x | y) > 1 : y != 0) ? 14 : 7; \
473
99.4k
            tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[ctx]); \
474
99.4k
            level_tok = tok + (3 << 6); \
475
99.4k
            if (dbg) \
476
99.4k
                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
99.4k
        } \
480
4.44M
        cf[rc] = tok << 11; \
481
4.44M
        if (tx_class == TX_CLASS_2D) \
482
4.44M
            level = levels + rc; \
483
4.44M
        else \
484
4.44M
            level = levels + x * stride + y; \
485
4.44M
        *level = (uint8_t) level_tok; \
486
111M
        for (int i = eob - 1; i > 0; i--) { /* ac */ \
487
106M
            unsigned rc_i; \
488
106M
            if (tx_class == TX_CLASS_2D) \
489
106M
                rc_i = scan[i], x = rc_i >> shift, y = rc_i & mask; \
490
106M
            else if (tx_class == TX_CLASS_H) \
491
8.51M
                x = i & mask, y = i >> shift, rc_i = i; \
492
8.51M
            else /* tx_class == TX_CLASS_V */ \
493
8.51M
                x = i & mask, y = i >> shift, rc_i = (x << shift2) | y; \
494
106M
            assert(x < 32 && y < 32); \
495
106M
            if (tx_class == TX_CLASS_2D) \
496
106M
                level = levels + rc_i; \
497
106M
            else \
498
106M
                level = levels + x * stride + y; \
499
106M
            ctx = get_lo_ctx(level, tx_class, &mag, lo_ctx_offsets, x, y, stride); \
500
106M
            if (tx_class == TX_CLASS_2D) \
501
106M
                y |= x; \
502
106M
            tok = dav1d_msac_decode_symbol_adapt4(&ts->msac, lo_cdf[ctx], 3); \
503
106M
            if (dbg) \
504
106M
                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
106M
            if (tok == 3) { \
507
8.17M
                mag &= 63; \
508
8.17M
                ctx = (y > (tx_class == TX_CLASS_2D) ? 14 : 7) + \
509
8.17M
                      (mag > 12 ? 6 : (mag + 1) >> 1); \
510
8.17M
                tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[ctx]); \
511
8.17M
                if (dbg) \
512
8.17M
                    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
8.17M
                *level = (uint8_t) (tok + (3 << 6)); \
516
8.17M
                cf[rc_i] = (tok << 11) | rc; \
517
8.17M
                rc = rc_i; \
518
98.6M
            } else { \
519
                /* 0x1 for tok, 0x7ff as bitmask for rc, 0x41 for level_tok */ \
520
98.6M
                tok *= 0x17ff41; \
521
98.6M
                *level = (uint8_t) tok; \
522
                /* tok ? (tok << 11) | rc : 0 */ \
523
98.6M
                tok = (tok >> 9) & (rc + ~0x7ffu); \
524
98.6M
                if (tok) rc = rc_i; \
525
98.6M
                cf[rc_i] = tok; \
526
98.6M
            } \
527
106M
        } \
528
        /* dc */ \
529
4.44M
        ctx = (tx_class == TX_CLASS_2D) ? 0 : \
530
4.44M
            get_lo_ctx(levels, tx_class, &mag, lo_ctx_offsets, 0, 0, stride); \
531
4.44M
        dc_tok = dav1d_msac_decode_symbol_adapt4(&ts->msac, lo_cdf[ctx], 3); \
532
4.44M
        if (dbg) \
533
4.44M
            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
4.44M
        if (dc_tok == 3) { \
536
1.58M
            if (tx_class == TX_CLASS_2D) \
537
1.58M
                mag = levels[0 * stride + 1] + levels[1 * stride + 0] + \
538
1.54M
                      levels[1 * stride + 1]; \
539
1.58M
            mag &= 63; \
540
1.58M
            ctx = mag > 12 ? 6 : (mag + 1) >> 1; \
541
1.58M
            dc_tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[ctx]); \
542
1.58M
            if (dbg) \
543
1.58M
                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
1.58M
        } \
546
4.44M
        break
547
548
4.44M
        const uint16_t *scan;
549
4.44M
        switch (tx_class) {
550
3.96M
        case TX_CLASS_2D: {
551
3.96M
            const unsigned nonsquare_tx = tx >= RTX_4X8;
552
3.96M
            const uint8_t (*const lo_ctx_offsets)[5] =
553
3.96M
                dav1d_lo_ctx_offsets[nonsquare_tx + (tx & nonsquare_tx)];
554
3.96M
            scan = dav1d_scans[tx];
555
3.96M
            const ptrdiff_t stride = 4 << slh;
556
3.96M
            const unsigned shift = slh + 2, shift2 = 0;
557
3.96M
            const unsigned mask = (4 << slh) - 1;
558
3.96M
            memset(levels, 0, stride * ((4 << slw) + 2));
559
3.96M
            DECODE_COEFS_CLASS(TX_CLASS_2D);
560
3.96M
        }
561
305k
        case TX_CLASS_H: {
562
305k
            const uint8_t (*const lo_ctx_offsets)[5] = NULL;
563
305k
            const ptrdiff_t stride = 16;
564
305k
            const unsigned shift = slh + 2, shift2 = 0;
565
305k
            const unsigned mask = (4 << slh) - 1;
566
305k
            memset(levels, 0, stride * ((4 << slh) + 2));
567
305k
            DECODE_COEFS_CLASS(TX_CLASS_H);
568
305k
        }
569
175k
        case TX_CLASS_V: {
570
175k
            const uint8_t (*const lo_ctx_offsets)[5] = NULL;
571
175k
            const ptrdiff_t stride = 16;
572
175k
            const unsigned shift = slw + 2, shift2 = slh + 2;
573
175k
            const unsigned mask = (4 << slw) - 1;
574
175k
            memset(levels, 0, stride * ((4 << slw) + 2));
575
175k
            DECODE_COEFS_CLASS(TX_CLASS_V);
576
175k
        }
577
0
#undef DECODE_COEFS_CLASS
578
0
        default: assert(0);
579
4.44M
        }
580
4.44M
    } else { // dc-only
581
2.29M
        int tok_br = dav1d_msac_decode_symbol_adapt4(&ts->msac, eob_cdf[0], 2);
582
2.29M
        dc_tok = 1 + tok_br;
583
2.29M
        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
2.29M
        if (tok_br == 2) {
587
91.0k
            dc_tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[0]);
588
91.0k
            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
91.0k
        }
592
2.29M
        rc = 0;
593
2.29M
    }
594
595
    // residual and sign
596
6.75M
    const uint16_t *const dq_tbl = ts->dq[b->seg_id][plane];
597
6.75M
    const uint8_t *const qm_tbl = *txtp < IDTX ? f->qm[tx][plane] : NULL;
598
6.75M
    const int dq_shift = imax(0, t_dim->ctx - 2);
599
6.75M
    const int cf_max = ~(~127U << (BITDEPTH == 8 ? 8 : f->cur.p.bpc));
600
6.75M
    unsigned cul_level, dc_sign_level;
601
602
6.75M
    if (!dc_tok) {
603
1.17M
        cul_level = 0;
604
1.17M
        dc_sign_level = 1 << 6;
605
1.17M
        if (qm_tbl) goto ac_qm;
606
807k
        goto ac_noqm;
607
1.17M
    }
608
609
5.57M
    const int dc_sign_ctx = get_dc_sign_ctx(tx, a, l);
610
5.57M
    uint16_t *const dc_sign_cdf = ts->cdf.coef.dc_sign[chroma][dc_sign_ctx];
611
5.57M
    const int dc_sign = dav1d_msac_decode_bool_adapt(&ts->msac, dc_sign_cdf);
612
5.57M
    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
5.57M
    int dc_dq = dq_tbl[0];
617
5.57M
    dc_sign_level = (dc_sign - 1) & (2 << 6);
618
619
5.57M
    if (qm_tbl) {
620
1.97M
        dc_dq = (dc_dq * qm_tbl[0] + 16) >> 5;
621
622
1.97M
        if (dc_tok == 15) {
623
50.3k
            dc_tok = read_golomb(&ts->msac) + 15;
624
50.3k
            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
50.3k
            dc_tok &= 0xfffff;
629
50.3k
            dc_dq = (dc_dq * dc_tok) & 0xffffff;
630
1.91M
        } else {
631
1.91M
            dc_dq *= dc_tok;
632
1.91M
            assert(dc_dq <= 0xffffff);
633
1.91M
        }
634
1.97M
        cul_level = dc_tok;
635
1.97M
        dc_dq >>= dq_shift;
636
1.97M
        dc_dq = umin(dc_dq, cf_max + dc_sign);
637
1.97M
        cf[0] = (coef) (dc_sign ? -dc_dq : dc_dq);
638
639
2.85M
        if (rc) ac_qm: {
640
2.85M
            const unsigned ac_dq = dq_tbl[1];
641
18.8M
            do {
642
18.8M
                const int sign = dav1d_msac_decode_bool_equi(&ts->msac);
643
18.8M
                if (dbg)
644
0
                    printf("Post-sign[%d=%d]: r=%d\n", rc, sign, ts->msac.rng);
645
18.8M
                const unsigned rc_tok = cf[rc];
646
18.8M
                unsigned tok, dq = (ac_dq * qm_tbl[rc] + 16) >> 5;
647
18.8M
                int dq_sat;
648
649
18.8M
                if (rc_tok >= (15 << 11)) {
650
1.26M
                    tok = read_golomb(&ts->msac) + 15;
651
1.26M
                    if (dbg)
652
0
                        printf("Post-residual[%d=%d->%d]: r=%d\n",
653
0
                               rc, tok - 15, tok, ts->msac.rng);
654
655
1.26M
                    tok &= 0xfffff;
656
1.26M
                    dq = (dq * tok) & 0xffffff;
657
17.5M
                } else {
658
17.5M
                    tok = rc_tok >> 11;
659
17.5M
                    dq *= tok;
660
17.5M
                    assert(dq <= 0xffffff);
661
17.5M
                }
662
18.8M
                cul_level += tok;
663
18.8M
                dq >>= dq_shift;
664
18.8M
                dq_sat = umin(dq, cf_max + sign);
665
18.8M
                cf[rc] = (coef) (sign ? -dq_sat : dq_sat);
666
667
18.8M
                rc = rc_tok & 0x3ff;
668
18.8M
            } while (rc);
669
2.85M
        }
670
3.60M
    } else {
671
        // non-qmatrix is the common case and allows for additional optimizations
672
3.60M
        if (dc_tok == 15) {
673
111k
            dc_tok = read_golomb(&ts->msac) + 15;
674
111k
            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
111k
            dc_tok &= 0xfffff;
679
111k
            dc_dq = ((dc_dq * dc_tok) & 0xffffff) >> dq_shift;
680
111k
            dc_dq = umin(dc_dq, cf_max + dc_sign);
681
3.49M
        } else {
682
3.49M
            dc_dq = ((dc_dq * dc_tok) >> dq_shift);
683
3.49M
            assert(dc_dq <= cf_max);
684
3.49M
        }
685
3.60M
        cul_level = dc_tok;
686
3.60M
        cf[0] = (coef) (dc_sign ? -dc_dq : dc_dq);
687
688
4.91M
        if (rc) ac_noqm: {
689
4.91M
            const unsigned ac_dq = dq_tbl[1];
690
21.7M
            do {
691
21.7M
                const int sign = dav1d_msac_decode_bool_equi(&ts->msac);
692
21.7M
                if (dbg)
693
0
                    printf("Post-sign[%d=%d]: r=%d\n", rc, sign, ts->msac.rng);
694
21.7M
                const unsigned rc_tok = cf[rc];
695
21.7M
                unsigned tok;
696
21.7M
                int dq;
697
698
                // residual
699
21.7M
                if (rc_tok >= (15 << 11)) {
700
385k
                    tok = read_golomb(&ts->msac) + 15;
701
385k
                    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
385k
                    tok &= 0xfffff;
707
708
                    // dequant, see 7.12.3
709
385k
                    dq = ((ac_dq * tok) & 0xffffff) >> dq_shift;
710
385k
                    dq = umin(dq, cf_max + sign);
711
21.3M
                } else {
712
                    // cannot exceed cf_max, so we can avoid the clipping
713
21.3M
                    tok = rc_tok >> 11;
714
21.3M
                    dq = ((ac_dq * tok) >> dq_shift);
715
21.3M
                    assert(dq <= cf_max);
716
21.3M
                }
717
21.7M
                cul_level += tok;
718
21.7M
                cf[rc] = (coef) (sign ? -dq : dq);
719
720
21.7M
                rc = rc_tok & 0x3ff; // next non-zero rc, zero if eob
721
21.7M
            } while (rc);
722
4.91M
        }
723
3.60M
    }
724
725
    // context
726
6.73M
    *res_ctx = umin(cul_level, 63) | dc_sign_level;
727
728
6.73M
    return eob;
729
5.57M
}
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
3.23M
{
737
3.23M
    const Dav1dFrameContext *const f = t->f;
738
3.23M
    Dav1dTileState *const ts = t->ts;
739
3.23M
    const Dav1dDSPContext *const dsp = f->dsp;
740
3.23M
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[ytx];
741
3.23M
    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
3.23M
    if (depth < 2 && tx_split[depth] &&
746
307k
        tx_split[depth] & (1 << (y_off * 4 + x_off)))
747
243k
    {
748
243k
        const enum RectTxfmSize sub = t_dim->sub;
749
243k
        const TxfmInfo *const sub_t_dim = &dav1d_txfm_dimensions[sub];
750
243k
        const int txsw = sub_t_dim->w, txsh = sub_t_dim->h;
751
752
243k
        read_coef_tree(t, bs, b, sub, depth + 1, tx_split,
753
243k
                       x_off * 2 + 0, y_off * 2 + 0, dst);
754
243k
        t->bx += txsw;
755
243k
        if (txw >= txh && t->bx < f->bw)
756
177k
            read_coef_tree(t, bs, b, sub, depth + 1, tx_split, x_off * 2 + 1,
757
177k
                           y_off * 2 + 0, dst ? &dst[4 * txsw] : NULL);
758
243k
        t->bx -= txsw;
759
243k
        t->by += txsh;
760
243k
        if (txh >= txw && t->by < f->bh) {
761
169k
            if (dst)
762
62.6k
                dst += 4 * txsh * PXSTRIDE(f->cur.stride[0]);
763
169k
            read_coef_tree(t, bs, b, sub, depth + 1, tx_split,
764
169k
                           x_off * 2 + 0, y_off * 2 + 1, dst);
765
169k
            t->bx += txsw;
766
169k
            if (txw >= txh && t->bx < f->bw)
767
106k
                read_coef_tree(t, bs, b, sub, depth + 1, tx_split, x_off * 2 + 1,
768
106k
                               y_off * 2 + 1, dst ? &dst[4 * txsw] : NULL);
769
169k
            t->bx -= txsw;
770
169k
        }
771
243k
        t->by -= txsh;
772
2.98M
    } else {
773
2.98M
        const int bx4 = t->bx & 31, by4 = t->by & 31;
774
2.98M
        enum TxfmType txtp;
775
2.98M
        uint8_t cf_ctx;
776
2.98M
        int eob;
777
2.98M
        coef *cf;
778
779
2.98M
        if (t->frame_thread.pass) {
780
2.98M
            const int p = t->frame_thread.pass & 1;
781
2.98M
            assert(ts->frame_thread[p].cf);
782
2.98M
            cf = ts->frame_thread[p].cf;
783
2.98M
            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
2.98M
        if (t->frame_thread.pass != 2) {
788
1.91M
            eob = decode_coefs(t, &t->a->lcoef[bx4], &t->l.lcoef[by4],
789
1.91M
                               ytx, bs, b, 0, 0, cf, &txtp, &cf_ctx);
790
1.91M
            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
1.91M
            dav1d_memset_likely_pow2(&t->a->lcoef[bx4], cf_ctx, imin(txw, f->bw - t->bx));
794
1.91M
            dav1d_memset_likely_pow2(&t->l.lcoef[by4], cf_ctx, imin(txh, f->bh - t->by));
795
1.91M
#define set_ctx(rep_macro) \
796
7.91M
            for (int y = 0; y < txh; y++) { \
797
5.99M
                rep_macro(txtp_map, 0, txtp); \
798
5.99M
                txtp_map += 32; \
799
5.99M
            }
800
1.91M
            uint8_t *txtp_map = &t->scratch.txtp_map[by4 * 32 + bx4];
801
1.91M
            case_set_upto16(t_dim->lw);
802
1.91M
#undef set_ctx
803
1.91M
            if (t->frame_thread.pass == 1)
804
1.91M
                *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
805
1.91M
        } else {
806
1.07M
            const int cbi = *ts->frame_thread[0].cbi++;
807
1.07M
            eob  = cbi >> 5;
808
1.07M
            txtp = cbi & 0x1f;
809
1.07M
        }
810
2.98M
        if (!(t->frame_thread.pass & 1)) {
811
1.07M
            assert(dst);
812
1.07M
            if (eob >= 0) {
813
835k
                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
835k
                dsp->itx.itxfm_add[ytx][txtp](dst, f->cur.stride[0], cf, eob
816
835k
                                              HIGHBD_CALL_SUFFIX);
817
835k
                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
835k
            }
820
1.07M
        }
821
2.98M
    }
822
3.23M
}
823
824
void bytefn(dav1d_read_coef_blocks)(Dav1dTaskContext *const t,
825
                                    const enum BlockSize bs, const Av1Block *const b)
826
7.16M
{
827
7.16M
    const Dav1dFrameContext *const f = t->f;
828
7.16M
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
829
7.16M
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
830
7.16M
    const int bx4 = t->bx & 31, by4 = t->by & 31;
831
7.16M
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
832
7.16M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
833
7.16M
    const int bw4 = b_dim[0], bh4 = b_dim[1];
834
7.16M
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
835
7.16M
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
836
5.85M
                           (bw4 > ss_hor || t->bx & 1) &&
837
5.45M
                           (bh4 > ss_ver || t->by & 1);
838
839
7.16M
    if (b->skip) {
840
3.95M
        BlockContext *const a = t->a;
841
3.95M
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
842
3.95M
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
843
3.95M
        if (has_chroma) {
844
2.85M
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
845
2.85M
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
846
2.85M
            memset_cw(&a->ccoef[0][cbx4], 0x40);
847
2.85M
            memset_cw(&a->ccoef[1][cbx4], 0x40);
848
2.85M
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
849
2.85M
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
850
2.85M
        }
851
3.95M
        return;
852
3.95M
    }
853
854
3.20M
    Dav1dTileState *const ts = t->ts;
855
3.20M
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
856
3.20M
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
857
3.20M
    assert(t->frame_thread.pass == 1);
858
3.20M
    assert(!b->skip);
859
3.20M
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
860
3.20M
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->intra ? b->tx : b->max_ytx];
861
3.20M
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
862
863
6.51M
    for (int init_y = 0; init_y < h4; init_y += 16) {
864
3.30M
        const int sub_h4 = imin(h4, 16 + init_y);
865
6.74M
        for (int init_x = 0; init_x < w4; init_x += 16) {
866
3.43M
            const int sub_w4 = imin(w4, init_x + 16);
867
3.43M
            int y_off = !!init_y, y, x;
868
7.34M
            for (y = init_y, t->by += init_y; y < sub_h4;
869
3.91M
                 y += t_dim->h, t->by += t_dim->h, y_off++)
870
3.91M
            {
871
3.91M
                int x_off = !!init_x;
872
9.94M
                for (x = init_x, t->bx += init_x; x < sub_w4;
873
6.03M
                     x += t_dim->w, t->bx += t_dim->w, x_off++)
874
6.03M
                {
875
6.03M
                    if (!b->intra) {
876
1.62M
                        read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
877
1.62M
                                       x_off, y_off, NULL);
878
4.41M
                    } else {
879
4.41M
                        uint8_t cf_ctx = 0x40;
880
4.41M
                        enum TxfmType txtp;
881
4.41M
                        const int eob =
882
4.41M
                            decode_coefs(t, &t->a->lcoef[bx4 + x],
883
4.41M
                                         &t->l.lcoef[by4 + y], b->tx, bs, b, 1,
884
4.41M
                                         0, ts->frame_thread[1].cf, &txtp, &cf_ctx);
885
4.41M
                        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
4.41M
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
889
4.41M
                        ts->frame_thread[1].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
890
4.41M
                        dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
891
4.41M
                        dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
892
4.41M
                    }
893
6.03M
                }
894
3.91M
                t->bx -= x;
895
3.91M
            }
896
3.43M
            t->by -= y;
897
898
3.43M
            if (!has_chroma) continue;
899
900
2.40M
            const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
901
2.40M
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
902
7.22M
            for (int pl = 0; pl < 2; pl++) {
903
10.0M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
904
5.23M
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
905
5.23M
                {
906
11.8M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
907
6.63M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
908
6.63M
                    {
909
6.63M
                        uint8_t cf_ctx = 0x40;
910
6.63M
                        enum TxfmType txtp;
911
6.63M
                        if (!b->intra)
912
2.24M
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
913
2.24M
                                                        bx4 + (x << ss_hor)];
914
6.63M
                        const int eob =
915
6.63M
                            decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
916
6.63M
                                         &t->l.ccoef[pl][cby4 + y], b->uvtx, bs,
917
6.63M
                                         b, b->intra, 1 + pl, ts->frame_thread[1].cf,
918
6.63M
                                         &txtp, &cf_ctx);
919
6.63M
                        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
6.63M
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
924
6.63M
                        ts->frame_thread[1].cf += uv_t_dim->w * uv_t_dim->h * 16;
925
6.63M
                        int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
926
6.63M
                        int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
927
6.63M
                        dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
928
6.63M
                        dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
929
6.63M
                    }
930
5.23M
                    t->bx -= x << ss_hor;
931
5.23M
                }
932
4.81M
                t->by -= y << ss_ver;
933
4.81M
            }
934
2.40M
        }
935
3.30M
    }
936
3.20M
}
dav1d_read_coef_blocks_8bpc
Line
Count
Source
826
3.48M
{
827
3.48M
    const Dav1dFrameContext *const f = t->f;
828
3.48M
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
829
3.48M
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
830
3.48M
    const int bx4 = t->bx & 31, by4 = t->by & 31;
831
3.48M
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
832
3.48M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
833
3.48M
    const int bw4 = b_dim[0], bh4 = b_dim[1];
834
3.48M
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
835
3.48M
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
836
3.10M
                           (bw4 > ss_hor || t->bx & 1) &&
837
2.86M
                           (bh4 > ss_ver || t->by & 1);
838
839
3.48M
    if (b->skip) {
840
1.99M
        BlockContext *const a = t->a;
841
1.99M
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
842
1.99M
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
843
1.99M
        if (has_chroma) {
844
1.45M
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
845
1.45M
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
846
1.45M
            memset_cw(&a->ccoef[0][cbx4], 0x40);
847
1.45M
            memset_cw(&a->ccoef[1][cbx4], 0x40);
848
1.45M
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
849
1.45M
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
850
1.45M
        }
851
1.99M
        return;
852
1.99M
    }
853
854
1.48M
    Dav1dTileState *const ts = t->ts;
855
1.48M
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
856
1.48M
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
857
1.48M
    assert(t->frame_thread.pass == 1);
858
1.48M
    assert(!b->skip);
859
1.48M
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
860
1.48M
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->intra ? b->tx : b->max_ytx];
861
1.48M
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
862
863
3.02M
    for (int init_y = 0; init_y < h4; init_y += 16) {
864
1.53M
        const int sub_h4 = imin(h4, 16 + init_y);
865
3.12M
        for (int init_x = 0; init_x < w4; init_x += 16) {
866
1.59M
            const int sub_w4 = imin(w4, init_x + 16);
867
1.59M
            int y_off = !!init_y, y, x;
868
3.36M
            for (y = init_y, t->by += init_y; y < sub_h4;
869
1.77M
                 y += t_dim->h, t->by += t_dim->h, y_off++)
870
1.77M
            {
871
1.77M
                int x_off = !!init_x;
872
4.34M
                for (x = init_x, t->bx += init_x; x < sub_w4;
873
2.56M
                     x += t_dim->w, t->bx += t_dim->w, x_off++)
874
2.56M
                {
875
2.56M
                    if (!b->intra) {
876
724k
                        read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
877
724k
                                       x_off, y_off, NULL);
878
1.84M
                    } else {
879
1.84M
                        uint8_t cf_ctx = 0x40;
880
1.84M
                        enum TxfmType txtp;
881
1.84M
                        const int eob =
882
1.84M
                            decode_coefs(t, &t->a->lcoef[bx4 + x],
883
1.84M
                                         &t->l.lcoef[by4 + y], b->tx, bs, b, 1,
884
1.84M
                                         0, ts->frame_thread[1].cf, &txtp, &cf_ctx);
885
1.84M
                        if (DEBUG_BLOCK_INFO)
886
0
                            printf("Post-y-cf-blk[tx=%d,txtp=%d,eob=%d]: r=%d\n",
887
0
                                   b->tx, txtp, eob, ts->msac.rng);
888
1.84M
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
889
1.84M
                        ts->frame_thread[1].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
890
1.84M
                        dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
891
1.84M
                        dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
892
1.84M
                    }
893
2.56M
                }
894
1.77M
                t->bx -= x;
895
1.77M
            }
896
1.59M
            t->by -= y;
897
898
1.59M
            if (!has_chroma) continue;
899
900
1.29M
            const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
901
1.29M
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
902
3.88M
            for (int pl = 0; pl < 2; pl++) {
903
5.33M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
904
2.75M
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
905
2.75M
                {
906
6.01M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
907
3.25M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
908
3.25M
                    {
909
3.25M
                        uint8_t cf_ctx = 0x40;
910
3.25M
                        enum TxfmType txtp;
911
3.25M
                        if (!b->intra)
912
1.10M
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
913
1.10M
                                                        bx4 + (x << ss_hor)];
914
3.25M
                        const int eob =
915
3.25M
                            decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
916
3.25M
                                         &t->l.ccoef[pl][cby4 + y], b->uvtx, bs,
917
3.25M
                                         b, b->intra, 1 + pl, ts->frame_thread[1].cf,
918
3.25M
                                         &txtp, &cf_ctx);
919
3.25M
                        if (DEBUG_BLOCK_INFO)
920
0
                            printf("Post-uv-cf-blk[pl=%d,tx=%d,"
921
0
                                   "txtp=%d,eob=%d]: r=%d\n",
922
0
                                   pl, b->uvtx, txtp, eob, ts->msac.rng);
923
3.25M
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
924
3.25M
                        ts->frame_thread[1].cf += uv_t_dim->w * uv_t_dim->h * 16;
925
3.25M
                        int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
926
3.25M
                        int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
927
3.25M
                        dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
928
3.25M
                        dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
929
3.25M
                    }
930
2.75M
                    t->bx -= x << ss_hor;
931
2.75M
                }
932
2.58M
                t->by -= y << ss_ver;
933
2.58M
            }
934
1.29M
        }
935
1.53M
    }
936
1.48M
}
dav1d_read_coef_blocks_16bpc
Line
Count
Source
826
3.67M
{
827
3.67M
    const Dav1dFrameContext *const f = t->f;
828
3.67M
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
829
3.67M
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
830
3.67M
    const int bx4 = t->bx & 31, by4 = t->by & 31;
831
3.67M
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
832
3.67M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
833
3.67M
    const int bw4 = b_dim[0], bh4 = b_dim[1];
834
3.67M
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
835
3.67M
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
836
2.75M
                           (bw4 > ss_hor || t->bx & 1) &&
837
2.58M
                           (bh4 > ss_ver || t->by & 1);
838
839
3.67M
    if (b->skip) {
840
1.95M
        BlockContext *const a = t->a;
841
1.95M
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
842
1.95M
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
843
1.95M
        if (has_chroma) {
844
1.39M
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
845
1.39M
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
846
1.39M
            memset_cw(&a->ccoef[0][cbx4], 0x40);
847
1.39M
            memset_cw(&a->ccoef[1][cbx4], 0x40);
848
1.39M
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
849
1.39M
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
850
1.39M
        }
851
1.95M
        return;
852
1.95M
    }
853
854
1.71M
    Dav1dTileState *const ts = t->ts;
855
1.71M
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
856
1.71M
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
857
1.71M
    assert(t->frame_thread.pass == 1);
858
1.71M
    assert(!b->skip);
859
1.71M
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
860
1.71M
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->intra ? b->tx : b->max_ytx];
861
1.71M
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
862
863
3.49M
    for (int init_y = 0; init_y < h4; init_y += 16) {
864
1.77M
        const int sub_h4 = imin(h4, 16 + init_y);
865
3.61M
        for (int init_x = 0; init_x < w4; init_x += 16) {
866
1.84M
            const int sub_w4 = imin(w4, init_x + 16);
867
1.84M
            int y_off = !!init_y, y, x;
868
3.98M
            for (y = init_y, t->by += init_y; y < sub_h4;
869
2.13M
                 y += t_dim->h, t->by += t_dim->h, y_off++)
870
2.13M
            {
871
2.13M
                int x_off = !!init_x;
872
5.60M
                for (x = init_x, t->bx += init_x; x < sub_w4;
873
3.46M
                     x += t_dim->w, t->bx += t_dim->w, x_off++)
874
3.46M
                {
875
3.46M
                    if (!b->intra) {
876
899k
                        read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
877
899k
                                       x_off, y_off, NULL);
878
2.56M
                    } else {
879
2.56M
                        uint8_t cf_ctx = 0x40;
880
2.56M
                        enum TxfmType txtp;
881
2.56M
                        const int eob =
882
2.56M
                            decode_coefs(t, &t->a->lcoef[bx4 + x],
883
2.56M
                                         &t->l.lcoef[by4 + y], b->tx, bs, b, 1,
884
2.56M
                                         0, ts->frame_thread[1].cf, &txtp, &cf_ctx);
885
2.56M
                        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
2.56M
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
889
2.56M
                        ts->frame_thread[1].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
890
2.56M
                        dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
891
2.56M
                        dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
892
2.56M
                    }
893
3.46M
                }
894
2.13M
                t->bx -= x;
895
2.13M
            }
896
1.84M
            t->by -= y;
897
898
1.84M
            if (!has_chroma) continue;
899
900
1.11M
            const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
901
1.11M
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
902
3.33M
            for (int pl = 0; pl < 2; pl++) {
903
4.70M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
904
2.48M
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
905
2.48M
                {
906
5.85M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
907
3.37M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
908
3.37M
                    {
909
3.37M
                        uint8_t cf_ctx = 0x40;
910
3.37M
                        enum TxfmType txtp;
911
3.37M
                        if (!b->intra)
912
1.14M
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
913
1.14M
                                                        bx4 + (x << ss_hor)];
914
3.37M
                        const int eob =
915
3.37M
                            decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
916
3.37M
                                         &t->l.ccoef[pl][cby4 + y], b->uvtx, bs,
917
3.37M
                                         b, b->intra, 1 + pl, ts->frame_thread[1].cf,
918
3.37M
                                         &txtp, &cf_ctx);
919
3.37M
                        if (DEBUG_BLOCK_INFO)
920
0
                            printf("Post-uv-cf-blk[pl=%d,tx=%d,"
921
0
                                   "txtp=%d,eob=%d]: r=%d\n",
922
0
                                   pl, b->uvtx, txtp, eob, ts->msac.rng);
923
3.37M
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
924
3.37M
                        ts->frame_thread[1].cf += uv_t_dim->w * uv_t_dim->h * 16;
925
3.37M
                        int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
926
3.37M
                        int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
927
3.37M
                        dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
928
3.37M
                        dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
929
3.37M
                    }
930
2.48M
                    t->bx -= x << ss_hor;
931
2.48M
                }
932
2.22M
                t->by -= y << ss_ver;
933
2.22M
            }
934
1.11M
        }
935
1.77M
    }
936
1.71M
}
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
3.91M
{
945
3.91M
    assert((dst8 != NULL) ^ (dst16 != NULL));
946
3.91M
    const Dav1dFrameContext *const f = t->f;
947
3.91M
    const int ss_ver = !!pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
948
3.91M
    const int ss_hor = !!pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
949
3.91M
    const int h_mul = 4 >> ss_hor, v_mul = 4 >> ss_ver;
950
3.91M
    const int mvx = mv.x, mvy = mv.y;
951
3.91M
    const int mx = mvx & (15 >> !ss_hor), my = mvy & (15 >> !ss_ver);
952
3.91M
    ptrdiff_t ref_stride = refp->p.stride[!!pl];
953
3.91M
    const pixel *ref;
954
955
3.91M
    if (refp->p.p.w == f->cur.p.w && refp->p.p.h == f->cur.p.h) {
956
2.08M
        const int dx = bx * h_mul + (mvx >> (3 + ss_hor));
957
2.08M
        const int dy = by * v_mul + (mvy >> (3 + ss_ver));
958
2.08M
        int w, h;
959
960
2.08M
        if (refp->p.data[0] != f->cur.data[0]) { // i.e. not for intrabc
961
1.22M
            w = (f->cur.p.w + ss_hor) >> ss_hor;
962
1.22M
            h = (f->cur.p.h + ss_ver) >> ss_ver;
963
1.22M
        } else {
964
860k
            w = f->bw * 4 >> ss_hor;
965
860k
            h = f->bh * 4 >> ss_ver;
966
860k
        }
967
2.08M
        if (dx < !!mx * 3 || dy < !!my * 3 ||
968
1.70M
            dx + bw4 * h_mul + !!mx * 4 > w ||
969
1.07M
            dy + bh4 * v_mul + !!my * 4 > h)
970
1.09M
        {
971
1.09M
            pixel *const emu_edge_buf = bitfn(t->scratch.emu_edge);
972
1.09M
            f->dsp->mc.emu_edge(bw4 * h_mul + !!mx * 7, bh4 * v_mul + !!my * 7,
973
1.09M
                                w, h, dx - !!mx * 3, dy - !!my * 3,
974
1.09M
                                emu_edge_buf, 192 * sizeof(pixel),
975
1.09M
                                refp->p.data[pl], ref_stride);
976
1.09M
            ref = &emu_edge_buf[192 * !!my * 3 + !!mx * 3];
977
1.09M
            ref_stride = 192 * sizeof(pixel);
978
1.09M
        } else {
979
995k
            ref = ((pixel *) refp->p.data[pl]) + PXSTRIDE(ref_stride) * dy + dx;
980
995k
        }
981
982
2.08M
        if (dst8 != NULL) {
983
1.80M
            f->dsp->mc.mc[filter_2d](dst8, dst_stride, ref, ref_stride, bw4 * h_mul,
984
1.80M
                                     bh4 * v_mul, mx << !ss_hor, my << !ss_ver
985
1.80M
                                     HIGHBD_CALL_SUFFIX);
986
1.80M
        } else {
987
283k
            f->dsp->mc.mct[filter_2d](dst16, ref, ref_stride, bw4 * h_mul,
988
283k
                                      bh4 * v_mul, mx << !ss_hor, my << !ss_ver
989
283k
                                      HIGHBD_CALL_SUFFIX);
990
283k
        }
991
2.08M
    } else {
992
1.82M
        assert(refp != &f->sr_cur);
993
994
1.82M
        const int orig_pos_y = (by * v_mul << 4) + mvy * (1 << !ss_ver);
995
1.82M
        const int orig_pos_x = (bx * h_mul << 4) + mvx * (1 << !ss_hor);
996
3.65M
#define scale_mv(res, val, scale) do { \
997
3.65M
            const int64_t tmp = (int64_t)(val) * scale + (scale - 0x4000) * 8; \
998
3.65M
            res = apply_sign64((int) ((llabs(tmp) + 128) >> 8), tmp) + 32;     \
999
3.65M
        } while (0)
1000
1.82M
        int pos_y, pos_x;
1001
1.82M
        scale_mv(pos_x, orig_pos_x, f->svc[refidx][0].scale);
1002
1.82M
        scale_mv(pos_y, orig_pos_y, f->svc[refidx][1].scale);
1003
1.82M
#undef scale_mv
1004
1.82M
        const int left = pos_x >> 10;
1005
1.82M
        const int top = pos_y >> 10;
1006
1.82M
        const int right =
1007
1.82M
            ((pos_x + (bw4 * h_mul - 1) * f->svc[refidx][0].step) >> 10) + 1;
1008
1.82M
        const int bottom =
1009
1.82M
            ((pos_y + (bh4 * v_mul - 1) * f->svc[refidx][1].step) >> 10) + 1;
1010
1011
1.82M
        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
1.82M
        const int w = (refp->p.p.w + ss_hor) >> ss_hor;
1018
1.82M
        const int h = (refp->p.p.h + ss_ver) >> ss_ver;
1019
1.82M
        if (left < 3 || top < 3 || right + 4 > w || bottom + 4 > h) {
1020
892k
            pixel *const emu_edge_buf = bitfn(t->scratch.emu_edge);
1021
892k
            f->dsp->mc.emu_edge(right - left + 7, bottom - top + 7,
1022
892k
                                w, h, left - 3, top - 3,
1023
892k
                                emu_edge_buf, 320 * sizeof(pixel),
1024
892k
                                refp->p.data[pl], ref_stride);
1025
892k
            ref = &emu_edge_buf[320 * 3 + 3];
1026
892k
            ref_stride = 320 * sizeof(pixel);
1027
892k
            if (DEBUG_BLOCK_INFO) printf("Emu\n");
1028
936k
        } else {
1029
936k
            ref = ((pixel *) refp->p.data[pl]) + PXSTRIDE(ref_stride) * top + left;
1030
936k
        }
1031
1032
1.82M
        if (dst8 != NULL) {
1033
1.46M
            f->dsp->mc.mc_scaled[filter_2d](dst8, dst_stride, ref, ref_stride,
1034
1.46M
                                            bw4 * h_mul, bh4 * v_mul,
1035
1.46M
                                            pos_x & 0x3ff, pos_y & 0x3ff,
1036
1.46M
                                            f->svc[refidx][0].step,
1037
1.46M
                                            f->svc[refidx][1].step
1038
1.46M
                                            HIGHBD_CALL_SUFFIX);
1039
1.46M
        } else {
1040
365k
            f->dsp->mc.mct_scaled[filter_2d](dst16, ref, ref_stride,
1041
365k
                                             bw4 * h_mul, bh4 * v_mul,
1042
365k
                                             pos_x & 0x3ff, pos_y & 0x3ff,
1043
365k
                                             f->svc[refidx][0].step,
1044
365k
                                             f->svc[refidx][1].step
1045
365k
                                             HIGHBD_CALL_SUFFIX);
1046
365k
        }
1047
1.82M
    }
1048
1049
3.91M
    return 0;
1050
3.91M
}
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
372k
{
1057
372k
    assert(!(t->bx & 1) && !(t->by & 1));
1058
372k
    const Dav1dFrameContext *const f = t->f;
1059
372k
    /*const*/ refmvs_block **r = &t->rt.r[(t->by & 31) + 5];
1060
372k
    pixel *const lap = bitfn(t->scratch.lap);
1061
372k
    const int ss_ver = !!pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1062
372k
    const int ss_hor = !!pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1063
372k
    const int h_mul = 4 >> ss_hor, v_mul = 4 >> ss_ver;
1064
372k
    int res;
1065
1066
372k
    if (t->by > t->ts->tiling.row_start &&
1067
323k
        (!pl || b_dim[0] * h_mul + b_dim[1] * v_mul >= 16))
1068
264k
    {
1069
553k
        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
288k
            const refmvs_block *const a_r = &r[-1][t->bx + x + 1];
1072
288k
            const uint8_t *const a_b_dim = dav1d_block_dimensions[a_r->bs];
1073
288k
            const int step4 = iclip(a_b_dim[0], 2, 16);
1074
1075
288k
            if (a_r->ref.ref[0] > 0) {
1076
283k
                const int ow4 = imin(step4, b_dim[0]);
1077
283k
                const int oh4 = imin(b_dim[1], 16) >> 1;
1078
283k
                res = mc(t, lap, NULL, ow4 * h_mul * sizeof(pixel), ow4, (oh4 * 3 + 3) >> 2,
1079
283k
                         t->bx + x, t->by, pl, a_r->mv.mv[0],
1080
283k
                         &f->refp[a_r->ref.ref[0] - 1], a_r->ref.ref[0] - 1,
1081
283k
                         dav1d_filter_2d[t->a->filter[1][bx4 + x + 1]][t->a->filter[0][bx4 + x + 1]]);
1082
283k
                if (res) return res;
1083
283k
                f->dsp->mc.blend_h(&dst[x * h_mul], dst_stride, lap,
1084
283k
                                   h_mul * ow4, v_mul * oh4);
1085
283k
                i++;
1086
283k
            }
1087
288k
            x += step4;
1088
288k
        }
1089
264k
    }
1090
1091
372k
    if (t->bx > t->ts->tiling.col_start)
1092
553k
        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
289k
            const refmvs_block *const l_r = &r[y + 1][t->bx - 1];
1095
289k
            const uint8_t *const l_b_dim = dav1d_block_dimensions[l_r->bs];
1096
289k
            const int step4 = iclip(l_b_dim[1], 2, 16);
1097
1098
289k
            if (l_r->ref.ref[0] > 0) {
1099
284k
                const int ow4 = imin(b_dim[0], 16) >> 1;
1100
284k
                const int oh4 = imin(step4, b_dim[1]);
1101
284k
                res = mc(t, lap, NULL, h_mul * ow4 * sizeof(pixel), ow4, oh4,
1102
284k
                         t->bx, t->by + y, pl, l_r->mv.mv[0],
1103
284k
                         &f->refp[l_r->ref.ref[0] - 1], l_r->ref.ref[0] - 1,
1104
284k
                         dav1d_filter_2d[t->l.filter[1][by4 + y + 1]][t->l.filter[0][by4 + y + 1]]);
1105
284k
                if (res) return res;
1106
284k
                f->dsp->mc.blend_v(&dst[y * v_mul * PXSTRIDE(dst_stride)],
1107
284k
                                   dst_stride, lap, h_mul * ow4, v_mul * oh4);
1108
284k
                i++;
1109
284k
            }
1110
289k
            y += step4;
1111
289k
        }
1112
372k
    return 0;
1113
372k
}
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
66.1k
{
1121
66.1k
    assert((dst8 != NULL) ^ (dst16 != NULL));
1122
66.1k
    const Dav1dFrameContext *const f = t->f;
1123
66.1k
    const Dav1dDSPContext *const dsp = f->dsp;
1124
66.1k
    const int ss_ver = !!pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1125
66.1k
    const int ss_hor = !!pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1126
66.1k
    const int h_mul = 4 >> ss_hor, v_mul = 4 >> ss_ver;
1127
66.1k
    assert(!((b_dim[0] * h_mul) & 7) && !((b_dim[1] * v_mul) & 7));
1128
66.1k
    const int32_t *const mat = wmp->matrix;
1129
66.1k
    const int width = (refp->p.p.w + ss_hor) >> ss_hor;
1130
66.1k
    const int height = (refp->p.p.h + ss_ver) >> ss_ver;
1131
1132
269k
    for (int y = 0; y < b_dim[1] * v_mul; y += 8) {
1133
203k
        const int src_y = t->by * 4 + ((y + 4) << ss_ver);
1134
203k
        const int64_t mat3_y = (int64_t) mat[3] * src_y + mat[0];
1135
203k
        const int64_t mat5_y = (int64_t) mat[5] * src_y + mat[1];
1136
791k
        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
588k
            const int src_x = t->bx * 4 + ((x + 4) << ss_hor);
1140
588k
            const int64_t mvx = ((int64_t) mat[2] * src_x + mat3_y) >> ss_hor;
1141
588k
            const int64_t mvy = ((int64_t) mat[4] * src_x + mat5_y) >> ss_ver;
1142
1143
588k
            const int dx = (int) (mvx >> 16) - 4;
1144
588k
            const int mx = (((int) mvx & 0xffff) - wmp->u.p.alpha * 4 -
1145
588k
                                                   wmp->u.p.beta  * 7) & ~0x3f;
1146
588k
            const int dy = (int) (mvy >> 16) - 4;
1147
588k
            const int my = (((int) mvy & 0xffff) - wmp->u.p.gamma * 4 -
1148
588k
                                                   wmp->u.p.delta * 4) & ~0x3f;
1149
1150
588k
            const pixel *ref_ptr;
1151
588k
            ptrdiff_t ref_stride = refp->p.stride[!!pl];
1152
1153
588k
            if (dx < 3 || dx + 8 + 4 > width || dy < 3 || dy + 8 + 4 > height) {
1154
504k
                pixel *const emu_edge_buf = bitfn(t->scratch.emu_edge);
1155
504k
                f->dsp->mc.emu_edge(15, 15, width, height, dx - 3, dy - 3,
1156
504k
                                    emu_edge_buf, 32 * sizeof(pixel),
1157
504k
                                    refp->p.data[pl], ref_stride);
1158
504k
                ref_ptr = &emu_edge_buf[32 * 3 + 3];
1159
504k
                ref_stride = 32 * sizeof(pixel);
1160
504k
            } else {
1161
84.2k
                ref_ptr = ((pixel *) refp->p.data[pl]) + PXSTRIDE(ref_stride) * dy + dx;
1162
84.2k
            }
1163
588k
            if (dst16 != NULL)
1164
156k
                dsp->mc.warp8x8t(&dst16[x], dstride, ref_ptr, ref_stride,
1165
156k
                                 wmp->u.abcd, mx, my HIGHBD_CALL_SUFFIX);
1166
431k
            else
1167
431k
                dsp->mc.warp8x8(&dst8[x], dstride, ref_ptr, ref_stride,
1168
431k
                                wmp->u.abcd, mx, my HIGHBD_CALL_SUFFIX);
1169
588k
        }
1170
203k
        if (dst8) dst8  += 8 * PXSTRIDE(dstride);
1171
54.1k
        else      dst16 += 8 * dstride;
1172
203k
    }
1173
66.1k
    return 0;
1174
66.1k
}
1175
1176
void bytefn(dav1d_recon_b_intra)(Dav1dTaskContext *const t, const enum BlockSize bs,
1177
                                 const enum EdgeFlags intra_edge_flags,
1178
                                 const Av1Block *const b)
1179
2.96M
{
1180
2.96M
    Dav1dTileState *const ts = t->ts;
1181
2.96M
    const Dav1dFrameContext *const f = t->f;
1182
2.96M
    const Dav1dDSPContext *const dsp = f->dsp;
1183
2.96M
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1184
2.96M
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1185
2.96M
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1186
2.96M
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1187
2.96M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1188
2.96M
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1189
2.96M
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1190
2.96M
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1191
2.96M
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1192
2.39M
                           (bw4 > ss_hor || t->bx & 1) &&
1193
2.23M
                           (bh4 > ss_ver || t->by & 1);
1194
2.96M
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->tx];
1195
2.96M
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
1196
1197
    // coefficient coding
1198
2.96M
    pixel *const edge = bitfn(t->scratch.edge) + 128;
1199
2.96M
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
1200
1201
2.96M
    const int intra_edge_filter_flag = f->seq_hdr->intra_edge_filter << 10;
1202
1203
6.00M
    for (int init_y = 0; init_y < h4; init_y += 16) {
1204
3.04M
        const int sub_h4 = imin(h4, 16 + init_y);
1205
3.04M
        const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
1206
6.20M
        for (int init_x = 0; init_x < w4; init_x += 16) {
1207
3.15M
            if (b->pal_sz[0]) {
1208
26.3k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1209
26.3k
                             4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1210
26.3k
                const uint8_t *pal_idx;
1211
26.3k
                if (t->frame_thread.pass) {
1212
26.3k
                    const int p = t->frame_thread.pass & 1;
1213
26.3k
                    assert(ts->frame_thread[p].pal_idx);
1214
26.3k
                    pal_idx = ts->frame_thread[p].pal_idx;
1215
26.3k
                    ts->frame_thread[p].pal_idx += bw4 * bh4 * 8;
1216
26.3k
                } else {
1217
0
                    pal_idx = t->scratch.pal_idx_y;
1218
0
                }
1219
26.3k
                const pixel *const pal = t->frame_thread.pass ?
1220
26.3k
                    f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1221
26.3k
                                        ((t->bx >> 1) + (t->by & 1))][0] :
1222
26.3k
                    bytefn(t->scratch.pal)[0];
1223
26.3k
                f->dsp->ipred.pal_pred(dst, f->cur.stride[0], pal,
1224
26.3k
                                       pal_idx, bw4 * 4, bh4 * 4);
1225
26.3k
                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
26.3k
            }
1229
1230
3.15M
            const int intra_flags = (sm_flag(t->a, bx4) |
1231
3.15M
                                     sm_flag(&t->l, by4) |
1232
3.15M
                                     intra_edge_filter_flag);
1233
3.15M
            const int sb_has_tr = init_x + 16 < w4 ? 1 : init_y ? 0 :
1234
3.04M
                              intra_edge_flags & EDGE_I444_TOP_HAS_RIGHT;
1235
3.15M
            const int sb_has_bl = init_x ? 0 : init_y + 16 < h4 ? 1 :
1236
3.04M
                              intra_edge_flags & EDGE_I444_LEFT_HAS_BOTTOM;
1237
3.15M
            int y, x;
1238
3.15M
            const int sub_w4 = imin(w4, init_x + 16);
1239
7.00M
            for (y = init_y, t->by += init_y; y < sub_h4;
1240
3.85M
                 y += t_dim->h, t->by += t_dim->h)
1241
3.85M
            {
1242
3.85M
                pixel *dst = ((pixel *) f->cur.data[0]) +
1243
3.85M
                               4 * (t->by * PXSTRIDE(f->cur.stride[0]) +
1244
3.85M
                                    t->bx + init_x);
1245
10.0M
                for (x = init_x, t->bx += init_x; x < sub_w4;
1246
6.19M
                     x += t_dim->w, t->bx += t_dim->w)
1247
6.19M
                {
1248
6.19M
                    if (b->pal_sz[0]) goto skip_y_pred;
1249
1250
6.16M
                    int angle = b->y_angle;
1251
6.16M
                    const enum EdgeFlags edge_flags =
1252
6.16M
                        (((y > init_y || !sb_has_tr) && (x + t_dim->w >= sub_w4)) ?
1253
4.45M
                             0 : EDGE_I444_TOP_HAS_RIGHT) |
1254
6.16M
                        ((x > init_x || (!sb_has_bl && y + t_dim->h >= sub_h4)) ?
1255
4.07M
                             0 : EDGE_I444_LEFT_HAS_BOTTOM);
1256
6.16M
                    const pixel *top_sb_edge = NULL;
1257
6.16M
                    if (!(t->by & (f->sb_step - 1))) {
1258
1.22M
                        top_sb_edge = f->ipred_edge[0];
1259
1.22M
                        const int sby = t->by >> f->sb_shift;
1260
1.22M
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1261
1.22M
                    }
1262
6.16M
                    const enum IntraPredMode m =
1263
6.16M
                        bytefn(dav1d_prepare_intra_edges)(t->bx,
1264
6.16M
                                                          t->bx > ts->tiling.col_start,
1265
6.16M
                                                          t->by,
1266
6.16M
                                                          t->by > ts->tiling.row_start,
1267
6.16M
                                                          ts->tiling.col_end,
1268
6.16M
                                                          ts->tiling.row_end,
1269
6.16M
                                                          edge_flags, dst,
1270
6.16M
                                                          f->cur.stride[0], top_sb_edge,
1271
6.16M
                                                          b->y_mode, &angle,
1272
6.16M
                                                          t_dim->w, t_dim->h,
1273
6.16M
                                                          f->seq_hdr->intra_edge_filter,
1274
6.16M
                                                          edge HIGHBD_CALL_SUFFIX);
1275
6.16M
                    dsp->ipred.intra_pred[m](dst, f->cur.stride[0], edge,
1276
6.16M
                                             t_dim->w * 4, t_dim->h * 4,
1277
6.16M
                                             angle | intra_flags,
1278
6.16M
                                             4 * f->bw - 4 * t->bx,
1279
6.16M
                                             4 * f->bh - 4 * t->by
1280
6.16M
                                             HIGHBD_CALL_SUFFIX);
1281
1282
6.16M
                    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
6.19M
                skip_y_pred: {}
1293
6.19M
                    if (!b->skip) {
1294
2.33M
                        coef *cf;
1295
2.33M
                        int eob;
1296
2.33M
                        enum TxfmType txtp;
1297
2.33M
                        if (t->frame_thread.pass) {
1298
2.33M
                            const int p = t->frame_thread.pass & 1;
1299
2.33M
                            const int cbi = *ts->frame_thread[p].cbi++;
1300
2.33M
                            cf = ts->frame_thread[p].cf;
1301
2.33M
                            ts->frame_thread[p].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
1302
2.33M
                            eob  = cbi >> 5;
1303
2.33M
                            txtp = cbi & 0x1f;
1304
2.33M
                        } 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
2.33M
                        if (eob >= 0) {
1317
1.74M
                            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
1.74M
                            dsp->itx.itxfm_add[b->tx]
1321
1.74M
                                              [txtp](dst,
1322
1.74M
                                                     f->cur.stride[0],
1323
1.74M
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1324
1.74M
                            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
1.74M
                        }
1328
3.86M
                    } 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
6.19M
                    dst += 4 * t_dim->w;
1333
6.19M
                }
1334
3.85M
                t->bx -= x;
1335
3.85M
            }
1336
3.15M
            t->by -= y;
1337
1338
3.15M
            if (!has_chroma) continue;
1339
1340
2.21M
            const ptrdiff_t stride = f->cur.stride[1];
1341
1342
2.21M
            if (b->uv_mode == CFL_PRED) {
1343
422k
                assert(!init_x && !init_y);
1344
1345
422k
                int16_t *const ac = t->scratch.ac;
1346
422k
                pixel *y_src = ((pixel *) f->cur.data[0]) + 4 * (t->bx & ~ss_hor) +
1347
422k
                                 4 * (t->by & ~ss_ver) * PXSTRIDE(f->cur.stride[0]);
1348
422k
                const ptrdiff_t uv_off = 4 * ((t->bx >> ss_hor) +
1349
422k
                                              (t->by >> ss_ver) * PXSTRIDE(stride));
1350
422k
                pixel *const uv_dst[2] = { ((pixel *) f->cur.data[1]) + uv_off,
1351
422k
                                           ((pixel *) f->cur.data[2]) + uv_off };
1352
1353
422k
                const int furthest_r =
1354
422k
                    ((cw4 << ss_hor) + t_dim->w - 1) & ~(t_dim->w - 1);
1355
422k
                const int furthest_b =
1356
422k
                    ((ch4 << ss_ver) + t_dim->h - 1) & ~(t_dim->h - 1);
1357
422k
                dsp->ipred.cfl_ac[f->cur.p.layout - 1](ac, y_src, f->cur.stride[0],
1358
422k
                                                         cbw4 - (furthest_r >> ss_hor),
1359
422k
                                                         cbh4 - (furthest_b >> ss_ver),
1360
422k
                                                         cbw4 * 4, cbh4 * 4);
1361
1.26M
                for (int pl = 0; pl < 2; pl++) {
1362
843k
                    if (!b->cfl_alpha[pl]) continue;
1363
673k
                    int angle = 0;
1364
673k
                    const pixel *top_sb_edge = NULL;
1365
673k
                    if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1366
180k
                        top_sb_edge = f->ipred_edge[pl + 1];
1367
180k
                        const int sby = t->by >> f->sb_shift;
1368
180k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1369
180k
                    }
1370
673k
                    const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1371
673k
                    const int xstart = ts->tiling.col_start >> ss_hor;
1372
673k
                    const int ystart = ts->tiling.row_start >> ss_ver;
1373
673k
                    const enum IntraPredMode m =
1374
673k
                        bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1375
673k
                                                          ypos, ypos > ystart,
1376
673k
                                                          ts->tiling.col_end >> ss_hor,
1377
673k
                                                          ts->tiling.row_end >> ss_ver,
1378
673k
                                                          0, uv_dst[pl], stride,
1379
673k
                                                          top_sb_edge, DC_PRED, &angle,
1380
673k
                                                          uv_t_dim->w, uv_t_dim->h, 0,
1381
673k
                                                          edge HIGHBD_CALL_SUFFIX);
1382
673k
                    dsp->ipred.cfl_pred[m](uv_dst[pl], stride, edge,
1383
673k
                                           uv_t_dim->w * 4,
1384
673k
                                           uv_t_dim->h * 4,
1385
673k
                                           ac, b->cfl_alpha[pl]
1386
673k
                                           HIGHBD_CALL_SUFFIX);
1387
673k
                }
1388
422k
                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
1.79M
            } else if (b->pal_sz[1]) {
1394
6.75k
                const ptrdiff_t uv_dstoff = 4 * ((t->bx >> ss_hor) +
1395
6.75k
                                              (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1396
6.75k
                const pixel (*pal)[8];
1397
6.75k
                const uint8_t *pal_idx;
1398
6.75k
                if (t->frame_thread.pass) {
1399
6.75k
                    const int p = t->frame_thread.pass & 1;
1400
6.75k
                    assert(ts->frame_thread[p].pal_idx);
1401
6.75k
                    pal = f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1402
6.75k
                                              ((t->bx >> 1) + (t->by & 1))];
1403
6.75k
                    pal_idx = ts->frame_thread[p].pal_idx;
1404
6.75k
                    ts->frame_thread[p].pal_idx += cbw4 * cbh4 * 8;
1405
6.75k
                } else {
1406
0
                    pal = bytefn(t->scratch.pal);
1407
0
                    pal_idx = t->scratch.pal_idx_uv;
1408
0
                }
1409
1410
6.75k
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[1]) + uv_dstoff,
1411
6.75k
                                       f->cur.stride[1], pal[1],
1412
6.75k
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1413
6.75k
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[2]) + uv_dstoff,
1414
6.75k
                                       f->cur.stride[1], pal[2],
1415
6.75k
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1416
6.75k
                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
6.75k
            }
1425
1426
2.21M
            const int sm_uv_fl = sm_uv_flag(t->a, cbx4) |
1427
2.21M
                                 sm_uv_flag(&t->l, cby4);
1428
2.21M
            const int uv_sb_has_tr =
1429
2.21M
                ((init_x + 16) >> ss_hor) < cw4 ? 1 : init_y ? 0 :
1430
2.13M
                intra_edge_flags & (EDGE_I420_TOP_HAS_RIGHT >> (f->cur.p.layout - 1));
1431
2.21M
            const int uv_sb_has_bl =
1432
2.21M
                init_x ? 0 : ((init_y + 16) >> ss_ver) < ch4 ? 1 :
1433
2.13M
                intra_edge_flags & (EDGE_I420_LEFT_HAS_BOTTOM >> (f->cur.p.layout - 1));
1434
2.21M
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
1435
6.64M
            for (int pl = 0; pl < 2; pl++) {
1436
9.29M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
1437
4.86M
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
1438
4.86M
                {
1439
4.86M
                    pixel *dst = ((pixel *) f->cur.data[1 + pl]) +
1440
4.86M
                                   4 * ((t->by >> ss_ver) * PXSTRIDE(stride) +
1441
4.86M
                                        ((t->bx + init_x) >> ss_hor));
1442
11.0M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
1443
6.23M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
1444
6.23M
                    {
1445
6.23M
                        if ((b->uv_mode == CFL_PRED && b->cfl_alpha[pl]) ||
1446
5.56M
                            b->pal_sz[1])
1447
688k
                        {
1448
688k
                            goto skip_uv_pred;
1449
688k
                        }
1450
1451
5.54M
                        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
5.54M
                        const enum EdgeFlags edge_flags =
1456
5.54M
                            (((y > (init_y >> ss_ver) || !uv_sb_has_tr) &&
1457
2.64M
                              (x + uv_t_dim->w >= sub_cw4)) ?
1458
4.00M
                                 0 : EDGE_I444_TOP_HAS_RIGHT) |
1459
5.54M
                            ((x > (init_x >> ss_hor) ||
1460
4.17M
                              (!uv_sb_has_bl && y + uv_t_dim->h >= sub_ch4)) ?
1461
3.45M
                                 0 : EDGE_I444_LEFT_HAS_BOTTOM);
1462
5.54M
                        const pixel *top_sb_edge = NULL;
1463
5.54M
                        if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1464
1.51M
                            top_sb_edge = f->ipred_edge[1 + pl];
1465
1.51M
                            const int sby = t->by >> f->sb_shift;
1466
1.51M
                            top_sb_edge += f->sb128w * 128 * (sby - 1);
1467
1.51M
                        }
1468
5.54M
                        const enum IntraPredMode uv_mode =
1469
5.54M
                             b->uv_mode == CFL_PRED ? DC_PRED : b->uv_mode;
1470
5.54M
                        const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1471
5.54M
                        const int xstart = ts->tiling.col_start >> ss_hor;
1472
5.54M
                        const int ystart = ts->tiling.row_start >> ss_ver;
1473
5.54M
                        const enum IntraPredMode m =
1474
5.54M
                            bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1475
5.54M
                                                              ypos, ypos > ystart,
1476
5.54M
                                                              ts->tiling.col_end >> ss_hor,
1477
5.54M
                                                              ts->tiling.row_end >> ss_ver,
1478
5.54M
                                                              edge_flags, dst, stride,
1479
5.54M
                                                              top_sb_edge, uv_mode,
1480
5.54M
                                                              &angle, uv_t_dim->w,
1481
5.54M
                                                              uv_t_dim->h,
1482
5.54M
                                                              f->seq_hdr->intra_edge_filter,
1483
5.54M
                                                              edge HIGHBD_CALL_SUFFIX);
1484
5.54M
                        angle |= intra_edge_filter_flag;
1485
5.54M
                        dsp->ipred.intra_pred[m](dst, stride, edge,
1486
5.54M
                                                 uv_t_dim->w * 4,
1487
5.54M
                                                 uv_t_dim->h * 4,
1488
5.54M
                                                 angle | sm_uv_fl,
1489
5.54M
                                                 (4 * f->bw + ss_hor -
1490
5.54M
                                                  4 * (t->bx & ~ss_hor)) >> ss_hor,
1491
5.54M
                                                 (4 * f->bh + ss_ver -
1492
5.54M
                                                  4 * (t->by & ~ss_ver)) >> ss_ver
1493
5.54M
                                                 HIGHBD_CALL_SUFFIX);
1494
5.54M
                        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
6.23M
                    skip_uv_pred: {}
1505
6.23M
                        if (!b->skip) {
1506
2.20M
                            enum TxfmType txtp;
1507
2.20M
                            int eob;
1508
2.20M
                            coef *cf;
1509
2.20M
                            if (t->frame_thread.pass) {
1510
2.20M
                                const int p = t->frame_thread.pass & 1;
1511
2.20M
                                const int cbi = *ts->frame_thread[p].cbi++;
1512
2.20M
                                cf = ts->frame_thread[p].cf;
1513
2.20M
                                ts->frame_thread[p].cf += uv_t_dim->w * uv_t_dim->h * 16;
1514
2.20M
                                eob  = cbi >> 5;
1515
2.20M
                                txtp = cbi & 0x1f;
1516
18.4E
                            } else {
1517
18.4E
                                uint8_t cf_ctx;
1518
18.4E
                                cf = bitfn(t->cf);
1519
18.4E
                                eob = decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
1520
18.4E
                                                   &t->l.ccoef[pl][cby4 + y],
1521
18.4E
                                                   b->uvtx, bs, b, 1, 1 + pl, cf,
1522
18.4E
                                                   &txtp, &cf_ctx);
1523
18.4E
                                if (DEBUG_BLOCK_INFO)
1524
0
                                    printf("Post-uv-cf-blk[pl=%d,tx=%d,"
1525
0
                                           "txtp=%d,eob=%d]: r=%d [x=%d,cbx4=%d]\n",
1526
0
                                           pl, b->uvtx, txtp, eob, ts->msac.rng, x, cbx4);
1527
18.4E
                                int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
1528
18.4E
                                int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
1529
18.4E
                                dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
1530
18.4E
                                dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
1531
18.4E
                            }
1532
2.20M
                            if (eob >= 0) {
1533
727k
                                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
727k
                                dsp->itx.itxfm_add[b->uvtx]
1537
727k
                                                  [txtp](dst, stride,
1538
727k
                                                         cf, eob HIGHBD_CALL_SUFFIX);
1539
727k
                                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
727k
                            }
1543
4.03M
                        } 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
6.23M
                        dst += uv_t_dim->w * 4;
1548
6.23M
                    }
1549
4.86M
                    t->bx -= x << ss_hor;
1550
4.86M
                }
1551
4.43M
                t->by -= y << ss_ver;
1552
4.43M
            }
1553
2.21M
        }
1554
3.04M
    }
1555
2.96M
}
dav1d_recon_b_intra_8bpc
Line
Count
Source
1179
1.35M
{
1180
1.35M
    Dav1dTileState *const ts = t->ts;
1181
1.35M
    const Dav1dFrameContext *const f = t->f;
1182
1.35M
    const Dav1dDSPContext *const dsp = f->dsp;
1183
1.35M
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1184
1.35M
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1185
1.35M
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1186
1.35M
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1187
1.35M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1188
1.35M
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1189
1.35M
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1190
1.35M
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1191
1.35M
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1192
1.18M
                           (bw4 > ss_hor || t->bx & 1) &&
1193
1.09M
                           (bh4 > ss_ver || t->by & 1);
1194
1.35M
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->tx];
1195
1.35M
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
1196
1197
    // coefficient coding
1198
1.35M
    pixel *const edge = bitfn(t->scratch.edge) + 128;
1199
1.35M
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
1200
1201
1.35M
    const int intra_edge_filter_flag = f->seq_hdr->intra_edge_filter << 10;
1202
1203
2.73M
    for (int init_y = 0; init_y < h4; init_y += 16) {
1204
1.38M
        const int sub_h4 = imin(h4, 16 + init_y);
1205
1.38M
        const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
1206
2.82M
        for (int init_x = 0; init_x < w4; init_x += 16) {
1207
1.43M
            if (b->pal_sz[0]) {
1208
9.54k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1209
9.54k
                             4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1210
9.54k
                const uint8_t *pal_idx;
1211
9.54k
                if (t->frame_thread.pass) {
1212
9.54k
                    const int p = t->frame_thread.pass & 1;
1213
9.54k
                    assert(ts->frame_thread[p].pal_idx);
1214
9.54k
                    pal_idx = ts->frame_thread[p].pal_idx;
1215
9.54k
                    ts->frame_thread[p].pal_idx += bw4 * bh4 * 8;
1216
9.54k
                } else {
1217
0
                    pal_idx = t->scratch.pal_idx_y;
1218
0
                }
1219
9.54k
                const pixel *const pal = t->frame_thread.pass ?
1220
9.54k
                    f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1221
9.54k
                                        ((t->bx >> 1) + (t->by & 1))][0] :
1222
9.54k
                    bytefn(t->scratch.pal)[0];
1223
9.54k
                f->dsp->ipred.pal_pred(dst, f->cur.stride[0], pal,
1224
9.54k
                                       pal_idx, bw4 * 4, bh4 * 4);
1225
9.54k
                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1226
0
                    hex_dump(dst, PXSTRIDE(f->cur.stride[0]),
1227
0
                             bw4 * 4, bh4 * 4, "y-pal-pred");
1228
9.54k
            }
1229
1230
1.43M
            const int intra_flags = (sm_flag(t->a, bx4) |
1231
1.43M
                                     sm_flag(&t->l, by4) |
1232
1.43M
                                     intra_edge_filter_flag);
1233
1.43M
            const int sb_has_tr = init_x + 16 < w4 ? 1 : init_y ? 0 :
1234
1.38M
                              intra_edge_flags & EDGE_I444_TOP_HAS_RIGHT;
1235
1.43M
            const int sb_has_bl = init_x ? 0 : init_y + 16 < h4 ? 1 :
1236
1.38M
                              intra_edge_flags & EDGE_I444_LEFT_HAS_BOTTOM;
1237
1.43M
            int y, x;
1238
1.43M
            const int sub_w4 = imin(w4, init_x + 16);
1239
3.17M
            for (y = init_y, t->by += init_y; y < sub_h4;
1240
1.73M
                 y += t_dim->h, t->by += t_dim->h)
1241
1.73M
            {
1242
1.73M
                pixel *dst = ((pixel *) f->cur.data[0]) +
1243
1.73M
                               4 * (t->by * PXSTRIDE(f->cur.stride[0]) +
1244
1.73M
                                    t->bx + init_x);
1245
4.33M
                for (x = init_x, t->bx += init_x; x < sub_w4;
1246
2.59M
                     x += t_dim->w, t->bx += t_dim->w)
1247
2.59M
                {
1248
2.59M
                    if (b->pal_sz[0]) goto skip_y_pred;
1249
1250
2.58M
                    int angle = b->y_angle;
1251
2.58M
                    const enum EdgeFlags edge_flags =
1252
2.58M
                        (((y > init_y || !sb_has_tr) && (x + t_dim->w >= sub_w4)) ?
1253
1.84M
                             0 : EDGE_I444_TOP_HAS_RIGHT) |
1254
2.58M
                        ((x > init_x || (!sb_has_bl && y + t_dim->h >= sub_h4)) ?
1255
1.65M
                             0 : EDGE_I444_LEFT_HAS_BOTTOM);
1256
2.58M
                    const pixel *top_sb_edge = NULL;
1257
2.58M
                    if (!(t->by & (f->sb_step - 1))) {
1258
577k
                        top_sb_edge = f->ipred_edge[0];
1259
577k
                        const int sby = t->by >> f->sb_shift;
1260
577k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1261
577k
                    }
1262
2.58M
                    const enum IntraPredMode m =
1263
2.58M
                        bytefn(dav1d_prepare_intra_edges)(t->bx,
1264
2.58M
                                                          t->bx > ts->tiling.col_start,
1265
2.58M
                                                          t->by,
1266
2.58M
                                                          t->by > ts->tiling.row_start,
1267
2.58M
                                                          ts->tiling.col_end,
1268
2.58M
                                                          ts->tiling.row_end,
1269
2.58M
                                                          edge_flags, dst,
1270
2.58M
                                                          f->cur.stride[0], top_sb_edge,
1271
2.58M
                                                          b->y_mode, &angle,
1272
2.58M
                                                          t_dim->w, t_dim->h,
1273
2.58M
                                                          f->seq_hdr->intra_edge_filter,
1274
2.58M
                                                          edge HIGHBD_CALL_SUFFIX);
1275
2.58M
                    dsp->ipred.intra_pred[m](dst, f->cur.stride[0], edge,
1276
2.58M
                                             t_dim->w * 4, t_dim->h * 4,
1277
2.58M
                                             angle | intra_flags,
1278
2.58M
                                             4 * f->bw - 4 * t->bx,
1279
2.58M
                                             4 * f->bh - 4 * t->by
1280
2.58M
                                             HIGHBD_CALL_SUFFIX);
1281
1282
2.58M
                    if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1283
0
                        hex_dump(edge - t_dim->h * 4, t_dim->h * 4,
1284
0
                                 t_dim->h * 4, 2, "l");
1285
0
                        hex_dump(edge, 0, 1, 1, "tl");
1286
0
                        hex_dump(edge + 1, t_dim->w * 4,
1287
0
                                 t_dim->w * 4, 2, "t");
1288
0
                        hex_dump(dst, f->cur.stride[0],
1289
0
                                 t_dim->w * 4, t_dim->h * 4, "y-intra-pred");
1290
0
                    }
1291
1292
2.59M
                skip_y_pred: {}
1293
2.59M
                    if (!b->skip) {
1294
885k
                        coef *cf;
1295
885k
                        int eob;
1296
885k
                        enum TxfmType txtp;
1297
885k
                        if (t->frame_thread.pass) {
1298
885k
                            const int p = t->frame_thread.pass & 1;
1299
885k
                            const int cbi = *ts->frame_thread[p].cbi++;
1300
885k
                            cf = ts->frame_thread[p].cf;
1301
885k
                            ts->frame_thread[p].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
1302
885k
                            eob  = cbi >> 5;
1303
885k
                            txtp = cbi & 0x1f;
1304
885k
                        } 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
885k
                        if (eob >= 0) {
1317
660k
                            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
660k
                            dsp->itx.itxfm_add[b->tx]
1321
660k
                                              [txtp](dst,
1322
660k
                                                     f->cur.stride[0],
1323
660k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1324
660k
                            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
660k
                        }
1328
1.71M
                    } else if (!t->frame_thread.pass) {
1329
0
                        dav1d_memset_pow2[t_dim->lw](&t->a->lcoef[bx4 + x], 0x40);
1330
0
                        dav1d_memset_pow2[t_dim->lh](&t->l.lcoef[by4 + y], 0x40);
1331
0
                    }
1332
2.59M
                    dst += 4 * t_dim->w;
1333
2.59M
                }
1334
1.73M
                t->bx -= x;
1335
1.73M
            }
1336
1.43M
            t->by -= y;
1337
1338
1.43M
            if (!has_chroma) continue;
1339
1340
1.09M
            const ptrdiff_t stride = f->cur.stride[1];
1341
1342
1.09M
            if (b->uv_mode == CFL_PRED) {
1343
204k
                assert(!init_x && !init_y);
1344
1345
204k
                int16_t *const ac = t->scratch.ac;
1346
204k
                pixel *y_src = ((pixel *) f->cur.data[0]) + 4 * (t->bx & ~ss_hor) +
1347
204k
                                 4 * (t->by & ~ss_ver) * PXSTRIDE(f->cur.stride[0]);
1348
204k
                const ptrdiff_t uv_off = 4 * ((t->bx >> ss_hor) +
1349
204k
                                              (t->by >> ss_ver) * PXSTRIDE(stride));
1350
204k
                pixel *const uv_dst[2] = { ((pixel *) f->cur.data[1]) + uv_off,
1351
204k
                                           ((pixel *) f->cur.data[2]) + uv_off };
1352
1353
204k
                const int furthest_r =
1354
204k
                    ((cw4 << ss_hor) + t_dim->w - 1) & ~(t_dim->w - 1);
1355
204k
                const int furthest_b =
1356
204k
                    ((ch4 << ss_ver) + t_dim->h - 1) & ~(t_dim->h - 1);
1357
204k
                dsp->ipred.cfl_ac[f->cur.p.layout - 1](ac, y_src, f->cur.stride[0],
1358
204k
                                                         cbw4 - (furthest_r >> ss_hor),
1359
204k
                                                         cbh4 - (furthest_b >> ss_ver),
1360
204k
                                                         cbw4 * 4, cbh4 * 4);
1361
612k
                for (int pl = 0; pl < 2; pl++) {
1362
408k
                    if (!b->cfl_alpha[pl]) continue;
1363
326k
                    int angle = 0;
1364
326k
                    const pixel *top_sb_edge = NULL;
1365
326k
                    if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1366
82.5k
                        top_sb_edge = f->ipred_edge[pl + 1];
1367
82.5k
                        const int sby = t->by >> f->sb_shift;
1368
82.5k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1369
82.5k
                    }
1370
326k
                    const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1371
326k
                    const int xstart = ts->tiling.col_start >> ss_hor;
1372
326k
                    const int ystart = ts->tiling.row_start >> ss_ver;
1373
326k
                    const enum IntraPredMode m =
1374
326k
                        bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1375
326k
                                                          ypos, ypos > ystart,
1376
326k
                                                          ts->tiling.col_end >> ss_hor,
1377
326k
                                                          ts->tiling.row_end >> ss_ver,
1378
326k
                                                          0, uv_dst[pl], stride,
1379
326k
                                                          top_sb_edge, DC_PRED, &angle,
1380
326k
                                                          uv_t_dim->w, uv_t_dim->h, 0,
1381
326k
                                                          edge HIGHBD_CALL_SUFFIX);
1382
326k
                    dsp->ipred.cfl_pred[m](uv_dst[pl], stride, edge,
1383
326k
                                           uv_t_dim->w * 4,
1384
326k
                                           uv_t_dim->h * 4,
1385
326k
                                           ac, b->cfl_alpha[pl]
1386
326k
                                           HIGHBD_CALL_SUFFIX);
1387
326k
                }
1388
204k
                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
887k
            } else if (b->pal_sz[1]) {
1394
2.89k
                const ptrdiff_t uv_dstoff = 4 * ((t->bx >> ss_hor) +
1395
2.89k
                                              (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1396
2.89k
                const pixel (*pal)[8];
1397
2.89k
                const uint8_t *pal_idx;
1398
2.89k
                if (t->frame_thread.pass) {
1399
2.89k
                    const int p = t->frame_thread.pass & 1;
1400
2.89k
                    assert(ts->frame_thread[p].pal_idx);
1401
2.89k
                    pal = f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1402
2.89k
                                              ((t->bx >> 1) + (t->by & 1))];
1403
2.89k
                    pal_idx = ts->frame_thread[p].pal_idx;
1404
2.89k
                    ts->frame_thread[p].pal_idx += cbw4 * cbh4 * 8;
1405
2.89k
                } else {
1406
0
                    pal = bytefn(t->scratch.pal);
1407
0
                    pal_idx = t->scratch.pal_idx_uv;
1408
0
                }
1409
1410
2.89k
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[1]) + uv_dstoff,
1411
2.89k
                                       f->cur.stride[1], pal[1],
1412
2.89k
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1413
2.89k
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[2]) + uv_dstoff,
1414
2.89k
                                       f->cur.stride[1], pal[2],
1415
2.89k
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1416
2.89k
                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1417
0
                    hex_dump(((pixel *) f->cur.data[1]) + uv_dstoff,
1418
0
                             PXSTRIDE(f->cur.stride[1]),
1419
0
                             cbw4 * 4, cbh4 * 4, "u-pal-pred");
1420
0
                    hex_dump(((pixel *) f->cur.data[2]) + uv_dstoff,
1421
0
                             PXSTRIDE(f->cur.stride[1]),
1422
0
                             cbw4 * 4, cbh4 * 4, "v-pal-pred");
1423
0
                }
1424
2.89k
            }
1425
1426
1.09M
            const int sm_uv_fl = sm_uv_flag(t->a, cbx4) |
1427
1.09M
                                 sm_uv_flag(&t->l, cby4);
1428
1.09M
            const int uv_sb_has_tr =
1429
1.09M
                ((init_x + 16) >> ss_hor) < cw4 ? 1 : init_y ? 0 :
1430
1.04M
                intra_edge_flags & (EDGE_I420_TOP_HAS_RIGHT >> (f->cur.p.layout - 1));
1431
1.09M
            const int uv_sb_has_bl =
1432
1.09M
                init_x ? 0 : ((init_y + 16) >> ss_ver) < ch4 ? 1 :
1433
1.04M
                intra_edge_flags & (EDGE_I420_LEFT_HAS_BOTTOM >> (f->cur.p.layout - 1));
1434
1.09M
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
1435
3.27M
            for (int pl = 0; pl < 2; pl++) {
1436
4.54M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
1437
2.36M
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
1438
2.35M
                {
1439
2.35M
                    pixel *dst = ((pixel *) f->cur.data[1 + pl]) +
1440
2.35M
                                   4 * ((t->by >> ss_ver) * PXSTRIDE(stride) +
1441
2.35M
                                        ((t->bx + init_x) >> ss_hor));
1442
5.18M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
1443
2.82M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
1444
2.82M
                    {
1445
2.82M
                        if ((b->uv_mode == CFL_PRED && b->cfl_alpha[pl]) ||
1446
2.50M
                            b->pal_sz[1])
1447
333k
                        {
1448
333k
                            goto skip_uv_pred;
1449
333k
                        }
1450
1451
2.49M
                        int angle = b->uv_angle;
1452
                        // this probably looks weird because we're using
1453
                        // luma flags in a chroma loop, but that's because
1454
                        // prepare_intra_edges() expects luma flags as input
1455
2.49M
                        const enum EdgeFlags edge_flags =
1456
2.49M
                            (((y > (init_y >> ss_ver) || !uv_sb_has_tr) &&
1457
1.08M
                              (x + uv_t_dim->w >= sub_cw4)) ?
1458
1.77M
                                 0 : EDGE_I444_TOP_HAS_RIGHT) |
1459
2.49M
                            ((x > (init_x >> ss_hor) ||
1460
2.02M
                              (!uv_sb_has_bl && y + uv_t_dim->h >= sub_ch4)) ?
1461
1.51M
                                 0 : EDGE_I444_LEFT_HAS_BOTTOM);
1462
2.49M
                        const pixel *top_sb_edge = NULL;
1463
2.49M
                        if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1464
729k
                            top_sb_edge = f->ipred_edge[1 + pl];
1465
729k
                            const int sby = t->by >> f->sb_shift;
1466
729k
                            top_sb_edge += f->sb128w * 128 * (sby - 1);
1467
729k
                        }
1468
2.49M
                        const enum IntraPredMode uv_mode =
1469
2.49M
                             b->uv_mode == CFL_PRED ? DC_PRED : b->uv_mode;
1470
2.49M
                        const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1471
2.49M
                        const int xstart = ts->tiling.col_start >> ss_hor;
1472
2.49M
                        const int ystart = ts->tiling.row_start >> ss_ver;
1473
2.49M
                        const enum IntraPredMode m =
1474
2.49M
                            bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1475
2.49M
                                                              ypos, ypos > ystart,
1476
2.49M
                                                              ts->tiling.col_end >> ss_hor,
1477
2.49M
                                                              ts->tiling.row_end >> ss_ver,
1478
2.49M
                                                              edge_flags, dst, stride,
1479
2.49M
                                                              top_sb_edge, uv_mode,
1480
2.49M
                                                              &angle, uv_t_dim->w,
1481
2.49M
                                                              uv_t_dim->h,
1482
2.49M
                                                              f->seq_hdr->intra_edge_filter,
1483
2.49M
                                                              edge HIGHBD_CALL_SUFFIX);
1484
2.49M
                        angle |= intra_edge_filter_flag;
1485
2.49M
                        dsp->ipred.intra_pred[m](dst, stride, edge,
1486
2.49M
                                                 uv_t_dim->w * 4,
1487
2.49M
                                                 uv_t_dim->h * 4,
1488
2.49M
                                                 angle | sm_uv_fl,
1489
2.49M
                                                 (4 * f->bw + ss_hor -
1490
2.49M
                                                  4 * (t->bx & ~ss_hor)) >> ss_hor,
1491
2.49M
                                                 (4 * f->bh + ss_ver -
1492
2.49M
                                                  4 * (t->by & ~ss_ver)) >> ss_ver
1493
2.49M
                                                 HIGHBD_CALL_SUFFIX);
1494
2.49M
                        if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1495
0
                            hex_dump(edge - uv_t_dim->h * 4, uv_t_dim->h * 4,
1496
0
                                     uv_t_dim->h * 4, 2, "l");
1497
0
                            hex_dump(edge, 0, 1, 1, "tl");
1498
0
                            hex_dump(edge + 1, uv_t_dim->w * 4,
1499
0
                                     uv_t_dim->w * 4, 2, "t");
1500
0
                            hex_dump(dst, stride, uv_t_dim->w * 4,
1501
0
                                     uv_t_dim->h * 4, pl ? "v-intra-pred" : "u-intra-pred");
1502
0
                        }
1503
1504
2.82M
                    skip_uv_pred: {}
1505
2.82M
                        if (!b->skip) {
1506
1.05M
                            enum TxfmType txtp;
1507
1.05M
                            int eob;
1508
1.05M
                            coef *cf;
1509
1.05M
                            if (t->frame_thread.pass) {
1510
1.05M
                                const int p = t->frame_thread.pass & 1;
1511
1.05M
                                const int cbi = *ts->frame_thread[p].cbi++;
1512
1.05M
                                cf = ts->frame_thread[p].cf;
1513
1.05M
                                ts->frame_thread[p].cf += uv_t_dim->w * uv_t_dim->h * 16;
1514
1.05M
                                eob  = cbi >> 5;
1515
1.05M
                                txtp = cbi & 0x1f;
1516
18.4E
                            } else {
1517
18.4E
                                uint8_t cf_ctx;
1518
18.4E
                                cf = bitfn(t->cf);
1519
18.4E
                                eob = decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
1520
18.4E
                                                   &t->l.ccoef[pl][cby4 + y],
1521
18.4E
                                                   b->uvtx, bs, b, 1, 1 + pl, cf,
1522
18.4E
                                                   &txtp, &cf_ctx);
1523
18.4E
                                if (DEBUG_BLOCK_INFO)
1524
0
                                    printf("Post-uv-cf-blk[pl=%d,tx=%d,"
1525
0
                                           "txtp=%d,eob=%d]: r=%d [x=%d,cbx4=%d]\n",
1526
0
                                           pl, b->uvtx, txtp, eob, ts->msac.rng, x, cbx4);
1527
18.4E
                                int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
1528
18.4E
                                int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
1529
18.4E
                                dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
1530
18.4E
                                dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
1531
18.4E
                            }
1532
1.05M
                            if (eob >= 0) {
1533
346k
                                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
346k
                                dsp->itx.itxfm_add[b->uvtx]
1537
346k
                                                  [txtp](dst, stride,
1538
346k
                                                         cf, eob HIGHBD_CALL_SUFFIX);
1539
346k
                                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
346k
                            }
1543
1.77M
                        } else if (!t->frame_thread.pass) {
1544
0
                            dav1d_memset_pow2[uv_t_dim->lw](&t->a->ccoef[pl][cbx4 + x], 0x40);
1545
0
                            dav1d_memset_pow2[uv_t_dim->lh](&t->l.ccoef[pl][cby4 + y], 0x40);
1546
0
                        }
1547
2.82M
                        dst += uv_t_dim->w * 4;
1548
2.82M
                    }
1549
2.36M
                    t->bx -= x << ss_hor;
1550
2.36M
                }
1551
2.18M
                t->by -= y << ss_ver;
1552
2.18M
            }
1553
1.09M
        }
1554
1.38M
    }
1555
1.35M
}
dav1d_recon_b_intra_16bpc
Line
Count
Source
1179
1.61M
{
1180
1.61M
    Dav1dTileState *const ts = t->ts;
1181
1.61M
    const Dav1dFrameContext *const f = t->f;
1182
1.61M
    const Dav1dDSPContext *const dsp = f->dsp;
1183
1.61M
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1184
1.61M
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1185
1.61M
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1186
1.61M
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1187
1.61M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1188
1.61M
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1189
1.61M
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1190
1.61M
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1191
1.61M
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1192
1.21M
                           (bw4 > ss_hor || t->bx & 1) &&
1193
1.13M
                           (bh4 > ss_ver || t->by & 1);
1194
1.61M
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->tx];
1195
1.61M
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
1196
1197
    // coefficient coding
1198
1.61M
    pixel *const edge = bitfn(t->scratch.edge) + 128;
1199
1.61M
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
1200
1201
1.61M
    const int intra_edge_filter_flag = f->seq_hdr->intra_edge_filter << 10;
1202
1203
3.26M
    for (int init_y = 0; init_y < h4; init_y += 16) {
1204
1.65M
        const int sub_h4 = imin(h4, 16 + init_y);
1205
1.65M
        const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
1206
3.37M
        for (int init_x = 0; init_x < w4; init_x += 16) {
1207
1.72M
            if (b->pal_sz[0]) {
1208
16.8k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1209
16.8k
                             4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1210
16.8k
                const uint8_t *pal_idx;
1211
16.8k
                if (t->frame_thread.pass) {
1212
16.8k
                    const int p = t->frame_thread.pass & 1;
1213
16.8k
                    assert(ts->frame_thread[p].pal_idx);
1214
16.8k
                    pal_idx = ts->frame_thread[p].pal_idx;
1215
16.8k
                    ts->frame_thread[p].pal_idx += bw4 * bh4 * 8;
1216
16.8k
                } else {
1217
0
                    pal_idx = t->scratch.pal_idx_y;
1218
0
                }
1219
16.8k
                const pixel *const pal = t->frame_thread.pass ?
1220
16.8k
                    f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1221
16.8k
                                        ((t->bx >> 1) + (t->by & 1))][0] :
1222
16.8k
                    bytefn(t->scratch.pal)[0];
1223
16.8k
                f->dsp->ipred.pal_pred(dst, f->cur.stride[0], pal,
1224
16.8k
                                       pal_idx, bw4 * 4, bh4 * 4);
1225
16.8k
                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
16.8k
            }
1229
1230
1.72M
            const int intra_flags = (sm_flag(t->a, bx4) |
1231
1.72M
                                     sm_flag(&t->l, by4) |
1232
1.72M
                                     intra_edge_filter_flag);
1233
1.72M
            const int sb_has_tr = init_x + 16 < w4 ? 1 : init_y ? 0 :
1234
1.65M
                              intra_edge_flags & EDGE_I444_TOP_HAS_RIGHT;
1235
1.72M
            const int sb_has_bl = init_x ? 0 : init_y + 16 < h4 ? 1 :
1236
1.65M
                              intra_edge_flags & EDGE_I444_LEFT_HAS_BOTTOM;
1237
1.72M
            int y, x;
1238
1.72M
            const int sub_w4 = imin(w4, init_x + 16);
1239
3.83M
            for (y = init_y, t->by += init_y; y < sub_h4;
1240
2.11M
                 y += t_dim->h, t->by += t_dim->h)
1241
2.11M
            {
1242
2.11M
                pixel *dst = ((pixel *) f->cur.data[0]) +
1243
2.11M
                               4 * (t->by * PXSTRIDE(f->cur.stride[0]) +
1244
2.11M
                                    t->bx + init_x);
1245
5.71M
                for (x = init_x, t->bx += init_x; x < sub_w4;
1246
3.60M
                     x += t_dim->w, t->bx += t_dim->w)
1247
3.60M
                {
1248
3.60M
                    if (b->pal_sz[0]) goto skip_y_pred;
1249
1250
3.57M
                    int angle = b->y_angle;
1251
3.57M
                    const enum EdgeFlags edge_flags =
1252
3.57M
                        (((y > init_y || !sb_has_tr) && (x + t_dim->w >= sub_w4)) ?
1253
2.61M
                             0 : EDGE_I444_TOP_HAS_RIGHT) |
1254
3.57M
                        ((x > init_x || (!sb_has_bl && y + t_dim->h >= sub_h4)) ?
1255
2.41M
                             0 : EDGE_I444_LEFT_HAS_BOTTOM);
1256
3.57M
                    const pixel *top_sb_edge = NULL;
1257
3.57M
                    if (!(t->by & (f->sb_step - 1))) {
1258
644k
                        top_sb_edge = f->ipred_edge[0];
1259
644k
                        const int sby = t->by >> f->sb_shift;
1260
644k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1261
644k
                    }
1262
3.57M
                    const enum IntraPredMode m =
1263
3.57M
                        bytefn(dav1d_prepare_intra_edges)(t->bx,
1264
3.57M
                                                          t->bx > ts->tiling.col_start,
1265
3.57M
                                                          t->by,
1266
3.57M
                                                          t->by > ts->tiling.row_start,
1267
3.57M
                                                          ts->tiling.col_end,
1268
3.57M
                                                          ts->tiling.row_end,
1269
3.57M
                                                          edge_flags, dst,
1270
3.57M
                                                          f->cur.stride[0], top_sb_edge,
1271
3.57M
                                                          b->y_mode, &angle,
1272
3.57M
                                                          t_dim->w, t_dim->h,
1273
3.57M
                                                          f->seq_hdr->intra_edge_filter,
1274
3.57M
                                                          edge HIGHBD_CALL_SUFFIX);
1275
3.57M
                    dsp->ipred.intra_pred[m](dst, f->cur.stride[0], edge,
1276
3.57M
                                             t_dim->w * 4, t_dim->h * 4,
1277
3.57M
                                             angle | intra_flags,
1278
3.57M
                                             4 * f->bw - 4 * t->bx,
1279
3.57M
                                             4 * f->bh - 4 * t->by
1280
3.57M
                                             HIGHBD_CALL_SUFFIX);
1281
1282
3.57M
                    if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1283
0
                        hex_dump(edge - t_dim->h * 4, t_dim->h * 4,
1284
0
                                 t_dim->h * 4, 2, "l");
1285
0
                        hex_dump(edge, 0, 1, 1, "tl");
1286
0
                        hex_dump(edge + 1, t_dim->w * 4,
1287
0
                                 t_dim->w * 4, 2, "t");
1288
0
                        hex_dump(dst, f->cur.stride[0],
1289
0
                                 t_dim->w * 4, t_dim->h * 4, "y-intra-pred");
1290
0
                    }
1291
1292
3.60M
                skip_y_pred: {}
1293
3.60M
                    if (!b->skip) {
1294
1.44M
                        coef *cf;
1295
1.44M
                        int eob;
1296
1.44M
                        enum TxfmType txtp;
1297
1.44M
                        if (t->frame_thread.pass) {
1298
1.44M
                            const int p = t->frame_thread.pass & 1;
1299
1.44M
                            const int cbi = *ts->frame_thread[p].cbi++;
1300
1.44M
                            cf = ts->frame_thread[p].cf;
1301
1.44M
                            ts->frame_thread[p].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
1302
1.44M
                            eob  = cbi >> 5;
1303
1.44M
                            txtp = cbi & 0x1f;
1304
1.44M
                        } 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
1.44M
                        if (eob >= 0) {
1317
1.08M
                            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
1.08M
                            dsp->itx.itxfm_add[b->tx]
1321
1.08M
                                              [txtp](dst,
1322
1.08M
                                                     f->cur.stride[0],
1323
1.08M
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1324
1.08M
                            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
1.08M
                        }
1328
2.15M
                    } else if (!t->frame_thread.pass) {
1329
0
                        dav1d_memset_pow2[t_dim->lw](&t->a->lcoef[bx4 + x], 0x40);
1330
0
                        dav1d_memset_pow2[t_dim->lh](&t->l.lcoef[by4 + y], 0x40);
1331
0
                    }
1332
3.60M
                    dst += 4 * t_dim->w;
1333
3.60M
                }
1334
2.11M
                t->bx -= x;
1335
2.11M
            }
1336
1.71M
            t->by -= y;
1337
1338
1.71M
            if (!has_chroma) continue;
1339
1340
1.12M
            const ptrdiff_t stride = f->cur.stride[1];
1341
1342
1.12M
            if (b->uv_mode == CFL_PRED) {
1343
217k
                assert(!init_x && !init_y);
1344
1345
217k
                int16_t *const ac = t->scratch.ac;
1346
217k
                pixel *y_src = ((pixel *) f->cur.data[0]) + 4 * (t->bx & ~ss_hor) +
1347
217k
                                 4 * (t->by & ~ss_ver) * PXSTRIDE(f->cur.stride[0]);
1348
217k
                const ptrdiff_t uv_off = 4 * ((t->bx >> ss_hor) +
1349
217k
                                              (t->by >> ss_ver) * PXSTRIDE(stride));
1350
217k
                pixel *const uv_dst[2] = { ((pixel *) f->cur.data[1]) + uv_off,
1351
217k
                                           ((pixel *) f->cur.data[2]) + uv_off };
1352
1353
217k
                const int furthest_r =
1354
217k
                    ((cw4 << ss_hor) + t_dim->w - 1) & ~(t_dim->w - 1);
1355
217k
                const int furthest_b =
1356
217k
                    ((ch4 << ss_ver) + t_dim->h - 1) & ~(t_dim->h - 1);
1357
217k
                dsp->ipred.cfl_ac[f->cur.p.layout - 1](ac, y_src, f->cur.stride[0],
1358
217k
                                                         cbw4 - (furthest_r >> ss_hor),
1359
217k
                                                         cbh4 - (furthest_b >> ss_ver),
1360
217k
                                                         cbw4 * 4, cbh4 * 4);
1361
653k
                for (int pl = 0; pl < 2; pl++) {
1362
435k
                    if (!b->cfl_alpha[pl]) continue;
1363
346k
                    int angle = 0;
1364
346k
                    const pixel *top_sb_edge = NULL;
1365
346k
                    if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1366
97.8k
                        top_sb_edge = f->ipred_edge[pl + 1];
1367
97.8k
                        const int sby = t->by >> f->sb_shift;
1368
97.8k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1369
97.8k
                    }
1370
346k
                    const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1371
346k
                    const int xstart = ts->tiling.col_start >> ss_hor;
1372
346k
                    const int ystart = ts->tiling.row_start >> ss_ver;
1373
346k
                    const enum IntraPredMode m =
1374
346k
                        bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1375
346k
                                                          ypos, ypos > ystart,
1376
346k
                                                          ts->tiling.col_end >> ss_hor,
1377
346k
                                                          ts->tiling.row_end >> ss_ver,
1378
346k
                                                          0, uv_dst[pl], stride,
1379
346k
                                                          top_sb_edge, DC_PRED, &angle,
1380
346k
                                                          uv_t_dim->w, uv_t_dim->h, 0,
1381
346k
                                                          edge HIGHBD_CALL_SUFFIX);
1382
346k
                    dsp->ipred.cfl_pred[m](uv_dst[pl], stride, edge,
1383
346k
                                           uv_t_dim->w * 4,
1384
346k
                                           uv_t_dim->h * 4,
1385
346k
                                           ac, b->cfl_alpha[pl]
1386
346k
                                           HIGHBD_CALL_SUFFIX);
1387
346k
                }
1388
217k
                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
906k
            } else if (b->pal_sz[1]) {
1394
3.85k
                const ptrdiff_t uv_dstoff = 4 * ((t->bx >> ss_hor) +
1395
3.85k
                                              (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1396
3.85k
                const pixel (*pal)[8];
1397
3.85k
                const uint8_t *pal_idx;
1398
3.85k
                if (t->frame_thread.pass) {
1399
3.85k
                    const int p = t->frame_thread.pass & 1;
1400
3.85k
                    assert(ts->frame_thread[p].pal_idx);
1401
3.85k
                    pal = f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1402
3.85k
                                              ((t->bx >> 1) + (t->by & 1))];
1403
3.85k
                    pal_idx = ts->frame_thread[p].pal_idx;
1404
3.85k
                    ts->frame_thread[p].pal_idx += cbw4 * cbh4 * 8;
1405
3.85k
                } else {
1406
0
                    pal = bytefn(t->scratch.pal);
1407
0
                    pal_idx = t->scratch.pal_idx_uv;
1408
0
                }
1409
1410
3.85k
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[1]) + uv_dstoff,
1411
3.85k
                                       f->cur.stride[1], pal[1],
1412
3.85k
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1413
3.85k
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[2]) + uv_dstoff,
1414
3.85k
                                       f->cur.stride[1], pal[2],
1415
3.85k
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1416
3.85k
                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1417
0
                    hex_dump(((pixel *) f->cur.data[1]) + uv_dstoff,
1418
0
                             PXSTRIDE(f->cur.stride[1]),
1419
0
                             cbw4 * 4, cbh4 * 4, "u-pal-pred");
1420
0
                    hex_dump(((pixel *) f->cur.data[2]) + uv_dstoff,
1421
0
                             PXSTRIDE(f->cur.stride[1]),
1422
0
                             cbw4 * 4, cbh4 * 4, "v-pal-pred");
1423
0
                }
1424
3.85k
            }
1425
1426
1.12M
            const int sm_uv_fl = sm_uv_flag(t->a, cbx4) |
1427
1.12M
                                 sm_uv_flag(&t->l, cby4);
1428
1.12M
            const int uv_sb_has_tr =
1429
1.12M
                ((init_x + 16) >> ss_hor) < cw4 ? 1 : init_y ? 0 :
1430
1.08M
                intra_edge_flags & (EDGE_I420_TOP_HAS_RIGHT >> (f->cur.p.layout - 1));
1431
1.12M
            const int uv_sb_has_bl =
1432
1.12M
                init_x ? 0 : ((init_y + 16) >> ss_ver) < ch4 ? 1 :
1433
1.08M
                intra_edge_flags & (EDGE_I420_LEFT_HAS_BOTTOM >> (f->cur.p.layout - 1));
1434
1.12M
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
1435
3.37M
            for (int pl = 0; pl < 2; pl++) {
1436
4.75M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
1437
2.50M
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
1438
2.50M
                {
1439
2.50M
                    pixel *dst = ((pixel *) f->cur.data[1 + pl]) +
1440
2.50M
                                   4 * ((t->by >> ss_ver) * PXSTRIDE(stride) +
1441
2.50M
                                        ((t->bx + init_x) >> ss_hor));
1442
5.90M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
1443
3.40M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
1444
3.40M
                    {
1445
3.40M
                        if ((b->uv_mode == CFL_PRED && b->cfl_alpha[pl]) ||
1446
3.05M
                            b->pal_sz[1])
1447
355k
                        {
1448
355k
                            goto skip_uv_pred;
1449
355k
                        }
1450
1451
3.05M
                        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
3.05M
                        const enum EdgeFlags edge_flags =
1456
3.05M
                            (((y > (init_y >> ss_ver) || !uv_sb_has_tr) &&
1457
1.56M
                              (x + uv_t_dim->w >= sub_cw4)) ?
1458
2.22M
                                 0 : EDGE_I444_TOP_HAS_RIGHT) |
1459
3.05M
                            ((x > (init_x >> ss_hor) ||
1460
2.14M
                              (!uv_sb_has_bl && y + uv_t_dim->h >= sub_ch4)) ?
1461
1.94M
                                 0 : EDGE_I444_LEFT_HAS_BOTTOM);
1462
3.05M
                        const pixel *top_sb_edge = NULL;
1463
3.05M
                        if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1464
786k
                            top_sb_edge = f->ipred_edge[1 + pl];
1465
786k
                            const int sby = t->by >> f->sb_shift;
1466
786k
                            top_sb_edge += f->sb128w * 128 * (sby - 1);
1467
786k
                        }
1468
3.05M
                        const enum IntraPredMode uv_mode =
1469
3.05M
                             b->uv_mode == CFL_PRED ? DC_PRED : b->uv_mode;
1470
3.05M
                        const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1471
3.05M
                        const int xstart = ts->tiling.col_start >> ss_hor;
1472
3.05M
                        const int ystart = ts->tiling.row_start >> ss_ver;
1473
3.05M
                        const enum IntraPredMode m =
1474
3.05M
                            bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1475
3.05M
                                                              ypos, ypos > ystart,
1476
3.05M
                                                              ts->tiling.col_end >> ss_hor,
1477
3.05M
                                                              ts->tiling.row_end >> ss_ver,
1478
3.05M
                                                              edge_flags, dst, stride,
1479
3.05M
                                                              top_sb_edge, uv_mode,
1480
3.05M
                                                              &angle, uv_t_dim->w,
1481
3.05M
                                                              uv_t_dim->h,
1482
3.05M
                                                              f->seq_hdr->intra_edge_filter,
1483
3.05M
                                                              edge HIGHBD_CALL_SUFFIX);
1484
3.05M
                        angle |= intra_edge_filter_flag;
1485
3.05M
                        dsp->ipred.intra_pred[m](dst, stride, edge,
1486
3.05M
                                                 uv_t_dim->w * 4,
1487
3.05M
                                                 uv_t_dim->h * 4,
1488
3.05M
                                                 angle | sm_uv_fl,
1489
3.05M
                                                 (4 * f->bw + ss_hor -
1490
3.05M
                                                  4 * (t->bx & ~ss_hor)) >> ss_hor,
1491
3.05M
                                                 (4 * f->bh + ss_ver -
1492
3.05M
                                                  4 * (t->by & ~ss_ver)) >> ss_ver
1493
3.05M
                                                 HIGHBD_CALL_SUFFIX);
1494
3.05M
                        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
3.40M
                    skip_uv_pred: {}
1505
3.40M
                        if (!b->skip) {
1506
1.15M
                            enum TxfmType txtp;
1507
1.15M
                            int eob;
1508
1.15M
                            coef *cf;
1509
1.15M
                            if (t->frame_thread.pass) {
1510
1.15M
                                const int p = t->frame_thread.pass & 1;
1511
1.15M
                                const int cbi = *ts->frame_thread[p].cbi++;
1512
1.15M
                                cf = ts->frame_thread[p].cf;
1513
1.15M
                                ts->frame_thread[p].cf += uv_t_dim->w * uv_t_dim->h * 16;
1514
1.15M
                                eob  = cbi >> 5;
1515
1.15M
                                txtp = cbi & 0x1f;
1516
18.4E
                            } else {
1517
18.4E
                                uint8_t cf_ctx;
1518
18.4E
                                cf = bitfn(t->cf);
1519
18.4E
                                eob = decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
1520
18.4E
                                                   &t->l.ccoef[pl][cby4 + y],
1521
18.4E
                                                   b->uvtx, bs, b, 1, 1 + pl, cf,
1522
18.4E
                                                   &txtp, &cf_ctx);
1523
18.4E
                                if (DEBUG_BLOCK_INFO)
1524
0
                                    printf("Post-uv-cf-blk[pl=%d,tx=%d,"
1525
0
                                           "txtp=%d,eob=%d]: r=%d [x=%d,cbx4=%d]\n",
1526
0
                                           pl, b->uvtx, txtp, eob, ts->msac.rng, x, cbx4);
1527
18.4E
                                int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
1528
18.4E
                                int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
1529
18.4E
                                dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
1530
18.4E
                                dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
1531
18.4E
                            }
1532
1.15M
                            if (eob >= 0) {
1533
380k
                                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
380k
                                dsp->itx.itxfm_add[b->uvtx]
1537
380k
                                                  [txtp](dst, stride,
1538
380k
                                                         cf, eob HIGHBD_CALL_SUFFIX);
1539
380k
                                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
380k
                            }
1543
2.25M
                        } 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
3.40M
                        dst += uv_t_dim->w * 4;
1548
3.40M
                    }
1549
2.50M
                    t->bx -= x << ss_hor;
1550
2.50M
                }
1551
2.24M
                t->by -= y << ss_ver;
1552
2.24M
            }
1553
1.12M
        }
1554
1.65M
    }
1555
1.61M
}
1556
1557
int bytefn(dav1d_recon_b_inter)(Dav1dTaskContext *const t, const enum BlockSize bs,
1558
                                const Av1Block *const b)
1559
1.29M
{
1560
1.29M
    Dav1dTileState *const ts = t->ts;
1561
1.29M
    const Dav1dFrameContext *const f = t->f;
1562
1.29M
    const Dav1dDSPContext *const dsp = f->dsp;
1563
1.29M
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1564
1.29M
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1565
1.29M
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1566
1.29M
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1567
1.29M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1568
1.29M
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1569
1.29M
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1570
1.29M
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1571
933k
                           (bw4 > ss_hor || t->bx & 1) &&
1572
880k
                           (bh4 > ss_ver || t->by & 1);
1573
1.29M
    const int chr_layout_idx = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I400 ? 0 :
1574
1.29M
                               DAV1D_PIXEL_LAYOUT_I444 - f->cur.p.layout;
1575
1.29M
    int res;
1576
1577
    // prediction
1578
1.29M
    const int cbh4 = (bh4 + ss_ver) >> ss_ver, cbw4 = (bw4 + ss_hor) >> ss_hor;
1579
1.29M
    pixel *dst = ((pixel *) f->cur.data[0]) +
1580
1.29M
        4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1581
1.29M
    const ptrdiff_t uvdstoff =
1582
1.29M
        4 * ((t->bx >> ss_hor) + (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1583
1.29M
    if (IS_KEY_OR_INTRA(f->frame_hdr)) {
1584
        // intrabc
1585
421k
        assert(!f->frame_hdr->super_res.enabled);
1586
421k
        res = mc(t, dst, NULL, f->cur.stride[0], bw4, bh4, t->bx, t->by, 0,
1587
421k
                 b->mv[0], &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1588
421k
        if (res) return res;
1589
659k
        if (has_chroma) for (int pl = 1; pl < 3; pl++) {
1590
439k
            res = mc(t, ((pixel *)f->cur.data[pl]) + uvdstoff, NULL, f->cur.stride[1],
1591
439k
                     bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1592
439k
                     t->bx & ~ss_hor, t->by & ~ss_ver, pl, b->mv[0],
1593
439k
                     &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1594
439k
            if (res) return res;
1595
439k
        }
1596
878k
    } else if (b->comp_type == COMP_INTER_NONE) {
1597
750k
        const Dav1dThreadPicture *const refp = &f->refp[b->ref[0]];
1598
750k
        const enum Filter2d filter_2d = b->filter2d;
1599
1600
750k
        if (imin(bw4, bh4) > 1 &&
1601
464k
            ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1602
449k
             (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1603
20.2k
        {
1604
20.2k
            res = warp_affine(t, dst, NULL, f->cur.stride[0], b_dim, 0, refp,
1605
20.2k
                              b->motion_mode == MM_WARP ? &t->warpmv :
1606
20.2k
                                  &f->frame_hdr->gmv[b->ref[0]]);
1607
20.2k
            if (res) return res;
1608
730k
        } else {
1609
730k
            res = mc(t, dst, NULL, f->cur.stride[0],
1610
730k
                     bw4, bh4, t->bx, t->by, 0, b->mv[0], refp, b->ref[0], filter_2d);
1611
730k
            if (res) return res;
1612
730k
            if (b->motion_mode == MM_OBMC) {
1613
142k
                res = obmc(t, dst, f->cur.stride[0], b_dim, 0, bx4, by4, w4, h4);
1614
142k
                if (res) return res;
1615
142k
            }
1616
730k
        }
1617
750k
        if (b->interintra_type) {
1618
30.9k
            pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1619
30.9k
            enum IntraPredMode m = b->interintra_mode == II_SMOOTH_PRED ?
1620
25.5k
                                   SMOOTH_PRED : b->interintra_mode;
1621
30.9k
            pixel *const tmp = bitfn(t->scratch.interintra);
1622
30.9k
            int angle = 0;
1623
30.9k
            const pixel *top_sb_edge = NULL;
1624
30.9k
            if (!(t->by & (f->sb_step - 1))) {
1625
9.48k
                top_sb_edge = f->ipred_edge[0];
1626
9.48k
                const int sby = t->by >> f->sb_shift;
1627
9.48k
                top_sb_edge += f->sb128w * 128 * (sby - 1);
1628
9.48k
            }
1629
30.9k
            m = bytefn(dav1d_prepare_intra_edges)(t->bx, t->bx > ts->tiling.col_start,
1630
30.9k
                                                  t->by, t->by > ts->tiling.row_start,
1631
30.9k
                                                  ts->tiling.col_end, ts->tiling.row_end,
1632
30.9k
                                                  0, dst, f->cur.stride[0], top_sb_edge,
1633
30.9k
                                                  m, &angle, bw4, bh4, 0, tl_edge
1634
30.9k
                                                  HIGHBD_CALL_SUFFIX);
1635
30.9k
            dsp->ipred.intra_pred[m](tmp, 4 * bw4 * sizeof(pixel),
1636
30.9k
                                     tl_edge, bw4 * 4, bh4 * 4, 0, 0, 0
1637
30.9k
                                     HIGHBD_CALL_SUFFIX);
1638
30.9k
            dsp->mc.blend(dst, f->cur.stride[0], tmp,
1639
30.9k
                          bw4 * 4, bh4 * 4, II_MASK(0, bs, b));
1640
30.9k
        }
1641
1642
750k
        if (!has_chroma) goto skip_inter_chroma_pred;
1643
1644
        // sub8x8 derivation
1645
506k
        int is_sub8x8 = bw4 == ss_hor || bh4 == ss_ver;
1646
506k
        refmvs_block *const *r;
1647
506k
        if (is_sub8x8) {
1648
49.0k
            assert(ss_hor == 1);
1649
49.0k
            r = &t->rt.r[(t->by & 31) + 5];
1650
49.0k
            if (bw4 == 1) is_sub8x8 &= r[0][t->bx - 1].ref.ref[0] > 0;
1651
49.0k
            if (bh4 == ss_ver) is_sub8x8 &= r[-1][t->bx].ref.ref[0] > 0;
1652
49.0k
            if (bw4 == 1 && bh4 == ss_ver)
1653
8.93k
                is_sub8x8 &= r[-1][t->bx - 1].ref.ref[0] > 0;
1654
49.0k
        }
1655
1656
        // chroma prediction
1657
506k
        if (is_sub8x8) {
1658
46.8k
            assert(ss_hor == 1);
1659
46.8k
            ptrdiff_t h_off = 0, v_off = 0;
1660
46.8k
            if (bw4 == 1 && bh4 == ss_ver) {
1661
23.6k
                for (int pl = 0; pl < 2; pl++) {
1662
15.7k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1663
15.7k
                             NULL, f->cur.stride[1],
1664
15.7k
                             bw4, bh4, t->bx - 1, t->by - 1, 1 + pl,
1665
15.7k
                             r[-1][t->bx - 1].mv.mv[0],
1666
15.7k
                             &f->refp[r[-1][t->bx - 1].ref.ref[0] - 1],
1667
15.7k
                             r[-1][t->bx - 1].ref.ref[0] - 1,
1668
15.7k
                             t->frame_thread.pass != 2 ? t->tl_4x4_filter :
1669
15.7k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx - 1].filter2d);
1670
15.7k
                    if (res) return res;
1671
15.7k
                }
1672
7.86k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1673
7.86k
                h_off = 2;
1674
7.86k
            }
1675
46.8k
            if (bw4 == 1) {
1676
25.3k
                const enum Filter2d left_filter_2d =
1677
25.3k
                    dav1d_filter_2d[t->l.filter[1][by4]][t->l.filter[0][by4]];
1678
75.9k
                for (int pl = 0; pl < 2; pl++) {
1679
50.6k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + v_off, NULL,
1680
50.6k
                             f->cur.stride[1], bw4, bh4, t->bx - 1,
1681
50.6k
                             t->by, 1 + pl, r[0][t->bx - 1].mv.mv[0],
1682
50.6k
                             &f->refp[r[0][t->bx - 1].ref.ref[0] - 1],
1683
50.6k
                             r[0][t->bx - 1].ref.ref[0] - 1,
1684
50.6k
                             t->frame_thread.pass != 2 ? left_filter_2d :
1685
50.6k
                                 f->frame_thread.b[(t->by * f->b4_stride) + t->bx - 1].filter2d);
1686
50.6k
                    if (res) return res;
1687
50.6k
                }
1688
25.3k
                h_off = 2;
1689
25.3k
            }
1690
46.8k
            if (bh4 == ss_ver) {
1691
29.3k
                const enum Filter2d top_filter_2d =
1692
29.3k
                    dav1d_filter_2d[t->a->filter[1][bx4]][t->a->filter[0][bx4]];
1693
88.1k
                for (int pl = 0; pl < 2; pl++) {
1694
58.7k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off, NULL,
1695
58.7k
                             f->cur.stride[1], bw4, bh4, t->bx, t->by - 1,
1696
58.7k
                             1 + pl, r[-1][t->bx].mv.mv[0],
1697
58.7k
                             &f->refp[r[-1][t->bx].ref.ref[0] - 1],
1698
58.7k
                             r[-1][t->bx].ref.ref[0] - 1,
1699
58.7k
                             t->frame_thread.pass != 2 ? top_filter_2d :
1700
58.7k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx].filter2d);
1701
58.7k
                    if (res) return res;
1702
58.7k
                }
1703
29.3k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1704
29.3k
            }
1705
140k
            for (int pl = 0; pl < 2; pl++) {
1706
93.6k
                res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off + v_off, NULL, f->cur.stride[1],
1707
93.6k
                         bw4, bh4, t->bx, t->by, 1 + pl, b->mv[0],
1708
93.6k
                         refp, b->ref[0], filter_2d);
1709
93.6k
                if (res) return res;
1710
93.6k
            }
1711
459k
        } else {
1712
459k
            if (imin(cbw4, cbh4) > 1 &&
1713
249k
                ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1714
239k
                 (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1715
13.8k
            {
1716
41.4k
                for (int pl = 0; pl < 2; pl++) {
1717
27.6k
                    res = warp_affine(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff, NULL,
1718
27.6k
                                      f->cur.stride[1], b_dim, 1 + pl, refp,
1719
27.6k
                                      b->motion_mode == MM_WARP ? &t->warpmv :
1720
27.6k
                                          &f->frame_hdr->gmv[b->ref[0]]);
1721
27.6k
                    if (res) return res;
1722
27.6k
                }
1723
445k
            } else {
1724
1.33M
                for (int pl = 0; pl < 2; pl++) {
1725
890k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1726
890k
                             NULL, f->cur.stride[1],
1727
890k
                             bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1728
890k
                             t->bx & ~ss_hor, t->by & ~ss_ver,
1729
890k
                             1 + pl, b->mv[0], refp, b->ref[0], filter_2d);
1730
890k
                    if (res) return res;
1731
890k
                    if (b->motion_mode == MM_OBMC) {
1732
230k
                        res = obmc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1733
230k
                                   f->cur.stride[1], b_dim, 1 + pl, bx4, by4, w4, h4);
1734
230k
                        if (res) return res;
1735
230k
                    }
1736
890k
                }
1737
445k
            }
1738
459k
            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
28.0k
                const uint8_t *const ii_mask = II_MASK(chr_layout_idx, bs, b);
1743
1744
84.0k
                for (int pl = 0; pl < 2; pl++) {
1745
56.0k
                    pixel *const tmp = bitfn(t->scratch.interintra);
1746
56.0k
                    pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1747
56.0k
                    enum IntraPredMode m =
1748
56.0k
                        b->interintra_mode == II_SMOOTH_PRED ?
1749
46.2k
                        SMOOTH_PRED : b->interintra_mode;
1750
56.0k
                    int angle = 0;
1751
56.0k
                    pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1752
56.0k
                    const pixel *top_sb_edge = NULL;
1753
56.0k
                    if (!(t->by & (f->sb_step - 1))) {
1754
15.4k
                        top_sb_edge = f->ipred_edge[pl + 1];
1755
15.4k
                        const int sby = t->by >> f->sb_shift;
1756
15.4k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1757
15.4k
                    }
1758
56.0k
                    m = bytefn(dav1d_prepare_intra_edges)(t->bx >> ss_hor,
1759
56.0k
                                                          (t->bx >> ss_hor) >
1760
56.0k
                                                              (ts->tiling.col_start >> ss_hor),
1761
56.0k
                                                          t->by >> ss_ver,
1762
56.0k
                                                          (t->by >> ss_ver) >
1763
56.0k
                                                              (ts->tiling.row_start >> ss_ver),
1764
56.0k
                                                          ts->tiling.col_end >> ss_hor,
1765
56.0k
                                                          ts->tiling.row_end >> ss_ver,
1766
56.0k
                                                          0, uvdst, f->cur.stride[1],
1767
56.0k
                                                          top_sb_edge, m,
1768
56.0k
                                                          &angle, cbw4, cbh4, 0, tl_edge
1769
56.0k
                                                          HIGHBD_CALL_SUFFIX);
1770
56.0k
                    dsp->ipred.intra_pred[m](tmp, cbw4 * 4 * sizeof(pixel),
1771
56.0k
                                             tl_edge, cbw4 * 4, cbh4 * 4, 0, 0, 0
1772
56.0k
                                             HIGHBD_CALL_SUFFIX);
1773
56.0k
                    dsp->mc.blend(uvdst, f->cur.stride[1], tmp,
1774
56.0k
                                  cbw4 * 4, cbh4 * 4, ii_mask);
1775
56.0k
                }
1776
28.0k
            }
1777
459k
        }
1778
1779
750k
    skip_inter_chroma_pred: {}
1780
750k
        t->tl_4x4_filter = filter_2d;
1781
750k
    } else {
1782
127k
        const enum Filter2d filter_2d = b->filter2d;
1783
        // Maximum super block size is 128x128
1784
127k
        int16_t (*tmp)[128 * 128] = t->scratch.compinter;
1785
127k
        int jnt_weight;
1786
127k
        uint8_t *const seg_mask = t->scratch.seg_mask;
1787
127k
        const uint8_t *mask;
1788
1789
381k
        for (int i = 0; i < 2; i++) {
1790
254k
            const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1791
1792
254k
            if (b->inter_mode == GLOBALMV_GLOBALMV && f->gmv_warp_allowed[b->ref[i]]) {
1793
9.06k
                res = warp_affine(t, NULL, tmp[i], bw4 * 4, b_dim, 0, refp,
1794
9.06k
                                  &f->frame_hdr->gmv[b->ref[i]]);
1795
9.06k
                if (res) return res;
1796
245k
            } else {
1797
245k
                res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by, 0,
1798
245k
                         b->mv[i], refp, b->ref[i], filter_2d);
1799
245k
                if (res) return res;
1800
245k
            }
1801
254k
        }
1802
127k
        switch (b->comp_type) {
1803
95.0k
        case COMP_INTER_AVG:
1804
95.0k
            dsp->mc.avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1805
95.0k
                        bw4 * 4, bh4 * 4 HIGHBD_CALL_SUFFIX);
1806
95.0k
            break;
1807
13.1k
        case COMP_INTER_WEIGHTED_AVG:
1808
13.1k
            jnt_weight = f->jnt_weights[b->ref[0]][b->ref[1]];
1809
13.1k
            dsp->mc.w_avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1810
13.1k
                          bw4 * 4, bh4 * 4, jnt_weight HIGHBD_CALL_SUFFIX);
1811
13.1k
            break;
1812
12.9k
        case COMP_INTER_SEG:
1813
12.9k
            dsp->mc.w_mask[chr_layout_idx](dst, f->cur.stride[0],
1814
12.9k
                                           tmp[b->mask_sign], tmp[!b->mask_sign],
1815
12.9k
                                           bw4 * 4, bh4 * 4, seg_mask,
1816
12.9k
                                           b->mask_sign HIGHBD_CALL_SUFFIX);
1817
12.9k
            mask = seg_mask;
1818
12.9k
            break;
1819
5.91k
        case COMP_INTER_WEDGE:
1820
5.91k
            mask = WEDGE_MASK(0, bs, 0, b->wedge_idx);
1821
5.91k
            dsp->mc.mask(dst, f->cur.stride[0],
1822
5.91k
                         tmp[b->mask_sign], tmp[!b->mask_sign],
1823
5.91k
                         bw4 * 4, bh4 * 4, mask HIGHBD_CALL_SUFFIX);
1824
5.91k
            if (has_chroma)
1825
4.52k
                mask = WEDGE_MASK(chr_layout_idx, bs, b->mask_sign, b->wedge_idx);
1826
5.91k
            break;
1827
127k
        }
1828
1829
        // chroma
1830
310k
        if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1831
621k
            for (int i = 0; i < 2; i++) {
1832
414k
                const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1833
414k
                if (b->inter_mode == GLOBALMV_GLOBALMV &&
1834
62.1k
                    imin(cbw4, cbh4) > 1 && f->gmv_warp_allowed[b->ref[i]])
1835
9.19k
                {
1836
9.19k
                    res = warp_affine(t, NULL, tmp[i], bw4 * 4 >> ss_hor,
1837
9.19k
                                      b_dim, 1 + pl,
1838
9.19k
                                      refp, &f->frame_hdr->gmv[b->ref[i]]);
1839
9.19k
                    if (res) return res;
1840
405k
                } else {
1841
405k
                    res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by,
1842
405k
                             1 + pl, b->mv[i], refp, b->ref[i], filter_2d);
1843
405k
                    if (res) return res;
1844
405k
                }
1845
414k
            }
1846
207k
            pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1847
207k
            switch (b->comp_type) {
1848
157k
            case COMP_INTER_AVG:
1849
157k
                dsp->mc.avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1850
157k
                            bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver
1851
157k
                            HIGHBD_CALL_SUFFIX);
1852
157k
                break;
1853
19.0k
            case COMP_INTER_WEIGHTED_AVG:
1854
19.0k
                dsp->mc.w_avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1855
19.0k
                              bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, jnt_weight
1856
19.0k
                              HIGHBD_CALL_SUFFIX);
1857
19.0k
                break;
1858
9.04k
            case COMP_INTER_WEDGE:
1859
30.6k
            case COMP_INTER_SEG:
1860
30.6k
                dsp->mc.mask(uvdst, f->cur.stride[1],
1861
30.6k
                             tmp[b->mask_sign], tmp[!b->mask_sign],
1862
30.6k
                             bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, mask
1863
30.6k
                             HIGHBD_CALL_SUFFIX);
1864
30.6k
                break;
1865
207k
            }
1866
207k
        }
1867
127k
    }
1868
1869
1.29M
    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
1.29M
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1880
1881
1.29M
    if (b->skip) {
1882
        // reset coef contexts
1883
507k
        BlockContext *const a = t->a;
1884
507k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
1885
507k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
1886
507k
        if (has_chroma) {
1887
326k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
1888
326k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
1889
326k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
1890
326k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
1891
326k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
1892
326k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
1893
326k
        }
1894
507k
        return 0;
1895
507k
    }
1896
1897
791k
    const TxfmInfo *const uvtx = &dav1d_txfm_dimensions[b->uvtx];
1898
791k
    const TxfmInfo *const ytx = &dav1d_txfm_dimensions[b->max_ytx];
1899
791k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
1900
1901
1.60M
    for (int init_y = 0; init_y < bh4; init_y += 16) {
1902
1.64M
        for (int init_x = 0; init_x < bw4; init_x += 16) {
1903
            // coefficient coding & inverse transforms
1904
834k
            int y_off = !!init_y, y;
1905
834k
            dst += PXSTRIDE(f->cur.stride[0]) * 4 * init_y;
1906
1.68M
            for (y = init_y, t->by += init_y; y < imin(h4, init_y + 16);
1907
849k
                 y += ytx->h, y_off++)
1908
849k
            {
1909
849k
                int x, x_off = !!init_x;
1910
1.76M
                for (x = init_x, t->bx += init_x; x < imin(w4, init_x + 16);
1911
910k
                     x += ytx->w, x_off++)
1912
910k
                {
1913
910k
                    read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
1914
910k
                                   x_off, y_off, &dst[x * 4]);
1915
910k
                    t->bx += ytx->w;
1916
910k
                }
1917
849k
                dst += PXSTRIDE(f->cur.stride[0]) * 4 * ytx->h;
1918
849k
                t->bx -= x;
1919
849k
                t->by += ytx->h;
1920
849k
            }
1921
834k
            dst -= PXSTRIDE(f->cur.stride[0]) * 4 * y;
1922
834k
            t->by -= y;
1923
1924
            // chroma coefs and inverse transform
1925
1.59M
            if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1926
1.06M
                pixel *uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff +
1927
1.06M
                    (PXSTRIDE(f->cur.stride[1]) * init_y * 4 >> ss_ver);
1928
1.06M
                for (y = init_y >> ss_ver, t->by += init_y;
1929
2.18M
                     y < imin(ch4, (init_y + 16) >> ss_ver); y += uvtx->h)
1930
1.12M
                {
1931
1.12M
                    int x;
1932
1.12M
                    for (x = init_x >> ss_hor, t->bx += init_x;
1933
2.38M
                         x < imin(cw4, (init_x + 16) >> ss_hor); x += uvtx->w)
1934
1.26M
                    {
1935
1.26M
                        coef *cf;
1936
1.26M
                        int eob;
1937
1.26M
                        enum TxfmType txtp;
1938
1.26M
                        if (t->frame_thread.pass) {
1939
1.26M
                            const int p = t->frame_thread.pass & 1;
1940
1.26M
                            const int cbi = *ts->frame_thread[p].cbi++;
1941
1.26M
                            cf = ts->frame_thread[p].cf;
1942
1.26M
                            ts->frame_thread[p].cf += uvtx->w * uvtx->h * 16;
1943
1.26M
                            eob  = cbi >> 5;
1944
1.26M
                            txtp = cbi & 0x1f;
1945
1.26M
                        } 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
1.26M
                        if (eob >= 0) {
1964
329k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1965
0
                                coef_dump(cf, uvtx->h * 4, uvtx->w * 4, 3, "dq");
1966
329k
                            dsp->itx.itxfm_add[b->uvtx]
1967
329k
                                              [txtp](&uvdst[4 * x],
1968
329k
                                                     f->cur.stride[1],
1969
329k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1970
329k
                            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
329k
                        }
1974
1.26M
                        t->bx += uvtx->w << ss_hor;
1975
1.26M
                    }
1976
1.12M
                    uvdst += PXSTRIDE(f->cur.stride[1]) * 4 * uvtx->h;
1977
1.12M
                    t->bx -= x << ss_hor;
1978
1.12M
                    t->by += uvtx->h << ss_ver;
1979
1.12M
                }
1980
1.06M
                t->by -= y << ss_ver;
1981
1.06M
            }
1982
834k
        }
1983
812k
    }
1984
791k
    return 0;
1985
1.29M
}
dav1d_recon_b_inter_8bpc
Line
Count
Source
1559
650k
{
1560
650k
    Dav1dTileState *const ts = t->ts;
1561
650k
    const Dav1dFrameContext *const f = t->f;
1562
650k
    const Dav1dDSPContext *const dsp = f->dsp;
1563
650k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1564
650k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1565
650k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1566
650k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1567
650k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1568
650k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1569
650k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1570
650k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1571
588k
                           (bw4 > ss_hor || t->bx & 1) &&
1572
549k
                           (bh4 > ss_ver || t->by & 1);
1573
650k
    const int chr_layout_idx = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I400 ? 0 :
1574
650k
                               DAV1D_PIXEL_LAYOUT_I444 - f->cur.p.layout;
1575
650k
    int res;
1576
1577
    // prediction
1578
650k
    const int cbh4 = (bh4 + ss_ver) >> ss_ver, cbw4 = (bw4 + ss_hor) >> ss_hor;
1579
650k
    pixel *dst = ((pixel *) f->cur.data[0]) +
1580
650k
        4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1581
650k
    const ptrdiff_t uvdstoff =
1582
650k
        4 * ((t->bx >> ss_hor) + (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1583
650k
    if (IS_KEY_OR_INTRA(f->frame_hdr)) {
1584
        // intrabc
1585
211k
        assert(!f->frame_hdr->super_res.enabled);
1586
211k
        res = mc(t, dst, NULL, f->cur.stride[0], bw4, bh4, t->bx, t->by, 0,
1587
211k
                 b->mv[0], &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1588
211k
        if (res) return res;
1589
499k
        if (has_chroma) for (int pl = 1; pl < 3; pl++) {
1590
332k
            res = mc(t, ((pixel *)f->cur.data[pl]) + uvdstoff, NULL, f->cur.stride[1],
1591
332k
                     bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1592
332k
                     t->bx & ~ss_hor, t->by & ~ss_ver, pl, b->mv[0],
1593
332k
                     &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1594
332k
            if (res) return res;
1595
332k
        }
1596
438k
    } else if (b->comp_type == COMP_INTER_NONE) {
1597
372k
        const Dav1dThreadPicture *const refp = &f->refp[b->ref[0]];
1598
372k
        const enum Filter2d filter_2d = b->filter2d;
1599
1600
372k
        if (imin(bw4, bh4) > 1 &&
1601
231k
            ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1602
220k
             (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1603
13.1k
        {
1604
13.1k
            res = warp_affine(t, dst, NULL, f->cur.stride[0], b_dim, 0, refp,
1605
13.1k
                              b->motion_mode == MM_WARP ? &t->warpmv :
1606
13.1k
                                  &f->frame_hdr->gmv[b->ref[0]]);
1607
13.1k
            if (res) return res;
1608
359k
        } else {
1609
359k
            res = mc(t, dst, NULL, f->cur.stride[0],
1610
359k
                     bw4, bh4, t->bx, t->by, 0, b->mv[0], refp, b->ref[0], filter_2d);
1611
359k
            if (res) return res;
1612
359k
            if (b->motion_mode == MM_OBMC) {
1613
74.3k
                res = obmc(t, dst, f->cur.stride[0], b_dim, 0, bx4, by4, w4, h4);
1614
74.3k
                if (res) return res;
1615
74.3k
            }
1616
359k
        }
1617
372k
        if (b->interintra_type) {
1618
13.7k
            pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1619
13.7k
            enum IntraPredMode m = b->interintra_mode == II_SMOOTH_PRED ?
1620
11.3k
                                   SMOOTH_PRED : b->interintra_mode;
1621
13.7k
            pixel *const tmp = bitfn(t->scratch.interintra);
1622
13.7k
            int angle = 0;
1623
13.7k
            const pixel *top_sb_edge = NULL;
1624
13.7k
            if (!(t->by & (f->sb_step - 1))) {
1625
4.24k
                top_sb_edge = f->ipred_edge[0];
1626
4.24k
                const int sby = t->by >> f->sb_shift;
1627
4.24k
                top_sb_edge += f->sb128w * 128 * (sby - 1);
1628
4.24k
            }
1629
13.7k
            m = bytefn(dav1d_prepare_intra_edges)(t->bx, t->bx > ts->tiling.col_start,
1630
13.7k
                                                  t->by, t->by > ts->tiling.row_start,
1631
13.7k
                                                  ts->tiling.col_end, ts->tiling.row_end,
1632
13.7k
                                                  0, dst, f->cur.stride[0], top_sb_edge,
1633
13.7k
                                                  m, &angle, bw4, bh4, 0, tl_edge
1634
13.7k
                                                  HIGHBD_CALL_SUFFIX);
1635
13.7k
            dsp->ipred.intra_pred[m](tmp, 4 * bw4 * sizeof(pixel),
1636
13.7k
                                     tl_edge, bw4 * 4, bh4 * 4, 0, 0, 0
1637
13.7k
                                     HIGHBD_CALL_SUFFIX);
1638
13.7k
            dsp->mc.blend(dst, f->cur.stride[0], tmp,
1639
13.7k
                          bw4 * 4, bh4 * 4, II_MASK(0, bs, b));
1640
13.7k
        }
1641
1642
372k
        if (!has_chroma) goto skip_inter_chroma_pred;
1643
1644
        // sub8x8 derivation
1645
288k
        int is_sub8x8 = bw4 == ss_hor || bh4 == ss_ver;
1646
288k
        refmvs_block *const *r;
1647
288k
        if (is_sub8x8) {
1648
29.7k
            assert(ss_hor == 1);
1649
29.7k
            r = &t->rt.r[(t->by & 31) + 5];
1650
29.7k
            if (bw4 == 1) is_sub8x8 &= r[0][t->bx - 1].ref.ref[0] > 0;
1651
29.7k
            if (bh4 == ss_ver) is_sub8x8 &= r[-1][t->bx].ref.ref[0] > 0;
1652
29.7k
            if (bw4 == 1 && bh4 == ss_ver)
1653
6.02k
                is_sub8x8 &= r[-1][t->bx - 1].ref.ref[0] > 0;
1654
29.7k
        }
1655
1656
        // chroma prediction
1657
288k
        if (is_sub8x8) {
1658
28.3k
            assert(ss_hor == 1);
1659
28.3k
            ptrdiff_t h_off = 0, v_off = 0;
1660
28.3k
            if (bw4 == 1 && bh4 == ss_ver) {
1661
15.6k
                for (int pl = 0; pl < 2; pl++) {
1662
10.4k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1663
10.4k
                             NULL, f->cur.stride[1],
1664
10.4k
                             bw4, bh4, t->bx - 1, t->by - 1, 1 + pl,
1665
10.4k
                             r[-1][t->bx - 1].mv.mv[0],
1666
10.4k
                             &f->refp[r[-1][t->bx - 1].ref.ref[0] - 1],
1667
10.4k
                             r[-1][t->bx - 1].ref.ref[0] - 1,
1668
10.4k
                             t->frame_thread.pass != 2 ? t->tl_4x4_filter :
1669
10.4k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx - 1].filter2d);
1670
10.4k
                    if (res) return res;
1671
10.4k
                }
1672
5.21k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1673
5.21k
                h_off = 2;
1674
5.21k
            }
1675
28.3k
            if (bw4 == 1) {
1676
16.6k
                const enum Filter2d left_filter_2d =
1677
16.6k
                    dav1d_filter_2d[t->l.filter[1][by4]][t->l.filter[0][by4]];
1678
49.9k
                for (int pl = 0; pl < 2; pl++) {
1679
33.3k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + v_off, NULL,
1680
33.3k
                             f->cur.stride[1], bw4, bh4, t->bx - 1,
1681
33.3k
                             t->by, 1 + pl, r[0][t->bx - 1].mv.mv[0],
1682
33.3k
                             &f->refp[r[0][t->bx - 1].ref.ref[0] - 1],
1683
33.3k
                             r[0][t->bx - 1].ref.ref[0] - 1,
1684
33.3k
                             t->frame_thread.pass != 2 ? left_filter_2d :
1685
33.3k
                                 f->frame_thread.b[(t->by * f->b4_stride) + t->bx - 1].filter2d);
1686
33.3k
                    if (res) return res;
1687
33.3k
                }
1688
16.6k
                h_off = 2;
1689
16.6k
            }
1690
28.3k
            if (bh4 == ss_ver) {
1691
16.9k
                const enum Filter2d top_filter_2d =
1692
16.9k
                    dav1d_filter_2d[t->a->filter[1][bx4]][t->a->filter[0][bx4]];
1693
50.7k
                for (int pl = 0; pl < 2; pl++) {
1694
33.8k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off, NULL,
1695
33.8k
                             f->cur.stride[1], bw4, bh4, t->bx, t->by - 1,
1696
33.8k
                             1 + pl, r[-1][t->bx].mv.mv[0],
1697
33.8k
                             &f->refp[r[-1][t->bx].ref.ref[0] - 1],
1698
33.8k
                             r[-1][t->bx].ref.ref[0] - 1,
1699
33.8k
                             t->frame_thread.pass != 2 ? top_filter_2d :
1700
33.8k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx].filter2d);
1701
33.8k
                    if (res) return res;
1702
33.8k
                }
1703
16.9k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1704
16.9k
            }
1705
85.0k
            for (int pl = 0; pl < 2; pl++) {
1706
56.7k
                res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off + v_off, NULL, f->cur.stride[1],
1707
56.7k
                         bw4, bh4, t->bx, t->by, 1 + pl, b->mv[0],
1708
56.7k
                         refp, b->ref[0], filter_2d);
1709
56.7k
                if (res) return res;
1710
56.7k
            }
1711
260k
        } else {
1712
260k
            if (imin(cbw4, cbh4) > 1 &&
1713
137k
                ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1714
130k
                 (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1715
9.15k
            {
1716
27.4k
                for (int pl = 0; pl < 2; pl++) {
1717
18.2k
                    res = warp_affine(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff, NULL,
1718
18.2k
                                      f->cur.stride[1], b_dim, 1 + pl, refp,
1719
18.2k
                                      b->motion_mode == MM_WARP ? &t->warpmv :
1720
18.2k
                                          &f->frame_hdr->gmv[b->ref[0]]);
1721
18.2k
                    if (res) return res;
1722
18.2k
                }
1723
250k
            } else {
1724
752k
                for (int pl = 0; pl < 2; pl++) {
1725
501k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1726
501k
                             NULL, f->cur.stride[1],
1727
501k
                             bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1728
501k
                             t->bx & ~ss_hor, t->by & ~ss_ver,
1729
501k
                             1 + pl, b->mv[0], refp, b->ref[0], filter_2d);
1730
501k
                    if (res) return res;
1731
501k
                    if (b->motion_mode == MM_OBMC) {
1732
136k
                        res = obmc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1733
136k
                                   f->cur.stride[1], b_dim, 1 + pl, bx4, by4, w4, h4);
1734
136k
                        if (res) return res;
1735
136k
                    }
1736
501k
                }
1737
250k
            }
1738
260k
            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
13.0k
                const uint8_t *const ii_mask = II_MASK(chr_layout_idx, bs, b);
1743
1744
39.2k
                for (int pl = 0; pl < 2; pl++) {
1745
26.1k
                    pixel *const tmp = bitfn(t->scratch.interintra);
1746
26.1k
                    pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1747
26.1k
                    enum IntraPredMode m =
1748
26.1k
                        b->interintra_mode == II_SMOOTH_PRED ?
1749
21.5k
                        SMOOTH_PRED : b->interintra_mode;
1750
26.1k
                    int angle = 0;
1751
26.1k
                    pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1752
26.1k
                    const pixel *top_sb_edge = NULL;
1753
26.1k
                    if (!(t->by & (f->sb_step - 1))) {
1754
7.69k
                        top_sb_edge = f->ipred_edge[pl + 1];
1755
7.69k
                        const int sby = t->by >> f->sb_shift;
1756
7.69k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1757
7.69k
                    }
1758
26.1k
                    m = bytefn(dav1d_prepare_intra_edges)(t->bx >> ss_hor,
1759
26.1k
                                                          (t->bx >> ss_hor) >
1760
26.1k
                                                              (ts->tiling.col_start >> ss_hor),
1761
26.1k
                                                          t->by >> ss_ver,
1762
26.1k
                                                          (t->by >> ss_ver) >
1763
26.1k
                                                              (ts->tiling.row_start >> ss_ver),
1764
26.1k
                                                          ts->tiling.col_end >> ss_hor,
1765
26.1k
                                                          ts->tiling.row_end >> ss_ver,
1766
26.1k
                                                          0, uvdst, f->cur.stride[1],
1767
26.1k
                                                          top_sb_edge, m,
1768
26.1k
                                                          &angle, cbw4, cbh4, 0, tl_edge
1769
26.1k
                                                          HIGHBD_CALL_SUFFIX);
1770
26.1k
                    dsp->ipred.intra_pred[m](tmp, cbw4 * 4 * sizeof(pixel),
1771
26.1k
                                             tl_edge, cbw4 * 4, cbh4 * 4, 0, 0, 0
1772
26.1k
                                             HIGHBD_CALL_SUFFIX);
1773
26.1k
                    dsp->mc.blend(uvdst, f->cur.stride[1], tmp,
1774
26.1k
                                  cbw4 * 4, cbh4 * 4, ii_mask);
1775
26.1k
                }
1776
13.0k
            }
1777
260k
        }
1778
1779
372k
    skip_inter_chroma_pred: {}
1780
372k
        t->tl_4x4_filter = filter_2d;
1781
372k
    } else {
1782
66.5k
        const enum Filter2d filter_2d = b->filter2d;
1783
        // Maximum super block size is 128x128
1784
66.5k
        int16_t (*tmp)[128 * 128] = t->scratch.compinter;
1785
66.5k
        int jnt_weight;
1786
66.5k
        uint8_t *const seg_mask = t->scratch.seg_mask;
1787
66.5k
        const uint8_t *mask;
1788
1789
199k
        for (int i = 0; i < 2; i++) {
1790
133k
            const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1791
1792
133k
            if (b->inter_mode == GLOBALMV_GLOBALMV && f->gmv_warp_allowed[b->ref[i]]) {
1793
4.43k
                res = warp_affine(t, NULL, tmp[i], bw4 * 4, b_dim, 0, refp,
1794
4.43k
                                  &f->frame_hdr->gmv[b->ref[i]]);
1795
4.43k
                if (res) return res;
1796
128k
            } else {
1797
128k
                res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by, 0,
1798
128k
                         b->mv[i], refp, b->ref[i], filter_2d);
1799
128k
                if (res) return res;
1800
128k
            }
1801
133k
        }
1802
66.5k
        switch (b->comp_type) {
1803
51.0k
        case COMP_INTER_AVG:
1804
51.0k
            dsp->mc.avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1805
51.0k
                        bw4 * 4, bh4 * 4 HIGHBD_CALL_SUFFIX);
1806
51.0k
            break;
1807
4.55k
        case COMP_INTER_WEIGHTED_AVG:
1808
4.55k
            jnt_weight = f->jnt_weights[b->ref[0]][b->ref[1]];
1809
4.55k
            dsp->mc.w_avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1810
4.55k
                          bw4 * 4, bh4 * 4, jnt_weight HIGHBD_CALL_SUFFIX);
1811
4.55k
            break;
1812
7.48k
        case COMP_INTER_SEG:
1813
7.48k
            dsp->mc.w_mask[chr_layout_idx](dst, f->cur.stride[0],
1814
7.48k
                                           tmp[b->mask_sign], tmp[!b->mask_sign],
1815
7.48k
                                           bw4 * 4, bh4 * 4, seg_mask,
1816
7.48k
                                           b->mask_sign HIGHBD_CALL_SUFFIX);
1817
7.48k
            mask = seg_mask;
1818
7.48k
            break;
1819
3.52k
        case COMP_INTER_WEDGE:
1820
3.52k
            mask = WEDGE_MASK(0, bs, 0, b->wedge_idx);
1821
3.52k
            dsp->mc.mask(dst, f->cur.stride[0],
1822
3.52k
                         tmp[b->mask_sign], tmp[!b->mask_sign],
1823
3.52k
                         bw4 * 4, bh4 * 4, mask HIGHBD_CALL_SUFFIX);
1824
3.52k
            if (has_chroma)
1825
2.97k
                mask = WEDGE_MASK(chr_layout_idx, bs, b->mask_sign, b->wedge_idx);
1826
3.52k
            break;
1827
66.5k
        }
1828
1829
        // chroma
1830
176k
        if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1831
352k
            for (int i = 0; i < 2; i++) {
1832
235k
                const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1833
235k
                if (b->inter_mode == GLOBALMV_GLOBALMV &&
1834
32.7k
                    imin(cbw4, cbh4) > 1 && f->gmv_warp_allowed[b->ref[i]])
1835
3.47k
                {
1836
3.47k
                    res = warp_affine(t, NULL, tmp[i], bw4 * 4 >> ss_hor,
1837
3.47k
                                      b_dim, 1 + pl,
1838
3.47k
                                      refp, &f->frame_hdr->gmv[b->ref[i]]);
1839
3.47k
                    if (res) return res;
1840
231k
                } else {
1841
231k
                    res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by,
1842
231k
                             1 + pl, b->mv[i], refp, b->ref[i], filter_2d);
1843
231k
                    if (res) return res;
1844
231k
                }
1845
235k
            }
1846
117k
            pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1847
117k
            switch (b->comp_type) {
1848
90.9k
            case COMP_INTER_AVG:
1849
90.9k
                dsp->mc.avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1850
90.9k
                            bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver
1851
90.9k
                            HIGHBD_CALL_SUFFIX);
1852
90.9k
                break;
1853
7.65k
            case COMP_INTER_WEIGHTED_AVG:
1854
7.65k
                dsp->mc.w_avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1855
7.65k
                              bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, jnt_weight
1856
7.65k
                              HIGHBD_CALL_SUFFIX);
1857
7.65k
                break;
1858
5.95k
            case COMP_INTER_WEDGE:
1859
19.0k
            case COMP_INTER_SEG:
1860
19.0k
                dsp->mc.mask(uvdst, f->cur.stride[1],
1861
19.0k
                             tmp[b->mask_sign], tmp[!b->mask_sign],
1862
19.0k
                             bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, mask
1863
19.0k
                             HIGHBD_CALL_SUFFIX);
1864
19.0k
                break;
1865
117k
            }
1866
117k
        }
1867
66.5k
    }
1868
1869
650k
    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
650k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1880
1881
650k
    if (b->skip) {
1882
        // reset coef contexts
1883
278k
        BlockContext *const a = t->a;
1884
278k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
1885
278k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
1886
278k
        if (has_chroma) {
1887
211k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
1888
211k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
1889
211k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
1890
211k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
1891
211k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
1892
211k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
1893
211k
        }
1894
278k
        return 0;
1895
278k
    }
1896
1897
372k
    const TxfmInfo *const uvtx = &dav1d_txfm_dimensions[b->uvtx];
1898
372k
    const TxfmInfo *const ytx = &dav1d_txfm_dimensions[b->max_ytx];
1899
372k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
1900
1901
755k
    for (int init_y = 0; init_y < bh4; init_y += 16) {
1902
777k
        for (int init_x = 0; init_x < bw4; init_x += 16) {
1903
            // coefficient coding & inverse transforms
1904
394k
            int y_off = !!init_y, y;
1905
394k
            dst += PXSTRIDE(f->cur.stride[0]) * 4 * init_y;
1906
792k
            for (y = init_y, t->by += init_y; y < imin(h4, init_y + 16);
1907
398k
                 y += ytx->h, y_off++)
1908
398k
            {
1909
398k
                int x, x_off = !!init_x;
1910
809k
                for (x = init_x, t->bx += init_x; x < imin(w4, init_x + 16);
1911
411k
                     x += ytx->w, x_off++)
1912
411k
                {
1913
411k
                    read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
1914
411k
                                   x_off, y_off, &dst[x * 4]);
1915
411k
                    t->bx += ytx->w;
1916
411k
                }
1917
398k
                dst += PXSTRIDE(f->cur.stride[0]) * 4 * ytx->h;
1918
398k
                t->bx -= x;
1919
398k
                t->by += ytx->h;
1920
398k
            }
1921
394k
            dst -= PXSTRIDE(f->cur.stride[0]) * 4 * y;
1922
394k
            t->by -= y;
1923
1924
            // chroma coefs and inverse transform
1925
967k
            if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1926
645k
                pixel *uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff +
1927
645k
                    (PXSTRIDE(f->cur.stride[1]) * init_y * 4 >> ss_ver);
1928
645k
                for (y = init_y >> ss_ver, t->by += init_y;
1929
1.31M
                     y < imin(ch4, (init_y + 16) >> ss_ver); y += uvtx->h)
1930
668k
                {
1931
668k
                    int x;
1932
668k
                    for (x = init_x >> ss_hor, t->bx += init_x;
1933
1.37M
                         x < imin(cw4, (init_x + 16) >> ss_hor); x += uvtx->w)
1934
708k
                    {
1935
708k
                        coef *cf;
1936
708k
                        int eob;
1937
708k
                        enum TxfmType txtp;
1938
708k
                        if (t->frame_thread.pass) {
1939
708k
                            const int p = t->frame_thread.pass & 1;
1940
708k
                            const int cbi = *ts->frame_thread[p].cbi++;
1941
708k
                            cf = ts->frame_thread[p].cf;
1942
708k
                            ts->frame_thread[p].cf += uvtx->w * uvtx->h * 16;
1943
708k
                            eob  = cbi >> 5;
1944
708k
                            txtp = cbi & 0x1f;
1945
708k
                        } 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
708k
                        if (eob >= 0) {
1964
171k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1965
0
                                coef_dump(cf, uvtx->h * 4, uvtx->w * 4, 3, "dq");
1966
171k
                            dsp->itx.itxfm_add[b->uvtx]
1967
171k
                                              [txtp](&uvdst[4 * x],
1968
171k
                                                     f->cur.stride[1],
1969
171k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1970
171k
                            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
171k
                        }
1974
708k
                        t->bx += uvtx->w << ss_hor;
1975
708k
                    }
1976
668k
                    uvdst += PXSTRIDE(f->cur.stride[1]) * 4 * uvtx->h;
1977
668k
                    t->bx -= x << ss_hor;
1978
668k
                    t->by += uvtx->h << ss_ver;
1979
668k
                }
1980
645k
                t->by -= y << ss_ver;
1981
645k
            }
1982
394k
        }
1983
382k
    }
1984
372k
    return 0;
1985
650k
}
dav1d_recon_b_inter_16bpc
Line
Count
Source
1559
648k
{
1560
648k
    Dav1dTileState *const ts = t->ts;
1561
648k
    const Dav1dFrameContext *const f = t->f;
1562
648k
    const Dav1dDSPContext *const dsp = f->dsp;
1563
648k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1564
648k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1565
648k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1566
648k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1567
648k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1568
648k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1569
648k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1570
648k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1571
344k
                           (bw4 > ss_hor || t->bx & 1) &&
1572
331k
                           (bh4 > ss_ver || t->by & 1);
1573
648k
    const int chr_layout_idx = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I400 ? 0 :
1574
648k
                               DAV1D_PIXEL_LAYOUT_I444 - f->cur.p.layout;
1575
648k
    int res;
1576
1577
    // prediction
1578
648k
    const int cbh4 = (bh4 + ss_ver) >> ss_ver, cbw4 = (bw4 + ss_hor) >> ss_hor;
1579
648k
    pixel *dst = ((pixel *) f->cur.data[0]) +
1580
648k
        4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1581
648k
    const ptrdiff_t uvdstoff =
1582
648k
        4 * ((t->bx >> ss_hor) + (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1583
648k
    if (IS_KEY_OR_INTRA(f->frame_hdr)) {
1584
        // intrabc
1585
209k
        assert(!f->frame_hdr->super_res.enabled);
1586
209k
        res = mc(t, dst, NULL, f->cur.stride[0], bw4, bh4, t->bx, t->by, 0,
1587
209k
                 b->mv[0], &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1588
209k
        if (res) return res;
1589
209k
        if (has_chroma) for (int pl = 1; pl < 3; pl++) {
1590
106k
            res = mc(t, ((pixel *)f->cur.data[pl]) + uvdstoff, NULL, f->cur.stride[1],
1591
106k
                     bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1592
106k
                     t->bx & ~ss_hor, t->by & ~ss_ver, pl, b->mv[0],
1593
106k
                     &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1594
106k
            if (res) return res;
1595
106k
        }
1596
439k
    } else if (b->comp_type == COMP_INTER_NONE) {
1597
378k
        const Dav1dThreadPicture *const refp = &f->refp[b->ref[0]];
1598
378k
        const enum Filter2d filter_2d = b->filter2d;
1599
1600
378k
        if (imin(bw4, bh4) > 1 &&
1601
232k
            ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1602
228k
             (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1603
7.09k
        {
1604
7.09k
            res = warp_affine(t, dst, NULL, f->cur.stride[0], b_dim, 0, refp,
1605
7.09k
                              b->motion_mode == MM_WARP ? &t->warpmv :
1606
7.09k
                                  &f->frame_hdr->gmv[b->ref[0]]);
1607
7.09k
            if (res) return res;
1608
371k
        } else {
1609
371k
            res = mc(t, dst, NULL, f->cur.stride[0],
1610
371k
                     bw4, bh4, t->bx, t->by, 0, b->mv[0], refp, b->ref[0], filter_2d);
1611
371k
            if (res) return res;
1612
371k
            if (b->motion_mode == MM_OBMC) {
1613
67.9k
                res = obmc(t, dst, f->cur.stride[0], b_dim, 0, bx4, by4, w4, h4);
1614
67.9k
                if (res) return res;
1615
67.9k
            }
1616
371k
        }
1617
378k
        if (b->interintra_type) {
1618
17.2k
            pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1619
17.2k
            enum IntraPredMode m = b->interintra_mode == II_SMOOTH_PRED ?
1620
14.2k
                                   SMOOTH_PRED : b->interintra_mode;
1621
17.2k
            pixel *const tmp = bitfn(t->scratch.interintra);
1622
17.2k
            int angle = 0;
1623
17.2k
            const pixel *top_sb_edge = NULL;
1624
17.2k
            if (!(t->by & (f->sb_step - 1))) {
1625
5.24k
                top_sb_edge = f->ipred_edge[0];
1626
5.24k
                const int sby = t->by >> f->sb_shift;
1627
5.24k
                top_sb_edge += f->sb128w * 128 * (sby - 1);
1628
5.24k
            }
1629
17.2k
            m = bytefn(dav1d_prepare_intra_edges)(t->bx, t->bx > ts->tiling.col_start,
1630
17.2k
                                                  t->by, t->by > ts->tiling.row_start,
1631
17.2k
                                                  ts->tiling.col_end, ts->tiling.row_end,
1632
17.2k
                                                  0, dst, f->cur.stride[0], top_sb_edge,
1633
17.2k
                                                  m, &angle, bw4, bh4, 0, tl_edge
1634
17.2k
                                                  HIGHBD_CALL_SUFFIX);
1635
17.2k
            dsp->ipred.intra_pred[m](tmp, 4 * bw4 * sizeof(pixel),
1636
17.2k
                                     tl_edge, bw4 * 4, bh4 * 4, 0, 0, 0
1637
17.2k
                                     HIGHBD_CALL_SUFFIX);
1638
17.2k
            dsp->mc.blend(dst, f->cur.stride[0], tmp,
1639
17.2k
                          bw4 * 4, bh4 * 4, II_MASK(0, bs, b));
1640
17.2k
        }
1641
1642
378k
        if (!has_chroma) goto skip_inter_chroma_pred;
1643
1644
        // sub8x8 derivation
1645
217k
        int is_sub8x8 = bw4 == ss_hor || bh4 == ss_ver;
1646
217k
        refmvs_block *const *r;
1647
217k
        if (is_sub8x8) {
1648
19.3k
            assert(ss_hor == 1);
1649
19.3k
            r = &t->rt.r[(t->by & 31) + 5];
1650
19.3k
            if (bw4 == 1) is_sub8x8 &= r[0][t->bx - 1].ref.ref[0] > 0;
1651
19.3k
            if (bh4 == ss_ver) is_sub8x8 &= r[-1][t->bx].ref.ref[0] > 0;
1652
19.3k
            if (bw4 == 1 && bh4 == ss_ver)
1653
2.91k
                is_sub8x8 &= r[-1][t->bx - 1].ref.ref[0] > 0;
1654
19.3k
        }
1655
1656
        // chroma prediction
1657
217k
        if (is_sub8x8) {
1658
18.4k
            assert(ss_hor == 1);
1659
18.4k
            ptrdiff_t h_off = 0, v_off = 0;
1660
18.4k
            if (bw4 == 1 && bh4 == ss_ver) {
1661
7.96k
                for (int pl = 0; pl < 2; pl++) {
1662
5.30k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1663
5.30k
                             NULL, f->cur.stride[1],
1664
5.30k
                             bw4, bh4, t->bx - 1, t->by - 1, 1 + pl,
1665
5.30k
                             r[-1][t->bx - 1].mv.mv[0],
1666
5.30k
                             &f->refp[r[-1][t->bx - 1].ref.ref[0] - 1],
1667
5.30k
                             r[-1][t->bx - 1].ref.ref[0] - 1,
1668
5.30k
                             t->frame_thread.pass != 2 ? t->tl_4x4_filter :
1669
5.30k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx - 1].filter2d);
1670
5.30k
                    if (res) return res;
1671
5.30k
                }
1672
2.65k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1673
2.65k
                h_off = 2;
1674
2.65k
            }
1675
18.4k
            if (bw4 == 1) {
1676
8.64k
                const enum Filter2d left_filter_2d =
1677
8.64k
                    dav1d_filter_2d[t->l.filter[1][by4]][t->l.filter[0][by4]];
1678
25.9k
                for (int pl = 0; pl < 2; pl++) {
1679
17.2k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + v_off, NULL,
1680
17.2k
                             f->cur.stride[1], bw4, bh4, t->bx - 1,
1681
17.2k
                             t->by, 1 + pl, r[0][t->bx - 1].mv.mv[0],
1682
17.2k
                             &f->refp[r[0][t->bx - 1].ref.ref[0] - 1],
1683
17.2k
                             r[0][t->bx - 1].ref.ref[0] - 1,
1684
17.2k
                             t->frame_thread.pass != 2 ? left_filter_2d :
1685
17.2k
                                 f->frame_thread.b[(t->by * f->b4_stride) + t->bx - 1].filter2d);
1686
17.2k
                    if (res) return res;
1687
17.2k
                }
1688
8.64k
                h_off = 2;
1689
8.64k
            }
1690
18.4k
            if (bh4 == ss_ver) {
1691
12.4k
                const enum Filter2d top_filter_2d =
1692
12.4k
                    dav1d_filter_2d[t->a->filter[1][bx4]][t->a->filter[0][bx4]];
1693
37.4k
                for (int pl = 0; pl < 2; pl++) {
1694
24.9k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off, NULL,
1695
24.9k
                             f->cur.stride[1], bw4, bh4, t->bx, t->by - 1,
1696
24.9k
                             1 + pl, r[-1][t->bx].mv.mv[0],
1697
24.9k
                             &f->refp[r[-1][t->bx].ref.ref[0] - 1],
1698
24.9k
                             r[-1][t->bx].ref.ref[0] - 1,
1699
24.9k
                             t->frame_thread.pass != 2 ? top_filter_2d :
1700
24.9k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx].filter2d);
1701
24.9k
                    if (res) return res;
1702
24.9k
                }
1703
12.4k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1704
12.4k
            }
1705
55.3k
            for (int pl = 0; pl < 2; pl++) {
1706
36.9k
                res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off + v_off, NULL, f->cur.stride[1],
1707
36.9k
                         bw4, bh4, t->bx, t->by, 1 + pl, b->mv[0],
1708
36.9k
                         refp, b->ref[0], filter_2d);
1709
36.9k
                if (res) return res;
1710
36.9k
            }
1711
199k
        } else {
1712
199k
            if (imin(cbw4, cbh4) > 1 &&
1713
111k
                ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1714
108k
                 (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1715
4.66k
            {
1716
13.9k
                for (int pl = 0; pl < 2; pl++) {
1717
9.32k
                    res = warp_affine(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff, NULL,
1718
9.32k
                                      f->cur.stride[1], b_dim, 1 + pl, refp,
1719
9.32k
                                      b->motion_mode == MM_WARP ? &t->warpmv :
1720
9.32k
                                          &f->frame_hdr->gmv[b->ref[0]]);
1721
9.32k
                    if (res) return res;
1722
9.32k
                }
1723
194k
            } else {
1724
583k
                for (int pl = 0; pl < 2; pl++) {
1725
388k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1726
388k
                             NULL, f->cur.stride[1],
1727
388k
                             bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1728
388k
                             t->bx & ~ss_hor, t->by & ~ss_ver,
1729
388k
                             1 + pl, b->mv[0], refp, b->ref[0], filter_2d);
1730
388k
                    if (res) return res;
1731
388k
                    if (b->motion_mode == MM_OBMC) {
1732
93.5k
                        res = obmc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1733
93.5k
                                   f->cur.stride[1], b_dim, 1 + pl, bx4, by4, w4, h4);
1734
93.5k
                        if (res) return res;
1735
93.5k
                    }
1736
388k
                }
1737
194k
            }
1738
199k
            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
14.9k
                const uint8_t *const ii_mask = II_MASK(chr_layout_idx, bs, b);
1743
1744
44.8k
                for (int pl = 0; pl < 2; pl++) {
1745
29.9k
                    pixel *const tmp = bitfn(t->scratch.interintra);
1746
29.9k
                    pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1747
29.9k
                    enum IntraPredMode m =
1748
29.9k
                        b->interintra_mode == II_SMOOTH_PRED ?
1749
24.7k
                        SMOOTH_PRED : b->interintra_mode;
1750
29.9k
                    int angle = 0;
1751
29.9k
                    pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1752
29.9k
                    const pixel *top_sb_edge = NULL;
1753
29.9k
                    if (!(t->by & (f->sb_step - 1))) {
1754
7.77k
                        top_sb_edge = f->ipred_edge[pl + 1];
1755
7.77k
                        const int sby = t->by >> f->sb_shift;
1756
7.77k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1757
7.77k
                    }
1758
29.9k
                    m = bytefn(dav1d_prepare_intra_edges)(t->bx >> ss_hor,
1759
29.9k
                                                          (t->bx >> ss_hor) >
1760
29.9k
                                                              (ts->tiling.col_start >> ss_hor),
1761
29.9k
                                                          t->by >> ss_ver,
1762
29.9k
                                                          (t->by >> ss_ver) >
1763
29.9k
                                                              (ts->tiling.row_start >> ss_ver),
1764
29.9k
                                                          ts->tiling.col_end >> ss_hor,
1765
29.9k
                                                          ts->tiling.row_end >> ss_ver,
1766
29.9k
                                                          0, uvdst, f->cur.stride[1],
1767
29.9k
                                                          top_sb_edge, m,
1768
29.9k
                                                          &angle, cbw4, cbh4, 0, tl_edge
1769
29.9k
                                                          HIGHBD_CALL_SUFFIX);
1770
29.9k
                    dsp->ipred.intra_pred[m](tmp, cbw4 * 4 * sizeof(pixel),
1771
29.9k
                                             tl_edge, cbw4 * 4, cbh4 * 4, 0, 0, 0
1772
29.9k
                                             HIGHBD_CALL_SUFFIX);
1773
29.9k
                    dsp->mc.blend(uvdst, f->cur.stride[1], tmp,
1774
29.9k
                                  cbw4 * 4, cbh4 * 4, ii_mask);
1775
29.9k
                }
1776
14.9k
            }
1777
199k
        }
1778
1779
378k
    skip_inter_chroma_pred: {}
1780
378k
        t->tl_4x4_filter = filter_2d;
1781
378k
    } else {
1782
60.5k
        const enum Filter2d filter_2d = b->filter2d;
1783
        // Maximum super block size is 128x128
1784
60.5k
        int16_t (*tmp)[128 * 128] = t->scratch.compinter;
1785
60.5k
        int jnt_weight;
1786
60.5k
        uint8_t *const seg_mask = t->scratch.seg_mask;
1787
60.5k
        const uint8_t *mask;
1788
1789
181k
        for (int i = 0; i < 2; i++) {
1790
121k
            const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1791
1792
121k
            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
116k
            } else {
1797
116k
                res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by, 0,
1798
116k
                         b->mv[i], refp, b->ref[i], filter_2d);
1799
116k
                if (res) return res;
1800
116k
            }
1801
121k
        }
1802
60.5k
        switch (b->comp_type) {
1803
44.0k
        case COMP_INTER_AVG:
1804
44.0k
            dsp->mc.avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1805
44.0k
                        bw4 * 4, bh4 * 4 HIGHBD_CALL_SUFFIX);
1806
44.0k
            break;
1807
8.60k
        case COMP_INTER_WEIGHTED_AVG:
1808
8.60k
            jnt_weight = f->jnt_weights[b->ref[0]][b->ref[1]];
1809
8.60k
            dsp->mc.w_avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1810
8.60k
                          bw4 * 4, bh4 * 4, jnt_weight HIGHBD_CALL_SUFFIX);
1811
8.60k
            break;
1812
5.48k
        case COMP_INTER_SEG:
1813
5.48k
            dsp->mc.w_mask[chr_layout_idx](dst, f->cur.stride[0],
1814
5.48k
                                           tmp[b->mask_sign], tmp[!b->mask_sign],
1815
5.48k
                                           bw4 * 4, bh4 * 4, seg_mask,
1816
5.48k
                                           b->mask_sign HIGHBD_CALL_SUFFIX);
1817
5.48k
            mask = seg_mask;
1818
5.48k
            break;
1819
2.38k
        case COMP_INTER_WEDGE:
1820
2.38k
            mask = WEDGE_MASK(0, bs, 0, b->wedge_idx);
1821
2.38k
            dsp->mc.mask(dst, f->cur.stride[0],
1822
2.38k
                         tmp[b->mask_sign], tmp[!b->mask_sign],
1823
2.38k
                         bw4 * 4, bh4 * 4, mask HIGHBD_CALL_SUFFIX);
1824
2.38k
            if (has_chroma)
1825
1.54k
                mask = WEDGE_MASK(chr_layout_idx, bs, b->mask_sign, b->wedge_idx);
1826
2.38k
            break;
1827
60.5k
        }
1828
1829
        // chroma
1830
134k
        if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1831
269k
            for (int i = 0; i < 2; i++) {
1832
179k
                const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1833
179k
                if (b->inter_mode == GLOBALMV_GLOBALMV &&
1834
29.3k
                    imin(cbw4, cbh4) > 1 && f->gmv_warp_allowed[b->ref[i]])
1835
5.71k
                {
1836
5.71k
                    res = warp_affine(t, NULL, tmp[i], bw4 * 4 >> ss_hor,
1837
5.71k
                                      b_dim, 1 + pl,
1838
5.71k
                                      refp, &f->frame_hdr->gmv[b->ref[i]]);
1839
5.71k
                    if (res) return res;
1840
173k
                } else {
1841
173k
                    res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by,
1842
173k
                             1 + pl, b->mv[i], refp, b->ref[i], filter_2d);
1843
173k
                    if (res) return res;
1844
173k
                }
1845
179k
            }
1846
89.7k
            pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1847
89.7k
            switch (b->comp_type) {
1848
66.7k
            case COMP_INTER_AVG:
1849
66.7k
                dsp->mc.avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1850
66.7k
                            bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver
1851
66.7k
                            HIGHBD_CALL_SUFFIX);
1852
66.7k
                break;
1853
11.3k
            case COMP_INTER_WEIGHTED_AVG:
1854
11.3k
                dsp->mc.w_avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1855
11.3k
                              bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, jnt_weight
1856
11.3k
                              HIGHBD_CALL_SUFFIX);
1857
11.3k
                break;
1858
3.08k
            case COMP_INTER_WEDGE:
1859
11.6k
            case COMP_INTER_SEG:
1860
11.6k
                dsp->mc.mask(uvdst, f->cur.stride[1],
1861
11.6k
                             tmp[b->mask_sign], tmp[!b->mask_sign],
1862
11.6k
                             bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, mask
1863
11.6k
                             HIGHBD_CALL_SUFFIX);
1864
11.6k
                break;
1865
89.7k
            }
1866
89.7k
        }
1867
60.5k
    }
1868
1869
648k
    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
648k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1880
1881
648k
    if (b->skip) {
1882
        // reset coef contexts
1883
229k
        BlockContext *const a = t->a;
1884
229k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
1885
229k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
1886
229k
        if (has_chroma) {
1887
115k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
1888
115k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
1889
115k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
1890
115k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
1891
115k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
1892
115k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
1893
115k
        }
1894
229k
        return 0;
1895
229k
    }
1896
1897
418k
    const TxfmInfo *const uvtx = &dav1d_txfm_dimensions[b->uvtx];
1898
418k
    const TxfmInfo *const ytx = &dav1d_txfm_dimensions[b->max_ytx];
1899
418k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
1900
1901
848k
    for (int init_y = 0; init_y < bh4; init_y += 16) {
1902
869k
        for (int init_x = 0; init_x < bw4; init_x += 16) {
1903
            // coefficient coding & inverse transforms
1904
439k
            int y_off = !!init_y, y;
1905
439k
            dst += PXSTRIDE(f->cur.stride[0]) * 4 * init_y;
1906
891k
            for (y = init_y, t->by += init_y; y < imin(h4, init_y + 16);
1907
451k
                 y += ytx->h, y_off++)
1908
451k
            {
1909
451k
                int x, x_off = !!init_x;
1910
950k
                for (x = init_x, t->bx += init_x; x < imin(w4, init_x + 16);
1911
499k
                     x += ytx->w, x_off++)
1912
499k
                {
1913
499k
                    read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
1914
499k
                                   x_off, y_off, &dst[x * 4]);
1915
499k
                    t->bx += ytx->w;
1916
499k
                }
1917
451k
                dst += PXSTRIDE(f->cur.stride[0]) * 4 * ytx->h;
1918
451k
                t->bx -= x;
1919
451k
                t->by += ytx->h;
1920
451k
            }
1921
439k
            dst -= PXSTRIDE(f->cur.stride[0]) * 4 * y;
1922
439k
            t->by -= y;
1923
1924
            // chroma coefs and inverse transform
1925
625k
            if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1926
417k
                pixel *uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff +
1927
417k
                    (PXSTRIDE(f->cur.stride[1]) * init_y * 4 >> ss_ver);
1928
417k
                for (y = init_y >> ss_ver, t->by += init_y;
1929
871k
                     y < imin(ch4, (init_y + 16) >> ss_ver); y += uvtx->h)
1930
454k
                {
1931
454k
                    int x;
1932
454k
                    for (x = init_x >> ss_hor, t->bx += init_x;
1933
1.01M
                         x < imin(cw4, (init_x + 16) >> ss_hor); x += uvtx->w)
1934
558k
                    {
1935
558k
                        coef *cf;
1936
558k
                        int eob;
1937
558k
                        enum TxfmType txtp;
1938
558k
                        if (t->frame_thread.pass) {
1939
558k
                            const int p = t->frame_thread.pass & 1;
1940
558k
                            const int cbi = *ts->frame_thread[p].cbi++;
1941
558k
                            cf = ts->frame_thread[p].cf;
1942
558k
                            ts->frame_thread[p].cf += uvtx->w * uvtx->h * 16;
1943
558k
                            eob  = cbi >> 5;
1944
558k
                            txtp = cbi & 0x1f;
1945
558k
                        } 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
558k
                        if (eob >= 0) {
1964
158k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1965
0
                                coef_dump(cf, uvtx->h * 4, uvtx->w * 4, 3, "dq");
1966
158k
                            dsp->itx.itxfm_add[b->uvtx]
1967
158k
                                              [txtp](&uvdst[4 * x],
1968
158k
                                                     f->cur.stride[1],
1969
158k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1970
158k
                            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
158k
                        }
1974
558k
                        t->bx += uvtx->w << ss_hor;
1975
558k
                    }
1976
454k
                    uvdst += PXSTRIDE(f->cur.stride[1]) * 4 * uvtx->h;
1977
454k
                    t->bx -= x << ss_hor;
1978
454k
                    t->by += uvtx->h << ss_ver;
1979
454k
                }
1980
417k
                t->by -= y << ss_ver;
1981
417k
            }
1982
439k
        }
1983
429k
    }
1984
418k
    return 0;
1985
648k
}
1986
1987
360k
void bytefn(dav1d_filter_sbrow_deblock_cols)(Dav1dFrameContext *const f, const int sby) {
1988
360k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK) ||
1989
360k
        (!f->frame_hdr->loopfilter.level_y[0] && !f->frame_hdr->loopfilter.level_y[1]))
1990
0
    {
1991
0
        return;
1992
0
    }
1993
360k
    const int y = sby * f->sb_step * 4;
1994
360k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1995
360k
    pixel *const p[3] = {
1996
360k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
1997
360k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
1998
360k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
1999
360k
    };
2000
360k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2001
360k
    bytefn(dav1d_loopfilter_sbrow_cols)(f, p, mask, sby,
2002
360k
                                        f->lf.start_of_tile_row[sby]);
2003
360k
}
dav1d_filter_sbrow_deblock_cols_8bpc
Line
Count
Source
1987
175k
void bytefn(dav1d_filter_sbrow_deblock_cols)(Dav1dFrameContext *const f, const int sby) {
1988
175k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK) ||
1989
175k
        (!f->frame_hdr->loopfilter.level_y[0] && !f->frame_hdr->loopfilter.level_y[1]))
1990
0
    {
1991
0
        return;
1992
0
    }
1993
175k
    const int y = sby * f->sb_step * 4;
1994
175k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1995
175k
    pixel *const p[3] = {
1996
175k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
1997
175k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
1998
175k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
1999
175k
    };
2000
175k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2001
175k
    bytefn(dav1d_loopfilter_sbrow_cols)(f, p, mask, sby,
2002
175k
                                        f->lf.start_of_tile_row[sby]);
2003
175k
}
dav1d_filter_sbrow_deblock_cols_16bpc
Line
Count
Source
1987
185k
void bytefn(dav1d_filter_sbrow_deblock_cols)(Dav1dFrameContext *const f, const int sby) {
1988
185k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK) ||
1989
185k
        (!f->frame_hdr->loopfilter.level_y[0] && !f->frame_hdr->loopfilter.level_y[1]))
1990
0
    {
1991
0
        return;
1992
0
    }
1993
185k
    const int y = sby * f->sb_step * 4;
1994
185k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1995
185k
    pixel *const p[3] = {
1996
185k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
1997
185k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
1998
185k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
1999
185k
    };
2000
185k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2001
185k
    bytefn(dav1d_loopfilter_sbrow_cols)(f, p, mask, sby,
2002
185k
                                        f->lf.start_of_tile_row[sby]);
2003
185k
}
2004
2005
421k
void bytefn(dav1d_filter_sbrow_deblock_rows)(Dav1dFrameContext *const f, const int sby) {
2006
421k
    const int y = sby * f->sb_step * 4;
2007
421k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2008
421k
    pixel *const p[3] = {
2009
421k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2010
421k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2011
421k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2012
421k
    };
2013
421k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2014
421k
    if (f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK &&
2015
421k
        (f->frame_hdr->loopfilter.level_y[0] || f->frame_hdr->loopfilter.level_y[1]))
2016
360k
    {
2017
360k
        bytefn(dav1d_loopfilter_sbrow_rows)(f, p, mask, sby);
2018
360k
    }
2019
421k
    if (f->seq_hdr->cdef || f->lf.restore_planes) {
2020
        // Store loop filtered pixels required by CDEF / LR
2021
350k
        bytefn(dav1d_copy_lpf)(f, p, sby);
2022
350k
    }
2023
421k
}
dav1d_filter_sbrow_deblock_rows_8bpc
Line
Count
Source
2005
212k
void bytefn(dav1d_filter_sbrow_deblock_rows)(Dav1dFrameContext *const f, const int sby) {
2006
212k
    const int y = sby * f->sb_step * 4;
2007
212k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2008
212k
    pixel *const p[3] = {
2009
212k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2010
212k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2011
212k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2012
212k
    };
2013
212k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2014
212k
    if (f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK &&
2015
212k
        (f->frame_hdr->loopfilter.level_y[0] || f->frame_hdr->loopfilter.level_y[1]))
2016
175k
    {
2017
175k
        bytefn(dav1d_loopfilter_sbrow_rows)(f, p, mask, sby);
2018
175k
    }
2019
212k
    if (f->seq_hdr->cdef || f->lf.restore_planes) {
2020
        // Store loop filtered pixels required by CDEF / LR
2021
171k
        bytefn(dav1d_copy_lpf)(f, p, sby);
2022
171k
    }
2023
212k
}
dav1d_filter_sbrow_deblock_rows_16bpc
Line
Count
Source
2005
208k
void bytefn(dav1d_filter_sbrow_deblock_rows)(Dav1dFrameContext *const f, const int sby) {
2006
208k
    const int y = sby * f->sb_step * 4;
2007
208k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2008
208k
    pixel *const p[3] = {
2009
208k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2010
208k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2011
208k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2012
208k
    };
2013
208k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2014
208k
    if (f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK &&
2015
208k
        (f->frame_hdr->loopfilter.level_y[0] || f->frame_hdr->loopfilter.level_y[1]))
2016
184k
    {
2017
184k
        bytefn(dav1d_loopfilter_sbrow_rows)(f, p, mask, sby);
2018
184k
    }
2019
208k
    if (f->seq_hdr->cdef || f->lf.restore_planes) {
2020
        // Store loop filtered pixels required by CDEF / LR
2021
179k
        bytefn(dav1d_copy_lpf)(f, p, sby);
2022
179k
    }
2023
208k
}
2024
2025
250k
void bytefn(dav1d_filter_sbrow_cdef)(Dav1dTaskContext *const tc, const int sby) {
2026
250k
    const Dav1dFrameContext *const f = tc->f;
2027
250k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_CDEF)) return;
2028
250k
    const int sbsz = f->sb_step;
2029
250k
    const int y = sby * sbsz * 4;
2030
250k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2031
250k
    pixel *const p[3] = {
2032
250k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2033
250k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2034
250k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2035
250k
    };
2036
250k
    Av1Filter *prev_mask = f->lf.mask + ((sby - 1) >> !f->seq_hdr->sb128) * f->sb128w;
2037
250k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2038
250k
    const int start = sby * sbsz;
2039
250k
    if (sby) {
2040
133k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2041
133k
        pixel *p_up[3] = {
2042
133k
            p[0] - 8 * PXSTRIDE(f->cur.stride[0]),
2043
133k
            p[1] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2044
133k
            p[2] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2045
133k
        };
2046
133k
        bytefn(dav1d_cdef_brow)(tc, p_up, prev_mask, start - 2, start, 1, sby);
2047
133k
    }
2048
250k
    const int n_blks = sbsz - 2 * (sby + 1 < f->sbh);
2049
250k
    const int end = imin(start + n_blks, f->bh);
2050
250k
    bytefn(dav1d_cdef_brow)(tc, p, mask, start, end, 0, sby);
2051
250k
}
dav1d_filter_sbrow_cdef_8bpc
Line
Count
Source
2025
134k
void bytefn(dav1d_filter_sbrow_cdef)(Dav1dTaskContext *const tc, const int sby) {
2026
134k
    const Dav1dFrameContext *const f = tc->f;
2027
134k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_CDEF)) return;
2028
134k
    const int sbsz = f->sb_step;
2029
134k
    const int y = sby * sbsz * 4;
2030
134k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2031
134k
    pixel *const p[3] = {
2032
134k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2033
134k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2034
134k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2035
134k
    };
2036
134k
    Av1Filter *prev_mask = f->lf.mask + ((sby - 1) >> !f->seq_hdr->sb128) * f->sb128w;
2037
134k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2038
134k
    const int start = sby * sbsz;
2039
134k
    if (sby) {
2040
84.3k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2041
84.3k
        pixel *p_up[3] = {
2042
84.3k
            p[0] - 8 * PXSTRIDE(f->cur.stride[0]),
2043
84.3k
            p[1] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2044
84.3k
            p[2] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2045
84.3k
        };
2046
84.3k
        bytefn(dav1d_cdef_brow)(tc, p_up, prev_mask, start - 2, start, 1, sby);
2047
84.3k
    }
2048
134k
    const int n_blks = sbsz - 2 * (sby + 1 < f->sbh);
2049
134k
    const int end = imin(start + n_blks, f->bh);
2050
134k
    bytefn(dav1d_cdef_brow)(tc, p, mask, start, end, 0, sby);
2051
134k
}
dav1d_filter_sbrow_cdef_16bpc
Line
Count
Source
2025
115k
void bytefn(dav1d_filter_sbrow_cdef)(Dav1dTaskContext *const tc, const int sby) {
2026
115k
    const Dav1dFrameContext *const f = tc->f;
2027
115k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_CDEF)) return;
2028
115k
    const int sbsz = f->sb_step;
2029
115k
    const int y = sby * sbsz * 4;
2030
115k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2031
115k
    pixel *const p[3] = {
2032
115k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2033
115k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2034
115k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2035
115k
    };
2036
115k
    Av1Filter *prev_mask = f->lf.mask + ((sby - 1) >> !f->seq_hdr->sb128) * f->sb128w;
2037
115k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2038
115k
    const int start = sby * sbsz;
2039
115k
    if (sby) {
2040
49.3k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2041
49.3k
        pixel *p_up[3] = {
2042
49.3k
            p[0] - 8 * PXSTRIDE(f->cur.stride[0]),
2043
49.3k
            p[1] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2044
49.3k
            p[2] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2045
49.3k
        };
2046
49.3k
        bytefn(dav1d_cdef_brow)(tc, p_up, prev_mask, start - 2, start, 1, sby);
2047
49.3k
    }
2048
115k
    const int n_blks = sbsz - 2 * (sby + 1 < f->sbh);
2049
115k
    const int end = imin(start + n_blks, f->bh);
2050
115k
    bytefn(dav1d_cdef_brow)(tc, p, mask, start, end, 0, sby);
2051
115k
}
2052
2053
66.5k
void bytefn(dav1d_filter_sbrow_resize)(Dav1dFrameContext *const f, const int sby) {
2054
66.5k
    const int sbsz = f->sb_step;
2055
66.5k
    const int y = sby * sbsz * 4;
2056
66.5k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2057
66.5k
    const pixel *const p[3] = {
2058
66.5k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2059
66.5k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2060
66.5k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2061
66.5k
    };
2062
66.5k
    pixel *const sr_p[3] = {
2063
66.5k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2064
66.5k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2065
66.5k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2066
66.5k
    };
2067
66.5k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400;
2068
249k
    for (int pl = 0; pl < 1 + 2 * has_chroma; pl++) {
2069
182k
        const int ss_ver = pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2070
182k
        const int h_start = 8 * !!sby >> ss_ver;
2071
182k
        const ptrdiff_t dst_stride = f->sr_cur.p.stride[!!pl];
2072
182k
        pixel *dst = sr_p[pl] - h_start * PXSTRIDE(dst_stride);
2073
182k
        const ptrdiff_t src_stride = f->cur.stride[!!pl];
2074
182k
        const pixel *src = p[pl] - h_start * PXSTRIDE(src_stride);
2075
182k
        const int h_end = 4 * (sbsz - 2 * (sby + 1 < f->sbh)) >> ss_ver;
2076
182k
        const int ss_hor = pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2077
182k
        const int dst_w = (f->sr_cur.p.p.w + ss_hor) >> ss_hor;
2078
182k
        const int src_w = (4 * f->bw + ss_hor) >> ss_hor;
2079
182k
        const int img_h = (f->cur.p.h - sbsz * 4 * sby + ss_ver) >> ss_ver;
2080
2081
182k
        f->dsp->mc.resize(dst, dst_stride, src, src_stride, dst_w,
2082
182k
                          imin(img_h, h_end) + h_start, src_w,
2083
182k
                          f->resize_step[!!pl], f->resize_start[!!pl]
2084
182k
                          HIGHBD_CALL_SUFFIX);
2085
182k
    }
2086
66.5k
}
dav1d_filter_sbrow_resize_8bpc
Line
Count
Source
2053
29.6k
void bytefn(dav1d_filter_sbrow_resize)(Dav1dFrameContext *const f, const int sby) {
2054
29.6k
    const int sbsz = f->sb_step;
2055
29.6k
    const int y = sby * sbsz * 4;
2056
29.6k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2057
29.6k
    const pixel *const p[3] = {
2058
29.6k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2059
29.6k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2060
29.6k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2061
29.6k
    };
2062
29.6k
    pixel *const sr_p[3] = {
2063
29.6k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2064
29.6k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2065
29.6k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2066
29.6k
    };
2067
29.6k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400;
2068
111k
    for (int pl = 0; pl < 1 + 2 * has_chroma; pl++) {
2069
81.4k
        const int ss_ver = pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2070
81.4k
        const int h_start = 8 * !!sby >> ss_ver;
2071
81.4k
        const ptrdiff_t dst_stride = f->sr_cur.p.stride[!!pl];
2072
81.4k
        pixel *dst = sr_p[pl] - h_start * PXSTRIDE(dst_stride);
2073
81.4k
        const ptrdiff_t src_stride = f->cur.stride[!!pl];
2074
81.4k
        const pixel *src = p[pl] - h_start * PXSTRIDE(src_stride);
2075
81.4k
        const int h_end = 4 * (sbsz - 2 * (sby + 1 < f->sbh)) >> ss_ver;
2076
81.4k
        const int ss_hor = pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2077
81.4k
        const int dst_w = (f->sr_cur.p.p.w + ss_hor) >> ss_hor;
2078
81.4k
        const int src_w = (4 * f->bw + ss_hor) >> ss_hor;
2079
81.4k
        const int img_h = (f->cur.p.h - sbsz * 4 * sby + ss_ver) >> ss_ver;
2080
2081
81.4k
        f->dsp->mc.resize(dst, dst_stride, src, src_stride, dst_w,
2082
81.4k
                          imin(img_h, h_end) + h_start, src_w,
2083
81.4k
                          f->resize_step[!!pl], f->resize_start[!!pl]
2084
81.4k
                          HIGHBD_CALL_SUFFIX);
2085
81.4k
    }
2086
29.6k
}
dav1d_filter_sbrow_resize_16bpc
Line
Count
Source
2053
36.9k
void bytefn(dav1d_filter_sbrow_resize)(Dav1dFrameContext *const f, const int sby) {
2054
36.9k
    const int sbsz = f->sb_step;
2055
36.9k
    const int y = sby * sbsz * 4;
2056
36.9k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2057
36.9k
    const pixel *const p[3] = {
2058
36.9k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2059
36.9k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2060
36.9k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2061
36.9k
    };
2062
36.9k
    pixel *const sr_p[3] = {
2063
36.9k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2064
36.9k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2065
36.9k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2066
36.9k
    };
2067
36.9k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400;
2068
138k
    for (int pl = 0; pl < 1 + 2 * has_chroma; pl++) {
2069
101k
        const int ss_ver = pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2070
101k
        const int h_start = 8 * !!sby >> ss_ver;
2071
101k
        const ptrdiff_t dst_stride = f->sr_cur.p.stride[!!pl];
2072
101k
        pixel *dst = sr_p[pl] - h_start * PXSTRIDE(dst_stride);
2073
101k
        const ptrdiff_t src_stride = f->cur.stride[!!pl];
2074
101k
        const pixel *src = p[pl] - h_start * PXSTRIDE(src_stride);
2075
101k
        const int h_end = 4 * (sbsz - 2 * (sby + 1 < f->sbh)) >> ss_ver;
2076
101k
        const int ss_hor = pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2077
101k
        const int dst_w = (f->sr_cur.p.p.w + ss_hor) >> ss_hor;
2078
101k
        const int src_w = (4 * f->bw + ss_hor) >> ss_hor;
2079
101k
        const int img_h = (f->cur.p.h - sbsz * 4 * sby + ss_ver) >> ss_ver;
2080
2081
101k
        f->dsp->mc.resize(dst, dst_stride, src, src_stride, dst_w,
2082
101k
                          imin(img_h, h_end) + h_start, src_w,
2083
101k
                          f->resize_step[!!pl], f->resize_start[!!pl]
2084
101k
                          HIGHBD_CALL_SUFFIX);
2085
101k
    }
2086
36.9k
}
2087
2088
249k
void bytefn(dav1d_filter_sbrow_lr)(Dav1dFrameContext *const f, const int sby) {
2089
249k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_RESTORATION)) return;
2090
249k
    const int y = sby * f->sb_step * 4;
2091
249k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2092
249k
    pixel *const sr_p[3] = {
2093
249k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2094
249k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2095
249k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2096
249k
    };
2097
249k
    bytefn(dav1d_lr_sbrow)(f, sr_p, sby);
2098
249k
}
dav1d_filter_sbrow_lr_8bpc
Line
Count
Source
2088
119k
void bytefn(dav1d_filter_sbrow_lr)(Dav1dFrameContext *const f, const int sby) {
2089
119k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_RESTORATION)) return;
2090
119k
    const int y = sby * f->sb_step * 4;
2091
119k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2092
119k
    pixel *const sr_p[3] = {
2093
119k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2094
119k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2095
119k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2096
119k
    };
2097
119k
    bytefn(dav1d_lr_sbrow)(f, sr_p, sby);
2098
119k
}
dav1d_filter_sbrow_lr_16bpc
Line
Count
Source
2088
130k
void bytefn(dav1d_filter_sbrow_lr)(Dav1dFrameContext *const f, const int sby) {
2089
130k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_RESTORATION)) return;
2090
130k
    const int y = sby * f->sb_step * 4;
2091
130k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2092
130k
    pixel *const sr_p[3] = {
2093
130k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2094
130k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2095
130k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2096
130k
    };
2097
130k
    bytefn(dav1d_lr_sbrow)(f, sr_p, sby);
2098
130k
}
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
469k
void bytefn(dav1d_backup_ipred_edge)(Dav1dTaskContext *const t) {
2112
469k
    const Dav1dFrameContext *const f = t->f;
2113
469k
    Dav1dTileState *const ts = t->ts;
2114
469k
    const int sby = t->by >> f->sb_shift;
2115
469k
    const int sby_off = f->sb128w * 128 * sby;
2116
469k
    const int x_off = ts->tiling.col_start;
2117
2118
469k
    const pixel *const y =
2119
469k
        ((const pixel *) f->cur.data[0]) + x_off * 4 +
2120
469k
                    ((t->by + f->sb_step) * 4 - 1) * PXSTRIDE(f->cur.stride[0]);
2121
469k
    pixel_copy(&f->ipred_edge[0][sby_off + x_off * 4], y,
2122
469k
               4 * (ts->tiling.col_end - x_off));
2123
2124
469k
    if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
2125
364k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2126
364k
        const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2127
2128
364k
        const ptrdiff_t uv_off = (x_off * 4 >> ss_hor) +
2129
364k
            (((t->by + f->sb_step) * 4 >> ss_ver) - 1) * PXSTRIDE(f->cur.stride[1]);
2130
1.09M
        for (int pl = 1; pl <= 2; pl++)
2131
728k
            pixel_copy(&f->ipred_edge[pl][sby_off + (x_off * 4 >> ss_hor)],
2132
401k
                       &((const pixel *) f->cur.data[pl])[uv_off],
2133
401k
                       4 * (ts->tiling.col_end - x_off) >> ss_hor);
2134
364k
    }
2135
469k
}
dav1d_backup_ipred_edge_8bpc
Line
Count
Source
2111
238k
void bytefn(dav1d_backup_ipred_edge)(Dav1dTaskContext *const t) {
2112
238k
    const Dav1dFrameContext *const f = t->f;
2113
238k
    Dav1dTileState *const ts = t->ts;
2114
238k
    const int sby = t->by >> f->sb_shift;
2115
238k
    const int sby_off = f->sb128w * 128 * sby;
2116
238k
    const int x_off = ts->tiling.col_start;
2117
2118
238k
    const pixel *const y =
2119
238k
        ((const pixel *) f->cur.data[0]) + x_off * 4 +
2120
238k
                    ((t->by + f->sb_step) * 4 - 1) * PXSTRIDE(f->cur.stride[0]);
2121
238k
    pixel_copy(&f->ipred_edge[0][sby_off + x_off * 4], y,
2122
238k
               4 * (ts->tiling.col_end - x_off));
2123
2124
238k
    if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
2125
200k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2126
200k
        const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2127
2128
200k
        const ptrdiff_t uv_off = (x_off * 4 >> ss_hor) +
2129
200k
            (((t->by + f->sb_step) * 4 >> ss_ver) - 1) * PXSTRIDE(f->cur.stride[1]);
2130
602k
        for (int pl = 1; pl <= 2; pl++)
2131
401k
            pixel_copy(&f->ipred_edge[pl][sby_off + (x_off * 4 >> ss_hor)],
2132
401k
                       &((const pixel *) f->cur.data[pl])[uv_off],
2133
401k
                       4 * (ts->tiling.col_end - x_off) >> ss_hor);
2134
200k
    }
2135
238k
}
dav1d_backup_ipred_edge_16bpc
Line
Count
Source
2111
231k
void bytefn(dav1d_backup_ipred_edge)(Dav1dTaskContext *const t) {
2112
231k
    const Dav1dFrameContext *const f = t->f;
2113
231k
    Dav1dTileState *const ts = t->ts;
2114
231k
    const int sby = t->by >> f->sb_shift;
2115
231k
    const int sby_off = f->sb128w * 128 * sby;
2116
231k
    const int x_off = ts->tiling.col_start;
2117
2118
231k
    const pixel *const y =
2119
231k
        ((const pixel *) f->cur.data[0]) + x_off * 4 +
2120
231k
                    ((t->by + f->sb_step) * 4 - 1) * PXSTRIDE(f->cur.stride[0]);
2121
231k
    pixel_copy(&f->ipred_edge[0][sby_off + x_off * 4], y,
2122
231k
               4 * (ts->tiling.col_end - x_off));
2123
2124
231k
    if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
2125
163k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2126
163k
        const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2127
2128
163k
        const ptrdiff_t uv_off = (x_off * 4 >> ss_hor) +
2129
163k
            (((t->by + f->sb_step) * 4 >> ss_ver) - 1) * PXSTRIDE(f->cur.stride[1]);
2130
491k
        for (int pl = 1; pl <= 2; pl++)
2131
327k
            pixel_copy(&f->ipred_edge[pl][sby_off + (x_off * 4 >> ss_hor)],
2132
163k
                       &((const pixel *) f->cur.data[pl])[uv_off],
2133
163k
                       4 * (ts->tiling.col_end - x_off) >> ss_hor);
2134
163k
    }
2135
231k
}
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
61.7k
{
2142
61.7k
    const Dav1dFrameContext *const f = t->f;
2143
61.7k
    pixel *const pal = t->frame_thread.pass ?
2144
61.7k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2145
61.7k
                            ((t->bx >> 1) + (t->by & 1))][0] :
2146
61.7k
        bytefn(t->scratch.pal)[0];
2147
292k
    for (int x = 0; x < bw4; x++)
2148
230k
        memcpy(bytefn(t->al_pal)[0][bx4 + x][0], pal, 8 * sizeof(pixel));
2149
257k
    for (int y = 0; y < bh4; y++)
2150
195k
        memcpy(bytefn(t->al_pal)[1][by4 + y][0], pal, 8 * sizeof(pixel));
2151
61.7k
}
dav1d_copy_pal_block_y_8bpc
Line
Count
Source
2141
25.6k
{
2142
25.6k
    const Dav1dFrameContext *const f = t->f;
2143
25.6k
    pixel *const pal = t->frame_thread.pass ?
2144
25.6k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2145
25.6k
                            ((t->bx >> 1) + (t->by & 1))][0] :
2146
25.6k
        bytefn(t->scratch.pal)[0];
2147
120k
    for (int x = 0; x < bw4; x++)
2148
94.4k
        memcpy(bytefn(t->al_pal)[0][bx4 + x][0], pal, 8 * sizeof(pixel));
2149
107k
    for (int y = 0; y < bh4; y++)
2150
81.3k
        memcpy(bytefn(t->al_pal)[1][by4 + y][0], pal, 8 * sizeof(pixel));
2151
25.6k
}
dav1d_copy_pal_block_y_16bpc
Line
Count
Source
2141
36.1k
{
2142
36.1k
    const Dav1dFrameContext *const f = t->f;
2143
36.1k
    pixel *const pal = t->frame_thread.pass ?
2144
36.1k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2145
36.1k
                            ((t->bx >> 1) + (t->by & 1))][0] :
2146
36.1k
        bytefn(t->scratch.pal)[0];
2147
172k
    for (int x = 0; x < bw4; x++)
2148
135k
        memcpy(bytefn(t->al_pal)[0][bx4 + x][0], pal, 8 * sizeof(pixel));
2149
150k
    for (int y = 0; y < bh4; y++)
2150
114k
        memcpy(bytefn(t->al_pal)[1][by4 + y][0], pal, 8 * sizeof(pixel));
2151
36.1k
}
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
18.6k
{
2158
18.6k
    const Dav1dFrameContext *const f = t->f;
2159
18.6k
    const pixel (*const pal)[8] = t->frame_thread.pass ?
2160
18.6k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2161
18.6k
                            ((t->bx >> 1) + (t->by & 1))] :
2162
18.6k
        bytefn(t->scratch.pal);
2163
    // see aomedia bug 2183 for why we use luma coordinates here
2164
55.8k
    for (int pl = 1; pl <= 2; pl++) {
2165
210k
        for (int x = 0; x < bw4; x++)
2166
173k
            memcpy(bytefn(t->al_pal)[0][bx4 + x][pl], pal[pl], 8 * sizeof(pixel));
2167
190k
        for (int y = 0; y < bh4; y++)
2168
153k
            memcpy(bytefn(t->al_pal)[1][by4 + y][pl], pal[pl], 8 * sizeof(pixel));
2169
37.2k
    }
2170
18.6k
}
dav1d_copy_pal_block_uv_8bpc
Line
Count
Source
2157
8.79k
{
2158
8.79k
    const Dav1dFrameContext *const f = t->f;
2159
8.79k
    const pixel (*const pal)[8] = t->frame_thread.pass ?
2160
8.79k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2161
8.79k
                            ((t->bx >> 1) + (t->by & 1))] :
2162
8.79k
        bytefn(t->scratch.pal);
2163
    // see aomedia bug 2183 for why we use luma coordinates here
2164
26.3k
    for (int pl = 1; pl <= 2; pl++) {
2165
101k
        for (int x = 0; x < bw4; x++)
2166
83.9k
            memcpy(bytefn(t->al_pal)[0][bx4 + x][pl], pal[pl], 8 * sizeof(pixel));
2167
92.9k
        for (int y = 0; y < bh4; y++)
2168
75.3k
            memcpy(bytefn(t->al_pal)[1][by4 + y][pl], pal[pl], 8 * sizeof(pixel));
2169
17.5k
    }
2170
8.79k
}
dav1d_copy_pal_block_uv_16bpc
Line
Count
Source
2157
9.81k
{
2158
9.81k
    const Dav1dFrameContext *const f = t->f;
2159
9.81k
    const pixel (*const pal)[8] = t->frame_thread.pass ?
2160
9.81k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2161
9.81k
                            ((t->bx >> 1) + (t->by & 1))] :
2162
9.81k
        bytefn(t->scratch.pal);
2163
    // see aomedia bug 2183 for why we use luma coordinates here
2164
29.4k
    for (int pl = 1; pl <= 2; pl++) {
2165
108k
        for (int x = 0; x < bw4; x++)
2166
89.3k
            memcpy(bytefn(t->al_pal)[0][bx4 + x][pl], pal[pl], 8 * sizeof(pixel));
2167
97.7k
        for (int y = 0; y < bh4; y++)
2168
78.0k
            memcpy(bytefn(t->al_pal)[1][by4 + y][pl], pal[pl], 8 * sizeof(pixel));
2169
19.6k
    }
2170
9.81k
}
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
80.3k
{
2176
80.3k
    Dav1dTileState *const ts = t->ts;
2177
80.3k
    const Dav1dFrameContext *const f = t->f;
2178
80.3k
    const int pal_sz = b->pal_sz[pl] = dav1d_msac_decode_symbol_adapt8(&ts->msac,
2179
80.3k
                                           ts->cdf.m.pal_sz[pl][sz_ctx], 6) + 2;
2180
80.3k
    pixel cache[16], used_cache[8];
2181
80.3k
    int l_cache = pl ? t->pal_sz_uv[1][by4] : t->l.pal_sz[by4];
2182
80.3k
    int n_cache = 0;
2183
    // don't reuse above palette outside SB64 boundaries
2184
80.3k
    int a_cache = by4 & 15 ? pl ? t->pal_sz_uv[0][bx4] : t->a->pal_sz[bx4] : 0;
2185
80.3k
    const pixel *l = bytefn(t->al_pal)[1][by4][pl];
2186
80.3k
    const pixel *a = bytefn(t->al_pal)[0][bx4][pl];
2187
2188
    // fill/sort cache
2189
132k
    while (l_cache && a_cache) {
2190
51.9k
        if (*l < *a) {
2191
19.6k
            if (!n_cache || cache[n_cache - 1] != *l)
2192
19.4k
                cache[n_cache++] = *l;
2193
19.6k
            l++;
2194
19.6k
            l_cache--;
2195
32.3k
        } else {
2196
32.3k
            if (*a == *l) {
2197
12.9k
                l++;
2198
12.9k
                l_cache--;
2199
12.9k
            }
2200
32.3k
            if (!n_cache || cache[n_cache - 1] != *a)
2201
31.2k
                cache[n_cache++] = *a;
2202
32.3k
            a++;
2203
32.3k
            a_cache--;
2204
32.3k
        }
2205
51.9k
    }
2206
80.3k
    if (l_cache) {
2207
96.3k
        do {
2208
96.3k
            if (!n_cache || cache[n_cache - 1] != *l)
2209
78.1k
                cache[n_cache++] = *l;
2210
96.3k
            l++;
2211
96.3k
        } while (--l_cache > 0);
2212
57.5k
    } else if (a_cache) {
2213
71.2k
        do {
2214
71.2k
            if (!n_cache || cache[n_cache - 1] != *a)
2215
57.2k
                cache[n_cache++] = *a;
2216
71.2k
            a++;
2217
71.2k
        } while (--a_cache > 0);
2218
17.2k
    }
2219
2220
    // find reused cache entries
2221
80.3k
    int i = 0;
2222
246k
    for (int n = 0; n < n_cache && i < pal_sz; n++)
2223
165k
        if (dav1d_msac_decode_bool_equi(&ts->msac))
2224
82.0k
            used_cache[i++] = cache[n];
2225
80.3k
    const int n_used_cache = i;
2226
2227
    // parse new entries
2228
80.3k
    pixel *const pal = t->frame_thread.pass ?
2229
80.3k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2230
80.3k
                            ((t->bx >> 1) + (t->by & 1))][pl] :
2231
80.3k
        bytefn(t->scratch.pal)[pl];
2232
80.3k
    if (i < pal_sz) {
2233
70.2k
        const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2234
70.2k
        int prev = pal[i++] = dav1d_msac_decode_bools(&ts->msac, bpc);
2235
2236
70.2k
        if (i < pal_sz) {
2237
63.8k
            int bits = bpc - 3 + dav1d_msac_decode_bools(&ts->msac, 2);
2238
63.8k
            const int max = (1 << bpc) - 1;
2239
2240
150k
            do {
2241
150k
                const int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2242
150k
                prev = pal[i++] = imin(prev + delta + !pl, max);
2243
150k
                if (prev + !pl >= max) {
2244
86.5k
                    for (; i < pal_sz; i++)
2245
56.5k
                        pal[i] = max;
2246
30.0k
                    break;
2247
30.0k
                }
2248
120k
                bits = imin(bits, 1 + ulog2(max - prev - !pl));
2249
120k
            } while (i < pal_sz);
2250
63.8k
        }
2251
2252
        // merge cache+new entries
2253
70.2k
        int n = 0, m = n_used_cache;
2254
401k
        for (i = 0; i < pal_sz; i++) {
2255
331k
            if (n < n_used_cache && (m >= pal_sz || used_cache[n] <= pal[m])) {
2256
54.6k
                pal[i] = used_cache[n++];
2257
277k
            } else {
2258
277k
                assert(m < pal_sz);
2259
277k
                pal[i] = pal[m++];
2260
277k
            }
2261
331k
        }
2262
70.2k
    } else {
2263
10.1k
        memcpy(pal, used_cache, n_used_cache * sizeof(*used_cache));
2264
10.1k
    }
2265
2266
80.3k
    if (DEBUG_BLOCK_INFO) {
2267
0
        printf("Post-pal[pl=%d,sz=%d,cache_size=%d,used_cache=%d]: r=%d, cache=",
2268
0
               pl, pal_sz, n_cache, n_used_cache, ts->msac.rng);
2269
0
        for (int n = 0; n < n_cache; n++)
2270
0
            printf("%c%02x", n ? ' ' : '[', cache[n]);
2271
0
        printf("%s, pal=", n_cache ? "]" : "[]");
2272
0
        for (int n = 0; n < pal_sz; n++)
2273
0
            printf("%c%02x", n ? ' ' : '[', pal[n]);
2274
0
        printf("]\n");
2275
0
    }
2276
80.3k
}
dav1d_read_pal_plane_8bpc
Line
Count
Source
2175
34.4k
{
2176
34.4k
    Dav1dTileState *const ts = t->ts;
2177
34.4k
    const Dav1dFrameContext *const f = t->f;
2178
34.4k
    const int pal_sz = b->pal_sz[pl] = dav1d_msac_decode_symbol_adapt8(&ts->msac,
2179
34.4k
                                           ts->cdf.m.pal_sz[pl][sz_ctx], 6) + 2;
2180
34.4k
    pixel cache[16], used_cache[8];
2181
34.4k
    int l_cache = pl ? t->pal_sz_uv[1][by4] : t->l.pal_sz[by4];
2182
34.4k
    int n_cache = 0;
2183
    // don't reuse above palette outside SB64 boundaries
2184
34.4k
    int a_cache = by4 & 15 ? pl ? t->pal_sz_uv[0][bx4] : t->a->pal_sz[bx4] : 0;
2185
34.4k
    const pixel *l = bytefn(t->al_pal)[1][by4][pl];
2186
34.4k
    const pixel *a = bytefn(t->al_pal)[0][bx4][pl];
2187
2188
    // fill/sort cache
2189
51.6k
    while (l_cache && a_cache) {
2190
17.2k
        if (*l < *a) {
2191
6.53k
            if (!n_cache || cache[n_cache - 1] != *l)
2192
6.44k
                cache[n_cache++] = *l;
2193
6.53k
            l++;
2194
6.53k
            l_cache--;
2195
10.7k
        } else {
2196
10.7k
            if (*a == *l) {
2197
4.46k
                l++;
2198
4.46k
                l_cache--;
2199
4.46k
            }
2200
10.7k
            if (!n_cache || cache[n_cache - 1] != *a)
2201
10.2k
                cache[n_cache++] = *a;
2202
10.7k
            a++;
2203
10.7k
            a_cache--;
2204
10.7k
        }
2205
17.2k
    }
2206
34.4k
    if (l_cache) {
2207
38.3k
        do {
2208
38.3k
            if (!n_cache || cache[n_cache - 1] != *l)
2209
30.7k
                cache[n_cache++] = *l;
2210
38.3k
            l++;
2211
38.3k
        } while (--l_cache > 0);
2212
25.4k
    } else if (a_cache) {
2213
27.4k
        do {
2214
27.4k
            if (!n_cache || cache[n_cache - 1] != *a)
2215
21.6k
                cache[n_cache++] = *a;
2216
27.4k
            a++;
2217
27.4k
        } while (--a_cache > 0);
2218
6.56k
    }
2219
2220
    // find reused cache entries
2221
34.4k
    int i = 0;
2222
95.9k
    for (int n = 0; n < n_cache && i < pal_sz; n++)
2223
61.4k
        if (dav1d_msac_decode_bool_equi(&ts->msac))
2224
30.7k
            used_cache[i++] = cache[n];
2225
34.4k
    const int n_used_cache = i;
2226
2227
    // parse new entries
2228
34.4k
    pixel *const pal = t->frame_thread.pass ?
2229
34.4k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2230
34.4k
                            ((t->bx >> 1) + (t->by & 1))][pl] :
2231
34.4k
        bytefn(t->scratch.pal)[pl];
2232
34.4k
    if (i < pal_sz) {
2233
30.5k
        const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2234
30.5k
        int prev = pal[i++] = dav1d_msac_decode_bools(&ts->msac, bpc);
2235
2236
30.5k
        if (i < pal_sz) {
2237
28.0k
            int bits = bpc - 3 + dav1d_msac_decode_bools(&ts->msac, 2);
2238
28.0k
            const int max = (1 << bpc) - 1;
2239
2240
66.0k
            do {
2241
66.0k
                const int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2242
66.0k
                prev = pal[i++] = imin(prev + delta + !pl, max);
2243
66.0k
                if (prev + !pl >= max) {
2244
39.7k
                    for (; i < pal_sz; i++)
2245
26.0k
                        pal[i] = max;
2246
13.6k
                    break;
2247
13.6k
                }
2248
52.3k
                bits = imin(bits, 1 + ulog2(max - prev - !pl));
2249
52.3k
            } while (i < pal_sz);
2250
28.0k
        }
2251
2252
        // merge cache+new entries
2253
30.5k
        int n = 0, m = n_used_cache;
2254
173k
        for (i = 0; i < pal_sz; i++) {
2255
143k
            if (n < n_used_cache && (m >= pal_sz || used_cache[n] <= pal[m])) {
2256
20.6k
                pal[i] = used_cache[n++];
2257
122k
            } else {
2258
122k
                assert(m < pal_sz);
2259
122k
                pal[i] = pal[m++];
2260
122k
            }
2261
143k
        }
2262
30.5k
    } else {
2263
3.81k
        memcpy(pal, used_cache, n_used_cache * sizeof(*used_cache));
2264
3.81k
    }
2265
2266
34.4k
    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
34.4k
}
dav1d_read_pal_plane_16bpc
Line
Count
Source
2175
45.9k
{
2176
45.9k
    Dav1dTileState *const ts = t->ts;
2177
45.9k
    const Dav1dFrameContext *const f = t->f;
2178
45.9k
    const int pal_sz = b->pal_sz[pl] = dav1d_msac_decode_symbol_adapt8(&ts->msac,
2179
45.9k
                                           ts->cdf.m.pal_sz[pl][sz_ctx], 6) + 2;
2180
45.9k
    pixel cache[16], used_cache[8];
2181
45.9k
    int l_cache = pl ? t->pal_sz_uv[1][by4] : t->l.pal_sz[by4];
2182
45.9k
    int n_cache = 0;
2183
    // don't reuse above palette outside SB64 boundaries
2184
45.9k
    int a_cache = by4 & 15 ? pl ? t->pal_sz_uv[0][bx4] : t->a->pal_sz[bx4] : 0;
2185
45.9k
    const pixel *l = bytefn(t->al_pal)[1][by4][pl];
2186
45.9k
    const pixel *a = bytefn(t->al_pal)[0][bx4][pl];
2187
2188
    // fill/sort cache
2189
80.6k
    while (l_cache && a_cache) {
2190
34.7k
        if (*l < *a) {
2191
13.1k
            if (!n_cache || cache[n_cache - 1] != *l)
2192
12.9k
                cache[n_cache++] = *l;
2193
13.1k
            l++;
2194
13.1k
            l_cache--;
2195
21.6k
        } else {
2196
21.6k
            if (*a == *l) {
2197
8.46k
                l++;
2198
8.46k
                l_cache--;
2199
8.46k
            }
2200
21.6k
            if (!n_cache || cache[n_cache - 1] != *a)
2201
21.0k
                cache[n_cache++] = *a;
2202
21.6k
            a++;
2203
21.6k
            a_cache--;
2204
21.6k
        }
2205
34.7k
    }
2206
45.9k
    if (l_cache) {
2207
58.0k
        do {
2208
58.0k
            if (!n_cache || cache[n_cache - 1] != *l)
2209
47.3k
                cache[n_cache++] = *l;
2210
58.0k
            l++;
2211
58.0k
        } while (--l_cache > 0);
2212
32.1k
    } else if (a_cache) {
2213
43.7k
        do {
2214
43.7k
            if (!n_cache || cache[n_cache - 1] != *a)
2215
35.6k
                cache[n_cache++] = *a;
2216
43.7k
            a++;
2217
43.7k
        } while (--a_cache > 0);
2218
10.6k
    }
2219
2220
    // find reused cache entries
2221
45.9k
    int i = 0;
2222
150k
    for (int n = 0; n < n_cache && i < pal_sz; n++)
2223
104k
        if (dav1d_msac_decode_bool_equi(&ts->msac))
2224
51.2k
            used_cache[i++] = cache[n];
2225
45.9k
    const int n_used_cache = i;
2226
2227
    // parse new entries
2228
45.9k
    pixel *const pal = t->frame_thread.pass ?
2229
45.9k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2230
45.9k
                            ((t->bx >> 1) + (t->by & 1))][pl] :
2231
45.9k
        bytefn(t->scratch.pal)[pl];
2232
45.9k
    if (i < pal_sz) {
2233
39.6k
        const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2234
39.6k
        int prev = pal[i++] = dav1d_msac_decode_bools(&ts->msac, bpc);
2235
2236
39.6k
        if (i < pal_sz) {
2237
35.7k
            int bits = bpc - 3 + dav1d_msac_decode_bools(&ts->msac, 2);
2238
35.7k
            const int max = (1 << bpc) - 1;
2239
2240
84.2k
            do {
2241
84.2k
                const int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2242
84.2k
                prev = pal[i++] = imin(prev + delta + !pl, max);
2243
84.2k
                if (prev + !pl >= max) {
2244
46.7k
                    for (; i < pal_sz; i++)
2245
30.4k
                        pal[i] = max;
2246
16.3k
                    break;
2247
16.3k
                }
2248
67.9k
                bits = imin(bits, 1 + ulog2(max - prev - !pl));
2249
67.9k
            } while (i < pal_sz);
2250
35.7k
        }
2251
2252
        // merge cache+new entries
2253
39.6k
        int n = 0, m = n_used_cache;
2254
227k
        for (i = 0; i < pal_sz; i++) {
2255
188k
            if (n < n_used_cache && (m >= pal_sz || used_cache[n] <= pal[m])) {
2256
34.0k
                pal[i] = used_cache[n++];
2257
154k
            } else {
2258
154k
                assert(m < pal_sz);
2259
154k
                pal[i] = pal[m++];
2260
154k
            }
2261
188k
        }
2262
39.6k
    } else {
2263
6.29k
        memcpy(pal, used_cache, n_used_cache * sizeof(*used_cache));
2264
6.29k
    }
2265
2266
45.9k
    if (DEBUG_BLOCK_INFO) {
2267
0
        printf("Post-pal[pl=%d,sz=%d,cache_size=%d,used_cache=%d]: r=%d, cache=",
2268
0
               pl, pal_sz, n_cache, n_used_cache, ts->msac.rng);
2269
0
        for (int n = 0; n < n_cache; n++)
2270
0
            printf("%c%02x", n ? ' ' : '[', cache[n]);
2271
0
        printf("%s, pal=", n_cache ? "]" : "[]");
2272
0
        for (int n = 0; n < pal_sz; n++)
2273
0
            printf("%c%02x", n ? ' ' : '[', pal[n]);
2274
0
        printf("]\n");
2275
0
    }
2276
45.9k
}
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
18.6k
{
2281
18.6k
    bytefn(dav1d_read_pal_plane)(t, b, 1, sz_ctx, bx4, by4);
2282
2283
    // V pal coding
2284
18.6k
    Dav1dTileState *const ts = t->ts;
2285
18.6k
    const Dav1dFrameContext *const f = t->f;
2286
18.6k
    pixel *const pal = t->frame_thread.pass ?
2287
18.6k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2288
18.6k
                            ((t->bx >> 1) + (t->by & 1))][2] :
2289
18.6k
        bytefn(t->scratch.pal)[2];
2290
18.6k
    const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2291
18.6k
    if (dav1d_msac_decode_bool_equi(&ts->msac)) {
2292
9.24k
        const int bits = bpc - 4 + dav1d_msac_decode_bools(&ts->msac, 2);
2293
9.24k
        int prev = pal[0] = dav1d_msac_decode_bools(&ts->msac, bpc);
2294
9.24k
        const int max = (1 << bpc) - 1;
2295
39.0k
        for (int i = 1; i < b->pal_sz[1]; i++) {
2296
29.8k
            int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2297
29.8k
            if (delta && dav1d_msac_decode_bool_equi(&ts->msac)) delta = -delta;
2298
29.8k
            prev = pal[i] = (prev + delta) & max;
2299
29.8k
        }
2300
9.37k
    } else {
2301
48.1k
        for (int i = 0; i < b->pal_sz[1]; i++)
2302
38.8k
            pal[i] = dav1d_msac_decode_bools(&ts->msac, bpc);
2303
9.37k
    }
2304
18.6k
    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
18.6k
}
dav1d_read_pal_uv_8bpc
Line
Count
Source
2280
8.79k
{
2281
8.79k
    bytefn(dav1d_read_pal_plane)(t, b, 1, sz_ctx, bx4, by4);
2282
2283
    // V pal coding
2284
8.79k
    Dav1dTileState *const ts = t->ts;
2285
8.79k
    const Dav1dFrameContext *const f = t->f;
2286
8.79k
    pixel *const pal = t->frame_thread.pass ?
2287
8.79k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2288
8.79k
                            ((t->bx >> 1) + (t->by & 1))][2] :
2289
8.79k
        bytefn(t->scratch.pal)[2];
2290
8.79k
    const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2291
8.79k
    if (dav1d_msac_decode_bool_equi(&ts->msac)) {
2292
4.28k
        const int bits = bpc - 4 + dav1d_msac_decode_bools(&ts->msac, 2);
2293
4.28k
        int prev = pal[0] = dav1d_msac_decode_bools(&ts->msac, bpc);
2294
4.28k
        const int max = (1 << bpc) - 1;
2295
18.2k
        for (int i = 1; i < b->pal_sz[1]; i++) {
2296
13.9k
            int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2297
13.9k
            if (delta && dav1d_msac_decode_bool_equi(&ts->msac)) delta = -delta;
2298
13.9k
            prev = pal[i] = (prev + delta) & max;
2299
13.9k
        }
2300
4.51k
    } else {
2301
23.1k
        for (int i = 0; i < b->pal_sz[1]; i++)
2302
18.6k
            pal[i] = dav1d_msac_decode_bools(&ts->msac, bpc);
2303
4.51k
    }
2304
8.79k
    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
8.79k
}
dav1d_read_pal_uv_16bpc
Line
Count
Source
2280
9.81k
{
2281
9.81k
    bytefn(dav1d_read_pal_plane)(t, b, 1, sz_ctx, bx4, by4);
2282
2283
    // V pal coding
2284
9.81k
    Dav1dTileState *const ts = t->ts;
2285
9.81k
    const Dav1dFrameContext *const f = t->f;
2286
9.81k
    pixel *const pal = t->frame_thread.pass ?
2287
9.81k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2288
9.81k
                            ((t->bx >> 1) + (t->by & 1))][2] :
2289
9.81k
        bytefn(t->scratch.pal)[2];
2290
9.81k
    const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2291
9.81k
    if (dav1d_msac_decode_bool_equi(&ts->msac)) {
2292
4.95k
        const int bits = bpc - 4 + dav1d_msac_decode_bools(&ts->msac, 2);
2293
4.95k
        int prev = pal[0] = dav1d_msac_decode_bools(&ts->msac, bpc);
2294
4.95k
        const int max = (1 << bpc) - 1;
2295
20.8k
        for (int i = 1; i < b->pal_sz[1]; i++) {
2296
15.8k
            int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2297
15.8k
            if (delta && dav1d_msac_decode_bool_equi(&ts->msac)) delta = -delta;
2298
15.8k
            prev = pal[i] = (prev + delta) & max;
2299
15.8k
        }
2300
4.95k
    } else {
2301
25.0k
        for (int i = 0; i < b->pal_sz[1]; i++)
2302
20.1k
            pal[i] = dav1d_msac_decode_bools(&ts->msac, bpc);
2303
4.85k
    }
2304
9.81k
    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
9.81k
}